SPI4 RXNE never raises on STM32G4
Hello, my project is using all 4 SPI interfaces on the STM32G474. SPI1-3 all work flawlessly, but SPI4 never triggers the RXNE flag. All SPI buses are configured identically, with the only differences being the pinouts and APB1 vs 2 bus. I am polling the transactions directly.
Initialization:
if (hspi_.Instance == SPI1)
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_SPI1);
else if (hspi_.Instance == SPI2)
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_SPI2);
else if (hspi_.Instance == SPI3)
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_SPI3);
else if (hspi_.Instance == SPI4)
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_SPI4);
LL_SPI_SetMode(hspi_.Instance, LL_SPI_MODE_MASTER);
LL_SPI_SetTransferDirection(hspi_.Instance, LL_SPI_FULL_DUPLEX);
LL_SPI_SetDataWidth(hspi_.Instance, LL_SPI_DATAWIDTH_8BIT);
LL_SPI_SetClockPolarity(hspi_.Instance, LL_SPI_POLARITY_LOW);
LL_SPI_SetClockPhase(hspi_.Instance, LL_SPI_PHASE_1EDGE);
LL_SPI_SetBaudRatePrescaler(hspi_.Instance, LL_SPI_BAUDRATEPRESCALER_DIV256);
LL_SPI_SetTransferBitOrder(hspi_.Instance, LL_SPI_MSB_FIRST);
LL_SPI_SetStandard(hspi_.Instance, LL_SPI_PROTOCOL_MOTOROLA);
LL_SPI_SetNSSMode(hspi_.Instance, LL_SPI_NSS_SOFT);
SET_BIT(hspi_.Instance->CR1, SPI_CR1_SSI);
LL_SPI_SetRxFIFOThreshold(hspi_.Instance, LL_SPI_RX_FIFO_TH_QUARTER);
LL_SPI_DisableNSSPulseMgt(hspi_.Instance);
LL_SPI_DisableCRC(hspi_.Instance);
LL_SPI_Enable(hspi_.Instance);
Transfer:
void write(uint8_t* data, size_t len) {
for (uint16_t i = 0; i < len; i++)
{
while (!LL_SPI_IsActiveFlag_TXE(hspi_.Instance)) {}
LL_SPI_TransmitData8(hspi_.Instance, data[i]);
while (!LL_SPI_IsActiveFlag_RXNE(hspi_.Instance)) {}
(void)LL_SPI_ReceiveData8(hspi_.Instance);
}
while (LL_SPI_IsActiveFlag_BSY(hspi_.Instance)) {}
return;
}
For SPI1-3, write works fine. For SPI4, it hangs on the while RXNE wait forever.
I verified SPI4 is enabled (check RCC_APB2ENR) and not held in reset (check RCC_APB2RSTR):
# RCC_APB2ENR SPI4_EN
(gdb) p/x *0x40021060 >> 15 & 1
$25 = 0x1
# RCC_APB2RSTR SPI4_RST
(gdb) p/x *0x40021040 >> 15 & 1
$20 = 0x0I can reproduce this across multiple boards and eval boards. Any idea what is wrong?
