ARM Cortex-M23 (ARMv8-M) Demo for Nuvoton NuMaker-PFM-M2351 Board
Using Keil uVision and IAR IDEs
[RTOS Ports]



This page documents pre-configured FreeRTOS projects that target the ARM Cortex-M23 core on the Nuvoton NuMaker-PFM-M2351 board.

Two projects are provided:

  1. An IAR Embedded Workbench project that uses the IAR compiler.
  2. A Keil uVision project that uses the armclang compiler.
The projects demonstrate using the ARM Cortex-M23 TrustZone and the ARM Cortex-M23 Memory Protection Unit (MPU).



IMPORTANT! Notes on using the FreeRTOS ARM Cortex-M23 port

Please read all the following points before using this RTOS port.

  1. Source Code Organization
  2. The Demo Application
  3. Building and Running the RTOS Demo Application
  4. RTOS Configuration and Usage Details
Also see the FAQ My application does not run, what could be wrong?.



Source Code Organization

The FreeRTOS zip file download contains the source code for all the FreeRTOS ports, and every demo application. That means it contains many more files than are required to use the FreeRTOS ARMv8-M Cortex-M23 port. See the Source Code Organization page for information on the zip file’s directory structure. The project files for this demo are organized as follows:

  • The IAR Embedded Workbench project file is located in FreeRTOS/Demo/CORTEX_MPU_M23_Nuvoton_NuMaker_PFM_M2351_IAR_GCC/Projects/IAR directory and is named FreeRTOSDemo.eww. This IAR workspace contains two projects – one for the secure side of the ARM Cortex-M23 core, and one for the non-secure side. The FreeRTOS ARMv8-M Cortex-M23 port files compiled in these two projects are organized as follows:

    • Port files compiled in the secure project are in the FreeRTOS/Source/portable/IAR/ARM_CM23/secure directory.
    • Port files compiled in the non-secure project are in the FreeRTOS/Source/portable/IAR/ARM_CM23/non_secure directory.

  • The Keil uVision project file is located in FreeRTOS/Demo/CORTEX_MPU_M23_Nuvoton_NuMaker_PFM_M2351_IAR_GCC/Projects/Keil directory and is named FreeRTOSDemo.uvmpw. This Keil multi-project workspace contains two projects – one for the secure side of the ARM Cortex-M23 core, and one for the non-secure side. The FreeRTOS ARMv8-M Cortex-M23 port files compiled in these two projects are organized as follows:

    • Port files compiled in the secure project are in the FreeRTOS/Source/portable/GCC/ARM_CM23/secure directory.
    • Port files compiled in the non-secure project are in the FreeRTOS/Source/portable/GCC/ARM_CM23/non_secure directory.



The Demo Application

The projects include two demos:
  1. TrustZone Demo
  2. Memory Protection Unit (MPU) Demo

TrustZone Demo

The TrustZone demo demonstrates how to export functions from the secure side of the ARM Cortex-M23 core, and how to call them from RTOS tasks on the non-secure side.
  • NonSecure Callable Function:

    The following function is exported from the secure side and is marked as non-secure callable:

    secureportNON_SECURE_CALLABLE uint32_t NSCFunction( Callback_t pxCallback )

    Note the use of secureportNON_SECURE_CALLABLE macro to mark the function as non-secure callable. This function accepts a callback as argument. It first invokes the callback function supplied as argument and then increments a secure side counter. The incremented value of the secure side counter is returned to the caller.

  • NonSecure Callback:

    The following function is implemented on the non-secure side and is passed to the above mentioned non-secure callable function as argument:

    void prvCallback( void )

    This function increments a non-secure counter.

  • Secure Calling Task:

    An un-privileged non-secure task is created using the xTaskCreateRestricted() API. This task first calls portALLOCATE_SECURE_CONTEXT to allocate itself a secure context – any non-secure task which wants to call a function exported from the secure side must allocate itself a secure context by calling portALLOCATE_SECURE_CONTEXT.

    The task then calls the secure side function and passes the non-secure callback as the argument. The non-secure counter is incremented in the callback and the secure counter is incremented in the secure function. Therefore, both the counters must be incremented after the call to the secure function is complete – this is ensured using configASSERT(). The task sleeps for one second and then repeats the same.

TrustZone Demo Call Sequence
The TrustZone Demo Call Sequence

Memory Protection Unit (MPU) Demo

The MPU demo demonstrates how to use the MPU to grant a task different access permissions for various memory regions. The MPU demo consists of the following two tasks:
  • RW Task:

    The RW task has Read-Write access to a shared region of memory (namely ucSharedMemory).

  • RO Task:

    The RO task has Read-Only access to the same shared region of memory (namely ucSharedMemory). This task tries to write to the shared memory and since it has read only permission to the shared memory, it results in a hard fault. The fault handler checks if it is the expected fault from the RO task and if so, it recovers gracefully by incrementing the Program Counter to the next statement.



