MCU:STM32F407
環(huán)境:VSCode + PlatformIO IDE + STM32CubeF4(v1.5.2)
編譯器:7.2.1 20170904 (release) [ARM/embedded-7-branch revision 255204]
PlatformIO Core: version 5.1.1
STM32F4 Core Feature Description
問題描述
由于用的是STM32F4平臺,在ST產(chǎn)品線中定位為高性能計算產(chǎn)品,帶有FPU和DSP指令集,這不用來做數(shù)字信號處理屬實浪費,剛好近期工作需求要用到FFT或者FIR,所以,萬事俱備,開搞!!
1. DSP庫在哪?文檔?
看了一下PlatformIO自帶的STM32CubeF4庫,為了節(jié)約服務(wù)器帶寬和用戶下載時間,所以包很精簡,可是...這用起來很不方便呀,沒有文檔怎么寫代碼?
image.png
于是去官網(wǎng)下了一個標準版本,1.6.1最新版,帶了文檔。然而后來才發(fā)現(xiàn),原來CMSIS文檔是有在線版的:>>> CMSIS DSP Software Library <<<
官網(wǎng):STMicroelectronics/STM32CubeF4: STM32Cube MCU Full Package for the STM32F4 series - Github
CMSIS文檔
2. 編譯Demo
按理說三分鐘出demo的事,結(jié)果一開始情況就不太妙...首先找到自帶例程(為了要例程還是得下完整庫)。拿一個FIR的例子開刀:
image.png
復(fù)制進自己的項目,該函數(shù)名,燒錄運行?運行效果:
image.png
image.png
!!直接復(fù)制進來用會 遇到成噸報錯轟炸!!
觀察日志會發(fā)現(xiàn)基本全是CMSIS庫中的變量缺失錯誤,以及類型缺失錯誤。定位錯誤可以發(fā)現(xiàn):
image.png
3. arm_math.h:932:41: error: redefinition of '__SMLALD' 但依然會有類似這種錯誤: C:UsersJOY.platformiopackagesframework-stm32cubef4DriversCMSISInclude/cmsis_gcc.h:1652:31: note: previous definition of '__SHADD16' was here 1652 | __STATIC_FORCEINLINE uint32_t __SHADD16(uint32_t op1, uint32_t op2) | ^~~~~~~~~In file included from libarm_fir_example_f32math_helper.h:45, from libarm_fir_example_f32arm_fir_example_f32.c:125:C:UsersJOY.platformiopackagesframework-stm32cubef4DriversCMSISDSPInclude/arm_math.h:932:41: error: redefinition of '__SMLALD' 932 | CMSIS_INLINE __STATIC_INLINE uint64_t __SMLALD( | ^~~~~~~~In file included from C:UsersJOY.platformiopackagesframework-stm32cubef4DriversCMSISInclude/cmsis_compiler.h:48, from C:UsersJOY.platformiopackagesframework-stm32cubef4DriversCMSISInclude/core_cm4.h:162, from C:UsersJOY.platformiopackagesframework-stm32cubef4DriversCMSISDeviceSTSTM32F4xxInclude/stm32f407xx.h:167, from C:UsersJOY.platformiopackagesframework-stm32cubef4DriversCMSISDeviceSTSTM32F4xxInclude/stm32f4xx.h:133, from C:UsersJOY.platformiopackagesframework-stm32cubef4DriversSTM32F4xx_HAL_DriverInc/stm32f4xx_hal_def.h:30, from C:UsersJOY.platformiopackagesframework-stm32cubef4DriversSTM32F4xx_HAL_DriverInc/stm32f4xx_hal_rcc.h:29, from C:UsersJOY.platformiopackagesframework-stm32cubef4DriversSTM32F4xx_HAL_DriverInc/stm32f4xx_hal_conf.h:281, from C:UsersJOY.platformiopackagesframework-stm32cubef4DriversSTM32F4xx_HAL_DriverInc/stm32f4xx_hal.h:30, from libarm_fir_example_f32math_helper.h:44, from libarm_fir_example_f32arm_fir_example_f32.c:125: 繼續(xù)定位,發(fā)現(xiàn)缺失的變量在cmsis_iccarm.h文件有定義: 根據(jù)導(dǎo)入鏈,查看arm_math.h文件,發(fā)現(xiàn)里面有這樣一行宏定義,在VSCode中顯示為灰色: #if defined(ARM_MATH_CM7) #include 'core_cm7.h' #define ARM_MATH_DSP#elif defined (ARM_MATH_CM4) #include 'core_cm4.h' #define ARM_MATH_DSP 這個解決辦法就很明確了,直接在頂層include 文件添加一個宏定義,對應(yīng)到自己的MCU平臺即可。由于STM32F4系列對應(yīng)于Cortex-M4架構(gòu),所以這里定義一個ARM_MATH_CM4。 math_helper.h頭部: #define ARM_MATH_CM4#include 編譯: 4. arm_fir_example_f32.c:202: undefined reference to `arm_fir_f32' Archiving .piobuildblack_f407zgliba89libarm_fir_example_f32.aArchiving .piobuildblack_f407zglibFrameworkCMSISDevice.aLinking .piobuildblack_f407zgfirmware.elf c:/users/joy/.platformio/packages/toolchain-gccarmnoneeabi@2.00000.0/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/bin/ld.exe: .piobuildblack_f407zgliba89libarm_fir_example_f32.a(arm_fir_example_f32.o): in function `fir_test':C:DocumentsPlatformIOProjectsSTM32F4_ADC_Sampling_v2/libarm_fir_example_f32/arm_fir_example_f32.c:194: undefined reference to `arm_fir_init_f32' c:/users/joy/.platformio/packages/toolchain-gccarmnoneeabi@2.00000.0/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/bin/ld.exe: C:DocumentsPlatformIOProjectsSTM32F4_ADC_Sampling_v2/libarm_fir_example_f32/arm_fir_example_f32.c:202: undefined reference to `arm_fir_f32' collect2.exe: error: ld returned 1 exit status*** [.piobuildblack_f407zgfirmware.elf] Error 1 經(jīng)典的符號未定義問題,而且是在link階段出現(xiàn)的,說明DSP庫沒有正確鏈接上。也就是說這個庫對于編譯器來說是不知道在哪個位置的,需要自己添加上。 定位庫文件: 用的GCC編譯器,進去發(fā)現(xiàn)問題來了,選哪個呢? 搜索了解后知道,l是指little endian,f是指帶有硬件除法器,那么沒有疑問,用帶lf的那個,也就是libarm_cortexM4lf_math.a。 5. 導(dǎo)入DSP靜態(tài)庫 問題又來了,怎么導(dǎo)入到PIO呢? 打開platformio.ini文件,在環(huán)境中添加一行: build_flags = -LC:UsersJOY.platformiopackagesframework-stm32cubef4DriversCMSISLibGCC -larm_cortexM4lf_math 第N次編譯,結(jié)果: c:/users/joy/.platformio/packages/toolchain-gccarmnoneeabi@2.00000.0/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/bin/ld.exe: error: C:UsersJOY.platformiopackagesframework-stm32cubef4DriversCMSISLibGCClibarm_cortexM4lf_math.a(arm_fir_init_q15.o) uses VFP register arguments, .piobuildblack_f407zgfirmware.elf does not c:/users/joy/.platformio/packages/toolchain-gccarmnoneeabi@2.00000.0/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/bin/ld.exe: failed to merge target specific data of file C:UsersJOY.platformiopackagesframework-stm32cubef4DriversCMSISLibGCClibarm_cortexM4lf_math.a(arm_fir_init_q15.o)c:/users/joy/.platformio/packages/toolchain-gccarmnoneeabi@2.00000.0/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/bin/ld.exe: error: C:UsersJOY.platformiopackagesframework-stm32cubef4DriversCMSISLibGCClibarm_cortexM4lf_math.a(arm_fir_init_f32.o) uses VFP register arguments, .piobuildblack_f407zgfirmware.elf does not c:/users/joy/.platformio/packages/toolchain-gccarmnoneeabi@2.00000.0/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/bin/ld.exe: failed to merge target specific data of file C:UsersJOY.platformiopackagesframework-stm32cubef4DriversCMSISLibGCClibarm_cortexM4lf_math.a(arm_fir_init_f32.o)c:/users/joy/.platformio/packages/toolchain-gccarmnoneeabi@2.00000.0/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/bin/ld.exe: error: C:UsersJOY.platformiopackagesframework-stm32cubef4DriversCMSISLibGCClibarm_cortexM4lf_math.a(arm_fir_f32.o) uses VFP register arguments, .piobuildblack_f407zgfirmware.elf does not c:/users/joy/.platformio/packages/toolchain-gccarmnoneeabi@2.00000.0/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/bin/ld.exe: failed to merge target specific data of file C:UsersJOY.platformiopackagesframework-stm32cubef4DriversCMSISLibGCClibarm_cortexM4lf_math.a(arm_fir_f32.o)collect2.exe: error: ld returned 1 exit status*** [.piobuildblack_f407zgfirmware.elf] Error 1 6. 啟用編譯器(MCU)浮點數(shù)擴展 這里理一下思路:我們要用F4的浮點數(shù)運算能力,但是浮點數(shù)運算需要用到VFP指令和寄存器,但是libarm_cortexM4lf_math.a使用了VFP寄存器,而.piobuildblack_f407zgfirmware.elf沒有使用.... 這個問題的解讀就是,生成一個可執(zhí)行文件elf時,其所有的中間對象*.o都要是同樣的編譯條件,至少對于VFP指令集的設(shè)置應(yīng)該是相同的。但是目前的ELF文件沒有啟用這個選項。 那么問題就簡單了,啟用一下不就可以了,而方式應(yīng)該就是通過對編譯器傳參,在platformIO中就對應(yīng)于,設(shè)置platformio.ini文件中的build_flags。 查過以上資料后,發(fā)現(xiàn)我應(yīng)該這么設(shè)置: [env:black_f407zg]build_type = debug platform = ststm32 board = black_f407zg framework = stm32cube upload_protocol = stlink debug_tool = stlink monitor_speed = 115200build_flags = -LC:UsersJOY.platformiopackagesframework-stm32cubef4DriversCMSISLibARM -larm_cortexM4lf_math -mthumb -mcpu=cortex-m4 -march=armv7e-m -mfloat-abi=hard -mfpu=fpv4-sp-d16 也就是添加一行5個flag -mthumb -mcpu=cortex-m4 -march=armv7e-m -mfloat-abi=hard -mfpu=fpv4-sp-d16 使用過后,編譯結(jié)果: c:/users/joy/.platformio/packages/toolchain-gccarmnoneeabi@2.00000.0/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/bin/ld.exe: failed to merge target specific data of file .piobuildblack_f407zgFrameworkHALDriverSrcstm32f4xx_ll_fsmc.o c:/users/joy/.platformio/packages/toolchain-gccarmnoneeabi@2.00000.0/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/bin/ld.exe: error: .piobuildblack_f407zgsrcsystem_stm32f4xx.o uses VFP register arguments, .piobuildblack_f407zgfirmware.elf does not c:/users/joy/.platformio/packages/toolchain-gccarmnoneeabi@2.00000.0/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/bin/ld.exe: failed to merge target specific data of file .piobuildblack_f407zgsrcsystem_stm32f4xx.o c:/users/joy/.platformio/packages/toolchain-gccarmnoneeabi@2.00000.0/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/bin/ld.exe: error: .piobuildblack_f407zgliba89libarm_fir_example_f32.a(arm_fir_example_f32.o) uses VFP register arguments, .piobuildblack_f407zgfirmware.elf does not...c:/users/joy/.platformio/packages/toolchain-gccarmnoneeabi@2.00000.0/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/bin/ld.exe: failed to merge target specific data of file .piobuildblack_f407zgliba89libarm_fir_example_f32.a(arm_fir_example_f32.o)c:/users/joy/.platformio/packages/toolchain-gccarmnoneeabi@2.00000.0/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/bin/ld.exe: error: .piobuildblack_f407zgliba89libarm_fir_example_f32.a(fft.o) uses VFP register arguments, .piobuildblack_f407zgfirmware.elf does not c:/users/joy/.platformio/packages/toolchain-gccarmnoneeabi@2.00000.0/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/bin/ld.exe: failed to merge target specific data of file .piobuildblack_f407zgliba89libarm_fir_example_f32.a(fft.o)c:/users/joy/.platformio/packages/toolchain-gccarmnoneeabi@2.00000.0/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/bin/ld.exe: error: .piobuildblack_f407zgliba89libarm_fir_example_f32.a(math_helper.o) uses VFP register arguments, .piobuildblack_f407zgfirmware.elf does not
類型錯誤很好解決,直接導(dǎo)入HAL的總?cè)肟?h文件#include
參考:#error 'Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)'
編譯過后,錯誤少了一大筐:
上一篇:搭建開發(fā)環(huán)境 --- 基于STM32CubeIDE
下一篇:NUCLEO-L432KC實現(xiàn)GPIO控制(STM32L432KC)
推薦閱讀最新更新時間:2025-04-03 12:30





