2

沁恒CH32V003F4P6 开发板上手报告和Win10环境配置 - Milton

 1 year ago
source link: https://www.cnblogs.com/milton/p/16838010.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

CH32V003

沁恒最近推出的低价CH32V003系列, 基于青稞RISC-V2A内核, 48MHz主频, 2KB SRAM, 16KB Flash, 工作电压兼容3.3V和5V. 主要参数如下

  • System Clock: 48MHz
  • SRAM: 2KB
  • Flash: 16KB
  • Power Supply: 3.3/5V
  • 多种低功耗模式: 睡眠, 待机
  • 上/下电复位, 可编程电压检测器
  • DMA: 1组1路通用
  • 运放比较器: 1组
  • ADC: 1组10位
  • Timer: 1个16位高级, 1个16位通用
  • WDG: 2个看门狗定时器和1个32位系统时基定时器
  • USART: 1
  • IIC: 1
  • SPI: 1
  • I/O: 18
  • UUID: 64bit
  • Debug port: 1-wire serial (SWDIO)
  • Package: TSSOP20, QFN20, SOP16, SOP8
650273-20221029081836120-1072861063.png
650273-20221029081853486-1223135455.jpg
  • 典型的WCH风格开发板, 土绿+密集的过孔+不计面积走长线.
  • 有开关, 但是没有专门的烧录口, 烧录是通过右边一排的 VCC, GND, PD1(SWDIO) 连接的.
  • 三颗LED, 一颗电源指示, 两颗未连接但是有排针, 可以自己用跳线连到其他pin口方便观察输出

烧录器 WCH-Link

650273-20221029081903081-519052753.jpg

CH32V003的烧录需要使用新出的WCHLink, 芯片是CH32V30x的这种, 据说旧的不支持但是我没实际测过.

Win10下的开发环境是比较简单的, 软件就是MounRiver, 版本v1.82, 下载地址 http://mounriver.com/download

软件集成了代码编辑, 编译环境和烧录工具. 直接安装即可. 因为是基于 Eclipse 开发, 使用体验还不错.

注意要使用较新的版本, 旧版本不支持 CH32V003, 编译会报错 riscv-none-embed/bin/ld.exe: cannot find -lprint

MounRiver的使用说明参考官方专栏, 介绍得较为详细

运行LED闪灯示例代码

下面以最简单的GPIO示例走一遍编译烧录的过程

开发板 ---> WCHLink, 注意如果已经通过PC的USB口连接了开发板, 就不要连WCHLink VCC, 如果连了WCHLink VCC, 就不要接USB口

  • VCC -> 3V3
  • GND -> GND
  • PD1 -> SWDIO

开发板本身

  • 连接一个LED到 PD0, 用于观察PD0的输出

下载示例代码: https://www.wch.cn/downloads/CH32V003EVT_ZIP.html

解压后, 在MounRiver中 File -> Load -> Project, 打开 EVT\EXAM\GPIO\GPIO_Toggle目录下的 GPIO_Toggle.wvproj

按 Shift + F7 或通过工具栏按钮编译即可. 编译正常会显示

07:29:58 **** Build of configuration obj for project GPIO_Toggle ****
make -j4 all 
   text	   data	    bss	    dec	    hex	filename
   3396	     40	    520	   3956	    f74	GPIO_Toggle.elf

07:30:02 Build Finished. 0 errors, 0 warnings. (took 4s.306ms)

示例项目中默认的构建结果为 bin 文件, 编译结束后在 obj 目录下能看到 GPIO_Toggle.bin, 但是没有 GPIO_Toggle.hex, 与项目预设的烧录目标 (hex) 不同, 为避免后面报错, 需要将编译输出修改为 hex:

  • 项目树中选中当前项目
  • 菜单 Project -> Properties
  • 对话框 C/C++ Build -> Settings -> GNU RISC-V Cross Create Flash Image -> General
  • 对话框 Output file format (-O): 将 Raw Binary 修改为 Intel HEX

再次编译后, 在 obj 目录下就能看到生成的 GPIO_Toggle.hex 文件

菜单 Flash -> Config, 点击第一个图标 Query Status 查询芯片状态, 连接成功后底下会显示0000#07:48:33:283>> Query Success, 同时会显示红色的Code Read-Protect Status Disabled或绿色的Code Read-Protect Status Enabled, 红色的表示读保护关闭, 这时候可以烧录, 如果是绿色表示读保护打开, 需要关闭后才能烧录. 下面 Target 中会显示检测到的MCU类型, 写入开始地址 0x08000000, 以及要写入的文件 obj\GPIO_Toggle.hex

以上无误后, 应用保存, 按 F8 或点击工具栏图标烧录, 烧录过程输出

------------ Begin flash process of "obj\GPIO_Toggle.hex" ------------ 
07:59:24:625 >> Current project vendor is WCH, debugger is WCH-Link

07:59:24:626 >> Attempt to open device and upgrade firmware if necessary...
07:59:24:629 >> WCH-Link no need to upgrade. Already the latest version.

07:59:24:711 >> Starting to Send Chip Type...
07:59:24:772 >> Send Chip Type Success

07:59:24:772 >> Starting to Check Read-Protect Status...
07:59:24:773 >> Read-Protect Status Currently Disabled

07:59:24:773 >> Starting to Erase All...
07:59:24:781 >> Erase All Success

07:59:24:841 >> Starting to Download & Verify...
07:59:25:278 >> Download & Verify Success

07:59:25:278 >> Starting to Reset...
07:59:25:295 >> Reset Success

07:59:25:295 >> Starting to Close Link...
07:59:25:296 >> Close Link Success
---------------------------------End ---------------------------------
Operation Finished (took 0s.672ms)

烧录成功后就能看到连接的LED开始闪烁


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK