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

cpu/stm32f1: spi_transfer_bytes proper counting. #1630

Merged
merged 2 commits into from
Sep 3, 2014

Conversation

jnohlgard
Copy link
Member

The transferred bytes were being counted more than once because of a +=
when calling spi_transfer_byte().

This patch should also handle errors from spi_transfer_byte() better
since it is now possible to detect errors after the first byte has
been successfully sent.

I do not have a board to test on so I would need someone else to verify that this is correct.

The transferred bytes were being counted more than once because of a +=
when calling spi_transfer_byte().

This patch should also handle errors from spi_transfer_byte() better
since it is now possible to detect errors _after_ the first byte has
been successfully sent.

Signed-off-by: Joakim Gebart <joakim@gebart.se>
@LudwigKnuepfer
Copy link
Member

ACK for the logic.

@@ -128,7 +128,7 @@ int spi_transfer_bytes(spi_t dev, char *out, char *in, unsigned int length)
if (out != NULL) {
DEBUG("out*: %p out: %x length: %x\n", out, *out, length);
while (length--) {
ret += spi_transfer_byte(dev, *(out)++, 0);
ret = spi_transfer_byte(dev, *(out)++, 0);
Copy link
Member

Choose a reason for hiding this comment

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

I think you can reduce the scope of ret while you're here.
I.e.: make the delacration local to the while loops.

@LudwigKnuepfer
Copy link
Member

Tested, works.

Reduced scope to inside the while loop as per comments in RIOT-OS#1630

Signed-off-by: Joakim Gebart <joakim@gebart.se>
@jnohlgard
Copy link
Member Author

I reduced the scope to define ret inside the while loop.

@LudwigKnuepfer
Copy link
Member

ACK & go

LudwigKnuepfer added a commit that referenced this pull request Sep 3, 2014
cpu/stm32f1: spi_transfer_bytes proper counting.
@LudwigKnuepfer LudwigKnuepfer merged commit 9b361aa into RIOT-OS:master Sep 3, 2014
@jnohlgard jnohlgard deleted the stm32f1-spi-fix branch February 6, 2015 13:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Platform: ARM Platform: This PR/issue effects ARM-based platforms Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants