# MPU definition for SC000

**URL:** <https://forums.freertos.org/t/mpu-definition-for-sc000/17431>\
**Category:** Kernel\
**Tags:** tutorial\
**Created:** [May 16, 2023, 7:37am UTC](https://forums.freertos.org/t/mpu-definition-for-sc000/17431 "2023-05-16T07:37:45Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![achechet](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/achechet/32/3282_2.png) [@achechet](https://forums.freertos.org/u/achechet)\
**Post date:** [May 16, 2023, 7:37am UTC](https://forums.freertos.org/t/mpu-definition-for-sc000/17431/1 "2023-05-16T07:37:45Z")

</div>

My controller (SC000) allows you to use the MPU. To do this, I have to select the region number in one register, and then write the settings (size, properties) into another register.  
Please, advise me how to link (convert) these settings with the settings in FreeRTOS-MPU?

---

<div class="post-metadata">

**Author:** ![aggarg](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/aggarg/32/4245_2.png) [@aggarg](https://forums.freertos.org/u/aggarg)\
**Post date:** [May 16, 2023, 7:49am UTC](https://forums.freertos.org/t/mpu-definition-for-sc000/17431/2 "2023-05-16T07:49:38Z")

</div>

Looking at [this document](https://developer.arm.com/Processors/SecurCore%20SC000), the programmer’s model for SC000 is same as Cortex-M0. If you want to statically program the MPU, then you can do that after boot up either by directly accessing the MPU registers or using CMSIS APIs. If you are looking for a FreeRTOS MPU port where you can have per task MPU regions, we do not have that for Cortex-M0. What do you want to achieve using MPU?

---

<div class="post-metadata">

**Author:** ![achechet](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/achechet/32/3282_2.png) [@achechet](https://forums.freertos.org/u/achechet)\
**Post date:** [May 16, 2023, 8:03am UTC](https://forums.freertos.org/t/mpu-definition-for-sc000/17431/3 "2023-05-16T08:03:21Z")

</div>

If you use the first option (static definition), how in this case link the MPU region and the space allocated for the task?

---

<div class="post-metadata">

**Author:** ![aggarg](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/aggarg/32/4245_2.png) [@aggarg](https://forums.freertos.org/u/aggarg)\
**Post date:** [May 16, 2023, 8:43am UTC](https://forums.freertos.org/t/mpu-definition-for-sc000/17431/4 "2023-05-16T08:43:51Z")

</div>

First of all, you need to define what you want to achieve. An example is -

1. Mark all the data region as not executable to prevent code injection attacks.
2. Mark all the code region as read only.

You can then program 2 MPU regions achieve the above.

> [@achechet](#):
>
> how in this case link the MPU region and the space allocated for the task?

If you want to have separate MPU regions for each task, then you need MPU support in the FreeRTOS port so that the MPU is programmed on every context switch.

What problem are you trying to solve?

---

<div class="post-metadata">

**Author:** ![achechet](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/achechet/32/3282_2.png) [@achechet](https://forums.freertos.org/u/achechet)\
**Post date:** [June 28, 2023, 10:13am UTC](https://forums.freertos.org/t/mpu-definition-for-sc000/17431/5 "2023-06-28T10:13:09Z")

</div>

> [@aggarg](#):
>
> If you want to have separate MPU regions for each task, then you need MPU support in the FreeRTOS port so that the MPU is programmed on every context switch.
> 
> What problem are you trying to solve?

I have an understanding of how to define the properties of the MPU region.  
My question is how to specify in which area to allocate the privileged task. How to chain startTask with memory allocation?  
There is no need to allocate a memory area every time.  
Each must be task is located in its own MPU region.  
Regions of MPU setup define staticly in StartUp file

---

<div class="post-metadata">

**Author:** ![aggarg](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/aggarg/32/4245_2.png) [@aggarg](https://forums.freertos.org/u/aggarg)\
**Post date:** [June 28, 2023, 10:26am UTC](https://forums.freertos.org/t/mpu-definition-for-sc000/17431/6 "2023-06-28T10:26:41Z")

</div>

Your description of the problem is not very clear. I’ll still try to answer based on my understanding of your problem.

> [@achechet](#):
>
> My question is how to specify in which area to allocate the privileged task. How to chain startTask with memory allocation?

When you create a task, 2 regions of memory are needed -

1. Stack
2. Task Control Block (TCB)

You can use the xTaskCreateStatic API which takes both of these memory buffer from the application and then you can place them wherever you want.

> [@achechet](#):
>
> Each must be task is located in its own MPU region.  
> Regions of MPU setup define staticly in StartUp file

You want to have a static MPU configuration at startup and place both Stack and TCB of each task in a separate region? If so, yes, you can do so. I’d recommend again to list down the threats that you are trying to address and ensure that those are addressed by your solution.

---

<div class="post-metadata">

**Author:** ![achechet](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/achechet/32/3282_2.png) [@achechet](https://forums.freertos.org/u/achechet)\
**Post date:** [June 28, 2023, 10:34am UTC](https://forums.freertos.org/t/mpu-definition-for-sc000/17431/7 "2023-06-28T10:34:14Z")

</div>

> [@aggarg](#):
>
> You want to have a static MPU configuration at startup and place both Stack and TCB of each task in a separate region? If so, yes, you can do so. I’d recommend again to list down the threats that you are trying to address and ensure that those are addressed by your solution.

two tasks are launched, one works with the serial port and receives jobs. the second task runs in the protected region and performs the calculations passing the results through the queue.

---

<div class="post-metadata">

**Author:** ![aggarg](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/aggarg/32/4245_2.png) [@aggarg](https://forums.freertos.org/u/aggarg)\
**Post date:** [June 28, 2023, 10:36am UTC](https://forums.freertos.org/t/mpu-definition-for-sc000/17431/8 "2023-06-28T10:36:47Z")

</div>

> [@achechet](#):
>
> two tasks are launched, one works with the serial port and receives jobs. the second task runs in the protected region and performs the calculations passing the results through the queue.

And are you facing any issue in this configuration?

---

<div class="post-metadata">

**Author:** ![achechet](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/achechet/32/3282_2.png) [@achechet](https://forums.freertos.org/u/achechet)\
**Post date:** [June 28, 2023, 10:42am UTC](https://forums.freertos.org/t/mpu-definition-for-sc000/17431/9 "2023-06-28T10:42:20Z")

</div>

where in task parameters I have to define location in memory? Or may be I have use wrong function to define tasks?

---

<div class="post-metadata">

**Author:** ![aggarg](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/aggarg/32/4245_2.png) [@aggarg](https://forums.freertos.org/u/aggarg)\
**Post date:** [June 28, 2023, 10:44am UTC](https://forums.freertos.org/t/mpu-definition-for-sc000/17431/10 "2023-06-28T10:44:12Z")

</div>

See the puxStackBuffer and pxTaskBuffer parameters - [This page describes the FreeRTOS xTaskCreateStatic() API function which allows an RTOS task to be created using statically allocated RAM.](https://www.freertos.org/xTaskCreateStatic.html)

---

<div class="post-metadata">

**Author:** ![achechet](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/achechet/32/3282_2.png) [@achechet](https://forums.freertos.org/u/achechet)\
**Post date:** [June 28, 2023, 11:11am UTC](https://forums.freertos.org/t/mpu-definition-for-sc000/17431/11 "2023-06-28T11:11:21Z")

</div>

Perhaps I did not describe the problem very accurately. I would like the code of the protected task to be placed in a certain area of memory

---

<div class="post-metadata">

**Author:** ![aggarg](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/aggarg/32/4245_2.png) [@aggarg](https://forums.freertos.org/u/aggarg)\
**Post date:** [June 28, 2023, 11:29am UTC](https://forums.freertos.org/t/mpu-definition-for-sc000/17431/12 "2023-06-28T11:29:36Z")

</div>

You can achieve that by specifying a section for the task code and then placing it in a memory region using linker script.

Code:

```c
void myTaskFunction( void * pvParams ) __attribute__ ( ( section( "protected_task" ) ) )
{
    /* Task definition. */
}

```

Linker Script:

```auto
  .protected_task:
  {
    . = ALIGN(4);
    *(protected_task)
    . = ALIGN(4);
  } >FLASH

```

---

<div class="post-metadata">

**Author:** ![achechet](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/achechet/32/3282_2.png) [@achechet](https://forums.freertos.org/u/achechet)\
**Post date:** [June 28, 2023, 11:56am UTC](https://forums.freertos.org/t/mpu-definition-for-sc000/17431/13 "2023-06-28T11:56:29Z")

</div>

Thank you a lot! Thank you a lot! Thank you a lot!
