2015-03-12 07:23 AM
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-awesome2015-03-12 08:39 AM
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.2016-03-10 10:34 AM
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.)
2016-03-10 01:19 PM
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...2016-03-14 02:29 AM
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 Accept as Solution on the reply which solved your issue or answered your question.
2016-03-15 01:37 PM
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=false2016-03-24 06:37 AM
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 Accept as Solution on the reply which solved your issue or answered your question.
2016-04-01 08:30 AM
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=false2016-04-02 08:48 AM
Which tool you use to generate the MISRA report
?
2016-04-02 10:39 AM
From the style, and form, it looks to be IAR
http://supp.iar.com/FilesPublic/UPDINFO/004916/arm/doc/EW_MisraC2004Reference.ENU.pdf