diff options
Diffstat (limited to 'usart_irq')
-rw-r--r-- | usart_irq/Makefile | 34 | ||||
-rw-r--r-- | usart_irq/main.c | 85 |
2 files changed, 119 insertions, 0 deletions
diff --git a/usart_irq/Makefile b/usart_irq/Makefile new file mode 100644 index 0000000..09b7d30 --- /dev/null +++ b/usart_irq/Makefile @@ -0,0 +1,34 @@ +PROJECT = usart_irq +BUILD_DIR = bin + +SHARED_DIR = ../libraries +CFILES = main.c +CFILES += usart.c fifo.c +#AFILES += api-asm.S + +# TODO - you will need to edit these two lines! +DEVICE=stm32f103c8 +#OOCD_FILE = board/stm32f4discovery.cfg + +# You shouldn't have to edit anything below here. +VPATH += $(SHARED_DIR) +INCLUDES += $(patsubst %,-I%, . $(SHARED_DIR)) +OPENCM3_DIR=../libopencm3 + +include $(OPENCM3_DIR)/mk/genlink-config.mk +include ../rules.mk +include $(OPENCM3_DIR)/mk/genlink-rules.mk + + +# Black Magic Probe: + +GDB=/usr/bin/arm-none-eabi-gdb +BMP_DEVICE=/dev/ttyACM0 + +bmp: $(PROJECT).elf + $(GDB) $(PROJECT).elf \ + -ex 'set confirm off' \ + -ex 'target extended-remote $(BMP_DEVICE)' \ + -ex 'monitor swdp_scan' \ + -ex 'attach 1' + diff --git a/usart_irq/main.c b/usart_irq/main.c new file mode 100644 index 0000000..c3e7966 --- /dev/null +++ b/usart_irq/main.c @@ -0,0 +1,85 @@ + + +#include <errno.h> +#include <stdio.h> +#include <unistd.h> + +#include <libopencm3/stm32/rcc.h> +#include <libopencm3/stm32/gpio.h> + +#include "usart.h" + + +#define DELAY 1000000 + + +void clock_init(void); +void gpio_init(void); +void delay(void); +int _write(int file, char *ptr, int len); + + +USART usart3; + + +int main(void) +{ + clock_init(); + gpio_init(); + usart_init(&usart3); + + gpio_set(GPIOC, GPIO13); + + char welcome[] = "Hallo Freunde!\r"; + usart_write(&usart3, welcome); + + uint8_t buff; + + while(1){ + if (usart_read_bytes(&usart3, &buff, 1)){ + usart_write_bytes(&usart3, &buff, 1); + } + } + + return 0; +} + + +void clock_init(void) +{ + rcc_periph_clock_enable(RCC_GPIOC); // for PC13 blinking +} + + +void gpio_init(void) +{ + gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO13); + gpio_clear(GPIOC, GPIO13); +} + + +void delay(void) +{ + for (int i = 0; i < DELAY; i++) { + __asm__("nop"); + } +} + + +int _write(int file, char *ptr, int len) +{ + int i; + + if (file == STDOUT_FILENO || file == STDERR_FILENO) { + for (i = 0; i < len; i++) { + if (ptr[i] == '\n') { + uint8_t cr = (uint8_t)'\r'; + usart_write_bytes(&usart3, &cr, 1); + } + usart_write_bytes(&usart3, (uint8_t *)&ptr[i], 1); + } + return i; + } + errno = EIO; + return -1; +} |