Brian Silverman | 44311d6 | 2013-12-06 22:03:29 -0800 | [diff] [blame] | 1 | #include <STM32F2XX.h> |
| 2 | |
Brian Silverman | 1b6fbd0 | 2013-12-12 18:08:47 -0800 | [diff] [blame] | 3 | #include "cape/fill_packet.h" |
Brian Silverman | ed183e6 | 2013-12-18 15:51:16 -0800 | [diff] [blame] | 4 | #include "cape/led.h" |
Brian Silverman | 44311d6 | 2013-12-06 22:03:29 -0800 | [diff] [blame] | 5 | |
| 6 | // The startup asm code defines this to the start of our exception vector table. |
| 7 | extern uint32_t _vectors; |
| 8 | |
Brian Silverman | 5020be6 | 2013-12-06 19:09:07 -0800 | [diff] [blame] | 9 | void _start(void) { |
Brian Silverman | 176c676 | 2013-12-19 16:28:09 -0800 | [diff] [blame] | 10 | led_set(LED_ERR, 1); |
| 11 | led_set(LED_HB, 0); |
Brian Silverman | 44311d6 | 2013-12-06 22:03:29 -0800 | [diff] [blame] | 12 | // Change the vector table offset to use our vector table instead of the |
| 13 | // bootloader's. |
| 14 | SCB->VTOR = (uint32_t)&_vectors; |
Brian Silverman | e3acf71 | 2013-12-14 10:48:10 -0800 | [diff] [blame] | 15 | // Data Memory Barrier to make sure it gets the updated vector table. |
| 16 | __asm__ __volatile__("dmb"); |
Brian Silverman | 1b6fbd0 | 2013-12-12 18:08:47 -0800 | [diff] [blame] | 17 | |
| 18 | fill_packet_start(); |
Brian Silverman | e3acf71 | 2013-12-14 10:48:10 -0800 | [diff] [blame] | 19 | |
| 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 Silverman | ed183e6 | 2013-12-18 15:51:16 -0800 | [diff] [blame] | 24 | |
Brian Silverman | e3acf71 | 2013-12-14 10:48:10 -0800 | [diff] [blame] | 25 | // 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 Silverman | 5020be6 | 2013-12-06 19:09:07 -0800 | [diff] [blame] | 30 | } |