Attempt at enabling TinyUSB with microzig #728
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Introduction
Figured I'd share my progress so far in enabling tinyusb with microzig.
This compiles tinyusb + pico-sdk headers into a static library and links to the firmware.
The short of it is that this seems to work for RP2040 from my limited testing with one significant issue where the USB reset wait seems to stall (but during earlier testing it did not).
When this does happen, I can work around it by commenting out
unreset_block_wait(RESETS_RESET_USBCTRL_BITS);in/.../rp2040_usb.c:rp2040_usb_initno clue what is going on there.Anyway, I don't think this is close to be ready to be pulled in but I am curious to get some feedback from people who might know what they are doing, I embarked on this as a learning exercise and stumbled through it.
Usage example here: https://github.com/Kytezign/rp2xxx_tusb_lib_build
Please let me know your thoughts.
Structural
Tinyusb submodule
I've added a tinyusb module into the microzig project and added it as a new dependency. That tinyusb sub-project is a build script plus a few missing dependencies required for the pico-sdk headers. Currently it also is puling
/usr/arm-none-eabi/include. It seems like that should be relatively easy to move away from but I'm not sure what the best option would be short of just copying the missing header files.The submodule pulls in a specific pico-sdk and related changeset if tinyusb (based on what the pico-sdk points to as a git-submodule). I don't really want to say too much about the actual build flow because I've more or less just stumbled into something that happens to work. But at a high level I've added a function into microzig that links a library to the firmware being built and adds the relevant tinyusb headers to the root module.
In addition to that microzig submodule, there is also a new file in the RP2040 hal area which exports a few functions also needed. A lot of it is related to debugging tinyusb (not needed when debug logging is disabled).
In the end I've done pretty limited testing - only CDC so far.
Issues
There are a lot of issues currently I'm sure, but the ones I'm most keenly aware of are: