How to taskYIELD() in an unprivileged thread with MPU?

tbacarrot wrote on Friday, October 19, 2018:

Hi all, I’m working on an Arm Cortex-M platform which enables MPU. It seems that taskYIELD() is a privileged function. So I wonder how to execute the same operation as taskYIELD() does in an unprivileged thread, when MPU is enabled.

I searched in mpu_wrappers.c but could not find a wrapper of taskYIELD(). May I know which API I should take a look at?

Thank you.

rtel wrote on Saturday, October 20, 2018:

You are right in that I don’t think there is a way of calling yield() from an unprivileged task, presumably because it writes to the hardware registers. It is something we could add in, if it is necessary for applications, although it is not somethign that is normally used unless you have preemption turned off - is that the case in your application?

tbacarrot wrote on Monday, October 22, 2018:

Hi Richard, thx.
I don’t have a special case yet in which yield() is the only solution.
It just crossed my mind when I implemented an unprivileged thread which should give a mutex and schedule it out. But It seems that semophore give might not always yield another thread immediately. Please correct me if I’m wrong.
So I’d like to check taskYIELD() and I saw in some FreeRTOS docs that yield() is directly called from a normal task. So I’m a little confused.

Can taskYIELD() either be fixed so that an unprivileged task can call it in (MPU enabled)? Or, can the documentation be fixed to reflect the fact that taskYIELD() can only be called from a privileged function?

I think that all that would be needed is to include vTaskYield() in the set of functions that get wrapped for MPU mode, so it generates a system-call trap that can do the Yield over in privilege space.

Yield is a bit of a strange function, in that its usage is somewhat specialized, but I can see how it could be useful for an unprivileged task, especially one at Idle Priority seeing it doesn’t have anything to do at the moment, but the data ready doesn’t generate a notification it could be waiting on.

Good suggestion @beethoven62. I am looking into how can we enable yield and will get back.

I would think building a wrapper for it in mpu_wrappers.c (and associated files) should work.