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

FDS after Init show ok,but always waitting for ready

Hi,

I  want to add FDS basedon  dimming_serve example ,However,after fds_init(); it  not jump to fds_evt_handler but stop wait .

The below is my code:

static void initialize(void)
{
    __LOG_INIT(LOG_SRC_APP | LOG_SRC_ACCESS | LOG_SRC_BEARER, LOG_LEVEL_INFO, LOG_CALLBACK_DEFAULT);
    __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "----- BLE Mesh Dimming Server Demo -----\n");

    ERROR_CHECK(app_timer_init());
    hal_leds_init();

    ble_stack_init();

#if MESH_FEATURE_GATT_ENABLED
    gap_params_init();
    conn_params_init();
#endif

    //mesh_init();

    uint32_t status = app_pwm_init(&PWM0, &m_pwm0_config, NULL);
    APP_ERROR_CHECK(status);
    m_pwm0_max = app_pwm_cycle_ticks_get(&PWM0);
    __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "PWM max ticks: %d\n", m_pwm0_max);

    #if 1
    //FDS
    /* Register first to receive an event when initialization is complete. */
    status=fds_register(fds_evt_handler);//(void) fds_register(fds_evt_handler);
    __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Status fds register is : %d\n",status);

    __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Initializing fds...\n");

    status=fds_init();
    __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Status fds init is : %d\n",status);
    APP_ERROR_CHECK(status);

    /* Wait for fds to initialize. */
    wait_for_fds_ready();
    #if 0
    __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Available commands:\n");
    __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "- print all\t\tprint records\n");
    __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "- print config\tprint configuration\n");
    __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "- update\t\tupdate configuration\n");
    __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "- stat\t\tshow statistics\n");
    __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "- write\t\twrite a new record\n");
    __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "- delete\t\tdelete a record\n");
    __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "- delete_all\tdelete all records\n");
    __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "- gc\t\trun garbage collection\n");
    #endif

    __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Reading flash usage statistics...\n");

    fds_stat_t stat = {0};

    status = fds_stat(&stat);
    APP_ERROR_CHECK(status);

    __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Found %d valid records.\n", stat.valid_records);
    __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Found %d dirty records (ready to be garbage collected).\n", stat.dirty_records);

    fds_record_desc_t desc = {0};
    fds_find_token_t  tok  = {0};

    status = fds_record_find(CONFIG_FILE, CONFIG_REC_KEY, &desc, &tok);

    if (status == FDS_SUCCESS)
    {
        /* A config file is in flash. Let's update it. */
        fds_flash_record_t config = {0};

        /* Open the record and read its contents. */
        status = fds_record_open(&desc, &config);
        APP_ERROR_CHECK(status);

        /* Copy the configuration from flash into m_dummy_cfg. */
        memcpy(&m_dummy_cfg, config.p_data, sizeof(configuration_t));

        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Config file found, updating boot count to %d\n", m_dummy_cfg.boot_count);

        /* Update boot count. */
        m_dummy_cfg.boot_count++;

        /* Close the record when done reading. */
        status = fds_record_close(&desc);
        APP_ERROR_CHECK(status);

        /* Write the updated record to flash. */
        status = fds_record_update(&desc, &m_dummy_record);
        APP_ERROR_CHECK(status);
    }
    else
    {
        /* System config not found; write a new one. */
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Writing config file...\n");

        status = fds_record_write(&desc, &m_dummy_record);
        APP_ERROR_CHECK(status);
    }

   #endif
}

And The Bellow is Log:

<t: 0>, main.c, 558, ----- BLE Mesh Dimming Server Demo -----
<t: 17925>, ble_softdevice_support.c, 124, RAM Start is 0x20002DA0
<t: 17945>, main.c, 575, PWM max ticks: 1600
<t: 17948>, main.c, 581, Status fds register is : 0
<t: 17950>, main.c, 583, Initializing fds...

How To solve this ? TKS in anvance.

Best Regards

Panda

