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

Nordic nRF52840 USB MSC File Corruption Issue

     We found USB MSC File Corruption issue on nRF52840 SDK. It is 100% repeatable.

     Below is the test method and  result:

      Test environment:

       Platform: nRF52840

        HW board used: PCA10056

       SDK tested/used: SDK16.0 / SDK17.0

       Example used: sdk16_0\examples\peripheral\usbd_msc

     Test Method:

  1. Replace the main.c  with the attached file. (We just has little modification and add a special test routine.)
  2. Compile and download FW to  PCA10056 EVB.
  3. Open Uart  terminal to see the debug log with buadrate 115200.
  4. Press Button 1 on the PCA10056 EVB. Test1.txt and totally 250 random files will be created automatically. Please refer to the attached debuglog.txt
  5. Connect USB and use notepad to open Test1.txt, found the file Test1.txt was Corrupted due to Random files creation.

Test Result:

 

 

   More information:

  1. You can also download  the attached “usbd_msc_pca10056.hex”  file to your PCA10056 EVB for quick test.
  2. We have tested the most updated SDK.17.0, this issue still exist.
  3. We have searched the internet, and many people have reported this issue before since sdk 15.2 but still no any solution provided.

    Ref link:

    https://devzone.nordicsemi.com/f/nordic-q-a/39428/usb-msc-corruption

    https://devzone.nordicsemi.com/f/nordic-q-a/48535/problem-about-fatfs-and-qspi-on-nrf52840

   This issue is very critical, please help to check the root cause and provide solution to us.

   Thanks.

Best regards,

John


/**
 * Copyright (c) 2016 - 2019, Nordic Semiconductor ASA
 *
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice, this
 *    list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form, except as embedded into a Nordic
 *    Semiconductor ASA integrated circuit in a product or a software update for
 *    such product, must reproduce the above copyright notice, this list of
 *    conditions and the following disclaimer in the documentation and/or other
 *    materials provided with the distribution.
 *
 * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
 *    contributors may be used to endorse or promote products derived from this
 *    software without specific prior written permission.
 *
 * 4. This software, with or without modification, must only be used with a
 *    Nordic Semiconductor ASA integrated circuit.
 *
 * 5. Any software provided in binary form under this license must not be reverse
 *    engineered, decompiled, modified and/or disassembled.
 *
 * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 */
#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
#include <inttypes.h>
#include <stdlib.h>

#include "nrf.h"
#include "nrf_block_dev.h"
#include "nrf_block_dev_ram.h"
#include "nrf_block_dev_empty.h"
#include "nrf_block_dev_qspi.h"
#include "nrf_block_dev_sdc.h"
#include "nrf_drv_usbd.h"
#include "nrf_drv_clock.h"
#include "nrf_gpio.h"
#include "nrf_atomic.h"
#include "nrf_drv_power.h"

#include "ff.h"
#include "diskio_blkdev.h"

#include "app_usbd.h"
#include "app_usbd_core.h"
#include "app_usbd_string_desc.h"
#include "app_usbd_msc.h"
#include "app_error.h"
#include "app_timer.h"

#include "bsp.h"


#include "nrf_log.h"
#include "nrf_log_ctrl.h"
#include "nrf_log_default_backends.h"

/**@file
 * @defgroup usbd_msc_example main.c
 * @{
 * @ingroup usbd_msc_example
 * @brief USBD MSC example
 *
 */

#define LED_USB_RESUME   (BSP_BOARD_LED_0)
#define LED_USB_START    (BSP_BOARD_LED_1)

#define BTN_RANDOM_FILE  0
#define BTN_LIST_DIR     1
#define BTN_MKFS         2

#define KEY_EV_RANDOM_FILE_MSK (1U << BTN_RANDOM_FILE)
#define KEY_EV_LIST_DIR_MSK    (1U << BTN_LIST_DIR   )
#define KEY_EV_MKFS_MSK        (1U << BTN_MKFS       )

/**
 * @brief Enable power USB detection
 *
 * Configure if example supports USB port connection
 */
#ifndef USBD_POWER_DETECTION
#define USBD_POWER_DETECTION true
#endif

/**
 * @brief SD card enable/disable
 */
#define USE_SD_CARD       0

/**
 * @brief FatFS for QPSI enable/disable
 */
#define USE_FATFS_QSPI    1

/**
 * @brief Mass storage class user event handler
 */
static void msc_user_ev_handler(app_usbd_class_inst_t const * p_inst,
                                app_usbd_msc_user_event_t     event);


/**
 * @brief Ram block device size
 *
 * @note Windows fails to format volumes smaller than 190KB
 */
#define RAM_BLOCK_DEVICE_SIZE (380 * 512)

/**
 * @brief  RAM block device work buffer
 */
static uint8_t m_block_dev_ram_buff[RAM_BLOCK_DEVICE_SIZE];

/**
 * @brief  RAM block device definition
 */
NRF_BLOCK_DEV_RAM_DEFINE(
    m_block_dev_ram,
    NRF_BLOCK_DEV_RAM_CONFIG(512, m_block_dev_ram_buff, sizeof(m_block_dev_ram_buff)),
    NFR_BLOCK_DEV_INFO_CONFIG("Nordic", "RAM", "1.00")
);


/**
 * @brief Empty block device definition
 */
NRF_BLOCK_DEV_EMPTY_DEFINE(
    m_block_dev_empty,
    NRF_BLOCK_DEV_EMPTY_CONFIG(512, 1024 * 1024),
    NFR_BLOCK_DEV_INFO_CONFIG("Nordic", "EMPTY", "1.00")
);


/**
 * @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")
);

#if USE_SD_CARD

#define SDC_SCK_PIN     (27)        ///< SDC serial clock (SCK) pin.
#define SDC_MOSI_PIN    (26)        ///< SDC serial data in (DI) pin.
#define SDC_MISO_PIN    (2)         ///< SDC serial data out (DO) pin.
#define SDC_CS_PIN      (32 + 15)   ///< SDC chip select (CS) pin.

/**
 * @brief  SDC block device definition
 */
NRF_BLOCK_DEV_SDC_DEFINE(
    m_block_dev_sdc,
    NRF_BLOCK_DEV_SDC_CONFIG(
        SDC_SECTOR_SIZE,
        APP_SDCARD_CONFIG(SDC_MOSI_PIN, SDC_MISO_PIN, SDC_SCK_PIN, SDC_CS_PIN)
     ),
     NFR_BLOCK_DEV_INFO_CONFIG("Nordic", "SDC", "1.00")
);


/**
 * @brief Block devices list passed to @ref APP_USBD_MSC_GLOBAL_DEF
 */
#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),    \
    NRF_BLOCKDEV_BASE_ADDR(m_block_dev_sdc, block_dev)      \
)

#else
/*
#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)     \
)
*/

#define BLOCKDEV_LIST() (                                   \
    NRF_BLOCKDEV_BASE_ADDR(m_block_dev_qspi, block_dev)     \
)

#endif

/**
 * @brief Endpoint list passed to @ref APP_USBD_MSC_GLOBAL_DEF
 */
#define ENDPOINT_LIST() APP_USBD_MSC_ENDPOINT_LIST(1, 1)

/**
 * @brief Mass storage class work buffer size
 */
#define MSC_WORKBUFFER_SIZE (1024)

/*lint -save -e26 -e64 -e123 -e505 -e651*/
/**
 * @brief Mass storage class instance
 */
APP_USBD_MSC_GLOBAL_DEF(m_app_msc,
                        0,
                        msc_user_ev_handler,
                        ENDPOINT_LIST(),
                        BLOCKDEV_LIST(),
                        MSC_WORKBUFFER_SIZE);

/*lint -restore*/

/**
 * @brief Events from keys
 */
static nrf_atomic_u32_t m_key_events;

/**
 * @brief  USB connection status
 */
static bool m_usb_connected = false;


#if USE_FATFS_QSPI

static FATFS m_filesystem;

static bool fatfs_init(void)
{
    FRESULT ff_result;
    DSTATUS disk_state = STA_NOINIT;

    memset(&m_filesystem, 0, sizeof(FATFS));

    // Initialize FATFS disk I/O interface by providing the block device.
    static diskio_blkdev_t drives[] =
    {
        DISKIO_BLOCKDEV_CONFIG(NRF_BLOCKDEV_BASE_ADDR(m_block_dev_qspi, block_dev), NULL)
    };

    diskio_blockdev_register(drives, ARRAY_SIZE(drives));

    NRF_LOG_INFO("Initializing disk 0 (QSPI)...");
    disk_state = disk_initialize(0);
    if (disk_state)
    {
        NRF_LOG_ERROR("Disk initialization failed.");
        return false;
    }

    NRF_LOG_INFO("Mounting volume...");
    ff_result = f_mount(&m_filesystem, "", 1);
    if (ff_result != FR_OK)
    {
        if (ff_result == FR_NO_FILESYSTEM)
        {
            NRF_LOG_ERROR("Mount failed. Filesystem not found. Please format device.");
        }
        else
        {
            NRF_LOG_ERROR("Mount failed: %u", ff_result);
        }
        return false;
    }

    return true;
}

static void fatfs_mkfs(void)
{
    FRESULT ff_result;

    if (m_usb_connected)
    {
        NRF_LOG_ERROR("Unable to operate on filesystem while USB is connected");
        return;
    }

    NRF_LOG_INFO("\r\nCreating filesystem...");
    static uint8_t buf[512];
    ff_result = f_mkfs("", FM_FAT, 1024, buf, sizeof(buf));	
    //ff_result = f_mkfs("", FM_FAT, 2048, buf, sizeof(buf));
	//ff_result = f_mkfs("", FM_FAT, 4096, buf, sizeof(buf));
    if (ff_result != FR_OK)
    {
        NRF_LOG_ERROR("Mkfs failed.");
        return;
    }

    NRF_LOG_INFO("Mounting volume...");
    ff_result = f_mount(&m_filesystem, "", 1);
    if (ff_result != FR_OK)
    {
        NRF_LOG_ERROR("Mount failed.");
        return;
    }

    NRF_LOG_INFO("Done");
}

static void fatfs_ls(void)
{
    DIR dir;
    FRESULT ff_result;
    FILINFO fno;

    if (m_usb_connected)
    {
        NRF_LOG_ERROR("Unable to operate on filesystem while USB is connected");
        return;
    }

    NRF_LOG_INFO("\r\nListing directory: /");
    ff_result = f_opendir(&dir, "/");
    if (ff_result != FR_OK)
    {
        NRF_LOG_ERROR("Directory listing failed: %u", ff_result);
        return;
    }

    uint32_t entries_count = 0;
    do
    {
        ff_result = f_readdir(&dir, &fno);
        if (ff_result != FR_OK)
        {
            NRF_LOG_ERROR("Directory read failed: %u", ff_result);
            return;
        }

        if (fno.fname[0])
        {
            if (fno.fattrib & AM_DIR)
            {
                NRF_LOG_RAW_INFO("   <DIR>   %s\r\n",(uint32_t)fno.fname);
            }
            else
            {
                NRF_LOG_RAW_INFO("%9lu  %s\r\n", fno.fsize, (uint32_t)fno.fname);
            }
        }

        ++entries_count;
        NRF_LOG_FLUSH();
    } while (fno.fname[0]);


    NRF_LOG_RAW_INFO("Entries count: %u\r\n", entries_count);
}

static void fatfs_file_create(void)
{
    FRESULT ff_result;
    FIL file;
    char filename[16];
    uint32_t num;
    char buf[] = "abcdef\r\n";
    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 ...", (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;
    }

    for (uint32_t i = 0; i < 1024; i++) {
        f_write(&file, buf, strlen(buf), &num);
    }

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

