<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Problem about fatfs  and QSPI on nRF52840</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/48535/problem-about-fatfs-and-qspi-on-nrf52840</link><description>Hi, I was using nRF52840 ， flash is mx25L25645GM2, I used fatfs with QSPI ,but I found fatfs was unstable,After some time, the stored file would dispear.Sometime there were scrambling symbols in my files</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 01 Oct 2020 15:13:34 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/48535/problem-about-fatfs-and-qspi-on-nrf52840" /><item><title>RE: Problem about fatfs  and QSPI on nRF52840</title><link>https://devzone.nordicsemi.com/thread/272601?ContentTypeID=1</link><pubDate>Thu, 01 Oct 2020 15:13:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c6cc2e70-aa25-40e0-afa5-bbeeb0b60337</guid><dc:creator>clell</dc:creator><description>&lt;p&gt;I had a similar issue&amp;nbsp;yesterday,&amp;nbsp;&amp;nbsp;on a 16MB QSPI Winbond&amp;nbsp;W25Q128JVSIQ, there was one block on the whole flash that would corrupt, it was repeatable and happened at the same location across devices. &amp;nbsp; It would also cause large block writes to fail too.&lt;/p&gt;
&lt;p&gt;I changed&amp;nbsp;NRF_BLOCK_DEV_QSPI_FLAG_CACHE_WRITEBACK to 0, and it now works fine. &amp;nbsp;Seems to be a bug in the CACHE_WRITEBACK code.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem about fatfs  and QSPI on nRF52840</title><link>https://devzone.nordicsemi.com/thread/223183?ContentTypeID=1</link><pubDate>Tue, 03 Dec 2019 02:41:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9272945b-9590-4d5c-acc1-4997cc2fca71</guid><dc:creator>junpu</dc:creator><description>&lt;p&gt;no&lt;/p&gt;
&lt;p&gt;Could you help me resolving it？&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem about fatfs  and QSPI on nRF52840</title><link>https://devzone.nordicsemi.com/thread/222969?ContentTypeID=1</link><pubDate>Mon, 02 Dec 2019 09:09:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c1194db8-c6e4-4ebf-b7a1-eebdaa436dea</guid><dc:creator>Serhii B.</dc:creator><description>&lt;p&gt;Hi, has the issue resolved?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem about fatfs  and QSPI on nRF52840</title><link>https://devzone.nordicsemi.com/thread/209454?ContentTypeID=1</link><pubDate>Thu, 12 Sep 2019 13:47:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4f815d99-48a9-4b4f-a54e-1c28db10e926</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;I tried to compile your project, but there seems to be some files missing (for instance recorder.c/h and gnss.c/h). Can you upload a project that can be compiled?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem about fatfs  and QSPI on nRF52840</title><link>https://devzone.nordicsemi.com/thread/205987?ContentTypeID=1</link><pubDate>Sun, 25 Aug 2019 21:02:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:160d4c47-d2c9-4fe7-96a1-2519e3493d94</guid><dc:creator>junpu</dc:creator><description>&lt;p&gt;Hi, I had upload my code here,&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem about fatfs  and QSPI on nRF52840</title><link>https://devzone.nordicsemi.com/thread/205986?ContentTypeID=1</link><pubDate>Sun, 25 Aug 2019 21:02:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b69be29b-4fe1-4ff3-9203-f73ef0af45f4</guid><dc:creator>junpu</dc:creator><description>&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/tracker.rar"&gt;devzone.nordicsemi.com/.../tracker.rar&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem about fatfs  and QSPI on nRF52840</title><link>https://devzone.nordicsemi.com/thread/202200?ContentTypeID=1</link><pubDate>Fri, 02 Aug 2019 14:52:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ca707fca-d582-4084-80ee-133e008d6757</guid><dc:creator>Jared</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;You could upload it here. Click Insert-&amp;gt;insert image/video/file-&amp;gt;chose file upload.I can make the case private if you prefer to not share it in a public case. You&amp;nbsp; only need to share the specific folder that you&amp;#39;re application is in, which contains the config file and other source files belonging to the project. You don&amp;#39;t need to share the entire SDK.&lt;/p&gt;
&lt;p&gt;regards&lt;/p&gt;
&lt;p&gt;Jared&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem about fatfs  and QSPI on nRF52840</title><link>https://devzone.nordicsemi.com/thread/202162?ContentTypeID=1</link><pubDate>Fri, 02 Aug 2019 13:08:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5b7365e5-e098-4c7e-8395-259ffe161a66</guid><dc:creator>junpu</dc:creator><description>&lt;p&gt;How to share my project folder? by mail or ？&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem about fatfs  and QSPI on nRF52840</title><link>https://devzone.nordicsemi.com/thread/201826?ContentTypeID=1</link><pubDate>Thu, 01 Aug 2019 11:27:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dfd4f8c1-fb01-4fa4-9a09-dac38ca40803</guid><dc:creator>Jared</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Could you share your entire project folder with me? I would like to try to reproduce it myself.&lt;/p&gt;
&lt;p&gt;regards&lt;/p&gt;
&lt;p&gt;Jared&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem about fatfs  and QSPI on nRF52840</title><link>https://devzone.nordicsemi.com/thread/200373?ContentTypeID=1</link><pubDate>Wed, 24 Jul 2019 23:12:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e0841092-598e-4ecb-a409-5314f48d83b4</guid><dc:creator>junpu</dc:creator><description>&lt;p&gt;Hi, I am sorry for late reply. My question is the same with&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/39428/usb-msc-corruption"&gt;https://devzone.nordicsemi.com/f/nordic-q-a/39428/usb-msc-corruption&lt;/a&gt;&amp;nbsp; . I found there was no answer in&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/39428/usb-msc-corruption"&gt;https://devzone.nordicsemi.com/f/nordic-q-a/39428/usb-msc-corruption&lt;/a&gt;.&amp;nbsp; Have&amp;nbsp; you got the solution?&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I could reproduce&amp;nbsp; on the development kit.&amp;nbsp; This problem l&lt;span&gt;acked of regularity, some minitues&amp;nbsp; or some houses.,&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem about fatfs  and QSPI on nRF52840</title><link>https://devzone.nordicsemi.com/thread/198327?ContentTypeID=1</link><pubDate>Mon, 15 Jul 2019 07:55:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:65f30d6a-1da6-49c5-90cc-0fe65c70405d</guid><dc:creator>Jared</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Sorry for the late reply&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;I can&amp;#39;t really see anything in the code that should create the issue. Are you able to reproduce the issue on the development kit? How long after flashing the application to the nRF do you experience the issue?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;regards&lt;/p&gt;
&lt;p&gt;Jared&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem about fatfs  and QSPI on nRF52840</title><link>https://devzone.nordicsemi.com/thread/194400?ContentTypeID=1</link><pubDate>Mon, 24 Jun 2019 13:29:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b307a112-0dd7-4866-954c-5a5b74ef320f</guid><dc:creator>junpu</dc:creator><description>&lt;p&gt;&lt;span&gt;Look forward to your favourable reply&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem about fatfs  and QSPI on nRF52840</title><link>https://devzone.nordicsemi.com/thread/194399?ContentTypeID=1</link><pubDate>Mon, 24 Jun 2019 13:29:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9edf683e-73f8-411f-b07f-34d90369734f</guid><dc:creator>junpu</dc:creator><description>&lt;p&gt;&lt;span&gt;Look forward to your favourable reply&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem about fatfs  and QSPI on nRF52840</title><link>https://devzone.nordicsemi.com/thread/193764?ContentTypeID=1</link><pubDate>Thu, 20 Jun 2019 00:24:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b17dc7e0-3289-45ed-9f4d-0ac69d14e570</guid><dc:creator>junpu</dc:creator><description>&lt;p&gt;the last is sdk_config.h&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem about fatfs  and QSPI on nRF52840</title><link>https://devzone.nordicsemi.com/thread/193763?ContentTypeID=1</link><pubDate>Thu, 20 Jun 2019 00:23:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7ebc9e90-9117-4e48-945b-22035765a3f8</guid><dc:creator>junpu</dc:creator><description>&lt;p&gt;// &amp;lt;5=&amp;gt; 5 &lt;br /&gt;// &amp;lt;6=&amp;gt; 6 &lt;br /&gt;// &amp;lt;7=&amp;gt; 7&lt;/p&gt;
&lt;p&gt;#ifndef USBD_CONFIG_IRQ_PRIORITY&lt;br /&gt;#define USBD_CONFIG_IRQ_PRIORITY 6&lt;br /&gt;#endif&lt;/p&gt;
&lt;p&gt;// &amp;lt;o&amp;gt; USBD_CONFIG_DMASCHEDULER_MODE - USBD SMA scheduler working scheme&lt;br /&gt; &lt;br /&gt;// &amp;lt;0=&amp;gt; Prioritized access &lt;br /&gt;// &amp;lt;1=&amp;gt; Round Robin&lt;/p&gt;
&lt;p&gt;#ifndef USBD_CONFIG_DMASCHEDULER_MODE&lt;br /&gt;#define USBD_CONFIG_DMASCHEDULER_MODE 0&lt;br /&gt;#endif&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem about fatfs  and QSPI on nRF52840</title><link>https://devzone.nordicsemi.com/thread/193762?ContentTypeID=1</link><pubDate>Thu, 20 Jun 2019 00:21:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9d6248de-03d1-479b-a5b9-86902b368b52</guid><dc:creator>junpu</dc:creator><description>&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;main.h

