#include "stm32f4xx.h" #include "sram_vtor.h" // #include #include // symbol from picolibc stored in flash memory extern const void *__interrupt_vector[]; // Reference manual for STM32F411xC/E // 10.1.3: // // The full vector table takes 0x198=408 bytes, with each entry requiring four // bytes. // // Arm®v7-M Architecture Reference Manual // B1.5.3: // // The Vector table must be naturally aligned to a power of two whose alignment // value is greater than or equal to (Number of Exceptions supported x 4), with // a minimum alignment of 128 bytes. static void (*sram_vectors[408/4])(void) __attribute__((aligned(512))); void NVIC_Relocate_VTOR(void) { // sanity-check that the memory alignment is such that no bits of the // address fall outside the VTOR register's bector table base offset field // assert( 0U == (((uintptr_t)sram_vectors) & ~SCB_VTOR_TBLOFF_Msk) ); // picolibc arm/interrupt.c assigns vectors up through systick (0x40 // bytes), which we'll relocate to the new sram location memcpy(sram_vectors, __interrupt_vector, 0x40); __DSB(); // ensure all memory is written before pointing VTOR at it SCB->VTOR = (uintptr_t)sram_vectors; }