CMSIS-Zone: Nuvoton NuMicro M2351

| CMSIS-Zone Version 1.2.0-alpha System Resource Management

- Main Page
- Usage and Description

All Files Pages
Nuvoton NuMicro M2351

This single processor demo application shows how to do the TrustZone Partitioning. It is split into a secure and non-secure part. Some peripherals are assigned to either the secure or the non-secure zone to demonstrate the generation of PPC setup and interrupt configuration in the partition.h template. Using CMSIS-Zone, it generates:

- A header file that contains #defines to control the various linker scatter files (and might be used in other parts of the application).
- Secure attribution unit (SAU) setup.

The application itself shows how to implement calls between the secure and the non-secure part and how to use this to blink an LED.

# Using the CMSIS-Zone project

- Import the project "Examples\M2351\Zone" into the CMSIS-Zone utility
- Open the M2351.azone file
- Generate the related output files

The M2351.azone file of that project has the following configuration settings:

- Added the zones `Secure` and `NonSecure`
- Created the memory regions `CODE_NS`, `CODE_S`, `Veneer`, `DATA_NS`, and `DATA_S`
- Selected various memory regions and peripherals for using in the different zones:

The zones use different Flash and SRAM regions for code and data. To generate the output, click on the Generate button in the Zone Editor tool bar. This creates the following files in the `ftl_gen` directory:

Template File | Generated File | Description
--- | --- | ---
helper.ftlinc | N/A | Helper template file with FTL functions.
mem_layout.h.ftl | mem_layout.h | Header file that contains the memory region definitions, for example for the linker scatter file.
partition_gen.h.ftl | partition_gen.h | Configuration of the secure attribution unit (SAU) and the NVIC interrupt assignment.
scatter_ns.sct.ftl | scatter_ns.sct | Example scatter file for the non-secure zone.
scatter_s.sct.ftl | scatter_s.sct | Example scatter file for the secure zone.

These files can be used in any IDE to create the final application. In the following, the usage in Arm Keil MDK is described.

# Using the MDK project

The example project can be loaded, built and debugged in µVision by performing the following steps:

1. Navigate to Examples/M2351/MDK
2. Open the multi-project workspace TrustZone.uvmpw
3. Optional: Update the generated files by executing the copy_gen.bat scripts in Secure\mdk and NonSecure\mdk folders.
4. Run the batch build in MDK. Both projects, Secure and NonSecure need to be compiled in order.
5. Set `Secure` as active project.
6. Connect the NuMaker-PFM-M2351 board using a Micro-USB cable at ICEJ.
7. Open Options for Target - Debug and make sure that the NULink Debugger is selected.
8. Launch a debug session and watch LEDG and LEDY blinking.

# MDK project setup

The multiproject workspace contains the `Secure` project and the `NonSecure` project:

The projects use the files generated in CMSIS-Zone as follows:

File | Used in | Description
--- | --- | ---
mem_layout.h | Secure, NonSecure | Input for the scatter files.
partition_gen.h | Secure | Configuration of the secure attribution unit (SAU) and the NVIC interrupt assignment.
scatter_ns.sct | NonSecure | Scatter file for non-secure zone (initally based on generated file).
scatter_s.sct | Secure | Scatter file for secure zone (initally based on generated file).

The scatter files `scatter_s.sct` and `scatter_ns.sct` are using a preinclude to mem_layout.h to get the information about the different memory regions.

Note
  If you want to learn more about the general project layout for an Armv8-M project using TrustZone, refer to Application Note 291.

## scatter_s.sct

As explained previously, the #defines in `mem_layout.h` can be used to create generic scatter files that are easy to update once changes in the CMSIS-Zone project happen. Using the mem_layout.h file from CMSIS-Zone, the following scatter file is used in the `Sections` project:

#! armclang -E --target=arm-arm-none-eabi -mcpu=cortex-m23 -I../ -xc
#include "mem_layout.h"
; *------- <<< Use Configuration Wizard in Context Menu >>> ------------------
;<h> Stack Configuration
; <o> Stack Size (in Bytes) <0x0-0xFFFFFFFF:8>
;</h>
#define STACK_SIZE 0x400
;<h> Heap Configuration
; <o> Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
;</h>
#define HEAP_SIZE 0xC00
; *-------------- <<< end of configuration section >>> -----------------------
LR_CODE_S REGION_CODE_S_START REGION_CODE_S_SIZE {
ER_CODE_S REGION_CODE_S_START REGION_CODE_S_SIZE {
(RESET,+FIRST)
(InRoot$$Sections)
.ANY (+RO +XO)
}
RW_DATA_S REGION_DATA_S_START REGION_DATA_S_SIZE-HEAP_SIZE-STACK_SIZE {
.ANY (+RW +ZI)
}
#if HEAP_SIZE>0
ARM_LIB_HEAP REGION_DATA_S_START+REGION_DATA_S_SIZE-HEAP_SIZE-STACK_SIZE EMPTY HEAP_SIZE {
}
#endif
#if STACK_SIZE>0
ARM_LIB_STACK REGION_DATA_S_START+REGION_DATA_S_SIZE-STACK_SIZE EMPTY STACK_SIZE {
}
#endif
}
LR_VENEER REGION_VENEER_START REGION_VENEER_SIZE {
ER_VENEER REGION_VENEER_START REGION_VENEER_SIZE {
(Veneer$$CMSE)
}
}