#ifndef MAIN_H
#define MAIN_
#include &amp;lt;stdint.h&amp;gt;
#include &amp;lt;stdbool.h&amp;gt;
#include &amp;lt;stddef.h&amp;gt;
#include &amp;lt;inttypes.h&amp;gt;
#include &amp;lt;stdlib.h&amp;gt;

#include &amp;quot;nrf.h&amp;quot;
#include &amp;quot;nrf_block_dev.h&amp;quot;
#include &amp;quot;nrf_block_dev_ram.h&amp;quot;
#include &amp;quot;nrf_block_dev_empty.h&amp;quot;
#include &amp;quot;nrf_block_dev_qspi.h&amp;quot;
#include &amp;quot;nrf_block_dev_sdc.h&amp;quot;
#include &amp;quot;nrf_drv_usbd.h&amp;quot;
#include &amp;quot;nrf_drv_clock.h&amp;quot;
#include &amp;quot;nrf_gpio.h&amp;quot;
#include &amp;quot;nrf_atomic.h&amp;quot;
#include &amp;quot;nrf_drv_power.h&amp;quot;

#include &amp;quot;ff.h&amp;quot;
#include &amp;quot;diskio_blkdev.h&amp;quot;

#include &amp;quot;app_usbd.h&amp;quot;
#include &amp;quot;app_usbd_core.h&amp;quot;
#include &amp;quot;app_usbd_string_desc.h&amp;quot;
#include &amp;quot;app_usbd_msc.h&amp;quot;
#include &amp;quot;app_error.h&amp;quot;
#include &amp;quot;app_timer.h&amp;quot;

#include &amp;quot;bsp.h&amp;quot;


#include &amp;quot;nrf_log.h&amp;quot;
#include &amp;quot;nrf_log_ctrl.h&amp;quot;
#include &amp;quot;nrf_log_default_backends.h&amp;quot;

#include &amp;quot;recorder.h&amp;quot;
#include &amp;quot;gnss.h&amp;quot;

#define NEED_NMEAPARSE
#ifdef NEED_NMEAPARSE
#include &amp;quot;minmea.h&amp;quot;
#endif

#include &amp;quot;boards.h&amp;quot;
#include &amp;quot;nrf_delay.h&amp;quot;

#define RESULT_SUCESS &amp;quot;sucessfully!&amp;quot;
#define RESULT_FAILED &amp;quot;failed!&amp;quot;
#define  ACTION_NAME &amp;quot;init&amp;quot;

