FreeRTOS Port for NXP Kinetis with MPU extension

marcbe wrote on Monday, April 10, 2017:

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

rtel wrote on Monday, April 10, 2017:

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.

marcbe wrote on Wednesday, April 12, 2017:

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?

rtel wrote on Wednesday, April 12, 2017:

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

marcbe wrote on Thursday, April 13, 2017:

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.

rtel wrote on Thursday, April 13, 2017:

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 traceTASK_SWITCHED_IN or
    traceTASK_SWITCHED_OUT 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

marcbe wrote on Tuesday, April 18, 2017:

You could define either the traceTASK_SWITCHED_IN

I will use the traceTASK_SWITCHED_IN 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 traceTASK_SWITCHED_IN the pxCurrentTCB will point to the task about to enter the Running state.

rtel wrote on Tuesday, April 18, 2017:

I assume the macro runs in privileged mode?

Yes, correct.

Isn’t it vice-versa? In case of the traceTASK_SWITCHED_IN the
pxCurrentTCB will point to the task about to enter the Running state.

Also correct.

pvranade wrote on Thursday, December 14, 2017:

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

marcbe wrote on Thursday, December 14, 2017:

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.

rtel wrote on Thursday, December 14, 2017:

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