<?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>Flash Storage Write API has issues</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/67926/flash-storage-write-api-has-issues</link><description>Hello, 
 I am trying to use the flash API of fstorage in my code. I have called below function at the start of my code. I want to save some integer values every 1 min interval. 
 Flash reading is working fine, but when writing was tried my whole code</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 05 Nov 2020 13:36:54 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/67926/flash-storage-write-api-has-issues" /><item><title>RE: Flash Storage Write API has issues</title><link>https://devzone.nordicsemi.com/thread/278607?ContentTypeID=1</link><pubDate>Thu, 05 Nov 2020 13:36:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5360ccd2-c2f9-4390-b421-beaa124506c4</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Yes, you need to update the linker configuration with fs_data, sdh_stack_obervers etc. You can just refer to the example project or &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/66078/fs_data-will-not-fit-in-region-unplaced_sections/270350#270350"&gt;Vidar&amp;#39;s post&lt;/a&gt; and copy from there. It is easy to miss a few tings, but in that case you can do as here and just search for whatever is missing in the&amp;nbsp;example project files and you usually see what you need to add.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Flash Storage Write API has issues</title><link>https://devzone.nordicsemi.com/thread/278582?ContentTypeID=1</link><pubDate>Thu, 05 Nov 2020 11:54:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4df94889-26ba-4f11-84e8-72a11b378037</guid><dc:creator>GeekAD</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp;As per flash storage example, I have added the code in my project. I have copied all the code as it is just changed the starting location and end of the flash. Which I have added in the below code.&lt;/p&gt;
&lt;p&gt;Now the error coming which was occurred last time with me. Here is the link&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/66078/fs_data-will-not-fit-in-region-unplaced_sections"&gt;fs_data issue&lt;/a&gt;&amp;nbsp;which is coming now again. Last time I have used his suggestions to clear this fs_data error. should I use this answer now..&lt;/p&gt;
&lt;p&gt;The logs are shown below.&lt;/p&gt;
&lt;p&gt;1&amp;gt; &amp;quot;C:/Program Files/SEGGER/SEGGER Embedded Studio for ARM 4.52c/gcc/arm-none-eabi/bin/ld&amp;quot; -X --omagic -eReset_Handler --defsym=__vfprintf=__vfprintf_long --defsym=__vfscanf=__vfscanf_int -EL --gc-sections &amp;quot;-TD:/LTPL_Oct2019/PIR/Scrap Folder/Current_code/FW1_PIR-KNX_R1_working/nRF5_SDK_15.2.0_9412b96/examples/peripheral/twi_master_with_twis_slave/pca10040/blank/ses/Output/twi_master_with_twis_slave_pca10040 Debug/Obj/twi_master_with_twis_slave_pca10040.ld&amp;quot; -Map Output/Debug/Exe/twi_master_with_twis_slave_pca10040.map -u_vectors -o Output/Debug/Exe/twi_master_with_twis_slave_pca10040.elf --emit-relocs --start-group &amp;quot;@D:/LTPL_Oct2019/PIR/Scrap Folder/Current_code/FW1_PIR-KNX_R1_working/nRF5_SDK_15.2.0_9412b96/examples/peripheral/twi_master_with_twis_slave/pca10040/blank/ses/Output/twi_master_with_twis_slave_pca10040 Debug/Obj/twi_master_with_twis_slave_pca10040.ind&amp;quot; --end-group&lt;br /&gt;1&amp;gt; C:/Program Files/SEGGER/SEGGER Embedded Studio for ARM 4.52c/gcc/arm-none-eabi/bin/ld: Output/Debug/Exe/twi_master_with_twis_slave_pca10040.elf section `.fs_data&amp;#39; will not fit in region `UNPLACED_SECTIONS&amp;#39;&lt;br /&gt;1&amp;gt; C:/Program Files/SEGGER/SEGGER Embedded Studio for ARM 4.52c/gcc/arm-none-eabi/bin/ld: region `UNPLACED_SECTIONS&amp;#39; overflowed by 20 bytes&lt;br /&gt;1&amp;gt; C:/Program Files/SEGGER/SEGGER Embedded Studio for ARM 4.52c/gcc/arm-none-eabi/bin/ld: Output/twi_master_with_twis_slave_pca10040 Debug/Obj/nrf_fstorage.o: in function `nrf_fstorage_is_busy&amp;#39;:&lt;br /&gt;1&amp;gt; D:\LTPL_Oct2019\PIR\Scrap Folder\Current_code\FW1_PIR-KNX_R1_working\nRF5_SDK_15.2.0_9412b96\components\libraries\fstorage/nrf_fstorage.c:219: undefined reference to `__start_fs_data&amp;#39;&lt;br /&gt;1&amp;gt; C:/Program Files/SEGGER/SEGGER Embedded Studio for ARM 4.52c/gcc/arm-none-eabi/bin/ld: D:\LTPL_Oct2019\PIR\Scrap Folder\Current_code\FW1_PIR-KNX_R1_working\nRF5_SDK_15.2.0_9412b96\components\libraries\fstorage/nrf_fstorage.c:219: undefined reference to `__stop_fs_data&amp;#39;&lt;br /&gt;1&amp;gt; C:/Program Files/SEGGER/SEGGER Embedded Studio for ARM 4.52c/gcc/arm-none-eabi/bin/ld: Output/twi_master_with_twis_slave_pca10040 Debug/Obj/nrf_sdh.o:D:\LTPL_Oct2019\PIR\Scrap Folder\Current_code\FW1_PIR-KNX_R1_working\nRF5_SDK_15.2.0_9412b96\components\softdevice\common/nrf_sdh.c:83: undefined reference to `__start_sdh_req_observers&amp;#39;&lt;br /&gt;1&amp;gt; C:/Program Files/SEGGER/SEGGER Embedded Studio for ARM 4.52c/gcc/arm-none-eabi/bin/ld: Output/twi_master_with_twis_slave_pca10040 Debug/Obj/nrf_sdh.o:(.rodata.sdh_req_observers+0x4): undefined reference to `__stop_sdh_req_observers&amp;#39;&lt;br /&gt;1&amp;gt; C:/Program Files/SEGGER/SEGGER Embedded Studio for ARM 4.52c/gcc/arm-none-eabi/bin/ld: Output/twi_master_with_twis_slave_pca10040 Debug/Obj/nrf_sdh.o:D:\LTPL_Oct2019\PIR\Scrap Folder\Current_code\FW1_PIR-KNX_R1_working\nRF5_SDK_15.2.0_9412b96\components\softdevice\common/nrf_sdh.c:86: undefined reference to `__start_sdh_state_observers&amp;#39;&lt;br /&gt;1&amp;gt; C:/Program Files/SEGGER/SEGGER Embedded Studio for ARM 4.52c/gcc/arm-none-eabi/bin/ld: Output/twi_master_with_twis_slave_pca10040 Debug/Obj/nrf_sdh.o:(.rodata.sdh_state_observers+0x4): undefined reference to `__stop_sdh_state_observers&amp;#39;&lt;br /&gt;1&amp;gt; C:/Program Files/SEGGER/SEGGER Embedded Studio for ARM 4.52c/gcc/arm-none-eabi/bin/ld: Output/twi_master_with_twis_slave_pca10040 Debug/Obj/nrf_sdh.o:D:\LTPL_Oct2019\PIR\Scrap Folder\Current_code\FW1_PIR-KNX_R1_working\nRF5_SDK_15.2.0_9412b96\components\softdevice\common/nrf_sdh.c:89: undefined reference to `__start_sdh_stack_observers&amp;#39;&lt;br /&gt;1&amp;gt; C:/Program Files/SEGGER/SEGGER Embedded Studio for ARM 4.52c/gcc/arm-none-eabi/bin/ld: Output/twi_master_with_twis_slave_pca10040 Debug/Obj/nrf_sdh.o:(.rodata.sdh_stack_observers+0x4): undefined reference to `__stop_sdh_stack_observers&amp;#39;&lt;br /&gt;Build failed&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;

