文件目录

拷贝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,
修改芯片型号,配置系统时钟,配置外设引脚(仅串口外设)
image.png
image.png
image.png
image.png
image.png

生成代码后,E:\Function_LIB\RTT_WORK\rt-thread\bsp\stm32\stm32f103_Fire_MINI\board\CubeMX_Config路径下可仅保留这四个文件
image.png

SystemClock

将E:\Function_LIB\RTT_WORK\rt-thread\bsp\stm32\stm32f103_Fire_MINI\board\CubeMX_Config\Src中的main.c的时钟函数

  1. void SystemClock_Config(void)
  2. {
  3. ...
  4. }

拷贝到E:\Function_LIB\RTT_WORK\rt-thread\bsp\stm32\stm32f103_Fire_MINI\board中的board.c中

board

在board.h中修改芯片flash和ram大小(256k和48k)

  1. #define STM32_FLASH_START_ADRESS ((uint32_t)0x08000000)
  2. #define STM32_FLASH_SIZE (256 * 1024)
  3. #define STM32_FLASH_END_ADDRESS ((uint32_t)(STM32_FLASH_START_ADRESS + STM32_FLASH_SIZE))
  4. /* Internal SRAM memory size[Kbytes] <8-64>, Default: 64*/
  5. #define STM32_SRAM_SIZE 48
  6. #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

修改对应芯片型号

  1. config SOC_STM32F103RC
  2. bool
  3. select SOC_SERIES_STM32F1
  4. select RT_USING_COMPONENTS_INIT
  5. select RT_USING_USER_MAIN
  6. default y

添加板载外设USB转串口选项

  1. menu "Onboard Peripheral Drivers"
  2. config BSP_USING_USB_TO_USART
  3. bool "Enable USB TO USART (uart1)"
  4. select BSP_USING_UART1
  5. default y
  6. endmenu

添加片上GPIO和串口驱动选项

  1. menu "On-chip Peripheral Drivers"
  2. config BSP_USING_GPIO
  3. bool "Enable GPIO"
  4. select RT_USING_PIN
  5. default y
  6. config BSP_USING_UART1
  7. bool "Enable UART1"
  8. select RT_USING_SERIAL
  9. default y
  10. endmenu

link

修改E:\Function_LIB\RTT_WORK\rt-thread\bsp\stm32\stm32f103_Fire_MINI\board\linker_scripts下的link文件

link.sct

  1. ; *************************************************************
  2. ; *** Scatter-Loading Description File generated by uVision ***
  3. ; *************************************************************
  4. LR_IROM1 0x08000000 0x00040000 { ; load region size_region
  5. ER_IROM1 0x08000000 0x00040000 { ; load address = execution address
  6. *.o (RESET, +First)
  7. *(InRoot$$Sections)
  8. .ANY (+RO)
  9. }
  10. RW_IRAM1 0x20000000 0x0000C000 { ; RW data
  11. .ANY (+RW +ZI)
  12. }
  13. }

LR_IROM1和ER_IROM1后的第二个数字(0x00040000)为flash内存位数的16进制(2561024)
RW_IRAM1后的第二个数字(0x0000C000)为RAM内存位数的16进制(48
1024)

link.lds

  1. /*
  2. * linker script for STM32F10x with GNU ld
  3. */
  4. /* Program Entry, set to mark it as "used" and avoid gc */
  5. MEMORY
  6. {
  7. ROM (rx) : ORIGIN = 0x08000000, LENGTH = 256k /* 256KB flash */
  8. RAM (rw) : ORIGIN = 0x20000000, LENGTH = 48k /* 48K sram */
  9. }

link.icf

  1. /*###ICF### Section handled by ICF editor, don't touch! ****/
  2. /*-Editor annotation file-*/
  3. /* IcfEditorFile="$TOOLKIT_DIR$\config\ide\IcfEditor\cortex_v1_0.xml" */
  4. /*-Specials-*/
  5. define symbol __ICFEDIT_intvec_start__ = 0x08000000;
  6. /*-Memory Regions-*/
  7. define symbol __ICFEDIT_region_ROM_start__ = 0x08000000;
  8. define symbol __ICFEDIT_region_ROM_end__ = 0x0803FFFF;
  9. define symbol __ICFEDIT_region_RAM_start__ = 0x20000000;
  10. 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工程修改)

  1. if rtconfig.CROSS_TOOL == 'gcc':
  2. src += [startup_path_prefix + '/STM32F1xx_HAL/CMSIS/Device/ST/STM32F1xx/Source/Templates/gcc/startup_stm32f103xe.s']
  3. elif rtconfig.CROSS_TOOL == 'keil':
  4. src += [startup_path_prefix + '/STM32F1xx_HAL/CMSIS/Device/ST/STM32F1xx/Source/Templates/arm/startup_stm32f103xe.s']
  5. elif rtconfig.CROSS_TOOL == 'iar':
  6. src += [startup_path_prefix + '/STM32F1xx_HAL/CMSIS/Device/ST/STM32F1xx/Source/Templates/iar/startup_stm32f103xe.s']
  7. # STM32F100xB || STM32F100xE || STM32F101x6
  8. # STM32F101xB || STM32F101xE || STM32F101xG
  9. # STM32F102x6 || STM32F102xB || STM32F103x6
  10. # STM32F103xB || STM32F103xE || STM32F103xG
  11. # STM32F105xC || STM32F107xC)
  12. # You can select chips from the list above
  13. CPPDEFINES = ['STM32F103xE']

template

修改工程模板
image.png

选择芯片型号
image.png

修改默认下载方式
image.png

保存,退出

rtconfig

使用env重新生成rtconfig.h
env界面命令menuconfig,打开外设,保存

  1. menuconfig

env界面命令scons —target=mdk5重新生成工程

  1. scons --target=mdk5

Project

链接:https://pan.baidu.com/s/1iDZMdFCW6kL3dhnXp7rTGw
提取码:f7pb