blob: 390112be93a103cdd2f37c4440dda8ba6c847974 [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 Silverman176c6762013-12-19 16:28:09 -080010 led_set(LED_ERR, 1);
11 led_set(LED_HB, 0);
Brian Silverman44311d62013-12-06 22:03:29 -080012 // Change the vector table offset to use our vector table instead of the
13 // bootloader's.
14 SCB->VTOR = (uint32_t)&_vectors;
Brian Silvermane3acf712013-12-14 10:48:10 -080015 // Data Memory Barrier to make sure it gets the updated vector table.
16 __asm__ __volatile__("dmb");
Brian Silverman1b6fbd02013-12-12 18:08:47 -080017
18 fill_packet_start();
Brian Silvermane3acf712013-12-14 10:48:10 -080019
20 // Make it go right to sleep after handling all exceptions. This actually
21 // decreses ISR latency a little bit because it doesn't have to stack the
22 // registers for the first one.
23 SCB->SCR |= SCB_SCR_SLEEPONEXIT_Msk;
Brian Silvermaned183e62013-12-18 15:51:16 -080024
Brian Silvermane3acf712013-12-14 10:48:10 -080025 // This seems like the perfect place to use WFI, but Brian on 2013-12-13
26 // couldn't find anything verifying that WFI doesn't increase the latency for
27 // the first interrupt handled, and we should never actually get here anyways,
28 // so it doesn't matter.
29 while (1) {}
Brian Silverman5020be62013-12-06 19:09:07 -080030}