cancel
Showing results for 
Search instead for 
Did you mean: 

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

Pavel A.
Evangelist III

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

1 ACCEPTED SOLUTION

Accepted Solutions
Pavel A.
Evangelist III

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 😉

View solution in original post

2 REPLIES 2
TDK
Guru

"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.

If you feel a post has answered your question, please click "Accept as Solution".
Pavel A.
Evangelist III

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 😉