blob: 1ed6218152c1fa8f9351ac3ce293d575882e2820 [file] [log] [blame]
Brian Silverman44311d62013-12-06 22:03:29 -08001#include <stdint.h>
2
Brian Silverman1b6fbd02013-12-12 18:08:47 -08003#include <STM32F2XX.h>
4
Brian Silverman44311d62013-12-06 22:03:29 -08005#include "cape/bootloader_handoff.h"
6
7// Sets everything up and then jumps to the main code.
8static void jump_to_main(void) __attribute__((noreturn));
9static void jump_to_main(void) {
Brian Silvermanaa9183a2013-12-08 10:33:47 -080010 __asm__ __volatile__(
Brian Silverman44311d62013-12-06 22:03:29 -080011 "mov sp, %[stack]\n\t"
12 "bx %[reset]" : :
13 [stack]"r"(RAM_START + RAM_SIZE), [reset]"r"(MAIN_FLASH_START | 1)
14 : "memory");
15 __builtin_unreachable();
16}
17
Brian Silverman5020be62013-12-06 19:09:07 -080018void _start(void) {
Brian Silverman1b6fbd02013-12-12 18:08:47 -080019 SYSCFG->CMPCR = SYSCFG_CMPCR_CMP_PD; // enable IO compensation cell
20 while (!(SYSCFG->CMPCR & SYSCFG_CMPCR_READY)) {} // wait for it to be ready
21
22 // We don't have anything on the 1 port D pin, so don't bother enabling it.
23 RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN | RCC_AHB1ENR_GPIOBEN | RCC_AHB1ENR_GPIOCEN;
24
Brian Silverman44311d62013-12-06 22:03:29 -080025 jump_to_main();
Brian Silverman5020be62013-12-06 19:09:07 -080026}