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

FATFS+QSPI+USBmsc bug

hello,nordic

    I use NRF52840 QSPI+FatFs+USB-msc(..\nRF5_SDK_15.2.0_9412b96\nRF5_SDK_15.2.0_9412b96\examples\peripheral\usbd_msc),I found there is a bug about write to flash and read from falsh.

bug description: 

nrfx_err_t nrfx_qspi_write(void const * p_tx_buffer,size_t tx_buffer_length,uint32_t dst_address);

nrfx_err_t nrfx_qspi_read(void * p_rx_buffer,size_t rx_buffer_length,uint32_t src_address);

If the p_tx_buffer and p_rx_buffer addresses are not four-byte aligned, the read data will be different from the previously written data.

In  NRF52840 QSPI+FatFs+USB-msc this example didn't process the address alingment .I test the example like this


uint8_t a[9] = {0,1,2,4,8};
uint8_t file_buf[599] = {1,2,3,4,5,6,7,8,9,10};
static void fatfs_file_create(void)
{
FRESULT ff_result;
FIL file;
char filename[16];
uint32_t bww;

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());

NRF_LOG_RAW_INFO("Creating random file: %s ...file_buf addr:%x,a :%x", (uint32_t)filename, file_buf, a);
NRF_LOG_FLUSH();

ff_result = f_open(&file, filename, FA_WRITE | FA_CREATE_ALWAYS);
if (ff_result != FR_OK)
{
NRF_LOG_ERROR("\r\nUnable to open or create file: %u", ff_result);
NRF_LOG_FLUSH();
return;
}

f_write(&file, file_buf, 599, &bww);
f_close(&file);

f_open(&file, filename, FA_READ);
f_read(&file, file_buf, 599, &bww);

NRF_LOG_INFO("%d, %d, %d, %d\r\n", file_buf[0], file_buf[1], file_buf[2], file_buf[3]);

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");
}

log info:

Creating random file: 0000181c.txt ...file_buf addr:20000015,a :2000000C

[00:00:00.000,000] <info> app: 2, 3, 4, 5

Related