This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

SDCard busy after several writes

Hi,

I've modified the SDCard example to write every 2 seconds 80 bytes to a SD Card. The SDCard is correctly mounted and the File is opened and kept open.

After several writes the program hangs being busy

And then the timer expires and the program crashes. I've tested with several SD Cards big and small and it did not change something. Furthermore, I've tested with several SDCARD Frequencies but same here. Is there any reason why the program hangs?

Parents
  • Hi,

    Can you provide minimal sample project that can be used to reproduce this issue?

    Best regards,
    Jørgen

  • Are you able to reproduce the issue by modifying the FatFS/SD Card example in the SDK?

  • Okay there several strange and undocumented things happening which you should take into your documentatio:

    1. If the Buffer you write is not a power of 2 it fails after the reaching the sector size.

    2. If the half of the sector size is reached the fatfs needs to be synced otherwise it stays busy.

    3. The f_sync call has to be in the main function in the while loop, while the write can be in a timer routine.

    Now I can write very fast about 256 bytes in chunks. But however if I reach 32512 it freezes again and the debugger says:

    That move window is called which means the sector window is moved. And therefore it needs to read from the disk and this does not return. Any idea why this happened?

    Best regards,

    Constantin

  • Okay solved now. The issue was related to the same undocumented issue before. If the cluster size is reached which is normally 32 kb the f_sync needs to shift the cluster. If during this sync a new write is called the fatfs freezes forever. This can only be handled if all write and sync operations are shifted to the main context and handled inside the while loop with flags.

    This is very uncomfortable and bad documented aswell. So please update the docu and make the example more explicitly for this case.

    Furthermore, the current implementation of the nrf_block_dev is not C++ compliant. Which was already stated in https://devzone.nordicsemi.com/f/nordic-q-a/21693/nrf_block_dev_sdc-h-c-compability and yet there was not solution nor work around for this issue. The only solution at the moment is to shift the NRF_BLOCK_DEV_SDC_DEFINE to an extra C file and write a init inside this c file which can be referenced in (extern "C") in a c++ class.

    Last but not least the app_sdcard does not use the SPIM module. Furthermore, I guess it would be a good  idead to use the spi_mngr for the SD card then I guess the syncing issue might be gone aswell.

    The issue can be closed although there is not yet a real solution.

Reply
  • Okay solved now. The issue was related to the same undocumented issue before. If the cluster size is reached which is normally 32 kb the f_sync needs to shift the cluster. If during this sync a new write is called the fatfs freezes forever. This can only be handled if all write and sync operations are shifted to the main context and handled inside the while loop with flags.

    This is very uncomfortable and bad documented aswell. So please update the docu and make the example more explicitly for this case.

    Furthermore, the current implementation of the nrf_block_dev is not C++ compliant. Which was already stated in https://devzone.nordicsemi.com/f/nordic-q-a/21693/nrf_block_dev_sdc-h-c-compability and yet there was not solution nor work around for this issue. The only solution at the moment is to shift the NRF_BLOCK_DEV_SDC_DEFINE to an extra C file and write a init inside this c file which can be referenced in (extern "C") in a c++ class.

    Last but not least the app_sdcard does not use the SPIM module. Furthermore, I guess it would be a good  idead to use the spi_mngr for the SD card then I guess the syncing issue might be gone aswell.

    The issue can be closed although there is not yet a real solution.

Children
Related