- 熱門資源推薦
- 熱門放大器推薦
設(shè)計資源 培訓(xùn) 開發(fā)板 精華推薦
- 嵌入式學(xué)習(xí)篇丨迅為4412開發(fā)板Android4.4系統(tǒng)編譯
- Linux系統(tǒng)編程篇丨迅為IMX6ULL-對應(yīng)視頻講解
- 嵌入式學(xué)習(xí)丨4412開發(fā)板-uboot源碼-匯編-源碼分析(一)嵌入式學(xué)習(xí)丨4412開發(fā)板-uboot源碼-匯
- 迅為IMX6ULL開發(fā)板-主頻和時鐘配置例程(二)
- 迅為IMX6ULL開發(fā)板-主頻和時鐘配置例程
- 迅為IMX6ULL開發(fā)板安裝VMware Tool工具
- i.MX6ULL終結(jié)者Debian文件系統(tǒng)的構(gòu)建i.MX6ULL 移植Debian文件系統(tǒng)
- 迅為i.MX6ULL開發(fā)板按鍵例程編譯及運行
- 迅為-i.MX6開發(fā)板手冊更新-非設(shè)備樹uboot-修改默認環(huán)境變量
- DER-672 - 使用 HiperLCS-2 芯片組和 HiperPFS-5 的 220 W 功率因數(shù)校正 LLC 電源,適用于電視和顯示器
- 使用 Richtek Technology Corporation 的 RT8162A 的參考設(shè)計
- AD8604ARQZ放大器光電二極管電路的典型應(yīng)用
- 基于 MCF5232CAB80 MPU ColdFire MCF5xxx 處理器的 M5235EVB、M523xEVB 評估板
- STM32
- ADP1046A-100-EVALZ,用于隔離式開關(guān)電源 ADP1046A 的 100 瓦評估套件
- L7805C高輸入電壓電路典型應(yīng)用(配置1)
- 噴墨打印機40W、5V、12V、28V交流轉(zhuǎn)直流多路輸出電源
- KSZ8081RNA-EVAL,KSZ8081RNA 10Base-T/100Base-TX PHY 收發(fā)器評估板
- 使用 Analog Devices 的 LT1424IN8-9 的參考設(shè)計
- BOE(京東方)董事長提議回購公司股份 堅定看好資本市場長期價值
- 英飛凌宣布收購Marvell的汽車以太網(wǎng)業(yè)務(wù)
- 強強聯(lián)合!兆易創(chuàng)新與納微半導(dǎo)體達成戰(zhàn)略合作
- 德州儀器模擬設(shè)計 | 運算放大器基本穩(wěn)定性概述
- 人形機器人新王者崛起:Figure估值直逼2900億,中國軍團能否迎頭趕上?
- 首創(chuàng)全球最小力傳感器,深圳企業(yè)為機器人裝上“超靈敏指尖”
- 投資約4億!智洋創(chuàng)新將建AI邊緣感知設(shè)備產(chǎn)業(yè)化項目
- 長城汽車、宇樹科技跨界合作!首期項目曝光
- 利用10BASE-T1S以太網(wǎng)簡化汽車應(yīng)用中的分區(qū)架構(gòu)
- 意法半導(dǎo)體公布2025年第一季度財報和電話會議時間安排
- 腦洞大開的汽車專利,你知道多少個?
- Lytx推出增強型機器視覺與AI風(fēng)險探測技術(shù) 助于安全駕駛
- secunet推出安全分析產(chǎn)品 可使汽車電子部件安全測試自動化
- 電動汽車電池浸入式冷卻新技術(shù) 有助于優(yōu)化能量密度和安全性
- 研究人員開發(fā)摻硼正極 提升電池能量密度
- stm32f0單片機在DEBUG的時候遇到的問題
- STM32出現(xiàn)“Internal command error”錯誤無法下載程序的解決方法
- STM32 J-LINK SW 調(diào)試常見問題
- STM32使用J-Link下載出錯解決方法
- 正版ST-link/V2引腳定義和注意事項