Building and Running the RTOS Demo Application

Using IAR Embedded Workbench IDE

  1. Download and install the Nu-Link IAR Driver:

    • Go to the following page: Nuvoton NuMaker-PFM-M2351
    • Click on the Resources tab.
    • Scroll down to the Software section and download the file named Nu-Link_IAR_Driver_Vx.xx.xxxx.
    • Unzip and install.

  2. Double click the FreeRTOS/Demo/CORTEX_MPU_M23_Nuvoton_NuMaker_PFM_M2351_IAR_GCC/Projects/IAR/FreeRTOSDemo.eww file to open it in the IAR Embedded Workbench IDE. The IAR workspace FreeRTOSDemo.eww contains a secure project (FreeRTOSDemo_s) and a non-secure project (FreeRTOSDemo_ns).

  3. Build the secure project by right clicking “FreeRTOSDemo_s – Release” and then clicking “Make”.

    IAR Embedded Workbench IDE - Build Secure Project
    IAR Embedded Workbench IDE – Build Secure Project. Click to enlarge.


  4. Build the non-secure project by right clicking “FreeRTOSDemo_ns – Release” and then clicking “Make”.

    IAR Embedded Workbench IDE - Build Non-Secure Project
    IAR Embedded Workbench IDE – Build Non-Secure Project. Click to enlarge.


  5. Set the non-secure project as active by right clicking on “FreeRTOSDemo_ns – Release” and then clicking “Set as Active”.

    IAR Embedded Workbench IDE - Set Non-Secure Project Active
    IAR Embedded Workbench IDE – Set Non-Secure Project Active. Click to enlarge.


  6. Flash the non-secure binary by clicking “Project –> Download –> Download active application”.

    IAR Embedded Workbench IDE - Flash the Non-Secure Binary
    IAR Embedded Workbench IDE – Flash the Non-Secure Binary. Click to enlarge.


  7. Set the secure project as active by right clicking on “FreeRTOSDemo_s – Release” and then clicking “Set as Active”.

    IAR Embedded Workbench IDE - Set Secure Project Active
    IAR Embedded Workbench IDE – Set Secure Project Active. Click to enlarge.


  8. Flash the secure binary by clicking “Project –> Download –> Download active application”.

    IAR Embedded Workbench IDE - Flash the Secure Binary
    IAR Embedded Workbench IDE – Flash the Secure Binary. Click to enlarge.


  9. Start the Debug Session by clicking “Project –> Download and Debug”.

    IAR Embedded Workbench IDE - Start Debug Session
    IAR Embedded Workbench IDE – Start Debug Session. Click to enlarge.



