Fork for LoDev S76S

Dependencies:   mbed BufferedSerial SX1276GenericLib USBDeviceHT

Files at this revision

API Documentation at this revision

Comitter:
steve918
Date:
Mon Feb 18 22:57:14 2019 +0000
Parent:
20:a1029437adca
Commit message:
First working rev for LoDev S76S

Changed in this revision

PinMap.h Show annotated file Show diff for this revision Revisions of this file
SX1276GenericPingPong/GenericPingPong.cpp Show annotated file Show diff for this revision Revisions of this file
main.h Show annotated file Show diff for this revision Revisions of this file
utils.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r a1029437adca -r 6379a5650867 PinMap.h
--- a/PinMap.h	Sun Jun 03 19:25:37 2018 +0000
+++ b/PinMap.h	Mon Feb 18 22:57:14 2019 +0000
@@ -1,104 +1,17 @@
-/*
- * Copyright (c) 2018 Helmut Tschemernjak
- * 30826 Garbsen (Hannover) Germany
- * Licensed under the Apache License, Version 2.0);
- */
-
-
-
-#ifdef TARGET_NUCLEO_L476RG
- #define FEATURE_LORA
- 
-#elif TARGET_DISCO_L072CZ_LRWAN1
- #define FEATURE_LORA
-
-#elif TARGET_STM32L432KC
- #define HELTEC_STM32L4
- #define FEATURE_LORA
- #define FEATURE_USBSERIAL
-#endif
-
-
+#define FEATURE_LORA
 
-#if defined(TARGET_DISCO_L072CZ_LRWAN1)
-#define LED             LED2
-
-#define LORA_SPI_MOSI   PA_7
-#define LORA_SPI_MISO   PA_6
-#define LORA_SPI_SCLK   PB_3
-#define LORA_CS         PA_15
-#define LORA_RESET      PC_0
-#define LORA_DIO0       PB_4
-#define LORA_DIO1       PB_1
-#define LORA_DIO2       PB_0
-#define LORA_DIO3       PC_13
-#define LORA_DIO4       PA_5
-#define LORA_DIO5       PA_4
-#define LORA_ANT_RX     PA_1
-#define LORA_ANT_TX     PC_2
-#define LORA_ANT_BOOST  PC_1
-#define LORA_TCXO       PA_12   // 32 MHz
-
-
-
-#elif defined(TARGET_NUCLEO_L476RG) // using the RFM95 board
+#define USBRX           PA_10
+#define USBTX           PA_9
 
-#define LORA_SPI_MOSI   PC_12
-#define LORA_SPI_MISO   PC_11
-#define LORA_SPI_SCLK   PC_10
-#define LORA_CS         PA_0
-#define LORA_RESET      PA_1
-#define LORA_DIO0       PD_2    // DIO0=TxDone/RXDone
-#define LORA_DIO1       PB_7    //
-#define LORA_DIO2       PC_14   // DIO2=FhssChangeChannel
-#define LORA_DIO3       PC_15   // DIO3=CADDone
-#define LORA_DIO4       PH_0    // ????
-#define LORA_DIO5       NC      // unused?
-
-#elif defined (HELTEC_STM32L4)
-
-#define USER_BUTTON     PH_3    // boot pin
-#define LED             PB_1    // green
-#define LED1            LED
-#define LED2            PB_0    // red
-
-#define POWER_VEXT      PA_3
-#define POWER_VEXT_ON   0
-#define POWER_VEXT_OFF  1
-
-
-#define LORA_SPI_MOSI   PA_7
-#define LORA_SPI_MISO   PA_6
-#define LORA_SPI_SCLK   PA_5
-#define LORA_CS         PA_4
-#define LORA_RESET      PA_1
-#define LORA_DIO0       PA_0    // DIO0=TxDone/RXDone/CADDone
-#define LORA_DIO1       NC      //
-#define LORA_DIO2       NC      // 
-#define LORA_DIO3       NC      // 
-#define LORA_DIO4       NC      // 
-#define LORA_DIO5       NC      // 
-
-#elif defined(TARGET_NUCLEO_L432KC) // using the RFM95 board
-
-// #define LED             PB_3    // green
-#define LED             PB_5    // green
-
-#define LORA_SPI_MOSI   PA_7
-#define LORA_SPI_MISO   PA_6
-#define LORA_SPI_SCLK   PB_5
-#define LORA_CS         PA_4
-#define LORA_RESET      PA_1
-#define LORA_DIO0       PA_0    // DIO0=TxDone/RXDone/CADDone
-#define LORA_DIO1       NC      //
-#define LORA_DIO2       NC      // 
-#define LORA_DIO3       NC      // 
-#define LORA_DIO4       NC      // 
-#define LORA_DIO5       NC      //
-
-
-#else 
-
-#error "unknown board"
-
-#endif
\ No newline at end of file
+#define LED             PB_5
+#define LORA_SPI_MOSI   PB_15
+#define LORA_SPI_MISO   PB_14
+#define LORA_SPI_SCLK   PB_13
+#define LORA_CS         PB_12
+#define LORA_RESET      PB_10
+#define LORA_DIO0       PB_11
+#define LORA_DIO1       PC_13
+#define LORA_DIO2       PB_9
+#define LORA_DIO3       PB_4
+#define LORA_DIO4       PB_3
+#define LORA_DIO5       PA_15
\ No newline at end of file
diff -r a1029437adca -r 6379a5650867 SX1276GenericPingPong/GenericPingPong.cpp
--- a/SX1276GenericPingPong/GenericPingPong.cpp	Sun Jun 03 19:25:37 2018 +0000
+++ b/SX1276GenericPingPong/GenericPingPong.cpp	Mon Feb 18 22:57:14 2019 +0000
@@ -19,8 +19,8 @@
 /* Set this flag to '1' to use the LoRa modulation or to '0' to use FSK modulation */
 #define USE_MODEM_LORA  1
 #define USE_MODEM_FSK   !USE_MODEM_LORA
