cancel
Showing results for 
Search instead for 
Did you mean: 

STM32CubeMX Makefile option.

David Bathurst
Associate III
Posted on March 06, 2018 at 23:19

I recently upgraded my CubeMX from 4.18.0 to 4.24.0 and was  very pleased to see a new 'Makefile' option under Project->Settings->Toolchain/IDE.   I'd previously used SW4STM32 and then ran a python script to generate a Makefile. Using this new feature, I've noticed a couple of issues with the generated Makefile when building on Ubuntu 16.04.4 LTS.

1. /bin/sh: /arm-none-eabi-gcc: No such file or directory

This turns out to be because BINPATH is set to nothing and the '/' between BINPATH and PREFIX means it looks for the compiler in the root directory.

BINPATH =

PREFIX = arm-none-eabi-

CC = $(BINPATH)/$(PREFIX)gcc

A simple fix is to correct BINPATH to /usr/bin:

BINPATH = /usr/bin

PREFIX = arm-none-eabi-

CC = $(BINPATH)/$(PREFIX)gcc

But I'm assuming editing the generated Makefile is not the correct way to do that, as my edits will presumably get overwritten whenever STM32CubeMX needs to regenerate it.  Is there somewhere in STM32CubeMX where you can specify some of these options?  It's not just that one I need to tweak, but also want some custom CFLAGS and LDFLAGS.  I guess I could gather all my Makefile changes into a sed script.  Would it be possible to add an advanced option to launch a user-supplied command after generating the Makefile?

After that fix, I run into a whole bunch of:

2. STM32CubeMX/Projects/Test1/Src/main.c:188: multiple definition of `main'

STM32CubeMX/Projects/Test1/Src/main.c:188: first defined here

Not just main() but a whole bunch of others such as HAL_MspInit(), MX_GPIO_Init() etc. etc.

It looks like a bunch of .c files gets repeated in C_SOURCES:

C_SOURCES = \

Src/usart.c \

Src/stm32f0xx_it.c \

Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_gpio.c \

Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_flash.c \

Src/stm32f0xx_hal_msp.c \

Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_pwr.c \

Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_tim_ex.c \

Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_rcc_ex.c \

Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_pwr_ex.c \

Src/gpio.c \

Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_uart_ex.c \

Src/system_stm32f0xx.c \

Src/stm32f0xx_it.c \

Src/stm32f0xx_hal_msp.c \

Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_dma.c \

Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_cortex.c \

Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_tim.c \

Src/main.c \

Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_i2c_ex.c \

Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_i2c.c \

Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_flash_ex.c \

Src/gpio.c \

Src/usart.c \

Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_uart.c \

Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_rcc.c \

Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal.c \

Src/main.c

usart.c stm32f0xx_it.c stm32f0xx_hal_msp.c gpio.c main.c all get listed twice from the Src directory.

Removing the duplicates gets me a clean build.

I've attached the .ioc file and the Makefile  produced by STM32MXCube (i.e. before I've tweaked it as described above).

1 REPLY 1
David Bathurst
Associate III
Posted on March 06, 2018 at 23:32

Ooops... after posting, I noticed via 'Related Content' that both of these issues have already been reported:

https://community.st.com/0D50X00009XkWowSAF

https://community.st.com/0D50X00009XkXAgSAN

Apologies for the added noise.