Make a copy of the vector table and set the STM32 vector table offset to the new table. Program freezes soon after.

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
riaancillie
Date:
Sat Jul 25 20:11:51 2015 +0000
Commit message:
Test vector table relocation;

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sat Jul 25 20:11:51 2015 +0000
@@ -0,0 +1,43 @@
+#include "mbed.h"
+
+//------------------------------------
+// Hyperterminal configuration
+// 115200 bauds, 8-bit data, no parity
+//------------------------------------
+
+Serial pc(SERIAL_TX, SERIAL_RX); 
+DigitalOut myled(LED1);
+ 
+extern uint32_t __Vectors[];              
+#define VECTORTABLE_SIZE        (512)     
+#define VECTORTABLE_ALIGNMENT   (0x200ul)                                           
+uint32_t vectorTable_RAM[VECTORTABLE_SIZE] __attribute__(( aligned (VECTORTABLE_ALIGNMENT) )); 
+int j;
+   
+int main() {
+  int i = 1;
+  pc.baud(115200);
+  pc.printf("Hello World !\r\n");
+    
+  //Duplicate and relocate the vector table 
+  for (i = 0; i < VECTORTABLE_SIZE; i++) {
+    vectorTable_RAM[i] = __Vectors[i];            /* copy vector table to RAM */
+  }
+  __disable_irq();
+  SCB->VTOR = (uint32_t)(&vectorTable_RAM);
+  __DSB();
+  __enable_irq();
+  
+  //Print 100 lines - this is where things just go wrong and the program freezes
+  for (j = 0; j <= 100; j++) 
+  {
+    pc.printf("test %d\r\n", j);    
+  }
+
+  while(1) { 
+      wait(1);
+      pc.printf("This program runs since %d seconds.\r\n", i++);
+      myled = !myled;
+  }
+}
+ 
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sat Jul 25 20:11:51 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/bad568076d81
\ No newline at end of file