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

SOFTDEVICE_HANDLER_APPSH_INIT + pstorage

ble_senso4s_v_0_7_poenostavljena4_1 power_manager.rarHi

I read a lot about p_storage library and I tested it and works great if I use SOFTDEVICE_HANDLER_INIT(NRF_CLOCK_LFCLKSRC_XTAL_20_PPM, NULL). On the other hand, If SOFTDEVICE_HANDLER_APPSH_INIT function is used for starting softdevice then the program stucks in while loop where the power_manage() function is located. I will be appreciated for any kind of information why this event happened and what is the reason for this.

best regards

Mike

  • This looks very similar to this:

    devzone.nordicsemi.com/.../

    and this:

    devzone.nordicsemi.com/.../

    It seems like you are starting the pstorage operation from within an interrupt context (app_timer) and then wait in a while loop in that very same interrupt for another interrupt to happen (example_cb_handler). But example_cb_handler() never gets called and your flag never gets set.

    Do you even need the while loop in your timer handler?

  • I agree with your conclusion if I use app_timer without a scheduler. If you will look carefully at my code you will see that app_timer uses a scheduler and thus app_timer is not executed in interrupt context. If I know correctly the problem with interrupt context can arise only if the app_timer does not use a scheduler. The attached code is the simplified version of the original code in which the pstorage functions are called a few times. Due to this fact, it is good to track a flag.

  • Hi,

    I have looked closer at your code and you are right of course. The timers are run from main context since you are using a scheduler. However, several places in your code you have these lines of code:

    while(pstorage_wait_flag)
    {
        power_manage();	
    }
    

    And I think you are suspicious about this yourself since at one point you have this comment

    // if power_manage() function is replaced by  app_sched_execute() then the program passes the timer 
    

    This is probably the core of the matter. These while loops effectively act as deadlocks because you are waiting for an event that sets pstorage_wait_flag to false, but you never allow the scheduler to process the event. In other words, the system might trigger an interrupt when your flash operation is completed, but unless you call app_sched_execute() the event is never processed and the flag never cleared.

    What you can try to do is to add app_sched_execute() to your while loops like this:

    while(pstorage_wait_flag)
    {
        app_sched_execute();
        power_manage();	
    }
    
Related