I am designing a board with a STM32F412CE processor. The code compiles and links fine when targeted for a ZG version (which has NUCLEO support), but it fails to link when targeting the smaller package type.
The linker error is:
c:/program files (x86)/gnu tools arm embedded/8 2019-q3-update/bin/…/lib/gcc/arm-none-eabi/8.3.1/…/…/…/…/arm-none-eabi/bin/ld.exe: BUILD/MYBOARD/GCC_ARM-DEBUG-BUILD/mbed-os/targets/TARGET_STM/serial_api.o: in function _serial_init_direct': mbed-os\targets\TARGET_STM/serial_api.c:79: undefined reference to __HAL_RCC_USART3_CLK_ENABLE’
collect2.exe: error: ld returned 1 exit status
This error originates in ‘stm32f4xx_hal_rcc_ex.h’ where USART3 is only included for the Z, V and R package variants of the F412 although the datasheet says that the C package does support USART3 (if only for Tx).
In your custom target set the "extra_labels_add" variable to STM32F412CE or STM32F412xE if you want to be more general
Change "macros_add"to "STM32F412Cx"
add these lines to before mentioned serial_device.c
#elif defined (TARGET_STM32F412xE) #define UART_NUM (3)
Now, the thing is, the STM really did a bad job of supporting MCUs other than those found on nucleo boards. By doing this you will probably run into other problems where you will need to change other interfaces you might be using as well - I2C/SPI/RTC/USB. All relevant files you will need to change are found in `mbed-os\targets\TARGET_STM\TARGET_STM32F4.
This is from the stm32f4xx_hal_rcc_ex.h header (line 4965). Here the function to enable the clock for USART3 is only enabled for the bigger packages. Maybe because in the 48 pin ‘C’ package, only the TX pin is brought out and an earlier silicon version it was not?
As I am not using this USART, I opted for removing the USART3_BASE definition from PeripheralNames.h which is local to my target. Thus, I don’t have to modify the mbed-os code.
I tried to create a basic process using STM32CubeIDE, and even a project generated with Cube fails in the same way. This is a bug from the HAL library.
@jeromecoutant is an ST employee, so he should look at it.