diff options
author | Vegard Storheil Eriksen <zyp@jvnv.net> | 2015-01-12 08:59:32 +0100 |
---|---|---|
committer | Vegard Storheil Eriksen <zyp@jvnv.net> | 2015-01-12 08:59:42 +0100 |
commit | 7b4ba03bc45dfed09759b9d0f99f6ddfde51ac43 (patch) | |
tree | 65b30289dc3d51594f3ee68ef6ed2c2c1b7bb3b0 | |
parent | ebddcef73dbe544718ea5d607072fad36e1809d4 (diff) |
Added F3 USART support.
-rw-r--r-- | usart/usart.cpp | 7 | ||||
-rw-r--r-- | usart/usart.h | 44 |
2 files changed, 16 insertions, 35 deletions
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<Interrupt::USART1>() { - 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 <interrupt/interrupt.h> #include <os/thread.h> +#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 |