cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with UART in secure and unprivileged mode U5

ECoud.1
Associate III

I am encountering an issue in the development of the TrustZone application related to the UART in secure non-privileged mode.

I want to switch to non-privileged mode when in secure and privileged mode. This transition works correctly. However, I have noticed that the UART does not work in non-privileged mode, even though it functions in privileged mode.

When I execute the code, it consistently ends up in the HardFaultHandler(). After debugging, I identified that the error occurs on line 227 of the main file, specifically during the call to the HAL_UART_Receive() function.

To configure the peripherals, I used the GTZC.

Detailed Analysis

  1. Event detected in the SFR register:

    • The UUSART1F bit is activated, indicating an illegal access event.
    • Upon verification, the USART is correctly configured in the desired mode: the secure bit is set to 1, and I am in non-privileged mode.
  2. Mode Transition:

    • The switch from privileged to non-privileged mode works, as the ARM control bit (in the CONTROL register) is correctly set to 1.
  3. Behavior of the MMFSR (Memory Management Fault Status Register):

    • During the HardFault, the DACCVIOL bit (data access violation indicator) is set to 1.
    • This bit indicates that the processor attempted to load or store data at a memory address not authorized for this operation.
    • The MMAR register contains the faulting address, and the PC register points to the instruction that caused the error.

Hypothesis

It seems the problem is related to a memory access violation in non-privileged mode. This could be caused by:

  • Incorrect configuration of USART permissions in the GTZC;
  • Or an access restriction related to rights management in non-privileged mode.

Actions Already Taken

  • Verification of the SFR and GTZC registers: the USART seems correctly configured.
  • Validation of the transition from secure privileged to non-privileged mode.

I am trying to determine why the processor considers the access to the USART as illegal in non-privileged mode. Here is the code enclosed

Thank you in advance for your assistance.

2 REPLIES 2
Jocelyn RICARD
ST Employee

Hello @ECoud.1 ,

according to your investigation it look like the memory you are trying to access is not setup to authorize non privilege access. 

If address is in flash, you will need to setup FLASH_PRIVBB. But default value allows non privilege access.

If access is in RAM, you need to setup GTZC to allow non privilege access to the concerned area.

Best regards

Jocelyn

ECoud.1
Associate III

Thank you for your response. Could you provide more details on how to configure the flash? I’ve read the datasheet, but I’m having difficulty understanding how to program it, especially since you mentioned that the default configuration allows non-privileged access. However, this doesn’t seem to be the case for me.

I’ve also configured the GTZC for the peripherals I want to use. I have a similar application running without TrustZone, and it works fine. Perhaps there’s some configuration I’m missing?

What I’m trying to achieve is encryption and decryption of data using the four modes of the Cortex-M33, but I haven’t been able to find tutorials or clear information on how to implement it.