From 7b4ba03bc45dfed09759b9d0f99f6ddfde51ac43 Mon Sep 17 00:00:00 2001 From: Vegard Storheil Eriksen Date: Mon, 12 Jan 2015 08:59:32 +0100 Subject: Added F3 USART support. --- usart/usart.cpp | 7 ------- usart/usart.h | 44 ++++++++++++++++---------------------------- 2 files changed, 16 insertions(+), 35 deletions(-) delete mode 100644 usart/usart.cpp diff --git a/usart/usart.cpp b/usart/usart.cpp deleted file mode 100644 index 61fe393..0000000 --- a/usart/usart.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include "usart.h" - -template<> -void interrupt() { - USART1.recv(); - //GPIOB.ODR ^= 1 << 1; -} diff --git a/usart/usart.h b/usart/usart.h index 567ccd1..c075b9b 100644 --- a/usart/usart.h +++ b/usart/usart.h @@ -5,6 +5,7 @@ #include #include +#if defined(STM32F1) || defined(STM32F4) struct USART_reg_t { volatile uint32_t SR; volatile uint32_t DR; @@ -14,6 +15,21 @@ struct USART_reg_t { volatile uint32_t CR3; volatile uint32_t GTPR; }; +#elif defined(STM32F3) +struct USART_reg_t { + volatile uint32_t CR1; + volatile uint32_t CR2; + volatile uint32_t CR3; + volatile uint32_t BRR; + volatile uint32_t GTPR; + volatile uint32_t RTOR; + volatile uint32_t RQR; + volatile uint32_t ISR; + volatile uint32_t ICR; + volatile uint32_t RDR; + volatile uint32_t TDR; +}; +#endif class USART_t { public: @@ -25,22 +41,6 @@ class USART_t { inline void set_baudrate(uint32_t baudrate) { reg.BRR = clk / baudrate; } - - inline void enable() { - reg.CR1 = 0x202c; - } - - inline void send(uint8_t data) { - while(!(reg.SR & 0x80)) { - Thread::yield(); - } // Wait for TXE. - - reg.DR = data; - } - - inline uint8_t recv() { - return reg.DR; - } }; #if defined(STM32F1) || defined(STM32F3) @@ -53,16 +53,4 @@ static USART_t USART2(0x40004400, 42000000); static USART_t USART3(0x40004800, 42000000); #endif -inline void usart_enable() { - RCC.enable(RCC.USART1); - USART1.set_baudrate(115200); - USART1.enable(); - - //Interrupt::enable(Interrupt::USART1); -} - -inline void usart_send(uint8_t data) { - USART1.send(data); -} - #endif -- cgit v1.2.3