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

Changing on_ble_evt interrupt priority

Working with: examples/ble_peripheral/ble_app_uart . I would like to change on_ble_evt priority level so that UART IRQ handler has lower priority then softdevice event dispatching routine.

So far I checked that there are following IRQ priority levels:

  • UART = 6 (or APP_LOW)
  • on_ble_evt = 7 (or APP_LOWEST)

Context: I want to synchronise UART and BLE_NUS in a way that UART sends data to NUS and is stalled (in interruption handler) waiting for BLE_NUS to complete. I assume that the completion flag will be set in on_ble_evt, then when event handling returns execution context is passed to UART handler.

How can I achieve that?

  • Hi

    After you have enabled the stack it should be possible to change the priority of the BLE events like this:

    NVIC_SetPriority(SD_EVT_IRQn, 7);
    

    Please be aware that you should only use interrupt priorities allocated to the application, and using an interrupt priority higher than the SVC handler doesn't really make sense (since it means you can't call SoftDevice functions inside the event handler), so the only recommended options are 6 and 7.

    Best regards
    Torbjørn

  • It does not solve my problem anyway, how can I stall UART RX? Let's assume I wait for '\n'. I want to stop receiving (but not start droping data) and wait for on_ble_evt call to resume UART RX. Ideally UART would use flow control to stop the communication with some host and wait for softdevice event to enable it again.

  • Hi

    You don't have to call app_uart_get(..) right away, even if you get the DATA_READY interrupt. You can simply ignore it, and wait for the NUS to finish before reading out the next byte. Assuming you have enough buffer space available to store the incoming data you will not lose any bytes.

    Best regards

Related