#define  LOG_ACTION_NAME &amp;quot;Log&amp;quot;
#define  CLOCK_ACTION_NAME &amp;quot;Clock&amp;quot;
#define  TIMER_ACTION_NAME &amp;quot;Timer&amp;quot;
#define  BSP_ACTION_NAME &amp;quot;BSP&amp;quot;



#define BUFFER_SIZE                     180
#define  IS_ASCII(x) ((((unsigned char)(x)) &amp;amp; 0x80 ) == 0x80 ?  false : true)
/**@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 &amp;lt;&amp;lt; BTN_RANDOM_FILE)
#define KEY_EV_LIST_DIR_MSK    (1U &amp;lt;&amp;lt; BTN_LIST_DIR   )
#define KEY_EV_MKFS_MSK        (1U &amp;lt;&amp;lt; 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(&amp;quot;Nordic&amp;quot;, &amp;quot;RAM&amp;quot;, &amp;quot;1.00&amp;quot;)
);


/**
 * @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(&amp;quot;Nordic&amp;quot;, &amp;quot;EMPTY&amp;quot;, &amp;quot;1.00&amp;quot;)
);


/**
 * @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(&amp;quot;Nordic&amp;quot;, &amp;quot;QSPI&amp;quot;, &amp;quot;1.00&amp;quot;)
);

#if USE_SD_CARD
#if 0
#define SDC_MISO_PIN    (19)        ///&amp;lt; SDC serial data out (DO) pin.
#define SDC_SCK_PIN     (20)        ///&amp;lt; SDC serial clock (SCK) pin.
#define SDC_MOSI_PIN    (21)        ///&amp;lt; SDC serial data in (DI) pin.
#define SDC_CS_PIN      (22)        ///&amp;lt; SDC chip select (CS) pin.
#else
//NOT OK
// #define SDC_MISO_PIN    (31)        ///&amp;lt; SDC serial data out (DO) pin.
// #define SDC_SCK_PIN     (30)        ///&amp;lt; SDC serial clock (SCK) pin.
// #define SDC_MOSI_PIN    (29)        ///&amp;lt; SDC serial data in (DI) pin.
// #define SDC_CS_PIN      (28)        ///&amp;lt; SDC chip select (CS) pin.


//OK
#define SDC_MISO_PIN    (28)         ///&amp;lt; SDC serial data out (DO) pin.
#define SDC_SCK_PIN     (31)        ///&amp;lt; SDC serial clock (SCK) pin.
#define SDC_MOSI_PIN    (30)        ///&amp;lt; SDC serial data in (DI) pin.
#define SDC_CS_PIN      (29)   ///&amp;lt; SDC chip select (CS) pin.


// #define SDC_MISO_PIN    (31)         ///&amp;lt; SDC serial data out (DO) pin.
// #define SDC_SCK_PIN     (26)        ///&amp;lt; SDC serial clock (SCK) pin.
// #define SDC_MOSI_PIN    (27)        ///&amp;lt; SDC serial data in (DI) pin.
// #define SDC_CS_PIN      (04)   ///&amp;lt; SDC chip select (CS) pin.




#endif
/**
 * @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(&amp;quot;Nordic&amp;quot;, &amp;quot;SDC&amp;quot;, &amp;quot;1.00&amp;quot;)
);


/**
 * @brief Block devices list passed to @ref APP_USBD_MSC_GLOBAL_DEF
 */
#if 0
#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_sdc, block_dev)      \
)
#else
#define BLOCKDEV_LIST() (                                   \
    NRF_BLOCKDEV_BASE_ADDR(m_block_dev_sdc, block_dev)      \
)
#endif

#else
#if 0
#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)     \
)
#else
#define BLOCKDEV_LIST() (                                   \
    NRF_BLOCKDEV_BASE_ADDR(m_block_dev_qspi, block_dev)     \
)
#endif
#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;
static FRESULT  fatfs_mkfs(void);
// #define SDC_SCK_PIN     (30)        ///&amp;lt; SDC serial clock (SCK) pin.
// #define SDC_MOSI_PIN    (29)        ///&amp;lt; SDC serial data in (DI) pin.
// #define SDC_CS_PIN      (28)        ///&amp;lt; SDC chip select (CS) pin.


//OK
#define SDC_MISO_PIN    (28)         ///&amp;lt; SDC serial data out (DO) pin.
#define SDC_SCK_PIN     (31)        ///&amp;lt; SDC serial clock (SCK) pin.
#define SDC_MOSI_PIN    (30)        ///&amp;lt; SDC serial data in (DI) pin.
#define SDC_CS_PIN      (29)   ///&amp;lt; SDC chip select (CS) pin.


// #define SDC_MISO_PIN    (31)         ///&amp;lt; SDC serial data out (DO) pin.
// #define SDC_SCK_PIN     (26)        ///&amp;lt; SDC serial clock (SCK) pin.
// #define SDC_MOSI_PIN    (27)        ///&amp;lt; SDC serial data in (DI) pin.
// #define SDC_CS_PIN      (04)   ///&amp;lt; SDC chip select (CS) pin.

void record_stat_data(int close_flag);
void delay_ms(unsigned short time);
void delay_us(unsigned short time);
uint32_t app_uart_get(uint8_t * p_byte);

#endif

&lt;/pre&gt;&lt;pre class="ui-code" data-mode="markdown"&gt;main.c

int main(void)
{
    ret_code_t ret;
    FRESULT ff_result; 
    int mode = 0;
    //char m_log_buf[256] = {0}; 
    int loop_cnt = 0;

    uint32_t time_ms = 500; //Time(in miliseconds) between consecutive compare events.
    uint32_t time_ticks;
    uint32_t err_code = NRF_SUCCESS;

    bool    init_result = true;

    static const app_usbd_config_t usbd_config =
    {
        .ev_state_proc = usbd_user_ev_handler
    };

    /*******************************************************************
     * Step 1: System init
     *******************************************************************/

    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);

    if(ret)
    {
   
        return -1;
    }
    /* Fill whole RAM block device buffer */
    for (size_t i = 0; i &amp;lt; 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);



    //Configure all leds on board.

