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?
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?
Dmitry said:Maybe it's possible but it makes too easy to shoot own's foot :)
Dmitry said:Could I make a feature request as you said? Are there plans to release an update for softdevice 5.x?
I think this has to come through the Regional Sales Manager of your area. Can you ask him to escalate this feature request. This way it is done through the proper channels.
I am unable to see which country/company you are from. If you give me your details, I will ask the RSM in that area to contact you.
Thank you, I updated my profile
sent you a private message with the details of the RSM.