3

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'
Tedi
  • 203
  • 1
  • 13
  • You might want to include the code that generated the compiler errors, or otherwise it isn't possible to answer the question. – Lundin Dec 14 '17 at 13:32
  • 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 Dec 14 '17 at 13:35

3 Answers3

5

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.

Lundin
  • 195,001
  • 40
  • 254
  • 396
  • Yes with c99 works just fine. In order for HAL to compile CMSIS must be included in the Makefile. I get the feeling that the ST claim that their HAL library is c89 but the CMSIS is c99. I get the feeling that this is marketing trick. If the HAL depends on code that is not ANSI C, by that I mean c89 then HAL should not be claimed as ANSI C. – Tedi Dec 14 '17 at 13:42
  • @Tedi I believe CMSIS is not written by ST but ARM, though? I'm also not sure if it conforms to ISO C and MISRA-C. – Lundin Dec 14 '17 at 13:44
  • ARM provides a template and the partner, that is ST creates the specific CMSIS header file. I am investigating this. – Tedi Dec 14 '17 at 13:46
  • CMSIS claims to be ANSI C [compliant](http://www.keil.com/pack/doc/CMSIS/General/html/index.html) but Misra 2012 compliant. Also the first file that compiler does not like is written by ARM... Some other files by ST.. Thank you very must for all the help. I will lower my standards and program in C99. – Tedi Dec 14 '17 at 13:51
  • The fishy part about CMSIS is explained by this sentence from the version 5 documentation. `Conforms to MISRA 2012 (but does not claim MISRA compliance). MISRA rule violations are documented` – Tedi Dec 14 '17 at 13:56
1

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 ...

unwind
  • 391,730
  • 64
  • 469
  • 606
  • Thank you. I chose @Lundin 's answer but your's is also good. I gave you a positive arrow though. With C99 it works. – Tedi Dec 14 '17 at 13:55
1

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.