From 0432ae374547f65eedababcf91bca77f047b7ba5 Mon Sep 17 00:00:00 2001
From: Angus Gratton <gus@projectgus.com>
Date: Mon, 14 Sep 2015 17:19:09 +1000
Subject: [PATCH] Use GPIO2 for led_debug.S

---
 core/exception_vectors.S                             | 3 ++-
 core/led_debug.s                                     | 8 +++++---
 examples/experiments/unaligned_load/unaligned_load.c | 4 ++++
 3 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/core/exception_vectors.S b/core/exception_vectors.S
index 7e8241c..9d700b2 100644
--- a/core/exception_vectors.S
+++ b/core/exception_vectors.S
@@ -16,6 +16,8 @@
    BSD Licensed as described in the file LICENSE
 */
 
+#include "led_debug.s"
+
 /* Some UserException causes, see table Table 4–64 in ISA reference */
 #define CAUSE_SYSCALL 1
 #define CAUSE_LOADSTORE 3
@@ -314,7 +316,6 @@ InnerLoadStoreExceptionHandler:
 	/* verified an 8- or 16-bit read
 	a2 holds instruction, a5 holds mask to apply to read value
 	*/
-
 	rsr.excvaddr a3 // read faulting address
 	ssa8l a3 /* sar is now shift to extract a3's byte */
 	movi	a4, ~3
diff --git a/core/led_debug.s b/core/led_debug.s
index 8196c9e..28caf65 100644
--- a/core/led_debug.s
+++ b/core/led_debug.s
@@ -4,6 +4,8 @@
  *
  * To have this work from initial reset, without needing an iomux call
  * first, choose a pin where iomux defaults to GPIO (ie 0,2,4,5)
+ *
+ * Current sets on=LOW, as the GPIO2 pin is active low
  */
 LED_GPIO=2
 GPIO_DIR_SET = 0x6000030c
@@ -19,11 +21,11 @@ GPIO_OUT_CLEAR = 0x60000308
 .endm
 
 // Turn LED on. rega, regb will be clobbered
-.macro led_on rega, regb
+.macro led_off rega, regb
 	led_op \rega, \regb, GPIO_OUT_SET
 .endm
 
-// Turn LED off. rega, regb will be clobbered
-.macro led_off rega, regb
+// Turn LED on. rega, regb will be clobbered
+.macro led_on rega, regb
 	led_op \rega, \regb, GPIO_OUT_CLEAR
 .endm
diff --git a/examples/experiments/unaligned_load/unaligned_load.c b/examples/experiments/unaligned_load/unaligned_load.c
index e7c7c8e..dd45a44 100644
--- a/examples/experiments/unaligned_load/unaligned_load.c
+++ b/examples/experiments/unaligned_load/unaligned_load.c
@@ -121,6 +121,10 @@ void test_string(const char *string, char *label, bool evict_cache)
 void user_init(void)
 {
     sdk_uart_div_modify(0, UART_CLK_FREQ / 115200);
+
+    gpio_enable(2, GPIO_OUTPUT); /* used for LED debug */
+    gpio_write(2, 1); /* active low */
+
     printf("\r\n\r\nSDK version:%s\r\n", sdk_system_get_sdk_version());
     test_string(dramtest, "DRAM", 0);
     test_string(iramtest, "IRAM", 0);