Skip to content

STM32: Change SPI Read to acknowledge write_value #3431

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

Merged
merged 1 commit into from
Sep 18, 2020
Merged

STM32: Change SPI Read to acknowledge write_value #3431

merged 1 commit into from
Sep 18, 2020

Conversation

hierophect
Copy link
Collaborator

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 the write_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 length len to prepare write_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.

@hierophect hierophect added the stm label Sep 16, 2020
@hierophect hierophect requested a review from jepler September 16, 2020 18:23
Copy link

@jepler jepler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! No testing performed on my end but this is much what I expected to see

@dhalbert
Copy link
Collaborator

dhalbert commented Sep 18, 2020

@hierophect Could you open issues for the suggestions in your third paragraph? Thanks.

@dhalbert dhalbert merged commit 8cf0171 into adafruit:main Sep 18, 2020
@hierophect hierophect deleted the stm32-spi-writevalue branch September 19, 2020 22:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

STM32: SPI.readinto ignores write_value, causes SD cards not to detect
3 participants