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

things allow/not allowed to call from callbacks NRF52/S132

Hi!

I was developing my custom service, and had a question around what kind of functionality is allowed or not allowed within a callback from the soft device or other peripheral drivers.

Examples:

example #1: softdevice handler for BLE events: err_code = softdevice_ble_evt_handler_set(ble_evt_dispatch);

Now I wanted to use std::make_shared within that event handler, and it seems that it will just hang the device or trigger some kind of fault (sometimes debugging isn't that clear).

example #2: TWI peripheral driver completion handler: err_code = nrf_drv_twi_init(&m_twi, &twi_drv_config, twi_handler, config);

In this case I wanted to call sd_ble_gatts_value_set, but this will also result in a hang or some kind of fault (again not that easy to debug).

Is there a clear list of what's allowed at what point?

Thanks, Peter

  • For 2, what interrupt priority have you configured the driver to use?

  • Hi! that was APP_IRQ_PRIORITY_HIGH, is there a good overview what kind of things need which priorty?

    Also something that might be related: if I turn on logging (compile flag NRF_LOG_ENABLED=1), then there will be exactly one advertisement, and nothing else. Also e.g. the app_timer does not work while advertising, but as soon as somebody connects, it will start working. Any ideas what all if this could be?

  • I'm not sure what kind of overview you mean, but you cannot call SoftDevice API from APP_IRQ_PRIORITY_HIGH (1). This is because every SoftDevice API call is triggering SVC interrupt and this interrupt is on level 2 (lower than application high level).

    You can call SoftDevice (including sd_nvic_... functions) from APP_IRQ_PRIORITY_LOW (3) and main context.

    The behavior you describe sounds really strange. What do you mean by one advertisment? One advertising packet? Then it would be very difficult for a central to connect...?

  • Hi Petter, your comments so far helped a lot. summarizing again:

    issue #1 is still the same

    issue #2 for TWI I changed the priority to LOW (just took the HIGH prio over from the TWI example in the SDK without looking at it too closely) -> this seems to work a lot better

    issue #3: ok, I found it and understood it, so no issue anymore.

    issue #4: now that the TWI callback works correctly, if I do NRF_LOG_INFO("%f",some_float_var), it will hang right there, unless I add linker option -u _printf_float, then it will always print 0.000000. I saw the macros for outputting a float as two integers, is this the recommended option?

    as for the overview, it wasn't completely clear to me from the docs on how those IRQ levels behave and what exactly is possible. I know that the docs mentioned several things, but it wasn't completely clear. I think I understand the IRQ levels now and my mistake with TWI there, but as for issue #1 and #4, it's unclear to me how IRQ levels that I control would influence that.

  • I'm not sure why you can't print floats, maybe add a separate question? I'm not sure what kind of overview you are after, but this Section in the SoftDevice specification should be examined at least.

Related