summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2017-09-02 17:26:31 (GMT)
committerChristian Pointner <equinox@spreadspace.org>2017-09-02 17:26:31 (GMT)
commit52a42de2c34f9eb0dd8cd81bad755db6c4857537 (patch)
tree31da5b3dc92b7df2cd37f86c85207700698b81dc
parent6265e46a54402744f9e8d66ddfd325a30ffef8f0 (diff)
serial-led example works now tooHEADmaster
-rw-r--r--defines.mk9
-rw-r--r--lib/serialio.c26
-rw-r--r--serial-led/Makefile2
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