Looking forward to this!
#tinyusb
1 messages · Page 13 of 1
@hathach is it possible that instead of deciding based on DTR, actually to use the fact that data has not been sent/fifo is not empty? Or just leave it up to the application (returning 0 if no space available). I also have a case where DTR/RTS lines are used for different things and we need to communicate with the other end even when lines are low. The application itself can detect that the other end is alive, but bytes can not be sent in any way. (Actually one packet comes, proving connectio...
Fixes #460
Describe the PR
A clear and concise description of what this PR solve.
Additional context
If applicable, add any other context about the PR and/or screenshots here.
@me-no-dev can you describe your issue in detail, the DTR is standard OS way for terminal to connect, using DTR for other purpose like Arduino autoreset is a actually hack. However, I am open for discussion if you could break it down and there are no other alternatives to address a real issue.
If I want to create a transparent USB-UART bridge to use for flashing ESP devices, the app needs to handle particular DTR/RTS changes that will trigger the target to reboot in the proper mode, after which it needs to communicate with the target. Unfortunately the last change leaves both RTS and DTR low and further communication is impossible.
If I want to create a transparent USB-UART bridge to use for flashing ESP devices, the app needs to handle particular DTR/RTS changes that will trigger the target to reboot in the proper mode, after which it needs to communicate with the target. Unfortunately the last change leaves both RTS and DTR low and further communication is impossible.
All starts as expected with both lines to high and baudrate update, then the series of 4 line changes are issued (while connected).
I still ...
@pallid shadow https://github.com/adafruit/Adafruit_CircuitPython_HTS221/issues/4#issuecomment-656283990
the calibration numbers look suspicious
How will you force something like that only on one platform? Surely both ways would work. And yes, I totally agree that it's really weird that endpoints and fifos do not match, especially since you can split the whole fifo memory to more than 5... but :) next silicon I guess. I will be looking into DMA as well, as that is something that can remove the limitation.
We can bring up this PR when using DMA, though that may take long time since current contributors seems to be happy with FIFO ...
Here is the signal flow of such upload process:
-
Line State: DTR:1, RTS:1 (Connected)
-
Line Coding: baud, etc.
-
Reset Target
- Line State: DTR:0, RTS:1 (Disconnected)
- Line State: DTR:1, RTS:1 (Connected)
- Line State: DTR:1, RTS:0 (Connected)
- Line State: DTR:0, RTS:0 (Disconnected)
-
Send the firmware (but TinyUSB thinks we are disconnected, so it fails)
-
Line State: DTR:0, RTS:0 (Disconnected)
Maybe we could try to figure out how to tell DCD to skip FIFO assignment in portable fashion, then we could merge this PR.
I could not come up with one :(
Endpoints are opened as they are found in the descriptors (as far as I understand the flow), so in order for endpoint to not be opened, it have to be somehow designated by another api call or something. Or... can we define the EP transfer size as 0 in the descriptor and have the dcd not open it? or not assign fifo? Would that still wo...
One more point for this PR (S2 specific): FIFOs will be larger, because the total space is divided by 4 instead of 6 (excluding EP0)
I don't like to add code that didn't run at all
Do you mean that you do not expect this to be ever needed? Because this code will run the same on STM (no reason fifo number to be the same a EP number. Designation is so internal that 99% of the dcd code do not care for that fifo number) and will run in more cases on ESP32S2. This is for the case where descriptors for multiple drivers are predefined by an upper layer library and loaded when necessary. You can fit into 6 endpoints constant ...
Describe the PR
This pull request adds support for Great Scott Gadget's LUNA USB multi-tool, which features a USB-attached SAMD21 "debug" microcontroller.
Additional context
LUNA hardware/software repository: https://github.com/greatscottgadgets/luna
More information about LUNA: https://luna.readthedocs.io/en/latest/
(The board uses a DFU bootloader; the linker script provided here places all device binaries after the protected boot region.)
thank you very much for the PR, would you mind updating the https://github.com/hathach/tinyusb/blob/master/docs/boards.md to include the reference link to LUNA as well.
PS: I am fan of your LUNA work :smiley:
I have a couple of question
- at state iv, the device is already in ROM loader right ?
- why not set DTR to 1 before sending firmware
- No, it is not in bootloader yet. The toggles interface with two fets to toggle RST and IO0 in the proper sequence to reset to bootloader. In reality a few milliseconds later is when the target is in bootloader.
- If we toggle the lines again, they will reset the target back into the firmware
- No, it is not in bootloader yet. The toggles interface with two fets to toggle RST and IO0 in the proper sequence to reset to bootloader. In reality a few milliseconds later is when the target is in bootloader.
- If we toggle the lines again, they will reset the target back into the firmware
Ok, so after a few ms of state iv, the device reset into bootloader. Why setting DTR to 1 again while in bootloader cause esp32s2 reset into application ? If I manually holding GPIO0 to force...
If I manually holding GPIO0 to force bootloader mode, and then connect with another terminal, it will also set the DTR to 1 as well, in that case would it reset to app upon connection as well ?
My English level did not help me understand what you mean? If you manually hold IO0 and connect from another terminal (just regular terminal, not esptool) on connect the chip will enter bootloader.
Ok, so after a few ms of state iv, the device reset into bootloader. Why setting DTR to 1 again...
because of the resulting switches of the fets. Any toggle of DTR at this point will cause the reset. Here is a schematic of such circuit:
OK, I am not good with hardware, so I am still failed to understand why DTR cannot be set again. It is native USB connection, DTR/RTS are software control line state and are not necessary hard-writed to anything. In my point of view, DTR is used to indicate active connection, you are using it for different purpose as hardware hack, and it is not reall...
I get your point, but regular USB UARTs do not prevent the data flow when toggling the lines, therefore we have been using this for the last 6 years (as far as I remember, not sure for longer). I am not sure if this is a hack really, we have APIs to control the lines in all operating systems.
Could this just be made optional? So schemes where lines need to switch and data needs to flow can be handled?
I get your point, but regular USB UARTs do not prevent the data flow when toggling the lines, therefore we have been using this for the last 6 years (as far as I remember, not sure for longer). I am not sure if this is a hack really, we have APIs to control the lines in all operating systems.
Could this just be made optional? So schemes where lines need to switch and data needs to flow can be handled?
sure, It is totally possible, however the stack will loose the ability to detect...
This is not an S2 upload scenario. This is the scenario where we use an S2 just like Arduino uses ATMega chips for USB-UART and the S2 is just acting as USB-UART and passing data/toggles through to the target ESP (can be any ESP model. they all work the same).
In this case the application is well aware of when it is connected and when not, but we can not tell tinyusb that. Flush is the only issue. If we were just to receive data from the host and not need to talk back to it, it would have ...
This is not an S2 upload scenario. This is the scenario where we use an S2 just like Arduino uses ATMega chips for USB-UART and the S2 is just acting as USB-UART and passing data/toggles through to the target ESP (can be any ESP model. they all work the same).
I see, seem like we are talking about totally different thing from the start. Could you explain it all again starting with the schematics. If you intend to use ATMega, you should probably want to use LUFA since TinyUSB doesn't supp...
We intend to use ESP32-S2, not ATMega. ATMega was just an example that the Arduino guys use on their boards.
Schematics are irrelevant to the point where they are the reason why esptool sends those particular line changes. In the resulting application where we use the S2, we can handle that in software without transistors on the other end. They are necessary only on boards that use regular USB-UART chips.
The application schematic is one S2 with USB, directly connected with RX/TX/EN/IO0...
However if the scenario isn't materialized yet, we can wait until you are working on it, and discuss more later on. Otherwise, we can just add an option for just in case scenario where in fact no body is using it.
Ahh you edit as I write :D We are in fact working on it. It is an active project and we hit this issue.
The application schematic is one S2 with USB, directly connected with RX/TX/EN/IO0 to the target ESP on the board (the ESP that will run the user applications and have antenna etc.).
Goal is the S2 to act just like any other FTDI, SiLabs, etc. USB-UART chip and pass transparently RX/TX and LineState changes. Everything is working as expected, except tx flush, because the last LineState that esptool sends before starting communication with the bootloader, leaves DTR low.
I see, so ...
Thanks for having the conversation :) I am not always the best at explaining.
@duempel after a lengthy discussion with @me-no-dev (there is a bit of misunderstanding at firs), you could just read the last 2,3 comments. I think there is actual a scenario where this option is a must. The DTR/CTS are used as proxy singal controlling to another target MCU pins rather than its original meaning of connection detection. in Arduino schematics, DTR is mostly connected to target mcu reset. Let's me know if you have any other opinion, otherwise, I think we can merge this PR.
Thanks for having the conversation :) I am not always the best at explaining.
no problems, English is not my native language as well :)
Hi! Is any chance to fix the flushing in some not-so-distant future?
It would be nice to have this logic in the driver. Thanks!
Thanks @me-no-dev and @hathach for bringing up this PR again. I've followed your conversation the last days but was too busy to leave any comments.
I think it is important to get CDC working without DTR being set. The example @me-no-dev gave is just one of the reasons. There are a lot of proprietary software solution which do not set this bit as it should. I just run into this trap again when changing USB middleware of an existing project to TinyUSB for development cases. There will be a lot...
I just remembered we were already talking about this here and here.
If no IN token is being sent by host the DTR bit is irrelevant anyway. But as you said the endpoint will be busy and no data can be sent out. In this case maybe it's better to not start a transfer. 🤔 Maybe a API to abort a transfer which can be called if a new connection was started by...
But I am not sure if a define is a good way to ignore DTR. I was reviewing CDC implementation and think that the way we are currently checking
tud_cdc_n_connectedwithintud_cdc_n_write_flushis not very useful.
Problem: DTR bit should be used to check if the data terminal is ready and able to receive new data. If DTR is not set and we send out the data, we can lose all of it, because we don't know if the terminal will take the data or not. But with our current implementation the...
I just remembered we were already talking about this here and here.
If no IN token is being sent by host the DTR bit is irrelevant anyway. But as you said the endpoint will be busy and no data can be sent out. In this case maybe it's better to not start a transfer. Maybe a API to abort a transfer which can be called if a new connection was start...
Right, however one may argue to have the data sent to host anyway, to have a full print log even terminal connected a few second late.
I think we could check the behavior of USB-Uart chips.
But we could tweak it to overwrite FIFO when DTR is not connected, and keep holding data in FIFO as long as possible.
This is a pretty good idea. If I understand you correctly we just have to set
p_cdc->tx_ff.overwritable = dtr?0:1;
within control request (e.g. here). This will enable that we can still write data to the buffer, even if we do not transfer them (in case no IN token are being reque...
I just tested the behavior with one FTDI chip and also with STLink Virtual COM Port of Nucleo board. The FTDI seemed to never store and send old data after starting a new connection.
Personally I prefer the FTDI behavior, maybe it's not a big thing but in some case we may have data leak problem if we store old data.
thank you very much for the PR, would you mind updating the https://github.com/hathach/tinyusb/blob/master/docs/boards.md to include the reference link to LUNA as well.
Added! Thanks. :)
PS: I am fan of your LUNA work 😃
Thanks! ^_^
I just tested the behavior with one FTDI chip and also with STLink Virtual COM Port of Nucleo board. The FTDI seemed to never store and send old data after starting a new connection.
Personally I prefer the FTDI behavior, maybe it's not a big thing but in some case we may have data leak problem if we store old data.
But with the ACM model it could be difficult to detect the connection state without DTR.
FTDI is custom usb2uart, they wrote both PC driver and firmware, they...
Yes, as @hathach said the FTDI driver have much more possibilities to detect connection and disconnection events. I see a lot of control packets for connection management here.
But I think the way we want to go now is just fine. Every user can decide on his own if he wants to implement DTR checking for his application or not.
Let's me know if you have anything to add to my above proposed approach. CDC is most used interface, hopefully the changes won't break other project.
Maybe an o...
[hathach/tinyusb] New branch created: improve\-highspeed
Describe the PR
HS device can operate at FS mode e.g plugging into FS host. Therefore actual link speed should be checked when returning configuration descriptors and/or other related scenario when there is difference between fs/hs mode.
- add tud_speed_get()
- define both fs and hs configuration descriptor
- rename CFG_TUD_CDC_EPSIZE to CFG_TUD_CDC_EP_BUFSIZE with default size of 64 for FS, and 512 for HS
Maybe an option for fifo overwriting would be a nice feature to keep consistency? Something like
CFG_TUD_CDC_DISABLE_UNCONNECTED_BUF_OVERWRITINGwith a shorter name . But this is just optional since write_available API can handle it.
IMHO, TX fifo must not be overwritten when we know there is client connected to drain data. Since most of the time, application will just call write() and check the written_bytes. Disabling overwrite will definitely cause loss of data for lots of current p...
@hathach I think there is a misunderstanding. Currently overwrite is always disabled. Because current projects are not overwriting the buffer, I asked for an option which just optionally disables 2. of your comment to keep behavior as it was before.
Changes of behavior:
- If DTR bit is set new and old implementation will work the same
- If no DTR is set, flushing of both implementation will remove data from fifo, but...
@duempel would you like to get write access to this branch or create a new PR to show your idea ?
Thanks @HiFiPhile but since the new discussed implementation would differ from this PR's description I think it's better to open a new PR for this.
Maybe we can just merge this PR in the first step, as @hathach already wanted to here. Since this is a very easy concept and will not bring any other issues up to existing applications.
I could then create a new issue to discuss about other possibilities. Let's wait what @...
Thanks @HiFiPhile but since the new discussed implementation would differ from this PR's description I think it's better to open a new PR for this.
Yeah, it makes more sense to implement this on a separated PR. There should be a reference to this PR along with a sum up as well.
Maybe we can just merge this PR in the first step, as @hathach already wanted to here. Since this is a very easy concept and will not brin...
If we are doing these changes to CDC class old applications have to be changed if they do not wish this behavior. Future applications can only make profit from it
Those applications will need to specifically enable the "do not check DTR" option. If they do, they should be aware of the consequences, as that is an option that you usually first need to learn the protocol in order to figure out that you need. Such applications then can/should detect on their own when they are connected or no...
@hathach I think there is a misunderstanding. Currently overwrite is always disabled. Because current projects are not overwriting the buffer, I asked for an option which just optionally disables 2. of your comment to keep behavior as it was before.
Changes of behavior:
- If DTR bit is set new and old implementation will work the same
- If no DTR is set, flushing of both implementation will remove data fr...
the driver does auto-flush on complete, for now I don't really have an motive to implement and test this. Maybe later when I have more free time.
Those applications will need to specifically enable the "do not check DTR" option. If they do, they should be aware of the consequences, as that is an option that you usually first need to learn the protocol in order to figure out that you need. Such applications then can/should detect on their own when they are connected or not. I have also gotten old data in the UART before... that is not something strange.
We will use a more dynamic approach the compiler switch proposed in this PR.
...
@gh2o Let's me know if you have time to wrap up the PR, else I could help with the changes. This callback maybe handy for many projects.
I really don't understand these questions of yours. Seem missing a context I think.
Sorry, they were meant for @duempel
@hathach alright I will be opening a new issue with reference to this PR and writing a little summary of everything we've already discussed about. Also I can show up a draft PR with our favorite changes for now. But today I will most likely not be able to do that anymore.
@me-no-dev yes you are right about the "do not check DTR" option. But as @hathach already said we were already discussing about an other solution which is different from this PR's approach.
How do you actually know t...
@hathach My experience was that I had to flush manually after each write. Otherwise, only the first write was successful and the second one returned an error.
@hathach My experience was that I had to flush manually after each write. Otherwise, only the first write was successful and the second one returned an error.
can you provide a modified version of cdc_msc that causes the issue. The chance should be as minimal as possible.
But I don't see a chance to detect disconnection events with this.
Clear. Thanks!
.-.
My original experiments were with ESP-IDF which uses an older version of tinyusb. Now I tried to reproduce the issue with the following code but I'm getting CPU panics all the time:
void cdc_task(void* params)
{
(void) params;
uint8_t buf1[2] = {'a'};
uint8_t buf2[2] = {'b'};
// RTOS forever loop
while ( 1 )
{
if ( tud_cdc_connected() )
{
// connected and there are data available
if ( tud_cdc_available() )
{
int ret = tud_c...
@dobairoland If you believe the behavior is incorrect, please open your own issue using bug template and provide details there. This issue is simply a feature request. Note: you need to build with the master of this repo rather than version in the IDF.
The changes to src/class/net/net_device.c seem unnecessary. The file could remain unchanged and the project still compiles without issue.
Set up
- PC OS : Ubuntu 20.04
- Board : msp_exp430f5529lp
- Firmware: examples/device/cdc_msc
Describe the bug
Failed to build due to a weird array-bound warning which I tried to fix but couldn't figure it out at this line
https://github.com/hathach/tinyusb/blob/master/src/portable/ti/msp430x5xx/dcd_msp430x5xx.c#L525
dcd_msp430x5xx.c:525:55: error: array subscript [65, 2097] is outside array bounds of 'volatile unsigned char[1]' [-Werror=array-bound...
Signed-off-by: Chang Feng
Describe the PR
Ref #459
In _usbd_driver array (in file usbd.c), could add a include like
#ifdef USBD_DRIVER_INCLUDE
#include USBD_DRIVER_INCLUDE
#endif
to support user custom usbd drivers, avoiding modifying files
@hathach I've made a compiler explorer project to experiment later. This is reduced down to the minimum: https://godbolt.org/z/WPsvbs
A workaround discussed on IRC (thanks @RichFelker) is:
#define EP_REGS(epnum, dir) (volatile unsigned char *)(uintptr_t)&USBOEPCNF_1 + 64*dir + 8*(epnum - 1)
If we do not yeld in ISR when we write to queue/give semaphore, the scheduler will not know of the change and will not check the queue untill the next OS tick. This change causes the task to be called immediately and makes communication many times faster.
Example reading the device descriptor
Before the change
After the change
@hathach this is also the progress with my USB decoder and direct result of it :)
this shouldn't be needed, since osal_freertos.h is only meant to be included by osal.h which already included tusb_common.h.
Excellent !! Thank you very much for the PR. Indeed, no wonder why the USB communication is somewhat slow on ESP32S2. I have scratched my head to find the reason.
wow, thanks for the quick fix. I tried the walkaround on both compiler explorer and my real env for msp430, but it doesn't seems to fix the warning as well :D. Yeah, I also kind of guess EP_REGS cause the warning, but failed to see how to make gcc happy :)
thanks for the PR, now I need to spam all the examples tud_descriptor_string_cb() with the quote :D. Note this MS OS Descriptor is v1 and applied only to win7 and prio. Win8 and win10 use BOS to retrieve MS OS v2
// The 0xEE index string is a Microsoft OS Descriptors.
// https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/microsoft-defined-usb-descriptors
Endpoints are opened as they are found in the descriptors (as far as I understand the flow), so in order for endpoint to not be opened, it have to be somehow designated by another api call or something. Or... can we define the EP transfer size as 0 in the descriptor and have the dcd not open it? or not assign fifo? Would that still work and enumerate fine? Will try!
Define EP size = 0 shouldn't be done, since it will potentially mess up with PC driver, and never guarantee to run. An wind...
In your constant EP assignment, you seem to miss the notification EP of CDC. Although it is not used, the EP still need to response with NAK.
It's up there :) 0x84 and 0x03 are for DATA, 0x85 is the notification EP
[hathach/tinyusb] New branch created: followup\-pr466\-pr468
Describe the PR
Follow up to #466 and #468
- Code style clean up
- move the MS OS 1.0 Descriptor (0xEE) note to all example.
agreed, but I had a couple of failed builds and opted for "better safe than sorry" approach :)
In your constant EP assignment, you seem to miss the notification EP of CDC. Although it is not used, the EP still need to response with NAK.
It's up there :) 0x84 and 0x03 are for DATA, 0x85 is the notification EP (weird numbers because of S2 ROM CDC)
ah right, there is also an extra 0x05 as well !!!, I was overlook.
@hathach this is also the progress with my USB decoder and direct result of it :)
Are you writing the USB decoder script with an OSC/Logic analyzer, that looks fantastic. Super work there
Are you writing the USB decoder script with an OSC/Logic analyzer
Yes :) The LA that I have is not widely used or support everything, so some coding had to be done :) I added since SETUP decoding and I am currently adding CRC check and calculation. It's limited to 12Mbps USB and far from your LA, but it works great and shows everything the I might need to debug the bus up to driver level.
<img width="2464" alt="Screenshot 2020-07-21 at 17 23 11" src="https://user-images.githubusercont...
Are you writing the USB decoder script with an OSC/Logic analyzer
Yes :) The LA that I have is not widely used or support everything, so some coding had to be done :) I added since SETUP decoding and I am currently adding CRC check and calculation. It's limited to 12Mbps USB and far from your LA, but it works great and shows everything the I might need to debug the bus up to driver level.
Super cool, I am sure lots of people will find your decoding script useful. I am too lazy f...
I am sure lots of people will find your decoding script useful.
I will definitely publish it. I am not sure if others will find it useful if they do not have an LA from the same company. The good thing is that it's all in JavaScript, so in reality a web layer can be written to display the data and also to accept files from different LAs (I em pretty sure that the APP that my LA uses is just a web app with QT backend), but requires someone with the free time and will at hand :D
Note to everyone: while working with nRF52 + freeRTOS, the USB IRQ can be triggered (BUS_RESET) before task scheduler is started, which will cause portYIELD_FROM_ISR -> SVCHandler run into hardfault. I could resolve this by moving the tud_init() next to vTaskStartScheduler().
https://github.com/adafruit/Adafruit_nRF52_Arduino/pull/542/files
This can be resolved completely by adding.
if(xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED) portYIELD_FROM_ISR(xHigherPriorityT...
This is never the case for ESP32 either. Maybe worth checking only until scheduler is running?
This is never the case for ESP32 either. Maybe worth checking only until scheduler is running?
there is no way to do just that, the only way is adding it into the osal_freertos.h . I will try to put up some docs, if anyone run into the issue. Then google this out, they may raise the issue for further action.
static bool _scheduler_started = false;
static bool check_if_scheduler_was_started(){
_scheduler_started = (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED);
return _scheduler_started;
}
...
if(_scheduler_started || check_if_scheduler_was_started()) portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
check_if_scheduler_was_started() should not be called once start was detected
[hathach/tinyusb] New branch created: fix\-samd21\-missing\-setup
Describe the PR
Fixed race condition with Adafruit_TinyUSB_ArduinoCore port commit 11d669b4d2a40eb2fc5e51b2a9707a6de9d42363 and SAMD BSP 1.6.1 prevent samd21 to enumerate.
Additional context
Also change flash target for adafruit m0/m4 to use bossac
static bool _scheduler_started = false; static bool check_if_scheduler_was_started(){ _scheduler_started = (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED); return _scheduler_started; } ... if(_scheduler_started || check_if_scheduler_was_started()) portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
check_if_scheduler_was_started()should not be called once start was detected
it is an great idea, however, since osal_freertos is all static ...
I think it is best to just move the tud_init() into the app device task in the example with a note to user is good enough for now.
https://github.com/hathach/tinyusb/blob/master/examples/device/cdc_msc_freertos/src/main.c#L118
[hathach/tinyusb] New branch created: call\-usbinit\-after\-kernel\-started
Describe the PR
TinyUSB IRQ handler make use of RTOS queue API. If stack is initialized before kernel/scheudler, the ISR can invoke RTOS API when kernel is in unknown state which could cause hardfault in case of freeRTOS with portYield().
- update example to call tud_init() after freeRTOS kernel is started
- add note to usb init functions
follow up to #468
I think it is best to just move the tud_init() into the app device task
this is the valid RTOS approach IMHO :) You start a task, init whatever it needs inside, then loop about it.
@cr1901 thanks for creating a compiler explorer project.
GCC 9 release seems to did some enhancements to existing warnings (quote from GCC 9 Release):
-Warray-bounds detects more instances of out-of-bounds indices.
But I have no idea what they actually changed. 😂
Maybe the warning/error is caused by volatile attribute. When changing this line
volatile uint8_t * ep_buf = &USBSTABUFF + (ep_regs[BBAX] << 3);
to
volatile ui...
I tried to figure out the cause of this problem and found Bug 94675 - [9/10/11 regression] -Warray-bounds false positive with -O2 since r9-1948. This seems to be related to our problem.
Maybe this commit can have brought up the false positives to gcc.
Also I did some very easy examples with compiler explorer that already threw the warning:
Yeah, I feel much better now. Since most people will use stock example as template, it is better to fix it asap :)
I tried to figure out the cause of this problem and found Bug 94675 - [9/10/11 regression] -Warray-bounds false positive with -O2 since r9-1948. This seems to be related to our problem.
Maybe this commit can have brought up the false positives to gcc.
Also I did some very easy examples with compiler explorer that already threw the war...
@duempel AFAIU, the warning in this case is a side-effect of the real problem with my code as-written.
The original line is: #define EP_REGS(epnum, dir) &USBOEPCNF_1 + 64*dir + 8*(epnum - 1)
USBOEPCNF_1 is declared as a volatile unsigned char. The compiler treats USBOEPCNF_1 as a 1 byte object. When I take the address via &USBOEPCNF_1, I've created a volatile unsigned char *. I am invoking UB by doing pointer arithmetic- + 64*dir + 8*(epnum - 1)- to move past the storag...
@cr1901 thanks for this detailed description.
Short version: TI shouldn't have declared USBOEPCNF_1 as volatile unsigned char. It should've been something like #define USBOEPCNF_1 (*(volatile unsigned char *)0xdeadbeef) (example address). However, I tried to use TI's definition and work around it. And it lead to code that worked in old compiler versions but was flagged as UB in newer versions :).
Yes I agree with you. A different define could have been better at this point.
casti...
Yes, doing all the arithmetic as uintptr_t is preferable. Alternatively, if TI's headers could be fixed, the incorrect type volatile unsigned char could be changed to volatile unsigned char [] (unspecified size) in which case the compiler would have to assume any non-negative offset may be valid.
Indeed my original solution is arguably invalid because the compiler can prove that the resulting pointer still points to the same object of size one, and any arithmetic as pointers outsid...
STM32F0 and STM32F1 seem listed as supported boards. I have the official STM32 core installed in the Arduino IDE (v1.8.13), but I don't seem to be able to compile any of the sample sketches for either the STM32F030F4P6 or the STM32F103C8T6. I get this error: fatal error: Adafruit_TinyUSB_Core.h: No such file or directory. Can someone tell me what could be wrong here? BTW there's no TinyUSB in Tools -> USB Stack on the STM32F103C8T6 (Blue Pill) and on the STM32F030F4P6 there's no Tools -> USB Stack option, period!
Aah darn! I was looking at the docs for https://github.com/hathach/tinyusb when I have installed https://github.com/adafruit/Adafruit_TinyUSB_Arduino
Short version: TI shouldn't have declared
USBOEPCNF_1asvolatile unsigned char. It should've been something like#define USBOEPCNF_1 (*(volatile unsigned char *)0xdeadbeef)(example address). However, I tried to use TI's definition and work around it. And it lead to code that worked in old compiler versions but was flagged as UB in newer versions :).
This is spot-on, USBOEPCNF_1 is linker symbol defined by PROVIDE, it should really be declared as pointer by TI. Following TI's d...
overall, this PR is good enough to merge. There is only a few of review for naming convention, and a request to remove the allocated fifo reset in unplugged event.
please remove the prefix dcd_ it is easy to mix up with public API of dcd.h
simple if should stay in the same line, it is just my preference. This is optional
it is recommended to have prefix _ before static variable, you could drop the dcd as well to simply _allocated_fifos
[hathach/tinyusb] New branch created: fix\-msp430\-warning
Describe the PR
fix #465 warning with msp430 gcc to 9.2.0.050, also update ci cached toolchain as well
The changes to src/class/net/net_device.c seem unnecessary. The file could remain unchanged and the project still compiles without issue.
Which board and gcc version you are building. revert those changes still cause issue on multiple target e.g SAMD51/SAMD21/stm32f4 etc .. Hmm although we did declare notify with CFG_TUSB_MEM_ALIGN, I even go further with
CFG_TUSB_MEM_SECTION CFG_TUSB_MEM_ALIGN static union
{
uint8_t rndis_buf[120] __attribute__ ((aligned(4))) ;
struct...
Great, thanks for the PR and quick update
with this PR merged, persistence is coming next :) one of the lines here was related more or less (would have failed without it)
Maybe should clarify :)
This line here was missing: https://github.com/hathach/tinyusb/pull/454/files#diff-371e8160b188a80c1a3821c75d194adfR289
Code without it is assuming a clean peripheral registers and just setting the new values without clearing their masks before, which with persistence was causing previous FIFO to be 2, new FIFO to be 4 and resulting in 6, which first does not exists and second is not the correct value :)
Describe what the question is
Hi,
I didn't see forum or something of a wiki, so asking maybe a simple question regarding getting tinyusb integrated into a stm32 project. If there is a better medium, please let me know.
I have been evaluating USB on stm32h747 device on the stm32h747eval board - specifically cdc and msc. The ST driver/stack with freely available arm eabi gcc toolchain seems to perform poorly. This has been confirmed by ST. So, I'm trying to see if tinyusb stack m...
OK, the difference is that I'm using:
gcc version 9.2.1 20191025 (release) [ARM/arm-9-branch revision 277599] (GNU Tools for Arm Embedded Processors 9-2019-q4-major)
There doesn't seem to be much choice; it feels inelegant to workaround the misguided compiler, but I don't have a good alternative that isn't convoluted. Thanks for your patience.
This looks more like bug report than a question, please update the post to use bug template, and also change the title to better reflect your problem.
OK, the difference is that I'm using:
gcc version 9.2.1 20191025 (release) [ARM/arm-9-branch revision 277599] (GNU Tools for Arm Embedded Processors 9-2019-q4-major)There doesn't seem to be much choice; it feels inelegant to workaround the misguided compiler, but I don't have a good alternative that isn't convoluted. Thanks for your patience.
I admit the changes is a bit odd to look at, maybe we could do it better later on by changing the declaration of noti...
related to #384 and I think this approach is even better than the current draft by #385 .Thanks for opening the issue. I will revise and put them together in a week or so for this feature.
[hathach/tinyusb] New branch created: fix\-strict\-prototype
Describe the PR
fix strict prototype
This is going to sound stupid, but while I was cleaning up the project files and build scripts to make a tarball for bug submission - it now works! The only change in the source files was in the main.cpp file where I moved a printf statement... I'll monitor it for a few days to make sure things are stable.
But to answer your questions -
I don't have a supported board handy - but with minor edits to stm32h743eval files, and I can get the stock cdc_msc example code to work on stm32h747eva...
I am glad you work it out, that is why I always ask user to reproduce the issue with stock example + minimal changes on the supported board. In general, I can only help with usb issue, any customization with mcu clock, hw modification, flash config etc ... is out of knowledge. My advice whenever you have an issue, just start again from stock example, and try to do bisect from that.
Closed since this issue is resolved.
Describe the PR
Constraint was incorrect for ISO endpoint as stated in TODO,
Additional context
If applicable, add any other context about the PR and/or screenshots here.
Describe the PR
For ISO endpoint driver has to specify when data
is to be transmitted (odd or even frame).
Currently code was not updating this bit resulting in
data being sent every other frame.
If interval was 1ms full data packed was sent every 2ms, and
ZLP was sent in between.
Additional context
I'm not sure if second part (handle_epin_ints) is really needed.
[hathach/tinyusb] New branch created: fix\-nrf\-unplugg\-isr\-event
Thanks for the PR, I am planning to move these checks into usbd_edpt_open() later on as well.
Describe the PR
- correct isr context for nrf DCD_EVENT_UNPLUGGED
- also rename debug lookup to prevent conflict
[hathach/tinyusb] New branch created: move\-dcdconnect\-to\-dcdinit
Describe the PR
Some MCU like nRF5x doesn't want to enable Pull-up when init. Pullup is preferably enabled within VBUS power detection, this help nrf5x to save (a little) more power than needed. Since nRF5x mostly run by itself on battery with bluetooth, this can help a bit (if any). In general, I think it may be just better to leave the dcd_init() to decide rather than usbd to force pull-up.
https://github.com/hathach/tinyusb/blob/master/src/portable/nordic/nrf5x/dcd_nrf5x.c#L808
...
[hathach/tinyusb] New branch created: add\-app\-driver\-2
Describe the PR
- Add app driver as suggested by #467, more preferable than #385
- Fix #384 , Fix #467
Additional context
If applicable, add any other context about the PR and/or screenshots here.
@igrr @me-no-dev
great, the PR look great, though I have no clues how these odd/even bit are used. Let's wait a couple of days to see if others has any suggestion then we could merge this.
tenary operator is more preferred, but it is only a minor suggestion.
in_ep[epnum].DIEPCTL |= (odd_frame_now ? USB_OTG_DIEPCTL_SD0PID_SEVNFRM_Msk : USB_OTG_DIEPCTL_SODDFRM_Msk);
We can definitely work with that 👍
I'm glad you're working on isochronous endpoints. I think there are a few more changes to do to get a full iso support. But these little change seems to get them working already. 👍
To focus on this PR's content: As you already mentioned I do not think that we need to set the EONUM bit within TXFE interrupt. Since a full iso transfer has to be sent within one frame, it's not useful to change this bit again. Did you try to run it without the changes to handle_ep_ints? I can not test it mys...
@duempel my USB knowledge is very limited so I'm not sure what are the constraints on ISO. I simply added this code in two places just in case. My application did not use second path as whole data frame is sent in one packet.
I can drop it and if later some finds out that ISO packets needs this frame bit set in interrupt maybe some of you will remember and add it accordingly.
As to OUT ISO, I'm not there yet.
@hathach Am I right that this approach, compared to #385, does not allow the list of drivers to be defined dynamically, and we still need to know the list of drivers at compile time?
This option is certainly better than not having any way to customize the driver list, so 👍 on that. However the callback option still seems to be preferable since it allows both compile-time defied list of custom drivers, or run-time defined list of custom drivers.
@hathach how does the stack react if you do not get
dcd_event_xfer_complete? Will you schedule a new transfer or has the previous to be finished first? This is very important to iso endpoints because it can happen that we do not get the full transfer transmitted within one frame and in this case device driver won't invokedcd_event_xfer_complete. We should introduce incomplete transfer interruptsIISOIXFRandIISOOXFRto isochronous endpoints maybe.
The stack should still wait fo...
[hathach/tinyusb] New branch created: fix\-nrf\-disconnect
Describe the PR
nrf disable pull-up does not generate any hw event to notify the stack
I think it's enough for most user cases.
but that is not a callback or did you link to the wrong place?
Sorry I meant to integrate this but got side tracked quite a bit.
right, I forgot what I have said, and thought it is merely for polling, will add one callback later on
I also did a bit of research concerning the ISO EP even/odd frame bit. This topic was heavly discussed here, where also a flowchart of how to handle it was presented. This might be of interest to you if you haven't seen it already!
Set up
I compiled the webusb_serial example for the STM32L053 discovery board.
- PC OS : Ubuntu 18.04.4
- Board : STM32L053 discovery
- Firmware: examples/device/webusb_serial
Describe the bug
CDC is working as expected (ttyACM0 device is available and data is sent back on the CDC device and is also visible on the webusb example website)
But if I enter something on the webpage which should be transmitted to the board, it is not sent back. It seems that no d...
You could enable the stack debug log with LOG=2 It provides internal states of the stack for analyzing. https://github.com/hathach/tinyusb/tree/master/examples#log
I don't have L053 to test with, but I will try to help you with the progress. Would you mind submitting the PR to add the board, that will help other with actual hardware to verify/test with.
@hathach Am I right that this approach, compared to #385, does not allow the list of drivers to be defined dynamically, and we still need to know the list of drivers at compile time?
This option is certainly better than not having any way to customize the driver list, so on that. However the callback option still seems to be preferable since it allows both compile-time defied list of custom drivers, or run-time defined list of custom drivers.
@igrr yeah, this approach is very sta...
I used the stm32l0538disco board which is already part of your source tree.
This is the debug output when the controller starts and is attached to the USB port of my PC. I think this is the normal enumeration process:
<pre>
USBD init
CDC init
VENDOR init
USBD Bus Reset
USBD Bus Reset
USBD Setup Received 80 06 00 01 00 00 40 00
Request Type: 80 Get Descriptor Device
Queue EP 80 with 18 bytes
USBD Xfer Complete on EP 80 with 18 bytes
Queue EP 00 with zlp Status
USBD Xfer C...
I don't see anything abnormal in the log. Did the webusb landing page appear, and you could connect/pair with device. The webusb is still also experimental in chrome. Could you pull out another PC preferably on different OS to test with.
Landing page appears and it is also possible to connect/pair with the device. And also the vendor control requests are working fine. But there seems to be no callback/event/... for received data.
I will try it on another PC.
it is probably udev, permission, and set-up things. It should probably work on windows.
@hathach I can try to give an example:
- The ESP32 camera driver is a separate component that can benefit from having it's own webcam driver support that can be loaded if the component is in the project and enabled.
- ESP32-Arduino will also be able to load it's own custom drivers (or the above camera driver) independent of what is precompiled from ESP-IDF.
I am sure @igrr could fill in more cases :)
I just tried it on Windows and it really works there. So, Windows and Linux are somehow handling this WebUSB stuff differently.
In case the data is not sent fast enough, dcd should detect this and let the stack know so that it could mark the endpoint as ready for next transfer.
Alright, our current ISO handling is not safe in this point. It can happen that we do not send out data and stack never gets a complete event. I'll write an issue to keep this in mind.
Though I don't think we need an extra INCOMPLETE event, ISO data is time-sensitive (audio/video), if it is sent late, it is just better to not send at ...
it is not a surprise, it is probably permission things ( check your udev and chrome docs etc ..) The feature is still experimental and may or may not work on some setup.
I'm not sure if this is a OS thing. Because I already have WebUSB running together with an STM32L401 controller and your stack.
Yes, pretty much what @me-no-dev said — the main reason for dynamic registration is to not centralize the knowledge of all the custom drivers in one place.
Which is not easy from the build system perspective — how to allow 3rd party components to contribute entries to CFG_TUD_APP_DRIVER_HEADER?
As an example, we have a virtual filesystem (VFS) component in IDF, which allows dynamic registration of filesystem drivers. The filesystem driver can be provided in a third party component, and VFS ...
thanks @igrr , it is a valid point to support 3rd party drivers. IDF is much more comprehensive that what I have been done so far. I will get back to the #385 . Thanks for explanation.
This is a follow up to #400 and #401
Is your feature request related to a problem? Please describe.
Within #400 and #401 it's been discussed if there is a need for CDC to work without the data terminal ready (DTR) bit being set. Usually terminal application will set this bit to tell the data communication equipment (DCE) device that the data terminal equipment (DTE) device is present. But this is no standard and there are cases in which the DTR bit is not set by DTE:
- A lot...
Thank you for your PR, there may be more works to support ISO, but this is already a great starter.
Thank you everyone of participating in the helpful discussion,hopefully we could got ISO support soon enough.
do your udev include the permission for VID/PID of the example ? If not, please try to add it, it may be needed for chrome to claim the interface.
This updates the lib/lwip submodule to STABLE-2_1_2_RELEASE (2018-11); tinyusb is currently using STABLE_2_1_0_RELEASE (2018-06). It seems worth adopting the newer version to gain the improvements/bug-fixes.
Thank you for the sum-up issue, this is definitely needed when doing PR later on :+1:
Hi!
Is there any progress on this issue/PR? I have just hit this problem on a project, where we have USB CDC and vendor class. It appears linux kernel sets the configuration, and some libraries (libusb) suggest we need to do set_configuration before other operations (not doing that fails other calls, as it depends on it to set some internal structures).
We have hotfixed it with the following patch (though it is VERY ughly, it seems to work so far):
Index: src/device/usbd.c
IDEA add...
Application is positioned first before built-in this allows overwriting built-in driver.
[hathach/tinyusb] New comment on pull request #385: support class drivers implemented by application
Application driver open() is invoked first before built-in one to allow overwriting behavior.
@me-no-dev @igrr @HiFiPhile the PR is ready for review, it may take a couple more PRs to complete, but let's me know what you think.
@LadislavOzobot latest commit shouldn't have issue with it, if you are not at latest, try to update it first.
I prefer to write uint8_t usbd_app_driver_get_cb(usbd_class_driver_t const* app_driver) TU_ATTR_WEAK;
I prefer to test _app_driver_count, since only the linker knows the existence of usbd_app_driver_get_cb, this if{} won't be optimized out if usbd_app_driver_get_cb not exist.
that would be uint8_t usbd_app_driver_get_cb(usbd_class_driver_t const** app_driver), which I find pointer to pointer is a bit annoying.
usbd_app_driver_get_cb allow LTO to optimize out the code, though it is much the same with _app_driver_count, gcc is smart enough to figure it out with either.
gcc is smart enough to figure it out with either.
Seems gcc is smarter than IAR :)
app_driver itself is an array, you don't need pointer to pointer of an array.
can you try to enable LTO option on IAR, I think IAR can only be smarter than gcc, they charge premium for that
Yeah, but you still need the pointer-to-pointer in the signature, I just won't tell you why :smiling_imp:
I think IAR can only be smarter than gcc
I've already enabled every options. Frankly their optimization is not so impressive, many times with const restrict keywords it re-read everything from the stack.
Their advantages are functional safety, MISRA and easy to use, for example to write a ram routine instead of fiddle with linker options and copy the routine with memcpy, I can use simply the keyword __ramfunc.
yeah, MISRA is a super nice thing to have.
Thanks, looks good to me.
[hathach/tinyusb] New comment on pull request #385: support class drivers implemented by application
thank you everyone for participating to the PR
implemented by #385
[hathach/tinyusb] New branch created: fix\-bt\-warning
Describe the PR
replace dcd_edpt_open by usbd_edpt_open
Describe the PR
Wrong FIFO was flushed in dcd_edpt_stall().
(epnum - 1) should only be used when accessing DIEPTXF registers.
For DIEPCTL and GRSTCTL epnum is correct index.
hmm, I think the current code may be correct, the open did config the FIFO with epnum - 1.
https://github.com/hathach/tinyusb/blob/master/src/portable/st/synopsys/dcd_synopsys.c#L593
I am not entirely sure though. If anyone else does not have any suggestions, I will try to pull out the manual for verification later
As I mentioned enum -1 is correct for DIEPTXF registers.
For other it is not, see few lines below in same function.
https://github.com/hathach/tinyusb/blob/b0f617ba209110a4d5f144f46ccfc9f2cbfa25e7/src/portable/st/synopsys/dcd_synopsys.c#L598
As I mentioned enum -1 is correct for DIEPTXF registers.
For other it is not, see few lines below in same function.
https://github.com/hathach/tinyusb/blob/b0f617ba209110a4d5f144f46ccfc9f2cbfa25e7/src/portable/st/synopsys/dcd_synopsys.c#L598
Sorry, I missed the context, and jump right to the diff. Will pull out the manual soon enough :)
Superb !! Thank you very much @kasjer, I could imagine you have burnt your weekend to spot this off-by-one fifo :+1:
Describe the PR
Endpoint close was implemented only in one driver so far.
This function is needed for interfaces with several alternate settings.
The way FIFO is allocated in dcd_edpt_open() allows to correctly close
only one IN endpoint (the one that was opened last).
Stall and close share code as was suggested by TODO comment.
Additional context
FIFO allocation schema could be changed to allow closing endpoints.
It could be that FIFO allocation is not done during open ...
I am using TinyUSB Arduino. My PC software requires me to provide a USB interface name. But TInyUSB can only set three strings: Manufacturer, Product Name, Serial number.
https://github.com/adafruit/Adafruit_TinyUSB_ArduinoCore/blob/2f485087fd64d3fafffad414f0dc316c685d33d9/Adafruit_USBD_Device.cpp#L361-L387
According to the standard USB HID protocol, it should be possible to include an interface name just like the one used in this code.
https://github.com/ARMmbed/DAPLink/blob/master/sour...
Hi
MCU:stm32h743
Demo:CDC_MSC_FreeRTOS
I rewrite the msc_disk.c with ST HAL sd card driver.But it's RW speed is too slow,at about 200K/S
Is it the TinyUSB issue or ST HAL sd card driver issue?
what RW speed that the tinyusb msc suppose to be?
Thank you.
you should test ST HAL SD card driver and then report back the max speed for writing you have there.
You can improve the USB transfer speed by adjusting the endpoint buffer size in tusb_config.h. It is set very low by default to fit most microcontrollers. But for the H7, you can bump this value up higher to improve throughput. Adjust to your liking, for example:
// MSC Buffer size of Device Mass storage
#define CFG_TUD_MSC_EP_BUFSIZE 4096
@kasjer That depends on how you define near future ;). I eventually would like to but since i do this in my spare time it will take a little longer. Since uac is a bit more complex i am sure the review process will also be demanding. There are also some more features from the tinyusb stack i would need e.g. an implementation for closing EPs. This would be my next point working on. Finally, i only have a custom made board with microphones at my disposal so i can not test for anything else (e...
Hi,
Certainly, i am happy if my code would be of use! I ran out of spare time recently so the work got stuck a bit. I already have a further developed version on my local repo available (which i have to push). From this point forward there sould not be much missing but to actually send audio data. Audio requests are already working and tested. The FIFOs within audio.c are not tested so far.
The driver right now supports at maximum one out, one in, one feedback, and one interrupt EP. T...
Thanks @PanRe it would be great to have you latest code.
I was so impressed with what I've seen, I can't wait to see it all.
best regards
Jerzy
you should test ST HAL SD card driver and then report back the max speed for writing you have there.
Thank you.
The TinyUSB is working well.But the ST HAL SDcard driver cannot working when using dma type function.I am still working on it
@PanRe thanks for sharing.
I see that there are a lot of tabs in the code. Eventually someone will reformat it and then it will look like someone else did the hard work for audio.
It would be great if you could make just one more commit with tabs removed to preserved creator in the future.
best regards
Jerzy
Sure, but it will take a little time! Is there a reference on how the formating should look like? A definition or smth alike.--Diese Nachricht wurde von meinem Android Mobiltelefon mit GMX Mail gesendet.Am 20.08.20, 10:23 schrieb kasjer notifications@github.com:
@PanRe thanks for sharing. I see that there are a lot of tabs in the code. Eventually someone will reformat it and then it will look like someone else did the hard work for audio. It would be great if you could ma...
Hi,
i am not following tests procedures here, but using my library for esp32 S2 on arduino i could achieve this performance:
-
this example is using RAM disk and internal flash:

-
this example is using SD card over SPI:
allows to correctly close
only one IN endpoint (the one that was opened last).
This is good start, we can focus on closing random endpoint later on when other thing work.
Stall and close shar...
Thanks for the PR, it looks good to me. ISO is troublesome (hence it is last to got supported), there is no surprise that it will take several more PRs to get it running. Let's leave this open for a more few days to see if anyone else have any other idea.
closed since this is not tinyusb issue but ST HAL driver one, and I don't have any knowledge with ST Hal to help with. If you want to benchmarch the stack performance, you should do it with msc ramdisk by reporting large enough size, and faking msc read/write API.
Thanks for updating the PR, there is still one request left though to optimize the USB transfer.
This is still not ideal since we may not transfer all available bytes e.g flush send out 5 bytes, but the complete_cb() fill more 200 bytes just a few statement later. Ideally it should be
if ( ep_addr == p_cdc->ep_in )
{
// invoke transmit callback to possibly refill tx fifo
if ( tud_cdc_tx_complete_cb ) tud_cdc_tx_complete_cb(itf);
if ( 0 == tud_cdc_n_write_flush(itf) )
{
// There is no data left, a ZLP should be sent if
// xferred_bytes is ...
Hi all,
I hope this is a good place for a question like this - likely it's a matter of my own naiveté as relatively inexperienced programmer... but possibly it also is about how the tinyusb Getting Started info could be a bit clearer.
I've detailed the steps I've taken in an attempt to get the webusb_serial example up & running in the STM32CubeIDE, so that I learn how to add webusb functionality to projects I've already been developing in it; the full text of these steps I've shared wit...
This pull request adds support for USB device mode on SAMD11 family of devices. The SAMD11 devices use a USB peripheral which is binary compatible with the SAMD21, so changes are minimal, and the SAMD11 family use the SAMD21 TUSB driver.
This requires https://github.com/hathach/microchip_driver/pull/1, which adds the SAMD11 Atmel Software Framework files to bring up the SAMD21.
Thank you for PR, it looks like a small changes, but surely people will it very useful for optimizing the cdc throughput.
hi hi, thanks for the PR, the CI build failed is due to my own out-of-sync mcu driver with samg55, I will push a fix right away.
[hathach/tinyusb] New branch created: fix\-samg55\-build
Describe the PR
samg55 bsp & mcu seems to be out of sync
Thank you for your PR.
- It is totally my fault for samg55 build issue, could you please pull/merge/rebase/push-force with master after #491.
- Add
-DCFG_EXAMPLE_MSC_READONLYto board.mk of samd11 this will help to get msc example running in readonly mode (and pass CI build for those example as well).
you could add -DCFG_EXAMPLE_MSC_READONLY to allow using ROM instead of RAM for read-only mass storage device. It can still be enumerated and show up the readme though PC won't be able to change the disk and/or readme contents. Here is how other small chip define this.
https://github.com/hathach/tinyusb/blob/master/hw/bsp/lpcxpresso1347/board.mk#L9
The macros is kind of required as well to pass CI build test.
Ideally we should add a new OPT_MCU_SAMD11, but it is not an issue. I will do a follow up later on. There is not much differences.
This PR adds support for persistent USB init for ESP32S2. This feature allows CDC to not re-enumerate when switching to and from Download mode. This feature should only be used with CDC and/or RT_DFU. Example is also provided.
WIP: For this example to work, a few fixes are needed in ESP-IDF. We have those in review currently and I will remove the WIP prefix once they are public. We can in a mean time use it to discuss the changes and make any necessary adjustments.
@ktemkin awesome, thank you :)
Thanks! I just rebased and plan to apply the other (MSX) fix later today. :)
Glad to be able to contribute! tinyusb’s been very useful to us so far, so it’s good to have a chance to contribute to it. :)
(As an aside, I must have been tired last night when juggling submodules; I just noticed that I used my fork’s master instead of creating a nice feature branch. Feels silly, but I suppose it works just as well.)
Bit of a complication -- for the SAMD21, both ROM and RAM are pretty limited (16KiB flash, 4KiB SRAM). I've been able to fit tinyusb + some very useful stuff, but I don't think we're going to find an optimization that makes all of the examples work in the limited space (e.g. with _MSC_READONLY, the MSC examples now fit in RAM, but not in ROM).
Do you have a suggested workaround -- perhaps a way to disable those examples for a particular board?
Thanks! I just rebased and plan to apply the other (MSC) fix later today. :)
Glad to be able to contribute! tinyusb’s been very useful to us, so it’s good to have a chance to contribute to it. :)
(As an aside, I must have been tired last night when juggling submodules; I just noticed that I used my fork’s
masterinstead of creating a nice feature branch. Feels silly, but I suppose it works just as well.)
Thanks, I am glad you find it useful. No problem at all with the sub...
Thanks for the PR, I will do the follow up to add OPT_MCU_SAMD11 and skip CI build for example that need more than 16 KB ROM/ 4KB RAM later on.
[hathach/tinyusb] New branch created: followup\-490\-samd11
Describe the PR
Follow up to #490 skip ci build for example that need more ROM/RAM could fit into SAMD11
Thank @me-no-dev , I convert it to draft, you can convert it back to ready when it is. Will review this in the next week.
Thanks @hathach !
If you want to give this a shot, there are two files in esp-idf that you need to edit. After that, you need to load the firmware once over UART and from then on can use the CDC instead. For Saola, you can go into the example folder and idf.py -p [port] flash monitor, given that you have the latest ESP-IDF and the changes applied and in PATH.
Here are the fixes:
- USB CLK will always reset
<img width="502" alt="Screenshot 2020-08-22 at 16 22 09" src="https://user...
Set up
[Mandatory] Provide details of your setup help us to reproduce the issue as quick as possible
- PC OS : Windows 10
- Board : stm32h743,designed by myself
- Firmware: examples/device/cdc_msc_freertos
my project is cdc_smc_freertos project.
The msc device is working well with sd card while cdc function didn't.
tud_cdc_connected() return fail in cdc task which means usb is unconnected,but I do connect the usb with computer.Is it a bug?
Does someone have ...
any reason not to use chip_usb_set_persist_flags(USBDC_PERSIST_ENA);?
similarly chip_usb_get_persist_flags() & USBDC_PERSIST_ENA ?
any reason not to include esp32s2/rom/usb/usb_persist.h which defines the USBDC_PERSIST_ENA constant being used? Similarly any reason not to chip_usb_get_persist_flags()?
IDF-Monitor will leave DTR and RTS LOW
Thanks for the diff on that, I was looking for how to fix that in my local IDF copy since monitor is a bit broken in CDC mode.
was not public when code was written
see above and not any different
i guess you got the idea by now.
ahh, it looks like it is available now at least via headers. I've been testing this change locally in my IDF replacement wrapper and so far it works nicely.
BTW chip_usb_get_persist_flags() reads the same register, but slower :)
@atanisoft I do not guarantee that the monitor changes are final, but those worked with CDC and all UART boards that I tried.
interesting, any idea why rom code is slower than direct register access?
Hi, I'm trying to send sysex messages from tinyusb to a connected computer.
However, I can't seem to figure out the proper way to do it. I tried using tud_midi_send with the proper USD MIDI event packets:
tud_midi_send((uint8_t[4]){0x04, 0xF0, 0x00, 0x01});
tud_midi_send((uint8_t[4]){0x07, 0x02, 0x03, 0xF7});
However, MIDI Monitor shows that this comes across as invalid data:
{0x03, 0xB0, 0x5A, (result >> 12) & 0xF});
tud_midi_send((uint8_t[4]){0x03...
it's working after I remove tud_cdc_connected() in the cdc task.
But it cannot send data by using tud_cdc_write() after I recieve the data.(buf is non-cacheable)
uint8_t count = tud_cdc_read(buf, sizeof(buf));
tud_cdc_write(buf,count);
[hathach/tinyusb] New branch created: improve\-midi
@theacodes I have revised and improve midi driver, would you mind trying it out here to see if that fixes your issue https://github.com/hathach/tinyusb/tree/improve-midi
Note: MIDI driver is based on cdc, but since it is much less used, it also got less PR/update than cdc.
Describe the bug
It is already known in STM32 community, that F2 and F4 MCUs fail to work with USB334x (USB3341, USB3343, USB3346, USB3347) (and maybe others) external PHYs in HS mode and fall back to FS. It is timing problem on ULPI, more in module 2 in USB334x errata. Workaround was introduced by enabling bit USB_OTG_DCFG_XCVRDLY as mentioned in [this community forum thread](https://community.st.com/s/question/0D50X0000...
thank you for opening the issue with useful and helpful reference link. Currently I don't have any of above hardware combination to start working on a PR. I will try to find one later on.
Seems that branch helps with the simple messages above:
y
([176, 90, 1], 0.0)
([176, 90, 2], 0.000307125)
([176, 90, 3], 0.000307125)
y
([176, 90, 1], 1.173538513)
([176, 90, 2], 0.000331076)
([176, 90, 3], 0.000331076)
y
([176, 90, 1], 0.9214775070000001)
([176, 90, 2], 0.000272757)
([176, 90, 3], 0.000272757)
And with SysEx
y
([240, 0, 1, 2, 3, 247], 0.0)
y
([240, 1, 1, 2, 3, 247], 2.854390695)
y
([240, 2, 1, 2, 3, 247], 0.6649876130000001)
y
([240,...
@theacodes I am glad that helps you, let's me know if you still have any other issue with MIDI driver. You could keep this issue opened until you got it all sorted out. Then we could merge that midi branch into master.
PS: I am noob with MIDI and instrument therefore the driver lack needed testing.
Describe the PR
Enhance MIDI driver, help to solve #495
- fix #436 tud_midi_rx_cb() not invoked
- fix xfer_cb() not handle ep in
- add ZLP if needed
maybe help with #377 (worth a try)
Sounds good. Happy to keep testing the MIDI driver, and feel free to cc me
on the PR for this. :)
On Mon, Aug 24, 2020 at 1:34 PM Ha Thach notifications@github.com wrote:
@theacodes https://github.com/theacodes I am glad that helps you, let's
me know if you still have any other issue with MIDI driver. You could keep
this issue opened until you got it all sorted out. Then we could merge that
midi branch into master.PS: I am noob with MIDI and instrument therefore the driver ...
which terminal software you are using, try to use other one that set DTR on connection if possible. Currently TinyUSB use that as indication for connected signal. There is lengthy discussion on this #401 . And issue #482 for implementation approach but I currently don't have the time to work on this.
Hi @PanRe I createad pull request towards you branch that has some small fixes here and there.
I managed to run mono and stereo microphone using you code.
There is one thing that I want to change.
I need just one FIFO for stereo channels.
Data that I have is already PCM data (left and right channel interleaved).
With current implementation I feed left and right FIFOs only to put in together again and since I use
operation system with mutexes filling endpoint buffer with data from two FI...
Thanks a lot thats good news! Unfortunately I am not able to look at the code the next days... But I will as soon as possible!Regarding the fifos, my intention was to offer both possibilities/modes, a fifo for every channel (as a test and quick and dirty possiblity) and one where the user can use his own "encoding" into the ep buffer (exactly what you ment). If you want to use this, set the tx fifo size to zero in the definitions. It might be, that there are a few fixes necessary ...
Set up
[Mandatory] Provide details of your setup help us to reproduce the issue as quick as possible
- PC OS : macOS 10.14.6
- Board : stm32f407disco
- Firmware: examples/device/webusb_serial
Describe the bug
I've compiled the webusb_serial example as described in the readme and uploaded it with STM32CubeProgrammer. Then, with the board powered via the same USB connection (with an AC charger brick) and the mini-USB port connected to my laptop, the Chrome p...
You could enable the stack debug log with LOG=2 It provides internal states of the stack for analyzing. https://github.com/hathach/tinyusb/tree/master/examples#log
may related to #481
[hathach/tinyusb] New branch created: bsp\-itsy\-nrf52840
Describe the PR
add itsybitsy nrf52840 board support
Alright I've got the logging working; was a bit of a discovery for me to realize that I needed an extra serial-to-USB converter, and to find out which pins on the board I needed, and that the datarate should be 115200.
Here is the output; at the end is where I tried to connect by clicking the Connect button in the browser.
By the way: I have another piece of tinyusb/webusb hardware here that does immediately connect and work (https://webusb.hackz.one/)
USBDUSBD init
CDC init
VENDOR...

this is how my board shows up in System Information
USBD Setup Received 01 0B 00 00 02 00 00 00
Set Interface
VENDOR control request
Stall EP0
Seem like it stall the SET_INTERFACE, I don't have a mac to test with. I will try to revise the issue and give a fix for you to test whenever I could.
I'm porting the USB Host example (CDC + MSC) to the stm32f4discovery board. Many modifications have been done in the BSP layer to support this use case.
It does not work yet, the main problem I'm currently experiencing is that the ISR are not being triggered. Any help would be welcome.
Perhaps related? My setup is a late 2013 Macbook Pro running macOS Mojave 10.14.6:
https://github.com/tessel/node-usb/issues/277
superb, thank you. I will check this out next week :) . Host stack doesn't receive much development recently, may need extra works than device to port anything :)
Hello, I want to use The Webusb of TinyUSB to realize program download, which requires hardware DTR and RTS control. Currently, I can't find the function to get the streaming signals of DTR and RTS in real time by looking up the program by myself. I would like to ask which function can achieve the real-time acquisition of the streaming signals of DTR and RTS?
do you mean webserial? in that case you should look at the specifications from https://wicg.github.io/serial/
The PR looks great, It will be perfect if you could also
- provide more descriptions for example in main.c
- provide more description of persist mode feature in dcd esp32s2
- Correct the in_isr value in the fake dcd event
- This is optional, but I like the example to be renamed to
esp32s2_cdc_persistor maybe simplyesp32s_cdc_persistif the S3 also support USB later on.
the 3rd argument is in_isr which should be false in this case, else it will use the freeRTOS fromISR() API version.
Could you put an few line of description on what is the persist feature and how it work e.g how to enable persist mode. This feature is not obvious with others.
same as above 3rd arg should be false
Thanks @hathach !
If you want to give this a shot, there are two files in esp-idf that you need to edit. After that, you need to load the firmware once over UART and from then on can use the CDC instead. For Saola, you can go into the example folder and
idf.py -p [port] flash monitor, given that you have the latest ESP-IDF and the changes applied and in PATH.While in
monitorand over CDC, you can hitCtrl+T Ctrl+Ato rebuild and reflash, without getting out of the monit...
do you mean webserial? in that case you should look at the specifications from https://wicg.github.io/serial/
yes, webserial.
I have read the relevant information in this website provided by you, but still can not solve the DTR and RTS signal I want to get, still thank you for your prompt.
Maybe this:
https://github.com/hathach/tinyusb/blob/master/examples/device/webusb_serial/src/main.c#L169
I tried to get the DTR and RTS control signals using this interface function, but failed. Thanks again for the tip
Maybe this:
https://github.com/hathach/tinyusb/blob/master/examples/device/webusb_serial/src/main.c#L169I tried to get the DTR and RTS control signals using this interface function, but failed. Thanks again for the tip
there is no DTR/RTS equivalent for webusb, the pair process is between browser and OS. You need to implement the connect like the web example to send connect/disconnect event. You may want to look at webserial which use standard cdc instead.
@hathach on the example name :) yeah, I also wondered a bit on how to name it. esp32s is actually a module that AiTinker are making and might not be true for future S chips past S3. I basically opted because of the dcd driver connection :) I don't mind renaming. Any better ideas?
Maybe this:
https://github.com/hathach/tinyusb/blob/master/examples/device/webusb_serial/src/main.c#L169I tried to get the DTR and RTS control signals using this interface function, but failed. Thanks again for the tip
there is no DTR/RTS equivalent for webusb, the pair process is between browser and OS. You need to implement the connect like the web example to send connect/disconnect event. You may want to look at webserial which use standard cdc instead...
- PC OS : Windows 10/
- Board : stm32h743 ,my own board
- Firmware: examples/device/cdc_msc
Describe the bug
My project could not support USB warm unplugged since my board doesn't use VBUS sensing pin.(alternative function)
It is only working at the first plug when my board is not powered by USB cable.
Any solution???
So, now I'm confused: webserial is a completely different protocol from "webusb protocol talking to a serial device" (like the webusb_serial example)?
@hathach on the example name :) yeah, I also wondered a bit on how to name it.
esp32sis actually a module that AiTinker are making and might not be true for future S chips past S3. I basically opted because of the dcd driver connection :) I don't mind renaming. Any better ideas?
Ok then just name it esp32s2_cdc_persist for now, we can always rename it later on.
Set up
[Mandatory] Provide details of your setup help us to reproduce the issue as quick as possible
- PC OS : Windows 10
- Board : stm32h743
- Firmware: examples/device/cdc_msc
Describe the bug
I am using latest ST sd card HAL Driver .I found out I have to set up usb_device_task with a high priority.Otherwise the TinyUSB won't work if I read sd card and open cdc port at the same time.
@hathach I have discussed and agreed with our IDF team to move this code DCD. Do you have anything against?
Hello,
Right now @kasjer and i are working on finalizing a working version for an audio 2.0 driver. During tests a possible bottleneck came up and i wanted your opinion on this issue. In general a FIFO is necessary in order to decouple the sampling process from the USB transmission process.
So the setup right now (e.g. for a microphone) is: Samples -> FIFO -> EP buffer -> USB FIFO, where -> means "put into".
As how tinyUSB is set up right now, all EP buffers are considered to be lin...
Describe the PR
Updated host stack as proof of concept, can mount msc + hid keyboard on both ehci and ohci.
Additional context
Still lots of work with usbh and hcd
As previously discussed, I'd like to share ideas how we could solve the DTR bit problem within CDC class. Sorry if you have been waiting for this. I couldn't work on it before since I've been on vacation. 🙈
Describe the PR
This PR is one possibility to solve #482 . The most important change is, that tud_cdc_n_connected(itf) is not checked within tud_cdc_n_write_flush anymore. This will allow us to transmit data, even if the host does not support control line states. In case the DT...
I've seen USB Host has been update in #505. I'm gonna rebase this branch and test again. Should I expect that to work?
Do I understand correctly that your board uses its own power supply and is not bus powered? Maybe this problem is related to #179 . I've also had problems with disconnecting and reconnecting without reseting the controller but had no time to search for the cause yet. Are you using FS or HS peripheral?
So is there a way to get the DTR/RTS control signal in real time By Tinyusb's CDC?
Yes it is. In CDC class there is a callback tud_cdc_line_state_cb which is invoked, whenever a new line state is requested. You can take a look at cdc_msc exmaple. The callback is used there at line L131 to print the welcome message when opening the port.
Thanks for working on the host features. I just took a first look at your PR and it seems like the host controller driver (HCD) is still very empty. Since STM32 Synopsys did not have HCD before it will be a lot of work to add this feature.
Do I understand correctly that your board uses its own power supply and is not bus powered? Maybe this problem is related to #179 . I've also had problems with disconnecting and reconnecting without reseting the controller but had no time to search for the cause yet. Are you using FS or HS peripheral?
Yes,I use FS peripheral.My DTR bit cannot be set by pc terminal.I don't know if it's relative to this issue.
But now I got an another issue.My cdc port will crash after transfer data for c...
I've seen USB Host has been update in #505. I'm gonna rebase this branch and test again. Should I expect that to work?
It works a proof of concept and is able to mount msc and keyboard. Though, there is still lots of work and little of time to work on host stack.
this is OK to move into DCD, as long as the dcd doesn't depend on the BSP (e.g pin/port mapping etc ..).
Hello,
Right now @kasjer and i are working on finalizing a working version for an audio 2.0 driver. During tests a possible bottleneck came up and i wanted your opinion on this issue. In general a FIFO is necessary in order to decouple the sampling process from the USB transmission process.
So the setup right now (e.g. for a microphone) is: Samples -> FIFO -> EP buffer -> USB FIFO, where -> means "put into".
As how tinyUSB is set up right now, all EP buffers are conside...
I find out that if the USB IRQ is running fast than the usb task,the cdc or msc will crash very soon.But I cannot set a high priority with usb task,because there are another tasks which cannot be delay.So,have TinyUSB take this into consideration?Is there any workaround?
Thank you!
I don't see any information that I could analyze and help you with. If you want people feedback, you should fist capture the rtos task switching with freertos trace, segger system view etc ... and post the screenshot here. Also provide the your own analysis & its context such as where the is the time the issue happen and why the CPU is blocked on certain resource.
closed due to lack of user response.
So, now I'm confused: webserial is a completely different protocol from "webusb protocol talking to a serial device" (like the
webusb_serialexample)?
There is two web standard, the
- webUSB is basically bind to any interface of an USB device, much like libusb claim interface. webUSB mostly used with vendor/custom class with either HID or BULK whichever the developer (device + web) like.
webusb_serialis just an example that emulate the use of webusb like an virtual serial. - we...
I don't know any other way to detect disconnection even with STM32 except for the current https://github.com/hathach/tinyusb/blob/master/src/portable/st/synopsys/dcd_synopsys.c#L1001
Most of stm32 devkit support this though. Maybe you should bring this issue to ST community, their engineer could possibly know the answer.
Even if DMA is supported on a microcontroller, my opinion is that tinyusb shouldn't hard-require implementations (at least the non-iso part of the user API) to use DMA. Tinyusb should remain relatively easy to port, and I think hard-requiring DMA complicates this.
I'm not even sure if hard-requiring DMA is wise for iso xfers (STM32F4 and friends come to mind- they support iso, but I recall that nothing says you have to use DMA. And STM should be fast enough to process interrupts).
Oh i never ment to hard require a DMA for ISO EPs. Most often, a DMA can not be used at all e.g. in my case I have 4 microphones and I need to encode them into a PCM stream with the four samples interleaved. This (at least for STM32F4) can not be done by DMA. Converting the EP buffer into a ring buffer, however, would give you a nice opportunity to attach a DMA (in case of an I2S stream where stereo samples are already interleaved).Of course the user API shall not be broken!--Dies...
I don't see any information that I could analyze and help you with. If you want people feedback, you should fist capture the rtos task switching with freertos trace, segger system view etc ... and post the screenshot here. Also provide the your own analysis & its context such as where the is the time the issue happen and why the CPU is blocked on certain resource.
I really don't know what's the detail,I only found out it will stuck in OTG_FS_IRQHandler() infinite loop.
So is there a way to get the DTR/RTS control signal in real time By Tinyusb's CDC?
Yes it is. In CDC class there is a callback
tud_cdc_line_state_cbwhich is invoked, whenever a new line state is requested. You can take a look at cdc_msc exmaple. The callback is used there at line L131 to print the welcome message when opening the port.
Hello, I tried thi...
I don't see any information that I could analyze and help you with. If you want people feedback, you should fist capture the rtos task switching with freertos trace, segger system view etc ... and post the screenshot here. Also provide the your own analysis & its context such as where the is the time the issue happen and why the CPU is blocked on certain resource.
the reasons is usbd_edpt_busy(TUD_OPT_RHPORT, p_cdc->ep_in) always return false after open terminal couples of minutes.
@hathach something is not ok with the latest code. example will not work as expected.
Set up
[Mandatory] Provide details of your setup help us to reproduce the issue as quick as possible
- PC OS : Ubuntu 20.04
- Board : Feather nRF52840 Express
- Firmware: Arduino with FreeRTOS, original issue is filed here https://github.com/adafruit/Adafruit_nRF52_Arduino/issues/565
Note: The race condition only happen if we use an additional mutex. Semaphore or any other type won't cause the issue. Explanation is below
void setup() {
// put your ...
you could take a look at this #507 for how to analyze and troubleshoot your issue. Since you are the only one that could reproduce the issue. These are mostly race condition, and these required to capture the whole picture of resource conflict between running task to be able to determine the root cause.
To make thing even more complicated, here is my drawing of the same process.

Also in your current implementation of the FIFOs i would recommend you not to store a count variable and modify it in both pull() and push() as the count variable might get messed up if two processes modify it (the writing of the count variable is not atomic). Rather i would compute count all time new.
I just remembered why I use count instead of computing it, since I don't want to waste 1 slot of storage, which could be 8/16 bytes depending on the item_size, the count variable is always...
@hathach something is not ok with the latest code. example will not work as expected.
do you know from which commit the issue start up happens, both tinyusb and IDF are moving, it could be a bit difficult to track.
May I suggest using LibreOffice Draw to make these sorts of diagrams :)?
May I suggest using LibreOffice Draw to make these sorts of diagrams :)?
I will try it next time, maybe I should also try to find an app to make my bad writing look prettier :smile: :smile:
you could take a look at this #507 for how to analyze and troubleshoot your issue. Since you are the only one that could reproduce the issue. These are mostly race condition, and these required to capture the whole picture of resource conflict between running task to be able to determine the root cause.
I don't think this is the cause,I have rewrite the FIFO with xStreamBuffer.There is mutex when call tud_cdc_n_write_flush in other high prioity task.
The MSC is also crash just like the...
you could take a look at this #507 for how to analyze and troubleshoot your issue. Since you are the only one that could reproduce the issue. These are mostly race condition, and these required to capture the whole picture of resource conflict between running task to be able to determine the root cause.
The MSC will crash soon even when I use no cdc function( no mutex).If I use cdc funtion at the same time,it will crash sooner.
you could take a look at this #507 for how to analyze and troubleshoot your issue. Since you are the only one that could reproduce the issue. These are mostly race condition, and these required to capture the whole picture of resource conflict between running task to be able to determine the root cause.
it will stuck in here as well (debug) when I read sd card and open pc terminal.
. I am thinking to add an additional mutex to claim the endpoint first before an API() could make a transfer. Ideally it would be 1 mutex per endpiont, but that seems to be a lot of memory for a edge case. Maybe only one general mutex is enough.
github issue is not forum support, it your custom code. You should be able to troubleshoot it.
do you know from which commit the issue start up happens, both tinyusb and IDF are moving, it could be a bit difficult to track.
I did not change anything that would cause that, but I am glad it happened anyway. I have not delved very deep yet, but the data endpoint is not working. Setup packets are OK. OUTs are NACKed. INs seem as well.
github issue is not forum support, it is your custom code, please try to troubleshoot it yourself.
this issue exists when I use unchaged TinyUSB.It's a bug
github issue is not forum support, it is your custom code, please try to troubleshoot it yourself.
I have try to fix this for weeks,I have try to diasble the usb interrupt after every transfer and enable it in usb task.this will solve the cdc crash issue but msc crash issue.
144: loop continue to run !!! At this time, the usbd task should be the one running, since the mutex is released by loop, a context switch should happen, but it is NOT
Sorry, i dont know nrf, but in general FreeRTOS wont switch task if semaphore/mutex can be claimed (dont have to wait to claim it). Maybe yield() after release mutex can be helpful?
144: loop continue to run !!! At this time, the usbd task should be the one running, since the mutex is released by loop, a context switch should happen, but it is NOT
Sorry, i dont know nrf, but in general FreeRTOS wont switch task if semaphore/mutex can be claimed (dont have to wait to claim it). Maybe yield() after release mutex can be helpful?
It does switch task when a mutex is released, however due to the simple implementation of FreeRTOS's priority inheritance, the LP lo...
hihi, sorry for late response, I am scratching my head with another race condition bug, will check this out as soon as I could.
Also in your current implementation of the FIFOs i would recommend you not to store a count variable and modify it in both pull() and push() as the count variable might get messed up if two processes modify it (the writing of the count variable is not atomic). Rather i would compute count all time new.
I just remembered why I use count instead of computing it, since I don't want to waste 1 slot of storage, which could be 8/16 bytes depending on the item_size, the count vari...
@PanRe yeah, I found the unmasked approach is nice as well. Though the power of 2 limitation can be a bit too strict for now. Maybe we can go back to this later on when everything is figured out. Since I don't see much benefit to implement it for now.
Within TinyUSB, the mutex API won't ever be called within ISR, the only osal that invoked in ISR is osal_queue_send(osal_queue_t qhdl, void const * data, bool in_isr) with the sole purpose to put the usb event into the usbd task queue for ...
As i mentioned before, i already figured it out how to handle non-power of two buffer sizes. I did that in my RERO project as well, where i built a ring buffer filled by DMA from USART.
Well we can pospone that surely but as i said then there is this extra copy process necessary since an additional FIFO is needed. If i have time left i prepare a PR for that.
For now, i will wait for @kasjer to finish his tests on the driver and as soon as this is finished i prepare a PR for you to get an au...
Hi there, I'm finishing speaker part. It turned out that for this to work correctly I need feedback endpoint and that is taking much time (also it was not clear to me what Windows really expect from audio device in terms of descriptors and it took me some time
to have it working, while Linux and Mac were happy with what I had originally). FIFO mechanics are not not affecting me, since I made some changes that use just one FIFO for all channels and this change alone drastically reduce CPU ti...
There may be another problem that you should look at. Take a look at lines 143, 148, 154. If i understand it correctly then there is no space in Queue probably and queue wait ticks is set to 0. It looks to me there is some code that are trying to push another message to queue before previous got received. Is it possible?
Line 133 looks good, xQueueSendFromISR, but the others not really.
Yield() every time does fix this particular issue, though I think it isn't the right approach
I think it is the correct way to do it. Loop task will get back to its original priority after releasing mutex, but there is not mentioned it will give control to task with higher priority. You have to call delay or yield to let scheduler to switch task.
There may be another problem that you should look at. Take a look at lines 143, 148, 154. If i understand it correctly then there is no space in Queue probably and queue wait ticks is set to 0. It looks to me there is some code that are trying to push another message to queue before previous got received. Is it possible?
I think it is the default mutex block time https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/master/include/semphr.h#L40 at those 143 148 154. I remembered freeRTOS imple...
As i mentioned before, i already figured it out how to handle non-power of two buffer sizes. I did that in my RERO project as well, where i built a ring buffer filled by DMA from USART.
Well we can pospone that surely but as i said then there is this extra copy process necessary since an additional FIFO is needed. If i have time left i prepare a PR for that.
For now, i will wait for @kasjer to finish his tests on the driver and as soon as this is finished i prepare a PR for you to get...
do you know from which commit the issue start up happens, both tinyusb and IDF are moving, it could be a bit difficult to track.
I did not change anything that would cause that, but I am glad it happened anyway. I have not delved very deep yet, but the data endpoint is not working. Setup packets are OK. OUTs are NACKed. INs seem as well.
Does this also happen with example in this repo, I can help to take a look at the problem, just let's me know your IDF commit hash to make sure...
Hi there, I'm finishing speaker part. It turned out that for this to work correctly I need feedback endpoint and that is taking much time (also it was not clear to me what Windows really expect from audio device in terms of descriptors and it took me some time
to have it working, while Linux and Mac were happy with what I had originally). FIFO mechanics are not not affecting me, since I made some changes that use just one FIFO for all channels and this change alone drastically reduce CPU...
Describe the PR
- fix #507 introduce optional usbd_edpt_claim, usbd_edpt_release which can be ued to gain exclusive access to usbd_edpt_xfer
- With class driver API() that submit transfer to endpoint. Currently
usbd_edpt_busy()is checked before callingusbd_edpt_xfer()e.g
uint32_t tud_cdc_n_write_flush (uint8_t itf)
{
cdcd_interface_t* p_cdc = &_cdcd_itf[itf];
// skip if previous transfer not complete yet
TU_VERIFY( !usbd_edpt_busy(TUD_OPT_RHPORT, p_cdc->ep_in)...
My first guess is that you still need the mutexes in case two or more threads try to write into the buffer since you need to protect the write pointer. The same holds for two or more threads reading from the buffer as all of them try to modify the read pointer. What is getting better is that you not need to block the read function while you execute the write function and vice versa (so you could use two separate mutexes for write and read here).For the rest i need a closer look if...
I submitted an draft PR for the fix at #508 , if anyone is interested, please give a comment/suggestion there.
Set up
[Mandatory] Provide details of your setup help us to reproduce the issue as quick as possible
- PC OS : Ubuntu 20.04
- Board : Feather nRF52840 Express
- Firmware: Arduino with FreeRTOS, original issue is filed here adafruit/Adafruit_nRF52_Arduino#565
Note: The race condition only happen if we use an additional mutex. Semaphore or any other type won't cause the issue. Explanati...
Could you please tell me what's the software you use to analyze USB packets just like the picture shows.
It is segger system view
Could you please tell me what's the software you use to analyze USB packets just like the picture shows.
It is segger system view
https://github.com/hathach/tinyusb/issues/503This my issue.
It shows this after cdc port crash.waht does USB STNC RESET PIPE AND CLEAR STALL means?

It is not about the modification of tinyusb, it is your whole project. What you mentioned is not reproducible by anyone. And you literally didn't provide any information for troubleshooting/anallyzing it. You could try to file another issue for this problem with
- A simplest modification to stock example to reproduce the issue. It is best to reproducible on one of the supported bsp. This makes sure other could reproduce it. Else It could be your own bug in other part of the project.
- P...
Could you please tell me what's the software you use to analyze USB packets just like the picture shows.
It is segger system view
Could you please tell me how to use segger system with TinyUSB?It might be the only way to troubleshoot my YinyUSB issue.
it's against master IDF with the changes above. Funny enough it's triggered often with one board and not the other. Problem is that EP_IN becomes busy (XFER Complete not received) after a few bytes are sent.
// R-Read, S-Space, W-Written, F-Flushed
h
R:1,S:64,W:1,F:1
g
R:1,S:64,W:1,F:1
f
R:1,S:64,W:1,F:1
h
R:1,S:64,W:1,F:1
g
EP_IN BUSY:132
R:1,S:64,W:1,F:0
f
EP_IN BUSY:132
R:1,S:63,W:1,F:0
h
EP_IN BUSY:132
R:1,S:62,W:1,F:0
g
EP_IN BUSY:132
R:1,S:61,W:1,F:0
f...
it's against master IDF with the changes above. Funny enough it's triggered often with one board and not the other. Problem is that EP_IN becomes busy (XFER Complete not received) after a few bytes are sent.
Ok just to be clear, the issue only happens with this PR right ? Maybe we both miss something in the diff
Here is simplified example i am running on esp32 S2 (also FreeRTOS) to see if task are switching with mutex:
int wrsize;
void task(void* p)
{
SemaphoreHandle_t mutex = xSemaphoreCreateMutex();
delay(100);
String text = String((char*)p);
while (1) {
if (xSemaphoreTake(mutex, portMAX_DELAY) == pdTRUE)
{
Serial.println(text);
xSemaphoreGive(mutex);
}
delay(1); // to switch tasks and let setup run
}
}
void setup() {
// put your setup...
Now lets consider my original answer, both task should usae the same mutex:
int wrsize;
SemaphoreHandle_t mutex = xSemaphoreCreateMutex();
void task(void* p)
{
// SemaphoreHandle_t mutex = xSemaphoreCreateMutex();
delay(100);
String text = String((char*)p);
while (1) {
if (xSemaphoreTake(mutex, portMAX_DELAY) == pdTRUE)
{
Serial.println(text);
xSemaphoreGive(mutex);
}
delay(1); // to switch tasks and let setup run, can be delay(1)
}...
@chegewara I am appreciate the time you spent testing out this issue. Though I am bit confused by your 2 example. Can I ask
- Did the Serial.printf() in your esp32s2 also use TinyUSB CDC as nrf52840 ?
- Are you trying to say FreeRTOS implementation is correct, in that case, please visit the link to freeRTOS forum I posted above here is the rtel response. And the code for this function hasn't changed since that anwser.
xTaskPriorityDisinherit when other mutexes are held
Posted by ...
- No, i am not using tinyusb at all in my test code, it was just test of freertos behavior with mutex
- yes, ive been reading all from link you posted at first place and i am also confused, thats why i prepared this test code
Im not saying that freertos works good or bad, but my understanding of freertos is telling me that all tasks should share the same mutex if you want to block HP by LP task.
Lets imagine situation you have 2 LP tasks and 2 HP tasks.
- task1 and task2 are LP,
- ...
- No, i am not using tinyusb at all in my test code, it was just test of freertos behavior with mutex
I see, your 2 examples are not the same as the above sketch running on nrf52 with TinyUSB CDC for Serial.printf.
- yes, ive been reading all from link you posted at first place and i am also confused, thats why i prepared this test code
I think you completely misunderstand my point, it probably due to my bad writing. Please re-read my first post again, I will make a short sumu...
Ok, here is quick test that proves your words with that case:
Setup3: priority = 1
Setup1: priority = 1
Setup2: priority = 21
task1 task1 task1
Setup3: priority = 21
Setup1: priority = 21
Setup2: priority = 21
task1 task1 task1
Setup3: priority = 21
When setup helds 2 mutexes, 1 shared with task priority 10, the other with task priority 21 and 1st mutex is not released, then priority of setup stays at highest inherited level. Only releasing all mutexes will let setup get b...
@chegewara There is no need to post an example here to prove my words at all. I already having an example sketch and the rtel response above already nailed it down. You are probably interested in freeRTOS, but I am only interested in fixing my stack.
If you got my point now, would you mind if I remove all of our converstation so far on the FreeRTOS, it is a bit distraction with lots of lengthy example. I am worried people will be off-topic from the actual race condition. Thank you.
I...
Is anyone here familiar with running TinyUSB outside of arduino. I am working on a SAMD11 project with the same processor thats on the xplained boards. I am having trouble figuring out how to get started. I include tusb.h and a usb_config that is a copy of the composite hid example. I also #define CFG_TUSB_MCU OPT_MCU_SAMD11
Then when I try to do things like call the tinyusb handler in the IRQ it fails to find dcd_int_handler function. Which tells me I don't have everything defined as it should be. What should I be doing to get this running without the magic of board.mk files and the like
Is your feature request related to a problem? Please describe.
Currently stream endpoint (ep buf + fifo) are used by cdc, midi, vendor are very similar to each other e.g
- read from fifo, if there is enough space --> submit transfer for epout
- write to fifo, if there is enough data or flush() --> submit transfer for epin
- on endpoint complete callback --> auto flush and/or auto prepare out transfer
The code is duplicated making it hard to maintain, since stream api is popular, m...
Ok just to be clear, the issue only happens with this PR right ? Maybe we both miss something in the diff
Just this PR, happens sometimes on persistent reboot. Regular reboot with peripheral reset is fine. And hard to trigger on some boards, but not on others.
Ideally it would be 1 mutex per endpiont, but that seems to be a lot of memory for edge case. Maybe only one general mutex is enough, and the edpt_claim()/edpt_release() is fast enough I guess. Let's me know what do you think about the PR and how we could improve it. I am open to any suggestion.
Usually I'd say that one mutex for claiming all endpoints should be ok. There is not much processing and high priority tasks can only be blocked very shortly. But this short blocking is not guara...
@Thanos-Love-Ironman I see you had some other problems which seem to stick together. Right now the information I have don't seem that there is actually a failure to usb because of warm plugging.
Does your Windows detects the USB device correctly (even after 2nd or 3rd plug)? Then the enumeration seem to work fine without any problems. The problem would be related to other system setups I guess.
But if the enumeration process will fail it could be because of the alternative function on U...
any reason for testing with bitmask here and in the bsp files it does equality test against USBDC_PERSIST_ENA?
I am currently using the tud_cdc_n_get_line_state interface function for retrieving the DTR signal, but the RTS control signal is not yet retrieved.
Which terminal software are you using to test this? I once spotted a similar behaviour when using HTerm. Changes to RTS were only received after changing DTR as well. I'd recommend you to test your implementation with other terminals as well. (Maybe some applications think it's not useful to set RTS if they are actually not ready 🤷♂️?) Putt...
Usually I'd say that one mutex for claiming all endpoints should be ok. There is not much processing and high priority tasks can only be blocked very shortly. But this short blocking is not guaranteed, as we can see with a setup like #507 . If the low priority task won't fall back to it's low priority after releasing the mutex other high prio tasks can be blocked for much longer than expected. This won't result in the error we saw before, but could cause problems to time critical tasks. I a...
hold your horses @atanisoft :) code is not final.
Yeah, I know it's not final but it is curious why the two approaches and if it might be playing a factor in the inconsistency you are seeing.
Ok just to be clear, the issue only happens with this PR right ? Maybe we both miss something in the diff
Just this PR, happens sometimes on persistent reboot. Regular reboot with peripheral reset is fine. And hard to trigger on some boards, but not on others.
Oh, that is a mystery, maybe it is related to the bsp like pin drive, voltage etc.. unfortunately I couldn't help you to troubleshoot this since I have little exp/knowledge with persistent mode.
@duempel oh, while removing the claimed bit, I realize there may be an issue. Since currently the edpt_claim() is optional. Using only 1 busy bit, the edpt_xfer() won't be able to force and check to see if the endpoint is currently transferring or not. E.g an API can call edpt_xfer() 2 times, and the busy is set just like using the claim_edpt() hmm. Maybe we can leave that later when forcing all API to use claim, however, it is not really necessary for endpoint that isn't directly involved ...
@atanisoft ... why are you trying to find reasons where there are none? I Ctrl+Z some code, which brought the old approach that you had issue with before... this bit that is read by the bootloader can in no way ever cause the problem I am describing. and it's the same exact thing anyway...
It's just a Q on why the inconsistent usage of USBDC_PERSIST_ENA between the bsp files and this one. There is no technical issue between the two approaches that I can think of but more of a style issue.
Thank you again, great PR, I think this over most of our discussion on this topic before. Strangely the code is actually much less than the discussion itself, which is actually a really good things, since we write less but cover most scenario. I only has a few comments, most importantly to remove the edpt_abort() since that is lots of works and may not needed since the case is not that severe. Most user won't even notice that. I like to add code step by step, it takes lots more time to get th...
xfer_abort() is too much work to implement now on all ports. I would suggest just simply clear the fifo for now. We can put an // TODO here for reminder . User won't probably notice it I guess hopefully :)
maybe naming it tu_fifo_set_mode() is more appropriate. aslo !dtr is less wording ;)
I am thinking we don't really need this option. The default to continue to send still suite most people in most cases I think. If people really want to clear the fifo. There is a tud_cdc_line_state_cb() callback, we can add an extra cdc-write_clear() for user to clear it themself. Just in case people want to have one cdc interface that clear() and another that does not.
PS: We can always add this option if needed later, but it is much harder to remove it once added.
Let's focus on the actual functionality and less on the style. Those aren't too important for new feature PR, I am fine with any ugly/hacking code as long as it makes sense and doesn't break thing. It is much easier to refactor a working code later on. Thanks.
In that case maybe using mutex in tinyusb is not correct way? Just thinking out loud.
@chegewara actually, thinking about this, It may make some sense. Maybe TinyUSB could implement osal_mutex as normal semaphore instead :thinking: . Of course, we will fall into the priority inversion scenario, though I am not sure between the 2 cases, which is worst hmmm.
@duempel Maybe TinyUSB could implement osal_mutex as normal semaphore in FreeRTOS instead :thinking: . Of course, we will fall into the priority inversion scenario, though I am not sure between the 2 cases, which is worst hmmm.
I am thinking about it and i see 2 potential solutions:
- use binary semaphore instead of mutex,
Binary semaphores and mutexes are very similar but have some subtle differences: Mutexes include a priority inheritance mechanism, binary semaphores do not. This makes binary semaphores the better choice for implementing synchronisation (between tasks or between tasks and an interrupt), and mutexes the better choice for implementing simple mutual exclusion.
- in tinyusb just before you are trying to claim mutex, store task priority, then right after releasing mutex restore task priority; im not sure if tinyusb allows to access more than 1 task to code that will try to claim mutex, because this wont work in such case (priority will be kept only for last task)
this is too much, a usb stack can never fix an RTOS kernel issue. We are better to leave the prio correction to the kernel. Else we will be gonna introduce more bugs. IMO, the alternat...
Maybe there is some point of priority inheritance, but i dont see it here now. It is only my personal point of view now, but binary semaphore should be good enough. Maybe @me-no-dev or @igrr has something to say about it.
Hi there, I'm finishing speaker part. It turned out that for this to work correctly I need feedback endpoint and that is taking much time (also it was not clear to me what Windows really expect from audio device in terms of descriptors and it took me some time
to have it working, while Linux and Mac were happy with what I had originally). FIFO mechanics are not not affecting me, since I made some changes that use just one FIFO for all channels and this change alone drastically re...
Surely using more mutex will increase the chance of HP being blocked
Yes using more mutex will increase the chance of blocking. But I actually wanted to say that using more mutex objects we can decrease the chance of blocking since EP3 would not try to get the same mutex as EP2. Well but one is just fine for now. Don't need to waste ressources on this.
_prep_out_transaction() is also invoked by user via cdc_read().
Oh yeah, my fault. I just wonder if we would really need it in ...
There are some more commits on my branch kasjer/uac2.
It's not all yet, since our work slightly diverged and I have conflicts which are mostly resolved.
You can take a look of what was done.
I also have changes to explicit feedback, that with proper descriptors works with Windows and Linux.
I noticed that @PanRe changes were adding FIFO bypass lately and my work uses FIFO for speaker and microphone so I hope we will not argue here (FIFO code had some minor discrepancies so maybe it was no...
Yes using more mutex will increase the chance of blocking. But I actually wanted to say that using more mutex objects we can decrease the chance of blocking since EP3 would not try to get the same mutex as EP2. Well but one is just fine for now. Don't need to waste ressources on this.
Right, I thought of this as well, 16 mutex is lots of resources. 1 Mutex can easily occupies 32 or 64 bytes.
Oh yeah, my fault. I just wonder if we would really need it in user API but this can be di...
[hathach/tinyusb] New branch created: fix\-hid\-gamepad\-template
Describe the PR
Fix incorrect gamepad input type
Spotted and fixed in Arduino port by https://github.com/adafruit/Adafruit_TinyUSB_ArduinoCore/pull/14/files
I think I found the bug!
If you send [0xf0, a, b, c, d, e, f, g, h, i..., z, 0xf7] (where the letters represent arbitrary payload values)
you get instead: [0xf0, a, b, c, a, b, d, a, b, e, a, b, f, a, b, .... z, a, b, 0xf7, a, b]
if you space that out in the three bytes of payload in each USB packet, you'll see the pattern:
[0xf0, a, b,
c, a, b,
d, a, b,
e, a, b,
f, a, b,
....
z, a, b,
0xf7, a, b]
This is a bug in the USB MIDI encoder in...
Set up
- PC OS : macOS 10.15
- Board : Feather M0 Express
Describe the bug
SysEx messages are mangled when sent over USB.
Example:
- Send
F0 7A 00 01 61 62 63 64 65 66 67 68 69 6A 6B 6C 6D F7 - USB host receives:
00 F0 7D 00 01 7D 00 61 7D 00 62 7D 00 63 7D 00 64
10 7D 00 65 7D 00 66 7D 00 67 7D 00 68 7D 00 69 7D
20 00 6A 7D 00 6B 7D 00 6C 7D 00 6D 7D 00 F7
To reproduce
Build and run this sketch. It uses both the `Adafruit_Tiny...
At the start of a new USB packet (4 bytes), while in the middle of a SysEx, the code mistakenly
set the buffer length to 4, not the target length. As a consequence, the 3rd and 4th bytes from
the last packet were included, after every byte of the SysEx after the first packet of three.
The fix is simple, as it was just a typo, as can bee seen from the other branches in the same
section of if/else statements: At the start of a new packet, the code should set up the target
length... the b...
I wrote my finding up as a separate bug (#511) and pull-request (#512) - since I'm not certain it fixes everything originally reported here.
Set up
[Mandatory] Provide details of your setup help us to reproduce the issue as quick as possible
- PC OS : Windows 10
- Board : STM32L072
- Firmware: examples/device/cdc_msc
Describe the bug
Hi, I'm evaluating Segger Embedded Studio with gcc and segger linker and I got errors with all functions defined as weak while linking.
For example:
case DCD_EVENT_RESUME:
if (tud_resume_cb) tud_resume_cb();
break;
Meanwhile I'm trying to convince Segger to add this support, since all other linkers I've used have no problem.
Hmm, I also use segger embedded studio for debugging occasionally and didn't have any issues with linking weak function. Have you tried out those project in the example https://github.com/hathach/tinyusb/tree/master/examples/device/cdc_msc/ses
Note: some may be out of date and needs update to compile.
This behavior is specified in the AAELF ("ELF for the ARM Architecture") document:
I am aware of the direct use of weak function which expanded to NOP. However, I am not sure how oth...
Thank you very much for the PR, give me a few days to ask for review help. Hi @kaysievers do you have a minute to review the changes, It is probably simple enough to you but is out of my expertise.
@hathach all in all I feel good with these changes. In _prep_out_transaction maybe claiming the endpoint would make more sense if we do this before availability check. In case tud_task has a higher priority than the user task which is calling a tud_cdc_n_read for example. The user task then processes _prep_out_transaction and reads the available bytes in rx fifo. If the higher priority task then invokes cdcd_xfer_cb and write data to rx fifo there might be less space. In this case the _prep...
Hmm, I also use segger embedded studio for debugging occasionally and didn't have any issues with linking weak function.
Do you use segger linker ? I'm using version 5.10a.
It's a demo project about this issue.
demo.zip
Hmm, I also use segger embedded studio for debugging occasionally and didn't have any issues with linking weak function.
Do you use segger linker ? I'm using version SES 5.10a with segger-ld 3.04.
It's a demo project about this issue.
demo.zip
I will try it later on, meanwhile can you compile with the nrf5x project here https://github.com/hathach/tinyusb/tree/master/examples/device/cdc_msc/ses/nrf5x
It wo...
merged now since it is ready and I need to move on with other works. Issues such as semaphore vs mutex can be done a follow-up PR if needed.
Thanks @chegewara for helpful discussion, though I decided to leave it as mutex (and move on with other works). The semaphore vs mutex can be done as follow-up PR if needed. After all the scenario is considered as "almost never occur" by FreeRTOS developers.
Describe the PR
Operator < used in while condition was obviously incorrect.
Loop starts with checking if unsigned variable is less then 0.
This condition is always false.
This reverses condition to follow intention of of the code.
Additional context
Oh my, you really got an eagle eye, it seems like I didn't test this code or the tests I used is irrelevant. Thank you for spotting the issue
Set up
[Mandatory] Provide details of your setup help us to reproduce the issue as quick as possible
- PC OS : Windows 10
- Board : SAMD11 XPLAINED
- Firmware: examples/device/hid_composite
examples/device/hid_generic_inout
Describe the bug
When programming either of these examples to the SAMD11, they constantly send String Descriptors to the host. It Doesn't seem like much of a pattern (it will sometimes send string index 1, the...
Funny enough it finally quiets down and starts only sending NAKs and SOFs eventually.
Some timed runs of how long it takes:
-
1minute and 24 seconds -
26 seconds -
22 seconds -
1 minute 34 seconds -
1 minute 12 seconds
The host doesn't send a suspend or anything, it just stops flooding descriptors
meanwhile can you compile with the nrf5x project here
I can compile this project since it's using gcc linker.
I think a solution to ensure compatibility between processors is to add a stub function instead using `if'
For example in usbd.c, change
// invoke callback
if (tud_umount_cb) tud_umount_cb();
to
TU_ATTR_WEAK void tud_umount_cb(){}
...
if (tud_umount_cb) tud_umount_cb();
Describe the PR
Rework of tu_fifo to use unmasked pointers as discussed in #504.
I want to use the UART log function of STM32F103Bluepill. The current code is as follows, which can be compiled and passed normally, but cannot receive and receive data in PA2 PA3 port.
`/*
- The MIT License (MIT)
- Copyright (c) 2019 Ha Thach (tinyusb.org)
- This file is part of the TinyUSB stack.
*/
#include "../board.h"
#include "stm32f1xx_hal.h"
//--------------------------------------------------------------------+
// Forward USB interrupt events to TinyUSB IR...
I am currently using the tud_cdc_n_get_line_state interface function for retrieving the DTR signal, but the RTS control signal is not yet retrieved.
Which terminal software are you using to test this? I once spotted a similar behaviour when using HTerm. Changes to RTS were only received after changing DTR as well. I'd recommend you to test your implementation with other terminals as well. (Maybe some applications think it's not useful to set RTS if they are actually not ready 🤷♂️?...
Thanks for filing the issue, are you using an IDE to compile the example, if yes then try to reproduce to see if the issue occur with existing makefile target.
Plugged in the EDBG and couldn't get anything on the COM port. Does logging work on the SAMD11?
Yeah, it doesn't work since uart API is not implemented on the board, maybe you could help to add the support for it ? https://github.com/hathach/tinyusb/blob/master/hw/bsp/samd11_xplained/samd11_xplained.c#L126
Since I don't h...
please use one of the template for issue, if you want something out of the usb functionality, try to implement it yourself since it is not considered as the scope of this repo.
Hi,
Coud you avoid using modulo as much as possible ? As on Cortex-M0 and 8bit MCUs division cost many CPU cycles, now it's called in every write and read operation.
Describe the PR
ISO endpoints were not covered in nrf5x driver.
Code deals with ISO IN and OUT endpoints.
Intermediate steps needed for ISO to work on NRF:
- increasing number for device endpoints (it was 8).
- increasing max endpoint size variable size
- closing endpoints
Additional context
Code should not affect current non-ISO control flow.
It was tested with audio driver that @PanRe is going hopefully to submit soon :)
It happens whether I use an IDE or just compile the examples using make. I will try to get some time to look at the uart stuff. Also I have a SAMD21 xplained board in the drawer and not sure if I can get one of the other examples to run on it.
Ah yes sorry for the delay! I promise to get the PR done by the end of this week! :)--Diese Nachricht wurde von meinem Android Mobiltelefon mit GMX Mail gesendet.Am 21.09.20, 16:19 schrieb kasjer notifications@github.com:
Describe the PR ISO endpoints were not covered in nrf5x driver. Code deals with ISO IN and OUT endpoints. Intermediate steps needed for ISO to work on NRF:
increasing number for device endpoints (it was 8).
increasing max endpoint size variable s...
Ah yes I see. Well this might by tricky since here we really need a true modulo result. But I have an idea how to solve this issue (I hope). I update the PR once I tested my idea.Am 21.09.20, 10:23 schrieb HiFiPhile notifications@github.com:
Hi,
Coud you avoid using modulo as much as possible ? As on Cortex-M0 and 8bit MCUs division cost many CPU cycles, now it's called in every write and read operation.
—You are receiving this because you authored the thread.Reply ...
Thank you for PR, I was bit busy lately and didn't test it out, but it looks great to be merged.
It happens whether I use an IDE or just compile the examples using make. I will try to get some time to look at the uart stuff. Also I have a SAMD21 xplained board in the drawer and not sure if I can get one of the other examples to run on it.
thanks for confirmation, samd21 should work well, since it is widely tested with Adafruit M0 board, though the SAMD21 xplained it not part of supported boards, you may need to add a port for it. SAMD11 mcu is only ported recently, maybe it has some...
I've rebased my repositories today for the first time since April. Everything seems to work fine. There is only one patch left.
Here is the current change to the MIDI interface to make it work reliably with SysEx messages:
https://github.com/versioduo/Adafruit_TinyUSB_ArduinoCore/commits/versioduo
Thank you very much for the great PR. It is a bit more complicated than I though, however, decoupling write() and read() and is able to use with DMA are indeed an incredible feature which will definitely has lots of benefit. Though I am hoping maybe we can make the code a bit simpler e.g like dropping (wAbs, rAbs) arguments if that is possible in parts of the API.
PS: Sorry for late response, I have been busy with other works, still trying to catch up.
i think you mean read pointer rather than write.
hmm this math seems to be more complicated than it should be, can we change it to
idx -= (idx >= depth) ? depth : 0;
or simply
if ( idx >= depth) idx -= depth
I still have a question, why wouldn't we do it twice, if needed, we could just do a. it is still much cheaper to run than % which cost 50 cycles or so on M0, this mostly only compare 1 and minus 1 90% of the time ?
while ( idx >= depth) idx -= depth;
These function aren't used yet, IMHO it is wroth to write unit test with various scenario to verify its behavior. Since fifo is primitive type, I have several existing tests for it here. If you have time and write couple of DMA read/write tests it would be great, not a problem if you don't, I could do it myself
https://github.com/hathach/tinyusb/blob/master/test/test/test_fifo.c
To run unit test, you will need to install Ruby, and install Ceedling via gem.
https://github.com/ThrowTheSwit...
meanwhile can you compile with the nrf5x project here
I can compile this project since it's using gcc linker.
I think a solution to ensure compatibility between processors is to add a stub function instead using `if'
For example in
usbd.c, change// invoke callback if (tud_umount_cb) tud_umount_cb();to
TU_ATTR_WEAK void tud_umount_cb(){} ... if (tud_umount_cb) tud_umount_cb();
@HiFiPhile...
I just realized @hathach posted his review when I'm reviewing :)
Thank you for this great PR, in general I'm agree with @hathach,
Could overflow when depth=0x8000;
I still need to double check that behavior on some of popular platform.
Maybe we won't support x86 one day ? Because execute weak function can cause segment fault on x86.
Describe the PR
Added a DFU skeleton to help the implementation of DFU feature.
Additional context
Now you just need to develop the DFU implementation on your software by creating the defined WEAK function on dfu_rt_device.h
hihi, sorry for late response, I am scratching my head with other things just now. Will check out this ASAP :sweat_smile:
I just realized @hathach posted his review when I'm reviewing :)
Thank you for this great PR, in general I'm agree with @hathach,
I just scratch the surface, being occupied by other work now. I will try a more thorough test later on.
I would assume so. I think it's just a bulk endpoint
I found something even better, a HID example PR for LUNA that does everything in gateware, no CPU needed
True copy and past error ^^
Well this might be micro-optimization but the idea here was the following:
- By design, the pointers are not allowed to become larger that 2*depth-1
- As a result we can guarantee that executing 2 times
idx -= depth & -(idx >= depth);is sufficient - There is a big discussion about branching, what is more efficient. Most people argue that branching may result in flushing the instruction pipeline and thus might result in worse delays. The version above simply avoids branching at all as th...
Ok! pos was the name of the parameter in the original version if i am not mistaken. I would prefer the name offset.
For _overflow() definitely but _count() is used pretty often. I would make _count() inline is this ok?
Uff honestly i am lacking time dramatically :D I also need to review the UAC2 PR. I did this DMA stuff before in my RERO project (in combination with USART) for an STM32F3 and F4. So i know this works at least for STMs. However, since DMAs are rather specific to the used MCUs i am not sure if it is possible to set up a general test?
I think it is a bit too micro optimization, I really prefer a simple code, while() loop probably works best. Mul & div make take longer on smaller mcu.
while ( idx >= depth) idx -= depth;
I will do the test then, test is run on x86, it actually doesn't run any DMA, just plain copying then move pointer forward, then read back data for verification. Test is all faking behavior :)
@kaysievers Thanks for letting me know, there is a couple of bug fix regarding MIDI later in the original stack recently.
https://github.com/hathach/tinyusb/pull/512
https://github.com/hathach/tinyusb/pull/497
I still haven't got time to check the PR last time we reverted yet. Will do it later on when having time, it probably works better now.
Hi, thanks for this awesome library! I'm currently integrating TinyUSB into modm (https://github.com/modm-io/modm/pull/478) and I found some minor things to improve:
- I added a simple
STM32F3_IRQ_REMAP, which can be defined in the config to remap the IRQs. The user must remap the IRQs in their hardware setup (it's justSYSCFG->CFGR1 |= SYSCFG_CFGR1_USB_IT_RMP;). - We're using TinyUSB in C++, which doesn't define the
__STDC_VERSION__macro, thus throwing a warning. Just a simple f...
Thank you! Maybe it is even better than somebody else tests the code. If there are any issues or questions don't hesitate to ask! :)
There is one idea left. Since write and read are decoupled we could introduce seperate mutexes for them. Right now write and read still block each other since they share a common mutex. I did not implement this so far since it would break the current API. I thought you know the project in more detail and i would leave it up to you to decide if its worth to implement it.
@hathach thanks for your review. I kept this draft pending as it is right now, because I hoped someone else could take a look and comment on it. Since I am defining a very new functionality for the CDC, some more ideas might be useful.
This is also the reason why I made this PR a little bit bigger than it will eventually become. Just to show an idea of the code to what we discussed before.
I'm a bit busy at the moment, but I'll work on the changes you recommended and push the update we ma...
Yes, adding the new function to all ports is way too much work for very rare used functionality. That's why I just added the usbd_edpt_xfer_abort API and made the dcd_edpt_xfer_abort optinal in usbd.c L1110. But I can understand if you say that we even do not want to introduce the usbd function for this rare use case.
Thanks a lot. I was struggling a lot with finding a good name for it. Like your idea! 😉 Also I wasn't 100% sure if we really need this function. We could just change the overwritable bit within tx_ff from cdc_device.c. Don't see a real problem here if we do not lock the fifo. But like now it might be safe for sure.
Great reason. It's easy to be user implemented. Also this makes our xfer_abort discusson become obsolete. 👍
it probably works better now.
The FIFOs still drop data, right? As long as that is the case, the current MIDI code cannot reliably work. MIDI packet flow needs to behave like a CDC serial line, just block, never drop anything.
Could you fix the MIDI FIFOs to work as expected?
Describe the PR
This PR adds a USB audio 2.0 (UAC2) driver.
First a very BIG thanks to @kasjer for helping finalizing and testing this driver! It took quiet some time to set all of this up and there definitely is room for improvement. But as a first start this sould be fine!
Additional context
In general
- multiple audio functions (drivers) are useable in parallel.
- at most one IN EP, one OUT EP, one feed back EP, and one INT EP are supported per audio function. This should...
@hathach There might be the need to adjust the unit tests because it does not know anything of dcd_alloc_mem_for_conf() and it complains that this function is called too often. Can assist here? Thanks a lot!
@robust walrus Hey I don't mean to bother you, but I was wondering if you have any experience using composite devices in tinyUSB. I tried to just put my own device descriptor in from another project and it didn't quite work. Then I tried just doubling the in/out example and that doesn't work either. So I am not sure if I am not doing it right or if TinyUSB just doesn't do multiple interfaces correctly.
@signal ocean circuitpython definitely uses composite devices
it doesn't use different configurations (I think that's the right term)
do they actually have 2 interfaces. I noticed the tinyusb composite example is a kbmouse over the same endpoints I think
ya, circuitpython is msc, cdc, hid and midi by default
I will dive into circuitpython and learn from there. I figured it was something I wasn't doing right, but figured theres always a chance I am spinning my wheels for no reason. Thanks!
np 🙂
it probably works better now.
The FIFOs still drop data, right? As long as that is the case, the current MIDI code cannot reliably work. MIDI packet flow needs to behave like a CDC serial line, just block, never drop anything.
Could you fix the MIDI FIFOs to work as expected?
The fifo is still overwritable for MIDI, I still haven't got time too look at this issue yet since the last time. I will try to do it later on.
@hathach thanks for your review. I kept this draft pending as it is right now, because I hoped someone else could take a look and comment on it. Since I am defining a very new functionality for the CDC, some more ideas might be useful.
This is also the reason why I made this PR a little bit bigger than it will eventually become. Just to show an idea of the code to what we discussed before.I'm a bit busy at the moment, but I'll work on the changes you recommended and push the upda...
using the while() loop for modulo now, I think we don't need to limit the depth to 2^15 any more, right ?
There is one idea left. Since write and read are decoupled we could introduce seperate mutexes for them. Right now write and read still block each other since they share a common mutex. I did not implement this so far since it would break the current API. I thought you know the project in more detail and i would leave it up to you to decide if its worth to implement it.
yeah, it should though, I will implement it in a separate PR, no worries. I will carry more tests and try to merge this...
We should let it stay at 2^15! The main reason is that the while loop is nothing else than the modulo operation in software without division and this can last extremely long!!! By limiting to 2^15 we guarantee that at most two iterations are required and thus we get a fast result. If you go back to 2^16 we are as slow as with modulo. E.g. think about doing the while loop for a depth of 100 and an index space size of 2^16, you end up staying in the while loop for 2^14 iterations if you are unl...
Thank you very much for this great PR, and sorry for being late with review (was busy with other works for last week :sleepy:). This look great, I only have a few minor comment,
- the only issue is the if logic in the
dcd_edpt_stall - There is lots of number
8used for ISO endpoint, maybe we should have an enumEPNUM_ISO = 8or any name like that just to make it easier to tell the diff when we refer to EP ISO or the count of CBI.
IMO, we should have an TU_ASSERT(epnum == 8) here to prevent ep address typo from application. This also make sure the app won't try to have 2 ISO interface as well (audio + video) which won't work with nrf52 port.
the if logic condition is inverted, the condition here is for control endpoint
let's default it to 9 for now so that nrf5x port doesn't have to manually defined it. Later on we could have an better #if according to the port so that we don't waste SRAM on some MCU (e.g some stm32 only support 4/5 pairs of endpoints). However the memory consumed is too small ( few bytes ) to worth the effort for now.
correct, I will change it to data_consumed that should be good for both cases
my bad, thanks for spotting it
wow wow wow, this is astounding, thank you very much @PanRe and @kasjer for this awesome work. This is quite a lots of changes, please give me a few days for proper reviewing and testing. I may try to merge the fifo enhancement #516 first.
@hathach There might be the need to adjust the unit tests because it does not know anything of dcd_alloc_mem_for_conf() and it complains that this function is called too often. Can assist here? Thanks a lot!
no problem, don't worry about the...
We should let it stay at 2^15! The main reason is that the while loop is nothing else than the modulo operation in software without division and this can last extremely long!!! By limiting to 2^15 we guarantee that at most two iterations are required and thus we get a fast result. If you go back to 2^16 we are as slow as with modulo. E.g. think about doing the while loop for a depth of 100 and an index space size of 2^16, you end up staying in the while loop for 2^14 iterations if you are u...
@kasjer ah, not actually, currently the data_received is indicator for OUT endpoint, since nrf controller will auto ACK the first OUT packet even if we didn't schedule any transfer in the software. Therefore it is more like data_available for CBI than consumed, there for the consumed is not really correct for CBI usage. These naming is really difficult :weary:
no problem, my original code is not too consistent with if else between stall and clear stall. I must write it at 2 different time and it is easy to overlook.
no problem, my original code is not too consistent with if else between stall and clear stall. I must write it at 2 different time and it is easy to overlook.
I have played with composite devices a little more and now realize my issue is trying to fire up multiple HID interfaces. I want to use 2 hid interfaces for two different report descriptors. Does anyone know if TinyUSB is capable of this? It seems the issue is not being able to separate the report descriptors possibly? It does just seem like it should work though.
Describe what the question is
I see the composite example uses a keyboard and mouse on the same interface. When I try to add multiple interfaces I start to get "device not started" issues. The descriptors come in and then it stalls. Is what I am trying to do supported by TinyUSB? If so can someone who has experience with it give me some pointers on what needs to be done to get this type of device rolling.
Most other libraries have you list the report descriptors separately per interfa...
90% of the work for multiple HIDs are done, though it is not very often used by most application. If you are willing to submit pr to add HID multiple interfaces support. I am happy to review. You could take a look at multiple CDC API for reference
https://github.com/hathach/tinyusb/blob/master/src/class/cdc/cdc_device.h#L61
Is your feature request related to a problem? Please describe.
As tinyusb grows more device class and board support thanks to the wonderful contributors, I get a bit concerned about keeping track of:
Which boards supports which parts of tinyusb? And when were the examples last built and known to work?
This would have to be a collaborative effort, considering that I don't think anyone has all the boards that tinyusb supports.
Describe the solution you'd like
I...
working on this now. making good progress, so hopefully all works as planned
working on this now. making good progress, so hopefully all works as planned
great to hear that, the most annoying part is we have to add itf arguments to all of the callbacks() API, which break current applications. I should have added that in the first place.
Describe the PR
Allows multiple hid interfaces within a single device. Includes example as well.
Additional context
https://github.com/hathach/tinyusb/commit/b7208d6f7e97e724853eb5d0e512a23005cc8790
This needs to be changed because it breaks all legacy hid usb_descriptors.c files. There should be a better way to do this, but I thought I would just get it done and then pose the question here. I need to be able to call tud_hid_descriptor_report_cb and pass desc_index as well as pa...
thanks @cr1901 it is a good idea, though I think having commit hash that last known good is too much of maintaining works. An example doesn't work on a specific MCU is mostly of: not enough RAM or ROM, not enough Endpoints, which are very static. Therefore I would consider it is a bug if it works in a previous commit but not at current latest. I think we could update the boards.md to become an table with additional notes on which example a board doesn't work or work with limited functiona...
Thank for the PR, sorry for late response, I have been too busy lately. Most of your modification and explanation make sense. I only want to know a bit more about the STM32 remap to see if we could implement it without having an extra DCD specific macro.
verify doesn't trigger any error, it is considered normal scenario for an VERIFY() to failed. Therefore I think we don't have a need to overwrite it.
thanks, nice catch. Actually I tried to update this once, but some error prevent this in a certain build. I forgot the reason, but look like it is addressed recently :).
like above, verify doesn't need to be overwritten.
Thank you for your PR, everything look good except for the tud_hid_descriptor_report_cb() that needs to be updated per review. Yeah, regarding the backward compatible, Ideally all the callback has need to have additional itf argument for application to know which interface that event occurred all, and this sadly break the existing code. The best approach now is
- when
CFG_TUD_HID == 1we will keep the current single interface API and define the callback_n() version as macro that expa...
please remove these completely, we don't really need to remember this :)
I think there is a bit of mixing-up here. The wIndex is actually the interface number of the HID interface and not the desc_index. It just happens to be the same 0, 1 order as the example. It will be different, if we have additional class before and/or between the hid interface.
What we should do here is use the wIndex to figure out the index of the targeted interface in hid pool and pass it as itf to the callback. It is a foor-loop comparing the wIndex agains the itf_num of the in...
Describe the PR
ISO endpoints for DA146xx were not supported so far.
To enable them and in turn allow USB audio to work following changes were made to DA146xx driver.
- Max endpoint size restriction was removed (64 bytes size of the internal FIFO).
It was achieved by adding DMA support and also FIFO level interrupt that can be used when DMA is in use.
(Only one endpoint in each direction can be used with DMA at a time). - dcd_edpt_close() function was added that will be ...
Superb !! Thank you very much for this great PR, sorry for being slow on reviewing, I am catching up now. PR look great, I haven't tested it yet, But I will definitely test it out with the UAC2 #521 later on.
did this when playing with the feature and forgot to pull them out. Will do
Realized I copy and pasted these with the report IDs later in the day haha.
We should be able to use the lower byte of wValue to determine the descriptor index. The setup packet has the correct index in it when sniffing with a beagle. I set up some traps to debug this and wValue is always 0x2200 instead of 0x2200 and then 0x2201. Trying to track down why, I feel like this is the right way to solve this problem if it isn't crazy. That way we are relying on the spec instead of a hack.

