本帖最后由 一碗面 于 2024-5-26 18:06 编辑

【简介】
本文讲述了如何使用Clion开发GD32H7

【前言】
与Clion开发stm32的配置类似,只需要添加GD32特定的OpenOCD工具,以及更改GD32对应的GCC编译链接库,启动文件等资源即可,还有烧录时候的配置文件。具体配置过程请看:https://www.cnblogs.com/xutongxin/articles/17609760.html

【串口重定向】
printf
  1. int _write (int fd, char *pBuffer, int size)
  2. {
  3.     for (int i = 0; i < size; i++)
  4.     {
  5.         while(RESET == usart_flag_get(USART0, USART_FLAG_TC));//等待上一次串口数据发送完成
  6.         usart_data_transmit(USART0, pBuffer[i]);//写DR,串口1将发送数据
  7.     }
  8.     return size;
  9. }

【gd32h7xx.cfg】
  1. # script for GD32H7xx Series

  2. source [find target/swj-dp.tcl]
  3. source [find mem_helper.tcl]

  4. if { [info exists CHIPNAME] } {
  5.    set _CHIPNAME $CHIPNAME
  6. } else {
  7.    set _CHIPNAME gd32h7xx
  8. }

  9. set _ENDIAN little

  10. # Work-area is a space in RAM used for flash programming
  11. # By default use 4kB
  12. if { [info exists WORKAREASIZE] } {
  13.    set _WORKAREASIZE $WORKAREASIZE
  14. } else {
  15.    set _WORKAREASIZE 0x1000
  16. }

  17. # Allow overriding the Flash bank size
  18. if { [info exists FLASH_SIZE] } {
  19.         set _FLASH_SIZE $FLASH_SIZE
  20. } else {
  21.         # autodetect size
  22.         set _FLASH_SIZE 0
  23. }

  24. #jtag scan chain
  25. if { [info exists CPUTAPID] } {
  26.    set _CPUTAPID $CPUTAPID
  27. } else {
  28.    set _CPUTAPID 0x0BD12477
  29. }

  30. swj_newdap $_CHIPNAME cpu -irlen 4 -ircapture 0x1 -irmask 0xf -expected-id $_CPUTAPID
  31. dap create $_CHIPNAME.dap -chain-position $_CHIPNAME.cpu

  32. if {[using_jtag]} {
  33.    jtag newtap $_CHIPNAME bs -irlen 5
  34. }
  35. set _TARGETNAME $_CHIPNAME.cpu
  36. target create $_TARGETNAME cortex_m -endian $_ENDIAN -dap $_CHIPNAME.dap

  37. $_TARGETNAME configure -work-area-phys 0x24000000 -work-area-size $_WORKAREASIZE -work-area-backup 0

  38. # flash size will be probed
  39. set _FLASHNAME $_CHIPNAME.flash
  40. flash bank $_FLASHNAME gd32h7xx 0x08000000 $_FLASH_SIZE 0 0 $_TARGETNAME

  41. # JTAG speed should be <= F_CPU/6. F_CPU after reset is 8MHz, so use F_JTAG = 1MHz
  42. adapter speed 1000

  43. adapter srst delay 100
  44. if {[using_jtag]} {
  45. jtag_ntrst_delay 100
  46. }

  47. reset_config srst_nogate

  48. if {![using_hla]} {
  49.     # if srst is not fitted use SYSRESETREQ to
  50.     # perform a soft reset
  51.     cortex_m reset_config sysresetreq
  52. }


【资料下载】
GD32H7的GCC模板:https://github.com/xutongxin1/GD32H7xx_CLion_GCC_Template
GD32F3:https://github.com/xutongxin1/GD32f30x_CLion_GCC_Template

【致谢】
感谢兆易创新这次测评机会,感谢xtx师兄对本项目的指导,感谢评测群里工作人员以及群大佬分享的资料。