Skip to main content
Visitor II
March 10, 2021
Solved

Bug in Low-Level driver LL_SPI_ReceiveData8 for STM32L0, STM32L4, STM32L5 and possibly others

  • March 10, 2021
  • 2 replies
  • 2107 views

Affected driver libraries: STM32Cube_FW_L5_V1.4.0, STM32Cube_FW_L4_V1.16.0, STM32Cube_FW_L0_V1.11.2 and possibly other device driver libraries based on the same SPI peripheral

File: stm32yyxx_ll_spi.h (Replace yy by L5, L4, F0, ...)

Functions affected: LL_SPI_ReceiveData8

Bug: Current implementation performs a 16bit read access to DR register and then casts the result to 8 bits. This leads to unexpected behavior. For example STM32L5 supports data packing, when SPI data frame size is less than or equal to 8 bits and 16 bits are read. In this case, the current implementation of LL_SPI_ReceiveData8 reads two (packed) bytes from DR register and discards the second one when casting the read result to 8 bits.

Correct implementation: Cast pointer to DR register to uint8_t before access.

__STATIC_INLINE uint8_t LL_SPI_ReceiveData8(SPI_TypeDef *SPIx)

{

  return *((__IO uint8_t *)&SPIx->DR)

}

    This topic has been closed for replies.
    Best answer by SOfne.1

    Hi @Imen DAHMEN​ 

    Thank you.

    As you can see in the corresponding git repository for STM32CubeF0 firmware package this issue is still present in STM32CubeF0 V1.11.2.

    Best regards,

    Sebastian

    2 replies

    Technical Moderator
    March 10, 2021

    Hello @SOfne.1​  and welcome to the STM32 Community :)

    Thanks for pointing out this issue.

    I am checking it internally and I will come back to you with details about corrective actions we will take, or explanation if needed.

    Imen

    Technical Moderator
    March 18, 2021

    ​Hi @SOfne.1​ ,

    This issue will be fixed in the coming release of STM32CubeL5 MCU package.

    Thanks for your contribution.

    Imen

    SOfne.1Author
    Visitor II
    March 22, 2021

    Hi @Imen DAHMEN​ 

    Thanks for your fast response. Will this issue be fixed in the next releases of STM32CubeF0 and STM32CubeL4 MCU package, too?

    Best regards,

    Sebastian

    Technical Moderator
    March 25, 2021

    Hi @SOfne.1​,

    You are right, only LL_SPI_TransmitData8() is correct in the latest CubeF0. I've escalated this issue to correct LL_SPI_ReceiveData8() API.

    The same correction will be performed for all impacted series.

    Imen