I wanted to include an image here. It is super wild, I have traced the data all the way back and can't figure out where it would be manipulated. It seems to just come in on the FIFO read so how would 1 byte be wrong on the setup packet.
Anybody in here that has a different device than a SAMD11 that can test the issue in https://github.com/hathach/tinyusb/pull/524#discussion_r499019634
should be able to change
uint8_t const * desc_report = tud_hid_descriptor_report_cb((uint8_t) request->wIndex);
to
uint8_t const * desc_report = tud_hid_descriptor_report_cb(desc_index);
and eventually get a 0x01 in there
I can't seem to figure out at what point the lower byte is dropped or why its dropped
I determined the descriptor index in hid_device. You are asking the descriptor report callback to return the correct hid descriptor based on the index requested not based on the interface.
Set up
[Mandatory] Provide details of your setup help us to reproduce the issue as quick as possible
- PC OS : Windows 10
- Board : SAMD11_xplained
- Firmware: examples/device/hid_multipleinterface
Describe the bug
When you read in a Get Descriptor request the high byte of wValue should be 0x22 which it is. The low byte should be the index of the descriptor, but it is always 0x00.
To reproduce
Steps to reproduce the behavior:
- Debug the Multiple...
I moved the issue with wValue out to its own bug for tracking and implemented the hack here so that this works for now.
I think this update should be reverted so the debug output is off by default when not explicitly enabled.
When testing the cdc_msc_freertos example on a stm32f1 board, it doesn't work properly. This is because the IRQ for the USB is higher than the freertos one.
This fix basically sets the USB IRQ priority to a lower value which enables it to function as it should.
Not that big an issue, since I can reuse the tinyusb variadic helpers for that purpose, and redirect to our assertion mechanism:
// Redirect TinyUSB asserts to use modm_assert
#define MODM_ASSERT_1ARGS(_cond) \
TU_VERIFY_DEFINE(_cond, modm_assert(0, "tu", \
__FILE__ ":" MODM_STRINGIFY(__LINE__) " -> \"" #_cond "\""), false)
#define MODM_ASSERT_2ARGS(_cond, _ret) \
TU_VERIFY_DEFINE(_cond, modm_assert_contin...
This only exists for the STM32F302 and the larger STM32F303 devices.
See RM0365 Table 40, page 208, footnote 1 (STM32F302) and [RM0318 Table 82, page 288, footnote 1](https://www.st.com/resource/en/reference_manual/dm00043574-stm32f303xb-c-d-e-stm32f303x6-8-stm32f328x8-stm...
I guess you could read the bit at runtime and select the right interrupts. Wouldn't be too much overhead.
I haven't had a chance to test with another OS yet. I have tried it on different hardware but all windows.
Also I spent some time working on the UART today using the hid_composite example and it doesn't fit. I even tried to conserve space using masks to load the registers instead of including any of the HAL/HPL sercom functions. You can test this as well as just including LOG=2 without any of the functionality yet. It compiles fine but fails to program to the device.
wow wow wow, this is astounding, thank you very much @PanRe and @kasjer for this awesome work. This is quite a lots of changes, please give me a few days for proper reviewing and testing. I may try to merge the fifo enhancement #516 first.
@hathach There might be the need to adjust the unit tests because it does not know anything of dcd_alloc_mem_for_conf() and it complains that this function is called too often. Can assist here? Thanks a lot!
no problem, don't w...
Everytime you try to turn debug or log on you will get the error back. It can be fixed by adding hw/mcu/microchip/samd11/hal/utils/src/utils_syscalls.c
to the SRC_C += in side board.mk for the samd11
this shouldn't be necessary since there is a -specs=nosys.specs in the rules.mk file, so it is probably correct that the linker is wrong, but I can't find where. It matches quite a few examples.
Thanks for PR, please move this to application i.e bsp_init() here is a similar code for other MCU
https://github.com/hathach/tinyusb/blob/master/hw/bsp/lpcxpresso1769/lpcxpresso1769.c#L114
the irq priority should be set by application, in this case, it is in bsp_init(). Setting it here is not flexible enough for all the application.
This PR is the second in a series of PRs targeted at porting SuperCAN's USB DFU 1.1 bootloader to TinyUSB.
This PR adds support for the D5035-01 hardware which is the device I use to test the bootloader.
Thank you for your brilliant PR, it works perfect with several test I throw at it.
This PR fixes two race conditions in the stm32 fsdev driver:
- USB->ISTR is a register where bits are cleared by writing 0. A non-atomic read-modify-write, as is done in reg16_clear_bits(), may inadvertently clear an interrupt flag that gets set between reading ISTR and writing ISTR, causing that interrupt to be dropped.
- Within the EPxR registers, CTR_TX and CTR_RX are also cleared by writing 0. Ensure that pcd_clear_rx_ep_ctr and pcd_clear_tx_ep_ctr write a 1 to the bit they are not clea...
Thank you very much for your PR. I think we should use the existing OPT_MCU_SAME5X for this board instead adding a new OPT_MCU_SAME51. Unless you have a good reason for that.
If possible, It is also helpful if you could include the board ref link to board.md as well https://github.com/hathach/tinyusb/blob/master/docs/boards.md
you could simply have HWRED ?= 1 then CFLAGS += -DHWREV=$(HWREV)
I have a question, why don't we just use the existing SAME5X instead of introducing the SAME51 ?
I wasn't aware of that. Done
This is because in hw/bsp/board_mcu.h there is an extra define for the SVC_Handler handler. While the code will compile fine without it, the binary won't run on the board. Since I don't have any other SAMX5X devices to test, I thought it prudent to add the extra define.
Function name and comment suggests that it will work on ISTR register.
There is not point in passing register address as argument in my opinion.
I would also get rid of reg16_, it was OK when generic register was modified.
Just opinion.
Thanks for finding so many issues. I had originally copied most of the code from the stm32 HAL, with these bugs included. Since then, the HAL was updated, but this driver was never fixed.
Everything looks good to me in this PR.
In my mind for the ISTR, I didn't want to change the reserved bits since the documentation doesn't say what they do, but that does create the race condition, so what you propose is correct. ST now does the same, so it should work nicely.
This is application/bsp related issue. The tinyusb stack doesn't need to know this difference. This should be resolved at application/bsp level. You could use the macro __SAME51J19A__ or adding bsp own __SAME51__ to the bsp to resolve this.
- Please use the
OPT_MCU_SAME5Xinstead ofOPT_MCU_SAME51 - If possible please also rename the
bsp/d5035-01tobsp/d5035_01, this is optional, it just make the board name consistent with others.
Thank you very much for this superb PRs with lots of works and modification. Due to its large work, I have only reviewed a small portion of this PR. I got into issue with building audio_test example, and attempt to fix it with PR to PR here https://github.com/PanRe/tinyusb/pull/3
I got the stm32f411 enumerated as audio device and response to several of host messages. Though since the audio_test doesn't do much now, we couldn't verify its actual functionality. Though that is definitely can...
also got into issue with macro not defined
I have issue with undef CFG_TUD_AUDIO_TX_DMA_RINGBUFFER_SIZE
error: "CFG_TUD_AUDIO_TX_DMA_RINGBUFFER_SIZE" is not defined, evaluates to 0 [-Werror=undef]
62 | #if CFG_TUD_AUDIO_TX_FIFO_SIZE && CFG_TUD_AUDIO_TX_DMA_RINGBUFFER_SIZE
I think we also need to have
#ifndef CFG_TUD_AUDIO_TX_DMA_RINGBUFFER_SIZE
#define CFG_TUD_AUDIO_TX_DMA_RINGBUFFER_SIZE 0
#endif
To be honest, I don't like the introduction of this function. defragmenting is not a real issue, it is mostly switching between open/close ISO endpoint, which could be addressed in other way like introducing dcd_edpt_iso_open with additional max packet size of all alternate Itf. If you could revert this change and still having the audio_test example running. I will update the ISO and dcd to better support open/close endpoint.
I think you mis-interpreter the request
https://github.com/hathach/tinyusb/blob/440e23c49181687790d9e18e62af501310b62d33/src/common/tusb_types.h#L432
From your capture screenshot the value is received correctly with value = 0x2200 and index = 0x0001 . As mentioned in the PR, the wIndex is the interface number and since each interface only has 1 hid descriptor, therefore the desc_index which is lower byte of wValue = 0x00 is correct.
I think you mixed up the HID report descriptor...
Actually this CFG_TUD_AUDIO_TX_DMA_RINGBUFFER_SIZE is not necessary any more in case of the new unmasked FIFO. I remove it completely.
Very well spotted! Do you think it is worth reworking the defines in audio_device.h such that AUDIO_FORMAT_TYPE_I is an enumeration again?
Thanks for spotting - there are many configurations possible and i did not catch up checking all of them at the end!
Yeah, we could. But it can wait until we finalize the api. There is little different in the usage of macro and enum in this case. There is no hurry at all
Thanks for spotting - there are many configurations possible and i did not catch up checking all of them at the end!
No problem :)
I see your reason why it would be better to have such a configuration parsing within USBD and not in DCD. This totally makes sense since other MCUs may need the same. However, i am not sure if handling ISO EPs without taking care of the remaining EPs is sufficient! Your idea of reserving space only for the ISO EPs is similar to my approach but i also take care that there is space for all used remaining EPs. So an overflow can be avoided and detected at compilation time. Every EP has its dedic...
Your idea of reserving space only for the ISO EPs is similar to my approach but i also take care that there is space for all used remaining EPs.
No I didn't say we will reserve space for ISO only. First of all the only endpoint that get closed and reopened is only ISO. It is unspoken truth that for all the ISO endpoints, its default interface (alternate = 0) must has no endpoint (closed ISO). Therefore ISO will likely be the last endpoints got opened. All other endpoints are opened when...
[hathach/tinyusb] New branch created: fix\-idf\-latest
Describe the PR
IDF change low level usb init sequence, this fix usb not working with latest IDF
Ah now the picture gets clearer. Actually a smart thought! Your are right, the interfaces which need to be activated by SET_INTERFACE will use what is left from the other EPs. I always have this highly complicated picture in mind, where the end user may has multiple multi-interface USB applications running (similar to audio). I guess this comes from reading too many USB specifications ^^. They always suggest you may close interfaces currently not needed in order to allow a bigger interfac...
Ah now the picture gets clearer. Actually a smart thought! Your are right, the interfaces which need to be activated by SET_INTERFACE will use what is left from the other EPs. I always have this highly complicated picture in mind, where the end user may has multiple multi-interface USB applications running (similar to audio). I guess this comes from reading too many USB specifications ^^. They always suggest you may close interfaces currently not needed in order to allow a bigger interf...
Actually, your implementation still need to handle this case of SET_INTERFACE request for changing the endpoint size as well...
Thats acutally not correct, my implementation would recognize ATL 3 and reserve the required 300 in the first place. It determines the worst case i.e. the biggest required FIFO size for every EP ever needed and sets up the FIFO this way. Thus the FIFO never needs to be reconfigured even in case of open/close EPs and it does not need any management.
Regarding ...
Both microphone and speaker in real life require code that is capable of handling sound.
This is very hardware dependent and I don't think we can have out of the box code that will work on more then one platform.
For microphone we can have some sort of noise generator that will produce stream that host can see.
For speaker it is a little more difficult, audio data has to go somewhere.
For my part I'm using I2S microphone and I2S speaker that works with STM32F4 MCUs.
Speaker also works ...
#289 reported an issue with net_lwip_webserver with the 'NXP Transdimension (18 / 43 / iMX RT)' target.
I had access to a MIMXRT1010_EVK, and the issue was nothing more than a too restrictive stack size in NXP's default stack size value in the linker script. A minor tweak to the BSP board.mk by adding LDFLAGS to override the value remedies this.
I suspect the same change will remedy others (most notably the MIMXRT1015_EVK, which should be nearly identical to the MIMXRT1010_EVK), but I'...
With #531, the iMX RT1010 now works, and I suspect the same minor tweak to the stack size will remedy others.
yep looked at the screenshots again and I am not sure what I was thinking on this day. Assumming I just saw the 2201 my brain was expecting and didn't see the 0x00 that came before 0x22 and the one that came after 0x01
realized there is a difference in definition between itf_num and itf. switched this over in the latest code.
everything should be set up now with callbacks depending on if CFG_TUD_HID>1 or not. Let me know if I am missing anything.
Thats acutally not correct, my implementation would recognize ATL 3 and reserve the required 300 in the first place. It determines the worst case i.e. the biggest required FIFO size for every EP ever needed and sets up the FIFO this way. Thus the FIFO never needs to be reconfigured even in case of open/close EPs and it does not need any management.
Yeah, I mean I know you reserve the largest space for ISO. But we still need to resize the ep when SET_INTERFACE with different ep size is re...
Thanks for the PR, it looks great now
thanks, I think this is mostly the symbol difference because of the startup asm code. SAMD51 used the modified/unified version from adafruit https://github.com/adafruit/samd-peripherals . By now, I just realized adafruit just adding same5 support to the repo. But that should be no problems, the tinyusb is a neutral library, application is free to pick any other driver/libraries they like :)
yeah, that happens when we debugging for too long :)
Yeah, I mean I know you reserve the largest space for ISO. But we still need to resize the ep when SET_INTERFACE with different ep size is received. For stm32, maybe we can leave it with max fifo size and should be no issues, other mcus may need different approach. I kind of mixed-up some thought along the way across MCUs approach.
That is correct, the EP needs to know its current size but the FIFO size is fixed to maximum required size so there will never occur any issues once everythin...
it is a bit late, but hid_multiple_interface would be a better name. But no problems, I will do rename later on.
Everything looks good, there are several minors review, but they are all optional. I could do a follow-up pr for that later on. Thank you for putting effort into this PR.
uint8_t const to place this in ROM
great, thanks. Do you know where is the line that make use of stack overflow e.g local dynamic array. I try to see if we could bring it to for say global scope to avoid stack overflow like this.
@PanRe I think this issue could be closed by now since it is implemented by #516
The heavy stack usage is pervasive throughout lwip; every TCP/IP stack that I've ever encountered has been like this.
I might be misunderstanding what you meant here but this should be correct

note these are not from the example so the descriptors aren't mouse then keyboard
yeah I figured since it was eventually going to get corrected and there weren't too many spots to do this in, it was alright being ugly and simple for now.
sorry, i mean mis-indent, btw please also change it to return NULL
I was going to do another push to update some of the items mentioned but then realized I would be pushing a commit that just made the 2nd descripter const and then reduced the example buffer size to 8. Figured those two housekeeping items could be done when n api and combining the helpers is done. I didn't do much, but I am glad I could contribute. I have asked a ton of questions and bugged a few people, so I feel better about myself a little now haha.
since return value is bool, you should return false instead of 0. or you could just simply drop it and just leave
TU_VERIFY(hid_itf<0xFF);
TU_VERFIY has a trick to have 2nd arg as optional.
I was going to do another push to update some of the items mentioned but then realized I would be pushing a commit that just made the 2nd descripter const and then reduced the example buffer size to 8. Figured those two housekeeping items could be done when n api and combining the helpers is done. I didn't do much, but I am glad I could contribute. I have asked a ton of questions and bugged a few people, so I feel better about myself a little now haha.
You are doing great, the PR add v...
The reason I needed the multi interface is that I have a generic HID interface that exchanges bytes and a keyboard interface. If they are the same interface I cannot capture the generic interface in my application because windows won't let you open a keyboard interface. Not sure if the same in other OS.
The reason I needed the multi interface is that I have a generic HID interface that exchanges bytes and a keyboard interface. If they are the same interface I cannot capture the generic interface in my application because windows won't let you open a keyboard interface. Not sure if the same in other OS.
Windows does a good job to prevent keylogger software :D . I am sure others will have a strict limit toward keyboard as well :)
super finding. Don't worry about the rest of the family. I will pull them out in the weekend to test with :+1:
thanks @majbthrd I have updated the 1st post. I will pull out other boards to test with in the weekend.
@majbthrd i just pull-out the rt1020-evk and rt1060-evk to test with
- both 1020 & 1060 work (page loaded) with default stack size of 0x400 on Windows VM
- both failed to load page with default/increased stack size on Linux
Would you mind testing it with Linux machine, since Linux use ECM and Windows use RNDIS, maybe there is a bit of issue somewhere. I am short on time to troubleshoot this for now, but if you could confirm the issue, I will update the 1st post that will make it easier t...
[hathach/tinyusb] New branch created: house\-keeping
Describe the PR
- follow up to #524
- also add generic
flash-pyocdtarget support for bsp with on-board daplink
I does rename the API to remove _n in the callback, and some other clean up work at #532
@PanRe do you have time to revert the dcd synopsys changes ? I would like to merge it this weekend to try to see if I could do further testing with audio this weekend. If you don't have time, I could merge it as it is and do the revert my self afterward (basically overwrite it with the current one) :D. Nice thing is we will have these modification in git log whenever we want to pull it up in the future :D
@hathach , that's so strange, as I used Linux to test the RT1010 port. This weekend, I'll take a more in depth look.
@hathach , that's so strange, as I used Linux to test the RT1010 port. This weekend, I'll take a more in depth look.
That is weird 🤔🤔
@salkinium sorry for late response, this is great idea to solve the shared CAN/USB. I like your last suggestion by checking the actual remap bit. The overhead is too small ( a couple of cycle for bit test) and this aren't call at any fast rate either. Would you mind changing it to dynamic check. Also since it only available to selected chips, it should be wrapped with SYSCFG_CFGR1_USB_IT_RMP e.g
#ifdef SYSCFG_CFGR1_USB_IT_RMP
if ( remapped )
{
use RMP IRQ
}else
#endif
{
us...
Thanks for the great idea with remap, would you mind taking a bit more time to make it dynamically check of the remapped bit in the SYSCFG_CFGR1, that would be perfect.
@PanRe do you have time to revert the dcd synopsys changes ? I hope to merge it this and try to see if I could do further testing with audio this weekend. If you don't have time, I could merge it as it is and do the revert my self afterward (basically overwrite it with the current one) :D. Nice thing is we will have these modification in git log whenever we want to pull it up in the future :D
Done! I had to keep some changes @kasjer introduces for ISO EPs. I also extended the exa...
thank you very much and also @kasjer for this brilliant PR. This will be a very interesting & exciting feature for the stack. I cannot say thank enough to you two.
closed since it should be fixed already by now
thank you very much and also @kasjer for this brilliant PR. This will be a very interesting & exciting feature for the stack. I cannot say thank enough to you two.
You are very welcome. There is still much to do yet! But i am happy that the driver finally made it into the stack! :)
@PanRe I think this issue could be closed by now since it is implemented by #516
Frankly we are not yet done here ^^. The idea was to convert the EP buffers at least for ISO EPs to FIFOs. The merged unmasked pointer FIFOs are now perfectly suited for this task but it still needs to be implemented (if desired).
thank you very much and also @kasjer for this brilliant PR. This will be a very interesting & exciting feature for the stack. I cannot say thank enough to you two.
You are very welcome. There is still much to do yet! But i am happy that the driver finally made it into the stack! :)
Yeah, lots left to be done, especially audio normally involved dsp work. But it is a great milestone 👍
@PanRe I think this issue could be closed by now since it is implemented by #516
Frankly we are not yet done here ^^. The idea was to convert the EP buffers at least for ISO EPs to FIFOs. The merged unmasked pointer FIFOs are now perfectly suited for this task but it still needs to be implemented (if desired).
Yeah, I think it is is best to be implemented in class driver e.g audio or video. Once it is mature enough we can spin it off like what I plan to do with...
@hathach, I think the stack size change that I suggested was unnecessary. I measured peak stack usage at 684 bytes, and that is below the original, default of 1024 bytes. (In turns out my initial problems with running TinyUSB on the IMXRT1010-EVK had a lot more to do with the flaky built-in DAP on the evaluation board.)
I tested the IMXRT1010-EVK using net_lwip_webserver with the original stack size of 0x400 with Windows, Linux, and MacOS. I saw no issue.
@hathach, your mention of EC...
The goal of net_lwip_webserver is example code that works on as many different platforms as possible. Operation under Windows, Linux, and macOS has been tested, but smartphones seem to be under-developed and artificially picky (if not buggy). Given the sheer cornucopia of phone out there, it is probably a losing battle, but I've added comments in main.c with a couple of suggestion on things to try.
Add BSP for Atmel/Microchip ATSAMD21-XPRO
audio_test project is failing on d5035_01; this change should have had nothing whatsoever to do with that
In the ensuing months, I had forgotten that it would inevitably be doomed due to #255
@hathach, I think the stack size change that I suggested was unnecessary. I measured peak stack usage at 684 bytes, and that is below the original, default of 1024 bytes. (In turns out my initial problems with running TinyUSB on the IMXRT1010-EVK had a lot more to do with the flaky built-in DAP on the evaluation board.)
Ah right, daplink is bit slow partly since it is external qspi flash, I have updated the flash-pyocd target, it should be easier to flash.
I tested the IMXRT1010-EVK...
audio_test project is failing on d5035_01; this change should have had nothing whatsoever to do with that
yeah, don't worry, I will fix that right away, it is due to microchip re-invent the assert() macro that conflict with the built-in one. I will probably skip that example for that board.
@majbthrd can you re-open the PR, look like adafruit/asf4 mass commenout the LITTLE_ENDIAN for all variants already https://github.com/adafruit/asf4/blob/circuitpython/samd21/include/samd21j18a.h
I will push the submodule update, please make a merge after that.
[hathach/tinyusb] New branch created: update\-microchip\-driver
Describe the PR
- update microchip driver for #534
- also skip audio_test for same5x for now due to assert() macro conflict
almost perfect, though hand-on testing with f3 disco prove that syscfg clk must be enabled before we could do the remap.
I pull out my f3 disco board to test with, I believe we need to enable the syscfg clk first for the remap to take effect.
__HAL_RCC_SYSCFG_CLK_ENABLE();
__HAL_REMAPINTERRUPT_USB_ENABLE();
``
Whoops, I got distracted with work, so I forgot to test this in hardware. Fixed now.
perfect now, thank you very much for your PR. I will merge when ci passed.
no problem at all, writing code is much harder than testing :)
thank you very much for another brilliant PR :+1: :+1:
[hathach/tinyusb] New branch created: host\-async\-control
Ooops, I will try to do more test, maybe it is some OS setting, btw which Linux distro you are testing with, I am on ubuntu 20.04
I'm testing against: Ubuntu 18.04, Ubuntu 14.04, Windows 7, Windows 10, macOS High Sierra 10.13.16
I'm compiling with: gcc 9.2.1 (ARM 2019-q4)
Thanks for all your hard work, @hathach !
Ooops, I will try to do more test, maybe it is some OS setting, btw which Linux distro you are testing with, I am on ubuntu 20.04
I'm testing against: Ubuntu 18.04, Ubuntu 14.04, Windows 7, Windows 10, macOS High Sierra 10.13.16
I'm compiling with: gcc 9.2.1 (ARM 2019-q4)
Thanks for all your hard work, @hathach !
thanks for your os info. I have updated the 1st post, I will test it out later on. Have to switch on other works. But I think it is probably something min...
Describe the PR
OSAL_QUEUE_DEF was not updated while FIFO was changed
to use unmasked pointers.
Two fields that are crucial to new functionality were left
uninitialized resulting in FIFO slowing down in time.
Additional context
Is your feature request related to a problem? Please describe.
Multiple cores MCUs without RTOS can behave like multiple thread RTOS (each core is a thread), therefore we will need to have mutex to prevent race condition e.g
-fifo mutex
- usbd endpoint claim mutex
Describe the PR
This example code creates USB Audio 2.0 headset device.
Device has two audio interfaces first stereo speaker
with 48kHz stereo stream.
Second interface for microphone with 48kHz mono stream.
This example can be used to start working on audio device.
It can be also used to verify ISO endpoints for boards.
Speaker adaptive clock (bound to SOF).
Microphone for now has asynchronous clock.
Volume and mute control while present are not used for data stream
modifi...
small code and data reduction by:
a) tweaking lwip compile-time options in examples/device/net_lwip_webserver/src/lwipopts.h
b) changing the DHCP server to not store duplicate values of what the stack already knows
brilliant !!! Thank you very much for the PR, I will check + test it out asap :+1: :+1:
Describe the PR
This example code creates USB Audio 2.0 headset device.
Device has two audio interfaces first stereo speaker
with 48kHz stereo stream.
Second interface for microphone with 48kHz mono stream.This example can be used to start working on audio device.
It can be also used to verify ISO endpoints for boards.Speaker adaptive clock (bound to SOF).
Microphone for now has asynchronous clock.Volume and mute control while present are not us...
very minor, would you also wrap the debug in the #ifndef this help when compiling with LOG= option for debugging.
@hathach I will leave fixing FIFO issue for synopsys to you. I'm sure you have better overall vision on how it should be done.
It is not part of the headset code anyway so separate PR addressing this will have chance for better review.
@hathach I will leave fixing FIFO issue for synopsys to you. I'm sure you have better overall vision on how it should be done.
It is not part of the headset code anyway so separate PR addressing this will have chance for better review.
yeah, that makes lots of sense, I will merge this and make an issue for this. Will try to find time this weekend for a better fix.
Thank you very much for this incredible PR. This is really a great working base for us to add more work on UAC2. I really need further reading the UAC2 and more hand-on testing audio class.
The current audio API is a bit technical that needs lots of reading to get it work. I am hoping to simplify it more to make it easier for user. That is for sure more complicate and need a series of following-up PRs.
Is your feature request related to a problem? Please describe.
current synopsys EP FIFO allocation scheme does not support high ISO packet size e.g 192 in #538 . It assumes all FS endpoints packet only has up to 64 bytes. However FS ISO can have up to 1023 bytes.
https://github.com/hathach/tinyusb/blob/master/src/portable/st/synopsys/dcd_synopsys.c#L216
We need a better scheme not only resolve this FIFO OUT, but also open/close/re-open ISO endpoints with different packet size e.g...
In fact we completely forgot this point last time we discussed about the reverted FIFO allocation in dcd_synopsis! We only had IN EPs or the TX part in mind...
I do not want to be annoying but IMHO you need to know upfront the required size of the RX FIFO since you can not change it easily once USB transfers are in progress. Either you fix it statically as you proposed above or you parse through the descriptors and find out how much you need. For the latter option we already have tested co...
Describe the PR
Allow use of internal FS PHY on OTG_HS interface
Additional context
Some ST parts (like STM32F74xxx / STM32F75xxx, maybe others) allow the USB_OTG_FS core to be used with either an external ULPI PHY or an internal full-speed-only (12mbps) PHY. Currently the code assumes than an ULPI PHY is used unless the chip has an internal high-speed PHY (#if defined(USB_HS_PHYC)), with no provision to use the internal FS PHY.
I'm not sure an #ifdef is the right way to do ...
Hi there! I am diving in to TinyUSB because I am interested in using an Adafruit Feather nRF52840 as a USB host for a keyboard.
I have been playing around with modifying the Adafruit clone of the TinyUSB files to enable host mode, but in switching the CFG_TUSB_RHPORT0_MODE to OP_MODE_HOST it looks like I will lose the USB serial device for console logs.
I am trying to figure out what configurations this hardware supports and wonder if it's possible to have a USB host on it at all, ...
@PanRe yeah, actually we don't forgot it, we just don't have time to work on it just yet (as well as bunch of other issues :smiley: ).
- We shift the parsing of the descriptors from dcd_synobsis into usbd.c (put get_ep_size_report() into usbd.c)
- We change dcd_alloc_mem_for_conf() to be called with the generated EP size report i.e. dcd_alloc_mem_for_conf(uint8_t rhport, ep_sz_tt_report_t rep)
Thank you for your suggestion, I will definitely need it when looking at the issue late...
@hathach Do you have plan to support this API for ESP32-S2? Or any update.
no update and no plan, I will work on it when I got some time. Any PRs is welcome.
could you tell me which boards and mcu you are testing with ?
I'm using a custom board with STM32F750V8
please use OPT_MODE_HIGH_SPEED instead, also make sure you test it on actual hardware. Since I don't have the hardware to test with.
you should use the builtin highspeed test instead of introducing new macro, if CFG_TUSB_RHPORT1_MODE is not OPT_MODE_HIGH_SPEED, we can use the fullspeed phy
#if TUD_OPT_HIGH_SPEED
same as above, but you could put the OPT_MODE_HIGH_SPEED into the if (condition)
When the net class driver was originally added to tinyusb, @hathach put in a "TODO should not include external files" comment in ./src/class/net/net_device.h
This PR re-factors the code to remove the dependency on these include files. It also has the benefit of making the net class driver not specific to lwIP, making it more agnostic as to which network stack is chosen by the user.
It does this by putting the lwIP-dependent portion of the code in ./examples/device/net_lwip_webserver/s...
Thank you very much for putting more effort to improve the example. Indeed, I was planning to make tinyusb as neutral and independent as possible with the net driver, but couldn't got the time to do so :)
I'm using tinyusb with an Adafruit SAMD core... I'd like to implement a yield function - as my own code needs to be sure to do something periodically..... But when USE_TINYUSB is defined, main.cpp defines yield() and there is no further hook.
Is there a known approach for doing something during "yield-time" when using tinyusb?
@hollow gust are you using tinyusb with arduino? tinyusb itself lets you control when it runs because you have to call into it
@robust walrus I'm using it with an Adafruit Feather M0 Express - so the Adafruit SAMD core. The issue is that main.cpp in that core has:
#if defined(USE_TINYUSB)
// run TinyUSB background task when yield()
extern "C" void yield(void)
{
tud_task();
tud_cdc_write_flush();
}
#endif
So now there is no way to define your own yield function -- cause it is there.
by core you mean arduino right?
can you just comment that out and supply your own? I don't know arduino
tud_task() is what needs to be called regularly
well - yes... but that's hacking code that is part of an external library - and will get overwritten when updating...
Just thought perhaps tud_task had a hook or there was some magic way I wasn't hip to
you may have better luck asking in arduino
tud_task doesn't have any hooks that I know of
thanks
On Arduino, tinyusb functions can't be called from interrupt routines - right? Specifically I'd like to send and receive MIDI from a timer routine - but it seems to me that the FIFOs in midi_device.c aren't going to be safe.
Is that right?
Describe the PR
close #314
STM recently releasing their driver on github, we should use this for st_driver to simplify the process of updating STM32 driver
Describe the PR
This was a confusing name; "Ethernet control model" (CDC ECM)
and "network control model" (CDC NCM) are two separate USB subclasses.
Additional context
I'm working on a PR to add CDC NCM support to tinyUSB, and this is an initial cleanup step.
Thanks for letting me know. Would you mind sharing which board you use for host development? I am having trouble finding which ones support host mode.
[hathach/tinyusb] New branch created: use\-same51\-from\-asf4
Describe the PR
same5x is added recently to asf4, it is better to re-use it than maintaining its driver ourself.
@jgressmann may want to review this.
[hathach/tinyusb] New branch created: cdc\-auto\-write\-flush
Describe the PR
cdc write() auto call flush if there is enough data in the fifo. fix #463
Hi @duempel. Thank you for working on this. I suspect that this is what I'm looking for. However, currently there are conflicts with the master branch. I've tried to resolve the conflicts myself because I also need patches from the master branch. Probably I did something wrong because I'm getting the following error with the latest version of ESP-IDF:
0 panic'ed (IntegerDivideByZero). Exception was unhandled.
Core 0 register dump:
0x4008b01b: dcd_edpt_xfer at /home/dragon/esp/e...
Hello @dobairoland , thank you for your interest in this feature. Since TinyUSB's master branch has received a lot of updates in the last months, there are currently conflicts with this PR.
I will try to merge the current master into my branch tomorrow to update the PR draft quickly. The further changes to create the final PR will be done in the following days.
If you want to test the changes, I would be very happy. Keeping you updated.
Set up
- PC OS : Windows 10 & Arch Linux
- Board : Custom board based on ESP32-S2
- Firmware: Slightly modified version of examples/device/cdc_msc
Describe the bug
Linux can unmount the disc without any issue. The device cannot be "ejected" using the same firmware on Windows. (The same computer is used)
To reproduce
Linux:
- tud_msc_write10_cb() invoked, lba=2, offset=0 - write root directory
- tud_msc_write10_cb() invoked, lba=0, offset=0...
Alright, I just merged all the changes into the feature branch. @dobairoland you can check if it's working for you now (I sadly don't have an esp32s2 to test here right now - but it's working on other platforms). In a couple of days I also want to finalize the PR with the changes that @hathach requested.
I don't think this is up to tinyusb to do. In order to not appear again you need to track the eject and change the readiness of the drive.
The example doesn't do this because the drive is in RAM and always available. Relevant code is here: https://github.com/hathach/tinyusb/blob/master/examples/device/cdc_msc/src/msc_disk.c#L156
Here is how we do it in CircuitPython: https://github.com/adafruit/circuitpython/blob/main/supervisor/shared/usb/usb_msc_flash.c#L210
Describe the PR
Add implementation of CDC NCM networking interface
Additional context
CDC-NCM is the newest USB class for Ethernet over USB, available here: https://www.usb.org/document-library/network-control-model-devices-specification-v10-and-errata-and-adopters-agreement
It has two main advantages over the earler CDC-ECM:
- Instead of a direct mapping of one control transfer per datagram, NCM packs multiple datagrams into a transfer
buffer ("NTB"), allowing for better ef...
thanks @tannewt for answering, yeah, this is application level code and beyond a usb stack to handle. @dobairoland please analyze the scsi command and its parameter when host issue the msc eject. Then act accordingly to whatever your application want to do.
@tannewt Thank you for the kind help. It is working now.
@hathach I think the example should be ejectable even if the RAM drive is always ready. For example, if I have an USB flash HDD ejected then it is ejected properly and is not showing anymore in "This PC" even though I still have the disk in the USB.
@hathach I think the example should be ejectable even if the RAM drive is always ready. For example, if I have an USB flash HDD ejected then it is ejected properly and is not showing anymore in "This PC" even though I still have the disk in the USB.
It should, would you mind submitting a PR for it ?
Make the disk disappear on Windows after it was ejected. The device needs to be re-inserted or reseted to re-appear again.
This doesn't affect Linux where the device can be mounted and unmounted repeatedly.
Note that this should be applied to three more examples.
@duempel Thank you for resolving the conflicts. Unfortunately, I'm getting the same error as before.
There is no device connected in the beginning when it fails on the first call of tud_cdc_write() for the reason of division by zero here.
I don't have this issue with 075334af80303488a8c874255d725cb4ca15a7de.
I believe that it can work on other platforms because the exception occurs ...
We actually use the non-disappearance in CircuitPython so that we can use "Eject" to flush any remaining writes to the disk, but then not have to unplug and plug it back in. There is no other simple way to flush writes. This is particularly important because Windows in the past has not flushed writes to FAT12 drives for up to 90 seconds. Supposedly this has been fixed in newer versions of Windows 10, but I haven't had a chance to test it yet.
I'd like this to have a compile-time switch to ...
Ok, I've fixed my previous issue with a tud_cdc_available() check.
I'm sorry for posting again. tud_cdc_available() never true for me so tud_cdc_connected() should be used instead. Then I can read with minicom what was sent and works fine for me.
Unfortunately, this doesn't solve my original problem I was hoping to solve: to be able to read and write while DTR is not set.
@dobairoland thanks for your feedback. It's not easy to spot the cause of this issue now. As far as I understand you are using your own user application. Have you tried to run the cdc_msc_freertos example on your esp?
My first thoughts were: It seems that an endpoint transfer (dcd_edpt_xfer) is called before the endpoint was opened correctly. This could happen for example if you write and flush data before calling tusb_init (due to task priority or other reasons). This could also e...
@hathach based on the explained behaviour from my last comment I think it is useful to provide more stability and block application mistakes. In this PR I deleted the tud_cdc_n_connected() check within the tud_cdc_n_write_flush(). What do you think about adding a tud_ready() call or introducing a ready variable for every cdc interface to check before usbd_edpt_xfer calls?
Thank you @duempel for the ideas.
I see in my logs that everything has been initialized.
USBD init
CDC init
MSC init
VENDOR init
It is not possible for my application to write before initialization because TASK A calls tusb_init and after that it starts TASK B which in the end starts TASK C which writes to CDC.
I will try the cdc_msc_freertos example to modify and report back on the results.
The issue can be reproduced with the cdc_msc_freertos example as well by not checking tud_cdc_available() before attempting to read:
Rebooting...
ESP-ROM:esp32s2-rc4-20191025
Build:Oct 25 2019
rst:0x3 (RTC_SW_SYS_RST),boot:0x8 (SPI_FAST_FLASH_BOOT)
Saved PC:0x4002330d
SPIWP:0xee
mode:DIO, clock div:1
load:0x3ffe6100,len:0x8
load:0x3ffe6108,len:0x1814
load:0x4004c000,len:0x9d0
load:0x40050000,len:0x2e30
entry 0x4004c1ec
I (48) boot: ESP-IDF v4.3-dev-1728-g2fc1d7f544-dir...
Describe the PR
Implement dcd_edpt_close() to esp32-s2. This referred to st/synopsys implementation.
Additional context
The examples which support esp32-s2 are tested, include a modification version of uac2_headset.
Relate to #340.
Another way to do this is to un-set the is_removable flag in the SCSI INQUIRY response, https://github.com/hathach/tinyusb/blob/a65a0a7996f7ff4cdd50b8d229fb8f9ea01695d1/src/class/msc/msc_device.c#L339
look good but I think the comment has a typo
hmm the comment should be until ejected without NOT.
Wow, thank you very much for this great PR, this NCM is definitely new to me. This looks really good at quick look, though since it is pretty big addition, It will take time for decent review, I will try to review as much as I could. Meanwhile since it is still WIP, I will mark it as draft PR, feel free to mark it as ready when you think it work reliably.
@majbthrd is probably also interested in this PR as well.
Describe the PR
Rework USB host control, enumeration, hub and part of msc, hid driver to work asynchronously. Still plenty of work left.
My first thoughts were: It seems that an endpoint transfer (dcd_edpt_xfer) is called before the endpoint was opened correctly. This could happen for example if you write and flush data before calling
tusb_init(due to task priority or other reasons). This could also explain why it's working with use oftud_cdc_available()ortud_cdc_connected(). The use could delay your endpoint access calls until it's fully initialized.
All other API must be called after tusb_init(), applica...
thank you for your PR, can I ask whether you work for espressif. Since you seem to undo their PR https://github.com/hathach/tinyusb/pull/454
esp32s2 has less fifo than endpoint, which is _allocated_fifos for, it is the number of fifos.
thank for the PR, will merge and correct the comment as follow up
Speaking personally, the things that I'd like to see are:
-
either move NCM class driver files into ./src/class/net or we move existing ./src/class/net/ into ./src/class/cdc; having some CDC network implementations be more CDC than others doesn't make sense; thoughts from @hathach ?
-
Share a single ./src/class/net/net_device.h with the same "Application API" and two sets of "INTERNAL USBD-CLASS DRIVER API": one for ECM/RNDIS and one for NCM.
-
MOST IMPORTANTLY: adopt the exac...
[hathach/tinyusb] New branch created: initial\-same7x
Describe the PR
- Clean up microchip sam mcu driver
- Also add initial work for same70: able to have led, button and uart working
currently I am using MCB LPC1857 board as main develop platform for host stack.
@dobairoland sorry for my late reply. The initialization process you described with task A,B and C seems to be good. But even in this scenario task C should not directly write to a cdc interface. The init call only prepares memory for cdc to work. But it is not opening an endpoint. This is done by the usb host when setting a configuration. You can see when a configuration is set within the log:
USBD Setup Received 00 09 01 00 00 00 00 00
Set Configuration
Open EP 81 with Size = 8...
Did you only remove the tud_cdc_available() check from the example and did not change anything else?
Yes, that was the only change:
diff --git a/examples/device/cdc_msc_freertos/src/main.c b/examples/device/cdc_msc_freertos/src/main.c
index 71225588..8cf013fe 100644
--- a/examples/device/cdc_msc_freertos/src/main.c
+++ b/examples/device/cdc_msc_freertos/src/main.c
@@ -169,7 +169,7 @@ void cdc_task(void* params)
while ( 1 )
{
// is data available to read from...
@me-no-dev do you have any update on the PR, do you think it is ready for review and merge. It is OK if is not ready yet, just want to check the status.
make BOARD=esp32s2_saola_1 PORT=1 DEBUG=1 LOG=2 all
PORT=0 or just drop PORT=
thanks @majbthrd for detail review, I agree the NCM and ECM/RNDIS should share the same API to make it easier for network stack to work with. @j4cbo I haven't looked at the code just yet, but whenever you think it is needed, you could also change the current usbnet ECM/RNDIS API so that it also work the same way as NCM as well.
I'm sorry but I tried the following sequence of commands but still I see no tinyusb debug output in the log. The output remains the same as I posted earlier.
rm -r _build/
make BOARD=esp32s2_saola_1 DEBUG=1 LOG=2 all
make BOARD=esp32s2_saola_1 PORT=1 flash
ah esp32s2 doesn't get LOG= option support, please try to modify the tusb_config.h directly to enable it https://github.com/hathach/tinyusb/blob/master/examples/device/cdc_msc_freertos/src/tusb_config.h#L72
#define CFG_TUSB_DEBUG 1
Thank you for the help. So I see only this:
USBD init
CDC init
MSC init
Guru Meditation Error: Core 0 panic'ed (IntegerDivideByZero). Exception was unhandled.
There is nothing else from tinyusb in the log.
A few questions and then details about where I'm coming from
- whats the status of the STM32L4 port?
- do I need to edit the descriptors in the miditest example to make a windows PC recognise it?
- if integrating into a project using ST's HAL libraries, should I configure the USB peripheral first using their routines, or not?
- if not, is the hang in dcd_synopsys.c known about? is there a workaround?
- how is the tinyusb interrupt handler hooked up? I can't see anything in the tinyusb co...
Sorry @hathach :) finishing up some Arduino work and then will move back onto USB. In a mean time the missing fixes have landed onto master, except the edit for idf-monitor. After some deeper research, changing the behaviour there made some development boards and environments non-working. The team is hoping that an option to ignore DTR will be merged here soon :)
hello! I was able to make a bit of progress, so I can close this now but in case anyone finds this and wonders the same things as me:
- the STM32L4 port seems to work for midi!
- I discovered that I hadnt copied the hw/bsp/ folder over to my project, and so when searching for the interrupt handler's caller, I failed to find stm32l476disco.c; from that file I learned that it was simply a case of declaring this function in your code, this is weak linked by default to a stub:
`void OTG_FS_IRQ...
Why do the releases contain the date in the name? this is redundant and creates unnecessary clutter
I like it that way, what is the reason to not include it ?
There is nothing else from tinyusb in the log.
there is divide by zero exception, the cpu is hanged. You should try to see at where and when this happens.
@me-no-dev no problem at all, we are all busy, which is a good (and bad) thing :). Oh, I don't know you are waiting for the ignore DTR, there is working in progress PR here #506 . I plan to review and work on it this weekedn, will try to get it merge in a week a so.
L4 is work in progress, work here and there but also break left and right. you could subscribe to its own issue for update. Though currently I don't have much time to work on L4.
there is divide by zero exception, the cpu is hanged. You should try to see at where and when this happens.
I already did since that is what I'm getting from the beginning. I started with my own application then I was asked if I could reproduce it with the cdc_msc_freertos example. I had to remove only the tud_cdc_available() check: https://github.com/hathach/tinyusb/pull/506#issuecomment-723971780
It clutters the release names, and eventually the archive links, the date is shown on the releases page right under the name.
But if you like it that way there are no major issues I don't think.
I don't see any issue with link or archive as you mentioned. Can you be specific on the name and link by posting it here
You're right it doesn't affect the link, my bad. Again no real issues here, If you have preference for that format.
@hathach have reverted this part back, please check.
can you please explain this calculation?
It's a workaround provided by @hathach in #540 , but actually need better solution.
this is based on recommended by stm32 guide, however, it is not optimal for non-ISO application. I plan to work on a better fifo allocation scheme later on. I think it is probably best to leave this PR pending until we get thing settled with stm32 first. 2 moving targets are harder to work with than 1.
@hathach I finally got some minutes to make the changes you suggested within your review. I kept this PR as draft, because I just add some changes to cdc example code, which I don't know if you like them. But we can make this to merge very soon. 😉
The updated cdc example uses tud_cdc_rx_cb callback to recognize if there is a connected terminal. If we receive character here we can be pretty sure that a connection is set up. Within the callback we then check the line state and can print in...
@dobairoland it's very difficult to help you debugging because I do not have the ESP here. But you could check if the error still occurs if you do the following changes:
-
Add
TU_VERIFY( p_cdc->ep_out, );at the beginning of_prep_out_transactionin cdc_device.c #L85 -
Add
TU_VERIFY( p_cdc->ep_in, 0 );at the beginng oftud_cdc_n_write_flushin cdc_device.c [#L180](...
I'm getting a different behavior with the new commits in this PR.
USBD Xfer Complete on EP 03 with 31 bytes
MSC xfer callback
SCSI Command: Test Unit Ready
Queue EP 83 with 13 bytes ... OK
USBD Xfer Complete on EP 83 with 13 bytes
MSC xfer callback
SCSI Status: 0
Queue EP 03 with 31 bytes ... OK
USBD Xfer Complete on EP 03 with 31 bytes
MSC xfer callback
SCSI Command: Test Unit Ready
Queue EP 83 with 13 bytes ... OK
USBD Xfer Complete on EP 83 with 13 bytes...
Here are the logs with the requested changes:
USBD Xfer Complete on EP 83 with 13 bytes
MSC xfer callback
SCSI Status: 0
Queue EP 03 with 31 bytes ... OK
USBD Setup Received 21 22 03 00 00 00 00 00
CDC control request
Set Control Line State: DTR = 1, RTS = 1
Queue EP 80 with zlp Status
USBD Xfer Complete on EP 80 with 0 bytes
USBD Setup Received 21 20 00 00 00 00 07 00
CDC control request
Set Line Coding
Queue EP 00 with 7 bytes
USBD Xfer Complete on...
Describe the PR
Current class driver hooks for control transfer is only control_request (setup stage) and control_complete(data stage). There is a need to introduce control_ack_complete() that invoked when the zlp of ack stage is complete. However, 3 callbacks with the same signature is a bit too much,. This PR merge 3 of them into control_xfer_cb(rhport, stage, request)
Note: the reason to add callback for status complete is for request such as CDC tud_cdc_line_state_cb, hand...
thanks @duempel sorry for being late on response, I am on the run with other issue. And don't worry too much about the ESP if you don't have the mcu to test with. Just focus on what you think and could best test for the PR, I will do the test on esp32s2 and fix it if needed later on. This PR will be probably used very often by esp32s2 user. @dobairoland would you mind moving the log on a gist or something, the long log make pr discussion more difficult to follow.
However, 3 callbacks with the same signature is a bit too much,.
It's your code; I'm just a contributor :P. But I don't agree with this.
From skimming your changes, putting all the callbacks into one function creates a rather large control_xfer_cb function. You can trim control_xfer_cb by calling into the real inlined callbacks in each branch of the if/else chain. But isn't that inlining equivalent to what you're already doing before this change :P? This seems like more w...
However, 3 callbacks with the same signature is a bit too much,.
It's your code; I'm just a contributor :P. But I don't agree with this.
From skimming your changes, putting all the callbacks into one function creates a rather large
control_xfer_cbfunction. You can trimcontrol_xfer_cbby calling into the realinlined callbacks in each branch of theif/elsechain. But isn't that inlining equivalent to what you're already doing before this change :P? This seems li...
would you mind moving the log on a gist or something, the long log make pr discussion more difficult to follow.
I'm sorry. I moved them into files.
Setup
Setup 1:
PC OS: Windows 10
Board: Seeeduino Xiao (samd21),
Firmware: examples/device/usbtmc
Setup 2:
PC OS: Raspberry Pi OS (using pyvisa 1.11.1, pyvisa-py 0.4.1)
Board: Seeeduino Xiao (samd21),
Firmware: examples/device/usbtmc
Describe the bug
On Windows 10 pyvisa (using NI VISA backend) will not report the device.
On Raspberry Pi pyvisa reports the device, but the resource manager is unable to connect.
To reproduce
Steps to reproduce the behavior:
- ...
Affected versions
At least 0.7.0 and latest master (589dfdb)
Describe the bug
It's a simple coding bug in tusb_init() implementation:
bool tusb_init(void)
{
// skip if already initialized
if (_initialized) return true;
#if TUSB_OPT_HOST_ENABLED
TU_ASSERT( tuh_init() ); // init host stack
#endif
#if TUSB_OPT_DEVICE_ENABLED
TU_ASSERT ( tud_init() ); // init device stack
#endif
_initialized = true;
return TUSB_ERROR_NONE;
}
The functio...
I tried examples/device/hid_generic_inout and had no issues with the compile and uf2 programming. I was able to run the example without any issues.
I don't fully understand the idea behind returning error code / status from this function if it uses TU_ASSERT to handle errors... Even if we fix it to return true on correct initialization, it will never be able to return false because of those assertions...
Ah right, thank you for openning the issue, this is left over from legacy code. will fix it right away.
@hathach That was fast. Thank you! :+1:
you are right, we have to add a check whether usb is enumerated to prevent executing edpt_xfer(). I will do it in a follow up PR
It is not necessary for example to send out the warning. I will do a follow up clean up
A bit of testing does show it work rather well as currently. I didn't know any terminal that doesn't set DTR to test with with the overwritable, but the code look good enough. Since it has been going for a while, I will merge it now and do a follow up with tud_ready() check
@hathach thanks for merging your latest changes in here. If you want to test out the functionallity I could recommend HTerm to you. Usually I use this terminal on windows, but it's also available for linux. HTerm has the ability to manually control DTR and RTS bits with buttons.
Since it has been going for a while, I will merge it now and do a follow up with tud_ready() check
Alright, I feel good with this. Thanks for your help and I'm happy we finally get this to master.
@dobairoland I couldn't reproduce your issue with my esp32s2 saola board but omitting the tud_cdc_available() in the example. If you still has the issue merged master, please open the issue and provide way to reproduce it including software terminal and os which you are using.
@hathach thanks for merging your latest changes in here. If you want to test out the functionallity I could recommend HTerm to you. Usually I use this terminal on windows, but it's also available for linux. HTerm has the ability to manually control DTR and RTS bits with buttons.
Since it has been going for a while, I will merge it now and do a follow up with tud_ready() check
Alright, I feel good with this. Thanks for your help and I'm happy we finally get this to master.
...
@HiFiPhile and @me-no-dev may be interested in this merged PR, let me know if there is an hiccups
@HiFiPhile and @me-no-dev may be interested in this merged PR, let me know if there is an hiccups
Will try in a day or two and report back :) thanks!
@me-no-dev may need to modify IDF since the tusb_init() has been returned the incorrect code due to legacy error code (removed currently)
https://github.com/espressif/esp-idf/blob/master/components/tinyusb/additions/src/tinyusb.c#L107
I am the one to say thanks, normally I couldn't be that fast, but thankfully this one is easy enough to fix.
I did notice this in DMESG on the raspberry pi:
[ 2.214996] usb 1-1.4: new full-speed USB device number 4 using xhci_hcd
[ 2.354164] usb 1-1.4: New USB device found, idVendor=cafe, idProduct=4000, bcdDevice= 1.00
[ 2.354184] usb 1-1.4: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 2.354202] usb 1-1.4: Product: TinyUSB Device
[ 2.354218] usb 1-1.4: Manufacturer: TinyUSB
[ 2.354234] usb 1-1.4: SerialNumber: 123456
**[ 2.359368] usb 1-1.4: can't set con...
#557 slightly change the control transfer callback for the driver by introducing the stage (setup/data/ack) argument. You probably may want to update the driver. It does not change the driver much, but still need to update a bit.
[hathach/tinyusb] New branch created: add\-tud\-connected
Describe the PR
which return true as long as we receive the very first SETUP packet from host.
requested by @dhalbert
[hathach/tinyusb] New branch created: correctly\-invoke\-scsi\-callback
Describe the PR
There has been some race condition between host software and device handling with scsi complete callback. E.g windows complain when reboot from bootloader to application since status is not yet sent to host. This fix #375
@dhalbert may want to give it a try with issue on internal flash file system on nrf52840, or maybe pointing the user with the issue to test with this.
I tried using my itsybitsy_m4 (SAMD51) and it has the exact same issue.
What gdb server do people use for tinyusb dev?
@pseudo sinew I’ve seen some comments mention using openocd
Well, OpenOCD running GDB Server
have you managed to get the stack log with LOG=1 or 2 option. Also you should try to test with PC first, when it all works well, then test with RPI later on.
PS: just realize itsybitsy bsp doesn't have board_uart_read/board_uart_write implemented just yet, you need to implement that first before getting the log. I will add it later when I have time.