Arm Mbed OS support forum

STM32F412Cx fails to link

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).

We had a similar problem when we tried STM32L422, but with SPI.
I will assume you are using 6.3.0 version of the OS.

The problem stems from this file:

mbed-os\targets\TARGET_STM\TARGET_STM32F4\serial_device.c

There are lines that define:

#elif defined (TARGET_STM32F412xG)
#define UART_NUM (4)
...

Also, it depends on how you defined your custom target. NUCLEO_F412ZG is defined in mbed-os\targets\targets.json like this:

"NUCLEO_F412ZG": {
        "inherits": [
            "MCU_STM32F4"
        ],
        "supported_form_factors": [
            "ARDUINO",
            "MORPHO"
        ],
        "extra_labels_add": [
            "STM32F412xG"
        ],
        "macros_add": [
            "STM32F412Zx"
        ],
        "detect_code": [
            "0826"
        ],
        "device_has_add": [
            "CAN",
            "TRNG",
            "USBDEVICE"
        ],
        "device_name": "STM32F412ZG"
    },

So, your solution would be:

  1. In your custom target set the "extra_labels_add" variable to STM32F412CE or STM32F412xE if you want to be more general

  2. Change "macros_add"to "STM32F412Cx"

  3. 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.

Hi Ante,

I am using OS5.15.

The real bug is located here in my opinion:

#if defined(STM32F412Zx) || defined(STM32F412Vx) || defined(STM32F412Rx) || defined(STM32F413xx) || defined(STM32F423xx)
#define __HAL_RCC_USART3_CLK_ENABLE() do { \
                                      __IO uint32_t tmpreg = 0x00U; \
                                      SET_BIT(RCC->APB1ENR, RCC_APB1ENR_USART3EN);\
                                      /* Delay after an RCC peripheral clock enabling */ \
                                      tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_USART3EN);\
                                      UNUSED(tmpreg); \
                                      } while(0U)
#endif /* STM32F412Zx || STM32F412Vx || STM32F412Rx || STM32F413xx || STM32F423xx */

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.

1 Like

You are quite right.

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.

Hi

I tried compilation with STM32F412CE,
I don’t see any issue with HAL_RCC_USART3_CLK_ENABLE

Jerome

We had a similar problem when we tried STM32L422, but with SPI.

I tried also STM32L422 compilation,
I just had an issue in ADC file => https://github.com/ARMmbed/mbed-os/pull/13905

Jerome

@jeromecoutant

I am using

  • STM32CubeIDE 1.4.0
  • New STM32 project
  • Choose STM32F412CE, target reference STM32F412CEUx
  • Firmware Package FW_F4 V1.25.2
  • In cube/device configurator -> Connectivity -> USART3 -> choose single wire/half duplex
  • Save, generate code
  • open main, build all

I get:

arm-none-eabi-gcc "../Core/Src/sysmem.c" -mcpu=cortex-m4 -std=gnu11 -g3 -DSTM32F412Cx -DUSE_HAL_DRIVER -DDEBUG -c -I../Core/Inc -I../Drivers/STM32F4xx_HAL_Driver/Inc -I../Drivers/STM32F4xx_HAL_Driver/Inc/Legacy -I../Drivers/CMSIS/Device/ST/STM32F4xx/Include -I../Drivers/CMSIS/Include -O0 -ffunction-sections -fdata-sections -Wall -fstack-usage -MMD -MP -MF"Core/Src/sysmem.d" -MT"Core/Src/sysmem.o" --specs=nano.specs -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb -o "Core/Src/sysmem.o"
arm-none-eabi-gcc "../Core/Src/system_stm32f4xx.c" -mcpu=cortex-m4 -std=gnu11 -g3 -DSTM32F412Cx -DUSE_HAL_DRIVER -DDEBUG -c -I../Core/Inc -I../Drivers/STM32F4xx_HAL_Driver/Inc -I../Drivers/STM32F4xx_HAL_Driver/Inc/Legacy -I../Drivers/CMSIS/Device/ST/STM32F4xx/Include -I../Drivers/CMSIS/Include -O0 -ffunction-sections -fdata-sections -Wall -fstack-usage -MMD -MP -MF"Core/Src/system_stm32f4xx.d" -MT"Core/Src/system_stm32f4xx.o" --specs=nano.specs -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb -o "Core/Src/system_stm32f4xx.o"
../Core/Src/stm32f4xx_hal_msp.c: In function 'HAL_UART_MspInit':
../Core/Src/stm32f4xx_hal_msp.c:95:5: warning: implicit declaration of function '__HAL_RCC_USART3_CLK_ENABLE'; did you mean '__HAL_RCC_USART2_CLK_ENABLE'? [-Wimplicit-function-declaration]
     __HAL_RCC_USART3_CLK_ENABLE();
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~
     __HAL_RCC_USART2_CLK_ENABLE
../Core/Src/stm32f4xx_hal_msp.c: In function 'HAL_UART_MspDeInit':
../Core/Src/stm32f4xx_hal_msp.c:129:5: warning: implicit declaration of function '__HAL_RCC_USART3_CLK_DISABLE'; did you mean '__HAL_RCC_USART6_CLK_DISABLE'? [-Wimplicit-function-declaration]
     __HAL_RCC_USART3_CLK_DISABLE();
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
     __HAL_RCC_USART6_CLK_DISABLE
arm-none-eabi-gcc -o "TEst.elf" @"objects.list"   -mcpu=cortex-m4 -T"C:\Users\Ante\STM32CubeIDE\workspace_1.4.0\TEst\STM32F412CEUX_FLASH.ld" --specs=nosys.specs -Wl,-Map="TEst.map" -Wl,--gc-sections -static --specs=nano.specs -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb -Wl,--start-group -lc -lm -Wl,--end-group
Core/Src/stm32f4xx_hal_msp.o: In function `HAL_UART_MspInit':
C:/Users/Ante/STM32CubeIDE/workspace_1.4.0/TEst/Debug/../Core/Src/stm32f4xx_hal_msp.c:95: undefined reference to `__HAL_RCC_USART3_CLK_ENABLE'
collect2.exe: error: ld returned 1 exit status
make: *** [makefile:50: TEst.elf] Error 1
"make -j8 all" terminated with exit code 2. Build might be incomplete.

Maybe you should raise an issue in ST forum…
With MBED, it is OK :slight_smile: