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.
23 extern void main(void);
24 extern char __stack__;
25 extern char __text_start__, __text_end__;
26 extern char __data_start__, __data_end__;
27 extern char __bss_start__, __bss_end__;
29 /* Interrupt functions */
31 void stm_halt_isr(void)
33 ao_panic(AO_PANIC_CRASH);
36 void stm_ignore_isr(void)
40 const void *stm_interrupt_vector[];
43 stm_flash_size(void) {
44 uint16_t dev_id = stm_dev_id();
48 case 0x416: /* cat 1 */
49 kbytes = stm_flash_size_medium.f_size;
51 case 0x429: /* cat 2 */
52 kbytes = stm_flash_size_medium.f_size & 0xff;
54 case 0x427: /* cat 3 */
55 kbytes = stm_flash_size_large.f_size;
57 case 0x436: /* cat 4 */
58 switch (stm_flash_size_large.f_size) {
67 case 0x437: /* cat 5 */
68 kbytes = stm_flash_size_large.f_size;
71 return (uint32_t) kbytes * 1024;
77 if (ao_boot_check_chain()) {
83 /* Set interrupt vector table offset */
84 stm_nvic.vto = (uint32_t) &stm_interrupt_vector;
85 memcpy(&__data_start__, &__text_end__, &__data_end__ - &__data_start__);
86 memset(&__bss_start__, '\0', &__bss_end__ - &__bss_start__);
90 #define STRINGIFY(x) #x
93 void __attribute__ ((weak)) stm_ ## name ## _isr(void); \
94 _Pragma(STRINGIFY(weak stm_ ## name ## _isr = stm_ignore_isr))
96 #define isr_halt(name) \
97 void __attribute__ ((weak)) stm_ ## name ## _isr(void); \
98 _Pragma(STRINGIFY(weak stm_ ## name ## _isr = stm_halt_isr))
155 #define i(addr,name) [(addr)/4] = stm_ ## name ## _isr
157 __attribute__ ((section(".interrupt")))
158 const void *stm_interrupt_vector[] = {
172 i(0x48, tamper_stamp),
181 i(0x6c, dma1_channel1),
182 i(0x70, dma1_channel2),
183 i(0x74, dma1_channel3),
184 i(0x78, dma1_channel4),
185 i(0x7c, dma1_channel5),
186 i(0x80, dma1_channel6),
187 i(0x84, dma1_channel7),
212 i(0xe8, usb_fs_wkup),