/*****************************************************************************
* Include section
* Include Files from the Compiler libraries
*****************************************************************************/

#include &amp;lt;stdbool.h&amp;gt;
#include &amp;lt;stdint.h&amp;gt;
#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;ctype.h&amp;gt;
#include &amp;lt;string.h&amp;gt;
#include &amp;quot;stddef.h&amp;quot;
//#include &amp;quot;config.h&amp;quot;
#include &amp;quot;nrf_drv_twi.h&amp;quot;
#include &amp;quot;nrf_gpio.h&amp;quot;
#include &amp;quot;app_error.h&amp;quot;
#include &amp;quot;nrf.h&amp;quot;
#include &amp;quot;bsp.h&amp;quot;
#include &amp;quot;app_util_platform.h&amp;quot;
#include &amp;quot;app_timer.h&amp;quot;
#include &amp;quot;nrf_drv_clock.h&amp;quot;
#include &amp;quot;boards.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;nrf_cli.h&amp;quot;
#include &amp;quot;nrf_cli_uart.h&amp;quot;
#include &amp;quot;nrf_soc.h&amp;quot;
#include &amp;quot;nordic_common.h&amp;quot;
#include &amp;quot;app_util.h&amp;quot;
#include &amp;quot;nrf_fstorage.h&amp;quot;


#include &amp;quot;nrf_sdh.h&amp;quot;
#include &amp;quot;nrf_sdh_ble.h&amp;quot;
#include &amp;quot;nrf_fstorage_sd.h&amp;quot;


/*****************************************************************************
* Include section
* User Prepared Include Files
*****************************************************************************/
#include &amp;quot;GPIOTE_driver.h&amp;quot;
#include &amp;quot;Relay_driver.h&amp;quot;
#include &amp;quot;TC78H620FNG.h&amp;quot;
#include &amp;quot;relay.h&amp;quot;
#include&amp;quot;Timer.h&amp;quot;
#include &amp;quot;nrf_delay.h&amp;quot;
#include &amp;quot;OPT3001_sensor.h&amp;quot;
#include &amp;quot;PIR.h&amp;quot;
#include &amp;quot;LED.h&amp;quot;
#include &amp;quot;config_relay.h&amp;quot;
#include &amp;quot;main.h&amp;quot;

#include &amp;quot;Definations.h&amp;quot;

#include &amp;quot;KNX_Timer.h&amp;quot;
#include &amp;quot;INIT.h&amp;quot;
#include &amp;quot;Test_Code1.h&amp;quot;
#include &amp;quot;Lighting_channel.h&amp;quot;
#include &amp;quot;Lighting_operation.h&amp;quot;
#include &amp;quot;Local_Relay.h&amp;quot;
#include &amp;quot;Presence_Channel.h&amp;quot;
#include &amp;quot;Presence_Operation.h&amp;quot;
#include &amp;quot;KNX_Operation_Handling.h&amp;quot;
#include &amp;quot;KNX_Datapoint_Handling.h&amp;quot;
#include &amp;quot;General_Settings.h&amp;quot;


