# Issue in using "HAL\_UART\_Transmit" in FreeRTOS-MPU Usermode task

**URL:** <https://forums.freertos.org/t/issue-in-using-hal-uart-transmit-in-freertos-mpu-usermode-task/8272>\
**Category:** Kernel\
**Created:** [November 18, 2019, 11:16am UTC](https://forums.freertos.org/t/issue-in-using-hal-uart-transmit-in-freertos-mpu-usermode-task/8272 "2019-11-18T11:16:34Z")\
**Posts on this page:** 5\
**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:** [November 18, 2019, 11:16am UTC](https://forums.freertos.org/t/issue-in-using-hal-uart-transmit-in-freertos-mpu-usermode-task/8272/1 "2019-11-18T11:16:34Z")

</div>

**[nilesh291](https://sourceforge.net/u/nilesh291/)** wrote on [Monday, November 18, 2019](https://sourceforge.net/p/freertos/discussion/382005/thread/8dcae23f86/#254a):

Hi,

I am using FreeRTOS-MPU port with STM32F412. I have taken example which is given in STM32CubeF4 sdk package.

All things are working fine but I am not able to figure out that how to use “HAL\_UART\_Transmit” in FreeRTOS Usermode (Non- Priviledge) task. Currently it gives memory fault if I call this API inside the Use mode task. However this API is working fine if the task is in Privilege mode.

---

<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:** [November 18, 2019, 2:57pm UTC](https://forums.freertos.org/t/issue-in-using-hal-uart-transmit-in-freertos-mpu-usermode-task/8272/2 "2019-11-18T14:57:37Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Monday, November 18, 2019](https://sourceforge.net/p/freertos/discussion/382005/thread/8dcae23f86/#254a/dd1a):

The UART will be memory mapped, so writing to the UART is just like  
accessing a memory location. If you have a user mode task that needs to  
write to the UART you will have to use an MPU region to grant it access  
to the memory mapped UART registers, or make UART writes a system call  
in which case the actual write is performed by whichever priliged task  
services the system call (in other words have an SVC handler for UART  
writers, the UART write API function readies the data to be written then  
executes the SVC assembler instruction which results in an exception  
executing in privileged mode, and once in privileged mode you can assess  
the memory mapped UART registers).

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [November 19, 2019, 4:27am UTC](https://forums.freertos.org/t/issue-in-using-hal-uart-transmit-in-freertos-mpu-usermode-task/8272/3 "2019-11-19T04:27:53Z")

</div>

**[nilesh291](https://sourceforge.net/u/nilesh291/)** wrote on [Tuesday, November 19, 2019](https://sourceforge.net/p/freertos/discussion/382005/thread/8dcae23f86/#8b83):

Thanks a lot.  
I will check these method.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [November 19, 2019, 4:43am UTC](https://forums.freertos.org/t/issue-in-using-hal-uart-transmit-in-freertos-mpu-usermode-task/8272/4 "2019-11-19T04:43:34Z")

</div>

**[nilesh291](https://sourceforge.net/u/nilesh291/)** wrote on [Tuesday, November 19, 2019](https://sourceforge.net/p/freertos/discussion/382005/thread/8dcae23f86/#7633):

Hi @rtel,

If possible, can you elaborate second method (UART writes a system call …) and explain with example?  
This will be much appreciated.

---

<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:** [November 19, 2019, 4:29pm UTC](https://forums.freertos.org/t/issue-in-using-hal-uart-transmit-in-freertos-mpu-usermode-task/8272/5 "2019-11-19T16:29:50Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Tuesday, November 19, 2019](https://sourceforge.net/p/freertos/discussion/382005/thread/8dcae23f86/#7633/6732):

…it is by far the harder method as you need to extend the SVC  
handler. Currently the SVC handler handles three cases - starting the  
scheduler, yielding and raising the privilege - you would need to extend  
that to also handle your UART writes.  
[https://sourceforge.net/p/freertos/code/HEAD/tree/tags/V10.2.1/FreeRTOS/Source/portable/GCC/ARM\_CM4\_MPU/port.c#l260](https://sourceforge.net/p/freertos/code/HEAD/tree/tags/V10.2.1/FreeRTOS/Source/portable/GCC/ARM_CM4_MPU/port.c#l260)
