diff options
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | include/serial.h | 8 | ||||
-rw-r--r-- | lib/liblua.a | bin | 172446 -> 0 bytes | |||
-rw-r--r-- | src/main.c | 25 | ||||
-rw-r--r-- | src/serial.c | 27 |
5 files changed, 54 insertions, 8 deletions
@@ -17,7 +17,7 @@ OFILES = $(patsubst src/%.c, $(OUTDIR)/%.o, $(CFILES)) \ $(patsubst src/%.s, $(OUTDIR)/%.asm.o, $(AFILES)) LIBDIR = -Llib -LIBS = -llua +LIBS = HEX = main.hex diff --git a/include/serial.h b/include/serial.h new file mode 100644 index 0000000..5b90748 --- /dev/null +++ b/include/serial.h @@ -0,0 +1,8 @@ +#ifndef SERIAL_H_ +#define SERIAL_H_ + +void serial_init(void); +void serial_put(int c); +char serial_get(void); + +#endif // SERIAL_H_ diff --git a/lib/liblua.a b/lib/liblua.a Binary files differdeleted file mode 100644 index d5a4c6b..0000000 --- a/lib/liblua.a +++ /dev/null @@ -5,6 +5,7 @@ #include <gpio.h>
#include <lcd.h>
#include <initrd.h>
+#include <serial.h>
/**
* Accomplishments:
@@ -15,7 +16,8 @@ * - gpio lib
* - lcd support
* - initrd support
- * - lua?
+ * - lua? - no, something better, smaller
+ * - serial IO
*/
void pulse(uint8_t byte);
@@ -35,12 +37,14 @@ int main(void) gpio_mode(GPIOA, 5, OUTPUT);
+ serial_init();
+
task_init(kmain);
while (1);
}
-void task(void);
+void serial_getter(void);
void kmain(void)
{
asm("cpsie i");
@@ -48,12 +52,11 @@ void kmain(void) task_start(lcd_handler, 128);
delay(200);
- char *s = initrd_getfile("test.txt");
- const char *t = "Yoyoyo";
-
- asm("mov r0, %0; svc 2" :: "r" (s));
- asm("mov r0, %0; svc 2" :: "r" (t));
+ //char *s = initrd_getfile("test.txt");
+ // svc puts
+ //asm("mov r0, %0; svc 2" :: "r" (s));
+ task_start(serial_getter, 128);
while (1) {
gpio_dout(GPIOA, 5, 1);
delay(500);
@@ -62,3 +65,11 @@ void kmain(void) }
}
+void serial_getter(void)
+{
+ char buf[2] = { 0, 0 };
+ while (1) {
+ buf[0] = serial_get();
+ asm("mov r0, %0; svc 2" :: "r" (buf));
+ }
+}
diff --git a/src/serial.c b/src/serial.c new file mode 100644 index 0000000..692faf0 --- /dev/null +++ b/src/serial.c @@ -0,0 +1,27 @@ +#include <stm32l476xx.h> +#include <gpio.h> + +void serial_init(void) +{ + gpio_mode(GPIOA, 2, ALTERNATE); + gpio_mode(GPIOA, 3, ALTERNATE); + GPIOA->AFR[0] &= ~(0x0000FF00); + GPIOA->AFR[0] |= 0x00007700; + RCC->APB1ENR1 |= RCC_APB1ENR1_USART2EN; + + // start usart device + USART2->BRR = 80000000L / 115200L; + USART2->CR1 |= USART_CR1_TE | USART_CR1_RE | USART_CR1_UE; +} + +void serial_put(int c) +{ + while (!(USART2->ISR & USART_ISR_TXE)); + USART2->TDR = c & 0xFF; +} + +char serial_get(void) +{ + while (!(USART2->ISR & USART_ISR_RXNE)); + return USART2->RDR & 0xFF; +} |