sd_ecb_block_encrypt() execution time

We have a custom protocol with strict deadlines in the radio stack between receiving a packet, decrypting it, processing encrypting an ack and send the ack.

For that reason, we have strict deadlines on sd_ecb_block_encrypt(), and it seems to work for every case, except now one.

In this case, we are running:

- nrf52840

- Softdevice s140 v7.2.0

- nrf5-sdk 17.0.2

- FreeRTOS 10.0.0, the version shipped with nrf5-sdk

Our setup runs all radio code from the radio interrupt in an allocated radio slot, and thus on priority 0. Except the calls to softdevice, in which we trigger an SWI and drops to interrupt priority 5 for that call, and has the deadline specified on a TIMER0 compare. If we miss the deadline, then we log and retries later. Otherwise, we don't have any other interrupts during that period

I have measured that the call to sd_ecb_block_encrypt() and a block copy takes 15.8us in every case we have without running FreeRTOS, or when using that version of FreeRTOS while connected to a debugger, but in running state. But when disconnecting the debugger and reset the CPU, many of those calls starts 26.8us each, in a rate so we miss the deadline when sending bigger packets.

Also have a version where we upgraded FreeRTOS to a later version, and the issue seems to be gone.

We are not running any concurrent bluetooth, or having any other code using the encyrption.

To measure it, I'm using a saleae logic analyzer and pull a pin low just before the call, and high afterwards, to be able to measure timings without debugger/trace. I can't really find a pattern for it, but it seems to affect when running multiple in a row. Note: In the plot low signal means call to sd_ecb_block_encrypt()



I would have preferred to provide more steps to reproduce for this issue, but by the nature of not being able to track any pattern or being able to look at it with a debugger make it lot harder. But feeling uncomfortable without knowing the reason for this issue, since we don't know when it will appear or how to get around it. And thus lost in what to test

So what could make sd_ecb_block_encrypt() increase in execution time when not having debugger connected?

Parents Reply Children
  • Hi,


    Sorry for the delays. But I have finally managed to test it. I haven't hooked up an oscilloscope yet, but I've tried without the fix and then with the fix in our main system where we got the packet loss due to missing the deadlines.

    I can confirm that the fix/workaround works fine. So no issue with missing the deadline we have. Have been sending a couple of hundred packets with 100% PDR it seems now. Before, I might have had one or two of those to squeeze through before.

    Thanks for the help :)

    One last question then:

    How long should we keep this workaround, and what should we look for in the release notes if it gets fixed?

  • Oh, also one more thing.

    Will this become a problem if we use it on the s132 softdevice too, or do that have the same issue?

    We are running the same project on both nrf52840 and nrf52832, and we want to keep the codebase as common as possible

  • Max, Thanks for confirming that the fix works.

    Max Sikström said:
    How long should we keep this workaround, and what should we look for in the release notes if it gets fixed?

    Unfortunately, I do not think we are releasing any baremetal Softdevice(s) versions anymore. The fix for this has been applied to Softdevice Controller (Zephyr based Nordic BLE controller). So you need to maintain this workaround in your application as long as you use nRF5 SDK and not the latest Nordic Connect SDK.

    Max Sikström said:
    Will this become a problem if we use it on the s132 softdevice too, or do that have the same issue?

    This part of the Softdevice code is common for both S132 and S140. So, Yes, you need to maintain this code for both versions of your application.

  • That makes sense. Think I've heard about that too.

    Regarding this workaround, I don't think that's a problem as long as we know what to expect.

    Thanks!

  • Max Sikström said:
    Regarding this workaround, I don't think that's a problem as long as we know what to expect.

    I have confidence in the workaround and it is not a complex one either. If you do not have anything else then please mark this reply as verified so as to help other community members in the future.

Related