-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Fix dropped bytes on spi write #11660
Conversation
The cyhal_spi_send api was changed to read and discard a byte on every send operation (at the protocol level all SPI transfers are bidirectional). This means that to achieve a truly bidirectional transfer, the cyhal_spi_transfer API must be called (as opposed to a write followed by a read).
@shuopeng-deng, thank you for your changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This wouldn't be quite right if configured for > 8-bit transfers, but not sure this HAL (or even the Mbed OS core) correctly supports that case anyway. (There's a seperate SPI feature branch which I believe is looking at that, among other things).
Correct, master_write is for 8bit transfer only. |
None of that is specified - some of the code suggests that the intent is that it work, and there's no reason it shouldn't. ( The SPI feature branch drops that HAL API anyway, and sends it all through And tests it. I don't think any of this is tested on master. |
I was just checking the docs : @shuopeng-deng Is this fix correct - cypress driver states it supports 8 or 16 bits (format function docs). |
Don't think so - despite the name |
The proper fix would be then as it is, but also support 2 bytes transfer (based on bits set via |
You could basically cheat and rely on the little-endianness - just make both (This trick working is why little-endianness is the one true endianness). That's how |
remove an unnecessary cast
CI started |
Test run: SUCCESSSummary: 11 of 11 test jobs passed |
} | ||
if (CY_RSLT_SUCCESS != cyhal_spi_recv(&(spi->hal_spi), &received)) { | ||
MBED_ERROR(MBED_MAKE_ERROR(MBED_MODULE_DRIVER_SPI, MBED_ERROR_CODE_FAILED_OPERATION), "cyhal_spi_recv"); | ||
int received; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It occurred to me after writing my previous little-endian hack suggestion that you do need to initialise received
to 0, as the transfer call will only fill in the bottom byte in the 8-bit case (or 2 bytes in 9-16 bit).
Can you please make that tweak?
@shuopeng-deng Please review above suggestion |
Description
The cyhal_spi_send api was changed to read and discard a byte on every
send operation (at the protocol level all SPI transfers are bidirectional).
This means that to achieve a truly bidirectional transfer, the
cyhal_spi_transfer API must be called (as opposed to a write followed
by a read).
GreenTea_CY8CKIT_062S2_43012_GCC_ARM.txt
GreenTea_CY8CPROTO_062_4343W_GCC_ARM.txt
Pull request type
Reviewers
@ARMmbed/team-cypress
Release Notes