This config extends the default configuration with features like:
- disabling MCU code protection before programming
- enabling protection again afterward
- MounRiver Studio versions below 2 cannot automatically disable flash protection.
- WCH-LinkUtility is not available on Linux-based operating systems.
- OpenOCD version with WCH RISC-V support
- WCH-Link adapter
There are two ways to use this configuration.
Replace the default OpenOCD configuration.
(If you're using MounRiver Studio, the path to the default configuration file is: /MRS_Community/toolchain/OpenOCD/bin/
)
To use the custom lock
and unlock
functions, configure the IDE as shown in the image below
Create a bash-script for use without an IDE.
#!/bin/bash
OPENOCD_PATH=<path/to/wch/openocd/bin>
CFG_PATH=<path/to/configuration>
$OPENOCD_PATH/openocd \
-f $CFG_PATH/wch-riscv.cfg \ # Choosing custom configuration file
-c "init" \
-c "unlock" \ # Releasing protection if active
-c "program $1 verify" \ # Flashing firmware
-c "lock" \ # Enabling protection
-c "reset" \
-c "exit"
The script argument should be either a hex
or elf
firmware file.
Original article on Habr: Использование OpenOCD для установки/снятия запрета чтения памяти CH32V20x