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 | 44311d6 | 2013-12-06 22:03:29 -0800 | [diff] [blame] | 10 | // Change the vector table offset to use our vector table instead of the |
| 11 | // bootloader's. |
| 12 | SCB->VTOR = (uint32_t)&_vectors; |
Brian Silverman | e3acf71 | 2013-12-14 10:48:10 -0800 | [diff] [blame] | 13 | // Data Memory Barrier to make sure it gets the updated vector table. |
| 14 | __asm__ __volatile__("dmb"); |
Brian Silverman | ed183e6 | 2013-12-18 15:51:16 -0800 | [diff] [blame^] | 15 | led_set(LED_DB, 0); |
Brian Silverman | 1b6fbd0 | 2013-12-12 18:08:47 -0800 | [diff] [blame] | 16 | |
| 17 | fill_packet_start(); |
Brian Silverman | e3acf71 | 2013-12-14 10:48:10 -0800 | [diff] [blame] | 18 | |
| 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 Silverman | ed183e6 | 2013-12-18 15:51:16 -0800 | [diff] [blame^] | 23 | |
| 24 | led_set(LED_ERR, 0); |
| 25 | |
Brian Silverman | e3acf71 | 2013-12-14 10:48:10 -0800 | [diff] [blame] | 26 | // 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 Silverman | 5020be6 | 2013-12-06 19:09:07 -0800 | [diff] [blame] | 31 | } |