]> begriffs open source - cmsis-driver-bare/blob - lib/sram_vtor.c
Pass cmsis validator test
[cmsis-driver-bare] / lib / sram_vtor.c
1 #include "stm32f4xx.h"
2 #include "sram_vtor.h"
3
4 // #include <assert.h>
5 #include <string.h>
6
7 // symbol from picolibc stored in flash memory
8
9 extern const void *__interrupt_vector[];
10
11 // Reference manual for STM32F411xC/E
12 // 10.1.3:
13 //
14 // The full vector table takes 0x198=408 bytes, with each entry requiring four
15 // bytes.
16 //
17 // ArmĀ®v7-M Architecture Reference Manual
18 // B1.5.3:
19 //
20 // The Vector table must be naturally aligned to a power of two whose alignment
21 // value is greater than or equal to (Number of Exceptions supported x 4), with
22 // a minimum alignment of 128 bytes.
23
24 static
25 void (*sram_vectors[408/4])(void)
26         __attribute__((aligned(512)));
27
28 void NVIC_Relocate_VTOR(void)
29 {
30         // sanity-check that the memory alignment is such that no bits of the
31         // address fall outside the VTOR register's bector table base offset field
32
33         // assert( 0U == (((uintptr_t)sram_vectors) & ~SCB_VTOR_TBLOFF_Msk) );
34
35         // picolibc arm/interrupt.c assigns vectors up through systick (0x40
36         // bytes), which we'll relocate to the new sram location
37         memcpy(sram_vectors, __interrupt_vector, 0x40);
38         __DSB(); // ensure all memory is written before pointing VTOR at it
39         SCB->VTOR = (uintptr_t)sram_vectors;
40 }