我使用的是GD32F103VET6芯片进行移植,以下是本人的gitee库。
Gitee//gitee.com/zhaodhajhdjahwd/gd32-bsp
1 BSP 框架制作
在具体移植GD32407V-START的BSP之前,先做好GD32的BSP架构。BSP 框架结构如下图所示:在这里插入图片描述GD32的BSP架构主要分为三个部分:libraries、tools和具体的Boards,其中libraries包含了GD32的通用库,包括每个系列的HAL以及适配RT-Thread的drivers;tools是生成工程的Python脚本工具;另外就是Boards文件,当然这里的Boards有很多,我这里值列举了GD32103C-eval。这里先谈谈libraries和tools的构建,然后在后文单独讨论具体板级BSP的制作。1.1 Libraries构建
Libraries文件夹包含兆易创新提供的HAL库,这个直接在兆易创新的官网就可以下载。
http://www.gd32mcu.com/cn/download/0?kw=GD32F1
然后将HAL库(GD32F10x_Firmware_Library)复制到libraries目录下,重命名为GD32F10x_Firmware_Library,其他的系列类似
GD32F10x_Firmware_Library就是官方的文件,基本是不用动的,只是在文件夹中需要添加构建工程的脚本文件SConscript,其实也就是Python脚本。SConscript文件的内容如下:
1importrtconfig
2frombuildingimport*
3
4#getcurrentdirectory
5cwd=GetCurrentDir()
6
7#ThesetofsourcefilesassociatedwiththisSConscriptfile.
8
9src=Split('''
10CMSIS/GD/GD32F10x/Source/system_gd32f10x.c
11GD32F10x_standard_peripheral/Source/gd32f10x_gpio.c
12GD32F10x_standard_peripheral/Source/gd32f10x_rcu.c
13GD32F10x_standard_peripheral/Source/gd32f10x_exti.c
14GD32F10x_standard_peripheral/Source/gd32f10x_misc.c
15''')
16
17ifGetDepend(['RT_USING_SERIAL']):
18src+=['GD32F10x_standard_peripheral/Source/gd32f10x_usart.c']
19
20ifGetDepend(['RT_USING_I2C']):
21src+=['GD32F10x_standard_peripheral/Source/gd32f10x_i2c.c']
22
23ifGetDepend(['RT_USING_SPI']):
24src+=['GD32F10x_standard_peripheral/Source/gd32f10x_spi.c']
25
26ifGetDepend(['RT_USING_CAN']):
27src+=['GD32F10x_standard_peripheral/Source/gd32f10x_can.c']
28
29ifGetDepend(['BSP_USING_ETH']):
30src+=['GD32F10x_standard_peripheral/Source/gd32f10x_enet.c']
31
32ifGetDepend(['RT_USING_ADC']):
33src+=['GD32F10x_standard_peripheral/Source/gd32f10x_adc.c']
34
35ifGetDepend(['RT_USING_DAC']):
36src+=['GD32F10x_standard_peripheral/Source/gd32f10x_dac.c']
37
38ifGetDepend(['RT_USING_HWTIMER']):
39src+=['GD32F10x_standard_peripheral/Source/gd32f10x_timer.c']
40
41ifGetDepend(['RT_USING_RTC']):
42src+=['GD32F10x_standard_peripheral/Source/gd32f10x_rtc.c']
43src+=['GD32F10x_standard_peripheral/Source/gd32f10x_pmu.c']
44
45ifGetDepend(['RT_USING_WDT']):
46src+=['GD32F10x_standard_peripheral/Source/gd32f10x_wwdgt.c']
47src+=['GD32F10x_standard_peripheral/Source/gd32f10x_fwdgt.c']
48
49ifGetDepend(['RT_USING_SDIO']):
50src+=['GD32F10x_standard_peripheral/Source/gd32f10x_sdio.c']
51
52path=[
53cwd+'/CMSIS/GD/GD32F10x/Include',
54cwd+'/CMSIS',
55cwd+'/GD32F10x_standard_peripheral/Include',]
56
57CPPDEFINES=['USE_STDPERIPH_DRIVER']
58
59group=DefineGroup('Libraries',src,depend=[''],CPPPATH=path,CPPDEFINES=CPPDEFINES)
60
61Return('group')
该文件主要的作用就是添加库文件和头文件路径,一部分文件是属于基础文件,因此直接调用Python库的Split包含,另外一部分文件是根据实际的应用需求添加的。
接下来说说Kconfig文件,这里是对内核和组件的功能进行配置,对RT-Thread的组件进行自由裁剪。如果使用RT-Thread studio,则通过RT-Thread Setting可以体现Kconfig文件的作用。
如果使用ENV环境,则在使用 menuconfig配置和裁剪 RT-Thread时体现。
后面所有的Kconfig文件都是一样的逻辑。下表列举一些常用的Kconfig句法规则。
Kconfig的语法规则网上资料很多,自行去学习吧。
bsp/gd32/Kconfig内容如下:
1configSOC_FAMILY_GD32
2bool
3
4configSOC_SERIES_GD32F1
5bool
6selectARCH_ARM_CORTEX_M3
7selectSOC_FAMILY_GD32
8
9configSOC_SERIES_GD32F2
10bool
11selectARCH_ARM_CORTEX_M3
12selectSOC_FAMILY_GD32
13
14configSOC_SERIES_GD32F3
15bool
16selectARCH_ARM_CORTEX_M4
17selectSOC_FAMILY_GD32
18
19configSOC_SERIES_GD32F4
20bool
21selectARCH_ARM_CORTEX_M4
22selectSOC_FAMILY_GD32
最后谈谈HAL_Drivers,这个文件夹就是GD32的外设驱动文件夹,为上层应用提供调用接口。
好了,先看E:RT_ThreadGD32_BSPrt_thread_codebspgd32f103librariesgd32_drivers/SConscript文件。
1Import('RTT_ROOT')
2Import('rtconfig')
3frombuildingimport*
4
5cwd=GetCurrentDir()
6
7#addthegeneraldrivers.
8src=Split("""
9""")
10
11#addpindrivers.
12ifGetDepend('RT_USING_PIN'):
13src+=['drv_gpio.c']
14
15#addusartdrivers.
16ifGetDepend(['RT_USING_SERIAL']):
17src+=['drv_usart.c']
18
19#addi2cdrivers.
20ifGetDepend(['RT_USING_I2C','RT_USING_I2C_BITOPS']):
21ifGetDepend('BSP_USING_I2C0')orGetDepend('BSP_USING_I2C1')orGetDepend('BSP_USING_I2C2')orGetDepend('BSP_USING_I2C3'):
22src+=['drv_soft_i2c.c']
23
24#addspidrivers.
25ifGetDepend('RT_USING_SPI'):
26src+=['drv_spi.c']
27
28#addspiflashdrivers.
29ifGetDepend('RT_USING_SFUD'):
30src+=['drv_spi_flash.c','drv_spi.c']
31
32ifGetDepend('RT_USING_WDT'):
33src+=['drv_wdt.c']
34
35ifGetDepend('RT_USING_RTC'):
36src+=['drv_rtc.c']
37
38ifGetDepend('RT_USING_HWTIMER'):
39src+=['drv_hwtimer.c']
40
41ifGetDepend('RT_USING_ADC'):
42src+=['drv_adc.c']
43
44path=[cwd]
45
46group=DefineGroup('Drivers',src,depend=[''],CPPPATH=path)
47
48Return('group')
E:RT_ThreadGD32_BSPrt_thread_codebspgd32f103librariesgd32_drivers/Kconfig文件结构如下:
1ifBSP_USING_USBD
2configBSP_USBD_TYPE_FS
3bool
4#"USBFullSpeed(FS)Core"
5configBSP_USBD_TYPE_HS
6bool
7#"USBHighSpeed(HS)Core"
8
9configBSP_USBD_SPEED_HS
10bool
11#"USBHighSpeed(HS)Mode"
12configBSP_USBD_SPEED_HSINFS
13bool
14#"USBHighSpeed(HS)CoreinFSmode"
15
16configBSP_USBD_PHY_EMBEDDED
17bool
18#"UsingEmbeddedphyinterface"
19configBSP_USBD_PHY_UTMI
20bool
21#"UTMI:USB2.0TransceiverMacrocellInterace"
22configBSP_USBD_PHY_ULPI
23bool
24#"ULPI:UTMI+LowPinInterface"
25endif
1.2 Tools构建
该文件夹就是工程构建的脚本,
1importos
2importsys
3importshutil
4
5cwd_path=os.getcwd()
6sys.path.append(os.path.join(os.path.dirname(cwd_path),'rt-thread','tools'))
7
8
9#BSPdistfunction
10defdist_do_building(BSP_ROOT,dist_dir):
11frommkdistimportbsp_copy_files
12importrtconfig
13
14print("=>copygd32bsplibrary")
15library_dir=os.path.join(dist_dir,'libraries')
16library_path=os.path.join(os.path.dirname(BSP_ROOT),'libraries')
17bsp_copy_files(os.path.join(library_path,rtconfig.BSP_LIBRARY_TYPE),
18os.path.join(library_dir,rtconfig.BSP_LIBRARY_TYPE))
19
20print("=>copybspdrivers")
21bsp_copy_files(os.path.join(library_path,'HAL_Drivers'),os.path.join(library_dir,'HAL_Drivers'))
22shutil.copyfile(os.path.join(library_path,'Kconfig'),os.path.join(library_dir,'Kconfig'))
以上代码很简单,主要使用了Python的OS模块的join函数,该函数的作用就是连接两个或更多的路径名。最后将BSP依赖的文件复制到指定目录下。在使用scons --dist 命令打包的时候,就是依赖的该脚本,生成的dist 文件夹的工程到任何目录下使用,也就是将BSP相关的库以及内核文件提取出来,可以将该工程任意拷贝。1.3 gd32f103vet6-eval构建
2 BSP移植
2.1 Keil环境准备
接下来我们下载GD32F30x的软件支持包。
下载地址:http://www.gd32mcu.com/cn/download/0?kw=GD32F1
双击安装包,按照操作步骤进行安装。
安装成功后,重新打开Keil,则可以在File->Device Database中出现Gigadevice的下拉选项,点击可以查看到相应的型号。2.2 BSP工程制作
1.构建基础工程
首先看看RT-Thread代码仓库中已有很多BSP,而我要移植的是Cortex-M4内核。这里我找了一个相似的内核,把它复制一份,并修改文件名为:gd32103C-eval。这样就有一个基础的工程。然后就开始增删改查,完成最终的BSP,几乎所有的BSP的制作都是如此。
2.修改BSP构建脚本
E:RT_ThreadGD32_BSPrt_thread_codebspgd32f103gd32f103vet6/Kconfig修改后的内容如下
1mainmenu"RT-ThreadConfiguration"
2
3configBSP_DIR
4string
5optionenv="BSP_ROOT"
6default"."
7
8configRTT_DIR
9string
10optionenv="RTT_ROOT"
11default"../../.."
12
13configPKGS_DIR
14string
15optionenv="PKGS_ROOT"
16default"packages"
17
18source"$RTT_DIR/Kconfig"
19source"$PKGS_DIR/Kconfig"
20source"../libraries/Kconfig"
21source"board/Kconfig"
该文件是获取所有路径下的Kconfig。
E:RT_ThreadGD32_BSPrt_thread_codebspgd32f103gd32f103vet6/SConscript修改后的内容如下:
1#formodulecompiling
2importos
3Import('RTT_ROOT')
4frombuildingimport*
5
6cwd=GetCurrentDir()
7objs=[]
8list=os.listdir(cwd)
9
10fordinlist:
11path=os.path.join(cwd,d)
12ifos.path.isfile(os.path.join(path,'SConscript')):
13objs=objs+SConscript(os.path.join(d,'SConscript'))
14
15Return('objs')
该文件是用于遍历当前目录的所有文件夹。
E:RT_ThreadGD32_BSPrt_thread_codebspgd32f103gd32f103vet6/SConstruct修改后的内容如下:
1importos
2importsys
3importrtconfig
4
5ifos.getenv('RTT_ROOT'):
6RTT_ROOT=os.getenv('RTT_ROOT')
7else:
8RTT_ROOT=os.path.normpath(os.getcwd()+'/../../..')
9
10sys.path=sys.path+[os.path.join(RTT_ROOT,'tools')]
11try:
12frombuildingimport*
13except:
14print('CannotfoundRT-Threadrootdirectory,pleasecheckRTT_ROOT')
15print(RTT_ROOT)
16exit(-1)
17
18TARGET='rtthread.'+rtconfig.TARGET_EXT
19
20DefaultEnvironment(tools=[])
21env=Environment(tools=['mingw'],
22AS=rtconfig.AS,ASFLAGS=rtconfig.AFLAGS,
23CC=rtconfig.CC,CCFLAGS=rtconfig.CFLAGS,
24AR=rtconfig.AR,ARFLAGS='-rc',
25CXX=rtconfig.CXX,CXXFLAGS=rtconfig.CXXFLAGS,
26LINK=rtconfig.LINK,LINKFLAGS=rtconfig.LFLAGS)
27env.PrependENVPath('PATH',rtconfig.EXEC_PATH)
28
29ifrtconfig.PLATFORM=='iar':
30env.Replace(CCCOM=['$CC$CCFLAGS$CPPFLAGS$_CPPDEFFLAGS$_CPPINCFLAGS-o$TARGET$SOURCES'])
31env.Replace(ARFLAGS=[''])
32env.Replace(LINKCOM=env["LINKCOM"]+'--maprtthread.map')
33
34Export('RTT_ROOT')
35Export('rtconfig')
36
37SDK_ROOT=os.path.abspath('./')
38
39ifos.path.exists(SDK_ROOT+'/libraries'):
40libraries_path_prefix=SDK_ROOT+'/libraries'
41else:
42libraries_path_prefix=os.path.dirname(SDK_ROOT)+'/libraries'
43
44SDK_LIB=libraries_path_prefix
45Export('SDK_LIB')
46
47#preparebuildingenvironment
48objs=PrepareBuilding(env,RTT_ROOT,has_libcpu=False)
49
50gd32_library='GD32F10x_Firmware_Library'
51rtconfig.BSP_LIBRARY_TYPE=gd32_library
52
53#includelibraries
54objs.extend(SConscript(os.path.join(libraries_path_prefix,gd32_library,'SConscript')))
55
56#includedrivers
57objs.extend(SConscript(os.path.join(libraries_path_prefix,'gd32_drivers','SConscript')))
58
59#makeabuilding
60DoBuilding(TARGET,objs)
该文件用于链接所有的依赖文件,并调用make进行编译。
3.修改开发环境信息
E:RT_ThreadGD32_BSPrt_thread_codebspgd32f103gd32f103vet6/cconfig.h修改后的内容如下
1#ifndefCCONFIG_H__
2#defineCCONFIG_H__
3/*Automaticallygeneratedfile;DONOTEDIT.*/
4/*compilerconfigurefileforRT-ThreadinGCC*/
5
6#defineHAVE_NEWLIB_H1
7#defineLIBC_VERSION"newlib2.4.0"
8
9#defineHAVE_SYS_SIGNAL_H1
10#defineHAVE_SYS_SELECT_H1
11#defineHAVE_PTHREAD_H1
12
13#defineHAVE_FDSET1
14#defineHAVE_SIGACTION1
15#defineGCC_VERSION_STR"5.4.120160919(release)[ARM/embedded-5-branchrevision240496]"
16#defineSTDC"2011"
17
18#endif
该文件是是编译BSP的环境信息,需根据实时修改。
4.修改KEIL的模板工程
双击:template.uvprojx即可修改模板工程。
修改为对应芯片设备:
修改FLASH和RAM的配置:该部分需参照技术手册进行修改
修改可执行文件名字:
修改默认调试工具:CMSIS-DAP Debugger。
5.修改board文件夹
(1) 修改E:RT_ThreadGD32_BSPrt_thread_codebspgd32f103gd32f103vet6boardlinker_scripts/link.icf
修改后的内容如下
1/*###ICF###SectionhandledbyICFeditor,don'ttouch!****/
2/*-Editorannotationfile-*/
3/*IcfEditorFile="$TOOLKIT_DIR$configideIcfEditorcortex_v1_0.xml"*/
4/*-Specials-*/
5definesymbol__ICFEDIT_intvec_start__=0x08000000;
6/*-MemoryRegions-*/
7definesymbol__ICFEDIT_region_ROM_start__=0x08000000;
8definesymbol__ICFEDIT_region_ROM_end__=0x08080000;
9definesymbol__ICFEDIT_region_RAM_start__=0x20000000;
10definesymbol__ICFEDIT_region_RAM_end__=0x20010000;
11/*-Sizes-*/
12definesymbol__ICFEDIT_size_cstack__=0x200;
13definesymbol__ICFEDIT_size_heap__=0x200;
14/****EndofICFeditorsection.###ICF###*/
15
16exportsymbol__ICFEDIT_region_RAM_end__;
17
18definesymbol__region_RAM1_start__=0x10000000;
19definesymbol__region_RAM1_end__=0x1000FFFF;
20
21definememorymemwithsize=4G;
22defineregionROM_region=mem:[from__ICFEDIT_region_ROM_start__to__ICFEDIT_region_ROM_end__];
23defineregionRAM_region=mem:[from__ICFEDIT_region_RAM_start__to__ICFEDIT_region_RAM_end__];
24defineregionRAM1_region=mem:[from__region_RAM1_start__to__region_RAM1_end__];
25
26defineblockCSTACKwithalignment=8,size=__ICFEDIT_size_cstack__{};
27defineblockHEAPwithalignment=8,size=__ICFEDIT_size_heap__{};
28
29initializebycopy{readwrite};
30donotinitialize{section.noinit};
31
32keep{sectionFSymTab};
33keep{sectionVSymTab};
34keep{section.rti_fn*};
35placeataddressmem:__ICFEDIT_intvec_start__{readonlysection.intvec};
36
37placeinROM_region{readonly};
38placeinRAM_region{readwrite,
39blockCSTACK,blockHEAP};
40placeinRAM1_region{section.sram};
该文件是IAR编译的链接脚本,根据《GD32F103xx_Datasheet_Rev2.1》可知,GD32F103VET6的flash大小为3072KB,SRAM大小为192KB,因此需要设置ROM和RAM的起始地址和堆栈大小等。(2) 修改E:RT_ThreadGD32_BSPrt_thread_codebspgd32f103gd32f103vet6boardlinker_scripts/link.ld修改后的内容如下:
1/*
2*linkerscriptforGD32F30xwithGNUld
3*BruceOu2021-12-18
4*/
5
6/*ProgramEntry,settomarkitas"used"andavoidgc*/
7MEMORY
8{
9CODE(rx):ORIGIN=0x08000000,LENGTH=512k/*256KBflash*/
10DATA(rw):ORIGIN=0x20000000,LENGTH=64k/*48KBsram*/
11}
12ENTRY(Reset_Handler)
13_system_stack_size=0x200;
14
15SECTIONS
16{
17.text:
18{
19.=ALIGN(4);
20_stext=.;
21KEEP(*(.isr_vector))/*Startupcode*/
22.=ALIGN(4);
23*(.text)/*remainingcode*/
24*(.text.*)/*remainingcode*/
25*(.rodata)/*read-onlydata(constants)*/
26*(.rodata*)
27*(.glue_7)
28*(.glue_7t)
29*(.gnu.linkonce.t*)
30
31/*sectioninformationforfinshshell*/
32.=ALIGN(4);
33__fsymtab_start=.;
34KEEP(*(FSymTab))
35__fsymtab_end=.;
36.=ALIGN(4);
37__vsymtab_start=.;
38KEEP(*(VSymTab))
39__vsymtab_end=.;
40.=ALIGN(4);
41
42/*sectioninformationforinitial.*/
43.=ALIGN(4);
44__rt_init_start=.;
45KEEP(*(SORT(.rti_fn*)))
46__rt_init_end=.;
47.=ALIGN(4);
48
49.=ALIGN(4);
50_etext=.;
51}>CODE=0
52
53/*.ARM.exidxissorted,sohastogoinitsownoutputsection.*/
54__exidx_start=.;
55.ARM.exidx:
56{
57*(.ARM.exidx*.gnu.linkonce.armexidx.*)
58
59/*Thisisusedbythestartupinordertoinitializethe.datasecion*/
60_sidata=.;
61}>CODE
62__exidx_end=.;
63
64/*.datasectionwhichisusedforinitializeddata*/
65
66.data:AT(_sidata)
67{
68.=ALIGN(4);
69/*Thisisusedbythestartupinordertoinitializethe.datasecion*/
70_sdata=.;
71
72*(.data)
73*(.data.*)
74*(.gnu.linkonce.d*)
75
76.=ALIGN(4);
77/*Thisisusedbythestartupinordertoinitializethe.datasecion*/
78_edata=.;
79}>DATA
80
81.stack:
82{
83.=.+_system_stack_size;
84.=ALIGN(4);
85_estack=.;
86}>DATA
87
88__bss_start=.;
89.bss:
90{
91.=ALIGN(4);
92/*Thisisusedbythestartupinordertoinitializethe.bsssecion*/
93_sbss=.;
94
95*(.bss)
96*(.bss.*)
97*(COMMON)
98
99.=ALIGN(4);
100/*Thisisusedbythestartupinordertoinitializethe.bsssecion*/
101_ebss=.;
102
103*(.bss.init)
104}>DATA
105__bss_end=.;
106
107_end=.;
108
109/*Stabsdebuggingsections.*/
110.stab0:{*(.stab)}
111.stabstr0:{*(.stabstr)}
112.stab.excl0:{*(.stab.excl)}
113.stab.exclstr0:{*(.stab.exclstr)}
114.stab.index0:{*(.stab.index)}
115.stab.indexstr0:{*(.stab.indexstr)}
116.comment0:{*(.comment)}
117/*DWARFdebugsections.
118*SymbolsintheDWARFdebuggingsectionsarerelativetothebeginning
119*ofthesectionsowebeginthemat0.*/
120/*DWARF1*/
121.debug0:{*(.debug)}
122.line0:{*(.line)}
123/*GNUDWARF1extensions*/
124.debug_srcinfo0:{*(.debug_srcinfo)}
125.debug_sfnames0:{*(.debug_sfnames)}
126/*DWARF1.1andDWARF2*/
127.debug_aranges0:{*(.debug_aranges)}
128.debug_pubnames0:{*(.debug_pubnames)}
129/*DWARF2*/
130.debug_info0:{*(.debug_info.gnu.linkonce.wi.*)}
131.debug_abbrev0:{*(.debug_abbrev)}
132.debug_line0:{*(.debug_line)}
133.debug_frame0:{*(.debug_frame)}
134.debug_str0:{*(.debug_str)}
135.debug_loc0:{*(.debug_loc)}
136.debug_macinfo0:{*(.debug_macinfo)}
137/*SGI/MIPSDWARF2extensions*/
138.debug_weaknames0:{*(.debug_weaknames)}
139.debug_funcnames0:{*(.debug_funcnames)}
140.debug_typenames0:{*(.debug_typenames)}
141.debug_varnames0:{*(.debug_varnames)}
142}
该文件是GCC编译的链接脚本,根据《GD32F407xx_Datasheet_Rev2.1》可知,GD32F407VKT6的flash大小为3072KB,SRAM大小为192KB,因此CODE和DATA 的LENGTH分别设置为3072KB和192KB,其他芯片类似,但其实地址都是一样的。(3) 修改E:RT_ThreadGD32_BSPrt_thread_codebspgd32f103gd32f103vet6board/linker_scripts/link.sct该文件是MDK的连接脚本,根据《GD32F407xx_Datasheet_Rev2.1》手册,因此需要将 LR_IROM1 和 ER_IROM1 的参数设置为 0x00300000;RAM 的大小为192k,因此需要将 RW_IRAM1 的参数设置为 0x00030000。
1;*************************************************************
2;***Scatter-LoadingDescriptionFilegeneratedbyuVision***
3;*************************************************************
4
5LR_IROM10x080000000x00080000{;loadregionsize_region
6ER_IROM10x080000000x00080000{;loadaddress=executionaddress
7*.o(RESET,+First)
8*(InRoot$$Sections)
9.ANY(+RO)
10}
11RW_IRAM10x200000000x00010000{;RWdata
12.ANY(+RW+ZI)
13}
14}
(4) 修改
E:RT_ThreadGD32_BSPrt_thread_codebspgd32f103gd32f103vet6board/board.h文件
修改后内容如下:
1/*
2*Copyright(c)2006-2021,RT-ThreadDevelopmentTeam
3*
4*SPDX-License-Identifier:Apache-2.0
5*
6*ChangeLogs:
7*DateAuthorNotes
8*2021-12-18BruceOufirstimplementation
9*/
10#ifndef__BOARD_H__
11#define__BOARD_H__
12
13#include"gd32f10x.h"
14#include"drv_usart.h"
15#include"drv_gpio.h"
16
17#include"gd32f10x_exti.h"
18
19#defineEXT_SDRAM_BEGIN(0xC0000000U)/*thebeginingaddressofexternalSDRAM*/
20#defineEXT_SDRAM_END(EXT_SDRAM_BEGIN+(32U*1024*1024))/*theendaddressofexternalSDRAM*/
21
22//InternalSRAMmemorysize[Kbytes]<8-48>
23//Default:48
24#ifdef__ICCARM__
25//Use*.icframsymbal,toavoidhardcode.
26externchar__ICFEDIT_region_RAM_end__;
27#defineGD32_SRAM_END&__ICFEDIT_region_RAM_end__
28#else
29#defineGD32_SRAM_SIZE64
30#defineGD32_SRAM_END(0x20000000+GD32_SRAM_SIZE*1024)
31#endif
32
33#ifdef__CC_ARM
34externintImage$$RW_IRAM1$$ZI$$Limit;
35#defineHEAP_BEGIN(&Image$$RW_IRAM1$$ZI$$Limit)
36#elif__ICCARM__
37#pragmasection="HEAP"
38#defineHEAP_BEGIN(__segment_end("HEAP"))
39#else
40externint__bss_end;
41#defineHEAP_BEGIN(&__bss_end)
42#endif
43
44#defineHEAP_ENDGD32_SRAM_END
45
46#endif
值得注意的是,不同的编译器规定的堆栈内存的起始地址 HEAP_BEGIN 和结束地址 HEAP_END。这里 HEAP_BEGIN 和 HEAP_END 的值需要和前面的链接脚本是一致的,需要结合实际去修改。
(5) 修改
E:RT_ThreadGD32_BSPrt_thread_codebspgd32f103gd32f103vet6board/board.c文件
修改后的文件如下:
1/*
2*Copyright(c)2006-2021,RT-ThreadDevelopmentTeam
3*
4*SPDX-License-Identifier:Apache-2.0
5*
6*ChangeLogs:
7*DateAuthorNotes
8*2021-12-18BruceOufirstimplementation
9*/
10#include
11#include
12#include
13#include
14
15/**
16*@briefThisfunctionisexecutedincaseoferroroccurrence.
17*@paramNone
18*@retvalNone
19*/
20voidError_Handler(void)
21{
22/*USERCODEBEGINError_Handler*/
23/*UsercanaddhisownimplementationtoreporttheHALerrorreturnstate*/
24while(1)
25{
26}
27/*USERCODEENDError_Handler*/
28}
29
30/**SystemClockConfiguration
31*/
32voidSystemClock_Config(void)
33{
34SysTick_Config(SystemCoreClock/RT_TICK_PER_SECOND);
35NVIC_SetPriority(SysTick_IRQn,0);
36}
37
38/**
39*Thisisthetimerinterruptserviceroutine.
40*
41*/
42voidSysTick_Handler(void)
43{
44/*enterinterrupt*/
45rt_interrupt_enter();
46
47rt_tick_increase();
48
49/*leaveinterrupt*/
50rt_interrupt_leave();
51}
52
53/**
54*ThisfunctionwillinitialGD32board.
55*/
56voidrt_hw_board_init()
57{
58/*NVICConfiguration*/
59#defineNVIC_VTOR_MASK0x3FFFFF80
60#ifdefVECT_TAB_RAM
61/*SettheVectorTablebaselocationat0x10000000*/
62SCB->VTOR=(0x10000000&NVIC_VTOR_MASK);
63#else/*VECT_TAB_FLASH*/
64/*SettheVectorTablebaselocationat0x08000000*/
65SCB->VTOR=(0x08000000&NVIC_VTOR_MASK);
66#endif
67
68SystemClock_Config();
69
70#ifdefRT_USING_COMPONENTS_INIT
71rt_components_board_init();
72#endif
73
74#ifdefRT_USING_CONSOLE
75rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
76#endif
77
78#ifdefBSP_USING_SDRAM
79rt_system_heap_init((void*)EXT_SDRAM_BEGIN,(void*)EXT_SDRAM_END);
80#else
81rt_system_heap_init((void*)HEAP_BEGIN,(void*)HEAP_END);
82#endif
83}
84
85/*@}*/
该文件重点关注的就是SystemClock_Config配置,SystemCoreClock的定义在system_gd32f1xx.c中定义的.
(6) 修改
E:RT_ThreadGD32_BSPrt_thread_codebspgd32f103gd32f103vet6board/Kconfig文件
修改后内容如下:
1menu"HardwareDriversConfig"
2
3configSOC_SERIES_GD32F10x
4bool
5defaulty
6
7configSOC_GD32103V
8bool
9selectSOC_SERIES_GD32F10x
10selectRT_USING_COMPONENTS_INIT
11selectRT_USING_USER_MAIN
12defaulty
13
14menu"OnboardPeripheralDrivers"
15
16endmenu
17
18menu"On-chipPeripheralDrivers"
19
20configBSP_USING_GPIO
21bool"EnableGPIO"
22selectRT_USING_PIN
23defaulty
24
25menuconfigBSP_USING_UART
26bool"EnableUART"
27defaulty
28selectRT_USING_SERIAL
29ifBSP_USING_UART
30configBSP_USING_UART0
31bool"EnableUART0"
32defaultn
33
34configBSP_UART0_RX_USING_DMA
35bool"EnableUART0RXDMA"
36dependsonBSP_USING_UART0
37selectRT_SERIAL_USING_DMA
38defaultn
39
40configBSP_USING_UART1
41bool"EnableUART1"
42defaulty
43
44configBSP_UART1_RX_USING_DMA
45bool"EnableUART1RXDMA"
46dependsonBSP_USING_UART1
47selectRT_SERIAL_USING_DMA
48defaultn
49
50configBSP_USING_UART2
51bool"EnableUART2"
52defaultn
53
54configBSP_UART2_RX_USING_DMA
55bool"EnableUART2RXDMA"
56dependsonBSP_USING_UART2
57selectRT_SERIAL_USING_DMA
58defaultn
59
60configBSP_USING_UART3
61bool"EnableUART3"
62defaultn
63
64configBSP_UART3_RX_USING_DMA
65bool"EnableUART3RXDMA"
66dependsonBSP_USING_UART3
67selectRT_SERIAL_USING_DMA
68defaultn
69
70configBSP_USING_UART4
71bool"EnableUART4"
72defaultn
73
74configBSP_UART4_RX_USING_DMA
75bool"EnableUART4RXDMA"
76dependsonBSP_USING_UART4
77selectRT_SERIAL_USING_DMA
78defaultn
79endif
80
81menuconfigBSP_USING_SPI
82bool"EnableSPIBUS"
83defaultn
84selectRT_USING_SPI
85ifBSP_USING_SPI
86configBSP_USING_SPI1
87bool"EnableSPI1BUS"
88defaultn
89
90configBSP_SPI1_TX_USING_DMA
91bool"EnableSPI1TXDMA"
92dependsonBSP_USING_SPI1
93defaultn
94
95configBSP_SPI1_RX_USING_DMA
96bool"EnableSPI1RXDMA"
97dependsonBSP_USING_SPI1
98selectBSP_SPI1_TX_USING_DMA
99defaultn
100endif
101
102menuconfigBSP_USING_I2C1
103bool"EnableI2C1BUS(softwaresimulation)"
104defaultn
105selectRT_USING_I2C
106selectRT_USING_I2C_BITOPS
107selectRT_USING_PIN
108ifBSP_USING_I2C1
109configBSP_I2C1_SCL_PIN
110int"i2c1sclpinnumber"
111range1216
112default24
113configBSP_I2C1_SDA_PIN
114int"I2C1sdapinnumber"
115range1216
116default25
117endif
118
119configBSP_USING_WDT
120bool"EnableWatchdogTimer"
121selectRT_USING_WDT
122defaultn
123
124configBSP_USING_RTC
125bool"EnableInternalRTC"
126selectRT_USING_RTC
127defaultn
128
129menuconfigBSP_USING_HWTIMER
130bool"Enablehwtimer"
131defaultn
132selectRT_USING_HWTIMER
133ifBSP_USING_HWTIMER
134configBSP_USING_HWTIMER0
135bool"usinghwtimer0"
136defaultn
137configBSP_USING_HWTIMER1
138bool"usinghwtimer1"
139defaultn
140configBSP_USING_HWTIMER2
141bool"usinghwtimer2"
142defaultn
143configBSP_USING_HWTIMER3
144bool"usinghwtimer3"
145defaultn
146configBSP_USING_HWTIMER4
147bool"usinghwtimer4"
148defaultn
149configBSP_USING_HWTIMER5
150bool"usinghwtimer5"
151defaultn
152configBSP_USING_HWTIMER6
153bool"usinghwtimer6"
154defaultn
155configBSP_USING_HWTIMER7
156bool"usinghwtimer7"
157defaultn
158endif
159
160menuconfigBSP_USING_ADC
161bool"EnableADC"
162defaultn
163selectRT_USING_ADC
164ifBSP_USING_ADC
165configBSP_USING_ADC0
166bool"usingadc0"
167defaultn
168configBSP_USING_ADC1
169bool"usingadc1"
170defaultn
171endif
172source"../libraries/gd32_drivers/Kconfig"
173
174endmenu
175
176menu"BoardextendedmoduleDrivers"
177
178endmenu
179
180endmenu
这个文件就是配置板子驱动的,这里可根据实际需求添加。
(7) 修改
E:RT_ThreadGD32_BSPrt_thread_codebspgd32f103gd32f103vet6board/SConscript文件
修改后内容如下:
1importos
2importrtconfig
3frombuildingimport*
4
5Import('SDK_LIB')
6
7cwd=GetCurrentDir()
8
9#addgeneraldrivers
10src=Split('''
11board.c
12''')
13
14path=[cwd]
15
16startup_path_prefix=SDK_LIB
17
18ifrtconfig.PLATFORM=='gcc':
19src+=[startup_path_prefix+'/GD32F10x_Firmware_Library/CMSIS/GD/GD32F10x/Source/GCC/startup_gd32f10x_hd.s']
20elifrtconfig.PLATFORMin['armcc','armclang']:
21src+=[startup_path_prefix+'/GD32F10x_Firmware_Library/CMSIS/GD/GD32F10x/Source/ARM/startup_gd32f10x_hd.s']
22elifrtconfig.CROSS_TOOL=='iar':
23src+=[startup_path_prefix+'/GD32F10x_Firmware_Library/CMSIS/GD/GD32F10x/Source/IAR/startup_gd32f10x_hd.s']
24
25CPPDEFINES=['GD32F10X_HD']
26group=DefineGroup('Drivers',src,depend=[''],CPPPATH=path,CPPDEFINES=CPPDEFINES)
27
28Return('group')
29
30
31
32cwd=GetCurrentDir()
33
34#addgeneraldrivers
35src=Split('''
36board.c
37''')
38
39path=[cwd]
40
41startup_path_prefix=SDK_LIB
42
43ifrtconfig.CROSS_TOOL=='gcc':
44src+=[startup_path_prefix+'/GD32F4xx_HAL/CMSIS/GD/GD32F4xx/Source/GCC/startup_gd32f4xx.S']
45elifrtconfig.CROSS_TOOL=='keil':
46src+=[startup_path_prefix+'/GD32F4xx_HAL/CMSIS/GD/GD32F4xx/Source/ARM/startup_gd32f4xx.s']
47elifrtconfig.CROSS_TOOL=='iar':
48src+=[startup_path_prefix+'/GD32F4xx_HAL/CMSIS/GD/GD32F4xx/Source/IAR/startup_gd32f4xx.s']
49
50CPPDEFINES=['GD32F407xx']
51group=DefineGroup('Drivers',src,depend=[''],CPPPATH=path,CPPDEFINES=CPPDEFINES)
52
53Return('group')
该文件主要添加board文件夹的.c文件和头文件路径。另外根据开发环境选择相应的汇编文件,和前面的libraries的SConscript语法是一样,文件的结构都是类似的,这里就没有注释了。到这里,基本所有的依赖脚本都配置完成了,接下来将通过menuconfig配置工程。6.menuconfig配置
-
BSP
+关注
关注
1文章
87浏览量
26147 -
RT-Thread
+关注
关注
31文章
1285浏览量
40075 -
GD32F103
+关注
关注
5文章
18浏览量
9431
发布评论请先 登录
相关推荐
评论