Issue in using "HAL_UART_Transmit" in FreeRTOS-MPU Usermode task

nilesh291 wrote on Monday, November 18, 2019:


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.

rtel wrote on Monday, November 18, 2019:

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).

nilesh291 wrote on Tuesday, November 19, 2019:

Thanks a lot.
I will check these method.

nilesh291 wrote on Tuesday, November 19, 2019:

Hi @rtel,

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

rtel wrote on Tuesday, November 19, 2019:

…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.