# STM32F Cortex M4 MPU Crash

**URL:** <https://forums.freertos.org/t/stm32f-cortex-m4-mpu-crash/7121>\
**Category:** Kernel\
**Created:** [April 10, 2018, 2:21am UTC](https://forums.freertos.org/t/stm32f-cortex-m4-mpu-crash/7121 "2018-04-10T02:21:15Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [April 10, 2018, 2:21am UTC](https://forums.freertos.org/t/stm32f-cortex-m4-mpu-crash/7121/1 "2018-04-10T02:21:15Z")

</div>

**[nmithun](https://sourceforge.net/u/nmithun/)** wrote on [Tuesday, April 10, 2018](https://sourceforge.net/p/freertos/discussion/382005/thread/e1915d14/#a14b):

Hi,

We have been trying to use ARM\_CM4F\_MPU port in one of our application. Freertos version is 10.0.0.

An unprivileged task always Mem Faults when trying to use a kernel API though mpu\_wrappers is elevating the privilege of during kernel execution.

When Task calls vTaskDelay(), it crashes inside portYIELD\_WITHIN\_API() though I can see it gets executed when CPU state is in Privilege mode. nPRIV in CONTROL Register is 0 when this yield is called.

Any pointers on what could cause this?

Regards

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [April 10, 2018, 4:27am UTC](https://forums.freertos.org/t/stm32f-cortex-m4-mpu-crash/7121/2 "2018-04-10T04:27:13Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Tuesday, April 10, 2018](https://sourceforge.net/p/freertos/discussion/382005/thread/e1915d14/#a14b/2b72):

Was this a project you put together yourself, or a project we provided?  
If a project you put together yourself then did you update the linker  
script (or constants, depending on the compiler you are using) so the  
memory bounds of the privileged data sections are defined correctly?

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [April 10, 2018, 6:52am UTC](https://forums.freertos.org/t/stm32f-cortex-m4-mpu-crash/7121/3 "2018-04-10T06:52:59Z")

</div>

**[nmithun](https://sourceforge.net/u/nmithun/)** wrote on [Tuesday, April 10, 2018](https://sourceforge.net/p/freertos/discussion/382005/thread/e1915d14/#a14b/2b72/3444):

This project was put together ourselves.

On entry to this task, we are accessing a couple of variables in SRAM whose region is defined as NON PRIVILEGE READ\_WRITE. We are able to read write on this region. After this we are using vTaskDelay() inside which it Mem Faults when it calls portYIELD\_WITHIN\_API().

Even if the variables are disabed and only vTaskDelay() is called on entry inside this task, it faults.

void ProcessMainTask(void \*arg) //Non Privilege Task  
{  
g\_NonPrivMemArray[0] = 1;  
while(1)  
{  
vTaskDelay(10);  
}  
}

It assigns g\_NonPrivMemArray[0] with 1, then tries to delay and crashes.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [April 10, 2018, 7:07am UTC](https://forums.freertos.org/t/stm32f-cortex-m4-mpu-crash/7121/4 "2018-04-10T07:07:03Z")

</div>

**[nmithun](https://sourceforge.net/u/nmithun/)** wrote on [Tuesday, April 10, 2018](https://sourceforge.net/p/freertos/discussion/382005/thread/e1915d14/#a14b/2b72/3444/5d74):

Also, if I use the same application code with Freertos 9.0.0 version avaiable in STMCube it does not crash here.

There is not change in application at all. Just replaced RTOS from 10.0.0 to 9.0.0 provided in STMCube.

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [April 10, 2018, 2:58pm UTC](https://forums.freertos.org/t/stm32f-cortex-m4-mpu-crash/7121/5 "2018-04-10T14:58:20Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Tuesday, April 10, 2018](https://sourceforge.net/p/freertos/discussion/382005/thread/e1915d14/#a14b/2b72/3444/5d74/1ed9):

Does STM32 Cube contain the MPU version of FreeRTOS? I thought it only  
contained the non-MPU version.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [April 11, 2018, 2:03am UTC](https://forums.freertos.org/t/stm32f-cortex-m4-mpu-crash/7121/6 "2018-04-11T02:03:33Z")

</div>

**[nmithun](https://sourceforge.net/u/nmithun/)** wrote on [Wednesday, April 11, 2018](https://sourceforge.net/p/freertos/discussion/382005/thread/e1915d14/#a14b/2b72/3444/5d74/1ed9/bd26):

Yes it contains an MPU version also. But it has version 9.0.0 of Freertos. We initially ported 10.0.0 into our application and all our tests have been on this version.

So we are hesitant to go back to 9.0.0 as we will have to redo all our tests.
