]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_MPU_M33F_NXP_LPC55S69_MCUXpresso/Projects/MCUXpresso/Secure/main_s.c
Add ARMv8M demo project for NXP LPC55S69.
[freertos] / FreeRTOS / Demo / CORTEX_MPU_M33F_NXP_LPC55S69_MCUXpresso / Projects / MCUXpresso / Secure / main_s.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 /* FreeRTOS includes. */\r
29 #include "secure_port_macros.h"\r
30 \r
31 /* Device includes. */\r
32 #include "fsl_device_registers.h"\r
33 #include "fsl_debug_console.h"\r
34 #include "arm_cmse.h"\r
35 #include "board.h"\r
36 #include "tzm_config.h"\r
37 #include "pin_mux.h"\r
38 #include "clock_config.h"\r
39 \r
40 #if ( __ARM_FEATURE_CMSE & 1 ) == 0\r
41         #error "Need ARMv8-M security extensions"\r
42 #elif ( __ARM_FEATURE_CMSE & 2 ) == 0\r
43         #error "Compile with --cmse"\r
44 #endif\r
45 \r
46 /* Start address of non-secure application. */\r
47 #define mainNONSECURE_APP_START_ADDRESS         ( 0x00010000UL )\r
48 \r
49 /* typedef for non-secure Reset Handler. */\r
50 typedef void ( *NonSecureResetHandler_t ) ( void ) __attribute__( ( cmse_nonsecure_call ) );\r
51 /*-----------------------------------------------------------*/\r
52 \r
53 /**\r
54  * @brief Boots into the non-secure code.\r
55  *\r
56  * @param[in] ulNonSecureStartAddress Start address of the non-secure application.\r
57  */\r
58 static void prvBootNonSecure( uint32_t ulNonSecureStartAddress );\r
59 \r
60 /**\r
61  * @brief Application-specific implementation of the SystemInitHook() weak\r
62  * function.\r
63  */\r
64 void SystemInitHook( void );\r
65 /*-----------------------------------------------------------*/\r
66 \r
67 static void prvBootNonSecure( uint32_t ulNonSecureStartAddress )\r
68 {\r
69         NonSecureResetHandler_t pxNonSecureResetHandler;\r
70 \r
71         /* Setup the non-secure vector table. */\r
72         SCB_NS->VTOR = ulNonSecureStartAddress;\r
73 \r
74         /* Main Stack Pointer value for the non-secure side is the first entry in\r
75          * the non-secure vector table. Read the first entry and assign the same to\r
76          * the non-secure main stack pointer(MSP_NS). */\r
77         secureportSET_MSP_NS( *( ( uint32_t * )( ulNonSecureStartAddress ) ) );\r
78 \r
79         /* Reset Handler for the non-secure side is the second entry in the\r
80          * non-secure vector table. Read the second entry to get the non-secure\r
81          * Reset Handler. */\r
82         pxNonSecureResetHandler = ( NonSecureResetHandler_t )( * ( ( uint32_t * ) ( ( ulNonSecureStartAddress ) + 4U ) ) );\r
83 \r
84         /* Start non-secure state software application by jumping to the non-secure\r
85          * Reset Handler. */\r
86         pxNonSecureResetHandler();\r
87 }\r
88 /*-----------------------------------------------------------*/\r
89 \r
90 void SystemInitHook( void )\r
91 {\r
92         /* Set CP10 and CP11 full access from Non-Secure code. */\r
93         SCB_NS->CPACR |= ( ( 3UL << 10 * 2 ) | ( 3UL << 11 * 2 ) );\r
94 \r
95         /* The TrustZone should be configured as early as possible after RESET.\r
96          * Therefore it is called from SystemInit() during startup. The\r
97          * SystemInitHook() weak function overloading is used for this purpose.\r
98          */\r
99         BOARD_InitTrustZone();\r
100 }\r
101 /*-----------------------------------------------------------*/\r
102 \r
103 /* Secure main(). */\r
104 int main(void)\r
105 {\r
106         PRINTF( "Booting Secure World.\r\n" );\r
107 \r
108         /* Attach main clock divide to FLEXCOMM0 (debug console). */\r
109         CLOCK_AttachClk( BOARD_DEBUG_UART_CLK_ATTACH );\r
110 \r
111         /* Init board hardware. */\r
112         BOARD_InitPins();\r
113         BOARD_BootClockFROHF96M();\r
114         BOARD_InitDebugConsole();\r
115 \r
116         /* Boot the non-secure code. */\r
117         PRINTF( "Booting Non-Secure World.\r\n" );\r
118         prvBootNonSecure( mainNONSECURE_APP_START_ADDRESS );\r
119 \r
120         /* Non-secure software does not return, this code is not executed. */\r
121         for( ; ; )\r
122         {\r
123                 /* Should not reach here. */\r
124         }\r
125 }\r
126 /*-----------------------------------------------------------*/\r