Question
STM32F3cube 1.1.0 current state of MISRA compliance
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