From a5f6fdc780d55f2bf2a1624815879e15c51082b5 Mon Sep 17 00:00:00 2001 From: guozhanxin Date: Wed, 22 Dec 2021 00:39:08 +0800 Subject: [PATCH] add clang-arm support. --- .../stm32l496-ali-developer/board/SConscript | 2 +- bsp/stm32/stm32l496-ali-developer/rtconfig.py | 35 +++++++++++++++++++ components/drivers/spi/SConscript | 2 +- .../libc/compilers/common/nogcc/SConscript | 2 +- .../libc/compilers/gcc/newlib/SConscript | 2 +- libcpu/arm/cortex-m4/SConscript | 2 +- tools/building.py | 2 +- 7 files changed, 41 insertions(+), 6 deletions(-) diff --git a/bsp/stm32/stm32l496-ali-developer/board/SConscript b/bsp/stm32/stm32l496-ali-developer/board/SConscript index 4c26186b46..9298652b29 100644 --- a/bsp/stm32/stm32l496-ali-developer/board/SConscript +++ b/bsp/stm32/stm32l496-ali-developer/board/SConscript @@ -24,7 +24,7 @@ path += [cwd + '/ports'] startup_path_prefix = SDK_LIB -if rtconfig.CROSS_TOOL == 'gcc': +if rtconfig.CROSS_TOOL == 'gcc' or rtconfig.CROSS_TOOL == 'clang': src += [startup_path_prefix + '/STM32L4xx_HAL/CMSIS/Device/ST/STM32L4xx/Source/Templates/gcc/startup_stm32l496xx.s'] elif rtconfig.CROSS_TOOL == 'keil': src += [startup_path_prefix + '/STM32L4xx_HAL/CMSIS/Device/ST/STM32L4xx/Source/Templates/arm/startup_stm32l496xx.s'] diff --git a/bsp/stm32/stm32l496-ali-developer/rtconfig.py b/bsp/stm32/stm32l496-ali-developer/rtconfig.py index b6c0783af5..439b79a3c3 100644 --- a/bsp/stm32/stm32l496-ali-developer/rtconfig.py +++ b/bsp/stm32/stm32l496-ali-developer/rtconfig.py @@ -24,6 +24,9 @@ elif CROSS_TOOL == 'keil': elif CROSS_TOOL == 'iar': PLATFORM = 'iar' EXEC_PATH = r'C:/Program Files (x86)/IAR Systems/Embedded Workbench 8.0' +elif CROSS_TOOL == 'clang': + PLATFORM = 'clang' + EXEC_PATH = r'D:\envs\LLVMEmbeddedToolchainForArm-13.0.0\bin' if os.getenv('RTT_EXEC_PATH'): EXEC_PATH = os.getenv('RTT_EXEC_PATH') @@ -176,6 +179,38 @@ elif PLATFORM == 'iar': EXEC_PATH = EXEC_PATH + '/arm/bin/' POST_ACTION = 'ielftool --bin $TARGET rtthread.bin' +elif PLATFORM == 'clang': + # toolchains + PREFIX = 'llvm-' + CC = 'clang' + AS = 'clang' + AR = PREFIX + 'ar' + CXX = 'clang++' + LINK = 'clang' + TARGET_EXT = 'elf' + SIZE = PREFIX + 'size' + OBJDUMP = PREFIX + 'objdump' + OBJCPY = PREFIX + 'objcopy' + + DEVICE = ' --config armv7em_hard_fpv4_sp_d16_nosys' + CFLAGS = DEVICE + AFLAGS = ' -c' + DEVICE + ' -Wa,-mimplicit-it=thumb ' ## -x assembler-with-cpp + LFLAGS = DEVICE + ' -Wl,--gc-sections,-Map=rt-thread.map,-u,Reset_Handler -T board/linker_scripts/link.lds' + + CPATH = '' + LPATH = '' + + if BUILD == 'debug': + CFLAGS += ' -O0 -gdwarf-2 -g' + AFLAGS += ' -gdwarf-2' + else: + CFLAGS += ' -O2' + + CXXFLAGS = CFLAGS + + POST_ACTION = OBJCPY + ' -O binary $TARGET rtthread.bin\n' + SIZE + ' $TARGET \n' + + def dist_handle(BSP_ROOT, dist_dir): import sys cwd_path = os.getcwd() diff --git a/components/drivers/spi/SConscript b/components/drivers/spi/SConscript index d6cb93f7f1..da14ed5fef 100644 --- a/components/drivers/spi/SConscript +++ b/components/drivers/spi/SConscript @@ -25,7 +25,7 @@ if GetDepend('RT_USING_SFUD'): CPPPATH += [cwd + '/sfud/inc'] if GetDepend('RT_SFUD_USING_SFDP'): src_device += ['sfud/src/sfud_sfdp.c'] - if rtconfig.CROSS_TOOL == 'gcc': + if rtconfig.CROSS_TOOL == 'gcc' or rtconfig.CROSS_TOOL == 'clang': LOCAL_CCFLAGS += ' -std=c99' elif rtconfig.CROSS_TOOL == 'keil': if rtconfig.PLATFORM == 'armcc': diff --git a/components/libc/compilers/common/nogcc/SConscript b/components/libc/compilers/common/nogcc/SConscript index c766c8f82d..b144f1b3b4 100644 --- a/components/libc/compilers/common/nogcc/SConscript +++ b/components/libc/compilers/common/nogcc/SConscript @@ -10,6 +10,6 @@ group = [] if GetDepend('RT_USING_LIBC'): src += Glob('*.c') -if rtconfig.PLATFORM != 'gcc' or rtconfig.ARCH == 'sim': +if (rtconfig.PLATFORM != 'gcc' and rtconfig.PLATFORM != 'clang') or rtconfig.ARCH == 'sim': group = DefineGroup('libc', src, depend = [], CPPPATH = CPPPATH) Return('group') diff --git a/components/libc/compilers/gcc/newlib/SConscript b/components/libc/compilers/gcc/newlib/SConscript index 58672a0255..7ab0dd046b 100644 --- a/components/libc/compilers/gcc/newlib/SConscript +++ b/components/libc/compilers/gcc/newlib/SConscript @@ -7,7 +7,7 @@ group = [] LIBS = ['m'] # link libm CPPPATH = [cwd] -if rtconfig.PLATFORM == 'gcc': +if rtconfig.PLATFORM == 'gcc' or rtconfig.PLATFORM == 'clang': if GetDepend('RT_USING_LIBC'): LIBS += ['c'] # link libc src += Glob('*.c') diff --git a/libcpu/arm/cortex-m4/SConscript b/libcpu/arm/cortex-m4/SConscript index 75f0d9a7cc..fd80cd2a68 100644 --- a/libcpu/arm/cortex-m4/SConscript +++ b/libcpu/arm/cortex-m4/SConscript @@ -14,7 +14,7 @@ if rtconfig.PLATFORM == 'armcc' or rtconfig.PLATFORM == 'armclang': if rtconfig.PLATFORM == 'armclang': src += Glob('*_rvds.S') -if rtconfig.PLATFORM == 'gcc': +if rtconfig.PLATFORM == 'gcc' or rtconfig.PLATFORM == 'clang': src += Glob('*_init.S') src += Glob('*_gcc.S') diff --git a/tools/building.py b/tools/building.py index 10641c11a9..52212bac9a 100644 --- a/tools/building.py +++ b/tools/building.py @@ -121,7 +121,7 @@ class Win32Spawn: def GenCconfigFile(env, BuildOptions): import rtconfig - if rtconfig.PLATFORM == 'gcc': + if rtconfig.PLATFORM == 'gcc' or rtconfig.PLATFORM == 'clang': contents = '' if not os.path.isfile('cconfig.h'): import gcc