Compile error after CubeMX code generation


I am working on adding an absolute encoder and was looking to repurpose some of the GPIO pins. I made the relevant modifications in CubeMX and then generated the code. Then I created a new Makefile and compiled the code but receive an error as shown below:

$ make
arm-none-eabi-gcc -c -mthumb -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -D__weak=attribute((weak)) -D__packed=attribute((packed)) -DUSE_HAL_DRIVER -DSTM32F405xx -D__weak=attribute((weak)) -D__packed=attribute((packed)) -DUSE_HAL_DRIVER -DSTM32F405xx -IDrivers/CMSIS/Device/ST/STM32F4xx/Include -IDrivers/CMSIS/Include -IDrivers/DRV8301 -IDrivers/STM32F4xx_HAL_Driver/Inc -IDrivers/STM32F4xx_HAL_Driver/Inc/Legacy -IInc -IMiddlewares/ST/STM32_USB_Device_Library/Class/CDC/Inc -IMiddlewares/ST/STM32_USB_Device_Library/Core/Inc -IMiddlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS -IMiddlewares/Third_Party/FreeRTOS/Source/include -IMiddlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F -IMotorControl -O0 -Wall -fdata-sections -ffunction-sections -g -gdwarf-2 -std=c99 -MD -MP -MF .dep/drv8301.o.d -Wa,-a,-ad,-alms=build/drv8301.lst Drivers/DRV8301/drv8301.c -o build/drv8301.o
/usr/bin/sh: -c: line 0: syntax error near unexpected token (' /usr/bin/sh: -c: line 0:arm-none-eabi-gcc -c -mthumb -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -D__weak=attribute((weak)) -D__packed=attribute((packed)) -DUSE_HAL_DRIVER -DSTM32F405xx -D__weak=attribute((weak)) -D__packed=attribute((packed)) -DUSE_HAL_DRIVER -DSTM32F405xx -IDrivers/CMSIS/Device/ST/STM32F4xx/Include -IDrivers/CMSIS/Include -IDrivers/DRV8301 -IDrivers/STM32F4xx_HAL_Driver/Inc -IDrivers/STM32F4xx_HAL_Driver/Inc/Legacy -IInc -IMiddlewares/ST/STM32_USB_Device_Library/Class/CDC/Inc -IMiddlewares/ST/STM32_USB_Device_Library/Core/Inc -IMiddlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS -IMiddlewares/Third_Party/FreeRTOS/Source/include -IMiddlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F -IMotorControl -O0 -Wall -fdata-sections -ffunction-sections -g -gdwarf-2 -std=c99 -MD -MP -MF .dep/drv8301.o.d -Wa,-a,-ad,-alms=build/drv8301.lst Drivers/DRV8301/drv8301.c -o build/drv8301.o’
make: *** [build/drv8301.o] Error 1

Has anybody else had the same error?



When you say you created a new Makefile, do you mean you used CubeMX2Makefile? The following assumes that’s the case:

That tool is super hacky and very unreliable. It’s better than nothing, and was useful, but don’t trust it to just work xP. I would use git diff to check which files got added by CubeMX, and just add them manually to the makefile.
Of course, feel free to dig into CubeMX2Makefile and try to fix the problems; it would be very useful to many people if it was more reliable.


You are correct @madcowswe. I just reused the old makefile and it was fine. Will have a dig around when I can and see what was wrong.