Bug in STM32 hal_spi_v2_lld.c Topic is solved

Report here problems in any of ChibiOS components. This forum is NOT for support.
CsZoli
Posts: 3
Joined: Thu Nov 10, 2022 11:42 am
Has thanked: 1 time
Been thanked: 2 times

Bug in STM32 hal_spi_v2_lld.c  Topic is solved

Postby CsZoli » Thu Nov 10, 2022 12:23 pm

Hi,

The bug exist in ChibiOS 21.11.2 at the following conditions
- Chibistudio 2022-01 with GCC 9.2.1.
- STM32F103
Bug visible when CPOL=1

on STM32 SPI clock line (SCK) is indefinit/tristate when SPI not enabled (SPE bit 0)
In the new v2 driver SPI is only enabled (SPE=1) during communication (spiexchange)
This cause incorrect operation as SPI clock line must be high when CS goes low (when CPOL=1).

My suggestion is to insert a spip->spi->CR1 |= SPI_CR1_SPE; at the end of spi_lld_start(SPIDriver *spip) function at row 216 in hal_spi_v2_lld.c:

/* SPI setup.*/
spi_lld_configure(spip);
spip->spi->CR1 |= SPI_CR1_SPE; // <- this line should added
return HAL_RET_SUCCESS;

With this mod clock line activated (goes high) after spiStart(...) so when spiSelect(..) pulls down CS line, start conditions are correct.

Regards
Zoltan

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: Bug in STM32 hal_spi_v2_lld.c

Postby Giovanni » Thu Nov 10, 2022 1:44 pm

Hi,

Thanks for finding, the problem is clear, note that SPIv2 and SPIv3 keep SPE enabled so this only happens in SPIv1 (the one used by F1 devices).

The fix is not sufficient, SPE would be still disabled after the 1st transfer and the problem would happen again on successive ones. Will post an update before next release.

Giovanni

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: Bug in STM32 hal_spi_v2_lld.c

Postby Giovanni » Tue Nov 15, 2022 6:41 pm

Hi,

I committed a fix on repository trunk, could you give it a try?

Giovanni

CsZoli
Posts: 3
Joined: Thu Nov 10, 2022 11:42 am
Has thanked: 1 time
Been thanked: 2 times

Re: Bug in STM32 hal_spi_v2_lld.c

Postby CsZoli » Sun Nov 20, 2022 5:59 pm

Hi Giovanni,

Yes, I can confirm it is working perfectly!
Also clock line remain high after transfer, as it should.
Thanks for your quick action!

Regards
Zoltan


Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 16 guests