STM32CubeMXで生成したコードをEclipseに取り込んでコンパイルするとエラーとなった。
arm-none-eabi-gcc -mcpu=cortex-m7 -mthumb -mfloat-abi=hard -mfpu=fpv5-d16 '-D__weak=__attribute__((weak))' '-D__packed="__attribute__((__packed__))"' -DUSE_HAL_DRIVER -DSTM32F769xx -I"/Volumes/Extreme900/workspace/eclipse/hello_stm32f7-disco/Inc" -I"/Volumes/Extreme900/workspace/eclipse/hello_stm32f7-disco/Drivers/STM32F7xx_HAL_Driver/Inc" -I"/Volumes/Extreme900/workspace/eclipse/hello_stm32f7-disco/Drivers/STM32F7xx_HAL_Driver/Inc/Legacy" -I"/Volumes/Extreme900/workspace/eclipse/hello_stm32f7-disco/Drivers/CMSIS/Device/ST/STM32F7xx/Include" -I"/Volumes/Extreme900/workspace/eclipse/hello_stm32f7-disco/Drivers/CMSIS/Include" -Og -g3 -Wall -fmessage-length=0 -ffunction-sections -c -fmessage-length=0 -MMD -MP -MF"Drivers/STM32F7xx_HAL_Driver/Src/stm32f7xx_ll_usb.d" -MT"Drivers/STM32F7xx_HAL_Driver/Src/stm32f7xx_ll_usb.o" -o "Drivers/STM32F7xx_HAL_Driver/Src/stm32f7xx_ll_usb.o" "../Drivers/STM32F7xx_HAL_Driver/Src/stm32f7xx_ll_usb.c"
../Drivers/STM32F7xx_HAL_Driver/Src/stm32f7xx_ll_usb.c: In function 'USB_WritePacket':
../Drivers/STM32F7xx_HAL_Driver/Src/stm32f7xx_ll_usb.c:958:53: error: expected ')' before 'uint32_t'
USBx_DFIFO((uint32_t)ch_ep_num) = *((__packed uint32_t *)pSrc);
^~~~~~~~
uint32_tの前に閉じ括弧が必要と言っている。どうやら__packedの処理のあたりが怪しい。このコンパイルオプションをみると__packedはマクロ定数として処しているようだ。
そこで以下の対処をしてコンパイルエラーは解消した。
- プロジェクトを右クリック→プロパティ としてプロパティ設定画面を開く
- 「C/C++一般」→「コード解析」→「パスおよびシンボル」を選択

__packed(とついでに__weakも)二重引用符を削除する。

二重引用符で囲まれたものをシェルにうまく伝わっていないのかな?
なおコンパイル環境は以下の通り。
- OS: macOS Mojave
- Eclipse: 2019-03
- CubeMX: Version 5.2.0
- 対象マイコン: STM32F769I-DISCO


コメント