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

NRF_ERROR_NO_MEM in app_timer timeout handler

Hello,

I'm developing a bootloader based on the one included in SDK 13.1. It is now restarting due to an NRF_ERROR_NO_MEM that I'm not sure where it's coming from. It must come from an APP_ERROR_CHECK but I don't know which one.

I used to have a RAM warning from softdevice_enable and I got rid of it by changing the RAM region in the linker script accordingly.

/** RAM (rwx) :  ORIGIN = 0x20002C00, LENGTH = 0x5380 ORIGINAL RAM REGION */
  RAM (rwx) :  ORIGIN = 0x20002060, LENGTH = 0xDFA0

I thought that maybe with such an increase in the RAM region it would be solved but I was wrong.

I read in some threads that it may have something to do with the usage of timers (I added two to the bootloader) and an APP_TIMER_MAX_TIMERS macro that I should be modifying each time I add a timer, but the APP_ERROR_CHECKS after the timer initializations work without a problem. I also believe that that macro does not exist anymore in SDK 13.

What else can I do to solve this problem besides trying to reduce the RAM usage of my application? The NRF52832 chipset I'm using has 64 KB of RAM.

Update: I found the APP_ERROR_CHECK that's failing:

static void timeout_handler_exec(timer_node_t * p_timer)
{
#if APP_TIMER_CONFIG_USE_SCHEDULER
    app_timer_event_t timer_event;

    timer_event.timeout_handler = p_timer->p_timeout_handler;
    timer_event.p_context       = p_timer->p_context;
    uint32_t err_code = app_sched_event_put(&timer_event, sizeof(timer_event), timeout_handler_scheduled_exec);
    NRF_LOG_INFO("timeout handler err code: %d\r\n", err_code);
    APP_ERROR_CHECK(err_code);
#else
    p_timer->p_timeout_handler(p_timer->p_context);
#endif
}

It looks like app_sched_put_event() fails because the app scheduler queue is full, and it therefore returns an NRF_ERROR_NO_MEM error.

  • Apparently I had a repeated timer that was firing too often and that was filling the app scheduler's queue.

    The period of the timer was 500 ms and I increased it to 1 second and that solved the issue.

  • Thank you for posting this!  I just ported some code from an older SDK on the nrf52832, to a newer SDK on the nrf52840 and had the same exact problem.  Interesting that it's a problem with the newer hardware and SDK, but not the older code.  

  • Hi Andy,

    for everybody who occasionally gets the NRF_ERROR_NO_MEM error issued from the application timer or scheduler, I would like to give a simple (maybe silly Wink) hint, as I stumbled over it a few times.

    When starting some processes that are able to trigger interrupts - as the application timer does - it is important to remember that very often their interrupt handler just queues an event to the scheduler, with the intent that the scheduled events will be served outside the interrupt (in the main loop) at a later time, by calling app_sched_execute() at regular intervals.

    Therefore, remember to place the call of app_sched_execute() inside the main loop, and perhaps also inside functions (called from the main loop) which take a long time before they return (e.g. waiting loops, waiting for some signal).

    The function app_sched_execute() will serve scheduled events and prevent that the events queue overruns (error NRF_ERROR_NO_MEM) .

Related