# huming2207/ch32v305_dap architecture

> Architecture diagram of the GitHub repository huming2207/ch32v305_dap, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/huming2207/ch32v305_dap
- Repository: https://github.com/huming2207/ch32v305_dap

## Overview

This is CH32V305 firmware for a CMSIS-DAP debug probe, with USB device support and a USB-to-UART bridge. The main loop initializes the probe and repeatedly handles DAP and UART-bridge work; DAP commands ultimately support target debug access over SWD. The tree also includes SWO/UART DAP support and optional mass-storage code. Some implementation files were not sampled, so uncertain runtime links are omitted or marked unverified rather than inferred from naming.

Main entry points: [`CherryDAP/DAP/Source/DAP.c`](https://github.com/huming2207/ch32v305_dap/blob/master/CherryDAP/DAP/Source/DAP.c) (CMSIS-DAP commands), [`CherryDAP/dap_main.c`](https://github.com/huming2207/ch32v305_dap/blob/master/CherryDAP/dap_main.c) (DAP orchestration), [`CherryUSB/core/usbd_core.c`](https://github.com/huming2207/ch32v305_dap/blob/master/CherryUSB/core/usbd_core.c) (USB device core), [`User/main.c`](https://github.com/huming2207/ch32v305_dap/blob/master/User/main.c) (Firmware main)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_firmware["Firmware runtime"]
  node_main["Firmware main<br/>[main.c]"]
  node_ring["Transfer buffers<br/>[chry_ringbuffer.c]"]
  node_uart_bridge["UART bridge<br/>[usb2uart.c]"]
end

subgraph group_dap["DAP and debug"]
  node_dap_entry["DAP orchestration<br/>[dap_main.c]"]
  node_dap_protocol["CMSIS-DAP commands<br/>[DAP.c]"]
  node_swd_target["SWD target access<br/>[swd_host.c]"]
  node_dap_swo["SWO trace<br/>[SWO.c]"]
  node_dap_uart["DAP UART<br/>[UART.c]"]
  node_dap_vendor["Vendor commands<br/>[DAP_vendor.c]"]
  node_jtag["JTAG-DP<br/>[JTAG_DP.c]"]
  node_sw_dp["SW-DP<br/>[SW_DP.c]"]
end

subgraph group_usb["USB device"]
  node_usb_core["USB device core<br/>[usbd_core.c]"]
  node_usb_cdc["USB CDC<br/>[usbd_cdc.c]"]
  node_usb_msc["USB mass storage<br/>[usbd_msc.c]"]
  node_usb_port["USBHS controller<br/>[usb_dc_usbhs.c]"]
end

subgraph group_platform["CH32V305 platform"]
  node_dap_config["Probe configuration<br/>[DAP_config.h]"]
  node_debug["Debug support<br/>[debug.c]"]
  node_riscv["RISC-V core support<br/>[core_riscv.c]"]
  node_peripherals["CH32 peripherals<br/>[ch32v30x.h]"]
end

node_host(("USB host"))

node_host -->|"sends USB traffic"| node_usb_core
node_main -->|"initializes, handles"| node_dap_entry
node_main -->|"handles bridge"| node_uart_bridge
node_main -->|"uses support"| node_debug
node_dap_entry -.->|"dispatches commands"| node_dap_protocol
node_dap_entry -.->|"configures device"| node_usb_core
node_dap_entry -->|"uses CDC interface"| node_usb_cdc
node_dap_entry -->|"uses MSC interface"| node_usb_msc
node_usb_core -.->|"uses controller"| node_usb_port
node_usb_cdc -.->|"registers class"| node_usb_core
node_dap_entry -->|"uses buffers"| node_ring
node_uart_bridge -.->|"uses buffers"| node_ring
node_dap_protocol -->|"uses configuration"| node_dap_config
node_swd_target -->|"uses configuration"| node_dap_config
node_dap_protocol -.->|"accesses target"| node_swd_target
node_dap_protocol -.->|"supports trace"| node_dap_swo
node_dap_protocol -.->|"supports UART"| node_dap_uart
node_dap_protocol -.->|"supports vendor commands"| node_dap_vendor
node_dap_protocol -.->|"supports JTAG-DP"| node_jtag
node_dap_protocol -.->|"supports SW-DP"| node_sw_dp
node_debug -->|"uses device definitions"| node_peripherals
node_peripherals -->|"uses core definitions"| node_riscv

click node_main "https://github.com/huming2207/ch32v305_dap/blob/master/User/main.c"
click node_dap_entry "https://github.com/huming2207/ch32v305_dap/blob/master/CherryDAP/dap_main.c"
click node_dap_protocol "https://github.com/huming2207/ch32v305_dap/blob/master/CherryDAP/DAP/Source/DAP.c"
click node_swd_target "https://github.com/huming2207/ch32v305_dap/blob/master/DAPHost/swd_host.c"
click node_dap_swo "https://github.com/huming2207/ch32v305_dap/blob/master/CherryDAP/DAP/Source/SWO.c"
click node_dap_uart "https://github.com/huming2207/ch32v305_dap/blob/master/CherryDAP/DAP/Source/UART.c"
click node_dap_vendor "https://github.com/huming2207/ch32v305_dap/blob/master/CherryDAP/DAP/Source/DAP_vendor.c"
click node_jtag "https://github.com/huming2207/ch32v305_dap/blob/master/CherryDAP/DAP/Source/JTAG_DP.c"
click node_sw_dp "https://github.com/huming2207/ch32v305_dap/blob/master/CherryDAP/DAP/Source/SW_DP.c"
click node_usb_core "https://github.com/huming2207/ch32v305_dap/blob/master/CherryUSB/core/usbd_core.c"
click node_usb_cdc "https://github.com/huming2207/ch32v305_dap/blob/master/CherryUSB/class/cdc/usbd_cdc.c"
click node_usb_msc "https://github.com/huming2207/ch32v305_dap/blob/master/CherryUSB/class/msc/usbd_msc.c"
click node_usb_port "https://github.com/huming2207/ch32v305_dap/blob/master/CherryUSB/port/ch32/usb_dc_usbhs.c"
click node_ring "https://github.com/huming2207/ch32v305_dap/blob/master/CherryRB/chry_ringbuffer.c"
click node_uart_bridge "https://github.com/huming2207/ch32v305_dap/blob/master/User/usb2uart.c"
click node_dap_config "https://github.com/huming2207/ch32v305_dap/blob/master/User/DAP_config.h"
click node_debug "https://github.com/huming2207/ch32v305_dap/blob/master/Debug/debug.c"
click node_riscv "https://github.com/huming2207/ch32v305_dap/blob/master/Core/core_riscv.c"
click node_peripherals "https://github.com/huming2207/ch32v305_dap/blob/master/Peripheral/inc/ch32v30x.h"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_main,node_ring,node_uart_bridge toneBlue
class node_dap_entry,node_dap_protocol,node_swd_target,node_dap_swo,node_dap_uart,node_dap_vendor,node_jtag,node_sw_dp toneAmber
class node_usb_core,node_usb_cdc,node_usb_msc,node_usb_port toneMint
class node_dap_config,node_debug,node_riscv,node_peripherals toneRose
class node_host toneIndigo
```

## Components

### Firmware runtime

- [Firmware main](https://github.com/huming2207/ch32v305_dap/blob/master/User/main.c): `User/main.c`
- [Transfer buffers](https://github.com/huming2207/ch32v305_dap/blob/master/CherryRB/chry_ringbuffer.c): `CherryRB/chry_ringbuffer.c`
- [UART bridge](https://github.com/huming2207/ch32v305_dap/blob/master/User/usb2uart.c): `User/usb2uart.c`

### DAP and debug

- [DAP orchestration](https://github.com/huming2207/ch32v305_dap/blob/master/CherryDAP/dap_main.c): `CherryDAP/dap_main.c`
- [CMSIS-DAP commands](https://github.com/huming2207/ch32v305_dap/blob/master/CherryDAP/DAP/Source/DAP.c): `CherryDAP/DAP/Source/DAP.c`
- [SWD target access](https://github.com/huming2207/ch32v305_dap/blob/master/DAPHost/swd_host.c): `DAPHost/swd_host.c`
- [SWO trace](https://github.com/huming2207/ch32v305_dap/blob/master/CherryDAP/DAP/Source/SWO.c): `CherryDAP/DAP/Source/SWO.c`
- [DAP UART](https://github.com/huming2207/ch32v305_dap/blob/master/CherryDAP/DAP/Source/UART.c): `CherryDAP/DAP/Source/UART.c`
- [Vendor commands](https://github.com/huming2207/ch32v305_dap/blob/master/CherryDAP/DAP/Source/DAP_vendor.c): `CherryDAP/DAP/Source/DAP_vendor.c`
- [JTAG-DP](https://github.com/huming2207/ch32v305_dap/blob/master/CherryDAP/DAP/Source/JTAG_DP.c): `CherryDAP/DAP/Source/JTAG_DP.c`
- [SW-DP](https://github.com/huming2207/ch32v305_dap/blob/master/CherryDAP/DAP/Source/SW_DP.c): `CherryDAP/DAP/Source/SW_DP.c`

### USB device

- [USB device core](https://github.com/huming2207/ch32v305_dap/blob/master/CherryUSB/core/usbd_core.c): `CherryUSB/core/usbd_core.c`
- [USB CDC](https://github.com/huming2207/ch32v305_dap/blob/master/CherryUSB/class/cdc/usbd_cdc.c): `CherryUSB/class/cdc/usbd_cdc.c`
- [USB mass storage](https://github.com/huming2207/ch32v305_dap/blob/master/CherryUSB/class/msc/usbd_msc.c): `CherryUSB/class/msc/usbd_msc.c`
- [USBHS controller](https://github.com/huming2207/ch32v305_dap/blob/master/CherryUSB/port/ch32/usb_dc_usbhs.c): `CherryUSB/port/ch32/usb_dc_usbhs.c`

### CH32V305 platform

- [Probe configuration](https://github.com/huming2207/ch32v305_dap/blob/master/User/DAP_config.h): `User/DAP_config.h`
- [Debug support](https://github.com/huming2207/ch32v305_dap/blob/master/Debug/debug.c): `Debug/debug.c`
- [RISC-V core support](https://github.com/huming2207/ch32v305_dap/blob/master/Core/core_riscv.c): `Core/core_riscv.c`
- [CH32 peripherals](https://github.com/huming2207/ch32v305_dap/blob/master/Peripheral/inc/ch32v30x.h): `Peripheral/inc/ch32v30x.h`

### Other components

- **USB host**

## Connections

- USB host → USB device core: sends USB traffic
- Firmware main → DAP orchestration: initializes, handles (evidence: `User/main.c`)
- Firmware main → UART bridge: handles bridge (evidence: `User/main.c`)
- Firmware main → Debug support: uses support (evidence: `User/main.c`)
- DAP orchestration → CMSIS-DAP commands: dispatches commands
- DAP orchestration → USB device core: configures device
- DAP orchestration → USB CDC: uses CDC interface
- DAP orchestration → USB mass storage: uses MSC interface
- USB device core → USBHS controller: uses controller
- USB CDC → USB device core: registers class
- DAP orchestration → Transfer buffers: uses buffers
- UART bridge → Transfer buffers: uses buffers
- CMSIS-DAP commands → Probe configuration: uses configuration (evidence: `CherryDAP/DAP/Source/DAP.c`)
- SWD target access → Probe configuration: uses configuration (evidence: `DAPHost/swd_host.c`)
- CMSIS-DAP commands → SWD target access: accesses target
- CMSIS-DAP commands → SWO trace: supports trace
- CMSIS-DAP commands → DAP UART: supports UART
- CMSIS-DAP commands → Vendor commands: supports vendor commands
- CMSIS-DAP commands → JTAG-DP: supports JTAG-DP
- CMSIS-DAP commands → SW-DP: supports SW-DP
- Debug support → CH32 peripherals: uses device definitions
- CH32 peripherals → RISC-V core support: uses core definitions (evidence: `Peripheral/inc/ch32v30x.h`)
