1 /***********************************************************************************************************************
2 * Copyright [2020-2021] Renesas Electronics Corporation and/or its affiliates. All Rights Reserved.
3 *
4 * This software and documentation are supplied by Renesas Electronics America Inc. and may only be used with products
5 * of Renesas Electronics Corp. and its affiliates ("Renesas"). No other uses are authorized. Renesas products are
6 * sold pursuant to Renesas terms and conditions of sale. Purchasers are solely responsible for the selection and use
7 * of Renesas products and Renesas assumes no liability. No license, express or implied, to any intellectual property
8 * right is granted by Renesas. This software is protected under all applicable laws, including copyright laws. Renesas
9 * reserves the right to change or discontinue this software and/or this documentation. THE SOFTWARE AND DOCUMENTATION
10 * IS DELIVERED TO YOU "AS IS," AND RENESAS MAKES NO REPRESENTATIONS OR WARRANTIES, AND TO THE FULLEST EXTENT
11 * PERMISSIBLE UNDER APPLICABLE LAW, DISCLAIMS ALL WARRANTIES, WHETHER EXPLICITLY OR IMPLICITLY, INCLUDING WARRANTIES
12 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT, WITH RESPECT TO THE SOFTWARE OR
13 * DOCUMENTATION. RENESAS SHALL HAVE NO LIABILITY ARISING OUT OF ANY SECURITY VULNERABILITY OR BREACH. TO THE MAXIMUM
14 * EXTENT PERMITTED BY LAW, IN NO EVENT WILL RENESAS BE LIABLE TO YOU IN CONNECTION WITH THE SOFTWARE OR DOCUMENTATION
15 * (OR ANY PERSON OR ENTITY CLAIMING RIGHTS DERIVED FROM YOU) FOR ANY LOSS, DAMAGES, OR CLAIMS WHATSOEVER, INCLUDING,
16 * WITHOUT LIMITATION, ANY DIRECT, CONSEQUENTIAL, SPECIAL, INDIRECT, PUNITIVE, OR INCIDENTAL DAMAGES; ANY LOST PROFITS,
17 * OTHER ECONOMIC DAMAGE, PROPERTY DAMAGE, OR PERSONAL INJURY; AND EVEN IF RENESAS HAS BEEN ADVISED OF THE POSSIBILITY
18 * OF SUCH LOSS, DAMAGES, CLAIMS OR COSTS.
19 **********************************************************************************************************************/
20
21 /*******************************************************************************************************************//**
22 * @addtogroup BSP_MCU
23 * @{
24 **********************************************************************************************************************/
25
26 /***********************************************************************************************************************
27 * Includes <System Includes> , "Project Includes"
28 **********************************************************************************************************************/
29 #include "bsp_api.h"
30
31 /***********************************************************************************************************************
32 * Macro definitions
33 **********************************************************************************************************************/
34 #if BSP_TZ_SECURE_BUILD
35 #define BSP_TZ_STACK_SEAL_SIZE (8U)
36 #else
37 #define BSP_TZ_STACK_SEAL_SIZE (0U)
38 #endif
39
40 /***********************************************************************************************************************
41 * Typedef definitions
42 **********************************************************************************************************************/
43
44 /* Defines function pointers to be used with vector table. */
45 typedef void (* exc_ptr_t)(void);
46
47 /***********************************************************************************************************************
48 * Exported global variables (to be accessed by other files)
49 **********************************************************************************************************************/
50
51 /***********************************************************************************************************************
52 * Private global variables and functions
53 **********************************************************************************************************************/
54 void Reset_Handler(void);
55 void Default_Handler(void);
56 int32_t main(void);
57
58 /*******************************************************************************************************************//**
59 * MCU starts executing here out of reset. Main stack pointer is set up already.
60 **********************************************************************************************************************/
Reset_Handler(void)61 void Reset_Handler (void)
62 {
63 /* Initialize system using BSP. */
64 SystemInit();
65
66 /* Call user application. */
67 #ifdef __ARMCC_VERSION
68 main();
69 #elif defined(__GNUC__)
70 extern int entry(void);
71 entry();
72 #endif
73
74 while (1)
75 {
76 /* Infinite Loop. */
77 }
78 }
79
80 /*******************************************************************************************************************//**
81 * Default exception handler.
82 **********************************************************************************************************************/
Default_Handler(void)83 void Default_Handler (void)
84 {
85 /** A error has occurred. The user will need to investigate the cause. Common problems are stack corruption
86 * or use of an invalid pointer. Use the Fault Status window in e2 studio or manually check the fault status
87 * registers for more information.
88 */
89 BSP_CFG_HANDLE_UNRECOVERABLE_ERROR(0);
90 }
91
92 /* Main stack */
93 static uint8_t g_main_stack[BSP_CFG_STACK_MAIN_BYTES + BSP_TZ_STACK_SEAL_SIZE] BSP_ALIGN_VARIABLE(BSP_STACK_ALIGNMENT)
94 BSP_PLACE_IN_SECTION(BSP_SECTION_STACK);
95
96 /* Heap */
97 #if (BSP_CFG_HEAP_BYTES > 0)
98
99 BSP_DONT_REMOVE static uint8_t g_heap[BSP_CFG_HEAP_BYTES] BSP_ALIGN_VARIABLE(BSP_STACK_ALIGNMENT) \
100 BSP_PLACE_IN_SECTION(BSP_SECTION_HEAP);
101 #endif
102
103 /* All system exceptions in the vector table are weak references to Default_Handler. If the user wishes to handle
104 * these exceptions in their code they should define their own function with the same name.
105 */
106 #if defined(__ICCARM__)
107 #define WEAK_REF_ATTRIBUTE
108
109 #pragma weak HardFault_Handler = Default_Handler
110 #pragma weak MemManage_Handler = Default_Handler
111 #pragma weak BusFault_Handler = Default_Handler
112 #pragma weak UsageFault_Handler = Default_Handler
113 #pragma weak SecureFault_Handler = Default_Handler
114 #pragma weak SVC_Handler = Default_Handler
115 #pragma weak DebugMon_Handler = Default_Handler
116 #pragma weak PendSV_Handler = Default_Handler
117 #pragma weak SysTick_Handler = Default_Handler
118 #elif defined(__GNUC__)
119
120 #define WEAK_REF_ATTRIBUTE __attribute__((weak, alias("Default_Handler")))
121 #endif
122
123 void NMI_Handler(void); // NMI has many sources and is handled by BSP
124 void HardFault_Handler(void) WEAK_REF_ATTRIBUTE;
125 void MemManage_Handler(void) WEAK_REF_ATTRIBUTE;
126 void BusFault_Handler(void) WEAK_REF_ATTRIBUTE;
127 void UsageFault_Handler(void) WEAK_REF_ATTRIBUTE;
128 void SecureFault_Handler(void) WEAK_REF_ATTRIBUTE;
129 void SVC_Handler(void) WEAK_REF_ATTRIBUTE;
130 void DebugMon_Handler(void) WEAK_REF_ATTRIBUTE;
131 void PendSV_Handler(void) WEAK_REF_ATTRIBUTE;
132 void SysTick_Handler(void) WEAK_REF_ATTRIBUTE;
133
134 /* Vector table. */
135 BSP_DONT_REMOVE const exc_ptr_t __Vectors[BSP_CORTEX_VECTOR_TABLE_ENTRIES] BSP_PLACE_IN_SECTION(
136 BSP_SECTION_FIXED_VECTORS) =
137 {
138 (exc_ptr_t) (&g_main_stack[0] + BSP_CFG_STACK_MAIN_BYTES), /* Initial Stack Pointer */
139 Reset_Handler, /* Reset Handler */
140 NMI_Handler, /* NMI Handler */
141 HardFault_Handler, /* Hard Fault Handler */
142 MemManage_Handler, /* MPU Fault Handler */
143 BusFault_Handler, /* Bus Fault Handler */
144 UsageFault_Handler, /* Usage Fault Handler */
145 SecureFault_Handler, /* Secure Fault Handler */
146 0, /* Reserved */
147 0, /* Reserved */
148 0, /* Reserved */
149 SVC_Handler, /* SVCall Handler */
150 DebugMon_Handler, /* Debug Monitor Handler */
151 0, /* Reserved */
152 PendSV_Handler, /* PendSV Handler */
153 SysTick_Handler, /* SysTick Handler */
154 };
155
156 /** @} (end addtogroup BSP_MCU) */
157