slave spi on stm32f4 receives incorrect data
I have an jetson xavier driving STM32F407G-DISC1 on SPI1 default pins : PA4/5/6/7 .
The SPI_FLAG_RXNE flag behaviour is very strange, resulting in wrong values being received.
Config used:
/* SPI1 parameter configuration*/
hspi1.Instance = SPI1;
hspi1.Init.Mode = SPI_MODE_SLAVE;
hspi1.Init.Direction = SPI_DIRECTION_2LINES;
hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
hspi1.Init.NSS = SPI_NSS_HARD_INPUT;
hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
In these plots CH3 is connected to a gpio that tracks SPI_FLAG_RXNE, while CH4 is connected to !SPI_FLAG_BSY .
What I expect to see is SPI_FLAG_RXNE firing with the rising edge of SCK on the reception of the 8th bit like this:

However with this SPI driver the SPI_FLAG_RXNE signal seems to look like this:

Result is wrong data received. This happens independent of SCK speed. Validated the STM32 slave inputs using a simple bitbang SPI slave, and data is received with no errors.
SPI_FLAG_RXNE and !SPI_FLAG_BSY were brought out to gpio with something like:
volatile uint8_t rxd = 0;
while(true) {
uint32_t spiFlags = hspi->Instance->SR;
bool is_free = ! (spiFlags & SPI_FLAG_BSY);
bool is_rx_buffer_ready = (spiFlags & SPI_FLAG_RXNE);
set_gpio_led(led_orange, is_free);
set_gpio_led(led_green, is_rx_buffer_ready);
if (is_rx_buffer_ready) {
small_delay();
rxd = hspi->Instance->DR;
}
}