Compilation Issues with STM32 HAL Libraries in Strict ANSI-C Mode

Good day everyone, I'm in a bit of a hit and miss on something guys. I have an embedded project that starts as a blank project with an empty main() function, including only the STM32 HAL and CMSIS. This project uses the STM32 HAL libraries, which in turn use the stm32f072rb CMSIS header files. The HAL documentation states that it is written in Strict ANSI-C: "The source code of drivers is developed in Strict ANSI-C, which makes it independent of the development tools. It is checked with the CodeSonarTM static analysis tool, fully documented, and MISRA-C 2004 compliant." I understand Strict ANSI-C to mean C89, so I added the following GCC flags to my Makefile:
CFLAGS = -std=c89\
-pedantic-errors
CFLAGS = -std=c89\
-pedantic-errors
However, when I compile with these flags, I receive numerous errors and warnings. Without these flags, the code compiles without issues. I'm very confused about this. Am I missing something, or is there a mistake in their documentation? Here are some of the GCC compiler errors with the flags enabled, which appear repeatedly across many STM32 HAL files:
error: expected '=', ',', ';', 'asm' or '__attribute__' before 'void'
error: unknown type name 'inline'
error: expected '=', ',', ';', 'asm' or '__attribute__' before 'NVIC_GetPriority'
error: expected '=', ',', ';', 'asm' or '__attribute__' before 'void'
error: unknown type name 'inline'
error: expected '=', ',', ';', 'asm' or '__attribute__' before 'NVIC_GetPriority'
2 Replies
RED HAT
RED HAT4mo ago
@Sterling The errors you’re encountering suggest that there are features in the STM32 HAL code that are not compatible with C89. For instance, the inline keyword is not part of C89 but was introduced in C99. The STM32 HAL documentation may use "Strict ANSI-C" loosely, possibly meaning they aim for high portability rather than strict adherence to C89. you can use C99 standard, Instead of -std=c89, try using -std=c99. The inline keyword and other features would then be recognized.
CFLAGS = -std=c99\
-pedantic-errors
CFLAGS = -std=c99\
-pedantic-errors
If you must use C89, you may need to manually adjust the HAL code or find alternative ways to handle inline and other incompatible constructs. This can be very labor-intensive.
Sterling
Sterling4mo ago
Okayy then, @RED HAT , I think I will just use the C99 rather.. thanks for this 🙏
Want results from more Discord servers?
Add your server