#申请原创#以STM32F407为例
使用RTthread-studio创建STM32F407的工程;
工程名为STM32F4,我选择的是串口1作为打印,DAPLink作为烧录口;
打开工程,构建工程;
编译完成无错误;
下载完成后成功打印!
接下来是转换成keil工程!
------------------------------------我是分割线-----------------------------------------------
首先需要创建一个keil工程,名字为template的工程
修改文件:
import os
# toolchains options
ARCH='arm'
CPU='cortex-m4'
CROSS_TOOL='keil'
# bsp lib config
BSP_LIBRARY_TYPE = None
# cross_tool provides the cross compiler
# EXEC_PATH is the compiler execute path, for example, CodeSourcery, Keil MDK, IAR
PLATFORM = 'armcc'
EXEC_PATH = r'KEIL的路径,根目录即可'
if os.getenv('RTT_EXEC_PATH'):
EXEC_PATH = os.getenv('RTT_EXEC_PATH')
BUILD = 'debug'
CC = 'armcc'
AS = 'armasm'
AR = 'armar'
LINK = 'armlink'
TARGET_EXT = 'axf'
DEVICE = ' --cpu Cortex-M4'
CFLAGS = DEVICE + ' --apcs=interwork'
AFLAGS = DEVICE
LFLAGS = DEVICE + ' --info sizes --info totals --info unused --info veneers --list rtthread.map --scatter "./linker_scripts/stm32_rom.sct"'
LFLAGS += ' --keep *.o(.rti_fn.*) --keep *.o(FSymTab) --keep *.o(VSymTab)'
EXEC_PATH += '/ARM/ARMCC/bin'
print(EXEC_PATH)
CFLAGS += ' --c99'
if BUILD == 'debug':
CFLAGS += ' -g -O0'
AFLAGS += ' -g'
else:
CFLAGS += ' -O2'
POST_ACTION = 'fromelf --bin $TARGET --output rtthread.bin \nfromelf -z $TARGET'
2.Sconstruct
import os
import sys
import rtconfig
RTT_ROOT = os.path.normpath(os.getcwd() + '/rt-thread')
sys.path = sys.path + [os.path.join(RTT_ROOT, 'tools')]
try:
from building import *
except Exception as e:
print("Error message:", e.message)
print('Cannot found RT-Thread root directory, please check RTT_ROOT')
print(RTT_ROOT)
sys.exit(-1)
TARGET = 'rt-thread.elf'
DefaultEnvironment(tools=[])
env = Environment(tools = ['mingw'],
AS = rtconfig.AS, ASFLAGS = rtconfig.AFLAGS,
CC = rtconfig.CC, CCFLAGS = rtconfig.CFLAGS,
AR = rtconfig.AR, ARFLAGS = '-rc',
LINK = rtconfig.LINK, LINKFLAGS = rtconfig.LFLAGS)
env.PrependENVPath('PATH', rtconfig.EXEC_PATH)
env.AppendUnique(CPPDEFINES = [])
Export('RTT_ROOT')
Export('rtconfig')
# prepare building environment
objs = PrepareBuilding(env, RTT_ROOT, has_libcpu=False)
# make a building
DoBuilding(TARGET, objs)
然后使用RTthread的ComEmu功能生成KEIL工程,输入命令scons --target=mdk5
然而我们打开的工程不全
需要添加几个脚本,以下是工程目录
1.在applications添加SConscript脚本
from building import *
Import('rtconfig')
cwd = GetCurrentDir()
src = Glob('*.c')
PATH = [cwd]
CPPDEFINES = ['RT_USING_ARM_LIBC','SOC_FAMILY_STM32','SOC_SERIES_STM32F4','STM32F407xx','USE_HAL_DRIVER','HAL_IWDG_MODULE_ENABLED','HAL_ADC_MODULE_ENABLED']
if rtconfig.PLATFORM == 'armcc' or rtconfig.PLATFORM == 'armclang':
group = DefineGroup('Applications', src, depend = [''], CPPPATH = PATH,CPPDEFINES = CPPDEFINES)
Return('group')
第一、二行加载rtconfig文件
第三行获取当前路径
第四行获取当前路径.c文件
第五行添加宏定义
第六行确定编译器版本
第七行在KEIL上添加Applications组,添加的路径为PATH,添加宏定义为CPPDEFINES,返回group。
我们在使用env功能scons --target=mdk5重新生成看效果,并且自动添加路径在库配置里面。
以此类推,所需要添加的文件的文件夹内都添加该脚本;
重新使用scons --target=mdk5生成keil工程
编译时有个报错
Undefined symbol Image$RW_IRAM1$ZI$Limit (referred from board.c)
该问题是因为rt-thread studio和keil环境不一致导致,将Image$RW_IRAM1$ZI$Limit内的$符号改为2个$即可
Image$$RW_IRAM1$$ZI$$Limit
编译成功并下载完成
以上即是rt-thread工程生成keil工程的全部过程
|