Skip to main content
Associate III
August 15, 2026
Question

STM32CubeMX2 Generated Code Throws Error When Treating Warnings As Errors

  • August 15, 2026
  • 3 replies
  • 95 views


After generating a CMAKE project using STM32CubeMX2 v1.1.1 followed by setting compiler options to “treat warnings as errors” (-Werror) and enable strict standards-conformance (-Wpedantic) in the root CMakeLists.txt file, I am errors in, mx_def.h.

 

Though this post shows the workaround:

  • What is the recommended C Standard that STM32C5 project should follow?
  • If the generated code stated “gnu11” but yet uses “gnu23”, shouldn’t the generator use the latter instead (see solution)?
  • And, what are the dangers of doing so?

 

Error Message:

error: ISO C restricts enumerator values to range of 'int' before C23

 

Full Error message:

[build] C:/PathTo/ProjectName/source/App/generated/hal/mx_def.h:32:38: error: ISO C restricts enumerator values to range of 'int' before C23 [-Werror=pedantic]
[build]    32 |   SYSTEM_OK                        = 0xEAEAEAEAU,        /* System initialization successfully       */
[build]       |                                      ^~~~~~~~~~~
[build] C:/PathTo/ProjectName/source/App/generated/hal/mx_def.h:33:38: error: ISO C restricts enumerator values to range of 'int' before C23 [-Werror=pedantic]
[build]    33 |   SYSTEM_PRESYSTEM_ERROR           = 0xF5F5F5F5U,        /* Error during System pre-initialization   */
[build]       |        

 

Screen Shot:

Reproduce Issue
 

To recreate this error:

  1. Open your generated project’s root “CMakeLists.txt” (generated by CubeMX2)
  2. Add the following to the target_compile_options(..) section:
  3. Clean and Compile Project
  4. The above errors will appear

Path: (root)/CMakeLists.txt

target_compile_options(${CMAKE_PROJECT_NAME} PUBLIC
  # Add additional compiler flags here

  # Warnings for C code:
  -Wpedantic              # Enable strict standards-conformance warnings (cleaner portable C code).
  -Wno-strict-prototypes  # Ignore pre-ANSI C style of '(void)'
  -Werror                 # Treats all warnings as errors
)

 
The Cause of the issue
 

The generated mx_def.h  enum, system_status_t uses values too large for C11 standard (i.e. greater than signed int), however they are allowed in C23 and GNU23 C Standard.

 

The Solution

  1. Open your generated file, “cmake/flags.cmake”
  2. Locate the “target_compile_options(“ that defines, “-std=gnu11
  3. Update this value to “-std=gnu23
  4. Clean project and recompile.

Path: cmake/flags.cmake

# file-format: 1.0.0
if(CMAKE_BUILD_TYPE STREQUAL "debug_GCC_STM32C562RET6")
  set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES SUFFIX ".elf")
  target_compile_options(${CMAKE_PROJECT_NAME} PUBLIC ${CPU_FLAGS})
  target_compile_options(${CMAKE_PROJECT_NAME} PUBLIC "SHELL:-g3 -O0 -fdata-sections -ffunction-sections -std=gnu11 -Wall -fstack-usage --specs=nano.specs --specs=nosys.specs -Werror=implicit-function-declaration ${CC_SECURE}")
  target_include_directories(${CMAKE_PROJECT_NAME} PUBLIC

 

Recommendation

The generated project’s Target Compiler Option-std” specification should match the code that is generated.

3 replies

T_Hamdi
ST Employee
August 18, 2026

Hello ​@Suess 

Thank you for bringing this issue to our attention.

I reported this internally.

Internal ticket number: CDM0065174

with regrads,

Hamdi 

"To give better visibility on the answered topics, please click on ""Accept as Solution"" on the reply which solved your issue or answered your question.Hamdi Teyeb"
SuessAuthor
Associate III
August 25, 2026

@T_Hamdi  where is the correct place for us to submit bugs and see the status on them?

ST Technical Moderator
August 26, 2026

Hello ​@Suess 

You can continue posting the limitations you identify in this forum and we try our best to manage them properly. The status remains an internal information. We keep you informed once the fix is available or there is a final statement.

In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. Saket_Om