//----------------------------------------------------------------------------
// Constants section
//----------------------------------------------------------------------------

#define FLASH_START_ADDR   0x26000
#define FLASH_END_ADDR     0x27000
//----------------------------------------------------------------------------
// Boolean variables section
//----------------------------------------------------------------------------

bool gb_PIR_Operation_Start=0;

//-----------------------------------------------------------------------------
// Character variables section
//----------------------------------------------------------------------------

uint8_t gb_Power_ON_flag=0;
//----------------------------------------------------------------------------
// unsigned integer variables section
//----------------------------------------------------------------------------


uint16_t  gb_OPT_RAW_DATA, gb_OPT_CONFIGURATION_REG_DATA;
//----------------------------------------------------------------------------
// Signed integer variables section
//----------------------------------------------------------------------------


//----------------------------------------------------------------------------
// unsigned long integer variables section
//----------------------------------------------------------------------------


//----------------------------------------------------------------------------
// signed long integer variables section
//----------------------------------------------------------------------------


//----------------------------------------------------------------------------
// unsigned long long integer variables section
//----------------------------------------------------------------------------


//----------------------------------------------------------------------------
// signed long long integer variables section
//----------------------------------------------------------------------------


//----------------------------------------------------------------------------
// Float variables section
//----------------------------------------------------------------------------


//----------------------------------------------------------------------------
// Double variables section
//----------------------------------------------------------------------------


//----------------------------------------------------------------------------
// Structure or Union variables section
//----------------------------------------------------------------------------




//----------------------------------------------------------------------------
// Local Functions Prototypes
//----------------------------------------------------------------------------

void Flash_init(void);
//----------------------------------------------------------------------------
// Global Functions
//----------------------------------------------------------------------------


#define BUTTON_DETECTION_DELAY  APP_TIMER_TICKS(50)
#define APP_BLE_CONN_CFG_TAG    1


/* Defined in cli.c */
extern void cli_init(void);
extern void cli_start(void);
extern void cli_process(void);

static void fstorage_evt_handler(nrf_fstorage_evt_t * p_evt);


NRF_FSTORAGE_DEF(nrf_fstorage_t fstorage) =
{
    /* Set a handler for fstorage events. */
    .evt_handler = fstorage_evt_handler,

    /* These below are the boundaries of the flash space assigned to this instance of fstorage.
     * You must set these manually, even at runtime, before nrf_fstorage_init() is called.
     * The function nrf5_flash_end_addr_get() can be used to retrieve the last address on the
     * last page of flash available to write data. */
    .start_addr = FLASH_START_ADDR,
    .end_addr   = FLASH_END_ADDR,
};

/* Dummy data to write to flash. */
static uint32_t m_data          = 0xBADC0FFE;
uint32_t R_data=0;
static char     m_hello_world[] = &amp;quot;hello world&amp;quot;;


/**@brief   Helper function to obtain the last address on the last page of the on-chip flash that
 *          can be used to write user data.
 */
static uint32_t nrf5_flash_end_addr_get()
{
    uint32_t const bootloader_addr = NRF_UICR-&amp;gt;NRFFW[0];
    uint32_t const page_sz         = NRF_FICR-&amp;gt;CODEPAGESIZE;
    uint32_t const code_sz         = NRF_FICR-&amp;gt;CODESIZE;

    return (bootloader_addr != 0xFFFFFFFF ?
            bootloader_addr : (code_sz * page_sz));
}


#ifdef SOFTDEVICE_PRESENT
/**@brief   Function for initializing the SoftDevice and enabling the BLE stack. */
static void ble_stack_init(void)
{
    ret_code_t rc;
    uint32_t   ram_start;

    /* Enable the SoftDevice. */
    rc = nrf_sdh_enable_request();
    APP_ERROR_CHECK(rc);

    rc = nrf_sdh_ble_default_cfg_set(APP_BLE_CONN_CFG_TAG, &amp;amp;ram_start);
    APP_ERROR_CHECK(rc);

    rc = nrf_sdh_ble_enable(&amp;amp;ram_start);
    APP_ERROR_CHECK(rc);
}
#else
static void clock_init(void)
{
    /* Initialize the clock. */
    ret_code_t rc = nrf_drv_clock_init();
    APP_ERROR_CHECK(rc);

    nrf_drv_clock_lfclk_request(NULL);

    // Wait for the clock to be ready.
    while (!nrf_clock_lf_is_running()) {;}
}
#endif


/**@brief   Initialize the timer. */
static void timer_init_1(void)
{
    ret_code_t err_code = app_timer_init();
    APP_ERROR_CHECK(err_code);
}


/**@brief   Sleep until an event is received. */
static void power_manage(void)
{
#ifdef SOFTDEVICE_PRESENT
    (void) sd_app_evt_wait();
#else
    __WFE();
#endif
}


static void fstorage_evt_handler(nrf_fstorage_evt_t * p_evt)
{
    if (p_evt-&amp;gt;result != NRF_SUCCESS)
    {
        NRF_LOG_INFO(&amp;quot;--&amp;gt; Event received: ERROR while executing an fstorage operation.&amp;quot;);
        return;
    }

    switch (p_evt-&amp;gt;id)
    {
        case NRF_FSTORAGE_EVT_WRITE_RESULT:
        {
            NRF_LOG_INFO(&amp;quot;--&amp;gt; Event received: wrote %d bytes at address 0x%x.&amp;quot;,
                         p_evt-&amp;gt;len, p_evt-&amp;gt;addr);
        } break;

        case NRF_FSTORAGE_EVT_ERASE_RESULT:
        {
            NRF_LOG_INFO(&amp;quot;--&amp;gt; Event received: erased %d page from address 0x%x.&amp;quot;,
                         p_evt-&amp;gt;len, p_evt-&amp;gt;addr);
        } break;

        default:
            break;
    }
}


