STM32: Change SPI Read to acknowledge write_value #3431
Merged
+12
−4
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Some SPI devices on STM32 have been having difficulty connecting, particularly SD cards and some breakouts such as the NRF24L01. This is because the STM32 HAL does not have defined behavior for its output pin (MOSI) when performing Reads - SD cards and the NRF24L01 require specific values such as 0xFF or a key value, but during a
HAL_SPI_Receive
, this line will typically just be random junk. This is supposed to be handled by setting thewrite_value
parameter - however, the STM32 port previously ignored this value since it was based off NRF52, which also does not use it.This PR switches the HAL function to HAL_SPI_TransmitReceive, which maintains both lines, so it can use
write_value
. This requires adding a memset of lengthlen
to preparewrite_value
to be issued as outgoing data, which may reduce performance somewhat at fast SPI speeds.This probably should also be done on the ESP32-S2 port, which appears to be having similar difficulties with SD cards. I'm not entirely sure why it isn't an issue on the NRF52 - that port may have a default Logic 1 level for the output while reading, and special cases like the NRF24L01 may simply never have come up.
Thanks @jerryneedell for findig and @jepler for identifying and suggesting the code for this fix. Resolves #3176. Also adds a minor makefile change (ADD_CFLAGS variable) to assist debugging.