ch32-rs / ch32v203-demo

8 stars 2 forks source link

How does this project flush? #1

Closed 74th closed 1 year ago

74th commented 1 year ago

Hello. I am interested in this ch32v and rust and very excited about this ch32-rs project. I would like to build and run this ch32v203-demo project.

Sorry for the basic question, but how does this project build and flash? Are there any other steps required? I have a CH32V203 board, WCH-LinkE and MountRiverStudio's openocd. I successes to flash the hex file generated by MountRiverStudio with this openocd.

cargo build --release
cp ./target/riscv32imac-unknown-none-elf/release/ch32v203-demo  /some//MRS_Toolchain_Linux_x64_V1.60/OpenOCD/bin/ch32v203-demo.elf
sudo ./openocd -f wch-riscv.cfg  -c init -c halt  -c "program ch32v203-demo.elf"  -c exit

output

Open On-Chip Debugger 0.11.0+dev-02215-gcc0ecfb6d-dirty (2022-10-10-10:35)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
Info : only one transport option; autoselect 'jtag'
Ready for Remote Connections
Info : WCH-LinkE-CH32V307  mod:RV version 2.7 
Info : wlink_init ok
Info : This adapter doesn't support configurable speed
Info : JTAG tap: riscv.cpu tap/device found: 0x00000001 (mfg: 0x000 (<invalid>), part: 0x0000, ver: 0x0)
Warn : Bypassing JTAG setup events due to errors
Info : [riscv.cpu.0] datacount=2 progbufsize=8
Info : Examined RISC-V core; found 1 harts
Info :  hart 0: XLEN=32, misa=0x40901105
[riscv.cpu.0] Target successfully examined.
Info : starting gdb server for riscv.cpu.0 on 3333
Info : Listening on port 3333 for gdb connections
Info : JTAG tap: riscv.cpu tap/device found: 0x00000001 (mfg: 0x000 (<invalid>), part: 0x0000, ver: 0x0)
Warn : Bypassing JTAG setup events due to errors
** Programming Started **
Info : device id = 0xadb1abcd
Info : flash size = 64kbytes
Warn : no flash bank found for address 0x08000000
Warn : no flash bank found for address 0x08000248
embedded:startup.tcl:1136: Error: ** Programming Failed **
in procedure 'program' 
in procedure 'program_error' called at file "embedded:startup.tcl", line 1201
at file "embedded:startup.tcl", line 1136
andelf commented 1 year ago

Hi, @74th

cp ./target/riscv32imac-unknown-none-elf/release/ch32v203-demo /some//MRS_Toolchain_Linux_x64_V1.60/OpenOCD/bin/ch32v203-demo.elf

It seems that openocd can only handle pure binary instead of an ELF file.

You can use the following:

riscv64-unknown-elf-objcopy -O binary \
    path/to/elf \
    firmware.bin
andelf commented 1 year ago

I personally use https://github.com/ch32-rs/wchisp for programming the MCU.

74th commented 1 year ago

Thanks for the answer! I used the riscv64-unknown-elf-objcopy you mentioned and was able to build and run it. Knowing that I could write via USB, I was also able to write using wchisp. It is convenient!

I will try to use ch32-rs for development. Thank you very much.