]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_MPU_M23_Nuvoton_NuMaker_PFM_M2351_IAR_GCC/Projects/Keil/NonSecure/main_ns.c
Do not strip required symbols when LTO is on
[freertos] / FreeRTOS / Demo / CORTEX_MPU_M23_Nuvoton_NuMaker_PFM_M2351_IAR_GCC / Projects / Keil / NonSecure / main_ns.c
1 /*\r
2  * FreeRTOS Kernel V10.2.0\r
3  * Copyright (C) 2019 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
4  *\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
11  *\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
14  *\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
21  *\r
22  * http://www.FreeRTOS.org\r
23  * http://aws.amazon.com/freertos\r
24  *\r
25  * 1 tab == 4 spaces!\r
26  */\r
27 \r
28 /* Device includes. */\r
29 #include <arm_cmse.h>\r
30 #include "NuMicro.h"\r
31 \r
32 /* FreeRTOS includes. */\r
33 #include "FreeRTOS.h"\r
34 #include "task.h"\r
35 \r
36 /* Demo includes. */\r
37 #include "tz_demo.h"\r
38 #include "mpu_demo.h"\r
39 \r
40 /* Externs needed by the MPU setup code. These must match the memory map as\r
41  * specified in Scatter-Loading description file (FreeRTOSDemo_ns.sct). */\r
42 /* Privileged flash. */\r
43 const uint32_t * __privileged_functions_start__         = ( uint32_t * ) ( 0x10040000 );\r
44 const uint32_t * __privileged_functions_end__           = ( uint32_t * ) ( 0x10047000 - 0x1 );  /* Last address in privileged Flash region. */\r
45 \r
46 /* Flash containing system calls. Note that the section containing system calls\r
47  * is unprivileged so that unprivileged tasks can make system calls.*/\r
48 const uint32_t * __syscalls_flash_start__                       = ( uint32_t * ) ( 0x10047000 );\r
49 const uint32_t * __syscalls_flash_end__                         = ( uint32_t * ) ( 0x10048000 - 0x1 );  /* Last address in Flash region containing system calls. */\r
50 \r
51 /* Unprivileged flash. */\r
52 const uint32_t * __unprivileged_flash_start__           = ( uint32_t * ) ( 0x10048000 );\r
53 const uint32_t * __unprivileged_flash_end__                     = ( uint32_t * ) ( 0x10080000 - 0x1 );  /* Last address in un-privileged Flash region. */\r
54 \r
55 /* Privileged RAM. It contains kernel data. */\r
56 const uint32_t * __privileged_sram_start__                      = ( uint32_t * ) ( 0x30008000 );\r
57 const uint32_t * __privileged_sram_end__                        = ( uint32_t * ) ( 0x30009000 - 0x1 );  /* Last address in privileged RAM. */\r
58 \r
59 /* Unprivileged RAM. */\r
60 const uint32_t * __unprivileged_sram_start__            = ( uint32_t * ) ( 0x30009000 );\r
61 const uint32_t * __unprivileged_sram_end__                      = ( uint32_t * ) ( 0x30018000 - 0x1 );  /* Last address in un-privileged RAM. */\r
62 /*-----------------------------------------------------------*/\r
63 \r
64 /**\r
65  * @brief Create all demo tasks.\r
66  */\r
67 static void prvCreateTasks( void );\r
68 \r
69 /**\r
70  * @brief The hard fault handler.\r
71  *\r
72  * It calls a function called vHandleMemoryFault.\r
73  */\r
74 void HardFault_Handler( void ) __attribute__ ( ( naked ) );\r
75 /*-----------------------------------------------------------*/\r
76 \r
77 static void prvCreateTasks( void )\r
78 {\r
79         /* Create tasks for the MPU Demo. */\r
80         vStartMPUDemo();\r
81 \r
82         /* Create tasks for the TZ Demo. */\r
83         vStartTZDemo();\r
84 \r
85 }\r
86 /*-----------------------------------------------------------*/\r
87 \r
88 /* Stack overflow hook. */\r
89 void vApplicationStackOverflowHook( TaskHandle_t xTask, signed char *pcTaskName )\r
90 {\r
91         /* Force an assert. */\r
92         configASSERT( pcTaskName == 0 );\r
93 }\r
94 /*-----------------------------------------------------------*/\r
95 \r
96 /* Non-Secure main. */\r
97 int main( void )\r
98 {\r
99         /* Initialize debug port. */\r
100         DEBUG_PORT->BAUD = UART_BAUD_MODE2 | UART_BAUD_MODE2_DIVIDER( __HIRC, 115200 );\r
101         DEBUG_PORT->LINE = UART_WORD_LEN_8 | UART_PARITY_NONE | UART_STOP_BIT_1;\r
102 \r
103         /* Print banner. */\r
104         printf( "\n" );\r
105         printf( "+---------------------------------------------+\n" );\r
106         printf( "|           Nonsecure is running ...          |\n" );\r
107         printf( "+---------------------------------------------+\n" );\r
108 \r
109         /* Create tasks. */\r
110         prvCreateTasks();\r
111 \r
112         /* Start scheduler. */\r
113         vTaskStartScheduler();\r
114 \r
115         /* Should not reach here as the schedular is already started. */\r
116         for( ; ; )\r
117         {\r
118         }\r
119 }\r
120 /*-----------------------------------------------------------*/\r
121 \r
122 /* configUSE_STATIC_ALLOCATION is set to 1, so the application must provide an\r
123  * implementation of vApplicationGetIdleTaskMemory() to provide the memory that\r
124  * is used by the Idle task. */\r
125 void vApplicationGetIdleTaskMemory(     StaticTask_t ** ppxIdleTaskTCBBuffer,\r
126                                                                         StackType_t ** ppxIdleTaskStackBuffer,\r
127                                                                         uint32_t * pulIdleTaskStackSize )\r
128 {\r
129         /* If the buffers to be provided to the Idle task are declared inside this\r
130          * function then they must be declared static - otherwise they will be\r
131          * allocated on the stack and so not exists after this function exits. */\r
132         static StaticTask_t xIdleTaskTCB;\r
133         static StackType_t uxIdleTaskStack[ configMINIMAL_STACK_SIZE ] __attribute__( ( aligned( 32 ) ) );\r
134 \r
135         /* Pass out a pointer to the StaticTask_t structure in which the Idle\r
136          * task's state will be stored. */\r
137         *ppxIdleTaskTCBBuffer = &xIdleTaskTCB;\r
138 \r
139         /* Pass out the array that will be used as the Idle task's stack. */\r
140         *ppxIdleTaskStackBuffer = uxIdleTaskStack;\r
141 \r
142         /* Pass out the size of the array pointed to by *ppxIdleTaskStackBuffer.\r
143          * Note that, as the array is necessarily of type StackType_t,\r
144          * configMINIMAL_STACK_SIZE is specified in words, not bytes. */\r
145         *pulIdleTaskStackSize = configMINIMAL_STACK_SIZE;\r
146 }\r
147 /*-----------------------------------------------------------*/\r
148 \r
149 /* configUSE_STATIC_ALLOCATION and configUSE_TIMERS are both set to 1, so the\r
150  * application must provide an implementation of vApplicationGetTimerTaskMemory()\r
151  * to provide the memory that is used by the Timer service task. */\r
152 void vApplicationGetTimerTaskMemory( StaticTask_t ** ppxTimerTaskTCBBuffer,\r
153                                                                          StackType_t ** ppxTimerTaskStackBuffer,\r
154                                                                          uint32_t * pulTimerTaskStackSize )\r
155 {\r
156         /* If the buffers to be provided to the Timer task are declared inside this\r
157          * function then they must be declared static - otherwise they will be\r
158          * allocated on the stack and so not exists after this function exits. */\r
159         static StaticTask_t xTimerTaskTCB;\r
160         static StackType_t uxTimerTaskStack[ configTIMER_TASK_STACK_DEPTH ] __attribute__( ( aligned( 32 ) ) );\r
161 \r
162         /* Pass out a pointer to the StaticTask_t structure in which the Timer\r
163          * task's state will be stored. */\r
164         *ppxTimerTaskTCBBuffer = &xTimerTaskTCB;\r
165 \r
166         /* Pass out the array that will be used as the Timer task's stack. */\r
167         *ppxTimerTaskStackBuffer = uxTimerTaskStack;\r
168 \r
169         /* Pass out the size of the array pointed to by *ppxTimerTaskStackBuffer.\r
170          * Note that, as the array is necessarily of type StackType_t,\r
171          * configTIMER_TASK_STACK_DEPTH is specified in words, not bytes. */\r
172         *pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH;\r
173 }\r
174 /*-----------------------------------------------------------*/\r
175 \r
176 void HardFault_Handler( void )\r
177 {\r
178         __asm volatile\r
179         (\r
180                 " movs r0, #4                                                                           \n"\r
181                 " mov r1, lr                                                                            \n"\r
182                 " tst r0, r1                                                                            \n"\r
183                 " beq msp_used_for_stacking                                                     \n"\r
184                 " mrs r0, psp                                                                           \n"\r
185                 " ldr r2, handler_address_const                                         \n"\r
186                 " bx r2                                                                                         \n"\r
187                 "msp_used_for_stacking:                                                         \n"\r
188                 "       mrs r0, msp                                                                             \n"\r
189                 "       ldr r2, handler_address_const                                   \n"\r
190                 "       bx r2                                                                                   \n"\r
191                 "                                                                                                       \n"\r
192                 " .align 4                                                                                      \n"\r
193                 " handler_address_const: .word vHandleMemoryFault       \n"\r
194         );\r
195 }\r
196 /*-----------------------------------------------------------*/\r