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

Problem about fatfs and QSPI on nRF52840

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
static bool fatfs_init(void)
{
FRESULT ff_result;
bool init_result = true;
DSTATUS disk_state = STA_NOINIT;
bool flag = false;
memset(&m_filesystem, 0, sizeof(FATFS));
// Initialize FATFS disk I/O interface by providing the block device.
static diskio_blkdev_t drives[] =
{
#if USE_SD_CARD
DISKIO_BLOCKDEV_CONFIG(NRF_BLOCKDEV_BASE_ADDR(m_block_dev_sdc, block_dev), NULL)
#else
DISKIO_BLOCKDEV_CONFIG(NRF_BLOCKDEV_BASE_ADDR(m_block_dev_qspi, block_dev), NULL)
#endif
};
diskio_blockdev_register(drives, ARRAY_SIZE(drives));
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Hi, I was using nRF52840 , flash is mx25L25645GM2, I used fatfs with QSPI ,but I found fatfs was unstable,After some time, the stored file would dispear.Sometime there were scrambling symbols in my files

  • Attach the picture

  • Hi, 

    Which SDK and Softdevice version and revision of the nRF52840 are you using?

    Regards

    Jared

  • sdk :nRF5_SDK_15.2.0_9412b96  

    revision of the nRF52840 : cortex-m4 nrf52840_xxAA 1024KB+4KB 256KB  PCA10056

  • Hi,

    Could you share your definition of the block_dev? And the functions where you open read/write and close the files.

    Regards

    Jared 

  • Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    /**
    * @brief QSPI block device definition
    */
    NRF_BLOCK_DEV_QSPI_DEFINE(
    m_block_dev_qspi,
    NRF_BLOCK_DEV_QSPI_CONFIG(
    512,
    NRF_BLOCK_DEV_QSPI_FLAG_CACHE_WRITEBACK,
    NRF_DRV_QSPI_DEFAULT_CONFIG
    ),
    NFR_BLOCK_DEV_INFO_CONFIG("Nordic", "QSPI", "1.00")
    );
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    static uint32_t file_open(const char*filename)
    {
    static FIL file;
    FRESULT ff_result;
    NRF_LOG_INFO("Opening file: %s.", NRF_LOG_PUSH(filename));
    if(get_record_disabled()){
    return NRF_ERROR_BUSY;
    }
    ff_result = f_open(&file, filename, FA_READ | FA_WRITE | FA_OPEN_APPEND);
    if (ff_result != FR_OK)
    {
    NRF_LOG_INFO("Unable to open or create file: %d", ff_result);
    return NRF_ERROR_BUSY;
    }
    m_opened_file = &file;
    return NRF_SUCCESS;
    }
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    static uint32_t file_write(const uint8_t *buf, uint32_t len)
    {
    uint32_t written = 0;
    FRESULT ff_result;
    if(m_opened_file == NULL){
    NRF_LOG_ERROR("Sorry, open file first");
    return NRF_ERROR_BUSY;
    }
    NRF_LOG_HEXDUMP_DEBUG(buf, len);
    if(get_record_disabled()){
    return NRF_ERROR_BUSY;
    }
    f_lseek(m_opened_file,f_size(m_opened_file));
    ff_result = f_write(m_opened_file, buf, len, (UINT *) &written);
    if (ff_result != FR_OK || written != len)
    {
    NRF_LOG_ERROR("Failed to write, ff_result: %d, written: %d", ff_result, written);
    return NRF_ERROR_NULL;
    }
    else
    {
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

1 2 3 4 5