static void fatfs_uninit(void)
{
    NRF_LOG_INFO("Un-initializing disk 0 (QSPI)...");
    UNUSED_RETURN_VALUE(disk_uninitialize(0));
}
#else //USE_FATFS_QSPI
#define fatfs_init()        false
#define fatfs_mkfs()        do { } while (0)
#define fatfs_ls()          do { } while (0)
#define fatfs_file_create() do { } while (0)
#define fatfs_uninit()      do { } while (0)
#endif

/**
 * @brief Class specific event handler.
 *
 * @param p_inst    Class instance.
 * @param event     Class specific event.
 */
static void msc_user_ev_handler(app_usbd_class_inst_t const * p_inst,
                                app_usbd_msc_user_event_t     event)
{
    UNUSED_PARAMETER(p_inst);
    UNUSED_PARAMETER(event);
}

/**
 * @brief USBD library specific event handler.
 *
 * @param event     USBD library event.
 */
static void usbd_user_ev_handler(app_usbd_event_type_t event)
{
    switch (event)
    {
        case APP_USBD_EVT_DRV_SUSPEND:
            bsp_board_led_off(LED_USB_RESUME);
            break;
        case APP_USBD_EVT_DRV_RESUME:
            bsp_board_led_on(LED_USB_RESUME);
            break;
        case APP_USBD_EVT_STARTED:
            bsp_board_led_on(LED_USB_START);
            break;
        case APP_USBD_EVT_STOPPED:
            UNUSED_RETURN_VALUE(fatfs_init());
            app_usbd_disable();
            bsp_board_leds_off();
            break;
        case APP_USBD_EVT_POWER_DETECTED:
            NRF_LOG_INFO("USB power detected");

            if (!nrf_drv_usbd_is_enabled())
            {
                fatfs_uninit();
                app_usbd_enable();
            }
            break;
        case APP_USBD_EVT_POWER_REMOVED:
            NRF_LOG_INFO("USB power removed");
            app_usbd_stop();
            m_usb_connected = false;
            break;
        case APP_USBD_EVT_POWER_READY:
            NRF_LOG_INFO("USB ready");
            app_usbd_start();
            m_usb_connected = true;
            break;
        default:
            break;
    }
}

static void bsp_event_callback(bsp_event_t ev)
{
    switch (ev)
    {
        /* Just set a flag to be processed in the main loop */
        case CONCAT_2(BSP_EVENT_KEY_, BTN_RANDOM_FILE):
            UNUSED_RETURN_VALUE(nrf_atomic_u32_or(&m_key_events, KEY_EV_RANDOM_FILE_MSK));
            break;

        case CONCAT_2(BSP_EVENT_KEY_, BTN_LIST_DIR):
            UNUSED_RETURN_VALUE(nrf_atomic_u32_or(&m_key_events, KEY_EV_LIST_DIR_MSK));
            break;

        case CONCAT_2(BSP_EVENT_KEY_, BTN_MKFS):
            UNUSED_RETURN_VALUE(nrf_atomic_u32_or(&m_key_events, KEY_EV_MKFS_MSK));
            break;

        default:
            return; // no implementation needed
    }
}

void create_test_file(void) {
    FRESULT ff_result = FR_OK;
    FIL file1;
    uint32_t num;
    char buf[] = "123456\r\n";
	
    ff_result = f_open(&file1, "test1.txt", FA_CREATE_ALWAYS | FA_WRITE);
	if (ff_result != FR_OK) {
		NRF_LOG_INFO("\r\n#1Unable to open file: %u", ff_result);
    }
    for (uint32_t i = 0; i < 4096; i++) {
        f_write(&file1, buf, strlen(buf), &num);
    }

    ff_result = f_close(&file1);
    if (ff_result != FR_OK) {
		NRF_LOG_INFO("\r\n#1Unable to close file: %u", ff_result);
    }
	NRF_LOG_INFO("\r\n Test1.ext created Done");
}

int main(void)
{
    ret_code_t ret;
    static const app_usbd_config_t usbd_config = {
        .ev_state_proc = usbd_user_ev_handler
    };

    ret = NRF_LOG_INIT(app_usbd_sof_timestamp_get);
    APP_ERROR_CHECK(ret);
    NRF_LOG_DEFAULT_BACKENDS_INIT();

    ret = nrf_drv_clock_init();
    APP_ERROR_CHECK(ret);

    /* Fill whole RAM block device buffer */
    for (size_t i = 0; i < sizeof(m_block_dev_ram_buff); ++i)
    {
        m_block_dev_ram_buff[i] = i;
    }

    /* Configure LEDs and buttons */
    nrf_drv_clock_lfclk_request(NULL);
    ret = app_timer_init();
    APP_ERROR_CHECK(ret);
    ret = bsp_init(BSP_INIT_BUTTONS, bsp_event_callback);
    APP_ERROR_CHECK(ret);
    bsp_board_init(BSP_INIT_LEDS);

    if (fatfs_init())
    {
        fatfs_ls();
        fatfs_file_create();
    }

	
    ret = app_usbd_init(&usbd_config);
    APP_ERROR_CHECK(ret);

    app_usbd_class_inst_t const * class_inst_msc = app_usbd_msc_class_inst_get(&m_app_msc);
    ret = app_usbd_class_append(class_inst_msc);
    APP_ERROR_CHECK(ret);

    NRF_LOG_INFO("USBD MSC example started.");

    if (USBD_POWER_DETECTION)
    {
        ret = app_usbd_power_events_enable();
        APP_ERROR_CHECK(ret);
    }
    else
    {
        NRF_LOG_INFO("No USB power detection enabled\r\nStarting USB now");

        app_usbd_enable();
        app_usbd_start();
        m_usb_connected = true;
    }

	
    while (true)
    {
        while (app_usbd_event_queue_process())
        {
            /* Nothing to do */
        }

        /* Process BSP key events flags.*/
        uint32_t events = nrf_atomic_u32_fetch_store(&m_key_events, 0);
        if (events & KEY_EV_RANDOM_FILE_MSK)
        {
		    NRF_LOG_INFO("1. Format Disk."); 
            fatfs_mkfs();		
		    NRF_LOG_INFO("2. Create Test file."); 			
            create_test_file();
		    NRF_LOG_INFO("3. Create Random files."); 
             for (uint32_t i = 0; i < 250; i++) {
               NRF_LOG_INFO("File create count(max 250): %d",i+1);
                 fatfs_file_create();
             }
			 NRF_LOG_INFO("4. Created file list:");    
			 fatfs_ls();
			 NRF_LOG_INFO("5. Connect to PC and open TEST1.txt to check if file corrupted or not."); 
        }

        if (events & KEY_EV_LIST_DIR_MSK)
        {
            fatfs_ls();
        }

        if (events & KEY_EV_MKFS_MSK)
        {
            fatfs_mkfs();
        }

        UNUSED_RETURN_VALUE(NRF_LOG_PROCESS());
        /* Sleep CPU only if there was no interrupt since last loop processing */
        __WFE();
    }
}

/** @} */
[00:00:00.000,000] <info> app:
Creating filesystem...
[00:00:00.000,000] <info> app: Mounting volume...
[00:00:00.000,000] <info> app: Done
[00:00:00.000,000] <info> app: 1. Format Disk.
[00:00:00.000,000] <info> app:
Creating filesystem...
[00:00:00.000,000] <info> app: Mounting volume...
[00:00:00.000,000] <info> app: Done
[00:00:00.000,000] <info> app: 2. Create Test file.
[00:00:00.000,000] <info> app:
 Test1.ext created Done
