STMicroelectronics / stm32f4xx-hal-driver

Provides the STM32Cube MCU Component "hal_driver" of the STM32F4 series.
BSD 3-Clause "New" or "Revised" License
119 stars 50 forks source link

Add support for Half-Duplex SPI as described in RM0090 Section 28.3.8 #10

Closed sgauche closed 1 year ago

sgauche commented 2 years ago

Caution

The Issues are strictly limited for the reporting of problem encountered with the software provided in this project. For any other problem related to the STM32 product, the performance, the hardware characteristics and boards, the tools the environment in general, please post your report to the ST Community in the STM32 MCUs dedicated page.

Describe the set-up

Describe the bug (skip if none)

When using SPI in half-duplex mode, the SPI is not disabled at the appropriate time during a read as described in RM0090 Section 28.3.8 so an extra transaction is started.

In master unidirectional receive-only mode (MSTR=1, BIDIMODE=0,
RXONLY=1) or bidirectional receive mode (MSTR=1, BIDIMODE=1, BIDIOE=0)
This case must be managed in a particular way to ensure that the SPI does not initiate a
new transfer. The sequence below is valid only for SPI Motorola configuration (FRF bit set to
0):
1. Wait for the second to last occurrence of RXNE=1 (n–1)
2. Then wait for one SPI clock cycle (using a software loop) before disabling the SPI
(SPE=0)
3. Then wait for the last RXNE=1 before entering the Halt mode (or disabling the
peripheral clock)

How to reproduce the bug (skip if none)

call HAL_SPI_Receive after a HAL_SPI_Transmit with hspi->Init.Direction == SPI_DIRECTION_1LINE

Additional context

Screenshots

ASELSTM commented 1 year ago

ST Internal Reference: 156227

ASELSTM commented 1 year ago

Hi @sgauche,

To ensure that the SPI does not initiate a new transfer you should call HAL_SPI_DeInit() and HAL_SPI_Init() before starting a new master receive. This is actually mentioned within the the stm32f4xx_hal_spi driver in the section "How to use this driver".

https://github.com/STMicroelectronics/stm32f4xx_hal_driver/blob/b0adc88696d491e49086bf995eb24bfd435af284/Src/stm32f4xx_hal_spi.c#L64-L69

Would you please thus make sur that you are executing these instructions in your code.

With regards,

ASELSTM commented 1 year ago

Hi @sgauche,

Please allow me to close this thread as no activity. You may reopen it at anytime if you have any details to share with us in order to help you to solve the issue. Thank you for your comprehension.

With regards,