MODSERIAL with support for more devices

Fork of MODSERIAL by Erik -

Files at this revision

API Documentation at this revision

Comitter:
ducky64
Date:
Fri Jul 01 01:13:49 2016 +0000
Parent:
41:d8422efe4761
Commit message:
Nucleo F303K8 support

Changed in this revision

Device/MODSERIAL_NUCLEO_F303K8.cpp Show annotated file Show diff for this revision Revisions of this file
Device/MODSERIAL_NUCLEO_F303K8.h Show annotated file Show diff for this revision Revisions of this file
MACROS.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Device/MODSERIAL_NUCLEO_F303K8.cpp	Fri Jul 01 01:13:49 2016 +0000
@@ -0,0 +1,19 @@
+#ifdef TARGET_NUCLEO_F303K8
+#include "MODSERIAL.h"
+
+void MODSERIAL::setBase(void ) {
+switch( _serial.index ) {
+        case 0: _base = USART1; _IRQ = USART1_IRQn; break;
+        case 1: _base = USART2; _IRQ = USART2_IRQn; break;
+        default: _base = NULL; _IRQ = (IRQn_Type)NULL; break;
+    }
+}
+
+void MODSERIAL::initDevice(void) {};
+
+bool MODSERIAL::txIsBusy( void )
+{
+    return ( (((USART_TypeDef*)_base)->ISR & ( 1UL << 6 )) == 0 ) ? true : false;
+}
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Device/MODSERIAL_NUCLEO_F303K8.h	Fri Jul 01 01:13:49 2016 +0000
@@ -0,0 +1,28 @@
+#if defined(TARGET_NUCLEO_F303K8)
+
+#define MODSERIAL_IRQ_REG ((USART_TypeDef*)_base)->CR1
+/**
+ * TCIE probably isn't the optimal definition (since it waits for transmission
+ * complete before firing, as opposed to TXEIE which fires as soon as the buffer
+ * is empty and able to accept another frame to transmit), but this is what
+ * STM32F3's serial_api.c expects (and breaks if using TXEIE).
+ * But if serial_api.c changes to TXEIE this (probably) will also need to be
+ * updated.
+ */
+#define DISABLE_TX_IRQ MODSERIAL_IRQ_REG &= ~USART_CR1_TCIE
+#define DISABLE_RX_IRQ MODSERIAL_IRQ_REG &= ~USART_CR1_RXNEIE
+#define ENABLE_TX_IRQ MODSERIAL_IRQ_REG |= USART_CR1_TCIE
+#define ENABLE_RX_IRQ MODSERIAL_IRQ_REG |= USART_CR1_RXNEIE
+
+#define MODSERIAL_READ_REG ((USART_TypeDef*)_base)->RDR
+#define MODSERIAL_WRITE_REG ((USART_TypeDef*)_base)->TDR
+#define MODSERIAL_READABLE ((((USART_TypeDef*)_base)->ISR & USART_ISR_RXNE) != 0)
+#define MODSERIAL_WRITABLE ((((USART_TypeDef*)_base)->ISR & USART_ISR_TXE) != 0)
+
+#define RESET_TX_FIFO while(0 == 1)
+#define RESET_RX_FIFO while(MODSERIAL_READABLE) char dummy = MODSERIAL_READ_REG
+
+#define RX_IRQ_ENABLED ((MODSERIAL_IRQ_REG & USART_CR1_RXNEIE) != 0)
+#define TX_IRQ_ENABLED ((MODSERIAL_IRQ_REG & USART_CR1_TCIE) != 0)
+
+#endif
--- a/MACROS.h	Tue Nov 17 12:11:44 2015 -0300
+++ b/MACROS.h	Fri Jul 01 01:13:49 2016 +0000
@@ -29,6 +29,7 @@
 #include "MODSERIAL_KL05Z.h"
 #include "MODSERIAL_KSDK.h"
 #include "MODSERIAL_NUCLEO_F401RE.h"
+#include "MODSERIAL_NUCLEO_F303K8.h"
 #include "MODSERIAL_PAC_F401RB.h"
 
 #define MODSERIAL_TX_BUFFER_EMPTY (buffer_count[TxIrq]==0)