-
Notifications
You must be signed in to change notification settings - Fork 2
Home
Hoy he recibido la placa nanoCH32V203 que compré en Aliexpress en este enlace
Voy a ponerla en marcha y documentar lo que voy haciendo
La placa al enchufarse hace parpadear un LED azul. Parece que lleva un programa de Blink cargado
Al conectarlo al PC, NO aparece ningún dispositivo. Simplemente se recibe alimentación y se ejecuta el programa blink.
Leyendo la documentación veo que dejando apretado el botón Boot, pulsando rst (pulsar y soltar) y soltando Boot se entra en el modo bootloader. En este modo Ya sí que vemos el dispositivo:
$ lsusb
[...]
Bus 001 Device 011: ID 4348:55e0 WinChipHead
Al apretar Rst se sale de este modo y el dispositivo desaparece
Leyendo la documentación que tienen en la wiki de github: https://github.com/wuxx/nanoCH32V203 voy a instalar las herramientas libres para su uso. Lo primero será el programador
El programa está creado en RUST (Me gusta!!). Lo primero instalar las herramientas de rust. Esto lo dejé documentando en el Log de aprendizaje de Rust
Una vez instalado, lo podemos comprobar executando este comando:
obijuan@Hoth:~$ rustc -V
rustc 1.65.0 (897e37553 2022-11-02)
La versión instalada es la 1.65.0
Para instalar el programador hay que ejecutar este comando:
obijuan@Hoth:~$ cargo install wchisp --git https://github.com/ch32-rs/wchisp
Updating git repository `https://github.com/ch32-rs/wchisp`
Installing wchisp v0.2.0 (https://github.com/ch32-rs/wchisp#b3143d6c)
Updating crates.io index
[...]
Finished release [optimized] target(s) in 2m 02s
Installing /home/obijuan/.cargo/bin/wchisp
Installed package `wchisp v0.2.0 (https://github.com/ch32-rs/wchisp#b3143d6c)` (executable `wchisp`)
El programador se llama wchisp. Para comprobar que está instalado, ejecutamos:
obijuan@Hoth:~$ wchisp --version
wchisp 0.2.0
Para comprobar si la placa está conectada ejecutamos wchisp info
obijuan@Hoth:~$ wchisp info
Error: No WCH ISP USB device found(4348:55e0 device not found at index #0)
obijuan@Hoth:~$
Este mensaje nos sale si no tenemos conectada la placa o bien si NO ESTAMOS EN EL MODO BOOTLOADER
Si ahora pasamos a Bootloader sale esto:
obijuan@Hoth:~$ wchisp info
Error: Access denied (insufficient permissions)
Ahora nos indica que NO tenemos permisos de acceso, por lo que hay que ejecutarlo con sudo:
obijuan@Hoth:~$ sudo wchisp info
sudo: wchisp: command not found
Sin embargo esto tampoco funciona porque en el path del root no encuentra wchisp. Por ello hay que indicar el path completo:
obijuan@Hoth:~$ sudo /home/obijuan/.cargo/bin/wchisp info
17:54:38 [INFO] Chip: CH32V203C8T6[0x3119] (Code Flash: 64KiB)
17:54:38 [INFO] Chip UID: cd-ab-15-fc-5b-bc-3d-64
17:54:38 [INFO] BTVER(bootloader ver): 02.60
17:54:38 [INFO] Code Flash protected: false
17:54:38 [INFO] Current config registers: a55a3fc000ff00ffffffffff
RDPR_USER: 0xC03F5AA5
[7:0] RDPR 0b10100101 (0xA5)
`- Unprotected
[16:16] IWDG_SW 0b1 (0x1)
`- IWDG enabled by the software, and disabled by hardware
[17:17] STOP_RST 0b1 (0x1)
`- Disable
[18:18] STANDBY_RST 0b1 (0x1)
`- Disable, entering standby-mode without RST
[23:22] SRAM_CODE_MODE 0b0 (0x0)
`- CODE-192KB + RAM-128KB / CODE-128KB + RAM-64KB depending on the chip
DATA: 0xFF00FF00
[7:0] DATA0 0b0 (0x0)
[23:16] DATA1 0b0 (0x0)
WRP: 0xFFFFFFFF
`- Unprotected
El fichero .rules se encuentra en este repositorio:
Lo descargamos y ejecutamos estas instrucciones para su instalación:
obijuan@Hoth:~$ sudo cp ./50-wch.rules /etc/udev/rules.
obijuan@Hoth:~$ sudo udevadm control --reload-rules
Ahora desconectamos la placa, la volvemos a conectar y comprobamos si funcion wchisp info:
obijuan@Hoth:~$ wchisp info
18:04:34 [INFO] Chip: CH32V203C8T6[0x3119] (Code Flash: 64KiB)
18:04:34 [INFO] Chip UID: cd-ab-15-fc-5b-bc-3d-64
18:04:34 [INFO] BTVER(bootloader ver): 02.60
18:04:34 [INFO] Code Flash protected: false
18:04:34 [INFO] Current config registers: a55a3fc000ff00ffffffffff
RDPR_USER: 0xC03F5AA5
[7:0] RDPR 0b10100101 (0xA5)
`- Unprotected
[16:16] IWDG_SW 0b1 (0x1)
`- IWDG enabled by the software, and disabled by hardware
[17:17] STOP_RST 0b1 (0x1)
`- Disable
[18:18] STANDBY_RST 0b1 (0x1)
`- Disable, entering standby-mode without RST
[23:22] SRAM_CODE_MODE 0b0 (0x0)
`- CODE-192KB + RAM-128KB / CODE-128KB + RAM-64KB depending on the chip
DATA: 0xFF00FF00
[7:0] DATA0 0b0 (0x0)
[23:16] DATA1 0b0 (0x0)
WRP: 0xFFFFFFFF
`- Unprotected
Siiii!! Ya lo tenemos!!!!
En este enlace se muestran los ficheros compilados:
Ahí se encuentran los siguientes programas para probar:
- blink_1000.bin
- blink_250.bin
- lcd_st7789.bin
Los descargamos todos. Vamos cargar blink_1000.bin:
obijuan@Hoth:~$ wchisp flash blink_1000.bin
18:15:17 [INFO] Chip: CH32V203C8T6[0x3119] (Code Flash: 64KiB)
18:15:17 [INFO] Chip UID: cd-ab-15-fc-5b-bc-3d-64
18:15:17 [INFO] BTVER(bootloader ver): 02.60
18:15:17 [INFO] Code Flash protected: false
18:15:17 [INFO] Current config registers: a55a3fc000ff00ffffffffff
RDPR_USER: 0xC03F5AA5
[7:0] RDPR 0b10100101 (0xA5)
`- Unprotected
[16:16] IWDG_SW 0b1 (0x1)
`- IWDG enabled by the software, and disabled by hardware
[17:17] STOP_RST 0b1 (0x1)
`- Disable
[18:18] STANDBY_RST 0b1 (0x1)
`- Disable, entering standby-mode without RST
[23:22] SRAM_CODE_MODE 0b0 (0x0)
`- CODE-192KB + RAM-128KB / CODE-128KB + RAM-64KB depending on the chip
DATA: 0xFF00FF00
[7:0] DATA0 0b0 (0x0)
[23:16] DATA1 0b0 (0x0)
WRP: 0xFFFFFFFF
`- Unprotected
18:15:17 [INFO] Read blink_1000.bin as Binary format
18:15:17 [INFO] Firmware size: 8192
18:15:17 [INFO] Erasing...
18:15:17 [INFO] Erased 9 code flash sectors
18:15:18 [INFO] Erase done
18:15:18 [INFO] Writing to code flash...
██████████████████████████████████████████████████████████████████████ 8192/819218:15:18 [INFO] Code flash 8192 bytes written
18:15:19 [INFO] Verifying...
██████████████████████████████████████████████████████████████████████ 8192/819218:15:20 [INFO] Verify OK
18:15:20 [INFO] Now reset device and skip any communication errors
18:15:20 [INFO] Device reset
obijuan@Hoth:~$
Y efectivamente vemos cómo ahora el LED parpadea, pero más lento... a la frecuencia de 1Hz
Repetimos con otro programa. Entramos en el modo bootloader y ejecutamos:
obijuan@Hoth:~$ wchisp flash lcd_st7789.bin
[...]
uuueeeee Este ejemplo muestra el logo de RISC-V en la pantalla... Es ¡Espectacular!

El roadmap es el siguiente:
- Instalar las herramientas del gcc para risc-v
- Compilar el ejemplo de la pantalla
- Cargar ejemplo compilado para comprobar si todo ok
- Modificar el ejemplo para que sólo se ponga a parpadear el led
- Simplificar al máximo! --> Circuito que enciende led y termina
El ejemplo del blinky está en este repositorio: https://github.com/wuxx/nanoCH32V203/tree/master/doc/EVT/EXAM/GPIO/GPIO_Toggle/User
Se bajan desde aquí:
Para instalarlo he descomprimido el fichero .tgz en el directorio ~/Bin
Para usarlo primero hay que meterlo en el PATH:
obijuan@Hoth:~$ export PATH=${PATH}:~/Bin/xpack-riscv-none-embed-gcc-10.2.0-1.2-linux-x64/xpack-riscv-none-embed-gcc-10.2.0-1.2/bin
Una vez en el Path, ahora ya podemos comprobar la versión de por ejemplo el GCC:
obijuan@Hoth:~$ riscv-none-embed-gcc --version
riscv-none-embed-gcc (xPack GNU RISC-V Embedded GCC x86_64) 10.2.0
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
obijuan@Hoth:~$
Clonamos el repositorio de los ejemplos:
obijuan@Hoth:~/Test$ git clone https://github.com/wuxx/CH32V203-makefile-example
Cloning into 'CH32V203-makefile-example'...
remote: Enumerating objects: 310, done.
remote: Counting objects: 100% (310/310), done.
remote: Compressing objects: 100% (151/151), done.
remote: Total 310 (delta 148), reused 310 (delta 148), pack-reused 0
Receiving objects: 100% (310/310), 742.71 KiB | 3.77 MiB/s, done.
Resolving deltas: 100% (148/148), done.
Para compilar entramos en el directorio CH32V203-makefile-example
obijuan@Hoth:~/Test$ cd CH32V203-makefile-example
obijuan@Hoth:~/Test/CH32V203-makefile-example$
y ejecutamos make:
obijuan@Hoth:~/Test/CH32V203-makefile-example$ make
mkdir -p build/./app/
riscv-none-embed-gcc -march=rv32imafc
[...]
riscv-none-embed-objcopy -Oihex build/app.elf ./build/app.hex
riscv-none-embed-objcopy -Obinary build/app.elf ./build/app.bin
sz ./build/app.bin
make: sz: No such file or directory
make: *** [Makefile:31: build/app.elf] Error 127
Sale un error, pero es porque el comando sz no está instalado (pero no tengo claro para qué es...). Sin embargo los ficheros ejecutables sí que están creados
Ahora conectamos la placa, la ponemos en el modo de carga y ejecutamos el comando:
obijuan@Hoth:~/Test/CH32V203-makefile-example$ wchisp flash ./build/app.bin
19:24:45 [INFO] Chip: CH32V203C8T6[0x3119] (Code Flash: 64KiB)
19:24:45 [INFO] Chip UID: cd-ab-15-fc-5b-bc-3d-64
19:24:45 [INFO] BTVER(bootloader ver): 02.60
19:24:45 [INFO] Code Flash protected: false
19:24:45 [INFO] Current config registers: a55a3fc000ff00ffffffffff
RDPR_USER: 0xC03F5AA5
[7:0] RDPR 0b10100101 (0xA5)
`- Unprotected
[16:16] IWDG_SW 0b1 (0x1)
`- IWDG enabled by the software, and disabled by hardware
[17:17] STOP_RST 0b1 (0x1)
`- Disable
[18:18] STANDBY_RST 0b1 (0x1)
`- Disable, entering standby-mode without RST
[23:22] SRAM_CODE_MODE 0b0 (0x0)
`- CODE-192KB + RAM-128KB / CODE-128KB + RAM-64KB depending on the chip
DATA: 0xFF00FF00
[7:0] DATA0 0b0 (0x0)
[23:16] DATA1 0b0 (0x0)
WRP: 0xFFFFFFFF
`- Unprotected
19:24:45 [INFO] Read ./build/app.bin as Binary format
19:24:45 [INFO] Firmware size: 61440
19:24:45 [INFO] Erasing...
19:24:45 [INFO] Erased 61 code flash sectors
19:24:46 [INFO] Erase done
19:24:46 [INFO] Writing to code flash...
████████████████████████████████████████████████████████████████████ 61440/6144019:24:46 [INFO] Code flash 61440 bytes written
19:24:47 [INFO] Verifying...
████████████████████████████████████████████████████████████████████ 61440/6144019:24:48 [INFO] Verify OK
19:24:48 [INFO] Now reset device and skip any communication errors
19:24:48 [INFO] Device reset
obijuan@Hoth:~/Test/CH32V203-makefile-example$
Listo!!! Se ha cargado el programa compilado!!
Ahora he aumentado la pausa de 100ms a 1000ms... he recompilado y ¡¡Funciona!!
Ya tengo la versión del hola mundo mínima
#include "ch32v20x.h"
/* Peripheral declaration */
#define GPIOA_CFGHR (0x40010800 + 1*4)
#define GPIOA_BSHR (0x40010800 + 4*4)
#define GPIOA_BCR (0x40010800 + 5*4)
#define RCC_APB2PCENR (0x40021000 + 6*4)
int main(void)
{
//-- Habilitar APB2: Puerto A
*(uint32_t *)RCC_APB2PCENR = 0x4;
//-- Configurar pin A15
*(uint32_t *)GPIOA_CFGHR = 0x30000000;
//-- Turn LED on
*(uint32_t *)GPIOA_BCR = 0x8000;
//-- Turn LED off
//*(uint32_t *)GPIOA_BSHR = 0x8000;
while (1);
}