[00:00:00.000,000] <info> app: 3. Create Random files.
[00:00:00.000,000] <info> app: File create count(max 250): 1
Creating random file: 1dcf9710.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 2
Creating random file: 0b24a2c2.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 3
Creating random file: 33a3d95f.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 4
Creating random file: 0adfc95d.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 5
Creating random file: 1e1c3b19.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 6
Creating random file: 28c043e4.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 7
Creating random file: 167a32f6.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 8
Creating random file: 3e7ba54f.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 9
Creating random file: 36b9ff2f.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 10
Creating random file: 11cb778f.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 11
Creating random file: 225dffa2.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 12
Creating random file: 23c4bc83.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 13
Creating random file: 1ea3d733.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 14
Creating random file: 1b1f0889.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 15
Creating random file: 14a81861.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 16
Creating random file: 2be4a53b.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 17
Creating random file: 1c9c50c3.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 18
Creating random file: 21b11433.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 19
Creating random file: 39744bf6.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 20
Creating random file: 08c1e02b.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 21
Creating random file: 1f5c8349.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 22
Creating random file: 28a0d2dd.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 23
Creating random file: 19b115ba.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 24
Creating random file: 0a833df4.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 25
Creating random file: 0fc9f855.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 26
Creating random file: 02ef6db0.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 27
Creating random file: 39a828b4.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 28
Creating random file: 319b46a8.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 29
Creating random file: 26722a8a.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 30
Creating random file: 2427d64d.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 31
Creating random file: 01a27670.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 32
Creating random file: 210f9428.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 33
Creating random file: 34b0bda7.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 34
Creating random file: 1f103c17.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 35
Creating random file: 114ad262.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 36
Creating random file: 38ac2324.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 37
Creating random file: 17b658fc.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 38
Creating random file: 1b97bf46.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 39
Creating random file: 081c3598.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 40
Creating random file: 38a0ae59.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 41
Creating random file: 383f29d1.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 42
Creating random file: 0b16833a.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 43
Creating random file: 359d2f2d.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 44
Creating random file: 11ad6071.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 45
Creating random file: 34357368.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 46
Creating random file: 013ed5d8.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 47
Creating random file: 0538ccad.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 48
Creating random file: 0ad2b8db.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 49
Creating random file: 20b42f24.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 50
Creating random file: 3db7c099.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 51
Creating random file: 1ec34628.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 52
Creating random file: 03dc4bd3.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 53
Creating random file: 2b2d9e04.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 54
Creating random file: 142fb54c.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 55
Creating random file: 0291b415.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 56
Creating random file: 05e079e8.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 57
Creating random file: 3c96285e.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 58
Creating random file: 28a3fc76.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 59
Creating random file: 09199193.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 60
Creating random file: 15527425.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 61
Creating random file: 0af78ddd.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 62
Creating random file: 1d62d586.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 63
Creating random file: 2f66b041.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 64
Creating random file: 3832b699.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 65
Creating random file: 3983703b.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 66
Creating random file: 1f5eb361.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 67
Creating random file: 0863acd9.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 68
Creating random file: 018e3064.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 69
Creating random file: 03829741.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 70
Creating random file: 398b7144.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 71
Creating random file: 040bc524.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 72
Creating random file: 09e7a403.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 73
Creating random file: 0ae1b034.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 74
Creating random file: 17296968.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 75
Creating random file: 0759efcb.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 76
Creating random file: 1a16e9d6.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 77
Creating random file: 25446a35.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 78
Creating random file: 34195f1c.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 79
Creating random file: 2471b125.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 80
Creating random file: 363d5230.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 81
Creating random file: 21b2df1d.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 82
Creating random file: 32fb3fcf.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 83
Creating random file: 25e17a99.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 84
Creating random file: 0748cbd4.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 85
Creating random file: 33e28aa9.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 86
Creating random file: 06aa173e.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 87
Creating random file: 1c5e02ae.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 88
Creating random file: 08dae9a4.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 89
Creating random file: 0cd67986.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 90
Creating random file: 29d4aae2.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 91
Creating random file: 2251dda2.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 92
Creating random file: 292fb93f.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 93
Creating random file: 1953b807.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 94
Creating random file: 37ebdf57.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 95
Creating random file: 1de4f4ca.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 96
Creating random file: 1a481eda.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 97
Creating random file: 34493fa7.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 98
Creating random file: 0be0a4a1.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 99
Creating random file: 22184e34.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 100
Creating random file: 0b19bd90.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 101
Creating random file: 3115ad92.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 102
Creating random file: 1586b952.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 103
Creating random file: 212fee12.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 104
Creating random file: 047b364a.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 105
Creating random file: 13feb37b.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 106
Creating random file: 31b34074.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 107
Creating random file: 29b66982.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 108
Creating random file: 2ed17592.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 109
Creating random file: 1b8c3122.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 110
Creating random file: 2011e00c.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 111
Creating random file: 37ad87ac.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 112
Creating random file: 1d99328f.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 113
Creating random file: 0ef03695.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 114
Creating random file: 3acac32c.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 115
Creating random file: 37527ea3.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 116
Creating random file: 35d4832d.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 117
Creating random file: 0a3f718a.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 118
Creating random file: 0a72fe1a.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 119
Creating random file: 02e4129f.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 120
Creating random file: 0d2c17ca.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 121
Creating random file: 2b69e840.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 122
Creating random file: 24552587.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 123
Creating random file: 12f63f72.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 124
Creating random file: 1dc81bfc.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 125
Creating random file: 11ca649b.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 126
Creating random file: 260e36b1.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 127
Creating random file: 0c2c987f.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 128
Creating random file: 0db17b73.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 129
Creating random file: 02667610.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 130
Creating random file: 166e1afa.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 131
Creating random file: 11993e9f.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 132
Creating random file: 2ebea403.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 133
Creating random file: 0d8489c5.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 134
Creating random file: 1aeed13f.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 135
Creating random file: 11f8bb32.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 136
Creating random file: 3ddad1a2.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 137
Creating random file: 365ac72b.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 138
Creating random file: 35c3d4d1.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 139
Creating random file: 238b4e34.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 140
Creating random file: 2c3b405c.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 141
Creating random file: 08e42499.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 142
Creating random file: 08ee16f0.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 143
Creating random file: 0bdce93b.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 144
Creating random file: 298ac524.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 145
Creating random file: 070d1267.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 146
Creating random file: 2109118f.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 147
Creating random file: 07ff53a7.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 148
Creating random file: 3c3336ef.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 149
Creating random file: 1042f782.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 150
Creating random file: 1ec6c4fd.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 151
Creating random file: 10f2efc9.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 152
Creating random file: 1154f3b0.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 153
Creating random file: 11711aec.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 154
Creating random file: 1e8fcc7e.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 155
Creating random file: 0307734f.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 156
Creating random file: 26e84604.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 157
Creating random file: 0861250b.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 158
Creating random file: 3bb8c238.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 159
Creating random file: 1c6fdf17.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 160
Creating random file: 2c28758c.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 161
Creating random file: 3b1d669d.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 162
Creating random file: 1cc937e4.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 163
Creating random file: 0d029500.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 164
Creating random file: 3019622b.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 165
Creating random file: 39ee845f.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 166
Creating random file: 2575a1ba.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 167
Creating random file: 22574d5f.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 168
Creating random file: 0e5ad1de.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 169
Creating random file: 3924b759.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 170
Creating random file: 29a0e781.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 171
Creating random file: 0259982a.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 172
Creating random file: 33dd0a37.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 173
Creating random file: 3b1fafea.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 174
Creating random file: 3121088c.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 175
Creating random file: 0afc1e41.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 176
Creating random file: 32d16adc.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 177
Creating random file: 0d1c8e2a.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 178
Creating random file: 07ea83ac.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 179
Creating random file: 2f9a2b1c.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 180
Creating random file: 0dce14bc.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 181
Creating random file: 152a6056.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 182
Creating random file: 069507fc.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 183
Creating random file: 1a5e1bbe.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 184
Creating random file: 2a7b8bd5.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 185
Creating random file: 0b09bcdb.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 186
Creating random file: 10f3595c.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 187
Creating random file: 251227ad.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 188
Creating random file: 2f4b7060.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 189
Creating random file: 1f5b82cc.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 190
Creating random file: 20ef694e.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 191
Creating random file: 1e784863.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 192
Creating random file: 088860ea.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 193
Creating random file: 1284e8eb.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 194
Creating random file: 101ddfbb.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 195
Creating random file: 2e3fd09b.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 196
Creating random file: 06de3465.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 197
Creating random file: 38d31b42.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 198
Creating random file: 18841994.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 199
Creating random file: 1e6de637.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 200
Creating random file: 3a302a7c.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 201
Creating random file: 21ed4d3e.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 202
Creating random file: 3a0ee528.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 203
Creating random file: 2cb053f5.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 204
Creating random file: 3f668667.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 205
Creating random file: 2a2550f9.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 206
Creating random file: 0638eb31.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 207
Creating random file: 19ab2038.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 208
Creating random file: 23908632.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 209
Creating random file: 0d0245d1.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 210
Creating random file: 0904bbe7.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 211
Creating random file: 25364868.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 212
Creating random file: 3c8b19ad.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 213
Creating random file: 0d509385.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 214
Creating random file: 33ed0bdf.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 215
Creating random file: 3f59e2ce.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 216
Creating random file: 0ab4c808.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 217
Creating random file: 1902c77f.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 218
Creating random file: 306d09d4.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 219
Creating random file: 20f28976.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 220
Creating random file: 07d21006.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 221
Creating random file: 197cec9b.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 222
Creating random file: 3c74da80.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 223
Creating random file: 2c4a6f21.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 224
Creating random file: 0a2c4bcc.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 225
Creating random file: 3eb6be0d.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 226
Creating random file: 1876aed2.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 227
Creating random file: 0a989ebe.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 228
Creating random file: 2c33f141.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 229
Creating random file: 22ea0ae4.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 230
Creating random file: 17d77e1c.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 231
Creating random file: 1cbcb625.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 232
Creating random file: 169f8009.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 233
Creating random file: 142fa1f3.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 234
Creating random file: 15c17987.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 235
Creating random file: 2aad3ca0.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 236
Creating random file: 372ed159.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 237
Creating random file: 133210a8.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 238
Creating random file: 2133d627.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 239
Creating random file: 02d903d3.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 240
Creating random file: 23e6307f.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 241
Creating random file: 3d335d5b.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 242
Creating random file: 30b3c162.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 243
Creating random file: 3afa67b3.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 244
Creating random file: 3219c7e9.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 245
Creating random file: 17c509a0.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 246
Creating random file: 38953716.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 247
Creating random file: 3cc6e452.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 248
Creating random file: 3f76359d.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 249
Creating random file: 33a362ac.txt ...done
[00:00:00.000,000] <info> app: File create count(max 250): 250
Creating random file: 12ec58f3.txt ...done
[00:00:00.000,000] <info> app: 4. Created file list:
[00:00:00.000,000] <info> app:
Listing directory: /
    32768  TEST1.TXT
     8192  1DCF9710.TXT
     8192  0B24A2C2.TXT
     8192  33A3D95F.TXT
     8192  0ADFC95D.TXT
     8192  1E1C3B19.TXT
     8192  28C043E4.TXT
     8192  167A32F6.TXT
     8192  3E7BA54F.TXT
     8192  36B9FF2F.TXT
     8192  11CB778F.TXT
     8192  225DFFA2.TXT
     8192  23C4BC83.TXT
     8192  1EA3D733.TXT
     8192  1B1F0889.TXT
     8192  14A81861.TXT
     8192  2BE4A53B.TXT
     8192  1C9C50C3.TXT
     8192  21B11433.TXT
     8192  39744BF6.TXT
     8192  08C1E02B.TXT
     8192  1F5C8349.TXT
     8192  28A0D2DD.TXT
     8192  19B115BA.TXT
     8192  0A833DF4.TXT
     8192  0FC9F855.TXT
     8192  02EF6DB0.TXT
     8192  39A828B4.TXT
     8192  319B46A8.TXT
     8192  26722A8A.TXT
     8192  2427D64D.TXT
     8192  01A27670.TXT
     8192  210F9428.TXT
     8192  34B0BDA7.TXT
     8192  1F103C17.TXT
     8192  114AD262.TXT
     8192  38AC2324.TXT
     8192  17B658FC.TXT
     8192  1B97BF46.TXT
     8192  081C3598.TXT
     8192  38A0AE59.TXT
     8192  383F29D1.TXT
     8192  0B16833A.TXT
     8192  359D2F2D.TXT
     8192  11AD6071.TXT
     8192  34357368.TXT
     8192  013ED5D8.TXT
     8192  0538CCAD.TXT
     8192  0AD2B8DB.TXT
     8192  20B42F24.TXT
     8192  3DB7C099.TXT
     8192  1EC34628.TXT
     8192  03DC4BD3.TXT
     8192  2B2D9E04.TXT
     8192  142FB54C.TXT
     8192  0291B415.TXT
     8192  05E079E8.TXT
     8192  3C96285E.TXT
     8192  28A3FC76.TXT
     8192  09199193.TXT
     8192  15527425.TXT
     8192  0AF78DDD.TXT
     8192  1D62D586.TXT
     8192  2F66B041.TXT
     8192  3832B699.TXT
     8192  3983703B.TXT
     8192  1F5EB361.TXT
     8192  0863ACD9.TXT
     8192  018E3064.TXT
     8192  03829741.TXT
     8192  398B7144.TXT
     8192  040BC524.TXT
     8192  09E7A403.TXT
     8192  0AE1B034.TXT
     8192  17296968.TXT
     8192  0759EFCB.TXT
     8192  1A16E9D6.TXT
     8192  25446A35.TXT
     8192  34195F1C.TXT
     8192  2471B125.TXT
     8192  363D5230.TXT
     8192  21B2DF1D.TXT
     8192  32FB3FCF.TXT
     8192  25E17A99.TXT
     8192  0748CBD4.TXT
     8192  33E28AA9.TXT
     8192  06AA173E.TXT
     8192  1C5E02AE.TXT
     8192  08DAE9A4.TXT
     8192  0CD67986.TXT
     8192  29D4AAE2.TXT
     8192  2251DDA2.TXT
     8192  292FB93F.TXT
     8192  1953B807.TXT
     8192  37EBDF57.TXT
     8192  1DE4F4CA.TXT
     8192  1A481EDA.TXT
     8192  34493FA7.TXT
     8192  0BE0A4A1.TXT
     8192  22184E34.TXT
     8192  0B19BD90.TXT
     8192  3115AD92.TXT
     8192  1586B952.TXT
     8192  212FEE12.TXT
     8192  047B364A.TXT
     8192  13FEB37B.TXT
     8192  31B34074.TXT
     8192  29B66982.TXT
     8192  2ED17592.TXT
     8192  1B8C3122.TXT
     8192  2011E00C.TXT
     8192  37AD87AC.TXT
     8192  1D99328F.TXT
     8192  0EF03695.TXT
     8192  3ACAC32C.TXT
     8192  37527EA3.TXT
     8192  35D4832D.TXT
     8192  0A3F718A.TXT
     8192  0A72FE1A.TXT
     8192  02E4129F.TXT
     8192  0D2C17CA.TXT
     8192  2B69E840.TXT
     8192  24552587.TXT
     8192  12F63F72.TXT
     8192  1DC81BFC.TXT
     8192  11CA649B.TXT
     8192  260E36B1.TXT
     8192  0C2C987F.TXT
     8192  0DB17B73.TXT
     8192  02667610.TXT
     8192  166E1AFA.TXT
     8192  11993E9F.TXT
     8192  2EBEA403.TXT
     8192  0D8489C5.TXT
     8192  1AEED13F.TXT
     8192  11F8BB32.TXT
     8192  3DDAD1A2.TXT
     8192  365AC72B.TXT
     8192  35C3D4D1.TXT
     8192  238B4E34.TXT
     8192  2C3B405C.TXT
     8192  08E42499.TXT
     8192  08EE16F0.TXT
     8192  0BDCE93B.TXT
     8192  298AC524.TXT
     8192  070D1267.TXT
     8192  2109118F.TXT
     8192  07FF53A7.TXT
     8192  3C3336EF.TXT
     8192  1042F782.TXT
     8192  1EC6C4FD.TXT
     8192  10F2EFC9.TXT
     8192  1154F3B0.TXT
     8192  11711AEC.TXT
     8192  1E8FCC7E.TXT
     8192  0307734F.TXT
     8192  26E84604.TXT
     8192  0861250B.TXT
     8192  3BB8C238.TXT
     8192  1C6FDF17.TXT
     8192  2C28758C.TXT
     8192  3B1D669D.TXT
     8192  1CC937E4.TXT
     8192  0D029500.TXT
     8192  3019622B.TXT
     8192  39EE845F.TXT
     8192  2575A1BA.TXT
     8192  22574D5F.TXT
     8192  0E5AD1DE.TXT
     8192  3924B759.TXT
     8192  29A0E781.TXT
     8192  0259982A.TXT
     8192  33DD0A37.TXT
     8192  3B1FAFEA.TXT
     8192  3121088C.TXT
     8192  0AFC1E41.TXT
     8192  32D16ADC.TXT
     8192  0D1C8E2A.TXT
     8192  07EA83AC.TXT
     8192  2F9A2B1C.TXT
     8192  0DCE14BC.TXT
     8192  152A6056.TXT
     8192  069507FC.TXT
     8192  1A5E1BBE.TXT
     8192  2A7B8BD5.TXT
     8192  0B09BCDB.TXT
     8192  10F3595C.TXT
     8192  251227AD.TXT
     8192  2F4B7060.TXT
     8192  1F5B82CC.TXT
     8192  20EF694E.TXT
     8192  1E784863.TXT
     8192  088860EA.TXT
     8192  1284E8EB.TXT
     8192  101DDFBB.TXT
     8192  2E3FD09B.TXT
     8192  06DE3465.TXT
     8192  38D31B42.TXT
     8192  18841994.TXT
     8192  1E6DE637.TXT
     8192  3A302A7C.TXT
     8192  21ED4D3E.TXT
     8192  3A0EE528.TXT
     8192  2CB053F5.TXT
     8192  3F668667.TXT
     8192  2A2550F9.TXT
     8192  0638EB31.TXT
     8192  19AB2038.TXT
     8192  23908632.TXT
     8192  0D0245D1.TXT
     8192  0904BBE7.TXT
     8192  25364868.TXT
     8192  3C8B19AD.TXT
     8192  0D509385.TXT
     8192  33ED0BDF.TXT
     8192  3F59E2CE.TXT
     8192  0AB4C808.TXT
     8192  1902C77F.TXT
     8192  306D09D4.TXT
     8192  20F28976.TXT
     8192  07D21006.TXT
     8192  197CEC9B.TXT
     8192  3C74DA80.TXT
     8192  2C4A6F21.TXT
     8192  0A2C4BCC.TXT
     8192  3EB6BE0D.TXT
     8192  1876AED2.TXT
     8192  0A989EBE.TXT
     8192  2C33F141.TXT
     8192  22EA0AE4.TXT
     8192  17D77E1C.TXT
     8192  1CBCB625.TXT
     8192  169F8009.TXT
     8192  142FA1F3.TXT
     8192  15C17987.TXT
     8192  2AAD3CA0.TXT
     8192  372ED159.TXT
     8192  133210A8.TXT
     8192  2133D627.TXT
     8192  02D903D3.TXT
     8192  23E6307F.TXT
     8192  3D335D5B.TXT
     8192  30B3C162.TXT
     8192  3AFA67B3.TXT
     8192  3219C7E9.TXT
     8192  17C509A0.TXT
     8192  38953716.TXT
     8192  3CC6E452.TXT
     8192  3F76359D.TXT
     8192  33A362AC.TXT
     8192  12EC58F3.TXT
