cancel
Showing results for 
Search instead for 
Did you mean: 

SPI "Receive Only Master" doesn't work with DMA

BMcDo.3
Associate III

In STM32CubeMX, version 6.3.0, using STM32CubeF4 v1.25.2, when a SPI port is set to mode "Receive Only Master", it sets `hspi#.Init.Direction = SPI_DIRECTION_2LINES_RXONLY;` in generated code, as (I think) it should. However, the generated code doesn't work for DMA mode (`HAL_SPI_Receive_DMA()`). The SCK doesn't shut off at the end of the requested transfer, and the `HAL_SPI_RxCpltCallback()` interrupt handler doesn't hit.

If I set the SPI mode in CubeMX as "Full-Duplex Master", then manually change `hspi#.Init.Direction = SPI_DIRECTION_2LINES;` to `SPI_DIRECTION_2LINES_RXONLY` in the generated `MX_SPI#_Init()`, the bad behavior is the same. I can optionally remove the call to `HAL_GPIO_Init()` for the MOSI line, and it still works, though.

Is this an issue with the CubeMX-generated code, the HAL, and/or the Silicon itself?

(I realize I'm not using the latest CubeF4 HAL, and we're working on updating that. Meanwhile, I checked the diff against the latest, and didn't spot any seemingly relevant changes.)

4 REPLIES 4

Rx-only SPI is tricky, and Cube/HAL does not help at all.

> I can optionally remove the call to `HAL_GPIO_Init()` for the MOSI line, and it still works, though.

Use that.

JW

> Rx-only SPI is tricky, and Cube/HAL does not help at all.

Thanks for the info.

I still think CubeMX should be generating (and HAL supporting) working code. Or at the absolute very least, disable the option for which it cannot generate working code, and point users to info about it.

> > I can optionally remove the call to `HAL_GPIO_Init()` for the MOSI line, and it still works, though.

> Use that.

I'm going to do that for now. But I hope they can fix it.

S.Ma
Principal

Always tell which mcu as each peripheral IP has different generations. 2 Lane works best. You need to use transmitreceive function, even if you send garbage to a pin which is not activated as the transmit drives the clock.

BOzge.1
Associate

Had the same issue and fixed it by switching to full-duplex mode as mentioned above. This was very frustrating to debug and I hope ST fixes this in CubeIDE!