2365 views|7 replies

305

Posts

0

Resources
The OP
 

【NUCLEO-L552ZE Review】-2: Stay in TrustZone [Copy link]

This post was last edited by MianQi on 2020-12-29 10:53

In the previous post, I mentioned that after following the steps in the tutorial, I could not see EXTI Line 13, but 14. The solution to this problem is to set it in "Pinout view":

But there is still a problem - in the check box to the right of external interrupt 13 (including 14), it cannot be selected, but there is a prompt in the legend below - the gray mark "Enabled":

In this case, let's continue. The generated engineering code is as follows (see the upper left corner):

The idea in the tutorial (https://www.stmcu.com.cn/ecosystem/chip/chipfamily-STM32L5-4) is this:

1. PC7 (green LED) and PB7 (blue LED) are set as indicator lights to the S (safety) and NS (non-safety) areas respectively;

2. PC13 (blue user key switch) is used as the access port for external interrupts;

3. PG7 and PG8 are used as TX and RX of LPUART1 respectively to realize the interaction between PC and MCU. They are located in the NS non-safe area;

4. Set the same code in the interrupt service subroutine (EXTI_ISR()) of the secure and non-secure areas to flip the blue and green LEDs.

The actual effect is: by default, the interrupt of EXTI 13 points to the secure area, but by calling the Secure code through the API, you can reset the direction of EXTI 13 - the NVIC of the secure area or the non-secure area. In this way, you can observe that the EXTI_ISR() in the secure area is valid for both lights, while the non-secure area is only valid for one light.

This post is from stm32/stm8

Latest reply

Thanks for sharing! Looking forward to the follow-up review!   Details Published on 2020-12-29 22:34
 

7462

Posts

2

Resources
2
 

Thanks for sharing! Looking forward to the follow-up review!

This post is from stm32/stm8
 
Personal signature

默认摸鱼,再摸鱼。2022、9、28

 

305

Posts

0

Resources
3
 
This post was last edited by MianQi on 2020-12-31 17:32

The "Project Configuration Code Generation" button is here: (upper left corner)

The generated project file tree is as follows:

Note: The secure area has one more file than the non-secure area: secure_nsc.c

According to the instructions in the tutorial (https://www.stmcu.com.cn/ecosystem/chip/chipfamily-STM32L5-4): do two tasks in the S (safe) area and NS (non-safe) area respectively:

Safe Zone: MX_MX_GPIO_Init() and MX_GTZC_Init()

Non-secure area: MX_MX_GPIO_Init() and MX_LPUART1_UART_Init()

This post is from stm32/stm8
 
Personal signature

“Everyone wants the project to be good, fast, and cheap... pick two.”

- Unknown

 

305

Posts

0

Resources
4
 

Add two sections of code in each of the S and NS areas: The first section of code is the same, both are "EXTI.13_ISR", and the location is here in main.c:

/* USER CODE BEGIN 4 */

/* USER CODE END 4 */

The content of the code is:

void HAL_GPIO_EXTI_Rising_Callback(uint16_t GPIO_Pin)

{

UNUSED(GPIO_Pin);

HAL_GPIO_TogglePin(LED_GREEN_GPIO_Port, LED_GREEN_Pin);

HAL_GPIO_TogglePin(LED_BLUE_GPIO_Port, LED_BLUE_Pin);

}


The second code segment, the content of area S is:

CMSE_NS_ENTRY void SECURE_RetargetISR(uint8_t flag)

{

if (flag == 0x31)

{

NVIC_DisableIRQ (EXTI13_IRQn);

HAL_EXTI_ConfigLineAttributes(EXTI_LINE_13, EXTI_LINE_NSEC);

NVIC_SetTargetState (EXTI13_IRQn);

NVIC_EnableIRQ (EXTI13_IRQn);

}

else if (flag == 0x30)

{

NVIC_DisableIRQ(EXTI13_IRQn);

HAL_EXTI_ConfigLineAttributes (EXTI_LINE_13, EXTI_LINE_SEC);

NVIC_ClearTargetState (EXTI13_IRQn);

NVIC_EnableIRQ (EXTI13_IRQn);

}

}

The purpose is to implement the switch EXTI.13 target function for NS to call. The location is in secure_nsc.c.


The contents of the NS area are:

while (HAL_UART_Receive (&hlpuart1, &InputChar, 1, 1000) == HAL_OK)

{

if (InputChar != Status)

{

if (InputChar == 0x30)

HAL_UART_Transmit (&hlpuart1, “\r\n to be switched to S world.”);

else if (InputChar == 0x31)

HAL_UART_Transmit (&hlpuart1, “\r\n to be switched to NS world.”);

SECURE_RetargetISR (InputChar);

Status = InputChar;

if (Status = 0x30)

HAL_UART_Transmit(&hlpuart1, “\r\n User Button has been switched to S world.”);

else if (Status == 0x31)

HAL_UART_Transmit (&hlpuart1, “\r\n User Button has been switched to NS world.”);

else

HAL_UART_Transmit (&hlpuart1, “\r\n the same state, do nothing. \n”);

}

The location is: while(1) in main.c.


This post is from stm32/stm8
 
Personal signature

“Everyone wants the project to be good, fast, and cheap... pick two.”

- Unknown

 
 

305

Posts

0

Resources
5
 

When you plug in the board, it will prompt "NODE_L552ZE".

Compile and report an error:

08:02:08 **** Incremental Build of configuration Debug for project test_TrustZone-1_NonSecure ****

make -j8 all

arm-none-eabi-gcc "../Core/Src/main.c" -mcpu=cortex-m33 -std=gnu11 -g3 -DUSE_HAL_DRIVER -DSTM32L552xx -DDEBUG -c -I../Core/Inc -I../../Secure_nsclib -I../../Drivers/STM32L5xx_HAL_Driver/Inc -I../../Drivers/CMSIS/Device/ST/STM32L5xx/Include -I../../Drivers/STM32L5xx_HAL_Driver/Inc/Legacy -I../../Drivers/CMSIS/Include -O0 -ffunction-sections -fdata-sections -Wall -fstack-usage -MMD -MP -MF"Core/Src/main.d" -MT"Core/Src/main.o" --specs=nano.specs -mfpu=fpv5-sp-d16 -mfloat-abi=hard -mthumb -o "Core/Src/main.o"

../Core/Src/main.c: In function 'main':

../Core/Src/main.c:102:41: error: 'InputChar' undeclared (first use in this function)

while (HAL_UART_Receive (&hlpuart1, &InputChar, 1, 1000) == HAL_OK)

^~~~~~~~~

../Core/Src/main.c:102:41: note: each undeclared identifier is reported only once for each function it appears in

../Core/Src/main.c:104:22: error: 'Status' undeclared (first use in this function); did you mean 'ITStatus'?

if (InputChar != Status)

^~~~~~

ITStatus

../Core/Src/main.c:107:37: warning: pointer targets in passing argument 2 of 'HAL_UART_Transmit' differ in signedness [-Wpointer-sign]

HAL_UART_Transmit (&hlpuart1, "\r\n to be switched to S world.");

^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

In file included from ../Core/Inc/stm32l5xx_hal_conf.h:402:0,

from ../../Drivers/STM32L5xx_HAL_Driver/Inc/stm32l5xx_hal.h:30,

from ../Core/Inc/main.h:31,

from ../Core/Src/main.c:21:

../../Drivers/STM32L5xx_HAL_Driver/Inc/stm32l5xx_hal_uart.h:1581:19: note: expected 'uint8_t * {aka unsigned char *}' but argument is of type 'char *'

HAL_StatusTypeDef HAL_UART_Transmit(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout);

^~~~~~~~~~~~~~~~~

../Core/Src/main.c:107:7: error: too few arguments to function 'HAL_UART_Transmit'

HAL_UART_Transmit (&hlpuart1, "\r\n to be switched to S world.");

^~~~~~~~~~~~~~~~~

In file included from ../Core/Inc/stm32l5xx_hal_conf.h:402:0,

from ../../Drivers/STM32L5xx_HAL_Driver/Inc/stm32l5xx_hal.h:30,

from ../Core/Inc/main.h:31,

from ../Core/Src/main.c:21:

../../Drivers/STM32L5xx_HAL_Driver/Inc/stm32l5xx_hal_uart.h:1581:19: note: declared here

HAL_StatusTypeDef HAL_UART_Transmit(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout);

^~~~~~~~~~~~~~~~~

../Core/Src/main.c:109:37: warning: pointer targets in passing argument 2 of 'HAL_UART_Transmit' differ in signedness [-Wpointer-sign]

HAL_UART_Transmit (&hlpuart1, "\r\n to be switched to NS world.");

^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

In file included from ../Core/Inc/stm32l5xx_hal_conf.h:402:0,

from ../../Drivers/STM32L5xx_HAL_Driver/Inc/stm32l5xx_hal.h:30,

from ../Core/Inc/main.h:31,

from ../Core/Src/main.c:21:

../../Drivers/STM32L5xx_HAL_Driver/Inc/stm32l5xx_hal_uart.h:1581:19: note: expected 'uint8_t * {aka unsigned char *}' but argument is of type 'char *'

HAL_StatusTypeDef HAL_UART_Transmit(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout);

^~~~~~~~~~~~~~~~~

../Core/Src/main.c:109:7: error: too few arguments to function 'HAL_UART_Transmit'

HAL_UART_Transmit (&hlpuart1, "\r\n to be switched to NS world.");

^~~~~~~~~~~~~~~~~

In file included from ../Core/Inc/stm32l5xx_hal_conf.h:402:0,

from ../../Drivers/STM32L5xx_HAL_Driver/Inc/stm32l5xx_hal.h:30,

from ../Core/Inc/main.h:31,

from ../Core/Src/main.c:21:

../../Drivers/STM32L5xx_HAL_Driver/Inc/stm32l5xx_hal_uart.h:1581:19: note: declared here

HAL_StatusTypeDef HAL_UART_Transmit(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout);

^~~~~~~~~~~~~~~~~

../Core/Src/main.c:111:6: warning: implicit declaration of function 'SECURE_RetargetISR' [-Wimplicit-function-declaration]

SECURE_RetargetISR (InputChar);

^~~~~~~~~~~~~~~~~~

../Core/Src/main.c:115:36: warning: pointer targets in passing argument 2 of 'HAL_UART_Transmit' differ in signedness [-Wpointer-sign]

HAL_UART_Transmit(&hlpuart1, "\r\n User Button has been switched to S world.");

^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

In file included from ../Core/Inc/stm32l5xx_hal_conf.h:402:0,

from ../../Drivers/STM32L5xx_HAL_Driver/Inc/stm32l5xx_hal.h:30,

from ../Core/Inc/main.h:31,

from ../Core/Src/main.c:21:

../../Drivers/STM32L5xx_HAL_Driver/Inc/stm32l5xx_hal_uart.h:1581:19: note: expected 'uint8_t * {aka unsigned char *}' but argument is of type 'char *'

HAL_StatusTypeDef HAL_UART_Transmit(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout);

^~~~~~~~~~~~~~~~~

../Core/Src/main.c:115:7: error: too few arguments to function 'HAL_UART_Transmit'

HAL_UART_Transmit(&hlpuart1, "\r\n User Button has been switched to S world.");

^~~~~~~~~~~~~~~~~

In file included from ../Core/Inc/stm32l5xx_hal_conf.h:402:0,

from ../../Drivers/STM32L5xx_HAL_Driver/Inc/stm32l5xx_hal.h:30,

from ../Core/Inc/main.h:31,

from ../Core/Src/main.c:21:

../../Drivers/STM32L5xx_HAL_Driver/Inc/stm32l5xx_hal_uart.h:1581:19: note: declared here

HAL_StatusTypeDef HAL_UART_Transmit(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout);

^~~~~~~~~~~~~~~~~

../Core/Src/main.c:117:36: warning: pointer targets in passing argument 2 of 'HAL_UART_Transmit' differ in signedness [-Wpointer-sign]

HAL_UART_Transmit(&hlpuart1, "\r\n User Button has been switched to NS world.");

^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

In file included from ../Core/Inc/stm32l5xx_hal_conf.h:402:0,

from ../../Drivers/STM32L5xx_HAL_Driver/Inc/stm32l5xx_hal.h:30,

from ../Core/Inc/main.h:31,

from ../Core/Src/main.c:21:

../../Drivers/STM32L5xx_HAL_Driver/Inc/stm32l5xx_hal_uart.h:1581:19: note: expected 'uint8_t * {aka unsigned char *}' but argument is of type 'char *'

HAL_StatusTypeDef HAL_UART_Transmit(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout);

^~~~~~~~~~~~~~~~~

../Core/Src/main.c:117:7: error: too few arguments to function 'HAL_UART_Transmit'

HAL_UART_Transmit(&hlpuart1, "\r\n User Button has been switched to NS world.");

^~~~~~~~~~~~~~~~~

In file included from ../Core/Inc/stm32l5xx_hal_conf.h:402:0,

from ../../Drivers/STM32L5xx_HAL_Driver/Inc/stm32l5xx_hal.h:30,

from ../Core/Inc/main.h:31,

from ../Core/Src/main.c:21:

../../Drivers/STM32L5xx_HAL_Driver/Inc/stm32l5xx_hal_uart.h:1581:19: note: declared here

HAL_StatusTypeDef HAL_UART_Transmit(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout);

^~~~~~~~~~~~~~~~~

../Core/Src/main.c:120:36: warning: pointer targets in passing argument 2 of 'HAL_UART_Transmit' differ in signedness [-Wpointer-sign]

HAL_UART_Transmit(&hlpuart1, "\r\n the same state, do nothing. \n");

^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

In file included from ../Core/Inc/stm32l5xx_hal_conf.h:402:0,

from ../../Drivers/STM32L5xx_HAL_Driver/Inc/stm32l5xx_hal.h:30,

from ../Core/Inc/main.h:31,

from ../Core/Src/main.c:21:

../../Drivers/STM32L5xx_HAL_Driver/Inc/stm32l5xx_hal_uart.h:1581:19: note: expected 'uint8_t * {aka unsigned char *}' but argument is of type 'char *'

HAL_StatusTypeDef HAL_UART_Transmit(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout);

^~~~~~~~~~~~~~~~~

../Core/Src/main.c:120:7: error: too few arguments to function 'HAL_UART_Transmit'

HAL_UART_Transmit(&hlpuart1, "\r\n the same state, do nothing. \n");

^~~~~~~~~~~~~~~~~

In file included from ../Core/Inc/stm32l5xx_hal_conf.h:402:0,

from ../../Drivers/STM32L5xx_HAL_Driver/Inc/stm32l5xx_hal.h:30,

from ../Core/Inc/main.h:31,

from ../Core/Src/main.c:21:

../../Drivers/STM32L5xx_HAL_Driver/Inc/stm32l5xx_hal_uart.h:1581:19: note: declared here

HAL_StatusTypeDef HAL_UART_Transmit(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout);

^~~~~~~~~~~~~~~~~

../Core/Src/main.c: In function 'HAL_GPIO_EXTI_Rising_Callback':

../Core/Src/main.c:293:21: error: 'LED_GREEN_GPIO_Port' undeclared (first use in this function); did you mean 'LED_BLUE_GPIO_Port'?

HAL_GPIO_TogglePin(LED_GREEN_GPIO_Port, LED_GREEN_Pin);

^~~~~~~~~~~~~~~~~~~

LED_BLUE_GPIO_Port

../Core/Src/main.c:293:42: error: 'LED_GREEN_Pin' undeclared (first use in this function); did you mean 'LED_BLUE_Pin'?

HAL_GPIO_TogglePin(LED_GREEN_GPIO_Port, LED_GREEN_Pin);

^~~~~~~~~~~~~

LED_BLUE_Pin

make: *** [Core/Src/subdir.mk:33: Core/Src/main.o] Error 1

"make -j8 all" terminated with exit code 2. Build might be incomplete.

08:02:08 Build Failed. 10 errors, 6 warnings. (took 665ms)

This post is from stm32/stm8
 
Personal signature

“Everyone wants the project to be good, fast, and cheap... pick two.”

- Unknown

 
 

305

Posts

0

Resources
6
 
This post was last edited by MianQi on 2021-1-8 17:44

The exploration of TrustZone continues. This time, I changed the machine and changed the operating system from Ubuntu 20.04 to Windows 10.

The test steps have also changed:

1. First use STM32CubeProgrammer to configure the option bytes, then use the independent STM32CubeMX for initial setup, and then enter STM32CubeIDE directly from the prompt of STM32CubeMX.

2. Enter the four code snippets in the example one by one, and build each time.

The test results show that the problem lies in the fourth section, which is the second section of code in the NS area.

This post is from stm32/stm8
 
Personal signature

“Everyone wants the project to be good, fast, and cheap... pick two.”

- Unknown

 
 

305

Posts

0

Resources
7
 

Latest progress: No error when building, but an error when running:

This post is from stm32/stm8
 
Personal signature

“Everyone wants the project to be good, fast, and cheap... pick two.”

- Unknown

 
 

305

Posts

0

Resources
8
 

New progress - you can run:

So, the User Button also takes effect: https://v.youku.com/v_show/id_XNTA3NDAxMDI2OA==.html

The current problem is that serial communication cannot be achieved. I tried Putty and VS Code, but neither of them can input keyboard or have dialogue. I am still looking for the reason.

This post is from stm32/stm8
 
Personal signature

“Everyone wants the project to be good, fast, and cheap... pick two.”

- Unknown

 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list