-
Notifications
You must be signed in to change notification settings - Fork 5
feat(USB-OTG): Add USB-OTG CDC RX/TX support #41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
👋 Hello radimkarnis, we appreciate your contribution to this project! Click to see more instructions ...
Review and merge process you can expect ...
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds USB-OTG peripheral support for ESP32-S2, ESP32-S3, and ESP32-P4 chips, enabling data transmission and reception through USB-OTG CDC-ACM interface. The implementation follows the library's three-layer architecture with public APIs, implementation layer, and target-specific overrides.
Key Changes:
- Added USB-OTG CDC-ACM communication support with TX buffering and RX callbacks
- Implemented reset handling via RTS line state detection
- Added target-specific implementations for ESP32-S2/S3/P4 with appropriate interrupt routing
Reviewed changes
Copilot reviewed 19 out of 23 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/usb_otg.c | Main USB-OTG implementation with TX buffering, RX callbacks, and reset detection |
| src/target/esp32s3/src/usb_otg.c | ESP32-S3 specific USB-OTG interrupt setup and reset handling |
| src/target/esp32s2/src/usb_otg.c | ESP32-S2 specific USB-OTG implementation with interrupt matrix routing |
| src/target/esp32p4/src/usb_otg.c | ESP32-P4 specific implementation with CLIC interrupt handling |
| src/target/common/src/usb_otg.c | Weak default implementations for unsupported chips |
| src/target/base/include/target/usb_otg.h | Internal API header for target layer |
| include/esp-stub-lib/usb_otg.h | Public API header for library users |
| src/target/esp32s3/include/soc/rtc_cntl_reg.h | RTC control register definitions for ESP32-S3 |
| src/target/esp32s3/ld/esp32s3.rom.api.ld | Added esp_rom_isr_mask ROM API mapping |
| src/target/esp32s2/ld/esp32s2.rom.api.ld | Added esp_rom_isr_mask ROM API mapping |
| src/target/esp32p4/ld/esp32p4.rom.api.ld | Added esp_rom_isr_mask ROM API mapping |
| CMakeLists.txt | Added usb_otg.c to main library sources |
| Various target CMakeLists.txt | Added usb_otg.c to target-specific sources |
74d383f to
cb3e9fb
Compare
|
@radimkarnis Before diving into the review, I wanted to discuss the approach to conditional compilation in this PR. I noticed a large #if block in I think now is the right time to discuss this, as I'm seeing an increase in #if block usage across the codebase. I’d love to hear your thoughts. Was there a specific challenge that made the weak/strong pattern hard to apply here, or would you be open to refactoring this to match the UART approach? |
|
@erhankur yes, thank you for your concern! That's also my everlasting question: how to do this correctly. Putting most of the code into src/ (public interface) and not defining the functions in common/ (as weak defaults) introduces the need for an #ifdef, but reduces the need to repeat all of the implementations when a new target will have to be introduced.
Adding new features to the stub-lib is now showing us with @Dzarda7 how much work really has to be done to support a target, and we are starting to really consider how many files we add and how many things will have to be re-implemented. This is a real trade-off between architectural purity (no #ifdefs) and practical maintainability (less boilerplate). I am definitely open to refactoring this the way we agree on, but I also feel like now that we are "in the trenches", we start to feel new challenges and the real scale of the project. Let's decide if we really want to avoid #ifdefs or if we agree to at least localize them to a certain layer. |
|
@radimkarnis Thanks for the explanation. I agree this is a real trade-off, and I’m open to balancing architectural cleanliness with practical maintainability. OK. Let's try to keep such conditionals (SOC_CAPS only) localized and limited. We can revisit the structure if this pattern starts to grow. |
erhankur
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
I know we discussed the #ifdefs in usb-jtag-serial already where we kept it. But I thought about it again and I think it might be really hard to track what is going on in the code now as target specific stuff is now not just in target folder, but also in src folder. I would either put it into target/common or use the per target folders. I am a bit pro architectural cleanliness, but no strong opinion. Both has some tradeoffs.
Feel free to keep the #ifdefs but I believe we should keep them at least on target level if possible. |
cb3e9fb to
c5df728
Compare
We should avoid per target ifdefs. I am fine with soc capabilities under src/ . We should not propogate to the bottom.
Couldn't we simplify/divide functions as common+target specific? I believe recent targets have same pattern for most of the peripherals. |
I did not mean per target, I meant soc caps, but to do it here, as I believe top-level c files in main src folder should be target agnostic, but I might be wrong here.
Yes, no issue for now as we mostly have RISC-V targets in common and xtensa in per target. I meant for the future where there might be some changes like when comming from xtensa to RISC-V and then we need per target. There is definitely a way to solve this again, just something to be aware of for the future. |
c5df728 to
b50a3ce
Compare
|
Thank you for all opinions. After our discussion, I will now merge this, but I am open to changing the architecture. We will soon see how much workload it is to add a new target; we can refactor based on this info afterwards. |
dobairoland
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Uh oh!
There was an error while loading. Please reload this page.