static void print_flash_info(nrf_fstorage_t * p_fstorage)
{
    NRF_LOG_INFO(&amp;quot;========| flash info |========&amp;quot;);
    NRF_LOG_INFO(&amp;quot;erase unit: \t%d bytes&amp;quot;,      p_fstorage-&amp;gt;p_flash_info-&amp;gt;erase_unit);
    NRF_LOG_INFO(&amp;quot;program unit: \t%d bytes&amp;quot;,    p_fstorage-&amp;gt;p_flash_info-&amp;gt;program_unit);
    NRF_LOG_INFO(&amp;quot;==============================&amp;quot;);
}


void wait_for_flash_ready(nrf_fstorage_t const * p_fstorage)
{
    /* While fstorage is busy, sleep and wait for an event. */
    while (nrf_fstorage_is_busy(p_fstorage))
    {
        power_manage();
    }
}


static void log_init(void)
{
    ret_code_t rc = NRF_LOG_INIT(NULL);
    APP_ERROR_CHECK(rc);
}

//***************************************************************************/
void main(void)
{
          // Hardware initialization 
          Hardware_INIT();

          // flash initialization 
          Flash_init();

         
       

     

          //Power ON Flag set
          gb_Power_ON_flag=1;

          // config all function 
          // Config_all();

          //nrf_delay_ms(2000);
          gb_Calibration_Time_flag_for_OPT=0;



          // load 30 sec to timer for PIR to configure 
          gb_PIR_config_time=35;
      
          // wait time 30 sec for PIR sensor to calibrate itself 
          while(gb_PIR_config_time!=0){   /* do nothing */}
      
          printf(&amp;quot;delay_1\n&amp;quot;);
          // nrf_drv_gpiote_out_set(const_LED);   // LED can be made ON to indicate PIR is active now


          gb_PIR_Operation_Start=0;

          /* Main loop */


    while (1)
    {
    //operation 
    }
    
}
void Flash_init(void)
{  ret_code_t rc;

    timer_init_1();
    log_init();
//    cli_init();

    NRF_LOG_INFO(&amp;quot;fstorage example started.&amp;quot;);

    nrf_fstorage_api_t * p_fs_api;

#ifdef SOFTDEVICE_PRESENT
    NRF_LOG_INFO(&amp;quot;SoftDevice is present.&amp;quot;);
    NRF_LOG_INFO(&amp;quot;Initializing nrf_fstorage_sd implementation...&amp;quot;);
    /* Initialize an fstorage instance using the nrf_fstorage_sd backend.
     * nrf_fstorage_sd uses the SoftDevice to write to flash. This implementation can safely be
     * used whenever there is a SoftDevice, regardless of its status (enabled/disabled). */
    p_fs_api = &amp;amp;nrf_fstorage_sd;
#else
    NRF_LOG_INFO(&amp;quot;SoftDevice not present.&amp;quot;);
    NRF_LOG_INFO(&amp;quot;Initializing nrf_fstorage_nvmc implementation...&amp;quot;);
    /* Initialize an fstorage instance using the nrf_fstorage_nvmc backend.
     * nrf_fstorage_nvmc uses the NVMC peripheral. This implementation can be used when the
     * SoftDevice is disabled or not present.
     *
     * Using this implementation when the SoftDevice is enabled results in a hardfault. */
    p_fs_api = &amp;amp;nrf_fstorage_nvmc;
#endif

    rc = nrf_fstorage_init(&amp;amp;fstorage, p_fs_api, NULL);
    APP_ERROR_CHECK(rc);

    print_flash_info(&amp;amp;fstorage);

    /* It is possible to set the start and end addresses of an fstorage instance at runtime.
     * They can be set multiple times, should it be needed. The helper function below can
     * be used to determine the last address on the last page of flash memory available to
     * store data. */
    (void) nrf5_flash_end_addr_get();

    /* Let&amp;#39;s write to flash. */
    NRF_LOG_INFO(&amp;quot;Writing \&amp;quot;%x\&amp;quot; to flash.&amp;quot;, m_data);
    rc = nrf_fstorage_write(&amp;amp;fstorage, 0x3e000, &amp;amp;m_data, sizeof(m_data), NULL);
    APP_ERROR_CHECK(rc);

    wait_for_flash_ready(&amp;amp;fstorage);
    NRF_LOG_INFO(&amp;quot;Done.&amp;quot;);

#ifdef SOFTDEVICE_PRESENT
    /* Enable the SoftDevice and the BLE stack. */
    NRF_LOG_INFO(&amp;quot;Enabling the SoftDevice.&amp;quot;);
    ble_stack_init();

    m_data = 0xDEADBEEF;

    NRF_LOG_INFO(&amp;quot;Writing \&amp;quot;%x\&amp;quot; to flash.&amp;quot;, m_data);
    rc = nrf_fstorage_write(&amp;amp;fstorage, 0x3e100, &amp;amp;m_data, sizeof(m_data), NULL);
    APP_ERROR_CHECK(rc);

    wait_for_flash_ready(&amp;amp;fstorage);
    NRF_LOG_INFO(&amp;quot;Done.&amp;quot;);
#endif

    NRF_LOG_INFO(&amp;quot;Writing \&amp;quot;%s\&amp;quot; to flash.&amp;quot;, m_hello_world);
    rc = nrf_fstorage_write(&amp;amp;fstorage, 0x3f000, m_hello_world, sizeof(m_hello_world), NULL);
    APP_ERROR_CHECK(rc);

    wait_for_flash_ready(&amp;amp;fstorage);
    NRF_LOG_INFO(&amp;quot;Done.&amp;quot;);

//    NRF_LOG_INFO(&amp;quot;Use &amp;#39;read&amp;#39; to read bytes from the flash.&amp;quot;);
//    NRF_LOG_INFO(&amp;quot;Use &amp;#39;write&amp;#39; to write bytes to the flash.&amp;quot;);
//    NRF_LOG_INFO(&amp;quot;Use &amp;#39;erase&amp;#39; to erase flash pages.&amp;quot;);
//    NRF_LOG_INFO(&amp;quot;Use &amp;#39;flasharea&amp;#39; to print and configure the flash read boundaries.&amp;quot;);

    rc = nrf_fstorage_read(&amp;amp;fstorage, 0x3e100, &amp;amp;R_data, sizeof(R_data));
    APP_ERROR_CHECK(rc);
    NRF_LOG_INFO(&amp;quot;R_data=%x&amp;quot;,R_data);
    printf(&amp;quot;R_data=%x&amp;quot;,R_data);
}


