2 * FreeRTOS Kernel V10.3.0
\r
3 * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
\r
5 * Permission is hereby granted, free of charge, to any person obtaining a copy of
\r
6 * this software and associated documentation files (the "Software"), to deal in
\r
7 * the Software without restriction, including without limitation the rights to
\r
8 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
\r
9 * the Software, and to permit persons to whom the Software is furnished to do so,
\r
10 * subject to the following conditions:
\r
12 * The above copyright notice and this permission notice shall be included in all
\r
13 * copies or substantial portions of the Software.
\r
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
\r
17 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
\r
18 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
\r
19 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
22 * http://www.FreeRTOS.org
\r
23 * http://aws.amazon.com/freertos
\r
25 * 1 tab == 4 spaces!
\r
28 /* Device includes. */
\r
29 #include <arm_cmse.h>
\r
30 #include "NuMicro.h"
\r
32 /* FreeRTOS includes. */
\r
33 #include "FreeRTOS.h"
\r
36 /* Demo includes. */
\r
37 #include "tz_demo.h"
\r
38 #include "mpu_demo.h"
\r
40 /* Externs needed by the MPU setup code. These are defined in Scatter-Loading
\r
41 * description file (FreeRTOSDemo_ns.sct). */
\r
42 extern uint32_t Image$$ER_IROM_NS_PRIVILEGED$$Base;
\r
43 extern uint32_t Image$$ER_IROM_NS_PRIVILEGED_ALIGN$$Limit;
\r
44 extern uint32_t Image$$ER_IROM_NS_FREERTOS_SYSTEM_CALLS$$Base;
\r
45 extern uint32_t Image$$ER_IROM_NS_FREERTOS_SYSTEM_CALLS_ALIGN$$Limit;
\r
46 extern uint32_t Image$$ER_IROM_NS_UNPRIVILEGED$$Base;
\r
47 extern uint32_t Image$$ER_IROM_NS_UNPRIVILEGED_ALIGN$$Limit;
\r
49 extern uint32_t Image$$ER_IRAM_NS_PRIVILEGED$$Base;
\r
50 extern uint32_t Image$$ER_IRAM_NS_PRIVILEGED_ALIGN$$Limit;
\r
51 extern uint32_t Image$$ER_IRAM_NS_UNPRIVILEGED$$Base;
\r
52 extern uint32_t Image$$ER_IRAM_NS_UNPRIVILEGED_ALIGN$$Limit;
\r
54 /* Privileged flash. */
\r
55 const uint32_t * __privileged_functions_start__ = ( uint32_t * ) &( Image$$ER_IROM_NS_PRIVILEGED$$Base );
\r
56 const uint32_t * __privileged_functions_end__ = ( uint32_t * ) ( ( uint32_t ) &( Image$$ER_IROM_NS_PRIVILEGED_ALIGN$$Limit ) - 0x1 ); /* Last address in privileged Flash region. */
\r
58 /* Flash containing system calls. */
\r
59 const uint32_t * __syscalls_flash_start__ = ( uint32_t * ) &( Image$$ER_IROM_NS_FREERTOS_SYSTEM_CALLS$$Base );
\r
60 const uint32_t * __syscalls_flash_end__ = ( uint32_t * ) ( ( uint32_t ) &( Image$$ER_IROM_NS_FREERTOS_SYSTEM_CALLS_ALIGN$$Limit ) - 0x1 ); /* Last address in Flash region containing system calls. */
\r
62 /* Unprivileged flash. Note that the section containing system calls is
\r
63 * unprivileged so that unprivileged tasks can make system calls. */
\r
64 const uint32_t * __unprivileged_flash_start__ = ( uint32_t * ) &( Image$$ER_IROM_NS_UNPRIVILEGED$$Base );
\r
65 const uint32_t * __unprivileged_flash_end__ = ( uint32_t * ) ( ( uint32_t ) &( Image$$ER_IROM_NS_UNPRIVILEGED_ALIGN$$Limit ) - 0x1 ); /* Last address in un-privileged Flash region. */
\r
67 /* RAM with priviledged access only. This contains kernel data. */
\r
68 const uint32_t * __privileged_sram_start__ = ( uint32_t * ) &( Image$$ER_IRAM_NS_PRIVILEGED$$Base );
\r
69 const uint32_t * __privileged_sram_end__ = ( uint32_t * ) ( ( uint32_t ) &( Image$$ER_IRAM_NS_PRIVILEGED_ALIGN$$Limit ) - 0x1 ); /* Last address in privileged RAM. */
\r
71 /* Unprivileged RAM. */
\r
72 const uint32_t * __unprivileged_sram_start__ = ( uint32_t * ) &( Image$$ER_IRAM_NS_UNPRIVILEGED$$Base );
\r
73 const uint32_t * __unprivileged_sram_end__ = ( uint32_t * ) ( ( uint32_t ) &( Image$$ER_IRAM_NS_UNPRIVILEGED_ALIGN$$Limit ) - 0x1 ); /* Last address in un-privileged RAM. */
\r
74 /*-----------------------------------------------------------*/
\r
77 * @brief Create all demo tasks.
\r
79 static void prvCreateTasks( void );
\r
82 * @brief The hard fault handler.
\r
84 * It calls a function called vHandleMemoryFault.
\r
86 void HardFault_Handler( void ) __attribute__ ( ( naked ) );
\r
87 /*-----------------------------------------------------------*/
\r
89 /* For instructions on how to build and run this demo, visit the following link:
\r
90 * https://www.freertos.org/RTOS-Cortex-M23-NuMaker-PFM-M2351-Keil.html
\r
93 /* Non-Secure main. */
\r
96 /* Initialize debug port. */
\r
97 DEBUG_PORT->BAUD = UART_BAUD_MODE2 | UART_BAUD_MODE2_DIVIDER( __HIRC, 115200 );
\r
98 DEBUG_PORT->LINE = UART_WORD_LEN_8 | UART_PARITY_NONE | UART_STOP_BIT_1;
\r
100 /* Print banner. */
\r
102 printf( "+---------------------------------------------+\n" );
\r
103 printf( "| Nonsecure is running ... |\n" );
\r
104 printf( "+---------------------------------------------+\n" );
\r
106 /* Create tasks. */
\r
109 /* Start scheduler. */
\r
110 vTaskStartScheduler();
\r
112 /* Will not get here if the scheduler starts successfully. If you do end up
\r
113 here then there wasn't enough heap memory available to start either the idle
\r
114 task or the timer/daemon task. https://www.freertos.org/a00111.html */
\r
120 /*-----------------------------------------------------------*/
\r
122 static void prvCreateTasks( void )
\r
124 /* Create tasks for the MPU Demo. */
\r
127 /* Create tasks for the TZ Demo. */
\r
131 /*-----------------------------------------------------------*/
\r
133 /* Stack overflow hook. */
\r
134 void vApplicationStackOverflowHook( TaskHandle_t xTask, signed char *pcTaskName )
\r
136 /* Force an assert. */
\r
137 configASSERT( pcTaskName == 0 );
\r
139 /*-----------------------------------------------------------*/
\r
141 /* configUSE_STATIC_ALLOCATION is set to 1, so the application must provide an
\r
142 * implementation of vApplicationGetIdleTaskMemory() to provide the memory that
\r
143 * is used by the Idle task. */
\r
144 void vApplicationGetIdleTaskMemory( StaticTask_t ** ppxIdleTaskTCBBuffer,
\r
145 StackType_t ** ppxIdleTaskStackBuffer,
\r
146 uint32_t * pulIdleTaskStackSize )
\r
148 /* If the buffers to be provided to the Idle task are declared inside this
\r
149 * function then they must be declared static - otherwise they will be
\r
150 * allocated on the stack and so not exists after this function exits. */
\r
151 static StaticTask_t xIdleTaskTCB;
\r
152 static StackType_t uxIdleTaskStack[ configMINIMAL_STACK_SIZE ] __attribute__( ( aligned( 32 ) ) );
\r
154 /* Pass out a pointer to the StaticTask_t structure in which the Idle
\r
155 * task's state will be stored. */
\r
156 *ppxIdleTaskTCBBuffer = &xIdleTaskTCB;
\r
158 /* Pass out the array that will be used as the Idle task's stack. */
\r
159 *ppxIdleTaskStackBuffer = uxIdleTaskStack;
\r
161 /* Pass out the size of the array pointed to by *ppxIdleTaskStackBuffer.
\r
162 * Note that, as the array is necessarily of type StackType_t,
\r
163 * configMINIMAL_STACK_SIZE is specified in words, not bytes. */
\r
164 *pulIdleTaskStackSize = configMINIMAL_STACK_SIZE;
\r
166 /*-----------------------------------------------------------*/
\r
168 /* configUSE_STATIC_ALLOCATION and configUSE_TIMERS are both set to 1, so the
\r
169 * application must provide an implementation of vApplicationGetTimerTaskMemory()
\r
170 * to provide the memory that is used by the Timer service task. */
\r
171 void vApplicationGetTimerTaskMemory( StaticTask_t ** ppxTimerTaskTCBBuffer,
\r
172 StackType_t ** ppxTimerTaskStackBuffer,
\r
173 uint32_t * pulTimerTaskStackSize )
\r
175 /* If the buffers to be provided to the Timer task are declared inside this
\r
176 * function then they must be declared static - otherwise they will be
\r
177 * allocated on the stack and so not exists after this function exits. */
\r
178 static StaticTask_t xTimerTaskTCB;
\r
179 static StackType_t uxTimerTaskStack[ configTIMER_TASK_STACK_DEPTH ] __attribute__( ( aligned( 32 ) ) );
\r
181 /* Pass out a pointer to the StaticTask_t structure in which the Timer
\r
182 * task's state will be stored. */
\r
183 *ppxTimerTaskTCBBuffer = &xTimerTaskTCB;
\r
185 /* Pass out the array that will be used as the Timer task's stack. */
\r
186 *ppxTimerTaskStackBuffer = uxTimerTaskStack;
\r
188 /* Pass out the size of the array pointed to by *ppxTimerTaskStackBuffer.
\r
189 * Note that, as the array is necessarily of type StackType_t,
\r
190 * configTIMER_TASK_STACK_DEPTH is specified in words, not bytes. */
\r
191 *pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH;
\r
193 /*-----------------------------------------------------------*/
\r
195 void HardFault_Handler( void )
\r
202 " beq msp_used_for_stacking \n"
\r
204 " ldr r2, handler_address_const \n"
\r
206 "msp_used_for_stacking: \n"
\r
208 " ldr r2, handler_address_const \n"
\r
212 " handler_address_const: .word vHandleMemoryFault \n"
\r
215 /*-----------------------------------------------------------*/
\r