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

[example] Adding SpiFlash FatFs compatibility test #1057

Merged
merged 2 commits into from
Aug 16, 2023

Conversation

rasmuskleist
Copy link
Contributor

I have experimented with integrating FatFs with the BdSpiBlockDevice using fibers as discussed in #893 and #814. The example is for testing the compatibility of the physical drive with FatFs and is adapted from elm-chan. I have tested the example on the STM32G491MET6 on my local setup, but have added the example in the same location as the remaining flash examples.

Currently, the example blocks at disk_read in the "Single sector write test (unaligned buffer address)". I have tried to debug this issue and have found that pbuff+3 in dr = disk_write(pdrv, pbuff+3, lba, 1); causes the subsequent call to disk_read to block inside spiOperation() and specifically at RF_CALL(Spi::transfer(const_cast<uint8_t*>(tx), rx, length));. I must admit that I am quite dumbfounded by this bug and do not really know where to start. Do you have any suggestions to why this bug is occring? At this point I am a little bit lost.

@rasmuskleist rasmuskleist force-pushed the example-spiflash-fatfs branch 3 times, most recently from 02c3294 to 0f55145 Compare August 15, 2023 17:57
@rasmuskleist
Copy link
Contributor Author

I am not quite sure what the problem was, but my suggestion is that my local cmake setup did not add the ffconf_local.hpp to overwrite the FF_MAX_SS. As a consequence the buffer size was only 512b although I expected 4096. Why this first caused problems when adding to the buffer pointer, is probably because I had allocated a 4096 byte stack for the fiber, but this is just guessing. At least the example is now working and should demonstrate that FatFs can be used resumably with fibers!

Also, It occured to me that the flipping of the waitWhileBusy() in #1054 is wrong. It does not wait for program/erase to finish if multiple erase/program are performed in the loops. The test I wrote does not catch this mistake because it programs the flash in page size blocks... Sorry for this!

@rasmuskleist rasmuskleist marked this pull request as ready for review August 15, 2023 18:17
Copy link
Member

@salkinium salkinium left a comment

Choose a reason for hiding this comment

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

Thanks for the super awesome example!!! It's fantastic that this actually works so well! (Sorry that I wasn't helpful here, full-time work keeps me quite busy)

The test I wrote does not catch this mistake because it programs the flash in page size blocks... Sorry for this!

Don't sweat it, I made/make many mistakes too. You're PRs are always very high quality!

examples/nucleo_f429zi/spi_flash_fatfs/main.cpp Outdated Show resolved Hide resolved
@rasmuskleist rasmuskleist force-pushed the example-spiflash-fatfs branch from 0f55145 to 74f9cad Compare August 16, 2023 07:13
@rasmuskleist
Copy link
Contributor Author

Thanks for the nice comments! Yeah I am quite happy it was so smoothless. Next step will be to mount the drive and read/write files. I can possibly contribute a rudimentary example of this in a later PR if you wish?

@salkinium
Copy link
Member

I can possibly contribute a rudimentary example of this in a later PR if you wish?

Sure, that would be great!

@salkinium salkinium merged commit 74f9cad into modm-io:develop Aug 16, 2023
@salkinium salkinium added this to the 2023q3 milestone Aug 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

2 participants