/*****************************************************************************
* End of file.
*****************************************************************************/



&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Flash Storage Write API has issues</title><link>https://devzone.nordicsemi.com/thread/278535?ContentTypeID=1</link><pubDate>Thu, 05 Nov 2020 07:50:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9e1d5cbe-498c-4575-8b80-d904b0564cb5</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;The Flash Storage Example demonstrates exactly how to properly use fstorage. Please note that there are projects for both using and not using a SoftDevice and differences in the code (search for SOFTDEVICE_PRESENT). You also need to use nrf_fstorage_sd.c with the SoftDevice and nrf_fstorage_nvmc.c if not using a SoftDevice. Essentially you just need to do&amp;nbsp;exactly the same as in the example project using SoftDevice (but you can of course skip all the CLI related stuff).&lt;/p&gt;
&lt;p&gt;In addition to the example projects that demonstrate this in full (including sdk_config.h), you also have the &lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v15.2.0/lib_fstorage.html"&gt;fstorage documentation&lt;/a&gt; that describes how fstorage works and&amp;nbsp;should be used.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Flash Storage Write API has issues</title><link>https://devzone.nordicsemi.com/thread/278528?ContentTypeID=1</link><pubDate>Thu, 05 Nov 2020 05:00:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:faac9b15-ae0e-4914-bce0-6c190a1e9964</guid><dc:creator>GeekAD</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;It is a bit difficult for me to share the total code. Instead of that can you please suggest the process of adding flash storage to any code? I mean which definitions need to be enabled in sdk_config.h and which preprocessor definition need to add in the project and all the process in simple steps. So that I can try that in my code. I will roll back my all changes and try to go by your steps.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Flash Storage Write API has issues</title><link>https://devzone.nordicsemi.com/thread/278473?ContentTypeID=1</link><pubDate>Wed, 04 Nov 2020 14:20:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:35f300ff-7193-4413-b5f9-ea0e05f543dd</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;This does not build when dropped into the flash_storage example. Also, it is a bit vague which modifications you have made and I am very interested in seeing exactly your setup so that I do not have to make assumptions and know I will see the issue you are seeing. Therefore I wonder if you can make a zip archive of the whole project folder (e.g. &amp;lt;SDK&amp;gt;\examples\peripheral\flash_fstorage\ and including all subfolder etc) and upload here? That way I&amp;nbsp; can test exactly the same setup as you? Please specify which exact project file you are using as well.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Flash Storage Write API has issues</title><link>https://devzone.nordicsemi.com/thread/278466?ContentTypeID=1</link><pubDate>Wed, 04 Nov 2020 14:09:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b8d298f9-f9a4-48db-bf2e-337de5f38509</guid><dc:creator>GeekAD</dc:creator><description>&lt;p&gt;I have just replicated the flash storage example along with sdk_config definitions. Nothing much added. May be from my side sdk_config.h definitions are missings or I am enabling different library.&lt;/p&gt;
&lt;p&gt;Kindly guide me to that also.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Flash Storage Write API has issues</title><link>https://devzone.nordicsemi.com/thread/278464?ContentTypeID=1</link><pubDate>Wed, 04 Nov 2020 14:05:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:01d7f2d1-9f28-49ca-85cf-ea04e12f6838</guid><dc:creator>GeekAD</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I have attached the main file code. I am using SDK 15.2 with SoftDevice 6.1.0.&lt;/p&gt;
&lt;p&gt;I have not updated the definition of SOFTDEVICE_PRESENT&amp;nbsp; in the linker. When added more issue is coming.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;
#include &amp;lt;stdbool.h&amp;gt;
#include &amp;lt;stdint.h&amp;gt;
#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;ctype.h&amp;gt;
#include &amp;lt;string.h&amp;gt;
#include &amp;quot;stddef.h&amp;quot;
//#include &amp;quot;config.h&amp;quot;
#include &amp;quot;nrf_drv_twi.h&amp;quot;
#include &amp;quot;nrf_gpio.h&amp;quot;
#include &amp;quot;app_error.h&amp;quot;
#include &amp;quot;nrf.h&amp;quot;
#include &amp;quot;bsp.h&amp;quot;
#include &amp;quot;app_util_platform.h&amp;quot;
#include &amp;quot;app_timer.h&amp;quot;
#include &amp;quot;nrf_drv_clock.h&amp;quot;
#include &amp;quot;boards.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;nrf_cli.h&amp;quot;
#include &amp;quot;nrf_cli_uart.h&amp;quot;
#include &amp;quot;nrf_fstorage.h&amp;quot;
#include &amp;quot;nrf_fstorage_sd.h&amp;quot;
#include &amp;quot;nrf_sdh_ble.h&amp;quot;
#include &amp;quot;nrf_sdh.h&amp;quot;


