【简介】
本文讲述了如何使用Clion开发GD32H7
【前言】
与Clion开发stm32的配置类似,只需要添加GD32特定的OpenOCD工具,以及更改GD32对应的GCC编译链接库,启动文件等资源即可,还有烧录时候的配置文件。具体配置过程请看:https://www.cnblogs.com/xutongxin/articles/17609760.html
【串口重定向】
printf
- int _write (int fd, char *pBuffer, int size)
- {
- for (int i = 0; i < size; i++)
- {
- while(RESET == usart_flag_get(USART0, USART_FLAG_TC));//等待上一次串口数据发送完成
- usart_data_transmit(USART0, pBuffer[i]);//写DR,串口1将发送数据
- }
- return size;
- }
【gd32h7xx.cfg】
- # script for GD32H7xx Series
- source [find target/swj-dp.tcl]
- source [find mem_helper.tcl]
- if { [info exists CHIPNAME] } {
- set _CHIPNAME $CHIPNAME
- } else {
- set _CHIPNAME gd32h7xx
- }
- set _ENDIAN little
- # Work-area is a space in RAM used for flash programming
- # By default use 4kB
- if { [info exists WORKAREASIZE] } {
- set _WORKAREASIZE $WORKAREASIZE
- } else {
- set _WORKAREASIZE 0x1000
- }
- # Allow overriding the Flash bank size
- if { [info exists FLASH_SIZE] } {
- set _FLASH_SIZE $FLASH_SIZE
- } else {
- # autodetect size
- set _FLASH_SIZE 0
- }
- #jtag scan chain
- if { [info exists CPUTAPID] } {
- set _CPUTAPID $CPUTAPID
- } else {
- set _CPUTAPID 0x0BD12477
- }
- swj_newdap $_CHIPNAME cpu -irlen 4 -ircapture 0x1 -irmask 0xf -expected-id $_CPUTAPID
- dap create $_CHIPNAME.dap -chain-position $_CHIPNAME.cpu
- if {[using_jtag]} {
- jtag newtap $_CHIPNAME bs -irlen 5
- }
- set _TARGETNAME $_CHIPNAME.cpu
- target create $_TARGETNAME cortex_m -endian $_ENDIAN -dap $_CHIPNAME.dap
- $_TARGETNAME configure -work-area-phys 0x24000000 -work-area-size $_WORKAREASIZE -work-area-backup 0
- # flash size will be probed
- set _FLASHNAME $_CHIPNAME.flash
- flash bank $_FLASHNAME gd32h7xx 0x08000000 $_FLASH_SIZE 0 0 $_TARGETNAME
- # JTAG speed should be <= F_CPU/6. F_CPU after reset is 8MHz, so use F_JTAG = 1MHz
- adapter speed 1000
- adapter srst delay 100
- if {[using_jtag]} {
- jtag_ntrst_delay 100
- }
- reset_config srst_nogate
- if {![using_hla]} {
- # if srst is not fitted use SYSRESETREQ to
- # perform a soft reset
- cortex_m reset_config sysresetreq
- }
【资料下载】
GD32H7的GCC模板:https://github.com/xutongxin1/GD32H7xx_CLion_GCC_Template
GD32F3:https://github.com/xutongxin1/GD32f30x_CLion_GCC_Template
【致谢】
感谢兆易创新这次测评机会,感谢xtx师兄对本项目的指导,感谢评测群里工作人员以及群大佬分享的资料。