Blinks an LED from the reset ISR
authorMatt Mullins <mmullins@mmlx.us>
Sun, 23 Dec 2012 02:57:24 +0000 (18:57 -0800)
committerMatt Mullins <mmullins@mmlx.us>
Sun, 23 Dec 2012 02:57:47 +0000 (18:57 -0800)
Makefile
isr_table.c
led_blink.c [new file with mode: 0644]
led_blink.h [new file with mode: 0644]

index c08c72a..251d061 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -3,7 +3,7 @@ CC=$(ARCH)-gcc
 LD=$(ARCH)-ld
 OBJCOPY=$(ARCH)-objcopy
 
-CFLAGS=-mcpu=cortex-m4 -nostdinc -I $(STELLARISWARE)/inc
+CFLAGS=-ggdb -std=gnu99 -mcpu=cortex-m4 -nostdinc -I $(STELLARISWARE)/inc
 LDFLAGS=-Tstellaris.t
 
 STELLARISWARE=/home/mmullins/projects/stellaris/StellarisWare
@@ -13,7 +13,7 @@ all: led_blink.bin
 %.o: %.c
        $(CC) $(CFLAGS) -c -o $@ $^
 
-led_blink: isr_table.o
+led_blink: isr_table.o led_blink.o
        $(LD) $(LDFLAGS) -o $@ $^
 
 led_blink.bin: led_blink
index 198e8f1..e013b40 100644 (file)
@@ -1,9 +1,11 @@
+#include "led_blink.h"
+
 static void infinite_loop_isr();
 
 __attribute__((section(".reset")))
 void (*reset_vectors[])() = {
        (void(*)()) 0x20007000,
-       infinite_loop_isr,
+       main_isr,
        infinite_loop_isr,
        infinite_loop_isr,
        infinite_loop_isr,
diff --git a/led_blink.c b/led_blink.c
new file mode 100644 (file)
index 0000000..9b0f47b
--- /dev/null
@@ -0,0 +1,32 @@
+#include "led_blink.h"
+#include <lm4f120h5qr.h>
+
+__attribute__((isr))
+void main_isr() {
+       // Enable Port F
+       SYSCTL_RCGCGPIO_R = 0x20;
+
+       // Wait for a few clocks to let GPIO module stabilize
+       for (int i = 0; i < 10; ++i) {
+       }
+
+       // RGB pins (PF1, 2, 3) as outputs
+       GPIO_PORTF_DIR_R = 0xE;
+
+       // deliver 2mA of current
+       GPIO_PORTF_DR2R_R = 0xE;
+
+       // set to digital mode
+       GPIO_PORTF_DEN_R = 0xE;
+
+       // Set RGB pins to 1
+       *(GPIO_PORTF_DATA_BITS_R + 0xE) = 0x2;
+
+       // infinite loop
+       for (;;) { 
+               *(GPIO_PORTF_DATA_BITS_R + 0xC) ^= 0xC;
+
+               for (int j = 0; j < 1000000; ++j) {
+               }
+       }
+}
diff --git a/led_blink.h b/led_blink.h
new file mode 100644 (file)
index 0000000..24c4feb
--- /dev/null
@@ -0,0 +1,6 @@
+#ifndef __led_blink_H__
+#define __led_blink_H__
+
+extern void main_isr();
+
+#endif