This error is found on the STM32G071 but is likely on other devices too.
Ref AN4286 (rev 12) - Section 2, page 8, last paragraph:
"When the slave must transmit data, the master sends its clock, so it must transmit data on the MOSI line to be able to receive slave data on the MISO line. In this case, the master must always send 0x00 (datum not used by the slave)."
Unfortunately HAL_SPI_Receive() sends the data pointed to by the receive buffer pointer. So this is likely to be random data if the receive buffer has not been initialised (or used for something else previously).
In practice I have only seen a problem with this occasionally with BL_ReadMemory_Command(). The read command will succeed but a subsequent command (in my case a write) will fail on the initial command sequence. Took a while to find the bug as it did not happen with most data. ;)
The solution is to use HAL_SPI_TransmitReceive() instead with a zero'd dummy tx buffer.
Alternatively re-write the HAL_SPI_Receive() so it just sends zeros if memory use is an issue.
hth.
This error is found on the STM32G071 but is likely on other devices too.
Ref AN4286 (rev 12) - Section 2, page 8, last paragraph: "When the slave must transmit data, the master sends its clock, so it must transmit data on the MOSI line to be able to receive slave data on the MISO line. In this case, the master must always send 0x00 (datum not used by the slave)." Unfortunately HAL_SPI_Receive() sends the data pointed to by the receive buffer pointer. So this is likely to be random data if the receive buffer has not been initialised (or used for something else previously). In practice I have only seen a problem with this occasionally with BL_ReadMemory_Command(). The read command will succeed but a subsequent command (in my case a write) will fail on the initial command sequence. Took a while to find the bug as it did not happen with most data. ;) The solution is to use HAL_SPI_TransmitReceive() instead with a zero'd dummy tx buffer. Alternatively re-write the HAL_SPI_Receive() so it just sends zeros if memory use is an issue. hth.