Entries count: 252
[00:00:00.000,000] <info> app: 5. Connect to PC and open TEST1.txt to check if file corrupted or not.
usbd_msc_pca10056.hex

Parents
  • Thanks.

    We also tried the attached main.c. It auto write log_entry to a file every 0.5sec.

    When data reord reach to about 256, the file corruption issue happens.

    Please see my attached main.c and the debug log.

        Repeat Sequence:

    1. Press Button 3  to format disk and reset the record_number to 0.
    2. Wait until the data record count  reach to  256.
    3. Connect PC to check the LOG_DATA.TXT.

    Platform: nRF52840

    HW board used: PCA10056

    SDK tested/used: SDK16.0 / SDK17.0

    Example used: sdk16_0\examples\peripheral\usbd_msc

    /**
     * Copyright (c) 2016 - 2018, Nordic Semiconductor ASA
     *
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without modification,
     * are permitted provided that the following conditions are met:
     *
     * 1. Redistributions of source code must retain the above copyright notice, this
     *    list of conditions and the following disclaimer.
     *
     * 2. Redistributions in binary form, except as embedded into a Nordic
     *    Semiconductor ASA integrated circuit in a product or a software update for
     *    such product, must reproduce the above copyright notice, this list of
     *    conditions and the following disclaimer in the documentation and/or other
     *    materials provided with the distribution.
     *
     * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
     *    contributors may be used to endorse or promote products derived from this
     *    software without specific prior written permission.
     *
     * 4. This software, with or without modification, must only be used with a
     *    Nordic Semiconductor ASA integrated circuit.
     *
     * 5. Any software provided in binary form under this license must not be reverse
     *    engineered, decompiled, modified and/or disassembled.
     *
     * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
     * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
     * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
     * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
     * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
     * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     *
     */
    #include <stdint.h>
    #include <stdbool.h>
    #include <stddef.h>
    #include <inttypes.h>
    #include <stdlib.h>
    
    #include "nrf.h"
    #include "nrf_block_dev.h"
    #include "nrf_block_dev_ram.h"
    #include "nrf_block_dev_empty.h"
    #include "nrf_block_dev_qspi.h"
    #include "nrf_block_dev_sdc.h"
    #include "nrf_drv_usbd.h"
    #include "nrf_drv_clock.h"
    #include "nrf_gpio.h"
    #include "nrf_atomic.h"
    #include "nrf_drv_power.h"
    
    #include "ff.h"
    #include "diskio_blkdev.h"
    
    #include "app_scheduler.h"
    #include "app_usbd.h"
    #include "app_usbd_core.h"
    #include "app_usbd_string_desc.h"
    #include "app_usbd_msc.h"
    #include "app_error.h"
    #include "app_timer.h"
    
    #include "bsp.h"
    
    
    #include "nrf_log.h"
    #include "nrf_log_ctrl.h"
    #include "nrf_log_default_backends.h"
    
    /**@file
     * @defgroup usbd_msc_example main.c
     * @{
     * @ingroup usbd_msc_example
     * @brief USBD MSC example
     *
     */
     
    APP_TIMER_DEF(log_timer_id);
    
    #define LED_USB_RESUME   (BSP_BOARD_LED_0)
    #define LED_USB_START    (BSP_BOARD_LED_1)
    
    #define BTN_RANDOM_FILE  0
    #define BTN_LIST_DIR     1
    #define BTN_MKFS         2
    
    #define KEY_EV_RANDOM_FILE_MSK (1U << BTN_RANDOM_FILE)
    #define KEY_EV_LIST_DIR_MSK    (1U << BTN_LIST_DIR   )
    #define KEY_EV_MKFS_MSK        (1U << BTN_MKFS       )
    
    /**
     * @brief Enable power USB detection
     *
     * Configure if example supports USB port connection
     */
    #ifndef USBD_POWER_DETECTION
    #define USBD_POWER_DETECTION true
    #endif
    
    /**
     * @brief SD card enable/disable
     */
    #define USE_SD_CARD       0
    
    /**
     * @brief FatFS for QPSI enable/disable
     */
    #define USE_FATFS_QSPI    1
    
    #define LOG_TIMER_TICKS    500 //500ms
    
    static void log_timer_stop(void);
    static void log_timer_start(uint32_t ticks);
    
    /**
     * @brief Mass storage class user event handler
     */
    static void msc_user_ev_handler(app_usbd_class_inst_t const * p_inst,
                                    app_usbd_msc_user_event_t     event);
    
    
    /**
     * @brief Ram block device size
     *
     * @note Windows fails to format volumes smaller than 190KB
     */
    #define RAM_BLOCK_DEVICE_SIZE (380 * 512)
    
    /**
     * @brief  RAM block device work buffer
     */
    static uint8_t m_block_dev_ram_buff[RAM_BLOCK_DEVICE_SIZE];
    
    /**
     * @brief  RAM block device definition
     */
    NRF_BLOCK_DEV_RAM_DEFINE(
        m_block_dev_ram,
        NRF_BLOCK_DEV_RAM_CONFIG(512, m_block_dev_ram_buff, sizeof(m_block_dev_ram_buff)),
        NFR_BLOCK_DEV_INFO_CONFIG("Nordic", "RAM", "1.00")
    );
    
    
    /**
     * @brief Empty block device definition
     */
    NRF_BLOCK_DEV_EMPTY_DEFINE(
        m_block_dev_empty,
        NRF_BLOCK_DEV_EMPTY_CONFIG(512, 1024 * 1024),
        NFR_BLOCK_DEV_INFO_CONFIG("Nordic", "EMPTY", "1.00")
    );
    
    
    /**
     * @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")
    );
    
    #if USE_SD_CARD
    
    #define SDC_SCK_PIN     (27)        ///< SDC serial clock (SCK) pin.
    #define SDC_MOSI_PIN    (26)        ///< SDC serial data in (DI) pin.
    #define SDC_MISO_PIN    (2)         ///< SDC serial data out (DO) pin.
    #define SDC_CS_PIN      (32 + 15)   ///< SDC chip select (CS) pin.
    
    /**
     * @brief  SDC block device definition
     */
    NRF_BLOCK_DEV_SDC_DEFINE(
        m_block_dev_sdc,
        NRF_BLOCK_DEV_SDC_CONFIG(
            SDC_SECTOR_SIZE,
            APP_SDCARD_CONFIG(SDC_MOSI_PIN, SDC_MISO_PIN, SDC_SCK_PIN, SDC_CS_PIN)
         ),
         NFR_BLOCK_DEV_INFO_CONFIG("Nordic", "SDC", "1.00")
    );
    
    
    /**
     * @brief Block devices list passed to @ref APP_USBD_MSC_GLOBAL_DEF
     */
    #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),    \
        NRF_BLOCKDEV_BASE_ADDR(m_block_dev_sdc, block_dev)      \
    )
    
    #else
    //#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)     \
    //)
    #define BLOCKDEV_LIST() ( NRF_BLOCKDEV_BASE_ADDR(m_block_dev_qspi, block_dev) ) //Only use QSPI as block device
    #endif
    
    /**
     * @brief Endpoint list passed to @ref APP_USBD_MSC_GLOBAL_DEF
     */
    #define ENDPOINT_LIST() APP_USBD_MSC_ENDPOINT_LIST(1, 1)
    
    /**
     * @brief Mass storage class work buffer size
     */
    #define MSC_WORKBUFFER_SIZE (1024)
    
    /*lint -save -e26 -e64 -e123 -e505 -e651*/
    /**
     * @brief Mass storage class instance
     */
    APP_USBD_MSC_GLOBAL_DEF(m_app_msc,
                            0,
                            msc_user_ev_handler,
                            ENDPOINT_LIST(),
                            BLOCKDEV_LIST(),
                            MSC_WORKBUFFER_SIZE);
    
    /*lint -restore*/
    
    /**
     * @brief Events from keys
     */
    static nrf_atomic_u32_t m_key_events;
    
    /**
     * @brief  USB connection status
     */
    static bool m_usb_connected = false;
    
    
    #if USE_FATFS_QSPI
    
    static FATFS m_filesystem;
    
    static bool fatfs_init(void)
    {
        FRESULT ff_result;
        DSTATUS disk_state = STA_NOINIT;
    
        memset(&m_filesystem, 0, sizeof(FATFS));
    
        // Initialize FATFS disk I/O interface by providing the block device.
        static diskio_blkdev_t drives[] =
        {
            DISKIO_BLOCKDEV_CONFIG(NRF_BLOCKDEV_BASE_ADDR(m_block_dev_qspi, block_dev), NULL)
        };
    
        diskio_blockdev_register(drives, ARRAY_SIZE(drives));
    
        NRF_LOG_INFO("Initializing disk 0 (QSPI)...");
        disk_state = disk_initialize(0);
        if (disk_state)
        {
            NRF_LOG_ERROR("Disk initialization failed.");
            return false;
        }
    
        NRF_LOG_INFO("Mounting volume...");
        ff_result = f_mount(&m_filesystem, "", 1);
        if (ff_result != FR_OK)
        {
            if (ff_result == FR_NO_FILESYSTEM)
            {
                NRF_LOG_ERROR("Mount failed. Filesystem not found. Please format device.");
            }
            else
            {
                NRF_LOG_ERROR("Mount failed: %u", ff_result);
            }
            return false;
        }
    
        return true;
    }
    
    static void fatfs_mkfs(void)
    {
        FRESULT ff_result;
    
        if (m_usb_connected)
        {
            NRF_LOG_ERROR("Unable to operate on filesystem while USB is connected");
            return;
        }
    
        NRF_LOG_INFO("\r\nCreating filesystem...");
        static uint8_t buf[512];
        ff_result = f_mkfs("", FM_FAT, 4096, buf, sizeof(buf)); //Changed from 1024 to 4096 byte allocation
        if (ff_result != FR_OK)
        {
            NRF_LOG_ERROR("Mkfs failed. ff_res:%d", ff_result);
            return;
        }
    
        NRF_LOG_INFO("Mounting volume...");
        ff_result = f_mount(&m_filesystem, "", 1);
        if (ff_result != FR_OK)
        {
            NRF_LOG_ERROR("Mount failed.");
            return;
        }
    
        NRF_LOG_INFO("Done");
    }
    
    static void fatfs_ls(void)
    {
        DIR dir;
        FRESULT ff_result;
        FILINFO fno;
    
        if (m_usb_connected)
        {
            NRF_LOG_ERROR("Unable to operate on filesystem while USB is connected");
            return;
        }
    
        NRF_LOG_INFO("\r\nListing directory: /");
        ff_result = f_opendir(&dir, "/");
        if (ff_result != FR_OK)
        {
            NRF_LOG_ERROR("Directory listing failed: %u", ff_result);
            return;
        }
    
        uint32_t entries_count = 0;
        do
        {
            ff_result = f_readdir(&dir, &fno);
            if (ff_result != FR_OK)
            {
                NRF_LOG_ERROR("Directory read failed: %u", ff_result);
                return;
            }
    
            if (fno.fname[0])
            {
                if (fno.fattrib & AM_DIR)
                {
                    NRF_LOG_RAW_INFO("   <DIR>   %s\r\n",(uint32_t)fno.fname);
                }
                else
                {
                    NRF_LOG_RAW_INFO("%9lu  %s\r\n", fno.fsize, (uint32_t)fno.fname);
                }
            }
    
            ++entries_count;
            NRF_LOG_FLUSH();
        } while (fno.fname[0]);
    
    
        NRF_LOG_RAW_INFO("Entries count: %u\r\n", entries_count);
    }
    
    static void fatfs_create_test_file(void)
    {
        FRESULT ff_result;
        FIL file;
        uint32_t file_size = 0;
    
    
        ff_result = f_open(&file, "log_data.txt", FA_READ);
        if (ff_result != FR_OK)
        {
            NRF_LOG_ERROR("log_data.txt Does not exist\r\n");
            NRF_LOG_INFO("Creating log_data.txt");
            ff_result = f_open(&file, "log_data.txt", FA_CREATE_ALWAYS | FA_WRITE);
            if (ff_result != FR_OK)
            {
                if(!m_usb_connected)
                    NRF_LOG_ERROR("Unable to open or create file: log_data.txt");
                NRF_LOG_FLUSH();
                return;
            }
        }
    
        ff_result = f_close(&file);
        if (ff_result != FR_OK)
        {
            NRF_LOG_ERROR("Unable to close file: %u \r\n", ff_result);
            NRF_LOG_FLUSH();
            return;
        }
    
        file_size = f_size(&file);
        NRF_LOG_INFO("log_data.txt create SUCCESSFUL; file size = %d\r\n", file_size);
    }
    
    static uint32_t record_number = 0; //Record number for stored data
    static volatile bool write_file = false;
    
    static void log_data_write_handler(void * p_context)
    {
        write_file = true;
    }
    
    static void write(void)
    {
        int i = 0;
        char log_record[128] = {0};
        char log_record_r[128] = {0};
    
        FRESULT ff_result;
        FIL file;
        uint32_t fileSize;
        	uint32_t num;
    
        ff_result = f_open(&file, "log_data.txt", FA_OPEN_APPEND | FA_OPEN_ALWAYS | FA_WRITE | FA_READ);
        if (ff_result != FR_OK)
        {
            if(!m_usb_connected)
                NRF_LOG_INFO("Unable to open or create log_data.txt: %u", ff_result);
            NRF_LOG_FLUSH();
            return;
        }
    
        ++record_number;
    //    sprintf(log_record, "%d,%d,%d\r\n", record_number,rand(),rand());
        sprintf(log_record, "1234567890123456789012345678901234567890%d\r\n", record_number+10000000);
        //if (record_number>276 && record_number<290)
    
        FSIZE_t ptr = f_tell(&file);
    //    NRF_LOG_INFO("Pointer: %lu", ptr);
        
    	
    	//i = f_printf(&file, log_record);
    	
    	i =  f_write(&file, log_record, strlen(log_record), &num);
    	
    //    if (i != 50)
    //    {
    //      NRF_LOG_INFO("f_printf != EOF, %d, %d, %d", i, record_number, sizeof(log_record));
    //    }
    //    NRF_LOG_INFO("AW: Pointer: %lu",f_tell(&file));
    //    f_lseek(&file, ptr);
    //    NRF_LOG_INFO("LS: Pointer: %lu",f_tell(&file));
    
    //    if (record_number>2)
    //    {
    //        f_gets(log_record_r, 50, &file);
    //        if (strcmp(log_record, log_record_r) != 0) {
    //
    //            NRF_LOG_INFO("Records are corrupted");
    //        }
    //
    //    }
    
        i = f_close(&file);
        if (i != 0)
        {
          NRF_LOG_INFO("f_close != 0, %d, %d", i, record_number);
        }
    
        NRF_LOG_INFO("Wrote Data Record: %d", record_number);
    }
    
    static void log_timer_stop(void)
    {
        write_file = false;
        app_timer_stop(log_timer_id);
    } 
    
    static void log_timer_start(uint32_t ticks)
    {
        ret_code_t err_code;
    
        log_timer_stop();
    
        err_code = app_timer_start(log_timer_id, APP_TIMER_TICKS(ticks), NULL);
        APP_ERROR_CHECK(err_code);
    }
    
    static void log_timer_init(void)
    {
        ret_code_t err_code;
        err_code = app_timer_create(&log_timer_id, APP_TIMER_MODE_REPEATED, log_data_write_handler);
        APP_ERROR_CHECK(err_code);
    }
    
    
    static void fatfs_file_create(void)
    {
        FRESULT ff_result;
        FIL file;
        char filename[16];
    
        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 ...", (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;
        }
    
        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");
    }
    
    static void fatfs_uninit(void)
    {
        NRF_LOG_INFO("Un-initializing disk 0 (QSPI)...");
        UNUSED_RETURN_VALUE(disk_uninitialize(0));
    }
    #else //USE_FATFS_QSPI
    #define fatfs_init()        false
    #define fatfs_mkfs()        do { } while (0)
    #define fatfs_ls()          do { } while (0)
    #define fatfs_file_create() do { } while (0)
    #define fatfs_uninit()      do { } while (0)
    #endif
    
    /**
     * @brief Class specific event handler.
     *
     * @param p_inst    Class instance.
     * @param event     Class specific event.
     */
    static void msc_user_ev_handler(app_usbd_class_inst_t const * p_inst,
                                    app_usbd_msc_user_event_t     event)
    {
        UNUSED_PARAMETER(p_inst);
        UNUSED_PARAMETER(event);
    }
    
    /**
     * @brief USBD library specific event handler.
     *
     * @param event     USBD library event.
     */
    static void usbd_user_ev_handler(app_usbd_event_type_t event)
    {
        switch (event)
        {
            case APP_USBD_EVT_DRV_SUSPEND:
                bsp_board_led_off(LED_USB_RESUME);
                break;
            case APP_USBD_EVT_DRV_RESUME:
                bsp_board_led_on(LED_USB_RESUME);
                break;
            case APP_USBD_EVT_STARTED:
                bsp_board_led_on(LED_USB_START);
                break;
            case APP_USBD_EVT_STOPPED:
                UNUSED_RETURN_VALUE(fatfs_init());
                app_usbd_disable();
                bsp_board_leds_off();
                break;
            case APP_USBD_EVT_POWER_DETECTED:
                NRF_LOG_INFO("USB power detected");
                log_timer_stop();
                if (!nrf_drv_usbd_is_enabled())
                {
                    fatfs_uninit();
                    app_usbd_enable();
                }
                break;
            case APP_USBD_EVT_POWER_REMOVED:
                NRF_LOG_INFO("USB power removed");
                app_usbd_stop();
                m_usb_connected = false;
                log_timer_start(LOG_TIMER_TICKS);
                break;
            case APP_USBD_EVT_POWER_READY:
                NRF_LOG_INFO("USB ready");
                app_usbd_start();
                m_usb_connected = true;
                break;
            default:
                break;
        }
    }
    
    static void bsp_event_callback(bsp_event_t ev)
    {
        switch (ev)
        {
            /* Just set a flag to be processed in the main loop */
            case CONCAT_2(BSP_EVENT_KEY_, BTN_RANDOM_FILE):
                UNUSED_RETURN_VALUE(nrf_atomic_u32_or(&m_key_events, KEY_EV_RANDOM_FILE_MSK));
                break;
    
            case CONCAT_2(BSP_EVENT_KEY_, BTN_LIST_DIR):
                UNUSED_RETURN_VALUE(nrf_atomic_u32_or(&m_key_events, KEY_EV_LIST_DIR_MSK));
                break;
    
            case CONCAT_2(BSP_EVENT_KEY_, BTN_MKFS):
                UNUSED_RETURN_VALUE(nrf_atomic_u32_or(&m_key_events, KEY_EV_MKFS_MSK));
                break;
    
            default:
                return; // no implementation needed
        }
    }
    
    
    int main(void)
    {
        ret_code_t ret;
    
        APP_SCHED_INIT(32, 20);
    
        static const app_usbd_config_t usbd_config = {
            .ev_state_proc = usbd_user_ev_handler
        };
    
        ret = NRF_LOG_INIT(app_usbd_sof_timestamp_get);
        APP_ERROR_CHECK(ret);
        NRF_LOG_DEFAULT_BACKENDS_INIT();
    
        ret = nrf_drv_clock_init();
        APP_ERROR_CHECK(ret);
    
        /* Fill whole RAM block device buffer */
        for (size_t i = 0; i < sizeof(m_block_dev_ram_buff); ++i)
        {
            m_block_dev_ram_buff[i] = i;
        }
    
        /* Configure LEDs and buttons */
        nrf_drv_clock_lfclk_request(NULL);
        ret = app_timer_init();
        APP_ERROR_CHECK(ret);
        log_timer_init(); //Create timer for log generation
    
        ret = bsp_init(BSP_INIT_BUTTONS, bsp_event_callback);
        APP_ERROR_CHECK(ret);
        bsp_board_init(BSP_INIT_LEDS);
    
        if (fatfs_init())
        {
            fatfs_ls();
    //        fatfs_file_create();
            fatfs_create_test_file();
        }
    
        ret = app_usbd_init(&usbd_config);
        APP_ERROR_CHECK(ret);
    
        app_usbd_class_inst_t const * class_inst_msc = app_usbd_msc_class_inst_get(&m_app_msc);
        ret = app_usbd_class_append(class_inst_msc);
        APP_ERROR_CHECK(ret);
    
        NRF_LOG_INFO("USBD MSC example started.");
    
        if (USBD_POWER_DETECTION)
        {
            ret = app_usbd_power_events_enable();
            APP_ERROR_CHECK(ret);
        }
        else
        {
            NRF_LOG_INFO("No USB power detection enabled\r\nStarting USB now");
    
            app_usbd_enable();
            app_usbd_start();
            m_usb_connected = true;
        }
    
        log_timer_start(LOG_TIMER_TICKS); //Start repeated timer for every 500ms
        while (true)
        {
            if(!app_usbd_event_queue_process())
            {
                app_sched_execute();
            }
            
            if (write_file) {
                write_file = false;
                write();
            }
    
            /* Process BSP key events flags.*/
            uint32_t events = nrf_atomic_u32_fetch_store(&m_key_events, 0);
    //        if (events & KEY_EV_RANDOM_FILE_MSK)
    //        {
    //            fatfs_file_create();
    //        }
    //
            if (events & KEY_EV_LIST_DIR_MSK)
            {
                fatfs_ls();
            }
    //
            if (events & KEY_EV_MKFS_MSK)
            {
                fatfs_mkfs();
                record_number = 0;
            }
    //
            NRF_LOG_FLUSH();
            /* Sleep CPU only if there was no interrupt since last loop processing */
            __WFE();
        }
    }
    
    /** @} */
    
    [07/09/20 - 19:57:10:732] [00:00:00.000,000] <info> app_timer: RTC: initialized.
    [07/09/20 - 19:57:10:738] [00:00:00.000,000] <info> app: Initializing disk 0 (QSPI)...
    [07/09/20 - 19:57:10:743] [00:00:00.000,000] <info> app: Mounting volume...
    [07/09/20 - 19:57:10:746] [00:00:00.000,000] <info> app:
    [07/09/20 - 19:57:10:748] Listing directory: /
    [07/09/20 - 19:57:10:750]     22400  LOG_DATA.TXT
    [07/09/20 - 19:57:10:754]    <DIR>   SYSTEM~1
    [07/09/20 - 19:57:10:754] Entries count: 3
    [07/09/20 - 19:57:10:761] [00:00:00.000,000] <info> app: log_data.txt create SUCCESSFUL; file size = 22400
    [07/09/20 - 19:57:10:762]
    [07/09/20 - 19:57:10:767] [00:00:00.000,000] <info> app: USBD MSC example started.
    [07/09/20 - 19:57:11:595] [00:00:00.000,000] <info> app: Wrote Data Record: 1
    [07/09/20 - 19:57:12:093] [00:00:00.000,000] <info> app: Wrote Data Record: 2
    [07/09/20 - 19:57:12:590] [00:00:00.000,000] <info> app: Wrote Data Record: 3
    [07/09/20 - 19:57:13:093] [00:00:00.000,000] <info> app: Wrote Data Record: 4
    [07/09/20 - 19:57:13:593] [00:00:00.000,000] <info> app: Wrote Data Record: 5
    [07/09/20 - 19:57:14:096] [00:00:00.000,000] <info> app: Wrote Data Record: 6
    [07/09/20 - 19:57:14:589] [00:00:00.000,000] <info> app: Wrote Data Record: 7
    [07/09/20 - 19:57:15:092] [00:00:00.000,000] <info> app: Wrote Data Record: 8
    [07/09/20 - 19:57:15:592] [00:00:00.000,000] <info> app: Wrote Data Record: 9
    [07/09/20 - 19:57:16:092] [00:00:00.000,000] <info> app: Wrote Data Record: 10
    [07/09/20 - 19:57:16:589] [00:00:00.000,000] <info> app: Wrote Data Record: 11
    [07/09/20 - 19:57:17:093] [00:00:00.000,000] <info> app: Wrote Data Record: 12
    [07/09/20 - 19:57:17:596] [00:00:00.000,000] <info> app: Wrote Data Record: 13
    [07/09/20 - 19:57:18:096] [00:00:00.000,000] <info> app: Wrote Data Record: 14
    [07/09/20 - 19:57:18:589] [00:00:00.000,000] <info> app: Wrote Data Record: 15
    [07/09/20 - 19:57:19:092] [00:00:00.000,000] <info> app: Wrote Data Record: 16
    [07/09/20 - 19:57:19:591] [00:00:00.000,000] <info> app: Wrote Data Record: 17
    [07/09/20 - 19:57:20:097] [00:00:00.000,000] <info> app: Wrote Data Record: 18
    [07/09/20 - 19:57:20:588] [00:00:00.000,000] <info> app: Wrote Data Record: 19
    [07/09/20 - 19:57:21:091] [00:00:00.000,000] <info> app: Wrote Data Record: 20
    [07/09/20 - 19:57:21:592] [00:00:00.000,000] <info> app: Wrote Data Record: 21
    [07/09/20 - 19:57:22:095] [00:00:00.000,000] <info> app: Wrote Data Record: 22
    [07/09/20 - 19:57:22:588] [00:00:00.000,000] <info> app: Wrote Data Record: 23
    [07/09/20 - 19:57:23:094] [00:00:00.000,000] <info> app: Wrote Data Record: 24
    [07/09/20 - 19:57:23:590] [00:00:00.000,000] <info> app: Wrote Data Record: 25
    [07/09/20 - 19:57:24:090] [00:00:00.000,000] <info> app: Wrote Data Record: 26
    [07/09/20 - 19:57:24:591] [00:00:00.000,000] <info> app: Wrote Data Record: 27
    [07/09/20 - 19:57:25:091] [00:00:00.000,000] <info> app: Wrote Data Record: 28
    [07/09/20 - 19:57:25:591] [00:00:00.000,000] <info> app: Wrote Data Record: 29
    [07/09/20 - 19:57:26:090] [00:00:00.000,000] <info> app: Wrote Data Record: 30
    [07/09/20 - 19:57:26:587] [00:00:00.000,000] <info> app: Wrote Data Record: 31
    [07/09/20 - 19:57:27:090] [00:00:00.000,000] <info> app: Wrote Data Record: 32
    [07/09/20 - 19:57:27:589] [00:00:00.000,000] <info> app: Wrote Data Record: 33
    [07/09/20 - 19:57:28:086] [00:00:00.000,000] <info> app: Wrote Data Record: 34
    [07/09/20 - 19:57:28:585] [00:00:00.000,000] <info> app: Wrote Data Record: 35
    [07/09/20 - 19:57:29:092] [00:00:00.000,000] <info> app: Wrote Data Record: 36
    [07/09/20 - 19:57:29:588] [00:00:00.000,000] <info> app: Wrote Data Record: 37
    [07/09/20 - 19:57:30:088] [00:00:00.000,000] <info> app: Wrote Data Record: 38
    [07/09/20 - 19:57:30:584] [00:00:00.000,000] <info> app: Wrote Data Record: 39
    [07/09/20 - 19:57:31:088] [00:00:00.000,000] <info> app: Wrote Data Record: 40
    [07/09/20 - 19:57:31:587] [00:00:00.000,000] <info> app: Wrote Data Record: 41
    [07/09/20 - 19:57:32:087] [00:00:00.000,000] <info> app: Wrote Data Record: 42
    [07/09/20 - 19:57:32:585] [00:00:00.000,000] <info> app: Wrote Data Record: 43
    [07/09/20 - 19:57:33:084] [00:00:00.000,000] <info> app: Wrote Data Record: 44
    [07/09/20 - 19:57:33:586] [00:00:00.000,000] <info> app: Wrote Data Record: 45
    [07/09/20 - 19:57:34:086] [00:00:00.000,000] <info> app: Wrote Data Record: 46
    [07/09/20 - 19:57:34:588] [00:00:00.000,000] <info> app: Wrote Data Record: 47
    [07/09/20 - 19:57:35:085] [00:00:00.000,000] <info> app: Wrote Data Record: 48
    [07/09/20 - 19:57:35:591] [00:00:00.000,000] <info> app: Wrote Data Record: 49
    [07/09/20 - 19:57:36:086] [00:00:00.000,000] <info> app: Wrote Data Record: 50
    [07/09/20 - 19:57:36:582] [00:00:00.000,000] <info> app: Wrote Data Record: 51
    [07/09/20 - 19:57:37:090] [00:00:00.000,000] <info> app: Wrote Data Record: 52
    [07/09/20 - 19:57:37:586] [00:00:00.000,000] <info> app: Wrote Data Record: 53
    [07/09/20 - 19:57:38:081] [00:00:00.000,000] <info> app: Wrote Data Record: 54
    [07/09/20 - 19:57:38:581] [00:00:00.000,000] <info> app: Wrote Data Record: 55
    [07/09/20 - 19:57:39:084] [00:00:00.000,000] <info> app: Wrote Data Record: 56
    [07/09/20 - 19:57:39:584] [00:00:00.000,000] <info> app: Wrote Data Record: 57
    [07/09/20 - 19:57:40:088] [00:00:00.000,000] <info> app: Wrote Data Record: 58
    [07/09/20 - 19:57:40:585] [00:00:00.000,000] <info> app: Wrote Data Record: 59
    [07/09/20 - 19:57:41:084] [00:00:00.000,000] <info> app: Wrote Data Record: 60
    [07/09/20 - 19:57:41:584] [00:00:00.000,000] <info> app: Wrote Data Record: 61
    [07/09/20 - 19:57:42:088] [00:00:00.000,000] <info> app: Wrote Data Record: 62
    [07/09/20 - 19:57:42:580] [00:00:00.000,000] <info> app: Wrote Data Record: 63
    [07/09/20 - 19:57:43:084] [00:00:00.000,000] <info> app: Wrote Data Record: 64
    [07/09/20 - 19:57:43:589] [00:00:00.000,000] <info> app: Wrote Data Record: 65
    [07/09/20 - 19:57:44:090] [00:00:00.000,000] <info> app: Wrote Data Record: 66
    [07/09/20 - 19:57:44:586] [00:00:00.000,000] <info> app: Wrote Data Record: 67
    [07/09/20 - 19:57:45:093] [00:00:00.000,000] <info> app: Wrote Data Record: 68
    [07/09/20 - 19:57:45:588] [00:00:00.000,000] <info> app: Wrote Data Record: 69
    [07/09/20 - 19:57:46:087] [00:00:00.000,000] <info> app: Wrote Data Record: 70
    [07/09/20 - 19:57:46:584] [00:00:00.000,000] <info> app: Wrote Data Record: 71
    [07/09/20 - 19:57:47:091] [00:00:00.000,000] <info> app: Wrote Data Record: 72
    [07/09/20 - 19:57:47:586] [00:00:00.000,000] <info> app: Wrote Data Record: 73
    [07/09/20 - 19:57:48:091] [00:00:00.000,000] <info> app: Wrote Data Record: 74
    [07/09/20 - 19:57:48:587] [00:00:00.000,000] <info> app: Wrote Data Record: 75
    [07/09/20 - 19:57:49:090] [00:00:00.000,000] <info> app: Wrote Data Record: 76
    [07/09/20 - 19:57:49:590] [00:00:00.000,000] <info> app: Wrote Data Record: 77
    [07/09/20 - 19:57:50:090] [00:00:00.000,000] <info> app: Wrote Data Record: 78
    [07/09/20 - 19:57:50:582] [00:00:00.000,000] <info> app: Wrote Data Record: 79
    [07/09/20 - 19:57:51:085] [00:00:00.000,000] <info> app: Wrote Data Record: 80
    [07/09/20 - 19:57:51:585] [00:00:00.000,000] <info> app: Wrote Data Record: 81
    [07/09/20 - 19:57:52:085] [00:00:00.000,000] <info> app: Wrote Data Record: 82
    [07/09/20 - 19:57:52:582] [00:00:00.000,000] <info> app: Wrote Data Record: 83
    [07/09/20 - 19:57:53:085] [00:00:00.000,000] <info> app: Wrote Data Record: 84
    [07/09/20 - 19:57:53:585] [00:00:00.000,000] <info> app: Wrote Data Record: 85
    [07/09/20 - 19:57:54:085] [00:00:00.000,000] <info> app: Wrote Data Record: 86
    [07/09/20 - 19:57:54:582] [00:00:00.000,000] <info> app: Wrote Data Record: 87
    [07/09/20 - 19:57:55:085] [00:00:00.000,000] <info> app: Wrote Data Record: 88
    [07/09/20 - 19:57:55:589] [00:00:00.000,000] <info> app: Wrote Data Record: 89
    [07/09/20 - 19:57:56:085] [00:00:00.000,000] <info> app: Wrote Data Record: 90
    [07/09/20 - 19:57:56:589] [00:00:00.000,000] <info> app: Wrote Data Record: 91
    [07/09/20 - 19:57:57:084] [00:00:00.000,000] <info> app: Wrote Data Record: 92
    [07/09/20 - 19:57:57:584] [00:00:00.000,000] <info> app: Wrote Data Record: 93
    [07/09/20 - 19:57:58:091] [00:00:00.000,000] <info> app: Wrote Data Record: 94
    [07/09/20 - 19:57:58:580] [00:00:00.000,000] <info> app: Wrote Data Record: 95
    [07/09/20 - 19:57:59:092] [00:00:00.000,000] <info> app: Wrote Data Record: 96
    [07/09/20 - 19:57:59:591] [00:00:00.000,000] <info> app: Wrote Data Record: 97
    [07/09/20 - 19:58:00:091] [00:00:00.000,000] <info> app: Wrote Data Record: 98
    [07/09/20 - 19:58:00:581] [00:00:00.000,000] <info> app: Wrote Data Record: 99
    [07/09/20 - 19:58:01:091] [00:00:00.000,000] <info> app: Wrote Data Record: 100
    [07/09/20 - 19:58:01:591] [00:00:00.000,000] <info> app: Wrote Data Record: 101
    [07/09/20 - 19:58:02:091] [00:00:00.000,000] <info> app: Wrote Data Record: 102
    [07/09/20 - 19:58:02:588] [00:00:00.000,000] <info> app: Wrote Data Record: 103
    [07/09/20 - 19:58:03:091] [00:00:00.000,000] <info> app: Wrote Data Record: 104
    [07/09/20 - 19:58:03:588] [00:00:00.000,000] <info> app: Wrote Data Record: 105
    [07/09/20 - 19:58:04:089] [00:00:00.000,000] <info> app: Wrote Data Record: 106
    [07/09/20 - 19:58:04:586] [00:00:00.000,000] <info> app: Wrote Data Record: 107
    [07/09/20 - 19:58:05:090] [00:00:00.000,000] <info> app: Wrote Data Record: 108
    [07/09/20 - 19:58:05:589] [00:00:00.000,000] <info> app: Wrote Data Record: 109
    [07/09/20 - 19:58:06:089] [00:00:00.000,000] <info> app: Wrote Data Record: 110
    [07/09/20 - 19:58:06:587] [00:00:00.000,000] <info> app: Wrote Data Record: 111
    [07/09/20 - 19:58:07:089] [00:00:00.000,000] <info> app: Wrote Data Record: 112
    [07/09/20 - 19:58:07:589] [00:00:00.000,000] <info> app: Wrote Data Record: 113
    [07/09/20 - 19:58:08:089] [00:00:00.000,000] <info> app: Wrote Data Record: 114
    [07/09/20 - 19:58:08:586] [00:00:00.000,000] <info> app: Wrote Data Record: 115
    [07/09/20 - 19:58:09:089] [00:00:00.000,000] <info> app: Wrote Data Record: 116
    [07/09/20 - 19:58:09:589] [00:00:00.000,000] <info> app: Wrote Data Record: 117
    [07/09/20 - 19:58:10:089] [00:00:00.000,000] <info> app: Wrote Data Record: 118
    [07/09/20 - 19:58:10:585] [00:00:00.000,000] <info> app: Wrote Data Record: 119
    [07/09/20 - 19:58:11:089] [00:00:00.000,000] <info> app: Wrote Data Record: 120
    [07/09/20 - 19:58:11:589] [00:00:00.000,000] <info> app: Wrote Data Record: 121
    [07/09/20 - 19:58:12:088] [00:00:00.000,000] <info> app: Wrote Data Record: 122
    [07/09/20 - 19:58:12:585] [00:00:00.000,000] <info> app: Wrote Data Record: 123
    [07/09/20 - 19:58:13:089] [00:00:00.000,000] <info> app: Wrote Data Record: 124
    [07/09/20 - 19:58:13:583] [00:00:00.000,000] <info> app: Wrote Data Record: 125
    [07/09/20 - 19:58:14:085] [00:00:00.000,000] <info> app: Wrote Data Record: 126
    [07/09/20 - 19:58:14:584] [00:00:00.000,000] <info> app: Wrote Data Record: 127
    [07/09/20 - 19:58:15:082] [00:00:00.000,000] <info> app: Wrote Data Record: 128
    [07/09/20 - 19:58:15:587] [00:00:00.000,000] <info> app: Wrote Data Record: 129
    [07/09/20 - 19:58:16:087] [00:00:00.000,000] <info> app: Wrote Data Record: 130
    [07/09/20 - 19:58:16:583] [00:00:00.000,000] <info> app: Wrote Data Record: 131
    [07/09/20 - 19:58:17:082] [00:00:00.000,000] <info> app: Wrote Data Record: 132
    [07/09/20 - 19:58:17:587] [00:00:00.000,000] <info> app: Wrote Data Record: 133
    [07/09/20 - 19:58:18:086] [00:00:00.000,000] <info> app: Wrote Data Record: 134
    [07/09/20 - 19:58:18:583] [00:00:00.000,000] <info> app: Wrote Data Record: 135
    [07/09/20 - 19:58:19:085] [00:00:00.000,000] <info> app: Wrote Data Record: 136
    [07/09/20 - 19:58:19:587] [00:00:00.000,000] <info> app: Wrote Data Record: 137
    [07/09/20 - 19:58:20:087] [00:00:00.000,000] <info> app: Wrote Data Record: 138
    [07/09/20 - 19:58:20:582] [00:00:00.000,000] <info> app: Wrote Data Record: 139
    [07/09/20 - 19:58:21:086] [00:00:00.000,000] <info> app: Wrote Data Record: 140
    [07/09/20 - 19:58:21:586] [00:00:00.000,000] <info> app: Wrote Data Record: 141
    [07/09/20 - 19:58:22:085] [00:00:00.000,000] <info> app: Wrote Data Record: 142
    [07/09/20 - 19:58:22:583] [00:00:00.000,000] <info> app: Wrote Data Record: 143
    [07/09/20 - 19:58:23:086] [00:00:00.000,000] <info> app: Wrote Data Record: 144
    [07/09/20 - 19:58:23:585] [00:00:00.000,000] <info> app: Wrote Data Record: 145
    [07/09/20 - 19:58:24:243] [00:00:00.000,000] <info> app: Wrote Data Record: 146
    [07/09/20 - 19:58:24:588] [00:00:00.000,000] <info> app: Wrote Data Record: 147
    [07/09/20 - 19:58:25:090] [00:00:00.000,000] <info> app: Wrote Data Record: 148
    [07/09/20 - 19:58:25:589] [00:00:00.000,000] <info> app: Wrote Data Record: 149
    [07/09/20 - 19:58:26:090] [00:00:00.000,000] <info> app: Wrote Data Record: 150
    [07/09/20 - 19:58:26:586] [00:00:00.000,000] <info> app: Wrote Data Record: 151
    [07/09/20 - 19:58:27:089] [00:00:00.000,000] <info> app: Wrote Data Record: 152
    [07/09/20 - 19:58:27:589] [00:00:00.000,000] <info> app: Wrote Data Record: 153
    [07/09/20 - 19:58:28:093] [00:00:00.000,000] <info> app: Wrote Data Record: 154
    [07/09/20 - 19:58:28:585] [00:00:00.000,000] <info> app: Wrote Data Record: 155
    [07/09/20 - 19:58:29:088] [00:00:00.000,000] <info> app: Wrote Data Record: 156
    [07/09/20 - 19:58:29:587] [00:00:00.000,000] <info> app: Wrote Data Record: 157
    [07/09/20 - 19:58:30:092] [00:00:00.000,000] <info> app: Wrote Data Record: 158
    [07/09/20 - 19:58:30:585] [00:00:00.000,000] <info> app: Wrote Data Record: 159
    [07/09/20 - 19:58:31:087] [00:00:00.000,000] <info> app: Wrote Data Record: 160
    [07/09/20 - 19:58:31:586] [00:00:00.000,000] <info> app: Wrote Data Record: 161
    [07/09/20 - 19:58:32:087] [00:00:00.000,000] <info> app: Wrote Data Record: 162
    [07/09/20 - 19:58:32:584] [00:00:00.000,000] <info> app: Wrote Data Record: 163
    [07/09/20 - 19:58:33:091] [00:00:00.000,000] <info> app: Wrote Data Record: 164
    [07/09/20 - 19:58:33:586] [00:00:00.000,000] <info> app: Wrote Data Record: 165
    [07/09/20 - 19:58:34:086] [00:00:00.000,000] <info> app: Wrote Data Record: 166
    [07/09/20 - 19:58:34:583] [00:00:00.000,000] <info> app: Wrote Data Record: 167
    [07/09/20 - 19:58:35:085] [00:00:00.000,000] <info> app: Wrote Data Record: 168
    [07/09/20 - 19:58:35:590] [00:00:00.000,000] <info> app: Wrote Data Record: 169
    [07/09/20 - 19:58:36:086] [00:00:00.000,000] <info> app: Wrote Data Record: 170
    [07/09/20 - 19:58:36:586] [00:00:00.000,000] <info> app: Wrote Data Record: 171
    [07/09/20 - 19:58:37:090] [00:00:00.000,000] <info> app: Wrote Data Record: 172
    [07/09/20 - 19:58:37:589] [00:00:00.000,000] <info> app: Wrote Data Record: 173
    [07/09/20 - 19:58:38:084] [00:00:00.000,000] <info> app: Wrote Data Record: 174
    [07/09/20 - 19:58:38:582] [00:00:00.000,000] <info> app: Wrote Data Record: 175
    [07/09/20 - 19:58:39:085] [00:00:00.000,000] <info> app: Wrote Data Record: 176
    [07/09/20 - 19:58:39:588] [00:00:00.000,000] <info> app: Wrote Data Record: 177
    [07/09/20 - 19:58:40:084] [00:00:00.000,000] <info> app: Wrote Data Record: 178
    [07/09/20 - 19:58:40:581] [00:00:00.000,000] <info> app: Wrote Data Record: 179
    [07/09/20 - 19:58:41:084] [00:00:00.000,000] <info> app: Wrote Data Record: 180
    [07/09/20 - 19:58:41:584] [00:00:00.000,000] <info> app: Wrote Data Record: 181
    [07/09/20 - 19:58:42:089] [00:00:00.000,000] <info> app: Wrote Data Record: 182
    [07/09/20 - 19:58:42:586] [00:00:00.000,000] <info> app: Wrote Data Record: 183
    [07/09/20 - 19:58:43:084] [00:00:00.000,000] <info> app: Wrote Data Record: 184
    [07/09/20 - 19:58:43:583] [00:00:00.000,000] <info> app: Wrote Data Record: 185
    [07/09/20 - 19:58:44:084] [00:00:00.000,000] <info> app: Wrote Data Record: 186
    [07/09/20 - 19:58:44:578] [00:00:00.000,000] <info> app: Wrote Data Record: 187
    [07/09/20 - 19:58:45:086] [00:00:00.000,000] <info> app: Wrote Data Record: 188
    [07/09/20 - 19:58:45:582] [00:00:00.000,000] <info> app: Wrote Data Record: 189
    [07/09/20 - 19:58:46:082] [00:00:00.000,000] <info> app: Wrote Data Record: 190
    [07/09/20 - 19:58:46:579] [00:00:00.000,000] <info> app: Wrote Data Record: 191
    [07/09/20 - 19:58:47:082] [00:00:00.000,000] <info> app: Wrote Data Record: 192
    [07/09/20 - 19:58:47:582] [00:00:00.000,000] <info> app: Wrote Data Record: 193
    [07/09/20 - 19:58:48:082] [00:00:00.000,000] <info> app: Wrote Data Record: 194
    [07/09/20 - 19:58:48:579] [00:00:00.000,000] <info> app: Wrote Data Record: 195
    [07/09/20 - 19:58:49:086] [00:00:00.000,000] <info> app: Wrote Data Record: 196
    [07/09/20 - 19:58:49:586] [00:00:00.000,000] <info> app: Wrote Data Record: 197
    [07/09/20 - 19:58:50:082] [00:00:00.000,000] <info> app: Wrote Data Record: 198
    [07/09/20 - 19:58:50:583] [00:00:00.000,000] <info> app: Wrote Data Record: 199
    [07/09/20 - 19:58:51:082] [00:00:00.000,000] <info> app: Wrote Data Record: 200
    [07/09/20 - 19:58:51:581] [00:00:00.000,000] <info> app: Wrote Data Record: 201
    [07/09/20 - 19:58:52:082] [00:00:00.000,000] <info> app: Wrote Data Record: 202
    [07/09/20 - 19:58:52:579] [00:00:00.000,000] <info> app: Wrote Data Record: 203
    [07/09/20 - 19:58:53:081] [00:00:00.000,000] <info> app: Wrote Data Record: 204
    [07/09/20 - 19:58:53:581] [00:00:00.000,000] <info> app: Wrote Data Record: 205
    [07/09/20 - 19:58:54:085] [00:00:00.000,000] <info> app: Wrote Data Record: 206
    [07/09/20 - 19:58:54:578] [00:00:00.000,000] <info> app: Wrote Data Record: 207
    [07/09/20 - 19:58:55:078] [00:00:00.000,000] <info> app: Wrote Data Record: 208
    [07/09/20 - 19:58:55:584] [00:00:00.000,000] <info> app: Wrote Data Record: 209
    [07/09/20 - 19:58:56:084] [00:00:00.000,000] <info> app: Wrote Data Record: 210
    [07/09/20 - 19:58:56:578] [00:00:00.000,000] <info> app: Wrote Data Record: 211
    [07/09/20 - 19:58:57:079] [00:00:00.000,000] <info> app: Wrote Data Record: 212
    [07/09/20 - 19:58:57:579] [00:00:00.000,000] <info> app: Wrote Data Record: 213
    [07/09/20 - 19:58:58:080] [00:00:00.000,000] <info> app: Wrote Data Record: 214
    [07/09/20 - 19:58:58:577] [00:00:00.000,000] <info> app: Wrote Data Record: 215
    [07/09/20 - 19:58:59:079] [00:00:00.000,000] <info> app: Wrote Data Record: 216
    [07/09/20 - 19:58:59:580] [00:00:00.000,000] <info> app: Wrote Data Record: 217
    [07/09/20 - 19:59:00:079] [00:00:00.000,000] <info> app: Wrote Data Record: 218
    [07/09/20 - 19:59:00:576] [00:00:00.000,000] <info> app: Wrote Data Record: 219
    [07/09/20 - 19:59:01:080] [00:00:00.000,000] <info> app: Wrote Data Record: 220
    [07/09/20 - 19:59:01:579] [00:00:00.000,000] <info> app: Wrote Data Record: 221
    [07/09/20 - 19:59:02:079] [00:00:00.000,000] <info> app: Wrote Data Record: 222
    [07/09/20 - 19:59:02:577] [00:00:00.000,000] <info> app: Wrote Data Record: 223
    [07/09/20 - 19:59:03:080] [00:00:00.000,000] <info> app: Wrote Data Record: 224
    [07/09/20 - 19:59:03:578] [00:00:00.000,000] <info> app: Wrote Data Record: 225
    [07/09/20 - 19:59:04:080] [00:00:00.000,000] <info> app: Wrote Data Record: 226
    [07/09/20 - 19:59:04:580] [00:00:00.000,000] <info> app: Wrote Data Record: 227
    [07/09/20 - 19:59:05:236] [00:00:00.000,000] <info> app: Wrote Data Record: 228
    [07/09/20 - 19:59:05:594] [00:00:00.000,000] <info> app: Wrote Data Record: 229
    [07/09/20 - 19:59:06:085] [00:00:00.000,000] <info> app: Wrote Data Record: 230
    [07/09/20 - 19:59:06:587] [00:00:00.000,000] <info> app: Wrote Data Record: 231
    [07/09/20 - 19:59:07:089] [00:00:00.000,000] <info> app: Wrote Data Record: 232
    [07/09/20 - 19:59:07:587] [00:00:00.000,000] <info> app: Wrote Data Record: 233
    [07/09/20 - 19:59:08:084] [00:00:00.000,000] <info> app: Wrote Data Record: 234
    [07/09/20 - 19:59:08:588] [00:00:00.000,000] <info> app: Wrote Data Record: 235
    [07/09/20 - 19:59:09:087] [00:00:00.000,000] <info> app: Wrote Data Record: 236
    [07/09/20 - 19:59:09:591] [00:00:00.000,000] <info> app: Wrote Data Record: 237
    [07/09/20 - 19:59:10:084] [00:00:00.000,000] <info> app: Wrote Data Record: 238
    [07/09/20 - 19:59:10:586] [00:00:00.000,000] <info> app: Wrote Data Record: 239
    [07/09/20 - 19:59:11:090] [00:00:00.000,000] <info> app: Wrote Data Record: 240
    [07/09/20 - 19:59:11:591] [00:00:00.000,000] <info> app: Wrote Data Record: 241
    [07/09/20 - 19:59:12:091] [00:00:00.000,000] <info> app: Wrote Data Record: 242
    [07/09/20 - 19:59:12:599] [00:00:00.000,000] <info> app: Wrote Data Record: 243
    [07/09/20 - 19:59:13:090] [00:00:00.000,000] <info> app: Wrote Data Record: 244
    [07/09/20 - 19:59:13:593] [00:00:00.000,000] <info> app: Wrote Data Record: 245
    [07/09/20 - 19:59:14:096] [00:00:00.000,000] <info> app: Wrote Data Record: 246
    [07/09/20 - 19:59:14:598] [00:00:00.000,000] <info> app: Wrote Data Record: 247
    [07/09/20 - 19:59:15:093] [00:00:00.000,000] <info> app: Wrote Data Record: 248
    [07/09/20 - 19:59:15:594] [00:00:00.000,000] <info> app: Wrote Data Record: 249
    [07/09/20 - 19:59:16:090] [00:00:00.000,000] <info> app: Wrote Data Record: 250
    [07/09/20 - 19:59:16:597] [00:00:00.000,000] <info> app: Wrote Data Record: 251
    [07/09/20 - 19:59:17:098] [00:00:00.000,000] <info> app: Wrote Data Record: 252
    [07/09/20 - 19:59:17:593] [00:00:00.000,000] <info> app: Wrote Data Record: 253
    [07/09/20 - 19:59:18:094] [00:00:00.000,000] <info> app: Wrote Data Record: 254
    [07/09/20 - 19:59:18:593] [00:00:00.000,000] <info> app: Wrote Data Record: 255
    [07/09/20 - 19:59:19:089] [00:00:00.000,000] <info> app: Wrote Data Record: 256
    [07/09/20 - 19:59:19:592] [00:00:00.000,000] <info> app: Wrote Data Record: 257
    [07/09/20 - 19:59:20:094] [00:00:00.000,000] <info> app: Wrote Data Record: 258
    [07/09/20 - 19:59:20:597] [00:00:00.000,000] <info> app: Wrote Data Record: 259
    [07/09/20 - 19:59:21:096] [00:00:00.000,000] <info> app: Wrote Data Record: 260
    [07/09/20 - 19:59:21:175] [00:00:00.000,000] <info> app: USB power detected
    [07/09/20 - 19:59:21:181] [00:00:00.000,000] <info> app: Un-initializing disk 0 (QSPI)...
    [07/09/20 - 19:59:21:185] [00:00:00.000,000] <info> app: USB ready
    
    LOG_DATA.TXT

  • Hi,

    Thank you for the detailed description and simple way to reproduce. I see the same on my side. A possible workaround is to disable writeback, by inserting 0 instead of NRF_BLOCK_DEV_QSPI_FLAG_CACHE_WRITEBACK on line 167. Does that work as a workaround for you?

  • Hi,

    Sorry, the repeat method was wrong, I have corrected it. Please see below.

    (1)Press button 3, format the disk, and create two folders, which name "Active" and "Totals".

    (2)Press button 1, write a test1.txt in the folder "Active".

    (3)Press button 2.

    (3-1)verify test1.txt.

    (3-2)creat test2.txt in the folder "Totals".

    (3-3)verify test1.txt again.

    The project file(IDE: IAR 8.32.4 )

    usbd_msc_test.zip

  • Ah, yes. That makes sense. I will test and forward to the team working on this.

  • Has there been any update with the team working on this? 

  • Hi,

    This is still being actively looked into by the SDK team, but we do not have any conclusions yet.

  • Just keeping the thread alive, and seeing if there's been any progress at all

