Skip to main content
ru_it
Visitor II
March 12, 2015
Question

STM32F3cube 1.1.0 current state of MISRA compliance

  • March 12, 2015
  • 12 replies
  • 2583 views
Posted on March 12, 2015 at 15:23

Hello ST team,

I am currently evaluating the STM32F3cube library. The documentation states, that it complies with MISRA 2004, which made me consider using the library in the first place. After some light browsing through the source code, I quickly found the following code in the file stm32f3xx_hal_adc_ex.c (Version 1.1.0 of 12-Sept-2014):

HAL_StatusTypeDef HAL_ADC_Init(ADC_HandleTypeDef* hadc) 
{ 
uint32_t WaitLoopIndex = 0; 
/* Set the intermediate state before moving the ADC voltage regulator */ 
/* to state enable. */ 
hadc->Instance->CR &= ~(ADC_CR_ADVREGEN); 
/* Set ADVREGEN bits to 0x01 */ 
hadc->Instance->CR |= ADC_CR_ADVREGEN_0; 
/* Delay for ADC stabilization time. */ 
/* Delay fixed to worst case: maximum CPU frequency */ 
while(WaitLoopIndex < ADC_STAB_DELAY_CPU_CYCLES) 
{ 
WaitLoopIndex++; 
} 
}

This code starts the voltage regulator of the ADC in the

HAL_ADC_Init

function. as stated in the stm32f3 manual, one has to wait 10µs after enabling the regulator, which is done using busy waiting in a loop using a non-volatile loop counter. There are a few more instances of this pattern inside the ADCexdriver. Of course this only works if the compilers's optimization is turned off (up to -O1 in gcc). Otherwise, the loopwould be removed, because it is dead code and has no effect on the program except for the duration. Since this also violates theMISRA coding rules and is easily detected by static code checkers, I was wondering, if I am missing some documentation, which tells me, which MISRA rules where checked and how. Also I would like to know which compilers and which compiler settings need to be used to get reliable code. I currently assume these are unintended bugs but it might as well be intetional if special compiler flags are required. I hope you can clarify this for me. Best regards #everything-is-awesome
    This topic has been closed for replies.

    12 replies

    Tesla DeLorean
    Guru
    March 12, 2015
    Posted on March 12, 2015 at 16:39

    Since this also violates the MISRA coding rules and is easily detected by static code checkers, I was wondering, if I am missing some documentation, which tells me, which MISRA rules where checked and how.

    I don't know about the current state of things, but last time did a basic code walk for the Cube/HAL stuff it scared the heck out of me. You'd want to analyze the code to your own level of satisfaction, because all the code is provided for free and without warranty or recourse.
    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    David Brooks
    Associate III
    March 10, 2016
    Posted on March 10, 2016 at 19:34

    Does anyone have an update on this question? The Cube Manual says generated code is Misra-compliant, but thousands of messages are generated in the sample projects. I realize one can demonstrate compliance without including all of the rules, but what rules did ST employ and what were their justifications for excluding them? (A requirement to claim compliance.)

    Tesla DeLorean
    Guru
    March 10, 2016
    Posted on March 10, 2016 at 22:19

    Does anyone have an update on this question?

    Depressingly a year on it hasn't been addressed.

    I hear CubeMX won a JD Power award for best in class code generation...

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    Amel NASRI
    ST Technical Moderator
    March 14, 2016
    Posted on March 14, 2016 at 10:29

    Hi dmbrooks44,

    Could you please precise where exactly did you faced a MISRA-C non-compliance: which firmware or driver? Or is it within CubeMX generated code?

    -Mayla-

    To give better visibility on the answered topics, please click on "Best Answer" on the reply which solved your issue or answered your question.
    David Brooks
    Associate III
    March 15, 2016
    Posted on March 15, 2016 at 21:37

    Within Cube-generated code V4.0

    ________________

    Attachments :

    LAB_HID_Card_Reader_-_Flash-Debug_C-STAT_summary.html : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HzMj&d=%2Fa%2F0X0000000bLW%2FxCIMYsI_uJiML.RwF59fKydt_eif1X4sv3ZjRUzowu4&asPdf=false
    Amel NASRI
    ST Technical Moderator
    March 24, 2016
    Posted on March 24, 2016 at 14:37

    Hi dmbrooks44,

    The CubeMX user manual is UM1718 and we don't say there that generated code is MISRA-C compliant.

    May be you are referring to the HAL user manuals: the HAL drivers are compliant, with a validation report available on request from your ST contact.

    We will keep you updated about the MISRA-C compliance of CubeMX generated code.

    -Mayla-

    To give better visibility on the answered topics, please click on "Best Answer" on the reply which solved your issue or answered your question.
    David Brooks
    Associate III
    April 1, 2016
    Posted on April 01, 2016 at 17:30

    Please see the attached Misra Report showing numerous errors in the HAL files. I look forward to your response.

    ________________

    Attachments :

    MisraC_2004_Report.txt : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HzPM&d=%2Fa%2F0X0000000bLX%2FLs6vVCfNg.6vrFTeLIjKppFDvviHmzR8A5dS9bDiN30&asPdf=false
    Rosiney Silva
    Associate
    April 2, 2016
    Posted on April 02, 2016 at 17:48

    Which tool you use to generate the MISRA report

    ?

    Tesla DeLorean
    Guru
    April 2, 2016
    Posted on April 02, 2016 at 19:39

    From the style, and form, it looks to be IAR

    http://supp.iar.com/FilesPublic/UPDINFO/004916/arm/doc/EW_MisraC2004Reference.ENU.pdf

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    Rosiney Silva
    Associate
    April 2, 2016
    Posted on April 02, 2016 at 22:05

    Thanks for the reference

    clive1

    .