summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBirte Kristina Friesel <derf@finalrewind.org>2024-01-27 18:58:25 +0100
committerBirte Kristina Friesel <derf@finalrewind.org>2024-01-27 18:58:25 +0100
commitb452e3f54fa46579182bc5e5fb993347e182d5a1 (patch)
treead14461de22643e13d2fd1a2f05236c76aac02bd
parent7f98f3fd0d3c0f67cf77370f5480c43681424630 (diff)
MSP430FR5969: Add driver for UART output on eUSCI_A1 (stdout1)
-rw-r--r--include/arch/msp430fr5969lp/driver/stdout1.h24
-rw-r--r--src/arch/msp430fr5969lp/Kconfig10
-rw-r--r--src/arch/msp430fr5969lp/Makefile.inc8
-rw-r--r--src/arch/msp430fr5969lp/driver/stdout1.cc64
4 files changed, 103 insertions, 3 deletions
diff --git a/include/arch/msp430fr5969lp/driver/stdout1.h b/include/arch/msp430fr5969lp/driver/stdout1.h
new file mode 100644
index 0000000..baf5dc7
--- /dev/null
+++ b/include/arch/msp430fr5969lp/driver/stdout1.h
@@ -0,0 +1,24 @@
+/*
+ * Copyright 2020 Birte Kristina Friesel
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+#ifndef STANDARDOUTPUT1_H
+#define STANDARDOUTPUT1_H
+
+#include "object/outputstream.h"
+
+class StandardOutput1 : public OutputStream {
+ private:
+ StandardOutput1(const StandardOutput1 &copy);
+
+ public:
+ StandardOutput1 () {}
+ void setup();
+
+ virtual void put(char c) override;
+};
+
+extern StandardOutput1 kout1;
+
+#endif
diff --git a/src/arch/msp430fr5969lp/Kconfig b/src/arch/msp430fr5969lp/Kconfig
index 2f0f441..b96a032 100644
--- a/src/arch/msp430fr5969lp/Kconfig
+++ b/src/arch/msp430fr5969lp/Kconfig
@@ -27,8 +27,16 @@ config arch_msp430fr5969lp_driver_spi
bool "SPI on eUSCI_B0"
select meta_driver_spi
+config arch_msp430fr5969lp_driver_stdout1
+bool "UART Output on eUSCI_A1 / P2.5"
+help
+ TX: P2.5 (eUSCI_A1 / UCA1TXD)
+select meta_driver_stdout1
+
config arch_msp430fr5969lp_driver_stdin
-bool "UART Input"
+bool "UART Input on eUSCI_A0 / P2.1"
+help
+ RX: P2.1 (eUSCI_A0 / UCA0RXD)
select meta_driver_stdin
config arch_msp430fr5969lp_driver_timer
diff --git a/src/arch/msp430fr5969lp/Makefile.inc b/src/arch/msp430fr5969lp/Makefile.inc
index 583a95a..0412516 100644
--- a/src/arch/msp430fr5969lp/Makefile.inc
+++ b/src/arch/msp430fr5969lp/Makefile.inc
@@ -75,8 +75,12 @@ ifdef CONFIG_arch_msp430fr5969lp_driver_adc
CXX_TARGETS += src/arch/msp430fr5969lp/driver/adc.cc
endif
-ifdef CONFIG_arch_msp430fr5969lp_driver_dmx
- CXX_TARGETS += src/arch/msp430fr5969lp/driver/dmx.cc
+ifdef CONFIG_arch_msp430fr5969lp_driver_dmx1
+ CXX_TARGETS += src/arch/msp430fr5969lp/driver/dmx1.cc
+endif
+
+ifdef CONFIG_arch_msp430fr5969lp_driver_stdout1
+ CXX_TARGETS += src/arch/msp430fr5969lp/driver/stdout1.cc
endif
ifdef CONFIG_arch_msp430fr5969lp_driver_stdin
diff --git a/src/arch/msp430fr5969lp/driver/stdout1.cc b/src/arch/msp430fr5969lp/driver/stdout1.cc
new file mode 100644
index 0000000..576eec0
--- /dev/null
+++ b/src/arch/msp430fr5969lp/driver/stdout1.cc
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2020 Birte Kristina Friesel
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+#include "driver/stdout1.h"
+#include <msp430.h>
+
+/*
+ * Baud rate calculation according to datasheet:
+ * N := f_{BRCLK} / Baudrate = F_CPU / 115200 in our case
+ * if N <= 16: OS16 = 0, UCBR0 = int(N)
+ * if N > 16: OS16 = 1, UCBR0 = int(N/16), UCBRF0 = int(((n/16) - int(n/16)) * 16) = int(N)%16
+ * Set UCBRS0 according to table 21-4
+ */
+
+void StandardOutput1::setup()
+{
+ UCA1CTLW0 |= UCSWRST;
+#if F_CPU == 16000000UL
+ // 16M / 115200 == 138.88889 -> UCOS16 = 1, UCBR0 = 16, UCBRF0 = 10, UCBRS0 = 0xf7 ("0.8751")
+ UCA1CTLW0 = UCSWRST | UCSSEL__SMCLK;
+ UCA1MCTLW = UCOS16 | (10<<4) | 0xF700;
+ UCA1BR0 = 8;
+#elif F_CPU == 8000000UL
+ // 8M / 115200 == 69.444444 -> UCOS16 = 1, UCBR0 = 4, UCBRF0 = 5, UCBRS0 = 0x55 ("0.4378")
+ UCA1CTLW0 = UCSWRST | UCSSEL__SMCLK;
+ UCA1MCTLW = UCOS16 | (5<<4) | 0x5500;
+ UCA1BR0 = 4;
+#elif F_CPU == 4000000UL
+ // 4M / 115200 == 34.722222 -> UCOS16 = 1, UCBR0 = 2, UCBRF0 = 2, UCBRS0 = 0xbb ("0.7147")
+ UCA1CTLW0 = UCSWRST | UCSSEL__SMCLK;
+ UCA1MCTLW = UCOS16 | (2<<4) | 0xbb00;
+ UCA1BR0 = 2;
+#elif F_CPU == 1000000UL
+ // 1M / 115200 == 8.6805556 -> UCOS16 = 0, UCBR0 = 8, UCBRF0 = 0, UCBRS0 = 0xd6 ("0.6667")
+ UCA1CTLW0 = UCSWRST | UCSSEL__SMCLK;
+ UCA1MCTLW = 0x5500;
+ UCA1BR0 = 8;
+#else
+#error Unsupported F_CPU
+#endif
+
+ UCA1IRCTL = 0;
+ UCA1ABCTL = 0;
+
+ P2SEL0 &= ~BIT5;
+ P2SEL1 |= BIT5;
+ P2DIR |= BIT5;
+
+ UCA1CTLW0 &= ~UCSWRST;
+}
+
+void StandardOutput1::put(char c)
+{
+ while (!(UCA1IFG & UCTXIFG));
+ UCA1TXBUF = c;
+
+ if (c == '\n') {
+ put('\r');
+ }
+}
+
+StandardOutput1 kout1;