ARMCLANG +CMAKE 编译STM32问题(2)

1.报错汇总

armlink 添加--library_type 后报错 Error: L6218E: Undefined symbol __use_two_region_memory (referred from startup_stm32l011xx.o).

armlink Error: L6218E: Undefined symbol __use_two_region_memory

armclang: warning: -Wl,--library_type=microlib: 'linker' input unused

2 解决问题

工程芯空间限制,需要使用Mircolib , 在ARM 开发文档中,描述了如何添加

armlink.exe 描述

CMakelists添加上述选项 后,编译直接报错:

Error: L6218E: Undefined symbol __use_two_region_memory (referred from startup_stm32l011xx.o).
Error: L6218E: Undefined symbol __initial_sp (referred from entry2.o).
Not enough information to list image symbols.
Not enough information to list load addresses in the image map.
Finished: 2 information, 0 warning and 2 error messages.
ninja: build stopped: subcommand failed.

显然根据文档描述来进行编译选项添加是不行的,说明该语法通过CMAKE 后生成的指令无法识别。

还是得回到MDK上来进行对比,找出KEIL的编译选项

#C/C++
-xc -std=c99 --target=arm-arm-none-eabi -mcpu=cortex-m0plus -c
-fno-rtti -funsigned-char -fshort-enums -fshort-wchar
-D__MICROLIB -gdwarf-3 -Oz -ffunction-sections -Wno-packed -Wno-missing-variable-declarations -Wno-missing-prototypes -Wno-missing-noreturn -Wno-sign-conversion -Wno-nonportable-include-path -Wno-reserved-id-macro -Wno-unused-macros -Wno-documentation-unknown-command -Wno-documentation -Wno-license-management -Wno-parentheses-equality -I ../Inc -I ../Drivers/STM32L0xx_HAL_Driver/Inc -I ../Drivers/STM32L0xx_HAL_Driver/Inc/Legacy -I ../Drivers/CMSIS/Device/ST/STM32L0xx/Include -I ../Drivers/CMSIS/Include
-I./RTE/_RAB060_CMAKE
-I"D:/Program/KEIL MDK/ARM/PACK/ARM/CMSIS/5.5.1/CMSIS/Core/Include"
-I"D:/Program/KEIL MDK/ARM/PACK/Keil/STM32L0xx_DFP/2.3.0/Drivers/CMSIS/Device/ST/STM32L0xx/Include"
-D__UVISION_VERSION="528" -D_RTE_ -DSTM32L011xx -DUSE_HAL_DRIVER -DSTM32L011xx
-o ./RAB060_CMAKE/*.o -MD


#ASM
--cpu Cortex-M0+ -g --pd "__MICROLIB SETA 1"
-I.\RTE\_RAB060_CMAKE
-I"D:\Program\KEIL MDK\ARM\PACK\ARM\CMSIS\5.5.1\CMSIS\Core\Include"
-I"D:\Program\KEIL MDK\ARM\PACK\Keil\STM32L0xx_DFP\2.3.0\Drivers\CMSIS\Device\ST\STM32L0xx\Include"
--pd "__UVISION_VERSION SETA 528"
--pd "_RTE_ SETA 1"
--pd "STM32L011xx SETA 1"
--list *.lst
--xref -o .\RAB060_CMAKE\*.o
--depend .\RAB060_CMAKE\*.d

#LINKER
--cpu Cortex-M0+ *.o
--library_type=microlib --strict --scatter ".\RAB060_CMAKE\RAB060_CMAKE.sct"
--summary_stderr --info summarysizes --map --load_addr_map_info --xref --callgraph --symbols
--info sizes --info totals --info unused --info veneers
--list "RAB060_CMAKE.map"
-o .\RAB060_CMAKE\RAB060_CMAKE.axf

好家伙,一看就发现这个microlib 添加指令除了armlink.exe 的一致,其余都不一样

ARMCLANG: -D__MICROLI

ARMASM: --pd "__UVISION_VERSION SETA 528"

add_compile_options(-D__MICROLIB)
add_link_options(--library_type=microlib)

编译成功,无报错,无警告。

最后来看下编译后大小对比,节省了608byte,要知道我这芯片总共大小也才2KB,节省了不少空间。

未启用microlib 
Program Size: Code=9102 RO-data=258 RW-data=12 ZI-data=1996  
启用后microlib 
Program Size: Code=8314 RO-data=258 RW-data=12 ZI-data=1388  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值