looking for a sample, to have writing a file onto the SD-CARD, that a PC will understand

Hi,

I managed to have the fat_fs sample to work.

Now i would like to be able to write and read files,  onto the SD-CARD, that a PC will understand, it seems to  needs some more then 

the  disk_access_write(),  disk_access_read()  of the fat_fs,    Correct?
What do i need to look into,  to have data to be written onto the SD-card? , such that the PC does understand.
Best Regards,
Theo
Parents
  • Hi,

    You should be able to use a similar approach as the FatFS example in nRF5 SDK uses to write a text file to the SD-card:

    #define FILE_NAME   "NORDIC.TXT"
    #define TEST_STRING "SD card example."
    
    ...
    
    ff_result = f_open(&file, FILE_NAME, FA_READ | FA_WRITE | FA_OPEN_APPEND);
    if (ff_result != FR_OK)
    {
    	NRF_LOG_INFO("Unable to open or create file: " FILE_NAME ".");
    	return;
    }
    
    ff_result = f_write(&file, TEST_STRING, sizeof(TEST_STRING) - 1, (UINT *) &bytes_written);
    if (ff_result != FR_OK)
    {
    	NRF_LOG_INFO("Write failed\r\n.");
    }
    else
    {
    	NRF_LOG_INFO("%d bytes written.", bytes_written);
    }
    
    (void) f_close(&file);

    Note that Zephyr provides a common FS API for the different file systems, so you should replace "f_" with "fs_", and replace the return code checks with the corresponding Zephyr error codes.

    Best regards,
    Jørgen

Reply
  • Hi,

    You should be able to use a similar approach as the FatFS example in nRF5 SDK uses to write a text file to the SD-card:

    #define FILE_NAME   "NORDIC.TXT"
    #define TEST_STRING "SD card example."
    
    ...
    
    ff_result = f_open(&file, FILE_NAME, FA_READ | FA_WRITE | FA_OPEN_APPEND);
    if (ff_result != FR_OK)
    {
    	NRF_LOG_INFO("Unable to open or create file: " FILE_NAME ".");
    	return;
    }
    
    ff_result = f_write(&file, TEST_STRING, sizeof(TEST_STRING) - 1, (UINT *) &bytes_written);
    if (ff_result != FR_OK)
    {
    	NRF_LOG_INFO("Write failed\r\n.");
    }
    else
    {
    	NRF_LOG_INFO("%d bytes written.", bytes_written);
    }
    
    (void) f_close(&file);

    Note that Zephyr provides a common FS API for the different file systems, so you should replace "f_" with "fs_", and replace the return code checks with the corresponding Zephyr error codes.

    Best regards,
    Jørgen

Children
Related