I just had a headscratcher I got a few of these boards
https://www.aliexpress.com/item/1005004350410929.htmlAnd tried to load the webapp.
This time putting the board in
DFU mode , and use
wchisp for programming via an USB-C cable.
One board was success , two other boards failed in verify.
I tried to switch to another USB cable ... Same result.
After digging a bit i found out the boards came from the factory
with flash protection active Below are my notes for disabling flash protection via wchisp.
Enter DFU mode (like STM32F4)
Press Reset + BOOT0
Release Reset
Release Boot0
*********** WCHISP ********
Commands
-------------------
> wchisp flash ./path/to/firmware.{bin,hex,elf}
> wchisp config info
> wchisp config reset
******************************
Info Unprotected
$ wchisp info
14:26:26 [INFO] Chip: CH32V307VCT6[0x7017] (Code Flash: 256KiB)
14:26:26 [INFO] Chip UID: FD-47-89-26-3B-38-C1-A6
14:26:26 [INFO] BTVER(bootloader ver): 02.90
14:26:26 [INFO] Code Flash protected: false <<<---------*** UNPROTECTED
14:26:26 [INFO] Current config registers: a55aff0000ff00ffffffffff00020900fd4789263b38c1a6
RDPR_USER: 0x00FF5AA5
[7:0] RDPR 0xA5 (0b10100101)
`- Unprotected <<<---------*** UNPROTECTED
[16:16] IWDG_SW 0x1 (0b1)
`- IWDG enabled by the software, and disabled by hardware
[17:17] STOP_RST 0x1 (0b1)
`- Disable
[18:18] STANDBY_RST 0x1 (0b1)
`- Disable, entering standby-mode without RST
[23:22] SRAM_CODE_MODE 0x3 (0b11)
`- CODE-228KB + RAM-32KB <<<-------****** Flash/Ram mode
DATA: 0xFF00FF00
[7:0] DATA0 0x0 (0b0)
[23:16] DATA1 0x0 (0b0)
WRP: 0xFFFFFFFF
`- Unprotected
*********************
Info Protected
$ wchisp info
14:21:38 [WARN] WRP register: bfffffff
14:21:38 [INFO] Chip: CH32V307VCT6[0x7017] (Code Flash: 256KiB)
14:21:38 [INFO] Chip UID: 3F-49-89-26-3B-38-03-A8
14:21:38 [INFO] BTVER(bootloader ver): 02.90
14:21:38 [INFO] Code Flash protected: true <<<---------*** PROTECTED
14:21:38 [INFO] Current config registers: ff001fe000ff00ffbfffffff000209003f4989263b3803a8
RDPR_USER: 0xE01F00FF
[7:0] RDPR 0xFF (0b11111111)
`- Protected <<<---------*** PROTECTED
[16:16] IWDG_SW 0x1 (0b1)
`- IWDG enabled by the software, and disabled by hardware
[17:17] STOP_RST 0x1 (0b1)
`- Disable
[18:18] STANDBY_RST 0x1 (0b1)
`- Disable, entering standby-mode without RST
[23:22] SRAM_CODE_MODE 0x0 (0b0)
`- CODE-192KB + RAM-128KB <<<-------****** Flash/Ram mode
DATA: 0xFF00FF00
[7:0] DATA0 0x0 (0b0)
[23:16] DATA1 0x0 (0b0)
WRP: 0xFFFFFFBF
`- Some 4K sections are protected <<<---------*** PROTECTED
*********************
Config Reset (If info shows protected)
wchisp config reset
** Must power reset device after config reset ... "Flash unprotect" (like on stm)
*********************
Note that the config reset will set the MCU for
default 32K Ram / 288K Flash.
And that it seems like wchisp doesn't have code for setting the Ram/Flash config .... yet.
If you're using wchisp , there is a way to get mongoose to set the (preferred) 64K Ram/ 256K Flash for you ... Thnx Tellurium
1:
Uncomment this line in main.c , to have mogoose set the config.
2:
Do a : make clean all (It will build for 32K)
3:
Upload that ...
Now the chip should be set for 64K Ram.
4:
Now build for 64K Ram
make CFLAGS_EXTRA='-Wl,--defsym -Wl,RAM_64K=1' clean all
5:
Upload that ....
wchisp won't touch/change the Ram/Flash config, unless told to reset config.
So you could "recomment" the line you uncommented in main.c. If you prefer mongoose not to alter the Ram/Flash config.
/Bingo