-#define RF_FREQUENCY            RF_FREQUENCY_868_1  // Hz
-#define TX_OUTPUT_POWER         14                  // 14 dBm
+#define RF_FREQUENCY            915010000  // Hz
+#define TX_OUTPUT_POWER         14         // 14 dBm
 
 #if USE_MODEM_LORA == 1
 
@@ -51,9 +51,8 @@
 #endif 
 
 
-#define RX_TIMEOUT_VALUE    3500	// in ms
+#define RX_TIMEOUT_VALUE    5000	// in ms
 
-//#define BUFFER_SIZE       32        // Define the payload size here
 #define BUFFER_SIZE         64        // Define the payload size here
 
 /*
@@ -89,7 +88,7 @@
 
 
 const uint8_t PingMsg[] = { 0xff, 0xff, 0x00, 0x00, 'P', 'I', 'N', 'G'};// "PING";
-const uint8_t PongMsg[] = { 0xff, 0xff, 0x00, 0x00, 'P', 'O', 'N', 'G'};// "PONG";
+const uint8_t PongMsg[] = { 0xff, 0xff, 0x00, 0x00, 'P', 'O', 'N' , 'G'};// "PONG";
 
 uint16_t BufferSize = BUFFER_SIZE;
 uint8_t *Buffer;
@@ -99,34 +98,15 @@
 
 int SX1276PingPong() 
 {
-#if( defined ( TARGET_KL25Z ) || defined ( TARGET_LPC11U6X ) )
-    DigitalOut *led = new DigitalOut(LED2);
-#elif defined(TARGET_NUCLEO_L073RZ) || defined(TARGET_DISCO_L072CZ_LRWAN1)
-    DigitalOut *led = new DigitalOut(LED4);   // RX red
-    led3 = new DigitalOut(LED3);  // TX blue
-#else
     DigitalOut *led = new DigitalOut(LED1);
     led3 = led;
-#endif
     
     Buffer = new  uint8_t[BUFFER_SIZE];
     *led3 = 1;
 
-#ifdef B_L072Z_LRWAN1_LORA
-    Radio = new SX1276Generic(NULL, MURATA_SX1276,
-    		LORA_SPI_MOSI, LORA_SPI_MISO, LORA_SPI_SCLK, LORA_CS, LORA_RESET,
-        	LORA_DIO0, LORA_DIO1, LORA_DIO2, LORA_DIO3, LORA_DIO4, LORA_DIO5,
-        	LORA_ANT_RX, LORA_ANT_TX, LORA_ANT_BOOST, LORA_TCXO);
-#elif defined(HELTEC_STM32L4)
-    Radio = new SX1276Generic(NULL, HELTEC_L4_1276,
-			LORA_SPI_MOSI, LORA_SPI_MISO, LORA_SPI_SCLK, LORA_CS, LORA_RESET,
-            LORA_DIO0, LORA_DIO1, LORA_DIO2, LORA_DIO3, LORA_DIO4, LORA_DIO5,
-            POWER_VEXT);
-#else // RFM95
     Radio = new SX1276Generic(NULL, RFM95_SX1276,
 			LORA_SPI_MOSI, LORA_SPI_MISO, LORA_SPI_SCLK, LORA_CS, LORA_RESET,
             LORA_DIO0, LORA_DIO1, LORA_DIO2, LORA_DIO3, LORA_DIO4, LORA_DIO5);
-#endif
     
     uint8_t i;
     bool isMaster = true;
@@ -155,27 +135,8 @@
     }
 
     
-    switch(Radio->DetectBoardType()) {
-        case SX1276MB1LAS:
-            if (DEBUG_MESSAGE)
-                dprintf(" > Board Type: SX1276MB1LAS <");
-            break;
-        case SX1276MB1MAS:
-            if (DEBUG_MESSAGE)
-                dprintf(" > Board Type: SX1276MB1LAS <");
-        case MURATA_SX1276:
-            if (DEBUG_MESSAGE)
-            	dprintf(" > Board Type: MURATA_SX1276_STM32L0 <");
-            break;
-        case RFM95_SX1276:
-            if (DEBUG_MESSAGE)
-                dprintf(" > HopeRF RFM95xx <");
-            break;
-        default:
-            dprintf(" > Board Type: unknown <");
-    }
-
-    Radio->SetChannel(RF_FREQUENCY ); 
+   Radio->DetectBoardType();
+   Radio->SetChannel(RF_FREQUENCY ); 
 
 #if USE_MODEM_LORA == 1
     
@@ -223,9 +184,6 @@
     
     while( 1 )
     {
-#ifdef TARGET_STM32L4
-    //     WatchDogUpdate();
-#endif
         
         switch( State )
         {
diff -r a1029437adca -r 6379a5650867 main.h
--- a/main.h	Sun Jun 03 19:25:37 2018 +0000
+++ b/main.h	Mon Feb 18 22:57:14 2019 +0000
@@ -7,16 +7,10 @@
 #include "mbed.h"
 #include "PinMap.h"
 #include "BufferedSerial.h"
-#ifdef FEATURE_USBSERIAL
-#include "USBSerialBuffered.h"
-#endif
 #include "GenericPingPong.h"
 
 
 extern BufferedSerial *ser;
-#ifdef FEATURE_USBSERIAL
-extern USBSerialBuffered *usb;
-#endif
 extern bool _useDprintf;
 extern void InitSerial(int timeout, DigitalOut *led);  
 extern void dump(const char *title, const void *data, int len, bool dwords = false);
diff -r a1029437adca -r 6379a5650867 utils.cpp
--- a/utils.cpp	Sun Jun 03 19:25:37 2018 +0000
+++ b/utils.cpp	Mon Feb 18 22:57:14 2019 +0000
@@ -7,9 +7,6 @@
 time_t cvt_date(char const *date, char const *time);
 
 BufferedSerial *ser;
-#ifdef FEATURE_USBSERIAL
-USBSerialBuffered *usb;
-#endif
 bool _useDprintf;
 
 /*
@@ -28,38 +25,15 @@
 void InitSerial(int timeout, DigitalOut *led)
 {
     _useDprintf = true;
-    bool uartActive;
     {
-        {
-            // need to turn rx low to avoid floating signal
-            DigitalOut rx(USBRX);
-            rx = 0;
-        }
-        DigitalIn uartRX(USBRX);
-        uartActive = uartRX.read();
+        // need to turn rx low to avoid floating signal
+        DigitalOut rx(USBRX);
+        rx = 0;
     }
-#ifdef FEATURE_USBSERIAL
-    if (!uartActive) {
-        usb = new USBSerialBuffered();
-        Timer t;
-        t.start();
-        while(!usb->connected()) {
-            if (led)
-                *led = !*led;
-            wait_ms(100);
-            if (timeout) {
-                if (t.read_ms() >= timeout)
-                    return;
-            }
-        }
-        busyTimerFunc();
-        return;
-    } else {
-#else
+    DigitalIn uartRX(USBRX);
     {
-#endif
         ser = new BufferedSerial(USBTX, USBRX);
-        ser->baud(230400);
+        ser->baud(115200);
         ser->format(8);
     }
     time_t t = cvt_date(__DATE__, __TIME__);
@@ -115,14 +89,7 @@
 
     if (timstamp)
         printTimeStamp();
-#ifdef FEATURE_USBSERIAL
-    if (usb) {
-        usb->vprintf_irqsafe(format, arg);
-        if (newline)
-            usb->printf_irqsafe("\r\n");
-#else
     if (0) {
-#endif
     } else if (ser) {
         // serial jas 
         int r = 0;