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.