Parents
  • Hi, 

    When adding fds (and fstorage) care should be taken to avoid overlapping the flash area occupied by the mesh flash manager module. We have a guide here about integrating Mesh into nRF5 SDK and vice versa. 

    How do you configure the fds module ? and fstorage module ? 

    Do you need to use fds or it's possible to use flash manager from mesh instead ? 

  • Hi Hung,

       I have read the guide and The bellow is what i did:

          1)set the Heap Size to 8192 bytes in project option

          2)in nrf_mesh_config_app.h file add include and define

          3)for the "optional changes"and "Flash palcement project files"part ,the code has alreadly been existed.

      I have enable FDS_ENABLED 1 in file sdk_config.h

      My purpose is to storage data  which  power on again after user's setting.

     The new Log:

     0> <t:          0>, main.c,  597, ----- BLE Mesh Dimming Server Demo -----
     0> <t:       8648>, ble_softdevice_support.c,  133, RAM Start is 0x20002DA0
     0> <t:       9257>, main.c,  570, Initializing and adding models
     0> <t:      14086>, main.c,  614, PWM max ticks: 1600
     0> <t:      14089>, main.c,  620, Status fds register is : 0
     0> <t:      14091>, main.c,  622, Initializing fds...
     0> <t:      14107>, main.c,  625, Status fds init is : 0
     0> <t:          0>, main.c,  597, ----- BLE Mesh Dimming Server Demo -----
     0> <t:       8656>, ble_softdevice_support.c,  133, RAM Start is 0x20002DA0
     0> <t:       9271>, main.c,  570, Initializing and adding models
     0> <t:      14092>, main.c,  614, PWM max ticks: 1600
     0> <t:      14095>, main.c,  620, Status fds register is : 0
     0> <t:      14097>, main.c,  622, Initializing fds...
     0> <t:      14107>, main.c,  625, Status fds init is : 0
     0> <t:          0>, main.c,  597, ----- BLE Mesh Dimming Server Demo -----
     0> <t:       8649>, ble_softdevice_support.c,  133, RAM Start is 0x20002DA0
     0> <t:       9272>, main.c,  570, Initializing and adding models
     0> <t:      14107>, main.c,  614, PWM max ticks: 1600
     0> <t:      14109>, main.c,  620, Status fds register is : 0
     0> <t:      14111>, main.c,  622, Initializing fds...
     0> <t:      14114>, main.c,  266, Event: FDS_EVT_INIT received (FDS_SUCCESS)
     0> <t:      14116>, main.c,  625, Status fds init is : 0
     0> <t:      14119>, main.c,  642, Reading flash usage statistics...
     0> <t:      14121>, main.c,  649, Found 0 valid records.
     0> <t:      14123>, main.c,  650, Found 0 dirty records (ready to be garbage collected).
     0> <t:      14127>, main.c,  686, Writing config file...
     0> <t:      14131>, main.c,  689, Write Status is : 0
     0> <t:          0>, main.c,  597, ----- BLE Mesh Dimming Server Demo -----
     0> <t:       8649>, ble_softdevice_support.c,  133, RAM Start is 0x20002DA0
     0> <t:       9237>, main.c,  570, Initializing and adding models
     0> <t:      14067>, main.c,  614, PWM max ticks: 1600
     0> <t:      14069>, main.c,  620, Status fds register is : 0
     0> <t:      14071>, main.c,  622, Initializing fds...
     0> <t:      14074>, main.c,  266, Event: FDS_EVT_INIT received (FDS_SUCCESS)
     0> <t:      14077>, main.c,  625, Status fds init is : 0
     0> <t:      14079>, main.c,  642, Reading flash usage statistics...
     0> <t:      14082>, main.c,  649, Found 0 valid records.
     0> <t:      14084>, main.c,  650, Found 1 dirty records (ready to be garbage collected).
     0> <t:      14087>, main.c,  686, Writing config file...
     0> <t:      14092>, main.c,  689, Write Status is : 0
    

    I have pressed  RESET Button four times. The process stopped after 'fds_record_write' this time.

    Could you give me some advices.Thanks.

    Best Regars,

    Panda

  • Hi Hung,

       I send you main codedimming_server_DFU.rar   ,Just extract it and place path :...\nrf5_SDK_for_Mesh_v3.2.0_src\examples\experimental_dimming .

       nRF SDK:     nRF5_SDK_15.3.0_59ac345

       mseh SDK:  nrf5_SDK_for_Mesh_v3.2.0_src 

       I used NRF_FSTORAGE_SD  fstorage (example default) .FDS_PHY_PAGES=3*1024/1024=3 (fds_internal_defs.h and sdk_config.h)

      If anything else is needed,Please tell me .Thank you for you help.

    Best Regards,

    Panda

  • Hi Panda, 

    I think we found what's wrong with the code.  You forgot to include INITIALIZE_USER_SECTIONS in the preprocessor definition. 

    Without that the section variable will not be initialized with the value defined in the section register. 

  • Hi Hung,

        I do as you said to include INITIALIZE_USER_SECTIONS , But it does not work ,the result just like before .Could you return back full project work well your side? Thanks in advance.

    Best Regards,

    Panda

       

  • Hi Panda, 

    Please find the .zip here. Make sure you trigger a reset after programming. 

    dimming_server_DFU.zip

  • Hi Hung,

      I tried just now .It sames that FDS write not ready..the log is bellow.

      RTT View:

      

     

     0> <t:          0>, main.c,  597, ----- BLE Mesh Dimming Server Demo -----
     0> <t:      12957>, ble_softdevice_support.c,  133, RAM Start is 0x20002DA0
     0> <t:      13494>, main.c,  570, Initializing and adding models
     0> <t:      18360>, main.c,  620, Status fds register is : 0
     0> <t:      18363>, main.c,  622, Initializing fds...
     0> <t:      18384>, main.c,  625, Status fds init is : 0
     0> <t:          0>, main.c,  597, ----- BLE Mesh Dimming Server Demo -----
     0> <t:       8406>, ble_softdevice_support.c,  133, RAM Start is 0x20002DA0
     0> <t:       8949>, main.c,  570, Initializing and adding models
     0> <t:      13812>, main.c,  620, Status fds register is : 0
     0> <t:      13815>, main.c,  622, Initializing fds...
     0> <t:      13831>, main.c,  625, Status fds init is : 0
     0> <t:          0>, main.c,  597, ----- BLE Mesh Dimming Server Demo -----
     0> <t:       8408>, ble_softdevice_support.c,  133, RAM Start is 0x20002DA0
     0> <t:       8941>, main.c,  570, Initializing and adding models
     0> <t:      13808>, main.c,  620, Status fds register is : 0
     0> <t:      13811>, main.c,  622, Initializing fds...
     0> <t:      13821>, main.c,  625, Status fds init is : 0
     0> <t:          0>, main.c,  597, ----- BLE Mesh Dimming Server Demo -----
     0> <t:       8408>, ble_softdevice_support.c,  133, RAM Start is 0x20002DA0
     0> <t:       8955>, main.c,  570, Initializing and adding models
     0> <t:      13810>, main.c,  620, Status fds register is : 0
     0> <t:      13812>, main.c,  622, Initializing fds...
     0> <t:      13815>, main.c,  266, Event: FDS_EVT_INIT received (FDS_SUCCESS)
     0> <t:      13818>, main.c,  625, Status fds init is : 0
     0> <t:      13820>, main.c,  642, Reading flash usage statistics...
     0> <t:      13823>, main.c,  649, Found 0 valid records.
     0> <t:      13825>, main.c,  650, Found 0 dirty records (ready to be garbage collected).
     0> <t:      13828>, main.c,  686, Writing config file...
     0> <t:      13833>, main.c,  689, Write Status is : 0
    

       I try another example using Keil5 IDE,It does work.However ,My project is based on SES ,So I have to solve it.Could you help me to find any other issues maybe without attention? Thank You. 

     Best Regards,

    Panda