Reply Children
  • Hi,

    Yes, there has been some progress. We have found a bug in the QSPI backend where it does not handle all possible states when configured in writeback mode. This can be fixed by modifying nrf_block_dev_qspi.c from SDK 17.0.2 like this (same approach should also be valid for older SDK version):

    diff --git a/components/libraries/block_dev/qspi/nrf_block_dev_qspi.c b/components/libraries/block_dev/qspi/nrf_block_dev_qspi.c
    index 6f1e0cd..29dc3cd 100644
    --- a/components/libraries/block_dev/qspi/nrf_block_dev_qspi.c
    +++ b/components/libraries/block_dev/qspi/nrf_block_dev_qspi.c
    @@ -1,4 +1,4 @@
    -/**
    +/*$$$LICENCE_NORDIC_STANDARD<2016>$$$*/
      * Copyright (c) 2016 - 2020, Nordic Semiconductor ASA
      *
      * All rights reserved.
    @@ -715,7 +715,9 @@ static ret_code_t block_dev_qspi_write_req(nrf_block_dev_t const * p_blk_dev,
         }
         else
         {
    -        if (p_work->writeback_mode)
    +        if (p_work->writeback_mode &&
    +            p_work->erase_unit_idx != BD_ERASE_UNIT_INVALID_ID &&
    +            p_work->erase_unit_dirty_blocks)
             {
                 ret = block_dev_qspi_write_start(p_qspi_dev);
             }
    

    We have not been able to reproduce the file corruption issue with this patch applied.

  • Thanks a looooot Einar,

    I was facing a similar issue and this modification solved the problem!! 

Related