cnlohr / rv003usb

CH32V003 RISC-V Pure Software USB Controller
MIT License
459 stars 47 forks source link

Download error "Fault writing memory" with minichlink option -U #21

Closed xsrf closed 10 months ago

xsrf commented 1 year ago

Hey, I've got a bare CH32V003A4M6 with just GND, 3V3 and SWIO connected to the WCH-Link programmer. When trying to upload the bootloader, I'm getting these errors:

C:\Users\Andreas\Documents\Projects\rv003usb\bootloader>make
riscv64-unknown-elf-gcc -o bootloader.elf bootloader.c ../rv003usb/rv003usb.S -g -Os -flto -ffunction-sections -static-libgcc -march=rv32ec -mabi=ilp32e -I/usr/include/newlib -I../ch32v003fun/ch32v003fun/../extralibs -I../ch32v003fun/ch32v003fun -nostdlib -I. -Wall -I. -I../lib -DUSE_TINY_BOOT -I../rv003usb -T ch32v003fun-usb-bootloader.ld -Wl,--gc-sections -L../ch32v003fun/ch32v003fun/../misc -lgcc
riscv64-unknown-elf-size bootloader.elf
   text    data     bss     dec     hex filename
   1872       0      92    1964     7ac bootloader.elf
riscv64-unknown-elf-objdump -S bootloader.elf > bootloader.lst
riscv64-unknown-elf-objdump -t bootloader.elf > bootloader.map
riscv64-unknown-elf-objcopy -O binary bootloader.elf bootloader.bin
riscv64-unknown-elf-objcopy -O ihex bootloader.elf bootloader.hex
make -C ../ch32v003fun/minichlink all
make[1]: Entering directory 'C:/Users/Andreas/Documents/Projects/rv003usb/ch32v003fun/minichlink'
make[1]: Nothing to be done for 'all'.
make[1]: Leaving directory 'C:/Users/Andreas/Documents/Projects/rv003usb/ch32v003fun/minichlink'
../ch32v003fun/ch32v003fun/../minichlink/minichlink -a -U -w bootloader.bin bootloader -B
Found WCH Link
WCH Programmer is LinkE version 2.8
Chip Type: 003
Setup success
Flash Storage: 16 kB
Part UUID    : 44-a8-ab-cd-ac-b8-bc-43
PFlags       : ff-ff-ff-ff
Part Type (B): 07-13-bb-91
Read protection: disabled
Interface Setup
FLASH_OBTKEYR = 00000000 (0)
Fault writing memory (DMABSTRACTS = 08000302) (Execption executing Abstract Command) DMSTATUS: 004c0382
Fault on DefaultReadWord Part 1
Fault writing memory (DMABSTRACTS = 08000302) (Execption executing Abstract Command) DMSTATUS: 004c0382
Fault on DefaultWriteWord Part 3
Error: Flash operation error
Fault writing memory (DMABSTRACTS = 08000302) (Execption executing Abstract Command) DMSTATUS: 004c0382
Fault on DefaultWriteWord Part 3
Fault writing memory (DMABSTRACTS = 08000302) (Execption executing Abstract Command) DMSTATUS: 004c0382
Fault on DefaultWriteWord Part 3
Fault writing memory (DMABSTRACTS = 08000302) (Execption executing Abstract Command) DMSTATUS: 004c0382
Fault on DefaultWriteWord Part 1
Fault writing memory (DMABSTRACTS = 08000302) (Execption executing Abstract Command) DMSTATUS: 004c0382
Fault on DefaultWriteWord Part 2
Fault writing memory (DMABSTRACTS = 08000302) (Execption executing Abstract Command) DMSTATUS: 004c0382
Fault on DefaultWriteWord Part 2
Fault writing memory (DMABSTRACTS = 08000302) (Execption executing Abstract Command) DMSTATUS: 004c0382
Fault on DefaultWriteWord Part 2
Fault writing memory (DMABSTRACTS = 08000302) (Execption executing Abstract Command) DMSTATUS: 004c0382
Fault on DefaultWriteWord Part 2
Fault writing memory (DMABSTRACTS = 08000302) (Execption executing Abstract Command) DMSTATUS: 004c0382
Fault on DefaultWriteWord Part 2
...

Uploading other code, like the blink example, works. After the errors, the previous code still runs.

minichlink.exe -? doesn't tell me what -B and -U do, but when I try them it won't say its an unknown command, so 🤷‍♂️

However, removing -U results in Image written. and it looks like it worked - at least the blink code now is delayed when powered on. But so far I can't get it to enumerate via USB.

cnlohr commented 10 months ago

Try other demos other than the bootloader. The bootloader is jank.

xsrf commented 10 months ago

Do you know what -U does? Why do you use it?