CH32X035 port#3703
Conversation
Seems like v103, do you have board to test with ? |
|
| target | .text | .rodata | .data | .bss | total | % diff |
|---|---|---|---|---|---|---|
| ch32v103c_bluepill/dfu_runtime | 8,668 → 8,796 (+128) | — | — | — | 9,036 → 9,164 (+128) | +1.4% |
| ch32v103c_bluepill/hid_generic_inout | 9,648 → 9,780 (+132) | — | — | — | 10,016 → 10,148 (+132) | +1.3% |
| ch32v103c_bluepill/hid_multiple_interface | 10,484 → 10,616 (+132) | — | — | — | 10,852 → 10,984 (+132) | +1.2% |
| ch32v103c_bluepill/hid_boot_interface | 10,504 → 10,632 (+128) | — | — | — | 10,872 → 11,000 (+128) | +1.2% |
| ch32v103c_bluepill/hid_composite | 10,732 → 10,856 (+124) | — | — | — | 11,100 → 11,224 (+124) | +1.1% |
| ch32v103c_bluepill/midi_test | 10,832 → 10,956 (+124) | — | — | — | 11,200 → 11,324 (+124) | +1.1% |
| ch32v103c_bluepill/cdc_dual_ports | 11,848 → 11,976 (+128) | — | — | — | 12,216 → 12,344 (+128) | +1.0% |
| ch32v103c_bluepill/printer_to_cdc | 12,016 → 12,144 (+128) | — | — | — | 12,376 → 12,504 (+128) | +1.0% |
| ch32v103c_bluepill/audio_test | 12,124 → 12,252 (+128) | — | — | — | 12,508 → 12,636 (+128) | +1.0% |
| ch32v103c_bluepill/dfu | 12,912 → 13,044 (+132) | — | — | — | 13,376 → 13,508 (+132) | +1.0% |
I don't have the board unfortunately. I may take a look if I need a 5V capable mcu though (although py32f07x is also 5V capable but has additional DACs unlike v103) |
Got claude to analyze the discrepency, here's the output verbatim: |
dcd_edpt_xfer() re-enabled the USB interrupt before update_in() / ep_rx_set_response(), which read-modify-write the (combined) EP control register. On CH58x the ISR RMWs that same register to flip the manual data toggle, so a transfer interrupt landing mid-RMW could drop the toggle flip and desync the endpoint. Move dcd_int_enable() to after the arming so the whole sequence is atomic w.r.t. the ISR (matching the CH32X035 port hathach#3703). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
thank you, after #3515, this should be relatively easy. I have the CH32X035 board but run out of wlinke debugger (attached to hil rig). will get this mcu ported when it got on my desk |
|
I also simplified the comments, since I found a hallucination involving X035.
|
|
According to the manuals, it says only EP4 needs manual toggling, maybe manual toggle should only be enabled for EP4? |
Hardware-in-the-loop (HIL) Test Reporthfp.json✅ 46 passed · ❌ 10 failed · ⚪ 0 skipped · blank not run
tinyusb-esp.json✅ 12 passed · ❌ 12 failed · ⚪ 0 skipped · blank not run
tinyusb.json✅ 21 passed · ❌ 326 failed · ⚪ 17 skipped · blank not run
|
|
Hi, I see many comment changes, please verify are they intended. |
|
Yes they are intended, since there was a hallucination about the x035 and I was concerned there are more, so I got my agent to shrink all of them so they can be verified easily |
|
Many comments are from Ha Thach like
They shoudn't be removed. |
7f1322b to
d2b4873
Compare
Size Difference ReportBecause TinyUSB code size varies by port and configuration, the metrics below represent the averaged totals across all example builds. Note: If there is no change, only one value is shown. Changes >1% in size
Changes <1% in sizeNo entries. No changes
|
Signed-off-by: HiFiPhile <admin@hifiphile.com>
Signed-off-by: HiFiPhile <admin@hifiphile.com>
Signed-off-by: HiFiPhile <admin@hifiphile.com>
Signed-off-by: HiFiPhile <admin@hifiphile.com>
|
@claude review |
|
Claude encountered an error after 6m 4s —— View job Review in progress
|
There was a problem hiding this comment.
Pull request overview
Adds a new WCH CH32X035 (and intended CH32X033) TinyUSB port by wiring the MCU into TinyUSB’s MCU selection/dependency system, introducing a new BSP family + board, and extending the shared WCH USBFS DCD to handle CH32X035’s endpoint register/buffer quirks (notably EP4 and combined TX/RX control behavior).
Changes:
- Add CH32X035 as a supported MCU option and dependency (OpenWCH SDK) and document it in README/docs.
- Extend
dcd_ch32_usbfs.c+ WCH register glue for CH32X035-specific register layout/buffer handling. - Introduce a new BSP family (
hw/bsp/ch32x035) with build/linker/OpenOCD support and a WeAct board definition.
Reviewed changes
Copilot reviewed 32 out of 32 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| tools/get_deps.py | Adds the OpenWCH ch32x035 SDK dependency. |
| src/tusb_option.h | Introduces OPT_MCU_CH32X035 (MCU selection constant). |
| src/portable/wch/dcd_ch32_usbfs.c | Updates WCH USBFS DCD for CH32X035 register/buffer and EP0/EP4 handling. |
| src/portable/wch/ch32_usbfs_reg.h | Adds CH32X035 register header integration and WCH USBFS feature flags. |
| src/common/tusb_mcu.h | Enables WCH USBFS USBIP for CH32X035. |
| README.rst | Documents CH32X033/CH32X035 under supported CPUs. |
| hw/bsp/ch32x035/wch-riscv.cfg | Adds OpenOCD config for WCH RISC-V + WLinkE. |
| hw/bsp/ch32x035/system_ch32x035.h | Adds system header for CH32X035 BSP. |
| hw/bsp/ch32x035/system_ch32x035.c | Adds system clock implementation for CH32X035 BSP. |
| hw/bsp/ch32x035/linker/ch32x035.ld | Adds linker script for CH32X035 memory layout. |
| hw/bsp/ch32x035/family.mk | Adds Make-based family build configuration for CH32X035. |
| hw/bsp/ch32x035/family.cmake | Adds CMake-based family build configuration for CH32X035. |
| hw/bsp/ch32x035/family.c | Adds board API + interrupt handlers for CH32X035 BSP. |
| hw/bsp/ch32x035/ch32x035_it.h | Adds interrupt handler declarations for CH32X035 BSP. |
| hw/bsp/ch32x035/ch32x035_conf.h | Adds WCH peripheral library config header for CH32X035 BSP. |
| hw/bsp/ch32x035/boards/weact_ch32x035_core_board/board.mk | Adds board-specific Make overrides (clock, memory sizes). |
| hw/bsp/ch32x035/boards/weact_ch32x035_core_board/board.h | Adds WeAct board pin/LED definitions. |
| hw/bsp/ch32x035/boards/weact_ch32x035_core_board/board.cmake | Adds WeAct board-specific CMake definitions. |
| examples/device/uac2_speaker_fb/src/audio_debug.py | Updates PID used by the audio debug helper. |
| examples/device/uac2_speaker_fb/skip.txt | Adds CH32X035 (and other WCH MCUs) to skip list for this example. |
| examples/device/uac2_headset/skip.txt | Adds CH32X035 (and other WCH MCUs) to skip list for this example. |
| examples/device/net_lwip_webserver/skip.txt | Adds CH32X035 to skip list. |
| examples/device/midi_test_freertos/skip.txt | Adds CH32X035 to skip list. |
| examples/device/hid_composite_freertos/skip.txt | Adds CH32X035 to skip list. |
| examples/device/cdc_msc_freertos/skip.txt | Adds CH32X035 to skip list. |
| examples/device/audio_test/skip.txt | Adds CH32X035 to skip list. |
| examples/device/audio_test_multi_rate/skip.txt | Adds CH32X035 to skip list. |
| examples/device/audio_test_freertos/skip.txt | Adds CH32X035 to skip list. |
| examples/device/audio_4_channel_mic/skip.txt | Adds CH32X035 to skip list. |
| examples/device/audio_4_channel_mic_freertos/skip.txt | Adds CH32X035 to skip list. |
| docs/reference/dependencies.rst | Adds the hw/mcu/wch/ch32x035 dependency entry. |
| docs/reference/boards.rst | Adds WeAct CH32X035 board entry to the reference list. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: HiFiPhile <admin@hifiphile.com>
|
Thank you, please check if CH32X035 works correctly with latest changes. |
|
I went ahead and added the change to restrict manual toggling to EP4. |
|
Are you sure only EP4 needs manual toggle on CH32X035 ? From the manual there is no auto toggle bit at all. Also ch582 needs manual toggle: |
|
Yes, I'm quite sure since it is indeed in the manual under TOG_AUTO/AUTO_TOG CH32X035Page 223 for EP1, this exists for all EPs not 4 CH58xEP4 doesn't have auto toggle for both chips.
This issue was fixed too: https://github.com/rhgndf/tinyusb/blob/e80049bfb305ce2164310a510af78814234ede1b/src/portable/wch/dcd_ch32_usbfs.c#L600 For the multi-packet bulk transfers, it works with cdc_msc_throughput with the results:
|
Modified endpoint response handling for USBFS to ensure proper ACK/NAK behavior based on transfer validity.




Adds support for both CH32X035 and CH32X033.
I'm also evaluating this MCU due to it being low cost and have USB.
CH32X035 has both TX and RX CTRL bits in the same byte, so there are changes to how these registers are written in the dcd.
If the current approach isn't satisfactory, there are some alternatives:
EP4 special handling:
This is a bit confusing, and Codex/Claude has been very helpful to get that part working. In short: no DMA and no auto-toggle, so some special handling has to be built in.
EP3 no special large buffer
The code has some existing handling for large EP3 buffer, but as far as I can tell that functionality doesn't exist in ch32x035, should I #if that out for this port?
Related: adafruit/Adafruit_TinyUSB_Arduino#486