Toggle navigation
首页
问答
文章
积分商城
专家
专区
更多专区...
文档中心
返回主站
搜索
提问
会员
中心
登录
注册
工具链
使用 LLVM-for-Arm 工具链编译 RT-Thread 源码
发布于 2021-12-21 09:51:45 浏览:2400
订阅该版
[tocm] # 使用 LLVM 编译 RT-Thread ## 硬件测试环境 pdd 不久前搞活动, 99 块买了两块阿里出的 L469 的开发板,最高主频为 80Mhz。所以本次测试硬件就使用该开发板进行测试。 ![board.png](https://oss-club.rt-thread.org/uploads/20211221/0af7c3fce1796ec9b2b89e1862ef3654.png.webp) ## 工具准备 1. 使用 git 工具下载 llvm 工具链: ````shell git clone https://github.com/ARM-software/LLVM-embedded-toolchain-for-Arm.git ```` 2. 下载 make 工具: ```shell git clone https://github.com/xpack-dev-tools/windows-build-tools-xpack.git ``` ## 编译 1. 在 `rt-thread\bsp\stm32\stm32l496-ali-developer` 目录下打开 env 工具: 2. 使用命令 `scons --target=cmake` 生成 CMakelists.txt 文件: 3. 这里的命令生成的 CMake 文件使用的是 gcc 的工具链,需要修改一下使用 llvm 的工具链: ```cmake SET(CMAKE_C_COMPILER "D:/download/idm/LLVMEmbeddedToolchainForArm-13.0.0-windows/LLVMEmbeddedToolchainForArm-13.0.0/bin/clang.exe") SET(CMAKE_ASM_COMPILER "D:/download/idm/LLVMEmbeddedToolchainForArm-13.0.0-windows/LLVMEmbeddedToolchainForArm-13.0.0/bin/clang.exe") SET(CMAKE_C_FLAGS "--config armv7em_hard_fpv4_sp_d16_nosys -Os") SET(CMAKE_ASM_FLAGS " -c --config armv7em_hard_fpv4_sp_d16_nosys -Wa,-mimplicit-it=thumb") SET(CMAKE_C_COMPILER_WORKS TRUE) SET(CMAKE_CXX_COMPILER "D:/download/idm/LLVMEmbeddedToolchainForArm-13.0.0-windows/LLVMEmbeddedToolchainForArm-13.0.0/bin/clang++.exe") SET(CMAKE_CXX_FLAGS "--config armv7em_hard_fpv4_sp_d16_nosys -Os") SET(CMAKE_CXX_COMPILER_WORKS TRUE) SET(CMAKE_OBJCOPY "D:/download/idm/LLVMEmbeddedToolchainForArm-13.0.0-windows/LLVMEmbeddedToolchainForArm-13.0.0/bin/llvm-objcopy.exe") SET(CMAKE_SIZE "D:/download/idm/LLVMEmbeddedToolchainForArm-13.0.0-windows/LLVMEmbeddedToolchainForArm-13.0.0/bin/llvm-size.exe") SET(CMAKE_EXE_LINKER_FLAGS "--config armv7em_hard_fpv4_sp_d16_nosys ,--gc-sections,-Map=rtthread.map,-u,Reset_Handler -T ${CMAKE_SOURCE_DIR}/board/linker_scripts/link.lds") ``` 4. 输入命令 `cd build & cmake -G "MinGW Makefiles" .. & D:\software\tools\xpack-windows-build-tools-2.12.2\bin\make.exe` 编译工程: ```shell LiuKang@DESKTOP-538H6DE D:\repo\github\rt-thread\bsp\stm32\stm32l496-ali-developer $ cd build LiuKang@DESKTOP-538H6DE D:\repo\github\rt-thread\bsp\stm32\stm32l496-ali-developer\build $ cmake -G "MinGW Makefiles" .. -- Configuring done -- Generating done -- Build files have been written to: D:/repo/github/rt-thread/bsp/stm32/stm32l496-ali-developer/build LiuKang@DESKTOP-538H6DE D:\repo\github\rt-thread\bsp\stm32\stm32l496-ali-developer\build $ D:\software\tools\xpack-windows-build-tools-2.12.2\bin\make.exe [ 1%] Building C object CMakeFiles/rtthread.elf.dir/applications/main.c.obj [ 2%] Building C object CMakeFiles/rtthread.elf.dir/packages/CoreMark-latest/core_main.c.obj [ 4%] Building C object CMakeFiles/rtthread.elf.dir/packages/CoreMark-latest/core_util.c.obj [ 5%] Building C object CMakeFiles/rtthread.elf.dir/packages/CoreMark-latest/core_portme.c.obj [ 7%] Building C object CMakeFiles/rtthread.elf.dir/packages/CoreMark-latest/core_list_join.c.obj [ 8%] Building C object CMakeFiles/rtthread.elf.dir/packages/CoreMark-latest/core_state.c.obj [ 10%] Building C object CMakeFiles/rtthread.elf.dir/packages/CoreMark-latest/core_matrix.c.obj [ 11%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/libcpu/arm/common/showmem.c.obj [ 13%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/libcpu/arm/common/div0.c.obj [ 14%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/libcpu/arm/common/backtrace.c.obj [ 15%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/libcpu/arm/cortex-m4/cpuport.c.obj [ 17%] Building ASM object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/libcpu/arm/cortex-m4/context_gcc.S.obj [ 18%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/components/drivers/misc/pin.c.obj [ 20%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/components/drivers/serial/serial.c.obj [ 21%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/components/drivers/src/dataqueue.c.obj [ 23%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/components/drivers/src/ringblk_buf.c.obj [ 24%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/components/drivers/src/ringbuffer.c.obj [ 26%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/components/drivers/src/waitqueue.c.obj [ 27%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/components/drivers/src/completion.c.obj [ 28%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/components/drivers/src/pipe.c.obj [ 30%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/components/drivers/src/workqueue.c.obj [ 31%] Building ASM object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/bsp/stm32/libraries/STM32L4xx_HAL/CMSIS/Device/ST/STM32L4xx/Source/Templates/gcc/startup_stm32l496xx.s.obj clang: warning: argument unused during compilation: '-D HAVE_CCONFIG_H' [-Wunused-command-line-argument] clang: warning: argument unused during compilation: '-D RT_USING_NEWLIB' [-Wunused-command-line-argument] clang: warning: argument unused during compilation: '-D STM32L496xx' [-Wunused-command-line-argument] clang: warning: argument unused during compilation: '-D USE_HAL_DRIVER' [-Wunused-command-line-argument] clang: warning: argument unused during compilation: '-D __RTTHREAD__' [-Wunused-command-line-argument] [ 33%] Building C object CMakeFiles/rtthread.elf.dir/board/CubeMX_Config/Src/stm32l4xx_hal_msp.c.obj [ 34%] Building C object CMakeFiles/rtthread.elf.dir/board/board.c.obj [ 36%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/bsp/stm32/libraries/HAL_Drivers/drv_gpio.c.obj [ 37%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/bsp/stm32/libraries/HAL_Drivers/drv_usart.c.obj [ 39%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/bsp/stm32/libraries/HAL_Drivers/drv_common.c.obj [ 40%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/components/finsh/shell.c.obj [ 42%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/components/finsh/msh.c.obj [ 43%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/components/finsh/cmd.c.obj [ 44%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/src/idle.c.obj [ 46%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/src/kservice.c.obj [ 47%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/src/scheduler.c.obj [ 49%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/src/irq.c.obj [ 50%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/src/timer.c.obj [ 52%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/src/mempool.c.obj [ 53%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/src/ipc.c.obj [ 55%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/src/device.c.obj [ 56%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/src/clock.c.obj [ 57%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/src/thread.c.obj [ 59%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/src/mem.c.obj [ 60%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/src/components.c.obj [ 62%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/src/object.c.obj [ 63%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/components/libc/compilers/common/stdlib.c.obj [ 65%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/components/libc/compilers/common/time.c.obj [ 66%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/components/libc/compilers/gcc/newlib/syscalls.c.obj [ 68%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/components/libc/compilers/gcc/newlib/libc_syms.c.obj [ 69%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/bsp/stm32/libraries/STM32L4xx_HAL/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_cryp.c.obj [ 71%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/bsp/stm32/libraries/STM32L4xx_HAL/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_uart.c.obj [ 72%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/bsp/stm32/libraries/STM32L4xx_HAL/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_usart.c.obj [ 73%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/bsp/stm32/libraries/STM32L4xx_HAL/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_cortex.c.obj [ 75%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/bsp/stm32/libraries/STM32L4xx_HAL/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_gpio.c.obj [ 76%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/bsp/stm32/libraries/STM32L4xx_HAL/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_dma.c.obj [ 78%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/bsp/stm32/libraries/STM32L4xx_HAL/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_pwr.c.obj [ 79%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/bsp/stm32/libraries/STM32L4xx_HAL/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_rcc_ex.c.obj [ 81%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/bsp/stm32/libraries/STM32L4xx_HAL/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_rcc.c.obj [ 82%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/bsp/stm32/libraries/STM32L4xx_HAL/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_dma_ex.c.obj [ 84%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/bsp/stm32/libraries/STM32L4xx_HAL/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_exti.c.obj [ 85%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/bsp/stm32/libraries/STM32L4xx_HAL/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_crc.c.obj [ 86%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/bsp/stm32/libraries/STM32L4xx_HAL/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal.c.obj [ 88%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/bsp/stm32/libraries/STM32L4xx_HAL/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_usart_ex.c.obj [ 89%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/bsp/stm32/libraries/STM32L4xx_HAL/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_uart_ex.c.obj [ 91%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/bsp/stm32/libraries/STM32L4xx_HAL/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_crc_ex.c.obj [ 92%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/bsp/stm32/libraries/STM32L4xx_HAL/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_comp.c.obj [ 94%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/bsp/stm32/libraries/STM32L4xx_HAL/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_pwr_ex.c.obj [ 95%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/bsp/stm32/libraries/STM32L4xx_HAL/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_rng.c.obj [ 97%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/bsp/stm32/libraries/STM32L4xx_HAL/CMSIS/Device/ST/STM32L4xx/Source/Templates/system_stm32l4xx.c.obj [ 98%] Building C object CMakeFiles/rtthread.elf.dir/D_/repo/github/rt-thread/bsp/stm32/libraries/STM32L4xx_HAL/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_cryp_ex.c.obj [100%] Linking C executable rtthread.elf clang: warning: argument unused during compilation: '-Wa,-mimplicit-it=thumb' [-Wunused-command-line-argument] text data bss dec hex filename 117152 2864 1844 121860 1dc04 rtthread.elf [100%] Built target rtthread.elf ``` 5. 下载 bin 文件到开发板: ![down.png](https://oss-club.rt-thread.org/uploads/20211221/5172c10d0a8582ea50d645726093fdc7.png.webp) 6. llvm 的编译下载就完成啦。 ## 跑分测试 使用 LLVM、GCC、IAR 三种工具链编译出来的可执行文件,测试一下跑分情况: ### GCC 5.4.1 优化等级:`-Os` ![gcc5.4.1.png](https://oss-club.rt-thread.org/uploads/20211221/6d5c77f12bf0d55be2e4711fe0f41620.png) ### GCC 10.3.1 优化等级:`-Os` ![gcc10.3.png](https://oss-club.rt-thread.org/uploads/20211221/9a5b0700d418394fab3081934aecef41.png) ### LLVM 优化等级:`-Os` ![llvm.png](https://oss-club.rt-thread.org/uploads/20211221/8c9324275d596dc6cce904ad63d09210.png.webp) ### IAR 优化等级: ![iar1.png](https://oss-club.rt-thread.org/uploads/20211221/684ae12681d616997de790fc80056005.png) IAR 跑分情况 ![iar.png](https://oss-club.rt-thread.org/uploads/20211221/35fb3cc74ec68ef874c2fe103c540600.png) ### MDK 优化等级: ![mdk1.png](https://oss-club.rt-thread.org/uploads/20211221/dda65e807f22822b9cc5e1a5c44f1949.png) MDK AC6 跑分情况 ![mdk.png](https://oss-club.rt-thread.org/uploads/20211221/88509524a8bdbd201ec6b63738ac9e99.png) ### 跑分排名 IAR (199.94) > MDK AC6 (160.74) > LLVM (159.24) > GCC 5.4.1 (143.1.8) > GCC 10.3.1 (136.48)
11
条评论
默认排序
按发布时间排序
登录
注册新账号
关于作者
Papalymo
请勿打扰
文章
25
回答
85
被采纳
17
关注TA
发私信
相关文章
1
qemu-vexpress-a9 编译环境
2
D1s M7工具链求寻
3
如何在env工具中添加其他编译工具链
4
请问各位大佬,这是工具链出问题了吗,我环境配了还几天了,还是一支不对,有没有大佬帮忙看看,帮忙配配环境啊
5
请问qemu里不同版本RT-Thead对应的工具链版本应该怎么确定?
6
编译时出现错误提示,请问需要安装什么工具链
7
rtt studio 切换工具链后再回到 ARM Cross GCC工具链,不能正常生成bin文件和显示固件大小
推荐文章
1
RT-Thread应用项目汇总
2
玩转RT-Thread系列教程
3
国产MCU移植系列教程汇总,欢迎查看!
4
机器人操作系统 (ROS2) 和 RT-Thread 通信
5
五分钟玩转RT-Thread新社区
6
【技术三千问】之《玩转ART-Pi》,看这篇就够了!干货汇总
7
关于STM32H7开发板上使用SDIO接口驱动SD卡挂载文件系统的问题总结
8
STM32的“GPU”——DMA2D实例详解
9
RT-Thread隐藏的宝藏之completion
10
【ART-PI】RT-Thread 开启RTC 与 Alarm组件
热门标签
RT-Thread Studio
串口
Env
LWIP
SPI
AT
Bootloader
Hardfault
CAN总线
FinSH
ART-Pi
USB
DMA
文件系统
RT-Thread
SCons
RT-Thread Nano
线程
MQTT
STM32
RTC
FAL
rt-smart
ESP8266
I2C_IIC
UART
WIZnet_W5500
ota在线升级
freemodbus
PWM
flash
cubemx
packages_软件包
BSP
潘多拉开发板_Pandora
定时器
ADC
flashDB
GD32
socket
中断
编译报错
Debug
SFUD
rt_mq_消息队列_msg_queue
msh
keil_MDK
ulog
C++_cpp
MicroPython
本月问答贡献
a1012112796
10
个答案
1
次被采纳
踩姑娘的小蘑菇
4
个答案
1
次被采纳
红枫
4
个答案
1
次被采纳
张世争
4
个答案
1
次被采纳
Ryan_CW
4
个答案
1
次被采纳
本月文章贡献
catcatbing
3
篇文章
5
次点赞
YZRD
2
篇文章
4
次点赞
qq1078249029
2
篇文章
2
次点赞
xnosky
2
篇文章
1
次点赞
Woshizhapuren
1
篇文章
5
次点赞
回到
顶部
发布
问题
投诉
建议
回到
底部