From 52a42de2c34f9eb0dd8cd81bad755db6c4857537 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Sat, 2 Sep 2017 19:26:31 +0200 Subject: serial-led example works now too --- defines.mk | 9 +++++++-- lib/serialio.c | 26 ++++++++++++++++++++++++++ serial-led/Makefile | 2 +- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/defines.mk b/defines.mk index 6d8669a..62551a4 100644 --- a/defines.mk +++ b/defines.mk @@ -24,18 +24,20 @@ ifeq ($(BOARD_TYPE),discovery) MCU := stm8s105c6 F_XTAL := 16000000 SPL_MCU := STM8S105 + PROG := stlink LED_CNT := 1 LED_GPIO := GPIOD LED_PINNUM := 0 - PROG := stlink + SERIAL_IO := UART2 endif ifeq ($(BOARD_TYPE),stm8blue) MCU := stm8s103f3 SPL_MCU := STM8S103 + PROG := stlinkv2 LED_CNT := 1 LED_GPIO := GPIOB LED_PINNUM := 5 - PROG := stlinkv2 + SERIAL_IO := UART1 endif CC = sdcc @@ -63,6 +65,9 @@ ifdef LED_CNT CFLAGS += -DLED_GPIO=$(LED_GPIO) CFLAGS += -DLED_PINNUM=$(LED_PINNUM) endif +ifdef SERIAL_IO + CFLAGS += -DSERIAL_IO_$(SERIAL_IO) +endif ## Linker flags diff --git a/lib/serialio.c b/lib/serialio.c index 899ca3e..eec6193 100644 --- a/lib/serialio.c +++ b/lib/serialio.c @@ -24,18 +24,38 @@ #include "serialio.h" + void putchar(char c) { +#if defined(SERIAL_IO_UART1) + while (UART1_GetFlagStatus(UART1_FLAG_TXE) == RESET); + UART1_SendData8(c); +#elif defined(SERIAL_IO_UART2) while (UART2_GetFlagStatus(UART2_FLAG_TXE) == RESET); UART2_SendData8(c); +#else + #error "serial-io library is not usable for this board" +#endif } char getchar(void) { +#if defined(SERIAL_IO_UART1) + return UART1_ReceiveData8(); +#elif defined(SERIAL_IO_UART2) return UART2_ReceiveData8(); +#else + #error "serial-io library is not usable for this board" +#endif } void serialio_init(const uint32_t baudrate) { +#if defined(SERIAL_IO_UART1) + UART1_Init(baudrate, UART1_WORDLENGTH_8D, UART1_STOPBITS_1, UART1_PARITY_NO, UART1_SYNCMODE_CLOCK_DISABLE, UART1_MODE_TXRX_ENABLE); +#elif defined(SERIAL_IO_UART2) UART2_Init(baudrate, UART2_WORDLENGTH_8D, UART2_STOPBITS_1, UART2_PARITY_NO, UART2_SYNCMODE_CLOCK_DISABLE, UART2_MODE_TXRX_ENABLE); +#else + #error "serial-io library is not usable for this board" +#endif } void serialio_task(void) @@ -44,5 +64,11 @@ void serialio_task(void) uint8_t serialio_bytes_received(void) { +#if defined(SERIAL_IO_UART1) + return (UART1_GetFlagStatus(UART1_FLAG_RXNE) == RESET) ? 0 : 1; +#elif defined(SERIAL_IO_UART2) return (UART2_GetFlagStatus(UART2_FLAG_RXNE) == RESET) ? 0 : 1; +#else + #error "serial-io library is not usable for this board" +#endif } diff --git a/serial-led/Makefile b/serial-led/Makefile index a039111..607adff 100644 --- a/serial-led/Makefile +++ b/serial-led/Makefile @@ -21,7 +21,7 @@ ## NAME := serial-led -BOARD_TYPE := discovery +BOARD_TYPE := stm8blue OBJ := $(NAME).rel LIBS := util led serialio EXTERNAL_LIBS := spl -- cgit v1.2.3