Skip to main content
Super User
December 26, 2021
Solved

SPI clock polarity in the STM32H7 Cube library, HAL vs LL [SOLVED]

  • December 26, 2021
  • 1 reply
  • 1638 views

Dear experts,

I'm having a weird issue with SPI initialization on STM32H743/753 .

The device connected to the SPI master needs HIGH clock polarity (CPOL). So we clicked this in CubeMX, and the generated code indeed has "hspi1.Init.CLKPolarity    = SPI_POLARITY_HIGH" and it works.

Then we switched to LL for the SPI. The LL variant is obviosly

" SPI_InitStruct.ClockPolarity   = LL_SPI_POLARITY_HIGH;"

But now it fails, and works if we change it to LL_SPI_POLARITY_LOW!

Has anybody seen this behavior? H7 HAL library v 1.9.0

    This topic has been closed for replies.
    Best answer by Pavel A.

    Figured it out (I guess). POLARITY_HIGH with PHASE_2EDGE behaves with my device close enough to POLARITY_LOW with PHASE_1EDGE.

    The other guy who does LL changed also 2EDGE to 1EDGE.

    So there's no bug in the ST library ;)

    1 reply

    Super User
    December 26, 2021

    "works" doesn't imply correct. Look at the signal on the line to see what it's doing, or examine the registers.

    Could be an issue where the SPI isn't initialized before you drop CS and causes an extra clock.

    Pavel A.AuthorAnswer
    Super User
    January 4, 2022

    Figured it out (I guess). POLARITY_HIGH with PHASE_2EDGE behaves with my device close enough to POLARITY_LOW with PHASE_1EDGE.

    The other guy who does LL changed also 2EDGE to 1EDGE.

    So there's no bug in the ST library ;)