0

fds in sdk14

Stifler86 gravatar image

asked 2017-09-13 15:37:20 +0200

updated 2017-09-13 15:37:52 +0200

I'm trying to migrate my old app based on buttonless app sdk13 to buttonless app sdk14. I solved issuie according to migrate guide remove chunk things and etc. My app works well until I add fds_init function in my main.c file.
Here's my fds_test_init function

ret_code_t fds_test_init (void)
{

        ret_code_t ret = fds_register(fds_evt_handler);
        if (ret != FDS_SUCCESS)
        {
                    return ret;
        }
        ret = fds_init();
        if (ret != FDS_SUCCESS)
        {
                return ret;
        }
        return NRF_SUCCESS;
        }

After I comment calling of that function in my main.c the app starts work. After comment again not working. I see nothing in RTT terminal

The same code works well with sdk13

edit retag flag offensive close delete report spam

Comments

What is your error code?

RichieJH ( 2017-09-13 17:02:03 +0200 )editconvert to answer

Actually I didn't get any info in neither RTT terminal nor uart terminal. Do you mean error code that returned by APP_ERROR_CHECK ?

Stas ( 2017-09-13 17:51:31 +0200 )editconvert to answer

No, the error code returned by "ret". APP_ERROR_CHECK just enables a loop for debugging.

RichieJH ( 2017-09-13 18:51:00 +0200 )editconvert to answer

Where I can find this code?

Stas ( 2017-09-13 19:01:54 +0200 )editconvert to answer

It's in ret, it's a number.

RichieJH ( 2017-09-13 21:07:41 +0200 )editconvert to answer

I've tried to get ret_code using function SEGGER_RTT_printf(0, "%d", ret_code); but I get nothing in terminal if use fds_init function even if I to write any message before calling fds_init. Also I've tried to get err_code via debugging (keil), I set breakpoint next to ret_code_t ret = fds_register(fds_evt_handler); but in watch window most of the time err_code's value <not in scope>. screen is there any guide how to get ret_code?

Stas ( 2017-09-14 04:22:06 +0200 )editconvert to answer

I forgat to change optimization level of debugging to level 0. So now I can see that ret either returned by fds_register or fds_init functions is 0.

Stas ( 2017-09-14 05:58:24 +0200 )editconvert to answer

If it's returning 0 that means success, so this is not where your issue is. Be sure to fully erase the chip when re-programming since old FDS data is maintained and can cause issues if you changing your FDS implementation.

RichieJH ( 2017-09-14 07:58:46 +0200 )editconvert to answer

Yes. I do all the time by that way (eraseall, program softdevice, program app). There were not any problems with sdk13, but now... There's main function

int main(void)
{
    bool erase_bonds;
        uint32_t err_code;
    // Initialize.
    log_init();
        SEGGER_RTT_printf(0, "start app\n\r");

        m_clock_timer_init();
        pwm_init_corr();
        pwm_init_rgb();

        HX711_init();

        err_code = fds_test_init();
        APP_ERROR_CHECK(err_code);


    //fds_init_values();
    //fds_get_init_data();
        //test_expired();
        //fds_clear();  
    //  rgb_set(50, 50, 50, 3, 1500);
    timers_init();
    power_management_init();
    buttons_leds_init(&erase_bonds);
    ble_stack_init();
    peer_manager_init();
    gap_params_init();
    gatt_init();
    advertising_init();
    services_init();
    conn_params_init();

    //NRF_LOG_INFO("Start scale driver app\n");

    // Start execution.
    application_timers_start();
    advertising_start(erase_bonds);

    // Enter main loop.
    for (;;)
    {
        if (NRF_LOG_PROCESS() == false)
        {
            nrf_pwr_mgmt_run();
        }
    }
}

If I comment these raws:

//err_code = fds_test_init();
    //      APP_ERROR_CHECK(err_code);

app starts work

Stas ( 2017-09-14 08:40:01 +0200 )editconvert to answer

Check your fds_evt_handler for error codes for "FDS_EVT_INIT".

RichieJH ( 2017-09-14 08:48:03 +0200 )editconvert to answer

As I understand program doesn't return any fds event handler because I try to set breakpoints on different raws inside fds_evt_handler function but the program doesn't stop there. Also I've tried to add SEGGER function for detecting no works too.

