From 0d936a4f7c6452f0b5ffc7968d6baad7af579652 Mon Sep 17 00:00:00 2001 From: Carlo Parata Date: Wed, 30 Sep 2020 15:37:58 +0200 Subject: [PATCH] Add support to X-NUCLEO-IDB05A2 --- README.md | 2 +- examples/Central/LedControl/LedControl.ino | 14 ++++++++++++-- .../PeripheralExplorer/PeripheralExplorer.ino | 12 ++++++++++-- examples/Central/Scan/Scan.ino | 12 ++++++++++-- examples/Central/ScanCallback/ScanCallback.ino | 12 ++++++++++-- .../Central/SensorTagButton/SensorTagButton.ino | 12 ++++++++++-- examples/Peripheral/ButtonLED/ButtonLED.ino | 14 ++++++++++++-- examples/Peripheral/CallbackLED/CallbackLED.ino | 12 ++++++++++-- examples/Peripheral/LED/LED.ino | 12 ++++++++++-- library.properties | 4 ++-- src/utility/HCISpiTransport.cpp | 12 ++++++------ src/utility/HCISpiTransport.h | 3 ++- 12 files changed, 95 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 100cef59..2fb6e425 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # STM32duinoBLE This library is a fork of ArduinoBLE library to add the support of SPBTLE-RF and SPBTLE-1S BLE modules. -It was successfully tested with the X-NUCLEO-IDB05A1 or X-NUCLEO-BNRG2A1 expansion board and a NUCLEO-F401RE +It was successfully tested with the X-NUCLEO-IDB05A2 or X-NUCLEO-IDB05A1 or X-NUCLEO-BNRG2A1 expansion board and a NUCLEO-F401RE or NUCLEO-L476RG or NUCLEO-L053R8, with B-L475E-IOT01A and with STEVAL-MKSBOX1V1. In order to use this library with STEVAL-MKSBOX1V1, you need to update the firmware of the SPBTLE-1S BLE module mounted on that board as described in the following wiki page: diff --git a/examples/Central/LedControl/LedControl.ino b/examples/Central/LedControl/LedControl.ino index bc1e963c..909a400c 100644 --- a/examples/Central/LedControl/LedControl.ino +++ b/examples/Central/LedControl/LedControl.ino @@ -29,11 +29,21 @@ HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, PD13, PE6, PA8, 8000000, BLELocalDevice BLE(&HCISpiTransport); const int buttonPin = PC13; // set buttonPin to digital pin PC13 #else -/* Shield IDB05A1 with SPI clock on D3 */ +/* Shield IDB05A2 with SPI clock on D3 */ SPIClass SpiHCI(D11, D12, D3); -HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI_MODE0); +HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M0, A1, A0, D7, 8000000, SPI_MODE0); BLELocalDevice BLE(&HCISpiTransport); const int buttonPin = PC13; // set buttonPin to digital pin PC13 +/* Shield IDB05A2 with SPI clock on D13 */ +/*#define SpiHCI SPI +HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M0, A1, A0, D7, 8000000, SPI_MODE0); +BLELocalDevice BLE(&HCISpiTransport); +const int buttonPin = PC13; // set buttonPin to digital pin PC13 */ +/* Shield IDB05A1 with SPI clock on D3 */ +/*SPIClass SpiHCI(D11, D12, D3); +HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI_MODE0); +BLELocalDevice BLE(&HCISpiTransport); +const int buttonPin = PC13; // set buttonPin to digital pin PC13 */ /* Shield IDB05A1 with SPI clock on D13 */ /*#define SpiHCI SPI HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI_MODE0); diff --git a/examples/Central/PeripheralExplorer/PeripheralExplorer.ino b/examples/Central/PeripheralExplorer/PeripheralExplorer.ino index 83fb396a..1414ca90 100644 --- a/examples/Central/PeripheralExplorer/PeripheralExplorer.ino +++ b/examples/Central/PeripheralExplorer/PeripheralExplorer.ino @@ -26,10 +26,18 @@ SPIClass SpiHCI(PC12, PC11, PC10); HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, PD13, PE6, PA8, 8000000, SPI_MODE0); BLELocalDevice BLE(&HCISpiTransport); #else -/* Shield IDB05A1 with SPI clock on D3 */ +/* Shield IDB05A2 with SPI clock on D3 */ SPIClass SpiHCI(D11, D12, D3); -HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI_MODE0); +HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M0, A1, A0, D7, 8000000, SPI_MODE0); BLELocalDevice BLE(&HCISpiTransport); +/* Shield IDB05A2 with SPI clock on D13 */ +/*#define SpiHCI SPI +HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M0, A1, A0, D7, 8000000, SPI_MODE0); +BLELocalDevice BLE(&HCISpiTransport); */ +/* Shield IDB05A1 with SPI clock on D3 */ +/*SPIClass SpiHCI(D11, D12, D3); +HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI_MODE0); +BLELocalDevice BLE(&HCISpiTransport); */ /* Shield IDB05A1 with SPI clock on D13 */ /*#define SpiHCI SPI HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI_MODE0); diff --git a/examples/Central/Scan/Scan.ino b/examples/Central/Scan/Scan.ino index e477a26c..ac3c4d0f 100644 --- a/examples/Central/Scan/Scan.ino +++ b/examples/Central/Scan/Scan.ino @@ -23,10 +23,18 @@ SPIClass SpiHCI(PC12, PC11, PC10); HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, PD13, PE6, PA8, 8000000, SPI_MODE0); BLELocalDevice BLE(&HCISpiTransport); #else -/* Shield IDB05A1 with SPI clock on D3 */ +/* Shield IDB05A2 with SPI clock on D3 */ SPIClass SpiHCI(D11, D12, D3); -HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI_MODE0); +HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M0, A1, A0, D7, 8000000, SPI_MODE0); BLELocalDevice BLE(&HCISpiTransport); +/* Shield IDB05A2 with SPI clock on D13 */ +/*#define SpiHCI SPI +HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M0, A1, A0, D7, 8000000, SPI_MODE0); +BLELocalDevice BLE(&HCISpiTransport); */ +/* Shield IDB05A1 with SPI clock on D3 */ +/*SPIClass SpiHCI(D11, D12, D3); +HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI_MODE0); +BLELocalDevice BLE(&HCISpiTransport); */ /* Shield IDB05A1 with SPI clock on D13 */ /*#define SpiHCI SPI HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI_MODE0); diff --git a/examples/Central/ScanCallback/ScanCallback.ino b/examples/Central/ScanCallback/ScanCallback.ino index 178c51ae..e7ad4291 100644 --- a/examples/Central/ScanCallback/ScanCallback.ino +++ b/examples/Central/ScanCallback/ScanCallback.ino @@ -25,10 +25,18 @@ SPIClass SpiHCI(PC12, PC11, PC10); HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, PD13, PE6, PA8, 8000000, SPI_MODE0); BLELocalDevice BLE(&HCISpiTransport); #else -/* Shield IDB05A1 with SPI clock on D3 */ +/* Shield IDB05A2 with SPI clock on D3 */ SPIClass SpiHCI(D11, D12, D3); -HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI_MODE0); +HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M0, A1, A0, D7, 8000000, SPI_MODE0); BLELocalDevice BLE(&HCISpiTransport); +/* Shield IDB05A2 with SPI clock on D13 */ +/*#define SpiHCI SPI +HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M0, A1, A0, D7, 8000000, SPI_MODE0); +BLELocalDevice BLE(&HCISpiTransport); */ +/* Shield IDB05A1 with SPI clock on D3 */ +/*SPIClass SpiHCI(D11, D12, D3); +HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI_MODE0); +BLELocalDevice BLE(&HCISpiTransport); */ /* Shield IDB05A1 with SPI clock on D13 */ /*#define SpiHCI SPI HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI_MODE0); diff --git a/examples/Central/SensorTagButton/SensorTagButton.ino b/examples/Central/SensorTagButton/SensorTagButton.ino index b557adaa..90ab4846 100644 --- a/examples/Central/SensorTagButton/SensorTagButton.ino +++ b/examples/Central/SensorTagButton/SensorTagButton.ino @@ -27,10 +27,18 @@ SPIClass SpiHCI(PC12, PC11, PC10); HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, PD13, PE6, PA8, 8000000, SPI_MODE0); BLELocalDevice BLE(&HCISpiTransport); #else -/* Shield IDB05A1 with SPI clock on D3 */ +/* Shield IDB05A2 with SPI clock on D3 */ SPIClass SpiHCI(D11, D12, D3); -HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI_MODE0); +HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M0, A1, A0, D7, 8000000, SPI_MODE0); BLELocalDevice BLE(&HCISpiTransport); +/* Shield IDB05A2 with SPI clock on D13 */ +/*#define SpiHCI SPI +HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M0, A1, A0, D7, 8000000, SPI_MODE0); +BLELocalDevice BLE(&HCISpiTransport); */ +/* Shield IDB05A1 with SPI clock on D3 */ +/*SPIClass SpiHCI(D11, D12, D3); +HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI_MODE0); +BLELocalDevice BLE(&HCISpiTransport); */ /* Shield IDB05A1 with SPI clock on D13 */ /*#define SpiHCI SPI HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI_MODE0); diff --git a/examples/Peripheral/ButtonLED/ButtonLED.ino b/examples/Peripheral/ButtonLED/ButtonLED.ino index 99417d68..18d84199 100644 --- a/examples/Peripheral/ButtonLED/ButtonLED.ino +++ b/examples/Peripheral/ButtonLED/ButtonLED.ino @@ -30,11 +30,21 @@ HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, PD13, PE6, PA8, 8000000, BLELocalDevice BLE(&HCISpiTransport); const int buttonPin = PC13; // set buttonPin to digital pin PC13 #else -/* Shield IDB05A1 with SPI clock on D3 */ +/* Shield IDB05A2 with SPI clock on D3 */ SPIClass SpiHCI(D11, D12, D3); -HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI_MODE0); +HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M0, A1, A0, D7, 8000000, SPI_MODE0); BLELocalDevice BLE(&HCISpiTransport); const int buttonPin = PC13; // set buttonPin to digital pin PC13 +/* Shield IDB05A2 with SPI clock on D13 */ +/*#define SpiHCI SPI +HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M0, A1, A0, D7, 8000000, SPI_MODE0); +BLELocalDevice BLE(&HCISpiTransport); +const int buttonPin = PC13; // set buttonPin to digital pin PC13 */ +/* Shield IDB05A1 with SPI clock on D3 */ +/*SPIClass SpiHCI(D11, D12, D3); +HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI_MODE0); +BLELocalDevice BLE(&HCISpiTransport); +const int buttonPin = PC13; // set buttonPin to digital pin PC13 */ /* Shield IDB05A1 with SPI clock on D13 */ /*#define SpiHCI SPI HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI_MODE0); diff --git a/examples/Peripheral/CallbackLED/CallbackLED.ino b/examples/Peripheral/CallbackLED/CallbackLED.ino index 7a28a4ed..29388188 100644 --- a/examples/Peripheral/CallbackLED/CallbackLED.ino +++ b/examples/Peripheral/CallbackLED/CallbackLED.ino @@ -28,10 +28,18 @@ SPIClass SpiHCI(PC12, PC11, PC10); HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, PD13, PE6, PA8, 8000000, SPI_MODE0); BLELocalDevice BLE(&HCISpiTransport); #else -/* Shield IDB05A1 with SPI clock on D3 */ +/* Shield IDB05A2 with SPI clock on D3 */ SPIClass SpiHCI(D11, D12, D3); -HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI_MODE0); +HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M0, A1, A0, D7, 8000000, SPI_MODE0); BLELocalDevice BLE(&HCISpiTransport); +/* Shield IDB05A2 with SPI clock on D13 */ +/*#define SpiHCI SPI +HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M0, A1, A0, D7, 8000000, SPI_MODE0); +BLELocalDevice BLE(&HCISpiTransport); */ +/* Shield IDB05A1 with SPI clock on D3 */ +/*SPIClass SpiHCI(D11, D12, D3); +HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI_MODE0); +BLELocalDevice BLE(&HCISpiTransport); */ /* Shield IDB05A1 with SPI clock on D13 */ /*SPIClass SpiHCI(D11, D12, D13); HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI_MODE0); diff --git a/examples/Peripheral/LED/LED.ino b/examples/Peripheral/LED/LED.ino index 422796fa..d7ec5c6e 100644 --- a/examples/Peripheral/LED/LED.ino +++ b/examples/Peripheral/LED/LED.ino @@ -26,10 +26,18 @@ SPIClass SpiHCI(PC12, PC11, PC10); HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, PD13, PE6, PA8, 8000000, SPI_MODE0); BLELocalDevice BLE(&HCISpiTransport); #else -/* Shield IDB05A1 with SPI clock on D3 */ +/* Shield IDB05A2 with SPI clock on D3 */ SPIClass SpiHCI(D11, D12, D3); -HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI_MODE0); +HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M0, A1, A0, D7, 8000000, SPI_MODE0); BLELocalDevice BLE(&HCISpiTransport); +/* Shield IDB05A2 with SPI clock on D13 */ +/*#define SpiHCI SPI +HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M0, A1, A0, D7, 8000000, SPI_MODE0); +BLELocalDevice BLE(&HCISpiTransport); */ +/* Shield IDB05A1 with SPI clock on D3 */ +/*SPIClass SpiHCI(D11, D12, D3); +HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI_MODE0); +BLELocalDevice BLE(&HCISpiTransport); */ /* Shield IDB05A1 with SPI clock on D13 */ /*#define SpiHCI SPI HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI_MODE0); diff --git a/library.properties b/library.properties index 73aa266e..4c083ef0 100644 --- a/library.properties +++ b/library.properties @@ -1,8 +1,8 @@ name=STM32duinoBLE -version=1.2.1 +version=1.3.0 author=Arduino, SRA maintainer=stm32duino -sentence=Fork of ArduinoBLE library to add the support of SPBTLE-RF and SPBTLE-1S BLE modules. +sentence=Fork of ArduinoBLE library to add the support of SPBTLE-RF, SPBTLE-1S, BLUENRG-M2SP and BLUENRG-M0 BLE modules. paragraph=This library supports creating a BLE peripheral and BLE central mode. category=Communication url=https://github.com/stm32duino/STM32duinoBLE diff --git a/src/utility/HCISpiTransport.cpp b/src/utility/HCISpiTransport.cpp index 486df38a..99dd6ca2 100644 --- a/src/utility/HCISpiTransport.cpp +++ b/src/utility/HCISpiTransport.cpp @@ -66,7 +66,7 @@ int HCISpiTransportClass::begin() digitalWrite(_ble_rst, HIGH); delay(5); - if (_ble_chip == SPBTLE_RF) + if (_ble_chip == SPBTLE_RF || _ble_chip == BLUENRG_M0) { // Wait for Blue Initialize wait_for_blue_initialize(); @@ -102,7 +102,7 @@ void HCISpiTransportClass::wait(unsigned long timeout) int HCISpiTransportClass::available() { - if(_ble_chip != SPBTLE_RF && _ble_chip !=SPBTLE_1S && _ble_chip !=BLUENRG_M2SP) + if(_ble_chip != SPBTLE_RF && _ble_chip != SPBTLE_1S && _ble_chip != BLUENRG_M2SP && _ble_chip != BLUENRG_M0) { return 0; } @@ -137,7 +137,7 @@ int HCISpiTransportClass::available() /* Write the header */ _spi->transfer(header_master, 5); - if (_ble_chip == SPBTLE_RF) + if (_ble_chip == SPBTLE_RF || _ble_chip == BLUENRG_M0) { /* device is ready */ if(header_master[0] == 0x02) @@ -262,7 +262,7 @@ int HCISpiTransportClass::available() if(ble_reset) { - if (_ble_chip == SPBTLE_RF) + if (_ble_chip == SPBTLE_RF || _ble_chip == BLUENRG_M0) { /* BLE chip was reset: we need to enable LL_ONLY */ enable_ll_only(); @@ -330,14 +330,14 @@ size_t HCISpiTransportClass::write(const uint8_t* data, size_t length) int result = 0; uint32_t tickstart = millis(); - if(_ble_chip != SPBTLE_RF && _ble_chip !=SPBTLE_1S && _ble_chip !=BLUENRG_M2SP) + if(_ble_chip != SPBTLE_RF && _ble_chip != SPBTLE_1S && _ble_chip != BLUENRG_M2SP && _ble_chip != BLUENRG_M0) { return 0; } do { - if (_ble_chip == SPBTLE_RF) + if (_ble_chip == SPBTLE_RF || _ble_chip == BLUENRG_M0) { result = 0; diff --git a/src/utility/HCISpiTransport.h b/src/utility/HCISpiTransport.h index aeb509d1..e16502f1 100644 --- a/src/utility/HCISpiTransport.h +++ b/src/utility/HCISpiTransport.h @@ -26,7 +26,8 @@ typedef enum BLEChip_s { SPBTLE_RF, SPBTLE_1S, - BLUENRG_M2SP + BLUENRG_M2SP, + BLUENRG_M0 } BLEChip_t; #ifndef BLE_SPI_BYTE_ORDER