Search code examples
cgccstm32c89hal

STM32 HAL C standard


I am a little confused...

I have an embedded project that uses the STM32 HAL libraries which in turn uses the stm32f072rb CMSIS header files.

The HAL claims here that it is Strict ANSI-C

The source code of drivers is developed in Strict ANSI-C, which makes it
independent from the development tools. It is checked with CodeSonarTM static
analysis tool. It is fully documented and is MISRA-C 2004 compliant.

I have the belief that Strict ANSI-C means C89 so I added these gcc flags to my Makefile.

CFLAGS =            -std=c89\
                    -pedantic-errors

But when I do it gives lots of errors and warnings. If I remove these flags it compiles.

I am very confused over this. Am I lacking something or their documentation is wrong?

Here are some gcc compiler erros with the flag enabled... They keep repeating over many of STM32 HAL files.

error: expected '=', ',', ';', 'asm' or '__attribute__' before 'void'
error: unknown type name 'inline'
error: expected '=', ',', ';', 'asm' or '__attribute__' before 'NVIC_GetPriority'

Solution

  • error: unknown type name 'inline' points at a feature that was added with C99.

    I suspect that the problem is that their documentation says "ANSI-C". "ANSI-C" is a rubbish term which does indeed most of the time refer to C89. Since the year 1990, ANSI has nothing to do with the C standard any longer, so those who keep talking about "ANSI-C" after the year 1990 are simply confused, see What is the difference between C, C99, ANSI C and GNU C?.

    Your compiler options are correct for strict C89/C90 code. Try to compile with -std=c99 -pedantic-errors instead.

    However, MISRA-C:2004 does explicitly not allow C99 features, so this is fishy. Code containing inline is definitely not MISRA-C:2004 compliant. For C99 support, MISRA-C:2012 is needed.