summaryrefslogtreecommitdiff
path: root/src/arch/stm32f446re-nucleo/driver/stdout.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/arch/stm32f446re-nucleo/driver/stdout.cc')
-rw-r--r--src/arch/stm32f446re-nucleo/driver/stdout.cc31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/arch/stm32f446re-nucleo/driver/stdout.cc b/src/arch/stm32f446re-nucleo/driver/stdout.cc
new file mode 100644
index 0000000..2c20158
--- /dev/null
+++ b/src/arch/stm32f446re-nucleo/driver/stdout.cc
@@ -0,0 +1,31 @@
+#include "driver/stdout.h"
+
+#include <libopencm3/stm32/rcc.h>
+#include <libopencm3/stm32/gpio.h>
+#include <libopencm3/stm32/usart.h>
+
+void StandardOutput::setup()
+{
+ rcc_periph_clock_enable(RCC_USART2);
+ gpio_mode_setup(GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO2);
+ gpio_set_af(GPIOA, GPIO_AF7, GPIO2);
+
+ usart_set_baudrate(USART2, 115200);
+ usart_set_databits(USART2, 8);
+ usart_set_stopbits(USART2, USART_STOPBITS_1);
+ usart_set_mode(USART2, USART_MODE_TX);
+ usart_set_parity(USART2, USART_PARITY_NONE);
+ usart_set_flow_control(USART2, USART_FLOWCONTROL_NONE);
+
+ usart_enable(USART2);
+}
+
+void StandardOutput::put(char c)
+{
+ usart_send_blocking(USART2, c);
+ if (c == '\n') {
+ put('\r');
+ }
+}
+
+StandardOutput kout;