Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Constants and Chip Families

riscvchip — chip family codes

Source: RiscvChip in src/lib.rs. The one-byte value is returned by AttachChip and is passed to SetSpeed and to the special-erase subcommands.

CodeFamilySeries / notes
0x01CH32V103RISC-V3A
0x02CH57XCH571/CH573, RISC-V3A BLE 4.2
0x03CH56XCH565/CH569, RISC-V3A
0x04CH32F10XCortex-M (not a RISC-V target)
0x05CH32V20XRISC-V4B/V4C
0x06CH32V30XRISC-V4C/V4F, shares type 5 traits
0x07CH582CH581/CH582/CH583, RISC-V4A BLE 5.3
0x08CH32F20XCortex-M (not a RISC-V target)
0x09CH32V003RISC-V2A
0x0aCH8571Undocumented RISC-V EC controller
0x0bCH59XCH59x RISC-V4C BLE 5.4, falls back as CH58X
0x0cCH643RISC-V4C, RGB display driver
0x0dCH32X035CH32X035/033, RISC-V4C USB-PD
0x0eCH32L103RISC-V4C low-power USB-PD
0x0fCH564RISC-V4J
0x46CH645CH645/CH653, RISC-V4C
0x49CH641RISC-V2A USB-PD, falls back as CH32V003
0x4bCH585CH585/CH584, RISC-V3C BLE 5.4 / NFC / USB HS
0x4eCH32V00XCH32V002/4/5/6/7, CH32M007
0x86CH32V317RISC-V4
0x8bCH570CH570/CH572, RISC-V BLE
0x8eCH32M030RISC-V motor control
0xa6CH32V4X7CH32V407/CH32V467
0xabCH586CH586/CH587, RISC-V BLE 5.4
0xc6CH32H41XCH32H415/416/417, RISC-V5F + RISC-V3F
0xceCH32V205New-generation CH32V205/CH32V203 (QingKe V3B), unrelated to CH32V20X
0xe6CH32X3X5CH32X315/CH32X305, RISC-V3F

RiscvChip also implements clap’s ValueEnum, so --chip accepts the family name plus part-number aliases such as CH32H417QEU or CH32X315MCU6. The ChipID-to-part-name database is chip_id_to_chip_name in src/chips.rs.

Speed codes (0x0c SetSpeed)

CodeSpeed variantClock
0x01High (default)6000 kHz
0x02Medium4000 kHz
0x03Low400 kHz

Protection flags (0x06 ConfigChip)

ConstantValue
FLAG_READ_PROTECTED0x01
FLAG_READ_UNPROTECTED0x02
FLAG_WRITE_PROTECTED0x11
FLAG_WRITE_UNPROTECTED0x00

CheckReadProtect returns the read flags; CheckReadProtectEx returns the write flags.

Error reasons

REASONMeaning
0x55Failed to connect to the target RISC-V chip
otherUnknown; wlink preserves the whole frame in Error::Protocol(reason, bytes)

USB constants

ConstantValue
VENDOR_ID0x1a86
PRODUCT_ID (RV)0x8010
PRODUCT_ID_DAP0x8012
ENDPOINT_OUT / ENDPOINT_IN0x01 / 0x81
DATA_ENDPOINT_OUT / DATA_ENDPOINT_IN0x02 / 0x82
ENDPOINT_OUT_DAP0x02

Flash algorithm blobs

Each supported family has a binary “flash OP” blob in src/flash_op.rs, sent over the data endpoint after 0x02 / 0x05 Program::WriteFlashOP. They are opaque byte arrays selected by RiscvChip::get_flash_op, for example CH32V307: [u8; 446], CH32V003: [u8; 498], CH32H417: [u8; 618], CH564: [u8; 1532]. Some families have an _ALT variant. Packet and write chunk sizes come from RiscvChip::data_packet_size and RiscvChip::write_pack_size in src/lib.rs.

Debug interface keys

ConstantValue
KEY10x45670123
KEY20xCDEF89AB

Used to unlock flash/option-byte writes through the debug interface; see DMI.