summaryrefslogtreecommitdiffstats
path: root/boot/usart.c
diff options
context:
space:
mode:
Diffstat (limited to 'boot/usart.c')
-rw-r--r--boot/usart.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/boot/usart.c b/boot/usart.c
new file mode 100644
index 0000000..c602710
--- /dev/null
+++ b/boot/usart.c
@@ -0,0 +1,68 @@
+#include "project.h"
+
+
+#define TX2 GPIO5
+#define TX2_PORT GPIOD
+
+#define RX2 GPIO6
+#define RX2_PORT GPIOD
+
+
+void
+usart2_xmit_chr (char d)
+{
+ usart_send_blocking (USART2, d);
+}
+
+
+void
+usart2_xmit_str (const char *s)
+{
+ while (*s)
+ usart_send_blocking (USART2, * (s++));
+}
+
+
+void usart2_xmit_nl (void)
+{
+ usart2_xmit_str ("\r\n");
+}
+
+void usart2_xmit_xdigit (unsigned d)
+{
+ if (d < 0xa) usart2_xmit_chr ('0' + d);
+ else usart2_xmit_chr ('a' + (d - 0xa));
+}
+
+void usart2_xmit_uint32 (uint32_t v)
+{
+ unsigned i;
+
+ for (i = 0; i < 8; ++i) {
+ usart2_xmit_xdigit (v >> 28);
+ v <<= 4;
+ }
+}
+
+
+void
+usart_init (void)
+{
+ rcc_periph_clock_enable (RCC_GPIOD);
+ rcc_periph_clock_enable (RCC_USART2);
+
+
+ MAP_INPUT (RX2);
+ MAP_AF (TX2, GPIO_AF7);
+ MAP_AF_PU (RX2, GPIO_AF7);
+
+
+ usart_set_baudrate (USART2, 38400);
+ usart_set_databits (USART2, 8);
+ usart_set_stopbits (USART2, USART_STOPBITS_1);
+ usart_set_parity (USART2, USART_PARITY_NONE);
+ usart_set_flow_control (USART2, USART_FLOWCONTROL_NONE);
+ usart_set_mode (USART2, USART_MODE_TX_RX);
+
+ usart_enable (USART2);
+}