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

check alignment for DMA buffers #17

Merged

Conversation

tsandmann
Copy link
Contributor

I really like the idea of using DMA to access the SD card, but you should check the user-supplied buffers to SDHC_CardReadBlock(() and SDHC_CardWriteBlock() for a correct alignment to prevent data corruption. The least 2 significant bits of SDHC_DSADDR are always 0 on a K66 device, therefore the buffer address has to be 4 byte aligned.

@FrankBoesing
Copy link
Contributor

no need to check it this way.. if you just delete the lower bits the program will crash too because it will overwrite other variables.

@tsandmann
Copy link
Contributor Author

no need to check it this way.. if you just delete the lower bits the program will crash too because it will overwrite other variables.

but SDHC_CardWriteBlock() would write wrong data to the SD card then resulting in corrupted data on the card.

@FrankBoesing
Copy link
Contributor

Yes, It does writes wrong data, if you move the buffer... and the user does not know about it. So where is this better?

@FrankBoesing
Copy link
Contributor

its even worse.

@tsandmann tsandmann deleted the bugfixes/dma_alignment branch March 18, 2019 19:31
@tsandmann
Copy link
Contributor Author

Yes, that's why it just checks the alignment and returns -1 to inform the user, if the alignment is wrong. Or do I miss anything here?

@FrankBoesing
Copy link
Contributor

FrankBoesing commented Mar 18, 2019

oops, forgot about the return.. you're right. forget it.

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

Successfully merging this pull request may close these issues.

None yet

3 participants