aboutsummaryrefslogtreecommitdiffstats
path: root/src/rp2040
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2024-01-20 20:04:16 -0500
committerKevin O'Connor <kevin@koconnor.net>2024-01-25 11:05:11 -0500
commitf1982edcd5e68328a824ae9998e63778b08581e7 (patch)
tree497700f54344ffdec290d226207a30ca0e264b49 /src/rp2040
parent44e79e0c37a440212a1b7f974adbdbe250e91f83 (diff)
downloadkutter-f1982edcd5e68328a824ae9998e63778b08581e7.tar.gz
kutter-f1982edcd5e68328a824ae9998e63778b08581e7.tar.xz
kutter-f1982edcd5e68328a824ae9998e63778b08581e7.zip
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>
Diffstat (limited to 'src/rp2040')
-rw-r--r--src/rp2040/main.c21
-rw-r--r--src/rp2040/rp2040_link.lds.S6
2 files changed, 27 insertions, 0 deletions
diff --git a/src/rp2040/main.c b/src/rp2040/main.c
index 0b144d0b..e7b64e5f 100644
--- a/src/rp2040/main.c
+++ b/src/rp2040/main.c
@@ -17,6 +17,26 @@
/****************************************************************
+ * 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();
}
diff --git a/src/rp2040/rp2040_link.lds.S b/src/rp2040/rp2040_link.lds.S
index fd178847..9b0264a2 100644
--- a/src/rp2040/rp2040_link.lds.S
+++ b/src/rp2040/rp2040_link.lds.S
@@ -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);