#include &amp;quot;nrf_soc.h&amp;quot;
/*****************************************************************************
* Include section
* User Prepared Include Files
*****************************************************************************/
#include &amp;quot;GPIOTE_driver.h&amp;quot;
#include &amp;quot;Relay_driver.h&amp;quot;

#include &amp;quot;relay.h&amp;quot;
#include&amp;quot;Timer.h&amp;quot;
#include &amp;quot;nrf_delay.h&amp;quot;

#include &amp;quot;PIR.h&amp;quot;
#include &amp;quot;LED.h&amp;quot;
#include &amp;quot;config_relay.h&amp;quot;
#include &amp;quot;main.h&amp;quot;

#include &amp;quot;Definations.h&amp;quot;



//----------------------------------------------------------------------------
// Constants section
//----------------------------------------------------------------------------
#define FLASH_START_ADDR   0x60000
#define FLASH_END_ADDR     0x61000
#define BUTTON_DETECTION_DELAY  APP_TIMER_TICKS(50)
#define APP_BLE_CONN_CFG_TAG    1

//----------------------------------------------------------------------------
// Boolean variables section
//----------------------------------------------------------------------------

bool gb_PIR_Operation_Start=0;

//-----------------------------------------------------------------------------
// Character variables section
//----------------------------------------------------------------------------

uint8_t gb_Power_ON_flag=0;
//----------------------------------------------------------------------------
// unsigned integer variables section
//----------------------------------------------------------------------------


uint16_t  gb_OPT_RAW_DATA, gb_OPT_CONFIGURATION_REG_DATA;
//----------------------------------------------------------------------------
// Signed integer variables section
//----------------------------------------------------------------------------


//----------------------------------------------------------------------------
// unsigned long integer variables section
//----------------------------------------------------------------------------


//----------------------------------------------------------------------------
// signed long integer variables section
//----------------------------------------------------------------------------


//----------------------------------------------------------------------------
// unsigned long long integer variables section
//----------------------------------------------------------------------------


//----------------------------------------------------------------------------
// signed long long integer variables section
//----------------------------------------------------------------------------


//----------------------------------------------------------------------------
// Float variables section
//----------------------------------------------------------------------------


//----------------------------------------------------------------------------
// Double variables section
//----------------------------------------------------------------------------


//----------------------------------------------------------------------------
// Structure or Union variables section
//----------------------------------------------------------------------------




//----------------------------------------------------------------------------
// Local Functions Prototypes
//----------------------------------------------------------------------------

void Flash_init(void);
//void Flash_read(void);
void Flash_Operation(void);

#ifdef  FLASH_12
void wait_for_flash_ready(nrf_fstorage_t const * p_fstorage);


// flash 
static void fstorage_evt_handler(nrf_fstorage_evt_t * p_evt);



NRF_FSTORAGE_DEF(nrf_fstorage_t fstorage) =
{
    /* Set a handler for fstorage events. */
    .evt_handler = fstorage_evt_handler,

    /* These below are the boundaries of the flash space assigned to this instance of fstorage.
     * You must set these manually, even at runtime, before nrf_fstorage_init() is called.
     * The function nrf5_flash_end_addr_get() can be used to retrieve the last address on the
     * last page of flash available to write data. */
    .start_addr = FLASH_START_ADDR,         //    0x70ff0
    .end_addr   = FLASH_END_ADDR,          //     0x80000
};


/* Dummy data to write to flash. */
static uint32_t m_data          = 0xBADC0FFE;
static uint32_t gb_m_data=0;
static char     m_hello_world[] = &amp;quot;hello world&amp;quot;;
static char     gb_restored_string[50];


/**@brief   Helper function to obtain the last address on the last page of the on-chip flash that
 *          can be used to write user data.
 */
static uint32_t nrf5_flash_end_addr_get()
{
    uint32_t const bootloader_addr = NRF_UICR-&amp;gt;NRFFW[0];
    uint32_t const page_sz         = NRF_FICR-&amp;gt;CODEPAGESIZE;
    uint32_t const code_sz         = NRF_FICR-&amp;gt;CODESIZE;

    return (bootloader_addr != 0xFFFFFFFF ?
            bootloader_addr : (code_sz * page_sz));
}



/**@brief   Initialize the timer. */
static void timer_init_1(void)
{
    ret_code_t err_code = app_timer_init();
    APP_ERROR_CHECK(err_code);
}

/**@brief   Sleep until an event is received. */
static void power_manage(void)
{
//#ifdef SOFTDEVICE_PRESENT
    (void) sd_app_evt_wait();
//#else
//    __WFE();
//#endif
}