#if 1
    ret = fatfs_init();

    APP_ERROR_CHECK(!ret);
    if(ret!=true)
    {

        ff_result = fatfs_mkfs();
        if (ff_result != FR_OK)
        {
       
            init_result = false;
            return -1;
        }
		
        bsp_board_led_off(BSP_BOARD_LED_1);
nrf_delay_ms(30*1000);
//        sleep(30);//while(1);
    
    }
	nrf_delay_ms(10);

    fatfs_ls();

#endif

    bsp_board_led_on(BSP_BOARD_LED_0);
    nrf_delay_ms(3000);
    bsp_board_led_off(BSP_BOARD_LED_0);

    ret = gnss_init();
#if 0
    m_log_buf_len =   sprintf( (char *) m_log_buf, &amp;quot;%s %s %s : %d.\r\n&amp;quot;,BSP_ACTION_NAME,ACTION_NAME,(NRF_SUCCESS==ret)?RESULT_SUCESS:RESULT_FAILED, ret );
    record_stat_data(0);
#endif
    if(ret)
    {
       // m_log_buf_len =   sprintf( (char *) m_log_buf, &amp;quot;Step 1:System  init failed,because of gnss.\r\n&amp;quot; );
        return -1;
    }
    /*******************************************************************
     * Step 2: System configure GPS
     *******************************************************************/

    ret = init_param();
    if(NRF_SUCCESS != ret)
    {
    ff_result = fatfs_mkfs();
    if(!ff_result)
    {
      ret = init_param();
      if(NRF_SUCCESS != ret)
      {
        return ret;
      }
    }else
    {


        return ret;
        }
    }
    mode = get_mode_from_param();

    if(mode &amp;lt;0 || mode &amp;gt;4)
    {
 
		NRF_LOG_ERROR(&amp;quot;GNSS mode from config err: %d&amp;quot;, mode);
        return mode;
    }

    NRF_LOG_INFO(&amp;quot;GNSS mode from config: %d&amp;quot;, mode);
    ret = gnss_set_mode(mode);
    if(NRF_SUCCESS != ret)
    {

        return ret;
    }
    //        set_gnss_mode(mode);
    // fatfs_file_create();

    /*******************************************************************
     * Step 3: System configure USB 
     *******************************************************************/
    ret = app_usbd_init(&amp;amp;usbd_config);
    APP_ERROR_CHECK(ret);
    if(NRF_SUCCESS != ret)
    {

    }
    app_usbd_class_inst_t const * class_inst_msc = app_usbd_msc_class_inst_get(&amp;amp;m_app_msc);
    ret = app_usbd_class_append(class_inst_msc);
    APP_ERROR_CHECK(ret);
    if(NRF_SUCCESS != ret)
    {

    }
    NRF_LOG_INFO(&amp;quot;USBD configure  finished.&amp;quot;);

    //    gnss_set_callback(on_uart_receive);

    if (USBD_POWER_DETECTION)
    {
        ret = app_usbd_power_events_enable();
        APP_ERROR_CHECK(ret);
    }
    else
    {
        NRF_LOG_INFO(&amp;quot;No USB power detection enabled\r\nStarting USB now&amp;quot;);

        app_usbd_enable();
        app_usbd_start();
        m_usb_connected = true;
    }


    /*******************************************************************
     * Step 4: 
     *******************************************************************/
    while (true)
    {
        while (app_usbd_event_queue_process() &amp;amp;&amp;amp; loop_cnt&amp;lt;100)
        {
        #if 0
            /* Nothing to do */
            m_log_buf_len =   sprintf( (char *) m_log_buf, &amp;quot;Step 4: Enter app_usbd_event_queue_process loop .\r\n&amp;quot;);
		  
            record_stat_data(0);
		#endif
            loop_cnt++;
			
        }

        /* Process BSP key events flags.*/
        uint32_t events = nrf_atomic_u32_fetch_store(&amp;amp;m_key_events, 0);
        if (events &amp;amp; KEY_EV_RANDOM_FILE_MSK)
        {
            //            fatfs_file_create();
            //            recorder_stest();
            mode = 0;
            init_param();
            mode = get_mode_from_param();
            NRF_LOG_INFO(&amp;quot;GNSS mode from config: %d&amp;quot;, mode);

        }

        if (events &amp;amp; KEY_EV_LIST_DIR_MSK)
        {
            //            fatfs_ls();
            recorder_fatfs_ls();
        }

        if (events &amp;amp; KEY_EV_MKFS_MSK)
        {
            fatfs_mkfs();
        }

        uart_data_process();

        UNUSED_RETURN_VALUE(NRF_LOG_PROCESS());
        /* Sleep CPU only if there was no interrupt since last loop processing */
        __WFE();
    }
}&lt;/pre&gt;&lt;pre class="ui-code" data-mode="ruby"&gt;record.c

#include &amp;quot;recorder.h&amp;quot;
#include &amp;quot;ff.h&amp;quot;
#include &amp;quot;diskio_blkdev.h&amp;quot;
#include &amp;quot;nrf_log_ctrl.h&amp;quot;
#include &amp;quot;nrf_delay.h&amp;quot;
#include &amp;quot;ini.h&amp;quot;

#define NRF_LOG_MODULE_NAME recorder
#include &amp;lt;nrf_log.h&amp;gt;
NRF_LOG_MODULE_REGISTER();

#define LEN_FILENAME 128
/*每次记录完是不是关闭文件*/
#define CLOSE_FILE_AFTER_RECORDED 0

