STMicroelectronics / STM32CubeL4

STM32Cube MCU Full Package for the STM32L4 series - (HAL + LL Drivers, CMSIS Core, CMSIS Device, MW libraries plus a set of Projects running on all boards provided by ST (Nucleo, Evaluation and Discovery Kits))
Other
262 stars 153 forks source link

MISRA C Compliance #5

Closed thebruce87m closed 4 years ago

thebruce87m commented 4 years ago

Hi All,

I have come across the following information:

I don't have access to CodeSonar but pc-lint is an industry standard tool for checking MISRA compliance and indeed used by ARM to check CMSIS so I trust the results.

The PC-Lint tool gives multiple violations for the HAL library, for example the code below in stm32l4xx_hal_i2c.c:

HAL_StatusTypeDef HAL_I2C_Init(I2C_HandleTypeDef *hi2c)
{
  /* Check the I2C handle allocation */
  if (hi2c == NULL)
  {
    return HAL_ERROR;
  }

  /* Check the parameters */
  assert_param(IS_I2C_ALL_INSTANCE(hi2c->Instance));
  assert_param(IS_I2C_OWN_ADDRESS1(hi2c->Init.OwnAddress1));
  assert_param(IS_I2C_ADDRESSING_MODE(hi2c->Init.AddressingMode));
  assert_param(IS_I2C_DUAL_ADDRESS(hi2c->Init.DualAddressMode));
  assert_param(IS_I2C_OWN_ADDRESS2(hi2c->Init.OwnAddress2));
  assert_param(IS_I2C_OWN_ADDRESS2_MASK(hi2c->Init.OwnAddress2Masks));
  assert_param(IS_I2C_GENERAL_CALL(hi2c->Init.GeneralCallMode));
  assert_param(IS_I2C_NO_STRETCH(hi2c->Init.NoStretchMode));

...

  return HAL_OK;
}

Shows multiple return statements in the function HAL_I2C_Init(). PC-Lint shows this as an error below:

    return HAL_ERROR;
    ^
..\Drivers\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_i2c.c(477,0): Note 904: Return statement before end of function 'HAL_I2C_Init(I2C_HandleTypeDef *)'
    [MISRA 2004 Rule 14.7, required]"

So my questions are:

ALABSTM commented 4 years ago

Hi @thebruce87m,

Thank you for reporting this issue. It will be forwarded to our development teams. I will let you updated as soon as they provide me with their feedback. Thank you for your patience.

Take care and stay safe.

With regards,

ALABSTM commented 4 years ago

Hi @thebruce87m,

Thank you again for both reports, this one on GitHub and the other on the ST Community forum.

To answer your first question, I confirm that our STM32L4/L4+ HAL- and LL-driver source are MISRA C:2004 compliant. However, compliance does not necessarily mean strict and absolute conformity to all rules.

Regarding the way to perform MISRA C checks on our HAL- and LL-driver, there are no particular instructions. We use the check mechanism offered by IAR's IDE as briefly explained from page 5 to page 7 (Implementation and interpretation of the MISRA C rules) of this document.

Regarding the obtention of a MISRA C check report, it is possible under the condition a NDA (Non-Disclosure Agreement) is signed by the requester.

Please allow me now these few comments on the PC-Lint report you shared with the ST Community:

I hope you find in these explanations answers to your questions. Thank you once more for your reports. Take care and stay safe.

With regards,

thebruce87m commented 4 years ago

Thanks for the response. We are pursuing an NDA in order to get the X-CUBE-STL libraries so I will ask for the MISRA report once we have this.

Note that I am not the user on the forum that posted the report - as of the time of writing this I do not have any posts at all on the forum - but it was interesting to see your analysis.