void fds_evt_handler(fds_evt_t const * const p_fds_evt)
{
    switch (p_fds_evt->id)
    {
            SEGGER_RTT_printf(0, "handler\n\r");
        case FDS_EVT_INIT:
            if (p_fds_evt->result != FDS_SUCCESS)
            {
                             SEGGER_RTT_printf(0, "failed\n\r");
                // Initialization failed.
            }
            break;
                case FDS_EVT_WRITE:
                        if (p_fds_evt->result == FDS_SUCCESS)
                        {
                            write_flag=1;
                        }
                        break;

                case FDS_EVT_DEL_RECORD:
                        if (p_fds_evt->result == FDS_SUCCESS)
                        {
                            delete_flag=1;
                        //  SEGGER_RTT_printf(0, "del\n\r");
                        }
                        break;
        default:
            break;
    }
}
Stas ( 2017-09-14 09:00:44 +0200 )editconvert to answer

It does send an fds_evt_handler for all asynchronous calls (init, write, delete, update, gc). Check 1. You have registered your fds_evt_handler properly 2. Your sys_evt_handler looks like this :

 static void sys_evt_dispatch(uint32_t sys_evt) {
  fs_sys_event_handler(sys_evt);
  ble_advertising_on_sys_evt(sys_evt);
}

3. Your return is 0 for the actual init call and 4. Your p_fds_evt->result is 0 on the call back

RichieJH ( 2017-09-14 09:12:46 +0200 )editconvert to answer
  1. I don't know what does it means "register properly". I do it like in example code on infocenter of nordic. As I think there are not any changes in this part between sdk13 and sdk14.
  2. I can't find this function. But I guess it's the same as should be, because I've changed nothing in component folder files.
  3. After I step through raw ret = fds_init(); the ret is 0 in watch window while debugging.
  4. I can't check this value because my program as I think doen't go into fds_evt_handler
Stas ( 2017-09-14 09:36:21 +0200 )editconvert to answer

Could you try following this debug guide, to see if any other functions are returning non-zero error codes?

Jørgen Holmefjord ( 2017-09-14 12:40:18 +0200 )editconvert to answer

I tried but get nothing. I noticed one new thing... If I do double program it works (with second attempts), so if I erase, program sd, program app, program app again it works.

Stas ( 2017-09-14 14:42:08 +0200 )editconvert to answer

I've just simplified an example. I take ble_app_uart example in sdk14, and add just two functions from infocenter example

static void fds_evt_handler(fds_evt_t const * p_fds_evt)
{
    switch (p_fds_evt->id)
    {
        case FDS_EVT_INIT:
            if (p_fds_evt->result != FDS_SUCCESS)
            {
                // Initialization failed.
            }
            break;
        default:
            break;
    }
}

ret_code_t fds_test_init (void)
{
        ret_code_t ret = fds_register(fds_evt_handler);
        if (ret != FDS_SUCCESS)
        {
                    return ret;
        }
        ret = fds_init();
        if (ret != FDS_SUCCESS)
        {
                return ret;
        }

        return NRF_SUCCESS;

}

in main function I call fds_test_init and again app stops working.

Stas ( 2017-09-14 15:47:29 +0200 )editconvert to answer

Please try someone do the same way

Stas ( 2017-09-14 16:56:49 +0200 )editconvert to answer

Thanks now I get rid of this issue, but after add fds_record_write function I get fatal_error, check ret's value via debug it's 2. Can't find what does it means.

Stas ( 2017-09-15 11:22:06 +0200 )editconvert to answer

The error codes are described here. Error code 2 should mean FDS_ERR_NOT_INITIALIZED - Error. The module has not been initialized. Are you getting the FDS_EVT_INIT event before you are calling fds_record_write?

Jørgen Holmefjord ( 2017-09-15 11:28:51 +0200 )editconvert to answer

Now it works. I added init flag:

   case FDS_EVT_INIT:
            if (p_fds_evt->result != FDS_SUCCESS)
            {
                // Initialization failed.
            }
                        init_flag = 1;
            break;

and before calling fds_write_value wait of flag change

while(init_flag == 0);

Thanks. In my code in SDK13 I shouldn't do it and in example on github too. Probably some new changes in sdk14

Stas ( 2017-09-16 05:32:52 +0200 )editconvert to answer

1 answer

Sort by » oldest newest most voted
1
joh2 gravatar image

answered 2017-09-15 09:20:04 +0200

updated 2017-09-17 19:45:09 +0200

Notice the note in the FDS documentation saying "Before initializing FDS, you must initialize the SoftDevice and register a callback handler to handle FDS events". In your main-function, you are calling fds_test_init() before ble_stack_init(). This will lead to a hardfault, as the softdevice calls used in fstorage backend nrf_fstorage_sd is not yet available.

edit flag offensive delete publish link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer. Do not ask a new question or reply to an answer here.

[hide preview]

User menu

    or sign up

Recent questions

Question Tools

1 follower

Stats

Asked: 2017-09-13 15:37:20 +0200

Seen: 94 times

Last updated: Sep 13