Gitee//gitee.com/zhaodhajhdjahwd/gd32-bsp
http://www.gd32mcu.com/cn/download/0?kw=GD32F1
然后将HAL库(GD32F10x_Firmware_Library)复制到libraries目录下,重命名为GD32F10x_Firmware_Library,其他的系列类似
1import rtconfig
2from building import *
3
4# get current directory
5cwd = GetCurrentDir()
6
7# The set of source files associated with this SConscript file.
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
17if GetDepend(['RT_USING_SERIAL']):
18 src += ['GD32F10x_standard_peripheral/Source/gd32f10x_usart.c']
19
20if GetDepend(['RT_USING_I2C']):
21 src += ['GD32F10x_standard_peripheral/Source/gd32f10x_i2c.c']
22
23if GetDepend(['RT_USING_SPI']):
24 src += ['GD32F10x_standard_peripheral/Source/gd32f10x_spi.c']
25
26if GetDepend(['RT_USING_CAN']):
27 src += ['GD32F10x_standard_peripheral/Source/gd32f10x_can.c']
28
29if GetDepend(['BSP_USING_ETH']):
30 src += ['GD32F10x_standard_peripheral/Source/gd32f10x_enet.c']
31
32if GetDepend(['RT_USING_ADC']):
33 src += ['GD32F10x_standard_peripheral/Source/gd32f10x_adc.c']
34
35if GetDepend(['RT_USING_DAC']):
36 src += ['GD32F10x_standard_peripheral/Source/gd32f10x_dac.c']
37
38if GetDepend(['RT_USING_HWTIMER']):
39 src += ['GD32F10x_standard_peripheral/Source/gd32f10x_timer.c']
40
41if GetDepend(['RT_USING_RTC']):
42 src += ['GD32F10x_standard_peripheral/Source/gd32f10x_rtc.c']
43 src += ['GD32F10x_standard_peripheral/Source/gd32f10x_pmu.c']
44
45if GetDepend(['RT_USING_WDT']):
46 src += ['GD32F10x_standard_peripheral/Source/gd32f10x_wwdgt.c']
47 src += ['GD32F10x_standard_peripheral/Source/gd32f10x_fwdgt.c']
48
49if GetDepend(['RT_USING_SDIO']):
50 src += ['GD32F10x_standard_peripheral/Source/gd32f10x_sdio.c']
51
52path = [
53 cwd + '/CMSIS/GD/GD32F10x/Include',
54 cwd + '/CMSIS',
55 cwd + '/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内容如下:
1config SOC_FAMILY_GD32
2 bool
3
4config SOC_SERIES_GD32F1
5 bool
6 select ARCH_ARM_CORTEX_M3
7 select SOC_FAMILY_GD32
8
9config SOC_SERIES_GD32F2
10 bool
11 select ARCH_ARM_CORTEX_M3
12 select SOC_FAMILY_GD32
13
14config SOC_SERIES_GD32F3
15 bool
16 select ARCH_ARM_CORTEX_M4
17 select SOC_FAMILY_GD32
18
19config SOC_SERIES_GD32F4
20 bool
21 select ARCH_ARM_CORTEX_M4
22 select SOC_FAMILY_GD32
最后谈谈HAL_Drivers,这个文件夹就是GD32的外设驱动文件夹,为上层应用提供调用接口。
好了,先看E:RT_ThreadGD32_BSPrt_thread_codebspgd32f103librariesgd32_drivers/SConscript文件。
1Import('RTT_ROOT')
2Import('rtconfig')
3from building import *
4
5cwd = GetCurrentDir()
6
7# add the general drivers.
8src = Split("""
9""")
10
11# add pin drivers.
12if GetDepend('RT_USING_PIN'):
13 src += ['drv_gpio.c']
14
15# add usart drivers.
16if GetDepend(['RT_USING_SERIAL']):
17 src += ['drv_usart.c']
18
19# add i2c drivers.
20if GetDepend(['RT_USING_I2C', 'RT_USING_I2C_BITOPS']):
21 if GetDepend('BSP_USING_I2C0') or GetDepend('BSP_USING_I2C1') or GetDepend('BSP_USING_I2C2') or GetDepend('BSP_USING_I2C3'):
22 src += ['drv_soft_i2c.c']
23
24# add spi drivers.
25if GetDepend('RT_USING_SPI'):
26 src += ['drv_spi.c']
27
28# add spi flash drivers.
29if GetDepend('RT_USING_SFUD'):
30 src += ['drv_spi_flash.c', 'drv_spi.c']
31
32if GetDepend('RT_USING_WDT'):
33 src += ['drv_wdt.c']
34
35if GetDepend('RT_USING_RTC'):
36 src += ['drv_rtc.c']
37
38if GetDepend('RT_USING_HWTIMER'):
39 src += ['drv_hwtimer.c']
40
41if GetDepend('RT_USING_ADC'):
42 src += ['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文件结构如下:
1if BSP_USING_USBD
2 config BSP_USBD_TYPE_FS
3 bool
4 # "USB Full Speed (FS) Core"
5 config BSP_USBD_TYPE_HS
6 bool
7 # "USB High Speed (HS) Core"
8
9 config BSP_USBD_SPEED_HS
10 bool
11 # "USB High Speed (HS) Mode"
12 config BSP_USBD_SPEED_HSINFS
13 bool
14 # "USB High Speed (HS) Core in FS mode"
15
16 config BSP_USBD_PHY_EMBEDDED
17 bool
18 # "Using Embedded phy interface"
19 config BSP_USBD_PHY_UTMI
20 bool
21 # "UTMI: USB 2.0 Transceiver Macrocell Interace"
22 config BSP_USBD_PHY_ULPI
23 bool
24 # "ULPI: UTMI+ Low Pin Interface"
25endif
1.2 Tools构建
该文件夹就是工程构建的脚本,
1import os
2import sys
3import shutil
4
5cwd_path = os.getcwd()
6sys.path.append(os.path.join(os.path.dirname(cwd_path), 'rt-thread', 'tools'))
7
8
9# BSP dist function
10def dist_do_building(BSP_ROOT, dist_dir):
11 from mkdist import bsp_copy_files
12 import rtconfig
13
14 print("=> copy gd32 bsp library")
15 library_dir = os.path.join(dist_dir, 'libraries')
16 library_path = os.path.join(os.path.dirname(BSP_ROOT), 'libraries')
17 bsp_copy_files(os.path.join(library_path, rtconfig.BSP_LIBRARY_TYPE),
18 os.path.join(library_dir, rtconfig.BSP_LIBRARY_TYPE))
19
20 print("=> copy bsp drivers")
21 bsp_copy_files(os.path.join(library_path, 'HAL_Drivers'), os.path.join(library_dir, 'HAL_Drivers'))
22 shutil.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.1 Keil环境准备
接下来我们下载GD32F30x的软件支持包。
下载地址:http://www.gd32mcu.com/cn/download/0?kw=GD32F1
双击安装包,按照操作步骤进行安装。
1.构建基础工程
首先看看RT-Thread代码仓库中已有很多BSP,而我要移植的是Cortex-M4内核。这里我找了一个相似的内核,把它复制一份,并修改文件名为:gd32103C-eval。这样就有一个基础的工程。然后就开始增删改查,完成最终的BSP,几乎所有的BSP的制作都是如此。
2.修改BSP构建脚本
E:RT_ThreadGD32_BSPrt_thread_codebspgd32f103gd32f103vet6/Kconfig修改后的内容如下
1mainmenu "RT-Thread Configuration"
2
3config BSP_DIR
4 string
5 option env="BSP_ROOT"
6 default "."
7
8config RTT_DIR
9 string
10 option env="RTT_ROOT"
11 default "../../.."
12
13config PKGS_DIR
14 string
15 option env="PKGS_ROOT"
16 default "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# for module compiling
2import os
3Import('RTT_ROOT')
4from building import *
5
6cwd = GetCurrentDir()
7objs = []
8list = os.listdir(cwd)
9
10for d in list:
11 path = os.path.join(cwd, d)
12 if os.path.isfile(os.path.join(path, 'SConscript')):
13 objs = objs + SConscript(os.path.join(d, 'SConscript'))
14
15Return('objs')
该文件是用于遍历当前目录的所有文件夹。
E:RT_ThreadGD32_BSPrt_thread_codebspgd32f103gd32f103vet6/SConstruct修改后的内容如下:
1import os
2import sys
3import rtconfig
4
5if os.getenv('RTT_ROOT'):
6 RTT_ROOT = os.getenv('RTT_ROOT')
7else:
8 RTT_ROOT = os.path.normpath(os.getcwd() + '/../../..')
9
10sys.path = sys.path + [os.path.join(RTT_ROOT, 'tools')]
11try:
12 from building import *
13except:
14 print('Cannot found RT-Thread root directory, please check RTT_ROOT')
15 print(RTT_ROOT)
16 exit(-1)
17
18TARGET = 'rtthread.' + rtconfig.TARGET_EXT
19
20DefaultEnvironment(tools=[])
21env = Environment(tools = ['mingw'],
22 AS = rtconfig.AS, ASFLAGS = rtconfig.AFLAGS,
23 CC = rtconfig.CC, CCFLAGS = rtconfig.CFLAGS,
24 AR = rtconfig.AR, ARFLAGS = '-rc',
25 CXX = rtconfig.CXX, CXXFLAGS = rtconfig.CXXFLAGS,
26 LINK = rtconfig.LINK, LINKFLAGS = rtconfig.LFLAGS)
27env.PrependENVPath('PATH', rtconfig.EXEC_PATH)
28
29if rtconfig.PLATFORM == 'iar':
30 env.Replace(CCCOM = ['$CC $CCFLAGS $CPPFLAGS $_CPPDEFFLAGS $_CPPINCFLAGS -o $TARGET $SOURCES'])
31 env.Replace(ARFLAGS = [''])
32 env.Replace(LINKCOM = env["LINKCOM"] + ' --map rtthread.map')
33
34Export('RTT_ROOT')
35Export('rtconfig')
36
37SDK_ROOT = os.path.abspath('./')
38
39if os.path.exists(SDK_ROOT + '/libraries'):
40 libraries_path_prefix = SDK_ROOT + '/libraries'
41else:
42 libraries_path_prefix = os.path.dirname(SDK_ROOT) + '/libraries'
43
44SDK_LIB = libraries_path_prefix
45Export('SDK_LIB')
46
47# prepare building environment
48objs = PrepareBuilding(env, RTT_ROOT, has_libcpu=False)
49
50gd32_library = 'GD32F10x_Firmware_Library'
51rtconfig.BSP_LIBRARY_TYPE = gd32_library
52
53# include libraries
54objs.extend(SConscript(os.path.join(libraries_path_prefix, gd32_library, 'SConscript')))
55
56# include drivers
57objs.extend(SConscript(os.path.join(libraries_path_prefix, 'gd32_drivers', 'SConscript')))
58
59# make a building
60DoBuilding(TARGET, objs)
该文件用于链接所有的依赖文件,并调用make进行编译。
3.修改开发环境信息
E:RT_ThreadGD32_BSPrt_thread_codebspgd32f103gd32f103vet6/cconfig.h修改后的内容如下
1#ifndef CCONFIG_H__
2#define CCONFIG_H__
3/* Automatically generated file; DO NOT EDIT. */
4/* compiler configure file for RT-Thread in GCC*/
5
6#define HAVE_NEWLIB_H 1
7#define LIBC_VERSION "newlib 2.4.0"
8
9#define HAVE_SYS_SIGNAL_H 1
10#define HAVE_SYS_SELECT_H 1
11#define HAVE_PTHREAD_H 1
12
13#define HAVE_FDSET 1
14#define HAVE_SIGACTION 1
15#define GCC_VERSION_STR "5.4.1 20160919 (release) [ARM/embedded-5-branch revision 240496]"
16#define STDC "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### Section handled by ICF editor, don't touch! ****/
2/*-Editor annotation file-*/
3/* IcfEditorFile="$TOOLKIT_DIR$configideIcfEditorcortex_v1_0.xml" */
4/*-Specials-*/
5define symbol __ICFEDIT_intvec_start__ = 0x08000000;
6/*-Memory Regions-*/
7define symbol __ICFEDIT_region_ROM_start__ = 0x08000000;
8define symbol __ICFEDIT_region_ROM_end__ = 0x08080000;
9define symbol __ICFEDIT_region_RAM_start__ = 0x20000000;
10define symbol __ICFEDIT_region_RAM_end__ = 0x20010000;
11/*-Sizes-*/
12define symbol __ICFEDIT_size_cstack__ = 0x200;
13define symbol __ICFEDIT_size_heap__ = 0x200;
14/**** End of ICF editor section. ###ICF###*/
15
16export symbol __ICFEDIT_region_RAM_end__;
17
18define symbol __region_RAM1_start__ = 0x10000000;
19define symbol __region_RAM1_end__ = 0x1000FFFF;
20
21define memory mem with size = 4G;
22define region ROM_region = mem:[from __ICFEDIT_region_ROM_start__ to __ICFEDIT_region_ROM_end__];
23define region RAM_region = mem:[from __ICFEDIT_region_RAM_start__ to __ICFEDIT_region_RAM_end__];
24define region RAM1_region = mem:[from __region_RAM1_start__ to __region_RAM1_end__];
25
26define block CSTACK with alignment = 8, size = __ICFEDIT_size_cstack__ { };
27define block HEAP with alignment = 8, size = __ICFEDIT_size_heap__ { };
28
29initialize by copy { readwrite };
30do not initialize { section .noinit };
31
32keep { section FSymTab };
33keep { section VSymTab };
34keep { section .rti_fn* };
35place at address mem:__ICFEDIT_intvec_start__ { readonly section .intvec };
36
37place in ROM_region { readonly };
38place in RAM_region { readwrite,
39 block CSTACK, block HEAP };
40place in RAM1_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 * linker script for GD32F30x with GNU ld
3 * BruceOu 2021-12-18
4 */
5
6/* Program Entry, set to mark it as "used" and avoid gc */
7MEMORY
8{
9 CODE (rx) : ORIGIN = 0x08000000, LENGTH = 512k /* 256KB flash */
10 DATA (rw) : ORIGIN = 0x20000000, LENGTH = 64k /* 48KB sram */
11}
12ENTRY(Reset_Handler)
13_system_stack_size = 0x200;
14
15SECTIONS
16{
17 .text :
18 {
19 . = ALIGN(4);
20 _stext = .;
21 KEEP(*(.isr_vector)) /* Startup code */
22 . = ALIGN(4);
23 *(.text) /* remaining code */
24 *(.text.*) /* remaining code */
25 *(.rodata) /* read-only data (constants) */
26 *(.rodata*)
27 *(.glue_7)
28 *(.glue_7t)
29 *(.gnu.linkonce.t*)
30
31 /* section information for finsh shell */
32 . = ALIGN(4);
33 __fsymtab_start = .;
34 KEEP(*(FSymTab))
35 __fsymtab_end = .;
36 . = ALIGN(4);
37 __vsymtab_start = .;
38 KEEP(*(VSymTab))
39 __vsymtab_end = .;
40 . = ALIGN(4);
41
42 /* section information for initial. */
43 . = ALIGN(4);
44 __rt_init_start = .;
45 KEEP(*(SORT(.rti_fn*)))
46 __rt_init_end = .;
47 . = ALIGN(4);
48
49 . = ALIGN(4);
50 _etext = .;
51 } > CODE = 0
52
53 /* .ARM.exidx is sorted, so has to go in its own output section. */
54 __exidx_start = .;
55 .ARM.exidx :
56 {
57 *(.ARM.exidx* .gnu.linkonce.armexidx.*)
58
59 /* This is used by the startup in order to initialize the .data secion */
60 _sidata = .;
61 } > CODE
62 __exidx_end = .;
63
64 /* .data section which is used for initialized data */
65
66 .data : AT (_sidata)
67 {
68 . = ALIGN(4);
69 /* This is used by the startup in order to initialize the .data secion */
70 _sdata = . ;
71
72 *(.data)
73 *(.data.*)
74 *(.gnu.linkonce.d*)
75
76 . = ALIGN(4);
77 /* This is used by the startup in order to initialize the .data secion */
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 /* This is used by the startup in order to initialize the .bss secion */
93 _sbss = .;
94
95 *(.bss)
96 *(.bss.*)
97 *(COMMON)
98
99 . = ALIGN(4);
100 /* This is used by the startup in order to initialize the .bss secion */
101 _ebss = . ;
102
103 *(.bss.init)
104 } > DATA
105 __bss_end = .;
106
107 _end = .;
108
109 /* Stabs debugging sections. */
110 .stab 0 : { *(.stab) }
111 .stabstr 0 : { *(.stabstr) }
112 .stab.excl 0 : { *(.stab.excl) }
113 .stab.exclstr 0 : { *(.stab.exclstr) }
114 .stab.index 0 : { *(.stab.index) }
115 .stab.indexstr 0 : { *(.stab.indexstr) }
116 .comment 0 : { *(.comment) }
117 /* DWARF debug sections.
118 * Symbols in the DWARF debugging sections are relative to the beginning
119 * of the section so we begin them at 0. */
120 /* DWARF 1 */
121 .debug 0 : { *(.debug) }
122 .line 0 : { *(.line) }
123 /* GNU DWARF 1 extensions */
124 .debug_srcinfo 0 : { *(.debug_srcinfo) }
125 .debug_sfnames 0 : { *(.debug_sfnames) }
126 /* DWARF 1.1 and DWARF 2 */
127 .debug_aranges 0 : { *(.debug_aranges) }
128 .debug_pubnames 0 : { *(.debug_pubnames) }
129 /* DWARF 2 */
130 .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }
131 .debug_abbrev 0 : { *(.debug_abbrev) }
132 .debug_line 0 : { *(.debug_line) }
133 .debug_frame 0 : { *(.debug_frame) }
134 .debug_str 0 : { *(.debug_str) }
135 .debug_loc 0 : { *(.debug_loc) }
136 .debug_macinfo 0 : { *(.debug_macinfo) }
137 /* SGI/MIPS DWARF 2 extensions */
138 .debug_weaknames 0 : { *(.debug_weaknames) }
139 .debug_funcnames 0 : { *(.debug_funcnames) }
140 .debug_typenames 0 : { *(.debug_typenames) }
141 .debug_varnames 0 : { *(.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-Loading Description File generated by uVision ***
3; *************************************************************
4
5LR_IROM1 0x08000000 0x00080000 { ; load region size_region
6 ER_IROM1 0x08000000 0x00080000 { ; load address = execution address
7 *.o (RESET, +First)
8 *(InRoot$$Sections)
9 .ANY (+RO)
10 }
11 RW_IRAM1 0x20000000 0x00010000 { ; RW data
12 .ANY (+RW +ZI)
13 }
14}
(4) 修改
E:RT_ThreadGD32_BSPrt_thread_codebspgd32f103gd32f103vet6board/board.h文件
修改后内容如下:
1/*
2 * Copyright (c) 2006-2021, RT-Thread Development Team
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 *
6 * Change Logs:
7 * Date Author Notes
8 * 2021-12-18 BruceOu first implementation
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#define EXT_SDRAM_BEGIN (0xC0000000U) /* the begining address of external SDRAM */
20#define EXT_SDRAM_END (EXT_SDRAM_BEGIN + (32U * 1024 * 1024)) /* the end address of external SDRAM */
21
22// Internal SRAM memory size[Kbytes] <8-48>
23// Default: 48
24#ifdef __ICCARM__
25// Use *.icf ram symbal, to avoid hardcode.
26extern char __ICFEDIT_region_RAM_end__;
27#define GD32_SRAM_END &__ICFEDIT_region_RAM_end__
28#else
29#define GD32_SRAM_SIZE 64
30#define GD32_SRAM_END (0x20000000 + GD32_SRAM_SIZE * 1024)
31#endif
32
33#ifdef __CC_ARM
34extern int Image$$RW_IRAM1$$ZI$$Limit;
35#define HEAP_BEGIN (&Image$$RW_IRAM1$$ZI$$Limit)
36#elif __ICCARM__
37#pragma section="HEAP"
38#define HEAP_BEGIN (__segment_end("HEAP"))
39#else
40extern int __bss_end;
41#define HEAP_BEGIN (&__bss_end)
42#endif
43
44#define HEAP_END GD32_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-Thread Development Team
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 *
6 * Change Logs:
7 * Date Author Notes
8 * 2021-12-18 BruceOu first implementation
9 */
10#include
11#include
12#include
13#include
14
15/**
16 * @brief This function is executed in case of error occurrence.
17 * @param None
18 * @retval None
19 */
20void Error_Handler(void)
21{
22 /* USER CODE BEGIN Error_Handler */
23 /* User can add his own implementation to report the HAL error return state */
24 while (1)
25 {
26 }
27 /* USER CODE END Error_Handler */
28}
29
30/** System Clock Configuration
31*/
32void SystemClock_Config(void)
33{
34 SysTick_Config(SystemCoreClock / RT_TICK_PER_SECOND);
35 NVIC_SetPriority(SysTick_IRQn, 0);
36}
37
38/**
39 * This is the timer interrupt service routine.
40 *
41 */
42void SysTick_Handler(void)
43{
44 /* enter interrupt */
45 rt_interrupt_enter();
46
47 rt_tick_increase();
48
49 /* leave interrupt */
50 rt_interrupt_leave();
51}
52
53/**
54 * This function will initial GD32 board.
55 */
56void rt_hw_board_init()
57{
58 /* NVIC Configuration */
59#define NVIC_VTOR_MASK 0x3FFFFF80
60#ifdef VECT_TAB_RAM
61 /* Set the Vector Table base location at 0x10000000 */
62 SCB->VTOR = (0x10000000 & NVIC_VTOR_MASK);
63#else /* VECT_TAB_FLASH */
64 /* Set the Vector Table base location at 0x08000000 */
65 SCB->VTOR = (0x08000000 & NVIC_VTOR_MASK);
66#endif
67
68 SystemClock_Config();
69
70#ifdef RT_USING_COMPONENTS_INIT
71 rt_components_board_init();
72#endif
73
74#ifdef RT_USING_CONSOLE
75 rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
76#endif
77
78#ifdef BSP_USING_SDRAM
79 rt_system_heap_init((void *)EXT_SDRAM_BEGIN, (void *)EXT_SDRAM_END);
80#else
81 rt_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 "Hardware Drivers Config"
2
3config SOC_SERIES_GD32F10x
4 bool
5 default y
6
7config SOC_GD32103V
8 bool
9 select SOC_SERIES_GD32F10x
10 select RT_USING_COMPONENTS_INIT
11 select RT_USING_USER_MAIN
12 default y
13
14menu "Onboard Peripheral Drivers"
15
16endmenu
17
18menu "On-chip Peripheral Drivers"
19
20 config BSP_USING_GPIO
21 bool "Enable GPIO"
22 select RT_USING_PIN
23 default y
24
25 menuconfig BSP_USING_UART
26 bool "Enable UART"
27 default y
28 select RT_USING_SERIAL
29 if BSP_USING_UART
30 config BSP_USING_UART0
31 bool "Enable UART0"
32 default n
33
34 config BSP_UART0_RX_USING_DMA
35 bool "Enable UART0 RX DMA"
36 depends on BSP_USING_UART0
37 select RT_SERIAL_USING_DMA
38 default n
39
40 config BSP_USING_UART1
41 bool "Enable UART1"
42 default y
43
44 config BSP_UART1_RX_USING_DMA
45 bool "Enable UART1 RX DMA"
46 depends on BSP_USING_UART1
47 select RT_SERIAL_USING_DMA
48 default n
49
50 config BSP_USING_UART2
51 bool "Enable UART2"
52 default n
53
54 config BSP_UART2_RX_USING_DMA
55 bool "Enable UART2 RX DMA"
56 depends on BSP_USING_UART2
57 select RT_SERIAL_USING_DMA
58 default n
59
60 config BSP_USING_UART3
61 bool "Enable UART3"
62 default n
63
64 config BSP_UART3_RX_USING_DMA
65 bool "Enable UART3 RX DMA"
66 depends on BSP_USING_UART3
67 select RT_SERIAL_USING_DMA
68 default n
69
70 config BSP_USING_UART4
71 bool "Enable UART4"
72 default n
73
74 config BSP_UART4_RX_USING_DMA
75 bool "Enable UART4 RX DMA"
76 depends on BSP_USING_UART4
77 select RT_SERIAL_USING_DMA
78 default n
79 endif
80
81 menuconfig BSP_USING_SPI
82 bool "Enable SPI BUS"
83 default n
84 select RT_USING_SPI
85 if BSP_USING_SPI
86 config BSP_USING_SPI1
87 bool "Enable SPI1 BUS"
88 default n
89
90 config BSP_SPI1_TX_USING_DMA
91 bool "Enable SPI1 TX DMA"
92 depends on BSP_USING_SPI1
93 default n
94
95 config BSP_SPI1_RX_USING_DMA
96 bool "Enable SPI1 RX DMA"
97 depends on BSP_USING_SPI1
98 select BSP_SPI1_TX_USING_DMA
99 default n
100 endif
101
102 menuconfig BSP_USING_I2C1
103 bool "Enable I2C1 BUS (software simulation)"
104 default n
105 select RT_USING_I2C
106 select RT_USING_I2C_BITOPS
107 select RT_USING_PIN
108 if BSP_USING_I2C1
109 config BSP_I2C1_SCL_PIN
110 int "i2c1 scl pin number"
111 range 1 216
112 default 24
113 config BSP_I2C1_SDA_PIN
114 int "I2C1 sda pin number"
115 range 1 216
116 default 25
117 endif
118
119 config BSP_USING_WDT
120 bool "Enable Watchdog Timer"
121 select RT_USING_WDT
122 default n
123
124 config BSP_USING_RTC
125 bool "Enable Internal RTC"
126 select RT_USING_RTC
127 default n
128
129 menuconfig BSP_USING_HWTIMER
130 bool "Enable hwtimer"
131 default n
132 select RT_USING_HWTIMER
133 if BSP_USING_HWTIMER
134 config BSP_USING_HWTIMER0
135 bool "using hwtimer0"
136 default n
137 config BSP_USING_HWTIMER1
138 bool "using hwtimer1"
139 default n
140 config BSP_USING_HWTIMER2
141 bool "using hwtimer2"
142 default n
143 config BSP_USING_HWTIMER3
144 bool "using hwtimer3"
145 default n
146 config BSP_USING_HWTIMER4
147 bool "using hwtimer4"
148 default n
149 config BSP_USING_HWTIMER5
150 bool "using hwtimer5"
151 default n
152 config BSP_USING_HWTIMER6
153 bool "using hwtimer6"
154 default n
155 config BSP_USING_HWTIMER7
156 bool "using hwtimer7"
157 default n
158 endif
159
160 menuconfig BSP_USING_ADC
161 bool "Enable ADC"
162 default n
163 select RT_USING_ADC
164 if BSP_USING_ADC
165 config BSP_USING_ADC0
166 bool "using adc0"
167 default n
168 config BSP_USING_ADC1
169 bool "using adc1"
170 default n
171 endif
172 source "../libraries/gd32_drivers/Kconfig"
173
174endmenu
175
176menu "Board extended module Drivers"
177
178endmenu
179
180endmenu
这个文件就是配置板子驱动的,这里可根据实际需求添加。
(7) 修改
E:RT_ThreadGD32_BSPrt_thread_codebspgd32f103gd32f103vet6board/SConscript文件
修改后内容如下:
1import os
2import rtconfig
3from building import *
4
5Import('SDK_LIB')
6
7cwd = GetCurrentDir()
8
9# add general drivers
10src = Split('''
11board.c
12''')
13
14path = [cwd]
15
16startup_path_prefix = SDK_LIB
17
18if rtconfig.PLATFORM == 'gcc':
19 src += [startup_path_prefix + '/GD32F10x_Firmware_Library/CMSIS/GD/GD32F10x/Source/GCC/startup_gd32f10x_hd.s']
20elif rtconfig.PLATFORM in ['armcc', 'armclang']:
21 src += [startup_path_prefix + '/GD32F10x_Firmware_Library/CMSIS/GD/GD32F10x/Source/ARM/startup_gd32f10x_hd.s']
22elif rtconfig.CROSS_TOOL == 'iar':
23 src += [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# add general drivers
35src = Split('''
36board.c
37''')
38
39path = [cwd]
40
41startup_path_prefix = SDK_LIB
42
43if rtconfig.CROSS_TOOL == 'gcc':
44 src += [startup_path_prefix + '/GD32F4xx_HAL/CMSIS/GD/GD32F4xx/Source/GCC/startup_gd32f4xx.S']
45elif rtconfig.CROSS_TOOL == 'keil':
46 src += [startup_path_prefix + '/GD32F4xx_HAL/CMSIS/GD/GD32F4xx/Source/ARM/startup_gd32f4xx.s']
47elif rtconfig.CROSS_TOOL == 'iar':
48 src += [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配置
原文标题:【国产MCU移植】手把手教你使用RT-Thread制作GD32F103系列BSP
文章出处:【微信公众号:RTThread物联网操作系统】欢迎添加关注!文章转载请注明出处。
全部0条评论
快来发表一下你的评论吧 !