blob: be9717174dc6e638bb0c7b4451b64fa1f86380b8 [file] [log] [blame]
Brian Silverman44311d62013-12-06 22:03:29 -08001#include <STM32F2XX.h>
2
Brian Silverman1b6fbd02013-12-12 18:08:47 -08003#include "cape/fill_packet.h"
Brian Silvermaned183e62013-12-18 15:51:16 -08004#include "cape/led.h"
Brian Silverman44311d62013-12-06 22:03:29 -08005
6// The startup asm code defines this to the start of our exception vector table.
7extern uint32_t _vectors;
8
Brian Silverman5020be62013-12-06 19:09:07 -08009void _start(void) {
Brian Silverman44311d62013-12-06 22:03:29 -080010 // Change the vector table offset to use our vector table instead of the
11 // bootloader's.
12 SCB->VTOR = (uint32_t)&_vectors;
Brian Silvermane3acf712013-12-14 10:48:10 -080013 // Data Memory Barrier to make sure it gets the updated vector table.
14 __asm__ __volatile__("dmb");
Brian Silvermaned183e62013-12-18 15:51:16 -080015 led_set(LED_DB, 0);
Brian Silverman1b6fbd02013-12-12 18:08:47 -080016
17 fill_packet_start();
Brian Silvermane3acf712013-12-14 10:48:10 -080018
19 // Make it go right to sleep after handling all exceptions. This actually
20 // decreses ISR latency a little bit because it doesn't have to stack the
21 // registers for the first one.
22 SCB->SCR |= SCB_SCR_SLEEPONEXIT_Msk;
Brian Silvermaned183e62013-12-18 15:51:16 -080023
24 led_set(LED_ERR, 0);
25
Brian Silvermane3acf712013-12-14 10:48:10 -080026 // This seems like the perfect place to use WFI, but Brian on 2013-12-13
27 // couldn't find anything verifying that WFI doesn't increase the latency for
28 // the first interrupt handled, and we should never actually get here anyways,
29 // so it doesn't matter.
30 while (1) {}
Brian Silverman5020be62013-12-06 19:09:07 -080031}