AnsweredAssumed Answered

Years on, continue to see the same bad timeout code

Question asked by Clive Two.Zero on May 30, 2018
Latest reply on May 30, 2018 by dhenry

I've railed on this before, but it keeps getting into the HAL code base. Can someone in charge of managing the software group please explain to the team members who keep using this construct what is wrong with it.. This shouldn't be a lesson that needs to be repeated. It shouldn't be my job to walk the code.

 

STM32Cube_FW_L4_V1.11.0\Projects\32L4R9IDISCOVERY\Demonstrations\MenuLauncher\Core\Src\sd_diskio_dma.c

 

DRESULT SD_read(BYTE lun, BYTE *buff, DWORD sector, UINT count)
{
  DRESULT res = RES_ERROR;
  ReadStatus = 0;
  uint32_t timeout;

 

  if(BSP_SD_ReadBlocks_DMA((uint32_t*)buff,
                           (uint32_t) (sector),
                           count) == MSD_OK)
  {
    /* Wait for the Rading process is completed or a timeout occurs */
    timeout = HAL_GetTick() + SD_TIMEOUT;
    while((ReadStatus == 0) && (HAL_GetTick() < timeout))
    {
      __NOP();
    }

...

 

Found this in at least half a dozen files, and might well exists in other timeout loops.

 

Here done correctly

 

STM32Cube_FW_L4_V1.11.0\Projects\STM32L4R9I-EVAL\Applications\FatFs\FatFs_uSD_DMA_Standalone\Src\sd_diskio_dma.c

 

  if(BSP_SD_ReadBlocks_DMA((uint32_t*)buff,
                           (uint32_t) (sector),
                           count) == MSD_OK)
  {
    /* Wait for the Rading process is completed or a timeout occurs */
     timeout = HAL_GetTick();
    while((ReadStatus == 0) && ((HAL_GetTick() - timeout) < SD_TIMEOUT))
    {
    }

...

 

This is not a concept that is hard to grasp, identify the individuals who write those lines of code, they poison the repository. Can we have team members who can sight read code properly check off code from individuals that can't.

Outcomes