rp2040: Load vectortable into ram

Load the interrupt vector table into ram at startup.  This reduces the
chance of a flash cache access causing timing instability.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2024-01-20 20:04:16 -05:00
parent 44e79e0c37
commit f1982edcd5
2 changed files with 27 additions and 0 deletions

View File

@ -16,6 +16,26 @@
#include "sched.h" // sched_main
/****************************************************************
* Ram IRQ vector table
****************************************************************/
// Copy vector table to ram and activate it
static void
enable_ram_vectortable(void)
{
// Symbols created by rp2040_link.lds.S linker script
extern uint32_t _ram_vectortable_start, _ram_vectortable_end;
extern uint32_t _text_vectortable_start;
uint32_t count = (&_ram_vectortable_end - &_ram_vectortable_start) * 4;
__builtin_memcpy(&_ram_vectortable_start, &_text_vectortable_start, count);
barrier();
SCB->VTOR = (uint32_t)&_ram_vectortable_start;
}
/****************************************************************
* Bootloader
****************************************************************/
@ -145,6 +165,7 @@ clock_setup(void)
void
armcm_main(void)
{
enable_ram_vectortable();
clock_setup();
sched_main();
}

View File

@ -37,6 +37,12 @@ SECTIONS
. = ALIGN(4);
_data_flash = .;
.ram_vectortable (NOLOAD) : {
_ram_vectortable_start = .;
. = . + ( _text_vectortable_end - _text_vectortable_start ) ;
_ram_vectortable_end = .;
} > ram
.data : AT (_data_flash)
{
. = ALIGN(4);