2024-04-05 06:28 AM - edited 2024-04-05 06:30 AM
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 :
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)
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 !
2024-04-05 06:42 AM - edited 2024-04-05 06:43 AM
Have you actually read the MISRA document?
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.
2024-04-05 06:52 AM
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).
2024-04-05 06:57 AM
@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.
2024-04-05 07:07 AM
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.
2024-04-05 07:27 AM
@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.
2024-04-05 07:38 AM - edited 2024-04-05 07:42 AM
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)
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