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 #ifndef IS_FLASH_LOADER
24 #error Should define IS_FLASH_LOADER
25 #define IS_FLASH_LOADER 0
29 #define RELOCATE_INTERRUPT 1
32 extern void main(void);
33 extern char __stack__;
34 extern char __text_start__, __text_end__;
35 extern char __data_start__, __data_end__;
36 extern char __bss_start__, __bss_end__;
37 #if RELOCATE_INTERRUPT
38 extern char __interrupt_rom__, __interrupt_start__, __interrupt_end__;
41 /* Interrupt functions */
43 void stm_halt_isr(void)
45 ao_panic(AO_PANIC_CRASH);
48 void stm_ignore_isr(void)
52 const void *stm_interrupt_vector[];
55 stm_flash_size(void) {
56 uint16_t dev_id = stm_dev_id();
61 kbytes = stm_flash_size_04x.f_size;
64 return (uint32_t) kbytes * 1024;
70 if (ao_boot_check_chain()) {
76 #if RELOCATE_INTERRUPT
78 stm_rcc.apb2enr |= (1 << STM_RCC_APB2ENR_SYSCFGCOMPEN);
80 memcpy(&__interrupt_start__, &__interrupt_rom__, &__interrupt_end__ - &__interrupt_start__);
81 stm_syscfg.cfgr1 = (stm_syscfg.cfgr1 & ~(STM_SYSCFG_CFGR1_MEM_MODE_MASK << STM_SYSCFG_CFGR1_MEM_MODE)) |
82 (STM_SYSCFG_CFGR1_MEM_MODE_SRAM << STM_SYSCFG_CFGR1_MEM_MODE);
84 memcpy(&__data_start__, &__text_end__, &__data_end__ - &__data_start__);
85 memset(&__bss_start__, '\0', &__bss_end__ - &__bss_start__);
89 #define STRINGIFY(x) #x
92 void __attribute__ ((weak)) stm_ ## name ## _isr(void); \
93 _Pragma(STRINGIFY(weak stm_ ## name ## _isr = stm_ignore_isr))
95 #define isr_halt(name) \
96 void __attribute__ ((weak)) stm_ ## name ## _isr(void); \
97 _Pragma(STRINGIFY(weak stm_ ## name ## _isr = stm_halt_isr))
121 isr(tim1_brk_up_trg_com)
137 isr(usart3_4_5_6_7_8)
141 #define i(addr,name) [(addr)/4] = stm_ ## name ## _isr
143 __attribute__ ((section(".interrupt")))
144 const void *stm_interrupt_vector[] = {
153 i(0x40, wwdg), /* IRQ0 */
164 i(0x6c, dma_ch4_5_6),
166 i(0x74, tim1_brk_up_trg_com),
182 i(0xb4, usart3_4_5_6_7_8),