aboutsummaryrefslogtreecommitdiffstats
path: root/examples/test-fsmc.cpp
diff options
context:
space:
mode:
authorMarti Bolivar <mbolivar@leaflabs.com>2011-05-09 16:35:13 -0400
committerMarti Bolivar <mbolivar@leaflabs.com>2011-05-09 16:40:58 -0400
commit868fb1c273e562a1140abfa948022c9d4f55bccf (patch)
tree73067aa8cf6f8bd0d7663a634c1f878a78b567ed /examples/test-fsmc.cpp
parent47c53377292a4db28057fc6394c928cde3727e97 (diff)
downloadlibrambutan-868fb1c273e562a1140abfa948022c9d4f55bccf.tar.gz
librambutan-868fb1c273e562a1140abfa948022c9d4f55bccf.zip
Reverting commits between `git merge-head master refactor` and master.
This is a combination of 11 revert commits, and allows for a clean merge of the work done in the refactor branch. The combined commit messages follow. Revert "Committing basic ring_buffer test." This reverts commit 987fa5f433e0cd41b1621dad8b4e331cf82d49f3. Revert "qa-slave-shield.cpp and test-session.cpp fixes for Mini and RET6 Edition." This reverts commit cdd367bdd264c9e19180032c119850fbba2115ba. Revert "Brought examples/ up to date; PIN_MAP bugfix for D24." This reverts commit b4c2d4514c6d52cac8a649c5d5c24b68a3c0a416. Revert "Separated GPIO config to a separate FSMC routine." This reverts commit 744848ad0fc33eed66acc44e41c3c9d646c5b100. Revert "Slightly faster RAM writes (6.5MHz)." This reverts commit 8ba0b6bb065acb4aff26bc9c838de5f37515caf1. Revert "FSMC working but slow (~6 MHz)." This reverts commit 0dc9490cf4f4f10a23b08fef1728773f10c1b76a. Revert "Maple Mini ERROR_LED_PIN fix." This reverts commit 07d437706840901db1e09ff0ab88229c67c1fa8a. Revert "Fixing USBSerial::read(void*, uint32) return value (thanks, Crenn!)" This reverts commit 3ba7196712a5bfe4fe1166b6c34d49c3d7254568. Revert "Trivial gpio_init() bugfix" This reverts commit f6ce003bb935f26eeefa54acf7c2ae6afaabd871. Revert "Trivial changes to test-session.cpp" This reverts commit a32a37b121ac7e62660d2a83fe67c857fe705122. Revert ".gitignore: Ignore cscope* files" This reverts commit d8c72c17bd6d7416a0846e69f4f5ae5cb229d58e.
Diffstat (limited to 'examples/test-fsmc.cpp')
-rw-r--r--examples/test-fsmc.cpp202
1 files changed, 105 insertions, 97 deletions
diff --git a/examples/test-fsmc.cpp b/examples/test-fsmc.cpp
index d1c8567..f4fd068 100644
--- a/examples/test-fsmc.cpp
+++ b/examples/test-fsmc.cpp
@@ -1,111 +1,119 @@
-#include <stdio.h>
-#include <stddef.h>
#include "wirish.h"
#include "fsmc.h"
-#define LED BOARD_LED_PIN
-
-// Start of FSMC SRAM bank 1
-static uint16 *const ptr_start = (uint16*)0x60000000;
-// End of Maple Native SRAM chip address space (512K 16-bit words)
-static uint16 *const ptr_end = (uint16*)0x60080000;
-// For snprintf
-static char buf[100];
+#define LED_PIN 23 // hack for maple native
+#define DISC_PIN 14 // hack for USB on native
+
+// System control block registers
+#define SCB_BASE (SCB_Reg*)(0xE000ED00)
+
+// This stuff should ultimately get moved to util.h or scb.h or w/e.
+// Also in interactive test program and the HardFault IRQ handler.
+typedef struct {
+ volatile uint32 CPUID;
+ volatile uint32 ICSR;
+ volatile uint32 VTOR;
+ volatile uint32 AIRCR;
+ volatile uint32 SCR;
+ volatile uint32 CCR;
+ volatile uint32 SHPR1;
+ volatile uint32 SHPR2;
+ volatile uint32 SHPR3;
+ volatile uint32 SHCRS;
+ volatile uint32 CFSR;
+ volatile uint32 HFSR;
+ uint32 pad1;
+ volatile uint32 MMAR;
+ volatile uint32 BFAR;
+} SCB_Reg;
+
+SCB_Reg *scb;
+
+uint16 *ptr;
+int toggle = 0;
+int count = 0;
void setup() {
- pinMode(LED, OUTPUT);
- digitalWrite(LED, HIGH);
-
- Serial1.begin(115200);
- Serial1.println("Hello World!");
-
- Serial1.print("Initializing RAM chip... ");
- fsmc_native_sram_init();
- Serial1.println("Done.");
+ uint32 id;
+ scb = (SCB_Reg*)SCB_BASE;
+
+ pinMode(LED_PIN, OUTPUT);
+ pinMode(DISC_PIN, OUTPUT);
+ digitalWrite(DISC_PIN,1);
+ digitalWrite(LED_PIN,1);
+
+ Serial1.begin(9600);
+ Serial1.println("Hello World!");
+
+ Serial1.print("Init... ");
+ fsmc_native_sram_init();
+ Serial1.println("Done.");
+
+ // Start of channel1 SRAM bank (through to 0x63FFFFFF, though only a chunk
+ // of this is valid)
+ ptr = (uint16*)(0x60000000);
+
+ Serial1.print("Writing... ");
+ *ptr = 0x1234;
+ Serial1.println("Done.");
+
+ Serial1.print("Reading... ");
+ id = *ptr;
+ Serial1.print("Done: "); // shouldn't be 0xFFFFFFFF
+ Serial1.println(id,BIN);
+
+ Serial1.println("Dumping System Control Block Registers");
+ Serial1.print("CPUID: ");
+ id = scb->CPUID;
+ Serial1.println(id,BIN);
+ Serial1.print("ICSR: ");
+ id = scb->ICSR;
+ Serial1.println(id,BIN);
+ Serial1.print("CFSR: ");
+ id = scb->CFSR;
+ Serial1.println(id,BIN);
+ Serial1.print("HFSR: ");
+ id = scb->HFSR;
+ Serial1.println(id,BIN);
+ Serial1.print("MMAR: ");
+ id = scb->MMAR;
+ Serial1.println(id,BIN);
+ Serial1.print("BFAR: ");
+ id = scb->BFAR;
+ Serial1.println(id,BIN);
+
+ Serial1.println("Now testing all memory addresses... (will hardfault at the end)");
+ delay(3000);
}
-void test_single_write() {
- uint16 *ptr = ptr_start;
- uint16 tmp;
-
- Serial1.print("Writing 0x1234... ");
- *ptr = 0x1234;
- Serial1.println("Done.");
-
- Serial1.print("Reading... ");
- tmp = *ptr;
- Serial1.print("Done: 0x");
- Serial1.println(tmp, HEX);
-
- if (tmp != 0x1234) {
- Serial1.println("Mismatch, abort.");
- ASSERT(0);
- }
-}
-
-void test_all_addresses() {
- uint32 start, end;
- uint16 count = 0;
- uint16 *ptr;
- Serial1.println("Now writing all memory addresses (unrolled loop)");
- SerialUSB.end();
- start = micros();
- for (ptr = ptr_start; ptr < ptr_end;) {
- *ptr++ = count++;
- *ptr++ = count++;
- *ptr++ = count++;
- *ptr++ = count++;
- *ptr++ = count++;
- *ptr++ = count++;
- *ptr++ = count++;
- *ptr++ = count++;
- *ptr++ = count++;
- *ptr++ = count++;
- *ptr++ = count++;
- *ptr++ = count++;
- *ptr++ = count++;
- *ptr++ = count++;
- *ptr++ = count++;
- *ptr++ = count++;
- }
- end = micros();
- SerialUSB.begin();
- Serial1.print("Done. Elapsed time (us): ");
- Serial1.println(end - start);
-
- Serial1.println("Validating writes.");
- for (ptr = ptr_start, count = 0; ptr < ptr_end; ptr++, count++) {
- if (*ptr != count) {
- snprintf(buf, sizeof buf, "mismatch: %p = 0x%xu, should be 0x%xu.",
- ptr, *ptr, count);
- Serial1.println(buf);
- ASSERT(0);
+void loop() {
+ digitalWrite(LED_PIN, toggle);
+ toggle ^= 1;
+ delay(1);
+
+ for(int i = 0; i<100; i++) { // modify this to speed things up
+ count++;
+ ptr++;
+ //delay(10); // tweak this to test SRAM resiliance over time
+ *ptr = (0x0000FFFF & count);
+ if(*ptr != (0x0000FFFF & count)) {
+ Serial1.println("ERROR: mismatch, halting");
+ while(1) { }
}
- }
- ptrdiff_t nwrites = ptr_end - ptr_start;
- double us_per_write = double(end-start) / double(nwrites);
- Serial1.println("Done; all writes seem valid.");
- snprintf(buf, sizeof buf,
- "Number of writes = %d; avg. time per write = %g us (%g MHz)",
- nwrites, us_per_write, 1 / us_per_write);
- Serial1.println(buf);
-}
-
-__attribute__((constructor)) void premain() {
- init();
+ }
+
+ Serial1.print((uint32)(ptr),HEX);
+ Serial1.print(": ");
+ Serial1.println(*ptr,BIN);
}
int main(void) {
- setup();
-
- test_single_write();
- test_all_addresses();
-
- Serial1.println("Tests pass, finished.");
-
- while (true)
- ;
+ init();
+ setup();
- return 0;
+ while (1) {
+ loop();
+ }
+ return 0;
}