Using Keil uVision IDE

  1. Download and install the Nu-Link Keil Driver:

    • Go to the following page: Nuvoton NuMaker-PFM-M2351
    • Click on the Resources tab.
    • Scroll down to the Software section and download the file named Nu-Link_Keil_Driver_Vx.xx.xxxx.
    • Unzip and install.

  2. Double click the FreeRTOS/Demo/CORTEX_MPU_M23_Nuvoton_NuMaker_PFM_M2351_IAR_GCC/Projects/Keil/FreeRTOSDemo.uvmpw file to open it in the Keil uVision IDE. The Keil multi-project workspace FreeRTOSDemo.uvmpw contains a secure project (FreeRTOSDemo_s) and a non-secure project (FreeRTOSDemo_ns).

  3. Set the secure project as active by right clicking on “Project: FreeRTOSDemo_s” and selecting “Set as Active Project”.

    Keil uVision IDE - Set Secure Project Active
    Keil uVision IDE – Set Secure Project Active. Click to enlarge.


  4. Build the secure project by clicking “Project –> Build ‘FreeRTOSDemo_s (FreeRTOSDemo_s)'”.

    Keil uVision IDE - Build Secure Project
    Keil uVision IDE – Build Secure Project. Click to enlarge.


  5. Open the Options Window for the secure project by clicking “Project –> Options for FreeRTOSDemo_s – Target ‘FreeRTOSDemo_s’…”.

    Keil uVision IDE - Open Secure Project Options
    Keil uVision IDE – Open Secure Project Options. Click to enlarge.


  6. Open the Nu-Link Driver Setup Window by clicking “Settings” button next to the “/wp-content/uploads/2019/05/Nuvoton Nu-Link Debugger” in the Debug tab.

    Keil uVision IDE - Open Nu-Link Driver Setup
    Keil uVision IDE – Open Nu-Link Driver Setup. Click to enlarge.


  7. Select “M2351” in the “Chip Type” dropdown.

    Keil uVision IDE - Select M2351
    Keil uVision IDE – Select M2351. Click to enlarge.


  8. Dismiss “Nu-Link Driver Setup” and “Options” Windows by clicking “OK” on both the windows.

  9. Set the non-secure project as active by right clicking on “Project: FreeRTOSDemo_ns” and selecting “Set as Active Project”.

    Keil uVision IDE - Set Non-Secure Project Active
    Keil uVision IDE – Set Non-Secure Project Active. Click to enlarge.


  10. Build the non-secure project by clicking “Project –> Build ‘FreeRTOSDemo_ns (FreeRTOSDemo_ns)'”.

    Keil uVision IDE - Build Non-Secure Project
    Keil uVision IDE – Build Non-Secure Project. Click to enlarge.


  11. Open the Options Window for the non-secure project by clicking “Project –> Options for FreeRTOSDemo_ns – Target ‘FreeRTOSDemo_ns’…”.

    Keil uVision IDE - Open Non-Secure Project Options
    Keil uVision IDE – Open Non-Secure Project Options. Click to enlarge.


  12. Open the Nu-Link Driver Setup Window by clicking “Settings” button next to the “/wp-content/uploads/2019/05/Nuvoton Nu-Link Debugger” in the Debug tab.

    Keil uVision IDE - Open Nu-Link Driver Setup
    Keil uVision IDE – Open Nu-Link Driver Setup. Click to enlarge.


  13. Select “M2351” in the “Chip Type” dropdown.

    Keil uVision IDE - Select M2351
    Keil uVision IDE – Select M2351. Click to enlarge.


  14. Dismiss “Nu-Link Driver Setup” and “Options” Windows by clicking “OK” on both the windows.

  15. Flash the non-secure binary by clicking “Flash –> Download”.

    Keil uVision IDE - Flash the Non-Secure Binary
    Keil uVision IDE – Flash the Non-Secure Binary. Click to enlarge.


  16. Set the secure project as active by right clicking on “Project: FreeRTOSDemo_s” and selecting “Set as Active Project”.

    Keil uVision IDE - Set Secure Project Active
    Keil uVision IDE – Set Secure Project Active. Click to enlarge.


  17. Flash the secure binary by clicking “Flash –> Download”.

    Keil uVision IDE - Flash the Secure Binary
    Keil uVision IDE – Flash the Secure Binary. Click to enlarge.


  18. Start the Debug Session by clicking “Debug –> Start/Stop Debug Session”.

    Keil uVision IDE - Start Debug Session
    Keil uVision IDE – Start Debug Session. Click to enlarge.




RTOS Configuration and Usage Details

  • Configuration items specific to this demo are contained in FreeRTOS/Demo/CORTEX_MPU_M23_Nuvoton_NuMaker_PFM_M2351_IAR_GCC/Projects/Keil/ConfigFreeRTOSConfig.h for the Keil uVision IDE project and in FreeRTOS/Demo/CORTEX_MPU_M23_Nuvoton_NuMaker_PFM_M2351_IAR_GCC/Projects/IAR/ConfigFreeRTOSConfig.h for the IAR Embedded Workbench IDE project. The constants defined in that file can be edited to suit your application. The following configuration options are specific to the ARM Cortex-M23 port:

    • configENABLE_MPU – Enable/Disable Memory Protection Unit (MPU).
    • configENABLE_TRUSTZONE – Enable/Disable TrustZone.

  • If you want to run FreeRTOS with TrustZone disabled, set configENABLE_TRUSTZONE to 0 in your FreeRTOSConfig.h and use the FreeRTOS port files in the FreeRTOS/Source/portable/GCC/ARM_CM23_NTZ directory for GCC and in the FreeRTOS/Source/portable/IAR/ARM_CM23_NTZ directory for IAR.

  • If you want to run FreeRTOS on the secure side, set configENABLE_TRUSTZONE to 0 and configRUN_FREERTOS_SECURE_ONLY to 1 in your FreeRTOSConfig.h and use the FreeRTOS port files in the FreeRTOS/Source/portable/GCC/ARM_CM23_NTZ directory for GCC and in the FreeRTOS/Source/portable/IAR/ARM_CM23_NTZ directory for IAR.

  • Source/Portable/MemMang/heap_4.c is included in the project to provide the memory allocation required by the RTOS kernel. Please refer to the Memory Management section of the API documentation for full information.

  • vPortEndScheduler() has not been implemented.



Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

FreeRTOS v10.2.1 is available for immediate download. MIT licensed, includes 64-bit RISC-V, NXP Cortex-M33 demo & Nuvoton Cortex-M23 demo & STM32H745 dual core (AMP) demo.

Watch for updates in the coming months as we add new IoT-related functionality and improved website navigation and resources

View a recording of the “OTA Update Security and Reliability” webinar, presented by TI and AWS.

Careers

FreeRTOS and other embedded software careers at AWS.

FreeRTOS Partners
ARM Connected RTOS partner for all ARM microcontroller cores
Espressif ESP32
IAR Partner
Microchip Premier RTOS Partner
Renesas
STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0
Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers
OpenRTOS and SafeRTOS
Xilinx Microblaze and Zynq partner

Profile