cancel
Showing results for 
Search instead for 
Did you mean: 

is stm32CubeIDE use C MISRA 2004 Compliance

All in the title.
I'm asking this question because I have compilation warning inside a library that I included in my project. And inside the source-code of this library, there is a mention about rules of C MISRA-2004 that are not respected.
Here is the mention :

/** \page CMSIS_MISRA_Exceptions  MISRA-C:2004 Compliance Exceptions
  CMSIS violates the following MISRA-C:2004 rules:

 

   \li Required Rule 8.5, object/function definition in header file.<br>
     Function definitions in header files are used to allow 'inlining'.

 

   \li Required Rule 18.4, declaration of union type or object of union type: '{...}'.<br>
     Unions are used for effective representation of core registers.

 

   \li Advisory Rule 19.7, Function-like macro defined.<br>
     Function-like macros are used to allow more efficient code.
 */

The warning concern an union (like Rule 18.4 that is not respected).

Here is the warning :

C:/Users/xxxx/ST/BlueNRG-1_2 DK 3.2.3(v4.0)/Library/CMSIS/Device/ST/BlueNRG1/Include/BlueNRG1.h:1541:5: warning: no semicolon at end of struct or union

1541 | } CLOCK_EN_b;

 

Here is the (simplified) struct that provoke the warning :

 

 

 

typedef struct { /*!< (@ 0x40900000) CKGEN_SOC Structure */ __IM uint32_t RESERVED[2]; union { __IM uint8_t REASON_RST; /*!< (@ 0x00000008) Indicates the reset reason from Cortex-M0 */ struct { __IM uint8_t : 1; } REASON_RST_b; } ; __IM uint8_t RESERVED1; union { __IM uint32_t DIE_ID; /*!< (@ 0x0000001C) Identification information of the device */ struct { __IM uint32_t REV : 4; /*!< [3..0] Cut revision */ */ } DIE_ID_b; } ; union { __IOM uint32_t CLOCK_EN; /*!< (@ 0x00000020) Enable or gates the APB clock of the peripherals */ struct { __IOM uint32_t GPIO : 1; /*!< [0..0] GPIO clock */ */ } CLOCK_EN_b; } ; union { __IOM uint8_t DMA_CONFIG; /*!< (@ 0x00000024) DMA config */ struct { __IOM uint8_t ADC_CH0 : 1; /*!< [0..0] Select ADC on DMA channel 0 instead of peripheral */ } DMA_CONFIG_b; } ; __IM uint8_t RESERVED4; __IM uint16_t RESERVED5; } CKGEN_SOC_Type; /*!< Size = 40 (0x28)
View more

 

 

So I read the rule 18.4 of MISRA C 2004 compliance, and surprisingly, I didnt fount any

information and how a union in a struct should be write in code.

Thanks for help !

6 REPLIES 6

Have you actually read the MISRA document?

AndrewNeil_0-1712324483167.png

So the notes you've seen in the CMSIS Library comments are just fulfilling that requirement to document this deviation from the Rule.

This is acceptable.

 

As I said, I did read this rule.

But that doesnt really answer my question : is stm32cubeIDE use C MISRA 2004 Compliance ?

I dont know why I get a warning from the struct I provided (from the source-code).


@q3z85d41xqz036d wrote:

But that doesnt really answer my question : is stm32cubeIDE use C MISRA 2004 Compliance ?


Yes, it does answer the question about MISRA compliance - it meets the compliance criteria of documenting what it does.

 


@q3z85d41xqz036d wrote:

I dont know why I get a warning from the struct I provided (from the source-code).


Where does that warning come from? It looks like just a compiler warning?

Compiler warnings are nothing to do with MISRA compliance.

 

I understood that the library want to follow MISRA-C, as there is this comment that I provide (about broken rules of MISRA Compliance). But maybe this library follow MISRA Compliance, but the code-parser used by stm32cubeIDE doesnt. I just wanted to have the context.

The warning is shown after the build operation, my compiler is gcc.


@q3z85d41xqz036d wrote:

The warning is shown after the build operation, my compiler is gcc.


So it's just a normal compiler warning - nothing to do with MISRA.

Show the actual code which gives this warning.

Here is the (simplified) struct the provoke the warning :

 

 

 

 

typedef struct { /*!< (@ 0x40900000) CKGEN_SOC Structure */ __IM uint32_t RESERVED[2]; union { __IM uint8_t REASON_RST; /*!< (@ 0x00000008) Indicates the reset reason from Cortex-M0 */ struct { __IM uint8_t : 1; } REASON_RST_b; } ; __IM uint8_t RESERVED1; union { __IM uint32_t DIE_ID; /*!< (@ 0x0000001C) Identification information of the device */ struct { __IM uint32_t REV : 4; /*!< [3..0] Cut revision */ */ } DIE_ID_b; } ; union { __IOM uint32_t CLOCK_EN; /*!< (@ 0x00000020) Enable or gates the APB clock of the peripherals */ struct { __IOM uint32_t GPIO : 1; /*!< [0..0] GPIO clock */ */ } CLOCK_EN_b; // HERE IS LINE 1541 } ; union { __IOM uint8_t DMA_CONFIG; /*!< (@ 0x00000024) DMA config */ struct { __IOM uint8_t ADC_CH0 : 1; /*!< [0..0] Select ADC on DMA channel 0 instead of peripheral */ } DMA_CONFIG_b; } ; __IM uint8_t RESERVED4; __IM uint16_t RESERVED5; } CKGEN_SOC_Type; /*!< Size = 40 (0x28)
View more

 

 

 

 

 Here is the warning :

C:/Users/xxxx/ST/BlueNRG-1_2 DK 3.2.3(v4.0)/Library/CMSIS/Device/ST/BlueNRG1/Include/BlueNRG1.h:1541:5: warning: no semicolon at end of struct or union | } CLOCK_EN_b;
I put a comment on "real" line 1541