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

About nRF52840 save file error

Hi all:

Currently, when using nRF52840 for archiving applications, I will encounter a condition and this will result in data corruption.

And I found a way to reproduce the problem using official tools. Does anyone have the same situation as me?

Test board: PCA10056

Software example: usbd_msc_pca10056 (SDK15.2/15.3/16.0 test results are the same)

1.

static void fatfs_file_create(void) function is changed to the following within the example Code usbd_msc_pca10056:

static void fatfs_file_create(void)

{

FRESULT ff_result;

FIL file;

char filename[16];

char demo_buff[256];

uint32_t byteswritten;

if (m_usb_connected)

{

NRF_LOG_ERROR("Unable to operate on filesystem while USB is connected");

return;

}

//(void)snprintf(filename, sizeof(filename), "%08x.txt", rand());

(void)snprintf(filename, sizeof(filename), "data/demo.txt");

NRF_LOG_RAW_INFO("Creating random file: %s ...", (uint32_t)filename);

NRF_LOG_FLUSH();

ff_result = f_open(&file, filename, FA_CREATE_ALWAYS | FA_WRITE);

if (ff_result != FR_OK)

{

NRF_LOG_ERROR("\r\nUnable to open or create file: %u", ff_result);

NRF_LOG_FLUSH();

return;

}

//debug...

for(uint16_t i=0;i<256;i++)

{

demo_buff[i] = i;

}

for(uint16_t i=0;i<96;i++)

{

ff_result = f_write( &file , demo_buff , 256 , &byteswritten );

if(ff_result == FR_OK)

{

NRF_LOG_RAW_INFO("file write success:%d\r\n",byteswritten);

}

else

{

NRF_LOG_RAW_INFO("file write error\r\n");

}

NRF_LOG_FLUSH();

ff_result = f_sync(&file);

if(ff_result != FR_OK)

{

NRF_LOG_RAW_INFO("file synced error\r\n");

}

}

//debug...

ff_result = f_close(&file);

if (ff_result != FR_OK)

{

NRF_LOG_ERROR("\r\nUnable to close file: %u", ff_result);

NRF_LOG_FLUSH();

return;

}

NRF_LOG_RAW_INFO("done\r\n");

}

Change the file created in the example to the /data folder, the name is fixed to DEMO.txt, the content is 0x00~0xFF and repeats 96 times, and each time the round is finished, f_sync is used to synchronize the process of writing the file. .

The file content generated at this time is normal.

PS:

a. Configure the unit size when formatting. I choose 2048 bytes.

b. After formatting, you need to add a data folder to the space yourself, otherwise you will not be able to generate files.

c. Erase all reproduce the problem before burning will be relatively stable.

2.

Delete m_block_dev_ram / m_block_dev_empty in BLOCKDEV_LIST(), leaving only m_block_dev_qspi as follows:

#define BLOCKDEV_LIST() ( \

NRF_BLOCKDEV_BASE_ADDR(m_block_dev_qspi, block_dev) \

)

The regenerated file content will appear. The block content of 512 bytes is not 0x00~0xFF, but is 0 or garbled.

3. Try to add the 2 lines deleted in step 2, as follows:

#define BLOCKDEV_LIST() ( \

NRF_BLOCKDEV_BASE_ADDR(m_block_dev_ram, block_dev), \

NRF_BLOCKDEV_BASE_ADDR(m_block_dev_empty, block_dev), \

NRF_BLOCKDEV_BASE_ADDR(m_block_dev_qspi, block_dev), \

)

The regenerated file content will return to normal.

Parents
  • Hi,

    Configure the unit size when formatting. I choose 2048 bytes.

    Does it help to set the file allocation unit parameter in f_mkfs() from 1024 to 2048 ?


    3. Try to add the 2 lines deleted in step 2, as follows:
    The regenerated file content will return to normal.

     So this fixed the issue, correct ?

  • Hi,

    The proposed method is mainly to reproduce the problem.
    What I want to know is the reason for this problem.


    For example, as you mentioned,
    1. The question is: Is the f_mkfs() parameter different from the PC formatting settings option?
    But I don’t seem to affect when I don’t delete those two lines.

    2. Or when I delete those two lines will cause fatfs to be disturbed?
    I only want to see the QSPI DISK when I connect to the PC, so I choose to delete those two lines, or have other methods that don't have to be deleted but can be disabled by the PC?

    If I don't understand the reason, I can't guarantee that the follow-up development will not repeat itself.

Reply
  • Hi,

    The proposed method is mainly to reproduce the problem.
    What I want to know is the reason for this problem.


    For example, as you mentioned,
    1. The question is: Is the f_mkfs() parameter different from the PC formatting settings option?
    But I don’t seem to affect when I don’t delete those two lines.

    2. Or when I delete those two lines will cause fatfs to be disturbed?
    I only want to see the QSPI DISK when I connect to the PC, so I choose to delete those two lines, or have other methods that don't have to be deleted but can be disabled by the PC?

    If I don't understand the reason, I can't guarantee that the follow-up development will not repeat itself.

Children
Related