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; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
24 extern void main(void);
26 /* Interrupt functions */
28 void stm_halt_isr(void)
30 ao_panic(AO_PANIC_CRASH);
33 void stm_ignore_isr(void)
38 stm_flash_size(void) {
39 uint16_t dev_id = stm_dev_id();
43 case 0x416: /* cat 1 */
44 kbytes = stm_flash_size_medium.f_size;
46 case 0x429: /* cat 2 */
47 kbytes = stm_flash_size_medium.f_size & 0xff;
49 case 0x427: /* cat 3 */
50 kbytes = stm_flash_size_large.f_size;
52 case 0x436: /* cat 4 */
53 switch (stm_flash_size_large.f_size) {
62 case 0x437: /* cat 5 */
63 kbytes = stm_flash_size_large.f_size;
66 return (uint32_t) kbytes * 1024;
69 #define STRINGIFY(x) #x
72 void __attribute__ ((weak)) stm_ ## name ## _isr(void); \
73 _Pragma(STRINGIFY(weak stm_ ## name ## _isr = stm_ignore_isr))
75 #define isr_halt(name) \
76 void __attribute__ ((weak)) stm_ ## name ## _isr(void); \
77 _Pragma(STRINGIFY(weak stm_ ## name ## _isr = stm_halt_isr))
134 #define i(addr,name) [(addr)/4] = stm_ ## name ## _isr
136 extern char __stack[];
137 void _start(void) __attribute__((__noreturn__));
138 void main(void) __attribute__((__noreturn__));
140 /* This must be exactly 256 bytes long so that the configuration data
141 * gets loaded at the right place
144 __attribute__ ((section(".init")))
145 const void * const __interrupt_vector[64] = {
159 i(0x48, tamper_stamp),
168 i(0x6c, dma1_channel1),
169 i(0x70, dma1_channel2),
170 i(0x74, dma1_channel3),
171 i(0x78, dma1_channel4),
172 i(0x7c, dma1_channel5),
173 i(0x80, dma1_channel6),
174 i(0x84, dma1_channel7),
199 i(0xe8, usb_fs_wkup),
204 extern char __data_source[];
205 extern char __data_start[];
206 extern char __data_size[];
207 extern char __bss_start[];
208 extern char __bss_size[];
211 memcpy(__data_start, __data_source, (uintptr_t) __data_size);
212 memset(__bss_start, '\0', (uintptr_t) __bss_size);
215 if (ao_boot_check_chain()) {
217 if (ao_boot_check_pin())
220 ao_boot_chain(AO_BOOT_APPLICATION_BASE);
224 /* Set interrupt vector table offset */
225 stm_nvic.vto = (uint32_t) &__interrupt_vector;