2021-09-08 02:55 PM
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.)
2021-09-08 05:02 PM
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
2021-09-08 06:50 PM
> 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.
2021-09-08 07:38 PM
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.
2022-05-24 01:35 AM
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!