1 /***********************************************************************************************************************
2 * Copyright [2020-2022] 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 main();
68
69 while (1)
70 {
71 /* Infinite Loop. */
72 }
73 }
74
75 /*******************************************************************************************************************//**
76 * Default exception handler.
77 **********************************************************************************************************************/
Default_Handler(void)78 void Default_Handler (void)
79 {
80 /** A error has occurred. The user will need to investigate the cause. Common problems are stack corruption
81 * or use of an invalid pointer. Use the Fault Status window in e2 studio or manually check the fault status
82 * registers for more information.
83 */
84 BSP_CFG_HANDLE_UNRECOVERABLE_ERROR(0);
85 }
86
87 /* Main stack */
88 static uint8_t g_main_stack[BSP_CFG_STACK_MAIN_BYTES + BSP_TZ_STACK_SEAL_SIZE] BSP_ALIGN_VARIABLE(BSP_STACK_ALIGNMENT)
89 BSP_PLACE_IN_SECTION(BSP_SECTION_STACK);
90
91 /* Heap */
92 #if (BSP_CFG_HEAP_BYTES > 0)
93
94 BSP_DONT_REMOVE static uint8_t g_heap[BSP_CFG_HEAP_BYTES] BSP_ALIGN_VARIABLE(BSP_STACK_ALIGNMENT) \
95 BSP_PLACE_IN_SECTION(BSP_SECTION_HEAP);
96 #endif
97
98 /* All system exceptions in the vector table are weak references to Default_Handler. If the user wishes to handle
99 * these exceptions in their code they should define their own function with the same name.
100 */
101 #if defined(__ICCARM__)
102 #define WEAK_REF_ATTRIBUTE
103
104 #pragma weak HardFault_Handler = Default_Handler
105 #pragma weak MemManage_Handler = Default_Handler
106 #pragma weak BusFault_Handler = Default_Handler
107 #pragma weak UsageFault_Handler = Default_Handler
108 #pragma weak SecureFault_Handler = Default_Handler
109 #pragma weak SVC_Handler = Default_Handler
110 #pragma weak DebugMon_Handler = Default_Handler
111 #pragma weak PendSV_Handler = Default_Handler
112 #pragma weak SysTick_Handler = Default_Handler
113 #elif defined(__GNUC__)
114
115 #define WEAK_REF_ATTRIBUTE __attribute__((weak, alias("Default_Handler")))
116 #endif
117
118 void NMI_Handler(void); // NMI has many sources and is handled by BSP
119 void HardFault_Handler(void) WEAK_REF_ATTRIBUTE;
120 void MemManage_Handler(void) WEAK_REF_ATTRIBUTE;
121 void BusFault_Handler(void) WEAK_REF_ATTRIBUTE;
122 void UsageFault_Handler(void) WEAK_REF_ATTRIBUTE;
123 void SecureFault_Handler(void) WEAK_REF_ATTRIBUTE;
124 void SVC_Handler(void) WEAK_REF_ATTRIBUTE;
125 void DebugMon_Handler(void) WEAK_REF_ATTRIBUTE;
126 void PendSV_Handler(void) WEAK_REF_ATTRIBUTE;
127 void SysTick_Handler(void) WEAK_REF_ATTRIBUTE;
128
129 /* Vector table. */
130 BSP_DONT_REMOVE const exc_ptr_t __Vectors[BSP_CORTEX_VECTOR_TABLE_ENTRIES] BSP_PLACE_IN_SECTION(
131 BSP_SECTION_FIXED_VECTORS) =
132 {
133 (exc_ptr_t) (&g_main_stack[0] + BSP_CFG_STACK_MAIN_BYTES), /* Initial Stack Pointer */
134 Reset_Handler, /* Reset Handler */
135 NMI_Handler, /* NMI Handler */
136 HardFault_Handler, /* Hard Fault Handler */
137 MemManage_Handler, /* MPU Fault Handler */
138 BusFault_Handler, /* Bus Fault Handler */
139 UsageFault_Handler, /* Usage Fault Handler */
140 SecureFault_Handler, /* Secure Fault Handler */
141 0, /* Reserved */
142 0, /* Reserved */
143 0, /* Reserved */
144 SVC_Handler, /* SVCall Handler */
145 DebugMon_Handler, /* Debug Monitor Handler */
146 0, /* Reserved */
147 PendSV_Handler, /* PendSV Handler */
148 SysTick_Handler, /* SysTick Handler */
149 };
150
151 /** @} (end addtogroup BSP_MCU) */
152