static void ble_stack_init(void)
{
    ret_code_t rc;
    uint32_t   ram_start;

    /* Enable the SoftDevice. */
    rc = nrf_sdh_enable_request();
    APP_ERROR_CHECK(rc);

    rc = nrf_sdh_ble_default_cfg_set(APP_BLE_CONN_CFG_TAG, &amp;amp;ram_start);
    APP_ERROR_CHECK(rc);

    rc = nrf_sdh_ble_enable(&amp;amp;ram_start);
    APP_ERROR_CHECK(rc);
}

static void print_flash_info(nrf_fstorage_t * p_fstorage)
{
    printf(&amp;quot;========| flash info |========&amp;quot;);
    printf(&amp;quot;erase unit: \t%d bytes&amp;quot;,      p_fstorage-&amp;gt;p_flash_info-&amp;gt;erase_unit);
    printf(&amp;quot;program unit: \t%d bytes&amp;quot;,    p_fstorage-&amp;gt;p_flash_info-&amp;gt;program_unit);
    printf(&amp;quot;==============================&amp;quot;);
}

static void fstorage_evt_handler(nrf_fstorage_evt_t * p_evt)
{
    if (p_evt-&amp;gt;result != NRF_SUCCESS)
    {
        NRF_LOG_INFO(&amp;quot;--&amp;gt; Event received: ERROR while executing an fstorage operation.&amp;quot;);
        return;
    }

    switch (p_evt-&amp;gt;id)
    {
        case NRF_FSTORAGE_EVT_WRITE_RESULT:
        {
            NRF_LOG_INFO(&amp;quot;--&amp;gt; Event received: wrote %d bytes at address 0x%x.&amp;quot;,
                         p_evt-&amp;gt;len, p_evt-&amp;gt;addr);
        } break;

        case NRF_FSTORAGE_EVT_ERASE_RESULT:
        {
            NRF_LOG_INFO(&amp;quot;--&amp;gt; Event received: erased %d page from address 0x%x.&amp;quot;,
                         p_evt-&amp;gt;len, p_evt-&amp;gt;addr);
        } break;

        case  NRF_FSTORAGE_EVT_READ_RESULT :
                      printf(&amp;quot;Flash read sucess\n&amp;quot;);
                      break;


        default:
            break;
    }
}

void wait_for_flash_ready(nrf_fstorage_t const * p_fstorage)
{
    /* While fstorage is busy, sleep and wait for an event. */
    while (nrf_fstorage_is_busy(p_fstorage))
    {
        power_manage();
    }
}

#endif

//----------------------------------------------------------------------------
// Global Functions
//----------------------------------------------------------------------------

void main(void)
{
 ret_code_t rc=0;
 uint32_t data_1=5;

    // Hardware initialization 
    Hardware_INIT();
    #ifdef  FLASH_12
    // Flash initialization 
      Flash_init();
  
    // Flash Read function
      Flash_Operation();
    #endif
    
     
   
    printf(&amp;quot;\r Initialization completed \r\n &amp;quot;);
    

  

    //Power ON Flag set
    gb_Power_ON_flag=1;

    // config all function 
    // Config_all();

    //nrf_delay_ms(2000);
    gb_Calibration_Time_flag_for_OPT=0;



      // relay made off 
      //x`(1);

   

      // load 30 sec to timer for PIR to configure 
      gb_PIR_config_time=35;
      
      // wait time 30 sec for PIR sensor to calibrate itself 
      while(gb_PIR_config_time!=0){   /* do nothing */}
      
      printf(&amp;quot;delay\n&amp;quot;);
      // nrf_drv_gpiote_out_set(const_LED);   // LED can be made ON to indicate PIR is active now
     
      // operation start flag is cleared
      gb_PIR_Operation_Start=0;
   
    
/* Main loop */


    while (1)
    {
    // operation 
    }
}

void Flash_init(void)
{
 uint32_t data_1=5;
      ret_code_t rc;

      #ifdef  FLASH_12
      nrf_fstorage_api_t * p_fs_api;

     /* Initialize an fstorage instance using the nrf_fstorage_sd backend.
     * nrf_fstorage_sd uses the SoftDevice to write to flash. This implementation can safely be
     * used whenever there is a SoftDevice, regardless of its status (enabled/disabled). */
      p_fs_api = &amp;amp;nrf_fstorage_sd;



      rc = nrf_fstorage_init(&amp;amp;fstorage, p_fs_api, NULL);
      APP_ERROR_CHECK(rc);

      /* It is possible to set the start and end addresses of an fstorage instance at runtime.
     * They can be set multiple times, should it be needed. The helper function below can
     * be used to determine the last address on the last page of flash memory available to
     * store data. */
//     (void) nrf5_flash_end_addr_get();


//       print_flash_info(&amp;amp;fstorage);

      #ifdef  UART_Flash
      printf(&amp;quot;Flash Init=%d\n&amp;quot;,rc);
      #endif
//
    
//            wait_for_flash_ready(&amp;amp;fstorage);


    #endif

}