#define CONFIG_FILE &amp;quot;CONFIG.INI&amp;quot;
#define CONFIG_CONTENT \
&amp;quot;;---------------------------------------------------\r\n&amp;quot;\
&amp;quot;;-----do not delete these lines with no meaning-----\r\n&amp;quot;\
&amp;quot;;---------------------------------------------------\r\n&amp;quot;\
&amp;quot;;--------these lines may fix some bugs--------------\r\n&amp;quot;\
&amp;quot;;---------------------------------------------------\r\n&amp;quot;\
&amp;quot;;---------------------------------------------------\r\n&amp;quot;\
&amp;quot;;---------------------------------------------------\r\n&amp;quot;\
&amp;quot;;---------------------------------------------------\r\n&amp;quot;\
&amp;quot;;---------------------------------------------------\r\n&amp;quot;\
&amp;quot;;---------------------------------------------------\r\n&amp;quot;\
&amp;quot;;---------------------------------------------------\r\n&amp;quot;\
&amp;quot;;---------------------------------------------------\r\n&amp;quot;\
&amp;quot;;---------------------------------------------------\r\n&amp;quot;\
&amp;quot;;---------------------------------------------------\r\n&amp;quot;\
&amp;quot;;---------------------------------------------------\r\n&amp;quot;\
&amp;quot;;---------------------------------------------------\r\n&amp;quot;\
&amp;quot;;---------------------------------------------------\r\n&amp;quot;\
&amp;quot;;---------------------------------------------------\r\n&amp;quot;\
&amp;quot;;---------------------------------------------------\r\n&amp;quot;\
&amp;quot;;---------------------------------------------------\r\n&amp;quot;\
&amp;quot;;---------------------------------------------------\r\n&amp;quot;\
&amp;quot;;---------------------------------------------------\r\n&amp;quot;\
&amp;quot;;---------------------------------------------------\r\n&amp;quot;\
&amp;quot;;---------------------------------------------------\r\n&amp;quot;\
&amp;quot;;---------------------------------------------------\r\n&amp;quot;\
&amp;quot;;---------------------------------------------------\r\n&amp;quot;\
&amp;quot;;---------------------------------------------------\r\n&amp;quot;\
&amp;quot;;config starts--------------------------------------\r\n&amp;quot;\
&amp;quot;;---mode\r\n&amp;quot;\
&amp;quot;;------1\tGPS only\r\n&amp;quot;\
&amp;quot;;------2\tGLONASS only\r\n&amp;quot;\
&amp;quot;;------3\tGPS+GLONASS\r\n&amp;quot;\
&amp;quot;;------4\tGPS+BDS(default)\r\n&amp;quot;\
&amp;quot;;------5\tBDS only\r\n&amp;quot;\
&amp;quot;;------6\tGPS+GLONASS+Galileo\r\n&amp;quot;\
&amp;quot;mode=4\r\n&amp;quot;

#define CONFIG_KEYWORD &amp;quot;config starts&amp;quot;
#define CONFIG_CONTENT_LENGTH_MAX 4096


#define PARAM_MODE_KEY &amp;quot;mode&amp;quot;

typedef struct {
    int mode;
}param_t;

static bool m_record_disabled;
static FIL* m_opened_file = NULL;
static char m_filename[LEN_FILENAME] = &amp;quot;default.csv&amp;quot;;
static char m_endline[] = &amp;quot;\n&amp;quot;;
static param_t m_param = {0};


uint32_t init_config_file();
static uint32_t file_close();

void set_record_disabled(bool disabled)
{
    m_record_disabled = disabled;
    if(m_opened_file){
        file_close();
    }
}

bool get_record_disabled()
{
    return m_record_disabled;
}



uint32_t recorder_fatfs_ls(void)
{
   DIR dir;
   FRESULT ff_result;
   FILINFO fno;

   if (m_record_disabled)
   {
       NRF_LOG_ERROR(&amp;quot;Unable to operate on filesystem while USB is connected&amp;quot;);
       return NRF_ERROR_BUSY;
   }

   NRF_LOG_INFO(&amp;quot;\r\nListing directory: /&amp;quot;);
   if(get_record_disabled()){
       return NRF_ERROR_BUSY;
   }
   ff_result = f_opendir(&amp;amp;dir, &amp;quot;/&amp;quot;);
   if (ff_result != FR_OK)
   {
       NRF_LOG_ERROR(&amp;quot;Directory listing failed: %u&amp;quot;, ff_result);
       return NRF_ERROR_FORBIDDEN;
   }

   uint32_t entries_count = 0;
   do
   {
       ff_result = f_readdir(&amp;amp;dir, &amp;amp;fno);
       if (ff_result != FR_OK)
       {
           NRF_LOG_ERROR(&amp;quot;Directory read failed: %u&amp;quot;, ff_result);
           return NRF_ERROR_NULL;
       }

       if (fno.fname[0])
       {
           if (fno.fattrib &amp;amp; AM_DIR)
           {
               NRF_LOG_RAW_INFO(&amp;quot;   &amp;lt;DIR&amp;gt;   %s\r\n&amp;quot;,(uint32_t)fno.fname);
           }
           else
           {
               NRF_LOG_RAW_INFO(&amp;quot;%9lu  %s\r\n&amp;quot;, fno.fsize, (uint32_t)fno.fname);
           }
       }

       ++entries_count;
       NRF_LOG_FLUSH();
   } while (fno.fname[0]);

   NRF_LOG_RAW_INFO(&amp;quot;Entries count: %u\r\n&amp;quot;, entries_count);
   return NRF_SUCCESS;
}


static uint32_t file_close()
{
    FRESULT ff_result = f_close(m_opened_file);
    if (ff_result != FR_OK)
    {
        NRF_LOG_ERROR(&amp;quot;\r\nUnable to close file: %u&amp;quot;, ff_result);
        NRF_LOG_FLUSH();
        return NRF_ERROR_NULL;
    }
    
    NRF_LOG_INFO(&amp;quot;closed %x.&amp;quot;, (uint32_t)m_opened_file);
    m_opened_file = NULL;
    return NRF_SUCCESS;

}

