文件目录
拷贝E:\Function_LIB\RTT_WORK\rt-thread\bsp\stm32\libraries\templates
下的stm32f10x文件夹(通用模板)
至E:\Function_LIB\RTT_WORK\rt-thread\bsp\stm32
与libraries同一级
修改stm32f10x文件夹名,自定义开发板命名stm32f103_Fire_MINI
注:路径rt-thread之前的可自定义,rt-thread之后的路径保持原有
Cube
E:\Function_LIB\RTT_WORK\rt-thread\bsp\stm32\stm32f103_Fire_MINI\board\CubeMX_Config
下运行cube程序CubeMX_Config.ioc,
修改芯片型号,配置系统时钟,配置外设引脚(仅串口外设)
生成代码后,E:\Function_LIB\RTT_WORK\rt-thread\bsp\stm32\stm32f103_Fire_MINI\board\CubeMX_Config路径下可仅保留这四个文件
SystemClock
将E:\Function_LIB\RTT_WORK\rt-thread\bsp\stm32\stm32f103_Fire_MINI\board\CubeMX_Config\Src中的main.c的时钟函数
void SystemClock_Config(void)
{
...
}
拷贝到E:\Function_LIB\RTT_WORK\rt-thread\bsp\stm32\stm32f103_Fire_MINI\board中的board.c中
board
在board.h中修改芯片flash和ram大小(256k和48k)
#define STM32_FLASH_START_ADRESS ((uint32_t)0x08000000)
#define STM32_FLASH_SIZE (256 * 1024)
#define STM32_FLASH_END_ADDRESS ((uint32_t)(STM32_FLASH_START_ADRESS + STM32_FLASH_SIZE))
/* Internal SRAM memory size[Kbytes] <8-64>, Default: 64*/
#define STM32_SRAM_SIZE 48
#define STM32_SRAM_END (0x20000000 + STM32_SRAM_SIZE * 1024)
注意:STM32F4芯片虽然RAM有192但是只有128可以用户使用,所以设置的内存大小必须是128,另外64是CCM仅CPU可以使用
Kconfig
修改E:\Function_LIB\RTT_WORK\rt-thread\bsp\stm32\stm32f103_Fire_MINI\board中的Kconfig
修改对应芯片型号
config SOC_STM32F103RC
bool
select SOC_SERIES_STM32F1
select RT_USING_COMPONENTS_INIT
select RT_USING_USER_MAIN
default y
添加板载外设USB转串口选项
menu "Onboard Peripheral Drivers"
config BSP_USING_USB_TO_USART
bool "Enable USB TO USART (uart1)"
select BSP_USING_UART1
default y
endmenu
添加片上GPIO和串口驱动选项
menu "On-chip Peripheral Drivers"
config BSP_USING_GPIO
bool "Enable GPIO"
select RT_USING_PIN
default y
config BSP_USING_UART1
bool "Enable UART1"
select RT_USING_SERIAL
default y
endmenu
link
修改E:\Function_LIB\RTT_WORK\rt-thread\bsp\stm32\stm32f103_Fire_MINI\board\linker_scripts下的link文件
link.sct
; *************************************************************
; *** Scatter-Loading Description File generated by uVision ***
; *************************************************************
LR_IROM1 0x08000000 0x00040000 { ; load region size_region
ER_IROM1 0x08000000 0x00040000 { ; load address = execution address
*.o (RESET, +First)
*(InRoot$$Sections)
.ANY (+RO)
}
RW_IRAM1 0x20000000 0x0000C000 { ; RW data
.ANY (+RW +ZI)
}
}
LR_IROM1和ER_IROM1后的第二个数字(0x00040000)为flash内存位数的16进制(2561024)
RW_IRAM1后的第二个数字(0x0000C000)为RAM内存位数的16进制(481024)
link.lds
/*
* linker script for STM32F10x with GNU ld
*/
/* Program Entry, set to mark it as "used" and avoid gc */
MEMORY
{
ROM (rx) : ORIGIN = 0x08000000, LENGTH = 256k /* 256KB flash */
RAM (rw) : ORIGIN = 0x20000000, LENGTH = 48k /* 48K sram */
}
link.icf
/*###ICF### Section handled by ICF editor, don't touch! ****/
/*-Editor annotation file-*/
/* IcfEditorFile="$TOOLKIT_DIR$\config\ide\IcfEditor\cortex_v1_0.xml" */
/*-Specials-*/
define symbol __ICFEDIT_intvec_start__ = 0x08000000;
/*-Memory Regions-*/
define symbol __ICFEDIT_region_ROM_start__ = 0x08000000;
define symbol __ICFEDIT_region_ROM_end__ = 0x0803FFFF;
define symbol __ICFEDIT_region_RAM_start__ = 0x20000000;
define symbol __ICFEDIT_region_RAM_end__ = 0x2000BFFF;
flash内存 = 0x08000000~0x0803FFFF = 256k
RAM内存 = 0x20000000~0x2000BFFF = 48k
SConscript
修改E:\Function_LIB\RTT_WORK\rt-thread\bsp\stm32\stm32f103_Fire_MINI\board中的SConscript文件
修改启动文件和芯片型号(根据cube生成的mdk工程修改)
if rtconfig.CROSS_TOOL == 'gcc':
src += [startup_path_prefix + '/STM32F1xx_HAL/CMSIS/Device/ST/STM32F1xx/Source/Templates/gcc/startup_stm32f103xe.s']
elif rtconfig.CROSS_TOOL == 'keil':
src += [startup_path_prefix + '/STM32F1xx_HAL/CMSIS/Device/ST/STM32F1xx/Source/Templates/arm/startup_stm32f103xe.s']
elif rtconfig.CROSS_TOOL == 'iar':
src += [startup_path_prefix + '/STM32F1xx_HAL/CMSIS/Device/ST/STM32F1xx/Source/Templates/iar/startup_stm32f103xe.s']
# STM32F100xB || STM32F100xE || STM32F101x6
# STM32F101xB || STM32F101xE || STM32F101xG
# STM32F102x6 || STM32F102xB || STM32F103x6
# STM32F103xB || STM32F103xE || STM32F103xG
# STM32F105xC || STM32F107xC)
# You can select chips from the list above
CPPDEFINES = ['STM32F103xE']
template
修改工程模板
选择芯片型号
修改默认下载方式
保存,退出
rtconfig
使用env重新生成rtconfig.h
env界面命令menuconfig,打开外设,保存
menuconfig
env界面命令scons —target=mdk5重新生成工程
scons --target=mdk5