ST / X_NUCLEO_IDB0XA1

Dependents:   Nucleo_Zumo_BLE_IDB04A1 contest_IOT5 contest_IOT6 contest_IOT_10 ... more

Fork of X_NUCLEO_IDB0XA1 by ST Expansion SW Team

Arduino Connector Compatibility Warning

X-NUCLEO-IDB04A1 and X-NUCLEO-IDB05A1 are Arduino compatible with an exception: instead of using pin D13 for the SPI clock, they use pin D3. The default configuration for this library is having the SPI clock on pin D3.

To be fully Arduino compatible, X-NUCLEO-IDB04A1 and X-NUCLEO-IDB05A1 need a small HW patch.

For X-NUCLEO-IDB04A1 this patch consists in removing zero resistor R10 and instead soldering zero resistor R11. For X-NUCLEO-IDB05A1 this patch consists in removing zero resistor R4 and instead soldering zero resistor R6.

In case you patch your board, then you also have to configure this library to use pin D13 to drive the SPI clock (see macro IDB0XA1_D13_PATCH in file x_nucleo_idb0xa1_targets.h).

If you use pin D13 for the SPI clock, please be aware that on STM32 Nucleo boards you may not drive the LED, otherwise you will get a conflict: the LED on STM32 Nucleo boards is connected to pin D13.

Referring to the current list of tested platforms (see X-NUCLEO-IDB04A1 and X-NUCLEO-IDB05A1 pages), the patch is required by ST-Nucleo-F103RB; ST-Nucleo-F302R8; ST-Nucleo-F411RE; and ST-Nucleo-F446RE.

Revision:
219:d8e8cd4d4521
Parent:
210:08c4c85ca679
Child:
220:e02936f0d4c7
diff -r 48776140c30d -r d8e8cd4d4521 source/platform/btle.cpp
--- a/source/platform/btle.cpp	Thu Mar 31 11:12:14 2016 +0200
+++ b/source/platform/btle.cpp	Thu Mar 31 11:16:47 2016 +0200
@@ -74,16 +74,14 @@
 
 void HCI_Input(tHciDataPacket * hciReadPacket);
 
-//#define BDADDR_SIZE 6
-//tHalUint8 bdaddr[BDADDR_SIZE]= {0xaa, 0x00, 0x00, 0xE1, 0x80, 0x02};
-
 uint16_t g_gap_service_handle = 0;
 uint16_t g_appearance_char_handle = 0;
 uint16_t g_device_name_char_handle = 0;
 
 /* Private variables ---------------------------------------------------------*/
 volatile uint8_t set_connectable = 1;
-// ANDREA
+
+static char versionString[32];
 uint8_t bnrg_expansion_board = IDB04A1; /* at startup, suppose the X-NUCLEO-IDB04A1 is used */
 
 Gap::Address_t bleAddr;
@@ -99,9 +97,9 @@
     @returns void
 */
 /**************************************************************************/
-void btle_init(bool isSetAddress, uint8_t role)
+void btleInit(bool isSetAddress, uint8_t role)
 {
-    PRINTF("btle_init>>\n\r"); 
+    PRINTF("btleInit>>\n\r");
     
     int ret;
     uint8_t  hwVersion;
@@ -133,8 +131,11 @@
         bnrg_expansion_board = IDB05A1;
     }
 
+    /* set BLE version string */
+    setVersionString(hwVersion, fwVersion);
+
     /* The Nucleo board must be configured as SERVER */
-    //check if isSetAddress is set than set address.
+    //check if isSetAddress is set then set address.
     // ANDREA
     if(isSetAddress)
     {
@@ -161,7 +162,7 @@
         PRINTF("GATT_Init failed.\n");
     }
     if (bnrg_expansion_board == IDB05A1) {
-        ret = aci_gap_init_IDB05A1(GAP_PERIPHERAL_ROLE_IDB05A1|GAP_CENTRAL_ROLE_IDB05A1, 0, 0x07, &service_handle, &dev_name_char_handle, &appearance_char_handle);
+        ret = aci_gap_init_IDB05A1(GAP_PERIPHERAL_ROLE_IDB05A1|GAP_CENTRAL_ROLE_IDB05A1|GAP_OBSERVER_ROLE_IDB05A1, 0, 0x07, &service_handle, &dev_name_char_handle, &appearance_char_handle);
     } else {
         ret = aci_gap_init_IDB04A1(role, &service_handle, &dev_name_char_handle, &appearance_char_handle);
     }
@@ -218,6 +219,45 @@
 }
 #endif
 
+/* set BLE Version string */
+void setVersionString(uint8_t hwVersion, uint16_t fwVersion)
+{
+    if(bnrg_expansion_board == IDB04A1 || bnrg_expansion_board == IDB05A1) {
+        snprintf(versionString, sizeof(versionString), "ST BLE4.1 HW v%u.%u FW v%u.%u",
+                                                        hwVersion>>4, (hwVersion&0x0F),
+                                                        fwVersion>>8, (fwVersion&0x00F0)>>4);
+    } else {
+        snprintf(versionString, sizeof(versionString), "ST (unknown spec)");
+    }
+}
+
+/* get BLE Version string */
+const char* getVersionString(void)
+{
+    return versionString;
+}
+
+tBleStatus btleStartRadioScan(uint8_t scan_type,
+                              uint16_t scan_interval,
+                              uint16_t scan_window,
+                              uint8_t own_address_type)
+{
+  tBleStatus ret;
+
+  // Observer role is not supported by X-NUCLEO-IDB04A1, return BLE_ERROR_NOT_IMPLEMENTED
+  if(bnrg_expansion_board == IDB05A1) {
+      ret = aci_gap_start_observation_procedure(scan_interval,
+	                                        scan_window,
+                                                scan_type,
+		                                own_address_type,
+                                                1); // 1 to filter duplicates
+  } else {
+      ret = BLE_STATUS_INVALID_CID;
+  }
+
+  return ret;
+
+}
 
 /*!
     @brief  Not Used
@@ -536,8 +576,7 @@
             //printf("EVT_BLUE_GAP_PROCEDURE_COMPLETE (code=0x%02X)\n\r", pr->procedure_code);
             
             switch(pr->procedure_code) {
-            case GAP_LIMITED_DISCOVERY_PROC:
-            case GAP_GENERAL_DISCOVERY_PROC:
+            case GAP_OBSERVATION_PROC_IDB05A1:
               
               BlueNRGGap::getInstance().Discovery_CB(BlueNRGGap::DISCOVERY_COMPLETE, 0, NULL, NULL, NULL, NULL, NULL);
               break;