Skip to main content
Associate III
June 28, 2025
Solved

Accessing UART in Nonsecure region

  • June 28, 2025
  • 4 replies
  • 488 views

I am using stm32h563zi microcontroller (Nucleo-H563zi) in this i have created project  using trust zone. In this aim was to use UART4 to transmit message. But i am unable to transmit, i have uploaded main.c of secure and nonsecure. what is the possible error in not transmitting the message usign UART4 in nonsecure.

Best answer by Jocelyn RICARD

Hello ​@Shubham08 ,

from your description the only thing you need to do is to implement the libc fputc, __write or __io_put_char depending on your compiler to write on the UART. Please check printf example.

It is also possible to output both secure and non secure printf on the same uart but this is not supported by CubeMX because each peripheral is allocated to only one domain. To do this, just define the uart as non secure. In secure app you will need do the uart configuration manually taking the non secure implementation as example. 

Best regards

Jocelyn

4 replies

Jocelyn RICARD
ST Employee
July 10, 2025

Hello @Shubham08 ,

Please first make all non secure SRAM and non secure peripheral access to privilege.

Also please check same code will work in a non TrustZone environment.

Best regards

Jocelyn

Associate II
July 3, 2026

Hi Jocelyn,

Re: “Please first make all non secure SRAM and non secure peripheral access to privilege”

Any chance you could be specific? Maybe a code snippet that demonstrates this, and in which file it belongs?

I am having issues myself with a button interrupt working in Non-TZ, then TZ, but same code is not working in the OEMiRoT TZ example. Hopefully some more insight into the exact commands that ‘implement’ a new peripheral into the TZ architecture will show me what I’m missing. 

Shubham08Author
Associate III
July 13, 2025

Hii Jocelyn RICHARD,

Can you provide some documentation which will help in understandign the flow or working of trustzone. I have followed the code in example selector but i am not getting how it is done. 

e.g I want to print "Hello world" using uart 4 and print "Currently in truztzone" using uart2. I have configured uart4 in non_secure zone and uart2 in secure zone. after selecting peripheral in .ioc and generating code in stm32cube what will be the flow of the code to achieve the aim to print.

 

Regards,

Shubham

Jocelyn RICARD
Jocelyn RICARDBest answer
ST Employee
July 6, 2026

Hello ​@Shubham08 ,

from your description the only thing you need to do is to implement the libc fputc, __write or __io_put_char depending on your compiler to write on the UART. Please check printf example.

It is also possible to output both secure and non secure printf on the same uart but this is not supported by CubeMX because each peripheral is allocated to only one domain. To do this, just define the uart as non secure. In secure app you will need do the uart configuration manually taking the non secure implementation as example. 

Best regards

Jocelyn