void Flash_Operation(void)
{
 ret_code_t rc;
 uint32_t local_var=0, data=5;
 uint8_t  len=0;
  
  /***********************************Flash Read *****************************************/
    #ifdef  FLASH_12
//      wait_for_flash_ready(&amp;amp;fstorage);
//    printf(&amp;quot;Done.&amp;quot;);

      rc = nrf_fstorage_read(&amp;amp;fstorage, FLASH_START_ADDR, &amp;amp;local_var, sizeof(local_var));
       
       APP_ERROR_CHECK(rc);
//        wait_for_flash_ready(&amp;amp;fstorage);
                 
                 NRF_LOG_INFO(&amp;quot;Enabling the SoftDevice.&amp;quot;);
                  ble_stack_init();
                   
      #ifdef  UART_Flash
        printf(&amp;quot;local_var=%x , RC=%x \n&amp;quot;,local_var,rc); 
        printf(&amp;quot;Flash read Done.\n&amp;quot;);
      #endif


      #endif
     /***********************************Flash read end *****************************************/

      /***********************************Flash write *****************************************/
          
//           rc = nrf_fstorage_erase(&amp;amp;fstorage, FLASH_START_ADDR , 1, NULL);
        
            APP_ERROR_CHECK(rc);
            wait_for_flash_ready(&amp;amp;fstorage);
            rc = nrf_fstorage_write(&amp;amp;fstorage, FLASH_START_ADDR , &amp;amp;data, sizeof(data), NULL);
    
            APP_ERROR_CHECK(rc);
            wait_for_flash_ready(&amp;amp;fstorage);
            
                #ifdef  UART_Flash
                printf(&amp;quot;ERR code=%d,Flash write %x\n&amp;quot;,rc,data);
                #endif
        /***********************************Flash write end *****************************************/

}



/*****************************************************************************
* End of file.
*****************************************************************************/

&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Flash Storage Write API has issues</title><link>https://devzone.nordicsemi.com/thread/278460?ContentTypeID=1</link><pubDate>Wed, 04 Nov 2020 13:55:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d97c55e2-0ca3-4770-9ed7-74a6dfb60cd8</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;I see. I do not see anything obvious, then. Can you upload code that reproduce this on a DK so that I can get a full understanding and test on my side? Which SDK version are you using?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Flash Storage Write API has issues</title><link>https://devzone.nordicsemi.com/thread/278458?ContentTypeID=1</link><pubDate>Wed, 04 Nov 2020 13:47:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dd141233-964f-4698-b539-41920af1f4da</guid><dc:creator>GeekAD</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I am calling this function at the beginning of the main. and yes I am using softdevice.&lt;pre class="ui-code" data-mode="text"&gt;
    // Hardware initialization 
    Hardware_INIT();
    #ifdef  FLASH_12
    // Flash initialization 
      Flash_init();
  
    // Flash Read &amp;amp; write function to check if it is actually working
      Flash_Operation();
    #endif
    
     &lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Flash Storage Write API has issues</title><link>https://devzone.nordicsemi.com/thread/278439?ContentTypeID=1</link><pubDate>Wed, 04 Nov 2020 12:42:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b120ebcb-694d-40a7-817c-8a087052e5ed</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
[quote user="AshishDain"]Can you please explain more on this I am not clear on what you said&amp;nbsp;&lt;span&gt;&amp;quot;Is it so that&amp;nbsp;&lt;/span&gt;the call to&amp;nbsp;nrf_fstorage_write() on line 86 in the snippet returns but not the call to wait_for_flash_ready() on line 89? &amp;quot;[/quote]
&lt;p&gt;I&amp;nbsp;was just writing down how I understood your description of the behaviour to try to be sure I got it right. To rephrase: Is it so that execution reaches&amp;nbsp;wait_for_flash_ready() after the call to&amp;nbsp;wait_for_flash_ready(), but it never returns? I assume so.&lt;/p&gt;
[quote user="AshishDain"]I have changed the priority of other peripherals but the issue is still there. As you said, fstorage priority higher or same but I couldn&amp;#39;t able to find in the sdk_config.h file[/quote]
&lt;p&gt;If my initial theory is relevant, then what matters is the priority where you are waiting for the flash operation to finish relative to the fstorage priority, which is essentially the SoftDevice interrupt priority, if you are using a SoftDevice. Can you confirm that you are using a SoftDevice?&lt;/p&gt;
&lt;p&gt;If yes,&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;How is your&amp;nbsp;Flash_Operation() called? where is it called from? Is it from an event handler or similar running (interrupt), or from the main loop?&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If this is not the issue or you do not make progress perhaps you can show more or all of your project so that I get a proper context to understand what is happening?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Flash Storage Write API has issues</title><link>https://devzone.nordicsemi.com/thread/278359?ContentTypeID=1</link><pubDate>Wed, 04 Nov 2020 05:07:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b09eaf13-cfd3-42df-88d0-38a0dde2e9eb</guid><dc:creator>GeekAD</dc:creator><description>&lt;p&gt;Hi Einar,&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Can you please explain more on this I am not clear on what you said&amp;nbsp;&lt;span&gt;&amp;quot;Is it so that&amp;nbsp;&lt;/span&gt;the call to&amp;nbsp;nrf_fstorage_write() on line 86 in the snippet returns but not the call to wait_for_flash_ready() on line 89? &amp;quot;&lt;/p&gt;
&lt;p&gt;I have changed the priority of other peripherals but the issue is still there. As you said, fstorage priority higher or same but I couldn&amp;#39;t able to find in the sdk_config.h file&lt;/p&gt;
&lt;div class="content full threaded-reply-content user-defined-markup"&gt;
&lt;div class="content"&gt;&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Flash Storage Write API has issues</title><link>https://devzone.nordicsemi.com/thread/278294?ContentTypeID=1</link><pubDate>Tue, 03 Nov 2020 14:07:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7aa60e6a-7c62-4839-9db1-9f5b4d0dd757</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Is it so that the call to&amp;nbsp;nrf_fstorage_write() on line 86 in the snippet returns but not the call to wait_for_flash_ready() on line 89? If so, a typical reason for such a behavior would be if this code is running with the same or higher&amp;nbsp;interrupt priority than fstorage. If so the scheduled write would never happen, and there would be a deadlock.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>