2 * Copyright © 2012 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
22 extern void main(void);
23 extern char __stack__;
24 extern char __text_start__, __text_end__;
25 extern char __data_start__, __data_end__;
26 extern char __bss_start__, __bss_end__;
28 /* Interrupt functions */
30 void stm_halt_isr(void)
32 ao_panic(AO_PANIC_CRASH);
35 void stm_ignore_isr(void)
39 const void *stm_interrupt_vector[];
41 #define BOOT_FETCH(o) (*((uint32_t *) (AO_BOOT_APPLICATION_BASE + (o))))
43 #ifdef AO_BOOT_APPLICATION_PIN
46 #define AO_BOOT_APPLICATION 0x5a5aa5a5
47 #define AO_BOOT_APPLICATION_CHECK 0xc3c33c3c
49 static uint32_t ao_boot_application;
50 static uint32_t ao_boot_application_check;
59 asm ("mov sp, %0" : : "r" (sp));
60 asm ("mov lr, %0" : : "r" (pc));
65 ao_reboot_application(void)
67 ao_boot_application = AO_BOOT_APPLICATION;
68 ao_boot_application_check = AO_BOOT_APPLICATION_CHECK;
75 #ifdef AO_BOOT_APPLICATION_PIN
78 if (ao_boot_application == AO_BOOT_APPLICATION &&
79 ao_boot_application_check == AO_BOOT_APPLICATION_CHECK) {
80 ao_boot_application = 0;
81 ao_boot_application_check = 0;
84 /* Enable power interface clock */
85 stm_rcc.apb1enr |= (1 << STM_RCC_APB1ENR_PWREN);
87 /* Enable the input pin */
88 ao_enable_input(&AO_BOOT_APPLICATION_GPIO, AO_BOOT_APPLICATION_PIN,
89 AO_BOOT_APPLICATION_MODE);
92 v = stm_gpio_get(&AO_BOOT_APPLICATION_GPIO, AO_BOOT_APPLICATION_PIN);
94 /* Reset the chip to turn off the port and the power interface clock */
95 ao_gpio_set_mode(&AO_BOOT_APPLICATION_GPIO, AO_BOOT_APPLICATION_PIN, 0);
96 ao_disable_port(&AO_BOOT_APPLICATION_GPIO);
97 stm_rcc.apb1enr &= ~(1 << STM_RCC_APB1ENR_PWREN);
98 if (v == AO_BOOT_APPLICATION_VALUE)
102 /* Set interrupt vector table offset */
103 stm_nvic.vto = (uint32_t) &stm_interrupt_vector;
104 memcpy(&__data_start__, &__text_end__, &__data_end__ - &__data_start__);
105 memset(&__bss_start__, '\0', &__bss_end__ - &__bss_start__);
109 #define STRINGIFY(x) #x
112 void __attribute__ ((weak)) stm_ ## name ## _isr(void); \
113 _Pragma(STRINGIFY(weak stm_ ## name ## _isr = stm_ignore_isr))
115 #define isr_halt(name) \
116 void __attribute__ ((weak)) stm_ ## name ## _isr(void); \
117 _Pragma(STRINGIFY(weak stm_ ## name ## _isr = stm_halt_isr))
174 #define i(addr,name) [(addr)/4] = stm_ ## name ## _isr
176 __attribute__ ((section(".interrupt")))
177 const void *stm_interrupt_vector[] = {
191 i(0x48, tamper_stamp),
200 i(0x6c, dma1_channel1),
201 i(0x70, dma1_channel2),
202 i(0x74, dma1_channel3),
203 i(0x78, dma1_channel4),
204 i(0x7c, dma1_channel5),
205 i(0x80, dma1_channel6),
206 i(0x84, dma1_channel7),
231 i(0xe8, usb_fs_wkup),