blob: 411a734edd348e8d525c412a7041a6d7ecd9f8f6 [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 Silverman44311d62013-12-06 22:03:29 -08004
5// The startup asm code defines this to the start of our exception vector table.
6extern uint32_t _vectors;
7
Brian Silverman5020be62013-12-06 19:09:07 -08008void _start(void) {
Brian Silverman44311d62013-12-06 22:03:29 -08009 // Change the vector table offset to use our vector table instead of the
10 // bootloader's.
11 SCB->VTOR = (uint32_t)&_vectors;
Brian Silvermane3acf712013-12-14 10:48:10 -080012 // Data Memory Barrier to make sure it gets the updated vector table.
13 __asm__ __volatile__("dmb");
Brian Silverman1b6fbd02013-12-12 18:08:47 -080014
15 fill_packet_start();
Brian Silvermane3acf712013-12-14 10:48:10 -080016
17 // Make it go right to sleep after handling all exceptions. This actually
18 // decreses ISR latency a little bit because it doesn't have to stack the
19 // registers for the first one.
20 SCB->SCR |= SCB_SCR_SLEEPONEXIT_Msk;
21 // This seems like the perfect place to use WFI, but Brian on 2013-12-13
22 // couldn't find anything verifying that WFI doesn't increase the latency for
23 // the first interrupt handled, and we should never actually get here anyways,
24 // so it doesn't matter.
25 while (1) {}
Brian Silverman5020be62013-12-06 19:09:07 -080026}