static uint32_t file_open(const char*filename)
{
    static FIL file;
    FRESULT ff_result;

    NRF_LOG_INFO(&amp;quot;Opening file: %s.&amp;quot;, NRF_LOG_PUSH(filename));
    if(get_record_disabled()){
        return NRF_ERROR_BUSY;
    }
    ff_result = f_open(&amp;amp;file, filename, FA_READ | FA_WRITE | FA_OPEN_APPEND);
    if (ff_result != FR_OK)
    {
       NRF_LOG_INFO(&amp;quot;Unable to open or create file: %d&amp;quot;, ff_result);
       return NRF_ERROR_BUSY;
    }
    m_opened_file = &amp;amp;file;
    return NRF_SUCCESS;
}
static uint32_t file_write(const uint8_t *buf, uint32_t len)
{
    uint32_t written = 0;
    FRESULT ff_result;
    if(m_opened_file == NULL){
        NRF_LOG_ERROR(&amp;quot;Sorry, open file first&amp;quot;);
        return NRF_ERROR_BUSY;
    }
    NRF_LOG_HEXDUMP_DEBUG(buf, len);
    if(get_record_disabled()){
        return NRF_ERROR_BUSY;
    }
	f_lseek(m_opened_file,f_size(m_opened_file));
    ff_result = f_write(m_opened_file, buf, len, (UINT *) &amp;amp;written);
    if (ff_result != FR_OK || written != len)
    {
        NRF_LOG_ERROR(&amp;quot;Failed to write, ff_result: %d, written: %d&amp;quot;, ff_result, written);
        return NRF_ERROR_NULL;
    }
    else
    {
        NRF_LOG_DEBUG(&amp;quot;%d bytes written.&amp;quot;, written);
    }
    f_sync(m_opened_file);
    return NRF_SUCCESS;
}

uint32_t set_record_filename(const char* name)
{
    if(name[0] == &amp;#39;\0&amp;#39;){
        return NRF_ERROR_NULL;
    }
    memset(m_filename, 0x00, LEN_FILENAME);
    int n = snprintf(m_filename, LEN_FILENAME, &amp;quot;%s.csv&amp;quot;, name);
    NRF_LOG_INFO(&amp;quot;Set record file name:&amp;quot;)
    NRF_LOG_HEXDUMP_INFO(m_filename, n + 1);
    if(m_opened_file){
        file_close();
    }
    return file_open(m_filename);
}

uint32_t record_one_line(uint8_t *buf, uint32_t len)
{
    uint32_t ret;
    bool result = false;
    if(m_opened_file == NULL)
    {
        #if CLOSE_FILE_AFTER_RECORDED
        if(get_record_disabled()){
            return NRF_ERROR_BUSY;
        }
        ret = file_open(m_filename);
        if(ret != NRF_SUCCESS){
            return NRF_ERROR_BUSY;
        }
        #endif
         return NRF_ERROR_NULL;
    }
    result = get_record_disabled();
    if(result == true)
    {
        return NRF_ERROR_BUSY;
    }
	
    ret = file_write(buf, len);
    if(ret != NRF_SUCCESS)
    {
        NRF_LOG_ERROR(&amp;quot;Failed1 to record one line&amp;quot;);
        return NRF_ERROR_NULL;
    }
    
    ret = file_write(&amp;amp;m_endline, sizeof(m_endline) - 1);
    if(ret != NRF_SUCCESS)
    {
        NRF_LOG_ERROR(&amp;quot;Failed to record one line&amp;quot;);
        return NRF_ERROR_NULL;
    }
#if CLOSE_FILE_AFTER_RECORDED
   file_close();
#endif
    NRF_LOG_WARNING(&amp;quot;Recorded one line: %d&amp;quot;, len);
    return NRF_SUCCESS;
}


static void show_file_info()
{
//    NRF_LOG_INFO(&amp;quot;m_opened_file: %X.&amp;quot;, m_opened_file);
}


static void fatfs_example()
{
    static FATFS fs;
    static DIR dir;
    static FILINFO fno;
    static FIL file;

    uint32_t bytes_written;
    FRESULT ff_result;
    DSTATUS disk_state = STA_NOINIT;
#define FILE_NAME &amp;quot;heheda&amp;quot;
#define TEST_STRING &amp;quot;123&amp;quot;

    D_RETURN_VALUE(NRF_LOG_PROCESS());
    file_open(m_filename);
    while(1){   
        file_write(TEST_STRING, sizeof(TEST_STRING) - 1);
        nrf_delay_ms(500);
    }

    (void) f_close(&amp;amp;file);
    return;
}

void recorder_test()
{
#if 0
    char random_file_name[32];
    memset(random_file_name, 0x00, 32);

    snprintf(random_file_name, sizeof(random_file_name), &amp;quot;%08x.txt&amp;quot;, rand());
    new_file_create(random_file_name, false);
#endif
    char random_data[32] __attribute__ ((aligned (4)));
    int n = snprintf(random_data, sizeof(random_data), &amp;quot;%08x&amp;quot;, rand() * rand());
    record_one_line(random_data, n);
    show_file_info();
}

bool is_file_opened()
{ 
    return NULL != m_opened_file;
}

uint32_t paser_mode_from_config(const char* data, int len, int* mode)
{
#define MODE_CONFIG_PREFIX &amp;quot;mode=&amp;quot;
    if(!data || !mode)
        return NRF_ERROR_INVALID_PARAM;
    char *input = data;
    int index = 0;
    int line_start = index;
    int line_len = 0;
    bool is_valid = true;
    static char c;// static for debug

    while(index &amp;lt; len){
        c = input[index];
        if(c == &amp;#39;;&amp;#39;){ // this is comment
            is_valid = false;
        }
        else if(c == &amp;#39;\r&amp;#39; || c == &amp;#39;\n&amp;#39;){ // this is the end of line
            input[index] = &amp;#39;\0&amp;#39;;
            if(is_valid){ // check &amp;quot;mode=&amp;quot;
                line_len = index - line_start;
                if(0 == strncasecmp(input + line_start, MODE_CONFIG_PREFIX, sizeof(MODE_CONFIG_PREFIX) - 1)){
                    int m = atoi(input + line_start + sizeof(MODE_CONFIG_PREFIX) - 1);
                    NRF_LOG_INFO(&amp;quot;Success to read mode from config: %d&amp;quot;, m);
                    *mode = m;
                    break;
                }
            }
            is_valid = true;
            line_start = index + 1;
        }
        index++;
    }

    return NRF_SUCCESS;
}

