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

sd_app_evt_wait and unprivileged thread mode

Hello,

Our board is based on nRF52832 with S132 5.1.0, without RTOS. Now we have a requirement to protect sensitive memory areas with MPU, so I'm trying to run firmware in unprivileged mode (CONTROL=0x01), and I got Bus Fault in sd_app_evt_wait() handler. Should I use __WFE() instead, is it safe with SoftDevice enabled?

Dmitry

Parents
  • You are right, the sd_app_evt_wait always runs the sleep instructions in the privileged thread mode and hence it expects to return it to that state. I think this needs to be a feature request to change that behavior, as I do not see anything wrong in what you are doing. For now we are limited by this behavior.

    Could below be a possible workaround?

    Can we switch to privileged thread mode just before sleeping and change to unprivileged thread mode after wakeup? this way the SD thread mode switch behavior is consistent with the application.

  • If I understand right, this workaround should:

    - enter privileged mode (for example, using SVC 0x01)

    - from SVC handler, clear CONTROL register and change return address in stack to some intermediate Thread code

    - that code will call SVC 0x3E (sd_app_evt_wait)

    - at return, it will set CONTROL register back and pass control to calling function

    Maybe it's possible but it makes too easy to shoot own's foot :)  I decided to set MPU XN bit on RAM and leave in privileged mode - at least this way protects from accidental reading of critical memory regions.

    Could I make a feature request as you said? Are there plans to release an update for softdevice 5.x?

Reply
  • If I understand right, this workaround should:

    - enter privileged mode (for example, using SVC 0x01)

    - from SVC handler, clear CONTROL register and change return address in stack to some intermediate Thread code

    - that code will call SVC 0x3E (sd_app_evt_wait)

    - at return, it will set CONTROL register back and pass control to calling function

    Maybe it's possible but it makes too easy to shoot own's foot :)  I decided to set MPU XN bit on RAM and leave in privileged mode - at least this way protects from accidental reading of critical memory regions.

    Could I make a feature request as you said? Are there plans to release an update for softdevice 5.x?

Children
Related