Reply
  • Hi Hung,

      I tried just now .It sames that FDS write not ready..the log is bellow.

      RTT View:

      

     

     0> <t:          0>, main.c,  597, ----- BLE Mesh Dimming Server Demo -----
     0> <t:      12957>, ble_softdevice_support.c,  133, RAM Start is 0x20002DA0
     0> <t:      13494>, main.c,  570, Initializing and adding models
     0> <t:      18360>, main.c,  620, Status fds register is : 0
     0> <t:      18363>, main.c,  622, Initializing fds...
     0> <t:      18384>, main.c,  625, Status fds init is : 0
     0> <t:          0>, main.c,  597, ----- BLE Mesh Dimming Server Demo -----
     0> <t:       8406>, ble_softdevice_support.c,  133, RAM Start is 0x20002DA0
     0> <t:       8949>, main.c,  570, Initializing and adding models
     0> <t:      13812>, main.c,  620, Status fds register is : 0
     0> <t:      13815>, main.c,  622, Initializing fds...
     0> <t:      13831>, main.c,  625, Status fds init is : 0
     0> <t:          0>, main.c,  597, ----- BLE Mesh Dimming Server Demo -----
     0> <t:       8408>, ble_softdevice_support.c,  133, RAM Start is 0x20002DA0
     0> <t:       8941>, main.c,  570, Initializing and adding models
     0> <t:      13808>, main.c,  620, Status fds register is : 0
     0> <t:      13811>, main.c,  622, Initializing fds...
     0> <t:      13821>, main.c,  625, Status fds init is : 0
     0> <t:          0>, main.c,  597, ----- BLE Mesh Dimming Server Demo -----
     0> <t:       8408>, ble_softdevice_support.c,  133, RAM Start is 0x20002DA0
     0> <t:       8955>, main.c,  570, Initializing and adding models
     0> <t:      13810>, main.c,  620, Status fds register is : 0
     0> <t:      13812>, main.c,  622, Initializing fds...
     0> <t:      13815>, main.c,  266, Event: FDS_EVT_INIT received (FDS_SUCCESS)
     0> <t:      13818>, main.c,  625, Status fds init is : 0
     0> <t:      13820>, main.c,  642, Reading flash usage statistics...
     0> <t:      13823>, main.c,  649, Found 0 valid records.
     0> <t:      13825>, main.c,  650, Found 0 dirty records (ready to be garbage collected).
     0> <t:      13828>, main.c,  686, Writing config file...
     0> <t:      13833>, main.c,  689, Write Status is : 0
    

       I try another example using Keil5 IDE,It does work.However ,My project is based on SES ,So I have to solve it.Could you help me to find any other issues maybe without attention? Thank You. 

     Best Regards,

    Panda

