Example showing \"hang\" when reading from bad pointer, and catching this in the HardFault_Handler

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
simon
Date:
Sun Mar 04 08:03:59 2012 +0000
Commit message:

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	Sun Mar 04 08:03:59 2012 +0000
@@ -0,0 +1,30 @@
+// Example of hanging when reading a bad pointer
+
+#include "mbed.h"
+
+DigitalOut myled(LED1);
+
+int x[10] = {0};
+
+extern "C" void HardFault_Handler() {
+    error("Hit HardFault handler!\n");
+}
+
+int main() {
+    int *ok_ptr = x;
+    int *bad_ptr = (int*)0xe600b0; // not in RAM!
+    printf("ok_ptr = 0x%08X, bad_ptr = 0x%08X\n", ok_ptr, bad_ptr);
+    
+    int ok_read = ok_ptr[0];
+    printf("ok_read = %d\n", ok_read);
+    
+    int bad_read = bad_ptr[0]; 
+    printf("bad_read = %d\n", bad_read);
+
+    while(1) {
+        myled = 1;
+        wait(0.2);
+        myled = 0;
+        wait(0.2);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sun Mar 04 08:03:59 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/4c0c40fd0593