That would line up with the area that I've found to be flaky in the Pi USB - plug/unplug events. It could even be triggering the documented erratum RP2040-E5 from the datasheet.He has now confessed that he's turning on some powerful 230V equipment that is physically nearby. Apparently that causes the USB connection to go burp, that Linux no longer sends or at least the RP2040 no longer receives the stuff the applications try to send.
I think that the practical solution to this is some kind of watchdog on USB traffic and a hard reset if necessary to force a clean re-enumeration, but I've not yet found out how to do that. A hard reset of the USB peripheral is easy, but how to unwind and restart TinyUSB is more of a challenge.
Getting a dual CDC interface is easy - just increment the number of CDC interfaces in tusb_config.hDo you happen to know a howto that explains what to do to get the dual CDC interface? This was in the demo for a recent chibios. I've switched to RP2040 a couple of years ago, but now I'm working on a project that DOES use chibios on STM again, and I'm happily using that feature. I haven't googled yet. Maybe I should. ... OK. I did. Not really a clean example for pico found. Might be possible to piece together from various other examples. If you know a good example, I'd appreciate it if you'd let me know.
Code:
#define CFG_TUD_CDC 1
There's three pieces of knowledge you are after:
1) How to get your own CDC interface rather than the one that's magically generated behind the scenes by stdio in the default builds. This is relatively straightforward - you need to have your own tusb_config.h and usb_descriptors.c in your build (but can probably pinch the ones out of the SDK as a basis), and tinyusb_device in the target_link_libraries of your CMakelists.txt. You then need to call tud_init() in your initialisation, and poll tud_task() repeatedly in your main loop.
I also find I need this:
Code:
# Make sure TinyUSB can find tusb_config.htarget_include_directories(my_project_name PUBLIC ${CMAKE_CURRENT_LIST_DIR})
3) How to get the SDK to use one of your CDCs for stdin/stdout. This is the easy bit: if you enable pico_enable_stdio_usb(my_project_name 1) in a project that already has tinyusb_device in it, then it just takes over the first CDC interface (interface zero) and uses that for stdio, supressing the stuff it usually does to secretly call tud_task() when you are not looking.
Here are a couple of links out of my bookmarks that I found helpful when I was exploring this, but note that they don't cover everything and don't always do things the right way - I spent some time reading the tinyUSB source code to figure things out. I'd be like to share some of my code, but I don't have time to sanitise it right now.
https://mixi-developers.mixi.co.jp/cont ... ad29dbf49b
https://github.com/Noltari/pico-uart-bridge
Statistics: Posted by arg001 — Tue Jul 23, 2024 8:06 pm