Skip to main content
Lukas1
Associate II
April 2, 2020
Solved

changing SPI-settings ends up in HAL-Timeout

  • April 2, 2020
  • 1 reply
  • 906 views

Hi,

I have to change the CPOL and CPHA of SPI, because I'm communicating with different SPI-Devices. This worked fine on a Nucleo-Board with a Cortex M7.

On the Cortex M4 of the STM32MP157-DK2 it ends up in HAL-Timeout :(

After some time I found a solution.

I added this in front of the code changing the SPI-settings:

HAL_SPI_DeInit(&hspi5);
HAL_SPI_Init(&hspi5);
 
/** code to change settings of CPOL und CPHA **/

Now it works perfectly fine :)

My question is now: why?

regards

Lukas

This topic has been closed for replies.
Best answer by PatrickF

Hi,

You did not mention how do you change the settings ?

HAL initialization are usually not intended to be issue more than one time, so it is recommended to use DeInit() as you mention.

in STM32MP15x Reference Manual, it is clearly stated you cannot change CPOL/CPHA once the SPI is enabled.

           Note: Prior to changing the CPOL/CPHA bits the SPI must be disabled by resetting the SPE bit.

You can also directly play with IP registers (if you see this as allowed according to Reference Manual).

You have many SPI related fonctions in stm32mp1xx_ll_spi.h (e.g. LL_SPI_Disable(), LL_SPI_SetClockPolarity(), LL_SPI_SetClockPhase(), LL_SPI_Enable(), etc...).

Cortex-M7 device you mention likely uses different SPI and SW versions, so I have no explanation why it was working (have you checked the related Reference Manual ?)

1 reply

PatrickF
PatrickFBest answer
Technical Moderator
April 2, 2020

Hi,

You did not mention how do you change the settings ?

HAL initialization are usually not intended to be issue more than one time, so it is recommended to use DeInit() as you mention.

in STM32MP15x Reference Manual, it is clearly stated you cannot change CPOL/CPHA once the SPI is enabled.

           Note: Prior to changing the CPOL/CPHA bits the SPI must be disabled by resetting the SPE bit.

You can also directly play with IP registers (if you see this as allowed according to Reference Manual).

You have many SPI related fonctions in stm32mp1xx_ll_spi.h (e.g. LL_SPI_Disable(), LL_SPI_SetClockPolarity(), LL_SPI_SetClockPhase(), LL_SPI_Enable(), etc...).

Cortex-M7 device you mention likely uses different SPI and SW versions, so I have no explanation why it was working (have you checked the related Reference Manual ?)

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.NEW ! Sidekick STM32 AI agent, see here