Children
  • Hi Panda, 
    Did you test with the light_switch_dimming_server_DFU_nrf52832_xxAA_s132_6_1_1.emProject project ? 

    I suspect there could be an issue that your ses doesn't use the flash_placement.xml for section. Could you try erasing the file and check if it built ? 

    I attached the .hex file please try testing this hex. Please make sure to do an erase all (nrfjprog --eraseall) before testing

    light_switch_dimming_server_DFU_nrf52832_xxAA_s132_6.1.1.hex

  • Hi Hung,

      I Used your giving hex file to program with nrfutil tool as follow:

     Then I pressed reset button two times,The Log shows it works ok.

     0> <t:          0>, main.c,  597, ----- BLE Mesh Dimming Server Demo -----
     0> <t:      13096>, main.c,  570, Initializing and adding models
     0> <t:      17869>, main.c,  620, Status fds register is : 0
     0> <t:      17872>, main.c,  622, Initializing fds...
     0> <t:      17893>, main.c,  625, Status fds init is : 0
     0> <t:      17939>, main.c,  266, Event: FDS_EVT_INIT received (FDS_SUCCESS)
     0> <t:          0>, main.c,  597, ----- BLE Mesh Dimming Server Demo -----
     0> <t:       8743>, main.c,  570, Initializing and adding models
     0> <t:      13522>, main.c,  620, Status fds register is : 0
     0> <t:      13525>, main.c,  622, Initializing fds...
     0> <t:      13527>, main.c,  266, Event: FDS_EVT_INIT received (FDS_SUCCESS)
     0> <t:      13530>, main.c,  625, Status fds init is : 0
     0> <t:      13533>, main.c,  642, Reading flash usage statistics...
     0> <t:      13535>, main.c,  649, Found 0 valid records.
     0> <t:      13538>, main.c,  650, Found 0 dirty records (ready to be garbage collected).
     0> <t:      13541>, main.c,  686, Writing config file...
     0> <t:      13546>, main.c,  689, Write Status is : 0
     0> <t:      13611>, main.c,  266, Event: FDS_EVT_WRITE received (FDS_SUCCESS)
     0> <t:      13614>, main.c,  286, Record ID:	0x0001<t:      13616>, main.c,  287, File ID:	0xF010<t:      13618>, main.c,  288, Record key:	0x7010<t:          0>, main.c,  597, ----- BLE Mesh Dimming Server Demo -----
     0> <t:       8734>, main.c,  570, Initializing and adding models
     0> <t:      13506>, main.c,  620, Status fds register is : 0
     0> <t:      13508>, main.c,  622, Initializing fds...
     0> <t:      13511>, main.c,  266, Event: FDS_EVT_INIT received (FDS_SUCCESS)
     0> <t:      13514>, main.c,  625, Status fds init is : 0
     0> <t:      13516>, main.c,  642, Reading flash usage statistics...
     0> <t:      13519>, main.c,  649, Found 1 valid records.
     0> <t:      13521>, main.c,  650, Found 0 dirty records (ready to be garbage collected).
     0> <t:      13525>, main.c,  669, Config file found, updating boot count to 0
     0> <t:      13618>, main.c,  266, Event: FDS_EVT_UPDATE received (FDS_SUCCESS)
    
    .

       However,when I rebuild the project you return back with above method using rebuild hex and test again ,It does not work right even i change the flash_placement.xml/flash_placement1.xml .

       I check my SEGGER Embedded Studio ,the version is 3.12  .Does it matter?

      If there are anyother advises,please tell me. Thank you.

    Best Regards,

    Panda

      

      

  • Hi Hung,

        A good news,I use SES Version  4.16a to rebuild the project,then erase and program  ,It does work OK now.I think this is where the problem exist.Thanks for your help all the time.

    Best Regards,

    Panda

  • Good to hear that it works now. I'm not sure why SES v3.12 didn't work, might be that it doesn't support Section or has the flash/section configuration slightly different. 

  • Hi Hung,

         I have met FDS (FDS_ERR_OPERATION_TIMEOUT) and even not working issues. I erase all and program.First few time it works well, however when after happening  DS_ERR_OPERATION_TIMEOUT, the FDS function not work . 

         The fllowing is

     //=====================    below: OK =============================//
    0> <t:    2287078>, access.c,  942, RX opcode =[FFFF8206]
     0> <t:    2287080>, access.c,  943, msg length =[0005]
     0> <t:    2287083>, access.c,  944, msg rx: : 0A00011414
     0> <t:    2287085>, access.c,  952, element index =[0]
     0> <t:    2287088>, access.c, 1015, In coming is OK ! 
     0> <t:    2287090>, generic_level_server.c,  101, Opcode Jumper to Level handl_set !
     0> <t:    2287093>, app_level.c,  498, Level SET: Level: 10  delay: 100  tt: 2000  req-delta: 10 
     0> <t:    2287098>, access.c,  284, appkey_handle is 65535 
     0> <t:    2287100>, access.c,  285, address_handle  is 0 
     0> <t:    2287103>, access.c,  402, Source address: 9 Target Address: 4
     0> <t:    2287106>, access.c,  407, sensor msg tx: : 00000A0014
     0> <t:    2287115>, access.c,  972, is_opcode_of_model true
     0> <t:    2287117>, access.c,  983, address_match false
     0> <t:    2287119>, access.c,  988, bitfield_get true
     0> <t:    2287121>, access.c,  995, ACCESS_INTERNAL_STATE_IS_ALLOCATED true
     0> <t:    2290375>, app_level.c,  280, Selecting interval for one step change
     0> <t:    2290378>, app_level.c,  284, timeout_rtc_ticks: 6554 ticks
     0> <t:    2296935>, app_level.c,  303, delta= 10
     0> <t:    2296937>, app_level.c,  313, One Level cb happen !
     0> <t:    2296939>, app_level.c,  314, Present Level: 0
     0> <t:    2296942>, app_level.c,  316, ELAPSED_TIME: 0 ,Transition Time: 0
     0> <t:    2296945>, main.c,  268, m_pwm0_present_level is:     0
     0> <t:    2296947>, main.c,  291, Pwm value:    0
     0> <t:    2303504>, app_level.c,  303, delta= 10
     0> <t:    2303506>, app_level.c,  313, One Level cb happen !
     0> <t:    2303508>, app_level.c,  314, Present Level: 1
     0> <t:    2303511>, app_level.c,  316, ELAPSED_TIME: 1 ,Transition Time: 200
     0> <t:    2303514>, main.c,  268, m_pwm0_present_level is:     1
     0> <t:    2303517>, main.c,  291, Pwm value:  100
     0> <t:    2310073>, app_level.c,  303, delta= 10
     0> <t:    2310075>, app_level.c,  313, One Level cb happen !
     0> <t:    2310077>, app_level.c,  314, Present Level: 2
     0> <t:    2310080>, app_level.c,  316, ELAPSED_TIME: 2 ,Transition Time: 400
     0> <t:    2310083>, main.c,  268, m_pwm0_present_level is:     2
     0> <t:    2310086>, main.c,  291, Pwm value:  200
     0> <t:    2316642>, app_level.c,  303, delta= 10
     0> <t:    2316644>, app_level.c,  313, One Level cb happen !
     0> <t:    2316646>, app_level.c,  314, Present Level: 3
     0> <t:    2316649>, app_level.c,  316, ELAPSED_TIME: 3 ,Transition Time: 601
     0> <t:    2316652>, main.c,  268, m_pwm0_present_level is:     3
     0> <t:    2316655>, main.c,  291, Pwm value:  300
     0> <t:    2323211>, app_level.c,  303, delta= 10
     0> <t:    2323214>, app_level.c,  313, One Level cb happen !
     0> <t:    2323216>, app_level.c,  314, Present Level: 4
     0> <t:    2323218>, app_level.c,  316, ELAPSED_TIME: 4 ,Transition Time: 801
     0> <t:    2323221>, main.c,  268, m_pwm0_present_level is:     4
     0> <t:    2323224>, main.c,  291, Pwm value:  400
     0> <t:    2329781>, app_level.c,  303, delta= 10
     0> <t:    2329783>, app_level.c,  313, One Level cb happen !
     0> <t:    2329785>, app_level.c,  314, Present Level: 5
     0> <t:    2329788>, app_level.c,  316, ELAPSED_TIME: 5 ,Transition Time: 1002
     0> <t:    2329791>, main.c,  268, m_pwm0_present_level is:     5
     0> <t:    2329794>, main.c,  291, Pwm value:  500
     0> <t:    2336350>, app_level.c,  303, delta= 10
     0> <t:    2336352>, app_level.c,  313, One Level cb happen !
     0> <t:    2336355>, app_level.c,  314, Present Level: 6
     0> <t:    2336357>, app_level.c,  316, ELAPSED_TIME: 6 ,Transition Time: 1202
     0> <t:    2336360>, main.c,  268, m_pwm0_present_level is:     6
     0> <t:    2336363>, main.c,  291, Pwm value:  600
     0> <t:    2342919>, app_level.c,  303, delta= 10
     0> <t:    2342921>, app_level.c,  313, One Level cb happen !
     0> <t:    2342923>, app_level.c,  314, Present Level: 7
     0> <t:    2342926>, app_level.c,  316, ELAPSED_TIME: 7 ,Transition Time: 1403
     0> <t:    2342929>, main.c,  268, m_pwm0_present_level is:     7
     0> <t:    2342932>, main.c,  291, Pwm value:  700
     0> <t:    2349488>, app_level.c,  303, delta= 10
     0> <t:    2349490>, app_level.c,  313, One Level cb happen !
     0> <t:    2349493>, app_level.c,  314, Present Level: 8
     0> <t:    2349495>, app_level.c,  316, ELAPSED_TIME: 8 ,Transition Time: 1603
     0> <t:    2349498>, main.c,  268, m_pwm0_present_level is:     8
     0> <t:    2349501>, main.c,  291, Pwm value:  800
     0> <t:    2356057>, app_level.c,  303, delta= 10
     0> <t:    2356059>, app_level.c,  313, One Level cb happen !
     0> <t:    2356061>, app_level.c,  314, Present Level: 9
     0> <t:    2356064>, app_level.c,  316, ELAPSED_TIME: 9 ,Transition Time: 1804
     0> <t:    2356067>, main.c,  268, m_pwm0_present_level is:     9
     0> <t:    2356070>, main.c,  291, Pwm value:  900
     0> <t:    2362626>, access.c,  284, appkey_handle is 65535 
     0> <t:    2362629>, access.c,  285, address_handle  is 0 
     0> <t:    2362631>, main.c,  268, m_pwm0_present_level is:    10
     0> <t:    2362634>, main.c,  291, Pwm value: 1000
     0> <t:    2362636>, app_level.c,  337, Level_transition_complete:    10
     0> <t:    2362639>, app_level.c,  340, pwm_value is 10 ,Flag is 1
     0> <t:    2362642>, user.c,  586, Is Coming to FDS!
     0> <t:    2362644>, user.c,  591, Element 0, value is 10!
     0> <t:    2362647>, user.c,  428, delete_next: 1,pending_flag:0.
     0> <t:    2362649>, user.c,  433, Deleting next record.
     0> <t:    2362654>, user.c,  613, FDS Data is Writting ...
     0> <t:    2365909>, user.c,  332, Event: FDS_EVT_DEL_RECORD received (FDS_SUCCESS)
     0> <t:    2365912>, user.c,  371, Record ID:	0x0011
     0> <t:    2365914>, user.c,  372, File ID:	0xF010
     0> <t:    2365916>, user.c,  373, Record key:	0x7010
     0> <t:    2366550>, user.c,  332, Event: FDS_EVT_WRITE received (FDS_SUCCESS)
     0> <t:    2366553>, user.c,  348, Record ID:	0x0012
     0> <t:    2366555>, user.c,  349, File ID:	0xF010
     0> <t:    2366557>, user.c,  350, Record key:	0x7010
    
    //================below:  (FDS_ERR_OPERATION_TIMEOUT)=================//
     0> <t:    5019568>, access.c,  942, RX opcode =[FFFF8206]
     0> <t:    5019570>, access.c,  943, msg length =[0005]
     0> <t:    5019573>, access.c,  944, msg rx: : 0000021414
     0> <t:    5019575>, access.c,  952, element index =[0]
     0> <t:    5019577>, access.c, 1015, In coming is OK ! 
     0> <t:    5019580>, generic_level_server.c,  101, Opcode Jumper to Level handl_set !
     0> <t:    5019583>, app_level.c,  498, Level SET: Level: 0  delay: 100  tt: 2000  req-delta: -10 
     0> <t:    5019588>, access.c,  284, appkey_handle is 65535 
     0> <t:    5019590>, access.c,  285, address_handle  is 0 
     0> <t:    5019593>, access.c,  402, Source address: 9 Target Address: 4
     0> <t:    5019596>, access.c,  407, sensor msg tx: : 0A00000014
     0> <t:    5019605>, access.c,  972, is_opcode_of_model true
     0> <t:    5019607>, access.c,  983, address_match false
     0> <t:    5019609>, access.c,  988, bitfield_get true
     0> <t:    5019611>, access.c,  995, ACCESS_INTERNAL_STATE_IS_ALLOCATED true
     0> <t:    5020808>, access.c,  284, appkey_handle is 65535 
     0> <t:    5020810>, access.c,  285, address_handle  is 65535 
     0> <t:    5022865>, app_level.c,  280, Selecting interval for one step change
     0> <t:    5022868>, app_level.c,  284, timeout_rtc_ticks: 6554 ticks
     0> <t:    5029425>, app_level.c,  303, delta= -10
     0> <t:    5029427>, app_level.c,  313, One Level cb happen !
     0> <t:    5029429>, app_level.c,  314, Present Level: 10
     0> <t:    5029432>, app_level.c,  316, ELAPSED_TIME: 10 ,Transition Time: 0
     0> <t:    5029435>, main.c,  268, m_pwm0_present_level is:    10
     0> <t:    5029437>, main.c,  291, Pwm value: 1000
     0> <t:    5035994>, app_level.c,  303, delta= -10
     0> <t:    5035996>, app_level.c,  313, One Level cb happen !
     0> <t:    5035999>, app_level.c,  314, Present Level: 9
     0> <t:    5036001>, app_level.c,  316, ELAPSED_TIME: 9 ,Transition Time: 200
     0> <t:    5036004>, main.c,  268, m_pwm0_present_level is:     9
     0> <t:    5036007>, main.c,  291, Pwm value:  900
     0> <t:    5042563>, app_level.c,  303, delta= -10
     0> <t:    5042565>, app_level.c,  313, One Level cb happen !
     0> <t:    5042568>, app_level.c,  314, Present Level: 8
     0> <t:    5042570>, app_level.c,  316, ELAPSED_TIME: 8 ,Transition Time: 400
     0> <t:    5042573>, main.c,  268, m_pwm0_present_level is:     8
     0> <t:    5042576>, main.c,  291, Pwm value:  800
     0> <t:    5049132>, app_level.c,  303, delta= -10
     0> <t:    5049134>, app_level.c,  313, One Level cb happen !
     0> <t:    5049136>, app_level.c,  314, Present Level: 7
     0> <t:    5049139>, app_level.c,  316, ELAPSED_TIME: 7 ,Transition Time: 601
     0> <t:    5049142>, main.c,  268, m_pwm0_present_level is:     7
     0> <t:    5049145>, main.c,  291, Pwm value:  700
     0> <t:    5055701>, app_level.c,  303, delta= -10
     0> <t:    5055703>, app_level.c,  313, One Level cb happen !
     0> <t:    5055705>, app_level.c,  314, Present Level: 6
     0> <t:    5055708>, app_level.c,  316, ELAPSED_TIME: 6 ,Transition Time: 801
     0> <t:    5055711>, main.c,  268, m_pwm0_present_level is:     6
     0> <t:    5055714>, main.c,  291, Pwm value:  600
     0> <t:    5062271>, app_level.c,  303, delta= -10
     0> <t:    5062273>, app_level.c,  313, One Level cb happen !
     0> <t:    5062276>, app_level.c,  314, Present Level: 5
     0> <t:    5062278>, app_level.c,  316, ELAPSED_TIME: 5 ,Transition Time: 1002
     0> <t:    5062281>, main.c,  268, m_pwm0_present_level is:     5
     0> <t:    5062284>, main.c,  291, Pwm value:  500
     0> <t:    5068840>, app_level.c,  303, delta= -10
     0> <t:    5068842>, app_level.c,  313, One Level cb happen !
     0> <t:    5068844>, app_level.c,  314, Present Level: 4
     0> <t:    5068847>, app_level.c,  316, ELAPSED_TIME: 4 ,Transition Time: 1202
     0> <t:    5068850>, main.c,  268, m_pwm0_present_level is:     4
     0> <t:    5068853>, main.c,  291, Pwm value:  400
     0> <t:    5075409>, app_level.c,  303, delta= -10
     0> <t:    5075411>, app_level.c,  313, One Level cb happen !
     0> <t:    5075414>, app_level.c,  314, Present Level: 3
     0> <t:    5075416>, app_level.c,  316, ELAPSED_TIME: 3 ,Transition Time: 1403
     0> <t:    5075419>, main.c,  268, m_pwm0_present_level is:     3
     0> <t:    5075422>, main.c,  291, Pwm value:  300
     0> <t:    5081978>, app_level.c,  303, delta= -10
     0> <t:    5081980>, app_level.c,  313, One Level cb happen !
     0> <t:    5081982>, app_level.c,  314, Present Level: 2
     0> <t:    5081985>, app_level.c,  316, ELAPSED_TIME: 2 ,Transition Time: 1603
     0> <t:    5081989>, main.c,  268, m_pwm0_present_level is:     2
     0> <t:    5081991>, main.c,  291, Pwm value:  200
     0> <t:    5088548>, app_level.c,  303, delta= -10
     0> <t:    5088550>, app_level.c,  313, One Level cb happen !
     0> <t:    5088553>, app_level.c,  314, Present Level: 1
     0> <t:    5088555>, app_level.c,  316, ELAPSED_TIME: 1 ,Transition Time: 1804
     0> <t:    5088558>, main.c,  268, m_pwm0_present_level is:     1
     0> <t:    5088561>, main.c,  291, Pwm value:  100
     0> <t:    5095117>, access.c,  284, appkey_handle is 65535 
     0> <t:    5095120>, access.c,  285, address_handle  is 0 
     0> <t:    5095122>, main.c,  268, m_pwm0_present_level is:     0
     0> <t:    5095125>, main.c,  291, Pwm value:    0
     0> <t:    5095127>, app_level.c,  337, Level_transition_complete:     0
     0> <t:    5095130>, app_level.c,  340, pwm_value is 0 ,Flag is 1
     0> <t:    5095133>, user.c,  586, Is Coming to FDS!
     0> <t:    5095135>, user.c,  591, Element 0, value is 0!
     0> <t:    5095138>, user.c,  428, delete_next: 1,pending_flag:0.
     0> <t:    5095141>, user.c,  433, Deleting next record.
     0> <t:    5095179>, user.c,  332, Event: FDS_EVT_DEL_RECORD received (FDS_ERR_OPERATION_TIMEOUT)
     0> <t:    5095220>, user.c,  332, Event: FDS_EVT_WRITE received (FDS_ERR_OPERATION_TIMEOUT)
     0> <t:    5095224>, user.c,  613, FDS Data is Writting ...
    //=================== bellow : No working================================//
     0> <t:    6268450>, access.c,  942, RX opcode =[FFFF8206]
     0> <t:    6268453>, access.c,  943, msg length =[0005]
     0> <t:    6268455>, access.c,  944, msg rx: : 0A00041414
     0> <t:    6268458>, access.c,  952, element index =[0]
     0> <t:    6268460>, access.c, 1015, In coming is OK ! 
     0> <t:    6268463>, generic_level_server.c,  101, Opcode Jumper to Level handl_set !
     0> <t:    6268466>, app_level.c,  498, Level SET: Level: 10  delay: 100  tt: 2000  req-delta: 10 
     0> <t:    6268471>, access.c,  284, appkey_handle is 65535 
     0> <t:    6268473>, access.c,  285, address_handle  is 0 
     0> <t:    6268476>, access.c,  402, Source address: 9 Target Address: 4
     0> <t:    6268479>, access.c,  407, sensor msg tx: : 00000A0014
     0> <t:    6268488>, access.c,  972, is_opcode_of_model true
     0> <t:    6268490>, access.c,  983, address_match false
     0> <t:    6268492>, access.c,  988, bitfield_get true
     0> <t:    6268494>, access.c,  995, ACCESS_INTERNAL_STATE_IS_ALLOCATED true
     0> <t:    6271747>, app_level.c,  280, Selecting interval for one step change
     0> <t:    6271750>, app_level.c,  284, timeout_rtc_ticks: 6554 ticks
     0> <t:    6278307>, app_level.c,  303, delta= 10
     0> <t:    6278309>, app_level.c,  313, One Level cb happen !
     0> <t:    6278312>, app_level.c,  314, Present Level: 0
     0> <t:    6278314>, app_level.c,  316, ELAPSED_TIME: 0 ,Transition Time: 0
     0> <t:    6278317>, main.c,  268, m_pwm0_present_level is:     0
     0> <t:    6278319>, main.c,  291, Pwm value:    0
     0> <t:    6284876>, app_level.c,  303, delta= 10
     0> <t:    6284878>, app_level.c,  313, One Level cb happen !
     0> <t:    6284881>, app_level.c,  314, Present Level: 1
     0> <t:    6284883>, app_level.c,  316, ELAPSED_TIME: 1 ,Transition Time: 200
     0> <t:    6284886>, main.c,  268, m_pwm0_present_level is:     1
     0> <t:    6284889>, main.c,  291, Pwm value:  100
     0> <t:    6291445>, app_level.c,  303, delta= 10
     0> <t:    6291447>, app_level.c,  313, One Level cb happen !
     0> <t:    6291450>, app_level.c,  314, Present Level: 2
     0> <t:    6291452>, app_level.c,  316, ELAPSED_TIME: 2 ,Transition Time: 400
     0> <t:    6291455>, main.c,  268, m_pwm0_present_level is:     2
     0> <t:    6291458>, main.c,  291, Pwm value:  200
     0> <t:    6298014>, app_level.c,  303, delta= 10
     0> <t:    6298016>, app_level.c,  313, One Level cb happen !
     0> <t:    6298019>, app_level.c,  314, Present Level: 3
     0> <t:    6298021>, app_level.c,  316, ELAPSED_TIME: 3 ,Transition Time: 601
     0> <t:    6298024>, main.c,  268, m_pwm0_present_level is:     3
     0> <t:    6298027>, main.c,  291, Pwm value:  300
     0> <t:    6304583>, app_level.c,  303, delta= 10
     0> <t:    6304585>, app_level.c,  313, One Level cb happen !
     0> <t:    6304588>, app_level.c,  314, Present Level: 4
     0> <t:    6304590>, app_level.c,  316, ELAPSED_TIME: 4 ,Transition Time: 801
     0> <t:    6304593>, main.c,  268, m_pwm0_present_level is:     4
     0> <t:    6304596>, main.c,  291, Pwm value:  400
     0> <t:    6311152>, app_level.c,  303, delta= 10
     0> <t:    6311154>, app_level.c,  313, One Level cb happen !
     0> <t:    6311157>, app_level.c,  314, Present Level: 5
     0> <t:    6311159>, app_level.c,  316, ELAPSED_TIME: 5 ,Transition Time: 1002
     0> <t:    6311162>, main.c,  268, m_pwm0_present_level is:     5
     0> <t:    6311165>, main.c,  291, Pwm value:  500
     0> <t:    6317721>, app_level.c,  303, delta= 10
     0> <t:    6317723>, app_level.c,  313, One Level cb happen !
     0> <t:    6317725>, app_level.c,  314, Present Level: 6
     0> <t:    6317728>, app_level.c,  316, ELAPSED_TIME: 6 ,Transition Time: 1202
     0> <t:    6317731>, main.c,  268, m_pwm0_present_level is:     6
     0> <t:    6317734>, main.c,  291, Pwm value:  600
     0> <t:    6324290>, app_level.c,  303, delta= 10
     0> <t:    6324292>, app_level.c,  313, One Level cb happen !
     0> <t:    6324295>, app_level.c,  314, Present Level: 7
     0> <t:    6324297>, app_level.c,  316, ELAPSED_TIME: 7 ,Transition Time: 1403
     0> <t:    6324300>, main.c,  268, m_pwm0_present_level is:     7
     0> <t:    6324303>, main.c,  291, Pwm value:  700
     0> <t:    6330860>, app_level.c,  303, delta= 10
     0> <t:    6330862>, app_level.c,  313, One Level cb happen !
     0> <t:    6330864>, app_level.c,  314, Present Level: 8
     0> <t:    6330867>, app_level.c,  316, ELAPSED_TIME: 8 ,Transition Time: 1603
     0> <t:    6330870>, main.c,  268, m_pwm0_present_level is:     8
     0> <t:    6330873>, main.c,  291, Pwm value:  800
     0> <t:    6331528>, access.c,  284, appkey_handle is 65535 
     0> <t:    6331531>, access.c,  285, address_handle  is 65535 
     0> <t:    6337429>, app_level.c,  303, delta= 10
     0> <t:    6337431>, app_level.c,  313, One Level cb happen !
     0> <t:    6337434>, app_level.c,  314, Present Level: 9
     0> <t:    6337436>, app_level.c,  316, ELAPSED_TIME: 9 ,Transition Time: 1804
     0> <t:    6337439>, main.c,  268, m_pwm0_present_level is:     9
     0> <t:    6337442>, main.c,  291, Pwm value:  900
     0> <t:    6343998>, access.c,  284, appkey_handle is 65535 
     0> <t:    6344001>, access.c,  285, address_handle  is 0 
     0> <t:    6344003>, main.c,  268, m_pwm0_present_level is:    10
     0> <t:    6344006>, main.c,  291, Pwm value: 1000
     0> <t:    6344008>, app_level.c,  337, Level_transition_complete:    10
     0> <t:    6344011>, app_level.c,  340, pwm_value is 10 ,Flag is 1
     0> <t:    6986888>, access.c,  284, appkey_handle is 65535 
     0> <t:    6986890>, access.c,  285, address_handle  is 65535 
    //=======================bellow  BUTTON RESET =======================//
    
     0> <t:       5335>, user.c,  491, ---FDS example started .---
     0> <t:       5337>, user.c,  496, Initializing fds...
     0> <t:       5340>, user.c,  332, Event: FDS_EVT_INIT received (FDS_SUCCESS)
     0> <t:       5343>, user.c,  509, Found 1 valid records.
     0> <t:       5345>, user.c,  510, Found 1 dirty records (ready to be garbage collected).
     0> <t:       5348>, user.c,  528, PWM Value is 10 and 40 
     0> <t:       5351>, user.c,  542, Config file found, updating boot count to 13.
    

        A part Code:

    static void initialize(void)
    {
    ...
    fds_test();
    }
    int main(void)
    {
      initialize();
      ...
      for (;;)
      {
            fds_data();
            (void)sd_app_evt_wait();
      }
    }
    void fds_data(void)
    {
        //app_level_server_t * p_server;
       // __LOG(LOG_SRC_APP, LOG_LEVEL_INFO,"Waking !\n");
        if(fds_flag==true)
        {
            __LOG(LOG_SRC_APP, LOG_LEVEL_INFO,"Is Coming to FDS!\n");
            fds_flag=false;
            if(element_number==0)
            {
                m_dummy_cfg.pwm_value[0]=pwm_value;//p_server->state.present_level;
              __LOG(LOG_SRC_APP, LOG_LEVEL_INFO,"Element 0, value is %d!\n",m_dummy_cfg.pwm_value[0]);
            }
            else if(element_number==1)
            {
                m_dummy_cfg.pwm_value[1]=pwm_value;//p_server->state.present_level;
                __LOG(LOG_SRC_APP, LOG_LEVEL_INFO,"Element 1, value is %d!\n",m_dummy_cfg.pwm_value[1]);
            }
        
            fds_record_desc_t desc = {0};  
            fds_find_token_t  tok  = {0};
            ret_code_t rc = fds_record_find(CONFIG_FILE, CONFIG_REC_KEY, &desc, &tok); 
            if (rc == FDS_SUCCESS)
            {
              m_fds_deleted=false;
              delete_all_begin();
              delete_all_process();
             // wait_for_fds_delete();
            }
            m_fds_write=false;
            rc = fds_record_write(&desc, &m_dummy_record);
            if(rc==FDS_SUCCESS)
            {
              __LOG(LOG_SRC_APP, LOG_LEVEL_INFO,"FDS Data is Writting ...\n");
            }
            APP_ERROR_CHECK(rc);
            wait_for_fds_write();
          
             (void) sd_app_evt_wait();
        }
    }
    void fds_test(void)   //int main(void)
    {
        ret_code_t rc;
    
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "---FDS example started .---\n");
        /* Register first to receive an event when initialization is complete. */
        (void) fds_register(fds_evt_handler);
    
        
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Initializing fds...\n");
    
        rc = fds_init();
        APP_ERROR_CHECK(rc);
    
        /* Wait for fds to initialize. */
        wait_for_fds_ready();
    
        fds_stat_t stat = {0};
    
        rc = fds_stat(&stat);
        APP_ERROR_CHECK(rc);
    
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO,"Found %d valid records.\n", stat.valid_records);
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO,"Found %d dirty records (ready to be garbage collected).\n", stat.dirty_records);
    
        fds_record_desc_t desc = {0};  //用来操作记录的描述符结构清零
        fds_find_token_t  tok  = {0};  //保存秘钥的令牌清零
    
        rc = fds_record_find(CONFIG_FILE, CONFIG_REC_KEY, &desc, &tok);
    
        if (rc == FDS_SUCCESS)
        {
            /* A config file is in flash. Let's update it. */
            fds_flash_record_t config = {0};
    
            /* Open the record and read its contents. */
            rc = fds_record_open(&desc, &config);
            APP_ERROR_CHECK(rc);
    
            /* Copy the configuration from flash into m_dummy_cfg. */
            memcpy(&m_dummy_cfg, config.p_data, sizeof(configuration_t));
            __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "PWM Value is %d and %d \r\n", m_dummy_cfg.pwm_value[0], m_dummy_cfg.pwm_value[1]);
            //add 
            #if 0
    	uint32_t *data;
            __LOG(LOG_SRC_APP, LOG_LEVEL_INFO,"Data = ");
    	data = (uint32_t *)config.p_data;
    	for (uint16_t i=0;i<config.p_header->length_words;i++)
    	{
                    __LOG(LOG_SRC_APP, LOG_LEVEL_INFO,"0x%8x ",data[i]);
    
            }
            __LOG(LOG_SRC_APP, LOG_LEVEL_INFO,"\r\n");
            #endif
    
            __LOG(LOG_SRC_APP, LOG_LEVEL_INFO,"Config file found, updating boot count to %d.\n", m_dummy_cfg.boot_count);
    
            /* Update boot count. */
            m_dummy_cfg.boot_count++;
    
            /* Close the record when done reading. */
            rc = fds_record_close(&desc);
            APP_ERROR_CHECK(rc);
    
            /* Write the updated record to flash. */
            rc = fds_record_update(&desc, &m_dummy_record);
            APP_ERROR_CHECK(rc);
            if(stat.dirty_records>=3)
            {
              m_fds_gc=false;
              rc=fds_gc();
              APP_ERROR_CHECK(rc);
               wait_for_fds_gc();
            }
        }
        else
        {
            /* System config not found; write a new one. */
            __LOG(LOG_SRC_APP, LOG_LEVEL_INFO,"Writing config file...\n");
    
            m_dummy_cfg.pwm_value[0]=50;
            m_dummy_cfg.pwm_value[1]=40;
            m_fds_write=false;
            rc = fds_record_write(&desc, &m_dummy_record);
            APP_ERROR_CHECK(rc);
            wait_for_fds_write();
        }
    }

       The include file is here: include.rar

        Could you give me some help to slove this issue?Thank you.

    Best Regards,

    Panda.

Related