FreeRTOS Port for NXP Kinetis with MPU extension

I am trying to get FreeRTOS with MPU support to run on NXP Kinetis MK66F. Unfortunately I found out the MPU delivered with K66 isn’t the one provided by ARM. Instead it’s an implementation from Freescale/NXP which isn’t supported yet by FreeRTOS, is it? FreeRTOS comes with a port for Cortex-M4F with MPU but this one doesn’t work on K66. Is there a port for Kinetis Series with MPU Support available? If not, how can it be ported? Freescale provides peripheral drivers for MPU – could these be used for porting FreeRTOS? Thanks

FreeRTOS Port for NXP Kinetis with MPU extension

It is possible that NXP have an example, but I don’t know. We only provide examples for the ARM MPU. How different is the NXP MPU? The ARM one is not very flexible, which makes it hard to use in a system that only has a small amount of RAM. It might be the NXP one gives you more flexibility.

FreeRTOS Port for NXP Kinetis with MPU extension

Yes the NXP MPU indeed is more flexible. It allows up to 12 regions to be declared on 32 byte boundaries with rwx attributes for supervisor and user mode. Furthermore the NXP MPU allows to include a process identifier for in access permission evaluation. How can I modify the task creation / scheduler in a way which allows Definition of a process identifier (PID) per task (e.g. when using xTaskCreateRestricte) and setting this PID with each context switch?

FreeRTOS Port for NXP Kinetis with MPU extension

How can I modify the task creation / scheduler in a way which allows Definition of a process identifier (PID) per task
Do you just want a unique identifier per task? The task’s handle is unique to the task. If that is not appropriate then perhaps you could use thread local storage? http://www.freertos.org/thread-local-storage-pointers.html

FreeRTOS Port for NXP Kinetis with MPU extension

Do you just want a unique identifier per task? The task’s handle is unique to the task.
Can I explicitly set the task handle to a defined value? I would like to use predefined PIDs for each task. The task itself doesn’t need to know its PID but the scheduler does. Where exactly is the context switch performed? I need a function which will be called each time a task is set to running, which is running in supervisor mode and knows the PID of the next task.

FreeRTOS Port for NXP Kinetis with MPU extension

Context switches are only ever performed in the PendSV handler. If you want a user function to execute then you have a couple of options: 1) You could use a task hook http://www.freertos.org/xTaskCallApplicationTaskHook.html 2) You could define either the traceTASKSWITCHEDIN or traceTASKSWITCHEDOUT trace macros – in the first case pxCurrentTCB will point to the task that executed previously, and in the second pxCurrentTCB will point to the task that is going to execute next (which could be the same task). http://www.freertos.org/rtos-trace-macros.html

FreeRTOS Port for NXP Kinetis with MPU extension

You could define either the traceTASKSWITCHEDIN
I will use the traceTASKSWITCHEDIN macro together with the task tag. I assume the macro runs in privileged mode?
in the first case pxCurrentTCB will point to the task that executed previously, and in the second pxCurrentTCB will point to the task that is going to execute next
Isn’t it vice-versa? In case of the traceTASKSWITCHEDIN the pxCurrentTCB will point to the task about to enter the Running state.

FreeRTOS Port for NXP Kinetis with MPU extension

I assume the macro runs in privileged mode?
Yes, correct.
Isn’t it vice-versa? In case of the traceTASKSWITCHEDIN the pxCurrentTCB will point to the task about to enter the Running state.
Also correct.

FreeRTOS Port for NXP Kinetis with MPU extension

Curious to know if you could port FreeRTOS to NXP Kinetis MK66F?

FreeRTOS Port for NXP Kinetis with MPU extension

I have a working port for K66 but without the MPU by now. I am still working at the project and the MPU might be included in future. Then the solution would be to use the task handle to store the tasks specific MPU configuration.. The traceTASK_SWITCHED macro is used to configure the MPU.

FreeRTOS Port for NXP Kinetis with MPU extension

FreeRTOS will run on any Cortex-M0, M0+, M3, M4, M4F or M7 based MCU from any manufacturer using any of the ARM compilers we support – no porting is required – you just need to create a project. https://www.freertos.org/Creating-a-new-FreeRTOS-project.html https://www.freertos.org/porting-a-freertos-demo-to-different-hardware.html