serial support
This commit is contained in:
parent
67243b6d98
commit
a93e506b78
2
Makefile
2
Makefile
@ -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
|
||||
|
||||
|
8
include/serial.h
Normal file
8
include/serial.h
Normal file
@ -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_
|
BIN
lib/liblua.a
BIN
lib/liblua.a
Binary file not shown.
25
src/main.c
25
src/main.c
@ -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));
|
||||
}
|
||||
}
|
||||
|
27
src/serial.c
Normal file
27
src/serial.c
Normal file
@ -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;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user