149a45ad9SMatthias Ringwald /*******************************************************************************
249a45ad9SMatthias Ringwald * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
349a45ad9SMatthias Ringwald *
449a45ad9SMatthias Ringwald * Permission is hereby granted, free of charge, to any person obtaining a
549a45ad9SMatthias Ringwald * copy of this software and associated documentation files (the "Software"),
649a45ad9SMatthias Ringwald * to deal in the Software without restriction, including without limitation
749a45ad9SMatthias Ringwald * the rights to use, copy, modify, merge, publish, distribute, sublicense,
849a45ad9SMatthias Ringwald * and/or sell copies of the Software, and to permit persons to whom the
949a45ad9SMatthias Ringwald * Software is furnished to do so, subject to the following conditions:
1049a45ad9SMatthias Ringwald *
1149a45ad9SMatthias Ringwald * The above copyright notice and this permission notice shall be included
1249a45ad9SMatthias Ringwald * in all copies or substantial portions of the Software.
1349a45ad9SMatthias Ringwald *
1449a45ad9SMatthias Ringwald * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
1549a45ad9SMatthias Ringwald * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
1649a45ad9SMatthias Ringwald * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
1749a45ad9SMatthias Ringwald * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
1849a45ad9SMatthias Ringwald * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
1949a45ad9SMatthias Ringwald * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
2049a45ad9SMatthias Ringwald * OTHER DEALINGS IN THE SOFTWARE.
2149a45ad9SMatthias Ringwald *
2249a45ad9SMatthias Ringwald * Except as contained in this notice, the name of Maxim Integrated
2349a45ad9SMatthias Ringwald * Products, Inc. shall not be used except as stated in the Maxim Integrated
2449a45ad9SMatthias Ringwald * Products, Inc. Branding Policy.
2549a45ad9SMatthias Ringwald *
2649a45ad9SMatthias Ringwald * The mere transfer of this software does not imply any licenses
2749a45ad9SMatthias Ringwald * of trade secrets, proprietary technology, copyrights, patents,
2849a45ad9SMatthias Ringwald * trademarks, maskwork rights, or any other form of intellectual
2949a45ad9SMatthias Ringwald * property whatsoever. Maxim Integrated Products, Inc. retains all
3049a45ad9SMatthias Ringwald * ownership rights.
3149a45ad9SMatthias Ringwald *
3249a45ad9SMatthias Ringwald * $Date: 2016-03-17 14:27:29 -0700 (Thu, 17 Mar 2016) $
3349a45ad9SMatthias Ringwald * $Revision: 21966 $
3449a45ad9SMatthias Ringwald *
3549a45ad9SMatthias Ringwald ******************************************************************************/
3649a45ad9SMatthias Ringwald
3749a45ad9SMatthias Ringwald #include <stdio.h>
3849a45ad9SMatthias Ringwald #include "mxc_config.h"
3949a45ad9SMatthias Ringwald #include "mxc_assert.h"
4049a45ad9SMatthias Ringwald #include "board.h"
4149a45ad9SMatthias Ringwald #include "gpio.h"
4249a45ad9SMatthias Ringwald #include "uart.h"
4349a45ad9SMatthias Ringwald #include "spim.h"
4449a45ad9SMatthias Ringwald #include "max14690n.h"
4549a45ad9SMatthias Ringwald
46*7dabc299SMatthias Ringwald #define UART_ERRORS (MXC_F_UART_INTEN_RX_FIFO_OVERFLOW | \
47*7dabc299SMatthias Ringwald MXC_F_UART_INTEN_RX_FRAMING_ERR | \
48*7dabc299SMatthias Ringwald MXC_F_UART_INTEN_RX_PARITY_ERR)
49*7dabc299SMatthias Ringwald
5049a45ad9SMatthias Ringwald /***** Global Variables *****/
5149a45ad9SMatthias Ringwald
5249a45ad9SMatthias Ringwald // LEDs
5349a45ad9SMatthias Ringwald // Note: EvKit board uses 3.3v supply so these must be open-drain.
5449a45ad9SMatthias Ringwald const gpio_cfg_t led_pin[] = {
5549a45ad9SMatthias Ringwald { PORT_2, PIN_4, GPIO_FUNC_GPIO, GPIO_PAD_OPEN_DRAIN },
5649a45ad9SMatthias Ringwald { PORT_2, PIN_5, GPIO_FUNC_GPIO, GPIO_PAD_OPEN_DRAIN },
5749a45ad9SMatthias Ringwald { PORT_2, PIN_6, GPIO_FUNC_GPIO, GPIO_PAD_OPEN_DRAIN },
5849a45ad9SMatthias Ringwald };
5949a45ad9SMatthias Ringwald const unsigned int num_leds = (sizeof(led_pin) / sizeof(gpio_cfg_t));
6049a45ad9SMatthias Ringwald
6149a45ad9SMatthias Ringwald // Pushbuttons
6249a45ad9SMatthias Ringwald const gpio_cfg_t pb_pin[] = {
6349a45ad9SMatthias Ringwald { PORT_2, PIN_3, GPIO_FUNC_GPIO, GPIO_PAD_INPUT_PULLUP },
6449a45ad9SMatthias Ringwald };
6549a45ad9SMatthias Ringwald const unsigned int num_pbs = (sizeof(pb_pin) / sizeof(gpio_cfg_t));
6649a45ad9SMatthias Ringwald
6749a45ad9SMatthias Ringwald // Console UART configuration
6849a45ad9SMatthias Ringwald const uart_cfg_t console_uart_cfg = {
6949a45ad9SMatthias Ringwald .parity = UART_PARITY_DISABLE,
7049a45ad9SMatthias Ringwald .size = UART_DATA_SIZE_8_BITS,
7149a45ad9SMatthias Ringwald .extra_stop = 0,
7249a45ad9SMatthias Ringwald .cts = 0,
7349a45ad9SMatthias Ringwald .rts = 0,
7449a45ad9SMatthias Ringwald .baud = CONSOLE_BAUD,
7549a45ad9SMatthias Ringwald };
7649a45ad9SMatthias Ringwald const sys_cfg_uart_t console_sys_cfg = {
7749a45ad9SMatthias Ringwald .clk_scale = CLKMAN_SCALE_AUTO,
7849a45ad9SMatthias Ringwald .io_cfg = IOMAN_UART(CONSOLE_UART, IOMAN_MAP_A, IOMAN_MAP_UNUSED, IOMAN_MAP_UNUSED, 1, 0, 0)
7949a45ad9SMatthias Ringwald };
8049a45ad9SMatthias Ringwald
8149a45ad9SMatthias Ringwald // MAX14690 PMIC
8249a45ad9SMatthias Ringwald const ioman_cfg_t max14690_io_cfg = IOMAN_I2CM2(IOMAN_MAP_A, 1);
8349a45ad9SMatthias Ringwald const gpio_cfg_t max14690_int = { PORT_3, PIN_7, GPIO_FUNC_GPIO, GPIO_PAD_INPUT_PULLUP };
8449a45ad9SMatthias Ringwald const gpio_cfg_t max14690_mpc0 = { PORT_2, PIN_7, GPIO_FUNC_GPIO, GPIO_PAD_NORMAL };
8549a45ad9SMatthias Ringwald
8649a45ad9SMatthias Ringwald /***** File Scope Variables *****/
8749a45ad9SMatthias Ringwald
8849a45ad9SMatthias Ringwald /******************************************************************************/
mxc_assert(const char * expr,const char * file,int line)8949a45ad9SMatthias Ringwald void mxc_assert(const char *expr, const char *file, int line)
9049a45ad9SMatthias Ringwald {
9149a45ad9SMatthias Ringwald printf("MXC_ASSERT %s #%d: (%s)\n", file, line, expr);
9249a45ad9SMatthias Ringwald while (1);
9349a45ad9SMatthias Ringwald }
9449a45ad9SMatthias Ringwald
9549a45ad9SMatthias Ringwald /******************************************************************************/
Console_Init(void)96*7dabc299SMatthias Ringwald int Console_Init(void)
97*7dabc299SMatthias Ringwald {
98*7dabc299SMatthias Ringwald int err;
99*7dabc299SMatthias Ringwald
100*7dabc299SMatthias Ringwald if ((err = UART_Init(MXC_UART_GET_UART(CONSOLE_UART), &console_uart_cfg, &console_sys_cfg)) != E_NO_ERROR) {
101*7dabc299SMatthias Ringwald MXC_ASSERT_FAIL();
102*7dabc299SMatthias Ringwald return err;
103*7dabc299SMatthias Ringwald }
104*7dabc299SMatthias Ringwald
105*7dabc299SMatthias Ringwald // Setup the interrupt
106*7dabc299SMatthias Ringwald NVIC_ClearPendingIRQ(MXC_UART_GET_IRQ(CONSOLE_UART));
107*7dabc299SMatthias Ringwald NVIC_DisableIRQ(MXC_UART_GET_IRQ(CONSOLE_UART));
108*7dabc299SMatthias Ringwald NVIC_SetPriority(MXC_UART_GET_IRQ(CONSOLE_UART), 1);
109*7dabc299SMatthias Ringwald NVIC_EnableIRQ(MXC_UART_GET_IRQ(CONSOLE_UART));
110*7dabc299SMatthias Ringwald MXC_UART1->inten |= (MXC_F_UART_INTEN_RX_FIFO_NOT_EMPTY | UART_ERRORS);
111*7dabc299SMatthias Ringwald
112*7dabc299SMatthias Ringwald return E_NO_ERROR;
113*7dabc299SMatthias Ringwald }
114*7dabc299SMatthias Ringwald
115*7dabc299SMatthias Ringwald /******************************************************************************/
Console_PrepForSleep(void)116*7dabc299SMatthias Ringwald int Console_PrepForSleep(void)
117*7dabc299SMatthias Ringwald {
118*7dabc299SMatthias Ringwald fflush(stdout);
119*7dabc299SMatthias Ringwald return UART_PrepForSleep(MXC_UART_GET_UART(CONSOLE_UART));
120*7dabc299SMatthias Ringwald }
121*7dabc299SMatthias Ringwald
UART0_IRQHandler(void)122*7dabc299SMatthias Ringwald void UART0_IRQHandler(void)
123*7dabc299SMatthias Ringwald {
124*7dabc299SMatthias Ringwald UART_Handler(MXC_UART_GET_UART(0));
125*7dabc299SMatthias Ringwald }
126*7dabc299SMatthias Ringwald
UART1_IRQHandler(void)127*7dabc299SMatthias Ringwald void UART1_IRQHandler(void)
128*7dabc299SMatthias Ringwald {
129*7dabc299SMatthias Ringwald UART_Handler(MXC_UART_GET_UART(1));
130*7dabc299SMatthias Ringwald }
131*7dabc299SMatthias Ringwald
UART2_IRQHandler(void)132*7dabc299SMatthias Ringwald void UART2_IRQHandler(void)
133*7dabc299SMatthias Ringwald {
134*7dabc299SMatthias Ringwald UART_Handler(MXC_UART_GET_UART(2));
135*7dabc299SMatthias Ringwald }
136*7dabc299SMatthias Ringwald
UART3_IRQHandler(void)137*7dabc299SMatthias Ringwald void UART3_IRQHandler(void)
138*7dabc299SMatthias Ringwald {
139*7dabc299SMatthias Ringwald UART_Handler(MXC_UART_GET_UART(3));
140*7dabc299SMatthias Ringwald }
141*7dabc299SMatthias Ringwald
142*7dabc299SMatthias Ringwald /******************************************************************************/
Board_Init(void)14349a45ad9SMatthias Ringwald int Board_Init(void)
14449a45ad9SMatthias Ringwald {
14549a45ad9SMatthias Ringwald int err;
14649a45ad9SMatthias Ringwald
14749a45ad9SMatthias Ringwald if ((err = Console_Init()) != E_NO_ERROR) {
14849a45ad9SMatthias Ringwald MXC_ASSERT_FAIL();
14949a45ad9SMatthias Ringwald return err;
15049a45ad9SMatthias Ringwald }
15149a45ad9SMatthias Ringwald
15249a45ad9SMatthias Ringwald if ((err = LED_Init()) != E_NO_ERROR) {
15349a45ad9SMatthias Ringwald MXC_ASSERT_FAIL();
15449a45ad9SMatthias Ringwald return err;
15549a45ad9SMatthias Ringwald }
15649a45ad9SMatthias Ringwald
15749a45ad9SMatthias Ringwald if ((err = PB_Init()) != E_NO_ERROR) {
15849a45ad9SMatthias Ringwald MXC_ASSERT_FAIL();
15949a45ad9SMatthias Ringwald return err;
16049a45ad9SMatthias Ringwald }
16149a45ad9SMatthias Ringwald
16249a45ad9SMatthias Ringwald /* On the Pegasus board MPC1 is connected to CAP which is high when VBUS is present.
16349a45ad9SMatthias Ringwald * The LDO_OUTPUT_MPC1 setting will automatically enable the output when VBUS is present.
16449a45ad9SMatthias Ringwald * The LDO_OUTPUT_MPC1 setting will also disable the output when powered from the battery.
16549a45ad9SMatthias Ringwald * The Pegasus board uses LDO2 for VDDB (USB), LEDs and the SD card connector.
16649a45ad9SMatthias Ringwald * Use the MAX14690_LDO2setMode(mode) function to enable LDO2 when needed.
16749a45ad9SMatthias Ringwald */
16849a45ad9SMatthias Ringwald if ((err = MAX14690N_Init(3.3, LDO_OUTPUT_MPC1, 3.3, LDO_OUTPUT_DISABLED)) != E_NO_ERROR) {
16949a45ad9SMatthias Ringwald MXC_ASSERT_FAIL();
17049a45ad9SMatthias Ringwald return err;
17149a45ad9SMatthias Ringwald }
17249a45ad9SMatthias Ringwald
17349a45ad9SMatthias Ringwald return E_NO_ERROR;
17449a45ad9SMatthias Ringwald }
17549a45ad9SMatthias Ringwald
176*7dabc299SMatthias Ringwald #ifdef CRASH_DUMP
FaultISR_C(uint32_t * hardfault_args)177*7dabc299SMatthias Ringwald void FaultISR_C(uint32_t *hardfault_args)
17849a45ad9SMatthias Ringwald {
179*7dabc299SMatthias Ringwald unsigned int stacked_r0;
180*7dabc299SMatthias Ringwald unsigned int stacked_r1;
181*7dabc299SMatthias Ringwald unsigned int stacked_r2;
182*7dabc299SMatthias Ringwald unsigned int stacked_r3;
183*7dabc299SMatthias Ringwald unsigned int stacked_r12;
184*7dabc299SMatthias Ringwald unsigned int stacked_lr;
185*7dabc299SMatthias Ringwald unsigned int stacked_pc;
186*7dabc299SMatthias Ringwald unsigned int stacked_psr;
18749a45ad9SMatthias Ringwald
188*7dabc299SMatthias Ringwald volatile unsigned char mmsr;
189*7dabc299SMatthias Ringwald volatile unsigned char bfsr;
190*7dabc299SMatthias Ringwald volatile unsigned short ufsr;
191*7dabc299SMatthias Ringwald volatile unsigned int hfsr;
192*7dabc299SMatthias Ringwald
193*7dabc299SMatthias Ringwald stacked_r0 = ((unsigned int) hardfault_args[0]);
194*7dabc299SMatthias Ringwald stacked_r1 = ((unsigned int) hardfault_args[1]);
195*7dabc299SMatthias Ringwald stacked_r2 = ((unsigned int) hardfault_args[2]);
196*7dabc299SMatthias Ringwald stacked_r3 = ((unsigned int) hardfault_args[3]);
197*7dabc299SMatthias Ringwald stacked_r12 = ((unsigned int) hardfault_args[4]);
198*7dabc299SMatthias Ringwald stacked_lr = ((unsigned int) hardfault_args[5]);
199*7dabc299SMatthias Ringwald stacked_pc = ((unsigned int) hardfault_args[6]);
200*7dabc299SMatthias Ringwald stacked_psr = ((unsigned int) hardfault_args[7]);
201*7dabc299SMatthias Ringwald
202*7dabc299SMatthias Ringwald printf("\n\n[Hard fault handler - all numbers in hex]\n");
203*7dabc299SMatthias Ringwald printf("R0 = 0x%08x\n", stacked_r0);
204*7dabc299SMatthias Ringwald printf("R1 = 0x%08x\n", stacked_r1);
205*7dabc299SMatthias Ringwald printf("R2 = 0x%08x\n", stacked_r2);
206*7dabc299SMatthias Ringwald printf("R3 = 0x%08x\n", stacked_r3);
207*7dabc299SMatthias Ringwald printf("R12 = 0x%08x\n", stacked_r12);
208*7dabc299SMatthias Ringwald printf("LR [R14] = 0x%08x subroutine call return address\n", stacked_lr);
209*7dabc299SMatthias Ringwald printf("PC [R15] = 0x%08x program counter address\n", stacked_pc);
210*7dabc299SMatthias Ringwald printf("PSR = 0x%08x\n", stacked_psr);
211*7dabc299SMatthias Ringwald printf("MMAR = 0x%08x memory manage fault address\n", (*((volatile unsigned int *) (0xE000ED34))));
212*7dabc299SMatthias Ringwald printf("BFAR = 0x%08x bus fault address\n", (*((volatile unsigned int *) (0xE000ED38))));
213*7dabc299SMatthias Ringwald
214*7dabc299SMatthias Ringwald /***********************************************************************************************
215*7dabc299SMatthias Ringwald * Memory Management Fault Status Register: (0xE000ED28)
216*7dabc299SMatthias Ringwald * Bit Name Description
217*7dabc299SMatthias Ringwald * 7 MMARVALID MMAR is valid (0x40)
218*7dabc299SMatthias Ringwald * 4 MSTKERR Stacking error (0x10)
219*7dabc299SMatthias Ringwald * 3 MUNSTKERR Unstacking error (0x8)
220*7dabc299SMatthias Ringwald * 1 DACCVIOL Data access violation (0x2)
221*7dabc299SMatthias Ringwald * 0 IACCVIOL Instruction access violation (0x1)
222*7dabc299SMatthias Ringwald ***********************************************************************************************/
223*7dabc299SMatthias Ringwald mmsr = (*((volatile unsigned char *) (0xE000ED28)));
224*7dabc299SMatthias Ringwald printf("MMSR = 0x%02x ", mmsr);
225*7dabc299SMatthias Ringwald if (mmsr & 0x40)
226*7dabc299SMatthias Ringwald printf("MMARVALID: MMAR is valid ");
227*7dabc299SMatthias Ringwald if (mmsr & 0x10)
228*7dabc299SMatthias Ringwald printf("MSTKERR: Stacking error\n");
229*7dabc299SMatthias Ringwald else if (mmsr & 0x8)
230*7dabc299SMatthias Ringwald printf("MUNSTKERR: Unstacking error\n");
231*7dabc299SMatthias Ringwald else if (mmsr & 0x2)
232*7dabc299SMatthias Ringwald printf("DACCVIOL: Data access violation\n");
233*7dabc299SMatthias Ringwald else if (mmsr & 0x1)
234*7dabc299SMatthias Ringwald printf("IACCVIOL: Instruction access violation\n");
235*7dabc299SMatthias Ringwald else
236*7dabc299SMatthias Ringwald printf("\n");
237*7dabc299SMatthias Ringwald
238*7dabc299SMatthias Ringwald /***********************************************************************************************
239*7dabc299SMatthias Ringwald * Bus Fault Status Register: (0xE000ED28)
240*7dabc299SMatthias Ringwald * Bit Name Description
241*7dabc299SMatthias Ringwald * 7 BFARVALID BFAR is valid (0x80)
242*7dabc299SMatthias Ringwald * 4 STKERR Stacking error (0x10)
243*7dabc299SMatthias Ringwald * 3 UNSTKERR Unstacking error (0x8)
244*7dabc299SMatthias Ringwald * 2 IMPREISERR Imprecise data access violation (0x4)
245*7dabc299SMatthias Ringwald * 1 PRECISERR Precise data access violation (0x2)
246*7dabc299SMatthias Ringwald * 0 IBUSERR Instruction access violation (0x1)
247*7dabc299SMatthias Ringwald ***********************************************************************************************/
248*7dabc299SMatthias Ringwald bfsr = (*((volatile unsigned char *) (0xE000ED29)));
249*7dabc299SMatthias Ringwald printf("BFSR = 0x%02x ", bfsr);
250*7dabc299SMatthias Ringwald if (bfsr & 0x80)
251*7dabc299SMatthias Ringwald printf("BFARVALID: BFAR is valid ");
252*7dabc299SMatthias Ringwald if (bfsr & 0x10)
253*7dabc299SMatthias Ringwald printf("STKERR: Stacking error\n");
254*7dabc299SMatthias Ringwald else if (bfsr & 0x8)
255*7dabc299SMatthias Ringwald printf("UNSTKERR: Unstacking error\n");
256*7dabc299SMatthias Ringwald else if (bfsr & 0x4)
257*7dabc299SMatthias Ringwald printf("IMPREISERR: Imprecise data access violation\n");
258*7dabc299SMatthias Ringwald else if (bfsr & 0x2)
259*7dabc299SMatthias Ringwald printf("PRECISERR: Precise data access violation\n");
260*7dabc299SMatthias Ringwald else if (bfsr & 0x1)
261*7dabc299SMatthias Ringwald printf("IBUSERR: Instruction access violation\n");
262*7dabc299SMatthias Ringwald else
263*7dabc299SMatthias Ringwald printf("\n");
264*7dabc299SMatthias Ringwald
265*7dabc299SMatthias Ringwald /***********************************************************************************************
266*7dabc299SMatthias Ringwald * Usage Fault Status Register: (0xE000ED2A)
267*7dabc299SMatthias Ringwald * Bit Name Description
268*7dabc299SMatthias Ringwald * 9 DIVBYZERO Divide by zero will take place (0x200)
269*7dabc299SMatthias Ringwald * 8 UNALIGNED Unaligned access will take place (0x100)
270*7dabc299SMatthias Ringwald * 3 NOCP Attempt to execute a coprocessor instruction (0x8)
271*7dabc299SMatthias Ringwald * 2 INVPC Attempt to do exception with bad value (0x4)
272*7dabc299SMatthias Ringwald * 1 INVSTATE Attempt to switch to invalid state (0x2)
273*7dabc299SMatthias Ringwald * 0 UNDEFINSTR Attempt to execute an undefined instruction (0x1)
274*7dabc299SMatthias Ringwald ***********************************************************************************************/
275*7dabc299SMatthias Ringwald ufsr = (*((volatile unsigned short *) (0xE000ED2A)));
276*7dabc299SMatthias Ringwald printf("UFSR = 0x%04x ", ufsr);
277*7dabc299SMatthias Ringwald if (ufsr & 0x200)
278*7dabc299SMatthias Ringwald printf("DIVBYZERO: Divide by zero will take place\n");
279*7dabc299SMatthias Ringwald else if (ufsr & 0x100)
280*7dabc299SMatthias Ringwald printf("UNALIGNED: Unaligned access will take place\n");
281*7dabc299SMatthias Ringwald else if (ufsr & 0x8)
282*7dabc299SMatthias Ringwald printf("NOCP: Attempt to execute a coprocessor instruction\n");
283*7dabc299SMatthias Ringwald else if (ufsr & 0x4)
284*7dabc299SMatthias Ringwald printf("INVPC: Attempt to do exception with bad value\n");
285*7dabc299SMatthias Ringwald else if (ufsr & 0x2)
286*7dabc299SMatthias Ringwald printf("INVSTATE: Attempt to switch to invalid state\n");
287*7dabc299SMatthias Ringwald else if (ufsr & 0x1)
288*7dabc299SMatthias Ringwald printf("UNDEFINSTR: Attempt to execute an undefined instruction\n");
289*7dabc299SMatthias Ringwald else
290*7dabc299SMatthias Ringwald printf("\n");
291*7dabc299SMatthias Ringwald
292*7dabc299SMatthias Ringwald /***********************************************************************************************
293*7dabc299SMatthias Ringwald * Usage Fault Status Register: (0xE000ED2A)
294*7dabc299SMatthias Ringwald * Bit Name Description
295*7dabc299SMatthias Ringwald * 31 DEBUGEVT Hard fault caused by debug event (0x8000_0000)
296*7dabc299SMatthias Ringwald * 30 FORCED Hard fault caused by bus/memory management/usage fault (0x4000_0000)
297*7dabc299SMatthias Ringwald * 1 VECTBL Hard fault caused by failed vector fetch (0x1)
298*7dabc299SMatthias Ringwald ***********************************************************************************************/
299*7dabc299SMatthias Ringwald hfsr = (*((volatile unsigned int *) (0xE000ED2C)));
300*7dabc299SMatthias Ringwald printf("HFSR = 0x%08x ", hfsr);
301*7dabc299SMatthias Ringwald if (hfsr & 0x80000000)
302*7dabc299SMatthias Ringwald printf("DEBUGEVT: Hard fault caused by debug event\n");
303*7dabc299SMatthias Ringwald else if (hfsr & 0x40000000)
304*7dabc299SMatthias Ringwald printf("FORCED: Hard fault caused by bus/memory management/usage fault\n");
305*7dabc299SMatthias Ringwald else if (hfsr & 0x1)
306*7dabc299SMatthias Ringwald printf("VECTBL: Hard fault caused by failed vector fetch\n");
307*7dabc299SMatthias Ringwald else
308*7dabc299SMatthias Ringwald printf("\n");
309*7dabc299SMatthias Ringwald
310*7dabc299SMatthias Ringwald printf ("AFSR = 0x%08x\n", (*((volatile unsigned int *)(0xE000ED3C))));
311*7dabc299SMatthias Ringwald printf ("SCB_SHCSR = %x\n", SCB->SHCSR);
312*7dabc299SMatthias Ringwald
313*7dabc299SMatthias Ringwald while (1) ; /* Spin so we can use a debugger to anlayzer the situation */
31449a45ad9SMatthias Ringwald }
315*7dabc299SMatthias Ringwald #else /* ENABLE_CRASH_DUMP */
FaultISR_C(uint32_t * hardfault_args)316*7dabc299SMatthias Ringwald void FaultISR_C(uint32_t *hardfault_args)
31749a45ad9SMatthias Ringwald {
318*7dabc299SMatthias Ringwald /* spin so we can use a debugger to anlayze the situation */
319*7dabc299SMatthias Ringwald while(1);
320*7dabc299SMatthias Ringwald /* reset the system */
321*7dabc299SMatthias Ringwald //NVIC_SystemReset();
322*7dabc299SMatthias Ringwald }
323*7dabc299SMatthias Ringwald #endif /* CRASH_DUMP */
324*7dabc299SMatthias Ringwald
325*7dabc299SMatthias Ringwald
HardFault_Handler(void)326*7dabc299SMatthias Ringwald void HardFault_Handler(void)
327*7dabc299SMatthias Ringwald {
328*7dabc299SMatthias Ringwald printf("HardFault_Handler! (main)\n");
329*7dabc299SMatthias Ringwald __asm(
330*7dabc299SMatthias Ringwald " TST LR, #4\n"
331*7dabc299SMatthias Ringwald " ITE EQ \n"
332*7dabc299SMatthias Ringwald " MRSEQ R0, MSP \n"
333*7dabc299SMatthias Ringwald " MRSNE R0, PSP \n"
334*7dabc299SMatthias Ringwald " B FaultISR_C \n");
33549a45ad9SMatthias Ringwald }
336