3
votes

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'
3
You might want to include the code that generated the compiler errors, or otherwise it isn't possible to answer the question.Lundin
It is a blank project with an empty main() function that only includes the STM32 HAL and the CMSIS. I do not have any code written. The problem is either in the HAL or my understanding. The first file that has errors is cmsis_gcc.h which is only a header file provided by STM32 which is 1374 lines of code... :(Tedi

3 Answers

6
votes

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.

1
votes

Quoting Wikipedia:

ANSI C, ISO C and Standard C refer to the successive standards for the C programming language published by the American National Standards Institute (ANSI) and the International Organization for Standardization (ISO).

So it seems "ANSI C" is not well-defined, it's not said which particular version of the C standard is being used.

Since it's clearly using inline, it must be at least C99, so try that. It works for me ...

1
votes

To further clarify, the file in question, mostly like something like core_cm.h (depending on which MCU you are using), has conditionally code. In your particular case, it's choking on something like

STATIC INLINE ...

and STATIC, and INLINE are conditionally defined as different things depending on which compiler you are using. GCC would provide the correct define (GNUC) for the conditional code, but as mentioned, you need to specify C99 for the inline keyword.

FYI, the // comment is also C99, and not C89/C90.