int User;
char Prev_section[50];

int dumper(void* user, const char* section, const char* name,
           const char* value)
{
    User = *((int*)user);
    if (strcmp(section, Prev_section))
    {
        strncpy(Prev_section, section, sizeof(Prev_section));
        Prev_section[sizeof(Prev_section) - 1] = &amp;#39;\0&amp;#39;;
    }
    NRF_LOG_INFO(&amp;quot;... %s=%s;\n&amp;quot;, NRF_LOG_PUSH(name), NRF_LOG_PUSH(value));

    if(0 == strncasecmp(name, PARAM_MODE_KEY, sizeof(PARAM_MODE_KEY) - 1))
    {
        int m = atoi(value);
        NRF_LOG_INFO(&amp;quot;Success to read mode from config: %d&amp;quot;, m);
        m_param.mode = m;
    }
    return 1;
}

int get_mode_from_param()
{

    if(m_param.mode == 0)
	{
        init_config_file();
    }
    return m_param.mode;
}
static uint32_t read_from_config_file()
{
    FIL file;
    FRESULT ff_result;
    UINT read = 0;
    char buffer[CONFIG_CONTENT_LENGTH_MAX] = {0};
    int e;
    static int u = 100;
    *Prev_section = &amp;#39;\0&amp;#39;;

    NRF_LOG_INFO(&amp;quot;Opening config file&amp;quot;);
    if(get_record_disabled()){
        return NRF_ERROR_BUSY;
    }
    ff_result = f_open(&amp;amp;file, CONFIG_FILE, FA_READ | FA_OPEN_EXISTING);
    if (ff_result != FR_OK)
    {
       NRF_LOG_INFO(&amp;quot;Unable to open file: %d&amp;quot;, ff_result);
       return NRF_ERROR_BUSY;
    }

    ff_result = f_read(&amp;amp;file, buffer, CONFIG_CONTENT_LENGTH_MAX, &amp;amp;read);
    if (ff_result != FR_OK)
    {
        NRF_LOG_ERROR(&amp;quot;Failed to read, ff_result: %d, read: %d&amp;quot;, ff_result, read);
        return NRF_ERROR_NULL;
    }
    NRF_LOG_INFO(&amp;quot;read from config file: %d&amp;quot;, read);
//    NRF_LOG_HEXDUMP_INFO(buffer, read);

    if(NULL == strnstr(buffer, CONFIG_KEYWORD, CONFIG_CONTENT_LENGTH_MAX))
    {
        NRF_LOG_INFO(&amp;quot;config key word not found&amp;quot;);
        goto exit;
    }

    e = ini_parse_string(buffer, dumper, &amp;amp;u);
    NRF_LOG_INFO(&amp;quot;e=%d user=%d\n&amp;quot;, e, User);

    // if(NRF_SUCCESS != paser_mode_from_config(buffer, read, mode)){
    //     *mode = 0;
    // }
    
exit:
    ff_result = f_close(&amp;amp;file);
    if (ff_result != FR_OK)
    {
        NRF_LOG_ERROR(&amp;quot;\r\nUnable to close config file: %u&amp;quot;, ff_result);
        NRF_LOG_FLUSH();
        return NRF_ERROR_NULL;
    }
    
    NRF_LOG_INFO(&amp;quot;closed config file&amp;quot;);

    return NRF_SUCCESS;
}

uint32_t init_config_file_prefix(const char*filename)
{
    FIL file;
    FRESULT ff_result;
    UINT written;

    NRF_LOG_INFO(&amp;quot;Creating config file&amp;quot;);
    if(get_record_disabled()){
        return NRF_ERROR_BUSY;
    }
    ff_result = f_open(&amp;amp;file, filename, FA_WRITE | FA_CREATE_ALWAYS);
    if (ff_result != FR_OK)
    {
       NRF_LOG_INFO(&amp;quot;Unable to create file: %d&amp;quot;, ff_result);
       return NRF_ERROR_BUSY;
    }

    if(get_record_disabled()){
        return NRF_ERROR_BUSY;
    }
    ff_result = f_write(&amp;amp;file, CONFIG_CONTENT, sizeof(CONFIG_CONTENT), (UINT *) &amp;amp;written);
    if (ff_result != FR_OK || written != sizeof(CONFIG_CONTENT))
    {
        NRF_LOG_ERROR(&amp;quot;Failed to write, ff_result: %d, written: %d&amp;quot;, ff_result, written);
        return NRF_ERROR_NULL;
    }
    else
    {
        NRF_LOG_INFO(&amp;quot;[&amp;quot;CONFIG_CONTENT&amp;quot;] %d bytes written.&amp;quot;, written);
    }

    ff_result = f_close(&amp;amp;file);
    if (ff_result != FR_OK)
    {
        NRF_LOG_ERROR(&amp;quot;\r\nUnable to close config file: %u&amp;quot;, ff_result);
        NRF_LOG_FLUSH();
        return NRF_ERROR_NULL;
    }
    
    NRF_LOG_INFO(&amp;quot;closed config file&amp;quot;);
    
    return NRF_SUCCESS;
}

uint32_t init_config_file()
{
    uint32_t ret = -1;
    ret = init_config_file_prefix(&amp;quot;fake&amp;quot;);
    if(NRF_SUCCESS != ret)
    {
        NRF_LOG_ERROR(&amp;quot;Failed to init_config_file_prefix fake, result: %d&amp;quot;, ret);
        return ret;
    }
    ret = init_config_file_prefix(CONFIG_FILE);
    if(NRF_SUCCESS != ret)
    {
        NRF_LOG_ERROR(&amp;quot;Failed to init_config_file_prefix %s, result: %d&amp;quot;,CONFIG_FILE, ret);
        return ret;
    }
}

static uint32_t open_config_file()
{
    return !NRF_SUCCESS;
}

