Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use of HAL_SPI_Receive() can cause errors #8

Open
tobydesignerds opened this issue Mar 28, 2023 · 2 comments
Open

Use of HAL_SPI_Receive() can cause errors #8

tobydesignerds opened this issue Mar 28, 2023 · 2 comments

Comments

@tobydesignerds
Copy link

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.

@blueduckjf
Copy link

Thanks, I am glad I caught this early.

@shibbs
Copy link

shibbs commented Jun 24, 2024

Had this issue as well, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants