Open ohmtech-rdi opened 1 year ago
Hi Raphael! I'm sorry for the delay in response. Thank you for documenting and reporting the issue as well as a temporary workaround.
We'll have a closer look at this when we get a chance.
@ohmtech-rdi
So I haven't quite been able to reproduce this yet, but I have seen the occasional windows warning complaining of an unknown device. This doesn't seem to exactly match what you're running into, but it could very well be related.
Most of the class functions (CDC_Transfer/Receive Packet) seem to fail safely if the USB has not completed setup.
Do you have any other code that would execute within that first 1000ms delay you posted as a workaround that would block IRQs from happening? That would likely result in an actual failure to negotiate the setup with the host rather than to just fail to print.
A few things that would make this easier to track down (and to potentially avoid) would be a bit of added error handling to both the Logger, and the UsbHandle classes, as well as the ability to check current connection/USB status.
I'll continue to look into this. There are a few other USB related things I'll be looking at over the next week or so. As I find more I'll let you know.
If you could provide a minimal example that triggers this error for you (even if only intermittently) that would be quite helpful. Thanks!
Description
When using the Logger over "internal USB", logging either does work, or doesn't work at all, or just a few frames of logs are received and then it doesn't work anymore.
Analysis
After
impl_.Init();
is called,PrintLine
will immediately start toCDC_Transmit_FS
. At some point of time, aOTG_FS_IRQHandler
interruption will be fired, in which it will setup the CDC. Typically when the bug happens:The first time
CDC_Transmit_FS
is called:hcdc
isNULL
, and it seems thathcdc
is big enough for theTxState
to be mapped to an address that can be at least read.Workaround
I introduced a delay between
impl_.Init();
and beforeCDC_Transmit_FS
is first called:And that seems to solve it, at least when the program is living in the
FLASH
section.