177 lines
9.8 KiB
C
177 lines
9.8 KiB
C
#include <stdint.h>
|
|
|
|
extern void stack_start(void); // Defined in link.ld
|
|
extern int main(void);
|
|
|
|
void init_memory(void) {
|
|
// Copy .data SECTION to ram
|
|
extern uint32_t _data_start, _data_end, _data_addr;
|
|
for (uint32_t *dst = &_data_start, *src = &_data_addr; dst < &_data_end;) {
|
|
*dst++ = *src++;
|
|
}
|
|
|
|
// Initialize .bss SECTION with zeros
|
|
extern uint32_t _bss_start, _bss_end;
|
|
for (uint32_t *dst = &_bss_start; dst < &_bss_end; dst++) {
|
|
*dst = 0;
|
|
}
|
|
}
|
|
|
|
// Interrupt and exception vectors
|
|
void reset(void) {
|
|
(void)init_memory();
|
|
|
|
main();
|
|
|
|
// Infinite loop in case main returns
|
|
for (;;) (void) 0;
|
|
}
|
|
|
|
|
|
void nmi(void) __attribute__ ((weak, alias("default_handler")));
|
|
void hard_fault(void) __attribute__ ((weak, alias("default_handler")));
|
|
void mem_manage(void) __attribute__ ((weak, alias("default_handler")));
|
|
void bus_fault(void) __attribute__ ((weak, alias("default_handler")));
|
|
void usage_fault(void) __attribute__ ((weak, alias("default_handler")));
|
|
void sv_call(void) __attribute__ ((weak, alias("default_handler")));
|
|
void x(void) __attribute__ ((weak, alias("default_handler")));
|
|
void debug_monitor(void) __attribute__ ((weak, alias("default_handler")));
|
|
void pend_sv(void) __attribute__ ((weak, alias("default_handler")));
|
|
void systick(void) __attribute__ ((weak, alias("default_handler")));
|
|
void wwdg(void) __attribute__ ((weak, alias("default_handler")));
|
|
void pvd(void) __attribute__ ((weak, alias("default_handler")));
|
|
void tamp_stamp(void) __attribute__ ((weak, alias("default_handler")));
|
|
void rtc_wkup(void) __attribute__ ((weak, alias("default_handler")));
|
|
void flash(void) __attribute__ ((weak, alias("default_handler")));
|
|
void rcc(void) __attribute__ ((weak, alias("default_handler")));
|
|
void exti0(void) __attribute__ ((weak, alias("default_handler")));
|
|
void exti1(void) __attribute__ ((weak, alias("default_handler")));
|
|
void exti2(void) __attribute__ ((weak, alias("default_handler")));
|
|
void exti3(void) __attribute__ ((weak, alias("default_handler")));
|
|
void exti4(void) __attribute__ ((weak, alias("default_handler")));
|
|
void dma1_stream0(void) __attribute__ ((weak, alias("default_handler")));
|
|
void dma1_stream1(void) __attribute__ ((weak, alias("default_handler")));
|
|
void dma1_stream2(void) __attribute__ ((weak, alias("default_handler")));
|
|
void dma1_stream3(void) __attribute__ ((weak, alias("default_handler")));
|
|
void dma1_stream4(void) __attribute__ ((weak, alias("default_handler")));
|
|
void dma1_stream5(void) __attribute__ ((weak, alias("default_handler")));
|
|
void dma1_stream6(void) __attribute__ ((weak, alias("default_handler")));
|
|
void adc(void) __attribute__ ((weak, alias("default_handler")));
|
|
void exti9_5(void) __attribute__ ((weak, alias("default_handler")));
|
|
void tim1_brk_tim9(void) __attribute__ ((weak, alias("default_handler")));
|
|
void tim1_up_tim10(void) __attribute__ ((weak, alias("default_handler")));
|
|
void tim1_trg_com_tim11(void) __attribute__ ((weak, alias("default_handler")));
|
|
void tim1_cc(void) __attribute__ ((weak, alias("default_handler")));
|
|
void tim2(void) __attribute__ ((weak, alias("default_handler")));
|
|
void tim3(void) __attribute__ ((weak, alias("default_handler")));
|
|
void tim4(void) __attribute__ ((weak, alias("default_handler")));
|
|
void i2c1_ev(void) __attribute__ ((weak, alias("default_handler")));
|
|
void i2c1_er(void) __attribute__ ((weak, alias("default_handler")));
|
|
void i2c2_ev(void) __attribute__ ((weak, alias("default_handler")));
|
|
void i2c2_er(void) __attribute__ ((weak, alias("default_handler")));
|
|
void spi1(void) __attribute__ ((weak, alias("default_handler")));
|
|
void spi2(void) __attribute__ ((weak, alias("default_handler")));
|
|
void usart1(void) __attribute__ ((weak, alias("default_handler")));
|
|
void usart2(void) __attribute__ ((weak, alias("default_handler")));
|
|
void exti15_10(void) __attribute__ ((weak, alias("default_handler")));
|
|
void rtc_alarm(void) __attribute__ ((weak, alias("default_handler")));
|
|
void otg_fs_wkup(void) __attribute__ ((weak, alias("default_handler")));
|
|
void dma1_stream7(void) __attribute__ ((weak, alias("default_handler")));
|
|
void sdio(void) __attribute__ ((weak, alias("default_handler")));
|
|
void tim5(void) __attribute__ ((weak, alias("default_handler")));
|
|
void spi3(void) __attribute__ ((weak, alias("default_handler")));
|
|
void dma2_stream0(void) __attribute__ ((weak, alias("default_handler")));
|
|
void dma2_stream1(void) __attribute__ ((weak, alias("default_handler")));
|
|
void dma2_stream2(void) __attribute__ ((weak, alias("default_handler")));
|
|
void dma2_stream3(void) __attribute__ ((weak, alias("default_handler")));
|
|
void dma2_stream4(void) __attribute__ ((weak, alias("default_handler")));
|
|
void otg_fs(void) __attribute__ ((weak, alias("default_handler")));
|
|
void dma2_stream5(void) __attribute__ ((weak, alias("default_handler")));
|
|
void dma2_stream6(void) __attribute__ ((weak, alias("default_handler")));
|
|
void dma2_stream7(void) __attribute__ ((weak, alias("default_handler")));
|
|
void usart6(void) __attribute__ ((weak, alias("default_handler")));
|
|
void i2c3_ev(void) __attribute__ ((weak, alias("default_handler")));
|
|
void i2c3_er(void) __attribute__ ((weak, alias("default_handler")));
|
|
void fpu(void) __attribute__ ((weak, alias("default_handler")));
|
|
void spi4(void) __attribute__ ((weak, alias("default_handler")));
|
|
void spi5(void) __attribute__ ((weak, alias("default_handler")));
|
|
|
|
void default_handler(void) {
|
|
for (;;) (void) 0;
|
|
}
|
|
|
|
// Create minimal interrupt vector table
|
|
// 16 standard and 86 STM32F411xC/E-specific handlers of 32bit size each
|
|
void (*const interrupt_vector_table[16 + 86])(void) __attribute__((section(".isr_vector"))) = {
|
|
stack_start, // Defined in link.ld
|
|
reset, // Reset
|
|
nmi, // Non maskable interrupt, Clock Security System
|
|
hard_fault, // All class of fault
|
|
mem_manage, // Memory management
|
|
bus_fault, // Pre-fetch fault, memory access fault
|
|
usage_fault, // Undefined instruction or illegal state
|
|
0, 0, 0, 0, // Reserved
|
|
sv_call, // System Service call via SWI instruction
|
|
debug_monitor, // Debug Monitor
|
|
0, // Reserved
|
|
pend_sv, // Pendable request for system service
|
|
systick, // System tick timer
|
|
wwdg, // Window Watchdog interrupt
|
|
pvd, // EXTI Line 16 interrupt / PVD through EXTI line detection interrupt
|
|
tamp_stamp, // EXTI Line 21 interrupt / Tamper and TimeStamp interrupts through the EXTI line
|
|
rtc_wkup, // EXTI Line 22 interrupt / RTC Wakeup interrupt through the EXTI line
|
|
flash, // Flash global interrupt
|
|
rcc, // RCC global interrupt
|
|
exti0, // EXTI Line0 interrupt
|
|
exti1, // EXTI Line1 interrupt
|
|
exti2, // EXTI Line2 interrupt
|
|
exti3, // EXTI Line3 interrupt
|
|
exti4, // EXTI Line4 interrupt
|
|
dma1_stream0, // DMA1 Stream0 global interrupt
|
|
dma1_stream1, // DMA1 Stream1 global interrupt
|
|
dma1_stream2, // DMA1 Stream2 global interrupt
|
|
dma1_stream3, // DMA1 Stream3 global interrupt
|
|
dma1_stream4, // DMA1 Stream4 global interrupt
|
|
dma1_stream5, // DMA1 Stream5 global interrupt
|
|
dma1_stream6, // DMA1 Stream6 global interrupt
|
|
adc, // ADC1 global interrupts
|
|
exti9_5, // EXTI Line[9:5] interrupts
|
|
tim1_brk_tim9, // TIM1 Break interrupt and TIM9 global interrupt
|
|
tim1_up_tim10, // TIM1 Update interrupt and TIM10 global interrupt
|
|
tim1_trg_com_tim11, // TIM1 Trigger and Commutation interrupts and TIM11 global interrupt
|
|
tim1_cc, // TIM1 Capture Compare interrupt
|
|
tim2, // TIM2 global interrupt
|
|
tim3, // TIM3 global interrupt
|
|
tim4, // TIM4 global interrupt
|
|
i2c1_ev, // I2C1 event interrupt
|
|
i2c1_er, // I2C1 error interrupt
|
|
i2c2_ev, // I2C2 event interrupt
|
|
i2c2_er, // I2C2 error interrupt
|
|
spi1, // SPI1 global interrupt
|
|
spi2, // SPI2 global interrupt
|
|
usart1, // USART1 global interrupt
|
|
usart2, // USART2 global interrupt
|
|
exti15_10, // EXTI Line[15:10] interrupts
|
|
rtc_alarm, // EXTI Line 17 interrupt / RTC Alarms (A and B) through EXTI line interrupt
|
|
otg_fs_wkup, // EXTI Line 18 interrupt / USB On-The-Go FS Wakeup through EXTI line interrupt
|
|
dma1_stream7, // MA1 Stream7 global interrupt
|
|
sdio, // SDIO global interrupt
|
|
tim5, // TIM5 global interrupt
|
|
spi3, // SPI3 global interrupt
|
|
dma2_stream0, // DMA2 Stream0 global interrupt
|
|
dma2_stream1, // DMA2 Stream1 global interrupt
|
|
dma2_stream2, // DMA2 Stream2 global interrupt
|
|
dma2_stream3, // DMA2 Stream3 global interrupt
|
|
dma2_stream4, // DMA2 Stream4 global interrupt
|
|
otg_fs, // USB On The Go FS global interrupt
|
|
dma2_stream5, // DMA2 Stream5 global interrupt
|
|
dma2_stream6, // DMA2 Stream6 global interrupt
|
|
dma2_stream7, // DMA2 Stream7 global interrupt
|
|
usart6, // USART6 global interrupt
|
|
i2c3_ev, // I2C3 event interrupt
|
|
i2c3_er, // I2C3 error interrupt
|
|
fpu, // FPU global interrupt
|
|
spi4, // SPI4 global interrupt
|
|
spi5 // SPI5 global interrupt
|
|
};
|