cancel
Showing results for 
Search instead for 
Did you mean: 

X-CUBE-AI 5.2.0 Validation: static declaration of 'MX_USART2_UART_Init' follows non-static declaration

piernov
Associate II

With a fresh installation of STM32CubeIDE, after adding X-CUBE-AI 5.2.0 Validation template to a project, build fails with:

../Core/Src/main.c:55:13: error: static declaration of 'MX_USART2_UART_Init' follows non-static declaration

How to reproduce:

Create a new STM32 project.

In the board selector choose (for example) Nucleo-L476RE-P, validate project creation.

Add the X-CUBE-AI 5.2.0 software pack to the project with the Validation application template.

Set the Platform settings in the X-CUBE-AI configuration to the UART as needed.

Create a new network and import your model (TFLite used here).

Save and generate code.

Try to build project.

Actual behaviour:

Build fails with:

arm-none-eabi-gcc "../Core/Src/system_stm32l4xx.c" -mcpu=cortex-m4 -std=gnu11 -g3 -DUSE_HAL_DRIVER -DSTM32L452xx -DDEBUG -c -I../Core/Inc -I../Drivers/STM32L4xx_HAL_Driver/Inc -I../Drivers/STM32L4xx_HAL_Driver/Inc/Legacy -I../Drivers/CMSIS/Device/ST/STM32L4xx/Include -I../Drivers/CMSIS/Include -I../X-CUBE-AI/App -I../X-CUBE-AI -I../X-CUBE-AI/Target -I../Middlewares/ST/AI/Inc -O0 -ffunction-sections -fdata-sections -Wall -fstack-usage -MMD -MP -MF"Core/Src/system_stm32l4xx.d" -MT"Core/Src/system_stm32l4xx.o" --specs=nano.specs -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb -o "Core/Src/system_stm32l4xx.o"
../Core/Src/main.c:55:13: error: static declaration of 'MX_USART2_UART_Init' follows non-static declaration
 static void MX_USART2_UART_Init(void);
             ^~~~~~~~~~~~~~~~~~~
In file included from ../Core/Src/main.c:21:0:
../Core/Inc/main.h:85:8: note: previous declaration of 'MX_USART2_UART_Init' was here
 void   MX_USART2_UART_Init(void);
        ^~~~~~~~~~~~~~~~~~~

Indeed, `Core/Src/main.c` contains a forward declaration with the prototype:

static void MX_USART2_UART_Init(void);

Then the definition with the prototype:

static void MX_USART2_UART_Init(void)

While `Core/Inc/main.h` contains a declaration with the prototype:

void   MX_USART2_UART_Init(void);

`MX_USART2_UART_Init()` is called in `X-CUBE-AI/App/app_x-cube-ai.c` so it cannot be static in `Core/Src/main.c`.

Expected behaviour:

Project builds successfully.

`Core/Src/main.c` contains non-static prototype of `MX_USART2_UART_Init()` so that it can be called from `X-CUBE-AI/App/app_x-cube-ai.c`.

Temporary workaround:

After generating the code, you can remove the static forward declaration of `MX_USART2_UART_Init()` and remove the `static` keyword from its definition in `Core/Src/main.c`.

3 REPLIES 3
Khouloud ZEMMELI
ST Employee

Hello @piernov​ 

Thanks for your feedback,

In fact, you can change the Functions Visibility directly through CubeMX and according to your need, you can find this option under Project Manager- Advanced Settings as mentioned in the image below:

0693W000008wHG4QAM.png 

Hope my answer helped you, when your question is answered please close this topic by choosing Select as Best, this will help other users find that answer faster.

Thanks for your contribution, Khouloud

piernov
Associate II

Hi, thanks for your answer.

This is indeed the proper way to solve this problem.

However, in a previous version (it may have been STM32CubeIDE 1.2.0 and X-CUBE-AI 5.0.0, not sure), I did not encounter this problem to begin with. After creating a fresh project and adding the Validation template of X-CUBE-AI, the project could be built immediately without changing the MX_USART2_UART_Init() function visibility.

I think the visibility should be automatically changed when adding the Validation template of the X-CUBE-AI package.

Thanks,

Hi again @piernov​ 

Actually, when the function is generated as static, it will be initialized only in main.c, in case when it's generated as non-static, it will be defined also under main.h, so that the problem will not appear.

Could you please check with the latest CubeMX/IDE versions (6.2.0 and 1.6.0)?

Thanks, Khouloud