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

app_timer RAM usage on SDK 10

Is there any difference in RAM overhead with the new app_timer module on SDK 10?

I'm my application on SDK 6.1, I have 25 app_timers which run without any issue.
APP_TIMER_MAX_TIMERS 25 APP_TIMER_OP_QUEUE_SIZE 22

However I cannot use more than 10 on SDK 10 without getting a compile-time RAM overflow error. I'm trying to slowly develop an application on top of ble_app_hrs. As far as I can tell the new APP_TIMER_DEF() macro handles all memory declaration and allocation for app_timers. But is this causing more RAM overhead?

Thanks guys

  • Hi Dave,

    The APP_TIMER_DEF() macro will expand to two static variables:

    app_timer_t
    app_timer_id_t
    

    The last one is just a pointer to app_timer_t. The total size of one timer will be:

    sizeof(app_timer_t) + one pointer = 32 + 4 bytes
    

    In addition, you have a operational queue, which sets aside a static array:

    #define APP_TIMER_BUF_SIZE(OP_QUEUE_SIZE)                                              \
        (                                                                                              \
            (                                                                                          \
                APP_TIMER_INT_LEVELS                                                                   \
                *                                                                                      \
                (APP_TIMER_USER_SIZE + ((OP_QUEUE_SIZE) + 1) * APP_TIMER_USER_OP_SIZE)                 \
            )                                                                                          \
        )
    

    This calculation boils down to this:

    3 * (8 + (OP_QUEUE_SIZE+1) * 24)
    

    If this macro is set to 22, it will take up

    3*(8+(22+1)*24) = 1752 bytes
    

    Most likely, you do not need to have the OP_QUEUE_SIZE this high, unless you are starting/stopping most of your app_timer instances in different priorities (main, pri 3, pri 1).

    The op_queue_size is a bit tricky to understand, but if you are running all app_timer operations in only main-context, this can be set to '1'. Once you start calling app_timer functions from main, interrupt priority 1, and interrupt priority 3, the queue size must be upped in order to be able to queue up the theoretical maximum queue that can occur in app_timer.

    It's explained a bit more in detail here (for an older app_timer version, but still valid for the value of op_queue_size): devzone.nordicsemi.com/.../

    Cheers, Håkon

Related