int read_mode_from_record()
{
    int mode= 0;
    int count = 5;
    uint32_t ret = NRF_SUCCESS;
    ret = read_mode_from_config_file(&amp;amp;mode);
    #if 1
    if(NRF_SUCCESS != ret){
    #else
    if(1){
    #endif
        NRF_LOG_INFO(&amp;quot;Initing config file&amp;quot;);
        init_config_file();
        return 0;
    }
    return mode;
}


uint32_t init_param()
{
    uint32_t ret = -1;

    ret = read_from_config_file();
    if(NRF_SUCCESS != ret)
	{
        ret = init_config_file();
        if(NRF_SUCCESS == ret) /* read config file again */
        {
            ret = read_from_config_file();
            if(NRF_SUCCESS != ret)
            {
                NRF_LOG_ERROR(&amp;quot;read config file failed again.&amp;quot;);
                return ret;
            }

        }
        else
        {

            NRF_LOG_ERROR(&amp;quot;init config file failed. &amp;quot;);
            return  ret;
        }
    }

    NRF_LOG_INFO(&amp;quot;Initing param sucessfully&amp;quot;);
    return NRF_SUCCESS;
}
&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem about fatfs  and QSPI on nRF52840</title><link>https://devzone.nordicsemi.com/thread/193669?ContentTypeID=1</link><pubDate>Wed, 19 Jun 2019 12:29:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:61169b16-e7be-4566-9024-d1300dddc765</guid><dc:creator>junpu</dc:creator><description>&lt;p&gt;The above code was the code you decribed, but I am afraid the could not be enough, so I attach all my code&amp;nbsp; in the following .&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem about fatfs  and QSPI on nRF52840</title><link>https://devzone.nordicsemi.com/thread/193668?ContentTypeID=1</link><pubDate>Wed, 19 Jun 2019 12:28:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c7d7bef5-aade-402c-95ac-45d504416f54</guid><dc:creator>junpu</dc:creator><description>&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/**
 * @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(&amp;quot;Nordic&amp;quot;, &amp;quot;QSPI&amp;quot;, &amp;quot;1.00&amp;quot;)
);&lt;/pre&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static uint32_t file_open(const char*filename)
{
    static FIL file;
    FRESULT ff_result;

    NRF_LOG_INFO(&amp;quot;Opening file: %s.&amp;quot;, NRF_LOG_PUSH(filename));
    if(get_record_disabled()){
        return NRF_ERROR_BUSY;
    }
    ff_result = f_open(&amp;amp;file, filename, FA_READ | FA_WRITE | FA_OPEN_APPEND);
    if (ff_result != FR_OK)
    {
       NRF_LOG_INFO(&amp;quot;Unable to open or create file: %d&amp;quot;, ff_result);
       return NRF_ERROR_BUSY;
    }
    m_opened_file = &amp;amp;file;
    return NRF_SUCCESS;
}&lt;/pre&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static uint32_t file_write(const uint8_t *buf, uint32_t len)
{
    uint32_t written = 0;
    FRESULT ff_result;
    if(m_opened_file == NULL){
        NRF_LOG_ERROR(&amp;quot;Sorry, open file first&amp;quot;);
        return NRF_ERROR_BUSY;
    }
    NRF_LOG_HEXDUMP_DEBUG(buf, len);
    if(get_record_disabled()){
        return NRF_ERROR_BUSY;
    }
	f_lseek(m_opened_file,f_size(m_opened_file));
    ff_result = f_write(m_opened_file, buf, len, (UINT *) &amp;amp;written);
    if (ff_result != FR_OK || written != len)
    {
        NRF_LOG_ERROR(&amp;quot;Failed to write, ff_result: %d, written: %d&amp;quot;, ff_result, written);
        return NRF_ERROR_NULL;
    }
    else
    {
        NRF_LOG_DEBUG(&amp;quot;%d bytes written.&amp;quot;, written);
    }
    f_sync(m_opened_file);
    return NRF_SUCCESS;
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem about fatfs  and QSPI on nRF52840</title><link>https://devzone.nordicsemi.com/thread/193595?ContentTypeID=1</link><pubDate>Wed, 19 Jun 2019 09:00:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:47c5f213-8dfd-4e65-9258-ff0ea0c0728e</guid><dc:creator>Jared</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Could you share your definition of the block_dev? And the functions where you open read/write and close the files.&lt;/p&gt;
&lt;p&gt;Regards&lt;/p&gt;
&lt;p&gt;Jared&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem about fatfs  and QSPI on nRF52840</title><link>https://devzone.nordicsemi.com/thread/193521?ContentTypeID=1</link><pubDate>Wed, 19 Jun 2019 02:11:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e5ae0ab4-2730-404b-b81f-c47434704f9e</guid><dc:creator>junpu</dc:creator><description>&lt;p&gt;sdk :nRF5_SDK_15.2.0_9412b96&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;revision of the nRF52840 ： cortex-m4 nrf52840_xxAA 1024KB+4KB 256KB&amp;nbsp; PCA10056&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem about fatfs  and QSPI on nRF52840</title><link>https://devzone.nordicsemi.com/thread/193186?ContentTypeID=1</link><pubDate>Mon, 17 Jun 2019 12:49:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7dd75499-c683-47c3-9e03-f6f8b4960ce7</guid><dc:creator>Jared</dc:creator><description>&lt;p&gt;Hi,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Which SDK and Softdevice version and revision of the nRF52840 are you using?&lt;/p&gt;
&lt;p&gt;Regards&lt;/p&gt;
&lt;p&gt;Jared&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem about fatfs  and QSPI on nRF52840</title><link>https://devzone.nordicsemi.com/thread/192520?ContentTypeID=1</link><pubDate>Thu, 13 Jun 2019 00:21:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8215f711-cd2e-4487-9972-66cc720eb897</guid><dc:creator>junpu</dc:creator><description>&lt;p&gt;Attach the picture&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/2019_2D00_6_2D00_12-14_2D00_04_2D00_37.png" /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>