Prototype RF driver for STM Sub-1 GHz RF expansion board based on the SPSGRF-868 module for STM32 Nucleo.

Prototype RF Driver for STM Sub-1 GHz RF Expansion Boards based on the SPSGRF-868 and SPSGRF-915 Modules for STM32 Nucleo

Currently supported boards:

Note, in order to use expansion board X-NUCLEO-IDS01A4 in mbed you need to perform the following HW modifications on the board:

  • Unmount resistor R4
  • Mount resistor R7

Furthermore, on some Nucleo development boards (e.g. the NUCLEO_F429ZI), in order to be able to use Ethernet together with these Sub-1 GHz RF expansion boards, you need to compile this driver with macro SPIRIT1_SPI_MOSI=PB_5 defined, while the development board typically requires some HW modification as e.g. described here!

This driver can be used together with the 6LoWPAN stack (a.k.a. Nanostack).

Revision:
63:d7530f62ed93
Parent:
62:44ab5af08199
Child:
64:28ef790e4ef7
--- a/source/NanostackRfPhySpirit1.cpp	Mon Jun 26 13:53:43 2017 +0200
+++ b/source/NanostackRfPhySpirit1.cpp	Mon Jun 26 18:04:11 2017 +0200
@@ -251,8 +251,8 @@
 static inline void rf_set_pan_id(uint8_t *ptr) {
     stored_pan_id = (ptr[0] << 8) + ptr[1]; // big-endian
     tr_debug("%s (%d), adr0=%x, adr1=%x, val=%d",
-             __func__, __LINE__,
-             ptr[0], ptr[1], stored_pan_id);
+            __func__, __LINE__,
+            ptr[0], ptr[1], stored_pan_id);
 }
 
 static int8_t rf_address_write(phy_address_type_e address_type, uint8_t *address_ptr)
@@ -315,7 +315,14 @@
 /* Note: we are in IRQ context */
 static inline bool rf_check_mac_address(uint8_t *dest) {
     for(int i = 0; i < 8; i++) {
-        if(dest[i] != stored_mac_address[7-i]) return false;
+        if(dest[i] != stored_mac_address[7-i]) {
+#ifdef HEAVY_TRACING
+            tr_debug("%s (%d): i=%d, dest=%x, stored=%x",
+                    __func__, __LINE__,
+                    i, dest[i], stored_mac_address[7-i]);
+#endif
+            return false;
+        }
     }
     return true;
 }
@@ -369,6 +376,7 @@
         case 0x00:
             ret = true; // no check possible;
             break;
+
         case 0x02:
             min_size += 4; // pan id + short dest adr
 
@@ -380,24 +388,11 @@
             }
 
             dst_pan_id = rf_read_16_bit(&rf_rx_buf[3]);
-            if(dst_pan_id == 0xFFFF) {
+            if((dst_pan_id != stored_pan_id) && (dst_pan_id != 0xFFFF)) {
 #ifdef HEAVY_TRACING
                 tr_debug("%s (%d)", __func__, __LINE__);
 #endif
-                ret = true;
-                break;
-            }
-
-            if(dst_pan_id == stored_pan_id) {
-#ifdef HEAVY_TRACING
-                tr_debug("%s (%d)", __func__, __LINE__);
-#endif
-                ret = true;
-                break;
-            } else {
-#ifdef HEAVY_TRACING
-                tr_debug("%s (%d): %d!=%d", __func__, __LINE__, dst_pan_id, stored_pan_id);
-#endif
+                return false;
             }
 
             if(len < 7) {
@@ -408,18 +403,16 @@
             }
 
             dst_short_adr = rf_read_16_bit(&rf_rx_buf[5]);
-            if(dst_short_adr == stored_short_adr) {
-#ifdef HEAVY_TRACING
-                tr_debug("%s (%d)", __func__, __LINE__);
-#endif
-                ret = true;
-                break;
-            } else {
+            if((dst_short_adr != stored_short_adr) && (dst_short_adr != 0xFFFF)) {
 #ifdef HEAVY_TRACING
                 tr_debug("%s (%d): %d!=%d", __func__, __LINE__, dst_short_adr, stored_short_adr);
 #endif
+                return false;
             }
+
+            ret = true;
             break;
+
         case 0x03:
             min_size += 10; // pan id + dest mac addr
 
@@ -431,20 +424,11 @@
             }
 
             dst_pan_id = rf_read_16_bit(&rf_rx_buf[3]);
-            if(dst_pan_id == 0xFFFF) {
+            if((dst_pan_id != stored_pan_id) && (dst_pan_id != 0xFFFF)) {
 #ifdef HEAVY_TRACING
                 tr_debug("%s (%d)", __func__, __LINE__);
 #endif
-                ret = true;
-                break;
-            }
-
-            if(dst_pan_id == stored_pan_id) {
-#ifdef HEAVY_TRACING
-                tr_debug("%s (%d)", __func__, __LINE__);
-#endif
-                ret = true;
-                break;
+                return false;
             }
 
             if(len < 13) {
@@ -455,7 +439,16 @@
             }
 
             ret = rf_check_mac_address(&rf_rx_buf[5]);
+
+            if(!ret) {
+#ifdef HEAVY_TRACING
+                tr_debug("%s (%d)", __func__, __LINE__);
+#endif
+                return false;
+            }
+
             break;
+
         default:
             /* not supported */
 #ifdef HEAVY_TRACING
@@ -686,13 +679,13 @@
 
 NanostackRfPhySpirit1::NanostackRfPhySpirit1(PinName spi_mosi, PinName spi_miso, PinName spi_sclk,
                                              PinName dev_irq,  PinName dev_cs, PinName dev_sdn, PinName brd_led) :
-            _spi_mosi(spi_mosi),
-            _spi_miso(spi_miso),
-            _spi_sclk(spi_sclk),
-            _dev_irq(dev_irq),
-            _dev_cs(dev_cs),
-            _dev_sdn(dev_sdn),
-            _brd_led(brd_led)
+    _spi_mosi(spi_mosi),
+    _spi_miso(spi_miso),
+    _spi_sclk(spi_sclk),
+    _dev_irq(dev_irq),
+    _dev_cs(dev_cs),
+    _dev_sdn(dev_sdn),
+    _brd_led(brd_led)
 {
     /* Nothing to do */
     tr_debug("%s (%d)", __func__, __LINE__);