From 8527443f3749f77592b3801f31a614131f341237 Mon Sep 17 00:00:00 2001 From: Carlo Parata <carlo.parata@st.com> Date: Thu, 19 Sep 2019 10:33:53 +0200 Subject: [PATCH 001/226] Add support to STBTLE-RF and STBTLE-1S --- library.properties | 2 +- src/utility/HCISpiTransport.cpp | 549 +++++++++++++++++++++++++++++++ src/utility/HCISpiTransport.h | 71 ++++ src/utility/HCIUartTransport.cpp | 4 + 4 files changed, 625 insertions(+), 1 deletion(-) create mode 100644 src/utility/HCISpiTransport.cpp create mode 100644 src/utility/HCISpiTransport.h diff --git a/library.properties b/library.properties index a9eb8e1e..4b22f8d4 100644 --- a/library.properties +++ b/library.properties @@ -6,5 +6,5 @@ sentence=Enables BLE connectivity on the Arduino MKR WiFi 1010, Arduino UNO WiFi paragraph=This library supports creating a BLE peripheral and BLE central mode. category=Communication url=https://www.arduino.cc/en/Reference/ArduinoBLE -architectures=samd,megaavr,mbed +architectures=samd,megaavr,mbed,stm32 includes=ArduinoBLE.h diff --git a/src/utility/HCISpiTransport.cpp b/src/utility/HCISpiTransport.cpp new file mode 100644 index 00000000..3af5dc27 --- /dev/null +++ b/src/utility/HCISpiTransport.cpp @@ -0,0 +1,549 @@ +/* + This file is part of the ArduinoBLE library. + Copyright (c) 2018 Arduino SA. All rights reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifdef ARDUINO_ARCH_STM32 + +#include "HCISpiTransport.h" + +#if defined(ARDUINO_STEVAL_MKSBOX1V1) +SPIClass SpiHCI(PC3, PD3, PD1); /* STEVAL_MKSBOX1V1 */ +#elif defined(ARDUINO_DISCO_L475VG_IOT) +SPIClass SpiHCI(PC12, PC11, PC10); /* B-L475E-IOT01A1 */ +#else +SPIClass SpiHCI(D11, D12, D3); /* Shield IDB05A1 */ +#endif /* ARDUINO_STEVAL_MKSBOX1V1 */ +volatile int data_avail = 0; + +HCISpiTransportClass::HCISpiTransportClass(SPIClass& spi, uint8_t cs_pin, uint8_t spi_irq, uint8_t ble_rst, unsigned long frequency, int spi_mode) : + _spi(&spi), + _cs_pin(cs_pin), + _spi_irq(spi_irq), + _ble_rst(ble_rst), + _frequency(frequency), + _spi_mode(spi_mode) +{ + _read_index = 0; + _write_index = 0; + _write_index_initial = 0; + _initial_phase = 1; +} + +HCISpiTransportClass::~HCISpiTransportClass() +{ +} + +extern "C" void SPI_Irq_Callback(void) +{ + data_avail = 1; +} + +int HCISpiTransportClass::begin() +{ + _read_index = 0; + _write_index = 0; + _write_index_initial = 0; + _initial_phase = 1; + memset(_rxbuff, 0, sizeof(_rxbuff)); + pinMode(_cs_pin, OUTPUT); + digitalWrite(_cs_pin, HIGH); + + _spi->begin(); + + pinMode(_spi_irq, INPUT); + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + + // Reset chip + pinMode(_ble_rst, OUTPUT); + digitalWrite(_ble_rst, LOW); + delay(5); + digitalWrite(_ble_rst, HIGH); + delay(5); + +#if defined(STBTLE_RF) + // Wait for Blue Initialize + wait_for_blue_initialize(); +#endif /* STBTLE_RF */ + +#if defined(STBTLE_1S) + // Wait a while for the reset of the BLE module + delay(300); +#endif /* STBTLE_1S */ + + return 1; +} + +void HCISpiTransportClass::end() +{ + detachInterrupt(_spi_irq); + _spi->end(); +} + +void HCISpiTransportClass::wait(unsigned long timeout) +{ + for (unsigned long start = millis(); (millis() - start) < timeout;) + { + if (available()) + { + break; + } + } +} + +int HCISpiTransportClass::available() +{ + if(_read_index != _write_index) + { + return 1; + } else if(data_avail) + { + int ble_reset = 0; + + if(digitalRead(_spi_irq) == 0) + { + return 0; + } + + data_avail = 0; + + while(digitalRead(_spi_irq) == 1 && _write_index != BLE_MODULE_SPI_BUFFER_SIZE) + { + uint8_t header_master[5] = {0x0b, 0x00, 0x00, 0x00, 0x00}; + + _spi->beginTransaction(SPISettings(_frequency, MSBFIRST, _spi_mode)); + + digitalWrite(_cs_pin, LOW); + + /* Write the header */ + _spi->transfer(header_master, 5); + +#if defined(STBTLE_RF) + /* device is ready */ + if(header_master[0] == 0x02) + { +#endif /* STBTLE_RF */ + uint16_t byte_count = (header_master[4] << 8) | header_master[3]; + + if(byte_count > 0) + { + if(_initial_phase) + { + /* avoid to read more data that available size of the buffer */ + if(byte_count > (BLE_MODULE_SPI_BUFFER_SIZE - _write_index_initial)) + { + byte_count = (BLE_MODULE_SPI_BUFFER_SIZE - _write_index_initial); + } + + /* Read the response */ + for(int j=0; j < byte_count; j++) + { + _rxbuff[_write_index_initial] = _spi->transfer(0xFF); + _write_index_initial++; + } + +#if defined(STBTLE_RF) + /* Check if the message is a Blue Initialize */ + /* If so we need to send the command to enable LL_ONLY */ + if(byte_count == 6) + { + if(_rxbuff[_write_index_initial - 6] == 0x04 && + _rxbuff[_write_index_initial - 5] == 0xFF && + _rxbuff[_write_index_initial - 4] == 0x03 && + _rxbuff[_write_index_initial - 3] == 0x01 && + _rxbuff[_write_index_initial - 2] == 0x00 && + _rxbuff[_write_index_initial - 1] == 0x01) + { + ble_reset = 1; + } + } +#endif /* STBTLE_RF */ +#if defined(STBTLE_1S) + /* Check if the message is a CMD_COMPLETE */ + /* We suppose that the first CMD is always a HCI_RESET */ + if(byte_count == 7) + { + if(_rxbuff[_write_index_initial - 7] == 0x04 && + _rxbuff[_write_index_initial - 6] == 0x0E && + _rxbuff[_write_index_initial - 5] == 0x04 && + _rxbuff[_write_index_initial - 4] == 0x01 && + _rxbuff[_write_index_initial - 3] == 0x03 && + _rxbuff[_write_index_initial - 2] == 0x0C && + _rxbuff[_write_index_initial - 1] == 0x00) + { + ble_reset = 1; + } + } +#endif /* STBTLE_1S */ + } else + { + /* avoid to read more data that available size of the buffer */ + if(byte_count > (BLE_MODULE_SPI_BUFFER_SIZE - _write_index)) + { + byte_count = (BLE_MODULE_SPI_BUFFER_SIZE - _write_index); + /* SPI buffer is full but we still have data to store, so we set the data_avail flag to true */ + data_avail = 1; + } + + /* Read the response */ + for(int j=0; j < byte_count; j++) + { + _rxbuff[_write_index] = _spi->transfer(0xFF); + _write_index++; + } + } + } +#if defined(STBTLE_RF) + } +#endif /* STBTLE_RF */ + + digitalWrite(_cs_pin, HIGH); + + _spi->endTransaction(); + } + + if(ble_reset) + { +#if defined(STBTLE_RF) + /* BLE chip was reset: we need to enable LL_ONLY */ + enable_ll_only(); + wait_for_enable_ll_only(); +#endif /* STBTLE_RF */ +#if defined(STBTLE_1S) + /* BLE chip was reset: we need to wait for a while */ + delay(300); +#endif /* STBTLE_1S */ + + /* Now we can update the write index and close the initial phase */ + _write_index = _write_index_initial; + _initial_phase = 0; + _write_index_initial = 0; + } + + if(_read_index != _write_index) + { + return 1; + } else + { + return 0; + } + } else + { + return 0; + } +} + +int HCISpiTransportClass::peek() +{ + int peek_val = -1; + + if(_read_index != _write_index) + { + peek_val = _rxbuff[_read_index]; + } + + return peek_val; +} + +int HCISpiTransportClass::read() +{ + int read_val = -1; + + if(_read_index != _write_index) + { + read_val = _rxbuff[_read_index]; + _read_index++; + if(_read_index == _write_index) + { + /* Reset buffer index */ + _read_index = 0; + _write_index = 0; + } + } + + return read_val; +} + +size_t HCISpiTransportClass::write(const uint8_t* data, size_t length) +{ + uint8_t header_master[5] = {0x0a, 0x00, 0x00, 0x00, 0x00}; + void *my_data = (void *)data; + int result = 0; + uint32_t tickstart = millis(); + + do + { +#if defined(STBTLE_1S) + uint32_t tickstart_data_available = millis(); +#endif /* STBTLE_1S */ + result = 0; + + _spi->beginTransaction(SPISettings(_frequency, MSBFIRST, _spi_mode)); + + digitalWrite(_cs_pin, LOW); + +#if defined(STBTLE_1S) + /* + * Wait until BlueNRG-1 is ready. + * When ready it will raise the IRQ pin. + */ + while(!(digitalRead(_spi_irq) == 1)) + { + if((millis() - tickstart_data_available) > 1000) + { + result = -3; + break; + } + } + + if(result == -3) + { + digitalWrite(_cs_pin, HIGH); + _spi->endTransaction(); + break; + } +#endif /* STBTLE_1S */ + + /* Write the header */ + _spi->transfer(header_master, 5); + +#if defined(STBTLE_RF) + /* device is ready */ + if(header_master[0] == 0x02) + { + if(header_master[1] >= length) +#endif /* STBTLE_RF */ +#if defined(STBTLE_1S) + if((int)((((uint16_t)header_master[2])<<8) | ((uint16_t)header_master[1])) >= (int)length) +#endif /* STBTLE_1S */ + { + /* Write the data */ + _spi->transfer(my_data, length); + } else + { + result = -2; + } +#if defined(STBTLE_RF) + } else + { + result = -1; + } +#endif /* STBTLE_RF */ + + digitalWrite(_cs_pin, HIGH); + + _spi->endTransaction(); + + if((millis() - tickstart) > 1000) + { + result = -3; + break; + } + } while(result < 0); + + if(result < 0) + { + return 0; + } else + { + return length; + } +} + +#if defined(STBTLE_RF) +void HCISpiTransportClass::wait_for_blue_initialize() +{ + int event_blue_initialize = 0; + uint8_t event[16]; + + do + { + while(!data_avail); + + if(digitalRead(_spi_irq) == 0) + { + continue; + } + + data_avail = 0; + while(digitalRead(_spi_irq) == 1) + { + uint8_t header_master[5] = {0x0b, 0x00, 0x00, 0x00, 0x00}; + + _spi->beginTransaction(SPISettings(_frequency, MSBFIRST, _spi_mode)); + + digitalWrite(_cs_pin, LOW); + + /* Write the header */ + _spi->transfer(header_master, 5); + + /* device is ready */ + if(header_master[0] == 0x02) + { + /* device is ready */ + uint16_t byte_count = (header_master[4] << 8) | header_master[3]; + + if(byte_count > 0) + { + /* Read the response */ + if(byte_count == 6) + { + for(int j=0; j < byte_count; j++) + { + event[j] = _spi->transfer(0xFF); + } + + if(event[0] == 0x04 && + event[1] == 0xFF && + event[2] == 0x03 && + event[3] == 0x01 && + event[4] == 0x00 && + event[5] == 0x01) + { + event_blue_initialize = 1; + } + } else + { + for(int j=0; j < byte_count; j++) + { + _spi->transfer(0xFF); + } + } + } + } + + digitalWrite(_cs_pin, HIGH); + + _spi->endTransaction(); + } + } while(!event_blue_initialize); +} + +void HCISpiTransportClass::wait_for_enable_ll_only() +{ + uint8_t data[8]; + int status = 0; + + do + { + while(!data_avail); + + if(digitalRead(_spi_irq) == 0) + { + continue; + } + + data_avail = 0; + while(digitalRead(_spi_irq) == 1) + { + uint8_t header_master[5] = {0x0b, 0x00, 0x00, 0x00, 0x00}; + + _spi->beginTransaction(SPISettings(_frequency, MSBFIRST, _spi_mode)); + + digitalWrite(_cs_pin, LOW); + + /* Write the header */ + _spi->transfer(header_master, 5); + + /* device is ready */ + if(header_master[0] == 0x02) + { + /* device is ready */ + uint16_t byte_count = (header_master[4] << 8) | header_master[3]; + + if(byte_count > 0) + { + /* Read the response */ + for(int j=0; j < byte_count; j++) + { + data[j] = _spi->transfer(0xFF); + } + + if(byte_count == 7) + { + if(data[0] == 0x04 && + data[1] == 0x0E && + data[2] == 0x04 && + data[3] == 0x01 && + data[4] == 0x0C && + data[5] == 0xFC && + data[6] == 0x00) + { + status = 1; + } + } + } + } + + digitalWrite(_cs_pin, HIGH); + + _spi->endTransaction(); + } + } while(!status); +} + +void HCISpiTransportClass::enable_ll_only() +{ + uint8_t header_master[5] = {0x0a, 0x00, 0x00, 0x00, 0x00}; + uint8_t cmd[7] = {0x01,0x0C,0xFC,0x03,0x2C,0x01,0x01}; // Enable LL_ONLY + int result = 0; + + do + { + result = 0; + + _spi->beginTransaction(SPISettings(_frequency, MSBFIRST, _spi_mode)); + + digitalWrite(_cs_pin, LOW); + + /* Write the header */ + _spi->transfer(header_master, 5); + + /* device is ready */ + if(header_master[0] == 0x02) + { + /* Write the data */ + if(header_master[1] >= 7) + { + /* Write the data */ + _spi->transfer((void *)cmd, 7); + } else + { + result = -2; + } + } else + { + result = -1; + } + + digitalWrite(_cs_pin, HIGH); + + _spi->endTransaction(); + } while (result < 0); +} +#endif /* STBTLE_RF */ + +#if defined(ARDUINO_STEVAL_MKSBOX1V1) +HCISpiTransportClass HCISpiTransport(SpiHCI, PD0, PD4, PA8, 1000000, SPI_MODE1); /* STEVAL_MKSBOX1V1 */ +#elif defined(ARDUINO_DISCO_L475VG_IOT) +HCISpiTransportClass HCISpiTransport(SpiHCI, PD13, PE6, PA8, 8000000, SPI_MODE0); /* B-L475E-IOT01A1 */ +#else +HCISpiTransportClass HCISpiTransport(SpiHCI, A1, A0, D7, 8000000, SPI_MODE0); /* Shield IDB05A1 */ +#endif /* ARDUINO_STEVAL_MKSBOX1V1 */ +HCITransportInterface& HCITransport = HCISpiTransport; + +#endif /* ARDUINO_ARCH_STM32 */ diff --git a/src/utility/HCISpiTransport.h b/src/utility/HCISpiTransport.h new file mode 100644 index 00000000..fda92068 --- /dev/null +++ b/src/utility/HCISpiTransport.h @@ -0,0 +1,71 @@ +/* + This file is part of the ArduinoBLE library. + Copyright (c) 2018 Arduino SA. All rights reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef _HCI_SPI_TRANSPORT_H_ +#define _HCI_SPI_TRANSPORT_H_ + +#include "HCITransport.h" +#include "SPI.h" + +#if defined(ARDUINO_STEVAL_MKSBOX1V1) +#define STBTLE_1S /* STEVAL_MKSBOX1V1 */ +#elif defined(ARDUINO_DISCO_L475VG_IOT) +#define STBTLE_RF /* B-L475E-IOT01A1 */ +#else +#define STBTLE_RF /* Shield IDB05A1 */ +#endif /* ARDUINO_STEVAL_MKSBOX1V1 */ + +#define BLE_MODULE_SPI_BUFFER_SIZE 128 + +class HCISpiTransportClass : public HCITransportInterface { +public: + HCISpiTransportClass(SPIClass& spi, uint8_t cs_pin, uint8_t spi_irq, uint8_t ble_rst, unsigned long frequency, int spi_mode); + virtual ~HCISpiTransportClass(); + + virtual int begin(); + virtual void end(); + + virtual void wait(unsigned long timeout); + + virtual int available(); + virtual int peek(); + virtual int read(); + + virtual size_t write(const uint8_t* data, size_t length); + +private: +#if defined(STBTLE_RF) + void wait_for_blue_initialize(); + void wait_for_enable_ll_only(); + void enable_ll_only(); +#endif /* STBTLE_RF */ + SPIClass* _spi; + uint8_t _cs_pin; + uint8_t _spi_irq; + uint8_t _ble_rst; + unsigned long _frequency; + int _spi_mode; + uint8_t _rxbuff[BLE_MODULE_SPI_BUFFER_SIZE]; + uint16_t _read_index; + uint16_t _write_index; + uint16_t _write_index_initial; + uint8_t _initial_phase; +}; + +#endif /* _HCI_SPI_TRANSPORT_H_ */ diff --git a/src/utility/HCIUartTransport.cpp b/src/utility/HCIUartTransport.cpp index 6f33e2ef..48578766 100644 --- a/src/utility/HCIUartTransport.cpp +++ b/src/utility/HCIUartTransport.cpp @@ -17,6 +17,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#ifndef ARDUINO_ARCH_STM32 + #ifndef ARDUINO_ARCH_MBED #include "HCIUartTransport.h" @@ -97,3 +99,5 @@ HCIUartTransportClass HCIUartTransport(SerialHCI, 912600); HCITransportInterface& HCITransport = HCIUartTransport; #endif + +#endif /* ARDUINO_ARCH_STM32 */ From 137c8300d0cc4c07765c0fc68d3b9e8806299331 Mon Sep 17 00:00:00 2001 From: Carlo Parata <carlo.parata@st.com> Date: Fri, 20 Sep 2019 10:29:45 +0200 Subject: [PATCH 002/226] Update README and library properties for STM32duinoBLE --- README.md | 15 ++++++--------- library.properties | 10 +++++----- src/utility/HCISpiTransport.cpp | 4 ++-- src/utility/HCISpiTransport.h | 4 ++-- 4 files changed, 15 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index b9dcdaaf..7d6b8fbc 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,13 @@ -# ArduinoBLE +# STM32duinoBLE -[](https://travis-ci.org/arduino-libraries/ArduinoBLE) +This library is a fork of ArduinoBLE library to add the support of STBTLE-RF and STBTLE-1S BLE modules. -Enables BLE connectivity on the Arduino MKR WiFi 1010, Arduino UNO WiFi Rev.2, Arduino Nano 33 IoT, and Arduino Nano 33 BLE. +You can find the official Pull Request at the following link: -This library supports creating a BLE peripheral and BLE central mode. +https://github.com/arduino-libraries/ArduinoBLE/pull/26 -For the Arduino MKR WiFi 1010, Arduino UNO WiFi Rev.2, and Arduino Nano 33 IoT boards, it requires the NINA module to be running [Arduino NINA-W102 firmware](https://github.com/arduino/nina-fw) v1.2.0 or later. - - -For more information about this library please visit us at: -https://www.arduino.cc/en/Reference/ArduinoBLE +For more information about ArduinoBLE library please visit the official web page at: +https://github.com/arduino-libraries/ArduinoBLE ## License diff --git a/library.properties b/library.properties index 4b22f8d4..0f75e882 100644 --- a/library.properties +++ b/library.properties @@ -1,10 +1,10 @@ -name=ArduinoBLE +name=STM32duinoBLE version=1.1.1 -author=Arduino -maintainer=Arduino <info@arduino.cc> -sentence=Enables BLE connectivity on the Arduino MKR WiFi 1010, Arduino UNO WiFi Rev.2, Arduino Nano 33 IoT, and Arduino Nano 33 BLE. +author=Arduino, SRA +maintainer=stm32duino +sentence=Fork of ArduinoBLE library to add the support of STBTLE-RF and STBTLE-1S BLE modules. paragraph=This library supports creating a BLE peripheral and BLE central mode. category=Communication -url=https://www.arduino.cc/en/Reference/ArduinoBLE +url=https://github.com/stm32duino/STM32duinoBLE architectures=samd,megaavr,mbed,stm32 includes=ArduinoBLE.h diff --git a/src/utility/HCISpiTransport.cpp b/src/utility/HCISpiTransport.cpp index 3af5dc27..dd157e43 100644 --- a/src/utility/HCISpiTransport.cpp +++ b/src/utility/HCISpiTransport.cpp @@ -1,6 +1,6 @@ /* - This file is part of the ArduinoBLE library. - Copyright (c) 2018 Arduino SA. All rights reserved. + This file is part of the STM32duinoBLE library. + Copyright (c) 2019 STMicroelectronics. All rights reserved. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public diff --git a/src/utility/HCISpiTransport.h b/src/utility/HCISpiTransport.h index fda92068..1515257a 100644 --- a/src/utility/HCISpiTransport.h +++ b/src/utility/HCISpiTransport.h @@ -1,6 +1,6 @@ /* - This file is part of the ArduinoBLE library. - Copyright (c) 2018 Arduino SA. All rights reserved. + This file is part of the STM32duinoBLE library. + Copyright (c) 2019 STMicroelectronics. All rights reserved. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public From d5566408ce6b06fb5932f6a297c5e2904cf1310d Mon Sep 17 00:00:00 2001 From: Carlo Parata <carlo.parata@st.com> Date: Fri, 20 Sep 2019 11:44:53 +0200 Subject: [PATCH 003/226] Fix issue on Disconnection event --- src/utility/ATT.cpp | 2 +- src/utility/ATT.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utility/ATT.cpp b/src/utility/ATT.cpp index dfa0838a..c28e24d3 100644 --- a/src/utility/ATT.cpp +++ b/src/utility/ATT.cpp @@ -351,7 +351,7 @@ void ATTClass::handleData(uint16_t connectionHandle, uint8_t dlen, uint8_t data[ } } -void ATTClass::removeConnection(uint8_t handle, uint16_t /*reason*/) +void ATTClass::removeConnection(uint16_t handle, uint8_t /*reason*/) { int peerIndex = -1; int peerCount = 0; diff --git a/src/utility/ATT.h b/src/utility/ATT.h index 45802da5..2d006841 100644 --- a/src/utility/ATT.h +++ b/src/utility/ATT.h @@ -53,7 +53,7 @@ class ATTClass { void handleData(uint16_t connectionHandle, uint8_t dlen, uint8_t data[]); - void removeConnection(uint8_t handle, uint16_t reason); + void removeConnection(uint16_t handle, uint8_t reason); uint16_t connectionHandle(uint8_t addressType, const uint8_t address[6]) const; BLERemoteDevice* device(uint8_t addressType, const uint8_t address[6]) const; From e37e3aae8969768aec14db0f8029c9530ee8109d Mon Sep 17 00:00:00 2001 From: Carlo Parata <carlo.parata@st.com> Date: Wed, 25 Sep 2019 14:51:27 +0200 Subject: [PATCH 004/226] Update README and Library properties --- README.md | 7 +++++++ library.properties | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7d6b8fbc..2d575585 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,12 @@ # STM32duinoBLE This library is a fork of ArduinoBLE library to add the support of STBTLE-RF and STBTLE-1S BLE modules. +It was successfully tested with the X-NUCLEO-IDB05A1 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 STBTLE-1S BLE module +mounted on that board as described in the following wiki page: + +https://github.com/stm32duino/wiki/wiki/STM32duinoBLE-with-STEVAL_MKSBOX1V1 You can find the official Pull Request at the following link: @@ -12,6 +18,7 @@ https://github.com/arduino-libraries/ArduinoBLE ## License ``` +Copyright (c) 2019 STMicroelectronics. All rights reserved. Copyright (c) 2019 Arduino SA. All rights reserved. This library is free software; you can redistribute it and/or diff --git a/library.properties b/library.properties index 0f75e882..f63b530a 100644 --- a/library.properties +++ b/library.properties @@ -6,5 +6,5 @@ sentence=Fork of ArduinoBLE library to add the support of STBTLE-RF and STBTLE-1 paragraph=This library supports creating a BLE peripheral and BLE central mode. category=Communication url=https://github.com/stm32duino/STM32duinoBLE -architectures=samd,megaavr,mbed,stm32 +architectures=stm32 includes=ArduinoBLE.h From fa813f01247e94ff29b4c4bb8ed28bb364fe72b2 Mon Sep 17 00:00:00 2001 From: Carlo Parata <carlo.parata@st.com> Date: Tue, 12 Nov 2019 14:00:26 +0100 Subject: [PATCH 005/226] Replace typo STBTLE with SPBTLE --- README.md | 4 +-- library.properties | 2 +- src/utility/HCISpiTransport.cpp | 56 ++++++++++++++++----------------- src/utility/HCISpiTransport.h | 10 +++--- 4 files changed, 36 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index 2d575585..0376b8e4 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ # STM32duinoBLE -This library is a fork of ArduinoBLE library to add the support of STBTLE-RF and STBTLE-1S BLE modules. +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 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 STBTLE-1S BLE module +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: https://github.com/stm32duino/wiki/wiki/STM32duinoBLE-with-STEVAL_MKSBOX1V1 diff --git a/library.properties b/library.properties index f63b530a..4f8706ca 100644 --- a/library.properties +++ b/library.properties @@ -2,7 +2,7 @@ name=STM32duinoBLE version=1.1.1 author=Arduino, SRA maintainer=stm32duino -sentence=Fork of ArduinoBLE library to add the support of STBTLE-RF and STBTLE-1S BLE modules. +sentence=Fork of ArduinoBLE library to add the support of SPBTLE-RF and SPBTLE-1S 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 dd157e43..ab9eeaea 100644 --- a/src/utility/HCISpiTransport.cpp +++ b/src/utility/HCISpiTransport.cpp @@ -75,15 +75,15 @@ int HCISpiTransportClass::begin() digitalWrite(_ble_rst, HIGH); delay(5); -#if defined(STBTLE_RF) +#if defined(SPBTLE_RF) // Wait for Blue Initialize wait_for_blue_initialize(); -#endif /* STBTLE_RF */ +#endif /* SPBTLE_RF */ -#if defined(STBTLE_1S) +#if defined(SPBTLE_1S) // Wait a while for the reset of the BLE module delay(300); -#endif /* STBTLE_1S */ +#endif /* SPBTLE_1S */ return 1; } @@ -132,11 +132,11 @@ int HCISpiTransportClass::available() /* Write the header */ _spi->transfer(header_master, 5); -#if defined(STBTLE_RF) +#if defined(SPBTLE_RF) /* device is ready */ if(header_master[0] == 0x02) { -#endif /* STBTLE_RF */ +#endif /* SPBTLE_RF */ uint16_t byte_count = (header_master[4] << 8) | header_master[3]; if(byte_count > 0) @@ -156,7 +156,7 @@ int HCISpiTransportClass::available() _write_index_initial++; } -#if defined(STBTLE_RF) +#if defined(SPBTLE_RF) /* Check if the message is a Blue Initialize */ /* If so we need to send the command to enable LL_ONLY */ if(byte_count == 6) @@ -171,8 +171,8 @@ int HCISpiTransportClass::available() ble_reset = 1; } } -#endif /* STBTLE_RF */ -#if defined(STBTLE_1S) +#endif /* SPBTLE_RF */ +#if defined(SPBTLE_1S) /* Check if the message is a CMD_COMPLETE */ /* We suppose that the first CMD is always a HCI_RESET */ if(byte_count == 7) @@ -188,7 +188,7 @@ int HCISpiTransportClass::available() ble_reset = 1; } } -#endif /* STBTLE_1S */ +#endif /* SPBTLE_1S */ } else { /* avoid to read more data that available size of the buffer */ @@ -207,9 +207,9 @@ int HCISpiTransportClass::available() } } } -#if defined(STBTLE_RF) +#if defined(SPBTLE_RF) } -#endif /* STBTLE_RF */ +#endif /* SPBTLE_RF */ digitalWrite(_cs_pin, HIGH); @@ -218,15 +218,15 @@ int HCISpiTransportClass::available() if(ble_reset) { -#if defined(STBTLE_RF) +#if defined(SPBTLE_RF) /* BLE chip was reset: we need to enable LL_ONLY */ enable_ll_only(); wait_for_enable_ll_only(); -#endif /* STBTLE_RF */ -#if defined(STBTLE_1S) +#endif /* SPBTLE_RF */ +#if defined(SPBTLE_1S) /* BLE chip was reset: we need to wait for a while */ delay(300); -#endif /* STBTLE_1S */ +#endif /* SPBTLE_1S */ /* Now we can update the write index and close the initial phase */ _write_index = _write_index_initial; @@ -287,16 +287,16 @@ size_t HCISpiTransportClass::write(const uint8_t* data, size_t length) do { -#if defined(STBTLE_1S) +#if defined(SPBTLE_1S) uint32_t tickstart_data_available = millis(); -#endif /* STBTLE_1S */ +#endif /* SPBTLE_1S */ result = 0; _spi->beginTransaction(SPISettings(_frequency, MSBFIRST, _spi_mode)); digitalWrite(_cs_pin, LOW); -#if defined(STBTLE_1S) +#if defined(SPBTLE_1S) /* * Wait until BlueNRG-1 is ready. * When ready it will raise the IRQ pin. @@ -316,20 +316,20 @@ size_t HCISpiTransportClass::write(const uint8_t* data, size_t length) _spi->endTransaction(); break; } -#endif /* STBTLE_1S */ +#endif /* SPBTLE_1S */ /* Write the header */ _spi->transfer(header_master, 5); -#if defined(STBTLE_RF) +#if defined(SPBTLE_RF) /* device is ready */ if(header_master[0] == 0x02) { if(header_master[1] >= length) -#endif /* STBTLE_RF */ -#if defined(STBTLE_1S) +#endif /* SPBTLE_RF */ +#if defined(SPBTLE_1S) if((int)((((uint16_t)header_master[2])<<8) | ((uint16_t)header_master[1])) >= (int)length) -#endif /* STBTLE_1S */ +#endif /* SPBTLE_1S */ { /* Write the data */ _spi->transfer(my_data, length); @@ -337,12 +337,12 @@ size_t HCISpiTransportClass::write(const uint8_t* data, size_t length) { result = -2; } -#if defined(STBTLE_RF) +#if defined(SPBTLE_RF) } else { result = -1; } -#endif /* STBTLE_RF */ +#endif /* SPBTLE_RF */ digitalWrite(_cs_pin, HIGH); @@ -364,7 +364,7 @@ size_t HCISpiTransportClass::write(const uint8_t* data, size_t length) } } -#if defined(STBTLE_RF) +#if defined(SPBTLE_RF) void HCISpiTransportClass::wait_for_blue_initialize() { int event_blue_initialize = 0; @@ -535,7 +535,7 @@ void HCISpiTransportClass::enable_ll_only() _spi->endTransaction(); } while (result < 0); } -#endif /* STBTLE_RF */ +#endif /* SPBTLE_RF */ #if defined(ARDUINO_STEVAL_MKSBOX1V1) HCISpiTransportClass HCISpiTransport(SpiHCI, PD0, PD4, PA8, 1000000, SPI_MODE1); /* STEVAL_MKSBOX1V1 */ diff --git a/src/utility/HCISpiTransport.h b/src/utility/HCISpiTransport.h index 1515257a..70f03684 100644 --- a/src/utility/HCISpiTransport.h +++ b/src/utility/HCISpiTransport.h @@ -24,11 +24,11 @@ #include "SPI.h" #if defined(ARDUINO_STEVAL_MKSBOX1V1) -#define STBTLE_1S /* STEVAL_MKSBOX1V1 */ +#define SPBTLE_1S /* STEVAL_MKSBOX1V1 */ #elif defined(ARDUINO_DISCO_L475VG_IOT) -#define STBTLE_RF /* B-L475E-IOT01A1 */ +#define SPBTLE_RF /* B-L475E-IOT01A1 */ #else -#define STBTLE_RF /* Shield IDB05A1 */ +#define SPBTLE_RF /* Shield IDB05A1 */ #endif /* ARDUINO_STEVAL_MKSBOX1V1 */ #define BLE_MODULE_SPI_BUFFER_SIZE 128 @@ -50,11 +50,11 @@ class HCISpiTransportClass : public HCITransportInterface { virtual size_t write(const uint8_t* data, size_t length); private: -#if defined(STBTLE_RF) +#if defined(SPBTLE_RF) void wait_for_blue_initialize(); void wait_for_enable_ll_only(); void enable_ll_only(); -#endif /* STBTLE_RF */ +#endif /* SPBTLE_RF */ SPIClass* _spi; uint8_t _cs_pin; uint8_t _spi_irq; From c4f359a90e97b3574dc524b2821f35eb9ac32806 Mon Sep 17 00:00:00 2001 From: Carlo Parata <carlo.parata@st.com> Date: Fri, 7 Feb 2020 11:20:49 +0100 Subject: [PATCH 006/226] Improve STM32duinoBLE robustness and flexibility --- README.md | 9 +- examples/Central/LedControl/LedControl.ino | 82 +++++- .../PeripheralExplorer/PeripheralExplorer.ino | 56 +++- examples/Central/Scan/Scan.ino | 47 ++- .../Central/ScanCallback/ScanCallback.ino | 45 ++- .../SensorTagButton/SensorTagButton.ino | 69 ++++- .../BatteryMonitor/BatteryMonitor.ino | 106 ------- examples/Peripheral/ButtonLED/ButtonLED.ino | 42 ++- .../Peripheral/CallbackLED/CallbackLED.ino | 34 ++- examples/Peripheral/LED/LED.ino | 35 ++- keywords.txt | 1 + src/ArduinoBLE.h | 1 + src/local/BLELocalDevice.cpp | 53 +--- src/local/BLELocalDevice.h | 10 +- src/utility/GAP.cpp | 20 +- src/utility/GAP.h | 2 +- src/utility/HCI.cpp | 54 ++-- src/utility/HCI.h | 5 + src/utility/HCICordioTransport.cpp | 271 ----------------- src/utility/HCICordioTransport.h | 54 ---- src/utility/HCISpiTransport.cpp | 276 +++++++++++------- src/utility/HCISpiTransport.h | 17 +- src/utility/HCIUartTransport.cpp | 103 ------- src/utility/HCIUartTransport.h | 46 --- 24 files changed, 603 insertions(+), 835 deletions(-) delete mode 100644 examples/Peripheral/BatteryMonitor/BatteryMonitor.ino delete mode 100644 src/utility/HCICordioTransport.cpp delete mode 100644 src/utility/HCICordioTransport.h delete mode 100644 src/utility/HCIUartTransport.cpp delete mode 100644 src/utility/HCIUartTransport.h diff --git a/README.md b/README.md index 0376b8e4..437e1ae3 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,17 @@ # 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 expansion board and a NUCLEO-F401RE or NUCLEO-L476RG or -NUCLEO-L053R8, with B-L475E-IOT01A and with STEVAL-MKSBOX1V1. +It was successfully tested with the 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: https://github.com/stm32duino/wiki/wiki/STM32duinoBLE-with-STEVAL_MKSBOX1V1 -You can find the official Pull Request at the following link: +In order to use this library with X-NUCLEO-BNRG2A1, you need to update the firmware of the BLUENRG-M2SP BLE module +mounted on that expansion board as described in the following wiki page: -https://github.com/arduino-libraries/ArduinoBLE/pull/26 +https://github.com/stm32duino/wiki/wiki/STM32duinoBLE-with-X_NUCLEO_BNRG2A1 For more information about ArduinoBLE library please visit the official web page at: https://github.com/arduino-libraries/ArduinoBLE diff --git a/examples/Central/LedControl/LedControl.ino b/examples/Central/LedControl/LedControl.ino index 8301a311..af082e00 100644 --- a/examples/Central/LedControl/LedControl.ino +++ b/examples/Central/LedControl/LedControl.ino @@ -6,9 +6,7 @@ it will remotely control the BLE Peripheral's LED, when the button is pressed or released. The circuit: - - Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT, - Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board. - - Button with pull-up resistor connected to pin 2. + - STEVAL-MKSBOX1V1, B-L475E-IOT01A1, or a Nucleo board plus the X-NUCLEO-IDB05A1 or the X-NUCLEO-BNRG2A1 You can use it with another board that is compatible with this library and the Peripherals -> LED example. @@ -18,12 +16,47 @@ #include <ArduinoBLE.h> +#if defined(ARDUINO_STEVAL_MKSBOX1V1) +/* STEVAL-MKSBOX1V1 */ +SPIClass SpiHCI(PC3, PD3, PD1); +HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_1S, PD0, PD4, PA8, 1000000, SPI_MODE1); +BLELocalDevice BLE(&HCISpiTransport); +const int buttonPin = PG1; // set buttonPin to digital pin PG1 +#elif defined(ARDUINO_DISCO_L475VG_IOT) +/* B-L475E-IOT01A1 */ +SPIClass SpiHCI(PC12, PC11, PC10); +HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, PD13, PE6, PA8, 8000000, SPI_MODE0); +BLELocalDevice BLE(&HCISpiTransport); +const int buttonPin = PC13; // set buttonPin to digital pin PC13 +#else +/* 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 */ +/*SPIClass SpiHCI(D11, D12, D13); +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 BNRG2A1 with SPI clock on D3 */ +/*SPIClass SpiHCI(D11, D12, D3); +HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1); +BLELocalDevice BLE(&HCISpiTransport); +const int buttonPin = PC13; // set buttonPin to digital pin PC13 */ +/* Shield BNRG2A1 with SPI clock on D13 */ +/*SPIClass SpiHCI(D11, D12, D13); +HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1); +BLELocalDevice BLE(&HCISpiTransport); +const int buttonPin = PC13; // set buttonPin to digital pin PC13 */ +#endif + // variables for button -const int buttonPin = 2; int oldButtonState = LOW; +int initialButtonState = LOW; void setup() { - Serial.begin(9600); + Serial.begin(115200); while (!Serial); // configure the button pin as input @@ -32,10 +65,23 @@ void setup() { // initialize the BLE hardware BLE.begin(); + // Get initial button state + initialButtonState = digitalRead(buttonPin); + oldButtonState = initialButtonState; + Serial.println("BLE Central - LED control"); // start scanning for peripherals - BLE.scanForUuid("19b10000-e8f2-537e-4f6c-d104768a1214"); + int ret = 1; + do + { + ret = BLE.scanForUuid("19b10000-e8f2-537e-4f6c-d104768a1214"); + if (ret == 0) + { + BLE.end(); + BLE.begin(); + } + } while(ret == 0); } void loop() { @@ -57,12 +103,30 @@ void loop() { } // stop scanning - BLE.stopScan(); + int ret = 1; + do + { + ret = BLE.stopScan(); + if (ret == 0) + { + BLE.end(); + BLE.begin(); + } + } while(ret == 0); controlLed(peripheral); // peripheral disconnected, start scanning again - BLE.scanForUuid("19b10000-e8f2-537e-4f6c-d104768a1214"); + ret = 1; + do + { + ret = BLE.scanForUuid("19b10000-e8f2-537e-4f6c-d104768a1214"); + if (ret == 0) + { + BLE.end(); + BLE.begin(); + } + } while(ret == 0); } } @@ -110,7 +174,7 @@ void controlLed(BLEDevice peripheral) { // button changed oldButtonState = buttonState; - if (buttonState) { + if (buttonState != initialButtonState) { Serial.println("button pressed"); // button is pressed, write 0x01 to turn the LED on diff --git a/examples/Central/PeripheralExplorer/PeripheralExplorer.ino b/examples/Central/PeripheralExplorer/PeripheralExplorer.ino index 100225d6..357a8ef4 100644 --- a/examples/Central/PeripheralExplorer/PeripheralExplorer.ino +++ b/examples/Central/PeripheralExplorer/PeripheralExplorer.ino @@ -5,8 +5,7 @@ is found. Then connects, and discovers + prints all the peripheral's attributes. The circuit: - - Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT, - Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board. + - STEVAL-MKSBOX1V1, B-L475E-IOT01A1, or a Nucleo board plus the X-NUCLEO-IDB05A1 or the X-NUCLEO-BNRG2A1 You can use it with another board that is compatible with this library and the Peripherals -> LED example. @@ -16,8 +15,37 @@ #include <ArduinoBLE.h> +#if defined(ARDUINO_STEVAL_MKSBOX1V1) +/* STEVAL-MKSBOX1V1 */ +SPIClass SpiHCI(PC3, PD3, PD1); +HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_1S, PD0, PD4, PA8, 1000000, SPI_MODE1); +BLELocalDevice BLE(&HCISpiTransport); +#elif defined(ARDUINO_DISCO_L475VG_IOT) +/* B-L475E-IOT01A1 */ +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 */ +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); +BLELocalDevice BLE(&HCISpiTransport); */ +/* Shield BNRG2A1 with SPI clock on D3 */ +/*SPIClass SpiHCI(D11, D12, D3); +HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1); +BLELocalDevice BLE(&HCISpiTransport); */ +/* Shield BNRG2A1 with SPI clock on D13 */ +/*SPIClass SpiHCI(D11, D12, D13); +HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1); +BLELocalDevice BLE(&HCISpiTransport); */ +#endif + void setup() { - Serial.begin(9600); + Serial.begin(115200); while (!Serial); // begin initialization @@ -30,7 +58,16 @@ void setup() { Serial.println("BLE Central - Peripheral Explorer"); // start scanning for peripherals - BLE.scan(); + int ret = 1; + do + { + ret = BLE.scan(); + if (ret == 0) + { + BLE.end(); + BLE.begin(); + } + } while(ret == 0); } void loop() { @@ -50,7 +87,16 @@ void loop() { // see if peripheral is a LED if (peripheral.localName() == "LED") { // stop scanning - BLE.stopScan(); + int ret = 1; + do + { + ret = BLE.stopScan(); + if (ret == 0) + { + BLE.end(); + BLE.begin(); + } + } while(ret == 0); explorerPeripheral(peripheral); diff --git a/examples/Central/Scan/Scan.ino b/examples/Central/Scan/Scan.ino index 784f3058..5326514f 100644 --- a/examples/Central/Scan/Scan.ino +++ b/examples/Central/Scan/Scan.ino @@ -5,16 +5,44 @@ address, local name, adverised service UUID's. The circuit: - - Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT, - Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board. + - STEVAL-MKSBOX1V1, B-L475E-IOT01A1, or a Nucleo board plus the X-NUCLEO-IDB05A1 or the X-NUCLEO-BNRG2A1 This example code is in the public domain. */ #include <ArduinoBLE.h> +#if defined(ARDUINO_STEVAL_MKSBOX1V1) +/* STEVAL-MKSBOX1V1 */ +SPIClass SpiHCI(PC3, PD3, PD1); +HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_1S, PD0, PD4, PA8, 1000000, SPI_MODE1); +BLELocalDevice BLE(&HCISpiTransport); +#elif defined(ARDUINO_DISCO_L475VG_IOT) +/* B-L475E-IOT01A1 */ +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 */ +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); +BLELocalDevice BLE(&HCISpiTransport); */ +/* Shield BNRG2A1 with SPI clock on D3 */ +/*SPIClass SpiHCI(D11, D12, D3); +HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1); +BLELocalDevice BLE(&HCISpiTransport); */ +/* Shield BNRG2A1 with SPI clock on D13 */ +/*SPIClass SpiHCI(D11, D12, D13); +HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1); +BLELocalDevice BLE(&HCISpiTransport); */ +#endif + void setup() { - Serial.begin(9600); + Serial.begin(115200); while (!Serial); // begin initialization @@ -26,8 +54,17 @@ void setup() { Serial.println("BLE Central scan"); - // start scanning for peripheral - BLE.scan(); + // start scanning for peripherals + int ret = 1; + do + { + ret = BLE.scan(); + if (ret == 0) + { + BLE.end(); + BLE.begin(); + } + } while(ret == 0); } void loop() { diff --git a/examples/Central/ScanCallback/ScanCallback.ino b/examples/Central/ScanCallback/ScanCallback.ino index 9583079c..f84b88e1 100644 --- a/examples/Central/ScanCallback/ScanCallback.ino +++ b/examples/Central/ScanCallback/ScanCallback.ino @@ -7,16 +7,44 @@ reported for every single advertisement it makes. The circuit: - - Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT, - Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board. + - STEVAL-MKSBOX1V1, B-L475E-IOT01A1, or a Nucleo board plus the X-NUCLEO-IDB05A1 or the X-NUCLEO-BNRG2A1 This example code is in the public domain. */ #include <ArduinoBLE.h> +#if defined(ARDUINO_STEVAL_MKSBOX1V1) +/* STEVAL-MKSBOX1V1 */ +SPIClass SpiHCI(PC3, PD3, PD1); +HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_1S, PD0, PD4, PA8, 1000000, SPI_MODE1); +BLELocalDevice BLE(&HCISpiTransport); +#elif defined(ARDUINO_DISCO_L475VG_IOT) +/* B-L475E-IOT01A1 */ +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 */ +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); +BLELocalDevice BLE(&HCISpiTransport); */ +/* Shield BNRG2A1 with SPI clock on D3 */ +/*SPIClass SpiHCI(D11, D12, D3); +HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1); +BLELocalDevice BLE(&HCISpiTransport); */ +/* Shield BNRG2A1 with SPI clock on D13 */ +/*SPIClass SpiHCI(D11, D12, D13); +HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1); +BLELocalDevice BLE(&HCISpiTransport); */ +#endif + void setup() { - Serial.begin(9600); + Serial.begin(115200); while (!Serial); // begin initialization @@ -32,7 +60,16 @@ void setup() { BLE.setEventHandler(BLEDiscovered, bleCentralDiscoverHandler); // start scanning for peripherals with duplicates - BLE.scan(true); + int ret = 1; + do + { + ret = BLE.scan(true); + if (ret == 0) + { + BLE.end(); + BLE.begin(); + } + } while(ret == 0); } void loop() { diff --git a/examples/Central/SensorTagButton/SensorTagButton.ino b/examples/Central/SensorTagButton/SensorTagButton.ino index 72dad90b..dd8d8ade 100644 --- a/examples/Central/SensorTagButton/SensorTagButton.ino +++ b/examples/Central/SensorTagButton/SensorTagButton.ino @@ -8,8 +8,7 @@ outputted to the Serial Monitor when one is pressed. The circuit: - - Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT, - Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board. + - STEVAL-MKSBOX1V1, B-L475E-IOT01A1, or a Nucleo board plus the X-NUCLEO-IDB05A1 or the X-NUCLEO-BNRG2A1 - TI SensorTag This example code is in the public domain. @@ -17,8 +16,37 @@ #include <ArduinoBLE.h> +#if defined(ARDUINO_STEVAL_MKSBOX1V1) +/* STEVAL-MKSBOX1V1 */ +SPIClass SpiHCI(PC3, PD3, PD1); +HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_1S, PD0, PD4, PA8, 1000000, SPI_MODE1); +BLELocalDevice BLE(&HCISpiTransport); +#elif defined(ARDUINO_DISCO_L475VG_IOT) +/* B-L475E-IOT01A1 */ +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 */ +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); +BLELocalDevice BLE(&HCISpiTransport); */ +/* Shield BNRG2A1 with SPI clock on D3 */ +/*SPIClass SpiHCI(D11, D12, D3); +HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1); +BLELocalDevice BLE(&HCISpiTransport); */ +/* Shield BNRG2A1 with SPI clock on D13 */ +/*SPIClass SpiHCI(D11, D12, D13); +HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1); +BLELocalDevice BLE(&HCISpiTransport); */ +#endif + void setup() { - Serial.begin(9600); + Serial.begin(115200); while (!Serial); // begin initialization @@ -31,8 +59,17 @@ void setup() { Serial.println("BLE Central - SensorTag button"); Serial.println("Make sure to turn on the device."); - // start scanning for peripheral - BLE.scan(); + // start scanning for peripherals + int ret = 1; + do + { + ret = BLE.scan(); + if (ret == 0) + { + BLE.end(); + BLE.begin(); + } + } while(ret == 0); } void loop() { @@ -53,12 +90,30 @@ void loop() { // "CC2650 SensorTag" if (peripheral.localName() == "CC2650 SensorTag") { // stop scanning - BLE.stopScan(); + int ret = 1; + do + { + ret = BLE.stopScan(); + if (ret == 0) + { + BLE.end(); + BLE.begin(); + } + } while(ret == 0); monitorSensorTagButtons(peripheral); // peripheral disconnected, start scanning again - BLE.scan(); + ret = 1; + do + { + ret = BLE.scan(); + if (ret == 0) + { + BLE.end(); + BLE.begin(); + } + } while(ret == 0); } } } diff --git a/examples/Peripheral/BatteryMonitor/BatteryMonitor.ino b/examples/Peripheral/BatteryMonitor/BatteryMonitor.ino deleted file mode 100644 index 6c5d3d30..00000000 --- a/examples/Peripheral/BatteryMonitor/BatteryMonitor.ino +++ /dev/null @@ -1,106 +0,0 @@ -/* - Battery Monitor - - This example creates a BLE peripheral with the standard battery service and - level characteristic. The A0 pin is used to calculate the battery level. - - The circuit: - - Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT, - Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board. - - You can use a generic BLE central app, like LightBlue (iOS and Android) or - nRF Connect (Android), to interact with the services and characteristics - created in this sketch. - - This example code is in the public domain. -*/ - -#include <ArduinoBLE.h> - - // BLE Battery Service -BLEService batteryService("180F"); - -// BLE Battery Level Characteristic -BLEUnsignedCharCharacteristic batteryLevelChar("2A19", // standard 16-bit characteristic UUID - BLERead | BLENotify); // remote clients will be able to get notifications if this characteristic changes - -int oldBatteryLevel = 0; // last battery level reading from analog input -long previousMillis = 0; // last time the battery level was checked, in ms - -void setup() { - Serial.begin(9600); // initialize serial communication - while (!Serial); - - pinMode(LED_BUILTIN, OUTPUT); // initialize the built-in LED pin to indicate when a central is connected - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting BLE failed!"); - - while (1); - } - - /* Set a local name for the BLE device - This name will appear in advertising packets - and can be used by remote devices to identify this BLE device - The name can be changed but maybe be truncated based on space left in advertisement packet - */ - BLE.setLocalName("BatteryMonitor"); - BLE.setAdvertisedService(batteryService); // add the service UUID - batteryService.addCharacteristic(batteryLevelChar); // add the battery level characteristic - BLE.addService(batteryService); // Add the battery service - batteryLevelChar.writeValue(oldBatteryLevel); // set initial value for this characteristic - - /* Start advertising BLE. It will start continuously transmitting BLE - advertising packets and will be visible to remote BLE central devices - until it receives a new connection */ - - // start advertising - BLE.advertise(); - - Serial.println("Bluetooth device active, waiting for connections..."); -} - -void loop() { - // wait for a BLE central - BLEDevice central = BLE.central(); - - // if a central is connected to the peripheral: - if (central) { - Serial.print("Connected to central: "); - // print the central's BT address: - Serial.println(central.address()); - // turn on the LED to indicate the connection: - digitalWrite(LED_BUILTIN, HIGH); - - // check the battery level every 200ms - // while the central is connected: - while (central.connected()) { - long currentMillis = millis(); - // if 200ms have passed, check the battery level: - if (currentMillis - previousMillis >= 200) { - previousMillis = currentMillis; - updateBatteryLevel(); - } - } - // when the central disconnects, turn off the LED: - digitalWrite(LED_BUILTIN, LOW); - Serial.print("Disconnected from central: "); - Serial.println(central.address()); - } -} - -void updateBatteryLevel() { - /* Read the current voltage level on the A0 analog input pin. - This is used here to simulate the charge level of a battery. - */ - int battery = analogRead(A0); - int batteryLevel = map(battery, 0, 1023, 0, 100); - - if (batteryLevel != oldBatteryLevel) { // if the battery level has changed - Serial.print("Battery Level % is now: "); // print it - Serial.println(batteryLevel); - batteryLevelChar.writeValue(batteryLevel); // and update the battery level characteristic - oldBatteryLevel = batteryLevel; // save the level for next comparison - } -} diff --git a/examples/Peripheral/ButtonLED/ButtonLED.ino b/examples/Peripheral/ButtonLED/ButtonLED.ino index bd373731..9b0dfb0b 100644 --- a/examples/Peripheral/ButtonLED/ButtonLED.ino +++ b/examples/Peripheral/ButtonLED/ButtonLED.ino @@ -6,9 +6,7 @@ represents the state of the button. The circuit: - - Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT, - Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board. - - Button connected to pin 4 + - STEVAL-MKSBOX1V1, B-L475E-IOT01A1, or a Nucleo board plus the X-NUCLEO-IDB05A1 or the X-NUCLEO-BNRG2A1 You can use a generic BLE central app, like LightBlue (iOS and Android) or nRF Connect (Android), to interact with the services and characteristics @@ -19,8 +17,42 @@ #include <ArduinoBLE.h> +#if defined(ARDUINO_STEVAL_MKSBOX1V1) +/* STEVAL-MKSBOX1V1 */ +SPIClass SpiHCI(PC3, PD3, PD1); +HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_1S, PD0, PD4, PA8, 1000000, SPI_MODE1); +BLELocalDevice BLE(&HCISpiTransport); +const int buttonPin = PG1; // set buttonPin to digital pin PG1 +#elif defined(ARDUINO_DISCO_L475VG_IOT) +/* B-L475E-IOT01A1 */ +SPIClass SpiHCI(PC12, PC11, PC10); +HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, PD13, PE6, PA8, 8000000, SPI_MODE0); +BLELocalDevice BLE(&HCISpiTransport); +const int buttonPin = PC13; // set buttonPin to digital pin PC13 +#else +/* 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 */ +/*SPIClass SpiHCI(D11, D12, D13); +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 BNRG2A1 with SPI clock on D3 */ +/*SPIClass SpiHCI(D11, D12, D3); +HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1); +BLELocalDevice BLE(&HCISpiTransport); +const int buttonPin = PC13; // set buttonPin to digital pin PC13 */ +/* Shield BNRG2A1 with SPI clock on D13 */ +/*SPIClass SpiHCI(D11, D12, D13); +HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1); +BLELocalDevice BLE(&HCISpiTransport); +const int buttonPin = PC13; // set buttonPin to digital pin PC13 */ +#endif + const int ledPin = LED_BUILTIN; // set ledPin to on-board LED -const int buttonPin = 4; // set buttonPin to digital pin 4 BLEService ledService("19B10010-E8F2-537E-4F6C-D104768A1214"); // create service @@ -30,7 +62,7 @@ BLEByteCharacteristic ledCharacteristic("19B10011-E8F2-537E-4F6C-D104768A1214", BLEByteCharacteristic buttonCharacteristic("19B10012-E8F2-537E-4F6C-D104768A1214", BLERead | BLENotify); void setup() { - Serial.begin(9600); + Serial.begin(115200); while (!Serial); pinMode(ledPin, OUTPUT); // use the LED as an output diff --git a/examples/Peripheral/CallbackLED/CallbackLED.ino b/examples/Peripheral/CallbackLED/CallbackLED.ino index a874a77b..c794856e 100644 --- a/examples/Peripheral/CallbackLED/CallbackLED.ino +++ b/examples/Peripheral/CallbackLED/CallbackLED.ino @@ -6,8 +6,7 @@ library are used. The circuit: - - Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT, - Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board. + - STEVAL-MKSBOX1V1, B-L475E-IOT01A1, or a Nucleo board plus the X-NUCLEO-IDB05A1 or the X-NUCLEO-BNRG2A1 You can use a generic BLE central app, like LightBlue (iOS and Android) or nRF Connect (Android), to interact with the services and characteristics @@ -18,6 +17,35 @@ #include <ArduinoBLE.h> +#if defined(ARDUINO_STEVAL_MKSBOX1V1) +/* STEVAL-MKSBOX1V1 */ +SPIClass SpiHCI(PC3, PD3, PD1); +HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_1S, PD0, PD4, PA8, 1000000, SPI_MODE1); +BLELocalDevice BLE(&HCISpiTransport); +#elif defined(ARDUINO_DISCO_L475VG_IOT) +/* B-L475E-IOT01A1 */ +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 */ +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); +BLELocalDevice BLE(&HCISpiTransport); */ +/* Shield BNRG2A1 with SPI clock on D3 */ +/*SPIClass SpiHCI(D11, D12, D3); +HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1); +BLELocalDevice BLE(&HCISpiTransport); */ +/* Shield BNRG2A1 with SPI clock on D13 */ +/*SPIClass SpiHCI(D11, D12, D13); +HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1); +BLELocalDevice BLE(&HCISpiTransport); */ +#endif + BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // create service // create switch characteristic and allow remote device to read and write @@ -26,7 +54,7 @@ BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214 const int ledPin = LED_BUILTIN; // pin to use for the LED void setup() { - Serial.begin(9600); + Serial.begin(115200); while (!Serial); pinMode(ledPin, OUTPUT); // use the LED pin as an output diff --git a/examples/Peripheral/LED/LED.ino b/examples/Peripheral/LED/LED.ino index 1ede6535..a6da2dca 100644 --- a/examples/Peripheral/LED/LED.ino +++ b/examples/Peripheral/LED/LED.ino @@ -5,8 +5,7 @@ characteristic to control an LED. The circuit: - - Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT, - Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board. + - STEVAL-MKSBOX1V1, B-L475E-IOT01A1, or a Nucleo board plus the X-NUCLEO-IDB05A1 or the X-NUCLEO-BNRG2A1 You can use a generic BLE central app, like LightBlue (iOS and Android) or nRF Connect (Android), to interact with the services and characteristics @@ -14,9 +13,37 @@ This example code is in the public domain. */ - #include <ArduinoBLE.h> +#if defined(ARDUINO_STEVAL_MKSBOX1V1) +/* STEVAL-MKSBOX1V1 */ +SPIClass SpiHCI(PC3, PD3, PD1); +HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_1S, PD0, PD4, PA8, 1000000, SPI_MODE1); +BLELocalDevice BLE(&HCISpiTransport); +#elif defined(ARDUINO_DISCO_L475VG_IOT) +/* B-L475E-IOT01A1 */ +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 */ +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); +BLELocalDevice BLE(&HCISpiTransport); */ +/* Shield BNRG2A1 with SPI clock on D3 */ +/*SPIClass SpiHCI(D11, D12, D3); +HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1); +BLELocalDevice BLE(&HCISpiTransport); */ +/* Shield BNRG2A1 with SPI clock on D13 */ +/*SPIClass SpiHCI(D11, D12, D13); +HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1); +BLELocalDevice BLE(&HCISpiTransport); */ +#endif + BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // BLE LED Service // BLE LED Switch Characteristic - custom 128-bit UUID, read and writable by central @@ -25,7 +52,7 @@ BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214 const int ledPin = LED_BUILTIN; // pin to use for the LED void setup() { - Serial.begin(9600); + Serial.begin(115200); while (!Serial); // set LED pin to output mode diff --git a/keywords.txt b/keywords.txt index 464cac72..12f67785 100644 --- a/keywords.txt +++ b/keywords.txt @@ -80,6 +80,7 @@ setConnectable KEYWORD2 setTimeout KEYWORD2 debug KEYWORD2 noDebug KEYWORD2 +setTransport KEYWORD2 properties KEYWORD2 valueSize KEYWORD2 diff --git a/src/ArduinoBLE.h b/src/ArduinoBLE.h index dc6e8188..41c11111 100644 --- a/src/ArduinoBLE.h +++ b/src/ArduinoBLE.h @@ -24,5 +24,6 @@ #include "BLEProperty.h" #include "BLEStringCharacteristic.h" #include "BLETypedCharacteristics.h" +#include "utility/HCISpiTransport.h" #endif diff --git a/src/local/BLELocalDevice.cpp b/src/local/BLELocalDevice.cpp index d2c8a1b3..51e48b7f 100644 --- a/src/local/BLELocalDevice.cpp +++ b/src/local/BLELocalDevice.cpp @@ -18,14 +18,13 @@ */ #include "utility/ATT.h" -#include "utility/HCI.h" #include "utility/GAP.h" #include "utility/GATT.h" #include "utility/L2CAPSignaling.h" - #include "BLELocalDevice.h" -BLELocalDevice::BLELocalDevice() +BLELocalDevice::BLELocalDevice(HCITransportInterface *HCITransport) : + _HCITransport(HCITransport) { } @@ -35,39 +34,7 @@ BLELocalDevice::~BLELocalDevice() int BLELocalDevice::begin() { -#if defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_AVR_UNO_WIFI_REV2) || defined(ARDUINO_SAMD_NANO_33_IOT) - // reset the NINA in BLE mode - pinMode(SPIWIFI_SS, OUTPUT); - pinMode(NINA_RESETN, OUTPUT); - - digitalWrite(SPIWIFI_SS, LOW); -#endif - -#if defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_AVR_UNO_WIFI_REV2) - digitalWrite(NINA_RESETN, HIGH); - delay(100); - digitalWrite(NINA_RESETN, LOW); - delay(750); -#elif defined(ARDUINO_SAMD_NANO_33_IOT) - // inverted reset - digitalWrite(NINA_RESETN, LOW); - delay(100); - digitalWrite(NINA_RESETN, HIGH); - delay(750); -#endif - - -#ifdef ARDUINO_AVR_UNO_WIFI_REV2 - // set SS HIGH - digitalWrite(SPIWIFI_SS, HIGH); - - // set RTS HIGH - pinMode(NINA_RTS, OUTPUT); - digitalWrite(NINA_RTS, HIGH); - - // set CTS as input - pinMode(NINA_CTS, INPUT); -#endif + HCI.setTransport(_HCITransport); if (!HCI.begin()) { end(); @@ -116,14 +83,6 @@ void BLELocalDevice::end() GATT.end(); HCI.end(); - -#if defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_AVR_UNO_WIFI_REV2) - // disable the NINA - digitalWrite(NINA_RESETN, HIGH); -#elif defined(ARDUINO_SAMD_NANO_33_IOT) - // disable the NINA - digitalWrite(NINA_RESETN, LOW); -#endif } void BLELocalDevice::poll() @@ -240,9 +199,9 @@ int BLELocalDevice::scanForAddress(String address, bool withDuplicates) return GAP.scanForAddress(address, withDuplicates); } -void BLELocalDevice::stopScan() +int BLELocalDevice::stopScan() { - GAP.stopScan(); + return GAP.stopScan(); } BLEDevice BLELocalDevice::central() @@ -297,5 +256,3 @@ void BLELocalDevice::noDebug() { HCI.noDebug(); } - -BLELocalDevice BLE; diff --git a/src/local/BLELocalDevice.h b/src/local/BLELocalDevice.h index 20837c14..27f001fb 100644 --- a/src/local/BLELocalDevice.h +++ b/src/local/BLELocalDevice.h @@ -20,12 +20,13 @@ #ifndef _BLE_LOCAL_DEVICE_H_ #define _BLE_LOCAL_DEVICE_H_ +#include "utility/HCI.h" #include "BLEDevice.h" #include "BLEService.h" class BLELocalDevice { public: - BLELocalDevice(); + BLELocalDevice(HCITransportInterface *HCITransport); virtual ~BLELocalDevice(); int begin(); @@ -39,7 +40,7 @@ class BLELocalDevice { String address() const; - int rssi(); + int rssi(); void setAdvertisedServiceUuid(const char* advertisedServiceUuid); void setAdvertisedService(const BLEService& service); @@ -59,7 +60,7 @@ class BLELocalDevice { int scanForName(String name, bool withDuplicates = false); int scanForUuid(String uuid, bool withDuplicates = false); int scanForAddress(String address, bool withDuplicates = false); - void stopScan(); + int stopScan(); BLEDevice central(); BLEDevice available(); @@ -76,8 +77,7 @@ class BLELocalDevice { void noDebug(); private: + HCITransportInterface *_HCITransport; }; -extern BLELocalDevice BLE; - #endif diff --git a/src/utility/GAP.cpp b/src/utility/GAP.cpp index ae2e90cd..2948a38a 100644 --- a/src/utility/GAP.cpp +++ b/src/utility/GAP.cpp @@ -153,7 +153,7 @@ int GAPClass::advertise() return 0; } - _advertising = false; + _advertising = true; return 1; } @@ -167,7 +167,12 @@ void GAPClass::stopAdvertise() int GAPClass::scan(bool withDuplicates) { - HCI.leSetScanEnable(false, true); + if(_scanning) { + // Check if the HCI command fails + if (HCI.leSetScanEnable(false, true) != 0) { + return 0; + } + } // active scan, 10 ms scan interval (N * 0.625), 10 ms scan window (N * 0.625), public own address type, no filter if (HCI.leSetScanParameters(0x01, 0x0010, 0x0010, 0x00, 0x00) != 0) { @@ -210,9 +215,14 @@ int GAPClass::scanForAddress(String address, bool withDuplicates) return scan(withDuplicates); } -void GAPClass::stopScan() +int GAPClass::stopScan() { - HCI.leSetScanEnable(false, false); + if(_scanning) { + // Check if the HCI command fails + if (HCI.leSetScanEnable(false, false) != 0) { + return 0; + } + } _scanning = false; @@ -223,6 +233,8 @@ void GAPClass::stopScan() } _discoveredDevices.clear(); + + return 1; } BLEDevice GAPClass::available() diff --git a/src/utility/GAP.h b/src/utility/GAP.h index c2a99daa..b1b1cf48 100644 --- a/src/utility/GAP.h +++ b/src/utility/GAP.h @@ -42,7 +42,7 @@ class GAPClass { int scanForName(String name, bool withDuplicates); int scanForUuid(String uuid, bool withDuplicates); int scanForAddress(String address, bool withDuplicates); - void stopScan(); + int stopScan(); BLEDevice available(); void setAdvertisingInterval(uint16_t advertisingInterval); diff --git a/src/utility/HCI.cpp b/src/utility/HCI.cpp index 0234803f..f1bc1552 100644 --- a/src/utility/HCI.cpp +++ b/src/utility/HCI.cpp @@ -19,7 +19,6 @@ #include "ATT.h" #include "GAP.h" -#include "HCITransport.h" #include "L2CAPSignaling.h" #include "HCI.h" @@ -75,8 +74,10 @@ HCIClass::HCIClass() : _debug(NULL), _recvIndex(0), - _pendingPkt(0) + _pendingPkt(0), + _HCITransport(0) { + } HCIClass::~HCIClass() @@ -87,12 +88,12 @@ int HCIClass::begin() { _recvIndex = 0; - return HCITransport.begin(); + return _HCITransport->begin(); } void HCIClass::end() { - HCITransport.end(); + _HCITransport->end(); } void HCIClass::poll() @@ -102,16 +103,12 @@ void HCIClass::poll() void HCIClass::poll(unsigned long timeout) { -#ifdef ARDUINO_AVR_UNO_WIFI_REV2 - digitalWrite(NINA_RTS, LOW); -#endif - if (timeout) { - HCITransport.wait(timeout); + _HCITransport->wait(timeout); } - while (HCITransport.available()) { - byte b = HCITransport.read(); + while (_HCITransport->available()) { + byte b = _HCITransport->read(); _recvBuffer[_recvIndex++] = b; @@ -120,35 +117,23 @@ void HCIClass::poll(unsigned long timeout) if (_debug) { dumpPkt("HCI ACLDATA RX <- ", _recvIndex, _recvBuffer); } -#ifdef ARDUINO_AVR_UNO_WIFI_REV2 - digitalWrite(NINA_RTS, HIGH); -#endif + int pktLen = _recvIndex - 1; _recvIndex = 0; handleAclDataPkt(pktLen, &_recvBuffer[1]); - -#ifdef ARDUINO_AVR_UNO_WIFI_REV2 - digitalWrite(NINA_RTS, LOW); -#endif } } else if (_recvBuffer[0] == HCI_EVENT_PKT) { if (_recvIndex > 3 && _recvIndex >= (3 + _recvBuffer[2])) { if (_debug) { dumpPkt("HCI EVENT RX <- ", _recvIndex, _recvBuffer); } -#ifdef ARDUINO_AVR_UNO_WIFI_REV2 - digitalWrite(NINA_RTS, HIGH); -#endif + // received full event int pktLen = _recvIndex - 1; _recvIndex = 0; handleEventPkt(pktLen, &_recvBuffer[1]); - -#ifdef ARDUINO_AVR_UNO_WIFI_REV2 - digitalWrite(NINA_RTS, LOW); -#endif } } else { _recvIndex = 0; @@ -158,10 +143,6 @@ void HCIClass::poll(unsigned long timeout) } } } - -#ifdef ARDUINO_AVR_UNO_WIFI_REV2 - digitalWrite(NINA_RTS, HIGH); -#endif } int HCIClass::reset() @@ -240,9 +221,7 @@ int HCIClass::readLeBufferSize(uint16_t& pktLen, uint8_t& maxPkt) pktLen = leBufferSize->pktLen; _maxPkt = maxPkt = leBufferSize->maxPkt; -#ifndef __AVR__ ATT.setMaxMtu(pktLen - 9); // max pkt len - ACL header size -#endif } return result; @@ -436,7 +415,7 @@ int HCIClass::sendAclPkt(uint16_t handle, uint8_t cid, uint8_t plen, void* data) } _pendingPkt++; - HCITransport.write(txBuffer, sizeof(aclHdr) + plen); + _HCITransport->write(txBuffer, sizeof(aclHdr) + plen); return 0; } @@ -477,7 +456,7 @@ int HCIClass::sendCommand(uint16_t opcode, uint8_t plen, void* parameters) dumpPkt("HCI COMMAND TX -> ", sizeof(pktHdr) + plen, txBuffer); } - HCITransport.write(txBuffer, sizeof(pktHdr) + plen); + _HCITransport->write(txBuffer, sizeof(pktHdr) + plen); _cmdCompleteOpcode = 0xffff; _cmdCompleteStatus = -1; @@ -571,7 +550,9 @@ void HCIClass::handleEventPkt(uint8_t /*plen*/, uint8_t pdata[]) ATT.removeConnection(disconnComplete->handle, disconnComplete->reason); L2CAPSignaling.removeConnection(disconnComplete->handle, disconnComplete->reason); - HCI.leSetAdvertiseEnable(0x01); + if(GAP.advertising()) { + HCI.leSetAdvertiseEnable(0x01); + } } else if (eventHdr->evt == EVT_CMD_COMPLETE) { struct __attribute__ ((packed)) CmdComplete { uint8_t ncmd; @@ -686,4 +667,9 @@ void HCIClass::dumpPkt(const char* prefix, uint8_t plen, uint8_t pdata[]) } } +void HCIClass::setTransport(HCITransportInterface *HCITransport) +{ + _HCITransport = HCITransport; +} + HCIClass HCI; diff --git a/src/utility/HCI.h b/src/utility/HCI.h index 86ec679c..01923e3a 100644 --- a/src/utility/HCI.h +++ b/src/utility/HCI.h @@ -21,6 +21,7 @@ #define _HCI_H_ #include <Arduino.h> +#include "HCITransport.h" class HCIClass { public: @@ -71,6 +72,8 @@ class HCIClass { void debug(Stream& stream); void noDebug(); + void setTransport(HCITransportInterface *HCITransport); + private: int sendCommand(uint16_t opcode, uint8_t plen = 0, void* parameters = NULL); @@ -94,6 +97,8 @@ class HCIClass { uint8_t _pendingPkt; uint8_t _aclPktBuffer[255]; + + HCITransportInterface *_HCITransport; }; extern HCIClass HCI; diff --git a/src/utility/HCICordioTransport.cpp b/src/utility/HCICordioTransport.cpp deleted file mode 100644 index f2a83d97..00000000 --- a/src/utility/HCICordioTransport.cpp +++ /dev/null @@ -1,271 +0,0 @@ -/* - This file is part of the ArduinoBLE library. - Copyright (c) 2019 Arduino SA. All rights reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#ifdef ARDUINO_ARCH_MBED - -#include <driver/CordioHCITransportDriver.h> -#include <driver/CordioHCIDriver.h> - -#include <mbed_config.h> - -// Parts of this file are based on: https://github.com/ARMmbed/mbed-os-cordio-hci-passthrough/pull/2 -// With permission from the Arm Mbed team to re-license - -#if CORDIO_ZERO_COPY_HCI -#include <wsf_types.h> -#include <wsf_buf.h> -#include <wsf_msg.h> -#include <wsf_os.h> -#include <wsf_buf.h> -#include <wsf_timer.h> - -/* avoid many small allocs (and WSF doesn't have smaller buffers) */ -#define MIN_WSF_ALLOC (16) -#endif //CORDIO_ZERO_COPY_HCI - -#include "HCICordioTransport.h" - -extern ble::vendor::cordio::CordioHCIDriver& ble_cordio_get_hci_driver(); - -namespace ble { - namespace vendor { - namespace cordio { - struct CordioHCIHook { - static CordioHCIDriver& getDriver() { - return ble_cordio_get_hci_driver(); - } - - static CordioHCITransportDriver& getTransportDriver() { - return getDriver()._transport_driver; - } - - static void setDataReceivedHandler(void (*handler)(uint8_t*, uint8_t)) { - getTransportDriver().set_data_received_handler(handler); - } - }; - } - } -} - -using ble::vendor::cordio::CordioHCIHook; - -#if CORDIO_ZERO_COPY_HCI -extern uint8_t *SystemHeapStart; -extern uint32_t SystemHeapSize; - -void init_wsf(ble::vendor::cordio::buf_pool_desc_t& buf_pool_desc) { - static bool init = false; - - if (init) { - return; - } - init = true; - - // use the buffer for the WSF heap - SystemHeapStart = buf_pool_desc.buffer_memory; - SystemHeapSize = buf_pool_desc.buffer_size; - - // Initialize buffers with the ones provided by the HCI driver - uint16_t bytes_used = WsfBufInit( - buf_pool_desc.pool_count, - (wsfBufPoolDesc_t*)buf_pool_desc.pool_description - ); - - // Raise assert if not enough memory was allocated - MBED_ASSERT(bytes_used != 0); - - SystemHeapStart += bytes_used; - SystemHeapSize -= bytes_used; - - WsfTimerInit(); -} - - -extern "C" void wsf_mbed_ble_signal_event(void) -{ - // do nothing -} -#endif //CORDIO_ZERO_COPY_HCI - -static void bleLoop() -{ -#if CORDIO_ZERO_COPY_HCI - uint64_t last_update_us = 0; - mbed::LowPowerTimer timer; - - timer.start(); - - while (true) { - last_update_us += (uint64_t) timer.read_high_resolution_us(); - timer.reset(); - - uint64_t last_update_ms = (last_update_us / 1000); - wsfTimerTicks_t wsf_ticks = (last_update_ms / WSF_MS_PER_TICK); - - if (wsf_ticks > 0) { - WsfTimerUpdate(wsf_ticks); - last_update_us -= (last_update_ms * 1000); - } - - wsfOsDispatcher(); - - bool sleep = false; - { - /* call needs interrupts disabled */ - mbed::CriticalSectionLock critical_section; - if (wsfOsReadyToSleep()) { - sleep = true; - } - } - - uint64_t time_spent = (uint64_t) timer.read_high_resolution_us(); - - /* don't bother sleeping if we're already past tick */ - if (sleep && (WSF_MS_PER_TICK * 1000 > time_spent)) { - /* sleep to maintain constant tick rate */ - uint64_t wait_time_us = WSF_MS_PER_TICK * 1000 - time_spent; - uint64_t wait_time_ms = wait_time_us / 1000; - - wait_time_us = wait_time_us % 1000; - - if (wait_time_ms) { - rtos::ThisThread::sleep_for(wait_time_ms); - } - - if (wait_time_us) { - wait_us(wait_time_us); - } - } - } -#else - while(true) { - rtos::Thread::wait(osWaitForever); - } -#endif // CORDIO_ZERO_COPY_HCI -} - -static rtos::EventFlags bleEventFlags; -static rtos::Thread bleLoopThread; - - -HCICordioTransportClass::HCICordioTransportClass() : - _begun(false) -{ -} - -HCICordioTransportClass::~HCICordioTransportClass() -{ -} - -int HCICordioTransportClass::begin() -{ - _rxBuf.clear(); - -#if CORDIO_ZERO_COPY_HCI - ble::vendor::cordio::buf_pool_desc_t bufPoolDesc = CordioHCIHook::getDriver().get_buffer_pool_description(); - init_wsf(bufPoolDesc); -#endif - - CordioHCIHook::getDriver().initialize(); - bleLoopThread.start(bleLoop); - - CordioHCIHook::setDataReceivedHandler(HCICordioTransportClass::onDataReceived); - - _begun = true; - - return 1; -} - -void HCICordioTransportClass::end() -{ - bleLoopThread.terminate(); - - CordioHCIHook::getDriver().terminate(); - - _begun = false; -} - -void HCICordioTransportClass::wait(unsigned long timeout) -{ - if (available()) { - return; - } - - // wait for handleRxData to signal - bleEventFlags.wait_all(0x01, timeout, true); -} - -int HCICordioTransportClass::available() -{ - return _rxBuf.available(); -} - -int HCICordioTransportClass::peek() -{ - return _rxBuf.peek(); -} - -int HCICordioTransportClass::read() -{ - return _rxBuf.read_char(); -} - -size_t HCICordioTransportClass::write(const uint8_t* data, size_t length) -{ - if (!_begun) { - return 0; - } - - uint8_t packetLength = length - 1; - uint8_t packetType = data[0]; - -#if CORDIO_ZERO_COPY_HCI - uint8_t* packet = (uint8_t*)WsfMsgAlloc(max(packetLength, MIN_WSF_ALLOC)); - - memcpy(packet, &data[1], packetLength); - - return CordioHCIHook::getTransportDriver().write(packetType, packetLength, packet); -#else - return CordioHCIHook::.getTransportDriver().write(packetType, packetLength, &data[1]); -#endif -} - -void HCICordioTransportClass::handleRxData(uint8_t* data, uint8_t len) -{ - if (_rxBuf.availableForStore() < len) { - // drop! - return; - } - - for (int i = 0; i < len; i++) { - _rxBuf.store_char(data[i]); - } - - bleEventFlags.set(0x01); -} - -HCICordioTransportClass HCICordioTransport; -HCITransportInterface& HCITransport = HCICordioTransport; - -void HCICordioTransportClass::onDataReceived(uint8_t* data, uint8_t len) -{ - HCICordioTransport.handleRxData(data, len); -} - -#endif diff --git a/src/utility/HCICordioTransport.h b/src/utility/HCICordioTransport.h deleted file mode 100644 index b8d0596a..00000000 --- a/src/utility/HCICordioTransport.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - This file is part of the ArduinoBLE library. - Copyright (c) 2019 Arduino SA. All rights reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#ifndef _HCI_CORDIO_TRANSPORT_H_ -#define _HCI_CORDIO_TRANSPORT_H_ - -#include <string.h> - -#include "api/RingBuffer.h" - -#include "HCITransport.h" - -class HCICordioTransportClass : public HCITransportInterface { -public: - HCICordioTransportClass(); - virtual ~HCICordioTransportClass(); - - virtual int begin(); - virtual void end(); - - virtual void wait(unsigned long timeout); - - virtual int available(); - virtual int peek(); - virtual int read(); - - virtual size_t write(const uint8_t* data, size_t length); - -private: - static void onDataReceived(uint8_t* data, uint8_t len); - void handleRxData(uint8_t* data, uint8_t len); - -private: - bool _begun; - RingBufferN<256> _rxBuf; -}; - -#endif diff --git a/src/utility/HCISpiTransport.cpp b/src/utility/HCISpiTransport.cpp index ab9eeaea..08e3f12b 100644 --- a/src/utility/HCISpiTransport.cpp +++ b/src/utility/HCISpiTransport.cpp @@ -17,21 +17,13 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifdef ARDUINO_ARCH_STM32 - #include "HCISpiTransport.h" -#if defined(ARDUINO_STEVAL_MKSBOX1V1) -SPIClass SpiHCI(PC3, PD3, PD1); /* STEVAL_MKSBOX1V1 */ -#elif defined(ARDUINO_DISCO_L475VG_IOT) -SPIClass SpiHCI(PC12, PC11, PC10); /* B-L475E-IOT01A1 */ -#else -SPIClass SpiHCI(D11, D12, D3); /* Shield IDB05A1 */ -#endif /* ARDUINO_STEVAL_MKSBOX1V1 */ volatile int data_avail = 0; -HCISpiTransportClass::HCISpiTransportClass(SPIClass& spi, uint8_t cs_pin, uint8_t spi_irq, uint8_t ble_rst, unsigned long frequency, int spi_mode) : +HCISpiTransportClass::HCISpiTransportClass(SPIClass& spi, BLEChip_t ble_chip, uint8_t cs_pin, uint8_t spi_irq, uint8_t ble_rst, unsigned long frequency, int spi_mode) : _spi(&spi), + _ble_chip(ble_chip), _cs_pin(cs_pin), _spi_irq(spi_irq), _ble_rst(ble_rst), @@ -75,15 +67,18 @@ int HCISpiTransportClass::begin() digitalWrite(_ble_rst, HIGH); delay(5); -#if defined(SPBTLE_RF) - // Wait for Blue Initialize - wait_for_blue_initialize(); -#endif /* SPBTLE_RF */ + if (_ble_chip == SPBTLE_RF) + { + // Wait for Blue Initialize + wait_for_blue_initialize(); + } else if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP) + { + // Wait a while for the reset of the BLE module + delay(300); + } else + { -#if defined(SPBTLE_1S) - // Wait a while for the reset of the BLE module - delay(300); -#endif /* SPBTLE_1S */ + } return 1; } @@ -125,6 +120,11 @@ int HCISpiTransportClass::available() { uint8_t header_master[5] = {0x0b, 0x00, 0x00, 0x00, 0x00}; + if(_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP) + { + detachInterrupt(_spi_irq); + } + _spi->beginTransaction(SPISettings(_frequency, MSBFIRST, _spi_mode)); digitalWrite(_cs_pin, LOW); @@ -132,11 +132,65 @@ int HCISpiTransportClass::available() /* Write the header */ _spi->transfer(header_master, 5); -#if defined(SPBTLE_RF) - /* device is ready */ - if(header_master[0] == 0x02) + if (_ble_chip == SPBTLE_RF) + { + /* device is ready */ + if(header_master[0] == 0x02) + { + uint16_t byte_count = (header_master[4] << 8) | header_master[3]; + + if(byte_count > 0) + { + if(_initial_phase) + { + /* avoid to read more data that available size of the buffer */ + if(byte_count > (BLE_MODULE_SPI_BUFFER_SIZE - _write_index_initial)) + { + byte_count = (BLE_MODULE_SPI_BUFFER_SIZE - _write_index_initial); + } + + /* Read the response */ + for(int j=0; j < byte_count; j++) + { + _rxbuff[_write_index_initial] = _spi->transfer(0xFF); + _write_index_initial++; + } + + /* Check if the message is a Blue Initialize */ + /* If so we need to send the command to enable LL_ONLY */ + if(byte_count == 6) + { + if(_rxbuff[_write_index_initial - 6] == 0x04 && + _rxbuff[_write_index_initial - 5] == 0xFF && + _rxbuff[_write_index_initial - 4] == 0x03 && + _rxbuff[_write_index_initial - 3] == 0x01 && + _rxbuff[_write_index_initial - 2] == 0x00 && + _rxbuff[_write_index_initial - 1] == 0x01) + { + ble_reset = 1; + } + } + } else + { + /* avoid to read more data that available size of the buffer */ + if(byte_count > (BLE_MODULE_SPI_BUFFER_SIZE - _write_index)) + { + byte_count = (BLE_MODULE_SPI_BUFFER_SIZE - _write_index); + /* SPI buffer is full but we still have data to store, so we set the data_avail flag to true */ + data_avail = 1; + } + + /* Read the response */ + for(int j=0; j < byte_count; j++) + { + _rxbuff[_write_index] = _spi->transfer(0xFF); + _write_index++; + } + } + } + } + } else if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP) { -#endif /* SPBTLE_RF */ uint16_t byte_count = (header_master[4] << 8) | header_master[3]; if(byte_count > 0) @@ -156,23 +210,6 @@ int HCISpiTransportClass::available() _write_index_initial++; } -#if defined(SPBTLE_RF) - /* Check if the message is a Blue Initialize */ - /* If so we need to send the command to enable LL_ONLY */ - if(byte_count == 6) - { - if(_rxbuff[_write_index_initial - 6] == 0x04 && - _rxbuff[_write_index_initial - 5] == 0xFF && - _rxbuff[_write_index_initial - 4] == 0x03 && - _rxbuff[_write_index_initial - 3] == 0x01 && - _rxbuff[_write_index_initial - 2] == 0x00 && - _rxbuff[_write_index_initial - 1] == 0x01) - { - ble_reset = 1; - } - } -#endif /* SPBTLE_RF */ -#if defined(SPBTLE_1S) /* Check if the message is a CMD_COMPLETE */ /* We suppose that the first CMD is always a HCI_RESET */ if(byte_count == 7) @@ -188,7 +225,6 @@ int HCISpiTransportClass::available() ble_reset = 1; } } -#endif /* SPBTLE_1S */ } else { /* avoid to read more data that available size of the buffer */ @@ -207,26 +243,36 @@ int HCISpiTransportClass::available() } } } -#if defined(SPBTLE_RF) + } else + { + } -#endif /* SPBTLE_RF */ digitalWrite(_cs_pin, HIGH); _spi->endTransaction(); + + if(_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP) + { + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + } } if(ble_reset) { -#if defined(SPBTLE_RF) - /* BLE chip was reset: we need to enable LL_ONLY */ - enable_ll_only(); - wait_for_enable_ll_only(); -#endif /* SPBTLE_RF */ -#if defined(SPBTLE_1S) - /* BLE chip was reset: we need to wait for a while */ - delay(300); -#endif /* SPBTLE_1S */ + if (_ble_chip == SPBTLE_RF) + { + /* BLE chip was reset: we need to enable LL_ONLY */ + enable_ll_only(); + wait_for_enable_ll_only(); + } else if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP) + { + /* BLE chip was reset: we need to wait for a while */ + delay(300); + } else + { + + } /* Now we can update the write index and close the initial phase */ _write_index = _write_index_initial; @@ -287,49 +333,78 @@ size_t HCISpiTransportClass::write(const uint8_t* data, size_t length) do { -#if defined(SPBTLE_1S) - uint32_t tickstart_data_available = millis(); -#endif /* SPBTLE_1S */ - result = 0; + if (_ble_chip == SPBTLE_RF) + { + result = 0; - _spi->beginTransaction(SPISettings(_frequency, MSBFIRST, _spi_mode)); + _spi->beginTransaction(SPISettings(_frequency, MSBFIRST, _spi_mode)); - digitalWrite(_cs_pin, LOW); + digitalWrite(_cs_pin, LOW); -#if defined(SPBTLE_1S) - /* - * Wait until BlueNRG-1 is ready. - * When ready it will raise the IRQ pin. - */ - while(!(digitalRead(_spi_irq) == 1)) - { - if((millis() - tickstart_data_available) > 1000) + /* Write the header */ + _spi->transfer(header_master, 5); + + /* device is ready */ + if(header_master[0] == 0x02) { - result = -3; - break; + if(header_master[1] >= length) + { + /* Write the data */ + _spi->transfer(my_data, length); + } else + { + result = -2; + } + } else + { + result = -1; } - } - if(result == -3) - { digitalWrite(_cs_pin, HIGH); - _spi->endTransaction(); - break; - } -#endif /* SPBTLE_1S */ - /* Write the header */ - _spi->transfer(header_master, 5); + _spi->endTransaction(); -#if defined(SPBTLE_RF) - /* device is ready */ - if(header_master[0] == 0x02) + if((millis() - tickstart) > 1000) + { + result = -3; + break; + } + } else if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP) { - if(header_master[1] >= length) -#endif /* SPBTLE_RF */ -#if defined(SPBTLE_1S) + uint32_t tickstart_data_available = millis(); + result = 0; + + detachInterrupt(_spi_irq); + + _spi->beginTransaction(SPISettings(_frequency, MSBFIRST, _spi_mode)); + + digitalWrite(_cs_pin, LOW); + + /* + * Wait until BlueNRG-1 is ready. + * When ready it will raise the IRQ pin. + */ + while(!(digitalRead(_spi_irq) == 1)) + { + if((millis() - tickstart_data_available) > 1000) + { + result = -3; + break; + } + } + + if(result == -3) + { + digitalWrite(_cs_pin, HIGH); + _spi->endTransaction(); + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + break; + } + + /* Write the header */ + _spi->transfer(header_master, 5); + if((int)((((uint16_t)header_master[2])<<8) | ((uint16_t)header_master[1])) >= (int)length) -#endif /* SPBTLE_1S */ { /* Write the data */ _spi->transfer(my_data, length); @@ -337,21 +412,21 @@ size_t HCISpiTransportClass::write(const uint8_t* data, size_t length) { result = -2; } -#if defined(SPBTLE_RF) - } else - { - result = -1; - } -#endif /* SPBTLE_RF */ - digitalWrite(_cs_pin, HIGH); + digitalWrite(_cs_pin, HIGH); - _spi->endTransaction(); + _spi->endTransaction(); + + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); - if((millis() - tickstart) > 1000) + if((millis() - tickstart) > 1000) + { + result = -3; + break; + } + } else { - result = -3; - break; + } } while(result < 0); @@ -364,7 +439,6 @@ size_t HCISpiTransportClass::write(const uint8_t* data, size_t length) } } -#if defined(SPBTLE_RF) void HCISpiTransportClass::wait_for_blue_initialize() { int event_blue_initialize = 0; @@ -535,15 +609,3 @@ void HCISpiTransportClass::enable_ll_only() _spi->endTransaction(); } while (result < 0); } -#endif /* SPBTLE_RF */ - -#if defined(ARDUINO_STEVAL_MKSBOX1V1) -HCISpiTransportClass HCISpiTransport(SpiHCI, PD0, PD4, PA8, 1000000, SPI_MODE1); /* STEVAL_MKSBOX1V1 */ -#elif defined(ARDUINO_DISCO_L475VG_IOT) -HCISpiTransportClass HCISpiTransport(SpiHCI, PD13, PE6, PA8, 8000000, SPI_MODE0); /* B-L475E-IOT01A1 */ -#else -HCISpiTransportClass HCISpiTransport(SpiHCI, A1, A0, D7, 8000000, SPI_MODE0); /* Shield IDB05A1 */ -#endif /* ARDUINO_STEVAL_MKSBOX1V1 */ -HCITransportInterface& HCITransport = HCISpiTransport; - -#endif /* ARDUINO_ARCH_STM32 */ diff --git a/src/utility/HCISpiTransport.h b/src/utility/HCISpiTransport.h index 70f03684..0318ebd5 100644 --- a/src/utility/HCISpiTransport.h +++ b/src/utility/HCISpiTransport.h @@ -23,19 +23,17 @@ #include "HCITransport.h" #include "SPI.h" -#if defined(ARDUINO_STEVAL_MKSBOX1V1) -#define SPBTLE_1S /* STEVAL_MKSBOX1V1 */ -#elif defined(ARDUINO_DISCO_L475VG_IOT) -#define SPBTLE_RF /* B-L475E-IOT01A1 */ -#else -#define SPBTLE_RF /* Shield IDB05A1 */ -#endif /* ARDUINO_STEVAL_MKSBOX1V1 */ +typedef enum BLEChip_s { + SPBTLE_RF, + SPBTLE_1S, + BLUENRG_M2SP +} BLEChip_t; #define BLE_MODULE_SPI_BUFFER_SIZE 128 class HCISpiTransportClass : public HCITransportInterface { public: - HCISpiTransportClass(SPIClass& spi, uint8_t cs_pin, uint8_t spi_irq, uint8_t ble_rst, unsigned long frequency, int spi_mode); + HCISpiTransportClass(SPIClass& spi, BLEChip_t ble_chip, uint8_t cs_pin, uint8_t spi_irq, uint8_t ble_rst, unsigned long frequency, int spi_mode); virtual ~HCISpiTransportClass(); virtual int begin(); @@ -50,12 +48,11 @@ class HCISpiTransportClass : public HCITransportInterface { virtual size_t write(const uint8_t* data, size_t length); private: -#if defined(SPBTLE_RF) void wait_for_blue_initialize(); void wait_for_enable_ll_only(); void enable_ll_only(); -#endif /* SPBTLE_RF */ SPIClass* _spi; + BLEChip_t _ble_chip; uint8_t _cs_pin; uint8_t _spi_irq; uint8_t _ble_rst; diff --git a/src/utility/HCIUartTransport.cpp b/src/utility/HCIUartTransport.cpp deleted file mode 100644 index 48578766..00000000 --- a/src/utility/HCIUartTransport.cpp +++ /dev/null @@ -1,103 +0,0 @@ -/* - This file is part of the ArduinoBLE library. - Copyright (c) 2018 Arduino SA. All rights reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#ifndef ARDUINO_ARCH_STM32 - -#ifndef ARDUINO_ARCH_MBED - -#include "HCIUartTransport.h" - -#if defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_AVR_UNO_WIFI_REV2) -#define SerialHCI Serial2 -#elif defined(ARDUINO_SAMD_NANO_33_IOT) -// SerialHCI is already defined in the variant -#else -#error "Unsupported board selected!" -#endif - -HCIUartTransportClass::HCIUartTransportClass(HardwareSerial& uart, unsigned long baudrate) : - _uart(&uart), - _baudrate(baudrate) -{ -} - -HCIUartTransportClass::~HCIUartTransportClass() -{ -} - -int HCIUartTransportClass::begin() -{ - _uart->begin(_baudrate); - - return 1; -} - -void HCIUartTransportClass::end() -{ - _uart->end(); -} - -void HCIUartTransportClass::wait(unsigned long timeout) -{ - for (unsigned long start = millis(); (millis() - start) < timeout;) { - if (available()) { - break; - } - } -} - -int HCIUartTransportClass::available() -{ - return _uart->available(); -} - -int HCIUartTransportClass::peek() -{ - return _uart->peek(); -} - -int HCIUartTransportClass::read() -{ - return _uart->read(); -} - -size_t HCIUartTransportClass::write(const uint8_t* data, size_t length) -{ -#ifdef ARDUINO_AVR_UNO_WIFI_REV2 - // wait while the CTS pin is low - while (digitalRead(NINA_CTS) == HIGH); -#endif - - size_t result = _uart->write(data, length); - - _uart->flush(); - - return result; -} - -#ifdef ARDUINO_AVR_UNO_WIFI_REV2 -HCIUartTransportClass HCIUartTransport(SerialHCI, 119600); -#else -HCIUartTransportClass HCIUartTransport(SerialHCI, 912600); -#endif -HCITransportInterface& HCITransport = HCIUartTransport; - -#endif - -#endif /* ARDUINO_ARCH_STM32 */ diff --git a/src/utility/HCIUartTransport.h b/src/utility/HCIUartTransport.h deleted file mode 100644 index ba70dff4..00000000 --- a/src/utility/HCIUartTransport.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - This file is part of the ArduinoBLE library. - Copyright (c) 2018 Arduino SA. All rights reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#ifndef _HCI_UART_TRANSPORT_H_ -#define _HCI_UART_TRANSPORT_H_ - -#include "HCITransport.h" - -class HCIUartTransportClass : public HCITransportInterface { -public: - HCIUartTransportClass(HardwareSerial& uart, unsigned long baudrate); - virtual ~HCIUartTransportClass(); - - virtual int begin(); - virtual void end(); - - virtual void wait(unsigned long timeout); - - virtual int available(); - virtual int peek(); - virtual int read(); - - virtual size_t write(const uint8_t* data, size_t length); - -private: - HardwareSerial* _uart; - unsigned long _baudrate; -}; - -#endif From 02ff3a64f54b21ce815460964c8ec508e6f15ac4 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Mon, 17 Feb 2020 09:00:30 +0100 Subject: [PATCH 007/226] SPISettings managements Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- src/utility/HCISpiTransport.cpp | 19 +++++++++---------- src/utility/HCISpiTransport.h | 8 +++++--- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/utility/HCISpiTransport.cpp b/src/utility/HCISpiTransport.cpp index 08e3f12b..6f86f86b 100644 --- a/src/utility/HCISpiTransport.cpp +++ b/src/utility/HCISpiTransport.cpp @@ -21,15 +21,14 @@ volatile int data_avail = 0; -HCISpiTransportClass::HCISpiTransportClass(SPIClass& spi, BLEChip_t ble_chip, uint8_t cs_pin, uint8_t spi_irq, uint8_t ble_rst, unsigned long frequency, int spi_mode) : +HCISpiTransportClass::HCISpiTransportClass(SPIClass& spi, BLEChip_t ble_chip, uint8_t cs_pin, uint8_t spi_irq, uint8_t ble_rst, uint32_t frequency, uint8_t spi_mode) : _spi(&spi), _ble_chip(ble_chip), _cs_pin(cs_pin), _spi_irq(spi_irq), - _ble_rst(ble_rst), - _frequency(frequency), - _spi_mode(spi_mode) + _ble_rst(ble_rst) { + _spiSettings = SPISettings(frequency, (BitOrder)BLE_SPI_BYTE_ORDER, spi_mode); _read_index = 0; _write_index = 0; _write_index_initial = 0; @@ -125,7 +124,7 @@ int HCISpiTransportClass::available() detachInterrupt(_spi_irq); } - _spi->beginTransaction(SPISettings(_frequency, MSBFIRST, _spi_mode)); + _spi->beginTransaction(_spiSettings); digitalWrite(_cs_pin, LOW); @@ -337,7 +336,7 @@ size_t HCISpiTransportClass::write(const uint8_t* data, size_t length) { result = 0; - _spi->beginTransaction(SPISettings(_frequency, MSBFIRST, _spi_mode)); + _spi->beginTransaction(_spiSettings); digitalWrite(_cs_pin, LOW); @@ -376,7 +375,7 @@ size_t HCISpiTransportClass::write(const uint8_t* data, size_t length) detachInterrupt(_spi_irq); - _spi->beginTransaction(SPISettings(_frequency, MSBFIRST, _spi_mode)); + _spi->beginTransaction(_spiSettings); digitalWrite(_cs_pin, LOW); @@ -458,7 +457,7 @@ void HCISpiTransportClass::wait_for_blue_initialize() { uint8_t header_master[5] = {0x0b, 0x00, 0x00, 0x00, 0x00}; - _spi->beginTransaction(SPISettings(_frequency, MSBFIRST, _spi_mode)); + _spi->beginTransaction(_spiSettings); digitalWrite(_cs_pin, LOW); @@ -526,7 +525,7 @@ void HCISpiTransportClass::wait_for_enable_ll_only() { uint8_t header_master[5] = {0x0b, 0x00, 0x00, 0x00, 0x00}; - _spi->beginTransaction(SPISettings(_frequency, MSBFIRST, _spi_mode)); + _spi->beginTransaction(_spiSettings); digitalWrite(_cs_pin, LOW); @@ -580,7 +579,7 @@ void HCISpiTransportClass::enable_ll_only() { result = 0; - _spi->beginTransaction(SPISettings(_frequency, MSBFIRST, _spi_mode)); + _spi->beginTransaction(_spiSettings); digitalWrite(_cs_pin, LOW); diff --git a/src/utility/HCISpiTransport.h b/src/utility/HCISpiTransport.h index 0318ebd5..aeb509d1 100644 --- a/src/utility/HCISpiTransport.h +++ b/src/utility/HCISpiTransport.h @@ -29,11 +29,14 @@ typedef enum BLEChip_s { BLUENRG_M2SP } BLEChip_t; +#ifndef BLE_SPI_BYTE_ORDER +#define BLE_SPI_BYTE_ORDER MSBFIRST +#endif #define BLE_MODULE_SPI_BUFFER_SIZE 128 class HCISpiTransportClass : public HCITransportInterface { public: - HCISpiTransportClass(SPIClass& spi, BLEChip_t ble_chip, uint8_t cs_pin, uint8_t spi_irq, uint8_t ble_rst, unsigned long frequency, int spi_mode); + HCISpiTransportClass(SPIClass& spi, BLEChip_t ble_chip, uint8_t cs_pin, uint8_t spi_irq, uint8_t ble_rst, uint32_t frequency, uint8_t spi_mode); virtual ~HCISpiTransportClass(); virtual int begin(); @@ -52,12 +55,11 @@ class HCISpiTransportClass : public HCITransportInterface { void wait_for_enable_ll_only(); void enable_ll_only(); SPIClass* _spi; + SPISettings _spiSettings; BLEChip_t _ble_chip; uint8_t _cs_pin; uint8_t _spi_irq; uint8_t _ble_rst; - unsigned long _frequency; - int _spi_mode; uint8_t _rxbuff[BLE_MODULE_SPI_BUFFER_SIZE]; uint16_t _read_index; uint16_t _write_index; From 2f22ce95979cc609a23dcfac3bd67650cef763e9 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Tue, 19 Nov 2019 12:07:36 +0100 Subject: [PATCH 008/226] Replace boolean with standard bool https://github.com/arduino/Arduino/issues/4673 Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- examples/Peripheral/ButtonLED/ButtonLED.ino | 2 +- src/BLETypedCharacteristics.h | 2 +- src/utility/ATT.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/Peripheral/ButtonLED/ButtonLED.ino b/examples/Peripheral/ButtonLED/ButtonLED.ino index 9b0dfb0b..ea14b7c8 100644 --- a/examples/Peripheral/ButtonLED/ButtonLED.ino +++ b/examples/Peripheral/ButtonLED/ButtonLED.ino @@ -104,7 +104,7 @@ void loop() { char buttonValue = digitalRead(buttonPin); // has the value changed since the last read - boolean buttonChanged = (buttonCharacteristic.value() != buttonValue); + bool buttonChanged = (buttonCharacteristic.value() != buttonValue); if (buttonChanged) { // button state changed, update characteristics diff --git a/src/BLETypedCharacteristics.h b/src/BLETypedCharacteristics.h index 465fc046..8bd98c78 100644 --- a/src/BLETypedCharacteristics.h +++ b/src/BLETypedCharacteristics.h @@ -27,7 +27,7 @@ class BLEBoolCharacteristic : public BLETypedCharacteristic<bool> { BLEBoolCharacteristic(const char* uuid, unsigned char properties); }; -class BLEBooleanCharacteristic : public BLETypedCharacteristic<boolean> { +class BLEBooleanCharacteristic : public BLETypedCharacteristic<bool> { public: BLEBooleanCharacteristic(const char* uuid, unsigned char properties); }; diff --git a/src/utility/ATT.cpp b/src/utility/ATT.cpp index 2696960e..6605a8a3 100644 --- a/src/utility/ATT.cpp +++ b/src/utility/ATT.cpp @@ -1142,7 +1142,7 @@ void ATTClass::readByTypeResp(uint16_t connectionHandle, uint8_t dlen, uint8_t d void ATTClass::writeReqOrCmd(uint16_t connectionHandle, uint16_t mtu, uint8_t op, uint8_t dlen, uint8_t data[]) { - boolean withResponse = (op == ATT_OP_WRITE_REQ); + bool withResponse = (op == ATT_OP_WRITE_REQ); if (dlen < sizeof(uint16_t)) { if (withResponse) { From 7e7cf887cf24410e50ce25d55bb2a3c312687ea1 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Mon, 17 Feb 2020 10:08:13 +0100 Subject: [PATCH 009/226] Fix workflow to build ST targets Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- .github/workflows/compile-examples.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index 884f11d6..baeeeec6 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -7,10 +7,9 @@ jobs: strategy: matrix: fqbn: [ - "arduino:samd:mkrwifi1010", - "arduino:samd:nano_33_iot", - "arduino:megaavr:uno2018:mode=on", - "arduino:mbed:nano33ble" + '"STM32:stm32:Eval:pnum=STEVAL_MKSBOX1V1,usb=CDCgen" "https://github.com/stm32duino/BoardManagerFiles/raw/master/STM32/package_stm_index.json"', + '"STM32:stm32:Nucleo_64:pnum=NUCLEO_L476RG" "https://github.com/stm32duino/BoardManagerFiles/raw/master/STM32/package_stm_index.json"', + '"STM32:stm32:Disco:pnum=DISCO_L475VG_IOT" "https://github.com/stm32duino/BoardManagerFiles/raw/master/STM32/package_stm_index.json"' ] steps: From ab1df57890c5e6d94e989c1efc17244c9782f3de Mon Sep 17 00:00:00 2001 From: Carlo Parata <carlo.parata@st.com> Date: Mon, 17 Feb 2020 10:38:38 +0100 Subject: [PATCH 010/226] Update examples/Central/PeripheralExplorer/PeripheralExplorer.ino Co-Authored-By: Frederic Pillon <frederic.pillon@st.com> --- examples/Central/PeripheralExplorer/PeripheralExplorer.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/Central/PeripheralExplorer/PeripheralExplorer.ino b/examples/Central/PeripheralExplorer/PeripheralExplorer.ino index 357a8ef4..b32185cd 100644 --- a/examples/Central/PeripheralExplorer/PeripheralExplorer.ino +++ b/examples/Central/PeripheralExplorer/PeripheralExplorer.ino @@ -31,7 +31,7 @@ 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); +/*#define SpiHCI SPI HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI_MODE0); BLELocalDevice BLE(&HCISpiTransport); */ /* Shield BNRG2A1 with SPI clock on D3 */ From 19ce6152cd33e9201f9704a6fdfcf6e3cc1ed9ed Mon Sep 17 00:00:00 2001 From: Carlo Parata <carlo.parata@st.com> Date: Mon, 17 Feb 2020 10:38:49 +0100 Subject: [PATCH 011/226] Update examples/Central/PeripheralExplorer/PeripheralExplorer.ino Co-Authored-By: Frederic Pillon <frederic.pillon@st.com> --- examples/Central/PeripheralExplorer/PeripheralExplorer.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/Central/PeripheralExplorer/PeripheralExplorer.ino b/examples/Central/PeripheralExplorer/PeripheralExplorer.ino index b32185cd..82e1cc60 100644 --- a/examples/Central/PeripheralExplorer/PeripheralExplorer.ino +++ b/examples/Central/PeripheralExplorer/PeripheralExplorer.ino @@ -39,7 +39,7 @@ BLELocalDevice BLE(&HCISpiTransport); */ HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1); BLELocalDevice BLE(&HCISpiTransport); */ /* Shield BNRG2A1 with SPI clock on D13 */ -/*SPIClass SpiHCI(D11, D12, D13); +/*#define SpiHCI SPI HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1); BLELocalDevice BLE(&HCISpiTransport); */ #endif From 81ff00b5579f7bb3583fd4de23afb3a1d59c1eef Mon Sep 17 00:00:00 2001 From: Carlo Parata <carlo.parata@st.com> Date: Mon, 17 Feb 2020 10:38:57 +0100 Subject: [PATCH 012/226] Update examples/Central/LedControl/LedControl.ino Co-Authored-By: Frederic Pillon <frederic.pillon@st.com> --- examples/Central/LedControl/LedControl.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/Central/LedControl/LedControl.ino b/examples/Central/LedControl/LedControl.ino index af082e00..5770c7cf 100644 --- a/examples/Central/LedControl/LedControl.ino +++ b/examples/Central/LedControl/LedControl.ino @@ -35,7 +35,7 @@ HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI BLELocalDevice BLE(&HCISpiTransport); const int buttonPin = PC13; // set buttonPin to digital pin PC13 /* Shield IDB05A1 with SPI clock on D13 */ -/*SPIClass SpiHCI(D11, D12, D13); +/*#define SpiHCI SPI HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI_MODE0); BLELocalDevice BLE(&HCISpiTransport); const int buttonPin = PC13; // set buttonPin to digital pin PC13 */ From 9f4679794b399a99b9cfd2077cd342ab774d80f5 Mon Sep 17 00:00:00 2001 From: Carlo Parata <carlo.parata@st.com> Date: Mon, 17 Feb 2020 10:39:06 +0100 Subject: [PATCH 013/226] Update examples/Central/LedControl/LedControl.ino Co-Authored-By: Frederic Pillon <frederic.pillon@st.com> --- examples/Central/LedControl/LedControl.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/Central/LedControl/LedControl.ino b/examples/Central/LedControl/LedControl.ino index 5770c7cf..a3115f53 100644 --- a/examples/Central/LedControl/LedControl.ino +++ b/examples/Central/LedControl/LedControl.ino @@ -45,7 +45,7 @@ HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, BLELocalDevice BLE(&HCISpiTransport); const int buttonPin = PC13; // set buttonPin to digital pin PC13 */ /* Shield BNRG2A1 with SPI clock on D13 */ -/*SPIClass SpiHCI(D11, D12, D13); +/*#define SpiHCI SPI HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1); BLELocalDevice BLE(&HCISpiTransport); const int buttonPin = PC13; // set buttonPin to digital pin PC13 */ From 775a60aaaec40cf98bcaf354e4baaa965123a361 Mon Sep 17 00:00:00 2001 From: Carlo Parata <carlo.parata@st.com> Date: Mon, 17 Feb 2020 10:39:13 +0100 Subject: [PATCH 014/226] Update examples/Central/Scan/Scan.ino Co-Authored-By: Frederic Pillon <frederic.pillon@st.com> --- examples/Central/Scan/Scan.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/Central/Scan/Scan.ino b/examples/Central/Scan/Scan.ino index 5326514f..650798ac 100644 --- a/examples/Central/Scan/Scan.ino +++ b/examples/Central/Scan/Scan.ino @@ -28,7 +28,7 @@ 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); +/*#define SpiHCI SPI HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI_MODE0); BLELocalDevice BLE(&HCISpiTransport); */ /* Shield BNRG2A1 with SPI clock on D3 */ From f7d45fad296b21b29e087affbf47592b4ccb41e4 Mon Sep 17 00:00:00 2001 From: Carlo Parata <carlo.parata@st.com> Date: Mon, 17 Feb 2020 10:39:25 +0100 Subject: [PATCH 015/226] Update examples/Central/Scan/Scan.ino Co-Authored-By: Frederic Pillon <frederic.pillon@st.com> --- examples/Central/Scan/Scan.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/Central/Scan/Scan.ino b/examples/Central/Scan/Scan.ino index 650798ac..74ce1a71 100644 --- a/examples/Central/Scan/Scan.ino +++ b/examples/Central/Scan/Scan.ino @@ -36,7 +36,7 @@ BLELocalDevice BLE(&HCISpiTransport); */ HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1); BLELocalDevice BLE(&HCISpiTransport); */ /* Shield BNRG2A1 with SPI clock on D13 */ -/*SPIClass SpiHCI(D11, D12, D13); +/*#define SpiHCI SPI HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1); BLELocalDevice BLE(&HCISpiTransport); */ #endif From c9f4239e46a53a7b9e40705b2065ef1d14bef8d6 Mon Sep 17 00:00:00 2001 From: Carlo Parata <carlo.parata@st.com> Date: Mon, 17 Feb 2020 10:39:37 +0100 Subject: [PATCH 016/226] Update examples/Central/ScanCallback/ScanCallback.ino Co-Authored-By: Frederic Pillon <frederic.pillon@st.com> --- examples/Central/ScanCallback/ScanCallback.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/Central/ScanCallback/ScanCallback.ino b/examples/Central/ScanCallback/ScanCallback.ino index f84b88e1..e88f8789 100644 --- a/examples/Central/ScanCallback/ScanCallback.ino +++ b/examples/Central/ScanCallback/ScanCallback.ino @@ -30,7 +30,7 @@ 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); +/*#define SpiHCI SPI HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI_MODE0); BLELocalDevice BLE(&HCISpiTransport); */ /* Shield BNRG2A1 with SPI clock on D3 */ From b598a3fa8d0fa3d8c180e9625add9db3409aa775 Mon Sep 17 00:00:00 2001 From: Carlo Parata <carlo.parata@st.com> Date: Mon, 17 Feb 2020 10:39:48 +0100 Subject: [PATCH 017/226] Update examples/Central/ScanCallback/ScanCallback.ino Co-Authored-By: Frederic Pillon <frederic.pillon@st.com> --- examples/Central/ScanCallback/ScanCallback.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/Central/ScanCallback/ScanCallback.ino b/examples/Central/ScanCallback/ScanCallback.ino index e88f8789..3c927140 100644 --- a/examples/Central/ScanCallback/ScanCallback.ino +++ b/examples/Central/ScanCallback/ScanCallback.ino @@ -38,7 +38,7 @@ BLELocalDevice BLE(&HCISpiTransport); */ HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1); BLELocalDevice BLE(&HCISpiTransport); */ /* Shield BNRG2A1 with SPI clock on D13 */ -/*SPIClass SpiHCI(D11, D12, D13); +/*#define SpiHCI SPI HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1); BLELocalDevice BLE(&HCISpiTransport); */ #endif From aa6e1b30e8a3ebe426231107c4bc0b1a3f15c538 Mon Sep 17 00:00:00 2001 From: Carlo Parata <carlo.parata@st.com> Date: Mon, 17 Feb 2020 10:40:00 +0100 Subject: [PATCH 018/226] Update examples/Central/SensorTagButton/SensorTagButton.ino Co-Authored-By: Frederic Pillon <frederic.pillon@st.com> --- examples/Central/SensorTagButton/SensorTagButton.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/Central/SensorTagButton/SensorTagButton.ino b/examples/Central/SensorTagButton/SensorTagButton.ino index dd8d8ade..cb43ae7d 100644 --- a/examples/Central/SensorTagButton/SensorTagButton.ino +++ b/examples/Central/SensorTagButton/SensorTagButton.ino @@ -32,7 +32,7 @@ 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); +/*#define SpiHCI SPI HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI_MODE0); BLELocalDevice BLE(&HCISpiTransport); */ /* Shield BNRG2A1 with SPI clock on D3 */ From 18e0ca187283face9db991e610113bbdc0ed3ecb Mon Sep 17 00:00:00 2001 From: Carlo Parata <carlo.parata@st.com> Date: Mon, 17 Feb 2020 10:40:13 +0100 Subject: [PATCH 019/226] Update examples/Central/SensorTagButton/SensorTagButton.ino Co-Authored-By: Frederic Pillon <frederic.pillon@st.com> --- examples/Central/SensorTagButton/SensorTagButton.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/Central/SensorTagButton/SensorTagButton.ino b/examples/Central/SensorTagButton/SensorTagButton.ino index cb43ae7d..b17f0766 100644 --- a/examples/Central/SensorTagButton/SensorTagButton.ino +++ b/examples/Central/SensorTagButton/SensorTagButton.ino @@ -40,7 +40,7 @@ BLELocalDevice BLE(&HCISpiTransport); */ HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1); BLELocalDevice BLE(&HCISpiTransport); */ /* Shield BNRG2A1 with SPI clock on D13 */ -/*SPIClass SpiHCI(D11, D12, D13); +/*#define SpiHCI SPI HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1); BLELocalDevice BLE(&HCISpiTransport); */ #endif From fafde937b1b5322af7433dbf25ab21754d8207c2 Mon Sep 17 00:00:00 2001 From: Carlo Parata <carlo.parata@st.com> Date: Mon, 17 Feb 2020 10:40:23 +0100 Subject: [PATCH 020/226] Update examples/Peripheral/ButtonLED/ButtonLED.ino Co-Authored-By: Frederic Pillon <frederic.pillon@st.com> --- examples/Peripheral/ButtonLED/ButtonLED.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/Peripheral/ButtonLED/ButtonLED.ino b/examples/Peripheral/ButtonLED/ButtonLED.ino index ea14b7c8..9dd04044 100644 --- a/examples/Peripheral/ButtonLED/ButtonLED.ino +++ b/examples/Peripheral/ButtonLED/ButtonLED.ino @@ -36,7 +36,7 @@ HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI BLELocalDevice BLE(&HCISpiTransport); const int buttonPin = PC13; // set buttonPin to digital pin PC13 /* Shield IDB05A1 with SPI clock on D13 */ -/*SPIClass SpiHCI(D11, D12, D13); +/*#define SpiHCI SPI HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI_MODE0); BLELocalDevice BLE(&HCISpiTransport); const int buttonPin = PC13; // set buttonPin to digital pin PC13 */ From b95942fe54cc07f5e41e57a34eaf048036483b4a Mon Sep 17 00:00:00 2001 From: Carlo Parata <carlo.parata@st.com> Date: Mon, 17 Feb 2020 10:40:33 +0100 Subject: [PATCH 021/226] Update examples/Peripheral/ButtonLED/ButtonLED.ino Co-Authored-By: Frederic Pillon <frederic.pillon@st.com> --- examples/Peripheral/ButtonLED/ButtonLED.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/Peripheral/ButtonLED/ButtonLED.ino b/examples/Peripheral/ButtonLED/ButtonLED.ino index 9dd04044..0e93f03b 100644 --- a/examples/Peripheral/ButtonLED/ButtonLED.ino +++ b/examples/Peripheral/ButtonLED/ButtonLED.ino @@ -46,7 +46,7 @@ HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, BLELocalDevice BLE(&HCISpiTransport); const int buttonPin = PC13; // set buttonPin to digital pin PC13 */ /* Shield BNRG2A1 with SPI clock on D13 */ -/*SPIClass SpiHCI(D11, D12, D13); +/*#define SpiHCI SPI HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1); BLELocalDevice BLE(&HCISpiTransport); const int buttonPin = PC13; // set buttonPin to digital pin PC13 */ From da2c4fdad68d4963f049efefd6f126c17036afa5 Mon Sep 17 00:00:00 2001 From: Carlo Parata <carlo.parata@st.com> Date: Mon, 17 Feb 2020 10:40:44 +0100 Subject: [PATCH 022/226] Update examples/Peripheral/CallbackLED/CallbackLED.ino Co-Authored-By: Frederic Pillon <frederic.pillon@st.com> --- examples/Peripheral/CallbackLED/CallbackLED.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/Peripheral/CallbackLED/CallbackLED.ino b/examples/Peripheral/CallbackLED/CallbackLED.ino index c794856e..6b9e499d 100644 --- a/examples/Peripheral/CallbackLED/CallbackLED.ino +++ b/examples/Peripheral/CallbackLED/CallbackLED.ino @@ -37,7 +37,7 @@ BLELocalDevice BLE(&HCISpiTransport); HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI_MODE0); BLELocalDevice BLE(&HCISpiTransport); */ /* Shield BNRG2A1 with SPI clock on D3 */ -/*SPIClass SpiHCI(D11, D12, D3); +/*#define SpiHCI SPI HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1); BLELocalDevice BLE(&HCISpiTransport); */ /* Shield BNRG2A1 with SPI clock on D13 */ From 11bb9499910485b2f8b6cec100cfafb0f832fd42 Mon Sep 17 00:00:00 2001 From: Carlo Parata <carlo.parata@st.com> Date: Mon, 17 Feb 2020 10:40:55 +0100 Subject: [PATCH 023/226] Update examples/Peripheral/CallbackLED/CallbackLED.ino Co-Authored-By: Frederic Pillon <frederic.pillon@st.com> --- examples/Peripheral/CallbackLED/CallbackLED.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/Peripheral/CallbackLED/CallbackLED.ino b/examples/Peripheral/CallbackLED/CallbackLED.ino index 6b9e499d..24929e5e 100644 --- a/examples/Peripheral/CallbackLED/CallbackLED.ino +++ b/examples/Peripheral/CallbackLED/CallbackLED.ino @@ -41,7 +41,7 @@ BLELocalDevice BLE(&HCISpiTransport); */ HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1); BLELocalDevice BLE(&HCISpiTransport); */ /* Shield BNRG2A1 with SPI clock on D13 */ -/*SPIClass SpiHCI(D11, D12, D13); +/*#define SpiHCI SPI HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1); BLELocalDevice BLE(&HCISpiTransport); */ #endif From d4bb5d87ce8f0cc48b44a0f97b2db0fb24471359 Mon Sep 17 00:00:00 2001 From: Carlo Parata <carlo.parata@st.com> Date: Mon, 17 Feb 2020 10:41:08 +0100 Subject: [PATCH 024/226] Update examples/Peripheral/LED/LED.ino Co-Authored-By: Frederic Pillon <frederic.pillon@st.com> --- examples/Peripheral/LED/LED.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/Peripheral/LED/LED.ino b/examples/Peripheral/LED/LED.ino index a6da2dca..a23fe1a4 100644 --- a/examples/Peripheral/LED/LED.ino +++ b/examples/Peripheral/LED/LED.ino @@ -31,7 +31,7 @@ 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); +/*#define SpiHCI SPI HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI_MODE0); BLELocalDevice BLE(&HCISpiTransport); */ /* Shield BNRG2A1 with SPI clock on D3 */ From e53282b2c1b537e098c107b97424f504a57c19f2 Mon Sep 17 00:00:00 2001 From: Carlo Parata <carlo.parata@st.com> Date: Mon, 17 Feb 2020 10:41:21 +0100 Subject: [PATCH 025/226] Update examples/Peripheral/LED/LED.ino Co-Authored-By: Frederic Pillon <frederic.pillon@st.com> --- examples/Peripheral/LED/LED.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/Peripheral/LED/LED.ino b/examples/Peripheral/LED/LED.ino index a23fe1a4..c1a1ed58 100644 --- a/examples/Peripheral/LED/LED.ino +++ b/examples/Peripheral/LED/LED.ino @@ -39,7 +39,7 @@ BLELocalDevice BLE(&HCISpiTransport); */ HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1); BLELocalDevice BLE(&HCISpiTransport); */ /* Shield BNRG2A1 with SPI clock on D13 */ -/*SPIClass SpiHCI(D11, D12, D13); +/*#define SpiHCI SPI HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1); BLELocalDevice BLE(&HCISpiTransport); */ #endif From 5d789c63edcc99c463714a75fbe5ae1dc414e98a Mon Sep 17 00:00:00 2001 From: Carlo Parata <carlo.parata@st.com> Date: Mon, 17 Feb 2020 11:11:51 +0100 Subject: [PATCH 026/226] Improve check when BLE chip is not supported --- src/utility/HCISpiTransport.cpp | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/utility/HCISpiTransport.cpp b/src/utility/HCISpiTransport.cpp index 6f86f86b..486df38a 100644 --- a/src/utility/HCISpiTransport.cpp +++ b/src/utility/HCISpiTransport.cpp @@ -76,7 +76,8 @@ int HCISpiTransportClass::begin() delay(300); } else { - + // BLE chip not supported + return 0; } return 1; @@ -101,6 +102,11 @@ void HCISpiTransportClass::wait(unsigned long timeout) int HCISpiTransportClass::available() { + if(_ble_chip != SPBTLE_RF && _ble_chip !=SPBTLE_1S && _ble_chip !=BLUENRG_M2SP) + { + return 0; + } + if(_read_index != _write_index) { return 1; @@ -242,9 +248,6 @@ int HCISpiTransportClass::available() } } } - } else - { - } digitalWrite(_cs_pin, HIGH); @@ -268,9 +271,6 @@ int HCISpiTransportClass::available() { /* BLE chip was reset: we need to wait for a while */ delay(300); - } else - { - } /* Now we can update the write index and close the initial phase */ @@ -330,6 +330,11 @@ 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) + { + return 0; + } + do { if (_ble_chip == SPBTLE_RF) @@ -423,9 +428,6 @@ size_t HCISpiTransportClass::write(const uint8_t* data, size_t length) result = -3; break; } - } else - { - } } while(result < 0); From bd1b0e0eb5c82e9ad0072cadd340ac1c2841de61 Mon Sep 17 00:00:00 2001 From: Carlo Parata <carlo.parata@st.com> Date: Mon, 17 Feb 2020 11:34:49 +0100 Subject: [PATCH 027/226] Update keywords.txt with new classes, methods and constants --- keywords.txt | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/keywords.txt b/keywords.txt index 12f67785..e7f1b228 100644 --- a/keywords.txt +++ b/keywords.txt @@ -30,6 +30,9 @@ BLEFloatCharacteristic KEYWORD1 BLEDoubleCharacteristic KEYWORD1 BLEStringCharacteristic KEYWORD1 +HCISpiTransportClass KEYWORD1 +HCITransportInterface KEYWORD1 + ####################################### # Methods and Functions (KEYWORD2) ####################################### @@ -112,7 +115,11 @@ setValueBE KEYWORD2 valueBE KEYWORD2 uuid KEYWORD2 -addCharacteristic KEYWORD +addCharacteristic KEYWORD2 + +wait KEYWORD2 +peek KEYWORD2 +write KEYWORD2 ####################################### # Constants (LITERAL1) @@ -132,5 +139,10 @@ BLEIndicate LITERAL1 BLESubscribed LITERAL1 BLEUnsubscribed LITERAL1 BLEWritten LITERAL1 -BLEUpdated LITERAL1 +BLEUpdated LITERAL1 + +SPBTLE_RF LITERAL1 +SPBTLE_1S LITERAL1 +BLUENRG_M2SP LITERAL1 +BLEChip_t LITERAL1 From 742e409953bbd2ee46f0fcb75fa3b1ea7e30a3ae Mon Sep 17 00:00:00 2001 From: Carlo Parata <carlo.parata@st.com> Date: Mon, 17 Feb 2020 12:23:56 +0100 Subject: [PATCH 028/226] Replace ArduinoBLE.h with STM32duinoBLE.h and create a new release for publication --- examples/Central/LedControl/LedControl.ino | 2 +- examples/Central/PeripheralExplorer/PeripheralExplorer.ino | 2 +- examples/Central/Scan/Scan.ino | 2 +- examples/Central/ScanCallback/ScanCallback.ino | 2 +- examples/Central/SensorTagButton/SensorTagButton.ino | 2 +- examples/Peripheral/ButtonLED/ButtonLED.ino | 2 +- examples/Peripheral/CallbackLED/CallbackLED.ino | 2 +- examples/Peripheral/LED/LED.ino | 2 +- keywords.txt | 5 ++--- library.properties | 4 ++-- src/{ArduinoBLE.h => STM32duinoBLE.h} | 4 ++-- 11 files changed, 14 insertions(+), 15 deletions(-) rename src/{ArduinoBLE.h => STM32duinoBLE.h} (94%) diff --git a/examples/Central/LedControl/LedControl.ino b/examples/Central/LedControl/LedControl.ino index a3115f53..bc1e963c 100644 --- a/examples/Central/LedControl/LedControl.ino +++ b/examples/Central/LedControl/LedControl.ino @@ -14,7 +14,7 @@ This example code is in the public domain. */ -#include <ArduinoBLE.h> +#include <STM32duinoBLE.h> #if defined(ARDUINO_STEVAL_MKSBOX1V1) /* STEVAL-MKSBOX1V1 */ diff --git a/examples/Central/PeripheralExplorer/PeripheralExplorer.ino b/examples/Central/PeripheralExplorer/PeripheralExplorer.ino index 82e1cc60..83fb396a 100644 --- a/examples/Central/PeripheralExplorer/PeripheralExplorer.ino +++ b/examples/Central/PeripheralExplorer/PeripheralExplorer.ino @@ -13,7 +13,7 @@ This example code is in the public domain. */ -#include <ArduinoBLE.h> +#include <STM32duinoBLE.h> #if defined(ARDUINO_STEVAL_MKSBOX1V1) /* STEVAL-MKSBOX1V1 */ diff --git a/examples/Central/Scan/Scan.ino b/examples/Central/Scan/Scan.ino index 74ce1a71..0d2377a8 100644 --- a/examples/Central/Scan/Scan.ino +++ b/examples/Central/Scan/Scan.ino @@ -10,7 +10,7 @@ This example code is in the public domain. */ -#include <ArduinoBLE.h> +#include <STM32duinoBLE.h> #if defined(ARDUINO_STEVAL_MKSBOX1V1) /* STEVAL-MKSBOX1V1 */ diff --git a/examples/Central/ScanCallback/ScanCallback.ino b/examples/Central/ScanCallback/ScanCallback.ino index 3c927140..104591a7 100644 --- a/examples/Central/ScanCallback/ScanCallback.ino +++ b/examples/Central/ScanCallback/ScanCallback.ino @@ -12,7 +12,7 @@ This example code is in the public domain. */ -#include <ArduinoBLE.h> +#include <STM32duinoBLE.h> #if defined(ARDUINO_STEVAL_MKSBOX1V1) /* STEVAL-MKSBOX1V1 */ diff --git a/examples/Central/SensorTagButton/SensorTagButton.ino b/examples/Central/SensorTagButton/SensorTagButton.ino index b17f0766..b557adaa 100644 --- a/examples/Central/SensorTagButton/SensorTagButton.ino +++ b/examples/Central/SensorTagButton/SensorTagButton.ino @@ -14,7 +14,7 @@ This example code is in the public domain. */ -#include <ArduinoBLE.h> +#include <STM32duinoBLE.h> #if defined(ARDUINO_STEVAL_MKSBOX1V1) /* STEVAL-MKSBOX1V1 */ diff --git a/examples/Peripheral/ButtonLED/ButtonLED.ino b/examples/Peripheral/ButtonLED/ButtonLED.ino index 0e93f03b..99417d68 100644 --- a/examples/Peripheral/ButtonLED/ButtonLED.ino +++ b/examples/Peripheral/ButtonLED/ButtonLED.ino @@ -15,7 +15,7 @@ This example code is in the public domain. */ -#include <ArduinoBLE.h> +#include <STM32duinoBLE.h> #if defined(ARDUINO_STEVAL_MKSBOX1V1) /* STEVAL-MKSBOX1V1 */ diff --git a/examples/Peripheral/CallbackLED/CallbackLED.ino b/examples/Peripheral/CallbackLED/CallbackLED.ino index 24929e5e..7a28a4ed 100644 --- a/examples/Peripheral/CallbackLED/CallbackLED.ino +++ b/examples/Peripheral/CallbackLED/CallbackLED.ino @@ -15,7 +15,7 @@ This example code is in the public domain. */ -#include <ArduinoBLE.h> +#include <STM32duinoBLE.h> #if defined(ARDUINO_STEVAL_MKSBOX1V1) /* STEVAL-MKSBOX1V1 */ diff --git a/examples/Peripheral/LED/LED.ino b/examples/Peripheral/LED/LED.ino index c1a1ed58..422796fa 100644 --- a/examples/Peripheral/LED/LED.ino +++ b/examples/Peripheral/LED/LED.ino @@ -13,7 +13,7 @@ This example code is in the public domain. */ -#include <ArduinoBLE.h> +#include <STM32duinoBLE.h> #if defined(ARDUINO_STEVAL_MKSBOX1V1) /* STEVAL-MKSBOX1V1 */ diff --git a/keywords.txt b/keywords.txt index e7f1b228..9214671b 100644 --- a/keywords.txt +++ b/keywords.txt @@ -1,13 +1,12 @@ ####################################### -# Syntax Coloring Map For ArduinoBLE +# Syntax Coloring Map For STM32duinoBLE ####################################### ####################################### # Datatypes (KEYWORD1) ####################################### -ArduinoBLE KEYWORD1 -BLE KEYWORD1 +STM32duinoBLE KEYWORD1 BLEDevice KEYWORD1 BLECharacteristic KEYWORD1 diff --git a/library.properties b/library.properties index b1eaf241..909871e2 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=STM32duinoBLE -version=1.1.2 +version=1.2.0 author=Arduino, SRA maintainer=stm32duino sentence=Fork of ArduinoBLE library to add the support of SPBTLE-RF and SPBTLE-1S BLE modules. @@ -7,4 +7,4 @@ paragraph=This library supports creating a BLE peripheral and BLE central mode. category=Communication url=https://github.com/stm32duino/STM32duinoBLE architectures=stm32 -includes=ArduinoBLE.h +includes=STM32duinoBLE.h diff --git a/src/ArduinoBLE.h b/src/STM32duinoBLE.h similarity index 94% rename from src/ArduinoBLE.h rename to src/STM32duinoBLE.h index 41c11111..b5fa9b54 100644 --- a/src/ArduinoBLE.h +++ b/src/STM32duinoBLE.h @@ -17,8 +17,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef _ARDUINO_BLE_H_ -#define _ARDUINO_BLE_H_ +#ifndef _STM32DUINO_BLE_H_ +#define _STM32DUINO_BLE_H_ #include "local/BLELocalDevice.h" #include "BLEProperty.h" From 3499bfa232198913761683f8ff5405c0da7f3a20 Mon Sep 17 00:00:00 2001 From: Carlo Parata <carlo.parata@st.com> Date: Mon, 17 Feb 2020 12:35:36 +0100 Subject: [PATCH 029/226] Update CHANGELOG --- CHANGELOG | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index a29f8598..4844008e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,4 +1,7 @@ -ArduinoBLE ?.?.? - ????.??.?? +STM32duinoBLE 1.2.0 - 2020.02.17 +* Added support to X-NUCLEO-BNRG2A1 +* Renamed ArduinoBLE as STM32duinoBLE +* Moved the SPI Transport instance in the application code to improve portability ArduinoBLE 1.1.2 - 2019.11.12 From 73a4e1a4db194450db7ead841a926efb9a2d73c5 Mon Sep 17 00:00:00 2001 From: Carlo Parata <carlo.parata@st.com> Date: Wed, 25 Mar 2020 19:17:06 +0100 Subject: [PATCH 030/226] Update README --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 437e1ae3..100cef59 100644 --- a/README.md +++ b/README.md @@ -6,12 +6,12 @@ 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: -https://github.com/stm32duino/wiki/wiki/STM32duinoBLE-with-STEVAL_MKSBOX1V1 +https://github.com/stm32duino/wiki/wiki/STM32duinoBLE#stm32duinoble-with-steval_mksbox1v1 In order to use this library with X-NUCLEO-BNRG2A1, you need to update the firmware of the BLUENRG-M2SP BLE module mounted on that expansion board as described in the following wiki page: -https://github.com/stm32duino/wiki/wiki/STM32duinoBLE-with-X_NUCLEO_BNRG2A1 +https://github.com/stm32duino/wiki/wiki/STM32duinoBLE#stm32duinoble-with-x-nucleo-bnrg2a1 For more information about ArduinoBLE library please visit the official web page at: https://github.com/arduino-libraries/ArduinoBLE From 93c68879590edd00a8763fb43fe7eaae60145a8c Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Thu, 10 Sep 2020 10:18:19 +0200 Subject: [PATCH 031/226] Fix Typo --- examples/Central/ScanCallback/ScanCallback.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/Central/ScanCallback/ScanCallback.ino b/examples/Central/ScanCallback/ScanCallback.ino index 104591a7..178c51ae 100644 --- a/examples/Central/ScanCallback/ScanCallback.ino +++ b/examples/Central/ScanCallback/ScanCallback.ino @@ -2,7 +2,7 @@ Scan Callback This example scans for BLE peripherals and prints out their advertising details: - address, local name, adverised service UUIDs. Unlike the Scan example, it uses + address, local name, advertised service UUIDs. Unlike the Scan example, it uses the callback style APIs and disables filtering so the peripheral discovery is reported for every single advertisement it makes. From 3559592f40065edb97d259a0d4304b5b1ee4ca11 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Thu, 10 Sep 2020 10:18:59 +0200 Subject: [PATCH 032/226] Fix typo --- examples/Central/Scan/Scan.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/Central/Scan/Scan.ino b/examples/Central/Scan/Scan.ino index 0d2377a8..e477a26c 100644 --- a/examples/Central/Scan/Scan.ino +++ b/examples/Central/Scan/Scan.ino @@ -2,7 +2,7 @@ Scan This example scans for BLE peripherals and prints out their advertising details: - address, local name, adverised service UUID's. + address, local name, advertised service UUID's. The circuit: - STEVAL-MKSBOX1V1, B-L475E-IOT01A1, or a Nucleo board plus the X-NUCLEO-IDB05A1 or the X-NUCLEO-BNRG2A1 From e7e1bf7274b2e12b82d8d2cbe68bf28a28d0424a Mon Sep 17 00:00:00 2001 From: Francois Ramu <francois.ramu@st.com> Date: Mon, 7 Sep 2020 16:16:46 +0200 Subject: [PATCH 033/226] add stm32L4+ discovery kit for BLE access of all examples B_L4S5I_IOT01A is using same pins for Bluetooth and SPI3 as the discovery kit B-L475E-IOT01A1 Signed-off-by: Francois Ramu <francois.ramu@st.com> --- examples/Central/LedControl/LedControl.ino | 6 +++--- examples/Central/PeripheralExplorer/PeripheralExplorer.ino | 6 +++--- examples/Central/Scan/Scan.ino | 6 +++--- examples/Central/ScanCallback/ScanCallback.ino | 6 +++--- examples/Central/SensorTagButton/SensorTagButton.ino | 6 +++--- examples/Peripheral/ButtonLED/ButtonLED.ino | 6 +++--- examples/Peripheral/CallbackLED/CallbackLED.ino | 6 +++--- examples/Peripheral/LED/LED.ino | 6 +++--- 8 files changed, 24 insertions(+), 24 deletions(-) diff --git a/examples/Central/LedControl/LedControl.ino b/examples/Central/LedControl/LedControl.ino index bc1e963c..a029a811 100644 --- a/examples/Central/LedControl/LedControl.ino +++ b/examples/Central/LedControl/LedControl.ino @@ -6,7 +6,7 @@ it will remotely control the BLE Peripheral's LED, when the button is pressed or released. The circuit: - - STEVAL-MKSBOX1V1, B-L475E-IOT01A1, or a Nucleo board plus the X-NUCLEO-IDB05A1 or the X-NUCLEO-BNRG2A1 + - STEVAL-MKSBOX1V1, B-L475E-IOT01A1, B_L4S5I_IOT01A, or a Nucleo board plus the X-NUCLEO-IDB05A1 or the X-NUCLEO-BNRG2A1 You can use it with another board that is compatible with this library and the Peripherals -> LED example. @@ -22,8 +22,8 @@ SPIClass SpiHCI(PC3, PD3, PD1); HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_1S, PD0, PD4, PA8, 1000000, SPI_MODE1); BLELocalDevice BLE(&HCISpiTransport); const int buttonPin = PG1; // set buttonPin to digital pin PG1 -#elif defined(ARDUINO_DISCO_L475VG_IOT) -/* B-L475E-IOT01A1 */ +#elif defined(ARDUINO_DISCO_L475VG_IOT) || defined(ARDUINO_B_L4S5I_IOT01A) +/* B-L475E-IOT01A1 or B_L4S5I_IOT01A */ SPIClass SpiHCI(PC12, PC11, PC10); HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, PD13, PE6, PA8, 8000000, SPI_MODE0); BLELocalDevice BLE(&HCISpiTransport); diff --git a/examples/Central/PeripheralExplorer/PeripheralExplorer.ino b/examples/Central/PeripheralExplorer/PeripheralExplorer.ino index 83fb396a..dd297548 100644 --- a/examples/Central/PeripheralExplorer/PeripheralExplorer.ino +++ b/examples/Central/PeripheralExplorer/PeripheralExplorer.ino @@ -5,7 +5,7 @@ is found. Then connects, and discovers + prints all the peripheral's attributes. The circuit: - - STEVAL-MKSBOX1V1, B-L475E-IOT01A1, or a Nucleo board plus the X-NUCLEO-IDB05A1 or the X-NUCLEO-BNRG2A1 + - STEVAL-MKSBOX1V1, B-L475E-IOT01A1, B_L4S5I_IOT01A, or a Nucleo board plus the X-NUCLEO-IDB05A1 or the X-NUCLEO-BNRG2A1 You can use it with another board that is compatible with this library and the Peripherals -> LED example. @@ -20,8 +20,8 @@ SPIClass SpiHCI(PC3, PD3, PD1); HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_1S, PD0, PD4, PA8, 1000000, SPI_MODE1); BLELocalDevice BLE(&HCISpiTransport); -#elif defined(ARDUINO_DISCO_L475VG_IOT) -/* B-L475E-IOT01A1 */ +#elif defined(ARDUINO_DISCO_L475VG_IOT) || defined(ARDUINO_B_L4S5I_IOT01A) +/* B-L475E-IOT01A1 or B_L4S5I_IOT01A */ SPIClass SpiHCI(PC12, PC11, PC10); HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, PD13, PE6, PA8, 8000000, SPI_MODE0); BLELocalDevice BLE(&HCISpiTransport); diff --git a/examples/Central/Scan/Scan.ino b/examples/Central/Scan/Scan.ino index e477a26c..72f12c44 100644 --- a/examples/Central/Scan/Scan.ino +++ b/examples/Central/Scan/Scan.ino @@ -5,7 +5,7 @@ address, local name, advertised service UUID's. The circuit: - - STEVAL-MKSBOX1V1, B-L475E-IOT01A1, or a Nucleo board plus the X-NUCLEO-IDB05A1 or the X-NUCLEO-BNRG2A1 + - STEVAL-MKSBOX1V1, B-L475E-IOT01A1, B_L4S5I_IOT01A, or a Nucleo board plus the X-NUCLEO-IDB05A1 or the X-NUCLEO-BNRG2A1 This example code is in the public domain. */ @@ -17,8 +17,8 @@ SPIClass SpiHCI(PC3, PD3, PD1); HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_1S, PD0, PD4, PA8, 1000000, SPI_MODE1); BLELocalDevice BLE(&HCISpiTransport); -#elif defined(ARDUINO_DISCO_L475VG_IOT) -/* B-L475E-IOT01A1 */ +#elif defined(ARDUINO_DISCO_L475VG_IOT) || defined(ARDUINO_B_L4S5I_IOT01A) +/* B-L475E-IOT01A1 or B_L4S5I_IOT01A */ SPIClass SpiHCI(PC12, PC11, PC10); HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, PD13, PE6, PA8, 8000000, SPI_MODE0); BLELocalDevice BLE(&HCISpiTransport); diff --git a/examples/Central/ScanCallback/ScanCallback.ino b/examples/Central/ScanCallback/ScanCallback.ino index 178c51ae..eae5ec2f 100644 --- a/examples/Central/ScanCallback/ScanCallback.ino +++ b/examples/Central/ScanCallback/ScanCallback.ino @@ -7,7 +7,7 @@ reported for every single advertisement it makes. The circuit: - - STEVAL-MKSBOX1V1, B-L475E-IOT01A1, or a Nucleo board plus the X-NUCLEO-IDB05A1 or the X-NUCLEO-BNRG2A1 + - STEVAL-MKSBOX1V1, B-L475E-IOT01A1, B_L4S5I_IOT01A, or a Nucleo board plus the X-NUCLEO-IDB05A1 or the X-NUCLEO-BNRG2A1 This example code is in the public domain. */ @@ -19,8 +19,8 @@ SPIClass SpiHCI(PC3, PD3, PD1); HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_1S, PD0, PD4, PA8, 1000000, SPI_MODE1); BLELocalDevice BLE(&HCISpiTransport); -#elif defined(ARDUINO_DISCO_L475VG_IOT) -/* B-L475E-IOT01A1 */ +#elif defined(ARDUINO_DISCO_L475VG_IOT) || defined(ARDUINO_B_L4S5I_IOT01A) +/* B-L475E-IOT01A1 or B_L4S5I_IOT01A */ SPIClass SpiHCI(PC12, PC11, PC10); HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, PD13, PE6, PA8, 8000000, SPI_MODE0); BLELocalDevice BLE(&HCISpiTransport); diff --git a/examples/Central/SensorTagButton/SensorTagButton.ino b/examples/Central/SensorTagButton/SensorTagButton.ino index b557adaa..1a695ee8 100644 --- a/examples/Central/SensorTagButton/SensorTagButton.ino +++ b/examples/Central/SensorTagButton/SensorTagButton.ino @@ -8,7 +8,7 @@ outputted to the Serial Monitor when one is pressed. The circuit: - - STEVAL-MKSBOX1V1, B-L475E-IOT01A1, or a Nucleo board plus the X-NUCLEO-IDB05A1 or the X-NUCLEO-BNRG2A1 + - STEVAL-MKSBOX1V1, B-L475E-IOT01A1, B_L4S5I_IOT01A, or a Nucleo board plus the X-NUCLEO-IDB05A1 or the X-NUCLEO-BNRG2A1 - TI SensorTag This example code is in the public domain. @@ -21,8 +21,8 @@ SPIClass SpiHCI(PC3, PD3, PD1); HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_1S, PD0, PD4, PA8, 1000000, SPI_MODE1); BLELocalDevice BLE(&HCISpiTransport); -#elif defined(ARDUINO_DISCO_L475VG_IOT) -/* B-L475E-IOT01A1 */ +#elif defined(ARDUINO_DISCO_L475VG_IOT) || defined(ARDUINO_B_L4S5I_IOT01A) +/* B-L475E-IOT01A1 or B_L4S5I_IOT01A */ SPIClass SpiHCI(PC12, PC11, PC10); HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, PD13, PE6, PA8, 8000000, SPI_MODE0); BLELocalDevice BLE(&HCISpiTransport); diff --git a/examples/Peripheral/ButtonLED/ButtonLED.ino b/examples/Peripheral/ButtonLED/ButtonLED.ino index 99417d68..fbae13f3 100644 --- a/examples/Peripheral/ButtonLED/ButtonLED.ino +++ b/examples/Peripheral/ButtonLED/ButtonLED.ino @@ -6,7 +6,7 @@ represents the state of the button. The circuit: - - STEVAL-MKSBOX1V1, B-L475E-IOT01A1, or a Nucleo board plus the X-NUCLEO-IDB05A1 or the X-NUCLEO-BNRG2A1 + - STEVAL-MKSBOX1V1, B-L475E-IOT01A1, B_L4S5I_IOT01A, or a Nucleo board plus the X-NUCLEO-IDB05A1 or the X-NUCLEO-BNRG2A1 You can use a generic BLE central app, like LightBlue (iOS and Android) or nRF Connect (Android), to interact with the services and characteristics @@ -23,8 +23,8 @@ SPIClass SpiHCI(PC3, PD3, PD1); HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_1S, PD0, PD4, PA8, 1000000, SPI_MODE1); BLELocalDevice BLE(&HCISpiTransport); const int buttonPin = PG1; // set buttonPin to digital pin PG1 -#elif defined(ARDUINO_DISCO_L475VG_IOT) -/* B-L475E-IOT01A1 */ +#elif defined(ARDUINO_DISCO_L475VG_IOT) || defined(ARDUINO_B_L4S5I_IOT01A) +/* B-L475E-IOT01A1 or B_L4S5I_IOT01A */ SPIClass SpiHCI(PC12, PC11, PC10); HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, PD13, PE6, PA8, 8000000, SPI_MODE0); BLELocalDevice BLE(&HCISpiTransport); diff --git a/examples/Peripheral/CallbackLED/CallbackLED.ino b/examples/Peripheral/CallbackLED/CallbackLED.ino index 7a28a4ed..ea521187 100644 --- a/examples/Peripheral/CallbackLED/CallbackLED.ino +++ b/examples/Peripheral/CallbackLED/CallbackLED.ino @@ -6,7 +6,7 @@ library are used. The circuit: - - STEVAL-MKSBOX1V1, B-L475E-IOT01A1, or a Nucleo board plus the X-NUCLEO-IDB05A1 or the X-NUCLEO-BNRG2A1 + - STEVAL-MKSBOX1V1, B-L475E-IOT01A1, B_L4S5I_IOT01A, or a Nucleo board plus the X-NUCLEO-IDB05A1 or the X-NUCLEO-BNRG2A1 You can use a generic BLE central app, like LightBlue (iOS and Android) or nRF Connect (Android), to interact with the services and characteristics @@ -22,8 +22,8 @@ SPIClass SpiHCI(PC3, PD3, PD1); HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_1S, PD0, PD4, PA8, 1000000, SPI_MODE1); BLELocalDevice BLE(&HCISpiTransport); -#elif defined(ARDUINO_DISCO_L475VG_IOT) -/* B-L475E-IOT01A1 */ +#elif defined(ARDUINO_DISCO_L475VG_IOT) || defined(ARDUINO_B_L4S5I_IOT01A) +/* B-L475E-IOT01A1 or B_L4S5I_IOT01A */ SPIClass SpiHCI(PC12, PC11, PC10); HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, PD13, PE6, PA8, 8000000, SPI_MODE0); BLELocalDevice BLE(&HCISpiTransport); diff --git a/examples/Peripheral/LED/LED.ino b/examples/Peripheral/LED/LED.ino index 422796fa..5697a007 100644 --- a/examples/Peripheral/LED/LED.ino +++ b/examples/Peripheral/LED/LED.ino @@ -5,7 +5,7 @@ characteristic to control an LED. The circuit: - - STEVAL-MKSBOX1V1, B-L475E-IOT01A1, or a Nucleo board plus the X-NUCLEO-IDB05A1 or the X-NUCLEO-BNRG2A1 + - STEVAL-MKSBOX1V1, B-L475E-IOT01A1, B_L4S5I_IOT01A, or a Nucleo board plus the X-NUCLEO-IDB05A1 or the X-NUCLEO-BNRG2A1 You can use a generic BLE central app, like LightBlue (iOS and Android) or nRF Connect (Android), to interact with the services and characteristics @@ -20,8 +20,8 @@ SPIClass SpiHCI(PC3, PD3, PD1); HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_1S, PD0, PD4, PA8, 1000000, SPI_MODE1); BLELocalDevice BLE(&HCISpiTransport); -#elif defined(ARDUINO_DISCO_L475VG_IOT) -/* B-L475E-IOT01A1 */ +#elif defined(ARDUINO_DISCO_L475VG_IOT) || defined(ARDUINO_B_L4S5I_IOT01A) +/* B-L475E-IOT01A1 or B_L4S5I_IOT01A */ SPIClass SpiHCI(PC12, PC11, PC10); HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, PD13, PE6, PA8, 8000000, SPI_MODE0); BLELocalDevice BLE(&HCISpiTransport); From 14fd996cf56952864e2b9860e04bbe379cb4e169 Mon Sep 17 00:00:00 2001 From: Carlo Parata <carlo.parata@st.com> Date: Thu, 24 Sep 2020 15:20:31 +0200 Subject: [PATCH 034/226] Fix compilation warning --- src/utility/GAP.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utility/GAP.h b/src/utility/GAP.h index b1b1cf48..cc64aab5 100644 --- a/src/utility/GAP.h +++ b/src/utility/GAP.h @@ -77,7 +77,7 @@ class GAPClass { uint16_t _serviceDataUuid; const uint8_t* _serviceData; - int _serviceDataLength; + uint32_t _serviceDataLength; BLEDeviceEventHandler _discoverEventHandler; BLELinkedList<BLEDevice*> _discoveredDevices; From 0d936a4f7c6452f0b5ffc7968d6baad7af579652 Mon Sep 17 00:00:00 2001 From: Carlo Parata <carlo.parata@st.com> Date: Wed, 30 Sep 2020 15:37:58 +0200 Subject: [PATCH 035/226] 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 From e6d06350b5879837c769f25f47c2b6d7941331c0 Mon Sep 17 00:00:00 2001 From: Carlo Parata <carlo.parata@st.com> Date: Wed, 30 Sep 2020 16:48:09 +0200 Subject: [PATCH 036/226] Update comment and restore B_L4S5I_IOT01A support --- examples/Central/LedControl/LedControl.ino | 2 +- examples/Central/PeripheralExplorer/PeripheralExplorer.ino | 2 +- examples/Central/Scan/Scan.ino | 2 +- examples/Central/ScanCallback/ScanCallback.ino | 2 +- examples/Central/SensorTagButton/SensorTagButton.ino | 2 +- examples/Peripheral/ButtonLED/ButtonLED.ino | 2 +- examples/Peripheral/CallbackLED/CallbackLED.ino | 2 +- examples/Peripheral/LED/LED.ino | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/examples/Central/LedControl/LedControl.ino b/examples/Central/LedControl/LedControl.ino index 69cb6156..4eec9259 100644 --- a/examples/Central/LedControl/LedControl.ino +++ b/examples/Central/LedControl/LedControl.ino @@ -6,7 +6,7 @@ it will remotely control the BLE Peripheral's LED, when the button is pressed or released. The circuit: - - STEVAL-MKSBOX1V1, B-L475E-IOT01A1, B_L4S5I_IOT01A, or a Nucleo board plus the X-NUCLEO-IDB05A1 or the X-NUCLEO-BNRG2A1 + - STEVAL-MKSBOX1V1, B-L475E-IOT01A1, B_L4S5I_IOT01A, or a Nucleo board plus the X-NUCLEO-IDB05A2 or the X-NUCLEO-IDB05A1 or the X-NUCLEO-BNRG2A1 You can use it with another board that is compatible with this library and the Peripherals -> LED example. diff --git a/examples/Central/PeripheralExplorer/PeripheralExplorer.ino b/examples/Central/PeripheralExplorer/PeripheralExplorer.ino index d86a13c8..5f33e4bd 100644 --- a/examples/Central/PeripheralExplorer/PeripheralExplorer.ino +++ b/examples/Central/PeripheralExplorer/PeripheralExplorer.ino @@ -5,7 +5,7 @@ is found. Then connects, and discovers + prints all the peripheral's attributes. The circuit: - - STEVAL-MKSBOX1V1, B-L475E-IOT01A1, B_L4S5I_IOT01A, or a Nucleo board plus the X-NUCLEO-IDB05A1 or the X-NUCLEO-BNRG2A1 + - STEVAL-MKSBOX1V1, B-L475E-IOT01A1, B_L4S5I_IOT01A, or a Nucleo board plus the X-NUCLEO-IDB05A2 or the X-NUCLEO-IDB05A1 or the X-NUCLEO-BNRG2A1 You can use it with another board that is compatible with this library and the Peripherals -> LED example. diff --git a/examples/Central/Scan/Scan.ino b/examples/Central/Scan/Scan.ino index 4b62c040..30e382e5 100644 --- a/examples/Central/Scan/Scan.ino +++ b/examples/Central/Scan/Scan.ino @@ -5,7 +5,7 @@ address, local name, advertised service UUID's. The circuit: - - STEVAL-MKSBOX1V1, B-L475E-IOT01A1, B_L4S5I_IOT01A, or a Nucleo board plus the X-NUCLEO-IDB05A1 or the X-NUCLEO-BNRG2A1 + - STEVAL-MKSBOX1V1, B-L475E-IOT01A1, B_L4S5I_IOT01A, or a Nucleo board plus the X-NUCLEO-IDB05A2 or the X-NUCLEO-IDB05A1 or the X-NUCLEO-BNRG2A1 This example code is in the public domain. */ diff --git a/examples/Central/ScanCallback/ScanCallback.ino b/examples/Central/ScanCallback/ScanCallback.ino index 02b76f19..e7c1711e 100644 --- a/examples/Central/ScanCallback/ScanCallback.ino +++ b/examples/Central/ScanCallback/ScanCallback.ino @@ -7,7 +7,7 @@ reported for every single advertisement it makes. The circuit: - - STEVAL-MKSBOX1V1, B-L475E-IOT01A1, B_L4S5I_IOT01A, or a Nucleo board plus the X-NUCLEO-IDB05A1 or the X-NUCLEO-BNRG2A1 + - STEVAL-MKSBOX1V1, B-L475E-IOT01A1, B_L4S5I_IOT01A, or a Nucleo board plus the X-NUCLEO-IDB05A2 or the X-NUCLEO-IDB05A1 or the X-NUCLEO-BNRG2A1 This example code is in the public domain. */ diff --git a/examples/Central/SensorTagButton/SensorTagButton.ino b/examples/Central/SensorTagButton/SensorTagButton.ino index 8daed4dc..0fdfdb13 100644 --- a/examples/Central/SensorTagButton/SensorTagButton.ino +++ b/examples/Central/SensorTagButton/SensorTagButton.ino @@ -8,7 +8,7 @@ outputted to the Serial Monitor when one is pressed. The circuit: - - STEVAL-MKSBOX1V1, B-L475E-IOT01A1, B_L4S5I_IOT01A, or a Nucleo board plus the X-NUCLEO-IDB05A1 or the X-NUCLEO-BNRG2A1 + - STEVAL-MKSBOX1V1, B-L475E-IOT01A1, B_L4S5I_IOT01A, or a Nucleo board plus the X-NUCLEO-IDB05A2 or the X-NUCLEO-IDB05A1 or the X-NUCLEO-BNRG2A1 - TI SensorTag This example code is in the public domain. diff --git a/examples/Peripheral/ButtonLED/ButtonLED.ino b/examples/Peripheral/ButtonLED/ButtonLED.ino index b99fe8b1..e343fb26 100644 --- a/examples/Peripheral/ButtonLED/ButtonLED.ino +++ b/examples/Peripheral/ButtonLED/ButtonLED.ino @@ -6,7 +6,7 @@ represents the state of the button. The circuit: - - STEVAL-MKSBOX1V1, B-L475E-IOT01A1, B_L4S5I_IOT01A, or a Nucleo board plus the X-NUCLEO-IDB05A1 or the X-NUCLEO-BNRG2A1 + - STEVAL-MKSBOX1V1, B-L475E-IOT01A1, B_L4S5I_IOT01A, or a Nucleo board plus the X-NUCLEO-IDB05A2 or the X-NUCLEO-IDB05A1 or the X-NUCLEO-BNRG2A1 You can use a generic BLE central app, like LightBlue (iOS and Android) or nRF Connect (Android), to interact with the services and characteristics diff --git a/examples/Peripheral/CallbackLED/CallbackLED.ino b/examples/Peripheral/CallbackLED/CallbackLED.ino index 3e61d3d3..44be0e39 100644 --- a/examples/Peripheral/CallbackLED/CallbackLED.ino +++ b/examples/Peripheral/CallbackLED/CallbackLED.ino @@ -6,7 +6,7 @@ library are used. The circuit: - - STEVAL-MKSBOX1V1, B-L475E-IOT01A1, B_L4S5I_IOT01A, or a Nucleo board plus the X-NUCLEO-IDB05A1 or the X-NUCLEO-BNRG2A1 + - STEVAL-MKSBOX1V1, B-L475E-IOT01A1, B_L4S5I_IOT01A, or a Nucleo board plus the X-NUCLEO-IDB05A2 or the X-NUCLEO-IDB05A1 or the X-NUCLEO-BNRG2A1 You can use a generic BLE central app, like LightBlue (iOS and Android) or nRF Connect (Android), to interact with the services and characteristics diff --git a/examples/Peripheral/LED/LED.ino b/examples/Peripheral/LED/LED.ino index 8b2a5131..8269bfcc 100644 --- a/examples/Peripheral/LED/LED.ino +++ b/examples/Peripheral/LED/LED.ino @@ -5,7 +5,7 @@ characteristic to control an LED. The circuit: - - STEVAL-MKSBOX1V1, B-L475E-IOT01A1, B_L4S5I_IOT01A, or a Nucleo board plus the X-NUCLEO-IDB05A1 or the X-NUCLEO-BNRG2A1 + - STEVAL-MKSBOX1V1, B-L475E-IOT01A1, B_L4S5I_IOT01A, or a Nucleo board plus the X-NUCLEO-IDB05A2 or the X-NUCLEO-IDB05A1 or the X-NUCLEO-BNRG2A1 You can use a generic BLE central app, like LightBlue (iOS and Android) or nRF Connect (Android), to interact with the services and characteristics From f7dbf187386fa29ef7a2577b83ec49faa2d9e71f Mon Sep 17 00:00:00 2001 From: Francois Ramu <francois.ramu@st.com> Date: Wed, 4 Nov 2020 16:44:37 +0100 Subject: [PATCH 037/226] Support of the shared memory transport layer for the stm32wb55 with STM32WB built-in chip (STM32WB_RF) It also Allows HCI SPI Transport with STM32WBxx Signed-off-by: Francois Ramu <francois.ramu@st.com> --- src/STM32duinoBLE.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/STM32duinoBLE.h b/src/STM32duinoBLE.h index b5fa9b54..4bf51468 100644 --- a/src/STM32duinoBLE.h +++ b/src/STM32duinoBLE.h @@ -24,6 +24,10 @@ #include "BLEProperty.h" #include "BLEStringCharacteristic.h" #include "BLETypedCharacteristics.h" + +#if defined(STM32WBxx) +#include "utility/HCISharedMemTransport.h" +#endif #include "utility/HCISpiTransport.h" #endif From 3019930966782e57d119e62b64248b0fee36d20f Mon Sep 17 00:00:00 2001 From: Francois Ramu <francois.ramu@st.com> Date: Tue, 13 Oct 2020 17:03:40 +0200 Subject: [PATCH 038/226] Include the STM32Cube_FW to support the BLE of the stm32wb55 Only in case STM32WBxx device defined Signed-off-by: Francois Ramu <francois.ramu@st.com> --- src/utility/STM32Cube_FW/README.md | 6 + src/utility/STM32Cube_FW/app_conf.h | 535 +++++++++++ src/utility/STM32Cube_FW/ble_bufsize.h | 161 ++++ src/utility/STM32Cube_FW/hw.h | 97 ++ src/utility/STM32Cube_FW/hw_ipcc.c | 342 +++++++ src/utility/STM32Cube_FW/mbox_def.h | 212 +++++ src/utility/STM32Cube_FW/shci.c | 567 ++++++++++++ src/utility/STM32Cube_FW/shci.h | 888 +++++++++++++++++++ src/utility/STM32Cube_FW/shci_tl.c | 344 +++++++ src/utility/STM32Cube_FW/shci_tl.h | 169 ++++ src/utility/STM32Cube_FW/stm32_wpan_common.h | 143 +++ src/utility/STM32Cube_FW/stm_list.c | 206 +++++ src/utility/STM32Cube_FW/stm_list.h | 58 ++ src/utility/STM32Cube_FW/tl.h | 294 ++++++ src/utility/STM32Cube_FW/tl_mbox.c | 545 ++++++++++++ 15 files changed, 4567 insertions(+) create mode 100644 src/utility/STM32Cube_FW/README.md create mode 100644 src/utility/STM32Cube_FW/app_conf.h create mode 100644 src/utility/STM32Cube_FW/ble_bufsize.h create mode 100644 src/utility/STM32Cube_FW/hw.h create mode 100644 src/utility/STM32Cube_FW/hw_ipcc.c create mode 100644 src/utility/STM32Cube_FW/mbox_def.h create mode 100644 src/utility/STM32Cube_FW/shci.c create mode 100644 src/utility/STM32Cube_FW/shci.h create mode 100644 src/utility/STM32Cube_FW/shci_tl.c create mode 100644 src/utility/STM32Cube_FW/shci_tl.h create mode 100644 src/utility/STM32Cube_FW/stm32_wpan_common.h create mode 100644 src/utility/STM32Cube_FW/stm_list.c create mode 100644 src/utility/STM32Cube_FW/stm_list.h create mode 100644 src/utility/STM32Cube_FW/tl.h create mode 100644 src/utility/STM32Cube_FW/tl_mbox.c diff --git a/src/utility/STM32Cube_FW/README.md b/src/utility/STM32Cube_FW/README.md new file mode 100644 index 00000000..880fcbbc --- /dev/null +++ b/src/utility/STM32Cube_FW/README.md @@ -0,0 +1,6 @@ + +## Source + +[STMicroelectronics/STM32CubeWB Release v1.8.0](https://github.com/STMicroelectronics/STM32CubeWB/releases/tag/v1.8.0) +- Application: [BLE_TransparentMode](https://github.com/STMicroelectronics/STM32CubeWB/tree/v1.8.0/Projects/P-NUCLEO-WB55.Nucleo/Applications/BLE/BLE_TransparentMode) + diff --git a/src/utility/STM32Cube_FW/app_conf.h b/src/utility/STM32Cube_FW/app_conf.h new file mode 100644 index 00000000..22c7b5c5 --- /dev/null +++ b/src/utility/STM32Cube_FW/app_conf.h @@ -0,0 +1,535 @@ +/** + ****************************************************************************** + * File Name : app_conf.h + * Description : Application configuration file for STM32WPAN Middleware. + ****************************************************************************** + * @attention + * + * <h2><center>© Copyright (c) 2020 STMicroelectronics. + * All rights reserved.</center></h2> + * + * This software component is licensed by ST under Ultimate Liberty license + * SLA0044, the "License"; You may not use this file except in compliance with + * the License. You may obtain a copy of the License at: + * www.st.com/SLA0044 + * + ****************************************************************************** + */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef APP_CONF_H +#define APP_CONF_H + +#include "hw.h" +#include "ble_bufsize.h" + + +/****************************************************************************** + * Application Config + ******************************************************************************/ + +/**< generic parameters ******************************************************/ + +/** + * Define Tx Power + */ +#define CFG_TX_POWER (0x18) /* -0.15dBm */ + +/** + * Define Advertising parameters + */ +#define CFG_ADV_BD_ADDRESS (0x7257acd87a6c) +#define CFG_FAST_CONN_ADV_INTERVAL_MIN (0x80) /**< 80ms */ +#define CFG_FAST_CONN_ADV_INTERVAL_MAX (0xa0) /**< 100ms */ +#define CFG_LP_CONN_ADV_INTERVAL_MIN (0x640) /**< 1s */ +#define CFG_LP_CONN_ADV_INTERVAL_MAX (0xfa0) /**< 2.5s */ + +/** + * Define IO Authentication + */ +#define CFG_BONDING_MODE (1) +#define CFG_FIXED_PIN (111111) +#define CFG_USED_FIXED_PIN (0) +#define CFG_ENCRYPTION_KEY_SIZE_MAX (16) +#define CFG_ENCRYPTION_KEY_SIZE_MIN (8) + +/** + * Define IO capabilities + */ +#define CFG_IO_CAPABILITY_DISPLAY_ONLY (0x00) +#define CFG_IO_CAPABILITY_DISPLAY_YES_NO (0x01) +#define CFG_IO_CAPABILITY_KEYBOARD_ONLY (0x02) +#define CFG_IO_CAPABILITY_NO_INPUT_NO_OUTPUT (0x03) +#define CFG_IO_CAPABILITY_KEYBOARD_DISPLAY (0x04) + +#define CFG_IO_CAPABILITY CFG_IO_CAPABILITY_DISPLAY_YES_NO + +/** + * Define MITM modes + */ +#define CFG_MITM_PROTECTION_NOT_REQUIRED (0x00) +#define CFG_MITM_PROTECTION_REQUIRED (0x01) + +#define CFG_MITM_PROTECTION CFG_MITM_PROTECTION_REQUIRED + +/** + * Define Secure Connections Support + */ +#define CFG_SECURE_NOT_SUPPORTED (0x00) +#define CFG_SECURE_OPTIONAL (0x01) +#define CFG_SECURE_MANDATORY (0x02) + +#define CFG_SC_SUPPORT CFG_SECURE_OPTIONAL + +/** + * Define Keypress Notification Support + */ +#define CFG_KEYPRESS_NOT_SUPPORTED (0x00) +#define CFG_KEYPRESS_SUPPORTED (0x01) + +#define CFG_KEYPRESS_NOTIFICATION_SUPPORT CFG_KEYPRESS_NOT_SUPPORTED + +/** + * Numeric Comparison Answers + */ +#define YES (0x01) +#define NO (0x00) + +/** + * Device name configuration for Generic Access Service + */ +#define CFG_GAP_DEVICE_NAME "TEMPLATE" +#define CFG_GAP_DEVICE_NAME_LENGTH (8) + +/** + * Define PHY + */ +#define ALL_PHYS_PREFERENCE 0x00 +#define RX_2M_PREFERRED 0x02 +#define TX_2M_PREFERRED 0x02 +#define TX_1M 0x01 +#define TX_2M 0x02 +#define RX_1M 0x01 +#define RX_2M 0x02 + +/** +* Identity root key used to derive LTK and CSRK +*/ +#define CFG_BLE_IRK {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0} + +/** +* Encryption root key used to derive LTK and CSRK +*/ +#define CFG_BLE_ERK {0xfe,0xdc,0xba,0x09,0x87,0x65,0x43,0x21,0xfe,0xdc,0xba,0x09,0x87,0x65,0x43,0x21} + +/* USER CODE BEGIN Generic_Parameters */ +/** + * SMPS supply + * SMPS not used when Set to 0 + * SMPS used when Set to 1 + */ +#define CFG_USE_SMPS 1 +/* USER CODE END Generic_Parameters */ + +/**< specific parameters */ +/*****************************************************/ + +/** +* AD Element - Group B Feature +*/ +/* LSB - Second Byte */ +#define CFG_FEATURE_OTA_REBOOT (0x20) + +/****************************************************************************** + * BLE Stack + ******************************************************************************/ +/** + * Maximum number of simultaneous connections that the device will support. + * Valid values are from 1 to 8 + */ +#define CFG_BLE_NUM_LINK 8 + +/** + * Maximum number of Services that can be stored in the GATT database. + * Note that the GAP and GATT services are automatically added so this parameter should be 2 plus the number of user services + */ +#define CFG_BLE_NUM_GATT_SERVICES 8 + +/** + * Maximum number of Attributes + * (i.e. the number of characteristic + the number of characteristic values + the number of descriptors, excluding the services) + * that can be stored in the GATT database. + * Note that certain characteristics and relative descriptors are added automatically during device initialization + * so this parameters should be 9 plus the number of user Attributes + */ +#define CFG_BLE_NUM_GATT_ATTRIBUTES 68 + +/** + * Maximum supported ATT_MTU size + */ +#define CFG_BLE_MAX_ATT_MTU (156) + +/** + * Size of the storage area for Attribute values + * This value depends on the number of attributes used by application. In particular the sum of the following quantities (in octets) should be made for each attribute: + * - attribute value length + * - 5, if UUID is 16 bit; 19, if UUID is 128 bit + * - 2, if server configuration descriptor is used + * - 2*DTM_NUM_LINK, if client configuration descriptor is used + * - 2, if extended properties is used + * The total amount of memory needed is the sum of the above quantities for each attribute. + */ +#define CFG_BLE_ATT_VALUE_ARRAY_SIZE (1344) + +/** + * Prepare Write List size in terms of number of packet + */ +//#define CFG_BLE_PREPARE_WRITE_LIST_SIZE BLE_PREP_WRITE_X_ATT(CFG_BLE_MAX_ATT_MTU) +#define CFG_BLE_PREPARE_WRITE_LIST_SIZE (0x3A) + +/** + * Number of allocated memory blocks + */ +//#define CFG_BLE_MBLOCK_COUNT (BLE_MBLOCKS_CALC(CFG_BLE_PREPARE_WRITE_LIST_SIZE, CFG_BLE_MAX_ATT_MTU, CFG_BLE_NUM_LINK)) +#define CFG_BLE_MBLOCK_COUNT (0x79) +/** + * Enable or disable the Extended Packet length feature. Valid values are 0 or 1. + */ +#define CFG_BLE_DATA_LENGTH_EXTENSION 1 + +/** + * Sleep clock accuracy in Slave mode (ppm value) + */ +#define CFG_BLE_SLAVE_SCA 500 + +/** + * Sleep clock accuracy in Master mode + * 0 : 251 ppm to 500 ppm + * 1 : 151 ppm to 250 ppm + * 2 : 101 ppm to 150 ppm + * 3 : 76 ppm to 100 ppm + * 4 : 51 ppm to 75 ppm + * 5 : 31 ppm to 50 ppm + * 6 : 21 ppm to 30 ppm + * 7 : 0 ppm to 20 ppm + */ +#define CFG_BLE_MASTER_SCA 0 + +/** + * Source for the 32 kHz slow speed clock + * 1 : internal RO + * 0 : external crystal ( no calibration ) + */ +#define CFG_BLE_LSE_SOURCE 0 + +/** + * Start up time of the high speed (16 or 32 MHz) crystal oscillator in units of 625/256 us (~2.44 us) + */ +#define CFG_BLE_HSE_STARTUP_TIME 0x148 + +/** + * Maximum duration of the connection event when the device is in Slave mode in units of 625/256 us (~2.44 us) + */ +#define CFG_BLE_MAX_CONN_EVENT_LENGTH ( 0xFFFFFFFF ) + +/** + * Viterbi Mode + * 1 : enabled + * 0 : disabled + */ +#define CFG_BLE_VITERBI_MODE 1 + +/** + * LL Only Mode + * 1 : LL Only + * 0 : LL + Host + */ +#define CFG_BLE_LL_ONLY 1 +/****************************************************************************** + * Transport Layer + ******************************************************************************/ +/** + * Queue length of BLE Event + * This parameter defines the number of asynchronous events that can be stored in the HCI layer before + * being reported to the application. When a command is sent to the BLE core coprocessor, the HCI layer + * is waiting for the event with the Num_HCI_Command_Packets set to 1. The receive queue shall be large + * enough to store all asynchronous events received in between. + * When CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE is set to 27, this allow to store three 255 bytes long asynchronous events + * between the HCI command and its event. + * This parameter depends on the value given to CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE. When the queue size is to small, + * the system may hang if the queue is full with asynchronous events and the HCI layer is still waiting + * for a CC/CS event, In that case, the notification TL_BLE_HCI_ToNot() is called to indicate + * to the application a HCI command did not receive its command event within 30s (Default HCI Timeout). + */ +#define CFG_TLBLE_EVT_QUEUE_LENGTH 5 +/** + * This parameter should be set to fit most events received by the HCI layer. It defines the buffer size of each element + * allocated in the queue of received events and can be used to optimize the amount of RAM allocated by the Memory Manager. + * It should not exceed 255 which is the maximum HCI packet payload size (a greater value is a lost of memory as it will + * never be used) + * It shall be at least 4 to receive the command status event in one frame. + * The default value is set to 27 to allow receiving an event of MTU size in a single buffer. This value maybe reduced + * further depending on the application. + * + */ +#define CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE 255 /**< Set to 255 with the memory manager and the mailbox */ + +#define TL_BLE_EVENT_FRAME_SIZE ( TL_EVT_HDR_SIZE + CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE ) +/****************************************************************************** + * UART interfaces + ******************************************************************************/ + +/** + * Select UART interfaces + */ +#define CFG_DEBUG_TRACE_UART hw_uart1 +#define CFG_CONSOLE_MENU 0 +/****************************************************************************** + * USB interface + ******************************************************************************/ + +/** + * Enable/Disable USB interface + */ +#define CFG_USB_INTERFACE_ENABLE 0 + +/****************************************************************************** + * Low Power + ******************************************************************************/ +/** + * When set to 1, the low power mode is enable + * When set to 0, the device stays in RUN mode + */ +#define CFG_LPM_SUPPORTED 1 + +/****************************************************************************** + * Timer Server + ******************************************************************************/ +/** + * CFG_RTC_WUCKSEL_DIVIDER: This sets the RTCCLK divider to the wakeup timer. + * The higher is the value, the better is the power consumption and the accuracy of the timerserver + * The lower is the value, the finest is the granularity + * + * CFG_RTC_ASYNCH_PRESCALER: This sets the asynchronous prescaler of the RTC. It should as high as possible ( to output + * clock as low as possible) but the output clock should be equal or higher frequency compare to the clock feeding + * the wakeup timer. A lower clock speed would impact the accuracy of the timer server. + * + * CFG_RTC_SYNCH_PRESCALER: This sets the synchronous prescaler of the RTC. + * When the 1Hz calendar clock is required, it shall be sets according to other settings + * When the 1Hz calendar clock is not needed, CFG_RTC_SYNCH_PRESCALER should be set to 0x7FFF (MAX VALUE) + * + * CFG_RTCCLK_DIVIDER_CONF: + * Shall be set to either 0,2,4,8,16 + * When set to either 2,4,8,16, the 1Hhz calendar is supported + * When set to 0, the user sets its own configuration + * + * The following settings are computed with LSI as input to the RTC + */ +#define CFG_RTCCLK_DIVIDER_CONF 0 + +#if (CFG_RTCCLK_DIVIDER_CONF == 0) + /** + * Custom configuration + * It does not support 1Hz calendar + * It divides the RTC CLK by 16 + */ + #define CFG_RTCCLK_DIV (16) + #define CFG_RTC_WUCKSEL_DIVIDER (0) + #define CFG_RTC_ASYNCH_PRESCALER (CFG_RTCCLK_DIV - 1) + #define CFG_RTC_SYNCH_PRESCALER (0x7FFF) + +#else + + #if (CFG_RTCCLK_DIVIDER_CONF == 2) + /** + * It divides the RTC CLK by 2 + */ + #define CFG_RTC_WUCKSEL_DIVIDER (3) + #endif + + #if (CFG_RTCCLK_DIVIDER_CONF == 4) + /** + * It divides the RTC CLK by 4 + */ + #define CFG_RTC_WUCKSEL_DIVIDER (2) + #endif + + #if (CFG_RTCCLK_DIVIDER_CONF == 8) + /** + * It divides the RTC CLK by 8 + */ + #define CFG_RTC_WUCKSEL_DIVIDER (1) + #endif + + #if (CFG_RTCCLK_DIVIDER_CONF == 16) + /** + * It divides the RTC CLK by 16 + */ + #define CFG_RTC_WUCKSEL_DIVIDER (0) + #endif + + #define CFG_RTCCLK_DIV CFG_RTCCLK_DIVIDER_CONF + #define CFG_RTC_ASYNCH_PRESCALER (CFG_RTCCLK_DIV - 1) + #define CFG_RTC_SYNCH_PRESCALER (DIVR( LSE_VALUE, (CFG_RTC_ASYNCH_PRESCALER+1) ) - 1 ) + +#endif + +/** tick timer value in us */ +#define CFG_TS_TICK_VAL DIVR( (CFG_RTCCLK_DIV * 1000000), LSE_VALUE ) + +typedef enum { + CFG_TIM_PROC_ID_ISR, +} CFG_TimProcID_t; + +/****************************************************************************** + * Debug + ******************************************************************************/ +/** + * When set, this resets some hw resources to set the device in the same state than the power up + * The FW resets only register that may prevent the FW to run properly + * + * This shall be set to 0 in a final product + * + */ +#define CFG_HW_RESET_BY_FW 1 + +/** + * keep debugger enabled while in any low power mode when set to 1 + * should be set to 0 in production + */ +#define CFG_DEBUGGER_SUPPORTED 0 + +/** + * When set to 1, the traces are enabled in the BLE services + */ +#define CFG_DEBUG_BLE_TRACE 0 + +/** + * Enable or Disable traces in application + */ +#define CFG_DEBUG_APP_TRACE 0 + +#if (CFG_DEBUG_APP_TRACE != 0) + #define APP_DBG_MSG PRINT_MESG_DBG +#else + #define APP_DBG_MSG PRINT_NO_MESG +#endif + +#if ( (CFG_DEBUG_BLE_TRACE != 0) || (CFG_DEBUG_APP_TRACE != 0) ) + #define CFG_DEBUG_TRACE 1 +#endif + +#if (CFG_DEBUG_TRACE != 0) + #undef CFG_LPM_SUPPORTED + #undef CFG_DEBUGGER_SUPPORTED + #define CFG_LPM_SUPPORTED 0 + #define CFG_DEBUGGER_SUPPORTED 1 +#endif + +/** + * When CFG_DEBUG_TRACE_FULL is set to 1, the trace are output with the API name, the file name and the line number + * When CFG_DEBUG_TRACE_LIGHT is set to 1, only the debug message is output + * + * When both are set to 0, no trace are output + * When both are set to 1, CFG_DEBUG_TRACE_FULL is selected + */ +#define CFG_DEBUG_TRACE_LIGHT 0 +#define CFG_DEBUG_TRACE_FULL 0 + +#if (( CFG_DEBUG_TRACE != 0 ) && ( CFG_DEBUG_TRACE_LIGHT == 0 ) && (CFG_DEBUG_TRACE_FULL == 0)) + #undef CFG_DEBUG_TRACE_FULL + #undef CFG_DEBUG_TRACE_LIGHT + #define CFG_DEBUG_TRACE_FULL 0 + #define CFG_DEBUG_TRACE_LIGHT 1 +#endif + +#if ( CFG_DEBUG_TRACE == 0 ) + #undef CFG_DEBUG_TRACE_FULL + #undef CFG_DEBUG_TRACE_LIGHT + #define CFG_DEBUG_TRACE_FULL 0 + #define CFG_DEBUG_TRACE_LIGHT 0 +#endif + +/** + * When not set, the traces is looping on sending the trace over UART + */ +#define DBG_TRACE_USE_CIRCULAR_QUEUE 1 + +/** + * max buffer Size to queue data traces and max data trace allowed. + * Only Used if DBG_TRACE_USE_CIRCULAR_QUEUE is defined + */ +#define DBG_TRACE_MSG_QUEUE_SIZE 4096 +#define MAX_DBG_TRACE_MSG_SIZE 1024 + +/* USER CODE BEGIN Defines */ +#define CFG_LED_SUPPORTED 0 +#define CFG_BUTTON_SUPPORTED 1 +/* USER CODE END Defines */ + +/****************************************************************************** + * FreeRTOS + ******************************************************************************/ +#define CFG_SHCI_USER_EVT_PROCESS_NAME "SHCI_USER_EVT_PROCESS" +#define CFG_SHCI_USER_EVT_PROCESS_ATTR_BITS (0) +#define CFG_SHCI_USER_EVT_PROCESS_CB_MEM (0) +#define CFG_SHCI_USER_EVT_PROCESS_CB_SIZE (0) +#define CFG_SHCI_USER_EVT_PROCESS_STACK_MEM (0) +#define CFG_SHCI_USER_EVT_PROCESS_PRIORITY osPriorityNone +#define CFG_SHCI_USER_EVT_PROCESS_STACK_SIZE (128 * 7) + +#define CFG_HCI_USER_EVT_PROCESS_NAME "HCI_USER_EVT_PROCESS" +#define CFG_HCI_USER_EVT_PROCESS_ATTR_BITS (0) +#define CFG_HCI_USER_EVT_PROCESS_CB_MEM (0) +#define CFG_HCI_USER_EVT_PROCESS_CB_SIZE (0) +#define CFG_HCI_USER_EVT_PROCESS_STACK_MEM (0) +#define CFG_HCI_USER_EVT_PROCESS_PRIORITY osPriorityNone +#define CFG_HCI_USER_EVT_PROCESS_STACK_SIZE (128 * 8) + +#define CFG_ADV_UPDATE_PROCESS_NAME "ADV_UPDATE_PROCESS" +#define CFG_ADV_UPDATE_PROCESS_ATTR_BITS (0) +#define CFG_ADV_UPDATE_PROCESS_CB_MEM (0) +#define CFG_ADV_UPDATE_PROCESS_CB_SIZE (0) +#define CFG_ADV_UPDATE_PROCESS_STACK_MEM (0) +#define CFG_ADV_UPDATE_PROCESS_PRIORITY osPriorityNone +#define CFG_ADV_UPDATE_PROCESS_STACK_SIZE (128 * 6) + +#define CFG_HRS_PROCESS_NAME "HRS_PROCESS" +#define CFG_HRS_PROCESS_ATTR_BITS (0) +#define CFG_HRS_PROCESS_CB_MEM (0) +#define CFG_HRS_PROCESS_CB_SIZE (0) +#define CFG_HRS_PROCESS_STACK_MEM (0) +#define CFG_HRS_PROCESS_PRIORITY osPriorityNone +#define CFG_HRS_PROCESS_STACK_SIZE (128 * 5) + +/* USER CODE BEGIN FreeRTOS_Defines */ +#define PUSH_BUTTON_SW1_EXTI_IRQHandler EXTI4_IRQHandler +#define PUSH_BUTTON_SW2_EXTI_IRQHandler EXTI0_IRQHandler +#define PUSH_BUTTON_SW3_EXTI_IRQHandler EXTI1_IRQHandler +/* USER CODE END FreeRTOS_Defines */ + +/****************************************************************************** + * LOW POWER + ******************************************************************************/ +/** + * Supported requester to the MCU Low Power Manager - can be increased up to 32 + * It lists a bit mapping of all user of the Low Power Manager + */ +typedef enum { + CFG_LPM_APP, + CFG_LPM_APP_BLE, + /* USER CODE BEGIN CFG_LPM_Id_t */ + + /* USER CODE END CFG_LPM_Id_t */ +} CFG_LPM_Id_t; + +/****************************************************************************** + * OTP manager + ******************************************************************************/ +#define CFG_OTP_BASE_ADDRESS OTP_AREA_BASE + +#define CFG_OTP_END_ADRESS OTP_AREA_END_ADDR + +#endif /*APP_CONF_H */ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/src/utility/STM32Cube_FW/ble_bufsize.h b/src/utility/STM32Cube_FW/ble_bufsize.h new file mode 100644 index 00000000..2961cd99 --- /dev/null +++ b/src/utility/STM32Cube_FW/ble_bufsize.h @@ -0,0 +1,161 @@ +/***************************************************************************** + * @file ble_bufsize.h + * @author MCD Application Team + * @brief Definition of BLE stack buffers size + ***************************************************************************** + * @attention + * + * <h2><center>© Copyright (c) 2019 STMicroelectronics. + * All rights reserved.</center></h2> + * + * This software component is licensed by ST under Ultimate Liberty license + * SLA0044, the "License"; You may not use this file except in compliance with + * the License. You may obtain a copy of the License at: + * www.st.com/SLA0044 + * + ***************************************************************************** + */ + +#ifndef BLE_BUFSIZE_H__ +#define BLE_BUFSIZE_H__ + + +/* + * BLE_DEFAULT_ATT_MTU: minimum MTU value that GATT must support. + */ +#define BLE_DEFAULT_ATT_MTU 23 + +/* + * BLE_DEFAULT_MAX_ATT_MTU: maximum supported ATT MTU size. + */ +#define BLE_DEFAULT_MAX_ATT_MTU 158 + +/* + * BLE_DEFAULT_MAX_ATT_SIZE: maximum attribute size. + */ +#define BLE_DEFAULT_MAX_ATT_SIZE 512 + +/* + * BLE_PREP_WRITE_X_ATT: compute how many Prepare Write Request are needed to + * write a characteristic with size 'max_att' when the used ATT_MTU value is + * equal to BLE_DEFAULT_ATT_MTU (23). + */ +#define BLE_PREP_WRITE_X_ATT(max_att) \ + (DIVC(max_att, BLE_DEFAULT_ATT_MTU - 5) * 2) + +/* + * BLE_DEFAULT_PREP_WRITE_LIST_SIZE: default minimum Prepare Write List size. + */ +#define BLE_DEFAULT_PREP_WRITE_LIST_SIZE \ + BLE_PREP_WRITE_X_ATT(BLE_DEFAULT_MAX_ATT_SIZE) + +/* + * BLE_MEM_BLOCK_X_MTU: compute how many memory blocks are needed to compose + * an ATT packet with ATT_MTU=mtu. + */ +#define BLE_MEM_BLOCK_SIZE 32 + +#define BLE_MEM_BLOCK_X_TX(mtu) \ + (DIVC((mtu) + 4U, BLE_MEM_BLOCK_SIZE) + 1U) + +#define BLE_MEM_BLOCK_X_RX(mtu, n_link) \ + ((DIVC((mtu) + 4U, BLE_MEM_BLOCK_SIZE) + 2U) * (n_link) + 1) + +#define BLE_MEM_BLOCK_X_MTU(mtu, n_link) \ + (BLE_MEM_BLOCK_X_TX(mtu) + BLE_MEM_BLOCK_X_RX(mtu, n_link)) + +/* + * BLE_MBLOCKS_SECURE_CONNECTIONS: minimum number of blocks required for + * secure connections + */ +#define BLE_MBLOCKS_SECURE_CONNECTIONS 4 + +/* + * BLE_MBLOCKS_CALC: minimum number of buffers needed by the stack. + * This is the minimum racomanded value and depends on: + * - pw: size of Prepare Write List + * - mtu: ATT_MTU size + * - n_link: maximum number of simultaneous connections + */ +#define BLE_MBLOCKS_CALC(pw, mtu, n_link) \ + ((pw) + MAX(BLE_MEM_BLOCK_X_MTU(mtu, n_link), \ + BLE_MBLOCKS_SECURE_CONNECTIONS)) + +/* + * BLE_DEFAULT_MBLOCKS_COUNT: default memory blocks count + */ +#define BLE_DEFAULT_MBLOCKS_COUNT(n_link) \ + BLE_MBLOCKS_CALC(BLE_DEFAULT_PREP_WRITE_LIST_SIZE, \ + BLE_DEFAULT_MAX_ATT_MTU, n_link) + +/* + * BLE_FIXED_BUFFER_SIZE_BYTES: + * A part of the RAM, is dynamically allocated by initializing all the pointers + * defined in a global context variable "mem_alloc_ctx_p". + * This initialization is made in the Dynamic_allocator functions, which + * assign a portion of RAM given by the external application to the above + * mentioned "global pointers". + * + * The size of this Dynamic RAM is made of 2 main components: + * - a part that is parameters-dependent (num of links, GATT buffers, ...), + * and which value is defined by the following macro; + * - a part, that may be considered "fixed", i.e. independent from the above + * mentioned parameters. +*/ +#if (SLAVE_ONLY == 0) && (LL_ONLY == 0) + #define BLE_FIXED_BUFFER_SIZE_BYTES 6960 /* Full stack */ +#elif SLAVE_ONLY == 0 + #define BLE_FIXED_BUFFER_SIZE_BYTES 6256 /* LL only */ +#else + #define BLE_FIXED_BUFFER_SIZE_BYTES 6696 /* Slave only */ +#endif + +/* + * BLE_PER_LINK_SIZE_BYTES: additional memory size used per link + */ +#if (SLAVE_ONLY == 0) && (LL_ONLY == 0) + #define BLE_PER_LINK_SIZE_BYTES 380 /* Full stack */ +#elif SLAVE_ONLY == 0 + #define BLE_PER_LINK_SIZE_BYTES 196 /* LL only */ +#else + #define BLE_PER_LINK_SIZE_BYTES 332 /* Slave only */ +#endif + +/* + * BLE_TOTAL_BUFFER_SIZE: this macro returns the amount of memory, in bytes, + * needed for the storage of data structures (except GATT database elements) + * whose size depends on the number of supported connections. + * + * @param num_links: Maximum number of simultaneous connections that the device + * will support. Valid values are from 1 to 8. + * + * @param mblocks_count: Number of memory blocks allocated for packets. + */ +#define BLE_TOTAL_BUFFER_SIZE(n_link, mblocks_count) \ + (BLE_FIXED_BUFFER_SIZE_BYTES + \ + (BLE_PER_LINK_SIZE_BYTES * (n_link)) + \ + ((BLE_MEM_BLOCK_SIZE + 12) * (mblocks_count))) + +/* + * BLE_TOTAL_BUFFER_SIZE_GATT: this macro returns the amount of memory, + * in bytes, needed for the storage of GATT database elements. + * + * @param num_gatt_attributes: Maximum number of Attributes (i.e. the number + * of characteristic + the number of characteristic values + the number of + * descriptors, excluding the services) that can be stored in the GATT + * database. Note that certain characteristics and relative descriptors are + * added automatically during device initialization so this parameters should + * be 9 plus the number of user Attributes + * + * @param num_gatt_services: Maximum number of Services that can be stored in + * the GATT database. Note that the GAP and GATT services are automatically + * added so this parameter should be 2 plus the number of user services + * + * @param att_value_array_size: Size of the storage area for Attribute values. + */ +#define BLE_TOTAL_BUFFER_SIZE_GATT(num_gatt_attributes, num_gatt_services, att_value_array_size) \ + (((((att_value_array_size) - 1) | 3) + 1) + \ + (40 * (num_gatt_attributes)) + (48 * (num_gatt_services))) + + +#endif /* ! BLE_BUFSIZE_H__ */ diff --git a/src/utility/STM32Cube_FW/hw.h b/src/utility/STM32Cube_FW/hw.h new file mode 100644 index 00000000..09b12aff --- /dev/null +++ b/src/utility/STM32Cube_FW/hw.h @@ -0,0 +1,97 @@ +/** + ****************************************************************************** + * @file hw.h + * @author MCD Application Team + * @brief Hardware + ****************************************************************************** + * @attention + * + * <h2><center>© Copyright (c) 2019 STMicroelectronics. + * All rights reserved.</center></h2> + * + * This software component is licensed by ST under BSD 3-Clause license, + * the "License"; You may not use this file except in compliance with the + * License. You may obtain a copy of the License at: + * opensource.org/licenses/BSD-3-Clause + * + ****************************************************************************** + */ + + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __HW_H +#define __HW_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include "stm32_def.h" +#include "stm32wbxx_ll_bus.h" +#include "stm32wbxx_ll_exti.h" +#include "stm32wbxx_ll_system.h" +#include "stm32wbxx_ll_rcc.h" +#include "stm32wbxx_ll_ipcc.h" +#include "stm32wbxx_ll_cortex.h" +#include "stm32wbxx_ll_utils.h" +#include "stm32wbxx_ll_pwr.h" + +/****************************************************************************** + * HW IPCC + ******************************************************************************/ +void HW_IPCC_Enable(void); +void HW_IPCC_Init(void); + +void HW_IPCC_BLE_Init(void); +void HW_IPCC_BLE_SendCmd(void); +void HW_IPCC_MM_SendFreeBuf(void (*cb)(void)); +void HW_IPCC_BLE_RxEvtNot(void); +void HW_IPCC_BLE_SendAclData(void); +void HW_IPCC_BLE_AclDataAckNot(void); + +void HW_IPCC_SYS_Init(void); +void HW_IPCC_SYS_SendCmd(void); +void HW_IPCC_SYS_CmdEvtNot(void); +void HW_IPCC_SYS_EvtNot(void); + +void HW_IPCC_THREAD_Init(void); +void HW_IPCC_OT_SendCmd(void); +void HW_IPCC_CLI_SendCmd(void); +void HW_IPCC_THREAD_SendAck(void); +void HW_IPCC_OT_CmdEvtNot(void); +void HW_IPCC_CLI_CmdEvtNot(void); +void HW_IPCC_THREAD_EvtNot(void); +void HW_IPCC_THREAD_CliSendAck(void); +void HW_IPCC_THREAD_CliEvtNot(void); + + +void HW_IPCC_LLDTESTS_Init(void); +void HW_IPCC_LLDTESTS_SendCliCmd(void); +void HW_IPCC_LLDTESTS_ReceiveCliRsp(void); +void HW_IPCC_LLDTESTS_SendCliRspAck(void); +void HW_IPCC_LLDTESTS_ReceiveM0Cmd(void); +void HW_IPCC_LLDTESTS_SendM0CmdAck(void); + + +void HW_IPCC_LLD_BLE_Init(void); +void HW_IPCC_LLD_BLE_SendCliCmd(void); +void HW_IPCC_LLD_BLE_ReceiveCliRsp(void); +void HW_IPCC_LLD_BLE_SendCliRspAck(void); +void HW_IPCC_LLD_BLE_ReceiveM0Cmd(void); +void HW_IPCC_LLD_BLE_SendM0CmdAck(void); +void HW_IPCC_LLD_BLE_SendCmd(void); +void HW_IPCC_LLD_BLE_ReceiveRsp(void); +void HW_IPCC_LLD_BLE_SendRspAck(void); + + +void HW_IPCC_TRACES_Init(void); +void HW_IPCC_TRACES_EvtNot(void); + +#ifdef __cplusplus +} +#endif + +#endif /*__HW_H */ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/src/utility/STM32Cube_FW/hw_ipcc.c b/src/utility/STM32Cube_FW/hw_ipcc.c new file mode 100644 index 00000000..dbeb3eeb --- /dev/null +++ b/src/utility/STM32Cube_FW/hw_ipcc.c @@ -0,0 +1,342 @@ +/** + ****************************************************************************** + * File Name : Target/hw_ipcc.c + * Description : Hardware IPCC source file for STM32WPAN Middleware. + * + ****************************************************************************** + * @attention + * + * <h2><center>© Copyright (c) 2020 STMicroelectronics. + * All rights reserved.</center></h2> + * + * This software component is licensed by ST under Ultimate Liberty license + * SLA0044, the "License"; You may not use this file except in compliance with + * the License. You may obtain a copy of the License at: + * www.st.com/SLA0044 + * + ****************************************************************************** + */ +#if defined(STM32WBxx) +/* Includes ------------------------------------------------------------------*/ +#include "hw.h" +#include "mbox_def.h" + +/* Global variables ---------------------------------------------------------*/ +/* Private defines -----------------------------------------------------------*/ +#define HW_IPCC_TX_PENDING( channel ) ( !(LL_C1_IPCC_IsActiveFlag_CHx( IPCC, channel )) ) && (((~(IPCC->C1MR)) & (channel << 16U))) +#define HW_IPCC_RX_PENDING( channel ) (LL_C2_IPCC_IsActiveFlag_CHx( IPCC, channel )) && (((~(IPCC->C1MR)) & (channel << 0U))) + +/* Private macros ------------------------------------------------------------*/ +/* Private typedef -----------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +static void (*FreeBufCb)(void); + +/* Private function prototypes -----------------------------------------------*/ +static void HW_IPCC_BLE_EvtHandler(void); +static void HW_IPCC_BLE_AclDataEvtHandler(void); +static void HW_IPCC_MM_FreeBufHandler(void); +static void HW_IPCC_SYS_CmdEvtHandler(void); +static void HW_IPCC_SYS_EvtHandler(void); +static void HW_IPCC_TRACES_EvtHandler(void); + +#ifdef THREAD_WB + static void HW_IPCC_OT_CmdEvtHandler(void); + static void HW_IPCC_THREAD_NotEvtHandler(void); + static void HW_IPCC_THREAD_CliNotEvtHandler(void); +#endif + +/* Public function definition -----------------------------------------------*/ + +/****************************************************************************** + * INTERRUPT HANDLER + ******************************************************************************/ + +void IPCC_C1_RX_IRQHandler(void) +{ + if (HW_IPCC_RX_PENDING(HW_IPCC_SYSTEM_EVENT_CHANNEL)) { + HW_IPCC_SYS_EvtHandler(); + } +#ifdef THREAD_WB + else if (HW_IPCC_RX_PENDING(HW_IPCC_THREAD_NOTIFICATION_ACK_CHANNEL)) { + HW_IPCC_THREAD_NotEvtHandler(); + } else if (HW_IPCC_RX_PENDING(HW_IPCC_THREAD_CLI_NOTIFICATION_ACK_CHANNEL)) { + HW_IPCC_THREAD_CliNotEvtHandler(); + } +#endif /* THREAD_WB */ + else if (HW_IPCC_RX_PENDING(HW_IPCC_BLE_EVENT_CHANNEL)) { + HW_IPCC_BLE_EvtHandler(); + } else if (HW_IPCC_RX_PENDING(HW_IPCC_TRACES_CHANNEL)) { + HW_IPCC_TRACES_EvtHandler(); + } +} + +void IPCC_C1_TX_IRQHandler(void) +{ + if (HW_IPCC_TX_PENDING(HW_IPCC_SYSTEM_CMD_RSP_CHANNEL)) { + HW_IPCC_SYS_CmdEvtHandler(); + } +#ifdef THREAD_WB + else if (HW_IPCC_TX_PENDING(HW_IPCC_THREAD_OT_CMD_RSP_CHANNEL)) { + HW_IPCC_OT_CmdEvtHandler(); + } +#endif /* THREAD_WB */ + else if (HW_IPCC_TX_PENDING(HW_IPCC_SYSTEM_CMD_RSP_CHANNEL)) { + HW_IPCC_SYS_CmdEvtHandler(); + } else if (HW_IPCC_TX_PENDING(HW_IPCC_MM_RELEASE_BUFFER_CHANNEL)) { + HW_IPCC_MM_FreeBufHandler(); + } else if (HW_IPCC_TX_PENDING(HW_IPCC_HCI_ACL_DATA_CHANNEL)) { + HW_IPCC_BLE_AclDataEvtHandler(); + } +} + +/****************************************************************************** + * GENERAL + ******************************************************************************/ +void HW_IPCC_Enable(void) +{ + /** + * When the device is out of standby, it is required to use the EXTI mechanism to wakeup CPU2 + */ + LL_C2_EXTI_EnableEvent_32_63(LL_EXTI_LINE_41); + LL_EXTI_EnableRisingTrig_32_63(LL_EXTI_LINE_41); + + /** + * In case the SBSFU is implemented, it may have already set the C2BOOT bit to startup the CPU2. + * In that case, to keep the mechanism transparent to the user application, it shall call the system command + * SHCI_C2_Reinit( ) before jumping to the application. + * When the CPU2 receives that command, it waits for its event input to be set to restart the CPU2 firmware. + * This is required because once C2BOOT has been set once, a clear/set on C2BOOT has no effect. + * When SHCI_C2_Reinit( ) is not called, generating an event to the CPU2 does not have any effect + * So, by default, the application shall both set the event flag and set the C2BOOT bit. + */ + __SEV(); /* Set the internal event flag and send an event to the CPU2 */ + __WFE(); /* Clear the internal event flag */ + LL_PWR_EnableBootC2(); + + return; +} + +void HW_IPCC_Init(void) +{ + LL_AHB3_GRP1_EnableClock(LL_AHB3_GRP1_PERIPH_IPCC); + + LL_C1_IPCC_EnableIT_RXO(IPCC); + LL_C1_IPCC_EnableIT_TXF(IPCC); + + HAL_NVIC_EnableIRQ(IPCC_C1_RX_IRQn); + HAL_NVIC_EnableIRQ(IPCC_C1_TX_IRQn); + + return; +} + +/****************************************************************************** + * BLE + ******************************************************************************/ +void HW_IPCC_BLE_Init(void) +{ + LL_C1_IPCC_EnableReceiveChannel(IPCC, HW_IPCC_BLE_EVENT_CHANNEL); + + return; +} + +void HW_IPCC_BLE_SendCmd(void) +{ + LL_C1_IPCC_SetFlag_CHx(IPCC, HW_IPCC_BLE_CMD_CHANNEL); + + return; +} + +static void HW_IPCC_BLE_EvtHandler(void) +{ + HW_IPCC_BLE_RxEvtNot(); + + LL_C1_IPCC_ClearFlag_CHx(IPCC, HW_IPCC_BLE_EVENT_CHANNEL); + + return; +} + +void HW_IPCC_BLE_SendAclData(void) +{ + LL_C1_IPCC_SetFlag_CHx(IPCC, HW_IPCC_HCI_ACL_DATA_CHANNEL); + LL_C1_IPCC_EnableTransmitChannel(IPCC, HW_IPCC_HCI_ACL_DATA_CHANNEL); + + return; +} + +static void HW_IPCC_BLE_AclDataEvtHandler(void) +{ + LL_C1_IPCC_DisableTransmitChannel(IPCC, HW_IPCC_HCI_ACL_DATA_CHANNEL); + + HW_IPCC_BLE_AclDataAckNot(); + + return; +} + +__WEAK void HW_IPCC_BLE_AclDataAckNot(void) {}; +__WEAK void HW_IPCC_BLE_RxEvtNot(void) {}; + +/****************************************************************************** + * SYSTEM + ******************************************************************************/ +void HW_IPCC_SYS_Init(void) +{ + LL_C1_IPCC_EnableReceiveChannel(IPCC, HW_IPCC_SYSTEM_EVENT_CHANNEL); + + return; +} + +void HW_IPCC_SYS_SendCmd(void) +{ + LL_C1_IPCC_SetFlag_CHx(IPCC, HW_IPCC_SYSTEM_CMD_RSP_CHANNEL); + LL_C1_IPCC_EnableTransmitChannel(IPCC, HW_IPCC_SYSTEM_CMD_RSP_CHANNEL); + + return; +} + +static void HW_IPCC_SYS_CmdEvtHandler(void) +{ + LL_C1_IPCC_DisableTransmitChannel(IPCC, HW_IPCC_SYSTEM_CMD_RSP_CHANNEL); + + HW_IPCC_SYS_CmdEvtNot(); + + return; +} + +static void HW_IPCC_SYS_EvtHandler(void) +{ + HW_IPCC_SYS_EvtNot(); + + LL_C1_IPCC_ClearFlag_CHx(IPCC, HW_IPCC_SYSTEM_EVENT_CHANNEL); + + return; +} + +__WEAK void HW_IPCC_SYS_CmdEvtNot(void) {}; +__WEAK void HW_IPCC_SYS_EvtNot(void) {}; + +/****************************************************************************** + * THREAD + ******************************************************************************/ +#ifdef THREAD_WB +void HW_IPCC_THREAD_Init(void) +{ + LL_C1_IPCC_EnableReceiveChannel(IPCC, HW_IPCC_THREAD_NOTIFICATION_ACK_CHANNEL); + LL_C1_IPCC_EnableReceiveChannel(IPCC, HW_IPCC_THREAD_CLI_NOTIFICATION_ACK_CHANNEL); + + return; +} + +void HW_IPCC_OT_SendCmd(void) +{ + LL_C1_IPCC_SetFlag_CHx(IPCC, HW_IPCC_THREAD_OT_CMD_RSP_CHANNEL); + LL_C1_IPCC_EnableTransmitChannel(IPCC, HW_IPCC_THREAD_OT_CMD_RSP_CHANNEL); + + return; +} + +void HW_IPCC_CLI_SendCmd(void) +{ + LL_C1_IPCC_SetFlag_CHx(IPCC, HW_IPCC_THREAD_CLI_CMD_CHANNEL); + + return; +} + +void HW_IPCC_THREAD_SendAck(void) +{ + LL_C1_IPCC_ClearFlag_CHx(IPCC, HW_IPCC_THREAD_NOTIFICATION_ACK_CHANNEL); + LL_C1_IPCC_EnableReceiveChannel(IPCC, HW_IPCC_THREAD_NOTIFICATION_ACK_CHANNEL); + + return; +} + +void HW_IPCC_THREAD_CliSendAck(void) +{ + LL_C1_IPCC_ClearFlag_CHx(IPCC, HW_IPCC_THREAD_CLI_NOTIFICATION_ACK_CHANNEL); + LL_C1_IPCC_EnableReceiveChannel(IPCC, HW_IPCC_THREAD_CLI_NOTIFICATION_ACK_CHANNEL); + + return; +} + +static void HW_IPCC_OT_CmdEvtHandler(void) +{ + LL_C1_IPCC_DisableTransmitChannel(IPCC, HW_IPCC_THREAD_OT_CMD_RSP_CHANNEL); + + HW_IPCC_OT_CmdEvtNot(); + + return; +} + +static void HW_IPCC_THREAD_NotEvtHandler(void) +{ + LL_C1_IPCC_DisableReceiveChannel(IPCC, HW_IPCC_THREAD_NOTIFICATION_ACK_CHANNEL); + + HW_IPCC_THREAD_EvtNot(); + + return; +} + +static void HW_IPCC_THREAD_CliNotEvtHandler(void) +{ + LL_C1_IPCC_DisableReceiveChannel(IPCC, HW_IPCC_THREAD_CLI_NOTIFICATION_ACK_CHANNEL); + + HW_IPCC_THREAD_CliEvtNot(); + + return; +} + +__WEAK void HW_IPCC_OT_CmdEvtNot(void) {}; +__WEAK void HW_IPCC_CLI_CmdEvtNot(void) {}; +__WEAK void HW_IPCC_THREAD_EvtNot(void) {}; + +#endif /* THREAD_WB */ + +/****************************************************************************** + * MEMORY MANAGER + ******************************************************************************/ +void HW_IPCC_MM_SendFreeBuf(void (*cb)(void)) +{ + if (LL_C1_IPCC_IsActiveFlag_CHx(IPCC, HW_IPCC_MM_RELEASE_BUFFER_CHANNEL)) { + FreeBufCb = cb; + LL_C1_IPCC_EnableTransmitChannel(IPCC, HW_IPCC_MM_RELEASE_BUFFER_CHANNEL); + } else { + cb(); + + LL_C1_IPCC_SetFlag_CHx(IPCC, HW_IPCC_MM_RELEASE_BUFFER_CHANNEL); + } + + return; +} + +static void HW_IPCC_MM_FreeBufHandler(void) +{ + LL_C1_IPCC_DisableTransmitChannel(IPCC, HW_IPCC_MM_RELEASE_BUFFER_CHANNEL); + + FreeBufCb(); + + LL_C1_IPCC_SetFlag_CHx(IPCC, HW_IPCC_MM_RELEASE_BUFFER_CHANNEL); + + return; +} + +/****************************************************************************** + * TRACES + ******************************************************************************/ +void HW_IPCC_TRACES_Init(void) +{ + LL_C1_IPCC_EnableReceiveChannel(IPCC, HW_IPCC_TRACES_CHANNEL); + + return; +} + +static void HW_IPCC_TRACES_EvtHandler(void) +{ + HW_IPCC_TRACES_EvtNot(); + + LL_C1_IPCC_ClearFlag_CHx(IPCC, HW_IPCC_TRACES_CHANNEL); + + return; +} + +__WEAK void HW_IPCC_TRACES_EvtNot(void) {}; +#endif /* STM32WBxx */ +/******************* (C) COPYRIGHT 2019 STMicroelectronics *****END OF FILE****/ diff --git a/src/utility/STM32Cube_FW/mbox_def.h b/src/utility/STM32Cube_FW/mbox_def.h new file mode 100644 index 00000000..d5a7d46b --- /dev/null +++ b/src/utility/STM32Cube_FW/mbox_def.h @@ -0,0 +1,212 @@ +/** + ****************************************************************************** + * @file mbox_def.h + * @author MCD Application Team + * @brief Mailbox definition + ****************************************************************************** + * @attention + * + * <h2><center>© Copyright (c) 2019 STMicroelectronics. + * All rights reserved.</center></h2> + * + * This software component is licensed by ST under BSD 3-Clause license, + * the "License"; You may not use this file except in compliance with the + * License. You may obtain a copy of the License at: + * opensource.org/licenses/BSD-3-Clause + * + ****************************************************************************** + */ + + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __MBOX_H +#define __MBOX_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "stm32_wpan_common.h" + +/** + * This file shall be identical between the CPU1 and the CPU2 + */ + +/** + ********************************************************************************* + * TABLES + ********************************************************************************* + */ + +/** + * Version + * [0:3] = Build - 0: Untracked - 15:Released - x: Tracked version + * [4:7] = branch - 0: Mass Market - x: ... + * [8:15] = Subversion + * [16:23] = Version minor + * [24:31] = Version major + * + * Memory Size + * [0:7] = Flash ( Number of 4k sector) + * [8:15] = Reserved ( Shall be set to 0 - may be used as flash extension ) + * [16:23] = SRAM2b ( Number of 1k sector) + * [24:31] = SRAM2a ( Number of 1k sector) + */ +typedef PACKED_STRUCT { + uint32_t Version; +} MB_SafeBootInfoTable_t; + +typedef PACKED_STRUCT { + uint32_t Version; + uint32_t MemorySize; + uint32_t FusInfo; +} MB_FusInfoTable_t; + +typedef PACKED_STRUCT { + uint32_t Version; + uint32_t MemorySize; + uint32_t InfoStack; + uint32_t Reserved; +} MB_WirelessFwInfoTable_t; + +typedef struct { + MB_SafeBootInfoTable_t SafeBootInfoTable; + MB_FusInfoTable_t FusInfoTable; + MB_WirelessFwInfoTable_t WirelessFwInfoTable; +} MB_DeviceInfoTable_t; + +typedef struct { + uint8_t *pcmd_buffer; + uint8_t *pcs_buffer; + uint8_t *pevt_queue; + uint8_t *phci_acl_data_buffer; +} MB_BleTable_t; + +typedef struct { + uint8_t *notack_buffer; + uint8_t *clicmdrsp_buffer; + uint8_t *otcmdrsp_buffer; +} MB_ThreadTable_t; + +typedef struct { + uint8_t *clicmdrsp_buffer; + uint8_t *m0cmd_buffer; +} MB_LldTestsTable_t; + +typedef struct { + uint8_t *cmdrsp_buffer; + uint8_t *m0cmd_buffer; +} MB_LldBleTable_t; + +/** + * msg + * [0:7] = cmd/evt + * [8:31] = Reserved + */ +typedef struct { + uint8_t *pcmd_buffer; + uint8_t *sys_queue; +} MB_SysTable_t; + +typedef struct { + uint8_t *spare_ble_buffer; + uint8_t *spare_sys_buffer; + uint8_t *blepool; + uint32_t blepoolsize; + uint8_t *pevt_free_buffer_queue; + uint8_t *traces_evt_pool; + uint32_t tracespoolsize; +} MB_MemManagerTable_t; + +typedef struct { + uint8_t *traces_queue; +} MB_TracesTable_t; + +typedef struct { + MB_DeviceInfoTable_t *p_device_info_table; + MB_BleTable_t *p_ble_table; + MB_ThreadTable_t *p_thread_table; + MB_SysTable_t *p_sys_table; + MB_MemManagerTable_t *p_mem_manager_table; + MB_TracesTable_t *p_traces_table; + MB_LldTestsTable_t *p_lld_tests_table; + MB_LldBleTable_t *p_lld_ble_table; +} MB_RefTable_t; + +#ifdef __cplusplus +} +#endif + +/** + ********************************************************************************* + * IPCC CHANNELS + ********************************************************************************* + */ + +/* CPU1 CPU2 + * | (SYSTEM) | + * |----HW_IPCC_SYSTEM_CMD_RSP_CHANNEL-------------->| + * | | + * |<---HW_IPCC_SYSTEM_EVENT_CHANNEL-----------------| + * | | + * | (THREAD) | + * |----HW_IPCC_THREAD_OT_CMD_RSP_CHANNEL----------->| + * | | + * |----HW_IPCC_THREAD_CLI_CMD_CHANNEL-------------->| + * | | + * |<---HW_IPCC_THREAD_NOTIFICATION_ACK_CHANNEL------| + * | | + * |<---HW_IPCC_THREAD_CLI_NOTIFICATION_ACK_CHANNEL--| + * | | + * | (BLE) | + * |----HW_IPCC_BLE_CMD_CHANNEL--------------------->| + * | | + * |----HW_IPCC_HCI_ACL_DATA_CHANNEL---------------->| + * | | + * |<---HW_IPCC_BLE_EVENT_CHANNEL--------------------| + * | | + * | (LLD BLE) | + * |----HW_IPCC_LLD_BLE_CMD_CHANNEL----------------->| + * | | + * |<---HW_IPCC_LLD_BLE_RSP_CHANNEL------------------| + * | | + * |<---HW_IPCC_LLD_BLE_M0_CMD_CHANNEL---------------| + * | | + * | (BUFFER) | + * |----HW_IPCC_MM_RELEASE_BUFFER_CHANNE------------>| + * | | + * | (TRACE) | + * |<----HW_IPCC_TRACES_CHANNEL----------------------| + * | | + * + * + * + */ + + + +/** CPU1 */ +#define HW_IPCC_BLE_CMD_CHANNEL LL_IPCC_CHANNEL_1 +#define HW_IPCC_SYSTEM_CMD_RSP_CHANNEL LL_IPCC_CHANNEL_2 +#define HW_IPCC_THREAD_OT_CMD_RSP_CHANNEL LL_IPCC_CHANNEL_3 +#define HW_IPCC_MM_RELEASE_BUFFER_CHANNEL LL_IPCC_CHANNEL_4 +#define HW_IPCC_THREAD_CLI_CMD_CHANNEL LL_IPCC_CHANNEL_5 +#define HW_IPCC_LLDTESTS_CLI_CMD_CHANNEL LL_IPCC_CHANNEL_5 +#define HW_IPCC_LLD_BLE_CLI_CMD_CHANNEL LL_IPCC_CHANNEL_5 +#define HW_IPCC_LLD_BLE_CMD_CHANNEL LL_IPCC_CHANNEL_5 +#define HW_IPCC_HCI_ACL_DATA_CHANNEL LL_IPCC_CHANNEL_6 + +/** CPU2 */ +#define HW_IPCC_BLE_EVENT_CHANNEL LL_IPCC_CHANNEL_1 +#define HW_IPCC_SYSTEM_EVENT_CHANNEL LL_IPCC_CHANNEL_2 +#define HW_IPCC_THREAD_NOTIFICATION_ACK_CHANNEL LL_IPCC_CHANNEL_3 +#define HW_IPCC_LLDTESTS_M0_CMD_CHANNEL LL_IPCC_CHANNEL_3 +#define HW_IPCC_LLD_BLE_M0_CMD_CHANNEL LL_IPCC_CHANNEL_3 +#define HW_IPCC_TRACES_CHANNEL LL_IPCC_CHANNEL_4 +#define HW_IPCC_THREAD_CLI_NOTIFICATION_ACK_CHANNEL LL_IPCC_CHANNEL_5 +#define HW_IPCC_LLDTESTS_CLI_RSP_CHANNEL LL_IPCC_CHANNEL_5 +#define HW_IPCC_LLD_BLE_CLI_RSP_CHANNEL LL_IPCC_CHANNEL_5 +#define HW_IPCC_LLD_BLE_RSP_CHANNEL LL_IPCC_CHANNEL_5 +#endif /*__MBOX_H */ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/src/utility/STM32Cube_FW/shci.c b/src/utility/STM32Cube_FW/shci.c new file mode 100644 index 00000000..d23157f2 --- /dev/null +++ b/src/utility/STM32Cube_FW/shci.c @@ -0,0 +1,567 @@ +/** + ****************************************************************************** + * @file shci.c + * @author MCD Application Team + * @brief HCI command for the system channel + ****************************************************************************** + * @attention + * + * <h2><center>© Copyright (c) 2019 STMicroelectronics. + * All rights reserved.</center></h2> + * + * This software component is licensed by ST under BSD 3-Clause license, + * the "License"; You may not use this file except in compliance with the + * License. You may obtain a copy of the License at: + * opensource.org/licenses/BSD-3-Clause + * + ****************************************************************************** + */ + +#if defined(STM32WBxx) +/* Includes ------------------------------------------------------------------*/ +#include "stm32_wpan_common.h" + +#include "shci_tl.h" +#include "shci.h" +#include "stm32wbxx.h" + +/* Private typedef -----------------------------------------------------------*/ +/* Private defines -----------------------------------------------------------*/ +/* Private macros ------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +/* Global variables ----------------------------------------------------------*/ +/* Private function prototypes -----------------------------------------------*/ +/* Local Functions Definition ------------------------------------------------------*/ +/* Public Functions Definition ------------------------------------------------------*/ + +/** + * C2 COMMAND + * These commands are sent to the CPU2 + */ +uint8_t SHCI_C2_FUS_GetState(SHCI_FUS_GetState_ErrorCode_t *p_error_code) +{ + /** + * A command status event + payload has the same size than the expected command complete + */ + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE + 1]; + TL_EvtPacket_t *p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send(SHCI_OPCODE_C2_FUS_GET_STATE, + 0, + 0, + p_rsp); + + if (p_error_code != 0) { + *p_error_code = (SHCI_FUS_GetState_ErrorCode_t)(((TL_CcEvt_t *)(p_rsp->evtserial.evt.payload))->payload[1]); + } + + return (((TL_CcEvt_t *)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_FUS_FwUpgrade(uint32_t fw_src_add, uint32_t fw_dest_add) +{ + /** + * TL_BLEEVT_CS_BUFFER_SIZE is 15 bytes so it is large enough to hold the 8 bytes of command parameters + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + TL_EvtPacket_t *p_rsp; + uint32_t *p_cmd; + uint8_t cmd_length; + + p_cmd = (uint32_t *)local_buffer; + cmd_length = 0; + + if (fw_src_add != 0) { + *p_cmd = fw_src_add; + cmd_length += 4; + } + + if (fw_dest_add != 0) { + *(p_cmd + 1) = fw_dest_add; + cmd_length += 4; + } + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send(SHCI_OPCODE_C2_FUS_FW_UPGRADE, + cmd_length, + local_buffer, + p_rsp); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t *)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_FUS_FwDelete(void) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + TL_EvtPacket_t *p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send(SHCI_OPCODE_C2_FUS_FW_DELETE, + 0, + 0, + p_rsp); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t *)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_FUS_UpdateAuthKey(SHCI_C2_FUS_UpdateAuthKey_Cmd_Param_t *pParam) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + TL_EvtPacket_t *p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send(SHCI_OPCODE_C2_FUS_UPDATE_AUTH_KEY, + sizeof(SHCI_C2_FUS_UpdateAuthKey_Cmd_Param_t), + (uint8_t *)pParam, + p_rsp); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t *)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_FUS_LockAuthKey(void) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + TL_EvtPacket_t *p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send(SHCI_OPCODE_C2_FUS_LOCK_AUTH_KEY, + 0, + 0, + p_rsp); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t *)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_FUS_StoreUsrKey(SHCI_C2_FUS_StoreUsrKey_Cmd_Param_t *pParam, uint8_t *p_key_index) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE + 1]; + TL_EvtPacket_t *p_rsp; + uint8_t local_payload_len; + + if (pParam->KeyType == KEYTYPE_ENCRYPTED) { + /** + * When the key is encrypted, the 12 bytes IV Key is included in the payload as well + * The IV key is always 12 bytes + */ + local_payload_len = pParam->KeySize + 2 + 12; + } else { + local_payload_len = pParam->KeySize + 2; + } + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send(SHCI_OPCODE_C2_FUS_STORE_USR_KEY, + local_payload_len, + (uint8_t *)pParam, + p_rsp); + + *p_key_index = (((TL_CcEvt_t *)(p_rsp->evtserial.evt.payload))->payload[1]); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t *)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_FUS_LoadUsrKey(uint8_t key_index) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + TL_EvtPacket_t *p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + local_buffer[0] = key_index; + + shci_send(SHCI_OPCODE_C2_FUS_LOAD_USR_KEY, + 1, + local_buffer, + p_rsp); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t *)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_FUS_StartWs(void) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + TL_EvtPacket_t *p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send(SHCI_OPCODE_C2_FUS_START_WS, + 0, + 0, + p_rsp); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t *)(p_rsp->evtserial.evt.payload))->payload[0]); +} + + +SHCI_CmdStatus_t SHCI_C2_FUS_LockUsrKey(uint8_t key_index) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + TL_EvtPacket_t *p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + local_buffer[0] = key_index; + + shci_send(SHCI_OPCODE_C2_FUS_LOCK_USR_KEY, + 1, + local_buffer, + p_rsp); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t *)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_BLE_Init(SHCI_C2_Ble_Init_Cmd_Packet_t *pCmdPacket) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + TL_EvtPacket_t *p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send(SHCI_OPCODE_C2_BLE_INIT, + sizeof(SHCI_C2_Ble_Init_Cmd_Param_t), + (uint8_t *)&pCmdPacket->Param, + p_rsp); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t *)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_THREAD_Init(void) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + TL_EvtPacket_t *p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send(SHCI_OPCODE_C2_THREAD_INIT, + 0, + 0, + p_rsp); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t *)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_LLDTESTS_Init(uint8_t param_size, uint8_t *p_param) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + TL_EvtPacket_t *p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send(SHCI_OPCODE_C2_LLD_TESTS_INIT, + param_size, + p_param, + p_rsp); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t *)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_LLD_BLE_Init(uint8_t param_size, uint8_t *p_param) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + TL_EvtPacket_t *p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send(SHCI_OPCODE_C2_LLD_BLE_INIT, + param_size, + p_param, + p_rsp); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t *)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_DEBUG_Init(SHCI_C2_DEBUG_Init_Cmd_Packet_t *pCmdPacket) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + TL_EvtPacket_t *p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send(SHCI_OPCODE_C2_DEBUG_INIT, + sizeof(SHCI_C2_DEBUG_init_Cmd_Param_t), + (uint8_t *)&pCmdPacket->Param, + p_rsp); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t *)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_FLASH_EraseActivity(SHCI_EraseActivity_t erase_activity) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + TL_EvtPacket_t *p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + local_buffer[0] = erase_activity; + + shci_send(SHCI_OPCODE_C2_FLASH_ERASE_ACTIVITY, + 1, + local_buffer, + p_rsp); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t *)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_CONCURRENT_SetMode(SHCI_C2_CONCURRENT_Mode_Param_t Mode) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + TL_EvtPacket_t *p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + local_buffer[0] = Mode; + + shci_send(SHCI_OPCODE_C2_CONCURRENT_SET_MODE, + 1, + local_buffer, + p_rsp); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t *)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_FLASH_StoreData(SHCI_C2_FLASH_Ip_t Ip) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + TL_EvtPacket_t *p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + local_buffer[0] = Ip; + + shci_send(SHCI_OPCODE_C2_FLASH_STORE_DATA, + 1, + local_buffer, + p_rsp); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t *)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_FLASH_EraseData(SHCI_C2_FLASH_Ip_t Ip) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + TL_EvtPacket_t *p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + local_buffer[0] = Ip; + + shci_send(SHCI_OPCODE_C2_FLASH_ERASE_DATA, + 1, + local_buffer, + p_rsp); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t *)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_RADIO_AllowLowPower(SHCI_C2_FLASH_Ip_t Ip, uint8_t FlagRadioLowPowerOn) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + TL_EvtPacket_t *p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + local_buffer[0] = Ip; + local_buffer[1] = FlagRadioLowPowerOn; + + shci_send(SHCI_OPCODE_C2_RADIO_ALLOW_LOW_POWER, + 2, + local_buffer, + p_rsp); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t *)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_Reinit(void) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + TL_EvtPacket_t *p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send(SHCI_OPCODE_C2_REINIT, + 0, + 0, + p_rsp); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t *)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_ExtpaConfig(uint32_t gpio_port, uint16_t gpio_pin_number, uint8_t gpio_polarity, uint8_t gpio_status) +{ + /** + * TL_BLEEVT_CS_BUFFER_SIZE is 15 bytes so it is large enough to hold the 8 bytes of command parameters + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + TL_EvtPacket_t *p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + ((SHCI_C2_EXTPA_CONFIG_Cmd_Param_t *)local_buffer)->gpio_port = gpio_port; + ((SHCI_C2_EXTPA_CONFIG_Cmd_Param_t *)local_buffer)->gpio_pin_number = gpio_pin_number; + ((SHCI_C2_EXTPA_CONFIG_Cmd_Param_t *)local_buffer)->gpio_polarity = gpio_polarity; + ((SHCI_C2_EXTPA_CONFIG_Cmd_Param_t *)local_buffer)->gpio_status = gpio_status; + + shci_send(SHCI_OPCODE_C2_EXTPA_CONFIG, + 8, + local_buffer, + p_rsp); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t *)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_SetFlashActivityControl(SHCI_C2_SET_FLASH_ACTIVITY_CONTROL_Source_t Source) +{ + /** + * TL_BLEEVT_CS_BUFFER_SIZE is 15 bytes so it is large enough to hold the 1 byte of command parameter + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + TL_EvtPacket_t *p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + local_buffer[0] = (uint8_t)Source; + + shci_send(SHCI_OPCODE_C2_SET_FLASH_ACTIVITY_CONTROL, + 1, + local_buffer, + p_rsp); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t *)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_Config(SHCI_C2_CONFIG_Cmd_Param_t *pCmdPacket) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + TL_EvtPacket_t *p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send(SHCI_OPCODE_C2_CONFIG, + sizeof(SHCI_C2_CONFIG_Cmd_Param_t), + (uint8_t *)pCmdPacket, + p_rsp); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t *)(p_rsp->evtserial.evt.payload))->payload[0]); +} + + +/** + * Local System COMMAND + * These commands are NOT sent to the CPU2 + */ + +SHCI_CmdStatus_t SHCI_GetWirelessFwInfo(WirelessFwInfo_t *pWirelessInfo) +{ + uint32_t ipccdba = 0; + MB_RefTable_t *p_RefTable = NULL; + uint32_t version = 0; + uint32_t memorySize = 0; + uint32_t infoStack = 0; + + ipccdba = READ_BIT(FLASH->IPCCBR, FLASH_IPCCBR_IPCCDBA); + p_RefTable = (MB_RefTable_t *)((ipccdba << 2) + SRAM2A_BASE); + + /** + * Retrieve the WirelessFwInfoTable + * This table is stored in RAM at startup during the TL (transport layer) initialization + */ + version = p_RefTable->p_device_info_table->WirelessFwInfoTable.Version; + pWirelessInfo->VersionMajor = ((version & INFO_VERSION_MAJOR_MASK) >> INFO_VERSION_MAJOR_OFFSET); + pWirelessInfo->VersionMinor = ((version & INFO_VERSION_MINOR_MASK) >> INFO_VERSION_MINOR_OFFSET); + pWirelessInfo->VersionSub = ((version & INFO_VERSION_SUB_MASK) >> INFO_VERSION_SUB_OFFSET); + pWirelessInfo->VersionBranch = ((version & INFO_VERSION_BRANCH_MASK) >> INFO_VERSION_BRANCH_OFFSET); + pWirelessInfo->VersionReleaseType = ((version & INFO_VERSION_TYPE_MASK) >> INFO_VERSION_TYPE_OFFSET); + + memorySize = p_RefTable->p_device_info_table->WirelessFwInfoTable.MemorySize; + pWirelessInfo->MemorySizeSram2B = ((memorySize & INFO_SIZE_SRAM2B_MASK) >> INFO_SIZE_SRAM2B_OFFSET); + pWirelessInfo->MemorySizeSram2A = ((memorySize & INFO_SIZE_SRAM2A_MASK) >> INFO_SIZE_SRAM2A_OFFSET); + pWirelessInfo->MemorySizeSram1 = ((memorySize & INFO_SIZE_SRAM1_MASK) >> INFO_SIZE_SRAM1_OFFSET); + pWirelessInfo->MemorySizeFlash = ((memorySize & INFO_SIZE_FLASH_MASK) >> INFO_SIZE_FLASH_OFFSET); + + infoStack = p_RefTable->p_device_info_table->WirelessFwInfoTable.InfoStack; + pWirelessInfo->StackType = ((infoStack & INFO_STACK_TYPE_MASK) >> INFO_STACK_TYPE_OFFSET); + + /** + * Retrieve the FusInfoTable + * This table is stored in RAM at startup during the TL (transport layer) initialization + */ + version = p_RefTable->p_device_info_table->FusInfoTable.Version; + pWirelessInfo->FusVersionMajor = ((version & INFO_VERSION_MAJOR_MASK) >> INFO_VERSION_MAJOR_OFFSET); + pWirelessInfo->FusVersionMinor = ((version & INFO_VERSION_MINOR_MASK) >> INFO_VERSION_MINOR_OFFSET); + pWirelessInfo->FusVersionSub = ((version & INFO_VERSION_SUB_MASK) >> INFO_VERSION_SUB_OFFSET); + + memorySize = p_RefTable->p_device_info_table->FusInfoTable.MemorySize; + pWirelessInfo->FusMemorySizeSram2B = ((memorySize & INFO_SIZE_SRAM2B_MASK) >> INFO_SIZE_SRAM2B_OFFSET); + pWirelessInfo->FusMemorySizeSram2A = ((memorySize & INFO_SIZE_SRAM2A_MASK) >> INFO_SIZE_SRAM2A_OFFSET); + pWirelessInfo->FusMemorySizeFlash = ((memorySize & INFO_SIZE_FLASH_MASK) >> INFO_SIZE_FLASH_OFFSET); + + return (SHCI_Success); +} +#endif /* STM32WBxx */ +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/src/utility/STM32Cube_FW/shci.h b/src/utility/STM32Cube_FW/shci.h new file mode 100644 index 00000000..35227c76 --- /dev/null +++ b/src/utility/STM32Cube_FW/shci.h @@ -0,0 +1,888 @@ +/** + ****************************************************************************** + * @file shci.h + * @author MCD Application Team + * @brief HCI command for the system channel + ****************************************************************************** + * @attention + * + * <h2><center>© Copyright (c) 2019 STMicroelectronics. + * All rights reserved.</center></h2> + * + * This software component is licensed by ST under BSD 3-Clause license, + * the "License"; You may not use this file except in compliance with the + * License. You may obtain a copy of the License at: + * opensource.org/licenses/BSD-3-Clause + * + ****************************************************************************** + */ + + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __SHCI_H +#define __SHCI_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include "mbox_def.h" /* Requested to expose the MB_WirelessFwInfoTable_t structure */ + +/* Exported types ------------------------------------------------------------*/ + +/* SYSTEM EVENT */ +typedef enum { + WIRELESS_FW_RUNNING = 0x00, + RSS_FW_RUNNING = 0x01, +} SHCI_SysEvt_Ready_Rsp_t; + +/* ERROR CODES + * + * These error codes are detected on M0 side and are send back to the M4 via a system + * notification message. It is up to the application running on M4 to manage these errors + * + * These errors can be generated by all layers (low level driver, stack, framework infrastructure, etc..) + */ +typedef enum { + ERR_BLE_INIT = 0, + ERR_THREAD_LLD_FATAL_ERROR = 125, /* The LLD driver used on 802_15_4 detected a fatal error */ + ERR_THREAD_UNKNOWN_CMD = 126, /* The command send by the M4 to control the Thread stack is unknown */ +} SCHI_SystemErrCode_t; + +#define SHCI_EVTCODE ( 0xFF ) +#define SHCI_SUB_EVT_CODE_BASE ( 0x9200 ) + +/** + * THE ORDER SHALL NOT BE CHANGED TO GUARANTEE COMPATIBILITY WITH THE CPU1 DEFINITION + */ +typedef enum { + SHCI_SUB_EVT_CODE_READY = SHCI_SUB_EVT_CODE_BASE, + SHCI_SUB_EVT_ERROR_NOTIF, + SHCI_SUB_EVT_BLE_NVM_RAM_UPDATE, + SHCI_SUB_EVT_OT_NVM_RAM_UPDATE, + SHCI_SUB_EVT_NVM_START_WRITE, + SHCI_SUB_EVT_NVM_END_WRITE, + SHCI_SUB_EVT_NVM_START_ERASE, + SHCI_SUB_EVT_NVM_END_ERASE, +} SHCI_SUB_EVT_CODE_t; + +/** + * SHCI_SUB_EVT_CODE_READY + * This notifies the CPU1 that the CPU2 is now ready to receive commands + * It reports as well which firmware is running on CPU2 : The wireless stack of the FUS (previously named RSS) + */ +typedef PACKED_STRUCT{ + SHCI_SysEvt_Ready_Rsp_t sysevt_ready_rsp; +} SHCI_C2_Ready_Evt_t; + +/** + * SHCI_SUB_EVT_ERROR_NOTIF + * This reports to the CPU1 some error form the CPU2 + */ +typedef PACKED_STRUCT{ + SCHI_SystemErrCode_t errorCode; +} SHCI_C2_ErrorNotif_Evt_t; + +/** + * SHCI_SUB_EVT_BLE_NVM_RAM_UPDATE + * This notifies the CPU1 which part of the BLE NVM RAM has been updated so that only the modified + * section could be written in Flash/NVM + * StartAddress : Start address of the section that has been modified + * Size : Size (in bytes) of the section that has been modified + */ +typedef PACKED_STRUCT{ + uint32_t StartAddress; + uint32_t Size; +} SHCI_C2_BleNvmRamUpdate_Evt_t; + +/** + * SHCI_SUB_EVT_OT_NVM_RAM_UPDATE + * This notifies the CPU1 which part of the 'OT NVM RAM' has been updated so that only the modified + * section could be written in Flash/NVM + * StartAddress : Start address of the section that has been modified + * Size : Size (in bytes) of the section that has been modified + */ +typedef PACKED_STRUCT{ + uint32_t StartAddress; + uint32_t Size; +} SHCI_C2_OtNvmRamUpdate_Evt_t; + +/** + * SHCI_SUB_EVT_NVM_START_WRITE + * This notifies the CPU1 that the CPU2 has started a write procedure in Flash + * NumberOfWords : The number of 64bits data the CPU2 needs to write in Flash. + * For each 64bits data, the algorithm as described in AN5289 is executed. + * When this number is reported to 0, it means the Number of 64bits to be written + * was unknown when the procedure has started. + * When all data are written, the SHCI_SUB_EVT_NVM_END_WRITE event is reported + */ +typedef PACKED_STRUCT{ + uint32_t NumberOfWords; +} SHCI_C2_NvmStartWrite_Evt_t; + +/** + * SHCI_SUB_EVT_NVM_END_WRITE + * This notifies the CPU1 that the CPU2 has written all expected data in Flash + */ + +/** + * SHCI_SUB_EVT_NVM_START_ERASE + * This notifies the CPU1 that the CPU2 has started a erase procedure in Flash + * NumberOfSectors : The number of sectors the CPU2 needs to erase in Flash. + * For each sector, the algorithm as described in AN5289 is executed. + * When this number is reported to 0, it means the Number of sectors to be erased + * was unknown when the procedure has started. + * When all sectors are erased, the SHCI_SUB_EVT_NVM_END_ERASE event is reported + */ +typedef PACKED_STRUCT{ + uint32_t NumberOfSectors; +} SHCI_C2_NvmStartErase_Evt_t; + +/** + * SHCI_SUB_EVT_NVM_END_ERASE + * This notifies the CPU1 that the CPU2 has erased all expected flash sectors + */ + +/* SYSTEM COMMAND */ +typedef PACKED_STRUCT { + uint32_t MetaData[3]; +} SHCI_Header_t; + +typedef enum { + SHCI_Success = 0x00, + SHCI_UNKNOWN_CMD = 0x01, + SHCI_ERR_UNSUPPORTED_FEATURE = 0x11, + SHCI_ERR_INVALID_HCI_CMD_PARAMS = 0x12, + SHCI_FUS_CMD_NOT_SUPPORTED = 0xFF, +} SHCI_CmdStatus_t; + +typedef enum { + SHCI_8BITS = 0x01, + SHCI_16BITS = 0x02, + SHCI_32BITS = 0x04, +} SHCI_Busw_t; + +#define SHCI_OGF ( 0x3F ) +#define SHCI_OCF_BASE ( 0x50 ) + +/** + * THE ORDER SHALL NOT BE CHANGED TO GUARANTEE COMPATIBILITY WITH THE CPU2 DEFINITION + */ +typedef enum { + SHCI_OCF_C2_RESERVED1 = SHCI_OCF_BASE, + SHCI_OCF_C2_RESERVED2, + SHCI_OCF_C2_FUS_GET_STATE, + SHCI_OCF_C2_FUS_RESERVED1, + SHCI_OCF_C2_FUS_FW_UPGRADE, + SHCI_OCF_C2_FUS_FW_DELETE, + SHCI_OCF_C2_FUS_UPDATE_AUTH_KEY, + SHCI_OCF_C2_FUS_LOCK_AUTH_KEY, + SHCI_OCF_C2_FUS_STORE_USR_KEY, + SHCI_OCF_C2_FUS_LOAD_USR_KEY, + SHCI_OCF_C2_FUS_START_WS, + SHCI_OCF_C2_FUS_RESERVED2, + SHCI_OCF_C2_FUS_RESERVED3, + SHCI_OCF_C2_FUS_LOCK_USR_KEY, + SHCI_OCF_C2_FUS_RESERVED5, + SHCI_OCF_C2_FUS_RESERVED6, + SHCI_OCF_C2_FUS_RESERVED7, + SHCI_OCF_C2_FUS_RESERVED8, + SHCI_OCF_C2_FUS_RESERVED9, + SHCI_OCF_C2_FUS_RESERVED10, + SHCI_OCF_C2_FUS_RESERVED11, + SHCI_OCF_C2_FUS_RESERVED12, + SHCI_OCF_C2_BLE_INIT, + SHCI_OCF_C2_THREAD_INIT, + SHCI_OCF_C2_DEBUG_INIT, + SHCI_OCF_C2_FLASH_ERASE_ACTIVITY, + SHCI_OCF_C2_CONCURRENT_SET_MODE, + SHCI_OCF_C2_FLASH_STORE_DATA, + SHCI_OCF_C2_FLASH_ERASE_DATA, + SHCI_OCF_C2_RADIO_ALLOW_LOW_POWER, + SHCI_OCF_C2_REINIT, + SHCI_OCF_C2_LLD_TESTS_INIT, + SHCI_OCF_C2_EXTPA_CONFIG, + SHCI_OCF_C2_SET_FLASH_ACTIVITY_CONTROL, + SHCI_OCF_C2_LLD_BLE_INIT, + SHCI_OCF_C2_CONFIG, +} SHCI_OCF_t; + +#define SHCI_OPCODE_C2_FUS_GET_STATE (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_GET_STATE) +/** No command parameters */ +/** Response parameters*/ +typedef enum { + FUS_STATE_NO_ERROR = 0x00, + FUS_STATE_IMG_NOT_FOUND = 0x01, + FUS_STATE_IMG_CORRUPT = 0x02, + FUS_STATE_IMG_NOT_AUTHENTIC = 0x03, + FUS_STATE_IMG_NOT_ENOUGH_SPACE = 0x04, + FUS_STATE_ERR_UNKNOWN = 0xFF, +} SHCI_FUS_GetState_ErrorCode_t; + +#define SHCI_OPCODE_C2_FUS_RESERVED1 (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_RESERVED1) +/** No command parameters */ +/** No response parameters*/ + +#define SHCI_OPCODE_C2_FUS_FW_UPGRADE (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_FW_UPGRADE) +/** No structure for command parameters */ +/** No response parameters*/ + +#define SHCI_OPCODE_C2_FUS_FW_DELETE (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_FW_DELETE) +/** No command parameters */ +/** No response parameters*/ + +#define SHCI_OPCODE_C2_FUS_UPDATE_AUTH_KEY (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_UPDATE_AUTH_KEY) +typedef PACKED_STRUCT { + uint8_t KeySize; + uint8_t KeyData[64]; +} SHCI_C2_FUS_UpdateAuthKey_Cmd_Param_t; + +/** No response parameters*/ + +#define SHCI_OPCODE_C2_FUS_LOCK_AUTH_KEY (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_LOCK_AUTH_KEY) +/** No command parameters */ +/** No response parameters*/ + +#define SHCI_OPCODE_C2_FUS_STORE_USR_KEY (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_STORE_USR_KEY) +/** Command parameters */ +/* List of supported key type */ +enum { + KEYTYPE_NONE = 0x00, + KEYTYPE_SIMPLE = 0x01, + KEYTYPE_MASTER = 0x02, + KEYTYPE_ENCRYPTED = 0x03, +}; + +/* List of supported key size */ +enum { + KEYSIZE_16 = 16, + KEYSIZE_32 = 32, +}; + +typedef PACKED_STRUCT{ + uint8_t KeyType; + uint8_t KeySize; + uint8_t KeyData[32 + 12]; +} SHCI_C2_FUS_StoreUsrKey_Cmd_Param_t; + +/** Response parameters*/ +/** It responds a 1 byte value holding the index given for the stored key */ + +#define SHCI_OPCODE_C2_FUS_LOAD_USR_KEY (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_LOAD_USR_KEY) +/** Command parameters */ +/** 1 byte holding the key index value */ + +/** No response parameters*/ + +#define SHCI_OPCODE_C2_FUS_START_WS (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_START_WS) +/** No command parameters */ +/** No response parameters*/ + +#define SHCI_OPCODE_C2_FUS_RESERVED2 (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_RESERVED2) +/** No command parameters */ +/** No response parameters*/ + +#define SHCI_OPCODE_C2_FUS_RESERVED3 (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_RESERVED3) +/** No command parameters */ +/** No response parameters*/ + +#define SHCI_OPCODE_C2_FUS_LOCK_USR_KEY (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_LOCK_USR_KEY) +/** Command parameters */ +/** 1 byte holding the key index value */ + +/** No response parameters*/ + +#define SHCI_OPCODE_C2_FUS_RESERVED5 (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_RESERVED5) +/** No command parameters */ +/** No response parameters*/ + +#define SHCI_OPCODE_C2_FUS_RESERVED6 (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_RESERVED6) +/** No command parameters */ +/** No response parameters*/ + +#define SHCI_OPCODE_C2_FUS_RESERVED7 (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_RESERVED7) +/** No command parameters */ +/** No response parameters*/ + +#define SHCI_OPCODE_C2_FUS_RESERVED8 (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_RESERVED8) +/** No command parameters */ +/** No response parameters*/ + +#define SHCI_OPCODE_C2_FUS_RESERVED9 (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_RESERVED9) +/** No command parameters */ +/** No response parameters*/ + +#define SHCI_OPCODE_C2_FUS_RESERVED10 (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_RESERVED10) +/** No command parameters */ +/** No response parameters*/ + +#define SHCI_OPCODE_C2_FUS_RESERVED11 (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_RESERVED11) +/** No command parameters */ +/** No response parameters*/ + +#define SHCI_OPCODE_C2_FUS_RESERVED12 (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_RESERVED12) +/** No command parameters */ +/** No response parameters*/ + +#define SHCI_OPCODE_C2_BLE_INIT (( SHCI_OGF << 10) + SHCI_OCF_C2_BLE_INIT) +/** THE ORDER SHALL NOT BE CHANGED */ +typedef PACKED_STRUCT{ + uint8_t *pBleBufferAddress; /**< NOT USED CURRENTLY */ + uint32_t BleBufferSize; /**< Size of the Buffer allocated in pBleBufferAddress */ + uint16_t NumAttrRecord; + uint16_t NumAttrServ; + uint16_t AttrValueArrSize; + uint8_t NumOfLinks; + uint8_t ExtendedPacketLengthEnable; + uint8_t PrWriteListSize; + uint8_t MblockCount; + uint16_t AttMtu; + uint16_t SlaveSca; + uint8_t MasterSca; + uint8_t LsSource; + uint32_t MaxConnEventLength; + uint16_t HsStartupTime; + uint8_t ViterbiEnable; + uint8_t LlOnly; + uint8_t HwVersion; +} SHCI_C2_Ble_Init_Cmd_Param_t; + +typedef PACKED_STRUCT{ + SHCI_Header_t Header; /** Does not need to be initialized by the user */ + SHCI_C2_Ble_Init_Cmd_Param_t Param; +} SHCI_C2_Ble_Init_Cmd_Packet_t; + +/** No response parameters*/ + +#define SHCI_OPCODE_C2_THREAD_INIT (( SHCI_OGF << 10) + SHCI_OCF_C2_THREAD_INIT) +/** No command parameters */ +/** No response parameters*/ + +#define SHCI_OPCODE_C2_DEBUG_INIT (( SHCI_OGF << 10) + SHCI_OCF_C2_DEBUG_INIT) +/** Command parameters */ +typedef PACKED_STRUCT { + uint8_t thread_config; + uint8_t ble_config; +} SHCI_C2_DEBUG_TracesConfig_t; + +typedef PACKED_STRUCT { + uint8_t ble_dtb_cfg; + uint8_t reserved[3]; +} SHCI_C2_DEBUG_GeneralConfig_t; + +typedef PACKED_STRUCT{ + uint8_t *pGpioConfig; + uint8_t *pTracesConfig; + uint8_t *pGeneralConfig; + uint8_t GpioConfigSize; + uint8_t TracesConfigSize; + uint8_t GeneralConfigSize; +} SHCI_C2_DEBUG_init_Cmd_Param_t; + +typedef PACKED_STRUCT{ + SHCI_Header_t Header; /** Does not need to be initialized by the user */ + SHCI_C2_DEBUG_init_Cmd_Param_t Param; +} SHCI_C2_DEBUG_Init_Cmd_Packet_t; +/** No response parameters*/ + +#define SHCI_OPCODE_C2_FLASH_ERASE_ACTIVITY (( SHCI_OGF << 10) + SHCI_OCF_C2_FLASH_ERASE_ACTIVITY) +/** Command parameters */ +typedef enum { + ERASE_ACTIVITY_OFF = 0x00, + ERASE_ACTIVITY_ON = 0x01, +} SHCI_EraseActivity_t; + +/** No response parameters*/ + +#define SHCI_OPCODE_C2_CONCURRENT_SET_MODE (( SHCI_OGF << 10) + SHCI_OCF_C2_CONCURRENT_SET_MODE) +/** command parameters */ +typedef enum { + BLE_ENABLE, + THREAD_ENABLE, +} SHCI_C2_CONCURRENT_Mode_Param_t; +/** No response parameters*/ + +#define SHCI_OPCODE_C2_FLASH_STORE_DATA (( SHCI_OGF << 10) + SHCI_OCF_C2_FLASH_STORE_DATA) +#define SHCI_OPCODE_C2_FLASH_ERASE_DATA (( SHCI_OGF << 10) + SHCI_OCF_C2_FLASH_ERASE_DATA) +/** command parameters */ +typedef enum { + BLE_IP, + THREAD_IP, +} SHCI_C2_FLASH_Ip_t; +/** No response parameters*/ + +#define SHCI_OPCODE_C2_RADIO_ALLOW_LOW_POWER (( SHCI_OGF << 10) + SHCI_OCF_C2_RADIO_ALLOW_LOW_POWER) + +#define SHCI_OPCODE_C2_REINIT (( SHCI_OGF << 10) + SHCI_OCF_C2_REINIT) + +#define SHCI_OPCODE_C2_LLD_TESTS_INIT (( SHCI_OGF << 10) + SHCI_OCF_C2_LLD_TESTS_INIT) + +#define SHCI_OPCODE_C2_LLD_BLE_INIT (( SHCI_OGF << 10) + SHCI_OCF_C2_LLD_BLE_INIT) + +#define SHCI_OPCODE_C2_EXTPA_CONFIG (( SHCI_OGF << 10) + SHCI_OCF_C2_EXTPA_CONFIG) +/** Command parameters */ +enum { + EXT_PA_ENABLED_LOW, + EXT_PA_ENABLED_HIGH, +}/* gpio_polarity */; + +enum { + EXT_PA_DISABLED, + EXT_PA_ENABLED, +}/* gpio_status */; + +typedef PACKED_STRUCT{ + uint32_t gpio_port; + uint16_t gpio_pin_number; + uint8_t gpio_polarity; + uint8_t gpio_status; +} SHCI_C2_EXTPA_CONFIG_Cmd_Param_t; + +/** No response parameters*/ + +#define SHCI_OPCODE_C2_SET_FLASH_ACTIVITY_CONTROL (( SHCI_OGF << 10) + SHCI_OCF_C2_SET_FLASH_ACTIVITY_CONTROL) +/** Command parameters */ +typedef enum { + FLASH_ACTIVITY_CONTROL_PES, + FLASH_ACTIVITY_CONTROL_SEM7, +} SHCI_C2_SET_FLASH_ACTIVITY_CONTROL_Source_t; + +/** No response parameters*/ + +#define SHCI_OPCODE_C2_CONFIG (( SHCI_OGF << 10) + SHCI_OCF_C2_CONFIG) +/** Command parameters */ +typedef PACKED_STRUCT{ + uint8_t PayloadCmdSize; + uint8_t Config1; + uint8_t EvtMask1; + uint8_t Spare1; + uint32_t BleNvmRamAddress; + uint32_t ThreadNvmRamAddress; +} SHCI_C2_CONFIG_Cmd_Param_t; + +/** + * PayloadCmdSize + * Value that shall be used + */ +#define SHCI_C2_CONFIG_PAYLOAD_CMD_SIZE (sizeof(SHCI_C2_CONFIG_Cmd_Param_t) - 1) + +/** + * Config1 + * Each definition below may be added together to build the Config1 value + * WARNING : Only one definition per bit shall be added to build the Config1 value + */ +#define SHCI_C2_CONFIG_CONFIG1_BIT0_BLE_NVM_DATA_TO_INTERNAL_FLASH (0<<0) +#define SHCI_C2_CONFIG_CONFIG1_BIT0_BLE_NVM_DATA_TO_SRAM (1<<0) +#define SHCI_C2_CONFIG_CONFIG1_BIT1_THREAD_NVM_DATA_TO_INTERNAL_FLASH (0<<1) +#define SHCI_C2_CONFIG_CONFIG1_BIT1_THREAD_NVM_DATA_TO_SRAM (1<<1) + +/** + * EvtMask1 + * Each definition below may be added together to build the EvtMask1 value + */ +#define SHCI_C2_CONFIG_EVTMASK1_BIT0_ERROR_NOTIF_ENABLE (1<<0) +#define SHCI_C2_CONFIG_EVTMASK1_BIT1_BLE_NVM_RAM_UPDATE_ENABLE (1<<1) +#define SHCI_C2_CONFIG_EVTMASK1_BIT2_OT_NVM_RAM_UPDATE_ENABLE (1<<2) +#define SHCI_C2_CONFIG_EVTMASK1_BIT3_NVM_START_WRITE_ENABLE (1<<3) +#define SHCI_C2_CONFIG_EVTMASK1_BIT4_NVM_END_WRITE_ENABLE (1<<4) +#define SHCI_C2_CONFIG_EVTMASK1_BIT5_NVM_START_ERASE_ENABLE (1<<5) +#define SHCI_C2_CONFIG_EVTMASK1_BIT6_NVM_END_ERASE_ENABLE (1<<6) + +/** + * BleNvmRamAddress + * The buffer shall have a size of BLE_NVM_SRAM_SIZE number of 32bits + * The buffer shall be allocated in SRAM2 + */ +#define BLE_NVM_SRAM_SIZE (507) + +/** + * ThreadNvmRamAddress + * The buffer shall have a size of THREAD_NVM_SRAM_SIZE number of 32bits + * The buffer shall be allocated in SRAM2 + */ +#define THREAD_NVM_SRAM_SIZE (1016) + + +/** No response parameters*/ + +/* Exported type --------------------------------------------------------*/ + +typedef MB_WirelessFwInfoTable_t SHCI_WirelessFwInfoTable_t; + +/* + * At startup, the information relative to the wireless binary are stored in RAM through a structure defined by + * SHCI_WirelessFwInfoTable_t.This structure contains 4 fields (Version,MemorySize, Stack_info and a reserved part) + * each of those coded on 32 bits as shown on the table below: + * + * + * |7 |6 |5 |4 |3 |2 |1 |0 |7 |6 |5 |4 |3 |2 |1 |0 |7 |6 |5 |4 |3 |2 |1 |0 |7 |6 |5 |4 |3 |2 |1 |0 | + * ------------------------------------------------------------------------------------------------- + * Version | Major version | Minor version | Sub version | Branch |Release Type| + * ------------------------------------------------------------------------------------------------- + * MemorySize | SRAM2B (kB) | SRAM2A (kB) | SRAM1 (kB) | FLASH (4kb) | + * ------------------------------------------------------------------------------------------------- + * Info stack | Reserved | Reserved | Reserved | Type (MAC,Thread,BLE) | + * ------------------------------------------------------------------------------------------------- + * Reserved | Reserved | Reserved | Reserved | Reserved | + * ------------------------------------------------------------------------------------------------- + * + */ + +/* Field Version */ +#define INFO_VERSION_MAJOR_OFFSET 24 +#define INFO_VERSION_MAJOR_MASK 0xff000000 +#define INFO_VERSION_MINOR_OFFSET 16 +#define INFO_VERSION_MINOR_MASK 0x00ff0000 +#define INFO_VERSION_SUB_OFFSET 8 +#define INFO_VERSION_SUB_MASK 0x0000ff00 +#define INFO_VERSION_BRANCH_OFFSET 4 +#define INFO_VERSION_BRANCH_MASK 0x0000000f0 +#define INFO_VERSION_TYPE_OFFSET 0 +#define INFO_VERSION_TYPE_MASK 0x00000000f + +#define INFO_VERSION_TYPE_RELEASE 1 + +/* Field Memory */ +#define INFO_SIZE_SRAM2B_OFFSET 24 +#define INFO_SIZE_SRAM2B_MASK 0xff000000 +#define INFO_SIZE_SRAM2A_OFFSET 16 +#define INFO_SIZE_SRAM2A_MASK 0x00ff0000 +#define INFO_SIZE_SRAM1_OFFSET 8 +#define INFO_SIZE_SRAM1_MASK 0x0000ff00 +#define INFO_SIZE_FLASH_OFFSET 0 +#define INFO_SIZE_FLASH_MASK 0x000000ff + +/* Field stack information */ +#define INFO_STACK_TYPE_OFFSET 0 +#define INFO_STACK_TYPE_MASK 0x000000ff +#define INFO_STACK_TYPE_NONE 0 + +#define INFO_STACK_TYPE_BLE_STANDARD 0x01 +#define INFO_STACK_TYPE_BLE_HCI 0x02 +#define INFO_STACK_TYPE_BLE_LIGHT 0x03 +#define INFO_STACK_TYPE_THREAD_FTD 0x10 +#define INFO_STACK_TYPE_THREAD_MTD 0x11 +#define INFO_STACK_TYPE_BLE_THREAD_FTD_STATIC 0x50 +#define INFO_STACK_TYPE_BLE_THREAD_FTD_DYAMIC 0x51 +#define INFO_STACK_TYPE_BLE_PHY_VALID 0x62 +#define INFO_STACK_TYPE_BLE_LLD_TESTS 0x63 +#define INFO_STACK_TYPE_BLE_RLV 0x64 +#define INFO_STACK_TYPE_RLV 0x80 + +typedef struct { + /** + * Wireless Info + */ + uint8_t VersionMajor; + uint8_t VersionMinor; + uint8_t VersionSub; + uint8_t VersionBranch; + uint8_t VersionReleaseType; + uint8_t MemorySizeSram2B; /*< Multiple of 1K */ + uint8_t MemorySizeSram2A; /*< Multiple of 1K */ + uint8_t MemorySizeSram1; /*< Multiple of 1K */ + uint8_t MemorySizeFlash; /*< Multiple of 4K */ + uint8_t StackType; + /** + * Fus Info + */ + uint8_t FusVersionMajor; + uint8_t FusVersionMinor; + uint8_t FusVersionSub; + uint8_t FusMemorySizeSram2B; /*< Multiple of 1K */ + uint8_t FusMemorySizeSram2A; /*< Multiple of 1K */ + uint8_t FusMemorySizeFlash; /*< Multiple of 4K */ +} WirelessFwInfo_t; + + +/* Exported functions ------------------------------------------------------- */ + +/** + * For all SHCI_C2_FUS_xxx() command: + * When the wireless FW is running on the CPU2, the command returns SHCI_FUS_CMD_NOT_SUPPORTED + * When any FUS command is sent after the SHCI_FUS_CMD_NOT_SUPPORTED has been received, + * the CPU2 switches on the RSS ( This reboots automatically the device ) + */ +/** +* SHCI_C2_FUS_GetState +* @brief Read the FUS State +* If the user is not interested by the Error code response, a null value may +* be passed as parameter +* +* @param p_rsp : return the error code when the FUS State Value = 0xFF +* @retval FUS State Values +*/ +uint8_t SHCI_C2_FUS_GetState(SHCI_FUS_GetState_ErrorCode_t *p_rsp); + +/** +* SHCI_C2_FUS_FwUpgrade +* @brief Request the FUS to install the CPU2 firmware update +* +* @param fw_src_add: Address of the firmware image location +* @param fw_dest_add: Address of the firmware destination +* @retval Status +*/ +SHCI_CmdStatus_t SHCI_C2_FUS_FwUpgrade(uint32_t fw_src_add, uint32_t fw_dest_add); + +/** +* SHCI_C2_FUS_FwDelete +* @brief Delete the wireless stack on CPU2 +* +* @param None +* @retval Status +*/ +SHCI_CmdStatus_t SHCI_C2_FUS_FwDelete(void); + +/** +* SHCI_C2_FUS_UpdateAuthKey +* @brief Request the FUS to update the authentication key +* +* @param pCmdPacket +* @retval Status +*/ +SHCI_CmdStatus_t SHCI_C2_FUS_UpdateAuthKey(SHCI_C2_FUS_UpdateAuthKey_Cmd_Param_t *pParam); + +/** +* SHCI_C2_FUS_LockAuthKey +* @brief Request the FUS to prevent any future update of the authentication key +* +* @param None +* @retval Status +*/ +SHCI_CmdStatus_t SHCI_C2_FUS_LockAuthKey(void); + +/** +* SHCI_C2_FUS_StoreUsrKey +* @brief Request the FUS to store the user key +* +* @param pParam : command parameter +* @param p_key_index : Index allocated by the FUS to the stored key +* +* @retval Status +*/ +SHCI_CmdStatus_t SHCI_C2_FUS_StoreUsrKey(SHCI_C2_FUS_StoreUsrKey_Cmd_Param_t *pParam, uint8_t *p_key_index); + +/** +* SHCI_C2_FUS_LoadUsrKey +* @brief Request the FUS to load the user key into the AES +* +* @param key_index : index of the user key to load in AES1 +* @retval Status +*/ +SHCI_CmdStatus_t SHCI_C2_FUS_LoadUsrKey(uint8_t key_index); + +/** +* SHCI_C2_FUS_StartWs +* @brief Request the FUS to reboot on the wireless stack +* +* @param None +* @retval Status +*/ +SHCI_CmdStatus_t SHCI_C2_FUS_StartWs(void); + +/** +* SHCI_C2_FUS_LockUsrKey +* @brief Request the FUS to lock the user key so that it cannot be updated later on +* +* @param key_index : index of the user key to lock +* @retval Status +*/ +SHCI_CmdStatus_t SHCI_C2_FUS_LockUsrKey(uint8_t key_index); + +/** +* SHCI_C2_BLE_Init +* @brief Provides parameters and starts the BLE Stack +* +* @param pCmdPacket : Parameters to be provided to the BLE Stack +* @retval Status +*/ +SHCI_CmdStatus_t SHCI_C2_BLE_Init(SHCI_C2_Ble_Init_Cmd_Packet_t *pCmdPacket); + +/** +* SHCI_C2_THREAD_Init +* @brief Starts the THREAD Stack +* +* @param None +* @retval Status +*/ +SHCI_CmdStatus_t SHCI_C2_THREAD_Init(void); + +/** +* SHCI_C2_LLDTESTS_Init +* @brief Starts the LLD tests CLI +* +* @param param_size : Nb of bytes +* @param p_param : pointer with data to give from M4 to M0 +* @retval Status +*/ +SHCI_CmdStatus_t SHCI_C2_LLDTESTS_Init(uint8_t param_size, uint8_t *p_param); + +/** +* SHCI_C2_LLD_BLE_Init +* @brief Starts the LLD tests CLI +* +* @param param_size : Nb of bytes +* @param p_param : pointer with data to give from M4 to M0 +* @retval Status +*/ +SHCI_CmdStatus_t SHCI_C2_LLD_BLE_Init(uint8_t param_size, uint8_t *p_param); + +/** +* SHCI_C2_DEBUG_Init +* @brief Starts the Traces +* +* @param None +* @retval Status +*/ +SHCI_CmdStatus_t SHCI_C2_DEBUG_Init(SHCI_C2_DEBUG_Init_Cmd_Packet_t *pCmdPacket); + +/** +* SHCI_C2_FLASH_EraseActivity +* @brief Provides the information of the start and the end of a flash erase window on the CPU1 +* +* @param erase_activity: Start/End of erase activity +* @retval Status +*/ +SHCI_CmdStatus_t SHCI_C2_FLASH_EraseActivity(SHCI_EraseActivity_t erase_activity); + +/** +* SHCI_C2_CONCURRENT_SetMode +* @brief Enable/Disable Thread on CPU2 (M0+) +* +* @param Mode: BLE or Thread enable flag +* @retval Status +*/ +SHCI_CmdStatus_t SHCI_C2_CONCURRENT_SetMode(SHCI_C2_CONCURRENT_Mode_Param_t Mode); + +/** +* SHCI_C2_FLASH_StoreData +* @brief Store Data in Flash +* +* @param Ip: BLE or THREAD +* @retval Status +*/ +SHCI_CmdStatus_t SHCI_C2_FLASH_StoreData(SHCI_C2_FLASH_Ip_t Ip); + +/** +* SHCI_C2_FLASH_EraseData +* @brief Erase Data in Flash +* +* @param Ip: BLE or THREAD +* @retval Status +*/ +SHCI_CmdStatus_t SHCI_C2_FLASH_EraseData(SHCI_C2_FLASH_Ip_t Ip); + +/** +* SHCI_C2_RADIO_AllowLowPower +* @brief Allow or forbid IP_radio (802_15_4 or BLE) to enter in low power mode. +* +* @param Ip: BLE or 802_15_5 +* @param FlagRadioLowPowerOn: True or false +* @retval Status +*/ +SHCI_CmdStatus_t SHCI_C2_RADIO_AllowLowPower(SHCI_C2_FLASH_Ip_t Ip, uint8_t FlagRadioLowPowerOn); + +/** + * SHCI_GetWirelessFwInfo + * @brief This function read back the information relative to the wireless binary loaded. + * Refer yourself to SHCI_WirelessFwInfoTable_t structure to get the significance + * of the different parameters returned. + * @param pWirelessInfo : Pointer to WirelessFwInfo_t. + * + * @retval SHCI_Success + */ +SHCI_CmdStatus_t SHCI_GetWirelessFwInfo(WirelessFwInfo_t *pWirelessInfo); + +/** +* SHCI_C2_Reinit +* @brief This is required to allow the CPU1 to fake a set C2BOOT when it has already been set. +* In order to fake a C2BOOT, the CPU1 shall : +* - Send SHCI_C2_Reinit() +* - call SEV instruction +* WARNING: +* This function is intended to be used by the SBSFU +* +* @param None +* @retval Status +*/ +SHCI_CmdStatus_t SHCI_C2_Reinit(void); + +/** +* SHCI_C2_ExtpaConfig +* @brief Send the Ext PA configuration +* When the CPU2 receives the command, it controls the Ext PA as requested by the configuration +* This configures only which IO is used to enable/disable the ExtPA and the associated polarity +* This command has no effect on the other IO that is used to control the mode of the Ext PA (Rx/Tx) +* +* @param gpio_port: GPIOx where x can be (A..F) to select the GPIO peripheral for STM32WBxx family +* @param gpio_pin_number: This parameter can be one of GPIO_PIN_x (= LL_GPIO_PIN_x) where x can be (0..15). +* @param gpio_polarity: This parameter can be either +* - EXT_PA_ENABLED_LOW: ExtPA is enabled when GPIO is low +* - EXT_PA_ENABLED_HIGH: ExtPA is enabled when GPIO is high +* @param gpio_status: This parameter can be either +* - EXT_PA_DISABLED: Stop driving the ExtPA +* - EXT_PA_ENABLED: Drive the ExtPA according to radio activity +* (ON before the Event and OFF at the end of the event) +* @retval Status +*/ +SHCI_CmdStatus_t SHCI_C2_ExtpaConfig(uint32_t gpio_port, uint16_t gpio_pin_number, uint8_t gpio_polarity, uint8_t gpio_status); + +/** +* SHCI_C2_SetFlashActivityControl +* @brief Set the mechanism to be used on CPU2 to prevent the CPU1 to either write or erase in flash +* +* @param Source: It can be one of the following list +* - FLASH_ACTIVITY_CONTROL_PES : The CPU2 set the PES bit to prevent the CPU1 to either read or write in flash +* - FLASH_ACTIVITY_CONTROL_SEM7 : The CPU2 gets the semaphore 7 to prevent the CPU1 to either read or write in flash. +* This requires the CPU1 to first get semaphore 7 before erasing or writing the flash. +* +* @retval Status +*/ +SHCI_CmdStatus_t SHCI_C2_SetFlashActivityControl(SHCI_C2_SET_FLASH_ACTIVITY_CONTROL_Source_t Source); + +/** +* SHCI_C2_Config +* @brief Send the system configuration to the CPU2 +* +* @param pCmdPacket: address of the buffer holding following parameters +* uint8_t PayloadCmdSize : Size of the payload - shall be SHCI_C2_CONFIG_PAYLOAD_CMD_SIZE +* uint8_t Config1 : +* - bit0 : 0 - BLE NVM Data data are flushed in internal secure flash +* 1 - BLE NVM Data are written in SRAM cache pointed by BleNvmRamAddress +* - bit1 : 0 - THREAD NVM Data data are flushed in internal secure flash +* 1 - THREAD NVM Data are written in SRAM cache pointed by ThreadNvmRamAddress +* - bit2 to bit7 : Unused, shall be set to 0 +* uint8_t EvtMask1 : +* When a bit is set to 0, the event is not reported +* bit0 : Asynchronous Event with Sub Evt Code 0x9201 (= SHCI_SUB_EVT_ERROR_NOTIF) +* ... +* bit31 : Asynchronous Event with Sub Evt Code 0x9220 +* uint8_t Spare1 : Unused, shall be set to 0 +* uint32_t BleNvmRamAddress : +* Only considered when Config1.bit0 = 1 +* When set to 0, data are kept in internal SRAM on CPU2 +* Otherwise, data are copied in the cache pointed by BleNvmRamAddress +* The size of the buffer shall be BLE_NVM_SRAM_SIZE (number of 32bits) +* The buffer shall be allocated in SRAM2 +* uint32_t ThreadNvmRamAddress : +* Only considered when Config1.bit1 = 1 +* When set to 0, data are kept in internal SRAM on CPU2 +* Otherwise, data are copied in the cache pointed by ThreadNvmRamAddress +* The size of the buffer shall be THREAD_NVM_SRAM_SIZE (number of 32bits) +* The buffer shall be allocated in SRAM2 +* +* Please check macro definition to be used for this function +* They are defined in this file next to the definition of SHCI_OPCODE_C2_CONFIG +* +* @retval Status +*/ +SHCI_CmdStatus_t SHCI_C2_Config(SHCI_C2_CONFIG_Cmd_Param_t *pCmdPacket); + +#ifdef __cplusplus +} +#endif + +#endif /*__SHCI_H */ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/src/utility/STM32Cube_FW/shci_tl.c b/src/utility/STM32Cube_FW/shci_tl.c new file mode 100644 index 00000000..1ab15b47 --- /dev/null +++ b/src/utility/STM32Cube_FW/shci_tl.c @@ -0,0 +1,344 @@ +/** + ****************************************************************************** + * @file shci.c + * @author MCD Application Team + * @brief System HCI command implementation + ****************************************************************************** + * @attention + * + * <h2><center>© Copyright (c) 2019 STMicroelectronics. + * All rights reserved.</center></h2> + * + * This software component is licensed by ST under BSD 3-Clause license, + * the "License"; You may not use this file except in compliance with the + * License. You may obtain a copy of the License at: + * opensource.org/licenses/BSD-3-Clause + * + ****************************************************************************** + */ + +#if defined(STM32WBxx) +/* Includes ------------------------------------------------------------------*/ +#include "stm32_wpan_common.h" + +#include "stm_list.h" +#include "shci_tl.h" +#include "stm32_def.h" + +/** + * These traces are not yet supported in an usual way in the delivery package + * They can enabled by adding the definition of TL_SHCI_CMD_DBG_EN and/or TL_SHCI_EVT_DBG_EN in the preprocessor option in the IDE + */ +#if ( (TL_SHCI_CMD_DBG_EN != 0) || (TL_SHCI_EVT_DBG_EN != 0) ) + #include "app_conf.h" + #include "dbg_trace.h" +#endif + +#if (TL_SHCI_CMD_DBG_EN != 0) + #define TL_SHCI_CMD_DBG_MSG PRINT_MESG_DBG + #define TL_SHCI_CMD_DBG_BUF PRINT_LOG_BUFF_DBG +#else + #define TL_SHCI_CMD_DBG_MSG(...) + #define TL_SHCI_CMD_DBG_BUF(...) +#endif + +#if (TL_SHCI_EVT_DBG_EN != 0) + #define TL_SHCI_EVT_DBG_MSG PRINT_MESG_DBG + #define TL_SHCI_EVT_DBG_BUF PRINT_LOG_BUFF_DBG +#else + #define TL_SHCI_EVT_DBG_MSG(...) + #define TL_SHCI_EVT_DBG_BUF(...) +#endif + +/* Private typedef -----------------------------------------------------------*/ +typedef enum { + SHCI_TL_CMD_RESP_RELEASE, + SHCI_TL_CMD_RESP_WAIT, +} SHCI_TL_CmdRespStatus_t; + +/* Private defines -----------------------------------------------------------*/ +/** + * The default System HCI layer timeout is set to 33s + */ +#define SHCI_TL_DEFAULT_TIMEOUT (33000) + +/* Private macros ------------------------------------------------------------*/ +/* Public variables ---------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +/** + * START of Section SYSTEM_DRIVER_CONTEXT + */ +PLACE_IN_SECTION("SYSTEM_DRIVER_CONTEXT") static tListNode SHciAsynchEventQueue; +PLACE_IN_SECTION("SYSTEM_DRIVER_CONTEXT") static volatile SHCI_TL_CmdStatus_t SHCICmdStatus; +PLACE_IN_SECTION("SYSTEM_DRIVER_CONTEXT") static TL_CmdPacket_t *pCmdBuffer; +PLACE_IN_SECTION("SYSTEM_DRIVER_CONTEXT") SHCI_TL_UserEventFlowStatus_t SHCI_TL_UserEventFlow; +/** + * END of Section SYSTEM_DRIVER_CONTEXT + */ + +static tSHciContext shciContext; +static void (* StatusNotCallBackFunction)(SHCI_TL_CmdStatus_t status); + +static volatile SHCI_TL_CmdRespStatus_t CmdRspStatusFlag; + +/* Private function prototypes -----------------------------------------------*/ +static void Cmd_SetStatus(SHCI_TL_CmdStatus_t shcicmdstatus); +static void TlCmdEvtReceived(TL_EvtPacket_t *shcievt); +static void TlUserEvtReceived(TL_EvtPacket_t *shcievt); +static void TlInit(TL_CmdPacket_t *p_cmdbuffer); +static void OutputCmdTrace(TL_CmdPacket_t *pCmdBuffer); +static void OutputRspTrace(TL_EvtPacket_t *p_rsp); +static void OutputEvtTrace(TL_EvtPacket_t *phcievtbuffer); + +/* Interface ------- ---------------------------------------------------------*/ +void shci_init(void(* UserEvtRx)(void *pData), void *pConf) +{ + StatusNotCallBackFunction = ((SHCI_TL_HciInitConf_t *)pConf)->StatusNotCallBack; + shciContext.UserEvtRx = UserEvtRx; + + shci_register_io_bus(&shciContext.io); + + TlInit((TL_CmdPacket_t *)(((SHCI_TL_HciInitConf_t *)pConf)->p_cmdbuffer)); + + return; +} + +void shci_user_evt_proc(void) +{ + TL_EvtPacket_t *phcievtbuffer; + tSHCI_UserEvtRxParam UserEvtRxParam; + + /** + * Up to release version v1.2.0, a while loop was implemented to read out events from the queue as long as + * it is not empty. However, in a bare metal implementation, this leads to calling in a "blocking" mode + * shci_user_evt_proc() as long as events are received without giving the opportunity to run other tasks + * in the background. + * From now, the events are reported one by one. When it is checked there is still an event pending in the queue, + * a request to the user is made to call again shci_user_evt_proc(). + * This gives the opportunity to the application to run other background tasks between each event. + */ + + /** + * It is more secure to use LST_remove_head()/LST_insert_head() compare to LST_get_next_node()/LST_remove_node() + * in case the user overwrite the header where the next/prev pointers are located + */ + if ((LST_is_empty(&SHciAsynchEventQueue) == FALSE) && (SHCI_TL_UserEventFlow != SHCI_TL_UserEventFlow_Disable)) { + LST_remove_head(&SHciAsynchEventQueue, (tListNode **)&phcievtbuffer); + + OutputEvtTrace(phcievtbuffer); + + if (shciContext.UserEvtRx != NULL) { + UserEvtRxParam.pckt = phcievtbuffer; + UserEvtRxParam.status = SHCI_TL_UserEventFlow_Enable; + shciContext.UserEvtRx((void *)&UserEvtRxParam); + SHCI_TL_UserEventFlow = UserEvtRxParam.status; + } else { + SHCI_TL_UserEventFlow = SHCI_TL_UserEventFlow_Enable; + } + + if (SHCI_TL_UserEventFlow != SHCI_TL_UserEventFlow_Disable) { + TL_MM_EvtDone(phcievtbuffer); + } else { + /** + * put back the event in the queue + */ + LST_insert_head(&SHciAsynchEventQueue, (tListNode *)phcievtbuffer); + } + } + + if ((LST_is_empty(&SHciAsynchEventQueue) == FALSE) && (SHCI_TL_UserEventFlow != SHCI_TL_UserEventFlow_Disable)) { + shci_notify_asynch_evt((void *) &SHciAsynchEventQueue); + } + + return; +} + +void shci_resume_flow(void) +{ + SHCI_TL_UserEventFlow = SHCI_TL_UserEventFlow_Enable; + + /** + * It is better to go through the background process as it is not sure from which context this API may + * be called + */ + shci_notify_asynch_evt((void *) &SHciAsynchEventQueue); + + return; +} + +void shci_send(uint16_t cmd_code, uint8_t len_cmd_payload, uint8_t *p_cmd_payload, TL_EvtPacket_t *p_rsp) +{ + Cmd_SetStatus(SHCI_TL_CmdBusy); + + pCmdBuffer->cmdserial.cmd.cmdcode = cmd_code; + pCmdBuffer->cmdserial.cmd.plen = len_cmd_payload; + + memcpy(pCmdBuffer->cmdserial.cmd.payload, p_cmd_payload, len_cmd_payload); + + OutputCmdTrace(pCmdBuffer); + + shciContext.io.Send(0, 0); + + shci_cmd_resp_wait(SHCI_TL_DEFAULT_TIMEOUT); + + /** + * The command complete of a system command does not have the header + * It starts immediately with the evtserial field + */ + memcpy(&(p_rsp->evtserial), pCmdBuffer, ((TL_EvtSerial_t *)pCmdBuffer)->evt.plen + TL_EVT_HDR_SIZE); + + OutputRspTrace(p_rsp); + + Cmd_SetStatus(SHCI_TL_CmdAvailable); + + return; +} + +void shci_notify_asynch_evt(void *pdata) +{ + UNUSED(pdata); + /* Need to parse data in future version */ + shci_user_evt_proc(); +} + +void shci_register_io_bus(tSHciIO *fops) +{ + /* Register IO bus services */ + fops->Init = TL_SYS_Init; + fops->Send = TL_SYS_SendCmd; +} + +/* Private functions ---------------------------------------------------------*/ +static void TlInit(TL_CmdPacket_t *p_cmdbuffer) +{ + TL_SYS_InitConf_t Conf; + + pCmdBuffer = p_cmdbuffer; + + LST_init_head(&SHciAsynchEventQueue); + + Cmd_SetStatus(SHCI_TL_CmdAvailable); + + SHCI_TL_UserEventFlow = SHCI_TL_UserEventFlow_Enable; + + /* Initialize low level driver */ + if (shciContext.io.Init) { + + Conf.p_cmdbuffer = (uint8_t *)p_cmdbuffer; + Conf.IoBusCallBackCmdEvt = TlCmdEvtReceived; + Conf.IoBusCallBackUserEvt = TlUserEvtReceived; + shciContext.io.Init(&Conf); + } + + return; +} + +static void Cmd_SetStatus(SHCI_TL_CmdStatus_t shcicmdstatus) +{ + if (shcicmdstatus == SHCI_TL_CmdBusy) { + if (StatusNotCallBackFunction != 0) { + StatusNotCallBackFunction(SHCI_TL_CmdBusy); + } + SHCICmdStatus = SHCI_TL_CmdBusy; + } else { + SHCICmdStatus = SHCI_TL_CmdAvailable; + if (StatusNotCallBackFunction != 0) { + StatusNotCallBackFunction(SHCI_TL_CmdAvailable); + } + } + + return; +} + +static void TlCmdEvtReceived(TL_EvtPacket_t *shcievt) +{ + (void)(shcievt); + shci_cmd_resp_release(0); /**< Notify the application the Cmd response has been received */ + + return; +} + +static void TlUserEvtReceived(TL_EvtPacket_t *shcievt) +{ + LST_insert_tail(&SHciAsynchEventQueue, (tListNode *)shcievt); + shci_notify_asynch_evt((void *) &SHciAsynchEventQueue); /**< Notify the application a full HCI event has been received */ + + return; +} + +static void OutputCmdTrace(TL_CmdPacket_t *pCmdBuffer) +{ + TL_SHCI_CMD_DBG_MSG("sys cmd: 0x%04X", pCmdBuffer->cmdserial.cmd.cmdcode); + + if (pCmdBuffer->cmdserial.cmd.plen != 0) { + TL_SHCI_CMD_DBG_MSG(" payload:"); + TL_SHCI_CMD_DBG_BUF(pCmdBuffer->cmdserial.cmd.payload, pCmdBuffer->cmdserial.cmd.plen, ""); + } + TL_SHCI_CMD_DBG_MSG("\r\n"); + + return; +} + +static void OutputRspTrace(TL_EvtPacket_t *p_rsp) +{ + switch (p_rsp->evtserial.evt.evtcode) { + case TL_BLEEVT_CC_OPCODE: + TL_SHCI_CMD_DBG_MSG("sys rsp: 0x%02X", p_rsp->evtserial.evt.evtcode); + TL_SHCI_CMD_DBG_MSG(" cmd opcode: 0x%02X", ((TL_CcEvt_t *)(p_rsp->evtserial.evt.payload))->cmdcode); + TL_SHCI_CMD_DBG_MSG(" status: 0x%02X", ((TL_CcEvt_t *)(p_rsp->evtserial.evt.payload))->payload[0]); + if ((p_rsp->evtserial.evt.plen - 4) != 0) { + TL_SHCI_CMD_DBG_MSG(" payload:"); + TL_SHCI_CMD_DBG_BUF(&((TL_CcEvt_t *)(p_rsp->evtserial.evt.payload))->payload[1], p_rsp->evtserial.evt.plen - 4, ""); + } + break; + + default: + TL_SHCI_CMD_DBG_MSG("unknown sys rsp received: %02X", p_rsp->evtserial.evt.evtcode); + break; + } + + TL_SHCI_CMD_DBG_MSG("\r\n"); + + return; +} + +static void OutputEvtTrace(TL_EvtPacket_t *phcievtbuffer) +{ + if (phcievtbuffer->evtserial.evt.evtcode != TL_BLEEVT_VS_OPCODE) { + TL_SHCI_EVT_DBG_MSG("unknown sys evt received: %02X", phcievtbuffer->evtserial.evt.evtcode); + } else { + TL_SHCI_EVT_DBG_MSG("sys evt: 0x%02X", phcievtbuffer->evtserial.evt.evtcode); + TL_SHCI_EVT_DBG_MSG(" subevtcode: 0x%04X", ((TL_AsynchEvt_t *)(phcievtbuffer->evtserial.evt.payload))->subevtcode); + if ((phcievtbuffer->evtserial.evt.plen - 2) != 0) { + TL_SHCI_EVT_DBG_MSG(" payload:"); + TL_SHCI_EVT_DBG_BUF(((TL_AsynchEvt_t *)(phcievtbuffer->evtserial.evt.payload))->payload, phcievtbuffer->evtserial.evt.plen - 2, ""); + } + } + + TL_SHCI_EVT_DBG_MSG("\r\n"); + + return; +} + +/* Weak implementation ----------------------------------------------------------------*/ +__WEAK void shci_cmd_resp_wait(uint32_t timeout) +{ + (void)timeout; + + CmdRspStatusFlag = SHCI_TL_CMD_RESP_WAIT; + while (CmdRspStatusFlag != SHCI_TL_CMD_RESP_RELEASE); + + return; +} + +__WEAK void shci_cmd_resp_release(uint32_t flag) +{ + (void)flag; + + CmdRspStatusFlag = SHCI_TL_CMD_RESP_RELEASE; + + return; +} + +#endif /* STM32WBxx */ + diff --git a/src/utility/STM32Cube_FW/shci_tl.h b/src/utility/STM32Cube_FW/shci_tl.h new file mode 100644 index 00000000..f6cc8043 --- /dev/null +++ b/src/utility/STM32Cube_FW/shci_tl.h @@ -0,0 +1,169 @@ +/** + ****************************************************************************** + * @file shci_tl.h + * @author MCD Application Team + * @brief System HCI command header for the system channel + ****************************************************************************** + * @attention + * + * <h2><center>© Copyright (c) 2019 STMicroelectronics. + * All rights reserved.</center></h2> + * + * This software component is licensed by ST under BSD 3-Clause license, + * the "License"; You may not use this file except in compliance with the + * License. You may obtain a copy of the License at: + * opensource.org/licenses/BSD-3-Clause + * + ****************************************************************************** + */ + + +#ifndef __SHCI_TL_H_ +#define __SHCI_TL_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "tl.h" + +/* Exported defines -----------------------------------------------------------*/ +typedef enum { + SHCI_TL_UserEventFlow_Disable, + SHCI_TL_UserEventFlow_Enable, +} SHCI_TL_UserEventFlowStatus_t; + +typedef enum { + SHCI_TL_CmdBusy, + SHCI_TL_CmdAvailable +} SHCI_TL_CmdStatus_t; + +/** + * @brief Structure used to manage the BUS IO operations. + * All the structure fields will point to functions defined at user level. + * @{ + */ +typedef struct { + int32_t (* Init)(void *pConf); /**< Pointer to SHCI TL function for the IO Bus initialization */ + int32_t (* DeInit)(void); /**< Pointer to SHCI TL function for the IO Bus de-initialization */ + int32_t (* Reset)(void); /**< Pointer to SHCI TL function for the IO Bus reset */ + int32_t (* Receive)(uint8_t *, uint16_t); /**< Pointer to SHCI TL function for the IO Bus data reception */ + int32_t (* Send)(uint8_t *, uint16_t); /**< Pointer to SHCI TL function for the IO Bus data transmission */ + int32_t (* DataAck)(uint8_t *, uint16_t *len); /**< Pointer to SHCI TL function for the IO Bus data ack reception */ + int32_t (* GetTick)(void); /**< Pointer to BSP function for getting the HAL time base timestamp */ +} tSHciIO; +/** + * @} + */ + +/** + * @brief Contain the SHCI context + * @{ + */ +typedef struct { + tSHciIO io; /**< Manage the BUS IO operations */ + void (* UserEvtRx)(void *pData); /**< User System events callback function pointer */ +} tSHciContext; + +typedef struct { + SHCI_TL_UserEventFlowStatus_t status; + TL_EvtPacket_t *pckt; +} tSHCI_UserEvtRxParam; + +typedef struct { + uint8_t *p_cmdbuffer; + void (* StatusNotCallBack)(SHCI_TL_CmdStatus_t status); +} SHCI_TL_HciInitConf_t; + +/** + * shci_send + * @brief Send an System HCI Command + * + * @param : cmd_code = Opcode of the command + * @param : len_cmd_payload = Length of the command payload + * @param : p_cmd_payload = Address of the command payload + * @param : p_rsp_status = Address of the full buffer holding the command complete event + * @retval : None + */ +void shci_send(uint16_t cmd_code, uint8_t len_cmd_payload, uint8_t *p_cmd_payload, TL_EvtPacket_t *p_rsp_status); + +/** + * @brief Register IO bus services. + * @param fops The SHCI IO structure managing the IO BUS + * @retval None + */ +void shci_register_io_bus(tSHciIO *fops); + +/** + * @brief Interrupt service routine that must be called when the system channel + * reports a packet has been received + * + * @param pdata Packet or event pointer + * @retval None + */ +void shci_notify_asynch_evt(void *pdata); + +/** + * @brief This function resume the User Event Flow which has been stopped on return + * from UserEvtRx() when the User Event has not been processed. + * + * @param None + * @retval None + */ +void shci_resume_flow(void); + + +/** + * @brief This function is called when an System HCI Command is sent to the CPU2 and the response is waited. + * It is called from the same context the System HCI command has been sent. + * It shall not return until the command response notified by shci_cmd_resp_release() is received. + * A weak implementation is available in shci_tl.c based on polling mechanism + * The user may re-implement this function in the application to improve performance : + * - It may use UTIL_SEQ_WaitEvt() API when using the Sequencer + * - It may use a semaphore when using cmsis_os interface + * + * @param timeout: Waiting timeout + * @retval None + */ +void shci_cmd_resp_wait(uint32_t timeout); + +/** + * @brief This function is called when an System HCI command is received from the CPU2. + * A weak implementation is available in shci_tl.c based on polling mechanism + * The user may re-implement this function in the application to improve performance : + * - It may use UTIL_SEQ_SetEvt() API when using the Sequencer + * - It may use a semaphore when using cmsis_os interface + * + * + * @param flag: Release flag + * @retval None + */ +void shci_cmd_resp_release(uint32_t flag); + + +/** + * @brief This process shall be called each time the shci_notify_asynch_evt notification is received + * + * @param None + * @retval None + */ + +void shci_user_evt_proc(void); + +/** + * @brief Initialize the System Host Controller Interface. + * This function must be called before any communication on the System Channel + * + * @param pData: System events callback function pointer + * This callback is triggered when an user event is received on + * the System Channel from CPU2. + * @param pConf: Configuration structure pointer + * @retval None + */ +void shci_init(void(* UserEvtRx)(void *pData), void *pConf); + +#ifdef __cplusplus +} +#endif + +#endif /* __SHCI_TL_H_ */ diff --git a/src/utility/STM32Cube_FW/stm32_wpan_common.h b/src/utility/STM32Cube_FW/stm32_wpan_common.h new file mode 100644 index 00000000..12f1a583 --- /dev/null +++ b/src/utility/STM32Cube_FW/stm32_wpan_common.h @@ -0,0 +1,143 @@ +/** + ****************************************************************************** + * @file stm32_wpan_common.h + * @author MCD Application Team + * @brief Common file to utilities + ****************************************************************************** + * @attention + * + * <h2><center>© Copyright (c) 2018 STMicroelectronics. + * All rights reserved.</center></h2> + * + * This software component is licensed by ST under Ultimate Liberty license + * SLA0044, the "License"; You may not use this file except in compliance with + * the License. You may obtain a copy of the License at: + * www.st.com/SLA0044 + * + ****************************************************************************** + */ + + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __STM32_WPAN_COMMON_H +#define __STM32_WPAN_COMMON_H + +#ifdef __cplusplus +extern "C" { +#endif + +#define __ASM __asm /*!< asm keyword for GNU Compiler */ +#define __INLINE inline /*!< inline keyword for GNU Compiler */ +#define __STATIC_INLINE static inline + +#include <stdint.h> +#include <string.h> +#include <stdio.h> +#include <stdlib.h> +#include <stdarg.h> +#include "cmsis_compiler.h" + +/* -------------------------------- * + * Basic definitions * + * -------------------------------- */ + +#undef NULL +#define NULL 0U + +#undef FALSE +#define FALSE 0U + +#undef TRUE +#define TRUE (!0U) + +/* -------------------------------- * + * Critical Section definition * + * -------------------------------- */ +#undef BACKUP_PRIMASK +#define BACKUP_PRIMASK() uint32_t primask_bit= __get_PRIMASK() + +#undef DISABLE_IRQ +#define DISABLE_IRQ() __disable_irq() + +#undef RESTORE_PRIMASK +#define RESTORE_PRIMASK() __set_PRIMASK(primask_bit) + +/* -------------------------------- * + * Macro delimiters * + * -------------------------------- */ +#undef M_BEGIN +#define M_BEGIN do { + +#undef M_END +#define M_END } while(0) + +/* -------------------------------- * + * Some useful macro definitions * + * -------------------------------- */ +#undef MAX +#define MAX(a, b) (((a) > (b)) ? (a) : (b)) + +#undef MIN +#define MIN(a, b) (((a) < (b)) ? (a) : (b)) + +#undef MODINC +#define MODINC( a, m ) M_BEGIN (a)++; if ((a)>=(m)) (a)=0; M_END + +#undef MODDEC +#define MODDEC( a, m ) M_BEGIN if ((a)==0) (a)=(m); (a)--; M_END + +#undef MODADD +#define MODADD( a, b, m ) M_BEGIN (a)+=(b); if ((a)>=(m)) (a)-=(m); M_END + +#undef MODSUB +#define MODSUB( a, b, m ) MODADD( a, (m)-(b), m ) + +#undef ALIGN +#ifdef WIN32 +#define ALIGN(n) +#else +#define ALIGN(n) __attribute__((aligned(n))) +#endif + +#undef PAUSE +#define PAUSE( t ) M_BEGIN \ + volatile int _i; \ + for ( _i = t; _i > 0; _i -- ); \ + M_END +#undef DIVF +#define DIVF( x, y ) ((x)/(y)) + +#undef DIVC +#define DIVC( x, y ) (((x)+(y)-1)/(y)) + +#undef DIVR +#define DIVR( x, y ) (((x)+((y)/2))/(y)) + +#undef SHRR +#define SHRR( x, n ) ((((x)>>((n)-1))+1)>>1) + +#undef BITN +#define BITN( w, n ) (((w)[(n)/32] >> ((n)%32)) & 1) + +#undef BITNSET +#define BITNSET( w, n, b ) M_BEGIN (w)[(n)/32] |= ((U32)(b))<<((n)%32); M_END + +/* -------------------------------- * + * Section attribute * + * -------------------------------- */ +#undef PLACE_IN_SECTION +#define PLACE_IN_SECTION( __x__ ) __attribute__((section (__x__))) + +/* ----------------------------------- * + * Packed usage (compiler dependent) * + * ----------------------------------- */ +#undef PACKED_STRUCT +#define PACKED_STRUCT struct __packed + +#ifdef __cplusplus +} +#endif + +#endif /*__STM32_WPAN_COMMON_H */ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/src/utility/STM32Cube_FW/stm_list.c b/src/utility/STM32Cube_FW/stm_list.c new file mode 100644 index 00000000..509b2b57 --- /dev/null +++ b/src/utility/STM32Cube_FW/stm_list.c @@ -0,0 +1,206 @@ +/** + ****************************************************************************** + * @file stm_list.c + * @author MCD Application Team + * @brief TCircular Linked List Implementation. + ****************************************************************************** + * @attention + * + * <h2><center>© Copyright (c) 2019 STMicroelectronics. + * All rights reserved.</center></h2> + * + * This software component is licensed by ST under BSD 3-Clause license, + * the "License"; You may not use this file except in compliance with the + * License. You may obtain a copy of the License at: + * opensource.org/licenses/BSD-3-Clause + * + ****************************************************************************** + */ + +#if defined(STM32WBxx) +/****************************************************************************** + * Include Files + ******************************************************************************/ +#include "stm_list.h" +#include "cmsis_gcc.h" +#include "stm32_wpan_common.h" + +/****************************************************************************** + * Function Definitions + ******************************************************************************/ +void LST_init_head(tListNode *listHead) +{ + listHead->next = listHead; + listHead->prev = listHead; +} + +bool LST_is_empty(tListNode *listHead) +{ + uint32_t primask_bit; + bool return_value; + + primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ + __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ + if (listHead->next == listHead) { + return_value = TRUE; + } else { + return_value = FALSE; + } + __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ + + return return_value; +} + +void LST_insert_head(tListNode *listHead, tListNode *node) +{ + uint32_t primask_bit; + + primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ + __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ + + node->next = listHead->next; + node->prev = listHead; + listHead->next = node; + (node->next)->prev = node; + + __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ +} + + +void LST_insert_tail(tListNode *listHead, tListNode *node) +{ + uint32_t primask_bit; + + primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ + __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ + + node->next = listHead; + node->prev = listHead->prev; + listHead->prev = node; + (node->prev)->next = node; + + __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ +} + + +void LST_remove_node(tListNode *node) +{ + uint32_t primask_bit; + + primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ + __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ + + (node->prev)->next = node->next; + (node->next)->prev = node->prev; + + __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ +} + + +void LST_remove_head(tListNode *listHead, tListNode **node) +{ + uint32_t primask_bit; + + primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ + __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ + + *node = listHead->next; + LST_remove_node(listHead->next); + + __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ +} + + +void LST_remove_tail(tListNode *listHead, tListNode **node) +{ + uint32_t primask_bit; + + primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ + __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ + + *node = listHead->prev; + LST_remove_node(listHead->prev); + + __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ +} + + +void LST_insert_node_after(tListNode *node, tListNode *ref_node) +{ + uint32_t primask_bit; + + primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ + __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ + + node->next = ref_node->next; + node->prev = ref_node; + ref_node->next = node; + (node->next)->prev = node; + + __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ +} + + +void LST_insert_node_before(tListNode *node, tListNode *ref_node) +{ + uint32_t primask_bit; + + primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ + __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ + + node->next = ref_node; + node->prev = ref_node->prev; + ref_node->prev = node; + (node->prev)->next = node; + + __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ +} + + +int LST_get_size(tListNode *listHead) +{ + int size = 0; + tListNode *temp; + uint32_t primask_bit; + + primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ + __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ + + temp = listHead->next; + while (temp != listHead) { + size++; + temp = temp->next; + } + + __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ + + return (size); +} + +void LST_get_next_node(tListNode *ref_node, tListNode **node) +{ + uint32_t primask_bit; + + primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ + __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ + + *node = ref_node->next; + + __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ +} + + +void LST_get_prev_node(tListNode *ref_node, tListNode **node) +{ + uint32_t primask_bit; + + primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ + __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ + + *node = ref_node->prev; + + __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ +} + +#endif /* STM32WBxx */ + diff --git a/src/utility/STM32Cube_FW/stm_list.h b/src/utility/STM32Cube_FW/stm_list.h new file mode 100644 index 00000000..b5f1cc8d --- /dev/null +++ b/src/utility/STM32Cube_FW/stm_list.h @@ -0,0 +1,58 @@ +/** + ****************************************************************************** + * @file stm_list.h + * @author MCD Application Team + * @brief Header file for linked list library. + ****************************************************************************** + * @attention + * + * <h2><center>© Copyright (c) 2019 STMicroelectronics. + * All rights reserved.</center></h2> + * + * This software component is licensed by ST under BSD 3-Clause license, + * the "License"; You may not use this file except in compliance with the + * License. You may obtain a copy of the License at: + * opensource.org/licenses/BSD-3-Clause + * + ****************************************************************************** + */ + + +#ifndef _STM_LIST_H_ +#define _STM_LIST_H_ + +/* Includes ------------------------------------------------------------------*/ + +#include "stdint.h" +#include "stdbool.h" + +typedef struct _tListNode { + struct _tListNode *next; + struct _tListNode *prev; +} tListNode; + +void LST_init_head(tListNode *listHead); + +bool LST_is_empty(tListNode *listHead); + +void LST_insert_head(tListNode *listHead, tListNode *node); + +void LST_insert_tail(tListNode *listHead, tListNode *node); + +void LST_remove_node(tListNode *node); + +void LST_remove_head(tListNode *listHead, tListNode **node); + +void LST_remove_tail(tListNode *listHead, tListNode **node); + +void LST_insert_node_after(tListNode *node, tListNode *ref_node); + +void LST_insert_node_before(tListNode *node, tListNode *ref_node); + +int LST_get_size(tListNode *listHead); + +void LST_get_next_node(tListNode *ref_node, tListNode **node); + +void LST_get_prev_node(tListNode *ref_node, tListNode **node); + +#endif /* _STM_LIST_H_ */ diff --git a/src/utility/STM32Cube_FW/tl.h b/src/utility/STM32Cube_FW/tl.h new file mode 100644 index 00000000..f8abf288 --- /dev/null +++ b/src/utility/STM32Cube_FW/tl.h @@ -0,0 +1,294 @@ +/** + ****************************************************************************** + * @file tl.h + * @author MCD Application Team + * @brief Header for tl module + ****************************************************************************** + * @attention + * + * <h2><center>© Copyright (c) 2019 STMicroelectronics. + * All rights reserved.</center></h2> + * + * This software component is licensed by ST under BSD 3-Clause license, + * the "License"; You may not use this file except in compliance with the + * License. You may obtain a copy of the License at: + * opensource.org/licenses/BSD-3-Clause + * + ****************************************************************************** + */ + + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __TL_H +#define __TL_H + +#ifdef __cplusplus +extern "C" { +#endif + + +/* Includes ------------------------------------------------------------------*/ +#include "stm32_wpan_common.h" + +/* Exported defines -----------------------------------------------------------*/ +#define TL_BLECMD_PKT_TYPE ( 0x01 ) +#define TL_ACL_DATA_PKT_TYPE ( 0x02 ) +#define TL_BLEEVT_PKT_TYPE ( 0x04 ) +#define TL_OTCMD_PKT_TYPE ( 0x08 ) +#define TL_OTRSP_PKT_TYPE ( 0x09 ) +#define TL_CLICMD_PKT_TYPE ( 0x0A ) +#define TL_OTNOT_PKT_TYPE ( 0x0C ) +#define TL_OTACK_PKT_TYPE ( 0x0D ) +#define TL_CLINOT_PKT_TYPE ( 0x0E ) +#define TL_CLIACK_PKT_TYPE ( 0x0F ) +#define TL_SYSCMD_PKT_TYPE ( 0x10 ) +#define TL_SYSRSP_PKT_TYPE ( 0x11 ) +#define TL_SYSEVT_PKT_TYPE ( 0x12 ) +#define TL_CLIRESP_PKT_TYPE ( 0x15 ) +#define TL_M0CMD_PKT_TYPE ( 0x16 ) +#define TL_LOCCMD_PKT_TYPE ( 0x20 ) +#define TL_LOCRSP_PKT_TYPE ( 0x21 ) +#define TL_TRACES_APP_PKT_TYPE ( 0x40 ) +#define TL_TRACES_WL_PKT_TYPE ( 0x41 ) + +#define TL_CMD_HDR_SIZE (4) +#define TL_EVT_HDR_SIZE (3) +#define TL_EVT_CS_PAYLOAD_SIZE (4) + +#define TL_BLEEVT_CC_OPCODE (0x0E) +#define TL_BLEEVT_CS_OPCODE (0x0F) +#define TL_BLEEVT_VS_OPCODE (0xFF) + +#define TL_BLEEVT_CS_PACKET_SIZE (TL_EVT_HDR_SIZE + sizeof(TL_CsEvt_t)) +#define TL_BLEEVT_CS_BUFFER_SIZE (sizeof(TL_PacketHeader_t) + TL_BLEEVT_CS_PACKET_SIZE) + +/* Exported types ------------------------------------------------------------*/ +/**< Packet header */ +typedef PACKED_STRUCT { + uint32_t *next; + uint32_t *prev; +} TL_PacketHeader_t; + +/******************************************************************************* + * Event type + */ + +/** + * This the payload of TL_Evt_t for a command status event + */ +typedef PACKED_STRUCT { + uint8_t status; + uint8_t numcmd; + uint16_t cmdcode; +} TL_CsEvt_t; + +/** + * This the payload of TL_Evt_t for a command complete event + */ +typedef PACKED_STRUCT { + uint8_t numcmd; + uint16_t cmdcode; + uint8_t payload[1]; +} TL_CcEvt_t; + +/** + * This the payload of TL_Evt_t for an asynchronous event + */ +typedef PACKED_STRUCT { + uint16_t subevtcode; + uint8_t payload[1]; +} TL_AsynchEvt_t; + +typedef PACKED_STRUCT { + uint8_t evtcode; + uint8_t plen; + uint8_t payload[1]; +} TL_Evt_t; + +typedef PACKED_STRUCT { + uint8_t type; + TL_Evt_t evt; +} TL_EvtSerial_t; + +/** + * This format shall be used for all events (asynchronous and command response) reported + * by the CPU2 except for the command response of a system command where the header is not there + * and the format to be used shall be TL_EvtSerial_t. + * Note: Be careful that the asynchronous events reported by the CPU2 on the system channel do + * include the header and shall use TL_EvtPacket_t format. Only the command response format on the + * system channel is different. + */ +typedef PACKED_STRUCT { + TL_PacketHeader_t header; + TL_EvtSerial_t evtserial; +} TL_EvtPacket_t; + +/***************************************************************************************** + * Command type + */ + +typedef PACKED_STRUCT { + uint16_t cmdcode; + uint8_t plen; + uint8_t payload[255]; +} TL_Cmd_t; + +typedef PACKED_STRUCT { + uint8_t type; + TL_Cmd_t cmd; +} TL_CmdSerial_t; + +typedef PACKED_STRUCT { + TL_PacketHeader_t header; + TL_CmdSerial_t cmdserial; +} TL_CmdPacket_t; + +/***************************************************************************************** + * HCI ACL DATA type + */ +typedef PACKED_STRUCT { + uint8_t type; + uint16_t handle; + uint16_t length; + uint8_t acl_data[1]; +} TL_AclDataSerial_t; + +typedef PACKED_STRUCT { + TL_PacketHeader_t header; + TL_AclDataSerial_t AclDataSerial; +} TL_AclDataPacket_t; + +typedef struct { + uint8_t *p_BleSpareEvtBuffer; + uint8_t *p_SystemSpareEvtBuffer; + uint8_t *p_AsynchEvtPool; + uint32_t AsynchEvtPoolSize; + uint8_t *p_TracesEvtPool; + uint32_t TracesEvtPoolSize; +} TL_MM_Config_t; + +typedef struct { + uint8_t *p_ThreadOtCmdRspBuffer; + uint8_t *p_ThreadCliRspBuffer; + uint8_t *p_ThreadNotAckBuffer; +} TL_TH_Config_t; + +typedef struct { + uint8_t *p_LldTestsCliCmdRspBuffer; + uint8_t *p_LldTestsM0CmdBuffer; +} TL_LLD_tests_Config_t; + +typedef struct { + uint8_t *p_LldBleCmdRspBuffer; + uint8_t *p_LldBleM0CmdBuffer; +} TL_LLD_BLE_Config_t; + +typedef struct { + uint8_t *p_Mac_802_15_4_CmdRspBuffer; + uint8_t *p_Mac_802_15_4_NotAckBuffer; +} TL_MAC_802_15_4_Config_t; + +typedef struct { + uint8_t *p_ZigbeeOtCmdRspBuffer; + uint8_t *p_ZigbeeNotAckBuffer; + uint8_t *p_ZigbeeNotifRequestBuffer; +} TL_ZIGBEE_Config_t; + +/** + * @brief Contain the BLE HCI Init Configuration + * @{ + */ +typedef struct { + void (* IoBusEvtCallBack)(TL_EvtPacket_t *phcievt); + void (* IoBusAclDataTxAck)(void); + uint8_t *p_cmdbuffer; + uint8_t *p_AclDataBuffer; +} TL_BLE_InitConf_t; + +/** + * @brief Contain the SYSTEM HCI Init Configuration + * @{ + */ +typedef struct { + void (* IoBusCallBackCmdEvt)(TL_EvtPacket_t *phcievt); + void (* IoBusCallBackUserEvt)(TL_EvtPacket_t *phcievt); + uint8_t *p_cmdbuffer; +} TL_SYS_InitConf_t; + +/* Exported constants --------------------------------------------------------*/ +/* External variables --------------------------------------------------------*/ +/* Exported macros -----------------------------------------------------------*/ +/* Exported functions ------------------------------------------------------- */ + +/****************************************************************************** + * GENERAL + ******************************************************************************/ +void TL_Enable(void); +void TL_Init(void); + +/****************************************************************************** + * BLE + ******************************************************************************/ +int32_t TL_BLE_Init(void *pConf); +int32_t TL_BLE_SendCmd(uint8_t *buffer, uint16_t size); +int32_t TL_BLE_SendAclData(uint8_t *buffer, uint16_t size); + +/****************************************************************************** + * SYSTEM + ******************************************************************************/ +int32_t TL_SYS_Init(void *pConf); +int32_t TL_SYS_SendCmd(uint8_t *buffer, uint16_t size); + +/****************************************************************************** + * THREAD + ******************************************************************************/ +void TL_THREAD_Init(TL_TH_Config_t *p_Config); +void TL_OT_SendCmd(void); +void TL_CLI_SendCmd(void); +void TL_OT_CmdEvtReceived(TL_EvtPacket_t *Otbuffer); +void TL_THREAD_NotReceived(TL_EvtPacket_t *Notbuffer); +void TL_THREAD_SendAck(void); +void TL_THREAD_CliSendAck(void); +void TL_THREAD_CliNotReceived(TL_EvtPacket_t *Notbuffer); + +/****************************************************************************** + * LLD TESTS + ******************************************************************************/ +void TL_LLDTESTS_Init(TL_LLD_tests_Config_t *p_Config); +void TL_LLDTESTS_SendCliCmd(void); +void TL_LLDTESTS_ReceiveCliRsp(TL_CmdPacket_t *Notbuffer); +void TL_LLDTESTS_SendCliRspAck(void); +void TL_LLDTESTS_ReceiveM0Cmd(TL_CmdPacket_t *Notbuffer); +void TL_LLDTESTS_SendM0CmdAck(void); + +/****************************************************************************** + * LLD BLE + ******************************************************************************/ +void TL_LLD_BLE_Init(TL_LLD_BLE_Config_t *p_Config); +void TL_LLD_BLE_SendCliCmd(void); +void TL_LLD_BLE_ReceiveCliRsp(TL_CmdPacket_t *Notbuffer); +void TL_LLD_BLE_SendCliRspAck(void); +void TL_LLD_BLE_ReceiveM0Cmd(TL_CmdPacket_t *Notbuffer); +void TL_LLD_BLE_SendM0CmdAck(void); +void TL_LLD_BLE_SendCmd(void); +void TL_LLD_BLE_ReceiveRsp(TL_CmdPacket_t *Notbuffer); +void TL_LLD_BLE_SendRspAck(void); +/****************************************************************************** + * MEMORY MANAGER + ******************************************************************************/ +void TL_MM_Init(TL_MM_Config_t *p_Config); +void TL_MM_EvtDone(TL_EvtPacket_t *hcievt); + +/****************************************************************************** + * TRACES + ******************************************************************************/ +void TL_TRACES_Init(void); +void TL_TRACES_EvtReceived(TL_EvtPacket_t *hcievt); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*__TL_H */ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/src/utility/STM32Cube_FW/tl_mbox.c b/src/utility/STM32Cube_FW/tl_mbox.c new file mode 100644 index 00000000..a235493d --- /dev/null +++ b/src/utility/STM32Cube_FW/tl_mbox.c @@ -0,0 +1,545 @@ +/** + ****************************************************************************** + * @file tl_mbox.c + * @author MCD Application Team + * @brief Transport layer for the mailbox interface + ****************************************************************************** + * @attention + * + * <h2><center>© Copyright (c) 2019 STMicroelectronics. + * All rights reserved.</center></h2> + * + * This software component is licensed by ST under BSD 3-Clause license, + * the "License"; You may not use this file except in compliance with the + * License. You may obtain a copy of the License at: + * opensource.org/licenses/BSD-3-Clause + * + ****************************************************************************** + */ + +#if defined(STM32WBxx) +/* Includes ------------------------------------------------------------------*/ +#include "stm32_wpan_common.h" +#include "hw.h" + +#include "stm_list.h" +#include "tl.h" +#include "mbox_def.h" + +/** + * These traces are not yet supported in an usual way in the delivery package + * They can enabled by adding the definition of TL_MM_DBG_EN in the preprocessor option in the IDE + */ +#if(TL_MM_DBG_EN != 0) + #include "app_conf.h" + #include "dbg_trace.h" +#endif + +#if (TL_MM_DBG_EN != 0) + #define TL_MM_DBG__MSG PRINT_MESG_DBG +#else + #define TL_MM_DBG__MSG(...) +#endif + +/* Private typedef -----------------------------------------------------------*/ +/* Private defines -----------------------------------------------------------*/ +/* Private macros ------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ + +/**< reference table */ +PLACE_IN_SECTION("MAPPING_TABLE") static volatile MB_RefTable_t TL_RefTable; +PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_DeviceInfoTable_t TL_DeviceInfoTable; +PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_BleTable_t TL_BleTable; +PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_ThreadTable_t TL_ThreadTable; +PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_LldTestsTable_t TL_LldTestsTable; +PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_LldBleTable_t TL_LldBleTable; +PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_SysTable_t TL_SysTable; +PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_MemManagerTable_t TL_MemManagerTable; +PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_TracesTable_t TL_TracesTable; + +/**< tables */ +PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode FreeBufQueue; +PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode TracesEvtQueue; +PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static uint8_t CsBuffer[sizeof(TL_PacketHeader_t) + TL_EVT_HDR_SIZE + sizeof(TL_CsEvt_t)]; +PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static tListNode EvtQueue; +PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static tListNode SystemEvtQueue; + + +static tListNode LocalFreeBufQueue; +static void (* BLE_IoBusEvtCallBackFunction)(TL_EvtPacket_t *phcievt); +static void (* BLE_IoBusAclDataTxAck)(void); +static void (* SYS_CMD_IoBusCallBackFunction)(TL_EvtPacket_t *phcievt); +static void (* SYS_EVT_IoBusCallBackFunction)(TL_EvtPacket_t *phcievt); + + +/* Global variables ----------------------------------------------------------*/ +/* Private function prototypes -----------------------------------------------*/ +static void SendFreeBuf(void); +static void OutputMemReleaseTrace(TL_EvtPacket_t *phcievt); + +/* Public Functions Definition ------------------------------------------------------*/ + +/****************************************************************************** + * GENERAL + ******************************************************************************/ +void TL_Enable(void) +{ + HW_IPCC_Enable(); + + return; +} + + +void TL_Init(void) +{ + TL_RefTable.p_device_info_table = &TL_DeviceInfoTable; + TL_RefTable.p_ble_table = &TL_BleTable; + TL_RefTable.p_thread_table = &TL_ThreadTable; + TL_RefTable.p_lld_tests_table = &TL_LldTestsTable; + TL_RefTable.p_lld_ble_table = &TL_LldBleTable; + TL_RefTable.p_sys_table = &TL_SysTable; + TL_RefTable.p_mem_manager_table = &TL_MemManagerTable; + TL_RefTable.p_traces_table = &TL_TracesTable; + + HW_IPCC_Init(); + + return; +} + +/****************************************************************************** + * BLE + ******************************************************************************/ +int32_t TL_BLE_Init(void *pConf) +{ + MB_BleTable_t *p_bletable; + + TL_BLE_InitConf_t *pInitHciConf = (TL_BLE_InitConf_t *) pConf; + + LST_init_head(&EvtQueue); + + p_bletable = TL_RefTable.p_ble_table; + + p_bletable->pcmd_buffer = pInitHciConf->p_cmdbuffer; + p_bletable->phci_acl_data_buffer = pInitHciConf->p_AclDataBuffer; + p_bletable->pcs_buffer = (uint8_t *)CsBuffer; + p_bletable->pevt_queue = (uint8_t *)&EvtQueue; + + HW_IPCC_BLE_Init(); + + BLE_IoBusEvtCallBackFunction = pInitHciConf->IoBusEvtCallBack; + BLE_IoBusAclDataTxAck = pInitHciConf->IoBusAclDataTxAck; + + return 0; +} + +int32_t TL_BLE_SendCmd(uint8_t *buffer, uint16_t size) +{ + (void)(buffer); + (void)(size); + + ((TL_CmdPacket_t *)(TL_RefTable.p_ble_table->pcmd_buffer))->cmdserial.type = TL_BLECMD_PKT_TYPE; + + HW_IPCC_BLE_SendCmd(); + + return 0; +} + +void HW_IPCC_BLE_RxEvtNot(void) +{ + TL_EvtPacket_t *phcievt; + + while (LST_is_empty(&EvtQueue) == FALSE) { + LST_remove_head(&EvtQueue, (tListNode **)&phcievt); + + BLE_IoBusEvtCallBackFunction(phcievt); + } + + return; +} + +int32_t TL_BLE_SendAclData(uint8_t *buffer, uint16_t size) +{ + (void)(buffer); + (void)(size); + + ((TL_AclDataPacket_t *)(TL_RefTable.p_ble_table->phci_acl_data_buffer))->AclDataSerial.type = TL_ACL_DATA_PKT_TYPE; + + HW_IPCC_BLE_SendAclData(); + + return 0; +} + +void HW_IPCC_BLE_AclDataAckNot(void) +{ + BLE_IoBusAclDataTxAck(); + + return; +} + +/****************************************************************************** + * SYSTEM + ******************************************************************************/ +int32_t TL_SYS_Init(void *pConf) +{ + MB_SysTable_t *p_systable; + + TL_SYS_InitConf_t *pInitHciConf = (TL_SYS_InitConf_t *) pConf; + + LST_init_head(&SystemEvtQueue); + p_systable = TL_RefTable.p_sys_table; + p_systable->pcmd_buffer = pInitHciConf->p_cmdbuffer; + p_systable->sys_queue = (uint8_t *)&SystemEvtQueue; + + HW_IPCC_SYS_Init(); + + SYS_CMD_IoBusCallBackFunction = pInitHciConf->IoBusCallBackCmdEvt; + SYS_EVT_IoBusCallBackFunction = pInitHciConf->IoBusCallBackUserEvt; + + return 0; +} + +int32_t TL_SYS_SendCmd(uint8_t *buffer, uint16_t size) +{ + (void)(buffer); + (void)(size); + + ((TL_CmdPacket_t *)(TL_RefTable.p_sys_table->pcmd_buffer))->cmdserial.type = TL_SYSCMD_PKT_TYPE; + + HW_IPCC_SYS_SendCmd(); + + return 0; +} + +void HW_IPCC_SYS_CmdEvtNot(void) +{ + SYS_CMD_IoBusCallBackFunction((TL_EvtPacket_t *)(TL_RefTable.p_sys_table->pcmd_buffer)); + + return; +} + +void HW_IPCC_SYS_EvtNot(void) +{ + TL_EvtPacket_t *p_evt; + + while (LST_is_empty(&SystemEvtQueue) == FALSE) { + LST_remove_head(&SystemEvtQueue, (tListNode **)&p_evt); + SYS_EVT_IoBusCallBackFunction(p_evt); + } + + return; +} + +/****************************************************************************** + * THREAD + ******************************************************************************/ +#ifdef THREAD_WB +void TL_THREAD_Init(TL_TH_Config_t *p_Config) +{ + MB_ThreadTable_t *p_thread_table; + + p_thread_table = TL_RefTable.p_thread_table; + + p_thread_table->clicmdrsp_buffer = p_Config->p_ThreadCliRspBuffer; + p_thread_table->otcmdrsp_buffer = p_Config->p_ThreadOtCmdRspBuffer; + p_thread_table->notack_buffer = p_Config->p_ThreadNotAckBuffer; + + HW_IPCC_THREAD_Init(); + + return; +} + +void TL_OT_SendCmd(void) +{ + ((TL_CmdPacket_t *)(TL_RefTable.p_thread_table->otcmdrsp_buffer))->cmdserial.type = TL_OTCMD_PKT_TYPE; + + HW_IPCC_OT_SendCmd(); + + return; +} + +void TL_CLI_SendCmd(void) +{ + ((TL_CmdPacket_t *)(TL_RefTable.p_thread_table->clicmdrsp_buffer))->cmdserial.type = TL_CLICMD_PKT_TYPE; + + HW_IPCC_CLI_SendCmd(); + + return; +} + +void TL_THREAD_SendAck(void) +{ + ((TL_CmdPacket_t *)(TL_RefTable.p_thread_table->notack_buffer))->cmdserial.type = TL_OTACK_PKT_TYPE; + + HW_IPCC_THREAD_SendAck(); + + return; +} + +void TL_THREAD_CliSendAck(void) +{ + ((TL_CmdPacket_t *)(TL_RefTable.p_thread_table->notack_buffer))->cmdserial.type = TL_OTACK_PKT_TYPE; + + HW_IPCC_THREAD_CliSendAck(); + + return; +} + +void HW_IPCC_OT_CmdEvtNot(void) +{ + TL_OT_CmdEvtReceived((TL_EvtPacket_t *)(TL_RefTable.p_thread_table->otcmdrsp_buffer)); + + return; +} + +void HW_IPCC_THREAD_EvtNot(void) +{ + TL_THREAD_NotReceived((TL_EvtPacket_t *)(TL_RefTable.p_thread_table->notack_buffer)); + + return; +} + +void HW_IPCC_THREAD_CliEvtNot(void) +{ + TL_THREAD_CliNotReceived((TL_EvtPacket_t *)(TL_RefTable.p_thread_table->clicmdrsp_buffer)); + + return; +} + +__WEAK void TL_OT_CmdEvtReceived(TL_EvtPacket_t *Otbuffer) {}; +__WEAK void TL_THREAD_NotReceived(TL_EvtPacket_t *Notbuffer) {}; +__WEAK void TL_THREAD_CliNotReceived(TL_EvtPacket_t *Notbuffer) {}; + +#endif /* THREAD_WB */ + +/****************************************************************************** + * LLD TESTS + ******************************************************************************/ +#ifdef LLD_TESTS_WB +void TL_LLDTESTS_Init(TL_LLD_tests_Config_t *p_Config) +{ + MB_LldTestsTable_t *p_lld_tests_table; + + p_lld_tests_table = TL_RefTable.p_lld_tests_table; + p_lld_tests_table->clicmdrsp_buffer = p_Config->p_LldTestsCliCmdRspBuffer; + p_lld_tests_table->m0cmd_buffer = p_Config->p_LldTestsM0CmdBuffer; + HW_IPCC_LLDTESTS_Init(); + return; +} + +void TL_LLDTESTS_SendCliCmd(void) +{ + ((TL_CmdPacket_t *)(TL_RefTable.p_lld_tests_table->clicmdrsp_buffer))->cmdserial.type = TL_CLICMD_PKT_TYPE; + HW_IPCC_LLDTESTS_SendCliCmd(); + return; +} + +void HW_IPCC_LLDTESTS_ReceiveCliRsp(void) +{ + TL_LLDTESTS_ReceiveCliRsp((TL_CmdPacket_t *)(TL_RefTable.p_lld_tests_table->clicmdrsp_buffer)); + return; +} + +void TL_LLDTESTS_SendCliRspAck(void) +{ + HW_IPCC_LLDTESTS_SendCliRspAck(); + return; +} + +void HW_IPCC_LLDTESTS_ReceiveM0Cmd(void) +{ + TL_LLDTESTS_ReceiveM0Cmd((TL_CmdPacket_t *)(TL_RefTable.p_lld_tests_table->m0cmd_buffer)); + return; +} + + +void TL_LLDTESTS_SendM0CmdAck(void) +{ + HW_IPCC_LLDTESTS_SendM0CmdAck(); + return; +} + +__WEAK void TL_LLDTESTS_ReceiveCliRsp(TL_CmdPacket_t *Notbuffer) {}; +__WEAK void TL_LLDTESTS_ReceiveM0Cmd(TL_CmdPacket_t *Notbuffer) {}; +#endif /* LLD_TESTS_WB */ + +/****************************************************************************** + * LLD BLE + ******************************************************************************/ +#ifdef LLD_BLE_WB +void TL_LLD_BLE_Init(TL_LLD_BLE_Config_t *p_Config) +{ + MB_LldBleTable_t *p_lld_ble_table; + + p_lld_ble_table = TL_RefTable.p_lld_ble_table; + p_lld_ble_table->cmdrsp_buffer = p_Config->p_LldBleCmdRspBuffer; + p_lld_ble_table->m0cmd_buffer = p_Config->p_LldBleM0CmdBuffer; + HW_IPCC_LLD_BLE_Init(); + return; +} + +void TL_LLD_BLE_SendCliCmd(void) +{ + ((TL_CmdPacket_t *)(TL_RefTable.p_lld_ble_table->cmdrsp_buffer))->cmdserial.type = TL_CLICMD_PKT_TYPE; + HW_IPCC_LLD_BLE_SendCliCmd(); + return; +} + +void HW_IPCC_LLD_BLE_ReceiveCliRsp(void) +{ + TL_LLD_BLE_ReceiveCliRsp((TL_CmdPacket_t *)(TL_RefTable.p_lld_ble_table->cmdrsp_buffer)); + return; +} + +void TL_LLD_BLE_SendCliRspAck(void) +{ + HW_IPCC_LLD_BLE_SendCliRspAck(); + return; +} + +void HW_IPCC_LLD_BLE_ReceiveM0Cmd(void) +{ + TL_LLD_BLE_ReceiveM0Cmd((TL_CmdPacket_t *)(TL_RefTable.p_lld_ble_table->m0cmd_buffer)); + return; +} + + +void TL_LLD_BLE_SendM0CmdAck(void) +{ + HW_IPCC_LLD_BLE_SendM0CmdAck(); + return; +} + +__WEAK void TL_LLD_BLE_ReceiveCliRsp(TL_CmdPacket_t *Notbuffer) {}; +__WEAK void TL_LLD_BLE_ReceiveM0Cmd(TL_CmdPacket_t *Notbuffer) {}; + +/* Transparent Mode */ +void TL_LLD_BLE_SendCmd(void) +{ + ((TL_CmdPacket_t *)(TL_RefTable.p_lld_ble_table->cmdrsp_buffer))->cmdserial.type = TL_CLICMD_PKT_TYPE; + HW_IPCC_LLD_BLE_SendCmd(); + return; +} + +void HW_IPCC_LLD_BLE_ReceiveRsp(void) +{ + TL_LLD_BLE_ReceiveRsp((TL_CmdPacket_t *)(TL_RefTable.p_lld_ble_table->cmdrsp_buffer)); + return; +} + +void TL_LLD_BLE_SendRspAck(void) +{ + HW_IPCC_LLD_BLE_SendRspAck(); + return; +} +#endif /* LLD_BLE_WB */ + +/****************************************************************************** + * MEMORY MANAGER + ******************************************************************************/ +void TL_MM_Init(TL_MM_Config_t *p_Config) +{ + static MB_MemManagerTable_t *p_mem_manager_table; + + LST_init_head(&FreeBufQueue); + LST_init_head(&LocalFreeBufQueue); + + p_mem_manager_table = TL_RefTable.p_mem_manager_table; + + p_mem_manager_table->blepool = p_Config->p_AsynchEvtPool; + p_mem_manager_table->blepoolsize = p_Config->AsynchEvtPoolSize; + p_mem_manager_table->pevt_free_buffer_queue = (uint8_t *)&FreeBufQueue; + p_mem_manager_table->spare_ble_buffer = p_Config->p_BleSpareEvtBuffer; + p_mem_manager_table->spare_sys_buffer = p_Config->p_SystemSpareEvtBuffer; + p_mem_manager_table->traces_evt_pool = p_Config->p_TracesEvtPool; + p_mem_manager_table->tracespoolsize = p_Config->TracesEvtPoolSize; + + return; +} + +void TL_MM_EvtDone(TL_EvtPacket_t *phcievt) +{ + LST_insert_tail(&LocalFreeBufQueue, (tListNode *)phcievt); + + OutputMemReleaseTrace(phcievt); + + HW_IPCC_MM_SendFreeBuf(SendFreeBuf); + + return; +} + +static void SendFreeBuf(void) +{ + tListNode *p_node; + + while (FALSE == LST_is_empty(&LocalFreeBufQueue)) { + LST_remove_head(&LocalFreeBufQueue, (tListNode **)&p_node); + LST_insert_tail((tListNode *)(TL_RefTable.p_mem_manager_table->pevt_free_buffer_queue), p_node); + } + + return; +} + +static void OutputMemReleaseTrace(TL_EvtPacket_t *phcievt) +{ + switch (phcievt->evtserial.evt.evtcode) { + case TL_BLEEVT_CS_OPCODE: + TL_MM_DBG__MSG("mm evt released: 0x%02X", phcievt->evtserial.evt.evtcode); + TL_MM_DBG__MSG(" cmd opcode: 0x%04X", ((TL_CsEvt_t *)(phcievt->evtserial.evt.payload))->cmdcode); + TL_MM_DBG__MSG(" buffer addr: 0x%08X", phcievt); + break; + + case TL_BLEEVT_CC_OPCODE: + TL_MM_DBG__MSG("mm evt released: 0x%02X", phcievt->evtserial.evt.evtcode); + TL_MM_DBG__MSG(" cmd opcode: 0x%04X", ((TL_CcEvt_t *)(phcievt->evtserial.evt.payload))->cmdcode); + TL_MM_DBG__MSG(" buffer addr: 0x%08X", phcievt); + break; + + case TL_BLEEVT_VS_OPCODE: + TL_MM_DBG__MSG("mm evt released: 0x%02X", phcievt->evtserial.evt.evtcode); + TL_MM_DBG__MSG(" subevtcode: 0x%04X", ((TL_AsynchEvt_t *)(phcievt->evtserial.evt.payload))->subevtcode); + TL_MM_DBG__MSG(" buffer addr: 0x%08X", phcievt); + break; + + default: + TL_MM_DBG__MSG("mm evt released: 0x%02X", phcievt->evtserial.evt.evtcode); + TL_MM_DBG__MSG(" buffer addr: 0x%08X", phcievt); + break; + } + + TL_MM_DBG__MSG("\r\n"); + + return; +} + +/****************************************************************************** + * TRACES + ******************************************************************************/ +void TL_TRACES_Init(void) +{ + LST_init_head(&TracesEvtQueue); + + TL_RefTable.p_traces_table->traces_queue = (uint8_t *)&TracesEvtQueue; + + HW_IPCC_TRACES_Init(); + + return; +} + +void HW_IPCC_TRACES_EvtNot(void) +{ + TL_EvtPacket_t *phcievt; + + while (LST_is_empty(&TracesEvtQueue) == FALSE) { + LST_remove_head(&TracesEvtQueue, (tListNode **)&phcievt); + TL_TRACES_EvtReceived(phcievt); + } + + return; +} + +__WEAK void TL_TRACES_EvtReceived(TL_EvtPacket_t *hcievt) +{ + (void)(hcievt); +} +#endif /* STM32WBxx */ +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ From 732ffed41b4b4ff32e9a8a23fd53fc0cc3867387 Mon Sep 17 00:00:00 2001 From: Francois Ramu <francois.ramu@st.com> Date: Thu, 12 Nov 2020 12:25:50 +0100 Subject: [PATCH 039/226] This BLE RF configuration has many unused define values which are removed there Signed-off-by: Francois Ramu <francois.ramu@st.com> --- src/utility/STM32Cube_FW/app_conf.h | 403 +--------------------------- 1 file changed, 13 insertions(+), 390 deletions(-) diff --git a/src/utility/STM32Cube_FW/app_conf.h b/src/utility/STM32Cube_FW/app_conf.h index 22c7b5c5..667dbbd4 100644 --- a/src/utility/STM32Cube_FW/app_conf.h +++ b/src/utility/STM32Cube_FW/app_conf.h @@ -29,116 +29,23 @@ ******************************************************************************/ /**< generic parameters ******************************************************/ +/* HCI related defines */ -/** - * Define Tx Power - */ -#define CFG_TX_POWER (0x18) /* -0.15dBm */ - -/** - * Define Advertising parameters - */ -#define CFG_ADV_BD_ADDRESS (0x7257acd87a6c) -#define CFG_FAST_CONN_ADV_INTERVAL_MIN (0x80) /**< 80ms */ -#define CFG_FAST_CONN_ADV_INTERVAL_MAX (0xa0) /**< 100ms */ -#define CFG_LP_CONN_ADV_INTERVAL_MIN (0x640) /**< 1s */ -#define CFG_LP_CONN_ADV_INTERVAL_MAX (0xfa0) /**< 2.5s */ - -/** - * Define IO Authentication - */ -#define CFG_BONDING_MODE (1) -#define CFG_FIXED_PIN (111111) -#define CFG_USED_FIXED_PIN (0) -#define CFG_ENCRYPTION_KEY_SIZE_MAX (16) -#define CFG_ENCRYPTION_KEY_SIZE_MIN (8) - -/** - * Define IO capabilities - */ -#define CFG_IO_CAPABILITY_DISPLAY_ONLY (0x00) -#define CFG_IO_CAPABILITY_DISPLAY_YES_NO (0x01) -#define CFG_IO_CAPABILITY_KEYBOARD_ONLY (0x02) -#define CFG_IO_CAPABILITY_NO_INPUT_NO_OUTPUT (0x03) -#define CFG_IO_CAPABILITY_KEYBOARD_DISPLAY (0x04) - -#define CFG_IO_CAPABILITY CFG_IO_CAPABILITY_DISPLAY_YES_NO - -/** - * Define MITM modes - */ -#define CFG_MITM_PROTECTION_NOT_REQUIRED (0x00) -#define CFG_MITM_PROTECTION_REQUIRED (0x01) +#define ACI_HAL_SET_TX_POWER_LEVEL 0xFC0F +#define ACI_WRITE_CONFIG_DATA_OPCODE 0xFC0C +#define ACI_READ_CONFIG_DATA_OPCODE 0xFC0D +#define MAX_HCI_ACL_PACKET_SIZE (sizeof(TL_PacketHeader_t) + 5 + 251) +#define HCI_RESET 0x0C03 -#define CFG_MITM_PROTECTION CFG_MITM_PROTECTION_REQUIRED - -/** - * Define Secure Connections Support - */ -#define CFG_SECURE_NOT_SUPPORTED (0x00) -#define CFG_SECURE_OPTIONAL (0x01) -#define CFG_SECURE_MANDATORY (0x02) - -#define CFG_SC_SUPPORT CFG_SECURE_OPTIONAL - -/** - * Define Keypress Notification Support - */ -#define CFG_KEYPRESS_NOT_SUPPORTED (0x00) -#define CFG_KEYPRESS_SUPPORTED (0x01) - -#define CFG_KEYPRESS_NOTIFICATION_SUPPORT CFG_KEYPRESS_NOT_SUPPORTED - -/** - * Numeric Comparison Answers - */ -#define YES (0x01) -#define NO (0x00) - -/** - * Device name configuration for Generic Access Service - */ -#define CFG_GAP_DEVICE_NAME "TEMPLATE" -#define CFG_GAP_DEVICE_NAME_LENGTH (8) - -/** - * Define PHY - */ -#define ALL_PHYS_PREFERENCE 0x00 -#define RX_2M_PREFERRED 0x02 -#define TX_2M_PREFERRED 0x02 -#define TX_1M 0x01 -#define TX_2M 0x02 -#define RX_1M 0x01 -#define RX_2M 0x02 - -/** -* Identity root key used to derive LTK and CSRK -*/ -#define CFG_BLE_IRK {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0} - -/** -* Encryption root key used to derive LTK and CSRK -*/ -#define CFG_BLE_ERK {0xfe,0xdc,0xba,0x09,0x87,0x65,0x43,0x21,0xfe,0xdc,0xba,0x09,0x87,0x65,0x43,0x21} +#ifndef BLE_SHARED_MEM_BYTE_ORDER + #define BLE_SHARED_MEM_BYTE_ORDER MSBFIRST +#endif +#define BLE_MODULE_SHARED_MEM_BUFFER_SIZE 128 -/* USER CODE BEGIN Generic_Parameters */ /** - * SMPS supply - * SMPS not used when Set to 0 - * SMPS used when Set to 1 + * Define Tx Power */ -#define CFG_USE_SMPS 1 -/* USER CODE END Generic_Parameters */ - -/**< specific parameters */ -/*****************************************************/ - -/** -* AD Element - Group B Feature -*/ -/* LSB - Second Byte */ -#define CFG_FEATURE_OTA_REBOOT (0x20) +#define CFG_TX_POWER (0x18) /* -0.15dBm */ /****************************************************************************** * BLE Stack @@ -245,291 +152,7 @@ * 0 : LL + Host */ #define CFG_BLE_LL_ONLY 1 -/****************************************************************************** - * Transport Layer - ******************************************************************************/ -/** - * Queue length of BLE Event - * This parameter defines the number of asynchronous events that can be stored in the HCI layer before - * being reported to the application. When a command is sent to the BLE core coprocessor, the HCI layer - * is waiting for the event with the Num_HCI_Command_Packets set to 1. The receive queue shall be large - * enough to store all asynchronous events received in between. - * When CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE is set to 27, this allow to store three 255 bytes long asynchronous events - * between the HCI command and its event. - * This parameter depends on the value given to CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE. When the queue size is to small, - * the system may hang if the queue is full with asynchronous events and the HCI layer is still waiting - * for a CC/CS event, In that case, the notification TL_BLE_HCI_ToNot() is called to indicate - * to the application a HCI command did not receive its command event within 30s (Default HCI Timeout). - */ -#define CFG_TLBLE_EVT_QUEUE_LENGTH 5 -/** - * This parameter should be set to fit most events received by the HCI layer. It defines the buffer size of each element - * allocated in the queue of received events and can be used to optimize the amount of RAM allocated by the Memory Manager. - * It should not exceed 255 which is the maximum HCI packet payload size (a greater value is a lost of memory as it will - * never be used) - * It shall be at least 4 to receive the command status event in one frame. - * The default value is set to 27 to allow receiving an event of MTU size in a single buffer. This value maybe reduced - * further depending on the application. - * - */ -#define CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE 255 /**< Set to 255 with the memory manager and the mailbox */ - -#define TL_BLE_EVENT_FRAME_SIZE ( TL_EVT_HDR_SIZE + CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE ) -/****************************************************************************** - * UART interfaces - ******************************************************************************/ - -/** - * Select UART interfaces - */ -#define CFG_DEBUG_TRACE_UART hw_uart1 -#define CFG_CONSOLE_MENU 0 -/****************************************************************************** - * USB interface - ******************************************************************************/ - -/** - * Enable/Disable USB interface - */ -#define CFG_USB_INTERFACE_ENABLE 0 - -/****************************************************************************** - * Low Power - ******************************************************************************/ -/** - * When set to 1, the low power mode is enable - * When set to 0, the device stays in RUN mode - */ -#define CFG_LPM_SUPPORTED 1 - -/****************************************************************************** - * Timer Server - ******************************************************************************/ -/** - * CFG_RTC_WUCKSEL_DIVIDER: This sets the RTCCLK divider to the wakeup timer. - * The higher is the value, the better is the power consumption and the accuracy of the timerserver - * The lower is the value, the finest is the granularity - * - * CFG_RTC_ASYNCH_PRESCALER: This sets the asynchronous prescaler of the RTC. It should as high as possible ( to output - * clock as low as possible) but the output clock should be equal or higher frequency compare to the clock feeding - * the wakeup timer. A lower clock speed would impact the accuracy of the timer server. - * - * CFG_RTC_SYNCH_PRESCALER: This sets the synchronous prescaler of the RTC. - * When the 1Hz calendar clock is required, it shall be sets according to other settings - * When the 1Hz calendar clock is not needed, CFG_RTC_SYNCH_PRESCALER should be set to 0x7FFF (MAX VALUE) - * - * CFG_RTCCLK_DIVIDER_CONF: - * Shall be set to either 0,2,4,8,16 - * When set to either 2,4,8,16, the 1Hhz calendar is supported - * When set to 0, the user sets its own configuration - * - * The following settings are computed with LSI as input to the RTC - */ -#define CFG_RTCCLK_DIVIDER_CONF 0 - -#if (CFG_RTCCLK_DIVIDER_CONF == 0) - /** - * Custom configuration - * It does not support 1Hz calendar - * It divides the RTC CLK by 16 - */ - #define CFG_RTCCLK_DIV (16) - #define CFG_RTC_WUCKSEL_DIVIDER (0) - #define CFG_RTC_ASYNCH_PRESCALER (CFG_RTCCLK_DIV - 1) - #define CFG_RTC_SYNCH_PRESCALER (0x7FFF) - -#else - - #if (CFG_RTCCLK_DIVIDER_CONF == 2) - /** - * It divides the RTC CLK by 2 - */ - #define CFG_RTC_WUCKSEL_DIVIDER (3) - #endif - - #if (CFG_RTCCLK_DIVIDER_CONF == 4) - /** - * It divides the RTC CLK by 4 - */ - #define CFG_RTC_WUCKSEL_DIVIDER (2) - #endif - - #if (CFG_RTCCLK_DIVIDER_CONF == 8) - /** - * It divides the RTC CLK by 8 - */ - #define CFG_RTC_WUCKSEL_DIVIDER (1) - #endif - - #if (CFG_RTCCLK_DIVIDER_CONF == 16) - /** - * It divides the RTC CLK by 16 - */ - #define CFG_RTC_WUCKSEL_DIVIDER (0) - #endif - - #define CFG_RTCCLK_DIV CFG_RTCCLK_DIVIDER_CONF - #define CFG_RTC_ASYNCH_PRESCALER (CFG_RTCCLK_DIV - 1) - #define CFG_RTC_SYNCH_PRESCALER (DIVR( LSE_VALUE, (CFG_RTC_ASYNCH_PRESCALER+1) ) - 1 ) - -#endif - -/** tick timer value in us */ -#define CFG_TS_TICK_VAL DIVR( (CFG_RTCCLK_DIV * 1000000), LSE_VALUE ) - -typedef enum { - CFG_TIM_PROC_ID_ISR, -} CFG_TimProcID_t; - -/****************************************************************************** - * Debug - ******************************************************************************/ -/** - * When set, this resets some hw resources to set the device in the same state than the power up - * The FW resets only register that may prevent the FW to run properly - * - * This shall be set to 0 in a final product - * - */ -#define CFG_HW_RESET_BY_FW 1 - -/** - * keep debugger enabled while in any low power mode when set to 1 - * should be set to 0 in production - */ -#define CFG_DEBUGGER_SUPPORTED 0 - -/** - * When set to 1, the traces are enabled in the BLE services - */ -#define CFG_DEBUG_BLE_TRACE 0 - -/** - * Enable or Disable traces in application - */ -#define CFG_DEBUG_APP_TRACE 0 - -#if (CFG_DEBUG_APP_TRACE != 0) - #define APP_DBG_MSG PRINT_MESG_DBG -#else - #define APP_DBG_MSG PRINT_NO_MESG -#endif - -#if ( (CFG_DEBUG_BLE_TRACE != 0) || (CFG_DEBUG_APP_TRACE != 0) ) - #define CFG_DEBUG_TRACE 1 -#endif - -#if (CFG_DEBUG_TRACE != 0) - #undef CFG_LPM_SUPPORTED - #undef CFG_DEBUGGER_SUPPORTED - #define CFG_LPM_SUPPORTED 0 - #define CFG_DEBUGGER_SUPPORTED 1 -#endif - -/** - * When CFG_DEBUG_TRACE_FULL is set to 1, the trace are output with the API name, the file name and the line number - * When CFG_DEBUG_TRACE_LIGHT is set to 1, only the debug message is output - * - * When both are set to 0, no trace are output - * When both are set to 1, CFG_DEBUG_TRACE_FULL is selected - */ -#define CFG_DEBUG_TRACE_LIGHT 0 -#define CFG_DEBUG_TRACE_FULL 0 - -#if (( CFG_DEBUG_TRACE != 0 ) && ( CFG_DEBUG_TRACE_LIGHT == 0 ) && (CFG_DEBUG_TRACE_FULL == 0)) - #undef CFG_DEBUG_TRACE_FULL - #undef CFG_DEBUG_TRACE_LIGHT - #define CFG_DEBUG_TRACE_FULL 0 - #define CFG_DEBUG_TRACE_LIGHT 1 -#endif - -#if ( CFG_DEBUG_TRACE == 0 ) - #undef CFG_DEBUG_TRACE_FULL - #undef CFG_DEBUG_TRACE_LIGHT - #define CFG_DEBUG_TRACE_FULL 0 - #define CFG_DEBUG_TRACE_LIGHT 0 -#endif - -/** - * When not set, the traces is looping on sending the trace over UART - */ -#define DBG_TRACE_USE_CIRCULAR_QUEUE 1 - -/** - * max buffer Size to queue data traces and max data trace allowed. - * Only Used if DBG_TRACE_USE_CIRCULAR_QUEUE is defined - */ -#define DBG_TRACE_MSG_QUEUE_SIZE 4096 -#define MAX_DBG_TRACE_MSG_SIZE 1024 - -/* USER CODE BEGIN Defines */ -#define CFG_LED_SUPPORTED 0 -#define CFG_BUTTON_SUPPORTED 1 -/* USER CODE END Defines */ - -/****************************************************************************** - * FreeRTOS - ******************************************************************************/ -#define CFG_SHCI_USER_EVT_PROCESS_NAME "SHCI_USER_EVT_PROCESS" -#define CFG_SHCI_USER_EVT_PROCESS_ATTR_BITS (0) -#define CFG_SHCI_USER_EVT_PROCESS_CB_MEM (0) -#define CFG_SHCI_USER_EVT_PROCESS_CB_SIZE (0) -#define CFG_SHCI_USER_EVT_PROCESS_STACK_MEM (0) -#define CFG_SHCI_USER_EVT_PROCESS_PRIORITY osPriorityNone -#define CFG_SHCI_USER_EVT_PROCESS_STACK_SIZE (128 * 7) - -#define CFG_HCI_USER_EVT_PROCESS_NAME "HCI_USER_EVT_PROCESS" -#define CFG_HCI_USER_EVT_PROCESS_ATTR_BITS (0) -#define CFG_HCI_USER_EVT_PROCESS_CB_MEM (0) -#define CFG_HCI_USER_EVT_PROCESS_CB_SIZE (0) -#define CFG_HCI_USER_EVT_PROCESS_STACK_MEM (0) -#define CFG_HCI_USER_EVT_PROCESS_PRIORITY osPriorityNone -#define CFG_HCI_USER_EVT_PROCESS_STACK_SIZE (128 * 8) - -#define CFG_ADV_UPDATE_PROCESS_NAME "ADV_UPDATE_PROCESS" -#define CFG_ADV_UPDATE_PROCESS_ATTR_BITS (0) -#define CFG_ADV_UPDATE_PROCESS_CB_MEM (0) -#define CFG_ADV_UPDATE_PROCESS_CB_SIZE (0) -#define CFG_ADV_UPDATE_PROCESS_STACK_MEM (0) -#define CFG_ADV_UPDATE_PROCESS_PRIORITY osPriorityNone -#define CFG_ADV_UPDATE_PROCESS_STACK_SIZE (128 * 6) - -#define CFG_HRS_PROCESS_NAME "HRS_PROCESS" -#define CFG_HRS_PROCESS_ATTR_BITS (0) -#define CFG_HRS_PROCESS_CB_MEM (0) -#define CFG_HRS_PROCESS_CB_SIZE (0) -#define CFG_HRS_PROCESS_STACK_MEM (0) -#define CFG_HRS_PROCESS_PRIORITY osPriorityNone -#define CFG_HRS_PROCESS_STACK_SIZE (128 * 5) - -/* USER CODE BEGIN FreeRTOS_Defines */ -#define PUSH_BUTTON_SW1_EXTI_IRQHandler EXTI4_IRQHandler -#define PUSH_BUTTON_SW2_EXTI_IRQHandler EXTI0_IRQHandler -#define PUSH_BUTTON_SW3_EXTI_IRQHandler EXTI1_IRQHandler -/* USER CODE END FreeRTOS_Defines */ - -/****************************************************************************** - * LOW POWER - ******************************************************************************/ -/** - * Supported requester to the MCU Low Power Manager - can be increased up to 32 - * It lists a bit mapping of all user of the Low Power Manager - */ -typedef enum { - CFG_LPM_APP, - CFG_LPM_APP_BLE, - /* USER CODE BEGIN CFG_LPM_Id_t */ - - /* USER CODE END CFG_LPM_Id_t */ -} CFG_LPM_Id_t; - -/****************************************************************************** - * OTP manager - ******************************************************************************/ -#define CFG_OTP_BASE_ADDRESS OTP_AREA_BASE - -#define CFG_OTP_END_ADRESS OTP_AREA_END_ADDR -#endif /*APP_CONF_H */ +#endif /* APP_CONF_H */ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ From 163bd85bf724a6d4f17c48ae051bd6ca1a108c3d Mon Sep 17 00:00:00 2001 From: Francois Ramu <francois.ramu@st.com> Date: Thu, 12 Nov 2020 13:21:31 +0100 Subject: [PATCH 040/226] Missing IPCC enable for C2 in several examples from stm32CubeWB This fix is coming from https://github.com/STMicroelectronics/STM32CubeWB/issues/19 Signed-off-by: Francois Ramu <francois.ramu@st.com> --- src/utility/STM32Cube_FW/hw_ipcc.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/utility/STM32Cube_FW/hw_ipcc.c b/src/utility/STM32Cube_FW/hw_ipcc.c index dbeb3eeb..925075f8 100644 --- a/src/utility/STM32Cube_FW/hw_ipcc.c +++ b/src/utility/STM32Cube_FW/hw_ipcc.c @@ -94,6 +94,12 @@ void IPCC_C1_TX_IRQHandler(void) ******************************************************************************/ void HW_IPCC_Enable(void) { + /** + * Such as IPCC IP available to the CPU2, it is required to keep the IPCC clock running + when FUS is running on CPU2 and CPU1 enters deep sleep mode + */ + LL_C2_AHB3_GRP1_EnableClock(LL_C2_AHB3_GRP1_PERIPH_IPCC); + /** * When the device is out of standby, it is required to use the EXTI mechanism to wakeup CPU2 */ From 19df1cb134e1e63f2151c7224eb9ceb224e82a4f Mon Sep 17 00:00:00 2001 From: Francois Ramu <francois.ramu@st.com> Date: Thu, 5 Nov 2020 18:41:53 +0100 Subject: [PATCH 041/226] Add shared memory transport layer for the stm32wb55 to use connection and services the BLE RF through IPM SharedMem The Rx data are stored in a fifo to manage connection, and ACL packets with context section to protect index when receiving data. The BLE init set the device address and power settings just after the HCI_RESET command sent The LSE clock is used for the RF and WakeUp capability by the variant. There is no BLEChip enum as only one chip at this time. Debug is activated with CONFIG_DEBUG enabled Signed-off-by: Francois Ramu <francois.ramu@st.com> --- src/utility/HCISharedMemTransport.cpp | 733 ++++++++++++++++++++++++++ src/utility/HCISharedMemTransport.h | 95 ++++ 2 files changed, 828 insertions(+) create mode 100644 src/utility/HCISharedMemTransport.cpp create mode 100644 src/utility/HCISharedMemTransport.h diff --git a/src/utility/HCISharedMemTransport.cpp b/src/utility/HCISharedMemTransport.cpp new file mode 100644 index 00000000..13b68298 --- /dev/null +++ b/src/utility/HCISharedMemTransport.cpp @@ -0,0 +1,733 @@ +/* + This file is part of the STM32duinoBLE library. + Copyright (c) 2019 STMicroelectronics. All rights reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ +#if defined(STM32WBxx) + +#include "HCISharedMemTransport.h" +#include "STM32Cube_FW/hw.h" + +/* Private variables ---------------------------------------------------------*/ +PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static TL_CmdPacket_t BleCmdBuffer; + +PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static uint8_t EvtPool[POOL_SIZE]; +PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static TL_CmdPacket_t SystemCmdBuffer; +PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static uint8_t + SystemSpareEvtBuffer[sizeof(TL_PacketHeader_t) + TL_EVT_HDR_SIZE + 255]; +PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static uint8_t + BleSpareEvtBuffer[sizeof(TL_PacketHeader_t) + TL_EVT_HDR_SIZE + 255]; +PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static uint8_t + HciAclDataBuffer[sizeof(TL_PacketHeader_t) + 5 + 251]; + + +/* global var used as semaphore to control incoming events */ +volatile bool sys_event; /* true : M0 core is already up and running */ +volatile bool acl_data_on; /* true : sending ACL data in progress, false : send is possible */ +volatile bool data_overflow; + +/* buffer to store the received packets */ +volatile uint8_t _rxbuff[BLE_MODULE_SHARED_MEM_BUFFER_SIZE]; +volatile uint16_t _read_index; /* fifo position when reading */ +volatile uint16_t _write_index; /* fifo position when receiving */ + +/* var of different device steps during init and receiving */ +volatile bool phase_bd_addr; +volatile bool phase_tx_power; +volatile bool phase_reset; +volatile bool phase_running; + +/** Bluetooth Device Address */ +static uint8_t bd_addr_udn[CONFIG_DATA_PUBADDR_LEN]; + +/* Private functions ---------------------------------------------------------*/ +/** + * TL Mailbox synchronisation means + */ + +/* returns true if sys_event was received, false otherwise */ +static bool sysevt_wait(void) +{ + /* sys_event remains false until event is received */ + for (unsigned long start = millis(); (millis() - start) < BLE_IPCC_TIMEOUT;) { + /* Wait for 10sec max - if not return an error */ + if (sys_event) { break; } + } + + if (!sys_event) { +#if defined(PRINT_IPCC_INFO) + printf("ERROR: sys_evt timeout\r\n"); +#endif /*(PRINT_IPCC_INFO)*/ + /* no event received, timeout occurs */ + return false; + } + /* release immediately, now that M0 runs */ + return true; +} + +/* WEAK callbacks from the BLE TL driver - will be called under Interrupt */ +static void sysevt_received(void *pdata) +{ + UNUSED(pdata); + /* For now only READY event is received, so we know this is it */ + __disable_irq(); + sys_event = true; + __enable_irq(); + /* But later on ... we'll have to parse the answer */ +} + +/* returns true if sysevt was already received, which means M0 core is + * already up and running */ +static bool sysevt_check(void) +{ + /* Check if system is UP and running already */ + for (unsigned long start = millis(); (millis() - start) < 10;) { + /* Wait for 10ms max - if not return an error */ + if (sys_event) { break; } + } + if (sys_event) { + /* release immediately as M0 already runs */ + return true; + } + return false; +} + +static void acl_data_ack(void) +{ + /** + * The current implementation assumes the taskGUI will not send a new HCI ACL DATA packet before this ack is received + * ( which means the CPU2 has handled the previous packet ) + * In order to implement a secure mechanism, it is required either + * - a flow control with the stack + * - a local pool of buffer to store packets received from the stack + */ + __disable_irq(); + acl_data_on = false; + __enable_irq(); +} + +static bool acl_data_wait(void) +{ + /* Wait 10 sec for previous ACL command to be ack'ed by Low Layers + * before sending the next one */ + for (unsigned long start = millis(); (millis() - start) < BLE_IPCC_TIMEOUT;) { + /* Wait for 10sec max - if not return an error */ + if (!acl_data_on) { break; } + } + if (acl_data_on) { + /* no event received, timeout occurs */ +#if defined(PRINT_IPCC_INFO) + printf("ERROR: acl data timeout\r\n"); +#endif /*(PRINT_IPCC_INFO)*/ + return false; + } + /* release immediately, now that M0 runs */ + __disable_irq(); + acl_data_on = false; + __enable_irq(); + return true; +} + +static void syscmd_status_not(SHCI_TL_CmdStatus_t status) +{ +#if defined(PRINT_IPCC_INFO) + printf("syscmd_status_not, status:%d\r\n", status); +#else + UNUSED(status); +#endif /*(PRINT_IPCC_INFO)*/ +} + +/* to received BLE packet from the SharedMem */ +void evt_received(TL_EvtPacket_t *hcievt) +{ + uint16_t len = 0; + + /* We need to memcpy the data before passing to higher layers. + * The received packet is copied in the _rxbuff + * but it must not exceed the BLE_MODULE_SHARED_MEM_BUFFER_SIZE + */ + switch (hcievt->evtserial.type) { + case TL_BLEEVT_PKT_TYPE: { + /* before starting the running_phase', a RESET command (0x0C03) is sent + * by the HCI. Then this evt packet is temporarily kept in the _rxbuff + * the set_bd_address (0xFC0C) and the set_tw_power (0xFC0F) commands are sent. + * Only when both evt are received (not store in the _rxbuffer), + * the Reset packet is handled at HCI layer : the running_phase begins + */ + if (phase_running == false) { + /* check the Rx event of complete the previous bd_addr opcode 0xFC0C */ + if ((hcievt->evtserial.evt.evtcode == TL_BLEEVT_CC_OPCODE) && + (hcievt->evtserial.evt.payload[0] == 0x01) && + (hcievt->evtserial.evt.payload[1] == 0x0C) && + (hcievt->evtserial.evt.payload[2] == 0xFC)) { + phase_bd_addr = true; + if (hcievt->evtserial.evt.payload[3] != 0) { +#if defined(PRINT_IPCC_INFO) + printf("Error: wrong BD Addr\r\n"); +#endif /*(PRINT_IPCC_INFO)*/ + } + /* rx data is no more useful : not stored in the _rxbuff */ + break; + } + /* check the Rx event of complete the previous tx power opcode 0xFC0F */ + if ((hcievt->evtserial.evt.evtcode == TL_BLEEVT_CC_OPCODE) && + (hcievt->evtserial.evt.payload[0] == 0x01) && + (hcievt->evtserial.evt.payload[1] == 0x0F) && + (hcievt->evtserial.evt.payload[2] == 0xFC)) { + phase_tx_power = true; + if (hcievt->evtserial.evt.payload[3] != 0) { +#if defined(PRINT_IPCC_INFO) + printf("Error: wrong Tx power\r\n"); +#endif /*(PRINT_IPCC_INFO)*/ + } + /* rx data is no more useful : not stored in the _rxbuff */ + break; + } + /* check if the reset phase is in progress (opcode is 0x0C03) */ + if ((hcievt->evtserial.evt.evtcode == TL_BLEEVT_CC_OPCODE) && + (hcievt->evtserial.evt.payload[0] == 0x01) && + (hcievt->evtserial.evt.payload[1] == 0x03) && + (hcievt->evtserial.evt.payload[2] == 0x0C)) { + phase_reset = true; +#if defined(PRINT_IPCC_INFO) + if (hcievt->evtserial.evt.payload[3] != 0) { + printf("Error: wrong reset\r\n"); + } +#endif /*(PRINT_IPCC_INFO)*/ + } + } + __disable_irq(); + /* store received data in the _rxbuff buffer */ + len = hcievt->evtserial.evt.plen + TL_EVT_HDR_SIZE; + if (len < BLE_MODULE_SHARED_MEM_BUFFER_SIZE - _write_index) { + /* at the position of the _write_index */ + memcpy((uint8_t *)&_rxbuff[_write_index], (uint8_t *)&hcievt->evtserial, len); + /* move index */ + _write_index += len; + } else { + data_overflow = true; + } + __enable_irq(); + } + break; + case TL_ACL_DATA_PKT_TYPE: { + TL_AclDataSerial_t *acl = &(((TL_AclDataPacket_t *)hcievt)->AclDataSerial); + __disable_irq(); + len = acl->length + 5; + if (len < BLE_MODULE_SHARED_MEM_BUFFER_SIZE - _write_index) { + memcpy((uint8_t *)&_rxbuff[_write_index], (uint8_t *)acl, len); + /* move index */ + _write_index += len; + } else { + data_overflow = true; + } + __enable_irq(); + } + break; + default: + /* should not happen */ +#if defined(PRINT_IPCC_INFO) + printf("BLE TL evt_received, wrong type:%d\r\n", hcievt->evtserial.type); + while(1); /* let's block to check */ +#endif /*(PRINT_IPCC_INFO)*/ + break; + } +#if defined(PRINT_IPCC_INFO) + if (data_overflow) { + printf("Error: data read overflow\r\n"); + } +#endif /*(PRINT_IPCC_INFO)*/ + + /* In case Event belongs to the Evt Pool we need to inform */ + if (((uint8_t *)hcievt >= EvtPool) && ((uint8_t *)hcievt < (EvtPool + POOL_SIZE))) { + /* Free the message from shared memory */ + TL_MM_EvtDone(hcievt); + } +} + +/* to send BLE packet to the SharedMem */ +uint16_t mbox_write(uint8_t type, uint16_t len, const uint8_t *pData) + { + TL_CmdPacket_t *bleCmdBuf = &BleCmdBuffer; + // Note: Until enum is available + // type 01 Command + // type 02 ACL DATA + // type 03 SCO Voice (not supported) + // type 04 event - uplink (not supported) + switch (type) { + case 1: { //BLE command + bleCmdBuf->cmdserial.type = type; // for now this param is overwritten in TL_BLE_SendCmd + bleCmdBuf->cmdserial.cmd.plen = len; + memcpy((void *) &bleCmdBuf->cmdserial.cmd, pData, len); + /* We're tracing here the command, after copy in shared mem but before M0 trigger. */ + TL_BLE_SendCmd(NULL, 0); // unused parameters for now + } + break; + case 2: { //ACL DATA + if (!acl_data_wait()) { +#if defined(PRINT_IPCC_INFO) + printf("ERROR: previous ACL message not ACK'd\r\n"); +#endif /*(PRINT_IPCC_INFO)*/ + /* return number of bytes sent, 0 in this error case */ + return 0; + } + TL_AclDataSerial_t *aclDataSerial = (TL_AclDataSerial_t *)(HciAclDataBuffer + sizeof(TL_PacketHeader_t)); + aclDataSerial->type = type; // for now this param is overwritten in TL_BLE_SendCmd + memcpy(HciAclDataBuffer + + sizeof(TL_PacketHeader_t) + sizeof(type), pData, len); + TL_BLE_SendAclData(NULL, 0); // unused parameters for now + __disable_irq(); + acl_data_on = true; /* data being send */ + __enable_irq(); + } + break; + default: +#if defined(PRINT_IPCC_INFO) + printf("ERROR: not supported type\r\n"); +#endif /*(PRINT_IPCC_INFO)*/ + /* return number of bytes sent, 0 in this error case */ + len = 0; + break; + } + return len; + } + +/** + * Few utilities functions + */ +/* This function fills in a BD address table */ +static bool get_bd_address(uint8_t *bd_addr) +{ + uint32_t udn; + uint32_t company_id; + uint32_t device_id; + bool bd_found; + + udn = LL_FLASH_GetUDN(); + + if (udn != 0xFFFFFFFF) { + /* "Found Unique Device Number: %#06x", udn) */ + + company_id = LL_FLASH_GetSTCompanyID(); + device_id = LL_FLASH_GetDeviceID(); + + bd_addr[0] = (uint8_t)(udn & 0x000000FF); + bd_addr[1] = (uint8_t)((udn & 0x0000FF00) >> 8); + bd_addr[2] = (uint8_t)((udn & 0x00FF0000) >> 16); + bd_addr[3] = (uint8_t)device_id; + bd_addr[4] = (uint8_t)(company_id & 0x000000FF); + bd_addr[5] = (uint8_t)((company_id & 0x0000FF00) >> 8); + + bd_found = true; + } else { + bd_addr =NULL; + bd_found = false; + } + + return bd_found; +} + +static void init_debug(void) +{ + /* In case of debug profile, configure debugger support */ + +#if defined(CONFIG_DEBUG) +#if defined(PRINT_IPCC_INFO) + printf("init_debug ENABLED\r\n"); +#endif /*(PRINT_IPCC_INFO)*/ + /** + * Keep debugger enabled while in any low power mode + */ + HAL_DBGMCU_EnableDBGSleepMode(); + HAL_DBGMCU_EnableDBGStopMode(); + HAL_DBGMCU_EnableDBGStandbyMode(); + + /* Enable debugger: Debug power up request wakeup EXTI line 48 */ + LL_EXTI_EnableIT_32_63(LL_EXTI_LINE_48); + LL_C2_EXTI_EnableIT_32_63(LL_EXTI_LINE_48); + +#endif /* CONFIG_DEBUG */ +} + +/* Class definition ----------------------------------------------------------*/ + +HCISharedMemTransportClass::HCISharedMemTransportClass() +{ + _read_index = 0; /* fifo position when reading */ + _write_index = 0; /* fifo position when receiving */ + + memset((void *)_rxbuff, 0, sizeof(_rxbuff)); + + sys_event = false; + acl_data_on = false; + + data_overflow = false; + + phase_bd_addr = false; + phase_tx_power = false; + phase_reset = false; + phase_running = false; +} + +HCISharedMemTransportClass::~HCISharedMemTransportClass() +{ +} + +int HCISharedMemTransportClass::begin() +{ + int status = 1; + /* clean data Rx variables */ + _read_index = 0; + _write_index = 0; + + memset((void *)_rxbuff, 0, sizeof(_rxbuff)); + + /* Check whether M0 sub-system was started already by + * checking if the system event was already received + * before. If it was not, then go thru all init. */ + if (!sysevt_check()) { + start_ble_rf(); + init_debug(); + /* Take BLE out of reset */ + stm32wb_reset(); + /* "C2 unlocking" */ + transport_init(); + /* At this stage, we got the ready event, + * passed thru TL_SYS_EvtReceived */ + + WirelessFwInfo_t wireless_info_instance; + WirelessFwInfo_t *p_wireless_info = &wireless_info_instance; + SHCI_GetWirelessFwInfo(p_wireless_info); +#if defined(PRINT_IPCC_INFO) + printf("WB copro FW version = %d.%d.%d\r\n", p_wireless_info->VersionMajor, p_wireless_info->VersionMinor, p_wireless_info->VersionSub); +#endif /*(PRINT_IPCC_INFO)*/ + + /* Now start BLE service on firmware side, using Vendor specific + * command on the System Channel + */ + status = stm32wb_start_ble(); + + /* Once reset complete event is received we will need + * to send a few more commands: + * set bd addr with bt_ipm_set_addr(); + * during the HCI rest command */ + } + /* IPM Channel is now open */ +#if defined(PRINT_IPCC_INFO) + printf("IPM Channel Open Completed\r\n"); +#endif /*(PRINT_IPCC_INFO)*/ + + return status; +} + +void HCISharedMemTransportClass::end() +{ + /* M0 sub-system is already on (sys_event) */ + acl_data_on = false; + data_overflow = false; + + /* the HCI RESET command ready to be processed again */ + phase_bd_addr = false; + phase_tx_power = false; + phase_reset = false; + phase_running = false; +} + +void HCISharedMemTransportClass::wait(unsigned long timeout) +{ + for (unsigned long start = millis(); (millis() - start) < timeout;) + { + if (available()) + { + break; + } + } +} + +int HCISharedMemTransportClass::available() +{ + /* assuming the reset is already achieved, + * the LL-only mode is already configured. */ + + if (_read_index != _write_index) { + return 1; + } else if (data_overflow) { + __disable_irq(); + data_overflow = false; + __enable_irq(); + if (_read_index != _write_index) { + return 1; + } + } + + return 0; +} + +int HCISharedMemTransportClass::peek() +{ + int peek_val = -1; +__disable_irq(); + if(_read_index != _write_index) + { + peek_val = _rxbuff[_read_index]; + } +__enable_irq(); + return peek_val; +} + +int HCISharedMemTransportClass::read() +{ + int read_val = -1; +__disable_irq(); + if(_read_index != _write_index) + { + read_val = _rxbuff[_read_index]; + _read_index++; + if(_read_index == _write_index) + { + /* Reset buffer index */ + _read_index = 0; + _write_index = 0; + } + } +__enable_irq(); + return read_val; +} + +size_t HCISharedMemTransportClass::write(const uint8_t* data, size_t length) +{ + const uint8_t* msg_data; + msg_data = &data[1]; + + /* capture the HCI reset send command opcode = 0x0C03 + * After HCI reset event complete in the evt_received(), + * the bd_addr and tx_power must be sent + * before the phase_running begins. + */ + if (phase_running) { + return mbox_write(data[0], (length-1), msg_data);; + } + if ( (data[1] == 0x03) && (data[2] == 0x0C)) { + phase_reset = false; + + mbox_write(data[0], (length-1), msg_data); + + /* capture event after HCI_RESET */ + while (!phase_reset); + + /* set the bd add */ + if (!bt_ipm_set_addr()) { + /* in case of error, no data are written */ + return 0; + } + /* wait for the Rx complete */ + while (!phase_bd_addr); + /* this sequence is now complete */ + + /* set the Tx power */ + bt_ipm_set_power(); + /* wait for the Rx complete */ + while (!phase_tx_power); + + /* this sequence is now complete */ + phase_running = true; + + return (length-1); /* mbox_size of the HCI reset command */ + } + return 0; /* mbox_size of the HCI reset command */ +} + +//private: +void HCISharedMemTransportClass::start_ble_rf(void) +{ + if ((LL_RCC_IsActiveFlag_PINRST()) && (!LL_RCC_IsActiveFlag_SFTRST())) { + /* Simulate power off reset */ + LL_PWR_EnableBkUpAccess(); + LL_PWR_EnableBkUpAccess(); + LL_RCC_ForceBackupDomainReset(); + LL_RCC_ReleaseBackupDomainReset(); + } + + /* Switch OFF LSI as LSE is the source clock */ + LL_RCC_LSI2_Disable(); +} + +void HCISharedMemTransportClass::stm32wb_reset(void) + { + // Reset IPCC + LL_AHB3_GRP1_EnableClock(LL_AHB3_GRP1_PERIPH_IPCC); + + LL_C1_IPCC_ClearFlag_CHx( + IPCC, + LL_IPCC_CHANNEL_1 | LL_IPCC_CHANNEL_2 | LL_IPCC_CHANNEL_3 | LL_IPCC_CHANNEL_4 + | LL_IPCC_CHANNEL_5 | LL_IPCC_CHANNEL_6); + + LL_C2_IPCC_ClearFlag_CHx( + IPCC, + LL_IPCC_CHANNEL_1 | LL_IPCC_CHANNEL_2 | LL_IPCC_CHANNEL_3 | LL_IPCC_CHANNEL_4 + | LL_IPCC_CHANNEL_5 | LL_IPCC_CHANNEL_6); + + LL_C1_IPCC_DisableTransmitChannel( + IPCC, + LL_IPCC_CHANNEL_1 | LL_IPCC_CHANNEL_2 | LL_IPCC_CHANNEL_3 | LL_IPCC_CHANNEL_4 + | LL_IPCC_CHANNEL_5 | LL_IPCC_CHANNEL_6); + + LL_C2_IPCC_DisableTransmitChannel( + IPCC, + LL_IPCC_CHANNEL_1 | LL_IPCC_CHANNEL_2 | LL_IPCC_CHANNEL_3 | LL_IPCC_CHANNEL_4 + | LL_IPCC_CHANNEL_5 | LL_IPCC_CHANNEL_6); + + LL_C1_IPCC_DisableReceiveChannel( + IPCC, + LL_IPCC_CHANNEL_1 | LL_IPCC_CHANNEL_2 | LL_IPCC_CHANNEL_3 | LL_IPCC_CHANNEL_4 + | LL_IPCC_CHANNEL_5 | LL_IPCC_CHANNEL_6); + + LL_C2_IPCC_DisableReceiveChannel( + IPCC, + LL_IPCC_CHANNEL_1 | LL_IPCC_CHANNEL_2 | LL_IPCC_CHANNEL_3 | LL_IPCC_CHANNEL_4 + | LL_IPCC_CHANNEL_5 | LL_IPCC_CHANNEL_6); + + /* IPCC default IRQ handlers: IPCC_C1_TX_IRQHandler & IPCC_C1_RX_IRQHandler + * are mapped in the flash mem area, so that NVIC does not need to SetVector + */ + } + +int HCISharedMemTransportClass::stm32wb_start_ble(void) +{ + SHCI_C2_Ble_Init_Cmd_Packet_t ble_init_cmd_packet = { + 0, 0, 0, /**< Header unused */ + 0, /** pBleBufferAddress not used */ + 0, /** BleBufferSize not used */ + CFG_BLE_NUM_GATT_ATTRIBUTES, + CFG_BLE_NUM_GATT_SERVICES, + CFG_BLE_ATT_VALUE_ARRAY_SIZE, + CFG_BLE_NUM_LINK, + CFG_BLE_DATA_LENGTH_EXTENSION, + CFG_BLE_PREPARE_WRITE_LIST_SIZE, + CFG_BLE_MBLOCK_COUNT, + CFG_BLE_MAX_ATT_MTU, + CFG_BLE_SLAVE_SCA, + CFG_BLE_MASTER_SCA, + CFG_BLE_LSE_SOURCE, + CFG_BLE_MAX_CONN_EVENT_LENGTH, + CFG_BLE_HSE_STARTUP_TIME, + CFG_BLE_VITERBI_MODE, + CFG_BLE_LL_ONLY, + 0 /** TODO Should be read from HW */ + }; + /** + * Starts the BLE Stack on CPU2 + */ + if (SHCI_C2_BLE_Init(&ble_init_cmd_packet) == SHCI_Success) { + return 1; + } + return 0; +} + +void HCISharedMemTransportClass::transport_init(void) + { + TL_MM_Config_t tl_mm_config; + TL_BLE_InitConf_t tl_ble_config; + /* STM32WB offers a System Channel HCI interface for + offering system services, with proprietary commands. + System Channel must be used as well for starting up + BLE service so we need to initialize it. */ + SHCI_TL_HciInitConf_t shci_init_config; + + /**< Reference table initialization */ + TL_Init(); + + /**< System channel initialization */ + shci_init_config.p_cmdbuffer = (uint8_t *)&SystemCmdBuffer; + shci_init_config.StatusNotCallBack = syscmd_status_not; + shci_init(sysevt_received, (void *) &shci_init_config); + + /**< Memory Manager channel initialization */ + tl_mm_config.p_BleSpareEvtBuffer = BleSpareEvtBuffer; + tl_mm_config.p_SystemSpareEvtBuffer = SystemSpareEvtBuffer; + tl_mm_config.p_AsynchEvtPool = EvtPool; + tl_mm_config.AsynchEvtPoolSize = POOL_SIZE; + TL_MM_Init(&tl_mm_config); + + TL_Enable(); + + /* At this stage, we'll need to wait for ready event, + * passed thru TL_SYS_EvtReceived */ + if (!sysevt_wait()) { +#if defined(PRINT_IPCC_INFO) + printf("ERROR booting WB controller\r\n"); +#endif /*(PRINT_IPCC_INFO)*/ + } else { + /**< BLE channel initialization */ + tl_ble_config.p_cmdbuffer = (uint8_t *)&BleCmdBuffer; + tl_ble_config.p_AclDataBuffer = HciAclDataBuffer; + tl_ble_config.IoBusEvtCallBack = evt_received; + tl_ble_config.IoBusAclDataTxAck = acl_data_ack; + TL_BLE_Init((void *)&tl_ble_config); + } + } + +int HCISharedMemTransportClass::bt_ipm_set_addr(void) +{ + /* the specific table for set addr is 8 bytes: + * one byte for config_offset + * one byte for length + * 6 bytes for payload */ + uint8_t data[4+8]; + + phase_bd_addr = false; + + if (get_bd_address(bd_addr_udn)) { + /* create ACI_HAL_WRITE_CONFIG_DATA */ + + data[0] = BT_BUF_CMD; + data[1] = uint8_t(ACI_WRITE_CONFIG_DATA_OPCODE & 0x000000FF); /* OCF */ + data[2] = uint8_t((ACI_WRITE_CONFIG_DATA_OPCODE & 0x0000FF00) >> 8); /* OGF */ + data[3] = 8; /* length of parameters */ + /* fill the ACI_HAL_WRITE_CONFIG_DATA with the addr*/ + data[4] = CONFIG_DATA_PUBADDR_OFFSET; /* the offset */ + data[5] = 6; /* is the length of the bd_addr table */ + memcpy(data + 6, bd_addr_udn, 6); + /* send the ACI_HAL_WRITE_CONFIG_DATA */ + mbox_write(data[0], 11, &data[1]); + /* now wait for the corresponding Rx event */ + return 1; /* success */ + } + return 0; /* Error */ +} + +int HCISharedMemTransportClass::bt_ipm_set_power(void) +{ + /* the specific table for power is 2 bytes: + * En_High_Power byte, PA_level byte */ + uint8_t data[4+2]; + + phase_tx_power = false; + + data[0] = BT_BUF_CMD; /* the type */ + data[1] = (uint8_t)(ACI_HAL_SET_TX_POWER_LEVEL & 0x000000FF); /* the OPCODE */ + data[2] = (uint8_t)((ACI_HAL_SET_TX_POWER_LEVEL & 0x0000FF00) >> 8); + data[3] = 2; /* the length */ + /* fill the ACI_HAL_WRITE_CONFIG_DATA */ + data[4] = 0x01; /* En_High_Power */ + data[5] = CFG_TX_POWER; /* PA_level */ + + /* send the ACI_HAL_WRITE_CONFIG_DATA */ + mbox_write(data[0], 5, &data[1]); + /* now wait for the corresponding Rx event */ + return 1; /* success */ +} + +#endif /* STM32WBxx */ diff --git a/src/utility/HCISharedMemTransport.h b/src/utility/HCISharedMemTransport.h new file mode 100644 index 00000000..6a1b3829 --- /dev/null +++ b/src/utility/HCISharedMemTransport.h @@ -0,0 +1,95 @@ +/* + This file is part of the STM32duinoBLE library. + Copyright (c) 2019 STMicroelectronics. All rights reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef _HCI_SHARED_MEM_TRANSPORT_H_ +#define _HCI_SHARED_MEM_TRANSPORT_H_ + +#include "HCITransport.h" + +/* STM32WB include files */ +#include "stm32wb55xx.h" +#include "stm32wbxx_ll_rcc.h" +#include "stm32wbxx_ll_ipcc.h" +#include "stm32wbxx_ll_system.h" +#include "STM32Cube_FW/tl.h" +#include "STM32Cube_FW/shci.h" +#include "STM32Cube_FW/shci_tl.h" +#include "STM32Cube_FW/stm_list.h" +#include "STM32Cube_FW/app_conf.h" + +/* this one is for printing info content when HW serial enabled */ +//#define PRINT_IPCC_INFO + +/* this CONFIG_DEBUG must be defined for -Og option */ +//#define CONFIG_DEBUG + +/****************************************************************************** + * BLE config parameters + ******************************************************************************/ +/* Defined from WB Cube reference SW */ +#define CFG_TLBLE_EVT_QUEUE_LENGTH 5 +#define CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE 255 /**< Set to 255 with the memory manager and the mailbox */ +#define TL_BLE_EVENT_FRAME_SIZE ( TL_EVT_HDR_SIZE + CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE ) +#define POOL_SIZE (CFG_TLBLE_EVT_QUEUE_LENGTH*4*DIVC(( sizeof(TL_PacketHeader_t) + TL_BLE_EVENT_FRAME_SIZE ), 4)) + +#define CONFIG_DATA_PUBADDR_OFFSET (0x00) /**< Bluetooth public address */ +#define CONFIG_DATA_PUBADDR_LEN (6) + +#define BT_BUF_CMD 1 +#define BT_BUF_ACL_OUT 2 + +/* timeout (in ms) to wait for an incoming event */ +#define BLE_IPCC_TIMEOUT 10000 + +/* to received BLE packet from the SharedMem */ +void evt_received(TL_EvtPacket_t *hcievt); + +/* to send BLE packet to the SharedMem */ +uint16_t mbox_write(uint8_t type, uint16_t len, const uint8_t *pData); + +class HCISharedMemTransportClass : public HCITransportInterface { +public: + HCISharedMemTransportClass(); + virtual ~HCISharedMemTransportClass(); + + virtual int begin(); + virtual void end(); + + virtual void wait(unsigned long timeout); + + virtual int available(); + virtual int peek(); + virtual int read(); + + virtual size_t write(const uint8_t* data, size_t length); + +private: + + /* method to initialize the BLE device */ + void transport_init(void); + void start_ble_rf(void); + void stm32wb_reset(void); + int stm32wb_start_ble(void); + int bt_ipm_ble_init(void); + int bt_ipm_set_addr(void); + int bt_ipm_set_power(void); + + }; + +#endif /* _HCI_SHARED_MEM_TRANSPORT_H_ */ From 0660a9497d27bd25cfe22ff4a5a6febe99988ab1 Mon Sep 17 00:00:00 2001 From: Francois Ramu <francois.ramu@st.com> Date: Thu, 19 Nov 2020 19:07:13 +0100 Subject: [PATCH 042/226] Fix [-Waddress-of-packed-member] warning Signed-off-by: Francois Ramu <francois.ramu@st.com> --- src/utility/HCISharedMemTransport.cpp | 981 +++++++++++++------------- src/utility/HCISharedMemTransport.h | 41 +- src/utility/HCISpiTransport.cpp | 306 +++----- src/utility/HCISpiTransport.h | 52 +- src/utility/STM32Cube_FW/stm_list.h | 12 +- 5 files changed, 659 insertions(+), 733 deletions(-) diff --git a/src/utility/HCISharedMemTransport.cpp b/src/utility/HCISharedMemTransport.cpp index 13b68298..c798fe74 100644 --- a/src/utility/HCISharedMemTransport.cpp +++ b/src/utility/HCISharedMemTransport.cpp @@ -27,11 +27,11 @@ PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static TL_CmdPacket_t BleCmdBuffer; PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static uint8_t EvtPool[POOL_SIZE]; PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static TL_CmdPacket_t SystemCmdBuffer; PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static uint8_t - SystemSpareEvtBuffer[sizeof(TL_PacketHeader_t) + TL_EVT_HDR_SIZE + 255]; +SystemSpareEvtBuffer[sizeof(TL_PacketHeader_t) + TL_EVT_HDR_SIZE + 255]; PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static uint8_t - BleSpareEvtBuffer[sizeof(TL_PacketHeader_t) + TL_EVT_HDR_SIZE + 255]; +BleSpareEvtBuffer[sizeof(TL_PacketHeader_t) + TL_EVT_HDR_SIZE + 255]; PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static uint8_t - HciAclDataBuffer[sizeof(TL_PacketHeader_t) + 5 + 251]; +HciAclDataBuffer[sizeof(TL_PacketHeader_t) + 5 + 251]; /* global var used as semaphore to control incoming events */ @@ -61,248 +61,254 @@ static uint8_t bd_addr_udn[CONFIG_DATA_PUBADDR_LEN]; /* returns true if sys_event was received, false otherwise */ static bool sysevt_wait(void) { - /* sys_event remains false until event is received */ - for (unsigned long start = millis(); (millis() - start) < BLE_IPCC_TIMEOUT;) { - /* Wait for 10sec max - if not return an error */ - if (sys_event) { break; } + /* sys_event remains false until event is received */ + for (unsigned long start = millis(); (millis() - start) < BLE_IPCC_TIMEOUT;) { + /* Wait for 10sec max - if not return an error */ + if (sys_event) { + break; } + } - if (!sys_event) { + if (!sys_event) { #if defined(PRINT_IPCC_INFO) - printf("ERROR: sys_evt timeout\r\n"); + printf("ERROR: sys_evt timeout\r\n"); #endif /*(PRINT_IPCC_INFO)*/ - /* no event received, timeout occurs */ - return false; - } - /* release immediately, now that M0 runs */ - return true; + /* no event received, timeout occurs */ + return false; + } + /* release immediately, now that M0 runs */ + return true; } /* WEAK callbacks from the BLE TL driver - will be called under Interrupt */ static void sysevt_received(void *pdata) { - UNUSED(pdata); - /* For now only READY event is received, so we know this is it */ - __disable_irq(); - sys_event = true; - __enable_irq(); - /* But later on ... we'll have to parse the answer */ + UNUSED(pdata); + /* For now only READY event is received, so we know this is it */ + __disable_irq(); + sys_event = true; + __enable_irq(); + /* But later on ... we'll have to parse the answer */ } /* returns true if sysevt was already received, which means M0 core is * already up and running */ static bool sysevt_check(void) { - /* Check if system is UP and running already */ - for (unsigned long start = millis(); (millis() - start) < 10;) { - /* Wait for 10ms max - if not return an error */ - if (sys_event) { break; } - } + /* Check if system is UP and running already */ + for (unsigned long start = millis(); (millis() - start) < 10;) { + /* Wait for 10ms max - if not return an error */ if (sys_event) { - /* release immediately as M0 already runs */ - return true; + break; } - return false; + } + if (sys_event) { + /* release immediately as M0 already runs */ + return true; + } + return false; } static void acl_data_ack(void) { - /** - * The current implementation assumes the taskGUI will not send a new HCI ACL DATA packet before this ack is received - * ( which means the CPU2 has handled the previous packet ) - * In order to implement a secure mechanism, it is required either - * - a flow control with the stack - * - a local pool of buffer to store packets received from the stack - */ - __disable_irq(); - acl_data_on = false; - __enable_irq(); + /** + * The current implementation assumes the taskGUI will not send a new HCI ACL DATA packet before this ack is received + * ( which means the CPU2 has handled the previous packet ) + * In order to implement a secure mechanism, it is required either + * - a flow control with the stack + * - a local pool of buffer to store packets received from the stack + */ + __disable_irq(); + acl_data_on = false; + __enable_irq(); } static bool acl_data_wait(void) { - /* Wait 10 sec for previous ACL command to be ack'ed by Low Layers - * before sending the next one */ - for (unsigned long start = millis(); (millis() - start) < BLE_IPCC_TIMEOUT;) { - /* Wait for 10sec max - if not return an error */ - if (!acl_data_on) { break; } + /* Wait 10 sec for previous ACL command to be ack'ed by Low Layers + * before sending the next one */ + for (unsigned long start = millis(); (millis() - start) < BLE_IPCC_TIMEOUT;) { + /* Wait for 10sec max - if not return an error */ + if (!acl_data_on) { + break; } - if (acl_data_on) { - /* no event received, timeout occurs */ + } + if (acl_data_on) { + /* no event received, timeout occurs */ #if defined(PRINT_IPCC_INFO) - printf("ERROR: acl data timeout\r\n"); + printf("ERROR: acl data timeout\r\n"); #endif /*(PRINT_IPCC_INFO)*/ - return false; - } - /* release immediately, now that M0 runs */ - __disable_irq(); - acl_data_on = false; - __enable_irq(); - return true; + return false; + } + /* release immediately, now that M0 runs */ + __disable_irq(); + acl_data_on = false; + __enable_irq(); + return true; } static void syscmd_status_not(SHCI_TL_CmdStatus_t status) { #if defined(PRINT_IPCC_INFO) - printf("syscmd_status_not, status:%d\r\n", status); + printf("syscmd_status_not, status:%d\r\n", status); #else - UNUSED(status); + UNUSED(status); #endif /*(PRINT_IPCC_INFO)*/ } /* to received BLE packet from the SharedMem */ void evt_received(TL_EvtPacket_t *hcievt) { - uint16_t len = 0; - - /* We need to memcpy the data before passing to higher layers. - * The received packet is copied in the _rxbuff - * but it must not exceed the BLE_MODULE_SHARED_MEM_BUFFER_SIZE - */ - switch (hcievt->evtserial.type) { - case TL_BLEEVT_PKT_TYPE: { - /* before starting the running_phase', a RESET command (0x0C03) is sent - * by the HCI. Then this evt packet is temporarily kept in the _rxbuff - * the set_bd_address (0xFC0C) and the set_tw_power (0xFC0F) commands are sent. - * Only when both evt are received (not store in the _rxbuffer), - * the Reset packet is handled at HCI layer : the running_phase begins - */ - if (phase_running == false) { - /* check the Rx event of complete the previous bd_addr opcode 0xFC0C */ - if ((hcievt->evtserial.evt.evtcode == TL_BLEEVT_CC_OPCODE) && - (hcievt->evtserial.evt.payload[0] == 0x01) && - (hcievt->evtserial.evt.payload[1] == 0x0C) && - (hcievt->evtserial.evt.payload[2] == 0xFC)) { - phase_bd_addr = true; - if (hcievt->evtserial.evt.payload[3] != 0) { -#if defined(PRINT_IPCC_INFO) - printf("Error: wrong BD Addr\r\n"); -#endif /*(PRINT_IPCC_INFO)*/ - } - /* rx data is no more useful : not stored in the _rxbuff */ - break; - } - /* check the Rx event of complete the previous tx power opcode 0xFC0F */ - if ((hcievt->evtserial.evt.evtcode == TL_BLEEVT_CC_OPCODE) && - (hcievt->evtserial.evt.payload[0] == 0x01) && - (hcievt->evtserial.evt.payload[1] == 0x0F) && - (hcievt->evtserial.evt.payload[2] == 0xFC)) { - phase_tx_power = true; - if (hcievt->evtserial.evt.payload[3] != 0) { -#if defined(PRINT_IPCC_INFO) - printf("Error: wrong Tx power\r\n"); -#endif /*(PRINT_IPCC_INFO)*/ - } - /* rx data is no more useful : not stored in the _rxbuff */ - break; - } - /* check if the reset phase is in progress (opcode is 0x0C03) */ - if ((hcievt->evtserial.evt.evtcode == TL_BLEEVT_CC_OPCODE) && - (hcievt->evtserial.evt.payload[0] == 0x01) && - (hcievt->evtserial.evt.payload[1] == 0x03) && - (hcievt->evtserial.evt.payload[2] == 0x0C)) { - phase_reset = true; + uint16_t len = 0; + + /* We need to memcpy the data before passing to higher layers. + * The received packet is copied in the _rxbuff + * but it must not exceed the BLE_MODULE_SHARED_MEM_BUFFER_SIZE + */ + switch (hcievt->evtserial.type) { + case TL_BLEEVT_PKT_TYPE: { + /* before starting the running_phase', a RESET command (0x0C03) is sent + * by the HCI. Then this evt packet is temporarily kept in the _rxbuff + * the set_bd_address (0xFC0C) and the set_tw_power (0xFC0F) commands are sent. + * Only when both evt are received (not store in the _rxbuffer), + * the Reset packet is handled at HCI layer : the running_phase begins + */ + if (phase_running == false) { + /* check the Rx event of complete the previous bd_addr opcode 0xFC0C */ + if ((hcievt->evtserial.evt.evtcode == TL_BLEEVT_CC_OPCODE) && + (hcievt->evtserial.evt.payload[0] == 0x01) && + (hcievt->evtserial.evt.payload[1] == 0x0C) && + (hcievt->evtserial.evt.payload[2] == 0xFC)) { + phase_bd_addr = true; + if (hcievt->evtserial.evt.payload[3] != 0) { #if defined(PRINT_IPCC_INFO) - if (hcievt->evtserial.evt.payload[3] != 0) { - printf("Error: wrong reset\r\n"); - } + printf("Error: wrong BD Addr\r\n"); #endif /*(PRINT_IPCC_INFO)*/ - } - } - __disable_irq(); - /* store received data in the _rxbuff buffer */ - len = hcievt->evtserial.evt.plen + TL_EVT_HDR_SIZE; - if (len < BLE_MODULE_SHARED_MEM_BUFFER_SIZE - _write_index) { - /* at the position of the _write_index */ - memcpy((uint8_t *)&_rxbuff[_write_index], (uint8_t *)&hcievt->evtserial, len); - /* move index */ - _write_index += len; - } else { - data_overflow = true; - } - __enable_irq(); } + /* rx data is no more useful : not stored in the _rxbuff */ break; - case TL_ACL_DATA_PKT_TYPE: { - TL_AclDataSerial_t *acl = &(((TL_AclDataPacket_t *)hcievt)->AclDataSerial); - __disable_irq(); - len = acl->length + 5; - if (len < BLE_MODULE_SHARED_MEM_BUFFER_SIZE - _write_index) { - memcpy((uint8_t *)&_rxbuff[_write_index], (uint8_t *)acl, len); - /* move index */ - _write_index += len; - } else { - data_overflow = true; - } - __enable_irq(); + } + /* check the Rx event of complete the previous tx power opcode 0xFC0F */ + if ((hcievt->evtserial.evt.evtcode == TL_BLEEVT_CC_OPCODE) && + (hcievt->evtserial.evt.payload[0] == 0x01) && + (hcievt->evtserial.evt.payload[1] == 0x0F) && + (hcievt->evtserial.evt.payload[2] == 0xFC)) { + phase_tx_power = true; + if (hcievt->evtserial.evt.payload[3] != 0) { +#if defined(PRINT_IPCC_INFO) + printf("Error: wrong Tx power\r\n"); +#endif /*(PRINT_IPCC_INFO)*/ } + /* rx data is no more useful : not stored in the _rxbuff */ break; - default: - /* should not happen */ + } + /* check if the reset phase is in progress (opcode is 0x0C03) */ + if ((hcievt->evtserial.evt.evtcode == TL_BLEEVT_CC_OPCODE) && + (hcievt->evtserial.evt.payload[0] == 0x01) && + (hcievt->evtserial.evt.payload[1] == 0x03) && + (hcievt->evtserial.evt.payload[2] == 0x0C)) { + phase_reset = true; #if defined(PRINT_IPCC_INFO) - printf("BLE TL evt_received, wrong type:%d\r\n", hcievt->evtserial.type); - while(1); /* let's block to check */ + if (hcievt->evtserial.evt.payload[3] != 0) { + printf("Error: wrong reset\r\n"); + } #endif /*(PRINT_IPCC_INFO)*/ - break; + } + } + __disable_irq(); + /* store received data in the _rxbuff buffer */ + len = hcievt->evtserial.evt.plen + TL_EVT_HDR_SIZE; + if (len < BLE_MODULE_SHARED_MEM_BUFFER_SIZE - _write_index) { + /* at the position of the _write_index */ + memcpy((uint8_t *)&_rxbuff[_write_index], (uint8_t *)&hcievt->evtserial, len); + /* move index */ + _write_index += len; + } else { + data_overflow = true; + } + __enable_irq(); + } + break; + case TL_ACL_DATA_PKT_TYPE: { + TL_AclDataSerial_t *acl = &(((TL_AclDataPacket_t *)hcievt)->AclDataSerial); + __disable_irq(); + len = acl->length + 5; + if (len < BLE_MODULE_SHARED_MEM_BUFFER_SIZE - _write_index) { + memcpy((uint8_t *)&_rxbuff[_write_index], (uint8_t *)acl, len); + /* move index */ + _write_index += len; + } else { + data_overflow = true; } + __enable_irq(); + } + break; + default: + /* should not happen */ #if defined(PRINT_IPCC_INFO) - if (data_overflow) { - printf("Error: data read overflow\r\n"); - } + printf("BLE TL evt_received, wrong type:%d\r\n", hcievt->evtserial.type); + while (1); /* let's block to check */ +#endif /*(PRINT_IPCC_INFO)*/ + break; + } +#if defined(PRINT_IPCC_INFO) + if (data_overflow) { + printf("Error: data read overflow\r\n"); + } #endif /*(PRINT_IPCC_INFO)*/ - /* In case Event belongs to the Evt Pool we need to inform */ - if (((uint8_t *)hcievt >= EvtPool) && ((uint8_t *)hcievt < (EvtPool + POOL_SIZE))) { - /* Free the message from shared memory */ - TL_MM_EvtDone(hcievt); - } + /* In case Event belongs to the Evt Pool we need to inform */ + if (((uint8_t *)hcievt >= EvtPool) && ((uint8_t *)hcievt < (EvtPool + POOL_SIZE))) { + /* Free the message from shared memory */ + TL_MM_EvtDone(hcievt); + } } /* to send BLE packet to the SharedMem */ uint16_t mbox_write(uint8_t type, uint16_t len, const uint8_t *pData) - { - TL_CmdPacket_t *bleCmdBuf = &BleCmdBuffer; - // Note: Until enum is available - // type 01 Command - // type 02 ACL DATA - // type 03 SCO Voice (not supported) - // type 04 event - uplink (not supported) - switch (type) { - case 1: { //BLE command - bleCmdBuf->cmdserial.type = type; // for now this param is overwritten in TL_BLE_SendCmd - bleCmdBuf->cmdserial.cmd.plen = len; - memcpy((void *) &bleCmdBuf->cmdserial.cmd, pData, len); - /* We're tracing here the command, after copy in shared mem but before M0 trigger. */ - TL_BLE_SendCmd(NULL, 0); // unused parameters for now - } - break; - case 2: { //ACL DATA - if (!acl_data_wait()) { +{ + TL_CmdPacket_t *bleCmdBuf = &BleCmdBuffer; + // Note: Until enum is available + // type 01 Command + // type 02 ACL DATA + // type 03 SCO Voice (not supported) + // type 04 event - uplink (not supported) + switch (type) { + case 1: { //BLE command + bleCmdBuf->cmdserial.type = type; // for now this param is overwritten in TL_BLE_SendCmd + bleCmdBuf->cmdserial.cmd.plen = len; + memcpy((void *) &bleCmdBuf->cmdserial.cmd, pData, len); + /* We're tracing here the command, after copy in shared mem but before M0 trigger. */ + TL_BLE_SendCmd(NULL, 0); // unused parameters for now + } + break; + case 2: { //ACL DATA + if (!acl_data_wait()) { #if defined(PRINT_IPCC_INFO) - printf("ERROR: previous ACL message not ACK'd\r\n"); + printf("ERROR: previous ACL message not ACK'd\r\n"); #endif /*(PRINT_IPCC_INFO)*/ - /* return number of bytes sent, 0 in this error case */ - return 0; - } - TL_AclDataSerial_t *aclDataSerial = (TL_AclDataSerial_t *)(HciAclDataBuffer + sizeof(TL_PacketHeader_t)); - aclDataSerial->type = type; // for now this param is overwritten in TL_BLE_SendCmd - memcpy(HciAclDataBuffer + + sizeof(TL_PacketHeader_t) + sizeof(type), pData, len); - TL_BLE_SendAclData(NULL, 0); // unused parameters for now - __disable_irq(); - acl_data_on = true; /* data being send */ - __enable_irq(); - } - break; - default: + /* return number of bytes sent, 0 in this error case */ + return 0; + } + TL_AclDataSerial_t *aclDataSerial = (TL_AclDataSerial_t *)(HciAclDataBuffer + sizeof(TL_PacketHeader_t)); + aclDataSerial->type = type; // for now this param is overwritten in TL_BLE_SendCmd + memcpy(HciAclDataBuffer + sizeof(TL_PacketHeader_t) + sizeof(type), pData, len); + TL_BLE_SendAclData(NULL, 0); // unused parameters for now + __disable_irq(); + acl_data_on = true; /* data being send */ + __enable_irq(); + } + break; + default: #if defined(PRINT_IPCC_INFO) - printf("ERROR: not supported type\r\n"); + printf("ERROR: not supported type\r\n"); #endif /*(PRINT_IPCC_INFO)*/ - /* return number of bytes sent, 0 in this error case */ - len = 0; - break; - } - return len; - } + /* return number of bytes sent, 0 in this error case */ + len = 0; + break; + } + return len; +} /** * Few utilities functions @@ -310,53 +316,53 @@ uint16_t mbox_write(uint8_t type, uint16_t len, const uint8_t *pData) /* This function fills in a BD address table */ static bool get_bd_address(uint8_t *bd_addr) { - uint32_t udn; - uint32_t company_id; - uint32_t device_id; - bool bd_found; - - udn = LL_FLASH_GetUDN(); - - if (udn != 0xFFFFFFFF) { - /* "Found Unique Device Number: %#06x", udn) */ - - company_id = LL_FLASH_GetSTCompanyID(); - device_id = LL_FLASH_GetDeviceID(); - - bd_addr[0] = (uint8_t)(udn & 0x000000FF); - bd_addr[1] = (uint8_t)((udn & 0x0000FF00) >> 8); - bd_addr[2] = (uint8_t)((udn & 0x00FF0000) >> 16); - bd_addr[3] = (uint8_t)device_id; - bd_addr[4] = (uint8_t)(company_id & 0x000000FF); - bd_addr[5] = (uint8_t)((company_id & 0x0000FF00) >> 8); - - bd_found = true; - } else { - bd_addr =NULL; - bd_found = false; - } + uint32_t udn; + uint32_t company_id; + uint32_t device_id; + bool bd_found; + + udn = LL_FLASH_GetUDN(); + + if (udn != 0xFFFFFFFF) { + /* "Found Unique Device Number: %#06x", udn) */ + + company_id = LL_FLASH_GetSTCompanyID(); + device_id = LL_FLASH_GetDeviceID(); + + bd_addr[0] = (uint8_t)(udn & 0x000000FF); + bd_addr[1] = (uint8_t)((udn & 0x0000FF00) >> 8); + bd_addr[2] = (uint8_t)((udn & 0x00FF0000) >> 16); + bd_addr[3] = (uint8_t)device_id; + bd_addr[4] = (uint8_t)(company_id & 0x000000FF); + bd_addr[5] = (uint8_t)((company_id & 0x0000FF00) >> 8); + + bd_found = true; + } else { + bd_addr = NULL; + bd_found = false; + } - return bd_found; + return bd_found; } static void init_debug(void) { - /* In case of debug profile, configure debugger support */ + /* In case of debug profile, configure debugger support */ #if defined(CONFIG_DEBUG) #if defined(PRINT_IPCC_INFO) - printf("init_debug ENABLED\r\n"); + printf("init_debug ENABLED\r\n"); #endif /*(PRINT_IPCC_INFO)*/ - /** - * Keep debugger enabled while in any low power mode - */ - HAL_DBGMCU_EnableDBGSleepMode(); - HAL_DBGMCU_EnableDBGStopMode(); - HAL_DBGMCU_EnableDBGStandbyMode(); + /** + * Keep debugger enabled while in any low power mode + */ + HAL_DBGMCU_EnableDBGSleepMode(); + HAL_DBGMCU_EnableDBGStopMode(); + HAL_DBGMCU_EnableDBGStandbyMode(); - /* Enable debugger: Debug power up request wakeup EXTI line 48 */ - LL_EXTI_EnableIT_32_63(LL_EXTI_LINE_48); - LL_C2_EXTI_EnableIT_32_63(LL_EXTI_LINE_48); + /* Enable debugger: Debug power up request wakeup EXTI line 48 */ + LL_EXTI_EnableIT_32_63(LL_EXTI_LINE_48); + LL_C2_EXTI_EnableIT_32_63(LL_EXTI_LINE_48); #endif /* CONFIG_DEBUG */ } @@ -370,15 +376,15 @@ HCISharedMemTransportClass::HCISharedMemTransportClass() memset((void *)_rxbuff, 0, sizeof(_rxbuff)); - sys_event = false; - acl_data_on = false; + sys_event = false; + acl_data_on = false; - data_overflow = false; + data_overflow = false; - phase_bd_addr = false; - phase_tx_power = false; - phase_reset = false; - phase_running = false; + phase_bd_addr = false; + phase_tx_power = false; + phase_reset = false; + phase_running = false; } HCISharedMemTransportClass::~HCISharedMemTransportClass() @@ -387,70 +393,68 @@ HCISharedMemTransportClass::~HCISharedMemTransportClass() int HCISharedMemTransportClass::begin() { - int status = 1; - /* clean data Rx variables */ - _read_index = 0; - _write_index = 0; - - memset((void *)_rxbuff, 0, sizeof(_rxbuff)); - - /* Check whether M0 sub-system was started already by - * checking if the system event was already received - * before. If it was not, then go thru all init. */ - if (!sysevt_check()) { - start_ble_rf(); - init_debug(); - /* Take BLE out of reset */ - stm32wb_reset(); - /* "C2 unlocking" */ - transport_init(); - /* At this stage, we got the ready event, - * passed thru TL_SYS_EvtReceived */ - - WirelessFwInfo_t wireless_info_instance; - WirelessFwInfo_t *p_wireless_info = &wireless_info_instance; - SHCI_GetWirelessFwInfo(p_wireless_info); + int status = 1; + /* clean data Rx variables */ + _read_index = 0; + _write_index = 0; + + memset((void *)_rxbuff, 0, sizeof(_rxbuff)); + + /* Check whether M0 sub-system was started already by + * checking if the system event was already received + * before. If it was not, then go thru all init. */ + if (!sysevt_check()) { + start_ble_rf(); + init_debug(); + /* Take BLE out of reset */ + stm32wb_reset(); + /* "C2 unlocking" */ + transport_init(); + /* At this stage, we got the ready event, + * passed thru TL_SYS_EvtReceived */ + + WirelessFwInfo_t wireless_info_instance; + WirelessFwInfo_t *p_wireless_info = &wireless_info_instance; + SHCI_GetWirelessFwInfo(p_wireless_info); #if defined(PRINT_IPCC_INFO) - printf("WB copro FW version = %d.%d.%d\r\n", p_wireless_info->VersionMajor, p_wireless_info->VersionMinor, p_wireless_info->VersionSub); + printf("WB copro FW version = %d.%d.%d\r\n", p_wireless_info->VersionMajor, p_wireless_info->VersionMinor, p_wireless_info->VersionSub); #endif /*(PRINT_IPCC_INFO)*/ - /* Now start BLE service on firmware side, using Vendor specific - * command on the System Channel - */ - status = stm32wb_start_ble(); + /* Now start BLE service on firmware side, using Vendor specific + * command on the System Channel + */ + status = stm32wb_start_ble(); - /* Once reset complete event is received we will need - * to send a few more commands: - * set bd addr with bt_ipm_set_addr(); - * during the HCI rest command */ - } - /* IPM Channel is now open */ + /* Once reset complete event is received we will need + * to send a few more commands: + * set bd addr with bt_ipm_set_addr(); + * during the HCI rest command */ + } + /* IPM Channel is now open */ #if defined(PRINT_IPCC_INFO) - printf("IPM Channel Open Completed\r\n"); + printf("IPM Channel Open Completed\r\n"); #endif /*(PRINT_IPCC_INFO)*/ - return status; + return status; } void HCISharedMemTransportClass::end() { - /* M0 sub-system is already on (sys_event) */ - acl_data_on = false; - data_overflow = false; - - /* the HCI RESET command ready to be processed again */ - phase_bd_addr = false; - phase_tx_power = false; - phase_reset = false; - phase_running = false; + /* M0 sub-system is already on (sys_event) */ + acl_data_on = false; + data_overflow = false; + + /* the HCI RESET command ready to be processed again */ + phase_bd_addr = false; + phase_tx_power = false; + phase_reset = false; + phase_running = false; } void HCISharedMemTransportClass::wait(unsigned long timeout) { - for (unsigned long start = millis(); (millis() - start) < timeout;) - { - if (available()) - { + for (unsigned long start = millis(); (millis() - start) < timeout;) { + if (available()) { break; } } @@ -458,276 +462,273 @@ void HCISharedMemTransportClass::wait(unsigned long timeout) int HCISharedMemTransportClass::available() { - /* assuming the reset is already achieved, - * the LL-only mode is already configured. */ + /* assuming the reset is already achieved, + * the LL-only mode is already configured. */ + if (_read_index != _write_index) { + return 1; + } else if (data_overflow) { + __disable_irq(); + data_overflow = false; + __enable_irq(); if (_read_index != _write_index) { - return 1; - } else if (data_overflow) { - __disable_irq(); - data_overflow = false; - __enable_irq(); - if (_read_index != _write_index) { - return 1; - } + return 1; } + } - return 0; + return 0; } int HCISharedMemTransportClass::peek() { int peek_val = -1; -__disable_irq(); - if(_read_index != _write_index) - { + __disable_irq(); + if (_read_index != _write_index) { peek_val = _rxbuff[_read_index]; } -__enable_irq(); + __enable_irq(); return peek_val; } int HCISharedMemTransportClass::read() { int read_val = -1; -__disable_irq(); - if(_read_index != _write_index) - { + __disable_irq(); + if (_read_index != _write_index) { read_val = _rxbuff[_read_index]; _read_index++; - if(_read_index == _write_index) - { + if (_read_index == _write_index) { /* Reset buffer index */ _read_index = 0; _write_index = 0; } } -__enable_irq(); + __enable_irq(); return read_val; } -size_t HCISharedMemTransportClass::write(const uint8_t* data, size_t length) +size_t HCISharedMemTransportClass::write(const uint8_t *data, size_t length) { - const uint8_t* msg_data; - msg_data = &data[1]; - - /* capture the HCI reset send command opcode = 0x0C03 - * After HCI reset event complete in the evt_received(), - * the bd_addr and tx_power must be sent - * before the phase_running begins. - */ - if (phase_running) { - return mbox_write(data[0], (length-1), msg_data);; - } - if ( (data[1] == 0x03) && (data[2] == 0x0C)) { - phase_reset = false; + const uint8_t *msg_data; + msg_data = &data[1]; + + /* capture the HCI reset send command opcode = 0x0C03 + * After HCI reset event complete in the evt_received(), + * the bd_addr and tx_power must be sent + * before the phase_running begins. + */ + if (phase_running) { + return mbox_write(data[0], (length - 1), msg_data);; + } + if ((data[1] == 0x03) && (data[2] == 0x0C)) { + phase_reset = false; - mbox_write(data[0], (length-1), msg_data); + mbox_write(data[0], (length - 1), msg_data); - /* capture event after HCI_RESET */ - while (!phase_reset); + /* capture event after HCI_RESET */ + while (!phase_reset); - /* set the bd add */ - if (!bt_ipm_set_addr()) { - /* in case of error, no data are written */ - return 0; - } - /* wait for the Rx complete */ - while (!phase_bd_addr); - /* this sequence is now complete */ + /* set the bd add */ + if (!bt_ipm_set_addr()) { + /* in case of error, no data are written */ + return 0; + } + /* wait for the Rx complete */ + while (!phase_bd_addr); + /* this sequence is now complete */ - /* set the Tx power */ - bt_ipm_set_power(); - /* wait for the Rx complete */ - while (!phase_tx_power); + /* set the Tx power */ + bt_ipm_set_power(); + /* wait for the Rx complete */ + while (!phase_tx_power); - /* this sequence is now complete */ - phase_running = true; + /* this sequence is now complete */ + phase_running = true; - return (length-1); /* mbox_size of the HCI reset command */ - } - return 0; /* mbox_size of the HCI reset command */ + return (length - 1); /* mbox_size of the HCI reset command */ + } + return 0; /* mbox_size of the HCI reset command */ } //private: void HCISharedMemTransportClass::start_ble_rf(void) { - if ((LL_RCC_IsActiveFlag_PINRST()) && (!LL_RCC_IsActiveFlag_SFTRST())) { - /* Simulate power off reset */ - LL_PWR_EnableBkUpAccess(); - LL_PWR_EnableBkUpAccess(); - LL_RCC_ForceBackupDomainReset(); - LL_RCC_ReleaseBackupDomainReset(); - } + if ((LL_RCC_IsActiveFlag_PINRST()) && (!LL_RCC_IsActiveFlag_SFTRST())) { + /* Simulate power off reset */ + LL_PWR_EnableBkUpAccess(); + LL_PWR_EnableBkUpAccess(); + LL_RCC_ForceBackupDomainReset(); + LL_RCC_ReleaseBackupDomainReset(); + } - /* Switch OFF LSI as LSE is the source clock */ - LL_RCC_LSI2_Disable(); + /* Switch OFF LSI as LSE is the source clock */ + LL_RCC_LSI2_Disable(); } void HCISharedMemTransportClass::stm32wb_reset(void) - { - // Reset IPCC - LL_AHB3_GRP1_EnableClock(LL_AHB3_GRP1_PERIPH_IPCC); - - LL_C1_IPCC_ClearFlag_CHx( - IPCC, - LL_IPCC_CHANNEL_1 | LL_IPCC_CHANNEL_2 | LL_IPCC_CHANNEL_3 | LL_IPCC_CHANNEL_4 - | LL_IPCC_CHANNEL_5 | LL_IPCC_CHANNEL_6); - - LL_C2_IPCC_ClearFlag_CHx( - IPCC, - LL_IPCC_CHANNEL_1 | LL_IPCC_CHANNEL_2 | LL_IPCC_CHANNEL_3 | LL_IPCC_CHANNEL_4 - | LL_IPCC_CHANNEL_5 | LL_IPCC_CHANNEL_6); - - LL_C1_IPCC_DisableTransmitChannel( - IPCC, - LL_IPCC_CHANNEL_1 | LL_IPCC_CHANNEL_2 | LL_IPCC_CHANNEL_3 | LL_IPCC_CHANNEL_4 - | LL_IPCC_CHANNEL_5 | LL_IPCC_CHANNEL_6); - - LL_C2_IPCC_DisableTransmitChannel( - IPCC, - LL_IPCC_CHANNEL_1 | LL_IPCC_CHANNEL_2 | LL_IPCC_CHANNEL_3 | LL_IPCC_CHANNEL_4 - | LL_IPCC_CHANNEL_5 | LL_IPCC_CHANNEL_6); - - LL_C1_IPCC_DisableReceiveChannel( - IPCC, - LL_IPCC_CHANNEL_1 | LL_IPCC_CHANNEL_2 | LL_IPCC_CHANNEL_3 | LL_IPCC_CHANNEL_4 - | LL_IPCC_CHANNEL_5 | LL_IPCC_CHANNEL_6); - - LL_C2_IPCC_DisableReceiveChannel( - IPCC, - LL_IPCC_CHANNEL_1 | LL_IPCC_CHANNEL_2 | LL_IPCC_CHANNEL_3 | LL_IPCC_CHANNEL_4 - | LL_IPCC_CHANNEL_5 | LL_IPCC_CHANNEL_6); - - /* IPCC default IRQ handlers: IPCC_C1_TX_IRQHandler & IPCC_C1_RX_IRQHandler - * are mapped in the flash mem area, so that NVIC does not need to SetVector - */ - } +{ + // Reset IPCC + LL_AHB3_GRP1_EnableClock(LL_AHB3_GRP1_PERIPH_IPCC); + + LL_C1_IPCC_ClearFlag_CHx( + IPCC, + LL_IPCC_CHANNEL_1 | LL_IPCC_CHANNEL_2 | LL_IPCC_CHANNEL_3 | LL_IPCC_CHANNEL_4 + | LL_IPCC_CHANNEL_5 | LL_IPCC_CHANNEL_6); + + LL_C2_IPCC_ClearFlag_CHx( + IPCC, + LL_IPCC_CHANNEL_1 | LL_IPCC_CHANNEL_2 | LL_IPCC_CHANNEL_3 | LL_IPCC_CHANNEL_4 + | LL_IPCC_CHANNEL_5 | LL_IPCC_CHANNEL_6); + + LL_C1_IPCC_DisableTransmitChannel( + IPCC, + LL_IPCC_CHANNEL_1 | LL_IPCC_CHANNEL_2 | LL_IPCC_CHANNEL_3 | LL_IPCC_CHANNEL_4 + | LL_IPCC_CHANNEL_5 | LL_IPCC_CHANNEL_6); + + LL_C2_IPCC_DisableTransmitChannel( + IPCC, + LL_IPCC_CHANNEL_1 | LL_IPCC_CHANNEL_2 | LL_IPCC_CHANNEL_3 | LL_IPCC_CHANNEL_4 + | LL_IPCC_CHANNEL_5 | LL_IPCC_CHANNEL_6); + + LL_C1_IPCC_DisableReceiveChannel( + IPCC, + LL_IPCC_CHANNEL_1 | LL_IPCC_CHANNEL_2 | LL_IPCC_CHANNEL_3 | LL_IPCC_CHANNEL_4 + | LL_IPCC_CHANNEL_5 | LL_IPCC_CHANNEL_6); + + LL_C2_IPCC_DisableReceiveChannel( + IPCC, + LL_IPCC_CHANNEL_1 | LL_IPCC_CHANNEL_2 | LL_IPCC_CHANNEL_3 | LL_IPCC_CHANNEL_4 + | LL_IPCC_CHANNEL_5 | LL_IPCC_CHANNEL_6); + + /* IPCC default IRQ handlers: IPCC_C1_TX_IRQHandler & IPCC_C1_RX_IRQHandler + * are mapped in the flash mem area, so that NVIC does not need to SetVector + */ +} int HCISharedMemTransportClass::stm32wb_start_ble(void) { - SHCI_C2_Ble_Init_Cmd_Packet_t ble_init_cmd_packet = { - 0, 0, 0, /**< Header unused */ - 0, /** pBleBufferAddress not used */ - 0, /** BleBufferSize not used */ - CFG_BLE_NUM_GATT_ATTRIBUTES, - CFG_BLE_NUM_GATT_SERVICES, - CFG_BLE_ATT_VALUE_ARRAY_SIZE, - CFG_BLE_NUM_LINK, - CFG_BLE_DATA_LENGTH_EXTENSION, - CFG_BLE_PREPARE_WRITE_LIST_SIZE, - CFG_BLE_MBLOCK_COUNT, - CFG_BLE_MAX_ATT_MTU, - CFG_BLE_SLAVE_SCA, - CFG_BLE_MASTER_SCA, - CFG_BLE_LSE_SOURCE, - CFG_BLE_MAX_CONN_EVENT_LENGTH, - CFG_BLE_HSE_STARTUP_TIME, - CFG_BLE_VITERBI_MODE, - CFG_BLE_LL_ONLY, - 0 /** TODO Should be read from HW */ - }; - /** - * Starts the BLE Stack on CPU2 - */ - if (SHCI_C2_BLE_Init(&ble_init_cmd_packet) == SHCI_Success) { - return 1; - } - return 0; + SHCI_C2_Ble_Init_Cmd_Packet_t ble_init_cmd_packet = { + 0, 0, 0, /**< Header unused */ + 0, /** pBleBufferAddress not used */ + 0, /** BleBufferSize not used */ + CFG_BLE_NUM_GATT_ATTRIBUTES, + CFG_BLE_NUM_GATT_SERVICES, + CFG_BLE_ATT_VALUE_ARRAY_SIZE, + CFG_BLE_NUM_LINK, + CFG_BLE_DATA_LENGTH_EXTENSION, + CFG_BLE_PREPARE_WRITE_LIST_SIZE, + CFG_BLE_MBLOCK_COUNT, + CFG_BLE_MAX_ATT_MTU, + CFG_BLE_SLAVE_SCA, + CFG_BLE_MASTER_SCA, + CFG_BLE_LSE_SOURCE, + CFG_BLE_MAX_CONN_EVENT_LENGTH, + CFG_BLE_HSE_STARTUP_TIME, + CFG_BLE_VITERBI_MODE, + CFG_BLE_LL_ONLY, + 0 /** TODO Should be read from HW */ + }; + /** + * Starts the BLE Stack on CPU2 + */ + if (SHCI_C2_BLE_Init(&ble_init_cmd_packet) == SHCI_Success) { + return 1; + } + return 0; } void HCISharedMemTransportClass::transport_init(void) - { - TL_MM_Config_t tl_mm_config; - TL_BLE_InitConf_t tl_ble_config; - /* STM32WB offers a System Channel HCI interface for - offering system services, with proprietary commands. - System Channel must be used as well for starting up - BLE service so we need to initialize it. */ - SHCI_TL_HciInitConf_t shci_init_config; - - /**< Reference table initialization */ - TL_Init(); - - /**< System channel initialization */ - shci_init_config.p_cmdbuffer = (uint8_t *)&SystemCmdBuffer; - shci_init_config.StatusNotCallBack = syscmd_status_not; - shci_init(sysevt_received, (void *) &shci_init_config); - - /**< Memory Manager channel initialization */ - tl_mm_config.p_BleSpareEvtBuffer = BleSpareEvtBuffer; - tl_mm_config.p_SystemSpareEvtBuffer = SystemSpareEvtBuffer; - tl_mm_config.p_AsynchEvtPool = EvtPool; - tl_mm_config.AsynchEvtPoolSize = POOL_SIZE; - TL_MM_Init(&tl_mm_config); - - TL_Enable(); - - /* At this stage, we'll need to wait for ready event, - * passed thru TL_SYS_EvtReceived */ - if (!sysevt_wait()) { +{ + TL_MM_Config_t tl_mm_config; + TL_BLE_InitConf_t tl_ble_config; + /* STM32WB offers a System Channel HCI interface for + offering system services, with proprietary commands. + System Channel must be used as well for starting up + BLE service so we need to initialize it. */ + SHCI_TL_HciInitConf_t shci_init_config; + + /**< Reference table initialization */ + TL_Init(); + + /**< System channel initialization */ + shci_init_config.p_cmdbuffer = (uint8_t *)&SystemCmdBuffer; + shci_init_config.StatusNotCallBack = syscmd_status_not; + shci_init(sysevt_received, (void *) &shci_init_config); + + /**< Memory Manager channel initialization */ + tl_mm_config.p_BleSpareEvtBuffer = BleSpareEvtBuffer; + tl_mm_config.p_SystemSpareEvtBuffer = SystemSpareEvtBuffer; + tl_mm_config.p_AsynchEvtPool = EvtPool; + tl_mm_config.AsynchEvtPoolSize = POOL_SIZE; + TL_MM_Init(&tl_mm_config); + + TL_Enable(); + + /* At this stage, we'll need to wait for ready event, + * passed thru TL_SYS_EvtReceived */ + if (!sysevt_wait()) { #if defined(PRINT_IPCC_INFO) - printf("ERROR booting WB controller\r\n"); + printf("ERROR booting WB controller\r\n"); #endif /*(PRINT_IPCC_INFO)*/ - } else { - /**< BLE channel initialization */ - tl_ble_config.p_cmdbuffer = (uint8_t *)&BleCmdBuffer; - tl_ble_config.p_AclDataBuffer = HciAclDataBuffer; - tl_ble_config.IoBusEvtCallBack = evt_received; - tl_ble_config.IoBusAclDataTxAck = acl_data_ack; - TL_BLE_Init((void *)&tl_ble_config); - } - } + } else { + /**< BLE channel initialization */ + tl_ble_config.p_cmdbuffer = (uint8_t *)&BleCmdBuffer; + tl_ble_config.p_AclDataBuffer = HciAclDataBuffer; + tl_ble_config.IoBusEvtCallBack = evt_received; + tl_ble_config.IoBusAclDataTxAck = acl_data_ack; + TL_BLE_Init((void *)&tl_ble_config); + } +} int HCISharedMemTransportClass::bt_ipm_set_addr(void) { - /* the specific table for set addr is 8 bytes: - * one byte for config_offset - * one byte for length - * 6 bytes for payload */ - uint8_t data[4+8]; - - phase_bd_addr = false; - - if (get_bd_address(bd_addr_udn)) { - /* create ACI_HAL_WRITE_CONFIG_DATA */ - - data[0] = BT_BUF_CMD; - data[1] = uint8_t(ACI_WRITE_CONFIG_DATA_OPCODE & 0x000000FF); /* OCF */ - data[2] = uint8_t((ACI_WRITE_CONFIG_DATA_OPCODE & 0x0000FF00) >> 8); /* OGF */ - data[3] = 8; /* length of parameters */ - /* fill the ACI_HAL_WRITE_CONFIG_DATA with the addr*/ - data[4] = CONFIG_DATA_PUBADDR_OFFSET; /* the offset */ - data[5] = 6; /* is the length of the bd_addr table */ - memcpy(data + 6, bd_addr_udn, 6); - /* send the ACI_HAL_WRITE_CONFIG_DATA */ - mbox_write(data[0], 11, &data[1]); - /* now wait for the corresponding Rx event */ - return 1; /* success */ - } - return 0; /* Error */ + /* the specific table for set addr is 8 bytes: + * one byte for config_offset + * one byte for length + * 6 bytes for payload */ + uint8_t data[4 + 8]; + + phase_bd_addr = false; + + if (get_bd_address(bd_addr_udn)) { + /* create ACI_HAL_WRITE_CONFIG_DATA */ + + data[0] = BT_BUF_CMD; + data[1] = uint8_t(ACI_WRITE_CONFIG_DATA_OPCODE & 0x000000FF); /* OCF */ + data[2] = uint8_t((ACI_WRITE_CONFIG_DATA_OPCODE & 0x0000FF00) >> 8); /* OGF */ + data[3] = 8; /* length of parameters */ + /* fill the ACI_HAL_WRITE_CONFIG_DATA with the addr*/ + data[4] = CONFIG_DATA_PUBADDR_OFFSET; /* the offset */ + data[5] = 6; /* is the length of the bd_addr table */ + memcpy(data + 6, bd_addr_udn, 6); + /* send the ACI_HAL_WRITE_CONFIG_DATA */ + mbox_write(data[0], 11, &data[1]); + /* now wait for the corresponding Rx event */ + return 1; /* success */ + } + return 0; /* Error */ } int HCISharedMemTransportClass::bt_ipm_set_power(void) { - /* the specific table for power is 2 bytes: - * En_High_Power byte, PA_level byte */ - uint8_t data[4+2]; - - phase_tx_power = false; - - data[0] = BT_BUF_CMD; /* the type */ - data[1] = (uint8_t)(ACI_HAL_SET_TX_POWER_LEVEL & 0x000000FF); /* the OPCODE */ - data[2] = (uint8_t)((ACI_HAL_SET_TX_POWER_LEVEL & 0x0000FF00) >> 8); - data[3] = 2; /* the length */ - /* fill the ACI_HAL_WRITE_CONFIG_DATA */ - data[4] = 0x01; /* En_High_Power */ - data[5] = CFG_TX_POWER; /* PA_level */ - - /* send the ACI_HAL_WRITE_CONFIG_DATA */ - mbox_write(data[0], 5, &data[1]); - /* now wait for the corresponding Rx event */ - return 1; /* success */ + /* the specific table for power is 2 bytes: + * En_High_Power byte, PA_level byte */ + uint8_t data[4 + 2]; + + phase_tx_power = false; + + data[0] = BT_BUF_CMD; /* the type */ + data[1] = (uint8_t)(ACI_HAL_SET_TX_POWER_LEVEL & 0x000000FF); /* the OPCODE */ + data[2] = (uint8_t)((ACI_HAL_SET_TX_POWER_LEVEL & 0x0000FF00) >> 8); + data[3] = 2; /* the length */ + /* fill the ACI_HAL_WRITE_CONFIG_DATA */ + data[4] = 0x01; /* En_High_Power */ + data[5] = CFG_TX_POWER; /* PA_level */ + + /* send the ACI_HAL_WRITE_CONFIG_DATA */ + mbox_write(data[0], 5, &data[1]); + /* now wait for the corresponding Rx event */ + return 1; /* success */ } #endif /* STM32WBxx */ diff --git a/src/utility/HCISharedMemTransport.h b/src/utility/HCISharedMemTransport.h index 6a1b3829..9b9751f2 100644 --- a/src/utility/HCISharedMemTransport.h +++ b/src/utility/HCISharedMemTransport.h @@ -30,7 +30,6 @@ #include "STM32Cube_FW/tl.h" #include "STM32Cube_FW/shci.h" #include "STM32Cube_FW/shci_tl.h" -#include "STM32Cube_FW/stm_list.h" #include "STM32Cube_FW/app_conf.h" /* this one is for printing info content when HW serial enabled */ @@ -64,32 +63,32 @@ void evt_received(TL_EvtPacket_t *hcievt); uint16_t mbox_write(uint8_t type, uint16_t len, const uint8_t *pData); class HCISharedMemTransportClass : public HCITransportInterface { -public: - HCISharedMemTransportClass(); - virtual ~HCISharedMemTransportClass(); + public: + HCISharedMemTransportClass(); + virtual ~HCISharedMemTransportClass(); - virtual int begin(); - virtual void end(); + virtual int begin(); + virtual void end(); - virtual void wait(unsigned long timeout); + virtual void wait(unsigned long timeout); - virtual int available(); - virtual int peek(); - virtual int read(); + virtual int available(); + virtual int peek(); + virtual int read(); - virtual size_t write(const uint8_t* data, size_t length); + virtual size_t write(const uint8_t *data, size_t length); -private: + private: - /* method to initialize the BLE device */ - void transport_init(void); - void start_ble_rf(void); - void stm32wb_reset(void); - int stm32wb_start_ble(void); - int bt_ipm_ble_init(void); - int bt_ipm_set_addr(void); - int bt_ipm_set_power(void); + /* method to initialize the BLE device */ + void transport_init(void); + void start_ble_rf(void); + void stm32wb_reset(void); + int stm32wb_start_ble(void); + int bt_ipm_ble_init(void); + int bt_ipm_set_addr(void); + int bt_ipm_set_power(void); - }; +}; #endif /* _HCI_SHARED_MEM_TRANSPORT_H_ */ diff --git a/src/utility/HCISpiTransport.cpp b/src/utility/HCISpiTransport.cpp index 99dd6ca2..512e6e9a 100644 --- a/src/utility/HCISpiTransport.cpp +++ b/src/utility/HCISpiTransport.cpp @@ -21,7 +21,7 @@ volatile int data_avail = 0; -HCISpiTransportClass::HCISpiTransportClass(SPIClass& spi, BLEChip_t ble_chip, uint8_t cs_pin, uint8_t spi_irq, uint8_t ble_rst, uint32_t frequency, uint8_t spi_mode) : +HCISpiTransportClass::HCISpiTransportClass(SPIClass &spi, BLEChip_t ble_chip, uint8_t cs_pin, uint8_t spi_irq, uint8_t ble_rst, uint32_t frequency, uint8_t spi_mode) : _spi(&spi), _ble_chip(ble_chip), _cs_pin(cs_pin), @@ -66,16 +66,13 @@ int HCISpiTransportClass::begin() digitalWrite(_ble_rst, HIGH); delay(5); - if (_ble_chip == SPBTLE_RF || _ble_chip == BLUENRG_M0) - { + if (_ble_chip == SPBTLE_RF || _ble_chip == BLUENRG_M0) { // Wait for Blue Initialize wait_for_blue_initialize(); - } else if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP) - { + } else if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP) { // Wait a while for the reset of the BLE module delay(300); - } else - { + } else { // BLE chip not supported return 0; } @@ -91,10 +88,8 @@ void HCISpiTransportClass::end() void HCISpiTransportClass::wait(unsigned long timeout) { - for (unsigned long start = millis(); (millis() - start) < timeout;) - { - if (available()) - { + for (unsigned long start = millis(); (millis() - start) < timeout;) { + if (available()) { break; } } @@ -102,31 +97,25 @@ void HCISpiTransportClass::wait(unsigned long timeout) int HCISpiTransportClass::available() { - if(_ble_chip != SPBTLE_RF && _ble_chip != SPBTLE_1S && _ble_chip != BLUENRG_M2SP && _ble_chip != BLUENRG_M0) - { + if (_ble_chip != SPBTLE_RF && _ble_chip != SPBTLE_1S && _ble_chip != BLUENRG_M2SP && _ble_chip != BLUENRG_M0) { return 0; } - if(_read_index != _write_index) - { + if (_read_index != _write_index) { return 1; - } else if(data_avail) - { + } else if (data_avail) { int ble_reset = 0; - if(digitalRead(_spi_irq) == 0) - { + if (digitalRead(_spi_irq) == 0) { return 0; } data_avail = 0; - while(digitalRead(_spi_irq) == 1 && _write_index != BLE_MODULE_SPI_BUFFER_SIZE) - { + while (digitalRead(_spi_irq) == 1 && _write_index != BLE_MODULE_SPI_BUFFER_SIZE) { uint8_t header_master[5] = {0x0b, 0x00, 0x00, 0x00, 0x00}; - if(_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP) - { + if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP) { detachInterrupt(_spi_irq); } @@ -137,112 +126,91 @@ int HCISpiTransportClass::available() /* Write the header */ _spi->transfer(header_master, 5); - if (_ble_chip == SPBTLE_RF || _ble_chip == BLUENRG_M0) - { + if (_ble_chip == SPBTLE_RF || _ble_chip == BLUENRG_M0) { /* device is ready */ - if(header_master[0] == 0x02) - { + if (header_master[0] == 0x02) { uint16_t byte_count = (header_master[4] << 8) | header_master[3]; - if(byte_count > 0) - { - if(_initial_phase) - { + if (byte_count > 0) { + if (_initial_phase) { /* avoid to read more data that available size of the buffer */ - if(byte_count > (BLE_MODULE_SPI_BUFFER_SIZE - _write_index_initial)) - { + if (byte_count > (BLE_MODULE_SPI_BUFFER_SIZE - _write_index_initial)) { byte_count = (BLE_MODULE_SPI_BUFFER_SIZE - _write_index_initial); } /* Read the response */ - for(int j=0; j < byte_count; j++) - { + for (int j = 0; j < byte_count; j++) { _rxbuff[_write_index_initial] = _spi->transfer(0xFF); _write_index_initial++; } /* Check if the message is a Blue Initialize */ /* If so we need to send the command to enable LL_ONLY */ - if(byte_count == 6) - { - if(_rxbuff[_write_index_initial - 6] == 0x04 && - _rxbuff[_write_index_initial - 5] == 0xFF && - _rxbuff[_write_index_initial - 4] == 0x03 && - _rxbuff[_write_index_initial - 3] == 0x01 && - _rxbuff[_write_index_initial - 2] == 0x00 && - _rxbuff[_write_index_initial - 1] == 0x01) - { + if (byte_count == 6) { + if (_rxbuff[_write_index_initial - 6] == 0x04 && + _rxbuff[_write_index_initial - 5] == 0xFF && + _rxbuff[_write_index_initial - 4] == 0x03 && + _rxbuff[_write_index_initial - 3] == 0x01 && + _rxbuff[_write_index_initial - 2] == 0x00 && + _rxbuff[_write_index_initial - 1] == 0x01) { ble_reset = 1; } } - } else - { + } else { /* avoid to read more data that available size of the buffer */ - if(byte_count > (BLE_MODULE_SPI_BUFFER_SIZE - _write_index)) - { + if (byte_count > (BLE_MODULE_SPI_BUFFER_SIZE - _write_index)) { byte_count = (BLE_MODULE_SPI_BUFFER_SIZE - _write_index); /* SPI buffer is full but we still have data to store, so we set the data_avail flag to true */ data_avail = 1; } /* Read the response */ - for(int j=0; j < byte_count; j++) - { + for (int j = 0; j < byte_count; j++) { _rxbuff[_write_index] = _spi->transfer(0xFF); _write_index++; } } } } - } else if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP) - { + } else if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP) { uint16_t byte_count = (header_master[4] << 8) | header_master[3]; - if(byte_count > 0) - { - if(_initial_phase) - { + if (byte_count > 0) { + if (_initial_phase) { /* avoid to read more data that available size of the buffer */ - if(byte_count > (BLE_MODULE_SPI_BUFFER_SIZE - _write_index_initial)) - { + if (byte_count > (BLE_MODULE_SPI_BUFFER_SIZE - _write_index_initial)) { byte_count = (BLE_MODULE_SPI_BUFFER_SIZE - _write_index_initial); } /* Read the response */ - for(int j=0; j < byte_count; j++) - { + for (int j = 0; j < byte_count; j++) { _rxbuff[_write_index_initial] = _spi->transfer(0xFF); _write_index_initial++; } /* Check if the message is a CMD_COMPLETE */ /* We suppose that the first CMD is always a HCI_RESET */ - if(byte_count == 7) - { - if(_rxbuff[_write_index_initial - 7] == 0x04 && - _rxbuff[_write_index_initial - 6] == 0x0E && - _rxbuff[_write_index_initial - 5] == 0x04 && - _rxbuff[_write_index_initial - 4] == 0x01 && - _rxbuff[_write_index_initial - 3] == 0x03 && - _rxbuff[_write_index_initial - 2] == 0x0C && - _rxbuff[_write_index_initial - 1] == 0x00) - { + if (byte_count == 7) { + if (_rxbuff[_write_index_initial - 7] == 0x04 && + _rxbuff[_write_index_initial - 6] == 0x0E && + _rxbuff[_write_index_initial - 5] == 0x04 && + _rxbuff[_write_index_initial - 4] == 0x01 && + _rxbuff[_write_index_initial - 3] == 0x03 && + _rxbuff[_write_index_initial - 2] == 0x0C && + _rxbuff[_write_index_initial - 1] == 0x00) { ble_reset = 1; } } - } else - { + } else { /* avoid to read more data that available size of the buffer */ - if(byte_count > (BLE_MODULE_SPI_BUFFER_SIZE - _write_index)) - { + if (byte_count > (BLE_MODULE_SPI_BUFFER_SIZE - _write_index)) { byte_count = (BLE_MODULE_SPI_BUFFER_SIZE - _write_index); /* SPI buffer is full but we still have data to store, so we set the data_avail flag to true */ data_avail = 1; } /* Read the response */ - for(int j=0; j < byte_count; j++) - { + for (int j = 0; j < byte_count; j++) { _rxbuff[_write_index] = _spi->transfer(0xFF); _write_index++; } @@ -254,21 +222,17 @@ int HCISpiTransportClass::available() _spi->endTransaction(); - if(_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP) - { + if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP) { attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); } } - if(ble_reset) - { - if (_ble_chip == SPBTLE_RF || _ble_chip == BLUENRG_M0) - { + if (ble_reset) { + if (_ble_chip == SPBTLE_RF || _ble_chip == BLUENRG_M0) { /* BLE chip was reset: we need to enable LL_ONLY */ enable_ll_only(); wait_for_enable_ll_only(); - } else if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP) - { + } else if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP) { /* BLE chip was reset: we need to wait for a while */ delay(300); } @@ -279,15 +243,12 @@ int HCISpiTransportClass::available() _write_index_initial = 0; } - if(_read_index != _write_index) - { + if (_read_index != _write_index) { return 1; - } else - { + } else { return 0; } - } else - { + } else { return 0; } } @@ -296,8 +257,7 @@ int HCISpiTransportClass::peek() { int peek_val = -1; - if(_read_index != _write_index) - { + if (_read_index != _write_index) { peek_val = _rxbuff[_read_index]; } @@ -308,12 +268,10 @@ int HCISpiTransportClass::read() { int read_val = -1; - if(_read_index != _write_index) - { + if (_read_index != _write_index) { read_val = _rxbuff[_read_index]; _read_index++; - if(_read_index == _write_index) - { + if (_read_index == _write_index) { /* Reset buffer index */ _read_index = 0; _write_index = 0; @@ -323,22 +281,19 @@ int HCISpiTransportClass::read() return read_val; } -size_t HCISpiTransportClass::write(const uint8_t* data, size_t length) +size_t HCISpiTransportClass::write(const uint8_t *data, size_t length) { uint8_t header_master[5] = {0x0a, 0x00, 0x00, 0x00, 0x00}; void *my_data = (void *)data; int result = 0; uint32_t tickstart = millis(); - if(_ble_chip != SPBTLE_RF && _ble_chip != SPBTLE_1S && _ble_chip != BLUENRG_M2SP && _ble_chip != BLUENRG_M0) - { + 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 || _ble_chip == BLUENRG_M0) - { + do { + if (_ble_chip == SPBTLE_RF || _ble_chip == BLUENRG_M0) { result = 0; _spi->beginTransaction(_spiSettings); @@ -349,18 +304,14 @@ size_t HCISpiTransportClass::write(const uint8_t* data, size_t length) _spi->transfer(header_master, 5); /* device is ready */ - if(header_master[0] == 0x02) - { - if(header_master[1] >= length) - { + if (header_master[0] == 0x02) { + if (header_master[1] >= length) { /* Write the data */ _spi->transfer(my_data, length); - } else - { + } else { result = -2; } - } else - { + } else { result = -1; } @@ -368,13 +319,11 @@ size_t HCISpiTransportClass::write(const uint8_t* data, size_t length) _spi->endTransaction(); - if((millis() - tickstart) > 1000) - { + if ((millis() - tickstart) > 1000) { result = -3; break; } - } else if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP) - { + } else if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP) { uint32_t tickstart_data_available = millis(); result = 0; @@ -388,17 +337,14 @@ size_t HCISpiTransportClass::write(const uint8_t* data, size_t length) * Wait until BlueNRG-1 is ready. * When ready it will raise the IRQ pin. */ - while(!(digitalRead(_spi_irq) == 1)) - { - if((millis() - tickstart_data_available) > 1000) - { + while (!(digitalRead(_spi_irq) == 1)) { + if ((millis() - tickstart_data_available) > 1000) { result = -3; break; } } - if(result == -3) - { + if (result == -3) { digitalWrite(_cs_pin, HIGH); _spi->endTransaction(); attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); @@ -408,12 +354,10 @@ size_t HCISpiTransportClass::write(const uint8_t* data, size_t length) /* Write the header */ _spi->transfer(header_master, 5); - if((int)((((uint16_t)header_master[2])<<8) | ((uint16_t)header_master[1])) >= (int)length) - { + if ((int)((((uint16_t)header_master[2]) << 8) | ((uint16_t)header_master[1])) >= (int)length) { /* Write the data */ _spi->transfer(my_data, length); - } else - { + } else { result = -2; } @@ -423,19 +367,16 @@ size_t HCISpiTransportClass::write(const uint8_t* data, size_t length) attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); - if((millis() - tickstart) > 1000) - { + if ((millis() - tickstart) > 1000) { result = -3; break; } } - } while(result < 0); + } while (result < 0); - if(result < 0) - { + if (result < 0) { return 0; - } else - { + } else { return length; } } @@ -445,18 +386,15 @@ void HCISpiTransportClass::wait_for_blue_initialize() int event_blue_initialize = 0; uint8_t event[16]; - do - { - while(!data_avail); + do { + while (!data_avail); - if(digitalRead(_spi_irq) == 0) - { + if (digitalRead(_spi_irq) == 0) { continue; } data_avail = 0; - while(digitalRead(_spi_irq) == 1) - { + while (digitalRead(_spi_irq) == 1) { uint8_t header_master[5] = {0x0b, 0x00, 0x00, 0x00, 0x00}; _spi->beginTransaction(_spiSettings); @@ -467,34 +405,27 @@ void HCISpiTransportClass::wait_for_blue_initialize() _spi->transfer(header_master, 5); /* device is ready */ - if(header_master[0] == 0x02) - { + if (header_master[0] == 0x02) { /* device is ready */ uint16_t byte_count = (header_master[4] << 8) | header_master[3]; - if(byte_count > 0) - { + if (byte_count > 0) { /* Read the response */ - if(byte_count == 6) - { - for(int j=0; j < byte_count; j++) - { + if (byte_count == 6) { + for (int j = 0; j < byte_count; j++) { event[j] = _spi->transfer(0xFF); } - if(event[0] == 0x04 && - event[1] == 0xFF && - event[2] == 0x03 && - event[3] == 0x01 && - event[4] == 0x00 && - event[5] == 0x01) - { + if (event[0] == 0x04 && + event[1] == 0xFF && + event[2] == 0x03 && + event[3] == 0x01 && + event[4] == 0x00 && + event[5] == 0x01) { event_blue_initialize = 1; } - } else - { - for(int j=0; j < byte_count; j++) - { + } else { + for (int j = 0; j < byte_count; j++) { _spi->transfer(0xFF); } } @@ -505,7 +436,7 @@ void HCISpiTransportClass::wait_for_blue_initialize() _spi->endTransaction(); } - } while(!event_blue_initialize); + } while (!event_blue_initialize); } void HCISpiTransportClass::wait_for_enable_ll_only() @@ -513,18 +444,15 @@ void HCISpiTransportClass::wait_for_enable_ll_only() uint8_t data[8]; int status = 0; - do - { - while(!data_avail); + do { + while (!data_avail); - if(digitalRead(_spi_irq) == 0) - { + if (digitalRead(_spi_irq) == 0) { continue; } data_avail = 0; - while(digitalRead(_spi_irq) == 1) - { + while (digitalRead(_spi_irq) == 1) { uint8_t header_master[5] = {0x0b, 0x00, 0x00, 0x00, 0x00}; _spi->beginTransaction(_spiSettings); @@ -535,29 +463,24 @@ void HCISpiTransportClass::wait_for_enable_ll_only() _spi->transfer(header_master, 5); /* device is ready */ - if(header_master[0] == 0x02) - { + if (header_master[0] == 0x02) { /* device is ready */ uint16_t byte_count = (header_master[4] << 8) | header_master[3]; - if(byte_count > 0) - { + if (byte_count > 0) { /* Read the response */ - for(int j=0; j < byte_count; j++) - { + for (int j = 0; j < byte_count; j++) { data[j] = _spi->transfer(0xFF); } - if(byte_count == 7) - { - if(data[0] == 0x04 && - data[1] == 0x0E && - data[2] == 0x04 && - data[3] == 0x01 && - data[4] == 0x0C && - data[5] == 0xFC && - data[6] == 0x00) - { + if (byte_count == 7) { + if (data[0] == 0x04 && + data[1] == 0x0E && + data[2] == 0x04 && + data[3] == 0x01 && + data[4] == 0x0C && + data[5] == 0xFC && + data[6] == 0x00) { status = 1; } } @@ -568,17 +491,16 @@ void HCISpiTransportClass::wait_for_enable_ll_only() _spi->endTransaction(); } - } while(!status); + } while (!status); } void HCISpiTransportClass::enable_ll_only() { uint8_t header_master[5] = {0x0a, 0x00, 0x00, 0x00, 0x00}; - uint8_t cmd[7] = {0x01,0x0C,0xFC,0x03,0x2C,0x01,0x01}; // Enable LL_ONLY + uint8_t cmd[7] = {0x01, 0x0C, 0xFC, 0x03, 0x2C, 0x01, 0x01}; // Enable LL_ONLY int result = 0; - do - { + do { result = 0; _spi->beginTransaction(_spiSettings); @@ -589,19 +511,15 @@ void HCISpiTransportClass::enable_ll_only() _spi->transfer(header_master, 5); /* device is ready */ - if(header_master[0] == 0x02) - { + if (header_master[0] == 0x02) { /* Write the data */ - if(header_master[1] >= 7) - { + if (header_master[1] >= 7) { /* Write the data */ _spi->transfer((void *)cmd, 7); - } else - { + } else { result = -2; } - } else - { + } else { result = -1; } diff --git a/src/utility/HCISpiTransport.h b/src/utility/HCISpiTransport.h index e16502f1..4da3befb 100644 --- a/src/utility/HCISpiTransport.h +++ b/src/utility/HCISpiTransport.h @@ -31,41 +31,41 @@ typedef enum BLEChip_s { } BLEChip_t; #ifndef BLE_SPI_BYTE_ORDER -#define BLE_SPI_BYTE_ORDER MSBFIRST + #define BLE_SPI_BYTE_ORDER MSBFIRST #endif #define BLE_MODULE_SPI_BUFFER_SIZE 128 class HCISpiTransportClass : public HCITransportInterface { -public: - HCISpiTransportClass(SPIClass& spi, BLEChip_t ble_chip, uint8_t cs_pin, uint8_t spi_irq, uint8_t ble_rst, uint32_t frequency, uint8_t spi_mode); - virtual ~HCISpiTransportClass(); + public: + HCISpiTransportClass(SPIClass &spi, BLEChip_t ble_chip, uint8_t cs_pin, uint8_t spi_irq, uint8_t ble_rst, uint32_t frequency, uint8_t spi_mode); + virtual ~HCISpiTransportClass(); - virtual int begin(); - virtual void end(); + virtual int begin(); + virtual void end(); - virtual void wait(unsigned long timeout); + virtual void wait(unsigned long timeout); - virtual int available(); - virtual int peek(); - virtual int read(); + virtual int available(); + virtual int peek(); + virtual int read(); - virtual size_t write(const uint8_t* data, size_t length); + virtual size_t write(const uint8_t *data, size_t length); -private: - void wait_for_blue_initialize(); - void wait_for_enable_ll_only(); - void enable_ll_only(); - SPIClass* _spi; - SPISettings _spiSettings; - BLEChip_t _ble_chip; - uint8_t _cs_pin; - uint8_t _spi_irq; - uint8_t _ble_rst; - uint8_t _rxbuff[BLE_MODULE_SPI_BUFFER_SIZE]; - uint16_t _read_index; - uint16_t _write_index; - uint16_t _write_index_initial; - uint8_t _initial_phase; + private: + void wait_for_blue_initialize(); + void wait_for_enable_ll_only(); + void enable_ll_only(); + SPIClass *_spi; + SPISettings _spiSettings; + BLEChip_t _ble_chip; + uint8_t _cs_pin; + uint8_t _spi_irq; + uint8_t _ble_rst; + uint8_t _rxbuff[BLE_MODULE_SPI_BUFFER_SIZE]; + uint16_t _read_index; + uint16_t _write_index; + uint16_t _write_index_initial; + uint8_t _initial_phase; }; #endif /* _HCI_SPI_TRANSPORT_H_ */ diff --git a/src/utility/STM32Cube_FW/stm_list.h b/src/utility/STM32Cube_FW/stm_list.h index b5f1cc8d..885b50c1 100644 --- a/src/utility/STM32Cube_FW/stm_list.h +++ b/src/utility/STM32Cube_FW/stm_list.h @@ -23,10 +23,14 @@ /* Includes ------------------------------------------------------------------*/ -#include "stdint.h" #include "stdbool.h" +#include "stm32_wpan_common.h" -typedef struct _tListNode { +#ifdef __cplusplus +extern "C" { +#endif + +typedef PACKED_STRUCT _tListNode { struct _tListNode *next; struct _tListNode *prev; } tListNode; @@ -55,4 +59,8 @@ void LST_get_next_node(tListNode *ref_node, tListNode **node); void LST_get_prev_node(tListNode *ref_node, tListNode **node); +#ifdef __cplusplus +} +#endif + #endif /* _STM_LIST_H_ */ From 8f0e11671858e011a75eec01801f669d50ed1b88 Mon Sep 17 00:00:00 2001 From: Francois Ramu <francois.ramu@st.com> Date: Fri, 25 Sep 2020 13:39:19 +0200 Subject: [PATCH 043/226] Modify the examples to run on the nucleo_wb55rg board Signed-off-by: Francois Ramu <francois.ramu@st.com> --- examples/Central/LedControl/LedControl.ino | 5 +++++ examples/Central/PeripheralExplorer/PeripheralExplorer.ino | 4 ++++ examples/Central/Scan/Scan.ino | 4 ++++ examples/Central/ScanCallback/ScanCallback.ino | 4 ++++ examples/Central/SensorTagButton/SensorTagButton.ino | 4 ++++ examples/Peripheral/ButtonLED/ButtonLED.ino | 5 +++++ examples/Peripheral/CallbackLED/CallbackLED.ino | 4 ++++ examples/Peripheral/LED/LED.ino | 4 ++++ 8 files changed, 34 insertions(+) diff --git a/examples/Central/LedControl/LedControl.ino b/examples/Central/LedControl/LedControl.ino index 4eec9259..2b916c53 100644 --- a/examples/Central/LedControl/LedControl.ino +++ b/examples/Central/LedControl/LedControl.ino @@ -28,6 +28,11 @@ SPIClass SpiHCI(PC12, PC11, PC10); HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, PD13, PE6, PA8, 8000000, SPI_MODE0); BLELocalDevice BLE(&HCISpiTransport); const int buttonPin = PC13; // set buttonPin to digital pin PC13 +#elif defined(ARDUINO_PNUCLEO_WB55RG) +/* PNUCLEO_WB55RG */ +HCISharedMemTransportClass HCISharedMemTransport; +BLELocalDevice BLE(&HCISharedMemTransport); +const int buttonPin = PC4; // set buttonPin to digital pin PC4 #else /* Shield IDB05A2 with SPI clock on D3 */ SPIClass SpiHCI(D11, D12, D3); diff --git a/examples/Central/PeripheralExplorer/PeripheralExplorer.ino b/examples/Central/PeripheralExplorer/PeripheralExplorer.ino index 5f33e4bd..5d5da6a3 100644 --- a/examples/Central/PeripheralExplorer/PeripheralExplorer.ino +++ b/examples/Central/PeripheralExplorer/PeripheralExplorer.ino @@ -25,6 +25,10 @@ BLELocalDevice BLE(&HCISpiTransport); SPIClass SpiHCI(PC12, PC11, PC10); HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, PD13, PE6, PA8, 8000000, SPI_MODE0); BLELocalDevice BLE(&HCISpiTransport); +#elif defined(ARDUINO_PNUCLEO_WB55RG) +/* PNUCLEO_WB55RG */ +HCISharedMemTransportClass HCISharedMemTransport; +BLELocalDevice BLE(&HCISharedMemTransport); #else /* Shield IDB05A2 with SPI clock on D3 */ SPIClass SpiHCI(D11, D12, D3); diff --git a/examples/Central/Scan/Scan.ino b/examples/Central/Scan/Scan.ino index 30e382e5..8d1357b3 100644 --- a/examples/Central/Scan/Scan.ino +++ b/examples/Central/Scan/Scan.ino @@ -22,6 +22,10 @@ BLELocalDevice BLE(&HCISpiTransport); SPIClass SpiHCI(PC12, PC11, PC10); HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, PD13, PE6, PA8, 8000000, SPI_MODE0); BLELocalDevice BLE(&HCISpiTransport); +#elif defined(ARDUINO_PNUCLEO_WB55RG) +/* PNUCLEO_WB55RG */ +HCISharedMemTransportClass HCISharedMemTransport; +BLELocalDevice BLE(&HCISharedMemTransport); #else /* Shield IDB05A2 with SPI clock on D3 */ SPIClass SpiHCI(D11, D12, D3); diff --git a/examples/Central/ScanCallback/ScanCallback.ino b/examples/Central/ScanCallback/ScanCallback.ino index e7c1711e..0cf28c57 100644 --- a/examples/Central/ScanCallback/ScanCallback.ino +++ b/examples/Central/ScanCallback/ScanCallback.ino @@ -24,6 +24,10 @@ BLELocalDevice BLE(&HCISpiTransport); SPIClass SpiHCI(PC12, PC11, PC10); HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, PD13, PE6, PA8, 8000000, SPI_MODE0); BLELocalDevice BLE(&HCISpiTransport); +#elif defined(ARDUINO_PNUCLEO_WB55RG) +/* PNUCLEO_WB55RG */ +HCISharedMemTransportClass HCISharedMemTransport; +BLELocalDevice BLE(&HCISharedMemTransport); #else /* Shield IDB05A2 with SPI clock on D3 */ SPIClass SpiHCI(D11, D12, D3); diff --git a/examples/Central/SensorTagButton/SensorTagButton.ino b/examples/Central/SensorTagButton/SensorTagButton.ino index 0fdfdb13..fdb469d3 100644 --- a/examples/Central/SensorTagButton/SensorTagButton.ino +++ b/examples/Central/SensorTagButton/SensorTagButton.ino @@ -26,6 +26,10 @@ BLELocalDevice BLE(&HCISpiTransport); SPIClass SpiHCI(PC12, PC11, PC10); HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, PD13, PE6, PA8, 8000000, SPI_MODE0); BLELocalDevice BLE(&HCISpiTransport); +#elif defined(ARDUINO_PNUCLEO_WB55RG) +/* PNUCLEO_WB55RG */ +HCISharedMemTransportClass HCISharedMemTransport; +BLELocalDevice BLE(&HCISharedMemTransport); #else /* Shield IDB05A2 with SPI clock on D3 */ SPIClass SpiHCI(D11, D12, D3); diff --git a/examples/Peripheral/ButtonLED/ButtonLED.ino b/examples/Peripheral/ButtonLED/ButtonLED.ino index e343fb26..a84fbd92 100644 --- a/examples/Peripheral/ButtonLED/ButtonLED.ino +++ b/examples/Peripheral/ButtonLED/ButtonLED.ino @@ -29,6 +29,11 @@ SPIClass SpiHCI(PC12, PC11, PC10); HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, PD13, PE6, PA8, 8000000, SPI_MODE0); BLELocalDevice BLE(&HCISpiTransport); const int buttonPin = PC13; // set buttonPin to digital pin PC13 +#elif defined(ARDUINO_PNUCLEO_WB55RG) +/* PNUCLEO_WB55RG */ +HCISharedMemTransportClass HCISharedMemTransport; +BLELocalDevice BLE(&HCISharedMemTransport); +const int buttonPin = PC4; // set buttonPin to digital pin PC4 #else /* Shield IDB05A2 with SPI clock on D3 */ SPIClass SpiHCI(D11, D12, D3); diff --git a/examples/Peripheral/CallbackLED/CallbackLED.ino b/examples/Peripheral/CallbackLED/CallbackLED.ino index 44be0e39..b1d5da94 100644 --- a/examples/Peripheral/CallbackLED/CallbackLED.ino +++ b/examples/Peripheral/CallbackLED/CallbackLED.ino @@ -27,6 +27,10 @@ BLELocalDevice BLE(&HCISpiTransport); SPIClass SpiHCI(PC12, PC11, PC10); HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, PD13, PE6, PA8, 8000000, SPI_MODE0); BLELocalDevice BLE(&HCISpiTransport); +#elif defined(ARDUINO_PNUCLEO_WB55RG) +/* PNUCLEO_WB55RG */ +HCISharedMemTransportClass HCISharedMemTransport; +BLELocalDevice BLE(&HCISharedMemTransport); #else /* Shield IDB05A2 with SPI clock on D3 */ SPIClass SpiHCI(D11, D12, D3); diff --git a/examples/Peripheral/LED/LED.ino b/examples/Peripheral/LED/LED.ino index 8269bfcc..d7748474 100644 --- a/examples/Peripheral/LED/LED.ino +++ b/examples/Peripheral/LED/LED.ino @@ -25,6 +25,10 @@ BLELocalDevice BLE(&HCISpiTransport); SPIClass SpiHCI(PC12, PC11, PC10); HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, PD13, PE6, PA8, 8000000, SPI_MODE0); BLELocalDevice BLE(&HCISpiTransport); +#elif defined(ARDUINO_PNUCLEO_WB55RG) +/* PNUCLEO_WB55RG */ +HCISharedMemTransportClass HCISharedMemTransport; +BLELocalDevice BLE(&HCISharedMemTransport); #else /* Shield IDB05A2 with SPI clock on D3 */ SPIClass SpiHCI(D11, D12, D3); From 3a063dff2f8d4159ced2c98e7d866973dbaf6eec Mon Sep 17 00:00:00 2001 From: Francois Ramu <francois.ramu@st.com> Date: Thu, 28 Jan 2021 16:40:56 +0100 Subject: [PATCH 044/226] Include a timeout when waiting for the cmd_resp Signed-off-by: Francois Ramu <francois.ramu@st.com> --- src/utility/STM32Cube_FW/shci_tl.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/utility/STM32Cube_FW/shci_tl.c b/src/utility/STM32Cube_FW/shci_tl.c index 1ab15b47..c2d7589e 100644 --- a/src/utility/STM32Cube_FW/shci_tl.c +++ b/src/utility/STM32Cube_FW/shci_tl.c @@ -21,6 +21,8 @@ /* Includes ------------------------------------------------------------------*/ #include "stm32_wpan_common.h" +#include <Arduino.h> + #include "stm_list.h" #include "shci_tl.h" #include "stm32_def.h" @@ -323,11 +325,12 @@ static void OutputEvtTrace(TL_EvtPacket_t *phcievtbuffer) /* Weak implementation ----------------------------------------------------------------*/ __WEAK void shci_cmd_resp_wait(uint32_t timeout) { - (void)timeout; - CmdRspStatusFlag = SHCI_TL_CMD_RESP_WAIT; - while (CmdRspStatusFlag != SHCI_TL_CMD_RESP_RELEASE); - + for (unsigned long start = millis(); (millis() - start) < timeout;) { + if (CmdRspStatusFlag == SHCI_TL_CMD_RESP_RELEASE) { + break; + } + } return; } From afeccd3c7f9c6a6164e2dbd76886537dd8699a40 Mon Sep 17 00:00:00 2001 From: Francois Ramu <francois.ramu@st.com> Date: Tue, 2 Feb 2021 12:36:53 +0100 Subject: [PATCH 045/226] Activate default clocks on the STM32WB Signed-off-by: Francois Ramu <francois.ramu@st.com> --- src/utility/HCISharedMemTransport.cpp | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/utility/HCISharedMemTransport.cpp b/src/utility/HCISharedMemTransport.cpp index c798fe74..b97fea95 100644 --- a/src/utility/HCISharedMemTransport.cpp +++ b/src/utility/HCISharedMemTransport.cpp @@ -553,14 +553,24 @@ size_t HCISharedMemTransportClass::write(const uint8_t *data, size_t length) //private: void HCISharedMemTransportClass::start_ble_rf(void) { - if ((LL_RCC_IsActiveFlag_PINRST()) && (!LL_RCC_IsActiveFlag_SFTRST())) { - /* Simulate power off reset */ - LL_PWR_EnableBkUpAccess(); - LL_PWR_EnableBkUpAccess(); - LL_RCC_ForceBackupDomainReset(); - LL_RCC_ReleaseBackupDomainReset(); + /* Set the DBP bit in the Power control register 1 (PWR_CR1) */ + LL_PWR_EnableBkUpAccess(); + + /* LSE belongs to the back-up domain, enable access.*/ + while (!LL_PWR_IsEnabledBkUpAccess()) { + /* Wait for Backup domain access */ + } + LL_RCC_ForceBackupDomainReset(); + LL_RCC_ReleaseBackupDomainReset(); + + /* Enable LSE Oscillator (32.768 kHz) */ + LL_RCC_LSE_Enable(); + while (!LL_RCC_LSE_IsReady()) { + /* Wait for LSE ready */ } + LL_PWR_DisableBkUpAccess(); + /* Switch OFF LSI as LSE is the source clock */ LL_RCC_LSI2_Disable(); } From 870c91ee0b5836b324809e2b93fd289558149f35 Mon Sep 17 00:00:00 2001 From: Francois Ramu <francois.ramu@st.com> Date: Thu, 4 Feb 2021 10:38:12 +0100 Subject: [PATCH 046/226] Set a new bd address for the BLE device In case the bd address cannot be computed from the flash then the otp is read to provide a valid one in a OTP_BT_t Signed-off-by: Francois Ramu <francois.ramu@st.com> --- src/utility/HCISharedMemTransport.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/utility/HCISharedMemTransport.cpp b/src/utility/HCISharedMemTransport.cpp index c798fe74..02bba7c7 100644 --- a/src/utility/HCISharedMemTransport.cpp +++ b/src/utility/HCISharedMemTransport.cpp @@ -20,6 +20,7 @@ #include "HCISharedMemTransport.h" #include "STM32Cube_FW/hw.h" +#include "otp.h" /* Private variables ---------------------------------------------------------*/ PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static TL_CmdPacket_t BleCmdBuffer; @@ -338,8 +339,13 @@ static bool get_bd_address(uint8_t *bd_addr) bd_found = true; } else { - bd_addr = NULL; - bd_found = false; + OTP_BT_t *p_otp = (OTP_BT_t *)OTP_Read(0); + if (p_otp) { + memcpy(bd_addr, p_otp->bd_address, CONFIG_DATA_PUBADDR_LEN); + bd_found = true; + } else { + bd_found = false; + } } return bd_found; From 439eca03d4351e24a5f94f48e765ed95ead8db68 Mon Sep 17 00:00:00 2001 From: Carlo Parata <carlo.parata@st.com> Date: Mon, 8 Feb 2021 16:11:26 +0100 Subject: [PATCH 047/226] Add static random address support for all ST BLE chips --- src/utility/HCISharedMemTransport.cpp | 200 +++++++- src/utility/HCISharedMemTransport.h | 5 + src/utility/HCISpiTransport.cpp | 639 +++++++++++++++++++++++++- src/utility/HCISpiTransport.h | 7 + 4 files changed, 829 insertions(+), 22 deletions(-) diff --git a/src/utility/HCISharedMemTransport.cpp b/src/utility/HCISharedMemTransport.cpp index 8ccd6b25..17526274 100644 --- a/src/utility/HCISharedMemTransport.cpp +++ b/src/utility/HCISharedMemTransport.cpp @@ -48,11 +48,17 @@ volatile uint16_t _write_index; /* fifo position when receiving */ /* var of different device steps during init and receiving */ volatile bool phase_bd_addr; volatile bool phase_tx_power; +volatile bool phase_gatt_init; +volatile bool phase_gap_init; +volatile bool phase_random_addr; +volatile bool phase_get_random_addr; volatile bool phase_reset; volatile bool phase_running; +volatile bool is_random_addr_msg; /** Bluetooth Device Address */ static uint8_t bd_addr_udn[CONFIG_DATA_PUBADDR_LEN]; +static uint8_t helper_random_addr[6]; /* Private functions ---------------------------------------------------------*/ /** @@ -175,12 +181,21 @@ void evt_received(TL_EvtPacket_t *hcievt) * the Reset packet is handled at HCI layer : the running_phase begins */ if (phase_running == false) { - /* check the Rx event of complete the previous bd_addr opcode 0xFC0C */ + /* check the Rx event of complete the previous bd_addr or random address opcode 0xFC0C */ if ((hcievt->evtserial.evt.evtcode == TL_BLEEVT_CC_OPCODE) && (hcievt->evtserial.evt.payload[0] == 0x01) && (hcievt->evtserial.evt.payload[1] == 0x0C) && (hcievt->evtserial.evt.payload[2] == 0xFC)) { - phase_bd_addr = true; + /* First setting must be global address and is_random_addr_msg should be false + * Second setting must be static random address and is_random_addr_msg should be true + */ + if(!is_random_addr_msg) { + phase_bd_addr = true; + is_random_addr_msg = true; + } else { + phase_random_addr = true; + is_random_addr_msg = false; + } if (hcievt->evtserial.evt.payload[3] != 0) { #if defined(PRINT_IPCC_INFO) printf("Error: wrong BD Addr\r\n"); @@ -203,6 +218,50 @@ void evt_received(TL_EvtPacket_t *hcievt) /* rx data is no more useful : not stored in the _rxbuff */ break; } + /* check the Rx event of complete the previous gatt init 0xFD01 */ + if ((hcievt->evtserial.evt.evtcode == TL_BLEEVT_CC_OPCODE) && + (hcievt->evtserial.evt.payload[0] == 0x01) && + (hcievt->evtserial.evt.payload[1] == 0x01) && + (hcievt->evtserial.evt.payload[2] == 0xFD)) { + phase_gatt_init = true; + if (hcievt->evtserial.evt.payload[3] != 0) { +#if defined(PRINT_IPCC_INFO) + printf("Error: wrong Random Addr\r\n"); +#endif /*(PRINT_IPCC_INFO)*/ + } + /* rx data is no more useful : not stored in the _rxbuff */ + break; + } + /* check the Rx event of complete the previous gap init 0xFC8A */ + if ((hcievt->evtserial.evt.evtcode == TL_BLEEVT_CC_OPCODE) && + (hcievt->evtserial.evt.payload[0] == 0x01) && + (hcievt->evtserial.evt.payload[1] == 0x8A) && + (hcievt->evtserial.evt.payload[2] == 0xFC)) { + phase_gap_init = true; + if (hcievt->evtserial.evt.payload[3] != 0) { +#if defined(PRINT_IPCC_INFO) + printf("Error: wrong Random Addr\r\n"); +#endif /*(PRINT_IPCC_INFO)*/ + } + /* rx data is no more useful : not stored in the _rxbuff */ + break; + } + /* check the Rx event of complete the previous get random addr opcode 0xFC0D */ + if ((hcievt->evtserial.evt.evtcode == TL_BLEEVT_CC_OPCODE) && + (hcievt->evtserial.evt.payload[0] == 0x01) && + (hcievt->evtserial.evt.payload[1] == 0x0D) && + (hcievt->evtserial.evt.payload[2] == 0xFC)) { + if (hcievt->evtserial.evt.payload[3] != 0) { +#if defined(PRINT_IPCC_INFO) + printf("Error: wrong Random Addr\r\n"); +#endif /*(PRINT_IPCC_INFO)*/ + } + + memcpy(helper_random_addr, &hcievt->evtserial.evt.payload[5], 6); + phase_get_random_addr = true; + /* rx data is no more useful : not stored in the _rxbuff */ + break; + } /* check if the reset phase is in progress (opcode is 0x0C03) */ if ((hcievt->evtserial.evt.evtcode == TL_BLEEVT_CC_OPCODE) && (hcievt->evtserial.evt.payload[0] == 0x01) && @@ -389,8 +448,13 @@ HCISharedMemTransportClass::HCISharedMemTransportClass() phase_bd_addr = false; phase_tx_power = false; + phase_gatt_init = false; + phase_gap_init = false; + phase_random_addr = false; + phase_get_random_addr = false; phase_reset = false; phase_running = false; + is_random_addr_msg = false; } HCISharedMemTransportClass::~HCISharedMemTransportClass() @@ -453,8 +517,13 @@ void HCISharedMemTransportClass::end() /* the HCI RESET command ready to be processed again */ phase_bd_addr = false; phase_tx_power = false; + phase_gatt_init = false; + phase_gap_init = false; + phase_random_addr = false; + phase_get_random_addr = false; phase_reset = false; phase_running = false; + is_random_addr_msg = false; } void HCISharedMemTransportClass::wait(unsigned long timeout) @@ -543,11 +612,34 @@ size_t HCISharedMemTransportClass::write(const uint8_t *data, size_t length) while (!phase_bd_addr); /* this sequence is now complete */ + /* set the random address */ + bt_ipm_set_random_addr(); + /* wait for the Rx complete */ + while (!phase_random_addr); + /* set the Tx power */ bt_ipm_set_power(); /* wait for the Rx complete */ while (!phase_tx_power); + /* gatt init */ + bt_ipm_gatt_init(); + /* wait for the Rx complete */ + while (!phase_gatt_init); + + /* gap init */ + bt_ipm_gap_init(); + /* wait for the Rx complete */ + while (!phase_gap_init); + + /* get the random address */ + bt_ipm_get_random_addr(); + /* wait for the Rx complete */ + while (!phase_get_random_addr); + + /* Now we can copy the random address and save it in the transport class */ + memcpy(_random_addr, helper_random_addr, 6); + /* this sequence is now complete */ phase_running = true; @@ -725,6 +817,41 @@ int HCISharedMemTransportClass::bt_ipm_set_addr(void) return 0; /* Error */ } +int HCISharedMemTransportClass::bt_ipm_set_random_addr(void) +{ + /* the specific table for set addr is 8 bytes: + * one byte for config_offset + * one byte for length + * 6 bytes for payload */ + uint8_t data[4 + 8]; + + /* + * Static random Address + * The two upper bits shall be set to 1 + * The lowest 32bits is read from the UDN to differentiate between devices + * The RNG may be used to provide a random number on each power on + */ + uint32_t srd_bd_addr[2]; + + phase_random_addr = false; + + srd_bd_addr[1] = 0x0000ED6E; + srd_bd_addr[0] = LL_FLASH_GetUDN( ); + + data[0] = BT_BUF_CMD; + data[1] = uint8_t(ACI_WRITE_CONFIG_DATA_OPCODE & 0x000000FF); /* OCF */ + data[2] = uint8_t((ACI_WRITE_CONFIG_DATA_OPCODE & 0x0000FF00) >> 8); /* OGF */ + data[3] = 8; /* length of parameters */ + /* fill the ACI_HAL_WRITE_CONFIG_DATA with the addr*/ + data[4] = 0x2E; /* the offset */ + data[5] = 6; /* is the length of the random address */ + memcpy(data + 6, srd_bd_addr, 6); + /* send the ACI_HAL_WRITE_CONFIG_DATA */ + mbox_write(data[0], 11, &data[1]); + /* now wait for the corresponding Rx event */ + return 1; /* success */ +} + int HCISharedMemTransportClass::bt_ipm_set_power(void) { /* the specific table for power is 2 bytes: @@ -737,14 +864,79 @@ int HCISharedMemTransportClass::bt_ipm_set_power(void) data[1] = (uint8_t)(ACI_HAL_SET_TX_POWER_LEVEL & 0x000000FF); /* the OPCODE */ data[2] = (uint8_t)((ACI_HAL_SET_TX_POWER_LEVEL & 0x0000FF00) >> 8); data[3] = 2; /* the length */ - /* fill the ACI_HAL_WRITE_CONFIG_DATA */ + /* fill the SET_POWER */ data[4] = 0x01; /* En_High_Power */ data[5] = CFG_TX_POWER; /* PA_level */ - /* send the ACI_HAL_WRITE_CONFIG_DATA */ + /* send the SET_POWER */ mbox_write(data[0], 5, &data[1]); /* now wait for the corresponding Rx event */ return 1; /* success */ } +int HCISharedMemTransportClass::bt_ipm_gatt_init(void) +{ + /* the specific table for gatt init */ + uint8_t data[4]; + + phase_gatt_init = false; + + data[0] = BT_BUF_CMD; /* the type */ + data[1] = 0x01; /* the OPCODE */ + data[2] = 0xFD; + data[3] = 0; /* the length */ + + /* send the GATT_INIT */ + mbox_write(data[0], 3, &data[1]); + /* now wait for the corresponding Rx event */ + return 1; /* success */ +} + +int HCISharedMemTransportClass::bt_ipm_gap_init(void) +{ + /* the specific table for gap init is 3 bytes: + * Role byte, enable_privacy byte, device_name_char_len byte */ + uint8_t data[4 + 3]; + + phase_tx_power = false; + + data[0] = BT_BUF_CMD; /* the type */ + data[1] = 0x8A; /* the OPCODE */ + data[2] = 0xFC; + data[3] = 3; /* the length */ + /* fill the GAP_INIT */ + data[4] = 0x0F; /* role */ + data[5] = 0x00; /* enable_privacy */ + data[6] = 0x00; /* device_name_char_len */ + + /* send the GAP_INIT */ + mbox_write(data[0], 6, &data[1]); + /* now wait for the corresponding Rx event */ + return 1; /* success */ +} + +int HCISharedMemTransportClass::bt_ipm_get_random_addr(void) +{ + /* the specific table for set addr is 8 bytes: + * one byte for config_offset + * one byte for length + * 6 bytes for payload */ + uint8_t data[4 + 1]; + + phase_get_random_addr = false; + + /* create ACI_READ_CONFIG_DATA_OPCODE */ + data[0] = BT_BUF_CMD; + data[1] = uint8_t(ACI_READ_CONFIG_DATA_OPCODE & 0x000000FF); /* OCF */ + data[2] = uint8_t((ACI_READ_CONFIG_DATA_OPCODE & 0x0000FF00) >> 8); /* OGF */ + data[3] = 1; /* length of parameters */ + /* fill the ACI_READ_CONFIG_DATA_OPCODE with the offset*/ + data[4] = 0x2E; /* the offset */ + + /* send the ACI_READ_CONFIG_DATA_OPCODE */ + mbox_write(data[0], 4, &data[1]); + /* now wait for the corresponding Rx event */ + return 1; /* success */ +} + #endif /* STM32WBxx */ diff --git a/src/utility/HCISharedMemTransport.h b/src/utility/HCISharedMemTransport.h index 9b9751f2..e4bd6ed6 100644 --- a/src/utility/HCISharedMemTransport.h +++ b/src/utility/HCISharedMemTransport.h @@ -87,8 +87,13 @@ class HCISharedMemTransportClass : public HCITransportInterface { int stm32wb_start_ble(void); int bt_ipm_ble_init(void); int bt_ipm_set_addr(void); + int bt_ipm_set_random_addr(void); int bt_ipm_set_power(void); + int bt_ipm_gatt_init(void); + int bt_ipm_gap_init(void); + int bt_ipm_get_random_addr(void); + uint8_t _random_addr[6]; }; #endif /* _HCI_SHARED_MEM_TRANSPORT_H_ */ diff --git a/src/utility/HCISpiTransport.cpp b/src/utility/HCISpiTransport.cpp index 512e6e9a..cb2430c2 100644 --- a/src/utility/HCISpiTransport.cpp +++ b/src/utility/HCISpiTransport.cpp @@ -237,6 +237,15 @@ int HCISpiTransportClass::available() delay(300); } + /* Call ACI Gatt Init and ACI Gap Init to activate the random BLE address */ + aci_gatt_init(); + wait_for_aci_gatt_init(); + aci_gap_init(); + wait_for_aci_gap_init(); + /* Call ACI Read Config Parameter to retrieve the random BLE address */ + aci_read_config_parameter(); + wait_for_aci_read_config_parameter(); + /* Now we can update the write index and close the initial phase */ _write_index = _write_index_initial; _initial_phase = 0; @@ -397,6 +406,10 @@ void HCISpiTransportClass::wait_for_blue_initialize() while (digitalRead(_spi_irq) == 1) { uint8_t header_master[5] = {0x0b, 0x00, 0x00, 0x00, 0x00}; + if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP) { + detachInterrupt(_spi_irq); + } + _spi->beginTransaction(_spiSettings); digitalWrite(_cs_pin, LOW); @@ -404,9 +417,35 @@ void HCISpiTransportClass::wait_for_blue_initialize() /* Write the header */ _spi->transfer(header_master, 5); - /* device is ready */ - if (header_master[0] == 0x02) { + if (_ble_chip == SPBTLE_RF || _ble_chip == BLUENRG_M0) { /* device is ready */ + if (header_master[0] == 0x02) { + /* device is ready */ + uint16_t byte_count = (header_master[4] << 8) | header_master[3]; + + if (byte_count > 0) { + /* Read the response */ + if (byte_count == 6) { + for (int j = 0; j < byte_count; j++) { + event[j] = _spi->transfer(0xFF); + } + + if (event[0] == 0x04 && + event[1] == 0xFF && + event[2] == 0x03 && + event[3] == 0x01 && + event[4] == 0x00 && + event[5] == 0x01) { + event_blue_initialize = 1; + } + } else { + for (int j = 0; j < byte_count; j++) { + _spi->transfer(0xFF); + } + } + } + } + } else if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP) { uint16_t byte_count = (header_master[4] << 8) | header_master[3]; if (byte_count > 0) { @@ -435,6 +474,10 @@ void HCISpiTransportClass::wait_for_blue_initialize() digitalWrite(_cs_pin, HIGH); _spi->endTransaction(); + + if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP) { + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + } } } while (!event_blue_initialize); } @@ -455,6 +498,10 @@ void HCISpiTransportClass::wait_for_enable_ll_only() while (digitalRead(_spi_irq) == 1) { uint8_t header_master[5] = {0x0b, 0x00, 0x00, 0x00, 0x00}; + if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP) { + detachInterrupt(_spi_irq); + } + _spi->beginTransaction(_spiSettings); digitalWrite(_cs_pin, LOW); @@ -462,9 +509,32 @@ void HCISpiTransportClass::wait_for_enable_ll_only() /* Write the header */ _spi->transfer(header_master, 5); - /* device is ready */ - if (header_master[0] == 0x02) { + if (_ble_chip == SPBTLE_RF || _ble_chip == BLUENRG_M0) { /* device is ready */ + if (header_master[0] == 0x02) { + /* device is ready */ + uint16_t byte_count = (header_master[4] << 8) | header_master[3]; + + if (byte_count > 0) { + /* Read the response */ + for (int j = 0; j < byte_count; j++) { + data[j] = _spi->transfer(0xFF); + } + + if (byte_count >= 7) { + if (data[0] == 0x04 && + data[1] == 0x0E && + data[2] == 0x04 && + data[3] == 0x01 && + data[4] == 0x0C && + data[5] == 0xFC && + data[6] == 0x00) { + status = 1; + } + } + } + } + } else if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP) { uint16_t byte_count = (header_master[4] << 8) | header_master[3]; if (byte_count > 0) { @@ -473,7 +543,7 @@ void HCISpiTransportClass::wait_for_enable_ll_only() data[j] = _spi->transfer(0xFF); } - if (byte_count == 7) { + if (byte_count >= 7) { if (data[0] == 0x04 && data[1] == 0x0E && data[2] == 0x04 && @@ -490,6 +560,10 @@ void HCISpiTransportClass::wait_for_enable_ll_only() digitalWrite(_cs_pin, HIGH); _spi->endTransaction(); + + if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP) { + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + } } } while (!status); } @@ -501,30 +575,559 @@ void HCISpiTransportClass::enable_ll_only() int result = 0; do { - result = 0; + if (_ble_chip == SPBTLE_RF || _ble_chip == BLUENRG_M0) { + result = 0; + + _spi->beginTransaction(_spiSettings); + + digitalWrite(_cs_pin, LOW); + + /* Write the header */ + _spi->transfer(header_master, 5); + + /* device is ready */ + if (header_master[0] == 0x02) { + /* Write the data */ + if (header_master[1] >= 7) { + /* Write the data */ + _spi->transfer((void *)cmd, 7); + } else { + result = -2; + } + } else { + result = -1; + } + + digitalWrite(_cs_pin, HIGH); + + _spi->endTransaction(); + } else if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP) { + uint32_t tickstart_data_available = millis(); + result = 0; + + detachInterrupt(_spi_irq); + + _spi->beginTransaction(_spiSettings); + + digitalWrite(_cs_pin, LOW); - _spi->beginTransaction(_spiSettings); + while (!(digitalRead(_spi_irq) == 1)) { + if ((millis() - tickstart_data_available) > 1000) { + result = -3; + break; + } + } - digitalWrite(_cs_pin, LOW); + if (result == -3) { + digitalWrite(_cs_pin, HIGH); + _spi->endTransaction(); + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + break; + } - /* Write the header */ - _spi->transfer(header_master, 5); + /* Write the header */ + _spi->transfer(header_master, 5); - /* device is ready */ - if (header_master[0] == 0x02) { - /* Write the data */ - if (header_master[1] >= 7) { + if ((int)((((uint16_t)header_master[2]) << 8) | ((uint16_t)header_master[1])) >= 7) { /* Write the data */ _spi->transfer((void *)cmd, 7); } else { result = -2; } - } else { - result = -1; + + digitalWrite(_cs_pin, HIGH); + + _spi->endTransaction(); + + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + } + } while (result < 0); +} + +void HCISpiTransportClass::wait_for_aci_gatt_init() +{ + uint8_t data[8]; + int status = 0; + + do { + while (!data_avail); + + if (digitalRead(_spi_irq) == 0) { + continue; + } + + data_avail = 0; + while (digitalRead(_spi_irq) == 1) { + uint8_t header_master[5] = {0x0b, 0x00, 0x00, 0x00, 0x00}; + + if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP) { + detachInterrupt(_spi_irq); + } + + _spi->beginTransaction(_spiSettings); + + digitalWrite(_cs_pin, LOW); + + /* Write the header */ + _spi->transfer(header_master, 5); + + if (_ble_chip == SPBTLE_RF || _ble_chip == BLUENRG_M0) { + /* device is ready */ + if (header_master[0] == 0x02) { + /* device is ready */ + uint16_t byte_count = (header_master[4] << 8) | header_master[3]; + + if (byte_count > 0) { + /* Read the response */ + for (int j = 0; j < byte_count; j++) { + data[j] = _spi->transfer(0xFF); + } + + if (byte_count >= 7) { + if (data[0] == 0x04 && + data[1] == 0x0E && + data[2] == 0x04 && + data[3] == 0x01 && + data[4] == 0x01 && + data[5] == 0xFD && + data[6] == 0x00) { + status = 1; + } + } + } + } + } else if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP) { + uint16_t byte_count = (header_master[4] << 8) | header_master[3]; + + if (byte_count > 0) { + /* Read the response */ + for (int j = 0; j < byte_count; j++) { + data[j] = _spi->transfer(0xFF); + } + + if (byte_count >= 7) { + if (data[0] == 0x04 && + data[1] == 0x0E && + data[2] == 0x04 && + data[3] == 0x01 && + data[4] == 0x01 && + data[5] == 0xFD && + data[6] == 0x00) { + status = 1; + } + } + } + } + + digitalWrite(_cs_pin, HIGH); + + _spi->endTransaction(); + + if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP) { + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + } + } + } while (!status); +} + +void HCISpiTransportClass::aci_gatt_init() +{ + uint8_t header_master[5] = {0x0a, 0x00, 0x00, 0x00, 0x00}; + uint8_t cmd[4] = {0x01, 0x01, 0xFD, 0x00}; // ACI_GATT_INIT + int result = 0; + + do { + if (_ble_chip == SPBTLE_RF || _ble_chip == BLUENRG_M0) { + result = 0; + + _spi->beginTransaction(_spiSettings); + + digitalWrite(_cs_pin, LOW); + + /* Write the header */ + _spi->transfer(header_master, 5); + + /* device is ready */ + if (header_master[0] == 0x02) { + /* Write the data */ + if (header_master[1] >= 4) { + /* Write the data */ + _spi->transfer((void *)cmd, 4); + } else { + result = -2; + } + } else { + result = -1; + } + + digitalWrite(_cs_pin, HIGH); + + _spi->endTransaction(); + } else if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP) { + uint32_t tickstart_data_available = millis(); + result = 0; + + detachInterrupt(_spi_irq); + + _spi->beginTransaction(_spiSettings); + + digitalWrite(_cs_pin, LOW); + + while (!(digitalRead(_spi_irq) == 1)) { + if ((millis() - tickstart_data_available) > 1000) { + result = -3; + break; + } + } + + if (result == -3) { + digitalWrite(_cs_pin, HIGH); + _spi->endTransaction(); + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + break; + } + + /* Write the header */ + _spi->transfer(header_master, 5); + + if ((int)((((uint16_t)header_master[2]) << 8) | ((uint16_t)header_master[1])) >= 4) { + /* Write the data */ + _spi->transfer((void *)cmd, 4); + } else { + result = -2; + } + + digitalWrite(_cs_pin, HIGH); + + _spi->endTransaction(); + + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); } + } while (result < 0); +} + +void HCISpiTransportClass::wait_for_aci_gap_init() +{ + uint8_t data[14]; + int status = 0; - digitalWrite(_cs_pin, HIGH); + do { + while (!data_avail); - _spi->endTransaction(); + if (digitalRead(_spi_irq) == 0) { + continue; + } + + data_avail = 0; + while (digitalRead(_spi_irq) == 1) { + uint8_t header_master[5] = {0x0b, 0x00, 0x00, 0x00, 0x00}; + + if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP) { + detachInterrupt(_spi_irq); + } + + _spi->beginTransaction(_spiSettings); + + digitalWrite(_cs_pin, LOW); + + /* Write the header */ + _spi->transfer(header_master, 5); + + if (_ble_chip == SPBTLE_RF || _ble_chip == BLUENRG_M0) { + /* device is ready */ + if (header_master[0] == 0x02) { + /* device is ready */ + uint16_t byte_count = (header_master[4] << 8) | header_master[3]; + + if (byte_count > 0) { + /* Read the response */ + for (int j = 0; j < byte_count; j++) { + data[j] = _spi->transfer(0xFF); + } + + if (byte_count >= 13) { + if (data[0] == 0x04 && + data[1] == 0x0E && + data[2] == 0x0A && + data[3] == 0x01 && + data[4] == 0x8A && + data[5] == 0xFC && + data[6] == 0x00) { + status = 1; + } + } + } + } + } else if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP) { + uint16_t byte_count = (header_master[4] << 8) | header_master[3]; + + if (byte_count > 0) { + /* Read the response */ + for (int j = 0; j < byte_count; j++) { + data[j] = _spi->transfer(0xFF); + } + + if (byte_count >= 13) { + if (data[0] == 0x04 && + data[1] == 0x0E && + data[2] == 0x0A && + data[3] == 0x01 && + data[4] == 0x8A && + data[5] == 0xFC && + data[6] == 0x00) { + status = 1; + } + } + } + } + + digitalWrite(_cs_pin, HIGH); + + _spi->endTransaction(); + + if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP) { + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + } + } + } while (!status); +} + +void HCISpiTransportClass::aci_gap_init() +{ + uint8_t header_master[5] = {0x0a, 0x00, 0x00, 0x00, 0x00}; + uint8_t cmd[7] = {0x01, 0x8A, 0xFC, 0x03, 0x0F, 0x00, 0x00}; // ACI_GAP_INIT + int result = 0; + + do { + if (_ble_chip == SPBTLE_RF || _ble_chip == BLUENRG_M0) { + result = 0; + + _spi->beginTransaction(_spiSettings); + + digitalWrite(_cs_pin, LOW); + + /* Write the header */ + _spi->transfer(header_master, 5); + + /* device is ready */ + if (header_master[0] == 0x02) { + /* Write the data */ + if (header_master[1] >= 7) { + /* Write the data */ + _spi->transfer((void *)cmd, 7); + } else { + result = -2; + } + } else { + result = -1; + } + + digitalWrite(_cs_pin, HIGH); + + _spi->endTransaction(); + } else if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP) { + uint32_t tickstart_data_available = millis(); + result = 0; + + detachInterrupt(_spi_irq); + + _spi->beginTransaction(_spiSettings); + + digitalWrite(_cs_pin, LOW); + + while (!(digitalRead(_spi_irq) == 1)) { + if ((millis() - tickstart_data_available) > 1000) { + result = -3; + break; + } + } + + if (result == -3) { + digitalWrite(_cs_pin, HIGH); + _spi->endTransaction(); + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + break; + } + + /* Write the header */ + _spi->transfer(header_master, 5); + + if ((int)((((uint16_t)header_master[2]) << 8) | ((uint16_t)header_master[1])) >= 7) { + /* Write the data */ + _spi->transfer((void *)cmd, 7); + } else { + result = -2; + } + + digitalWrite(_cs_pin, HIGH); + + _spi->endTransaction(); + + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + } + } while (result < 0); +} + +void HCISpiTransportClass::wait_for_aci_read_config_parameter() +{ + uint8_t data[15]; + int status = 0; + + do { + while (!data_avail); + + if (digitalRead(_spi_irq) == 0) { + continue; + } + + data_avail = 0; + while (digitalRead(_spi_irq) == 1) { + uint8_t header_master[5] = {0x0b, 0x00, 0x00, 0x00, 0x00}; + + if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP) { + detachInterrupt(_spi_irq); + } + + _spi->beginTransaction(_spiSettings); + + digitalWrite(_cs_pin, LOW); + + /* Write the header */ + _spi->transfer(header_master, 5); + + if (_ble_chip == SPBTLE_RF || _ble_chip == BLUENRG_M0) { + /* device is ready */ + if (header_master[0] == 0x02) { + /* device is ready */ + uint16_t byte_count = (header_master[4] << 8) | header_master[3]; + + if (byte_count > 0) { + /* Read the response */ + for (int j = 0; j < byte_count; j++) { + data[j] = _spi->transfer(0xFF); + } + + if (byte_count >= 13) { + if (data[0] == 0x04 && + data[1] == 0x0E && + data[2] == 0x0A && + data[3] == 0x01 && + data[4] == 0x0D && + data[5] == 0xFC && + data[6] == 0x00) { + memcpy(_random_addr, &data[7], 6); + status = 1; + } + } + } + } + } else if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP) { + uint16_t byte_count = (header_master[4] << 8) | header_master[3]; + + if (byte_count > 0) { + /* Read the response */ + for (int j = 0; j < byte_count; j++) { + data[j] = _spi->transfer(0xFF); + } + + if (byte_count >= 14) { + if (data[0] == 0x04 && + data[1] == 0x0E && + data[2] == 0x0B && + data[3] == 0x01 && + data[4] == 0x0D && + data[5] == 0xFC && + data[6] == 0x00) { + memcpy(_random_addr, &data[8], 6); + status = 1; + } + } + } + } + + digitalWrite(_cs_pin, HIGH); + + _spi->endTransaction(); + + if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP) { + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + } + } + } while (!status); +} + +void HCISpiTransportClass::aci_read_config_parameter() +{ + uint8_t header_master[5] = {0x0a, 0x00, 0x00, 0x00, 0x00}; + uint8_t cmd[5] = {0x01, 0x0D, 0xFC, 0x01, 0x80}; // ACI_READ_CONFIG_PARAMETER + int result = 0; + + do { + if (_ble_chip == SPBTLE_RF || _ble_chip == BLUENRG_M0) { + result = 0; + + _spi->beginTransaction(_spiSettings); + + digitalWrite(_cs_pin, LOW); + + /* Write the header */ + _spi->transfer(header_master, 5); + + /* device is ready */ + if (header_master[0] == 0x02) { + /* Write the data */ + if (header_master[1] >= 5) { + /* Write the data */ + _spi->transfer((void *)cmd, 5); + } else { + result = -2; + } + } else { + result = -1; + } + + digitalWrite(_cs_pin, HIGH); + + _spi->endTransaction(); + } else if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP) { + uint32_t tickstart_data_available = millis(); + result = 0; + + detachInterrupt(_spi_irq); + + _spi->beginTransaction(_spiSettings); + + digitalWrite(_cs_pin, LOW); + + while (!(digitalRead(_spi_irq) == 1)) { + if ((millis() - tickstart_data_available) > 1000) { + result = -3; + break; + } + } + + if (result == -3) { + digitalWrite(_cs_pin, HIGH); + _spi->endTransaction(); + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + break; + } + + /* Write the header */ + _spi->transfer(header_master, 5); + + if ((int)((((uint16_t)header_master[2]) << 8) | ((uint16_t)header_master[1])) >= 5) { + /* Write the data */ + _spi->transfer((void *)cmd, 5); + } else { + result = -2; + } + + digitalWrite(_cs_pin, HIGH); + + _spi->endTransaction(); + + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + } } while (result < 0); } diff --git a/src/utility/HCISpiTransport.h b/src/utility/HCISpiTransport.h index 4da3befb..9c3afc34 100644 --- a/src/utility/HCISpiTransport.h +++ b/src/utility/HCISpiTransport.h @@ -55,6 +55,12 @@ class HCISpiTransportClass : public HCITransportInterface { void wait_for_blue_initialize(); void wait_for_enable_ll_only(); void enable_ll_only(); + void wait_for_aci_gatt_init(); + void aci_gatt_init(); + void wait_for_aci_gap_init(); + void aci_gap_init(); + void wait_for_aci_read_config_parameter(); + void aci_read_config_parameter(); SPIClass *_spi; SPISettings _spiSettings; BLEChip_t _ble_chip; @@ -66,6 +72,7 @@ class HCISpiTransportClass : public HCITransportInterface { uint16_t _write_index; uint16_t _write_index_initial; uint8_t _initial_phase; + uint8_t _random_addr[6]; }; #endif /* _HCI_SPI_TRANSPORT_H_ */ From 9ec4d798943885f5bbd8e068456c67f03a2ad673 Mon Sep 17 00:00:00 2001 From: Carlo Parata <carlo.parata@st.com> Date: Mon, 8 Feb 2021 16:25:43 +0100 Subject: [PATCH 048/226] Fix code spelling issues --- src/utility/HCISpiTransport.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utility/HCISpiTransport.cpp b/src/utility/HCISpiTransport.cpp index cb2430c2..a503b427 100644 --- a/src/utility/HCISpiTransport.cpp +++ b/src/utility/HCISpiTransport.cpp @@ -237,12 +237,12 @@ int HCISpiTransportClass::available() delay(300); } - /* Call ACI Gatt Init and ACI Gap Init to activate the random BLE address */ + /* Call Gatt Init and Gap Init to activate the random BLE address */ aci_gatt_init(); wait_for_aci_gatt_init(); aci_gap_init(); wait_for_aci_gap_init(); - /* Call ACI Read Config Parameter to retrieve the random BLE address */ + /* Call Read Config Parameter to retrieve the random BLE address */ aci_read_config_parameter(); wait_for_aci_read_config_parameter(); From d1535a02b79afc3d1b9443e2f91a5b7dda1dc738 Mon Sep 17 00:00:00 2001 From: Carlo Parata <carlo.parata@st.com> Date: Mon, 8 Feb 2021 16:42:53 +0100 Subject: [PATCH 049/226] Fix typo --- src/utility/HCISharedMemTransport.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utility/HCISharedMemTransport.cpp b/src/utility/HCISharedMemTransport.cpp index 17526274..50d7e83c 100644 --- a/src/utility/HCISharedMemTransport.cpp +++ b/src/utility/HCISharedMemTransport.cpp @@ -898,7 +898,7 @@ int HCISharedMemTransportClass::bt_ipm_gap_init(void) * Role byte, enable_privacy byte, device_name_char_len byte */ uint8_t data[4 + 3]; - phase_tx_power = false; + phase_gap_init = false; data[0] = BT_BUF_CMD; /* the type */ data[1] = 0x8A; /* the OPCODE */ From c1c7d1acbbc3a98cf668f3775f0ddfb1c9f06056 Mon Sep 17 00:00:00 2001 From: Carlo Parata <carlo.parata@st.com> Date: Tue, 9 Feb 2021 15:35:13 +0100 Subject: [PATCH 050/226] Add the possibility to choose the ownAddressType in the Arduino stack --- src/local/BLELocalDevice.cpp | 8 ++++++-- src/local/BLELocalDevice.h | 8 +++++++- src/utility/ATT.cpp | 7 ++++++- src/utility/ATT.h | 4 ++++ src/utility/GAP.cpp | 11 ++++++++--- src/utility/GAP.h | 3 +++ 6 files changed, 34 insertions(+), 7 deletions(-) diff --git a/src/local/BLELocalDevice.cpp b/src/local/BLELocalDevice.cpp index 78918760..21de8efc 100644 --- a/src/local/BLELocalDevice.cpp +++ b/src/local/BLELocalDevice.cpp @@ -23,8 +23,8 @@ #include "utility/L2CAPSignaling.h" #include "BLELocalDevice.h" -BLELocalDevice::BLELocalDevice(HCITransportInterface *HCITransport) : - _HCITransport(HCITransport) +BLELocalDevice::BLELocalDevice(HCITransportInterface *HCITransport, uint8_t ownBdaddrType) : + _HCITransport(HCITransport), _ownBdaddrType(ownBdaddrType) { _advertisingData.setFlags(BLEFlagsGeneralDiscoverable | BLEFlagsBREDRNotSupported); } @@ -76,6 +76,10 @@ int BLELocalDevice::begin() GATT.begin(); + GAP.setOwnBdaddrType(_ownBdaddrType); + + ATT.setOwnBdaddrType(_ownBdaddrType); + return 1; } diff --git a/src/local/BLELocalDevice.h b/src/local/BLELocalDevice.h index bcf3c416..beddb0ee 100644 --- a/src/local/BLELocalDevice.h +++ b/src/local/BLELocalDevice.h @@ -25,9 +25,14 @@ #include "BLEService.h" #include "BLEAdvertisingData.h" +#define PUBLIC_ADDR (0) +#define STATIC_RANDOM_ADDR (1) +#define RESOLVABLE_PRIVATE_ADDR (2) +#define NON_RESOLVABLE_PRIVATE_ADDR (3) + class BLELocalDevice { public: - BLELocalDevice(HCITransportInterface *HCITransport); + BLELocalDevice(HCITransportInterface *HCITransport, uint8_t ownBdaddrType = STATIC_RANDOM_ADDR); virtual ~BLELocalDevice(); virtual int begin(); @@ -90,6 +95,7 @@ class BLELocalDevice { HCITransportInterface *_HCITransport; BLEAdvertisingData _advertisingData; BLEAdvertisingData _scanResponseData; + uint8_t _ownBdaddrType; }; extern BLELocalDevice& BLE; diff --git a/src/utility/ATT.cpp b/src/utility/ATT.cpp index 6ec2f27e..6c502068 100644 --- a/src/utility/ATT.cpp +++ b/src/utility/ATT.cpp @@ -109,7 +109,7 @@ ATTClass::~ATTClass() bool ATTClass::connect(uint8_t peerBdaddrType, uint8_t peerBdaddr[6]) { - if (HCI.leCreateConn(0x0060, 0x0030, 0x00, peerBdaddrType, peerBdaddr, 0x00, + if (HCI.leCreateConn(0x0060, 0x0030, 0x00, peerBdaddrType, peerBdaddr, _ownBdaddrType, 0x0006, 0x000c, 0x0000, 0x00c8, 0x0004, 0x0006) != 0) { return false; } @@ -1688,6 +1688,11 @@ void ATTClass::writeCmd(uint16_t connectionHandle, uint16_t handle, const uint8_ sendReq(connectionHandle, &writeReq, 3 + dataLen, NULL); } +void ATTClass::setOwnBdaddrType(uint8_t ownBdaddrType) +{ + _ownBdaddrType = ownBdaddrType; +} + #if !defined(FAKE_ATT) ATTClass ATTObj; ATTClass& ATT = ATTObj; diff --git a/src/utility/ATT.h b/src/utility/ATT.h index d7f54d9d..eba4a76b 100644 --- a/src/utility/ATT.h +++ b/src/utility/ATT.h @@ -77,6 +77,8 @@ class ATTClass { virtual int writeReq(uint16_t connectionHandle, uint16_t handle, const uint8_t* data, uint8_t dataLen, uint8_t responseBuffer[]); virtual void writeCmd(uint16_t connectionHandle, uint16_t handle, const uint8_t* data, uint8_t dataLen); + void setOwnBdaddrType(uint8_t ownBdaddrType); + private: virtual void error(uint16_t connectionHandle, uint8_t dlen, uint8_t data[]); virtual void mtuReq(uint16_t connectionHandle, uint8_t dlen, uint8_t data[]); @@ -135,6 +137,8 @@ class ATTClass { } _pendingResp; BLEDeviceEventHandler _eventHandlers[2]; + + uint8_t _ownBdaddrType; }; extern ATTClass& ATT; diff --git a/src/utility/GAP.cpp b/src/utility/GAP.cpp index 1a3858b2..9bdb10b1 100644 --- a/src/utility/GAP.cpp +++ b/src/utility/GAP.cpp @@ -54,7 +54,7 @@ int GAPClass::advertise(uint8_t* advData, uint8_t advDataLen, uint8_t* scanData, stopAdvertise(); - if (HCI.leSetAdvertisingParameters(_advertisingInterval, _advertisingInterval, type, 0x00, 0x00, directBdaddr, 0x07, 0) != 0) { + if (HCI.leSetAdvertisingParameters(_advertisingInterval, _advertisingInterval, type, _ownBdaddrType, 0x00, directBdaddr, 0x07, 0) != 0) { return 0; } @@ -91,8 +91,8 @@ int GAPClass::scan(bool withDuplicates) } } - // active scan, 10 ms scan interval (N * 0.625), 10 ms scan window (N * 0.625), public own address type, no filter - if (HCI.leSetScanParameters(0x01, 0x0010, 0x0010, 0x00, 0x00) != 0) { + // active scan, 10 ms scan interval (N * 0.625), 10 ms scan window (N * 0.625), public or static random own address type, no filter + if (HCI.leSetScanParameters(0x01, 0x0010, 0x0010, _ownBdaddrType, 0x00) != 0) { return false; } @@ -270,6 +270,11 @@ bool GAPClass::matchesScanFilter(const BLEDevice& device) return true; } +void GAPClass::setOwnBdaddrType(uint8_t ownBdaddrType) +{ + _ownBdaddrType = ownBdaddrType; +} + #if !defined(FAKE_GAP) GAPClass GAPObj; GAPClass& GAP = GAPObj; diff --git a/src/utility/GAP.h b/src/utility/GAP.h index f1c34b4f..c79a2aa7 100644 --- a/src/utility/GAP.h +++ b/src/utility/GAP.h @@ -45,6 +45,8 @@ class GAPClass { virtual void setEventHandler(BLEDeviceEvent event, BLEDeviceEventHandler eventHandler); + void setOwnBdaddrType(uint8_t ownBdaddrType); + protected: friend class HCIClass; @@ -67,6 +69,7 @@ class GAPClass { String _scanNameFilter; String _scanUuidFilter; String _scanAddressFilter; + uint8_t _ownBdaddrType; }; extern GAPClass& GAP; From ec6547b50aab2c353c1992e6acaa70bfa9763f27 Mon Sep 17 00:00:00 2001 From: Carlo Parata <carlo.parata@st.com> Date: Tue, 9 Feb 2021 16:34:29 +0100 Subject: [PATCH 051/226] Fix button issue on WB55 --- examples/Central/LedControl/LedControl.ino | 2 +- examples/Peripheral/ButtonLED/ButtonLED.ino | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/Central/LedControl/LedControl.ino b/examples/Central/LedControl/LedControl.ino index 225ba38b..c3ca2082 100644 --- a/examples/Central/LedControl/LedControl.ino +++ b/examples/Central/LedControl/LedControl.ino @@ -102,7 +102,7 @@ void setup() { while (!Serial); // configure the button pin as input - pinMode(buttonPin, INPUT); + pinMode(buttonPin, INPUT_PULLUP); // initialize the BLE hardware BLE.begin(); diff --git a/examples/Peripheral/ButtonLED/ButtonLED.ino b/examples/Peripheral/ButtonLED/ButtonLED.ino index 27f74649..4567aaa8 100644 --- a/examples/Peripheral/ButtonLED/ButtonLED.ino +++ b/examples/Peripheral/ButtonLED/ButtonLED.ino @@ -108,7 +108,7 @@ void setup() { while (!Serial); pinMode(ledPin, OUTPUT); // use the LED as an output - pinMode(buttonPin, INPUT); // use button pin as an input + pinMode(buttonPin, INPUT_PULLUP); // use button pin as an input // begin initialization if (!BLE.begin()) { From 15e87896745c8618ca5bcbc3ab3f1691b97f2f83 Mon Sep 17 00:00:00 2001 From: Francois Ramu <francois.ramu@st.com> Date: Thu, 11 Feb 2021 10:16:50 +0100 Subject: [PATCH 052/226] mbox_write returns the nb of bytes actually written Check the value which is returned by the mbox_write function, if it differs from the len of data to be sent, this is an error Signed-off-by: Francois Ramu <francois.ramu@st.com> --- src/utility/HCISharedMemTransport.cpp | 40 ++++++++++++++++++++------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/src/utility/HCISharedMemTransport.cpp b/src/utility/HCISharedMemTransport.cpp index 50d7e83c..ee2a41a6 100644 --- a/src/utility/HCISharedMemTransport.cpp +++ b/src/utility/HCISharedMemTransport.cpp @@ -324,7 +324,7 @@ void evt_received(TL_EvtPacket_t *hcievt) } } -/* to send BLE packet to the SharedMem */ +/* to send BLE packet to the SharedMem : return nb of bytes actually written */ uint16_t mbox_write(uint8_t type, uint16_t len, const uint8_t *pData) { TL_CmdPacket_t *bleCmdBuf = &BleCmdBuffer; @@ -598,8 +598,10 @@ size_t HCISharedMemTransportClass::write(const uint8_t *data, size_t length) if ((data[1] == 0x03) && (data[2] == 0x0C)) { phase_reset = false; - mbox_write(data[0], (length - 1), msg_data); - + if (mbox_write(data[0], (length - 1), msg_data) != (length - 1)) { + /* Error: no data are written */ + return 0; + } /* capture event after HCI_RESET */ while (!phase_reset); @@ -645,7 +647,7 @@ size_t HCISharedMemTransportClass::write(const uint8_t *data, size_t length) return (length - 1); /* mbox_size of the HCI reset command */ } - return 0; /* mbox_size of the HCI reset command */ + return 0; /* Error: no data written */ } //private: @@ -810,7 +812,10 @@ int HCISharedMemTransportClass::bt_ipm_set_addr(void) data[5] = 6; /* is the length of the bd_addr table */ memcpy(data + 6, bd_addr_udn, 6); /* send the ACI_HAL_WRITE_CONFIG_DATA */ - mbox_write(data[0], 11, &data[1]); + if (mbox_write(data[0], 11, &data[1]) != 11) { + /* Error: no data are written */ + return 0; + } /* now wait for the corresponding Rx event */ return 1; /* success */ } @@ -847,7 +852,10 @@ int HCISharedMemTransportClass::bt_ipm_set_random_addr(void) data[5] = 6; /* is the length of the random address */ memcpy(data + 6, srd_bd_addr, 6); /* send the ACI_HAL_WRITE_CONFIG_DATA */ - mbox_write(data[0], 11, &data[1]); + if (mbox_write(data[0], 11, &data[1]) != 11) { + /* Error: no data are written */ + return 0; + } /* now wait for the corresponding Rx event */ return 1; /* success */ } @@ -869,7 +877,10 @@ int HCISharedMemTransportClass::bt_ipm_set_power(void) data[5] = CFG_TX_POWER; /* PA_level */ /* send the SET_POWER */ - mbox_write(data[0], 5, &data[1]); + if (mbox_write(data[0], 5, &data[1]) != 5) { + /* Error: no data are written */ + return 0; + } /* now wait for the corresponding Rx event */ return 1; /* success */ } @@ -887,7 +898,10 @@ int HCISharedMemTransportClass::bt_ipm_gatt_init(void) data[3] = 0; /* the length */ /* send the GATT_INIT */ - mbox_write(data[0], 3, &data[1]); + if (mbox_write(data[0], 3, &data[1]) != 3) { + /* Error: no data are written */ + return 0; + } /* now wait for the corresponding Rx event */ return 1; /* success */ } @@ -910,7 +924,10 @@ int HCISharedMemTransportClass::bt_ipm_gap_init(void) data[6] = 0x00; /* device_name_char_len */ /* send the GAP_INIT */ - mbox_write(data[0], 6, &data[1]); + if (mbox_write(data[0], 6, &data[1]) != 6) { + /* Error: no data are written */ + return 0; + } /* now wait for the corresponding Rx event */ return 1; /* success */ } @@ -934,7 +951,10 @@ int HCISharedMemTransportClass::bt_ipm_get_random_addr(void) data[4] = 0x2E; /* the offset */ /* send the ACI_READ_CONFIG_DATA_OPCODE */ - mbox_write(data[0], 4, &data[1]); + if (mbox_write(data[0], 4, &data[1]) != 4) { + /* Error: no data are written */ + return 0; + } /* now wait for the corresponding Rx event */ return 1; /* success */ } From becff9ed3a00a08965cbd4334ec915896a333b1a Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Thu, 14 Jan 2021 14:24:16 +0100 Subject: [PATCH 053/226] Use B_L475E_IOT01A official name Since STM32 core version 2.0.0, the board name has been updated from DISCO_L475VG_IOT to B_L475E_IOT01A. Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- .github/workflows/compile-examples.yml | 2 +- examples/Central/LedControl/LedControl.ino | 2 +- examples/Central/PeripheralExplorer/PeripheralExplorer.ino | 2 +- examples/Central/Scan/Scan.ino | 2 +- examples/Central/ScanCallback/ScanCallback.ino | 2 +- examples/Central/SensorTagButton/SensorTagButton.ino | 2 +- examples/Peripheral/ButtonLED/ButtonLED.ino | 2 +- examples/Peripheral/CallbackLED/CallbackLED.ino | 2 +- examples/Peripheral/LED/LED.ino | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index baeeeec6..a20e43ca 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -9,7 +9,7 @@ jobs: fqbn: [ '"STM32:stm32:Eval:pnum=STEVAL_MKSBOX1V1,usb=CDCgen" "https://github.com/stm32duino/BoardManagerFiles/raw/master/STM32/package_stm_index.json"', '"STM32:stm32:Nucleo_64:pnum=NUCLEO_L476RG" "https://github.com/stm32duino/BoardManagerFiles/raw/master/STM32/package_stm_index.json"', - '"STM32:stm32:Disco:pnum=DISCO_L475VG_IOT" "https://github.com/stm32duino/BoardManagerFiles/raw/master/STM32/package_stm_index.json"' + '"STM32:stm32:Disco:pnum=B_L475E_IOT01A" "https://github.com/stm32duino/BoardManagerFiles/raw/master/STM32/package_stm_index.json"' ] steps: diff --git a/examples/Central/LedControl/LedControl.ino b/examples/Central/LedControl/LedControl.ino index c3ca2082..7e6a1d23 100644 --- a/examples/Central/LedControl/LedControl.ino +++ b/examples/Central/LedControl/LedControl.ino @@ -25,7 +25,7 @@ BLELocalDevice BLEObj(&HCISpiTransport); BLELocalDevice& BLE = BLEObj; #endif const int buttonPin = PG1; // set buttonPin to digital pin PG1 -#elif defined(ARDUINO_DISCO_L475VG_IOT) || defined(ARDUINO_B_L4S5I_IOT01A) +#elif defined(ARDUINO_B_L475E_IOT01A) || defined(ARDUINO_B_L4S5I_IOT01A) /* B-L475E-IOT01A1 or B_L4S5I_IOT01A */ SPIClass SpiHCI(PC12, PC11, PC10); HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, PD13, PE6, PA8, 8000000, SPI_MODE0); diff --git a/examples/Central/PeripheralExplorer/PeripheralExplorer.ino b/examples/Central/PeripheralExplorer/PeripheralExplorer.ino index 03529672..0590a32b 100644 --- a/examples/Central/PeripheralExplorer/PeripheralExplorer.ino +++ b/examples/Central/PeripheralExplorer/PeripheralExplorer.ino @@ -23,7 +23,7 @@ HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_1S, PD0, PD4, PA8, 1000000, BLELocalDevice BLEObj(&HCISpiTransport); BLELocalDevice& BLE = BLEObj; #endif -#elif defined(ARDUINO_DISCO_L475VG_IOT) || defined(ARDUINO_B_L4S5I_IOT01A) +#elif defined(ARDUINO_B_L475E_IOT01A) || defined(ARDUINO_B_L4S5I_IOT01A) /* B-L475E-IOT01A1 or B_L4S5I_IOT01A */ SPIClass SpiHCI(PC12, PC11, PC10); HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, PD13, PE6, PA8, 8000000, SPI_MODE0); diff --git a/examples/Central/Scan/Scan.ino b/examples/Central/Scan/Scan.ino index 71942fae..8c897b3b 100644 --- a/examples/Central/Scan/Scan.ino +++ b/examples/Central/Scan/Scan.ino @@ -20,7 +20,7 @@ HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_1S, PD0, PD4, PA8, 1000000, BLELocalDevice BLEObj(&HCISpiTransport); BLELocalDevice& BLE = BLEObj; #endif -#elif defined(ARDUINO_DISCO_L475VG_IOT) || defined(ARDUINO_B_L4S5I_IOT01A) +#elif defined(ARDUINO_B_L475E_IOT01A) || defined(ARDUINO_B_L4S5I_IOT01A) /* B-L475E-IOT01A1 or B_L4S5I_IOT01A */ SPIClass SpiHCI(PC12, PC11, PC10); HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, PD13, PE6, PA8, 8000000, SPI_MODE0); diff --git a/examples/Central/ScanCallback/ScanCallback.ino b/examples/Central/ScanCallback/ScanCallback.ino index 84c133ca..a25a765d 100644 --- a/examples/Central/ScanCallback/ScanCallback.ino +++ b/examples/Central/ScanCallback/ScanCallback.ino @@ -22,7 +22,7 @@ HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_1S, PD0, PD4, PA8, 1000000, BLELocalDevice BLEObj(&HCISpiTransport); BLELocalDevice& BLE = BLEObj; #endif -#elif defined(ARDUINO_DISCO_L475VG_IOT) || defined(ARDUINO_B_L4S5I_IOT01A) +#elif defined(ARDUINO_B_L475E_IOT01A) || defined(ARDUINO_B_L4S5I_IOT01A) /* B-L475E-IOT01A1 or B_L4S5I_IOT01A */ SPIClass SpiHCI(PC12, PC11, PC10); HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, PD13, PE6, PA8, 8000000, SPI_MODE0); diff --git a/examples/Central/SensorTagButton/SensorTagButton.ino b/examples/Central/SensorTagButton/SensorTagButton.ino index be7016e4..2e3b9a81 100644 --- a/examples/Central/SensorTagButton/SensorTagButton.ino +++ b/examples/Central/SensorTagButton/SensorTagButton.ino @@ -24,7 +24,7 @@ HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_1S, PD0, PD4, PA8, 1000000, BLELocalDevice BLEObj(&HCISpiTransport); BLELocalDevice& BLE = BLEObj; #endif -#elif defined(ARDUINO_DISCO_L475VG_IOT) || defined(ARDUINO_B_L4S5I_IOT01A) +#elif defined(ARDUINO_B_L475E_IOT01A) || defined(ARDUINO_B_L4S5I_IOT01A) /* B-L475E-IOT01A1 or B_L4S5I_IOT01A */ SPIClass SpiHCI(PC12, PC11, PC10); HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, PD13, PE6, PA8, 8000000, SPI_MODE0); diff --git a/examples/Peripheral/ButtonLED/ButtonLED.ino b/examples/Peripheral/ButtonLED/ButtonLED.ino index 4567aaa8..f39693f7 100644 --- a/examples/Peripheral/ButtonLED/ButtonLED.ino +++ b/examples/Peripheral/ButtonLED/ButtonLED.ino @@ -26,7 +26,7 @@ BLELocalDevice BLEObj(&HCISpiTransport); BLELocalDevice& BLE = BLEObj; #endif const int buttonPin = PG1; // set buttonPin to digital pin PG1 -#elif defined(ARDUINO_DISCO_L475VG_IOT) || defined(ARDUINO_B_L4S5I_IOT01A) +#elif defined(ARDUINO_B_L475E_IOT01A) || defined(ARDUINO_B_L4S5I_IOT01A) /* B-L475E-IOT01A1 or B_L4S5I_IOT01A */ SPIClass SpiHCI(PC12, PC11, PC10); HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, PD13, PE6, PA8, 8000000, SPI_MODE0); diff --git a/examples/Peripheral/CallbackLED/CallbackLED.ino b/examples/Peripheral/CallbackLED/CallbackLED.ino index fdbda111..822ba867 100644 --- a/examples/Peripheral/CallbackLED/CallbackLED.ino +++ b/examples/Peripheral/CallbackLED/CallbackLED.ino @@ -25,7 +25,7 @@ HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_1S, PD0, PD4, PA8, 1000000, BLELocalDevice BLEObj(&HCISpiTransport); BLELocalDevice& BLE = BLEObj; #endif -#elif defined(ARDUINO_DISCO_L475VG_IOT) || defined(ARDUINO_B_L4S5I_IOT01A) +#elif defined(ARDUINO_B_L475E_IOT01A) || defined(ARDUINO_B_L4S5I_IOT01A) /* B-L475E-IOT01A1 or B_L4S5I_IOT01A */ SPIClass SpiHCI(PC12, PC11, PC10); HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, PD13, PE6, PA8, 8000000, SPI_MODE0); diff --git a/examples/Peripheral/LED/LED.ino b/examples/Peripheral/LED/LED.ino index 26afe71d..a9e16cef 100644 --- a/examples/Peripheral/LED/LED.ino +++ b/examples/Peripheral/LED/LED.ino @@ -23,7 +23,7 @@ HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_1S, PD0, PD4, PA8, 1000000, BLELocalDevice BLEObj(&HCISpiTransport); BLELocalDevice& BLE = BLEObj; #endif -#elif defined(ARDUINO_DISCO_L475VG_IOT) || defined(ARDUINO_B_L4S5I_IOT01A) +#elif defined(ARDUINO_B_L475E_IOT01A) || defined(ARDUINO_B_L4S5I_IOT01A) /* B-L475E-IOT01A1 or B_L4S5I_IOT01A */ SPIClass SpiHCI(PC12, PC11, PC10); HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, PD13, PE6, PA8, 8000000, SPI_MODE0); From fc7c4c65d1901b1532ee7727004125766c184edd Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Tue, 30 Mar 2021 16:47:42 +0200 Subject: [PATCH 054/226] Fix P_NUCLEO_WB55RG official name Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- examples/Central/LedControl/LedControl.ino | 2 +- examples/Central/PeripheralExplorer/PeripheralExplorer.ino | 2 +- examples/Central/Scan/Scan.ino | 2 +- examples/Central/ScanCallback/ScanCallback.ino | 2 +- examples/Central/SensorTagButton/SensorTagButton.ino | 2 +- examples/Peripheral/ButtonLED/ButtonLED.ino | 2 +- examples/Peripheral/CallbackLED/CallbackLED.ino | 2 +- examples/Peripheral/LED/LED.ino | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/examples/Central/LedControl/LedControl.ino b/examples/Central/LedControl/LedControl.ino index 7e6a1d23..c1fc972c 100644 --- a/examples/Central/LedControl/LedControl.ino +++ b/examples/Central/LedControl/LedControl.ino @@ -34,7 +34,7 @@ BLELocalDevice BLEObj(&HCISpiTransport); BLELocalDevice& BLE = BLEObj; #endif const int buttonPin = PC13; // set buttonPin to digital pin PC13 -#elif defined(ARDUINO_PNUCLEO_WB55RG) +#elif defined(ARDUINO_P_NUCLEO_WB55RG) /* PNUCLEO_WB55RG */ HCISharedMemTransportClass HCISharedMemTransport; #if !defined(FAKE_BLELOCALDEVICE) diff --git a/examples/Central/PeripheralExplorer/PeripheralExplorer.ino b/examples/Central/PeripheralExplorer/PeripheralExplorer.ino index 0590a32b..5bf1b2af 100644 --- a/examples/Central/PeripheralExplorer/PeripheralExplorer.ino +++ b/examples/Central/PeripheralExplorer/PeripheralExplorer.ino @@ -31,7 +31,7 @@ HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, PD13, PE6, PA8, 8000000, BLELocalDevice BLEObj(&HCISpiTransport); BLELocalDevice& BLE = BLEObj; #endif -#elif defined(ARDUINO_PNUCLEO_WB55RG) +#elif defined(ARDUINO_P_NUCLEO_WB55RG) /* PNUCLEO_WB55RG */ HCISharedMemTransportClass HCISharedMemTransport; #if !defined(FAKE_BLELOCALDEVICE) diff --git a/examples/Central/Scan/Scan.ino b/examples/Central/Scan/Scan.ino index 8c897b3b..eadadd46 100644 --- a/examples/Central/Scan/Scan.ino +++ b/examples/Central/Scan/Scan.ino @@ -28,7 +28,7 @@ HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, PD13, PE6, PA8, 8000000, BLELocalDevice BLEObj(&HCISpiTransport); BLELocalDevice& BLE = BLEObj; #endif -#elif defined(ARDUINO_PNUCLEO_WB55RG) +#elif defined(ARDUINO_P_NUCLEO_WB55RG) /* PNUCLEO_WB55RG */ HCISharedMemTransportClass HCISharedMemTransport; #if !defined(FAKE_BLELOCALDEVICE) diff --git a/examples/Central/ScanCallback/ScanCallback.ino b/examples/Central/ScanCallback/ScanCallback.ino index a25a765d..c821a7fd 100644 --- a/examples/Central/ScanCallback/ScanCallback.ino +++ b/examples/Central/ScanCallback/ScanCallback.ino @@ -30,7 +30,7 @@ HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, PD13, PE6, PA8, 8000000, BLELocalDevice BLEObj(&HCISpiTransport); BLELocalDevice& BLE = BLEObj; #endif -#elif defined(ARDUINO_PNUCLEO_WB55RG) +#elif defined(ARDUINO_P_NUCLEO_WB55RG) /* PNUCLEO_WB55RG */ HCISharedMemTransportClass HCISharedMemTransport; #if !defined(FAKE_BLELOCALDEVICE) diff --git a/examples/Central/SensorTagButton/SensorTagButton.ino b/examples/Central/SensorTagButton/SensorTagButton.ino index 2e3b9a81..714036df 100644 --- a/examples/Central/SensorTagButton/SensorTagButton.ino +++ b/examples/Central/SensorTagButton/SensorTagButton.ino @@ -32,7 +32,7 @@ HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, PD13, PE6, PA8, 8000000, BLELocalDevice BLEObj(&HCISpiTransport); BLELocalDevice& BLE = BLEObj; #endif -#elif defined(ARDUINO_PNUCLEO_WB55RG) +#elif defined(ARDUINO_P_NUCLEO_WB55RG) /* PNUCLEO_WB55RG */ HCISharedMemTransportClass HCISharedMemTransport; #if !defined(FAKE_BLELOCALDEVICE) diff --git a/examples/Peripheral/ButtonLED/ButtonLED.ino b/examples/Peripheral/ButtonLED/ButtonLED.ino index f39693f7..b9708986 100644 --- a/examples/Peripheral/ButtonLED/ButtonLED.ino +++ b/examples/Peripheral/ButtonLED/ButtonLED.ino @@ -35,7 +35,7 @@ BLELocalDevice BLEObj(&HCISpiTransport); BLELocalDevice& BLE = BLEObj; #endif const int buttonPin = PC13; // set buttonPin to digital pin PC13 -#elif defined(ARDUINO_PNUCLEO_WB55RG) +#elif defined(ARDUINO_P_NUCLEO_WB55RG) /* PNUCLEO_WB55RG */ HCISharedMemTransportClass HCISharedMemTransport; #if !defined(FAKE_BLELOCALDEVICE) diff --git a/examples/Peripheral/CallbackLED/CallbackLED.ino b/examples/Peripheral/CallbackLED/CallbackLED.ino index 822ba867..beaa8868 100644 --- a/examples/Peripheral/CallbackLED/CallbackLED.ino +++ b/examples/Peripheral/CallbackLED/CallbackLED.ino @@ -33,7 +33,7 @@ HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, PD13, PE6, PA8, 8000000, BLELocalDevice BLEObj(&HCISpiTransport); BLELocalDevice& BLE = BLEObj; #endif -#elif defined(ARDUINO_PNUCLEO_WB55RG) +#elif defined(ARDUINO_P_NUCLEO_WB55RG) /* PNUCLEO_WB55RG */ HCISharedMemTransportClass HCISharedMemTransport; #if !defined(FAKE_BLELOCALDEVICE) diff --git a/examples/Peripheral/LED/LED.ino b/examples/Peripheral/LED/LED.ino index a9e16cef..aa39ebd3 100644 --- a/examples/Peripheral/LED/LED.ino +++ b/examples/Peripheral/LED/LED.ino @@ -31,7 +31,7 @@ HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, PD13, PE6, PA8, 8000000, BLELocalDevice BLEObj(&HCISpiTransport); BLELocalDevice& BLE = BLEObj; #endif -#elif defined(ARDUINO_PNUCLEO_WB55RG) +#elif defined(ARDUINO_P_NUCLEO_WB55RG) /* PNUCLEO_WB55RG */ HCISharedMemTransportClass HCISharedMemTransport; #if !defined(FAKE_BLELOCALDEVICE) From f03924fcb0319e99cd82ad49267d9539fb927e55 Mon Sep 17 00:00:00 2001 From: per1234 <accounts@perglass.com> Date: Sat, 26 Sep 2020 16:13:57 -0700 Subject: [PATCH 055/226] Update version of actions/checkout action used in Compile Examples CI workflow The action now has a default fetch-depth value of 1, so there is no need to specify this input. --- .github/workflows/compile-examples.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index f39d1a6e..a91246d2 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -13,9 +13,7 @@ jobs: ] steps: - - uses: actions/checkout@v1 - with: - fetch-depth: 1 + - uses: actions/checkout@v2 - uses: arduino/actions/libraries/compile-examples@master with: github-token: ${{ secrets.GITHUB_TOKEN }} From 04bcd680bf44d43cb42d4d39ae2ae107175c950f Mon Sep 17 00:00:00 2001 From: per1234 <accounts@perglass.com> Date: Sat, 26 Sep 2020 16:15:51 -0700 Subject: [PATCH 056/226] Update name of action used to compile examples in CI workflow The action has been moved to a dedicated repository, where all future development work will happen. --- .github/workflows/compile-examples.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index a91246d2..e531342d 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -14,7 +14,7 @@ jobs: steps: - uses: actions/checkout@v2 - - uses: arduino/actions/libraries/compile-examples@master + - uses: arduino/compile-sketches@v1 with: github-token: ${{ secrets.GITHUB_TOKEN }} fqbn: ${{ matrix.fqbn }} From 4342fe888041b6e7c6e8d21c3c62e5fc7eba57a5 Mon Sep 17 00:00:00 2001 From: per1234 <accounts@perglass.com> Date: Sat, 26 Sep 2020 16:18:05 -0700 Subject: [PATCH 057/226] Use consistent formatting style in Compile Examples CI action The previous inconsistent markup style, although perfectly valid, made the workflow harder to understand. --- .github/workflows/compile-examples.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index e531342d..52a11582 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -1,5 +1,8 @@ name: Compile Examples -on: [push, pull_request] +on: + - push + - pull_request + jobs: build: runs-on: ubuntu-latest From e3bdb384002e8592a2472972d4ed19299254c92a Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Tue, 4 May 2021 16:06:31 +0200 Subject: [PATCH 058/226] Use consistent indent size in Compile Examples workflow The initial single space indent made the workflow difficult to edit and harmed readability. --- .github/workflows/compile-examples.yml | 30 +++++++++++++------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index 52a11582..ab55f19b 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -4,20 +4,20 @@ on: - pull_request jobs: - build: - runs-on: ubuntu-latest + build: + runs-on: ubuntu-latest - strategy: - matrix: - fqbn: [ - '"STM32:stm32:Eval:pnum=STEVAL_MKSBOX1V1,usb=CDCgen" "https://github.com/stm32duino/BoardManagerFiles/raw/master/STM32/package_stm_index.json"', - '"STM32:stm32:Nucleo_64:pnum=NUCLEO_L476RG" "https://github.com/stm32duino/BoardManagerFiles/raw/master/STM32/package_stm_index.json"', - '"STM32:stm32:Disco:pnum=B_L475E_IOT01A" "https://github.com/stm32duino/BoardManagerFiles/raw/master/STM32/package_stm_index.json"' - ] + strategy: + matrix: + fqbn: [ + '"STM32:stm32:Eval:pnum=STEVAL_MKSBOX1V1,usb=CDCgen" "https://github.com/stm32duino/BoardManagerFiles/raw/master/STM32/package_stm_index.json"', + '"STM32:stm32:Nucleo_64:pnum=NUCLEO_L476RG" "https://github.com/stm32duino/BoardManagerFiles/raw/master/STM32/package_stm_index.json"', + '"STM32:stm32:Disco:pnum=B_L475E_IOT01A" "https://github.com/stm32duino/BoardManagerFiles/raw/master/STM32/package_stm_index.json"' + ] - steps: - - uses: actions/checkout@v2 - - uses: arduino/compile-sketches@v1 - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - fqbn: ${{ matrix.fqbn }} + steps: + - uses: actions/checkout@v2 + - uses: arduino/compile-sketches@v1 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + fqbn: ${{ matrix.fqbn }} From 4031a6a84f260e3a7a395439453fda951d12305a Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Tue, 4 May 2021 17:20:49 +0200 Subject: [PATCH 059/226] fix: ci: update with new maintainer name Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- .github/workflows/compile-examples.yml | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index ab55f19b..4efa2d9d 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -9,11 +9,11 @@ jobs: strategy: matrix: - fqbn: [ - '"STM32:stm32:Eval:pnum=STEVAL_MKSBOX1V1,usb=CDCgen" "https://github.com/stm32duino/BoardManagerFiles/raw/master/STM32/package_stm_index.json"', - '"STM32:stm32:Nucleo_64:pnum=NUCLEO_L476RG" "https://github.com/stm32duino/BoardManagerFiles/raw/master/STM32/package_stm_index.json"', - '"STM32:stm32:Disco:pnum=B_L475E_IOT01A" "https://github.com/stm32duino/BoardManagerFiles/raw/master/STM32/package_stm_index.json"' - ] + fqbn: + - STMicroelectronics:stm32:Eval:pnum=STEVAL_MKSBOX1V1,usb=CDCgen + - STMicroelectronics:stm32:Nucleo_64:pnum=NUCLEO_L476RG + - STMicroelectronics:stm32:Disco:pnum=B_L475E_IOT01A + - STMicroelectronics:stm32:Nucleo_64:pnum=P_NUCLEO_WB55RG steps: - uses: actions/checkout@v2 @@ -21,3 +21,6 @@ jobs: with: github-token: ${{ secrets.GITHUB_TOKEN }} fqbn: ${{ matrix.fqbn }} + platforms: | + - source-url: https://github.com/stm32duino/BoardManagerFiles/raw/master/package_stmicroelectronics_index.json + name: STMicroelectronics:stm32 From 23053fbc16d9dd69e5fc9902d764530cfac3cb66 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Wed, 5 May 2021 15:17:35 +0200 Subject: [PATCH 060/226] Update library.properties --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index f50f1b3c..58ac0226 100644 --- a/library.properties +++ b/library.properties @@ -2,7 +2,7 @@ name=STM32duinoBLE version=1.2.0 author=Arduino, SRA maintainer=stm32duino -sentence=Fork of ArduinoBLE library to add the support of SPBTLE-RF, SPBTLE-1S, BLUENRG-M2SP and BLUENRG-M0 BLE modules. +sentence=Fork of ArduinoBLE library to add the support of STM32WB, 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 From ac6431e9e3c83f137defe794dc2bcdfe51ef83ad Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Thu, 8 Jul 2021 14:31:58 +0200 Subject: [PATCH 061/226] fix: remove specific include Correct CMSIS devide header already included by the core. Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- src/utility/HCISharedMemTransport.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/utility/HCISharedMemTransport.h b/src/utility/HCISharedMemTransport.h index e4bd6ed6..464a24f6 100644 --- a/src/utility/HCISharedMemTransport.h +++ b/src/utility/HCISharedMemTransport.h @@ -23,7 +23,6 @@ #include "HCITransport.h" /* STM32WB include files */ -#include "stm32wb55xx.h" #include "stm32wbxx_ll_rcc.h" #include "stm32wbxx_ll_ipcc.h" #include "stm32wbxx_ll_system.h" From faffc11b61b3b56e91914c0f9accba11c7fcac97 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Thu, 8 Jul 2021 14:33:34 +0200 Subject: [PATCH 062/226] examples: add STM32WB5MM-DK support Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- examples/Central/LedControl/LedControl.ino | 3 +-- examples/Central/PeripheralExplorer/PeripheralExplorer.ino | 3 +-- examples/Central/Scan/Scan.ino | 3 +-- examples/Central/ScanCallback/ScanCallback.ino | 3 +-- examples/Central/SensorTagButton/SensorTagButton.ino | 3 +-- examples/Peripheral/ButtonLED/ButtonLED.ino | 3 +-- examples/Peripheral/CallbackLED/CallbackLED.ino | 3 +-- examples/Peripheral/LED/LED.ino | 3 +-- 8 files changed, 8 insertions(+), 16 deletions(-) diff --git a/examples/Central/LedControl/LedControl.ino b/examples/Central/LedControl/LedControl.ino index c1fc972c..2f64bc28 100644 --- a/examples/Central/LedControl/LedControl.ino +++ b/examples/Central/LedControl/LedControl.ino @@ -34,8 +34,7 @@ BLELocalDevice BLEObj(&HCISpiTransport); BLELocalDevice& BLE = BLEObj; #endif const int buttonPin = PC13; // set buttonPin to digital pin PC13 -#elif defined(ARDUINO_P_NUCLEO_WB55RG) -/* PNUCLEO_WB55RG */ +#elif defined(ARDUINO_P_NUCLEO_WB55RG) || defined(ARDUINO_STM32WB5MM_DK) HCISharedMemTransportClass HCISharedMemTransport; #if !defined(FAKE_BLELOCALDEVICE) BLELocalDevice BLEObj(&HCISharedMemTransport); diff --git a/examples/Central/PeripheralExplorer/PeripheralExplorer.ino b/examples/Central/PeripheralExplorer/PeripheralExplorer.ino index 5bf1b2af..e5461fa5 100644 --- a/examples/Central/PeripheralExplorer/PeripheralExplorer.ino +++ b/examples/Central/PeripheralExplorer/PeripheralExplorer.ino @@ -31,8 +31,7 @@ HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, PD13, PE6, PA8, 8000000, BLELocalDevice BLEObj(&HCISpiTransport); BLELocalDevice& BLE = BLEObj; #endif -#elif defined(ARDUINO_P_NUCLEO_WB55RG) -/* PNUCLEO_WB55RG */ +#elif defined(ARDUINO_P_NUCLEO_WB55RG) || defined(ARDUINO_STM32WB5MM_DK) HCISharedMemTransportClass HCISharedMemTransport; #if !defined(FAKE_BLELOCALDEVICE) BLELocalDevice BLEObj(&HCISharedMemTransport); diff --git a/examples/Central/Scan/Scan.ino b/examples/Central/Scan/Scan.ino index eadadd46..bf1bef5f 100644 --- a/examples/Central/Scan/Scan.ino +++ b/examples/Central/Scan/Scan.ino @@ -28,8 +28,7 @@ HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, PD13, PE6, PA8, 8000000, BLELocalDevice BLEObj(&HCISpiTransport); BLELocalDevice& BLE = BLEObj; #endif -#elif defined(ARDUINO_P_NUCLEO_WB55RG) -/* PNUCLEO_WB55RG */ +#elif defined(ARDUINO_P_NUCLEO_WB55RG) || defined(ARDUINO_STM32WB5MM_DK) HCISharedMemTransportClass HCISharedMemTransport; #if !defined(FAKE_BLELOCALDEVICE) BLELocalDevice BLEObj(&HCISharedMemTransport); diff --git a/examples/Central/ScanCallback/ScanCallback.ino b/examples/Central/ScanCallback/ScanCallback.ino index c821a7fd..4d9bbc77 100644 --- a/examples/Central/ScanCallback/ScanCallback.ino +++ b/examples/Central/ScanCallback/ScanCallback.ino @@ -30,8 +30,7 @@ HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, PD13, PE6, PA8, 8000000, BLELocalDevice BLEObj(&HCISpiTransport); BLELocalDevice& BLE = BLEObj; #endif -#elif defined(ARDUINO_P_NUCLEO_WB55RG) -/* PNUCLEO_WB55RG */ +#elif defined(ARDUINO_P_NUCLEO_WB55RG) || defined(ARDUINO_STM32WB5MM_DK) HCISharedMemTransportClass HCISharedMemTransport; #if !defined(FAKE_BLELOCALDEVICE) BLELocalDevice BLEObj(&HCISharedMemTransport); diff --git a/examples/Central/SensorTagButton/SensorTagButton.ino b/examples/Central/SensorTagButton/SensorTagButton.ino index 714036df..c6377f9f 100644 --- a/examples/Central/SensorTagButton/SensorTagButton.ino +++ b/examples/Central/SensorTagButton/SensorTagButton.ino @@ -32,8 +32,7 @@ HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, PD13, PE6, PA8, 8000000, BLELocalDevice BLEObj(&HCISpiTransport); BLELocalDevice& BLE = BLEObj; #endif -#elif defined(ARDUINO_P_NUCLEO_WB55RG) -/* PNUCLEO_WB55RG */ +#elif defined(ARDUINO_P_NUCLEO_WB55RG) || defined(ARDUINO_STM32WB5MM_DK) HCISharedMemTransportClass HCISharedMemTransport; #if !defined(FAKE_BLELOCALDEVICE) BLELocalDevice BLEObj(&HCISharedMemTransport); diff --git a/examples/Peripheral/ButtonLED/ButtonLED.ino b/examples/Peripheral/ButtonLED/ButtonLED.ino index b9708986..c3f777d4 100644 --- a/examples/Peripheral/ButtonLED/ButtonLED.ino +++ b/examples/Peripheral/ButtonLED/ButtonLED.ino @@ -35,8 +35,7 @@ BLELocalDevice BLEObj(&HCISpiTransport); BLELocalDevice& BLE = BLEObj; #endif const int buttonPin = PC13; // set buttonPin to digital pin PC13 -#elif defined(ARDUINO_P_NUCLEO_WB55RG) -/* PNUCLEO_WB55RG */ +#elif defined(ARDUINO_P_NUCLEO_WB55RG) || defined(ARDUINO_STM32WB5MM_DK) HCISharedMemTransportClass HCISharedMemTransport; #if !defined(FAKE_BLELOCALDEVICE) BLELocalDevice BLEObj(&HCISharedMemTransport); diff --git a/examples/Peripheral/CallbackLED/CallbackLED.ino b/examples/Peripheral/CallbackLED/CallbackLED.ino index beaa8868..28bf40a8 100644 --- a/examples/Peripheral/CallbackLED/CallbackLED.ino +++ b/examples/Peripheral/CallbackLED/CallbackLED.ino @@ -33,8 +33,7 @@ HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, PD13, PE6, PA8, 8000000, BLELocalDevice BLEObj(&HCISpiTransport); BLELocalDevice& BLE = BLEObj; #endif -#elif defined(ARDUINO_P_NUCLEO_WB55RG) -/* PNUCLEO_WB55RG */ +#elif defined(ARDUINO_P_NUCLEO_WB55RG) || defined(ARDUINO_STM32WB5MM_DK) HCISharedMemTransportClass HCISharedMemTransport; #if !defined(FAKE_BLELOCALDEVICE) BLELocalDevice BLEObj(&HCISharedMemTransport); diff --git a/examples/Peripheral/LED/LED.ino b/examples/Peripheral/LED/LED.ino index aa39ebd3..2ea0e5ae 100644 --- a/examples/Peripheral/LED/LED.ino +++ b/examples/Peripheral/LED/LED.ino @@ -31,8 +31,7 @@ HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, PD13, PE6, PA8, 8000000, BLELocalDevice BLEObj(&HCISpiTransport); BLELocalDevice& BLE = BLEObj; #endif -#elif defined(ARDUINO_P_NUCLEO_WB55RG) -/* PNUCLEO_WB55RG */ +#elif defined(ARDUINO_P_NUCLEO_WB55RG) || defined(ARDUINO_STM32WB5MM_DK) HCISharedMemTransportClass HCISharedMemTransport; #if !defined(FAKE_BLELOCALDEVICE) BLELocalDevice BLEObj(&HCISharedMemTransport); From 1cf1da0d5fbd1b43626249c430c69c92b8de3be5 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Tue, 5 Oct 2021 16:04:46 +0200 Subject: [PATCH 063/226] ci: change to main branch Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- .github/workflows/compile-examples.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index 4efa2d9d..da41142d 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -22,5 +22,5 @@ jobs: github-token: ${{ secrets.GITHUB_TOKEN }} fqbn: ${{ matrix.fqbn }} platforms: | - - source-url: https://github.com/stm32duino/BoardManagerFiles/raw/master/package_stmicroelectronics_index.json + - source-url: https://github.com/stm32duino/BoardManagerFiles/raw/main/package_stmicroelectronics_index.json name: STMicroelectronics:stm32 From 095fe1802f363865f631133e0f2c01fa3f9325a8 Mon Sep 17 00:00:00 2001 From: KMeldgaard <36625114+KMeldgaard@users.noreply.github.com> Date: Mon, 15 Nov 2021 14:54:07 +0100 Subject: [PATCH 064/226] Added support for custom app_conf.h (#35) --- README.md | 5 + src/utility/STM32Cube_FW/app_conf.h | 162 ++--------------- src/utility/STM32Cube_FW/app_conf_default.h | 185 ++++++++++++++++++++ 3 files changed, 202 insertions(+), 150 deletions(-) create mode 100644 src/utility/STM32Cube_FW/app_conf_default.h diff --git a/README.md b/README.md index 2fb6e425..b2d48b13 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,11 @@ https://github.com/stm32duino/wiki/wiki/STM32duinoBLE#stm32duinoble-with-x-nucle For more information about ArduinoBLE library please visit the official web page at: https://github.com/arduino-libraries/ArduinoBLE +# Configuration +STM32Cube_WPAN has several configuration options, which are set in the `app_conf.h`. +This package has a default configuration named `app_conf_default.h`. +The user can include the file `app_conf_custom.h` to customize the ble application. Options wrapped in `#ifndef, #endif` in `app_conf_default.h` can be overwritten. Additional options can be added. + ## License ``` diff --git a/src/utility/STM32Cube_FW/app_conf.h b/src/utility/STM32Cube_FW/app_conf.h index 667dbbd4..888c91a0 100644 --- a/src/utility/STM32Cube_FW/app_conf.h +++ b/src/utility/STM32Cube_FW/app_conf.h @@ -1,158 +1,20 @@ -/** - ****************************************************************************** - * File Name : app_conf.h - * Description : Application configuration file for STM32WPAN Middleware. - ****************************************************************************** - * @attention - * - * <h2><center>© Copyright (c) 2020 STMicroelectronics. - * All rights reserved.</center></h2> - * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 - * - ****************************************************************************** - */ +//----------------------------- +// @file app_conf.h +// @author Kasper Meldgaard +// @brief Wrapper for BLE app configuration based on comment by fpistm +// (https://github.com/stm32duino/STM32duinoBLE/issues/34). +// @date 15-11-2021 +// @copyright Copyright (c) 2021 -/* Define to prevent recursive inclusion -------------------------------------*/ #ifndef APP_CONF_H #define APP_CONF_H -#include "hw.h" #include "ble_bufsize.h" +#include "hw.h" - -/****************************************************************************** - * Application Config - ******************************************************************************/ - -/**< generic parameters ******************************************************/ -/* HCI related defines */ - -#define ACI_HAL_SET_TX_POWER_LEVEL 0xFC0F -#define ACI_WRITE_CONFIG_DATA_OPCODE 0xFC0C -#define ACI_READ_CONFIG_DATA_OPCODE 0xFC0D -#define MAX_HCI_ACL_PACKET_SIZE (sizeof(TL_PacketHeader_t) + 5 + 251) -#define HCI_RESET 0x0C03 - -#ifndef BLE_SHARED_MEM_BYTE_ORDER - #define BLE_SHARED_MEM_BYTE_ORDER MSBFIRST +#if __has_include("app_conf_custom.h") +#include "app_conf_custom.h" #endif -#define BLE_MODULE_SHARED_MEM_BUFFER_SIZE 128 - -/** - * Define Tx Power - */ -#define CFG_TX_POWER (0x18) /* -0.15dBm */ - -/****************************************************************************** - * BLE Stack - ******************************************************************************/ -/** - * Maximum number of simultaneous connections that the device will support. - * Valid values are from 1 to 8 - */ -#define CFG_BLE_NUM_LINK 8 - -/** - * Maximum number of Services that can be stored in the GATT database. - * Note that the GAP and GATT services are automatically added so this parameter should be 2 plus the number of user services - */ -#define CFG_BLE_NUM_GATT_SERVICES 8 - -/** - * Maximum number of Attributes - * (i.e. the number of characteristic + the number of characteristic values + the number of descriptors, excluding the services) - * that can be stored in the GATT database. - * Note that certain characteristics and relative descriptors are added automatically during device initialization - * so this parameters should be 9 plus the number of user Attributes - */ -#define CFG_BLE_NUM_GATT_ATTRIBUTES 68 - -/** - * Maximum supported ATT_MTU size - */ -#define CFG_BLE_MAX_ATT_MTU (156) - -/** - * Size of the storage area for Attribute values - * This value depends on the number of attributes used by application. In particular the sum of the following quantities (in octets) should be made for each attribute: - * - attribute value length - * - 5, if UUID is 16 bit; 19, if UUID is 128 bit - * - 2, if server configuration descriptor is used - * - 2*DTM_NUM_LINK, if client configuration descriptor is used - * - 2, if extended properties is used - * The total amount of memory needed is the sum of the above quantities for each attribute. - */ -#define CFG_BLE_ATT_VALUE_ARRAY_SIZE (1344) - -/** - * Prepare Write List size in terms of number of packet - */ -//#define CFG_BLE_PREPARE_WRITE_LIST_SIZE BLE_PREP_WRITE_X_ATT(CFG_BLE_MAX_ATT_MTU) -#define CFG_BLE_PREPARE_WRITE_LIST_SIZE (0x3A) - -/** - * Number of allocated memory blocks - */ -//#define CFG_BLE_MBLOCK_COUNT (BLE_MBLOCKS_CALC(CFG_BLE_PREPARE_WRITE_LIST_SIZE, CFG_BLE_MAX_ATT_MTU, CFG_BLE_NUM_LINK)) -#define CFG_BLE_MBLOCK_COUNT (0x79) -/** - * Enable or disable the Extended Packet length feature. Valid values are 0 or 1. - */ -#define CFG_BLE_DATA_LENGTH_EXTENSION 1 - -/** - * Sleep clock accuracy in Slave mode (ppm value) - */ -#define CFG_BLE_SLAVE_SCA 500 - -/** - * Sleep clock accuracy in Master mode - * 0 : 251 ppm to 500 ppm - * 1 : 151 ppm to 250 ppm - * 2 : 101 ppm to 150 ppm - * 3 : 76 ppm to 100 ppm - * 4 : 51 ppm to 75 ppm - * 5 : 31 ppm to 50 ppm - * 6 : 21 ppm to 30 ppm - * 7 : 0 ppm to 20 ppm - */ -#define CFG_BLE_MASTER_SCA 0 - -/** - * Source for the 32 kHz slow speed clock - * 1 : internal RO - * 0 : external crystal ( no calibration ) - */ -#define CFG_BLE_LSE_SOURCE 0 - -/** - * Start up time of the high speed (16 or 32 MHz) crystal oscillator in units of 625/256 us (~2.44 us) - */ -#define CFG_BLE_HSE_STARTUP_TIME 0x148 - -/** - * Maximum duration of the connection event when the device is in Slave mode in units of 625/256 us (~2.44 us) - */ -#define CFG_BLE_MAX_CONN_EVENT_LENGTH ( 0xFFFFFFFF ) - -/** - * Viterbi Mode - * 1 : enabled - * 0 : disabled - */ -#define CFG_BLE_VITERBI_MODE 1 - -/** - * LL Only Mode - * 1 : LL Only - * 0 : LL + Host - */ -#define CFG_BLE_LL_ONLY 1 - -#endif /* APP_CONF_H */ +#include "app_conf_default.h" -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ +#endif /* APP_CONF_H */ \ No newline at end of file diff --git a/src/utility/STM32Cube_FW/app_conf_default.h b/src/utility/STM32Cube_FW/app_conf_default.h new file mode 100644 index 00000000..58c9f5bb --- /dev/null +++ b/src/utility/STM32Cube_FW/app_conf_default.h @@ -0,0 +1,185 @@ +/** + ****************************************************************************** + * File Name : app_conf_default.h + * Description : Default application configuration file for STM32WPAN Middleware. + ****************************************************************************** + * @attention + * + * <h2><center>© Copyright (c) 2020 STMicroelectronics. + * All rights reserved.</center></h2> + * + * This software component is licensed by ST under Ultimate Liberty license + * SLA0044, the "License"; You may not use this file except in compliance with + * the License. You may obtain a copy of the License at: + * www.st.com/SLA0044 + * + ****************************************************************************** + */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef APP_CONF_DEFAULT_H +#define APP_CONF_DEFAULT_H + +/****************************************************************************** + * Application Config + ******************************************************************************/ + +/**< generic parameters ******************************************************/ +/* HCI related defines */ + +#define ACI_HAL_SET_TX_POWER_LEVEL 0xFC0F +#define ACI_WRITE_CONFIG_DATA_OPCODE 0xFC0C +#define ACI_READ_CONFIG_DATA_OPCODE 0xFC0D +#define MAX_HCI_ACL_PACKET_SIZE (sizeof(TL_PacketHeader_t) + 5 + 251) +#define HCI_RESET 0x0C03 + +#ifndef BLE_SHARED_MEM_BYTE_ORDER +#define BLE_SHARED_MEM_BYTE_ORDER MSBFIRST +#endif +#define BLE_MODULE_SHARED_MEM_BUFFER_SIZE 128 + +/** + * Define Tx Power + */ +#ifndef CFG_TX_POWER +#define CFG_TX_POWER (0x18) /* -0.15dBm */ +#endif + +/****************************************************************************** + * BLE Stack + ******************************************************************************/ +/** + * Maximum number of simultaneous connections that the device will support. + * Valid values are from 1 to 8 + */ +#ifndef CFG_BLE_NUM_LINK +#define CFG_BLE_NUM_LINK 8 +#endif + +/** + * Maximum number of Services that can be stored in the GATT database. + * Note that the GAP and GATT services are automatically added so this parameter should be 2 plus the number of user + * services + */ +#ifndef CFG_BLE_NUM_GATT_SERVICES +#define CFG_BLE_NUM_GATT_SERVICES 8 +#endif + +/** + * Maximum number of Attributes + * (i.e. the number of characteristic + the number of characteristic values + the number of descriptors, excluding the + * services) that can be stored in the GATT database. Note that certain characteristics and relative descriptors are + * added automatically during device initialization so this parameters should be 9 plus the number of user Attributes + */ +#ifndef CFG_BLE_NUM_GATT_ATTRIBUTES +#define CFG_BLE_NUM_GATT_ATTRIBUTES 68 +#endif + +/** + * Maximum supported ATT_MTU size + */ +#ifndef CFG_BLE_MAX_ATT_MTU +#define CFG_BLE_MAX_ATT_MTU (156) +#endif + +/** + * Size of the storage area for Attribute values + * This value depends on the number of attributes used by application. In particular the sum of the following + * quantities (in octets) should be made for each attribute: + * - attribute value length + * - 5, if UUID is 16 bit; 19, if UUID is 128 bit + * - 2, if server configuration descriptor is used + * - 2*DTM_NUM_LINK, if client configuration descriptor is used + * - 2, if extended properties is used + * The total amount of memory needed is the sum of the above quantities for each attribute. + */ +#ifndef CFG_BLE_ATT_VALUE_ARRAY_SIZE +#define CFG_BLE_ATT_VALUE_ARRAY_SIZE (1344) +#endif + +/** + * Prepare Write List size in terms of number of packet + */ +//#define CFG_BLE_PREPARE_WRITE_LIST_SIZE BLE_PREP_WRITE_X_ATT(CFG_BLE_MAX_ATT_MTU) +#ifndef CFG_BLE_PREPARE_WRITE_LIST_SIZE +#define CFG_BLE_PREPARE_WRITE_LIST_SIZE (0x3A) +#endif + +/** + * Number of allocated memory blocks + */ +//#define CFG_BLE_MBLOCK_COUNT (BLE_MBLOCKS_CALC(CFG_BLE_PREPARE_WRITE_LIST_SIZE, CFG_BLE_MAX_ATT_MTU, +// CFG_BLE_NUM_LINK)) +#ifndef CFG_BLE_MBLOCK_COUNT +#define CFG_BLE_MBLOCK_COUNT (0x79) +#endif + +/** + * Enable or disable the Extended Packet length feature. Valid values are 0 or 1. + */ +#ifndef CFG_BLE_DATA_LENGTH_EXTENSION +#define CFG_BLE_DATA_LENGTH_EXTENSION 1 +#endif + +/** + * Sleep clock accuracy in Slave mode (ppm value) + */ +#ifndef CFG_BLE_SLAVE_SCA +#define CFG_BLE_SLAVE_SCA 500 +#endif + +/** + * Sleep clock accuracy in Master mode + * 0 : 251 ppm to 500 ppm + * 1 : 151 ppm to 250 ppm + * 2 : 101 ppm to 150 ppm + * 3 : 76 ppm to 100 ppm + * 4 : 51 ppm to 75 ppm + * 5 : 31 ppm to 50 ppm + * 6 : 21 ppm to 30 ppm + * 7 : 0 ppm to 20 ppm + */ +#ifndef CFG_BLE_MASTER_SCA +#define CFG_BLE_MASTER_SCA 0 +#endif + +/** + * Source for the 32 kHz slow speed clock + * 1 : internal RO + * 0 : external crystal ( no calibration ) + */ +#ifndef CFG_BLE_LSE_SOURCE +#define CFG_BLE_LSE_SOURCE 0 +#endif + +/** + * Start up time of the high speed (16 or 32 MHz) crystal oscillator in units of 625/256 us (~2.44 us) + */ +#ifndef CFG_BLE_HSE_STARTUP_TIME +#define CFG_BLE_HSE_STARTUP_TIME 0x148 +#endif + +/** + * Maximum duration of the connection event when the device is in Slave mode in units of 625/256 us (~2.44 us) + */ +#ifndef CFG_BLE_MAX_CONN_EVENT_LENGTH +#define CFG_BLE_MAX_CONN_EVENT_LENGTH (0xFFFFFFFF) +#endif + +/** + * Viterbi Mode + * 1 : enabled + * 0 : disabled + */ +#define CFG_BLE_VITERBI_MODE 1 + +/** + * LL Only Mode + * 1 : LL Only + * 0 : LL + Host + */ +#define CFG_BLE_LL_ONLY 1 + +#endif /* APP_CONF_DEFAULT_H */ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ From 6a6c5505cfe72d11d42979324ff4f98aef4c6af0 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Wed, 1 Dec 2021 10:21:53 +0100 Subject: [PATCH 065/226] Revert "Added support for custom app_conf.h (#35)" This reverts commit 095fe1802f363865f631133e0f2c01fa3f9325a8. --- README.md | 5 - src/utility/STM32Cube_FW/app_conf.h | 162 +++++++++++++++-- src/utility/STM32Cube_FW/app_conf_default.h | 185 -------------------- 3 files changed, 150 insertions(+), 202 deletions(-) delete mode 100644 src/utility/STM32Cube_FW/app_conf_default.h diff --git a/README.md b/README.md index b2d48b13..2fb6e425 100644 --- a/README.md +++ b/README.md @@ -16,11 +16,6 @@ https://github.com/stm32duino/wiki/wiki/STM32duinoBLE#stm32duinoble-with-x-nucle For more information about ArduinoBLE library please visit the official web page at: https://github.com/arduino-libraries/ArduinoBLE -# Configuration -STM32Cube_WPAN has several configuration options, which are set in the `app_conf.h`. -This package has a default configuration named `app_conf_default.h`. -The user can include the file `app_conf_custom.h` to customize the ble application. Options wrapped in `#ifndef, #endif` in `app_conf_default.h` can be overwritten. Additional options can be added. - ## License ``` diff --git a/src/utility/STM32Cube_FW/app_conf.h b/src/utility/STM32Cube_FW/app_conf.h index 888c91a0..667dbbd4 100644 --- a/src/utility/STM32Cube_FW/app_conf.h +++ b/src/utility/STM32Cube_FW/app_conf.h @@ -1,20 +1,158 @@ -//----------------------------- -// @file app_conf.h -// @author Kasper Meldgaard -// @brief Wrapper for BLE app configuration based on comment by fpistm -// (https://github.com/stm32duino/STM32duinoBLE/issues/34). -// @date 15-11-2021 -// @copyright Copyright (c) 2021 +/** + ****************************************************************************** + * File Name : app_conf.h + * Description : Application configuration file for STM32WPAN Middleware. + ****************************************************************************** + * @attention + * + * <h2><center>© Copyright (c) 2020 STMicroelectronics. + * All rights reserved.</center></h2> + * + * This software component is licensed by ST under Ultimate Liberty license + * SLA0044, the "License"; You may not use this file except in compliance with + * the License. You may obtain a copy of the License at: + * www.st.com/SLA0044 + * + ****************************************************************************** + */ +/* Define to prevent recursive inclusion -------------------------------------*/ #ifndef APP_CONF_H #define APP_CONF_H -#include "ble_bufsize.h" #include "hw.h" +#include "ble_bufsize.h" + + +/****************************************************************************** + * Application Config + ******************************************************************************/ + +/**< generic parameters ******************************************************/ +/* HCI related defines */ + +#define ACI_HAL_SET_TX_POWER_LEVEL 0xFC0F +#define ACI_WRITE_CONFIG_DATA_OPCODE 0xFC0C +#define ACI_READ_CONFIG_DATA_OPCODE 0xFC0D +#define MAX_HCI_ACL_PACKET_SIZE (sizeof(TL_PacketHeader_t) + 5 + 251) +#define HCI_RESET 0x0C03 -#if __has_include("app_conf_custom.h") -#include "app_conf_custom.h" +#ifndef BLE_SHARED_MEM_BYTE_ORDER + #define BLE_SHARED_MEM_BYTE_ORDER MSBFIRST #endif -#include "app_conf_default.h" +#define BLE_MODULE_SHARED_MEM_BUFFER_SIZE 128 + +/** + * Define Tx Power + */ +#define CFG_TX_POWER (0x18) /* -0.15dBm */ + +/****************************************************************************** + * BLE Stack + ******************************************************************************/ +/** + * Maximum number of simultaneous connections that the device will support. + * Valid values are from 1 to 8 + */ +#define CFG_BLE_NUM_LINK 8 + +/** + * Maximum number of Services that can be stored in the GATT database. + * Note that the GAP and GATT services are automatically added so this parameter should be 2 plus the number of user services + */ +#define CFG_BLE_NUM_GATT_SERVICES 8 + +/** + * Maximum number of Attributes + * (i.e. the number of characteristic + the number of characteristic values + the number of descriptors, excluding the services) + * that can be stored in the GATT database. + * Note that certain characteristics and relative descriptors are added automatically during device initialization + * so this parameters should be 9 plus the number of user Attributes + */ +#define CFG_BLE_NUM_GATT_ATTRIBUTES 68 + +/** + * Maximum supported ATT_MTU size + */ +#define CFG_BLE_MAX_ATT_MTU (156) + +/** + * Size of the storage area for Attribute values + * This value depends on the number of attributes used by application. In particular the sum of the following quantities (in octets) should be made for each attribute: + * - attribute value length + * - 5, if UUID is 16 bit; 19, if UUID is 128 bit + * - 2, if server configuration descriptor is used + * - 2*DTM_NUM_LINK, if client configuration descriptor is used + * - 2, if extended properties is used + * The total amount of memory needed is the sum of the above quantities for each attribute. + */ +#define CFG_BLE_ATT_VALUE_ARRAY_SIZE (1344) + +/** + * Prepare Write List size in terms of number of packet + */ +//#define CFG_BLE_PREPARE_WRITE_LIST_SIZE BLE_PREP_WRITE_X_ATT(CFG_BLE_MAX_ATT_MTU) +#define CFG_BLE_PREPARE_WRITE_LIST_SIZE (0x3A) + +/** + * Number of allocated memory blocks + */ +//#define CFG_BLE_MBLOCK_COUNT (BLE_MBLOCKS_CALC(CFG_BLE_PREPARE_WRITE_LIST_SIZE, CFG_BLE_MAX_ATT_MTU, CFG_BLE_NUM_LINK)) +#define CFG_BLE_MBLOCK_COUNT (0x79) +/** + * Enable or disable the Extended Packet length feature. Valid values are 0 or 1. + */ +#define CFG_BLE_DATA_LENGTH_EXTENSION 1 + +/** + * Sleep clock accuracy in Slave mode (ppm value) + */ +#define CFG_BLE_SLAVE_SCA 500 + +/** + * Sleep clock accuracy in Master mode + * 0 : 251 ppm to 500 ppm + * 1 : 151 ppm to 250 ppm + * 2 : 101 ppm to 150 ppm + * 3 : 76 ppm to 100 ppm + * 4 : 51 ppm to 75 ppm + * 5 : 31 ppm to 50 ppm + * 6 : 21 ppm to 30 ppm + * 7 : 0 ppm to 20 ppm + */ +#define CFG_BLE_MASTER_SCA 0 + +/** + * Source for the 32 kHz slow speed clock + * 1 : internal RO + * 0 : external crystal ( no calibration ) + */ +#define CFG_BLE_LSE_SOURCE 0 + +/** + * Start up time of the high speed (16 or 32 MHz) crystal oscillator in units of 625/256 us (~2.44 us) + */ +#define CFG_BLE_HSE_STARTUP_TIME 0x148 + +/** + * Maximum duration of the connection event when the device is in Slave mode in units of 625/256 us (~2.44 us) + */ +#define CFG_BLE_MAX_CONN_EVENT_LENGTH ( 0xFFFFFFFF ) + +/** + * Viterbi Mode + * 1 : enabled + * 0 : disabled + */ +#define CFG_BLE_VITERBI_MODE 1 + +/** + * LL Only Mode + * 1 : LL Only + * 0 : LL + Host + */ +#define CFG_BLE_LL_ONLY 1 + +#endif /* APP_CONF_H */ -#endif /* APP_CONF_H */ \ No newline at end of file +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/src/utility/STM32Cube_FW/app_conf_default.h b/src/utility/STM32Cube_FW/app_conf_default.h deleted file mode 100644 index 58c9f5bb..00000000 --- a/src/utility/STM32Cube_FW/app_conf_default.h +++ /dev/null @@ -1,185 +0,0 @@ -/** - ****************************************************************************** - * File Name : app_conf_default.h - * Description : Default application configuration file for STM32WPAN Middleware. - ****************************************************************************** - * @attention - * - * <h2><center>© Copyright (c) 2020 STMicroelectronics. - * All rights reserved.</center></h2> - * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 - * - ****************************************************************************** - */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef APP_CONF_DEFAULT_H -#define APP_CONF_DEFAULT_H - -/****************************************************************************** - * Application Config - ******************************************************************************/ - -/**< generic parameters ******************************************************/ -/* HCI related defines */ - -#define ACI_HAL_SET_TX_POWER_LEVEL 0xFC0F -#define ACI_WRITE_CONFIG_DATA_OPCODE 0xFC0C -#define ACI_READ_CONFIG_DATA_OPCODE 0xFC0D -#define MAX_HCI_ACL_PACKET_SIZE (sizeof(TL_PacketHeader_t) + 5 + 251) -#define HCI_RESET 0x0C03 - -#ifndef BLE_SHARED_MEM_BYTE_ORDER -#define BLE_SHARED_MEM_BYTE_ORDER MSBFIRST -#endif -#define BLE_MODULE_SHARED_MEM_BUFFER_SIZE 128 - -/** - * Define Tx Power - */ -#ifndef CFG_TX_POWER -#define CFG_TX_POWER (0x18) /* -0.15dBm */ -#endif - -/****************************************************************************** - * BLE Stack - ******************************************************************************/ -/** - * Maximum number of simultaneous connections that the device will support. - * Valid values are from 1 to 8 - */ -#ifndef CFG_BLE_NUM_LINK -#define CFG_BLE_NUM_LINK 8 -#endif - -/** - * Maximum number of Services that can be stored in the GATT database. - * Note that the GAP and GATT services are automatically added so this parameter should be 2 plus the number of user - * services - */ -#ifndef CFG_BLE_NUM_GATT_SERVICES -#define CFG_BLE_NUM_GATT_SERVICES 8 -#endif - -/** - * Maximum number of Attributes - * (i.e. the number of characteristic + the number of characteristic values + the number of descriptors, excluding the - * services) that can be stored in the GATT database. Note that certain characteristics and relative descriptors are - * added automatically during device initialization so this parameters should be 9 plus the number of user Attributes - */ -#ifndef CFG_BLE_NUM_GATT_ATTRIBUTES -#define CFG_BLE_NUM_GATT_ATTRIBUTES 68 -#endif - -/** - * Maximum supported ATT_MTU size - */ -#ifndef CFG_BLE_MAX_ATT_MTU -#define CFG_BLE_MAX_ATT_MTU (156) -#endif - -/** - * Size of the storage area for Attribute values - * This value depends on the number of attributes used by application. In particular the sum of the following - * quantities (in octets) should be made for each attribute: - * - attribute value length - * - 5, if UUID is 16 bit; 19, if UUID is 128 bit - * - 2, if server configuration descriptor is used - * - 2*DTM_NUM_LINK, if client configuration descriptor is used - * - 2, if extended properties is used - * The total amount of memory needed is the sum of the above quantities for each attribute. - */ -#ifndef CFG_BLE_ATT_VALUE_ARRAY_SIZE -#define CFG_BLE_ATT_VALUE_ARRAY_SIZE (1344) -#endif - -/** - * Prepare Write List size in terms of number of packet - */ -//#define CFG_BLE_PREPARE_WRITE_LIST_SIZE BLE_PREP_WRITE_X_ATT(CFG_BLE_MAX_ATT_MTU) -#ifndef CFG_BLE_PREPARE_WRITE_LIST_SIZE -#define CFG_BLE_PREPARE_WRITE_LIST_SIZE (0x3A) -#endif - -/** - * Number of allocated memory blocks - */ -//#define CFG_BLE_MBLOCK_COUNT (BLE_MBLOCKS_CALC(CFG_BLE_PREPARE_WRITE_LIST_SIZE, CFG_BLE_MAX_ATT_MTU, -// CFG_BLE_NUM_LINK)) -#ifndef CFG_BLE_MBLOCK_COUNT -#define CFG_BLE_MBLOCK_COUNT (0x79) -#endif - -/** - * Enable or disable the Extended Packet length feature. Valid values are 0 or 1. - */ -#ifndef CFG_BLE_DATA_LENGTH_EXTENSION -#define CFG_BLE_DATA_LENGTH_EXTENSION 1 -#endif - -/** - * Sleep clock accuracy in Slave mode (ppm value) - */ -#ifndef CFG_BLE_SLAVE_SCA -#define CFG_BLE_SLAVE_SCA 500 -#endif - -/** - * Sleep clock accuracy in Master mode - * 0 : 251 ppm to 500 ppm - * 1 : 151 ppm to 250 ppm - * 2 : 101 ppm to 150 ppm - * 3 : 76 ppm to 100 ppm - * 4 : 51 ppm to 75 ppm - * 5 : 31 ppm to 50 ppm - * 6 : 21 ppm to 30 ppm - * 7 : 0 ppm to 20 ppm - */ -#ifndef CFG_BLE_MASTER_SCA -#define CFG_BLE_MASTER_SCA 0 -#endif - -/** - * Source for the 32 kHz slow speed clock - * 1 : internal RO - * 0 : external crystal ( no calibration ) - */ -#ifndef CFG_BLE_LSE_SOURCE -#define CFG_BLE_LSE_SOURCE 0 -#endif - -/** - * Start up time of the high speed (16 or 32 MHz) crystal oscillator in units of 625/256 us (~2.44 us) - */ -#ifndef CFG_BLE_HSE_STARTUP_TIME -#define CFG_BLE_HSE_STARTUP_TIME 0x148 -#endif - -/** - * Maximum duration of the connection event when the device is in Slave mode in units of 625/256 us (~2.44 us) - */ -#ifndef CFG_BLE_MAX_CONN_EVENT_LENGTH -#define CFG_BLE_MAX_CONN_EVENT_LENGTH (0xFFFFFFFF) -#endif - -/** - * Viterbi Mode - * 1 : enabled - * 0 : disabled - */ -#define CFG_BLE_VITERBI_MODE 1 - -/** - * LL Only Mode - * 1 : LL Only - * 0 : LL + Host - */ -#define CFG_BLE_LL_ONLY 1 - -#endif /* APP_CONF_DEFAULT_H */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ From b64df412e90a7cd61966115560077d2479c9abd5 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Wed, 1 Dec 2021 10:22:00 +0100 Subject: [PATCH 066/226] Revert "Include a timeout when waiting for the cmd_resp" This reverts commit 3a063dff2f8d4159ced2c98e7d866973dbaf6eec. --- src/utility/STM32Cube_FW/shci_tl.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/utility/STM32Cube_FW/shci_tl.c b/src/utility/STM32Cube_FW/shci_tl.c index c2d7589e..1ab15b47 100644 --- a/src/utility/STM32Cube_FW/shci_tl.c +++ b/src/utility/STM32Cube_FW/shci_tl.c @@ -21,8 +21,6 @@ /* Includes ------------------------------------------------------------------*/ #include "stm32_wpan_common.h" -#include <Arduino.h> - #include "stm_list.h" #include "shci_tl.h" #include "stm32_def.h" @@ -325,12 +323,11 @@ static void OutputEvtTrace(TL_EvtPacket_t *phcievtbuffer) /* Weak implementation ----------------------------------------------------------------*/ __WEAK void shci_cmd_resp_wait(uint32_t timeout) { + (void)timeout; + CmdRspStatusFlag = SHCI_TL_CMD_RESP_WAIT; - for (unsigned long start = millis(); (millis() - start) < timeout;) { - if (CmdRspStatusFlag == SHCI_TL_CMD_RESP_RELEASE) { - break; - } - } + while (CmdRspStatusFlag != SHCI_TL_CMD_RESP_RELEASE); + return; } From a5260674fd145fa82d3871b7339439594ad6f9fa Mon Sep 17 00:00:00 2001 From: Francois Ramu <francois.ramu@st.com> Date: Thu, 19 Nov 2020 19:07:13 +0100 Subject: [PATCH 067/226] Revert "Fix [-Waddress-of-packed-member] warning" --- src/utility/STM32Cube_FW/stm_list.h | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/utility/STM32Cube_FW/stm_list.h b/src/utility/STM32Cube_FW/stm_list.h index 885b50c1..b5f1cc8d 100644 --- a/src/utility/STM32Cube_FW/stm_list.h +++ b/src/utility/STM32Cube_FW/stm_list.h @@ -23,14 +23,10 @@ /* Includes ------------------------------------------------------------------*/ +#include "stdint.h" #include "stdbool.h" -#include "stm32_wpan_common.h" -#ifdef __cplusplus -extern "C" { -#endif - -typedef PACKED_STRUCT _tListNode { +typedef struct _tListNode { struct _tListNode *next; struct _tListNode *prev; } tListNode; @@ -59,8 +55,4 @@ void LST_get_next_node(tListNode *ref_node, tListNode **node); void LST_get_prev_node(tListNode *ref_node, tListNode **node); -#ifdef __cplusplus -} -#endif - #endif /* _STM_LIST_H_ */ From 643daea841c8eae8c96133a694fb8b0bd6ce0bda Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Wed, 1 Dec 2021 10:29:17 +0100 Subject: [PATCH 068/226] Revert "Missing IPCC enable for C2 in several examples from stm32CubeWB" This reverts commit 163bd85bf724a6d4f17c48ae051bd6ca1a108c3d. --- src/utility/STM32Cube_FW/hw_ipcc.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/utility/STM32Cube_FW/hw_ipcc.c b/src/utility/STM32Cube_FW/hw_ipcc.c index 925075f8..dbeb3eeb 100644 --- a/src/utility/STM32Cube_FW/hw_ipcc.c +++ b/src/utility/STM32Cube_FW/hw_ipcc.c @@ -94,12 +94,6 @@ void IPCC_C1_TX_IRQHandler(void) ******************************************************************************/ void HW_IPCC_Enable(void) { - /** - * Such as IPCC IP available to the CPU2, it is required to keep the IPCC clock running - when FUS is running on CPU2 and CPU1 enters deep sleep mode - */ - LL_C2_AHB3_GRP1_EnableClock(LL_C2_AHB3_GRP1_PERIPH_IPCC); - /** * When the device is out of standby, it is required to use the EXTI mechanism to wakeup CPU2 */ From 98952728fec94cebb2db5ccbffbcefb3c5fb66ba Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Wed, 1 Dec 2021 10:38:36 +0100 Subject: [PATCH 069/226] Revert "This BLE RF configuration has many unused define values" This reverts commit 732ffed41b4b4ff32e9a8a23fd53fc0cc3867387. --- src/utility/STM32Cube_FW/app_conf.h | 403 +++++++++++++++++++++++++++- 1 file changed, 390 insertions(+), 13 deletions(-) diff --git a/src/utility/STM32Cube_FW/app_conf.h b/src/utility/STM32Cube_FW/app_conf.h index 667dbbd4..22c7b5c5 100644 --- a/src/utility/STM32Cube_FW/app_conf.h +++ b/src/utility/STM32Cube_FW/app_conf.h @@ -29,24 +29,117 @@ ******************************************************************************/ /**< generic parameters ******************************************************/ -/* HCI related defines */ - -#define ACI_HAL_SET_TX_POWER_LEVEL 0xFC0F -#define ACI_WRITE_CONFIG_DATA_OPCODE 0xFC0C -#define ACI_READ_CONFIG_DATA_OPCODE 0xFC0D -#define MAX_HCI_ACL_PACKET_SIZE (sizeof(TL_PacketHeader_t) + 5 + 251) -#define HCI_RESET 0x0C03 - -#ifndef BLE_SHARED_MEM_BYTE_ORDER - #define BLE_SHARED_MEM_BYTE_ORDER MSBFIRST -#endif -#define BLE_MODULE_SHARED_MEM_BUFFER_SIZE 128 /** * Define Tx Power */ #define CFG_TX_POWER (0x18) /* -0.15dBm */ +/** + * Define Advertising parameters + */ +#define CFG_ADV_BD_ADDRESS (0x7257acd87a6c) +#define CFG_FAST_CONN_ADV_INTERVAL_MIN (0x80) /**< 80ms */ +#define CFG_FAST_CONN_ADV_INTERVAL_MAX (0xa0) /**< 100ms */ +#define CFG_LP_CONN_ADV_INTERVAL_MIN (0x640) /**< 1s */ +#define CFG_LP_CONN_ADV_INTERVAL_MAX (0xfa0) /**< 2.5s */ + +/** + * Define IO Authentication + */ +#define CFG_BONDING_MODE (1) +#define CFG_FIXED_PIN (111111) +#define CFG_USED_FIXED_PIN (0) +#define CFG_ENCRYPTION_KEY_SIZE_MAX (16) +#define CFG_ENCRYPTION_KEY_SIZE_MIN (8) + +/** + * Define IO capabilities + */ +#define CFG_IO_CAPABILITY_DISPLAY_ONLY (0x00) +#define CFG_IO_CAPABILITY_DISPLAY_YES_NO (0x01) +#define CFG_IO_CAPABILITY_KEYBOARD_ONLY (0x02) +#define CFG_IO_CAPABILITY_NO_INPUT_NO_OUTPUT (0x03) +#define CFG_IO_CAPABILITY_KEYBOARD_DISPLAY (0x04) + +#define CFG_IO_CAPABILITY CFG_IO_CAPABILITY_DISPLAY_YES_NO + +/** + * Define MITM modes + */ +#define CFG_MITM_PROTECTION_NOT_REQUIRED (0x00) +#define CFG_MITM_PROTECTION_REQUIRED (0x01) + +#define CFG_MITM_PROTECTION CFG_MITM_PROTECTION_REQUIRED + +/** + * Define Secure Connections Support + */ +#define CFG_SECURE_NOT_SUPPORTED (0x00) +#define CFG_SECURE_OPTIONAL (0x01) +#define CFG_SECURE_MANDATORY (0x02) + +#define CFG_SC_SUPPORT CFG_SECURE_OPTIONAL + +/** + * Define Keypress Notification Support + */ +#define CFG_KEYPRESS_NOT_SUPPORTED (0x00) +#define CFG_KEYPRESS_SUPPORTED (0x01) + +#define CFG_KEYPRESS_NOTIFICATION_SUPPORT CFG_KEYPRESS_NOT_SUPPORTED + +/** + * Numeric Comparison Answers + */ +#define YES (0x01) +#define NO (0x00) + +/** + * Device name configuration for Generic Access Service + */ +#define CFG_GAP_DEVICE_NAME "TEMPLATE" +#define CFG_GAP_DEVICE_NAME_LENGTH (8) + +/** + * Define PHY + */ +#define ALL_PHYS_PREFERENCE 0x00 +#define RX_2M_PREFERRED 0x02 +#define TX_2M_PREFERRED 0x02 +#define TX_1M 0x01 +#define TX_2M 0x02 +#define RX_1M 0x01 +#define RX_2M 0x02 + +/** +* Identity root key used to derive LTK and CSRK +*/ +#define CFG_BLE_IRK {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0} + +/** +* Encryption root key used to derive LTK and CSRK +*/ +#define CFG_BLE_ERK {0xfe,0xdc,0xba,0x09,0x87,0x65,0x43,0x21,0xfe,0xdc,0xba,0x09,0x87,0x65,0x43,0x21} + +/* USER CODE BEGIN Generic_Parameters */ +/** + * SMPS supply + * SMPS not used when Set to 0 + * SMPS used when Set to 1 + */ +#define CFG_USE_SMPS 1 +/* USER CODE END Generic_Parameters */ + +/**< specific parameters */ +/*****************************************************/ + +/** +* AD Element - Group B Feature +*/ +/* LSB - Second Byte */ +#define CFG_FEATURE_OTA_REBOOT (0x20) + /****************************************************************************** * BLE Stack ******************************************************************************/ @@ -152,7 +245,291 @@ * 0 : LL + Host */ #define CFG_BLE_LL_ONLY 1 +/****************************************************************************** + * Transport Layer + ******************************************************************************/ +/** + * Queue length of BLE Event + * This parameter defines the number of asynchronous events that can be stored in the HCI layer before + * being reported to the application. When a command is sent to the BLE core coprocessor, the HCI layer + * is waiting for the event with the Num_HCI_Command_Packets set to 1. The receive queue shall be large + * enough to store all asynchronous events received in between. + * When CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE is set to 27, this allow to store three 255 bytes long asynchronous events + * between the HCI command and its event. + * This parameter depends on the value given to CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE. When the queue size is to small, + * the system may hang if the queue is full with asynchronous events and the HCI layer is still waiting + * for a CC/CS event, In that case, the notification TL_BLE_HCI_ToNot() is called to indicate + * to the application a HCI command did not receive its command event within 30s (Default HCI Timeout). + */ +#define CFG_TLBLE_EVT_QUEUE_LENGTH 5 +/** + * This parameter should be set to fit most events received by the HCI layer. It defines the buffer size of each element + * allocated in the queue of received events and can be used to optimize the amount of RAM allocated by the Memory Manager. + * It should not exceed 255 which is the maximum HCI packet payload size (a greater value is a lost of memory as it will + * never be used) + * It shall be at least 4 to receive the command status event in one frame. + * The default value is set to 27 to allow receiving an event of MTU size in a single buffer. This value maybe reduced + * further depending on the application. + * + */ +#define CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE 255 /**< Set to 255 with the memory manager and the mailbox */ + +#define TL_BLE_EVENT_FRAME_SIZE ( TL_EVT_HDR_SIZE + CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE ) +/****************************************************************************** + * UART interfaces + ******************************************************************************/ + +/** + * Select UART interfaces + */ +#define CFG_DEBUG_TRACE_UART hw_uart1 +#define CFG_CONSOLE_MENU 0 +/****************************************************************************** + * USB interface + ******************************************************************************/ + +/** + * Enable/Disable USB interface + */ +#define CFG_USB_INTERFACE_ENABLE 0 + +/****************************************************************************** + * Low Power + ******************************************************************************/ +/** + * When set to 1, the low power mode is enable + * When set to 0, the device stays in RUN mode + */ +#define CFG_LPM_SUPPORTED 1 + +/****************************************************************************** + * Timer Server + ******************************************************************************/ +/** + * CFG_RTC_WUCKSEL_DIVIDER: This sets the RTCCLK divider to the wakeup timer. + * The higher is the value, the better is the power consumption and the accuracy of the timerserver + * The lower is the value, the finest is the granularity + * + * CFG_RTC_ASYNCH_PRESCALER: This sets the asynchronous prescaler of the RTC. It should as high as possible ( to output + * clock as low as possible) but the output clock should be equal or higher frequency compare to the clock feeding + * the wakeup timer. A lower clock speed would impact the accuracy of the timer server. + * + * CFG_RTC_SYNCH_PRESCALER: This sets the synchronous prescaler of the RTC. + * When the 1Hz calendar clock is required, it shall be sets according to other settings + * When the 1Hz calendar clock is not needed, CFG_RTC_SYNCH_PRESCALER should be set to 0x7FFF (MAX VALUE) + * + * CFG_RTCCLK_DIVIDER_CONF: + * Shall be set to either 0,2,4,8,16 + * When set to either 2,4,8,16, the 1Hhz calendar is supported + * When set to 0, the user sets its own configuration + * + * The following settings are computed with LSI as input to the RTC + */ +#define CFG_RTCCLK_DIVIDER_CONF 0 + +#if (CFG_RTCCLK_DIVIDER_CONF == 0) + /** + * Custom configuration + * It does not support 1Hz calendar + * It divides the RTC CLK by 16 + */ + #define CFG_RTCCLK_DIV (16) + #define CFG_RTC_WUCKSEL_DIVIDER (0) + #define CFG_RTC_ASYNCH_PRESCALER (CFG_RTCCLK_DIV - 1) + #define CFG_RTC_SYNCH_PRESCALER (0x7FFF) + +#else + + #if (CFG_RTCCLK_DIVIDER_CONF == 2) + /** + * It divides the RTC CLK by 2 + */ + #define CFG_RTC_WUCKSEL_DIVIDER (3) + #endif + + #if (CFG_RTCCLK_DIVIDER_CONF == 4) + /** + * It divides the RTC CLK by 4 + */ + #define CFG_RTC_WUCKSEL_DIVIDER (2) + #endif + + #if (CFG_RTCCLK_DIVIDER_CONF == 8) + /** + * It divides the RTC CLK by 8 + */ + #define CFG_RTC_WUCKSEL_DIVIDER (1) + #endif + + #if (CFG_RTCCLK_DIVIDER_CONF == 16) + /** + * It divides the RTC CLK by 16 + */ + #define CFG_RTC_WUCKSEL_DIVIDER (0) + #endif + + #define CFG_RTCCLK_DIV CFG_RTCCLK_DIVIDER_CONF + #define CFG_RTC_ASYNCH_PRESCALER (CFG_RTCCLK_DIV - 1) + #define CFG_RTC_SYNCH_PRESCALER (DIVR( LSE_VALUE, (CFG_RTC_ASYNCH_PRESCALER+1) ) - 1 ) + +#endif + +/** tick timer value in us */ +#define CFG_TS_TICK_VAL DIVR( (CFG_RTCCLK_DIV * 1000000), LSE_VALUE ) + +typedef enum { + CFG_TIM_PROC_ID_ISR, +} CFG_TimProcID_t; + +/****************************************************************************** + * Debug + ******************************************************************************/ +/** + * When set, this resets some hw resources to set the device in the same state than the power up + * The FW resets only register that may prevent the FW to run properly + * + * This shall be set to 0 in a final product + * + */ +#define CFG_HW_RESET_BY_FW 1 + +/** + * keep debugger enabled while in any low power mode when set to 1 + * should be set to 0 in production + */ +#define CFG_DEBUGGER_SUPPORTED 0 + +/** + * When set to 1, the traces are enabled in the BLE services + */ +#define CFG_DEBUG_BLE_TRACE 0 + +/** + * Enable or Disable traces in application + */ +#define CFG_DEBUG_APP_TRACE 0 + +#if (CFG_DEBUG_APP_TRACE != 0) + #define APP_DBG_MSG PRINT_MESG_DBG +#else + #define APP_DBG_MSG PRINT_NO_MESG +#endif + +#if ( (CFG_DEBUG_BLE_TRACE != 0) || (CFG_DEBUG_APP_TRACE != 0) ) + #define CFG_DEBUG_TRACE 1 +#endif + +#if (CFG_DEBUG_TRACE != 0) + #undef CFG_LPM_SUPPORTED + #undef CFG_DEBUGGER_SUPPORTED + #define CFG_LPM_SUPPORTED 0 + #define CFG_DEBUGGER_SUPPORTED 1 +#endif + +/** + * When CFG_DEBUG_TRACE_FULL is set to 1, the trace are output with the API name, the file name and the line number + * When CFG_DEBUG_TRACE_LIGHT is set to 1, only the debug message is output + * + * When both are set to 0, no trace are output + * When both are set to 1, CFG_DEBUG_TRACE_FULL is selected + */ +#define CFG_DEBUG_TRACE_LIGHT 0 +#define CFG_DEBUG_TRACE_FULL 0 + +#if (( CFG_DEBUG_TRACE != 0 ) && ( CFG_DEBUG_TRACE_LIGHT == 0 ) && (CFG_DEBUG_TRACE_FULL == 0)) + #undef CFG_DEBUG_TRACE_FULL + #undef CFG_DEBUG_TRACE_LIGHT + #define CFG_DEBUG_TRACE_FULL 0 + #define CFG_DEBUG_TRACE_LIGHT 1 +#endif + +#if ( CFG_DEBUG_TRACE == 0 ) + #undef CFG_DEBUG_TRACE_FULL + #undef CFG_DEBUG_TRACE_LIGHT + #define CFG_DEBUG_TRACE_FULL 0 + #define CFG_DEBUG_TRACE_LIGHT 0 +#endif + +/** + * When not set, the traces is looping on sending the trace over UART + */ +#define DBG_TRACE_USE_CIRCULAR_QUEUE 1 + +/** + * max buffer Size to queue data traces and max data trace allowed. + * Only Used if DBG_TRACE_USE_CIRCULAR_QUEUE is defined + */ +#define DBG_TRACE_MSG_QUEUE_SIZE 4096 +#define MAX_DBG_TRACE_MSG_SIZE 1024 + +/* USER CODE BEGIN Defines */ +#define CFG_LED_SUPPORTED 0 +#define CFG_BUTTON_SUPPORTED 1 +/* USER CODE END Defines */ + +/****************************************************************************** + * FreeRTOS + ******************************************************************************/ +#define CFG_SHCI_USER_EVT_PROCESS_NAME "SHCI_USER_EVT_PROCESS" +#define CFG_SHCI_USER_EVT_PROCESS_ATTR_BITS (0) +#define CFG_SHCI_USER_EVT_PROCESS_CB_MEM (0) +#define CFG_SHCI_USER_EVT_PROCESS_CB_SIZE (0) +#define CFG_SHCI_USER_EVT_PROCESS_STACK_MEM (0) +#define CFG_SHCI_USER_EVT_PROCESS_PRIORITY osPriorityNone +#define CFG_SHCI_USER_EVT_PROCESS_STACK_SIZE (128 * 7) + +#define CFG_HCI_USER_EVT_PROCESS_NAME "HCI_USER_EVT_PROCESS" +#define CFG_HCI_USER_EVT_PROCESS_ATTR_BITS (0) +#define CFG_HCI_USER_EVT_PROCESS_CB_MEM (0) +#define CFG_HCI_USER_EVT_PROCESS_CB_SIZE (0) +#define CFG_HCI_USER_EVT_PROCESS_STACK_MEM (0) +#define CFG_HCI_USER_EVT_PROCESS_PRIORITY osPriorityNone +#define CFG_HCI_USER_EVT_PROCESS_STACK_SIZE (128 * 8) + +#define CFG_ADV_UPDATE_PROCESS_NAME "ADV_UPDATE_PROCESS" +#define CFG_ADV_UPDATE_PROCESS_ATTR_BITS (0) +#define CFG_ADV_UPDATE_PROCESS_CB_MEM (0) +#define CFG_ADV_UPDATE_PROCESS_CB_SIZE (0) +#define CFG_ADV_UPDATE_PROCESS_STACK_MEM (0) +#define CFG_ADV_UPDATE_PROCESS_PRIORITY osPriorityNone +#define CFG_ADV_UPDATE_PROCESS_STACK_SIZE (128 * 6) + +#define CFG_HRS_PROCESS_NAME "HRS_PROCESS" +#define CFG_HRS_PROCESS_ATTR_BITS (0) +#define CFG_HRS_PROCESS_CB_MEM (0) +#define CFG_HRS_PROCESS_CB_SIZE (0) +#define CFG_HRS_PROCESS_STACK_MEM (0) +#define CFG_HRS_PROCESS_PRIORITY osPriorityNone +#define CFG_HRS_PROCESS_STACK_SIZE (128 * 5) + +/* USER CODE BEGIN FreeRTOS_Defines */ +#define PUSH_BUTTON_SW1_EXTI_IRQHandler EXTI4_IRQHandler +#define PUSH_BUTTON_SW2_EXTI_IRQHandler EXTI0_IRQHandler +#define PUSH_BUTTON_SW3_EXTI_IRQHandler EXTI1_IRQHandler +/* USER CODE END FreeRTOS_Defines */ + +/****************************************************************************** + * LOW POWER + ******************************************************************************/ +/** + * Supported requester to the MCU Low Power Manager - can be increased up to 32 + * It lists a bit mapping of all user of the Low Power Manager + */ +typedef enum { + CFG_LPM_APP, + CFG_LPM_APP_BLE, + /* USER CODE BEGIN CFG_LPM_Id_t */ + + /* USER CODE END CFG_LPM_Id_t */ +} CFG_LPM_Id_t; + +/****************************************************************************** + * OTP manager + ******************************************************************************/ +#define CFG_OTP_BASE_ADDRESS OTP_AREA_BASE + +#define CFG_OTP_END_ADRESS OTP_AREA_END_ADDR -#endif /* APP_CONF_H */ +#endif /*APP_CONF_H */ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ From ce7cb45b33e9590d3bdf6268dbda3d60cb2a8e06 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Wed, 1 Dec 2021 10:38:58 +0100 Subject: [PATCH 070/226] Revert "Include the STM32Cube_FW to support the BLE of the stm32wb55" This reverts commit 3019930966782e57d119e62b64248b0fee36d20f. --- src/utility/STM32Cube_FW/app_conf.h | 535 ----------- src/utility/STM32Cube_FW/ble_bufsize.h | 161 ---- src/utility/STM32Cube_FW/hw.h | 97 -- src/utility/STM32Cube_FW/hw_ipcc.c | 342 ------- src/utility/STM32Cube_FW/mbox_def.h | 212 ----- src/utility/STM32Cube_FW/shci.c | 567 ------------ src/utility/STM32Cube_FW/shci.h | 888 ------------------- src/utility/STM32Cube_FW/shci_tl.c | 344 ------- src/utility/STM32Cube_FW/shci_tl.h | 169 ---- src/utility/STM32Cube_FW/stm32_wpan_common.h | 143 --- src/utility/STM32Cube_FW/stm_list.c | 206 ----- src/utility/STM32Cube_FW/stm_list.h | 58 -- src/utility/STM32Cube_FW/tl.h | 294 ------ src/utility/STM32Cube_FW/tl_mbox.c | 545 ------------ 14 files changed, 4561 deletions(-) delete mode 100644 src/utility/STM32Cube_FW/app_conf.h delete mode 100644 src/utility/STM32Cube_FW/ble_bufsize.h delete mode 100644 src/utility/STM32Cube_FW/hw.h delete mode 100644 src/utility/STM32Cube_FW/hw_ipcc.c delete mode 100644 src/utility/STM32Cube_FW/mbox_def.h delete mode 100644 src/utility/STM32Cube_FW/shci.c delete mode 100644 src/utility/STM32Cube_FW/shci.h delete mode 100644 src/utility/STM32Cube_FW/shci_tl.c delete mode 100644 src/utility/STM32Cube_FW/shci_tl.h delete mode 100644 src/utility/STM32Cube_FW/stm32_wpan_common.h delete mode 100644 src/utility/STM32Cube_FW/stm_list.c delete mode 100644 src/utility/STM32Cube_FW/stm_list.h delete mode 100644 src/utility/STM32Cube_FW/tl.h delete mode 100644 src/utility/STM32Cube_FW/tl_mbox.c diff --git a/src/utility/STM32Cube_FW/app_conf.h b/src/utility/STM32Cube_FW/app_conf.h deleted file mode 100644 index 22c7b5c5..00000000 --- a/src/utility/STM32Cube_FW/app_conf.h +++ /dev/null @@ -1,535 +0,0 @@ -/** - ****************************************************************************** - * File Name : app_conf.h - * Description : Application configuration file for STM32WPAN Middleware. - ****************************************************************************** - * @attention - * - * <h2><center>© Copyright (c) 2020 STMicroelectronics. - * All rights reserved.</center></h2> - * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 - * - ****************************************************************************** - */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef APP_CONF_H -#define APP_CONF_H - -#include "hw.h" -#include "ble_bufsize.h" - - -/****************************************************************************** - * Application Config - ******************************************************************************/ - -/**< generic parameters ******************************************************/ - -/** - * Define Tx Power - */ -#define CFG_TX_POWER (0x18) /* -0.15dBm */ - -/** - * Define Advertising parameters - */ -#define CFG_ADV_BD_ADDRESS (0x7257acd87a6c) -#define CFG_FAST_CONN_ADV_INTERVAL_MIN (0x80) /**< 80ms */ -#define CFG_FAST_CONN_ADV_INTERVAL_MAX (0xa0) /**< 100ms */ -#define CFG_LP_CONN_ADV_INTERVAL_MIN (0x640) /**< 1s */ -#define CFG_LP_CONN_ADV_INTERVAL_MAX (0xfa0) /**< 2.5s */ - -/** - * Define IO Authentication - */ -#define CFG_BONDING_MODE (1) -#define CFG_FIXED_PIN (111111) -#define CFG_USED_FIXED_PIN (0) -#define CFG_ENCRYPTION_KEY_SIZE_MAX (16) -#define CFG_ENCRYPTION_KEY_SIZE_MIN (8) - -/** - * Define IO capabilities - */ -#define CFG_IO_CAPABILITY_DISPLAY_ONLY (0x00) -#define CFG_IO_CAPABILITY_DISPLAY_YES_NO (0x01) -#define CFG_IO_CAPABILITY_KEYBOARD_ONLY (0x02) -#define CFG_IO_CAPABILITY_NO_INPUT_NO_OUTPUT (0x03) -#define CFG_IO_CAPABILITY_KEYBOARD_DISPLAY (0x04) - -#define CFG_IO_CAPABILITY CFG_IO_CAPABILITY_DISPLAY_YES_NO - -/** - * Define MITM modes - */ -#define CFG_MITM_PROTECTION_NOT_REQUIRED (0x00) -#define CFG_MITM_PROTECTION_REQUIRED (0x01) - -#define CFG_MITM_PROTECTION CFG_MITM_PROTECTION_REQUIRED - -/** - * Define Secure Connections Support - */ -#define CFG_SECURE_NOT_SUPPORTED (0x00) -#define CFG_SECURE_OPTIONAL (0x01) -#define CFG_SECURE_MANDATORY (0x02) - -#define CFG_SC_SUPPORT CFG_SECURE_OPTIONAL - -/** - * Define Keypress Notification Support - */ -#define CFG_KEYPRESS_NOT_SUPPORTED (0x00) -#define CFG_KEYPRESS_SUPPORTED (0x01) - -#define CFG_KEYPRESS_NOTIFICATION_SUPPORT CFG_KEYPRESS_NOT_SUPPORTED - -/** - * Numeric Comparison Answers - */ -#define YES (0x01) -#define NO (0x00) - -/** - * Device name configuration for Generic Access Service - */ -#define CFG_GAP_DEVICE_NAME "TEMPLATE" -#define CFG_GAP_DEVICE_NAME_LENGTH (8) - -/** - * Define PHY - */ -#define ALL_PHYS_PREFERENCE 0x00 -#define RX_2M_PREFERRED 0x02 -#define TX_2M_PREFERRED 0x02 -#define TX_1M 0x01 -#define TX_2M 0x02 -#define RX_1M 0x01 -#define RX_2M 0x02 - -/** -* Identity root key used to derive LTK and CSRK -*/ -#define CFG_BLE_IRK {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0} - -/** -* Encryption root key used to derive LTK and CSRK -*/ -#define CFG_BLE_ERK {0xfe,0xdc,0xba,0x09,0x87,0x65,0x43,0x21,0xfe,0xdc,0xba,0x09,0x87,0x65,0x43,0x21} - -/* USER CODE BEGIN Generic_Parameters */ -/** - * SMPS supply - * SMPS not used when Set to 0 - * SMPS used when Set to 1 - */ -#define CFG_USE_SMPS 1 -/* USER CODE END Generic_Parameters */ - -/**< specific parameters */ -/*****************************************************/ - -/** -* AD Element - Group B Feature -*/ -/* LSB - Second Byte */ -#define CFG_FEATURE_OTA_REBOOT (0x20) - -/****************************************************************************** - * BLE Stack - ******************************************************************************/ -/** - * Maximum number of simultaneous connections that the device will support. - * Valid values are from 1 to 8 - */ -#define CFG_BLE_NUM_LINK 8 - -/** - * Maximum number of Services that can be stored in the GATT database. - * Note that the GAP and GATT services are automatically added so this parameter should be 2 plus the number of user services - */ -#define CFG_BLE_NUM_GATT_SERVICES 8 - -/** - * Maximum number of Attributes - * (i.e. the number of characteristic + the number of characteristic values + the number of descriptors, excluding the services) - * that can be stored in the GATT database. - * Note that certain characteristics and relative descriptors are added automatically during device initialization - * so this parameters should be 9 plus the number of user Attributes - */ -#define CFG_BLE_NUM_GATT_ATTRIBUTES 68 - -/** - * Maximum supported ATT_MTU size - */ -#define CFG_BLE_MAX_ATT_MTU (156) - -/** - * Size of the storage area for Attribute values - * This value depends on the number of attributes used by application. In particular the sum of the following quantities (in octets) should be made for each attribute: - * - attribute value length - * - 5, if UUID is 16 bit; 19, if UUID is 128 bit - * - 2, if server configuration descriptor is used - * - 2*DTM_NUM_LINK, if client configuration descriptor is used - * - 2, if extended properties is used - * The total amount of memory needed is the sum of the above quantities for each attribute. - */ -#define CFG_BLE_ATT_VALUE_ARRAY_SIZE (1344) - -/** - * Prepare Write List size in terms of number of packet - */ -//#define CFG_BLE_PREPARE_WRITE_LIST_SIZE BLE_PREP_WRITE_X_ATT(CFG_BLE_MAX_ATT_MTU) -#define CFG_BLE_PREPARE_WRITE_LIST_SIZE (0x3A) - -/** - * Number of allocated memory blocks - */ -//#define CFG_BLE_MBLOCK_COUNT (BLE_MBLOCKS_CALC(CFG_BLE_PREPARE_WRITE_LIST_SIZE, CFG_BLE_MAX_ATT_MTU, CFG_BLE_NUM_LINK)) -#define CFG_BLE_MBLOCK_COUNT (0x79) -/** - * Enable or disable the Extended Packet length feature. Valid values are 0 or 1. - */ -#define CFG_BLE_DATA_LENGTH_EXTENSION 1 - -/** - * Sleep clock accuracy in Slave mode (ppm value) - */ -#define CFG_BLE_SLAVE_SCA 500 - -/** - * Sleep clock accuracy in Master mode - * 0 : 251 ppm to 500 ppm - * 1 : 151 ppm to 250 ppm - * 2 : 101 ppm to 150 ppm - * 3 : 76 ppm to 100 ppm - * 4 : 51 ppm to 75 ppm - * 5 : 31 ppm to 50 ppm - * 6 : 21 ppm to 30 ppm - * 7 : 0 ppm to 20 ppm - */ -#define CFG_BLE_MASTER_SCA 0 - -/** - * Source for the 32 kHz slow speed clock - * 1 : internal RO - * 0 : external crystal ( no calibration ) - */ -#define CFG_BLE_LSE_SOURCE 0 - -/** - * Start up time of the high speed (16 or 32 MHz) crystal oscillator in units of 625/256 us (~2.44 us) - */ -#define CFG_BLE_HSE_STARTUP_TIME 0x148 - -/** - * Maximum duration of the connection event when the device is in Slave mode in units of 625/256 us (~2.44 us) - */ -#define CFG_BLE_MAX_CONN_EVENT_LENGTH ( 0xFFFFFFFF ) - -/** - * Viterbi Mode - * 1 : enabled - * 0 : disabled - */ -#define CFG_BLE_VITERBI_MODE 1 - -/** - * LL Only Mode - * 1 : LL Only - * 0 : LL + Host - */ -#define CFG_BLE_LL_ONLY 1 -/****************************************************************************** - * Transport Layer - ******************************************************************************/ -/** - * Queue length of BLE Event - * This parameter defines the number of asynchronous events that can be stored in the HCI layer before - * being reported to the application. When a command is sent to the BLE core coprocessor, the HCI layer - * is waiting for the event with the Num_HCI_Command_Packets set to 1. The receive queue shall be large - * enough to store all asynchronous events received in between. - * When CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE is set to 27, this allow to store three 255 bytes long asynchronous events - * between the HCI command and its event. - * This parameter depends on the value given to CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE. When the queue size is to small, - * the system may hang if the queue is full with asynchronous events and the HCI layer is still waiting - * for a CC/CS event, In that case, the notification TL_BLE_HCI_ToNot() is called to indicate - * to the application a HCI command did not receive its command event within 30s (Default HCI Timeout). - */ -#define CFG_TLBLE_EVT_QUEUE_LENGTH 5 -/** - * This parameter should be set to fit most events received by the HCI layer. It defines the buffer size of each element - * allocated in the queue of received events and can be used to optimize the amount of RAM allocated by the Memory Manager. - * It should not exceed 255 which is the maximum HCI packet payload size (a greater value is a lost of memory as it will - * never be used) - * It shall be at least 4 to receive the command status event in one frame. - * The default value is set to 27 to allow receiving an event of MTU size in a single buffer. This value maybe reduced - * further depending on the application. - * - */ -#define CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE 255 /**< Set to 255 with the memory manager and the mailbox */ - -#define TL_BLE_EVENT_FRAME_SIZE ( TL_EVT_HDR_SIZE + CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE ) -/****************************************************************************** - * UART interfaces - ******************************************************************************/ - -/** - * Select UART interfaces - */ -#define CFG_DEBUG_TRACE_UART hw_uart1 -#define CFG_CONSOLE_MENU 0 -/****************************************************************************** - * USB interface - ******************************************************************************/ - -/** - * Enable/Disable USB interface - */ -#define CFG_USB_INTERFACE_ENABLE 0 - -/****************************************************************************** - * Low Power - ******************************************************************************/ -/** - * When set to 1, the low power mode is enable - * When set to 0, the device stays in RUN mode - */ -#define CFG_LPM_SUPPORTED 1 - -/****************************************************************************** - * Timer Server - ******************************************************************************/ -/** - * CFG_RTC_WUCKSEL_DIVIDER: This sets the RTCCLK divider to the wakeup timer. - * The higher is the value, the better is the power consumption and the accuracy of the timerserver - * The lower is the value, the finest is the granularity - * - * CFG_RTC_ASYNCH_PRESCALER: This sets the asynchronous prescaler of the RTC. It should as high as possible ( to output - * clock as low as possible) but the output clock should be equal or higher frequency compare to the clock feeding - * the wakeup timer. A lower clock speed would impact the accuracy of the timer server. - * - * CFG_RTC_SYNCH_PRESCALER: This sets the synchronous prescaler of the RTC. - * When the 1Hz calendar clock is required, it shall be sets according to other settings - * When the 1Hz calendar clock is not needed, CFG_RTC_SYNCH_PRESCALER should be set to 0x7FFF (MAX VALUE) - * - * CFG_RTCCLK_DIVIDER_CONF: - * Shall be set to either 0,2,4,8,16 - * When set to either 2,4,8,16, the 1Hhz calendar is supported - * When set to 0, the user sets its own configuration - * - * The following settings are computed with LSI as input to the RTC - */ -#define CFG_RTCCLK_DIVIDER_CONF 0 - -#if (CFG_RTCCLK_DIVIDER_CONF == 0) - /** - * Custom configuration - * It does not support 1Hz calendar - * It divides the RTC CLK by 16 - */ - #define CFG_RTCCLK_DIV (16) - #define CFG_RTC_WUCKSEL_DIVIDER (0) - #define CFG_RTC_ASYNCH_PRESCALER (CFG_RTCCLK_DIV - 1) - #define CFG_RTC_SYNCH_PRESCALER (0x7FFF) - -#else - - #if (CFG_RTCCLK_DIVIDER_CONF == 2) - /** - * It divides the RTC CLK by 2 - */ - #define CFG_RTC_WUCKSEL_DIVIDER (3) - #endif - - #if (CFG_RTCCLK_DIVIDER_CONF == 4) - /** - * It divides the RTC CLK by 4 - */ - #define CFG_RTC_WUCKSEL_DIVIDER (2) - #endif - - #if (CFG_RTCCLK_DIVIDER_CONF == 8) - /** - * It divides the RTC CLK by 8 - */ - #define CFG_RTC_WUCKSEL_DIVIDER (1) - #endif - - #if (CFG_RTCCLK_DIVIDER_CONF == 16) - /** - * It divides the RTC CLK by 16 - */ - #define CFG_RTC_WUCKSEL_DIVIDER (0) - #endif - - #define CFG_RTCCLK_DIV CFG_RTCCLK_DIVIDER_CONF - #define CFG_RTC_ASYNCH_PRESCALER (CFG_RTCCLK_DIV - 1) - #define CFG_RTC_SYNCH_PRESCALER (DIVR( LSE_VALUE, (CFG_RTC_ASYNCH_PRESCALER+1) ) - 1 ) - -#endif - -/** tick timer value in us */ -#define CFG_TS_TICK_VAL DIVR( (CFG_RTCCLK_DIV * 1000000), LSE_VALUE ) - -typedef enum { - CFG_TIM_PROC_ID_ISR, -} CFG_TimProcID_t; - -/****************************************************************************** - * Debug - ******************************************************************************/ -/** - * When set, this resets some hw resources to set the device in the same state than the power up - * The FW resets only register that may prevent the FW to run properly - * - * This shall be set to 0 in a final product - * - */ -#define CFG_HW_RESET_BY_FW 1 - -/** - * keep debugger enabled while in any low power mode when set to 1 - * should be set to 0 in production - */ -#define CFG_DEBUGGER_SUPPORTED 0 - -/** - * When set to 1, the traces are enabled in the BLE services - */ -#define CFG_DEBUG_BLE_TRACE 0 - -/** - * Enable or Disable traces in application - */ -#define CFG_DEBUG_APP_TRACE 0 - -#if (CFG_DEBUG_APP_TRACE != 0) - #define APP_DBG_MSG PRINT_MESG_DBG -#else - #define APP_DBG_MSG PRINT_NO_MESG -#endif - -#if ( (CFG_DEBUG_BLE_TRACE != 0) || (CFG_DEBUG_APP_TRACE != 0) ) - #define CFG_DEBUG_TRACE 1 -#endif - -#if (CFG_DEBUG_TRACE != 0) - #undef CFG_LPM_SUPPORTED - #undef CFG_DEBUGGER_SUPPORTED - #define CFG_LPM_SUPPORTED 0 - #define CFG_DEBUGGER_SUPPORTED 1 -#endif - -/** - * When CFG_DEBUG_TRACE_FULL is set to 1, the trace are output with the API name, the file name and the line number - * When CFG_DEBUG_TRACE_LIGHT is set to 1, only the debug message is output - * - * When both are set to 0, no trace are output - * When both are set to 1, CFG_DEBUG_TRACE_FULL is selected - */ -#define CFG_DEBUG_TRACE_LIGHT 0 -#define CFG_DEBUG_TRACE_FULL 0 - -#if (( CFG_DEBUG_TRACE != 0 ) && ( CFG_DEBUG_TRACE_LIGHT == 0 ) && (CFG_DEBUG_TRACE_FULL == 0)) - #undef CFG_DEBUG_TRACE_FULL - #undef CFG_DEBUG_TRACE_LIGHT - #define CFG_DEBUG_TRACE_FULL 0 - #define CFG_DEBUG_TRACE_LIGHT 1 -#endif - -#if ( CFG_DEBUG_TRACE == 0 ) - #undef CFG_DEBUG_TRACE_FULL - #undef CFG_DEBUG_TRACE_LIGHT - #define CFG_DEBUG_TRACE_FULL 0 - #define CFG_DEBUG_TRACE_LIGHT 0 -#endif - -/** - * When not set, the traces is looping on sending the trace over UART - */ -#define DBG_TRACE_USE_CIRCULAR_QUEUE 1 - -/** - * max buffer Size to queue data traces and max data trace allowed. - * Only Used if DBG_TRACE_USE_CIRCULAR_QUEUE is defined - */ -#define DBG_TRACE_MSG_QUEUE_SIZE 4096 -#define MAX_DBG_TRACE_MSG_SIZE 1024 - -/* USER CODE BEGIN Defines */ -#define CFG_LED_SUPPORTED 0 -#define CFG_BUTTON_SUPPORTED 1 -/* USER CODE END Defines */ - -/****************************************************************************** - * FreeRTOS - ******************************************************************************/ -#define CFG_SHCI_USER_EVT_PROCESS_NAME "SHCI_USER_EVT_PROCESS" -#define CFG_SHCI_USER_EVT_PROCESS_ATTR_BITS (0) -#define CFG_SHCI_USER_EVT_PROCESS_CB_MEM (0) -#define CFG_SHCI_USER_EVT_PROCESS_CB_SIZE (0) -#define CFG_SHCI_USER_EVT_PROCESS_STACK_MEM (0) -#define CFG_SHCI_USER_EVT_PROCESS_PRIORITY osPriorityNone -#define CFG_SHCI_USER_EVT_PROCESS_STACK_SIZE (128 * 7) - -#define CFG_HCI_USER_EVT_PROCESS_NAME "HCI_USER_EVT_PROCESS" -#define CFG_HCI_USER_EVT_PROCESS_ATTR_BITS (0) -#define CFG_HCI_USER_EVT_PROCESS_CB_MEM (0) -#define CFG_HCI_USER_EVT_PROCESS_CB_SIZE (0) -#define CFG_HCI_USER_EVT_PROCESS_STACK_MEM (0) -#define CFG_HCI_USER_EVT_PROCESS_PRIORITY osPriorityNone -#define CFG_HCI_USER_EVT_PROCESS_STACK_SIZE (128 * 8) - -#define CFG_ADV_UPDATE_PROCESS_NAME "ADV_UPDATE_PROCESS" -#define CFG_ADV_UPDATE_PROCESS_ATTR_BITS (0) -#define CFG_ADV_UPDATE_PROCESS_CB_MEM (0) -#define CFG_ADV_UPDATE_PROCESS_CB_SIZE (0) -#define CFG_ADV_UPDATE_PROCESS_STACK_MEM (0) -#define CFG_ADV_UPDATE_PROCESS_PRIORITY osPriorityNone -#define CFG_ADV_UPDATE_PROCESS_STACK_SIZE (128 * 6) - -#define CFG_HRS_PROCESS_NAME "HRS_PROCESS" -#define CFG_HRS_PROCESS_ATTR_BITS (0) -#define CFG_HRS_PROCESS_CB_MEM (0) -#define CFG_HRS_PROCESS_CB_SIZE (0) -#define CFG_HRS_PROCESS_STACK_MEM (0) -#define CFG_HRS_PROCESS_PRIORITY osPriorityNone -#define CFG_HRS_PROCESS_STACK_SIZE (128 * 5) - -/* USER CODE BEGIN FreeRTOS_Defines */ -#define PUSH_BUTTON_SW1_EXTI_IRQHandler EXTI4_IRQHandler -#define PUSH_BUTTON_SW2_EXTI_IRQHandler EXTI0_IRQHandler -#define PUSH_BUTTON_SW3_EXTI_IRQHandler EXTI1_IRQHandler -/* USER CODE END FreeRTOS_Defines */ - -/****************************************************************************** - * LOW POWER - ******************************************************************************/ -/** - * Supported requester to the MCU Low Power Manager - can be increased up to 32 - * It lists a bit mapping of all user of the Low Power Manager - */ -typedef enum { - CFG_LPM_APP, - CFG_LPM_APP_BLE, - /* USER CODE BEGIN CFG_LPM_Id_t */ - - /* USER CODE END CFG_LPM_Id_t */ -} CFG_LPM_Id_t; - -/****************************************************************************** - * OTP manager - ******************************************************************************/ -#define CFG_OTP_BASE_ADDRESS OTP_AREA_BASE - -#define CFG_OTP_END_ADRESS OTP_AREA_END_ADDR - -#endif /*APP_CONF_H */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/src/utility/STM32Cube_FW/ble_bufsize.h b/src/utility/STM32Cube_FW/ble_bufsize.h deleted file mode 100644 index 2961cd99..00000000 --- a/src/utility/STM32Cube_FW/ble_bufsize.h +++ /dev/null @@ -1,161 +0,0 @@ -/***************************************************************************** - * @file ble_bufsize.h - * @author MCD Application Team - * @brief Definition of BLE stack buffers size - ***************************************************************************** - * @attention - * - * <h2><center>© Copyright (c) 2019 STMicroelectronics. - * All rights reserved.</center></h2> - * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 - * - ***************************************************************************** - */ - -#ifndef BLE_BUFSIZE_H__ -#define BLE_BUFSIZE_H__ - - -/* - * BLE_DEFAULT_ATT_MTU: minimum MTU value that GATT must support. - */ -#define BLE_DEFAULT_ATT_MTU 23 - -/* - * BLE_DEFAULT_MAX_ATT_MTU: maximum supported ATT MTU size. - */ -#define BLE_DEFAULT_MAX_ATT_MTU 158 - -/* - * BLE_DEFAULT_MAX_ATT_SIZE: maximum attribute size. - */ -#define BLE_DEFAULT_MAX_ATT_SIZE 512 - -/* - * BLE_PREP_WRITE_X_ATT: compute how many Prepare Write Request are needed to - * write a characteristic with size 'max_att' when the used ATT_MTU value is - * equal to BLE_DEFAULT_ATT_MTU (23). - */ -#define BLE_PREP_WRITE_X_ATT(max_att) \ - (DIVC(max_att, BLE_DEFAULT_ATT_MTU - 5) * 2) - -/* - * BLE_DEFAULT_PREP_WRITE_LIST_SIZE: default minimum Prepare Write List size. - */ -#define BLE_DEFAULT_PREP_WRITE_LIST_SIZE \ - BLE_PREP_WRITE_X_ATT(BLE_DEFAULT_MAX_ATT_SIZE) - -/* - * BLE_MEM_BLOCK_X_MTU: compute how many memory blocks are needed to compose - * an ATT packet with ATT_MTU=mtu. - */ -#define BLE_MEM_BLOCK_SIZE 32 - -#define BLE_MEM_BLOCK_X_TX(mtu) \ - (DIVC((mtu) + 4U, BLE_MEM_BLOCK_SIZE) + 1U) - -#define BLE_MEM_BLOCK_X_RX(mtu, n_link) \ - ((DIVC((mtu) + 4U, BLE_MEM_BLOCK_SIZE) + 2U) * (n_link) + 1) - -#define BLE_MEM_BLOCK_X_MTU(mtu, n_link) \ - (BLE_MEM_BLOCK_X_TX(mtu) + BLE_MEM_BLOCK_X_RX(mtu, n_link)) - -/* - * BLE_MBLOCKS_SECURE_CONNECTIONS: minimum number of blocks required for - * secure connections - */ -#define BLE_MBLOCKS_SECURE_CONNECTIONS 4 - -/* - * BLE_MBLOCKS_CALC: minimum number of buffers needed by the stack. - * This is the minimum racomanded value and depends on: - * - pw: size of Prepare Write List - * - mtu: ATT_MTU size - * - n_link: maximum number of simultaneous connections - */ -#define BLE_MBLOCKS_CALC(pw, mtu, n_link) \ - ((pw) + MAX(BLE_MEM_BLOCK_X_MTU(mtu, n_link), \ - BLE_MBLOCKS_SECURE_CONNECTIONS)) - -/* - * BLE_DEFAULT_MBLOCKS_COUNT: default memory blocks count - */ -#define BLE_DEFAULT_MBLOCKS_COUNT(n_link) \ - BLE_MBLOCKS_CALC(BLE_DEFAULT_PREP_WRITE_LIST_SIZE, \ - BLE_DEFAULT_MAX_ATT_MTU, n_link) - -/* - * BLE_FIXED_BUFFER_SIZE_BYTES: - * A part of the RAM, is dynamically allocated by initializing all the pointers - * defined in a global context variable "mem_alloc_ctx_p". - * This initialization is made in the Dynamic_allocator functions, which - * assign a portion of RAM given by the external application to the above - * mentioned "global pointers". - * - * The size of this Dynamic RAM is made of 2 main components: - * - a part that is parameters-dependent (num of links, GATT buffers, ...), - * and which value is defined by the following macro; - * - a part, that may be considered "fixed", i.e. independent from the above - * mentioned parameters. -*/ -#if (SLAVE_ONLY == 0) && (LL_ONLY == 0) - #define BLE_FIXED_BUFFER_SIZE_BYTES 6960 /* Full stack */ -#elif SLAVE_ONLY == 0 - #define BLE_FIXED_BUFFER_SIZE_BYTES 6256 /* LL only */ -#else - #define BLE_FIXED_BUFFER_SIZE_BYTES 6696 /* Slave only */ -#endif - -/* - * BLE_PER_LINK_SIZE_BYTES: additional memory size used per link - */ -#if (SLAVE_ONLY == 0) && (LL_ONLY == 0) - #define BLE_PER_LINK_SIZE_BYTES 380 /* Full stack */ -#elif SLAVE_ONLY == 0 - #define BLE_PER_LINK_SIZE_BYTES 196 /* LL only */ -#else - #define BLE_PER_LINK_SIZE_BYTES 332 /* Slave only */ -#endif - -/* - * BLE_TOTAL_BUFFER_SIZE: this macro returns the amount of memory, in bytes, - * needed for the storage of data structures (except GATT database elements) - * whose size depends on the number of supported connections. - * - * @param num_links: Maximum number of simultaneous connections that the device - * will support. Valid values are from 1 to 8. - * - * @param mblocks_count: Number of memory blocks allocated for packets. - */ -#define BLE_TOTAL_BUFFER_SIZE(n_link, mblocks_count) \ - (BLE_FIXED_BUFFER_SIZE_BYTES + \ - (BLE_PER_LINK_SIZE_BYTES * (n_link)) + \ - ((BLE_MEM_BLOCK_SIZE + 12) * (mblocks_count))) - -/* - * BLE_TOTAL_BUFFER_SIZE_GATT: this macro returns the amount of memory, - * in bytes, needed for the storage of GATT database elements. - * - * @param num_gatt_attributes: Maximum number of Attributes (i.e. the number - * of characteristic + the number of characteristic values + the number of - * descriptors, excluding the services) that can be stored in the GATT - * database. Note that certain characteristics and relative descriptors are - * added automatically during device initialization so this parameters should - * be 9 plus the number of user Attributes - * - * @param num_gatt_services: Maximum number of Services that can be stored in - * the GATT database. Note that the GAP and GATT services are automatically - * added so this parameter should be 2 plus the number of user services - * - * @param att_value_array_size: Size of the storage area for Attribute values. - */ -#define BLE_TOTAL_BUFFER_SIZE_GATT(num_gatt_attributes, num_gatt_services, att_value_array_size) \ - (((((att_value_array_size) - 1) | 3) + 1) + \ - (40 * (num_gatt_attributes)) + (48 * (num_gatt_services))) - - -#endif /* ! BLE_BUFSIZE_H__ */ diff --git a/src/utility/STM32Cube_FW/hw.h b/src/utility/STM32Cube_FW/hw.h deleted file mode 100644 index 09b12aff..00000000 --- a/src/utility/STM32Cube_FW/hw.h +++ /dev/null @@ -1,97 +0,0 @@ -/** - ****************************************************************************** - * @file hw.h - * @author MCD Application Team - * @brief Hardware - ****************************************************************************** - * @attention - * - * <h2><center>© Copyright (c) 2019 STMicroelectronics. - * All rights reserved.</center></h2> - * - * This software component is licensed by ST under BSD 3-Clause license, - * the "License"; You may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * opensource.org/licenses/BSD-3-Clause - * - ****************************************************************************** - */ - - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __HW_H -#define __HW_H - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "stm32_def.h" -#include "stm32wbxx_ll_bus.h" -#include "stm32wbxx_ll_exti.h" -#include "stm32wbxx_ll_system.h" -#include "stm32wbxx_ll_rcc.h" -#include "stm32wbxx_ll_ipcc.h" -#include "stm32wbxx_ll_cortex.h" -#include "stm32wbxx_ll_utils.h" -#include "stm32wbxx_ll_pwr.h" - -/****************************************************************************** - * HW IPCC - ******************************************************************************/ -void HW_IPCC_Enable(void); -void HW_IPCC_Init(void); - -void HW_IPCC_BLE_Init(void); -void HW_IPCC_BLE_SendCmd(void); -void HW_IPCC_MM_SendFreeBuf(void (*cb)(void)); -void HW_IPCC_BLE_RxEvtNot(void); -void HW_IPCC_BLE_SendAclData(void); -void HW_IPCC_BLE_AclDataAckNot(void); - -void HW_IPCC_SYS_Init(void); -void HW_IPCC_SYS_SendCmd(void); -void HW_IPCC_SYS_CmdEvtNot(void); -void HW_IPCC_SYS_EvtNot(void); - -void HW_IPCC_THREAD_Init(void); -void HW_IPCC_OT_SendCmd(void); -void HW_IPCC_CLI_SendCmd(void); -void HW_IPCC_THREAD_SendAck(void); -void HW_IPCC_OT_CmdEvtNot(void); -void HW_IPCC_CLI_CmdEvtNot(void); -void HW_IPCC_THREAD_EvtNot(void); -void HW_IPCC_THREAD_CliSendAck(void); -void HW_IPCC_THREAD_CliEvtNot(void); - - -void HW_IPCC_LLDTESTS_Init(void); -void HW_IPCC_LLDTESTS_SendCliCmd(void); -void HW_IPCC_LLDTESTS_ReceiveCliRsp(void); -void HW_IPCC_LLDTESTS_SendCliRspAck(void); -void HW_IPCC_LLDTESTS_ReceiveM0Cmd(void); -void HW_IPCC_LLDTESTS_SendM0CmdAck(void); - - -void HW_IPCC_LLD_BLE_Init(void); -void HW_IPCC_LLD_BLE_SendCliCmd(void); -void HW_IPCC_LLD_BLE_ReceiveCliRsp(void); -void HW_IPCC_LLD_BLE_SendCliRspAck(void); -void HW_IPCC_LLD_BLE_ReceiveM0Cmd(void); -void HW_IPCC_LLD_BLE_SendM0CmdAck(void); -void HW_IPCC_LLD_BLE_SendCmd(void); -void HW_IPCC_LLD_BLE_ReceiveRsp(void); -void HW_IPCC_LLD_BLE_SendRspAck(void); - - -void HW_IPCC_TRACES_Init(void); -void HW_IPCC_TRACES_EvtNot(void); - -#ifdef __cplusplus -} -#endif - -#endif /*__HW_H */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/src/utility/STM32Cube_FW/hw_ipcc.c b/src/utility/STM32Cube_FW/hw_ipcc.c deleted file mode 100644 index dbeb3eeb..00000000 --- a/src/utility/STM32Cube_FW/hw_ipcc.c +++ /dev/null @@ -1,342 +0,0 @@ -/** - ****************************************************************************** - * File Name : Target/hw_ipcc.c - * Description : Hardware IPCC source file for STM32WPAN Middleware. - * - ****************************************************************************** - * @attention - * - * <h2><center>© Copyright (c) 2020 STMicroelectronics. - * All rights reserved.</center></h2> - * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 - * - ****************************************************************************** - */ -#if defined(STM32WBxx) -/* Includes ------------------------------------------------------------------*/ -#include "hw.h" -#include "mbox_def.h" - -/* Global variables ---------------------------------------------------------*/ -/* Private defines -----------------------------------------------------------*/ -#define HW_IPCC_TX_PENDING( channel ) ( !(LL_C1_IPCC_IsActiveFlag_CHx( IPCC, channel )) ) && (((~(IPCC->C1MR)) & (channel << 16U))) -#define HW_IPCC_RX_PENDING( channel ) (LL_C2_IPCC_IsActiveFlag_CHx( IPCC, channel )) && (((~(IPCC->C1MR)) & (channel << 0U))) - -/* Private macros ------------------------------------------------------------*/ -/* Private typedef -----------------------------------------------------------*/ -/* Private variables ---------------------------------------------------------*/ -static void (*FreeBufCb)(void); - -/* Private function prototypes -----------------------------------------------*/ -static void HW_IPCC_BLE_EvtHandler(void); -static void HW_IPCC_BLE_AclDataEvtHandler(void); -static void HW_IPCC_MM_FreeBufHandler(void); -static void HW_IPCC_SYS_CmdEvtHandler(void); -static void HW_IPCC_SYS_EvtHandler(void); -static void HW_IPCC_TRACES_EvtHandler(void); - -#ifdef THREAD_WB - static void HW_IPCC_OT_CmdEvtHandler(void); - static void HW_IPCC_THREAD_NotEvtHandler(void); - static void HW_IPCC_THREAD_CliNotEvtHandler(void); -#endif - -/* Public function definition -----------------------------------------------*/ - -/****************************************************************************** - * INTERRUPT HANDLER - ******************************************************************************/ - -void IPCC_C1_RX_IRQHandler(void) -{ - if (HW_IPCC_RX_PENDING(HW_IPCC_SYSTEM_EVENT_CHANNEL)) { - HW_IPCC_SYS_EvtHandler(); - } -#ifdef THREAD_WB - else if (HW_IPCC_RX_PENDING(HW_IPCC_THREAD_NOTIFICATION_ACK_CHANNEL)) { - HW_IPCC_THREAD_NotEvtHandler(); - } else if (HW_IPCC_RX_PENDING(HW_IPCC_THREAD_CLI_NOTIFICATION_ACK_CHANNEL)) { - HW_IPCC_THREAD_CliNotEvtHandler(); - } -#endif /* THREAD_WB */ - else if (HW_IPCC_RX_PENDING(HW_IPCC_BLE_EVENT_CHANNEL)) { - HW_IPCC_BLE_EvtHandler(); - } else if (HW_IPCC_RX_PENDING(HW_IPCC_TRACES_CHANNEL)) { - HW_IPCC_TRACES_EvtHandler(); - } -} - -void IPCC_C1_TX_IRQHandler(void) -{ - if (HW_IPCC_TX_PENDING(HW_IPCC_SYSTEM_CMD_RSP_CHANNEL)) { - HW_IPCC_SYS_CmdEvtHandler(); - } -#ifdef THREAD_WB - else if (HW_IPCC_TX_PENDING(HW_IPCC_THREAD_OT_CMD_RSP_CHANNEL)) { - HW_IPCC_OT_CmdEvtHandler(); - } -#endif /* THREAD_WB */ - else if (HW_IPCC_TX_PENDING(HW_IPCC_SYSTEM_CMD_RSP_CHANNEL)) { - HW_IPCC_SYS_CmdEvtHandler(); - } else if (HW_IPCC_TX_PENDING(HW_IPCC_MM_RELEASE_BUFFER_CHANNEL)) { - HW_IPCC_MM_FreeBufHandler(); - } else if (HW_IPCC_TX_PENDING(HW_IPCC_HCI_ACL_DATA_CHANNEL)) { - HW_IPCC_BLE_AclDataEvtHandler(); - } -} - -/****************************************************************************** - * GENERAL - ******************************************************************************/ -void HW_IPCC_Enable(void) -{ - /** - * When the device is out of standby, it is required to use the EXTI mechanism to wakeup CPU2 - */ - LL_C2_EXTI_EnableEvent_32_63(LL_EXTI_LINE_41); - LL_EXTI_EnableRisingTrig_32_63(LL_EXTI_LINE_41); - - /** - * In case the SBSFU is implemented, it may have already set the C2BOOT bit to startup the CPU2. - * In that case, to keep the mechanism transparent to the user application, it shall call the system command - * SHCI_C2_Reinit( ) before jumping to the application. - * When the CPU2 receives that command, it waits for its event input to be set to restart the CPU2 firmware. - * This is required because once C2BOOT has been set once, a clear/set on C2BOOT has no effect. - * When SHCI_C2_Reinit( ) is not called, generating an event to the CPU2 does not have any effect - * So, by default, the application shall both set the event flag and set the C2BOOT bit. - */ - __SEV(); /* Set the internal event flag and send an event to the CPU2 */ - __WFE(); /* Clear the internal event flag */ - LL_PWR_EnableBootC2(); - - return; -} - -void HW_IPCC_Init(void) -{ - LL_AHB3_GRP1_EnableClock(LL_AHB3_GRP1_PERIPH_IPCC); - - LL_C1_IPCC_EnableIT_RXO(IPCC); - LL_C1_IPCC_EnableIT_TXF(IPCC); - - HAL_NVIC_EnableIRQ(IPCC_C1_RX_IRQn); - HAL_NVIC_EnableIRQ(IPCC_C1_TX_IRQn); - - return; -} - -/****************************************************************************** - * BLE - ******************************************************************************/ -void HW_IPCC_BLE_Init(void) -{ - LL_C1_IPCC_EnableReceiveChannel(IPCC, HW_IPCC_BLE_EVENT_CHANNEL); - - return; -} - -void HW_IPCC_BLE_SendCmd(void) -{ - LL_C1_IPCC_SetFlag_CHx(IPCC, HW_IPCC_BLE_CMD_CHANNEL); - - return; -} - -static void HW_IPCC_BLE_EvtHandler(void) -{ - HW_IPCC_BLE_RxEvtNot(); - - LL_C1_IPCC_ClearFlag_CHx(IPCC, HW_IPCC_BLE_EVENT_CHANNEL); - - return; -} - -void HW_IPCC_BLE_SendAclData(void) -{ - LL_C1_IPCC_SetFlag_CHx(IPCC, HW_IPCC_HCI_ACL_DATA_CHANNEL); - LL_C1_IPCC_EnableTransmitChannel(IPCC, HW_IPCC_HCI_ACL_DATA_CHANNEL); - - return; -} - -static void HW_IPCC_BLE_AclDataEvtHandler(void) -{ - LL_C1_IPCC_DisableTransmitChannel(IPCC, HW_IPCC_HCI_ACL_DATA_CHANNEL); - - HW_IPCC_BLE_AclDataAckNot(); - - return; -} - -__WEAK void HW_IPCC_BLE_AclDataAckNot(void) {}; -__WEAK void HW_IPCC_BLE_RxEvtNot(void) {}; - -/****************************************************************************** - * SYSTEM - ******************************************************************************/ -void HW_IPCC_SYS_Init(void) -{ - LL_C1_IPCC_EnableReceiveChannel(IPCC, HW_IPCC_SYSTEM_EVENT_CHANNEL); - - return; -} - -void HW_IPCC_SYS_SendCmd(void) -{ - LL_C1_IPCC_SetFlag_CHx(IPCC, HW_IPCC_SYSTEM_CMD_RSP_CHANNEL); - LL_C1_IPCC_EnableTransmitChannel(IPCC, HW_IPCC_SYSTEM_CMD_RSP_CHANNEL); - - return; -} - -static void HW_IPCC_SYS_CmdEvtHandler(void) -{ - LL_C1_IPCC_DisableTransmitChannel(IPCC, HW_IPCC_SYSTEM_CMD_RSP_CHANNEL); - - HW_IPCC_SYS_CmdEvtNot(); - - return; -} - -static void HW_IPCC_SYS_EvtHandler(void) -{ - HW_IPCC_SYS_EvtNot(); - - LL_C1_IPCC_ClearFlag_CHx(IPCC, HW_IPCC_SYSTEM_EVENT_CHANNEL); - - return; -} - -__WEAK void HW_IPCC_SYS_CmdEvtNot(void) {}; -__WEAK void HW_IPCC_SYS_EvtNot(void) {}; - -/****************************************************************************** - * THREAD - ******************************************************************************/ -#ifdef THREAD_WB -void HW_IPCC_THREAD_Init(void) -{ - LL_C1_IPCC_EnableReceiveChannel(IPCC, HW_IPCC_THREAD_NOTIFICATION_ACK_CHANNEL); - LL_C1_IPCC_EnableReceiveChannel(IPCC, HW_IPCC_THREAD_CLI_NOTIFICATION_ACK_CHANNEL); - - return; -} - -void HW_IPCC_OT_SendCmd(void) -{ - LL_C1_IPCC_SetFlag_CHx(IPCC, HW_IPCC_THREAD_OT_CMD_RSP_CHANNEL); - LL_C1_IPCC_EnableTransmitChannel(IPCC, HW_IPCC_THREAD_OT_CMD_RSP_CHANNEL); - - return; -} - -void HW_IPCC_CLI_SendCmd(void) -{ - LL_C1_IPCC_SetFlag_CHx(IPCC, HW_IPCC_THREAD_CLI_CMD_CHANNEL); - - return; -} - -void HW_IPCC_THREAD_SendAck(void) -{ - LL_C1_IPCC_ClearFlag_CHx(IPCC, HW_IPCC_THREAD_NOTIFICATION_ACK_CHANNEL); - LL_C1_IPCC_EnableReceiveChannel(IPCC, HW_IPCC_THREAD_NOTIFICATION_ACK_CHANNEL); - - return; -} - -void HW_IPCC_THREAD_CliSendAck(void) -{ - LL_C1_IPCC_ClearFlag_CHx(IPCC, HW_IPCC_THREAD_CLI_NOTIFICATION_ACK_CHANNEL); - LL_C1_IPCC_EnableReceiveChannel(IPCC, HW_IPCC_THREAD_CLI_NOTIFICATION_ACK_CHANNEL); - - return; -} - -static void HW_IPCC_OT_CmdEvtHandler(void) -{ - LL_C1_IPCC_DisableTransmitChannel(IPCC, HW_IPCC_THREAD_OT_CMD_RSP_CHANNEL); - - HW_IPCC_OT_CmdEvtNot(); - - return; -} - -static void HW_IPCC_THREAD_NotEvtHandler(void) -{ - LL_C1_IPCC_DisableReceiveChannel(IPCC, HW_IPCC_THREAD_NOTIFICATION_ACK_CHANNEL); - - HW_IPCC_THREAD_EvtNot(); - - return; -} - -static void HW_IPCC_THREAD_CliNotEvtHandler(void) -{ - LL_C1_IPCC_DisableReceiveChannel(IPCC, HW_IPCC_THREAD_CLI_NOTIFICATION_ACK_CHANNEL); - - HW_IPCC_THREAD_CliEvtNot(); - - return; -} - -__WEAK void HW_IPCC_OT_CmdEvtNot(void) {}; -__WEAK void HW_IPCC_CLI_CmdEvtNot(void) {}; -__WEAK void HW_IPCC_THREAD_EvtNot(void) {}; - -#endif /* THREAD_WB */ - -/****************************************************************************** - * MEMORY MANAGER - ******************************************************************************/ -void HW_IPCC_MM_SendFreeBuf(void (*cb)(void)) -{ - if (LL_C1_IPCC_IsActiveFlag_CHx(IPCC, HW_IPCC_MM_RELEASE_BUFFER_CHANNEL)) { - FreeBufCb = cb; - LL_C1_IPCC_EnableTransmitChannel(IPCC, HW_IPCC_MM_RELEASE_BUFFER_CHANNEL); - } else { - cb(); - - LL_C1_IPCC_SetFlag_CHx(IPCC, HW_IPCC_MM_RELEASE_BUFFER_CHANNEL); - } - - return; -} - -static void HW_IPCC_MM_FreeBufHandler(void) -{ - LL_C1_IPCC_DisableTransmitChannel(IPCC, HW_IPCC_MM_RELEASE_BUFFER_CHANNEL); - - FreeBufCb(); - - LL_C1_IPCC_SetFlag_CHx(IPCC, HW_IPCC_MM_RELEASE_BUFFER_CHANNEL); - - return; -} - -/****************************************************************************** - * TRACES - ******************************************************************************/ -void HW_IPCC_TRACES_Init(void) -{ - LL_C1_IPCC_EnableReceiveChannel(IPCC, HW_IPCC_TRACES_CHANNEL); - - return; -} - -static void HW_IPCC_TRACES_EvtHandler(void) -{ - HW_IPCC_TRACES_EvtNot(); - - LL_C1_IPCC_ClearFlag_CHx(IPCC, HW_IPCC_TRACES_CHANNEL); - - return; -} - -__WEAK void HW_IPCC_TRACES_EvtNot(void) {}; -#endif /* STM32WBxx */ -/******************* (C) COPYRIGHT 2019 STMicroelectronics *****END OF FILE****/ diff --git a/src/utility/STM32Cube_FW/mbox_def.h b/src/utility/STM32Cube_FW/mbox_def.h deleted file mode 100644 index d5a7d46b..00000000 --- a/src/utility/STM32Cube_FW/mbox_def.h +++ /dev/null @@ -1,212 +0,0 @@ -/** - ****************************************************************************** - * @file mbox_def.h - * @author MCD Application Team - * @brief Mailbox definition - ****************************************************************************** - * @attention - * - * <h2><center>© Copyright (c) 2019 STMicroelectronics. - * All rights reserved.</center></h2> - * - * This software component is licensed by ST under BSD 3-Clause license, - * the "License"; You may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * opensource.org/licenses/BSD-3-Clause - * - ****************************************************************************** - */ - - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __MBOX_H -#define __MBOX_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include "stm32_wpan_common.h" - -/** - * This file shall be identical between the CPU1 and the CPU2 - */ - -/** - ********************************************************************************* - * TABLES - ********************************************************************************* - */ - -/** - * Version - * [0:3] = Build - 0: Untracked - 15:Released - x: Tracked version - * [4:7] = branch - 0: Mass Market - x: ... - * [8:15] = Subversion - * [16:23] = Version minor - * [24:31] = Version major - * - * Memory Size - * [0:7] = Flash ( Number of 4k sector) - * [8:15] = Reserved ( Shall be set to 0 - may be used as flash extension ) - * [16:23] = SRAM2b ( Number of 1k sector) - * [24:31] = SRAM2a ( Number of 1k sector) - */ -typedef PACKED_STRUCT { - uint32_t Version; -} MB_SafeBootInfoTable_t; - -typedef PACKED_STRUCT { - uint32_t Version; - uint32_t MemorySize; - uint32_t FusInfo; -} MB_FusInfoTable_t; - -typedef PACKED_STRUCT { - uint32_t Version; - uint32_t MemorySize; - uint32_t InfoStack; - uint32_t Reserved; -} MB_WirelessFwInfoTable_t; - -typedef struct { - MB_SafeBootInfoTable_t SafeBootInfoTable; - MB_FusInfoTable_t FusInfoTable; - MB_WirelessFwInfoTable_t WirelessFwInfoTable; -} MB_DeviceInfoTable_t; - -typedef struct { - uint8_t *pcmd_buffer; - uint8_t *pcs_buffer; - uint8_t *pevt_queue; - uint8_t *phci_acl_data_buffer; -} MB_BleTable_t; - -typedef struct { - uint8_t *notack_buffer; - uint8_t *clicmdrsp_buffer; - uint8_t *otcmdrsp_buffer; -} MB_ThreadTable_t; - -typedef struct { - uint8_t *clicmdrsp_buffer; - uint8_t *m0cmd_buffer; -} MB_LldTestsTable_t; - -typedef struct { - uint8_t *cmdrsp_buffer; - uint8_t *m0cmd_buffer; -} MB_LldBleTable_t; - -/** - * msg - * [0:7] = cmd/evt - * [8:31] = Reserved - */ -typedef struct { - uint8_t *pcmd_buffer; - uint8_t *sys_queue; -} MB_SysTable_t; - -typedef struct { - uint8_t *spare_ble_buffer; - uint8_t *spare_sys_buffer; - uint8_t *blepool; - uint32_t blepoolsize; - uint8_t *pevt_free_buffer_queue; - uint8_t *traces_evt_pool; - uint32_t tracespoolsize; -} MB_MemManagerTable_t; - -typedef struct { - uint8_t *traces_queue; -} MB_TracesTable_t; - -typedef struct { - MB_DeviceInfoTable_t *p_device_info_table; - MB_BleTable_t *p_ble_table; - MB_ThreadTable_t *p_thread_table; - MB_SysTable_t *p_sys_table; - MB_MemManagerTable_t *p_mem_manager_table; - MB_TracesTable_t *p_traces_table; - MB_LldTestsTable_t *p_lld_tests_table; - MB_LldBleTable_t *p_lld_ble_table; -} MB_RefTable_t; - -#ifdef __cplusplus -} -#endif - -/** - ********************************************************************************* - * IPCC CHANNELS - ********************************************************************************* - */ - -/* CPU1 CPU2 - * | (SYSTEM) | - * |----HW_IPCC_SYSTEM_CMD_RSP_CHANNEL-------------->| - * | | - * |<---HW_IPCC_SYSTEM_EVENT_CHANNEL-----------------| - * | | - * | (THREAD) | - * |----HW_IPCC_THREAD_OT_CMD_RSP_CHANNEL----------->| - * | | - * |----HW_IPCC_THREAD_CLI_CMD_CHANNEL-------------->| - * | | - * |<---HW_IPCC_THREAD_NOTIFICATION_ACK_CHANNEL------| - * | | - * |<---HW_IPCC_THREAD_CLI_NOTIFICATION_ACK_CHANNEL--| - * | | - * | (BLE) | - * |----HW_IPCC_BLE_CMD_CHANNEL--------------------->| - * | | - * |----HW_IPCC_HCI_ACL_DATA_CHANNEL---------------->| - * | | - * |<---HW_IPCC_BLE_EVENT_CHANNEL--------------------| - * | | - * | (LLD BLE) | - * |----HW_IPCC_LLD_BLE_CMD_CHANNEL----------------->| - * | | - * |<---HW_IPCC_LLD_BLE_RSP_CHANNEL------------------| - * | | - * |<---HW_IPCC_LLD_BLE_M0_CMD_CHANNEL---------------| - * | | - * | (BUFFER) | - * |----HW_IPCC_MM_RELEASE_BUFFER_CHANNE------------>| - * | | - * | (TRACE) | - * |<----HW_IPCC_TRACES_CHANNEL----------------------| - * | | - * - * - * - */ - - - -/** CPU1 */ -#define HW_IPCC_BLE_CMD_CHANNEL LL_IPCC_CHANNEL_1 -#define HW_IPCC_SYSTEM_CMD_RSP_CHANNEL LL_IPCC_CHANNEL_2 -#define HW_IPCC_THREAD_OT_CMD_RSP_CHANNEL LL_IPCC_CHANNEL_3 -#define HW_IPCC_MM_RELEASE_BUFFER_CHANNEL LL_IPCC_CHANNEL_4 -#define HW_IPCC_THREAD_CLI_CMD_CHANNEL LL_IPCC_CHANNEL_5 -#define HW_IPCC_LLDTESTS_CLI_CMD_CHANNEL LL_IPCC_CHANNEL_5 -#define HW_IPCC_LLD_BLE_CLI_CMD_CHANNEL LL_IPCC_CHANNEL_5 -#define HW_IPCC_LLD_BLE_CMD_CHANNEL LL_IPCC_CHANNEL_5 -#define HW_IPCC_HCI_ACL_DATA_CHANNEL LL_IPCC_CHANNEL_6 - -/** CPU2 */ -#define HW_IPCC_BLE_EVENT_CHANNEL LL_IPCC_CHANNEL_1 -#define HW_IPCC_SYSTEM_EVENT_CHANNEL LL_IPCC_CHANNEL_2 -#define HW_IPCC_THREAD_NOTIFICATION_ACK_CHANNEL LL_IPCC_CHANNEL_3 -#define HW_IPCC_LLDTESTS_M0_CMD_CHANNEL LL_IPCC_CHANNEL_3 -#define HW_IPCC_LLD_BLE_M0_CMD_CHANNEL LL_IPCC_CHANNEL_3 -#define HW_IPCC_TRACES_CHANNEL LL_IPCC_CHANNEL_4 -#define HW_IPCC_THREAD_CLI_NOTIFICATION_ACK_CHANNEL LL_IPCC_CHANNEL_5 -#define HW_IPCC_LLDTESTS_CLI_RSP_CHANNEL LL_IPCC_CHANNEL_5 -#define HW_IPCC_LLD_BLE_CLI_RSP_CHANNEL LL_IPCC_CHANNEL_5 -#define HW_IPCC_LLD_BLE_RSP_CHANNEL LL_IPCC_CHANNEL_5 -#endif /*__MBOX_H */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/src/utility/STM32Cube_FW/shci.c b/src/utility/STM32Cube_FW/shci.c deleted file mode 100644 index d23157f2..00000000 --- a/src/utility/STM32Cube_FW/shci.c +++ /dev/null @@ -1,567 +0,0 @@ -/** - ****************************************************************************** - * @file shci.c - * @author MCD Application Team - * @brief HCI command for the system channel - ****************************************************************************** - * @attention - * - * <h2><center>© Copyright (c) 2019 STMicroelectronics. - * All rights reserved.</center></h2> - * - * This software component is licensed by ST under BSD 3-Clause license, - * the "License"; You may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * opensource.org/licenses/BSD-3-Clause - * - ****************************************************************************** - */ - -#if defined(STM32WBxx) -/* Includes ------------------------------------------------------------------*/ -#include "stm32_wpan_common.h" - -#include "shci_tl.h" -#include "shci.h" -#include "stm32wbxx.h" - -/* Private typedef -----------------------------------------------------------*/ -/* Private defines -----------------------------------------------------------*/ -/* Private macros ------------------------------------------------------------*/ -/* Private variables ---------------------------------------------------------*/ -/* Global variables ----------------------------------------------------------*/ -/* Private function prototypes -----------------------------------------------*/ -/* Local Functions Definition ------------------------------------------------------*/ -/* Public Functions Definition ------------------------------------------------------*/ - -/** - * C2 COMMAND - * These commands are sent to the CPU2 - */ -uint8_t SHCI_C2_FUS_GetState(SHCI_FUS_GetState_ErrorCode_t *p_error_code) -{ - /** - * A command status event + payload has the same size than the expected command complete - */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE + 1]; - TL_EvtPacket_t *p_rsp; - - p_rsp = (TL_EvtPacket_t *)local_buffer; - - shci_send(SHCI_OPCODE_C2_FUS_GET_STATE, - 0, - 0, - p_rsp); - - if (p_error_code != 0) { - *p_error_code = (SHCI_FUS_GetState_ErrorCode_t)(((TL_CcEvt_t *)(p_rsp->evtserial.evt.payload))->payload[1]); - } - - return (((TL_CcEvt_t *)(p_rsp->evtserial.evt.payload))->payload[0]); -} - -SHCI_CmdStatus_t SHCI_C2_FUS_FwUpgrade(uint32_t fw_src_add, uint32_t fw_dest_add) -{ - /** - * TL_BLEEVT_CS_BUFFER_SIZE is 15 bytes so it is large enough to hold the 8 bytes of command parameters - * Buffer is large enough to hold command complete without payload - */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; - TL_EvtPacket_t *p_rsp; - uint32_t *p_cmd; - uint8_t cmd_length; - - p_cmd = (uint32_t *)local_buffer; - cmd_length = 0; - - if (fw_src_add != 0) { - *p_cmd = fw_src_add; - cmd_length += 4; - } - - if (fw_dest_add != 0) { - *(p_cmd + 1) = fw_dest_add; - cmd_length += 4; - } - - p_rsp = (TL_EvtPacket_t *)local_buffer; - - shci_send(SHCI_OPCODE_C2_FUS_FW_UPGRADE, - cmd_length, - local_buffer, - p_rsp); - - return (SHCI_CmdStatus_t)(((TL_CcEvt_t *)(p_rsp->evtserial.evt.payload))->payload[0]); -} - -SHCI_CmdStatus_t SHCI_C2_FUS_FwDelete(void) -{ - /** - * Buffer is large enough to hold command complete without payload - */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; - TL_EvtPacket_t *p_rsp; - - p_rsp = (TL_EvtPacket_t *)local_buffer; - - shci_send(SHCI_OPCODE_C2_FUS_FW_DELETE, - 0, - 0, - p_rsp); - - return (SHCI_CmdStatus_t)(((TL_CcEvt_t *)(p_rsp->evtserial.evt.payload))->payload[0]); -} - -SHCI_CmdStatus_t SHCI_C2_FUS_UpdateAuthKey(SHCI_C2_FUS_UpdateAuthKey_Cmd_Param_t *pParam) -{ - /** - * Buffer is large enough to hold command complete without payload - */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; - TL_EvtPacket_t *p_rsp; - - p_rsp = (TL_EvtPacket_t *)local_buffer; - - shci_send(SHCI_OPCODE_C2_FUS_UPDATE_AUTH_KEY, - sizeof(SHCI_C2_FUS_UpdateAuthKey_Cmd_Param_t), - (uint8_t *)pParam, - p_rsp); - - return (SHCI_CmdStatus_t)(((TL_CcEvt_t *)(p_rsp->evtserial.evt.payload))->payload[0]); -} - -SHCI_CmdStatus_t SHCI_C2_FUS_LockAuthKey(void) -{ - /** - * Buffer is large enough to hold command complete without payload - */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; - TL_EvtPacket_t *p_rsp; - - p_rsp = (TL_EvtPacket_t *)local_buffer; - - shci_send(SHCI_OPCODE_C2_FUS_LOCK_AUTH_KEY, - 0, - 0, - p_rsp); - - return (SHCI_CmdStatus_t)(((TL_CcEvt_t *)(p_rsp->evtserial.evt.payload))->payload[0]); -} - -SHCI_CmdStatus_t SHCI_C2_FUS_StoreUsrKey(SHCI_C2_FUS_StoreUsrKey_Cmd_Param_t *pParam, uint8_t *p_key_index) -{ - /** - * Buffer is large enough to hold command complete without payload - */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE + 1]; - TL_EvtPacket_t *p_rsp; - uint8_t local_payload_len; - - if (pParam->KeyType == KEYTYPE_ENCRYPTED) { - /** - * When the key is encrypted, the 12 bytes IV Key is included in the payload as well - * The IV key is always 12 bytes - */ - local_payload_len = pParam->KeySize + 2 + 12; - } else { - local_payload_len = pParam->KeySize + 2; - } - - p_rsp = (TL_EvtPacket_t *)local_buffer; - - shci_send(SHCI_OPCODE_C2_FUS_STORE_USR_KEY, - local_payload_len, - (uint8_t *)pParam, - p_rsp); - - *p_key_index = (((TL_CcEvt_t *)(p_rsp->evtserial.evt.payload))->payload[1]); - - return (SHCI_CmdStatus_t)(((TL_CcEvt_t *)(p_rsp->evtserial.evt.payload))->payload[0]); -} - -SHCI_CmdStatus_t SHCI_C2_FUS_LoadUsrKey(uint8_t key_index) -{ - /** - * Buffer is large enough to hold command complete without payload - */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; - TL_EvtPacket_t *p_rsp; - - p_rsp = (TL_EvtPacket_t *)local_buffer; - - local_buffer[0] = key_index; - - shci_send(SHCI_OPCODE_C2_FUS_LOAD_USR_KEY, - 1, - local_buffer, - p_rsp); - - return (SHCI_CmdStatus_t)(((TL_CcEvt_t *)(p_rsp->evtserial.evt.payload))->payload[0]); -} - -SHCI_CmdStatus_t SHCI_C2_FUS_StartWs(void) -{ - /** - * Buffer is large enough to hold command complete without payload - */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; - TL_EvtPacket_t *p_rsp; - - p_rsp = (TL_EvtPacket_t *)local_buffer; - - shci_send(SHCI_OPCODE_C2_FUS_START_WS, - 0, - 0, - p_rsp); - - return (SHCI_CmdStatus_t)(((TL_CcEvt_t *)(p_rsp->evtserial.evt.payload))->payload[0]); -} - - -SHCI_CmdStatus_t SHCI_C2_FUS_LockUsrKey(uint8_t key_index) -{ - /** - * Buffer is large enough to hold command complete without payload - */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; - TL_EvtPacket_t *p_rsp; - - p_rsp = (TL_EvtPacket_t *)local_buffer; - - local_buffer[0] = key_index; - - shci_send(SHCI_OPCODE_C2_FUS_LOCK_USR_KEY, - 1, - local_buffer, - p_rsp); - - return (SHCI_CmdStatus_t)(((TL_CcEvt_t *)(p_rsp->evtserial.evt.payload))->payload[0]); -} - -SHCI_CmdStatus_t SHCI_C2_BLE_Init(SHCI_C2_Ble_Init_Cmd_Packet_t *pCmdPacket) -{ - /** - * Buffer is large enough to hold command complete without payload - */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; - TL_EvtPacket_t *p_rsp; - - p_rsp = (TL_EvtPacket_t *)local_buffer; - - shci_send(SHCI_OPCODE_C2_BLE_INIT, - sizeof(SHCI_C2_Ble_Init_Cmd_Param_t), - (uint8_t *)&pCmdPacket->Param, - p_rsp); - - return (SHCI_CmdStatus_t)(((TL_CcEvt_t *)(p_rsp->evtserial.evt.payload))->payload[0]); -} - -SHCI_CmdStatus_t SHCI_C2_THREAD_Init(void) -{ - /** - * Buffer is large enough to hold command complete without payload - */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; - TL_EvtPacket_t *p_rsp; - - p_rsp = (TL_EvtPacket_t *)local_buffer; - - shci_send(SHCI_OPCODE_C2_THREAD_INIT, - 0, - 0, - p_rsp); - - return (SHCI_CmdStatus_t)(((TL_CcEvt_t *)(p_rsp->evtserial.evt.payload))->payload[0]); -} - -SHCI_CmdStatus_t SHCI_C2_LLDTESTS_Init(uint8_t param_size, uint8_t *p_param) -{ - /** - * Buffer is large enough to hold command complete without payload - */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; - TL_EvtPacket_t *p_rsp; - - p_rsp = (TL_EvtPacket_t *)local_buffer; - - shci_send(SHCI_OPCODE_C2_LLD_TESTS_INIT, - param_size, - p_param, - p_rsp); - - return (SHCI_CmdStatus_t)(((TL_CcEvt_t *)(p_rsp->evtserial.evt.payload))->payload[0]); -} - -SHCI_CmdStatus_t SHCI_C2_LLD_BLE_Init(uint8_t param_size, uint8_t *p_param) -{ - /** - * Buffer is large enough to hold command complete without payload - */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; - TL_EvtPacket_t *p_rsp; - - p_rsp = (TL_EvtPacket_t *)local_buffer; - - shci_send(SHCI_OPCODE_C2_LLD_BLE_INIT, - param_size, - p_param, - p_rsp); - - return (SHCI_CmdStatus_t)(((TL_CcEvt_t *)(p_rsp->evtserial.evt.payload))->payload[0]); -} - -SHCI_CmdStatus_t SHCI_C2_DEBUG_Init(SHCI_C2_DEBUG_Init_Cmd_Packet_t *pCmdPacket) -{ - /** - * Buffer is large enough to hold command complete without payload - */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; - TL_EvtPacket_t *p_rsp; - - p_rsp = (TL_EvtPacket_t *)local_buffer; - - shci_send(SHCI_OPCODE_C2_DEBUG_INIT, - sizeof(SHCI_C2_DEBUG_init_Cmd_Param_t), - (uint8_t *)&pCmdPacket->Param, - p_rsp); - - return (SHCI_CmdStatus_t)(((TL_CcEvt_t *)(p_rsp->evtserial.evt.payload))->payload[0]); -} - -SHCI_CmdStatus_t SHCI_C2_FLASH_EraseActivity(SHCI_EraseActivity_t erase_activity) -{ - /** - * Buffer is large enough to hold command complete without payload - */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; - TL_EvtPacket_t *p_rsp; - - p_rsp = (TL_EvtPacket_t *)local_buffer; - - local_buffer[0] = erase_activity; - - shci_send(SHCI_OPCODE_C2_FLASH_ERASE_ACTIVITY, - 1, - local_buffer, - p_rsp); - - return (SHCI_CmdStatus_t)(((TL_CcEvt_t *)(p_rsp->evtserial.evt.payload))->payload[0]); -} - -SHCI_CmdStatus_t SHCI_C2_CONCURRENT_SetMode(SHCI_C2_CONCURRENT_Mode_Param_t Mode) -{ - /** - * Buffer is large enough to hold command complete without payload - */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; - TL_EvtPacket_t *p_rsp; - - p_rsp = (TL_EvtPacket_t *)local_buffer; - - local_buffer[0] = Mode; - - shci_send(SHCI_OPCODE_C2_CONCURRENT_SET_MODE, - 1, - local_buffer, - p_rsp); - - return (SHCI_CmdStatus_t)(((TL_CcEvt_t *)(p_rsp->evtserial.evt.payload))->payload[0]); -} - -SHCI_CmdStatus_t SHCI_C2_FLASH_StoreData(SHCI_C2_FLASH_Ip_t Ip) -{ - /** - * Buffer is large enough to hold command complete without payload - */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; - TL_EvtPacket_t *p_rsp; - - p_rsp = (TL_EvtPacket_t *)local_buffer; - - local_buffer[0] = Ip; - - shci_send(SHCI_OPCODE_C2_FLASH_STORE_DATA, - 1, - local_buffer, - p_rsp); - - return (SHCI_CmdStatus_t)(((TL_CcEvt_t *)(p_rsp->evtserial.evt.payload))->payload[0]); -} - -SHCI_CmdStatus_t SHCI_C2_FLASH_EraseData(SHCI_C2_FLASH_Ip_t Ip) -{ - /** - * Buffer is large enough to hold command complete without payload - */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; - TL_EvtPacket_t *p_rsp; - - p_rsp = (TL_EvtPacket_t *)local_buffer; - - local_buffer[0] = Ip; - - shci_send(SHCI_OPCODE_C2_FLASH_ERASE_DATA, - 1, - local_buffer, - p_rsp); - - return (SHCI_CmdStatus_t)(((TL_CcEvt_t *)(p_rsp->evtserial.evt.payload))->payload[0]); -} - -SHCI_CmdStatus_t SHCI_C2_RADIO_AllowLowPower(SHCI_C2_FLASH_Ip_t Ip, uint8_t FlagRadioLowPowerOn) -{ - /** - * Buffer is large enough to hold command complete without payload - */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; - TL_EvtPacket_t *p_rsp; - - p_rsp = (TL_EvtPacket_t *)local_buffer; - - local_buffer[0] = Ip; - local_buffer[1] = FlagRadioLowPowerOn; - - shci_send(SHCI_OPCODE_C2_RADIO_ALLOW_LOW_POWER, - 2, - local_buffer, - p_rsp); - - return (SHCI_CmdStatus_t)(((TL_CcEvt_t *)(p_rsp->evtserial.evt.payload))->payload[0]); -} - -SHCI_CmdStatus_t SHCI_C2_Reinit(void) -{ - /** - * Buffer is large enough to hold command complete without payload - */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; - TL_EvtPacket_t *p_rsp; - - p_rsp = (TL_EvtPacket_t *)local_buffer; - - shci_send(SHCI_OPCODE_C2_REINIT, - 0, - 0, - p_rsp); - - return (SHCI_CmdStatus_t)(((TL_CcEvt_t *)(p_rsp->evtserial.evt.payload))->payload[0]); -} - -SHCI_CmdStatus_t SHCI_C2_ExtpaConfig(uint32_t gpio_port, uint16_t gpio_pin_number, uint8_t gpio_polarity, uint8_t gpio_status) -{ - /** - * TL_BLEEVT_CS_BUFFER_SIZE is 15 bytes so it is large enough to hold the 8 bytes of command parameters - * Buffer is large enough to hold command complete without payload - */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; - TL_EvtPacket_t *p_rsp; - - p_rsp = (TL_EvtPacket_t *)local_buffer; - - ((SHCI_C2_EXTPA_CONFIG_Cmd_Param_t *)local_buffer)->gpio_port = gpio_port; - ((SHCI_C2_EXTPA_CONFIG_Cmd_Param_t *)local_buffer)->gpio_pin_number = gpio_pin_number; - ((SHCI_C2_EXTPA_CONFIG_Cmd_Param_t *)local_buffer)->gpio_polarity = gpio_polarity; - ((SHCI_C2_EXTPA_CONFIG_Cmd_Param_t *)local_buffer)->gpio_status = gpio_status; - - shci_send(SHCI_OPCODE_C2_EXTPA_CONFIG, - 8, - local_buffer, - p_rsp); - - return (SHCI_CmdStatus_t)(((TL_CcEvt_t *)(p_rsp->evtserial.evt.payload))->payload[0]); -} - -SHCI_CmdStatus_t SHCI_C2_SetFlashActivityControl(SHCI_C2_SET_FLASH_ACTIVITY_CONTROL_Source_t Source) -{ - /** - * TL_BLEEVT_CS_BUFFER_SIZE is 15 bytes so it is large enough to hold the 1 byte of command parameter - * Buffer is large enough to hold command complete without payload - */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; - TL_EvtPacket_t *p_rsp; - - p_rsp = (TL_EvtPacket_t *)local_buffer; - - local_buffer[0] = (uint8_t)Source; - - shci_send(SHCI_OPCODE_C2_SET_FLASH_ACTIVITY_CONTROL, - 1, - local_buffer, - p_rsp); - - return (SHCI_CmdStatus_t)(((TL_CcEvt_t *)(p_rsp->evtserial.evt.payload))->payload[0]); -} - -SHCI_CmdStatus_t SHCI_C2_Config(SHCI_C2_CONFIG_Cmd_Param_t *pCmdPacket) -{ - /** - * Buffer is large enough to hold command complete without payload - */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; - TL_EvtPacket_t *p_rsp; - - p_rsp = (TL_EvtPacket_t *)local_buffer; - - shci_send(SHCI_OPCODE_C2_CONFIG, - sizeof(SHCI_C2_CONFIG_Cmd_Param_t), - (uint8_t *)pCmdPacket, - p_rsp); - - return (SHCI_CmdStatus_t)(((TL_CcEvt_t *)(p_rsp->evtserial.evt.payload))->payload[0]); -} - - -/** - * Local System COMMAND - * These commands are NOT sent to the CPU2 - */ - -SHCI_CmdStatus_t SHCI_GetWirelessFwInfo(WirelessFwInfo_t *pWirelessInfo) -{ - uint32_t ipccdba = 0; - MB_RefTable_t *p_RefTable = NULL; - uint32_t version = 0; - uint32_t memorySize = 0; - uint32_t infoStack = 0; - - ipccdba = READ_BIT(FLASH->IPCCBR, FLASH_IPCCBR_IPCCDBA); - p_RefTable = (MB_RefTable_t *)((ipccdba << 2) + SRAM2A_BASE); - - /** - * Retrieve the WirelessFwInfoTable - * This table is stored in RAM at startup during the TL (transport layer) initialization - */ - version = p_RefTable->p_device_info_table->WirelessFwInfoTable.Version; - pWirelessInfo->VersionMajor = ((version & INFO_VERSION_MAJOR_MASK) >> INFO_VERSION_MAJOR_OFFSET); - pWirelessInfo->VersionMinor = ((version & INFO_VERSION_MINOR_MASK) >> INFO_VERSION_MINOR_OFFSET); - pWirelessInfo->VersionSub = ((version & INFO_VERSION_SUB_MASK) >> INFO_VERSION_SUB_OFFSET); - pWirelessInfo->VersionBranch = ((version & INFO_VERSION_BRANCH_MASK) >> INFO_VERSION_BRANCH_OFFSET); - pWirelessInfo->VersionReleaseType = ((version & INFO_VERSION_TYPE_MASK) >> INFO_VERSION_TYPE_OFFSET); - - memorySize = p_RefTable->p_device_info_table->WirelessFwInfoTable.MemorySize; - pWirelessInfo->MemorySizeSram2B = ((memorySize & INFO_SIZE_SRAM2B_MASK) >> INFO_SIZE_SRAM2B_OFFSET); - pWirelessInfo->MemorySizeSram2A = ((memorySize & INFO_SIZE_SRAM2A_MASK) >> INFO_SIZE_SRAM2A_OFFSET); - pWirelessInfo->MemorySizeSram1 = ((memorySize & INFO_SIZE_SRAM1_MASK) >> INFO_SIZE_SRAM1_OFFSET); - pWirelessInfo->MemorySizeFlash = ((memorySize & INFO_SIZE_FLASH_MASK) >> INFO_SIZE_FLASH_OFFSET); - - infoStack = p_RefTable->p_device_info_table->WirelessFwInfoTable.InfoStack; - pWirelessInfo->StackType = ((infoStack & INFO_STACK_TYPE_MASK) >> INFO_STACK_TYPE_OFFSET); - - /** - * Retrieve the FusInfoTable - * This table is stored in RAM at startup during the TL (transport layer) initialization - */ - version = p_RefTable->p_device_info_table->FusInfoTable.Version; - pWirelessInfo->FusVersionMajor = ((version & INFO_VERSION_MAJOR_MASK) >> INFO_VERSION_MAJOR_OFFSET); - pWirelessInfo->FusVersionMinor = ((version & INFO_VERSION_MINOR_MASK) >> INFO_VERSION_MINOR_OFFSET); - pWirelessInfo->FusVersionSub = ((version & INFO_VERSION_SUB_MASK) >> INFO_VERSION_SUB_OFFSET); - - memorySize = p_RefTable->p_device_info_table->FusInfoTable.MemorySize; - pWirelessInfo->FusMemorySizeSram2B = ((memorySize & INFO_SIZE_SRAM2B_MASK) >> INFO_SIZE_SRAM2B_OFFSET); - pWirelessInfo->FusMemorySizeSram2A = ((memorySize & INFO_SIZE_SRAM2A_MASK) >> INFO_SIZE_SRAM2A_OFFSET); - pWirelessInfo->FusMemorySizeFlash = ((memorySize & INFO_SIZE_FLASH_MASK) >> INFO_SIZE_FLASH_OFFSET); - - return (SHCI_Success); -} -#endif /* STM32WBxx */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/src/utility/STM32Cube_FW/shci.h b/src/utility/STM32Cube_FW/shci.h deleted file mode 100644 index 35227c76..00000000 --- a/src/utility/STM32Cube_FW/shci.h +++ /dev/null @@ -1,888 +0,0 @@ -/** - ****************************************************************************** - * @file shci.h - * @author MCD Application Team - * @brief HCI command for the system channel - ****************************************************************************** - * @attention - * - * <h2><center>© Copyright (c) 2019 STMicroelectronics. - * All rights reserved.</center></h2> - * - * This software component is licensed by ST under BSD 3-Clause license, - * the "License"; You may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * opensource.org/licenses/BSD-3-Clause - * - ****************************************************************************** - */ - - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __SHCI_H -#define __SHCI_H - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "mbox_def.h" /* Requested to expose the MB_WirelessFwInfoTable_t structure */ - -/* Exported types ------------------------------------------------------------*/ - -/* SYSTEM EVENT */ -typedef enum { - WIRELESS_FW_RUNNING = 0x00, - RSS_FW_RUNNING = 0x01, -} SHCI_SysEvt_Ready_Rsp_t; - -/* ERROR CODES - * - * These error codes are detected on M0 side and are send back to the M4 via a system - * notification message. It is up to the application running on M4 to manage these errors - * - * These errors can be generated by all layers (low level driver, stack, framework infrastructure, etc..) - */ -typedef enum { - ERR_BLE_INIT = 0, - ERR_THREAD_LLD_FATAL_ERROR = 125, /* The LLD driver used on 802_15_4 detected a fatal error */ - ERR_THREAD_UNKNOWN_CMD = 126, /* The command send by the M4 to control the Thread stack is unknown */ -} SCHI_SystemErrCode_t; - -#define SHCI_EVTCODE ( 0xFF ) -#define SHCI_SUB_EVT_CODE_BASE ( 0x9200 ) - -/** - * THE ORDER SHALL NOT BE CHANGED TO GUARANTEE COMPATIBILITY WITH THE CPU1 DEFINITION - */ -typedef enum { - SHCI_SUB_EVT_CODE_READY = SHCI_SUB_EVT_CODE_BASE, - SHCI_SUB_EVT_ERROR_NOTIF, - SHCI_SUB_EVT_BLE_NVM_RAM_UPDATE, - SHCI_SUB_EVT_OT_NVM_RAM_UPDATE, - SHCI_SUB_EVT_NVM_START_WRITE, - SHCI_SUB_EVT_NVM_END_WRITE, - SHCI_SUB_EVT_NVM_START_ERASE, - SHCI_SUB_EVT_NVM_END_ERASE, -} SHCI_SUB_EVT_CODE_t; - -/** - * SHCI_SUB_EVT_CODE_READY - * This notifies the CPU1 that the CPU2 is now ready to receive commands - * It reports as well which firmware is running on CPU2 : The wireless stack of the FUS (previously named RSS) - */ -typedef PACKED_STRUCT{ - SHCI_SysEvt_Ready_Rsp_t sysevt_ready_rsp; -} SHCI_C2_Ready_Evt_t; - -/** - * SHCI_SUB_EVT_ERROR_NOTIF - * This reports to the CPU1 some error form the CPU2 - */ -typedef PACKED_STRUCT{ - SCHI_SystemErrCode_t errorCode; -} SHCI_C2_ErrorNotif_Evt_t; - -/** - * SHCI_SUB_EVT_BLE_NVM_RAM_UPDATE - * This notifies the CPU1 which part of the BLE NVM RAM has been updated so that only the modified - * section could be written in Flash/NVM - * StartAddress : Start address of the section that has been modified - * Size : Size (in bytes) of the section that has been modified - */ -typedef PACKED_STRUCT{ - uint32_t StartAddress; - uint32_t Size; -} SHCI_C2_BleNvmRamUpdate_Evt_t; - -/** - * SHCI_SUB_EVT_OT_NVM_RAM_UPDATE - * This notifies the CPU1 which part of the 'OT NVM RAM' has been updated so that only the modified - * section could be written in Flash/NVM - * StartAddress : Start address of the section that has been modified - * Size : Size (in bytes) of the section that has been modified - */ -typedef PACKED_STRUCT{ - uint32_t StartAddress; - uint32_t Size; -} SHCI_C2_OtNvmRamUpdate_Evt_t; - -/** - * SHCI_SUB_EVT_NVM_START_WRITE - * This notifies the CPU1 that the CPU2 has started a write procedure in Flash - * NumberOfWords : The number of 64bits data the CPU2 needs to write in Flash. - * For each 64bits data, the algorithm as described in AN5289 is executed. - * When this number is reported to 0, it means the Number of 64bits to be written - * was unknown when the procedure has started. - * When all data are written, the SHCI_SUB_EVT_NVM_END_WRITE event is reported - */ -typedef PACKED_STRUCT{ - uint32_t NumberOfWords; -} SHCI_C2_NvmStartWrite_Evt_t; - -/** - * SHCI_SUB_EVT_NVM_END_WRITE - * This notifies the CPU1 that the CPU2 has written all expected data in Flash - */ - -/** - * SHCI_SUB_EVT_NVM_START_ERASE - * This notifies the CPU1 that the CPU2 has started a erase procedure in Flash - * NumberOfSectors : The number of sectors the CPU2 needs to erase in Flash. - * For each sector, the algorithm as described in AN5289 is executed. - * When this number is reported to 0, it means the Number of sectors to be erased - * was unknown when the procedure has started. - * When all sectors are erased, the SHCI_SUB_EVT_NVM_END_ERASE event is reported - */ -typedef PACKED_STRUCT{ - uint32_t NumberOfSectors; -} SHCI_C2_NvmStartErase_Evt_t; - -/** - * SHCI_SUB_EVT_NVM_END_ERASE - * This notifies the CPU1 that the CPU2 has erased all expected flash sectors - */ - -/* SYSTEM COMMAND */ -typedef PACKED_STRUCT { - uint32_t MetaData[3]; -} SHCI_Header_t; - -typedef enum { - SHCI_Success = 0x00, - SHCI_UNKNOWN_CMD = 0x01, - SHCI_ERR_UNSUPPORTED_FEATURE = 0x11, - SHCI_ERR_INVALID_HCI_CMD_PARAMS = 0x12, - SHCI_FUS_CMD_NOT_SUPPORTED = 0xFF, -} SHCI_CmdStatus_t; - -typedef enum { - SHCI_8BITS = 0x01, - SHCI_16BITS = 0x02, - SHCI_32BITS = 0x04, -} SHCI_Busw_t; - -#define SHCI_OGF ( 0x3F ) -#define SHCI_OCF_BASE ( 0x50 ) - -/** - * THE ORDER SHALL NOT BE CHANGED TO GUARANTEE COMPATIBILITY WITH THE CPU2 DEFINITION - */ -typedef enum { - SHCI_OCF_C2_RESERVED1 = SHCI_OCF_BASE, - SHCI_OCF_C2_RESERVED2, - SHCI_OCF_C2_FUS_GET_STATE, - SHCI_OCF_C2_FUS_RESERVED1, - SHCI_OCF_C2_FUS_FW_UPGRADE, - SHCI_OCF_C2_FUS_FW_DELETE, - SHCI_OCF_C2_FUS_UPDATE_AUTH_KEY, - SHCI_OCF_C2_FUS_LOCK_AUTH_KEY, - SHCI_OCF_C2_FUS_STORE_USR_KEY, - SHCI_OCF_C2_FUS_LOAD_USR_KEY, - SHCI_OCF_C2_FUS_START_WS, - SHCI_OCF_C2_FUS_RESERVED2, - SHCI_OCF_C2_FUS_RESERVED3, - SHCI_OCF_C2_FUS_LOCK_USR_KEY, - SHCI_OCF_C2_FUS_RESERVED5, - SHCI_OCF_C2_FUS_RESERVED6, - SHCI_OCF_C2_FUS_RESERVED7, - SHCI_OCF_C2_FUS_RESERVED8, - SHCI_OCF_C2_FUS_RESERVED9, - SHCI_OCF_C2_FUS_RESERVED10, - SHCI_OCF_C2_FUS_RESERVED11, - SHCI_OCF_C2_FUS_RESERVED12, - SHCI_OCF_C2_BLE_INIT, - SHCI_OCF_C2_THREAD_INIT, - SHCI_OCF_C2_DEBUG_INIT, - SHCI_OCF_C2_FLASH_ERASE_ACTIVITY, - SHCI_OCF_C2_CONCURRENT_SET_MODE, - SHCI_OCF_C2_FLASH_STORE_DATA, - SHCI_OCF_C2_FLASH_ERASE_DATA, - SHCI_OCF_C2_RADIO_ALLOW_LOW_POWER, - SHCI_OCF_C2_REINIT, - SHCI_OCF_C2_LLD_TESTS_INIT, - SHCI_OCF_C2_EXTPA_CONFIG, - SHCI_OCF_C2_SET_FLASH_ACTIVITY_CONTROL, - SHCI_OCF_C2_LLD_BLE_INIT, - SHCI_OCF_C2_CONFIG, -} SHCI_OCF_t; - -#define SHCI_OPCODE_C2_FUS_GET_STATE (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_GET_STATE) -/** No command parameters */ -/** Response parameters*/ -typedef enum { - FUS_STATE_NO_ERROR = 0x00, - FUS_STATE_IMG_NOT_FOUND = 0x01, - FUS_STATE_IMG_CORRUPT = 0x02, - FUS_STATE_IMG_NOT_AUTHENTIC = 0x03, - FUS_STATE_IMG_NOT_ENOUGH_SPACE = 0x04, - FUS_STATE_ERR_UNKNOWN = 0xFF, -} SHCI_FUS_GetState_ErrorCode_t; - -#define SHCI_OPCODE_C2_FUS_RESERVED1 (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_RESERVED1) -/** No command parameters */ -/** No response parameters*/ - -#define SHCI_OPCODE_C2_FUS_FW_UPGRADE (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_FW_UPGRADE) -/** No structure for command parameters */ -/** No response parameters*/ - -#define SHCI_OPCODE_C2_FUS_FW_DELETE (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_FW_DELETE) -/** No command parameters */ -/** No response parameters*/ - -#define SHCI_OPCODE_C2_FUS_UPDATE_AUTH_KEY (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_UPDATE_AUTH_KEY) -typedef PACKED_STRUCT { - uint8_t KeySize; - uint8_t KeyData[64]; -} SHCI_C2_FUS_UpdateAuthKey_Cmd_Param_t; - -/** No response parameters*/ - -#define SHCI_OPCODE_C2_FUS_LOCK_AUTH_KEY (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_LOCK_AUTH_KEY) -/** No command parameters */ -/** No response parameters*/ - -#define SHCI_OPCODE_C2_FUS_STORE_USR_KEY (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_STORE_USR_KEY) -/** Command parameters */ -/* List of supported key type */ -enum { - KEYTYPE_NONE = 0x00, - KEYTYPE_SIMPLE = 0x01, - KEYTYPE_MASTER = 0x02, - KEYTYPE_ENCRYPTED = 0x03, -}; - -/* List of supported key size */ -enum { - KEYSIZE_16 = 16, - KEYSIZE_32 = 32, -}; - -typedef PACKED_STRUCT{ - uint8_t KeyType; - uint8_t KeySize; - uint8_t KeyData[32 + 12]; -} SHCI_C2_FUS_StoreUsrKey_Cmd_Param_t; - -/** Response parameters*/ -/** It responds a 1 byte value holding the index given for the stored key */ - -#define SHCI_OPCODE_C2_FUS_LOAD_USR_KEY (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_LOAD_USR_KEY) -/** Command parameters */ -/** 1 byte holding the key index value */ - -/** No response parameters*/ - -#define SHCI_OPCODE_C2_FUS_START_WS (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_START_WS) -/** No command parameters */ -/** No response parameters*/ - -#define SHCI_OPCODE_C2_FUS_RESERVED2 (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_RESERVED2) -/** No command parameters */ -/** No response parameters*/ - -#define SHCI_OPCODE_C2_FUS_RESERVED3 (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_RESERVED3) -/** No command parameters */ -/** No response parameters*/ - -#define SHCI_OPCODE_C2_FUS_LOCK_USR_KEY (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_LOCK_USR_KEY) -/** Command parameters */ -/** 1 byte holding the key index value */ - -/** No response parameters*/ - -#define SHCI_OPCODE_C2_FUS_RESERVED5 (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_RESERVED5) -/** No command parameters */ -/** No response parameters*/ - -#define SHCI_OPCODE_C2_FUS_RESERVED6 (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_RESERVED6) -/** No command parameters */ -/** No response parameters*/ - -#define SHCI_OPCODE_C2_FUS_RESERVED7 (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_RESERVED7) -/** No command parameters */ -/** No response parameters*/ - -#define SHCI_OPCODE_C2_FUS_RESERVED8 (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_RESERVED8) -/** No command parameters */ -/** No response parameters*/ - -#define SHCI_OPCODE_C2_FUS_RESERVED9 (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_RESERVED9) -/** No command parameters */ -/** No response parameters*/ - -#define SHCI_OPCODE_C2_FUS_RESERVED10 (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_RESERVED10) -/** No command parameters */ -/** No response parameters*/ - -#define SHCI_OPCODE_C2_FUS_RESERVED11 (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_RESERVED11) -/** No command parameters */ -/** No response parameters*/ - -#define SHCI_OPCODE_C2_FUS_RESERVED12 (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_RESERVED12) -/** No command parameters */ -/** No response parameters*/ - -#define SHCI_OPCODE_C2_BLE_INIT (( SHCI_OGF << 10) + SHCI_OCF_C2_BLE_INIT) -/** THE ORDER SHALL NOT BE CHANGED */ -typedef PACKED_STRUCT{ - uint8_t *pBleBufferAddress; /**< NOT USED CURRENTLY */ - uint32_t BleBufferSize; /**< Size of the Buffer allocated in pBleBufferAddress */ - uint16_t NumAttrRecord; - uint16_t NumAttrServ; - uint16_t AttrValueArrSize; - uint8_t NumOfLinks; - uint8_t ExtendedPacketLengthEnable; - uint8_t PrWriteListSize; - uint8_t MblockCount; - uint16_t AttMtu; - uint16_t SlaveSca; - uint8_t MasterSca; - uint8_t LsSource; - uint32_t MaxConnEventLength; - uint16_t HsStartupTime; - uint8_t ViterbiEnable; - uint8_t LlOnly; - uint8_t HwVersion; -} SHCI_C2_Ble_Init_Cmd_Param_t; - -typedef PACKED_STRUCT{ - SHCI_Header_t Header; /** Does not need to be initialized by the user */ - SHCI_C2_Ble_Init_Cmd_Param_t Param; -} SHCI_C2_Ble_Init_Cmd_Packet_t; - -/** No response parameters*/ - -#define SHCI_OPCODE_C2_THREAD_INIT (( SHCI_OGF << 10) + SHCI_OCF_C2_THREAD_INIT) -/** No command parameters */ -/** No response parameters*/ - -#define SHCI_OPCODE_C2_DEBUG_INIT (( SHCI_OGF << 10) + SHCI_OCF_C2_DEBUG_INIT) -/** Command parameters */ -typedef PACKED_STRUCT { - uint8_t thread_config; - uint8_t ble_config; -} SHCI_C2_DEBUG_TracesConfig_t; - -typedef PACKED_STRUCT { - uint8_t ble_dtb_cfg; - uint8_t reserved[3]; -} SHCI_C2_DEBUG_GeneralConfig_t; - -typedef PACKED_STRUCT{ - uint8_t *pGpioConfig; - uint8_t *pTracesConfig; - uint8_t *pGeneralConfig; - uint8_t GpioConfigSize; - uint8_t TracesConfigSize; - uint8_t GeneralConfigSize; -} SHCI_C2_DEBUG_init_Cmd_Param_t; - -typedef PACKED_STRUCT{ - SHCI_Header_t Header; /** Does not need to be initialized by the user */ - SHCI_C2_DEBUG_init_Cmd_Param_t Param; -} SHCI_C2_DEBUG_Init_Cmd_Packet_t; -/** No response parameters*/ - -#define SHCI_OPCODE_C2_FLASH_ERASE_ACTIVITY (( SHCI_OGF << 10) + SHCI_OCF_C2_FLASH_ERASE_ACTIVITY) -/** Command parameters */ -typedef enum { - ERASE_ACTIVITY_OFF = 0x00, - ERASE_ACTIVITY_ON = 0x01, -} SHCI_EraseActivity_t; - -/** No response parameters*/ - -#define SHCI_OPCODE_C2_CONCURRENT_SET_MODE (( SHCI_OGF << 10) + SHCI_OCF_C2_CONCURRENT_SET_MODE) -/** command parameters */ -typedef enum { - BLE_ENABLE, - THREAD_ENABLE, -} SHCI_C2_CONCURRENT_Mode_Param_t; -/** No response parameters*/ - -#define SHCI_OPCODE_C2_FLASH_STORE_DATA (( SHCI_OGF << 10) + SHCI_OCF_C2_FLASH_STORE_DATA) -#define SHCI_OPCODE_C2_FLASH_ERASE_DATA (( SHCI_OGF << 10) + SHCI_OCF_C2_FLASH_ERASE_DATA) -/** command parameters */ -typedef enum { - BLE_IP, - THREAD_IP, -} SHCI_C2_FLASH_Ip_t; -/** No response parameters*/ - -#define SHCI_OPCODE_C2_RADIO_ALLOW_LOW_POWER (( SHCI_OGF << 10) + SHCI_OCF_C2_RADIO_ALLOW_LOW_POWER) - -#define SHCI_OPCODE_C2_REINIT (( SHCI_OGF << 10) + SHCI_OCF_C2_REINIT) - -#define SHCI_OPCODE_C2_LLD_TESTS_INIT (( SHCI_OGF << 10) + SHCI_OCF_C2_LLD_TESTS_INIT) - -#define SHCI_OPCODE_C2_LLD_BLE_INIT (( SHCI_OGF << 10) + SHCI_OCF_C2_LLD_BLE_INIT) - -#define SHCI_OPCODE_C2_EXTPA_CONFIG (( SHCI_OGF << 10) + SHCI_OCF_C2_EXTPA_CONFIG) -/** Command parameters */ -enum { - EXT_PA_ENABLED_LOW, - EXT_PA_ENABLED_HIGH, -}/* gpio_polarity */; - -enum { - EXT_PA_DISABLED, - EXT_PA_ENABLED, -}/* gpio_status */; - -typedef PACKED_STRUCT{ - uint32_t gpio_port; - uint16_t gpio_pin_number; - uint8_t gpio_polarity; - uint8_t gpio_status; -} SHCI_C2_EXTPA_CONFIG_Cmd_Param_t; - -/** No response parameters*/ - -#define SHCI_OPCODE_C2_SET_FLASH_ACTIVITY_CONTROL (( SHCI_OGF << 10) + SHCI_OCF_C2_SET_FLASH_ACTIVITY_CONTROL) -/** Command parameters */ -typedef enum { - FLASH_ACTIVITY_CONTROL_PES, - FLASH_ACTIVITY_CONTROL_SEM7, -} SHCI_C2_SET_FLASH_ACTIVITY_CONTROL_Source_t; - -/** No response parameters*/ - -#define SHCI_OPCODE_C2_CONFIG (( SHCI_OGF << 10) + SHCI_OCF_C2_CONFIG) -/** Command parameters */ -typedef PACKED_STRUCT{ - uint8_t PayloadCmdSize; - uint8_t Config1; - uint8_t EvtMask1; - uint8_t Spare1; - uint32_t BleNvmRamAddress; - uint32_t ThreadNvmRamAddress; -} SHCI_C2_CONFIG_Cmd_Param_t; - -/** - * PayloadCmdSize - * Value that shall be used - */ -#define SHCI_C2_CONFIG_PAYLOAD_CMD_SIZE (sizeof(SHCI_C2_CONFIG_Cmd_Param_t) - 1) - -/** - * Config1 - * Each definition below may be added together to build the Config1 value - * WARNING : Only one definition per bit shall be added to build the Config1 value - */ -#define SHCI_C2_CONFIG_CONFIG1_BIT0_BLE_NVM_DATA_TO_INTERNAL_FLASH (0<<0) -#define SHCI_C2_CONFIG_CONFIG1_BIT0_BLE_NVM_DATA_TO_SRAM (1<<0) -#define SHCI_C2_CONFIG_CONFIG1_BIT1_THREAD_NVM_DATA_TO_INTERNAL_FLASH (0<<1) -#define SHCI_C2_CONFIG_CONFIG1_BIT1_THREAD_NVM_DATA_TO_SRAM (1<<1) - -/** - * EvtMask1 - * Each definition below may be added together to build the EvtMask1 value - */ -#define SHCI_C2_CONFIG_EVTMASK1_BIT0_ERROR_NOTIF_ENABLE (1<<0) -#define SHCI_C2_CONFIG_EVTMASK1_BIT1_BLE_NVM_RAM_UPDATE_ENABLE (1<<1) -#define SHCI_C2_CONFIG_EVTMASK1_BIT2_OT_NVM_RAM_UPDATE_ENABLE (1<<2) -#define SHCI_C2_CONFIG_EVTMASK1_BIT3_NVM_START_WRITE_ENABLE (1<<3) -#define SHCI_C2_CONFIG_EVTMASK1_BIT4_NVM_END_WRITE_ENABLE (1<<4) -#define SHCI_C2_CONFIG_EVTMASK1_BIT5_NVM_START_ERASE_ENABLE (1<<5) -#define SHCI_C2_CONFIG_EVTMASK1_BIT6_NVM_END_ERASE_ENABLE (1<<6) - -/** - * BleNvmRamAddress - * The buffer shall have a size of BLE_NVM_SRAM_SIZE number of 32bits - * The buffer shall be allocated in SRAM2 - */ -#define BLE_NVM_SRAM_SIZE (507) - -/** - * ThreadNvmRamAddress - * The buffer shall have a size of THREAD_NVM_SRAM_SIZE number of 32bits - * The buffer shall be allocated in SRAM2 - */ -#define THREAD_NVM_SRAM_SIZE (1016) - - -/** No response parameters*/ - -/* Exported type --------------------------------------------------------*/ - -typedef MB_WirelessFwInfoTable_t SHCI_WirelessFwInfoTable_t; - -/* - * At startup, the information relative to the wireless binary are stored in RAM through a structure defined by - * SHCI_WirelessFwInfoTable_t.This structure contains 4 fields (Version,MemorySize, Stack_info and a reserved part) - * each of those coded on 32 bits as shown on the table below: - * - * - * |7 |6 |5 |4 |3 |2 |1 |0 |7 |6 |5 |4 |3 |2 |1 |0 |7 |6 |5 |4 |3 |2 |1 |0 |7 |6 |5 |4 |3 |2 |1 |0 | - * ------------------------------------------------------------------------------------------------- - * Version | Major version | Minor version | Sub version | Branch |Release Type| - * ------------------------------------------------------------------------------------------------- - * MemorySize | SRAM2B (kB) | SRAM2A (kB) | SRAM1 (kB) | FLASH (4kb) | - * ------------------------------------------------------------------------------------------------- - * Info stack | Reserved | Reserved | Reserved | Type (MAC,Thread,BLE) | - * ------------------------------------------------------------------------------------------------- - * Reserved | Reserved | Reserved | Reserved | Reserved | - * ------------------------------------------------------------------------------------------------- - * - */ - -/* Field Version */ -#define INFO_VERSION_MAJOR_OFFSET 24 -#define INFO_VERSION_MAJOR_MASK 0xff000000 -#define INFO_VERSION_MINOR_OFFSET 16 -#define INFO_VERSION_MINOR_MASK 0x00ff0000 -#define INFO_VERSION_SUB_OFFSET 8 -#define INFO_VERSION_SUB_MASK 0x0000ff00 -#define INFO_VERSION_BRANCH_OFFSET 4 -#define INFO_VERSION_BRANCH_MASK 0x0000000f0 -#define INFO_VERSION_TYPE_OFFSET 0 -#define INFO_VERSION_TYPE_MASK 0x00000000f - -#define INFO_VERSION_TYPE_RELEASE 1 - -/* Field Memory */ -#define INFO_SIZE_SRAM2B_OFFSET 24 -#define INFO_SIZE_SRAM2B_MASK 0xff000000 -#define INFO_SIZE_SRAM2A_OFFSET 16 -#define INFO_SIZE_SRAM2A_MASK 0x00ff0000 -#define INFO_SIZE_SRAM1_OFFSET 8 -#define INFO_SIZE_SRAM1_MASK 0x0000ff00 -#define INFO_SIZE_FLASH_OFFSET 0 -#define INFO_SIZE_FLASH_MASK 0x000000ff - -/* Field stack information */ -#define INFO_STACK_TYPE_OFFSET 0 -#define INFO_STACK_TYPE_MASK 0x000000ff -#define INFO_STACK_TYPE_NONE 0 - -#define INFO_STACK_TYPE_BLE_STANDARD 0x01 -#define INFO_STACK_TYPE_BLE_HCI 0x02 -#define INFO_STACK_TYPE_BLE_LIGHT 0x03 -#define INFO_STACK_TYPE_THREAD_FTD 0x10 -#define INFO_STACK_TYPE_THREAD_MTD 0x11 -#define INFO_STACK_TYPE_BLE_THREAD_FTD_STATIC 0x50 -#define INFO_STACK_TYPE_BLE_THREAD_FTD_DYAMIC 0x51 -#define INFO_STACK_TYPE_BLE_PHY_VALID 0x62 -#define INFO_STACK_TYPE_BLE_LLD_TESTS 0x63 -#define INFO_STACK_TYPE_BLE_RLV 0x64 -#define INFO_STACK_TYPE_RLV 0x80 - -typedef struct { - /** - * Wireless Info - */ - uint8_t VersionMajor; - uint8_t VersionMinor; - uint8_t VersionSub; - uint8_t VersionBranch; - uint8_t VersionReleaseType; - uint8_t MemorySizeSram2B; /*< Multiple of 1K */ - uint8_t MemorySizeSram2A; /*< Multiple of 1K */ - uint8_t MemorySizeSram1; /*< Multiple of 1K */ - uint8_t MemorySizeFlash; /*< Multiple of 4K */ - uint8_t StackType; - /** - * Fus Info - */ - uint8_t FusVersionMajor; - uint8_t FusVersionMinor; - uint8_t FusVersionSub; - uint8_t FusMemorySizeSram2B; /*< Multiple of 1K */ - uint8_t FusMemorySizeSram2A; /*< Multiple of 1K */ - uint8_t FusMemorySizeFlash; /*< Multiple of 4K */ -} WirelessFwInfo_t; - - -/* Exported functions ------------------------------------------------------- */ - -/** - * For all SHCI_C2_FUS_xxx() command: - * When the wireless FW is running on the CPU2, the command returns SHCI_FUS_CMD_NOT_SUPPORTED - * When any FUS command is sent after the SHCI_FUS_CMD_NOT_SUPPORTED has been received, - * the CPU2 switches on the RSS ( This reboots automatically the device ) - */ -/** -* SHCI_C2_FUS_GetState -* @brief Read the FUS State -* If the user is not interested by the Error code response, a null value may -* be passed as parameter -* -* @param p_rsp : return the error code when the FUS State Value = 0xFF -* @retval FUS State Values -*/ -uint8_t SHCI_C2_FUS_GetState(SHCI_FUS_GetState_ErrorCode_t *p_rsp); - -/** -* SHCI_C2_FUS_FwUpgrade -* @brief Request the FUS to install the CPU2 firmware update -* -* @param fw_src_add: Address of the firmware image location -* @param fw_dest_add: Address of the firmware destination -* @retval Status -*/ -SHCI_CmdStatus_t SHCI_C2_FUS_FwUpgrade(uint32_t fw_src_add, uint32_t fw_dest_add); - -/** -* SHCI_C2_FUS_FwDelete -* @brief Delete the wireless stack on CPU2 -* -* @param None -* @retval Status -*/ -SHCI_CmdStatus_t SHCI_C2_FUS_FwDelete(void); - -/** -* SHCI_C2_FUS_UpdateAuthKey -* @brief Request the FUS to update the authentication key -* -* @param pCmdPacket -* @retval Status -*/ -SHCI_CmdStatus_t SHCI_C2_FUS_UpdateAuthKey(SHCI_C2_FUS_UpdateAuthKey_Cmd_Param_t *pParam); - -/** -* SHCI_C2_FUS_LockAuthKey -* @brief Request the FUS to prevent any future update of the authentication key -* -* @param None -* @retval Status -*/ -SHCI_CmdStatus_t SHCI_C2_FUS_LockAuthKey(void); - -/** -* SHCI_C2_FUS_StoreUsrKey -* @brief Request the FUS to store the user key -* -* @param pParam : command parameter -* @param p_key_index : Index allocated by the FUS to the stored key -* -* @retval Status -*/ -SHCI_CmdStatus_t SHCI_C2_FUS_StoreUsrKey(SHCI_C2_FUS_StoreUsrKey_Cmd_Param_t *pParam, uint8_t *p_key_index); - -/** -* SHCI_C2_FUS_LoadUsrKey -* @brief Request the FUS to load the user key into the AES -* -* @param key_index : index of the user key to load in AES1 -* @retval Status -*/ -SHCI_CmdStatus_t SHCI_C2_FUS_LoadUsrKey(uint8_t key_index); - -/** -* SHCI_C2_FUS_StartWs -* @brief Request the FUS to reboot on the wireless stack -* -* @param None -* @retval Status -*/ -SHCI_CmdStatus_t SHCI_C2_FUS_StartWs(void); - -/** -* SHCI_C2_FUS_LockUsrKey -* @brief Request the FUS to lock the user key so that it cannot be updated later on -* -* @param key_index : index of the user key to lock -* @retval Status -*/ -SHCI_CmdStatus_t SHCI_C2_FUS_LockUsrKey(uint8_t key_index); - -/** -* SHCI_C2_BLE_Init -* @brief Provides parameters and starts the BLE Stack -* -* @param pCmdPacket : Parameters to be provided to the BLE Stack -* @retval Status -*/ -SHCI_CmdStatus_t SHCI_C2_BLE_Init(SHCI_C2_Ble_Init_Cmd_Packet_t *pCmdPacket); - -/** -* SHCI_C2_THREAD_Init -* @brief Starts the THREAD Stack -* -* @param None -* @retval Status -*/ -SHCI_CmdStatus_t SHCI_C2_THREAD_Init(void); - -/** -* SHCI_C2_LLDTESTS_Init -* @brief Starts the LLD tests CLI -* -* @param param_size : Nb of bytes -* @param p_param : pointer with data to give from M4 to M0 -* @retval Status -*/ -SHCI_CmdStatus_t SHCI_C2_LLDTESTS_Init(uint8_t param_size, uint8_t *p_param); - -/** -* SHCI_C2_LLD_BLE_Init -* @brief Starts the LLD tests CLI -* -* @param param_size : Nb of bytes -* @param p_param : pointer with data to give from M4 to M0 -* @retval Status -*/ -SHCI_CmdStatus_t SHCI_C2_LLD_BLE_Init(uint8_t param_size, uint8_t *p_param); - -/** -* SHCI_C2_DEBUG_Init -* @brief Starts the Traces -* -* @param None -* @retval Status -*/ -SHCI_CmdStatus_t SHCI_C2_DEBUG_Init(SHCI_C2_DEBUG_Init_Cmd_Packet_t *pCmdPacket); - -/** -* SHCI_C2_FLASH_EraseActivity -* @brief Provides the information of the start and the end of a flash erase window on the CPU1 -* -* @param erase_activity: Start/End of erase activity -* @retval Status -*/ -SHCI_CmdStatus_t SHCI_C2_FLASH_EraseActivity(SHCI_EraseActivity_t erase_activity); - -/** -* SHCI_C2_CONCURRENT_SetMode -* @brief Enable/Disable Thread on CPU2 (M0+) -* -* @param Mode: BLE or Thread enable flag -* @retval Status -*/ -SHCI_CmdStatus_t SHCI_C2_CONCURRENT_SetMode(SHCI_C2_CONCURRENT_Mode_Param_t Mode); - -/** -* SHCI_C2_FLASH_StoreData -* @brief Store Data in Flash -* -* @param Ip: BLE or THREAD -* @retval Status -*/ -SHCI_CmdStatus_t SHCI_C2_FLASH_StoreData(SHCI_C2_FLASH_Ip_t Ip); - -/** -* SHCI_C2_FLASH_EraseData -* @brief Erase Data in Flash -* -* @param Ip: BLE or THREAD -* @retval Status -*/ -SHCI_CmdStatus_t SHCI_C2_FLASH_EraseData(SHCI_C2_FLASH_Ip_t Ip); - -/** -* SHCI_C2_RADIO_AllowLowPower -* @brief Allow or forbid IP_radio (802_15_4 or BLE) to enter in low power mode. -* -* @param Ip: BLE or 802_15_5 -* @param FlagRadioLowPowerOn: True or false -* @retval Status -*/ -SHCI_CmdStatus_t SHCI_C2_RADIO_AllowLowPower(SHCI_C2_FLASH_Ip_t Ip, uint8_t FlagRadioLowPowerOn); - -/** - * SHCI_GetWirelessFwInfo - * @brief This function read back the information relative to the wireless binary loaded. - * Refer yourself to SHCI_WirelessFwInfoTable_t structure to get the significance - * of the different parameters returned. - * @param pWirelessInfo : Pointer to WirelessFwInfo_t. - * - * @retval SHCI_Success - */ -SHCI_CmdStatus_t SHCI_GetWirelessFwInfo(WirelessFwInfo_t *pWirelessInfo); - -/** -* SHCI_C2_Reinit -* @brief This is required to allow the CPU1 to fake a set C2BOOT when it has already been set. -* In order to fake a C2BOOT, the CPU1 shall : -* - Send SHCI_C2_Reinit() -* - call SEV instruction -* WARNING: -* This function is intended to be used by the SBSFU -* -* @param None -* @retval Status -*/ -SHCI_CmdStatus_t SHCI_C2_Reinit(void); - -/** -* SHCI_C2_ExtpaConfig -* @brief Send the Ext PA configuration -* When the CPU2 receives the command, it controls the Ext PA as requested by the configuration -* This configures only which IO is used to enable/disable the ExtPA and the associated polarity -* This command has no effect on the other IO that is used to control the mode of the Ext PA (Rx/Tx) -* -* @param gpio_port: GPIOx where x can be (A..F) to select the GPIO peripheral for STM32WBxx family -* @param gpio_pin_number: This parameter can be one of GPIO_PIN_x (= LL_GPIO_PIN_x) where x can be (0..15). -* @param gpio_polarity: This parameter can be either -* - EXT_PA_ENABLED_LOW: ExtPA is enabled when GPIO is low -* - EXT_PA_ENABLED_HIGH: ExtPA is enabled when GPIO is high -* @param gpio_status: This parameter can be either -* - EXT_PA_DISABLED: Stop driving the ExtPA -* - EXT_PA_ENABLED: Drive the ExtPA according to radio activity -* (ON before the Event and OFF at the end of the event) -* @retval Status -*/ -SHCI_CmdStatus_t SHCI_C2_ExtpaConfig(uint32_t gpio_port, uint16_t gpio_pin_number, uint8_t gpio_polarity, uint8_t gpio_status); - -/** -* SHCI_C2_SetFlashActivityControl -* @brief Set the mechanism to be used on CPU2 to prevent the CPU1 to either write or erase in flash -* -* @param Source: It can be one of the following list -* - FLASH_ACTIVITY_CONTROL_PES : The CPU2 set the PES bit to prevent the CPU1 to either read or write in flash -* - FLASH_ACTIVITY_CONTROL_SEM7 : The CPU2 gets the semaphore 7 to prevent the CPU1 to either read or write in flash. -* This requires the CPU1 to first get semaphore 7 before erasing or writing the flash. -* -* @retval Status -*/ -SHCI_CmdStatus_t SHCI_C2_SetFlashActivityControl(SHCI_C2_SET_FLASH_ACTIVITY_CONTROL_Source_t Source); - -/** -* SHCI_C2_Config -* @brief Send the system configuration to the CPU2 -* -* @param pCmdPacket: address of the buffer holding following parameters -* uint8_t PayloadCmdSize : Size of the payload - shall be SHCI_C2_CONFIG_PAYLOAD_CMD_SIZE -* uint8_t Config1 : -* - bit0 : 0 - BLE NVM Data data are flushed in internal secure flash -* 1 - BLE NVM Data are written in SRAM cache pointed by BleNvmRamAddress -* - bit1 : 0 - THREAD NVM Data data are flushed in internal secure flash -* 1 - THREAD NVM Data are written in SRAM cache pointed by ThreadNvmRamAddress -* - bit2 to bit7 : Unused, shall be set to 0 -* uint8_t EvtMask1 : -* When a bit is set to 0, the event is not reported -* bit0 : Asynchronous Event with Sub Evt Code 0x9201 (= SHCI_SUB_EVT_ERROR_NOTIF) -* ... -* bit31 : Asynchronous Event with Sub Evt Code 0x9220 -* uint8_t Spare1 : Unused, shall be set to 0 -* uint32_t BleNvmRamAddress : -* Only considered when Config1.bit0 = 1 -* When set to 0, data are kept in internal SRAM on CPU2 -* Otherwise, data are copied in the cache pointed by BleNvmRamAddress -* The size of the buffer shall be BLE_NVM_SRAM_SIZE (number of 32bits) -* The buffer shall be allocated in SRAM2 -* uint32_t ThreadNvmRamAddress : -* Only considered when Config1.bit1 = 1 -* When set to 0, data are kept in internal SRAM on CPU2 -* Otherwise, data are copied in the cache pointed by ThreadNvmRamAddress -* The size of the buffer shall be THREAD_NVM_SRAM_SIZE (number of 32bits) -* The buffer shall be allocated in SRAM2 -* -* Please check macro definition to be used for this function -* They are defined in this file next to the definition of SHCI_OPCODE_C2_CONFIG -* -* @retval Status -*/ -SHCI_CmdStatus_t SHCI_C2_Config(SHCI_C2_CONFIG_Cmd_Param_t *pCmdPacket); - -#ifdef __cplusplus -} -#endif - -#endif /*__SHCI_H */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/src/utility/STM32Cube_FW/shci_tl.c b/src/utility/STM32Cube_FW/shci_tl.c deleted file mode 100644 index 1ab15b47..00000000 --- a/src/utility/STM32Cube_FW/shci_tl.c +++ /dev/null @@ -1,344 +0,0 @@ -/** - ****************************************************************************** - * @file shci.c - * @author MCD Application Team - * @brief System HCI command implementation - ****************************************************************************** - * @attention - * - * <h2><center>© Copyright (c) 2019 STMicroelectronics. - * All rights reserved.</center></h2> - * - * This software component is licensed by ST under BSD 3-Clause license, - * the "License"; You may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * opensource.org/licenses/BSD-3-Clause - * - ****************************************************************************** - */ - -#if defined(STM32WBxx) -/* Includes ------------------------------------------------------------------*/ -#include "stm32_wpan_common.h" - -#include "stm_list.h" -#include "shci_tl.h" -#include "stm32_def.h" - -/** - * These traces are not yet supported in an usual way in the delivery package - * They can enabled by adding the definition of TL_SHCI_CMD_DBG_EN and/or TL_SHCI_EVT_DBG_EN in the preprocessor option in the IDE - */ -#if ( (TL_SHCI_CMD_DBG_EN != 0) || (TL_SHCI_EVT_DBG_EN != 0) ) - #include "app_conf.h" - #include "dbg_trace.h" -#endif - -#if (TL_SHCI_CMD_DBG_EN != 0) - #define TL_SHCI_CMD_DBG_MSG PRINT_MESG_DBG - #define TL_SHCI_CMD_DBG_BUF PRINT_LOG_BUFF_DBG -#else - #define TL_SHCI_CMD_DBG_MSG(...) - #define TL_SHCI_CMD_DBG_BUF(...) -#endif - -#if (TL_SHCI_EVT_DBG_EN != 0) - #define TL_SHCI_EVT_DBG_MSG PRINT_MESG_DBG - #define TL_SHCI_EVT_DBG_BUF PRINT_LOG_BUFF_DBG -#else - #define TL_SHCI_EVT_DBG_MSG(...) - #define TL_SHCI_EVT_DBG_BUF(...) -#endif - -/* Private typedef -----------------------------------------------------------*/ -typedef enum { - SHCI_TL_CMD_RESP_RELEASE, - SHCI_TL_CMD_RESP_WAIT, -} SHCI_TL_CmdRespStatus_t; - -/* Private defines -----------------------------------------------------------*/ -/** - * The default System HCI layer timeout is set to 33s - */ -#define SHCI_TL_DEFAULT_TIMEOUT (33000) - -/* Private macros ------------------------------------------------------------*/ -/* Public variables ---------------------------------------------------------*/ -/* Private variables ---------------------------------------------------------*/ -/** - * START of Section SYSTEM_DRIVER_CONTEXT - */ -PLACE_IN_SECTION("SYSTEM_DRIVER_CONTEXT") static tListNode SHciAsynchEventQueue; -PLACE_IN_SECTION("SYSTEM_DRIVER_CONTEXT") static volatile SHCI_TL_CmdStatus_t SHCICmdStatus; -PLACE_IN_SECTION("SYSTEM_DRIVER_CONTEXT") static TL_CmdPacket_t *pCmdBuffer; -PLACE_IN_SECTION("SYSTEM_DRIVER_CONTEXT") SHCI_TL_UserEventFlowStatus_t SHCI_TL_UserEventFlow; -/** - * END of Section SYSTEM_DRIVER_CONTEXT - */ - -static tSHciContext shciContext; -static void (* StatusNotCallBackFunction)(SHCI_TL_CmdStatus_t status); - -static volatile SHCI_TL_CmdRespStatus_t CmdRspStatusFlag; - -/* Private function prototypes -----------------------------------------------*/ -static void Cmd_SetStatus(SHCI_TL_CmdStatus_t shcicmdstatus); -static void TlCmdEvtReceived(TL_EvtPacket_t *shcievt); -static void TlUserEvtReceived(TL_EvtPacket_t *shcievt); -static void TlInit(TL_CmdPacket_t *p_cmdbuffer); -static void OutputCmdTrace(TL_CmdPacket_t *pCmdBuffer); -static void OutputRspTrace(TL_EvtPacket_t *p_rsp); -static void OutputEvtTrace(TL_EvtPacket_t *phcievtbuffer); - -/* Interface ------- ---------------------------------------------------------*/ -void shci_init(void(* UserEvtRx)(void *pData), void *pConf) -{ - StatusNotCallBackFunction = ((SHCI_TL_HciInitConf_t *)pConf)->StatusNotCallBack; - shciContext.UserEvtRx = UserEvtRx; - - shci_register_io_bus(&shciContext.io); - - TlInit((TL_CmdPacket_t *)(((SHCI_TL_HciInitConf_t *)pConf)->p_cmdbuffer)); - - return; -} - -void shci_user_evt_proc(void) -{ - TL_EvtPacket_t *phcievtbuffer; - tSHCI_UserEvtRxParam UserEvtRxParam; - - /** - * Up to release version v1.2.0, a while loop was implemented to read out events from the queue as long as - * it is not empty. However, in a bare metal implementation, this leads to calling in a "blocking" mode - * shci_user_evt_proc() as long as events are received without giving the opportunity to run other tasks - * in the background. - * From now, the events are reported one by one. When it is checked there is still an event pending in the queue, - * a request to the user is made to call again shci_user_evt_proc(). - * This gives the opportunity to the application to run other background tasks between each event. - */ - - /** - * It is more secure to use LST_remove_head()/LST_insert_head() compare to LST_get_next_node()/LST_remove_node() - * in case the user overwrite the header where the next/prev pointers are located - */ - if ((LST_is_empty(&SHciAsynchEventQueue) == FALSE) && (SHCI_TL_UserEventFlow != SHCI_TL_UserEventFlow_Disable)) { - LST_remove_head(&SHciAsynchEventQueue, (tListNode **)&phcievtbuffer); - - OutputEvtTrace(phcievtbuffer); - - if (shciContext.UserEvtRx != NULL) { - UserEvtRxParam.pckt = phcievtbuffer; - UserEvtRxParam.status = SHCI_TL_UserEventFlow_Enable; - shciContext.UserEvtRx((void *)&UserEvtRxParam); - SHCI_TL_UserEventFlow = UserEvtRxParam.status; - } else { - SHCI_TL_UserEventFlow = SHCI_TL_UserEventFlow_Enable; - } - - if (SHCI_TL_UserEventFlow != SHCI_TL_UserEventFlow_Disable) { - TL_MM_EvtDone(phcievtbuffer); - } else { - /** - * put back the event in the queue - */ - LST_insert_head(&SHciAsynchEventQueue, (tListNode *)phcievtbuffer); - } - } - - if ((LST_is_empty(&SHciAsynchEventQueue) == FALSE) && (SHCI_TL_UserEventFlow != SHCI_TL_UserEventFlow_Disable)) { - shci_notify_asynch_evt((void *) &SHciAsynchEventQueue); - } - - return; -} - -void shci_resume_flow(void) -{ - SHCI_TL_UserEventFlow = SHCI_TL_UserEventFlow_Enable; - - /** - * It is better to go through the background process as it is not sure from which context this API may - * be called - */ - shci_notify_asynch_evt((void *) &SHciAsynchEventQueue); - - return; -} - -void shci_send(uint16_t cmd_code, uint8_t len_cmd_payload, uint8_t *p_cmd_payload, TL_EvtPacket_t *p_rsp) -{ - Cmd_SetStatus(SHCI_TL_CmdBusy); - - pCmdBuffer->cmdserial.cmd.cmdcode = cmd_code; - pCmdBuffer->cmdserial.cmd.plen = len_cmd_payload; - - memcpy(pCmdBuffer->cmdserial.cmd.payload, p_cmd_payload, len_cmd_payload); - - OutputCmdTrace(pCmdBuffer); - - shciContext.io.Send(0, 0); - - shci_cmd_resp_wait(SHCI_TL_DEFAULT_TIMEOUT); - - /** - * The command complete of a system command does not have the header - * It starts immediately with the evtserial field - */ - memcpy(&(p_rsp->evtserial), pCmdBuffer, ((TL_EvtSerial_t *)pCmdBuffer)->evt.plen + TL_EVT_HDR_SIZE); - - OutputRspTrace(p_rsp); - - Cmd_SetStatus(SHCI_TL_CmdAvailable); - - return; -} - -void shci_notify_asynch_evt(void *pdata) -{ - UNUSED(pdata); - /* Need to parse data in future version */ - shci_user_evt_proc(); -} - -void shci_register_io_bus(tSHciIO *fops) -{ - /* Register IO bus services */ - fops->Init = TL_SYS_Init; - fops->Send = TL_SYS_SendCmd; -} - -/* Private functions ---------------------------------------------------------*/ -static void TlInit(TL_CmdPacket_t *p_cmdbuffer) -{ - TL_SYS_InitConf_t Conf; - - pCmdBuffer = p_cmdbuffer; - - LST_init_head(&SHciAsynchEventQueue); - - Cmd_SetStatus(SHCI_TL_CmdAvailable); - - SHCI_TL_UserEventFlow = SHCI_TL_UserEventFlow_Enable; - - /* Initialize low level driver */ - if (shciContext.io.Init) { - - Conf.p_cmdbuffer = (uint8_t *)p_cmdbuffer; - Conf.IoBusCallBackCmdEvt = TlCmdEvtReceived; - Conf.IoBusCallBackUserEvt = TlUserEvtReceived; - shciContext.io.Init(&Conf); - } - - return; -} - -static void Cmd_SetStatus(SHCI_TL_CmdStatus_t shcicmdstatus) -{ - if (shcicmdstatus == SHCI_TL_CmdBusy) { - if (StatusNotCallBackFunction != 0) { - StatusNotCallBackFunction(SHCI_TL_CmdBusy); - } - SHCICmdStatus = SHCI_TL_CmdBusy; - } else { - SHCICmdStatus = SHCI_TL_CmdAvailable; - if (StatusNotCallBackFunction != 0) { - StatusNotCallBackFunction(SHCI_TL_CmdAvailable); - } - } - - return; -} - -static void TlCmdEvtReceived(TL_EvtPacket_t *shcievt) -{ - (void)(shcievt); - shci_cmd_resp_release(0); /**< Notify the application the Cmd response has been received */ - - return; -} - -static void TlUserEvtReceived(TL_EvtPacket_t *shcievt) -{ - LST_insert_tail(&SHciAsynchEventQueue, (tListNode *)shcievt); - shci_notify_asynch_evt((void *) &SHciAsynchEventQueue); /**< Notify the application a full HCI event has been received */ - - return; -} - -static void OutputCmdTrace(TL_CmdPacket_t *pCmdBuffer) -{ - TL_SHCI_CMD_DBG_MSG("sys cmd: 0x%04X", pCmdBuffer->cmdserial.cmd.cmdcode); - - if (pCmdBuffer->cmdserial.cmd.plen != 0) { - TL_SHCI_CMD_DBG_MSG(" payload:"); - TL_SHCI_CMD_DBG_BUF(pCmdBuffer->cmdserial.cmd.payload, pCmdBuffer->cmdserial.cmd.plen, ""); - } - TL_SHCI_CMD_DBG_MSG("\r\n"); - - return; -} - -static void OutputRspTrace(TL_EvtPacket_t *p_rsp) -{ - switch (p_rsp->evtserial.evt.evtcode) { - case TL_BLEEVT_CC_OPCODE: - TL_SHCI_CMD_DBG_MSG("sys rsp: 0x%02X", p_rsp->evtserial.evt.evtcode); - TL_SHCI_CMD_DBG_MSG(" cmd opcode: 0x%02X", ((TL_CcEvt_t *)(p_rsp->evtserial.evt.payload))->cmdcode); - TL_SHCI_CMD_DBG_MSG(" status: 0x%02X", ((TL_CcEvt_t *)(p_rsp->evtserial.evt.payload))->payload[0]); - if ((p_rsp->evtserial.evt.plen - 4) != 0) { - TL_SHCI_CMD_DBG_MSG(" payload:"); - TL_SHCI_CMD_DBG_BUF(&((TL_CcEvt_t *)(p_rsp->evtserial.evt.payload))->payload[1], p_rsp->evtserial.evt.plen - 4, ""); - } - break; - - default: - TL_SHCI_CMD_DBG_MSG("unknown sys rsp received: %02X", p_rsp->evtserial.evt.evtcode); - break; - } - - TL_SHCI_CMD_DBG_MSG("\r\n"); - - return; -} - -static void OutputEvtTrace(TL_EvtPacket_t *phcievtbuffer) -{ - if (phcievtbuffer->evtserial.evt.evtcode != TL_BLEEVT_VS_OPCODE) { - TL_SHCI_EVT_DBG_MSG("unknown sys evt received: %02X", phcievtbuffer->evtserial.evt.evtcode); - } else { - TL_SHCI_EVT_DBG_MSG("sys evt: 0x%02X", phcievtbuffer->evtserial.evt.evtcode); - TL_SHCI_EVT_DBG_MSG(" subevtcode: 0x%04X", ((TL_AsynchEvt_t *)(phcievtbuffer->evtserial.evt.payload))->subevtcode); - if ((phcievtbuffer->evtserial.evt.plen - 2) != 0) { - TL_SHCI_EVT_DBG_MSG(" payload:"); - TL_SHCI_EVT_DBG_BUF(((TL_AsynchEvt_t *)(phcievtbuffer->evtserial.evt.payload))->payload, phcievtbuffer->evtserial.evt.plen - 2, ""); - } - } - - TL_SHCI_EVT_DBG_MSG("\r\n"); - - return; -} - -/* Weak implementation ----------------------------------------------------------------*/ -__WEAK void shci_cmd_resp_wait(uint32_t timeout) -{ - (void)timeout; - - CmdRspStatusFlag = SHCI_TL_CMD_RESP_WAIT; - while (CmdRspStatusFlag != SHCI_TL_CMD_RESP_RELEASE); - - return; -} - -__WEAK void shci_cmd_resp_release(uint32_t flag) -{ - (void)flag; - - CmdRspStatusFlag = SHCI_TL_CMD_RESP_RELEASE; - - return; -} - -#endif /* STM32WBxx */ - diff --git a/src/utility/STM32Cube_FW/shci_tl.h b/src/utility/STM32Cube_FW/shci_tl.h deleted file mode 100644 index f6cc8043..00000000 --- a/src/utility/STM32Cube_FW/shci_tl.h +++ /dev/null @@ -1,169 +0,0 @@ -/** - ****************************************************************************** - * @file shci_tl.h - * @author MCD Application Team - * @brief System HCI command header for the system channel - ****************************************************************************** - * @attention - * - * <h2><center>© Copyright (c) 2019 STMicroelectronics. - * All rights reserved.</center></h2> - * - * This software component is licensed by ST under BSD 3-Clause license, - * the "License"; You may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * opensource.org/licenses/BSD-3-Clause - * - ****************************************************************************** - */ - - -#ifndef __SHCI_TL_H_ -#define __SHCI_TL_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#include "tl.h" - -/* Exported defines -----------------------------------------------------------*/ -typedef enum { - SHCI_TL_UserEventFlow_Disable, - SHCI_TL_UserEventFlow_Enable, -} SHCI_TL_UserEventFlowStatus_t; - -typedef enum { - SHCI_TL_CmdBusy, - SHCI_TL_CmdAvailable -} SHCI_TL_CmdStatus_t; - -/** - * @brief Structure used to manage the BUS IO operations. - * All the structure fields will point to functions defined at user level. - * @{ - */ -typedef struct { - int32_t (* Init)(void *pConf); /**< Pointer to SHCI TL function for the IO Bus initialization */ - int32_t (* DeInit)(void); /**< Pointer to SHCI TL function for the IO Bus de-initialization */ - int32_t (* Reset)(void); /**< Pointer to SHCI TL function for the IO Bus reset */ - int32_t (* Receive)(uint8_t *, uint16_t); /**< Pointer to SHCI TL function for the IO Bus data reception */ - int32_t (* Send)(uint8_t *, uint16_t); /**< Pointer to SHCI TL function for the IO Bus data transmission */ - int32_t (* DataAck)(uint8_t *, uint16_t *len); /**< Pointer to SHCI TL function for the IO Bus data ack reception */ - int32_t (* GetTick)(void); /**< Pointer to BSP function for getting the HAL time base timestamp */ -} tSHciIO; -/** - * @} - */ - -/** - * @brief Contain the SHCI context - * @{ - */ -typedef struct { - tSHciIO io; /**< Manage the BUS IO operations */ - void (* UserEvtRx)(void *pData); /**< User System events callback function pointer */ -} tSHciContext; - -typedef struct { - SHCI_TL_UserEventFlowStatus_t status; - TL_EvtPacket_t *pckt; -} tSHCI_UserEvtRxParam; - -typedef struct { - uint8_t *p_cmdbuffer; - void (* StatusNotCallBack)(SHCI_TL_CmdStatus_t status); -} SHCI_TL_HciInitConf_t; - -/** - * shci_send - * @brief Send an System HCI Command - * - * @param : cmd_code = Opcode of the command - * @param : len_cmd_payload = Length of the command payload - * @param : p_cmd_payload = Address of the command payload - * @param : p_rsp_status = Address of the full buffer holding the command complete event - * @retval : None - */ -void shci_send(uint16_t cmd_code, uint8_t len_cmd_payload, uint8_t *p_cmd_payload, TL_EvtPacket_t *p_rsp_status); - -/** - * @brief Register IO bus services. - * @param fops The SHCI IO structure managing the IO BUS - * @retval None - */ -void shci_register_io_bus(tSHciIO *fops); - -/** - * @brief Interrupt service routine that must be called when the system channel - * reports a packet has been received - * - * @param pdata Packet or event pointer - * @retval None - */ -void shci_notify_asynch_evt(void *pdata); - -/** - * @brief This function resume the User Event Flow which has been stopped on return - * from UserEvtRx() when the User Event has not been processed. - * - * @param None - * @retval None - */ -void shci_resume_flow(void); - - -/** - * @brief This function is called when an System HCI Command is sent to the CPU2 and the response is waited. - * It is called from the same context the System HCI command has been sent. - * It shall not return until the command response notified by shci_cmd_resp_release() is received. - * A weak implementation is available in shci_tl.c based on polling mechanism - * The user may re-implement this function in the application to improve performance : - * - It may use UTIL_SEQ_WaitEvt() API when using the Sequencer - * - It may use a semaphore when using cmsis_os interface - * - * @param timeout: Waiting timeout - * @retval None - */ -void shci_cmd_resp_wait(uint32_t timeout); - -/** - * @brief This function is called when an System HCI command is received from the CPU2. - * A weak implementation is available in shci_tl.c based on polling mechanism - * The user may re-implement this function in the application to improve performance : - * - It may use UTIL_SEQ_SetEvt() API when using the Sequencer - * - It may use a semaphore when using cmsis_os interface - * - * - * @param flag: Release flag - * @retval None - */ -void shci_cmd_resp_release(uint32_t flag); - - -/** - * @brief This process shall be called each time the shci_notify_asynch_evt notification is received - * - * @param None - * @retval None - */ - -void shci_user_evt_proc(void); - -/** - * @brief Initialize the System Host Controller Interface. - * This function must be called before any communication on the System Channel - * - * @param pData: System events callback function pointer - * This callback is triggered when an user event is received on - * the System Channel from CPU2. - * @param pConf: Configuration structure pointer - * @retval None - */ -void shci_init(void(* UserEvtRx)(void *pData), void *pConf); - -#ifdef __cplusplus -} -#endif - -#endif /* __SHCI_TL_H_ */ diff --git a/src/utility/STM32Cube_FW/stm32_wpan_common.h b/src/utility/STM32Cube_FW/stm32_wpan_common.h deleted file mode 100644 index 12f1a583..00000000 --- a/src/utility/STM32Cube_FW/stm32_wpan_common.h +++ /dev/null @@ -1,143 +0,0 @@ -/** - ****************************************************************************** - * @file stm32_wpan_common.h - * @author MCD Application Team - * @brief Common file to utilities - ****************************************************************************** - * @attention - * - * <h2><center>© Copyright (c) 2018 STMicroelectronics. - * All rights reserved.</center></h2> - * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 - * - ****************************************************************************** - */ - - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __STM32_WPAN_COMMON_H -#define __STM32_WPAN_COMMON_H - -#ifdef __cplusplus -extern "C" { -#endif - -#define __ASM __asm /*!< asm keyword for GNU Compiler */ -#define __INLINE inline /*!< inline keyword for GNU Compiler */ -#define __STATIC_INLINE static inline - -#include <stdint.h> -#include <string.h> -#include <stdio.h> -#include <stdlib.h> -#include <stdarg.h> -#include "cmsis_compiler.h" - -/* -------------------------------- * - * Basic definitions * - * -------------------------------- */ - -#undef NULL -#define NULL 0U - -#undef FALSE -#define FALSE 0U - -#undef TRUE -#define TRUE (!0U) - -/* -------------------------------- * - * Critical Section definition * - * -------------------------------- */ -#undef BACKUP_PRIMASK -#define BACKUP_PRIMASK() uint32_t primask_bit= __get_PRIMASK() - -#undef DISABLE_IRQ -#define DISABLE_IRQ() __disable_irq() - -#undef RESTORE_PRIMASK -#define RESTORE_PRIMASK() __set_PRIMASK(primask_bit) - -/* -------------------------------- * - * Macro delimiters * - * -------------------------------- */ -#undef M_BEGIN -#define M_BEGIN do { - -#undef M_END -#define M_END } while(0) - -/* -------------------------------- * - * Some useful macro definitions * - * -------------------------------- */ -#undef MAX -#define MAX(a, b) (((a) > (b)) ? (a) : (b)) - -#undef MIN -#define MIN(a, b) (((a) < (b)) ? (a) : (b)) - -#undef MODINC -#define MODINC( a, m ) M_BEGIN (a)++; if ((a)>=(m)) (a)=0; M_END - -#undef MODDEC -#define MODDEC( a, m ) M_BEGIN if ((a)==0) (a)=(m); (a)--; M_END - -#undef MODADD -#define MODADD( a, b, m ) M_BEGIN (a)+=(b); if ((a)>=(m)) (a)-=(m); M_END - -#undef MODSUB -#define MODSUB( a, b, m ) MODADD( a, (m)-(b), m ) - -#undef ALIGN -#ifdef WIN32 -#define ALIGN(n) -#else -#define ALIGN(n) __attribute__((aligned(n))) -#endif - -#undef PAUSE -#define PAUSE( t ) M_BEGIN \ - volatile int _i; \ - for ( _i = t; _i > 0; _i -- ); \ - M_END -#undef DIVF -#define DIVF( x, y ) ((x)/(y)) - -#undef DIVC -#define DIVC( x, y ) (((x)+(y)-1)/(y)) - -#undef DIVR -#define DIVR( x, y ) (((x)+((y)/2))/(y)) - -#undef SHRR -#define SHRR( x, n ) ((((x)>>((n)-1))+1)>>1) - -#undef BITN -#define BITN( w, n ) (((w)[(n)/32] >> ((n)%32)) & 1) - -#undef BITNSET -#define BITNSET( w, n, b ) M_BEGIN (w)[(n)/32] |= ((U32)(b))<<((n)%32); M_END - -/* -------------------------------- * - * Section attribute * - * -------------------------------- */ -#undef PLACE_IN_SECTION -#define PLACE_IN_SECTION( __x__ ) __attribute__((section (__x__))) - -/* ----------------------------------- * - * Packed usage (compiler dependent) * - * ----------------------------------- */ -#undef PACKED_STRUCT -#define PACKED_STRUCT struct __packed - -#ifdef __cplusplus -} -#endif - -#endif /*__STM32_WPAN_COMMON_H */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/src/utility/STM32Cube_FW/stm_list.c b/src/utility/STM32Cube_FW/stm_list.c deleted file mode 100644 index 509b2b57..00000000 --- a/src/utility/STM32Cube_FW/stm_list.c +++ /dev/null @@ -1,206 +0,0 @@ -/** - ****************************************************************************** - * @file stm_list.c - * @author MCD Application Team - * @brief TCircular Linked List Implementation. - ****************************************************************************** - * @attention - * - * <h2><center>© Copyright (c) 2019 STMicroelectronics. - * All rights reserved.</center></h2> - * - * This software component is licensed by ST under BSD 3-Clause license, - * the "License"; You may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * opensource.org/licenses/BSD-3-Clause - * - ****************************************************************************** - */ - -#if defined(STM32WBxx) -/****************************************************************************** - * Include Files - ******************************************************************************/ -#include "stm_list.h" -#include "cmsis_gcc.h" -#include "stm32_wpan_common.h" - -/****************************************************************************** - * Function Definitions - ******************************************************************************/ -void LST_init_head(tListNode *listHead) -{ - listHead->next = listHead; - listHead->prev = listHead; -} - -bool LST_is_empty(tListNode *listHead) -{ - uint32_t primask_bit; - bool return_value; - - primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ - __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ - if (listHead->next == listHead) { - return_value = TRUE; - } else { - return_value = FALSE; - } - __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ - - return return_value; -} - -void LST_insert_head(tListNode *listHead, tListNode *node) -{ - uint32_t primask_bit; - - primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ - __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ - - node->next = listHead->next; - node->prev = listHead; - listHead->next = node; - (node->next)->prev = node; - - __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ -} - - -void LST_insert_tail(tListNode *listHead, tListNode *node) -{ - uint32_t primask_bit; - - primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ - __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ - - node->next = listHead; - node->prev = listHead->prev; - listHead->prev = node; - (node->prev)->next = node; - - __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ -} - - -void LST_remove_node(tListNode *node) -{ - uint32_t primask_bit; - - primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ - __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ - - (node->prev)->next = node->next; - (node->next)->prev = node->prev; - - __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ -} - - -void LST_remove_head(tListNode *listHead, tListNode **node) -{ - uint32_t primask_bit; - - primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ - __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ - - *node = listHead->next; - LST_remove_node(listHead->next); - - __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ -} - - -void LST_remove_tail(tListNode *listHead, tListNode **node) -{ - uint32_t primask_bit; - - primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ - __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ - - *node = listHead->prev; - LST_remove_node(listHead->prev); - - __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ -} - - -void LST_insert_node_after(tListNode *node, tListNode *ref_node) -{ - uint32_t primask_bit; - - primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ - __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ - - node->next = ref_node->next; - node->prev = ref_node; - ref_node->next = node; - (node->next)->prev = node; - - __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ -} - - -void LST_insert_node_before(tListNode *node, tListNode *ref_node) -{ - uint32_t primask_bit; - - primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ - __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ - - node->next = ref_node; - node->prev = ref_node->prev; - ref_node->prev = node; - (node->prev)->next = node; - - __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ -} - - -int LST_get_size(tListNode *listHead) -{ - int size = 0; - tListNode *temp; - uint32_t primask_bit; - - primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ - __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ - - temp = listHead->next; - while (temp != listHead) { - size++; - temp = temp->next; - } - - __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ - - return (size); -} - -void LST_get_next_node(tListNode *ref_node, tListNode **node) -{ - uint32_t primask_bit; - - primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ - __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ - - *node = ref_node->next; - - __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ -} - - -void LST_get_prev_node(tListNode *ref_node, tListNode **node) -{ - uint32_t primask_bit; - - primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ - __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ - - *node = ref_node->prev; - - __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ -} - -#endif /* STM32WBxx */ - diff --git a/src/utility/STM32Cube_FW/stm_list.h b/src/utility/STM32Cube_FW/stm_list.h deleted file mode 100644 index b5f1cc8d..00000000 --- a/src/utility/STM32Cube_FW/stm_list.h +++ /dev/null @@ -1,58 +0,0 @@ -/** - ****************************************************************************** - * @file stm_list.h - * @author MCD Application Team - * @brief Header file for linked list library. - ****************************************************************************** - * @attention - * - * <h2><center>© Copyright (c) 2019 STMicroelectronics. - * All rights reserved.</center></h2> - * - * This software component is licensed by ST under BSD 3-Clause license, - * the "License"; You may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * opensource.org/licenses/BSD-3-Clause - * - ****************************************************************************** - */ - - -#ifndef _STM_LIST_H_ -#define _STM_LIST_H_ - -/* Includes ------------------------------------------------------------------*/ - -#include "stdint.h" -#include "stdbool.h" - -typedef struct _tListNode { - struct _tListNode *next; - struct _tListNode *prev; -} tListNode; - -void LST_init_head(tListNode *listHead); - -bool LST_is_empty(tListNode *listHead); - -void LST_insert_head(tListNode *listHead, tListNode *node); - -void LST_insert_tail(tListNode *listHead, tListNode *node); - -void LST_remove_node(tListNode *node); - -void LST_remove_head(tListNode *listHead, tListNode **node); - -void LST_remove_tail(tListNode *listHead, tListNode **node); - -void LST_insert_node_after(tListNode *node, tListNode *ref_node); - -void LST_insert_node_before(tListNode *node, tListNode *ref_node); - -int LST_get_size(tListNode *listHead); - -void LST_get_next_node(tListNode *ref_node, tListNode **node); - -void LST_get_prev_node(tListNode *ref_node, tListNode **node); - -#endif /* _STM_LIST_H_ */ diff --git a/src/utility/STM32Cube_FW/tl.h b/src/utility/STM32Cube_FW/tl.h deleted file mode 100644 index f8abf288..00000000 --- a/src/utility/STM32Cube_FW/tl.h +++ /dev/null @@ -1,294 +0,0 @@ -/** - ****************************************************************************** - * @file tl.h - * @author MCD Application Team - * @brief Header for tl module - ****************************************************************************** - * @attention - * - * <h2><center>© Copyright (c) 2019 STMicroelectronics. - * All rights reserved.</center></h2> - * - * This software component is licensed by ST under BSD 3-Clause license, - * the "License"; You may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * opensource.org/licenses/BSD-3-Clause - * - ****************************************************************************** - */ - - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __TL_H -#define __TL_H - -#ifdef __cplusplus -extern "C" { -#endif - - -/* Includes ------------------------------------------------------------------*/ -#include "stm32_wpan_common.h" - -/* Exported defines -----------------------------------------------------------*/ -#define TL_BLECMD_PKT_TYPE ( 0x01 ) -#define TL_ACL_DATA_PKT_TYPE ( 0x02 ) -#define TL_BLEEVT_PKT_TYPE ( 0x04 ) -#define TL_OTCMD_PKT_TYPE ( 0x08 ) -#define TL_OTRSP_PKT_TYPE ( 0x09 ) -#define TL_CLICMD_PKT_TYPE ( 0x0A ) -#define TL_OTNOT_PKT_TYPE ( 0x0C ) -#define TL_OTACK_PKT_TYPE ( 0x0D ) -#define TL_CLINOT_PKT_TYPE ( 0x0E ) -#define TL_CLIACK_PKT_TYPE ( 0x0F ) -#define TL_SYSCMD_PKT_TYPE ( 0x10 ) -#define TL_SYSRSP_PKT_TYPE ( 0x11 ) -#define TL_SYSEVT_PKT_TYPE ( 0x12 ) -#define TL_CLIRESP_PKT_TYPE ( 0x15 ) -#define TL_M0CMD_PKT_TYPE ( 0x16 ) -#define TL_LOCCMD_PKT_TYPE ( 0x20 ) -#define TL_LOCRSP_PKT_TYPE ( 0x21 ) -#define TL_TRACES_APP_PKT_TYPE ( 0x40 ) -#define TL_TRACES_WL_PKT_TYPE ( 0x41 ) - -#define TL_CMD_HDR_SIZE (4) -#define TL_EVT_HDR_SIZE (3) -#define TL_EVT_CS_PAYLOAD_SIZE (4) - -#define TL_BLEEVT_CC_OPCODE (0x0E) -#define TL_BLEEVT_CS_OPCODE (0x0F) -#define TL_BLEEVT_VS_OPCODE (0xFF) - -#define TL_BLEEVT_CS_PACKET_SIZE (TL_EVT_HDR_SIZE + sizeof(TL_CsEvt_t)) -#define TL_BLEEVT_CS_BUFFER_SIZE (sizeof(TL_PacketHeader_t) + TL_BLEEVT_CS_PACKET_SIZE) - -/* Exported types ------------------------------------------------------------*/ -/**< Packet header */ -typedef PACKED_STRUCT { - uint32_t *next; - uint32_t *prev; -} TL_PacketHeader_t; - -/******************************************************************************* - * Event type - */ - -/** - * This the payload of TL_Evt_t for a command status event - */ -typedef PACKED_STRUCT { - uint8_t status; - uint8_t numcmd; - uint16_t cmdcode; -} TL_CsEvt_t; - -/** - * This the payload of TL_Evt_t for a command complete event - */ -typedef PACKED_STRUCT { - uint8_t numcmd; - uint16_t cmdcode; - uint8_t payload[1]; -} TL_CcEvt_t; - -/** - * This the payload of TL_Evt_t for an asynchronous event - */ -typedef PACKED_STRUCT { - uint16_t subevtcode; - uint8_t payload[1]; -} TL_AsynchEvt_t; - -typedef PACKED_STRUCT { - uint8_t evtcode; - uint8_t plen; - uint8_t payload[1]; -} TL_Evt_t; - -typedef PACKED_STRUCT { - uint8_t type; - TL_Evt_t evt; -} TL_EvtSerial_t; - -/** - * This format shall be used for all events (asynchronous and command response) reported - * by the CPU2 except for the command response of a system command where the header is not there - * and the format to be used shall be TL_EvtSerial_t. - * Note: Be careful that the asynchronous events reported by the CPU2 on the system channel do - * include the header and shall use TL_EvtPacket_t format. Only the command response format on the - * system channel is different. - */ -typedef PACKED_STRUCT { - TL_PacketHeader_t header; - TL_EvtSerial_t evtserial; -} TL_EvtPacket_t; - -/***************************************************************************************** - * Command type - */ - -typedef PACKED_STRUCT { - uint16_t cmdcode; - uint8_t plen; - uint8_t payload[255]; -} TL_Cmd_t; - -typedef PACKED_STRUCT { - uint8_t type; - TL_Cmd_t cmd; -} TL_CmdSerial_t; - -typedef PACKED_STRUCT { - TL_PacketHeader_t header; - TL_CmdSerial_t cmdserial; -} TL_CmdPacket_t; - -/***************************************************************************************** - * HCI ACL DATA type - */ -typedef PACKED_STRUCT { - uint8_t type; - uint16_t handle; - uint16_t length; - uint8_t acl_data[1]; -} TL_AclDataSerial_t; - -typedef PACKED_STRUCT { - TL_PacketHeader_t header; - TL_AclDataSerial_t AclDataSerial; -} TL_AclDataPacket_t; - -typedef struct { - uint8_t *p_BleSpareEvtBuffer; - uint8_t *p_SystemSpareEvtBuffer; - uint8_t *p_AsynchEvtPool; - uint32_t AsynchEvtPoolSize; - uint8_t *p_TracesEvtPool; - uint32_t TracesEvtPoolSize; -} TL_MM_Config_t; - -typedef struct { - uint8_t *p_ThreadOtCmdRspBuffer; - uint8_t *p_ThreadCliRspBuffer; - uint8_t *p_ThreadNotAckBuffer; -} TL_TH_Config_t; - -typedef struct { - uint8_t *p_LldTestsCliCmdRspBuffer; - uint8_t *p_LldTestsM0CmdBuffer; -} TL_LLD_tests_Config_t; - -typedef struct { - uint8_t *p_LldBleCmdRspBuffer; - uint8_t *p_LldBleM0CmdBuffer; -} TL_LLD_BLE_Config_t; - -typedef struct { - uint8_t *p_Mac_802_15_4_CmdRspBuffer; - uint8_t *p_Mac_802_15_4_NotAckBuffer; -} TL_MAC_802_15_4_Config_t; - -typedef struct { - uint8_t *p_ZigbeeOtCmdRspBuffer; - uint8_t *p_ZigbeeNotAckBuffer; - uint8_t *p_ZigbeeNotifRequestBuffer; -} TL_ZIGBEE_Config_t; - -/** - * @brief Contain the BLE HCI Init Configuration - * @{ - */ -typedef struct { - void (* IoBusEvtCallBack)(TL_EvtPacket_t *phcievt); - void (* IoBusAclDataTxAck)(void); - uint8_t *p_cmdbuffer; - uint8_t *p_AclDataBuffer; -} TL_BLE_InitConf_t; - -/** - * @brief Contain the SYSTEM HCI Init Configuration - * @{ - */ -typedef struct { - void (* IoBusCallBackCmdEvt)(TL_EvtPacket_t *phcievt); - void (* IoBusCallBackUserEvt)(TL_EvtPacket_t *phcievt); - uint8_t *p_cmdbuffer; -} TL_SYS_InitConf_t; - -/* Exported constants --------------------------------------------------------*/ -/* External variables --------------------------------------------------------*/ -/* Exported macros -----------------------------------------------------------*/ -/* Exported functions ------------------------------------------------------- */ - -/****************************************************************************** - * GENERAL - ******************************************************************************/ -void TL_Enable(void); -void TL_Init(void); - -/****************************************************************************** - * BLE - ******************************************************************************/ -int32_t TL_BLE_Init(void *pConf); -int32_t TL_BLE_SendCmd(uint8_t *buffer, uint16_t size); -int32_t TL_BLE_SendAclData(uint8_t *buffer, uint16_t size); - -/****************************************************************************** - * SYSTEM - ******************************************************************************/ -int32_t TL_SYS_Init(void *pConf); -int32_t TL_SYS_SendCmd(uint8_t *buffer, uint16_t size); - -/****************************************************************************** - * THREAD - ******************************************************************************/ -void TL_THREAD_Init(TL_TH_Config_t *p_Config); -void TL_OT_SendCmd(void); -void TL_CLI_SendCmd(void); -void TL_OT_CmdEvtReceived(TL_EvtPacket_t *Otbuffer); -void TL_THREAD_NotReceived(TL_EvtPacket_t *Notbuffer); -void TL_THREAD_SendAck(void); -void TL_THREAD_CliSendAck(void); -void TL_THREAD_CliNotReceived(TL_EvtPacket_t *Notbuffer); - -/****************************************************************************** - * LLD TESTS - ******************************************************************************/ -void TL_LLDTESTS_Init(TL_LLD_tests_Config_t *p_Config); -void TL_LLDTESTS_SendCliCmd(void); -void TL_LLDTESTS_ReceiveCliRsp(TL_CmdPacket_t *Notbuffer); -void TL_LLDTESTS_SendCliRspAck(void); -void TL_LLDTESTS_ReceiveM0Cmd(TL_CmdPacket_t *Notbuffer); -void TL_LLDTESTS_SendM0CmdAck(void); - -/****************************************************************************** - * LLD BLE - ******************************************************************************/ -void TL_LLD_BLE_Init(TL_LLD_BLE_Config_t *p_Config); -void TL_LLD_BLE_SendCliCmd(void); -void TL_LLD_BLE_ReceiveCliRsp(TL_CmdPacket_t *Notbuffer); -void TL_LLD_BLE_SendCliRspAck(void); -void TL_LLD_BLE_ReceiveM0Cmd(TL_CmdPacket_t *Notbuffer); -void TL_LLD_BLE_SendM0CmdAck(void); -void TL_LLD_BLE_SendCmd(void); -void TL_LLD_BLE_ReceiveRsp(TL_CmdPacket_t *Notbuffer); -void TL_LLD_BLE_SendRspAck(void); -/****************************************************************************** - * MEMORY MANAGER - ******************************************************************************/ -void TL_MM_Init(TL_MM_Config_t *p_Config); -void TL_MM_EvtDone(TL_EvtPacket_t *hcievt); - -/****************************************************************************** - * TRACES - ******************************************************************************/ -void TL_TRACES_Init(void); -void TL_TRACES_EvtReceived(TL_EvtPacket_t *hcievt); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*__TL_H */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/src/utility/STM32Cube_FW/tl_mbox.c b/src/utility/STM32Cube_FW/tl_mbox.c deleted file mode 100644 index a235493d..00000000 --- a/src/utility/STM32Cube_FW/tl_mbox.c +++ /dev/null @@ -1,545 +0,0 @@ -/** - ****************************************************************************** - * @file tl_mbox.c - * @author MCD Application Team - * @brief Transport layer for the mailbox interface - ****************************************************************************** - * @attention - * - * <h2><center>© Copyright (c) 2019 STMicroelectronics. - * All rights reserved.</center></h2> - * - * This software component is licensed by ST under BSD 3-Clause license, - * the "License"; You may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * opensource.org/licenses/BSD-3-Clause - * - ****************************************************************************** - */ - -#if defined(STM32WBxx) -/* Includes ------------------------------------------------------------------*/ -#include "stm32_wpan_common.h" -#include "hw.h" - -#include "stm_list.h" -#include "tl.h" -#include "mbox_def.h" - -/** - * These traces are not yet supported in an usual way in the delivery package - * They can enabled by adding the definition of TL_MM_DBG_EN in the preprocessor option in the IDE - */ -#if(TL_MM_DBG_EN != 0) - #include "app_conf.h" - #include "dbg_trace.h" -#endif - -#if (TL_MM_DBG_EN != 0) - #define TL_MM_DBG__MSG PRINT_MESG_DBG -#else - #define TL_MM_DBG__MSG(...) -#endif - -/* Private typedef -----------------------------------------------------------*/ -/* Private defines -----------------------------------------------------------*/ -/* Private macros ------------------------------------------------------------*/ -/* Private variables ---------------------------------------------------------*/ - -/**< reference table */ -PLACE_IN_SECTION("MAPPING_TABLE") static volatile MB_RefTable_t TL_RefTable; -PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_DeviceInfoTable_t TL_DeviceInfoTable; -PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_BleTable_t TL_BleTable; -PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_ThreadTable_t TL_ThreadTable; -PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_LldTestsTable_t TL_LldTestsTable; -PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_LldBleTable_t TL_LldBleTable; -PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_SysTable_t TL_SysTable; -PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_MemManagerTable_t TL_MemManagerTable; -PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_TracesTable_t TL_TracesTable; - -/**< tables */ -PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode FreeBufQueue; -PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode TracesEvtQueue; -PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static uint8_t CsBuffer[sizeof(TL_PacketHeader_t) + TL_EVT_HDR_SIZE + sizeof(TL_CsEvt_t)]; -PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static tListNode EvtQueue; -PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static tListNode SystemEvtQueue; - - -static tListNode LocalFreeBufQueue; -static void (* BLE_IoBusEvtCallBackFunction)(TL_EvtPacket_t *phcievt); -static void (* BLE_IoBusAclDataTxAck)(void); -static void (* SYS_CMD_IoBusCallBackFunction)(TL_EvtPacket_t *phcievt); -static void (* SYS_EVT_IoBusCallBackFunction)(TL_EvtPacket_t *phcievt); - - -/* Global variables ----------------------------------------------------------*/ -/* Private function prototypes -----------------------------------------------*/ -static void SendFreeBuf(void); -static void OutputMemReleaseTrace(TL_EvtPacket_t *phcievt); - -/* Public Functions Definition ------------------------------------------------------*/ - -/****************************************************************************** - * GENERAL - ******************************************************************************/ -void TL_Enable(void) -{ - HW_IPCC_Enable(); - - return; -} - - -void TL_Init(void) -{ - TL_RefTable.p_device_info_table = &TL_DeviceInfoTable; - TL_RefTable.p_ble_table = &TL_BleTable; - TL_RefTable.p_thread_table = &TL_ThreadTable; - TL_RefTable.p_lld_tests_table = &TL_LldTestsTable; - TL_RefTable.p_lld_ble_table = &TL_LldBleTable; - TL_RefTable.p_sys_table = &TL_SysTable; - TL_RefTable.p_mem_manager_table = &TL_MemManagerTable; - TL_RefTable.p_traces_table = &TL_TracesTable; - - HW_IPCC_Init(); - - return; -} - -/****************************************************************************** - * BLE - ******************************************************************************/ -int32_t TL_BLE_Init(void *pConf) -{ - MB_BleTable_t *p_bletable; - - TL_BLE_InitConf_t *pInitHciConf = (TL_BLE_InitConf_t *) pConf; - - LST_init_head(&EvtQueue); - - p_bletable = TL_RefTable.p_ble_table; - - p_bletable->pcmd_buffer = pInitHciConf->p_cmdbuffer; - p_bletable->phci_acl_data_buffer = pInitHciConf->p_AclDataBuffer; - p_bletable->pcs_buffer = (uint8_t *)CsBuffer; - p_bletable->pevt_queue = (uint8_t *)&EvtQueue; - - HW_IPCC_BLE_Init(); - - BLE_IoBusEvtCallBackFunction = pInitHciConf->IoBusEvtCallBack; - BLE_IoBusAclDataTxAck = pInitHciConf->IoBusAclDataTxAck; - - return 0; -} - -int32_t TL_BLE_SendCmd(uint8_t *buffer, uint16_t size) -{ - (void)(buffer); - (void)(size); - - ((TL_CmdPacket_t *)(TL_RefTable.p_ble_table->pcmd_buffer))->cmdserial.type = TL_BLECMD_PKT_TYPE; - - HW_IPCC_BLE_SendCmd(); - - return 0; -} - -void HW_IPCC_BLE_RxEvtNot(void) -{ - TL_EvtPacket_t *phcievt; - - while (LST_is_empty(&EvtQueue) == FALSE) { - LST_remove_head(&EvtQueue, (tListNode **)&phcievt); - - BLE_IoBusEvtCallBackFunction(phcievt); - } - - return; -} - -int32_t TL_BLE_SendAclData(uint8_t *buffer, uint16_t size) -{ - (void)(buffer); - (void)(size); - - ((TL_AclDataPacket_t *)(TL_RefTable.p_ble_table->phci_acl_data_buffer))->AclDataSerial.type = TL_ACL_DATA_PKT_TYPE; - - HW_IPCC_BLE_SendAclData(); - - return 0; -} - -void HW_IPCC_BLE_AclDataAckNot(void) -{ - BLE_IoBusAclDataTxAck(); - - return; -} - -/****************************************************************************** - * SYSTEM - ******************************************************************************/ -int32_t TL_SYS_Init(void *pConf) -{ - MB_SysTable_t *p_systable; - - TL_SYS_InitConf_t *pInitHciConf = (TL_SYS_InitConf_t *) pConf; - - LST_init_head(&SystemEvtQueue); - p_systable = TL_RefTable.p_sys_table; - p_systable->pcmd_buffer = pInitHciConf->p_cmdbuffer; - p_systable->sys_queue = (uint8_t *)&SystemEvtQueue; - - HW_IPCC_SYS_Init(); - - SYS_CMD_IoBusCallBackFunction = pInitHciConf->IoBusCallBackCmdEvt; - SYS_EVT_IoBusCallBackFunction = pInitHciConf->IoBusCallBackUserEvt; - - return 0; -} - -int32_t TL_SYS_SendCmd(uint8_t *buffer, uint16_t size) -{ - (void)(buffer); - (void)(size); - - ((TL_CmdPacket_t *)(TL_RefTable.p_sys_table->pcmd_buffer))->cmdserial.type = TL_SYSCMD_PKT_TYPE; - - HW_IPCC_SYS_SendCmd(); - - return 0; -} - -void HW_IPCC_SYS_CmdEvtNot(void) -{ - SYS_CMD_IoBusCallBackFunction((TL_EvtPacket_t *)(TL_RefTable.p_sys_table->pcmd_buffer)); - - return; -} - -void HW_IPCC_SYS_EvtNot(void) -{ - TL_EvtPacket_t *p_evt; - - while (LST_is_empty(&SystemEvtQueue) == FALSE) { - LST_remove_head(&SystemEvtQueue, (tListNode **)&p_evt); - SYS_EVT_IoBusCallBackFunction(p_evt); - } - - return; -} - -/****************************************************************************** - * THREAD - ******************************************************************************/ -#ifdef THREAD_WB -void TL_THREAD_Init(TL_TH_Config_t *p_Config) -{ - MB_ThreadTable_t *p_thread_table; - - p_thread_table = TL_RefTable.p_thread_table; - - p_thread_table->clicmdrsp_buffer = p_Config->p_ThreadCliRspBuffer; - p_thread_table->otcmdrsp_buffer = p_Config->p_ThreadOtCmdRspBuffer; - p_thread_table->notack_buffer = p_Config->p_ThreadNotAckBuffer; - - HW_IPCC_THREAD_Init(); - - return; -} - -void TL_OT_SendCmd(void) -{ - ((TL_CmdPacket_t *)(TL_RefTable.p_thread_table->otcmdrsp_buffer))->cmdserial.type = TL_OTCMD_PKT_TYPE; - - HW_IPCC_OT_SendCmd(); - - return; -} - -void TL_CLI_SendCmd(void) -{ - ((TL_CmdPacket_t *)(TL_RefTable.p_thread_table->clicmdrsp_buffer))->cmdserial.type = TL_CLICMD_PKT_TYPE; - - HW_IPCC_CLI_SendCmd(); - - return; -} - -void TL_THREAD_SendAck(void) -{ - ((TL_CmdPacket_t *)(TL_RefTable.p_thread_table->notack_buffer))->cmdserial.type = TL_OTACK_PKT_TYPE; - - HW_IPCC_THREAD_SendAck(); - - return; -} - -void TL_THREAD_CliSendAck(void) -{ - ((TL_CmdPacket_t *)(TL_RefTable.p_thread_table->notack_buffer))->cmdserial.type = TL_OTACK_PKT_TYPE; - - HW_IPCC_THREAD_CliSendAck(); - - return; -} - -void HW_IPCC_OT_CmdEvtNot(void) -{ - TL_OT_CmdEvtReceived((TL_EvtPacket_t *)(TL_RefTable.p_thread_table->otcmdrsp_buffer)); - - return; -} - -void HW_IPCC_THREAD_EvtNot(void) -{ - TL_THREAD_NotReceived((TL_EvtPacket_t *)(TL_RefTable.p_thread_table->notack_buffer)); - - return; -} - -void HW_IPCC_THREAD_CliEvtNot(void) -{ - TL_THREAD_CliNotReceived((TL_EvtPacket_t *)(TL_RefTable.p_thread_table->clicmdrsp_buffer)); - - return; -} - -__WEAK void TL_OT_CmdEvtReceived(TL_EvtPacket_t *Otbuffer) {}; -__WEAK void TL_THREAD_NotReceived(TL_EvtPacket_t *Notbuffer) {}; -__WEAK void TL_THREAD_CliNotReceived(TL_EvtPacket_t *Notbuffer) {}; - -#endif /* THREAD_WB */ - -/****************************************************************************** - * LLD TESTS - ******************************************************************************/ -#ifdef LLD_TESTS_WB -void TL_LLDTESTS_Init(TL_LLD_tests_Config_t *p_Config) -{ - MB_LldTestsTable_t *p_lld_tests_table; - - p_lld_tests_table = TL_RefTable.p_lld_tests_table; - p_lld_tests_table->clicmdrsp_buffer = p_Config->p_LldTestsCliCmdRspBuffer; - p_lld_tests_table->m0cmd_buffer = p_Config->p_LldTestsM0CmdBuffer; - HW_IPCC_LLDTESTS_Init(); - return; -} - -void TL_LLDTESTS_SendCliCmd(void) -{ - ((TL_CmdPacket_t *)(TL_RefTable.p_lld_tests_table->clicmdrsp_buffer))->cmdserial.type = TL_CLICMD_PKT_TYPE; - HW_IPCC_LLDTESTS_SendCliCmd(); - return; -} - -void HW_IPCC_LLDTESTS_ReceiveCliRsp(void) -{ - TL_LLDTESTS_ReceiveCliRsp((TL_CmdPacket_t *)(TL_RefTable.p_lld_tests_table->clicmdrsp_buffer)); - return; -} - -void TL_LLDTESTS_SendCliRspAck(void) -{ - HW_IPCC_LLDTESTS_SendCliRspAck(); - return; -} - -void HW_IPCC_LLDTESTS_ReceiveM0Cmd(void) -{ - TL_LLDTESTS_ReceiveM0Cmd((TL_CmdPacket_t *)(TL_RefTable.p_lld_tests_table->m0cmd_buffer)); - return; -} - - -void TL_LLDTESTS_SendM0CmdAck(void) -{ - HW_IPCC_LLDTESTS_SendM0CmdAck(); - return; -} - -__WEAK void TL_LLDTESTS_ReceiveCliRsp(TL_CmdPacket_t *Notbuffer) {}; -__WEAK void TL_LLDTESTS_ReceiveM0Cmd(TL_CmdPacket_t *Notbuffer) {}; -#endif /* LLD_TESTS_WB */ - -/****************************************************************************** - * LLD BLE - ******************************************************************************/ -#ifdef LLD_BLE_WB -void TL_LLD_BLE_Init(TL_LLD_BLE_Config_t *p_Config) -{ - MB_LldBleTable_t *p_lld_ble_table; - - p_lld_ble_table = TL_RefTable.p_lld_ble_table; - p_lld_ble_table->cmdrsp_buffer = p_Config->p_LldBleCmdRspBuffer; - p_lld_ble_table->m0cmd_buffer = p_Config->p_LldBleM0CmdBuffer; - HW_IPCC_LLD_BLE_Init(); - return; -} - -void TL_LLD_BLE_SendCliCmd(void) -{ - ((TL_CmdPacket_t *)(TL_RefTable.p_lld_ble_table->cmdrsp_buffer))->cmdserial.type = TL_CLICMD_PKT_TYPE; - HW_IPCC_LLD_BLE_SendCliCmd(); - return; -} - -void HW_IPCC_LLD_BLE_ReceiveCliRsp(void) -{ - TL_LLD_BLE_ReceiveCliRsp((TL_CmdPacket_t *)(TL_RefTable.p_lld_ble_table->cmdrsp_buffer)); - return; -} - -void TL_LLD_BLE_SendCliRspAck(void) -{ - HW_IPCC_LLD_BLE_SendCliRspAck(); - return; -} - -void HW_IPCC_LLD_BLE_ReceiveM0Cmd(void) -{ - TL_LLD_BLE_ReceiveM0Cmd((TL_CmdPacket_t *)(TL_RefTable.p_lld_ble_table->m0cmd_buffer)); - return; -} - - -void TL_LLD_BLE_SendM0CmdAck(void) -{ - HW_IPCC_LLD_BLE_SendM0CmdAck(); - return; -} - -__WEAK void TL_LLD_BLE_ReceiveCliRsp(TL_CmdPacket_t *Notbuffer) {}; -__WEAK void TL_LLD_BLE_ReceiveM0Cmd(TL_CmdPacket_t *Notbuffer) {}; - -/* Transparent Mode */ -void TL_LLD_BLE_SendCmd(void) -{ - ((TL_CmdPacket_t *)(TL_RefTable.p_lld_ble_table->cmdrsp_buffer))->cmdserial.type = TL_CLICMD_PKT_TYPE; - HW_IPCC_LLD_BLE_SendCmd(); - return; -} - -void HW_IPCC_LLD_BLE_ReceiveRsp(void) -{ - TL_LLD_BLE_ReceiveRsp((TL_CmdPacket_t *)(TL_RefTable.p_lld_ble_table->cmdrsp_buffer)); - return; -} - -void TL_LLD_BLE_SendRspAck(void) -{ - HW_IPCC_LLD_BLE_SendRspAck(); - return; -} -#endif /* LLD_BLE_WB */ - -/****************************************************************************** - * MEMORY MANAGER - ******************************************************************************/ -void TL_MM_Init(TL_MM_Config_t *p_Config) -{ - static MB_MemManagerTable_t *p_mem_manager_table; - - LST_init_head(&FreeBufQueue); - LST_init_head(&LocalFreeBufQueue); - - p_mem_manager_table = TL_RefTable.p_mem_manager_table; - - p_mem_manager_table->blepool = p_Config->p_AsynchEvtPool; - p_mem_manager_table->blepoolsize = p_Config->AsynchEvtPoolSize; - p_mem_manager_table->pevt_free_buffer_queue = (uint8_t *)&FreeBufQueue; - p_mem_manager_table->spare_ble_buffer = p_Config->p_BleSpareEvtBuffer; - p_mem_manager_table->spare_sys_buffer = p_Config->p_SystemSpareEvtBuffer; - p_mem_manager_table->traces_evt_pool = p_Config->p_TracesEvtPool; - p_mem_manager_table->tracespoolsize = p_Config->TracesEvtPoolSize; - - return; -} - -void TL_MM_EvtDone(TL_EvtPacket_t *phcievt) -{ - LST_insert_tail(&LocalFreeBufQueue, (tListNode *)phcievt); - - OutputMemReleaseTrace(phcievt); - - HW_IPCC_MM_SendFreeBuf(SendFreeBuf); - - return; -} - -static void SendFreeBuf(void) -{ - tListNode *p_node; - - while (FALSE == LST_is_empty(&LocalFreeBufQueue)) { - LST_remove_head(&LocalFreeBufQueue, (tListNode **)&p_node); - LST_insert_tail((tListNode *)(TL_RefTable.p_mem_manager_table->pevt_free_buffer_queue), p_node); - } - - return; -} - -static void OutputMemReleaseTrace(TL_EvtPacket_t *phcievt) -{ - switch (phcievt->evtserial.evt.evtcode) { - case TL_BLEEVT_CS_OPCODE: - TL_MM_DBG__MSG("mm evt released: 0x%02X", phcievt->evtserial.evt.evtcode); - TL_MM_DBG__MSG(" cmd opcode: 0x%04X", ((TL_CsEvt_t *)(phcievt->evtserial.evt.payload))->cmdcode); - TL_MM_DBG__MSG(" buffer addr: 0x%08X", phcievt); - break; - - case TL_BLEEVT_CC_OPCODE: - TL_MM_DBG__MSG("mm evt released: 0x%02X", phcievt->evtserial.evt.evtcode); - TL_MM_DBG__MSG(" cmd opcode: 0x%04X", ((TL_CcEvt_t *)(phcievt->evtserial.evt.payload))->cmdcode); - TL_MM_DBG__MSG(" buffer addr: 0x%08X", phcievt); - break; - - case TL_BLEEVT_VS_OPCODE: - TL_MM_DBG__MSG("mm evt released: 0x%02X", phcievt->evtserial.evt.evtcode); - TL_MM_DBG__MSG(" subevtcode: 0x%04X", ((TL_AsynchEvt_t *)(phcievt->evtserial.evt.payload))->subevtcode); - TL_MM_DBG__MSG(" buffer addr: 0x%08X", phcievt); - break; - - default: - TL_MM_DBG__MSG("mm evt released: 0x%02X", phcievt->evtserial.evt.evtcode); - TL_MM_DBG__MSG(" buffer addr: 0x%08X", phcievt); - break; - } - - TL_MM_DBG__MSG("\r\n"); - - return; -} - -/****************************************************************************** - * TRACES - ******************************************************************************/ -void TL_TRACES_Init(void) -{ - LST_init_head(&TracesEvtQueue); - - TL_RefTable.p_traces_table->traces_queue = (uint8_t *)&TracesEvtQueue; - - HW_IPCC_TRACES_Init(); - - return; -} - -void HW_IPCC_TRACES_EvtNot(void) -{ - TL_EvtPacket_t *phcievt; - - while (LST_is_empty(&TracesEvtQueue) == FALSE) { - LST_remove_head(&TracesEvtQueue, (tListNode **)&phcievt); - TL_TRACES_EvtReceived(phcievt); - } - - return; -} - -__WEAK void TL_TRACES_EvtReceived(TL_EvtPacket_t *hcievt) -{ - (void)(hcievt); -} -#endif /* STM32WBxx */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ From 370b06da90ebfa990d15b34787fd1e9002b520fa Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Wed, 1 Dec 2021 11:15:00 +0100 Subject: [PATCH 071/226] chore: include STM32Cube_FW to support the BLE of the stm32wb55 Orignal file from the v1.8.0: https://github.com/STMicroelectronics/STM32CubeWB/releases/tag/v1.8.0 Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- src/utility/STM32Cube_FW/app_conf.h | 510 ++++++++++ src/utility/STM32Cube_FW/ble_bufsize.h | 161 ++++ src/utility/STM32Cube_FW/hw.h | 107 +++ src/utility/STM32Cube_FW/hw_ipcc.c | 517 ++++++++++ src/utility/STM32Cube_FW/mbox_def.h | 258 +++++ src/utility/STM32Cube_FW/shci.c | 609 ++++++++++++ src/utility/STM32Cube_FW/shci.h | 944 +++++++++++++++++++ src/utility/STM32Cube_FW/shci_tl.c | 351 +++++++ src/utility/STM32Cube_FW/shci_tl.h | 175 ++++ src/utility/STM32Cube_FW/stm32_wpan_common.h | 170 ++++ src/utility/STM32Cube_FW/stm_list.c | 208 ++++ src/utility/STM32Cube_FW/stm_list.h | 55 ++ src/utility/STM32Cube_FW/tl.h | 334 +++++++ src/utility/STM32Cube_FW/tl_mbox.c | 686 ++++++++++++++ 14 files changed, 5085 insertions(+) create mode 100644 src/utility/STM32Cube_FW/app_conf.h create mode 100644 src/utility/STM32Cube_FW/ble_bufsize.h create mode 100644 src/utility/STM32Cube_FW/hw.h create mode 100644 src/utility/STM32Cube_FW/hw_ipcc.c create mode 100644 src/utility/STM32Cube_FW/mbox_def.h create mode 100644 src/utility/STM32Cube_FW/shci.c create mode 100644 src/utility/STM32Cube_FW/shci.h create mode 100644 src/utility/STM32Cube_FW/shci_tl.c create mode 100644 src/utility/STM32Cube_FW/shci_tl.h create mode 100644 src/utility/STM32Cube_FW/stm32_wpan_common.h create mode 100644 src/utility/STM32Cube_FW/stm_list.c create mode 100644 src/utility/STM32Cube_FW/stm_list.h create mode 100644 src/utility/STM32Cube_FW/tl.h create mode 100644 src/utility/STM32Cube_FW/tl_mbox.c diff --git a/src/utility/STM32Cube_FW/app_conf.h b/src/utility/STM32Cube_FW/app_conf.h new file mode 100644 index 00000000..ac5ccd4d --- /dev/null +++ b/src/utility/STM32Cube_FW/app_conf.h @@ -0,0 +1,510 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * File Name : app_conf.h + * Description : Application configuration file for STM32WPAN Middleware. + ****************************************************************************** + * @attention + * + * <h2><center>© Copyright (c) 2020 STMicroelectronics. + * All rights reserved.</center></h2> + * + * This software component is licensed by ST under Ultimate Liberty license + * SLA0044, the "License"; You may not use this file except in compliance with + * the License. You may obtain a copy of the License at: + * www.st.com/SLA0044 + * + ****************************************************************************** + */ +/* USER CODE END Header */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef APP_CONF_H +#define APP_CONF_H + +#include "hw.h" +#include "hw_conf.h" +#include "hw_if.h" + +/****************************************************************************** + * Application Config + ******************************************************************************/ + +/** + * Define Secure Connections Support + */ +#define CFG_SECURE_NOT_SUPPORTED (0x00) +#define CFG_SECURE_OPTIONAL (0x01) +#define CFG_SECURE_MANDATORY (0x02) + +#define CFG_SC_SUPPORT CFG_SECURE_OPTIONAL + +/** + * Define Keypress Notification Support + */ +#define CFG_KEYPRESS_NOT_SUPPORTED (0x00) +#define CFG_KEYPRESS_SUPPORTED (0x01) + +#define CFG_KEYPRESS_NOTIFICATION_SUPPORT CFG_KEYPRESS_NOT_SUPPORTED + +/** + * Numeric Comparison Answers + */ +#define YES (0x01) +#define NO (0x00) + +/** + * Device name configuration for Generic Access Service + */ +#define CFG_GAP_DEVICE_NAME "TEMPLATE" +#define CFG_GAP_DEVICE_NAME_LENGTH (8) + +/** +* Identity root key used to derive LTK and CSRK +*/ +#define CFG_BLE_IRK {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0} + +/** +* Encryption root key used to derive LTK and CSRK +*/ +#define CFG_BLE_ERK {0xfe,0xdc,0xba,0x09,0x87,0x65,0x43,0x21,0xfe,0xdc,0xba,0x09,0x87,0x65,0x43,0x21} + +/* USER CODE BEGIN Generic_Parameters */ +/** + * SMPS supply + * SMPS not used when Set to 0 + * SMPS used when Set to 1 + */ +#define CFG_USE_SMPS 1 +/* USER CODE END Generic_Parameters */ + +/**< specific parameters */ +/*****************************************************/ + +#define PUSH_BUTTON_SW1_EXTI_IRQHandler EXTI4_IRQHandler + +/****************************************************************************** + * Information Table + * + * Version + * [0:3] = Build - 0: Untracked - 15:Released - x: Tracked version + * [4:7] = branch - 0: Mass Market - x: ... + * [8:15] = Subversion + * [16:23] = Version minor + * [24:31] = Version major + * + ******************************************************************************/ +#define CFG_FW_MAJOR_VERSION (0) +#define CFG_FW_MINOR_VERSION (0) +#define CFG_FW_SUBVERSION (1) +#define CFG_FW_BRANCH (0) +#define CFG_FW_BUILD (0) + +/****************************************************************************** + * BLE Stack + ******************************************************************************/ +/** + * Maximum number of simultaneous connections that the device will support. + * Valid values are from 1 to 8 + */ +#define CFG_BLE_NUM_LINK 8 + +/** + * Maximum number of Services that can be stored in the GATT database. + * Note that the GAP and GATT services are automatically added so this parameter should be 2 plus the number of user services + */ +#define CFG_BLE_NUM_GATT_SERVICES 8 + +/** + * Maximum number of Attributes + * (i.e. the number of characteristic + the number of characteristic values + the number of descriptors, excluding the services) + * that can be stored in the GATT database. + * Note that certain characteristics and relative descriptors are added automatically during device initialization + * so this parameters should be 9 plus the number of user Attributes + */ +#define CFG_BLE_NUM_GATT_ATTRIBUTES 68 + +/** + * Maximum supported ATT_MTU size + */ +#define CFG_BLE_MAX_ATT_MTU (156) + +/** + * Size of the storage area for Attribute values + * This value depends on the number of attributes used by application. In particular the sum of the following quantities (in octets) should be made for each attribute: + * - attribute value length + * - 5, if UUID is 16 bit; 19, if UUID is 128 bit + * - 2, if server configuration descriptor is used + * - 2*DTM_NUM_LINK, if client configuration descriptor is used + * - 2, if extended properties is used + * The total amount of memory needed is the sum of the above quantities for each attribute. + */ +#define CFG_BLE_ATT_VALUE_ARRAY_SIZE (1344) + +/** + * Prepare Write List size in terms of number of packet + */ +#define CFG_BLE_PREPARE_WRITE_LIST_SIZE BLE_PREP_WRITE_X_ATT(CFG_BLE_MAX_ATT_MTU) + +/** + * Number of allocated memory blocks + */ +#define CFG_BLE_MBLOCK_COUNT (BLE_MBLOCKS_CALC(CFG_BLE_PREPARE_WRITE_LIST_SIZE, CFG_BLE_MAX_ATT_MTU, CFG_BLE_NUM_LINK)) + +/** + * Enable or disable the Extended Packet length feature. Valid values are 0 or 1. + */ +#define CFG_BLE_DATA_LENGTH_EXTENSION 1 + +/** + * Sleep clock accuracy in Slave mode (ppm value) + */ +#define CFG_BLE_SLAVE_SCA 500 + +/** + * Sleep clock accuracy in Master mode + * 0 : 251 ppm to 500 ppm + * 1 : 151 ppm to 250 ppm + * 2 : 101 ppm to 150 ppm + * 3 : 76 ppm to 100 ppm + * 4 : 51 ppm to 75 ppm + * 5 : 31 ppm to 50 ppm + * 6 : 21 ppm to 30 ppm + * 7 : 0 ppm to 20 ppm + */ +#define CFG_BLE_MASTER_SCA 0 + +/** + * Source for the 32 kHz slow speed clock + * 1 : internal RO + * 0 : external crystal ( no calibration ) + */ +#define CFG_BLE_LSE_SOURCE 0 + +/** + * Start up time of the high speed (16 or 32 MHz) crystal oscillator in units of 625/256 us (~2.44 us) + */ +#define CFG_BLE_HSE_STARTUP_TIME 0x148 + +/** + * Maximum duration of the connection event when the device is in Slave mode in units of 625/256 us (~2.44 us) + */ +#define CFG_BLE_MAX_CONN_EVENT_LENGTH ( 0xFFFFFFFF ) + +/** + * Viterbi Mode + * 1 : enabled + * 0 : disabled + */ +#define CFG_BLE_VITERBI_MODE 1 + +/** + * LL Only Mode + * 1 : LL Only + * 0 : LL + Host + */ +#define CFG_BLE_LL_ONLY 0 +/****************************************************************************** + * Transport Layer + ******************************************************************************/ +/** + * Queue length of BLE Event + * This parameter defines the number of asynchronous events that can be stored in the HCI layer before + * being reported to the application. When a command is sent to the BLE core coprocessor, the HCI layer + * is waiting for the event with the Num_HCI_Command_Packets set to 1. The receive queue shall be large + * enough to store all asynchronous events received in between. + * When CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE is set to 27, this allow to store three 255 bytes long asynchronous events + * between the HCI command and its event. + * This parameter depends on the value given to CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE. When the queue size is to small, + * the system may hang if the queue is full with asynchronous events and the HCI layer is still waiting + * for a CC/CS event, In that case, the notification TL_BLE_HCI_ToNot() is called to indicate + * to the application a HCI command did not receive its command event within 30s (Default HCI Timeout). + */ +#define CFG_TLBLE_EVT_QUEUE_LENGTH 5 +/** + * This parameter should be set to fit most events received by the HCI layer. It defines the buffer size of each element + * allocated in the queue of received events and can be used to optimize the amount of RAM allocated by the Memory Manager. + * It should not exceed 255 which is the maximum HCI packet payload size (a greater value is a lost of memory as it will + * never be used) + * It shall be at least 4 to receive the command status event in one frame. + * The default value is set to 27 to allow receiving an event of MTU size in a single buffer. This value maybe reduced + * further depending on the application. + * + */ +#define CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE 255 /**< Set to 255 with the memory manager and the mailbox */ + +#define TL_BLE_EVENT_FRAME_SIZE ( TL_EVT_HDR_SIZE + CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE ) +/****************************************************************************** + * UART interfaces + ******************************************************************************/ + +/** + * Select UART interfaces + */ +#define CFG_UART_GUI hw_uart1 +#define CFG_DEBUG_TRACE_UART 0 +/****************************************************************************** + * USB interface + ******************************************************************************/ + +/** + * Enable/Disable USB interface + */ +#define CFG_USB_INTERFACE_ENABLE 0 + +/****************************************************************************** + * Low Power + ******************************************************************************/ +/** + * When set to 1, the low power mode is enable + * When set to 0, the device stays in RUN mode + */ +#define CFG_LPM_SUPPORTED 1 + +/****************************************************************************** + * Timer Server + ******************************************************************************/ +/** + * CFG_RTC_WUCKSEL_DIVIDER: This sets the RTCCLK divider to the wakeup timer. + * The higher is the value, the better is the power consumption and the accuracy of the timerserver + * The lower is the value, the finest is the granularity + * + * CFG_RTC_ASYNCH_PRESCALER: This sets the asynchronous prescaler of the RTC. It should as high as possible ( to ouput + * clock as low as possible) but the output clock should be equal or higher frequency compare to the clock feeding + * the wakeup timer. A lower clock speed would impact the accuracy of the timer server. + * + * CFG_RTC_SYNCH_PRESCALER: This sets the synchronous prescaler of the RTC. + * When the 1Hz calendar clock is required, it shall be sets according to other settings + * When the 1Hz calendar clock is not needed, CFG_RTC_SYNCH_PRESCALER should be set to 0x7FFF (MAX VALUE) + * + * CFG_RTCCLK_DIVIDER_CONF: + * Shall be set to either 0,2,4,8,16 + * When set to either 2,4,8,16, the 1Hhz calendar is supported + * When set to 0, the user sets its own configuration + * + * The following settings are computed with LSI as input to the RTC + */ +#define CFG_RTCCLK_DIVIDER_CONF 0 + +#if (CFG_RTCCLK_DIVIDER_CONF == 0) +/** + * Custom configuration + * It does not support 1Hz calendar + * It divides the RTC CLK by 16 + */ +#define CFG_RTCCLK_DIV (16) +#define CFG_RTC_WUCKSEL_DIVIDER (0) +#define CFG_RTC_ASYNCH_PRESCALER (CFG_RTCCLK_DIV - 1) +#define CFG_RTC_SYNCH_PRESCALER (0x7FFF) + +#else + +#if (CFG_RTCCLK_DIVIDER_CONF == 2) +/** + * It divides the RTC CLK by 2 + */ +#define CFG_RTC_WUCKSEL_DIVIDER (3) +#endif + +#if (CFG_RTCCLK_DIVIDER_CONF == 4) +/** + * It divides the RTC CLK by 4 + */ +#define CFG_RTC_WUCKSEL_DIVIDER (2) +#endif + +#if (CFG_RTCCLK_DIVIDER_CONF == 8) +/** + * It divides the RTC CLK by 8 + */ +#define CFG_RTC_WUCKSEL_DIVIDER (1) +#endif + +#if (CFG_RTCCLK_DIVIDER_CONF == 16) +/** + * It divides the RTC CLK by 16 + */ +#define CFG_RTC_WUCKSEL_DIVIDER (0) +#endif + +#define CFG_RTCCLK_DIV CFG_RTCCLK_DIVIDER_CONF +#define CFG_RTC_ASYNCH_PRESCALER (CFG_RTCCLK_DIV - 1) +#define CFG_RTC_SYNCH_PRESCALER (DIVR( LSE_VALUE, (CFG_RTC_ASYNCH_PRESCALER+1) ) - 1 ) + +#endif + +/** tick timer value in us */ +#define CFG_TS_TICK_VAL DIVR( (CFG_RTCCLK_DIV * 1000000), LSE_VALUE ) + +typedef enum +{ + CFG_TIM_PROC_ID_ISR, +} CFG_TimProcID_t; + +/****************************************************************************** + * Debug + ******************************************************************************/ +/** + * When set, this resets some hw resources to set the device in the same state than the power up + * The FW resets only register that may prevent the FW to run properly + * + * This shall be set to 0 in a final product + * + */ +#define CFG_HW_RESET_BY_FW 1 + +/** + * keep debugger enabled while in any low power mode when set to 1 + * should be set to 0 in production + */ +#define CFG_DEBUGGER_SUPPORTED 0 + +/** + * When set to 1, the traces are enabled in the BLE services + */ +#define CFG_DEBUG_BLE_TRACE 0 + +/** + * Enable or Disable traces in application + */ +#define CFG_DEBUG_APP_TRACE 0 + +#if (CFG_DEBUG_APP_TRACE != 0) +#define APP_DBG_MSG PRINT_MESG_DBG +#else +#define APP_DBG_MSG PRINT_NO_MESG +#endif + +#if ( (CFG_DEBUG_BLE_TRACE != 0) || (CFG_DEBUG_APP_TRACE != 0) ) +#define CFG_DEBUG_TRACE 1 +#endif + +#if (CFG_DEBUG_TRACE != 0) +#undef CFG_LPM_SUPPORTED +#undef CFG_DEBUGGER_SUPPORTED +#define CFG_LPM_SUPPORTED 0 +#define CFG_DEBUGGER_SUPPORTED 1 +#endif + +/** + * When CFG_DEBUG_TRACE_FULL is set to 1, the trace are output with the API name, the file name and the line number + * When CFG_DEBUG_TRACE_LIGHT is set to 1, only the debug message is output + * + * When both are set to 0, no trace are output + * When both are set to 1, CFG_DEBUG_TRACE_FULL is selected + */ +#define CFG_DEBUG_TRACE_LIGHT 0 +#define CFG_DEBUG_TRACE_FULL 0 + +#if (( CFG_DEBUG_TRACE != 0 ) && ( CFG_DEBUG_TRACE_LIGHT == 0 ) && (CFG_DEBUG_TRACE_FULL == 0)) +#undef CFG_DEBUG_TRACE_FULL +#undef CFG_DEBUG_TRACE_LIGHT +#define CFG_DEBUG_TRACE_FULL 0 +#define CFG_DEBUG_TRACE_LIGHT 1 +#endif + +#if ( CFG_DEBUG_TRACE == 0 ) +#undef CFG_DEBUG_TRACE_FULL +#undef CFG_DEBUG_TRACE_LIGHT +#define CFG_DEBUG_TRACE_FULL 0 +#define CFG_DEBUG_TRACE_LIGHT 0 +#endif + +/** + * When not set, the traces is looping on sending the trace over UART + */ +#define DBG_TRACE_USE_CIRCULAR_QUEUE 1 + +/** + * max buffer Size to queue data traces and max data trace allowed. + * Only Used if DBG_TRACE_USE_CIRCULAR_QUEUE is defined + */ +#define DBG_TRACE_MSG_QUEUE_SIZE 4096 +#define MAX_DBG_TRACE_MSG_SIZE 1024 + +/* USER CODE BEGIN Defines */ +#define CFG_LED_SUPPORTED 1 +#define CFG_BUTTON_SUPPORTED 1 +/* USER CODE END Defines */ + +/****************************************************************************** + * Scheduler + ******************************************************************************/ + +/** + * These are the lists of task id registered to the scheduler + * Each task id shall be in the range [0:31] + * This mechanism allows to implement a generic code in the API TL_BLE_HCI_StatusNot() to comply with + * the requirement that a HCI/ACI command shall never be sent if there is already one pending + */ + +/**< Add in that list all tasks that may send a ACI/HCI command */ +typedef enum +{ + CFG_TASK_BLE_HCI_CMD_ID, + CFG_TASK_SYS_HCI_CMD_ID, + CFG_TASK_HCI_ACL_DATA_ID, + CFG_TASK_SYS_LOCAL_CMD_ID, + CFG_TASK_TX_TO_HOST_ID, +/* USER CODE BEGIN CFG_Task_Id_With_HCI_Cmd_t */ + +/* USER CODE END CFG_Task_Id_With_HCI_Cmd_t */ + CFG_LAST_TASK_ID_WITH_HCICMD, /**< Shall be LAST in the list */ +} CFG_Task_Id_With_HCI_Cmd_t; + +/**< Add in that list all tasks that never send a ACI/HCI command */ +typedef enum +{ + CFG_FIRST_TASK_ID_WITH_NO_HCICMD = CFG_LAST_TASK_ID_WITH_HCICMD - 1, /**< Shall be FIRST in the list */ + CFG_TASK_SYSTEM_HCI_ASYNCH_EVT_ID, +/* USER CODE BEGIN CFG_Task_Id_With_NO_HCI_Cmd_t */ + +/* USER CODE END CFG_Task_Id_With_NO_HCI_Cmd_t */ + CFG_LAST_TASK_ID_WITHO_NO_HCICMD /**< Shall be LAST in the list */ +} CFG_Task_Id_With_NO_HCI_Cmd_t; +#define CFG_TASK_NBR CFG_LAST_TASK_ID_WITHO_NO_HCICMD + +/** + * This is the list of priority required by the application + * Each Id shall be in the range 0..31 + */ +typedef enum +{ + CFG_SCH_PRIO_0, + CFG_PRIO_NBR, +} CFG_SCH_Prio_Id_t; + +/** + * This is a bit mapping over 32bits listing all events id supported in the application + */ +typedef enum +{ + CFG_IDLEEVT_SYSTEM_HCI_CMD_EVT_RSP_ID, +} CFG_IdleEvt_Id_t; + +/****************************************************************************** + * LOW POWER + ******************************************************************************/ +/** + * Supported requester to the MCU Low Power Manager - can be increased up to 32 + * It lits a bit mapping of all user of the Low Power Manager + */ +typedef enum +{ + CFG_LPM_APP, + CFG_LPM_APP_BLE, + /* USER CODE BEGIN CFG_LPM_Id_t */ + + /* USER CODE END CFG_LPM_Id_t */ +} CFG_LPM_Id_t; + +/****************************************************************************** + * OTP manager + ******************************************************************************/ +#define CFG_OTP_BASE_ADDRESS OTP_AREA_BASE + +#define CFG_OTP_END_ADRESS OTP_AREA_END_ADDR + +#endif /*APP_CONF_H */ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/src/utility/STM32Cube_FW/ble_bufsize.h b/src/utility/STM32Cube_FW/ble_bufsize.h new file mode 100644 index 00000000..c5a5d569 --- /dev/null +++ b/src/utility/STM32Cube_FW/ble_bufsize.h @@ -0,0 +1,161 @@ +/***************************************************************************** + * @file ble_bufsize.h + * @author MCD Application Team + * @brief Definition of BLE stack buffers size + ***************************************************************************** + * @attention + * + * <h2><center>© Copyright (c) 2019 STMicroelectronics. + * All rights reserved.</center></h2> + * + * This software component is licensed by ST under Ultimate Liberty license + * SLA0044, the "License"; You may not use this file except in compliance with + * the License. You may obtain a copy of the License at: + * www.st.com/SLA0044 + * + ***************************************************************************** + */ + +#ifndef BLE_BUFSIZE_H__ +#define BLE_BUFSIZE_H__ + + +/* + * BLE_DEFAULT_ATT_MTU: minimum MTU value that GATT must support. + */ +#define BLE_DEFAULT_ATT_MTU 23 + +/* + * BLE_DEFAULT_MAX_ATT_MTU: maximum supported ATT MTU size. + */ +#define BLE_DEFAULT_MAX_ATT_MTU 158 + +/* + * BLE_DEFAULT_MAX_ATT_SIZE: maximum attribute size. + */ +#define BLE_DEFAULT_MAX_ATT_SIZE 512 + +/* + * BLE_PREP_WRITE_X_ATT: compute how many Prepare Write Request are needed to + * write a characteristic with size 'max_att' when the used ATT_MTU value is + * equal to BLE_DEFAULT_ATT_MTU (23). + */ +#define BLE_PREP_WRITE_X_ATT(max_att) \ + (DIVC(max_att, BLE_DEFAULT_ATT_MTU - 5) * 2) + +/* + * BLE_DEFAULT_PREP_WRITE_LIST_SIZE: default minimum Prepare Write List size. + */ +#define BLE_DEFAULT_PREP_WRITE_LIST_SIZE \ + BLE_PREP_WRITE_X_ATT(BLE_DEFAULT_MAX_ATT_SIZE) + +/* + * BLE_MEM_BLOCK_X_MTU: compute how many memory blocks are needed to compose + * an ATT packet with ATT_MTU=mtu. + */ +#define BLE_MEM_BLOCK_SIZE 32 + +#define BLE_MEM_BLOCK_X_TX(mtu) \ + (DIVC((mtu) + 4U, BLE_MEM_BLOCK_SIZE) + 1U) + +#define BLE_MEM_BLOCK_X_RX(mtu, n_link) \ + ((DIVC((mtu) + 4U, BLE_MEM_BLOCK_SIZE) + 2U) * (n_link) + 1) + +#define BLE_MEM_BLOCK_X_MTU(mtu, n_link) \ + (BLE_MEM_BLOCK_X_TX(mtu) + BLE_MEM_BLOCK_X_RX(mtu, n_link)) + +/* + * BLE_MBLOCKS_SECURE_CONNECTIONS: minimum number of blocks required for + * secure connections + */ +#define BLE_MBLOCKS_SECURE_CONNECTIONS 4 + +/* + * BLE_MBLOCKS_CALC: minimum number of buffers needed by the stack. + * This is the minimum racomanded value and depends on: + * - pw: size of Prepare Write List + * - mtu: ATT_MTU size + * - n_link: maximum number of simultaneous connections + */ +#define BLE_MBLOCKS_CALC(pw, mtu, n_link) \ + ((pw) + MAX(BLE_MEM_BLOCK_X_MTU(mtu, n_link), \ + BLE_MBLOCKS_SECURE_CONNECTIONS)) + +/* + * BLE_DEFAULT_MBLOCKS_COUNT: default memory blocks count + */ +#define BLE_DEFAULT_MBLOCKS_COUNT(n_link) \ + BLE_MBLOCKS_CALC(BLE_DEFAULT_PREP_WRITE_LIST_SIZE, \ + BLE_DEFAULT_MAX_ATT_MTU, n_link) + +/* + * BLE_FIXED_BUFFER_SIZE_BYTES: + * A part of the RAM, is dinamically allocated by initilizing all the pointers + * defined in a global context variable "mem_alloc_ctx_p". + * This initialization is made in the Dynamic_allocator functions, which + * assing a portion of RAM given by the external application to the above + * mentioned "global pointers". + * + * The size of this Dynamic RAM is made of 2 main components: + * - a part that is parameters-dependent (num of links, GATT buffers, ...), + * and which value is explicited by the following macro; + * - a part, that may be considered "fixed", i.e. independent from the above + * mentioned parameters. +*/ +#if (SLAVE_ONLY == 0) && (LL_ONLY == 0) +#define BLE_FIXED_BUFFER_SIZE_BYTES 6960 /* Full stack */ +#elif SLAVE_ONLY == 0 +#define BLE_FIXED_BUFFER_SIZE_BYTES 6256 /* LL only */ +#else +#define BLE_FIXED_BUFFER_SIZE_BYTES 6696 /* Slave only */ +#endif + +/* + * BLE_PER_LINK_SIZE_BYTES: additional memory size used per link + */ +#if (SLAVE_ONLY == 0) && (LL_ONLY == 0) +#define BLE_PER_LINK_SIZE_BYTES 380 /* Full stack */ +#elif SLAVE_ONLY == 0 +#define BLE_PER_LINK_SIZE_BYTES 196 /* LL only */ +#else +#define BLE_PER_LINK_SIZE_BYTES 332 /* Slave only */ +#endif + +/* + * BLE_TOTAL_BUFFER_SIZE: this macro returns the amount of memory, in bytes, + * needed for the storage of data structures (except GATT database elements) + * whose size depends on the number of supported connections. + * + * @param num_links: Maximum number of simultaneous connections that the device + * will support. Valid values are from 1 to 8. + * + * @param mblocks_count: Number of memory blocks allocated for packets. + */ +#define BLE_TOTAL_BUFFER_SIZE(n_link, mblocks_count) \ + (BLE_FIXED_BUFFER_SIZE_BYTES + \ + (BLE_PER_LINK_SIZE_BYTES * (n_link)) + \ + ((BLE_MEM_BLOCK_SIZE + 12) * (mblocks_count))) + +/* + * BLE_TOTAL_BUFFER_SIZE_GATT: this macro returns the amount of memory, + * in bytes, needed for the storage of GATT database elements. + * + * @param num_gatt_attributes: Maximum number of Attributes (i.e. the number + * of characteristic + the number of characteristic values + the number of + * descriptors, excluding the services) that can be stored in the GATT + * database. Note that certain characteristics and relative descriptors are + * added automatically during device initialization so this parameters should + * be 9 plus the number of user Attributes + * + * @param num_gatt_services: Maximum number of Services that can be stored in + * the GATT database. Note that the GAP and GATT services are automatically + * added so this parameter should be 2 plus the number of user services + * + * @param att_value_array_size: Size of the storage area for Attribute values. + */ +#define BLE_TOTAL_BUFFER_SIZE_GATT(num_gatt_attributes, num_gatt_services, att_value_array_size) \ + (((((att_value_array_size) - 1) | 3) + 1) + \ + (40 * (num_gatt_attributes)) + (48 * (num_gatt_services))) + + +#endif /* ! BLE_BUFSIZE_H__ */ diff --git a/src/utility/STM32Cube_FW/hw.h b/src/utility/STM32Cube_FW/hw.h new file mode 100644 index 00000000..879fa6de --- /dev/null +++ b/src/utility/STM32Cube_FW/hw.h @@ -0,0 +1,107 @@ +/** + ****************************************************************************** + * @file hw.h + * @author MCD Application Team + * @brief Hardware + ****************************************************************************** + * @attention + * + * <h2><center>© Copyright (c) 2019 STMicroelectronics. + * All rights reserved.</center></h2> + * + * This software component is licensed by ST under BSD 3-Clause license, + * the "License"; You may not use this file except in compliance with the + * License. You may obtain a copy of the License at: + * opensource.org/licenses/BSD-3-Clause + * + ****************************************************************************** + */ + + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __HW_H +#define __HW_H + +#ifdef __cplusplus +extern "C" { +#endif + + /* Includes ------------------------------------------------------------------*/ + + /****************************************************************************** + * HW IPCC + ******************************************************************************/ + void HW_IPCC_Enable( void ); + void HW_IPCC_Init( void ); + void HW_IPCC_Rx_Handler( void ); + void HW_IPCC_Tx_Handler( void ); + + void HW_IPCC_BLE_Init( void ); + void HW_IPCC_BLE_SendCmd( void ); + void HW_IPCC_MM_SendFreeBuf( void (*cb)( void ) ); + void HW_IPCC_BLE_RxEvtNot( void ); + void HW_IPCC_BLE_SendAclData( void ); + void HW_IPCC_BLE_AclDataAckNot( void ); + + void HW_IPCC_SYS_Init( void ); + void HW_IPCC_SYS_SendCmd( void ); + void HW_IPCC_SYS_CmdEvtNot( void ); + void HW_IPCC_SYS_EvtNot( void ); + + void HW_IPCC_THREAD_Init( void ); + void HW_IPCC_OT_SendCmd( void ); + void HW_IPCC_CLI_SendCmd( void ); + void HW_IPCC_THREAD_SendAck( void ); + void HW_IPCC_OT_CmdEvtNot( void ); + void HW_IPCC_CLI_CmdEvtNot( void ); + void HW_IPCC_THREAD_EvtNot( void ); + void HW_IPCC_THREAD_CliSendAck( void ); + void HW_IPCC_THREAD_CliEvtNot( void ); + + + void HW_IPCC_LLDTESTS_Init( void ); + void HW_IPCC_LLDTESTS_SendCliCmd( void ); + void HW_IPCC_LLDTESTS_ReceiveCliRsp( void ); + void HW_IPCC_LLDTESTS_SendCliRspAck( void ); + void HW_IPCC_LLDTESTS_ReceiveM0Cmd( void ); + void HW_IPCC_LLDTESTS_SendM0CmdAck( void ); + + + void HW_IPCC_LLD_BLE_Init( void ); + void HW_IPCC_LLD_BLE_SendCliCmd( void ); + void HW_IPCC_LLD_BLE_ReceiveCliRsp( void ); + void HW_IPCC_LLD_BLE_SendCliRspAck( void ); + void HW_IPCC_LLD_BLE_ReceiveM0Cmd( void ); + void HW_IPCC_LLD_BLE_SendM0CmdAck( void ); + void HW_IPCC_LLD_BLE_SendCmd( void ); + void HW_IPCC_LLD_BLE_ReceiveRsp( void ); + void HW_IPCC_LLD_BLE_SendRspAck( void ); + + + void HW_IPCC_TRACES_Init( void ); + void HW_IPCC_TRACES_EvtNot( void ); + + void HW_IPCC_MAC_802_15_4_Init( void ); + void HW_IPCC_MAC_802_15_4_SendCmd( void ); + void HW_IPCC_MAC_802_15_4_SendAck( void ); + void HW_IPCC_MAC_802_15_4_CmdEvtNot( void ); + void HW_IPCC_MAC_802_15_4_EvtNot( void ); + + void HW_IPCC_ZIGBEE_Init( void ); + + void HW_IPCC_ZIGBEE_SendM4RequestToM0(void); /* M4 Request to M0 */ + void HW_IPCC_ZIGBEE_RecvAppliAckFromM0(void); /* Request ACK from M0 */ + + void HW_IPCC_ZIGBEE_RecvM0NotifyToM4(void); /* M0 Notify to M4 */ + void HW_IPCC_ZIGBEE_SendM4AckToM0Notify(void); /* Notify ACK from M4 */ + void HW_IPCC_ZIGBEE_RecvM0RequestToM4(void); /* M0 Request to M4 */ + void HW_IPCC_ZIGBEE_SendM4AckToM0Request(void); /* Request ACK from M4 */ + + +#ifdef __cplusplus +} +#endif + +#endif /*__HW_H */ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/src/utility/STM32Cube_FW/hw_ipcc.c b/src/utility/STM32Cube_FW/hw_ipcc.c new file mode 100644 index 00000000..6da31992 --- /dev/null +++ b/src/utility/STM32Cube_FW/hw_ipcc.c @@ -0,0 +1,517 @@ +/** + ****************************************************************************** + * File Name : Target/hw_ipcc.c + * Description : Hardware IPCC source file for STM32WPAN Middleware. + * + ****************************************************************************** + * @attention + * + * <h2><center>© Copyright (c) 2020 STMicroelectronics. + * All rights reserved.</center></h2> + * + * This software component is licensed by ST under Ultimate Liberty license + * SLA0044, the "License"; You may not use this file except in compliance with + * the License. You may obtain a copy of the License at: + * www.st.com/SLA0044 + * + ****************************************************************************** + */ + +/* Includes ------------------------------------------------------------------*/ +#include "app_common.h" +#include "mbox_def.h" + +/* Global variables ---------------------------------------------------------*/ +/* Private defines -----------------------------------------------------------*/ +#define HW_IPCC_TX_PENDING( channel ) ( !(LL_C1_IPCC_IsActiveFlag_CHx( IPCC, channel )) ) && (((~(IPCC->C1MR)) & (channel << 16U))) +#define HW_IPCC_RX_PENDING( channel ) (LL_C2_IPCC_IsActiveFlag_CHx( IPCC, channel )) && (((~(IPCC->C1MR)) & (channel << 0U))) + +/* Private macros ------------------------------------------------------------*/ +/* Private typedef -----------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +static void (*FreeBufCb)( void ); + +/* Private function prototypes -----------------------------------------------*/ +static void HW_IPCC_BLE_EvtHandler( void ); +static void HW_IPCC_BLE_AclDataEvtHandler( void ); +static void HW_IPCC_MM_FreeBufHandler( void ); +static void HW_IPCC_SYS_CmdEvtHandler( void ); +static void HW_IPCC_SYS_EvtHandler( void ); +static void HW_IPCC_TRACES_EvtHandler( void ); + +#ifdef THREAD_WB +static void HW_IPCC_OT_CmdEvtHandler( void ); +static void HW_IPCC_THREAD_NotEvtHandler( void ); +static void HW_IPCC_THREAD_CliNotEvtHandler( void ); +#endif + +#ifdef MAC_802_15_4_WB +static void HW_IPCC_MAC_802_15_4_CmdEvtHandler( void ); +static void HW_IPCC_MAC_802_15_4_NotEvtHandler( void ); +#endif + +#ifdef ZIGBEE_WB +static void HW_IPCC_ZIGBEE_CmdEvtHandler( void ); +static void HW_IPCC_ZIGBEE_StackNotifEvtHandler( void ); +static void HW_IPCC_ZIGBEE_StackM0RequestHandler( void ); + +#endif + +/* Public function definition -----------------------------------------------*/ + +/****************************************************************************** + * INTERRUPT HANDLER + ******************************************************************************/ +void HW_IPCC_Rx_Handler( void ) +{ + if (HW_IPCC_RX_PENDING( HW_IPCC_SYSTEM_EVENT_CHANNEL )) + { + HW_IPCC_SYS_EvtHandler(); + } +#ifdef MAC_802_15_4_WB + else if (HW_IPCC_RX_PENDING( HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL )) + { + HW_IPCC_MAC_802_15_4_NotEvtHandler(); + } +#endif /* MAC_802_15_4_WB */ +#ifdef THREAD_WB + else if (HW_IPCC_RX_PENDING( HW_IPCC_THREAD_NOTIFICATION_ACK_CHANNEL )) + { + HW_IPCC_THREAD_NotEvtHandler(); + } + else if (HW_IPCC_RX_PENDING( HW_IPCC_THREAD_CLI_NOTIFICATION_ACK_CHANNEL )) + { + HW_IPCC_THREAD_CliNotEvtHandler(); + } +#endif /* THREAD_WB */ +#ifdef ZIGBEE_WB + else if (HW_IPCC_RX_PENDING( HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL )) + { + HW_IPCC_ZIGBEE_StackNotifEvtHandler(); + } + else if (HW_IPCC_RX_PENDING( HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL )) + { + HW_IPCC_ZIGBEE_StackM0RequestHandler(); + } +#endif /* ZIGBEE_WB */ + else if (HW_IPCC_RX_PENDING( HW_IPCC_BLE_EVENT_CHANNEL )) + { + HW_IPCC_BLE_EvtHandler(); + } + else if (HW_IPCC_RX_PENDING( HW_IPCC_TRACES_CHANNEL )) + { + HW_IPCC_TRACES_EvtHandler(); + } + + return; +} + +void HW_IPCC_Tx_Handler( void ) +{ + if (HW_IPCC_TX_PENDING( HW_IPCC_SYSTEM_CMD_RSP_CHANNEL )) + { + HW_IPCC_SYS_CmdEvtHandler(); + } +#ifdef MAC_802_15_4_WB + else if (HW_IPCC_TX_PENDING( HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL )) + { + HW_IPCC_MAC_802_15_4_CmdEvtHandler(); + } +#endif /* MAC_802_15_4_WB */ +#ifdef THREAD_WB + else if (HW_IPCC_TX_PENDING( HW_IPCC_THREAD_OT_CMD_RSP_CHANNEL )) + { + HW_IPCC_OT_CmdEvtHandler(); + } +#endif /* THREAD_WB */ +#ifdef ZIGBEE_WB + if (HW_IPCC_TX_PENDING( HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL )) + { + HW_IPCC_ZIGBEE_CmdEvtHandler(); + } +#endif /* ZIGBEE_WB */ + else if (HW_IPCC_TX_PENDING( HW_IPCC_SYSTEM_CMD_RSP_CHANNEL )) + { + HW_IPCC_SYS_CmdEvtHandler(); + } + else if (HW_IPCC_TX_PENDING( HW_IPCC_MM_RELEASE_BUFFER_CHANNEL )) + { + HW_IPCC_MM_FreeBufHandler(); + } + else if (HW_IPCC_TX_PENDING( HW_IPCC_HCI_ACL_DATA_CHANNEL )) + { + HW_IPCC_BLE_AclDataEvtHandler(); + } + + return; +} +/****************************************************************************** + * GENERAL + ******************************************************************************/ +void HW_IPCC_Enable( void ) +{ + /** + * When the device is out of standby, it is required to use the EXTI mechanism to wakeup CPU2 + */ + LL_C2_EXTI_EnableEvent_32_63( LL_EXTI_LINE_41 ); + LL_EXTI_EnableRisingTrig_32_63( LL_EXTI_LINE_41 ); + + /** + * In case the SBSFU is implemented, it may have already set the C2BOOT bit to startup the CPU2. + * In that case, to keep the mechanism transparent to the user application, it shall call the system command + * SHCI_C2_Reinit( ) before jumping to the application. + * When the CPU2 receives that command, it waits for its event input to be set to restart the CPU2 firmware. + * This is required because once C2BOOT has been set once, a clear/set on C2BOOT has no effect. + * When SHCI_C2_Reinit( ) is not called, generating an event to the CPU2 does not have any effect + * So, by default, the application shall both set the event flag and set the C2BOOT bit. + */ + __SEV( ); /* Set the internal event flag and send an event to the CPU2 */ + __WFE( ); /* Clear the internal event flag */ + LL_PWR_EnableBootC2( ); + + return; +} + +void HW_IPCC_Init( void ) +{ + LL_AHB3_GRP1_EnableClock( LL_AHB3_GRP1_PERIPH_IPCC ); + + LL_C1_IPCC_EnableIT_RXO( IPCC ); + LL_C1_IPCC_EnableIT_TXF( IPCC ); + + HAL_NVIC_EnableIRQ(IPCC_C1_RX_IRQn); + HAL_NVIC_EnableIRQ(IPCC_C1_TX_IRQn); + + return; +} + +/****************************************************************************** + * BLE + ******************************************************************************/ +void HW_IPCC_BLE_Init( void ) +{ + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_BLE_EVENT_CHANNEL ); + + return; +} + +void HW_IPCC_BLE_SendCmd( void ) +{ + LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_BLE_CMD_CHANNEL ); + + return; +} + +static void HW_IPCC_BLE_EvtHandler( void ) +{ + HW_IPCC_BLE_RxEvtNot(); + + LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_BLE_EVENT_CHANNEL ); + + return; +} + +void HW_IPCC_BLE_SendAclData( void ) +{ + LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_HCI_ACL_DATA_CHANNEL ); + LL_C1_IPCC_EnableTransmitChannel( IPCC, HW_IPCC_HCI_ACL_DATA_CHANNEL ); + + return; +} + +static void HW_IPCC_BLE_AclDataEvtHandler( void ) +{ + LL_C1_IPCC_DisableTransmitChannel( IPCC, HW_IPCC_HCI_ACL_DATA_CHANNEL ); + + HW_IPCC_BLE_AclDataAckNot(); + + return; +} + +__weak void HW_IPCC_BLE_AclDataAckNot( void ){}; +__weak void HW_IPCC_BLE_RxEvtNot( void ){}; + +/****************************************************************************** + * SYSTEM + ******************************************************************************/ +void HW_IPCC_SYS_Init( void ) +{ + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_SYSTEM_EVENT_CHANNEL ); + + return; +} + +void HW_IPCC_SYS_SendCmd( void ) +{ + LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_SYSTEM_CMD_RSP_CHANNEL ); + LL_C1_IPCC_EnableTransmitChannel( IPCC, HW_IPCC_SYSTEM_CMD_RSP_CHANNEL ); + + return; +} + +static void HW_IPCC_SYS_CmdEvtHandler( void ) +{ + LL_C1_IPCC_DisableTransmitChannel( IPCC, HW_IPCC_SYSTEM_CMD_RSP_CHANNEL ); + + HW_IPCC_SYS_CmdEvtNot(); + + return; +} + +static void HW_IPCC_SYS_EvtHandler( void ) +{ + HW_IPCC_SYS_EvtNot(); + + LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_SYSTEM_EVENT_CHANNEL ); + + return; +} + +__weak void HW_IPCC_SYS_CmdEvtNot( void ){}; +__weak void HW_IPCC_SYS_EvtNot( void ){}; + +/****************************************************************************** + * MAC 802.15.4 + ******************************************************************************/ +#ifdef MAC_802_15_4_WB +void HW_IPCC_MAC_802_15_4_Init( void ) +{ + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL ); + + return; +} + +void HW_IPCC_MAC_802_15_4_SendCmd( void ) +{ + LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL ); + LL_C1_IPCC_EnableTransmitChannel( IPCC, HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL ); + + return; +} + +void HW_IPCC_MAC_802_15_4_SendAck( void ) +{ + LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL ); + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL ); + + return; +} + +static void HW_IPCC_MAC_802_15_4_CmdEvtHandler( void ) +{ + LL_C1_IPCC_DisableTransmitChannel( IPCC, HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL ); + + HW_IPCC_MAC_802_15_4_CmdEvtNot(); + + return; +} + +static void HW_IPCC_MAC_802_15_4_NotEvtHandler( void ) +{ + LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL ); + + HW_IPCC_MAC_802_15_4_EvtNot(); + + return; +} +__weak void HW_IPCC_MAC_802_15_4_CmdEvtNot( void ){}; +__weak void HW_IPCC_MAC_802_15_4_EvtNot( void ){}; +#endif + +/****************************************************************************** + * THREAD + ******************************************************************************/ +#ifdef THREAD_WB +void HW_IPCC_THREAD_Init( void ) +{ + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_THREAD_NOTIFICATION_ACK_CHANNEL ); + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_THREAD_CLI_NOTIFICATION_ACK_CHANNEL ); + + return; +} + +void HW_IPCC_OT_SendCmd( void ) +{ + LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_THREAD_OT_CMD_RSP_CHANNEL ); + LL_C1_IPCC_EnableTransmitChannel( IPCC, HW_IPCC_THREAD_OT_CMD_RSP_CHANNEL ); + + return; +} + +void HW_IPCC_CLI_SendCmd( void ) +{ + LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_THREAD_CLI_CMD_CHANNEL ); + + return; +} + +void HW_IPCC_THREAD_SendAck( void ) +{ + LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_THREAD_NOTIFICATION_ACK_CHANNEL ); + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_THREAD_NOTIFICATION_ACK_CHANNEL ); + + return; +} + +void HW_IPCC_THREAD_CliSendAck( void ) +{ + LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_THREAD_CLI_NOTIFICATION_ACK_CHANNEL ); + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_THREAD_CLI_NOTIFICATION_ACK_CHANNEL ); + + return; +} + +static void HW_IPCC_OT_CmdEvtHandler( void ) +{ + LL_C1_IPCC_DisableTransmitChannel( IPCC, HW_IPCC_THREAD_OT_CMD_RSP_CHANNEL ); + + HW_IPCC_OT_CmdEvtNot(); + + return; +} + +static void HW_IPCC_THREAD_NotEvtHandler( void ) +{ + LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_THREAD_NOTIFICATION_ACK_CHANNEL ); + + HW_IPCC_THREAD_EvtNot(); + + return; +} + +static void HW_IPCC_THREAD_CliNotEvtHandler( void ) +{ + LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_THREAD_CLI_NOTIFICATION_ACK_CHANNEL ); + + HW_IPCC_THREAD_CliEvtNot(); + + return; +} + +__weak void HW_IPCC_OT_CmdEvtNot( void ){}; +__weak void HW_IPCC_CLI_CmdEvtNot( void ){}; +__weak void HW_IPCC_THREAD_EvtNot( void ){}; + +#endif /* THREAD_WB */ + +/****************************************************************************** + * ZIGBEE + ******************************************************************************/ +#ifdef ZIGBEE_WB +void HW_IPCC_ZIGBEE_Init( void ) +{ + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL ); + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL ); + + return; +} + +void HW_IPCC_ZIGBEE_SendM4RequestToM0( void ) +{ + LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL ); + LL_C1_IPCC_EnableTransmitChannel( IPCC, HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL ); + + return; +} + +void HW_IPCC_ZIGBEE_SendM4AckToM0Notify( void ) +{ + LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL ); + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL ); + + return; +} + +static void HW_IPCC_ZIGBEE_CmdEvtHandler( void ) +{ + LL_C1_IPCC_DisableTransmitChannel( IPCC, HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL ); + + HW_IPCC_ZIGBEE_RecvAppliAckFromM0(); + + return; +} + +static void HW_IPCC_ZIGBEE_StackNotifEvtHandler( void ) +{ + LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL ); + + HW_IPCC_ZIGBEE_RecvM0NotifyToM4(); + + return; +} + +static void HW_IPCC_ZIGBEE_StackM0RequestHandler( void ) +{ + LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL ); + + HW_IPCC_ZIGBEE_RecvM0RequestToM4(); + + return; +} + +void HW_IPCC_ZIGBEE_SendM4AckToM0Request( void ) +{ + LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL ); + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL ); + + return; +} + +__weak void HW_IPCC_ZIGBEE_RecvAppliAckFromM0( void ){}; +__weak void HW_IPCC_ZIGBEE_RecvM0NotifyToM4( void ){}; +__weak void HW_IPCC_ZIGBEE_RecvM0RequestToM4( void ){}; +#endif /* ZIGBEE_WB */ + +/****************************************************************************** + * MEMORY MANAGER + ******************************************************************************/ +void HW_IPCC_MM_SendFreeBuf( void (*cb)( void ) ) +{ + if ( LL_C1_IPCC_IsActiveFlag_CHx( IPCC, HW_IPCC_MM_RELEASE_BUFFER_CHANNEL ) ) + { + FreeBufCb = cb; + LL_C1_IPCC_EnableTransmitChannel( IPCC, HW_IPCC_MM_RELEASE_BUFFER_CHANNEL ); + } + else + { + cb(); + + LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_MM_RELEASE_BUFFER_CHANNEL ); + } + + return; +} + +static void HW_IPCC_MM_FreeBufHandler( void ) +{ + LL_C1_IPCC_DisableTransmitChannel( IPCC, HW_IPCC_MM_RELEASE_BUFFER_CHANNEL ); + + FreeBufCb(); + + LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_MM_RELEASE_BUFFER_CHANNEL ); + + return; +} + +/****************************************************************************** + * TRACES + ******************************************************************************/ +void HW_IPCC_TRACES_Init( void ) +{ + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_TRACES_CHANNEL ); + + return; +} + +static void HW_IPCC_TRACES_EvtHandler( void ) +{ + HW_IPCC_TRACES_EvtNot(); + + LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_TRACES_CHANNEL ); + + return; +} + +__weak void HW_IPCC_TRACES_EvtNot( void ){}; + +/******************* (C) COPYRIGHT 2019 STMicroelectronics *****END OF FILE****/ diff --git a/src/utility/STM32Cube_FW/mbox_def.h b/src/utility/STM32Cube_FW/mbox_def.h new file mode 100644 index 00000000..1741a8c3 --- /dev/null +++ b/src/utility/STM32Cube_FW/mbox_def.h @@ -0,0 +1,258 @@ +/** + ****************************************************************************** + * @file mbox_def.h + * @author MCD Application Team + * @brief Mailbox definition + ****************************************************************************** + * @attention + * + * <h2><center>© Copyright (c) 2019 STMicroelectronics. + * All rights reserved.</center></h2> + * + * This software component is licensed by ST under BSD 3-Clause license, + * the "License"; You may not use this file except in compliance with the + * License. You may obtain a copy of the License at: + * opensource.org/licenses/BSD-3-Clause + * + ****************************************************************************** + */ + + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __MBOX_H +#define __MBOX_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "stm32_wpan_common.h" + + /** + * This file shall be identical between the CPU1 and the CPU2 + */ + + /** + ********************************************************************************* + * TABLES + ********************************************************************************* + */ + + /** + * Version + * [0:3] = Build - 0: Untracked - 15:Released - x: Tracked version + * [4:7] = branch - 0: Mass Market - x: ... + * [8:15] = Subversion + * [16:23] = Version minor + * [24:31] = Version major + * + * Memory Size + * [0:7] = Flash ( Number of 4k sector) + * [8:15] = Reserved ( Shall be set to 0 - may be used as flash extension ) + * [16:23] = SRAM2b ( Number of 1k sector) + * [24:31] = SRAM2a ( Number of 1k sector) + */ + typedef PACKED_STRUCT + { + uint32_t Version; + } MB_SafeBootInfoTable_t; + + typedef PACKED_STRUCT + { + uint32_t Version; + uint32_t MemorySize; + uint32_t FusInfo; + } MB_FusInfoTable_t; + + typedef PACKED_STRUCT + { + uint32_t Version; + uint32_t MemorySize; + uint32_t InfoStack; + uint32_t Reserved; + } MB_WirelessFwInfoTable_t; + + typedef struct + { + MB_SafeBootInfoTable_t SafeBootInfoTable; + MB_FusInfoTable_t FusInfoTable; + MB_WirelessFwInfoTable_t WirelessFwInfoTable; + } MB_DeviceInfoTable_t; + + typedef struct + { + uint8_t *pcmd_buffer; + uint8_t *pcs_buffer; + uint8_t *pevt_queue; + uint8_t *phci_acl_data_buffer; + } MB_BleTable_t; + + typedef struct + { + uint8_t *notack_buffer; + uint8_t *clicmdrsp_buffer; + uint8_t *otcmdrsp_buffer; + } MB_ThreadTable_t; + + typedef struct + { + uint8_t *clicmdrsp_buffer; + uint8_t *m0cmd_buffer; + } MB_LldTestsTable_t; + + typedef struct + { + uint8_t *cmdrsp_buffer; + uint8_t *m0cmd_buffer; + } MB_LldBleTable_t; + + typedef struct + { + uint8_t *notifM0toM4_buffer; + uint8_t *appliCmdM4toM0_buffer; + uint8_t *requestM0toM4_buffer; + } MB_ZigbeeTable_t; + /** + * msg + * [0:7] = cmd/evt + * [8:31] = Reserved + */ + typedef struct + { + uint8_t *pcmd_buffer; + uint8_t *sys_queue; + } MB_SysTable_t; + + typedef struct + { + uint8_t *spare_ble_buffer; + uint8_t *spare_sys_buffer; + uint8_t *blepool; + uint32_t blepoolsize; + uint8_t *pevt_free_buffer_queue; + uint8_t *traces_evt_pool; + uint32_t tracespoolsize; + } MB_MemManagerTable_t; + + typedef struct + { + uint8_t *traces_queue; + } MB_TracesTable_t; + + typedef struct + { + uint8_t *p_cmdrsp_buffer; + uint8_t *p_notack_buffer; + uint8_t *evt_queue; + } MB_Mac_802_15_4_t; + + typedef struct + { + MB_DeviceInfoTable_t *p_device_info_table; + MB_BleTable_t *p_ble_table; + MB_ThreadTable_t *p_thread_table; + MB_SysTable_t *p_sys_table; + MB_MemManagerTable_t *p_mem_manager_table; + MB_TracesTable_t *p_traces_table; + MB_Mac_802_15_4_t *p_mac_802_15_4_table; + MB_ZigbeeTable_t *p_zigbee_table; + MB_LldTestsTable_t *p_lld_tests_table; + MB_LldBleTable_t *p_lld_ble_table; +} MB_RefTable_t; + +#ifdef __cplusplus +} +#endif + +/** + ********************************************************************************* + * IPCC CHANNELS + ********************************************************************************* + */ + +/* CPU1 CPU2 + * | (SYSTEM) | + * |----HW_IPCC_SYSTEM_CMD_RSP_CHANNEL-------------->| + * | | + * |<---HW_IPCC_SYSTEM_EVENT_CHANNEL-----------------| + * | | + * | (ZIGBEE) | + * |----HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL------------>| + * | | + * |----HW_IPCC_ZIGBEE_CMD_CLI_CHANNEL-------------->| + * | | + * |<---HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL-------| + * | | + * |<---HW_IPCC_ZIGBEE_CLI_NOTIF_ACK_CHANNEL---------| + * | | + * | (THREAD) | + * |----HW_IPCC_THREAD_OT_CMD_RSP_CHANNEL----------->| + * | | + * |----HW_IPCC_THREAD_CLI_CMD_CHANNEL-------------->| + * | | + * |<---HW_IPCC_THREAD_NOTIFICATION_ACK_CHANNEL------| + * | | + * |<---HW_IPCC_THREAD_CLI_NOTIFICATION_ACK_CHANNEL--| + * | | + * | (BLE) | + * |----HW_IPCC_BLE_CMD_CHANNEL--------------------->| + * | | + * |----HW_IPCC_HCI_ACL_DATA_CHANNEL---------------->| + * | | + * |<---HW_IPCC_BLE_EVENT_CHANNEL--------------------| + * | | + * | (LLD BLE) | + * |----HW_IPCC_LLD_BLE_CMD_CHANNEL----------------->| + * | | + * |<---HW_IPCC_LLD_BLE_RSP_CHANNEL------------------| + * | | + * |<---HW_IPCC_LLD_BLE_M0_CMD_CHANNEL---------------| + * | | + * | (MAC) | + * |----HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL-------->| + * | | + * |<---HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL| + * | | + * | (BUFFER) | + * |----HW_IPCC_MM_RELEASE_BUFFER_CHANNE------------>| + * | | + * | (TRACE) | + * |<----HW_IPCC_TRACES_CHANNEL----------------------| + * | | + * + * + * + */ + + + +/** CPU1 */ +#define HW_IPCC_BLE_CMD_CHANNEL LL_IPCC_CHANNEL_1 +#define HW_IPCC_SYSTEM_CMD_RSP_CHANNEL LL_IPCC_CHANNEL_2 +#define HW_IPCC_THREAD_OT_CMD_RSP_CHANNEL LL_IPCC_CHANNEL_3 +#define HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL LL_IPCC_CHANNEL_3 +#define HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL LL_IPCC_CHANNEL_3 +#define HW_IPCC_MM_RELEASE_BUFFER_CHANNEL LL_IPCC_CHANNEL_4 +#define HW_IPCC_THREAD_CLI_CMD_CHANNEL LL_IPCC_CHANNEL_5 +#define HW_IPCC_LLDTESTS_CLI_CMD_CHANNEL LL_IPCC_CHANNEL_5 +#define HW_IPCC_LLD_BLE_CLI_CMD_CHANNEL LL_IPCC_CHANNEL_5 +#define HW_IPCC_LLD_BLE_CMD_CHANNEL LL_IPCC_CHANNEL_5 +#define HW_IPCC_HCI_ACL_DATA_CHANNEL LL_IPCC_CHANNEL_6 + +/** CPU2 */ +#define HW_IPCC_BLE_EVENT_CHANNEL LL_IPCC_CHANNEL_1 +#define HW_IPCC_SYSTEM_EVENT_CHANNEL LL_IPCC_CHANNEL_2 +#define HW_IPCC_THREAD_NOTIFICATION_ACK_CHANNEL LL_IPCC_CHANNEL_3 +#define HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL LL_IPCC_CHANNEL_3 +#define HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL LL_IPCC_CHANNEL_3 +#define HW_IPCC_LLDTESTS_M0_CMD_CHANNEL LL_IPCC_CHANNEL_3 +#define HW_IPCC_LLD_BLE_M0_CMD_CHANNEL LL_IPCC_CHANNEL_3 +#define HW_IPCC_TRACES_CHANNEL LL_IPCC_CHANNEL_4 +#define HW_IPCC_THREAD_CLI_NOTIFICATION_ACK_CHANNEL LL_IPCC_CHANNEL_5 +#define HW_IPCC_LLDTESTS_CLI_RSP_CHANNEL LL_IPCC_CHANNEL_5 +#define HW_IPCC_LLD_BLE_CLI_RSP_CHANNEL LL_IPCC_CHANNEL_5 +#define HW_IPCC_LLD_BLE_RSP_CHANNEL LL_IPCC_CHANNEL_5 +#define HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL LL_IPCC_CHANNEL_5 +#endif /*__MBOX_H */ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/src/utility/STM32Cube_FW/shci.c b/src/utility/STM32Cube_FW/shci.c new file mode 100644 index 00000000..1edf1feb --- /dev/null +++ b/src/utility/STM32Cube_FW/shci.c @@ -0,0 +1,609 @@ +/** + ****************************************************************************** + * @file shci.c + * @author MCD Application Team + * @brief HCI command for the system channel + ****************************************************************************** + * @attention + * + * <h2><center>© Copyright (c) 2019 STMicroelectronics. + * All rights reserved.</center></h2> + * + * This software component is licensed by ST under BSD 3-Clause license, + * the "License"; You may not use this file except in compliance with the + * License. You may obtain a copy of the License at: + * opensource.org/licenses/BSD-3-Clause + * + ****************************************************************************** + */ + + +/* Includes ------------------------------------------------------------------*/ +#include "stm32_wpan_common.h" + +#include "shci_tl.h" +#include "shci.h" +#include "stm32wbxx.h" + +/* Private typedef -----------------------------------------------------------*/ +/* Private defines -----------------------------------------------------------*/ +/* Private macros ------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +/* Global variables ----------------------------------------------------------*/ +/* Private function prototypes -----------------------------------------------*/ +/* Local Functions Definition ------------------------------------------------------*/ +/* Public Functions Definition ------------------------------------------------------*/ + +/** + * C2 COMMAND + * These commands are sent to the CPU2 + */ +uint8_t SHCI_C2_FUS_GetState( SHCI_FUS_GetState_ErrorCode_t *p_error_code ) +{ + /** + * A command status event + payload has the same size than the expected command complete + */ + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE + 1]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send( SHCI_OPCODE_C2_FUS_GET_STATE, + 0, + 0, + p_rsp ); + + if(p_error_code != 0) + { + *p_error_code = (SHCI_FUS_GetState_ErrorCode_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[1]); + } + + return (((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_FUS_FwUpgrade( uint32_t fw_src_add, uint32_t fw_dest_add ) +{ + /** + * TL_BLEEVT_CS_BUFFER_SIZE is 15 bytes so it is large enough to hold the 8 bytes of command parameters + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + uint32_t *p_cmd; + uint8_t cmd_length; + + p_cmd = (uint32_t*)local_buffer; + cmd_length = 0; + + if(fw_src_add != 0) + { + *p_cmd = fw_src_add; + cmd_length += 4; + } + + if(fw_dest_add != 0) + { + *(p_cmd+1) = fw_dest_add; + cmd_length += 4; + } + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send( SHCI_OPCODE_C2_FUS_FW_UPGRADE, + cmd_length, + local_buffer, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_FUS_FwDelete( void ) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send( SHCI_OPCODE_C2_FUS_FW_DELETE, + 0, + 0, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_FUS_UpdateAuthKey( SHCI_C2_FUS_UpdateAuthKey_Cmd_Param_t *pParam ) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send( SHCI_OPCODE_C2_FUS_UPDATE_AUTH_KEY, + sizeof( SHCI_C2_FUS_UpdateAuthKey_Cmd_Param_t ), + (uint8_t*)pParam, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_FUS_LockAuthKey( void ) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send( SHCI_OPCODE_C2_FUS_LOCK_AUTH_KEY, + 0, + 0, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_FUS_StoreUsrKey( SHCI_C2_FUS_StoreUsrKey_Cmd_Param_t *pParam, uint8_t *p_key_index ) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE + 1]; + TL_EvtPacket_t * p_rsp; + uint8_t local_payload_len; + + if(pParam->KeyType == KEYTYPE_ENCRYPTED) + { + /** + * When the key is encrypted, the 12 bytes IV Key is included in the payload as well + * The IV key is always 12 bytes + */ + local_payload_len = pParam->KeySize + 2 + 12; + } + else + { + local_payload_len = pParam->KeySize + 2; + } + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send( SHCI_OPCODE_C2_FUS_STORE_USR_KEY, + local_payload_len , + (uint8_t*)pParam, + p_rsp ); + + *p_key_index = (((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[1]); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_FUS_LoadUsrKey( uint8_t key_index ) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + local_buffer[0] = key_index; + + shci_send( SHCI_OPCODE_C2_FUS_LOAD_USR_KEY, + 1, + local_buffer, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_FUS_StartWs( void ) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send( SHCI_OPCODE_C2_FUS_START_WS, + 0, + 0, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + + +SHCI_CmdStatus_t SHCI_C2_FUS_LockUsrKey( uint8_t key_index ) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + local_buffer[0] = key_index; + + shci_send( SHCI_OPCODE_C2_FUS_LOCK_USR_KEY, + 1, + local_buffer, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_BLE_Init( SHCI_C2_Ble_Init_Cmd_Packet_t *pCmdPacket ) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send( SHCI_OPCODE_C2_BLE_INIT, + sizeof( SHCI_C2_Ble_Init_Cmd_Param_t ), + (uint8_t*)&pCmdPacket->Param, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_THREAD_Init( void ) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send( SHCI_OPCODE_C2_THREAD_INIT, + 0, + 0, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_LLDTESTS_Init( uint8_t param_size, uint8_t * p_param ) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send( SHCI_OPCODE_C2_LLD_TESTS_INIT, + param_size, + p_param, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_LLD_BLE_Init( uint8_t param_size, uint8_t * p_param ) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send( SHCI_OPCODE_C2_LLD_BLE_INIT, + param_size, + p_param, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_ZIGBEE_Init( void ) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send( SHCI_OPCODE_C2_ZIGBEE_INIT, + 0, + 0, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_DEBUG_Init( SHCI_C2_DEBUG_Init_Cmd_Packet_t *pCmdPacket ) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send( SHCI_OPCODE_C2_DEBUG_INIT, + sizeof( SHCI_C2_DEBUG_init_Cmd_Param_t ), + (uint8_t*)&pCmdPacket->Param, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_FLASH_EraseActivity( SHCI_EraseActivity_t erase_activity ) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + local_buffer[0] = erase_activity; + + shci_send( SHCI_OPCODE_C2_FLASH_ERASE_ACTIVITY, + 1, + local_buffer, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_CONCURRENT_SetMode( SHCI_C2_CONCURRENT_Mode_Param_t Mode ) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + local_buffer[0] = Mode; + + shci_send( SHCI_OPCODE_C2_CONCURRENT_SET_MODE, + 1, + local_buffer, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_FLASH_StoreData( SHCI_C2_FLASH_Ip_t Ip ) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + local_buffer[0] = Ip; + + shci_send( SHCI_OPCODE_C2_FLASH_STORE_DATA, + 1, + local_buffer, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_FLASH_EraseData( SHCI_C2_FLASH_Ip_t Ip ) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + local_buffer[0] = Ip; + + shci_send( SHCI_OPCODE_C2_FLASH_ERASE_DATA, + 1, + local_buffer, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_RADIO_AllowLowPower( SHCI_C2_FLASH_Ip_t Ip,uint8_t FlagRadioLowPowerOn) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + local_buffer[0] = Ip; + local_buffer[1] = FlagRadioLowPowerOn; + + shci_send( SHCI_OPCODE_C2_RADIO_ALLOW_LOW_POWER, + 2, + local_buffer, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_MAC_802_15_4_Init( void ) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send( SHCI_OPCODE_C2_MAC_802_15_4_INIT, + 0, + 0, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_Reinit( void ) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send( SHCI_OPCODE_C2_REINIT, + 0, + 0, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_ExtpaConfig(uint32_t gpio_port, uint16_t gpio_pin_number, uint8_t gpio_polarity, uint8_t gpio_status) +{ + /** + * TL_BLEEVT_CS_BUFFER_SIZE is 15 bytes so it is large enough to hold the 8 bytes of command parameters + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + ((SHCI_C2_EXTPA_CONFIG_Cmd_Param_t*)local_buffer)->gpio_port = gpio_port; + ((SHCI_C2_EXTPA_CONFIG_Cmd_Param_t*)local_buffer)->gpio_pin_number = gpio_pin_number; + ((SHCI_C2_EXTPA_CONFIG_Cmd_Param_t*)local_buffer)->gpio_polarity = gpio_polarity; + ((SHCI_C2_EXTPA_CONFIG_Cmd_Param_t*)local_buffer)->gpio_status = gpio_status; + + shci_send( SHCI_OPCODE_C2_EXTPA_CONFIG, + 8, + local_buffer, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_SetFlashActivityControl(SHCI_C2_SET_FLASH_ACTIVITY_CONTROL_Source_t Source) +{ + /** + * TL_BLEEVT_CS_BUFFER_SIZE is 15 bytes so it is large enough to hold the 1 byte of command parameter + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + local_buffer[0] = (uint8_t)Source; + + shci_send( SHCI_OPCODE_C2_SET_FLASH_ACTIVITY_CONTROL, + 1, + local_buffer, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_Config(SHCI_C2_CONFIG_Cmd_Param_t *pCmdPacket) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send( SHCI_OPCODE_C2_CONFIG, + sizeof(SHCI_C2_CONFIG_Cmd_Param_t), + (uint8_t*)pCmdPacket, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + + +/** + * Local System COMMAND + * These commands are NOT sent to the CPU2 + */ + +SHCI_CmdStatus_t SHCI_GetWirelessFwInfo( WirelessFwInfo_t* pWirelessInfo ) +{ + uint32_t ipccdba = 0; + MB_RefTable_t * p_RefTable = NULL; + uint32_t version = 0; + uint32_t memorySize = 0; + uint32_t infoStack = 0; + + ipccdba = READ_BIT( FLASH->IPCCBR, FLASH_IPCCBR_IPCCDBA ); + p_RefTable = (MB_RefTable_t*)((ipccdba<<2) + SRAM2A_BASE); + + /** + * Retrieve the WirelessFwInfoTable + * This table is stored in RAM at startup during the TL (transport layer) initialization + */ + version = p_RefTable->p_device_info_table->WirelessFwInfoTable.Version; + pWirelessInfo->VersionMajor = ((version & INFO_VERSION_MAJOR_MASK) >> INFO_VERSION_MAJOR_OFFSET); + pWirelessInfo->VersionMinor = ((version & INFO_VERSION_MINOR_MASK) >> INFO_VERSION_MINOR_OFFSET); + pWirelessInfo->VersionSub = ((version & INFO_VERSION_SUB_MASK) >> INFO_VERSION_SUB_OFFSET); + pWirelessInfo->VersionBranch = ((version & INFO_VERSION_BRANCH_MASK) >> INFO_VERSION_BRANCH_OFFSET); + pWirelessInfo->VersionReleaseType = ((version & INFO_VERSION_TYPE_MASK) >> INFO_VERSION_TYPE_OFFSET); + + memorySize = p_RefTable->p_device_info_table->WirelessFwInfoTable.MemorySize; + pWirelessInfo->MemorySizeSram2B = ((memorySize & INFO_SIZE_SRAM2B_MASK) >> INFO_SIZE_SRAM2B_OFFSET); + pWirelessInfo->MemorySizeSram2A = ((memorySize & INFO_SIZE_SRAM2A_MASK) >> INFO_SIZE_SRAM2A_OFFSET); + pWirelessInfo->MemorySizeSram1 = ((memorySize & INFO_SIZE_SRAM1_MASK) >> INFO_SIZE_SRAM1_OFFSET); + pWirelessInfo->MemorySizeFlash = ((memorySize & INFO_SIZE_FLASH_MASK) >> INFO_SIZE_FLASH_OFFSET); + + infoStack = p_RefTable->p_device_info_table->WirelessFwInfoTable.InfoStack; + pWirelessInfo->StackType = ((infoStack & INFO_STACK_TYPE_MASK) >> INFO_STACK_TYPE_OFFSET); + + /** + * Retrieve the FusInfoTable + * This table is stored in RAM at startup during the TL (transport layer) initialization + */ + version = p_RefTable->p_device_info_table->FusInfoTable.Version; + pWirelessInfo->FusVersionMajor = ((version & INFO_VERSION_MAJOR_MASK) >> INFO_VERSION_MAJOR_OFFSET); + pWirelessInfo->FusVersionMinor = ((version & INFO_VERSION_MINOR_MASK) >> INFO_VERSION_MINOR_OFFSET); + pWirelessInfo->FusVersionSub = ((version & INFO_VERSION_SUB_MASK) >> INFO_VERSION_SUB_OFFSET); + + memorySize = p_RefTable->p_device_info_table->FusInfoTable.MemorySize; + pWirelessInfo->FusMemorySizeSram2B = ((memorySize & INFO_SIZE_SRAM2B_MASK) >> INFO_SIZE_SRAM2B_OFFSET); + pWirelessInfo->FusMemorySizeSram2A = ((memorySize & INFO_SIZE_SRAM2A_MASK) >> INFO_SIZE_SRAM2A_OFFSET); + pWirelessInfo->FusMemorySizeFlash = ((memorySize & INFO_SIZE_FLASH_MASK) >> INFO_SIZE_FLASH_OFFSET); + + return (SHCI_Success); +} + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/src/utility/STM32Cube_FW/shci.h b/src/utility/STM32Cube_FW/shci.h new file mode 100644 index 00000000..e737f4c5 --- /dev/null +++ b/src/utility/STM32Cube_FW/shci.h @@ -0,0 +1,944 @@ +/** + ****************************************************************************** + * @file shci.h + * @author MCD Application Team + * @brief HCI command for the system channel + ****************************************************************************** + * @attention + * + * <h2><center>© Copyright (c) 2019 STMicroelectronics. + * All rights reserved.</center></h2> + * + * This software component is licensed by ST under BSD 3-Clause license, + * the "License"; You may not use this file except in compliance with the + * License. You may obtain a copy of the License at: + * opensource.org/licenses/BSD-3-Clause + * + ****************************************************************************** + */ + + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __SHCI_H +#define __SHCI_H + +#ifdef __cplusplus +extern "C" { +#endif + + /* Includes ------------------------------------------------------------------*/ +#include "mbox_def.h" /* Requested to expose the MB_WirelessFwInfoTable_t structure */ + + /* Exported types ------------------------------------------------------------*/ + + /* SYSTEM EVENT */ + typedef enum + { + WIRELESS_FW_RUNNING = 0x00, + RSS_FW_RUNNING = 0x01, + } SHCI_SysEvt_Ready_Rsp_t; + + /* ERROR CODES + * + * These error codes are detected on M0 side and are send back to the M4 via a system + * notification message. It is up to the application running on M4 to manage these errors + * + * These errors can be generated by all layers (low level driver, stack, framework infrastructure, etc..) + */ + typedef enum + { + ERR_BLE_INIT = 0, + ERR_THREAD_LLD_FATAL_ERROR = 125, /* The LLD driver used on 802_15_4 detected a fatal error */ + ERR_THREAD_UNKNOWN_CMD = 126, /* The command send by the M4 to control the Thread stack is unknown */ + ERR_ZIGBEE_UNKNOWN_CMD = 200, /* The command send by the M4 to control the Zigbee stack is unknown */ + } SCHI_SystemErrCode_t; + +#define SHCI_EVTCODE ( 0xFF ) +#define SHCI_SUB_EVT_CODE_BASE ( 0x9200 ) + + /** + * THE ORDER SHALL NOT BE CHANGED TO GUARANTEE COMPATIBILITY WITH THE CPU1 DEFINITION + */ + typedef enum + { + SHCI_SUB_EVT_CODE_READY = SHCI_SUB_EVT_CODE_BASE, + SHCI_SUB_EVT_ERROR_NOTIF, + SHCI_SUB_EVT_BLE_NVM_RAM_UPDATE, + SHCI_SUB_EVT_OT_NVM_RAM_UPDATE, + SHCI_SUB_EVT_NVM_START_WRITE, + SHCI_SUB_EVT_NVM_END_WRITE, + SHCI_SUB_EVT_NVM_START_ERASE, + SHCI_SUB_EVT_NVM_END_ERASE, + } SHCI_SUB_EVT_CODE_t; + + /** + * SHCI_SUB_EVT_CODE_READY + * This notifies the CPU1 that the CPU2 is now ready to receive commands + * It reports as well which firmware is running on CPU2 : The wireless stack of the FUS (previously named RSS) + */ + typedef PACKED_STRUCT{ + SHCI_SysEvt_Ready_Rsp_t sysevt_ready_rsp; + } SHCI_C2_Ready_Evt_t; + + /** + * SHCI_SUB_EVT_ERROR_NOTIF + * This reports to the CPU1 some error form the CPU2 + */ + typedef PACKED_STRUCT{ + SCHI_SystemErrCode_t errorCode; + } SHCI_C2_ErrorNotif_Evt_t; + + /** + * SHCI_SUB_EVT_BLE_NVM_RAM_UPDATE + * This notifies the CPU1 which part of the BLE NVM RAM has been updated so that only the modified + * section could be written in Flash/NVM + * StartAddress : Start address of the section that has been modified + * Size : Size (in bytes) of the section that has been modified + */ + typedef PACKED_STRUCT{ + uint32_t StartAddress; + uint32_t Size; + } SHCI_C2_BleNvmRamUpdate_Evt_t; + + /** + * SHCI_SUB_EVT_OT_NVM_RAM_UPDATE + * This notifies the CPU1 which part of the OT NVM RAM has been updated so that only the modified + * section could be written in Flash/NVM + * StartAddress : Start address of the section that has been modified + * Size : Size (in bytes) of the section that has been modified + */ + typedef PACKED_STRUCT{ + uint32_t StartAddress; + uint32_t Size; + } SHCI_C2_OtNvmRamUpdate_Evt_t; + + /** + * SHCI_SUB_EVT_NVM_START_WRITE + * This notifies the CPU1 that the CPU2 has started a write procedure in Flash + * NumberOfWords : The number of 64bits data the CPU2 needs to write in Flash. + * For each 64bits data, the algorithm as described in AN5289 is executed. + * When this number is reported to 0, it means the Number of 64bits to be written + * was unknown when the procedure has started. + * When all data are written, the SHCI_SUB_EVT_NVM_END_WRITE event is reported + */ + typedef PACKED_STRUCT{ + uint32_t NumberOfWords; + } SHCI_C2_NvmStartWrite_Evt_t; + + /** + * SHCI_SUB_EVT_NVM_END_WRITE + * This notifies the CPU1 that the CPU2 has written all expected data in Flash + */ + + /** + * SHCI_SUB_EVT_NVM_START_ERASE + * This notifies the CPU1 that the CPU2 has started a erase procedure in Flash + * NumberOfSectors : The number of sectors the CPU2 needs to erase in Flash. + * For each sector, the algorithm as described in AN5289 is executed. + * When this number is reported to 0, it means the Number of sectors to be erased + * was unknown when the procedure has started. + * When all sectors are erased, the SHCI_SUB_EVT_NVM_END_ERASE event is reported + */ + typedef PACKED_STRUCT{ + uint32_t NumberOfSectors; + } SHCI_C2_NvmStartErase_Evt_t; + + /** + * SHCI_SUB_EVT_NVM_END_ERASE + * This notifies the CPU1 that the CPU2 has erased all expected flash sectors + */ + + /* SYSTEM COMMAND */ + typedef PACKED_STRUCT + { + uint32_t MetaData[3]; + } SHCI_Header_t; + + typedef enum + { + SHCI_Success = 0x00, + SHCI_UNKNOWN_CMD = 0x01, + SHCI_ERR_UNSUPPORTED_FEATURE = 0x11, + SHCI_ERR_INVALID_HCI_CMD_PARAMS = 0x12, + SHCI_FUS_CMD_NOT_SUPPORTED = 0xFF, + } SHCI_CmdStatus_t; + + typedef enum + { + SHCI_8BITS = 0x01, + SHCI_16BITS = 0x02, + SHCI_32BITS = 0x04, + } SHCI_Busw_t; + +#define SHCI_OGF ( 0x3F ) +#define SHCI_OCF_BASE ( 0x50 ) + + /** + * THE ORDER SHALL NOT BE CHANGED TO GUARANTEE COMPATIBILITY WITH THE CPU2 DEFINITION + */ + typedef enum + { + SHCI_OCF_C2_RESERVED1 = SHCI_OCF_BASE, + SHCI_OCF_C2_RESERVED2, + SHCI_OCF_C2_FUS_GET_STATE, + SHCI_OCF_C2_FUS_RESERVED1, + SHCI_OCF_C2_FUS_FW_UPGRADE, + SHCI_OCF_C2_FUS_FW_DELETE, + SHCI_OCF_C2_FUS_UPDATE_AUTH_KEY, + SHCI_OCF_C2_FUS_LOCK_AUTH_KEY, + SHCI_OCF_C2_FUS_STORE_USR_KEY, + SHCI_OCF_C2_FUS_LOAD_USR_KEY, + SHCI_OCF_C2_FUS_START_WS, + SHCI_OCF_C2_FUS_RESERVED2, + SHCI_OCF_C2_FUS_RESERVED3, + SHCI_OCF_C2_FUS_LOCK_USR_KEY, + SHCI_OCF_C2_FUS_RESERVED5, + SHCI_OCF_C2_FUS_RESERVED6, + SHCI_OCF_C2_FUS_RESERVED7, + SHCI_OCF_C2_FUS_RESERVED8, + SHCI_OCF_C2_FUS_RESERVED9, + SHCI_OCF_C2_FUS_RESERVED10, + SHCI_OCF_C2_FUS_RESERVED11, + SHCI_OCF_C2_FUS_RESERVED12, + SHCI_OCF_C2_BLE_INIT, + SHCI_OCF_C2_THREAD_INIT, + SHCI_OCF_C2_DEBUG_INIT, + SHCI_OCF_C2_FLASH_ERASE_ACTIVITY, + SHCI_OCF_C2_CONCURRENT_SET_MODE, + SHCI_OCF_C2_FLASH_STORE_DATA, + SHCI_OCF_C2_FLASH_ERASE_DATA, + SHCI_OCF_C2_RADIO_ALLOW_LOW_POWER, + SHCI_OCF_C2_MAC_802_15_4_INIT, + SHCI_OCF_C2_REINIT, + SHCI_OCF_C2_ZIGBEE_INIT, + SHCI_OCF_C2_LLD_TESTS_INIT, + SHCI_OCF_C2_EXTPA_CONFIG, + SHCI_OCF_C2_SET_FLASH_ACTIVITY_CONTROL, + SHCI_OCF_C2_LLD_BLE_INIT, + SHCI_OCF_C2_CONFIG, + } SHCI_OCF_t; + +#define SHCI_OPCODE_C2_FUS_GET_STATE (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_GET_STATE) +/** No command parameters */ +/** Response parameters*/ + typedef enum + { + FUS_STATE_NO_ERROR = 0x00, + FUS_STATE_IMG_NOT_FOUND = 0x01, + FUS_STATE_IMG_CORRUPT = 0x02, + FUS_STATE_IMG_NOT_AUTHENTIC = 0x03, + FUS_STATE_IMG_NOT_ENOUGH_SPACE = 0x04, + FUS_STATE_ERR_UNKNOWN = 0xFF, + } SHCI_FUS_GetState_ErrorCode_t; + +#define SHCI_OPCODE_C2_FUS_RESERVED1 (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_RESERVED1) +/** No command parameters */ +/** No response parameters*/ + +#define SHCI_OPCODE_C2_FUS_FW_UPGRADE (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_FW_UPGRADE) + /** No structure for command parameters */ + /** No response parameters*/ + +#define SHCI_OPCODE_C2_FUS_FW_DELETE (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_FW_DELETE) +/** No command parameters */ +/** No response parameters*/ + +#define SHCI_OPCODE_C2_FUS_UPDATE_AUTH_KEY (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_UPDATE_AUTH_KEY) + typedef PACKED_STRUCT{ + uint8_t KeySize; + uint8_t KeyData[64]; + } SHCI_C2_FUS_UpdateAuthKey_Cmd_Param_t; + + /** No response parameters*/ + +#define SHCI_OPCODE_C2_FUS_LOCK_AUTH_KEY (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_LOCK_AUTH_KEY) +/** No command parameters */ +/** No response parameters*/ + +#define SHCI_OPCODE_C2_FUS_STORE_USR_KEY (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_STORE_USR_KEY) + /** Command parameters */ + /* List of supported key type */ + enum + { + KEYTYPE_NONE = 0x00, + KEYTYPE_SIMPLE = 0x01, + KEYTYPE_MASTER = 0x02, + KEYTYPE_ENCRYPTED = 0x03, + }; + + /* List of supported key size */ + enum + { + KEYSIZE_16 = 16, + KEYSIZE_32 = 32, + }; + + typedef PACKED_STRUCT{ + uint8_t KeyType; + uint8_t KeySize; + uint8_t KeyData[32 + 12]; + } SHCI_C2_FUS_StoreUsrKey_Cmd_Param_t; + + /** Response parameters*/ + /** It responds a 1 byte value holding the index given for the stored key */ + +#define SHCI_OPCODE_C2_FUS_LOAD_USR_KEY (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_LOAD_USR_KEY) + /** Command parameters */ + /** 1 byte holding the key index value */ + + /** No response parameters*/ + +#define SHCI_OPCODE_C2_FUS_START_WS (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_START_WS) +/** No command parameters */ +/** No response parameters*/ + +#define SHCI_OPCODE_C2_FUS_RESERVED2 (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_RESERVED2) +/** No command parameters */ +/** No response parameters*/ + +#define SHCI_OPCODE_C2_FUS_RESERVED3 (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_RESERVED3) +/** No command parameters */ +/** No response parameters*/ + +#define SHCI_OPCODE_C2_FUS_LOCK_USR_KEY (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_LOCK_USR_KEY) + /** Command parameters */ + /** 1 byte holding the key index value */ + + /** No response parameters*/ + +#define SHCI_OPCODE_C2_FUS_RESERVED5 (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_RESERVED5) +/** No command parameters */ +/** No response parameters*/ + +#define SHCI_OPCODE_C2_FUS_RESERVED6 (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_RESERVED6) +/** No command parameters */ +/** No response parameters*/ + +#define SHCI_OPCODE_C2_FUS_RESERVED7 (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_RESERVED7) +/** No command parameters */ +/** No response parameters*/ + +#define SHCI_OPCODE_C2_FUS_RESERVED8 (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_RESERVED8) +/** No command parameters */ +/** No response parameters*/ + +#define SHCI_OPCODE_C2_FUS_RESERVED9 (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_RESERVED9) +/** No command parameters */ +/** No response parameters*/ + +#define SHCI_OPCODE_C2_FUS_RESERVED10 (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_RESERVED10) +/** No command parameters */ +/** No response parameters*/ + +#define SHCI_OPCODE_C2_FUS_RESERVED11 (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_RESERVED11) +/** No command parameters */ +/** No response parameters*/ + +#define SHCI_OPCODE_C2_FUS_RESERVED12 (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_RESERVED12) +/** No command parameters */ +/** No response parameters*/ + +#define SHCI_OPCODE_C2_BLE_INIT (( SHCI_OGF << 10) + SHCI_OCF_C2_BLE_INIT) + /** THE ORDER SHALL NOT BE CHANGED */ + typedef PACKED_STRUCT{ + uint8_t* pBleBufferAddress; /**< NOT USED CURRENTLY */ + uint32_t BleBufferSize; /**< Size of the Buffer allocated in pBleBufferAddress */ + uint16_t NumAttrRecord; + uint16_t NumAttrServ; + uint16_t AttrValueArrSize; + uint8_t NumOfLinks; + uint8_t ExtendedPacketLengthEnable; + uint8_t PrWriteListSize; + uint8_t MblockCount; + uint16_t AttMtu; + uint16_t SlaveSca; + uint8_t MasterSca; + uint8_t LsSource; + uint32_t MaxConnEventLength; + uint16_t HsStartupTime; + uint8_t ViterbiEnable; + uint8_t LlOnly; + uint8_t HwVersion; + } SHCI_C2_Ble_Init_Cmd_Param_t; + + typedef PACKED_STRUCT{ + SHCI_Header_t Header; /** Does not need to be initialized by the user */ + SHCI_C2_Ble_Init_Cmd_Param_t Param; + } SHCI_C2_Ble_Init_Cmd_Packet_t; + + /** No response parameters*/ + +#define SHCI_OPCODE_C2_THREAD_INIT (( SHCI_OGF << 10) + SHCI_OCF_C2_THREAD_INIT) +/** No command parameters */ +/** No response parameters*/ + +#define SHCI_OPCODE_C2_DEBUG_INIT (( SHCI_OGF << 10) + SHCI_OCF_C2_DEBUG_INIT) + /** Command parameters */ + typedef PACKED_STRUCT + { + uint8_t thread_config; + uint8_t ble_config; + uint8_t mac_802_15_4_config; + uint8_t zigbee_config; + } SHCI_C2_DEBUG_TracesConfig_t; + + typedef PACKED_STRUCT + { + uint8_t ble_dtb_cfg; + uint8_t reserved[3]; + } SHCI_C2_DEBUG_GeneralConfig_t; + + typedef PACKED_STRUCT{ + uint8_t *pGpioConfig; + uint8_t *pTracesConfig; + uint8_t *pGeneralConfig; + uint8_t GpioConfigSize; + uint8_t TracesConfigSize; + uint8_t GeneralConfigSize; + } SHCI_C2_DEBUG_init_Cmd_Param_t; + + typedef PACKED_STRUCT{ + SHCI_Header_t Header; /** Does not need to be initialized by the user */ + SHCI_C2_DEBUG_init_Cmd_Param_t Param; + } SHCI_C2_DEBUG_Init_Cmd_Packet_t; + /** No response parameters*/ + +#define SHCI_OPCODE_C2_FLASH_ERASE_ACTIVITY (( SHCI_OGF << 10) + SHCI_OCF_C2_FLASH_ERASE_ACTIVITY) + /** Command parameters */ + typedef enum + { + ERASE_ACTIVITY_OFF = 0x00, + ERASE_ACTIVITY_ON = 0x01, + } SHCI_EraseActivity_t; + + /** No response parameters*/ + +#define SHCI_OPCODE_C2_CONCURRENT_SET_MODE (( SHCI_OGF << 10) + SHCI_OCF_C2_CONCURRENT_SET_MODE) +/** command parameters */ + typedef enum + { + BLE_ENABLE, + THREAD_ENABLE, + ZIGBEE_ENABLE, + } SHCI_C2_CONCURRENT_Mode_Param_t; + /** No response parameters*/ + +#define SHCI_OPCODE_C2_FLASH_STORE_DATA (( SHCI_OGF << 10) + SHCI_OCF_C2_FLASH_STORE_DATA) +#define SHCI_OPCODE_C2_FLASH_ERASE_DATA (( SHCI_OGF << 10) + SHCI_OCF_C2_FLASH_ERASE_DATA) +/** command parameters */ + typedef enum + { + BLE_IP, + THREAD_IP, + ZIGBEE_IP, + } SHCI_C2_FLASH_Ip_t; + /** No response parameters*/ + +#define SHCI_OPCODE_C2_RADIO_ALLOW_LOW_POWER (( SHCI_OGF << 10) + SHCI_OCF_C2_RADIO_ALLOW_LOW_POWER) + +#define SHCI_OPCODE_C2_MAC_802_15_4_INIT (( SHCI_OGF << 10) + SHCI_OCF_C2_MAC_802_15_4_INIT) + +#define SHCI_OPCODE_C2_REINIT (( SHCI_OGF << 10) + SHCI_OCF_C2_REINIT) + +#define SHCI_OPCODE_C2_ZIGBEE_INIT (( SHCI_OGF << 10) + SHCI_OCF_C2_ZIGBEE_INIT) + +#define SHCI_OPCODE_C2_LLD_TESTS_INIT (( SHCI_OGF << 10) + SHCI_OCF_C2_LLD_TESTS_INIT) + +#define SHCI_OPCODE_C2_LLD_BLE_INIT (( SHCI_OGF << 10) + SHCI_OCF_C2_LLD_BLE_INIT) + +#define SHCI_OPCODE_C2_EXTPA_CONFIG (( SHCI_OGF << 10) + SHCI_OCF_C2_EXTPA_CONFIG) + /** Command parameters */ + enum + { + EXT_PA_ENABLED_LOW, + EXT_PA_ENABLED_HIGH, + }/* gpio_polarity */; + + enum + { + EXT_PA_DISABLED, + EXT_PA_ENABLED, + }/* gpio_status */; + + typedef PACKED_STRUCT{ + uint32_t gpio_port; + uint16_t gpio_pin_number; + uint8_t gpio_polarity; + uint8_t gpio_status; + } SHCI_C2_EXTPA_CONFIG_Cmd_Param_t; + + /** No response parameters*/ + +#define SHCI_OPCODE_C2_SET_FLASH_ACTIVITY_CONTROL (( SHCI_OGF << 10) + SHCI_OCF_C2_SET_FLASH_ACTIVITY_CONTROL) + /** Command parameters */ + typedef enum + { + FLASH_ACTIVITY_CONTROL_PES, + FLASH_ACTIVITY_CONTROL_SEM7, + }SHCI_C2_SET_FLASH_ACTIVITY_CONTROL_Source_t; + + /** No response parameters*/ + +#define SHCI_OPCODE_C2_CONFIG (( SHCI_OGF << 10) + SHCI_OCF_C2_CONFIG) + /** Command parameters */ + typedef PACKED_STRUCT{ + uint8_t PayloadCmdSize; + uint8_t Config1; + uint8_t EvtMask1; + uint8_t Spare1; + uint32_t BleNvmRamAddress; + uint32_t ThreadNvmRamAddress; + } SHCI_C2_CONFIG_Cmd_Param_t; + +/** + * PayloadCmdSize + * Value that shall be used + */ +#define SHCI_C2_CONFIG_PAYLOAD_CMD_SIZE (sizeof(SHCI_C2_CONFIG_Cmd_Param_t) - 1) + +/** + * Config1 + * Each definition below may be added together to build the Config1 value + * WARNING : Only one definition per bit shall be added to build the Config1 value + */ +#define SHCI_C2_CONFIG_CONFIG1_BIT0_BLE_NVM_DATA_TO_INTERNAL_FLASH (0<<0) +#define SHCI_C2_CONFIG_CONFIG1_BIT0_BLE_NVM_DATA_TO_SRAM (1<<0) +#define SHCI_C2_CONFIG_CONFIG1_BIT1_THREAD_NVM_DATA_TO_INTERNAL_FLASH (0<<1) +#define SHCI_C2_CONFIG_CONFIG1_BIT1_THREAD_NVM_DATA_TO_SRAM (1<<1) + +/** + * EvtMask1 + * Each definition below may be added together to build the EvtMask1 value + */ +#define SHCI_C2_CONFIG_EVTMASK1_BIT0_ERROR_NOTIF_ENABLE (1<<0) +#define SHCI_C2_CONFIG_EVTMASK1_BIT1_BLE_NVM_RAM_UPDATE_ENABLE (1<<1) +#define SHCI_C2_CONFIG_EVTMASK1_BIT2_OT_NVM_RAM_UPDATE_ENABLE (1<<2) +#define SHCI_C2_CONFIG_EVTMASK1_BIT3_NVM_START_WRITE_ENABLE (1<<3) +#define SHCI_C2_CONFIG_EVTMASK1_BIT4_NVM_END_WRITE_ENABLE (1<<4) +#define SHCI_C2_CONFIG_EVTMASK1_BIT5_NVM_START_ERASE_ENABLE (1<<5) +#define SHCI_C2_CONFIG_EVTMASK1_BIT6_NVM_END_ERASE_ENABLE (1<<6) + +/** + * BleNvmRamAddress + * The buffer shall have a size of BLE_NVM_SRAM_SIZE number of 32bits + * The buffer shall be allocated in SRAM2 + */ +#define BLE_NVM_SRAM_SIZE (507) + +/** + * ThreadNvmRamAddress + * The buffer shall have a size of THREAD_NVM_SRAM_SIZE number of 32bits + * The buffer shall be allocated in SRAM2 + */ +#define THREAD_NVM_SRAM_SIZE (1016) + + + /** No response parameters*/ + + /* Exported type --------------------------------------------------------*/ + +typedef MB_WirelessFwInfoTable_t SHCI_WirelessFwInfoTable_t; + +/* + * At startup, the informations relative to the wireless binary are stored in RAM trough a structure defined by + * SHCI_WirelessFwInfoTable_t.This structure contains 4 fields (Version,MemorySize, Stack_info and a reserved part) + * each of those coded on 32 bits as shown on the table below: + * + * + * |7 |6 |5 |4 |3 |2 |1 |0 |7 |6 |5 |4 |3 |2 |1 |0 |7 |6 |5 |4 |3 |2 |1 |0 |7 |6 |5 |4 |3 |2 |1 |0 | + * ------------------------------------------------------------------------------------------------- + * Version | Major version | Minor version | Sub version | Branch |Releas Type| + * ------------------------------------------------------------------------------------------------- + * MemorySize | SRAM2B (kB) | SRAM2A (kB) | SRAM1 (kB) | FLASH (4kb) | + * ------------------------------------------------------------------------------------------------- + * Info stack | Reserved | Reserved | Reserved | Type (MAC,Thread,BLE) | + * ------------------------------------------------------------------------------------------------- + * Reserved | Reserved | Reserved | Reserved | Reserved | + * ------------------------------------------------------------------------------------------------- + * + */ + +/* Field Version */ +#define INFO_VERSION_MAJOR_OFFSET 24 +#define INFO_VERSION_MAJOR_MASK 0xff000000 +#define INFO_VERSION_MINOR_OFFSET 16 +#define INFO_VERSION_MINOR_MASK 0x00ff0000 +#define INFO_VERSION_SUB_OFFSET 8 +#define INFO_VERSION_SUB_MASK 0x0000ff00 +#define INFO_VERSION_BRANCH_OFFSET 4 +#define INFO_VERSION_BRANCH_MASK 0x0000000f0 +#define INFO_VERSION_TYPE_OFFSET 0 +#define INFO_VERSION_TYPE_MASK 0x00000000f + +#define INFO_VERSION_TYPE_RELEASE 1 + +/* Field Memory */ +#define INFO_SIZE_SRAM2B_OFFSET 24 +#define INFO_SIZE_SRAM2B_MASK 0xff000000 +#define INFO_SIZE_SRAM2A_OFFSET 16 +#define INFO_SIZE_SRAM2A_MASK 0x00ff0000 +#define INFO_SIZE_SRAM1_OFFSET 8 +#define INFO_SIZE_SRAM1_MASK 0x0000ff00 +#define INFO_SIZE_FLASH_OFFSET 0 +#define INFO_SIZE_FLASH_MASK 0x000000ff + +/* Field stack information */ +#define INFO_STACK_TYPE_OFFSET 0 +#define INFO_STACK_TYPE_MASK 0x000000ff +#define INFO_STACK_TYPE_NONE 0 + +#define INFO_STACK_TYPE_BLE_STANDARD 0x01 +#define INFO_STACK_TYPE_BLE_HCI 0x02 +#define INFO_STACK_TYPE_BLE_LIGHT 0x03 +#define INFO_STACK_TYPE_THREAD_FTD 0x10 +#define INFO_STACK_TYPE_THREAD_MTD 0x11 +#define INFO_STACK_TYPE_ZIGBEE_FFD 0x30 +#define INFO_STACK_TYPE_ZIGBEE_RFD 0x31 +#define INFO_STACK_TYPE_MAC 0x40 +#define INFO_STACK_TYPE_BLE_THREAD_FTD_STATIC 0x50 +#define INFO_STACK_TYPE_BLE_THREAD_FTD_DYAMIC 0x51 +#define INFO_STACK_TYPE_802154_LLD_TESTS 0x60 +#define INFO_STACK_TYPE_802154_PHY_VALID 0x61 +#define INFO_STACK_TYPE_BLE_PHY_VALID 0x62 +#define INFO_STACK_TYPE_BLE_LLD_TESTS 0x63 +#define INFO_STACK_TYPE_BLE_RLV 0x64 +#define INFO_STACK_TYPE_802154_RLV 0x65 +#define INFO_STACK_TYPE_BLE_ZIGBEE_FFD_STATIC 0x70 +#define INFO_STACK_TYPE_BLE_ZIGBEE_FFD_DYNAMIC 0x78 +#define INFO_STACK_TYPE_RLV 0x80 + +typedef struct { +/** + * Wireless Info + */ + uint8_t VersionMajor; + uint8_t VersionMinor; + uint8_t VersionSub; + uint8_t VersionBranch; + uint8_t VersionReleaseType; + uint8_t MemorySizeSram2B; /*< Multiple of 1K */ + uint8_t MemorySizeSram2A; /*< Multiple of 1K */ + uint8_t MemorySizeSram1; /*< Multiple of 1K */ + uint8_t MemorySizeFlash; /*< Multiple of 4K */ + uint8_t StackType; +/** + * Fus Info + */ + uint8_t FusVersionMajor; + uint8_t FusVersionMinor; + uint8_t FusVersionSub; + uint8_t FusMemorySizeSram2B; /*< Multiple of 1K */ + uint8_t FusMemorySizeSram2A; /*< Multiple of 1K */ + uint8_t FusMemorySizeFlash; /*< Multiple of 4K */ +}WirelessFwInfo_t; + + +/* Exported functions ------------------------------------------------------- */ + +/** + * For all SHCI_C2_FUS_xxx() command: + * When the wireless FW is running on the CPU2, the command returns SHCI_FUS_CMD_NOT_SUPPORTED + * When any FUS command is sent after the SHCI_FUS_CMD_NOT_SUPPORTED has been received, + * the CPU2 switches on the RSS ( This reboots automatically the device ) + */ + /** + * SHCI_C2_FUS_GetState + * @brief Read the FUS State + * If the user is not interested by the Error code response, a null value may + * be passed as parameter + * + * @param p_rsp : return the error code when the FUS State Value = 0xFF + * @retval FUS State Values + */ + uint8_t SHCI_C2_FUS_GetState( SHCI_FUS_GetState_ErrorCode_t *p_rsp ); + + /** + * SHCI_C2_FUS_FwUpgrade + * @brief Request the FUS to install the CPU2 firmware update + * + * @param fw_src_add: Address of the firmware image location + * @param fw_dest_add: Address of the firmware destination + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_FUS_FwUpgrade( uint32_t fw_src_add, uint32_t fw_dest_add ); + + /** + * SHCI_C2_FUS_FwDelete + * @brief Delete the wireless stack on CPU2 + * + * @param None + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_FUS_FwDelete( void ); + + /** + * SHCI_C2_FUS_UpdateAuthKey + * @brief Request the FUS to update the authentication key + * + * @param pCmdPacket + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_FUS_UpdateAuthKey( SHCI_C2_FUS_UpdateAuthKey_Cmd_Param_t *pParam ); + + /** + * SHCI_C2_FUS_LockAuthKey + * @brief Request the FUS to prevent any future update of the authentication key + * + * @param None + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_FUS_LockAuthKey( void ); + + /** + * SHCI_C2_FUS_StoreUsrKey + * @brief Request the FUS to store the user key + * + * @param pParam : command parameter + * @param p_key_index : Index allocated by the FUS to the stored key + * + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_FUS_StoreUsrKey( SHCI_C2_FUS_StoreUsrKey_Cmd_Param_t *pParam, uint8_t *p_key_index ); + + /** + * SHCI_C2_FUS_LoadUsrKey + * @brief Request the FUS to load the user key into the AES + * + * @param key_index : index of the user key to load in AES1 + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_FUS_LoadUsrKey( uint8_t key_index ); + + /** + * SHCI_C2_FUS_StartWs + * @brief Request the FUS to reboot on the wireless stack + * + * @param None + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_FUS_StartWs( void ); + + /** + * SHCI_C2_FUS_LockUsrKey + * @brief Request the FUS to lock the user key so that it cannot be updated later on + * + * @param key_index : index of the user key to lock + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_FUS_LockUsrKey( uint8_t key_index ); + + /** + * SHCI_C2_BLE_Init + * @brief Provides parameters and starts the BLE Stack + * + * @param pCmdPacket : Parameters to be provided to the BLE Stack + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_BLE_Init( SHCI_C2_Ble_Init_Cmd_Packet_t *pCmdPacket ); + + /** + * SHCI_C2_THREAD_Init + * @brief Starts the THREAD Stack + * + * @param None + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_THREAD_Init( void ); + + /** + * SHCI_C2_LLDTESTS_Init + * @brief Starts the LLD tests CLI + * + * @param param_size : Nb of bytes + * @param p_param : pointeur with data to give from M4 to M0 + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_LLDTESTS_Init( uint8_t param_size, uint8_t * p_param ); + + /** + * SHCI_C2_LLD_BLE_Init + * @brief Starts the LLD tests CLI + * + * @param param_size : Nb of bytes + * @param p_param : pointeur with data to give from M4 to M0 + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_LLD_BLE_Init( uint8_t param_size, uint8_t * p_param ); + + /** + * SHCI_C2_ZIGBEE_Init + * @brief Starts the Zigbee Stack + * + * @param None + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_ZIGBEE_Init( void ); + + /** + * SHCI_C2_DEBUG_Init + * @brief Starts the Traces + * + * @param None + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_DEBUG_Init( SHCI_C2_DEBUG_Init_Cmd_Packet_t *pCmdPacket ); + + /** + * SHCI_C2_FLASH_EraseActivity + * @brief Provides the information of the start and the end of a flash erase window on the CPU1 + * + * @param erase_activity: Start/End of erase activity + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_FLASH_EraseActivity( SHCI_EraseActivity_t erase_activity ); + + /** + * SHCI_C2_CONCURRENT_SetMode + * @brief Enable/Disable Thread on CPU2 (M0+) + * + * @param Mode: BLE or Thread enable flag + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_CONCURRENT_SetMode( SHCI_C2_CONCURRENT_Mode_Param_t Mode ); + + /** + * SHCI_C2_FLASH_StoreData + * @brief Store Data in Flash + * + * @param Ip: BLE or THREAD + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_FLASH_StoreData( SHCI_C2_FLASH_Ip_t Ip ); + + /** + * SHCI_C2_FLASH_EraseData + * @brief Erase Data in Flash + * + * @param Ip: BLE or THREAD + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_FLASH_EraseData( SHCI_C2_FLASH_Ip_t Ip ); + + /** + * SHCI_C2_RADIO_AllowLowPower + * @brief Allow or forbid IP_radio (802_15_4 or BLE) to enter in low power mode. + * + * @param Ip: BLE or 802_15_5 + * @param FlagRadioLowPowerOn: True or false + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_RADIO_AllowLowPower( SHCI_C2_FLASH_Ip_t Ip,uint8_t FlagRadioLowPowerOn); + + + /** + * SHCI_C2_MAC_802_15_4_Init + * @brief Starts the MAC 802.15.4 on M0 + * + * @param None + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_MAC_802_15_4_Init( void ); + + /** + * SHCI_GetWirelessFwInfo + * @brief This function read back the informations relative to the wireless binary loaded. + * Refer yourself to SHCI_WirelessFwInfoTable_t structure to get the significance + * of the different parameters returned. + * @param pWirelessInfo : Pointer to WirelessFwInfo_t. + * + * @retval SHCI_Success + */ + SHCI_CmdStatus_t SHCI_GetWirelessFwInfo( WirelessFwInfo_t* pWirelessInfo ); + + /** + * SHCI_C2_Reinit + * @brief This is required to allow the CPU1 to fake a set C2BOOT when it has already been set. + * In order to fake a C2BOOT, the CPU1 shall : + * - Send SHCI_C2_Reinit() + * - call SEV instruction + * WARNING: + * This function is intended to be used by the SBSFU + * + * @param None + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_Reinit( void ); + + /** + * SHCI_C2_ExtpaConfig + * @brief Send the Ext PA configuration + * When the CPU2 receives the command, it controls the Ext PA as requested by the configuration + * This configures only which IO is used to enable/disable the ExtPA and the associated polarity + * This command has no effect on the other IO that is used to control the mode of the Ext PA (Rx/Tx) + * + * @param gpio_port: GPIOx where x can be (A..F) to select the GPIO peripheral for STM32WBxx family + * @param gpio_pin_number: This parameter can be one of GPIO_PIN_x (= LL_GPIO_PIN_x) where x can be (0..15). + * @param gpio_polarity: This parameter can be either + * - EXT_PA_ENABLED_LOW: ExtPA is enabled when GPIO is low + * - EXT_PA_ENABLED_HIGH: ExtPA is enabled when GPIO is high + * @param gpio_status: This parameter can be either + * - EXT_PA_DISABLED: Stop driving the ExtPA + * - EXT_PA_ENABLED: Drive the ExtPA according to radio activity + * (ON before the Event and OFF at the end of the event) + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_ExtpaConfig(uint32_t gpio_port, uint16_t gpio_pin_number, uint8_t gpio_polarity, uint8_t gpio_status); + + /** + * SHCI_C2_SetFlashActivityControl + * @brief Set the mechanism to be used on CPU2 to prevent the CPU1 to either write or erase in flash + * + * @param Source: It can be one of the following list + * - FLASH_ACTIVITY_CONTROL_PES : The CPU2 set the PES bit to prevent the CPU1 to either read or write in flash + * - FLASH_ACTIVITY_CONTROL_SEM7 : The CPU2 gets the semaphore 7 to prevent the CPU1 to either read or write in flash. + * This requires the CPU1 to first get semaphore 7 before erasing or writing the flash. + * + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_SetFlashActivityControl(SHCI_C2_SET_FLASH_ACTIVITY_CONTROL_Source_t Source); + + /** + * SHCI_C2_Config + * @brief Send the system configuration to the CPU2 + * + * @param pCmdPacket: address of the buffer holding following parameters + * uint8_t PayloadCmdSize : Size of the payload - shall be SHCI_C2_CONFIG_PAYLOAD_CMD_SIZE + * uint8_t Config1 : + * - bit0 : 0 - BLE NVM Data data are flushed in internal secure flash + * 1 - BLE NVM Data are written in SRAM cache pointed by BleNvmRamAddress + * - bit1 : 0 - THREAD NVM Data data are flushed in internal secure flash + * 1 - THREAD NVM Data are written in SRAM cache pointed by ThreadNvmRamAddress + * - bit2 to bit7 : Unused, shall be set to 0 + * uint8_t EvtMask1 : + * When a bit is set to 0, the event is not reported + * bit0 : Asynchronous Event with Sub Evt Code 0x9201 (= SHCI_SUB_EVT_ERROR_NOTIF) + * ... + * bit31 : Asynchronous Event with Sub Evt Code 0x9220 + * uint8_t Spare1 : Unused, shall be set to 0 + * uint32_t BleNvmRamAddress : + * Only considered when Config1.bit0 = 1 + * When set to 0, data are kept in internal SRAM on CPU2 + * Otherwise, data are copied in the cache pointed by BleNvmRamAddress + * The size of the buffer shall be BLE_NVM_SRAM_SIZE (number of 32bits) + * The buffer shall be allocated in SRAM2 + * uint32_t ThreadNvmRamAddress : + * Only considered when Config1.bit1 = 1 + * When set to 0, data are kept in internal SRAM on CPU2 + * Otherwise, data are copied in the cache pointed by ThreadNvmRamAddress + * The size of the buffer shall be THREAD_NVM_SRAM_SIZE (number of 32bits) + * The buffer shall be allocated in SRAM2 + * + * Please check macro definition to be used for this function + * They are defined in this file next to the definition of SHCI_OPCODE_C2_CONFIG + * + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_Config(SHCI_C2_CONFIG_Cmd_Param_t *pCmdPacket); + + #ifdef __cplusplus +} +#endif + +#endif /*__SHCI_H */ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/src/utility/STM32Cube_FW/shci_tl.c b/src/utility/STM32Cube_FW/shci_tl.c new file mode 100644 index 00000000..736f2793 --- /dev/null +++ b/src/utility/STM32Cube_FW/shci_tl.c @@ -0,0 +1,351 @@ +/** + ****************************************************************************** + * @file shci.c + * @author MCD Application Team + * @brief System HCI command implementation + ****************************************************************************** + * @attention + * + * <h2><center>© Copyright (c) 2019 STMicroelectronics. + * All rights reserved.</center></h2> + * + * This software component is licensed by ST under BSD 3-Clause license, + * the "License"; You may not use this file except in compliance with the + * License. You may obtain a copy of the License at: + * opensource.org/licenses/BSD-3-Clause + * + ****************************************************************************** + */ + + +/* Includes ------------------------------------------------------------------*/ +#include "stm32_wpan_common.h" + +#include "stm_list.h" +#include "shci_tl.h" + +/** + * These traces are not yet supported in an usual way in the delivery package + * They can enabled by adding the definition of TL_SHCI_CMD_DBG_EN and/or TL_SHCI_EVT_DBG_EN in the preprocessor option in the IDE + */ +#if ( (TL_SHCI_CMD_DBG_EN != 0) || (TL_SHCI_EVT_DBG_EN != 0) ) +#include "app_conf.h" +#include "dbg_trace.h" +#endif + +#if (TL_SHCI_CMD_DBG_EN != 0) +#define TL_SHCI_CMD_DBG_MSG PRINT_MESG_DBG +#define TL_SHCI_CMD_DBG_BUF PRINT_LOG_BUFF_DBG +#else +#define TL_SHCI_CMD_DBG_MSG(...) +#define TL_SHCI_CMD_DBG_BUF(...) +#endif + +#if (TL_SHCI_EVT_DBG_EN != 0) +#define TL_SHCI_EVT_DBG_MSG PRINT_MESG_DBG +#define TL_SHCI_EVT_DBG_BUF PRINT_LOG_BUFF_DBG +#else +#define TL_SHCI_EVT_DBG_MSG(...) +#define TL_SHCI_EVT_DBG_BUF(...) +#endif + +/* Private typedef -----------------------------------------------------------*/ +typedef enum +{ + SHCI_TL_CMD_RESP_RELEASE, + SHCI_TL_CMD_RESP_WAIT, +} SHCI_TL_CmdRespStatus_t; + +/* Private defines -----------------------------------------------------------*/ +/** + * The default System HCI layer timeout is set to 33s + */ +#define SHCI_TL_DEFAULT_TIMEOUT (33000) + +/* Private macros ------------------------------------------------------------*/ +/* Public variables ---------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +/** + * START of Section SYSTEM_DRIVER_CONTEXT + */ +PLACE_IN_SECTION("SYSTEM_DRIVER_CONTEXT") static tListNode SHciAsynchEventQueue; +PLACE_IN_SECTION("SYSTEM_DRIVER_CONTEXT") static volatile SHCI_TL_CmdStatus_t SHCICmdStatus; +PLACE_IN_SECTION("SYSTEM_DRIVER_CONTEXT") static TL_CmdPacket_t *pCmdBuffer; +PLACE_IN_SECTION("SYSTEM_DRIVER_CONTEXT") SHCI_TL_UserEventFlowStatus_t SHCI_TL_UserEventFlow; +/** + * END of Section SYSTEM_DRIVER_CONTEXT + */ + +static tSHciContext shciContext; +static void (* StatusNotCallBackFunction) (SHCI_TL_CmdStatus_t status); + +static volatile SHCI_TL_CmdRespStatus_t CmdRspStatusFlag; + +/* Private function prototypes -----------------------------------------------*/ +static void Cmd_SetStatus(SHCI_TL_CmdStatus_t shcicmdstatus); +static void TlCmdEvtReceived(TL_EvtPacket_t *shcievt); +static void TlUserEvtReceived(TL_EvtPacket_t *shcievt); +static void TlInit( TL_CmdPacket_t * p_cmdbuffer ); +static void OutputCmdTrace(TL_CmdPacket_t *pCmdBuffer); +static void OutputRspTrace(TL_EvtPacket_t *p_rsp); +static void OutputEvtTrace(TL_EvtPacket_t *phcievtbuffer); + +/* Interface ------- ---------------------------------------------------------*/ +void shci_init(void(* UserEvtRx)(void* pData), void* pConf) +{ + StatusNotCallBackFunction = ((SHCI_TL_HciInitConf_t *)pConf)->StatusNotCallBack; + shciContext.UserEvtRx = UserEvtRx; + + shci_register_io_bus (&shciContext.io); + + TlInit((TL_CmdPacket_t *)(((SHCI_TL_HciInitConf_t *)pConf)->p_cmdbuffer)); + + return; +} + +void shci_user_evt_proc(void) +{ + TL_EvtPacket_t *phcievtbuffer; + tSHCI_UserEvtRxParam UserEvtRxParam; + + /** + * Up to release version v1.2.0, a while loop was implemented to read out events from the queue as long as + * it is not empty. However, in a bare metal implementation, this leads to calling in a "blocking" mode + * shci_user_evt_proc() as long as events are received without giving the opportunity to run other tasks + * in the background. + * From now, the events are reported one by one. When it is checked there is still an event pending in the queue, + * a request to the user is made to call again shci_user_evt_proc(). + * This gives the opportunity to the application to run other background tasks between each event. + */ + + /** + * It is more secure to use LST_remove_head()/LST_insert_head() compare to LST_get_next_node()/LST_remove_node() + * in case the user overwrite the header where the next/prev pointers are located + */ + if((LST_is_empty(&SHciAsynchEventQueue) == FALSE) && (SHCI_TL_UserEventFlow != SHCI_TL_UserEventFlow_Disable)) + { + LST_remove_head ( &SHciAsynchEventQueue, (tListNode **)&phcievtbuffer ); + + OutputEvtTrace(phcievtbuffer); + + if (shciContext.UserEvtRx != NULL) + { + UserEvtRxParam.pckt = phcievtbuffer; + UserEvtRxParam.status = SHCI_TL_UserEventFlow_Enable; + shciContext.UserEvtRx((void *)&UserEvtRxParam); + SHCI_TL_UserEventFlow = UserEvtRxParam.status; + } + else + { + SHCI_TL_UserEventFlow = SHCI_TL_UserEventFlow_Enable; + } + + if(SHCI_TL_UserEventFlow != SHCI_TL_UserEventFlow_Disable) + { + TL_MM_EvtDone( phcievtbuffer ); + } + else + { + /** + * put back the event in the queue + */ + LST_insert_head ( &SHciAsynchEventQueue, (tListNode *)phcievtbuffer ); + } + } + + if((LST_is_empty(&SHciAsynchEventQueue) == FALSE) && (SHCI_TL_UserEventFlow != SHCI_TL_UserEventFlow_Disable)) + { + shci_notify_asynch_evt((void*) &SHciAsynchEventQueue); + } + + + return; +} + +void shci_resume_flow( void ) +{ + SHCI_TL_UserEventFlow = SHCI_TL_UserEventFlow_Enable; + + /** + * It is better to go through the background process as it is not sure from which context this API may + * be called + */ + shci_notify_asynch_evt((void*) &SHciAsynchEventQueue); + + return; +} + +void shci_send( uint16_t cmd_code, uint8_t len_cmd_payload, uint8_t * p_cmd_payload, TL_EvtPacket_t * p_rsp ) +{ + Cmd_SetStatus(SHCI_TL_CmdBusy); + + pCmdBuffer->cmdserial.cmd.cmdcode = cmd_code; + pCmdBuffer->cmdserial.cmd.plen = len_cmd_payload; + + memcpy(pCmdBuffer->cmdserial.cmd.payload, p_cmd_payload, len_cmd_payload ); + + OutputCmdTrace(pCmdBuffer); + + shciContext.io.Send(0,0); + + shci_cmd_resp_wait(SHCI_TL_DEFAULT_TIMEOUT); + + /** + * The command complete of a system command does not have the header + * It starts immediately with the evtserial field + */ + memcpy( &(p_rsp->evtserial), pCmdBuffer, ((TL_EvtSerial_t*)pCmdBuffer)->evt.plen + TL_EVT_HDR_SIZE ); + + OutputRspTrace(p_rsp); + + Cmd_SetStatus(SHCI_TL_CmdAvailable); + + return; +} + +/* Private functions ---------------------------------------------------------*/ +static void TlInit( TL_CmdPacket_t * p_cmdbuffer ) +{ + TL_SYS_InitConf_t Conf; + + pCmdBuffer = p_cmdbuffer; + + LST_init_head (&SHciAsynchEventQueue); + + Cmd_SetStatus(SHCI_TL_CmdAvailable); + + SHCI_TL_UserEventFlow = SHCI_TL_UserEventFlow_Enable; + + /* Initialize low level driver */ + if (shciContext.io.Init) + { + + Conf.p_cmdbuffer = (uint8_t *)p_cmdbuffer; + Conf.IoBusCallBackCmdEvt = TlCmdEvtReceived; + Conf.IoBusCallBackUserEvt = TlUserEvtReceived; + shciContext.io.Init(&Conf); + } + + return; +} + +static void Cmd_SetStatus(SHCI_TL_CmdStatus_t shcicmdstatus) +{ + if(shcicmdstatus == SHCI_TL_CmdBusy) + { + if(StatusNotCallBackFunction != 0) + { + StatusNotCallBackFunction( SHCI_TL_CmdBusy ); + } + SHCICmdStatus = SHCI_TL_CmdBusy; + } + else + { + SHCICmdStatus = SHCI_TL_CmdAvailable; + if(StatusNotCallBackFunction != 0) + { + StatusNotCallBackFunction( SHCI_TL_CmdAvailable ); + } + } + + return; +} + +static void TlCmdEvtReceived(TL_EvtPacket_t *shcievt) +{ + (void)(shcievt); + shci_cmd_resp_release(0); /**< Notify the application the Cmd response has been received */ + + return; +} + +static void TlUserEvtReceived(TL_EvtPacket_t *shcievt) +{ + LST_insert_tail(&SHciAsynchEventQueue, (tListNode *)shcievt); + shci_notify_asynch_evt((void*) &SHciAsynchEventQueue); /**< Notify the application a full HCI event has been received */ + + return; +} + +static void OutputCmdTrace(TL_CmdPacket_t *pCmdBuffer) +{ + TL_SHCI_CMD_DBG_MSG("sys cmd: 0x%04X", pCmdBuffer->cmdserial.cmd.cmdcode); + + if(pCmdBuffer->cmdserial.cmd.plen != 0) + { + TL_SHCI_CMD_DBG_MSG(" payload:"); + TL_SHCI_CMD_DBG_BUF(pCmdBuffer->cmdserial.cmd.payload, pCmdBuffer->cmdserial.cmd.plen, ""); + } + TL_SHCI_CMD_DBG_MSG("\r\n"); + + return; +} + +static void OutputRspTrace(TL_EvtPacket_t *p_rsp) +{ + switch(p_rsp->evtserial.evt.evtcode) + { + case TL_BLEEVT_CC_OPCODE: + TL_SHCI_CMD_DBG_MSG("sys rsp: 0x%02X", p_rsp->evtserial.evt.evtcode); + TL_SHCI_CMD_DBG_MSG(" cmd opcode: 0x%02X", ((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->cmdcode); + TL_SHCI_CMD_DBG_MSG(" status: 0x%02X", ((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); + if((p_rsp->evtserial.evt.plen-4) != 0) + { + TL_SHCI_CMD_DBG_MSG(" payload:"); + TL_SHCI_CMD_DBG_BUF(&((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[1], p_rsp->evtserial.evt.plen-4, ""); + } + break; + + default: + TL_SHCI_CMD_DBG_MSG("unknown sys rsp received: %02X", p_rsp->evtserial.evt.evtcode); + break; + } + + TL_SHCI_CMD_DBG_MSG("\r\n"); + + return; +} + +static void OutputEvtTrace(TL_EvtPacket_t *phcievtbuffer) +{ + if(phcievtbuffer->evtserial.evt.evtcode != TL_BLEEVT_VS_OPCODE) + { + TL_SHCI_EVT_DBG_MSG("unknown sys evt received: %02X", phcievtbuffer->evtserial.evt.evtcode); + } + else + { + TL_SHCI_EVT_DBG_MSG("sys evt: 0x%02X", phcievtbuffer->evtserial.evt.evtcode); + TL_SHCI_EVT_DBG_MSG(" subevtcode: 0x%04X", ((TL_AsynchEvt_t*)(phcievtbuffer->evtserial.evt.payload))->subevtcode); + if((phcievtbuffer->evtserial.evt.plen-2) != 0) + { + TL_SHCI_EVT_DBG_MSG(" payload:"); + TL_SHCI_EVT_DBG_BUF(((TL_AsynchEvt_t*)(phcievtbuffer->evtserial.evt.payload))->payload, phcievtbuffer->evtserial.evt.plen-2, ""); + } + } + + TL_SHCI_EVT_DBG_MSG("\r\n"); + + return; +} + +/* Weak implementation ----------------------------------------------------------------*/ +__WEAK void shci_cmd_resp_wait(uint32_t timeout) +{ + (void)timeout; + + CmdRspStatusFlag = SHCI_TL_CMD_RESP_WAIT; + while(CmdRspStatusFlag != SHCI_TL_CMD_RESP_RELEASE); + + return; +} + +__WEAK void shci_cmd_resp_release(uint32_t flag) +{ + (void)flag; + + CmdRspStatusFlag = SHCI_TL_CMD_RESP_RELEASE; + + return; +} + + diff --git a/src/utility/STM32Cube_FW/shci_tl.h b/src/utility/STM32Cube_FW/shci_tl.h new file mode 100644 index 00000000..3fbc492f --- /dev/null +++ b/src/utility/STM32Cube_FW/shci_tl.h @@ -0,0 +1,175 @@ +/** + ****************************************************************************** + * @file shci_tl.h + * @author MCD Application Team + * @brief System HCI command header for the system channel + ****************************************************************************** + * @attention + * + * <h2><center>© Copyright (c) 2019 STMicroelectronics. + * All rights reserved.</center></h2> + * + * This software component is licensed by ST under BSD 3-Clause license, + * the "License"; You may not use this file except in compliance with the + * License. You may obtain a copy of the License at: + * opensource.org/licenses/BSD-3-Clause + * + ****************************************************************************** + */ + + +#ifndef __SHCI_TL_H_ +#define __SHCI_TL_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "tl.h" + +/* Exported defines -----------------------------------------------------------*/ +typedef enum +{ + SHCI_TL_UserEventFlow_Disable, + SHCI_TL_UserEventFlow_Enable, +} SHCI_TL_UserEventFlowStatus_t; + +typedef enum +{ + SHCI_TL_CmdBusy, + SHCI_TL_CmdAvailable +} SHCI_TL_CmdStatus_t; + +/** + * @brief Structure used to manage the BUS IO operations. + * All the structure fields will point to functions defined at user level. + * @{ + */ +typedef struct +{ + int32_t (* Init) (void* pConf); /**< Pointer to SHCI TL function for the IO Bus initialization */ + int32_t (* DeInit) (void); /**< Pointer to SHCI TL function for the IO Bus de-initialization */ + int32_t (* Reset) (void); /**< Pointer to SHCI TL function for the IO Bus reset */ + int32_t (* Receive) (uint8_t*, uint16_t); /**< Pointer to SHCI TL function for the IO Bus data reception */ + int32_t (* Send) (uint8_t*, uint16_t); /**< Pointer to SHCI TL function for the IO Bus data transmission */ + int32_t (* DataAck) (uint8_t*, uint16_t* len); /**< Pointer to SHCI TL function for the IO Bus data ack reception */ + int32_t (* GetTick) (void); /**< Pointer to BSP function for getting the HAL time base timestamp */ +} tSHciIO; +/** + * @} + */ + +/** + * @brief Contain the SHCI context + * @{ + */ +typedef struct +{ + tSHciIO io; /**< Manage the BUS IO operations */ + void (* UserEvtRx) (void * pData); /**< User System events callback function pointer */ +} tSHciContext; + +typedef struct +{ + SHCI_TL_UserEventFlowStatus_t status; + TL_EvtPacket_t *pckt; +} tSHCI_UserEvtRxParam; + +typedef struct +{ + uint8_t *p_cmdbuffer; + void (* StatusNotCallBack) (SHCI_TL_CmdStatus_t status); +} SHCI_TL_HciInitConf_t; + +/** + * shci_send + * @brief Send an System HCI Command + * + * @param : cmd_code = Opcode of the command + * @param : len_cmd_payload = Length of the command payload + * @param : p_cmd_payload = Address of the command payload + * @param : p_rsp_status = Address of the full buffer holding the command complete event + * @retval : None + */ +void shci_send( uint16_t cmd_code, uint8_t len_cmd_payload, uint8_t * p_cmd_payload, TL_EvtPacket_t * p_rsp_status ); + +/** + * @brief Register IO bus services. + * @param fops The SHCI IO structure managing the IO BUS + * @retval None + */ +void shci_register_io_bus(tSHciIO* fops); + +/** + * @brief Interrupt service routine that must be called when the system channel + * reports a packet has been received + * + * @param pdata Packet or event pointer + * @retval None + */ +void shci_notify_asynch_evt(void* pdata); + +/** + * @brief This function resume the User Event Flow which has been stopped on return + * from UserEvtRx() when the User Event has not been processed. + * + * @param None + * @retval None + */ +void shci_resume_flow(void); + + +/** + * @brief This function is called when an System HCI Command is sent to the CPU2 and the response is waited. + * It is called from the same context the System HCI command has been sent. + * It shall not return until the command response notified by shci_cmd_resp_release() is received. + * A weak implementation is available in shci_tl.c based on polling mechanism + * The user may re-implement this function in the application to improve performance : + * - It may use UTIL_SEQ_WaitEvt() API when using the Sequencer + * - It may use a semaphore when using cmsis_os interface + * + * @param timeout: Waiting timeout + * @retval None + */ +void shci_cmd_resp_wait(uint32_t timeout); + +/** + * @brief This function is called when an System HCI command is received from the CPU2. + * A weak implementation is available in shci_tl.c based on polling mechanism + * The user may re-implement this function in the application to improve performance : + * - It may use UTIL_SEQ_SetEvt() API when using the Sequencer + * - It may use a semaphore when using cmsis_os interface + * + * + * @param flag: Release flag + * @retval None + */ +void shci_cmd_resp_release(uint32_t flag); + + +/** + * @brief This process shall be called each time the shci_notify_asynch_evt notification is received + * + * @param None + * @retval None + */ + +void shci_user_evt_proc(void); + +/** + * @brief Initialize the System Host Controller Interface. + * This function must be called before any communication on the System Channel + * + * @param pData: System events callback function pointer + * This callback is triggered when an user event is received on + * the System Channel from CPU2. + * @param pConf: Configuration structure pointer + * @retval None + */ +void shci_init(void(* UserEvtRx)(void* pData), void* pConf); + +#ifdef __cplusplus +} +#endif + +#endif /* __SHCI_TL_H_ */ diff --git a/src/utility/STM32Cube_FW/stm32_wpan_common.h b/src/utility/STM32Cube_FW/stm32_wpan_common.h new file mode 100644 index 00000000..cad9026d --- /dev/null +++ b/src/utility/STM32Cube_FW/stm32_wpan_common.h @@ -0,0 +1,170 @@ +/** + ****************************************************************************** + * @file stm32_wpan_common.h + * @author MCD Application Team + * @brief Common file to utilities + ****************************************************************************** + * @attention + * + * <h2><center>© Copyright (c) 2018 STMicroelectronics. + * All rights reserved.</center></h2> + * + * This software component is licensed by ST under Ultimate Liberty license + * SLA0044, the "License"; You may not use this file except in compliance with + * the License. You may obtain a copy of the License at: + * www.st.com/SLA0044 + * + ****************************************************************************** + */ + + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __STM32_WPAN_COMMON_H +#define __STM32_WPAN_COMMON_H + +#ifdef __cplusplus +extern "C" { +#endif + +#if defined ( __CC_ARM ) + #define __ASM __asm /*!< asm keyword for ARM Compiler */ + #define __INLINE __inline /*!< inline keyword for ARM Compiler */ + #define __STATIC_INLINE static __inline +#elif defined ( __ICCARM__ ) + #define __ASM __asm /*!< asm keyword for IAR Compiler */ + #define __INLINE inline /*!< inline keyword for IAR Compiler. Only available in High optimization mode! */ + #define __STATIC_INLINE static inline +#elif defined ( __GNUC__ ) + #define __ASM __asm /*!< asm keyword for GNU Compiler */ + #define __INLINE inline /*!< inline keyword for GNU Compiler */ + #define __STATIC_INLINE static inline +#endif + +#include <stdint.h> +#include <string.h> +#include <stdio.h> +#include <stdlib.h> +#include <stdarg.h> +#include "cmsis_compiler.h" + + /* -------------------------------- * + * Basic definitions * + * -------------------------------- */ + +#undef NULL +#define NULL 0U + +#undef FALSE +#define FALSE 0U + +#undef TRUE +#define TRUE (!0U) + + /* -------------------------------- * + * Critical Section definition * + * -------------------------------- */ +#undef BACKUP_PRIMASK +#define BACKUP_PRIMASK() uint32_t primask_bit= __get_PRIMASK() + +#undef DISABLE_IRQ +#define DISABLE_IRQ() __disable_irq() + +#undef RESTORE_PRIMASK +#define RESTORE_PRIMASK() __set_PRIMASK(primask_bit) + + /* -------------------------------- * + * Macro delimiters * + * -------------------------------- */ +#undef M_BEGIN +#define M_BEGIN do { + +#undef M_END +#define M_END } while(0) + + /* -------------------------------- * + * Some useful macro definitions * + * -------------------------------- */ +#undef MAX +#define MAX(a, b) (((a) > (b)) ? (a) : (b)) + +#undef MIN +#define MIN(a, b) (((a) < (b)) ? (a) : (b)) + +#undef MODINC +#define MODINC( a, m ) M_BEGIN (a)++; if ((a)>=(m)) (a)=0; M_END + +#undef MODDEC +#define MODDEC( a, m ) M_BEGIN if ((a)==0) (a)=(m); (a)--; M_END + +#undef MODADD +#define MODADD( a, b, m ) M_BEGIN (a)+=(b); if ((a)>=(m)) (a)-=(m); M_END + +#undef MODSUB +#define MODSUB( a, b, m ) MODADD( a, (m)-(b), m ) + +#undef ALIGN +#ifdef WIN32 +#define ALIGN(n) +#else +#define ALIGN(n) __attribute__((aligned(n))) +#endif + +#undef PAUSE +#define PAUSE( t ) M_BEGIN \ + volatile int _i; \ + for ( _i = t; _i > 0; _i -- ); \ + M_END +#undef DIVF +#define DIVF( x, y ) ((x)/(y)) + +#undef DIVC +#define DIVC( x, y ) (((x)+(y)-1)/(y)) + +#undef DIVR +#define DIVR( x, y ) (((x)+((y)/2))/(y)) + +#undef SHRR +#define SHRR( x, n ) ((((x)>>((n)-1))+1)>>1) + +#undef BITN +#define BITN( w, n ) (((w)[(n)/32] >> ((n)%32)) & 1) + +#undef BITNSET +#define BITNSET( w, n, b ) M_BEGIN (w)[(n)/32] |= ((U32)(b))<<((n)%32); M_END + +/* -------------------------------- * + * Section attribute * + * -------------------------------- */ +#undef PLACE_IN_SECTION +#define PLACE_IN_SECTION( __x__ ) __attribute__((section (__x__))) + +/* ----------------------------------- * + * Packed usage (compiler dependent) * + * ----------------------------------- */ +#undef PACKED__ +#undef PACKED_STRUCT + +#if defined ( __CC_ARM ) + #if defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050U) + #define PACKED__ __attribute__((packed)) + #define PACKED_STRUCT struct PACKED__ + #else + #define PACKED__(TYPE) __packed TYPE + #define PACKED_STRUCT PACKED__(struct) + #endif +#elif defined ( __GNUC__ ) + #define PACKED__ __attribute__((packed)) + #define PACKED_STRUCT struct PACKED__ +#elif defined (__ICCARM__) + #define PACKED_STRUCT __packed struct +#elif + #define PACKED_STRUCT __packed struct +#endif + +#ifdef __cplusplus +} +#endif + +#endif /*__STM32_WPAN_COMMON_H */ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/src/utility/STM32Cube_FW/stm_list.c b/src/utility/STM32Cube_FW/stm_list.c new file mode 100644 index 00000000..42e2d500 --- /dev/null +++ b/src/utility/STM32Cube_FW/stm_list.c @@ -0,0 +1,208 @@ +/** + ****************************************************************************** + * @file stm_list.c + * @author MCD Application Team + * @brief TCircular Linked List Implementation. + ****************************************************************************** + * @attention + * + * <h2><center>© Copyright (c) 2019 STMicroelectronics. + * All rights reserved.</center></h2> + * + * This software component is licensed by ST under BSD 3-Clause license, + * the "License"; You may not use this file except in compliance with the + * License. You may obtain a copy of the License at: + * opensource.org/licenses/BSD-3-Clause + * + ****************************************************************************** + */ + + +/****************************************************************************** + * Include Files + ******************************************************************************/ +#include "utilities_common.h" + +#include "stm_list.h" + +/****************************************************************************** + * Function Definitions + ******************************************************************************/ +void LST_init_head (tListNode * listHead) +{ + listHead->next = listHead; + listHead->prev = listHead; +} + +uint8_t LST_is_empty (tListNode * listHead) +{ + uint32_t primask_bit; + uint8_t return_value; + + primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ + __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ + if(listHead->next == listHead) + { + return_value = TRUE; + } + else + { + return_value = FALSE; + } + __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ + + return return_value; +} + +void LST_insert_head (tListNode * listHead, tListNode * node) +{ + uint32_t primask_bit; + + primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ + __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ + + node->next = listHead->next; + node->prev = listHead; + listHead->next = node; + (node->next)->prev = node; + + __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ +} + + +void LST_insert_tail (tListNode * listHead, tListNode * node) +{ + uint32_t primask_bit; + + primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ + __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ + + node->next = listHead; + node->prev = listHead->prev; + listHead->prev = node; + (node->prev)->next = node; + + __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ +} + + +void LST_remove_node (tListNode * node) +{ + uint32_t primask_bit; + + primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ + __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ + + (node->prev)->next = node->next; + (node->next)->prev = node->prev; + + __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ +} + + +void LST_remove_head (tListNode * listHead, tListNode ** node ) +{ + uint32_t primask_bit; + + primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ + __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ + + *node = listHead->next; + LST_remove_node (listHead->next); + + __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ +} + + +void LST_remove_tail (tListNode * listHead, tListNode ** node ) +{ + uint32_t primask_bit; + + primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ + __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ + + *node = listHead->prev; + LST_remove_node (listHead->prev); + + __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ +} + + +void LST_insert_node_after (tListNode * node, tListNode * ref_node) +{ + uint32_t primask_bit; + + primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ + __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ + + node->next = ref_node->next; + node->prev = ref_node; + ref_node->next = node; + (node->next)->prev = node; + + __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ +} + + +void LST_insert_node_before (tListNode * node, tListNode * ref_node) +{ + uint32_t primask_bit; + + primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ + __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ + + node->next = ref_node; + node->prev = ref_node->prev; + ref_node->prev = node; + (node->prev)->next = node; + + __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ +} + + +int LST_get_size (tListNode * listHead) +{ + int size = 0; + tListNode * temp; + uint32_t primask_bit; + + primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ + __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ + + temp = listHead->next; + while (temp != listHead) + { + size++; + temp = temp->next; + } + + __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ + + return (size); +} + +void LST_get_next_node (tListNode * ref_node, tListNode ** node) +{ + uint32_t primask_bit; + + primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ + __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ + + *node = ref_node->next; + + __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ +} + + +void LST_get_prev_node (tListNode * ref_node, tListNode ** node) +{ + uint32_t primask_bit; + + primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ + __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ + + *node = ref_node->prev; + + __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ +} + diff --git a/src/utility/STM32Cube_FW/stm_list.h b/src/utility/STM32Cube_FW/stm_list.h new file mode 100644 index 00000000..78e74463 --- /dev/null +++ b/src/utility/STM32Cube_FW/stm_list.h @@ -0,0 +1,55 @@ +/** + ****************************************************************************** + * @file stm_list.h + * @author MCD Application Team + * @brief Header file for linked list library. + ****************************************************************************** + * @attention + * + * <h2><center>© Copyright (c) 2019 STMicroelectronics. + * All rights reserved.</center></h2> + * + * This software component is licensed by ST under BSD 3-Clause license, + * the "License"; You may not use this file except in compliance with the + * License. You may obtain a copy of the License at: + * opensource.org/licenses/BSD-3-Clause + * + ****************************************************************************** + */ + + +#ifndef _STM_LIST_H_ +#define _STM_LIST_H_ + +/* Includes ------------------------------------------------------------------*/ + +typedef struct _tListNode { + struct _tListNode * next; + struct _tListNode * prev; +} tListNode; + +void LST_init_head (tListNode * listHead); + +uint8_t LST_is_empty (tListNode * listHead); + +void LST_insert_head (tListNode * listHead, tListNode * node); + +void LST_insert_tail (tListNode * listHead, tListNode * node); + +void LST_remove_node (tListNode * node); + +void LST_remove_head (tListNode * listHead, tListNode ** node ); + +void LST_remove_tail (tListNode * listHead, tListNode ** node ); + +void LST_insert_node_after (tListNode * node, tListNode * ref_node); + +void LST_insert_node_before (tListNode * node, tListNode * ref_node); + +int LST_get_size (tListNode * listHead); + +void LST_get_next_node (tListNode * ref_node, tListNode ** node); + +void LST_get_prev_node (tListNode * ref_node, tListNode ** node); + +#endif /* _STM_LIST_H_ */ diff --git a/src/utility/STM32Cube_FW/tl.h b/src/utility/STM32Cube_FW/tl.h new file mode 100644 index 00000000..e5fac413 --- /dev/null +++ b/src/utility/STM32Cube_FW/tl.h @@ -0,0 +1,334 @@ +/** + ****************************************************************************** + * @file tl.h + * @author MCD Application Team + * @brief Header for tl module + ****************************************************************************** + * @attention + * + * <h2><center>© Copyright (c) 2019 STMicroelectronics. + * All rights reserved.</center></h2> + * + * This software component is licensed by ST under BSD 3-Clause license, + * the "License"; You may not use this file except in compliance with the + * License. You may obtain a copy of the License at: + * opensource.org/licenses/BSD-3-Clause + * + ****************************************************************************** + */ + + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __TL_H +#define __TL_H + +#ifdef __cplusplus +extern "C" { +#endif + + +/* Includes ------------------------------------------------------------------*/ +#include "stm32_wpan_common.h" + +/* Exported defines -----------------------------------------------------------*/ +#define TL_BLECMD_PKT_TYPE ( 0x01 ) +#define TL_ACL_DATA_PKT_TYPE ( 0x02 ) +#define TL_BLEEVT_PKT_TYPE ( 0x04 ) +#define TL_OTCMD_PKT_TYPE ( 0x08 ) +#define TL_OTRSP_PKT_TYPE ( 0x09 ) +#define TL_CLICMD_PKT_TYPE ( 0x0A ) +#define TL_OTNOT_PKT_TYPE ( 0x0C ) +#define TL_OTACK_PKT_TYPE ( 0x0D ) +#define TL_CLINOT_PKT_TYPE ( 0x0E ) +#define TL_CLIACK_PKT_TYPE ( 0x0F ) +#define TL_SYSCMD_PKT_TYPE ( 0x10 ) +#define TL_SYSRSP_PKT_TYPE ( 0x11 ) +#define TL_SYSEVT_PKT_TYPE ( 0x12 ) +#define TL_CLIRESP_PKT_TYPE ( 0x15 ) +#define TL_M0CMD_PKT_TYPE ( 0x16 ) +#define TL_LOCCMD_PKT_TYPE ( 0x20 ) +#define TL_LOCRSP_PKT_TYPE ( 0x21 ) +#define TL_TRACES_APP_PKT_TYPE ( 0x40 ) +#define TL_TRACES_WL_PKT_TYPE ( 0x41 ) + +#define TL_CMD_HDR_SIZE (4) +#define TL_EVT_HDR_SIZE (3) +#define TL_EVT_CS_PAYLOAD_SIZE (4) + +#define TL_BLEEVT_CC_OPCODE (0x0E) +#define TL_BLEEVT_CS_OPCODE (0x0F) +#define TL_BLEEVT_VS_OPCODE (0xFF) + +#define TL_BLEEVT_CS_PACKET_SIZE (TL_EVT_HDR_SIZE + sizeof(TL_CsEvt_t)) +#define TL_BLEEVT_CS_BUFFER_SIZE (sizeof(TL_PacketHeader_t) + TL_BLEEVT_CS_PACKET_SIZE) + +/* Exported types ------------------------------------------------------------*/ +/**< Packet header */ +typedef PACKED_STRUCT +{ + uint32_t *next; + uint32_t *prev; +} TL_PacketHeader_t; + +/******************************************************************************* + * Event type + */ + +/** + * This the payload of TL_Evt_t for a command status event + */ +typedef PACKED_STRUCT +{ + uint8_t status; + uint8_t numcmd; + uint16_t cmdcode; +} TL_CsEvt_t; + +/** + * This the payload of TL_Evt_t for a command complete event + */ +typedef PACKED_STRUCT +{ + uint8_t numcmd; + uint16_t cmdcode; + uint8_t payload[1]; +} TL_CcEvt_t; + +/** + * This the payload of TL_Evt_t for an asynchronous event + */ +typedef PACKED_STRUCT +{ + uint16_t subevtcode; + uint8_t payload[1]; +} TL_AsynchEvt_t; + +typedef PACKED_STRUCT +{ + uint8_t evtcode; + uint8_t plen; + uint8_t payload[1]; +} TL_Evt_t; + +typedef PACKED_STRUCT +{ + uint8_t type; + TL_Evt_t evt; +} TL_EvtSerial_t; + +/** + * This format shall be used for all events (asynchronous and command response) reported + * by the CPU2 except for the command response of a system command where the header is not there + * and the format to be used shall be TL_EvtSerial_t. + * Note: Be careful that the asynchronous events reported by the CPU2 on the system channel do + * include the header and shall use TL_EvtPacket_t format. Only the command response format on the + * system channel is different. + */ +typedef PACKED_STRUCT +{ + TL_PacketHeader_t header; + TL_EvtSerial_t evtserial; +} TL_EvtPacket_t; + +/***************************************************************************************** + * Command type + */ + +typedef PACKED_STRUCT +{ + uint16_t cmdcode; + uint8_t plen; + uint8_t payload[255]; +} TL_Cmd_t; + +typedef PACKED_STRUCT +{ + uint8_t type; + TL_Cmd_t cmd; +} TL_CmdSerial_t; + +typedef PACKED_STRUCT +{ + TL_PacketHeader_t header; + TL_CmdSerial_t cmdserial; +} TL_CmdPacket_t; + +/***************************************************************************************** + * HCI ACL DATA type + */ +typedef PACKED_STRUCT +{ + uint8_t type; + uint16_t handle; + uint16_t length; + uint8_t acl_data[1]; +} TL_AclDataSerial_t; + +typedef PACKED_STRUCT +{ + TL_PacketHeader_t header; + TL_AclDataSerial_t AclDataSerial; +} TL_AclDataPacket_t; + +typedef struct +{ + uint8_t *p_BleSpareEvtBuffer; + uint8_t *p_SystemSpareEvtBuffer; + uint8_t *p_AsynchEvtPool; + uint32_t AsynchEvtPoolSize; + uint8_t *p_TracesEvtPool; + uint32_t TracesEvtPoolSize; +} TL_MM_Config_t; + +typedef struct +{ + uint8_t *p_ThreadOtCmdRspBuffer; + uint8_t *p_ThreadCliRspBuffer; + uint8_t *p_ThreadNotAckBuffer; +} TL_TH_Config_t; + +typedef struct +{ + uint8_t *p_LldTestsCliCmdRspBuffer; + uint8_t *p_LldTestsM0CmdBuffer; +} TL_LLD_tests_Config_t; + +typedef struct +{ + uint8_t *p_LldBleCmdRspBuffer; + uint8_t *p_LldBleM0CmdBuffer; +} TL_LLD_BLE_Config_t; + +typedef struct +{ + uint8_t *p_Mac_802_15_4_CmdRspBuffer; + uint8_t *p_Mac_802_15_4_NotAckBuffer; +} TL_MAC_802_15_4_Config_t; + +typedef struct +{ + uint8_t *p_ZigbeeOtCmdRspBuffer; + uint8_t *p_ZigbeeNotAckBuffer; + uint8_t *p_ZigbeeNotifRequestBuffer; +} TL_ZIGBEE_Config_t; + +/** + * @brief Contain the BLE HCI Init Configuration + * @{ + */ +typedef struct +{ + void (* IoBusEvtCallBack) ( TL_EvtPacket_t *phcievt ); + void (* IoBusAclDataTxAck) ( void ); + uint8_t *p_cmdbuffer; + uint8_t *p_AclDataBuffer; +} TL_BLE_InitConf_t; + +/** + * @brief Contain the SYSTEM HCI Init Configuration + * @{ + */ +typedef struct +{ + void (* IoBusCallBackCmdEvt) (TL_EvtPacket_t *phcievt); + void (* IoBusCallBackUserEvt) (TL_EvtPacket_t *phcievt); + uint8_t *p_cmdbuffer; +} TL_SYS_InitConf_t; + +/* Exported constants --------------------------------------------------------*/ +/* External variables --------------------------------------------------------*/ +/* Exported macros -----------------------------------------------------------*/ +/* Exported functions ------------------------------------------------------- */ + +/****************************************************************************** + * GENERAL + ******************************************************************************/ +void TL_Enable( void ); +void TL_Init( void ); + +/****************************************************************************** + * BLE + ******************************************************************************/ +int32_t TL_BLE_Init( void* pConf ); +int32_t TL_BLE_SendCmd( uint8_t* buffer, uint16_t size ); +int32_t TL_BLE_SendAclData( uint8_t* buffer, uint16_t size ); + +/****************************************************************************** + * SYSTEM + ******************************************************************************/ +int32_t TL_SYS_Init( void* pConf ); +int32_t TL_SYS_SendCmd( uint8_t* buffer, uint16_t size ); + +/****************************************************************************** + * THREAD + ******************************************************************************/ +void TL_THREAD_Init( TL_TH_Config_t *p_Config ); +void TL_OT_SendCmd( void ); +void TL_CLI_SendCmd( void ); +void TL_OT_CmdEvtReceived( TL_EvtPacket_t * Otbuffer ); +void TL_THREAD_NotReceived( TL_EvtPacket_t * Notbuffer ); +void TL_THREAD_SendAck ( void ); +void TL_THREAD_CliSendAck ( void ); +void TL_THREAD_CliNotReceived( TL_EvtPacket_t * Notbuffer ); + +/****************************************************************************** + * LLD TESTS + ******************************************************************************/ +void TL_LLDTESTS_Init( TL_LLD_tests_Config_t *p_Config ); +void TL_LLDTESTS_SendCliCmd( void ); +void TL_LLDTESTS_ReceiveCliRsp( TL_CmdPacket_t * Notbuffer ); +void TL_LLDTESTS_SendCliRspAck( void ); +void TL_LLDTESTS_ReceiveM0Cmd( TL_CmdPacket_t * Notbuffer ); +void TL_LLDTESTS_SendM0CmdAck( void ); + +/****************************************************************************** + * LLD BLE + ******************************************************************************/ +void TL_LLD_BLE_Init( TL_LLD_BLE_Config_t *p_Config ); +void TL_LLD_BLE_SendCliCmd( void ); +void TL_LLD_BLE_ReceiveCliRsp( TL_CmdPacket_t * Notbuffer ); +void TL_LLD_BLE_SendCliRspAck( void ); +void TL_LLD_BLE_ReceiveM0Cmd( TL_CmdPacket_t * Notbuffer ); +void TL_LLD_BLE_SendM0CmdAck( void ); +void TL_LLD_BLE_SendCmd( void ); +void TL_LLD_BLE_ReceiveRsp( TL_CmdPacket_t * Notbuffer ); +void TL_LLD_BLE_SendRspAck( void ); +/****************************************************************************** + * MEMORY MANAGER + ******************************************************************************/ +void TL_MM_Init( TL_MM_Config_t *p_Config ); +void TL_MM_EvtDone( TL_EvtPacket_t * hcievt ); + +/****************************************************************************** + * TRACES + ******************************************************************************/ +void TL_TRACES_Init( void ); +void TL_TRACES_EvtReceived( TL_EvtPacket_t * hcievt ); + +/****************************************************************************** + * MAC 802.15.4 + ******************************************************************************/ +void TL_MAC_802_15_4_Init( TL_MAC_802_15_4_Config_t *p_Config ); +void TL_MAC_802_15_4_SendCmd( void ); +void TL_MAC_802_15_4_CmdEvtReceived( TL_EvtPacket_t * Otbuffer ); +void TL_MAC_802_15_4_NotReceived( TL_EvtPacket_t * Notbuffer ); +void TL_MAC_802_15_4_SendAck ( void ); + +/****************************************************************************** + * ZIGBEE + ******************************************************************************/ +void TL_ZIGBEE_Init( TL_ZIGBEE_Config_t *p_Config ); +void TL_ZIGBEE_SendM4RequestToM0( void ); +void TL_ZIGBEE_SendM4AckToM0Notify ( void ); +void TL_ZIGBEE_NotReceived( TL_EvtPacket_t * Notbuffer ); +void TL_ZIGBEE_CmdEvtReceived( TL_EvtPacket_t * Otbuffer ); +void TL_ZIGBEE_M0RequestReceived(TL_EvtPacket_t * Otbuffer ); +void TL_ZIGBEE_SendM4AckToM0Request(void); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*__TL_H */ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/src/utility/STM32Cube_FW/tl_mbox.c b/src/utility/STM32Cube_FW/tl_mbox.c new file mode 100644 index 00000000..507edba2 --- /dev/null +++ b/src/utility/STM32Cube_FW/tl_mbox.c @@ -0,0 +1,686 @@ +/** + ****************************************************************************** + * @file tl_mbox.c + * @author MCD Application Team + * @brief Transport layer for the mailbox interface + ****************************************************************************** + * @attention + * + * <h2><center>© Copyright (c) 2019 STMicroelectronics. + * All rights reserved.</center></h2> + * + * This software component is licensed by ST under BSD 3-Clause license, + * the "License"; You may not use this file except in compliance with the + * License. You may obtain a copy of the License at: + * opensource.org/licenses/BSD-3-Clause + * + ****************************************************************************** + */ + + +/* Includes ------------------------------------------------------------------*/ +#include "stm32_wpan_common.h" +#include "hw.h" + +#include "stm_list.h" +#include "tl.h" +#include "mbox_def.h" + +/** + * These traces are not yet supported in an usual way in the delivery package + * They can enabled by adding the definition of TL_MM_DBG_EN in the preprocessor option in the IDE + */ +#if(TL_MM_DBG_EN != 0) +#include "app_conf.h" +#include "dbg_trace.h" +#endif + +#if (TL_MM_DBG_EN != 0) +#define TL_MM_DBG__MSG PRINT_MESG_DBG +#else +#define TL_MM_DBG__MSG(...) +#endif + +/* Private typedef -----------------------------------------------------------*/ +/* Private defines -----------------------------------------------------------*/ +/* Private macros ------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ + +/**< reference table */ +PLACE_IN_SECTION("MAPPING_TABLE") static volatile MB_RefTable_t TL_RefTable; +PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_DeviceInfoTable_t TL_DeviceInfoTable; +PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_BleTable_t TL_BleTable; +PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_ThreadTable_t TL_ThreadTable; +PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_LldTestsTable_t TL_LldTestsTable; +PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_LldBleTable_t TL_LldBleTable; +PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_SysTable_t TL_SysTable; +PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_MemManagerTable_t TL_MemManagerTable; +PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_TracesTable_t TL_TracesTable; +PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_Mac_802_15_4_t TL_Mac_802_15_4_Table; +PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_ZigbeeTable_t TL_Zigbee_Table; + +/**< tables */ +PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode FreeBufQueue; +PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode TracesEvtQueue; +PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static uint8_t CsBuffer[sizeof(TL_PacketHeader_t) + TL_EVT_HDR_SIZE + sizeof(TL_CsEvt_t)]; +PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode EvtQueue; +PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode SystemEvtQueue; + + +static tListNode LocalFreeBufQueue; +static void (* BLE_IoBusEvtCallBackFunction) (TL_EvtPacket_t *phcievt); +static void (* BLE_IoBusAclDataTxAck) ( void ); +static void (* SYS_CMD_IoBusCallBackFunction) (TL_EvtPacket_t *phcievt); +static void (* SYS_EVT_IoBusCallBackFunction) (TL_EvtPacket_t *phcievt); + + +/* Global variables ----------------------------------------------------------*/ +/* Private function prototypes -----------------------------------------------*/ +static void SendFreeBuf( void ); +static void OutputMemReleaseTrace(TL_EvtPacket_t * phcievt); + +/* Public Functions Definition ------------------------------------------------------*/ + +/****************************************************************************** + * GENERAL + ******************************************************************************/ +void TL_Enable( void ) +{ + HW_IPCC_Enable(); + + return; +} + + +void TL_Init( void ) +{ + TL_RefTable.p_device_info_table = &TL_DeviceInfoTable; + TL_RefTable.p_ble_table = &TL_BleTable; + TL_RefTable.p_thread_table = &TL_ThreadTable; + TL_RefTable.p_lld_tests_table = &TL_LldTestsTable; + TL_RefTable.p_lld_ble_table = &TL_LldBleTable; + TL_RefTable.p_sys_table = &TL_SysTable; + TL_RefTable.p_mem_manager_table = &TL_MemManagerTable; + TL_RefTable.p_traces_table = &TL_TracesTable; + TL_RefTable.p_mac_802_15_4_table = &TL_Mac_802_15_4_Table; + TL_RefTable.p_zigbee_table = &TL_Zigbee_Table; + HW_IPCC_Init(); + + return; +} + +/****************************************************************************** + * BLE + ******************************************************************************/ +int32_t TL_BLE_Init( void* pConf ) +{ + MB_BleTable_t * p_bletable; + + TL_BLE_InitConf_t *pInitHciConf = (TL_BLE_InitConf_t *) pConf; + + LST_init_head (&EvtQueue); + + p_bletable = TL_RefTable.p_ble_table; + + p_bletable->pcmd_buffer = pInitHciConf->p_cmdbuffer; + p_bletable->phci_acl_data_buffer = pInitHciConf->p_AclDataBuffer; + p_bletable->pcs_buffer = (uint8_t*)CsBuffer; + p_bletable->pevt_queue = (uint8_t*)&EvtQueue; + + HW_IPCC_BLE_Init(); + + BLE_IoBusEvtCallBackFunction = pInitHciConf->IoBusEvtCallBack; + BLE_IoBusAclDataTxAck = pInitHciConf->IoBusAclDataTxAck; + + return 0; +} + +int32_t TL_BLE_SendCmd( uint8_t* buffer, uint16_t size ) +{ + (void)(buffer); + (void)(size); + + ((TL_CmdPacket_t*)(TL_RefTable.p_ble_table->pcmd_buffer))->cmdserial.type = TL_BLECMD_PKT_TYPE; + + HW_IPCC_BLE_SendCmd(); + + return 0; +} + +void HW_IPCC_BLE_RxEvtNot(void) +{ + TL_EvtPacket_t *phcievt; + + while(LST_is_empty(&EvtQueue) == FALSE) + { + LST_remove_head (&EvtQueue, (tListNode **)&phcievt); + + BLE_IoBusEvtCallBackFunction(phcievt); + } + + return; +} + +int32_t TL_BLE_SendAclData( uint8_t* buffer, uint16_t size ) +{ + (void)(buffer); + (void)(size); + + ((TL_AclDataPacket_t *)(TL_RefTable.p_ble_table->phci_acl_data_buffer))->AclDataSerial.type = TL_ACL_DATA_PKT_TYPE; + + HW_IPCC_BLE_SendAclData(); + + return 0; +} + +void HW_IPCC_BLE_AclDataAckNot(void) +{ + BLE_IoBusAclDataTxAck( ); + + return; +} + +/****************************************************************************** + * SYSTEM + ******************************************************************************/ +int32_t TL_SYS_Init( void* pConf ) +{ + MB_SysTable_t * p_systable; + + TL_SYS_InitConf_t *pInitHciConf = (TL_SYS_InitConf_t *) pConf; + + LST_init_head (&SystemEvtQueue); + p_systable = TL_RefTable.p_sys_table; + p_systable->pcmd_buffer = pInitHciConf->p_cmdbuffer; + p_systable->sys_queue = (uint8_t*)&SystemEvtQueue; + + HW_IPCC_SYS_Init(); + + SYS_CMD_IoBusCallBackFunction = pInitHciConf->IoBusCallBackCmdEvt; + SYS_EVT_IoBusCallBackFunction = pInitHciConf->IoBusCallBackUserEvt; + + return 0; +} + +int32_t TL_SYS_SendCmd( uint8_t* buffer, uint16_t size ) +{ + (void)(buffer); + (void)(size); + + ((TL_CmdPacket_t *)(TL_RefTable.p_sys_table->pcmd_buffer))->cmdserial.type = TL_SYSCMD_PKT_TYPE; + + HW_IPCC_SYS_SendCmd(); + + return 0; +} + +void HW_IPCC_SYS_CmdEvtNot(void) +{ + SYS_CMD_IoBusCallBackFunction( (TL_EvtPacket_t*)(TL_RefTable.p_sys_table->pcmd_buffer) ); + + return; +} + +void HW_IPCC_SYS_EvtNot( void ) +{ + TL_EvtPacket_t *p_evt; + + while(LST_is_empty(&SystemEvtQueue) == FALSE) + { + LST_remove_head (&SystemEvtQueue, (tListNode **)&p_evt); + SYS_EVT_IoBusCallBackFunction( p_evt ); + } + + return; +} + +/****************************************************************************** + * THREAD + ******************************************************************************/ +#ifdef THREAD_WB +void TL_THREAD_Init( TL_TH_Config_t *p_Config ) +{ + MB_ThreadTable_t * p_thread_table; + + p_thread_table = TL_RefTable.p_thread_table; + + p_thread_table->clicmdrsp_buffer = p_Config->p_ThreadCliRspBuffer; + p_thread_table->otcmdrsp_buffer = p_Config->p_ThreadOtCmdRspBuffer; + p_thread_table->notack_buffer = p_Config->p_ThreadNotAckBuffer; + + HW_IPCC_THREAD_Init(); + + return; +} + +void TL_OT_SendCmd( void ) +{ + ((TL_CmdPacket_t *)(TL_RefTable.p_thread_table->otcmdrsp_buffer))->cmdserial.type = TL_OTCMD_PKT_TYPE; + + HW_IPCC_OT_SendCmd(); + + return; +} + +void TL_CLI_SendCmd( void ) +{ + ((TL_CmdPacket_t *)(TL_RefTable.p_thread_table->clicmdrsp_buffer))->cmdserial.type = TL_CLICMD_PKT_TYPE; + + HW_IPCC_CLI_SendCmd(); + + return; +} + +void TL_THREAD_SendAck ( void ) +{ + ((TL_CmdPacket_t *)(TL_RefTable.p_thread_table->notack_buffer))->cmdserial.type = TL_OTACK_PKT_TYPE; + + HW_IPCC_THREAD_SendAck(); + + return; +} + +void TL_THREAD_CliSendAck ( void ) +{ + ((TL_CmdPacket_t *)(TL_RefTable.p_thread_table->notack_buffer))->cmdserial.type = TL_OTACK_PKT_TYPE; + + HW_IPCC_THREAD_CliSendAck(); + + return; +} + +void HW_IPCC_OT_CmdEvtNot(void) +{ + TL_OT_CmdEvtReceived( (TL_EvtPacket_t*)(TL_RefTable.p_thread_table->otcmdrsp_buffer) ); + + return; +} + +void HW_IPCC_THREAD_EvtNot( void ) +{ + TL_THREAD_NotReceived( (TL_EvtPacket_t*)(TL_RefTable.p_thread_table->notack_buffer) ); + + return; +} + +void HW_IPCC_THREAD_CliEvtNot( void ) +{ + TL_THREAD_CliNotReceived( (TL_EvtPacket_t*)(TL_RefTable.p_thread_table->clicmdrsp_buffer) ); + + return; +} + +__WEAK void TL_OT_CmdEvtReceived( TL_EvtPacket_t * Otbuffer ){}; +__WEAK void TL_THREAD_NotReceived( TL_EvtPacket_t * Notbuffer ){}; +__WEAK void TL_THREAD_CliNotReceived( TL_EvtPacket_t * Notbuffer ){}; + +#endif /* THREAD_WB */ + +/****************************************************************************** + * LLD TESTS + ******************************************************************************/ +#ifdef LLD_TESTS_WB +void TL_LLDTESTS_Init( TL_LLD_tests_Config_t *p_Config ) +{ + MB_LldTestsTable_t * p_lld_tests_table; + + p_lld_tests_table = TL_RefTable.p_lld_tests_table; + p_lld_tests_table->clicmdrsp_buffer = p_Config->p_LldTestsCliCmdRspBuffer; + p_lld_tests_table->m0cmd_buffer = p_Config->p_LldTestsM0CmdBuffer; + HW_IPCC_LLDTESTS_Init(); + return; +} + +void TL_LLDTESTS_SendCliCmd( void ) +{ + ((TL_CmdPacket_t *)(TL_RefTable.p_lld_tests_table->clicmdrsp_buffer))->cmdserial.type = TL_CLICMD_PKT_TYPE; + HW_IPCC_LLDTESTS_SendCliCmd(); + return; +} + +void HW_IPCC_LLDTESTS_ReceiveCliRsp( void ) +{ + TL_LLDTESTS_ReceiveCliRsp( (TL_CmdPacket_t*)(TL_RefTable.p_lld_tests_table->clicmdrsp_buffer) ); + return; +} + +void TL_LLDTESTS_SendCliRspAck( void ) +{ + HW_IPCC_LLDTESTS_SendCliRspAck(); + return; +} + +void HW_IPCC_LLDTESTS_ReceiveM0Cmd( void ) +{ + TL_LLDTESTS_ReceiveM0Cmd( (TL_CmdPacket_t*)(TL_RefTable.p_lld_tests_table->m0cmd_buffer) ); + return; +} + + +void TL_LLDTESTS_SendM0CmdAck( void ) +{ + HW_IPCC_LLDTESTS_SendM0CmdAck(); + return; +} + +__WEAK void TL_LLDTESTS_ReceiveCliRsp( TL_CmdPacket_t * Notbuffer ){}; +__WEAK void TL_LLDTESTS_ReceiveM0Cmd( TL_CmdPacket_t * Notbuffer ){}; +#endif /* LLD_TESTS_WB */ + +/****************************************************************************** + * LLD BLE + ******************************************************************************/ +#ifdef LLD_BLE_WB +void TL_LLD_BLE_Init( TL_LLD_BLE_Config_t *p_Config ) +{ + MB_LldBleTable_t * p_lld_ble_table; + + p_lld_ble_table = TL_RefTable.p_lld_ble_table; + p_lld_ble_table->cmdrsp_buffer = p_Config->p_LldBleCmdRspBuffer; + p_lld_ble_table->m0cmd_buffer = p_Config->p_LldBleM0CmdBuffer; + HW_IPCC_LLD_BLE_Init(); + return; +} + +void TL_LLD_BLE_SendCliCmd( void ) +{ + ((TL_CmdPacket_t *)(TL_RefTable.p_lld_ble_table->cmdrsp_buffer))->cmdserial.type = TL_CLICMD_PKT_TYPE; + HW_IPCC_LLD_BLE_SendCliCmd(); + return; +} + +void HW_IPCC_LLD_BLE_ReceiveCliRsp( void ) +{ + TL_LLD_BLE_ReceiveCliRsp( (TL_CmdPacket_t*)(TL_RefTable.p_lld_ble_table->cmdrsp_buffer) ); + return; +} + +void TL_LLD_BLE_SendCliRspAck( void ) +{ + HW_IPCC_LLD_BLE_SendCliRspAck(); + return; +} + +void HW_IPCC_LLD_BLE_ReceiveM0Cmd( void ) +{ + TL_LLD_BLE_ReceiveM0Cmd( (TL_CmdPacket_t*)(TL_RefTable.p_lld_ble_table->m0cmd_buffer) ); + return; +} + + +void TL_LLD_BLE_SendM0CmdAck( void ) +{ + HW_IPCC_LLD_BLE_SendM0CmdAck(); + return; +} + +__WEAK void TL_LLD_BLE_ReceiveCliRsp( TL_CmdPacket_t * Notbuffer ){}; +__WEAK void TL_LLD_BLE_ReceiveM0Cmd( TL_CmdPacket_t * Notbuffer ){}; + +/* Transparent Mode */ +void TL_LLD_BLE_SendCmd( void ) +{ + ((TL_CmdPacket_t *)(TL_RefTable.p_lld_ble_table->cmdrsp_buffer))->cmdserial.type = TL_CLICMD_PKT_TYPE; + HW_IPCC_LLD_BLE_SendCmd(); + return; +} + +void HW_IPCC_LLD_BLE_ReceiveRsp( void ) +{ + TL_LLD_BLE_ReceiveRsp( (TL_CmdPacket_t*)(TL_RefTable.p_lld_ble_table->cmdrsp_buffer) ); + return; +} + +void TL_LLD_BLE_SendRspAck( void ) +{ + HW_IPCC_LLD_BLE_SendRspAck(); + return; +} +#endif /* LLD_BLE_WB */ + +#ifdef MAC_802_15_4_WB +/****************************************************************************** + * MAC 802.15.4 + ******************************************************************************/ +void TL_MAC_802_15_4_Init( TL_MAC_802_15_4_Config_t *p_Config ) +{ + MB_Mac_802_15_4_t * p_mac_802_15_4_table; + + p_mac_802_15_4_table = TL_RefTable.p_mac_802_15_4_table; + + p_mac_802_15_4_table->p_cmdrsp_buffer = p_Config->p_Mac_802_15_4_CmdRspBuffer; + p_mac_802_15_4_table->p_notack_buffer = p_Config->p_Mac_802_15_4_NotAckBuffer; + + HW_IPCC_MAC_802_15_4_Init(); + + return; +} + +void TL_MAC_802_15_4_SendCmd( void ) +{ + ((TL_CmdPacket_t *)(TL_RefTable.p_mac_802_15_4_table->p_cmdrsp_buffer))->cmdserial.type = TL_OTCMD_PKT_TYPE; + + HW_IPCC_MAC_802_15_4_SendCmd(); + + return; +} + +void TL_MAC_802_15_4_SendAck ( void ) +{ + ((TL_CmdPacket_t *)(TL_RefTable.p_mac_802_15_4_table->p_notack_buffer))->cmdserial.type = TL_OTACK_PKT_TYPE; + + HW_IPCC_MAC_802_15_4_SendAck(); + + return; +} + +void HW_IPCC_MAC_802_15_4_CmdEvtNot(void) +{ + TL_MAC_802_15_4_CmdEvtReceived( (TL_EvtPacket_t*)(TL_RefTable.p_mac_802_15_4_table->p_cmdrsp_buffer) ); + + return; +} + +void HW_IPCC_MAC_802_15_4_EvtNot( void ) +{ + TL_MAC_802_15_4_NotReceived( (TL_EvtPacket_t*)(TL_RefTable.p_mac_802_15_4_table->p_notack_buffer) ); + + return; +} + +__WEAK void TL_MAC_802_15_4_CmdEvtReceived( TL_EvtPacket_t * Otbuffer ){}; +__WEAK void TL_MAC_802_15_4_NotReceived( TL_EvtPacket_t * Notbuffer ){}; +#endif + +#ifdef ZIGBEE_WB +/****************************************************************************** + * ZIGBEE + ******************************************************************************/ +void TL_ZIGBEE_Init( TL_ZIGBEE_Config_t *p_Config ) +{ + MB_ZigbeeTable_t * p_zigbee_table; + + p_zigbee_table = TL_RefTable.p_zigbee_table; + p_zigbee_table->appliCmdM4toM0_buffer = p_Config->p_ZigbeeOtCmdRspBuffer; + p_zigbee_table->notifM0toM4_buffer = p_Config->p_ZigbeeNotAckBuffer; + p_zigbee_table->requestM0toM4_buffer = p_Config->p_ZigbeeNotifRequestBuffer; + + HW_IPCC_ZIGBEE_Init(); + + return; +} + +/* Zigbee M4 to M0 Request */ +void TL_ZIGBEE_SendM4RequestToM0( void ) +{ + ((TL_CmdPacket_t *)(TL_RefTable.p_zigbee_table->appliCmdM4toM0_buffer))->cmdserial.type = TL_OTCMD_PKT_TYPE; + + HW_IPCC_ZIGBEE_SendM4RequestToM0(); + + return; +} + +/* Used to receive an ACK from the M0 */ +void HW_IPCC_ZIGBEE_RecvAppliAckFromM0(void) +{ + TL_ZIGBEE_CmdEvtReceived( (TL_EvtPacket_t*)(TL_RefTable.p_zigbee_table->appliCmdM4toM0_buffer) ); + + return; +} + +/* Zigbee notification from M0 to M4 */ +void HW_IPCC_ZIGBEE_RecvM0NotifyToM4( void ) +{ + TL_ZIGBEE_NotReceived( (TL_EvtPacket_t*)(TL_RefTable.p_zigbee_table->notifM0toM4_buffer) ); + + return; +} + +/* Send an ACK to the M0 for a Notification */ +void TL_ZIGBEE_SendM4AckToM0Notify ( void ) +{ + ((TL_CmdPacket_t *)(TL_RefTable.p_zigbee_table->notifM0toM4_buffer))->cmdserial.type = TL_OTACK_PKT_TYPE; + + HW_IPCC_ZIGBEE_SendM4AckToM0Notify(); + + return; +} + +/* Zigbee M0 to M4 Request */ +void HW_IPCC_ZIGBEE_RecvM0RequestToM4( void ) +{ + TL_ZIGBEE_M0RequestReceived( (TL_EvtPacket_t*)(TL_RefTable.p_zigbee_table->requestM0toM4_buffer) ); + + return; +} + +/* Send an ACK to the M0 for a Request */ +void TL_ZIGBEE_SendM4AckToM0Request(void) +{ + ((TL_CmdPacket_t *)(TL_RefTable.p_zigbee_table->requestM0toM4_buffer))->cmdserial.type = TL_OTACK_PKT_TYPE; + + HW_IPCC_ZIGBEE_SendM4AckToM0Request(); + + return; +} + + +__WEAK void TL_ZIGBEE_CmdEvtReceived( TL_EvtPacket_t * Otbuffer ){}; +__WEAK void TL_ZIGBEE_NotReceived( TL_EvtPacket_t * Notbuffer ){}; +#endif + + + +/****************************************************************************** + * MEMORY MANAGER + ******************************************************************************/ +void TL_MM_Init( TL_MM_Config_t *p_Config ) +{ + static MB_MemManagerTable_t * p_mem_manager_table; + + LST_init_head (&FreeBufQueue); + LST_init_head (&LocalFreeBufQueue); + + p_mem_manager_table = TL_RefTable.p_mem_manager_table; + + p_mem_manager_table->blepool = p_Config->p_AsynchEvtPool; + p_mem_manager_table->blepoolsize = p_Config->AsynchEvtPoolSize; + p_mem_manager_table->pevt_free_buffer_queue = (uint8_t*)&FreeBufQueue; + p_mem_manager_table->spare_ble_buffer = p_Config->p_BleSpareEvtBuffer; + p_mem_manager_table->spare_sys_buffer = p_Config->p_SystemSpareEvtBuffer; + p_mem_manager_table->traces_evt_pool = p_Config->p_TracesEvtPool; + p_mem_manager_table->tracespoolsize = p_Config->TracesEvtPoolSize; + + return; +} + +void TL_MM_EvtDone(TL_EvtPacket_t * phcievt) +{ + LST_insert_tail(&LocalFreeBufQueue, (tListNode *)phcievt); + + OutputMemReleaseTrace(phcievt); + + HW_IPCC_MM_SendFreeBuf( SendFreeBuf ); + + return; +} + +static void SendFreeBuf( void ) +{ + tListNode *p_node; + + while ( FALSE == LST_is_empty (&LocalFreeBufQueue) ) + { + LST_remove_head( &LocalFreeBufQueue, (tListNode **)&p_node ); + LST_insert_tail( (tListNode*)(TL_RefTable.p_mem_manager_table->pevt_free_buffer_queue), p_node ); + } + + return; +} + +static void OutputMemReleaseTrace(TL_EvtPacket_t * phcievt) +{ + switch(phcievt->evtserial.evt.evtcode) + { + case TL_BLEEVT_CS_OPCODE: + TL_MM_DBG__MSG("mm evt released: 0x%02X", phcievt->evtserial.evt.evtcode); + TL_MM_DBG__MSG(" cmd opcode: 0x%04X", ((TL_CsEvt_t*)(phcievt->evtserial.evt.payload))->cmdcode); + TL_MM_DBG__MSG(" buffer addr: 0x%08X", phcievt); + break; + + case TL_BLEEVT_CC_OPCODE: + TL_MM_DBG__MSG("mm evt released: 0x%02X", phcievt->evtserial.evt.evtcode); + TL_MM_DBG__MSG(" cmd opcode: 0x%04X", ((TL_CcEvt_t*)(phcievt->evtserial.evt.payload))->cmdcode); + TL_MM_DBG__MSG(" buffer addr: 0x%08X", phcievt); + break; + + case TL_BLEEVT_VS_OPCODE: + TL_MM_DBG__MSG("mm evt released: 0x%02X", phcievt->evtserial.evt.evtcode); + TL_MM_DBG__MSG(" subevtcode: 0x%04X", ((TL_AsynchEvt_t*)(phcievt->evtserial.evt.payload))->subevtcode); + TL_MM_DBG__MSG(" buffer addr: 0x%08X", phcievt); + break; + + default: + TL_MM_DBG__MSG("mm evt released: 0x%02X", phcievt->evtserial.evt.evtcode); + TL_MM_DBG__MSG(" buffer addr: 0x%08X", phcievt); + break; + } + + TL_MM_DBG__MSG("\r\n"); + + return; +} + +/****************************************************************************** + * TRACES + ******************************************************************************/ +void TL_TRACES_Init( void ) +{ + LST_init_head (&TracesEvtQueue); + + TL_RefTable.p_traces_table->traces_queue = (uint8_t*)&TracesEvtQueue; + + HW_IPCC_TRACES_Init(); + + return; +} + +void HW_IPCC_TRACES_EvtNot(void) +{ + TL_EvtPacket_t *phcievt; + + while(LST_is_empty(&TracesEvtQueue) == FALSE) + { + LST_remove_head (&TracesEvtQueue, (tListNode **)&phcievt); + TL_TRACES_EvtReceived( phcievt ); + } + + return; +} + +__WEAK void TL_TRACES_EvtReceived( TL_EvtPacket_t * hcievt ) +{ + (void)(hcievt); +} + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ From ac3469e5f51cd684d75e85510319922c0530da05 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Wed, 1 Dec 2021 15:13:05 +0100 Subject: [PATCH 072/226] chore: clean up and adapt STM32Cube_FW sources for STM32duino Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- src/utility/STM32Cube_FW/app_conf.h | 390 +------------------ src/utility/STM32Cube_FW/ble_bufsize.h | 6 +- src/utility/STM32Cube_FW/hw.h | 28 +- src/utility/STM32Cube_FW/hw_ipcc.c | 187 +-------- src/utility/STM32Cube_FW/mbox_def.h | 34 -- src/utility/STM32Cube_FW/shci.c | 40 +- src/utility/STM32Cube_FW/shci.h | 50 +-- src/utility/STM32Cube_FW/shci_tl.c | 19 +- src/utility/STM32Cube_FW/stm32_wpan_common.h | 35 +- src/utility/STM32Cube_FW/stm_list.c | 11 +- src/utility/STM32Cube_FW/stm_list.h | 4 +- src/utility/STM32Cube_FW/tl.h | 33 -- src/utility/STM32Cube_FW/tl_mbox.c | 144 +------ 13 files changed, 87 insertions(+), 894 deletions(-) diff --git a/src/utility/STM32Cube_FW/app_conf.h b/src/utility/STM32Cube_FW/app_conf.h index ac5ccd4d..df081ef1 100644 --- a/src/utility/STM32Cube_FW/app_conf.h +++ b/src/utility/STM32Cube_FW/app_conf.h @@ -1,4 +1,3 @@ -/* USER CODE BEGIN Header */ /** ****************************************************************************** * File Name : app_conf.h @@ -16,89 +15,36 @@ * ****************************************************************************** */ -/* USER CODE END Header */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef APP_CONF_H #define APP_CONF_H #include "hw.h" -#include "hw_conf.h" -#include "hw_if.h" +#include "ble_bufsize.h" /****************************************************************************** * Application Config ******************************************************************************/ -/** - * Define Secure Connections Support - */ -#define CFG_SECURE_NOT_SUPPORTED (0x00) -#define CFG_SECURE_OPTIONAL (0x01) -#define CFG_SECURE_MANDATORY (0x02) - -#define CFG_SC_SUPPORT CFG_SECURE_OPTIONAL +/**< generic parameters ******************************************************/ +/* HCI related defines */ -/** - * Define Keypress Notification Support - */ -#define CFG_KEYPRESS_NOT_SUPPORTED (0x00) -#define CFG_KEYPRESS_SUPPORTED (0x01) - -#define CFG_KEYPRESS_NOTIFICATION_SUPPORT CFG_KEYPRESS_NOT_SUPPORTED - -/** - * Numeric Comparison Answers - */ -#define YES (0x01) -#define NO (0x00) +#define ACI_HAL_SET_TX_POWER_LEVEL 0xFC0F +#define ACI_WRITE_CONFIG_DATA_OPCODE 0xFC0C +#define ACI_READ_CONFIG_DATA_OPCODE 0xFC0D +#define MAX_HCI_ACL_PACKET_SIZE (sizeof(TL_PacketHeader_t) + 5 + 251) +#define HCI_RESET 0x0C03 -/** - * Device name configuration for Generic Access Service - */ -#define CFG_GAP_DEVICE_NAME "TEMPLATE" -#define CFG_GAP_DEVICE_NAME_LENGTH (8) - -/** -* Identity root key used to derive LTK and CSRK -*/ -#define CFG_BLE_IRK {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0} - -/** -* Encryption root key used to derive LTK and CSRK -*/ -#define CFG_BLE_ERK {0xfe,0xdc,0xba,0x09,0x87,0x65,0x43,0x21,0xfe,0xdc,0xba,0x09,0x87,0x65,0x43,0x21} +#ifndef BLE_SHARED_MEM_BYTE_ORDER + #define BLE_SHARED_MEM_BYTE_ORDER MSBFIRST +#endif +#define BLE_MODULE_SHARED_MEM_BUFFER_SIZE 128 -/* USER CODE BEGIN Generic_Parameters */ /** - * SMPS supply - * SMPS not used when Set to 0 - * SMPS used when Set to 1 + * Define Tx Power */ -#define CFG_USE_SMPS 1 -/* USER CODE END Generic_Parameters */ - -/**< specific parameters */ -/*****************************************************/ - -#define PUSH_BUTTON_SW1_EXTI_IRQHandler EXTI4_IRQHandler - -/****************************************************************************** - * Information Table - * - * Version - * [0:3] = Build - 0: Untracked - 15:Released - x: Tracked version - * [4:7] = branch - 0: Mass Market - x: ... - * [8:15] = Subversion - * [16:23] = Version minor - * [24:31] = Version major - * - ******************************************************************************/ -#define CFG_FW_MAJOR_VERSION (0) -#define CFG_FW_MINOR_VERSION (0) -#define CFG_FW_SUBVERSION (1) -#define CFG_FW_BRANCH (0) -#define CFG_FW_BUILD (0) +#define CFG_TX_POWER (0x18) /* -0.15dBm */ /****************************************************************************** * BLE Stack @@ -144,12 +90,14 @@ /** * Prepare Write List size in terms of number of packet */ -#define CFG_BLE_PREPARE_WRITE_LIST_SIZE BLE_PREP_WRITE_X_ATT(CFG_BLE_MAX_ATT_MTU) +// #define CFG_BLE_PREPARE_WRITE_LIST_SIZE BLE_PREP_WRITE_X_ATT(CFG_BLE_MAX_ATT_MTU) +#define CFG_BLE_PREPARE_WRITE_LIST_SIZE (0x3A) /** * Number of allocated memory blocks */ -#define CFG_BLE_MBLOCK_COUNT (BLE_MBLOCKS_CALC(CFG_BLE_PREPARE_WRITE_LIST_SIZE, CFG_BLE_MAX_ATT_MTU, CFG_BLE_NUM_LINK)) +// #define CFG_BLE_MBLOCK_COUNT (BLE_MBLOCKS_CALC(CFG_BLE_PREPARE_WRITE_LIST_SIZE, CFG_BLE_MAX_ATT_MTU, CFG_BLE_NUM_LINK)) +#define CFG_BLE_MBLOCK_COUNT (0x79) /** * Enable or disable the Extended Packet length feature. Valid values are 0 or 1. @@ -203,307 +151,7 @@ * 1 : LL Only * 0 : LL + Host */ -#define CFG_BLE_LL_ONLY 0 -/****************************************************************************** - * Transport Layer - ******************************************************************************/ -/** - * Queue length of BLE Event - * This parameter defines the number of asynchronous events that can be stored in the HCI layer before - * being reported to the application. When a command is sent to the BLE core coprocessor, the HCI layer - * is waiting for the event with the Num_HCI_Command_Packets set to 1. The receive queue shall be large - * enough to store all asynchronous events received in between. - * When CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE is set to 27, this allow to store three 255 bytes long asynchronous events - * between the HCI command and its event. - * This parameter depends on the value given to CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE. When the queue size is to small, - * the system may hang if the queue is full with asynchronous events and the HCI layer is still waiting - * for a CC/CS event, In that case, the notification TL_BLE_HCI_ToNot() is called to indicate - * to the application a HCI command did not receive its command event within 30s (Default HCI Timeout). - */ -#define CFG_TLBLE_EVT_QUEUE_LENGTH 5 -/** - * This parameter should be set to fit most events received by the HCI layer. It defines the buffer size of each element - * allocated in the queue of received events and can be used to optimize the amount of RAM allocated by the Memory Manager. - * It should not exceed 255 which is the maximum HCI packet payload size (a greater value is a lost of memory as it will - * never be used) - * It shall be at least 4 to receive the command status event in one frame. - * The default value is set to 27 to allow receiving an event of MTU size in a single buffer. This value maybe reduced - * further depending on the application. - * - */ -#define CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE 255 /**< Set to 255 with the memory manager and the mailbox */ - -#define TL_BLE_EVENT_FRAME_SIZE ( TL_EVT_HDR_SIZE + CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE ) -/****************************************************************************** - * UART interfaces - ******************************************************************************/ - -/** - * Select UART interfaces - */ -#define CFG_UART_GUI hw_uart1 -#define CFG_DEBUG_TRACE_UART 0 -/****************************************************************************** - * USB interface - ******************************************************************************/ - -/** - * Enable/Disable USB interface - */ -#define CFG_USB_INTERFACE_ENABLE 0 - -/****************************************************************************** - * Low Power - ******************************************************************************/ -/** - * When set to 1, the low power mode is enable - * When set to 0, the device stays in RUN mode - */ -#define CFG_LPM_SUPPORTED 1 - -/****************************************************************************** - * Timer Server - ******************************************************************************/ -/** - * CFG_RTC_WUCKSEL_DIVIDER: This sets the RTCCLK divider to the wakeup timer. - * The higher is the value, the better is the power consumption and the accuracy of the timerserver - * The lower is the value, the finest is the granularity - * - * CFG_RTC_ASYNCH_PRESCALER: This sets the asynchronous prescaler of the RTC. It should as high as possible ( to ouput - * clock as low as possible) but the output clock should be equal or higher frequency compare to the clock feeding - * the wakeup timer. A lower clock speed would impact the accuracy of the timer server. - * - * CFG_RTC_SYNCH_PRESCALER: This sets the synchronous prescaler of the RTC. - * When the 1Hz calendar clock is required, it shall be sets according to other settings - * When the 1Hz calendar clock is not needed, CFG_RTC_SYNCH_PRESCALER should be set to 0x7FFF (MAX VALUE) - * - * CFG_RTCCLK_DIVIDER_CONF: - * Shall be set to either 0,2,4,8,16 - * When set to either 2,4,8,16, the 1Hhz calendar is supported - * When set to 0, the user sets its own configuration - * - * The following settings are computed with LSI as input to the RTC - */ -#define CFG_RTCCLK_DIVIDER_CONF 0 - -#if (CFG_RTCCLK_DIVIDER_CONF == 0) -/** - * Custom configuration - * It does not support 1Hz calendar - * It divides the RTC CLK by 16 - */ -#define CFG_RTCCLK_DIV (16) -#define CFG_RTC_WUCKSEL_DIVIDER (0) -#define CFG_RTC_ASYNCH_PRESCALER (CFG_RTCCLK_DIV - 1) -#define CFG_RTC_SYNCH_PRESCALER (0x7FFF) - -#else - -#if (CFG_RTCCLK_DIVIDER_CONF == 2) -/** - * It divides the RTC CLK by 2 - */ -#define CFG_RTC_WUCKSEL_DIVIDER (3) -#endif - -#if (CFG_RTCCLK_DIVIDER_CONF == 4) -/** - * It divides the RTC CLK by 4 - */ -#define CFG_RTC_WUCKSEL_DIVIDER (2) -#endif - -#if (CFG_RTCCLK_DIVIDER_CONF == 8) -/** - * It divides the RTC CLK by 8 - */ -#define CFG_RTC_WUCKSEL_DIVIDER (1) -#endif - -#if (CFG_RTCCLK_DIVIDER_CONF == 16) -/** - * It divides the RTC CLK by 16 - */ -#define CFG_RTC_WUCKSEL_DIVIDER (0) -#endif - -#define CFG_RTCCLK_DIV CFG_RTCCLK_DIVIDER_CONF -#define CFG_RTC_ASYNCH_PRESCALER (CFG_RTCCLK_DIV - 1) -#define CFG_RTC_SYNCH_PRESCALER (DIVR( LSE_VALUE, (CFG_RTC_ASYNCH_PRESCALER+1) ) - 1 ) - -#endif - -/** tick timer value in us */ -#define CFG_TS_TICK_VAL DIVR( (CFG_RTCCLK_DIV * 1000000), LSE_VALUE ) - -typedef enum -{ - CFG_TIM_PROC_ID_ISR, -} CFG_TimProcID_t; - -/****************************************************************************** - * Debug - ******************************************************************************/ -/** - * When set, this resets some hw resources to set the device in the same state than the power up - * The FW resets only register that may prevent the FW to run properly - * - * This shall be set to 0 in a final product - * - */ -#define CFG_HW_RESET_BY_FW 1 - -/** - * keep debugger enabled while in any low power mode when set to 1 - * should be set to 0 in production - */ -#define CFG_DEBUGGER_SUPPORTED 0 - -/** - * When set to 1, the traces are enabled in the BLE services - */ -#define CFG_DEBUG_BLE_TRACE 0 - -/** - * Enable or Disable traces in application - */ -#define CFG_DEBUG_APP_TRACE 0 - -#if (CFG_DEBUG_APP_TRACE != 0) -#define APP_DBG_MSG PRINT_MESG_DBG -#else -#define APP_DBG_MSG PRINT_NO_MESG -#endif - -#if ( (CFG_DEBUG_BLE_TRACE != 0) || (CFG_DEBUG_APP_TRACE != 0) ) -#define CFG_DEBUG_TRACE 1 -#endif - -#if (CFG_DEBUG_TRACE != 0) -#undef CFG_LPM_SUPPORTED -#undef CFG_DEBUGGER_SUPPORTED -#define CFG_LPM_SUPPORTED 0 -#define CFG_DEBUGGER_SUPPORTED 1 -#endif - -/** - * When CFG_DEBUG_TRACE_FULL is set to 1, the trace are output with the API name, the file name and the line number - * When CFG_DEBUG_TRACE_LIGHT is set to 1, only the debug message is output - * - * When both are set to 0, no trace are output - * When both are set to 1, CFG_DEBUG_TRACE_FULL is selected - */ -#define CFG_DEBUG_TRACE_LIGHT 0 -#define CFG_DEBUG_TRACE_FULL 0 - -#if (( CFG_DEBUG_TRACE != 0 ) && ( CFG_DEBUG_TRACE_LIGHT == 0 ) && (CFG_DEBUG_TRACE_FULL == 0)) -#undef CFG_DEBUG_TRACE_FULL -#undef CFG_DEBUG_TRACE_LIGHT -#define CFG_DEBUG_TRACE_FULL 0 -#define CFG_DEBUG_TRACE_LIGHT 1 -#endif - -#if ( CFG_DEBUG_TRACE == 0 ) -#undef CFG_DEBUG_TRACE_FULL -#undef CFG_DEBUG_TRACE_LIGHT -#define CFG_DEBUG_TRACE_FULL 0 -#define CFG_DEBUG_TRACE_LIGHT 0 -#endif - -/** - * When not set, the traces is looping on sending the trace over UART - */ -#define DBG_TRACE_USE_CIRCULAR_QUEUE 1 - -/** - * max buffer Size to queue data traces and max data trace allowed. - * Only Used if DBG_TRACE_USE_CIRCULAR_QUEUE is defined - */ -#define DBG_TRACE_MSG_QUEUE_SIZE 4096 -#define MAX_DBG_TRACE_MSG_SIZE 1024 - -/* USER CODE BEGIN Defines */ -#define CFG_LED_SUPPORTED 1 -#define CFG_BUTTON_SUPPORTED 1 -/* USER CODE END Defines */ - -/****************************************************************************** - * Scheduler - ******************************************************************************/ - -/** - * These are the lists of task id registered to the scheduler - * Each task id shall be in the range [0:31] - * This mechanism allows to implement a generic code in the API TL_BLE_HCI_StatusNot() to comply with - * the requirement that a HCI/ACI command shall never be sent if there is already one pending - */ - -/**< Add in that list all tasks that may send a ACI/HCI command */ -typedef enum -{ - CFG_TASK_BLE_HCI_CMD_ID, - CFG_TASK_SYS_HCI_CMD_ID, - CFG_TASK_HCI_ACL_DATA_ID, - CFG_TASK_SYS_LOCAL_CMD_ID, - CFG_TASK_TX_TO_HOST_ID, -/* USER CODE BEGIN CFG_Task_Id_With_HCI_Cmd_t */ - -/* USER CODE END CFG_Task_Id_With_HCI_Cmd_t */ - CFG_LAST_TASK_ID_WITH_HCICMD, /**< Shall be LAST in the list */ -} CFG_Task_Id_With_HCI_Cmd_t; - -/**< Add in that list all tasks that never send a ACI/HCI command */ -typedef enum -{ - CFG_FIRST_TASK_ID_WITH_NO_HCICMD = CFG_LAST_TASK_ID_WITH_HCICMD - 1, /**< Shall be FIRST in the list */ - CFG_TASK_SYSTEM_HCI_ASYNCH_EVT_ID, -/* USER CODE BEGIN CFG_Task_Id_With_NO_HCI_Cmd_t */ - -/* USER CODE END CFG_Task_Id_With_NO_HCI_Cmd_t */ - CFG_LAST_TASK_ID_WITHO_NO_HCICMD /**< Shall be LAST in the list */ -} CFG_Task_Id_With_NO_HCI_Cmd_t; -#define CFG_TASK_NBR CFG_LAST_TASK_ID_WITHO_NO_HCICMD - -/** - * This is the list of priority required by the application - * Each Id shall be in the range 0..31 - */ -typedef enum -{ - CFG_SCH_PRIO_0, - CFG_PRIO_NBR, -} CFG_SCH_Prio_Id_t; - -/** - * This is a bit mapping over 32bits listing all events id supported in the application - */ -typedef enum -{ - CFG_IDLEEVT_SYSTEM_HCI_CMD_EVT_RSP_ID, -} CFG_IdleEvt_Id_t; - -/****************************************************************************** - * LOW POWER - ******************************************************************************/ -/** - * Supported requester to the MCU Low Power Manager - can be increased up to 32 - * It lits a bit mapping of all user of the Low Power Manager - */ -typedef enum -{ - CFG_LPM_APP, - CFG_LPM_APP_BLE, - /* USER CODE BEGIN CFG_LPM_Id_t */ - - /* USER CODE END CFG_LPM_Id_t */ -} CFG_LPM_Id_t; - -/****************************************************************************** - * OTP manager - ******************************************************************************/ -#define CFG_OTP_BASE_ADDRESS OTP_AREA_BASE - -#define CFG_OTP_END_ADRESS OTP_AREA_END_ADDR +#define CFG_BLE_LL_ONLY 1 #endif /*APP_CONF_H */ diff --git a/src/utility/STM32Cube_FW/ble_bufsize.h b/src/utility/STM32Cube_FW/ble_bufsize.h index c5a5d569..8930e401 100644 --- a/src/utility/STM32Cube_FW/ble_bufsize.h +++ b/src/utility/STM32Cube_FW/ble_bufsize.h @@ -90,15 +90,15 @@ /* * BLE_FIXED_BUFFER_SIZE_BYTES: - * A part of the RAM, is dinamically allocated by initilizing all the pointers + * A part of the RAM, is dynamically allocated by initializing all the pointers * defined in a global context variable "mem_alloc_ctx_p". * This initialization is made in the Dynamic_allocator functions, which - * assing a portion of RAM given by the external application to the above + * assign a portion of RAM given by the external application to the above * mentioned "global pointers". * * The size of this Dynamic RAM is made of 2 main components: * - a part that is parameters-dependent (num of links, GATT buffers, ...), - * and which value is explicited by the following macro; + * and which value is defined by the following macro; * - a part, that may be considered "fixed", i.e. independent from the above * mentioned parameters. */ diff --git a/src/utility/STM32Cube_FW/hw.h b/src/utility/STM32Cube_FW/hw.h index 879fa6de..a94bec9c 100644 --- a/src/utility/STM32Cube_FW/hw.h +++ b/src/utility/STM32Cube_FW/hw.h @@ -27,14 +27,21 @@ extern "C" { #endif /* Includes ------------------------------------------------------------------*/ +#include "stm32_def.h" +#include "stm32wbxx_ll_bus.h" +#include "stm32wbxx_ll_exti.h" +#include "stm32wbxx_ll_system.h" +#include "stm32wbxx_ll_rcc.h" +#include "stm32wbxx_ll_ipcc.h" +#include "stm32wbxx_ll_cortex.h" +#include "stm32wbxx_ll_utils.h" +#include "stm32wbxx_ll_pwr.h" /****************************************************************************** * HW IPCC ******************************************************************************/ void HW_IPCC_Enable( void ); void HW_IPCC_Init( void ); - void HW_IPCC_Rx_Handler( void ); - void HW_IPCC_Tx_Handler( void ); void HW_IPCC_BLE_Init( void ); void HW_IPCC_BLE_SendCmd( void ); @@ -80,23 +87,6 @@ extern "C" { void HW_IPCC_TRACES_Init( void ); void HW_IPCC_TRACES_EvtNot( void ); - - void HW_IPCC_MAC_802_15_4_Init( void ); - void HW_IPCC_MAC_802_15_4_SendCmd( void ); - void HW_IPCC_MAC_802_15_4_SendAck( void ); - void HW_IPCC_MAC_802_15_4_CmdEvtNot( void ); - void HW_IPCC_MAC_802_15_4_EvtNot( void ); - - void HW_IPCC_ZIGBEE_Init( void ); - - void HW_IPCC_ZIGBEE_SendM4RequestToM0(void); /* M4 Request to M0 */ - void HW_IPCC_ZIGBEE_RecvAppliAckFromM0(void); /* Request ACK from M0 */ - - void HW_IPCC_ZIGBEE_RecvM0NotifyToM4(void); /* M0 Notify to M4 */ - void HW_IPCC_ZIGBEE_SendM4AckToM0Notify(void); /* Notify ACK from M4 */ - void HW_IPCC_ZIGBEE_RecvM0RequestToM4(void); /* M0 Request to M4 */ - void HW_IPCC_ZIGBEE_SendM4AckToM0Request(void); /* Request ACK from M4 */ - #ifdef __cplusplus } diff --git a/src/utility/STM32Cube_FW/hw_ipcc.c b/src/utility/STM32Cube_FW/hw_ipcc.c index 6da31992..d1f8b650 100644 --- a/src/utility/STM32Cube_FW/hw_ipcc.c +++ b/src/utility/STM32Cube_FW/hw_ipcc.c @@ -16,9 +16,9 @@ * ****************************************************************************** */ - +#if defined(STM32WBxx) /* Includes ------------------------------------------------------------------*/ -#include "app_common.h" +#include "hw.h" #include "mbox_def.h" /* Global variables ---------------------------------------------------------*/ @@ -45,35 +45,17 @@ static void HW_IPCC_THREAD_NotEvtHandler( void ); static void HW_IPCC_THREAD_CliNotEvtHandler( void ); #endif -#ifdef MAC_802_15_4_WB -static void HW_IPCC_MAC_802_15_4_CmdEvtHandler( void ); -static void HW_IPCC_MAC_802_15_4_NotEvtHandler( void ); -#endif - -#ifdef ZIGBEE_WB -static void HW_IPCC_ZIGBEE_CmdEvtHandler( void ); -static void HW_IPCC_ZIGBEE_StackNotifEvtHandler( void ); -static void HW_IPCC_ZIGBEE_StackM0RequestHandler( void ); - -#endif - /* Public function definition -----------------------------------------------*/ /****************************************************************************** * INTERRUPT HANDLER ******************************************************************************/ -void HW_IPCC_Rx_Handler( void ) +void IPCC_C1_RX_IRQHandler(void) { if (HW_IPCC_RX_PENDING( HW_IPCC_SYSTEM_EVENT_CHANNEL )) { HW_IPCC_SYS_EvtHandler(); } -#ifdef MAC_802_15_4_WB - else if (HW_IPCC_RX_PENDING( HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL )) - { - HW_IPCC_MAC_802_15_4_NotEvtHandler(); - } -#endif /* MAC_802_15_4_WB */ #ifdef THREAD_WB else if (HW_IPCC_RX_PENDING( HW_IPCC_THREAD_NOTIFICATION_ACK_CHANNEL )) { @@ -84,16 +66,6 @@ void HW_IPCC_Rx_Handler( void ) HW_IPCC_THREAD_CliNotEvtHandler(); } #endif /* THREAD_WB */ -#ifdef ZIGBEE_WB - else if (HW_IPCC_RX_PENDING( HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL )) - { - HW_IPCC_ZIGBEE_StackNotifEvtHandler(); - } - else if (HW_IPCC_RX_PENDING( HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL )) - { - HW_IPCC_ZIGBEE_StackM0RequestHandler(); - } -#endif /* ZIGBEE_WB */ else if (HW_IPCC_RX_PENDING( HW_IPCC_BLE_EVENT_CHANNEL )) { HW_IPCC_BLE_EvtHandler(); @@ -102,34 +74,20 @@ void HW_IPCC_Rx_Handler( void ) { HW_IPCC_TRACES_EvtHandler(); } - - return; } -void HW_IPCC_Tx_Handler( void ) +void IPCC_C1_TX_IRQHandler(void) { if (HW_IPCC_TX_PENDING( HW_IPCC_SYSTEM_CMD_RSP_CHANNEL )) { HW_IPCC_SYS_CmdEvtHandler(); } -#ifdef MAC_802_15_4_WB - else if (HW_IPCC_TX_PENDING( HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL )) - { - HW_IPCC_MAC_802_15_4_CmdEvtHandler(); - } -#endif /* MAC_802_15_4_WB */ #ifdef THREAD_WB else if (HW_IPCC_TX_PENDING( HW_IPCC_THREAD_OT_CMD_RSP_CHANNEL )) { HW_IPCC_OT_CmdEvtHandler(); } #endif /* THREAD_WB */ -#ifdef ZIGBEE_WB - if (HW_IPCC_TX_PENDING( HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL )) - { - HW_IPCC_ZIGBEE_CmdEvtHandler(); - } -#endif /* ZIGBEE_WB */ else if (HW_IPCC_TX_PENDING( HW_IPCC_SYSTEM_CMD_RSP_CHANNEL )) { HW_IPCC_SYS_CmdEvtHandler(); @@ -142,9 +100,8 @@ void HW_IPCC_Tx_Handler( void ) { HW_IPCC_BLE_AclDataEvtHandler(); } - - return; } + /****************************************************************************** * GENERAL ******************************************************************************/ @@ -228,8 +185,8 @@ static void HW_IPCC_BLE_AclDataEvtHandler( void ) return; } -__weak void HW_IPCC_BLE_AclDataAckNot( void ){}; -__weak void HW_IPCC_BLE_RxEvtNot( void ){}; +__WEAK void HW_IPCC_BLE_AclDataAckNot( void ){}; +__WEAK void HW_IPCC_BLE_RxEvtNot( void ){}; /****************************************************************************** * SYSTEM @@ -267,56 +224,8 @@ static void HW_IPCC_SYS_EvtHandler( void ) return; } -__weak void HW_IPCC_SYS_CmdEvtNot( void ){}; -__weak void HW_IPCC_SYS_EvtNot( void ){}; - -/****************************************************************************** - * MAC 802.15.4 - ******************************************************************************/ -#ifdef MAC_802_15_4_WB -void HW_IPCC_MAC_802_15_4_Init( void ) -{ - LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL ); - - return; -} - -void HW_IPCC_MAC_802_15_4_SendCmd( void ) -{ - LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL ); - LL_C1_IPCC_EnableTransmitChannel( IPCC, HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL ); - - return; -} - -void HW_IPCC_MAC_802_15_4_SendAck( void ) -{ - LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL ); - LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL ); - - return; -} - -static void HW_IPCC_MAC_802_15_4_CmdEvtHandler( void ) -{ - LL_C1_IPCC_DisableTransmitChannel( IPCC, HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL ); - - HW_IPCC_MAC_802_15_4_CmdEvtNot(); - - return; -} - -static void HW_IPCC_MAC_802_15_4_NotEvtHandler( void ) -{ - LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL ); - - HW_IPCC_MAC_802_15_4_EvtNot(); - - return; -} -__weak void HW_IPCC_MAC_802_15_4_CmdEvtNot( void ){}; -__weak void HW_IPCC_MAC_802_15_4_EvtNot( void ){}; -#endif +__WEAK void HW_IPCC_SYS_CmdEvtNot( void ){}; +__WEAK void HW_IPCC_SYS_EvtNot( void ){}; /****************************************************************************** * THREAD @@ -388,80 +297,12 @@ static void HW_IPCC_THREAD_CliNotEvtHandler( void ) return; } -__weak void HW_IPCC_OT_CmdEvtNot( void ){}; -__weak void HW_IPCC_CLI_CmdEvtNot( void ){}; -__weak void HW_IPCC_THREAD_EvtNot( void ){}; +__WEAK void HW_IPCC_OT_CmdEvtNot( void ){}; +__WEAK void HW_IPCC_CLI_CmdEvtNot( void ){}; +__WEAK void HW_IPCC_THREAD_EvtNot( void ){}; #endif /* THREAD_WB */ -/****************************************************************************** - * ZIGBEE - ******************************************************************************/ -#ifdef ZIGBEE_WB -void HW_IPCC_ZIGBEE_Init( void ) -{ - LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL ); - LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL ); - - return; -} - -void HW_IPCC_ZIGBEE_SendM4RequestToM0( void ) -{ - LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL ); - LL_C1_IPCC_EnableTransmitChannel( IPCC, HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL ); - - return; -} - -void HW_IPCC_ZIGBEE_SendM4AckToM0Notify( void ) -{ - LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL ); - LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL ); - - return; -} - -static void HW_IPCC_ZIGBEE_CmdEvtHandler( void ) -{ - LL_C1_IPCC_DisableTransmitChannel( IPCC, HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL ); - - HW_IPCC_ZIGBEE_RecvAppliAckFromM0(); - - return; -} - -static void HW_IPCC_ZIGBEE_StackNotifEvtHandler( void ) -{ - LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL ); - - HW_IPCC_ZIGBEE_RecvM0NotifyToM4(); - - return; -} - -static void HW_IPCC_ZIGBEE_StackM0RequestHandler( void ) -{ - LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL ); - - HW_IPCC_ZIGBEE_RecvM0RequestToM4(); - - return; -} - -void HW_IPCC_ZIGBEE_SendM4AckToM0Request( void ) -{ - LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL ); - LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL ); - - return; -} - -__weak void HW_IPCC_ZIGBEE_RecvAppliAckFromM0( void ){}; -__weak void HW_IPCC_ZIGBEE_RecvM0NotifyToM4( void ){}; -__weak void HW_IPCC_ZIGBEE_RecvM0RequestToM4( void ){}; -#endif /* ZIGBEE_WB */ - /****************************************************************************** * MEMORY MANAGER ******************************************************************************/ @@ -512,6 +353,6 @@ static void HW_IPCC_TRACES_EvtHandler( void ) return; } -__weak void HW_IPCC_TRACES_EvtNot( void ){}; - +__WEAK void HW_IPCC_TRACES_EvtNot( void ){}; +#endif /* STM32WBxx */ /******************* (C) COPYRIGHT 2019 STMicroelectronics *****END OF FILE****/ diff --git a/src/utility/STM32Cube_FW/mbox_def.h b/src/utility/STM32Cube_FW/mbox_def.h index 1741a8c3..6bddf696 100644 --- a/src/utility/STM32Cube_FW/mbox_def.h +++ b/src/utility/STM32Cube_FW/mbox_def.h @@ -106,12 +106,6 @@ extern "C" { uint8_t *m0cmd_buffer; } MB_LldBleTable_t; - typedef struct - { - uint8_t *notifM0toM4_buffer; - uint8_t *appliCmdM4toM0_buffer; - uint8_t *requestM0toM4_buffer; - } MB_ZigbeeTable_t; /** * msg * [0:7] = cmd/evt @@ -139,13 +133,6 @@ extern "C" { uint8_t *traces_queue; } MB_TracesTable_t; - typedef struct - { - uint8_t *p_cmdrsp_buffer; - uint8_t *p_notack_buffer; - uint8_t *evt_queue; - } MB_Mac_802_15_4_t; - typedef struct { MB_DeviceInfoTable_t *p_device_info_table; @@ -154,8 +141,6 @@ extern "C" { MB_SysTable_t *p_sys_table; MB_MemManagerTable_t *p_mem_manager_table; MB_TracesTable_t *p_traces_table; - MB_Mac_802_15_4_t *p_mac_802_15_4_table; - MB_ZigbeeTable_t *p_zigbee_table; MB_LldTestsTable_t *p_lld_tests_table; MB_LldBleTable_t *p_lld_ble_table; } MB_RefTable_t; @@ -176,15 +161,6 @@ extern "C" { * | | * |<---HW_IPCC_SYSTEM_EVENT_CHANNEL-----------------| * | | - * | (ZIGBEE) | - * |----HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL------------>| - * | | - * |----HW_IPCC_ZIGBEE_CMD_CLI_CHANNEL-------------->| - * | | - * |<---HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL-------| - * | | - * |<---HW_IPCC_ZIGBEE_CLI_NOTIF_ACK_CHANNEL---------| - * | | * | (THREAD) | * |----HW_IPCC_THREAD_OT_CMD_RSP_CHANNEL----------->| * | | @@ -208,11 +184,6 @@ extern "C" { * | | * |<---HW_IPCC_LLD_BLE_M0_CMD_CHANNEL---------------| * | | - * | (MAC) | - * |----HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL-------->| - * | | - * |<---HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL| - * | | * | (BUFFER) | * |----HW_IPCC_MM_RELEASE_BUFFER_CHANNE------------>| * | | @@ -230,8 +201,6 @@ extern "C" { #define HW_IPCC_BLE_CMD_CHANNEL LL_IPCC_CHANNEL_1 #define HW_IPCC_SYSTEM_CMD_RSP_CHANNEL LL_IPCC_CHANNEL_2 #define HW_IPCC_THREAD_OT_CMD_RSP_CHANNEL LL_IPCC_CHANNEL_3 -#define HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL LL_IPCC_CHANNEL_3 -#define HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL LL_IPCC_CHANNEL_3 #define HW_IPCC_MM_RELEASE_BUFFER_CHANNEL LL_IPCC_CHANNEL_4 #define HW_IPCC_THREAD_CLI_CMD_CHANNEL LL_IPCC_CHANNEL_5 #define HW_IPCC_LLDTESTS_CLI_CMD_CHANNEL LL_IPCC_CHANNEL_5 @@ -243,8 +212,6 @@ extern "C" { #define HW_IPCC_BLE_EVENT_CHANNEL LL_IPCC_CHANNEL_1 #define HW_IPCC_SYSTEM_EVENT_CHANNEL LL_IPCC_CHANNEL_2 #define HW_IPCC_THREAD_NOTIFICATION_ACK_CHANNEL LL_IPCC_CHANNEL_3 -#define HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL LL_IPCC_CHANNEL_3 -#define HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL LL_IPCC_CHANNEL_3 #define HW_IPCC_LLDTESTS_M0_CMD_CHANNEL LL_IPCC_CHANNEL_3 #define HW_IPCC_LLD_BLE_M0_CMD_CHANNEL LL_IPCC_CHANNEL_3 #define HW_IPCC_TRACES_CHANNEL LL_IPCC_CHANNEL_4 @@ -252,7 +219,6 @@ extern "C" { #define HW_IPCC_LLDTESTS_CLI_RSP_CHANNEL LL_IPCC_CHANNEL_5 #define HW_IPCC_LLD_BLE_CLI_RSP_CHANNEL LL_IPCC_CHANNEL_5 #define HW_IPCC_LLD_BLE_RSP_CHANNEL LL_IPCC_CHANNEL_5 -#define HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL LL_IPCC_CHANNEL_5 #endif /*__MBOX_H */ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/src/utility/STM32Cube_FW/shci.c b/src/utility/STM32Cube_FW/shci.c index 1edf1feb..b848dd85 100644 --- a/src/utility/STM32Cube_FW/shci.c +++ b/src/utility/STM32Cube_FW/shci.c @@ -17,7 +17,7 @@ ****************************************************************************** */ - +#if defined(STM32WBxx) /* Includes ------------------------------------------------------------------*/ #include "stm32_wpan_common.h" @@ -316,24 +316,6 @@ SHCI_CmdStatus_t SHCI_C2_LLD_BLE_Init( uint8_t param_size, uint8_t * p_param ) return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); } -SHCI_CmdStatus_t SHCI_C2_ZIGBEE_Init( void ) -{ - /** - * Buffer is large enough to hold command complete without payload - */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; - TL_EvtPacket_t * p_rsp; - - p_rsp = (TL_EvtPacket_t *)local_buffer; - - shci_send( SHCI_OPCODE_C2_ZIGBEE_INIT, - 0, - 0, - p_rsp ); - - return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); -} - SHCI_CmdStatus_t SHCI_C2_DEBUG_Init( SHCI_C2_DEBUG_Init_Cmd_Packet_t *pCmdPacket ) { /** @@ -453,24 +435,6 @@ SHCI_CmdStatus_t SHCI_C2_RADIO_AllowLowPower( SHCI_C2_FLASH_Ip_t Ip,uint8_t Fla return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); } -SHCI_CmdStatus_t SHCI_C2_MAC_802_15_4_Init( void ) -{ - /** - * Buffer is large enough to hold command complete without payload - */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; - TL_EvtPacket_t * p_rsp; - - p_rsp = (TL_EvtPacket_t *)local_buffer; - - shci_send( SHCI_OPCODE_C2_MAC_802_15_4_INIT, - 0, - 0, - p_rsp ); - - return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); -} - SHCI_CmdStatus_t SHCI_C2_Reinit( void ) { /** @@ -605,5 +569,5 @@ SHCI_CmdStatus_t SHCI_GetWirelessFwInfo( WirelessFwInfo_t* pWirelessInfo ) return (SHCI_Success); } - +#endif /* STM32WBxx */ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/src/utility/STM32Cube_FW/shci.h b/src/utility/STM32Cube_FW/shci.h index e737f4c5..11c53ced 100644 --- a/src/utility/STM32Cube_FW/shci.h +++ b/src/utility/STM32Cube_FW/shci.h @@ -50,7 +50,6 @@ extern "C" { ERR_BLE_INIT = 0, ERR_THREAD_LLD_FATAL_ERROR = 125, /* The LLD driver used on 802_15_4 detected a fatal error */ ERR_THREAD_UNKNOWN_CMD = 126, /* The command send by the M4 to control the Thread stack is unknown */ - ERR_ZIGBEE_UNKNOWN_CMD = 200, /* The command send by the M4 to control the Zigbee stack is unknown */ } SCHI_SystemErrCode_t; #define SHCI_EVTCODE ( 0xFF ) @@ -102,7 +101,7 @@ extern "C" { /** * SHCI_SUB_EVT_OT_NVM_RAM_UPDATE - * This notifies the CPU1 which part of the OT NVM RAM has been updated so that only the modified + * This notifies the CPU1 which part of the 'OT NVM RAM' has been updated so that only the modified * section could be written in Flash/NVM * StartAddress : Start address of the section that has been modified * Size : Size (in bytes) of the section that has been modified @@ -208,9 +207,7 @@ extern "C" { SHCI_OCF_C2_FLASH_STORE_DATA, SHCI_OCF_C2_FLASH_ERASE_DATA, SHCI_OCF_C2_RADIO_ALLOW_LOW_POWER, - SHCI_OCF_C2_MAC_802_15_4_INIT, SHCI_OCF_C2_REINIT, - SHCI_OCF_C2_ZIGBEE_INIT, SHCI_OCF_C2_LLD_TESTS_INIT, SHCI_OCF_C2_EXTPA_CONFIG, SHCI_OCF_C2_SET_FLASH_ACTIVITY_CONTROL, @@ -378,8 +375,6 @@ extern "C" { { uint8_t thread_config; uint8_t ble_config; - uint8_t mac_802_15_4_config; - uint8_t zigbee_config; } SHCI_C2_DEBUG_TracesConfig_t; typedef PACKED_STRUCT @@ -419,7 +414,6 @@ extern "C" { { BLE_ENABLE, THREAD_ENABLE, - ZIGBEE_ENABLE, } SHCI_C2_CONCURRENT_Mode_Param_t; /** No response parameters*/ @@ -430,18 +424,13 @@ extern "C" { { BLE_IP, THREAD_IP, - ZIGBEE_IP, } SHCI_C2_FLASH_Ip_t; /** No response parameters*/ #define SHCI_OPCODE_C2_RADIO_ALLOW_LOW_POWER (( SHCI_OGF << 10) + SHCI_OCF_C2_RADIO_ALLOW_LOW_POWER) -#define SHCI_OPCODE_C2_MAC_802_15_4_INIT (( SHCI_OGF << 10) + SHCI_OCF_C2_MAC_802_15_4_INIT) - #define SHCI_OPCODE_C2_REINIT (( SHCI_OGF << 10) + SHCI_OCF_C2_REINIT) -#define SHCI_OPCODE_C2_ZIGBEE_INIT (( SHCI_OGF << 10) + SHCI_OCF_C2_ZIGBEE_INIT) - #define SHCI_OPCODE_C2_LLD_TESTS_INIT (( SHCI_OGF << 10) + SHCI_OCF_C2_LLD_TESTS_INIT) #define SHCI_OPCODE_C2_LLD_BLE_INIT (( SHCI_OGF << 10) + SHCI_OCF_C2_LLD_BLE_INIT) @@ -540,14 +529,14 @@ extern "C" { typedef MB_WirelessFwInfoTable_t SHCI_WirelessFwInfoTable_t; /* - * At startup, the informations relative to the wireless binary are stored in RAM trough a structure defined by + * At startup, the information relative to the wireless binary are stored in RAM through a structure defined by * SHCI_WirelessFwInfoTable_t.This structure contains 4 fields (Version,MemorySize, Stack_info and a reserved part) * each of those coded on 32 bits as shown on the table below: * * * |7 |6 |5 |4 |3 |2 |1 |0 |7 |6 |5 |4 |3 |2 |1 |0 |7 |6 |5 |4 |3 |2 |1 |0 |7 |6 |5 |4 |3 |2 |1 |0 | * ------------------------------------------------------------------------------------------------- - * Version | Major version | Minor version | Sub version | Branch |Releas Type| + * Version | Major version | Minor version | Sub version | Branch |Release Type| * ------------------------------------------------------------------------------------------------- * MemorySize | SRAM2B (kB) | SRAM2A (kB) | SRAM1 (kB) | FLASH (4kb) | * ------------------------------------------------------------------------------------------------- @@ -592,19 +581,11 @@ typedef MB_WirelessFwInfoTable_t SHCI_WirelessFwInfoTable_t; #define INFO_STACK_TYPE_BLE_LIGHT 0x03 #define INFO_STACK_TYPE_THREAD_FTD 0x10 #define INFO_STACK_TYPE_THREAD_MTD 0x11 -#define INFO_STACK_TYPE_ZIGBEE_FFD 0x30 -#define INFO_STACK_TYPE_ZIGBEE_RFD 0x31 -#define INFO_STACK_TYPE_MAC 0x40 #define INFO_STACK_TYPE_BLE_THREAD_FTD_STATIC 0x50 #define INFO_STACK_TYPE_BLE_THREAD_FTD_DYAMIC 0x51 -#define INFO_STACK_TYPE_802154_LLD_TESTS 0x60 -#define INFO_STACK_TYPE_802154_PHY_VALID 0x61 #define INFO_STACK_TYPE_BLE_PHY_VALID 0x62 #define INFO_STACK_TYPE_BLE_LLD_TESTS 0x63 #define INFO_STACK_TYPE_BLE_RLV 0x64 -#define INFO_STACK_TYPE_802154_RLV 0x65 -#define INFO_STACK_TYPE_BLE_ZIGBEE_FFD_STATIC 0x70 -#define INFO_STACK_TYPE_BLE_ZIGBEE_FFD_DYNAMIC 0x78 #define INFO_STACK_TYPE_RLV 0x80 typedef struct { @@ -750,7 +731,7 @@ typedef struct { * @brief Starts the LLD tests CLI * * @param param_size : Nb of bytes - * @param p_param : pointeur with data to give from M4 to M0 + * @param p_param : pointer with data to give from M4 to M0 * @retval Status */ SHCI_CmdStatus_t SHCI_C2_LLDTESTS_Init( uint8_t param_size, uint8_t * p_param ); @@ -760,20 +741,11 @@ typedef struct { * @brief Starts the LLD tests CLI * * @param param_size : Nb of bytes - * @param p_param : pointeur with data to give from M4 to M0 + * @param p_param : pointer with data to give from M4 to M0 * @retval Status */ SHCI_CmdStatus_t SHCI_C2_LLD_BLE_Init( uint8_t param_size, uint8_t * p_param ); - /** - * SHCI_C2_ZIGBEE_Init - * @brief Starts the Zigbee Stack - * - * @param None - * @retval Status - */ - SHCI_CmdStatus_t SHCI_C2_ZIGBEE_Init( void ); - /** * SHCI_C2_DEBUG_Init * @brief Starts the Traces @@ -829,19 +801,9 @@ typedef struct { */ SHCI_CmdStatus_t SHCI_C2_RADIO_AllowLowPower( SHCI_C2_FLASH_Ip_t Ip,uint8_t FlagRadioLowPowerOn); - - /** - * SHCI_C2_MAC_802_15_4_Init - * @brief Starts the MAC 802.15.4 on M0 - * - * @param None - * @retval Status - */ - SHCI_CmdStatus_t SHCI_C2_MAC_802_15_4_Init( void ); - /** * SHCI_GetWirelessFwInfo - * @brief This function read back the informations relative to the wireless binary loaded. + * @brief This function read back the information relative to the wireless binary loaded. * Refer yourself to SHCI_WirelessFwInfoTable_t structure to get the significance * of the different parameters returned. * @param pWirelessInfo : Pointer to WirelessFwInfo_t. diff --git a/src/utility/STM32Cube_FW/shci_tl.c b/src/utility/STM32Cube_FW/shci_tl.c index 736f2793..27906395 100644 --- a/src/utility/STM32Cube_FW/shci_tl.c +++ b/src/utility/STM32Cube_FW/shci_tl.c @@ -17,12 +17,13 @@ ****************************************************************************** */ - +#if defined(STM32WBxx) /* Includes ------------------------------------------------------------------*/ #include "stm32_wpan_common.h" #include "stm_list.h" #include "shci_tl.h" +#include "stm32_def.h" /** * These traces are not yet supported in an usual way in the delivery package @@ -203,6 +204,20 @@ void shci_send( uint16_t cmd_code, uint8_t len_cmd_payload, uint8_t * p_cmd_payl return; } +void shci_notify_asynch_evt(void *pdata) +{ + UNUSED(pdata); + /* Need to parse data in future version */ + shci_user_evt_proc(); +} + +void shci_register_io_bus(tSHciIO *fops) +{ + /* Register IO bus services */ + fops->Init = TL_SYS_Init; + fops->Send = TL_SYS_SendCmd; +} + /* Private functions ---------------------------------------------------------*/ static void TlInit( TL_CmdPacket_t * p_cmdbuffer ) { @@ -348,4 +363,4 @@ __WEAK void shci_cmd_resp_release(uint32_t flag) return; } - +#endif /* STM32WBxx */ \ No newline at end of file diff --git a/src/utility/STM32Cube_FW/stm32_wpan_common.h b/src/utility/STM32Cube_FW/stm32_wpan_common.h index cad9026d..93e909ca 100644 --- a/src/utility/STM32Cube_FW/stm32_wpan_common.h +++ b/src/utility/STM32Cube_FW/stm32_wpan_common.h @@ -26,19 +26,9 @@ extern "C" { #endif -#if defined ( __CC_ARM ) - #define __ASM __asm /*!< asm keyword for ARM Compiler */ - #define __INLINE __inline /*!< inline keyword for ARM Compiler */ - #define __STATIC_INLINE static __inline -#elif defined ( __ICCARM__ ) - #define __ASM __asm /*!< asm keyword for IAR Compiler */ - #define __INLINE inline /*!< inline keyword for IAR Compiler. Only available in High optimization mode! */ - #define __STATIC_INLINE static inline -#elif defined ( __GNUC__ ) - #define __ASM __asm /*!< asm keyword for GNU Compiler */ - #define __INLINE inline /*!< inline keyword for GNU Compiler */ - #define __STATIC_INLINE static inline -#endif +#define __ASM __asm /*!< asm keyword for GNU Compiler */ +#define __INLINE inline /*!< inline keyword for GNU Compiler */ +#define __STATIC_INLINE static inline #include <stdint.h> #include <string.h> @@ -141,25 +131,8 @@ extern "C" { /* ----------------------------------- * * Packed usage (compiler dependent) * * ----------------------------------- */ -#undef PACKED__ #undef PACKED_STRUCT - -#if defined ( __CC_ARM ) - #if defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050U) - #define PACKED__ __attribute__((packed)) - #define PACKED_STRUCT struct PACKED__ - #else - #define PACKED__(TYPE) __packed TYPE - #define PACKED_STRUCT PACKED__(struct) - #endif -#elif defined ( __GNUC__ ) - #define PACKED__ __attribute__((packed)) - #define PACKED_STRUCT struct PACKED__ -#elif defined (__ICCARM__) - #define PACKED_STRUCT __packed struct -#elif - #define PACKED_STRUCT __packed struct -#endif +#define PACKED_STRUCT struct __packed #ifdef __cplusplus } diff --git a/src/utility/STM32Cube_FW/stm_list.c b/src/utility/STM32Cube_FW/stm_list.c index 42e2d500..6e802a07 100644 --- a/src/utility/STM32Cube_FW/stm_list.c +++ b/src/utility/STM32Cube_FW/stm_list.c @@ -17,13 +17,13 @@ ****************************************************************************** */ - +#if defined(STM32WBxx) /****************************************************************************** * Include Files ******************************************************************************/ -#include "utilities_common.h" - #include "stm_list.h" +#include "cmsis_gcc.h" +#include "stm32_wpan_common.h" /****************************************************************************** * Function Definitions @@ -34,10 +34,10 @@ void LST_init_head (tListNode * listHead) listHead->prev = listHead; } -uint8_t LST_is_empty (tListNode * listHead) +bool LST_is_empty (tListNode * listHead) { uint32_t primask_bit; - uint8_t return_value; + bool return_value; primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ @@ -206,3 +206,4 @@ void LST_get_prev_node (tListNode * ref_node, tListNode ** node) __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ } +#endif /* STM32WBxx */ \ No newline at end of file diff --git a/src/utility/STM32Cube_FW/stm_list.h b/src/utility/STM32Cube_FW/stm_list.h index 78e74463..84e22cd7 100644 --- a/src/utility/STM32Cube_FW/stm_list.h +++ b/src/utility/STM32Cube_FW/stm_list.h @@ -22,6 +22,8 @@ #define _STM_LIST_H_ /* Includes ------------------------------------------------------------------*/ +#include "stdint.h" +#include "stdbool.h" typedef struct _tListNode { struct _tListNode * next; @@ -30,7 +32,7 @@ typedef struct _tListNode { void LST_init_head (tListNode * listHead); -uint8_t LST_is_empty (tListNode * listHead); +bool LST_is_empty (tListNode * listHead); void LST_insert_head (tListNode * listHead, tListNode * node); diff --git a/src/utility/STM32Cube_FW/tl.h b/src/utility/STM32Cube_FW/tl.h index e5fac413..4741599d 100644 --- a/src/utility/STM32Cube_FW/tl.h +++ b/src/utility/STM32Cube_FW/tl.h @@ -199,19 +199,6 @@ typedef struct uint8_t *p_LldBleM0CmdBuffer; } TL_LLD_BLE_Config_t; -typedef struct -{ - uint8_t *p_Mac_802_15_4_CmdRspBuffer; - uint8_t *p_Mac_802_15_4_NotAckBuffer; -} TL_MAC_802_15_4_Config_t; - -typedef struct -{ - uint8_t *p_ZigbeeOtCmdRspBuffer; - uint8_t *p_ZigbeeNotAckBuffer; - uint8_t *p_ZigbeeNotifRequestBuffer; -} TL_ZIGBEE_Config_t; - /** * @brief Contain the BLE HCI Init Configuration * @{ @@ -305,26 +292,6 @@ void TL_MM_EvtDone( TL_EvtPacket_t * hcievt ); void TL_TRACES_Init( void ); void TL_TRACES_EvtReceived( TL_EvtPacket_t * hcievt ); -/****************************************************************************** - * MAC 802.15.4 - ******************************************************************************/ -void TL_MAC_802_15_4_Init( TL_MAC_802_15_4_Config_t *p_Config ); -void TL_MAC_802_15_4_SendCmd( void ); -void TL_MAC_802_15_4_CmdEvtReceived( TL_EvtPacket_t * Otbuffer ); -void TL_MAC_802_15_4_NotReceived( TL_EvtPacket_t * Notbuffer ); -void TL_MAC_802_15_4_SendAck ( void ); - -/****************************************************************************** - * ZIGBEE - ******************************************************************************/ -void TL_ZIGBEE_Init( TL_ZIGBEE_Config_t *p_Config ); -void TL_ZIGBEE_SendM4RequestToM0( void ); -void TL_ZIGBEE_SendM4AckToM0Notify ( void ); -void TL_ZIGBEE_NotReceived( TL_EvtPacket_t * Notbuffer ); -void TL_ZIGBEE_CmdEvtReceived( TL_EvtPacket_t * Otbuffer ); -void TL_ZIGBEE_M0RequestReceived(TL_EvtPacket_t * Otbuffer ); -void TL_ZIGBEE_SendM4AckToM0Request(void); - #ifdef __cplusplus } /* extern "C" */ #endif diff --git a/src/utility/STM32Cube_FW/tl_mbox.c b/src/utility/STM32Cube_FW/tl_mbox.c index 507edba2..8b579d5b 100644 --- a/src/utility/STM32Cube_FW/tl_mbox.c +++ b/src/utility/STM32Cube_FW/tl_mbox.c @@ -17,7 +17,7 @@ ****************************************************************************** */ - +#if defined(STM32WBxx) /* Includes ------------------------------------------------------------------*/ #include "stm32_wpan_common.h" #include "hw.h" @@ -56,15 +56,13 @@ PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_LldBleTable_t TL_LldBleTable; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_SysTable_t TL_SysTable; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_MemManagerTable_t TL_MemManagerTable; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_TracesTable_t TL_TracesTable; -PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_Mac_802_15_4_t TL_Mac_802_15_4_Table; -PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_ZigbeeTable_t TL_Zigbee_Table; /**< tables */ PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode FreeBufQueue; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode TracesEvtQueue; PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static uint8_t CsBuffer[sizeof(TL_PacketHeader_t) + TL_EVT_HDR_SIZE + sizeof(TL_CsEvt_t)]; -PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode EvtQueue; -PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode SystemEvtQueue; +PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static tListNode EvtQueue; +PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static tListNode SystemEvtQueue; static tListNode LocalFreeBufQueue; @@ -102,8 +100,6 @@ void TL_Init( void ) TL_RefTable.p_sys_table = &TL_SysTable; TL_RefTable.p_mem_manager_table = &TL_MemManagerTable; TL_RefTable.p_traces_table = &TL_TracesTable; - TL_RefTable.p_mac_802_15_4_table = &TL_Mac_802_15_4_Table; - TL_RefTable.p_zigbee_table = &TL_Zigbee_Table; HW_IPCC_Init(); return; @@ -438,139 +434,6 @@ void TL_LLD_BLE_SendRspAck( void ) } #endif /* LLD_BLE_WB */ -#ifdef MAC_802_15_4_WB -/****************************************************************************** - * MAC 802.15.4 - ******************************************************************************/ -void TL_MAC_802_15_4_Init( TL_MAC_802_15_4_Config_t *p_Config ) -{ - MB_Mac_802_15_4_t * p_mac_802_15_4_table; - - p_mac_802_15_4_table = TL_RefTable.p_mac_802_15_4_table; - - p_mac_802_15_4_table->p_cmdrsp_buffer = p_Config->p_Mac_802_15_4_CmdRspBuffer; - p_mac_802_15_4_table->p_notack_buffer = p_Config->p_Mac_802_15_4_NotAckBuffer; - - HW_IPCC_MAC_802_15_4_Init(); - - return; -} - -void TL_MAC_802_15_4_SendCmd( void ) -{ - ((TL_CmdPacket_t *)(TL_RefTable.p_mac_802_15_4_table->p_cmdrsp_buffer))->cmdserial.type = TL_OTCMD_PKT_TYPE; - - HW_IPCC_MAC_802_15_4_SendCmd(); - - return; -} - -void TL_MAC_802_15_4_SendAck ( void ) -{ - ((TL_CmdPacket_t *)(TL_RefTable.p_mac_802_15_4_table->p_notack_buffer))->cmdserial.type = TL_OTACK_PKT_TYPE; - - HW_IPCC_MAC_802_15_4_SendAck(); - - return; -} - -void HW_IPCC_MAC_802_15_4_CmdEvtNot(void) -{ - TL_MAC_802_15_4_CmdEvtReceived( (TL_EvtPacket_t*)(TL_RefTable.p_mac_802_15_4_table->p_cmdrsp_buffer) ); - - return; -} - -void HW_IPCC_MAC_802_15_4_EvtNot( void ) -{ - TL_MAC_802_15_4_NotReceived( (TL_EvtPacket_t*)(TL_RefTable.p_mac_802_15_4_table->p_notack_buffer) ); - - return; -} - -__WEAK void TL_MAC_802_15_4_CmdEvtReceived( TL_EvtPacket_t * Otbuffer ){}; -__WEAK void TL_MAC_802_15_4_NotReceived( TL_EvtPacket_t * Notbuffer ){}; -#endif - -#ifdef ZIGBEE_WB -/****************************************************************************** - * ZIGBEE - ******************************************************************************/ -void TL_ZIGBEE_Init( TL_ZIGBEE_Config_t *p_Config ) -{ - MB_ZigbeeTable_t * p_zigbee_table; - - p_zigbee_table = TL_RefTable.p_zigbee_table; - p_zigbee_table->appliCmdM4toM0_buffer = p_Config->p_ZigbeeOtCmdRspBuffer; - p_zigbee_table->notifM0toM4_buffer = p_Config->p_ZigbeeNotAckBuffer; - p_zigbee_table->requestM0toM4_buffer = p_Config->p_ZigbeeNotifRequestBuffer; - - HW_IPCC_ZIGBEE_Init(); - - return; -} - -/* Zigbee M4 to M0 Request */ -void TL_ZIGBEE_SendM4RequestToM0( void ) -{ - ((TL_CmdPacket_t *)(TL_RefTable.p_zigbee_table->appliCmdM4toM0_buffer))->cmdserial.type = TL_OTCMD_PKT_TYPE; - - HW_IPCC_ZIGBEE_SendM4RequestToM0(); - - return; -} - -/* Used to receive an ACK from the M0 */ -void HW_IPCC_ZIGBEE_RecvAppliAckFromM0(void) -{ - TL_ZIGBEE_CmdEvtReceived( (TL_EvtPacket_t*)(TL_RefTable.p_zigbee_table->appliCmdM4toM0_buffer) ); - - return; -} - -/* Zigbee notification from M0 to M4 */ -void HW_IPCC_ZIGBEE_RecvM0NotifyToM4( void ) -{ - TL_ZIGBEE_NotReceived( (TL_EvtPacket_t*)(TL_RefTable.p_zigbee_table->notifM0toM4_buffer) ); - - return; -} - -/* Send an ACK to the M0 for a Notification */ -void TL_ZIGBEE_SendM4AckToM0Notify ( void ) -{ - ((TL_CmdPacket_t *)(TL_RefTable.p_zigbee_table->notifM0toM4_buffer))->cmdserial.type = TL_OTACK_PKT_TYPE; - - HW_IPCC_ZIGBEE_SendM4AckToM0Notify(); - - return; -} - -/* Zigbee M0 to M4 Request */ -void HW_IPCC_ZIGBEE_RecvM0RequestToM4( void ) -{ - TL_ZIGBEE_M0RequestReceived( (TL_EvtPacket_t*)(TL_RefTable.p_zigbee_table->requestM0toM4_buffer) ); - - return; -} - -/* Send an ACK to the M0 for a Request */ -void TL_ZIGBEE_SendM4AckToM0Request(void) -{ - ((TL_CmdPacket_t *)(TL_RefTable.p_zigbee_table->requestM0toM4_buffer))->cmdserial.type = TL_OTACK_PKT_TYPE; - - HW_IPCC_ZIGBEE_SendM4AckToM0Request(); - - return; -} - - -__WEAK void TL_ZIGBEE_CmdEvtReceived( TL_EvtPacket_t * Otbuffer ){}; -__WEAK void TL_ZIGBEE_NotReceived( TL_EvtPacket_t * Notbuffer ){}; -#endif - - - /****************************************************************************** * MEMORY MANAGER ******************************************************************************/ @@ -683,4 +546,5 @@ __WEAK void TL_TRACES_EvtReceived( TL_EvtPacket_t * hcievt ) (void)(hcievt); } +#endif /* STM32WBxx */ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ From 4d9fd3129ba4818d3ee4890b5d488c0f374ff81f Mon Sep 17 00:00:00 2001 From: Francois Ramu <francois.ramu@st.com> Date: Thu, 12 Nov 2020 13:21:31 +0100 Subject: [PATCH 073/226] fix: missing IPCC enable for C2 in several examples from stm32CubeWB This fix is coming from https://github.com/STMicroelectronics/STM32CubeWB/issues/19 Signed-off-by: Francois Ramu <francois.ramu@st.com> --- src/utility/STM32Cube_FW/hw_ipcc.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/utility/STM32Cube_FW/hw_ipcc.c b/src/utility/STM32Cube_FW/hw_ipcc.c index d1f8b650..658aadb4 100644 --- a/src/utility/STM32Cube_FW/hw_ipcc.c +++ b/src/utility/STM32Cube_FW/hw_ipcc.c @@ -107,6 +107,12 @@ void IPCC_C1_TX_IRQHandler(void) ******************************************************************************/ void HW_IPCC_Enable( void ) { + /** + * Such as IPCC IP available to the CPU2, it is required to keep the IPCC clock running + when FUS is running on CPU2 and CPU1 enters deep sleep mode + */ + LL_C2_AHB3_GRP1_EnableClock(LL_C2_AHB3_GRP1_PERIPH_IPCC); + /** * When the device is out of standby, it is required to use the EXTI mechanism to wakeup CPU2 */ From 108f46f8eeee221646a87f9823ac58ddec3252f6 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Wed, 1 Dec 2021 18:38:39 +0100 Subject: [PATCH 074/226] fix: [-Waddress-of-packed-member] warning Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- src/utility/STM32Cube_FW/stm_list.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/utility/STM32Cube_FW/stm_list.h b/src/utility/STM32Cube_FW/stm_list.h index 84e22cd7..529eeddb 100644 --- a/src/utility/STM32Cube_FW/stm_list.h +++ b/src/utility/STM32Cube_FW/stm_list.h @@ -20,12 +20,13 @@ #ifndef _STM_LIST_H_ #define _STM_LIST_H_ +#include "stm32_wpan_common.h" /* Includes ------------------------------------------------------------------*/ #include "stdint.h" #include "stdbool.h" -typedef struct _tListNode { +typedef PACKED_STRUCT _tListNode { struct _tListNode * next; struct _tListNode * prev; } tListNode; From 09680e7e3f4b7d04de1c4ef6eb9ab45c734cd8fa Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Wed, 1 Dec 2021 18:42:57 +0100 Subject: [PATCH 075/226] fix: include a timeout when waiting for the cmd_resp Signed-off-by: Francois Ramu <francois.ramu@st.com> --- src/utility/STM32Cube_FW/shci_tl.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/utility/STM32Cube_FW/shci_tl.c b/src/utility/STM32Cube_FW/shci_tl.c index 27906395..8d4d4ff4 100644 --- a/src/utility/STM32Cube_FW/shci_tl.c +++ b/src/utility/STM32Cube_FW/shci_tl.c @@ -21,6 +21,8 @@ /* Includes ------------------------------------------------------------------*/ #include "stm32_wpan_common.h" +#include <Arduino.h> + #include "stm_list.h" #include "shci_tl.h" #include "stm32_def.h" @@ -346,11 +348,12 @@ static void OutputEvtTrace(TL_EvtPacket_t *phcievtbuffer) /* Weak implementation ----------------------------------------------------------------*/ __WEAK void shci_cmd_resp_wait(uint32_t timeout) { - (void)timeout; - CmdRspStatusFlag = SHCI_TL_CMD_RESP_WAIT; - while(CmdRspStatusFlag != SHCI_TL_CMD_RESP_RELEASE); - + for (unsigned long start = millis(); (millis() - start) < timeout;) { + if (CmdRspStatusFlag == SHCI_TL_CMD_RESP_RELEASE) { + break; + } + } return; } @@ -363,4 +366,4 @@ __WEAK void shci_cmd_resp_release(uint32_t flag) return; } -#endif /* STM32WBxx */ \ No newline at end of file +#endif /* STM32WBxx */ From 14c0f7381f919d618c4a3f98e236bc9f86d7bdfd Mon Sep 17 00:00:00 2001 From: KMeldgaard <36625114+KMeldgaard@users.noreply.github.com> Date: Mon, 15 Nov 2021 14:54:07 +0100 Subject: [PATCH 076/226] Added support for custom app_conf.h (#35) --- README.md | 7 + src/utility/STM32Cube_FW/app_conf.h | 160 ++--------------- src/utility/STM32Cube_FW/app_conf_default.h | 185 ++++++++++++++++++++ 3 files changed, 203 insertions(+), 149 deletions(-) create mode 100644 src/utility/STM32Cube_FW/app_conf_default.h diff --git a/README.md b/README.md index 2fb6e425..3a0691ab 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,13 @@ https://github.com/stm32duino/wiki/wiki/STM32duinoBLE#stm32duinoble-with-x-nucle For more information about ArduinoBLE library please visit the official web page at: https://github.com/arduino-libraries/ArduinoBLE +# Configuration +STM32Cube_WPAN has several configuration options, which are set in the `app_conf.h`. +This package has a default configuration named `app_conf_default.h`. +The user can include the file `app_conf_custom.h` to customize the BLE application. +Options wrapped in `#ifndef`, `#endif` in `app_conf_default.h` can be overwritten. +Additional options can be added. + ## License ``` diff --git a/src/utility/STM32Cube_FW/app_conf.h b/src/utility/STM32Cube_FW/app_conf.h index df081ef1..3246393f 100644 --- a/src/utility/STM32Cube_FW/app_conf.h +++ b/src/utility/STM32Cube_FW/app_conf.h @@ -1,158 +1,20 @@ -/** - ****************************************************************************** - * File Name : app_conf.h - * Description : Application configuration file for STM32WPAN Middleware. - ****************************************************************************** - * @attention - * - * <h2><center>© Copyright (c) 2020 STMicroelectronics. - * All rights reserved.</center></h2> - * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 - * - ****************************************************************************** - */ +//----------------------------- +// @file app_conf.h +// @author Kasper Meldgaard +// @brief Wrapper for BLE app configuration based on comment by fpistm +// (https://github.com/stm32duino/STM32duinoBLE/issues/34). +// @date 15-11-2021 +// @copyright Copyright (c) 2021 -/* Define to prevent recursive inclusion -------------------------------------*/ #ifndef APP_CONF_H #define APP_CONF_H #include "hw.h" #include "ble_bufsize.h" -/****************************************************************************** - * Application Config - ******************************************************************************/ - -/**< generic parameters ******************************************************/ -/* HCI related defines */ - -#define ACI_HAL_SET_TX_POWER_LEVEL 0xFC0F -#define ACI_WRITE_CONFIG_DATA_OPCODE 0xFC0C -#define ACI_READ_CONFIG_DATA_OPCODE 0xFC0D -#define MAX_HCI_ACL_PACKET_SIZE (sizeof(TL_PacketHeader_t) + 5 + 251) -#define HCI_RESET 0x0C03 - -#ifndef BLE_SHARED_MEM_BYTE_ORDER - #define BLE_SHARED_MEM_BYTE_ORDER MSBFIRST +#if __has_include("app_conf_custom.h") + #include "app_conf_custom.h" #endif -#define BLE_MODULE_SHARED_MEM_BUFFER_SIZE 128 - -/** - * Define Tx Power - */ -#define CFG_TX_POWER (0x18) /* -0.15dBm */ - -/****************************************************************************** - * BLE Stack - ******************************************************************************/ -/** - * Maximum number of simultaneous connections that the device will support. - * Valid values are from 1 to 8 - */ -#define CFG_BLE_NUM_LINK 8 - -/** - * Maximum number of Services that can be stored in the GATT database. - * Note that the GAP and GATT services are automatically added so this parameter should be 2 plus the number of user services - */ -#define CFG_BLE_NUM_GATT_SERVICES 8 - -/** - * Maximum number of Attributes - * (i.e. the number of characteristic + the number of characteristic values + the number of descriptors, excluding the services) - * that can be stored in the GATT database. - * Note that certain characteristics and relative descriptors are added automatically during device initialization - * so this parameters should be 9 plus the number of user Attributes - */ -#define CFG_BLE_NUM_GATT_ATTRIBUTES 68 - -/** - * Maximum supported ATT_MTU size - */ -#define CFG_BLE_MAX_ATT_MTU (156) - -/** - * Size of the storage area for Attribute values - * This value depends on the number of attributes used by application. In particular the sum of the following quantities (in octets) should be made for each attribute: - * - attribute value length - * - 5, if UUID is 16 bit; 19, if UUID is 128 bit - * - 2, if server configuration descriptor is used - * - 2*DTM_NUM_LINK, if client configuration descriptor is used - * - 2, if extended properties is used - * The total amount of memory needed is the sum of the above quantities for each attribute. - */ -#define CFG_BLE_ATT_VALUE_ARRAY_SIZE (1344) - -/** - * Prepare Write List size in terms of number of packet - */ -// #define CFG_BLE_PREPARE_WRITE_LIST_SIZE BLE_PREP_WRITE_X_ATT(CFG_BLE_MAX_ATT_MTU) -#define CFG_BLE_PREPARE_WRITE_LIST_SIZE (0x3A) - -/** - * Number of allocated memory blocks - */ -// #define CFG_BLE_MBLOCK_COUNT (BLE_MBLOCKS_CALC(CFG_BLE_PREPARE_WRITE_LIST_SIZE, CFG_BLE_MAX_ATT_MTU, CFG_BLE_NUM_LINK)) -#define CFG_BLE_MBLOCK_COUNT (0x79) - -/** - * Enable or disable the Extended Packet length feature. Valid values are 0 or 1. - */ -#define CFG_BLE_DATA_LENGTH_EXTENSION 1 - -/** - * Sleep clock accuracy in Slave mode (ppm value) - */ -#define CFG_BLE_SLAVE_SCA 500 - -/** - * Sleep clock accuracy in Master mode - * 0 : 251 ppm to 500 ppm - * 1 : 151 ppm to 250 ppm - * 2 : 101 ppm to 150 ppm - * 3 : 76 ppm to 100 ppm - * 4 : 51 ppm to 75 ppm - * 5 : 31 ppm to 50 ppm - * 6 : 21 ppm to 30 ppm - * 7 : 0 ppm to 20 ppm - */ -#define CFG_BLE_MASTER_SCA 0 - -/** - * Source for the 32 kHz slow speed clock - * 1 : internal RO - * 0 : external crystal ( no calibration ) - */ -#define CFG_BLE_LSE_SOURCE 0 - -/** - * Start up time of the high speed (16 or 32 MHz) crystal oscillator in units of 625/256 us (~2.44 us) - */ -#define CFG_BLE_HSE_STARTUP_TIME 0x148 - -/** - * Maximum duration of the connection event when the device is in Slave mode in units of 625/256 us (~2.44 us) - */ -#define CFG_BLE_MAX_CONN_EVENT_LENGTH ( 0xFFFFFFFF ) - -/** - * Viterbi Mode - * 1 : enabled - * 0 : disabled - */ -#define CFG_BLE_VITERBI_MODE 1 - -/** - * LL Only Mode - * 1 : LL Only - * 0 : LL + Host - */ -#define CFG_BLE_LL_ONLY 1 - -#endif /*APP_CONF_H */ +#include "app_conf_default.h" -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ +#endif /* APP_CONF_H */ diff --git a/src/utility/STM32Cube_FW/app_conf_default.h b/src/utility/STM32Cube_FW/app_conf_default.h new file mode 100644 index 00000000..e870c321 --- /dev/null +++ b/src/utility/STM32Cube_FW/app_conf_default.h @@ -0,0 +1,185 @@ +/** + ****************************************************************************** + * File Name : app_conf_default.h + * Description : Default application configuration file for STM32WPAN Middleware. + ****************************************************************************** + * @attention + * + * <h2><center>© Copyright (c) 2020 STMicroelectronics. + * All rights reserved.</center></h2> + * + * This software component is licensed by ST under Ultimate Liberty license + * SLA0044, the "License"; You may not use this file except in compliance with + * the License. You may obtain a copy of the License at: + * www.st.com/SLA0044 + * + ****************************************************************************** + */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef APP_CONF_DEFAULT_H +#define APP_CONF_DEFAULT_H + +/****************************************************************************** + * Application Config + ******************************************************************************/ + +/**< generic parameters ******************************************************/ +/* HCI related defines */ + +#define ACI_HAL_SET_TX_POWER_LEVEL 0xFC0F +#define ACI_WRITE_CONFIG_DATA_OPCODE 0xFC0C +#define ACI_READ_CONFIG_DATA_OPCODE 0xFC0D +#define MAX_HCI_ACL_PACKET_SIZE (sizeof(TL_PacketHeader_t) + 5 + 251) +#define HCI_RESET 0x0C03 + +#ifndef BLE_SHARED_MEM_BYTE_ORDER + #define BLE_SHARED_MEM_BYTE_ORDER MSBFIRST +#endif +#define BLE_MODULE_SHARED_MEM_BUFFER_SIZE 128 + +/** + * Define Tx Power + */ +#ifndef CFG_TX_POWER + #define CFG_TX_POWER (0x18) /* -0.15dBm */ +#endif + +/****************************************************************************** + * BLE Stack + ******************************************************************************/ +/** + * Maximum number of simultaneous connections that the device will support. + * Valid values are from 1 to 8 + */ +#ifndef CFG_BLE_NUM_LINK + #define CFG_BLE_NUM_LINK 8 +#endif + +/** + * Maximum number of Services that can be stored in the GATT database. + * Note that the GAP and GATT services are automatically added so this parameter should be 2 plus the number of user + * services + */ +#ifndef CFG_BLE_NUM_GATT_SERVICES + #define CFG_BLE_NUM_GATT_SERVICES 8 +#endif + +/** + * Maximum number of Attributes + * (i.e. the number of characteristic + the number of characteristic values + the number of descriptors, excluding the + * services) that can be stored in the GATT database. Note that certain characteristics and relative descriptors are + * added automatically during device initialization so this parameters should be 9 plus the number of user Attributes + */ +#ifndef CFG_BLE_NUM_GATT_ATTRIBUTES + #define CFG_BLE_NUM_GATT_ATTRIBUTES 68 +#endif + +/** + * Maximum supported ATT_MTU size + */ +#ifndef CFG_BLE_MAX_ATT_MTU + #define CFG_BLE_MAX_ATT_MTU (156) +#endif + +/** + * Size of the storage area for Attribute values + * This value depends on the number of attributes used by application. In particular the sum of the following + * quantities (in octets) should be made for each attribute: + * - attribute value length + * - 5, if UUID is 16 bit; 19, if UUID is 128 bit + * - 2, if server configuration descriptor is used + * - 2*DTM_NUM_LINK, if client configuration descriptor is used + * - 2, if extended properties is used + * The total amount of memory needed is the sum of the above quantities for each attribute. + */ +#ifndef CFG_BLE_ATT_VALUE_ARRAY_SIZE + #define CFG_BLE_ATT_VALUE_ARRAY_SIZE (1344) +#endif + +/** + * Prepare Write List size in terms of number of packet + */ +//#define CFG_BLE_PREPARE_WRITE_LIST_SIZE BLE_PREP_WRITE_X_ATT(CFG_BLE_MAX_ATT_MTU) +#ifndef CFG_BLE_PREPARE_WRITE_LIST_SIZE + #define CFG_BLE_PREPARE_WRITE_LIST_SIZE (0x3A) +#endif + +/** + * Number of allocated memory blocks + */ +//#define CFG_BLE_MBLOCK_COUNT (BLE_MBLOCKS_CALC(CFG_BLE_PREPARE_WRITE_LIST_SIZE, CFG_BLE_MAX_ATT_MTU, +// CFG_BLE_NUM_LINK)) +#ifndef CFG_BLE_MBLOCK_COUNT + #define CFG_BLE_MBLOCK_COUNT (0x79) +#endif + +/** + * Enable or disable the Extended Packet length feature. Valid values are 0 or 1. + */ +#ifndef CFG_BLE_DATA_LENGTH_EXTENSION + #define CFG_BLE_DATA_LENGTH_EXTENSION 1 +#endif + +/** + * Sleep clock accuracy in Slave mode (ppm value) + */ +#ifndef CFG_BLE_SLAVE_SCA + #define CFG_BLE_SLAVE_SCA 500 +#endif + +/** + * Sleep clock accuracy in Master mode + * 0 : 251 ppm to 500 ppm + * 1 : 151 ppm to 250 ppm + * 2 : 101 ppm to 150 ppm + * 3 : 76 ppm to 100 ppm + * 4 : 51 ppm to 75 ppm + * 5 : 31 ppm to 50 ppm + * 6 : 21 ppm to 30 ppm + * 7 : 0 ppm to 20 ppm + */ +#ifndef CFG_BLE_MASTER_SCA + #define CFG_BLE_MASTER_SCA 0 +#endif + +/** + * Source for the 32 kHz slow speed clock + * 1 : internal RO + * 0 : external crystal ( no calibration ) + */ +#ifndef CFG_BLE_LSE_SOURCE + #define CFG_BLE_LSE_SOURCE 0 +#endif + +/** + * Start up time of the high speed (16 or 32 MHz) crystal oscillator in units of 625/256 us (~2.44 us) + */ +#ifndef CFG_BLE_HSE_STARTUP_TIME + #define CFG_BLE_HSE_STARTUP_TIME 0x148 +#endif + +/** + * Maximum duration of the connection event when the device is in Slave mode in units of 625/256 us (~2.44 us) + */ +#ifndef CFG_BLE_MAX_CONN_EVENT_LENGTH + #define CFG_BLE_MAX_CONN_EVENT_LENGTH (0xFFFFFFFF) +#endif + +/** + * Viterbi Mode + * 1 : enabled + * 0 : disabled + */ +#define CFG_BLE_VITERBI_MODE 1 + +/** + * LL Only Mode + * 1 : LL Only + * 0 : LL + Host + */ +#define CFG_BLE_LL_ONLY 1 + +#endif /* APP_CONF_DEFAULT_H */ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ From a36ed33ac795f449ec6e46dba9137650490d12c9 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Wed, 8 Dec 2021 11:03:29 +0100 Subject: [PATCH 077/226] Update spell-check.yml --- .github/workflows/spell-check.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/spell-check.yml b/.github/workflows/spell-check.yml index 6c44bcfb..f8da452a 100644 --- a/.github/workflows/spell-check.yml +++ b/.github/workflows/spell-check.yml @@ -13,4 +13,5 @@ jobs: - name: Spell check uses: arduino/actions/libraries/spell-check@master with: - skip-paths: ./extras/test \ No newline at end of file + skip-paths: ./extras/test, ./extras/STM32Cube_FW + From 331c39a9580374061464f562f0df92e6a3002eb5 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Wed, 8 Dec 2021 11:14:45 +0100 Subject: [PATCH 078/226] Update spell-check.yml --- .github/workflows/spell-check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/spell-check.yml b/.github/workflows/spell-check.yml index f8da452a..6fded7ff 100644 --- a/.github/workflows/spell-check.yml +++ b/.github/workflows/spell-check.yml @@ -13,5 +13,5 @@ jobs: - name: Spell check uses: arduino/actions/libraries/spell-check@master with: - skip-paths: ./extras/test, ./extras/STM32Cube_FW + skip-paths: ./extras/test,./extras/STM32Cube_FW From 8ce1025219060f97cdd5575ed3cae1044aedcef4 Mon Sep 17 00:00:00 2001 From: Alexandre Bourdiol <alexandre.bourdiol@st.com> Date: Thu, 2 Dec 2021 10:23:30 +0100 Subject: [PATCH 079/226] Add patch files to be applied on stm32wb Cube update Patches correspond to somes commits of PR #38 Signed-off-by: Alexandre Bourdiol <alexandre.bourdiol@st.com> --- ...nd-adapt-STM32Cube_FW-sources-for-ST.patch | 1582 +++++++++++++++++ ...imeout-when-waiting-for-the-cmd_resp.patch | 44 + ...ded-support-for-custom-app_conf.h-35.patch | 186 ++ .../0004-Stub-OutputDbgTrace-function.patch | 209 +++ 4 files changed, 2021 insertions(+) create mode 100644 extras/STM32Cube_FW/0001-chore-clean-up-and-adapt-STM32Cube_FW-sources-for-ST.patch create mode 100644 extras/STM32Cube_FW/0002-fix-include-a-timeout-when-waiting-for-the-cmd_resp.patch create mode 100644 extras/STM32Cube_FW/0003-Added-support-for-custom-app_conf.h-35.patch create mode 100644 extras/STM32Cube_FW/0004-Stub-OutputDbgTrace-function.patch diff --git a/extras/STM32Cube_FW/0001-chore-clean-up-and-adapt-STM32Cube_FW-sources-for-ST.patch b/extras/STM32Cube_FW/0001-chore-clean-up-and-adapt-STM32Cube_FW-sources-for-ST.patch new file mode 100644 index 00000000..3ae29806 --- /dev/null +++ b/extras/STM32Cube_FW/0001-chore-clean-up-and-adapt-STM32Cube_FW-sources-for-ST.patch @@ -0,0 +1,1582 @@ +From 6fcfc029ba21a3674456a12032720bff6ecfe27d Mon Sep 17 00:00:00 2001 +From: Alexandre Bourdiol <alexandre.bourdiol@st.com> +Date: Mon, 6 Dec 2021 11:08:32 +0100 +Subject: [PATCH 1/4] chore: clean up and adapt STM32Cube_FW sources for + STM32duino + +Signed-off-by: Frederic Pillon <frederic.pillon@st.com> +Signed-off-by: Alexandre Bourdiol <alexandre.bourdiol@st.com> +--- + src/utility/STM32Cube_FW/app_conf_default.h | 422 +------------------ + src/utility/STM32Cube_FW/ble_bufsize.h | 13 +- + src/utility/STM32Cube_FW/hw.h | 28 +- + src/utility/STM32Cube_FW/hw_ipcc.c | 184 +------- + src/utility/STM32Cube_FW/mbox_def.h | 34 -- + src/utility/STM32Cube_FW/shci.c | 40 +- + src/utility/STM32Cube_FW/shci.h | 47 +-- + src/utility/STM32Cube_FW/shci_tl.c | 19 +- + src/utility/STM32Cube_FW/stm32_wpan_common.h | 39 +- + src/utility/STM32Cube_FW/stm_list.c | 11 +- + src/utility/STM32Cube_FW/stm_list.h | 4 +- + src/utility/STM32Cube_FW/tl.h | 33 -- + src/utility/STM32Cube_FW/tl_mbox.c | 144 +------ + 13 files changed, 94 insertions(+), 924 deletions(-) + +diff --git a/src/utility/STM32Cube_FW/app_conf_default.h b/src/utility/STM32Cube_FW/app_conf_default.h +index 7ebc65a..4f300e0 100644 +--- a/src/utility/STM32Cube_FW/app_conf_default.h ++++ b/src/utility/STM32Cube_FW/app_conf_default.h +@@ -1,4 +1,3 @@ +-/* USER CODE BEGIN Header */ + /** + ****************************************************************************** + * @file app_conf.h +@@ -16,94 +15,36 @@ + * + ****************************************************************************** + */ +-/* USER CODE END Header */ + + /* Define to prevent recursive inclusion -------------------------------------*/ + #ifndef APP_CONF_H + #define APP_CONF_H + + #include "hw.h" +-#include "hw_conf.h" +-#include "hw_if.h" + #include "ble_bufsize.h" + + /****************************************************************************** + * Application Config + ******************************************************************************/ + +-/** +- * Define Secure Connections Support +- */ +-#define CFG_SECURE_NOT_SUPPORTED (0x00) +-#define CFG_SECURE_OPTIONAL (0x01) +-#define CFG_SECURE_MANDATORY (0x02) +- +-#define CFG_SC_SUPPORT CFG_SECURE_OPTIONAL +- +-/** +- * Define Keypress Notification Support +- */ +-#define CFG_KEYPRESS_NOT_SUPPORTED (0x00) +-#define CFG_KEYPRESS_SUPPORTED (0x01) ++/**< generic parameters ******************************************************/ ++/* HCI related defines */ + +-#define CFG_KEYPRESS_NOTIFICATION_SUPPORT CFG_KEYPRESS_NOT_SUPPORTED ++#define ACI_HAL_SET_TX_POWER_LEVEL 0xFC0F ++#define ACI_WRITE_CONFIG_DATA_OPCODE 0xFC0C ++#define ACI_READ_CONFIG_DATA_OPCODE 0xFC0D ++#define MAX_HCI_ACL_PACKET_SIZE (sizeof(TL_PacketHeader_t) + 5 + 251) ++#define HCI_RESET 0x0C03 + +-/** +- * Numeric Comparison Answers +- */ +-#define YES (0x01) +-#define NO (0x00) +- +-/** +- * Device name configuration for Generic Access Service +- */ +-#define CFG_GAP_DEVICE_NAME "TEMPLATE" +-#define CFG_GAP_DEVICE_NAME_LENGTH (8) +- +-/** +-* Identity root key used to derive LTK and CSRK +-*/ +-#define CFG_BLE_IRK {0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0} +- +-/** +-* Encryption root key used to derive LTK and CSRK +-*/ +-#define CFG_BLE_ERK {0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21, 0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21} ++#ifndef BLE_SHARED_MEM_BYTE_ORDER ++ #define BLE_SHARED_MEM_BYTE_ORDER MSBFIRST ++#endif ++#define BLE_MODULE_SHARED_MEM_BUFFER_SIZE 128 + + /** +- * SMPS supply +- * SMPS not used when Set to 0 +- * SMPS used when Set to 1 ++ * Define Tx Power + */ +-#define CFG_USE_SMPS 0 +- +-/* USER CODE BEGIN Generic_Parameters */ +-/* USER CODE END Generic_Parameters */ +- +-/**< specific parameters */ +-/*****************************************************/ +- +-/* USER CODE BEGIN Specific_Parameters */ +-#define PUSH_BUTTON_SW1_EXTI_IRQHandler EXTI4_IRQHandler +- +-/* USER CODE END Specific_Parameters */ +- +-/****************************************************************************** +- * Information Table +- * +- * Version +- * [0:3] = Build - 0: Untracked - 15:Released - x: Tracked version +- * [4:7] = branch - 0: Mass Market - x: ... +- * [8:15] = Subversion +- * [16:23] = Version minor +- * [24:31] = Version major +- * +- ******************************************************************************/ +-#define CFG_FW_MAJOR_VERSION (0) +-#define CFG_FW_MINOR_VERSION (0) +-#define CFG_FW_SUBVERSION (1) +-#define CFG_FW_BRANCH (0) +-#define CFG_FW_BUILD (0) ++#define CFG_TX_POWER (0x18) /* -0.15dBm */ + + /****************************************************************************** + * BLE Stack +@@ -152,13 +93,15 @@ + * Prepare Write List size in terms of number of packet + * This parameter is ignored by the CPU2 when CFG_BLE_OPTIONS is set to 1" + */ +-#define CFG_BLE_PREPARE_WRITE_LIST_SIZE BLE_PREP_WRITE_X_ATT(CFG_BLE_MAX_ATT_MTU) ++// #define CFG_BLE_PREPARE_WRITE_LIST_SIZE BLE_PREP_WRITE_X_ATT(CFG_BLE_MAX_ATT_MTU) ++#define CFG_BLE_PREPARE_WRITE_LIST_SIZE (0x3A) + + /** + * Number of allocated memory blocks + * This parameter is overwritten by the CPU2 with an hardcoded optimal value when the parameter when CFG_BLE_OPTIONS is set to 1 + */ +-#define CFG_BLE_MBLOCK_COUNT (BLE_MBLOCKS_CALC(CFG_BLE_PREPARE_WRITE_LIST_SIZE, CFG_BLE_MAX_ATT_MTU, CFG_BLE_NUM_LINK)) ++// #define CFG_BLE_MBLOCK_COUNT (BLE_MBLOCKS_CALC(CFG_BLE_PREPARE_WRITE_LIST_SIZE, CFG_BLE_MAX_ATT_MTU, CFG_BLE_NUM_LINK)) ++#define CFG_BLE_MBLOCK_COUNT (0x79) + + /** + * Enable or disable the Extended Packet length feature. Valid values are 0 or 1. +@@ -236,7 +179,7 @@ + * 0: LE Power Class 2-3 + * other bits: reserved (shall be set to 0) + */ +-#define CFG_BLE_OPTIONS (SHCI_C2_BLE_INIT_OPTIONS_LL_HOST | SHCI_C2_BLE_INIT_OPTIONS_WITH_SVC_CHANGE_DESC | SHCI_C2_BLE_INIT_OPTIONS_DEVICE_NAME_RW | SHCI_C2_BLE_INIT_OPTIONS_NO_EXT_ADV | SHCI_C2_BLE_INIT_OPTIONS_NO_CS_ALGO2 | SHCI_C2_BLE_INIT_OPTIONS_POWER_CLASS_2_3) ++#define CFG_BLE_OPTIONS (SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY) + + #define CFG_BLE_MAX_COC_INITIATOR_NBR (32) + +@@ -256,334 +199,5 @@ + + #define CFG_BLE_RX_MODEL_CONFIG SHCI_C2_BLE_INIT_RX_MODEL_AGC_RSSI_LEGACY + +-/****************************************************************************** +- * Transport Layer +- ******************************************************************************/ +-/** +- * Queue length of BLE Event +- * This parameter defines the number of asynchronous events that can be stored in the HCI layer before +- * being reported to the application. When a command is sent to the BLE core coprocessor, the HCI layer +- * is waiting for the event with the Num_HCI_Command_Packets set to 1. The receive queue shall be large +- * enough to store all asynchronous events received in between. +- * When CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE is set to 27, this allow to store three 255 bytes long asynchronous events +- * between the HCI command and its event. +- * This parameter depends on the value given to CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE. When the queue size is to small, +- * the system may hang if the queue is full with asynchronous events and the HCI layer is still waiting +- * for a CC/CS event, In that case, the notification TL_BLE_HCI_ToNot() is called to indicate +- * to the application a HCI command did not receive its command event within 30s (Default HCI Timeout). +- */ +-#define CFG_TLBLE_EVT_QUEUE_LENGTH 5 +-/** +- * This parameter should be set to fit most events received by the HCI layer. It defines the buffer size of each element +- * allocated in the queue of received events and can be used to optimize the amount of RAM allocated by the Memory Manager. +- * It should not exceed 255 which is the maximum HCI packet payload size (a greater value is a lost of memory as it will +- * never be used) +- * It shall be at least 4 to receive the command status event in one frame. +- * The default value is set to 27 to allow receiving an event of MTU size in a single buffer. This value maybe reduced +- * further depending on the application. +- */ +-#define CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE 255 /**< Set to 255 with the memory manager and the mailbox */ +- +-#define TL_BLE_EVENT_FRAME_SIZE ( TL_EVT_HDR_SIZE + CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE ) +-/****************************************************************************** +- * UART interfaces +- ******************************************************************************/ +- +-/** +- * Select UART interfaces +- */ +-#define CFG_UART_GUI hw_uart1 +-#define CFG_DEBUG_TRACE_UART 0 +-/****************************************************************************** +- * USB interface +- ******************************************************************************/ +- +-/** +- * Enable/Disable USB interface +- */ +-#define CFG_USB_INTERFACE_ENABLE 0 +- +-/****************************************************************************** +- * IPCC interface +- ******************************************************************************/ +- +-/** +- * The IPCC is dedicated to the communication between the CPU2 and the CPU1 +- * and shall not be modified by the application +- * The two following definitions shall not be modified +- */ +-#define HAL_IPCC_TX_IRQHandler(...) HW_IPCC_Tx_Handler( ) +-#define HAL_IPCC_RX_IRQHandler(...) HW_IPCC_Rx_Handler( ) +- +-/****************************************************************************** +- * Low Power +- ******************************************************************************/ +-/** +- * When set to 1, the low power mode is enable +- * When set to 0, the device stays in RUN mode +- */ +-#define CFG_LPM_SUPPORTED 1 +- +-/****************************************************************************** +- * RTC interface +- ******************************************************************************/ +-#define HAL_RTCEx_WakeUpTimerIRQHandler(...) HW_TS_RTC_Wakeup_Handler( ) +- +-/****************************************************************************** +- * Timer Server +- ******************************************************************************/ +-/** +- * CFG_RTC_WUCKSEL_DIVIDER: This sets the RTCCLK divider to the wakeup timer. +- * The lower is the value, the better is the power consumption and the accuracy of the timerserver +- * The higher is the value, the finest is the granularity +- * +- * CFG_RTC_ASYNCH_PRESCALER: This sets the asynchronous prescaler of the RTC. It should as high as possible ( to output +- * clock as low as possible) but the output clock should be equal or higher frequency compare to the clock feeding +- * the wakeup timer. A lower clock speed would impact the accuracy of the timer server. +- * +- * CFG_RTC_SYNCH_PRESCALER: This sets the synchronous prescaler of the RTC. +- * When the 1Hz calendar clock is required, it shall be sets according to other settings +- * When the 1Hz calendar clock is not needed, CFG_RTC_SYNCH_PRESCALER should be set to 0x7FFF (MAX VALUE) +- * +- * CFG_RTCCLK_DIVIDER_CONF: +- * Shall be set to either 0,2,4,8,16 +- * When set to either 2,4,8,16, the 1Hhz calendar is supported +- * When set to 0, the user sets its own configuration +- * +- * The following settings are computed with LSI as input to the RTC +- */ +- +-#define CFG_RTCCLK_DIVIDER_CONF 0 +- +-#if (CFG_RTCCLK_DIVIDER_CONF == 0) +-/** +- * Custom configuration +- * It does not support 1Hz calendar +- * It divides the RTC CLK by 16 +- */ +- +-#define CFG_RTCCLK_DIV (16) +-#define CFG_RTC_WUCKSEL_DIVIDER (0) +-#define CFG_RTC_ASYNCH_PRESCALER (0x0F) +-#define CFG_RTC_SYNCH_PRESCALER (0x7FFF) +- +-#else +- +-#if (CFG_RTCCLK_DIVIDER_CONF == 2) +-/** +- * It divides the RTC CLK by 2 +- */ +-#define CFG_RTC_WUCKSEL_DIVIDER (3) +-#endif +- +-#if (CFG_RTCCLK_DIVIDER_CONF == 4) +-/** +- * It divides the RTC CLK by 4 +- */ +-#define CFG_RTC_WUCKSEL_DIVIDER (2) +-#endif +- +-#if (CFG_RTCCLK_DIVIDER_CONF == 8) +-/** +- * It divides the RTC CLK by 8 +- */ +-#define CFG_RTC_WUCKSEL_DIVIDER (1) +-#endif +- +-#if (CFG_RTCCLK_DIVIDER_CONF == 16) +-/** +- * It divides the RTC CLK by 16 +- */ +-#define CFG_RTC_WUCKSEL_DIVIDER (0) +-#endif +- +-#define CFG_RTCCLK_DIV CFG_RTCCLK_DIVIDER_CONF +-#define CFG_RTC_ASYNCH_PRESCALER (CFG_RTCCLK_DIV - 1) +-#define CFG_RTC_SYNCH_PRESCALER (DIVR( LSE_VALUE, (CFG_RTC_ASYNCH_PRESCALER+1) ) - 1 ) +- +-#endif +- +-/** tick timer values */ +-#define CFG_TS_TICK_VAL DIVR( (CFG_RTCCLK_DIV * 1000000), LSE_VALUE ) +-#define CFG_TS_TICK_VAL_PS DIVR( ((uint64_t)CFG_RTCCLK_DIV * 1e12), (uint64_t)LSE_VALUE ) +- +-typedef enum +-{ +- CFG_TIM_PROC_ID_ISR, +- /* USER CODE BEGIN CFG_TimProcID_t */ +- +- /* USER CODE END CFG_TimProcID_t */ +-} CFG_TimProcID_t; +- +-/****************************************************************************** +- * Debug +- ******************************************************************************/ +-/** +- * When set, this resets some hw resources to set the device in the same state than the power up +- * The FW resets only register that may prevent the FW to run properly +- * +- * This shall be set to 0 in a final product +- * +- */ +-#define CFG_HW_RESET_BY_FW 1 +- +-/** +- * keep debugger enabled while in any low power mode when set to 1 +- * should be set to 0 in production +- */ +-#define CFG_DEBUGGER_SUPPORTED 0 +- +-/** +- * When set to 1, the traces are enabled in the BLE services +- */ +-#define CFG_DEBUG_BLE_TRACE 0 +- +-/** +- * Enable or Disable traces in application +- */ +-#define CFG_DEBUG_APP_TRACE 0 +- +-#if (CFG_DEBUG_APP_TRACE != 0) +-#define APP_DBG_MSG PRINT_MESG_DBG +-#else +-#define APP_DBG_MSG PRINT_NO_MESG +-#endif +- +-#if ( (CFG_DEBUG_BLE_TRACE != 0) || (CFG_DEBUG_APP_TRACE != 0) ) +-#define CFG_DEBUG_TRACE 1 +-#endif +- +-#if (CFG_DEBUG_TRACE != 0) +-#undef CFG_LPM_SUPPORTED +-#undef CFG_DEBUGGER_SUPPORTED +-#define CFG_LPM_SUPPORTED 0 +-#define CFG_DEBUGGER_SUPPORTED 1 +-#endif +- +-/** +- * When CFG_DEBUG_TRACE_FULL is set to 1, the trace are output with the API name, the file name and the line number +- * When CFG_DEBUG_TRACE_LIGHT is set to 1, only the debug message is output +- * +- * When both are set to 0, no trace are output +- * When both are set to 1, CFG_DEBUG_TRACE_FULL is selected +- */ +-#define CFG_DEBUG_TRACE_LIGHT 0 +-#define CFG_DEBUG_TRACE_FULL 0 +- +-#if (( CFG_DEBUG_TRACE != 0 ) && ( CFG_DEBUG_TRACE_LIGHT == 0 ) && (CFG_DEBUG_TRACE_FULL == 0)) +-#undef CFG_DEBUG_TRACE_FULL +-#undef CFG_DEBUG_TRACE_LIGHT +-#define CFG_DEBUG_TRACE_FULL 0 +-#define CFG_DEBUG_TRACE_LIGHT 1 +-#endif +- +-#if ( CFG_DEBUG_TRACE == 0 ) +-#undef CFG_DEBUG_TRACE_FULL +-#undef CFG_DEBUG_TRACE_LIGHT +-#define CFG_DEBUG_TRACE_FULL 0 +-#define CFG_DEBUG_TRACE_LIGHT 0 +-#endif +- +-/** +- * When not set, the traces is looping on sending the trace over UART +- */ +-#define DBG_TRACE_USE_CIRCULAR_QUEUE 1 +- +-/** +- * max buffer Size to queue data traces and max data trace allowed. +- * Only Used if DBG_TRACE_USE_CIRCULAR_QUEUE is defined +- */ +-#define DBG_TRACE_MSG_QUEUE_SIZE 4096 +-#define MAX_DBG_TRACE_MSG_SIZE 1024 +- +-/* USER CODE BEGIN Defines */ +-#define CFG_LED_SUPPORTED 1 +-#define CFG_BUTTON_SUPPORTED 1 +- +-#define PUSH_BUTTON_SW1_EXTI_IRQHandler EXTI4_IRQHandler +-#define PUSH_BUTTON_SW2_EXTI_IRQHandler EXTI0_IRQHandler +-#define PUSH_BUTTON_SW3_EXTI_IRQHandler EXTI1_IRQHandler +-/* USER CODE END Defines */ +- +-/****************************************************************************** +- * Scheduler +- ******************************************************************************/ +- +-/** +- * These are the lists of task id registered to the scheduler +- * Each task id shall be in the range [0:31] +- * This mechanism allows to implement a generic code in the API TL_BLE_HCI_StatusNot() to comply with +- * the requirement that a HCI/ACI command shall never be sent if there is already one pending +- */ +- +-/**< Add in that list all tasks that may send a ACI/HCI command */ +-typedef enum +-{ +- CFG_TASK_BLE_HCI_CMD_ID, +- CFG_TASK_SYS_HCI_CMD_ID, +- CFG_TASK_HCI_ACL_DATA_ID, +- CFG_TASK_SYS_LOCAL_CMD_ID, +- CFG_TASK_TX_TO_HOST_ID, +- /* USER CODE BEGIN CFG_Task_Id_With_HCI_Cmd_t */ +- CFG_TASK_SW1_BUTTON_PUSHED_ID, +- CFG_TASK_SW2_BUTTON_PUSHED_ID, +- CFG_TASK_SW3_BUTTON_PUSHED_ID, +- /* USER CODE END CFG_Task_Id_With_HCI_Cmd_t */ +- CFG_LAST_TASK_ID_WITH_HCICMD, /**< Shall be LAST in the list */ +-} CFG_Task_Id_With_HCI_Cmd_t; +- +-/**< Add in that list all tasks that never send a ACI/HCI command */ +-typedef enum +-{ +- CFG_FIRST_TASK_ID_WITH_NO_HCICMD = CFG_LAST_TASK_ID_WITH_HCICMD - 1, /**< Shall be FIRST in the list */ +- CFG_TASK_SYSTEM_HCI_ASYNCH_EVT_ID, +- /* USER CODE BEGIN CFG_Task_Id_With_NO_HCI_Cmd_t */ +- +- /* USER CODE END CFG_Task_Id_With_NO_HCI_Cmd_t */ +- CFG_LAST_TASK_ID_WITHO_NO_HCICMD /**< Shall be LAST in the list */ +-} CFG_Task_Id_With_NO_HCI_Cmd_t; +- +-#define CFG_TASK_NBR CFG_LAST_TASK_ID_WITHO_NO_HCICMD +- +-/** +- * This is the list of priority required by the application +- * Each Id shall be in the range 0..31 +- */ +-typedef enum +-{ +- CFG_SCH_PRIO_0, +- CFG_PRIO_NBR, +-} CFG_SCH_Prio_Id_t; +- +-/** +- * This is a bit mapping over 32bits listing all events id supported in the application +- */ +-typedef enum +-{ +- CFG_IDLEEVT_SYSTEM_HCI_CMD_EVT_RSP_ID, +-} CFG_IdleEvt_Id_t; +- +-/****************************************************************************** +- * LOW POWER +- ******************************************************************************/ +-/** +- * Supported requester to the MCU Low Power Manager - can be increased up to 32 +- * It list a bit mapping of all user of the Low Power Manager +- */ +-typedef enum +-{ +- CFG_LPM_APP, +- CFG_LPM_APP_BLE, +- /* USER CODE BEGIN CFG_LPM_Id_t */ +- +- /* USER CODE END CFG_LPM_Id_t */ +-} CFG_LPM_Id_t; +- +-/****************************************************************************** +- * OTP manager +- ******************************************************************************/ +-#define CFG_OTP_BASE_ADDRESS OTP_AREA_BASE +- +-#define CFG_OTP_END_ADRESS OTP_AREA_END_ADDR + + #endif /*APP_CONF_H */ +diff --git a/src/utility/STM32Cube_FW/ble_bufsize.h b/src/utility/STM32Cube_FW/ble_bufsize.h +index ba9c4d3..73b7887 100644 +--- a/src/utility/STM32Cube_FW/ble_bufsize.h ++++ b/src/utility/STM32Cube_FW/ble_bufsize.h +@@ -75,17 +75,24 @@ + ((pw) + MAX(BLE_MEM_BLOCK_X_MTU(mtu, n_link), \ + BLE_MBLOCKS_SECURE_CONNECTIONS)) + ++/* ++ * BLE_DEFAULT_MBLOCKS_COUNT: default memory blocks count ++ */ ++#define BLE_DEFAULT_MBLOCKS_COUNT(n_link) \ ++ BLE_MBLOCKS_CALC(BLE_DEFAULT_PREP_WRITE_LIST_SIZE, \ ++ BLE_DEFAULT_MAX_ATT_MTU, n_link) ++ + /* + * BLE_FIXED_BUFFER_SIZE_BYTES: +- * A part of the RAM, is dinamically allocated by initilizing all the pointers ++ * A part of the RAM, is dynamically allocated by initializing all the pointers + * defined in a global context variable "mem_alloc_ctx_p". + * This initialization is made in the Dynamic_allocator functions, which +- * assing a portion of RAM given by the external application to the above ++ * assign a portion of RAM given by the external application to the above + * mentioned "global pointers". + * + * The size of this Dynamic RAM is made of 2 main components: + * - a part that is parameters-dependent (num of links, GATT buffers, ...), +- * and which value is explicited by the following macro; ++ * and which value is defined by the following macro; + * - a part, that may be considered "fixed", i.e. independent from the above + * mentioned parameters. + */ +diff --git a/src/utility/STM32Cube_FW/hw.h b/src/utility/STM32Cube_FW/hw.h +index 503fa2c..fcf0451 100644 +--- a/src/utility/STM32Cube_FW/hw.h ++++ b/src/utility/STM32Cube_FW/hw.h +@@ -26,14 +26,21 @@ extern "C" { + #endif + + /* Includes ------------------------------------------------------------------*/ ++#include "stm32_def.h" ++#include "stm32wbxx_ll_bus.h" ++#include "stm32wbxx_ll_exti.h" ++#include "stm32wbxx_ll_system.h" ++#include "stm32wbxx_ll_rcc.h" ++#include "stm32wbxx_ll_ipcc.h" ++#include "stm32wbxx_ll_cortex.h" ++#include "stm32wbxx_ll_utils.h" ++#include "stm32wbxx_ll_pwr.h" + + /****************************************************************************** + * HW IPCC + ******************************************************************************/ + void HW_IPCC_Enable( void ); + void HW_IPCC_Init( void ); +- void HW_IPCC_Rx_Handler( void ); +- void HW_IPCC_Tx_Handler( void ); + + void HW_IPCC_BLE_Init( void ); + void HW_IPCC_BLE_SendCmd( void ); +@@ -80,23 +87,6 @@ extern "C" { + void HW_IPCC_TRACES_Init( void ); + void HW_IPCC_TRACES_EvtNot( void ); + +- void HW_IPCC_MAC_802_15_4_Init( void ); +- void HW_IPCC_MAC_802_15_4_SendCmd( void ); +- void HW_IPCC_MAC_802_15_4_SendAck( void ); +- void HW_IPCC_MAC_802_15_4_CmdEvtNot( void ); +- void HW_IPCC_MAC_802_15_4_EvtNot( void ); +- +- void HW_IPCC_ZIGBEE_Init( void ); +- +- void HW_IPCC_ZIGBEE_SendM4RequestToM0(void); /* M4 Request to M0 */ +- void HW_IPCC_ZIGBEE_RecvAppliAckFromM0(void); /* Request ACK from M0 */ +- +- void HW_IPCC_ZIGBEE_RecvM0NotifyToM4(void); /* M0 Notify to M4 */ +- void HW_IPCC_ZIGBEE_SendM4AckToM0Notify(void); /* Notify ACK from M4 */ +- void HW_IPCC_ZIGBEE_RecvM0RequestToM4(void); /* M0 Request to M4 */ +- void HW_IPCC_ZIGBEE_SendM4AckToM0Request(void); /* Request ACK from M4 */ +- +- + #ifdef __cplusplus + } + #endif +diff --git a/src/utility/STM32Cube_FW/hw_ipcc.c b/src/utility/STM32Cube_FW/hw_ipcc.c +index c5a941d..2f4f6cc 100644 +--- a/src/utility/STM32Cube_FW/hw_ipcc.c ++++ b/src/utility/STM32Cube_FW/hw_ipcc.c +@@ -18,8 +18,9 @@ + */ + /* USER CODE END Header */ + ++#if defined(STM32WBxx) + /* Includes ------------------------------------------------------------------*/ +-#include "app_common.h" ++#include "hw.h" + #include "mbox_def.h" + + /* Global variables ---------------------------------------------------------*/ +@@ -56,34 +57,17 @@ static void HW_IPCC_LLD_BLE_ReceiveRspHandler( void ); + static void HW_IPCC_LLD_BLE_ReceiveM0CmdHandler( void ); + #endif + +-#ifdef MAC_802_15_4_WB +-static void HW_IPCC_MAC_802_15_4_CmdEvtHandler( void ); +-static void HW_IPCC_MAC_802_15_4_NotEvtHandler( void ); +-#endif +- +-#ifdef ZIGBEE_WB +-static void HW_IPCC_ZIGBEE_CmdEvtHandler( void ); +-static void HW_IPCC_ZIGBEE_StackNotifEvtHandler( void ); +-static void HW_IPCC_ZIGBEE_StackM0RequestHandler( void ); +-#endif +- + /* Public function definition -----------------------------------------------*/ + + /****************************************************************************** + * INTERRUPT HANDLER + ******************************************************************************/ +-void HW_IPCC_Rx_Handler( void ) ++void IPCC_C1_RX_IRQHandler(void) + { + if (HW_IPCC_RX_PENDING( HW_IPCC_SYSTEM_EVENT_CHANNEL )) + { + HW_IPCC_SYS_EvtHandler(); + } +-#ifdef MAC_802_15_4_WB +- else if (HW_IPCC_RX_PENDING( HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL )) +- { +- HW_IPCC_MAC_802_15_4_NotEvtHandler(); +- } +-#endif /* MAC_802_15_4_WB */ + #ifdef THREAD_WB + else if (HW_IPCC_RX_PENDING( HW_IPCC_THREAD_NOTIFICATION_ACK_CHANNEL )) + { +@@ -114,16 +98,6 @@ void HW_IPCC_Rx_Handler( void ) + HW_IPCC_LLD_BLE_ReceiveM0CmdHandler(); + } + #endif /* LLD_TESTS_WB */ +-#ifdef ZIGBEE_WB +- else if (HW_IPCC_RX_PENDING( HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL )) +- { +- HW_IPCC_ZIGBEE_StackNotifEvtHandler(); +- } +- else if (HW_IPCC_RX_PENDING( HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL )) +- { +- HW_IPCC_ZIGBEE_StackM0RequestHandler(); +- } +-#endif /* ZIGBEE_WB */ + else if (HW_IPCC_RX_PENDING( HW_IPCC_BLE_EVENT_CHANNEL )) + { + HW_IPCC_BLE_EvtHandler(); +@@ -132,22 +106,14 @@ void HW_IPCC_Rx_Handler( void ) + { + HW_IPCC_TRACES_EvtHandler(); + } +- +- return; + } + +-void HW_IPCC_Tx_Handler( void ) ++void IPCC_C1_TX_IRQHandler(void) + { + if (HW_IPCC_TX_PENDING( HW_IPCC_SYSTEM_CMD_RSP_CHANNEL )) + { + HW_IPCC_SYS_CmdEvtHandler(); + } +-#ifdef MAC_802_15_4_WB +- else if (HW_IPCC_TX_PENDING( HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL )) +- { +- HW_IPCC_MAC_802_15_4_CmdEvtHandler(); +- } +-#endif /* MAC_802_15_4_WB */ + #ifdef THREAD_WB + else if (HW_IPCC_TX_PENDING( HW_IPCC_THREAD_OT_CMD_RSP_CHANNEL )) + { +@@ -157,12 +123,6 @@ void HW_IPCC_Tx_Handler( void ) + #ifdef LLD_TESTS_WB + // No TX handler for LLD tests + #endif /* LLD_TESTS_WB */ +-#ifdef ZIGBEE_WB +- if (HW_IPCC_TX_PENDING( HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL )) +- { +- HW_IPCC_ZIGBEE_CmdEvtHandler(); +- } +-#endif /* ZIGBEE_WB */ + else if (HW_IPCC_TX_PENDING( HW_IPCC_MM_RELEASE_BUFFER_CHANNEL )) + { + HW_IPCC_MM_FreeBufHandler(); +@@ -171,9 +131,8 @@ void HW_IPCC_Tx_Handler( void ) + { + HW_IPCC_BLE_AclDataEvtHandler(); + } +- +- return; + } ++ + /****************************************************************************** + * GENERAL + ******************************************************************************/ +@@ -263,8 +222,8 @@ static void HW_IPCC_BLE_AclDataEvtHandler( void ) + return; + } + +-__weak void HW_IPCC_BLE_AclDataAckNot( void ){}; +-__weak void HW_IPCC_BLE_RxEvtNot( void ){}; ++__WEAK void HW_IPCC_BLE_AclDataAckNot( void ){}; ++__WEAK void HW_IPCC_BLE_RxEvtNot( void ){}; + + /****************************************************************************** + * SYSTEM +@@ -302,56 +261,8 @@ static void HW_IPCC_SYS_EvtHandler( void ) + return; + } + +-__weak void HW_IPCC_SYS_CmdEvtNot( void ){}; +-__weak void HW_IPCC_SYS_EvtNot( void ){}; +- +-/****************************************************************************** +- * MAC 802.15.4 +- ******************************************************************************/ +-#ifdef MAC_802_15_4_WB +-void HW_IPCC_MAC_802_15_4_Init( void ) +-{ +- LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL ); +- +- return; +-} +- +-void HW_IPCC_MAC_802_15_4_SendCmd( void ) +-{ +- LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL ); +- LL_C1_IPCC_EnableTransmitChannel( IPCC, HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL ); +- +- return; +-} +- +-void HW_IPCC_MAC_802_15_4_SendAck( void ) +-{ +- LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL ); +- LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL ); +- +- return; +-} +- +-static void HW_IPCC_MAC_802_15_4_CmdEvtHandler( void ) +-{ +- LL_C1_IPCC_DisableTransmitChannel( IPCC, HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL ); +- +- HW_IPCC_MAC_802_15_4_CmdEvtNot(); +- +- return; +-} +- +-static void HW_IPCC_MAC_802_15_4_NotEvtHandler( void ) +-{ +- LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL ); +- +- HW_IPCC_MAC_802_15_4_EvtNot(); +- +- return; +-} +-__weak void HW_IPCC_MAC_802_15_4_CmdEvtNot( void ){}; +-__weak void HW_IPCC_MAC_802_15_4_EvtNot( void ){}; +-#endif ++__WEAK void HW_IPCC_SYS_CmdEvtNot( void ){}; ++__WEAK void HW_IPCC_SYS_EvtNot( void ){}; + + /****************************************************************************** + * THREAD +@@ -423,9 +334,9 @@ static void HW_IPCC_THREAD_CliNotEvtHandler( void ) + return; + } + +-__weak void HW_IPCC_OT_CmdEvtNot( void ){}; +-__weak void HW_IPCC_CLI_CmdEvtNot( void ){}; +-__weak void HW_IPCC_THREAD_EvtNot( void ){}; ++__WEAK void HW_IPCC_OT_CmdEvtNot( void ){}; ++__WEAK void HW_IPCC_CLI_CmdEvtNot( void ){}; ++__WEAK void HW_IPCC_THREAD_EvtNot( void ){}; + + #endif /* THREAD_WB */ + +@@ -547,74 +458,6 @@ void HW_IPCC_LLD_BLE_SendRspAck( void ) + + #endif /* LLD_BLE_WB */ + +-/****************************************************************************** +- * ZIGBEE +- ******************************************************************************/ +-#ifdef ZIGBEE_WB +-void HW_IPCC_ZIGBEE_Init( void ) +-{ +- LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL ); +- LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL ); +- +- return; +-} +- +-void HW_IPCC_ZIGBEE_SendM4RequestToM0( void ) +-{ +- LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL ); +- LL_C1_IPCC_EnableTransmitChannel( IPCC, HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL ); +- +- return; +-} +- +-void HW_IPCC_ZIGBEE_SendM4AckToM0Notify( void ) +-{ +- LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL ); +- LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL ); +- +- return; +-} +- +-static void HW_IPCC_ZIGBEE_CmdEvtHandler( void ) +-{ +- LL_C1_IPCC_DisableTransmitChannel( IPCC, HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL ); +- +- HW_IPCC_ZIGBEE_RecvAppliAckFromM0(); +- +- return; +-} +- +-static void HW_IPCC_ZIGBEE_StackNotifEvtHandler( void ) +-{ +- LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL ); +- +- HW_IPCC_ZIGBEE_RecvM0NotifyToM4(); +- +- return; +-} +- +-static void HW_IPCC_ZIGBEE_StackM0RequestHandler( void ) +-{ +- LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL ); +- +- HW_IPCC_ZIGBEE_RecvM0RequestToM4(); +- +- return; +-} +- +-void HW_IPCC_ZIGBEE_SendM4AckToM0Request( void ) +-{ +- LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL ); +- LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL ); +- +- return; +-} +- +-__weak void HW_IPCC_ZIGBEE_RecvAppliAckFromM0( void ){}; +-__weak void HW_IPCC_ZIGBEE_RecvM0NotifyToM4( void ){}; +-__weak void HW_IPCC_ZIGBEE_RecvM0RequestToM4( void ){}; +-#endif /* ZIGBEE_WB */ +- + /****************************************************************************** + * MEMORY MANAGER + ******************************************************************************/ +@@ -665,4 +508,5 @@ static void HW_IPCC_TRACES_EvtHandler( void ) + return; + } + +-__weak void HW_IPCC_TRACES_EvtNot( void ){}; ++__WEAK void HW_IPCC_TRACES_EvtNot( void ){}; ++#endif /* STM32WBxx */ +diff --git a/src/utility/STM32Cube_FW/mbox_def.h b/src/utility/STM32Cube_FW/mbox_def.h +index 06536d3..c898e52 100644 +--- a/src/utility/STM32Cube_FW/mbox_def.h ++++ b/src/utility/STM32Cube_FW/mbox_def.h +@@ -105,12 +105,6 @@ extern "C" { + uint8_t *m0cmd_buffer; + } MB_BleLldTable_t; + +- typedef struct +- { +- uint8_t *notifM0toM4_buffer; +- uint8_t *appliCmdM4toM0_buffer; +- uint8_t *requestM0toM4_buffer; +- } MB_ZigbeeTable_t; + /** + * msg + * [0:7] = cmd/evt +@@ -138,13 +132,6 @@ extern "C" { + uint8_t *traces_queue; + } MB_TracesTable_t; + +- typedef struct +- { +- uint8_t *p_cmdrsp_buffer; +- uint8_t *p_notack_buffer; +- uint8_t *evt_queue; +- } MB_Mac_802_15_4_t; +- + typedef struct + { + MB_DeviceInfoTable_t *p_device_info_table; +@@ -153,8 +140,6 @@ extern "C" { + MB_SysTable_t *p_sys_table; + MB_MemManagerTable_t *p_mem_manager_table; + MB_TracesTable_t *p_traces_table; +- MB_Mac_802_15_4_t *p_mac_802_15_4_table; +- MB_ZigbeeTable_t *p_zigbee_table; + MB_LldTestsTable_t *p_lld_tests_table; + MB_BleLldTable_t *p_ble_lld_table; + } MB_RefTable_t; +@@ -198,15 +183,6 @@ typedef struct + * | | + * |<---HW_IPCC_SYSTEM_EVENT_CHANNEL-----------------| + * | | +- * | (ZIGBEE) | +- * |----HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL------------>| +- * | | +- * |----HW_IPCC_ZIGBEE_CMD_CLI_CHANNEL-------------->| +- * | | +- * |<---HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL-------| +- * | | +- * |<---HW_IPCC_ZIGBEE_CLI_NOTIF_ACK_CHANNEL---------| +- * | | + * | (THREAD) | + * |----HW_IPCC_THREAD_OT_CMD_RSP_CHANNEL----------->| + * | | +@@ -230,11 +206,6 @@ typedef struct + * | | + * |<---HW_IPCC_BLE_LLD_M0_CMD_CHANNEL---------------| + * | | +- * | (MAC) | +- * |----HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL-------->| +- * | | +- * |<---HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL| +- * | | + * | (BUFFER) | + * |----HW_IPCC_MM_RELEASE_BUFFER_CHANNE------------>| + * | | +@@ -252,8 +223,6 @@ typedef struct + #define HW_IPCC_BLE_CMD_CHANNEL LL_IPCC_CHANNEL_1 + #define HW_IPCC_SYSTEM_CMD_RSP_CHANNEL LL_IPCC_CHANNEL_2 + #define HW_IPCC_THREAD_OT_CMD_RSP_CHANNEL LL_IPCC_CHANNEL_3 +-#define HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL LL_IPCC_CHANNEL_3 +-#define HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL LL_IPCC_CHANNEL_3 + #define HW_IPCC_MM_RELEASE_BUFFER_CHANNEL LL_IPCC_CHANNEL_4 + #define HW_IPCC_THREAD_CLI_CMD_CHANNEL LL_IPCC_CHANNEL_5 + #define HW_IPCC_LLDTESTS_CLI_CMD_CHANNEL LL_IPCC_CHANNEL_5 +@@ -265,8 +234,6 @@ typedef struct + #define HW_IPCC_BLE_EVENT_CHANNEL LL_IPCC_CHANNEL_1 + #define HW_IPCC_SYSTEM_EVENT_CHANNEL LL_IPCC_CHANNEL_2 + #define HW_IPCC_THREAD_NOTIFICATION_ACK_CHANNEL LL_IPCC_CHANNEL_3 +-#define HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL LL_IPCC_CHANNEL_3 +-#define HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL LL_IPCC_CHANNEL_3 + #define HW_IPCC_LLDTESTS_M0_CMD_CHANNEL LL_IPCC_CHANNEL_3 + #define HW_IPCC_BLE_LLD_M0_CMD_CHANNEL LL_IPCC_CHANNEL_3 + #define HW_IPCC_TRACES_CHANNEL LL_IPCC_CHANNEL_4 +@@ -274,6 +241,5 @@ typedef struct + #define HW_IPCC_LLDTESTS_CLI_RSP_CHANNEL LL_IPCC_CHANNEL_5 + #define HW_IPCC_BLE_LLD_CLI_RSP_CHANNEL LL_IPCC_CHANNEL_5 + #define HW_IPCC_BLE_LLD_RSP_CHANNEL LL_IPCC_CHANNEL_5 +-#define HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL LL_IPCC_CHANNEL_5 + #endif /*__MBOX_H */ + +diff --git a/src/utility/STM32Cube_FW/shci.c b/src/utility/STM32Cube_FW/shci.c +index 301db76..bd7bb3a 100644 +--- a/src/utility/STM32Cube_FW/shci.c ++++ b/src/utility/STM32Cube_FW/shci.c +@@ -16,7 +16,7 @@ + ****************************************************************************** + */ + +- ++#if defined(STM32WBxx) + /* Includes ------------------------------------------------------------------*/ + #include "stm32_wpan_common.h" + +@@ -352,24 +352,6 @@ SHCI_CmdStatus_t SHCI_C2_BLE_LLD_Init( uint8_t param_size, uint8_t * p_param ) + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); + } + +-SHCI_CmdStatus_t SHCI_C2_ZIGBEE_Init( void ) +-{ +- /** +- * Buffer is large enough to hold command complete without payload +- */ +- uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; +- TL_EvtPacket_t * p_rsp; +- +- p_rsp = (TL_EvtPacket_t *)local_buffer; +- +- shci_send( SHCI_OPCODE_C2_ZIGBEE_INIT, +- 0, +- 0, +- p_rsp ); +- +- return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +-} +- + SHCI_CmdStatus_t SHCI_C2_DEBUG_Init( SHCI_C2_DEBUG_Init_Cmd_Packet_t *pCmdPacket ) + { + /** +@@ -527,24 +509,6 @@ SHCI_CmdStatus_t SHCI_C2_RADIO_AllowLowPower( SHCI_C2_FLASH_Ip_t Ip,uint8_t Fla + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); + } + +-SHCI_CmdStatus_t SHCI_C2_MAC_802_15_4_Init( void ) +-{ +- /** +- * Buffer is large enough to hold command complete without payload +- */ +- uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; +- TL_EvtPacket_t * p_rsp; +- +- p_rsp = (TL_EvtPacket_t *)local_buffer; +- +- shci_send( SHCI_OPCODE_C2_MAC_802_15_4_INIT, +- 0, +- 0, +- p_rsp ); +- +- return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +-} +- + SHCI_CmdStatus_t SHCI_C2_Reinit( void ) + { + /** +@@ -739,3 +703,5 @@ SHCI_CmdStatus_t SHCI_GetWirelessFwInfo( WirelessFwInfo_t* pWirelessInfo ) + + return (SHCI_Success); + } ++#endif /* STM32WBxx */ ++ +diff --git a/src/utility/STM32Cube_FW/shci.h b/src/utility/STM32Cube_FW/shci.h +index c08f056..9449c22 100644 +--- a/src/utility/STM32Cube_FW/shci.h ++++ b/src/utility/STM32Cube_FW/shci.h +@@ -49,7 +49,6 @@ extern "C" { + ERR_BLE_INIT = 0, /* This event is currently not reported by the CPU2 */ + ERR_THREAD_LLD_FATAL_ERROR = 125, /* The LLD driver used on 802_15_4 detected a fatal error */ + ERR_THREAD_UNKNOWN_CMD = 126, /* The command send by the CPU1 to control the Thread stack is unknown */ +- ERR_ZIGBEE_UNKNOWN_CMD = 200, /* The command send by the CPU1 to control the Zigbee stack is unknown */ + } SCHI_SystemErrCode_t; + + #define SHCI_EVTCODE ( 0xFF ) +@@ -102,7 +101,7 @@ extern "C" { + + /** + * SHCI_SUB_EVT_THREAD_NVM_RAM_UPDATE +- * This notifies the CPU1 which part of the OT NVM RAM has been updated so that only the modified ++ * This notifies the CPU1 which part of the 'OT NVM RAM' has been updated so that only the modified + * section could be written in Flash/NVM + * StartAddress : Start address of the section that has been modified + * Size : Size (in bytes) of the section that has been modified +@@ -214,9 +213,7 @@ extern "C" { + SHCI_OCF_C2_FLASH_STORE_DATA, + SHCI_OCF_C2_FLASH_ERASE_DATA, + SHCI_OCF_C2_RADIO_ALLOW_LOW_POWER, +- SHCI_OCF_C2_MAC_802_15_4_INIT, + SHCI_OCF_C2_REINIT, +- SHCI_OCF_C2_ZIGBEE_INIT, + SHCI_OCF_C2_LLD_TESTS_INIT, + SHCI_OCF_C2_EXTPA_CONFIG, + SHCI_OCF_C2_SET_FLASH_ACTIVITY_CONTROL, +@@ -614,8 +611,6 @@ extern "C" { + { + uint8_t thread_config; + uint8_t ble_config; +- uint8_t mac_802_15_4_config; +- uint8_t zigbee_config; + } SHCI_C2_DEBUG_TracesConfig_t; + + typedef PACKED_STRUCT +@@ -674,8 +669,6 @@ extern "C" { + { + BLE_ENABLE, + THREAD_ENABLE, +- ZIGBEE_ENABLE, +- MAC_ENABLE, + } SHCI_C2_CONCURRENT_Mode_Param_t; + /** No response parameters*/ + +@@ -698,18 +691,13 @@ extern "C" { + { + BLE_IP, + THREAD_IP, +- ZIGBEE_IP, + } SHCI_C2_FLASH_Ip_t; + /** No response parameters*/ + + #define SHCI_OPCODE_C2_RADIO_ALLOW_LOW_POWER (( SHCI_OGF << 10) + SHCI_OCF_C2_RADIO_ALLOW_LOW_POWER) + +-#define SHCI_OPCODE_C2_MAC_802_15_4_INIT (( SHCI_OGF << 10) + SHCI_OCF_C2_MAC_802_15_4_INIT) +- + #define SHCI_OPCODE_C2_REINIT (( SHCI_OGF << 10) + SHCI_OCF_C2_REINIT) + +-#define SHCI_OPCODE_C2_ZIGBEE_INIT (( SHCI_OGF << 10) + SHCI_OCF_C2_ZIGBEE_INIT) +- + #define SHCI_OPCODE_C2_LLD_TESTS_INIT (( SHCI_OGF << 10) + SHCI_OCF_C2_LLD_TESTS_INIT) + + #define SHCI_OPCODE_C2_BLE_LLD_INIT (( SHCI_OGF << 10) + SHCI_OCF_C2_BLE_LLD_INIT) +@@ -817,7 +805,7 @@ extern "C" { + #define FUS_DEVICE_INFO_TABLE_VALIDITY_KEYWORD (0xA94656B9) + + /* +- * At startup, the informations relative to the wireless binary are stored in RAM trough a structure defined by ++ * At startup, the information relative to the wireless binary are stored in RAM through a structure defined by + * MB_WirelessFwInfoTable_t.This structure contains 4 fields (Version,MemorySize, Stack_info and a reserved part) + * each of those coded on 32 bits as shown on the table below: + * +@@ -870,9 +858,6 @@ extern "C" { + #define INFO_STACK_TYPE_BLE_BEACON 0x04 + #define INFO_STACK_TYPE_THREAD_FTD 0x10 + #define INFO_STACK_TYPE_THREAD_MTD 0x11 +-#define INFO_STACK_TYPE_ZIGBEE_FFD 0x30 +-#define INFO_STACK_TYPE_ZIGBEE_RFD 0x31 +-#define INFO_STACK_TYPE_MAC 0x40 + #define INFO_STACK_TYPE_BLE_THREAD_FTD_STATIC 0x50 + #define INFO_STACK_TYPE_BLE_THREAD_FTD_DYAMIC 0x51 + #define INFO_STACK_TYPE_802154_LLD_TESTS 0x60 +@@ -881,12 +866,7 @@ extern "C" { + #define INFO_STACK_TYPE_BLE_LLD_TESTS 0x63 + #define INFO_STACK_TYPE_BLE_RLV 0x64 + #define INFO_STACK_TYPE_802154_RLV 0x65 +-#define INFO_STACK_TYPE_BLE_ZIGBEE_FFD_STATIC 0x70 +-#define INFO_STACK_TYPE_BLE_ZIGBEE_RFD_STATIC 0x71 +-#define INFO_STACK_TYPE_BLE_ZIGBEE_FFD_DYNAMIC 0x78 +-#define INFO_STACK_TYPE_BLE_ZIGBEE_RFD_DYNAMIC 0x79 + #define INFO_STACK_TYPE_RLV 0x80 +-#define INFO_STACK_TYPE_BLE_MAC_STATIC 0x90 + + typedef struct { + /** +@@ -1060,7 +1040,7 @@ typedef struct { + * @brief Starts the LLD tests CLI + * + * @param param_size : Nb of bytes +- * @param p_param : pointeur with data to give from M4 to M0 ++ * @param p_param : pointer with data to give from M4 to M0 + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_LLDTESTS_Init( uint8_t param_size, uint8_t * p_param ); +@@ -1070,19 +1050,10 @@ typedef struct { + * @brief Starts the LLD tests BLE + * + * @param param_size : Nb of bytes +- * @param p_param : pointeur with data to give from M4 to M0 ++ * @param p_param : pointer with data to give from M4 to M0 + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_BLE_LLD_Init( uint8_t param_size, uint8_t * p_param ); +- +- /** +- * SHCI_C2_ZIGBEE_Init +- * @brief Starts the Zigbee Stack +- * +- * @param None +- * @retval Status +- */ +- SHCI_CmdStatus_t SHCI_C2_ZIGBEE_Init( void ); + + /** + * SHCI_C2_DEBUG_Init +@@ -1158,16 +1129,6 @@ typedef struct { + */ + SHCI_CmdStatus_t SHCI_C2_RADIO_AllowLowPower( SHCI_C2_FLASH_Ip_t Ip,uint8_t FlagRadioLowPowerOn); + +- +- /** +- * SHCI_C2_MAC_802_15_4_Init +- * @brief Starts the MAC 802.15.4 on M0 +- * +- * @param None +- * @retval Status +- */ +- SHCI_CmdStatus_t SHCI_C2_MAC_802_15_4_Init( void ); +- + /** + * SHCI_GetWirelessFwInfo + * @brief This function read back the informations relative to the wireless binary loaded. +diff --git a/src/utility/STM32Cube_FW/shci_tl.c b/src/utility/STM32Cube_FW/shci_tl.c +index 449b8b1..ef403aa 100644 +--- a/src/utility/STM32Cube_FW/shci_tl.c ++++ b/src/utility/STM32Cube_FW/shci_tl.c +@@ -16,12 +16,13 @@ + ****************************************************************************** + */ + +- ++#if defined(STM32WBxx) + /* Includes ------------------------------------------------------------------*/ + #include "stm32_wpan_common.h" + + #include "stm_list.h" + #include "shci_tl.h" ++#include "stm32_def.h" + + /* Private typedef -----------------------------------------------------------*/ + typedef enum +@@ -168,6 +169,20 @@ void shci_send( uint16_t cmd_code, uint8_t len_cmd_payload, uint8_t * p_cmd_payl + return; + } + ++void shci_notify_asynch_evt(void *pdata) ++{ ++ UNUSED(pdata); ++ /* Need to parse data in future version */ ++ shci_user_evt_proc(); ++} ++ ++void shci_register_io_bus(tSHciIO *fops) ++{ ++ /* Register IO bus services */ ++ fops->Init = TL_SYS_Init; ++ fops->Send = TL_SYS_SendCmd; ++} ++ + /* Private functions ---------------------------------------------------------*/ + static void TlInit( TL_CmdPacket_t * p_cmdbuffer ) + { +@@ -252,3 +267,5 @@ __WEAK void shci_cmd_resp_release(uint32_t flag) + return; + } + ++#endif /* STM32WBxx */ ++ +diff --git a/src/utility/STM32Cube_FW/stm32_wpan_common.h b/src/utility/STM32Cube_FW/stm32_wpan_common.h +index b47b804..5a2b2a5 100644 +--- a/src/utility/STM32Cube_FW/stm32_wpan_common.h ++++ b/src/utility/STM32Cube_FW/stm32_wpan_common.h +@@ -25,19 +25,9 @@ + extern "C" { + #endif + +-#if defined ( __CC_ARM ) +- #define __ASM __asm /*!< asm keyword for ARM Compiler */ +- #define __INLINE __inline /*!< inline keyword for ARM Compiler */ +- #define __STATIC_INLINE static __inline +-#elif defined ( __ICCARM__ ) +- #define __ASM __asm /*!< asm keyword for IAR Compiler */ +- #define __INLINE inline /*!< inline keyword for IAR Compiler. Only available in High optimization mode! */ +- #define __STATIC_INLINE static inline +-#elif defined ( __GNUC__ ) +- #define __ASM __asm /*!< asm keyword for GNU Compiler */ +- #define __INLINE inline /*!< inline keyword for GNU Compiler */ +- #define __STATIC_INLINE static inline +-#endif ++#define __ASM __asm /*!< asm keyword for GNU Compiler */ ++#define __INLINE inline /*!< inline keyword for GNU Compiler */ ++#define __STATIC_INLINE static inline + + #include <stdint.h> + #include <string.h> +@@ -140,29 +130,8 @@ extern "C" { + /* ----------------------------------- * + * Packed usage (compiler dependent) * + * ----------------------------------- */ +-#undef PACKED__ + #undef PACKED_STRUCT +- +-#if defined ( __CC_ARM ) +- #if defined ( __GNUC__ ) +- /* GNU extension */ +- #define PACKED__ __attribute__((packed)) +- #define PACKED_STRUCT struct PACKED__ +- #elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050U) +- #define PACKED__ __attribute__((packed)) +- #define PACKED_STRUCT struct PACKED__ +- #else +- #define PACKED__(TYPE) __packed TYPE +- #define PACKED_STRUCT PACKED__(struct) +- #endif +-#elif defined ( __GNUC__ ) +- #define PACKED__ __attribute__((packed)) +- #define PACKED_STRUCT struct PACKED__ +-#elif defined (__ICCARM__) +- #define PACKED_STRUCT __packed struct +-#else +- #define PACKED_STRUCT __packed struct +-#endif ++#define PACKED_STRUCT struct __packed + + #ifdef __cplusplus + } +diff --git a/src/utility/STM32Cube_FW/stm_list.c b/src/utility/STM32Cube_FW/stm_list.c +index 69c8c06..3dea751 100644 +--- a/src/utility/STM32Cube_FW/stm_list.c ++++ b/src/utility/STM32Cube_FW/stm_list.c +@@ -16,13 +16,13 @@ + ****************************************************************************** + */ + +- ++#if defined(STM32WBxx) + /****************************************************************************** + * Include Files + ******************************************************************************/ +-#include "utilities_common.h" +- + #include "stm_list.h" ++#include "cmsis_gcc.h" ++#include "stm32_wpan_common.h" + + /****************************************************************************** + * Function Definitions +@@ -33,10 +33,10 @@ void LST_init_head (tListNode * listHead) + listHead->prev = listHead; + } + +-uint8_t LST_is_empty (tListNode * listHead) ++bool LST_is_empty (tListNode * listHead) + { + uint32_t primask_bit; +- uint8_t return_value; ++ bool return_value; + + primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ + __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ +@@ -205,3 +205,4 @@ void LST_get_prev_node (tListNode * ref_node, tListNode ** node) + __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ + } + ++#endif /* STM32WBxx */ +\ No newline at end of file +diff --git a/src/utility/STM32Cube_FW/stm_list.h b/src/utility/STM32Cube_FW/stm_list.h +index b7c3254..769c211 100644 +--- a/src/utility/STM32Cube_FW/stm_list.h ++++ b/src/utility/STM32Cube_FW/stm_list.h +@@ -21,6 +21,8 @@ + #define _STM_LIST_H_ + + /* Includes ------------------------------------------------------------------*/ ++#include "stdint.h" ++#include "stdbool.h" + #include "stm32_wpan_common.h" + + typedef PACKED_STRUCT _tListNode { +@@ -30,7 +32,7 @@ typedef PACKED_STRUCT _tListNode { + + void LST_init_head (tListNode * listHead); + +-uint8_t LST_is_empty (tListNode * listHead); ++bool LST_is_empty (tListNode * listHead); + + void LST_insert_head (tListNode * listHead, tListNode * node); + +diff --git a/src/utility/STM32Cube_FW/tl.h b/src/utility/STM32Cube_FW/tl.h +index cb27246..16de7f1 100644 +--- a/src/utility/STM32Cube_FW/tl.h ++++ b/src/utility/STM32Cube_FW/tl.h +@@ -198,19 +198,6 @@ typedef struct + uint8_t *p_BleLldM0CmdBuffer; + } TL_BLE_LLD_Config_t; + +-typedef struct +-{ +- uint8_t *p_Mac_802_15_4_CmdRspBuffer; +- uint8_t *p_Mac_802_15_4_NotAckBuffer; +-} TL_MAC_802_15_4_Config_t; +- +-typedef struct +-{ +- uint8_t *p_ZigbeeOtCmdRspBuffer; +- uint8_t *p_ZigbeeNotAckBuffer; +- uint8_t *p_ZigbeeNotifRequestBuffer; +-} TL_ZIGBEE_Config_t; +- + /** + * @brief Contain the BLE HCI Init Configuration + * @{ +@@ -304,26 +291,6 @@ void TL_MM_EvtDone( TL_EvtPacket_t * hcievt ); + void TL_TRACES_Init( void ); + void TL_TRACES_EvtReceived( TL_EvtPacket_t * hcievt ); + +-/****************************************************************************** +- * MAC 802.15.4 +- ******************************************************************************/ +-void TL_MAC_802_15_4_Init( TL_MAC_802_15_4_Config_t *p_Config ); +-void TL_MAC_802_15_4_SendCmd( void ); +-void TL_MAC_802_15_4_CmdEvtReceived( TL_EvtPacket_t * Otbuffer ); +-void TL_MAC_802_15_4_NotReceived( TL_EvtPacket_t * Notbuffer ); +-void TL_MAC_802_15_4_SendAck ( void ); +- +-/****************************************************************************** +- * ZIGBEE +- ******************************************************************************/ +-void TL_ZIGBEE_Init( TL_ZIGBEE_Config_t *p_Config ); +-void TL_ZIGBEE_SendM4RequestToM0( void ); +-void TL_ZIGBEE_SendM4AckToM0Notify ( void ); +-void TL_ZIGBEE_NotReceived( TL_EvtPacket_t * Notbuffer ); +-void TL_ZIGBEE_CmdEvtReceived( TL_EvtPacket_t * Otbuffer ); +-void TL_ZIGBEE_M0RequestReceived(TL_EvtPacket_t * Otbuffer ); +-void TL_ZIGBEE_SendM4AckToM0Request(void); +- + #ifdef __cplusplus + } /* extern "C" */ + #endif +diff --git a/src/utility/STM32Cube_FW/tl_mbox.c b/src/utility/STM32Cube_FW/tl_mbox.c +index 148bcb1..709f5d2 100644 +--- a/src/utility/STM32Cube_FW/tl_mbox.c ++++ b/src/utility/STM32Cube_FW/tl_mbox.c +@@ -16,6 +16,7 @@ + ****************************************************************************** + */ + ++#if defined(STM32WBxx) + /* Includes ------------------------------------------------------------------*/ + #include "stm32_wpan_common.h" + #include "hw.h" +@@ -51,15 +52,13 @@ PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_BleLldTable_t TL_BleLldTable; + PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_SysTable_t TL_SysTable; + PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_MemManagerTable_t TL_MemManagerTable; + PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_TracesTable_t TL_TracesTable; +-PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_Mac_802_15_4_t TL_Mac_802_15_4_Table; +-PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_ZigbeeTable_t TL_Zigbee_Table; + + /**< tables */ + PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode FreeBufQueue; + PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode TracesEvtQueue; + PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static uint8_t CsBuffer[sizeof(TL_PacketHeader_t) + TL_EVT_HDR_SIZE + sizeof(TL_CsEvt_t)]; +-PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode EvtQueue; +-PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode SystemEvtQueue; ++PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static tListNode EvtQueue; ++PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static tListNode SystemEvtQueue; + + + static tListNode LocalFreeBufQueue; +@@ -97,8 +96,6 @@ void TL_Init( void ) + TL_RefTable.p_sys_table = &TL_SysTable; + TL_RefTable.p_mem_manager_table = &TL_MemManagerTable; + TL_RefTable.p_traces_table = &TL_TracesTable; +- TL_RefTable.p_mac_802_15_4_table = &TL_Mac_802_15_4_Table; +- TL_RefTable.p_zigbee_table = &TL_Zigbee_Table; + HW_IPCC_Init(); + + return; +@@ -451,139 +448,6 @@ void TL_BLE_LLD_SendRspAck( void ) + } + #endif /* BLE_LLD_WB */ + +-#ifdef MAC_802_15_4_WB +-/****************************************************************************** +- * MAC 802.15.4 +- ******************************************************************************/ +-void TL_MAC_802_15_4_Init( TL_MAC_802_15_4_Config_t *p_Config ) +-{ +- MB_Mac_802_15_4_t * p_mac_802_15_4_table; +- +- p_mac_802_15_4_table = TL_RefTable.p_mac_802_15_4_table; +- +- p_mac_802_15_4_table->p_cmdrsp_buffer = p_Config->p_Mac_802_15_4_CmdRspBuffer; +- p_mac_802_15_4_table->p_notack_buffer = p_Config->p_Mac_802_15_4_NotAckBuffer; +- +- HW_IPCC_MAC_802_15_4_Init(); +- +- return; +-} +- +-void TL_MAC_802_15_4_SendCmd( void ) +-{ +- ((TL_CmdPacket_t *)(TL_RefTable.p_mac_802_15_4_table->p_cmdrsp_buffer))->cmdserial.type = TL_OTCMD_PKT_TYPE; +- +- HW_IPCC_MAC_802_15_4_SendCmd(); +- +- return; +-} +- +-void TL_MAC_802_15_4_SendAck ( void ) +-{ +- ((TL_CmdPacket_t *)(TL_RefTable.p_mac_802_15_4_table->p_notack_buffer))->cmdserial.type = TL_OTACK_PKT_TYPE; +- +- HW_IPCC_MAC_802_15_4_SendAck(); +- +- return; +-} +- +-void HW_IPCC_MAC_802_15_4_CmdEvtNot(void) +-{ +- TL_MAC_802_15_4_CmdEvtReceived( (TL_EvtPacket_t*)(TL_RefTable.p_mac_802_15_4_table->p_cmdrsp_buffer) ); +- +- return; +-} +- +-void HW_IPCC_MAC_802_15_4_EvtNot( void ) +-{ +- TL_MAC_802_15_4_NotReceived( (TL_EvtPacket_t*)(TL_RefTable.p_mac_802_15_4_table->p_notack_buffer) ); +- +- return; +-} +- +-__WEAK void TL_MAC_802_15_4_CmdEvtReceived( TL_EvtPacket_t * Otbuffer ){}; +-__WEAK void TL_MAC_802_15_4_NotReceived( TL_EvtPacket_t * Notbuffer ){}; +-#endif +- +-#ifdef ZIGBEE_WB +-/****************************************************************************** +- * ZIGBEE +- ******************************************************************************/ +-void TL_ZIGBEE_Init( TL_ZIGBEE_Config_t *p_Config ) +-{ +- MB_ZigbeeTable_t * p_zigbee_table; +- +- p_zigbee_table = TL_RefTable.p_zigbee_table; +- p_zigbee_table->appliCmdM4toM0_buffer = p_Config->p_ZigbeeOtCmdRspBuffer; +- p_zigbee_table->notifM0toM4_buffer = p_Config->p_ZigbeeNotAckBuffer; +- p_zigbee_table->requestM0toM4_buffer = p_Config->p_ZigbeeNotifRequestBuffer; +- +- HW_IPCC_ZIGBEE_Init(); +- +- return; +-} +- +-/* Zigbee M4 to M0 Request */ +-void TL_ZIGBEE_SendM4RequestToM0( void ) +-{ +- ((TL_CmdPacket_t *)(TL_RefTable.p_zigbee_table->appliCmdM4toM0_buffer))->cmdserial.type = TL_OTCMD_PKT_TYPE; +- +- HW_IPCC_ZIGBEE_SendM4RequestToM0(); +- +- return; +-} +- +-/* Used to receive an ACK from the M0 */ +-void HW_IPCC_ZIGBEE_RecvAppliAckFromM0(void) +-{ +- TL_ZIGBEE_CmdEvtReceived( (TL_EvtPacket_t*)(TL_RefTable.p_zigbee_table->appliCmdM4toM0_buffer) ); +- +- return; +-} +- +-/* Zigbee notification from M0 to M4 */ +-void HW_IPCC_ZIGBEE_RecvM0NotifyToM4( void ) +-{ +- TL_ZIGBEE_NotReceived( (TL_EvtPacket_t*)(TL_RefTable.p_zigbee_table->notifM0toM4_buffer) ); +- +- return; +-} +- +-/* Send an ACK to the M0 for a Notification */ +-void TL_ZIGBEE_SendM4AckToM0Notify ( void ) +-{ +- ((TL_CmdPacket_t *)(TL_RefTable.p_zigbee_table->notifM0toM4_buffer))->cmdserial.type = TL_OTACK_PKT_TYPE; +- +- HW_IPCC_ZIGBEE_SendM4AckToM0Notify(); +- +- return; +-} +- +-/* Zigbee M0 to M4 Request */ +-void HW_IPCC_ZIGBEE_RecvM0RequestToM4( void ) +-{ +- TL_ZIGBEE_M0RequestReceived( (TL_EvtPacket_t*)(TL_RefTable.p_zigbee_table->requestM0toM4_buffer) ); +- +- return; +-} +- +-/* Send an ACK to the M0 for a Request */ +-void TL_ZIGBEE_SendM4AckToM0Request(void) +-{ +- ((TL_CmdPacket_t *)(TL_RefTable.p_zigbee_table->requestM0toM4_buffer))->cmdserial.type = TL_OTACK_PKT_TYPE; +- +- HW_IPCC_ZIGBEE_SendM4AckToM0Request(); +- +- return; +-} +- +- +-__WEAK void TL_ZIGBEE_CmdEvtReceived( TL_EvtPacket_t * Otbuffer ){}; +-__WEAK void TL_ZIGBEE_NotReceived( TL_EvtPacket_t * Notbuffer ){}; +-#endif +- +- +- + /****************************************************************************** + * MEMORY MANAGER + ******************************************************************************/ +@@ -845,3 +709,5 @@ static void OutputDbgTrace(TL_MB_PacketType_t packet_type, uint8_t* buffer) + + return; + } ++ ++#endif /* STM32WBxx */ +-- +2.31.1.windows.1 + diff --git a/extras/STM32Cube_FW/0002-fix-include-a-timeout-when-waiting-for-the-cmd_resp.patch b/extras/STM32Cube_FW/0002-fix-include-a-timeout-when-waiting-for-the-cmd_resp.patch new file mode 100644 index 00000000..c4a83d6e --- /dev/null +++ b/extras/STM32Cube_FW/0002-fix-include-a-timeout-when-waiting-for-the-cmd_resp.patch @@ -0,0 +1,44 @@ +From ac18897f0f9b87bb3196efb93ef47ccaaa0eff64 Mon Sep 17 00:00:00 2001 +From: Alexandre Bourdiol <alexandre.bourdiol@st.com> +Date: Mon, 6 Dec 2021 11:18:02 +0100 +Subject: [PATCH 2/4] fix: include a timeout when waiting for the cmd_resp + +Signed-off-by: Francois Ramu <francois.ramu@st.com> +Signed-off-by: Alexandre Bourdiol <alexandre.bourdiol@st.com> +--- + src/utility/STM32Cube_FW/shci_tl.c | 11 +++++++---- + 1 file changed, 7 insertions(+), 4 deletions(-) + +diff --git a/src/utility/STM32Cube_FW/shci_tl.c b/src/utility/STM32Cube_FW/shci_tl.c +index ef403aa..6cccc5d 100644 +--- a/src/utility/STM32Cube_FW/shci_tl.c ++++ b/src/utility/STM32Cube_FW/shci_tl.c +@@ -20,6 +20,8 @@ + /* Includes ------------------------------------------------------------------*/ + #include "stm32_wpan_common.h" + ++#include <Arduino.h> ++ + #include "stm_list.h" + #include "shci_tl.h" + #include "stm32_def.h" +@@ -250,11 +252,12 @@ static void TlUserEvtReceived(TL_EvtPacket_t *shcievt) + /* Weak implementation ----------------------------------------------------------------*/ + __WEAK void shci_cmd_resp_wait(uint32_t timeout) + { +- (void)timeout; +- + CmdRspStatusFlag = SHCI_TL_CMD_RESP_WAIT; +- while(CmdRspStatusFlag != SHCI_TL_CMD_RESP_RELEASE); +- ++ for (unsigned long start = millis(); (millis() - start) < timeout;) { ++ if (CmdRspStatusFlag == SHCI_TL_CMD_RESP_RELEASE) { ++ break; ++ } ++ } + return; + } + +-- +2.31.1.windows.1 + diff --git a/extras/STM32Cube_FW/0003-Added-support-for-custom-app_conf.h-35.patch b/extras/STM32Cube_FW/0003-Added-support-for-custom-app_conf.h-35.patch new file mode 100644 index 00000000..268523d5 --- /dev/null +++ b/extras/STM32Cube_FW/0003-Added-support-for-custom-app_conf.h-35.patch @@ -0,0 +1,186 @@ +From a771c9e9a12d085fc240a45f68ca5aafb8b42006 Mon Sep 17 00:00:00 2001 +From: Alexandre Bourdiol <alexandre.bourdiol@st.com> +Date: Mon, 6 Dec 2021 18:59:38 +0100 +Subject: [PATCH 3/4] Added support for custom app_conf.h (#35) + +--- + src/utility/STM32Cube_FW/app_conf_default.h | 75 ++++++++++++++------- + 1 file changed, 49 insertions(+), 26 deletions(-) + +diff --git a/src/utility/STM32Cube_FW/app_conf_default.h b/src/utility/STM32Cube_FW/app_conf_default.h +index 4f300e0..9f8e085 100644 +--- a/src/utility/STM32Cube_FW/app_conf_default.h ++++ b/src/utility/STM32Cube_FW/app_conf_default.h +@@ -1,8 +1,8 @@ + /** + ****************************************************************************** +- * @file app_conf.h ++ * @file app_conf_default.h + * @author MCD Application Team +- * @brief Application configuration file for STM32WPAN Middleware. ++ * @brief Default application configuration file for STM32WPAN Middleware. + ****************************************************************************** + * @attention + * +@@ -17,11 +17,8 @@ + */ + + /* Define to prevent recursive inclusion -------------------------------------*/ +-#ifndef APP_CONF_H +-#define APP_CONF_H +- +-#include "hw.h" +-#include "ble_bufsize.h" ++#ifndef APP_CONF_DEFAULT_H ++#define APP_CONF_DEFAULT_H + + /****************************************************************************** + * Application Config +@@ -44,7 +41,9 @@ + /** + * Define Tx Power + */ +-#define CFG_TX_POWER (0x18) /* -0.15dBm */ ++#ifndef CFG_TX_POWER ++ #define CFG_TX_POWER (0x18) /* -0.15dBm */ ++#endif + + /****************************************************************************** + * BLE Stack +@@ -53,32 +52,41 @@ + * Maximum number of simultaneous connections that the device will support. + * Valid values are from 1 to 8 + */ +-#define CFG_BLE_NUM_LINK 2 ++#ifndef CFG_BLE_NUM_LINK ++ #define CFG_BLE_NUM_LINK 2 ++#endif + + /** + * Maximum number of Services that can be stored in the GATT database. +- * Note that the GAP and GATT services are automatically added so this parameter should be 2 plus the number of user services ++ * Note that the GAP and GATT services are automatically added so this parameter should be 2 plus the number of user ++ * services + */ ++#ifndef CFG_BLE_NUM_GATT_SERVICES + #define CFG_BLE_NUM_GATT_SERVICES 8 ++#endif + + /** + * Maximum number of Attributes +- * (i.e. the number of characteristic + the number of characteristic values + the number of descriptors, excluding the services) +- * that can be stored in the GATT database. +- * Note that certain characteristics and relative descriptors are added automatically during device initialization +- * so this parameters should be 9 plus the number of user Attributes ++ * (i.e. the number of characteristic + the number of characteristic values + the number of descriptors, excluding the ++ * services) that can be stored in the GATT database. Note that certain characteristics and relative descriptors are ++ * added automatically during device initialization so this parameters should be 9 plus the number of user Attributes + */ +-#define CFG_BLE_NUM_GATT_ATTRIBUTES 68 ++#ifndef CFG_BLE_NUM_GATT_ATTRIBUTES ++ #define CFG_BLE_NUM_GATT_ATTRIBUTES 68 ++#endif + + /** + * Maximum supported ATT_MTU size + * This parameter is ignored by the CPU2 when CFG_BLE_OPTIONS is set to 1" + */ +-#define CFG_BLE_MAX_ATT_MTU (156) ++#ifndef CFG_BLE_MAX_ATT_MTU ++ #define CFG_BLE_MAX_ATT_MTU (156) ++#endif + + /** + * Size of the storage area for Attribute values +- * This value depends on the number of attributes used by application. In particular the sum of the following quantities (in octets) should be made for each attribute: ++ * This value depends on the number of attributes used by application. In particular the sum of the following ++ * quantities (in octets) should be made for each attribute: + * - attribute value length + * - 5, if UUID is 16 bit; 19, if UUID is 128 bit + * - 2, if server configuration descriptor is used +@@ -87,14 +95,18 @@ + * The total amount of memory needed is the sum of the above quantities for each attribute. + * This parameter is ignored by the CPU2 when CFG_BLE_OPTIONS is set to 1" + */ ++#ifndef CFG_BLE_ATT_VALUE_ARRAY_SIZE + #define CFG_BLE_ATT_VALUE_ARRAY_SIZE (1344) ++#endif + + /** + * Prepare Write List size in terms of number of packet + * This parameter is ignored by the CPU2 when CFG_BLE_OPTIONS is set to 1" + */ + // #define CFG_BLE_PREPARE_WRITE_LIST_SIZE BLE_PREP_WRITE_X_ATT(CFG_BLE_MAX_ATT_MTU) +-#define CFG_BLE_PREPARE_WRITE_LIST_SIZE (0x3A) ++#ifndef CFG_BLE_PREPARE_WRITE_LIST_SIZE ++ #define CFG_BLE_PREPARE_WRITE_LIST_SIZE (0x3A) ++#endif + + /** + * Number of allocated memory blocks +@@ -106,12 +118,16 @@ + /** + * Enable or disable the Extended Packet length feature. Valid values are 0 or 1. + */ +-#define CFG_BLE_DATA_LENGTH_EXTENSION 1 ++#ifndef CFG_BLE_DATA_LENGTH_EXTENSION ++ #define CFG_BLE_DATA_LENGTH_EXTENSION 1 ++#endif + + /** + * Sleep clock accuracy in Slave mode (ppm value) + */ +-#define CFG_BLE_SLAVE_SCA 500 ++#ifndef CFG_BLE_SLAVE_SCA ++ #define CFG_BLE_SLAVE_SCA 500 ++#endif + + /** + * Sleep clock accuracy in Master mode +@@ -124,24 +140,32 @@ + * 6 : 21 ppm to 30 ppm + * 7 : 0 ppm to 20 ppm + */ +-#define CFG_BLE_MASTER_SCA 0 ++#ifndef CFG_BLE_MASTER_SCA ++ #define CFG_BLE_MASTER_SCA 0 ++#endif + + /** + * Source for the low speed clock for RF wake-up + * 1 : external high speed crystal HSE/32/32 + * 0 : external low speed crystal ( no calibration ) + */ +-#define CFG_BLE_LSE_SOURCE 0 ++#ifndef CFG_BLE_LSE_SOURCE ++ #define CFG_BLE_LSE_SOURCE 0 ++#endif + + /** + * Start up time of the high speed (16 or 32 MHz) crystal oscillator in units of 625/256 us (~2.44 us) + */ +-#define CFG_BLE_HSE_STARTUP_TIME 0x148 ++#ifndef CFG_BLE_HSE_STARTUP_TIME ++ #define CFG_BLE_HSE_STARTUP_TIME 0x148 ++#endif + + /** + * Maximum duration of the connection event when the device is in Slave mode in units of 625/256 us (~2.44 us) + */ +-#define CFG_BLE_MAX_CONN_EVENT_LENGTH (0xFFFFFFFF) ++#ifndef CFG_BLE_MAX_CONN_EVENT_LENGTH ++ #define CFG_BLE_MAX_CONN_EVENT_LENGTH (0xFFFFFFFF) ++#endif + + /** + * Viterbi Mode +@@ -199,5 +223,4 @@ + + #define CFG_BLE_RX_MODEL_CONFIG SHCI_C2_BLE_INIT_RX_MODEL_AGC_RSSI_LEGACY + +- +-#endif /*APP_CONF_H */ ++#endif /* APP_CONF_DEFAULT_H */ +-- +2.31.1.windows.1 + diff --git a/extras/STM32Cube_FW/0004-Stub-OutputDbgTrace-function.patch b/extras/STM32Cube_FW/0004-Stub-OutputDbgTrace-function.patch new file mode 100644 index 00000000..6f844f7a --- /dev/null +++ b/extras/STM32Cube_FW/0004-Stub-OutputDbgTrace-function.patch @@ -0,0 +1,209 @@ +From a015490bdd861f421addd761ee4164358dc07c19 Mon Sep 17 00:00:00 2001 +From: Alexandre Bourdiol <alexandre.bourdiol@st.com> +Date: Tue, 7 Dec 2021 14:27:27 +0100 +Subject: [PATCH 4/4] Stub OutputDbgTrace() function + +Signed-off-by: Alexandre Bourdiol <alexandre.bourdiol@st.com> +--- + src/utility/STM32Cube_FW/tl_mbox.c | 178 +---------------------------- + 1 file changed, 3 insertions(+), 175 deletions(-) + +diff --git a/src/utility/STM32Cube_FW/tl_mbox.c b/src/utility/STM32Cube_FW/tl_mbox.c +index 709f5d2..db192c4 100644 +--- a/src/utility/STM32Cube_FW/tl_mbox.c ++++ b/src/utility/STM32Cube_FW/tl_mbox.c +@@ -24,7 +24,6 @@ + #include "stm_list.h" + #include "tl.h" + #include "mbox_def.h" +-#include "tl_dbg_conf.h" + + /* Private typedef -----------------------------------------------------------*/ + typedef enum +@@ -532,180 +531,9 @@ __WEAK void TL_TRACES_EvtReceived( TL_EvtPacket_t * hcievt ) + ******************************************************************************/ + static void OutputDbgTrace(TL_MB_PacketType_t packet_type, uint8_t* buffer) + { +- TL_EvtPacket_t *p_evt_packet; +- TL_CmdPacket_t *p_cmd_packet; +- +- switch(packet_type) +- { +- case TL_MB_MM_RELEASE_BUFFER: +- p_evt_packet = (TL_EvtPacket_t*)buffer; +- switch(p_evt_packet->evtserial.evt.evtcode) +- { +- case TL_BLEEVT_CS_OPCODE: +- TL_MM_DBG_MSG("mm evt released: 0x%02X", p_evt_packet->evtserial.evt.evtcode); +- TL_MM_DBG_MSG(" cmd opcode: 0x%04X", ((TL_CsEvt_t*)(p_evt_packet->evtserial.evt.payload))->cmdcode); +- TL_MM_DBG_MSG(" buffer addr: 0x%08X", p_evt_packet); +- break; +- +- case TL_BLEEVT_CC_OPCODE: +- TL_MM_DBG_MSG("mm evt released: 0x%02X", p_evt_packet->evtserial.evt.evtcode); +- TL_MM_DBG_MSG(" cmd opcode: 0x%04X", ((TL_CcEvt_t*)(p_evt_packet->evtserial.evt.payload))->cmdcode); +- TL_MM_DBG_MSG(" buffer addr: 0x%08X", p_evt_packet); +- break; +- +- case TL_BLEEVT_VS_OPCODE: +- TL_MM_DBG_MSG("mm evt released: 0x%02X", p_evt_packet->evtserial.evt.evtcode); +- TL_MM_DBG_MSG(" subevtcode: 0x%04X", ((TL_AsynchEvt_t*)(p_evt_packet->evtserial.evt.payload))->subevtcode); +- TL_MM_DBG_MSG(" buffer addr: 0x%08X", p_evt_packet); +- break; +- +- default: +- TL_MM_DBG_MSG("mm evt released: 0x%02X", p_evt_packet->evtserial.evt.evtcode); +- TL_MM_DBG_MSG(" buffer addr: 0x%08X", p_evt_packet); +- break; +- } +- +- TL_MM_DBG_MSG("\r\n"); +- break; +- +- case TL_MB_BLE_CMD: +- p_cmd_packet = (TL_CmdPacket_t*)buffer; +- TL_HCI_CMD_DBG_MSG("ble cmd: 0x%04X", p_cmd_packet->cmdserial.cmd.cmdcode); +- if(p_cmd_packet->cmdserial.cmd.plen != 0) +- { +- TL_HCI_CMD_DBG_MSG(" payload:"); +- TL_HCI_CMD_DBG_BUF(p_cmd_packet->cmdserial.cmd.payload, p_cmd_packet->cmdserial.cmd.plen, ""); +- } +- TL_HCI_CMD_DBG_MSG("\r\n"); +- +- TL_HCI_CMD_DBG_RAW(&p_cmd_packet->cmdserial, p_cmd_packet->cmdserial.cmd.plen+TL_CMD_HDR_SIZE); +- break; +- +- case TL_MB_BLE_CMD_RSP: +- p_evt_packet = (TL_EvtPacket_t*)buffer; +- switch(p_evt_packet->evtserial.evt.evtcode) +- { +- case TL_BLEEVT_CS_OPCODE: +- TL_HCI_CMD_DBG_MSG("ble rsp: 0x%02X", p_evt_packet->evtserial.evt.evtcode); +- TL_HCI_CMD_DBG_MSG(" cmd opcode: 0x%04X", ((TL_CsEvt_t*)(p_evt_packet->evtserial.evt.payload))->cmdcode); +- TL_HCI_CMD_DBG_MSG(" numhci: 0x%02X", ((TL_CsEvt_t*)(p_evt_packet->evtserial.evt.payload))->numcmd); +- TL_HCI_CMD_DBG_MSG(" status: 0x%02X", ((TL_CsEvt_t*)(p_evt_packet->evtserial.evt.payload))->status); +- break; +- +- case TL_BLEEVT_CC_OPCODE: +- TL_HCI_CMD_DBG_MSG("ble rsp: 0x%02X", p_evt_packet->evtserial.evt.evtcode); +- TL_HCI_CMD_DBG_MSG(" cmd opcode: 0x%04X", ((TL_CcEvt_t*)(p_evt_packet->evtserial.evt.payload))->cmdcode); +- TL_HCI_CMD_DBG_MSG(" numhci: 0x%02X", ((TL_CcEvt_t*)(p_evt_packet->evtserial.evt.payload))->numcmd); +- TL_HCI_CMD_DBG_MSG(" status: 0x%02X", ((TL_CcEvt_t*)(p_evt_packet->evtserial.evt.payload))->payload[0]); +- if((p_evt_packet->evtserial.evt.plen-4) != 0) +- { +- TL_HCI_CMD_DBG_MSG(" payload:"); +- TL_HCI_CMD_DBG_BUF(&((TL_CcEvt_t*)(p_evt_packet->evtserial.evt.payload))->payload[1], p_evt_packet->evtserial.evt.plen-4, ""); +- } +- break; +- +- default: +- TL_HCI_CMD_DBG_MSG("unknown ble rsp received: %02X", p_evt_packet->evtserial.evt.evtcode); +- break; +- } +- +- TL_HCI_CMD_DBG_MSG("\r\n"); +- +- TL_HCI_CMD_DBG_RAW(&p_evt_packet->evtserial, p_evt_packet->evtserial.evt.plen+TL_EVT_HDR_SIZE); +- break; +- +- case TL_MB_BLE_ASYNCH_EVT: +- p_evt_packet = (TL_EvtPacket_t*)buffer; +- if(p_evt_packet->evtserial.evt.evtcode != TL_BLEEVT_VS_OPCODE) +- { +- TL_HCI_EVT_DBG_MSG("ble evt: 0x%02X", p_evt_packet->evtserial.evt.evtcode); +- if((p_evt_packet->evtserial.evt.plen) != 0) +- { +- TL_HCI_EVT_DBG_MSG(" payload:"); +- TL_HCI_EVT_DBG_BUF(p_evt_packet->evtserial.evt.payload, p_evt_packet->evtserial.evt.plen, ""); +- } +- } +- else +- { +- TL_HCI_EVT_DBG_MSG("ble evt: 0x%02X", p_evt_packet->evtserial.evt.evtcode); +- TL_HCI_EVT_DBG_MSG(" subevtcode: 0x%04X", ((TL_AsynchEvt_t*)(p_evt_packet->evtserial.evt.payload))->subevtcode); +- if((p_evt_packet->evtserial.evt.plen-2) != 0) +- { +- TL_HCI_EVT_DBG_MSG(" payload:"); +- TL_HCI_EVT_DBG_BUF(((TL_AsynchEvt_t*)(p_evt_packet->evtserial.evt.payload))->payload, p_evt_packet->evtserial.evt.plen-2, ""); +- } +- } +- +- TL_HCI_EVT_DBG_MSG("\r\n"); +- +- TL_HCI_EVT_DBG_RAW(&p_evt_packet->evtserial, p_evt_packet->evtserial.evt.plen+TL_EVT_HDR_SIZE); +- break; +- +- case TL_MB_SYS_CMD: +- p_cmd_packet = (TL_CmdPacket_t*)buffer; +- +- TL_SHCI_CMD_DBG_MSG("sys cmd: 0x%04X", p_cmd_packet->cmdserial.cmd.cmdcode); +- +- if(p_cmd_packet->cmdserial.cmd.plen != 0) +- { +- TL_SHCI_CMD_DBG_MSG(" payload:"); +- TL_SHCI_CMD_DBG_BUF(p_cmd_packet->cmdserial.cmd.payload, p_cmd_packet->cmdserial.cmd.plen, ""); +- } +- TL_SHCI_CMD_DBG_MSG("\r\n"); +- +- TL_SHCI_CMD_DBG_RAW(&p_cmd_packet->cmdserial, p_cmd_packet->cmdserial.cmd.plen+TL_CMD_HDR_SIZE); +- break; +- +- case TL_MB_SYS_CMD_RSP: +- p_evt_packet = (TL_EvtPacket_t*)buffer; +- switch(p_evt_packet->evtserial.evt.evtcode) +- { +- case TL_BLEEVT_CC_OPCODE: +- TL_SHCI_CMD_DBG_MSG("sys rsp: 0x%02X", p_evt_packet->evtserial.evt.evtcode); +- TL_SHCI_CMD_DBG_MSG(" cmd opcode: 0x%02X", ((TL_CcEvt_t*)(p_evt_packet->evtserial.evt.payload))->cmdcode); +- TL_SHCI_CMD_DBG_MSG(" status: 0x%02X", ((TL_CcEvt_t*)(p_evt_packet->evtserial.evt.payload))->payload[0]); +- if((p_evt_packet->evtserial.evt.plen-4) != 0) +- { +- TL_SHCI_CMD_DBG_MSG(" payload:"); +- TL_SHCI_CMD_DBG_BUF(&((TL_CcEvt_t*)(p_evt_packet->evtserial.evt.payload))->payload[1], p_evt_packet->evtserial.evt.plen-4, ""); +- } +- break; +- +- default: +- TL_SHCI_CMD_DBG_MSG("unknown sys rsp received: %02X", p_evt_packet->evtserial.evt.evtcode); +- break; +- } +- +- TL_SHCI_CMD_DBG_MSG("\r\n"); +- +- TL_SHCI_CMD_DBG_RAW(&p_evt_packet->evtserial, p_evt_packet->evtserial.evt.plen+TL_EVT_HDR_SIZE); +- break; +- +- case TL_MB_SYS_ASYNCH_EVT: +- p_evt_packet = (TL_EvtPacket_t*)buffer; +- if(p_evt_packet->evtserial.evt.evtcode != TL_BLEEVT_VS_OPCODE) +- { +- TL_SHCI_EVT_DBG_MSG("unknown sys evt received: %02X", p_evt_packet->evtserial.evt.evtcode); +- } +- else +- { +- TL_SHCI_EVT_DBG_MSG("sys evt: 0x%02X", p_evt_packet->evtserial.evt.evtcode); +- TL_SHCI_EVT_DBG_MSG(" subevtcode: 0x%04X", ((TL_AsynchEvt_t*)(p_evt_packet->evtserial.evt.payload))->subevtcode); +- if((p_evt_packet->evtserial.evt.plen-2) != 0) +- { +- TL_SHCI_EVT_DBG_MSG(" payload:"); +- TL_SHCI_EVT_DBG_BUF(((TL_AsynchEvt_t*)(p_evt_packet->evtserial.evt.payload))->payload, p_evt_packet->evtserial.evt.plen-2, ""); +- } +- } +- +- TL_SHCI_EVT_DBG_MSG("\r\n"); +- +- TL_SHCI_EVT_DBG_RAW(&p_evt_packet->evtserial, p_evt_packet->evtserial.evt.plen+TL_EVT_HDR_SIZE); +- break; +- +- default: +- break; +- } ++ /* Function stubbed */ ++ UNUSED(packet_type); ++ UNUSED(buffer); + + return; + } +-- +2.31.1.windows.1 + From ab9e2f90350292d2390f58abe9f4b8e5a18ab851 Mon Sep 17 00:00:00 2001 From: Alexandre Bourdiol <alexandre.bourdiol@st.com> Date: Mon, 6 Dec 2021 19:17:44 +0100 Subject: [PATCH 080/226] Update STM32Cube_FW from Cube version v1.13.0 Signed-off-by: Alexandre Bourdiol <alexandre.bourdiol@st.com> --- src/utility/HCISharedMemTransport.cpp | 8 +- src/utility/STM32Cube_FW/LICENSE.md | 80 +++ src/utility/STM32Cube_FW/README.md | 4 +- src/utility/STM32Cube_FW/app_conf_default.h | 588 ++++++++++++++++--- src/utility/STM32Cube_FW/ble_bufsize.h | 73 +-- src/utility/STM32Cube_FW/hw.h | 58 +- src/utility/STM32Cube_FW/hw_ipcc.c | 362 +++++++++++- src/utility/STM32Cube_FW/mbox_def.h | 101 +++- src/utility/STM32Cube_FW/shci.c | 252 ++++++-- src/utility/STM32Cube_FW/shci.h | 503 ++++++++++++++-- src/utility/STM32Cube_FW/shci_tl.c | 145 +---- src/utility/STM32Cube_FW/shci_tl.h | 24 +- src/utility/STM32Cube_FW/stm32_wpan_common.h | 52 +- src/utility/STM32Cube_FW/stm_list.c | 26 +- src/utility/STM32Cube_FW/stm_list.h | 23 +- src/utility/STM32Cube_FW/tl.h | 81 ++- src/utility/STM32Cube_FW/tl_mbox.c | 481 ++++++++++++--- 17 files changed, 2248 insertions(+), 613 deletions(-) create mode 100644 src/utility/STM32Cube_FW/LICENSE.md diff --git a/src/utility/HCISharedMemTransport.cpp b/src/utility/HCISharedMemTransport.cpp index ee2a41a6..c8de8c56 100644 --- a/src/utility/HCISharedMemTransport.cpp +++ b/src/utility/HCISharedMemTransport.cpp @@ -735,8 +735,12 @@ int HCISharedMemTransportClass::stm32wb_start_ble(void) CFG_BLE_MAX_CONN_EVENT_LENGTH, CFG_BLE_HSE_STARTUP_TIME, CFG_BLE_VITERBI_MODE, - CFG_BLE_LL_ONLY, - 0 /** TODO Should be read from HW */ + CFG_BLE_OPTIONS, + 0, /** TODO Should be read from HW */ + CFG_BLE_MAX_COC_INITIATOR_NBR, + CFG_BLE_MIN_TX_POWER, + CFG_BLE_MAX_TX_POWER, + CFG_BLE_RX_MODEL_CONFIG }; /** * Starts the BLE Stack on CPU2 diff --git a/src/utility/STM32Cube_FW/LICENSE.md b/src/utility/STM32Cube_FW/LICENSE.md new file mode 100644 index 00000000..1af52330 --- /dev/null +++ b/src/utility/STM32Cube_FW/LICENSE.md @@ -0,0 +1,80 @@ +SLA0044 Rev5/February 2018 + +## Software license agreement + +### __ULTIMATE LIBERTY SOFTWARE LICENSE AGREEMENT__ + +BY INSTALLING, COPYING, DOWNLOADING, ACCESSING OR OTHERWISE USING THIS SOFTWARE +OR ANY PART THEREOF (AND THE RELATED DOCUMENTATION) FROM STMICROELECTRONICS +INTERNATIONAL N.V, SWISS BRANCH AND/OR ITS AFFILIATED COMPANIES +(STMICROELECTRONICS), THE RECIPIENT, ON BEHALF OF HIMSELF OR HERSELF, OR ON +BEHALF OF ANY ENTITY BY WHICH SUCH RECIPIENT IS EMPLOYED AND/OR ENGAGED AGREES +TO BE BOUND BY THIS SOFTWARE LICENSE AGREEMENT. + +Under STMicroelectronics’ intellectual property rights, the redistribution, +reproduction and use in source and binary forms of the software or any part +thereof, with or without modification, are permitted provided that the following +conditions are met: + +1. Redistribution of source code (modified or not) must retain any copyright +notice, this list of conditions and the disclaimer set forth below as items 10 +and 11. + +2. Redistributions in binary form, except as embedded into microcontroller or +microprocessor device manufactured by or for STMicroelectronics or a software +update for such device, must reproduce any copyright notice provided with the +binary code, this list of conditions, and the disclaimer set forth below as +items 10 and 11, in documentation and/or other materials provided with the +distribution. + +3. Neither the name of STMicroelectronics nor the names of other contributors to +this software may be used to endorse or promote products derived from this +software or part thereof without specific written permission. + +4. This software or any part thereof, including modifications and/or derivative +works of this software, must be used and execute solely and exclusively on or in +combination with a microcontroller or microprocessor device manufactured by or +for STMicroelectronics. + +5. No use, reproduction or redistribution of this software partially or totally +may be done in any manner that would subject this software to any Open Source +Terms. “Open Source Terms” shall mean any open source license which requires as +part of distribution of software that the source code of such software is +distributed therewith or otherwise made available, or open source license that +substantially complies with the Open Source definition specified at +www.opensource.org and any other comparable open source license such as for +example GNU General Public License (GPL), Eclipse Public License (EPL), Apache +Software License, BSD license or MIT license. + +6. STMicroelectronics has no obligation to provide any maintenance, support or +updates for the software. + +7. The software is and will remain the exclusive property of STMicroelectronics +and its licensors. The recipient will not take any action that jeopardizes +STMicroelectronics and its licensors' proprietary rights or acquire any rights +in the software, except the limited rights specified hereunder. + +8. The recipient shall comply with all applicable laws and regulations affecting +the use of the software or any part thereof including any applicable export +control law or regulation. + +9. Redistribution and use of this software or any part thereof other than as +permitted under this license is void and will automatically terminate your +rights under this license. + +10. THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY RIGHTS, WHICH ARE +DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT SHALL +STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +11. EXCEPT AS EXPRESSLY PERMITTED HEREUNDER, NO LICENSE OR OTHER RIGHTS, WHETHER +EXPRESS OR IMPLIED, ARE GRANTED UNDER ANY PATENT OR OTHER INTELLECTUAL PROPERTY +RIGHTS OF STMICROELECTRONICS OR ANY THIRD PARTY. diff --git a/src/utility/STM32Cube_FW/README.md b/src/utility/STM32Cube_FW/README.md index 880fcbbc..419d0eb0 100644 --- a/src/utility/STM32Cube_FW/README.md +++ b/src/utility/STM32Cube_FW/README.md @@ -1,6 +1,6 @@ ## Source -[STMicroelectronics/STM32CubeWB Release v1.8.0](https://github.com/STMicroelectronics/STM32CubeWB/releases/tag/v1.8.0) -- Application: [BLE_TransparentMode](https://github.com/STMicroelectronics/STM32CubeWB/tree/v1.8.0/Projects/P-NUCLEO-WB55.Nucleo/Applications/BLE/BLE_TransparentMode) +[STMicroelectronics/STM32CubeWB Release v1.13.0](https://github.com/STMicroelectronics/STM32CubeWB/releases/tag/v1.13.0) +- Application: [BLE_TransparentMode](https://github.com/STMicroelectronics/STM32CubeWB/tree/v1.13.0/Projects/P-NUCLEO-WB55.Nucleo/Applications/BLE/BLE_TransparentMode) diff --git a/src/utility/STM32Cube_FW/app_conf_default.h b/src/utility/STM32Cube_FW/app_conf_default.h index e870c321..7ebc65aa 100644 --- a/src/utility/STM32Cube_FW/app_conf_default.h +++ b/src/utility/STM32Cube_FW/app_conf_default.h @@ -1,49 +1,109 @@ +/* USER CODE BEGIN Header */ /** - ****************************************************************************** - * File Name : app_conf_default.h - * Description : Default application configuration file for STM32WPAN Middleware. - ****************************************************************************** - * @attention - * - * <h2><center>© Copyright (c) 2020 STMicroelectronics. - * All rights reserved.</center></h2> - * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 - * - ****************************************************************************** - */ + ****************************************************************************** + * @file app_conf.h + * @author MCD Application Team + * @brief Application configuration file for STM32WPAN Middleware. + ****************************************************************************** + * @attention + * + * Copyright (c) 2020-2021 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ /* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef APP_CONF_DEFAULT_H -#define APP_CONF_DEFAULT_H +#ifndef APP_CONF_H +#define APP_CONF_H + +#include "hw.h" +#include "hw_conf.h" +#include "hw_if.h" +#include "ble_bufsize.h" /****************************************************************************** * Application Config ******************************************************************************/ -/**< generic parameters ******************************************************/ -/* HCI related defines */ +/** + * Define Secure Connections Support + */ +#define CFG_SECURE_NOT_SUPPORTED (0x00) +#define CFG_SECURE_OPTIONAL (0x01) +#define CFG_SECURE_MANDATORY (0x02) + +#define CFG_SC_SUPPORT CFG_SECURE_OPTIONAL -#define ACI_HAL_SET_TX_POWER_LEVEL 0xFC0F -#define ACI_WRITE_CONFIG_DATA_OPCODE 0xFC0C -#define ACI_READ_CONFIG_DATA_OPCODE 0xFC0D -#define MAX_HCI_ACL_PACKET_SIZE (sizeof(TL_PacketHeader_t) + 5 + 251) -#define HCI_RESET 0x0C03 +/** + * Define Keypress Notification Support + */ +#define CFG_KEYPRESS_NOT_SUPPORTED (0x00) +#define CFG_KEYPRESS_SUPPORTED (0x01) -#ifndef BLE_SHARED_MEM_BYTE_ORDER - #define BLE_SHARED_MEM_BYTE_ORDER MSBFIRST -#endif -#define BLE_MODULE_SHARED_MEM_BUFFER_SIZE 128 +#define CFG_KEYPRESS_NOTIFICATION_SUPPORT CFG_KEYPRESS_NOT_SUPPORTED /** - * Define Tx Power + * Numeric Comparison Answers */ -#ifndef CFG_TX_POWER - #define CFG_TX_POWER (0x18) /* -0.15dBm */ -#endif +#define YES (0x01) +#define NO (0x00) + +/** + * Device name configuration for Generic Access Service + */ +#define CFG_GAP_DEVICE_NAME "TEMPLATE" +#define CFG_GAP_DEVICE_NAME_LENGTH (8) + +/** +* Identity root key used to derive LTK and CSRK +*/ +#define CFG_BLE_IRK {0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0} + +/** +* Encryption root key used to derive LTK and CSRK +*/ +#define CFG_BLE_ERK {0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21, 0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21} + +/** + * SMPS supply + * SMPS not used when Set to 0 + * SMPS used when Set to 1 + */ +#define CFG_USE_SMPS 0 + +/* USER CODE BEGIN Generic_Parameters */ +/* USER CODE END Generic_Parameters */ + +/**< specific parameters */ +/*****************************************************/ + +/* USER CODE BEGIN Specific_Parameters */ +#define PUSH_BUTTON_SW1_EXTI_IRQHandler EXTI4_IRQHandler + +/* USER CODE END Specific_Parameters */ + +/****************************************************************************** + * Information Table + * + * Version + * [0:3] = Build - 0: Untracked - 15:Released - x: Tracked version + * [4:7] = branch - 0: Mass Market - x: ... + * [8:15] = Subversion + * [16:23] = Version minor + * [24:31] = Version major + * + ******************************************************************************/ +#define CFG_FW_MAJOR_VERSION (0) +#define CFG_FW_MINOR_VERSION (0) +#define CFG_FW_SUBVERSION (1) +#define CFG_FW_BRANCH (0) +#define CFG_FW_BUILD (0) /****************************************************************************** * BLE Stack @@ -52,81 +112,63 @@ * Maximum number of simultaneous connections that the device will support. * Valid values are from 1 to 8 */ -#ifndef CFG_BLE_NUM_LINK - #define CFG_BLE_NUM_LINK 8 -#endif +#define CFG_BLE_NUM_LINK 2 /** * Maximum number of Services that can be stored in the GATT database. - * Note that the GAP and GATT services are automatically added so this parameter should be 2 plus the number of user - * services + * Note that the GAP and GATT services are automatically added so this parameter should be 2 plus the number of user services */ -#ifndef CFG_BLE_NUM_GATT_SERVICES - #define CFG_BLE_NUM_GATT_SERVICES 8 -#endif +#define CFG_BLE_NUM_GATT_SERVICES 8 /** * Maximum number of Attributes - * (i.e. the number of characteristic + the number of characteristic values + the number of descriptors, excluding the - * services) that can be stored in the GATT database. Note that certain characteristics and relative descriptors are - * added automatically during device initialization so this parameters should be 9 plus the number of user Attributes + * (i.e. the number of characteristic + the number of characteristic values + the number of descriptors, excluding the services) + * that can be stored in the GATT database. + * Note that certain characteristics and relative descriptors are added automatically during device initialization + * so this parameters should be 9 plus the number of user Attributes */ -#ifndef CFG_BLE_NUM_GATT_ATTRIBUTES - #define CFG_BLE_NUM_GATT_ATTRIBUTES 68 -#endif +#define CFG_BLE_NUM_GATT_ATTRIBUTES 68 /** * Maximum supported ATT_MTU size + * This parameter is ignored by the CPU2 when CFG_BLE_OPTIONS is set to 1" */ -#ifndef CFG_BLE_MAX_ATT_MTU - #define CFG_BLE_MAX_ATT_MTU (156) -#endif +#define CFG_BLE_MAX_ATT_MTU (156) /** * Size of the storage area for Attribute values - * This value depends on the number of attributes used by application. In particular the sum of the following - * quantities (in octets) should be made for each attribute: + * This value depends on the number of attributes used by application. In particular the sum of the following quantities (in octets) should be made for each attribute: * - attribute value length * - 5, if UUID is 16 bit; 19, if UUID is 128 bit * - 2, if server configuration descriptor is used * - 2*DTM_NUM_LINK, if client configuration descriptor is used * - 2, if extended properties is used * The total amount of memory needed is the sum of the above quantities for each attribute. + * This parameter is ignored by the CPU2 when CFG_BLE_OPTIONS is set to 1" */ -#ifndef CFG_BLE_ATT_VALUE_ARRAY_SIZE - #define CFG_BLE_ATT_VALUE_ARRAY_SIZE (1344) -#endif +#define CFG_BLE_ATT_VALUE_ARRAY_SIZE (1344) /** * Prepare Write List size in terms of number of packet + * This parameter is ignored by the CPU2 when CFG_BLE_OPTIONS is set to 1" */ -//#define CFG_BLE_PREPARE_WRITE_LIST_SIZE BLE_PREP_WRITE_X_ATT(CFG_BLE_MAX_ATT_MTU) -#ifndef CFG_BLE_PREPARE_WRITE_LIST_SIZE - #define CFG_BLE_PREPARE_WRITE_LIST_SIZE (0x3A) -#endif +#define CFG_BLE_PREPARE_WRITE_LIST_SIZE BLE_PREP_WRITE_X_ATT(CFG_BLE_MAX_ATT_MTU) /** * Number of allocated memory blocks + * This parameter is overwritten by the CPU2 with an hardcoded optimal value when the parameter when CFG_BLE_OPTIONS is set to 1 */ -//#define CFG_BLE_MBLOCK_COUNT (BLE_MBLOCKS_CALC(CFG_BLE_PREPARE_WRITE_LIST_SIZE, CFG_BLE_MAX_ATT_MTU, -// CFG_BLE_NUM_LINK)) -#ifndef CFG_BLE_MBLOCK_COUNT - #define CFG_BLE_MBLOCK_COUNT (0x79) -#endif +#define CFG_BLE_MBLOCK_COUNT (BLE_MBLOCKS_CALC(CFG_BLE_PREPARE_WRITE_LIST_SIZE, CFG_BLE_MAX_ATT_MTU, CFG_BLE_NUM_LINK)) /** * Enable or disable the Extended Packet length feature. Valid values are 0 or 1. */ -#ifndef CFG_BLE_DATA_LENGTH_EXTENSION - #define CFG_BLE_DATA_LENGTH_EXTENSION 1 -#endif +#define CFG_BLE_DATA_LENGTH_EXTENSION 1 /** * Sleep clock accuracy in Slave mode (ppm value) */ -#ifndef CFG_BLE_SLAVE_SCA - #define CFG_BLE_SLAVE_SCA 500 -#endif +#define CFG_BLE_SLAVE_SCA 500 /** * Sleep clock accuracy in Master mode @@ -139,47 +181,409 @@ * 6 : 21 ppm to 30 ppm * 7 : 0 ppm to 20 ppm */ -#ifndef CFG_BLE_MASTER_SCA - #define CFG_BLE_MASTER_SCA 0 -#endif +#define CFG_BLE_MASTER_SCA 0 /** - * Source for the 32 kHz slow speed clock - * 1 : internal RO - * 0 : external crystal ( no calibration ) + * Source for the low speed clock for RF wake-up + * 1 : external high speed crystal HSE/32/32 + * 0 : external low speed crystal ( no calibration ) */ -#ifndef CFG_BLE_LSE_SOURCE - #define CFG_BLE_LSE_SOURCE 0 -#endif +#define CFG_BLE_LSE_SOURCE 0 /** * Start up time of the high speed (16 or 32 MHz) crystal oscillator in units of 625/256 us (~2.44 us) */ -#ifndef CFG_BLE_HSE_STARTUP_TIME - #define CFG_BLE_HSE_STARTUP_TIME 0x148 -#endif +#define CFG_BLE_HSE_STARTUP_TIME 0x148 /** * Maximum duration of the connection event when the device is in Slave mode in units of 625/256 us (~2.44 us) */ -#ifndef CFG_BLE_MAX_CONN_EVENT_LENGTH - #define CFG_BLE_MAX_CONN_EVENT_LENGTH (0xFFFFFFFF) -#endif +#define CFG_BLE_MAX_CONN_EVENT_LENGTH (0xFFFFFFFF) /** * Viterbi Mode * 1 : enabled * 0 : disabled */ -#define CFG_BLE_VITERBI_MODE 1 +#define CFG_BLE_VITERBI_MODE 1 + +/** + * BLE stack Options flags to be configured with: + * - SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY + * - SHCI_C2_BLE_INIT_OPTIONS_LL_HOST + * - SHCI_C2_BLE_INIT_OPTIONS_NO_SVC_CHANGE_DESC + * - SHCI_C2_BLE_INIT_OPTIONS_WITH_SVC_CHANGE_DESC + * - SHCI_C2_BLE_INIT_OPTIONS_DEVICE_NAME_RO + * - SHCI_C2_BLE_INIT_OPTIONS_DEVICE_NAME_RW + * - SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV + * - SHCI_C2_BLE_INIT_OPTIONS_NO_EXT_ADV + * - SHCI_C2_BLE_INIT_OPTIONS_CS_ALGO2 + * - SHCI_C2_BLE_INIT_OPTIONS_NO_CS_ALGO2 + * - SHCI_C2_BLE_INIT_OPTIONS_POWER_CLASS_1 + * - SHCI_C2_BLE_INIT_OPTIONS_POWER_CLASS_2_3 + * which are used to set following configuration bits: + * (bit 0): 1: LL only + * 0: LL + host + * (bit 1): 1: no service change desc. + * 0: with service change desc. + * (bit 2): 1: device name Read-Only + * 0: device name R/W + * (bit 3): 1: extended advertizing supported [NOT SUPPORTED] + * 0: extended advertizing not supported [NOT SUPPORTED] + * (bit 4): 1: CS Algo #2 supported + * 0: CS Algo #2 not supported + * (bit 7): 1: LE Power Class 1 + * 0: LE Power Class 2-3 + * other bits: reserved (shall be set to 0) + */ +#define CFG_BLE_OPTIONS (SHCI_C2_BLE_INIT_OPTIONS_LL_HOST | SHCI_C2_BLE_INIT_OPTIONS_WITH_SVC_CHANGE_DESC | SHCI_C2_BLE_INIT_OPTIONS_DEVICE_NAME_RW | SHCI_C2_BLE_INIT_OPTIONS_NO_EXT_ADV | SHCI_C2_BLE_INIT_OPTIONS_NO_CS_ALGO2 | SHCI_C2_BLE_INIT_OPTIONS_POWER_CLASS_2_3) + +#define CFG_BLE_MAX_COC_INITIATOR_NBR (32) + +#define CFG_BLE_MIN_TX_POWER (0) + +#define CFG_BLE_MAX_TX_POWER (0) + +/** + * BLE Rx model configuration flags to be configured with: + * - SHCI_C2_BLE_INIT_RX_MODEL_AGC_RSSI_LEGACY + * - SHCI_C2_BLE_INIT_RX_MODEL_AGC_RSSI_BLOCKER + * which are used to set following configuration bits: + * (bit 0): 1: agc_rssi model improved vs RF blockers + * 0: Legacy agc_rssi model + * other bits: reserved (shall be set to 0) + */ + +#define CFG_BLE_RX_MODEL_CONFIG SHCI_C2_BLE_INIT_RX_MODEL_AGC_RSSI_LEGACY + +/****************************************************************************** + * Transport Layer + ******************************************************************************/ +/** + * Queue length of BLE Event + * This parameter defines the number of asynchronous events that can be stored in the HCI layer before + * being reported to the application. When a command is sent to the BLE core coprocessor, the HCI layer + * is waiting for the event with the Num_HCI_Command_Packets set to 1. The receive queue shall be large + * enough to store all asynchronous events received in between. + * When CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE is set to 27, this allow to store three 255 bytes long asynchronous events + * between the HCI command and its event. + * This parameter depends on the value given to CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE. When the queue size is to small, + * the system may hang if the queue is full with asynchronous events and the HCI layer is still waiting + * for a CC/CS event, In that case, the notification TL_BLE_HCI_ToNot() is called to indicate + * to the application a HCI command did not receive its command event within 30s (Default HCI Timeout). + */ +#define CFG_TLBLE_EVT_QUEUE_LENGTH 5 +/** + * This parameter should be set to fit most events received by the HCI layer. It defines the buffer size of each element + * allocated in the queue of received events and can be used to optimize the amount of RAM allocated by the Memory Manager. + * It should not exceed 255 which is the maximum HCI packet payload size (a greater value is a lost of memory as it will + * never be used) + * It shall be at least 4 to receive the command status event in one frame. + * The default value is set to 27 to allow receiving an event of MTU size in a single buffer. This value maybe reduced + * further depending on the application. + */ +#define CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE 255 /**< Set to 255 with the memory manager and the mailbox */ + +#define TL_BLE_EVENT_FRAME_SIZE ( TL_EVT_HDR_SIZE + CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE ) +/****************************************************************************** + * UART interfaces + ******************************************************************************/ + +/** + * Select UART interfaces + */ +#define CFG_UART_GUI hw_uart1 +#define CFG_DEBUG_TRACE_UART 0 +/****************************************************************************** + * USB interface + ******************************************************************************/ + +/** + * Enable/Disable USB interface + */ +#define CFG_USB_INTERFACE_ENABLE 0 + +/****************************************************************************** + * IPCC interface + ******************************************************************************/ + +/** + * The IPCC is dedicated to the communication between the CPU2 and the CPU1 + * and shall not be modified by the application + * The two following definitions shall not be modified + */ +#define HAL_IPCC_TX_IRQHandler(...) HW_IPCC_Tx_Handler( ) +#define HAL_IPCC_RX_IRQHandler(...) HW_IPCC_Rx_Handler( ) + +/****************************************************************************** + * Low Power + ******************************************************************************/ +/** + * When set to 1, the low power mode is enable + * When set to 0, the device stays in RUN mode + */ +#define CFG_LPM_SUPPORTED 1 + +/****************************************************************************** + * RTC interface + ******************************************************************************/ +#define HAL_RTCEx_WakeUpTimerIRQHandler(...) HW_TS_RTC_Wakeup_Handler( ) + +/****************************************************************************** + * Timer Server + ******************************************************************************/ +/** + * CFG_RTC_WUCKSEL_DIVIDER: This sets the RTCCLK divider to the wakeup timer. + * The lower is the value, the better is the power consumption and the accuracy of the timerserver + * The higher is the value, the finest is the granularity + * + * CFG_RTC_ASYNCH_PRESCALER: This sets the asynchronous prescaler of the RTC. It should as high as possible ( to output + * clock as low as possible) but the output clock should be equal or higher frequency compare to the clock feeding + * the wakeup timer. A lower clock speed would impact the accuracy of the timer server. + * + * CFG_RTC_SYNCH_PRESCALER: This sets the synchronous prescaler of the RTC. + * When the 1Hz calendar clock is required, it shall be sets according to other settings + * When the 1Hz calendar clock is not needed, CFG_RTC_SYNCH_PRESCALER should be set to 0x7FFF (MAX VALUE) + * + * CFG_RTCCLK_DIVIDER_CONF: + * Shall be set to either 0,2,4,8,16 + * When set to either 2,4,8,16, the 1Hhz calendar is supported + * When set to 0, the user sets its own configuration + * + * The following settings are computed with LSI as input to the RTC + */ + +#define CFG_RTCCLK_DIVIDER_CONF 0 + +#if (CFG_RTCCLK_DIVIDER_CONF == 0) +/** + * Custom configuration + * It does not support 1Hz calendar + * It divides the RTC CLK by 16 + */ + +#define CFG_RTCCLK_DIV (16) +#define CFG_RTC_WUCKSEL_DIVIDER (0) +#define CFG_RTC_ASYNCH_PRESCALER (0x0F) +#define CFG_RTC_SYNCH_PRESCALER (0x7FFF) + +#else + +#if (CFG_RTCCLK_DIVIDER_CONF == 2) +/** + * It divides the RTC CLK by 2 + */ +#define CFG_RTC_WUCKSEL_DIVIDER (3) +#endif + +#if (CFG_RTCCLK_DIVIDER_CONF == 4) +/** + * It divides the RTC CLK by 4 + */ +#define CFG_RTC_WUCKSEL_DIVIDER (2) +#endif + +#if (CFG_RTCCLK_DIVIDER_CONF == 8) +/** + * It divides the RTC CLK by 8 + */ +#define CFG_RTC_WUCKSEL_DIVIDER (1) +#endif + +#if (CFG_RTCCLK_DIVIDER_CONF == 16) +/** + * It divides the RTC CLK by 16 + */ +#define CFG_RTC_WUCKSEL_DIVIDER (0) +#endif + +#define CFG_RTCCLK_DIV CFG_RTCCLK_DIVIDER_CONF +#define CFG_RTC_ASYNCH_PRESCALER (CFG_RTCCLK_DIV - 1) +#define CFG_RTC_SYNCH_PRESCALER (DIVR( LSE_VALUE, (CFG_RTC_ASYNCH_PRESCALER+1) ) - 1 ) + +#endif + +/** tick timer values */ +#define CFG_TS_TICK_VAL DIVR( (CFG_RTCCLK_DIV * 1000000), LSE_VALUE ) +#define CFG_TS_TICK_VAL_PS DIVR( ((uint64_t)CFG_RTCCLK_DIV * 1e12), (uint64_t)LSE_VALUE ) +typedef enum +{ + CFG_TIM_PROC_ID_ISR, + /* USER CODE BEGIN CFG_TimProcID_t */ + + /* USER CODE END CFG_TimProcID_t */ +} CFG_TimProcID_t; + +/****************************************************************************** + * Debug + ******************************************************************************/ /** - * LL Only Mode - * 1 : LL Only - * 0 : LL + Host + * When set, this resets some hw resources to set the device in the same state than the power up + * The FW resets only register that may prevent the FW to run properly + * + * This shall be set to 0 in a final product + * */ -#define CFG_BLE_LL_ONLY 1 +#define CFG_HW_RESET_BY_FW 1 + +/** + * keep debugger enabled while in any low power mode when set to 1 + * should be set to 0 in production + */ +#define CFG_DEBUGGER_SUPPORTED 0 + +/** + * When set to 1, the traces are enabled in the BLE services + */ +#define CFG_DEBUG_BLE_TRACE 0 + +/** + * Enable or Disable traces in application + */ +#define CFG_DEBUG_APP_TRACE 0 + +#if (CFG_DEBUG_APP_TRACE != 0) +#define APP_DBG_MSG PRINT_MESG_DBG +#else +#define APP_DBG_MSG PRINT_NO_MESG +#endif + +#if ( (CFG_DEBUG_BLE_TRACE != 0) || (CFG_DEBUG_APP_TRACE != 0) ) +#define CFG_DEBUG_TRACE 1 +#endif + +#if (CFG_DEBUG_TRACE != 0) +#undef CFG_LPM_SUPPORTED +#undef CFG_DEBUGGER_SUPPORTED +#define CFG_LPM_SUPPORTED 0 +#define CFG_DEBUGGER_SUPPORTED 1 +#endif + +/** + * When CFG_DEBUG_TRACE_FULL is set to 1, the trace are output with the API name, the file name and the line number + * When CFG_DEBUG_TRACE_LIGHT is set to 1, only the debug message is output + * + * When both are set to 0, no trace are output + * When both are set to 1, CFG_DEBUG_TRACE_FULL is selected + */ +#define CFG_DEBUG_TRACE_LIGHT 0 +#define CFG_DEBUG_TRACE_FULL 0 + +#if (( CFG_DEBUG_TRACE != 0 ) && ( CFG_DEBUG_TRACE_LIGHT == 0 ) && (CFG_DEBUG_TRACE_FULL == 0)) +#undef CFG_DEBUG_TRACE_FULL +#undef CFG_DEBUG_TRACE_LIGHT +#define CFG_DEBUG_TRACE_FULL 0 +#define CFG_DEBUG_TRACE_LIGHT 1 +#endif + +#if ( CFG_DEBUG_TRACE == 0 ) +#undef CFG_DEBUG_TRACE_FULL +#undef CFG_DEBUG_TRACE_LIGHT +#define CFG_DEBUG_TRACE_FULL 0 +#define CFG_DEBUG_TRACE_LIGHT 0 +#endif + +/** + * When not set, the traces is looping on sending the trace over UART + */ +#define DBG_TRACE_USE_CIRCULAR_QUEUE 1 + +/** + * max buffer Size to queue data traces and max data trace allowed. + * Only Used if DBG_TRACE_USE_CIRCULAR_QUEUE is defined + */ +#define DBG_TRACE_MSG_QUEUE_SIZE 4096 +#define MAX_DBG_TRACE_MSG_SIZE 1024 + +/* USER CODE BEGIN Defines */ +#define CFG_LED_SUPPORTED 1 +#define CFG_BUTTON_SUPPORTED 1 + +#define PUSH_BUTTON_SW1_EXTI_IRQHandler EXTI4_IRQHandler +#define PUSH_BUTTON_SW2_EXTI_IRQHandler EXTI0_IRQHandler +#define PUSH_BUTTON_SW3_EXTI_IRQHandler EXTI1_IRQHandler +/* USER CODE END Defines */ + +/****************************************************************************** + * Scheduler + ******************************************************************************/ + +/** + * These are the lists of task id registered to the scheduler + * Each task id shall be in the range [0:31] + * This mechanism allows to implement a generic code in the API TL_BLE_HCI_StatusNot() to comply with + * the requirement that a HCI/ACI command shall never be sent if there is already one pending + */ + +/**< Add in that list all tasks that may send a ACI/HCI command */ +typedef enum +{ + CFG_TASK_BLE_HCI_CMD_ID, + CFG_TASK_SYS_HCI_CMD_ID, + CFG_TASK_HCI_ACL_DATA_ID, + CFG_TASK_SYS_LOCAL_CMD_ID, + CFG_TASK_TX_TO_HOST_ID, + /* USER CODE BEGIN CFG_Task_Id_With_HCI_Cmd_t */ + CFG_TASK_SW1_BUTTON_PUSHED_ID, + CFG_TASK_SW2_BUTTON_PUSHED_ID, + CFG_TASK_SW3_BUTTON_PUSHED_ID, + /* USER CODE END CFG_Task_Id_With_HCI_Cmd_t */ + CFG_LAST_TASK_ID_WITH_HCICMD, /**< Shall be LAST in the list */ +} CFG_Task_Id_With_HCI_Cmd_t; + +/**< Add in that list all tasks that never send a ACI/HCI command */ +typedef enum +{ + CFG_FIRST_TASK_ID_WITH_NO_HCICMD = CFG_LAST_TASK_ID_WITH_HCICMD - 1, /**< Shall be FIRST in the list */ + CFG_TASK_SYSTEM_HCI_ASYNCH_EVT_ID, + /* USER CODE BEGIN CFG_Task_Id_With_NO_HCI_Cmd_t */ + + /* USER CODE END CFG_Task_Id_With_NO_HCI_Cmd_t */ + CFG_LAST_TASK_ID_WITHO_NO_HCICMD /**< Shall be LAST in the list */ +} CFG_Task_Id_With_NO_HCI_Cmd_t; + +#define CFG_TASK_NBR CFG_LAST_TASK_ID_WITHO_NO_HCICMD + +/** + * This is the list of priority required by the application + * Each Id shall be in the range 0..31 + */ +typedef enum +{ + CFG_SCH_PRIO_0, + CFG_PRIO_NBR, +} CFG_SCH_Prio_Id_t; + +/** + * This is a bit mapping over 32bits listing all events id supported in the application + */ +typedef enum +{ + CFG_IDLEEVT_SYSTEM_HCI_CMD_EVT_RSP_ID, +} CFG_IdleEvt_Id_t; + +/****************************************************************************** + * LOW POWER + ******************************************************************************/ +/** + * Supported requester to the MCU Low Power Manager - can be increased up to 32 + * It list a bit mapping of all user of the Low Power Manager + */ +typedef enum +{ + CFG_LPM_APP, + CFG_LPM_APP_BLE, + /* USER CODE BEGIN CFG_LPM_Id_t */ + + /* USER CODE END CFG_LPM_Id_t */ +} CFG_LPM_Id_t; + +/****************************************************************************** + * OTP manager + ******************************************************************************/ +#define CFG_OTP_BASE_ADDRESS OTP_AREA_BASE -#endif /* APP_CONF_DEFAULT_H */ +#define CFG_OTP_END_ADRESS OTP_AREA_END_ADDR -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ +#endif /*APP_CONF_H */ diff --git a/src/utility/STM32Cube_FW/ble_bufsize.h b/src/utility/STM32Cube_FW/ble_bufsize.h index 8930e401..ba9c4d3c 100644 --- a/src/utility/STM32Cube_FW/ble_bufsize.h +++ b/src/utility/STM32Cube_FW/ble_bufsize.h @@ -1,17 +1,16 @@ /***************************************************************************** * @file ble_bufsize.h - * @author MCD Application Team + * @author MCD * @brief Definition of BLE stack buffers size ***************************************************************************** * @attention * - * <h2><center>© Copyright (c) 2019 STMicroelectronics. - * All rights reserved.</center></h2> + * Copyright (c) 2018-2021 STMicroelectronics. + * All rights reserved. * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. * ***************************************************************************** */ @@ -25,11 +24,6 @@ */ #define BLE_DEFAULT_ATT_MTU 23 -/* - * BLE_DEFAULT_MAX_ATT_MTU: maximum supported ATT MTU size. - */ -#define BLE_DEFAULT_MAX_ATT_MTU 158 - /* * BLE_DEFAULT_MAX_ATT_SIZE: maximum attribute size. */ @@ -81,44 +75,45 @@ ((pw) + MAX(BLE_MEM_BLOCK_X_MTU(mtu, n_link), \ BLE_MBLOCKS_SECURE_CONNECTIONS)) -/* - * BLE_DEFAULT_MBLOCKS_COUNT: default memory blocks count - */ -#define BLE_DEFAULT_MBLOCKS_COUNT(n_link) \ - BLE_MBLOCKS_CALC(BLE_DEFAULT_PREP_WRITE_LIST_SIZE, \ - BLE_DEFAULT_MAX_ATT_MTU, n_link) - /* * BLE_FIXED_BUFFER_SIZE_BYTES: - * A part of the RAM, is dynamically allocated by initializing all the pointers + * A part of the RAM, is dinamically allocated by initilizing all the pointers * defined in a global context variable "mem_alloc_ctx_p". * This initialization is made in the Dynamic_allocator functions, which - * assign a portion of RAM given by the external application to the above + * assing a portion of RAM given by the external application to the above * mentioned "global pointers". * * The size of this Dynamic RAM is made of 2 main components: * - a part that is parameters-dependent (num of links, GATT buffers, ...), - * and which value is defined by the following macro; + * and which value is explicited by the following macro; * - a part, that may be considered "fixed", i.e. independent from the above * mentioned parameters. */ -#if (SLAVE_ONLY == 0) && (LL_ONLY == 0) -#define BLE_FIXED_BUFFER_SIZE_BYTES 6960 /* Full stack */ -#elif SLAVE_ONLY == 0 -#define BLE_FIXED_BUFFER_SIZE_BYTES 6256 /* LL only */ +#if (BEACON_ONLY != 0) +#define BLE_FIXED_BUFFER_SIZE_BYTES 4184 /* Beacon only */ +#elif (LL_ONLY != 0) +#define BLE_FIXED_BUFFER_SIZE_BYTES 6068 /* LL only */ +#elif (SLAVE_ONLY != 0) +#define BLE_FIXED_BUFFER_SIZE_BYTES 6096 /* Peripheral only */ +#elif (BASIC_FEATURES != 0) +#define BLE_FIXED_BUFFER_SIZE_BYTES 6400 /* Basic Features */ #else -#define BLE_FIXED_BUFFER_SIZE_BYTES 6696 /* Slave only */ +#define BLE_FIXED_BUFFER_SIZE_BYTES 7312 /* Full stack */ #endif /* * BLE_PER_LINK_SIZE_BYTES: additional memory size used per link */ -#if (SLAVE_ONLY == 0) && (LL_ONLY == 0) -#define BLE_PER_LINK_SIZE_BYTES 380 /* Full stack */ -#elif SLAVE_ONLY == 0 -#define BLE_PER_LINK_SIZE_BYTES 196 /* LL only */ +#if (BEACON_ONLY != 0) +#define BLE_PER_LINK_SIZE_BYTES 192 /* Beacon only */ +#elif (LL_ONLY != 0) +#define BLE_PER_LINK_SIZE_BYTES 260 /* LL only */ +#elif (SLAVE_ONLY != 0) +#define BLE_PER_LINK_SIZE_BYTES 388 /* Peripheral only */ +#elif (BASIC_FEATURES != 0) +#define BLE_PER_LINK_SIZE_BYTES 388 /* Basic Features */ #else -#define BLE_PER_LINK_SIZE_BYTES 332 /* Slave only */ +#define BLE_PER_LINK_SIZE_BYTES 444 /* Full stack */ #endif /* @@ -126,16 +121,24 @@ * needed for the storage of data structures (except GATT database elements) * whose size depends on the number of supported connections. * - * @param num_links: Maximum number of simultaneous connections that the device + * @param n_link: Maximum number of simultaneous connections that the device * will support. Valid values are from 1 to 8. * * @param mblocks_count: Number of memory blocks allocated for packets. */ #define BLE_TOTAL_BUFFER_SIZE(n_link, mblocks_count) \ - (BLE_FIXED_BUFFER_SIZE_BYTES + \ + (16 + BLE_FIXED_BUFFER_SIZE_BYTES + \ (BLE_PER_LINK_SIZE_BYTES * (n_link)) + \ ((BLE_MEM_BLOCK_SIZE + 12) * (mblocks_count))) +/* + * BLE_EXT_ADV_BUFFER_SIZE + * additional memory size used for Extended advertising; + * It has to be added to BLE_TOTAL_BUFFER_SIZE(). + * The formula used is based on:(1792 + ((set_nbr) * (60 + (2 * (data_len))))) + */ +#define BLE_EXT_ADV_BUFFER_SIZE(set_nbr, data_len) (7596) + /* * BLE_TOTAL_BUFFER_SIZE_GATT: this macro returns the amount of memory, * in bytes, needed for the storage of GATT database elements. @@ -158,4 +161,4 @@ (40 * (num_gatt_attributes)) + (48 * (num_gatt_services))) -#endif /* ! BLE_BUFSIZE_H__ */ +#endif /* BLE_BUFSIZE_H__ */ diff --git a/src/utility/STM32Cube_FW/hw.h b/src/utility/STM32Cube_FW/hw.h index a94bec9c..503fa2ca 100644 --- a/src/utility/STM32Cube_FW/hw.h +++ b/src/utility/STM32Cube_FW/hw.h @@ -6,13 +6,12 @@ ****************************************************************************** * @attention * - * <h2><center>© Copyright (c) 2019 STMicroelectronics. - * All rights reserved.</center></h2> + * Copyright (c) 2018-2021 STMicroelectronics. + * All rights reserved. * - * This software component is licensed by ST under BSD 3-Clause license, - * the "License"; You may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * opensource.org/licenses/BSD-3-Clause + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ @@ -27,21 +26,14 @@ extern "C" { #endif /* Includes ------------------------------------------------------------------*/ -#include "stm32_def.h" -#include "stm32wbxx_ll_bus.h" -#include "stm32wbxx_ll_exti.h" -#include "stm32wbxx_ll_system.h" -#include "stm32wbxx_ll_rcc.h" -#include "stm32wbxx_ll_ipcc.h" -#include "stm32wbxx_ll_cortex.h" -#include "stm32wbxx_ll_utils.h" -#include "stm32wbxx_ll_pwr.h" /****************************************************************************** * HW IPCC ******************************************************************************/ void HW_IPCC_Enable( void ); void HW_IPCC_Init( void ); + void HW_IPCC_Rx_Handler( void ); + void HW_IPCC_Tx_Handler( void ); void HW_IPCC_BLE_Init( void ); void HW_IPCC_BLE_SendCmd( void ); @@ -74,24 +66,40 @@ extern "C" { void HW_IPCC_LLDTESTS_SendM0CmdAck( void ); - void HW_IPCC_LLD_BLE_Init( void ); - void HW_IPCC_LLD_BLE_SendCliCmd( void ); - void HW_IPCC_LLD_BLE_ReceiveCliRsp( void ); - void HW_IPCC_LLD_BLE_SendCliRspAck( void ); - void HW_IPCC_LLD_BLE_ReceiveM0Cmd( void ); - void HW_IPCC_LLD_BLE_SendM0CmdAck( void ); - void HW_IPCC_LLD_BLE_SendCmd( void ); - void HW_IPCC_LLD_BLE_ReceiveRsp( void ); - void HW_IPCC_LLD_BLE_SendRspAck( void ); + void HW_IPCC_BLE_LLD_Init( void ); + void HW_IPCC_BLE_LLD_SendCliCmd( void ); + void HW_IPCC_BLE_LLD_ReceiveCliRsp( void ); + void HW_IPCC_BLE_LLD_SendCliRspAck( void ); + void HW_IPCC_BLE_LLD_ReceiveM0Cmd( void ); + void HW_IPCC_BLE_LLD_SendM0CmdAck( void ); + void HW_IPCC_BLE_LLD_SendCmd( void ); + void HW_IPCC_BLE_LLD_ReceiveRsp( void ); + void HW_IPCC_BLE_LLD_SendRspAck( void ); void HW_IPCC_TRACES_Init( void ); void HW_IPCC_TRACES_EvtNot( void ); + void HW_IPCC_MAC_802_15_4_Init( void ); + void HW_IPCC_MAC_802_15_4_SendCmd( void ); + void HW_IPCC_MAC_802_15_4_SendAck( void ); + void HW_IPCC_MAC_802_15_4_CmdEvtNot( void ); + void HW_IPCC_MAC_802_15_4_EvtNot( void ); + + void HW_IPCC_ZIGBEE_Init( void ); + + void HW_IPCC_ZIGBEE_SendM4RequestToM0(void); /* M4 Request to M0 */ + void HW_IPCC_ZIGBEE_RecvAppliAckFromM0(void); /* Request ACK from M0 */ + + void HW_IPCC_ZIGBEE_RecvM0NotifyToM4(void); /* M0 Notify to M4 */ + void HW_IPCC_ZIGBEE_SendM4AckToM0Notify(void); /* Notify ACK from M4 */ + void HW_IPCC_ZIGBEE_RecvM0RequestToM4(void); /* M0 Request to M4 */ + void HW_IPCC_ZIGBEE_SendM4AckToM0Request(void); /* Request ACK from M4 */ + + #ifdef __cplusplus } #endif #endif /*__HW_H */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/src/utility/STM32Cube_FW/hw_ipcc.c b/src/utility/STM32Cube_FW/hw_ipcc.c index 658aadb4..c5a941d2 100644 --- a/src/utility/STM32Cube_FW/hw_ipcc.c +++ b/src/utility/STM32Cube_FW/hw_ipcc.c @@ -1,24 +1,25 @@ +/* USER CODE BEGIN Header */ /** - ****************************************************************************** - * File Name : Target/hw_ipcc.c - * Description : Hardware IPCC source file for STM32WPAN Middleware. - * - ****************************************************************************** + ****************************************************************************** + * @file hw_ipcc.c + * @author MCD Application Team + * @brief Hardware IPCC source file for STM32WPAN Middleware. + ****************************************************************************** * @attention * - * <h2><center>© Copyright (c) 2020 STMicroelectronics. - * All rights reserved.</center></h2> + * Copyright (c) 2020-2021 STMicroelectronics. + * All rights reserved. * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ -#if defined(STM32WBxx) +/* USER CODE END Header */ + /* Includes ------------------------------------------------------------------*/ -#include "hw.h" +#include "app_common.h" #include "mbox_def.h" /* Global variables ---------------------------------------------------------*/ @@ -45,17 +46,44 @@ static void HW_IPCC_THREAD_NotEvtHandler( void ); static void HW_IPCC_THREAD_CliNotEvtHandler( void ); #endif +#ifdef LLD_TESTS_WB +static void HW_IPCC_LLDTESTS_ReceiveCliRspHandler( void ); +static void HW_IPCC_LLDTESTS_ReceiveM0CmdHandler( void ); +#endif +#ifdef LLD_BLE_WB +/*static void HW_IPCC_LLD_BLE_ReceiveCliRspHandler( void );*/ +static void HW_IPCC_LLD_BLE_ReceiveRspHandler( void ); +static void HW_IPCC_LLD_BLE_ReceiveM0CmdHandler( void ); +#endif + +#ifdef MAC_802_15_4_WB +static void HW_IPCC_MAC_802_15_4_CmdEvtHandler( void ); +static void HW_IPCC_MAC_802_15_4_NotEvtHandler( void ); +#endif + +#ifdef ZIGBEE_WB +static void HW_IPCC_ZIGBEE_CmdEvtHandler( void ); +static void HW_IPCC_ZIGBEE_StackNotifEvtHandler( void ); +static void HW_IPCC_ZIGBEE_StackM0RequestHandler( void ); +#endif + /* Public function definition -----------------------------------------------*/ /****************************************************************************** * INTERRUPT HANDLER ******************************************************************************/ -void IPCC_C1_RX_IRQHandler(void) +void HW_IPCC_Rx_Handler( void ) { if (HW_IPCC_RX_PENDING( HW_IPCC_SYSTEM_EVENT_CHANNEL )) { HW_IPCC_SYS_EvtHandler(); } +#ifdef MAC_802_15_4_WB + else if (HW_IPCC_RX_PENDING( HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL )) + { + HW_IPCC_MAC_802_15_4_NotEvtHandler(); + } +#endif /* MAC_802_15_4_WB */ #ifdef THREAD_WB else if (HW_IPCC_RX_PENDING( HW_IPCC_THREAD_NOTIFICATION_ACK_CHANNEL )) { @@ -66,6 +94,36 @@ void IPCC_C1_RX_IRQHandler(void) HW_IPCC_THREAD_CliNotEvtHandler(); } #endif /* THREAD_WB */ +#ifdef LLD_TESTS_WB + else if (HW_IPCC_RX_PENDING( HW_IPCC_LLDTESTS_CLI_RSP_CHANNEL )) + { + HW_IPCC_LLDTESTS_ReceiveCliRspHandler(); + } + else if (HW_IPCC_RX_PENDING( HW_IPCC_LLDTESTS_M0_CMD_CHANNEL )) + { + HW_IPCC_LLDTESTS_ReceiveM0CmdHandler(); + } +#endif /* LLD_TESTS_WB */ +#ifdef LLD_BLE_WB + else if (HW_IPCC_RX_PENDING( HW_IPCC_LLD_BLE_RSP_CHANNEL )) + { + HW_IPCC_LLD_BLE_ReceiveRspHandler(); + } + else if (HW_IPCC_RX_PENDING( HW_IPCC_LLD_BLE_M0_CMD_CHANNEL )) + { + HW_IPCC_LLD_BLE_ReceiveM0CmdHandler(); + } +#endif /* LLD_TESTS_WB */ +#ifdef ZIGBEE_WB + else if (HW_IPCC_RX_PENDING( HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL )) + { + HW_IPCC_ZIGBEE_StackNotifEvtHandler(); + } + else if (HW_IPCC_RX_PENDING( HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL )) + { + HW_IPCC_ZIGBEE_StackM0RequestHandler(); + } +#endif /* ZIGBEE_WB */ else if (HW_IPCC_RX_PENDING( HW_IPCC_BLE_EVENT_CHANNEL )) { HW_IPCC_BLE_EvtHandler(); @@ -74,24 +132,37 @@ void IPCC_C1_RX_IRQHandler(void) { HW_IPCC_TRACES_EvtHandler(); } + + return; } -void IPCC_C1_TX_IRQHandler(void) +void HW_IPCC_Tx_Handler( void ) { if (HW_IPCC_TX_PENDING( HW_IPCC_SYSTEM_CMD_RSP_CHANNEL )) { HW_IPCC_SYS_CmdEvtHandler(); } +#ifdef MAC_802_15_4_WB + else if (HW_IPCC_TX_PENDING( HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL )) + { + HW_IPCC_MAC_802_15_4_CmdEvtHandler(); + } +#endif /* MAC_802_15_4_WB */ #ifdef THREAD_WB else if (HW_IPCC_TX_PENDING( HW_IPCC_THREAD_OT_CMD_RSP_CHANNEL )) { HW_IPCC_OT_CmdEvtHandler(); } #endif /* THREAD_WB */ - else if (HW_IPCC_TX_PENDING( HW_IPCC_SYSTEM_CMD_RSP_CHANNEL )) +#ifdef LLD_TESTS_WB +// No TX handler for LLD tests +#endif /* LLD_TESTS_WB */ +#ifdef ZIGBEE_WB + if (HW_IPCC_TX_PENDING( HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL )) { - HW_IPCC_SYS_CmdEvtHandler(); + HW_IPCC_ZIGBEE_CmdEvtHandler(); } +#endif /* ZIGBEE_WB */ else if (HW_IPCC_TX_PENDING( HW_IPCC_MM_RELEASE_BUFFER_CHANNEL )) { HW_IPCC_MM_FreeBufHandler(); @@ -100,8 +171,9 @@ void IPCC_C1_TX_IRQHandler(void) { HW_IPCC_BLE_AclDataEvtHandler(); } -} + return; +} /****************************************************************************** * GENERAL ******************************************************************************/ @@ -113,7 +185,7 @@ void HW_IPCC_Enable( void ) */ LL_C2_AHB3_GRP1_EnableClock(LL_C2_AHB3_GRP1_PERIPH_IPCC); - /** + /** * When the device is out of standby, it is required to use the EXTI mechanism to wakeup CPU2 */ LL_C2_EXTI_EnableEvent_32_63( LL_EXTI_LINE_41 ); @@ -191,8 +263,8 @@ static void HW_IPCC_BLE_AclDataEvtHandler( void ) return; } -__WEAK void HW_IPCC_BLE_AclDataAckNot( void ){}; -__WEAK void HW_IPCC_BLE_RxEvtNot( void ){}; +__weak void HW_IPCC_BLE_AclDataAckNot( void ){}; +__weak void HW_IPCC_BLE_RxEvtNot( void ){}; /****************************************************************************** * SYSTEM @@ -230,8 +302,56 @@ static void HW_IPCC_SYS_EvtHandler( void ) return; } -__WEAK void HW_IPCC_SYS_CmdEvtNot( void ){}; -__WEAK void HW_IPCC_SYS_EvtNot( void ){}; +__weak void HW_IPCC_SYS_CmdEvtNot( void ){}; +__weak void HW_IPCC_SYS_EvtNot( void ){}; + +/****************************************************************************** + * MAC 802.15.4 + ******************************************************************************/ +#ifdef MAC_802_15_4_WB +void HW_IPCC_MAC_802_15_4_Init( void ) +{ + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL ); + + return; +} + +void HW_IPCC_MAC_802_15_4_SendCmd( void ) +{ + LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL ); + LL_C1_IPCC_EnableTransmitChannel( IPCC, HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL ); + + return; +} + +void HW_IPCC_MAC_802_15_4_SendAck( void ) +{ + LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL ); + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL ); + + return; +} + +static void HW_IPCC_MAC_802_15_4_CmdEvtHandler( void ) +{ + LL_C1_IPCC_DisableTransmitChannel( IPCC, HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL ); + + HW_IPCC_MAC_802_15_4_CmdEvtNot(); + + return; +} + +static void HW_IPCC_MAC_802_15_4_NotEvtHandler( void ) +{ + LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL ); + + HW_IPCC_MAC_802_15_4_EvtNot(); + + return; +} +__weak void HW_IPCC_MAC_802_15_4_CmdEvtNot( void ){}; +__weak void HW_IPCC_MAC_802_15_4_EvtNot( void ){}; +#endif /****************************************************************************** * THREAD @@ -303,12 +423,198 @@ static void HW_IPCC_THREAD_CliNotEvtHandler( void ) return; } -__WEAK void HW_IPCC_OT_CmdEvtNot( void ){}; -__WEAK void HW_IPCC_CLI_CmdEvtNot( void ){}; -__WEAK void HW_IPCC_THREAD_EvtNot( void ){}; +__weak void HW_IPCC_OT_CmdEvtNot( void ){}; +__weak void HW_IPCC_CLI_CmdEvtNot( void ){}; +__weak void HW_IPCC_THREAD_EvtNot( void ){}; #endif /* THREAD_WB */ +/****************************************************************************** + * LLD TESTS + ******************************************************************************/ +#ifdef LLD_TESTS_WB +void HW_IPCC_LLDTESTS_Init( void ) +{ + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_LLDTESTS_CLI_RSP_CHANNEL ); + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_LLDTESTS_M0_CMD_CHANNEL ); + return; +} + +void HW_IPCC_LLDTESTS_SendCliCmd( void ) +{ + LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_LLDTESTS_CLI_CMD_CHANNEL ); + return; +} + +static void HW_IPCC_LLDTESTS_ReceiveCliRspHandler( void ) +{ + LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_LLDTESTS_CLI_RSP_CHANNEL ); + HW_IPCC_LLDTESTS_ReceiveCliRsp(); + return; +} + +void HW_IPCC_LLDTESTS_SendCliRspAck( void ) +{ + LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_LLDTESTS_CLI_RSP_CHANNEL ); + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_LLDTESTS_CLI_RSP_CHANNEL ); + return; +} + +static void HW_IPCC_LLDTESTS_ReceiveM0CmdHandler( void ) +{ + LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_LLDTESTS_M0_CMD_CHANNEL ); + HW_IPCC_LLDTESTS_ReceiveM0Cmd(); + return; +} + +void HW_IPCC_LLDTESTS_SendM0CmdAck( void ) +{ + LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_LLDTESTS_M0_CMD_CHANNEL ); + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_LLDTESTS_M0_CMD_CHANNEL ); + return; +} +__weak void HW_IPCC_LLDTESTS_ReceiveCliRsp( void ){}; +__weak void HW_IPCC_LLDTESTS_ReceiveM0Cmd( void ){}; +#endif /* LLD_TESTS_WB */ + +/****************************************************************************** + * LLD BLE + ******************************************************************************/ +#ifdef LLD_BLE_WB +void HW_IPCC_LLD_BLE_Init( void ) +{ + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_LLD_BLE_RSP_CHANNEL ); + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_LLD_BLE_M0_CMD_CHANNEL ); + return; +} + +void HW_IPCC_LLD_BLE_SendCliCmd( void ) +{ + LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_LLD_BLE_CLI_CMD_CHANNEL ); + return; +} + +/*static void HW_IPCC_LLD_BLE_ReceiveCliRspHandler( void ) +{ + LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_LLD_BLE_CLI_RSP_CHANNEL ); + HW_IPCC_LLD_BLE_ReceiveCliRsp(); + return; +}*/ + +void HW_IPCC_LLD_BLE_SendCliRspAck( void ) +{ + LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_LLD_BLE_CLI_RSP_CHANNEL ); + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_LLD_BLE_CLI_RSP_CHANNEL ); + return; +} + +static void HW_IPCC_LLD_BLE_ReceiveM0CmdHandler( void ) +{ + //LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_LLD_BLE_M0_CMD_CHANNEL ); + HW_IPCC_LLD_BLE_ReceiveM0Cmd(); + return; +} + +void HW_IPCC_LLD_BLE_SendM0CmdAck( void ) +{ + LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_LLD_BLE_M0_CMD_CHANNEL ); + //LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_LLD_BLE_M0_CMD_CHANNEL ); + return; +} +__weak void HW_IPCC_LLD_BLE_ReceiveCliRsp( void ){}; +__weak void HW_IPCC_LLD_BLE_ReceiveM0Cmd( void ){}; + +/* Transparent Mode */ +void HW_IPCC_LLD_BLE_SendCmd( void ) +{ + LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_LLD_BLE_CMD_CHANNEL ); + return; +} + +static void HW_IPCC_LLD_BLE_ReceiveRspHandler( void ) +{ + LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_LLD_BLE_RSP_CHANNEL ); + HW_IPCC_LLD_BLE_ReceiveRsp(); + return; +} + +void HW_IPCC_LLD_BLE_SendRspAck( void ) +{ + LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_LLD_BLE_RSP_CHANNEL ); + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_LLD_BLE_RSP_CHANNEL ); + return; +} + +#endif /* LLD_BLE_WB */ + +/****************************************************************************** + * ZIGBEE + ******************************************************************************/ +#ifdef ZIGBEE_WB +void HW_IPCC_ZIGBEE_Init( void ) +{ + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL ); + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL ); + + return; +} + +void HW_IPCC_ZIGBEE_SendM4RequestToM0( void ) +{ + LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL ); + LL_C1_IPCC_EnableTransmitChannel( IPCC, HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL ); + + return; +} + +void HW_IPCC_ZIGBEE_SendM4AckToM0Notify( void ) +{ + LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL ); + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL ); + + return; +} + +static void HW_IPCC_ZIGBEE_CmdEvtHandler( void ) +{ + LL_C1_IPCC_DisableTransmitChannel( IPCC, HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL ); + + HW_IPCC_ZIGBEE_RecvAppliAckFromM0(); + + return; +} + +static void HW_IPCC_ZIGBEE_StackNotifEvtHandler( void ) +{ + LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL ); + + HW_IPCC_ZIGBEE_RecvM0NotifyToM4(); + + return; +} + +static void HW_IPCC_ZIGBEE_StackM0RequestHandler( void ) +{ + LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL ); + + HW_IPCC_ZIGBEE_RecvM0RequestToM4(); + + return; +} + +void HW_IPCC_ZIGBEE_SendM4AckToM0Request( void ) +{ + LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL ); + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL ); + + return; +} + +__weak void HW_IPCC_ZIGBEE_RecvAppliAckFromM0( void ){}; +__weak void HW_IPCC_ZIGBEE_RecvM0NotifyToM4( void ){}; +__weak void HW_IPCC_ZIGBEE_RecvM0RequestToM4( void ){}; +#endif /* ZIGBEE_WB */ + /****************************************************************************** * MEMORY MANAGER ******************************************************************************/ @@ -359,6 +665,4 @@ static void HW_IPCC_TRACES_EvtHandler( void ) return; } -__WEAK void HW_IPCC_TRACES_EvtNot( void ){}; -#endif /* STM32WBxx */ -/******************* (C) COPYRIGHT 2019 STMicroelectronics *****END OF FILE****/ +__weak void HW_IPCC_TRACES_EvtNot( void ){}; diff --git a/src/utility/STM32Cube_FW/mbox_def.h b/src/utility/STM32Cube_FW/mbox_def.h index 6bddf696..06536d34 100644 --- a/src/utility/STM32Cube_FW/mbox_def.h +++ b/src/utility/STM32Cube_FW/mbox_def.h @@ -4,17 +4,16 @@ * @author MCD Application Team * @brief Mailbox definition ****************************************************************************** - * @attention - * - * <h2><center>© Copyright (c) 2019 STMicroelectronics. - * All rights reserved.</center></h2> - * - * This software component is licensed by ST under BSD 3-Clause license, - * the "License"; You may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * opensource.org/licenses/BSD-3-Clause - * - ****************************************************************************** + * @attention + * + * Copyright (c) 2018-2021 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** */ @@ -104,8 +103,14 @@ extern "C" { { uint8_t *cmdrsp_buffer; uint8_t *m0cmd_buffer; - } MB_LldBleTable_t; + } MB_BleLldTable_t; + typedef struct + { + uint8_t *notifM0toM4_buffer; + uint8_t *appliCmdM4toM0_buffer; + uint8_t *requestM0toM4_buffer; + } MB_ZigbeeTable_t; /** * msg * [0:7] = cmd/evt @@ -133,6 +138,13 @@ extern "C" { uint8_t *traces_queue; } MB_TracesTable_t; + typedef struct + { + uint8_t *p_cmdrsp_buffer; + uint8_t *p_notack_buffer; + uint8_t *evt_queue; + } MB_Mac_802_15_4_t; + typedef struct { MB_DeviceInfoTable_t *p_device_info_table; @@ -141,10 +153,35 @@ extern "C" { MB_SysTable_t *p_sys_table; MB_MemManagerTable_t *p_mem_manager_table; MB_TracesTable_t *p_traces_table; + MB_Mac_802_15_4_t *p_mac_802_15_4_table; + MB_ZigbeeTable_t *p_zigbee_table; MB_LldTestsTable_t *p_lld_tests_table; - MB_LldBleTable_t *p_lld_ble_table; + MB_BleLldTable_t *p_ble_lld_table; } MB_RefTable_t; +/** + * This table shall be used only in the case the CPU2 runs the FUS. + * It is used by the command SHCI_GetWirelessFwInfo() + */ +typedef struct +{ + uint32_t DeviceInfoTableState; + uint8_t Reserved1; + uint8_t LastFusActiveState; + uint8_t LastWirelessStackState; + uint8_t CurrentWirelessStackType; + uint32_t SafeBootVersion; + uint32_t FusVersion; + uint32_t FusMemorySize; + uint32_t WirelessStackVersion; + uint32_t WirelessStackMemorySize; + uint32_t WirelessFirmwareBleInfo; + uint32_t WirelessFirmwareThreadInfo; + uint32_t Reserved2; + uint64_t UID64; + uint16_t DeviceId; +} MB_FUS_DeviceInfoTable_t ; + #ifdef __cplusplus } #endif @@ -161,6 +198,15 @@ extern "C" { * | | * |<---HW_IPCC_SYSTEM_EVENT_CHANNEL-----------------| * | | + * | (ZIGBEE) | + * |----HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL------------>| + * | | + * |----HW_IPCC_ZIGBEE_CMD_CLI_CHANNEL-------------->| + * | | + * |<---HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL-------| + * | | + * |<---HW_IPCC_ZIGBEE_CLI_NOTIF_ACK_CHANNEL---------| + * | | * | (THREAD) | * |----HW_IPCC_THREAD_OT_CMD_RSP_CHANNEL----------->| * | | @@ -177,12 +223,17 @@ extern "C" { * | | * |<---HW_IPCC_BLE_EVENT_CHANNEL--------------------| * | | - * | (LLD BLE) | - * |----HW_IPCC_LLD_BLE_CMD_CHANNEL----------------->| + * | (BLE LLD) | + * |----HW_IPCC_BLE_LLD_CMD_CHANNEL----------------->| + * | | + * |<---HW_IPCC_BLE_LLD_RSP_CHANNEL------------------| + * | | + * |<---HW_IPCC_BLE_LLD_M0_CMD_CHANNEL---------------| * | | - * |<---HW_IPCC_LLD_BLE_RSP_CHANNEL------------------| + * | (MAC) | + * |----HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL-------->| * | | - * |<---HW_IPCC_LLD_BLE_M0_CMD_CHANNEL---------------| + * |<---HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL| * | | * | (BUFFER) | * |----HW_IPCC_MM_RELEASE_BUFFER_CHANNE------------>| @@ -201,24 +252,28 @@ extern "C" { #define HW_IPCC_BLE_CMD_CHANNEL LL_IPCC_CHANNEL_1 #define HW_IPCC_SYSTEM_CMD_RSP_CHANNEL LL_IPCC_CHANNEL_2 #define HW_IPCC_THREAD_OT_CMD_RSP_CHANNEL LL_IPCC_CHANNEL_3 +#define HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL LL_IPCC_CHANNEL_3 +#define HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL LL_IPCC_CHANNEL_3 #define HW_IPCC_MM_RELEASE_BUFFER_CHANNEL LL_IPCC_CHANNEL_4 #define HW_IPCC_THREAD_CLI_CMD_CHANNEL LL_IPCC_CHANNEL_5 #define HW_IPCC_LLDTESTS_CLI_CMD_CHANNEL LL_IPCC_CHANNEL_5 -#define HW_IPCC_LLD_BLE_CLI_CMD_CHANNEL LL_IPCC_CHANNEL_5 -#define HW_IPCC_LLD_BLE_CMD_CHANNEL LL_IPCC_CHANNEL_5 +#define HW_IPCC_BLE_LLD_CLI_CMD_CHANNEL LL_IPCC_CHANNEL_5 +#define HW_IPCC_BLE_LLD_CMD_CHANNEL LL_IPCC_CHANNEL_5 #define HW_IPCC_HCI_ACL_DATA_CHANNEL LL_IPCC_CHANNEL_6 /** CPU2 */ #define HW_IPCC_BLE_EVENT_CHANNEL LL_IPCC_CHANNEL_1 #define HW_IPCC_SYSTEM_EVENT_CHANNEL LL_IPCC_CHANNEL_2 #define HW_IPCC_THREAD_NOTIFICATION_ACK_CHANNEL LL_IPCC_CHANNEL_3 +#define HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL LL_IPCC_CHANNEL_3 +#define HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL LL_IPCC_CHANNEL_3 #define HW_IPCC_LLDTESTS_M0_CMD_CHANNEL LL_IPCC_CHANNEL_3 -#define HW_IPCC_LLD_BLE_M0_CMD_CHANNEL LL_IPCC_CHANNEL_3 +#define HW_IPCC_BLE_LLD_M0_CMD_CHANNEL LL_IPCC_CHANNEL_3 #define HW_IPCC_TRACES_CHANNEL LL_IPCC_CHANNEL_4 #define HW_IPCC_THREAD_CLI_NOTIFICATION_ACK_CHANNEL LL_IPCC_CHANNEL_5 #define HW_IPCC_LLDTESTS_CLI_RSP_CHANNEL LL_IPCC_CHANNEL_5 -#define HW_IPCC_LLD_BLE_CLI_RSP_CHANNEL LL_IPCC_CHANNEL_5 -#define HW_IPCC_LLD_BLE_RSP_CHANNEL LL_IPCC_CHANNEL_5 +#define HW_IPCC_BLE_LLD_CLI_RSP_CHANNEL LL_IPCC_CHANNEL_5 +#define HW_IPCC_BLE_LLD_RSP_CHANNEL LL_IPCC_CHANNEL_5 +#define HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL LL_IPCC_CHANNEL_5 #endif /*__MBOX_H */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/src/utility/STM32Cube_FW/shci.c b/src/utility/STM32Cube_FW/shci.c index b848dd85..301db76d 100644 --- a/src/utility/STM32Cube_FW/shci.c +++ b/src/utility/STM32Cube_FW/shci.c @@ -4,20 +4,19 @@ * @author MCD Application Team * @brief HCI command for the system channel ****************************************************************************** - * @attention - * - * <h2><center>© Copyright (c) 2019 STMicroelectronics. - * All rights reserved.</center></h2> - * - * This software component is licensed by ST under BSD 3-Clause license, - * the "License"; You may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * opensource.org/licenses/BSD-3-Clause - * - ****************************************************************************** + * @attention + * + * Copyright (c) 2018-2021 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** */ -#if defined(STM32WBxx) + /* Includes ------------------------------------------------------------------*/ #include "stm32_wpan_common.h" @@ -223,7 +222,6 @@ SHCI_CmdStatus_t SHCI_C2_FUS_StartWs( void ) return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); } - SHCI_CmdStatus_t SHCI_C2_FUS_LockUsrKey( uint8_t key_index ) { /** @@ -244,6 +242,44 @@ SHCI_CmdStatus_t SHCI_C2_FUS_LockUsrKey( uint8_t key_index ) return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); } +SHCI_CmdStatus_t SHCI_C2_FUS_UnloadUsrKey( uint8_t key_index ) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + local_buffer[0] = key_index; + + shci_send( SHCI_OPCODE_C2_FUS_UNLOAD_USR_KEY, + 1, + local_buffer, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_FUS_ActivateAntiRollback( void ) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send( SHCI_OPCODE_C2_FUS_ACTIVATE_ANTIROLLBACK, + 0, + 0, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + SHCI_CmdStatus_t SHCI_C2_BLE_Init( SHCI_C2_Ble_Init_Cmd_Packet_t *pCmdPacket ) { /** @@ -298,7 +334,7 @@ SHCI_CmdStatus_t SHCI_C2_LLDTESTS_Init( uint8_t param_size, uint8_t * p_param ) return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); } -SHCI_CmdStatus_t SHCI_C2_LLD_BLE_Init( uint8_t param_size, uint8_t * p_param ) +SHCI_CmdStatus_t SHCI_C2_BLE_LLD_Init( uint8_t param_size, uint8_t * p_param ) { /** * Buffer is large enough to hold command complete without payload @@ -308,7 +344,7 @@ SHCI_CmdStatus_t SHCI_C2_LLD_BLE_Init( uint8_t param_size, uint8_t * p_param ) p_rsp = (TL_EvtPacket_t *)local_buffer; - shci_send( SHCI_OPCODE_C2_LLD_BLE_INIT, + shci_send( SHCI_OPCODE_C2_BLE_LLD_INIT, param_size, p_param, p_rsp ); @@ -316,6 +352,24 @@ SHCI_CmdStatus_t SHCI_C2_LLD_BLE_Init( uint8_t param_size, uint8_t * p_param ) return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); } +SHCI_CmdStatus_t SHCI_C2_ZIGBEE_Init( void ) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send( SHCI_OPCODE_C2_ZIGBEE_INIT, + 0, + 0, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + SHCI_CmdStatus_t SHCI_C2_DEBUG_Init( SHCI_C2_DEBUG_Init_Cmd_Packet_t *pCmdPacket ) { /** @@ -374,6 +428,44 @@ SHCI_CmdStatus_t SHCI_C2_CONCURRENT_SetMode( SHCI_C2_CONCURRENT_Mode_Param_t Mod return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); } +SHCI_CmdStatus_t SHCI_C2_CONCURRENT_GetNextBleEvtTime( SHCI_C2_CONCURRENT_GetNextBleEvtTime_Param_t *pParam ) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE+4]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send( SHCI_OPCODE_C2_CONCURRENT_GET_NEXT_BLE_EVT_TIME, + 0, + 0, + p_rsp ); + + memcpy((void*)&(pParam->relative_time), (void*)&((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[1], sizeof(pParam->relative_time)); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_CONCURRENT_EnableNext_802154_EvtNotification( void ) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send( SHCI_OPCODE_C2_CONCURRENT_ENABLE_NEXT_802154_EVT_NOTIFICATION, + 0, + 0, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + SHCI_CmdStatus_t SHCI_C2_FLASH_StoreData( SHCI_C2_FLASH_Ip_t Ip ) { /** @@ -435,6 +527,24 @@ SHCI_CmdStatus_t SHCI_C2_RADIO_AllowLowPower( SHCI_C2_FLASH_Ip_t Ip,uint8_t Fla return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); } +SHCI_CmdStatus_t SHCI_C2_MAC_802_15_4_Init( void ) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send( SHCI_OPCODE_C2_MAC_802_15_4_INIT, + 0, + 0, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + SHCI_CmdStatus_t SHCI_C2_Reinit( void ) { /** @@ -516,6 +626,23 @@ SHCI_CmdStatus_t SHCI_C2_Config(SHCI_C2_CONFIG_Cmd_Param_t *pCmdPacket) return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); } +SHCI_CmdStatus_t SHCI_C2_802_15_4_DeInit( void ) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send( SHCI_OPCODE_C2_802_15_4_DEINIT, + 0, + 0, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} /** * Local System COMMAND @@ -526,48 +653,89 @@ SHCI_CmdStatus_t SHCI_GetWirelessFwInfo( WirelessFwInfo_t* pWirelessInfo ) { uint32_t ipccdba = 0; MB_RefTable_t * p_RefTable = NULL; - uint32_t version = 0; - uint32_t memorySize = 0; - uint32_t infoStack = 0; + uint32_t wireless_firmware_version = 0; + uint32_t wireless_firmware_memorySize = 0; + uint32_t wireless_firmware_infoStack = 0; + MB_FUS_DeviceInfoTable_t * p_fus_device_info_table = NULL; + uint32_t fus_version = 0; + uint32_t fus_memorySize = 0; ipccdba = READ_BIT( FLASH->IPCCBR, FLASH_IPCCBR_IPCCDBA ); - p_RefTable = (MB_RefTable_t*)((ipccdba<<2) + SRAM2A_BASE); + + /** + * The Device Info Table mapping depends on which firmware is running on CPU2. + * If the FUS is running on CPU2, FUS_DEVICE_INFO_TABLE_VALIDITY_KEYWORD shall be written in the table. + * Otherwise, it means the Wireless Firmware is running on the CPU2 + */ + p_fus_device_info_table = (MB_FUS_DeviceInfoTable_t*)(*(uint32_t*)((ipccdba<<2) + SRAM2A_BASE)); + + if(p_fus_device_info_table->DeviceInfoTableState == FUS_DEVICE_INFO_TABLE_VALIDITY_KEYWORD) + { + /* The FUS is running on CPU2 */ + /** + * Retrieve the WirelessFwInfoTable + * This table is stored in RAM at startup during the TL (transport layer) initialization + */ + wireless_firmware_version = p_fus_device_info_table->WirelessStackVersion; + wireless_firmware_memorySize = p_fus_device_info_table->WirelessStackMemorySize; + wireless_firmware_infoStack = p_fus_device_info_table->WirelessFirmwareBleInfo; + + /** + * Retrieve the FusInfoTable + * This table is stored in RAM at startup during the TL (transport layer) initialization + */ + fus_version = p_fus_device_info_table->FusVersion; + fus_memorySize = p_fus_device_info_table->FusMemorySize; + } + else + { + /* The Wireless Firmware is running on CPU2 */ + p_RefTable = (MB_RefTable_t*)((ipccdba<<2) + SRAM2A_BASE); + + /** + * Retrieve the WirelessFwInfoTable + * This table is stored in RAM at startup during the TL (transport layer) initialization + */ + wireless_firmware_version = p_RefTable->p_device_info_table->WirelessFwInfoTable.Version; + wireless_firmware_memorySize = p_RefTable->p_device_info_table->WirelessFwInfoTable.MemorySize; + wireless_firmware_infoStack = p_RefTable->p_device_info_table->WirelessFwInfoTable.InfoStack; + + /** + * Retrieve the FusInfoTable + * This table is stored in RAM at startup during the TL (transport layer) initialization + */ + fus_version = p_RefTable->p_device_info_table->FusInfoTable.Version; + fus_memorySize = p_RefTable->p_device_info_table->FusInfoTable.MemorySize; + } /** * Retrieve the WirelessFwInfoTable * This table is stored in RAM at startup during the TL (transport layer) initialization */ - version = p_RefTable->p_device_info_table->WirelessFwInfoTable.Version; - pWirelessInfo->VersionMajor = ((version & INFO_VERSION_MAJOR_MASK) >> INFO_VERSION_MAJOR_OFFSET); - pWirelessInfo->VersionMinor = ((version & INFO_VERSION_MINOR_MASK) >> INFO_VERSION_MINOR_OFFSET); - pWirelessInfo->VersionSub = ((version & INFO_VERSION_SUB_MASK) >> INFO_VERSION_SUB_OFFSET); - pWirelessInfo->VersionBranch = ((version & INFO_VERSION_BRANCH_MASK) >> INFO_VERSION_BRANCH_OFFSET); - pWirelessInfo->VersionReleaseType = ((version & INFO_VERSION_TYPE_MASK) >> INFO_VERSION_TYPE_OFFSET); + pWirelessInfo->VersionMajor = ((wireless_firmware_version & INFO_VERSION_MAJOR_MASK) >> INFO_VERSION_MAJOR_OFFSET); + pWirelessInfo->VersionMinor = ((wireless_firmware_version & INFO_VERSION_MINOR_MASK) >> INFO_VERSION_MINOR_OFFSET); + pWirelessInfo->VersionSub = ((wireless_firmware_version & INFO_VERSION_SUB_MASK) >> INFO_VERSION_SUB_OFFSET); + pWirelessInfo->VersionBranch = ((wireless_firmware_version & INFO_VERSION_BRANCH_MASK) >> INFO_VERSION_BRANCH_OFFSET); + pWirelessInfo->VersionReleaseType = ((wireless_firmware_version & INFO_VERSION_TYPE_MASK) >> INFO_VERSION_TYPE_OFFSET); - memorySize = p_RefTable->p_device_info_table->WirelessFwInfoTable.MemorySize; - pWirelessInfo->MemorySizeSram2B = ((memorySize & INFO_SIZE_SRAM2B_MASK) >> INFO_SIZE_SRAM2B_OFFSET); - pWirelessInfo->MemorySizeSram2A = ((memorySize & INFO_SIZE_SRAM2A_MASK) >> INFO_SIZE_SRAM2A_OFFSET); - pWirelessInfo->MemorySizeSram1 = ((memorySize & INFO_SIZE_SRAM1_MASK) >> INFO_SIZE_SRAM1_OFFSET); - pWirelessInfo->MemorySizeFlash = ((memorySize & INFO_SIZE_FLASH_MASK) >> INFO_SIZE_FLASH_OFFSET); + pWirelessInfo->MemorySizeSram2B = ((wireless_firmware_memorySize & INFO_SIZE_SRAM2B_MASK) >> INFO_SIZE_SRAM2B_OFFSET); + pWirelessInfo->MemorySizeSram2A = ((wireless_firmware_memorySize & INFO_SIZE_SRAM2A_MASK) >> INFO_SIZE_SRAM2A_OFFSET); + pWirelessInfo->MemorySizeSram1 = ((wireless_firmware_memorySize & INFO_SIZE_SRAM1_MASK) >> INFO_SIZE_SRAM1_OFFSET); + pWirelessInfo->MemorySizeFlash = ((wireless_firmware_memorySize & INFO_SIZE_FLASH_MASK) >> INFO_SIZE_FLASH_OFFSET); - infoStack = p_RefTable->p_device_info_table->WirelessFwInfoTable.InfoStack; - pWirelessInfo->StackType = ((infoStack & INFO_STACK_TYPE_MASK) >> INFO_STACK_TYPE_OFFSET); + pWirelessInfo->StackType = ((wireless_firmware_infoStack & INFO_STACK_TYPE_MASK) >> INFO_STACK_TYPE_OFFSET); /** * Retrieve the FusInfoTable * This table is stored in RAM at startup during the TL (transport layer) initialization */ - version = p_RefTable->p_device_info_table->FusInfoTable.Version; - pWirelessInfo->FusVersionMajor = ((version & INFO_VERSION_MAJOR_MASK) >> INFO_VERSION_MAJOR_OFFSET); - pWirelessInfo->FusVersionMinor = ((version & INFO_VERSION_MINOR_MASK) >> INFO_VERSION_MINOR_OFFSET); - pWirelessInfo->FusVersionSub = ((version & INFO_VERSION_SUB_MASK) >> INFO_VERSION_SUB_OFFSET); + pWirelessInfo->FusVersionMajor = ((fus_version & INFO_VERSION_MAJOR_MASK) >> INFO_VERSION_MAJOR_OFFSET); + pWirelessInfo->FusVersionMinor = ((fus_version & INFO_VERSION_MINOR_MASK) >> INFO_VERSION_MINOR_OFFSET); + pWirelessInfo->FusVersionSub = ((fus_version & INFO_VERSION_SUB_MASK) >> INFO_VERSION_SUB_OFFSET); - memorySize = p_RefTable->p_device_info_table->FusInfoTable.MemorySize; - pWirelessInfo->FusMemorySizeSram2B = ((memorySize & INFO_SIZE_SRAM2B_MASK) >> INFO_SIZE_SRAM2B_OFFSET); - pWirelessInfo->FusMemorySizeSram2A = ((memorySize & INFO_SIZE_SRAM2A_MASK) >> INFO_SIZE_SRAM2A_OFFSET); - pWirelessInfo->FusMemorySizeFlash = ((memorySize & INFO_SIZE_FLASH_MASK) >> INFO_SIZE_FLASH_OFFSET); + pWirelessInfo->FusMemorySizeSram2B = ((fus_memorySize & INFO_SIZE_SRAM2B_MASK) >> INFO_SIZE_SRAM2B_OFFSET); + pWirelessInfo->FusMemorySizeSram2A = ((fus_memorySize & INFO_SIZE_SRAM2A_MASK) >> INFO_SIZE_SRAM2A_OFFSET); + pWirelessInfo->FusMemorySizeFlash = ((fus_memorySize & INFO_SIZE_FLASH_MASK) >> INFO_SIZE_FLASH_OFFSET); return (SHCI_Success); } -#endif /* STM32WBxx */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/src/utility/STM32Cube_FW/shci.h b/src/utility/STM32Cube_FW/shci.h index 11c53ced..c08f056f 100644 --- a/src/utility/STM32Cube_FW/shci.h +++ b/src/utility/STM32Cube_FW/shci.h @@ -4,17 +4,16 @@ * @author MCD Application Team * @brief HCI command for the system channel ****************************************************************************** - * @attention - * - * <h2><center>© Copyright (c) 2019 STMicroelectronics. - * All rights reserved.</center></h2> - * - * This software component is licensed by ST under BSD 3-Clause license, - * the "License"; You may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * opensource.org/licenses/BSD-3-Clause - * - ****************************************************************************** + * @attention + * + * Copyright (c) 2018-2021 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** */ @@ -35,21 +34,22 @@ extern "C" { typedef enum { WIRELESS_FW_RUNNING = 0x00, - RSS_FW_RUNNING = 0x01, + FUS_FW_RUNNING = 0x01, } SHCI_SysEvt_Ready_Rsp_t; /* ERROR CODES * - * These error codes are detected on M0 side and are send back to the M4 via a system - * notification message. It is up to the application running on M4 to manage these errors + * These error codes are detected on CPU2 side and are send back to the CPU1 via a system + * notification message. It is up to the application running on CPU1 to manage these errors * * These errors can be generated by all layers (low level driver, stack, framework infrastructure, etc..) */ typedef enum { - ERR_BLE_INIT = 0, - ERR_THREAD_LLD_FATAL_ERROR = 125, /* The LLD driver used on 802_15_4 detected a fatal error */ - ERR_THREAD_UNKNOWN_CMD = 126, /* The command send by the M4 to control the Thread stack is unknown */ + ERR_BLE_INIT = 0, /* This event is currently not reported by the CPU2 */ + ERR_THREAD_LLD_FATAL_ERROR = 125, /* The LLD driver used on 802_15_4 detected a fatal error */ + ERR_THREAD_UNKNOWN_CMD = 126, /* The command send by the CPU1 to control the Thread stack is unknown */ + ERR_ZIGBEE_UNKNOWN_CMD = 200, /* The command send by the CPU1 to control the Zigbee stack is unknown */ } SCHI_SystemErrCode_t; #define SHCI_EVTCODE ( 0xFF ) @@ -63,11 +63,12 @@ extern "C" { SHCI_SUB_EVT_CODE_READY = SHCI_SUB_EVT_CODE_BASE, SHCI_SUB_EVT_ERROR_NOTIF, SHCI_SUB_EVT_BLE_NVM_RAM_UPDATE, - SHCI_SUB_EVT_OT_NVM_RAM_UPDATE, + SHCI_SUB_EVT_THREAD_NVM_RAM_UPDATE, SHCI_SUB_EVT_NVM_START_WRITE, SHCI_SUB_EVT_NVM_END_WRITE, SHCI_SUB_EVT_NVM_START_ERASE, SHCI_SUB_EVT_NVM_END_ERASE, + SHCI_SUB_EVT_CODE_CONCURRENT_802154_EVT, } SHCI_SUB_EVT_CODE_t; /** @@ -100,8 +101,8 @@ extern "C" { } SHCI_C2_BleNvmRamUpdate_Evt_t; /** - * SHCI_SUB_EVT_OT_NVM_RAM_UPDATE - * This notifies the CPU1 which part of the 'OT NVM RAM' has been updated so that only the modified + * SHCI_SUB_EVT_THREAD_NVM_RAM_UPDATE + * This notifies the CPU1 which part of the OT NVM RAM has been updated so that only the modified * section could be written in Flash/NVM * StartAddress : Start address of the section that has been modified * Size : Size (in bytes) of the section that has been modified @@ -109,7 +110,7 @@ extern "C" { typedef PACKED_STRUCT{ uint32_t StartAddress; uint32_t Size; - } SHCI_C2_OtNvmRamUpdate_Evt_t; + } SHCI_C2_ThreadNvmRamUpdate_Evt_t; /** * SHCI_SUB_EVT_NVM_START_WRITE @@ -150,6 +151,11 @@ extern "C" { /* SYSTEM COMMAND */ typedef PACKED_STRUCT { + /** + * MetaData holds : + * 2*32bits for chaining list + * 1*32bits with BLE header (type + Opcode + Length) + */ uint32_t MetaData[3]; } SHCI_Header_t; @@ -159,6 +165,7 @@ extern "C" { SHCI_UNKNOWN_CMD = 0x01, SHCI_ERR_UNSUPPORTED_FEATURE = 0x11, SHCI_ERR_INVALID_HCI_CMD_PARAMS = 0x12, + SHCI_ERR_INVALID_PARAMS = 0x42, SHCI_FUS_CMD_NOT_SUPPORTED = 0xFF, } SHCI_CmdStatus_t; @@ -191,8 +198,8 @@ extern "C" { SHCI_OCF_C2_FUS_RESERVED2, SHCI_OCF_C2_FUS_RESERVED3, SHCI_OCF_C2_FUS_LOCK_USR_KEY, - SHCI_OCF_C2_FUS_RESERVED5, - SHCI_OCF_C2_FUS_RESERVED6, + SHCI_OCF_C2_FUS_UNLOAD_USR_KEY, + SHCI_OCF_C2_FUS_ACTIVATE_ANTIROLLBACK, SHCI_OCF_C2_FUS_RESERVED7, SHCI_OCF_C2_FUS_RESERVED8, SHCI_OCF_C2_FUS_RESERVED9, @@ -207,27 +214,53 @@ extern "C" { SHCI_OCF_C2_FLASH_STORE_DATA, SHCI_OCF_C2_FLASH_ERASE_DATA, SHCI_OCF_C2_RADIO_ALLOW_LOW_POWER, + SHCI_OCF_C2_MAC_802_15_4_INIT, SHCI_OCF_C2_REINIT, + SHCI_OCF_C2_ZIGBEE_INIT, SHCI_OCF_C2_LLD_TESTS_INIT, SHCI_OCF_C2_EXTPA_CONFIG, SHCI_OCF_C2_SET_FLASH_ACTIVITY_CONTROL, - SHCI_OCF_C2_LLD_BLE_INIT, - SHCI_OCF_C2_CONFIG, + SHCI_OCF_C2_BLE_LLD_INIT, + SHCI_OCF_C2_CONFIG, + SHCI_OCF_C2_CONCURRENT_GET_NEXT_BLE_EVT_TIME, + SHCI_OCF_C2_CONCURRENT_ENABLE_NEXT_802154_EVT_NOTIFICATION, + SHCI_OCF_C2_802_15_4_DEINIT, } SHCI_OCF_t; #define SHCI_OPCODE_C2_FUS_GET_STATE (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_GET_STATE) /** No command parameters */ /** Response parameters*/ +/** It responds a 1 byte value holding FUS State error code when the FUS State value is 0xFF (FUS_STATE_VALUE_ERROR) */ typedef enum { - FUS_STATE_NO_ERROR = 0x00, - FUS_STATE_IMG_NOT_FOUND = 0x01, - FUS_STATE_IMG_CORRUPT = 0x02, - FUS_STATE_IMG_NOT_AUTHENTIC = 0x03, - FUS_STATE_IMG_NOT_ENOUGH_SPACE = 0x04, - FUS_STATE_ERR_UNKNOWN = 0xFF, + FUS_STATE_ERROR_NO_ERROR = 0x00, + FUS_STATE_ERROR_IMG_NOT_FOUND = 0x01, + FUS_STATE_ERROR_IMG_CORRUPT = 0x02, + FUS_STATE_ERROR_IMG_NOT_AUTHENTIC = 0x03, + FUS_STATE_ERROR_IMG_NOT_ENOUGH_SPACE = 0x04, + FUS_STATE_ERROR_IMAGE_USRABORT = 0x05, + FUS_STATE_ERROR_IMAGE_ERSERROR = 0x06, + FUS_STATE_ERROR_IMAGE_WRTERROR = 0x07, + FUS_STATE_ERROR_AUTH_TAG_ST_NOTFOUND = 0x08, + FUS_STATE_ERROR_AUTH_TAG_CUST_NOTFOUND = 0x09, + FUS_STATE_ERROR_AUTH_KEY_LOCKED = 0x0A, + FUS_STATE_ERROR_FW_ROLLBACK_ERROR = 0x11, + FUS_STATE_ERROR_STATE_NOT_RUNNING = 0xFE, + FUS_STATE_ERROR_ERR_UNKNOWN = 0xFF, } SHCI_FUS_GetState_ErrorCode_t; + enum + { + FUS_STATE_VALUE_IDLE = 0x00, + FUS_STATE_VALUE_FW_UPGRD_ONGOING = 0x10, + FUS_STATE_VALUE_FW_UPGRD_ONGOING_END = 0x1F, /* All values between 0x10 and 0x1F has the same meaning */ + FUS_STATE_VALUE_FUS_UPGRD_ONGOING = 0x20, + FUS_STATE_VALUE_FUS_UPGRD_ONGOING_END = 0x2F, /* All values between 0x20 and 0x2F has the same meaning */ + FUS_STATE_VALUE_SERVICE_ONGOING = 0x30, + FUS_STATE_VALUE_SERVICE_ONGOING_END = 0x3F, /* All values between 0x30 and 0x3F has the same meaning */ + FUS_STATE_VALUE_ERROR = 0xFF, + }; + #define SHCI_OPCODE_C2_FUS_RESERVED1 (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_RESERVED1) /** No command parameters */ /** No response parameters*/ @@ -303,11 +336,11 @@ extern "C" { /** No response parameters*/ -#define SHCI_OPCODE_C2_FUS_RESERVED5 (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_RESERVED5) +#define SHCI_OPCODE_C2_FUS_UNLOAD_USR_KEY (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_UNLOAD_USR_KEY) /** No command parameters */ -/** No response parameters*/ +/** 1 byte holding the key index value */ -#define SHCI_OPCODE_C2_FUS_RESERVED6 (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_RESERVED6) +#define SHCI_OPCODE_C2_FUS_ACTIVATE_ANTIROLLBACK (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_ACTIVATE_ANTIROLLBACK) /** No command parameters */ /** No response parameters*/ @@ -338,32 +371,238 @@ extern "C" { #define SHCI_OPCODE_C2_BLE_INIT (( SHCI_OGF << 10) + SHCI_OCF_C2_BLE_INIT) /** THE ORDER SHALL NOT BE CHANGED */ typedef PACKED_STRUCT{ - uint8_t* pBleBufferAddress; /**< NOT USED CURRENTLY */ - uint32_t BleBufferSize; /**< Size of the Buffer allocated in pBleBufferAddress */ + uint8_t* pBleBufferAddress; /**< NOT USED - shall be set to 0 */ + uint32_t BleBufferSize; /**< NOT USED - shall be set to 0 */ + + /** + * NumAttrRecord + * Maximum number of attribute records related to all the required characteristics (excluding the services) + * that can be stored in the GATT database, for the specific BLE user application. + * For each characteristic, the number of attribute records goes from two to five depending on the characteristic properties: + * - minimum of two (one for declaration and one for the value) + * - add one more record for each additional property: notify or indicate, broadcast, extended property. + * The total calculated value must be increased by 9, due to the records related to the standard attribute profile and + * GAP service characteristics, and automatically added when initializing GATT and GAP layers + * - Min value: <number of user attributes> + 9 + * - Max value: depending on the GATT database defined by user application + */ uint16_t NumAttrRecord; + + /** + * NumAttrServ + * Defines the maximum number of services that can be stored in the GATT database. Note that the GAP and GATT services + * are automatically added at initialization so this parameter must be the number of user services increased by two. + * - Min value: <number of user service> + 2 + * - Max value: depending GATT database defined by user application + */ uint16_t NumAttrServ; + + /** + * AttrValueArrSize + * NOTE: This parameter is ignored by the CPU2 when the parameter "Options" is set to "LL_only" ( see Options description in that structure ) + * + * Size of the storage area for the attribute values. + * Each characteristic contributes to the attrValueArrSize value as follows: + * - Characteristic value length plus: + * + 5 bytes if characteristic UUID is 16 bits + * + 19 bytes if characteristic UUID is 128 bits + * + 2 bytes if characteristic has a server configuration descriptor + * + 2 bytes * NumOfLinks if the characteristic has a client configuration descriptor + * + 2 bytes if the characteristic has extended properties + * Each descriptor contributes to the attrValueArrSize value as follows: + * - Descriptor length + */ uint16_t AttrValueArrSize; + + /** + * NumOfLinks + * Maximum number of BLE links supported + * - Min value: 1 + * - Max value: 8 + */ uint8_t NumOfLinks; + + /** + * ExtendedPacketLengthEnable + * Disable/enable the extended packet length BLE 5.0 feature + * - Disable: 0 + * - Enable: 1 + */ uint8_t ExtendedPacketLengthEnable; + + /** + * PrWriteListSize + * NOTE: This parameter is ignored by the CPU2 when the parameter "Options" is set to "LL_only" ( see Options description in that structure ) + * + * Maximum number of supported �prepare write request� + * - Min value: given by the macro DEFAULT_PREP_WRITE_LIST_SIZE + * - Max value: a value higher than the minimum required can be specified, but it is not recommended + */ uint8_t PrWriteListSize; + + /** + * MblockCount + * NOTE: This parameter is overwritten by the CPU2 with an hardcoded optimal value when the parameter "Options" is set to "LL_only" + * ( see Options description in that structure ) + * + * Number of allocated memory blocks for the BLE stack + * - Min value: given by the macro MBLOCKS_CALC + * - Max value: a higher value can improve data throughput performance, but uses more memory + */ uint8_t MblockCount; + + /** + * AttMtu + * NOTE: This parameter is ignored by the CPU2 when the parameter "Options" is set to "LL_only" ( see Options description in that structure ) + * + * Maximum ATT MTU size supported + * - Min value: 23 + * - Max value: 512 + */ uint16_t AttMtu; + + /** + * SlaveSca + * The sleep clock accuracy (ppm value) that used in BLE connected slave mode to calculate the window widening + * (in combination with the sleep clock accuracy sent by master in CONNECT_REQ PDU), + * refer to BLE 5.0 specifications - Vol 6 - Part B - chap 4.5.7 and 4.2.2 + * - Min value: 0 + * - Max value: 500 (worst possible admitted by specification) + */ uint16_t SlaveSca; + + /** + * MasterSca + * The sleep clock accuracy handled in master mode. It is used to determine the connection and advertising events timing. + * It is transmitted to the slave in CONNEC_REQ PDU used by the slave to calculate the window widening, + * see SlaveSca and Bluetooth Core Specification v5.0 Vol 6 - Part B - chap 4.5.7 and 4.2.2 + * Possible values: + * - 251 ppm to 500 ppm: 0 + * - 151 ppm to 250 ppm: 1 + * - 101 ppm to 150 ppm: 2 + * - 76 ppm to 100 ppm: 3 + * - 51 ppm to 75 ppm: 4 + * - 31 ppm to 50 ppm: 5 + * - 21 ppm to 30 ppm: 6 + * - 0 ppm to 20 ppm: 7 + */ uint8_t MasterSca; + + /** + * LsSource + * Source for the 32 kHz slow speed clock. + * - External crystal LSE: 0 - No calibration + * - Others:1 - As the accuracy of this oscillator can vary depending upon external conditions (temperature), + * it is calibrated every second to ensure correct behavior of timing sensitive BLE operations + */ uint8_t LsSource; + + /** + * MaxConnEventLength + * This parameter determines the maximum duration of a slave connection event. When this duration is reached the slave closes + * the current connections event (whatever is the CE_length parameter specified by the master in HCI_CREATE_CONNECTION HCI command), + * expressed in units of 625/256 �s (~2.44 �s) + * - Min value: 0 (if 0 is specified, the master and slave perform only a single TX-RX exchange per connection event) + * - Max value: 1638400 (4000 ms). A higher value can be specified (max 0xFFFFFFFF) but results in a maximum connection time + * of 4000 ms as specified. In this case the parameter is not applied, and the predicted CE length calculated on slave is not shortened + */ uint32_t MaxConnEventLength; + + /** + * HsStartupTime + * Startup time of the high speed (16 or 32 MHz) crystal oscillator in units of 625/256 �s (~2.44 �s). + * - Min value: 0 + * - Max value: 820 (~2 ms). A higher value can be specified, but the value that implemented in stack is forced to ~2 ms + */ uint16_t HsStartupTime; + + /** + * ViterbiEnable + * Viterbi implementation in BLE LL reception. + * - 0: Enable + * - 1: Disable + */ uint8_t ViterbiEnable; - uint8_t LlOnly; + + /** + * Options flags + * - bit 0: 1: LL only 0: LL + host + * - bit 1: 1: no service change desc. 0: with service change desc. + * - bit 2: 1: device name Read-Only 0: device name R/W + * - bit 3: 1: extended advertizing supported 0: extended advertizing not supported [NOT SUPPORTED] + * - bit 4: 1: CS Algo #2 supported 0: CS Algo #2 not supported + * - bit 7: 1: LE Power Class 1 0: LE Power Classe 2-3 + * - other bits: reserved ( shall be set to 0) + */ + uint8_t Options; + + /** + * HwVersion + * Reserved for future use - shall be set to 0 + */ uint8_t HwVersion; - } SHCI_C2_Ble_Init_Cmd_Param_t; + + /** + * Maximum number of connection-oriented channels in initiator mode. + * Range: 0 .. 64 + */ + uint8_t max_coc_initiator_nbr; + + /** + * Minimum transmit power in dBm supported by the Controller. + * Range: -127 .. 20 + */ + int8_t min_tx_power; + + /** + * Maximum transmit power in dBm supported by the Controller. + * Range: -127 .. 20 + */ + int8_t max_tx_power; + + /** + * RX model configuration + * - bit 0: 1: agc_rssi model improved vs RF blockers 0: Legacy agc_rssi model + * - other bits: reserved ( shall be set to 0) + */ + uint8_t rx_model_config; + + } SHCI_C2_Ble_Init_Cmd_Param_t; typedef PACKED_STRUCT{ SHCI_Header_t Header; /** Does not need to be initialized by the user */ SHCI_C2_Ble_Init_Cmd_Param_t Param; } SHCI_C2_Ble_Init_Cmd_Packet_t; - /** No response parameters*/ + /** + * Options + * Each definition below may be added together to build the Options value + * WARNING : Only one definition per bit shall be added to build the Options value + */ +#define SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY (1<<0) +#define SHCI_C2_BLE_INIT_OPTIONS_LL_HOST (0<<0) + +#define SHCI_C2_BLE_INIT_OPTIONS_NO_SVC_CHANGE_DESC (1<<1) +#define SHCI_C2_BLE_INIT_OPTIONS_WITH_SVC_CHANGE_DESC (0<<1) + +#define SHCI_C2_BLE_INIT_OPTIONS_DEVICE_NAME_RO (1<<2) +#define SHCI_C2_BLE_INIT_OPTIONS_DEVICE_NAME_RW (0<<2) + +#define SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV (1<<3) /*NOT SUPPORTED*/ +#define SHCI_C2_BLE_INIT_OPTIONS_NO_EXT_ADV (0<<3) /*NOT SUPPORTED*/ + +#define SHCI_C2_BLE_INIT_OPTIONS_CS_ALGO2 (1<<4) +#define SHCI_C2_BLE_INIT_OPTIONS_NO_CS_ALGO2 (0<<4) + +#define SHCI_C2_BLE_INIT_OPTIONS_POWER_CLASS_1 (1<<7) +#define SHCI_C2_BLE_INIT_OPTIONS_POWER_CLASS_2_3 (0<<7) + + /** + * RX models configuration + */ +#define SHCI_C2_BLE_INIT_RX_MODEL_AGC_RSSI_LEGACY (0<<0) +#define SHCI_C2_BLE_INIT_RX_MODEL_AGC_RSSI_BLOCKER (1<<0) + #define SHCI_OPCODE_C2_THREAD_INIT (( SHCI_OGF << 10) + SHCI_OCF_C2_THREAD_INIT) /** No command parameters */ @@ -375,12 +614,21 @@ extern "C" { { uint8_t thread_config; uint8_t ble_config; + uint8_t mac_802_15_4_config; + uint8_t zigbee_config; } SHCI_C2_DEBUG_TracesConfig_t; typedef PACKED_STRUCT { uint8_t ble_dtb_cfg; - uint8_t reserved[3]; + /** + * sys_dbg_cfg1 options flag + * - bit 0: 0: IP BLE core in LP mode 1: IP BLE core in run mode (no LP supported) + * - bit 1: 0: CPU2 STOP mode Enable 1: CPU2 STOP mode Disable + * - bit [2-7]: bits reserved ( shall be set to 0) + */ + uint8_t sys_dbg_cfg1; + uint8_t reserved[2]; } SHCI_C2_DEBUG_GeneralConfig_t; typedef PACKED_STRUCT{ @@ -398,6 +646,18 @@ extern "C" { } SHCI_C2_DEBUG_Init_Cmd_Packet_t; /** No response parameters*/ + /** + * Options + * Each definition below may be added together to build the Options value + * WARNING : Only one definition per bit shall be added to build the Options value + */ +#define SHCI_C2_DEBUG_OPTIONS_IPCORE_LP (0<<0) +#define SHCI_C2_DEBUG_OPTIONS_IPCORE_NO_LP (1<<0) + +#define SHCI_C2_DEBUG_OPTIONS_CPU2_STOP_EN (0<<1) +#define SHCI_C2_DEBUG_OPTIONS_CPU2_STOP_DIS (1<<1) + + #define SHCI_OPCODE_C2_FLASH_ERASE_ACTIVITY (( SHCI_OGF << 10) + SHCI_OCF_C2_FLASH_ERASE_ACTIVITY) /** Command parameters */ typedef enum @@ -414,9 +674,23 @@ extern "C" { { BLE_ENABLE, THREAD_ENABLE, + ZIGBEE_ENABLE, + MAC_ENABLE, } SHCI_C2_CONCURRENT_Mode_Param_t; /** No response parameters*/ +#define SHCI_OPCODE_C2_CONCURRENT_GET_NEXT_BLE_EVT_TIME (( SHCI_OGF << 10) + SHCI_OCF_C2_CONCURRENT_GET_NEXT_BLE_EVT_TIME) +/** command parameters */ + typedef PACKED_STRUCT + { + uint32_t relative_time; + } SHCI_C2_CONCURRENT_GetNextBleEvtTime_Param_t; + /** No response parameters*/ + +#define SHCI_OPCODE_C2_CONCURRENT_ENABLE_NEXT_802154_EVT_NOTIFICATION (( SHCI_OGF << 10) + SHCI_OCF_C2_CONCURRENT_ENABLE_NEXT_802154_EVT_NOTIFICATION) + /** No command parameters */ + /** No response parameters*/ + #define SHCI_OPCODE_C2_FLASH_STORE_DATA (( SHCI_OGF << 10) + SHCI_OCF_C2_FLASH_STORE_DATA) #define SHCI_OPCODE_C2_FLASH_ERASE_DATA (( SHCI_OGF << 10) + SHCI_OCF_C2_FLASH_ERASE_DATA) /** command parameters */ @@ -424,16 +698,21 @@ extern "C" { { BLE_IP, THREAD_IP, + ZIGBEE_IP, } SHCI_C2_FLASH_Ip_t; /** No response parameters*/ #define SHCI_OPCODE_C2_RADIO_ALLOW_LOW_POWER (( SHCI_OGF << 10) + SHCI_OCF_C2_RADIO_ALLOW_LOW_POWER) +#define SHCI_OPCODE_C2_MAC_802_15_4_INIT (( SHCI_OGF << 10) + SHCI_OCF_C2_MAC_802_15_4_INIT) + #define SHCI_OPCODE_C2_REINIT (( SHCI_OGF << 10) + SHCI_OCF_C2_REINIT) +#define SHCI_OPCODE_C2_ZIGBEE_INIT (( SHCI_OGF << 10) + SHCI_OCF_C2_ZIGBEE_INIT) + #define SHCI_OPCODE_C2_LLD_TESTS_INIT (( SHCI_OGF << 10) + SHCI_OCF_C2_LLD_TESTS_INIT) -#define SHCI_OPCODE_C2_LLD_BLE_INIT (( SHCI_OGF << 10) + SHCI_OCF_C2_LLD_BLE_INIT) +#define SHCI_OPCODE_C2_BLE_LLD_INIT (( SHCI_OGF << 10) + SHCI_OCF_C2_BLE_LLD_INIT) #define SHCI_OPCODE_C2_EXTPA_CONFIG (( SHCI_OGF << 10) + SHCI_OCF_C2_EXTPA_CONFIG) /** Command parameters */ @@ -477,14 +756,24 @@ extern "C" { uint8_t Spare1; uint32_t BleNvmRamAddress; uint32_t ThreadNvmRamAddress; + uint16_t RevisionID; } SHCI_C2_CONFIG_Cmd_Param_t; +#define SHCI_OPCODE_C2_802_15_4_DEINIT (( SHCI_OGF << 10) + SHCI_OCF_C2_802_15_4_DEINIT) + /** * PayloadCmdSize * Value that shall be used */ #define SHCI_C2_CONFIG_PAYLOAD_CMD_SIZE (sizeof(SHCI_C2_CONFIG_Cmd_Param_t) - 1) +/** + * Device revision ID + */ +#define SHCI_C2_CONFIG_CUT2_0 (0x2000) +#define SHCI_C2_CONFIG_CUT2_1 (0x2001) +#define SHCI_C2_CONFIG_CUT2_2 (0x2003) + /** * Config1 * Each definition below may be added together to build the Config1 value @@ -501,7 +790,7 @@ extern "C" { */ #define SHCI_C2_CONFIG_EVTMASK1_BIT0_ERROR_NOTIF_ENABLE (1<<0) #define SHCI_C2_CONFIG_EVTMASK1_BIT1_BLE_NVM_RAM_UPDATE_ENABLE (1<<1) -#define SHCI_C2_CONFIG_EVTMASK1_BIT2_OT_NVM_RAM_UPDATE_ENABLE (1<<2) +#define SHCI_C2_CONFIG_EVTMASK1_BIT2_THREAD_NVM_RAM_UPDATE_ENABLE (1<<2) #define SHCI_C2_CONFIG_EVTMASK1_BIT3_NVM_START_WRITE_ENABLE (1<<3) #define SHCI_C2_CONFIG_EVTMASK1_BIT4_NVM_END_WRITE_ENABLE (1<<4) #define SHCI_C2_CONFIG_EVTMASK1_BIT5_NVM_START_ERASE_ENABLE (1<<5) @@ -525,18 +814,17 @@ extern "C" { /** No response parameters*/ /* Exported type --------------------------------------------------------*/ - -typedef MB_WirelessFwInfoTable_t SHCI_WirelessFwInfoTable_t; +#define FUS_DEVICE_INFO_TABLE_VALIDITY_KEYWORD (0xA94656B9) /* - * At startup, the information relative to the wireless binary are stored in RAM through a structure defined by - * SHCI_WirelessFwInfoTable_t.This structure contains 4 fields (Version,MemorySize, Stack_info and a reserved part) + * At startup, the informations relative to the wireless binary are stored in RAM trough a structure defined by + * MB_WirelessFwInfoTable_t.This structure contains 4 fields (Version,MemorySize, Stack_info and a reserved part) * each of those coded on 32 bits as shown on the table below: * * * |7 |6 |5 |4 |3 |2 |1 |0 |7 |6 |5 |4 |3 |2 |1 |0 |7 |6 |5 |4 |3 |2 |1 |0 |7 |6 |5 |4 |3 |2 |1 |0 | * ------------------------------------------------------------------------------------------------- - * Version | Major version | Minor version | Sub version | Branch |Release Type| + * Version | Major version | Minor version | Sub version | Branch |ReleaseType| * ------------------------------------------------------------------------------------------------- * MemorySize | SRAM2B (kB) | SRAM2A (kB) | SRAM1 (kB) | FLASH (4kb) | * ------------------------------------------------------------------------------------------------- @@ -576,17 +864,29 @@ typedef MB_WirelessFwInfoTable_t SHCI_WirelessFwInfoTable_t; #define INFO_STACK_TYPE_MASK 0x000000ff #define INFO_STACK_TYPE_NONE 0 -#define INFO_STACK_TYPE_BLE_STANDARD 0x01 +#define INFO_STACK_TYPE_BLE_FULL 0x01 #define INFO_STACK_TYPE_BLE_HCI 0x02 #define INFO_STACK_TYPE_BLE_LIGHT 0x03 +#define INFO_STACK_TYPE_BLE_BEACON 0x04 #define INFO_STACK_TYPE_THREAD_FTD 0x10 #define INFO_STACK_TYPE_THREAD_MTD 0x11 +#define INFO_STACK_TYPE_ZIGBEE_FFD 0x30 +#define INFO_STACK_TYPE_ZIGBEE_RFD 0x31 +#define INFO_STACK_TYPE_MAC 0x40 #define INFO_STACK_TYPE_BLE_THREAD_FTD_STATIC 0x50 -#define INFO_STACK_TYPE_BLE_THREAD_FTD_DYAMIC 0x51 +#define INFO_STACK_TYPE_BLE_THREAD_FTD_DYAMIC 0x51 +#define INFO_STACK_TYPE_802154_LLD_TESTS 0x60 +#define INFO_STACK_TYPE_802154_PHY_VALID 0x61 #define INFO_STACK_TYPE_BLE_PHY_VALID 0x62 #define INFO_STACK_TYPE_BLE_LLD_TESTS 0x63 #define INFO_STACK_TYPE_BLE_RLV 0x64 +#define INFO_STACK_TYPE_802154_RLV 0x65 +#define INFO_STACK_TYPE_BLE_ZIGBEE_FFD_STATIC 0x70 +#define INFO_STACK_TYPE_BLE_ZIGBEE_RFD_STATIC 0x71 +#define INFO_STACK_TYPE_BLE_ZIGBEE_FFD_DYNAMIC 0x78 +#define INFO_STACK_TYPE_BLE_ZIGBEE_RFD_DYNAMIC 0x79 #define INFO_STACK_TYPE_RLV 0x80 +#define INFO_STACK_TYPE_BLE_MAC_STATIC 0x90 typedef struct { /** @@ -616,18 +916,16 @@ typedef struct { /* Exported functions ------------------------------------------------------- */ -/** - * For all SHCI_C2_FUS_xxx() command: - * When the wireless FW is running on the CPU2, the command returns SHCI_FUS_CMD_NOT_SUPPORTED - * When any FUS command is sent after the SHCI_FUS_CMD_NOT_SUPPORTED has been received, - * the CPU2 switches on the RSS ( This reboots automatically the device ) - */ /** * SHCI_C2_FUS_GetState * @brief Read the FUS State * If the user is not interested by the Error code response, a null value may * be passed as parameter * + * Note: This command is fully supported only by the FUS. + * When the wireless firmware receives that command, it responds SHCI_FUS_CMD_NOT_SUPPORTED the first time. + * When the wireless firmware receives that command a second time, it reboots the full device with the FUS running on CPU2 + * * @param p_rsp : return the error code when the FUS State Value = 0xFF * @retval FUS State Values */ @@ -636,6 +934,7 @@ typedef struct { /** * SHCI_C2_FUS_FwUpgrade * @brief Request the FUS to install the CPU2 firmware update + * Note: This command is only supported by the FUS. * * @param fw_src_add: Address of the firmware image location * @param fw_dest_add: Address of the firmware destination @@ -646,6 +945,7 @@ typedef struct { /** * SHCI_C2_FUS_FwDelete * @brief Delete the wireless stack on CPU2 + * Note: This command is only supported by the FUS. * * @param None * @retval Status @@ -655,6 +955,7 @@ typedef struct { /** * SHCI_C2_FUS_UpdateAuthKey * @brief Request the FUS to update the authentication key + * Note: This command is only supported by the FUS. * * @param pCmdPacket * @retval Status @@ -664,6 +965,7 @@ typedef struct { /** * SHCI_C2_FUS_LockAuthKey * @brief Request the FUS to prevent any future update of the authentication key + * Note: This command is only supported by the FUS. * * @param None * @retval Status @@ -673,6 +975,7 @@ typedef struct { /** * SHCI_C2_FUS_StoreUsrKey * @brief Request the FUS to store the user key + * Note: This command is supported by both the FUS and the wireless stack. * * @param pParam : command parameter * @param p_key_index : Index allocated by the FUS to the stored key @@ -684,6 +987,7 @@ typedef struct { /** * SHCI_C2_FUS_LoadUsrKey * @brief Request the FUS to load the user key into the AES + * Note: This command is supported by both the FUS and the wireless stack. * * @param key_index : index of the user key to load in AES1 * @retval Status @@ -693,6 +997,7 @@ typedef struct { /** * SHCI_C2_FUS_StartWs * @brief Request the FUS to reboot on the wireless stack + * Note: This command is only supported by the FUS. * * @param None * @retval Status @@ -702,17 +1007,41 @@ typedef struct { /** * SHCI_C2_FUS_LockUsrKey * @brief Request the FUS to lock the user key so that it cannot be updated later on + * Note: This command is supported by both the FUS and the wireless stack. * * @param key_index : index of the user key to lock * @retval Status */ SHCI_CmdStatus_t SHCI_C2_FUS_LockUsrKey( uint8_t key_index ); + /** + * SHCI_C2_FUS_UnloadUsrKey + * @brief Request the FUS to Unload the user key so that the CPU1 may use the AES with another Key + * Note: This command is supported by both the FUS and the wireless stack. + * + * @param key_index : index of the user key to unload + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_FUS_UnloadUsrKey( uint8_t key_index ); + + /** + * SHCI_C2_FUS_ActivateAntiRollback + * @brief Request the FUS to enable the AntiRollback feature so that it is not possible to update the wireless firmware + * with an older version than the current one. + * Note: + * - This command is only supported by the FUS. + * - Once this feature is enabled, it is not possible anymore to disable it. + * + * @param None + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_FUS_ActivateAntiRollback( void ); + /** * SHCI_C2_BLE_Init * @brief Provides parameters and starts the BLE Stack * - * @param pCmdPacket : Parameters to be provided to the BLE Stack + * @param pCmdPacket : Parameters are described SHCI_C2_Ble_Init_Cmd_Packet_t declaration * @retval Status */ SHCI_CmdStatus_t SHCI_C2_BLE_Init( SHCI_C2_Ble_Init_Cmd_Packet_t *pCmdPacket ); @@ -731,20 +1060,29 @@ typedef struct { * @brief Starts the LLD tests CLI * * @param param_size : Nb of bytes - * @param p_param : pointer with data to give from M4 to M0 + * @param p_param : pointeur with data to give from M4 to M0 * @retval Status */ SHCI_CmdStatus_t SHCI_C2_LLDTESTS_Init( uint8_t param_size, uint8_t * p_param ); /** - * SHCI_C2_LLD_BLE_Init - * @brief Starts the LLD tests CLI + * SHCI_C2_BLE_LLD_Init + * @brief Starts the LLD tests BLE * * @param param_size : Nb of bytes - * @param p_param : pointer with data to give from M4 to M0 + * @param p_param : pointeur with data to give from M4 to M0 * @retval Status */ - SHCI_CmdStatus_t SHCI_C2_LLD_BLE_Init( uint8_t param_size, uint8_t * p_param ); + SHCI_CmdStatus_t SHCI_C2_BLE_LLD_Init( uint8_t param_size, uint8_t * p_param ); + + /** + * SHCI_C2_ZIGBEE_Init + * @brief Starts the Zigbee Stack + * + * @param None + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_ZIGBEE_Init( void ); /** * SHCI_C2_DEBUG_Init @@ -758,6 +1096,7 @@ typedef struct { /** * SHCI_C2_FLASH_EraseActivity * @brief Provides the information of the start and the end of a flash erase window on the CPU1 + * The protection will be active until next end of radio event. * * @param erase_activity: Start/End of erase activity * @retval Status @@ -773,6 +1112,24 @@ typedef struct { */ SHCI_CmdStatus_t SHCI_C2_CONCURRENT_SetMode( SHCI_C2_CONCURRENT_Mode_Param_t Mode ); + /** + * SHCI_C2_CONCURRENT_GetNextBleEvtTime + * @brief Get the next BLE event date (relative time) + * + * @param Command Packet + * @retval None + */ + SHCI_CmdStatus_t SHCI_C2_CONCURRENT_GetNextBleEvtTime( SHCI_C2_CONCURRENT_GetNextBleEvtTime_Param_t *pParam ); + + /** + * SHCI_C2_CONCURRENT_EnableNext_802154_EvtNotification + * @brief Activate the next 802.15.4 event notification (one shot) + * + * @param None + * @retval None + */ + SHCI_CmdStatus_t SHCI_C2_CONCURRENT_EnableNext_802154_EvtNotification( void ); + /** * SHCI_C2_FLASH_StoreData * @brief Store Data in Flash @@ -801,10 +1158,20 @@ typedef struct { */ SHCI_CmdStatus_t SHCI_C2_RADIO_AllowLowPower( SHCI_C2_FLASH_Ip_t Ip,uint8_t FlagRadioLowPowerOn); + + /** + * SHCI_C2_MAC_802_15_4_Init + * @brief Starts the MAC 802.15.4 on M0 + * + * @param None + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_MAC_802_15_4_Init( void ); + /** * SHCI_GetWirelessFwInfo - * @brief This function read back the information relative to the wireless binary loaded. - * Refer yourself to SHCI_WirelessFwInfoTable_t structure to get the significance + * @brief This function read back the informations relative to the wireless binary loaded. + * Refer yourself to MB_WirelessFwInfoTable_t structure to get the significance * of the different parameters returned. * @param pWirelessInfo : Pointer to WirelessFwInfo_t. * @@ -897,10 +1264,18 @@ typedef struct { */ SHCI_CmdStatus_t SHCI_C2_Config(SHCI_C2_CONFIG_Cmd_Param_t *pCmdPacket); + /** + * SHCI_C2_802_15_4_DeInit + * @brief Deinit 802.15.4 layer (to be used before entering StandBy mode) + * + * @param None + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_802_15_4_DeInit( void ); + #ifdef __cplusplus } #endif #endif /*__SHCI_H */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/src/utility/STM32Cube_FW/shci_tl.c b/src/utility/STM32Cube_FW/shci_tl.c index 8d4d4ff4..449b8b16 100644 --- a/src/utility/STM32Cube_FW/shci_tl.c +++ b/src/utility/STM32Cube_FW/shci_tl.c @@ -4,53 +4,24 @@ * @author MCD Application Team * @brief System HCI command implementation ****************************************************************************** - * @attention - * - * <h2><center>© Copyright (c) 2019 STMicroelectronics. - * All rights reserved.</center></h2> - * - * This software component is licensed by ST under BSD 3-Clause license, - * the "License"; You may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * opensource.org/licenses/BSD-3-Clause - * - ****************************************************************************** + * @attention + * + * Copyright (c) 2018-2021 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** */ -#if defined(STM32WBxx) + /* Includes ------------------------------------------------------------------*/ #include "stm32_wpan_common.h" -#include <Arduino.h> - #include "stm_list.h" #include "shci_tl.h" -#include "stm32_def.h" - -/** - * These traces are not yet supported in an usual way in the delivery package - * They can enabled by adding the definition of TL_SHCI_CMD_DBG_EN and/or TL_SHCI_EVT_DBG_EN in the preprocessor option in the IDE - */ -#if ( (TL_SHCI_CMD_DBG_EN != 0) || (TL_SHCI_EVT_DBG_EN != 0) ) -#include "app_conf.h" -#include "dbg_trace.h" -#endif - -#if (TL_SHCI_CMD_DBG_EN != 0) -#define TL_SHCI_CMD_DBG_MSG PRINT_MESG_DBG -#define TL_SHCI_CMD_DBG_BUF PRINT_LOG_BUFF_DBG -#else -#define TL_SHCI_CMD_DBG_MSG(...) -#define TL_SHCI_CMD_DBG_BUF(...) -#endif - -#if (TL_SHCI_EVT_DBG_EN != 0) -#define TL_SHCI_EVT_DBG_MSG PRINT_MESG_DBG -#define TL_SHCI_EVT_DBG_BUF PRINT_LOG_BUFF_DBG -#else -#define TL_SHCI_EVT_DBG_MSG(...) -#define TL_SHCI_EVT_DBG_BUF(...) -#endif /* Private typedef -----------------------------------------------------------*/ typedef enum @@ -89,9 +60,6 @@ static void Cmd_SetStatus(SHCI_TL_CmdStatus_t shcicmdstatus); static void TlCmdEvtReceived(TL_EvtPacket_t *shcievt); static void TlUserEvtReceived(TL_EvtPacket_t *shcievt); static void TlInit( TL_CmdPacket_t * p_cmdbuffer ); -static void OutputCmdTrace(TL_CmdPacket_t *pCmdBuffer); -static void OutputRspTrace(TL_EvtPacket_t *p_rsp); -static void OutputEvtTrace(TL_EvtPacket_t *phcievtbuffer); /* Interface ------- ---------------------------------------------------------*/ void shci_init(void(* UserEvtRx)(void* pData), void* pConf) @@ -129,8 +97,6 @@ void shci_user_evt_proc(void) { LST_remove_head ( &SHciAsynchEventQueue, (tListNode **)&phcievtbuffer ); - OutputEvtTrace(phcievtbuffer); - if (shciContext.UserEvtRx != NULL) { UserEvtRxParam.pckt = phcievtbuffer; @@ -187,8 +153,6 @@ void shci_send( uint16_t cmd_code, uint8_t len_cmd_payload, uint8_t * p_cmd_payl memcpy(pCmdBuffer->cmdserial.cmd.payload, p_cmd_payload, len_cmd_payload ); - OutputCmdTrace(pCmdBuffer); - shciContext.io.Send(0,0); shci_cmd_resp_wait(SHCI_TL_DEFAULT_TIMEOUT); @@ -199,27 +163,11 @@ void shci_send( uint16_t cmd_code, uint8_t len_cmd_payload, uint8_t * p_cmd_payl */ memcpy( &(p_rsp->evtserial), pCmdBuffer, ((TL_EvtSerial_t*)pCmdBuffer)->evt.plen + TL_EVT_HDR_SIZE ); - OutputRspTrace(p_rsp); - Cmd_SetStatus(SHCI_TL_CmdAvailable); return; } -void shci_notify_asynch_evt(void *pdata) -{ - UNUSED(pdata); - /* Need to parse data in future version */ - shci_user_evt_proc(); -} - -void shci_register_io_bus(tSHciIO *fops) -{ - /* Register IO bus services */ - fops->Init = TL_SYS_Init; - fops->Send = TL_SYS_SendCmd; -} - /* Private functions ---------------------------------------------------------*/ static void TlInit( TL_CmdPacket_t * p_cmdbuffer ) { @@ -284,76 +232,14 @@ static void TlUserEvtReceived(TL_EvtPacket_t *shcievt) return; } -static void OutputCmdTrace(TL_CmdPacket_t *pCmdBuffer) -{ - TL_SHCI_CMD_DBG_MSG("sys cmd: 0x%04X", pCmdBuffer->cmdserial.cmd.cmdcode); - - if(pCmdBuffer->cmdserial.cmd.plen != 0) - { - TL_SHCI_CMD_DBG_MSG(" payload:"); - TL_SHCI_CMD_DBG_BUF(pCmdBuffer->cmdserial.cmd.payload, pCmdBuffer->cmdserial.cmd.plen, ""); - } - TL_SHCI_CMD_DBG_MSG("\r\n"); - - return; -} - -static void OutputRspTrace(TL_EvtPacket_t *p_rsp) -{ - switch(p_rsp->evtserial.evt.evtcode) - { - case TL_BLEEVT_CC_OPCODE: - TL_SHCI_CMD_DBG_MSG("sys rsp: 0x%02X", p_rsp->evtserial.evt.evtcode); - TL_SHCI_CMD_DBG_MSG(" cmd opcode: 0x%02X", ((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->cmdcode); - TL_SHCI_CMD_DBG_MSG(" status: 0x%02X", ((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); - if((p_rsp->evtserial.evt.plen-4) != 0) - { - TL_SHCI_CMD_DBG_MSG(" payload:"); - TL_SHCI_CMD_DBG_BUF(&((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[1], p_rsp->evtserial.evt.plen-4, ""); - } - break; - - default: - TL_SHCI_CMD_DBG_MSG("unknown sys rsp received: %02X", p_rsp->evtserial.evt.evtcode); - break; - } - - TL_SHCI_CMD_DBG_MSG("\r\n"); - - return; -} - -static void OutputEvtTrace(TL_EvtPacket_t *phcievtbuffer) -{ - if(phcievtbuffer->evtserial.evt.evtcode != TL_BLEEVT_VS_OPCODE) - { - TL_SHCI_EVT_DBG_MSG("unknown sys evt received: %02X", phcievtbuffer->evtserial.evt.evtcode); - } - else - { - TL_SHCI_EVT_DBG_MSG("sys evt: 0x%02X", phcievtbuffer->evtserial.evt.evtcode); - TL_SHCI_EVT_DBG_MSG(" subevtcode: 0x%04X", ((TL_AsynchEvt_t*)(phcievtbuffer->evtserial.evt.payload))->subevtcode); - if((phcievtbuffer->evtserial.evt.plen-2) != 0) - { - TL_SHCI_EVT_DBG_MSG(" payload:"); - TL_SHCI_EVT_DBG_BUF(((TL_AsynchEvt_t*)(phcievtbuffer->evtserial.evt.payload))->payload, phcievtbuffer->evtserial.evt.plen-2, ""); - } - } - - TL_SHCI_EVT_DBG_MSG("\r\n"); - - return; -} - /* Weak implementation ----------------------------------------------------------------*/ __WEAK void shci_cmd_resp_wait(uint32_t timeout) { + (void)timeout; + CmdRspStatusFlag = SHCI_TL_CMD_RESP_WAIT; - for (unsigned long start = millis(); (millis() - start) < timeout;) { - if (CmdRspStatusFlag == SHCI_TL_CMD_RESP_RELEASE) { - break; - } - } + while(CmdRspStatusFlag != SHCI_TL_CMD_RESP_RELEASE); + return; } @@ -366,4 +252,3 @@ __WEAK void shci_cmd_resp_release(uint32_t flag) return; } -#endif /* STM32WBxx */ diff --git a/src/utility/STM32Cube_FW/shci_tl.h b/src/utility/STM32Cube_FW/shci_tl.h index 3fbc492f..74d0ff38 100644 --- a/src/utility/STM32Cube_FW/shci_tl.h +++ b/src/utility/STM32Cube_FW/shci_tl.h @@ -4,20 +4,18 @@ * @author MCD Application Team * @brief System HCI command header for the system channel ****************************************************************************** - * @attention - * - * <h2><center>© Copyright (c) 2019 STMicroelectronics. - * All rights reserved.</center></h2> - * - * This software component is licensed by ST under BSD 3-Clause license, - * the "License"; You may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * opensource.org/licenses/BSD-3-Clause - * - ****************************************************************************** + * @attention + * + * Copyright (c) 2018-2021 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** */ - #ifndef __SHCI_TL_H_ #define __SHCI_TL_H_ @@ -160,7 +158,7 @@ void shci_user_evt_proc(void); * @brief Initialize the System Host Controller Interface. * This function must be called before any communication on the System Channel * - * @param pData: System events callback function pointer + * @param UserEvtRx: System events callback function pointer * This callback is triggered when an user event is received on * the System Channel from CPU2. * @param pConf: Configuration structure pointer diff --git a/src/utility/STM32Cube_FW/stm32_wpan_common.h b/src/utility/STM32Cube_FW/stm32_wpan_common.h index 93e909ca..b47b804a 100644 --- a/src/utility/STM32Cube_FW/stm32_wpan_common.h +++ b/src/utility/STM32Cube_FW/stm32_wpan_common.h @@ -6,13 +6,12 @@ ****************************************************************************** * @attention * - * <h2><center>© Copyright (c) 2018 STMicroelectronics. - * All rights reserved.</center></h2> + * Copyright (c) 2018-2021 STMicroelectronics. + * All rights reserved. * - * This software component is licensed by ST under Ultimate Liberty license - * SLA0044, the "License"; You may not use this file except in compliance with - * the License. You may obtain a copy of the License at: - * www.st.com/SLA0044 + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ @@ -26,9 +25,19 @@ extern "C" { #endif -#define __ASM __asm /*!< asm keyword for GNU Compiler */ -#define __INLINE inline /*!< inline keyword for GNU Compiler */ -#define __STATIC_INLINE static inline +#if defined ( __CC_ARM ) + #define __ASM __asm /*!< asm keyword for ARM Compiler */ + #define __INLINE __inline /*!< inline keyword for ARM Compiler */ + #define __STATIC_INLINE static __inline +#elif defined ( __ICCARM__ ) + #define __ASM __asm /*!< asm keyword for IAR Compiler */ + #define __INLINE inline /*!< inline keyword for IAR Compiler. Only available in High optimization mode! */ + #define __STATIC_INLINE static inline +#elif defined ( __GNUC__ ) + #define __ASM __asm /*!< asm keyword for GNU Compiler */ + #define __INLINE inline /*!< inline keyword for GNU Compiler */ + #define __STATIC_INLINE static inline +#endif #include <stdint.h> #include <string.h> @@ -131,13 +140,32 @@ extern "C" { /* ----------------------------------- * * Packed usage (compiler dependent) * * ----------------------------------- */ +#undef PACKED__ #undef PACKED_STRUCT -#define PACKED_STRUCT struct __packed + +#if defined ( __CC_ARM ) + #if defined ( __GNUC__ ) + /* GNU extension */ + #define PACKED__ __attribute__((packed)) + #define PACKED_STRUCT struct PACKED__ + #elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050U) + #define PACKED__ __attribute__((packed)) + #define PACKED_STRUCT struct PACKED__ + #else + #define PACKED__(TYPE) __packed TYPE + #define PACKED_STRUCT PACKED__(struct) + #endif +#elif defined ( __GNUC__ ) + #define PACKED__ __attribute__((packed)) + #define PACKED_STRUCT struct PACKED__ +#elif defined (__ICCARM__) + #define PACKED_STRUCT __packed struct +#else + #define PACKED_STRUCT __packed struct +#endif #ifdef __cplusplus } #endif #endif /*__STM32_WPAN_COMMON_H */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/src/utility/STM32Cube_FW/stm_list.c b/src/utility/STM32Cube_FW/stm_list.c index 6e802a07..69c8c064 100644 --- a/src/utility/STM32Cube_FW/stm_list.c +++ b/src/utility/STM32Cube_FW/stm_list.c @@ -4,26 +4,25 @@ * @author MCD Application Team * @brief TCircular Linked List Implementation. ****************************************************************************** - * @attention + * @attention * - * <h2><center>© Copyright (c) 2019 STMicroelectronics. - * All rights reserved.</center></h2> + * Copyright (c) 2018-2021 STMicroelectronics. + * All rights reserved. * - * This software component is licensed by ST under BSD 3-Clause license, - * the "License"; You may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * opensource.org/licenses/BSD-3-Clause + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** - */ + */ + -#if defined(STM32WBxx) /****************************************************************************** * Include Files ******************************************************************************/ +#include "utilities_common.h" + #include "stm_list.h" -#include "cmsis_gcc.h" -#include "stm32_wpan_common.h" /****************************************************************************** * Function Definitions @@ -34,10 +33,10 @@ void LST_init_head (tListNode * listHead) listHead->prev = listHead; } -bool LST_is_empty (tListNode * listHead) +uint8_t LST_is_empty (tListNode * listHead) { uint32_t primask_bit; - bool return_value; + uint8_t return_value; primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ @@ -206,4 +205,3 @@ void LST_get_prev_node (tListNode * ref_node, tListNode ** node) __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ } -#endif /* STM32WBxx */ \ No newline at end of file diff --git a/src/utility/STM32Cube_FW/stm_list.h b/src/utility/STM32Cube_FW/stm_list.h index 529eeddb..b7c3254c 100644 --- a/src/utility/STM32Cube_FW/stm_list.h +++ b/src/utility/STM32Cube_FW/stm_list.h @@ -4,36 +4,33 @@ * @author MCD Application Team * @brief Header file for linked list library. ****************************************************************************** - * @attention + * @attention * - * <h2><center>© Copyright (c) 2019 STMicroelectronics. - * All rights reserved.</center></h2> + * Copyright (c) 2018-2021 STMicroelectronics. + * All rights reserved. * - * This software component is licensed by ST under BSD 3-Clause license, - * the "License"; You may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * opensource.org/licenses/BSD-3-Clause + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** - */ + */ #ifndef _STM_LIST_H_ #define _STM_LIST_H_ -#include "stm32_wpan_common.h" /* Includes ------------------------------------------------------------------*/ -#include "stdint.h" -#include "stdbool.h" +#include "stm32_wpan_common.h" -typedef PACKED_STRUCT _tListNode { +typedef PACKED_STRUCT _tListNode { struct _tListNode * next; struct _tListNode * prev; } tListNode; void LST_init_head (tListNode * listHead); -bool LST_is_empty (tListNode * listHead); +uint8_t LST_is_empty (tListNode * listHead); void LST_insert_head (tListNode * listHead, tListNode * node); diff --git a/src/utility/STM32Cube_FW/tl.h b/src/utility/STM32Cube_FW/tl.h index 4741599d..cb27246b 100644 --- a/src/utility/STM32Cube_FW/tl.h +++ b/src/utility/STM32Cube_FW/tl.h @@ -4,17 +4,16 @@ * @author MCD Application Team * @brief Header for tl module ****************************************************************************** - * @attention - * - * <h2><center>© Copyright (c) 2019 STMicroelectronics. - * All rights reserved.</center></h2> - * - * This software component is licensed by ST under BSD 3-Clause license, - * the "License"; You may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * opensource.org/licenses/BSD-3-Clause - * - ****************************************************************************** + * @attention + * + * Copyright (c) 2018-2021 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** */ @@ -195,9 +194,22 @@ typedef struct typedef struct { - uint8_t *p_LldBleCmdRspBuffer; - uint8_t *p_LldBleM0CmdBuffer; -} TL_LLD_BLE_Config_t; + uint8_t *p_BleLldCmdRspBuffer; + uint8_t *p_BleLldM0CmdBuffer; +} TL_BLE_LLD_Config_t; + +typedef struct +{ + uint8_t *p_Mac_802_15_4_CmdRspBuffer; + uint8_t *p_Mac_802_15_4_NotAckBuffer; +} TL_MAC_802_15_4_Config_t; + +typedef struct +{ + uint8_t *p_ZigbeeOtCmdRspBuffer; + uint8_t *p_ZigbeeNotAckBuffer; + uint8_t *p_ZigbeeNotifRequestBuffer; +} TL_ZIGBEE_Config_t; /** * @brief Contain the BLE HCI Init Configuration @@ -269,17 +281,17 @@ void TL_LLDTESTS_ReceiveM0Cmd( TL_CmdPacket_t * Notbuffer ); void TL_LLDTESTS_SendM0CmdAck( void ); /****************************************************************************** - * LLD BLE + * BLE LLD ******************************************************************************/ -void TL_LLD_BLE_Init( TL_LLD_BLE_Config_t *p_Config ); -void TL_LLD_BLE_SendCliCmd( void ); -void TL_LLD_BLE_ReceiveCliRsp( TL_CmdPacket_t * Notbuffer ); -void TL_LLD_BLE_SendCliRspAck( void ); -void TL_LLD_BLE_ReceiveM0Cmd( TL_CmdPacket_t * Notbuffer ); -void TL_LLD_BLE_SendM0CmdAck( void ); -void TL_LLD_BLE_SendCmd( void ); -void TL_LLD_BLE_ReceiveRsp( TL_CmdPacket_t * Notbuffer ); -void TL_LLD_BLE_SendRspAck( void ); +void TL_BLE_LLD_Init( TL_BLE_LLD_Config_t *p_Config ); +void TL_BLE_LLD_SendCliCmd( void ); +void TL_BLE_LLD_ReceiveCliRsp( TL_CmdPacket_t * Notbuffer ); +void TL_BLE_LLD_SendCliRspAck( void ); +void TL_BLE_LLD_ReceiveM0Cmd( TL_CmdPacket_t * Notbuffer ); +void TL_BLE_LLD_SendM0CmdAck( void ); +void TL_BLE_LLD_SendCmd( void ); +void TL_BLE_LLD_ReceiveRsp( TL_CmdPacket_t * Notbuffer ); +void TL_BLE_LLD_SendRspAck( void ); /****************************************************************************** * MEMORY MANAGER ******************************************************************************/ @@ -292,10 +304,29 @@ void TL_MM_EvtDone( TL_EvtPacket_t * hcievt ); void TL_TRACES_Init( void ); void TL_TRACES_EvtReceived( TL_EvtPacket_t * hcievt ); +/****************************************************************************** + * MAC 802.15.4 + ******************************************************************************/ +void TL_MAC_802_15_4_Init( TL_MAC_802_15_4_Config_t *p_Config ); +void TL_MAC_802_15_4_SendCmd( void ); +void TL_MAC_802_15_4_CmdEvtReceived( TL_EvtPacket_t * Otbuffer ); +void TL_MAC_802_15_4_NotReceived( TL_EvtPacket_t * Notbuffer ); +void TL_MAC_802_15_4_SendAck ( void ); + +/****************************************************************************** + * ZIGBEE + ******************************************************************************/ +void TL_ZIGBEE_Init( TL_ZIGBEE_Config_t *p_Config ); +void TL_ZIGBEE_SendM4RequestToM0( void ); +void TL_ZIGBEE_SendM4AckToM0Notify ( void ); +void TL_ZIGBEE_NotReceived( TL_EvtPacket_t * Notbuffer ); +void TL_ZIGBEE_CmdEvtReceived( TL_EvtPacket_t * Otbuffer ); +void TL_ZIGBEE_M0RequestReceived(TL_EvtPacket_t * Otbuffer ); +void TL_ZIGBEE_SendM4AckToM0Request(void); + #ifdef __cplusplus } /* extern "C" */ #endif #endif /*__TL_H */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/src/utility/STM32Cube_FW/tl_mbox.c b/src/utility/STM32Cube_FW/tl_mbox.c index 8b579d5b..148bcb19 100644 --- a/src/utility/STM32Cube_FW/tl_mbox.c +++ b/src/utility/STM32Cube_FW/tl_mbox.c @@ -6,18 +6,16 @@ ****************************************************************************** * @attention * - * <h2><center>© Copyright (c) 2019 STMicroelectronics. - * All rights reserved.</center></h2> + * Copyright (c) 2018-2021 STMicroelectronics. + * All rights reserved. * - * This software component is licensed by ST under BSD 3-Clause license, - * the "License"; You may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * opensource.org/licenses/BSD-3-Clause + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ -#if defined(STM32WBxx) /* Includes ------------------------------------------------------------------*/ #include "stm32_wpan_common.h" #include "hw.h" @@ -25,23 +23,20 @@ #include "stm_list.h" #include "tl.h" #include "mbox_def.h" - -/** - * These traces are not yet supported in an usual way in the delivery package - * They can enabled by adding the definition of TL_MM_DBG_EN in the preprocessor option in the IDE - */ -#if(TL_MM_DBG_EN != 0) -#include "app_conf.h" -#include "dbg_trace.h" -#endif - -#if (TL_MM_DBG_EN != 0) -#define TL_MM_DBG__MSG PRINT_MESG_DBG -#else -#define TL_MM_DBG__MSG(...) -#endif +#include "tl_dbg_conf.h" /* Private typedef -----------------------------------------------------------*/ +typedef enum +{ + TL_MB_MM_RELEASE_BUFFER, + TL_MB_BLE_CMD, + TL_MB_BLE_CMD_RSP, + TL_MB_BLE_ASYNCH_EVT, + TL_MB_SYS_CMD, + TL_MB_SYS_CMD_RSP, + TL_MB_SYS_ASYNCH_EVT, +} TL_MB_PacketType_t; + /* Private defines -----------------------------------------------------------*/ /* Private macros ------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ @@ -52,17 +47,19 @@ PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_DeviceInfoTable_t TL_DeviceInfoTa PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_BleTable_t TL_BleTable; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_ThreadTable_t TL_ThreadTable; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_LldTestsTable_t TL_LldTestsTable; -PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_LldBleTable_t TL_LldBleTable; +PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_BleLldTable_t TL_BleLldTable; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_SysTable_t TL_SysTable; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_MemManagerTable_t TL_MemManagerTable; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_TracesTable_t TL_TracesTable; +PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_Mac_802_15_4_t TL_Mac_802_15_4_Table; +PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_ZigbeeTable_t TL_Zigbee_Table; /**< tables */ PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode FreeBufQueue; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode TracesEvtQueue; PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static uint8_t CsBuffer[sizeof(TL_PacketHeader_t) + TL_EVT_HDR_SIZE + sizeof(TL_CsEvt_t)]; -PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static tListNode EvtQueue; -PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static tListNode SystemEvtQueue; +PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode EvtQueue; +PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode SystemEvtQueue; static tListNode LocalFreeBufQueue; @@ -75,7 +72,7 @@ static void (* SYS_EVT_IoBusCallBackFunction) (TL_EvtPacket_t *phcievt); /* Global variables ----------------------------------------------------------*/ /* Private function prototypes -----------------------------------------------*/ static void SendFreeBuf( void ); -static void OutputMemReleaseTrace(TL_EvtPacket_t * phcievt); +static void OutputDbgTrace(TL_MB_PacketType_t packet_type, uint8_t* buffer); /* Public Functions Definition ------------------------------------------------------*/ @@ -96,10 +93,12 @@ void TL_Init( void ) TL_RefTable.p_ble_table = &TL_BleTable; TL_RefTable.p_thread_table = &TL_ThreadTable; TL_RefTable.p_lld_tests_table = &TL_LldTestsTable; - TL_RefTable.p_lld_ble_table = &TL_LldBleTable; + TL_RefTable.p_ble_lld_table = &TL_BleLldTable; TL_RefTable.p_sys_table = &TL_SysTable; TL_RefTable.p_mem_manager_table = &TL_MemManagerTable; TL_RefTable.p_traces_table = &TL_TracesTable; + TL_RefTable.p_mac_802_15_4_table = &TL_Mac_802_15_4_Table; + TL_RefTable.p_zigbee_table = &TL_Zigbee_Table; HW_IPCC_Init(); return; @@ -138,6 +137,8 @@ int32_t TL_BLE_SendCmd( uint8_t* buffer, uint16_t size ) ((TL_CmdPacket_t*)(TL_RefTable.p_ble_table->pcmd_buffer))->cmdserial.type = TL_BLECMD_PKT_TYPE; + OutputDbgTrace(TL_MB_BLE_CMD, TL_RefTable.p_ble_table->pcmd_buffer); + HW_IPCC_BLE_SendCmd(); return 0; @@ -151,6 +152,15 @@ void HW_IPCC_BLE_RxEvtNot(void) { LST_remove_head (&EvtQueue, (tListNode **)&phcievt); + if ( ((phcievt->evtserial.evt.evtcode) == TL_BLEEVT_CS_OPCODE) || ((phcievt->evtserial.evt.evtcode) == TL_BLEEVT_CC_OPCODE ) ) + { + OutputDbgTrace(TL_MB_BLE_CMD_RSP, (uint8_t*)phcievt); + } + else + { + OutputDbgTrace(TL_MB_BLE_ASYNCH_EVT, (uint8_t*)phcievt); + } + BLE_IoBusEvtCallBackFunction(phcievt); } @@ -205,6 +215,8 @@ int32_t TL_SYS_SendCmd( uint8_t* buffer, uint16_t size ) ((TL_CmdPacket_t *)(TL_RefTable.p_sys_table->pcmd_buffer))->cmdserial.type = TL_SYSCMD_PKT_TYPE; + OutputDbgTrace(TL_MB_SYS_CMD, TL_RefTable.p_sys_table->pcmd_buffer); + HW_IPCC_SYS_SendCmd(); return 0; @@ -212,6 +224,8 @@ int32_t TL_SYS_SendCmd( uint8_t* buffer, uint16_t size ) void HW_IPCC_SYS_CmdEvtNot(void) { + OutputDbgTrace(TL_MB_SYS_CMD_RSP, (uint8_t*)(TL_RefTable.p_sys_table->pcmd_buffer) ); + SYS_CMD_IoBusCallBackFunction( (TL_EvtPacket_t*)(TL_RefTable.p_sys_table->pcmd_buffer) ); return; @@ -224,6 +238,9 @@ void HW_IPCC_SYS_EvtNot( void ) while(LST_is_empty(&SystemEvtQueue) == FALSE) { LST_remove_head (&SystemEvtQueue, (tListNode **)&p_evt); + + OutputDbgTrace(TL_MB_SYS_ASYNCH_EVT, (uint8_t*)p_evt ); + SYS_EVT_IoBusCallBackFunction( p_evt ); } @@ -364,75 +381,208 @@ __WEAK void TL_LLDTESTS_ReceiveM0Cmd( TL_CmdPacket_t * Notbuffer ){}; #endif /* LLD_TESTS_WB */ /****************************************************************************** - * LLD BLE + * BLE LLD ******************************************************************************/ -#ifdef LLD_BLE_WB -void TL_LLD_BLE_Init( TL_LLD_BLE_Config_t *p_Config ) +#ifdef BLE_LLD_WB +void TL_BLE_LLD_Init( TL_BLE_LLD_Config_t *p_Config ) { - MB_LldBleTable_t * p_lld_ble_table; + MB_BleLldTable_t * p_ble_lld_table; - p_lld_ble_table = TL_RefTable.p_lld_ble_table; - p_lld_ble_table->cmdrsp_buffer = p_Config->p_LldBleCmdRspBuffer; - p_lld_ble_table->m0cmd_buffer = p_Config->p_LldBleM0CmdBuffer; - HW_IPCC_LLD_BLE_Init(); + p_ble_lld_table = TL_RefTable.p_ble_lld_table; + p_ble_lld_table->cmdrsp_buffer = p_Config->p_BleLldCmdRspBuffer; + p_ble_lld_table->m0cmd_buffer = p_Config->p_BleLldM0CmdBuffer; + HW_IPCC_BLE_LLD_Init(); return; } -void TL_LLD_BLE_SendCliCmd( void ) +void TL_BLE_LLD_SendCliCmd( void ) { - ((TL_CmdPacket_t *)(TL_RefTable.p_lld_ble_table->cmdrsp_buffer))->cmdserial.type = TL_CLICMD_PKT_TYPE; - HW_IPCC_LLD_BLE_SendCliCmd(); + ((TL_CmdPacket_t *)(TL_RefTable.p_ble_lld_table->cmdrsp_buffer))->cmdserial.type = TL_CLICMD_PKT_TYPE; + HW_IPCC_BLE_LLD_SendCliCmd(); return; } -void HW_IPCC_LLD_BLE_ReceiveCliRsp( void ) +void HW_IPCC_BLE_LLD_ReceiveCliRsp( void ) { - TL_LLD_BLE_ReceiveCliRsp( (TL_CmdPacket_t*)(TL_RefTable.p_lld_ble_table->cmdrsp_buffer) ); + TL_BLE_LLD_ReceiveCliRsp( (TL_CmdPacket_t*)(TL_RefTable.p_ble_lld_table->cmdrsp_buffer) ); return; } -void TL_LLD_BLE_SendCliRspAck( void ) +void TL_BLE_LLD_SendCliRspAck( void ) { - HW_IPCC_LLD_BLE_SendCliRspAck(); + HW_IPCC_BLE_LLD_SendCliRspAck(); return; } -void HW_IPCC_LLD_BLE_ReceiveM0Cmd( void ) +void HW_IPCC_BLE_LLD_ReceiveM0Cmd( void ) { - TL_LLD_BLE_ReceiveM0Cmd( (TL_CmdPacket_t*)(TL_RefTable.p_lld_ble_table->m0cmd_buffer) ); + TL_BLE_LLD_ReceiveM0Cmd( (TL_CmdPacket_t*)(TL_RefTable.p_ble_lld_table->m0cmd_buffer) ); return; } -void TL_LLD_BLE_SendM0CmdAck( void ) +void TL_BLE_LLD_SendM0CmdAck( void ) { - HW_IPCC_LLD_BLE_SendM0CmdAck(); + HW_IPCC_BLE_LLD_SendM0CmdAck(); return; } -__WEAK void TL_LLD_BLE_ReceiveCliRsp( TL_CmdPacket_t * Notbuffer ){}; -__WEAK void TL_LLD_BLE_ReceiveM0Cmd( TL_CmdPacket_t * Notbuffer ){}; +__WEAK void TL_BLE_LLD_ReceiveCliRsp( TL_CmdPacket_t * Notbuffer ){}; +__WEAK void TL_BLE_LLD_ReceiveM0Cmd( TL_CmdPacket_t * Notbuffer ){}; /* Transparent Mode */ -void TL_LLD_BLE_SendCmd( void ) +void TL_BLE_LLD_SendCmd( void ) +{ + ((TL_CmdPacket_t *)(TL_RefTable.p_ble_lld_table->cmdrsp_buffer))->cmdserial.type = TL_CLICMD_PKT_TYPE; + HW_IPCC_BLE_LLD_SendCmd(); + return; +} + +void HW_IPCC_BLE_LLD_ReceiveRsp( void ) +{ + TL_BLE_LLD_ReceiveRsp( (TL_CmdPacket_t*)(TL_RefTable.p_ble_lld_table->cmdrsp_buffer) ); + return; +} + +void TL_BLE_LLD_SendRspAck( void ) +{ + HW_IPCC_BLE_LLD_SendRspAck(); + return; +} +#endif /* BLE_LLD_WB */ + +#ifdef MAC_802_15_4_WB +/****************************************************************************** + * MAC 802.15.4 + ******************************************************************************/ +void TL_MAC_802_15_4_Init( TL_MAC_802_15_4_Config_t *p_Config ) +{ + MB_Mac_802_15_4_t * p_mac_802_15_4_table; + + p_mac_802_15_4_table = TL_RefTable.p_mac_802_15_4_table; + + p_mac_802_15_4_table->p_cmdrsp_buffer = p_Config->p_Mac_802_15_4_CmdRspBuffer; + p_mac_802_15_4_table->p_notack_buffer = p_Config->p_Mac_802_15_4_NotAckBuffer; + + HW_IPCC_MAC_802_15_4_Init(); + + return; +} + +void TL_MAC_802_15_4_SendCmd( void ) { - ((TL_CmdPacket_t *)(TL_RefTable.p_lld_ble_table->cmdrsp_buffer))->cmdserial.type = TL_CLICMD_PKT_TYPE; - HW_IPCC_LLD_BLE_SendCmd(); + ((TL_CmdPacket_t *)(TL_RefTable.p_mac_802_15_4_table->p_cmdrsp_buffer))->cmdserial.type = TL_OTCMD_PKT_TYPE; + + HW_IPCC_MAC_802_15_4_SendCmd(); + + return; +} + +void TL_MAC_802_15_4_SendAck ( void ) +{ + ((TL_CmdPacket_t *)(TL_RefTable.p_mac_802_15_4_table->p_notack_buffer))->cmdserial.type = TL_OTACK_PKT_TYPE; + + HW_IPCC_MAC_802_15_4_SendAck(); + return; } -void HW_IPCC_LLD_BLE_ReceiveRsp( void ) +void HW_IPCC_MAC_802_15_4_CmdEvtNot(void) { - TL_LLD_BLE_ReceiveRsp( (TL_CmdPacket_t*)(TL_RefTable.p_lld_ble_table->cmdrsp_buffer) ); + TL_MAC_802_15_4_CmdEvtReceived( (TL_EvtPacket_t*)(TL_RefTable.p_mac_802_15_4_table->p_cmdrsp_buffer) ); + return; } -void TL_LLD_BLE_SendRspAck( void ) +void HW_IPCC_MAC_802_15_4_EvtNot( void ) { - HW_IPCC_LLD_BLE_SendRspAck(); + TL_MAC_802_15_4_NotReceived( (TL_EvtPacket_t*)(TL_RefTable.p_mac_802_15_4_table->p_notack_buffer) ); + return; } -#endif /* LLD_BLE_WB */ + +__WEAK void TL_MAC_802_15_4_CmdEvtReceived( TL_EvtPacket_t * Otbuffer ){}; +__WEAK void TL_MAC_802_15_4_NotReceived( TL_EvtPacket_t * Notbuffer ){}; +#endif + +#ifdef ZIGBEE_WB +/****************************************************************************** + * ZIGBEE + ******************************************************************************/ +void TL_ZIGBEE_Init( TL_ZIGBEE_Config_t *p_Config ) +{ + MB_ZigbeeTable_t * p_zigbee_table; + + p_zigbee_table = TL_RefTable.p_zigbee_table; + p_zigbee_table->appliCmdM4toM0_buffer = p_Config->p_ZigbeeOtCmdRspBuffer; + p_zigbee_table->notifM0toM4_buffer = p_Config->p_ZigbeeNotAckBuffer; + p_zigbee_table->requestM0toM4_buffer = p_Config->p_ZigbeeNotifRequestBuffer; + + HW_IPCC_ZIGBEE_Init(); + + return; +} + +/* Zigbee M4 to M0 Request */ +void TL_ZIGBEE_SendM4RequestToM0( void ) +{ + ((TL_CmdPacket_t *)(TL_RefTable.p_zigbee_table->appliCmdM4toM0_buffer))->cmdserial.type = TL_OTCMD_PKT_TYPE; + + HW_IPCC_ZIGBEE_SendM4RequestToM0(); + + return; +} + +/* Used to receive an ACK from the M0 */ +void HW_IPCC_ZIGBEE_RecvAppliAckFromM0(void) +{ + TL_ZIGBEE_CmdEvtReceived( (TL_EvtPacket_t*)(TL_RefTable.p_zigbee_table->appliCmdM4toM0_buffer) ); + + return; +} + +/* Zigbee notification from M0 to M4 */ +void HW_IPCC_ZIGBEE_RecvM0NotifyToM4( void ) +{ + TL_ZIGBEE_NotReceived( (TL_EvtPacket_t*)(TL_RefTable.p_zigbee_table->notifM0toM4_buffer) ); + + return; +} + +/* Send an ACK to the M0 for a Notification */ +void TL_ZIGBEE_SendM4AckToM0Notify ( void ) +{ + ((TL_CmdPacket_t *)(TL_RefTable.p_zigbee_table->notifM0toM4_buffer))->cmdserial.type = TL_OTACK_PKT_TYPE; + + HW_IPCC_ZIGBEE_SendM4AckToM0Notify(); + + return; +} + +/* Zigbee M0 to M4 Request */ +void HW_IPCC_ZIGBEE_RecvM0RequestToM4( void ) +{ + TL_ZIGBEE_M0RequestReceived( (TL_EvtPacket_t*)(TL_RefTable.p_zigbee_table->requestM0toM4_buffer) ); + + return; +} + +/* Send an ACK to the M0 for a Request */ +void TL_ZIGBEE_SendM4AckToM0Request(void) +{ + ((TL_CmdPacket_t *)(TL_RefTable.p_zigbee_table->requestM0toM4_buffer))->cmdserial.type = TL_OTACK_PKT_TYPE; + + HW_IPCC_ZIGBEE_SendM4AckToM0Request(); + + return; +} + + +__WEAK void TL_ZIGBEE_CmdEvtReceived( TL_EvtPacket_t * Otbuffer ){}; +__WEAK void TL_ZIGBEE_NotReceived( TL_EvtPacket_t * Notbuffer ){}; +#endif + + /****************************************************************************** * MEMORY MANAGER @@ -461,7 +611,7 @@ void TL_MM_EvtDone(TL_EvtPacket_t * phcievt) { LST_insert_tail(&LocalFreeBufQueue, (tListNode *)phcievt); - OutputMemReleaseTrace(phcievt); + OutputDbgTrace(TL_MB_MM_RELEASE_BUFFER, (uint8_t*)phcievt); HW_IPCC_MM_SendFreeBuf( SendFreeBuf ); @@ -481,39 +631,6 @@ static void SendFreeBuf( void ) return; } -static void OutputMemReleaseTrace(TL_EvtPacket_t * phcievt) -{ - switch(phcievt->evtserial.evt.evtcode) - { - case TL_BLEEVT_CS_OPCODE: - TL_MM_DBG__MSG("mm evt released: 0x%02X", phcievt->evtserial.evt.evtcode); - TL_MM_DBG__MSG(" cmd opcode: 0x%04X", ((TL_CsEvt_t*)(phcievt->evtserial.evt.payload))->cmdcode); - TL_MM_DBG__MSG(" buffer addr: 0x%08X", phcievt); - break; - - case TL_BLEEVT_CC_OPCODE: - TL_MM_DBG__MSG("mm evt released: 0x%02X", phcievt->evtserial.evt.evtcode); - TL_MM_DBG__MSG(" cmd opcode: 0x%04X", ((TL_CcEvt_t*)(phcievt->evtserial.evt.payload))->cmdcode); - TL_MM_DBG__MSG(" buffer addr: 0x%08X", phcievt); - break; - - case TL_BLEEVT_VS_OPCODE: - TL_MM_DBG__MSG("mm evt released: 0x%02X", phcievt->evtserial.evt.evtcode); - TL_MM_DBG__MSG(" subevtcode: 0x%04X", ((TL_AsynchEvt_t*)(phcievt->evtserial.evt.payload))->subevtcode); - TL_MM_DBG__MSG(" buffer addr: 0x%08X", phcievt); - break; - - default: - TL_MM_DBG__MSG("mm evt released: 0x%02X", phcievt->evtserial.evt.evtcode); - TL_MM_DBG__MSG(" buffer addr: 0x%08X", phcievt); - break; - } - - TL_MM_DBG__MSG("\r\n"); - - return; -} - /****************************************************************************** * TRACES ******************************************************************************/ @@ -546,5 +663,185 @@ __WEAK void TL_TRACES_EvtReceived( TL_EvtPacket_t * hcievt ) (void)(hcievt); } -#endif /* STM32WBxx */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ +/****************************************************************************** + * DEBUG INFORMATION + ******************************************************************************/ +static void OutputDbgTrace(TL_MB_PacketType_t packet_type, uint8_t* buffer) +{ + TL_EvtPacket_t *p_evt_packet; + TL_CmdPacket_t *p_cmd_packet; + + switch(packet_type) + { + case TL_MB_MM_RELEASE_BUFFER: + p_evt_packet = (TL_EvtPacket_t*)buffer; + switch(p_evt_packet->evtserial.evt.evtcode) + { + case TL_BLEEVT_CS_OPCODE: + TL_MM_DBG_MSG("mm evt released: 0x%02X", p_evt_packet->evtserial.evt.evtcode); + TL_MM_DBG_MSG(" cmd opcode: 0x%04X", ((TL_CsEvt_t*)(p_evt_packet->evtserial.evt.payload))->cmdcode); + TL_MM_DBG_MSG(" buffer addr: 0x%08X", p_evt_packet); + break; + + case TL_BLEEVT_CC_OPCODE: + TL_MM_DBG_MSG("mm evt released: 0x%02X", p_evt_packet->evtserial.evt.evtcode); + TL_MM_DBG_MSG(" cmd opcode: 0x%04X", ((TL_CcEvt_t*)(p_evt_packet->evtserial.evt.payload))->cmdcode); + TL_MM_DBG_MSG(" buffer addr: 0x%08X", p_evt_packet); + break; + + case TL_BLEEVT_VS_OPCODE: + TL_MM_DBG_MSG("mm evt released: 0x%02X", p_evt_packet->evtserial.evt.evtcode); + TL_MM_DBG_MSG(" subevtcode: 0x%04X", ((TL_AsynchEvt_t*)(p_evt_packet->evtserial.evt.payload))->subevtcode); + TL_MM_DBG_MSG(" buffer addr: 0x%08X", p_evt_packet); + break; + + default: + TL_MM_DBG_MSG("mm evt released: 0x%02X", p_evt_packet->evtserial.evt.evtcode); + TL_MM_DBG_MSG(" buffer addr: 0x%08X", p_evt_packet); + break; + } + + TL_MM_DBG_MSG("\r\n"); + break; + + case TL_MB_BLE_CMD: + p_cmd_packet = (TL_CmdPacket_t*)buffer; + TL_HCI_CMD_DBG_MSG("ble cmd: 0x%04X", p_cmd_packet->cmdserial.cmd.cmdcode); + if(p_cmd_packet->cmdserial.cmd.plen != 0) + { + TL_HCI_CMD_DBG_MSG(" payload:"); + TL_HCI_CMD_DBG_BUF(p_cmd_packet->cmdserial.cmd.payload, p_cmd_packet->cmdserial.cmd.plen, ""); + } + TL_HCI_CMD_DBG_MSG("\r\n"); + + TL_HCI_CMD_DBG_RAW(&p_cmd_packet->cmdserial, p_cmd_packet->cmdserial.cmd.plen+TL_CMD_HDR_SIZE); + break; + + case TL_MB_BLE_CMD_RSP: + p_evt_packet = (TL_EvtPacket_t*)buffer; + switch(p_evt_packet->evtserial.evt.evtcode) + { + case TL_BLEEVT_CS_OPCODE: + TL_HCI_CMD_DBG_MSG("ble rsp: 0x%02X", p_evt_packet->evtserial.evt.evtcode); + TL_HCI_CMD_DBG_MSG(" cmd opcode: 0x%04X", ((TL_CsEvt_t*)(p_evt_packet->evtserial.evt.payload))->cmdcode); + TL_HCI_CMD_DBG_MSG(" numhci: 0x%02X", ((TL_CsEvt_t*)(p_evt_packet->evtserial.evt.payload))->numcmd); + TL_HCI_CMD_DBG_MSG(" status: 0x%02X", ((TL_CsEvt_t*)(p_evt_packet->evtserial.evt.payload))->status); + break; + + case TL_BLEEVT_CC_OPCODE: + TL_HCI_CMD_DBG_MSG("ble rsp: 0x%02X", p_evt_packet->evtserial.evt.evtcode); + TL_HCI_CMD_DBG_MSG(" cmd opcode: 0x%04X", ((TL_CcEvt_t*)(p_evt_packet->evtserial.evt.payload))->cmdcode); + TL_HCI_CMD_DBG_MSG(" numhci: 0x%02X", ((TL_CcEvt_t*)(p_evt_packet->evtserial.evt.payload))->numcmd); + TL_HCI_CMD_DBG_MSG(" status: 0x%02X", ((TL_CcEvt_t*)(p_evt_packet->evtserial.evt.payload))->payload[0]); + if((p_evt_packet->evtserial.evt.plen-4) != 0) + { + TL_HCI_CMD_DBG_MSG(" payload:"); + TL_HCI_CMD_DBG_BUF(&((TL_CcEvt_t*)(p_evt_packet->evtserial.evt.payload))->payload[1], p_evt_packet->evtserial.evt.plen-4, ""); + } + break; + + default: + TL_HCI_CMD_DBG_MSG("unknown ble rsp received: %02X", p_evt_packet->evtserial.evt.evtcode); + break; + } + + TL_HCI_CMD_DBG_MSG("\r\n"); + + TL_HCI_CMD_DBG_RAW(&p_evt_packet->evtserial, p_evt_packet->evtserial.evt.plen+TL_EVT_HDR_SIZE); + break; + + case TL_MB_BLE_ASYNCH_EVT: + p_evt_packet = (TL_EvtPacket_t*)buffer; + if(p_evt_packet->evtserial.evt.evtcode != TL_BLEEVT_VS_OPCODE) + { + TL_HCI_EVT_DBG_MSG("ble evt: 0x%02X", p_evt_packet->evtserial.evt.evtcode); + if((p_evt_packet->evtserial.evt.plen) != 0) + { + TL_HCI_EVT_DBG_MSG(" payload:"); + TL_HCI_EVT_DBG_BUF(p_evt_packet->evtserial.evt.payload, p_evt_packet->evtserial.evt.plen, ""); + } + } + else + { + TL_HCI_EVT_DBG_MSG("ble evt: 0x%02X", p_evt_packet->evtserial.evt.evtcode); + TL_HCI_EVT_DBG_MSG(" subevtcode: 0x%04X", ((TL_AsynchEvt_t*)(p_evt_packet->evtserial.evt.payload))->subevtcode); + if((p_evt_packet->evtserial.evt.plen-2) != 0) + { + TL_HCI_EVT_DBG_MSG(" payload:"); + TL_HCI_EVT_DBG_BUF(((TL_AsynchEvt_t*)(p_evt_packet->evtserial.evt.payload))->payload, p_evt_packet->evtserial.evt.plen-2, ""); + } + } + + TL_HCI_EVT_DBG_MSG("\r\n"); + + TL_HCI_EVT_DBG_RAW(&p_evt_packet->evtserial, p_evt_packet->evtserial.evt.plen+TL_EVT_HDR_SIZE); + break; + + case TL_MB_SYS_CMD: + p_cmd_packet = (TL_CmdPacket_t*)buffer; + + TL_SHCI_CMD_DBG_MSG("sys cmd: 0x%04X", p_cmd_packet->cmdserial.cmd.cmdcode); + + if(p_cmd_packet->cmdserial.cmd.plen != 0) + { + TL_SHCI_CMD_DBG_MSG(" payload:"); + TL_SHCI_CMD_DBG_BUF(p_cmd_packet->cmdserial.cmd.payload, p_cmd_packet->cmdserial.cmd.plen, ""); + } + TL_SHCI_CMD_DBG_MSG("\r\n"); + + TL_SHCI_CMD_DBG_RAW(&p_cmd_packet->cmdserial, p_cmd_packet->cmdserial.cmd.plen+TL_CMD_HDR_SIZE); + break; + + case TL_MB_SYS_CMD_RSP: + p_evt_packet = (TL_EvtPacket_t*)buffer; + switch(p_evt_packet->evtserial.evt.evtcode) + { + case TL_BLEEVT_CC_OPCODE: + TL_SHCI_CMD_DBG_MSG("sys rsp: 0x%02X", p_evt_packet->evtserial.evt.evtcode); + TL_SHCI_CMD_DBG_MSG(" cmd opcode: 0x%02X", ((TL_CcEvt_t*)(p_evt_packet->evtserial.evt.payload))->cmdcode); + TL_SHCI_CMD_DBG_MSG(" status: 0x%02X", ((TL_CcEvt_t*)(p_evt_packet->evtserial.evt.payload))->payload[0]); + if((p_evt_packet->evtserial.evt.plen-4) != 0) + { + TL_SHCI_CMD_DBG_MSG(" payload:"); + TL_SHCI_CMD_DBG_BUF(&((TL_CcEvt_t*)(p_evt_packet->evtserial.evt.payload))->payload[1], p_evt_packet->evtserial.evt.plen-4, ""); + } + break; + + default: + TL_SHCI_CMD_DBG_MSG("unknown sys rsp received: %02X", p_evt_packet->evtserial.evt.evtcode); + break; + } + + TL_SHCI_CMD_DBG_MSG("\r\n"); + + TL_SHCI_CMD_DBG_RAW(&p_evt_packet->evtserial, p_evt_packet->evtserial.evt.plen+TL_EVT_HDR_SIZE); + break; + + case TL_MB_SYS_ASYNCH_EVT: + p_evt_packet = (TL_EvtPacket_t*)buffer; + if(p_evt_packet->evtserial.evt.evtcode != TL_BLEEVT_VS_OPCODE) + { + TL_SHCI_EVT_DBG_MSG("unknown sys evt received: %02X", p_evt_packet->evtserial.evt.evtcode); + } + else + { + TL_SHCI_EVT_DBG_MSG("sys evt: 0x%02X", p_evt_packet->evtserial.evt.evtcode); + TL_SHCI_EVT_DBG_MSG(" subevtcode: 0x%04X", ((TL_AsynchEvt_t*)(p_evt_packet->evtserial.evt.payload))->subevtcode); + if((p_evt_packet->evtserial.evt.plen-2) != 0) + { + TL_SHCI_EVT_DBG_MSG(" payload:"); + TL_SHCI_EVT_DBG_BUF(((TL_AsynchEvt_t*)(p_evt_packet->evtserial.evt.payload))->payload, p_evt_packet->evtserial.evt.plen-2, ""); + } + } + + TL_SHCI_EVT_DBG_MSG("\r\n"); + + TL_SHCI_EVT_DBG_RAW(&p_evt_packet->evtserial, p_evt_packet->evtserial.evt.plen+TL_EVT_HDR_SIZE); + break; + + default: + break; + } + + return; +} From 6eb25bcc5bbc4c2299d6d3fe3a4452e94d82520e Mon Sep 17 00:00:00 2001 From: Alexandre Bourdiol <alexandre.bourdiol@st.com> Date: Mon, 6 Dec 2021 11:08:32 +0100 Subject: [PATCH 081/226] chore: clean up and adapt STM32Cube_FW sources for STM32duino Signed-off-by: Frederic Pillon <frederic.pillon@st.com> Signed-off-by: Alexandre Bourdiol <alexandre.bourdiol@st.com> --- src/utility/STM32Cube_FW/app_conf_default.h | 422 +------------------ src/utility/STM32Cube_FW/ble_bufsize.h | 13 +- src/utility/STM32Cube_FW/hw.h | 28 +- src/utility/STM32Cube_FW/hw_ipcc.c | 184 +------- src/utility/STM32Cube_FW/mbox_def.h | 34 -- src/utility/STM32Cube_FW/shci.c | 40 +- src/utility/STM32Cube_FW/shci.h | 47 +-- src/utility/STM32Cube_FW/shci_tl.c | 19 +- src/utility/STM32Cube_FW/stm32_wpan_common.h | 39 +- src/utility/STM32Cube_FW/stm_list.c | 11 +- src/utility/STM32Cube_FW/stm_list.h | 4 +- src/utility/STM32Cube_FW/tl.h | 33 -- src/utility/STM32Cube_FW/tl_mbox.c | 144 +------ 13 files changed, 94 insertions(+), 924 deletions(-) diff --git a/src/utility/STM32Cube_FW/app_conf_default.h b/src/utility/STM32Cube_FW/app_conf_default.h index 7ebc65aa..4f300e0a 100644 --- a/src/utility/STM32Cube_FW/app_conf_default.h +++ b/src/utility/STM32Cube_FW/app_conf_default.h @@ -1,4 +1,3 @@ -/* USER CODE BEGIN Header */ /** ****************************************************************************** * @file app_conf.h @@ -16,94 +15,36 @@ * ****************************************************************************** */ -/* USER CODE END Header */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef APP_CONF_H #define APP_CONF_H #include "hw.h" -#include "hw_conf.h" -#include "hw_if.h" #include "ble_bufsize.h" /****************************************************************************** * Application Config ******************************************************************************/ -/** - * Define Secure Connections Support - */ -#define CFG_SECURE_NOT_SUPPORTED (0x00) -#define CFG_SECURE_OPTIONAL (0x01) -#define CFG_SECURE_MANDATORY (0x02) - -#define CFG_SC_SUPPORT CFG_SECURE_OPTIONAL - -/** - * Define Keypress Notification Support - */ -#define CFG_KEYPRESS_NOT_SUPPORTED (0x00) -#define CFG_KEYPRESS_SUPPORTED (0x01) +/**< generic parameters ******************************************************/ +/* HCI related defines */ -#define CFG_KEYPRESS_NOTIFICATION_SUPPORT CFG_KEYPRESS_NOT_SUPPORTED +#define ACI_HAL_SET_TX_POWER_LEVEL 0xFC0F +#define ACI_WRITE_CONFIG_DATA_OPCODE 0xFC0C +#define ACI_READ_CONFIG_DATA_OPCODE 0xFC0D +#define MAX_HCI_ACL_PACKET_SIZE (sizeof(TL_PacketHeader_t) + 5 + 251) +#define HCI_RESET 0x0C03 -/** - * Numeric Comparison Answers - */ -#define YES (0x01) -#define NO (0x00) - -/** - * Device name configuration for Generic Access Service - */ -#define CFG_GAP_DEVICE_NAME "TEMPLATE" -#define CFG_GAP_DEVICE_NAME_LENGTH (8) - -/** -* Identity root key used to derive LTK and CSRK -*/ -#define CFG_BLE_IRK {0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0} - -/** -* Encryption root key used to derive LTK and CSRK -*/ -#define CFG_BLE_ERK {0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21, 0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21} +#ifndef BLE_SHARED_MEM_BYTE_ORDER + #define BLE_SHARED_MEM_BYTE_ORDER MSBFIRST +#endif +#define BLE_MODULE_SHARED_MEM_BUFFER_SIZE 128 /** - * SMPS supply - * SMPS not used when Set to 0 - * SMPS used when Set to 1 + * Define Tx Power */ -#define CFG_USE_SMPS 0 - -/* USER CODE BEGIN Generic_Parameters */ -/* USER CODE END Generic_Parameters */ - -/**< specific parameters */ -/*****************************************************/ - -/* USER CODE BEGIN Specific_Parameters */ -#define PUSH_BUTTON_SW1_EXTI_IRQHandler EXTI4_IRQHandler - -/* USER CODE END Specific_Parameters */ - -/****************************************************************************** - * Information Table - * - * Version - * [0:3] = Build - 0: Untracked - 15:Released - x: Tracked version - * [4:7] = branch - 0: Mass Market - x: ... - * [8:15] = Subversion - * [16:23] = Version minor - * [24:31] = Version major - * - ******************************************************************************/ -#define CFG_FW_MAJOR_VERSION (0) -#define CFG_FW_MINOR_VERSION (0) -#define CFG_FW_SUBVERSION (1) -#define CFG_FW_BRANCH (0) -#define CFG_FW_BUILD (0) +#define CFG_TX_POWER (0x18) /* -0.15dBm */ /****************************************************************************** * BLE Stack @@ -152,13 +93,15 @@ * Prepare Write List size in terms of number of packet * This parameter is ignored by the CPU2 when CFG_BLE_OPTIONS is set to 1" */ -#define CFG_BLE_PREPARE_WRITE_LIST_SIZE BLE_PREP_WRITE_X_ATT(CFG_BLE_MAX_ATT_MTU) +// #define CFG_BLE_PREPARE_WRITE_LIST_SIZE BLE_PREP_WRITE_X_ATT(CFG_BLE_MAX_ATT_MTU) +#define CFG_BLE_PREPARE_WRITE_LIST_SIZE (0x3A) /** * Number of allocated memory blocks * This parameter is overwritten by the CPU2 with an hardcoded optimal value when the parameter when CFG_BLE_OPTIONS is set to 1 */ -#define CFG_BLE_MBLOCK_COUNT (BLE_MBLOCKS_CALC(CFG_BLE_PREPARE_WRITE_LIST_SIZE, CFG_BLE_MAX_ATT_MTU, CFG_BLE_NUM_LINK)) +// #define CFG_BLE_MBLOCK_COUNT (BLE_MBLOCKS_CALC(CFG_BLE_PREPARE_WRITE_LIST_SIZE, CFG_BLE_MAX_ATT_MTU, CFG_BLE_NUM_LINK)) +#define CFG_BLE_MBLOCK_COUNT (0x79) /** * Enable or disable the Extended Packet length feature. Valid values are 0 or 1. @@ -236,7 +179,7 @@ * 0: LE Power Class 2-3 * other bits: reserved (shall be set to 0) */ -#define CFG_BLE_OPTIONS (SHCI_C2_BLE_INIT_OPTIONS_LL_HOST | SHCI_C2_BLE_INIT_OPTIONS_WITH_SVC_CHANGE_DESC | SHCI_C2_BLE_INIT_OPTIONS_DEVICE_NAME_RW | SHCI_C2_BLE_INIT_OPTIONS_NO_EXT_ADV | SHCI_C2_BLE_INIT_OPTIONS_NO_CS_ALGO2 | SHCI_C2_BLE_INIT_OPTIONS_POWER_CLASS_2_3) +#define CFG_BLE_OPTIONS (SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY) #define CFG_BLE_MAX_COC_INITIATOR_NBR (32) @@ -256,334 +199,5 @@ #define CFG_BLE_RX_MODEL_CONFIG SHCI_C2_BLE_INIT_RX_MODEL_AGC_RSSI_LEGACY -/****************************************************************************** - * Transport Layer - ******************************************************************************/ -/** - * Queue length of BLE Event - * This parameter defines the number of asynchronous events that can be stored in the HCI layer before - * being reported to the application. When a command is sent to the BLE core coprocessor, the HCI layer - * is waiting for the event with the Num_HCI_Command_Packets set to 1. The receive queue shall be large - * enough to store all asynchronous events received in between. - * When CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE is set to 27, this allow to store three 255 bytes long asynchronous events - * between the HCI command and its event. - * This parameter depends on the value given to CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE. When the queue size is to small, - * the system may hang if the queue is full with asynchronous events and the HCI layer is still waiting - * for a CC/CS event, In that case, the notification TL_BLE_HCI_ToNot() is called to indicate - * to the application a HCI command did not receive its command event within 30s (Default HCI Timeout). - */ -#define CFG_TLBLE_EVT_QUEUE_LENGTH 5 -/** - * This parameter should be set to fit most events received by the HCI layer. It defines the buffer size of each element - * allocated in the queue of received events and can be used to optimize the amount of RAM allocated by the Memory Manager. - * It should not exceed 255 which is the maximum HCI packet payload size (a greater value is a lost of memory as it will - * never be used) - * It shall be at least 4 to receive the command status event in one frame. - * The default value is set to 27 to allow receiving an event of MTU size in a single buffer. This value maybe reduced - * further depending on the application. - */ -#define CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE 255 /**< Set to 255 with the memory manager and the mailbox */ - -#define TL_BLE_EVENT_FRAME_SIZE ( TL_EVT_HDR_SIZE + CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE ) -/****************************************************************************** - * UART interfaces - ******************************************************************************/ - -/** - * Select UART interfaces - */ -#define CFG_UART_GUI hw_uart1 -#define CFG_DEBUG_TRACE_UART 0 -/****************************************************************************** - * USB interface - ******************************************************************************/ - -/** - * Enable/Disable USB interface - */ -#define CFG_USB_INTERFACE_ENABLE 0 - -/****************************************************************************** - * IPCC interface - ******************************************************************************/ - -/** - * The IPCC is dedicated to the communication between the CPU2 and the CPU1 - * and shall not be modified by the application - * The two following definitions shall not be modified - */ -#define HAL_IPCC_TX_IRQHandler(...) HW_IPCC_Tx_Handler( ) -#define HAL_IPCC_RX_IRQHandler(...) HW_IPCC_Rx_Handler( ) - -/****************************************************************************** - * Low Power - ******************************************************************************/ -/** - * When set to 1, the low power mode is enable - * When set to 0, the device stays in RUN mode - */ -#define CFG_LPM_SUPPORTED 1 - -/****************************************************************************** - * RTC interface - ******************************************************************************/ -#define HAL_RTCEx_WakeUpTimerIRQHandler(...) HW_TS_RTC_Wakeup_Handler( ) - -/****************************************************************************** - * Timer Server - ******************************************************************************/ -/** - * CFG_RTC_WUCKSEL_DIVIDER: This sets the RTCCLK divider to the wakeup timer. - * The lower is the value, the better is the power consumption and the accuracy of the timerserver - * The higher is the value, the finest is the granularity - * - * CFG_RTC_ASYNCH_PRESCALER: This sets the asynchronous prescaler of the RTC. It should as high as possible ( to output - * clock as low as possible) but the output clock should be equal or higher frequency compare to the clock feeding - * the wakeup timer. A lower clock speed would impact the accuracy of the timer server. - * - * CFG_RTC_SYNCH_PRESCALER: This sets the synchronous prescaler of the RTC. - * When the 1Hz calendar clock is required, it shall be sets according to other settings - * When the 1Hz calendar clock is not needed, CFG_RTC_SYNCH_PRESCALER should be set to 0x7FFF (MAX VALUE) - * - * CFG_RTCCLK_DIVIDER_CONF: - * Shall be set to either 0,2,4,8,16 - * When set to either 2,4,8,16, the 1Hhz calendar is supported - * When set to 0, the user sets its own configuration - * - * The following settings are computed with LSI as input to the RTC - */ - -#define CFG_RTCCLK_DIVIDER_CONF 0 - -#if (CFG_RTCCLK_DIVIDER_CONF == 0) -/** - * Custom configuration - * It does not support 1Hz calendar - * It divides the RTC CLK by 16 - */ - -#define CFG_RTCCLK_DIV (16) -#define CFG_RTC_WUCKSEL_DIVIDER (0) -#define CFG_RTC_ASYNCH_PRESCALER (0x0F) -#define CFG_RTC_SYNCH_PRESCALER (0x7FFF) - -#else - -#if (CFG_RTCCLK_DIVIDER_CONF == 2) -/** - * It divides the RTC CLK by 2 - */ -#define CFG_RTC_WUCKSEL_DIVIDER (3) -#endif - -#if (CFG_RTCCLK_DIVIDER_CONF == 4) -/** - * It divides the RTC CLK by 4 - */ -#define CFG_RTC_WUCKSEL_DIVIDER (2) -#endif - -#if (CFG_RTCCLK_DIVIDER_CONF == 8) -/** - * It divides the RTC CLK by 8 - */ -#define CFG_RTC_WUCKSEL_DIVIDER (1) -#endif - -#if (CFG_RTCCLK_DIVIDER_CONF == 16) -/** - * It divides the RTC CLK by 16 - */ -#define CFG_RTC_WUCKSEL_DIVIDER (0) -#endif - -#define CFG_RTCCLK_DIV CFG_RTCCLK_DIVIDER_CONF -#define CFG_RTC_ASYNCH_PRESCALER (CFG_RTCCLK_DIV - 1) -#define CFG_RTC_SYNCH_PRESCALER (DIVR( LSE_VALUE, (CFG_RTC_ASYNCH_PRESCALER+1) ) - 1 ) - -#endif - -/** tick timer values */ -#define CFG_TS_TICK_VAL DIVR( (CFG_RTCCLK_DIV * 1000000), LSE_VALUE ) -#define CFG_TS_TICK_VAL_PS DIVR( ((uint64_t)CFG_RTCCLK_DIV * 1e12), (uint64_t)LSE_VALUE ) - -typedef enum -{ - CFG_TIM_PROC_ID_ISR, - /* USER CODE BEGIN CFG_TimProcID_t */ - - /* USER CODE END CFG_TimProcID_t */ -} CFG_TimProcID_t; - -/****************************************************************************** - * Debug - ******************************************************************************/ -/** - * When set, this resets some hw resources to set the device in the same state than the power up - * The FW resets only register that may prevent the FW to run properly - * - * This shall be set to 0 in a final product - * - */ -#define CFG_HW_RESET_BY_FW 1 - -/** - * keep debugger enabled while in any low power mode when set to 1 - * should be set to 0 in production - */ -#define CFG_DEBUGGER_SUPPORTED 0 - -/** - * When set to 1, the traces are enabled in the BLE services - */ -#define CFG_DEBUG_BLE_TRACE 0 - -/** - * Enable or Disable traces in application - */ -#define CFG_DEBUG_APP_TRACE 0 - -#if (CFG_DEBUG_APP_TRACE != 0) -#define APP_DBG_MSG PRINT_MESG_DBG -#else -#define APP_DBG_MSG PRINT_NO_MESG -#endif - -#if ( (CFG_DEBUG_BLE_TRACE != 0) || (CFG_DEBUG_APP_TRACE != 0) ) -#define CFG_DEBUG_TRACE 1 -#endif - -#if (CFG_DEBUG_TRACE != 0) -#undef CFG_LPM_SUPPORTED -#undef CFG_DEBUGGER_SUPPORTED -#define CFG_LPM_SUPPORTED 0 -#define CFG_DEBUGGER_SUPPORTED 1 -#endif - -/** - * When CFG_DEBUG_TRACE_FULL is set to 1, the trace are output with the API name, the file name and the line number - * When CFG_DEBUG_TRACE_LIGHT is set to 1, only the debug message is output - * - * When both are set to 0, no trace are output - * When both are set to 1, CFG_DEBUG_TRACE_FULL is selected - */ -#define CFG_DEBUG_TRACE_LIGHT 0 -#define CFG_DEBUG_TRACE_FULL 0 - -#if (( CFG_DEBUG_TRACE != 0 ) && ( CFG_DEBUG_TRACE_LIGHT == 0 ) && (CFG_DEBUG_TRACE_FULL == 0)) -#undef CFG_DEBUG_TRACE_FULL -#undef CFG_DEBUG_TRACE_LIGHT -#define CFG_DEBUG_TRACE_FULL 0 -#define CFG_DEBUG_TRACE_LIGHT 1 -#endif - -#if ( CFG_DEBUG_TRACE == 0 ) -#undef CFG_DEBUG_TRACE_FULL -#undef CFG_DEBUG_TRACE_LIGHT -#define CFG_DEBUG_TRACE_FULL 0 -#define CFG_DEBUG_TRACE_LIGHT 0 -#endif - -/** - * When not set, the traces is looping on sending the trace over UART - */ -#define DBG_TRACE_USE_CIRCULAR_QUEUE 1 - -/** - * max buffer Size to queue data traces and max data trace allowed. - * Only Used if DBG_TRACE_USE_CIRCULAR_QUEUE is defined - */ -#define DBG_TRACE_MSG_QUEUE_SIZE 4096 -#define MAX_DBG_TRACE_MSG_SIZE 1024 - -/* USER CODE BEGIN Defines */ -#define CFG_LED_SUPPORTED 1 -#define CFG_BUTTON_SUPPORTED 1 - -#define PUSH_BUTTON_SW1_EXTI_IRQHandler EXTI4_IRQHandler -#define PUSH_BUTTON_SW2_EXTI_IRQHandler EXTI0_IRQHandler -#define PUSH_BUTTON_SW3_EXTI_IRQHandler EXTI1_IRQHandler -/* USER CODE END Defines */ - -/****************************************************************************** - * Scheduler - ******************************************************************************/ - -/** - * These are the lists of task id registered to the scheduler - * Each task id shall be in the range [0:31] - * This mechanism allows to implement a generic code in the API TL_BLE_HCI_StatusNot() to comply with - * the requirement that a HCI/ACI command shall never be sent if there is already one pending - */ - -/**< Add in that list all tasks that may send a ACI/HCI command */ -typedef enum -{ - CFG_TASK_BLE_HCI_CMD_ID, - CFG_TASK_SYS_HCI_CMD_ID, - CFG_TASK_HCI_ACL_DATA_ID, - CFG_TASK_SYS_LOCAL_CMD_ID, - CFG_TASK_TX_TO_HOST_ID, - /* USER CODE BEGIN CFG_Task_Id_With_HCI_Cmd_t */ - CFG_TASK_SW1_BUTTON_PUSHED_ID, - CFG_TASK_SW2_BUTTON_PUSHED_ID, - CFG_TASK_SW3_BUTTON_PUSHED_ID, - /* USER CODE END CFG_Task_Id_With_HCI_Cmd_t */ - CFG_LAST_TASK_ID_WITH_HCICMD, /**< Shall be LAST in the list */ -} CFG_Task_Id_With_HCI_Cmd_t; - -/**< Add in that list all tasks that never send a ACI/HCI command */ -typedef enum -{ - CFG_FIRST_TASK_ID_WITH_NO_HCICMD = CFG_LAST_TASK_ID_WITH_HCICMD - 1, /**< Shall be FIRST in the list */ - CFG_TASK_SYSTEM_HCI_ASYNCH_EVT_ID, - /* USER CODE BEGIN CFG_Task_Id_With_NO_HCI_Cmd_t */ - - /* USER CODE END CFG_Task_Id_With_NO_HCI_Cmd_t */ - CFG_LAST_TASK_ID_WITHO_NO_HCICMD /**< Shall be LAST in the list */ -} CFG_Task_Id_With_NO_HCI_Cmd_t; - -#define CFG_TASK_NBR CFG_LAST_TASK_ID_WITHO_NO_HCICMD - -/** - * This is the list of priority required by the application - * Each Id shall be in the range 0..31 - */ -typedef enum -{ - CFG_SCH_PRIO_0, - CFG_PRIO_NBR, -} CFG_SCH_Prio_Id_t; - -/** - * This is a bit mapping over 32bits listing all events id supported in the application - */ -typedef enum -{ - CFG_IDLEEVT_SYSTEM_HCI_CMD_EVT_RSP_ID, -} CFG_IdleEvt_Id_t; - -/****************************************************************************** - * LOW POWER - ******************************************************************************/ -/** - * Supported requester to the MCU Low Power Manager - can be increased up to 32 - * It list a bit mapping of all user of the Low Power Manager - */ -typedef enum -{ - CFG_LPM_APP, - CFG_LPM_APP_BLE, - /* USER CODE BEGIN CFG_LPM_Id_t */ - - /* USER CODE END CFG_LPM_Id_t */ -} CFG_LPM_Id_t; - -/****************************************************************************** - * OTP manager - ******************************************************************************/ -#define CFG_OTP_BASE_ADDRESS OTP_AREA_BASE - -#define CFG_OTP_END_ADRESS OTP_AREA_END_ADDR #endif /*APP_CONF_H */ diff --git a/src/utility/STM32Cube_FW/ble_bufsize.h b/src/utility/STM32Cube_FW/ble_bufsize.h index ba9c4d3c..73b78872 100644 --- a/src/utility/STM32Cube_FW/ble_bufsize.h +++ b/src/utility/STM32Cube_FW/ble_bufsize.h @@ -75,17 +75,24 @@ ((pw) + MAX(BLE_MEM_BLOCK_X_MTU(mtu, n_link), \ BLE_MBLOCKS_SECURE_CONNECTIONS)) +/* + * BLE_DEFAULT_MBLOCKS_COUNT: default memory blocks count + */ +#define BLE_DEFAULT_MBLOCKS_COUNT(n_link) \ + BLE_MBLOCKS_CALC(BLE_DEFAULT_PREP_WRITE_LIST_SIZE, \ + BLE_DEFAULT_MAX_ATT_MTU, n_link) + /* * BLE_FIXED_BUFFER_SIZE_BYTES: - * A part of the RAM, is dinamically allocated by initilizing all the pointers + * A part of the RAM, is dynamically allocated by initializing all the pointers * defined in a global context variable "mem_alloc_ctx_p". * This initialization is made in the Dynamic_allocator functions, which - * assing a portion of RAM given by the external application to the above + * assign a portion of RAM given by the external application to the above * mentioned "global pointers". * * The size of this Dynamic RAM is made of 2 main components: * - a part that is parameters-dependent (num of links, GATT buffers, ...), - * and which value is explicited by the following macro; + * and which value is defined by the following macro; * - a part, that may be considered "fixed", i.e. independent from the above * mentioned parameters. */ diff --git a/src/utility/STM32Cube_FW/hw.h b/src/utility/STM32Cube_FW/hw.h index 503fa2ca..fcf04517 100644 --- a/src/utility/STM32Cube_FW/hw.h +++ b/src/utility/STM32Cube_FW/hw.h @@ -26,14 +26,21 @@ extern "C" { #endif /* Includes ------------------------------------------------------------------*/ +#include "stm32_def.h" +#include "stm32wbxx_ll_bus.h" +#include "stm32wbxx_ll_exti.h" +#include "stm32wbxx_ll_system.h" +#include "stm32wbxx_ll_rcc.h" +#include "stm32wbxx_ll_ipcc.h" +#include "stm32wbxx_ll_cortex.h" +#include "stm32wbxx_ll_utils.h" +#include "stm32wbxx_ll_pwr.h" /****************************************************************************** * HW IPCC ******************************************************************************/ void HW_IPCC_Enable( void ); void HW_IPCC_Init( void ); - void HW_IPCC_Rx_Handler( void ); - void HW_IPCC_Tx_Handler( void ); void HW_IPCC_BLE_Init( void ); void HW_IPCC_BLE_SendCmd( void ); @@ -80,23 +87,6 @@ extern "C" { void HW_IPCC_TRACES_Init( void ); void HW_IPCC_TRACES_EvtNot( void ); - void HW_IPCC_MAC_802_15_4_Init( void ); - void HW_IPCC_MAC_802_15_4_SendCmd( void ); - void HW_IPCC_MAC_802_15_4_SendAck( void ); - void HW_IPCC_MAC_802_15_4_CmdEvtNot( void ); - void HW_IPCC_MAC_802_15_4_EvtNot( void ); - - void HW_IPCC_ZIGBEE_Init( void ); - - void HW_IPCC_ZIGBEE_SendM4RequestToM0(void); /* M4 Request to M0 */ - void HW_IPCC_ZIGBEE_RecvAppliAckFromM0(void); /* Request ACK from M0 */ - - void HW_IPCC_ZIGBEE_RecvM0NotifyToM4(void); /* M0 Notify to M4 */ - void HW_IPCC_ZIGBEE_SendM4AckToM0Notify(void); /* Notify ACK from M4 */ - void HW_IPCC_ZIGBEE_RecvM0RequestToM4(void); /* M0 Request to M4 */ - void HW_IPCC_ZIGBEE_SendM4AckToM0Request(void); /* Request ACK from M4 */ - - #ifdef __cplusplus } #endif diff --git a/src/utility/STM32Cube_FW/hw_ipcc.c b/src/utility/STM32Cube_FW/hw_ipcc.c index c5a941d2..2f4f6cc2 100644 --- a/src/utility/STM32Cube_FW/hw_ipcc.c +++ b/src/utility/STM32Cube_FW/hw_ipcc.c @@ -18,8 +18,9 @@ */ /* USER CODE END Header */ +#if defined(STM32WBxx) /* Includes ------------------------------------------------------------------*/ -#include "app_common.h" +#include "hw.h" #include "mbox_def.h" /* Global variables ---------------------------------------------------------*/ @@ -56,34 +57,17 @@ static void HW_IPCC_LLD_BLE_ReceiveRspHandler( void ); static void HW_IPCC_LLD_BLE_ReceiveM0CmdHandler( void ); #endif -#ifdef MAC_802_15_4_WB -static void HW_IPCC_MAC_802_15_4_CmdEvtHandler( void ); -static void HW_IPCC_MAC_802_15_4_NotEvtHandler( void ); -#endif - -#ifdef ZIGBEE_WB -static void HW_IPCC_ZIGBEE_CmdEvtHandler( void ); -static void HW_IPCC_ZIGBEE_StackNotifEvtHandler( void ); -static void HW_IPCC_ZIGBEE_StackM0RequestHandler( void ); -#endif - /* Public function definition -----------------------------------------------*/ /****************************************************************************** * INTERRUPT HANDLER ******************************************************************************/ -void HW_IPCC_Rx_Handler( void ) +void IPCC_C1_RX_IRQHandler(void) { if (HW_IPCC_RX_PENDING( HW_IPCC_SYSTEM_EVENT_CHANNEL )) { HW_IPCC_SYS_EvtHandler(); } -#ifdef MAC_802_15_4_WB - else if (HW_IPCC_RX_PENDING( HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL )) - { - HW_IPCC_MAC_802_15_4_NotEvtHandler(); - } -#endif /* MAC_802_15_4_WB */ #ifdef THREAD_WB else if (HW_IPCC_RX_PENDING( HW_IPCC_THREAD_NOTIFICATION_ACK_CHANNEL )) { @@ -114,16 +98,6 @@ void HW_IPCC_Rx_Handler( void ) HW_IPCC_LLD_BLE_ReceiveM0CmdHandler(); } #endif /* LLD_TESTS_WB */ -#ifdef ZIGBEE_WB - else if (HW_IPCC_RX_PENDING( HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL )) - { - HW_IPCC_ZIGBEE_StackNotifEvtHandler(); - } - else if (HW_IPCC_RX_PENDING( HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL )) - { - HW_IPCC_ZIGBEE_StackM0RequestHandler(); - } -#endif /* ZIGBEE_WB */ else if (HW_IPCC_RX_PENDING( HW_IPCC_BLE_EVENT_CHANNEL )) { HW_IPCC_BLE_EvtHandler(); @@ -132,22 +106,14 @@ void HW_IPCC_Rx_Handler( void ) { HW_IPCC_TRACES_EvtHandler(); } - - return; } -void HW_IPCC_Tx_Handler( void ) +void IPCC_C1_TX_IRQHandler(void) { if (HW_IPCC_TX_PENDING( HW_IPCC_SYSTEM_CMD_RSP_CHANNEL )) { HW_IPCC_SYS_CmdEvtHandler(); } -#ifdef MAC_802_15_4_WB - else if (HW_IPCC_TX_PENDING( HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL )) - { - HW_IPCC_MAC_802_15_4_CmdEvtHandler(); - } -#endif /* MAC_802_15_4_WB */ #ifdef THREAD_WB else if (HW_IPCC_TX_PENDING( HW_IPCC_THREAD_OT_CMD_RSP_CHANNEL )) { @@ -157,12 +123,6 @@ void HW_IPCC_Tx_Handler( void ) #ifdef LLD_TESTS_WB // No TX handler for LLD tests #endif /* LLD_TESTS_WB */ -#ifdef ZIGBEE_WB - if (HW_IPCC_TX_PENDING( HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL )) - { - HW_IPCC_ZIGBEE_CmdEvtHandler(); - } -#endif /* ZIGBEE_WB */ else if (HW_IPCC_TX_PENDING( HW_IPCC_MM_RELEASE_BUFFER_CHANNEL )) { HW_IPCC_MM_FreeBufHandler(); @@ -171,9 +131,8 @@ void HW_IPCC_Tx_Handler( void ) { HW_IPCC_BLE_AclDataEvtHandler(); } - - return; } + /****************************************************************************** * GENERAL ******************************************************************************/ @@ -263,8 +222,8 @@ static void HW_IPCC_BLE_AclDataEvtHandler( void ) return; } -__weak void HW_IPCC_BLE_AclDataAckNot( void ){}; -__weak void HW_IPCC_BLE_RxEvtNot( void ){}; +__WEAK void HW_IPCC_BLE_AclDataAckNot( void ){}; +__WEAK void HW_IPCC_BLE_RxEvtNot( void ){}; /****************************************************************************** * SYSTEM @@ -302,56 +261,8 @@ static void HW_IPCC_SYS_EvtHandler( void ) return; } -__weak void HW_IPCC_SYS_CmdEvtNot( void ){}; -__weak void HW_IPCC_SYS_EvtNot( void ){}; - -/****************************************************************************** - * MAC 802.15.4 - ******************************************************************************/ -#ifdef MAC_802_15_4_WB -void HW_IPCC_MAC_802_15_4_Init( void ) -{ - LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL ); - - return; -} - -void HW_IPCC_MAC_802_15_4_SendCmd( void ) -{ - LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL ); - LL_C1_IPCC_EnableTransmitChannel( IPCC, HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL ); - - return; -} - -void HW_IPCC_MAC_802_15_4_SendAck( void ) -{ - LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL ); - LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL ); - - return; -} - -static void HW_IPCC_MAC_802_15_4_CmdEvtHandler( void ) -{ - LL_C1_IPCC_DisableTransmitChannel( IPCC, HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL ); - - HW_IPCC_MAC_802_15_4_CmdEvtNot(); - - return; -} - -static void HW_IPCC_MAC_802_15_4_NotEvtHandler( void ) -{ - LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL ); - - HW_IPCC_MAC_802_15_4_EvtNot(); - - return; -} -__weak void HW_IPCC_MAC_802_15_4_CmdEvtNot( void ){}; -__weak void HW_IPCC_MAC_802_15_4_EvtNot( void ){}; -#endif +__WEAK void HW_IPCC_SYS_CmdEvtNot( void ){}; +__WEAK void HW_IPCC_SYS_EvtNot( void ){}; /****************************************************************************** * THREAD @@ -423,9 +334,9 @@ static void HW_IPCC_THREAD_CliNotEvtHandler( void ) return; } -__weak void HW_IPCC_OT_CmdEvtNot( void ){}; -__weak void HW_IPCC_CLI_CmdEvtNot( void ){}; -__weak void HW_IPCC_THREAD_EvtNot( void ){}; +__WEAK void HW_IPCC_OT_CmdEvtNot( void ){}; +__WEAK void HW_IPCC_CLI_CmdEvtNot( void ){}; +__WEAK void HW_IPCC_THREAD_EvtNot( void ){}; #endif /* THREAD_WB */ @@ -547,74 +458,6 @@ void HW_IPCC_LLD_BLE_SendRspAck( void ) #endif /* LLD_BLE_WB */ -/****************************************************************************** - * ZIGBEE - ******************************************************************************/ -#ifdef ZIGBEE_WB -void HW_IPCC_ZIGBEE_Init( void ) -{ - LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL ); - LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL ); - - return; -} - -void HW_IPCC_ZIGBEE_SendM4RequestToM0( void ) -{ - LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL ); - LL_C1_IPCC_EnableTransmitChannel( IPCC, HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL ); - - return; -} - -void HW_IPCC_ZIGBEE_SendM4AckToM0Notify( void ) -{ - LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL ); - LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL ); - - return; -} - -static void HW_IPCC_ZIGBEE_CmdEvtHandler( void ) -{ - LL_C1_IPCC_DisableTransmitChannel( IPCC, HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL ); - - HW_IPCC_ZIGBEE_RecvAppliAckFromM0(); - - return; -} - -static void HW_IPCC_ZIGBEE_StackNotifEvtHandler( void ) -{ - LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL ); - - HW_IPCC_ZIGBEE_RecvM0NotifyToM4(); - - return; -} - -static void HW_IPCC_ZIGBEE_StackM0RequestHandler( void ) -{ - LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL ); - - HW_IPCC_ZIGBEE_RecvM0RequestToM4(); - - return; -} - -void HW_IPCC_ZIGBEE_SendM4AckToM0Request( void ) -{ - LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL ); - LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL ); - - return; -} - -__weak void HW_IPCC_ZIGBEE_RecvAppliAckFromM0( void ){}; -__weak void HW_IPCC_ZIGBEE_RecvM0NotifyToM4( void ){}; -__weak void HW_IPCC_ZIGBEE_RecvM0RequestToM4( void ){}; -#endif /* ZIGBEE_WB */ - /****************************************************************************** * MEMORY MANAGER ******************************************************************************/ @@ -665,4 +508,5 @@ static void HW_IPCC_TRACES_EvtHandler( void ) return; } -__weak void HW_IPCC_TRACES_EvtNot( void ){}; +__WEAK void HW_IPCC_TRACES_EvtNot( void ){}; +#endif /* STM32WBxx */ diff --git a/src/utility/STM32Cube_FW/mbox_def.h b/src/utility/STM32Cube_FW/mbox_def.h index 06536d34..c898e52a 100644 --- a/src/utility/STM32Cube_FW/mbox_def.h +++ b/src/utility/STM32Cube_FW/mbox_def.h @@ -105,12 +105,6 @@ extern "C" { uint8_t *m0cmd_buffer; } MB_BleLldTable_t; - typedef struct - { - uint8_t *notifM0toM4_buffer; - uint8_t *appliCmdM4toM0_buffer; - uint8_t *requestM0toM4_buffer; - } MB_ZigbeeTable_t; /** * msg * [0:7] = cmd/evt @@ -138,13 +132,6 @@ extern "C" { uint8_t *traces_queue; } MB_TracesTable_t; - typedef struct - { - uint8_t *p_cmdrsp_buffer; - uint8_t *p_notack_buffer; - uint8_t *evt_queue; - } MB_Mac_802_15_4_t; - typedef struct { MB_DeviceInfoTable_t *p_device_info_table; @@ -153,8 +140,6 @@ extern "C" { MB_SysTable_t *p_sys_table; MB_MemManagerTable_t *p_mem_manager_table; MB_TracesTable_t *p_traces_table; - MB_Mac_802_15_4_t *p_mac_802_15_4_table; - MB_ZigbeeTable_t *p_zigbee_table; MB_LldTestsTable_t *p_lld_tests_table; MB_BleLldTable_t *p_ble_lld_table; } MB_RefTable_t; @@ -198,15 +183,6 @@ typedef struct * | | * |<---HW_IPCC_SYSTEM_EVENT_CHANNEL-----------------| * | | - * | (ZIGBEE) | - * |----HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL------------>| - * | | - * |----HW_IPCC_ZIGBEE_CMD_CLI_CHANNEL-------------->| - * | | - * |<---HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL-------| - * | | - * |<---HW_IPCC_ZIGBEE_CLI_NOTIF_ACK_CHANNEL---------| - * | | * | (THREAD) | * |----HW_IPCC_THREAD_OT_CMD_RSP_CHANNEL----------->| * | | @@ -230,11 +206,6 @@ typedef struct * | | * |<---HW_IPCC_BLE_LLD_M0_CMD_CHANNEL---------------| * | | - * | (MAC) | - * |----HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL-------->| - * | | - * |<---HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL| - * | | * | (BUFFER) | * |----HW_IPCC_MM_RELEASE_BUFFER_CHANNE------------>| * | | @@ -252,8 +223,6 @@ typedef struct #define HW_IPCC_BLE_CMD_CHANNEL LL_IPCC_CHANNEL_1 #define HW_IPCC_SYSTEM_CMD_RSP_CHANNEL LL_IPCC_CHANNEL_2 #define HW_IPCC_THREAD_OT_CMD_RSP_CHANNEL LL_IPCC_CHANNEL_3 -#define HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL LL_IPCC_CHANNEL_3 -#define HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL LL_IPCC_CHANNEL_3 #define HW_IPCC_MM_RELEASE_BUFFER_CHANNEL LL_IPCC_CHANNEL_4 #define HW_IPCC_THREAD_CLI_CMD_CHANNEL LL_IPCC_CHANNEL_5 #define HW_IPCC_LLDTESTS_CLI_CMD_CHANNEL LL_IPCC_CHANNEL_5 @@ -265,8 +234,6 @@ typedef struct #define HW_IPCC_BLE_EVENT_CHANNEL LL_IPCC_CHANNEL_1 #define HW_IPCC_SYSTEM_EVENT_CHANNEL LL_IPCC_CHANNEL_2 #define HW_IPCC_THREAD_NOTIFICATION_ACK_CHANNEL LL_IPCC_CHANNEL_3 -#define HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL LL_IPCC_CHANNEL_3 -#define HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL LL_IPCC_CHANNEL_3 #define HW_IPCC_LLDTESTS_M0_CMD_CHANNEL LL_IPCC_CHANNEL_3 #define HW_IPCC_BLE_LLD_M0_CMD_CHANNEL LL_IPCC_CHANNEL_3 #define HW_IPCC_TRACES_CHANNEL LL_IPCC_CHANNEL_4 @@ -274,6 +241,5 @@ typedef struct #define HW_IPCC_LLDTESTS_CLI_RSP_CHANNEL LL_IPCC_CHANNEL_5 #define HW_IPCC_BLE_LLD_CLI_RSP_CHANNEL LL_IPCC_CHANNEL_5 #define HW_IPCC_BLE_LLD_RSP_CHANNEL LL_IPCC_CHANNEL_5 -#define HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL LL_IPCC_CHANNEL_5 #endif /*__MBOX_H */ diff --git a/src/utility/STM32Cube_FW/shci.c b/src/utility/STM32Cube_FW/shci.c index 301db76d..bd7bb3a1 100644 --- a/src/utility/STM32Cube_FW/shci.c +++ b/src/utility/STM32Cube_FW/shci.c @@ -16,7 +16,7 @@ ****************************************************************************** */ - +#if defined(STM32WBxx) /* Includes ------------------------------------------------------------------*/ #include "stm32_wpan_common.h" @@ -352,24 +352,6 @@ SHCI_CmdStatus_t SHCI_C2_BLE_LLD_Init( uint8_t param_size, uint8_t * p_param ) return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); } -SHCI_CmdStatus_t SHCI_C2_ZIGBEE_Init( void ) -{ - /** - * Buffer is large enough to hold command complete without payload - */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; - TL_EvtPacket_t * p_rsp; - - p_rsp = (TL_EvtPacket_t *)local_buffer; - - shci_send( SHCI_OPCODE_C2_ZIGBEE_INIT, - 0, - 0, - p_rsp ); - - return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); -} - SHCI_CmdStatus_t SHCI_C2_DEBUG_Init( SHCI_C2_DEBUG_Init_Cmd_Packet_t *pCmdPacket ) { /** @@ -527,24 +509,6 @@ SHCI_CmdStatus_t SHCI_C2_RADIO_AllowLowPower( SHCI_C2_FLASH_Ip_t Ip,uint8_t Fla return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); } -SHCI_CmdStatus_t SHCI_C2_MAC_802_15_4_Init( void ) -{ - /** - * Buffer is large enough to hold command complete without payload - */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; - TL_EvtPacket_t * p_rsp; - - p_rsp = (TL_EvtPacket_t *)local_buffer; - - shci_send( SHCI_OPCODE_C2_MAC_802_15_4_INIT, - 0, - 0, - p_rsp ); - - return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); -} - SHCI_CmdStatus_t SHCI_C2_Reinit( void ) { /** @@ -739,3 +703,5 @@ SHCI_CmdStatus_t SHCI_GetWirelessFwInfo( WirelessFwInfo_t* pWirelessInfo ) return (SHCI_Success); } +#endif /* STM32WBxx */ + diff --git a/src/utility/STM32Cube_FW/shci.h b/src/utility/STM32Cube_FW/shci.h index c08f056f..9449c224 100644 --- a/src/utility/STM32Cube_FW/shci.h +++ b/src/utility/STM32Cube_FW/shci.h @@ -49,7 +49,6 @@ extern "C" { ERR_BLE_INIT = 0, /* This event is currently not reported by the CPU2 */ ERR_THREAD_LLD_FATAL_ERROR = 125, /* The LLD driver used on 802_15_4 detected a fatal error */ ERR_THREAD_UNKNOWN_CMD = 126, /* The command send by the CPU1 to control the Thread stack is unknown */ - ERR_ZIGBEE_UNKNOWN_CMD = 200, /* The command send by the CPU1 to control the Zigbee stack is unknown */ } SCHI_SystemErrCode_t; #define SHCI_EVTCODE ( 0xFF ) @@ -102,7 +101,7 @@ extern "C" { /** * SHCI_SUB_EVT_THREAD_NVM_RAM_UPDATE - * This notifies the CPU1 which part of the OT NVM RAM has been updated so that only the modified + * This notifies the CPU1 which part of the 'OT NVM RAM' has been updated so that only the modified * section could be written in Flash/NVM * StartAddress : Start address of the section that has been modified * Size : Size (in bytes) of the section that has been modified @@ -214,9 +213,7 @@ extern "C" { SHCI_OCF_C2_FLASH_STORE_DATA, SHCI_OCF_C2_FLASH_ERASE_DATA, SHCI_OCF_C2_RADIO_ALLOW_LOW_POWER, - SHCI_OCF_C2_MAC_802_15_4_INIT, SHCI_OCF_C2_REINIT, - SHCI_OCF_C2_ZIGBEE_INIT, SHCI_OCF_C2_LLD_TESTS_INIT, SHCI_OCF_C2_EXTPA_CONFIG, SHCI_OCF_C2_SET_FLASH_ACTIVITY_CONTROL, @@ -614,8 +611,6 @@ extern "C" { { uint8_t thread_config; uint8_t ble_config; - uint8_t mac_802_15_4_config; - uint8_t zigbee_config; } SHCI_C2_DEBUG_TracesConfig_t; typedef PACKED_STRUCT @@ -674,8 +669,6 @@ extern "C" { { BLE_ENABLE, THREAD_ENABLE, - ZIGBEE_ENABLE, - MAC_ENABLE, } SHCI_C2_CONCURRENT_Mode_Param_t; /** No response parameters*/ @@ -698,18 +691,13 @@ extern "C" { { BLE_IP, THREAD_IP, - ZIGBEE_IP, } SHCI_C2_FLASH_Ip_t; /** No response parameters*/ #define SHCI_OPCODE_C2_RADIO_ALLOW_LOW_POWER (( SHCI_OGF << 10) + SHCI_OCF_C2_RADIO_ALLOW_LOW_POWER) -#define SHCI_OPCODE_C2_MAC_802_15_4_INIT (( SHCI_OGF << 10) + SHCI_OCF_C2_MAC_802_15_4_INIT) - #define SHCI_OPCODE_C2_REINIT (( SHCI_OGF << 10) + SHCI_OCF_C2_REINIT) -#define SHCI_OPCODE_C2_ZIGBEE_INIT (( SHCI_OGF << 10) + SHCI_OCF_C2_ZIGBEE_INIT) - #define SHCI_OPCODE_C2_LLD_TESTS_INIT (( SHCI_OGF << 10) + SHCI_OCF_C2_LLD_TESTS_INIT) #define SHCI_OPCODE_C2_BLE_LLD_INIT (( SHCI_OGF << 10) + SHCI_OCF_C2_BLE_LLD_INIT) @@ -817,7 +805,7 @@ extern "C" { #define FUS_DEVICE_INFO_TABLE_VALIDITY_KEYWORD (0xA94656B9) /* - * At startup, the informations relative to the wireless binary are stored in RAM trough a structure defined by + * At startup, the information relative to the wireless binary are stored in RAM through a structure defined by * MB_WirelessFwInfoTable_t.This structure contains 4 fields (Version,MemorySize, Stack_info and a reserved part) * each of those coded on 32 bits as shown on the table below: * @@ -870,9 +858,6 @@ extern "C" { #define INFO_STACK_TYPE_BLE_BEACON 0x04 #define INFO_STACK_TYPE_THREAD_FTD 0x10 #define INFO_STACK_TYPE_THREAD_MTD 0x11 -#define INFO_STACK_TYPE_ZIGBEE_FFD 0x30 -#define INFO_STACK_TYPE_ZIGBEE_RFD 0x31 -#define INFO_STACK_TYPE_MAC 0x40 #define INFO_STACK_TYPE_BLE_THREAD_FTD_STATIC 0x50 #define INFO_STACK_TYPE_BLE_THREAD_FTD_DYAMIC 0x51 #define INFO_STACK_TYPE_802154_LLD_TESTS 0x60 @@ -881,12 +866,7 @@ extern "C" { #define INFO_STACK_TYPE_BLE_LLD_TESTS 0x63 #define INFO_STACK_TYPE_BLE_RLV 0x64 #define INFO_STACK_TYPE_802154_RLV 0x65 -#define INFO_STACK_TYPE_BLE_ZIGBEE_FFD_STATIC 0x70 -#define INFO_STACK_TYPE_BLE_ZIGBEE_RFD_STATIC 0x71 -#define INFO_STACK_TYPE_BLE_ZIGBEE_FFD_DYNAMIC 0x78 -#define INFO_STACK_TYPE_BLE_ZIGBEE_RFD_DYNAMIC 0x79 #define INFO_STACK_TYPE_RLV 0x80 -#define INFO_STACK_TYPE_BLE_MAC_STATIC 0x90 typedef struct { /** @@ -1060,7 +1040,7 @@ typedef struct { * @brief Starts the LLD tests CLI * * @param param_size : Nb of bytes - * @param p_param : pointeur with data to give from M4 to M0 + * @param p_param : pointer with data to give from M4 to M0 * @retval Status */ SHCI_CmdStatus_t SHCI_C2_LLDTESTS_Init( uint8_t param_size, uint8_t * p_param ); @@ -1070,19 +1050,10 @@ typedef struct { * @brief Starts the LLD tests BLE * * @param param_size : Nb of bytes - * @param p_param : pointeur with data to give from M4 to M0 + * @param p_param : pointer with data to give from M4 to M0 * @retval Status */ SHCI_CmdStatus_t SHCI_C2_BLE_LLD_Init( uint8_t param_size, uint8_t * p_param ); - - /** - * SHCI_C2_ZIGBEE_Init - * @brief Starts the Zigbee Stack - * - * @param None - * @retval Status - */ - SHCI_CmdStatus_t SHCI_C2_ZIGBEE_Init( void ); /** * SHCI_C2_DEBUG_Init @@ -1158,16 +1129,6 @@ typedef struct { */ SHCI_CmdStatus_t SHCI_C2_RADIO_AllowLowPower( SHCI_C2_FLASH_Ip_t Ip,uint8_t FlagRadioLowPowerOn); - - /** - * SHCI_C2_MAC_802_15_4_Init - * @brief Starts the MAC 802.15.4 on M0 - * - * @param None - * @retval Status - */ - SHCI_CmdStatus_t SHCI_C2_MAC_802_15_4_Init( void ); - /** * SHCI_GetWirelessFwInfo * @brief This function read back the informations relative to the wireless binary loaded. diff --git a/src/utility/STM32Cube_FW/shci_tl.c b/src/utility/STM32Cube_FW/shci_tl.c index 449b8b16..ef403aab 100644 --- a/src/utility/STM32Cube_FW/shci_tl.c +++ b/src/utility/STM32Cube_FW/shci_tl.c @@ -16,12 +16,13 @@ ****************************************************************************** */ - +#if defined(STM32WBxx) /* Includes ------------------------------------------------------------------*/ #include "stm32_wpan_common.h" #include "stm_list.h" #include "shci_tl.h" +#include "stm32_def.h" /* Private typedef -----------------------------------------------------------*/ typedef enum @@ -168,6 +169,20 @@ void shci_send( uint16_t cmd_code, uint8_t len_cmd_payload, uint8_t * p_cmd_payl return; } +void shci_notify_asynch_evt(void *pdata) +{ + UNUSED(pdata); + /* Need to parse data in future version */ + shci_user_evt_proc(); +} + +void shci_register_io_bus(tSHciIO *fops) +{ + /* Register IO bus services */ + fops->Init = TL_SYS_Init; + fops->Send = TL_SYS_SendCmd; +} + /* Private functions ---------------------------------------------------------*/ static void TlInit( TL_CmdPacket_t * p_cmdbuffer ) { @@ -252,3 +267,5 @@ __WEAK void shci_cmd_resp_release(uint32_t flag) return; } +#endif /* STM32WBxx */ + diff --git a/src/utility/STM32Cube_FW/stm32_wpan_common.h b/src/utility/STM32Cube_FW/stm32_wpan_common.h index b47b804a..5a2b2a55 100644 --- a/src/utility/STM32Cube_FW/stm32_wpan_common.h +++ b/src/utility/STM32Cube_FW/stm32_wpan_common.h @@ -25,19 +25,9 @@ extern "C" { #endif -#if defined ( __CC_ARM ) - #define __ASM __asm /*!< asm keyword for ARM Compiler */ - #define __INLINE __inline /*!< inline keyword for ARM Compiler */ - #define __STATIC_INLINE static __inline -#elif defined ( __ICCARM__ ) - #define __ASM __asm /*!< asm keyword for IAR Compiler */ - #define __INLINE inline /*!< inline keyword for IAR Compiler. Only available in High optimization mode! */ - #define __STATIC_INLINE static inline -#elif defined ( __GNUC__ ) - #define __ASM __asm /*!< asm keyword for GNU Compiler */ - #define __INLINE inline /*!< inline keyword for GNU Compiler */ - #define __STATIC_INLINE static inline -#endif +#define __ASM __asm /*!< asm keyword for GNU Compiler */ +#define __INLINE inline /*!< inline keyword for GNU Compiler */ +#define __STATIC_INLINE static inline #include <stdint.h> #include <string.h> @@ -140,29 +130,8 @@ extern "C" { /* ----------------------------------- * * Packed usage (compiler dependent) * * ----------------------------------- */ -#undef PACKED__ #undef PACKED_STRUCT - -#if defined ( __CC_ARM ) - #if defined ( __GNUC__ ) - /* GNU extension */ - #define PACKED__ __attribute__((packed)) - #define PACKED_STRUCT struct PACKED__ - #elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050U) - #define PACKED__ __attribute__((packed)) - #define PACKED_STRUCT struct PACKED__ - #else - #define PACKED__(TYPE) __packed TYPE - #define PACKED_STRUCT PACKED__(struct) - #endif -#elif defined ( __GNUC__ ) - #define PACKED__ __attribute__((packed)) - #define PACKED_STRUCT struct PACKED__ -#elif defined (__ICCARM__) - #define PACKED_STRUCT __packed struct -#else - #define PACKED_STRUCT __packed struct -#endif +#define PACKED_STRUCT struct __packed #ifdef __cplusplus } diff --git a/src/utility/STM32Cube_FW/stm_list.c b/src/utility/STM32Cube_FW/stm_list.c index 69c8c064..3dea7512 100644 --- a/src/utility/STM32Cube_FW/stm_list.c +++ b/src/utility/STM32Cube_FW/stm_list.c @@ -16,13 +16,13 @@ ****************************************************************************** */ - +#if defined(STM32WBxx) /****************************************************************************** * Include Files ******************************************************************************/ -#include "utilities_common.h" - #include "stm_list.h" +#include "cmsis_gcc.h" +#include "stm32_wpan_common.h" /****************************************************************************** * Function Definitions @@ -33,10 +33,10 @@ void LST_init_head (tListNode * listHead) listHead->prev = listHead; } -uint8_t LST_is_empty (tListNode * listHead) +bool LST_is_empty (tListNode * listHead) { uint32_t primask_bit; - uint8_t return_value; + bool return_value; primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ @@ -205,3 +205,4 @@ void LST_get_prev_node (tListNode * ref_node, tListNode ** node) __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ } +#endif /* STM32WBxx */ \ No newline at end of file diff --git a/src/utility/STM32Cube_FW/stm_list.h b/src/utility/STM32Cube_FW/stm_list.h index b7c3254c..769c2113 100644 --- a/src/utility/STM32Cube_FW/stm_list.h +++ b/src/utility/STM32Cube_FW/stm_list.h @@ -21,6 +21,8 @@ #define _STM_LIST_H_ /* Includes ------------------------------------------------------------------*/ +#include "stdint.h" +#include "stdbool.h" #include "stm32_wpan_common.h" typedef PACKED_STRUCT _tListNode { @@ -30,7 +32,7 @@ typedef PACKED_STRUCT _tListNode { void LST_init_head (tListNode * listHead); -uint8_t LST_is_empty (tListNode * listHead); +bool LST_is_empty (tListNode * listHead); void LST_insert_head (tListNode * listHead, tListNode * node); diff --git a/src/utility/STM32Cube_FW/tl.h b/src/utility/STM32Cube_FW/tl.h index cb27246b..16de7f16 100644 --- a/src/utility/STM32Cube_FW/tl.h +++ b/src/utility/STM32Cube_FW/tl.h @@ -198,19 +198,6 @@ typedef struct uint8_t *p_BleLldM0CmdBuffer; } TL_BLE_LLD_Config_t; -typedef struct -{ - uint8_t *p_Mac_802_15_4_CmdRspBuffer; - uint8_t *p_Mac_802_15_4_NotAckBuffer; -} TL_MAC_802_15_4_Config_t; - -typedef struct -{ - uint8_t *p_ZigbeeOtCmdRspBuffer; - uint8_t *p_ZigbeeNotAckBuffer; - uint8_t *p_ZigbeeNotifRequestBuffer; -} TL_ZIGBEE_Config_t; - /** * @brief Contain the BLE HCI Init Configuration * @{ @@ -304,26 +291,6 @@ void TL_MM_EvtDone( TL_EvtPacket_t * hcievt ); void TL_TRACES_Init( void ); void TL_TRACES_EvtReceived( TL_EvtPacket_t * hcievt ); -/****************************************************************************** - * MAC 802.15.4 - ******************************************************************************/ -void TL_MAC_802_15_4_Init( TL_MAC_802_15_4_Config_t *p_Config ); -void TL_MAC_802_15_4_SendCmd( void ); -void TL_MAC_802_15_4_CmdEvtReceived( TL_EvtPacket_t * Otbuffer ); -void TL_MAC_802_15_4_NotReceived( TL_EvtPacket_t * Notbuffer ); -void TL_MAC_802_15_4_SendAck ( void ); - -/****************************************************************************** - * ZIGBEE - ******************************************************************************/ -void TL_ZIGBEE_Init( TL_ZIGBEE_Config_t *p_Config ); -void TL_ZIGBEE_SendM4RequestToM0( void ); -void TL_ZIGBEE_SendM4AckToM0Notify ( void ); -void TL_ZIGBEE_NotReceived( TL_EvtPacket_t * Notbuffer ); -void TL_ZIGBEE_CmdEvtReceived( TL_EvtPacket_t * Otbuffer ); -void TL_ZIGBEE_M0RequestReceived(TL_EvtPacket_t * Otbuffer ); -void TL_ZIGBEE_SendM4AckToM0Request(void); - #ifdef __cplusplus } /* extern "C" */ #endif diff --git a/src/utility/STM32Cube_FW/tl_mbox.c b/src/utility/STM32Cube_FW/tl_mbox.c index 148bcb19..709f5d24 100644 --- a/src/utility/STM32Cube_FW/tl_mbox.c +++ b/src/utility/STM32Cube_FW/tl_mbox.c @@ -16,6 +16,7 @@ ****************************************************************************** */ +#if defined(STM32WBxx) /* Includes ------------------------------------------------------------------*/ #include "stm32_wpan_common.h" #include "hw.h" @@ -51,15 +52,13 @@ PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_BleLldTable_t TL_BleLldTable; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_SysTable_t TL_SysTable; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_MemManagerTable_t TL_MemManagerTable; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_TracesTable_t TL_TracesTable; -PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_Mac_802_15_4_t TL_Mac_802_15_4_Table; -PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_ZigbeeTable_t TL_Zigbee_Table; /**< tables */ PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode FreeBufQueue; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode TracesEvtQueue; PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static uint8_t CsBuffer[sizeof(TL_PacketHeader_t) + TL_EVT_HDR_SIZE + sizeof(TL_CsEvt_t)]; -PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode EvtQueue; -PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode SystemEvtQueue; +PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static tListNode EvtQueue; +PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static tListNode SystemEvtQueue; static tListNode LocalFreeBufQueue; @@ -97,8 +96,6 @@ void TL_Init( void ) TL_RefTable.p_sys_table = &TL_SysTable; TL_RefTable.p_mem_manager_table = &TL_MemManagerTable; TL_RefTable.p_traces_table = &TL_TracesTable; - TL_RefTable.p_mac_802_15_4_table = &TL_Mac_802_15_4_Table; - TL_RefTable.p_zigbee_table = &TL_Zigbee_Table; HW_IPCC_Init(); return; @@ -451,139 +448,6 @@ void TL_BLE_LLD_SendRspAck( void ) } #endif /* BLE_LLD_WB */ -#ifdef MAC_802_15_4_WB -/****************************************************************************** - * MAC 802.15.4 - ******************************************************************************/ -void TL_MAC_802_15_4_Init( TL_MAC_802_15_4_Config_t *p_Config ) -{ - MB_Mac_802_15_4_t * p_mac_802_15_4_table; - - p_mac_802_15_4_table = TL_RefTable.p_mac_802_15_4_table; - - p_mac_802_15_4_table->p_cmdrsp_buffer = p_Config->p_Mac_802_15_4_CmdRspBuffer; - p_mac_802_15_4_table->p_notack_buffer = p_Config->p_Mac_802_15_4_NotAckBuffer; - - HW_IPCC_MAC_802_15_4_Init(); - - return; -} - -void TL_MAC_802_15_4_SendCmd( void ) -{ - ((TL_CmdPacket_t *)(TL_RefTable.p_mac_802_15_4_table->p_cmdrsp_buffer))->cmdserial.type = TL_OTCMD_PKT_TYPE; - - HW_IPCC_MAC_802_15_4_SendCmd(); - - return; -} - -void TL_MAC_802_15_4_SendAck ( void ) -{ - ((TL_CmdPacket_t *)(TL_RefTable.p_mac_802_15_4_table->p_notack_buffer))->cmdserial.type = TL_OTACK_PKT_TYPE; - - HW_IPCC_MAC_802_15_4_SendAck(); - - return; -} - -void HW_IPCC_MAC_802_15_4_CmdEvtNot(void) -{ - TL_MAC_802_15_4_CmdEvtReceived( (TL_EvtPacket_t*)(TL_RefTable.p_mac_802_15_4_table->p_cmdrsp_buffer) ); - - return; -} - -void HW_IPCC_MAC_802_15_4_EvtNot( void ) -{ - TL_MAC_802_15_4_NotReceived( (TL_EvtPacket_t*)(TL_RefTable.p_mac_802_15_4_table->p_notack_buffer) ); - - return; -} - -__WEAK void TL_MAC_802_15_4_CmdEvtReceived( TL_EvtPacket_t * Otbuffer ){}; -__WEAK void TL_MAC_802_15_4_NotReceived( TL_EvtPacket_t * Notbuffer ){}; -#endif - -#ifdef ZIGBEE_WB -/****************************************************************************** - * ZIGBEE - ******************************************************************************/ -void TL_ZIGBEE_Init( TL_ZIGBEE_Config_t *p_Config ) -{ - MB_ZigbeeTable_t * p_zigbee_table; - - p_zigbee_table = TL_RefTable.p_zigbee_table; - p_zigbee_table->appliCmdM4toM0_buffer = p_Config->p_ZigbeeOtCmdRspBuffer; - p_zigbee_table->notifM0toM4_buffer = p_Config->p_ZigbeeNotAckBuffer; - p_zigbee_table->requestM0toM4_buffer = p_Config->p_ZigbeeNotifRequestBuffer; - - HW_IPCC_ZIGBEE_Init(); - - return; -} - -/* Zigbee M4 to M0 Request */ -void TL_ZIGBEE_SendM4RequestToM0( void ) -{ - ((TL_CmdPacket_t *)(TL_RefTable.p_zigbee_table->appliCmdM4toM0_buffer))->cmdserial.type = TL_OTCMD_PKT_TYPE; - - HW_IPCC_ZIGBEE_SendM4RequestToM0(); - - return; -} - -/* Used to receive an ACK from the M0 */ -void HW_IPCC_ZIGBEE_RecvAppliAckFromM0(void) -{ - TL_ZIGBEE_CmdEvtReceived( (TL_EvtPacket_t*)(TL_RefTable.p_zigbee_table->appliCmdM4toM0_buffer) ); - - return; -} - -/* Zigbee notification from M0 to M4 */ -void HW_IPCC_ZIGBEE_RecvM0NotifyToM4( void ) -{ - TL_ZIGBEE_NotReceived( (TL_EvtPacket_t*)(TL_RefTable.p_zigbee_table->notifM0toM4_buffer) ); - - return; -} - -/* Send an ACK to the M0 for a Notification */ -void TL_ZIGBEE_SendM4AckToM0Notify ( void ) -{ - ((TL_CmdPacket_t *)(TL_RefTable.p_zigbee_table->notifM0toM4_buffer))->cmdserial.type = TL_OTACK_PKT_TYPE; - - HW_IPCC_ZIGBEE_SendM4AckToM0Notify(); - - return; -} - -/* Zigbee M0 to M4 Request */ -void HW_IPCC_ZIGBEE_RecvM0RequestToM4( void ) -{ - TL_ZIGBEE_M0RequestReceived( (TL_EvtPacket_t*)(TL_RefTable.p_zigbee_table->requestM0toM4_buffer) ); - - return; -} - -/* Send an ACK to the M0 for a Request */ -void TL_ZIGBEE_SendM4AckToM0Request(void) -{ - ((TL_CmdPacket_t *)(TL_RefTable.p_zigbee_table->requestM0toM4_buffer))->cmdserial.type = TL_OTACK_PKT_TYPE; - - HW_IPCC_ZIGBEE_SendM4AckToM0Request(); - - return; -} - - -__WEAK void TL_ZIGBEE_CmdEvtReceived( TL_EvtPacket_t * Otbuffer ){}; -__WEAK void TL_ZIGBEE_NotReceived( TL_EvtPacket_t * Notbuffer ){}; -#endif - - - /****************************************************************************** * MEMORY MANAGER ******************************************************************************/ @@ -845,3 +709,5 @@ static void OutputDbgTrace(TL_MB_PacketType_t packet_type, uint8_t* buffer) return; } + +#endif /* STM32WBxx */ From 0d821e8bef7b962d09f54088426fe99250953ee4 Mon Sep 17 00:00:00 2001 From: Alexandre Bourdiol <alexandre.bourdiol@st.com> Date: Mon, 6 Dec 2021 11:18:02 +0100 Subject: [PATCH 082/226] fix: include a timeout when waiting for the cmd_resp Signed-off-by: Francois Ramu <francois.ramu@st.com> Signed-off-by: Alexandre Bourdiol <alexandre.bourdiol@st.com> --- src/utility/STM32Cube_FW/shci_tl.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/utility/STM32Cube_FW/shci_tl.c b/src/utility/STM32Cube_FW/shci_tl.c index ef403aab..6cccc5dd 100644 --- a/src/utility/STM32Cube_FW/shci_tl.c +++ b/src/utility/STM32Cube_FW/shci_tl.c @@ -20,6 +20,8 @@ /* Includes ------------------------------------------------------------------*/ #include "stm32_wpan_common.h" +#include <Arduino.h> + #include "stm_list.h" #include "shci_tl.h" #include "stm32_def.h" @@ -250,11 +252,12 @@ static void TlUserEvtReceived(TL_EvtPacket_t *shcievt) /* Weak implementation ----------------------------------------------------------------*/ __WEAK void shci_cmd_resp_wait(uint32_t timeout) { - (void)timeout; - CmdRspStatusFlag = SHCI_TL_CMD_RESP_WAIT; - while(CmdRspStatusFlag != SHCI_TL_CMD_RESP_RELEASE); - + for (unsigned long start = millis(); (millis() - start) < timeout;) { + if (CmdRspStatusFlag == SHCI_TL_CMD_RESP_RELEASE) { + break; + } + } return; } From 55aa462a677c26d8a4f6f86b2efacdb6b82e77b4 Mon Sep 17 00:00:00 2001 From: Alexandre Bourdiol <alexandre.bourdiol@st.com> Date: Mon, 6 Dec 2021 18:59:38 +0100 Subject: [PATCH 083/226] Added support for custom app_conf.h (#35) --- src/utility/STM32Cube_FW/app_conf_default.h | 75 ++++++++++++++------- 1 file changed, 49 insertions(+), 26 deletions(-) diff --git a/src/utility/STM32Cube_FW/app_conf_default.h b/src/utility/STM32Cube_FW/app_conf_default.h index 4f300e0a..9f8e085d 100644 --- a/src/utility/STM32Cube_FW/app_conf_default.h +++ b/src/utility/STM32Cube_FW/app_conf_default.h @@ -1,8 +1,8 @@ /** ****************************************************************************** - * @file app_conf.h + * @file app_conf_default.h * @author MCD Application Team - * @brief Application configuration file for STM32WPAN Middleware. + * @brief Default application configuration file for STM32WPAN Middleware. ****************************************************************************** * @attention * @@ -17,11 +17,8 @@ */ /* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef APP_CONF_H -#define APP_CONF_H - -#include "hw.h" -#include "ble_bufsize.h" +#ifndef APP_CONF_DEFAULT_H +#define APP_CONF_DEFAULT_H /****************************************************************************** * Application Config @@ -44,7 +41,9 @@ /** * Define Tx Power */ -#define CFG_TX_POWER (0x18) /* -0.15dBm */ +#ifndef CFG_TX_POWER + #define CFG_TX_POWER (0x18) /* -0.15dBm */ +#endif /****************************************************************************** * BLE Stack @@ -53,32 +52,41 @@ * Maximum number of simultaneous connections that the device will support. * Valid values are from 1 to 8 */ -#define CFG_BLE_NUM_LINK 2 +#ifndef CFG_BLE_NUM_LINK + #define CFG_BLE_NUM_LINK 2 +#endif /** * Maximum number of Services that can be stored in the GATT database. - * Note that the GAP and GATT services are automatically added so this parameter should be 2 plus the number of user services + * Note that the GAP and GATT services are automatically added so this parameter should be 2 plus the number of user + * services */ +#ifndef CFG_BLE_NUM_GATT_SERVICES #define CFG_BLE_NUM_GATT_SERVICES 8 +#endif /** * Maximum number of Attributes - * (i.e. the number of characteristic + the number of characteristic values + the number of descriptors, excluding the services) - * that can be stored in the GATT database. - * Note that certain characteristics and relative descriptors are added automatically during device initialization - * so this parameters should be 9 plus the number of user Attributes + * (i.e. the number of characteristic + the number of characteristic values + the number of descriptors, excluding the + * services) that can be stored in the GATT database. Note that certain characteristics and relative descriptors are + * added automatically during device initialization so this parameters should be 9 plus the number of user Attributes */ -#define CFG_BLE_NUM_GATT_ATTRIBUTES 68 +#ifndef CFG_BLE_NUM_GATT_ATTRIBUTES + #define CFG_BLE_NUM_GATT_ATTRIBUTES 68 +#endif /** * Maximum supported ATT_MTU size * This parameter is ignored by the CPU2 when CFG_BLE_OPTIONS is set to 1" */ -#define CFG_BLE_MAX_ATT_MTU (156) +#ifndef CFG_BLE_MAX_ATT_MTU + #define CFG_BLE_MAX_ATT_MTU (156) +#endif /** * Size of the storage area for Attribute values - * This value depends on the number of attributes used by application. In particular the sum of the following quantities (in octets) should be made for each attribute: + * This value depends on the number of attributes used by application. In particular the sum of the following + * quantities (in octets) should be made for each attribute: * - attribute value length * - 5, if UUID is 16 bit; 19, if UUID is 128 bit * - 2, if server configuration descriptor is used @@ -87,14 +95,18 @@ * The total amount of memory needed is the sum of the above quantities for each attribute. * This parameter is ignored by the CPU2 when CFG_BLE_OPTIONS is set to 1" */ +#ifndef CFG_BLE_ATT_VALUE_ARRAY_SIZE #define CFG_BLE_ATT_VALUE_ARRAY_SIZE (1344) +#endif /** * Prepare Write List size in terms of number of packet * This parameter is ignored by the CPU2 when CFG_BLE_OPTIONS is set to 1" */ // #define CFG_BLE_PREPARE_WRITE_LIST_SIZE BLE_PREP_WRITE_X_ATT(CFG_BLE_MAX_ATT_MTU) -#define CFG_BLE_PREPARE_WRITE_LIST_SIZE (0x3A) +#ifndef CFG_BLE_PREPARE_WRITE_LIST_SIZE + #define CFG_BLE_PREPARE_WRITE_LIST_SIZE (0x3A) +#endif /** * Number of allocated memory blocks @@ -106,12 +118,16 @@ /** * Enable or disable the Extended Packet length feature. Valid values are 0 or 1. */ -#define CFG_BLE_DATA_LENGTH_EXTENSION 1 +#ifndef CFG_BLE_DATA_LENGTH_EXTENSION + #define CFG_BLE_DATA_LENGTH_EXTENSION 1 +#endif /** * Sleep clock accuracy in Slave mode (ppm value) */ -#define CFG_BLE_SLAVE_SCA 500 +#ifndef CFG_BLE_SLAVE_SCA + #define CFG_BLE_SLAVE_SCA 500 +#endif /** * Sleep clock accuracy in Master mode @@ -124,24 +140,32 @@ * 6 : 21 ppm to 30 ppm * 7 : 0 ppm to 20 ppm */ -#define CFG_BLE_MASTER_SCA 0 +#ifndef CFG_BLE_MASTER_SCA + #define CFG_BLE_MASTER_SCA 0 +#endif /** * Source for the low speed clock for RF wake-up * 1 : external high speed crystal HSE/32/32 * 0 : external low speed crystal ( no calibration ) */ -#define CFG_BLE_LSE_SOURCE 0 +#ifndef CFG_BLE_LSE_SOURCE + #define CFG_BLE_LSE_SOURCE 0 +#endif /** * Start up time of the high speed (16 or 32 MHz) crystal oscillator in units of 625/256 us (~2.44 us) */ -#define CFG_BLE_HSE_STARTUP_TIME 0x148 +#ifndef CFG_BLE_HSE_STARTUP_TIME + #define CFG_BLE_HSE_STARTUP_TIME 0x148 +#endif /** * Maximum duration of the connection event when the device is in Slave mode in units of 625/256 us (~2.44 us) */ -#define CFG_BLE_MAX_CONN_EVENT_LENGTH (0xFFFFFFFF) +#ifndef CFG_BLE_MAX_CONN_EVENT_LENGTH + #define CFG_BLE_MAX_CONN_EVENT_LENGTH (0xFFFFFFFF) +#endif /** * Viterbi Mode @@ -199,5 +223,4 @@ #define CFG_BLE_RX_MODEL_CONFIG SHCI_C2_BLE_INIT_RX_MODEL_AGC_RSSI_LEGACY - -#endif /*APP_CONF_H */ +#endif /* APP_CONF_DEFAULT_H */ From abeaf9a760ec5937bb3a66e45dc3125d63fc2373 Mon Sep 17 00:00:00 2001 From: Alexandre Bourdiol <alexandre.bourdiol@st.com> Date: Tue, 7 Dec 2021 14:27:27 +0100 Subject: [PATCH 084/226] Stub OutputDbgTrace() function Signed-off-by: Alexandre Bourdiol <alexandre.bourdiol@st.com> --- src/utility/STM32Cube_FW/tl_mbox.c | 178 +---------------------------- 1 file changed, 3 insertions(+), 175 deletions(-) diff --git a/src/utility/STM32Cube_FW/tl_mbox.c b/src/utility/STM32Cube_FW/tl_mbox.c index 709f5d24..db192c4f 100644 --- a/src/utility/STM32Cube_FW/tl_mbox.c +++ b/src/utility/STM32Cube_FW/tl_mbox.c @@ -24,7 +24,6 @@ #include "stm_list.h" #include "tl.h" #include "mbox_def.h" -#include "tl_dbg_conf.h" /* Private typedef -----------------------------------------------------------*/ typedef enum @@ -532,180 +531,9 @@ __WEAK void TL_TRACES_EvtReceived( TL_EvtPacket_t * hcievt ) ******************************************************************************/ static void OutputDbgTrace(TL_MB_PacketType_t packet_type, uint8_t* buffer) { - TL_EvtPacket_t *p_evt_packet; - TL_CmdPacket_t *p_cmd_packet; - - switch(packet_type) - { - case TL_MB_MM_RELEASE_BUFFER: - p_evt_packet = (TL_EvtPacket_t*)buffer; - switch(p_evt_packet->evtserial.evt.evtcode) - { - case TL_BLEEVT_CS_OPCODE: - TL_MM_DBG_MSG("mm evt released: 0x%02X", p_evt_packet->evtserial.evt.evtcode); - TL_MM_DBG_MSG(" cmd opcode: 0x%04X", ((TL_CsEvt_t*)(p_evt_packet->evtserial.evt.payload))->cmdcode); - TL_MM_DBG_MSG(" buffer addr: 0x%08X", p_evt_packet); - break; - - case TL_BLEEVT_CC_OPCODE: - TL_MM_DBG_MSG("mm evt released: 0x%02X", p_evt_packet->evtserial.evt.evtcode); - TL_MM_DBG_MSG(" cmd opcode: 0x%04X", ((TL_CcEvt_t*)(p_evt_packet->evtserial.evt.payload))->cmdcode); - TL_MM_DBG_MSG(" buffer addr: 0x%08X", p_evt_packet); - break; - - case TL_BLEEVT_VS_OPCODE: - TL_MM_DBG_MSG("mm evt released: 0x%02X", p_evt_packet->evtserial.evt.evtcode); - TL_MM_DBG_MSG(" subevtcode: 0x%04X", ((TL_AsynchEvt_t*)(p_evt_packet->evtserial.evt.payload))->subevtcode); - TL_MM_DBG_MSG(" buffer addr: 0x%08X", p_evt_packet); - break; - - default: - TL_MM_DBG_MSG("mm evt released: 0x%02X", p_evt_packet->evtserial.evt.evtcode); - TL_MM_DBG_MSG(" buffer addr: 0x%08X", p_evt_packet); - break; - } - - TL_MM_DBG_MSG("\r\n"); - break; - - case TL_MB_BLE_CMD: - p_cmd_packet = (TL_CmdPacket_t*)buffer; - TL_HCI_CMD_DBG_MSG("ble cmd: 0x%04X", p_cmd_packet->cmdserial.cmd.cmdcode); - if(p_cmd_packet->cmdserial.cmd.plen != 0) - { - TL_HCI_CMD_DBG_MSG(" payload:"); - TL_HCI_CMD_DBG_BUF(p_cmd_packet->cmdserial.cmd.payload, p_cmd_packet->cmdserial.cmd.plen, ""); - } - TL_HCI_CMD_DBG_MSG("\r\n"); - - TL_HCI_CMD_DBG_RAW(&p_cmd_packet->cmdserial, p_cmd_packet->cmdserial.cmd.plen+TL_CMD_HDR_SIZE); - break; - - case TL_MB_BLE_CMD_RSP: - p_evt_packet = (TL_EvtPacket_t*)buffer; - switch(p_evt_packet->evtserial.evt.evtcode) - { - case TL_BLEEVT_CS_OPCODE: - TL_HCI_CMD_DBG_MSG("ble rsp: 0x%02X", p_evt_packet->evtserial.evt.evtcode); - TL_HCI_CMD_DBG_MSG(" cmd opcode: 0x%04X", ((TL_CsEvt_t*)(p_evt_packet->evtserial.evt.payload))->cmdcode); - TL_HCI_CMD_DBG_MSG(" numhci: 0x%02X", ((TL_CsEvt_t*)(p_evt_packet->evtserial.evt.payload))->numcmd); - TL_HCI_CMD_DBG_MSG(" status: 0x%02X", ((TL_CsEvt_t*)(p_evt_packet->evtserial.evt.payload))->status); - break; - - case TL_BLEEVT_CC_OPCODE: - TL_HCI_CMD_DBG_MSG("ble rsp: 0x%02X", p_evt_packet->evtserial.evt.evtcode); - TL_HCI_CMD_DBG_MSG(" cmd opcode: 0x%04X", ((TL_CcEvt_t*)(p_evt_packet->evtserial.evt.payload))->cmdcode); - TL_HCI_CMD_DBG_MSG(" numhci: 0x%02X", ((TL_CcEvt_t*)(p_evt_packet->evtserial.evt.payload))->numcmd); - TL_HCI_CMD_DBG_MSG(" status: 0x%02X", ((TL_CcEvt_t*)(p_evt_packet->evtserial.evt.payload))->payload[0]); - if((p_evt_packet->evtserial.evt.plen-4) != 0) - { - TL_HCI_CMD_DBG_MSG(" payload:"); - TL_HCI_CMD_DBG_BUF(&((TL_CcEvt_t*)(p_evt_packet->evtserial.evt.payload))->payload[1], p_evt_packet->evtserial.evt.plen-4, ""); - } - break; - - default: - TL_HCI_CMD_DBG_MSG("unknown ble rsp received: %02X", p_evt_packet->evtserial.evt.evtcode); - break; - } - - TL_HCI_CMD_DBG_MSG("\r\n"); - - TL_HCI_CMD_DBG_RAW(&p_evt_packet->evtserial, p_evt_packet->evtserial.evt.plen+TL_EVT_HDR_SIZE); - break; - - case TL_MB_BLE_ASYNCH_EVT: - p_evt_packet = (TL_EvtPacket_t*)buffer; - if(p_evt_packet->evtserial.evt.evtcode != TL_BLEEVT_VS_OPCODE) - { - TL_HCI_EVT_DBG_MSG("ble evt: 0x%02X", p_evt_packet->evtserial.evt.evtcode); - if((p_evt_packet->evtserial.evt.plen) != 0) - { - TL_HCI_EVT_DBG_MSG(" payload:"); - TL_HCI_EVT_DBG_BUF(p_evt_packet->evtserial.evt.payload, p_evt_packet->evtserial.evt.plen, ""); - } - } - else - { - TL_HCI_EVT_DBG_MSG("ble evt: 0x%02X", p_evt_packet->evtserial.evt.evtcode); - TL_HCI_EVT_DBG_MSG(" subevtcode: 0x%04X", ((TL_AsynchEvt_t*)(p_evt_packet->evtserial.evt.payload))->subevtcode); - if((p_evt_packet->evtserial.evt.plen-2) != 0) - { - TL_HCI_EVT_DBG_MSG(" payload:"); - TL_HCI_EVT_DBG_BUF(((TL_AsynchEvt_t*)(p_evt_packet->evtserial.evt.payload))->payload, p_evt_packet->evtserial.evt.plen-2, ""); - } - } - - TL_HCI_EVT_DBG_MSG("\r\n"); - - TL_HCI_EVT_DBG_RAW(&p_evt_packet->evtserial, p_evt_packet->evtserial.evt.plen+TL_EVT_HDR_SIZE); - break; - - case TL_MB_SYS_CMD: - p_cmd_packet = (TL_CmdPacket_t*)buffer; - - TL_SHCI_CMD_DBG_MSG("sys cmd: 0x%04X", p_cmd_packet->cmdserial.cmd.cmdcode); - - if(p_cmd_packet->cmdserial.cmd.plen != 0) - { - TL_SHCI_CMD_DBG_MSG(" payload:"); - TL_SHCI_CMD_DBG_BUF(p_cmd_packet->cmdserial.cmd.payload, p_cmd_packet->cmdserial.cmd.plen, ""); - } - TL_SHCI_CMD_DBG_MSG("\r\n"); - - TL_SHCI_CMD_DBG_RAW(&p_cmd_packet->cmdserial, p_cmd_packet->cmdserial.cmd.plen+TL_CMD_HDR_SIZE); - break; - - case TL_MB_SYS_CMD_RSP: - p_evt_packet = (TL_EvtPacket_t*)buffer; - switch(p_evt_packet->evtserial.evt.evtcode) - { - case TL_BLEEVT_CC_OPCODE: - TL_SHCI_CMD_DBG_MSG("sys rsp: 0x%02X", p_evt_packet->evtserial.evt.evtcode); - TL_SHCI_CMD_DBG_MSG(" cmd opcode: 0x%02X", ((TL_CcEvt_t*)(p_evt_packet->evtserial.evt.payload))->cmdcode); - TL_SHCI_CMD_DBG_MSG(" status: 0x%02X", ((TL_CcEvt_t*)(p_evt_packet->evtserial.evt.payload))->payload[0]); - if((p_evt_packet->evtserial.evt.plen-4) != 0) - { - TL_SHCI_CMD_DBG_MSG(" payload:"); - TL_SHCI_CMD_DBG_BUF(&((TL_CcEvt_t*)(p_evt_packet->evtserial.evt.payload))->payload[1], p_evt_packet->evtserial.evt.plen-4, ""); - } - break; - - default: - TL_SHCI_CMD_DBG_MSG("unknown sys rsp received: %02X", p_evt_packet->evtserial.evt.evtcode); - break; - } - - TL_SHCI_CMD_DBG_MSG("\r\n"); - - TL_SHCI_CMD_DBG_RAW(&p_evt_packet->evtserial, p_evt_packet->evtserial.evt.plen+TL_EVT_HDR_SIZE); - break; - - case TL_MB_SYS_ASYNCH_EVT: - p_evt_packet = (TL_EvtPacket_t*)buffer; - if(p_evt_packet->evtserial.evt.evtcode != TL_BLEEVT_VS_OPCODE) - { - TL_SHCI_EVT_DBG_MSG("unknown sys evt received: %02X", p_evt_packet->evtserial.evt.evtcode); - } - else - { - TL_SHCI_EVT_DBG_MSG("sys evt: 0x%02X", p_evt_packet->evtserial.evt.evtcode); - TL_SHCI_EVT_DBG_MSG(" subevtcode: 0x%04X", ((TL_AsynchEvt_t*)(p_evt_packet->evtserial.evt.payload))->subevtcode); - if((p_evt_packet->evtserial.evt.plen-2) != 0) - { - TL_SHCI_EVT_DBG_MSG(" payload:"); - TL_SHCI_EVT_DBG_BUF(((TL_AsynchEvt_t*)(p_evt_packet->evtserial.evt.payload))->payload, p_evt_packet->evtserial.evt.plen-2, ""); - } - } - - TL_SHCI_EVT_DBG_MSG("\r\n"); - - TL_SHCI_EVT_DBG_RAW(&p_evt_packet->evtserial, p_evt_packet->evtserial.evt.plen+TL_EVT_HDR_SIZE); - break; - - default: - break; - } + /* Function stubbed */ + UNUSED(packet_type); + UNUSED(buffer); return; } From 061ec8e7902ab1754a65264787f704d4bb265766 Mon Sep 17 00:00:00 2001 From: Alexandre Bourdiol <alexandre.bourdiol@st.com> Date: Fri, 8 Apr 2022 15:01:59 +0200 Subject: [PATCH 085/226] Update STM32Cube_FW from Cube version v1.13.3 Signed-off-by: Alexandre Bourdiol <alexandre.bourdiol@st.com> --- src/utility/STM32Cube_FW/README.md | 4 +- src/utility/STM32Cube_FW/ble_bufsize.h | 33 +- src/utility/STM32Cube_FW/shci.h | 9 +- src/utility/STM32Cube_FW/stm_list.c | 416 ++++++++++++------------- 4 files changed, 236 insertions(+), 226 deletions(-) diff --git a/src/utility/STM32Cube_FW/README.md b/src/utility/STM32Cube_FW/README.md index 419d0eb0..dc03bb92 100644 --- a/src/utility/STM32Cube_FW/README.md +++ b/src/utility/STM32Cube_FW/README.md @@ -1,6 +1,6 @@ ## Source -[STMicroelectronics/STM32CubeWB Release v1.13.0](https://github.com/STMicroelectronics/STM32CubeWB/releases/tag/v1.13.0) -- Application: [BLE_TransparentMode](https://github.com/STMicroelectronics/STM32CubeWB/tree/v1.13.0/Projects/P-NUCLEO-WB55.Nucleo/Applications/BLE/BLE_TransparentMode) +[STMicroelectronics/STM32CubeWB Release v1.13.3](https://github.com/STMicroelectronics/STM32CubeWB/releases/tag/v1.13.3) +- Application: [BLE_TransparentMode](https://github.com/STMicroelectronics/STM32CubeWB/tree/v1.13.3/Projects/P-NUCLEO-WB55.Nucleo/Applications/BLE/BLE_TransparentMode) diff --git a/src/utility/STM32Cube_FW/ble_bufsize.h b/src/utility/STM32Cube_FW/ble_bufsize.h index 73b78872..12b5fdb9 100644 --- a/src/utility/STM32Cube_FW/ble_bufsize.h +++ b/src/utility/STM32Cube_FW/ble_bufsize.h @@ -1,11 +1,11 @@ /***************************************************************************** * @file ble_bufsize.h - * @author MCD + * @author MDG * @brief Definition of BLE stack buffers size ***************************************************************************** * @attention * - * Copyright (c) 2018-2021 STMicroelectronics. + * Copyright (c) 2018-2022 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file @@ -97,28 +97,28 @@ * mentioned parameters. */ #if (BEACON_ONLY != 0) -#define BLE_FIXED_BUFFER_SIZE_BYTES 4184 /* Beacon only */ +#define BLE_FIXED_BUFFER_SIZE_BYTES 4076 /* Beacon only */ #elif (LL_ONLY != 0) -#define BLE_FIXED_BUFFER_SIZE_BYTES 6068 /* LL only */ +#define BLE_FIXED_BUFFER_SIZE_BYTES 5936 /* LL only */ #elif (SLAVE_ONLY != 0) -#define BLE_FIXED_BUFFER_SIZE_BYTES 6096 /* Peripheral only */ +#define BLE_FIXED_BUFFER_SIZE_BYTES 6204 /* Peripheral only */ #elif (BASIC_FEATURES != 0) -#define BLE_FIXED_BUFFER_SIZE_BYTES 6400 /* Basic Features */ +#define BLE_FIXED_BUFFER_SIZE_BYTES 6532 /* Basic Features */ #else -#define BLE_FIXED_BUFFER_SIZE_BYTES 7312 /* Full stack */ +#define BLE_FIXED_BUFFER_SIZE_BYTES 7052 /* Full stack */ #endif /* * BLE_PER_LINK_SIZE_BYTES: additional memory size used per link */ #if (BEACON_ONLY != 0) -#define BLE_PER_LINK_SIZE_BYTES 192 /* Beacon only */ +#define BLE_PER_LINK_SIZE_BYTES 128 /* Beacon only */ #elif (LL_ONLY != 0) #define BLE_PER_LINK_SIZE_BYTES 260 /* LL only */ #elif (SLAVE_ONLY != 0) -#define BLE_PER_LINK_SIZE_BYTES 388 /* Peripheral only */ +#define BLE_PER_LINK_SIZE_BYTES 392 /* Peripheral only */ #elif (BASIC_FEATURES != 0) -#define BLE_PER_LINK_SIZE_BYTES 388 /* Basic Features */ +#define BLE_PER_LINK_SIZE_BYTES 440 /* Basic Features */ #else #define BLE_PER_LINK_SIZE_BYTES 444 /* Full stack */ #endif @@ -141,10 +141,17 @@ /* * BLE_EXT_ADV_BUFFER_SIZE * additional memory size used for Extended advertising; - * It has to be added to BLE_TOTAL_BUFFER_SIZE(). - * The formula used is based on:(1792 + ((set_nbr) * (60 + (2 * (data_len))))) + * It has to be added to BLE_TOTAL_BUFFER_SIZE() if the Extended advertising + * feature is used. + * + * @param set_nbr: Maximum number of advertising sets. + * Valid values are from 1 to 8. + * + * @param data_len: Maximum size of advertising data. + * Valid values are from 31 to 1650. */ -#define BLE_EXT_ADV_BUFFER_SIZE(set_nbr, data_len) (7596) +#define BLE_EXT_ADV_BUFFER_SIZE(set_nbr, data_len) \ + (2304 + ((892 + (DIVC(data_len, 207) * 244)) * (set_nbr))) /* * BLE_TOTAL_BUFFER_SIZE_GATT: this macro returns the amount of memory, diff --git a/src/utility/STM32Cube_FW/shci.h b/src/utility/STM32Cube_FW/shci.h index 9449c224..d965ec84 100644 --- a/src/utility/STM32Cube_FW/shci.h +++ b/src/utility/STM32Cube_FW/shci.h @@ -526,7 +526,7 @@ extern "C" { * - bit 0: 1: LL only 0: LL + host * - bit 1: 1: no service change desc. 0: with service change desc. * - bit 2: 1: device name Read-Only 0: device name R/W - * - bit 3: 1: extended advertizing supported 0: extended advertizing not supported [NOT SUPPORTED] + * - bit 3: 1: extended advertizing supported 0: extended advertizing not supported * - bit 4: 1: CS Algo #2 supported 0: CS Algo #2 not supported * - bit 7: 1: LE Power Class 1 0: LE Power Classe 2-3 * - other bits: reserved ( shall be set to 0) @@ -585,8 +585,8 @@ extern "C" { #define SHCI_C2_BLE_INIT_OPTIONS_DEVICE_NAME_RO (1<<2) #define SHCI_C2_BLE_INIT_OPTIONS_DEVICE_NAME_RW (0<<2) -#define SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV (1<<3) /*NOT SUPPORTED*/ -#define SHCI_C2_BLE_INIT_OPTIONS_NO_EXT_ADV (0<<3) /*NOT SUPPORTED*/ +#define SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV (1<<3) +#define SHCI_C2_BLE_INIT_OPTIONS_NO_EXT_ADV (0<<3) #define SHCI_C2_BLE_INIT_OPTIONS_CS_ALGO2 (1<<4) #define SHCI_C2_BLE_INIT_OPTIONS_NO_CS_ALGO2 (0<<4) @@ -856,6 +856,9 @@ extern "C" { #define INFO_STACK_TYPE_BLE_HCI 0x02 #define INFO_STACK_TYPE_BLE_LIGHT 0x03 #define INFO_STACK_TYPE_BLE_BEACON 0x04 +#define INFO_STACK_TYPE_BLE_BASIC 0x05 +#define INFO_STACK_TYPE_BLE_FULL_EXT_ADV 0x06 +#define INFO_STACK_TYPE_BLE_HCI_EXT_ADV 0x07 #define INFO_STACK_TYPE_THREAD_FTD 0x10 #define INFO_STACK_TYPE_THREAD_MTD 0x11 #define INFO_STACK_TYPE_BLE_THREAD_FTD_STATIC 0x50 diff --git a/src/utility/STM32Cube_FW/stm_list.c b/src/utility/STM32Cube_FW/stm_list.c index 3dea7512..d8c9e093 100644 --- a/src/utility/STM32Cube_FW/stm_list.c +++ b/src/utility/STM32Cube_FW/stm_list.c @@ -1,208 +1,208 @@ -/** - ****************************************************************************** - * @file stm_list.c - * @author MCD Application Team - * @brief TCircular Linked List Implementation. - ****************************************************************************** - * @attention - * - * Copyright (c) 2018-2021 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ - -#if defined(STM32WBxx) -/****************************************************************************** - * Include Files - ******************************************************************************/ -#include "stm_list.h" -#include "cmsis_gcc.h" -#include "stm32_wpan_common.h" - -/****************************************************************************** - * Function Definitions - ******************************************************************************/ -void LST_init_head (tListNode * listHead) -{ - listHead->next = listHead; - listHead->prev = listHead; -} - -bool LST_is_empty (tListNode * listHead) -{ - uint32_t primask_bit; - bool return_value; - - primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ - __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ - if(listHead->next == listHead) - { - return_value = TRUE; - } - else - { - return_value = FALSE; - } - __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ - - return return_value; -} - -void LST_insert_head (tListNode * listHead, tListNode * node) -{ - uint32_t primask_bit; - - primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ - __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ - - node->next = listHead->next; - node->prev = listHead; - listHead->next = node; - (node->next)->prev = node; - - __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ -} - - -void LST_insert_tail (tListNode * listHead, tListNode * node) -{ - uint32_t primask_bit; - - primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ - __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ - - node->next = listHead; - node->prev = listHead->prev; - listHead->prev = node; - (node->prev)->next = node; - - __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ -} - - -void LST_remove_node (tListNode * node) -{ - uint32_t primask_bit; - - primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ - __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ - - (node->prev)->next = node->next; - (node->next)->prev = node->prev; - - __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ -} - - -void LST_remove_head (tListNode * listHead, tListNode ** node ) -{ - uint32_t primask_bit; - - primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ - __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ - - *node = listHead->next; - LST_remove_node (listHead->next); - - __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ -} - - -void LST_remove_tail (tListNode * listHead, tListNode ** node ) -{ - uint32_t primask_bit; - - primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ - __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ - - *node = listHead->prev; - LST_remove_node (listHead->prev); - - __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ -} - - -void LST_insert_node_after (tListNode * node, tListNode * ref_node) -{ - uint32_t primask_bit; - - primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ - __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ - - node->next = ref_node->next; - node->prev = ref_node; - ref_node->next = node; - (node->next)->prev = node; - - __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ -} - - -void LST_insert_node_before (tListNode * node, tListNode * ref_node) -{ - uint32_t primask_bit; - - primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ - __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ - - node->next = ref_node; - node->prev = ref_node->prev; - ref_node->prev = node; - (node->prev)->next = node; - - __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ -} - - -int LST_get_size (tListNode * listHead) -{ - int size = 0; - tListNode * temp; - uint32_t primask_bit; - - primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ - __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ - - temp = listHead->next; - while (temp != listHead) - { - size++; - temp = temp->next; - } - - __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ - - return (size); -} - -void LST_get_next_node (tListNode * ref_node, tListNode ** node) -{ - uint32_t primask_bit; - - primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ - __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ - - *node = ref_node->next; - - __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ -} - - -void LST_get_prev_node (tListNode * ref_node, tListNode ** node) -{ - uint32_t primask_bit; - - primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ - __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ - - *node = ref_node->prev; - - __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ -} - -#endif /* STM32WBxx */ \ No newline at end of file +/** + ****************************************************************************** + * @file stm_list.c + * @author MCD Application Team + * @brief TCircular Linked List Implementation. + ****************************************************************************** + * @attention + * + * Copyright (c) 2018-2021 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ + +#if defined(STM32WBxx) +/****************************************************************************** + * Include Files + ******************************************************************************/ +#include "stm_list.h" +#include "cmsis_gcc.h" +#include "stm32_wpan_common.h" + +/****************************************************************************** + * Function Definitions + ******************************************************************************/ +void LST_init_head (tListNode * listHead) +{ + listHead->next = listHead; + listHead->prev = listHead; +} + +bool LST_is_empty (tListNode * listHead) +{ + uint32_t primask_bit; + bool return_value; + + primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ + __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ + if(listHead->next == listHead) + { + return_value = TRUE; + } + else + { + return_value = FALSE; + } + __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ + + return return_value; +} + +void LST_insert_head (tListNode * listHead, tListNode * node) +{ + uint32_t primask_bit; + + primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ + __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ + + node->next = listHead->next; + node->prev = listHead; + listHead->next = node; + (node->next)->prev = node; + + __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ +} + + +void LST_insert_tail (tListNode * listHead, tListNode * node) +{ + uint32_t primask_bit; + + primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ + __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ + + node->next = listHead; + node->prev = listHead->prev; + listHead->prev = node; + (node->prev)->next = node; + + __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ +} + + +void LST_remove_node (tListNode * node) +{ + uint32_t primask_bit; + + primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ + __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ + + (node->prev)->next = node->next; + (node->next)->prev = node->prev; + + __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ +} + + +void LST_remove_head (tListNode * listHead, tListNode ** node ) +{ + uint32_t primask_bit; + + primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ + __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ + + *node = listHead->next; + LST_remove_node (listHead->next); + + __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ +} + + +void LST_remove_tail (tListNode * listHead, tListNode ** node ) +{ + uint32_t primask_bit; + + primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ + __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ + + *node = listHead->prev; + LST_remove_node (listHead->prev); + + __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ +} + + +void LST_insert_node_after (tListNode * node, tListNode * ref_node) +{ + uint32_t primask_bit; + + primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ + __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ + + node->next = ref_node->next; + node->prev = ref_node; + ref_node->next = node; + (node->next)->prev = node; + + __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ +} + + +void LST_insert_node_before (tListNode * node, tListNode * ref_node) +{ + uint32_t primask_bit; + + primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ + __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ + + node->next = ref_node; + node->prev = ref_node->prev; + ref_node->prev = node; + (node->prev)->next = node; + + __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ +} + + +int LST_get_size (tListNode * listHead) +{ + int size = 0; + tListNode * temp; + uint32_t primask_bit; + + primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ + __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ + + temp = listHead->next; + while (temp != listHead) + { + size++; + temp = temp->next; + } + + __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ + + return (size); +} + +void LST_get_next_node (tListNode * ref_node, tListNode ** node) +{ + uint32_t primask_bit; + + primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ + __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ + + *node = ref_node->next; + + __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ +} + + +void LST_get_prev_node (tListNode * ref_node, tListNode ** node) +{ + uint32_t primask_bit; + + primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ + __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ + + *node = ref_node->prev; + + __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ +} + +#endif /* STM32WBxx */ \ No newline at end of file From 381c3ca61658983c9836545603869a185f04eee8 Mon Sep 17 00:00:00 2001 From: Giuseppe Roberti <giuseppe.roberti@ieee.org> Date: Tue, 30 Aug 2022 11:55:17 +0200 Subject: [PATCH 086/226] Fix hard fault when str is NULL --- src/utility/BLEUuid.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/utility/BLEUuid.cpp b/src/utility/BLEUuid.cpp index fba6244a..0465ea9a 100644 --- a/src/utility/BLEUuid.cpp +++ b/src/utility/BLEUuid.cpp @@ -30,6 +30,11 @@ BLEUuid::BLEUuid(const char * str) : memset(_data, 0x00, sizeof(_data)); _length = 0; + + if (str == NULL) { + return; + } + for (int i = strlen(str) - 1; i >= 0 && _length < BLE_UUID_MAX_LENGTH; i -= 2) { if (str[i] == '-') { i++; From 6e951334cbf0a703c6a5a61972c9ed0de1fb4509 Mon Sep 17 00:00:00 2001 From: Giuseppe Roberti <giuseppe.roberti@ieee.org> Date: Tue, 9 Aug 2022 10:17:09 +0200 Subject: [PATCH 087/226] Support BlueNRG-LP --- examples/Peripheral/ButtonLED/ButtonLED.ino | 13 +- keywords.txt | 2 +- src/utility/HCISpiTransport.cpp | 314 +++++++++++++++++--- src/utility/HCISpiTransport.h | 7 +- 4 files changed, 295 insertions(+), 41 deletions(-) diff --git a/examples/Peripheral/ButtonLED/ButtonLED.ino b/examples/Peripheral/ButtonLED/ButtonLED.ino index c3f777d4..f12adb50 100644 --- a/examples/Peripheral/ButtonLED/ButtonLED.ino +++ b/examples/Peripheral/ButtonLED/ButtonLED.ino @@ -6,7 +6,7 @@ represents the state of the button. The circuit: - - STEVAL-MKSBOX1V1, B-L475E-IOT01A1, B_L4S5I_IOT01A, or a Nucleo board plus the X-NUCLEO-IDB05A2 or the X-NUCLEO-IDB05A1 or the X-NUCLEO-BNRG2A1 + - STEVAL-MKBOXPRO, STEVAL-MKSBOX1V1, B-L475E-IOT01A1, B_L4S5I_IOT01A, or a Nucleo board plus the X-NUCLEO-IDB05A2 or the X-NUCLEO-IDB05A1 or the X-NUCLEO-BNRG2A1 You can use a generic BLE central app, like LightBlue (iOS and Android) or nRF Connect (Android), to interact with the services and characteristics @@ -17,7 +17,16 @@ #include <STM32duinoBLE.h> -#if defined(ARDUINO_STEVAL_MKSBOX1V1) +#if defined(ARDUINO_STEVAL_MKBOXPRO) +/* STEVAL-MKBOXPRO */ +SPIClass SpiHCI(PA7, PA6, PA5); +HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_LP, PA2, PB11, PD4, 1000000, SPI_MODE3); +#if !defined(FAKE_BLELOCALDEVICE) +BLELocalDevice BLEObj(&HCISpiTransport); +BLELocalDevice& BLE = BLEObj; +#endif +const int buttonPin = PC13; // set buttonPin to digital pin PC13 +#elif defined(ARDUINO_STEVAL_MKSBOX1V1) /* STEVAL-MKSBOX1V1 */ SPIClass SpiHCI(PC3, PD3, PD1); HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_1S, PD0, PD4, PA8, 1000000, SPI_MODE1); diff --git a/keywords.txt b/keywords.txt index 9214671b..e13de56d 100644 --- a/keywords.txt +++ b/keywords.txt @@ -143,5 +143,5 @@ BLEUpdated LITERAL1 SPBTLE_RF LITERAL1 SPBTLE_1S LITERAL1 BLUENRG_M2SP LITERAL1 +BLUENRG_LP LITERAL1 BLEChip_t LITERAL1 - diff --git a/src/utility/HCISpiTransport.cpp b/src/utility/HCISpiTransport.cpp index a503b427..b2abddd4 100644 --- a/src/utility/HCISpiTransport.cpp +++ b/src/utility/HCISpiTransport.cpp @@ -33,6 +33,7 @@ HCISpiTransportClass::HCISpiTransportClass(SPIClass &spi, BLEChip_t ble_chip, ui _write_index = 0; _write_index_initial = 0; _initial_phase = 1; + _random_addr_done = false; } HCISpiTransportClass::~HCISpiTransportClass() @@ -66,7 +67,7 @@ int HCISpiTransportClass::begin() digitalWrite(_ble_rst, HIGH); delay(5); - if (_ble_chip == SPBTLE_RF || _ble_chip == BLUENRG_M0) { + if (_ble_chip == SPBTLE_RF || _ble_chip == BLUENRG_M0 || _ble_chip == BLUENRG_LP) { // Wait for Blue Initialize wait_for_blue_initialize(); } else if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP) { @@ -97,7 +98,7 @@ void HCISpiTransportClass::wait(unsigned long timeout) int HCISpiTransportClass::available() { - if (_ble_chip != SPBTLE_RF && _ble_chip != SPBTLE_1S && _ble_chip != BLUENRG_M2SP && _ble_chip != BLUENRG_M0) { + if (_ble_chip != SPBTLE_RF && _ble_chip != SPBTLE_1S && _ble_chip != BLUENRG_M2SP && _ble_chip != BLUENRG_M0 && _ble_chip != BLUENRG_LP) { return 0; } @@ -115,7 +116,7 @@ int HCISpiTransportClass::available() while (digitalRead(_spi_irq) == 1 && _write_index != BLE_MODULE_SPI_BUFFER_SIZE) { uint8_t header_master[5] = {0x0b, 0x00, 0x00, 0x00, 0x00}; - if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP) { + if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { detachInterrupt(_spi_irq); } @@ -172,7 +173,7 @@ int HCISpiTransportClass::available() } } } - } else if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP) { + } else if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { uint16_t byte_count = (header_master[4] << 8) | header_master[3]; if (byte_count > 0) { @@ -222,13 +223,13 @@ int HCISpiTransportClass::available() _spi->endTransaction(); - if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP) { + if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); } } if (ble_reset) { - if (_ble_chip == SPBTLE_RF || _ble_chip == BLUENRG_M0) { + if (_ble_chip == SPBTLE_RF || _ble_chip == BLUENRG_M0 || _ble_chip == BLUENRG_LP) { /* BLE chip was reset: we need to enable LL_ONLY */ enable_ll_only(); wait_for_enable_ll_only(); @@ -238,18 +239,32 @@ int HCISpiTransportClass::available() } /* Call Gatt Init and Gap Init to activate the random BLE address */ - aci_gatt_init(); - wait_for_aci_gatt_init(); - aci_gap_init(); - wait_for_aci_gap_init(); - /* Call Read Config Parameter to retrieve the random BLE address */ - aci_read_config_parameter(); - wait_for_aci_read_config_parameter(); - - /* Now we can update the write index and close the initial phase */ - _write_index = _write_index_initial; - _initial_phase = 0; - _write_index_initial = 0; + if (!_random_addr_done) { + aci_gatt_init(); + wait_for_aci_gatt_init(); + aci_gap_init(); + wait_for_aci_gap_init(); + /* Call Read Config Parameter to retrieve the random BLE address */ + aci_read_config_parameter(); + wait_for_aci_read_config_parameter(); + if (_ble_chip == BLUENRG_LP) { + hci_reset(); + _read_index = _write_index = _write_index_initial = 0; + _initial_phase = 1; + } else { + /* Now we can update the write index and close the initial phase */ + _write_index = _write_index_initial; + _initial_phase = 0; + _write_index_initial = 0; + } + } else { + set_address(); + wait_for_set_address(); + /* Now we can update the write index and close the initial phase */ + _write_index = _write_index_initial; + _initial_phase = 0; + _write_index_initial = 0; + } } if (_read_index != _write_index) { @@ -297,7 +312,7 @@ 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 && _ble_chip != BLUENRG_M0) { + if (_ble_chip != SPBTLE_RF && _ble_chip != SPBTLE_1S && _ble_chip != BLUENRG_M2SP && _ble_chip != BLUENRG_M0 && _ble_chip != BLUENRG_LP) { return 0; } @@ -332,7 +347,7 @@ size_t HCISpiTransportClass::write(const uint8_t *data, size_t length) result = -3; break; } - } else if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP) { + } else if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { uint32_t tickstart_data_available = millis(); result = 0; @@ -406,7 +421,7 @@ void HCISpiTransportClass::wait_for_blue_initialize() while (digitalRead(_spi_irq) == 1) { uint8_t header_master[5] = {0x0b, 0x00, 0x00, 0x00, 0x00}; - if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP) { + if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { detachInterrupt(_spi_irq); } @@ -469,13 +484,38 @@ void HCISpiTransportClass::wait_for_blue_initialize() } } } + } else if (_ble_chip == BLUENRG_LP) { + uint8_t byte_count = (header_master[4] << 8) | header_master[3]; + + if (byte_count > 0) { + /* Read the response */ + if (byte_count == 7) { + for (int j = 0; j < byte_count; j++) { + event[j] = _spi->transfer(0xFF); + } + + if (event[0] == 0x82 && + event[1] == 0xFF && + event[2] == 0x03 && + event[3] == 0x00 && + event[4] == 0x01 && + event[5] == 0x00 && + event[6] == 0x01) { + event_blue_initialize = 1; + } + } else { + for (int j = 0; j < byte_count; j++) { + _spi->transfer(0xFF); + } + } + } } digitalWrite(_cs_pin, HIGH); _spi->endTransaction(); - if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP) { + if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); } } @@ -498,7 +538,7 @@ void HCISpiTransportClass::wait_for_enable_ll_only() while (digitalRead(_spi_irq) == 1) { uint8_t header_master[5] = {0x0b, 0x00, 0x00, 0x00, 0x00}; - if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP) { + if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { detachInterrupt(_spi_irq); } @@ -534,7 +574,7 @@ void HCISpiTransportClass::wait_for_enable_ll_only() } } } - } else if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP) { + } else if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { uint16_t byte_count = (header_master[4] << 8) | header_master[3]; if (byte_count > 0) { @@ -561,7 +601,7 @@ void HCISpiTransportClass::wait_for_enable_ll_only() _spi->endTransaction(); - if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP) { + if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); } } @@ -601,7 +641,7 @@ void HCISpiTransportClass::enable_ll_only() digitalWrite(_cs_pin, HIGH); _spi->endTransaction(); - } else if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP) { + } else if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { uint32_t tickstart_data_available = millis(); result = 0; @@ -660,7 +700,7 @@ void HCISpiTransportClass::wait_for_aci_gatt_init() while (digitalRead(_spi_irq) == 1) { uint8_t header_master[5] = {0x0b, 0x00, 0x00, 0x00, 0x00}; - if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP) { + if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { detachInterrupt(_spi_irq); } @@ -696,7 +736,7 @@ void HCISpiTransportClass::wait_for_aci_gatt_init() } } } - } else if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP) { + } else if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { uint16_t byte_count = (header_master[4] << 8) | header_master[3]; if (byte_count > 0) { @@ -723,7 +763,7 @@ void HCISpiTransportClass::wait_for_aci_gatt_init() _spi->endTransaction(); - if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP) { + if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); } } @@ -763,7 +803,7 @@ void HCISpiTransportClass::aci_gatt_init() digitalWrite(_cs_pin, HIGH); _spi->endTransaction(); - } else if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP) { + } else if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { uint32_t tickstart_data_available = millis(); result = 0; @@ -822,7 +862,7 @@ void HCISpiTransportClass::wait_for_aci_gap_init() while (digitalRead(_spi_irq) == 1) { uint8_t header_master[5] = {0x0b, 0x00, 0x00, 0x00, 0x00}; - if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP) { + if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { detachInterrupt(_spi_irq); } @@ -858,7 +898,7 @@ void HCISpiTransportClass::wait_for_aci_gap_init() } } } - } else if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP) { + } else if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { uint16_t byte_count = (header_master[4] << 8) | header_master[3]; if (byte_count > 0) { @@ -885,7 +925,7 @@ void HCISpiTransportClass::wait_for_aci_gap_init() _spi->endTransaction(); - if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP) { + if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); } } @@ -896,6 +936,7 @@ void HCISpiTransportClass::aci_gap_init() { uint8_t header_master[5] = {0x0a, 0x00, 0x00, 0x00, 0x00}; uint8_t cmd[7] = {0x01, 0x8A, 0xFC, 0x03, 0x0F, 0x00, 0x00}; // ACI_GAP_INIT + uint8_t cmd_lp[8] = {0x01, 0x8A, 0xFC, 0x04, 0x0F, 0x00, 0x00, 0x00}; // ACI_GAP_INIT for BlueNRG-LP int result = 0; do { @@ -963,6 +1004,45 @@ void HCISpiTransportClass::aci_gap_init() _spi->endTransaction(); + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + } else if (_ble_chip == BLUENRG_LP) { + uint32_t tickstart_data_available = millis(); + result = 0; + + detachInterrupt(_spi_irq); + + _spi->beginTransaction(_spiSettings); + + digitalWrite(_cs_pin, LOW); + + while (!(digitalRead(_spi_irq) == 1)) { + if ((millis() - tickstart_data_available) > 1000) { + result = -3; + break; + } + } + + if (result == -3) { + digitalWrite(_cs_pin, HIGH); + _spi->endTransaction(); + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + break; + } + + /* Write the header */ + _spi->transfer(header_master, 5); + + if ((int)((((uint16_t)header_master[2]) << 8) | ((uint16_t)header_master[1])) >= 8) { + /* Write the data */ + _spi->transfer((void *)cmd_lp, 8); + } else { + result = -2; + } + + digitalWrite(_cs_pin, HIGH); + + _spi->endTransaction(); + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); } } while (result < 0); @@ -984,7 +1064,7 @@ void HCISpiTransportClass::wait_for_aci_read_config_parameter() while (digitalRead(_spi_irq) == 1) { uint8_t header_master[5] = {0x0b, 0x00, 0x00, 0x00, 0x00}; - if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP) { + if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { detachInterrupt(_spi_irq); } @@ -1021,7 +1101,7 @@ void HCISpiTransportClass::wait_for_aci_read_config_parameter() } } } - } else if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP) { + } else if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { uint16_t byte_count = (header_master[4] << 8) | header_master[3]; if (byte_count > 0) { @@ -1040,6 +1120,7 @@ void HCISpiTransportClass::wait_for_aci_read_config_parameter() data[6] == 0x00) { memcpy(_random_addr, &data[8], 6); status = 1; + _random_addr_done = true; } } } @@ -1049,7 +1130,7 @@ void HCISpiTransportClass::wait_for_aci_read_config_parameter() _spi->endTransaction(); - if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP) { + if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); } } @@ -1089,7 +1170,7 @@ void HCISpiTransportClass::aci_read_config_parameter() digitalWrite(_cs_pin, HIGH); _spi->endTransaction(); - } else if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP) { + } else if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { uint32_t tickstart_data_available = millis(); result = 0; @@ -1131,3 +1212,162 @@ void HCISpiTransportClass::aci_read_config_parameter() } } while (result < 0); } + +void HCISpiTransportClass::hci_reset() +{ + uint8_t header_master[5] = {0x0a, 0x00, 0x00, 0x00, 0x00}; + uint8_t cmd[4] = {0x01, 0x03, 0x0C, 0x00}; // HCI_RESET + int result = 0; + + do { + if (_ble_chip == BLUENRG_LP) { + uint32_t tickstart_data_available = millis(); + result = 0; + + detachInterrupt(_spi_irq); + + _spi->beginTransaction(_spiSettings); + + digitalWrite(_cs_pin, LOW); + + while (!(digitalRead(_spi_irq) == 1)) { + if ((millis() - tickstart_data_available) > 1000) { + result = -3; + break; + } + } + + if (result == -3) { + digitalWrite(_cs_pin, HIGH); + _spi->endTransaction(); + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + break; + } + + /* Write the header */ + _spi->transfer(header_master, 5); + + if ((int)((((uint16_t)header_master[2]) << 8) | ((uint16_t)header_master[1])) >= 4) { + /* Write the data */ + _spi->transfer((void *)cmd, 4); + } else { + result = -2; + } + + digitalWrite(_cs_pin, HIGH); + + _spi->endTransaction(); + + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + } + } while (result < 0); +} + +void HCISpiTransportClass::set_address() +{ + uint8_t header_master[5] = {0x0a, 0x00, 0x00, 0x00, 0x00}; + uint8_t cmd[10] = {0x01, 0x05, 0x20, 0x06}; // SET ADDR + int result = 0; + memcpy(&cmd[4], _random_addr, 6); + + do { + if (_ble_chip == BLUENRG_LP) { + uint32_t tickstart_data_available = millis(); + result = 0; + + detachInterrupt(_spi_irq); + + _spi->beginTransaction(_spiSettings); + + digitalWrite(_cs_pin, LOW); + + while (!(digitalRead(_spi_irq) == 1)) { + if ((millis() - tickstart_data_available) > 1000) { + result = -3; + break; + } + } + + if (result == -3) { + digitalWrite(_cs_pin, HIGH); + _spi->endTransaction(); + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + break; + } + + /* Write the header */ + _spi->transfer(header_master, 5); + + if ((int)((((uint16_t)header_master[2]) << 8) | ((uint16_t)header_master[1])) >= 10) { + /* Write the data */ + _spi->transfer((void *)cmd, 10); + } else { + result = -2; + } + + digitalWrite(_cs_pin, HIGH); + + _spi->endTransaction(); + + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + } + } while (result < 0); +} + +void HCISpiTransportClass::wait_for_set_address() +{ + uint8_t data[15]; + int status = 0; + + if (_ble_chip != BLUENRG_LP) return; + + do { + while (!data_avail); + + if (digitalRead(_spi_irq) == 0) { + continue; + } + + data_avail = 0; + while (digitalRead(_spi_irq) == 1) { + uint8_t header_master[5] = {0x0b, 0x00, 0x00, 0x00, 0x00}; + uint16_t byte_count = 0; + + detachInterrupt(_spi_irq); + + _spi->beginTransaction(_spiSettings); + + digitalWrite(_cs_pin, LOW); + + /* Write the header */ + _spi->transfer(header_master, 5); + + byte_count = (header_master[4] << 8) | header_master[3]; + + if (byte_count > 0) { + /* Read the response */ + for (int j = 0; j < byte_count; j++) { + data[j] = _spi->transfer(0xFF); + } + + if (byte_count >= 7) { // 040E0401052000 + if (data[0] == 0x04 && + data[1] == 0x0E && + data[2] == 0x04 && + data[3] == 0x01 && + data[4] == 0x05 && + data[5] == 0x20 && + data[6] == 0x00) { + status = 1; + } + } + } + + digitalWrite(_cs_pin, HIGH); + + _spi->endTransaction(); + + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + } + } while (!status); +} diff --git a/src/utility/HCISpiTransport.h b/src/utility/HCISpiTransport.h index 9c3afc34..34af1aa9 100644 --- a/src/utility/HCISpiTransport.h +++ b/src/utility/HCISpiTransport.h @@ -27,7 +27,8 @@ typedef enum BLEChip_s { SPBTLE_RF, SPBTLE_1S, BLUENRG_M2SP, - BLUENRG_M0 + BLUENRG_M0, + BLUENRG_LP } BLEChip_t; #ifndef BLE_SPI_BYTE_ORDER @@ -61,6 +62,9 @@ class HCISpiTransportClass : public HCITransportInterface { void aci_gap_init(); void wait_for_aci_read_config_parameter(); void aci_read_config_parameter(); + void hci_reset(); + void set_address(); + void wait_for_set_address(); SPIClass *_spi; SPISettings _spiSettings; BLEChip_t _ble_chip; @@ -73,6 +77,7 @@ class HCISpiTransportClass : public HCITransportInterface { uint16_t _write_index_initial; uint8_t _initial_phase; uint8_t _random_addr[6]; + bool _random_addr_done; }; #endif /* _HCI_SPI_TRANSPORT_H_ */ From 9cf284f8ce05446b1e0064bff07fd4e83b0075f5 Mon Sep 17 00:00:00 2001 From: Giuseppe Roberti <giuseppe.roberti@ieee.org> Date: Tue, 9 Aug 2022 13:34:06 +0200 Subject: [PATCH 088/226] Ugly fix delay --- src/utility/HCISpiTransport.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/utility/HCISpiTransport.cpp b/src/utility/HCISpiTransport.cpp index b2abddd4..eae96911 100644 --- a/src/utility/HCISpiTransport.cpp +++ b/src/utility/HCISpiTransport.cpp @@ -113,6 +113,11 @@ int HCISpiTransportClass::available() data_avail = 0; + // Wait for BlueNRG-LP to be ready (needs to be done after each HCI RESET) + if (_ble_chip == BLUENRG_LP && _initial_phase) { + delay(100); + } + while (digitalRead(_spi_irq) == 1 && _write_index != BLE_MODULE_SPI_BUFFER_SIZE) { uint8_t header_master[5] = {0x0b, 0x00, 0x00, 0x00, 0x00}; From 831e996f17f82efec25149e39ca8655f65dbdb05 Mon Sep 17 00:00:00 2001 From: Giuseppe Roberti <giuseppe.roberti@ieee.org> Date: Tue, 9 Aug 2022 16:32:20 +0200 Subject: [PATCH 089/226] LP only differ in cmd, not procedure --- src/utility/HCISpiTransport.cpp | 61 ++++++++------------------------- 1 file changed, 15 insertions(+), 46 deletions(-) diff --git a/src/utility/HCISpiTransport.cpp b/src/utility/HCISpiTransport.cpp index eae96911..5c18083f 100644 --- a/src/utility/HCISpiTransport.cpp +++ b/src/utility/HCISpiTransport.cpp @@ -940,8 +940,16 @@ void HCISpiTransportClass::wait_for_aci_gap_init() void HCISpiTransportClass::aci_gap_init() { uint8_t header_master[5] = {0x0a, 0x00, 0x00, 0x00, 0x00}; - uint8_t cmd[7] = {0x01, 0x8A, 0xFC, 0x03, 0x0F, 0x00, 0x00}; // ACI_GAP_INIT - uint8_t cmd_lp[8] = {0x01, 0x8A, 0xFC, 0x04, 0x0F, 0x00, 0x00, 0x00}; // ACI_GAP_INIT for BlueNRG-LP + uint8_t cmd_lp[8] = {0x01, 0x8A, 0xFC, 0x04, 0x0F, 0x00, 0x00, 0x00}; // ACI_GAP_INIT + uint8_t cmd_others[7] = {0x01, 0x8A, 0xFC, 0x03, 0x0F, 0x00, 0x00}; // ACI_GAP_INIT + uint8_t *cmd, cmd_size; + if (_ble_chip == BLUENRG_LP) { + cmd = cmd_lp; + cmd_size = 8; + } else { + cmd = cmd_others; + cmd_size = 7; + } int result = 0; do { @@ -958,9 +966,9 @@ void HCISpiTransportClass::aci_gap_init() /* device is ready */ if (header_master[0] == 0x02) { /* Write the data */ - if (header_master[1] >= 7) { + if (header_master[1] >= cmd_size) { /* Write the data */ - _spi->transfer((void *)cmd, 7); + _spi->transfer((void *)cmd, cmd_size); } else { result = -2; } @@ -971,46 +979,7 @@ void HCISpiTransportClass::aci_gap_init() digitalWrite(_cs_pin, HIGH); _spi->endTransaction(); - } else if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP) { - uint32_t tickstart_data_available = millis(); - result = 0; - - detachInterrupt(_spi_irq); - - _spi->beginTransaction(_spiSettings); - - digitalWrite(_cs_pin, LOW); - - while (!(digitalRead(_spi_irq) == 1)) { - if ((millis() - tickstart_data_available) > 1000) { - result = -3; - break; - } - } - - if (result == -3) { - digitalWrite(_cs_pin, HIGH); - _spi->endTransaction(); - attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); - break; - } - - /* Write the header */ - _spi->transfer(header_master, 5); - - if ((int)((((uint16_t)header_master[2]) << 8) | ((uint16_t)header_master[1])) >= 7) { - /* Write the data */ - _spi->transfer((void *)cmd, 7); - } else { - result = -2; - } - - digitalWrite(_cs_pin, HIGH); - - _spi->endTransaction(); - - attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); - } else if (_ble_chip == BLUENRG_LP) { + } else if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { uint32_t tickstart_data_available = millis(); result = 0; @@ -1037,9 +1006,9 @@ void HCISpiTransportClass::aci_gap_init() /* Write the header */ _spi->transfer(header_master, 5); - if ((int)((((uint16_t)header_master[2]) << 8) | ((uint16_t)header_master[1])) >= 8) { + if ((int)((((uint16_t)header_master[2]) << 8) | ((uint16_t)header_master[1])) >= cmd_size) { /* Write the data */ - _spi->transfer((void *)cmd_lp, 8); + _spi->transfer((void *)cmd, cmd_size); } else { result = -2; } From 93af438927ffc0119caf0b2b4d4c300da3dee364 Mon Sep 17 00:00:00 2001 From: Giuseppe Roberti <giuseppe.roberti@ieee.org> Date: Tue, 30 Aug 2022 14:51:20 +0200 Subject: [PATCH 090/226] Enable STEVAL-MKBOXPRO support in examples --- examples/Central/LedControl/LedControl.ino | 13 +++++++++++-- .../PeripheralExplorer/PeripheralExplorer.ino | 13 +++++++++++-- examples/Central/Scan/Scan.ino | 13 +++++++++++-- examples/Central/ScanCallback/ScanCallback.ino | 13 +++++++++++-- .../Central/SensorTagButton/SensorTagButton.ino | 13 +++++++++++-- examples/Peripheral/CallbackLED/CallbackLED.ino | 13 +++++++++++-- examples/Peripheral/LED/LED.ino | 13 +++++++++++-- 7 files changed, 77 insertions(+), 14 deletions(-) diff --git a/examples/Central/LedControl/LedControl.ino b/examples/Central/LedControl/LedControl.ino index 2f64bc28..d0f73383 100644 --- a/examples/Central/LedControl/LedControl.ino +++ b/examples/Central/LedControl/LedControl.ino @@ -6,7 +6,7 @@ it will remotely control the BLE Peripheral's LED, when the button is pressed or released. The circuit: - - STEVAL-MKSBOX1V1, B-L475E-IOT01A1, B_L4S5I_IOT01A, or a Nucleo board plus the X-NUCLEO-IDB05A2 or the X-NUCLEO-IDB05A1 or the X-NUCLEO-BNRG2A1 + - STEVAL-MKBOXPRO, STEVAL-MKSBOX1V1, B-L475E-IOT01A1, B_L4S5I_IOT01A, or a Nucleo board plus the X-NUCLEO-IDB05A2 or the X-NUCLEO-IDB05A1 or the X-NUCLEO-BNRG2A1 You can use it with another board that is compatible with this library and the Peripherals -> LED example. @@ -16,7 +16,16 @@ #include <STM32duinoBLE.h> -#if defined(ARDUINO_STEVAL_MKSBOX1V1) +#if defined(ARDUINO_STEVAL_MKBOXPRO) +/* STEVAL-MKBOXPRO */ +SPIClass SpiHCI(PA7, PA6, PA5); +HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_LP, PA2, PB11, PD4, 1000000, SPI_MODE3); +#if !defined(FAKE_BLELOCALDEVICE) +BLELocalDevice BLEObj(&HCISpiTransport); +BLELocalDevice& BLE = BLEObj; +#endif +const int buttonPin = PC13; // set buttonPin to digital pin PC13 +#elif defined(ARDUINO_STEVAL_MKSBOX1V1) /* STEVAL-MKSBOX1V1 */ SPIClass SpiHCI(PC3, PD3, PD1); HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_1S, PD0, PD4, PA8, 1000000, SPI_MODE1); diff --git a/examples/Central/PeripheralExplorer/PeripheralExplorer.ino b/examples/Central/PeripheralExplorer/PeripheralExplorer.ino index e5461fa5..ea8b3b24 100644 --- a/examples/Central/PeripheralExplorer/PeripheralExplorer.ino +++ b/examples/Central/PeripheralExplorer/PeripheralExplorer.ino @@ -5,7 +5,7 @@ is found. Then connects, and discovers + prints all the peripheral's attributes. The circuit: - - STEVAL-MKSBOX1V1, B-L475E-IOT01A1, B_L4S5I_IOT01A, or a Nucleo board plus the X-NUCLEO-IDB05A2 or the X-NUCLEO-IDB05A1 or the X-NUCLEO-BNRG2A1 + - STEVAL-MKBOXPRO, STEVAL-MKSBOX1V1, B-L475E-IOT01A1, B_L4S5I_IOT01A, or a Nucleo board plus the X-NUCLEO-IDB05A2 or the X-NUCLEO-IDB05A1 or the X-NUCLEO-BNRG2A1 You can use it with another board that is compatible with this library and the Peripherals -> LED example. @@ -15,7 +15,16 @@ #include <STM32duinoBLE.h> -#if defined(ARDUINO_STEVAL_MKSBOX1V1) +#if defined(ARDUINO_STEVAL_MKBOXPRO) +/* STEVAL-MKBOXPRO */ +SPIClass SpiHCI(PA7, PA6, PA5); +HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_LP, PA2, PB11, PD4, 1000000, SPI_MODE3); +#if !defined(FAKE_BLELOCALDEVICE) +BLELocalDevice BLEObj(&HCISpiTransport); +BLELocalDevice& BLE = BLEObj; +#endif +const int buttonPin = PC13; // set buttonPin to digital pin PC13 +#elif defined(ARDUINO_STEVAL_MKSBOX1V1) /* STEVAL-MKSBOX1V1 */ SPIClass SpiHCI(PC3, PD3, PD1); HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_1S, PD0, PD4, PA8, 1000000, SPI_MODE1); diff --git a/examples/Central/Scan/Scan.ino b/examples/Central/Scan/Scan.ino index bf1bef5f..bd22c65e 100644 --- a/examples/Central/Scan/Scan.ino +++ b/examples/Central/Scan/Scan.ino @@ -5,14 +5,23 @@ address, local name, advertised service UUID's. The circuit: - - STEVAL-MKSBOX1V1, B-L475E-IOT01A1, B_L4S5I_IOT01A, or a Nucleo board plus the X-NUCLEO-IDB05A2 or the X-NUCLEO-IDB05A1 or the X-NUCLEO-BNRG2A1 + - STEVAL-MKBOXPRO, STEVAL-MKSBOX1V1, B-L475E-IOT01A1, B_L4S5I_IOT01A, or a Nucleo board plus the X-NUCLEO-IDB05A2 or the X-NUCLEO-IDB05A1 or the X-NUCLEO-BNRG2A1 This example code is in the public domain. */ #include <STM32duinoBLE.h> -#if defined(ARDUINO_STEVAL_MKSBOX1V1) +#if defined(ARDUINO_STEVAL_MKBOXPRO) +/* STEVAL-MKBOXPRO */ +SPIClass SpiHCI(PA7, PA6, PA5); +HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_LP, PA2, PB11, PD4, 1000000, SPI_MODE3); +#if !defined(FAKE_BLELOCALDEVICE) +BLELocalDevice BLEObj(&HCISpiTransport); +BLELocalDevice& BLE = BLEObj; +#endif +const int buttonPin = PC13; // set buttonPin to digital pin PC13 +#elif defined(ARDUINO_STEVAL_MKSBOX1V1) /* STEVAL-MKSBOX1V1 */ SPIClass SpiHCI(PC3, PD3, PD1); HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_1S, PD0, PD4, PA8, 1000000, SPI_MODE1); diff --git a/examples/Central/ScanCallback/ScanCallback.ino b/examples/Central/ScanCallback/ScanCallback.ino index 4d9bbc77..dbc2536e 100644 --- a/examples/Central/ScanCallback/ScanCallback.ino +++ b/examples/Central/ScanCallback/ScanCallback.ino @@ -7,14 +7,23 @@ reported for every single advertisement it makes. The circuit: - - STEVAL-MKSBOX1V1, B-L475E-IOT01A1, B_L4S5I_IOT01A, or a Nucleo board plus the X-NUCLEO-IDB05A2 or the X-NUCLEO-IDB05A1 or the X-NUCLEO-BNRG2A1 + - STEVAL-MKBOXPRO, STEVAL-MKSBOX1V1, B-L475E-IOT01A1, B_L4S5I_IOT01A, or a Nucleo board plus the X-NUCLEO-IDB05A2 or the X-NUCLEO-IDB05A1 or the X-NUCLEO-BNRG2A1 This example code is in the public domain. */ #include <STM32duinoBLE.h> -#if defined(ARDUINO_STEVAL_MKSBOX1V1) +#if defined(ARDUINO_STEVAL_MKBOXPRO) +/* STEVAL-MKBOXPRO */ +SPIClass SpiHCI(PA7, PA6, PA5); +HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_LP, PA2, PB11, PD4, 1000000, SPI_MODE3); +#if !defined(FAKE_BLELOCALDEVICE) +BLELocalDevice BLEObj(&HCISpiTransport); +BLELocalDevice& BLE = BLEObj; +#endif +const int buttonPin = PC13; // set buttonPin to digital pin PC13 +#elif defined(ARDUINO_STEVAL_MKSBOX1V1) /* STEVAL-MKSBOX1V1 */ SPIClass SpiHCI(PC3, PD3, PD1); HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_1S, PD0, PD4, PA8, 1000000, SPI_MODE1); diff --git a/examples/Central/SensorTagButton/SensorTagButton.ino b/examples/Central/SensorTagButton/SensorTagButton.ino index c6377f9f..1831b172 100644 --- a/examples/Central/SensorTagButton/SensorTagButton.ino +++ b/examples/Central/SensorTagButton/SensorTagButton.ino @@ -8,7 +8,7 @@ outputted to the Serial Monitor when one is pressed. The circuit: - - STEVAL-MKSBOX1V1, B-L475E-IOT01A1, B_L4S5I_IOT01A, or a Nucleo board plus the X-NUCLEO-IDB05A2 or the X-NUCLEO-IDB05A1 or the X-NUCLEO-BNRG2A1 + - STEVAL-MKBOXPRO, STEVAL-MKSBOX1V1, B-L475E-IOT01A1, B_L4S5I_IOT01A, or a Nucleo board plus the X-NUCLEO-IDB05A2 or the X-NUCLEO-IDB05A1 or the X-NUCLEO-BNRG2A1 - TI SensorTag This example code is in the public domain. @@ -16,7 +16,16 @@ #include <STM32duinoBLE.h> -#if defined(ARDUINO_STEVAL_MKSBOX1V1) +#if defined(ARDUINO_STEVAL_MKBOXPRO) +/* STEVAL-MKBOXPRO */ +SPIClass SpiHCI(PA7, PA6, PA5); +HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_LP, PA2, PB11, PD4, 1000000, SPI_MODE3); +#if !defined(FAKE_BLELOCALDEVICE) +BLELocalDevice BLEObj(&HCISpiTransport); +BLELocalDevice& BLE = BLEObj; +#endif +const int buttonPin = PC13; // set buttonPin to digital pin PC13 +#elif defined(ARDUINO_STEVAL_MKSBOX1V1) /* STEVAL-MKSBOX1V1 */ SPIClass SpiHCI(PC3, PD3, PD1); HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_1S, PD0, PD4, PA8, 1000000, SPI_MODE1); diff --git a/examples/Peripheral/CallbackLED/CallbackLED.ino b/examples/Peripheral/CallbackLED/CallbackLED.ino index 28bf40a8..363d804b 100644 --- a/examples/Peripheral/CallbackLED/CallbackLED.ino +++ b/examples/Peripheral/CallbackLED/CallbackLED.ino @@ -6,7 +6,7 @@ library are used. The circuit: - - STEVAL-MKSBOX1V1, B-L475E-IOT01A1, B_L4S5I_IOT01A, or a Nucleo board plus the X-NUCLEO-IDB05A2 or the X-NUCLEO-IDB05A1 or the X-NUCLEO-BNRG2A1 + - STEVAL-MKBOXPRO, STEVAL-MKSBOX1V1, B-L475E-IOT01A1, B_L4S5I_IOT01A, or a Nucleo board plus the X-NUCLEO-IDB05A2 or the X-NUCLEO-IDB05A1 or the X-NUCLEO-BNRG2A1 You can use a generic BLE central app, like LightBlue (iOS and Android) or nRF Connect (Android), to interact with the services and characteristics @@ -17,7 +17,16 @@ #include <STM32duinoBLE.h> -#if defined(ARDUINO_STEVAL_MKSBOX1V1) +#if defined(ARDUINO_STEVAL_MKBOXPRO) +/* STEVAL-MKBOXPRO */ +SPIClass SpiHCI(PA7, PA6, PA5); +HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_LP, PA2, PB11, PD4, 1000000, SPI_MODE3); +#if !defined(FAKE_BLELOCALDEVICE) +BLELocalDevice BLEObj(&HCISpiTransport); +BLELocalDevice& BLE = BLEObj; +#endif +const int buttonPin = PC13; // set buttonPin to digital pin PC13 +#elif defined(ARDUINO_STEVAL_MKSBOX1V1) /* STEVAL-MKSBOX1V1 */ SPIClass SpiHCI(PC3, PD3, PD1); HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_1S, PD0, PD4, PA8, 1000000, SPI_MODE1); diff --git a/examples/Peripheral/LED/LED.ino b/examples/Peripheral/LED/LED.ino index 2ea0e5ae..48de79d7 100644 --- a/examples/Peripheral/LED/LED.ino +++ b/examples/Peripheral/LED/LED.ino @@ -5,7 +5,7 @@ characteristic to control an LED. The circuit: - - STEVAL-MKSBOX1V1, B-L475E-IOT01A1, B_L4S5I_IOT01A, or a Nucleo board plus the X-NUCLEO-IDB05A2 or the X-NUCLEO-IDB05A1 or the X-NUCLEO-BNRG2A1 + - STEVAL-MKBOXPRO, STEVAL-MKSBOX1V1, B-L475E-IOT01A1, B_L4S5I_IOT01A, or a Nucleo board plus the X-NUCLEO-IDB05A2 or the X-NUCLEO-IDB05A1 or the X-NUCLEO-BNRG2A1 You can use a generic BLE central app, like LightBlue (iOS and Android) or nRF Connect (Android), to interact with the services and characteristics @@ -15,7 +15,16 @@ */ #include <STM32duinoBLE.h> -#if defined(ARDUINO_STEVAL_MKSBOX1V1) +#if defined(ARDUINO_STEVAL_MKBOXPRO) +/* STEVAL-MKBOXPRO */ +SPIClass SpiHCI(PA7, PA6, PA5); +HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_LP, PA2, PB11, PD4, 1000000, SPI_MODE3); +#if !defined(FAKE_BLELOCALDEVICE) +BLELocalDevice BLEObj(&HCISpiTransport); +BLELocalDevice& BLE = BLEObj; +#endif +const int buttonPin = PC13; // set buttonPin to digital pin PC13 +#elif defined(ARDUINO_STEVAL_MKSBOX1V1) /* STEVAL-MKSBOX1V1 */ SPIClass SpiHCI(PC3, PD3, PD1); HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_1S, PD0, PD4, PA8, 1000000, SPI_MODE1); From 69a6b5fa1f2785d67e52d7e9b03771e215e437b6 Mon Sep 17 00:00:00 2001 From: Alexandre Bourdiol <alexandre.bourdiol@st.com> Date: Tue, 30 Aug 2022 13:50:51 +0200 Subject: [PATCH 091/226] fix: Regenrate BLE patches prepare Update STM32Cube_FW Prepare update to version 1.14.0 Signed-off-by: Alexandre Bourdiol <alexandre.bourdiol@st.com> --- ...nd-adapt-STM32Cube_FW-sources-for-ST.patch | 208 ++++++++--------- ...imeout-when-waiting-for-the-cmd_resp.patch | 11 +- ...Added-support-for-custom-app_conf.h.patch} | 85 ++++--- .../0004-Stub-OutputDbgTrace-function.patch | 209 ------------------ 4 files changed, 153 insertions(+), 360 deletions(-) rename extras/STM32Cube_FW/{0003-Added-support-for-custom-app_conf.h-35.patch => 0003-Added-support-for-custom-app_conf.h.patch} (61%) delete mode 100644 extras/STM32Cube_FW/0004-Stub-OutputDbgTrace-function.patch diff --git a/extras/STM32Cube_FW/0001-chore-clean-up-and-adapt-STM32Cube_FW-sources-for-ST.patch b/extras/STM32Cube_FW/0001-chore-clean-up-and-adapt-STM32Cube_FW-sources-for-ST.patch index 3ae29806..bbc8ba44 100644 --- a/extras/STM32Cube_FW/0001-chore-clean-up-and-adapt-STM32Cube_FW-sources-for-ST.patch +++ b/extras/STM32Cube_FW/0001-chore-clean-up-and-adapt-STM32Cube_FW-sources-for-ST.patch @@ -1,29 +1,28 @@ -From 6fcfc029ba21a3674456a12032720bff6ecfe27d Mon Sep 17 00:00:00 2001 +From 1c3ca9f22842e3ae283d3e979a5f38a195d8d4ee Mon Sep 17 00:00:00 2001 From: Alexandre Bourdiol <alexandre.bourdiol@st.com> -Date: Mon, 6 Dec 2021 11:08:32 +0100 -Subject: [PATCH 1/4] chore: clean up and adapt STM32Cube_FW sources for +Date: Tue, 30 Aug 2022 11:28:41 +0200 +Subject: [PATCH 1/3] chore: clean up and adapt STM32Cube_FW sources for STM32duino -Signed-off-by: Frederic Pillon <frederic.pillon@st.com> Signed-off-by: Alexandre Bourdiol <alexandre.bourdiol@st.com> --- - src/utility/STM32Cube_FW/app_conf_default.h | 422 +------------------ + src/utility/STM32Cube_FW/app_conf_default.h | 428 +------------------ src/utility/STM32Cube_FW/ble_bufsize.h | 13 +- src/utility/STM32Cube_FW/hw.h | 28 +- src/utility/STM32Cube_FW/hw_ipcc.c | 184 +------- src/utility/STM32Cube_FW/mbox_def.h | 34 -- src/utility/STM32Cube_FW/shci.c | 40 +- - src/utility/STM32Cube_FW/shci.h | 47 +-- + src/utility/STM32Cube_FW/shci.h | 47 +- src/utility/STM32Cube_FW/shci_tl.c | 19 +- src/utility/STM32Cube_FW/stm32_wpan_common.h | 39 +- src/utility/STM32Cube_FW/stm_list.c | 11 +- src/utility/STM32Cube_FW/stm_list.h | 4 +- src/utility/STM32Cube_FW/tl.h | 33 -- src/utility/STM32Cube_FW/tl_mbox.c | 144 +------ - 13 files changed, 94 insertions(+), 924 deletions(-) + 13 files changed, 91 insertions(+), 933 deletions(-) diff --git a/src/utility/STM32Cube_FW/app_conf_default.h b/src/utility/STM32Cube_FW/app_conf_default.h -index 7ebc65a..4f300e0 100644 +index c63c66e..54f824a 100644 --- a/src/utility/STM32Cube_FW/app_conf_default.h +++ b/src/utility/STM32Cube_FW/app_conf_default.h @@ -1,4 +1,3 @@ @@ -53,21 +52,21 @@ index 7ebc65a..4f300e0 100644 -/** - * Define Secure Connections Support - */ --#define CFG_SECURE_NOT_SUPPORTED (0x00) --#define CFG_SECURE_OPTIONAL (0x01) --#define CFG_SECURE_MANDATORY (0x02) +-#define CFG_SECURE_NOT_SUPPORTED (0x00) +-#define CFG_SECURE_OPTIONAL (0x01) +-#define CFG_SECURE_MANDATORY (0x02) - --#define CFG_SC_SUPPORT CFG_SECURE_OPTIONAL +-#define CFG_SC_SUPPORT CFG_SECURE_OPTIONAL - -/** - * Define Keypress Notification Support - */ --#define CFG_KEYPRESS_NOT_SUPPORTED (0x00) --#define CFG_KEYPRESS_SUPPORTED (0x01) +-#define CFG_KEYPRESS_NOT_SUPPORTED (0x00) +-#define CFG_KEYPRESS_SUPPORTED (0x01) +/**< generic parameters ******************************************************/ +/* HCI related defines */ --#define CFG_KEYPRESS_NOTIFICATION_SUPPORT CFG_KEYPRESS_NOT_SUPPORTED +-#define CFG_KEYPRESS_NOTIFICATION_SUPPORT CFG_KEYPRESS_NOT_SUPPORTED +#define ACI_HAL_SET_TX_POWER_LEVEL 0xFC0F +#define ACI_WRITE_CONFIG_DATA_OPCODE 0xFC0C +#define ACI_READ_CONFIG_DATA_OPCODE 0xFC0D @@ -141,7 +140,7 @@ index 7ebc65a..4f300e0 100644 * BLE Stack @@ -152,13 +93,15 @@ * Prepare Write List size in terms of number of packet - * This parameter is ignored by the CPU2 when CFG_BLE_OPTIONS is set to 1" + * This parameter is ignored by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set */ -#define CFG_BLE_PREPARE_WRITE_LIST_SIZE BLE_PREP_WRITE_X_ATT(CFG_BLE_MAX_ATT_MTU) +// #define CFG_BLE_PREPARE_WRITE_LIST_SIZE BLE_PREP_WRITE_X_ATT(CFG_BLE_MAX_ATT_MTU) @@ -149,7 +148,7 @@ index 7ebc65a..4f300e0 100644 /** * Number of allocated memory blocks - * This parameter is overwritten by the CPU2 with an hardcoded optimal value when the parameter when CFG_BLE_OPTIONS is set to 1 + * This parameter is overwritten by the CPU2 with an hardcoded optimal value when the parameter CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set */ -#define CFG_BLE_MBLOCK_COUNT (BLE_MBLOCKS_CALC(CFG_BLE_PREPARE_WRITE_LIST_SIZE, CFG_BLE_MAX_ATT_MTU, CFG_BLE_NUM_LINK)) +// #define CFG_BLE_MBLOCK_COUNT (BLE_MBLOCKS_CALC(CFG_BLE_PREPARE_WRITE_LIST_SIZE, CFG_BLE_MAX_ATT_MTU, CFG_BLE_NUM_LINK)) @@ -157,18 +156,18 @@ index 7ebc65a..4f300e0 100644 /** * Enable or disable the Extended Packet length feature. Valid values are 0 or 1. -@@ -236,7 +179,7 @@ +@@ -241,7 +184,7 @@ * 0: LE Power Class 2-3 * other bits: reserved (shall be set to 0) */ --#define CFG_BLE_OPTIONS (SHCI_C2_BLE_INIT_OPTIONS_LL_HOST | SHCI_C2_BLE_INIT_OPTIONS_WITH_SVC_CHANGE_DESC | SHCI_C2_BLE_INIT_OPTIONS_DEVICE_NAME_RW | SHCI_C2_BLE_INIT_OPTIONS_NO_EXT_ADV | SHCI_C2_BLE_INIT_OPTIONS_NO_CS_ALGO2 | SHCI_C2_BLE_INIT_OPTIONS_POWER_CLASS_2_3) +-#define CFG_BLE_OPTIONS (SHCI_C2_BLE_INIT_OPTIONS_LL_HOST | SHCI_C2_BLE_INIT_OPTIONS_WITH_SVC_CHANGE_DESC | SHCI_C2_BLE_INIT_OPTIONS_DEVICE_NAME_RW | SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV | SHCI_C2_BLE_INIT_OPTIONS_CS_ALGO2 | SHCI_C2_BLE_INIT_OPTIONS_POWER_CLASS_2_3) +#define CFG_BLE_OPTIONS (SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY) #define CFG_BLE_MAX_COC_INITIATOR_NBR (32) -@@ -256,334 +199,5 @@ +@@ -291,340 +234,5 @@ - #define CFG_BLE_RX_MODEL_CONFIG SHCI_C2_BLE_INIT_RX_MODEL_AGC_RSSI_LEGACY + #define CFG_BLE_RX_PATH_COMPENS (0) -/****************************************************************************** - * Transport Layer @@ -206,7 +205,7 @@ index 7ebc65a..4f300e0 100644 -/** - * Select UART interfaces - */ --#define CFG_UART_GUI hw_uart1 +-#define CFG_UART_GUI hw_uart1 -#define CFG_DEBUG_TRACE_UART 0 -/****************************************************************************** - * USB interface @@ -276,10 +275,10 @@ index 7ebc65a..4f300e0 100644 - * It divides the RTC CLK by 16 - */ - --#define CFG_RTCCLK_DIV (16) --#define CFG_RTC_WUCKSEL_DIVIDER (0) --#define CFG_RTC_ASYNCH_PRESCALER (0x0F) --#define CFG_RTC_SYNCH_PRESCALER (0x7FFF) +-#define CFG_RTCCLK_DIV (16) +-#define CFG_RTC_WUCKSEL_DIVIDER (0) +-#define CFG_RTC_ASYNCH_PRESCALER (0x0F) +-#define CFG_RTC_SYNCH_PRESCALER (0x7FFF) - -#else - @@ -370,7 +369,7 @@ index 7ebc65a..4f300e0 100644 -#if (CFG_DEBUG_TRACE != 0) -#undef CFG_LPM_SUPPORTED -#undef CFG_DEBUGGER_SUPPORTED --#define CFG_LPM_SUPPORTED 0 +-#define CFG_LPM_SUPPORTED 0 -#define CFG_DEBUGGER_SUPPORTED 1 -#endif - @@ -408,7 +407,7 @@ index 7ebc65a..4f300e0 100644 - * Only Used if DBG_TRACE_USE_CIRCULAR_QUEUE is defined - */ -#define DBG_TRACE_MSG_QUEUE_SIZE 4096 --#define MAX_DBG_TRACE_MSG_SIZE 1024 +-#define MAX_DBG_TRACE_MSG_SIZE 1024 - -/* USER CODE BEGIN Defines */ -#define CFG_LED_SUPPORTED 1 @@ -433,31 +432,31 @@ index 7ebc65a..4f300e0 100644 -/**< Add in that list all tasks that may send a ACI/HCI command */ -typedef enum -{ -- CFG_TASK_BLE_HCI_CMD_ID, -- CFG_TASK_SYS_HCI_CMD_ID, -- CFG_TASK_HCI_ACL_DATA_ID, -- CFG_TASK_SYS_LOCAL_CMD_ID, -- CFG_TASK_TX_TO_HOST_ID, -- /* USER CODE BEGIN CFG_Task_Id_With_HCI_Cmd_t */ -- CFG_TASK_SW1_BUTTON_PUSHED_ID, -- CFG_TASK_SW2_BUTTON_PUSHED_ID, -- CFG_TASK_SW3_BUTTON_PUSHED_ID, -- /* USER CODE END CFG_Task_Id_With_HCI_Cmd_t */ -- CFG_LAST_TASK_ID_WITH_HCICMD, /**< Shall be LAST in the list */ +- CFG_TASK_BLE_HCI_CMD_ID, +- CFG_TASK_SYS_HCI_CMD_ID, +- CFG_TASK_HCI_ACL_DATA_ID, +- CFG_TASK_SYS_LOCAL_CMD_ID, +- CFG_TASK_TX_TO_HOST_ID, +- /* USER CODE BEGIN CFG_Task_Id_With_HCI_Cmd_t */ +- CFG_TASK_SW1_BUTTON_PUSHED_ID, +- CFG_TASK_SW2_BUTTON_PUSHED_ID, +- CFG_TASK_SW3_BUTTON_PUSHED_ID, +- /* USER CODE END CFG_Task_Id_With_HCI_Cmd_t */ +- CFG_LAST_TASK_ID_WITH_HCICMD, /**< Shall be LAST in the list */ -} CFG_Task_Id_With_HCI_Cmd_t; - -/**< Add in that list all tasks that never send a ACI/HCI command */ -typedef enum -{ -- CFG_FIRST_TASK_ID_WITH_NO_HCICMD = CFG_LAST_TASK_ID_WITH_HCICMD - 1, /**< Shall be FIRST in the list */ -- CFG_TASK_SYSTEM_HCI_ASYNCH_EVT_ID, -- /* USER CODE BEGIN CFG_Task_Id_With_NO_HCI_Cmd_t */ +- CFG_FIRST_TASK_ID_WITH_NO_HCICMD = CFG_LAST_TASK_ID_WITH_HCICMD - 1, /**< Shall be FIRST in the list */ +- CFG_TASK_SYSTEM_HCI_ASYNCH_EVT_ID, +- /* USER CODE BEGIN CFG_Task_Id_With_NO_HCI_Cmd_t */ - -- /* USER CODE END CFG_Task_Id_With_NO_HCI_Cmd_t */ -- CFG_LAST_TASK_ID_WITHO_NO_HCICMD /**< Shall be LAST in the list */ +- /* USER CODE END CFG_Task_Id_With_NO_HCI_Cmd_t */ +- CFG_LAST_TASK_ID_WITH_NO_HCICMD /**< Shall be LAST in the list */ -} CFG_Task_Id_With_NO_HCI_Cmd_t; - --#define CFG_TASK_NBR CFG_LAST_TASK_ID_WITHO_NO_HCICMD +-#define CFG_TASK_NBR CFG_LAST_TASK_ID_WITH_NO_HCICMD - -/** - * This is the list of priority required by the application @@ -465,8 +464,10 @@ index 7ebc65a..4f300e0 100644 - */ -typedef enum -{ -- CFG_SCH_PRIO_0, -- CFG_PRIO_NBR, +- CFG_SCH_PRIO_0, +- /* USER CODE BEGIN CFG_SCH_Prio_Id_t */ +- +- /* USER CODE END CFG_SCH_Prio_Id_t */ -} CFG_SCH_Prio_Id_t; - -/** @@ -474,7 +475,10 @@ index 7ebc65a..4f300e0 100644 - */ -typedef enum -{ -- CFG_IDLEEVT_SYSTEM_HCI_CMD_EVT_RSP_ID, +- CFG_IDLEEVT_SYSTEM_HCI_CMD_EVT_RSP_ID, +- /* USER CODE BEGIN CFG_IdleEvt_Id_t */ +- +- /* USER CODE END CFG_IdleEvt_Id_t */ -} CFG_IdleEvt_Id_t; - -/****************************************************************************** @@ -486,11 +490,11 @@ index 7ebc65a..4f300e0 100644 - */ -typedef enum -{ -- CFG_LPM_APP, -- CFG_LPM_APP_BLE, -- /* USER CODE BEGIN CFG_LPM_Id_t */ +- CFG_LPM_APP, +- CFG_LPM_APP_BLE, +- /* USER CODE BEGIN CFG_LPM_Id_t */ - -- /* USER CODE END CFG_LPM_Id_t */ +- /* USER CODE END CFG_LPM_Id_t */ -} CFG_LPM_Id_t; - -/****************************************************************************** @@ -499,10 +503,11 @@ index 7ebc65a..4f300e0 100644 -#define CFG_OTP_BASE_ADDRESS OTP_AREA_BASE - -#define CFG_OTP_END_ADRESS OTP_AREA_END_ADDR - +- #endif /*APP_CONF_H */ + diff --git a/src/utility/STM32Cube_FW/ble_bufsize.h b/src/utility/STM32Cube_FW/ble_bufsize.h -index ba9c4d3..73b7887 100644 +index 0f0f419..247573b 100644 --- a/src/utility/STM32Cube_FW/ble_bufsize.h +++ b/src/utility/STM32Cube_FW/ble_bufsize.h @@ -75,17 +75,24 @@ @@ -586,7 +591,7 @@ index 503fa2c..fcf0451 100644 } #endif diff --git a/src/utility/STM32Cube_FW/hw_ipcc.c b/src/utility/STM32Cube_FW/hw_ipcc.c -index c5a941d..2f4f6cc 100644 +index fd620b8..7b9be81 100644 --- a/src/utility/STM32Cube_FW/hw_ipcc.c +++ b/src/utility/STM32Cube_FW/hw_ipcc.c @@ -18,8 +18,9 @@ @@ -701,7 +706,7 @@ index c5a941d..2f4f6cc 100644 /****************************************************************************** * GENERAL ******************************************************************************/ -@@ -263,8 +222,8 @@ static void HW_IPCC_BLE_AclDataEvtHandler( void ) +@@ -264,8 +223,8 @@ static void HW_IPCC_BLE_AclDataEvtHandler( void ) return; } @@ -712,7 +717,7 @@ index c5a941d..2f4f6cc 100644 /****************************************************************************** * SYSTEM -@@ -302,56 +261,8 @@ static void HW_IPCC_SYS_EvtHandler( void ) +@@ -303,56 +262,8 @@ static void HW_IPCC_SYS_EvtHandler( void ) return; } @@ -771,7 +776,7 @@ index c5a941d..2f4f6cc 100644 /****************************************************************************** * THREAD -@@ -423,9 +334,9 @@ static void HW_IPCC_THREAD_CliNotEvtHandler( void ) +@@ -424,9 +335,9 @@ static void HW_IPCC_THREAD_CliNotEvtHandler( void ) return; } @@ -784,7 +789,7 @@ index c5a941d..2f4f6cc 100644 #endif /* THREAD_WB */ -@@ -547,74 +458,6 @@ void HW_IPCC_LLD_BLE_SendRspAck( void ) +@@ -548,74 +459,6 @@ void HW_IPCC_LLD_BLE_SendRspAck( void ) #endif /* LLD_BLE_WB */ @@ -859,7 +864,7 @@ index c5a941d..2f4f6cc 100644 /****************************************************************************** * MEMORY MANAGER ******************************************************************************/ -@@ -665,4 +508,5 @@ static void HW_IPCC_TRACES_EvtHandler( void ) +@@ -666,4 +509,5 @@ static void HW_IPCC_TRACES_EvtHandler( void ) return; } @@ -867,10 +872,10 @@ index c5a941d..2f4f6cc 100644 +__WEAK void HW_IPCC_TRACES_EvtNot( void ){}; +#endif /* STM32WBxx */ diff --git a/src/utility/STM32Cube_FW/mbox_def.h b/src/utility/STM32Cube_FW/mbox_def.h -index 06536d3..c898e52 100644 +index 68b71f9..0c974f8 100644 --- a/src/utility/STM32Cube_FW/mbox_def.h +++ b/src/utility/STM32Cube_FW/mbox_def.h -@@ -105,12 +105,6 @@ extern "C" { +@@ -106,12 +106,6 @@ extern "C" { uint8_t *m0cmd_buffer; } MB_BleLldTable_t; @@ -883,7 +888,7 @@ index 06536d3..c898e52 100644 /** * msg * [0:7] = cmd/evt -@@ -138,13 +132,6 @@ extern "C" { +@@ -139,13 +133,6 @@ extern "C" { uint8_t *traces_queue; } MB_TracesTable_t; @@ -897,7 +902,7 @@ index 06536d3..c898e52 100644 typedef struct { MB_DeviceInfoTable_t *p_device_info_table; -@@ -153,8 +140,6 @@ extern "C" { +@@ -154,8 +141,6 @@ extern "C" { MB_SysTable_t *p_sys_table; MB_MemManagerTable_t *p_mem_manager_table; MB_TracesTable_t *p_traces_table; @@ -906,7 +911,7 @@ index 06536d3..c898e52 100644 MB_LldTestsTable_t *p_lld_tests_table; MB_BleLldTable_t *p_ble_lld_table; } MB_RefTable_t; -@@ -198,15 +183,6 @@ typedef struct +@@ -199,15 +184,6 @@ typedef struct * | | * |<---HW_IPCC_SYSTEM_EVENT_CHANNEL-----------------| * | | @@ -922,7 +927,7 @@ index 06536d3..c898e52 100644 * | (THREAD) | * |----HW_IPCC_THREAD_OT_CMD_RSP_CHANNEL----------->| * | | -@@ -230,11 +206,6 @@ typedef struct +@@ -231,11 +207,6 @@ typedef struct * | | * |<---HW_IPCC_BLE_LLD_M0_CMD_CHANNEL---------------| * | | @@ -934,7 +939,7 @@ index 06536d3..c898e52 100644 * | (BUFFER) | * |----HW_IPCC_MM_RELEASE_BUFFER_CHANNE------------>| * | | -@@ -252,8 +223,6 @@ typedef struct +@@ -253,8 +224,6 @@ typedef struct #define HW_IPCC_BLE_CMD_CHANNEL LL_IPCC_CHANNEL_1 #define HW_IPCC_SYSTEM_CMD_RSP_CHANNEL LL_IPCC_CHANNEL_2 #define HW_IPCC_THREAD_OT_CMD_RSP_CHANNEL LL_IPCC_CHANNEL_3 @@ -943,7 +948,7 @@ index 06536d3..c898e52 100644 #define HW_IPCC_MM_RELEASE_BUFFER_CHANNEL LL_IPCC_CHANNEL_4 #define HW_IPCC_THREAD_CLI_CMD_CHANNEL LL_IPCC_CHANNEL_5 #define HW_IPCC_LLDTESTS_CLI_CMD_CHANNEL LL_IPCC_CHANNEL_5 -@@ -265,8 +234,6 @@ typedef struct +@@ -266,8 +235,6 @@ typedef struct #define HW_IPCC_BLE_EVENT_CHANNEL LL_IPCC_CHANNEL_1 #define HW_IPCC_SYSTEM_EVENT_CHANNEL LL_IPCC_CHANNEL_2 #define HW_IPCC_THREAD_NOTIFICATION_ACK_CHANNEL LL_IPCC_CHANNEL_3 @@ -952,7 +957,7 @@ index 06536d3..c898e52 100644 #define HW_IPCC_LLDTESTS_M0_CMD_CHANNEL LL_IPCC_CHANNEL_3 #define HW_IPCC_BLE_LLD_M0_CMD_CHANNEL LL_IPCC_CHANNEL_3 #define HW_IPCC_TRACES_CHANNEL LL_IPCC_CHANNEL_4 -@@ -274,6 +241,5 @@ typedef struct +@@ -275,6 +242,5 @@ typedef struct #define HW_IPCC_LLDTESTS_CLI_RSP_CHANNEL LL_IPCC_CHANNEL_5 #define HW_IPCC_BLE_LLD_CLI_RSP_CHANNEL LL_IPCC_CHANNEL_5 #define HW_IPCC_BLE_LLD_RSP_CHANNEL LL_IPCC_CHANNEL_5 @@ -960,7 +965,7 @@ index 06536d3..c898e52 100644 #endif /*__MBOX_H */ diff --git a/src/utility/STM32Cube_FW/shci.c b/src/utility/STM32Cube_FW/shci.c -index 301db76..bd7bb3a 100644 +index 472a108..a847522 100644 --- a/src/utility/STM32Cube_FW/shci.c +++ b/src/utility/STM32Cube_FW/shci.c @@ -16,7 +16,7 @@ @@ -1022,14 +1027,14 @@ index 301db76..bd7bb3a 100644 SHCI_CmdStatus_t SHCI_C2_Reinit( void ) { /** -@@ -739,3 +703,5 @@ SHCI_CmdStatus_t SHCI_GetWirelessFwInfo( WirelessFwInfo_t* pWirelessInfo ) +@@ -739,4 +703,4 @@ SHCI_CmdStatus_t SHCI_GetWirelessFwInfo( WirelessFwInfo_t* pWirelessInfo ) return (SHCI_Success); } +- +#endif /* STM32WBxx */ -+ diff --git a/src/utility/STM32Cube_FW/shci.h b/src/utility/STM32Cube_FW/shci.h -index c08f056..9449c22 100644 +index 102089e..6b6ffd1 100644 --- a/src/utility/STM32Cube_FW/shci.h +++ b/src/utility/STM32Cube_FW/shci.h @@ -49,7 +49,6 @@ extern "C" { @@ -1049,7 +1054,7 @@ index c08f056..9449c22 100644 * section could be written in Flash/NVM * StartAddress : Start address of the section that has been modified * Size : Size (in bytes) of the section that has been modified -@@ -214,9 +213,7 @@ extern "C" { +@@ -216,9 +215,7 @@ extern "C" { SHCI_OCF_C2_FLASH_STORE_DATA, SHCI_OCF_C2_FLASH_ERASE_DATA, SHCI_OCF_C2_RADIO_ALLOW_LOW_POWER, @@ -1059,7 +1064,7 @@ index c08f056..9449c22 100644 SHCI_OCF_C2_LLD_TESTS_INIT, SHCI_OCF_C2_EXTPA_CONFIG, SHCI_OCF_C2_SET_FLASH_ACTIVITY_CONTROL, -@@ -614,8 +611,6 @@ extern "C" { +@@ -648,8 +645,6 @@ extern "C" { { uint8_t thread_config; uint8_t ble_config; @@ -1068,7 +1073,7 @@ index c08f056..9449c22 100644 } SHCI_C2_DEBUG_TracesConfig_t; typedef PACKED_STRUCT -@@ -674,8 +669,6 @@ extern "C" { +@@ -713,8 +708,6 @@ extern "C" { { BLE_ENABLE, THREAD_ENABLE, @@ -1077,7 +1082,7 @@ index c08f056..9449c22 100644 } SHCI_C2_CONCURRENT_Mode_Param_t; /** No response parameters*/ -@@ -698,18 +691,13 @@ extern "C" { +@@ -737,18 +730,13 @@ extern "C" { { BLE_IP, THREAD_IP, @@ -1096,7 +1101,7 @@ index c08f056..9449c22 100644 #define SHCI_OPCODE_C2_LLD_TESTS_INIT (( SHCI_OGF << 10) + SHCI_OCF_C2_LLD_TESTS_INIT) #define SHCI_OPCODE_C2_BLE_LLD_INIT (( SHCI_OGF << 10) + SHCI_OCF_C2_BLE_LLD_INIT) -@@ -817,7 +805,7 @@ extern "C" { +@@ -856,7 +844,7 @@ extern "C" { #define FUS_DEVICE_INFO_TABLE_VALIDITY_KEYWORD (0xA94656B9) /* @@ -1105,8 +1110,8 @@ index c08f056..9449c22 100644 * MB_WirelessFwInfoTable_t.This structure contains 4 fields (Version,MemorySize, Stack_info and a reserved part) * each of those coded on 32 bits as shown on the table below: * -@@ -870,9 +858,6 @@ extern "C" { - #define INFO_STACK_TYPE_BLE_BEACON 0x04 +@@ -912,9 +900,6 @@ extern "C" { + #define INFO_STACK_TYPE_BLE_HCI_EXT_ADV 0x07 #define INFO_STACK_TYPE_THREAD_FTD 0x10 #define INFO_STACK_TYPE_THREAD_MTD 0x11 -#define INFO_STACK_TYPE_ZIGBEE_FFD 0x30 @@ -1115,7 +1120,7 @@ index c08f056..9449c22 100644 #define INFO_STACK_TYPE_BLE_THREAD_FTD_STATIC 0x50 #define INFO_STACK_TYPE_BLE_THREAD_FTD_DYAMIC 0x51 #define INFO_STACK_TYPE_802154_LLD_TESTS 0x60 -@@ -881,12 +866,7 @@ extern "C" { +@@ -923,12 +908,7 @@ extern "C" { #define INFO_STACK_TYPE_BLE_LLD_TESTS 0x63 #define INFO_STACK_TYPE_BLE_RLV 0x64 #define INFO_STACK_TYPE_802154_RLV 0x65 @@ -1128,7 +1133,7 @@ index c08f056..9449c22 100644 typedef struct { /** -@@ -1060,7 +1040,7 @@ typedef struct { +@@ -1102,7 +1082,7 @@ typedef struct { * @brief Starts the LLD tests CLI * * @param param_size : Nb of bytes @@ -1137,7 +1142,7 @@ index c08f056..9449c22 100644 * @retval Status */ SHCI_CmdStatus_t SHCI_C2_LLDTESTS_Init( uint8_t param_size, uint8_t * p_param ); -@@ -1070,19 +1050,10 @@ typedef struct { +@@ -1112,19 +1092,10 @@ typedef struct { * @brief Starts the LLD tests BLE * * @param param_size : Nb of bytes @@ -1146,7 +1151,7 @@ index c08f056..9449c22 100644 * @retval Status */ SHCI_CmdStatus_t SHCI_C2_BLE_LLD_Init( uint8_t param_size, uint8_t * p_param ); -- +- - /** - * SHCI_C2_ZIGBEE_Init - * @brief Starts the Zigbee Stack @@ -1155,10 +1160,10 @@ index c08f056..9449c22 100644 - * @retval Status - */ - SHCI_CmdStatus_t SHCI_C2_ZIGBEE_Init( void ); - + /** * SHCI_C2_DEBUG_Init -@@ -1158,16 +1129,6 @@ typedef struct { +@@ -1200,16 +1171,6 @@ typedef struct { */ SHCI_CmdStatus_t SHCI_C2_RADIO_AllowLowPower( SHCI_C2_FLASH_Ip_t Ip,uint8_t FlagRadioLowPowerOn); @@ -1176,7 +1181,7 @@ index c08f056..9449c22 100644 * SHCI_GetWirelessFwInfo * @brief This function read back the informations relative to the wireless binary loaded. diff --git a/src/utility/STM32Cube_FW/shci_tl.c b/src/utility/STM32Cube_FW/shci_tl.c -index 449b8b1..ef403aa 100644 +index ddb3a02..d1a448d 100644 --- a/src/utility/STM32Cube_FW/shci_tl.c +++ b/src/utility/STM32Cube_FW/shci_tl.c @@ -16,12 +16,13 @@ @@ -1215,12 +1220,12 @@ index 449b8b1..ef403aa 100644 /* Private functions ---------------------------------------------------------*/ static void TlInit( TL_CmdPacket_t * p_cmdbuffer ) { -@@ -252,3 +267,5 @@ __WEAK void shci_cmd_resp_release(uint32_t flag) +@@ -252,4 +267,4 @@ __WEAK void shci_cmd_resp_release(uint32_t flag) return; } +- +#endif /* STM32WBxx */ -+ diff --git a/src/utility/STM32Cube_FW/stm32_wpan_common.h b/src/utility/STM32Cube_FW/stm32_wpan_common.h index b47b804..5a2b2a5 100644 --- a/src/utility/STM32Cube_FW/stm32_wpan_common.h @@ -1280,7 +1285,7 @@ index b47b804..5a2b2a5 100644 #ifdef __cplusplus } diff --git a/src/utility/STM32Cube_FW/stm_list.c b/src/utility/STM32Cube_FW/stm_list.c -index 69c8c06..3dea751 100644 +index 4c92864..77dec64 100644 --- a/src/utility/STM32Cube_FW/stm_list.c +++ b/src/utility/STM32Cube_FW/stm_list.c @@ -16,13 +16,13 @@ @@ -1299,7 +1304,7 @@ index 69c8c06..3dea751 100644 +#include "stm32_wpan_common.h" /****************************************************************************** - * Function Definitions + * Function Definitions @@ -33,10 +33,10 @@ void LST_init_head (tListNode * listHead) listHead->prev = listHead; } @@ -1313,12 +1318,11 @@ index 69c8c06..3dea751 100644 primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ -@@ -205,3 +205,4 @@ void LST_get_prev_node (tListNode * ref_node, tListNode ** node) +@@ -204,3 +204,4 @@ void LST_get_prev_node (tListNode * ref_node, tListNode ** node) + __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ } - +#endif /* STM32WBxx */ -\ No newline at end of file diff --git a/src/utility/STM32Cube_FW/stm_list.h b/src/utility/STM32Cube_FW/stm_list.h index b7c3254..769c211 100644 --- a/src/utility/STM32Cube_FW/stm_list.h @@ -1342,10 +1346,10 @@ index b7c3254..769c211 100644 void LST_insert_head (tListNode * listHead, tListNode * node); diff --git a/src/utility/STM32Cube_FW/tl.h b/src/utility/STM32Cube_FW/tl.h -index cb27246..16de7f1 100644 +index 2124d26..678769c 100644 --- a/src/utility/STM32Cube_FW/tl.h +++ b/src/utility/STM32Cube_FW/tl.h -@@ -198,19 +198,6 @@ typedef struct +@@ -199,19 +199,6 @@ typedef struct uint8_t *p_BleLldM0CmdBuffer; } TL_BLE_LLD_Config_t; @@ -1365,7 +1369,7 @@ index cb27246..16de7f1 100644 /** * @brief Contain the BLE HCI Init Configuration * @{ -@@ -304,26 +291,6 @@ void TL_MM_EvtDone( TL_EvtPacket_t * hcievt ); +@@ -305,26 +292,6 @@ void TL_MM_EvtDone( TL_EvtPacket_t * hcievt ); void TL_TRACES_Init( void ); void TL_TRACES_EvtReceived( TL_EvtPacket_t * hcievt ); @@ -1393,7 +1397,7 @@ index cb27246..16de7f1 100644 } /* extern "C" */ #endif diff --git a/src/utility/STM32Cube_FW/tl_mbox.c b/src/utility/STM32Cube_FW/tl_mbox.c -index 148bcb1..709f5d2 100644 +index 4112429..a9abb18 100644 --- a/src/utility/STM32Cube_FW/tl_mbox.c +++ b/src/utility/STM32Cube_FW/tl_mbox.c @@ -16,6 +16,7 @@ @@ -1431,7 +1435,7 @@ index 148bcb1..709f5d2 100644 HW_IPCC_Init(); return; -@@ -451,139 +448,6 @@ void TL_BLE_LLD_SendRspAck( void ) +@@ -452,139 +449,6 @@ void TL_BLE_LLD_SendRspAck( void ) } #endif /* BLE_LLD_WB */ @@ -1571,12 +1575,12 @@ index 148bcb1..709f5d2 100644 /****************************************************************************** * MEMORY MANAGER ******************************************************************************/ -@@ -845,3 +709,5 @@ static void OutputDbgTrace(TL_MB_PacketType_t packet_type, uint8_t* buffer) +@@ -846,4 +710,4 @@ static void OutputDbgTrace(TL_MB_PacketType_t packet_type, uint8_t* buffer) return; } -+ +- +#endif /* STM32WBxx */ -- -2.31.1.windows.1 +2.33.0.windows.1 diff --git a/extras/STM32Cube_FW/0002-fix-include-a-timeout-when-waiting-for-the-cmd_resp.patch b/extras/STM32Cube_FW/0002-fix-include-a-timeout-when-waiting-for-the-cmd_resp.patch index c4a83d6e..326b767e 100644 --- a/extras/STM32Cube_FW/0002-fix-include-a-timeout-when-waiting-for-the-cmd_resp.patch +++ b/extras/STM32Cube_FW/0002-fix-include-a-timeout-when-waiting-for-the-cmd_resp.patch @@ -1,16 +1,15 @@ -From ac18897f0f9b87bb3196efb93ef47ccaaa0eff64 Mon Sep 17 00:00:00 2001 +From 979f153a4e6d5d616ddea616bcd732e32cb1773c Mon Sep 17 00:00:00 2001 From: Alexandre Bourdiol <alexandre.bourdiol@st.com> -Date: Mon, 6 Dec 2021 11:18:02 +0100 -Subject: [PATCH 2/4] fix: include a timeout when waiting for the cmd_resp +Date: Tue, 30 Aug 2022 13:19:36 +0200 +Subject: [PATCH 2/3] fix: include a timeout when waiting for the cmd_resp -Signed-off-by: Francois Ramu <francois.ramu@st.com> Signed-off-by: Alexandre Bourdiol <alexandre.bourdiol@st.com> --- src/utility/STM32Cube_FW/shci_tl.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/utility/STM32Cube_FW/shci_tl.c b/src/utility/STM32Cube_FW/shci_tl.c -index ef403aa..6cccc5d 100644 +index d1a448d..678de84 100644 --- a/src/utility/STM32Cube_FW/shci_tl.c +++ b/src/utility/STM32Cube_FW/shci_tl.c @@ -20,6 +20,8 @@ @@ -40,5 +39,5 @@ index ef403aa..6cccc5d 100644 } -- -2.31.1.windows.1 +2.33.0.windows.1 diff --git a/extras/STM32Cube_FW/0003-Added-support-for-custom-app_conf.h-35.patch b/extras/STM32Cube_FW/0003-Added-support-for-custom-app_conf.h.patch similarity index 61% rename from extras/STM32Cube_FW/0003-Added-support-for-custom-app_conf.h-35.patch rename to extras/STM32Cube_FW/0003-Added-support-for-custom-app_conf.h.patch index 268523d5..33b69e55 100644 --- a/extras/STM32Cube_FW/0003-Added-support-for-custom-app_conf.h-35.patch +++ b/extras/STM32Cube_FW/0003-Added-support-for-custom-app_conf.h.patch @@ -1,14 +1,15 @@ -From a771c9e9a12d085fc240a45f68ca5aafb8b42006 Mon Sep 17 00:00:00 2001 +From d3ae98b9073e5f1e48efb32b1ef4d318814228fe Mon Sep 17 00:00:00 2001 From: Alexandre Bourdiol <alexandre.bourdiol@st.com> -Date: Mon, 6 Dec 2021 18:59:38 +0100 -Subject: [PATCH 3/4] Added support for custom app_conf.h (#35) +Date: Tue, 30 Aug 2022 13:31:31 +0200 +Subject: [PATCH 3/3] Added support for custom app_conf.h +Signed-off-by: Alexandre Bourdiol <alexandre.bourdiol@st.com> --- - src/utility/STM32Cube_FW/app_conf_default.h | 75 ++++++++++++++------- - 1 file changed, 49 insertions(+), 26 deletions(-) + src/utility/STM32Cube_FW/app_conf_default.h | 71 ++++++++++++++------- + 1 file changed, 47 insertions(+), 24 deletions(-) diff --git a/src/utility/STM32Cube_FW/app_conf_default.h b/src/utility/STM32Cube_FW/app_conf_default.h -index 4f300e0..9f8e085 100644 +index 54f824a..91672ac 100644 --- a/src/utility/STM32Cube_FW/app_conf_default.h +++ b/src/utility/STM32Cube_FW/app_conf_default.h @@ -1,8 +1,8 @@ @@ -47,34 +48,29 @@ index 4f300e0..9f8e085 100644 /****************************************************************************** * BLE Stack -@@ -53,32 +52,41 @@ +@@ -53,13 +52,17 @@ * Maximum number of simultaneous connections that the device will support. * Valid values are from 1 to 8 */ --#define CFG_BLE_NUM_LINK 2 +-#define CFG_BLE_NUM_LINK 8 +#ifndef CFG_BLE_NUM_LINK -+ #define CFG_BLE_NUM_LINK 2 ++ #define CFG_BLE_NUM_LINK 8 +#endif /** * Maximum number of Services that can be stored in the GATT database. -- * Note that the GAP and GATT services are automatically added so this parameter should be 2 plus the number of user services -+ * Note that the GAP and GATT services are automatically added so this parameter should be 2 plus the number of user -+ * services + * Note that the GAP and GATT services are automatically added so this parameter should be 2 plus the number of user services */ +-#define CFG_BLE_NUM_GATT_SERVICES 8 +#ifndef CFG_BLE_NUM_GATT_SERVICES - #define CFG_BLE_NUM_GATT_SERVICES 8 ++ #define CFG_BLE_NUM_GATT_SERVICES 8 +#endif /** * Maximum number of Attributes -- * (i.e. the number of characteristic + the number of characteristic values + the number of descriptors, excluding the services) -- * that can be stored in the GATT database. -- * Note that certain characteristics and relative descriptors are added automatically during device initialization -- * so this parameters should be 9 plus the number of user Attributes -+ * (i.e. the number of characteristic + the number of characteristic values + the number of descriptors, excluding the -+ * services) that can be stored in the GATT database. Note that certain characteristics and relative descriptors are -+ * added automatically during device initialization so this parameters should be 9 plus the number of user Attributes +@@ -68,13 +71,17 @@ + * Note that certain characteristics and relative descriptors are added automatically during device initialization + * so this parameters should be 9 plus the number of user Attributes */ -#define CFG_BLE_NUM_GATT_ATTRIBUTES 68 +#ifndef CFG_BLE_NUM_GATT_ATTRIBUTES @@ -83,7 +79,7 @@ index 4f300e0..9f8e085 100644 /** * Maximum supported ATT_MTU size - * This parameter is ignored by the CPU2 when CFG_BLE_OPTIONS is set to 1" + * This parameter is ignored by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set */ -#define CFG_BLE_MAX_ATT_MTU (156) +#ifndef CFG_BLE_MAX_ATT_MTU @@ -92,23 +88,18 @@ index 4f300e0..9f8e085 100644 /** * Size of the storage area for Attribute values -- * This value depends on the number of attributes used by application. In particular the sum of the following quantities (in octets) should be made for each attribute: -+ * This value depends on the number of attributes used by application. In particular the sum of the following -+ * quantities (in octets) should be made for each attribute: - * - attribute value length - * - 5, if UUID is 16 bit; 19, if UUID is 128 bit - * - 2, if server configuration descriptor is used -@@ -87,14 +95,18 @@ +@@ -87,14 +94,18 @@ * The total amount of memory needed is the sum of the above quantities for each attribute. - * This parameter is ignored by the CPU2 when CFG_BLE_OPTIONS is set to 1" + * This parameter is ignored by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set */ +-#define CFG_BLE_ATT_VALUE_ARRAY_SIZE (1344) +#ifndef CFG_BLE_ATT_VALUE_ARRAY_SIZE - #define CFG_BLE_ATT_VALUE_ARRAY_SIZE (1344) ++ #define CFG_BLE_ATT_VALUE_ARRAY_SIZE (1344) +#endif /** * Prepare Write List size in terms of number of packet - * This parameter is ignored by the CPU2 when CFG_BLE_OPTIONS is set to 1" + * This parameter is ignored by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set */ // #define CFG_BLE_PREPARE_WRITE_LIST_SIZE BLE_PREP_WRITE_X_ATT(CFG_BLE_MAX_ATT_MTU) -#define CFG_BLE_PREPARE_WRITE_LIST_SIZE (0x3A) @@ -118,7 +109,7 @@ index 4f300e0..9f8e085 100644 /** * Number of allocated memory blocks -@@ -106,12 +118,16 @@ +@@ -106,12 +117,16 @@ /** * Enable or disable the Extended Packet length feature. Valid values are 0 or 1. */ @@ -137,7 +128,7 @@ index 4f300e0..9f8e085 100644 /** * Sleep clock accuracy in Master mode -@@ -124,24 +140,32 @@ +@@ -124,7 +139,9 @@ * 6 : 21 ppm to 30 ppm * 7 : 0 ppm to 20 ppm */ @@ -147,14 +138,22 @@ index 4f300e0..9f8e085 100644 +#endif /** - * Source for the low speed clock for RF wake-up - * 1 : external high speed crystal HSE/32/32 - * 0 : external low speed crystal ( no calibration ) + * LsSource +@@ -132,21 +149,27 @@ + * - bit 0: 1: Calibration for the RF system wakeup clock source 0: No calibration for the RF system wakeup clock source + * - bit 1: 1: STM32W5M Module device 0: Other devices as STM32WBxx SOC, STM32WB1M module */ --#define CFG_BLE_LSE_SOURCE 0 +-#if defined(STM32WB5Mxx) +- #define CFG_BLE_LSE_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LSE_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LSE_MOD5MM_DEV) +-#else +- #define CFG_BLE_LSE_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LSE_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LSE_OTHER_DEV) +#ifndef CFG_BLE_LSE_SOURCE -+ #define CFG_BLE_LSE_SOURCE 0 -+#endif ++ #if defined(STM32WB5Mxx) ++ #define CFG_BLE_LSE_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LSE_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LSE_MOD5MM_DEV) ++ #else ++ #define CFG_BLE_LSE_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LSE_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LSE_OTHER_DEV) ++ #endif + #endif /** * Start up time of the high speed (16 or 32 MHz) crystal oscillator in units of 625/256 us (~2.44 us) @@ -174,13 +173,13 @@ index 4f300e0..9f8e085 100644 /** * Viterbi Mode -@@ -199,5 +223,4 @@ +@@ -234,5 +257,5 @@ - #define CFG_BLE_RX_MODEL_CONFIG SHCI_C2_BLE_INIT_RX_MODEL_AGC_RSSI_LEGACY + #define CFG_BLE_RX_PATH_COMPENS (0) -- -#endif /*APP_CONF_H */ +#endif /* APP_CONF_DEFAULT_H */ + -- -2.31.1.windows.1 +2.33.0.windows.1 diff --git a/extras/STM32Cube_FW/0004-Stub-OutputDbgTrace-function.patch b/extras/STM32Cube_FW/0004-Stub-OutputDbgTrace-function.patch deleted file mode 100644 index 6f844f7a..00000000 --- a/extras/STM32Cube_FW/0004-Stub-OutputDbgTrace-function.patch +++ /dev/null @@ -1,209 +0,0 @@ -From a015490bdd861f421addd761ee4164358dc07c19 Mon Sep 17 00:00:00 2001 -From: Alexandre Bourdiol <alexandre.bourdiol@st.com> -Date: Tue, 7 Dec 2021 14:27:27 +0100 -Subject: [PATCH 4/4] Stub OutputDbgTrace() function - -Signed-off-by: Alexandre Bourdiol <alexandre.bourdiol@st.com> ---- - src/utility/STM32Cube_FW/tl_mbox.c | 178 +---------------------------- - 1 file changed, 3 insertions(+), 175 deletions(-) - -diff --git a/src/utility/STM32Cube_FW/tl_mbox.c b/src/utility/STM32Cube_FW/tl_mbox.c -index 709f5d2..db192c4 100644 ---- a/src/utility/STM32Cube_FW/tl_mbox.c -+++ b/src/utility/STM32Cube_FW/tl_mbox.c -@@ -24,7 +24,6 @@ - #include "stm_list.h" - #include "tl.h" - #include "mbox_def.h" --#include "tl_dbg_conf.h" - - /* Private typedef -----------------------------------------------------------*/ - typedef enum -@@ -532,180 +531,9 @@ __WEAK void TL_TRACES_EvtReceived( TL_EvtPacket_t * hcievt ) - ******************************************************************************/ - static void OutputDbgTrace(TL_MB_PacketType_t packet_type, uint8_t* buffer) - { -- TL_EvtPacket_t *p_evt_packet; -- TL_CmdPacket_t *p_cmd_packet; -- -- switch(packet_type) -- { -- case TL_MB_MM_RELEASE_BUFFER: -- p_evt_packet = (TL_EvtPacket_t*)buffer; -- switch(p_evt_packet->evtserial.evt.evtcode) -- { -- case TL_BLEEVT_CS_OPCODE: -- TL_MM_DBG_MSG("mm evt released: 0x%02X", p_evt_packet->evtserial.evt.evtcode); -- TL_MM_DBG_MSG(" cmd opcode: 0x%04X", ((TL_CsEvt_t*)(p_evt_packet->evtserial.evt.payload))->cmdcode); -- TL_MM_DBG_MSG(" buffer addr: 0x%08X", p_evt_packet); -- break; -- -- case TL_BLEEVT_CC_OPCODE: -- TL_MM_DBG_MSG("mm evt released: 0x%02X", p_evt_packet->evtserial.evt.evtcode); -- TL_MM_DBG_MSG(" cmd opcode: 0x%04X", ((TL_CcEvt_t*)(p_evt_packet->evtserial.evt.payload))->cmdcode); -- TL_MM_DBG_MSG(" buffer addr: 0x%08X", p_evt_packet); -- break; -- -- case TL_BLEEVT_VS_OPCODE: -- TL_MM_DBG_MSG("mm evt released: 0x%02X", p_evt_packet->evtserial.evt.evtcode); -- TL_MM_DBG_MSG(" subevtcode: 0x%04X", ((TL_AsynchEvt_t*)(p_evt_packet->evtserial.evt.payload))->subevtcode); -- TL_MM_DBG_MSG(" buffer addr: 0x%08X", p_evt_packet); -- break; -- -- default: -- TL_MM_DBG_MSG("mm evt released: 0x%02X", p_evt_packet->evtserial.evt.evtcode); -- TL_MM_DBG_MSG(" buffer addr: 0x%08X", p_evt_packet); -- break; -- } -- -- TL_MM_DBG_MSG("\r\n"); -- break; -- -- case TL_MB_BLE_CMD: -- p_cmd_packet = (TL_CmdPacket_t*)buffer; -- TL_HCI_CMD_DBG_MSG("ble cmd: 0x%04X", p_cmd_packet->cmdserial.cmd.cmdcode); -- if(p_cmd_packet->cmdserial.cmd.plen != 0) -- { -- TL_HCI_CMD_DBG_MSG(" payload:"); -- TL_HCI_CMD_DBG_BUF(p_cmd_packet->cmdserial.cmd.payload, p_cmd_packet->cmdserial.cmd.plen, ""); -- } -- TL_HCI_CMD_DBG_MSG("\r\n"); -- -- TL_HCI_CMD_DBG_RAW(&p_cmd_packet->cmdserial, p_cmd_packet->cmdserial.cmd.plen+TL_CMD_HDR_SIZE); -- break; -- -- case TL_MB_BLE_CMD_RSP: -- p_evt_packet = (TL_EvtPacket_t*)buffer; -- switch(p_evt_packet->evtserial.evt.evtcode) -- { -- case TL_BLEEVT_CS_OPCODE: -- TL_HCI_CMD_DBG_MSG("ble rsp: 0x%02X", p_evt_packet->evtserial.evt.evtcode); -- TL_HCI_CMD_DBG_MSG(" cmd opcode: 0x%04X", ((TL_CsEvt_t*)(p_evt_packet->evtserial.evt.payload))->cmdcode); -- TL_HCI_CMD_DBG_MSG(" numhci: 0x%02X", ((TL_CsEvt_t*)(p_evt_packet->evtserial.evt.payload))->numcmd); -- TL_HCI_CMD_DBG_MSG(" status: 0x%02X", ((TL_CsEvt_t*)(p_evt_packet->evtserial.evt.payload))->status); -- break; -- -- case TL_BLEEVT_CC_OPCODE: -- TL_HCI_CMD_DBG_MSG("ble rsp: 0x%02X", p_evt_packet->evtserial.evt.evtcode); -- TL_HCI_CMD_DBG_MSG(" cmd opcode: 0x%04X", ((TL_CcEvt_t*)(p_evt_packet->evtserial.evt.payload))->cmdcode); -- TL_HCI_CMD_DBG_MSG(" numhci: 0x%02X", ((TL_CcEvt_t*)(p_evt_packet->evtserial.evt.payload))->numcmd); -- TL_HCI_CMD_DBG_MSG(" status: 0x%02X", ((TL_CcEvt_t*)(p_evt_packet->evtserial.evt.payload))->payload[0]); -- if((p_evt_packet->evtserial.evt.plen-4) != 0) -- { -- TL_HCI_CMD_DBG_MSG(" payload:"); -- TL_HCI_CMD_DBG_BUF(&((TL_CcEvt_t*)(p_evt_packet->evtserial.evt.payload))->payload[1], p_evt_packet->evtserial.evt.plen-4, ""); -- } -- break; -- -- default: -- TL_HCI_CMD_DBG_MSG("unknown ble rsp received: %02X", p_evt_packet->evtserial.evt.evtcode); -- break; -- } -- -- TL_HCI_CMD_DBG_MSG("\r\n"); -- -- TL_HCI_CMD_DBG_RAW(&p_evt_packet->evtserial, p_evt_packet->evtserial.evt.plen+TL_EVT_HDR_SIZE); -- break; -- -- case TL_MB_BLE_ASYNCH_EVT: -- p_evt_packet = (TL_EvtPacket_t*)buffer; -- if(p_evt_packet->evtserial.evt.evtcode != TL_BLEEVT_VS_OPCODE) -- { -- TL_HCI_EVT_DBG_MSG("ble evt: 0x%02X", p_evt_packet->evtserial.evt.evtcode); -- if((p_evt_packet->evtserial.evt.plen) != 0) -- { -- TL_HCI_EVT_DBG_MSG(" payload:"); -- TL_HCI_EVT_DBG_BUF(p_evt_packet->evtserial.evt.payload, p_evt_packet->evtserial.evt.plen, ""); -- } -- } -- else -- { -- TL_HCI_EVT_DBG_MSG("ble evt: 0x%02X", p_evt_packet->evtserial.evt.evtcode); -- TL_HCI_EVT_DBG_MSG(" subevtcode: 0x%04X", ((TL_AsynchEvt_t*)(p_evt_packet->evtserial.evt.payload))->subevtcode); -- if((p_evt_packet->evtserial.evt.plen-2) != 0) -- { -- TL_HCI_EVT_DBG_MSG(" payload:"); -- TL_HCI_EVT_DBG_BUF(((TL_AsynchEvt_t*)(p_evt_packet->evtserial.evt.payload))->payload, p_evt_packet->evtserial.evt.plen-2, ""); -- } -- } -- -- TL_HCI_EVT_DBG_MSG("\r\n"); -- -- TL_HCI_EVT_DBG_RAW(&p_evt_packet->evtserial, p_evt_packet->evtserial.evt.plen+TL_EVT_HDR_SIZE); -- break; -- -- case TL_MB_SYS_CMD: -- p_cmd_packet = (TL_CmdPacket_t*)buffer; -- -- TL_SHCI_CMD_DBG_MSG("sys cmd: 0x%04X", p_cmd_packet->cmdserial.cmd.cmdcode); -- -- if(p_cmd_packet->cmdserial.cmd.plen != 0) -- { -- TL_SHCI_CMD_DBG_MSG(" payload:"); -- TL_SHCI_CMD_DBG_BUF(p_cmd_packet->cmdserial.cmd.payload, p_cmd_packet->cmdserial.cmd.plen, ""); -- } -- TL_SHCI_CMD_DBG_MSG("\r\n"); -- -- TL_SHCI_CMD_DBG_RAW(&p_cmd_packet->cmdserial, p_cmd_packet->cmdserial.cmd.plen+TL_CMD_HDR_SIZE); -- break; -- -- case TL_MB_SYS_CMD_RSP: -- p_evt_packet = (TL_EvtPacket_t*)buffer; -- switch(p_evt_packet->evtserial.evt.evtcode) -- { -- case TL_BLEEVT_CC_OPCODE: -- TL_SHCI_CMD_DBG_MSG("sys rsp: 0x%02X", p_evt_packet->evtserial.evt.evtcode); -- TL_SHCI_CMD_DBG_MSG(" cmd opcode: 0x%02X", ((TL_CcEvt_t*)(p_evt_packet->evtserial.evt.payload))->cmdcode); -- TL_SHCI_CMD_DBG_MSG(" status: 0x%02X", ((TL_CcEvt_t*)(p_evt_packet->evtserial.evt.payload))->payload[0]); -- if((p_evt_packet->evtserial.evt.plen-4) != 0) -- { -- TL_SHCI_CMD_DBG_MSG(" payload:"); -- TL_SHCI_CMD_DBG_BUF(&((TL_CcEvt_t*)(p_evt_packet->evtserial.evt.payload))->payload[1], p_evt_packet->evtserial.evt.plen-4, ""); -- } -- break; -- -- default: -- TL_SHCI_CMD_DBG_MSG("unknown sys rsp received: %02X", p_evt_packet->evtserial.evt.evtcode); -- break; -- } -- -- TL_SHCI_CMD_DBG_MSG("\r\n"); -- -- TL_SHCI_CMD_DBG_RAW(&p_evt_packet->evtserial, p_evt_packet->evtserial.evt.plen+TL_EVT_HDR_SIZE); -- break; -- -- case TL_MB_SYS_ASYNCH_EVT: -- p_evt_packet = (TL_EvtPacket_t*)buffer; -- if(p_evt_packet->evtserial.evt.evtcode != TL_BLEEVT_VS_OPCODE) -- { -- TL_SHCI_EVT_DBG_MSG("unknown sys evt received: %02X", p_evt_packet->evtserial.evt.evtcode); -- } -- else -- { -- TL_SHCI_EVT_DBG_MSG("sys evt: 0x%02X", p_evt_packet->evtserial.evt.evtcode); -- TL_SHCI_EVT_DBG_MSG(" subevtcode: 0x%04X", ((TL_AsynchEvt_t*)(p_evt_packet->evtserial.evt.payload))->subevtcode); -- if((p_evt_packet->evtserial.evt.plen-2) != 0) -- { -- TL_SHCI_EVT_DBG_MSG(" payload:"); -- TL_SHCI_EVT_DBG_BUF(((TL_AsynchEvt_t*)(p_evt_packet->evtserial.evt.payload))->payload, p_evt_packet->evtserial.evt.plen-2, ""); -- } -- } -- -- TL_SHCI_EVT_DBG_MSG("\r\n"); -- -- TL_SHCI_EVT_DBG_RAW(&p_evt_packet->evtserial, p_evt_packet->evtserial.evt.plen+TL_EVT_HDR_SIZE); -- break; -- -- default: -- break; -- } -+ /* Function stubbed */ -+ UNUSED(packet_type); -+ UNUSED(buffer); - - return; - } --- -2.31.1.windows.1 - From 2cc9f0f8152e49918ef3f352310930c9dfd869da Mon Sep 17 00:00:00 2001 From: Alexandre Bourdiol <alexandre.bourdiol@st.com> Date: Tue, 30 Aug 2022 10:56:46 +0200 Subject: [PATCH 092/226] Update STM32Cube_FW from Cube version 1.14.1 Signed-off-by: Alexandre Bourdiol <alexandre.bourdiol@st.com> --- src/utility/STM32Cube_FW/README.md | 4 +- src/utility/STM32Cube_FW/app_conf_default.h | 556 ++++++++++++++++--- src/utility/STM32Cube_FW/ble_bufsize.h | 23 +- src/utility/STM32Cube_FW/hw.h | 28 +- src/utility/STM32Cube_FW/hw_ipcc.c | 195 ++++++- src/utility/STM32Cube_FW/mbox_def.h | 35 ++ src/utility/STM32Cube_FW/shci.c | 39 +- src/utility/STM32Cube_FW/shci.h | 98 +++- src/utility/STM32Cube_FW/shci_tl.c | 29 +- src/utility/STM32Cube_FW/stm32_wpan_common.h | 39 +- src/utility/STM32Cube_FW/stm_list.c | 414 +++++++------- src/utility/STM32Cube_FW/stm_list.h | 4 +- src/utility/STM32Cube_FW/tl.h | 34 ++ src/utility/STM32Cube_FW/tl_mbox.c | 324 ++++++++++- 14 files changed, 1444 insertions(+), 378 deletions(-) diff --git a/src/utility/STM32Cube_FW/README.md b/src/utility/STM32Cube_FW/README.md index dc03bb92..2cd8302a 100644 --- a/src/utility/STM32Cube_FW/README.md +++ b/src/utility/STM32Cube_FW/README.md @@ -1,6 +1,6 @@ ## Source -[STMicroelectronics/STM32CubeWB Release v1.13.3](https://github.com/STMicroelectronics/STM32CubeWB/releases/tag/v1.13.3) -- Application: [BLE_TransparentMode](https://github.com/STMicroelectronics/STM32CubeWB/tree/v1.13.3/Projects/P-NUCLEO-WB55.Nucleo/Applications/BLE/BLE_TransparentMode) +[STMicroelectronics/STM32CubeWB Release 1.14.0](https://github.com/STMicroelectronics/STM32CubeWB/releases/tag/1.14.0) +- Application: [BLE_TransparentMode](https://github.com/STMicroelectronics/STM32CubeWB/tree/1.14.0/Projects/P-NUCLEO-WB55.Nucleo/Applications/BLE/BLE_TransparentMode) diff --git a/src/utility/STM32Cube_FW/app_conf_default.h b/src/utility/STM32Cube_FW/app_conf_default.h index 9f8e085d..c63c66e9 100644 --- a/src/utility/STM32Cube_FW/app_conf_default.h +++ b/src/utility/STM32Cube_FW/app_conf_default.h @@ -1,8 +1,9 @@ +/* USER CODE BEGIN Header */ /** ****************************************************************************** - * @file app_conf_default.h + * @file app_conf.h * @author MCD Application Team - * @brief Default application configuration file for STM32WPAN Middleware. + * @brief Application configuration file for STM32WPAN Middleware. ****************************************************************************** * @attention * @@ -15,35 +16,94 @@ * ****************************************************************************** */ +/* USER CODE END Header */ /* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef APP_CONF_DEFAULT_H -#define APP_CONF_DEFAULT_H +#ifndef APP_CONF_H +#define APP_CONF_H + +#include "hw.h" +#include "hw_conf.h" +#include "hw_if.h" +#include "ble_bufsize.h" /****************************************************************************** * Application Config ******************************************************************************/ -/**< generic parameters ******************************************************/ -/* HCI related defines */ +/** + * Define Secure Connections Support + */ +#define CFG_SECURE_NOT_SUPPORTED (0x00) +#define CFG_SECURE_OPTIONAL (0x01) +#define CFG_SECURE_MANDATORY (0x02) -#define ACI_HAL_SET_TX_POWER_LEVEL 0xFC0F -#define ACI_WRITE_CONFIG_DATA_OPCODE 0xFC0C -#define ACI_READ_CONFIG_DATA_OPCODE 0xFC0D -#define MAX_HCI_ACL_PACKET_SIZE (sizeof(TL_PacketHeader_t) + 5 + 251) -#define HCI_RESET 0x0C03 +#define CFG_SC_SUPPORT CFG_SECURE_OPTIONAL -#ifndef BLE_SHARED_MEM_BYTE_ORDER - #define BLE_SHARED_MEM_BYTE_ORDER MSBFIRST -#endif -#define BLE_MODULE_SHARED_MEM_BUFFER_SIZE 128 +/** + * Define Keypress Notification Support + */ +#define CFG_KEYPRESS_NOT_SUPPORTED (0x00) +#define CFG_KEYPRESS_SUPPORTED (0x01) + +#define CFG_KEYPRESS_NOTIFICATION_SUPPORT CFG_KEYPRESS_NOT_SUPPORTED /** - * Define Tx Power + * Numeric Comparison Answers */ -#ifndef CFG_TX_POWER - #define CFG_TX_POWER (0x18) /* -0.15dBm */ -#endif +#define YES (0x01) +#define NO (0x00) + +/** + * Device name configuration for Generic Access Service + */ +#define CFG_GAP_DEVICE_NAME "TEMPLATE" +#define CFG_GAP_DEVICE_NAME_LENGTH (8) + +/** +* Identity root key used to derive LTK and CSRK +*/ +#define CFG_BLE_IRK {0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0} + +/** +* Encryption root key used to derive LTK and CSRK +*/ +#define CFG_BLE_ERK {0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21, 0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21} + +/** + * SMPS supply + * SMPS not used when Set to 0 + * SMPS used when Set to 1 + */ +#define CFG_USE_SMPS 0 + +/* USER CODE BEGIN Generic_Parameters */ +/* USER CODE END Generic_Parameters */ + +/**< specific parameters */ +/*****************************************************/ + +/* USER CODE BEGIN Specific_Parameters */ +#define PUSH_BUTTON_SW1_EXTI_IRQHandler EXTI4_IRQHandler + +/* USER CODE END Specific_Parameters */ + +/****************************************************************************** + * Information Table + * + * Version + * [0:3] = Build - 0: Untracked - 15:Released - x: Tracked version + * [4:7] = branch - 0: Mass Market - x: ... + * [8:15] = Subversion + * [16:23] = Version minor + * [24:31] = Version major + * + ******************************************************************************/ +#define CFG_FW_MAJOR_VERSION (0) +#define CFG_FW_MINOR_VERSION (0) +#define CFG_FW_SUBVERSION (1) +#define CFG_FW_BRANCH (0) +#define CFG_FW_BUILD (0) /****************************************************************************** * BLE Stack @@ -52,82 +112,63 @@ * Maximum number of simultaneous connections that the device will support. * Valid values are from 1 to 8 */ -#ifndef CFG_BLE_NUM_LINK - #define CFG_BLE_NUM_LINK 2 -#endif +#define CFG_BLE_NUM_LINK 8 /** * Maximum number of Services that can be stored in the GATT database. - * Note that the GAP and GATT services are automatically added so this parameter should be 2 plus the number of user - * services + * Note that the GAP and GATT services are automatically added so this parameter should be 2 plus the number of user services */ -#ifndef CFG_BLE_NUM_GATT_SERVICES #define CFG_BLE_NUM_GATT_SERVICES 8 -#endif /** * Maximum number of Attributes - * (i.e. the number of characteristic + the number of characteristic values + the number of descriptors, excluding the - * services) that can be stored in the GATT database. Note that certain characteristics and relative descriptors are - * added automatically during device initialization so this parameters should be 9 plus the number of user Attributes + * (i.e. the number of characteristic + the number of characteristic values + the number of descriptors, excluding the services) + * that can be stored in the GATT database. + * Note that certain characteristics and relative descriptors are added automatically during device initialization + * so this parameters should be 9 plus the number of user Attributes */ -#ifndef CFG_BLE_NUM_GATT_ATTRIBUTES - #define CFG_BLE_NUM_GATT_ATTRIBUTES 68 -#endif +#define CFG_BLE_NUM_GATT_ATTRIBUTES 68 /** * Maximum supported ATT_MTU size - * This parameter is ignored by the CPU2 when CFG_BLE_OPTIONS is set to 1" + * This parameter is ignored by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set */ -#ifndef CFG_BLE_MAX_ATT_MTU - #define CFG_BLE_MAX_ATT_MTU (156) -#endif +#define CFG_BLE_MAX_ATT_MTU (156) /** * Size of the storage area for Attribute values - * This value depends on the number of attributes used by application. In particular the sum of the following - * quantities (in octets) should be made for each attribute: + * This value depends on the number of attributes used by application. In particular the sum of the following quantities (in octets) should be made for each attribute: * - attribute value length * - 5, if UUID is 16 bit; 19, if UUID is 128 bit * - 2, if server configuration descriptor is used * - 2*DTM_NUM_LINK, if client configuration descriptor is used * - 2, if extended properties is used * The total amount of memory needed is the sum of the above quantities for each attribute. - * This parameter is ignored by the CPU2 when CFG_BLE_OPTIONS is set to 1" + * This parameter is ignored by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set */ -#ifndef CFG_BLE_ATT_VALUE_ARRAY_SIZE #define CFG_BLE_ATT_VALUE_ARRAY_SIZE (1344) -#endif /** * Prepare Write List size in terms of number of packet - * This parameter is ignored by the CPU2 when CFG_BLE_OPTIONS is set to 1" + * This parameter is ignored by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set */ -// #define CFG_BLE_PREPARE_WRITE_LIST_SIZE BLE_PREP_WRITE_X_ATT(CFG_BLE_MAX_ATT_MTU) -#ifndef CFG_BLE_PREPARE_WRITE_LIST_SIZE - #define CFG_BLE_PREPARE_WRITE_LIST_SIZE (0x3A) -#endif +#define CFG_BLE_PREPARE_WRITE_LIST_SIZE BLE_PREP_WRITE_X_ATT(CFG_BLE_MAX_ATT_MTU) /** * Number of allocated memory blocks - * This parameter is overwritten by the CPU2 with an hardcoded optimal value when the parameter when CFG_BLE_OPTIONS is set to 1 + * This parameter is overwritten by the CPU2 with an hardcoded optimal value when the parameter CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set */ -// #define CFG_BLE_MBLOCK_COUNT (BLE_MBLOCKS_CALC(CFG_BLE_PREPARE_WRITE_LIST_SIZE, CFG_BLE_MAX_ATT_MTU, CFG_BLE_NUM_LINK)) -#define CFG_BLE_MBLOCK_COUNT (0x79) +#define CFG_BLE_MBLOCK_COUNT (BLE_MBLOCKS_CALC(CFG_BLE_PREPARE_WRITE_LIST_SIZE, CFG_BLE_MAX_ATT_MTU, CFG_BLE_NUM_LINK)) /** * Enable or disable the Extended Packet length feature. Valid values are 0 or 1. */ -#ifndef CFG_BLE_DATA_LENGTH_EXTENSION - #define CFG_BLE_DATA_LENGTH_EXTENSION 1 -#endif +#define CFG_BLE_DATA_LENGTH_EXTENSION 1 /** * Sleep clock accuracy in Slave mode (ppm value) */ -#ifndef CFG_BLE_SLAVE_SCA - #define CFG_BLE_SLAVE_SCA 500 -#endif +#define CFG_BLE_SLAVE_SCA 500 /** * Sleep clock accuracy in Master mode @@ -140,32 +181,29 @@ * 6 : 21 ppm to 30 ppm * 7 : 0 ppm to 20 ppm */ -#ifndef CFG_BLE_MASTER_SCA - #define CFG_BLE_MASTER_SCA 0 -#endif +#define CFG_BLE_MASTER_SCA 0 /** - * Source for the low speed clock for RF wake-up - * 1 : external high speed crystal HSE/32/32 - * 0 : external low speed crystal ( no calibration ) + * LsSource + * Some information for Low speed clock mapped in bits field + * - bit 0: 1: Calibration for the RF system wakeup clock source 0: No calibration for the RF system wakeup clock source + * - bit 1: 1: STM32W5M Module device 0: Other devices as STM32WBxx SOC, STM32WB1M module */ -#ifndef CFG_BLE_LSE_SOURCE - #define CFG_BLE_LSE_SOURCE 0 +#if defined(STM32WB5Mxx) + #define CFG_BLE_LSE_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LSE_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LSE_MOD5MM_DEV) +#else + #define CFG_BLE_LSE_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LSE_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LSE_OTHER_DEV) #endif /** * Start up time of the high speed (16 or 32 MHz) crystal oscillator in units of 625/256 us (~2.44 us) */ -#ifndef CFG_BLE_HSE_STARTUP_TIME - #define CFG_BLE_HSE_STARTUP_TIME 0x148 -#endif +#define CFG_BLE_HSE_STARTUP_TIME 0x148 /** * Maximum duration of the connection event when the device is in Slave mode in units of 625/256 us (~2.44 us) */ -#ifndef CFG_BLE_MAX_CONN_EVENT_LENGTH - #define CFG_BLE_MAX_CONN_EVENT_LENGTH (0xFFFFFFFF) -#endif +#define CFG_BLE_MAX_CONN_EVENT_LENGTH (0xFFFFFFFF) /** * Viterbi Mode @@ -195,21 +233,21 @@ * 0: with service change desc. * (bit 2): 1: device name Read-Only * 0: device name R/W - * (bit 3): 1: extended advertizing supported [NOT SUPPORTED] - * 0: extended advertizing not supported [NOT SUPPORTED] + * (bit 3): 1: extended advertizing supported + * 0: extended advertizing not supported * (bit 4): 1: CS Algo #2 supported * 0: CS Algo #2 not supported * (bit 7): 1: LE Power Class 1 * 0: LE Power Class 2-3 * other bits: reserved (shall be set to 0) */ -#define CFG_BLE_OPTIONS (SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY) +#define CFG_BLE_OPTIONS (SHCI_C2_BLE_INIT_OPTIONS_LL_HOST | SHCI_C2_BLE_INIT_OPTIONS_WITH_SVC_CHANGE_DESC | SHCI_C2_BLE_INIT_OPTIONS_DEVICE_NAME_RW | SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV | SHCI_C2_BLE_INIT_OPTIONS_CS_ALGO2 | SHCI_C2_BLE_INIT_OPTIONS_POWER_CLASS_2_3) #define CFG_BLE_MAX_COC_INITIATOR_NBR (32) -#define CFG_BLE_MIN_TX_POWER (0) +#define CFG_BLE_MIN_TX_POWER (-40) -#define CFG_BLE_MAX_TX_POWER (0) +#define CFG_BLE_MAX_TX_POWER (6) /** * BLE Rx model configuration flags to be configured with: @@ -221,6 +259,372 @@ * other bits: reserved (shall be set to 0) */ -#define CFG_BLE_RX_MODEL_CONFIG SHCI_C2_BLE_INIT_RX_MODEL_AGC_RSSI_LEGACY +#define CFG_BLE_RX_MODEL_CONFIG (SHCI_C2_BLE_INIT_RX_MODEL_AGC_RSSI_LEGACY) + +/* Maximum number of advertising sets. + * Range: 1 .. 8 with limitation: + * This parameter is linked to CFG_BLE_MAX_ADV_DATA_LEN such as both compliant with allocated Total memory computed with BLE_EXT_ADV_BUFFER_SIZE based + * on Max Extended advertising configuration supported. + * This parameter is considered by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV flag set + */ + +#define CFG_BLE_MAX_ADV_SET_NBR (8) + + /* Maximum advertising data length (in bytes) + * Range: 31 .. 1650 with limitation: + * This parameter is linked to CFG_BLE_MAX_ADV_SET_NBR such as both compliant with allocated Total memory computed with BLE_EXT_ADV_BUFFER_SIZE based + * on Max Extended advertising configuration supported. + * This parameter is considered by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV flag set + */ + +#define CFG_BLE_MAX_ADV_DATA_LEN (207) + + /* RF TX Path Compensation Value (16-bit signed integer). Units: 0.1 dB. + * Range: -1280 .. 1280 + */ + +#define CFG_BLE_TX_PATH_COMPENS (0) + + /* RF RX Path Compensation Value (16-bit signed integer). Units: 0.1 dB. + * Range: -1280 .. 1280 + */ + +#define CFG_BLE_RX_PATH_COMPENS (0) + +/****************************************************************************** + * Transport Layer + ******************************************************************************/ +/** + * Queue length of BLE Event + * This parameter defines the number of asynchronous events that can be stored in the HCI layer before + * being reported to the application. When a command is sent to the BLE core coprocessor, the HCI layer + * is waiting for the event with the Num_HCI_Command_Packets set to 1. The receive queue shall be large + * enough to store all asynchronous events received in between. + * When CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE is set to 27, this allow to store three 255 bytes long asynchronous events + * between the HCI command and its event. + * This parameter depends on the value given to CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE. When the queue size is to small, + * the system may hang if the queue is full with asynchronous events and the HCI layer is still waiting + * for a CC/CS event, In that case, the notification TL_BLE_HCI_ToNot() is called to indicate + * to the application a HCI command did not receive its command event within 30s (Default HCI Timeout). + */ +#define CFG_TLBLE_EVT_QUEUE_LENGTH 5 +/** + * This parameter should be set to fit most events received by the HCI layer. It defines the buffer size of each element + * allocated in the queue of received events and can be used to optimize the amount of RAM allocated by the Memory Manager. + * It should not exceed 255 which is the maximum HCI packet payload size (a greater value is a lost of memory as it will + * never be used) + * It shall be at least 4 to receive the command status event in one frame. + * The default value is set to 27 to allow receiving an event of MTU size in a single buffer. This value maybe reduced + * further depending on the application. + */ +#define CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE 255 /**< Set to 255 with the memory manager and the mailbox */ + +#define TL_BLE_EVENT_FRAME_SIZE ( TL_EVT_HDR_SIZE + CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE ) +/****************************************************************************** + * UART interfaces + ******************************************************************************/ + +/** + * Select UART interfaces + */ +#define CFG_UART_GUI hw_uart1 +#define CFG_DEBUG_TRACE_UART 0 +/****************************************************************************** + * USB interface + ******************************************************************************/ + +/** + * Enable/Disable USB interface + */ +#define CFG_USB_INTERFACE_ENABLE 0 + +/****************************************************************************** + * IPCC interface + ******************************************************************************/ + +/** + * The IPCC is dedicated to the communication between the CPU2 and the CPU1 + * and shall not be modified by the application + * The two following definitions shall not be modified + */ +#define HAL_IPCC_TX_IRQHandler(...) HW_IPCC_Tx_Handler( ) +#define HAL_IPCC_RX_IRQHandler(...) HW_IPCC_Rx_Handler( ) + +/****************************************************************************** + * Low Power + ******************************************************************************/ +/** + * When set to 1, the low power mode is enable + * When set to 0, the device stays in RUN mode + */ +#define CFG_LPM_SUPPORTED 1 + +/****************************************************************************** + * RTC interface + ******************************************************************************/ +#define HAL_RTCEx_WakeUpTimerIRQHandler(...) HW_TS_RTC_Wakeup_Handler( ) + +/****************************************************************************** + * Timer Server + ******************************************************************************/ +/** + * CFG_RTC_WUCKSEL_DIVIDER: This sets the RTCCLK divider to the wakeup timer. + * The lower is the value, the better is the power consumption and the accuracy of the timerserver + * The higher is the value, the finest is the granularity + * + * CFG_RTC_ASYNCH_PRESCALER: This sets the asynchronous prescaler of the RTC. It should as high as possible ( to output + * clock as low as possible) but the output clock should be equal or higher frequency compare to the clock feeding + * the wakeup timer. A lower clock speed would impact the accuracy of the timer server. + * + * CFG_RTC_SYNCH_PRESCALER: This sets the synchronous prescaler of the RTC. + * When the 1Hz calendar clock is required, it shall be sets according to other settings + * When the 1Hz calendar clock is not needed, CFG_RTC_SYNCH_PRESCALER should be set to 0x7FFF (MAX VALUE) + * + * CFG_RTCCLK_DIVIDER_CONF: + * Shall be set to either 0,2,4,8,16 + * When set to either 2,4,8,16, the 1Hhz calendar is supported + * When set to 0, the user sets its own configuration + * + * The following settings are computed with LSI as input to the RTC + */ + +#define CFG_RTCCLK_DIVIDER_CONF 0 + +#if (CFG_RTCCLK_DIVIDER_CONF == 0) +/** + * Custom configuration + * It does not support 1Hz calendar + * It divides the RTC CLK by 16 + */ + +#define CFG_RTCCLK_DIV (16) +#define CFG_RTC_WUCKSEL_DIVIDER (0) +#define CFG_RTC_ASYNCH_PRESCALER (0x0F) +#define CFG_RTC_SYNCH_PRESCALER (0x7FFF) + +#else + +#if (CFG_RTCCLK_DIVIDER_CONF == 2) +/** + * It divides the RTC CLK by 2 + */ +#define CFG_RTC_WUCKSEL_DIVIDER (3) +#endif + +#if (CFG_RTCCLK_DIVIDER_CONF == 4) +/** + * It divides the RTC CLK by 4 + */ +#define CFG_RTC_WUCKSEL_DIVIDER (2) +#endif + +#if (CFG_RTCCLK_DIVIDER_CONF == 8) +/** + * It divides the RTC CLK by 8 + */ +#define CFG_RTC_WUCKSEL_DIVIDER (1) +#endif + +#if (CFG_RTCCLK_DIVIDER_CONF == 16) +/** + * It divides the RTC CLK by 16 + */ +#define CFG_RTC_WUCKSEL_DIVIDER (0) +#endif + +#define CFG_RTCCLK_DIV CFG_RTCCLK_DIVIDER_CONF +#define CFG_RTC_ASYNCH_PRESCALER (CFG_RTCCLK_DIV - 1) +#define CFG_RTC_SYNCH_PRESCALER (DIVR( LSE_VALUE, (CFG_RTC_ASYNCH_PRESCALER+1) ) - 1 ) + +#endif + +/** tick timer values */ +#define CFG_TS_TICK_VAL DIVR( (CFG_RTCCLK_DIV * 1000000), LSE_VALUE ) +#define CFG_TS_TICK_VAL_PS DIVR( ((uint64_t)CFG_RTCCLK_DIV * 1e12), (uint64_t)LSE_VALUE ) + +typedef enum +{ + CFG_TIM_PROC_ID_ISR, + /* USER CODE BEGIN CFG_TimProcID_t */ + + /* USER CODE END CFG_TimProcID_t */ +} CFG_TimProcID_t; + +/****************************************************************************** + * Debug + ******************************************************************************/ +/** + * When set, this resets some hw resources to set the device in the same state than the power up + * The FW resets only register that may prevent the FW to run properly + * + * This shall be set to 0 in a final product + * + */ +#define CFG_HW_RESET_BY_FW 1 + +/** + * keep debugger enabled while in any low power mode when set to 1 + * should be set to 0 in production + */ +#define CFG_DEBUGGER_SUPPORTED 0 + +/** + * When set to 1, the traces are enabled in the BLE services + */ +#define CFG_DEBUG_BLE_TRACE 0 + +/** + * Enable or Disable traces in application + */ +#define CFG_DEBUG_APP_TRACE 0 + +#if (CFG_DEBUG_APP_TRACE != 0) +#define APP_DBG_MSG PRINT_MESG_DBG +#else +#define APP_DBG_MSG PRINT_NO_MESG +#endif + +#if ( (CFG_DEBUG_BLE_TRACE != 0) || (CFG_DEBUG_APP_TRACE != 0) ) +#define CFG_DEBUG_TRACE 1 +#endif + +#if (CFG_DEBUG_TRACE != 0) +#undef CFG_LPM_SUPPORTED +#undef CFG_DEBUGGER_SUPPORTED +#define CFG_LPM_SUPPORTED 0 +#define CFG_DEBUGGER_SUPPORTED 1 +#endif + +/** + * When CFG_DEBUG_TRACE_FULL is set to 1, the trace are output with the API name, the file name and the line number + * When CFG_DEBUG_TRACE_LIGHT is set to 1, only the debug message is output + * + * When both are set to 0, no trace are output + * When both are set to 1, CFG_DEBUG_TRACE_FULL is selected + */ +#define CFG_DEBUG_TRACE_LIGHT 0 +#define CFG_DEBUG_TRACE_FULL 0 + +#if (( CFG_DEBUG_TRACE != 0 ) && ( CFG_DEBUG_TRACE_LIGHT == 0 ) && (CFG_DEBUG_TRACE_FULL == 0)) +#undef CFG_DEBUG_TRACE_FULL +#undef CFG_DEBUG_TRACE_LIGHT +#define CFG_DEBUG_TRACE_FULL 0 +#define CFG_DEBUG_TRACE_LIGHT 1 +#endif + +#if ( CFG_DEBUG_TRACE == 0 ) +#undef CFG_DEBUG_TRACE_FULL +#undef CFG_DEBUG_TRACE_LIGHT +#define CFG_DEBUG_TRACE_FULL 0 +#define CFG_DEBUG_TRACE_LIGHT 0 +#endif + +/** + * When not set, the traces is looping on sending the trace over UART + */ +#define DBG_TRACE_USE_CIRCULAR_QUEUE 1 + +/** + * max buffer Size to queue data traces and max data trace allowed. + * Only Used if DBG_TRACE_USE_CIRCULAR_QUEUE is defined + */ +#define DBG_TRACE_MSG_QUEUE_SIZE 4096 +#define MAX_DBG_TRACE_MSG_SIZE 1024 + +/* USER CODE BEGIN Defines */ +#define CFG_LED_SUPPORTED 1 +#define CFG_BUTTON_SUPPORTED 1 + +#define PUSH_BUTTON_SW1_EXTI_IRQHandler EXTI4_IRQHandler +#define PUSH_BUTTON_SW2_EXTI_IRQHandler EXTI0_IRQHandler +#define PUSH_BUTTON_SW3_EXTI_IRQHandler EXTI1_IRQHandler +/* USER CODE END Defines */ + +/****************************************************************************** + * Scheduler + ******************************************************************************/ + +/** + * These are the lists of task id registered to the scheduler + * Each task id shall be in the range [0:31] + * This mechanism allows to implement a generic code in the API TL_BLE_HCI_StatusNot() to comply with + * the requirement that a HCI/ACI command shall never be sent if there is already one pending + */ + +/**< Add in that list all tasks that may send a ACI/HCI command */ +typedef enum +{ + CFG_TASK_BLE_HCI_CMD_ID, + CFG_TASK_SYS_HCI_CMD_ID, + CFG_TASK_HCI_ACL_DATA_ID, + CFG_TASK_SYS_LOCAL_CMD_ID, + CFG_TASK_TX_TO_HOST_ID, + /* USER CODE BEGIN CFG_Task_Id_With_HCI_Cmd_t */ + CFG_TASK_SW1_BUTTON_PUSHED_ID, + CFG_TASK_SW2_BUTTON_PUSHED_ID, + CFG_TASK_SW3_BUTTON_PUSHED_ID, + /* USER CODE END CFG_Task_Id_With_HCI_Cmd_t */ + CFG_LAST_TASK_ID_WITH_HCICMD, /**< Shall be LAST in the list */ +} CFG_Task_Id_With_HCI_Cmd_t; + +/**< Add in that list all tasks that never send a ACI/HCI command */ +typedef enum +{ + CFG_FIRST_TASK_ID_WITH_NO_HCICMD = CFG_LAST_TASK_ID_WITH_HCICMD - 1, /**< Shall be FIRST in the list */ + CFG_TASK_SYSTEM_HCI_ASYNCH_EVT_ID, + /* USER CODE BEGIN CFG_Task_Id_With_NO_HCI_Cmd_t */ + + /* USER CODE END CFG_Task_Id_With_NO_HCI_Cmd_t */ + CFG_LAST_TASK_ID_WITH_NO_HCICMD /**< Shall be LAST in the list */ +} CFG_Task_Id_With_NO_HCI_Cmd_t; + +#define CFG_TASK_NBR CFG_LAST_TASK_ID_WITH_NO_HCICMD + +/** + * This is the list of priority required by the application + * Each Id shall be in the range 0..31 + */ +typedef enum +{ + CFG_SCH_PRIO_0, + /* USER CODE BEGIN CFG_SCH_Prio_Id_t */ + + /* USER CODE END CFG_SCH_Prio_Id_t */ +} CFG_SCH_Prio_Id_t; + +/** + * This is a bit mapping over 32bits listing all events id supported in the application + */ +typedef enum +{ + CFG_IDLEEVT_SYSTEM_HCI_CMD_EVT_RSP_ID, + /* USER CODE BEGIN CFG_IdleEvt_Id_t */ + + /* USER CODE END CFG_IdleEvt_Id_t */ +} CFG_IdleEvt_Id_t; + +/****************************************************************************** + * LOW POWER + ******************************************************************************/ +/** + * Supported requester to the MCU Low Power Manager - can be increased up to 32 + * It list a bit mapping of all user of the Low Power Manager + */ +typedef enum +{ + CFG_LPM_APP, + CFG_LPM_APP_BLE, + /* USER CODE BEGIN CFG_LPM_Id_t */ + + /* USER CODE END CFG_LPM_Id_t */ +} CFG_LPM_Id_t; + +/****************************************************************************** + * OTP manager + ******************************************************************************/ +#define CFG_OTP_BASE_ADDRESS OTP_AREA_BASE + +#define CFG_OTP_END_ADRESS OTP_AREA_END_ADDR + +#endif /*APP_CONF_H */ -#endif /* APP_CONF_DEFAULT_H */ diff --git a/src/utility/STM32Cube_FW/ble_bufsize.h b/src/utility/STM32Cube_FW/ble_bufsize.h index 12b5fdb9..0f0f4192 100644 --- a/src/utility/STM32Cube_FW/ble_bufsize.h +++ b/src/utility/STM32Cube_FW/ble_bufsize.h @@ -75,37 +75,32 @@ ((pw) + MAX(BLE_MEM_BLOCK_X_MTU(mtu, n_link), \ BLE_MBLOCKS_SECURE_CONNECTIONS)) -/* - * BLE_DEFAULT_MBLOCKS_COUNT: default memory blocks count - */ -#define BLE_DEFAULT_MBLOCKS_COUNT(n_link) \ - BLE_MBLOCKS_CALC(BLE_DEFAULT_PREP_WRITE_LIST_SIZE, \ - BLE_DEFAULT_MAX_ATT_MTU, n_link) - /* * BLE_FIXED_BUFFER_SIZE_BYTES: - * A part of the RAM, is dynamically allocated by initializing all the pointers + * A part of the RAM, is dinamically allocated by initilizing all the pointers * defined in a global context variable "mem_alloc_ctx_p". * This initialization is made in the Dynamic_allocator functions, which - * assign a portion of RAM given by the external application to the above + * assing a portion of RAM given by the external application to the above * mentioned "global pointers". * * The size of this Dynamic RAM is made of 2 main components: * - a part that is parameters-dependent (num of links, GATT buffers, ...), - * and which value is defined by the following macro; + * and which value is explicited by the following macro; * - a part, that may be considered "fixed", i.e. independent from the above * mentioned parameters. */ #if (BEACON_ONLY != 0) #define BLE_FIXED_BUFFER_SIZE_BYTES 4076 /* Beacon only */ +#elif (LL_ONLY_BASIC != 0) +#define BLE_FIXED_BUFFER_SIZE_BYTES 5692 /* LL only Basic*/ #elif (LL_ONLY != 0) -#define BLE_FIXED_BUFFER_SIZE_BYTES 5936 /* LL only */ +#define BLE_FIXED_BUFFER_SIZE_BYTES 5940 /* LL only Full */ #elif (SLAVE_ONLY != 0) #define BLE_FIXED_BUFFER_SIZE_BYTES 6204 /* Peripheral only */ #elif (BASIC_FEATURES != 0) #define BLE_FIXED_BUFFER_SIZE_BYTES 6532 /* Basic Features */ #else -#define BLE_FIXED_BUFFER_SIZE_BYTES 7052 /* Full stack */ +#define BLE_FIXED_BUFFER_SIZE_BYTES 7056 /* Full stack */ #endif /* @@ -113,8 +108,10 @@ */ #if (BEACON_ONLY != 0) #define BLE_PER_LINK_SIZE_BYTES 128 /* Beacon only */ +#elif (LL_ONLY_BASIC != 0) +#define BLE_PER_LINK_SIZE_BYTES 260 /* LL only Basic */ #elif (LL_ONLY != 0) -#define BLE_PER_LINK_SIZE_BYTES 260 /* LL only */ +#define BLE_PER_LINK_SIZE_BYTES 260 /* LL only Full */ #elif (SLAVE_ONLY != 0) #define BLE_PER_LINK_SIZE_BYTES 392 /* Peripheral only */ #elif (BASIC_FEATURES != 0) diff --git a/src/utility/STM32Cube_FW/hw.h b/src/utility/STM32Cube_FW/hw.h index fcf04517..503fa2ca 100644 --- a/src/utility/STM32Cube_FW/hw.h +++ b/src/utility/STM32Cube_FW/hw.h @@ -26,21 +26,14 @@ extern "C" { #endif /* Includes ------------------------------------------------------------------*/ -#include "stm32_def.h" -#include "stm32wbxx_ll_bus.h" -#include "stm32wbxx_ll_exti.h" -#include "stm32wbxx_ll_system.h" -#include "stm32wbxx_ll_rcc.h" -#include "stm32wbxx_ll_ipcc.h" -#include "stm32wbxx_ll_cortex.h" -#include "stm32wbxx_ll_utils.h" -#include "stm32wbxx_ll_pwr.h" /****************************************************************************** * HW IPCC ******************************************************************************/ void HW_IPCC_Enable( void ); void HW_IPCC_Init( void ); + void HW_IPCC_Rx_Handler( void ); + void HW_IPCC_Tx_Handler( void ); void HW_IPCC_BLE_Init( void ); void HW_IPCC_BLE_SendCmd( void ); @@ -87,6 +80,23 @@ extern "C" { void HW_IPCC_TRACES_Init( void ); void HW_IPCC_TRACES_EvtNot( void ); + void HW_IPCC_MAC_802_15_4_Init( void ); + void HW_IPCC_MAC_802_15_4_SendCmd( void ); + void HW_IPCC_MAC_802_15_4_SendAck( void ); + void HW_IPCC_MAC_802_15_4_CmdEvtNot( void ); + void HW_IPCC_MAC_802_15_4_EvtNot( void ); + + void HW_IPCC_ZIGBEE_Init( void ); + + void HW_IPCC_ZIGBEE_SendM4RequestToM0(void); /* M4 Request to M0 */ + void HW_IPCC_ZIGBEE_RecvAppliAckFromM0(void); /* Request ACK from M0 */ + + void HW_IPCC_ZIGBEE_RecvM0NotifyToM4(void); /* M0 Notify to M4 */ + void HW_IPCC_ZIGBEE_SendM4AckToM0Notify(void); /* Notify ACK from M4 */ + void HW_IPCC_ZIGBEE_RecvM0RequestToM4(void); /* M0 Request to M4 */ + void HW_IPCC_ZIGBEE_SendM4AckToM0Request(void); /* Request ACK from M4 */ + + #ifdef __cplusplus } #endif diff --git a/src/utility/STM32Cube_FW/hw_ipcc.c b/src/utility/STM32Cube_FW/hw_ipcc.c index 2f4f6cc2..fd620b85 100644 --- a/src/utility/STM32Cube_FW/hw_ipcc.c +++ b/src/utility/STM32Cube_FW/hw_ipcc.c @@ -18,9 +18,8 @@ */ /* USER CODE END Header */ -#if defined(STM32WBxx) /* Includes ------------------------------------------------------------------*/ -#include "hw.h" +#include "app_common.h" #include "mbox_def.h" /* Global variables ---------------------------------------------------------*/ @@ -57,17 +56,34 @@ static void HW_IPCC_LLD_BLE_ReceiveRspHandler( void ); static void HW_IPCC_LLD_BLE_ReceiveM0CmdHandler( void ); #endif +#ifdef MAC_802_15_4_WB +static void HW_IPCC_MAC_802_15_4_CmdEvtHandler( void ); +static void HW_IPCC_MAC_802_15_4_NotEvtHandler( void ); +#endif + +#ifdef ZIGBEE_WB +static void HW_IPCC_ZIGBEE_CmdEvtHandler( void ); +static void HW_IPCC_ZIGBEE_StackNotifEvtHandler( void ); +static void HW_IPCC_ZIGBEE_StackM0RequestHandler( void ); +#endif + /* Public function definition -----------------------------------------------*/ /****************************************************************************** * INTERRUPT HANDLER ******************************************************************************/ -void IPCC_C1_RX_IRQHandler(void) +void HW_IPCC_Rx_Handler( void ) { if (HW_IPCC_RX_PENDING( HW_IPCC_SYSTEM_EVENT_CHANNEL )) { HW_IPCC_SYS_EvtHandler(); } +#ifdef MAC_802_15_4_WB + else if (HW_IPCC_RX_PENDING( HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL )) + { + HW_IPCC_MAC_802_15_4_NotEvtHandler(); + } +#endif /* MAC_802_15_4_WB */ #ifdef THREAD_WB else if (HW_IPCC_RX_PENDING( HW_IPCC_THREAD_NOTIFICATION_ACK_CHANNEL )) { @@ -98,6 +114,16 @@ void IPCC_C1_RX_IRQHandler(void) HW_IPCC_LLD_BLE_ReceiveM0CmdHandler(); } #endif /* LLD_TESTS_WB */ +#ifdef ZIGBEE_WB + else if (HW_IPCC_RX_PENDING( HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL )) + { + HW_IPCC_ZIGBEE_StackNotifEvtHandler(); + } + else if (HW_IPCC_RX_PENDING( HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL )) + { + HW_IPCC_ZIGBEE_StackM0RequestHandler(); + } +#endif /* ZIGBEE_WB */ else if (HW_IPCC_RX_PENDING( HW_IPCC_BLE_EVENT_CHANNEL )) { HW_IPCC_BLE_EvtHandler(); @@ -106,14 +132,22 @@ void IPCC_C1_RX_IRQHandler(void) { HW_IPCC_TRACES_EvtHandler(); } + + return; } -void IPCC_C1_TX_IRQHandler(void) +void HW_IPCC_Tx_Handler( void ) { if (HW_IPCC_TX_PENDING( HW_IPCC_SYSTEM_CMD_RSP_CHANNEL )) { HW_IPCC_SYS_CmdEvtHandler(); } +#ifdef MAC_802_15_4_WB + else if (HW_IPCC_TX_PENDING( HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL )) + { + HW_IPCC_MAC_802_15_4_CmdEvtHandler(); + } +#endif /* MAC_802_15_4_WB */ #ifdef THREAD_WB else if (HW_IPCC_TX_PENDING( HW_IPCC_THREAD_OT_CMD_RSP_CHANNEL )) { @@ -123,6 +157,12 @@ void IPCC_C1_TX_IRQHandler(void) #ifdef LLD_TESTS_WB // No TX handler for LLD tests #endif /* LLD_TESTS_WB */ +#ifdef ZIGBEE_WB + if (HW_IPCC_TX_PENDING( HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL )) + { + HW_IPCC_ZIGBEE_CmdEvtHandler(); + } +#endif /* ZIGBEE_WB */ else if (HW_IPCC_TX_PENDING( HW_IPCC_MM_RELEASE_BUFFER_CHANNEL )) { HW_IPCC_MM_FreeBufHandler(); @@ -131,8 +171,9 @@ void IPCC_C1_TX_IRQHandler(void) { HW_IPCC_BLE_AclDataEvtHandler(); } -} + return; +} /****************************************************************************** * GENERAL ******************************************************************************/ @@ -140,15 +181,16 @@ void HW_IPCC_Enable( void ) { /** * Such as IPCC IP available to the CPU2, it is required to keep the IPCC clock running - when FUS is running on CPU2 and CPU1 enters deep sleep mode + * when FUS is running on CPU2 and CPU1 enters deep sleep mode */ LL_C2_AHB3_GRP1_EnableClock(LL_C2_AHB3_GRP1_PERIPH_IPCC); - /** - * When the device is out of standby, it is required to use the EXTI mechanism to wakeup CPU2 - */ - LL_C2_EXTI_EnableEvent_32_63( LL_EXTI_LINE_41 ); + /** + * When the device is out of standby, it is required to use the EXTI mechanism to wakeup CPU2 + */ LL_EXTI_EnableRisingTrig_32_63( LL_EXTI_LINE_41 ); + /* It is required to have at least a system clock cycle before a SEV after LL_EXTI_EnableRisingTrig_32_63() */ + LL_C2_EXTI_EnableEvent_32_63( LL_EXTI_LINE_41 ); /** * In case the SBSFU is implemented, it may have already set the C2BOOT bit to startup the CPU2. @@ -222,8 +264,8 @@ static void HW_IPCC_BLE_AclDataEvtHandler( void ) return; } -__WEAK void HW_IPCC_BLE_AclDataAckNot( void ){}; -__WEAK void HW_IPCC_BLE_RxEvtNot( void ){}; +__weak void HW_IPCC_BLE_AclDataAckNot( void ){}; +__weak void HW_IPCC_BLE_RxEvtNot( void ){}; /****************************************************************************** * SYSTEM @@ -261,8 +303,56 @@ static void HW_IPCC_SYS_EvtHandler( void ) return; } -__WEAK void HW_IPCC_SYS_CmdEvtNot( void ){}; -__WEAK void HW_IPCC_SYS_EvtNot( void ){}; +__weak void HW_IPCC_SYS_CmdEvtNot( void ){}; +__weak void HW_IPCC_SYS_EvtNot( void ){}; + +/****************************************************************************** + * MAC 802.15.4 + ******************************************************************************/ +#ifdef MAC_802_15_4_WB +void HW_IPCC_MAC_802_15_4_Init( void ) +{ + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL ); + + return; +} + +void HW_IPCC_MAC_802_15_4_SendCmd( void ) +{ + LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL ); + LL_C1_IPCC_EnableTransmitChannel( IPCC, HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL ); + + return; +} + +void HW_IPCC_MAC_802_15_4_SendAck( void ) +{ + LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL ); + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL ); + + return; +} + +static void HW_IPCC_MAC_802_15_4_CmdEvtHandler( void ) +{ + LL_C1_IPCC_DisableTransmitChannel( IPCC, HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL ); + + HW_IPCC_MAC_802_15_4_CmdEvtNot(); + + return; +} + +static void HW_IPCC_MAC_802_15_4_NotEvtHandler( void ) +{ + LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL ); + + HW_IPCC_MAC_802_15_4_EvtNot(); + + return; +} +__weak void HW_IPCC_MAC_802_15_4_CmdEvtNot( void ){}; +__weak void HW_IPCC_MAC_802_15_4_EvtNot( void ){}; +#endif /****************************************************************************** * THREAD @@ -334,9 +424,9 @@ static void HW_IPCC_THREAD_CliNotEvtHandler( void ) return; } -__WEAK void HW_IPCC_OT_CmdEvtNot( void ){}; -__WEAK void HW_IPCC_CLI_CmdEvtNot( void ){}; -__WEAK void HW_IPCC_THREAD_EvtNot( void ){}; +__weak void HW_IPCC_OT_CmdEvtNot( void ){}; +__weak void HW_IPCC_CLI_CmdEvtNot( void ){}; +__weak void HW_IPCC_THREAD_EvtNot( void ){}; #endif /* THREAD_WB */ @@ -458,6 +548,74 @@ void HW_IPCC_LLD_BLE_SendRspAck( void ) #endif /* LLD_BLE_WB */ +/****************************************************************************** + * ZIGBEE + ******************************************************************************/ +#ifdef ZIGBEE_WB +void HW_IPCC_ZIGBEE_Init( void ) +{ + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL ); + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL ); + + return; +} + +void HW_IPCC_ZIGBEE_SendM4RequestToM0( void ) +{ + LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL ); + LL_C1_IPCC_EnableTransmitChannel( IPCC, HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL ); + + return; +} + +void HW_IPCC_ZIGBEE_SendM4AckToM0Notify( void ) +{ + LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL ); + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL ); + + return; +} + +static void HW_IPCC_ZIGBEE_CmdEvtHandler( void ) +{ + LL_C1_IPCC_DisableTransmitChannel( IPCC, HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL ); + + HW_IPCC_ZIGBEE_RecvAppliAckFromM0(); + + return; +} + +static void HW_IPCC_ZIGBEE_StackNotifEvtHandler( void ) +{ + LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL ); + + HW_IPCC_ZIGBEE_RecvM0NotifyToM4(); + + return; +} + +static void HW_IPCC_ZIGBEE_StackM0RequestHandler( void ) +{ + LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL ); + + HW_IPCC_ZIGBEE_RecvM0RequestToM4(); + + return; +} + +void HW_IPCC_ZIGBEE_SendM4AckToM0Request( void ) +{ + LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL ); + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL ); + + return; +} + +__weak void HW_IPCC_ZIGBEE_RecvAppliAckFromM0( void ){}; +__weak void HW_IPCC_ZIGBEE_RecvM0NotifyToM4( void ){}; +__weak void HW_IPCC_ZIGBEE_RecvM0RequestToM4( void ){}; +#endif /* ZIGBEE_WB */ + /****************************************************************************** * MEMORY MANAGER ******************************************************************************/ @@ -508,5 +666,4 @@ static void HW_IPCC_TRACES_EvtHandler( void ) return; } -__WEAK void HW_IPCC_TRACES_EvtNot( void ){}; -#endif /* STM32WBxx */ +__weak void HW_IPCC_TRACES_EvtNot( void ){}; diff --git a/src/utility/STM32Cube_FW/mbox_def.h b/src/utility/STM32Cube_FW/mbox_def.h index c898e52a..68b71f9c 100644 --- a/src/utility/STM32Cube_FW/mbox_def.h +++ b/src/utility/STM32Cube_FW/mbox_def.h @@ -91,6 +91,7 @@ extern "C" { uint8_t *notack_buffer; uint8_t *clicmdrsp_buffer; uint8_t *otcmdrsp_buffer; + uint8_t *clinot_buffer; } MB_ThreadTable_t; typedef struct @@ -105,6 +106,12 @@ extern "C" { uint8_t *m0cmd_buffer; } MB_BleLldTable_t; + typedef struct + { + uint8_t *notifM0toM4_buffer; + uint8_t *appliCmdM4toM0_buffer; + uint8_t *requestM0toM4_buffer; + } MB_ZigbeeTable_t; /** * msg * [0:7] = cmd/evt @@ -132,6 +139,13 @@ extern "C" { uint8_t *traces_queue; } MB_TracesTable_t; + typedef struct + { + uint8_t *p_cmdrsp_buffer; + uint8_t *p_notack_buffer; + uint8_t *evt_queue; + } MB_Mac_802_15_4_t; + typedef struct { MB_DeviceInfoTable_t *p_device_info_table; @@ -140,6 +154,8 @@ extern "C" { MB_SysTable_t *p_sys_table; MB_MemManagerTable_t *p_mem_manager_table; MB_TracesTable_t *p_traces_table; + MB_Mac_802_15_4_t *p_mac_802_15_4_table; + MB_ZigbeeTable_t *p_zigbee_table; MB_LldTestsTable_t *p_lld_tests_table; MB_BleLldTable_t *p_ble_lld_table; } MB_RefTable_t; @@ -183,6 +199,15 @@ typedef struct * | | * |<---HW_IPCC_SYSTEM_EVENT_CHANNEL-----------------| * | | + * | (ZIGBEE) | + * |----HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL------------>| + * | | + * |----HW_IPCC_ZIGBEE_CMD_CLI_CHANNEL-------------->| + * | | + * |<---HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL-------| + * | | + * |<---HW_IPCC_ZIGBEE_CLI_NOTIF_ACK_CHANNEL---------| + * | | * | (THREAD) | * |----HW_IPCC_THREAD_OT_CMD_RSP_CHANNEL----------->| * | | @@ -206,6 +231,11 @@ typedef struct * | | * |<---HW_IPCC_BLE_LLD_M0_CMD_CHANNEL---------------| * | | + * | (MAC) | + * |----HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL-------->| + * | | + * |<---HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL| + * | | * | (BUFFER) | * |----HW_IPCC_MM_RELEASE_BUFFER_CHANNE------------>| * | | @@ -223,6 +253,8 @@ typedef struct #define HW_IPCC_BLE_CMD_CHANNEL LL_IPCC_CHANNEL_1 #define HW_IPCC_SYSTEM_CMD_RSP_CHANNEL LL_IPCC_CHANNEL_2 #define HW_IPCC_THREAD_OT_CMD_RSP_CHANNEL LL_IPCC_CHANNEL_3 +#define HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL LL_IPCC_CHANNEL_3 +#define HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL LL_IPCC_CHANNEL_3 #define HW_IPCC_MM_RELEASE_BUFFER_CHANNEL LL_IPCC_CHANNEL_4 #define HW_IPCC_THREAD_CLI_CMD_CHANNEL LL_IPCC_CHANNEL_5 #define HW_IPCC_LLDTESTS_CLI_CMD_CHANNEL LL_IPCC_CHANNEL_5 @@ -234,6 +266,8 @@ typedef struct #define HW_IPCC_BLE_EVENT_CHANNEL LL_IPCC_CHANNEL_1 #define HW_IPCC_SYSTEM_EVENT_CHANNEL LL_IPCC_CHANNEL_2 #define HW_IPCC_THREAD_NOTIFICATION_ACK_CHANNEL LL_IPCC_CHANNEL_3 +#define HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL LL_IPCC_CHANNEL_3 +#define HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL LL_IPCC_CHANNEL_3 #define HW_IPCC_LLDTESTS_M0_CMD_CHANNEL LL_IPCC_CHANNEL_3 #define HW_IPCC_BLE_LLD_M0_CMD_CHANNEL LL_IPCC_CHANNEL_3 #define HW_IPCC_TRACES_CHANNEL LL_IPCC_CHANNEL_4 @@ -241,5 +275,6 @@ typedef struct #define HW_IPCC_LLDTESTS_CLI_RSP_CHANNEL LL_IPCC_CHANNEL_5 #define HW_IPCC_BLE_LLD_CLI_RSP_CHANNEL LL_IPCC_CHANNEL_5 #define HW_IPCC_BLE_LLD_RSP_CHANNEL LL_IPCC_CHANNEL_5 +#define HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL LL_IPCC_CHANNEL_5 #endif /*__MBOX_H */ diff --git a/src/utility/STM32Cube_FW/shci.c b/src/utility/STM32Cube_FW/shci.c index bd7bb3a1..472a108e 100644 --- a/src/utility/STM32Cube_FW/shci.c +++ b/src/utility/STM32Cube_FW/shci.c @@ -16,7 +16,7 @@ ****************************************************************************** */ -#if defined(STM32WBxx) + /* Includes ------------------------------------------------------------------*/ #include "stm32_wpan_common.h" @@ -352,6 +352,24 @@ SHCI_CmdStatus_t SHCI_C2_BLE_LLD_Init( uint8_t param_size, uint8_t * p_param ) return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); } +SHCI_CmdStatus_t SHCI_C2_ZIGBEE_Init( void ) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send( SHCI_OPCODE_C2_ZIGBEE_INIT, + 0, + 0, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + SHCI_CmdStatus_t SHCI_C2_DEBUG_Init( SHCI_C2_DEBUG_Init_Cmd_Packet_t *pCmdPacket ) { /** @@ -509,6 +527,24 @@ SHCI_CmdStatus_t SHCI_C2_RADIO_AllowLowPower( SHCI_C2_FLASH_Ip_t Ip,uint8_t Fla return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); } +SHCI_CmdStatus_t SHCI_C2_MAC_802_15_4_Init( void ) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send( SHCI_OPCODE_C2_MAC_802_15_4_INIT, + 0, + 0, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + SHCI_CmdStatus_t SHCI_C2_Reinit( void ) { /** @@ -703,5 +739,4 @@ SHCI_CmdStatus_t SHCI_GetWirelessFwInfo( WirelessFwInfo_t* pWirelessInfo ) return (SHCI_Success); } -#endif /* STM32WBxx */ diff --git a/src/utility/STM32Cube_FW/shci.h b/src/utility/STM32Cube_FW/shci.h index d965ec84..102089e2 100644 --- a/src/utility/STM32Cube_FW/shci.h +++ b/src/utility/STM32Cube_FW/shci.h @@ -49,6 +49,7 @@ extern "C" { ERR_BLE_INIT = 0, /* This event is currently not reported by the CPU2 */ ERR_THREAD_LLD_FATAL_ERROR = 125, /* The LLD driver used on 802_15_4 detected a fatal error */ ERR_THREAD_UNKNOWN_CMD = 126, /* The command send by the CPU1 to control the Thread stack is unknown */ + ERR_ZIGBEE_UNKNOWN_CMD = 200, /* The command send by the CPU1 to control the Zigbee stack is unknown */ } SCHI_SystemErrCode_t; #define SHCI_EVTCODE ( 0xFF ) @@ -101,7 +102,7 @@ extern "C" { /** * SHCI_SUB_EVT_THREAD_NVM_RAM_UPDATE - * This notifies the CPU1 which part of the 'OT NVM RAM' has been updated so that only the modified + * This notifies the CPU1 which part of the OT NVM RAM has been updated so that only the modified * section could be written in Flash/NVM * StartAddress : Start address of the section that has been modified * Size : Size (in bytes) of the section that has been modified @@ -162,9 +163,11 @@ extern "C" { { SHCI_Success = 0x00, SHCI_UNKNOWN_CMD = 0x01, + SHCI_MEMORY_CAPACITY_EXCEEDED_ERR_CODE= 0x07, SHCI_ERR_UNSUPPORTED_FEATURE = 0x11, SHCI_ERR_INVALID_HCI_CMD_PARAMS = 0x12, - SHCI_ERR_INVALID_PARAMS = 0x42, + SHCI_ERR_INVALID_PARAMS = 0x42, /* only used for release < v1.13.0 */ + SHCI_ERR_INVALID_PARAMS_V2 = 0x92, /* available for release >= v1.13.0 */ SHCI_FUS_CMD_NOT_SUPPORTED = 0xFF, } SHCI_CmdStatus_t; @@ -213,7 +216,9 @@ extern "C" { SHCI_OCF_C2_FLASH_STORE_DATA, SHCI_OCF_C2_FLASH_ERASE_DATA, SHCI_OCF_C2_RADIO_ALLOW_LOW_POWER, + SHCI_OCF_C2_MAC_802_15_4_INIT, SHCI_OCF_C2_REINIT, + SHCI_OCF_C2_ZIGBEE_INIT, SHCI_OCF_C2_LLD_TESTS_INIT, SHCI_OCF_C2_EXTPA_CONFIG, SHCI_OCF_C2_SET_FLASH_ACTIVITY_CONTROL, @@ -487,10 +492,9 @@ extern "C" { /** * LsSource - * Source for the 32 kHz slow speed clock. - * - External crystal LSE: 0 - No calibration - * - Others:1 - As the accuracy of this oscillator can vary depending upon external conditions (temperature), - * it is calibrated every second to ensure correct behavior of timing sensitive BLE operations + * Some information for Low speed clock mapped in bits field + * - bit 0: 1: Calibration for the RF system wakeup clock source 0: No calibration for the RF system wakeup clock source + * - bit 1: 1: STM32W5M Module device 0: Other devices as STM32WBxx SOC, STM32WB1M module */ uint8_t LsSource; @@ -564,6 +568,32 @@ extern "C" { */ uint8_t rx_model_config; + /* Maximum number of advertising sets. + * Range: 1 .. 8 with limitation: + * This parameter is linked to max_adv_data_len such as both compliant with allocated Total memory computed with BLE_EXT_ADV_BUFFER_SIZE based + * on Max Extended advertising configuration supported. + * This parameter is considered by the CPU2 when Options has SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV flag set + */ + uint8_t max_adv_set_nbr; + + /* Maximum advertising data length (in bytes) + * Range: 31 .. 1650 with limitation: + * This parameter is linked to max_adv_set_nbr such as both compliant with allocated Total memory computed with BLE_EXT_ADV_BUFFER_SIZE based + * on Max Extended advertising configuration supported. + * This parameter is considered by the CPU2 when Options has SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV flag set + */ + uint16_t max_adv_data_len; + + /* RF TX Path Compensation Value (16-bit signed integer). Units: 0.1 dB. + * Range: -1280 .. 1280 + */ + int16_t tx_path_compens; + + /* RF RX Path Compensation Value (16-bit signed integer). Units: 0.1 dB. + * Range: -1280 .. 1280 + */ + int16_t rx_path_compens; + } SHCI_C2_Ble_Init_Cmd_Param_t; typedef PACKED_STRUCT{ @@ -600,6 +630,13 @@ extern "C" { #define SHCI_C2_BLE_INIT_RX_MODEL_AGC_RSSI_LEGACY (0<<0) #define SHCI_C2_BLE_INIT_RX_MODEL_AGC_RSSI_BLOCKER (1<<0) + /** + * LsSource information + */ +#define SHCI_C2_BLE_INIT_CFG_BLE_LSE_NOCALIB (0<<0) +#define SHCI_C2_BLE_INIT_CFG_BLE_LSE_CALIB (1<<0) +#define SHCI_C2_BLE_INIT_CFG_BLE_LSE_OTHER_DEV (0<<1) +#define SHCI_C2_BLE_INIT_CFG_BLE_LSE_MOD5MM_DEV (1<<1) #define SHCI_OPCODE_C2_THREAD_INIT (( SHCI_OGF << 10) + SHCI_OCF_C2_THREAD_INIT) /** No command parameters */ @@ -611,6 +648,8 @@ extern "C" { { uint8_t thread_config; uint8_t ble_config; + uint8_t mac_802_15_4_config; + uint8_t zigbee_config; } SHCI_C2_DEBUG_TracesConfig_t; typedef PACKED_STRUCT @@ -624,6 +663,11 @@ extern "C" { */ uint8_t sys_dbg_cfg1; uint8_t reserved[2]; + uint16_t STBY_DebugGpioaPinList; + uint16_t STBY_DebugGpiobPinList; + uint16_t STBY_DebugGpiocPinList; + uint16_t STBY_DtbGpioaPinList; + uint16_t STBY_DtbGpiobPinList; } SHCI_C2_DEBUG_GeneralConfig_t; typedef PACKED_STRUCT{ @@ -669,6 +713,8 @@ extern "C" { { BLE_ENABLE, THREAD_ENABLE, + ZIGBEE_ENABLE, + MAC_ENABLE, } SHCI_C2_CONCURRENT_Mode_Param_t; /** No response parameters*/ @@ -691,13 +737,18 @@ extern "C" { { BLE_IP, THREAD_IP, + ZIGBEE_IP, } SHCI_C2_FLASH_Ip_t; /** No response parameters*/ #define SHCI_OPCODE_C2_RADIO_ALLOW_LOW_POWER (( SHCI_OGF << 10) + SHCI_OCF_C2_RADIO_ALLOW_LOW_POWER) +#define SHCI_OPCODE_C2_MAC_802_15_4_INIT (( SHCI_OGF << 10) + SHCI_OCF_C2_MAC_802_15_4_INIT) + #define SHCI_OPCODE_C2_REINIT (( SHCI_OGF << 10) + SHCI_OCF_C2_REINIT) +#define SHCI_OPCODE_C2_ZIGBEE_INIT (( SHCI_OGF << 10) + SHCI_OCF_C2_ZIGBEE_INIT) + #define SHCI_OPCODE_C2_LLD_TESTS_INIT (( SHCI_OGF << 10) + SHCI_OCF_C2_LLD_TESTS_INIT) #define SHCI_OPCODE_C2_BLE_LLD_INIT (( SHCI_OGF << 10) + SHCI_OCF_C2_BLE_LLD_INIT) @@ -805,7 +856,7 @@ extern "C" { #define FUS_DEVICE_INFO_TABLE_VALIDITY_KEYWORD (0xA94656B9) /* - * At startup, the information relative to the wireless binary are stored in RAM through a structure defined by + * At startup, the informations relative to the wireless binary are stored in RAM trough a structure defined by * MB_WirelessFwInfoTable_t.This structure contains 4 fields (Version,MemorySize, Stack_info and a reserved part) * each of those coded on 32 bits as shown on the table below: * @@ -861,6 +912,9 @@ extern "C" { #define INFO_STACK_TYPE_BLE_HCI_EXT_ADV 0x07 #define INFO_STACK_TYPE_THREAD_FTD 0x10 #define INFO_STACK_TYPE_THREAD_MTD 0x11 +#define INFO_STACK_TYPE_ZIGBEE_FFD 0x30 +#define INFO_STACK_TYPE_ZIGBEE_RFD 0x31 +#define INFO_STACK_TYPE_MAC 0x40 #define INFO_STACK_TYPE_BLE_THREAD_FTD_STATIC 0x50 #define INFO_STACK_TYPE_BLE_THREAD_FTD_DYAMIC 0x51 #define INFO_STACK_TYPE_802154_LLD_TESTS 0x60 @@ -869,7 +923,12 @@ extern "C" { #define INFO_STACK_TYPE_BLE_LLD_TESTS 0x63 #define INFO_STACK_TYPE_BLE_RLV 0x64 #define INFO_STACK_TYPE_802154_RLV 0x65 +#define INFO_STACK_TYPE_BLE_ZIGBEE_FFD_STATIC 0x70 +#define INFO_STACK_TYPE_BLE_ZIGBEE_RFD_STATIC 0x71 +#define INFO_STACK_TYPE_BLE_ZIGBEE_FFD_DYNAMIC 0x78 +#define INFO_STACK_TYPE_BLE_ZIGBEE_RFD_DYNAMIC 0x79 #define INFO_STACK_TYPE_RLV 0x80 +#define INFO_STACK_TYPE_BLE_MAC_STATIC 0x90 typedef struct { /** @@ -1043,7 +1102,7 @@ typedef struct { * @brief Starts the LLD tests CLI * * @param param_size : Nb of bytes - * @param p_param : pointer with data to give from M4 to M0 + * @param p_param : pointeur with data to give from M4 to M0 * @retval Status */ SHCI_CmdStatus_t SHCI_C2_LLDTESTS_Init( uint8_t param_size, uint8_t * p_param ); @@ -1053,11 +1112,20 @@ typedef struct { * @brief Starts the LLD tests BLE * * @param param_size : Nb of bytes - * @param p_param : pointer with data to give from M4 to M0 + * @param p_param : pointeur with data to give from M4 to M0 * @retval Status */ SHCI_CmdStatus_t SHCI_C2_BLE_LLD_Init( uint8_t param_size, uint8_t * p_param ); + /** + * SHCI_C2_ZIGBEE_Init + * @brief Starts the Zigbee Stack + * + * @param None + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_ZIGBEE_Init( void ); + /** * SHCI_C2_DEBUG_Init * @brief Starts the Traces @@ -1132,6 +1200,16 @@ typedef struct { */ SHCI_CmdStatus_t SHCI_C2_RADIO_AllowLowPower( SHCI_C2_FLASH_Ip_t Ip,uint8_t FlagRadioLowPowerOn); + + /** + * SHCI_C2_MAC_802_15_4_Init + * @brief Starts the MAC 802.15.4 on M0 + * + * @param None + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_MAC_802_15_4_Init( void ); + /** * SHCI_GetWirelessFwInfo * @brief This function read back the informations relative to the wireless binary loaded. @@ -1219,7 +1297,7 @@ typedef struct { * When set to 0, data are kept in internal SRAM on CPU2 * Otherwise, data are copied in the cache pointed by ThreadNvmRamAddress * The size of the buffer shall be THREAD_NVM_SRAM_SIZE (number of 32bits) - * The buffer shall be allocated in SRAM2 + * The buffer shall be allocated in SRAM1 * * Please check macro definition to be used for this function * They are defined in this file next to the definition of SHCI_OPCODE_C2_CONFIG diff --git a/src/utility/STM32Cube_FW/shci_tl.c b/src/utility/STM32Cube_FW/shci_tl.c index 6cccc5dd..ddb3a02b 100644 --- a/src/utility/STM32Cube_FW/shci_tl.c +++ b/src/utility/STM32Cube_FW/shci_tl.c @@ -16,15 +16,12 @@ ****************************************************************************** */ -#if defined(STM32WBxx) + /* Includes ------------------------------------------------------------------*/ #include "stm32_wpan_common.h" -#include <Arduino.h> - #include "stm_list.h" #include "shci_tl.h" -#include "stm32_def.h" /* Private typedef -----------------------------------------------------------*/ typedef enum @@ -171,20 +168,6 @@ void shci_send( uint16_t cmd_code, uint8_t len_cmd_payload, uint8_t * p_cmd_payl return; } -void shci_notify_asynch_evt(void *pdata) -{ - UNUSED(pdata); - /* Need to parse data in future version */ - shci_user_evt_proc(); -} - -void shci_register_io_bus(tSHciIO *fops) -{ - /* Register IO bus services */ - fops->Init = TL_SYS_Init; - fops->Send = TL_SYS_SendCmd; -} - /* Private functions ---------------------------------------------------------*/ static void TlInit( TL_CmdPacket_t * p_cmdbuffer ) { @@ -252,12 +235,11 @@ static void TlUserEvtReceived(TL_EvtPacket_t *shcievt) /* Weak implementation ----------------------------------------------------------------*/ __WEAK void shci_cmd_resp_wait(uint32_t timeout) { + (void)timeout; + CmdRspStatusFlag = SHCI_TL_CMD_RESP_WAIT; - for (unsigned long start = millis(); (millis() - start) < timeout;) { - if (CmdRspStatusFlag == SHCI_TL_CMD_RESP_RELEASE) { - break; - } - } + while(CmdRspStatusFlag != SHCI_TL_CMD_RESP_RELEASE); + return; } @@ -270,5 +252,4 @@ __WEAK void shci_cmd_resp_release(uint32_t flag) return; } -#endif /* STM32WBxx */ diff --git a/src/utility/STM32Cube_FW/stm32_wpan_common.h b/src/utility/STM32Cube_FW/stm32_wpan_common.h index 5a2b2a55..b47b804a 100644 --- a/src/utility/STM32Cube_FW/stm32_wpan_common.h +++ b/src/utility/STM32Cube_FW/stm32_wpan_common.h @@ -25,9 +25,19 @@ extern "C" { #endif -#define __ASM __asm /*!< asm keyword for GNU Compiler */ -#define __INLINE inline /*!< inline keyword for GNU Compiler */ -#define __STATIC_INLINE static inline +#if defined ( __CC_ARM ) + #define __ASM __asm /*!< asm keyword for ARM Compiler */ + #define __INLINE __inline /*!< inline keyword for ARM Compiler */ + #define __STATIC_INLINE static __inline +#elif defined ( __ICCARM__ ) + #define __ASM __asm /*!< asm keyword for IAR Compiler */ + #define __INLINE inline /*!< inline keyword for IAR Compiler. Only available in High optimization mode! */ + #define __STATIC_INLINE static inline +#elif defined ( __GNUC__ ) + #define __ASM __asm /*!< asm keyword for GNU Compiler */ + #define __INLINE inline /*!< inline keyword for GNU Compiler */ + #define __STATIC_INLINE static inline +#endif #include <stdint.h> #include <string.h> @@ -130,8 +140,29 @@ extern "C" { /* ----------------------------------- * * Packed usage (compiler dependent) * * ----------------------------------- */ +#undef PACKED__ #undef PACKED_STRUCT -#define PACKED_STRUCT struct __packed + +#if defined ( __CC_ARM ) + #if defined ( __GNUC__ ) + /* GNU extension */ + #define PACKED__ __attribute__((packed)) + #define PACKED_STRUCT struct PACKED__ + #elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050U) + #define PACKED__ __attribute__((packed)) + #define PACKED_STRUCT struct PACKED__ + #else + #define PACKED__(TYPE) __packed TYPE + #define PACKED_STRUCT PACKED__(struct) + #endif +#elif defined ( __GNUC__ ) + #define PACKED__ __attribute__((packed)) + #define PACKED_STRUCT struct PACKED__ +#elif defined (__ICCARM__) + #define PACKED_STRUCT __packed struct +#else + #define PACKED_STRUCT __packed struct +#endif #ifdef __cplusplus } diff --git a/src/utility/STM32Cube_FW/stm_list.c b/src/utility/STM32Cube_FW/stm_list.c index d8c9e093..4c928647 100644 --- a/src/utility/STM32Cube_FW/stm_list.c +++ b/src/utility/STM32Cube_FW/stm_list.c @@ -1,208 +1,206 @@ -/** - ****************************************************************************** - * @file stm_list.c - * @author MCD Application Team - * @brief TCircular Linked List Implementation. - ****************************************************************************** - * @attention - * - * Copyright (c) 2018-2021 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ - -#if defined(STM32WBxx) -/****************************************************************************** - * Include Files - ******************************************************************************/ -#include "stm_list.h" -#include "cmsis_gcc.h" -#include "stm32_wpan_common.h" - -/****************************************************************************** - * Function Definitions - ******************************************************************************/ -void LST_init_head (tListNode * listHead) -{ - listHead->next = listHead; - listHead->prev = listHead; -} - -bool LST_is_empty (tListNode * listHead) -{ - uint32_t primask_bit; - bool return_value; - - primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ - __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ - if(listHead->next == listHead) - { - return_value = TRUE; - } - else - { - return_value = FALSE; - } - __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ - - return return_value; -} - -void LST_insert_head (tListNode * listHead, tListNode * node) -{ - uint32_t primask_bit; - - primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ - __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ - - node->next = listHead->next; - node->prev = listHead; - listHead->next = node; - (node->next)->prev = node; - - __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ -} - - -void LST_insert_tail (tListNode * listHead, tListNode * node) -{ - uint32_t primask_bit; - - primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ - __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ - - node->next = listHead; - node->prev = listHead->prev; - listHead->prev = node; - (node->prev)->next = node; - - __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ -} - - -void LST_remove_node (tListNode * node) -{ - uint32_t primask_bit; - - primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ - __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ - - (node->prev)->next = node->next; - (node->next)->prev = node->prev; - - __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ -} - - -void LST_remove_head (tListNode * listHead, tListNode ** node ) -{ - uint32_t primask_bit; - - primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ - __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ - - *node = listHead->next; - LST_remove_node (listHead->next); - - __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ -} - - -void LST_remove_tail (tListNode * listHead, tListNode ** node ) -{ - uint32_t primask_bit; - - primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ - __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ - - *node = listHead->prev; - LST_remove_node (listHead->prev); - - __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ -} - - -void LST_insert_node_after (tListNode * node, tListNode * ref_node) -{ - uint32_t primask_bit; - - primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ - __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ - - node->next = ref_node->next; - node->prev = ref_node; - ref_node->next = node; - (node->next)->prev = node; - - __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ -} - - -void LST_insert_node_before (tListNode * node, tListNode * ref_node) -{ - uint32_t primask_bit; - - primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ - __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ - - node->next = ref_node; - node->prev = ref_node->prev; - ref_node->prev = node; - (node->prev)->next = node; - - __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ -} - - -int LST_get_size (tListNode * listHead) -{ - int size = 0; - tListNode * temp; - uint32_t primask_bit; - - primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ - __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ - - temp = listHead->next; - while (temp != listHead) - { - size++; - temp = temp->next; - } - - __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ - - return (size); -} - -void LST_get_next_node (tListNode * ref_node, tListNode ** node) -{ - uint32_t primask_bit; - - primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ - __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ - - *node = ref_node->next; - - __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ -} - - -void LST_get_prev_node (tListNode * ref_node, tListNode ** node) -{ - uint32_t primask_bit; - - primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ - __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ - - *node = ref_node->prev; - - __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ -} - -#endif /* STM32WBxx */ \ No newline at end of file +/** + ****************************************************************************** + * @file stm_list.c + * @author MCD Application Team + * @brief TCircular Linked List Implementation. + ****************************************************************************** + * @attention + * + * Copyright (c) 2018-2021 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ + + +/****************************************************************************** + * Include Files + ******************************************************************************/ +#include "utilities_common.h" + +#include "stm_list.h" + +/****************************************************************************** + * Function Definitions + ******************************************************************************/ +void LST_init_head (tListNode * listHead) +{ + listHead->next = listHead; + listHead->prev = listHead; +} + +uint8_t LST_is_empty (tListNode * listHead) +{ + uint32_t primask_bit; + uint8_t return_value; + + primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ + __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ + if(listHead->next == listHead) + { + return_value = TRUE; + } + else + { + return_value = FALSE; + } + __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ + + return return_value; +} + +void LST_insert_head (tListNode * listHead, tListNode * node) +{ + uint32_t primask_bit; + + primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ + __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ + + node->next = listHead->next; + node->prev = listHead; + listHead->next = node; + (node->next)->prev = node; + + __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ +} + + +void LST_insert_tail (tListNode * listHead, tListNode * node) +{ + uint32_t primask_bit; + + primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ + __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ + + node->next = listHead; + node->prev = listHead->prev; + listHead->prev = node; + (node->prev)->next = node; + + __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ +} + + +void LST_remove_node (tListNode * node) +{ + uint32_t primask_bit; + + primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ + __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ + + (node->prev)->next = node->next; + (node->next)->prev = node->prev; + + __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ +} + + +void LST_remove_head (tListNode * listHead, tListNode ** node ) +{ + uint32_t primask_bit; + + primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ + __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ + + *node = listHead->next; + LST_remove_node (listHead->next); + + __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ +} + + +void LST_remove_tail (tListNode * listHead, tListNode ** node ) +{ + uint32_t primask_bit; + + primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ + __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ + + *node = listHead->prev; + LST_remove_node (listHead->prev); + + __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ +} + + +void LST_insert_node_after (tListNode * node, tListNode * ref_node) +{ + uint32_t primask_bit; + + primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ + __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ + + node->next = ref_node->next; + node->prev = ref_node; + ref_node->next = node; + (node->next)->prev = node; + + __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ +} + + +void LST_insert_node_before (tListNode * node, tListNode * ref_node) +{ + uint32_t primask_bit; + + primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ + __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ + + node->next = ref_node; + node->prev = ref_node->prev; + ref_node->prev = node; + (node->prev)->next = node; + + __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ +} + + +int LST_get_size (tListNode * listHead) +{ + int size = 0; + tListNode * temp; + uint32_t primask_bit; + + primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ + __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ + + temp = listHead->next; + while (temp != listHead) + { + size++; + temp = temp->next; + } + + __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ + + return (size); +} + +void LST_get_next_node (tListNode * ref_node, tListNode ** node) +{ + uint32_t primask_bit; + + primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ + __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ + + *node = ref_node->next; + + __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ +} + + +void LST_get_prev_node (tListNode * ref_node, tListNode ** node) +{ + uint32_t primask_bit; + + primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ + __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ + + *node = ref_node->prev; + + __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ +} diff --git a/src/utility/STM32Cube_FW/stm_list.h b/src/utility/STM32Cube_FW/stm_list.h index 769c2113..b7c3254c 100644 --- a/src/utility/STM32Cube_FW/stm_list.h +++ b/src/utility/STM32Cube_FW/stm_list.h @@ -21,8 +21,6 @@ #define _STM_LIST_H_ /* Includes ------------------------------------------------------------------*/ -#include "stdint.h" -#include "stdbool.h" #include "stm32_wpan_common.h" typedef PACKED_STRUCT _tListNode { @@ -32,7 +30,7 @@ typedef PACKED_STRUCT _tListNode { void LST_init_head (tListNode * listHead); -bool LST_is_empty (tListNode * listHead); +uint8_t LST_is_empty (tListNode * listHead); void LST_insert_head (tListNode * listHead, tListNode * node); diff --git a/src/utility/STM32Cube_FW/tl.h b/src/utility/STM32Cube_FW/tl.h index 16de7f16..2124d260 100644 --- a/src/utility/STM32Cube_FW/tl.h +++ b/src/utility/STM32Cube_FW/tl.h @@ -184,6 +184,7 @@ typedef struct uint8_t *p_ThreadOtCmdRspBuffer; uint8_t *p_ThreadCliRspBuffer; uint8_t *p_ThreadNotAckBuffer; + uint8_t *p_ThreadCliNotBuffer; } TL_TH_Config_t; typedef struct @@ -198,6 +199,19 @@ typedef struct uint8_t *p_BleLldM0CmdBuffer; } TL_BLE_LLD_Config_t; +typedef struct +{ + uint8_t *p_Mac_802_15_4_CmdRspBuffer; + uint8_t *p_Mac_802_15_4_NotAckBuffer; +} TL_MAC_802_15_4_Config_t; + +typedef struct +{ + uint8_t *p_ZigbeeOtCmdRspBuffer; + uint8_t *p_ZigbeeNotAckBuffer; + uint8_t *p_ZigbeeNotifRequestBuffer; +} TL_ZIGBEE_Config_t; + /** * @brief Contain the BLE HCI Init Configuration * @{ @@ -291,6 +305,26 @@ void TL_MM_EvtDone( TL_EvtPacket_t * hcievt ); void TL_TRACES_Init( void ); void TL_TRACES_EvtReceived( TL_EvtPacket_t * hcievt ); +/****************************************************************************** + * MAC 802.15.4 + ******************************************************************************/ +void TL_MAC_802_15_4_Init( TL_MAC_802_15_4_Config_t *p_Config ); +void TL_MAC_802_15_4_SendCmd( void ); +void TL_MAC_802_15_4_CmdEvtReceived( TL_EvtPacket_t * Otbuffer ); +void TL_MAC_802_15_4_NotReceived( TL_EvtPacket_t * Notbuffer ); +void TL_MAC_802_15_4_SendAck ( void ); + +/****************************************************************************** + * ZIGBEE + ******************************************************************************/ +void TL_ZIGBEE_Init( TL_ZIGBEE_Config_t *p_Config ); +void TL_ZIGBEE_SendM4RequestToM0( void ); +void TL_ZIGBEE_SendM4AckToM0Notify ( void ); +void TL_ZIGBEE_NotReceived( TL_EvtPacket_t * Notbuffer ); +void TL_ZIGBEE_CmdEvtReceived( TL_EvtPacket_t * Otbuffer ); +void TL_ZIGBEE_M0RequestReceived(TL_EvtPacket_t * Otbuffer ); +void TL_ZIGBEE_SendM4AckToM0Request(void); + #ifdef __cplusplus } /* extern "C" */ #endif diff --git a/src/utility/STM32Cube_FW/tl_mbox.c b/src/utility/STM32Cube_FW/tl_mbox.c index db192c4f..4112429d 100644 --- a/src/utility/STM32Cube_FW/tl_mbox.c +++ b/src/utility/STM32Cube_FW/tl_mbox.c @@ -16,7 +16,6 @@ ****************************************************************************** */ -#if defined(STM32WBxx) /* Includes ------------------------------------------------------------------*/ #include "stm32_wpan_common.h" #include "hw.h" @@ -24,6 +23,7 @@ #include "stm_list.h" #include "tl.h" #include "mbox_def.h" +#include "tl_dbg_conf.h" /* Private typedef -----------------------------------------------------------*/ typedef enum @@ -51,13 +51,15 @@ PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_BleLldTable_t TL_BleLldTable; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_SysTable_t TL_SysTable; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_MemManagerTable_t TL_MemManagerTable; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_TracesTable_t TL_TracesTable; +PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_Mac_802_15_4_t TL_Mac_802_15_4_Table; +PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_ZigbeeTable_t TL_Zigbee_Table; /**< tables */ PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode FreeBufQueue; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode TracesEvtQueue; PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static uint8_t CsBuffer[sizeof(TL_PacketHeader_t) + TL_EVT_HDR_SIZE + sizeof(TL_CsEvt_t)]; -PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static tListNode EvtQueue; -PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static tListNode SystemEvtQueue; +PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode EvtQueue; +PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode SystemEvtQueue; static tListNode LocalFreeBufQueue; @@ -95,6 +97,8 @@ void TL_Init( void ) TL_RefTable.p_sys_table = &TL_SysTable; TL_RefTable.p_mem_manager_table = &TL_MemManagerTable; TL_RefTable.p_traces_table = &TL_TracesTable; + TL_RefTable.p_mac_802_15_4_table = &TL_Mac_802_15_4_Table; + TL_RefTable.p_zigbee_table = &TL_Zigbee_Table; HW_IPCC_Init(); return; @@ -256,6 +260,7 @@ void TL_THREAD_Init( TL_TH_Config_t *p_Config ) p_thread_table->clicmdrsp_buffer = p_Config->p_ThreadCliRspBuffer; p_thread_table->otcmdrsp_buffer = p_Config->p_ThreadOtCmdRspBuffer; p_thread_table->notack_buffer = p_Config->p_ThreadNotAckBuffer; + p_thread_table->clinot_buffer = p_Config->p_ThreadCliNotBuffer; HW_IPCC_THREAD_Init(); @@ -314,7 +319,7 @@ void HW_IPCC_THREAD_EvtNot( void ) void HW_IPCC_THREAD_CliEvtNot( void ) { - TL_THREAD_CliNotReceived( (TL_EvtPacket_t*)(TL_RefTable.p_thread_table->clicmdrsp_buffer) ); + TL_THREAD_CliNotReceived( (TL_EvtPacket_t*)(TL_RefTable.p_thread_table->clinot_buffer) ); return; } @@ -447,6 +452,139 @@ void TL_BLE_LLD_SendRspAck( void ) } #endif /* BLE_LLD_WB */ +#ifdef MAC_802_15_4_WB +/****************************************************************************** + * MAC 802.15.4 + ******************************************************************************/ +void TL_MAC_802_15_4_Init( TL_MAC_802_15_4_Config_t *p_Config ) +{ + MB_Mac_802_15_4_t * p_mac_802_15_4_table; + + p_mac_802_15_4_table = TL_RefTable.p_mac_802_15_4_table; + + p_mac_802_15_4_table->p_cmdrsp_buffer = p_Config->p_Mac_802_15_4_CmdRspBuffer; + p_mac_802_15_4_table->p_notack_buffer = p_Config->p_Mac_802_15_4_NotAckBuffer; + + HW_IPCC_MAC_802_15_4_Init(); + + return; +} + +void TL_MAC_802_15_4_SendCmd( void ) +{ + ((TL_CmdPacket_t *)(TL_RefTable.p_mac_802_15_4_table->p_cmdrsp_buffer))->cmdserial.type = TL_OTCMD_PKT_TYPE; + + HW_IPCC_MAC_802_15_4_SendCmd(); + + return; +} + +void TL_MAC_802_15_4_SendAck ( void ) +{ + ((TL_CmdPacket_t *)(TL_RefTable.p_mac_802_15_4_table->p_notack_buffer))->cmdserial.type = TL_OTACK_PKT_TYPE; + + HW_IPCC_MAC_802_15_4_SendAck(); + + return; +} + +void HW_IPCC_MAC_802_15_4_CmdEvtNot(void) +{ + TL_MAC_802_15_4_CmdEvtReceived( (TL_EvtPacket_t*)(TL_RefTable.p_mac_802_15_4_table->p_cmdrsp_buffer) ); + + return; +} + +void HW_IPCC_MAC_802_15_4_EvtNot( void ) +{ + TL_MAC_802_15_4_NotReceived( (TL_EvtPacket_t*)(TL_RefTable.p_mac_802_15_4_table->p_notack_buffer) ); + + return; +} + +__WEAK void TL_MAC_802_15_4_CmdEvtReceived( TL_EvtPacket_t * Otbuffer ){}; +__WEAK void TL_MAC_802_15_4_NotReceived( TL_EvtPacket_t * Notbuffer ){}; +#endif + +#ifdef ZIGBEE_WB +/****************************************************************************** + * ZIGBEE + ******************************************************************************/ +void TL_ZIGBEE_Init( TL_ZIGBEE_Config_t *p_Config ) +{ + MB_ZigbeeTable_t * p_zigbee_table; + + p_zigbee_table = TL_RefTable.p_zigbee_table; + p_zigbee_table->appliCmdM4toM0_buffer = p_Config->p_ZigbeeOtCmdRspBuffer; + p_zigbee_table->notifM0toM4_buffer = p_Config->p_ZigbeeNotAckBuffer; + p_zigbee_table->requestM0toM4_buffer = p_Config->p_ZigbeeNotifRequestBuffer; + + HW_IPCC_ZIGBEE_Init(); + + return; +} + +/* Zigbee M4 to M0 Request */ +void TL_ZIGBEE_SendM4RequestToM0( void ) +{ + ((TL_CmdPacket_t *)(TL_RefTable.p_zigbee_table->appliCmdM4toM0_buffer))->cmdserial.type = TL_OTCMD_PKT_TYPE; + + HW_IPCC_ZIGBEE_SendM4RequestToM0(); + + return; +} + +/* Used to receive an ACK from the M0 */ +void HW_IPCC_ZIGBEE_RecvAppliAckFromM0(void) +{ + TL_ZIGBEE_CmdEvtReceived( (TL_EvtPacket_t*)(TL_RefTable.p_zigbee_table->appliCmdM4toM0_buffer) ); + + return; +} + +/* Zigbee notification from M0 to M4 */ +void HW_IPCC_ZIGBEE_RecvM0NotifyToM4( void ) +{ + TL_ZIGBEE_NotReceived( (TL_EvtPacket_t*)(TL_RefTable.p_zigbee_table->notifM0toM4_buffer) ); + + return; +} + +/* Send an ACK to the M0 for a Notification */ +void TL_ZIGBEE_SendM4AckToM0Notify ( void ) +{ + ((TL_CmdPacket_t *)(TL_RefTable.p_zigbee_table->notifM0toM4_buffer))->cmdserial.type = TL_OTACK_PKT_TYPE; + + HW_IPCC_ZIGBEE_SendM4AckToM0Notify(); + + return; +} + +/* Zigbee M0 to M4 Request */ +void HW_IPCC_ZIGBEE_RecvM0RequestToM4( void ) +{ + TL_ZIGBEE_M0RequestReceived( (TL_EvtPacket_t*)(TL_RefTable.p_zigbee_table->requestM0toM4_buffer) ); + + return; +} + +/* Send an ACK to the M0 for a Request */ +void TL_ZIGBEE_SendM4AckToM0Request(void) +{ + ((TL_CmdPacket_t *)(TL_RefTable.p_zigbee_table->requestM0toM4_buffer))->cmdserial.type = TL_OTACK_PKT_TYPE; + + HW_IPCC_ZIGBEE_SendM4AckToM0Request(); + + return; +} + + +__WEAK void TL_ZIGBEE_CmdEvtReceived( TL_EvtPacket_t * Otbuffer ){}; +__WEAK void TL_ZIGBEE_NotReceived( TL_EvtPacket_t * Notbuffer ){}; +#endif + + + /****************************************************************************** * MEMORY MANAGER ******************************************************************************/ @@ -531,11 +669,181 @@ __WEAK void TL_TRACES_EvtReceived( TL_EvtPacket_t * hcievt ) ******************************************************************************/ static void OutputDbgTrace(TL_MB_PacketType_t packet_type, uint8_t* buffer) { - /* Function stubbed */ - UNUSED(packet_type); - UNUSED(buffer); + TL_EvtPacket_t *p_evt_packet; + TL_CmdPacket_t *p_cmd_packet; + + switch(packet_type) + { + case TL_MB_MM_RELEASE_BUFFER: + p_evt_packet = (TL_EvtPacket_t*)buffer; + switch(p_evt_packet->evtserial.evt.evtcode) + { + case TL_BLEEVT_CS_OPCODE: + TL_MM_DBG_MSG("mm evt released: 0x%02X", p_evt_packet->evtserial.evt.evtcode); + TL_MM_DBG_MSG(" cmd opcode: 0x%04X", ((TL_CsEvt_t*)(p_evt_packet->evtserial.evt.payload))->cmdcode); + TL_MM_DBG_MSG(" buffer addr: 0x%08X", p_evt_packet); + break; + + case TL_BLEEVT_CC_OPCODE: + TL_MM_DBG_MSG("mm evt released: 0x%02X", p_evt_packet->evtserial.evt.evtcode); + TL_MM_DBG_MSG(" cmd opcode: 0x%04X", ((TL_CcEvt_t*)(p_evt_packet->evtserial.evt.payload))->cmdcode); + TL_MM_DBG_MSG(" buffer addr: 0x%08X", p_evt_packet); + break; + + case TL_BLEEVT_VS_OPCODE: + TL_MM_DBG_MSG("mm evt released: 0x%02X", p_evt_packet->evtserial.evt.evtcode); + TL_MM_DBG_MSG(" subevtcode: 0x%04X", ((TL_AsynchEvt_t*)(p_evt_packet->evtserial.evt.payload))->subevtcode); + TL_MM_DBG_MSG(" buffer addr: 0x%08X", p_evt_packet); + break; + + default: + TL_MM_DBG_MSG("mm evt released: 0x%02X", p_evt_packet->evtserial.evt.evtcode); + TL_MM_DBG_MSG(" buffer addr: 0x%08X", p_evt_packet); + break; + } + + TL_MM_DBG_MSG("\r\n"); + break; + + case TL_MB_BLE_CMD: + p_cmd_packet = (TL_CmdPacket_t*)buffer; + TL_HCI_CMD_DBG_MSG("ble cmd: 0x%04X", p_cmd_packet->cmdserial.cmd.cmdcode); + if(p_cmd_packet->cmdserial.cmd.plen != 0) + { + TL_HCI_CMD_DBG_MSG(" payload:"); + TL_HCI_CMD_DBG_BUF(p_cmd_packet->cmdserial.cmd.payload, p_cmd_packet->cmdserial.cmd.plen, ""); + } + TL_HCI_CMD_DBG_MSG("\r\n"); + + TL_HCI_CMD_DBG_RAW(&p_cmd_packet->cmdserial, p_cmd_packet->cmdserial.cmd.plen+TL_CMD_HDR_SIZE); + break; + + case TL_MB_BLE_CMD_RSP: + p_evt_packet = (TL_EvtPacket_t*)buffer; + switch(p_evt_packet->evtserial.evt.evtcode) + { + case TL_BLEEVT_CS_OPCODE: + TL_HCI_CMD_DBG_MSG("ble rsp: 0x%02X", p_evt_packet->evtserial.evt.evtcode); + TL_HCI_CMD_DBG_MSG(" cmd opcode: 0x%04X", ((TL_CsEvt_t*)(p_evt_packet->evtserial.evt.payload))->cmdcode); + TL_HCI_CMD_DBG_MSG(" numhci: 0x%02X", ((TL_CsEvt_t*)(p_evt_packet->evtserial.evt.payload))->numcmd); + TL_HCI_CMD_DBG_MSG(" status: 0x%02X", ((TL_CsEvt_t*)(p_evt_packet->evtserial.evt.payload))->status); + break; + + case TL_BLEEVT_CC_OPCODE: + TL_HCI_CMD_DBG_MSG("ble rsp: 0x%02X", p_evt_packet->evtserial.evt.evtcode); + TL_HCI_CMD_DBG_MSG(" cmd opcode: 0x%04X", ((TL_CcEvt_t*)(p_evt_packet->evtserial.evt.payload))->cmdcode); + TL_HCI_CMD_DBG_MSG(" numhci: 0x%02X", ((TL_CcEvt_t*)(p_evt_packet->evtserial.evt.payload))->numcmd); + TL_HCI_CMD_DBG_MSG(" status: 0x%02X", ((TL_CcEvt_t*)(p_evt_packet->evtserial.evt.payload))->payload[0]); + if((p_evt_packet->evtserial.evt.plen-4) != 0) + { + TL_HCI_CMD_DBG_MSG(" payload:"); + TL_HCI_CMD_DBG_BUF(&((TL_CcEvt_t*)(p_evt_packet->evtserial.evt.payload))->payload[1], p_evt_packet->evtserial.evt.plen-4, ""); + } + break; + + default: + TL_HCI_CMD_DBG_MSG("unknown ble rsp received: %02X", p_evt_packet->evtserial.evt.evtcode); + break; + } + + TL_HCI_CMD_DBG_MSG("\r\n"); + + TL_HCI_CMD_DBG_RAW(&p_evt_packet->evtserial, p_evt_packet->evtserial.evt.plen+TL_EVT_HDR_SIZE); + break; + + case TL_MB_BLE_ASYNCH_EVT: + p_evt_packet = (TL_EvtPacket_t*)buffer; + if(p_evt_packet->evtserial.evt.evtcode != TL_BLEEVT_VS_OPCODE) + { + TL_HCI_EVT_DBG_MSG("ble evt: 0x%02X", p_evt_packet->evtserial.evt.evtcode); + if((p_evt_packet->evtserial.evt.plen) != 0) + { + TL_HCI_EVT_DBG_MSG(" payload:"); + TL_HCI_EVT_DBG_BUF(p_evt_packet->evtserial.evt.payload, p_evt_packet->evtserial.evt.plen, ""); + } + } + else + { + TL_HCI_EVT_DBG_MSG("ble evt: 0x%02X", p_evt_packet->evtserial.evt.evtcode); + TL_HCI_EVT_DBG_MSG(" subevtcode: 0x%04X", ((TL_AsynchEvt_t*)(p_evt_packet->evtserial.evt.payload))->subevtcode); + if((p_evt_packet->evtserial.evt.plen-2) != 0) + { + TL_HCI_EVT_DBG_MSG(" payload:"); + TL_HCI_EVT_DBG_BUF(((TL_AsynchEvt_t*)(p_evt_packet->evtserial.evt.payload))->payload, p_evt_packet->evtserial.evt.plen-2, ""); + } + } + + TL_HCI_EVT_DBG_MSG("\r\n"); + + TL_HCI_EVT_DBG_RAW(&p_evt_packet->evtserial, p_evt_packet->evtserial.evt.plen+TL_EVT_HDR_SIZE); + break; + + case TL_MB_SYS_CMD: + p_cmd_packet = (TL_CmdPacket_t*)buffer; + + TL_SHCI_CMD_DBG_MSG("sys cmd: 0x%04X", p_cmd_packet->cmdserial.cmd.cmdcode); + + if(p_cmd_packet->cmdserial.cmd.plen != 0) + { + TL_SHCI_CMD_DBG_MSG(" payload:"); + TL_SHCI_CMD_DBG_BUF(p_cmd_packet->cmdserial.cmd.payload, p_cmd_packet->cmdserial.cmd.plen, ""); + } + TL_SHCI_CMD_DBG_MSG("\r\n"); + + TL_SHCI_CMD_DBG_RAW(&p_cmd_packet->cmdserial, p_cmd_packet->cmdserial.cmd.plen+TL_CMD_HDR_SIZE); + break; + + case TL_MB_SYS_CMD_RSP: + p_evt_packet = (TL_EvtPacket_t*)buffer; + switch(p_evt_packet->evtserial.evt.evtcode) + { + case TL_BLEEVT_CC_OPCODE: + TL_SHCI_CMD_DBG_MSG("sys rsp: 0x%02X", p_evt_packet->evtserial.evt.evtcode); + TL_SHCI_CMD_DBG_MSG(" cmd opcode: 0x%02X", ((TL_CcEvt_t*)(p_evt_packet->evtserial.evt.payload))->cmdcode); + TL_SHCI_CMD_DBG_MSG(" status: 0x%02X", ((TL_CcEvt_t*)(p_evt_packet->evtserial.evt.payload))->payload[0]); + if((p_evt_packet->evtserial.evt.plen-4) != 0) + { + TL_SHCI_CMD_DBG_MSG(" payload:"); + TL_SHCI_CMD_DBG_BUF(&((TL_CcEvt_t*)(p_evt_packet->evtserial.evt.payload))->payload[1], p_evt_packet->evtserial.evt.plen-4, ""); + } + break; + + default: + TL_SHCI_CMD_DBG_MSG("unknown sys rsp received: %02X", p_evt_packet->evtserial.evt.evtcode); + break; + } + + TL_SHCI_CMD_DBG_MSG("\r\n"); + + TL_SHCI_CMD_DBG_RAW(&p_evt_packet->evtserial, p_evt_packet->evtserial.evt.plen+TL_EVT_HDR_SIZE); + break; + + case TL_MB_SYS_ASYNCH_EVT: + p_evt_packet = (TL_EvtPacket_t*)buffer; + if(p_evt_packet->evtserial.evt.evtcode != TL_BLEEVT_VS_OPCODE) + { + TL_SHCI_EVT_DBG_MSG("unknown sys evt received: %02X", p_evt_packet->evtserial.evt.evtcode); + } + else + { + TL_SHCI_EVT_DBG_MSG("sys evt: 0x%02X", p_evt_packet->evtserial.evt.evtcode); + TL_SHCI_EVT_DBG_MSG(" subevtcode: 0x%04X", ((TL_AsynchEvt_t*)(p_evt_packet->evtserial.evt.payload))->subevtcode); + if((p_evt_packet->evtserial.evt.plen-2) != 0) + { + TL_SHCI_EVT_DBG_MSG(" payload:"); + TL_SHCI_EVT_DBG_BUF(((TL_AsynchEvt_t*)(p_evt_packet->evtserial.evt.payload))->payload, p_evt_packet->evtserial.evt.plen-2, ""); + } + } + + TL_SHCI_EVT_DBG_MSG("\r\n"); + + TL_SHCI_EVT_DBG_RAW(&p_evt_packet->evtserial, p_evt_packet->evtserial.evt.plen+TL_EVT_HDR_SIZE); + break; + + default: + break; + } return; } -#endif /* STM32WBxx */ From 4a9f4ae6b3e00b0bae34f806466b208919955afa Mon Sep 17 00:00:00 2001 From: Alexandre Bourdiol <alexandre.bourdiol@st.com> Date: Tue, 30 Aug 2022 11:28:41 +0200 Subject: [PATCH 093/226] chore: clean up and adapt STM32Cube_FW sources for STM32duino Signed-off-by: Alexandre Bourdiol <alexandre.bourdiol@st.com> --- src/utility/STM32Cube_FW/app_conf_default.h | 428 +------------------ src/utility/STM32Cube_FW/ble_bufsize.h | 13 +- src/utility/STM32Cube_FW/hw.h | 28 +- src/utility/STM32Cube_FW/hw_ipcc.c | 184 +------- src/utility/STM32Cube_FW/mbox_def.h | 34 -- src/utility/STM32Cube_FW/shci.c | 40 +- src/utility/STM32Cube_FW/shci.h | 47 +- src/utility/STM32Cube_FW/shci_tl.c | 19 +- src/utility/STM32Cube_FW/stm32_wpan_common.h | 39 +- src/utility/STM32Cube_FW/stm_list.c | 11 +- src/utility/STM32Cube_FW/stm_list.h | 4 +- src/utility/STM32Cube_FW/tl.h | 33 -- src/utility/STM32Cube_FW/tl_mbox.c | 144 +------ 13 files changed, 91 insertions(+), 933 deletions(-) diff --git a/src/utility/STM32Cube_FW/app_conf_default.h b/src/utility/STM32Cube_FW/app_conf_default.h index c63c66e9..54f824ae 100644 --- a/src/utility/STM32Cube_FW/app_conf_default.h +++ b/src/utility/STM32Cube_FW/app_conf_default.h @@ -1,4 +1,3 @@ -/* USER CODE BEGIN Header */ /** ****************************************************************************** * @file app_conf.h @@ -16,94 +15,36 @@ * ****************************************************************************** */ -/* USER CODE END Header */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef APP_CONF_H #define APP_CONF_H #include "hw.h" -#include "hw_conf.h" -#include "hw_if.h" #include "ble_bufsize.h" /****************************************************************************** * Application Config ******************************************************************************/ -/** - * Define Secure Connections Support - */ -#define CFG_SECURE_NOT_SUPPORTED (0x00) -#define CFG_SECURE_OPTIONAL (0x01) -#define CFG_SECURE_MANDATORY (0x02) - -#define CFG_SC_SUPPORT CFG_SECURE_OPTIONAL - -/** - * Define Keypress Notification Support - */ -#define CFG_KEYPRESS_NOT_SUPPORTED (0x00) -#define CFG_KEYPRESS_SUPPORTED (0x01) +/**< generic parameters ******************************************************/ +/* HCI related defines */ -#define CFG_KEYPRESS_NOTIFICATION_SUPPORT CFG_KEYPRESS_NOT_SUPPORTED +#define ACI_HAL_SET_TX_POWER_LEVEL 0xFC0F +#define ACI_WRITE_CONFIG_DATA_OPCODE 0xFC0C +#define ACI_READ_CONFIG_DATA_OPCODE 0xFC0D +#define MAX_HCI_ACL_PACKET_SIZE (sizeof(TL_PacketHeader_t) + 5 + 251) +#define HCI_RESET 0x0C03 -/** - * Numeric Comparison Answers - */ -#define YES (0x01) -#define NO (0x00) - -/** - * Device name configuration for Generic Access Service - */ -#define CFG_GAP_DEVICE_NAME "TEMPLATE" -#define CFG_GAP_DEVICE_NAME_LENGTH (8) - -/** -* Identity root key used to derive LTK and CSRK -*/ -#define CFG_BLE_IRK {0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0} - -/** -* Encryption root key used to derive LTK and CSRK -*/ -#define CFG_BLE_ERK {0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21, 0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21} +#ifndef BLE_SHARED_MEM_BYTE_ORDER + #define BLE_SHARED_MEM_BYTE_ORDER MSBFIRST +#endif +#define BLE_MODULE_SHARED_MEM_BUFFER_SIZE 128 /** - * SMPS supply - * SMPS not used when Set to 0 - * SMPS used when Set to 1 + * Define Tx Power */ -#define CFG_USE_SMPS 0 - -/* USER CODE BEGIN Generic_Parameters */ -/* USER CODE END Generic_Parameters */ - -/**< specific parameters */ -/*****************************************************/ - -/* USER CODE BEGIN Specific_Parameters */ -#define PUSH_BUTTON_SW1_EXTI_IRQHandler EXTI4_IRQHandler - -/* USER CODE END Specific_Parameters */ - -/****************************************************************************** - * Information Table - * - * Version - * [0:3] = Build - 0: Untracked - 15:Released - x: Tracked version - * [4:7] = branch - 0: Mass Market - x: ... - * [8:15] = Subversion - * [16:23] = Version minor - * [24:31] = Version major - * - ******************************************************************************/ -#define CFG_FW_MAJOR_VERSION (0) -#define CFG_FW_MINOR_VERSION (0) -#define CFG_FW_SUBVERSION (1) -#define CFG_FW_BRANCH (0) -#define CFG_FW_BUILD (0) +#define CFG_TX_POWER (0x18) /* -0.15dBm */ /****************************************************************************** * BLE Stack @@ -152,13 +93,15 @@ * Prepare Write List size in terms of number of packet * This parameter is ignored by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set */ -#define CFG_BLE_PREPARE_WRITE_LIST_SIZE BLE_PREP_WRITE_X_ATT(CFG_BLE_MAX_ATT_MTU) +// #define CFG_BLE_PREPARE_WRITE_LIST_SIZE BLE_PREP_WRITE_X_ATT(CFG_BLE_MAX_ATT_MTU) +#define CFG_BLE_PREPARE_WRITE_LIST_SIZE (0x3A) /** * Number of allocated memory blocks * This parameter is overwritten by the CPU2 with an hardcoded optimal value when the parameter CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set */ -#define CFG_BLE_MBLOCK_COUNT (BLE_MBLOCKS_CALC(CFG_BLE_PREPARE_WRITE_LIST_SIZE, CFG_BLE_MAX_ATT_MTU, CFG_BLE_NUM_LINK)) +// #define CFG_BLE_MBLOCK_COUNT (BLE_MBLOCKS_CALC(CFG_BLE_PREPARE_WRITE_LIST_SIZE, CFG_BLE_MAX_ATT_MTU, CFG_BLE_NUM_LINK)) +#define CFG_BLE_MBLOCK_COUNT (0x79) /** * Enable or disable the Extended Packet length feature. Valid values are 0 or 1. @@ -241,7 +184,7 @@ * 0: LE Power Class 2-3 * other bits: reserved (shall be set to 0) */ -#define CFG_BLE_OPTIONS (SHCI_C2_BLE_INIT_OPTIONS_LL_HOST | SHCI_C2_BLE_INIT_OPTIONS_WITH_SVC_CHANGE_DESC | SHCI_C2_BLE_INIT_OPTIONS_DEVICE_NAME_RW | SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV | SHCI_C2_BLE_INIT_OPTIONS_CS_ALGO2 | SHCI_C2_BLE_INIT_OPTIONS_POWER_CLASS_2_3) +#define CFG_BLE_OPTIONS (SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY) #define CFG_BLE_MAX_COC_INITIATOR_NBR (32) @@ -291,340 +234,5 @@ #define CFG_BLE_RX_PATH_COMPENS (0) -/****************************************************************************** - * Transport Layer - ******************************************************************************/ -/** - * Queue length of BLE Event - * This parameter defines the number of asynchronous events that can be stored in the HCI layer before - * being reported to the application. When a command is sent to the BLE core coprocessor, the HCI layer - * is waiting for the event with the Num_HCI_Command_Packets set to 1. The receive queue shall be large - * enough to store all asynchronous events received in between. - * When CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE is set to 27, this allow to store three 255 bytes long asynchronous events - * between the HCI command and its event. - * This parameter depends on the value given to CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE. When the queue size is to small, - * the system may hang if the queue is full with asynchronous events and the HCI layer is still waiting - * for a CC/CS event, In that case, the notification TL_BLE_HCI_ToNot() is called to indicate - * to the application a HCI command did not receive its command event within 30s (Default HCI Timeout). - */ -#define CFG_TLBLE_EVT_QUEUE_LENGTH 5 -/** - * This parameter should be set to fit most events received by the HCI layer. It defines the buffer size of each element - * allocated in the queue of received events and can be used to optimize the amount of RAM allocated by the Memory Manager. - * It should not exceed 255 which is the maximum HCI packet payload size (a greater value is a lost of memory as it will - * never be used) - * It shall be at least 4 to receive the command status event in one frame. - * The default value is set to 27 to allow receiving an event of MTU size in a single buffer. This value maybe reduced - * further depending on the application. - */ -#define CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE 255 /**< Set to 255 with the memory manager and the mailbox */ - -#define TL_BLE_EVENT_FRAME_SIZE ( TL_EVT_HDR_SIZE + CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE ) -/****************************************************************************** - * UART interfaces - ******************************************************************************/ - -/** - * Select UART interfaces - */ -#define CFG_UART_GUI hw_uart1 -#define CFG_DEBUG_TRACE_UART 0 -/****************************************************************************** - * USB interface - ******************************************************************************/ - -/** - * Enable/Disable USB interface - */ -#define CFG_USB_INTERFACE_ENABLE 0 - -/****************************************************************************** - * IPCC interface - ******************************************************************************/ - -/** - * The IPCC is dedicated to the communication between the CPU2 and the CPU1 - * and shall not be modified by the application - * The two following definitions shall not be modified - */ -#define HAL_IPCC_TX_IRQHandler(...) HW_IPCC_Tx_Handler( ) -#define HAL_IPCC_RX_IRQHandler(...) HW_IPCC_Rx_Handler( ) - -/****************************************************************************** - * Low Power - ******************************************************************************/ -/** - * When set to 1, the low power mode is enable - * When set to 0, the device stays in RUN mode - */ -#define CFG_LPM_SUPPORTED 1 - -/****************************************************************************** - * RTC interface - ******************************************************************************/ -#define HAL_RTCEx_WakeUpTimerIRQHandler(...) HW_TS_RTC_Wakeup_Handler( ) - -/****************************************************************************** - * Timer Server - ******************************************************************************/ -/** - * CFG_RTC_WUCKSEL_DIVIDER: This sets the RTCCLK divider to the wakeup timer. - * The lower is the value, the better is the power consumption and the accuracy of the timerserver - * The higher is the value, the finest is the granularity - * - * CFG_RTC_ASYNCH_PRESCALER: This sets the asynchronous prescaler of the RTC. It should as high as possible ( to output - * clock as low as possible) but the output clock should be equal or higher frequency compare to the clock feeding - * the wakeup timer. A lower clock speed would impact the accuracy of the timer server. - * - * CFG_RTC_SYNCH_PRESCALER: This sets the synchronous prescaler of the RTC. - * When the 1Hz calendar clock is required, it shall be sets according to other settings - * When the 1Hz calendar clock is not needed, CFG_RTC_SYNCH_PRESCALER should be set to 0x7FFF (MAX VALUE) - * - * CFG_RTCCLK_DIVIDER_CONF: - * Shall be set to either 0,2,4,8,16 - * When set to either 2,4,8,16, the 1Hhz calendar is supported - * When set to 0, the user sets its own configuration - * - * The following settings are computed with LSI as input to the RTC - */ - -#define CFG_RTCCLK_DIVIDER_CONF 0 - -#if (CFG_RTCCLK_DIVIDER_CONF == 0) -/** - * Custom configuration - * It does not support 1Hz calendar - * It divides the RTC CLK by 16 - */ - -#define CFG_RTCCLK_DIV (16) -#define CFG_RTC_WUCKSEL_DIVIDER (0) -#define CFG_RTC_ASYNCH_PRESCALER (0x0F) -#define CFG_RTC_SYNCH_PRESCALER (0x7FFF) - -#else - -#if (CFG_RTCCLK_DIVIDER_CONF == 2) -/** - * It divides the RTC CLK by 2 - */ -#define CFG_RTC_WUCKSEL_DIVIDER (3) -#endif - -#if (CFG_RTCCLK_DIVIDER_CONF == 4) -/** - * It divides the RTC CLK by 4 - */ -#define CFG_RTC_WUCKSEL_DIVIDER (2) -#endif - -#if (CFG_RTCCLK_DIVIDER_CONF == 8) -/** - * It divides the RTC CLK by 8 - */ -#define CFG_RTC_WUCKSEL_DIVIDER (1) -#endif - -#if (CFG_RTCCLK_DIVIDER_CONF == 16) -/** - * It divides the RTC CLK by 16 - */ -#define CFG_RTC_WUCKSEL_DIVIDER (0) -#endif - -#define CFG_RTCCLK_DIV CFG_RTCCLK_DIVIDER_CONF -#define CFG_RTC_ASYNCH_PRESCALER (CFG_RTCCLK_DIV - 1) -#define CFG_RTC_SYNCH_PRESCALER (DIVR( LSE_VALUE, (CFG_RTC_ASYNCH_PRESCALER+1) ) - 1 ) - -#endif - -/** tick timer values */ -#define CFG_TS_TICK_VAL DIVR( (CFG_RTCCLK_DIV * 1000000), LSE_VALUE ) -#define CFG_TS_TICK_VAL_PS DIVR( ((uint64_t)CFG_RTCCLK_DIV * 1e12), (uint64_t)LSE_VALUE ) - -typedef enum -{ - CFG_TIM_PROC_ID_ISR, - /* USER CODE BEGIN CFG_TimProcID_t */ - - /* USER CODE END CFG_TimProcID_t */ -} CFG_TimProcID_t; - -/****************************************************************************** - * Debug - ******************************************************************************/ -/** - * When set, this resets some hw resources to set the device in the same state than the power up - * The FW resets only register that may prevent the FW to run properly - * - * This shall be set to 0 in a final product - * - */ -#define CFG_HW_RESET_BY_FW 1 - -/** - * keep debugger enabled while in any low power mode when set to 1 - * should be set to 0 in production - */ -#define CFG_DEBUGGER_SUPPORTED 0 - -/** - * When set to 1, the traces are enabled in the BLE services - */ -#define CFG_DEBUG_BLE_TRACE 0 - -/** - * Enable or Disable traces in application - */ -#define CFG_DEBUG_APP_TRACE 0 - -#if (CFG_DEBUG_APP_TRACE != 0) -#define APP_DBG_MSG PRINT_MESG_DBG -#else -#define APP_DBG_MSG PRINT_NO_MESG -#endif - -#if ( (CFG_DEBUG_BLE_TRACE != 0) || (CFG_DEBUG_APP_TRACE != 0) ) -#define CFG_DEBUG_TRACE 1 -#endif - -#if (CFG_DEBUG_TRACE != 0) -#undef CFG_LPM_SUPPORTED -#undef CFG_DEBUGGER_SUPPORTED -#define CFG_LPM_SUPPORTED 0 -#define CFG_DEBUGGER_SUPPORTED 1 -#endif - -/** - * When CFG_DEBUG_TRACE_FULL is set to 1, the trace are output with the API name, the file name and the line number - * When CFG_DEBUG_TRACE_LIGHT is set to 1, only the debug message is output - * - * When both are set to 0, no trace are output - * When both are set to 1, CFG_DEBUG_TRACE_FULL is selected - */ -#define CFG_DEBUG_TRACE_LIGHT 0 -#define CFG_DEBUG_TRACE_FULL 0 - -#if (( CFG_DEBUG_TRACE != 0 ) && ( CFG_DEBUG_TRACE_LIGHT == 0 ) && (CFG_DEBUG_TRACE_FULL == 0)) -#undef CFG_DEBUG_TRACE_FULL -#undef CFG_DEBUG_TRACE_LIGHT -#define CFG_DEBUG_TRACE_FULL 0 -#define CFG_DEBUG_TRACE_LIGHT 1 -#endif - -#if ( CFG_DEBUG_TRACE == 0 ) -#undef CFG_DEBUG_TRACE_FULL -#undef CFG_DEBUG_TRACE_LIGHT -#define CFG_DEBUG_TRACE_FULL 0 -#define CFG_DEBUG_TRACE_LIGHT 0 -#endif - -/** - * When not set, the traces is looping on sending the trace over UART - */ -#define DBG_TRACE_USE_CIRCULAR_QUEUE 1 - -/** - * max buffer Size to queue data traces and max data trace allowed. - * Only Used if DBG_TRACE_USE_CIRCULAR_QUEUE is defined - */ -#define DBG_TRACE_MSG_QUEUE_SIZE 4096 -#define MAX_DBG_TRACE_MSG_SIZE 1024 - -/* USER CODE BEGIN Defines */ -#define CFG_LED_SUPPORTED 1 -#define CFG_BUTTON_SUPPORTED 1 - -#define PUSH_BUTTON_SW1_EXTI_IRQHandler EXTI4_IRQHandler -#define PUSH_BUTTON_SW2_EXTI_IRQHandler EXTI0_IRQHandler -#define PUSH_BUTTON_SW3_EXTI_IRQHandler EXTI1_IRQHandler -/* USER CODE END Defines */ - -/****************************************************************************** - * Scheduler - ******************************************************************************/ - -/** - * These are the lists of task id registered to the scheduler - * Each task id shall be in the range [0:31] - * This mechanism allows to implement a generic code in the API TL_BLE_HCI_StatusNot() to comply with - * the requirement that a HCI/ACI command shall never be sent if there is already one pending - */ - -/**< Add in that list all tasks that may send a ACI/HCI command */ -typedef enum -{ - CFG_TASK_BLE_HCI_CMD_ID, - CFG_TASK_SYS_HCI_CMD_ID, - CFG_TASK_HCI_ACL_DATA_ID, - CFG_TASK_SYS_LOCAL_CMD_ID, - CFG_TASK_TX_TO_HOST_ID, - /* USER CODE BEGIN CFG_Task_Id_With_HCI_Cmd_t */ - CFG_TASK_SW1_BUTTON_PUSHED_ID, - CFG_TASK_SW2_BUTTON_PUSHED_ID, - CFG_TASK_SW3_BUTTON_PUSHED_ID, - /* USER CODE END CFG_Task_Id_With_HCI_Cmd_t */ - CFG_LAST_TASK_ID_WITH_HCICMD, /**< Shall be LAST in the list */ -} CFG_Task_Id_With_HCI_Cmd_t; - -/**< Add in that list all tasks that never send a ACI/HCI command */ -typedef enum -{ - CFG_FIRST_TASK_ID_WITH_NO_HCICMD = CFG_LAST_TASK_ID_WITH_HCICMD - 1, /**< Shall be FIRST in the list */ - CFG_TASK_SYSTEM_HCI_ASYNCH_EVT_ID, - /* USER CODE BEGIN CFG_Task_Id_With_NO_HCI_Cmd_t */ - - /* USER CODE END CFG_Task_Id_With_NO_HCI_Cmd_t */ - CFG_LAST_TASK_ID_WITH_NO_HCICMD /**< Shall be LAST in the list */ -} CFG_Task_Id_With_NO_HCI_Cmd_t; - -#define CFG_TASK_NBR CFG_LAST_TASK_ID_WITH_NO_HCICMD - -/** - * This is the list of priority required by the application - * Each Id shall be in the range 0..31 - */ -typedef enum -{ - CFG_SCH_PRIO_0, - /* USER CODE BEGIN CFG_SCH_Prio_Id_t */ - - /* USER CODE END CFG_SCH_Prio_Id_t */ -} CFG_SCH_Prio_Id_t; - -/** - * This is a bit mapping over 32bits listing all events id supported in the application - */ -typedef enum -{ - CFG_IDLEEVT_SYSTEM_HCI_CMD_EVT_RSP_ID, - /* USER CODE BEGIN CFG_IdleEvt_Id_t */ - - /* USER CODE END CFG_IdleEvt_Id_t */ -} CFG_IdleEvt_Id_t; - -/****************************************************************************** - * LOW POWER - ******************************************************************************/ -/** - * Supported requester to the MCU Low Power Manager - can be increased up to 32 - * It list a bit mapping of all user of the Low Power Manager - */ -typedef enum -{ - CFG_LPM_APP, - CFG_LPM_APP_BLE, - /* USER CODE BEGIN CFG_LPM_Id_t */ - - /* USER CODE END CFG_LPM_Id_t */ -} CFG_LPM_Id_t; - -/****************************************************************************** - * OTP manager - ******************************************************************************/ -#define CFG_OTP_BASE_ADDRESS OTP_AREA_BASE - -#define CFG_OTP_END_ADRESS OTP_AREA_END_ADDR - #endif /*APP_CONF_H */ diff --git a/src/utility/STM32Cube_FW/ble_bufsize.h b/src/utility/STM32Cube_FW/ble_bufsize.h index 0f0f4192..247573be 100644 --- a/src/utility/STM32Cube_FW/ble_bufsize.h +++ b/src/utility/STM32Cube_FW/ble_bufsize.h @@ -75,17 +75,24 @@ ((pw) + MAX(BLE_MEM_BLOCK_X_MTU(mtu, n_link), \ BLE_MBLOCKS_SECURE_CONNECTIONS)) +/* + * BLE_DEFAULT_MBLOCKS_COUNT: default memory blocks count + */ +#define BLE_DEFAULT_MBLOCKS_COUNT(n_link) \ + BLE_MBLOCKS_CALC(BLE_DEFAULT_PREP_WRITE_LIST_SIZE, \ + BLE_DEFAULT_MAX_ATT_MTU, n_link) + /* * BLE_FIXED_BUFFER_SIZE_BYTES: - * A part of the RAM, is dinamically allocated by initilizing all the pointers + * A part of the RAM, is dynamically allocated by initializing all the pointers * defined in a global context variable "mem_alloc_ctx_p". * This initialization is made in the Dynamic_allocator functions, which - * assing a portion of RAM given by the external application to the above + * assign a portion of RAM given by the external application to the above * mentioned "global pointers". * * The size of this Dynamic RAM is made of 2 main components: * - a part that is parameters-dependent (num of links, GATT buffers, ...), - * and which value is explicited by the following macro; + * and which value is defined by the following macro; * - a part, that may be considered "fixed", i.e. independent from the above * mentioned parameters. */ diff --git a/src/utility/STM32Cube_FW/hw.h b/src/utility/STM32Cube_FW/hw.h index 503fa2ca..fcf04517 100644 --- a/src/utility/STM32Cube_FW/hw.h +++ b/src/utility/STM32Cube_FW/hw.h @@ -26,14 +26,21 @@ extern "C" { #endif /* Includes ------------------------------------------------------------------*/ +#include "stm32_def.h" +#include "stm32wbxx_ll_bus.h" +#include "stm32wbxx_ll_exti.h" +#include "stm32wbxx_ll_system.h" +#include "stm32wbxx_ll_rcc.h" +#include "stm32wbxx_ll_ipcc.h" +#include "stm32wbxx_ll_cortex.h" +#include "stm32wbxx_ll_utils.h" +#include "stm32wbxx_ll_pwr.h" /****************************************************************************** * HW IPCC ******************************************************************************/ void HW_IPCC_Enable( void ); void HW_IPCC_Init( void ); - void HW_IPCC_Rx_Handler( void ); - void HW_IPCC_Tx_Handler( void ); void HW_IPCC_BLE_Init( void ); void HW_IPCC_BLE_SendCmd( void ); @@ -80,23 +87,6 @@ extern "C" { void HW_IPCC_TRACES_Init( void ); void HW_IPCC_TRACES_EvtNot( void ); - void HW_IPCC_MAC_802_15_4_Init( void ); - void HW_IPCC_MAC_802_15_4_SendCmd( void ); - void HW_IPCC_MAC_802_15_4_SendAck( void ); - void HW_IPCC_MAC_802_15_4_CmdEvtNot( void ); - void HW_IPCC_MAC_802_15_4_EvtNot( void ); - - void HW_IPCC_ZIGBEE_Init( void ); - - void HW_IPCC_ZIGBEE_SendM4RequestToM0(void); /* M4 Request to M0 */ - void HW_IPCC_ZIGBEE_RecvAppliAckFromM0(void); /* Request ACK from M0 */ - - void HW_IPCC_ZIGBEE_RecvM0NotifyToM4(void); /* M0 Notify to M4 */ - void HW_IPCC_ZIGBEE_SendM4AckToM0Notify(void); /* Notify ACK from M4 */ - void HW_IPCC_ZIGBEE_RecvM0RequestToM4(void); /* M0 Request to M4 */ - void HW_IPCC_ZIGBEE_SendM4AckToM0Request(void); /* Request ACK from M4 */ - - #ifdef __cplusplus } #endif diff --git a/src/utility/STM32Cube_FW/hw_ipcc.c b/src/utility/STM32Cube_FW/hw_ipcc.c index fd620b85..7b9be81a 100644 --- a/src/utility/STM32Cube_FW/hw_ipcc.c +++ b/src/utility/STM32Cube_FW/hw_ipcc.c @@ -18,8 +18,9 @@ */ /* USER CODE END Header */ +#if defined(STM32WBxx) /* Includes ------------------------------------------------------------------*/ -#include "app_common.h" +#include "hw.h" #include "mbox_def.h" /* Global variables ---------------------------------------------------------*/ @@ -56,34 +57,17 @@ static void HW_IPCC_LLD_BLE_ReceiveRspHandler( void ); static void HW_IPCC_LLD_BLE_ReceiveM0CmdHandler( void ); #endif -#ifdef MAC_802_15_4_WB -static void HW_IPCC_MAC_802_15_4_CmdEvtHandler( void ); -static void HW_IPCC_MAC_802_15_4_NotEvtHandler( void ); -#endif - -#ifdef ZIGBEE_WB -static void HW_IPCC_ZIGBEE_CmdEvtHandler( void ); -static void HW_IPCC_ZIGBEE_StackNotifEvtHandler( void ); -static void HW_IPCC_ZIGBEE_StackM0RequestHandler( void ); -#endif - /* Public function definition -----------------------------------------------*/ /****************************************************************************** * INTERRUPT HANDLER ******************************************************************************/ -void HW_IPCC_Rx_Handler( void ) +void IPCC_C1_RX_IRQHandler(void) { if (HW_IPCC_RX_PENDING( HW_IPCC_SYSTEM_EVENT_CHANNEL )) { HW_IPCC_SYS_EvtHandler(); } -#ifdef MAC_802_15_4_WB - else if (HW_IPCC_RX_PENDING( HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL )) - { - HW_IPCC_MAC_802_15_4_NotEvtHandler(); - } -#endif /* MAC_802_15_4_WB */ #ifdef THREAD_WB else if (HW_IPCC_RX_PENDING( HW_IPCC_THREAD_NOTIFICATION_ACK_CHANNEL )) { @@ -114,16 +98,6 @@ void HW_IPCC_Rx_Handler( void ) HW_IPCC_LLD_BLE_ReceiveM0CmdHandler(); } #endif /* LLD_TESTS_WB */ -#ifdef ZIGBEE_WB - else if (HW_IPCC_RX_PENDING( HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL )) - { - HW_IPCC_ZIGBEE_StackNotifEvtHandler(); - } - else if (HW_IPCC_RX_PENDING( HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL )) - { - HW_IPCC_ZIGBEE_StackM0RequestHandler(); - } -#endif /* ZIGBEE_WB */ else if (HW_IPCC_RX_PENDING( HW_IPCC_BLE_EVENT_CHANNEL )) { HW_IPCC_BLE_EvtHandler(); @@ -132,22 +106,14 @@ void HW_IPCC_Rx_Handler( void ) { HW_IPCC_TRACES_EvtHandler(); } - - return; } -void HW_IPCC_Tx_Handler( void ) +void IPCC_C1_TX_IRQHandler(void) { if (HW_IPCC_TX_PENDING( HW_IPCC_SYSTEM_CMD_RSP_CHANNEL )) { HW_IPCC_SYS_CmdEvtHandler(); } -#ifdef MAC_802_15_4_WB - else if (HW_IPCC_TX_PENDING( HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL )) - { - HW_IPCC_MAC_802_15_4_CmdEvtHandler(); - } -#endif /* MAC_802_15_4_WB */ #ifdef THREAD_WB else if (HW_IPCC_TX_PENDING( HW_IPCC_THREAD_OT_CMD_RSP_CHANNEL )) { @@ -157,12 +123,6 @@ void HW_IPCC_Tx_Handler( void ) #ifdef LLD_TESTS_WB // No TX handler for LLD tests #endif /* LLD_TESTS_WB */ -#ifdef ZIGBEE_WB - if (HW_IPCC_TX_PENDING( HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL )) - { - HW_IPCC_ZIGBEE_CmdEvtHandler(); - } -#endif /* ZIGBEE_WB */ else if (HW_IPCC_TX_PENDING( HW_IPCC_MM_RELEASE_BUFFER_CHANNEL )) { HW_IPCC_MM_FreeBufHandler(); @@ -171,9 +131,8 @@ void HW_IPCC_Tx_Handler( void ) { HW_IPCC_BLE_AclDataEvtHandler(); } - - return; } + /****************************************************************************** * GENERAL ******************************************************************************/ @@ -264,8 +223,8 @@ static void HW_IPCC_BLE_AclDataEvtHandler( void ) return; } -__weak void HW_IPCC_BLE_AclDataAckNot( void ){}; -__weak void HW_IPCC_BLE_RxEvtNot( void ){}; +__WEAK void HW_IPCC_BLE_AclDataAckNot( void ){}; +__WEAK void HW_IPCC_BLE_RxEvtNot( void ){}; /****************************************************************************** * SYSTEM @@ -303,56 +262,8 @@ static void HW_IPCC_SYS_EvtHandler( void ) return; } -__weak void HW_IPCC_SYS_CmdEvtNot( void ){}; -__weak void HW_IPCC_SYS_EvtNot( void ){}; - -/****************************************************************************** - * MAC 802.15.4 - ******************************************************************************/ -#ifdef MAC_802_15_4_WB -void HW_IPCC_MAC_802_15_4_Init( void ) -{ - LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL ); - - return; -} - -void HW_IPCC_MAC_802_15_4_SendCmd( void ) -{ - LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL ); - LL_C1_IPCC_EnableTransmitChannel( IPCC, HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL ); - - return; -} - -void HW_IPCC_MAC_802_15_4_SendAck( void ) -{ - LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL ); - LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL ); - - return; -} - -static void HW_IPCC_MAC_802_15_4_CmdEvtHandler( void ) -{ - LL_C1_IPCC_DisableTransmitChannel( IPCC, HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL ); - - HW_IPCC_MAC_802_15_4_CmdEvtNot(); - - return; -} - -static void HW_IPCC_MAC_802_15_4_NotEvtHandler( void ) -{ - LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL ); - - HW_IPCC_MAC_802_15_4_EvtNot(); - - return; -} -__weak void HW_IPCC_MAC_802_15_4_CmdEvtNot( void ){}; -__weak void HW_IPCC_MAC_802_15_4_EvtNot( void ){}; -#endif +__WEAK void HW_IPCC_SYS_CmdEvtNot( void ){}; +__WEAK void HW_IPCC_SYS_EvtNot( void ){}; /****************************************************************************** * THREAD @@ -424,9 +335,9 @@ static void HW_IPCC_THREAD_CliNotEvtHandler( void ) return; } -__weak void HW_IPCC_OT_CmdEvtNot( void ){}; -__weak void HW_IPCC_CLI_CmdEvtNot( void ){}; -__weak void HW_IPCC_THREAD_EvtNot( void ){}; +__WEAK void HW_IPCC_OT_CmdEvtNot( void ){}; +__WEAK void HW_IPCC_CLI_CmdEvtNot( void ){}; +__WEAK void HW_IPCC_THREAD_EvtNot( void ){}; #endif /* THREAD_WB */ @@ -548,74 +459,6 @@ void HW_IPCC_LLD_BLE_SendRspAck( void ) #endif /* LLD_BLE_WB */ -/****************************************************************************** - * ZIGBEE - ******************************************************************************/ -#ifdef ZIGBEE_WB -void HW_IPCC_ZIGBEE_Init( void ) -{ - LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL ); - LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL ); - - return; -} - -void HW_IPCC_ZIGBEE_SendM4RequestToM0( void ) -{ - LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL ); - LL_C1_IPCC_EnableTransmitChannel( IPCC, HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL ); - - return; -} - -void HW_IPCC_ZIGBEE_SendM4AckToM0Notify( void ) -{ - LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL ); - LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL ); - - return; -} - -static void HW_IPCC_ZIGBEE_CmdEvtHandler( void ) -{ - LL_C1_IPCC_DisableTransmitChannel( IPCC, HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL ); - - HW_IPCC_ZIGBEE_RecvAppliAckFromM0(); - - return; -} - -static void HW_IPCC_ZIGBEE_StackNotifEvtHandler( void ) -{ - LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL ); - - HW_IPCC_ZIGBEE_RecvM0NotifyToM4(); - - return; -} - -static void HW_IPCC_ZIGBEE_StackM0RequestHandler( void ) -{ - LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL ); - - HW_IPCC_ZIGBEE_RecvM0RequestToM4(); - - return; -} - -void HW_IPCC_ZIGBEE_SendM4AckToM0Request( void ) -{ - LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL ); - LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL ); - - return; -} - -__weak void HW_IPCC_ZIGBEE_RecvAppliAckFromM0( void ){}; -__weak void HW_IPCC_ZIGBEE_RecvM0NotifyToM4( void ){}; -__weak void HW_IPCC_ZIGBEE_RecvM0RequestToM4( void ){}; -#endif /* ZIGBEE_WB */ - /****************************************************************************** * MEMORY MANAGER ******************************************************************************/ @@ -666,4 +509,5 @@ static void HW_IPCC_TRACES_EvtHandler( void ) return; } -__weak void HW_IPCC_TRACES_EvtNot( void ){}; +__WEAK void HW_IPCC_TRACES_EvtNot( void ){}; +#endif /* STM32WBxx */ diff --git a/src/utility/STM32Cube_FW/mbox_def.h b/src/utility/STM32Cube_FW/mbox_def.h index 68b71f9c..0c974f8f 100644 --- a/src/utility/STM32Cube_FW/mbox_def.h +++ b/src/utility/STM32Cube_FW/mbox_def.h @@ -106,12 +106,6 @@ extern "C" { uint8_t *m0cmd_buffer; } MB_BleLldTable_t; - typedef struct - { - uint8_t *notifM0toM4_buffer; - uint8_t *appliCmdM4toM0_buffer; - uint8_t *requestM0toM4_buffer; - } MB_ZigbeeTable_t; /** * msg * [0:7] = cmd/evt @@ -139,13 +133,6 @@ extern "C" { uint8_t *traces_queue; } MB_TracesTable_t; - typedef struct - { - uint8_t *p_cmdrsp_buffer; - uint8_t *p_notack_buffer; - uint8_t *evt_queue; - } MB_Mac_802_15_4_t; - typedef struct { MB_DeviceInfoTable_t *p_device_info_table; @@ -154,8 +141,6 @@ extern "C" { MB_SysTable_t *p_sys_table; MB_MemManagerTable_t *p_mem_manager_table; MB_TracesTable_t *p_traces_table; - MB_Mac_802_15_4_t *p_mac_802_15_4_table; - MB_ZigbeeTable_t *p_zigbee_table; MB_LldTestsTable_t *p_lld_tests_table; MB_BleLldTable_t *p_ble_lld_table; } MB_RefTable_t; @@ -199,15 +184,6 @@ typedef struct * | | * |<---HW_IPCC_SYSTEM_EVENT_CHANNEL-----------------| * | | - * | (ZIGBEE) | - * |----HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL------------>| - * | | - * |----HW_IPCC_ZIGBEE_CMD_CLI_CHANNEL-------------->| - * | | - * |<---HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL-------| - * | | - * |<---HW_IPCC_ZIGBEE_CLI_NOTIF_ACK_CHANNEL---------| - * | | * | (THREAD) | * |----HW_IPCC_THREAD_OT_CMD_RSP_CHANNEL----------->| * | | @@ -231,11 +207,6 @@ typedef struct * | | * |<---HW_IPCC_BLE_LLD_M0_CMD_CHANNEL---------------| * | | - * | (MAC) | - * |----HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL-------->| - * | | - * |<---HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL| - * | | * | (BUFFER) | * |----HW_IPCC_MM_RELEASE_BUFFER_CHANNE------------>| * | | @@ -253,8 +224,6 @@ typedef struct #define HW_IPCC_BLE_CMD_CHANNEL LL_IPCC_CHANNEL_1 #define HW_IPCC_SYSTEM_CMD_RSP_CHANNEL LL_IPCC_CHANNEL_2 #define HW_IPCC_THREAD_OT_CMD_RSP_CHANNEL LL_IPCC_CHANNEL_3 -#define HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL LL_IPCC_CHANNEL_3 -#define HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL LL_IPCC_CHANNEL_3 #define HW_IPCC_MM_RELEASE_BUFFER_CHANNEL LL_IPCC_CHANNEL_4 #define HW_IPCC_THREAD_CLI_CMD_CHANNEL LL_IPCC_CHANNEL_5 #define HW_IPCC_LLDTESTS_CLI_CMD_CHANNEL LL_IPCC_CHANNEL_5 @@ -266,8 +235,6 @@ typedef struct #define HW_IPCC_BLE_EVENT_CHANNEL LL_IPCC_CHANNEL_1 #define HW_IPCC_SYSTEM_EVENT_CHANNEL LL_IPCC_CHANNEL_2 #define HW_IPCC_THREAD_NOTIFICATION_ACK_CHANNEL LL_IPCC_CHANNEL_3 -#define HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL LL_IPCC_CHANNEL_3 -#define HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL LL_IPCC_CHANNEL_3 #define HW_IPCC_LLDTESTS_M0_CMD_CHANNEL LL_IPCC_CHANNEL_3 #define HW_IPCC_BLE_LLD_M0_CMD_CHANNEL LL_IPCC_CHANNEL_3 #define HW_IPCC_TRACES_CHANNEL LL_IPCC_CHANNEL_4 @@ -275,6 +242,5 @@ typedef struct #define HW_IPCC_LLDTESTS_CLI_RSP_CHANNEL LL_IPCC_CHANNEL_5 #define HW_IPCC_BLE_LLD_CLI_RSP_CHANNEL LL_IPCC_CHANNEL_5 #define HW_IPCC_BLE_LLD_RSP_CHANNEL LL_IPCC_CHANNEL_5 -#define HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL LL_IPCC_CHANNEL_5 #endif /*__MBOX_H */ diff --git a/src/utility/STM32Cube_FW/shci.c b/src/utility/STM32Cube_FW/shci.c index 472a108e..a8475222 100644 --- a/src/utility/STM32Cube_FW/shci.c +++ b/src/utility/STM32Cube_FW/shci.c @@ -16,7 +16,7 @@ ****************************************************************************** */ - +#if defined(STM32WBxx) /* Includes ------------------------------------------------------------------*/ #include "stm32_wpan_common.h" @@ -352,24 +352,6 @@ SHCI_CmdStatus_t SHCI_C2_BLE_LLD_Init( uint8_t param_size, uint8_t * p_param ) return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); } -SHCI_CmdStatus_t SHCI_C2_ZIGBEE_Init( void ) -{ - /** - * Buffer is large enough to hold command complete without payload - */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; - TL_EvtPacket_t * p_rsp; - - p_rsp = (TL_EvtPacket_t *)local_buffer; - - shci_send( SHCI_OPCODE_C2_ZIGBEE_INIT, - 0, - 0, - p_rsp ); - - return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); -} - SHCI_CmdStatus_t SHCI_C2_DEBUG_Init( SHCI_C2_DEBUG_Init_Cmd_Packet_t *pCmdPacket ) { /** @@ -527,24 +509,6 @@ SHCI_CmdStatus_t SHCI_C2_RADIO_AllowLowPower( SHCI_C2_FLASH_Ip_t Ip,uint8_t Fla return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); } -SHCI_CmdStatus_t SHCI_C2_MAC_802_15_4_Init( void ) -{ - /** - * Buffer is large enough to hold command complete without payload - */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; - TL_EvtPacket_t * p_rsp; - - p_rsp = (TL_EvtPacket_t *)local_buffer; - - shci_send( SHCI_OPCODE_C2_MAC_802_15_4_INIT, - 0, - 0, - p_rsp ); - - return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); -} - SHCI_CmdStatus_t SHCI_C2_Reinit( void ) { /** @@ -739,4 +703,4 @@ SHCI_CmdStatus_t SHCI_GetWirelessFwInfo( WirelessFwInfo_t* pWirelessInfo ) return (SHCI_Success); } - +#endif /* STM32WBxx */ diff --git a/src/utility/STM32Cube_FW/shci.h b/src/utility/STM32Cube_FW/shci.h index 102089e2..6b6ffd1a 100644 --- a/src/utility/STM32Cube_FW/shci.h +++ b/src/utility/STM32Cube_FW/shci.h @@ -49,7 +49,6 @@ extern "C" { ERR_BLE_INIT = 0, /* This event is currently not reported by the CPU2 */ ERR_THREAD_LLD_FATAL_ERROR = 125, /* The LLD driver used on 802_15_4 detected a fatal error */ ERR_THREAD_UNKNOWN_CMD = 126, /* The command send by the CPU1 to control the Thread stack is unknown */ - ERR_ZIGBEE_UNKNOWN_CMD = 200, /* The command send by the CPU1 to control the Zigbee stack is unknown */ } SCHI_SystemErrCode_t; #define SHCI_EVTCODE ( 0xFF ) @@ -102,7 +101,7 @@ extern "C" { /** * SHCI_SUB_EVT_THREAD_NVM_RAM_UPDATE - * This notifies the CPU1 which part of the OT NVM RAM has been updated so that only the modified + * This notifies the CPU1 which part of the 'OT NVM RAM' has been updated so that only the modified * section could be written in Flash/NVM * StartAddress : Start address of the section that has been modified * Size : Size (in bytes) of the section that has been modified @@ -216,9 +215,7 @@ extern "C" { SHCI_OCF_C2_FLASH_STORE_DATA, SHCI_OCF_C2_FLASH_ERASE_DATA, SHCI_OCF_C2_RADIO_ALLOW_LOW_POWER, - SHCI_OCF_C2_MAC_802_15_4_INIT, SHCI_OCF_C2_REINIT, - SHCI_OCF_C2_ZIGBEE_INIT, SHCI_OCF_C2_LLD_TESTS_INIT, SHCI_OCF_C2_EXTPA_CONFIG, SHCI_OCF_C2_SET_FLASH_ACTIVITY_CONTROL, @@ -648,8 +645,6 @@ extern "C" { { uint8_t thread_config; uint8_t ble_config; - uint8_t mac_802_15_4_config; - uint8_t zigbee_config; } SHCI_C2_DEBUG_TracesConfig_t; typedef PACKED_STRUCT @@ -713,8 +708,6 @@ extern "C" { { BLE_ENABLE, THREAD_ENABLE, - ZIGBEE_ENABLE, - MAC_ENABLE, } SHCI_C2_CONCURRENT_Mode_Param_t; /** No response parameters*/ @@ -737,18 +730,13 @@ extern "C" { { BLE_IP, THREAD_IP, - ZIGBEE_IP, } SHCI_C2_FLASH_Ip_t; /** No response parameters*/ #define SHCI_OPCODE_C2_RADIO_ALLOW_LOW_POWER (( SHCI_OGF << 10) + SHCI_OCF_C2_RADIO_ALLOW_LOW_POWER) -#define SHCI_OPCODE_C2_MAC_802_15_4_INIT (( SHCI_OGF << 10) + SHCI_OCF_C2_MAC_802_15_4_INIT) - #define SHCI_OPCODE_C2_REINIT (( SHCI_OGF << 10) + SHCI_OCF_C2_REINIT) -#define SHCI_OPCODE_C2_ZIGBEE_INIT (( SHCI_OGF << 10) + SHCI_OCF_C2_ZIGBEE_INIT) - #define SHCI_OPCODE_C2_LLD_TESTS_INIT (( SHCI_OGF << 10) + SHCI_OCF_C2_LLD_TESTS_INIT) #define SHCI_OPCODE_C2_BLE_LLD_INIT (( SHCI_OGF << 10) + SHCI_OCF_C2_BLE_LLD_INIT) @@ -856,7 +844,7 @@ extern "C" { #define FUS_DEVICE_INFO_TABLE_VALIDITY_KEYWORD (0xA94656B9) /* - * At startup, the informations relative to the wireless binary are stored in RAM trough a structure defined by + * At startup, the information relative to the wireless binary are stored in RAM through a structure defined by * MB_WirelessFwInfoTable_t.This structure contains 4 fields (Version,MemorySize, Stack_info and a reserved part) * each of those coded on 32 bits as shown on the table below: * @@ -912,9 +900,6 @@ extern "C" { #define INFO_STACK_TYPE_BLE_HCI_EXT_ADV 0x07 #define INFO_STACK_TYPE_THREAD_FTD 0x10 #define INFO_STACK_TYPE_THREAD_MTD 0x11 -#define INFO_STACK_TYPE_ZIGBEE_FFD 0x30 -#define INFO_STACK_TYPE_ZIGBEE_RFD 0x31 -#define INFO_STACK_TYPE_MAC 0x40 #define INFO_STACK_TYPE_BLE_THREAD_FTD_STATIC 0x50 #define INFO_STACK_TYPE_BLE_THREAD_FTD_DYAMIC 0x51 #define INFO_STACK_TYPE_802154_LLD_TESTS 0x60 @@ -923,12 +908,7 @@ extern "C" { #define INFO_STACK_TYPE_BLE_LLD_TESTS 0x63 #define INFO_STACK_TYPE_BLE_RLV 0x64 #define INFO_STACK_TYPE_802154_RLV 0x65 -#define INFO_STACK_TYPE_BLE_ZIGBEE_FFD_STATIC 0x70 -#define INFO_STACK_TYPE_BLE_ZIGBEE_RFD_STATIC 0x71 -#define INFO_STACK_TYPE_BLE_ZIGBEE_FFD_DYNAMIC 0x78 -#define INFO_STACK_TYPE_BLE_ZIGBEE_RFD_DYNAMIC 0x79 #define INFO_STACK_TYPE_RLV 0x80 -#define INFO_STACK_TYPE_BLE_MAC_STATIC 0x90 typedef struct { /** @@ -1102,7 +1082,7 @@ typedef struct { * @brief Starts the LLD tests CLI * * @param param_size : Nb of bytes - * @param p_param : pointeur with data to give from M4 to M0 + * @param p_param : pointer with data to give from M4 to M0 * @retval Status */ SHCI_CmdStatus_t SHCI_C2_LLDTESTS_Init( uint8_t param_size, uint8_t * p_param ); @@ -1112,19 +1092,10 @@ typedef struct { * @brief Starts the LLD tests BLE * * @param param_size : Nb of bytes - * @param p_param : pointeur with data to give from M4 to M0 + * @param p_param : pointer with data to give from M4 to M0 * @retval Status */ SHCI_CmdStatus_t SHCI_C2_BLE_LLD_Init( uint8_t param_size, uint8_t * p_param ); - - /** - * SHCI_C2_ZIGBEE_Init - * @brief Starts the Zigbee Stack - * - * @param None - * @retval Status - */ - SHCI_CmdStatus_t SHCI_C2_ZIGBEE_Init( void ); /** * SHCI_C2_DEBUG_Init @@ -1200,16 +1171,6 @@ typedef struct { */ SHCI_CmdStatus_t SHCI_C2_RADIO_AllowLowPower( SHCI_C2_FLASH_Ip_t Ip,uint8_t FlagRadioLowPowerOn); - - /** - * SHCI_C2_MAC_802_15_4_Init - * @brief Starts the MAC 802.15.4 on M0 - * - * @param None - * @retval Status - */ - SHCI_CmdStatus_t SHCI_C2_MAC_802_15_4_Init( void ); - /** * SHCI_GetWirelessFwInfo * @brief This function read back the informations relative to the wireless binary loaded. diff --git a/src/utility/STM32Cube_FW/shci_tl.c b/src/utility/STM32Cube_FW/shci_tl.c index ddb3a02b..d1a448d5 100644 --- a/src/utility/STM32Cube_FW/shci_tl.c +++ b/src/utility/STM32Cube_FW/shci_tl.c @@ -16,12 +16,13 @@ ****************************************************************************** */ - +#if defined(STM32WBxx) /* Includes ------------------------------------------------------------------*/ #include "stm32_wpan_common.h" #include "stm_list.h" #include "shci_tl.h" +#include "stm32_def.h" /* Private typedef -----------------------------------------------------------*/ typedef enum @@ -168,6 +169,20 @@ void shci_send( uint16_t cmd_code, uint8_t len_cmd_payload, uint8_t * p_cmd_payl return; } +void shci_notify_asynch_evt(void *pdata) +{ + UNUSED(pdata); + /* Need to parse data in future version */ + shci_user_evt_proc(); +} + +void shci_register_io_bus(tSHciIO *fops) +{ + /* Register IO bus services */ + fops->Init = TL_SYS_Init; + fops->Send = TL_SYS_SendCmd; +} + /* Private functions ---------------------------------------------------------*/ static void TlInit( TL_CmdPacket_t * p_cmdbuffer ) { @@ -252,4 +267,4 @@ __WEAK void shci_cmd_resp_release(uint32_t flag) return; } - +#endif /* STM32WBxx */ diff --git a/src/utility/STM32Cube_FW/stm32_wpan_common.h b/src/utility/STM32Cube_FW/stm32_wpan_common.h index b47b804a..5a2b2a55 100644 --- a/src/utility/STM32Cube_FW/stm32_wpan_common.h +++ b/src/utility/STM32Cube_FW/stm32_wpan_common.h @@ -25,19 +25,9 @@ extern "C" { #endif -#if defined ( __CC_ARM ) - #define __ASM __asm /*!< asm keyword for ARM Compiler */ - #define __INLINE __inline /*!< inline keyword for ARM Compiler */ - #define __STATIC_INLINE static __inline -#elif defined ( __ICCARM__ ) - #define __ASM __asm /*!< asm keyword for IAR Compiler */ - #define __INLINE inline /*!< inline keyword for IAR Compiler. Only available in High optimization mode! */ - #define __STATIC_INLINE static inline -#elif defined ( __GNUC__ ) - #define __ASM __asm /*!< asm keyword for GNU Compiler */ - #define __INLINE inline /*!< inline keyword for GNU Compiler */ - #define __STATIC_INLINE static inline -#endif +#define __ASM __asm /*!< asm keyword for GNU Compiler */ +#define __INLINE inline /*!< inline keyword for GNU Compiler */ +#define __STATIC_INLINE static inline #include <stdint.h> #include <string.h> @@ -140,29 +130,8 @@ extern "C" { /* ----------------------------------- * * Packed usage (compiler dependent) * * ----------------------------------- */ -#undef PACKED__ #undef PACKED_STRUCT - -#if defined ( __CC_ARM ) - #if defined ( __GNUC__ ) - /* GNU extension */ - #define PACKED__ __attribute__((packed)) - #define PACKED_STRUCT struct PACKED__ - #elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050U) - #define PACKED__ __attribute__((packed)) - #define PACKED_STRUCT struct PACKED__ - #else - #define PACKED__(TYPE) __packed TYPE - #define PACKED_STRUCT PACKED__(struct) - #endif -#elif defined ( __GNUC__ ) - #define PACKED__ __attribute__((packed)) - #define PACKED_STRUCT struct PACKED__ -#elif defined (__ICCARM__) - #define PACKED_STRUCT __packed struct -#else - #define PACKED_STRUCT __packed struct -#endif +#define PACKED_STRUCT struct __packed #ifdef __cplusplus } diff --git a/src/utility/STM32Cube_FW/stm_list.c b/src/utility/STM32Cube_FW/stm_list.c index 4c928647..77dec64f 100644 --- a/src/utility/STM32Cube_FW/stm_list.c +++ b/src/utility/STM32Cube_FW/stm_list.c @@ -16,13 +16,13 @@ ****************************************************************************** */ - +#if defined(STM32WBxx) /****************************************************************************** * Include Files ******************************************************************************/ -#include "utilities_common.h" - #include "stm_list.h" +#include "cmsis_gcc.h" +#include "stm32_wpan_common.h" /****************************************************************************** * Function Definitions @@ -33,10 +33,10 @@ void LST_init_head (tListNode * listHead) listHead->prev = listHead; } -uint8_t LST_is_empty (tListNode * listHead) +bool LST_is_empty (tListNode * listHead) { uint32_t primask_bit; - uint8_t return_value; + bool return_value; primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ @@ -204,3 +204,4 @@ void LST_get_prev_node (tListNode * ref_node, tListNode ** node) __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ } +#endif /* STM32WBxx */ diff --git a/src/utility/STM32Cube_FW/stm_list.h b/src/utility/STM32Cube_FW/stm_list.h index b7c3254c..769c2113 100644 --- a/src/utility/STM32Cube_FW/stm_list.h +++ b/src/utility/STM32Cube_FW/stm_list.h @@ -21,6 +21,8 @@ #define _STM_LIST_H_ /* Includes ------------------------------------------------------------------*/ +#include "stdint.h" +#include "stdbool.h" #include "stm32_wpan_common.h" typedef PACKED_STRUCT _tListNode { @@ -30,7 +32,7 @@ typedef PACKED_STRUCT _tListNode { void LST_init_head (tListNode * listHead); -uint8_t LST_is_empty (tListNode * listHead); +bool LST_is_empty (tListNode * listHead); void LST_insert_head (tListNode * listHead, tListNode * node); diff --git a/src/utility/STM32Cube_FW/tl.h b/src/utility/STM32Cube_FW/tl.h index 2124d260..678769cb 100644 --- a/src/utility/STM32Cube_FW/tl.h +++ b/src/utility/STM32Cube_FW/tl.h @@ -199,19 +199,6 @@ typedef struct uint8_t *p_BleLldM0CmdBuffer; } TL_BLE_LLD_Config_t; -typedef struct -{ - uint8_t *p_Mac_802_15_4_CmdRspBuffer; - uint8_t *p_Mac_802_15_4_NotAckBuffer; -} TL_MAC_802_15_4_Config_t; - -typedef struct -{ - uint8_t *p_ZigbeeOtCmdRspBuffer; - uint8_t *p_ZigbeeNotAckBuffer; - uint8_t *p_ZigbeeNotifRequestBuffer; -} TL_ZIGBEE_Config_t; - /** * @brief Contain the BLE HCI Init Configuration * @{ @@ -305,26 +292,6 @@ void TL_MM_EvtDone( TL_EvtPacket_t * hcievt ); void TL_TRACES_Init( void ); void TL_TRACES_EvtReceived( TL_EvtPacket_t * hcievt ); -/****************************************************************************** - * MAC 802.15.4 - ******************************************************************************/ -void TL_MAC_802_15_4_Init( TL_MAC_802_15_4_Config_t *p_Config ); -void TL_MAC_802_15_4_SendCmd( void ); -void TL_MAC_802_15_4_CmdEvtReceived( TL_EvtPacket_t * Otbuffer ); -void TL_MAC_802_15_4_NotReceived( TL_EvtPacket_t * Notbuffer ); -void TL_MAC_802_15_4_SendAck ( void ); - -/****************************************************************************** - * ZIGBEE - ******************************************************************************/ -void TL_ZIGBEE_Init( TL_ZIGBEE_Config_t *p_Config ); -void TL_ZIGBEE_SendM4RequestToM0( void ); -void TL_ZIGBEE_SendM4AckToM0Notify ( void ); -void TL_ZIGBEE_NotReceived( TL_EvtPacket_t * Notbuffer ); -void TL_ZIGBEE_CmdEvtReceived( TL_EvtPacket_t * Otbuffer ); -void TL_ZIGBEE_M0RequestReceived(TL_EvtPacket_t * Otbuffer ); -void TL_ZIGBEE_SendM4AckToM0Request(void); - #ifdef __cplusplus } /* extern "C" */ #endif diff --git a/src/utility/STM32Cube_FW/tl_mbox.c b/src/utility/STM32Cube_FW/tl_mbox.c index 4112429d..a9abb181 100644 --- a/src/utility/STM32Cube_FW/tl_mbox.c +++ b/src/utility/STM32Cube_FW/tl_mbox.c @@ -16,6 +16,7 @@ ****************************************************************************** */ +#if defined(STM32WBxx) /* Includes ------------------------------------------------------------------*/ #include "stm32_wpan_common.h" #include "hw.h" @@ -51,15 +52,13 @@ PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_BleLldTable_t TL_BleLldTable; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_SysTable_t TL_SysTable; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_MemManagerTable_t TL_MemManagerTable; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_TracesTable_t TL_TracesTable; -PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_Mac_802_15_4_t TL_Mac_802_15_4_Table; -PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_ZigbeeTable_t TL_Zigbee_Table; /**< tables */ PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode FreeBufQueue; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode TracesEvtQueue; PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static uint8_t CsBuffer[sizeof(TL_PacketHeader_t) + TL_EVT_HDR_SIZE + sizeof(TL_CsEvt_t)]; -PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode EvtQueue; -PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode SystemEvtQueue; +PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static tListNode EvtQueue; +PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static tListNode SystemEvtQueue; static tListNode LocalFreeBufQueue; @@ -97,8 +96,6 @@ void TL_Init( void ) TL_RefTable.p_sys_table = &TL_SysTable; TL_RefTable.p_mem_manager_table = &TL_MemManagerTable; TL_RefTable.p_traces_table = &TL_TracesTable; - TL_RefTable.p_mac_802_15_4_table = &TL_Mac_802_15_4_Table; - TL_RefTable.p_zigbee_table = &TL_Zigbee_Table; HW_IPCC_Init(); return; @@ -452,139 +449,6 @@ void TL_BLE_LLD_SendRspAck( void ) } #endif /* BLE_LLD_WB */ -#ifdef MAC_802_15_4_WB -/****************************************************************************** - * MAC 802.15.4 - ******************************************************************************/ -void TL_MAC_802_15_4_Init( TL_MAC_802_15_4_Config_t *p_Config ) -{ - MB_Mac_802_15_4_t * p_mac_802_15_4_table; - - p_mac_802_15_4_table = TL_RefTable.p_mac_802_15_4_table; - - p_mac_802_15_4_table->p_cmdrsp_buffer = p_Config->p_Mac_802_15_4_CmdRspBuffer; - p_mac_802_15_4_table->p_notack_buffer = p_Config->p_Mac_802_15_4_NotAckBuffer; - - HW_IPCC_MAC_802_15_4_Init(); - - return; -} - -void TL_MAC_802_15_4_SendCmd( void ) -{ - ((TL_CmdPacket_t *)(TL_RefTable.p_mac_802_15_4_table->p_cmdrsp_buffer))->cmdserial.type = TL_OTCMD_PKT_TYPE; - - HW_IPCC_MAC_802_15_4_SendCmd(); - - return; -} - -void TL_MAC_802_15_4_SendAck ( void ) -{ - ((TL_CmdPacket_t *)(TL_RefTable.p_mac_802_15_4_table->p_notack_buffer))->cmdserial.type = TL_OTACK_PKT_TYPE; - - HW_IPCC_MAC_802_15_4_SendAck(); - - return; -} - -void HW_IPCC_MAC_802_15_4_CmdEvtNot(void) -{ - TL_MAC_802_15_4_CmdEvtReceived( (TL_EvtPacket_t*)(TL_RefTable.p_mac_802_15_4_table->p_cmdrsp_buffer) ); - - return; -} - -void HW_IPCC_MAC_802_15_4_EvtNot( void ) -{ - TL_MAC_802_15_4_NotReceived( (TL_EvtPacket_t*)(TL_RefTable.p_mac_802_15_4_table->p_notack_buffer) ); - - return; -} - -__WEAK void TL_MAC_802_15_4_CmdEvtReceived( TL_EvtPacket_t * Otbuffer ){}; -__WEAK void TL_MAC_802_15_4_NotReceived( TL_EvtPacket_t * Notbuffer ){}; -#endif - -#ifdef ZIGBEE_WB -/****************************************************************************** - * ZIGBEE - ******************************************************************************/ -void TL_ZIGBEE_Init( TL_ZIGBEE_Config_t *p_Config ) -{ - MB_ZigbeeTable_t * p_zigbee_table; - - p_zigbee_table = TL_RefTable.p_zigbee_table; - p_zigbee_table->appliCmdM4toM0_buffer = p_Config->p_ZigbeeOtCmdRspBuffer; - p_zigbee_table->notifM0toM4_buffer = p_Config->p_ZigbeeNotAckBuffer; - p_zigbee_table->requestM0toM4_buffer = p_Config->p_ZigbeeNotifRequestBuffer; - - HW_IPCC_ZIGBEE_Init(); - - return; -} - -/* Zigbee M4 to M0 Request */ -void TL_ZIGBEE_SendM4RequestToM0( void ) -{ - ((TL_CmdPacket_t *)(TL_RefTable.p_zigbee_table->appliCmdM4toM0_buffer))->cmdserial.type = TL_OTCMD_PKT_TYPE; - - HW_IPCC_ZIGBEE_SendM4RequestToM0(); - - return; -} - -/* Used to receive an ACK from the M0 */ -void HW_IPCC_ZIGBEE_RecvAppliAckFromM0(void) -{ - TL_ZIGBEE_CmdEvtReceived( (TL_EvtPacket_t*)(TL_RefTable.p_zigbee_table->appliCmdM4toM0_buffer) ); - - return; -} - -/* Zigbee notification from M0 to M4 */ -void HW_IPCC_ZIGBEE_RecvM0NotifyToM4( void ) -{ - TL_ZIGBEE_NotReceived( (TL_EvtPacket_t*)(TL_RefTable.p_zigbee_table->notifM0toM4_buffer) ); - - return; -} - -/* Send an ACK to the M0 for a Notification */ -void TL_ZIGBEE_SendM4AckToM0Notify ( void ) -{ - ((TL_CmdPacket_t *)(TL_RefTable.p_zigbee_table->notifM0toM4_buffer))->cmdserial.type = TL_OTACK_PKT_TYPE; - - HW_IPCC_ZIGBEE_SendM4AckToM0Notify(); - - return; -} - -/* Zigbee M0 to M4 Request */ -void HW_IPCC_ZIGBEE_RecvM0RequestToM4( void ) -{ - TL_ZIGBEE_M0RequestReceived( (TL_EvtPacket_t*)(TL_RefTable.p_zigbee_table->requestM0toM4_buffer) ); - - return; -} - -/* Send an ACK to the M0 for a Request */ -void TL_ZIGBEE_SendM4AckToM0Request(void) -{ - ((TL_CmdPacket_t *)(TL_RefTable.p_zigbee_table->requestM0toM4_buffer))->cmdserial.type = TL_OTACK_PKT_TYPE; - - HW_IPCC_ZIGBEE_SendM4AckToM0Request(); - - return; -} - - -__WEAK void TL_ZIGBEE_CmdEvtReceived( TL_EvtPacket_t * Otbuffer ){}; -__WEAK void TL_ZIGBEE_NotReceived( TL_EvtPacket_t * Notbuffer ){}; -#endif - - - /****************************************************************************** * MEMORY MANAGER ******************************************************************************/ @@ -846,4 +710,4 @@ static void OutputDbgTrace(TL_MB_PacketType_t packet_type, uint8_t* buffer) return; } - +#endif /* STM32WBxx */ From 882addad6a096adf402041d662f4edb941b80071 Mon Sep 17 00:00:00 2001 From: Alexandre Bourdiol <alexandre.bourdiol@st.com> Date: Tue, 30 Aug 2022 13:19:36 +0200 Subject: [PATCH 094/226] fix: include a timeout when waiting for the cmd_resp Signed-off-by: Alexandre Bourdiol <alexandre.bourdiol@st.com> --- src/utility/STM32Cube_FW/shci_tl.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/utility/STM32Cube_FW/shci_tl.c b/src/utility/STM32Cube_FW/shci_tl.c index d1a448d5..678de84d 100644 --- a/src/utility/STM32Cube_FW/shci_tl.c +++ b/src/utility/STM32Cube_FW/shci_tl.c @@ -20,6 +20,8 @@ /* Includes ------------------------------------------------------------------*/ #include "stm32_wpan_common.h" +#include <Arduino.h> + #include "stm_list.h" #include "shci_tl.h" #include "stm32_def.h" @@ -250,11 +252,12 @@ static void TlUserEvtReceived(TL_EvtPacket_t *shcievt) /* Weak implementation ----------------------------------------------------------------*/ __WEAK void shci_cmd_resp_wait(uint32_t timeout) { - (void)timeout; - CmdRspStatusFlag = SHCI_TL_CMD_RESP_WAIT; - while(CmdRspStatusFlag != SHCI_TL_CMD_RESP_RELEASE); - + for (unsigned long start = millis(); (millis() - start) < timeout;) { + if (CmdRspStatusFlag == SHCI_TL_CMD_RESP_RELEASE) { + break; + } + } return; } From 4eb33a136d8f59874fa112df868f8b025d128c83 Mon Sep 17 00:00:00 2001 From: Alexandre Bourdiol <alexandre.bourdiol@st.com> Date: Tue, 30 Aug 2022 13:31:31 +0200 Subject: [PATCH 095/226] Added support for custom app_conf.h Signed-off-by: Alexandre Bourdiol <alexandre.bourdiol@st.com> --- src/utility/STM32Cube_FW/app_conf_default.h | 71 ++++++++++++++------- 1 file changed, 47 insertions(+), 24 deletions(-) diff --git a/src/utility/STM32Cube_FW/app_conf_default.h b/src/utility/STM32Cube_FW/app_conf_default.h index 54f824ae..91672ac9 100644 --- a/src/utility/STM32Cube_FW/app_conf_default.h +++ b/src/utility/STM32Cube_FW/app_conf_default.h @@ -1,8 +1,8 @@ /** ****************************************************************************** - * @file app_conf.h + * @file app_conf_default.h * @author MCD Application Team - * @brief Application configuration file for STM32WPAN Middleware. + * @brief Default application configuration file for STM32WPAN Middleware. ****************************************************************************** * @attention * @@ -17,11 +17,8 @@ */ /* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef APP_CONF_H -#define APP_CONF_H - -#include "hw.h" -#include "ble_bufsize.h" +#ifndef APP_CONF_DEFAULT_H +#define APP_CONF_DEFAULT_H /****************************************************************************** * Application Config @@ -44,7 +41,9 @@ /** * Define Tx Power */ -#define CFG_TX_POWER (0x18) /* -0.15dBm */ +#ifndef CFG_TX_POWER + #define CFG_TX_POWER (0x18) /* -0.15dBm */ +#endif /****************************************************************************** * BLE Stack @@ -53,13 +52,17 @@ * Maximum number of simultaneous connections that the device will support. * Valid values are from 1 to 8 */ -#define CFG_BLE_NUM_LINK 8 +#ifndef CFG_BLE_NUM_LINK + #define CFG_BLE_NUM_LINK 8 +#endif /** * Maximum number of Services that can be stored in the GATT database. * Note that the GAP and GATT services are automatically added so this parameter should be 2 plus the number of user services */ -#define CFG_BLE_NUM_GATT_SERVICES 8 +#ifndef CFG_BLE_NUM_GATT_SERVICES + #define CFG_BLE_NUM_GATT_SERVICES 8 +#endif /** * Maximum number of Attributes @@ -68,13 +71,17 @@ * Note that certain characteristics and relative descriptors are added automatically during device initialization * so this parameters should be 9 plus the number of user Attributes */ -#define CFG_BLE_NUM_GATT_ATTRIBUTES 68 +#ifndef CFG_BLE_NUM_GATT_ATTRIBUTES + #define CFG_BLE_NUM_GATT_ATTRIBUTES 68 +#endif /** * Maximum supported ATT_MTU size * This parameter is ignored by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set */ -#define CFG_BLE_MAX_ATT_MTU (156) +#ifndef CFG_BLE_MAX_ATT_MTU + #define CFG_BLE_MAX_ATT_MTU (156) +#endif /** * Size of the storage area for Attribute values @@ -87,14 +94,18 @@ * The total amount of memory needed is the sum of the above quantities for each attribute. * This parameter is ignored by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set */ -#define CFG_BLE_ATT_VALUE_ARRAY_SIZE (1344) +#ifndef CFG_BLE_ATT_VALUE_ARRAY_SIZE + #define CFG_BLE_ATT_VALUE_ARRAY_SIZE (1344) +#endif /** * Prepare Write List size in terms of number of packet * This parameter is ignored by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set */ // #define CFG_BLE_PREPARE_WRITE_LIST_SIZE BLE_PREP_WRITE_X_ATT(CFG_BLE_MAX_ATT_MTU) -#define CFG_BLE_PREPARE_WRITE_LIST_SIZE (0x3A) +#ifndef CFG_BLE_PREPARE_WRITE_LIST_SIZE + #define CFG_BLE_PREPARE_WRITE_LIST_SIZE (0x3A) +#endif /** * Number of allocated memory blocks @@ -106,12 +117,16 @@ /** * Enable or disable the Extended Packet length feature. Valid values are 0 or 1. */ -#define CFG_BLE_DATA_LENGTH_EXTENSION 1 +#ifndef CFG_BLE_DATA_LENGTH_EXTENSION + #define CFG_BLE_DATA_LENGTH_EXTENSION 1 +#endif /** * Sleep clock accuracy in Slave mode (ppm value) */ -#define CFG_BLE_SLAVE_SCA 500 +#ifndef CFG_BLE_SLAVE_SCA + #define CFG_BLE_SLAVE_SCA 500 +#endif /** * Sleep clock accuracy in Master mode @@ -124,7 +139,9 @@ * 6 : 21 ppm to 30 ppm * 7 : 0 ppm to 20 ppm */ -#define CFG_BLE_MASTER_SCA 0 +#ifndef CFG_BLE_MASTER_SCA + #define CFG_BLE_MASTER_SCA 0 +#endif /** * LsSource @@ -132,21 +149,27 @@ * - bit 0: 1: Calibration for the RF system wakeup clock source 0: No calibration for the RF system wakeup clock source * - bit 1: 1: STM32W5M Module device 0: Other devices as STM32WBxx SOC, STM32WB1M module */ -#if defined(STM32WB5Mxx) - #define CFG_BLE_LSE_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LSE_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LSE_MOD5MM_DEV) -#else - #define CFG_BLE_LSE_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LSE_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LSE_OTHER_DEV) +#ifndef CFG_BLE_LSE_SOURCE + #if defined(STM32WB5Mxx) + #define CFG_BLE_LSE_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LSE_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LSE_MOD5MM_DEV) + #else + #define CFG_BLE_LSE_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LSE_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LSE_OTHER_DEV) + #endif #endif /** * Start up time of the high speed (16 or 32 MHz) crystal oscillator in units of 625/256 us (~2.44 us) */ -#define CFG_BLE_HSE_STARTUP_TIME 0x148 +#ifndef CFG_BLE_HSE_STARTUP_TIME + #define CFG_BLE_HSE_STARTUP_TIME 0x148 +#endif /** * Maximum duration of the connection event when the device is in Slave mode in units of 625/256 us (~2.44 us) */ -#define CFG_BLE_MAX_CONN_EVENT_LENGTH (0xFFFFFFFF) +#ifndef CFG_BLE_MAX_CONN_EVENT_LENGTH + #define CFG_BLE_MAX_CONN_EVENT_LENGTH (0xFFFFFFFF) +#endif /** * Viterbi Mode @@ -234,5 +257,5 @@ #define CFG_BLE_RX_PATH_COMPENS (0) -#endif /*APP_CONF_H */ +#endif /* APP_CONF_DEFAULT_H */ From 3f234253695437855f6e5a2fc9b5e884f33ee749 Mon Sep 17 00:00:00 2001 From: Alexandre Bourdiol <alexandre.bourdiol@st.com> Date: Wed, 31 Aug 2022 17:18:16 +0200 Subject: [PATCH 096/226] Fix: Remove compilation warning about uninitialized struct field Signed-off-by: Alexandre Bourdiol <alexandre.bourdiol@st.com> --- src/utility/HCISharedMemTransport.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/utility/HCISharedMemTransport.cpp b/src/utility/HCISharedMemTransport.cpp index c8de8c56..2a70c905 100644 --- a/src/utility/HCISharedMemTransport.cpp +++ b/src/utility/HCISharedMemTransport.cpp @@ -740,7 +740,12 @@ int HCISharedMemTransportClass::stm32wb_start_ble(void) CFG_BLE_MAX_COC_INITIATOR_NBR, CFG_BLE_MIN_TX_POWER, CFG_BLE_MAX_TX_POWER, - CFG_BLE_RX_MODEL_CONFIG + CFG_BLE_RX_MODEL_CONFIG, + CFG_BLE_MAX_ADV_SET_NBR, + CFG_BLE_MAX_ADV_DATA_LEN, + CFG_BLE_TX_PATH_COMPENS, + CFG_BLE_RX_PATH_COMPENS + }; /** * Starts the BLE Stack on CPU2 From f77db6b5fc4400c89b54abcb498822a2bf619ea2 Mon Sep 17 00:00:00 2001 From: Alexandre Bourdiol <alexandre.bourdiol@st.com> Date: Fri, 2 Sep 2022 14:59:07 +0200 Subject: [PATCH 097/226] Fix: Move EvtPool array from MB_MEM2 to MB_MEM1 MB_MEM1 and MB_MEM2 ae now respectively in SRAM2a and SRAM2b SRAM2a being too small to put all shared memory variables Warning depends on split made on core: variants/STM32WBxx/WB55R(C-E-G)V/ldscript.ld Signed-off-by: Alexandre Bourdiol <alexandre.bourdiol@st.com> --- src/utility/HCISharedMemTransport.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utility/HCISharedMemTransport.cpp b/src/utility/HCISharedMemTransport.cpp index 2a70c905..0b46bda4 100644 --- a/src/utility/HCISharedMemTransport.cpp +++ b/src/utility/HCISharedMemTransport.cpp @@ -25,7 +25,7 @@ /* Private variables ---------------------------------------------------------*/ PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static TL_CmdPacket_t BleCmdBuffer; -PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static uint8_t EvtPool[POOL_SIZE]; +PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static uint8_t EvtPool[POOL_SIZE]; PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static TL_CmdPacket_t SystemCmdBuffer; PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static uint8_t SystemSpareEvtBuffer[sizeof(TL_PacketHeader_t) + TL_EVT_HDR_SIZE + 255]; From f4c26072f6fa09225d3c7ae0ece8dbfc94b3c9d5 Mon Sep 17 00:00:00 2001 From: Alexandre Bourdiol <alexandre.bourdiol@st.com> Date: Tue, 30 Aug 2022 13:32:30 +0200 Subject: [PATCH 098/226] fix: implement BLE debug based on core_debug() Signed-off-by: Alexandre Bourdiol <alexandre.bourdiol@st.com> --- src/utility/STM32Cube_FW/tl_dbg_conf.h | 140 +++++++++++++++++++++++++ 1 file changed, 140 insertions(+) create mode 100644 src/utility/STM32Cube_FW/tl_dbg_conf.h diff --git a/src/utility/STM32Cube_FW/tl_dbg_conf.h b/src/utility/STM32Cube_FW/tl_dbg_conf.h new file mode 100644 index 00000000..841d1968 --- /dev/null +++ b/src/utility/STM32Cube_FW/tl_dbg_conf.h @@ -0,0 +1,140 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * File Name : tl_dbg_conf.h + * Description : Debug configuration file for stm32wpan transport layer interface. + * + ****************************************************************************** + * @attention + * + * Copyright (c) 2019-2021 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef TL_DBG_CONF_H +#define TL_DBG_CONF_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* USER CODE BEGIN Tl_Conf */ + +/* Includes ------------------------------------------------------------------*/ +#include "core_debug.h" + +/** + * Enable or Disable traces + * The raw data output is the hci binary packet format as specified by the BT specification * + */ +#ifndef TL_SHCI_CMD_DBG_EN +#define TL_SHCI_CMD_DBG_EN 1 /* Reports System commands sent to CPU2 and the command response */ +#endif + +#ifndef TL_SHCI_EVT_DBG_EN +#define TL_SHCI_EVT_DBG_EN 1 /* Reports System Asynchronous Events received from CPU2 */ +#endif + +#ifndef TL_HCI_CMD_DBG_EN +#define TL_HCI_CMD_DBG_EN 1 /* Reports BLE command sent to CPU2 and the command response */ +#endif + +#ifndef TL_HCI_EVT_DBG_EN +#define TL_HCI_EVT_DBG_EN 1 /* Reports BLE Asynchronous Events received from CPU2 */ +#endif + +#ifndef TL_MM_DBG_EN +#define TL_MM_DBG_EN 1 /* Reports the information of the buffer released to CPU2 */ +#endif + +/** + * Macro definition + */ + +/** + * System Transport Layer + */ +#if (TL_SHCI_CMD_DBG_EN != 0) +#define TL_SHCI_CMD_DBG_MSG core_debug +#define TL_SHCI_CMD_DBG_BUF PRINT_LOG_BUFF_DBG +#else +#define TL_SHCI_CMD_DBG_MSG(...) +#define TL_SHCI_CMD_DBG_BUF(...) +#endif + +#define TL_SHCI_CMD_DBG_RAW(...) + +#if (TL_SHCI_EVT_DBG_EN != 0) +#define TL_SHCI_EVT_DBG_MSG core_debug +#define TL_SHCI_EVT_DBG_BUF PRINT_LOG_BUFF_DBG +#else +#define TL_SHCI_EVT_DBG_MSG(...) +#define TL_SHCI_EVT_DBG_BUF(...) +#endif + +#define TL_SHCI_EVT_DBG_RAW(...) + +/** + * BLE Transport Layer + */ +#if (TL_HCI_CMD_DBG_EN != 0) +#define TL_HCI_CMD_DBG_MSG core_debug +#define TL_HCI_CMD_DBG_BUF PRINT_LOG_BUFF_DBG +#else +#define TL_HCI_CMD_DBG_MSG(...) +#define TL_HCI_CMD_DBG_BUF(...) +#endif + +#define TL_HCI_CMD_DBG_RAW(...) + +#if (TL_HCI_EVT_DBG_EN != 0) +#define TL_HCI_EVT_DBG_MSG core_debug +#define TL_HCI_EVT_DBG_BUF PRINT_LOG_BUFF_DBG +#else +#define TL_HCI_EVT_DBG_MSG(...) +#define TL_HCI_EVT_DBG_BUF(...) +#endif + +#define TL_HCI_EVT_DBG_RAW(...) + +/** + * Memory Manager - Released buffer tracing + */ +#if (TL_MM_DBG_EN != 0) +#define TL_MM_DBG_MSG core_debug +#else +#define TL_MM_DBG_MSG(...) +#endif + + +#define PRINT_LOG_BUFF_DBG(...) DbgTraceBuffer(__VA_ARGS__) + +void DbgTraceBuffer(const void *pBuffer, uint32_t u32Length, const char *strFormat, ...) +{ + va_list vaArgs; + uint32_t u32Index; + va_start(vaArgs, strFormat); + vprintf(strFormat, vaArgs); + va_end(vaArgs); + for (u32Index = 0; u32Index < u32Length; u32Index ++) + { + core_debug(" %02X", ((const uint8_t *) pBuffer)[u32Index]); + } +} + +/* USER CODE END Tl_Conf */ + +#ifdef __cplusplus +} +#endif + +#endif /* TL_DBG_CONF_H */ + From 1c8974d88f88d764e3b2aa9d045bcd61f0e0a4c5 Mon Sep 17 00:00:00 2001 From: Alexandre Bourdiol <alexandre.bourdiol@st.com> Date: Mon, 24 Oct 2022 11:35:21 +0200 Subject: [PATCH 099/226] fix: HCI only Firmware not supporting ACI_GAP_INIT ACI_GATT_INIT On STM32WB, Cube FW version 1.14.1, messages ACI_GATT_INIT and ACI_GAP_INIT are not available on HCI only BLE firmware (stm32wb5x_BLE_HCILayer_fw.bin) This imply to move Random Address to host instead of relying on controller Signed-off-by: Alexandre Bourdiol <alexandre.bourdiol@st.com> --- src/local/BLELocalDevice.cpp | 12 ++ src/utility/HCI.cpp | 12 ++ src/utility/HCI.h | 1 + src/utility/HCISharedMemTransport.cpp | 214 +------------------------- src/utility/HCISharedMemTransport.h | 5 - 5 files changed, 33 insertions(+), 211 deletions(-) diff --git a/src/local/BLELocalDevice.cpp b/src/local/BLELocalDevice.cpp index d4824f53..36152065 100644 --- a/src/local/BLELocalDevice.cpp +++ b/src/local/BLELocalDevice.cpp @@ -51,6 +51,18 @@ int BLELocalDevice::begin() return 0; } + uint8_t randomNumber[8]; + if (HCI.leRand(randomNumber) != 0) { + end(); + return 0; + } + + randomNumber[5] |= 0xC0; // Force both MSB bit to b00 in order to define Random Address + if (HCI.leSetRandomAddress((uint8_t*)randomNumber) != 0) { + end(); + return 0; + } + uint8_t hciVer; uint16_t hciRev; uint8_t lmpVer; diff --git a/src/utility/HCI.cpp b/src/utility/HCI.cpp index 96b42537..f9c7d9c1 100644 --- a/src/utility/HCI.cpp +++ b/src/utility/HCI.cpp @@ -68,6 +68,7 @@ #define OCF_LE_CREATE_CONN 0x000d #define OCF_LE_CANCEL_CONN 0x000e #define OCF_LE_CONN_UPDATE 0x0013 +#define OCF_LE_RAND 0x0018 #define HCI_OE_USER_ENDED_CONNECTION 0x13 @@ -392,6 +393,17 @@ int HCIClass::leConnUpdate(uint16_t handle, uint16_t minInterval, uint16_t maxIn return sendCommand(OGF_LE_CTL << 10 | OCF_LE_CONN_UPDATE, sizeof(leConnUpdateData), &leConnUpdateData); } +int HCIClass::leRand(uint8_t randomNumber[8]) +{ + int result = sendCommand(OGF_LE_CTL << 10 | OCF_LE_RAND); + + if (result == 0) { + memcpy(randomNumber, _cmdResponse, 8); + } + + return result; +} + int HCIClass::sendAclPkt(uint16_t handle, uint8_t cid, uint8_t plen, void* data) { while (_pendingPkt >= _maxPkt) { diff --git a/src/utility/HCI.h b/src/utility/HCI.h index 0efd8125..b4a40e63 100644 --- a/src/utility/HCI.h +++ b/src/utility/HCI.h @@ -63,6 +63,7 @@ class HCIClass { virtual int leConnUpdate(uint16_t handle, uint16_t minInterval, uint16_t maxInterval, uint16_t latency, uint16_t supervisionTimeout); virtual int leCancelConn(); + virtual int leRand(uint8_t randomNumber[8]); virtual int sendAclPkt(uint16_t handle, uint8_t cid, uint8_t plen, void* data); diff --git a/src/utility/HCISharedMemTransport.cpp b/src/utility/HCISharedMemTransport.cpp index 0b46bda4..e8c422c9 100644 --- a/src/utility/HCISharedMemTransport.cpp +++ b/src/utility/HCISharedMemTransport.cpp @@ -48,17 +48,12 @@ volatile uint16_t _write_index; /* fifo position when receiving */ /* var of different device steps during init and receiving */ volatile bool phase_bd_addr; volatile bool phase_tx_power; -volatile bool phase_gatt_init; -volatile bool phase_gap_init; -volatile bool phase_random_addr; -volatile bool phase_get_random_addr; volatile bool phase_reset; volatile bool phase_running; -volatile bool is_random_addr_msg; + /** Bluetooth Device Address */ static uint8_t bd_addr_udn[CONFIG_DATA_PUBADDR_LEN]; -static uint8_t helper_random_addr[6]; /* Private functions ---------------------------------------------------------*/ /** @@ -186,16 +181,10 @@ void evt_received(TL_EvtPacket_t *hcievt) (hcievt->evtserial.evt.payload[0] == 0x01) && (hcievt->evtserial.evt.payload[1] == 0x0C) && (hcievt->evtserial.evt.payload[2] == 0xFC)) { - /* First setting must be global address and is_random_addr_msg should be false - * Second setting must be static random address and is_random_addr_msg should be true + /* First setting must be global address */ - if(!is_random_addr_msg) { - phase_bd_addr = true; - is_random_addr_msg = true; - } else { - phase_random_addr = true; - is_random_addr_msg = false; - } + phase_bd_addr = true; + if (hcievt->evtserial.evt.payload[3] != 0) { #if defined(PRINT_IPCC_INFO) printf("Error: wrong BD Addr\r\n"); @@ -218,50 +207,7 @@ void evt_received(TL_EvtPacket_t *hcievt) /* rx data is no more useful : not stored in the _rxbuff */ break; } - /* check the Rx event of complete the previous gatt init 0xFD01 */ - if ((hcievt->evtserial.evt.evtcode == TL_BLEEVT_CC_OPCODE) && - (hcievt->evtserial.evt.payload[0] == 0x01) && - (hcievt->evtserial.evt.payload[1] == 0x01) && - (hcievt->evtserial.evt.payload[2] == 0xFD)) { - phase_gatt_init = true; - if (hcievt->evtserial.evt.payload[3] != 0) { -#if defined(PRINT_IPCC_INFO) - printf("Error: wrong Random Addr\r\n"); -#endif /*(PRINT_IPCC_INFO)*/ - } - /* rx data is no more useful : not stored in the _rxbuff */ - break; - } - /* check the Rx event of complete the previous gap init 0xFC8A */ - if ((hcievt->evtserial.evt.evtcode == TL_BLEEVT_CC_OPCODE) && - (hcievt->evtserial.evt.payload[0] == 0x01) && - (hcievt->evtserial.evt.payload[1] == 0x8A) && - (hcievt->evtserial.evt.payload[2] == 0xFC)) { - phase_gap_init = true; - if (hcievt->evtserial.evt.payload[3] != 0) { -#if defined(PRINT_IPCC_INFO) - printf("Error: wrong Random Addr\r\n"); -#endif /*(PRINT_IPCC_INFO)*/ - } - /* rx data is no more useful : not stored in the _rxbuff */ - break; - } - /* check the Rx event of complete the previous get random addr opcode 0xFC0D */ - if ((hcievt->evtserial.evt.evtcode == TL_BLEEVT_CC_OPCODE) && - (hcievt->evtserial.evt.payload[0] == 0x01) && - (hcievt->evtserial.evt.payload[1] == 0x0D) && - (hcievt->evtserial.evt.payload[2] == 0xFC)) { - if (hcievt->evtserial.evt.payload[3] != 0) { -#if defined(PRINT_IPCC_INFO) - printf("Error: wrong Random Addr\r\n"); -#endif /*(PRINT_IPCC_INFO)*/ - } - memcpy(helper_random_addr, &hcievt->evtserial.evt.payload[5], 6); - phase_get_random_addr = true; - /* rx data is no more useful : not stored in the _rxbuff */ - break; - } /* check if the reset phase is in progress (opcode is 0x0C03) */ if ((hcievt->evtserial.evt.evtcode == TL_BLEEVT_CC_OPCODE) && (hcievt->evtserial.evt.payload[0] == 0x01) && @@ -391,10 +337,10 @@ static bool get_bd_address(uint8_t *bd_addr) bd_addr[0] = (uint8_t)(udn & 0x000000FF); bd_addr[1] = (uint8_t)((udn & 0x0000FF00) >> 8); - bd_addr[2] = (uint8_t)((udn & 0x00FF0000) >> 16); - bd_addr[3] = (uint8_t)device_id; - bd_addr[4] = (uint8_t)(company_id & 0x000000FF); - bd_addr[5] = (uint8_t)((company_id & 0x0000FF00) >> 8); + bd_addr[2] = (uint8_t)device_id; + bd_addr[3] = (uint8_t)(company_id & 0x000000FF); + bd_addr[4] = (uint8_t)((company_id & 0x0000FF00) >> 8); + bd_addr[5] = (uint8_t)((company_id & 0x00FF0000) >> 16); bd_found = true; } else { @@ -448,13 +394,8 @@ HCISharedMemTransportClass::HCISharedMemTransportClass() phase_bd_addr = false; phase_tx_power = false; - phase_gatt_init = false; - phase_gap_init = false; - phase_random_addr = false; - phase_get_random_addr = false; phase_reset = false; phase_running = false; - is_random_addr_msg = false; } HCISharedMemTransportClass::~HCISharedMemTransportClass() @@ -517,13 +458,8 @@ void HCISharedMemTransportClass::end() /* the HCI RESET command ready to be processed again */ phase_bd_addr = false; phase_tx_power = false; - phase_gatt_init = false; - phase_gap_init = false; - phase_random_addr = false; - phase_get_random_addr = false; phase_reset = false; phase_running = false; - is_random_addr_msg = false; } void HCISharedMemTransportClass::wait(unsigned long timeout) @@ -614,34 +550,11 @@ size_t HCISharedMemTransportClass::write(const uint8_t *data, size_t length) while (!phase_bd_addr); /* this sequence is now complete */ - /* set the random address */ - bt_ipm_set_random_addr(); - /* wait for the Rx complete */ - while (!phase_random_addr); - /* set the Tx power */ bt_ipm_set_power(); /* wait for the Rx complete */ while (!phase_tx_power); - /* gatt init */ - bt_ipm_gatt_init(); - /* wait for the Rx complete */ - while (!phase_gatt_init); - - /* gap init */ - bt_ipm_gap_init(); - /* wait for the Rx complete */ - while (!phase_gap_init); - - /* get the random address */ - bt_ipm_get_random_addr(); - /* wait for the Rx complete */ - while (!phase_get_random_addr); - - /* Now we can copy the random address and save it in the transport class */ - memcpy(_random_addr, helper_random_addr, 6); - /* this sequence is now complete */ phase_running = true; @@ -831,43 +744,6 @@ int HCISharedMemTransportClass::bt_ipm_set_addr(void) return 0; /* Error */ } -int HCISharedMemTransportClass::bt_ipm_set_random_addr(void) -{ - /* the specific table for set addr is 8 bytes: - * one byte for config_offset - * one byte for length - * 6 bytes for payload */ - uint8_t data[4 + 8]; - - /* - * Static random Address - * The two upper bits shall be set to 1 - * The lowest 32bits is read from the UDN to differentiate between devices - * The RNG may be used to provide a random number on each power on - */ - uint32_t srd_bd_addr[2]; - - phase_random_addr = false; - - srd_bd_addr[1] = 0x0000ED6E; - srd_bd_addr[0] = LL_FLASH_GetUDN( ); - - data[0] = BT_BUF_CMD; - data[1] = uint8_t(ACI_WRITE_CONFIG_DATA_OPCODE & 0x000000FF); /* OCF */ - data[2] = uint8_t((ACI_WRITE_CONFIG_DATA_OPCODE & 0x0000FF00) >> 8); /* OGF */ - data[3] = 8; /* length of parameters */ - /* fill the ACI_HAL_WRITE_CONFIG_DATA with the addr*/ - data[4] = 0x2E; /* the offset */ - data[5] = 6; /* is the length of the random address */ - memcpy(data + 6, srd_bd_addr, 6); - /* send the ACI_HAL_WRITE_CONFIG_DATA */ - if (mbox_write(data[0], 11, &data[1]) != 11) { - /* Error: no data are written */ - return 0; - } - /* now wait for the corresponding Rx event */ - return 1; /* success */ -} int HCISharedMemTransportClass::bt_ipm_set_power(void) { @@ -894,78 +770,4 @@ int HCISharedMemTransportClass::bt_ipm_set_power(void) return 1; /* success */ } -int HCISharedMemTransportClass::bt_ipm_gatt_init(void) -{ - /* the specific table for gatt init */ - uint8_t data[4]; - - phase_gatt_init = false; - - data[0] = BT_BUF_CMD; /* the type */ - data[1] = 0x01; /* the OPCODE */ - data[2] = 0xFD; - data[3] = 0; /* the length */ - - /* send the GATT_INIT */ - if (mbox_write(data[0], 3, &data[1]) != 3) { - /* Error: no data are written */ - return 0; - } - /* now wait for the corresponding Rx event */ - return 1; /* success */ -} - -int HCISharedMemTransportClass::bt_ipm_gap_init(void) -{ - /* the specific table for gap init is 3 bytes: - * Role byte, enable_privacy byte, device_name_char_len byte */ - uint8_t data[4 + 3]; - - phase_gap_init = false; - - data[0] = BT_BUF_CMD; /* the type */ - data[1] = 0x8A; /* the OPCODE */ - data[2] = 0xFC; - data[3] = 3; /* the length */ - /* fill the GAP_INIT */ - data[4] = 0x0F; /* role */ - data[5] = 0x00; /* enable_privacy */ - data[6] = 0x00; /* device_name_char_len */ - - /* send the GAP_INIT */ - if (mbox_write(data[0], 6, &data[1]) != 6) { - /* Error: no data are written */ - return 0; - } - /* now wait for the corresponding Rx event */ - return 1; /* success */ -} - -int HCISharedMemTransportClass::bt_ipm_get_random_addr(void) -{ - /* the specific table for set addr is 8 bytes: - * one byte for config_offset - * one byte for length - * 6 bytes for payload */ - uint8_t data[4 + 1]; - - phase_get_random_addr = false; - - /* create ACI_READ_CONFIG_DATA_OPCODE */ - data[0] = BT_BUF_CMD; - data[1] = uint8_t(ACI_READ_CONFIG_DATA_OPCODE & 0x000000FF); /* OCF */ - data[2] = uint8_t((ACI_READ_CONFIG_DATA_OPCODE & 0x0000FF00) >> 8); /* OGF */ - data[3] = 1; /* length of parameters */ - /* fill the ACI_READ_CONFIG_DATA_OPCODE with the offset*/ - data[4] = 0x2E; /* the offset */ - - /* send the ACI_READ_CONFIG_DATA_OPCODE */ - if (mbox_write(data[0], 4, &data[1]) != 4) { - /* Error: no data are written */ - return 0; - } - /* now wait for the corresponding Rx event */ - return 1; /* success */ -} - #endif /* STM32WBxx */ diff --git a/src/utility/HCISharedMemTransport.h b/src/utility/HCISharedMemTransport.h index 464a24f6..58fb871d 100644 --- a/src/utility/HCISharedMemTransport.h +++ b/src/utility/HCISharedMemTransport.h @@ -84,13 +84,8 @@ class HCISharedMemTransportClass : public HCITransportInterface { void start_ble_rf(void); void stm32wb_reset(void); int stm32wb_start_ble(void); - int bt_ipm_ble_init(void); int bt_ipm_set_addr(void); - int bt_ipm_set_random_addr(void); int bt_ipm_set_power(void); - int bt_ipm_gatt_init(void); - int bt_ipm_gap_init(void); - int bt_ipm_get_random_addr(void); uint8_t _random_addr[6]; }; From 8f40c2f3f68f301456ecad73c39287ff1a390d56 Mon Sep 17 00:00:00 2001 From: Alexandre Bourdiol <alexandre.bourdiol@st.com> Date: Tue, 25 Oct 2022 18:28:48 +0200 Subject: [PATCH 100/226] fix: CI spell check Signed-off-by: Alexandre Bourdiol <alexandre.bourdiol@st.com> --- src/local/BLELocalDevice.cpp | 6 ++++-- src/utility/STM32Cube_FW/shci.h | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/local/BLELocalDevice.cpp b/src/local/BLELocalDevice.cpp index 36152065..b5869b5a 100644 --- a/src/local/BLELocalDevice.cpp +++ b/src/local/BLELocalDevice.cpp @@ -56,8 +56,10 @@ int BLELocalDevice::begin() end(); return 0; } - - randomNumber[5] |= 0xC0; // Force both MSB bit to b00 in order to define Random Address + /* Random address only requires 6 bytes (48 bits) + * Force both MSB bits to b00 in order to define Static Random Address + */ + randomNumber[5] |= 0xC0; if (HCI.leSetRandomAddress((uint8_t*)randomNumber) != 0) { end(); return 0; diff --git a/src/utility/STM32Cube_FW/shci.h b/src/utility/STM32Cube_FW/shci.h index 6b6ffd1a..040baced 100644 --- a/src/utility/STM32Cube_FW/shci.h +++ b/src/utility/STM32Cube_FW/shci.h @@ -529,7 +529,7 @@ extern "C" { * - bit 2: 1: device name Read-Only 0: device name R/W * - bit 3: 1: extended advertizing supported 0: extended advertizing not supported * - bit 4: 1: CS Algo #2 supported 0: CS Algo #2 not supported - * - bit 7: 1: LE Power Class 1 0: LE Power Classe 2-3 + * - bit 7: 1: LE Power Class 1 0: LE Power Classes 2-3 * - other bits: reserved ( shall be set to 0) */ uint8_t Options; @@ -1173,7 +1173,7 @@ typedef struct { /** * SHCI_GetWirelessFwInfo - * @brief This function read back the informations relative to the wireless binary loaded. + * @brief This function read back the information relative to the wireless binary loaded. * Refer yourself to MB_WirelessFwInfoTable_t structure to get the significance * of the different parameters returned. * @param pWirelessInfo : Pointer to WirelessFwInfo_t. From 75ea6f44f51913ab7f6df5044d66545d4ddf5579 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Thu, 24 Nov 2022 10:01:39 +0100 Subject: [PATCH 101/226] ci: replace deprecated spellcheck by codespell --- .github/workflows/codespell.yml | 27 +++++++++++++++++++++++++++ .github/workflows/spell-check.yml | 17 ----------------- 2 files changed, 27 insertions(+), 17 deletions(-) create mode 100644 .github/workflows/codespell.yml delete mode 100644 .github/workflows/spell-check.yml diff --git a/.github/workflows/codespell.yml b/.github/workflows/codespell.yml new file mode 100644 index 00000000..5ea11f42 --- /dev/null +++ b/.github/workflows/codespell.yml @@ -0,0 +1,27 @@ +name: codespell + +on: + push: + branches: + - main + pull_request: + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: +jobs: + codespell: + name: Check for spelling errors + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@main + + # See: https://github.com/codespell-project/actions-codespell/blob/master/README.md + - name: Spell check + uses: codespell-project/actions-codespell@master + with: + check_filenames: true + check_hidden: true + # In the event of a false positive, add the word in all lower case to this file: + # ignore_words_file: ./extras/codespell-ignore-words-list.txt + path: src diff --git a/.github/workflows/spell-check.yml b/.github/workflows/spell-check.yml deleted file mode 100644 index 6fded7ff..00000000 --- a/.github/workflows/spell-check.yml +++ /dev/null @@ -1,17 +0,0 @@ -name: Spell Check - -on: [push, pull_request] - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - name: Checkout - uses: actions/checkout@v2 - - - name: Spell check - uses: arduino/actions/libraries/spell-check@master - with: - skip-paths: ./extras/test,./extras/STM32Cube_FW - From 6ecff2be25fb83eeb6ee8acef35ee1af30d405f1 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Fri, 9 Dec 2022 17:28:57 +0100 Subject: [PATCH 102/226] fix: wrong release version Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- src/utility/STM32Cube_FW/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utility/STM32Cube_FW/README.md b/src/utility/STM32Cube_FW/README.md index 2cd8302a..c9af001e 100644 --- a/src/utility/STM32Cube_FW/README.md +++ b/src/utility/STM32Cube_FW/README.md @@ -1,6 +1,6 @@ ## Source -[STMicroelectronics/STM32CubeWB Release 1.14.0](https://github.com/STMicroelectronics/STM32CubeWB/releases/tag/1.14.0) -- Application: [BLE_TransparentMode](https://github.com/STMicroelectronics/STM32CubeWB/tree/1.14.0/Projects/P-NUCLEO-WB55.Nucleo/Applications/BLE/BLE_TransparentMode) +[STMicroelectronics/STM32CubeWB Release v1.14.0](https://github.com/STMicroelectronics/STM32CubeWB/releases/tag/v1.14.0) +- Application: [BLE_TransparentMode](https://github.com/STMicroelectronics/STM32CubeWB/tree/v1.14.0/Projects/P-NUCLEO-WB55.Nucleo/Applications/BLE/BLE_TransparentMode) From ec0d56802bcea692eea78f98db08a2602d74ed07 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Tue, 13 Dec 2022 11:15:53 +0100 Subject: [PATCH 103/226] feat: adding gitattributes and editor config files Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- .editorconfig | 17 +++++++++++++++++ .gitattributes | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 .editorconfig create mode 100644 .gitattributes diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..c9b76fd6 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,17 @@ +[*] +end_of_line = lf +insert_final_newline = true +indent_style = space +indent_size = 2 +trim_trailing_whitespace = true + +[*.sh] +# like -i=2 +indent_style = space +indent_size = 2 + +#shell_variant = posix # like -ln=posix +#binary_next_line = true # like -bn +switch_case_indent = true # like -ci +space_redirects = true # like -sr +#keep_padding = true # like -kp diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..422ae6f5 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,42 @@ +# Set the default behavior, in case people don't have core.autocrlf set. +* text=auto + +# Explicitly declare text files you want to always be normalized and converted +# to native line endings on checkout. +.editorconfig text eol=lf +.flake8 text eol=lf +.gitattributes text eol=lf +.gitignore text eol=lf + +*.adoc text eol=lf +*.c text eol=lf +*.cmake text eol=lf +*.cpp text eol=lf +*.css text eol=lf +*.dtsi text eol=lf +*.gv text eol=lf +*.h text eol=lf +*.html text eol=lf +*.in text eol=lf +*.ino text eol=lf +*.json text eol=lf +*.ld text eol=lf +*.md text eol=lf +*.MD text eol=lf +*.old text eol=lf +*.patch text eol=lf +*.pde text eol=lf +*.properties text eol=lf +*.py text eol=lf +*.s text eol=lf +*.S text eol=lf +*.sh text eol=lf +*.spec text eol=lf +*.txt text eol=lf +*.yml text eol=lf + +# Denote all files that are truly binary and should not be modified. +*.jpg binary +*.pdf binary +*.png binary + From 777b4a40f72e588000e609b79d24a78c7a7695ea Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Tue, 13 Dec 2022 15:20:56 +0100 Subject: [PATCH 104/226] fix: regenerate STM32Cube_FW patches Prepare update to version 1.15.0 Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- ...nd-adapt-STM32Cube_FW-sources-for-ST.patch | 1122 ++++++++++++++--- ...imeout-when-waiting-for-the-cmd_resp.patch | 32 +- ...rt-for-customize-app_conf_default.h.patch} | 94 +- 3 files changed, 979 insertions(+), 269 deletions(-) rename extras/STM32Cube_FW/{0003-Added-support-for-custom-app_conf.h.patch => 0003-chore-add-support-for-customize-app_conf_default.h.patch} (58%) diff --git a/extras/STM32Cube_FW/0001-chore-clean-up-and-adapt-STM32Cube_FW-sources-for-ST.patch b/extras/STM32Cube_FW/0001-chore-clean-up-and-adapt-STM32Cube_FW-sources-for-ST.patch index bbc8ba44..8b9ba87d 100644 --- a/extras/STM32Cube_FW/0001-chore-clean-up-and-adapt-STM32Cube_FW-sources-for-ST.patch +++ b/extras/STM32Cube_FW/0001-chore-clean-up-and-adapt-STM32Cube_FW-sources-for-ST.patch @@ -1,54 +1,66 @@ -From 1c3ca9f22842e3ae283d3e979a5f38a195d8d4ee Mon Sep 17 00:00:00 2001 -From: Alexandre Bourdiol <alexandre.bourdiol@st.com> -Date: Tue, 30 Aug 2022 11:28:41 +0200 +From f72f61b2a895a9f02a338c600af1de239939b357 Mon Sep 17 00:00:00 2001 +From: Frederic Pillon <frederic.pillon@st.com> +Date: Mon, 12 Dec 2022 17:15:26 +0100 Subject: [PATCH 1/3] chore: clean up and adapt STM32Cube_FW sources for STM32duino -Signed-off-by: Alexandre Bourdiol <alexandre.bourdiol@st.com> +Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- - src/utility/STM32Cube_FW/app_conf_default.h | 428 +------------------ - src/utility/STM32Cube_FW/ble_bufsize.h | 13 +- + src/utility/STM32Cube_FW/app_conf_default.h | 914 ++++++------------- + src/utility/STM32Cube_FW/ble_bufsize.h | 7 + src/utility/STM32Cube_FW/hw.h | 28 +- - src/utility/STM32Cube_FW/hw_ipcc.c | 184 +------- - src/utility/STM32Cube_FW/mbox_def.h | 34 -- - src/utility/STM32Cube_FW/shci.c | 40 +- - src/utility/STM32Cube_FW/shci.h | 47 +- - src/utility/STM32Cube_FW/shci_tl.c | 19 +- + src/utility/STM32Cube_FW/hw_ipcc.c | 218 +---- + src/utility/STM32Cube_FW/mbox_def.h | 34 - + src/utility/STM32Cube_FW/shci.c | 39 +- + src/utility/STM32Cube_FW/shci.h | 51 +- + src/utility/STM32Cube_FW/shci_tl.c | 37 +- src/utility/STM32Cube_FW/stm32_wpan_common.h | 39 +- - src/utility/STM32Cube_FW/stm_list.c | 11 +- + src/utility/STM32Cube_FW/stm_list.c | 15 +- src/utility/STM32Cube_FW/stm_list.h | 4 +- - src/utility/STM32Cube_FW/tl.h | 33 -- - src/utility/STM32Cube_FW/tl_mbox.c | 144 +------ - 13 files changed, 91 insertions(+), 933 deletions(-) + src/utility/STM32Cube_FW/tl.h | 33 - + src/utility/STM32Cube_FW/tl_mbox.c | 143 +-- + 13 files changed, 323 insertions(+), 1239 deletions(-) + rewrite src/utility/STM32Cube_FW/app_conf_default.h (63%) diff --git a/src/utility/STM32Cube_FW/app_conf_default.h b/src/utility/STM32Cube_FW/app_conf_default.h -index c63c66e..54f824a 100644 +dissimilarity index 63% +index 2606a05..cc8c3e8 100644 --- a/src/utility/STM32Cube_FW/app_conf_default.h +++ b/src/utility/STM32Cube_FW/app_conf_default.h -@@ -1,4 +1,3 @@ +@@ -1,655 +1,259 @@ -/* USER CODE BEGIN Header */ - /** - ****************************************************************************** - * @file app_conf.h -@@ -16,94 +15,36 @@ - * - ****************************************************************************** - */ +-/** +- ****************************************************************************** +- * @file app_conf.h +- * @author MCD Application Team +- * @brief Application configuration file for STM32WPAN Middleware. +- ****************************************************************************** +- * @attention +- * +- * Copyright (c) 2020-2021 STMicroelectronics. +- * All rights reserved. +- * +- * This software is licensed under terms that can be found in the LICENSE file +- * in the root directory of this software component. +- * If no LICENSE file comes with this software, it is provided AS-IS. +- * +- ****************************************************************************** +- */ -/* USER CODE END Header */ - - /* Define to prevent recursive inclusion -------------------------------------*/ - #ifndef APP_CONF_H - #define APP_CONF_H - - #include "hw.h" +- +-/* Define to prevent recursive inclusion -------------------------------------*/ +-#ifndef APP_CONF_H +-#define APP_CONF_H +- +-#include "hw.h" -#include "hw_conf.h" -#include "hw_if.h" - #include "ble_bufsize.h" - - /****************************************************************************** - * Application Config - ******************************************************************************/ - +-#include "ble_bufsize.h" +- +-/****************************************************************************** +- * Application Config +- ******************************************************************************/ +- -/** - * Define Secure Connections Support - */ @@ -63,16 +75,9 @@ index c63c66e..54f824a 100644 - */ -#define CFG_KEYPRESS_NOT_SUPPORTED (0x00) -#define CFG_KEYPRESS_SUPPORTED (0x01) -+/**< generic parameters ******************************************************/ -+/* HCI related defines */ - +- -#define CFG_KEYPRESS_NOTIFICATION_SUPPORT CFG_KEYPRESS_NOT_SUPPORTED -+#define ACI_HAL_SET_TX_POWER_LEVEL 0xFC0F -+#define ACI_WRITE_CONFIG_DATA_OPCODE 0xFC0C -+#define ACI_READ_CONFIG_DATA_OPCODE 0xFC0D -+#define MAX_HCI_ACL_PACKET_SIZE (sizeof(TL_PacketHeader_t) + 5 + 251) -+#define HCI_RESET 0x0C03 - +- -/** - * Numeric Comparison Answers - */ @@ -94,17 +99,12 @@ index c63c66e..54f824a 100644 -* Encryption root key used to derive LTK and CSRK -*/ -#define CFG_BLE_ERK {0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21, 0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21} -+#ifndef BLE_SHARED_MEM_BYTE_ORDER -+ #define BLE_SHARED_MEM_BYTE_ORDER MSBFIRST -+#endif -+#define BLE_MODULE_SHARED_MEM_BUFFER_SIZE 128 - - /** +- +-/** - * SMPS supply - * SMPS not used when Set to 0 - * SMPS used when Set to 1 -+ * Define Tx Power - */ +- */ -#define CFG_USE_SMPS 0 - -/* USER CODE BEGIN Generic_Parameters */ @@ -134,41 +134,218 @@ index c63c66e..54f824a 100644 -#define CFG_FW_SUBVERSION (1) -#define CFG_FW_BRANCH (0) -#define CFG_FW_BUILD (0) -+#define CFG_TX_POWER (0x18) /* -0.15dBm */ - - /****************************************************************************** - * BLE Stack -@@ -152,13 +93,15 @@ - * Prepare Write List size in terms of number of packet - * This parameter is ignored by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set - */ +- +-/****************************************************************************** +- * BLE Stack +- ******************************************************************************/ +-/** +- * Maximum number of simultaneous connections that the device will support. +- * Valid values are from 1 to 8 +- */ +-#define CFG_BLE_NUM_LINK 8 +- +-/** +- * Maximum number of Services that can be stored in the GATT database. +- * Note that the GAP and GATT services are automatically added so this parameter should be 2 plus the number of user services +- */ +-#define CFG_BLE_NUM_GATT_SERVICES 8 +- +-/** +- * Maximum number of Attributes +- * (i.e. the number of characteristic + the number of characteristic values + the number of descriptors, excluding the services) +- * that can be stored in the GATT database. +- * Note that certain characteristics and relative descriptors are added automatically during device initialization +- * so this parameters should be 9 plus the number of user Attributes +- */ +-#define CFG_BLE_NUM_GATT_ATTRIBUTES 68 +- +-/** +- * Maximum supported ATT_MTU size +- * This parameter is ignored by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set +- */ +-#define CFG_BLE_MAX_ATT_MTU (156) +- +-/** +- * Size of the storage area for Attribute values +- * This value depends on the number of attributes used by application. In particular the sum of the following quantities (in octets) should be made for each attribute: +- * - attribute value length +- * - 5, if UUID is 16 bit; 19, if UUID is 128 bit +- * - 2, if server configuration descriptor is used +- * - 2*DTM_NUM_LINK, if client configuration descriptor is used +- * - 2, if extended properties is used +- * The total amount of memory needed is the sum of the above quantities for each attribute. +- * This parameter is ignored by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set +- */ +-#define CFG_BLE_ATT_VALUE_ARRAY_SIZE (1344) +- +-/** +- * Prepare Write List size in terms of number of packet +- * This parameter is ignored by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set +- */ -#define CFG_BLE_PREPARE_WRITE_LIST_SIZE BLE_PREP_WRITE_X_ATT(CFG_BLE_MAX_ATT_MTU) -+// #define CFG_BLE_PREPARE_WRITE_LIST_SIZE BLE_PREP_WRITE_X_ATT(CFG_BLE_MAX_ATT_MTU) -+#define CFG_BLE_PREPARE_WRITE_LIST_SIZE (0x3A) - - /** - * Number of allocated memory blocks - * This parameter is overwritten by the CPU2 with an hardcoded optimal value when the parameter CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set - */ +- +-/** +- * Number of allocated memory blocks +- * This parameter is overwritten by the CPU2 with an hardcoded optimal value when the parameter CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set +- */ -#define CFG_BLE_MBLOCK_COUNT (BLE_MBLOCKS_CALC(CFG_BLE_PREPARE_WRITE_LIST_SIZE, CFG_BLE_MAX_ATT_MTU, CFG_BLE_NUM_LINK)) -+// #define CFG_BLE_MBLOCK_COUNT (BLE_MBLOCKS_CALC(CFG_BLE_PREPARE_WRITE_LIST_SIZE, CFG_BLE_MAX_ATT_MTU, CFG_BLE_NUM_LINK)) -+#define CFG_BLE_MBLOCK_COUNT (0x79) - - /** - * Enable or disable the Extended Packet length feature. Valid values are 0 or 1. -@@ -241,7 +184,7 @@ - * 0: LE Power Class 2-3 - * other bits: reserved (shall be set to 0) - */ --#define CFG_BLE_OPTIONS (SHCI_C2_BLE_INIT_OPTIONS_LL_HOST | SHCI_C2_BLE_INIT_OPTIONS_WITH_SVC_CHANGE_DESC | SHCI_C2_BLE_INIT_OPTIONS_DEVICE_NAME_RW | SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV | SHCI_C2_BLE_INIT_OPTIONS_CS_ALGO2 | SHCI_C2_BLE_INIT_OPTIONS_POWER_CLASS_2_3) -+#define CFG_BLE_OPTIONS (SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY) - - #define CFG_BLE_MAX_COC_INITIATOR_NBR (32) - -@@ -291,340 +234,5 @@ - - #define CFG_BLE_RX_PATH_COMPENS (0) - +- +-/** +- * Enable or disable the Extended Packet length feature. Valid values are 0 or 1. +- */ +-#define CFG_BLE_DATA_LENGTH_EXTENSION 1 +- +-/** +- * Sleep clock accuracy in Slave mode (ppm value) +- */ +-#define CFG_BLE_SLAVE_SCA 500 +- +-/** +- * Sleep clock accuracy in Master mode +- * 0 : 251 ppm to 500 ppm +- * 1 : 151 ppm to 250 ppm +- * 2 : 101 ppm to 150 ppm +- * 3 : 76 ppm to 100 ppm +- * 4 : 51 ppm to 75 ppm +- * 5 : 31 ppm to 50 ppm +- * 6 : 21 ppm to 30 ppm +- * 7 : 0 ppm to 20 ppm +- */ +-#define CFG_BLE_MASTER_SCA 0 +- +-/** +- * LsSource +- * Some information for Low speed clock mapped in bits field +- * - bit 0: 1: Calibration for the RF system wakeup clock source 0: No calibration for the RF system wakeup clock source +- * - bit 1: 1: STM32WB5M Module device 0: Other devices as STM32WBxx SOC, STM32WB1M module +- * - bit 2: 1: HSE/1024 Clock config 0: LSE Clock config +- */ +-#if defined(STM32WB5Mxx) +- #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_MOD5MM_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) +-#else +- #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_OTHER_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) +-#endif +- +-/** +- * Start up time of the high speed (16 or 32 MHz) crystal oscillator in units of 625/256 us (~2.44 us) +- */ +-#define CFG_BLE_HSE_STARTUP_TIME 0x148 +- +-/** +- * Maximum duration of the connection event when the device is in Slave mode in units of 625/256 us (~2.44 us) +- */ +-#define CFG_BLE_MAX_CONN_EVENT_LENGTH (0xFFFFFFFF) +- +-/** +- * Viterbi Mode +- * 1 : enabled +- * 0 : disabled +- */ +-#define CFG_BLE_VITERBI_MODE 1 +- +-/** +- * BLE stack Options flags to be configured with: +- * - SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY +- * - SHCI_C2_BLE_INIT_OPTIONS_LL_HOST +- * - SHCI_C2_BLE_INIT_OPTIONS_NO_SVC_CHANGE_DESC +- * - SHCI_C2_BLE_INIT_OPTIONS_WITH_SVC_CHANGE_DESC +- * - SHCI_C2_BLE_INIT_OPTIONS_DEVICE_NAME_RO +- * - SHCI_C2_BLE_INIT_OPTIONS_DEVICE_NAME_RW +- * - SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV +- * - SHCI_C2_BLE_INIT_OPTIONS_NO_EXT_ADV +- * - SHCI_C2_BLE_INIT_OPTIONS_CS_ALGO2 +- * - SHCI_C2_BLE_INIT_OPTIONS_NO_CS_ALGO2 +- * - SHCI_C2_BLE_INIT_OPTIONS_REDUC_GATTDB_NVM +- * - SHCI_C2_BLE_INIT_OPTIONS_FULL_GATTDB_NVM +- * - SHCI_C2_BLE_INIT_OPTIONS_GATT_CACHING_USED +- * - SHCI_C2_BLE_INIT_OPTIONS_GATT_CACHING_NOTUSED +- * - SHCI_C2_BLE_INIT_OPTIONS_POWER_CLASS_1 +- * - SHCI_C2_BLE_INIT_OPTIONS_POWER_CLASS_2_3 +- * - SHCI_C2_BLE_INIT_OPTIONS_APPEARANCE_WRITABLE +- * - SHCI_C2_BLE_INIT_OPTIONS_APPEARANCE_READONLY +- * - SHCI_C2_BLE_INIT_OPTIONS_ENHANCED_ATT_SUPPORTED +- * - SHCI_C2_BLE_INIT_OPTIONS_ENHANCED_ATT_NOTSUPPORTED +- * which are used to set following configuration bits: +- * (bit 0): 1: LL only +- * 0: LL + host +- * (bit 1): 1: no service change desc. +- * 0: with service change desc. +- * (bit 2): 1: device name Read-Only +- * 0: device name R/W +- * (bit 3): 1: extended advertizing supported +- * 0: extended advertizing not supported +- * (bit 4): 1: CS Algo #2 supported +- * 0: CS Algo #2 not supported +- * (bit 5): 1: Reduced GATT database in NVM +- * 0: Full GATT database in NVM +- * (bit 6): 1: GATT caching is used +- * 0: GATT caching is not used +- * (bit 7): 1: LE Power Class 1 +- * 0: LE Power Class 2-3 +- * (bit 8): 1: appearance Writable +- * 0: appearance Read-Only +- * (bit 9): 1: Enhanced ATT supported +- * 0: Enhanced ATT not supported +- * other bits: reserved (shall be set to 0) +- */ +-#define CFG_BLE_OPTIONS (SHCI_C2_BLE_INIT_OPTIONS_LL_HOST | SHCI_C2_BLE_INIT_OPTIONS_WITH_SVC_CHANGE_DESC | SHCI_C2_BLE_INIT_OPTIONS_DEVICE_NAME_RW | SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV | SHCI_C2_BLE_INIT_OPTIONS_CS_ALGO2 | SHCI_C2_BLE_INIT_OPTIONS_FULL_GATTDB_NVM | SHCI_C2_BLE_INIT_OPTIONS_GATT_CACHING_NOTUSED | SHCI_C2_BLE_INIT_OPTIONS_POWER_CLASS_2_3 | SHCI_C2_BLE_INIT_OPTIONS_APPEARANCE_READONLY | SHCI_C2_BLE_INIT_OPTIONS_ENHANCED_ATT_NOTSUPPORTED) +- +-#define CFG_BLE_MAX_COC_INITIATOR_NBR (32) +- +-#define CFG_BLE_MIN_TX_POWER (-40) +- +-#define CFG_BLE_MAX_TX_POWER (6) +- +-/** +- * BLE Rx model configuration flags to be configured with: +- * - SHCI_C2_BLE_INIT_RX_MODEL_AGC_RSSI_LEGACY +- * - SHCI_C2_BLE_INIT_RX_MODEL_AGC_RSSI_BLOCKER +- * which are used to set following configuration bits: +- * (bit 0): 1: agc_rssi model improved vs RF blockers +- * 0: Legacy agc_rssi model +- * other bits: reserved (shall be set to 0) +- */ +- +-#define CFG_BLE_RX_MODEL_CONFIG (SHCI_C2_BLE_INIT_RX_MODEL_AGC_RSSI_LEGACY) +- +-/* Maximum number of advertising sets. +- * Range: 1 .. 8 with limitation: +- * This parameter is linked to CFG_BLE_MAX_ADV_DATA_LEN such as both compliant with allocated Total memory computed with BLE_EXT_ADV_BUFFER_SIZE based +- * on Max Extended advertising configuration supported. +- * This parameter is considered by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV flag set +- */ +- +-#define CFG_BLE_MAX_ADV_SET_NBR (8) +- +- /* Maximum advertising data length (in bytes) +- * Range: 31 .. 1650 with limitation: +- * This parameter is linked to CFG_BLE_MAX_ADV_SET_NBR such as both compliant with allocated Total memory computed with BLE_EXT_ADV_BUFFER_SIZE based +- * on Max Extended advertising configuration supported. +- * This parameter is considered by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV flag set +- */ +- +-#define CFG_BLE_MAX_ADV_DATA_LEN (207) +- +- /* RF TX Path Compensation Value (16-bit signed integer). Units: 0.1 dB. +- * Range: -1280 .. 1280 +- */ +- +-#define CFG_BLE_TX_PATH_COMPENS (0) +- +- /* RF RX Path Compensation Value (16-bit signed integer). Units: 0.1 dB. +- * Range: -1280 .. 1280 +- */ +- +-#define CFG_BLE_RX_PATH_COMPENS (0) +- +- /* BLE core version (16-bit signed integer). +- * - SHCI_C2_BLE_INIT_BLE_CORE_5_2 +- * - SHCI_C2_BLE_INIT_BLE_CORE_5_3 +- * which are used to set: 11(5.2), 12(5.3). +- */ +- +-#define CFG_BLE_CORE_VERSION (SHCI_C2_BLE_INIT_BLE_CORE_5_3) +- -/****************************************************************************** - * Transport Layer - ******************************************************************************/ @@ -504,13 +681,272 @@ index c63c66e..54f824a 100644 - -#define CFG_OTP_END_ADRESS OTP_AREA_END_ADDR - - #endif /*APP_CONF_H */ - +-#endif /*APP_CONF_H */ +- ++/** ++ ****************************************************************************** ++ * @file app_conf_default.h ++ * @author MCD Application Team ++ * @brief Default application configuration file for STM32WPAN Middleware. ++ ****************************************************************************** ++ * @attention ++ * ++ * Copyright (c) 2020-2021 STMicroelectronics. ++ * All rights reserved. ++ * ++ * This software is licensed under terms that can be found in the LICENSE file ++ * in the root directory of this software component. ++ * If no LICENSE file comes with this software, it is provided AS-IS. ++ * ++ ****************************************************************************** ++ */ ++ ++/* Define to prevent recursive inclusion -------------------------------------*/ ++#ifndef APP_CONF_DEFAULT_H ++#define APP_CONF_DEFAULT_H ++ ++/****************************************************************************** ++ * Application Config ++ ******************************************************************************/ ++ ++/**< generic parameters ******************************************************/ ++/* HCI related defines */ ++ ++#define ACI_HAL_SET_TX_POWER_LEVEL 0xFC0F ++#define ACI_WRITE_CONFIG_DATA_OPCODE 0xFC0C ++#define ACI_READ_CONFIG_DATA_OPCODE 0xFC0D ++#define MAX_HCI_ACL_PACKET_SIZE (sizeof(TL_PacketHeader_t) + 5 + 251) ++#define HCI_RESET 0x0C03 ++ ++#ifndef BLE_SHARED_MEM_BYTE_ORDER ++ #define BLE_SHARED_MEM_BYTE_ORDER MSBFIRST ++#endif ++#define BLE_MODULE_SHARED_MEM_BUFFER_SIZE 128 ++ ++/** ++ * Define Tx Power ++ */ ++#define CFG_TX_POWER (0x18) /* -0.15dBm */ ++ ++/****************************************************************************** ++ * BLE Stack ++ ******************************************************************************/ ++/** ++ * Maximum number of simultaneous connections that the device will support. ++ * Valid values are from 1 to 8 ++ */ ++#define CFG_BLE_NUM_LINK 8 ++ ++/** ++ * Maximum number of Services that can be stored in the GATT database. ++ * Note that the GAP and GATT services are automatically added so this parameter should be 2 plus the number of user services ++ */ ++#define CFG_BLE_NUM_GATT_SERVICES 8 ++ ++/** ++ * Maximum number of Attributes ++ * (i.e. the number of characteristic + the number of characteristic values + the number of descriptors, excluding the services) ++ * that can be stored in the GATT database. ++ * Note that certain characteristics and relative descriptors are added automatically during device initialization ++ * so this parameters should be 9 plus the number of user Attributes ++ */ ++#define CFG_BLE_NUM_GATT_ATTRIBUTES 68 ++ ++/** ++ * Maximum supported ATT_MTU size ++ * This parameter is ignored by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set ++ */ ++#define CFG_BLE_MAX_ATT_MTU (156) ++ ++/** ++ * Size of the storage area for Attribute values ++ * This value depends on the number of attributes used by application. In particular the sum of the following quantities (in octets) should be made for each attribute: ++ * - attribute value length ++ * - 5, if UUID is 16 bit; 19, if UUID is 128 bit ++ * - 2, if server configuration descriptor is used ++ * - 2*DTM_NUM_LINK, if client configuration descriptor is used ++ * - 2, if extended properties is used ++ * The total amount of memory needed is the sum of the above quantities for each attribute. ++ * This parameter is ignored by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set ++ */ ++#define CFG_BLE_ATT_VALUE_ARRAY_SIZE (1344) ++ ++/** ++ * Prepare Write List size in terms of number of packet ++ * This parameter is ignored by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set ++ */ ++// #define CFG_BLE_PREPARE_WRITE_LIST_SIZE BLE_PREP_WRITE_X_ATT(CFG_BLE_MAX_ATT_MTU) ++#define CFG_BLE_PREPARE_WRITE_LIST_SIZE (0x3A) ++ ++/** ++ * Number of allocated memory blocks ++ * This parameter is overwritten by the CPU2 with an hardcoded optimal value when the parameter CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set ++ */ ++// #define CFG_BLE_MBLOCK_COUNT (BLE_MBLOCKS_CALC(CFG_BLE_PREPARE_WRITE_LIST_SIZE, CFG_BLE_MAX_ATT_MTU, CFG_BLE_NUM_LINK)) ++#define CFG_BLE_MBLOCK_COUNT (0x79) ++ ++/** ++ * Enable or disable the Extended Packet length feature. Valid values are 0 or 1. ++ */ ++#define CFG_BLE_DATA_LENGTH_EXTENSION 1 ++ ++/** ++ * Sleep clock accuracy in Slave mode (ppm value) ++ */ ++#define CFG_BLE_SLAVE_SCA 500 ++ ++/** ++ * Sleep clock accuracy in Master mode ++ * 0 : 251 ppm to 500 ppm ++ * 1 : 151 ppm to 250 ppm ++ * 2 : 101 ppm to 150 ppm ++ * 3 : 76 ppm to 100 ppm ++ * 4 : 51 ppm to 75 ppm ++ * 5 : 31 ppm to 50 ppm ++ * 6 : 21 ppm to 30 ppm ++ * 7 : 0 ppm to 20 ppm ++ */ ++#define CFG_BLE_MASTER_SCA 0 ++ ++/** ++ * LsSource ++ * Some information for Low speed clock mapped in bits field ++ * - bit 0: 1: Calibration for the RF system wakeup clock source 0: No calibration for the RF system wakeup clock source ++ * - bit 1: 1: STM32WB5M Module device 0: Other devices as STM32WBxx SOC, STM32WB1M module ++ * - bit 2: 1: HSE/1024 Clock config 0: LSE Clock config ++ */ ++#if defined(STM32WB5Mxx) ++ #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_MOD5MM_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) ++#else ++ #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_OTHER_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) ++#endif ++ ++/** ++ * Start up time of the high speed (16 or 32 MHz) crystal oscillator in units of 625/256 us (~2.44 us) ++ */ ++#define CFG_BLE_HSE_STARTUP_TIME 0x148 ++ ++/** ++ * Maximum duration of the connection event when the device is in Slave mode in units of 625/256 us (~2.44 us) ++ */ ++#define CFG_BLE_MAX_CONN_EVENT_LENGTH (0xFFFFFFFF) ++ ++/** ++ * Viterbi Mode ++ * 1 : enabled ++ * 0 : disabled ++ */ ++#define CFG_BLE_VITERBI_MODE 1 ++ ++/** ++ * BLE stack Options flags to be configured with: ++ * - SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY ++ * - SHCI_C2_BLE_INIT_OPTIONS_LL_HOST ++ * - SHCI_C2_BLE_INIT_OPTIONS_NO_SVC_CHANGE_DESC ++ * - SHCI_C2_BLE_INIT_OPTIONS_WITH_SVC_CHANGE_DESC ++ * - SHCI_C2_BLE_INIT_OPTIONS_DEVICE_NAME_RO ++ * - SHCI_C2_BLE_INIT_OPTIONS_DEVICE_NAME_RW ++ * - SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV ++ * - SHCI_C2_BLE_INIT_OPTIONS_NO_EXT_ADV ++ * - SHCI_C2_BLE_INIT_OPTIONS_CS_ALGO2 ++ * - SHCI_C2_BLE_INIT_OPTIONS_NO_CS_ALGO2 ++ * - SHCI_C2_BLE_INIT_OPTIONS_REDUC_GATTDB_NVM ++ * - SHCI_C2_BLE_INIT_OPTIONS_FULL_GATTDB_NVM ++ * - SHCI_C2_BLE_INIT_OPTIONS_GATT_CACHING_USED ++ * - SHCI_C2_BLE_INIT_OPTIONS_GATT_CACHING_NOTUSED ++ * - SHCI_C2_BLE_INIT_OPTIONS_POWER_CLASS_1 ++ * - SHCI_C2_BLE_INIT_OPTIONS_POWER_CLASS_2_3 ++ * - SHCI_C2_BLE_INIT_OPTIONS_APPEARANCE_WRITABLE ++ * - SHCI_C2_BLE_INIT_OPTIONS_APPEARANCE_READONLY ++ * - SHCI_C2_BLE_INIT_OPTIONS_ENHANCED_ATT_SUPPORTED ++ * - SHCI_C2_BLE_INIT_OPTIONS_ENHANCED_ATT_NOTSUPPORTED ++ * which are used to set following configuration bits: ++ * (bit 0): 1: LL only ++ * 0: LL + host ++ * (bit 1): 1: no service change desc. ++ * 0: with service change desc. ++ * (bit 2): 1: device name Read-Only ++ * 0: device name R/W ++ * (bit 3): 1: extended advertizing supported ++ * 0: extended advertizing not supported ++ * (bit 4): 1: CS Algo #2 supported ++ * 0: CS Algo #2 not supported ++ * (bit 5): 1: Reduced GATT database in NVM ++ * 0: Full GATT database in NVM ++ * (bit 6): 1: GATT caching is used ++ * 0: GATT caching is not used ++ * (bit 7): 1: LE Power Class 1 ++ * 0: LE Power Class 2-3 ++ * (bit 8): 1: appearance Writable ++ * 0: appearance Read-Only ++ * (bit 9): 1: Enhanced ATT supported ++ * 0: Enhanced ATT not supported ++ * other bits: reserved (shall be set to 0) ++ */ ++#define CFG_BLE_OPTIONS (SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY) ++ ++#define CFG_BLE_MAX_COC_INITIATOR_NBR (32) ++ ++#define CFG_BLE_MIN_TX_POWER (-40) ++ ++#define CFG_BLE_MAX_TX_POWER (6) ++ ++/** ++ * BLE Rx model configuration flags to be configured with: ++ * - SHCI_C2_BLE_INIT_RX_MODEL_AGC_RSSI_LEGACY ++ * - SHCI_C2_BLE_INIT_RX_MODEL_AGC_RSSI_BLOCKER ++ * which are used to set following configuration bits: ++ * (bit 0): 1: agc_rssi model improved vs RF blockers ++ * 0: Legacy agc_rssi model ++ * other bits: reserved (shall be set to 0) ++ */ ++ ++#define CFG_BLE_RX_MODEL_CONFIG (SHCI_C2_BLE_INIT_RX_MODEL_AGC_RSSI_LEGACY) ++ ++/* Maximum number of advertising sets. ++ * Range: 1 .. 8 with limitation: ++ * This parameter is linked to CFG_BLE_MAX_ADV_DATA_LEN such as both compliant with allocated Total memory computed with BLE_EXT_ADV_BUFFER_SIZE based ++ * on Max Extended advertising configuration supported. ++ * This parameter is considered by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV flag set ++ */ ++ ++#define CFG_BLE_MAX_ADV_SET_NBR (8) ++ ++ /* Maximum advertising data length (in bytes) ++ * Range: 31 .. 1650 with limitation: ++ * This parameter is linked to CFG_BLE_MAX_ADV_SET_NBR such as both compliant with allocated Total memory computed with BLE_EXT_ADV_BUFFER_SIZE based ++ * on Max Extended advertising configuration supported. ++ * This parameter is considered by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV flag set ++ */ ++ ++#define CFG_BLE_MAX_ADV_DATA_LEN (207) ++ ++ /* RF TX Path Compensation Value (16-bit signed integer). Units: 0.1 dB. ++ * Range: -1280 .. 1280 ++ */ ++ ++#define CFG_BLE_TX_PATH_COMPENS (0) ++ ++ /* RF RX Path Compensation Value (16-bit signed integer). Units: 0.1 dB. ++ * Range: -1280 .. 1280 ++ */ ++ ++#define CFG_BLE_RX_PATH_COMPENS (0) ++ ++ /* BLE core version (16-bit signed integer). ++ * - SHCI_C2_BLE_INIT_BLE_CORE_5_2 ++ * - SHCI_C2_BLE_INIT_BLE_CORE_5_3 ++ * which are used to set: 11(5.2), 12(5.3). ++ */ ++ ++#define CFG_BLE_CORE_VERSION (SHCI_C2_BLE_INIT_BLE_CORE_5_3) ++ ++#endif /* APP_CONF_DEFAULT_H */ diff --git a/src/utility/STM32Cube_FW/ble_bufsize.h b/src/utility/STM32Cube_FW/ble_bufsize.h -index 0f0f419..247573b 100644 +index 4269fa4..cea5da8 100644 --- a/src/utility/STM32Cube_FW/ble_bufsize.h +++ b/src/utility/STM32Cube_FW/ble_bufsize.h -@@ -75,17 +75,24 @@ +@@ -75,6 +75,13 @@ ((pw) + MAX(BLE_MEM_BLOCK_X_MTU(mtu, n_link), \ BLE_MBLOCKS_SECURE_CONNECTIONS)) @@ -523,21 +959,7 @@ index 0f0f419..247573b 100644 + /* * BLE_FIXED_BUFFER_SIZE_BYTES: -- * A part of the RAM, is dinamically allocated by initilizing all the pointers -+ * A part of the RAM, is dynamically allocated by initializing all the pointers - * defined in a global context variable "mem_alloc_ctx_p". - * This initialization is made in the Dynamic_allocator functions, which -- * assing a portion of RAM given by the external application to the above -+ * assign a portion of RAM given by the external application to the above - * mentioned "global pointers". - * - * The size of this Dynamic RAM is made of 2 main components: - * - a part that is parameters-dependent (num of links, GATT buffers, ...), -- * and which value is explicited by the following macro; -+ * and which value is defined by the following macro; - * - a part, that may be considered "fixed", i.e. independent from the above - * mentioned parameters. - */ + * A part of the RAM, is dynamically allocated by initializing all the pointers diff --git a/src/utility/STM32Cube_FW/hw.h b/src/utility/STM32Cube_FW/hw.h index 503fa2c..fcf0451 100644 --- a/src/utility/STM32Cube_FW/hw.h @@ -591,12 +1013,19 @@ index 503fa2c..fcf0451 100644 } #endif diff --git a/src/utility/STM32Cube_FW/hw_ipcc.c b/src/utility/STM32Cube_FW/hw_ipcc.c -index fd620b8..7b9be81 100644 +index fd620b8..0c1868f 100644 --- a/src/utility/STM32Cube_FW/hw_ipcc.c +++ b/src/utility/STM32Cube_FW/hw_ipcc.c -@@ -18,8 +18,9 @@ +@@ -1,4 +1,3 @@ +-/* USER CODE BEGIN Header */ + /** + ****************************************************************************** + * @file hw_ipcc.c +@@ -16,10 +15,10 @@ + * + ****************************************************************************** */ - /* USER CODE END Header */ +-/* USER CODE END Header */ +#if defined(STM32WBxx) /* Includes ------------------------------------------------------------------*/ @@ -605,7 +1034,7 @@ index fd620b8..7b9be81 100644 #include "mbox_def.h" /* Global variables ---------------------------------------------------------*/ -@@ -56,34 +57,17 @@ static void HW_IPCC_LLD_BLE_ReceiveRspHandler( void ); +@@ -56,34 +55,17 @@ static void HW_IPCC_LLD_BLE_ReceiveRspHandler( void ); static void HW_IPCC_LLD_BLE_ReceiveM0CmdHandler( void ); #endif @@ -626,7 +1055,7 @@ index fd620b8..7b9be81 100644 * INTERRUPT HANDLER ******************************************************************************/ -void HW_IPCC_Rx_Handler( void ) -+void IPCC_C1_RX_IRQHandler(void) ++void IPCC_C1_RX_IRQHandler( void ) { if (HW_IPCC_RX_PENDING( HW_IPCC_SYSTEM_EVENT_CHANNEL )) { @@ -641,7 +1070,7 @@ index fd620b8..7b9be81 100644 #ifdef THREAD_WB else if (HW_IPCC_RX_PENDING( HW_IPCC_THREAD_NOTIFICATION_ACK_CHANNEL )) { -@@ -114,16 +98,6 @@ void HW_IPCC_Rx_Handler( void ) +@@ -114,16 +96,6 @@ void HW_IPCC_Rx_Handler( void ) HW_IPCC_LLD_BLE_ReceiveM0CmdHandler(); } #endif /* LLD_TESTS_WB */ @@ -658,7 +1087,7 @@ index fd620b8..7b9be81 100644 else if (HW_IPCC_RX_PENDING( HW_IPCC_BLE_EVENT_CHANNEL )) { HW_IPCC_BLE_EvtHandler(); -@@ -132,22 +106,14 @@ void HW_IPCC_Rx_Handler( void ) +@@ -132,22 +104,14 @@ void HW_IPCC_Rx_Handler( void ) { HW_IPCC_TRACES_EvtHandler(); } @@ -667,7 +1096,7 @@ index fd620b8..7b9be81 100644 } -void HW_IPCC_Tx_Handler( void ) -+void IPCC_C1_TX_IRQHandler(void) ++void IPCC_C1_TX_IRQHandler( void ) { if (HW_IPCC_TX_PENDING( HW_IPCC_SYSTEM_CMD_RSP_CHANNEL )) { @@ -682,7 +1111,7 @@ index fd620b8..7b9be81 100644 #ifdef THREAD_WB else if (HW_IPCC_TX_PENDING( HW_IPCC_THREAD_OT_CMD_RSP_CHANNEL )) { -@@ -157,12 +123,6 @@ void HW_IPCC_Tx_Handler( void ) +@@ -157,12 +121,6 @@ void HW_IPCC_Tx_Handler( void ) #ifdef LLD_TESTS_WB // No TX handler for LLD tests #endif /* LLD_TESTS_WB */ @@ -695,35 +1124,112 @@ index fd620b8..7b9be81 100644 else if (HW_IPCC_TX_PENDING( HW_IPCC_MM_RELEASE_BUFFER_CHANNEL )) { HW_IPCC_MM_FreeBufHandler(); -@@ -171,9 +131,8 @@ void HW_IPCC_Tx_Handler( void ) +@@ -171,8 +129,6 @@ void HW_IPCC_Tx_Handler( void ) { HW_IPCC_BLE_AclDataEvtHandler(); } - - return; } -+ /****************************************************************************** * GENERAL - ******************************************************************************/ -@@ -264,8 +223,8 @@ static void HW_IPCC_BLE_AclDataEvtHandler( void ) - return; +@@ -204,8 +160,6 @@ void HW_IPCC_Enable( void ) + __SEV( ); /* Set the internal event flag and send an event to the CPU2 */ + __WFE( ); /* Clear the internal event flag */ + LL_PWR_EnableBootC2( ); +- +- return; } --__weak void HW_IPCC_BLE_AclDataAckNot( void ){}; --__weak void HW_IPCC_BLE_RxEvtNot( void ){}; -+__WEAK void HW_IPCC_BLE_AclDataAckNot( void ){}; -+__WEAK void HW_IPCC_BLE_RxEvtNot( void ){}; + void HW_IPCC_Init( void ) +@@ -217,8 +171,6 @@ void HW_IPCC_Init( void ) + + HAL_NVIC_EnableIRQ(IPCC_C1_RX_IRQn); + HAL_NVIC_EnableIRQ(IPCC_C1_TX_IRQn); +- +- return; + } /****************************************************************************** - * SYSTEM -@@ -303,56 +262,8 @@ static void HW_IPCC_SYS_EvtHandler( void ) - return; +@@ -227,15 +179,11 @@ void HW_IPCC_Init( void ) + void HW_IPCC_BLE_Init( void ) + { + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_BLE_EVENT_CHANNEL ); +- +- return; + } + + void HW_IPCC_BLE_SendCmd( void ) + { + LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_BLE_CMD_CHANNEL ); +- +- return; + } + + static void HW_IPCC_BLE_EvtHandler( void ) +@@ -243,16 +191,12 @@ static void HW_IPCC_BLE_EvtHandler( void ) + HW_IPCC_BLE_RxEvtNot(); + + LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_BLE_EVENT_CHANNEL ); +- +- return; + } + + void HW_IPCC_BLE_SendAclData( void ) + { + LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_HCI_ACL_DATA_CHANNEL ); + LL_C1_IPCC_EnableTransmitChannel( IPCC, HW_IPCC_HCI_ACL_DATA_CHANNEL ); +- +- return; + } + + static void HW_IPCC_BLE_AclDataEvtHandler( void ) +@@ -260,8 +204,6 @@ static void HW_IPCC_BLE_AclDataEvtHandler( void ) + LL_C1_IPCC_DisableTransmitChannel( IPCC, HW_IPCC_HCI_ACL_DATA_CHANNEL ); + + HW_IPCC_BLE_AclDataAckNot(); +- +- return; + } + + __weak void HW_IPCC_BLE_AclDataAckNot( void ){}; +@@ -273,16 +215,12 @@ __weak void HW_IPCC_BLE_RxEvtNot( void ){}; + void HW_IPCC_SYS_Init( void ) + { + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_SYSTEM_EVENT_CHANNEL ); +- +- return; + } + + void HW_IPCC_SYS_SendCmd( void ) + { + LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_SYSTEM_CMD_RSP_CHANNEL ); + LL_C1_IPCC_EnableTransmitChannel( IPCC, HW_IPCC_SYSTEM_CMD_RSP_CHANNEL ); +- +- return; + } + + static void HW_IPCC_SYS_CmdEvtHandler( void ) +@@ -290,8 +228,6 @@ static void HW_IPCC_SYS_CmdEvtHandler( void ) + LL_C1_IPCC_DisableTransmitChannel( IPCC, HW_IPCC_SYSTEM_CMD_RSP_CHANNEL ); + + HW_IPCC_SYS_CmdEvtNot(); +- +- return; } --__weak void HW_IPCC_SYS_CmdEvtNot( void ){}; --__weak void HW_IPCC_SYS_EvtNot( void ){}; + static void HW_IPCC_SYS_EvtHandler( void ) +@@ -299,61 +235,11 @@ static void HW_IPCC_SYS_EvtHandler( void ) + HW_IPCC_SYS_EvtNot(); + + LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_SYSTEM_EVENT_CHANNEL ); - +- return; + } + + __weak void HW_IPCC_SYS_CmdEvtNot( void ){}; + __weak void HW_IPCC_SYS_EvtNot( void ){}; + -/****************************************************************************** - * MAC 802.15.4 - ******************************************************************************/ @@ -771,25 +1277,139 @@ index fd620b8..7b9be81 100644 -__weak void HW_IPCC_MAC_802_15_4_CmdEvtNot( void ){}; -__weak void HW_IPCC_MAC_802_15_4_EvtNot( void ){}; -#endif -+__WEAK void HW_IPCC_SYS_CmdEvtNot( void ){}; -+__WEAK void HW_IPCC_SYS_EvtNot( void ){}; - +- /****************************************************************************** * THREAD -@@ -424,9 +335,9 @@ static void HW_IPCC_THREAD_CliNotEvtHandler( void ) - return; + ******************************************************************************/ +@@ -393,8 +279,6 @@ void HW_IPCC_THREAD_CliSendAck( void ) + { + LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_THREAD_CLI_NOTIFICATION_ACK_CHANNEL ); + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_THREAD_CLI_NOTIFICATION_ACK_CHANNEL ); +- +- return; } --__weak void HW_IPCC_OT_CmdEvtNot( void ){}; --__weak void HW_IPCC_CLI_CmdEvtNot( void ){}; --__weak void HW_IPCC_THREAD_EvtNot( void ){}; -+__WEAK void HW_IPCC_OT_CmdEvtNot( void ){}; -+__WEAK void HW_IPCC_CLI_CmdEvtNot( void ){}; -+__WEAK void HW_IPCC_THREAD_EvtNot( void ){}; + static void HW_IPCC_OT_CmdEvtHandler( void ) +@@ -402,8 +286,6 @@ static void HW_IPCC_OT_CmdEvtHandler( void ) + LL_C1_IPCC_DisableTransmitChannel( IPCC, HW_IPCC_THREAD_OT_CMD_RSP_CHANNEL ); - #endif /* THREAD_WB */ + HW_IPCC_OT_CmdEvtNot(); +- +- return; + } -@@ -548,74 +459,6 @@ void HW_IPCC_LLD_BLE_SendRspAck( void ) + static void HW_IPCC_THREAD_NotEvtHandler( void ) +@@ -411,8 +293,6 @@ static void HW_IPCC_THREAD_NotEvtHandler( void ) + LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_THREAD_NOTIFICATION_ACK_CHANNEL ); + + HW_IPCC_THREAD_EvtNot(); +- +- return; + } + + static void HW_IPCC_THREAD_CliNotEvtHandler( void ) +@@ -420,8 +300,6 @@ static void HW_IPCC_THREAD_CliNotEvtHandler( void ) + LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_THREAD_CLI_NOTIFICATION_ACK_CHANNEL ); + + HW_IPCC_THREAD_CliEvtNot(); +- +- return; + } + + __weak void HW_IPCC_OT_CmdEvtNot( void ){}; +@@ -438,7 +316,6 @@ void HW_IPCC_LLDTESTS_Init( void ) + { + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_LLDTESTS_CLI_RSP_CHANNEL ); + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_LLDTESTS_M0_CMD_CHANNEL ); +- return; + } + + void HW_IPCC_LLDTESTS_SendCliCmd( void ) +@@ -451,28 +328,24 @@ static void HW_IPCC_LLDTESTS_ReceiveCliRspHandler( void ) + { + LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_LLDTESTS_CLI_RSP_CHANNEL ); + HW_IPCC_LLDTESTS_ReceiveCliRsp(); +- return; + } + + void HW_IPCC_LLDTESTS_SendCliRspAck( void ) + { + LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_LLDTESTS_CLI_RSP_CHANNEL ); + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_LLDTESTS_CLI_RSP_CHANNEL ); +- return; + } + + static void HW_IPCC_LLDTESTS_ReceiveM0CmdHandler( void ) + { + LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_LLDTESTS_M0_CMD_CHANNEL ); + HW_IPCC_LLDTESTS_ReceiveM0Cmd(); +- return; + } + + void HW_IPCC_LLDTESTS_SendM0CmdAck( void ) + { + LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_LLDTESTS_M0_CMD_CHANNEL ); + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_LLDTESTS_M0_CMD_CHANNEL ); +- return; + } + __weak void HW_IPCC_LLDTESTS_ReceiveCliRsp( void ){}; + __weak void HW_IPCC_LLDTESTS_ReceiveM0Cmd( void ){}; +@@ -486,13 +359,11 @@ void HW_IPCC_LLD_BLE_Init( void ) + { + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_LLD_BLE_RSP_CHANNEL ); + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_LLD_BLE_M0_CMD_CHANNEL ); +- return; + } + + void HW_IPCC_LLD_BLE_SendCliCmd( void ) + { + LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_LLD_BLE_CLI_CMD_CHANNEL ); +- return; + } + + /*static void HW_IPCC_LLD_BLE_ReceiveCliRspHandler( void ) +@@ -506,21 +377,18 @@ void HW_IPCC_LLD_BLE_SendCliRspAck( void ) + { + LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_LLD_BLE_CLI_RSP_CHANNEL ); + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_LLD_BLE_CLI_RSP_CHANNEL ); +- return; + } + + static void HW_IPCC_LLD_BLE_ReceiveM0CmdHandler( void ) + { + //LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_LLD_BLE_M0_CMD_CHANNEL ); + HW_IPCC_LLD_BLE_ReceiveM0Cmd(); +- return; + } + + void HW_IPCC_LLD_BLE_SendM0CmdAck( void ) + { + LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_LLD_BLE_M0_CMD_CHANNEL ); + //LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_LLD_BLE_M0_CMD_CHANNEL ); +- return; + } + __weak void HW_IPCC_LLD_BLE_ReceiveCliRsp( void ){}; + __weak void HW_IPCC_LLD_BLE_ReceiveM0Cmd( void ){}; +@@ -529,93 +397,22 @@ __weak void HW_IPCC_LLD_BLE_ReceiveM0Cmd( void ){}; + void HW_IPCC_LLD_BLE_SendCmd( void ) + { + LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_LLD_BLE_CMD_CHANNEL ); +- return; + } + + static void HW_IPCC_LLD_BLE_ReceiveRspHandler( void ) + { + LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_LLD_BLE_RSP_CHANNEL ); + HW_IPCC_LLD_BLE_ReceiveRsp(); +- return; + } + + void HW_IPCC_LLD_BLE_SendRspAck( void ) + { + LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_LLD_BLE_RSP_CHANNEL ); + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_LLD_BLE_RSP_CHANNEL ); +- return; + } #endif /* LLD_BLE_WB */ @@ -864,12 +1484,33 @@ index fd620b8..7b9be81 100644 /****************************************************************************** * MEMORY MANAGER ******************************************************************************/ -@@ -666,4 +509,5 @@ static void HW_IPCC_TRACES_EvtHandler( void ) - return; +@@ -632,8 +429,6 @@ void HW_IPCC_MM_SendFreeBuf( void (*cb)( void ) ) + + LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_MM_RELEASE_BUFFER_CHANNEL ); + } +- +- return; + } + + static void HW_IPCC_MM_FreeBufHandler( void ) +@@ -643,8 +438,6 @@ static void HW_IPCC_MM_FreeBufHandler( void ) + FreeBufCb(); + + LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_MM_RELEASE_BUFFER_CHANNEL ); +- +- return; + } + + /****************************************************************************** +@@ -662,8 +455,7 @@ static void HW_IPCC_TRACES_EvtHandler( void ) + HW_IPCC_TRACES_EvtNot(); + + LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_TRACES_CHANNEL ); +- +- return; } --__weak void HW_IPCC_TRACES_EvtNot( void ){}; -+__WEAK void HW_IPCC_TRACES_EvtNot( void ){}; + __weak void HW_IPCC_TRACES_EvtNot( void ){}; +#endif /* STM32WBxx */ diff --git a/src/utility/STM32Cube_FW/mbox_def.h b/src/utility/STM32Cube_FW/mbox_def.h index 68b71f9..0c974f8 100644 @@ -965,7 +1606,7 @@ index 68b71f9..0c974f8 100644 #endif /*__MBOX_H */ diff --git a/src/utility/STM32Cube_FW/shci.c b/src/utility/STM32Cube_FW/shci.c -index 472a108..a847522 100644 +index 301db76..a847522 100644 --- a/src/utility/STM32Cube_FW/shci.c +++ b/src/utility/STM32Cube_FW/shci.c @@ -16,7 +16,7 @@ @@ -1027,14 +1668,13 @@ index 472a108..a847522 100644 SHCI_CmdStatus_t SHCI_C2_Reinit( void ) { /** -@@ -739,4 +703,4 @@ SHCI_CmdStatus_t SHCI_GetWirelessFwInfo( WirelessFwInfo_t* pWirelessInfo ) +@@ -739,3 +703,4 @@ SHCI_CmdStatus_t SHCI_GetWirelessFwInfo( WirelessFwInfo_t* pWirelessInfo ) return (SHCI_Success); } -- +#endif /* STM32WBxx */ diff --git a/src/utility/STM32Cube_FW/shci.h b/src/utility/STM32Cube_FW/shci.h -index 102089e..6b6ffd1 100644 +index 7ca9021..a0f1e4d 100644 --- a/src/utility/STM32Cube_FW/shci.h +++ b/src/utility/STM32Cube_FW/shci.h @@ -49,7 +49,6 @@ extern "C" { @@ -1045,15 +1685,6 @@ index 102089e..6b6ffd1 100644 } SCHI_SystemErrCode_t; #define SHCI_EVTCODE ( 0xFF ) -@@ -102,7 +101,7 @@ extern "C" { - - /** - * SHCI_SUB_EVT_THREAD_NVM_RAM_UPDATE -- * This notifies the CPU1 which part of the OT NVM RAM has been updated so that only the modified -+ * This notifies the CPU1 which part of the 'OT NVM RAM' has been updated so that only the modified - * section could be written in Flash/NVM - * StartAddress : Start address of the section that has been modified - * Size : Size (in bytes) of the section that has been modified @@ -216,9 +215,7 @@ extern "C" { SHCI_OCF_C2_FLASH_STORE_DATA, SHCI_OCF_C2_FLASH_ERASE_DATA, @@ -1064,7 +1695,34 @@ index 102089e..6b6ffd1 100644 SHCI_OCF_C2_LLD_TESTS_INIT, SHCI_OCF_C2_EXTPA_CONFIG, SHCI_OCF_C2_SET_FLASH_ACTIVITY_CONTROL, -@@ -648,8 +645,6 @@ extern "C" { +@@ -436,7 +433,7 @@ extern "C" { + * PrWriteListSize + * NOTE: This parameter is ignored by the CPU2 when the parameter "Options" is set to "LL_only" ( see Options description in that structure ) + * +- * Maximum number of supported �prepare write request� ++ * Maximum number of supported "prepare write request" + * - Min value: given by the macro DEFAULT_PREP_WRITE_LIST_SIZE + * - Max value: a value higher than the minimum required can be specified, but it is not recommended + */ +@@ -503,7 +500,7 @@ extern "C" { + * MaxConnEventLength + * This parameter determines the maximum duration of a slave connection event. When this duration is reached the slave closes + * the current connections event (whatever is the CE_length parameter specified by the master in HCI_CREATE_CONNECTION HCI command), +- * expressed in units of 625/256 �s (~2.44 �s) ++ * expressed in units of 625/256 µs (~2.44 µs) + * - Min value: 0 (if 0 is specified, the master and slave perform only a single TX-RX exchange per connection event) + * - Max value: 1638400 (4000 ms). A higher value can be specified (max 0xFFFFFFFF) but results in a maximum connection time + * of 4000 ms as specified. In this case the parameter is not applied, and the predicted CE length calculated on slave is not shortened +@@ -512,7 +509,7 @@ extern "C" { + + /** + * HsStartupTime +- * Startup time of the high speed (16 or 32 MHz) crystal oscillator in units of 625/256 �s (~2.44 �s). ++ * Startup time of the high speed (16 or 32 MHz) crystal oscillator in units of 625/256 µs (~2.44 µs). + * - Min value: 0 + * - Max value: 820 (~2 ms). A higher value can be specified, but the value that implemented in stack is forced to ~2 ms + */ +@@ -678,8 +675,6 @@ extern "C" { { uint8_t thread_config; uint8_t ble_config; @@ -1073,7 +1731,7 @@ index 102089e..6b6ffd1 100644 } SHCI_C2_DEBUG_TracesConfig_t; typedef PACKED_STRUCT -@@ -713,8 +708,6 @@ extern "C" { +@@ -743,8 +738,6 @@ extern "C" { { BLE_ENABLE, THREAD_ENABLE, @@ -1082,7 +1740,7 @@ index 102089e..6b6ffd1 100644 } SHCI_C2_CONCURRENT_Mode_Param_t; /** No response parameters*/ -@@ -737,18 +730,13 @@ extern "C" { +@@ -767,18 +760,13 @@ extern "C" { { BLE_IP, THREAD_IP, @@ -1101,7 +1759,7 @@ index 102089e..6b6ffd1 100644 #define SHCI_OPCODE_C2_LLD_TESTS_INIT (( SHCI_OGF << 10) + SHCI_OCF_C2_LLD_TESTS_INIT) #define SHCI_OPCODE_C2_BLE_LLD_INIT (( SHCI_OGF << 10) + SHCI_OCF_C2_BLE_LLD_INIT) -@@ -856,7 +844,7 @@ extern "C" { +@@ -893,7 +881,7 @@ extern "C" { #define FUS_DEVICE_INFO_TABLE_VALIDITY_KEYWORD (0xA94656B9) /* @@ -1110,7 +1768,7 @@ index 102089e..6b6ffd1 100644 * MB_WirelessFwInfoTable_t.This structure contains 4 fields (Version,MemorySize, Stack_info and a reserved part) * each of those coded on 32 bits as shown on the table below: * -@@ -912,9 +900,6 @@ extern "C" { +@@ -949,9 +937,6 @@ extern "C" { #define INFO_STACK_TYPE_BLE_HCI_EXT_ADV 0x07 #define INFO_STACK_TYPE_THREAD_FTD 0x10 #define INFO_STACK_TYPE_THREAD_MTD 0x11 @@ -1120,7 +1778,7 @@ index 102089e..6b6ffd1 100644 #define INFO_STACK_TYPE_BLE_THREAD_FTD_STATIC 0x50 #define INFO_STACK_TYPE_BLE_THREAD_FTD_DYAMIC 0x51 #define INFO_STACK_TYPE_802154_LLD_TESTS 0x60 -@@ -923,12 +908,7 @@ extern "C" { +@@ -960,12 +945,7 @@ extern "C" { #define INFO_STACK_TYPE_BLE_LLD_TESTS 0x63 #define INFO_STACK_TYPE_BLE_RLV 0x64 #define INFO_STACK_TYPE_802154_RLV 0x65 @@ -1133,7 +1791,7 @@ index 102089e..6b6ffd1 100644 typedef struct { /** -@@ -1102,7 +1082,7 @@ typedef struct { +@@ -1139,7 +1119,7 @@ typedef struct { * @brief Starts the LLD tests CLI * * @param param_size : Nb of bytes @@ -1142,7 +1800,7 @@ index 102089e..6b6ffd1 100644 * @retval Status */ SHCI_CmdStatus_t SHCI_C2_LLDTESTS_Init( uint8_t param_size, uint8_t * p_param ); -@@ -1112,19 +1092,10 @@ typedef struct { +@@ -1149,20 +1129,11 @@ typedef struct { * @brief Starts the LLD tests BLE * * @param param_size : Nb of bytes @@ -1151,7 +1809,7 @@ index 102089e..6b6ffd1 100644 * @retval Status */ SHCI_CmdStatus_t SHCI_C2_BLE_LLD_Init( uint8_t param_size, uint8_t * p_param ); -- + - /** - * SHCI_C2_ZIGBEE_Init - * @brief Starts the Zigbee Stack @@ -1160,10 +1818,11 @@ index 102089e..6b6ffd1 100644 - * @retval Status - */ - SHCI_CmdStatus_t SHCI_C2_ZIGBEE_Init( void ); - +- /** * SHCI_C2_DEBUG_Init -@@ -1200,16 +1171,6 @@ typedef struct { + * @brief Starts the Traces +@@ -1237,16 +1208,6 @@ typedef struct { */ SHCI_CmdStatus_t SHCI_C2_RADIO_AllowLowPower( SHCI_C2_FLASH_Ip_t Ip,uint8_t FlagRadioLowPowerOn); @@ -1181,7 +1840,7 @@ index 102089e..6b6ffd1 100644 * SHCI_GetWirelessFwInfo * @brief This function read back the informations relative to the wireless binary loaded. diff --git a/src/utility/STM32Cube_FW/shci_tl.c b/src/utility/STM32Cube_FW/shci_tl.c -index ddb3a02..d1a448d 100644 +index 449b8b1..b3cee00 100644 --- a/src/utility/STM32Cube_FW/shci_tl.c +++ b/src/utility/STM32Cube_FW/shci_tl.c @@ -16,12 +16,13 @@ @@ -1199,42 +1858,116 @@ index ddb3a02..d1a448d 100644 /* Private typedef -----------------------------------------------------------*/ typedef enum -@@ -168,6 +169,20 @@ void shci_send( uint16_t cmd_code, uint8_t len_cmd_payload, uint8_t * p_cmd_payl - return; +@@ -70,8 +71,6 @@ void shci_init(void(* UserEvtRx)(void* pData), void* pConf) + shci_register_io_bus (&shciContext.io); + + TlInit((TL_CmdPacket_t *)(((SHCI_TL_HciInitConf_t *)pConf)->p_cmdbuffer)); +- +- return; } + void shci_user_evt_proc(void) +@@ -127,8 +126,6 @@ void shci_user_evt_proc(void) + shci_notify_asynch_evt((void*) &SHciAsynchEventQueue); + } + +- +- return; + } + + void shci_resume_flow( void ) +@@ -140,8 +137,6 @@ void shci_resume_flow( void ) + * be called + */ + shci_notify_asynch_evt((void*) &SHciAsynchEventQueue); +- +- return; + } + + void shci_send( uint16_t cmd_code, uint8_t len_cmd_payload, uint8_t * p_cmd_payload, TL_EvtPacket_t * p_rsp ) +@@ -164,8 +159,20 @@ void shci_send( uint16_t cmd_code, uint8_t len_cmd_payload, uint8_t * p_cmd_payl + memcpy( &(p_rsp->evtserial), pCmdBuffer, ((TL_EvtSerial_t*)pCmdBuffer)->evt.plen + TL_EVT_HDR_SIZE ); + + Cmd_SetStatus(SHCI_TL_CmdAvailable); ++} ++ +void shci_notify_asynch_evt(void *pdata) +{ + UNUSED(pdata); + /* Need to parse data in future version */ + shci_user_evt_proc(); +} -+ + +- return; +void shci_register_io_bus(tSHciIO *fops) +{ + /* Register IO bus services */ + fops->Init = TL_SYS_Init; + fops->Send = TL_SYS_SendCmd; -+} -+ + } + /* Private functions ---------------------------------------------------------*/ - static void TlInit( TL_CmdPacket_t * p_cmdbuffer ) +@@ -190,8 +197,6 @@ static void TlInit( TL_CmdPacket_t * p_cmdbuffer ) + Conf.IoBusCallBackUserEvt = TlUserEvtReceived; + shciContext.io.Init(&Conf); + } +- +- return; + } + + static void Cmd_SetStatus(SHCI_TL_CmdStatus_t shcicmdstatus) +@@ -212,24 +217,18 @@ static void Cmd_SetStatus(SHCI_TL_CmdStatus_t shcicmdstatus) + StatusNotCallBackFunction( SHCI_TL_CmdAvailable ); + } + } +- +- return; + } + + static void TlCmdEvtReceived(TL_EvtPacket_t *shcievt) { -@@ -252,4 +267,4 @@ __WEAK void shci_cmd_resp_release(uint32_t flag) - return; + (void)(shcievt); + shci_cmd_resp_release(0); /**< Notify the application the Cmd response has been received */ +- +- return; + } + + static void TlUserEvtReceived(TL_EvtPacket_t *shcievt) + { + LST_insert_tail(&SHciAsynchEventQueue, (tListNode *)shcievt); + shci_notify_asynch_evt((void*) &SHciAsynchEventQueue); /**< Notify the application a full HCI event has been received */ +- +- return; + } + + /* Weak implementation ----------------------------------------------------------------*/ +@@ -239,8 +238,6 @@ __WEAK void shci_cmd_resp_wait(uint32_t timeout) + + CmdRspStatusFlag = SHCI_TL_CMD_RESP_WAIT; + while(CmdRspStatusFlag != SHCI_TL_CMD_RESP_RELEASE); +- +- return; } + __WEAK void shci_cmd_resp_release(uint32_t flag) +@@ -248,7 +245,5 @@ __WEAK void shci_cmd_resp_release(uint32_t flag) + (void)flag; + + CmdRspStatusFlag = SHCI_TL_CMD_RESP_RELEASE; +- +- return; + } - +#endif /* STM32WBxx */ diff --git a/src/utility/STM32Cube_FW/stm32_wpan_common.h b/src/utility/STM32Cube_FW/stm32_wpan_common.h -index b47b804..5a2b2a5 100644 +index f407bb9..5a2b2a5 100644 --- a/src/utility/STM32Cube_FW/stm32_wpan_common.h +++ b/src/utility/STM32Cube_FW/stm32_wpan_common.h @@ -25,19 +25,9 @@ extern "C" { #endif --#if defined ( __CC_ARM ) +-#if defined ( __CC_ARM )||defined (__ARMCC_VERSION) - #define __ASM __asm /*!< asm keyword for ARM Compiler */ - #define __INLINE __inline /*!< inline keyword for ARM Compiler */ - #define __STATIC_INLINE static __inline @@ -1285,7 +2018,7 @@ index b47b804..5a2b2a5 100644 #ifdef __cplusplus } diff --git a/src/utility/STM32Cube_FW/stm_list.c b/src/utility/STM32Cube_FW/stm_list.c -index 4c92864..77dec64 100644 +index 4c92864..9892441 100644 --- a/src/utility/STM32Cube_FW/stm_list.c +++ b/src/utility/STM32Cube_FW/stm_list.c @@ -16,13 +16,13 @@ @@ -1305,7 +2038,7 @@ index 4c92864..77dec64 100644 /****************************************************************************** * Function Definitions -@@ -33,10 +33,10 @@ void LST_init_head (tListNode * listHead) +@@ -33,20 +33,20 @@ void LST_init_head (tListNode * listHead) listHead->prev = listHead; } @@ -1318,6 +2051,18 @@ index 4c92864..77dec64 100644 primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ + if(listHead->next == listHead) + { +- return_value = TRUE; ++ return_value = true; + } + else + { +- return_value = FALSE; ++ return_value = false; + } + __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ + @@ -204,3 +204,4 @@ void LST_get_prev_node (tListNode * ref_node, tListNode ** node) __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ @@ -1346,10 +2091,10 @@ index b7c3254..769c211 100644 void LST_insert_head (tListNode * listHead, tListNode * node); diff --git a/src/utility/STM32Cube_FW/tl.h b/src/utility/STM32Cube_FW/tl.h -index 2124d26..678769c 100644 +index c199bb2..982bb58 100644 --- a/src/utility/STM32Cube_FW/tl.h +++ b/src/utility/STM32Cube_FW/tl.h -@@ -199,19 +199,6 @@ typedef struct +@@ -202,19 +202,6 @@ typedef struct uint8_t *p_BleLldM0CmdBuffer; } TL_BLE_LLD_Config_t; @@ -1369,7 +2114,7 @@ index 2124d26..678769c 100644 /** * @brief Contain the BLE HCI Init Configuration * @{ -@@ -305,26 +292,6 @@ void TL_MM_EvtDone( TL_EvtPacket_t * hcievt ); +@@ -308,26 +295,6 @@ void TL_MM_EvtDone( TL_EvtPacket_t * hcievt ); void TL_TRACES_Init( void ); void TL_TRACES_EvtReceived( TL_EvtPacket_t * hcievt ); @@ -1397,7 +2142,7 @@ index 2124d26..678769c 100644 } /* extern "C" */ #endif diff --git a/src/utility/STM32Cube_FW/tl_mbox.c b/src/utility/STM32Cube_FW/tl_mbox.c -index 4112429..a9abb18 100644 +index fcd7766..a9abb18 100644 --- a/src/utility/STM32Cube_FW/tl_mbox.c +++ b/src/utility/STM32Cube_FW/tl_mbox.c @@ -16,6 +16,7 @@ @@ -1575,12 +2320,11 @@ index 4112429..a9abb18 100644 /****************************************************************************** * MEMORY MANAGER ******************************************************************************/ -@@ -846,4 +710,4 @@ static void OutputDbgTrace(TL_MB_PacketType_t packet_type, uint8_t* buffer) +@@ -846,3 +710,4 @@ static void OutputDbgTrace(TL_MB_PacketType_t packet_type, uint8_t* buffer) return; } -- +#endif /* STM32WBxx */ -- -2.33.0.windows.1 +2.38.0.windows.1 diff --git a/extras/STM32Cube_FW/0002-fix-include-a-timeout-when-waiting-for-the-cmd_resp.patch b/extras/STM32Cube_FW/0002-fix-include-a-timeout-when-waiting-for-the-cmd_resp.patch index 326b767e..5f7502df 100644 --- a/extras/STM32Cube_FW/0002-fix-include-a-timeout-when-waiting-for-the-cmd_resp.patch +++ b/extras/STM32Cube_FW/0002-fix-include-a-timeout-when-waiting-for-the-cmd_resp.patch @@ -1,27 +1,26 @@ -From 979f153a4e6d5d616ddea616bcd732e32cb1773c Mon Sep 17 00:00:00 2001 -From: Alexandre Bourdiol <alexandre.bourdiol@st.com> -Date: Tue, 30 Aug 2022 13:19:36 +0200 +From e12c9c97eec7eacb648720fc65adc2a3897ec257 Mon Sep 17 00:00:00 2001 +From: Frederic Pillon <frederic.pillon@st.com> +Date: Mon, 12 Dec 2022 17:17:48 +0100 Subject: [PATCH 2/3] fix: include a timeout when waiting for the cmd_resp -Signed-off-by: Alexandre Bourdiol <alexandre.bourdiol@st.com> +Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- - src/utility/STM32Cube_FW/shci_tl.c | 11 +++++++---- - 1 file changed, 7 insertions(+), 4 deletions(-) + src/utility/STM32Cube_FW/shci_tl.c | 9 ++++++--- + 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/utility/STM32Cube_FW/shci_tl.c b/src/utility/STM32Cube_FW/shci_tl.c -index d1a448d..678de84 100644 +index b3cee00..1abd1be 100644 --- a/src/utility/STM32Cube_FW/shci_tl.c +++ b/src/utility/STM32Cube_FW/shci_tl.c -@@ -20,6 +20,8 @@ - /* Includes ------------------------------------------------------------------*/ - #include "stm32_wpan_common.h" - -+#include <Arduino.h> -+ +@@ -23,6 +23,7 @@ #include "stm_list.h" #include "shci_tl.h" #include "stm32_def.h" -@@ -250,11 +252,12 @@ static void TlUserEvtReceived(TL_EvtPacket_t *shcievt) ++#include "wiring_time.h" + + /* Private typedef -----------------------------------------------------------*/ + typedef enum +@@ -234,10 +235,12 @@ static void TlUserEvtReceived(TL_EvtPacket_t *shcievt) /* Weak implementation ----------------------------------------------------------------*/ __WEAK void shci_cmd_resp_wait(uint32_t timeout) { @@ -29,15 +28,14 @@ index d1a448d..678de84 100644 - CmdRspStatusFlag = SHCI_TL_CMD_RESP_WAIT; - while(CmdRspStatusFlag != SHCI_TL_CMD_RESP_RELEASE); -- + for (unsigned long start = millis(); (millis() - start) < timeout;) { + if (CmdRspStatusFlag == SHCI_TL_CMD_RESP_RELEASE) { + break; + } + } - return; } + __WEAK void shci_cmd_resp_release(uint32_t flag) -- -2.33.0.windows.1 +2.38.0.windows.1 diff --git a/extras/STM32Cube_FW/0003-Added-support-for-custom-app_conf.h.patch b/extras/STM32Cube_FW/0003-chore-add-support-for-customize-app_conf_default.h.patch similarity index 58% rename from extras/STM32Cube_FW/0003-Added-support-for-custom-app_conf.h.patch rename to extras/STM32Cube_FW/0003-chore-add-support-for-customize-app_conf_default.h.patch index 33b69e55..a93713f2 100644 --- a/extras/STM32Cube_FW/0003-Added-support-for-custom-app_conf.h.patch +++ b/extras/STM32Cube_FW/0003-chore-add-support-for-customize-app_conf_default.h.patch @@ -1,54 +1,29 @@ -From d3ae98b9073e5f1e48efb32b1ef4d318814228fe Mon Sep 17 00:00:00 2001 -From: Alexandre Bourdiol <alexandre.bourdiol@st.com> -Date: Tue, 30 Aug 2022 13:31:31 +0200 -Subject: [PATCH 3/3] Added support for custom app_conf.h +From d7d18d20b957f52810315147d671c1976a18c1d2 Mon Sep 17 00:00:00 2001 +From: Frederic Pillon <frederic.pillon@st.com> +Date: Mon, 12 Dec 2022 17:29:27 +0100 +Subject: [PATCH 3/3] chore: add support for customize app_conf_default.h -Signed-off-by: Alexandre Bourdiol <alexandre.bourdiol@st.com> +Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- - src/utility/STM32Cube_FW/app_conf_default.h | 71 ++++++++++++++------- - 1 file changed, 47 insertions(+), 24 deletions(-) + src/utility/STM32Cube_FW/app_conf_default.h | 58 +++++++++++++++------ + 1 file changed, 42 insertions(+), 16 deletions(-) diff --git a/src/utility/STM32Cube_FW/app_conf_default.h b/src/utility/STM32Cube_FW/app_conf_default.h -index 54f824a..91672ac 100644 +index cc8c3e8..57f1027 100644 --- a/src/utility/STM32Cube_FW/app_conf_default.h +++ b/src/utility/STM32Cube_FW/app_conf_default.h -@@ -1,8 +1,8 @@ - /** - ****************************************************************************** -- * @file app_conf.h -+ * @file app_conf_default.h - * @author MCD Application Team -- * @brief Application configuration file for STM32WPAN Middleware. -+ * @brief Default application configuration file for STM32WPAN Middleware. - ****************************************************************************** - * @attention - * -@@ -17,11 +17,8 @@ - */ - - /* Define to prevent recursive inclusion -------------------------------------*/ --#ifndef APP_CONF_H --#define APP_CONF_H -- --#include "hw.h" --#include "ble_bufsize.h" -+#ifndef APP_CONF_DEFAULT_H -+#define APP_CONF_DEFAULT_H - - /****************************************************************************** - * Application Config -@@ -44,7 +41,9 @@ +@@ -41,7 +41,9 @@ /** * Define Tx Power */ -#define CFG_TX_POWER (0x18) /* -0.15dBm */ +#ifndef CFG_TX_POWER -+ #define CFG_TX_POWER (0x18) /* -0.15dBm */ ++ #define CFG_TX_POWER (0x18) /* -0.15dBm */ +#endif /****************************************************************************** * BLE Stack -@@ -53,13 +52,17 @@ +@@ -50,13 +52,17 @@ * Maximum number of simultaneous connections that the device will support. * Valid values are from 1 to 8 */ @@ -68,7 +43,7 @@ index 54f824a..91672ac 100644 /** * Maximum number of Attributes -@@ -68,13 +71,17 @@ +@@ -65,13 +71,17 @@ * Note that certain characteristics and relative descriptors are added automatically during device initialization * so this parameters should be 9 plus the number of user Attributes */ @@ -83,12 +58,12 @@ index 54f824a..91672ac 100644 */ -#define CFG_BLE_MAX_ATT_MTU (156) +#ifndef CFG_BLE_MAX_ATT_MTU -+ #define CFG_BLE_MAX_ATT_MTU (156) ++ #define CFG_BLE_MAX_ATT_MTU (156) +#endif /** * Size of the storage area for Attribute values -@@ -87,14 +94,18 @@ +@@ -84,14 +94,18 @@ * The total amount of memory needed is the sum of the above quantities for each attribute. * This parameter is ignored by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set */ @@ -104,18 +79,18 @@ index 54f824a..91672ac 100644 // #define CFG_BLE_PREPARE_WRITE_LIST_SIZE BLE_PREP_WRITE_X_ATT(CFG_BLE_MAX_ATT_MTU) -#define CFG_BLE_PREPARE_WRITE_LIST_SIZE (0x3A) +#ifndef CFG_BLE_PREPARE_WRITE_LIST_SIZE -+ #define CFG_BLE_PREPARE_WRITE_LIST_SIZE (0x3A) ++ #define CFG_BLE_PREPARE_WRITE_LIST_SIZE (0x3A) +#endif /** * Number of allocated memory blocks -@@ -106,12 +117,16 @@ +@@ -103,12 +117,16 @@ /** * Enable or disable the Extended Packet length feature. Valid values are 0 or 1. */ -#define CFG_BLE_DATA_LENGTH_EXTENSION 1 +#ifndef CFG_BLE_DATA_LENGTH_EXTENSION -+ #define CFG_BLE_DATA_LENGTH_EXTENSION 1 ++ #define CFG_BLE_DATA_LENGTH_EXTENSION 1 +#endif /** @@ -123,35 +98,35 @@ index 54f824a..91672ac 100644 */ -#define CFG_BLE_SLAVE_SCA 500 +#ifndef CFG_BLE_SLAVE_SCA -+ #define CFG_BLE_SLAVE_SCA 500 ++ #define CFG_BLE_SLAVE_SCA 500 +#endif /** * Sleep clock accuracy in Master mode -@@ -124,7 +139,9 @@ +@@ -121,7 +139,9 @@ * 6 : 21 ppm to 30 ppm * 7 : 0 ppm to 20 ppm */ -#define CFG_BLE_MASTER_SCA 0 +#ifndef CFG_BLE_MASTER_SCA -+ #define CFG_BLE_MASTER_SCA 0 ++ #define CFG_BLE_MASTER_SCA 0 +#endif /** * LsSource -@@ -132,21 +149,27 @@ - * - bit 0: 1: Calibration for the RF system wakeup clock source 0: No calibration for the RF system wakeup clock source - * - bit 1: 1: STM32W5M Module device 0: Other devices as STM32WBxx SOC, STM32WB1M module +@@ -130,21 +150,27 @@ + * - bit 1: 1: STM32WB5M Module device 0: Other devices as STM32WBxx SOC, STM32WB1M module + * - bit 2: 1: HSE/1024 Clock config 0: LSE Clock config */ -#if defined(STM32WB5Mxx) -- #define CFG_BLE_LSE_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LSE_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LSE_MOD5MM_DEV) +- #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_MOD5MM_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) -#else -- #define CFG_BLE_LSE_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LSE_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LSE_OTHER_DEV) -+#ifndef CFG_BLE_LSE_SOURCE +- #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_OTHER_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) ++#ifndef CFG_BLE_LS_SOURCE + #if defined(STM32WB5Mxx) -+ #define CFG_BLE_LSE_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LSE_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LSE_MOD5MM_DEV) ++ #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_MOD5MM_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) + #else -+ #define CFG_BLE_LSE_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LSE_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LSE_OTHER_DEV) ++ #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_OTHER_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) + #endif #endif @@ -160,7 +135,7 @@ index 54f824a..91672ac 100644 */ -#define CFG_BLE_HSE_STARTUP_TIME 0x148 +#ifndef CFG_BLE_HSE_STARTUP_TIME -+ #define CFG_BLE_HSE_STARTUP_TIME 0x148 ++ #define CFG_BLE_HSE_STARTUP_TIME 0x148 +#endif /** @@ -168,18 +143,11 @@ index 54f824a..91672ac 100644 */ -#define CFG_BLE_MAX_CONN_EVENT_LENGTH (0xFFFFFFFF) +#ifndef CFG_BLE_MAX_CONN_EVENT_LENGTH -+ #define CFG_BLE_MAX_CONN_EVENT_LENGTH (0xFFFFFFFF) ++ #define CFG_BLE_MAX_CONN_EVENT_LENGTH (0xFFFFFFFF) +#endif /** * Viterbi Mode -@@ -234,5 +257,5 @@ - - #define CFG_BLE_RX_PATH_COMPENS (0) - --#endif /*APP_CONF_H */ -+#endif /* APP_CONF_DEFAULT_H */ - -- -2.33.0.windows.1 +2.38.0.windows.1 From 2d60f4511b08f8ffa4cc2414a57aa12b96337208 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Tue, 13 Dec 2022 15:34:50 +0100 Subject: [PATCH 105/226] chore: update STM32Cube_FW from Cube version v1.15.0 Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- src/utility/STM32Cube_FW/README.md | 4 +- src/utility/STM32Cube_FW/app_conf_default.h | 524 ++++++++++++++++--- src/utility/STM32Cube_FW/ble_bufsize.h | 37 +- src/utility/STM32Cube_FW/hw.h | 28 +- src/utility/STM32Cube_FW/hw_ipcc.c | 184 ++++++- src/utility/STM32Cube_FW/mbox_def.h | 34 ++ src/utility/STM32Cube_FW/shci.c | 39 +- src/utility/STM32Cube_FW/shci.h | 96 +++- src/utility/STM32Cube_FW/shci_tl.c | 29 +- src/utility/STM32Cube_FW/stm32_wpan_common.h | 39 +- src/utility/STM32Cube_FW/stm_list.c | 11 +- src/utility/STM32Cube_FW/stm_list.h | 4 +- src/utility/STM32Cube_FW/tl.h | 46 +- src/utility/STM32Cube_FW/tl_mbox.c | 143 ++++- 14 files changed, 1048 insertions(+), 170 deletions(-) diff --git a/src/utility/STM32Cube_FW/README.md b/src/utility/STM32Cube_FW/README.md index c9af001e..69041d4c 100644 --- a/src/utility/STM32Cube_FW/README.md +++ b/src/utility/STM32Cube_FW/README.md @@ -1,6 +1,6 @@ ## Source -[STMicroelectronics/STM32CubeWB Release v1.14.0](https://github.com/STMicroelectronics/STM32CubeWB/releases/tag/v1.14.0) -- Application: [BLE_TransparentMode](https://github.com/STMicroelectronics/STM32CubeWB/tree/v1.14.0/Projects/P-NUCLEO-WB55.Nucleo/Applications/BLE/BLE_TransparentMode) +[STMicroelectronics/STM32CubeWB Release vv1.15.0](https://github.com/STMicroelectronics/STM32CubeWB/releases/tag/vv1.15.0) +- Application: [BLE_TransparentMode](https://github.com/STMicroelectronics/STM32CubeWB/tree/vv1.15.0/Projects/P-NUCLEO-WB55.Nucleo/Applications/BLE/BLE_TransparentMode) diff --git a/src/utility/STM32Cube_FW/app_conf_default.h b/src/utility/STM32Cube_FW/app_conf_default.h index 91672ac9..2606a059 100644 --- a/src/utility/STM32Cube_FW/app_conf_default.h +++ b/src/utility/STM32Cube_FW/app_conf_default.h @@ -1,8 +1,9 @@ +/* USER CODE BEGIN Header */ /** ****************************************************************************** - * @file app_conf_default.h + * @file app_conf.h * @author MCD Application Team - * @brief Default application configuration file for STM32WPAN Middleware. + * @brief Application configuration file for STM32WPAN Middleware. ****************************************************************************** * @attention * @@ -15,35 +16,94 @@ * ****************************************************************************** */ +/* USER CODE END Header */ /* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef APP_CONF_DEFAULT_H -#define APP_CONF_DEFAULT_H +#ifndef APP_CONF_H +#define APP_CONF_H + +#include "hw.h" +#include "hw_conf.h" +#include "hw_if.h" +#include "ble_bufsize.h" /****************************************************************************** * Application Config ******************************************************************************/ -/**< generic parameters ******************************************************/ -/* HCI related defines */ +/** + * Define Secure Connections Support + */ +#define CFG_SECURE_NOT_SUPPORTED (0x00) +#define CFG_SECURE_OPTIONAL (0x01) +#define CFG_SECURE_MANDATORY (0x02) -#define ACI_HAL_SET_TX_POWER_LEVEL 0xFC0F -#define ACI_WRITE_CONFIG_DATA_OPCODE 0xFC0C -#define ACI_READ_CONFIG_DATA_OPCODE 0xFC0D -#define MAX_HCI_ACL_PACKET_SIZE (sizeof(TL_PacketHeader_t) + 5 + 251) -#define HCI_RESET 0x0C03 +#define CFG_SC_SUPPORT CFG_SECURE_OPTIONAL -#ifndef BLE_SHARED_MEM_BYTE_ORDER - #define BLE_SHARED_MEM_BYTE_ORDER MSBFIRST -#endif -#define BLE_MODULE_SHARED_MEM_BUFFER_SIZE 128 +/** + * Define Keypress Notification Support + */ +#define CFG_KEYPRESS_NOT_SUPPORTED (0x00) +#define CFG_KEYPRESS_SUPPORTED (0x01) + +#define CFG_KEYPRESS_NOTIFICATION_SUPPORT CFG_KEYPRESS_NOT_SUPPORTED /** - * Define Tx Power + * Numeric Comparison Answers */ -#ifndef CFG_TX_POWER - #define CFG_TX_POWER (0x18) /* -0.15dBm */ -#endif +#define YES (0x01) +#define NO (0x00) + +/** + * Device name configuration for Generic Access Service + */ +#define CFG_GAP_DEVICE_NAME "TEMPLATE" +#define CFG_GAP_DEVICE_NAME_LENGTH (8) + +/** +* Identity root key used to derive LTK and CSRK +*/ +#define CFG_BLE_IRK {0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0} + +/** +* Encryption root key used to derive LTK and CSRK +*/ +#define CFG_BLE_ERK {0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21, 0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21} + +/** + * SMPS supply + * SMPS not used when Set to 0 + * SMPS used when Set to 1 + */ +#define CFG_USE_SMPS 0 + +/* USER CODE BEGIN Generic_Parameters */ +/* USER CODE END Generic_Parameters */ + +/**< specific parameters */ +/*****************************************************/ + +/* USER CODE BEGIN Specific_Parameters */ +#define PUSH_BUTTON_SW1_EXTI_IRQHandler EXTI4_IRQHandler + +/* USER CODE END Specific_Parameters */ + +/****************************************************************************** + * Information Table + * + * Version + * [0:3] = Build - 0: Untracked - 15:Released - x: Tracked version + * [4:7] = branch - 0: Mass Market - x: ... + * [8:15] = Subversion + * [16:23] = Version minor + * [24:31] = Version major + * + ******************************************************************************/ +#define CFG_FW_MAJOR_VERSION (0) +#define CFG_FW_MINOR_VERSION (0) +#define CFG_FW_SUBVERSION (1) +#define CFG_FW_BRANCH (0) +#define CFG_FW_BUILD (0) /****************************************************************************** * BLE Stack @@ -52,17 +112,13 @@ * Maximum number of simultaneous connections that the device will support. * Valid values are from 1 to 8 */ -#ifndef CFG_BLE_NUM_LINK - #define CFG_BLE_NUM_LINK 8 -#endif +#define CFG_BLE_NUM_LINK 8 /** * Maximum number of Services that can be stored in the GATT database. * Note that the GAP and GATT services are automatically added so this parameter should be 2 plus the number of user services */ -#ifndef CFG_BLE_NUM_GATT_SERVICES - #define CFG_BLE_NUM_GATT_SERVICES 8 -#endif +#define CFG_BLE_NUM_GATT_SERVICES 8 /** * Maximum number of Attributes @@ -71,17 +127,13 @@ * Note that certain characteristics and relative descriptors are added automatically during device initialization * so this parameters should be 9 plus the number of user Attributes */ -#ifndef CFG_BLE_NUM_GATT_ATTRIBUTES - #define CFG_BLE_NUM_GATT_ATTRIBUTES 68 -#endif +#define CFG_BLE_NUM_GATT_ATTRIBUTES 68 /** * Maximum supported ATT_MTU size * This parameter is ignored by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set */ -#ifndef CFG_BLE_MAX_ATT_MTU - #define CFG_BLE_MAX_ATT_MTU (156) -#endif +#define CFG_BLE_MAX_ATT_MTU (156) /** * Size of the storage area for Attribute values @@ -94,39 +146,29 @@ * The total amount of memory needed is the sum of the above quantities for each attribute. * This parameter is ignored by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set */ -#ifndef CFG_BLE_ATT_VALUE_ARRAY_SIZE - #define CFG_BLE_ATT_VALUE_ARRAY_SIZE (1344) -#endif +#define CFG_BLE_ATT_VALUE_ARRAY_SIZE (1344) /** * Prepare Write List size in terms of number of packet * This parameter is ignored by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set */ -// #define CFG_BLE_PREPARE_WRITE_LIST_SIZE BLE_PREP_WRITE_X_ATT(CFG_BLE_MAX_ATT_MTU) -#ifndef CFG_BLE_PREPARE_WRITE_LIST_SIZE - #define CFG_BLE_PREPARE_WRITE_LIST_SIZE (0x3A) -#endif +#define CFG_BLE_PREPARE_WRITE_LIST_SIZE BLE_PREP_WRITE_X_ATT(CFG_BLE_MAX_ATT_MTU) /** * Number of allocated memory blocks * This parameter is overwritten by the CPU2 with an hardcoded optimal value when the parameter CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set */ -// #define CFG_BLE_MBLOCK_COUNT (BLE_MBLOCKS_CALC(CFG_BLE_PREPARE_WRITE_LIST_SIZE, CFG_BLE_MAX_ATT_MTU, CFG_BLE_NUM_LINK)) -#define CFG_BLE_MBLOCK_COUNT (0x79) +#define CFG_BLE_MBLOCK_COUNT (BLE_MBLOCKS_CALC(CFG_BLE_PREPARE_WRITE_LIST_SIZE, CFG_BLE_MAX_ATT_MTU, CFG_BLE_NUM_LINK)) /** * Enable or disable the Extended Packet length feature. Valid values are 0 or 1. */ -#ifndef CFG_BLE_DATA_LENGTH_EXTENSION - #define CFG_BLE_DATA_LENGTH_EXTENSION 1 -#endif +#define CFG_BLE_DATA_LENGTH_EXTENSION 1 /** * Sleep clock accuracy in Slave mode (ppm value) */ -#ifndef CFG_BLE_SLAVE_SCA - #define CFG_BLE_SLAVE_SCA 500 -#endif +#define CFG_BLE_SLAVE_SCA 500 /** * Sleep clock accuracy in Master mode @@ -139,37 +181,30 @@ * 6 : 21 ppm to 30 ppm * 7 : 0 ppm to 20 ppm */ -#ifndef CFG_BLE_MASTER_SCA - #define CFG_BLE_MASTER_SCA 0 -#endif +#define CFG_BLE_MASTER_SCA 0 /** * LsSource * Some information for Low speed clock mapped in bits field * - bit 0: 1: Calibration for the RF system wakeup clock source 0: No calibration for the RF system wakeup clock source - * - bit 1: 1: STM32W5M Module device 0: Other devices as STM32WBxx SOC, STM32WB1M module - */ -#ifndef CFG_BLE_LSE_SOURCE - #if defined(STM32WB5Mxx) - #define CFG_BLE_LSE_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LSE_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LSE_MOD5MM_DEV) - #else - #define CFG_BLE_LSE_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LSE_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LSE_OTHER_DEV) - #endif + * - bit 1: 1: STM32WB5M Module device 0: Other devices as STM32WBxx SOC, STM32WB1M module + * - bit 2: 1: HSE/1024 Clock config 0: LSE Clock config + */ +#if defined(STM32WB5Mxx) + #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_MOD5MM_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) +#else + #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_OTHER_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) #endif /** * Start up time of the high speed (16 or 32 MHz) crystal oscillator in units of 625/256 us (~2.44 us) */ -#ifndef CFG_BLE_HSE_STARTUP_TIME - #define CFG_BLE_HSE_STARTUP_TIME 0x148 -#endif +#define CFG_BLE_HSE_STARTUP_TIME 0x148 /** * Maximum duration of the connection event when the device is in Slave mode in units of 625/256 us (~2.44 us) */ -#ifndef CFG_BLE_MAX_CONN_EVENT_LENGTH - #define CFG_BLE_MAX_CONN_EVENT_LENGTH (0xFFFFFFFF) -#endif +#define CFG_BLE_MAX_CONN_EVENT_LENGTH (0xFFFFFFFF) /** * Viterbi Mode @@ -190,8 +225,16 @@ * - SHCI_C2_BLE_INIT_OPTIONS_NO_EXT_ADV * - SHCI_C2_BLE_INIT_OPTIONS_CS_ALGO2 * - SHCI_C2_BLE_INIT_OPTIONS_NO_CS_ALGO2 + * - SHCI_C2_BLE_INIT_OPTIONS_REDUC_GATTDB_NVM + * - SHCI_C2_BLE_INIT_OPTIONS_FULL_GATTDB_NVM + * - SHCI_C2_BLE_INIT_OPTIONS_GATT_CACHING_USED + * - SHCI_C2_BLE_INIT_OPTIONS_GATT_CACHING_NOTUSED * - SHCI_C2_BLE_INIT_OPTIONS_POWER_CLASS_1 * - SHCI_C2_BLE_INIT_OPTIONS_POWER_CLASS_2_3 + * - SHCI_C2_BLE_INIT_OPTIONS_APPEARANCE_WRITABLE + * - SHCI_C2_BLE_INIT_OPTIONS_APPEARANCE_READONLY + * - SHCI_C2_BLE_INIT_OPTIONS_ENHANCED_ATT_SUPPORTED + * - SHCI_C2_BLE_INIT_OPTIONS_ENHANCED_ATT_NOTSUPPORTED * which are used to set following configuration bits: * (bit 0): 1: LL only * 0: LL + host @@ -203,11 +246,19 @@ * 0: extended advertizing not supported * (bit 4): 1: CS Algo #2 supported * 0: CS Algo #2 not supported + * (bit 5): 1: Reduced GATT database in NVM + * 0: Full GATT database in NVM + * (bit 6): 1: GATT caching is used + * 0: GATT caching is not used * (bit 7): 1: LE Power Class 1 * 0: LE Power Class 2-3 + * (bit 8): 1: appearance Writable + * 0: appearance Read-Only + * (bit 9): 1: Enhanced ATT supported + * 0: Enhanced ATT not supported * other bits: reserved (shall be set to 0) */ -#define CFG_BLE_OPTIONS (SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY) +#define CFG_BLE_OPTIONS (SHCI_C2_BLE_INIT_OPTIONS_LL_HOST | SHCI_C2_BLE_INIT_OPTIONS_WITH_SVC_CHANGE_DESC | SHCI_C2_BLE_INIT_OPTIONS_DEVICE_NAME_RW | SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV | SHCI_C2_BLE_INIT_OPTIONS_CS_ALGO2 | SHCI_C2_BLE_INIT_OPTIONS_FULL_GATTDB_NVM | SHCI_C2_BLE_INIT_OPTIONS_GATT_CACHING_NOTUSED | SHCI_C2_BLE_INIT_OPTIONS_POWER_CLASS_2_3 | SHCI_C2_BLE_INIT_OPTIONS_APPEARANCE_READONLY | SHCI_C2_BLE_INIT_OPTIONS_ENHANCED_ATT_NOTSUPPORTED) #define CFG_BLE_MAX_COC_INITIATOR_NBR (32) @@ -257,5 +308,348 @@ #define CFG_BLE_RX_PATH_COMPENS (0) -#endif /* APP_CONF_DEFAULT_H */ + /* BLE core version (16-bit signed integer). + * - SHCI_C2_BLE_INIT_BLE_CORE_5_2 + * - SHCI_C2_BLE_INIT_BLE_CORE_5_3 + * which are used to set: 11(5.2), 12(5.3). + */ + +#define CFG_BLE_CORE_VERSION (SHCI_C2_BLE_INIT_BLE_CORE_5_3) + +/****************************************************************************** + * Transport Layer + ******************************************************************************/ +/** + * Queue length of BLE Event + * This parameter defines the number of asynchronous events that can be stored in the HCI layer before + * being reported to the application. When a command is sent to the BLE core coprocessor, the HCI layer + * is waiting for the event with the Num_HCI_Command_Packets set to 1. The receive queue shall be large + * enough to store all asynchronous events received in between. + * When CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE is set to 27, this allow to store three 255 bytes long asynchronous events + * between the HCI command and its event. + * This parameter depends on the value given to CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE. When the queue size is to small, + * the system may hang if the queue is full with asynchronous events and the HCI layer is still waiting + * for a CC/CS event, In that case, the notification TL_BLE_HCI_ToNot() is called to indicate + * to the application a HCI command did not receive its command event within 30s (Default HCI Timeout). + */ +#define CFG_TLBLE_EVT_QUEUE_LENGTH 5 +/** + * This parameter should be set to fit most events received by the HCI layer. It defines the buffer size of each element + * allocated in the queue of received events and can be used to optimize the amount of RAM allocated by the Memory Manager. + * It should not exceed 255 which is the maximum HCI packet payload size (a greater value is a lost of memory as it will + * never be used) + * It shall be at least 4 to receive the command status event in one frame. + * The default value is set to 27 to allow receiving an event of MTU size in a single buffer. This value maybe reduced + * further depending on the application. + */ +#define CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE 255 /**< Set to 255 with the memory manager and the mailbox */ + +#define TL_BLE_EVENT_FRAME_SIZE ( TL_EVT_HDR_SIZE + CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE ) +/****************************************************************************** + * UART interfaces + ******************************************************************************/ + +/** + * Select UART interfaces + */ +#define CFG_UART_GUI hw_uart1 +#define CFG_DEBUG_TRACE_UART 0 +/****************************************************************************** + * USB interface + ******************************************************************************/ + +/** + * Enable/Disable USB interface + */ +#define CFG_USB_INTERFACE_ENABLE 0 + +/****************************************************************************** + * IPCC interface + ******************************************************************************/ + +/** + * The IPCC is dedicated to the communication between the CPU2 and the CPU1 + * and shall not be modified by the application + * The two following definitions shall not be modified + */ +#define HAL_IPCC_TX_IRQHandler(...) HW_IPCC_Tx_Handler( ) +#define HAL_IPCC_RX_IRQHandler(...) HW_IPCC_Rx_Handler( ) + +/****************************************************************************** + * Low Power + ******************************************************************************/ +/** + * When set to 1, the low power mode is enable + * When set to 0, the device stays in RUN mode + */ +#define CFG_LPM_SUPPORTED 1 + +/****************************************************************************** + * RTC interface + ******************************************************************************/ +#define HAL_RTCEx_WakeUpTimerIRQHandler(...) HW_TS_RTC_Wakeup_Handler( ) + +/****************************************************************************** + * Timer Server + ******************************************************************************/ +/** + * CFG_RTC_WUCKSEL_DIVIDER: This sets the RTCCLK divider to the wakeup timer. + * The lower is the value, the better is the power consumption and the accuracy of the timerserver + * The higher is the value, the finest is the granularity + * + * CFG_RTC_ASYNCH_PRESCALER: This sets the asynchronous prescaler of the RTC. It should as high as possible ( to output + * clock as low as possible) but the output clock should be equal or higher frequency compare to the clock feeding + * the wakeup timer. A lower clock speed would impact the accuracy of the timer server. + * + * CFG_RTC_SYNCH_PRESCALER: This sets the synchronous prescaler of the RTC. + * When the 1Hz calendar clock is required, it shall be sets according to other settings + * When the 1Hz calendar clock is not needed, CFG_RTC_SYNCH_PRESCALER should be set to 0x7FFF (MAX VALUE) + * + * CFG_RTCCLK_DIVIDER_CONF: + * Shall be set to either 0,2,4,8,16 + * When set to either 2,4,8,16, the 1Hhz calendar is supported + * When set to 0, the user sets its own configuration + * + * The following settings are computed with LSI as input to the RTC + */ + +#define CFG_RTCCLK_DIVIDER_CONF 0 + +#if (CFG_RTCCLK_DIVIDER_CONF == 0) +/** + * Custom configuration + * It does not support 1Hz calendar + * It divides the RTC CLK by 16 + */ + +#define CFG_RTCCLK_DIV (16) +#define CFG_RTC_WUCKSEL_DIVIDER (0) +#define CFG_RTC_ASYNCH_PRESCALER (0x0F) +#define CFG_RTC_SYNCH_PRESCALER (0x7FFF) + +#else + +#if (CFG_RTCCLK_DIVIDER_CONF == 2) +/** + * It divides the RTC CLK by 2 + */ +#define CFG_RTC_WUCKSEL_DIVIDER (3) +#endif + +#if (CFG_RTCCLK_DIVIDER_CONF == 4) +/** + * It divides the RTC CLK by 4 + */ +#define CFG_RTC_WUCKSEL_DIVIDER (2) +#endif + +#if (CFG_RTCCLK_DIVIDER_CONF == 8) +/** + * It divides the RTC CLK by 8 + */ +#define CFG_RTC_WUCKSEL_DIVIDER (1) +#endif + +#if (CFG_RTCCLK_DIVIDER_CONF == 16) +/** + * It divides the RTC CLK by 16 + */ +#define CFG_RTC_WUCKSEL_DIVIDER (0) +#endif + +#define CFG_RTCCLK_DIV CFG_RTCCLK_DIVIDER_CONF +#define CFG_RTC_ASYNCH_PRESCALER (CFG_RTCCLK_DIV - 1) +#define CFG_RTC_SYNCH_PRESCALER (DIVR( LSE_VALUE, (CFG_RTC_ASYNCH_PRESCALER+1) ) - 1 ) + +#endif + +/** tick timer values */ +#define CFG_TS_TICK_VAL DIVR( (CFG_RTCCLK_DIV * 1000000), LSE_VALUE ) +#define CFG_TS_TICK_VAL_PS DIVR( ((uint64_t)CFG_RTCCLK_DIV * 1e12), (uint64_t)LSE_VALUE ) + +typedef enum +{ + CFG_TIM_PROC_ID_ISR, + /* USER CODE BEGIN CFG_TimProcID_t */ + + /* USER CODE END CFG_TimProcID_t */ +} CFG_TimProcID_t; + +/****************************************************************************** + * Debug + ******************************************************************************/ +/** + * When set, this resets some hw resources to set the device in the same state than the power up + * The FW resets only register that may prevent the FW to run properly + * + * This shall be set to 0 in a final product + * + */ +#define CFG_HW_RESET_BY_FW 1 + +/** + * keep debugger enabled while in any low power mode when set to 1 + * should be set to 0 in production + */ +#define CFG_DEBUGGER_SUPPORTED 0 + +/** + * When set to 1, the traces are enabled in the BLE services + */ +#define CFG_DEBUG_BLE_TRACE 0 + +/** + * Enable or Disable traces in application + */ +#define CFG_DEBUG_APP_TRACE 0 + +#if (CFG_DEBUG_APP_TRACE != 0) +#define APP_DBG_MSG PRINT_MESG_DBG +#else +#define APP_DBG_MSG PRINT_NO_MESG +#endif + +#if ( (CFG_DEBUG_BLE_TRACE != 0) || (CFG_DEBUG_APP_TRACE != 0) ) +#define CFG_DEBUG_TRACE 1 +#endif + +#if (CFG_DEBUG_TRACE != 0) +#undef CFG_LPM_SUPPORTED +#undef CFG_DEBUGGER_SUPPORTED +#define CFG_LPM_SUPPORTED 0 +#define CFG_DEBUGGER_SUPPORTED 1 +#endif + +/** + * When CFG_DEBUG_TRACE_FULL is set to 1, the trace are output with the API name, the file name and the line number + * When CFG_DEBUG_TRACE_LIGHT is set to 1, only the debug message is output + * + * When both are set to 0, no trace are output + * When both are set to 1, CFG_DEBUG_TRACE_FULL is selected + */ +#define CFG_DEBUG_TRACE_LIGHT 0 +#define CFG_DEBUG_TRACE_FULL 0 + +#if (( CFG_DEBUG_TRACE != 0 ) && ( CFG_DEBUG_TRACE_LIGHT == 0 ) && (CFG_DEBUG_TRACE_FULL == 0)) +#undef CFG_DEBUG_TRACE_FULL +#undef CFG_DEBUG_TRACE_LIGHT +#define CFG_DEBUG_TRACE_FULL 0 +#define CFG_DEBUG_TRACE_LIGHT 1 +#endif + +#if ( CFG_DEBUG_TRACE == 0 ) +#undef CFG_DEBUG_TRACE_FULL +#undef CFG_DEBUG_TRACE_LIGHT +#define CFG_DEBUG_TRACE_FULL 0 +#define CFG_DEBUG_TRACE_LIGHT 0 +#endif + +/** + * When not set, the traces is looping on sending the trace over UART + */ +#define DBG_TRACE_USE_CIRCULAR_QUEUE 1 + +/** + * max buffer Size to queue data traces and max data trace allowed. + * Only Used if DBG_TRACE_USE_CIRCULAR_QUEUE is defined + */ +#define DBG_TRACE_MSG_QUEUE_SIZE 4096 +#define MAX_DBG_TRACE_MSG_SIZE 1024 + +/* USER CODE BEGIN Defines */ +#define CFG_LED_SUPPORTED 1 +#define CFG_BUTTON_SUPPORTED 1 + +#define PUSH_BUTTON_SW1_EXTI_IRQHandler EXTI4_IRQHandler +#define PUSH_BUTTON_SW2_EXTI_IRQHandler EXTI0_IRQHandler +#define PUSH_BUTTON_SW3_EXTI_IRQHandler EXTI1_IRQHandler +/* USER CODE END Defines */ + +/****************************************************************************** + * Scheduler + ******************************************************************************/ + +/** + * These are the lists of task id registered to the scheduler + * Each task id shall be in the range [0:31] + * This mechanism allows to implement a generic code in the API TL_BLE_HCI_StatusNot() to comply with + * the requirement that a HCI/ACI command shall never be sent if there is already one pending + */ + +/**< Add in that list all tasks that may send a ACI/HCI command */ +typedef enum +{ + CFG_TASK_BLE_HCI_CMD_ID, + CFG_TASK_SYS_HCI_CMD_ID, + CFG_TASK_HCI_ACL_DATA_ID, + CFG_TASK_SYS_LOCAL_CMD_ID, + CFG_TASK_TX_TO_HOST_ID, + /* USER CODE BEGIN CFG_Task_Id_With_HCI_Cmd_t */ + CFG_TASK_SW1_BUTTON_PUSHED_ID, + CFG_TASK_SW2_BUTTON_PUSHED_ID, + CFG_TASK_SW3_BUTTON_PUSHED_ID, + /* USER CODE END CFG_Task_Id_With_HCI_Cmd_t */ + CFG_LAST_TASK_ID_WITH_HCICMD, /**< Shall be LAST in the list */ +} CFG_Task_Id_With_HCI_Cmd_t; + +/**< Add in that list all tasks that never send a ACI/HCI command */ +typedef enum +{ + CFG_FIRST_TASK_ID_WITH_NO_HCICMD = CFG_LAST_TASK_ID_WITH_HCICMD - 1, /**< Shall be FIRST in the list */ + CFG_TASK_SYSTEM_HCI_ASYNCH_EVT_ID, + /* USER CODE BEGIN CFG_Task_Id_With_NO_HCI_Cmd_t */ + + /* USER CODE END CFG_Task_Id_With_NO_HCI_Cmd_t */ + CFG_LAST_TASK_ID_WITH_NO_HCICMD /**< Shall be LAST in the list */ +} CFG_Task_Id_With_NO_HCI_Cmd_t; + +#define CFG_TASK_NBR CFG_LAST_TASK_ID_WITH_NO_HCICMD + +/** + * This is the list of priority required by the application + * Each Id shall be in the range 0..31 + */ +typedef enum +{ + CFG_SCH_PRIO_0, + /* USER CODE BEGIN CFG_SCH_Prio_Id_t */ + + /* USER CODE END CFG_SCH_Prio_Id_t */ +} CFG_SCH_Prio_Id_t; + +/** + * This is a bit mapping over 32bits listing all events id supported in the application + */ +typedef enum +{ + CFG_IDLEEVT_SYSTEM_HCI_CMD_EVT_RSP_ID, + /* USER CODE BEGIN CFG_IdleEvt_Id_t */ + + /* USER CODE END CFG_IdleEvt_Id_t */ +} CFG_IdleEvt_Id_t; + +/****************************************************************************** + * LOW POWER + ******************************************************************************/ +/** + * Supported requester to the MCU Low Power Manager - can be increased up to 32 + * It list a bit mapping of all user of the Low Power Manager + */ +typedef enum +{ + CFG_LPM_APP, + CFG_LPM_APP_BLE, + /* USER CODE BEGIN CFG_LPM_Id_t */ + + /* USER CODE END CFG_LPM_Id_t */ +} CFG_LPM_Id_t; + +/****************************************************************************** + * OTP manager + ******************************************************************************/ +#define CFG_OTP_BASE_ADDRESS OTP_AREA_BASE + +#define CFG_OTP_END_ADRESS OTP_AREA_END_ADDR + +#endif /*APP_CONF_H */ diff --git a/src/utility/STM32Cube_FW/ble_bufsize.h b/src/utility/STM32Cube_FW/ble_bufsize.h index 247573be..4269fa43 100644 --- a/src/utility/STM32Cube_FW/ble_bufsize.h +++ b/src/utility/STM32Cube_FW/ble_bufsize.h @@ -75,16 +75,9 @@ ((pw) + MAX(BLE_MEM_BLOCK_X_MTU(mtu, n_link), \ BLE_MBLOCKS_SECURE_CONNECTIONS)) -/* - * BLE_DEFAULT_MBLOCKS_COUNT: default memory blocks count - */ -#define BLE_DEFAULT_MBLOCKS_COUNT(n_link) \ - BLE_MBLOCKS_CALC(BLE_DEFAULT_PREP_WRITE_LIST_SIZE, \ - BLE_DEFAULT_MAX_ATT_MTU, n_link) - /* * BLE_FIXED_BUFFER_SIZE_BYTES: - * A part of the RAM, is dynamically allocated by initializing all the pointers + * A part of the RAM, is dynamically allocated by initializing all the pointers * defined in a global context variable "mem_alloc_ctx_p". * This initialization is made in the Dynamic_allocator functions, which * assign a portion of RAM given by the external application to the above @@ -92,39 +85,39 @@ * * The size of this Dynamic RAM is made of 2 main components: * - a part that is parameters-dependent (num of links, GATT buffers, ...), - * and which value is defined by the following macro; + * and which value is made explicit by the following macro; * - a part, that may be considered "fixed", i.e. independent from the above * mentioned parameters. */ #if (BEACON_ONLY != 0) -#define BLE_FIXED_BUFFER_SIZE_BYTES 4076 /* Beacon only */ +#define BLE_FIXED_BUFFER_SIZE_BYTES 4092 /* Beacon only */ #elif (LL_ONLY_BASIC != 0) -#define BLE_FIXED_BUFFER_SIZE_BYTES 5692 /* LL only Basic*/ +#define BLE_FIXED_BUFFER_SIZE_BYTES 5788 /* LL only Basic*/ #elif (LL_ONLY != 0) -#define BLE_FIXED_BUFFER_SIZE_BYTES 5940 /* LL only Full */ +#define BLE_FIXED_BUFFER_SIZE_BYTES 6036 /* LL only Full */ #elif (SLAVE_ONLY != 0) -#define BLE_FIXED_BUFFER_SIZE_BYTES 6204 /* Peripheral only */ +#define BLE_FIXED_BUFFER_SIZE_BYTES 6292 /* Peripheral only */ #elif (BASIC_FEATURES != 0) -#define BLE_FIXED_BUFFER_SIZE_BYTES 6532 /* Basic Features */ +#define BLE_FIXED_BUFFER_SIZE_BYTES 6624 /* Basic Features */ #else -#define BLE_FIXED_BUFFER_SIZE_BYTES 7056 /* Full stack */ +#define BLE_FIXED_BUFFER_SIZE_BYTES 7144 /* Full stack */ #endif /* * BLE_PER_LINK_SIZE_BYTES: additional memory size used per link */ #if (BEACON_ONLY != 0) -#define BLE_PER_LINK_SIZE_BYTES 128 /* Beacon only */ +#define BLE_PER_LINK_SIZE_BYTES 112 /* Beacon only */ #elif (LL_ONLY_BASIC != 0) -#define BLE_PER_LINK_SIZE_BYTES 260 /* LL only Basic */ +#define BLE_PER_LINK_SIZE_BYTES 244 /* LL only Basic */ #elif (LL_ONLY != 0) -#define BLE_PER_LINK_SIZE_BYTES 260 /* LL only Full */ +#define BLE_PER_LINK_SIZE_BYTES 244 /* LL only Full */ #elif (SLAVE_ONLY != 0) -#define BLE_PER_LINK_SIZE_BYTES 392 /* Peripheral only */ +#define BLE_PER_LINK_SIZE_BYTES 336 /* Peripheral only */ #elif (BASIC_FEATURES != 0) -#define BLE_PER_LINK_SIZE_BYTES 440 /* Basic Features */ +#define BLE_PER_LINK_SIZE_BYTES 412 /* Basic Features */ #else -#define BLE_PER_LINK_SIZE_BYTES 444 /* Full stack */ +#define BLE_PER_LINK_SIZE_BYTES 424 /* Full stack */ #endif /* @@ -155,7 +148,7 @@ * Valid values are from 31 to 1650. */ #define BLE_EXT_ADV_BUFFER_SIZE(set_nbr, data_len) \ - (2304 + ((892 + (DIVC(data_len, 207) * 244)) * (set_nbr))) + (2512 + ((892 + (DIVC(data_len, 207) * 244)) * (set_nbr))) /* * BLE_TOTAL_BUFFER_SIZE_GATT: this macro returns the amount of memory, diff --git a/src/utility/STM32Cube_FW/hw.h b/src/utility/STM32Cube_FW/hw.h index fcf04517..503fa2ca 100644 --- a/src/utility/STM32Cube_FW/hw.h +++ b/src/utility/STM32Cube_FW/hw.h @@ -26,21 +26,14 @@ extern "C" { #endif /* Includes ------------------------------------------------------------------*/ -#include "stm32_def.h" -#include "stm32wbxx_ll_bus.h" -#include "stm32wbxx_ll_exti.h" -#include "stm32wbxx_ll_system.h" -#include "stm32wbxx_ll_rcc.h" -#include "stm32wbxx_ll_ipcc.h" -#include "stm32wbxx_ll_cortex.h" -#include "stm32wbxx_ll_utils.h" -#include "stm32wbxx_ll_pwr.h" /****************************************************************************** * HW IPCC ******************************************************************************/ void HW_IPCC_Enable( void ); void HW_IPCC_Init( void ); + void HW_IPCC_Rx_Handler( void ); + void HW_IPCC_Tx_Handler( void ); void HW_IPCC_BLE_Init( void ); void HW_IPCC_BLE_SendCmd( void ); @@ -87,6 +80,23 @@ extern "C" { void HW_IPCC_TRACES_Init( void ); void HW_IPCC_TRACES_EvtNot( void ); + void HW_IPCC_MAC_802_15_4_Init( void ); + void HW_IPCC_MAC_802_15_4_SendCmd( void ); + void HW_IPCC_MAC_802_15_4_SendAck( void ); + void HW_IPCC_MAC_802_15_4_CmdEvtNot( void ); + void HW_IPCC_MAC_802_15_4_EvtNot( void ); + + void HW_IPCC_ZIGBEE_Init( void ); + + void HW_IPCC_ZIGBEE_SendM4RequestToM0(void); /* M4 Request to M0 */ + void HW_IPCC_ZIGBEE_RecvAppliAckFromM0(void); /* Request ACK from M0 */ + + void HW_IPCC_ZIGBEE_RecvM0NotifyToM4(void); /* M0 Notify to M4 */ + void HW_IPCC_ZIGBEE_SendM4AckToM0Notify(void); /* Notify ACK from M4 */ + void HW_IPCC_ZIGBEE_RecvM0RequestToM4(void); /* M0 Request to M4 */ + void HW_IPCC_ZIGBEE_SendM4AckToM0Request(void); /* Request ACK from M4 */ + + #ifdef __cplusplus } #endif diff --git a/src/utility/STM32Cube_FW/hw_ipcc.c b/src/utility/STM32Cube_FW/hw_ipcc.c index 7b9be81a..fd620b85 100644 --- a/src/utility/STM32Cube_FW/hw_ipcc.c +++ b/src/utility/STM32Cube_FW/hw_ipcc.c @@ -18,9 +18,8 @@ */ /* USER CODE END Header */ -#if defined(STM32WBxx) /* Includes ------------------------------------------------------------------*/ -#include "hw.h" +#include "app_common.h" #include "mbox_def.h" /* Global variables ---------------------------------------------------------*/ @@ -57,17 +56,34 @@ static void HW_IPCC_LLD_BLE_ReceiveRspHandler( void ); static void HW_IPCC_LLD_BLE_ReceiveM0CmdHandler( void ); #endif +#ifdef MAC_802_15_4_WB +static void HW_IPCC_MAC_802_15_4_CmdEvtHandler( void ); +static void HW_IPCC_MAC_802_15_4_NotEvtHandler( void ); +#endif + +#ifdef ZIGBEE_WB +static void HW_IPCC_ZIGBEE_CmdEvtHandler( void ); +static void HW_IPCC_ZIGBEE_StackNotifEvtHandler( void ); +static void HW_IPCC_ZIGBEE_StackM0RequestHandler( void ); +#endif + /* Public function definition -----------------------------------------------*/ /****************************************************************************** * INTERRUPT HANDLER ******************************************************************************/ -void IPCC_C1_RX_IRQHandler(void) +void HW_IPCC_Rx_Handler( void ) { if (HW_IPCC_RX_PENDING( HW_IPCC_SYSTEM_EVENT_CHANNEL )) { HW_IPCC_SYS_EvtHandler(); } +#ifdef MAC_802_15_4_WB + else if (HW_IPCC_RX_PENDING( HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL )) + { + HW_IPCC_MAC_802_15_4_NotEvtHandler(); + } +#endif /* MAC_802_15_4_WB */ #ifdef THREAD_WB else if (HW_IPCC_RX_PENDING( HW_IPCC_THREAD_NOTIFICATION_ACK_CHANNEL )) { @@ -98,6 +114,16 @@ void IPCC_C1_RX_IRQHandler(void) HW_IPCC_LLD_BLE_ReceiveM0CmdHandler(); } #endif /* LLD_TESTS_WB */ +#ifdef ZIGBEE_WB + else if (HW_IPCC_RX_PENDING( HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL )) + { + HW_IPCC_ZIGBEE_StackNotifEvtHandler(); + } + else if (HW_IPCC_RX_PENDING( HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL )) + { + HW_IPCC_ZIGBEE_StackM0RequestHandler(); + } +#endif /* ZIGBEE_WB */ else if (HW_IPCC_RX_PENDING( HW_IPCC_BLE_EVENT_CHANNEL )) { HW_IPCC_BLE_EvtHandler(); @@ -106,14 +132,22 @@ void IPCC_C1_RX_IRQHandler(void) { HW_IPCC_TRACES_EvtHandler(); } + + return; } -void IPCC_C1_TX_IRQHandler(void) +void HW_IPCC_Tx_Handler( void ) { if (HW_IPCC_TX_PENDING( HW_IPCC_SYSTEM_CMD_RSP_CHANNEL )) { HW_IPCC_SYS_CmdEvtHandler(); } +#ifdef MAC_802_15_4_WB + else if (HW_IPCC_TX_PENDING( HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL )) + { + HW_IPCC_MAC_802_15_4_CmdEvtHandler(); + } +#endif /* MAC_802_15_4_WB */ #ifdef THREAD_WB else if (HW_IPCC_TX_PENDING( HW_IPCC_THREAD_OT_CMD_RSP_CHANNEL )) { @@ -123,6 +157,12 @@ void IPCC_C1_TX_IRQHandler(void) #ifdef LLD_TESTS_WB // No TX handler for LLD tests #endif /* LLD_TESTS_WB */ +#ifdef ZIGBEE_WB + if (HW_IPCC_TX_PENDING( HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL )) + { + HW_IPCC_ZIGBEE_CmdEvtHandler(); + } +#endif /* ZIGBEE_WB */ else if (HW_IPCC_TX_PENDING( HW_IPCC_MM_RELEASE_BUFFER_CHANNEL )) { HW_IPCC_MM_FreeBufHandler(); @@ -131,8 +171,9 @@ void IPCC_C1_TX_IRQHandler(void) { HW_IPCC_BLE_AclDataEvtHandler(); } -} + return; +} /****************************************************************************** * GENERAL ******************************************************************************/ @@ -223,8 +264,8 @@ static void HW_IPCC_BLE_AclDataEvtHandler( void ) return; } -__WEAK void HW_IPCC_BLE_AclDataAckNot( void ){}; -__WEAK void HW_IPCC_BLE_RxEvtNot( void ){}; +__weak void HW_IPCC_BLE_AclDataAckNot( void ){}; +__weak void HW_IPCC_BLE_RxEvtNot( void ){}; /****************************************************************************** * SYSTEM @@ -262,8 +303,56 @@ static void HW_IPCC_SYS_EvtHandler( void ) return; } -__WEAK void HW_IPCC_SYS_CmdEvtNot( void ){}; -__WEAK void HW_IPCC_SYS_EvtNot( void ){}; +__weak void HW_IPCC_SYS_CmdEvtNot( void ){}; +__weak void HW_IPCC_SYS_EvtNot( void ){}; + +/****************************************************************************** + * MAC 802.15.4 + ******************************************************************************/ +#ifdef MAC_802_15_4_WB +void HW_IPCC_MAC_802_15_4_Init( void ) +{ + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL ); + + return; +} + +void HW_IPCC_MAC_802_15_4_SendCmd( void ) +{ + LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL ); + LL_C1_IPCC_EnableTransmitChannel( IPCC, HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL ); + + return; +} + +void HW_IPCC_MAC_802_15_4_SendAck( void ) +{ + LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL ); + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL ); + + return; +} + +static void HW_IPCC_MAC_802_15_4_CmdEvtHandler( void ) +{ + LL_C1_IPCC_DisableTransmitChannel( IPCC, HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL ); + + HW_IPCC_MAC_802_15_4_CmdEvtNot(); + + return; +} + +static void HW_IPCC_MAC_802_15_4_NotEvtHandler( void ) +{ + LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL ); + + HW_IPCC_MAC_802_15_4_EvtNot(); + + return; +} +__weak void HW_IPCC_MAC_802_15_4_CmdEvtNot( void ){}; +__weak void HW_IPCC_MAC_802_15_4_EvtNot( void ){}; +#endif /****************************************************************************** * THREAD @@ -335,9 +424,9 @@ static void HW_IPCC_THREAD_CliNotEvtHandler( void ) return; } -__WEAK void HW_IPCC_OT_CmdEvtNot( void ){}; -__WEAK void HW_IPCC_CLI_CmdEvtNot( void ){}; -__WEAK void HW_IPCC_THREAD_EvtNot( void ){}; +__weak void HW_IPCC_OT_CmdEvtNot( void ){}; +__weak void HW_IPCC_CLI_CmdEvtNot( void ){}; +__weak void HW_IPCC_THREAD_EvtNot( void ){}; #endif /* THREAD_WB */ @@ -459,6 +548,74 @@ void HW_IPCC_LLD_BLE_SendRspAck( void ) #endif /* LLD_BLE_WB */ +/****************************************************************************** + * ZIGBEE + ******************************************************************************/ +#ifdef ZIGBEE_WB +void HW_IPCC_ZIGBEE_Init( void ) +{ + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL ); + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL ); + + return; +} + +void HW_IPCC_ZIGBEE_SendM4RequestToM0( void ) +{ + LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL ); + LL_C1_IPCC_EnableTransmitChannel( IPCC, HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL ); + + return; +} + +void HW_IPCC_ZIGBEE_SendM4AckToM0Notify( void ) +{ + LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL ); + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL ); + + return; +} + +static void HW_IPCC_ZIGBEE_CmdEvtHandler( void ) +{ + LL_C1_IPCC_DisableTransmitChannel( IPCC, HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL ); + + HW_IPCC_ZIGBEE_RecvAppliAckFromM0(); + + return; +} + +static void HW_IPCC_ZIGBEE_StackNotifEvtHandler( void ) +{ + LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL ); + + HW_IPCC_ZIGBEE_RecvM0NotifyToM4(); + + return; +} + +static void HW_IPCC_ZIGBEE_StackM0RequestHandler( void ) +{ + LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL ); + + HW_IPCC_ZIGBEE_RecvM0RequestToM4(); + + return; +} + +void HW_IPCC_ZIGBEE_SendM4AckToM0Request( void ) +{ + LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL ); + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL ); + + return; +} + +__weak void HW_IPCC_ZIGBEE_RecvAppliAckFromM0( void ){}; +__weak void HW_IPCC_ZIGBEE_RecvM0NotifyToM4( void ){}; +__weak void HW_IPCC_ZIGBEE_RecvM0RequestToM4( void ){}; +#endif /* ZIGBEE_WB */ + /****************************************************************************** * MEMORY MANAGER ******************************************************************************/ @@ -509,5 +666,4 @@ static void HW_IPCC_TRACES_EvtHandler( void ) return; } -__WEAK void HW_IPCC_TRACES_EvtNot( void ){}; -#endif /* STM32WBxx */ +__weak void HW_IPCC_TRACES_EvtNot( void ){}; diff --git a/src/utility/STM32Cube_FW/mbox_def.h b/src/utility/STM32Cube_FW/mbox_def.h index 0c974f8f..68b71f9c 100644 --- a/src/utility/STM32Cube_FW/mbox_def.h +++ b/src/utility/STM32Cube_FW/mbox_def.h @@ -106,6 +106,12 @@ extern "C" { uint8_t *m0cmd_buffer; } MB_BleLldTable_t; + typedef struct + { + uint8_t *notifM0toM4_buffer; + uint8_t *appliCmdM4toM0_buffer; + uint8_t *requestM0toM4_buffer; + } MB_ZigbeeTable_t; /** * msg * [0:7] = cmd/evt @@ -133,6 +139,13 @@ extern "C" { uint8_t *traces_queue; } MB_TracesTable_t; + typedef struct + { + uint8_t *p_cmdrsp_buffer; + uint8_t *p_notack_buffer; + uint8_t *evt_queue; + } MB_Mac_802_15_4_t; + typedef struct { MB_DeviceInfoTable_t *p_device_info_table; @@ -141,6 +154,8 @@ extern "C" { MB_SysTable_t *p_sys_table; MB_MemManagerTable_t *p_mem_manager_table; MB_TracesTable_t *p_traces_table; + MB_Mac_802_15_4_t *p_mac_802_15_4_table; + MB_ZigbeeTable_t *p_zigbee_table; MB_LldTestsTable_t *p_lld_tests_table; MB_BleLldTable_t *p_ble_lld_table; } MB_RefTable_t; @@ -184,6 +199,15 @@ typedef struct * | | * |<---HW_IPCC_SYSTEM_EVENT_CHANNEL-----------------| * | | + * | (ZIGBEE) | + * |----HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL------------>| + * | | + * |----HW_IPCC_ZIGBEE_CMD_CLI_CHANNEL-------------->| + * | | + * |<---HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL-------| + * | | + * |<---HW_IPCC_ZIGBEE_CLI_NOTIF_ACK_CHANNEL---------| + * | | * | (THREAD) | * |----HW_IPCC_THREAD_OT_CMD_RSP_CHANNEL----------->| * | | @@ -207,6 +231,11 @@ typedef struct * | | * |<---HW_IPCC_BLE_LLD_M0_CMD_CHANNEL---------------| * | | + * | (MAC) | + * |----HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL-------->| + * | | + * |<---HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL| + * | | * | (BUFFER) | * |----HW_IPCC_MM_RELEASE_BUFFER_CHANNE------------>| * | | @@ -224,6 +253,8 @@ typedef struct #define HW_IPCC_BLE_CMD_CHANNEL LL_IPCC_CHANNEL_1 #define HW_IPCC_SYSTEM_CMD_RSP_CHANNEL LL_IPCC_CHANNEL_2 #define HW_IPCC_THREAD_OT_CMD_RSP_CHANNEL LL_IPCC_CHANNEL_3 +#define HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL LL_IPCC_CHANNEL_3 +#define HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL LL_IPCC_CHANNEL_3 #define HW_IPCC_MM_RELEASE_BUFFER_CHANNEL LL_IPCC_CHANNEL_4 #define HW_IPCC_THREAD_CLI_CMD_CHANNEL LL_IPCC_CHANNEL_5 #define HW_IPCC_LLDTESTS_CLI_CMD_CHANNEL LL_IPCC_CHANNEL_5 @@ -235,6 +266,8 @@ typedef struct #define HW_IPCC_BLE_EVENT_CHANNEL LL_IPCC_CHANNEL_1 #define HW_IPCC_SYSTEM_EVENT_CHANNEL LL_IPCC_CHANNEL_2 #define HW_IPCC_THREAD_NOTIFICATION_ACK_CHANNEL LL_IPCC_CHANNEL_3 +#define HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL LL_IPCC_CHANNEL_3 +#define HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL LL_IPCC_CHANNEL_3 #define HW_IPCC_LLDTESTS_M0_CMD_CHANNEL LL_IPCC_CHANNEL_3 #define HW_IPCC_BLE_LLD_M0_CMD_CHANNEL LL_IPCC_CHANNEL_3 #define HW_IPCC_TRACES_CHANNEL LL_IPCC_CHANNEL_4 @@ -242,5 +275,6 @@ typedef struct #define HW_IPCC_LLDTESTS_CLI_RSP_CHANNEL LL_IPCC_CHANNEL_5 #define HW_IPCC_BLE_LLD_CLI_RSP_CHANNEL LL_IPCC_CHANNEL_5 #define HW_IPCC_BLE_LLD_RSP_CHANNEL LL_IPCC_CHANNEL_5 +#define HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL LL_IPCC_CHANNEL_5 #endif /*__MBOX_H */ diff --git a/src/utility/STM32Cube_FW/shci.c b/src/utility/STM32Cube_FW/shci.c index a8475222..301db76d 100644 --- a/src/utility/STM32Cube_FW/shci.c +++ b/src/utility/STM32Cube_FW/shci.c @@ -16,7 +16,7 @@ ****************************************************************************** */ -#if defined(STM32WBxx) + /* Includes ------------------------------------------------------------------*/ #include "stm32_wpan_common.h" @@ -352,6 +352,24 @@ SHCI_CmdStatus_t SHCI_C2_BLE_LLD_Init( uint8_t param_size, uint8_t * p_param ) return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); } +SHCI_CmdStatus_t SHCI_C2_ZIGBEE_Init( void ) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send( SHCI_OPCODE_C2_ZIGBEE_INIT, + 0, + 0, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + SHCI_CmdStatus_t SHCI_C2_DEBUG_Init( SHCI_C2_DEBUG_Init_Cmd_Packet_t *pCmdPacket ) { /** @@ -509,6 +527,24 @@ SHCI_CmdStatus_t SHCI_C2_RADIO_AllowLowPower( SHCI_C2_FLASH_Ip_t Ip,uint8_t Fla return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); } +SHCI_CmdStatus_t SHCI_C2_MAC_802_15_4_Init( void ) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send( SHCI_OPCODE_C2_MAC_802_15_4_INIT, + 0, + 0, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + SHCI_CmdStatus_t SHCI_C2_Reinit( void ) { /** @@ -703,4 +739,3 @@ SHCI_CmdStatus_t SHCI_GetWirelessFwInfo( WirelessFwInfo_t* pWirelessInfo ) return (SHCI_Success); } -#endif /* STM32WBxx */ diff --git a/src/utility/STM32Cube_FW/shci.h b/src/utility/STM32Cube_FW/shci.h index 040baced..7ca90210 100644 --- a/src/utility/STM32Cube_FW/shci.h +++ b/src/utility/STM32Cube_FW/shci.h @@ -49,6 +49,7 @@ extern "C" { ERR_BLE_INIT = 0, /* This event is currently not reported by the CPU2 */ ERR_THREAD_LLD_FATAL_ERROR = 125, /* The LLD driver used on 802_15_4 detected a fatal error */ ERR_THREAD_UNKNOWN_CMD = 126, /* The command send by the CPU1 to control the Thread stack is unknown */ + ERR_ZIGBEE_UNKNOWN_CMD = 200, /* The command send by the CPU1 to control the Zigbee stack is unknown */ } SCHI_SystemErrCode_t; #define SHCI_EVTCODE ( 0xFF ) @@ -101,7 +102,7 @@ extern "C" { /** * SHCI_SUB_EVT_THREAD_NVM_RAM_UPDATE - * This notifies the CPU1 which part of the 'OT NVM RAM' has been updated so that only the modified + * This notifies the CPU1 which part of the OT NVM RAM has been updated so that only the modified * section could be written in Flash/NVM * StartAddress : Start address of the section that has been modified * Size : Size (in bytes) of the section that has been modified @@ -215,7 +216,9 @@ extern "C" { SHCI_OCF_C2_FLASH_STORE_DATA, SHCI_OCF_C2_FLASH_ERASE_DATA, SHCI_OCF_C2_RADIO_ALLOW_LOW_POWER, + SHCI_OCF_C2_MAC_802_15_4_INIT, SHCI_OCF_C2_REINIT, + SHCI_OCF_C2_ZIGBEE_INIT, SHCI_OCF_C2_LLD_TESTS_INIT, SHCI_OCF_C2_EXTPA_CONFIG, SHCI_OCF_C2_SET_FLASH_ACTIVITY_CONTROL, @@ -492,6 +495,7 @@ extern "C" { * Some information for Low speed clock mapped in bits field * - bit 0: 1: Calibration for the RF system wakeup clock source 0: No calibration for the RF system wakeup clock source * - bit 1: 1: STM32W5M Module device 0: Other devices as STM32WBxx SOC, STM32WB1M module + * - bit 2: 1: HSE/1024 Clock config 0: LSE Clock config */ uint8_t LsSource; @@ -529,7 +533,11 @@ extern "C" { * - bit 2: 1: device name Read-Only 0: device name R/W * - bit 3: 1: extended advertizing supported 0: extended advertizing not supported * - bit 4: 1: CS Algo #2 supported 0: CS Algo #2 not supported - * - bit 7: 1: LE Power Class 1 0: LE Power Classes 2-3 + * - bit 5: 1: Reduced GATT database in NVM 0: Full GATT database in NVM + * - bit 6: 1: GATT caching is used 0: GATT caching is not used + * - bit 7: 1: LE Power Class 1 0: LE Power Classe 2-3 + * - bit 8: 1: appearance Writable 0: appearance Read-Only + * - bit 9: 1: Enhanced ATT supported 0: Enhanced ATT not supported * - other bits: reserved ( shall be set to 0) */ uint8_t Options; @@ -591,6 +599,11 @@ extern "C" { */ int16_t rx_path_compens; + /* BLE core specification version (8-bit unsigned integer). + * values as: 11(5.2), 12(5.3) + */ + uint8_t ble_core_version; + } SHCI_C2_Ble_Init_Cmd_Param_t; typedef PACKED_STRUCT{ @@ -618,22 +631,42 @@ extern "C" { #define SHCI_C2_BLE_INIT_OPTIONS_CS_ALGO2 (1<<4) #define SHCI_C2_BLE_INIT_OPTIONS_NO_CS_ALGO2 (0<<4) +#define SHCI_C2_BLE_INIT_OPTIONS_REDUC_GATTDB_NVM (1<<5) +#define SHCI_C2_BLE_INIT_OPTIONS_FULL_GATTDB_NVM (0<<5) + +#define SHCI_C2_BLE_INIT_OPTIONS_GATT_CACHING_USED (1<<6) +#define SHCI_C2_BLE_INIT_OPTIONS_GATT_CACHING_NOTUSED (0<<6) + #define SHCI_C2_BLE_INIT_OPTIONS_POWER_CLASS_1 (1<<7) #define SHCI_C2_BLE_INIT_OPTIONS_POWER_CLASS_2_3 (0<<7) +#define SHCI_C2_BLE_INIT_OPTIONS_APPEARANCE_WRITABLE (1<<8) +#define SHCI_C2_BLE_INIT_OPTIONS_APPEARANCE_READONLY (0<<8) + +#define SHCI_C2_BLE_INIT_OPTIONS_ENHANCED_ATT_SUPPORTED (1<<9) +#define SHCI_C2_BLE_INIT_OPTIONS_ENHANCED_ATT_NOTSUPPORTED (0<<9) + /** * RX models configuration */ #define SHCI_C2_BLE_INIT_RX_MODEL_AGC_RSSI_LEGACY (0<<0) #define SHCI_C2_BLE_INIT_RX_MODEL_AGC_RSSI_BLOCKER (1<<0) + /** + * BLE core version + */ +#define SHCI_C2_BLE_INIT_BLE_CORE_5_2 11 +#define SHCI_C2_BLE_INIT_BLE_CORE_5_3 12 + /** * LsSource information */ -#define SHCI_C2_BLE_INIT_CFG_BLE_LSE_NOCALIB (0<<0) -#define SHCI_C2_BLE_INIT_CFG_BLE_LSE_CALIB (1<<0) -#define SHCI_C2_BLE_INIT_CFG_BLE_LSE_OTHER_DEV (0<<1) -#define SHCI_C2_BLE_INIT_CFG_BLE_LSE_MOD5MM_DEV (1<<1) +#define SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB (0<<0) +#define SHCI_C2_BLE_INIT_CFG_BLE_LS_CALIB (1<<0) +#define SHCI_C2_BLE_INIT_CFG_BLE_LS_OTHER_DEV (0<<1) +#define SHCI_C2_BLE_INIT_CFG_BLE_LS_MOD5MM_DEV (1<<1) +#define SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE (0<<2) +#define SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_HSE_1024 (1<<2) #define SHCI_OPCODE_C2_THREAD_INIT (( SHCI_OGF << 10) + SHCI_OCF_C2_THREAD_INIT) /** No command parameters */ @@ -645,6 +678,8 @@ extern "C" { { uint8_t thread_config; uint8_t ble_config; + uint8_t mac_802_15_4_config; + uint8_t zigbee_config; } SHCI_C2_DEBUG_TracesConfig_t; typedef PACKED_STRUCT @@ -708,6 +743,8 @@ extern "C" { { BLE_ENABLE, THREAD_ENABLE, + ZIGBEE_ENABLE, + MAC_ENABLE, } SHCI_C2_CONCURRENT_Mode_Param_t; /** No response parameters*/ @@ -730,13 +767,18 @@ extern "C" { { BLE_IP, THREAD_IP, + ZIGBEE_IP, } SHCI_C2_FLASH_Ip_t; /** No response parameters*/ #define SHCI_OPCODE_C2_RADIO_ALLOW_LOW_POWER (( SHCI_OGF << 10) + SHCI_OCF_C2_RADIO_ALLOW_LOW_POWER) +#define SHCI_OPCODE_C2_MAC_802_15_4_INIT (( SHCI_OGF << 10) + SHCI_OCF_C2_MAC_802_15_4_INIT) + #define SHCI_OPCODE_C2_REINIT (( SHCI_OGF << 10) + SHCI_OCF_C2_REINIT) +#define SHCI_OPCODE_C2_ZIGBEE_INIT (( SHCI_OGF << 10) + SHCI_OCF_C2_ZIGBEE_INIT) + #define SHCI_OPCODE_C2_LLD_TESTS_INIT (( SHCI_OGF << 10) + SHCI_OCF_C2_LLD_TESTS_INIT) #define SHCI_OPCODE_C2_BLE_LLD_INIT (( SHCI_OGF << 10) + SHCI_OCF_C2_BLE_LLD_INIT) @@ -784,6 +826,7 @@ extern "C" { uint32_t BleNvmRamAddress; uint32_t ThreadNvmRamAddress; uint16_t RevisionID; + uint16_t DeviceID; } SHCI_C2_CONFIG_Cmd_Param_t; #define SHCI_OPCODE_C2_802_15_4_DEINIT (( SHCI_OGF << 10) + SHCI_OCF_C2_802_15_4_DEINIT) @@ -801,6 +844,12 @@ extern "C" { #define SHCI_C2_CONFIG_CUT2_1 (0x2001) #define SHCI_C2_CONFIG_CUT2_2 (0x2003) +/** + * Device ID + */ +#define SHCI_C2_CONFIG_STM32WB55xx (0x495) +#define SHCI_C2_CONFIG_STM32WB15xx (0x494) + /** * Config1 * Each definition below may be added together to build the Config1 value @@ -844,7 +893,7 @@ extern "C" { #define FUS_DEVICE_INFO_TABLE_VALIDITY_KEYWORD (0xA94656B9) /* - * At startup, the information relative to the wireless binary are stored in RAM through a structure defined by + * At startup, the informations relative to the wireless binary are stored in RAM trough a structure defined by * MB_WirelessFwInfoTable_t.This structure contains 4 fields (Version,MemorySize, Stack_info and a reserved part) * each of those coded on 32 bits as shown on the table below: * @@ -900,6 +949,9 @@ extern "C" { #define INFO_STACK_TYPE_BLE_HCI_EXT_ADV 0x07 #define INFO_STACK_TYPE_THREAD_FTD 0x10 #define INFO_STACK_TYPE_THREAD_MTD 0x11 +#define INFO_STACK_TYPE_ZIGBEE_FFD 0x30 +#define INFO_STACK_TYPE_ZIGBEE_RFD 0x31 +#define INFO_STACK_TYPE_MAC 0x40 #define INFO_STACK_TYPE_BLE_THREAD_FTD_STATIC 0x50 #define INFO_STACK_TYPE_BLE_THREAD_FTD_DYAMIC 0x51 #define INFO_STACK_TYPE_802154_LLD_TESTS 0x60 @@ -908,7 +960,12 @@ extern "C" { #define INFO_STACK_TYPE_BLE_LLD_TESTS 0x63 #define INFO_STACK_TYPE_BLE_RLV 0x64 #define INFO_STACK_TYPE_802154_RLV 0x65 +#define INFO_STACK_TYPE_BLE_ZIGBEE_FFD_STATIC 0x70 +#define INFO_STACK_TYPE_BLE_ZIGBEE_RFD_STATIC 0x71 +#define INFO_STACK_TYPE_BLE_ZIGBEE_FFD_DYNAMIC 0x78 +#define INFO_STACK_TYPE_BLE_ZIGBEE_RFD_DYNAMIC 0x79 #define INFO_STACK_TYPE_RLV 0x80 +#define INFO_STACK_TYPE_BLE_MAC_STATIC 0x90 typedef struct { /** @@ -1082,7 +1139,7 @@ typedef struct { * @brief Starts the LLD tests CLI * * @param param_size : Nb of bytes - * @param p_param : pointer with data to give from M4 to M0 + * @param p_param : pointeur with data to give from M4 to M0 * @retval Status */ SHCI_CmdStatus_t SHCI_C2_LLDTESTS_Init( uint8_t param_size, uint8_t * p_param ); @@ -1092,11 +1149,20 @@ typedef struct { * @brief Starts the LLD tests BLE * * @param param_size : Nb of bytes - * @param p_param : pointer with data to give from M4 to M0 + * @param p_param : pointeur with data to give from M4 to M0 * @retval Status */ SHCI_CmdStatus_t SHCI_C2_BLE_LLD_Init( uint8_t param_size, uint8_t * p_param ); + /** + * SHCI_C2_ZIGBEE_Init + * @brief Starts the Zigbee Stack + * + * @param None + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_ZIGBEE_Init( void ); + /** * SHCI_C2_DEBUG_Init * @brief Starts the Traces @@ -1171,9 +1237,19 @@ typedef struct { */ SHCI_CmdStatus_t SHCI_C2_RADIO_AllowLowPower( SHCI_C2_FLASH_Ip_t Ip,uint8_t FlagRadioLowPowerOn); + + /** + * SHCI_C2_MAC_802_15_4_Init + * @brief Starts the MAC 802.15.4 on M0 + * + * @param None + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_MAC_802_15_4_Init( void ); + /** * SHCI_GetWirelessFwInfo - * @brief This function read back the information relative to the wireless binary loaded. + * @brief This function read back the informations relative to the wireless binary loaded. * Refer yourself to MB_WirelessFwInfoTable_t structure to get the significance * of the different parameters returned. * @param pWirelessInfo : Pointer to WirelessFwInfo_t. diff --git a/src/utility/STM32Cube_FW/shci_tl.c b/src/utility/STM32Cube_FW/shci_tl.c index 678de84d..449b8b16 100644 --- a/src/utility/STM32Cube_FW/shci_tl.c +++ b/src/utility/STM32Cube_FW/shci_tl.c @@ -16,15 +16,12 @@ ****************************************************************************** */ -#if defined(STM32WBxx) + /* Includes ------------------------------------------------------------------*/ #include "stm32_wpan_common.h" -#include <Arduino.h> - #include "stm_list.h" #include "shci_tl.h" -#include "stm32_def.h" /* Private typedef -----------------------------------------------------------*/ typedef enum @@ -171,20 +168,6 @@ void shci_send( uint16_t cmd_code, uint8_t len_cmd_payload, uint8_t * p_cmd_payl return; } -void shci_notify_asynch_evt(void *pdata) -{ - UNUSED(pdata); - /* Need to parse data in future version */ - shci_user_evt_proc(); -} - -void shci_register_io_bus(tSHciIO *fops) -{ - /* Register IO bus services */ - fops->Init = TL_SYS_Init; - fops->Send = TL_SYS_SendCmd; -} - /* Private functions ---------------------------------------------------------*/ static void TlInit( TL_CmdPacket_t * p_cmdbuffer ) { @@ -252,12 +235,11 @@ static void TlUserEvtReceived(TL_EvtPacket_t *shcievt) /* Weak implementation ----------------------------------------------------------------*/ __WEAK void shci_cmd_resp_wait(uint32_t timeout) { + (void)timeout; + CmdRspStatusFlag = SHCI_TL_CMD_RESP_WAIT; - for (unsigned long start = millis(); (millis() - start) < timeout;) { - if (CmdRspStatusFlag == SHCI_TL_CMD_RESP_RELEASE) { - break; - } - } + while(CmdRspStatusFlag != SHCI_TL_CMD_RESP_RELEASE); + return; } @@ -270,4 +252,3 @@ __WEAK void shci_cmd_resp_release(uint32_t flag) return; } -#endif /* STM32WBxx */ diff --git a/src/utility/STM32Cube_FW/stm32_wpan_common.h b/src/utility/STM32Cube_FW/stm32_wpan_common.h index 5a2b2a55..f407bb98 100644 --- a/src/utility/STM32Cube_FW/stm32_wpan_common.h +++ b/src/utility/STM32Cube_FW/stm32_wpan_common.h @@ -25,9 +25,19 @@ extern "C" { #endif -#define __ASM __asm /*!< asm keyword for GNU Compiler */ -#define __INLINE inline /*!< inline keyword for GNU Compiler */ -#define __STATIC_INLINE static inline +#if defined ( __CC_ARM )||defined (__ARMCC_VERSION) + #define __ASM __asm /*!< asm keyword for ARM Compiler */ + #define __INLINE __inline /*!< inline keyword for ARM Compiler */ + #define __STATIC_INLINE static __inline +#elif defined ( __ICCARM__ ) + #define __ASM __asm /*!< asm keyword for IAR Compiler */ + #define __INLINE inline /*!< inline keyword for IAR Compiler. Only available in High optimization mode! */ + #define __STATIC_INLINE static inline +#elif defined ( __GNUC__ ) + #define __ASM __asm /*!< asm keyword for GNU Compiler */ + #define __INLINE inline /*!< inline keyword for GNU Compiler */ + #define __STATIC_INLINE static inline +#endif #include <stdint.h> #include <string.h> @@ -130,8 +140,29 @@ extern "C" { /* ----------------------------------- * * Packed usage (compiler dependent) * * ----------------------------------- */ +#undef PACKED__ #undef PACKED_STRUCT -#define PACKED_STRUCT struct __packed + +#if defined ( __CC_ARM ) + #if defined ( __GNUC__ ) + /* GNU extension */ + #define PACKED__ __attribute__((packed)) + #define PACKED_STRUCT struct PACKED__ + #elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050U) + #define PACKED__ __attribute__((packed)) + #define PACKED_STRUCT struct PACKED__ + #else + #define PACKED__(TYPE) __packed TYPE + #define PACKED_STRUCT PACKED__(struct) + #endif +#elif defined ( __GNUC__ ) + #define PACKED__ __attribute__((packed)) + #define PACKED_STRUCT struct PACKED__ +#elif defined (__ICCARM__) + #define PACKED_STRUCT __packed struct +#else + #define PACKED_STRUCT __packed struct +#endif #ifdef __cplusplus } diff --git a/src/utility/STM32Cube_FW/stm_list.c b/src/utility/STM32Cube_FW/stm_list.c index 77dec64f..4c928647 100644 --- a/src/utility/STM32Cube_FW/stm_list.c +++ b/src/utility/STM32Cube_FW/stm_list.c @@ -16,13 +16,13 @@ ****************************************************************************** */ -#if defined(STM32WBxx) + /****************************************************************************** * Include Files ******************************************************************************/ +#include "utilities_common.h" + #include "stm_list.h" -#include "cmsis_gcc.h" -#include "stm32_wpan_common.h" /****************************************************************************** * Function Definitions @@ -33,10 +33,10 @@ void LST_init_head (tListNode * listHead) listHead->prev = listHead; } -bool LST_is_empty (tListNode * listHead) +uint8_t LST_is_empty (tListNode * listHead) { uint32_t primask_bit; - bool return_value; + uint8_t return_value; primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ @@ -204,4 +204,3 @@ void LST_get_prev_node (tListNode * ref_node, tListNode ** node) __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ } -#endif /* STM32WBxx */ diff --git a/src/utility/STM32Cube_FW/stm_list.h b/src/utility/STM32Cube_FW/stm_list.h index 769c2113..b7c3254c 100644 --- a/src/utility/STM32Cube_FW/stm_list.h +++ b/src/utility/STM32Cube_FW/stm_list.h @@ -21,8 +21,6 @@ #define _STM_LIST_H_ /* Includes ------------------------------------------------------------------*/ -#include "stdint.h" -#include "stdbool.h" #include "stm32_wpan_common.h" typedef PACKED_STRUCT _tListNode { @@ -32,7 +30,7 @@ typedef PACKED_STRUCT _tListNode { void LST_init_head (tListNode * listHead); -bool LST_is_empty (tListNode * listHead); +uint8_t LST_is_empty (tListNode * listHead); void LST_insert_head (tListNode * listHead, tListNode * node); diff --git a/src/utility/STM32Cube_FW/tl.h b/src/utility/STM32Cube_FW/tl.h index 678769cb..c199bb21 100644 --- a/src/utility/STM32Cube_FW/tl.h +++ b/src/utility/STM32Cube_FW/tl.h @@ -84,29 +84,32 @@ typedef PACKED_STRUCT } TL_CsEvt_t; /** - * This the payload of TL_Evt_t for a command complete event + * This the payload of TL_Evt_t for a command complete event, only used a pointer */ typedef PACKED_STRUCT { uint8_t numcmd; uint16_t cmdcode; - uint8_t payload[1]; + uint8_t payload[255]; } TL_CcEvt_t; /** - * This the payload of TL_Evt_t for an asynchronous event + * This the payload of TL_Evt_t for an asynchronous event, only used a pointer */ typedef PACKED_STRUCT { uint16_t subevtcode; - uint8_t payload[1]; + uint8_t payload[255]; } TL_AsynchEvt_t; +/** + * This the payload of TL_Evt_t, only used a pointer + */ typedef PACKED_STRUCT { uint8_t evtcode; uint8_t plen; - uint8_t payload[1]; + uint8_t payload[255]; } TL_Evt_t; typedef PACKED_STRUCT @@ -199,6 +202,19 @@ typedef struct uint8_t *p_BleLldM0CmdBuffer; } TL_BLE_LLD_Config_t; +typedef struct +{ + uint8_t *p_Mac_802_15_4_CmdRspBuffer; + uint8_t *p_Mac_802_15_4_NotAckBuffer; +} TL_MAC_802_15_4_Config_t; + +typedef struct +{ + uint8_t *p_ZigbeeOtCmdRspBuffer; + uint8_t *p_ZigbeeNotAckBuffer; + uint8_t *p_ZigbeeNotifRequestBuffer; +} TL_ZIGBEE_Config_t; + /** * @brief Contain the BLE HCI Init Configuration * @{ @@ -292,6 +308,26 @@ void TL_MM_EvtDone( TL_EvtPacket_t * hcievt ); void TL_TRACES_Init( void ); void TL_TRACES_EvtReceived( TL_EvtPacket_t * hcievt ); +/****************************************************************************** + * MAC 802.15.4 + ******************************************************************************/ +void TL_MAC_802_15_4_Init( TL_MAC_802_15_4_Config_t *p_Config ); +void TL_MAC_802_15_4_SendCmd( void ); +void TL_MAC_802_15_4_CmdEvtReceived( TL_EvtPacket_t * Otbuffer ); +void TL_MAC_802_15_4_NotReceived( TL_EvtPacket_t * Notbuffer ); +void TL_MAC_802_15_4_SendAck ( void ); + +/****************************************************************************** + * ZIGBEE + ******************************************************************************/ +void TL_ZIGBEE_Init( TL_ZIGBEE_Config_t *p_Config ); +void TL_ZIGBEE_SendM4RequestToM0( void ); +void TL_ZIGBEE_SendM4AckToM0Notify ( void ); +void TL_ZIGBEE_NotReceived( TL_EvtPacket_t * Notbuffer ); +void TL_ZIGBEE_CmdEvtReceived( TL_EvtPacket_t * Otbuffer ); +void TL_ZIGBEE_M0RequestReceived(TL_EvtPacket_t * Otbuffer ); +void TL_ZIGBEE_SendM4AckToM0Request(void); + #ifdef __cplusplus } /* extern "C" */ #endif diff --git a/src/utility/STM32Cube_FW/tl_mbox.c b/src/utility/STM32Cube_FW/tl_mbox.c index a9abb181..fcd7766d 100644 --- a/src/utility/STM32Cube_FW/tl_mbox.c +++ b/src/utility/STM32Cube_FW/tl_mbox.c @@ -16,7 +16,6 @@ ****************************************************************************** */ -#if defined(STM32WBxx) /* Includes ------------------------------------------------------------------*/ #include "stm32_wpan_common.h" #include "hw.h" @@ -52,13 +51,15 @@ PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_BleLldTable_t TL_BleLldTable; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_SysTable_t TL_SysTable; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_MemManagerTable_t TL_MemManagerTable; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_TracesTable_t TL_TracesTable; +PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_Mac_802_15_4_t TL_Mac_802_15_4_Table; +PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_ZigbeeTable_t TL_Zigbee_Table; /**< tables */ PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode FreeBufQueue; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode TracesEvtQueue; PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static uint8_t CsBuffer[sizeof(TL_PacketHeader_t) + TL_EVT_HDR_SIZE + sizeof(TL_CsEvt_t)]; -PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static tListNode EvtQueue; -PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static tListNode SystemEvtQueue; +PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode EvtQueue; +PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode SystemEvtQueue; static tListNode LocalFreeBufQueue; @@ -96,6 +97,8 @@ void TL_Init( void ) TL_RefTable.p_sys_table = &TL_SysTable; TL_RefTable.p_mem_manager_table = &TL_MemManagerTable; TL_RefTable.p_traces_table = &TL_TracesTable; + TL_RefTable.p_mac_802_15_4_table = &TL_Mac_802_15_4_Table; + TL_RefTable.p_zigbee_table = &TL_Zigbee_Table; HW_IPCC_Init(); return; @@ -449,6 +452,139 @@ void TL_BLE_LLD_SendRspAck( void ) } #endif /* BLE_LLD_WB */ +#ifdef MAC_802_15_4_WB +/****************************************************************************** + * MAC 802.15.4 + ******************************************************************************/ +void TL_MAC_802_15_4_Init( TL_MAC_802_15_4_Config_t *p_Config ) +{ + MB_Mac_802_15_4_t * p_mac_802_15_4_table; + + p_mac_802_15_4_table = TL_RefTable.p_mac_802_15_4_table; + + p_mac_802_15_4_table->p_cmdrsp_buffer = p_Config->p_Mac_802_15_4_CmdRspBuffer; + p_mac_802_15_4_table->p_notack_buffer = p_Config->p_Mac_802_15_4_NotAckBuffer; + + HW_IPCC_MAC_802_15_4_Init(); + + return; +} + +void TL_MAC_802_15_4_SendCmd( void ) +{ + ((TL_CmdPacket_t *)(TL_RefTable.p_mac_802_15_4_table->p_cmdrsp_buffer))->cmdserial.type = TL_OTCMD_PKT_TYPE; + + HW_IPCC_MAC_802_15_4_SendCmd(); + + return; +} + +void TL_MAC_802_15_4_SendAck ( void ) +{ + ((TL_CmdPacket_t *)(TL_RefTable.p_mac_802_15_4_table->p_notack_buffer))->cmdserial.type = TL_OTACK_PKT_TYPE; + + HW_IPCC_MAC_802_15_4_SendAck(); + + return; +} + +void HW_IPCC_MAC_802_15_4_CmdEvtNot(void) +{ + TL_MAC_802_15_4_CmdEvtReceived( (TL_EvtPacket_t*)(TL_RefTable.p_mac_802_15_4_table->p_cmdrsp_buffer) ); + + return; +} + +void HW_IPCC_MAC_802_15_4_EvtNot( void ) +{ + TL_MAC_802_15_4_NotReceived( (TL_EvtPacket_t*)(TL_RefTable.p_mac_802_15_4_table->p_notack_buffer) ); + + return; +} + +__WEAK void TL_MAC_802_15_4_CmdEvtReceived( TL_EvtPacket_t * Otbuffer ){}; +__WEAK void TL_MAC_802_15_4_NotReceived( TL_EvtPacket_t * Notbuffer ){}; +#endif + +#ifdef ZIGBEE_WB +/****************************************************************************** + * ZIGBEE + ******************************************************************************/ +void TL_ZIGBEE_Init( TL_ZIGBEE_Config_t *p_Config ) +{ + MB_ZigbeeTable_t * p_zigbee_table; + + p_zigbee_table = TL_RefTable.p_zigbee_table; + p_zigbee_table->appliCmdM4toM0_buffer = p_Config->p_ZigbeeOtCmdRspBuffer; + p_zigbee_table->notifM0toM4_buffer = p_Config->p_ZigbeeNotAckBuffer; + p_zigbee_table->requestM0toM4_buffer = p_Config->p_ZigbeeNotifRequestBuffer; + + HW_IPCC_ZIGBEE_Init(); + + return; +} + +/* Zigbee M4 to M0 Request */ +void TL_ZIGBEE_SendM4RequestToM0( void ) +{ + ((TL_CmdPacket_t *)(TL_RefTable.p_zigbee_table->appliCmdM4toM0_buffer))->cmdserial.type = TL_OTCMD_PKT_TYPE; + + HW_IPCC_ZIGBEE_SendM4RequestToM0(); + + return; +} + +/* Used to receive an ACK from the M0 */ +void HW_IPCC_ZIGBEE_RecvAppliAckFromM0(void) +{ + TL_ZIGBEE_CmdEvtReceived( (TL_EvtPacket_t*)(TL_RefTable.p_zigbee_table->appliCmdM4toM0_buffer) ); + + return; +} + +/* Zigbee notification from M0 to M4 */ +void HW_IPCC_ZIGBEE_RecvM0NotifyToM4( void ) +{ + TL_ZIGBEE_NotReceived( (TL_EvtPacket_t*)(TL_RefTable.p_zigbee_table->notifM0toM4_buffer) ); + + return; +} + +/* Send an ACK to the M0 for a Notification */ +void TL_ZIGBEE_SendM4AckToM0Notify ( void ) +{ + ((TL_CmdPacket_t *)(TL_RefTable.p_zigbee_table->notifM0toM4_buffer))->cmdserial.type = TL_OTACK_PKT_TYPE; + + HW_IPCC_ZIGBEE_SendM4AckToM0Notify(); + + return; +} + +/* Zigbee M0 to M4 Request */ +void HW_IPCC_ZIGBEE_RecvM0RequestToM4( void ) +{ + TL_ZIGBEE_M0RequestReceived( (TL_EvtPacket_t*)(TL_RefTable.p_zigbee_table->requestM0toM4_buffer) ); + + return; +} + +/* Send an ACK to the M0 for a Request */ +void TL_ZIGBEE_SendM4AckToM0Request(void) +{ + ((TL_CmdPacket_t *)(TL_RefTable.p_zigbee_table->requestM0toM4_buffer))->cmdserial.type = TL_OTACK_PKT_TYPE; + + HW_IPCC_ZIGBEE_SendM4AckToM0Request(); + + return; +} + + +__WEAK void TL_ZIGBEE_CmdEvtReceived( TL_EvtPacket_t * Otbuffer ){}; +__WEAK void TL_ZIGBEE_NotReceived( TL_EvtPacket_t * Notbuffer ){}; +#endif + + + /****************************************************************************** * MEMORY MANAGER ******************************************************************************/ @@ -710,4 +846,3 @@ static void OutputDbgTrace(TL_MB_PacketType_t packet_type, uint8_t* buffer) return; } -#endif /* STM32WBxx */ From 70812b4e3a184585354f979472a75a648266f53f Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Mon, 12 Dec 2022 17:15:26 +0100 Subject: [PATCH 106/226] chore: clean up and adapt STM32Cube_FW sources for STM32duino Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- src/utility/STM32Cube_FW/app_conf_default.h | 442 +------------------ src/utility/STM32Cube_FW/ble_bufsize.h | 7 + src/utility/STM32Cube_FW/hw.h | 28 +- src/utility/STM32Cube_FW/hw_ipcc.c | 218 +-------- src/utility/STM32Cube_FW/mbox_def.h | 34 -- src/utility/STM32Cube_FW/shci.c | 39 +- src/utility/STM32Cube_FW/shci.h | 51 +-- src/utility/STM32Cube_FW/shci_tl.c | 37 +- src/utility/STM32Cube_FW/stm32_wpan_common.h | 39 +- src/utility/STM32Cube_FW/stm_list.c | 15 +- src/utility/STM32Cube_FW/stm_list.h | 4 +- src/utility/STM32Cube_FW/tl.h | 33 -- src/utility/STM32Cube_FW/tl_mbox.c | 143 +----- 13 files changed, 87 insertions(+), 1003 deletions(-) diff --git a/src/utility/STM32Cube_FW/app_conf_default.h b/src/utility/STM32Cube_FW/app_conf_default.h index 2606a059..cc8c3e89 100644 --- a/src/utility/STM32Cube_FW/app_conf_default.h +++ b/src/utility/STM32Cube_FW/app_conf_default.h @@ -1,9 +1,8 @@ -/* USER CODE BEGIN Header */ /** ****************************************************************************** - * @file app_conf.h + * @file app_conf_default.h * @author MCD Application Team - * @brief Application configuration file for STM32WPAN Middleware. + * @brief Default application configuration file for STM32WPAN Middleware. ****************************************************************************** * @attention * @@ -16,94 +15,33 @@ * ****************************************************************************** */ -/* USER CODE END Header */ /* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef APP_CONF_H -#define APP_CONF_H - -#include "hw.h" -#include "hw_conf.h" -#include "hw_if.h" -#include "ble_bufsize.h" +#ifndef APP_CONF_DEFAULT_H +#define APP_CONF_DEFAULT_H /****************************************************************************** * Application Config ******************************************************************************/ -/** - * Define Secure Connections Support - */ -#define CFG_SECURE_NOT_SUPPORTED (0x00) -#define CFG_SECURE_OPTIONAL (0x01) -#define CFG_SECURE_MANDATORY (0x02) - -#define CFG_SC_SUPPORT CFG_SECURE_OPTIONAL - -/** - * Define Keypress Notification Support - */ -#define CFG_KEYPRESS_NOT_SUPPORTED (0x00) -#define CFG_KEYPRESS_SUPPORTED (0x01) - -#define CFG_KEYPRESS_NOTIFICATION_SUPPORT CFG_KEYPRESS_NOT_SUPPORTED +/**< generic parameters ******************************************************/ +/* HCI related defines */ -/** - * Numeric Comparison Answers - */ -#define YES (0x01) -#define NO (0x00) +#define ACI_HAL_SET_TX_POWER_LEVEL 0xFC0F +#define ACI_WRITE_CONFIG_DATA_OPCODE 0xFC0C +#define ACI_READ_CONFIG_DATA_OPCODE 0xFC0D +#define MAX_HCI_ACL_PACKET_SIZE (sizeof(TL_PacketHeader_t) + 5 + 251) +#define HCI_RESET 0x0C03 -/** - * Device name configuration for Generic Access Service - */ -#define CFG_GAP_DEVICE_NAME "TEMPLATE" -#define CFG_GAP_DEVICE_NAME_LENGTH (8) - -/** -* Identity root key used to derive LTK and CSRK -*/ -#define CFG_BLE_IRK {0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0} - -/** -* Encryption root key used to derive LTK and CSRK -*/ -#define CFG_BLE_ERK {0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21, 0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21} +#ifndef BLE_SHARED_MEM_BYTE_ORDER + #define BLE_SHARED_MEM_BYTE_ORDER MSBFIRST +#endif +#define BLE_MODULE_SHARED_MEM_BUFFER_SIZE 128 /** - * SMPS supply - * SMPS not used when Set to 0 - * SMPS used when Set to 1 + * Define Tx Power */ -#define CFG_USE_SMPS 0 - -/* USER CODE BEGIN Generic_Parameters */ -/* USER CODE END Generic_Parameters */ - -/**< specific parameters */ -/*****************************************************/ - -/* USER CODE BEGIN Specific_Parameters */ -#define PUSH_BUTTON_SW1_EXTI_IRQHandler EXTI4_IRQHandler - -/* USER CODE END Specific_Parameters */ - -/****************************************************************************** - * Information Table - * - * Version - * [0:3] = Build - 0: Untracked - 15:Released - x: Tracked version - * [4:7] = branch - 0: Mass Market - x: ... - * [8:15] = Subversion - * [16:23] = Version minor - * [24:31] = Version major - * - ******************************************************************************/ -#define CFG_FW_MAJOR_VERSION (0) -#define CFG_FW_MINOR_VERSION (0) -#define CFG_FW_SUBVERSION (1) -#define CFG_FW_BRANCH (0) -#define CFG_FW_BUILD (0) +#define CFG_TX_POWER (0x18) /* -0.15dBm */ /****************************************************************************** * BLE Stack @@ -152,13 +90,15 @@ * Prepare Write List size in terms of number of packet * This parameter is ignored by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set */ -#define CFG_BLE_PREPARE_WRITE_LIST_SIZE BLE_PREP_WRITE_X_ATT(CFG_BLE_MAX_ATT_MTU) +// #define CFG_BLE_PREPARE_WRITE_LIST_SIZE BLE_PREP_WRITE_X_ATT(CFG_BLE_MAX_ATT_MTU) +#define CFG_BLE_PREPARE_WRITE_LIST_SIZE (0x3A) /** * Number of allocated memory blocks * This parameter is overwritten by the CPU2 with an hardcoded optimal value when the parameter CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set */ -#define CFG_BLE_MBLOCK_COUNT (BLE_MBLOCKS_CALC(CFG_BLE_PREPARE_WRITE_LIST_SIZE, CFG_BLE_MAX_ATT_MTU, CFG_BLE_NUM_LINK)) +// #define CFG_BLE_MBLOCK_COUNT (BLE_MBLOCKS_CALC(CFG_BLE_PREPARE_WRITE_LIST_SIZE, CFG_BLE_MAX_ATT_MTU, CFG_BLE_NUM_LINK)) +#define CFG_BLE_MBLOCK_COUNT (0x79) /** * Enable or disable the Extended Packet length feature. Valid values are 0 or 1. @@ -258,7 +198,7 @@ * 0: Enhanced ATT not supported * other bits: reserved (shall be set to 0) */ -#define CFG_BLE_OPTIONS (SHCI_C2_BLE_INIT_OPTIONS_LL_HOST | SHCI_C2_BLE_INIT_OPTIONS_WITH_SVC_CHANGE_DESC | SHCI_C2_BLE_INIT_OPTIONS_DEVICE_NAME_RW | SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV | SHCI_C2_BLE_INIT_OPTIONS_CS_ALGO2 | SHCI_C2_BLE_INIT_OPTIONS_FULL_GATTDB_NVM | SHCI_C2_BLE_INIT_OPTIONS_GATT_CACHING_NOTUSED | SHCI_C2_BLE_INIT_OPTIONS_POWER_CLASS_2_3 | SHCI_C2_BLE_INIT_OPTIONS_APPEARANCE_READONLY | SHCI_C2_BLE_INIT_OPTIONS_ENHANCED_ATT_NOTSUPPORTED) +#define CFG_BLE_OPTIONS (SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY) #define CFG_BLE_MAX_COC_INITIATOR_NBR (32) @@ -316,340 +256,4 @@ #define CFG_BLE_CORE_VERSION (SHCI_C2_BLE_INIT_BLE_CORE_5_3) -/****************************************************************************** - * Transport Layer - ******************************************************************************/ -/** - * Queue length of BLE Event - * This parameter defines the number of asynchronous events that can be stored in the HCI layer before - * being reported to the application. When a command is sent to the BLE core coprocessor, the HCI layer - * is waiting for the event with the Num_HCI_Command_Packets set to 1. The receive queue shall be large - * enough to store all asynchronous events received in between. - * When CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE is set to 27, this allow to store three 255 bytes long asynchronous events - * between the HCI command and its event. - * This parameter depends on the value given to CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE. When the queue size is to small, - * the system may hang if the queue is full with asynchronous events and the HCI layer is still waiting - * for a CC/CS event, In that case, the notification TL_BLE_HCI_ToNot() is called to indicate - * to the application a HCI command did not receive its command event within 30s (Default HCI Timeout). - */ -#define CFG_TLBLE_EVT_QUEUE_LENGTH 5 -/** - * This parameter should be set to fit most events received by the HCI layer. It defines the buffer size of each element - * allocated in the queue of received events and can be used to optimize the amount of RAM allocated by the Memory Manager. - * It should not exceed 255 which is the maximum HCI packet payload size (a greater value is a lost of memory as it will - * never be used) - * It shall be at least 4 to receive the command status event in one frame. - * The default value is set to 27 to allow receiving an event of MTU size in a single buffer. This value maybe reduced - * further depending on the application. - */ -#define CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE 255 /**< Set to 255 with the memory manager and the mailbox */ - -#define TL_BLE_EVENT_FRAME_SIZE ( TL_EVT_HDR_SIZE + CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE ) -/****************************************************************************** - * UART interfaces - ******************************************************************************/ - -/** - * Select UART interfaces - */ -#define CFG_UART_GUI hw_uart1 -#define CFG_DEBUG_TRACE_UART 0 -/****************************************************************************** - * USB interface - ******************************************************************************/ - -/** - * Enable/Disable USB interface - */ -#define CFG_USB_INTERFACE_ENABLE 0 - -/****************************************************************************** - * IPCC interface - ******************************************************************************/ - -/** - * The IPCC is dedicated to the communication between the CPU2 and the CPU1 - * and shall not be modified by the application - * The two following definitions shall not be modified - */ -#define HAL_IPCC_TX_IRQHandler(...) HW_IPCC_Tx_Handler( ) -#define HAL_IPCC_RX_IRQHandler(...) HW_IPCC_Rx_Handler( ) - -/****************************************************************************** - * Low Power - ******************************************************************************/ -/** - * When set to 1, the low power mode is enable - * When set to 0, the device stays in RUN mode - */ -#define CFG_LPM_SUPPORTED 1 - -/****************************************************************************** - * RTC interface - ******************************************************************************/ -#define HAL_RTCEx_WakeUpTimerIRQHandler(...) HW_TS_RTC_Wakeup_Handler( ) - -/****************************************************************************** - * Timer Server - ******************************************************************************/ -/** - * CFG_RTC_WUCKSEL_DIVIDER: This sets the RTCCLK divider to the wakeup timer. - * The lower is the value, the better is the power consumption and the accuracy of the timerserver - * The higher is the value, the finest is the granularity - * - * CFG_RTC_ASYNCH_PRESCALER: This sets the asynchronous prescaler of the RTC. It should as high as possible ( to output - * clock as low as possible) but the output clock should be equal or higher frequency compare to the clock feeding - * the wakeup timer. A lower clock speed would impact the accuracy of the timer server. - * - * CFG_RTC_SYNCH_PRESCALER: This sets the synchronous prescaler of the RTC. - * When the 1Hz calendar clock is required, it shall be sets according to other settings - * When the 1Hz calendar clock is not needed, CFG_RTC_SYNCH_PRESCALER should be set to 0x7FFF (MAX VALUE) - * - * CFG_RTCCLK_DIVIDER_CONF: - * Shall be set to either 0,2,4,8,16 - * When set to either 2,4,8,16, the 1Hhz calendar is supported - * When set to 0, the user sets its own configuration - * - * The following settings are computed with LSI as input to the RTC - */ - -#define CFG_RTCCLK_DIVIDER_CONF 0 - -#if (CFG_RTCCLK_DIVIDER_CONF == 0) -/** - * Custom configuration - * It does not support 1Hz calendar - * It divides the RTC CLK by 16 - */ - -#define CFG_RTCCLK_DIV (16) -#define CFG_RTC_WUCKSEL_DIVIDER (0) -#define CFG_RTC_ASYNCH_PRESCALER (0x0F) -#define CFG_RTC_SYNCH_PRESCALER (0x7FFF) - -#else - -#if (CFG_RTCCLK_DIVIDER_CONF == 2) -/** - * It divides the RTC CLK by 2 - */ -#define CFG_RTC_WUCKSEL_DIVIDER (3) -#endif - -#if (CFG_RTCCLK_DIVIDER_CONF == 4) -/** - * It divides the RTC CLK by 4 - */ -#define CFG_RTC_WUCKSEL_DIVIDER (2) -#endif - -#if (CFG_RTCCLK_DIVIDER_CONF == 8) -/** - * It divides the RTC CLK by 8 - */ -#define CFG_RTC_WUCKSEL_DIVIDER (1) -#endif - -#if (CFG_RTCCLK_DIVIDER_CONF == 16) -/** - * It divides the RTC CLK by 16 - */ -#define CFG_RTC_WUCKSEL_DIVIDER (0) -#endif - -#define CFG_RTCCLK_DIV CFG_RTCCLK_DIVIDER_CONF -#define CFG_RTC_ASYNCH_PRESCALER (CFG_RTCCLK_DIV - 1) -#define CFG_RTC_SYNCH_PRESCALER (DIVR( LSE_VALUE, (CFG_RTC_ASYNCH_PRESCALER+1) ) - 1 ) - -#endif - -/** tick timer values */ -#define CFG_TS_TICK_VAL DIVR( (CFG_RTCCLK_DIV * 1000000), LSE_VALUE ) -#define CFG_TS_TICK_VAL_PS DIVR( ((uint64_t)CFG_RTCCLK_DIV * 1e12), (uint64_t)LSE_VALUE ) - -typedef enum -{ - CFG_TIM_PROC_ID_ISR, - /* USER CODE BEGIN CFG_TimProcID_t */ - - /* USER CODE END CFG_TimProcID_t */ -} CFG_TimProcID_t; - -/****************************************************************************** - * Debug - ******************************************************************************/ -/** - * When set, this resets some hw resources to set the device in the same state than the power up - * The FW resets only register that may prevent the FW to run properly - * - * This shall be set to 0 in a final product - * - */ -#define CFG_HW_RESET_BY_FW 1 - -/** - * keep debugger enabled while in any low power mode when set to 1 - * should be set to 0 in production - */ -#define CFG_DEBUGGER_SUPPORTED 0 - -/** - * When set to 1, the traces are enabled in the BLE services - */ -#define CFG_DEBUG_BLE_TRACE 0 - -/** - * Enable or Disable traces in application - */ -#define CFG_DEBUG_APP_TRACE 0 - -#if (CFG_DEBUG_APP_TRACE != 0) -#define APP_DBG_MSG PRINT_MESG_DBG -#else -#define APP_DBG_MSG PRINT_NO_MESG -#endif - -#if ( (CFG_DEBUG_BLE_TRACE != 0) || (CFG_DEBUG_APP_TRACE != 0) ) -#define CFG_DEBUG_TRACE 1 -#endif - -#if (CFG_DEBUG_TRACE != 0) -#undef CFG_LPM_SUPPORTED -#undef CFG_DEBUGGER_SUPPORTED -#define CFG_LPM_SUPPORTED 0 -#define CFG_DEBUGGER_SUPPORTED 1 -#endif - -/** - * When CFG_DEBUG_TRACE_FULL is set to 1, the trace are output with the API name, the file name and the line number - * When CFG_DEBUG_TRACE_LIGHT is set to 1, only the debug message is output - * - * When both are set to 0, no trace are output - * When both are set to 1, CFG_DEBUG_TRACE_FULL is selected - */ -#define CFG_DEBUG_TRACE_LIGHT 0 -#define CFG_DEBUG_TRACE_FULL 0 - -#if (( CFG_DEBUG_TRACE != 0 ) && ( CFG_DEBUG_TRACE_LIGHT == 0 ) && (CFG_DEBUG_TRACE_FULL == 0)) -#undef CFG_DEBUG_TRACE_FULL -#undef CFG_DEBUG_TRACE_LIGHT -#define CFG_DEBUG_TRACE_FULL 0 -#define CFG_DEBUG_TRACE_LIGHT 1 -#endif - -#if ( CFG_DEBUG_TRACE == 0 ) -#undef CFG_DEBUG_TRACE_FULL -#undef CFG_DEBUG_TRACE_LIGHT -#define CFG_DEBUG_TRACE_FULL 0 -#define CFG_DEBUG_TRACE_LIGHT 0 -#endif - -/** - * When not set, the traces is looping on sending the trace over UART - */ -#define DBG_TRACE_USE_CIRCULAR_QUEUE 1 - -/** - * max buffer Size to queue data traces and max data trace allowed. - * Only Used if DBG_TRACE_USE_CIRCULAR_QUEUE is defined - */ -#define DBG_TRACE_MSG_QUEUE_SIZE 4096 -#define MAX_DBG_TRACE_MSG_SIZE 1024 - -/* USER CODE BEGIN Defines */ -#define CFG_LED_SUPPORTED 1 -#define CFG_BUTTON_SUPPORTED 1 - -#define PUSH_BUTTON_SW1_EXTI_IRQHandler EXTI4_IRQHandler -#define PUSH_BUTTON_SW2_EXTI_IRQHandler EXTI0_IRQHandler -#define PUSH_BUTTON_SW3_EXTI_IRQHandler EXTI1_IRQHandler -/* USER CODE END Defines */ - -/****************************************************************************** - * Scheduler - ******************************************************************************/ - -/** - * These are the lists of task id registered to the scheduler - * Each task id shall be in the range [0:31] - * This mechanism allows to implement a generic code in the API TL_BLE_HCI_StatusNot() to comply with - * the requirement that a HCI/ACI command shall never be sent if there is already one pending - */ - -/**< Add in that list all tasks that may send a ACI/HCI command */ -typedef enum -{ - CFG_TASK_BLE_HCI_CMD_ID, - CFG_TASK_SYS_HCI_CMD_ID, - CFG_TASK_HCI_ACL_DATA_ID, - CFG_TASK_SYS_LOCAL_CMD_ID, - CFG_TASK_TX_TO_HOST_ID, - /* USER CODE BEGIN CFG_Task_Id_With_HCI_Cmd_t */ - CFG_TASK_SW1_BUTTON_PUSHED_ID, - CFG_TASK_SW2_BUTTON_PUSHED_ID, - CFG_TASK_SW3_BUTTON_PUSHED_ID, - /* USER CODE END CFG_Task_Id_With_HCI_Cmd_t */ - CFG_LAST_TASK_ID_WITH_HCICMD, /**< Shall be LAST in the list */ -} CFG_Task_Id_With_HCI_Cmd_t; - -/**< Add in that list all tasks that never send a ACI/HCI command */ -typedef enum -{ - CFG_FIRST_TASK_ID_WITH_NO_HCICMD = CFG_LAST_TASK_ID_WITH_HCICMD - 1, /**< Shall be FIRST in the list */ - CFG_TASK_SYSTEM_HCI_ASYNCH_EVT_ID, - /* USER CODE BEGIN CFG_Task_Id_With_NO_HCI_Cmd_t */ - - /* USER CODE END CFG_Task_Id_With_NO_HCI_Cmd_t */ - CFG_LAST_TASK_ID_WITH_NO_HCICMD /**< Shall be LAST in the list */ -} CFG_Task_Id_With_NO_HCI_Cmd_t; - -#define CFG_TASK_NBR CFG_LAST_TASK_ID_WITH_NO_HCICMD - -/** - * This is the list of priority required by the application - * Each Id shall be in the range 0..31 - */ -typedef enum -{ - CFG_SCH_PRIO_0, - /* USER CODE BEGIN CFG_SCH_Prio_Id_t */ - - /* USER CODE END CFG_SCH_Prio_Id_t */ -} CFG_SCH_Prio_Id_t; - -/** - * This is a bit mapping over 32bits listing all events id supported in the application - */ -typedef enum -{ - CFG_IDLEEVT_SYSTEM_HCI_CMD_EVT_RSP_ID, - /* USER CODE BEGIN CFG_IdleEvt_Id_t */ - - /* USER CODE END CFG_IdleEvt_Id_t */ -} CFG_IdleEvt_Id_t; - -/****************************************************************************** - * LOW POWER - ******************************************************************************/ -/** - * Supported requester to the MCU Low Power Manager - can be increased up to 32 - * It list a bit mapping of all user of the Low Power Manager - */ -typedef enum -{ - CFG_LPM_APP, - CFG_LPM_APP_BLE, - /* USER CODE BEGIN CFG_LPM_Id_t */ - - /* USER CODE END CFG_LPM_Id_t */ -} CFG_LPM_Id_t; - -/****************************************************************************** - * OTP manager - ******************************************************************************/ -#define CFG_OTP_BASE_ADDRESS OTP_AREA_BASE - -#define CFG_OTP_END_ADRESS OTP_AREA_END_ADDR - -#endif /*APP_CONF_H */ - +#endif /* APP_CONF_DEFAULT_H */ diff --git a/src/utility/STM32Cube_FW/ble_bufsize.h b/src/utility/STM32Cube_FW/ble_bufsize.h index 4269fa43..cea5da84 100644 --- a/src/utility/STM32Cube_FW/ble_bufsize.h +++ b/src/utility/STM32Cube_FW/ble_bufsize.h @@ -75,6 +75,13 @@ ((pw) + MAX(BLE_MEM_BLOCK_X_MTU(mtu, n_link), \ BLE_MBLOCKS_SECURE_CONNECTIONS)) +/* + * BLE_DEFAULT_MBLOCKS_COUNT: default memory blocks count + */ +#define BLE_DEFAULT_MBLOCKS_COUNT(n_link) \ + BLE_MBLOCKS_CALC(BLE_DEFAULT_PREP_WRITE_LIST_SIZE, \ + BLE_DEFAULT_MAX_ATT_MTU, n_link) + /* * BLE_FIXED_BUFFER_SIZE_BYTES: * A part of the RAM, is dynamically allocated by initializing all the pointers diff --git a/src/utility/STM32Cube_FW/hw.h b/src/utility/STM32Cube_FW/hw.h index 503fa2ca..fcf04517 100644 --- a/src/utility/STM32Cube_FW/hw.h +++ b/src/utility/STM32Cube_FW/hw.h @@ -26,14 +26,21 @@ extern "C" { #endif /* Includes ------------------------------------------------------------------*/ +#include "stm32_def.h" +#include "stm32wbxx_ll_bus.h" +#include "stm32wbxx_ll_exti.h" +#include "stm32wbxx_ll_system.h" +#include "stm32wbxx_ll_rcc.h" +#include "stm32wbxx_ll_ipcc.h" +#include "stm32wbxx_ll_cortex.h" +#include "stm32wbxx_ll_utils.h" +#include "stm32wbxx_ll_pwr.h" /****************************************************************************** * HW IPCC ******************************************************************************/ void HW_IPCC_Enable( void ); void HW_IPCC_Init( void ); - void HW_IPCC_Rx_Handler( void ); - void HW_IPCC_Tx_Handler( void ); void HW_IPCC_BLE_Init( void ); void HW_IPCC_BLE_SendCmd( void ); @@ -80,23 +87,6 @@ extern "C" { void HW_IPCC_TRACES_Init( void ); void HW_IPCC_TRACES_EvtNot( void ); - void HW_IPCC_MAC_802_15_4_Init( void ); - void HW_IPCC_MAC_802_15_4_SendCmd( void ); - void HW_IPCC_MAC_802_15_4_SendAck( void ); - void HW_IPCC_MAC_802_15_4_CmdEvtNot( void ); - void HW_IPCC_MAC_802_15_4_EvtNot( void ); - - void HW_IPCC_ZIGBEE_Init( void ); - - void HW_IPCC_ZIGBEE_SendM4RequestToM0(void); /* M4 Request to M0 */ - void HW_IPCC_ZIGBEE_RecvAppliAckFromM0(void); /* Request ACK from M0 */ - - void HW_IPCC_ZIGBEE_RecvM0NotifyToM4(void); /* M0 Notify to M4 */ - void HW_IPCC_ZIGBEE_SendM4AckToM0Notify(void); /* Notify ACK from M4 */ - void HW_IPCC_ZIGBEE_RecvM0RequestToM4(void); /* M0 Request to M4 */ - void HW_IPCC_ZIGBEE_SendM4AckToM0Request(void); /* Request ACK from M4 */ - - #ifdef __cplusplus } #endif diff --git a/src/utility/STM32Cube_FW/hw_ipcc.c b/src/utility/STM32Cube_FW/hw_ipcc.c index fd620b85..0c1868f6 100644 --- a/src/utility/STM32Cube_FW/hw_ipcc.c +++ b/src/utility/STM32Cube_FW/hw_ipcc.c @@ -1,4 +1,3 @@ -/* USER CODE BEGIN Header */ /** ****************************************************************************** * @file hw_ipcc.c @@ -16,10 +15,10 @@ * ****************************************************************************** */ -/* USER CODE END Header */ +#if defined(STM32WBxx) /* Includes ------------------------------------------------------------------*/ -#include "app_common.h" +#include "hw.h" #include "mbox_def.h" /* Global variables ---------------------------------------------------------*/ @@ -56,34 +55,17 @@ static void HW_IPCC_LLD_BLE_ReceiveRspHandler( void ); static void HW_IPCC_LLD_BLE_ReceiveM0CmdHandler( void ); #endif -#ifdef MAC_802_15_4_WB -static void HW_IPCC_MAC_802_15_4_CmdEvtHandler( void ); -static void HW_IPCC_MAC_802_15_4_NotEvtHandler( void ); -#endif - -#ifdef ZIGBEE_WB -static void HW_IPCC_ZIGBEE_CmdEvtHandler( void ); -static void HW_IPCC_ZIGBEE_StackNotifEvtHandler( void ); -static void HW_IPCC_ZIGBEE_StackM0RequestHandler( void ); -#endif - /* Public function definition -----------------------------------------------*/ /****************************************************************************** * INTERRUPT HANDLER ******************************************************************************/ -void HW_IPCC_Rx_Handler( void ) +void IPCC_C1_RX_IRQHandler( void ) { if (HW_IPCC_RX_PENDING( HW_IPCC_SYSTEM_EVENT_CHANNEL )) { HW_IPCC_SYS_EvtHandler(); } -#ifdef MAC_802_15_4_WB - else if (HW_IPCC_RX_PENDING( HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL )) - { - HW_IPCC_MAC_802_15_4_NotEvtHandler(); - } -#endif /* MAC_802_15_4_WB */ #ifdef THREAD_WB else if (HW_IPCC_RX_PENDING( HW_IPCC_THREAD_NOTIFICATION_ACK_CHANNEL )) { @@ -114,16 +96,6 @@ void HW_IPCC_Rx_Handler( void ) HW_IPCC_LLD_BLE_ReceiveM0CmdHandler(); } #endif /* LLD_TESTS_WB */ -#ifdef ZIGBEE_WB - else if (HW_IPCC_RX_PENDING( HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL )) - { - HW_IPCC_ZIGBEE_StackNotifEvtHandler(); - } - else if (HW_IPCC_RX_PENDING( HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL )) - { - HW_IPCC_ZIGBEE_StackM0RequestHandler(); - } -#endif /* ZIGBEE_WB */ else if (HW_IPCC_RX_PENDING( HW_IPCC_BLE_EVENT_CHANNEL )) { HW_IPCC_BLE_EvtHandler(); @@ -132,22 +104,14 @@ void HW_IPCC_Rx_Handler( void ) { HW_IPCC_TRACES_EvtHandler(); } - - return; } -void HW_IPCC_Tx_Handler( void ) +void IPCC_C1_TX_IRQHandler( void ) { if (HW_IPCC_TX_PENDING( HW_IPCC_SYSTEM_CMD_RSP_CHANNEL )) { HW_IPCC_SYS_CmdEvtHandler(); } -#ifdef MAC_802_15_4_WB - else if (HW_IPCC_TX_PENDING( HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL )) - { - HW_IPCC_MAC_802_15_4_CmdEvtHandler(); - } -#endif /* MAC_802_15_4_WB */ #ifdef THREAD_WB else if (HW_IPCC_TX_PENDING( HW_IPCC_THREAD_OT_CMD_RSP_CHANNEL )) { @@ -157,12 +121,6 @@ void HW_IPCC_Tx_Handler( void ) #ifdef LLD_TESTS_WB // No TX handler for LLD tests #endif /* LLD_TESTS_WB */ -#ifdef ZIGBEE_WB - if (HW_IPCC_TX_PENDING( HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL )) - { - HW_IPCC_ZIGBEE_CmdEvtHandler(); - } -#endif /* ZIGBEE_WB */ else if (HW_IPCC_TX_PENDING( HW_IPCC_MM_RELEASE_BUFFER_CHANNEL )) { HW_IPCC_MM_FreeBufHandler(); @@ -171,8 +129,6 @@ void HW_IPCC_Tx_Handler( void ) { HW_IPCC_BLE_AclDataEvtHandler(); } - - return; } /****************************************************************************** * GENERAL @@ -204,8 +160,6 @@ void HW_IPCC_Enable( void ) __SEV( ); /* Set the internal event flag and send an event to the CPU2 */ __WFE( ); /* Clear the internal event flag */ LL_PWR_EnableBootC2( ); - - return; } void HW_IPCC_Init( void ) @@ -217,8 +171,6 @@ void HW_IPCC_Init( void ) HAL_NVIC_EnableIRQ(IPCC_C1_RX_IRQn); HAL_NVIC_EnableIRQ(IPCC_C1_TX_IRQn); - - return; } /****************************************************************************** @@ -227,15 +179,11 @@ void HW_IPCC_Init( void ) void HW_IPCC_BLE_Init( void ) { LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_BLE_EVENT_CHANNEL ); - - return; } void HW_IPCC_BLE_SendCmd( void ) { LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_BLE_CMD_CHANNEL ); - - return; } static void HW_IPCC_BLE_EvtHandler( void ) @@ -243,16 +191,12 @@ static void HW_IPCC_BLE_EvtHandler( void ) HW_IPCC_BLE_RxEvtNot(); LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_BLE_EVENT_CHANNEL ); - - return; } void HW_IPCC_BLE_SendAclData( void ) { LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_HCI_ACL_DATA_CHANNEL ); LL_C1_IPCC_EnableTransmitChannel( IPCC, HW_IPCC_HCI_ACL_DATA_CHANNEL ); - - return; } static void HW_IPCC_BLE_AclDataEvtHandler( void ) @@ -260,8 +204,6 @@ static void HW_IPCC_BLE_AclDataEvtHandler( void ) LL_C1_IPCC_DisableTransmitChannel( IPCC, HW_IPCC_HCI_ACL_DATA_CHANNEL ); HW_IPCC_BLE_AclDataAckNot(); - - return; } __weak void HW_IPCC_BLE_AclDataAckNot( void ){}; @@ -273,16 +215,12 @@ __weak void HW_IPCC_BLE_RxEvtNot( void ){}; void HW_IPCC_SYS_Init( void ) { LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_SYSTEM_EVENT_CHANNEL ); - - return; } void HW_IPCC_SYS_SendCmd( void ) { LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_SYSTEM_CMD_RSP_CHANNEL ); LL_C1_IPCC_EnableTransmitChannel( IPCC, HW_IPCC_SYSTEM_CMD_RSP_CHANNEL ); - - return; } static void HW_IPCC_SYS_CmdEvtHandler( void ) @@ -290,8 +228,6 @@ static void HW_IPCC_SYS_CmdEvtHandler( void ) LL_C1_IPCC_DisableTransmitChannel( IPCC, HW_IPCC_SYSTEM_CMD_RSP_CHANNEL ); HW_IPCC_SYS_CmdEvtNot(); - - return; } static void HW_IPCC_SYS_EvtHandler( void ) @@ -299,61 +235,11 @@ static void HW_IPCC_SYS_EvtHandler( void ) HW_IPCC_SYS_EvtNot(); LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_SYSTEM_EVENT_CHANNEL ); - - return; } __weak void HW_IPCC_SYS_CmdEvtNot( void ){}; __weak void HW_IPCC_SYS_EvtNot( void ){}; -/****************************************************************************** - * MAC 802.15.4 - ******************************************************************************/ -#ifdef MAC_802_15_4_WB -void HW_IPCC_MAC_802_15_4_Init( void ) -{ - LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL ); - - return; -} - -void HW_IPCC_MAC_802_15_4_SendCmd( void ) -{ - LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL ); - LL_C1_IPCC_EnableTransmitChannel( IPCC, HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL ); - - return; -} - -void HW_IPCC_MAC_802_15_4_SendAck( void ) -{ - LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL ); - LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL ); - - return; -} - -static void HW_IPCC_MAC_802_15_4_CmdEvtHandler( void ) -{ - LL_C1_IPCC_DisableTransmitChannel( IPCC, HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL ); - - HW_IPCC_MAC_802_15_4_CmdEvtNot(); - - return; -} - -static void HW_IPCC_MAC_802_15_4_NotEvtHandler( void ) -{ - LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL ); - - HW_IPCC_MAC_802_15_4_EvtNot(); - - return; -} -__weak void HW_IPCC_MAC_802_15_4_CmdEvtNot( void ){}; -__weak void HW_IPCC_MAC_802_15_4_EvtNot( void ){}; -#endif - /****************************************************************************** * THREAD ******************************************************************************/ @@ -393,8 +279,6 @@ void HW_IPCC_THREAD_CliSendAck( void ) { LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_THREAD_CLI_NOTIFICATION_ACK_CHANNEL ); LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_THREAD_CLI_NOTIFICATION_ACK_CHANNEL ); - - return; } static void HW_IPCC_OT_CmdEvtHandler( void ) @@ -402,8 +286,6 @@ static void HW_IPCC_OT_CmdEvtHandler( void ) LL_C1_IPCC_DisableTransmitChannel( IPCC, HW_IPCC_THREAD_OT_CMD_RSP_CHANNEL ); HW_IPCC_OT_CmdEvtNot(); - - return; } static void HW_IPCC_THREAD_NotEvtHandler( void ) @@ -411,8 +293,6 @@ static void HW_IPCC_THREAD_NotEvtHandler( void ) LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_THREAD_NOTIFICATION_ACK_CHANNEL ); HW_IPCC_THREAD_EvtNot(); - - return; } static void HW_IPCC_THREAD_CliNotEvtHandler( void ) @@ -420,8 +300,6 @@ static void HW_IPCC_THREAD_CliNotEvtHandler( void ) LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_THREAD_CLI_NOTIFICATION_ACK_CHANNEL ); HW_IPCC_THREAD_CliEvtNot(); - - return; } __weak void HW_IPCC_OT_CmdEvtNot( void ){}; @@ -438,7 +316,6 @@ void HW_IPCC_LLDTESTS_Init( void ) { LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_LLDTESTS_CLI_RSP_CHANNEL ); LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_LLDTESTS_M0_CMD_CHANNEL ); - return; } void HW_IPCC_LLDTESTS_SendCliCmd( void ) @@ -451,28 +328,24 @@ static void HW_IPCC_LLDTESTS_ReceiveCliRspHandler( void ) { LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_LLDTESTS_CLI_RSP_CHANNEL ); HW_IPCC_LLDTESTS_ReceiveCliRsp(); - return; } void HW_IPCC_LLDTESTS_SendCliRspAck( void ) { LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_LLDTESTS_CLI_RSP_CHANNEL ); LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_LLDTESTS_CLI_RSP_CHANNEL ); - return; } static void HW_IPCC_LLDTESTS_ReceiveM0CmdHandler( void ) { LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_LLDTESTS_M0_CMD_CHANNEL ); HW_IPCC_LLDTESTS_ReceiveM0Cmd(); - return; } void HW_IPCC_LLDTESTS_SendM0CmdAck( void ) { LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_LLDTESTS_M0_CMD_CHANNEL ); LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_LLDTESTS_M0_CMD_CHANNEL ); - return; } __weak void HW_IPCC_LLDTESTS_ReceiveCliRsp( void ){}; __weak void HW_IPCC_LLDTESTS_ReceiveM0Cmd( void ){}; @@ -486,13 +359,11 @@ void HW_IPCC_LLD_BLE_Init( void ) { LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_LLD_BLE_RSP_CHANNEL ); LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_LLD_BLE_M0_CMD_CHANNEL ); - return; } void HW_IPCC_LLD_BLE_SendCliCmd( void ) { LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_LLD_BLE_CLI_CMD_CHANNEL ); - return; } /*static void HW_IPCC_LLD_BLE_ReceiveCliRspHandler( void ) @@ -506,21 +377,18 @@ void HW_IPCC_LLD_BLE_SendCliRspAck( void ) { LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_LLD_BLE_CLI_RSP_CHANNEL ); LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_LLD_BLE_CLI_RSP_CHANNEL ); - return; } static void HW_IPCC_LLD_BLE_ReceiveM0CmdHandler( void ) { //LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_LLD_BLE_M0_CMD_CHANNEL ); HW_IPCC_LLD_BLE_ReceiveM0Cmd(); - return; } void HW_IPCC_LLD_BLE_SendM0CmdAck( void ) { LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_LLD_BLE_M0_CMD_CHANNEL ); //LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_LLD_BLE_M0_CMD_CHANNEL ); - return; } __weak void HW_IPCC_LLD_BLE_ReceiveCliRsp( void ){}; __weak void HW_IPCC_LLD_BLE_ReceiveM0Cmd( void ){}; @@ -529,93 +397,22 @@ __weak void HW_IPCC_LLD_BLE_ReceiveM0Cmd( void ){}; void HW_IPCC_LLD_BLE_SendCmd( void ) { LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_LLD_BLE_CMD_CHANNEL ); - return; } static void HW_IPCC_LLD_BLE_ReceiveRspHandler( void ) { LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_LLD_BLE_RSP_CHANNEL ); HW_IPCC_LLD_BLE_ReceiveRsp(); - return; } void HW_IPCC_LLD_BLE_SendRspAck( void ) { LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_LLD_BLE_RSP_CHANNEL ); LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_LLD_BLE_RSP_CHANNEL ); - return; } #endif /* LLD_BLE_WB */ -/****************************************************************************** - * ZIGBEE - ******************************************************************************/ -#ifdef ZIGBEE_WB -void HW_IPCC_ZIGBEE_Init( void ) -{ - LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL ); - LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL ); - - return; -} - -void HW_IPCC_ZIGBEE_SendM4RequestToM0( void ) -{ - LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL ); - LL_C1_IPCC_EnableTransmitChannel( IPCC, HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL ); - - return; -} - -void HW_IPCC_ZIGBEE_SendM4AckToM0Notify( void ) -{ - LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL ); - LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL ); - - return; -} - -static void HW_IPCC_ZIGBEE_CmdEvtHandler( void ) -{ - LL_C1_IPCC_DisableTransmitChannel( IPCC, HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL ); - - HW_IPCC_ZIGBEE_RecvAppliAckFromM0(); - - return; -} - -static void HW_IPCC_ZIGBEE_StackNotifEvtHandler( void ) -{ - LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL ); - - HW_IPCC_ZIGBEE_RecvM0NotifyToM4(); - - return; -} - -static void HW_IPCC_ZIGBEE_StackM0RequestHandler( void ) -{ - LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL ); - - HW_IPCC_ZIGBEE_RecvM0RequestToM4(); - - return; -} - -void HW_IPCC_ZIGBEE_SendM4AckToM0Request( void ) -{ - LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL ); - LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL ); - - return; -} - -__weak void HW_IPCC_ZIGBEE_RecvAppliAckFromM0( void ){}; -__weak void HW_IPCC_ZIGBEE_RecvM0NotifyToM4( void ){}; -__weak void HW_IPCC_ZIGBEE_RecvM0RequestToM4( void ){}; -#endif /* ZIGBEE_WB */ - /****************************************************************************** * MEMORY MANAGER ******************************************************************************/ @@ -632,8 +429,6 @@ void HW_IPCC_MM_SendFreeBuf( void (*cb)( void ) ) LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_MM_RELEASE_BUFFER_CHANNEL ); } - - return; } static void HW_IPCC_MM_FreeBufHandler( void ) @@ -643,8 +438,6 @@ static void HW_IPCC_MM_FreeBufHandler( void ) FreeBufCb(); LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_MM_RELEASE_BUFFER_CHANNEL ); - - return; } /****************************************************************************** @@ -662,8 +455,7 @@ static void HW_IPCC_TRACES_EvtHandler( void ) HW_IPCC_TRACES_EvtNot(); LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_TRACES_CHANNEL ); - - return; } __weak void HW_IPCC_TRACES_EvtNot( void ){}; +#endif /* STM32WBxx */ diff --git a/src/utility/STM32Cube_FW/mbox_def.h b/src/utility/STM32Cube_FW/mbox_def.h index 68b71f9c..0c974f8f 100644 --- a/src/utility/STM32Cube_FW/mbox_def.h +++ b/src/utility/STM32Cube_FW/mbox_def.h @@ -106,12 +106,6 @@ extern "C" { uint8_t *m0cmd_buffer; } MB_BleLldTable_t; - typedef struct - { - uint8_t *notifM0toM4_buffer; - uint8_t *appliCmdM4toM0_buffer; - uint8_t *requestM0toM4_buffer; - } MB_ZigbeeTable_t; /** * msg * [0:7] = cmd/evt @@ -139,13 +133,6 @@ extern "C" { uint8_t *traces_queue; } MB_TracesTable_t; - typedef struct - { - uint8_t *p_cmdrsp_buffer; - uint8_t *p_notack_buffer; - uint8_t *evt_queue; - } MB_Mac_802_15_4_t; - typedef struct { MB_DeviceInfoTable_t *p_device_info_table; @@ -154,8 +141,6 @@ extern "C" { MB_SysTable_t *p_sys_table; MB_MemManagerTable_t *p_mem_manager_table; MB_TracesTable_t *p_traces_table; - MB_Mac_802_15_4_t *p_mac_802_15_4_table; - MB_ZigbeeTable_t *p_zigbee_table; MB_LldTestsTable_t *p_lld_tests_table; MB_BleLldTable_t *p_ble_lld_table; } MB_RefTable_t; @@ -199,15 +184,6 @@ typedef struct * | | * |<---HW_IPCC_SYSTEM_EVENT_CHANNEL-----------------| * | | - * | (ZIGBEE) | - * |----HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL------------>| - * | | - * |----HW_IPCC_ZIGBEE_CMD_CLI_CHANNEL-------------->| - * | | - * |<---HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL-------| - * | | - * |<---HW_IPCC_ZIGBEE_CLI_NOTIF_ACK_CHANNEL---------| - * | | * | (THREAD) | * |----HW_IPCC_THREAD_OT_CMD_RSP_CHANNEL----------->| * | | @@ -231,11 +207,6 @@ typedef struct * | | * |<---HW_IPCC_BLE_LLD_M0_CMD_CHANNEL---------------| * | | - * | (MAC) | - * |----HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL-------->| - * | | - * |<---HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL| - * | | * | (BUFFER) | * |----HW_IPCC_MM_RELEASE_BUFFER_CHANNE------------>| * | | @@ -253,8 +224,6 @@ typedef struct #define HW_IPCC_BLE_CMD_CHANNEL LL_IPCC_CHANNEL_1 #define HW_IPCC_SYSTEM_CMD_RSP_CHANNEL LL_IPCC_CHANNEL_2 #define HW_IPCC_THREAD_OT_CMD_RSP_CHANNEL LL_IPCC_CHANNEL_3 -#define HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL LL_IPCC_CHANNEL_3 -#define HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL LL_IPCC_CHANNEL_3 #define HW_IPCC_MM_RELEASE_BUFFER_CHANNEL LL_IPCC_CHANNEL_4 #define HW_IPCC_THREAD_CLI_CMD_CHANNEL LL_IPCC_CHANNEL_5 #define HW_IPCC_LLDTESTS_CLI_CMD_CHANNEL LL_IPCC_CHANNEL_5 @@ -266,8 +235,6 @@ typedef struct #define HW_IPCC_BLE_EVENT_CHANNEL LL_IPCC_CHANNEL_1 #define HW_IPCC_SYSTEM_EVENT_CHANNEL LL_IPCC_CHANNEL_2 #define HW_IPCC_THREAD_NOTIFICATION_ACK_CHANNEL LL_IPCC_CHANNEL_3 -#define HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL LL_IPCC_CHANNEL_3 -#define HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL LL_IPCC_CHANNEL_3 #define HW_IPCC_LLDTESTS_M0_CMD_CHANNEL LL_IPCC_CHANNEL_3 #define HW_IPCC_BLE_LLD_M0_CMD_CHANNEL LL_IPCC_CHANNEL_3 #define HW_IPCC_TRACES_CHANNEL LL_IPCC_CHANNEL_4 @@ -275,6 +242,5 @@ typedef struct #define HW_IPCC_LLDTESTS_CLI_RSP_CHANNEL LL_IPCC_CHANNEL_5 #define HW_IPCC_BLE_LLD_CLI_RSP_CHANNEL LL_IPCC_CHANNEL_5 #define HW_IPCC_BLE_LLD_RSP_CHANNEL LL_IPCC_CHANNEL_5 -#define HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL LL_IPCC_CHANNEL_5 #endif /*__MBOX_H */ diff --git a/src/utility/STM32Cube_FW/shci.c b/src/utility/STM32Cube_FW/shci.c index 301db76d..a8475222 100644 --- a/src/utility/STM32Cube_FW/shci.c +++ b/src/utility/STM32Cube_FW/shci.c @@ -16,7 +16,7 @@ ****************************************************************************** */ - +#if defined(STM32WBxx) /* Includes ------------------------------------------------------------------*/ #include "stm32_wpan_common.h" @@ -352,24 +352,6 @@ SHCI_CmdStatus_t SHCI_C2_BLE_LLD_Init( uint8_t param_size, uint8_t * p_param ) return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); } -SHCI_CmdStatus_t SHCI_C2_ZIGBEE_Init( void ) -{ - /** - * Buffer is large enough to hold command complete without payload - */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; - TL_EvtPacket_t * p_rsp; - - p_rsp = (TL_EvtPacket_t *)local_buffer; - - shci_send( SHCI_OPCODE_C2_ZIGBEE_INIT, - 0, - 0, - p_rsp ); - - return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); -} - SHCI_CmdStatus_t SHCI_C2_DEBUG_Init( SHCI_C2_DEBUG_Init_Cmd_Packet_t *pCmdPacket ) { /** @@ -527,24 +509,6 @@ SHCI_CmdStatus_t SHCI_C2_RADIO_AllowLowPower( SHCI_C2_FLASH_Ip_t Ip,uint8_t Fla return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); } -SHCI_CmdStatus_t SHCI_C2_MAC_802_15_4_Init( void ) -{ - /** - * Buffer is large enough to hold command complete without payload - */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; - TL_EvtPacket_t * p_rsp; - - p_rsp = (TL_EvtPacket_t *)local_buffer; - - shci_send( SHCI_OPCODE_C2_MAC_802_15_4_INIT, - 0, - 0, - p_rsp ); - - return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); -} - SHCI_CmdStatus_t SHCI_C2_Reinit( void ) { /** @@ -739,3 +703,4 @@ SHCI_CmdStatus_t SHCI_GetWirelessFwInfo( WirelessFwInfo_t* pWirelessInfo ) return (SHCI_Success); } +#endif /* STM32WBxx */ diff --git a/src/utility/STM32Cube_FW/shci.h b/src/utility/STM32Cube_FW/shci.h index 7ca90210..a0f1e4d2 100644 --- a/src/utility/STM32Cube_FW/shci.h +++ b/src/utility/STM32Cube_FW/shci.h @@ -49,7 +49,6 @@ extern "C" { ERR_BLE_INIT = 0, /* This event is currently not reported by the CPU2 */ ERR_THREAD_LLD_FATAL_ERROR = 125, /* The LLD driver used on 802_15_4 detected a fatal error */ ERR_THREAD_UNKNOWN_CMD = 126, /* The command send by the CPU1 to control the Thread stack is unknown */ - ERR_ZIGBEE_UNKNOWN_CMD = 200, /* The command send by the CPU1 to control the Zigbee stack is unknown */ } SCHI_SystemErrCode_t; #define SHCI_EVTCODE ( 0xFF ) @@ -216,9 +215,7 @@ extern "C" { SHCI_OCF_C2_FLASH_STORE_DATA, SHCI_OCF_C2_FLASH_ERASE_DATA, SHCI_OCF_C2_RADIO_ALLOW_LOW_POWER, - SHCI_OCF_C2_MAC_802_15_4_INIT, SHCI_OCF_C2_REINIT, - SHCI_OCF_C2_ZIGBEE_INIT, SHCI_OCF_C2_LLD_TESTS_INIT, SHCI_OCF_C2_EXTPA_CONFIG, SHCI_OCF_C2_SET_FLASH_ACTIVITY_CONTROL, @@ -436,7 +433,7 @@ extern "C" { * PrWriteListSize * NOTE: This parameter is ignored by the CPU2 when the parameter "Options" is set to "LL_only" ( see Options description in that structure ) * - * Maximum number of supported �prepare write request� + * Maximum number of supported "prepare write request" * - Min value: given by the macro DEFAULT_PREP_WRITE_LIST_SIZE * - Max value: a value higher than the minimum required can be specified, but it is not recommended */ @@ -503,7 +500,7 @@ extern "C" { * MaxConnEventLength * This parameter determines the maximum duration of a slave connection event. When this duration is reached the slave closes * the current connections event (whatever is the CE_length parameter specified by the master in HCI_CREATE_CONNECTION HCI command), - * expressed in units of 625/256 �s (~2.44 �s) + * expressed in units of 625/256 µs (~2.44 µs) * - Min value: 0 (if 0 is specified, the master and slave perform only a single TX-RX exchange per connection event) * - Max value: 1638400 (4000 ms). A higher value can be specified (max 0xFFFFFFFF) but results in a maximum connection time * of 4000 ms as specified. In this case the parameter is not applied, and the predicted CE length calculated on slave is not shortened @@ -512,7 +509,7 @@ extern "C" { /** * HsStartupTime - * Startup time of the high speed (16 or 32 MHz) crystal oscillator in units of 625/256 �s (~2.44 �s). + * Startup time of the high speed (16 or 32 MHz) crystal oscillator in units of 625/256 µs (~2.44 µs). * - Min value: 0 * - Max value: 820 (~2 ms). A higher value can be specified, but the value that implemented in stack is forced to ~2 ms */ @@ -678,8 +675,6 @@ extern "C" { { uint8_t thread_config; uint8_t ble_config; - uint8_t mac_802_15_4_config; - uint8_t zigbee_config; } SHCI_C2_DEBUG_TracesConfig_t; typedef PACKED_STRUCT @@ -743,8 +738,6 @@ extern "C" { { BLE_ENABLE, THREAD_ENABLE, - ZIGBEE_ENABLE, - MAC_ENABLE, } SHCI_C2_CONCURRENT_Mode_Param_t; /** No response parameters*/ @@ -767,18 +760,13 @@ extern "C" { { BLE_IP, THREAD_IP, - ZIGBEE_IP, } SHCI_C2_FLASH_Ip_t; /** No response parameters*/ #define SHCI_OPCODE_C2_RADIO_ALLOW_LOW_POWER (( SHCI_OGF << 10) + SHCI_OCF_C2_RADIO_ALLOW_LOW_POWER) -#define SHCI_OPCODE_C2_MAC_802_15_4_INIT (( SHCI_OGF << 10) + SHCI_OCF_C2_MAC_802_15_4_INIT) - #define SHCI_OPCODE_C2_REINIT (( SHCI_OGF << 10) + SHCI_OCF_C2_REINIT) -#define SHCI_OPCODE_C2_ZIGBEE_INIT (( SHCI_OGF << 10) + SHCI_OCF_C2_ZIGBEE_INIT) - #define SHCI_OPCODE_C2_LLD_TESTS_INIT (( SHCI_OGF << 10) + SHCI_OCF_C2_LLD_TESTS_INIT) #define SHCI_OPCODE_C2_BLE_LLD_INIT (( SHCI_OGF << 10) + SHCI_OCF_C2_BLE_LLD_INIT) @@ -893,7 +881,7 @@ extern "C" { #define FUS_DEVICE_INFO_TABLE_VALIDITY_KEYWORD (0xA94656B9) /* - * At startup, the informations relative to the wireless binary are stored in RAM trough a structure defined by + * At startup, the information relative to the wireless binary are stored in RAM through a structure defined by * MB_WirelessFwInfoTable_t.This structure contains 4 fields (Version,MemorySize, Stack_info and a reserved part) * each of those coded on 32 bits as shown on the table below: * @@ -949,9 +937,6 @@ extern "C" { #define INFO_STACK_TYPE_BLE_HCI_EXT_ADV 0x07 #define INFO_STACK_TYPE_THREAD_FTD 0x10 #define INFO_STACK_TYPE_THREAD_MTD 0x11 -#define INFO_STACK_TYPE_ZIGBEE_FFD 0x30 -#define INFO_STACK_TYPE_ZIGBEE_RFD 0x31 -#define INFO_STACK_TYPE_MAC 0x40 #define INFO_STACK_TYPE_BLE_THREAD_FTD_STATIC 0x50 #define INFO_STACK_TYPE_BLE_THREAD_FTD_DYAMIC 0x51 #define INFO_STACK_TYPE_802154_LLD_TESTS 0x60 @@ -960,12 +945,7 @@ extern "C" { #define INFO_STACK_TYPE_BLE_LLD_TESTS 0x63 #define INFO_STACK_TYPE_BLE_RLV 0x64 #define INFO_STACK_TYPE_802154_RLV 0x65 -#define INFO_STACK_TYPE_BLE_ZIGBEE_FFD_STATIC 0x70 -#define INFO_STACK_TYPE_BLE_ZIGBEE_RFD_STATIC 0x71 -#define INFO_STACK_TYPE_BLE_ZIGBEE_FFD_DYNAMIC 0x78 -#define INFO_STACK_TYPE_BLE_ZIGBEE_RFD_DYNAMIC 0x79 #define INFO_STACK_TYPE_RLV 0x80 -#define INFO_STACK_TYPE_BLE_MAC_STATIC 0x90 typedef struct { /** @@ -1139,7 +1119,7 @@ typedef struct { * @brief Starts the LLD tests CLI * * @param param_size : Nb of bytes - * @param p_param : pointeur with data to give from M4 to M0 + * @param p_param : pointer with data to give from M4 to M0 * @retval Status */ SHCI_CmdStatus_t SHCI_C2_LLDTESTS_Init( uint8_t param_size, uint8_t * p_param ); @@ -1149,20 +1129,11 @@ typedef struct { * @brief Starts the LLD tests BLE * * @param param_size : Nb of bytes - * @param p_param : pointeur with data to give from M4 to M0 + * @param p_param : pointer with data to give from M4 to M0 * @retval Status */ SHCI_CmdStatus_t SHCI_C2_BLE_LLD_Init( uint8_t param_size, uint8_t * p_param ); - /** - * SHCI_C2_ZIGBEE_Init - * @brief Starts the Zigbee Stack - * - * @param None - * @retval Status - */ - SHCI_CmdStatus_t SHCI_C2_ZIGBEE_Init( void ); - /** * SHCI_C2_DEBUG_Init * @brief Starts the Traces @@ -1237,16 +1208,6 @@ typedef struct { */ SHCI_CmdStatus_t SHCI_C2_RADIO_AllowLowPower( SHCI_C2_FLASH_Ip_t Ip,uint8_t FlagRadioLowPowerOn); - - /** - * SHCI_C2_MAC_802_15_4_Init - * @brief Starts the MAC 802.15.4 on M0 - * - * @param None - * @retval Status - */ - SHCI_CmdStatus_t SHCI_C2_MAC_802_15_4_Init( void ); - /** * SHCI_GetWirelessFwInfo * @brief This function read back the informations relative to the wireless binary loaded. diff --git a/src/utility/STM32Cube_FW/shci_tl.c b/src/utility/STM32Cube_FW/shci_tl.c index 449b8b16..b3cee004 100644 --- a/src/utility/STM32Cube_FW/shci_tl.c +++ b/src/utility/STM32Cube_FW/shci_tl.c @@ -16,12 +16,13 @@ ****************************************************************************** */ - +#if defined(STM32WBxx) /* Includes ------------------------------------------------------------------*/ #include "stm32_wpan_common.h" #include "stm_list.h" #include "shci_tl.h" +#include "stm32_def.h" /* Private typedef -----------------------------------------------------------*/ typedef enum @@ -70,8 +71,6 @@ void shci_init(void(* UserEvtRx)(void* pData), void* pConf) shci_register_io_bus (&shciContext.io); TlInit((TL_CmdPacket_t *)(((SHCI_TL_HciInitConf_t *)pConf)->p_cmdbuffer)); - - return; } void shci_user_evt_proc(void) @@ -127,8 +126,6 @@ void shci_user_evt_proc(void) shci_notify_asynch_evt((void*) &SHciAsynchEventQueue); } - - return; } void shci_resume_flow( void ) @@ -140,8 +137,6 @@ void shci_resume_flow( void ) * be called */ shci_notify_asynch_evt((void*) &SHciAsynchEventQueue); - - return; } void shci_send( uint16_t cmd_code, uint8_t len_cmd_payload, uint8_t * p_cmd_payload, TL_EvtPacket_t * p_rsp ) @@ -164,8 +159,20 @@ void shci_send( uint16_t cmd_code, uint8_t len_cmd_payload, uint8_t * p_cmd_payl memcpy( &(p_rsp->evtserial), pCmdBuffer, ((TL_EvtSerial_t*)pCmdBuffer)->evt.plen + TL_EVT_HDR_SIZE ); Cmd_SetStatus(SHCI_TL_CmdAvailable); +} + +void shci_notify_asynch_evt(void *pdata) +{ + UNUSED(pdata); + /* Need to parse data in future version */ + shci_user_evt_proc(); +} - return; +void shci_register_io_bus(tSHciIO *fops) +{ + /* Register IO bus services */ + fops->Init = TL_SYS_Init; + fops->Send = TL_SYS_SendCmd; } /* Private functions ---------------------------------------------------------*/ @@ -190,8 +197,6 @@ static void TlInit( TL_CmdPacket_t * p_cmdbuffer ) Conf.IoBusCallBackUserEvt = TlUserEvtReceived; shciContext.io.Init(&Conf); } - - return; } static void Cmd_SetStatus(SHCI_TL_CmdStatus_t shcicmdstatus) @@ -212,24 +217,18 @@ static void Cmd_SetStatus(SHCI_TL_CmdStatus_t shcicmdstatus) StatusNotCallBackFunction( SHCI_TL_CmdAvailable ); } } - - return; } static void TlCmdEvtReceived(TL_EvtPacket_t *shcievt) { (void)(shcievt); shci_cmd_resp_release(0); /**< Notify the application the Cmd response has been received */ - - return; } static void TlUserEvtReceived(TL_EvtPacket_t *shcievt) { LST_insert_tail(&SHciAsynchEventQueue, (tListNode *)shcievt); shci_notify_asynch_evt((void*) &SHciAsynchEventQueue); /**< Notify the application a full HCI event has been received */ - - return; } /* Weak implementation ----------------------------------------------------------------*/ @@ -239,8 +238,6 @@ __WEAK void shci_cmd_resp_wait(uint32_t timeout) CmdRspStatusFlag = SHCI_TL_CMD_RESP_WAIT; while(CmdRspStatusFlag != SHCI_TL_CMD_RESP_RELEASE); - - return; } __WEAK void shci_cmd_resp_release(uint32_t flag) @@ -248,7 +245,5 @@ __WEAK void shci_cmd_resp_release(uint32_t flag) (void)flag; CmdRspStatusFlag = SHCI_TL_CMD_RESP_RELEASE; - - return; } - +#endif /* STM32WBxx */ diff --git a/src/utility/STM32Cube_FW/stm32_wpan_common.h b/src/utility/STM32Cube_FW/stm32_wpan_common.h index f407bb98..5a2b2a55 100644 --- a/src/utility/STM32Cube_FW/stm32_wpan_common.h +++ b/src/utility/STM32Cube_FW/stm32_wpan_common.h @@ -25,19 +25,9 @@ extern "C" { #endif -#if defined ( __CC_ARM )||defined (__ARMCC_VERSION) - #define __ASM __asm /*!< asm keyword for ARM Compiler */ - #define __INLINE __inline /*!< inline keyword for ARM Compiler */ - #define __STATIC_INLINE static __inline -#elif defined ( __ICCARM__ ) - #define __ASM __asm /*!< asm keyword for IAR Compiler */ - #define __INLINE inline /*!< inline keyword for IAR Compiler. Only available in High optimization mode! */ - #define __STATIC_INLINE static inline -#elif defined ( __GNUC__ ) - #define __ASM __asm /*!< asm keyword for GNU Compiler */ - #define __INLINE inline /*!< inline keyword for GNU Compiler */ - #define __STATIC_INLINE static inline -#endif +#define __ASM __asm /*!< asm keyword for GNU Compiler */ +#define __INLINE inline /*!< inline keyword for GNU Compiler */ +#define __STATIC_INLINE static inline #include <stdint.h> #include <string.h> @@ -140,29 +130,8 @@ extern "C" { /* ----------------------------------- * * Packed usage (compiler dependent) * * ----------------------------------- */ -#undef PACKED__ #undef PACKED_STRUCT - -#if defined ( __CC_ARM ) - #if defined ( __GNUC__ ) - /* GNU extension */ - #define PACKED__ __attribute__((packed)) - #define PACKED_STRUCT struct PACKED__ - #elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050U) - #define PACKED__ __attribute__((packed)) - #define PACKED_STRUCT struct PACKED__ - #else - #define PACKED__(TYPE) __packed TYPE - #define PACKED_STRUCT PACKED__(struct) - #endif -#elif defined ( __GNUC__ ) - #define PACKED__ __attribute__((packed)) - #define PACKED_STRUCT struct PACKED__ -#elif defined (__ICCARM__) - #define PACKED_STRUCT __packed struct -#else - #define PACKED_STRUCT __packed struct -#endif +#define PACKED_STRUCT struct __packed #ifdef __cplusplus } diff --git a/src/utility/STM32Cube_FW/stm_list.c b/src/utility/STM32Cube_FW/stm_list.c index 4c928647..98924414 100644 --- a/src/utility/STM32Cube_FW/stm_list.c +++ b/src/utility/STM32Cube_FW/stm_list.c @@ -16,13 +16,13 @@ ****************************************************************************** */ - +#if defined(STM32WBxx) /****************************************************************************** * Include Files ******************************************************************************/ -#include "utilities_common.h" - #include "stm_list.h" +#include "cmsis_gcc.h" +#include "stm32_wpan_common.h" /****************************************************************************** * Function Definitions @@ -33,20 +33,20 @@ void LST_init_head (tListNode * listHead) listHead->prev = listHead; } -uint8_t LST_is_empty (tListNode * listHead) +bool LST_is_empty (tListNode * listHead) { uint32_t primask_bit; - uint8_t return_value; + bool return_value; primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ if(listHead->next == listHead) { - return_value = TRUE; + return_value = true; } else { - return_value = FALSE; + return_value = false; } __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ @@ -204,3 +204,4 @@ void LST_get_prev_node (tListNode * ref_node, tListNode ** node) __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ } +#endif /* STM32WBxx */ diff --git a/src/utility/STM32Cube_FW/stm_list.h b/src/utility/STM32Cube_FW/stm_list.h index b7c3254c..769c2113 100644 --- a/src/utility/STM32Cube_FW/stm_list.h +++ b/src/utility/STM32Cube_FW/stm_list.h @@ -21,6 +21,8 @@ #define _STM_LIST_H_ /* Includes ------------------------------------------------------------------*/ +#include "stdint.h" +#include "stdbool.h" #include "stm32_wpan_common.h" typedef PACKED_STRUCT _tListNode { @@ -30,7 +32,7 @@ typedef PACKED_STRUCT _tListNode { void LST_init_head (tListNode * listHead); -uint8_t LST_is_empty (tListNode * listHead); +bool LST_is_empty (tListNode * listHead); void LST_insert_head (tListNode * listHead, tListNode * node); diff --git a/src/utility/STM32Cube_FW/tl.h b/src/utility/STM32Cube_FW/tl.h index c199bb21..982bb586 100644 --- a/src/utility/STM32Cube_FW/tl.h +++ b/src/utility/STM32Cube_FW/tl.h @@ -202,19 +202,6 @@ typedef struct uint8_t *p_BleLldM0CmdBuffer; } TL_BLE_LLD_Config_t; -typedef struct -{ - uint8_t *p_Mac_802_15_4_CmdRspBuffer; - uint8_t *p_Mac_802_15_4_NotAckBuffer; -} TL_MAC_802_15_4_Config_t; - -typedef struct -{ - uint8_t *p_ZigbeeOtCmdRspBuffer; - uint8_t *p_ZigbeeNotAckBuffer; - uint8_t *p_ZigbeeNotifRequestBuffer; -} TL_ZIGBEE_Config_t; - /** * @brief Contain the BLE HCI Init Configuration * @{ @@ -308,26 +295,6 @@ void TL_MM_EvtDone( TL_EvtPacket_t * hcievt ); void TL_TRACES_Init( void ); void TL_TRACES_EvtReceived( TL_EvtPacket_t * hcievt ); -/****************************************************************************** - * MAC 802.15.4 - ******************************************************************************/ -void TL_MAC_802_15_4_Init( TL_MAC_802_15_4_Config_t *p_Config ); -void TL_MAC_802_15_4_SendCmd( void ); -void TL_MAC_802_15_4_CmdEvtReceived( TL_EvtPacket_t * Otbuffer ); -void TL_MAC_802_15_4_NotReceived( TL_EvtPacket_t * Notbuffer ); -void TL_MAC_802_15_4_SendAck ( void ); - -/****************************************************************************** - * ZIGBEE - ******************************************************************************/ -void TL_ZIGBEE_Init( TL_ZIGBEE_Config_t *p_Config ); -void TL_ZIGBEE_SendM4RequestToM0( void ); -void TL_ZIGBEE_SendM4AckToM0Notify ( void ); -void TL_ZIGBEE_NotReceived( TL_EvtPacket_t * Notbuffer ); -void TL_ZIGBEE_CmdEvtReceived( TL_EvtPacket_t * Otbuffer ); -void TL_ZIGBEE_M0RequestReceived(TL_EvtPacket_t * Otbuffer ); -void TL_ZIGBEE_SendM4AckToM0Request(void); - #ifdef __cplusplus } /* extern "C" */ #endif diff --git a/src/utility/STM32Cube_FW/tl_mbox.c b/src/utility/STM32Cube_FW/tl_mbox.c index fcd7766d..a9abb181 100644 --- a/src/utility/STM32Cube_FW/tl_mbox.c +++ b/src/utility/STM32Cube_FW/tl_mbox.c @@ -16,6 +16,7 @@ ****************************************************************************** */ +#if defined(STM32WBxx) /* Includes ------------------------------------------------------------------*/ #include "stm32_wpan_common.h" #include "hw.h" @@ -51,15 +52,13 @@ PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_BleLldTable_t TL_BleLldTable; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_SysTable_t TL_SysTable; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_MemManagerTable_t TL_MemManagerTable; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_TracesTable_t TL_TracesTable; -PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_Mac_802_15_4_t TL_Mac_802_15_4_Table; -PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_ZigbeeTable_t TL_Zigbee_Table; /**< tables */ PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode FreeBufQueue; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode TracesEvtQueue; PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static uint8_t CsBuffer[sizeof(TL_PacketHeader_t) + TL_EVT_HDR_SIZE + sizeof(TL_CsEvt_t)]; -PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode EvtQueue; -PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode SystemEvtQueue; +PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static tListNode EvtQueue; +PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static tListNode SystemEvtQueue; static tListNode LocalFreeBufQueue; @@ -97,8 +96,6 @@ void TL_Init( void ) TL_RefTable.p_sys_table = &TL_SysTable; TL_RefTable.p_mem_manager_table = &TL_MemManagerTable; TL_RefTable.p_traces_table = &TL_TracesTable; - TL_RefTable.p_mac_802_15_4_table = &TL_Mac_802_15_4_Table; - TL_RefTable.p_zigbee_table = &TL_Zigbee_Table; HW_IPCC_Init(); return; @@ -452,139 +449,6 @@ void TL_BLE_LLD_SendRspAck( void ) } #endif /* BLE_LLD_WB */ -#ifdef MAC_802_15_4_WB -/****************************************************************************** - * MAC 802.15.4 - ******************************************************************************/ -void TL_MAC_802_15_4_Init( TL_MAC_802_15_4_Config_t *p_Config ) -{ - MB_Mac_802_15_4_t * p_mac_802_15_4_table; - - p_mac_802_15_4_table = TL_RefTable.p_mac_802_15_4_table; - - p_mac_802_15_4_table->p_cmdrsp_buffer = p_Config->p_Mac_802_15_4_CmdRspBuffer; - p_mac_802_15_4_table->p_notack_buffer = p_Config->p_Mac_802_15_4_NotAckBuffer; - - HW_IPCC_MAC_802_15_4_Init(); - - return; -} - -void TL_MAC_802_15_4_SendCmd( void ) -{ - ((TL_CmdPacket_t *)(TL_RefTable.p_mac_802_15_4_table->p_cmdrsp_buffer))->cmdserial.type = TL_OTCMD_PKT_TYPE; - - HW_IPCC_MAC_802_15_4_SendCmd(); - - return; -} - -void TL_MAC_802_15_4_SendAck ( void ) -{ - ((TL_CmdPacket_t *)(TL_RefTable.p_mac_802_15_4_table->p_notack_buffer))->cmdserial.type = TL_OTACK_PKT_TYPE; - - HW_IPCC_MAC_802_15_4_SendAck(); - - return; -} - -void HW_IPCC_MAC_802_15_4_CmdEvtNot(void) -{ - TL_MAC_802_15_4_CmdEvtReceived( (TL_EvtPacket_t*)(TL_RefTable.p_mac_802_15_4_table->p_cmdrsp_buffer) ); - - return; -} - -void HW_IPCC_MAC_802_15_4_EvtNot( void ) -{ - TL_MAC_802_15_4_NotReceived( (TL_EvtPacket_t*)(TL_RefTable.p_mac_802_15_4_table->p_notack_buffer) ); - - return; -} - -__WEAK void TL_MAC_802_15_4_CmdEvtReceived( TL_EvtPacket_t * Otbuffer ){}; -__WEAK void TL_MAC_802_15_4_NotReceived( TL_EvtPacket_t * Notbuffer ){}; -#endif - -#ifdef ZIGBEE_WB -/****************************************************************************** - * ZIGBEE - ******************************************************************************/ -void TL_ZIGBEE_Init( TL_ZIGBEE_Config_t *p_Config ) -{ - MB_ZigbeeTable_t * p_zigbee_table; - - p_zigbee_table = TL_RefTable.p_zigbee_table; - p_zigbee_table->appliCmdM4toM0_buffer = p_Config->p_ZigbeeOtCmdRspBuffer; - p_zigbee_table->notifM0toM4_buffer = p_Config->p_ZigbeeNotAckBuffer; - p_zigbee_table->requestM0toM4_buffer = p_Config->p_ZigbeeNotifRequestBuffer; - - HW_IPCC_ZIGBEE_Init(); - - return; -} - -/* Zigbee M4 to M0 Request */ -void TL_ZIGBEE_SendM4RequestToM0( void ) -{ - ((TL_CmdPacket_t *)(TL_RefTable.p_zigbee_table->appliCmdM4toM0_buffer))->cmdserial.type = TL_OTCMD_PKT_TYPE; - - HW_IPCC_ZIGBEE_SendM4RequestToM0(); - - return; -} - -/* Used to receive an ACK from the M0 */ -void HW_IPCC_ZIGBEE_RecvAppliAckFromM0(void) -{ - TL_ZIGBEE_CmdEvtReceived( (TL_EvtPacket_t*)(TL_RefTable.p_zigbee_table->appliCmdM4toM0_buffer) ); - - return; -} - -/* Zigbee notification from M0 to M4 */ -void HW_IPCC_ZIGBEE_RecvM0NotifyToM4( void ) -{ - TL_ZIGBEE_NotReceived( (TL_EvtPacket_t*)(TL_RefTable.p_zigbee_table->notifM0toM4_buffer) ); - - return; -} - -/* Send an ACK to the M0 for a Notification */ -void TL_ZIGBEE_SendM4AckToM0Notify ( void ) -{ - ((TL_CmdPacket_t *)(TL_RefTable.p_zigbee_table->notifM0toM4_buffer))->cmdserial.type = TL_OTACK_PKT_TYPE; - - HW_IPCC_ZIGBEE_SendM4AckToM0Notify(); - - return; -} - -/* Zigbee M0 to M4 Request */ -void HW_IPCC_ZIGBEE_RecvM0RequestToM4( void ) -{ - TL_ZIGBEE_M0RequestReceived( (TL_EvtPacket_t*)(TL_RefTable.p_zigbee_table->requestM0toM4_buffer) ); - - return; -} - -/* Send an ACK to the M0 for a Request */ -void TL_ZIGBEE_SendM4AckToM0Request(void) -{ - ((TL_CmdPacket_t *)(TL_RefTable.p_zigbee_table->requestM0toM4_buffer))->cmdserial.type = TL_OTACK_PKT_TYPE; - - HW_IPCC_ZIGBEE_SendM4AckToM0Request(); - - return; -} - - -__WEAK void TL_ZIGBEE_CmdEvtReceived( TL_EvtPacket_t * Otbuffer ){}; -__WEAK void TL_ZIGBEE_NotReceived( TL_EvtPacket_t * Notbuffer ){}; -#endif - - - /****************************************************************************** * MEMORY MANAGER ******************************************************************************/ @@ -846,3 +710,4 @@ static void OutputDbgTrace(TL_MB_PacketType_t packet_type, uint8_t* buffer) return; } +#endif /* STM32WBxx */ From a3c689a99506126587dfd7285c4b198db4a790e5 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Mon, 12 Dec 2022 17:17:48 +0100 Subject: [PATCH 107/226] fix: include a timeout when waiting for the cmd_resp Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- src/utility/STM32Cube_FW/shci_tl.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/utility/STM32Cube_FW/shci_tl.c b/src/utility/STM32Cube_FW/shci_tl.c index b3cee004..1abd1be9 100644 --- a/src/utility/STM32Cube_FW/shci_tl.c +++ b/src/utility/STM32Cube_FW/shci_tl.c @@ -23,6 +23,7 @@ #include "stm_list.h" #include "shci_tl.h" #include "stm32_def.h" +#include "wiring_time.h" /* Private typedef -----------------------------------------------------------*/ typedef enum @@ -234,10 +235,12 @@ static void TlUserEvtReceived(TL_EvtPacket_t *shcievt) /* Weak implementation ----------------------------------------------------------------*/ __WEAK void shci_cmd_resp_wait(uint32_t timeout) { - (void)timeout; - CmdRspStatusFlag = SHCI_TL_CMD_RESP_WAIT; - while(CmdRspStatusFlag != SHCI_TL_CMD_RESP_RELEASE); + for (unsigned long start = millis(); (millis() - start) < timeout;) { + if (CmdRspStatusFlag == SHCI_TL_CMD_RESP_RELEASE) { + break; + } + } } __WEAK void shci_cmd_resp_release(uint32_t flag) From fb82a698e41bd8e75507e6886e7b03e71d0e53c8 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Mon, 12 Dec 2022 17:29:27 +0100 Subject: [PATCH 108/226] chore: add support for customize app_conf_default.h Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- src/utility/STM32Cube_FW/app_conf_default.h | 58 +++++++++++++++------ 1 file changed, 42 insertions(+), 16 deletions(-) diff --git a/src/utility/STM32Cube_FW/app_conf_default.h b/src/utility/STM32Cube_FW/app_conf_default.h index cc8c3e89..57f1027e 100644 --- a/src/utility/STM32Cube_FW/app_conf_default.h +++ b/src/utility/STM32Cube_FW/app_conf_default.h @@ -41,7 +41,9 @@ /** * Define Tx Power */ -#define CFG_TX_POWER (0x18) /* -0.15dBm */ +#ifndef CFG_TX_POWER + #define CFG_TX_POWER (0x18) /* -0.15dBm */ +#endif /****************************************************************************** * BLE Stack @@ -50,13 +52,17 @@ * Maximum number of simultaneous connections that the device will support. * Valid values are from 1 to 8 */ -#define CFG_BLE_NUM_LINK 8 +#ifndef CFG_BLE_NUM_LINK + #define CFG_BLE_NUM_LINK 8 +#endif /** * Maximum number of Services that can be stored in the GATT database. * Note that the GAP and GATT services are automatically added so this parameter should be 2 plus the number of user services */ -#define CFG_BLE_NUM_GATT_SERVICES 8 +#ifndef CFG_BLE_NUM_GATT_SERVICES + #define CFG_BLE_NUM_GATT_SERVICES 8 +#endif /** * Maximum number of Attributes @@ -65,13 +71,17 @@ * Note that certain characteristics and relative descriptors are added automatically during device initialization * so this parameters should be 9 plus the number of user Attributes */ -#define CFG_BLE_NUM_GATT_ATTRIBUTES 68 +#ifndef CFG_BLE_NUM_GATT_ATTRIBUTES + #define CFG_BLE_NUM_GATT_ATTRIBUTES 68 +#endif /** * Maximum supported ATT_MTU size * This parameter is ignored by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set */ -#define CFG_BLE_MAX_ATT_MTU (156) +#ifndef CFG_BLE_MAX_ATT_MTU + #define CFG_BLE_MAX_ATT_MTU (156) +#endif /** * Size of the storage area for Attribute values @@ -84,14 +94,18 @@ * The total amount of memory needed is the sum of the above quantities for each attribute. * This parameter is ignored by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set */ -#define CFG_BLE_ATT_VALUE_ARRAY_SIZE (1344) +#ifndef CFG_BLE_ATT_VALUE_ARRAY_SIZE + #define CFG_BLE_ATT_VALUE_ARRAY_SIZE (1344) +#endif /** * Prepare Write List size in terms of number of packet * This parameter is ignored by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set */ // #define CFG_BLE_PREPARE_WRITE_LIST_SIZE BLE_PREP_WRITE_X_ATT(CFG_BLE_MAX_ATT_MTU) -#define CFG_BLE_PREPARE_WRITE_LIST_SIZE (0x3A) +#ifndef CFG_BLE_PREPARE_WRITE_LIST_SIZE + #define CFG_BLE_PREPARE_WRITE_LIST_SIZE (0x3A) +#endif /** * Number of allocated memory blocks @@ -103,12 +117,16 @@ /** * Enable or disable the Extended Packet length feature. Valid values are 0 or 1. */ -#define CFG_BLE_DATA_LENGTH_EXTENSION 1 +#ifndef CFG_BLE_DATA_LENGTH_EXTENSION + #define CFG_BLE_DATA_LENGTH_EXTENSION 1 +#endif /** * Sleep clock accuracy in Slave mode (ppm value) */ -#define CFG_BLE_SLAVE_SCA 500 +#ifndef CFG_BLE_SLAVE_SCA + #define CFG_BLE_SLAVE_SCA 500 +#endif /** * Sleep clock accuracy in Master mode @@ -121,7 +139,9 @@ * 6 : 21 ppm to 30 ppm * 7 : 0 ppm to 20 ppm */ -#define CFG_BLE_MASTER_SCA 0 +#ifndef CFG_BLE_MASTER_SCA + #define CFG_BLE_MASTER_SCA 0 +#endif /** * LsSource @@ -130,21 +150,27 @@ * - bit 1: 1: STM32WB5M Module device 0: Other devices as STM32WBxx SOC, STM32WB1M module * - bit 2: 1: HSE/1024 Clock config 0: LSE Clock config */ -#if defined(STM32WB5Mxx) - #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_MOD5MM_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) -#else - #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_OTHER_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) +#ifndef CFG_BLE_LS_SOURCE + #if defined(STM32WB5Mxx) + #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_MOD5MM_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) + #else + #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_OTHER_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) + #endif #endif /** * Start up time of the high speed (16 or 32 MHz) crystal oscillator in units of 625/256 us (~2.44 us) */ -#define CFG_BLE_HSE_STARTUP_TIME 0x148 +#ifndef CFG_BLE_HSE_STARTUP_TIME + #define CFG_BLE_HSE_STARTUP_TIME 0x148 +#endif /** * Maximum duration of the connection event when the device is in Slave mode in units of 625/256 us (~2.44 us) */ -#define CFG_BLE_MAX_CONN_EVENT_LENGTH (0xFFFFFFFF) +#ifndef CFG_BLE_MAX_CONN_EVENT_LENGTH + #define CFG_BLE_MAX_CONN_EVENT_LENGTH (0xFFFFFFFF) +#endif /** * Viterbi Mode From 45e49a6ab86ceb9c1a1cc69e411f552a75b26c18 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Tue, 13 Dec 2022 10:16:08 +0100 Subject: [PATCH 109/226] chore: rename CFG_BLE_LSE_SOURCE to CFG_BLE_LS_SOURCE Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- src/utility/HCISharedMemTransport.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utility/HCISharedMemTransport.cpp b/src/utility/HCISharedMemTransport.cpp index e8c422c9..4e2ed2cf 100644 --- a/src/utility/HCISharedMemTransport.cpp +++ b/src/utility/HCISharedMemTransport.cpp @@ -644,7 +644,7 @@ int HCISharedMemTransportClass::stm32wb_start_ble(void) CFG_BLE_MAX_ATT_MTU, CFG_BLE_SLAVE_SCA, CFG_BLE_MASTER_SCA, - CFG_BLE_LSE_SOURCE, + CFG_BLE_LS_SOURCE, CFG_BLE_MAX_CONN_EVENT_LENGTH, CFG_BLE_HSE_STARTUP_TIME, CFG_BLE_VITERBI_MODE, From 23e7407673113b849b598ab0ec592dc5cdd55090 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Tue, 13 Dec 2022 10:48:35 +0100 Subject: [PATCH 110/226] chore: add new field initalizer for SHCI_C2_Ble_Init_Cmd_Packet_t Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- src/utility/HCISharedMemTransport.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/utility/HCISharedMemTransport.cpp b/src/utility/HCISharedMemTransport.cpp index 4e2ed2cf..e51b5fa6 100644 --- a/src/utility/HCISharedMemTransport.cpp +++ b/src/utility/HCISharedMemTransport.cpp @@ -654,11 +654,11 @@ int HCISharedMemTransportClass::stm32wb_start_ble(void) CFG_BLE_MIN_TX_POWER, CFG_BLE_MAX_TX_POWER, CFG_BLE_RX_MODEL_CONFIG, - CFG_BLE_MAX_ADV_SET_NBR, - CFG_BLE_MAX_ADV_DATA_LEN, - CFG_BLE_TX_PATH_COMPENS, - CFG_BLE_RX_PATH_COMPENS - + CFG_BLE_MAX_ADV_SET_NBR, + CFG_BLE_MAX_ADV_DATA_LEN, + CFG_BLE_TX_PATH_COMPENS, + CFG_BLE_RX_PATH_COMPENS, + CFG_BLE_CORE_VERSION }; /** * Starts the BLE Stack on CPU2 From 731440bb7d96cbad541b60f73392739484a406e9 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Thu, 15 Dec 2022 10:51:31 +0100 Subject: [PATCH 111/226] doc: reference STM32WBxx Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- README.md | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 3a0691ab..2413f5c2 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,21 @@ # 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-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: - +This library is a fork of ArduinoBLE library to add the support of STM32WBxx, SPBTLE-RF and SPBTLE-1S BLE modules. +It was successfully tested with the P-NUCELO_WB55RG, STM32WB5MM-DK, 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 SM32WBxx series, you need to update the STM32WB Copro Wireless Binaries +with stm32wbxx_BLE_HCILayer_fw.bin depending of your mcu: +https://github.com/STMicroelectronics/STM32CubeWB/tree/master/Projects/STM32WB_Copro_Wireless_Binaries + Each subdirectories contains binaries and Release_Notes.html which explain how to update it. + + - 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: https://github.com/stm32duino/wiki/wiki/STM32duinoBLE#stm32duinoble-with-steval_mksbox1v1 -In order to use this library with X-NUCLEO-BNRG2A1, you need to update the firmware of the BLUENRG-M2SP BLE module -mounted on that expansion board as described in the following wiki page: - +- In order to use this library with X-NUCLEO-BNRG2A1, you need to update the firmware of the BLUENRG-M2SP BLE module +mounted on that expansion board as described in the following wiki page: https://github.com/stm32duino/wiki/wiki/STM32duinoBLE#stm32duinoble-with-x-nucleo-bnrg2a1 For more information about ArduinoBLE library please visit the official web page at: From 9b49cd60f423b3f1bd545acf959ffda19ae1961c Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Thu, 15 Dec 2022 10:52:49 +0100 Subject: [PATCH 112/226] fix: allows space at the end of line of markdown files Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- .editorconfig | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.editorconfig b/.editorconfig index c9b76fd6..c7bf2228 100644 --- a/.editorconfig +++ b/.editorconfig @@ -5,6 +5,9 @@ indent_style = space indent_size = 2 trim_trailing_whitespace = true +[*.md] +trim_trailing_whitespace = false + [*.sh] # like -i=2 indent_style = space From daa84754ced0f6f9d8d2aad8c05eedb2ea8eea00 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Thu, 15 Dec 2022 11:01:08 +0100 Subject: [PATCH 113/226] ci(codespell): skip STM32Cube_FW directory Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- .github/workflows/codespell.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/codespell.yml b/.github/workflows/codespell.yml index 5ea11f42..744a6d2e 100644 --- a/.github/workflows/codespell.yml +++ b/.github/workflows/codespell.yml @@ -24,4 +24,5 @@ jobs: check_hidden: true # In the event of a false positive, add the word in all lower case to this file: # ignore_words_file: ./extras/codespell-ignore-words-list.txt - path: src + skip: src/utility/STM32Cube_FW + path: src From 0fe8e71a68e537f84acb1b580f61292f5a631467 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Mon, 9 Jan 2023 10:33:24 +0100 Subject: [PATCH 114/226] chore: update app_conf default for STM32WB15xx Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- src/utility/STM32Cube_FW/app_conf_default.h | 32 +++++++++++++++++---- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/src/utility/STM32Cube_FW/app_conf_default.h b/src/utility/STM32Cube_FW/app_conf_default.h index 57f1027e..35cad34f 100644 --- a/src/utility/STM32Cube_FW/app_conf_default.h +++ b/src/utility/STM32Cube_FW/app_conf_default.h @@ -53,16 +53,24 @@ * Valid values are from 1 to 8 */ #ifndef CFG_BLE_NUM_LINK +#ifdef STM32WB15xx + #define CFG_BLE_NUM_LINK 3 +#else #define CFG_BLE_NUM_LINK 8 #endif +#endif /** * Maximum number of Services that can be stored in the GATT database. * Note that the GAP and GATT services are automatically added so this parameter should be 2 plus the number of user services */ #ifndef CFG_BLE_NUM_GATT_SERVICES +#ifdef STM32WB15xx + #define CFG_BLE_NUM_GATT_SERVICES 4 +#else #define CFG_BLE_NUM_GATT_SERVICES 8 #endif +#endif /** * Maximum number of Attributes @@ -72,7 +80,11 @@ * so this parameters should be 9 plus the number of user Attributes */ #ifndef CFG_BLE_NUM_GATT_ATTRIBUTES - #define CFG_BLE_NUM_GATT_ATTRIBUTES 68 +#ifdef STM32WB15xx + #define CFG_BLE_NUM_GATT_ATTRIBUTES 30 +#else + #define CFG_BLE_NUM_GATT_ATTRIBUTES 68 +#endif #endif /** @@ -95,8 +107,12 @@ * This parameter is ignored by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set */ #ifndef CFG_BLE_ATT_VALUE_ARRAY_SIZE +#ifdef STM32WB15xx + #define CFG_BLE_ATT_VALUE_ARRAY_SIZE (1290) +#else #define CFG_BLE_ATT_VALUE_ARRAY_SIZE (1344) #endif +#endif /** * Prepare Write List size in terms of number of packet @@ -250,8 +266,11 @@ * on Max Extended advertising configuration supported. * This parameter is considered by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV flag set */ - -#define CFG_BLE_MAX_ADV_SET_NBR (8) +#if defined(STM32WB15xx) + #define CFG_BLE_MAX_ADV_SET_NBR (3) +#else + #define CFG_BLE_MAX_ADV_SET_NBR (8) +#endif /* Maximum advertising data length (in bytes) * Range: 31 .. 1650 with limitation: @@ -259,8 +278,11 @@ * on Max Extended advertising configuration supported. * This parameter is considered by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV flag set */ - -#define CFG_BLE_MAX_ADV_DATA_LEN (207) +#if defined(STM32WB15xx) + #define CFG_BLE_MAX_ADV_DATA_LEN (414) +#else + #define CFG_BLE_MAX_ADV_DATA_LEN (207) +#endif /* RF TX Path Compensation Value (16-bit signed integer). Units: 0.1 dB. * Range: -1280 .. 1280 From 40dd5bd39392dfac0c4bb90ee7797e0817563461 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Mon, 9 Jan 2023 10:36:33 +0100 Subject: [PATCH 115/226] chore: update examples to support Nucleo WB15CC Will be available within stm32 core version higher than 2.4.0. Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- README.md | 6 +++--- examples/Central/LedControl/LedControl.ino | 2 +- examples/Central/PeripheralExplorer/PeripheralExplorer.ino | 2 +- examples/Central/Scan/Scan.ino | 2 +- examples/Central/ScanCallback/ScanCallback.ino | 2 +- examples/Central/SensorTagButton/SensorTagButton.ino | 2 +- examples/Peripheral/ButtonLED/ButtonLED.ino | 2 +- examples/Peripheral/CallbackLED/CallbackLED.ino | 2 +- examples/Peripheral/LED/LED.ino | 2 +- 9 files changed, 11 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 2413f5c2..b6e9de98 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ # STM32duinoBLE This library is a fork of ArduinoBLE library to add the support of STM32WBxx, SPBTLE-RF and SPBTLE-1S BLE modules. -It was successfully tested with the P-NUCELO_WB55RG, STM32WB5MM-DK, 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. +It was successfully tested with the NUCLEO-WB15CC, P-NUCELO_WB55RG, STM32WB5MM-DK, 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 SM32WBxx series, you need to update the STM32WB Copro Wireless Binaries with stm32wbxx_BLE_HCILayer_fw.bin depending of your mcu: diff --git a/examples/Central/LedControl/LedControl.ino b/examples/Central/LedControl/LedControl.ino index d0f73383..d3450e6d 100644 --- a/examples/Central/LedControl/LedControl.ino +++ b/examples/Central/LedControl/LedControl.ino @@ -43,7 +43,7 @@ BLELocalDevice BLEObj(&HCISpiTransport); BLELocalDevice& BLE = BLEObj; #endif const int buttonPin = PC13; // set buttonPin to digital pin PC13 -#elif defined(ARDUINO_P_NUCLEO_WB55RG) || defined(ARDUINO_STM32WB5MM_DK) +#elif defined(ARDUINO_NUCLEO_WB15CC) || defined(ARDUINO_P_NUCLEO_WB55RG) || defined(ARDUINO_STM32WB5MM_DK) HCISharedMemTransportClass HCISharedMemTransport; #if !defined(FAKE_BLELOCALDEVICE) BLELocalDevice BLEObj(&HCISharedMemTransport); diff --git a/examples/Central/PeripheralExplorer/PeripheralExplorer.ino b/examples/Central/PeripheralExplorer/PeripheralExplorer.ino index ea8b3b24..79ae6618 100644 --- a/examples/Central/PeripheralExplorer/PeripheralExplorer.ino +++ b/examples/Central/PeripheralExplorer/PeripheralExplorer.ino @@ -40,7 +40,7 @@ HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, PD13, PE6, PA8, 8000000, BLELocalDevice BLEObj(&HCISpiTransport); BLELocalDevice& BLE = BLEObj; #endif -#elif defined(ARDUINO_P_NUCLEO_WB55RG) || defined(ARDUINO_STM32WB5MM_DK) +#elif defined(ARDUINO_NUCLEO_WB15CC) || defined(ARDUINO_P_NUCLEO_WB55RG) || defined(ARDUINO_STM32WB5MM_DK) HCISharedMemTransportClass HCISharedMemTransport; #if !defined(FAKE_BLELOCALDEVICE) BLELocalDevice BLEObj(&HCISharedMemTransport); diff --git a/examples/Central/Scan/Scan.ino b/examples/Central/Scan/Scan.ino index bd22c65e..edbef56f 100644 --- a/examples/Central/Scan/Scan.ino +++ b/examples/Central/Scan/Scan.ino @@ -37,7 +37,7 @@ HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, PD13, PE6, PA8, 8000000, BLELocalDevice BLEObj(&HCISpiTransport); BLELocalDevice& BLE = BLEObj; #endif -#elif defined(ARDUINO_P_NUCLEO_WB55RG) || defined(ARDUINO_STM32WB5MM_DK) +#elif defined(ARDUINO_NUCLEO_WB15CC) || defined(ARDUINO_P_NUCLEO_WB55RG) || defined(ARDUINO_STM32WB5MM_DK) HCISharedMemTransportClass HCISharedMemTransport; #if !defined(FAKE_BLELOCALDEVICE) BLELocalDevice BLEObj(&HCISharedMemTransport); diff --git a/examples/Central/ScanCallback/ScanCallback.ino b/examples/Central/ScanCallback/ScanCallback.ino index dbc2536e..798cc326 100644 --- a/examples/Central/ScanCallback/ScanCallback.ino +++ b/examples/Central/ScanCallback/ScanCallback.ino @@ -39,7 +39,7 @@ HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, PD13, PE6, PA8, 8000000, BLELocalDevice BLEObj(&HCISpiTransport); BLELocalDevice& BLE = BLEObj; #endif -#elif defined(ARDUINO_P_NUCLEO_WB55RG) || defined(ARDUINO_STM32WB5MM_DK) +#elif defined(ARDUINO_NUCLEO_WB15CC) || defined(ARDUINO_P_NUCLEO_WB55RG) || defined(ARDUINO_STM32WB5MM_DK) HCISharedMemTransportClass HCISharedMemTransport; #if !defined(FAKE_BLELOCALDEVICE) BLELocalDevice BLEObj(&HCISharedMemTransport); diff --git a/examples/Central/SensorTagButton/SensorTagButton.ino b/examples/Central/SensorTagButton/SensorTagButton.ino index 1831b172..4b3557ac 100644 --- a/examples/Central/SensorTagButton/SensorTagButton.ino +++ b/examples/Central/SensorTagButton/SensorTagButton.ino @@ -41,7 +41,7 @@ HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, PD13, PE6, PA8, 8000000, BLELocalDevice BLEObj(&HCISpiTransport); BLELocalDevice& BLE = BLEObj; #endif -#elif defined(ARDUINO_P_NUCLEO_WB55RG) || defined(ARDUINO_STM32WB5MM_DK) +#elif defined(ARDUINO_NUCLEO_WB15CC) || defined(ARDUINO_P_NUCLEO_WB55RG) || defined(ARDUINO_STM32WB5MM_DK) HCISharedMemTransportClass HCISharedMemTransport; #if !defined(FAKE_BLELOCALDEVICE) BLELocalDevice BLEObj(&HCISharedMemTransport); diff --git a/examples/Peripheral/ButtonLED/ButtonLED.ino b/examples/Peripheral/ButtonLED/ButtonLED.ino index f12adb50..0a84b6ac 100644 --- a/examples/Peripheral/ButtonLED/ButtonLED.ino +++ b/examples/Peripheral/ButtonLED/ButtonLED.ino @@ -44,7 +44,7 @@ BLELocalDevice BLEObj(&HCISpiTransport); BLELocalDevice& BLE = BLEObj; #endif const int buttonPin = PC13; // set buttonPin to digital pin PC13 -#elif defined(ARDUINO_P_NUCLEO_WB55RG) || defined(ARDUINO_STM32WB5MM_DK) +#elif defined(ARDUINO_NUCLEO_WB15CC) || defined(ARDUINO_P_NUCLEO_WB55RG) || defined(ARDUINO_STM32WB5MM_DK) HCISharedMemTransportClass HCISharedMemTransport; #if !defined(FAKE_BLELOCALDEVICE) BLELocalDevice BLEObj(&HCISharedMemTransport); diff --git a/examples/Peripheral/CallbackLED/CallbackLED.ino b/examples/Peripheral/CallbackLED/CallbackLED.ino index 363d804b..45632e4f 100644 --- a/examples/Peripheral/CallbackLED/CallbackLED.ino +++ b/examples/Peripheral/CallbackLED/CallbackLED.ino @@ -42,7 +42,7 @@ HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, PD13, PE6, PA8, 8000000, BLELocalDevice BLEObj(&HCISpiTransport); BLELocalDevice& BLE = BLEObj; #endif -#elif defined(ARDUINO_P_NUCLEO_WB55RG) || defined(ARDUINO_STM32WB5MM_DK) +#elif defined(ARDUINO_NUCLEO_WB15CC) || defined(ARDUINO_P_NUCLEO_WB55RG) || defined(ARDUINO_STM32WB5MM_DK) HCISharedMemTransportClass HCISharedMemTransport; #if !defined(FAKE_BLELOCALDEVICE) BLELocalDevice BLEObj(&HCISharedMemTransport); diff --git a/examples/Peripheral/LED/LED.ino b/examples/Peripheral/LED/LED.ino index 48de79d7..9dd92e4d 100644 --- a/examples/Peripheral/LED/LED.ino +++ b/examples/Peripheral/LED/LED.ino @@ -40,7 +40,7 @@ HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, PD13, PE6, PA8, 8000000, BLELocalDevice BLEObj(&HCISpiTransport); BLELocalDevice& BLE = BLEObj; #endif -#elif defined(ARDUINO_P_NUCLEO_WB55RG) || defined(ARDUINO_STM32WB5MM_DK) +#elif defined(ARDUINO_NUCLEO_WB15CC) || defined(ARDUINO_P_NUCLEO_WB55RG) || defined(ARDUINO_STM32WB5MM_DK) HCISharedMemTransportClass HCISharedMemTransport; #if !defined(FAKE_BLELOCALDEVICE) BLELocalDevice BLEObj(&HCISharedMemTransport); From 3a116161880f2578617536a76fac0b2ded9fc5b3 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Mon, 9 Jan 2023 11:04:22 +0100 Subject: [PATCH 116/226] chore(examples): use USER_BTN if defined Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- examples/Central/LedControl/LedControl.ino | 16 ++++++---------- examples/Central/Scan/Scan.ino | 1 - examples/Central/ScanCallback/ScanCallback.ino | 1 - .../Central/SensorTagButton/SensorTagButton.ino | 3 +-- examples/Peripheral/ButtonLED/ButtonLED.ino | 16 ++++++---------- examples/Peripheral/CallbackLED/CallbackLED.ino | 3 +-- examples/Peripheral/LED/LED.ino | 1 - 7 files changed, 14 insertions(+), 27 deletions(-) diff --git a/examples/Central/LedControl/LedControl.ino b/examples/Central/LedControl/LedControl.ino index d3450e6d..7c090f79 100644 --- a/examples/Central/LedControl/LedControl.ino +++ b/examples/Central/LedControl/LedControl.ino @@ -16,6 +16,12 @@ #include <STM32duinoBLE.h> +#ifdef USER_BTN +const int buttonPin = USER_BTN; // set buttonPin to on-board user button +#else +const int buttonPin = PC13; // set buttonPin to digital pin PC13 */ +#endif + #if defined(ARDUINO_STEVAL_MKBOXPRO) /* STEVAL-MKBOXPRO */ SPIClass SpiHCI(PA7, PA6, PA5); @@ -24,7 +30,6 @@ HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_LP, PA2, PB11, PD4, 1000000 BLELocalDevice BLEObj(&HCISpiTransport); BLELocalDevice& BLE = BLEObj; #endif -const int buttonPin = PC13; // set buttonPin to digital pin PC13 #elif defined(ARDUINO_STEVAL_MKSBOX1V1) /* STEVAL-MKSBOX1V1 */ SPIClass SpiHCI(PC3, PD3, PD1); @@ -33,7 +38,6 @@ HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_1S, PD0, PD4, PA8, 1000000, BLELocalDevice BLEObj(&HCISpiTransport); BLELocalDevice& BLE = BLEObj; #endif -const int buttonPin = PG1; // set buttonPin to digital pin PG1 #elif defined(ARDUINO_B_L475E_IOT01A) || defined(ARDUINO_B_L4S5I_IOT01A) /* B-L475E-IOT01A1 or B_L4S5I_IOT01A */ SPIClass SpiHCI(PC12, PC11, PC10); @@ -42,14 +46,12 @@ HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, PD13, PE6, PA8, 8000000, BLELocalDevice BLEObj(&HCISpiTransport); BLELocalDevice& BLE = BLEObj; #endif -const int buttonPin = PC13; // set buttonPin to digital pin PC13 #elif defined(ARDUINO_NUCLEO_WB15CC) || defined(ARDUINO_P_NUCLEO_WB55RG) || defined(ARDUINO_STM32WB5MM_DK) HCISharedMemTransportClass HCISharedMemTransport; #if !defined(FAKE_BLELOCALDEVICE) BLELocalDevice BLEObj(&HCISharedMemTransport); BLELocalDevice& BLE = BLEObj; #endif -const int buttonPin = PC4; // set buttonPin to digital pin PC4 #else /* Shield IDB05A2 with SPI clock on D3 */ SPIClass SpiHCI(D11, D12, D3); @@ -58,7 +60,6 @@ HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M0, A1, A0, D7, 8000000, SP BLELocalDevice BLEObj(&HCISpiTransport); BLELocalDevice& BLE = BLEObj; #endif -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); @@ -66,7 +67,6 @@ HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M0, A1, A0, D7, 8000000, SP BLELocalDevice BLEObj(&HCISpiTransport); BLELocalDevice& BLE = BLEObj; #endif -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); @@ -74,7 +74,6 @@ HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI BLELocalDevice BLEObj(&HCISpiTransport); BLELocalDevice& BLE = BLEObj; #endif -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); @@ -82,7 +81,6 @@ HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI BLELocalDevice BLEObj(&HCISpiTransport); BLELocalDevice& BLE = BLEObj; #endif -const int buttonPin = PC13; // set buttonPin to digital pin PC13 */ /* Shield BNRG2A1 with SPI clock on D3 */ /*SPIClass SpiHCI(D11, D12, D3); HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1); @@ -90,7 +88,6 @@ HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, BLELocalDevice BLEObj(&HCISpiTransport); BLELocalDevice& BLE = BLEObj; #endif -const int buttonPin = PC13; // set buttonPin to digital pin PC13 */ /* Shield BNRG2A1 with SPI clock on D13 */ /*#define SpiHCI SPI HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1); @@ -98,7 +95,6 @@ HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, BLELocalDevice BLEObj(&HCISpiTransport); BLELocalDevice& BLE = BLEObj; #endif -const int buttonPin = PC13; // set buttonPin to digital pin PC13 */ #endif // variables for button diff --git a/examples/Central/Scan/Scan.ino b/examples/Central/Scan/Scan.ino index edbef56f..2010b31d 100644 --- a/examples/Central/Scan/Scan.ino +++ b/examples/Central/Scan/Scan.ino @@ -20,7 +20,6 @@ HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_LP, PA2, PB11, PD4, 1000000 BLELocalDevice BLEObj(&HCISpiTransport); BLELocalDevice& BLE = BLEObj; #endif -const int buttonPin = PC13; // set buttonPin to digital pin PC13 #elif defined(ARDUINO_STEVAL_MKSBOX1V1) /* STEVAL-MKSBOX1V1 */ SPIClass SpiHCI(PC3, PD3, PD1); diff --git a/examples/Central/ScanCallback/ScanCallback.ino b/examples/Central/ScanCallback/ScanCallback.ino index 798cc326..e4067a45 100644 --- a/examples/Central/ScanCallback/ScanCallback.ino +++ b/examples/Central/ScanCallback/ScanCallback.ino @@ -22,7 +22,6 @@ HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_LP, PA2, PB11, PD4, 1000000 BLELocalDevice BLEObj(&HCISpiTransport); BLELocalDevice& BLE = BLEObj; #endif -const int buttonPin = PC13; // set buttonPin to digital pin PC13 #elif defined(ARDUINO_STEVAL_MKSBOX1V1) /* STEVAL-MKSBOX1V1 */ SPIClass SpiHCI(PC3, PD3, PD1); diff --git a/examples/Central/SensorTagButton/SensorTagButton.ino b/examples/Central/SensorTagButton/SensorTagButton.ino index 4b3557ac..d4c740cc 100644 --- a/examples/Central/SensorTagButton/SensorTagButton.ino +++ b/examples/Central/SensorTagButton/SensorTagButton.ino @@ -24,7 +24,6 @@ HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_LP, PA2, PB11, PD4, 1000000 BLELocalDevice BLEObj(&HCISpiTransport); BLELocalDevice& BLE = BLEObj; #endif -const int buttonPin = PC13; // set buttonPin to digital pin PC13 #elif defined(ARDUINO_STEVAL_MKSBOX1V1) /* STEVAL-MKSBOX1V1 */ SPIClass SpiHCI(PC3, PD3, PD1); @@ -216,7 +215,7 @@ void monitorSensorTagButtons(BLEDevice peripheral) { if (simpleKeyCharacteristic.valueUpdated()) { // yes, get the value, characteristic is 1 byte so use byte value byte value = 0; - + simpleKeyCharacteristic.readValue(value); if (value & 0x01) { diff --git a/examples/Peripheral/ButtonLED/ButtonLED.ino b/examples/Peripheral/ButtonLED/ButtonLED.ino index 0a84b6ac..91dfcb2a 100644 --- a/examples/Peripheral/ButtonLED/ButtonLED.ino +++ b/examples/Peripheral/ButtonLED/ButtonLED.ino @@ -17,6 +17,12 @@ #include <STM32duinoBLE.h> +#ifdef USER_BTN +const int buttonPin = USER_BTN; // set buttonPin to on-board user button +#else +const int buttonPin = PC13; // set buttonPin to digital pin PC13 */ +#endif + #if defined(ARDUINO_STEVAL_MKBOXPRO) /* STEVAL-MKBOXPRO */ SPIClass SpiHCI(PA7, PA6, PA5); @@ -25,7 +31,6 @@ HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_LP, PA2, PB11, PD4, 1000000 BLELocalDevice BLEObj(&HCISpiTransport); BLELocalDevice& BLE = BLEObj; #endif -const int buttonPin = PC13; // set buttonPin to digital pin PC13 #elif defined(ARDUINO_STEVAL_MKSBOX1V1) /* STEVAL-MKSBOX1V1 */ SPIClass SpiHCI(PC3, PD3, PD1); @@ -34,7 +39,6 @@ HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_1S, PD0, PD4, PA8, 1000000, BLELocalDevice BLEObj(&HCISpiTransport); BLELocalDevice& BLE = BLEObj; #endif -const int buttonPin = PG1; // set buttonPin to digital pin PG1 #elif defined(ARDUINO_B_L475E_IOT01A) || defined(ARDUINO_B_L4S5I_IOT01A) /* B-L475E-IOT01A1 or B_L4S5I_IOT01A */ SPIClass SpiHCI(PC12, PC11, PC10); @@ -43,14 +47,12 @@ HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, PD13, PE6, PA8, 8000000, BLELocalDevice BLEObj(&HCISpiTransport); BLELocalDevice& BLE = BLEObj; #endif -const int buttonPin = PC13; // set buttonPin to digital pin PC13 #elif defined(ARDUINO_NUCLEO_WB15CC) || defined(ARDUINO_P_NUCLEO_WB55RG) || defined(ARDUINO_STM32WB5MM_DK) HCISharedMemTransportClass HCISharedMemTransport; #if !defined(FAKE_BLELOCALDEVICE) BLELocalDevice BLEObj(&HCISharedMemTransport); BLELocalDevice& BLE = BLEObj; #endif -const int buttonPin = PC4; // set buttonPin to digital pin PC4 #else /* Shield IDB05A2 with SPI clock on D3 */ SPIClass SpiHCI(D11, D12, D3); @@ -59,7 +61,6 @@ HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M0, A1, A0, D7, 8000000, SP BLELocalDevice BLEObj(&HCISpiTransport); BLELocalDevice& BLE = BLEObj; #endif -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); @@ -67,7 +68,6 @@ HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M0, A1, A0, D7, 8000000, SP BLELocalDevice BLEObj(&HCISpiTransport); BLELocalDevice& BLE = BLEObj; #endif -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); @@ -75,7 +75,6 @@ HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI BLELocalDevice BLEObj(&HCISpiTransport); BLELocalDevice& BLE = BLEObj; #endif -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); @@ -83,7 +82,6 @@ HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI BLELocalDevice BLEObj(&HCISpiTransport); BLELocalDevice& BLE = BLEObj; #endif -const int buttonPin = PC13; // set buttonPin to digital pin PC13 */ /* Shield BNRG2A1 with SPI clock on D3 */ /*SPIClass SpiHCI(D11, D12, D3); HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1); @@ -91,7 +89,6 @@ HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, BLELocalDevice BLEObj(&HCISpiTransport); BLELocalDevice& BLE = BLEObj; #endif -const int buttonPin = PC13; // set buttonPin to digital pin PC13 */ /* Shield BNRG2A1 with SPI clock on D13 */ /*#define SpiHCI SPI HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1); @@ -99,7 +96,6 @@ HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, BLELocalDevice BLEObj(&HCISpiTransport); BLELocalDevice& BLE = BLEObj; #endif -const int buttonPin = PC13; // set buttonPin to digital pin PC13 */ #endif const int ledPin = LED_BUILTIN; // set ledPin to on-board LED diff --git a/examples/Peripheral/CallbackLED/CallbackLED.ino b/examples/Peripheral/CallbackLED/CallbackLED.ino index 45632e4f..4177a44d 100644 --- a/examples/Peripheral/CallbackLED/CallbackLED.ino +++ b/examples/Peripheral/CallbackLED/CallbackLED.ino @@ -25,7 +25,6 @@ HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_LP, PA2, PB11, PD4, 1000000 BLELocalDevice BLEObj(&HCISpiTransport); BLELocalDevice& BLE = BLEObj; #endif -const int buttonPin = PC13; // set buttonPin to digital pin PC13 #elif defined(ARDUINO_STEVAL_MKSBOX1V1) /* STEVAL-MKSBOX1V1 */ SPIClass SpiHCI(PC3, PD3, PD1); @@ -103,7 +102,7 @@ const int ledPin = LED_BUILTIN; // pin to use for the LED void setup() { Serial.begin(115200); while (!Serial); - + pinMode(ledPin, OUTPUT); // use the LED pin as an output // begin initialization diff --git a/examples/Peripheral/LED/LED.ino b/examples/Peripheral/LED/LED.ino index 9dd92e4d..487c4287 100644 --- a/examples/Peripheral/LED/LED.ino +++ b/examples/Peripheral/LED/LED.ino @@ -23,7 +23,6 @@ HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_LP, PA2, PB11, PD4, 1000000 BLELocalDevice BLEObj(&HCISpiTransport); BLELocalDevice& BLE = BLEObj; #endif -const int buttonPin = PC13; // set buttonPin to digital pin PC13 #elif defined(ARDUINO_STEVAL_MKSBOX1V1) /* STEVAL-MKSBOX1V1 */ SPIClass SpiHCI(PC3, PD3, PD1); From ceb1e6258a8ec86a56f2b3aea273d2a67a927569 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Mon, 9 Jan 2023 11:12:06 +0100 Subject: [PATCH 117/226] fix(examples): aligned comments between all examples Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- examples/Central/LedControl/LedControl.ino | 60 +++++++++---------- .../PeripheralExplorer/PeripheralExplorer.ino | 60 +++++++++---------- examples/Central/Scan/Scan.ino | 60 +++++++++---------- .../Central/ScanCallback/ScanCallback.ino | 60 +++++++++---------- .../SensorTagButton/SensorTagButton.ino | 60 +++++++++---------- examples/Peripheral/ButtonLED/ButtonLED.ino | 60 +++++++++---------- .../Peripheral/CallbackLED/CallbackLED.ino | 60 +++++++++---------- examples/Peripheral/LED/LED.ino | 60 +++++++++---------- 8 files changed, 240 insertions(+), 240 deletions(-) diff --git a/examples/Central/LedControl/LedControl.ino b/examples/Central/LedControl/LedControl.ino index 7c090f79..09939cde 100644 --- a/examples/Central/LedControl/LedControl.ino +++ b/examples/Central/LedControl/LedControl.ino @@ -61,40 +61,40 @@ BLELocalDevice BLEObj(&HCISpiTransport); BLELocalDevice& BLE = BLEObj; #endif /* Shield IDB05A2 with SPI clock on D13 */ -/*#define SpiHCI SPI -HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M0, A1, A0, D7, 8000000, SPI_MODE0); -#if !defined(FAKE_BLELOCALDEVICE) -BLELocalDevice BLEObj(&HCISpiTransport); -BLELocalDevice& BLE = BLEObj; -#endif +// #define SpiHCI SPI +// HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M0, A1, A0, D7, 8000000, SPI_MODE0); +// #if !defined(FAKE_BLELOCALDEVICE) +// BLELocalDevice BLEObj(&HCISpiTransport); +// BLELocalDevice& BLE = BLEObj; +// #endif /* Shield IDB05A1 with SPI clock on D3 */ -/*SPIClass SpiHCI(D11, D12, D3); -HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI_MODE0); -#if !defined(FAKE_BLELOCALDEVICE) -BLELocalDevice BLEObj(&HCISpiTransport); -BLELocalDevice& BLE = BLEObj; -#endif +// SPIClass SpiHCI(D11, D12, D3); +// HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI_MODE0); +// #if !defined(FAKE_BLELOCALDEVICE) +// BLELocalDevice BLEObj(&HCISpiTransport); +// BLELocalDevice& BLE = BLEObj; +// #endif /* Shield IDB05A1 with SPI clock on D13 */ -/*#define SpiHCI SPI -HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI_MODE0); -#if !defined(FAKE_BLELOCALDEVICE) -BLELocalDevice BLEObj(&HCISpiTransport); -BLELocalDevice& BLE = BLEObj; -#endif +// #define SpiHCI SPI +// HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI_MODE0); +// #if !defined(FAKE_BLELOCALDEVICE) +// BLELocalDevice BLEObj(&HCISpiTransport); +// BLELocalDevice& BLE = BLEObj; +// #endif /* Shield BNRG2A1 with SPI clock on D3 */ -/*SPIClass SpiHCI(D11, D12, D3); -HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1); -#if !defined(FAKE_BLELOCALDEVICE) -BLELocalDevice BLEObj(&HCISpiTransport); -BLELocalDevice& BLE = BLEObj; -#endif +// SPIClass SpiHCI(D11, D12, D3); +// HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1); +// #if !defined(FAKE_BLELOCALDEVICE) +// BLELocalDevice BLEObj(&HCISpiTransport); +// BLELocalDevice& BLE = BLEObj; +// #endif /* Shield BNRG2A1 with SPI clock on D13 */ -/*#define SpiHCI SPI -HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1); -#if !defined(FAKE_BLELOCALDEVICE) -BLELocalDevice BLEObj(&HCISpiTransport); -BLELocalDevice& BLE = BLEObj; -#endif +// #define SpiHCI SPI +// HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1); +// #if !defined(FAKE_BLELOCALDEVICE) +// BLELocalDevice BLEObj(&HCISpiTransport); +// BLELocalDevice& BLE = BLEObj; +// #endif #endif // variables for button diff --git a/examples/Central/PeripheralExplorer/PeripheralExplorer.ino b/examples/Central/PeripheralExplorer/PeripheralExplorer.ino index 79ae6618..09e204f6 100644 --- a/examples/Central/PeripheralExplorer/PeripheralExplorer.ino +++ b/examples/Central/PeripheralExplorer/PeripheralExplorer.ino @@ -55,40 +55,40 @@ BLELocalDevice BLEObj(&HCISpiTransport); BLELocalDevice& BLE = BLEObj; #endif /* Shield IDB05A2 with SPI clock on D13 */ -/*#define SpiHCI SPI -HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M0, A1, A0, D7, 8000000, SPI_MODE0); -#if !defined(FAKE_BLELOCALDEVICE) -BLELocalDevice BLEObj(&HCISpiTransport); -BLELocalDevice& BLE = BLEObj; -#endif */ +// #define SpiHCI SPI +// HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M0, A1, A0, D7, 8000000, SPI_MODE0); +// #if !defined(FAKE_BLELOCALDEVICE) +// BLELocalDevice BLEObj(&HCISpiTransport); +// BLELocalDevice& BLE = BLEObj; +// #endif /* Shield IDB05A1 with SPI clock on D3 */ -/*SPIClass SpiHCI(D11, D12, D3); -HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI_MODE0); -#if !defined(FAKE_BLELOCALDEVICE) -BLELocalDevice BLEObj(&HCISpiTransport); -BLELocalDevice& BLE = BLEObj; -#endif */ +// SPIClass SpiHCI(D11, D12, D3); +// HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI_MODE0); +// #if !defined(FAKE_BLELOCALDEVICE) +// BLELocalDevice BLEObj(&HCISpiTransport); +// BLELocalDevice& BLE = BLEObj; +// #endif /* Shield IDB05A1 with SPI clock on D13 */ -/*#define SpiHCI SPI -HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI_MODE0); -#if !defined(FAKE_BLELOCALDEVICE) -BLELocalDevice BLEObj(&HCISpiTransport); -BLELocalDevice& BLE = BLEObj; -#endif */ +// #define SpiHCI SPI +// HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI_MODE0); +// #if !defined(FAKE_BLELOCALDEVICE) +// BLELocalDevice BLEObj(&HCISpiTransport); +// BLELocalDevice& BLE = BLEObj; +// #endif /* Shield BNRG2A1 with SPI clock on D3 */ -/*SPIClass SpiHCI(D11, D12, D3); -HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1); -#if !defined(FAKE_BLELOCALDEVICE) -BLELocalDevice BLEObj(&HCISpiTransport); -BLELocalDevice& BLE = BLEObj; -#endif */ +// SPIClass SpiHCI(D11, D12, D3); +// HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1); +// #if !defined(FAKE_BLELOCALDEVICE) +// BLELocalDevice BLEObj(&HCISpiTransport); +// BLELocalDevice& BLE = BLEObj; +// #endif /* Shield BNRG2A1 with SPI clock on D13 */ -/*#define SpiHCI SPI -HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1); -#if !defined(FAKE_BLELOCALDEVICE) -BLELocalDevice BLEObj(&HCISpiTransport); -BLELocalDevice& BLE = BLEObj; -#endif */ +// #define SpiHCI SPI +// HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1); +// #if !defined(FAKE_BLELOCALDEVICE) +// BLELocalDevice BLEObj(&HCISpiTransport); +// BLELocalDevice& BLE = BLEObj; +// #endif #endif void setup() { diff --git a/examples/Central/Scan/Scan.ino b/examples/Central/Scan/Scan.ino index 2010b31d..14ea9f13 100644 --- a/examples/Central/Scan/Scan.ino +++ b/examples/Central/Scan/Scan.ino @@ -51,40 +51,40 @@ BLELocalDevice BLEObj(&HCISpiTransport); BLELocalDevice& BLE = BLEObj; #endif /* Shield IDB05A2 with SPI clock on D13 */ -/*#define SpiHCI SPI -HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M0, A1, A0, D7, 8000000, SPI_MODE0); -#if !defined(FAKE_BLELOCALDEVICE) -BLELocalDevice BLEObj(&HCISpiTransport); -BLELocalDevice& BLE = BLEObj; -#endif */ +// #define SpiHCI SPI +// HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M0, A1, A0, D7, 8000000, SPI_MODE0); +// #if !defined(FAKE_BLELOCALDEVICE) +// BLELocalDevice BLEObj(&HCISpiTransport); +// BLELocalDevice& BLE = BLEObj; +// #endif /* Shield IDB05A1 with SPI clock on D3 */ -/*SPIClass SpiHCI(D11, D12, D3); -HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI_MODE0); -#if !defined(FAKE_BLELOCALDEVICE) -BLELocalDevice BLEObj(&HCISpiTransport); -BLELocalDevice& BLE = BLEObj; -#endif */ +// SPIClass SpiHCI(D11, D12, D3); +// HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI_MODE0); +// #if !defined(FAKE_BLELOCALDEVICE) +// BLELocalDevice BLEObj(&HCISpiTransport); +// BLELocalDevice& BLE = BLEObj; +// #endif /* Shield IDB05A1 with SPI clock on D13 */ -/*#define SpiHCI SPI -HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI_MODE0); -#if !defined(FAKE_BLELOCALDEVICE) -BLELocalDevice BLEObj(&HCISpiTransport); -BLELocalDevice& BLE = BLEObj; -#endif */ +// #define SpiHCI SPI +// HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI_MODE0); +// #if !defined(FAKE_BLELOCALDEVICE) +// BLELocalDevice BLEObj(&HCISpiTransport); +// BLELocalDevice& BLE = BLEObj; +// #endif /* Shield BNRG2A1 with SPI clock on D3 */ -/*SPIClass SpiHCI(D11, D12, D3); -HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1); -#if !defined(FAKE_BLELOCALDEVICE) -BLELocalDevice BLEObj(&HCISpiTransport); -BLELocalDevice& BLE = BLEObj; -#endif */ +// SPIClass SpiHCI(D11, D12, D3); +// HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1); +// #if !defined(FAKE_BLELOCALDEVICE) +// BLELocalDevice BLEObj(&HCISpiTransport); +// BLELocalDevice& BLE = BLEObj; +// #endif /* Shield BNRG2A1 with SPI clock on D13 */ -/*#define SpiHCI SPI -HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1); -#if !defined(FAKE_BLELOCALDEVICE) -BLELocalDevice BLEObj(&HCISpiTransport); -BLELocalDevice& BLE = BLEObj; -#endif */ +// #define SpiHCI SPI +// HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1); +// #if !defined(FAKE_BLELOCALDEVICE) +// BLELocalDevice BLEObj(&HCISpiTransport); +// BLELocalDevice& BLE = BLEObj; +// #endif #endif void setup() { diff --git a/examples/Central/ScanCallback/ScanCallback.ino b/examples/Central/ScanCallback/ScanCallback.ino index e4067a45..199b8a34 100644 --- a/examples/Central/ScanCallback/ScanCallback.ino +++ b/examples/Central/ScanCallback/ScanCallback.ino @@ -53,40 +53,40 @@ BLELocalDevice BLEObj(&HCISpiTransport); BLELocalDevice& BLE = BLEObj; #endif /* Shield IDB05A2 with SPI clock on D13 */ -/*#define SpiHCI SPI -HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M0, A1, A0, D7, 8000000, SPI_MODE0); -#if !defined(FAKE_BLELOCALDEVICE) -BLELocalDevice BLEObj(&HCISpiTransport); -BLELocalDevice& BLE = BLEObj; -#endif */ +// #define SpiHCI SPI +// HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M0, A1, A0, D7, 8000000, SPI_MODE0); +// #if !defined(FAKE_BLELOCALDEVICE) +// BLELocalDevice BLEObj(&HCISpiTransport); +// BLELocalDevice& BLE = BLEObj; +// #endif /* Shield IDB05A1 with SPI clock on D3 */ -/*SPIClass SpiHCI(D11, D12, D3); -HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI_MODE0); -#if !defined(FAKE_BLELOCALDEVICE) -BLELocalDevice BLEObj(&HCISpiTransport); -BLELocalDevice& BLE = BLEObj; -#endif */ +// SPIClass SpiHCI(D11, D12, D3); +// HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI_MODE0); +// #if !defined(FAKE_BLELOCALDEVICE) +// BLELocalDevice BLEObj(&HCISpiTransport); +// BLELocalDevice& BLE = BLEObj; +// #endif /* Shield IDB05A1 with SPI clock on D13 */ -/*#define SpiHCI SPI -HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI_MODE0); -#if !defined(FAKE_BLELOCALDEVICE) -BLELocalDevice BLEObj(&HCISpiTransport); -BLELocalDevice& BLE = BLEObj; -#endif */ +// #define SpiHCI SPI +// HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI_MODE0); +// #if !defined(FAKE_BLELOCALDEVICE) +// BLELocalDevice BLEObj(&HCISpiTransport); +// BLELocalDevice& BLE = BLEObj; +// #endif /* Shield BNRG2A1 with SPI clock on D3 */ -/*SPIClass SpiHCI(D11, D12, D3); -HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1); -#if !defined(FAKE_BLELOCALDEVICE) -BLELocalDevice BLEObj(&HCISpiTransport); -BLELocalDevice& BLE = BLEObj; -#endif */ +// SPIClass SpiHCI(D11, D12, D3); +// HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1); +// #if !defined(FAKE_BLELOCALDEVICE) +// BLELocalDevice BLEObj(&HCISpiTransport); +// BLELocalDevice& BLE = BLEObj; +// #endif /* Shield BNRG2A1 with SPI clock on D13 */ -/*#define SpiHCI SPI -HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1); -#if !defined(FAKE_BLELOCALDEVICE) -BLELocalDevice BLEObj(&HCISpiTransport); -BLELocalDevice& BLE = BLEObj; -#endif */ +// #define SpiHCI SPI +// HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1); +// #if !defined(FAKE_BLELOCALDEVICE) +// BLELocalDevice BLEObj(&HCISpiTransport); +// BLELocalDevice& BLE = BLEObj; +// #endif #endif void setup() { diff --git a/examples/Central/SensorTagButton/SensorTagButton.ino b/examples/Central/SensorTagButton/SensorTagButton.ino index d4c740cc..6a097c70 100644 --- a/examples/Central/SensorTagButton/SensorTagButton.ino +++ b/examples/Central/SensorTagButton/SensorTagButton.ino @@ -55,40 +55,40 @@ BLELocalDevice BLEObj(&HCISpiTransport); BLELocalDevice& BLE = BLEObj; #endif /* Shield IDB05A2 with SPI clock on D13 */ -/*#define SpiHCI SPI -HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M0, A1, A0, D7, 8000000, SPI_MODE0); -#if !defined(FAKE_BLELOCALDEVICE) -BLELocalDevice BLEObj(&HCISpiTransport); -BLELocalDevice& BLE = BLEObj; -#endif */ +// #define SpiHCI SPI +// HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M0, A1, A0, D7, 8000000, SPI_MODE0); +// #if !defined(FAKE_BLELOCALDEVICE) +// BLELocalDevice BLEObj(&HCISpiTransport); +// BLELocalDevice& BLE = BLEObj; +// #endif /* Shield IDB05A1 with SPI clock on D3 */ -/*SPIClass SpiHCI(D11, D12, D3); -HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI_MODE0); -#if !defined(FAKE_BLELOCALDEVICE) -BLELocalDevice BLEObj(&HCISpiTransport); -BLELocalDevice& BLE = BLEObj; -#endif */ +// SPIClass SpiHCI(D11, D12, D3); +// HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI_MODE0); +// #if !defined(FAKE_BLELOCALDEVICE) +// BLELocalDevice BLEObj(&HCISpiTransport); +// BLELocalDevice& BLE = BLEObj; +// #endif /* Shield IDB05A1 with SPI clock on D13 */ -/*#define SpiHCI SPI -HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI_MODE0); -#if !defined(FAKE_BLELOCALDEVICE) -BLELocalDevice BLEObj(&HCISpiTransport); -BLELocalDevice& BLE = BLEObj; -#endif */ +// #define SpiHCI SPI +// HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI_MODE0); +// #if !defined(FAKE_BLELOCALDEVICE) +// BLELocalDevice BLEObj(&HCISpiTransport); +// BLELocalDevice& BLE = BLEObj; +// #endif /* Shield BNRG2A1 with SPI clock on D3 */ -/*SPIClass SpiHCI(D11, D12, D3); -HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1); -#if !defined(FAKE_BLELOCALDEVICE) -BLELocalDevice BLEObj(&HCISpiTransport); -BLELocalDevice& BLE = BLEObj; -#endif */ +// SPIClass SpiHCI(D11, D12, D3); +// HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1); +// #if !defined(FAKE_BLELOCALDEVICE) +// BLELocalDevice BLEObj(&HCISpiTransport); +// BLELocalDevice& BLE = BLEObj; +// #endif /* Shield BNRG2A1 with SPI clock on D13 */ -/*#define SpiHCI SPI -HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1); -#if !defined(FAKE_BLELOCALDEVICE) -BLELocalDevice BLEObj(&HCISpiTransport); -BLELocalDevice& BLE = BLEObj; -#endif */ +// #define SpiHCI SPI +// HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1); +// #if !defined(FAKE_BLELOCALDEVICE) +// BLELocalDevice BLEObj(&HCISpiTransport); +// BLELocalDevice& BLE = BLEObj; +// #endif #endif void setup() { diff --git a/examples/Peripheral/ButtonLED/ButtonLED.ino b/examples/Peripheral/ButtonLED/ButtonLED.ino index 91dfcb2a..3163cf6a 100644 --- a/examples/Peripheral/ButtonLED/ButtonLED.ino +++ b/examples/Peripheral/ButtonLED/ButtonLED.ino @@ -62,40 +62,40 @@ BLELocalDevice BLEObj(&HCISpiTransport); BLELocalDevice& BLE = BLEObj; #endif /* Shield IDB05A2 with SPI clock on D13 */ -/*#define SpiHCI SPI -HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M0, A1, A0, D7, 8000000, SPI_MODE0); -#if !defined(FAKE_BLELOCALDEVICE) -BLELocalDevice BLEObj(&HCISpiTransport); -BLELocalDevice& BLE = BLEObj; -#endif +// #define SpiHCI SPI +// HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M0, A1, A0, D7, 8000000, SPI_MODE0); +// #if !defined(FAKE_BLELOCALDEVICE) +// BLELocalDevice BLEObj(&HCISpiTransport); +// BLELocalDevice& BLE = BLEObj; +// #endif /* Shield IDB05A1 with SPI clock on D3 */ -/*SPIClass SpiHCI(D11, D12, D3); -HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI_MODE0); -#if !defined(FAKE_BLELOCALDEVICE) -BLELocalDevice BLEObj(&HCISpiTransport); -BLELocalDevice& BLE = BLEObj; -#endif +// SPIClass SpiHCI(D11, D12, D3); +// HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI_MODE0); +// #if !defined(FAKE_BLELOCALDEVICE) +// BLELocalDevice BLEObj(&HCISpiTransport); +// BLELocalDevice& BLE = BLEObj; +// #endif /* Shield IDB05A1 with SPI clock on D13 */ -/*#define SpiHCI SPI -HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI_MODE0); -#if !defined(FAKE_BLELOCALDEVICE) -BLELocalDevice BLEObj(&HCISpiTransport); -BLELocalDevice& BLE = BLEObj; -#endif +// #define SpiHCI SPI +// HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI_MODE0); +// #if !defined(FAKE_BLELOCALDEVICE) +// BLELocalDevice BLEObj(&HCISpiTransport); +// BLELocalDevice& BLE = BLEObj; +// #endif /* Shield BNRG2A1 with SPI clock on D3 */ -/*SPIClass SpiHCI(D11, D12, D3); -HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1); -#if !defined(FAKE_BLELOCALDEVICE) -BLELocalDevice BLEObj(&HCISpiTransport); -BLELocalDevice& BLE = BLEObj; -#endif +// SPIClass SpiHCI(D11, D12, D3); +// HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1); +// #if !defined(FAKE_BLELOCALDEVICE) +// BLELocalDevice BLEObj(&HCISpiTransport); +// BLELocalDevice& BLE = BLEObj; +// #endif /* Shield BNRG2A1 with SPI clock on D13 */ -/*#define SpiHCI SPI -HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1); -#if !defined(FAKE_BLELOCALDEVICE) -BLELocalDevice BLEObj(&HCISpiTransport); -BLELocalDevice& BLE = BLEObj; -#endif +// #define SpiHCI SPI +// HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1); +// #if !defined(FAKE_BLELOCALDEVICE) +// BLELocalDevice BLEObj(&HCISpiTransport); +// BLELocalDevice& BLE = BLEObj; +// #endif #endif const int ledPin = LED_BUILTIN; // set ledPin to on-board LED diff --git a/examples/Peripheral/CallbackLED/CallbackLED.ino b/examples/Peripheral/CallbackLED/CallbackLED.ino index 4177a44d..5b416fbb 100644 --- a/examples/Peripheral/CallbackLED/CallbackLED.ino +++ b/examples/Peripheral/CallbackLED/CallbackLED.ino @@ -56,40 +56,40 @@ BLELocalDevice BLEObj(&HCISpiTransport); BLELocalDevice& BLE = BLEObj; #endif /* Shield IDB05A2 with SPI clock on D13 */ -/*#define SpiHCI SPI -HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M0, A1, A0, D7, 8000000, SPI_MODE0); -#if !defined(FAKE_BLELOCALDEVICE) -BLELocalDevice BLEObj(&HCISpiTransport); -BLELocalDevice& BLE = BLEObj; -#endif */ +// #define SpiHCI SPI +// HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M0, A1, A0, D7, 8000000, SPI_MODE0); +// #if !defined(FAKE_BLELOCALDEVICE) +// BLELocalDevice BLEObj(&HCISpiTransport); +// BLELocalDevice& BLE = BLEObj; +// #endif /* Shield IDB05A1 with SPI clock on D3 */ -/*SPIClass SpiHCI(D11, D12, D3); -HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI_MODE0); -#if !defined(FAKE_BLELOCALDEVICE) -BLELocalDevice BLEObj(&HCISpiTransport); -BLELocalDevice& BLE = BLEObj; -#endif */ +// SPIClass SpiHCI(D11, D12, D3); +// HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI_MODE0); +// #if !defined(FAKE_BLELOCALDEVICE) +// BLELocalDevice BLEObj(&HCISpiTransport); +// BLELocalDevice& BLE = BLEObj; +// #endif /* Shield IDB05A1 with SPI clock on D13 */ -/*#define SpiHCI SPI -HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI_MODE0); -#if !defined(FAKE_BLELOCALDEVICE) -BLELocalDevice BLEObj(&HCISpiTransport); -BLELocalDevice& BLE = BLEObj; -#endif */ +// #define SpiHCI SPI +// HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI_MODE0); +// #if !defined(FAKE_BLELOCALDEVICE) +// BLELocalDevice BLEObj(&HCISpiTransport); +// BLELocalDevice& BLE = BLEObj; +// #endif /* Shield BNRG2A1 with SPI clock on D3 */ -/*SPIClass SpiHCI(D11, D12, D3); -HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1); -#if !defined(FAKE_BLELOCALDEVICE) -BLELocalDevice BLEObj(&HCISpiTransport); -BLELocalDevice& BLE = BLEObj; -#endif */ +// SPIClass SpiHCI(D11, D12, D3); +// HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1); +// #if !defined(FAKE_BLELOCALDEVICE) +// BLELocalDevice BLEObj(&HCISpiTransport); +// BLELocalDevice& BLE = BLEObj; +// #endif /* Shield BNRG2A1 with SPI clock on D13 */ -/*#define SpiHCI SPI -HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1); -#if !defined(FAKE_BLELOCALDEVICE) -BLELocalDevice BLEObj(&HCISpiTransport); -BLELocalDevice& BLE = BLEObj; -#endif */ +// #define SpiHCI SPI +// HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1); +// #if !defined(FAKE_BLELOCALDEVICE) +// BLELocalDevice BLEObj(&HCISpiTransport); +// BLELocalDevice& BLE = BLEObj; +// #endif #endif BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // create service diff --git a/examples/Peripheral/LED/LED.ino b/examples/Peripheral/LED/LED.ino index 487c4287..32cbfc9f 100644 --- a/examples/Peripheral/LED/LED.ino +++ b/examples/Peripheral/LED/LED.ino @@ -54,40 +54,40 @@ BLELocalDevice BLEObj(&HCISpiTransport); BLELocalDevice& BLE = BLEObj; #endif /* Shield IDB05A2 with SPI clock on D13 */ -/*#define SpiHCI SPI -HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M0, A1, A0, D7, 8000000, SPI_MODE0); -#if !defined(FAKE_BLELOCALDEVICE) -BLELocalDevice BLEObj(&HCISpiTransport); -BLELocalDevice& BLE = BLEObj; -#endif */ +// #define SpiHCI SPI +// HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M0, A1, A0, D7, 8000000, SPI_MODE0); +// #if !defined(FAKE_BLELOCALDEVICE) +// BLELocalDevice BLEObj(&HCISpiTransport); +// BLELocalDevice& BLE = BLEObj; +// #endif /* Shield IDB05A1 with SPI clock on D3 */ -/*SPIClass SpiHCI(D11, D12, D3); -HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI_MODE0); -#if !defined(FAKE_BLELOCALDEVICE) -BLELocalDevice BLEObj(&HCISpiTransport); -BLELocalDevice& BLE = BLEObj; -#endif */ +// SPIClass SpiHCI(D11, D12, D3); +// HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI_MODE0); +// #if !defined(FAKE_BLELOCALDEVICE) +// BLELocalDevice BLEObj(&HCISpiTransport); +// BLELocalDevice& BLE = BLEObj; +// #endif /* Shield IDB05A1 with SPI clock on D13 */ -/*#define SpiHCI SPI -HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI_MODE0); -#if !defined(FAKE_BLELOCALDEVICE) -BLELocalDevice BLEObj(&HCISpiTransport); -BLELocalDevice& BLE = BLEObj; -#endif */ +// #define SpiHCI SPI +// HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI_MODE0); +// #if !defined(FAKE_BLELOCALDEVICE) +// BLELocalDevice BLEObj(&HCISpiTransport); +// BLELocalDevice& BLE = BLEObj; +// #endif /* Shield BNRG2A1 with SPI clock on D3 */ -/*SPIClass SpiHCI(D11, D12, D3); -HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1); -#if !defined(FAKE_BLELOCALDEVICE) -BLELocalDevice BLEObj(&HCISpiTransport); -BLELocalDevice& BLE = BLEObj; -#endif */ +// SPIClass SpiHCI(D11, D12, D3); +// HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1); +// #if !defined(FAKE_BLELOCALDEVICE) +// BLELocalDevice BLEObj(&HCISpiTransport); +// BLELocalDevice& BLE = BLEObj; +// #endif /* Shield BNRG2A1 with SPI clock on D13 */ -/*#define SpiHCI SPI -HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1); -#if !defined(FAKE_BLELOCALDEVICE) -BLELocalDevice BLEObj(&HCISpiTransport); -BLELocalDevice& BLE = BLEObj; -#endif */ +// #define SpiHCI SPI +// HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1); +// #if !defined(FAKE_BLELOCALDEVICE) +// BLELocalDevice BLEObj(&HCISpiTransport); +// BLELocalDevice& BLE = BLEObj; +// #endif #endif BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // BLE LED Service From ce6cc8fa0691b983917d7638e32b32da838a51dc Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Mon, 9 Jan 2023 11:31:16 +0100 Subject: [PATCH 118/226] fix: regenerate STM32Cube_FW patches due to STM32WB15xx support addition Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- ...nd-adapt-STM32Cube_FW-sources-for-ST.patch | 2 +- ...imeout-when-waiting-for-the-cmd_resp.patch | 2 +- ...ort-for-customize-app_conf_default.h.patch | 66 +++++++++++++++---- 3 files changed, 57 insertions(+), 13 deletions(-) diff --git a/extras/STM32Cube_FW/0001-chore-clean-up-and-adapt-STM32Cube_FW-sources-for-ST.patch b/extras/STM32Cube_FW/0001-chore-clean-up-and-adapt-STM32Cube_FW-sources-for-ST.patch index 8b9ba87d..171554eb 100644 --- a/extras/STM32Cube_FW/0001-chore-clean-up-and-adapt-STM32Cube_FW-sources-for-ST.patch +++ b/extras/STM32Cube_FW/0001-chore-clean-up-and-adapt-STM32Cube_FW-sources-for-ST.patch @@ -1,4 +1,4 @@ -From f72f61b2a895a9f02a338c600af1de239939b357 Mon Sep 17 00:00:00 2001 +From 70812b4e3a184585354f979472a75a648266f53f Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Mon, 12 Dec 2022 17:15:26 +0100 Subject: [PATCH 1/3] chore: clean up and adapt STM32Cube_FW sources for diff --git a/extras/STM32Cube_FW/0002-fix-include-a-timeout-when-waiting-for-the-cmd_resp.patch b/extras/STM32Cube_FW/0002-fix-include-a-timeout-when-waiting-for-the-cmd_resp.patch index 5f7502df..81ac67fd 100644 --- a/extras/STM32Cube_FW/0002-fix-include-a-timeout-when-waiting-for-the-cmd_resp.patch +++ b/extras/STM32Cube_FW/0002-fix-include-a-timeout-when-waiting-for-the-cmd_resp.patch @@ -1,4 +1,4 @@ -From e12c9c97eec7eacb648720fc65adc2a3897ec257 Mon Sep 17 00:00:00 2001 +From a3c689a99506126587dfd7285c4b198db4a790e5 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Mon, 12 Dec 2022 17:17:48 +0100 Subject: [PATCH 2/3] fix: include a timeout when waiting for the cmd_resp diff --git a/extras/STM32Cube_FW/0003-chore-add-support-for-customize-app_conf_default.h.patch b/extras/STM32Cube_FW/0003-chore-add-support-for-customize-app_conf_default.h.patch index a93713f2..a10fa6e7 100644 --- a/extras/STM32Cube_FW/0003-chore-add-support-for-customize-app_conf_default.h.patch +++ b/extras/STM32Cube_FW/0003-chore-add-support-for-customize-app_conf_default.h.patch @@ -1,15 +1,15 @@ -From d7d18d20b957f52810315147d671c1976a18c1d2 Mon Sep 17 00:00:00 2001 +From 81472cc135126cb46701a058647de2cf82160fb9 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Mon, 12 Dec 2022 17:29:27 +0100 Subject: [PATCH 3/3] chore: add support for customize app_conf_default.h Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- - src/utility/STM32Cube_FW/app_conf_default.h | 58 +++++++++++++++------ - 1 file changed, 42 insertions(+), 16 deletions(-) + src/utility/STM32Cube_FW/app_conf_default.h | 88 ++++++++++++++++----- + 1 file changed, 68 insertions(+), 20 deletions(-) diff --git a/src/utility/STM32Cube_FW/app_conf_default.h b/src/utility/STM32Cube_FW/app_conf_default.h -index cc8c3e8..57f1027 100644 +index cc8c3e8..35cad34 100644 --- a/src/utility/STM32Cube_FW/app_conf_default.h +++ b/src/utility/STM32Cube_FW/app_conf_default.h @@ -41,7 +41,9 @@ @@ -23,13 +23,17 @@ index cc8c3e8..57f1027 100644 /****************************************************************************** * BLE Stack -@@ -50,13 +52,17 @@ +@@ -50,13 +52,25 @@ * Maximum number of simultaneous connections that the device will support. * Valid values are from 1 to 8 */ -#define CFG_BLE_NUM_LINK 8 +#ifndef CFG_BLE_NUM_LINK ++#ifdef STM32WB15xx ++ #define CFG_BLE_NUM_LINK 3 ++#else + #define CFG_BLE_NUM_LINK 8 ++#endif +#endif /** @@ -38,18 +42,26 @@ index cc8c3e8..57f1027 100644 */ -#define CFG_BLE_NUM_GATT_SERVICES 8 +#ifndef CFG_BLE_NUM_GATT_SERVICES ++#ifdef STM32WB15xx ++ #define CFG_BLE_NUM_GATT_SERVICES 4 ++#else + #define CFG_BLE_NUM_GATT_SERVICES 8 ++#endif +#endif /** * Maximum number of Attributes -@@ -65,13 +71,17 @@ +@@ -65,13 +79,21 @@ * Note that certain characteristics and relative descriptors are added automatically during device initialization * so this parameters should be 9 plus the number of user Attributes */ -#define CFG_BLE_NUM_GATT_ATTRIBUTES 68 +#ifndef CFG_BLE_NUM_GATT_ATTRIBUTES -+ #define CFG_BLE_NUM_GATT_ATTRIBUTES 68 ++#ifdef STM32WB15xx ++ #define CFG_BLE_NUM_GATT_ATTRIBUTES 30 ++#else ++ #define CFG_BLE_NUM_GATT_ATTRIBUTES 68 ++#endif +#endif /** @@ -63,13 +75,17 @@ index cc8c3e8..57f1027 100644 /** * Size of the storage area for Attribute values -@@ -84,14 +94,18 @@ +@@ -84,14 +106,22 @@ * The total amount of memory needed is the sum of the above quantities for each attribute. * This parameter is ignored by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set */ -#define CFG_BLE_ATT_VALUE_ARRAY_SIZE (1344) +#ifndef CFG_BLE_ATT_VALUE_ARRAY_SIZE ++#ifdef STM32WB15xx ++ #define CFG_BLE_ATT_VALUE_ARRAY_SIZE (1290) ++#else + #define CFG_BLE_ATT_VALUE_ARRAY_SIZE (1344) ++#endif +#endif /** @@ -84,7 +100,7 @@ index cc8c3e8..57f1027 100644 /** * Number of allocated memory blocks -@@ -103,12 +117,16 @@ +@@ -103,12 +133,16 @@ /** * Enable or disable the Extended Packet length feature. Valid values are 0 or 1. */ @@ -103,7 +119,7 @@ index cc8c3e8..57f1027 100644 /** * Sleep clock accuracy in Master mode -@@ -121,7 +139,9 @@ +@@ -121,7 +155,9 @@ * 6 : 21 ppm to 30 ppm * 7 : 0 ppm to 20 ppm */ @@ -114,7 +130,7 @@ index cc8c3e8..57f1027 100644 /** * LsSource -@@ -130,21 +150,27 @@ +@@ -130,21 +166,27 @@ * - bit 1: 1: STM32WB5M Module device 0: Other devices as STM32WBxx SOC, STM32WB1M module * - bit 2: 1: HSE/1024 Clock config 0: LSE Clock config */ @@ -148,6 +164,34 @@ index cc8c3e8..57f1027 100644 /** * Viterbi Mode +@@ -224,8 +266,11 @@ + * on Max Extended advertising configuration supported. + * This parameter is considered by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV flag set + */ +- +-#define CFG_BLE_MAX_ADV_SET_NBR (8) ++#if defined(STM32WB15xx) ++ #define CFG_BLE_MAX_ADV_SET_NBR (3) ++#else ++ #define CFG_BLE_MAX_ADV_SET_NBR (8) ++#endif + + /* Maximum advertising data length (in bytes) + * Range: 31 .. 1650 with limitation: +@@ -233,8 +278,11 @@ + * on Max Extended advertising configuration supported. + * This parameter is considered by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV flag set + */ +- +-#define CFG_BLE_MAX_ADV_DATA_LEN (207) ++#if defined(STM32WB15xx) ++ #define CFG_BLE_MAX_ADV_DATA_LEN (414) ++#else ++ #define CFG_BLE_MAX_ADV_DATA_LEN (207) ++#endif + + /* RF TX Path Compensation Value (16-bit signed integer). Units: 0.1 dB. + * Range: -1280 .. 1280 -- 2.38.0.windows.1 From b5a70eb5cab31e4f768310157c2e25da0c582c13 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Mon, 9 Jan 2023 11:49:52 +0100 Subject: [PATCH 119/226] chore(examples): update circuit description Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- examples/Central/LedControl/LedControl.ino | 12 +++++++++++- .../PeripheralExplorer/PeripheralExplorer.ino | 12 +++++++++++- examples/Central/Scan/Scan.ino | 12 +++++++++++- examples/Central/ScanCallback/ScanCallback.ino | 12 +++++++++++- examples/Central/SensorTagButton/SensorTagButton.ino | 12 +++++++++++- examples/Peripheral/ButtonLED/ButtonLED.ino | 12 +++++++++++- examples/Peripheral/CallbackLED/CallbackLED.ino | 12 +++++++++++- examples/Peripheral/LED/LED.ino | 12 +++++++++++- 8 files changed, 88 insertions(+), 8 deletions(-) diff --git a/examples/Central/LedControl/LedControl.ino b/examples/Central/LedControl/LedControl.ino index 09939cde..13768360 100644 --- a/examples/Central/LedControl/LedControl.ino +++ b/examples/Central/LedControl/LedControl.ino @@ -6,7 +6,17 @@ it will remotely control the BLE Peripheral's LED, when the button is pressed or released. The circuit: - - STEVAL-MKBOXPRO, STEVAL-MKSBOX1V1, B-L475E-IOT01A1, B_L4S5I_IOT01A, or a Nucleo board plus the X-NUCLEO-IDB05A2 or the X-NUCLEO-IDB05A1 or the X-NUCLEO-BNRG2A1 + - Boards with integrated BLE or Nucleo board plus one of BLE X-Nucleo shield:: + - B-L475E-IOT01A1 + - B_L4S5I_IOT01A + - STEVAL-MKBOXPRO + - STEVAL-MKSBOX1V1, + - NUCLEO-WB15CC + - P-NUCLEO-WB55RG + - STM32WB5MM-DK + - X-NUCLEO-IDB05A2 + - X-NUCLEO-IDB05A1 + - X-NUCLEO-BNRG2A1 You can use it with another board that is compatible with this library and the Peripherals -> LED example. diff --git a/examples/Central/PeripheralExplorer/PeripheralExplorer.ino b/examples/Central/PeripheralExplorer/PeripheralExplorer.ino index 09e204f6..52da33ca 100644 --- a/examples/Central/PeripheralExplorer/PeripheralExplorer.ino +++ b/examples/Central/PeripheralExplorer/PeripheralExplorer.ino @@ -5,7 +5,17 @@ is found. Then connects, and discovers + prints all the peripheral's attributes. The circuit: - - STEVAL-MKBOXPRO, STEVAL-MKSBOX1V1, B-L475E-IOT01A1, B_L4S5I_IOT01A, or a Nucleo board plus the X-NUCLEO-IDB05A2 or the X-NUCLEO-IDB05A1 or the X-NUCLEO-BNRG2A1 + - Boards with integrated BLE or Nucleo board plus one of BLE X-Nucleo shield:: + - B-L475E-IOT01A1 + - B_L4S5I_IOT01A + - STEVAL-MKBOXPRO + - STEVAL-MKSBOX1V1, + - NUCLEO-WB15CC + - P-NUCLEO-WB55RG + - STM32WB5MM-DK + - X-NUCLEO-IDB05A2 + - X-NUCLEO-IDB05A1 + - X-NUCLEO-BNRG2A1 You can use it with another board that is compatible with this library and the Peripherals -> LED example. diff --git a/examples/Central/Scan/Scan.ino b/examples/Central/Scan/Scan.ino index 14ea9f13..cc7275fd 100644 --- a/examples/Central/Scan/Scan.ino +++ b/examples/Central/Scan/Scan.ino @@ -5,7 +5,17 @@ address, local name, advertised service UUID's. The circuit: - - STEVAL-MKBOXPRO, STEVAL-MKSBOX1V1, B-L475E-IOT01A1, B_L4S5I_IOT01A, or a Nucleo board plus the X-NUCLEO-IDB05A2 or the X-NUCLEO-IDB05A1 or the X-NUCLEO-BNRG2A1 + - Boards with integrated BLE or Nucleo board plus one of BLE X-Nucleo shield:: + - B-L475E-IOT01A1 + - B_L4S5I_IOT01A + - STEVAL-MKBOXPRO + - STEVAL-MKSBOX1V1, + - NUCLEO-WB15CC + - P-NUCLEO-WB55RG + - STM32WB5MM-DK + - X-NUCLEO-IDB05A2 + - X-NUCLEO-IDB05A1 + - X-NUCLEO-BNRG2A1 This example code is in the public domain. */ diff --git a/examples/Central/ScanCallback/ScanCallback.ino b/examples/Central/ScanCallback/ScanCallback.ino index 199b8a34..f2ca6d6c 100644 --- a/examples/Central/ScanCallback/ScanCallback.ino +++ b/examples/Central/ScanCallback/ScanCallback.ino @@ -7,7 +7,17 @@ reported for every single advertisement it makes. The circuit: - - STEVAL-MKBOXPRO, STEVAL-MKSBOX1V1, B-L475E-IOT01A1, B_L4S5I_IOT01A, or a Nucleo board plus the X-NUCLEO-IDB05A2 or the X-NUCLEO-IDB05A1 or the X-NUCLEO-BNRG2A1 + - Boards with integrated BLE or Nucleo board plus one of BLE X-Nucleo shield:: + - B-L475E-IOT01A1 + - B_L4S5I_IOT01A + - STEVAL-MKBOXPRO + - STEVAL-MKSBOX1V1, + - NUCLEO-WB15CC + - P-NUCLEO-WB55RG + - STM32WB5MM-DK + - X-NUCLEO-IDB05A2 + - X-NUCLEO-IDB05A1 + - X-NUCLEO-BNRG2A1 This example code is in the public domain. */ diff --git a/examples/Central/SensorTagButton/SensorTagButton.ino b/examples/Central/SensorTagButton/SensorTagButton.ino index 6a097c70..75ccf254 100644 --- a/examples/Central/SensorTagButton/SensorTagButton.ino +++ b/examples/Central/SensorTagButton/SensorTagButton.ino @@ -8,7 +8,17 @@ outputted to the Serial Monitor when one is pressed. The circuit: - - STEVAL-MKBOXPRO, STEVAL-MKSBOX1V1, B-L475E-IOT01A1, B_L4S5I_IOT01A, or a Nucleo board plus the X-NUCLEO-IDB05A2 or the X-NUCLEO-IDB05A1 or the X-NUCLEO-BNRG2A1 + - Boards with integrated BLE or Nucleo board plus one of BLE X-Nucleo shield:: + - B-L475E-IOT01A1 + - B_L4S5I_IOT01A + - STEVAL-MKBOXPRO + - STEVAL-MKSBOX1V1, + - NUCLEO-WB15CC + - P-NUCLEO-WB55RG + - STM32WB5MM-DK + - X-NUCLEO-IDB05A2 + - X-NUCLEO-IDB05A1 + - X-NUCLEO-BNRG2A1 - TI SensorTag This example code is in the public domain. diff --git a/examples/Peripheral/ButtonLED/ButtonLED.ino b/examples/Peripheral/ButtonLED/ButtonLED.ino index 3163cf6a..8d014ade 100644 --- a/examples/Peripheral/ButtonLED/ButtonLED.ino +++ b/examples/Peripheral/ButtonLED/ButtonLED.ino @@ -6,7 +6,17 @@ represents the state of the button. The circuit: - - STEVAL-MKBOXPRO, STEVAL-MKSBOX1V1, B-L475E-IOT01A1, B_L4S5I_IOT01A, or a Nucleo board plus the X-NUCLEO-IDB05A2 or the X-NUCLEO-IDB05A1 or the X-NUCLEO-BNRG2A1 + - Boards with integrated BLE or Nucleo board plus one of BLE X-Nucleo shield:: + - B-L475E-IOT01A1 + - B_L4S5I_IOT01A + - STEVAL-MKBOXPRO + - STEVAL-MKSBOX1V1, + - NUCLEO-WB15CC + - P-NUCLEO-WB55RG + - STM32WB5MM-DK + - X-NUCLEO-IDB05A2 + - X-NUCLEO-IDB05A1 + - X-NUCLEO-BNRG2A1 You can use a generic BLE central app, like LightBlue (iOS and Android) or nRF Connect (Android), to interact with the services and characteristics diff --git a/examples/Peripheral/CallbackLED/CallbackLED.ino b/examples/Peripheral/CallbackLED/CallbackLED.ino index 5b416fbb..5f3e6d97 100644 --- a/examples/Peripheral/CallbackLED/CallbackLED.ino +++ b/examples/Peripheral/CallbackLED/CallbackLED.ino @@ -6,7 +6,17 @@ library are used. The circuit: - - STEVAL-MKBOXPRO, STEVAL-MKSBOX1V1, B-L475E-IOT01A1, B_L4S5I_IOT01A, or a Nucleo board plus the X-NUCLEO-IDB05A2 or the X-NUCLEO-IDB05A1 or the X-NUCLEO-BNRG2A1 + - Boards with integrated BLE or Nucleo board plus one of BLE X-Nucleo shield:: + - B-L475E-IOT01A1 + - B_L4S5I_IOT01A + - STEVAL-MKBOXPRO + - STEVAL-MKSBOX1V1, + - NUCLEO-WB15CC + - P-NUCLEO-WB55RG + - STM32WB5MM-DK + - X-NUCLEO-IDB05A2 + - X-NUCLEO-IDB05A1 + - X-NUCLEO-BNRG2A1 You can use a generic BLE central app, like LightBlue (iOS and Android) or nRF Connect (Android), to interact with the services and characteristics diff --git a/examples/Peripheral/LED/LED.ino b/examples/Peripheral/LED/LED.ino index 32cbfc9f..1ce9ea81 100644 --- a/examples/Peripheral/LED/LED.ino +++ b/examples/Peripheral/LED/LED.ino @@ -5,7 +5,17 @@ characteristic to control an LED. The circuit: - - STEVAL-MKBOXPRO, STEVAL-MKSBOX1V1, B-L475E-IOT01A1, B_L4S5I_IOT01A, or a Nucleo board plus the X-NUCLEO-IDB05A2 or the X-NUCLEO-IDB05A1 or the X-NUCLEO-BNRG2A1 + - Boards with integrated BLE or Nucleo board plus one of BLE X-Nucleo shield:: + - B-L475E-IOT01A1 + - B_L4S5I_IOT01A + - STEVAL-MKBOXPRO + - STEVAL-MKSBOX1V1, + - NUCLEO-WB15CC + - P-NUCLEO-WB55RG + - STM32WB5MM-DK + - X-NUCLEO-IDB05A2 + - X-NUCLEO-IDB05A1 + - X-NUCLEO-BNRG2A1 You can use a generic BLE central app, like LightBlue (iOS and Android) or nRF Connect (Android), to interact with the services and characteristics From 616f2fb58d0a3acd6d61762c19759501852c31b4 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Mon, 9 Jan 2023 11:54:49 +0100 Subject: [PATCH 120/226] chore: bump library version Warning: not aligned with ArduinoBLE one Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index e9f8de55..e36e566c 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=STM32duinoBLE -version=1.2.1 +version=1.2.2 author=Arduino, SRA maintainer=stm32duino sentence=Fork of ArduinoBLE library to add the support of STM32WB, SPBTLE-RF, SPBTLE-1S, BLUENRG-M2SP and BLUENRG-M0 BLE modules. From 240590a0f52da596fa24a042e1fa2956a931c61c Mon Sep 17 00:00:00 2001 From: Lorenzo Bini <lorenzo.bini@studenti.unimi.it> Date: Tue, 14 Mar 2023 17:19:12 +0100 Subject: [PATCH 121/226] Add API to get random address --- src/local/BLELocalDevice.cpp | 19 +++++++++++++++++++ src/local/BLELocalDevice.h | 3 +++ 2 files changed, 22 insertions(+) diff --git a/src/local/BLELocalDevice.cpp b/src/local/BLELocalDevice.cpp index b5869b5a..60519dc6 100644 --- a/src/local/BLELocalDevice.cpp +++ b/src/local/BLELocalDevice.cpp @@ -60,6 +60,15 @@ int BLELocalDevice::begin() * Force both MSB bits to b00 in order to define Static Random Address */ randomNumber[5] |= 0xC0; + + // Copy the random address in private variable as it will be sent to the BLE chip + randomAddress [0] = randomNumber[0]; + randomAddress [1] = randomNumber[1]; + randomAddress [2] = randomNumber[2]; + randomAddress [3] = randomNumber[3]; + randomAddress [4] = randomNumber[4]; + randomAddress [5] = randomNumber[5]; + if (HCI.leSetRandomAddress((uint8_t*)randomNumber) != 0) { end(); return 0; @@ -105,6 +114,16 @@ void BLELocalDevice::end() HCI.end(); } +void BLELocalDevice::getRandomAddress(uint8_t buff[6]) +{ + buff [0] = randomAddress[0]; + buff [1] = randomAddress[1]; + buff [2] = randomAddress[2]; + buff [3] = randomAddress[3]; + buff [4] = randomAddress[4]; + buff [5] = randomAddress[5]; +} + void BLELocalDevice::poll() { HCI.poll(); diff --git a/src/local/BLELocalDevice.h b/src/local/BLELocalDevice.h index beddb0ee..f0cc345c 100644 --- a/src/local/BLELocalDevice.h +++ b/src/local/BLELocalDevice.h @@ -84,6 +84,8 @@ class BLELocalDevice { virtual void setTimeout(unsigned long timeout); + virtual void getRandomAddress(uint8_t buff[6]); + virtual void debug(Stream& stream); virtual void noDebug(); @@ -92,6 +94,7 @@ class BLELocalDevice { virtual BLEAdvertisingData& getScanResponseData(); private: + uint8_t randomAddress[6]; HCITransportInterface *_HCITransport; BLEAdvertisingData _advertisingData; BLEAdvertisingData _scanResponseData; From b0a1849df65d570672be178dffdbcfa7aa144b09 Mon Sep 17 00:00:00 2001 From: Carlo Parata <carlo.parata@st.com> Date: Fri, 17 Mar 2023 09:57:50 +0100 Subject: [PATCH 122/226] Update library.properties Signed-off-by: Carlo Parata <carlo.parata@st.com> --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index e36e566c..16bc2da4 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=STM32duinoBLE -version=1.2.2 +version=1.2.3 author=Arduino, SRA maintainer=stm32duino sentence=Fork of ArduinoBLE library to add the support of STM32WB, SPBTLE-RF, SPBTLE-1S, BLUENRG-M2SP and BLUENRG-M0 BLE modules. From 929b540b051eeb8621ad681c6922806cf9501a23 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Wed, 8 Feb 2023 16:50:46 +0100 Subject: [PATCH 123/226] fix: warning outside array bounds array subscript 'TL_CcEvt_t[0]' is partly outside array bounds Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- src/utility/STM32Cube_FW/shci.c | 56 ++++++++++++++++----------------- src/utility/STM32Cube_FW/tl.h | 3 ++ 2 files changed, 31 insertions(+), 28 deletions(-) diff --git a/src/utility/STM32Cube_FW/shci.c b/src/utility/STM32Cube_FW/shci.c index a8475222..8b241bbe 100644 --- a/src/utility/STM32Cube_FW/shci.c +++ b/src/utility/STM32Cube_FW/shci.c @@ -42,7 +42,7 @@ uint8_t SHCI_C2_FUS_GetState( SHCI_FUS_GetState_ErrorCode_t *p_error_code ) /** * A command status event + payload has the same size than the expected command complete */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE + 1]; + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; @@ -66,7 +66,7 @@ SHCI_CmdStatus_t SHCI_C2_FUS_FwUpgrade( uint32_t fw_src_add, uint32_t fw_dest_a * TL_BLEEVT_CS_BUFFER_SIZE is 15 bytes so it is large enough to hold the 8 bytes of command parameters * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; uint32_t *p_cmd; uint8_t cmd_length; @@ -101,7 +101,7 @@ SHCI_CmdStatus_t SHCI_C2_FUS_FwDelete( void ) /** * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; @@ -119,7 +119,7 @@ SHCI_CmdStatus_t SHCI_C2_FUS_UpdateAuthKey( SHCI_C2_FUS_UpdateAuthKey_Cmd_Param_ /** * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; @@ -137,7 +137,7 @@ SHCI_CmdStatus_t SHCI_C2_FUS_LockAuthKey( void ) /** * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; @@ -155,7 +155,7 @@ SHCI_CmdStatus_t SHCI_C2_FUS_StoreUsrKey( SHCI_C2_FUS_StoreUsrKey_Cmd_Param_t *p /** * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE + 1]; + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; uint8_t local_payload_len; @@ -189,7 +189,7 @@ SHCI_CmdStatus_t SHCI_C2_FUS_LoadUsrKey( uint8_t key_index ) /** * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; @@ -209,7 +209,7 @@ SHCI_CmdStatus_t SHCI_C2_FUS_StartWs( void ) /** * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; @@ -227,7 +227,7 @@ SHCI_CmdStatus_t SHCI_C2_FUS_LockUsrKey( uint8_t key_index ) /** * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; @@ -247,7 +247,7 @@ SHCI_CmdStatus_t SHCI_C2_FUS_UnloadUsrKey( uint8_t key_index ) /** * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; @@ -267,7 +267,7 @@ SHCI_CmdStatus_t SHCI_C2_FUS_ActivateAntiRollback( void ) /** * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; @@ -285,7 +285,7 @@ SHCI_CmdStatus_t SHCI_C2_BLE_Init( SHCI_C2_Ble_Init_Cmd_Packet_t *pCmdPacket ) /** * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; @@ -303,7 +303,7 @@ SHCI_CmdStatus_t SHCI_C2_THREAD_Init( void ) /** * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; @@ -321,7 +321,7 @@ SHCI_CmdStatus_t SHCI_C2_LLDTESTS_Init( uint8_t param_size, uint8_t * p_param ) /** * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; @@ -339,7 +339,7 @@ SHCI_CmdStatus_t SHCI_C2_BLE_LLD_Init( uint8_t param_size, uint8_t * p_param ) /** * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; @@ -357,7 +357,7 @@ SHCI_CmdStatus_t SHCI_C2_DEBUG_Init( SHCI_C2_DEBUG_Init_Cmd_Packet_t *pCmdPacket /** * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; @@ -375,7 +375,7 @@ SHCI_CmdStatus_t SHCI_C2_FLASH_EraseActivity( SHCI_EraseActivity_t erase_activit /** * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; @@ -395,7 +395,7 @@ SHCI_CmdStatus_t SHCI_C2_CONCURRENT_SetMode( SHCI_C2_CONCURRENT_Mode_Param_t Mod /** * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; @@ -415,7 +415,7 @@ SHCI_CmdStatus_t SHCI_C2_CONCURRENT_GetNextBleEvtTime( SHCI_C2_CONCURRENT_GetNex /** * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE+4]; + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; @@ -435,7 +435,7 @@ SHCI_CmdStatus_t SHCI_C2_CONCURRENT_EnableNext_802154_EvtNotification( void ) /** * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; @@ -453,7 +453,7 @@ SHCI_CmdStatus_t SHCI_C2_FLASH_StoreData( SHCI_C2_FLASH_Ip_t Ip ) /** * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; @@ -473,7 +473,7 @@ SHCI_CmdStatus_t SHCI_C2_FLASH_EraseData( SHCI_C2_FLASH_Ip_t Ip ) /** * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; @@ -493,7 +493,7 @@ SHCI_CmdStatus_t SHCI_C2_RADIO_AllowLowPower( SHCI_C2_FLASH_Ip_t Ip,uint8_t Fla /** * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; @@ -514,7 +514,7 @@ SHCI_CmdStatus_t SHCI_C2_Reinit( void ) /** * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; @@ -533,7 +533,7 @@ SHCI_CmdStatus_t SHCI_C2_ExtpaConfig(uint32_t gpio_port, uint16_t gpio_pin_numbe * TL_BLEEVT_CS_BUFFER_SIZE is 15 bytes so it is large enough to hold the 8 bytes of command parameters * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; @@ -557,7 +557,7 @@ SHCI_CmdStatus_t SHCI_C2_SetFlashActivityControl(SHCI_C2_SET_FLASH_ACTIVITY_CONT * TL_BLEEVT_CS_BUFFER_SIZE is 15 bytes so it is large enough to hold the 1 byte of command parameter * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; @@ -577,7 +577,7 @@ SHCI_CmdStatus_t SHCI_C2_Config(SHCI_C2_CONFIG_Cmd_Param_t *pCmdPacket) /** * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; @@ -595,7 +595,7 @@ SHCI_CmdStatus_t SHCI_C2_802_15_4_DeInit( void ) /** * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; diff --git a/src/utility/STM32Cube_FW/tl.h b/src/utility/STM32Cube_FW/tl.h index 982bb586..354851ac 100644 --- a/src/utility/STM32Cube_FW/tl.h +++ b/src/utility/STM32Cube_FW/tl.h @@ -61,6 +61,9 @@ extern "C" { #define TL_BLEEVT_CS_PACKET_SIZE (TL_EVT_HDR_SIZE + sizeof(TL_CsEvt_t)) #define TL_BLEEVT_CS_BUFFER_SIZE (sizeof(TL_PacketHeader_t) + TL_BLEEVT_CS_PACKET_SIZE) +#define TL_BLEEVT_CC_PACKET_SIZE (TL_EVT_HDR_SIZE + sizeof(TL_CcEvt_t)) +#define TL_BLEEVT_CC_BUFFER_SIZE (sizeof(TL_PacketHeader_t) + TL_BLEEVT_CC_PACKET_SIZE) + /* Exported types ------------------------------------------------------------*/ /**< Packet header */ typedef PACKED_STRUCT From a5e0fed7d1dd3a5553d8b2ffda878cc22f23b88e Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Wed, 29 Mar 2023 10:05:59 +0200 Subject: [PATCH 124/226] examples: add P_NUCLEO_WB55_USB_DONGLE support Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- examples/Central/LedControl/LedControl.ino | 3 ++- examples/Central/PeripheralExplorer/PeripheralExplorer.ino | 3 ++- examples/Central/Scan/Scan.ino | 3 ++- examples/Central/ScanCallback/ScanCallback.ino | 3 ++- examples/Central/SensorTagButton/SensorTagButton.ino | 3 ++- examples/Peripheral/ButtonLED/ButtonLED.ino | 3 ++- examples/Peripheral/CallbackLED/CallbackLED.ino | 3 ++- examples/Peripheral/LED/LED.ino | 3 ++- 8 files changed, 16 insertions(+), 8 deletions(-) diff --git a/examples/Central/LedControl/LedControl.ino b/examples/Central/LedControl/LedControl.ino index 13768360..08db7aca 100644 --- a/examples/Central/LedControl/LedControl.ino +++ b/examples/Central/LedControl/LedControl.ino @@ -56,7 +56,8 @@ HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, PD13, PE6, PA8, 8000000, BLELocalDevice BLEObj(&HCISpiTransport); BLELocalDevice& BLE = BLEObj; #endif -#elif defined(ARDUINO_NUCLEO_WB15CC) || defined(ARDUINO_P_NUCLEO_WB55RG) || defined(ARDUINO_STM32WB5MM_DK) +#elif defined(ARDUINO_NUCLEO_WB15CC) || defined(ARDUINO_P_NUCLEO_WB55RG) ||\ + defined(ARDUINO_STM32WB5MM_DK) || defined(P_NUCLEO_WB55_USB_DONGLE) HCISharedMemTransportClass HCISharedMemTransport; #if !defined(FAKE_BLELOCALDEVICE) BLELocalDevice BLEObj(&HCISharedMemTransport); diff --git a/examples/Central/PeripheralExplorer/PeripheralExplorer.ino b/examples/Central/PeripheralExplorer/PeripheralExplorer.ino index 52da33ca..44aa00c4 100644 --- a/examples/Central/PeripheralExplorer/PeripheralExplorer.ino +++ b/examples/Central/PeripheralExplorer/PeripheralExplorer.ino @@ -50,7 +50,8 @@ HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, PD13, PE6, PA8, 8000000, BLELocalDevice BLEObj(&HCISpiTransport); BLELocalDevice& BLE = BLEObj; #endif -#elif defined(ARDUINO_NUCLEO_WB15CC) || defined(ARDUINO_P_NUCLEO_WB55RG) || defined(ARDUINO_STM32WB5MM_DK) +#elif defined(ARDUINO_NUCLEO_WB15CC) || defined(ARDUINO_P_NUCLEO_WB55RG) ||\ + defined(ARDUINO_STM32WB5MM_DK) || defined(P_NUCLEO_WB55_USB_DONGLE) HCISharedMemTransportClass HCISharedMemTransport; #if !defined(FAKE_BLELOCALDEVICE) BLELocalDevice BLEObj(&HCISharedMemTransport); diff --git a/examples/Central/Scan/Scan.ino b/examples/Central/Scan/Scan.ino index cc7275fd..4c34e563 100644 --- a/examples/Central/Scan/Scan.ino +++ b/examples/Central/Scan/Scan.ino @@ -46,7 +46,8 @@ HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, PD13, PE6, PA8, 8000000, BLELocalDevice BLEObj(&HCISpiTransport); BLELocalDevice& BLE = BLEObj; #endif -#elif defined(ARDUINO_NUCLEO_WB15CC) || defined(ARDUINO_P_NUCLEO_WB55RG) || defined(ARDUINO_STM32WB5MM_DK) +#elif defined(ARDUINO_NUCLEO_WB15CC) || defined(ARDUINO_P_NUCLEO_WB55RG) ||\ + defined(ARDUINO_STM32WB5MM_DK) || defined(P_NUCLEO_WB55_USB_DONGLE) HCISharedMemTransportClass HCISharedMemTransport; #if !defined(FAKE_BLELOCALDEVICE) BLELocalDevice BLEObj(&HCISharedMemTransport); diff --git a/examples/Central/ScanCallback/ScanCallback.ino b/examples/Central/ScanCallback/ScanCallback.ino index f2ca6d6c..bba10789 100644 --- a/examples/Central/ScanCallback/ScanCallback.ino +++ b/examples/Central/ScanCallback/ScanCallback.ino @@ -48,7 +48,8 @@ HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, PD13, PE6, PA8, 8000000, BLELocalDevice BLEObj(&HCISpiTransport); BLELocalDevice& BLE = BLEObj; #endif -#elif defined(ARDUINO_NUCLEO_WB15CC) || defined(ARDUINO_P_NUCLEO_WB55RG) || defined(ARDUINO_STM32WB5MM_DK) +#elif defined(ARDUINO_NUCLEO_WB15CC) || defined(ARDUINO_P_NUCLEO_WB55RG) ||\ + defined(ARDUINO_STM32WB5MM_DK) || defined(P_NUCLEO_WB55_USB_DONGLE) HCISharedMemTransportClass HCISharedMemTransport; #if !defined(FAKE_BLELOCALDEVICE) BLELocalDevice BLEObj(&HCISharedMemTransport); diff --git a/examples/Central/SensorTagButton/SensorTagButton.ino b/examples/Central/SensorTagButton/SensorTagButton.ino index 75ccf254..b371617f 100644 --- a/examples/Central/SensorTagButton/SensorTagButton.ino +++ b/examples/Central/SensorTagButton/SensorTagButton.ino @@ -50,7 +50,8 @@ HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, PD13, PE6, PA8, 8000000, BLELocalDevice BLEObj(&HCISpiTransport); BLELocalDevice& BLE = BLEObj; #endif -#elif defined(ARDUINO_NUCLEO_WB15CC) || defined(ARDUINO_P_NUCLEO_WB55RG) || defined(ARDUINO_STM32WB5MM_DK) +#elif defined(ARDUINO_NUCLEO_WB15CC) || defined(ARDUINO_P_NUCLEO_WB55RG) ||\ + defined(ARDUINO_STM32WB5MM_DK) || defined(P_NUCLEO_WB55_USB_DONGLE) HCISharedMemTransportClass HCISharedMemTransport; #if !defined(FAKE_BLELOCALDEVICE) BLELocalDevice BLEObj(&HCISharedMemTransport); diff --git a/examples/Peripheral/ButtonLED/ButtonLED.ino b/examples/Peripheral/ButtonLED/ButtonLED.ino index 8d014ade..fb186766 100644 --- a/examples/Peripheral/ButtonLED/ButtonLED.ino +++ b/examples/Peripheral/ButtonLED/ButtonLED.ino @@ -57,7 +57,8 @@ HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, PD13, PE6, PA8, 8000000, BLELocalDevice BLEObj(&HCISpiTransport); BLELocalDevice& BLE = BLEObj; #endif -#elif defined(ARDUINO_NUCLEO_WB15CC) || defined(ARDUINO_P_NUCLEO_WB55RG) || defined(ARDUINO_STM32WB5MM_DK) +#elif defined(ARDUINO_NUCLEO_WB15CC) || defined(ARDUINO_P_NUCLEO_WB55RG) ||\ + defined(ARDUINO_STM32WB5MM_DK) || defined(P_NUCLEO_WB55_USB_DONGLE) HCISharedMemTransportClass HCISharedMemTransport; #if !defined(FAKE_BLELOCALDEVICE) BLELocalDevice BLEObj(&HCISharedMemTransport); diff --git a/examples/Peripheral/CallbackLED/CallbackLED.ino b/examples/Peripheral/CallbackLED/CallbackLED.ino index 5f3e6d97..0326f732 100644 --- a/examples/Peripheral/CallbackLED/CallbackLED.ino +++ b/examples/Peripheral/CallbackLED/CallbackLED.ino @@ -51,7 +51,8 @@ HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, PD13, PE6, PA8, 8000000, BLELocalDevice BLEObj(&HCISpiTransport); BLELocalDevice& BLE = BLEObj; #endif -#elif defined(ARDUINO_NUCLEO_WB15CC) || defined(ARDUINO_P_NUCLEO_WB55RG) || defined(ARDUINO_STM32WB5MM_DK) +#elif defined(ARDUINO_NUCLEO_WB15CC) || defined(ARDUINO_P_NUCLEO_WB55RG) ||\ + defined(ARDUINO_STM32WB5MM_DK) || defined(P_NUCLEO_WB55_USB_DONGLE) HCISharedMemTransportClass HCISharedMemTransport; #if !defined(FAKE_BLELOCALDEVICE) BLELocalDevice BLEObj(&HCISharedMemTransport); diff --git a/examples/Peripheral/LED/LED.ino b/examples/Peripheral/LED/LED.ino index 1ce9ea81..1ba9c9a8 100644 --- a/examples/Peripheral/LED/LED.ino +++ b/examples/Peripheral/LED/LED.ino @@ -49,7 +49,8 @@ HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, PD13, PE6, PA8, 8000000, BLELocalDevice BLEObj(&HCISpiTransport); BLELocalDevice& BLE = BLEObj; #endif -#elif defined(ARDUINO_NUCLEO_WB15CC) || defined(ARDUINO_P_NUCLEO_WB55RG) || defined(ARDUINO_STM32WB5MM_DK) +#elif defined(ARDUINO_NUCLEO_WB15CC) || defined(ARDUINO_P_NUCLEO_WB55RG) ||\ + defined(ARDUINO_STM32WB5MM_DK) || defined(P_NUCLEO_WB55_USB_DONGLE) HCISharedMemTransportClass HCISharedMemTransport; #if !defined(FAKE_BLELOCALDEVICE) BLELocalDevice BLEObj(&HCISharedMemTransport); From 902a770a9d2deb7d807d891ad8c0974e55290511 Mon Sep 17 00:00:00 2001 From: Lorenzo Bini <lorenzo.bini.97@proton.me> Date: Thu, 30 Mar 2023 12:03:37 +0200 Subject: [PATCH 125/226] Add support for latest firmware in BLUENRG-M2SP chips. This requires changing the SPI dummy package to 0x00 due to signaling over the MOSI pin --- src/utility/HCISpiTransport.cpp | 54 ++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/src/utility/HCISpiTransport.cpp b/src/utility/HCISpiTransport.cpp index 5c18083f..ac9b4814 100644 --- a/src/utility/HCISpiTransport.cpp +++ b/src/utility/HCISpiTransport.cpp @@ -67,10 +67,10 @@ int HCISpiTransportClass::begin() digitalWrite(_ble_rst, HIGH); delay(5); - if (_ble_chip == SPBTLE_RF || _ble_chip == BLUENRG_M0 || _ble_chip == BLUENRG_LP) { + if (_ble_chip == SPBTLE_RF || _ble_chip == BLUENRG_M0 || _ble_chip == BLUENRG_LP || _ble_chip == BLUENRG_M2SP) { // Wait for Blue Initialize wait_for_blue_initialize(); - } else if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP) { + } else if (_ble_chip == SPBTLE_1S) { // Wait a while for the reset of the BLE module delay(300); } else { @@ -146,7 +146,7 @@ int HCISpiTransportClass::available() /* Read the response */ for (int j = 0; j < byte_count; j++) { - _rxbuff[_write_index_initial] = _spi->transfer(0xFF); + _rxbuff[_write_index_initial] = _spi->transfer(0x00); _write_index_initial++; } @@ -172,7 +172,7 @@ int HCISpiTransportClass::available() /* Read the response */ for (int j = 0; j < byte_count; j++) { - _rxbuff[_write_index] = _spi->transfer(0xFF); + _rxbuff[_write_index] = _spi->transfer(0x00); _write_index++; } } @@ -190,7 +190,7 @@ int HCISpiTransportClass::available() /* Read the response */ for (int j = 0; j < byte_count; j++) { - _rxbuff[_write_index_initial] = _spi->transfer(0xFF); + _rxbuff[_write_index_initial] = _spi->transfer(0x00); _write_index_initial++; } @@ -217,7 +217,7 @@ int HCISpiTransportClass::available() /* Read the response */ for (int j = 0; j < byte_count; j++) { - _rxbuff[_write_index] = _spi->transfer(0xFF); + _rxbuff[_write_index] = _spi->transfer(0x00); _write_index++; } } @@ -234,11 +234,15 @@ int HCISpiTransportClass::available() } if (ble_reset) { - if (_ble_chip == SPBTLE_RF || _ble_chip == BLUENRG_M0 || _ble_chip == BLUENRG_LP) { + if (_ble_chip == BLUENRG_M2SP) { + wait_for_blue_initialize(); + } + + if (_ble_chip == SPBTLE_RF || _ble_chip == BLUENRG_M0 || _ble_chip == BLUENRG_LP || _ble_chip == BLUENRG_M2SP) { /* BLE chip was reset: we need to enable LL_ONLY */ enable_ll_only(); wait_for_enable_ll_only(); - } else if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP) { + } else if (_ble_chip == SPBTLE_1S) { /* BLE chip was reset: we need to wait for a while */ delay(300); } @@ -447,7 +451,7 @@ void HCISpiTransportClass::wait_for_blue_initialize() /* Read the response */ if (byte_count == 6) { for (int j = 0; j < byte_count; j++) { - event[j] = _spi->transfer(0xFF); + event[j] = _spi->transfer(0x00); } if (event[0] == 0x04 && @@ -460,7 +464,7 @@ void HCISpiTransportClass::wait_for_blue_initialize() } } else { for (int j = 0; j < byte_count; j++) { - _spi->transfer(0xFF); + _spi->transfer(0x00); } } } @@ -472,7 +476,7 @@ void HCISpiTransportClass::wait_for_blue_initialize() /* Read the response */ if (byte_count == 6) { for (int j = 0; j < byte_count; j++) { - event[j] = _spi->transfer(0xFF); + event[j] = _spi->transfer(0x00); } if (event[0] == 0x04 && @@ -485,7 +489,7 @@ void HCISpiTransportClass::wait_for_blue_initialize() } } else { for (int j = 0; j < byte_count; j++) { - _spi->transfer(0xFF); + _spi->transfer(0x00); } } } @@ -496,7 +500,7 @@ void HCISpiTransportClass::wait_for_blue_initialize() /* Read the response */ if (byte_count == 7) { for (int j = 0; j < byte_count; j++) { - event[j] = _spi->transfer(0xFF); + event[j] = _spi->transfer(0x00); } if (event[0] == 0x82 && @@ -510,7 +514,7 @@ void HCISpiTransportClass::wait_for_blue_initialize() } } else { for (int j = 0; j < byte_count; j++) { - _spi->transfer(0xFF); + _spi->transfer(0x00); } } } @@ -563,7 +567,7 @@ void HCISpiTransportClass::wait_for_enable_ll_only() if (byte_count > 0) { /* Read the response */ for (int j = 0; j < byte_count; j++) { - data[j] = _spi->transfer(0xFF); + data[j] = _spi->transfer(0x00); } if (byte_count >= 7) { @@ -585,7 +589,7 @@ void HCISpiTransportClass::wait_for_enable_ll_only() if (byte_count > 0) { /* Read the response */ for (int j = 0; j < byte_count; j++) { - data[j] = _spi->transfer(0xFF); + data[j] = _spi->transfer(0x00); } if (byte_count >= 7) { @@ -725,7 +729,7 @@ void HCISpiTransportClass::wait_for_aci_gatt_init() if (byte_count > 0) { /* Read the response */ for (int j = 0; j < byte_count; j++) { - data[j] = _spi->transfer(0xFF); + data[j] = _spi->transfer(0x00); } if (byte_count >= 7) { @@ -747,7 +751,7 @@ void HCISpiTransportClass::wait_for_aci_gatt_init() if (byte_count > 0) { /* Read the response */ for (int j = 0; j < byte_count; j++) { - data[j] = _spi->transfer(0xFF); + data[j] = _spi->transfer(0x00); } if (byte_count >= 7) { @@ -887,7 +891,7 @@ void HCISpiTransportClass::wait_for_aci_gap_init() if (byte_count > 0) { /* Read the response */ for (int j = 0; j < byte_count; j++) { - data[j] = _spi->transfer(0xFF); + data[j] = _spi->transfer(0x00); } if (byte_count >= 13) { @@ -909,7 +913,7 @@ void HCISpiTransportClass::wait_for_aci_gap_init() if (byte_count > 0) { /* Read the response */ for (int j = 0; j < byte_count; j++) { - data[j] = _spi->transfer(0xFF); + data[j] = _spi->transfer(0x00); } if (byte_count >= 13) { @@ -1058,7 +1062,7 @@ void HCISpiTransportClass::wait_for_aci_read_config_parameter() if (byte_count > 0) { /* Read the response */ for (int j = 0; j < byte_count; j++) { - data[j] = _spi->transfer(0xFF); + data[j] = _spi->transfer(0x00); } if (byte_count >= 13) { @@ -1081,7 +1085,7 @@ void HCISpiTransportClass::wait_for_aci_read_config_parameter() if (byte_count > 0) { /* Read the response */ for (int j = 0; j < byte_count; j++) { - data[j] = _spi->transfer(0xFF); + data[j] = _spi->transfer(0x00); } if (byte_count >= 14) { @@ -1293,7 +1297,9 @@ void HCISpiTransportClass::wait_for_set_address() uint8_t data[15]; int status = 0; - if (_ble_chip != BLUENRG_LP) return; + if (_ble_chip != BLUENRG_LP) { + return; + } do { while (!data_avail); @@ -1321,7 +1327,7 @@ void HCISpiTransportClass::wait_for_set_address() if (byte_count > 0) { /* Read the response */ for (int j = 0; j < byte_count; j++) { - data[j] = _spi->transfer(0xFF); + data[j] = _spi->transfer(0x00); } if (byte_count >= 7) { // 040E0401052000 From bd27383c8f197387ac7a828ea23cb15efcea88d5 Mon Sep 17 00:00:00 2001 From: Carlo Parata <carlo.parata@st.com> Date: Thu, 30 Mar 2023 16:15:07 +0200 Subject: [PATCH 126/226] Update library.properties Signed-off-by: Carlo Parata <carlo.parata@st.com> --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index 16bc2da4..c8a3119d 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=STM32duinoBLE -version=1.2.3 +version=1.2.4 author=Arduino, SRA maintainer=stm32duino sentence=Fork of ArduinoBLE library to add the support of STM32WB, SPBTLE-RF, SPBTLE-1S, BLUENRG-M2SP and BLUENRG-M0 BLE modules. From df966713d625f9f2c16ba126e3075f63d72985d2 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Wed, 5 Apr 2023 14:32:40 +0200 Subject: [PATCH 127/226] fix: regenerate STM32Cube_FW patches Prepare update to version 1.16.0 Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- ...001-chore-adapt-STM32Cube_FW-sources.patch | 351 +++ ...nd-adapt-STM32Cube_FW-sources-for-ST.patch | 2330 ----------------- ...imeout-when-waiting-for-the-cmd_resp.patch | 15 +- ...ort-for-customize-app_conf_default.h.patch | 38 +- ...004-fix-warning-outside-array-bounds.patch | 304 +++ 5 files changed, 681 insertions(+), 2357 deletions(-) create mode 100644 extras/STM32Cube_FW/0001-chore-adapt-STM32Cube_FW-sources.patch delete mode 100644 extras/STM32Cube_FW/0001-chore-clean-up-and-adapt-STM32Cube_FW-sources-for-ST.patch create mode 100644 extras/STM32Cube_FW/0004-fix-warning-outside-array-bounds.patch diff --git a/extras/STM32Cube_FW/0001-chore-adapt-STM32Cube_FW-sources.patch b/extras/STM32Cube_FW/0001-chore-adapt-STM32Cube_FW-sources.patch new file mode 100644 index 00000000..246a1257 --- /dev/null +++ b/extras/STM32Cube_FW/0001-chore-adapt-STM32Cube_FW-sources.patch @@ -0,0 +1,351 @@ +From ef2495f6fa746df9f86f0db39fa00244d22feb3b Mon Sep 17 00:00:00 2001 +From: Frederic Pillon <frederic.pillon@st.com> +Date: Wed, 5 Apr 2023 10:18:52 +0200 +Subject: [PATCH 1/4] chore: adapt STM32Cube_FW sources + +Compare to previous patch, do the minimum changes required +to ease further update. + +Signed-off-by: Frederic Pillon <frederic.pillon@st.com> +--- + src/utility/STM32Cube_FW/app_conf_default.h | 47 +++++++++++++++------ + src/utility/STM32Cube_FW/ble_bufsize.h | 11 ++++- + src/utility/STM32Cube_FW/hw.h | 15 +++++-- + src/utility/STM32Cube_FW/hw_ipcc.c | 4 +- + src/utility/STM32Cube_FW/shci.c | 3 +- + src/utility/STM32Cube_FW/shci_tl.c | 18 +++++++- + src/utility/STM32Cube_FW/stm_list.c | 7 ++- + src/utility/STM32Cube_FW/tl_mbox.c | 8 +++- + 8 files changed, 90 insertions(+), 23 deletions(-) + +diff --git a/src/utility/STM32Cube_FW/app_conf_default.h b/src/utility/STM32Cube_FW/app_conf_default.h +index 51bd33a..e89df14 100644 +--- a/src/utility/STM32Cube_FW/app_conf_default.h ++++ b/src/utility/STM32Cube_FW/app_conf_default.h +@@ -1,9 +1,9 @@ + /* USER CODE BEGIN Header */ + /** + ****************************************************************************** +- * @file app_conf.h ++ * @file app_conf_default.h + * @author MCD Application Team +- * @brief Application configuration file for STM32WPAN Middleware. ++ * @brief Default application configuration file for STM32WPAN Middleware. + ****************************************************************************** + * @attention + * +@@ -19,18 +19,38 @@ + /* USER CODE END Header */ + + /* Define to prevent recursive inclusion -------------------------------------*/ +-#ifndef APP_CONF_H +-#define APP_CONF_H +- ++#ifndef APP_CONF_DEFAULT_H ++#define APP_CONF_DEFAULT_H ++#if 0 + #include "hw.h" + #include "hw_conf.h" + #include "hw_if.h" + #include "ble_bufsize.h" +- ++#endif + /****************************************************************************** + * Application Config + ******************************************************************************/ + ++/**< generic parameters ******************************************************/ ++/* HCI related defines */ ++ ++#define ACI_HAL_SET_TX_POWER_LEVEL 0xFC0F ++#define ACI_WRITE_CONFIG_DATA_OPCODE 0xFC0C ++#define ACI_READ_CONFIG_DATA_OPCODE 0xFC0D ++#define MAX_HCI_ACL_PACKET_SIZE (sizeof(TL_PacketHeader_t) + 5 + 251) ++#define HCI_RESET 0x0C03 ++ ++#ifndef BLE_SHARED_MEM_BYTE_ORDER ++ #define BLE_SHARED_MEM_BYTE_ORDER MSBFIRST ++#endif ++#define BLE_MODULE_SHARED_MEM_BUFFER_SIZE 128 ++ ++/** ++ * Define Tx Power ++ */ ++#define CFG_TX_POWER (0x18) /* -0.15dBm */ ++ ++#if 0 + /** + * Define Secure Connections Support + */ +@@ -104,7 +124,7 @@ + #define CFG_FW_SUBVERSION (1) + #define CFG_FW_BRANCH (0) + #define CFG_FW_BUILD (0) +- ++#endif + /****************************************************************************** + * BLE Stack + ******************************************************************************/ +@@ -152,13 +172,15 @@ + * Prepare Write List size in terms of number of packet + * This parameter is ignored by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set + */ +-#define CFG_BLE_PREPARE_WRITE_LIST_SIZE BLE_PREP_WRITE_X_ATT(CFG_BLE_MAX_ATT_MTU) ++// #define CFG_BLE_PREPARE_WRITE_LIST_SIZE BLE_PREP_WRITE_X_ATT(CFG_BLE_MAX_ATT_MTU) ++#define CFG_BLE_PREPARE_WRITE_LIST_SIZE (0x3A) + + /** + * Number of allocated memory blocks + * This parameter is overwritten by the CPU2 with an hardcoded optimal value when the parameter CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set + */ +-#define CFG_BLE_MBLOCK_COUNT (BLE_MBLOCKS_CALC(CFG_BLE_PREPARE_WRITE_LIST_SIZE, CFG_BLE_MAX_ATT_MTU, CFG_BLE_NUM_LINK)) ++//#define CFG_BLE_MBLOCK_COUNT (BLE_MBLOCKS_CALC(CFG_BLE_PREPARE_WRITE_LIST_SIZE, CFG_BLE_MAX_ATT_MTU, CFG_BLE_NUM_LINK)) ++#define CFG_BLE_MBLOCK_COUNT (0x79) + + /** + * Enable or disable the Extended Packet length feature. Valid values are 0 or 1. +@@ -250,7 +272,7 @@ + * 0: LE Power Class 2-3 + * other bits: complete with Options_extension flag + */ +-#define CFG_BLE_OPTIONS (SHCI_C2_BLE_INIT_OPTIONS_LL_HOST | SHCI_C2_BLE_INIT_OPTIONS_WITH_SVC_CHANGE_DESC | SHCI_C2_BLE_INIT_OPTIONS_DEVICE_NAME_RW | SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV | SHCI_C2_BLE_INIT_OPTIONS_CS_ALGO2 | SHCI_C2_BLE_INIT_OPTIONS_FULL_GATTDB_NVM | SHCI_C2_BLE_INIT_OPTIONS_GATT_CACHING_NOTUSED | SHCI_C2_BLE_INIT_OPTIONS_POWER_CLASS_2_3) ++#define CFG_BLE_OPTIONS (SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY) + + /** + * BLE stack Options_extension flags to be configured with: +@@ -323,6 +345,7 @@ + + #define CFG_BLE_CORE_VERSION (SHCI_C2_BLE_INIT_BLE_CORE_5_3) + ++#if 0 + /****************************************************************************** + * Transport Layer + ******************************************************************************/ +@@ -657,5 +680,5 @@ typedef enum + #define CFG_OTP_BASE_ADDRESS OTP_AREA_BASE + + #define CFG_OTP_END_ADRESS OTP_AREA_END_ADDR +- +-#endif /*APP_CONF_H */ ++#endif ++#endif /*APP_CONF_DEFAULT_H */ +diff --git a/src/utility/STM32Cube_FW/ble_bufsize.h b/src/utility/STM32Cube_FW/ble_bufsize.h +index 7b7c170..53cf59a 100644 +--- a/src/utility/STM32Cube_FW/ble_bufsize.h ++++ b/src/utility/STM32Cube_FW/ble_bufsize.h +@@ -75,15 +75,22 @@ + ((pw) + MAX(BLE_MEM_BLOCK_X_MTU(mtu, n_link), \ + BLE_MBLOCKS_SECURE_CONNECTIONS)) + ++/* ++ * BLE_DEFAULT_MBLOCKS_COUNT: default memory blocks count ++ */ ++#define BLE_DEFAULT_MBLOCKS_COUNT(n_link) \ ++ BLE_MBLOCKS_CALC(BLE_DEFAULT_PREP_WRITE_LIST_SIZE, \ ++ BLE_DEFAULT_MAX_ATT_MTU, n_link) ++ + /* + * BLE_FIXED_BUFFER_SIZE_BYTES: + * A part of the RAM, is dynamically allocated by initializing all the pointers + * defined in a global context variable "mem_alloc_ctx_p". +- * This initialization is made in the Dynamic_allocator functions, which ++ * This initialization is made in the Dynamic_allocator functions, which + * assign a portion of RAM given by the external application to the above + * mentioned "global pointers". + * +- * The size of this Dynamic RAM is made of 2 main components: ++ * The size of this Dynamic RAM is made of 2 main components: + * - a part that is parameters-dependent (num of links, GATT buffers, ...), + * and which value is made explicit by the following macro; + * - a part, that may be considered "fixed", i.e. independent from the above +diff --git a/src/utility/STM32Cube_FW/hw.h b/src/utility/STM32Cube_FW/hw.h +index 503fa2c..1472a5e 100644 +--- a/src/utility/STM32Cube_FW/hw.h ++++ b/src/utility/STM32Cube_FW/hw.h +@@ -26,14 +26,23 @@ extern "C" { + #endif + + /* Includes ------------------------------------------------------------------*/ ++#include "stm32_def.h" ++#include "stm32wbxx_ll_bus.h" ++#include "stm32wbxx_ll_exti.h" ++#include "stm32wbxx_ll_system.h" ++#include "stm32wbxx_ll_rcc.h" ++#include "stm32wbxx_ll_ipcc.h" ++#include "stm32wbxx_ll_cortex.h" ++#include "stm32wbxx_ll_utils.h" ++#include "stm32wbxx_ll_pwr.h" + + /****************************************************************************** + * HW IPCC + ******************************************************************************/ + void HW_IPCC_Enable( void ); + void HW_IPCC_Init( void ); +- void HW_IPCC_Rx_Handler( void ); +- void HW_IPCC_Tx_Handler( void ); ++#define HW_IPCC_Rx_Handler IPCC_C1_RX_IRQHandler ++#define HW_IPCC_Tx_Handler IPCC_C1_TX_IRQHandler + + void HW_IPCC_BLE_Init( void ); + void HW_IPCC_BLE_SendCmd( void ); +@@ -76,7 +85,7 @@ extern "C" { + void HW_IPCC_BLE_LLD_ReceiveRsp( void ); + void HW_IPCC_BLE_LLD_SendRspAck( void ); + +- ++ + void HW_IPCC_TRACES_Init( void ); + void HW_IPCC_TRACES_EvtNot( void ); + +diff --git a/src/utility/STM32Cube_FW/hw_ipcc.c b/src/utility/STM32Cube_FW/hw_ipcc.c +index fd620b8..3461cbe 100644 +--- a/src/utility/STM32Cube_FW/hw_ipcc.c ++++ b/src/utility/STM32Cube_FW/hw_ipcc.c +@@ -18,8 +18,9 @@ + */ + /* USER CODE END Header */ + ++#if defined(STM32WBxx) + /* Includes ------------------------------------------------------------------*/ +-#include "app_common.h" ++#include "hw.h" + #include "mbox_def.h" + + /* Global variables ---------------------------------------------------------*/ +@@ -667,3 +668,4 @@ static void HW_IPCC_TRACES_EvtHandler( void ) + } + + __weak void HW_IPCC_TRACES_EvtNot( void ){}; ++#endif /* STM32WBxx */ +diff --git a/src/utility/STM32Cube_FW/shci.c b/src/utility/STM32Cube_FW/shci.c +index 301db76..cb7d7bd 100644 +--- a/src/utility/STM32Cube_FW/shci.c ++++ b/src/utility/STM32Cube_FW/shci.c +@@ -16,7 +16,7 @@ + ****************************************************************************** + */ + +- ++#if defined(STM32WBxx) + /* Includes ------------------------------------------------------------------*/ + #include "stm32_wpan_common.h" + +@@ -739,3 +739,4 @@ SHCI_CmdStatus_t SHCI_GetWirelessFwInfo( WirelessFwInfo_t* pWirelessInfo ) + + return (SHCI_Success); + } ++#endif /* STM32WBxx */ +diff --git a/src/utility/STM32Cube_FW/shci_tl.c b/src/utility/STM32Cube_FW/shci_tl.c +index 2b387b1..a336aa6 100644 +--- a/src/utility/STM32Cube_FW/shci_tl.c ++++ b/src/utility/STM32Cube_FW/shci_tl.c +@@ -16,12 +16,13 @@ + ****************************************************************************** + */ + +- ++#if defined(STM32WBxx) + /* Includes ------------------------------------------------------------------*/ + #include "stm32_wpan_common.h" + + #include "stm_list.h" + #include "shci_tl.h" ++#include "stm32_def.h" + + /* Private typedef -----------------------------------------------------------*/ + typedef enum +@@ -168,6 +169,20 @@ void shci_send( uint16_t cmd_code, uint8_t len_cmd_payload, uint8_t * p_cmd_payl + return; + } + ++void shci_notify_asynch_evt(void *pdata) ++{ ++ UNUSED(pdata); ++ /* Need to parse data in future version */ ++ shci_user_evt_proc(); ++} ++ ++void shci_register_io_bus(tSHciIO *fops) ++{ ++ /* Register IO bus services */ ++ fops->Init = TL_SYS_Init; ++ fops->Send = TL_SYS_SendCmd; ++} ++ + /* Private functions ---------------------------------------------------------*/ + static void TlInit( TL_CmdPacket_t * p_cmdbuffer ) + { +@@ -251,3 +266,4 @@ __WEAK void shci_cmd_resp_release(uint32_t flag) + + return; + } ++#endif /* STM32WBxx */ +diff --git a/src/utility/STM32Cube_FW/stm_list.c b/src/utility/STM32Cube_FW/stm_list.c +index 4c92864..4e8c364 100644 +--- a/src/utility/STM32Cube_FW/stm_list.c ++++ b/src/utility/STM32Cube_FW/stm_list.c +@@ -16,11 +16,13 @@ + ****************************************************************************** + */ + +- ++#if defined(STM32WBxx) + /****************************************************************************** + * Include Files + ******************************************************************************/ +-#include "utilities_common.h" ++#include "stdint.h" ++#include "cmsis_gcc.h" ++#include "stm32_wpan_common.h" + + #include "stm_list.h" + +@@ -204,3 +206,4 @@ void LST_get_prev_node (tListNode * ref_node, tListNode ** node) + + __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ + } ++#endif /* STM32WBxx */ +diff --git a/src/utility/STM32Cube_FW/tl_mbox.c b/src/utility/STM32Cube_FW/tl_mbox.c +index 27a998a..ff219b9 100644 +--- a/src/utility/STM32Cube_FW/tl_mbox.c ++++ b/src/utility/STM32Cube_FW/tl_mbox.c +@@ -16,6 +16,7 @@ + ****************************************************************************** + */ + ++#if defined(STM32WBxx) + /* Includes ------------------------------------------------------------------*/ + #include "stm32_wpan_common.h" + #include "hw.h" +@@ -51,9 +52,10 @@ PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_BleLldTable_t TL_BleLldTable; + PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_SysTable_t TL_SysTable; + PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_MemManagerTable_t TL_MemManagerTable; + PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_TracesTable_t TL_TracesTable; ++#if 0 + PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_Mac_802_15_4_t TL_Mac_802_15_4_Table; + PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_ZigbeeTable_t TL_Zigbee_Table; +- ++#endif + /**< tables */ + PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode FreeBufQueue; + PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode TracesEvtQueue; +@@ -97,8 +99,11 @@ void TL_Init( void ) + TL_RefTable.p_sys_table = &TL_SysTable; + TL_RefTable.p_mem_manager_table = &TL_MemManagerTable; + TL_RefTable.p_traces_table = &TL_TracesTable; ++ ++#if 0 + TL_RefTable.p_mac_802_15_4_table = &TL_Mac_802_15_4_Table; + TL_RefTable.p_zigbee_table = &TL_Zigbee_Table; ++#endif + HW_IPCC_Init(); + + return; +@@ -846,3 +851,4 @@ static void OutputDbgTrace(TL_MB_PacketType_t packet_type, uint8_t* buffer) + + return; + } ++#endif /* STM32WBxx */ +-- +2.38.0.windows.1 + diff --git a/extras/STM32Cube_FW/0001-chore-clean-up-and-adapt-STM32Cube_FW-sources-for-ST.patch b/extras/STM32Cube_FW/0001-chore-clean-up-and-adapt-STM32Cube_FW-sources-for-ST.patch deleted file mode 100644 index 171554eb..00000000 --- a/extras/STM32Cube_FW/0001-chore-clean-up-and-adapt-STM32Cube_FW-sources-for-ST.patch +++ /dev/null @@ -1,2330 +0,0 @@ -From 70812b4e3a184585354f979472a75a648266f53f Mon Sep 17 00:00:00 2001 -From: Frederic Pillon <frederic.pillon@st.com> -Date: Mon, 12 Dec 2022 17:15:26 +0100 -Subject: [PATCH 1/3] chore: clean up and adapt STM32Cube_FW sources for - STM32duino - -Signed-off-by: Frederic Pillon <frederic.pillon@st.com> ---- - src/utility/STM32Cube_FW/app_conf_default.h | 914 ++++++------------- - src/utility/STM32Cube_FW/ble_bufsize.h | 7 + - src/utility/STM32Cube_FW/hw.h | 28 +- - src/utility/STM32Cube_FW/hw_ipcc.c | 218 +---- - src/utility/STM32Cube_FW/mbox_def.h | 34 - - src/utility/STM32Cube_FW/shci.c | 39 +- - src/utility/STM32Cube_FW/shci.h | 51 +- - src/utility/STM32Cube_FW/shci_tl.c | 37 +- - src/utility/STM32Cube_FW/stm32_wpan_common.h | 39 +- - src/utility/STM32Cube_FW/stm_list.c | 15 +- - src/utility/STM32Cube_FW/stm_list.h | 4 +- - src/utility/STM32Cube_FW/tl.h | 33 - - src/utility/STM32Cube_FW/tl_mbox.c | 143 +-- - 13 files changed, 323 insertions(+), 1239 deletions(-) - rewrite src/utility/STM32Cube_FW/app_conf_default.h (63%) - -diff --git a/src/utility/STM32Cube_FW/app_conf_default.h b/src/utility/STM32Cube_FW/app_conf_default.h -dissimilarity index 63% -index 2606a05..cc8c3e8 100644 ---- a/src/utility/STM32Cube_FW/app_conf_default.h -+++ b/src/utility/STM32Cube_FW/app_conf_default.h -@@ -1,655 +1,259 @@ --/* USER CODE BEGIN Header */ --/** -- ****************************************************************************** -- * @file app_conf.h -- * @author MCD Application Team -- * @brief Application configuration file for STM32WPAN Middleware. -- ****************************************************************************** -- * @attention -- * -- * Copyright (c) 2020-2021 STMicroelectronics. -- * All rights reserved. -- * -- * This software is licensed under terms that can be found in the LICENSE file -- * in the root directory of this software component. -- * If no LICENSE file comes with this software, it is provided AS-IS. -- * -- ****************************************************************************** -- */ --/* USER CODE END Header */ -- --/* Define to prevent recursive inclusion -------------------------------------*/ --#ifndef APP_CONF_H --#define APP_CONF_H -- --#include "hw.h" --#include "hw_conf.h" --#include "hw_if.h" --#include "ble_bufsize.h" -- --/****************************************************************************** -- * Application Config -- ******************************************************************************/ -- --/** -- * Define Secure Connections Support -- */ --#define CFG_SECURE_NOT_SUPPORTED (0x00) --#define CFG_SECURE_OPTIONAL (0x01) --#define CFG_SECURE_MANDATORY (0x02) -- --#define CFG_SC_SUPPORT CFG_SECURE_OPTIONAL -- --/** -- * Define Keypress Notification Support -- */ --#define CFG_KEYPRESS_NOT_SUPPORTED (0x00) --#define CFG_KEYPRESS_SUPPORTED (0x01) -- --#define CFG_KEYPRESS_NOTIFICATION_SUPPORT CFG_KEYPRESS_NOT_SUPPORTED -- --/** -- * Numeric Comparison Answers -- */ --#define YES (0x01) --#define NO (0x00) -- --/** -- * Device name configuration for Generic Access Service -- */ --#define CFG_GAP_DEVICE_NAME "TEMPLATE" --#define CFG_GAP_DEVICE_NAME_LENGTH (8) -- --/** --* Identity root key used to derive LTK and CSRK --*/ --#define CFG_BLE_IRK {0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0} -- --/** --* Encryption root key used to derive LTK and CSRK --*/ --#define CFG_BLE_ERK {0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21, 0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21} -- --/** -- * SMPS supply -- * SMPS not used when Set to 0 -- * SMPS used when Set to 1 -- */ --#define CFG_USE_SMPS 0 -- --/* USER CODE BEGIN Generic_Parameters */ --/* USER CODE END Generic_Parameters */ -- --/**< specific parameters */ --/*****************************************************/ -- --/* USER CODE BEGIN Specific_Parameters */ --#define PUSH_BUTTON_SW1_EXTI_IRQHandler EXTI4_IRQHandler -- --/* USER CODE END Specific_Parameters */ -- --/****************************************************************************** -- * Information Table -- * -- * Version -- * [0:3] = Build - 0: Untracked - 15:Released - x: Tracked version -- * [4:7] = branch - 0: Mass Market - x: ... -- * [8:15] = Subversion -- * [16:23] = Version minor -- * [24:31] = Version major -- * -- ******************************************************************************/ --#define CFG_FW_MAJOR_VERSION (0) --#define CFG_FW_MINOR_VERSION (0) --#define CFG_FW_SUBVERSION (1) --#define CFG_FW_BRANCH (0) --#define CFG_FW_BUILD (0) -- --/****************************************************************************** -- * BLE Stack -- ******************************************************************************/ --/** -- * Maximum number of simultaneous connections that the device will support. -- * Valid values are from 1 to 8 -- */ --#define CFG_BLE_NUM_LINK 8 -- --/** -- * Maximum number of Services that can be stored in the GATT database. -- * Note that the GAP and GATT services are automatically added so this parameter should be 2 plus the number of user services -- */ --#define CFG_BLE_NUM_GATT_SERVICES 8 -- --/** -- * Maximum number of Attributes -- * (i.e. the number of characteristic + the number of characteristic values + the number of descriptors, excluding the services) -- * that can be stored in the GATT database. -- * Note that certain characteristics and relative descriptors are added automatically during device initialization -- * so this parameters should be 9 plus the number of user Attributes -- */ --#define CFG_BLE_NUM_GATT_ATTRIBUTES 68 -- --/** -- * Maximum supported ATT_MTU size -- * This parameter is ignored by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set -- */ --#define CFG_BLE_MAX_ATT_MTU (156) -- --/** -- * Size of the storage area for Attribute values -- * This value depends on the number of attributes used by application. In particular the sum of the following quantities (in octets) should be made for each attribute: -- * - attribute value length -- * - 5, if UUID is 16 bit; 19, if UUID is 128 bit -- * - 2, if server configuration descriptor is used -- * - 2*DTM_NUM_LINK, if client configuration descriptor is used -- * - 2, if extended properties is used -- * The total amount of memory needed is the sum of the above quantities for each attribute. -- * This parameter is ignored by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set -- */ --#define CFG_BLE_ATT_VALUE_ARRAY_SIZE (1344) -- --/** -- * Prepare Write List size in terms of number of packet -- * This parameter is ignored by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set -- */ --#define CFG_BLE_PREPARE_WRITE_LIST_SIZE BLE_PREP_WRITE_X_ATT(CFG_BLE_MAX_ATT_MTU) -- --/** -- * Number of allocated memory blocks -- * This parameter is overwritten by the CPU2 with an hardcoded optimal value when the parameter CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set -- */ --#define CFG_BLE_MBLOCK_COUNT (BLE_MBLOCKS_CALC(CFG_BLE_PREPARE_WRITE_LIST_SIZE, CFG_BLE_MAX_ATT_MTU, CFG_BLE_NUM_LINK)) -- --/** -- * Enable or disable the Extended Packet length feature. Valid values are 0 or 1. -- */ --#define CFG_BLE_DATA_LENGTH_EXTENSION 1 -- --/** -- * Sleep clock accuracy in Slave mode (ppm value) -- */ --#define CFG_BLE_SLAVE_SCA 500 -- --/** -- * Sleep clock accuracy in Master mode -- * 0 : 251 ppm to 500 ppm -- * 1 : 151 ppm to 250 ppm -- * 2 : 101 ppm to 150 ppm -- * 3 : 76 ppm to 100 ppm -- * 4 : 51 ppm to 75 ppm -- * 5 : 31 ppm to 50 ppm -- * 6 : 21 ppm to 30 ppm -- * 7 : 0 ppm to 20 ppm -- */ --#define CFG_BLE_MASTER_SCA 0 -- --/** -- * LsSource -- * Some information for Low speed clock mapped in bits field -- * - bit 0: 1: Calibration for the RF system wakeup clock source 0: No calibration for the RF system wakeup clock source -- * - bit 1: 1: STM32WB5M Module device 0: Other devices as STM32WBxx SOC, STM32WB1M module -- * - bit 2: 1: HSE/1024 Clock config 0: LSE Clock config -- */ --#if defined(STM32WB5Mxx) -- #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_MOD5MM_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) --#else -- #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_OTHER_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) --#endif -- --/** -- * Start up time of the high speed (16 or 32 MHz) crystal oscillator in units of 625/256 us (~2.44 us) -- */ --#define CFG_BLE_HSE_STARTUP_TIME 0x148 -- --/** -- * Maximum duration of the connection event when the device is in Slave mode in units of 625/256 us (~2.44 us) -- */ --#define CFG_BLE_MAX_CONN_EVENT_LENGTH (0xFFFFFFFF) -- --/** -- * Viterbi Mode -- * 1 : enabled -- * 0 : disabled -- */ --#define CFG_BLE_VITERBI_MODE 1 -- --/** -- * BLE stack Options flags to be configured with: -- * - SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY -- * - SHCI_C2_BLE_INIT_OPTIONS_LL_HOST -- * - SHCI_C2_BLE_INIT_OPTIONS_NO_SVC_CHANGE_DESC -- * - SHCI_C2_BLE_INIT_OPTIONS_WITH_SVC_CHANGE_DESC -- * - SHCI_C2_BLE_INIT_OPTIONS_DEVICE_NAME_RO -- * - SHCI_C2_BLE_INIT_OPTIONS_DEVICE_NAME_RW -- * - SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV -- * - SHCI_C2_BLE_INIT_OPTIONS_NO_EXT_ADV -- * - SHCI_C2_BLE_INIT_OPTIONS_CS_ALGO2 -- * - SHCI_C2_BLE_INIT_OPTIONS_NO_CS_ALGO2 -- * - SHCI_C2_BLE_INIT_OPTIONS_REDUC_GATTDB_NVM -- * - SHCI_C2_BLE_INIT_OPTIONS_FULL_GATTDB_NVM -- * - SHCI_C2_BLE_INIT_OPTIONS_GATT_CACHING_USED -- * - SHCI_C2_BLE_INIT_OPTIONS_GATT_CACHING_NOTUSED -- * - SHCI_C2_BLE_INIT_OPTIONS_POWER_CLASS_1 -- * - SHCI_C2_BLE_INIT_OPTIONS_POWER_CLASS_2_3 -- * - SHCI_C2_BLE_INIT_OPTIONS_APPEARANCE_WRITABLE -- * - SHCI_C2_BLE_INIT_OPTIONS_APPEARANCE_READONLY -- * - SHCI_C2_BLE_INIT_OPTIONS_ENHANCED_ATT_SUPPORTED -- * - SHCI_C2_BLE_INIT_OPTIONS_ENHANCED_ATT_NOTSUPPORTED -- * which are used to set following configuration bits: -- * (bit 0): 1: LL only -- * 0: LL + host -- * (bit 1): 1: no service change desc. -- * 0: with service change desc. -- * (bit 2): 1: device name Read-Only -- * 0: device name R/W -- * (bit 3): 1: extended advertizing supported -- * 0: extended advertizing not supported -- * (bit 4): 1: CS Algo #2 supported -- * 0: CS Algo #2 not supported -- * (bit 5): 1: Reduced GATT database in NVM -- * 0: Full GATT database in NVM -- * (bit 6): 1: GATT caching is used -- * 0: GATT caching is not used -- * (bit 7): 1: LE Power Class 1 -- * 0: LE Power Class 2-3 -- * (bit 8): 1: appearance Writable -- * 0: appearance Read-Only -- * (bit 9): 1: Enhanced ATT supported -- * 0: Enhanced ATT not supported -- * other bits: reserved (shall be set to 0) -- */ --#define CFG_BLE_OPTIONS (SHCI_C2_BLE_INIT_OPTIONS_LL_HOST | SHCI_C2_BLE_INIT_OPTIONS_WITH_SVC_CHANGE_DESC | SHCI_C2_BLE_INIT_OPTIONS_DEVICE_NAME_RW | SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV | SHCI_C2_BLE_INIT_OPTIONS_CS_ALGO2 | SHCI_C2_BLE_INIT_OPTIONS_FULL_GATTDB_NVM | SHCI_C2_BLE_INIT_OPTIONS_GATT_CACHING_NOTUSED | SHCI_C2_BLE_INIT_OPTIONS_POWER_CLASS_2_3 | SHCI_C2_BLE_INIT_OPTIONS_APPEARANCE_READONLY | SHCI_C2_BLE_INIT_OPTIONS_ENHANCED_ATT_NOTSUPPORTED) -- --#define CFG_BLE_MAX_COC_INITIATOR_NBR (32) -- --#define CFG_BLE_MIN_TX_POWER (-40) -- --#define CFG_BLE_MAX_TX_POWER (6) -- --/** -- * BLE Rx model configuration flags to be configured with: -- * - SHCI_C2_BLE_INIT_RX_MODEL_AGC_RSSI_LEGACY -- * - SHCI_C2_BLE_INIT_RX_MODEL_AGC_RSSI_BLOCKER -- * which are used to set following configuration bits: -- * (bit 0): 1: agc_rssi model improved vs RF blockers -- * 0: Legacy agc_rssi model -- * other bits: reserved (shall be set to 0) -- */ -- --#define CFG_BLE_RX_MODEL_CONFIG (SHCI_C2_BLE_INIT_RX_MODEL_AGC_RSSI_LEGACY) -- --/* Maximum number of advertising sets. -- * Range: 1 .. 8 with limitation: -- * This parameter is linked to CFG_BLE_MAX_ADV_DATA_LEN such as both compliant with allocated Total memory computed with BLE_EXT_ADV_BUFFER_SIZE based -- * on Max Extended advertising configuration supported. -- * This parameter is considered by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV flag set -- */ -- --#define CFG_BLE_MAX_ADV_SET_NBR (8) -- -- /* Maximum advertising data length (in bytes) -- * Range: 31 .. 1650 with limitation: -- * This parameter is linked to CFG_BLE_MAX_ADV_SET_NBR such as both compliant with allocated Total memory computed with BLE_EXT_ADV_BUFFER_SIZE based -- * on Max Extended advertising configuration supported. -- * This parameter is considered by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV flag set -- */ -- --#define CFG_BLE_MAX_ADV_DATA_LEN (207) -- -- /* RF TX Path Compensation Value (16-bit signed integer). Units: 0.1 dB. -- * Range: -1280 .. 1280 -- */ -- --#define CFG_BLE_TX_PATH_COMPENS (0) -- -- /* RF RX Path Compensation Value (16-bit signed integer). Units: 0.1 dB. -- * Range: -1280 .. 1280 -- */ -- --#define CFG_BLE_RX_PATH_COMPENS (0) -- -- /* BLE core version (16-bit signed integer). -- * - SHCI_C2_BLE_INIT_BLE_CORE_5_2 -- * - SHCI_C2_BLE_INIT_BLE_CORE_5_3 -- * which are used to set: 11(5.2), 12(5.3). -- */ -- --#define CFG_BLE_CORE_VERSION (SHCI_C2_BLE_INIT_BLE_CORE_5_3) -- --/****************************************************************************** -- * Transport Layer -- ******************************************************************************/ --/** -- * Queue length of BLE Event -- * This parameter defines the number of asynchronous events that can be stored in the HCI layer before -- * being reported to the application. When a command is sent to the BLE core coprocessor, the HCI layer -- * is waiting for the event with the Num_HCI_Command_Packets set to 1. The receive queue shall be large -- * enough to store all asynchronous events received in between. -- * When CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE is set to 27, this allow to store three 255 bytes long asynchronous events -- * between the HCI command and its event. -- * This parameter depends on the value given to CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE. When the queue size is to small, -- * the system may hang if the queue is full with asynchronous events and the HCI layer is still waiting -- * for a CC/CS event, In that case, the notification TL_BLE_HCI_ToNot() is called to indicate -- * to the application a HCI command did not receive its command event within 30s (Default HCI Timeout). -- */ --#define CFG_TLBLE_EVT_QUEUE_LENGTH 5 --/** -- * This parameter should be set to fit most events received by the HCI layer. It defines the buffer size of each element -- * allocated in the queue of received events and can be used to optimize the amount of RAM allocated by the Memory Manager. -- * It should not exceed 255 which is the maximum HCI packet payload size (a greater value is a lost of memory as it will -- * never be used) -- * It shall be at least 4 to receive the command status event in one frame. -- * The default value is set to 27 to allow receiving an event of MTU size in a single buffer. This value maybe reduced -- * further depending on the application. -- */ --#define CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE 255 /**< Set to 255 with the memory manager and the mailbox */ -- --#define TL_BLE_EVENT_FRAME_SIZE ( TL_EVT_HDR_SIZE + CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE ) --/****************************************************************************** -- * UART interfaces -- ******************************************************************************/ -- --/** -- * Select UART interfaces -- */ --#define CFG_UART_GUI hw_uart1 --#define CFG_DEBUG_TRACE_UART 0 --/****************************************************************************** -- * USB interface -- ******************************************************************************/ -- --/** -- * Enable/Disable USB interface -- */ --#define CFG_USB_INTERFACE_ENABLE 0 -- --/****************************************************************************** -- * IPCC interface -- ******************************************************************************/ -- --/** -- * The IPCC is dedicated to the communication between the CPU2 and the CPU1 -- * and shall not be modified by the application -- * The two following definitions shall not be modified -- */ --#define HAL_IPCC_TX_IRQHandler(...) HW_IPCC_Tx_Handler( ) --#define HAL_IPCC_RX_IRQHandler(...) HW_IPCC_Rx_Handler( ) -- --/****************************************************************************** -- * Low Power -- ******************************************************************************/ --/** -- * When set to 1, the low power mode is enable -- * When set to 0, the device stays in RUN mode -- */ --#define CFG_LPM_SUPPORTED 1 -- --/****************************************************************************** -- * RTC interface -- ******************************************************************************/ --#define HAL_RTCEx_WakeUpTimerIRQHandler(...) HW_TS_RTC_Wakeup_Handler( ) -- --/****************************************************************************** -- * Timer Server -- ******************************************************************************/ --/** -- * CFG_RTC_WUCKSEL_DIVIDER: This sets the RTCCLK divider to the wakeup timer. -- * The lower is the value, the better is the power consumption and the accuracy of the timerserver -- * The higher is the value, the finest is the granularity -- * -- * CFG_RTC_ASYNCH_PRESCALER: This sets the asynchronous prescaler of the RTC. It should as high as possible ( to output -- * clock as low as possible) but the output clock should be equal or higher frequency compare to the clock feeding -- * the wakeup timer. A lower clock speed would impact the accuracy of the timer server. -- * -- * CFG_RTC_SYNCH_PRESCALER: This sets the synchronous prescaler of the RTC. -- * When the 1Hz calendar clock is required, it shall be sets according to other settings -- * When the 1Hz calendar clock is not needed, CFG_RTC_SYNCH_PRESCALER should be set to 0x7FFF (MAX VALUE) -- * -- * CFG_RTCCLK_DIVIDER_CONF: -- * Shall be set to either 0,2,4,8,16 -- * When set to either 2,4,8,16, the 1Hhz calendar is supported -- * When set to 0, the user sets its own configuration -- * -- * The following settings are computed with LSI as input to the RTC -- */ -- --#define CFG_RTCCLK_DIVIDER_CONF 0 -- --#if (CFG_RTCCLK_DIVIDER_CONF == 0) --/** -- * Custom configuration -- * It does not support 1Hz calendar -- * It divides the RTC CLK by 16 -- */ -- --#define CFG_RTCCLK_DIV (16) --#define CFG_RTC_WUCKSEL_DIVIDER (0) --#define CFG_RTC_ASYNCH_PRESCALER (0x0F) --#define CFG_RTC_SYNCH_PRESCALER (0x7FFF) -- --#else -- --#if (CFG_RTCCLK_DIVIDER_CONF == 2) --/** -- * It divides the RTC CLK by 2 -- */ --#define CFG_RTC_WUCKSEL_DIVIDER (3) --#endif -- --#if (CFG_RTCCLK_DIVIDER_CONF == 4) --/** -- * It divides the RTC CLK by 4 -- */ --#define CFG_RTC_WUCKSEL_DIVIDER (2) --#endif -- --#if (CFG_RTCCLK_DIVIDER_CONF == 8) --/** -- * It divides the RTC CLK by 8 -- */ --#define CFG_RTC_WUCKSEL_DIVIDER (1) --#endif -- --#if (CFG_RTCCLK_DIVIDER_CONF == 16) --/** -- * It divides the RTC CLK by 16 -- */ --#define CFG_RTC_WUCKSEL_DIVIDER (0) --#endif -- --#define CFG_RTCCLK_DIV CFG_RTCCLK_DIVIDER_CONF --#define CFG_RTC_ASYNCH_PRESCALER (CFG_RTCCLK_DIV - 1) --#define CFG_RTC_SYNCH_PRESCALER (DIVR( LSE_VALUE, (CFG_RTC_ASYNCH_PRESCALER+1) ) - 1 ) -- --#endif -- --/** tick timer values */ --#define CFG_TS_TICK_VAL DIVR( (CFG_RTCCLK_DIV * 1000000), LSE_VALUE ) --#define CFG_TS_TICK_VAL_PS DIVR( ((uint64_t)CFG_RTCCLK_DIV * 1e12), (uint64_t)LSE_VALUE ) -- --typedef enum --{ -- CFG_TIM_PROC_ID_ISR, -- /* USER CODE BEGIN CFG_TimProcID_t */ -- -- /* USER CODE END CFG_TimProcID_t */ --} CFG_TimProcID_t; -- --/****************************************************************************** -- * Debug -- ******************************************************************************/ --/** -- * When set, this resets some hw resources to set the device in the same state than the power up -- * The FW resets only register that may prevent the FW to run properly -- * -- * This shall be set to 0 in a final product -- * -- */ --#define CFG_HW_RESET_BY_FW 1 -- --/** -- * keep debugger enabled while in any low power mode when set to 1 -- * should be set to 0 in production -- */ --#define CFG_DEBUGGER_SUPPORTED 0 -- --/** -- * When set to 1, the traces are enabled in the BLE services -- */ --#define CFG_DEBUG_BLE_TRACE 0 -- --/** -- * Enable or Disable traces in application -- */ --#define CFG_DEBUG_APP_TRACE 0 -- --#if (CFG_DEBUG_APP_TRACE != 0) --#define APP_DBG_MSG PRINT_MESG_DBG --#else --#define APP_DBG_MSG PRINT_NO_MESG --#endif -- --#if ( (CFG_DEBUG_BLE_TRACE != 0) || (CFG_DEBUG_APP_TRACE != 0) ) --#define CFG_DEBUG_TRACE 1 --#endif -- --#if (CFG_DEBUG_TRACE != 0) --#undef CFG_LPM_SUPPORTED --#undef CFG_DEBUGGER_SUPPORTED --#define CFG_LPM_SUPPORTED 0 --#define CFG_DEBUGGER_SUPPORTED 1 --#endif -- --/** -- * When CFG_DEBUG_TRACE_FULL is set to 1, the trace are output with the API name, the file name and the line number -- * When CFG_DEBUG_TRACE_LIGHT is set to 1, only the debug message is output -- * -- * When both are set to 0, no trace are output -- * When both are set to 1, CFG_DEBUG_TRACE_FULL is selected -- */ --#define CFG_DEBUG_TRACE_LIGHT 0 --#define CFG_DEBUG_TRACE_FULL 0 -- --#if (( CFG_DEBUG_TRACE != 0 ) && ( CFG_DEBUG_TRACE_LIGHT == 0 ) && (CFG_DEBUG_TRACE_FULL == 0)) --#undef CFG_DEBUG_TRACE_FULL --#undef CFG_DEBUG_TRACE_LIGHT --#define CFG_DEBUG_TRACE_FULL 0 --#define CFG_DEBUG_TRACE_LIGHT 1 --#endif -- --#if ( CFG_DEBUG_TRACE == 0 ) --#undef CFG_DEBUG_TRACE_FULL --#undef CFG_DEBUG_TRACE_LIGHT --#define CFG_DEBUG_TRACE_FULL 0 --#define CFG_DEBUG_TRACE_LIGHT 0 --#endif -- --/** -- * When not set, the traces is looping on sending the trace over UART -- */ --#define DBG_TRACE_USE_CIRCULAR_QUEUE 1 -- --/** -- * max buffer Size to queue data traces and max data trace allowed. -- * Only Used if DBG_TRACE_USE_CIRCULAR_QUEUE is defined -- */ --#define DBG_TRACE_MSG_QUEUE_SIZE 4096 --#define MAX_DBG_TRACE_MSG_SIZE 1024 -- --/* USER CODE BEGIN Defines */ --#define CFG_LED_SUPPORTED 1 --#define CFG_BUTTON_SUPPORTED 1 -- --#define PUSH_BUTTON_SW1_EXTI_IRQHandler EXTI4_IRQHandler --#define PUSH_BUTTON_SW2_EXTI_IRQHandler EXTI0_IRQHandler --#define PUSH_BUTTON_SW3_EXTI_IRQHandler EXTI1_IRQHandler --/* USER CODE END Defines */ -- --/****************************************************************************** -- * Scheduler -- ******************************************************************************/ -- --/** -- * These are the lists of task id registered to the scheduler -- * Each task id shall be in the range [0:31] -- * This mechanism allows to implement a generic code in the API TL_BLE_HCI_StatusNot() to comply with -- * the requirement that a HCI/ACI command shall never be sent if there is already one pending -- */ -- --/**< Add in that list all tasks that may send a ACI/HCI command */ --typedef enum --{ -- CFG_TASK_BLE_HCI_CMD_ID, -- CFG_TASK_SYS_HCI_CMD_ID, -- CFG_TASK_HCI_ACL_DATA_ID, -- CFG_TASK_SYS_LOCAL_CMD_ID, -- CFG_TASK_TX_TO_HOST_ID, -- /* USER CODE BEGIN CFG_Task_Id_With_HCI_Cmd_t */ -- CFG_TASK_SW1_BUTTON_PUSHED_ID, -- CFG_TASK_SW2_BUTTON_PUSHED_ID, -- CFG_TASK_SW3_BUTTON_PUSHED_ID, -- /* USER CODE END CFG_Task_Id_With_HCI_Cmd_t */ -- CFG_LAST_TASK_ID_WITH_HCICMD, /**< Shall be LAST in the list */ --} CFG_Task_Id_With_HCI_Cmd_t; -- --/**< Add in that list all tasks that never send a ACI/HCI command */ --typedef enum --{ -- CFG_FIRST_TASK_ID_WITH_NO_HCICMD = CFG_LAST_TASK_ID_WITH_HCICMD - 1, /**< Shall be FIRST in the list */ -- CFG_TASK_SYSTEM_HCI_ASYNCH_EVT_ID, -- /* USER CODE BEGIN CFG_Task_Id_With_NO_HCI_Cmd_t */ -- -- /* USER CODE END CFG_Task_Id_With_NO_HCI_Cmd_t */ -- CFG_LAST_TASK_ID_WITH_NO_HCICMD /**< Shall be LAST in the list */ --} CFG_Task_Id_With_NO_HCI_Cmd_t; -- --#define CFG_TASK_NBR CFG_LAST_TASK_ID_WITH_NO_HCICMD -- --/** -- * This is the list of priority required by the application -- * Each Id shall be in the range 0..31 -- */ --typedef enum --{ -- CFG_SCH_PRIO_0, -- /* USER CODE BEGIN CFG_SCH_Prio_Id_t */ -- -- /* USER CODE END CFG_SCH_Prio_Id_t */ --} CFG_SCH_Prio_Id_t; -- --/** -- * This is a bit mapping over 32bits listing all events id supported in the application -- */ --typedef enum --{ -- CFG_IDLEEVT_SYSTEM_HCI_CMD_EVT_RSP_ID, -- /* USER CODE BEGIN CFG_IdleEvt_Id_t */ -- -- /* USER CODE END CFG_IdleEvt_Id_t */ --} CFG_IdleEvt_Id_t; -- --/****************************************************************************** -- * LOW POWER -- ******************************************************************************/ --/** -- * Supported requester to the MCU Low Power Manager - can be increased up to 32 -- * It list a bit mapping of all user of the Low Power Manager -- */ --typedef enum --{ -- CFG_LPM_APP, -- CFG_LPM_APP_BLE, -- /* USER CODE BEGIN CFG_LPM_Id_t */ -- -- /* USER CODE END CFG_LPM_Id_t */ --} CFG_LPM_Id_t; -- --/****************************************************************************** -- * OTP manager -- ******************************************************************************/ --#define CFG_OTP_BASE_ADDRESS OTP_AREA_BASE -- --#define CFG_OTP_END_ADRESS OTP_AREA_END_ADDR -- --#endif /*APP_CONF_H */ -- -+/** -+ ****************************************************************************** -+ * @file app_conf_default.h -+ * @author MCD Application Team -+ * @brief Default application configuration file for STM32WPAN Middleware. -+ ****************************************************************************** -+ * @attention -+ * -+ * Copyright (c) 2020-2021 STMicroelectronics. -+ * All rights reserved. -+ * -+ * This software is licensed under terms that can be found in the LICENSE file -+ * in the root directory of this software component. -+ * If no LICENSE file comes with this software, it is provided AS-IS. -+ * -+ ****************************************************************************** -+ */ -+ -+/* Define to prevent recursive inclusion -------------------------------------*/ -+#ifndef APP_CONF_DEFAULT_H -+#define APP_CONF_DEFAULT_H -+ -+/****************************************************************************** -+ * Application Config -+ ******************************************************************************/ -+ -+/**< generic parameters ******************************************************/ -+/* HCI related defines */ -+ -+#define ACI_HAL_SET_TX_POWER_LEVEL 0xFC0F -+#define ACI_WRITE_CONFIG_DATA_OPCODE 0xFC0C -+#define ACI_READ_CONFIG_DATA_OPCODE 0xFC0D -+#define MAX_HCI_ACL_PACKET_SIZE (sizeof(TL_PacketHeader_t) + 5 + 251) -+#define HCI_RESET 0x0C03 -+ -+#ifndef BLE_SHARED_MEM_BYTE_ORDER -+ #define BLE_SHARED_MEM_BYTE_ORDER MSBFIRST -+#endif -+#define BLE_MODULE_SHARED_MEM_BUFFER_SIZE 128 -+ -+/** -+ * Define Tx Power -+ */ -+#define CFG_TX_POWER (0x18) /* -0.15dBm */ -+ -+/****************************************************************************** -+ * BLE Stack -+ ******************************************************************************/ -+/** -+ * Maximum number of simultaneous connections that the device will support. -+ * Valid values are from 1 to 8 -+ */ -+#define CFG_BLE_NUM_LINK 8 -+ -+/** -+ * Maximum number of Services that can be stored in the GATT database. -+ * Note that the GAP and GATT services are automatically added so this parameter should be 2 plus the number of user services -+ */ -+#define CFG_BLE_NUM_GATT_SERVICES 8 -+ -+/** -+ * Maximum number of Attributes -+ * (i.e. the number of characteristic + the number of characteristic values + the number of descriptors, excluding the services) -+ * that can be stored in the GATT database. -+ * Note that certain characteristics and relative descriptors are added automatically during device initialization -+ * so this parameters should be 9 plus the number of user Attributes -+ */ -+#define CFG_BLE_NUM_GATT_ATTRIBUTES 68 -+ -+/** -+ * Maximum supported ATT_MTU size -+ * This parameter is ignored by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set -+ */ -+#define CFG_BLE_MAX_ATT_MTU (156) -+ -+/** -+ * Size of the storage area for Attribute values -+ * This value depends on the number of attributes used by application. In particular the sum of the following quantities (in octets) should be made for each attribute: -+ * - attribute value length -+ * - 5, if UUID is 16 bit; 19, if UUID is 128 bit -+ * - 2, if server configuration descriptor is used -+ * - 2*DTM_NUM_LINK, if client configuration descriptor is used -+ * - 2, if extended properties is used -+ * The total amount of memory needed is the sum of the above quantities for each attribute. -+ * This parameter is ignored by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set -+ */ -+#define CFG_BLE_ATT_VALUE_ARRAY_SIZE (1344) -+ -+/** -+ * Prepare Write List size in terms of number of packet -+ * This parameter is ignored by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set -+ */ -+// #define CFG_BLE_PREPARE_WRITE_LIST_SIZE BLE_PREP_WRITE_X_ATT(CFG_BLE_MAX_ATT_MTU) -+#define CFG_BLE_PREPARE_WRITE_LIST_SIZE (0x3A) -+ -+/** -+ * Number of allocated memory blocks -+ * This parameter is overwritten by the CPU2 with an hardcoded optimal value when the parameter CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set -+ */ -+// #define CFG_BLE_MBLOCK_COUNT (BLE_MBLOCKS_CALC(CFG_BLE_PREPARE_WRITE_LIST_SIZE, CFG_BLE_MAX_ATT_MTU, CFG_BLE_NUM_LINK)) -+#define CFG_BLE_MBLOCK_COUNT (0x79) -+ -+/** -+ * Enable or disable the Extended Packet length feature. Valid values are 0 or 1. -+ */ -+#define CFG_BLE_DATA_LENGTH_EXTENSION 1 -+ -+/** -+ * Sleep clock accuracy in Slave mode (ppm value) -+ */ -+#define CFG_BLE_SLAVE_SCA 500 -+ -+/** -+ * Sleep clock accuracy in Master mode -+ * 0 : 251 ppm to 500 ppm -+ * 1 : 151 ppm to 250 ppm -+ * 2 : 101 ppm to 150 ppm -+ * 3 : 76 ppm to 100 ppm -+ * 4 : 51 ppm to 75 ppm -+ * 5 : 31 ppm to 50 ppm -+ * 6 : 21 ppm to 30 ppm -+ * 7 : 0 ppm to 20 ppm -+ */ -+#define CFG_BLE_MASTER_SCA 0 -+ -+/** -+ * LsSource -+ * Some information for Low speed clock mapped in bits field -+ * - bit 0: 1: Calibration for the RF system wakeup clock source 0: No calibration for the RF system wakeup clock source -+ * - bit 1: 1: STM32WB5M Module device 0: Other devices as STM32WBxx SOC, STM32WB1M module -+ * - bit 2: 1: HSE/1024 Clock config 0: LSE Clock config -+ */ -+#if defined(STM32WB5Mxx) -+ #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_MOD5MM_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) -+#else -+ #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_OTHER_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) -+#endif -+ -+/** -+ * Start up time of the high speed (16 or 32 MHz) crystal oscillator in units of 625/256 us (~2.44 us) -+ */ -+#define CFG_BLE_HSE_STARTUP_TIME 0x148 -+ -+/** -+ * Maximum duration of the connection event when the device is in Slave mode in units of 625/256 us (~2.44 us) -+ */ -+#define CFG_BLE_MAX_CONN_EVENT_LENGTH (0xFFFFFFFF) -+ -+/** -+ * Viterbi Mode -+ * 1 : enabled -+ * 0 : disabled -+ */ -+#define CFG_BLE_VITERBI_MODE 1 -+ -+/** -+ * BLE stack Options flags to be configured with: -+ * - SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY -+ * - SHCI_C2_BLE_INIT_OPTIONS_LL_HOST -+ * - SHCI_C2_BLE_INIT_OPTIONS_NO_SVC_CHANGE_DESC -+ * - SHCI_C2_BLE_INIT_OPTIONS_WITH_SVC_CHANGE_DESC -+ * - SHCI_C2_BLE_INIT_OPTIONS_DEVICE_NAME_RO -+ * - SHCI_C2_BLE_INIT_OPTIONS_DEVICE_NAME_RW -+ * - SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV -+ * - SHCI_C2_BLE_INIT_OPTIONS_NO_EXT_ADV -+ * - SHCI_C2_BLE_INIT_OPTIONS_CS_ALGO2 -+ * - SHCI_C2_BLE_INIT_OPTIONS_NO_CS_ALGO2 -+ * - SHCI_C2_BLE_INIT_OPTIONS_REDUC_GATTDB_NVM -+ * - SHCI_C2_BLE_INIT_OPTIONS_FULL_GATTDB_NVM -+ * - SHCI_C2_BLE_INIT_OPTIONS_GATT_CACHING_USED -+ * - SHCI_C2_BLE_INIT_OPTIONS_GATT_CACHING_NOTUSED -+ * - SHCI_C2_BLE_INIT_OPTIONS_POWER_CLASS_1 -+ * - SHCI_C2_BLE_INIT_OPTIONS_POWER_CLASS_2_3 -+ * - SHCI_C2_BLE_INIT_OPTIONS_APPEARANCE_WRITABLE -+ * - SHCI_C2_BLE_INIT_OPTIONS_APPEARANCE_READONLY -+ * - SHCI_C2_BLE_INIT_OPTIONS_ENHANCED_ATT_SUPPORTED -+ * - SHCI_C2_BLE_INIT_OPTIONS_ENHANCED_ATT_NOTSUPPORTED -+ * which are used to set following configuration bits: -+ * (bit 0): 1: LL only -+ * 0: LL + host -+ * (bit 1): 1: no service change desc. -+ * 0: with service change desc. -+ * (bit 2): 1: device name Read-Only -+ * 0: device name R/W -+ * (bit 3): 1: extended advertizing supported -+ * 0: extended advertizing not supported -+ * (bit 4): 1: CS Algo #2 supported -+ * 0: CS Algo #2 not supported -+ * (bit 5): 1: Reduced GATT database in NVM -+ * 0: Full GATT database in NVM -+ * (bit 6): 1: GATT caching is used -+ * 0: GATT caching is not used -+ * (bit 7): 1: LE Power Class 1 -+ * 0: LE Power Class 2-3 -+ * (bit 8): 1: appearance Writable -+ * 0: appearance Read-Only -+ * (bit 9): 1: Enhanced ATT supported -+ * 0: Enhanced ATT not supported -+ * other bits: reserved (shall be set to 0) -+ */ -+#define CFG_BLE_OPTIONS (SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY) -+ -+#define CFG_BLE_MAX_COC_INITIATOR_NBR (32) -+ -+#define CFG_BLE_MIN_TX_POWER (-40) -+ -+#define CFG_BLE_MAX_TX_POWER (6) -+ -+/** -+ * BLE Rx model configuration flags to be configured with: -+ * - SHCI_C2_BLE_INIT_RX_MODEL_AGC_RSSI_LEGACY -+ * - SHCI_C2_BLE_INIT_RX_MODEL_AGC_RSSI_BLOCKER -+ * which are used to set following configuration bits: -+ * (bit 0): 1: agc_rssi model improved vs RF blockers -+ * 0: Legacy agc_rssi model -+ * other bits: reserved (shall be set to 0) -+ */ -+ -+#define CFG_BLE_RX_MODEL_CONFIG (SHCI_C2_BLE_INIT_RX_MODEL_AGC_RSSI_LEGACY) -+ -+/* Maximum number of advertising sets. -+ * Range: 1 .. 8 with limitation: -+ * This parameter is linked to CFG_BLE_MAX_ADV_DATA_LEN such as both compliant with allocated Total memory computed with BLE_EXT_ADV_BUFFER_SIZE based -+ * on Max Extended advertising configuration supported. -+ * This parameter is considered by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV flag set -+ */ -+ -+#define CFG_BLE_MAX_ADV_SET_NBR (8) -+ -+ /* Maximum advertising data length (in bytes) -+ * Range: 31 .. 1650 with limitation: -+ * This parameter is linked to CFG_BLE_MAX_ADV_SET_NBR such as both compliant with allocated Total memory computed with BLE_EXT_ADV_BUFFER_SIZE based -+ * on Max Extended advertising configuration supported. -+ * This parameter is considered by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV flag set -+ */ -+ -+#define CFG_BLE_MAX_ADV_DATA_LEN (207) -+ -+ /* RF TX Path Compensation Value (16-bit signed integer). Units: 0.1 dB. -+ * Range: -1280 .. 1280 -+ */ -+ -+#define CFG_BLE_TX_PATH_COMPENS (0) -+ -+ /* RF RX Path Compensation Value (16-bit signed integer). Units: 0.1 dB. -+ * Range: -1280 .. 1280 -+ */ -+ -+#define CFG_BLE_RX_PATH_COMPENS (0) -+ -+ /* BLE core version (16-bit signed integer). -+ * - SHCI_C2_BLE_INIT_BLE_CORE_5_2 -+ * - SHCI_C2_BLE_INIT_BLE_CORE_5_3 -+ * which are used to set: 11(5.2), 12(5.3). -+ */ -+ -+#define CFG_BLE_CORE_VERSION (SHCI_C2_BLE_INIT_BLE_CORE_5_3) -+ -+#endif /* APP_CONF_DEFAULT_H */ -diff --git a/src/utility/STM32Cube_FW/ble_bufsize.h b/src/utility/STM32Cube_FW/ble_bufsize.h -index 4269fa4..cea5da8 100644 ---- a/src/utility/STM32Cube_FW/ble_bufsize.h -+++ b/src/utility/STM32Cube_FW/ble_bufsize.h -@@ -75,6 +75,13 @@ - ((pw) + MAX(BLE_MEM_BLOCK_X_MTU(mtu, n_link), \ - BLE_MBLOCKS_SECURE_CONNECTIONS)) - -+/* -+ * BLE_DEFAULT_MBLOCKS_COUNT: default memory blocks count -+ */ -+#define BLE_DEFAULT_MBLOCKS_COUNT(n_link) \ -+ BLE_MBLOCKS_CALC(BLE_DEFAULT_PREP_WRITE_LIST_SIZE, \ -+ BLE_DEFAULT_MAX_ATT_MTU, n_link) -+ - /* - * BLE_FIXED_BUFFER_SIZE_BYTES: - * A part of the RAM, is dynamically allocated by initializing all the pointers -diff --git a/src/utility/STM32Cube_FW/hw.h b/src/utility/STM32Cube_FW/hw.h -index 503fa2c..fcf0451 100644 ---- a/src/utility/STM32Cube_FW/hw.h -+++ b/src/utility/STM32Cube_FW/hw.h -@@ -26,14 +26,21 @@ extern "C" { - #endif - - /* Includes ------------------------------------------------------------------*/ -+#include "stm32_def.h" -+#include "stm32wbxx_ll_bus.h" -+#include "stm32wbxx_ll_exti.h" -+#include "stm32wbxx_ll_system.h" -+#include "stm32wbxx_ll_rcc.h" -+#include "stm32wbxx_ll_ipcc.h" -+#include "stm32wbxx_ll_cortex.h" -+#include "stm32wbxx_ll_utils.h" -+#include "stm32wbxx_ll_pwr.h" - - /****************************************************************************** - * HW IPCC - ******************************************************************************/ - void HW_IPCC_Enable( void ); - void HW_IPCC_Init( void ); -- void HW_IPCC_Rx_Handler( void ); -- void HW_IPCC_Tx_Handler( void ); - - void HW_IPCC_BLE_Init( void ); - void HW_IPCC_BLE_SendCmd( void ); -@@ -80,23 +87,6 @@ extern "C" { - void HW_IPCC_TRACES_Init( void ); - void HW_IPCC_TRACES_EvtNot( void ); - -- void HW_IPCC_MAC_802_15_4_Init( void ); -- void HW_IPCC_MAC_802_15_4_SendCmd( void ); -- void HW_IPCC_MAC_802_15_4_SendAck( void ); -- void HW_IPCC_MAC_802_15_4_CmdEvtNot( void ); -- void HW_IPCC_MAC_802_15_4_EvtNot( void ); -- -- void HW_IPCC_ZIGBEE_Init( void ); -- -- void HW_IPCC_ZIGBEE_SendM4RequestToM0(void); /* M4 Request to M0 */ -- void HW_IPCC_ZIGBEE_RecvAppliAckFromM0(void); /* Request ACK from M0 */ -- -- void HW_IPCC_ZIGBEE_RecvM0NotifyToM4(void); /* M0 Notify to M4 */ -- void HW_IPCC_ZIGBEE_SendM4AckToM0Notify(void); /* Notify ACK from M4 */ -- void HW_IPCC_ZIGBEE_RecvM0RequestToM4(void); /* M0 Request to M4 */ -- void HW_IPCC_ZIGBEE_SendM4AckToM0Request(void); /* Request ACK from M4 */ -- -- - #ifdef __cplusplus - } - #endif -diff --git a/src/utility/STM32Cube_FW/hw_ipcc.c b/src/utility/STM32Cube_FW/hw_ipcc.c -index fd620b8..0c1868f 100644 ---- a/src/utility/STM32Cube_FW/hw_ipcc.c -+++ b/src/utility/STM32Cube_FW/hw_ipcc.c -@@ -1,4 +1,3 @@ --/* USER CODE BEGIN Header */ - /** - ****************************************************************************** - * @file hw_ipcc.c -@@ -16,10 +15,10 @@ - * - ****************************************************************************** - */ --/* USER CODE END Header */ - -+#if defined(STM32WBxx) - /* Includes ------------------------------------------------------------------*/ --#include "app_common.h" -+#include "hw.h" - #include "mbox_def.h" - - /* Global variables ---------------------------------------------------------*/ -@@ -56,34 +55,17 @@ static void HW_IPCC_LLD_BLE_ReceiveRspHandler( void ); - static void HW_IPCC_LLD_BLE_ReceiveM0CmdHandler( void ); - #endif - --#ifdef MAC_802_15_4_WB --static void HW_IPCC_MAC_802_15_4_CmdEvtHandler( void ); --static void HW_IPCC_MAC_802_15_4_NotEvtHandler( void ); --#endif -- --#ifdef ZIGBEE_WB --static void HW_IPCC_ZIGBEE_CmdEvtHandler( void ); --static void HW_IPCC_ZIGBEE_StackNotifEvtHandler( void ); --static void HW_IPCC_ZIGBEE_StackM0RequestHandler( void ); --#endif -- - /* Public function definition -----------------------------------------------*/ - - /****************************************************************************** - * INTERRUPT HANDLER - ******************************************************************************/ --void HW_IPCC_Rx_Handler( void ) -+void IPCC_C1_RX_IRQHandler( void ) - { - if (HW_IPCC_RX_PENDING( HW_IPCC_SYSTEM_EVENT_CHANNEL )) - { - HW_IPCC_SYS_EvtHandler(); - } --#ifdef MAC_802_15_4_WB -- else if (HW_IPCC_RX_PENDING( HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL )) -- { -- HW_IPCC_MAC_802_15_4_NotEvtHandler(); -- } --#endif /* MAC_802_15_4_WB */ - #ifdef THREAD_WB - else if (HW_IPCC_RX_PENDING( HW_IPCC_THREAD_NOTIFICATION_ACK_CHANNEL )) - { -@@ -114,16 +96,6 @@ void HW_IPCC_Rx_Handler( void ) - HW_IPCC_LLD_BLE_ReceiveM0CmdHandler(); - } - #endif /* LLD_TESTS_WB */ --#ifdef ZIGBEE_WB -- else if (HW_IPCC_RX_PENDING( HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL )) -- { -- HW_IPCC_ZIGBEE_StackNotifEvtHandler(); -- } -- else if (HW_IPCC_RX_PENDING( HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL )) -- { -- HW_IPCC_ZIGBEE_StackM0RequestHandler(); -- } --#endif /* ZIGBEE_WB */ - else if (HW_IPCC_RX_PENDING( HW_IPCC_BLE_EVENT_CHANNEL )) - { - HW_IPCC_BLE_EvtHandler(); -@@ -132,22 +104,14 @@ void HW_IPCC_Rx_Handler( void ) - { - HW_IPCC_TRACES_EvtHandler(); - } -- -- return; - } - --void HW_IPCC_Tx_Handler( void ) -+void IPCC_C1_TX_IRQHandler( void ) - { - if (HW_IPCC_TX_PENDING( HW_IPCC_SYSTEM_CMD_RSP_CHANNEL )) - { - HW_IPCC_SYS_CmdEvtHandler(); - } --#ifdef MAC_802_15_4_WB -- else if (HW_IPCC_TX_PENDING( HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL )) -- { -- HW_IPCC_MAC_802_15_4_CmdEvtHandler(); -- } --#endif /* MAC_802_15_4_WB */ - #ifdef THREAD_WB - else if (HW_IPCC_TX_PENDING( HW_IPCC_THREAD_OT_CMD_RSP_CHANNEL )) - { -@@ -157,12 +121,6 @@ void HW_IPCC_Tx_Handler( void ) - #ifdef LLD_TESTS_WB - // No TX handler for LLD tests - #endif /* LLD_TESTS_WB */ --#ifdef ZIGBEE_WB -- if (HW_IPCC_TX_PENDING( HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL )) -- { -- HW_IPCC_ZIGBEE_CmdEvtHandler(); -- } --#endif /* ZIGBEE_WB */ - else if (HW_IPCC_TX_PENDING( HW_IPCC_MM_RELEASE_BUFFER_CHANNEL )) - { - HW_IPCC_MM_FreeBufHandler(); -@@ -171,8 +129,6 @@ void HW_IPCC_Tx_Handler( void ) - { - HW_IPCC_BLE_AclDataEvtHandler(); - } -- -- return; - } - /****************************************************************************** - * GENERAL -@@ -204,8 +160,6 @@ void HW_IPCC_Enable( void ) - __SEV( ); /* Set the internal event flag and send an event to the CPU2 */ - __WFE( ); /* Clear the internal event flag */ - LL_PWR_EnableBootC2( ); -- -- return; - } - - void HW_IPCC_Init( void ) -@@ -217,8 +171,6 @@ void HW_IPCC_Init( void ) - - HAL_NVIC_EnableIRQ(IPCC_C1_RX_IRQn); - HAL_NVIC_EnableIRQ(IPCC_C1_TX_IRQn); -- -- return; - } - - /****************************************************************************** -@@ -227,15 +179,11 @@ void HW_IPCC_Init( void ) - void HW_IPCC_BLE_Init( void ) - { - LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_BLE_EVENT_CHANNEL ); -- -- return; - } - - void HW_IPCC_BLE_SendCmd( void ) - { - LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_BLE_CMD_CHANNEL ); -- -- return; - } - - static void HW_IPCC_BLE_EvtHandler( void ) -@@ -243,16 +191,12 @@ static void HW_IPCC_BLE_EvtHandler( void ) - HW_IPCC_BLE_RxEvtNot(); - - LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_BLE_EVENT_CHANNEL ); -- -- return; - } - - void HW_IPCC_BLE_SendAclData( void ) - { - LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_HCI_ACL_DATA_CHANNEL ); - LL_C1_IPCC_EnableTransmitChannel( IPCC, HW_IPCC_HCI_ACL_DATA_CHANNEL ); -- -- return; - } - - static void HW_IPCC_BLE_AclDataEvtHandler( void ) -@@ -260,8 +204,6 @@ static void HW_IPCC_BLE_AclDataEvtHandler( void ) - LL_C1_IPCC_DisableTransmitChannel( IPCC, HW_IPCC_HCI_ACL_DATA_CHANNEL ); - - HW_IPCC_BLE_AclDataAckNot(); -- -- return; - } - - __weak void HW_IPCC_BLE_AclDataAckNot( void ){}; -@@ -273,16 +215,12 @@ __weak void HW_IPCC_BLE_RxEvtNot( void ){}; - void HW_IPCC_SYS_Init( void ) - { - LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_SYSTEM_EVENT_CHANNEL ); -- -- return; - } - - void HW_IPCC_SYS_SendCmd( void ) - { - LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_SYSTEM_CMD_RSP_CHANNEL ); - LL_C1_IPCC_EnableTransmitChannel( IPCC, HW_IPCC_SYSTEM_CMD_RSP_CHANNEL ); -- -- return; - } - - static void HW_IPCC_SYS_CmdEvtHandler( void ) -@@ -290,8 +228,6 @@ static void HW_IPCC_SYS_CmdEvtHandler( void ) - LL_C1_IPCC_DisableTransmitChannel( IPCC, HW_IPCC_SYSTEM_CMD_RSP_CHANNEL ); - - HW_IPCC_SYS_CmdEvtNot(); -- -- return; - } - - static void HW_IPCC_SYS_EvtHandler( void ) -@@ -299,61 +235,11 @@ static void HW_IPCC_SYS_EvtHandler( void ) - HW_IPCC_SYS_EvtNot(); - - LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_SYSTEM_EVENT_CHANNEL ); -- -- return; - } - - __weak void HW_IPCC_SYS_CmdEvtNot( void ){}; - __weak void HW_IPCC_SYS_EvtNot( void ){}; - --/****************************************************************************** -- * MAC 802.15.4 -- ******************************************************************************/ --#ifdef MAC_802_15_4_WB --void HW_IPCC_MAC_802_15_4_Init( void ) --{ -- LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL ); -- -- return; --} -- --void HW_IPCC_MAC_802_15_4_SendCmd( void ) --{ -- LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL ); -- LL_C1_IPCC_EnableTransmitChannel( IPCC, HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL ); -- -- return; --} -- --void HW_IPCC_MAC_802_15_4_SendAck( void ) --{ -- LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL ); -- LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL ); -- -- return; --} -- --static void HW_IPCC_MAC_802_15_4_CmdEvtHandler( void ) --{ -- LL_C1_IPCC_DisableTransmitChannel( IPCC, HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL ); -- -- HW_IPCC_MAC_802_15_4_CmdEvtNot(); -- -- return; --} -- --static void HW_IPCC_MAC_802_15_4_NotEvtHandler( void ) --{ -- LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL ); -- -- HW_IPCC_MAC_802_15_4_EvtNot(); -- -- return; --} --__weak void HW_IPCC_MAC_802_15_4_CmdEvtNot( void ){}; --__weak void HW_IPCC_MAC_802_15_4_EvtNot( void ){}; --#endif -- - /****************************************************************************** - * THREAD - ******************************************************************************/ -@@ -393,8 +279,6 @@ void HW_IPCC_THREAD_CliSendAck( void ) - { - LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_THREAD_CLI_NOTIFICATION_ACK_CHANNEL ); - LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_THREAD_CLI_NOTIFICATION_ACK_CHANNEL ); -- -- return; - } - - static void HW_IPCC_OT_CmdEvtHandler( void ) -@@ -402,8 +286,6 @@ static void HW_IPCC_OT_CmdEvtHandler( void ) - LL_C1_IPCC_DisableTransmitChannel( IPCC, HW_IPCC_THREAD_OT_CMD_RSP_CHANNEL ); - - HW_IPCC_OT_CmdEvtNot(); -- -- return; - } - - static void HW_IPCC_THREAD_NotEvtHandler( void ) -@@ -411,8 +293,6 @@ static void HW_IPCC_THREAD_NotEvtHandler( void ) - LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_THREAD_NOTIFICATION_ACK_CHANNEL ); - - HW_IPCC_THREAD_EvtNot(); -- -- return; - } - - static void HW_IPCC_THREAD_CliNotEvtHandler( void ) -@@ -420,8 +300,6 @@ static void HW_IPCC_THREAD_CliNotEvtHandler( void ) - LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_THREAD_CLI_NOTIFICATION_ACK_CHANNEL ); - - HW_IPCC_THREAD_CliEvtNot(); -- -- return; - } - - __weak void HW_IPCC_OT_CmdEvtNot( void ){}; -@@ -438,7 +316,6 @@ void HW_IPCC_LLDTESTS_Init( void ) - { - LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_LLDTESTS_CLI_RSP_CHANNEL ); - LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_LLDTESTS_M0_CMD_CHANNEL ); -- return; - } - - void HW_IPCC_LLDTESTS_SendCliCmd( void ) -@@ -451,28 +328,24 @@ static void HW_IPCC_LLDTESTS_ReceiveCliRspHandler( void ) - { - LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_LLDTESTS_CLI_RSP_CHANNEL ); - HW_IPCC_LLDTESTS_ReceiveCliRsp(); -- return; - } - - void HW_IPCC_LLDTESTS_SendCliRspAck( void ) - { - LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_LLDTESTS_CLI_RSP_CHANNEL ); - LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_LLDTESTS_CLI_RSP_CHANNEL ); -- return; - } - - static void HW_IPCC_LLDTESTS_ReceiveM0CmdHandler( void ) - { - LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_LLDTESTS_M0_CMD_CHANNEL ); - HW_IPCC_LLDTESTS_ReceiveM0Cmd(); -- return; - } - - void HW_IPCC_LLDTESTS_SendM0CmdAck( void ) - { - LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_LLDTESTS_M0_CMD_CHANNEL ); - LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_LLDTESTS_M0_CMD_CHANNEL ); -- return; - } - __weak void HW_IPCC_LLDTESTS_ReceiveCliRsp( void ){}; - __weak void HW_IPCC_LLDTESTS_ReceiveM0Cmd( void ){}; -@@ -486,13 +359,11 @@ void HW_IPCC_LLD_BLE_Init( void ) - { - LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_LLD_BLE_RSP_CHANNEL ); - LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_LLD_BLE_M0_CMD_CHANNEL ); -- return; - } - - void HW_IPCC_LLD_BLE_SendCliCmd( void ) - { - LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_LLD_BLE_CLI_CMD_CHANNEL ); -- return; - } - - /*static void HW_IPCC_LLD_BLE_ReceiveCliRspHandler( void ) -@@ -506,21 +377,18 @@ void HW_IPCC_LLD_BLE_SendCliRspAck( void ) - { - LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_LLD_BLE_CLI_RSP_CHANNEL ); - LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_LLD_BLE_CLI_RSP_CHANNEL ); -- return; - } - - static void HW_IPCC_LLD_BLE_ReceiveM0CmdHandler( void ) - { - //LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_LLD_BLE_M0_CMD_CHANNEL ); - HW_IPCC_LLD_BLE_ReceiveM0Cmd(); -- return; - } - - void HW_IPCC_LLD_BLE_SendM0CmdAck( void ) - { - LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_LLD_BLE_M0_CMD_CHANNEL ); - //LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_LLD_BLE_M0_CMD_CHANNEL ); -- return; - } - __weak void HW_IPCC_LLD_BLE_ReceiveCliRsp( void ){}; - __weak void HW_IPCC_LLD_BLE_ReceiveM0Cmd( void ){}; -@@ -529,93 +397,22 @@ __weak void HW_IPCC_LLD_BLE_ReceiveM0Cmd( void ){}; - void HW_IPCC_LLD_BLE_SendCmd( void ) - { - LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_LLD_BLE_CMD_CHANNEL ); -- return; - } - - static void HW_IPCC_LLD_BLE_ReceiveRspHandler( void ) - { - LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_LLD_BLE_RSP_CHANNEL ); - HW_IPCC_LLD_BLE_ReceiveRsp(); -- return; - } - - void HW_IPCC_LLD_BLE_SendRspAck( void ) - { - LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_LLD_BLE_RSP_CHANNEL ); - LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_LLD_BLE_RSP_CHANNEL ); -- return; - } - - #endif /* LLD_BLE_WB */ - --/****************************************************************************** -- * ZIGBEE -- ******************************************************************************/ --#ifdef ZIGBEE_WB --void HW_IPCC_ZIGBEE_Init( void ) --{ -- LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL ); -- LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL ); -- -- return; --} -- --void HW_IPCC_ZIGBEE_SendM4RequestToM0( void ) --{ -- LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL ); -- LL_C1_IPCC_EnableTransmitChannel( IPCC, HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL ); -- -- return; --} -- --void HW_IPCC_ZIGBEE_SendM4AckToM0Notify( void ) --{ -- LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL ); -- LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL ); -- -- return; --} -- --static void HW_IPCC_ZIGBEE_CmdEvtHandler( void ) --{ -- LL_C1_IPCC_DisableTransmitChannel( IPCC, HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL ); -- -- HW_IPCC_ZIGBEE_RecvAppliAckFromM0(); -- -- return; --} -- --static void HW_IPCC_ZIGBEE_StackNotifEvtHandler( void ) --{ -- LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL ); -- -- HW_IPCC_ZIGBEE_RecvM0NotifyToM4(); -- -- return; --} -- --static void HW_IPCC_ZIGBEE_StackM0RequestHandler( void ) --{ -- LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL ); -- -- HW_IPCC_ZIGBEE_RecvM0RequestToM4(); -- -- return; --} -- --void HW_IPCC_ZIGBEE_SendM4AckToM0Request( void ) --{ -- LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL ); -- LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL ); -- -- return; --} -- --__weak void HW_IPCC_ZIGBEE_RecvAppliAckFromM0( void ){}; --__weak void HW_IPCC_ZIGBEE_RecvM0NotifyToM4( void ){}; --__weak void HW_IPCC_ZIGBEE_RecvM0RequestToM4( void ){}; --#endif /* ZIGBEE_WB */ -- - /****************************************************************************** - * MEMORY MANAGER - ******************************************************************************/ -@@ -632,8 +429,6 @@ void HW_IPCC_MM_SendFreeBuf( void (*cb)( void ) ) - - LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_MM_RELEASE_BUFFER_CHANNEL ); - } -- -- return; - } - - static void HW_IPCC_MM_FreeBufHandler( void ) -@@ -643,8 +438,6 @@ static void HW_IPCC_MM_FreeBufHandler( void ) - FreeBufCb(); - - LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_MM_RELEASE_BUFFER_CHANNEL ); -- -- return; - } - - /****************************************************************************** -@@ -662,8 +455,7 @@ static void HW_IPCC_TRACES_EvtHandler( void ) - HW_IPCC_TRACES_EvtNot(); - - LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_TRACES_CHANNEL ); -- -- return; - } - - __weak void HW_IPCC_TRACES_EvtNot( void ){}; -+#endif /* STM32WBxx */ -diff --git a/src/utility/STM32Cube_FW/mbox_def.h b/src/utility/STM32Cube_FW/mbox_def.h -index 68b71f9..0c974f8 100644 ---- a/src/utility/STM32Cube_FW/mbox_def.h -+++ b/src/utility/STM32Cube_FW/mbox_def.h -@@ -106,12 +106,6 @@ extern "C" { - uint8_t *m0cmd_buffer; - } MB_BleLldTable_t; - -- typedef struct -- { -- uint8_t *notifM0toM4_buffer; -- uint8_t *appliCmdM4toM0_buffer; -- uint8_t *requestM0toM4_buffer; -- } MB_ZigbeeTable_t; - /** - * msg - * [0:7] = cmd/evt -@@ -139,13 +133,6 @@ extern "C" { - uint8_t *traces_queue; - } MB_TracesTable_t; - -- typedef struct -- { -- uint8_t *p_cmdrsp_buffer; -- uint8_t *p_notack_buffer; -- uint8_t *evt_queue; -- } MB_Mac_802_15_4_t; -- - typedef struct - { - MB_DeviceInfoTable_t *p_device_info_table; -@@ -154,8 +141,6 @@ extern "C" { - MB_SysTable_t *p_sys_table; - MB_MemManagerTable_t *p_mem_manager_table; - MB_TracesTable_t *p_traces_table; -- MB_Mac_802_15_4_t *p_mac_802_15_4_table; -- MB_ZigbeeTable_t *p_zigbee_table; - MB_LldTestsTable_t *p_lld_tests_table; - MB_BleLldTable_t *p_ble_lld_table; - } MB_RefTable_t; -@@ -199,15 +184,6 @@ typedef struct - * | | - * |<---HW_IPCC_SYSTEM_EVENT_CHANNEL-----------------| - * | | -- * | (ZIGBEE) | -- * |----HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL------------>| -- * | | -- * |----HW_IPCC_ZIGBEE_CMD_CLI_CHANNEL-------------->| -- * | | -- * |<---HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL-------| -- * | | -- * |<---HW_IPCC_ZIGBEE_CLI_NOTIF_ACK_CHANNEL---------| -- * | | - * | (THREAD) | - * |----HW_IPCC_THREAD_OT_CMD_RSP_CHANNEL----------->| - * | | -@@ -231,11 +207,6 @@ typedef struct - * | | - * |<---HW_IPCC_BLE_LLD_M0_CMD_CHANNEL---------------| - * | | -- * | (MAC) | -- * |----HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL-------->| -- * | | -- * |<---HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL| -- * | | - * | (BUFFER) | - * |----HW_IPCC_MM_RELEASE_BUFFER_CHANNE------------>| - * | | -@@ -253,8 +224,6 @@ typedef struct - #define HW_IPCC_BLE_CMD_CHANNEL LL_IPCC_CHANNEL_1 - #define HW_IPCC_SYSTEM_CMD_RSP_CHANNEL LL_IPCC_CHANNEL_2 - #define HW_IPCC_THREAD_OT_CMD_RSP_CHANNEL LL_IPCC_CHANNEL_3 --#define HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL LL_IPCC_CHANNEL_3 --#define HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL LL_IPCC_CHANNEL_3 - #define HW_IPCC_MM_RELEASE_BUFFER_CHANNEL LL_IPCC_CHANNEL_4 - #define HW_IPCC_THREAD_CLI_CMD_CHANNEL LL_IPCC_CHANNEL_5 - #define HW_IPCC_LLDTESTS_CLI_CMD_CHANNEL LL_IPCC_CHANNEL_5 -@@ -266,8 +235,6 @@ typedef struct - #define HW_IPCC_BLE_EVENT_CHANNEL LL_IPCC_CHANNEL_1 - #define HW_IPCC_SYSTEM_EVENT_CHANNEL LL_IPCC_CHANNEL_2 - #define HW_IPCC_THREAD_NOTIFICATION_ACK_CHANNEL LL_IPCC_CHANNEL_3 --#define HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL LL_IPCC_CHANNEL_3 --#define HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL LL_IPCC_CHANNEL_3 - #define HW_IPCC_LLDTESTS_M0_CMD_CHANNEL LL_IPCC_CHANNEL_3 - #define HW_IPCC_BLE_LLD_M0_CMD_CHANNEL LL_IPCC_CHANNEL_3 - #define HW_IPCC_TRACES_CHANNEL LL_IPCC_CHANNEL_4 -@@ -275,6 +242,5 @@ typedef struct - #define HW_IPCC_LLDTESTS_CLI_RSP_CHANNEL LL_IPCC_CHANNEL_5 - #define HW_IPCC_BLE_LLD_CLI_RSP_CHANNEL LL_IPCC_CHANNEL_5 - #define HW_IPCC_BLE_LLD_RSP_CHANNEL LL_IPCC_CHANNEL_5 --#define HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL LL_IPCC_CHANNEL_5 - #endif /*__MBOX_H */ - -diff --git a/src/utility/STM32Cube_FW/shci.c b/src/utility/STM32Cube_FW/shci.c -index 301db76..a847522 100644 ---- a/src/utility/STM32Cube_FW/shci.c -+++ b/src/utility/STM32Cube_FW/shci.c -@@ -16,7 +16,7 @@ - ****************************************************************************** - */ - -- -+#if defined(STM32WBxx) - /* Includes ------------------------------------------------------------------*/ - #include "stm32_wpan_common.h" - -@@ -352,24 +352,6 @@ SHCI_CmdStatus_t SHCI_C2_BLE_LLD_Init( uint8_t param_size, uint8_t * p_param ) - return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); - } - --SHCI_CmdStatus_t SHCI_C2_ZIGBEE_Init( void ) --{ -- /** -- * Buffer is large enough to hold command complete without payload -- */ -- uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; -- TL_EvtPacket_t * p_rsp; -- -- p_rsp = (TL_EvtPacket_t *)local_buffer; -- -- shci_send( SHCI_OPCODE_C2_ZIGBEE_INIT, -- 0, -- 0, -- p_rsp ); -- -- return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); --} -- - SHCI_CmdStatus_t SHCI_C2_DEBUG_Init( SHCI_C2_DEBUG_Init_Cmd_Packet_t *pCmdPacket ) - { - /** -@@ -527,24 +509,6 @@ SHCI_CmdStatus_t SHCI_C2_RADIO_AllowLowPower( SHCI_C2_FLASH_Ip_t Ip,uint8_t Fla - return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); - } - --SHCI_CmdStatus_t SHCI_C2_MAC_802_15_4_Init( void ) --{ -- /** -- * Buffer is large enough to hold command complete without payload -- */ -- uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; -- TL_EvtPacket_t * p_rsp; -- -- p_rsp = (TL_EvtPacket_t *)local_buffer; -- -- shci_send( SHCI_OPCODE_C2_MAC_802_15_4_INIT, -- 0, -- 0, -- p_rsp ); -- -- return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); --} -- - SHCI_CmdStatus_t SHCI_C2_Reinit( void ) - { - /** -@@ -739,3 +703,4 @@ SHCI_CmdStatus_t SHCI_GetWirelessFwInfo( WirelessFwInfo_t* pWirelessInfo ) - - return (SHCI_Success); - } -+#endif /* STM32WBxx */ -diff --git a/src/utility/STM32Cube_FW/shci.h b/src/utility/STM32Cube_FW/shci.h -index 7ca9021..a0f1e4d 100644 ---- a/src/utility/STM32Cube_FW/shci.h -+++ b/src/utility/STM32Cube_FW/shci.h -@@ -49,7 +49,6 @@ extern "C" { - ERR_BLE_INIT = 0, /* This event is currently not reported by the CPU2 */ - ERR_THREAD_LLD_FATAL_ERROR = 125, /* The LLD driver used on 802_15_4 detected a fatal error */ - ERR_THREAD_UNKNOWN_CMD = 126, /* The command send by the CPU1 to control the Thread stack is unknown */ -- ERR_ZIGBEE_UNKNOWN_CMD = 200, /* The command send by the CPU1 to control the Zigbee stack is unknown */ - } SCHI_SystemErrCode_t; - - #define SHCI_EVTCODE ( 0xFF ) -@@ -216,9 +215,7 @@ extern "C" { - SHCI_OCF_C2_FLASH_STORE_DATA, - SHCI_OCF_C2_FLASH_ERASE_DATA, - SHCI_OCF_C2_RADIO_ALLOW_LOW_POWER, -- SHCI_OCF_C2_MAC_802_15_4_INIT, - SHCI_OCF_C2_REINIT, -- SHCI_OCF_C2_ZIGBEE_INIT, - SHCI_OCF_C2_LLD_TESTS_INIT, - SHCI_OCF_C2_EXTPA_CONFIG, - SHCI_OCF_C2_SET_FLASH_ACTIVITY_CONTROL, -@@ -436,7 +433,7 @@ extern "C" { - * PrWriteListSize - * NOTE: This parameter is ignored by the CPU2 when the parameter "Options" is set to "LL_only" ( see Options description in that structure ) - * -- * Maximum number of supported �prepare write request� -+ * Maximum number of supported "prepare write request" - * - Min value: given by the macro DEFAULT_PREP_WRITE_LIST_SIZE - * - Max value: a value higher than the minimum required can be specified, but it is not recommended - */ -@@ -503,7 +500,7 @@ extern "C" { - * MaxConnEventLength - * This parameter determines the maximum duration of a slave connection event. When this duration is reached the slave closes - * the current connections event (whatever is the CE_length parameter specified by the master in HCI_CREATE_CONNECTION HCI command), -- * expressed in units of 625/256 �s (~2.44 �s) -+ * expressed in units of 625/256 µs (~2.44 µs) - * - Min value: 0 (if 0 is specified, the master and slave perform only a single TX-RX exchange per connection event) - * - Max value: 1638400 (4000 ms). A higher value can be specified (max 0xFFFFFFFF) but results in a maximum connection time - * of 4000 ms as specified. In this case the parameter is not applied, and the predicted CE length calculated on slave is not shortened -@@ -512,7 +509,7 @@ extern "C" { - - /** - * HsStartupTime -- * Startup time of the high speed (16 or 32 MHz) crystal oscillator in units of 625/256 �s (~2.44 �s). -+ * Startup time of the high speed (16 or 32 MHz) crystal oscillator in units of 625/256 µs (~2.44 µs). - * - Min value: 0 - * - Max value: 820 (~2 ms). A higher value can be specified, but the value that implemented in stack is forced to ~2 ms - */ -@@ -678,8 +675,6 @@ extern "C" { - { - uint8_t thread_config; - uint8_t ble_config; -- uint8_t mac_802_15_4_config; -- uint8_t zigbee_config; - } SHCI_C2_DEBUG_TracesConfig_t; - - typedef PACKED_STRUCT -@@ -743,8 +738,6 @@ extern "C" { - { - BLE_ENABLE, - THREAD_ENABLE, -- ZIGBEE_ENABLE, -- MAC_ENABLE, - } SHCI_C2_CONCURRENT_Mode_Param_t; - /** No response parameters*/ - -@@ -767,18 +760,13 @@ extern "C" { - { - BLE_IP, - THREAD_IP, -- ZIGBEE_IP, - } SHCI_C2_FLASH_Ip_t; - /** No response parameters*/ - - #define SHCI_OPCODE_C2_RADIO_ALLOW_LOW_POWER (( SHCI_OGF << 10) + SHCI_OCF_C2_RADIO_ALLOW_LOW_POWER) - --#define SHCI_OPCODE_C2_MAC_802_15_4_INIT (( SHCI_OGF << 10) + SHCI_OCF_C2_MAC_802_15_4_INIT) -- - #define SHCI_OPCODE_C2_REINIT (( SHCI_OGF << 10) + SHCI_OCF_C2_REINIT) - --#define SHCI_OPCODE_C2_ZIGBEE_INIT (( SHCI_OGF << 10) + SHCI_OCF_C2_ZIGBEE_INIT) -- - #define SHCI_OPCODE_C2_LLD_TESTS_INIT (( SHCI_OGF << 10) + SHCI_OCF_C2_LLD_TESTS_INIT) - - #define SHCI_OPCODE_C2_BLE_LLD_INIT (( SHCI_OGF << 10) + SHCI_OCF_C2_BLE_LLD_INIT) -@@ -893,7 +881,7 @@ extern "C" { - #define FUS_DEVICE_INFO_TABLE_VALIDITY_KEYWORD (0xA94656B9) - - /* -- * At startup, the informations relative to the wireless binary are stored in RAM trough a structure defined by -+ * At startup, the information relative to the wireless binary are stored in RAM through a structure defined by - * MB_WirelessFwInfoTable_t.This structure contains 4 fields (Version,MemorySize, Stack_info and a reserved part) - * each of those coded on 32 bits as shown on the table below: - * -@@ -949,9 +937,6 @@ extern "C" { - #define INFO_STACK_TYPE_BLE_HCI_EXT_ADV 0x07 - #define INFO_STACK_TYPE_THREAD_FTD 0x10 - #define INFO_STACK_TYPE_THREAD_MTD 0x11 --#define INFO_STACK_TYPE_ZIGBEE_FFD 0x30 --#define INFO_STACK_TYPE_ZIGBEE_RFD 0x31 --#define INFO_STACK_TYPE_MAC 0x40 - #define INFO_STACK_TYPE_BLE_THREAD_FTD_STATIC 0x50 - #define INFO_STACK_TYPE_BLE_THREAD_FTD_DYAMIC 0x51 - #define INFO_STACK_TYPE_802154_LLD_TESTS 0x60 -@@ -960,12 +945,7 @@ extern "C" { - #define INFO_STACK_TYPE_BLE_LLD_TESTS 0x63 - #define INFO_STACK_TYPE_BLE_RLV 0x64 - #define INFO_STACK_TYPE_802154_RLV 0x65 --#define INFO_STACK_TYPE_BLE_ZIGBEE_FFD_STATIC 0x70 --#define INFO_STACK_TYPE_BLE_ZIGBEE_RFD_STATIC 0x71 --#define INFO_STACK_TYPE_BLE_ZIGBEE_FFD_DYNAMIC 0x78 --#define INFO_STACK_TYPE_BLE_ZIGBEE_RFD_DYNAMIC 0x79 - #define INFO_STACK_TYPE_RLV 0x80 --#define INFO_STACK_TYPE_BLE_MAC_STATIC 0x90 - - typedef struct { - /** -@@ -1139,7 +1119,7 @@ typedef struct { - * @brief Starts the LLD tests CLI - * - * @param param_size : Nb of bytes -- * @param p_param : pointeur with data to give from M4 to M0 -+ * @param p_param : pointer with data to give from M4 to M0 - * @retval Status - */ - SHCI_CmdStatus_t SHCI_C2_LLDTESTS_Init( uint8_t param_size, uint8_t * p_param ); -@@ -1149,20 +1129,11 @@ typedef struct { - * @brief Starts the LLD tests BLE - * - * @param param_size : Nb of bytes -- * @param p_param : pointeur with data to give from M4 to M0 -+ * @param p_param : pointer with data to give from M4 to M0 - * @retval Status - */ - SHCI_CmdStatus_t SHCI_C2_BLE_LLD_Init( uint8_t param_size, uint8_t * p_param ); - -- /** -- * SHCI_C2_ZIGBEE_Init -- * @brief Starts the Zigbee Stack -- * -- * @param None -- * @retval Status -- */ -- SHCI_CmdStatus_t SHCI_C2_ZIGBEE_Init( void ); -- - /** - * SHCI_C2_DEBUG_Init - * @brief Starts the Traces -@@ -1237,16 +1208,6 @@ typedef struct { - */ - SHCI_CmdStatus_t SHCI_C2_RADIO_AllowLowPower( SHCI_C2_FLASH_Ip_t Ip,uint8_t FlagRadioLowPowerOn); - -- -- /** -- * SHCI_C2_MAC_802_15_4_Init -- * @brief Starts the MAC 802.15.4 on M0 -- * -- * @param None -- * @retval Status -- */ -- SHCI_CmdStatus_t SHCI_C2_MAC_802_15_4_Init( void ); -- - /** - * SHCI_GetWirelessFwInfo - * @brief This function read back the informations relative to the wireless binary loaded. -diff --git a/src/utility/STM32Cube_FW/shci_tl.c b/src/utility/STM32Cube_FW/shci_tl.c -index 449b8b1..b3cee00 100644 ---- a/src/utility/STM32Cube_FW/shci_tl.c -+++ b/src/utility/STM32Cube_FW/shci_tl.c -@@ -16,12 +16,13 @@ - ****************************************************************************** - */ - -- -+#if defined(STM32WBxx) - /* Includes ------------------------------------------------------------------*/ - #include "stm32_wpan_common.h" - - #include "stm_list.h" - #include "shci_tl.h" -+#include "stm32_def.h" - - /* Private typedef -----------------------------------------------------------*/ - typedef enum -@@ -70,8 +71,6 @@ void shci_init(void(* UserEvtRx)(void* pData), void* pConf) - shci_register_io_bus (&shciContext.io); - - TlInit((TL_CmdPacket_t *)(((SHCI_TL_HciInitConf_t *)pConf)->p_cmdbuffer)); -- -- return; - } - - void shci_user_evt_proc(void) -@@ -127,8 +126,6 @@ void shci_user_evt_proc(void) - shci_notify_asynch_evt((void*) &SHciAsynchEventQueue); - } - -- -- return; - } - - void shci_resume_flow( void ) -@@ -140,8 +137,6 @@ void shci_resume_flow( void ) - * be called - */ - shci_notify_asynch_evt((void*) &SHciAsynchEventQueue); -- -- return; - } - - void shci_send( uint16_t cmd_code, uint8_t len_cmd_payload, uint8_t * p_cmd_payload, TL_EvtPacket_t * p_rsp ) -@@ -164,8 +159,20 @@ void shci_send( uint16_t cmd_code, uint8_t len_cmd_payload, uint8_t * p_cmd_payl - memcpy( &(p_rsp->evtserial), pCmdBuffer, ((TL_EvtSerial_t*)pCmdBuffer)->evt.plen + TL_EVT_HDR_SIZE ); - - Cmd_SetStatus(SHCI_TL_CmdAvailable); -+} -+ -+void shci_notify_asynch_evt(void *pdata) -+{ -+ UNUSED(pdata); -+ /* Need to parse data in future version */ -+ shci_user_evt_proc(); -+} - -- return; -+void shci_register_io_bus(tSHciIO *fops) -+{ -+ /* Register IO bus services */ -+ fops->Init = TL_SYS_Init; -+ fops->Send = TL_SYS_SendCmd; - } - - /* Private functions ---------------------------------------------------------*/ -@@ -190,8 +197,6 @@ static void TlInit( TL_CmdPacket_t * p_cmdbuffer ) - Conf.IoBusCallBackUserEvt = TlUserEvtReceived; - shciContext.io.Init(&Conf); - } -- -- return; - } - - static void Cmd_SetStatus(SHCI_TL_CmdStatus_t shcicmdstatus) -@@ -212,24 +217,18 @@ static void Cmd_SetStatus(SHCI_TL_CmdStatus_t shcicmdstatus) - StatusNotCallBackFunction( SHCI_TL_CmdAvailable ); - } - } -- -- return; - } - - static void TlCmdEvtReceived(TL_EvtPacket_t *shcievt) - { - (void)(shcievt); - shci_cmd_resp_release(0); /**< Notify the application the Cmd response has been received */ -- -- return; - } - - static void TlUserEvtReceived(TL_EvtPacket_t *shcievt) - { - LST_insert_tail(&SHciAsynchEventQueue, (tListNode *)shcievt); - shci_notify_asynch_evt((void*) &SHciAsynchEventQueue); /**< Notify the application a full HCI event has been received */ -- -- return; - } - - /* Weak implementation ----------------------------------------------------------------*/ -@@ -239,8 +238,6 @@ __WEAK void shci_cmd_resp_wait(uint32_t timeout) - - CmdRspStatusFlag = SHCI_TL_CMD_RESP_WAIT; - while(CmdRspStatusFlag != SHCI_TL_CMD_RESP_RELEASE); -- -- return; - } - - __WEAK void shci_cmd_resp_release(uint32_t flag) -@@ -248,7 +245,5 @@ __WEAK void shci_cmd_resp_release(uint32_t flag) - (void)flag; - - CmdRspStatusFlag = SHCI_TL_CMD_RESP_RELEASE; -- -- return; - } -- -+#endif /* STM32WBxx */ -diff --git a/src/utility/STM32Cube_FW/stm32_wpan_common.h b/src/utility/STM32Cube_FW/stm32_wpan_common.h -index f407bb9..5a2b2a5 100644 ---- a/src/utility/STM32Cube_FW/stm32_wpan_common.h -+++ b/src/utility/STM32Cube_FW/stm32_wpan_common.h -@@ -25,19 +25,9 @@ - extern "C" { - #endif - --#if defined ( __CC_ARM )||defined (__ARMCC_VERSION) -- #define __ASM __asm /*!< asm keyword for ARM Compiler */ -- #define __INLINE __inline /*!< inline keyword for ARM Compiler */ -- #define __STATIC_INLINE static __inline --#elif defined ( __ICCARM__ ) -- #define __ASM __asm /*!< asm keyword for IAR Compiler */ -- #define __INLINE inline /*!< inline keyword for IAR Compiler. Only available in High optimization mode! */ -- #define __STATIC_INLINE static inline --#elif defined ( __GNUC__ ) -- #define __ASM __asm /*!< asm keyword for GNU Compiler */ -- #define __INLINE inline /*!< inline keyword for GNU Compiler */ -- #define __STATIC_INLINE static inline --#endif -+#define __ASM __asm /*!< asm keyword for GNU Compiler */ -+#define __INLINE inline /*!< inline keyword for GNU Compiler */ -+#define __STATIC_INLINE static inline - - #include <stdint.h> - #include <string.h> -@@ -140,29 +130,8 @@ extern "C" { - /* ----------------------------------- * - * Packed usage (compiler dependent) * - * ----------------------------------- */ --#undef PACKED__ - #undef PACKED_STRUCT -- --#if defined ( __CC_ARM ) -- #if defined ( __GNUC__ ) -- /* GNU extension */ -- #define PACKED__ __attribute__((packed)) -- #define PACKED_STRUCT struct PACKED__ -- #elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050U) -- #define PACKED__ __attribute__((packed)) -- #define PACKED_STRUCT struct PACKED__ -- #else -- #define PACKED__(TYPE) __packed TYPE -- #define PACKED_STRUCT PACKED__(struct) -- #endif --#elif defined ( __GNUC__ ) -- #define PACKED__ __attribute__((packed)) -- #define PACKED_STRUCT struct PACKED__ --#elif defined (__ICCARM__) -- #define PACKED_STRUCT __packed struct --#else -- #define PACKED_STRUCT __packed struct --#endif -+#define PACKED_STRUCT struct __packed - - #ifdef __cplusplus - } -diff --git a/src/utility/STM32Cube_FW/stm_list.c b/src/utility/STM32Cube_FW/stm_list.c -index 4c92864..9892441 100644 ---- a/src/utility/STM32Cube_FW/stm_list.c -+++ b/src/utility/STM32Cube_FW/stm_list.c -@@ -16,13 +16,13 @@ - ****************************************************************************** - */ - -- -+#if defined(STM32WBxx) - /****************************************************************************** - * Include Files - ******************************************************************************/ --#include "utilities_common.h" -- - #include "stm_list.h" -+#include "cmsis_gcc.h" -+#include "stm32_wpan_common.h" - - /****************************************************************************** - * Function Definitions -@@ -33,20 +33,20 @@ void LST_init_head (tListNode * listHead) - listHead->prev = listHead; - } - --uint8_t LST_is_empty (tListNode * listHead) -+bool LST_is_empty (tListNode * listHead) - { - uint32_t primask_bit; -- uint8_t return_value; -+ bool return_value; - - primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ - __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ - if(listHead->next == listHead) - { -- return_value = TRUE; -+ return_value = true; - } - else - { -- return_value = FALSE; -+ return_value = false; - } - __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ - -@@ -204,3 +204,4 @@ void LST_get_prev_node (tListNode * ref_node, tListNode ** node) - - __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ - } -+#endif /* STM32WBxx */ -diff --git a/src/utility/STM32Cube_FW/stm_list.h b/src/utility/STM32Cube_FW/stm_list.h -index b7c3254..769c211 100644 ---- a/src/utility/STM32Cube_FW/stm_list.h -+++ b/src/utility/STM32Cube_FW/stm_list.h -@@ -21,6 +21,8 @@ - #define _STM_LIST_H_ - - /* Includes ------------------------------------------------------------------*/ -+#include "stdint.h" -+#include "stdbool.h" - #include "stm32_wpan_common.h" - - typedef PACKED_STRUCT _tListNode { -@@ -30,7 +32,7 @@ typedef PACKED_STRUCT _tListNode { - - void LST_init_head (tListNode * listHead); - --uint8_t LST_is_empty (tListNode * listHead); -+bool LST_is_empty (tListNode * listHead); - - void LST_insert_head (tListNode * listHead, tListNode * node); - -diff --git a/src/utility/STM32Cube_FW/tl.h b/src/utility/STM32Cube_FW/tl.h -index c199bb2..982bb58 100644 ---- a/src/utility/STM32Cube_FW/tl.h -+++ b/src/utility/STM32Cube_FW/tl.h -@@ -202,19 +202,6 @@ typedef struct - uint8_t *p_BleLldM0CmdBuffer; - } TL_BLE_LLD_Config_t; - --typedef struct --{ -- uint8_t *p_Mac_802_15_4_CmdRspBuffer; -- uint8_t *p_Mac_802_15_4_NotAckBuffer; --} TL_MAC_802_15_4_Config_t; -- --typedef struct --{ -- uint8_t *p_ZigbeeOtCmdRspBuffer; -- uint8_t *p_ZigbeeNotAckBuffer; -- uint8_t *p_ZigbeeNotifRequestBuffer; --} TL_ZIGBEE_Config_t; -- - /** - * @brief Contain the BLE HCI Init Configuration - * @{ -@@ -308,26 +295,6 @@ void TL_MM_EvtDone( TL_EvtPacket_t * hcievt ); - void TL_TRACES_Init( void ); - void TL_TRACES_EvtReceived( TL_EvtPacket_t * hcievt ); - --/****************************************************************************** -- * MAC 802.15.4 -- ******************************************************************************/ --void TL_MAC_802_15_4_Init( TL_MAC_802_15_4_Config_t *p_Config ); --void TL_MAC_802_15_4_SendCmd( void ); --void TL_MAC_802_15_4_CmdEvtReceived( TL_EvtPacket_t * Otbuffer ); --void TL_MAC_802_15_4_NotReceived( TL_EvtPacket_t * Notbuffer ); --void TL_MAC_802_15_4_SendAck ( void ); -- --/****************************************************************************** -- * ZIGBEE -- ******************************************************************************/ --void TL_ZIGBEE_Init( TL_ZIGBEE_Config_t *p_Config ); --void TL_ZIGBEE_SendM4RequestToM0( void ); --void TL_ZIGBEE_SendM4AckToM0Notify ( void ); --void TL_ZIGBEE_NotReceived( TL_EvtPacket_t * Notbuffer ); --void TL_ZIGBEE_CmdEvtReceived( TL_EvtPacket_t * Otbuffer ); --void TL_ZIGBEE_M0RequestReceived(TL_EvtPacket_t * Otbuffer ); --void TL_ZIGBEE_SendM4AckToM0Request(void); -- - #ifdef __cplusplus - } /* extern "C" */ - #endif -diff --git a/src/utility/STM32Cube_FW/tl_mbox.c b/src/utility/STM32Cube_FW/tl_mbox.c -index fcd7766..a9abb18 100644 ---- a/src/utility/STM32Cube_FW/tl_mbox.c -+++ b/src/utility/STM32Cube_FW/tl_mbox.c -@@ -16,6 +16,7 @@ - ****************************************************************************** - */ - -+#if defined(STM32WBxx) - /* Includes ------------------------------------------------------------------*/ - #include "stm32_wpan_common.h" - #include "hw.h" -@@ -51,15 +52,13 @@ PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_BleLldTable_t TL_BleLldTable; - PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_SysTable_t TL_SysTable; - PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_MemManagerTable_t TL_MemManagerTable; - PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_TracesTable_t TL_TracesTable; --PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_Mac_802_15_4_t TL_Mac_802_15_4_Table; --PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_ZigbeeTable_t TL_Zigbee_Table; - - /**< tables */ - PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode FreeBufQueue; - PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode TracesEvtQueue; - PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static uint8_t CsBuffer[sizeof(TL_PacketHeader_t) + TL_EVT_HDR_SIZE + sizeof(TL_CsEvt_t)]; --PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode EvtQueue; --PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode SystemEvtQueue; -+PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static tListNode EvtQueue; -+PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static tListNode SystemEvtQueue; - - - static tListNode LocalFreeBufQueue; -@@ -97,8 +96,6 @@ void TL_Init( void ) - TL_RefTable.p_sys_table = &TL_SysTable; - TL_RefTable.p_mem_manager_table = &TL_MemManagerTable; - TL_RefTable.p_traces_table = &TL_TracesTable; -- TL_RefTable.p_mac_802_15_4_table = &TL_Mac_802_15_4_Table; -- TL_RefTable.p_zigbee_table = &TL_Zigbee_Table; - HW_IPCC_Init(); - - return; -@@ -452,139 +449,6 @@ void TL_BLE_LLD_SendRspAck( void ) - } - #endif /* BLE_LLD_WB */ - --#ifdef MAC_802_15_4_WB --/****************************************************************************** -- * MAC 802.15.4 -- ******************************************************************************/ --void TL_MAC_802_15_4_Init( TL_MAC_802_15_4_Config_t *p_Config ) --{ -- MB_Mac_802_15_4_t * p_mac_802_15_4_table; -- -- p_mac_802_15_4_table = TL_RefTable.p_mac_802_15_4_table; -- -- p_mac_802_15_4_table->p_cmdrsp_buffer = p_Config->p_Mac_802_15_4_CmdRspBuffer; -- p_mac_802_15_4_table->p_notack_buffer = p_Config->p_Mac_802_15_4_NotAckBuffer; -- -- HW_IPCC_MAC_802_15_4_Init(); -- -- return; --} -- --void TL_MAC_802_15_4_SendCmd( void ) --{ -- ((TL_CmdPacket_t *)(TL_RefTable.p_mac_802_15_4_table->p_cmdrsp_buffer))->cmdserial.type = TL_OTCMD_PKT_TYPE; -- -- HW_IPCC_MAC_802_15_4_SendCmd(); -- -- return; --} -- --void TL_MAC_802_15_4_SendAck ( void ) --{ -- ((TL_CmdPacket_t *)(TL_RefTable.p_mac_802_15_4_table->p_notack_buffer))->cmdserial.type = TL_OTACK_PKT_TYPE; -- -- HW_IPCC_MAC_802_15_4_SendAck(); -- -- return; --} -- --void HW_IPCC_MAC_802_15_4_CmdEvtNot(void) --{ -- TL_MAC_802_15_4_CmdEvtReceived( (TL_EvtPacket_t*)(TL_RefTable.p_mac_802_15_4_table->p_cmdrsp_buffer) ); -- -- return; --} -- --void HW_IPCC_MAC_802_15_4_EvtNot( void ) --{ -- TL_MAC_802_15_4_NotReceived( (TL_EvtPacket_t*)(TL_RefTable.p_mac_802_15_4_table->p_notack_buffer) ); -- -- return; --} -- --__WEAK void TL_MAC_802_15_4_CmdEvtReceived( TL_EvtPacket_t * Otbuffer ){}; --__WEAK void TL_MAC_802_15_4_NotReceived( TL_EvtPacket_t * Notbuffer ){}; --#endif -- --#ifdef ZIGBEE_WB --/****************************************************************************** -- * ZIGBEE -- ******************************************************************************/ --void TL_ZIGBEE_Init( TL_ZIGBEE_Config_t *p_Config ) --{ -- MB_ZigbeeTable_t * p_zigbee_table; -- -- p_zigbee_table = TL_RefTable.p_zigbee_table; -- p_zigbee_table->appliCmdM4toM0_buffer = p_Config->p_ZigbeeOtCmdRspBuffer; -- p_zigbee_table->notifM0toM4_buffer = p_Config->p_ZigbeeNotAckBuffer; -- p_zigbee_table->requestM0toM4_buffer = p_Config->p_ZigbeeNotifRequestBuffer; -- -- HW_IPCC_ZIGBEE_Init(); -- -- return; --} -- --/* Zigbee M4 to M0 Request */ --void TL_ZIGBEE_SendM4RequestToM0( void ) --{ -- ((TL_CmdPacket_t *)(TL_RefTable.p_zigbee_table->appliCmdM4toM0_buffer))->cmdserial.type = TL_OTCMD_PKT_TYPE; -- -- HW_IPCC_ZIGBEE_SendM4RequestToM0(); -- -- return; --} -- --/* Used to receive an ACK from the M0 */ --void HW_IPCC_ZIGBEE_RecvAppliAckFromM0(void) --{ -- TL_ZIGBEE_CmdEvtReceived( (TL_EvtPacket_t*)(TL_RefTable.p_zigbee_table->appliCmdM4toM0_buffer) ); -- -- return; --} -- --/* Zigbee notification from M0 to M4 */ --void HW_IPCC_ZIGBEE_RecvM0NotifyToM4( void ) --{ -- TL_ZIGBEE_NotReceived( (TL_EvtPacket_t*)(TL_RefTable.p_zigbee_table->notifM0toM4_buffer) ); -- -- return; --} -- --/* Send an ACK to the M0 for a Notification */ --void TL_ZIGBEE_SendM4AckToM0Notify ( void ) --{ -- ((TL_CmdPacket_t *)(TL_RefTable.p_zigbee_table->notifM0toM4_buffer))->cmdserial.type = TL_OTACK_PKT_TYPE; -- -- HW_IPCC_ZIGBEE_SendM4AckToM0Notify(); -- -- return; --} -- --/* Zigbee M0 to M4 Request */ --void HW_IPCC_ZIGBEE_RecvM0RequestToM4( void ) --{ -- TL_ZIGBEE_M0RequestReceived( (TL_EvtPacket_t*)(TL_RefTable.p_zigbee_table->requestM0toM4_buffer) ); -- -- return; --} -- --/* Send an ACK to the M0 for a Request */ --void TL_ZIGBEE_SendM4AckToM0Request(void) --{ -- ((TL_CmdPacket_t *)(TL_RefTable.p_zigbee_table->requestM0toM4_buffer))->cmdserial.type = TL_OTACK_PKT_TYPE; -- -- HW_IPCC_ZIGBEE_SendM4AckToM0Request(); -- -- return; --} -- -- --__WEAK void TL_ZIGBEE_CmdEvtReceived( TL_EvtPacket_t * Otbuffer ){}; --__WEAK void TL_ZIGBEE_NotReceived( TL_EvtPacket_t * Notbuffer ){}; --#endif -- -- -- - /****************************************************************************** - * MEMORY MANAGER - ******************************************************************************/ -@@ -846,3 +710,4 @@ static void OutputDbgTrace(TL_MB_PacketType_t packet_type, uint8_t* buffer) - - return; - } -+#endif /* STM32WBxx */ --- -2.38.0.windows.1 - diff --git a/extras/STM32Cube_FW/0002-fix-include-a-timeout-when-waiting-for-the-cmd_resp.patch b/extras/STM32Cube_FW/0002-fix-include-a-timeout-when-waiting-for-the-cmd_resp.patch index 81ac67fd..feeef35a 100644 --- a/extras/STM32Cube_FW/0002-fix-include-a-timeout-when-waiting-for-the-cmd_resp.patch +++ b/extras/STM32Cube_FW/0002-fix-include-a-timeout-when-waiting-for-the-cmd_resp.patch @@ -1,15 +1,15 @@ -From a3c689a99506126587dfd7285c4b198db4a790e5 Mon Sep 17 00:00:00 2001 +From 12683bb7a3f0b0ad1e10400cba0e3694f9b9ee95 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Mon, 12 Dec 2022 17:17:48 +0100 -Subject: [PATCH 2/3] fix: include a timeout when waiting for the cmd_resp +Subject: [PATCH 2/4] fix: include a timeout when waiting for the cmd_resp Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- - src/utility/STM32Cube_FW/shci_tl.c | 9 ++++++--- - 1 file changed, 6 insertions(+), 3 deletions(-) + src/utility/STM32Cube_FW/shci_tl.c | 10 ++++++---- + 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/utility/STM32Cube_FW/shci_tl.c b/src/utility/STM32Cube_FW/shci_tl.c -index b3cee00..1abd1be 100644 +index a336aa6..d1d35f5 100644 --- a/src/utility/STM32Cube_FW/shci_tl.c +++ b/src/utility/STM32Cube_FW/shci_tl.c @@ -23,6 +23,7 @@ @@ -20,7 +20,7 @@ index b3cee00..1abd1be 100644 /* Private typedef -----------------------------------------------------------*/ typedef enum -@@ -234,10 +235,12 @@ static void TlUserEvtReceived(TL_EvtPacket_t *shcievt) +@@ -250,11 +251,12 @@ static void TlUserEvtReceived(TL_EvtPacket_t *shcievt) /* Weak implementation ----------------------------------------------------------------*/ __WEAK void shci_cmd_resp_wait(uint32_t timeout) { @@ -28,14 +28,15 @@ index b3cee00..1abd1be 100644 - CmdRspStatusFlag = SHCI_TL_CMD_RESP_WAIT; - while(CmdRspStatusFlag != SHCI_TL_CMD_RESP_RELEASE); +- + for (unsigned long start = millis(); (millis() - start) < timeout;) { + if (CmdRspStatusFlag == SHCI_TL_CMD_RESP_RELEASE) { + break; + } + } + return; } - __WEAK void shci_cmd_resp_release(uint32_t flag) -- 2.38.0.windows.1 diff --git a/extras/STM32Cube_FW/0003-chore-add-support-for-customize-app_conf_default.h.patch b/extras/STM32Cube_FW/0003-chore-add-support-for-customize-app_conf_default.h.patch index a10fa6e7..e2da2673 100644 --- a/extras/STM32Cube_FW/0003-chore-add-support-for-customize-app_conf_default.h.patch +++ b/extras/STM32Cube_FW/0003-chore-add-support-for-customize-app_conf_default.h.patch @@ -1,18 +1,18 @@ -From 81472cc135126cb46701a058647de2cf82160fb9 Mon Sep 17 00:00:00 2001 +From 8575588fedd55cf7238a1a810708100e700e57c0 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Mon, 12 Dec 2022 17:29:27 +0100 -Subject: [PATCH 3/3] chore: add support for customize app_conf_default.h +Subject: [PATCH 3/4] chore: add support for customize app_conf_default.h Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- - src/utility/STM32Cube_FW/app_conf_default.h | 88 ++++++++++++++++----- - 1 file changed, 68 insertions(+), 20 deletions(-) + src/utility/STM32Cube_FW/app_conf_default.h | 86 ++++++++++++++++----- + 1 file changed, 68 insertions(+), 18 deletions(-) diff --git a/src/utility/STM32Cube_FW/app_conf_default.h b/src/utility/STM32Cube_FW/app_conf_default.h -index cc8c3e8..35cad34 100644 +index e89df14..1f17900 100644 --- a/src/utility/STM32Cube_FW/app_conf_default.h +++ b/src/utility/STM32Cube_FW/app_conf_default.h -@@ -41,7 +41,9 @@ +@@ -48,7 +48,9 @@ /** * Define Tx Power */ @@ -21,9 +21,9 @@ index cc8c3e8..35cad34 100644 + #define CFG_TX_POWER (0x18) /* -0.15dBm */ +#endif - /****************************************************************************** - * BLE Stack -@@ -50,13 +52,25 @@ + #if 0 + /** +@@ -132,13 +134,25 @@ * Maximum number of simultaneous connections that the device will support. * Valid values are from 1 to 8 */ @@ -51,7 +51,7 @@ index cc8c3e8..35cad34 100644 /** * Maximum number of Attributes -@@ -65,13 +79,21 @@ +@@ -147,13 +161,21 @@ * Note that certain characteristics and relative descriptors are added automatically during device initialization * so this parameters should be 9 plus the number of user Attributes */ @@ -75,7 +75,7 @@ index cc8c3e8..35cad34 100644 /** * Size of the storage area for Attribute values -@@ -84,14 +106,22 @@ +@@ -166,14 +188,22 @@ * The total amount of memory needed is the sum of the above quantities for each attribute. * This parameter is ignored by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set */ @@ -100,7 +100,7 @@ index cc8c3e8..35cad34 100644 /** * Number of allocated memory blocks -@@ -103,12 +133,16 @@ +@@ -185,12 +215,16 @@ /** * Enable or disable the Extended Packet length feature. Valid values are 0 or 1. */ @@ -119,7 +119,7 @@ index cc8c3e8..35cad34 100644 /** * Sleep clock accuracy in Master mode -@@ -121,7 +155,9 @@ +@@ -203,7 +237,9 @@ * 6 : 21 ppm to 30 ppm * 7 : 0 ppm to 20 ppm */ @@ -130,7 +130,7 @@ index cc8c3e8..35cad34 100644 /** * LsSource -@@ -130,21 +166,27 @@ +@@ -212,21 +248,27 @@ * - bit 1: 1: STM32WB5M Module device 0: Other devices as STM32WBxx SOC, STM32WB1M module * - bit 2: 1: HSE/1024 Clock config 0: LSE Clock config */ @@ -164,11 +164,10 @@ index cc8c3e8..35cad34 100644 /** * Viterbi Mode -@@ -224,8 +266,11 @@ - * on Max Extended advertising configuration supported. +@@ -314,7 +356,11 @@ * This parameter is considered by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV flag set */ -- + -#define CFG_BLE_MAX_ADV_SET_NBR (8) +#if defined(STM32WB15xx) + #define CFG_BLE_MAX_ADV_SET_NBR (3) @@ -178,11 +177,10 @@ index cc8c3e8..35cad34 100644 /* Maximum advertising data length (in bytes) * Range: 31 .. 1650 with limitation: -@@ -233,8 +278,11 @@ - * on Max Extended advertising configuration supported. +@@ -323,7 +369,11 @@ * This parameter is considered by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV flag set */ -- + -#define CFG_BLE_MAX_ADV_DATA_LEN (207) +#if defined(STM32WB15xx) + #define CFG_BLE_MAX_ADV_DATA_LEN (414) diff --git a/extras/STM32Cube_FW/0004-fix-warning-outside-array-bounds.patch b/extras/STM32Cube_FW/0004-fix-warning-outside-array-bounds.patch new file mode 100644 index 00000000..ae4aed42 --- /dev/null +++ b/extras/STM32Cube_FW/0004-fix-warning-outside-array-bounds.patch @@ -0,0 +1,304 @@ +From 64caac5c39a47cac4ab840ba975bca065aa40efa Mon Sep 17 00:00:00 2001 +From: Frederic Pillon <frederic.pillon@st.com> +Date: Wed, 8 Feb 2023 16:50:46 +0100 +Subject: [PATCH 4/4] fix: warning outside array bounds + +array subscript 'TL_CcEvt_t[0]' is partly outside array bounds + +Signed-off-by: Frederic Pillon <frederic.pillon@st.com> +--- + src/utility/STM32Cube_FW/shci.c | 60 ++++++++++++++++----------------- + src/utility/STM32Cube_FW/tl.h | 3 ++ + 2 files changed, 33 insertions(+), 30 deletions(-) + +diff --git a/src/utility/STM32Cube_FW/shci.c b/src/utility/STM32Cube_FW/shci.c +index cb7d7bd..6348145 100644 +--- a/src/utility/STM32Cube_FW/shci.c ++++ b/src/utility/STM32Cube_FW/shci.c +@@ -42,7 +42,7 @@ uint8_t SHCI_C2_FUS_GetState( SHCI_FUS_GetState_ErrorCode_t *p_error_code ) + /** + * A command status event + payload has the same size than the expected command complete + */ +- uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE + 1]; ++ uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; +@@ -66,7 +66,7 @@ SHCI_CmdStatus_t SHCI_C2_FUS_FwUpgrade( uint32_t fw_src_add, uint32_t fw_dest_a + * TL_BLEEVT_CS_BUFFER_SIZE is 15 bytes so it is large enough to hold the 8 bytes of command parameters + * Buffer is large enough to hold command complete without payload + */ +- uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; ++ uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + uint32_t *p_cmd; + uint8_t cmd_length; +@@ -101,7 +101,7 @@ SHCI_CmdStatus_t SHCI_C2_FUS_FwDelete( void ) + /** + * Buffer is large enough to hold command complete without payload + */ +- uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; ++ uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; +@@ -119,7 +119,7 @@ SHCI_CmdStatus_t SHCI_C2_FUS_UpdateAuthKey( SHCI_C2_FUS_UpdateAuthKey_Cmd_Param_ + /** + * Buffer is large enough to hold command complete without payload + */ +- uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; ++ uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; +@@ -137,7 +137,7 @@ SHCI_CmdStatus_t SHCI_C2_FUS_LockAuthKey( void ) + /** + * Buffer is large enough to hold command complete without payload + */ +- uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; ++ uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; +@@ -155,7 +155,7 @@ SHCI_CmdStatus_t SHCI_C2_FUS_StoreUsrKey( SHCI_C2_FUS_StoreUsrKey_Cmd_Param_t *p + /** + * Buffer is large enough to hold command complete without payload + */ +- uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE + 1]; ++ uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + uint8_t local_payload_len; + +@@ -189,7 +189,7 @@ SHCI_CmdStatus_t SHCI_C2_FUS_LoadUsrKey( uint8_t key_index ) + /** + * Buffer is large enough to hold command complete without payload + */ +- uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; ++ uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; +@@ -209,7 +209,7 @@ SHCI_CmdStatus_t SHCI_C2_FUS_StartWs( void ) + /** + * Buffer is large enough to hold command complete without payload + */ +- uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; ++ uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; +@@ -227,7 +227,7 @@ SHCI_CmdStatus_t SHCI_C2_FUS_LockUsrKey( uint8_t key_index ) + /** + * Buffer is large enough to hold command complete without payload + */ +- uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; ++ uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; +@@ -247,7 +247,7 @@ SHCI_CmdStatus_t SHCI_C2_FUS_UnloadUsrKey( uint8_t key_index ) + /** + * Buffer is large enough to hold command complete without payload + */ +- uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; ++ uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; +@@ -267,7 +267,7 @@ SHCI_CmdStatus_t SHCI_C2_FUS_ActivateAntiRollback( void ) + /** + * Buffer is large enough to hold command complete without payload + */ +- uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; ++ uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; +@@ -285,7 +285,7 @@ SHCI_CmdStatus_t SHCI_C2_BLE_Init( SHCI_C2_Ble_Init_Cmd_Packet_t *pCmdPacket ) + /** + * Buffer is large enough to hold command complete without payload + */ +- uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; ++ uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; +@@ -303,7 +303,7 @@ SHCI_CmdStatus_t SHCI_C2_THREAD_Init( void ) + /** + * Buffer is large enough to hold command complete without payload + */ +- uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; ++ uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; +@@ -321,7 +321,7 @@ SHCI_CmdStatus_t SHCI_C2_LLDTESTS_Init( uint8_t param_size, uint8_t * p_param ) + /** + * Buffer is large enough to hold command complete without payload + */ +- uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; ++ uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; +@@ -339,7 +339,7 @@ SHCI_CmdStatus_t SHCI_C2_BLE_LLD_Init( uint8_t param_size, uint8_t * p_param ) + /** + * Buffer is large enough to hold command complete without payload + */ +- uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; ++ uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; +@@ -357,7 +357,7 @@ SHCI_CmdStatus_t SHCI_C2_ZIGBEE_Init( void ) + /** + * Buffer is large enough to hold command complete without payload + */ +- uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; ++ uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; +@@ -375,7 +375,7 @@ SHCI_CmdStatus_t SHCI_C2_DEBUG_Init( SHCI_C2_DEBUG_Init_Cmd_Packet_t *pCmdPacket + /** + * Buffer is large enough to hold command complete without payload + */ +- uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; ++ uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; +@@ -393,7 +393,7 @@ SHCI_CmdStatus_t SHCI_C2_FLASH_EraseActivity( SHCI_EraseActivity_t erase_activit + /** + * Buffer is large enough to hold command complete without payload + */ +- uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; ++ uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; +@@ -413,7 +413,7 @@ SHCI_CmdStatus_t SHCI_C2_CONCURRENT_SetMode( SHCI_C2_CONCURRENT_Mode_Param_t Mod + /** + * Buffer is large enough to hold command complete without payload + */ +- uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; ++ uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; +@@ -433,7 +433,7 @@ SHCI_CmdStatus_t SHCI_C2_CONCURRENT_GetNextBleEvtTime( SHCI_C2_CONCURRENT_GetNex + /** + * Buffer is large enough to hold command complete without payload + */ +- uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE+4]; ++ uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; +@@ -453,7 +453,7 @@ SHCI_CmdStatus_t SHCI_C2_CONCURRENT_EnableNext_802154_EvtNotification( void ) + /** + * Buffer is large enough to hold command complete without payload + */ +- uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; ++ uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; +@@ -471,7 +471,7 @@ SHCI_CmdStatus_t SHCI_C2_FLASH_StoreData( SHCI_C2_FLASH_Ip_t Ip ) + /** + * Buffer is large enough to hold command complete without payload + */ +- uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; ++ uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; +@@ -491,7 +491,7 @@ SHCI_CmdStatus_t SHCI_C2_FLASH_EraseData( SHCI_C2_FLASH_Ip_t Ip ) + /** + * Buffer is large enough to hold command complete without payload + */ +- uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; ++ uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; +@@ -511,7 +511,7 @@ SHCI_CmdStatus_t SHCI_C2_RADIO_AllowLowPower( SHCI_C2_FLASH_Ip_t Ip,uint8_t Fla + /** + * Buffer is large enough to hold command complete without payload + */ +- uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; ++ uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; +@@ -532,7 +532,7 @@ SHCI_CmdStatus_t SHCI_C2_MAC_802_15_4_Init( void ) + /** + * Buffer is large enough to hold command complete without payload + */ +- uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; ++ uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; +@@ -550,7 +550,7 @@ SHCI_CmdStatus_t SHCI_C2_Reinit( void ) + /** + * Buffer is large enough to hold command complete without payload + */ +- uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; ++ uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; +@@ -569,7 +569,7 @@ SHCI_CmdStatus_t SHCI_C2_ExtpaConfig(uint32_t gpio_port, uint16_t gpio_pin_numbe + * TL_BLEEVT_CS_BUFFER_SIZE is 15 bytes so it is large enough to hold the 8 bytes of command parameters + * Buffer is large enough to hold command complete without payload + */ +- uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; ++ uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; +@@ -593,7 +593,7 @@ SHCI_CmdStatus_t SHCI_C2_SetFlashActivityControl(SHCI_C2_SET_FLASH_ACTIVITY_CONT + * TL_BLEEVT_CS_BUFFER_SIZE is 15 bytes so it is large enough to hold the 1 byte of command parameter + * Buffer is large enough to hold command complete without payload + */ +- uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; ++ uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; +@@ -613,7 +613,7 @@ SHCI_CmdStatus_t SHCI_C2_Config(SHCI_C2_CONFIG_Cmd_Param_t *pCmdPacket) + /** + * Buffer is large enough to hold command complete without payload + */ +- uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; ++ uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; +@@ -631,7 +631,7 @@ SHCI_CmdStatus_t SHCI_C2_802_15_4_DeInit( void ) + /** + * Buffer is large enough to hold command complete without payload + */ +- uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; ++ uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; +diff --git a/src/utility/STM32Cube_FW/tl.h b/src/utility/STM32Cube_FW/tl.h +index 6bfa265..63126b3 100644 +--- a/src/utility/STM32Cube_FW/tl.h ++++ b/src/utility/STM32Cube_FW/tl.h +@@ -61,6 +61,9 @@ extern "C" { + #define TL_BLEEVT_CS_PACKET_SIZE (TL_EVT_HDR_SIZE + sizeof(TL_CsEvt_t)) + #define TL_BLEEVT_CS_BUFFER_SIZE (sizeof(TL_PacketHeader_t) + TL_BLEEVT_CS_PACKET_SIZE) + ++#define TL_BLEEVT_CC_PACKET_SIZE (TL_EVT_HDR_SIZE + sizeof(TL_CcEvt_t)) ++#define TL_BLEEVT_CC_BUFFER_SIZE (sizeof(TL_PacketHeader_t) + TL_BLEEVT_CC_PACKET_SIZE) ++ + /* Exported types ------------------------------------------------------------*/ + /**< Packet header */ + typedef PACKED_STRUCT +-- +2.38.0.windows.1 + From a903124433f4caacb07997a4856cfc4fc71948f8 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Wed, 5 Apr 2023 14:37:41 +0200 Subject: [PATCH 128/226] chore: update STM32Cube_FW from Cube version v1.16.0 Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- src/utility/STM32Cube_FW/README.md | 4 +- src/utility/STM32Cube_FW/app_conf_default.h | 544 +++++++++++++++---- src/utility/STM32Cube_FW/ble_bufsize.h | 15 +- src/utility/STM32Cube_FW/hw.h | 28 +- src/utility/STM32Cube_FW/hw_ipcc.c | 218 +++++++- src/utility/STM32Cube_FW/mbox_def.h | 34 ++ src/utility/STM32Cube_FW/shci.c | 95 +++- src/utility/STM32Cube_FW/shci.h | 76 ++- src/utility/STM32Cube_FW/shci_tl.c | 45 +- src/utility/STM32Cube_FW/stm32_wpan_common.h | 39 +- src/utility/STM32Cube_FW/stm_list.c | 15 +- src/utility/STM32Cube_FW/stm_list.h | 4 +- src/utility/STM32Cube_FW/tl.h | 73 ++- src/utility/STM32Cube_FW/tl_mbox.c | 145 ++++- 14 files changed, 1125 insertions(+), 210 deletions(-) diff --git a/src/utility/STM32Cube_FW/README.md b/src/utility/STM32Cube_FW/README.md index 69041d4c..780e2706 100644 --- a/src/utility/STM32Cube_FW/README.md +++ b/src/utility/STM32Cube_FW/README.md @@ -1,6 +1,6 @@ ## Source -[STMicroelectronics/STM32CubeWB Release vv1.15.0](https://github.com/STMicroelectronics/STM32CubeWB/releases/tag/vv1.15.0) -- Application: [BLE_TransparentMode](https://github.com/STMicroelectronics/STM32CubeWB/tree/vv1.15.0/Projects/P-NUCLEO-WB55.Nucleo/Applications/BLE/BLE_TransparentMode) +[STMicroelectronics/STM32CubeWB Release vvv1.16.0](https://github.com/STMicroelectronics/STM32CubeWB/releases/tag/vvv1.16.0) +- Application: [BLE_TransparentMode](https://github.com/STMicroelectronics/STM32CubeWB/tree/vvv1.16.0/Projects/P-NUCLEO-WB55.Nucleo/Applications/BLE/BLE_TransparentMode) diff --git a/src/utility/STM32Cube_FW/app_conf_default.h b/src/utility/STM32Cube_FW/app_conf_default.h index 35cad34f..51bd33af 100644 --- a/src/utility/STM32Cube_FW/app_conf_default.h +++ b/src/utility/STM32Cube_FW/app_conf_default.h @@ -1,8 +1,9 @@ +/* USER CODE BEGIN Header */ /** ****************************************************************************** - * @file app_conf_default.h + * @file app_conf.h * @author MCD Application Team - * @brief Default application configuration file for STM32WPAN Middleware. + * @brief Application configuration file for STM32WPAN Middleware. ****************************************************************************** * @attention * @@ -15,35 +16,94 @@ * ****************************************************************************** */ +/* USER CODE END Header */ /* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef APP_CONF_DEFAULT_H -#define APP_CONF_DEFAULT_H +#ifndef APP_CONF_H +#define APP_CONF_H + +#include "hw.h" +#include "hw_conf.h" +#include "hw_if.h" +#include "ble_bufsize.h" /****************************************************************************** * Application Config ******************************************************************************/ -/**< generic parameters ******************************************************/ -/* HCI related defines */ +/** + * Define Secure Connections Support + */ +#define CFG_SECURE_NOT_SUPPORTED (0x00) +#define CFG_SECURE_OPTIONAL (0x01) +#define CFG_SECURE_MANDATORY (0x02) -#define ACI_HAL_SET_TX_POWER_LEVEL 0xFC0F -#define ACI_WRITE_CONFIG_DATA_OPCODE 0xFC0C -#define ACI_READ_CONFIG_DATA_OPCODE 0xFC0D -#define MAX_HCI_ACL_PACKET_SIZE (sizeof(TL_PacketHeader_t) + 5 + 251) -#define HCI_RESET 0x0C03 +#define CFG_SC_SUPPORT CFG_SECURE_OPTIONAL -#ifndef BLE_SHARED_MEM_BYTE_ORDER - #define BLE_SHARED_MEM_BYTE_ORDER MSBFIRST -#endif -#define BLE_MODULE_SHARED_MEM_BUFFER_SIZE 128 +/** + * Define Keypress Notification Support + */ +#define CFG_KEYPRESS_NOT_SUPPORTED (0x00) +#define CFG_KEYPRESS_SUPPORTED (0x01) + +#define CFG_KEYPRESS_NOTIFICATION_SUPPORT CFG_KEYPRESS_NOT_SUPPORTED /** - * Define Tx Power + * Numeric Comparison Answers */ -#ifndef CFG_TX_POWER - #define CFG_TX_POWER (0x18) /* -0.15dBm */ -#endif +#define YES (0x01) +#define NO (0x00) + +/** + * Device name configuration for Generic Access Service + */ +#define CFG_GAP_DEVICE_NAME "TEMPLATE" +#define CFG_GAP_DEVICE_NAME_LENGTH (8) + +/** +* Identity root key used to derive LTK and CSRK +*/ +#define CFG_BLE_IRK {0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0} + +/** +* Encryption root key used to derive LTK and CSRK +*/ +#define CFG_BLE_ERK {0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21, 0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21} + +/** + * SMPS supply + * SMPS not used when Set to 0 + * SMPS used when Set to 1 + */ +#define CFG_USE_SMPS 0 + +/* USER CODE BEGIN Generic_Parameters */ +/* USER CODE END Generic_Parameters */ + +/**< specific parameters */ +/*****************************************************/ + +/* USER CODE BEGIN Specific_Parameters */ +#define PUSH_BUTTON_SW1_EXTI_IRQHandler EXTI4_IRQHandler + +/* USER CODE END Specific_Parameters */ + +/****************************************************************************** + * Information Table + * + * Version + * [0:3] = Build - 0: Untracked - 15:Released - x: Tracked version + * [4:7] = branch - 0: Mass Market - x: ... + * [8:15] = Subversion + * [16:23] = Version minor + * [24:31] = Version major + * + ******************************************************************************/ +#define CFG_FW_MAJOR_VERSION (0) +#define CFG_FW_MINOR_VERSION (0) +#define CFG_FW_SUBVERSION (1) +#define CFG_FW_BRANCH (0) +#define CFG_FW_BUILD (0) /****************************************************************************** * BLE Stack @@ -52,25 +112,13 @@ * Maximum number of simultaneous connections that the device will support. * Valid values are from 1 to 8 */ -#ifndef CFG_BLE_NUM_LINK -#ifdef STM32WB15xx - #define CFG_BLE_NUM_LINK 3 -#else - #define CFG_BLE_NUM_LINK 8 -#endif -#endif +#define CFG_BLE_NUM_LINK 8 /** * Maximum number of Services that can be stored in the GATT database. * Note that the GAP and GATT services are automatically added so this parameter should be 2 plus the number of user services */ -#ifndef CFG_BLE_NUM_GATT_SERVICES -#ifdef STM32WB15xx - #define CFG_BLE_NUM_GATT_SERVICES 4 -#else - #define CFG_BLE_NUM_GATT_SERVICES 8 -#endif -#endif +#define CFG_BLE_NUM_GATT_SERVICES 8 /** * Maximum number of Attributes @@ -79,21 +127,13 @@ * Note that certain characteristics and relative descriptors are added automatically during device initialization * so this parameters should be 9 plus the number of user Attributes */ -#ifndef CFG_BLE_NUM_GATT_ATTRIBUTES -#ifdef STM32WB15xx - #define CFG_BLE_NUM_GATT_ATTRIBUTES 30 -#else - #define CFG_BLE_NUM_GATT_ATTRIBUTES 68 -#endif -#endif +#define CFG_BLE_NUM_GATT_ATTRIBUTES 68 /** * Maximum supported ATT_MTU size * This parameter is ignored by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set */ -#ifndef CFG_BLE_MAX_ATT_MTU - #define CFG_BLE_MAX_ATT_MTU (156) -#endif +#define CFG_BLE_MAX_ATT_MTU (156) /** * Size of the storage area for Attribute values @@ -106,43 +146,29 @@ * The total amount of memory needed is the sum of the above quantities for each attribute. * This parameter is ignored by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set */ -#ifndef CFG_BLE_ATT_VALUE_ARRAY_SIZE -#ifdef STM32WB15xx - #define CFG_BLE_ATT_VALUE_ARRAY_SIZE (1290) -#else - #define CFG_BLE_ATT_VALUE_ARRAY_SIZE (1344) -#endif -#endif +#define CFG_BLE_ATT_VALUE_ARRAY_SIZE (1344) /** * Prepare Write List size in terms of number of packet * This parameter is ignored by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set */ -// #define CFG_BLE_PREPARE_WRITE_LIST_SIZE BLE_PREP_WRITE_X_ATT(CFG_BLE_MAX_ATT_MTU) -#ifndef CFG_BLE_PREPARE_WRITE_LIST_SIZE - #define CFG_BLE_PREPARE_WRITE_LIST_SIZE (0x3A) -#endif +#define CFG_BLE_PREPARE_WRITE_LIST_SIZE BLE_PREP_WRITE_X_ATT(CFG_BLE_MAX_ATT_MTU) /** * Number of allocated memory blocks * This parameter is overwritten by the CPU2 with an hardcoded optimal value when the parameter CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set */ -// #define CFG_BLE_MBLOCK_COUNT (BLE_MBLOCKS_CALC(CFG_BLE_PREPARE_WRITE_LIST_SIZE, CFG_BLE_MAX_ATT_MTU, CFG_BLE_NUM_LINK)) -#define CFG_BLE_MBLOCK_COUNT (0x79) +#define CFG_BLE_MBLOCK_COUNT (BLE_MBLOCKS_CALC(CFG_BLE_PREPARE_WRITE_LIST_SIZE, CFG_BLE_MAX_ATT_MTU, CFG_BLE_NUM_LINK)) /** * Enable or disable the Extended Packet length feature. Valid values are 0 or 1. */ -#ifndef CFG_BLE_DATA_LENGTH_EXTENSION - #define CFG_BLE_DATA_LENGTH_EXTENSION 1 -#endif +#define CFG_BLE_DATA_LENGTH_EXTENSION 1 /** * Sleep clock accuracy in Slave mode (ppm value) */ -#ifndef CFG_BLE_SLAVE_SCA - #define CFG_BLE_SLAVE_SCA 500 -#endif +#define CFG_BLE_SLAVE_SCA 500 /** * Sleep clock accuracy in Master mode @@ -155,9 +181,7 @@ * 6 : 21 ppm to 30 ppm * 7 : 0 ppm to 20 ppm */ -#ifndef CFG_BLE_MASTER_SCA - #define CFG_BLE_MASTER_SCA 0 -#endif +#define CFG_BLE_MASTER_SCA 0 /** * LsSource @@ -166,27 +190,21 @@ * - bit 1: 1: STM32WB5M Module device 0: Other devices as STM32WBxx SOC, STM32WB1M module * - bit 2: 1: HSE/1024 Clock config 0: LSE Clock config */ -#ifndef CFG_BLE_LS_SOURCE - #if defined(STM32WB5Mxx) - #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_MOD5MM_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) - #else - #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_OTHER_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) - #endif +#if defined(STM32WB5Mxx) + #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_MOD5MM_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) +#else + #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_OTHER_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) #endif /** * Start up time of the high speed (16 or 32 MHz) crystal oscillator in units of 625/256 us (~2.44 us) */ -#ifndef CFG_BLE_HSE_STARTUP_TIME - #define CFG_BLE_HSE_STARTUP_TIME 0x148 -#endif +#define CFG_BLE_HSE_STARTUP_TIME 0x148 /** * Maximum duration of the connection event when the device is in Slave mode in units of 625/256 us (~2.44 us) */ -#ifndef CFG_BLE_MAX_CONN_EVENT_LENGTH - #define CFG_BLE_MAX_CONN_EVENT_LENGTH (0xFFFFFFFF) -#endif +#define CFG_BLE_MAX_CONN_EVENT_LENGTH (0xFFFFFFFF) /** * Viterbi Mode @@ -213,10 +231,6 @@ * - SHCI_C2_BLE_INIT_OPTIONS_GATT_CACHING_NOTUSED * - SHCI_C2_BLE_INIT_OPTIONS_POWER_CLASS_1 * - SHCI_C2_BLE_INIT_OPTIONS_POWER_CLASS_2_3 - * - SHCI_C2_BLE_INIT_OPTIONS_APPEARANCE_WRITABLE - * - SHCI_C2_BLE_INIT_OPTIONS_APPEARANCE_READONLY - * - SHCI_C2_BLE_INIT_OPTIONS_ENHANCED_ATT_SUPPORTED - * - SHCI_C2_BLE_INIT_OPTIONS_ENHANCED_ATT_NOTSUPPORTED * which are used to set following configuration bits: * (bit 0): 1: LL only * 0: LL + host @@ -234,13 +248,24 @@ * 0: GATT caching is not used * (bit 7): 1: LE Power Class 1 * 0: LE Power Class 2-3 - * (bit 8): 1: appearance Writable + * other bits: complete with Options_extension flag + */ +#define CFG_BLE_OPTIONS (SHCI_C2_BLE_INIT_OPTIONS_LL_HOST | SHCI_C2_BLE_INIT_OPTIONS_WITH_SVC_CHANGE_DESC | SHCI_C2_BLE_INIT_OPTIONS_DEVICE_NAME_RW | SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV | SHCI_C2_BLE_INIT_OPTIONS_CS_ALGO2 | SHCI_C2_BLE_INIT_OPTIONS_FULL_GATTDB_NVM | SHCI_C2_BLE_INIT_OPTIONS_GATT_CACHING_NOTUSED | SHCI_C2_BLE_INIT_OPTIONS_POWER_CLASS_2_3) + +/** + * BLE stack Options_extension flags to be configured with: + * - SHCI_C2_BLE_INIT_OPTIONS_APPEARANCE_WRITABLE + * - SHCI_C2_BLE_INIT_OPTIONS_APPEARANCE_READONLY + * - SHCI_C2_BLE_INIT_OPTIONS_ENHANCED_ATT_SUPPORTED + * - SHCI_C2_BLE_INIT_OPTIONS_ENHANCED_ATT_NOTSUPPORTED + * which are used to set following configuration bits: + * (bit 0): 1: appearance Writable * 0: appearance Read-Only - * (bit 9): 1: Enhanced ATT supported + * (bit 1): 1: Enhanced ATT supported * 0: Enhanced ATT not supported * other bits: reserved (shall be set to 0) */ -#define CFG_BLE_OPTIONS (SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY) +#define CFG_BLE_OPTIONS_EXT (SHCI_C2_BLE_INIT_OPTIONS_APPEARANCE_READONLY | SHCI_C2_BLE_INIT_OPTIONS_ENHANCED_ATT_NOTSUPPORTED) #define CFG_BLE_MAX_COC_INITIATOR_NBR (32) @@ -266,11 +291,8 @@ * on Max Extended advertising configuration supported. * This parameter is considered by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV flag set */ -#if defined(STM32WB15xx) - #define CFG_BLE_MAX_ADV_SET_NBR (3) -#else - #define CFG_BLE_MAX_ADV_SET_NBR (8) -#endif + +#define CFG_BLE_MAX_ADV_SET_NBR (8) /* Maximum advertising data length (in bytes) * Range: 31 .. 1650 with limitation: @@ -278,11 +300,8 @@ * on Max Extended advertising configuration supported. * This parameter is considered by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV flag set */ -#if defined(STM32WB15xx) - #define CFG_BLE_MAX_ADV_DATA_LEN (414) -#else - #define CFG_BLE_MAX_ADV_DATA_LEN (207) -#endif + +#define CFG_BLE_MAX_ADV_DATA_LEN (207) /* RF TX Path Compensation Value (16-bit signed integer). Units: 0.1 dB. * Range: -1280 .. 1280 @@ -304,4 +323,339 @@ #define CFG_BLE_CORE_VERSION (SHCI_C2_BLE_INIT_BLE_CORE_5_3) -#endif /* APP_CONF_DEFAULT_H */ +/****************************************************************************** + * Transport Layer + ******************************************************************************/ +/** + * Queue length of BLE Event + * This parameter defines the number of asynchronous events that can be stored in the HCI layer before + * being reported to the application. When a command is sent to the BLE core coprocessor, the HCI layer + * is waiting for the event with the Num_HCI_Command_Packets set to 1. The receive queue shall be large + * enough to store all asynchronous events received in between. + * When CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE is set to 27, this allow to store three 255 bytes long asynchronous events + * between the HCI command and its event. + * This parameter depends on the value given to CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE. When the queue size is to small, + * the system may hang if the queue is full with asynchronous events and the HCI layer is still waiting + * for a CC/CS event, In that case, the notification TL_BLE_HCI_ToNot() is called to indicate + * to the application a HCI command did not receive its command event within 30s (Default HCI Timeout). + */ +#define CFG_TLBLE_EVT_QUEUE_LENGTH 5 +/** + * This parameter should be set to fit most events received by the HCI layer. It defines the buffer size of each element + * allocated in the queue of received events and can be used to optimize the amount of RAM allocated by the Memory Manager. + * It should not exceed 255 which is the maximum HCI packet payload size (a greater value is a lost of memory as it will + * never be used) + * It shall be at least 4 to receive the command status event in one frame. + * The default value is set to 27 to allow receiving an event of MTU size in a single buffer. This value maybe reduced + * further depending on the application. + */ +#define CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE 255 /**< Set to 255 with the memory manager and the mailbox */ + +#define TL_BLE_EVENT_FRAME_SIZE ( TL_EVT_HDR_SIZE + CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE ) +/****************************************************************************** + * UART interfaces + ******************************************************************************/ + +/** + * Select UART interfaces + */ +#define CFG_UART_GUI hw_uart1 +#define CFG_DEBUG_TRACE_UART 0 +/****************************************************************************** + * USB interface + ******************************************************************************/ + +/** + * Enable/Disable USB interface + */ +#define CFG_USB_INTERFACE_ENABLE 0 + +/****************************************************************************** + * IPCC interface + ******************************************************************************/ + +/** + * The IPCC is dedicated to the communication between the CPU2 and the CPU1 + * and shall not be modified by the application + * The two following definitions shall not be modified + */ +#define HAL_IPCC_TX_IRQHandler(...) HW_IPCC_Tx_Handler( ) +#define HAL_IPCC_RX_IRQHandler(...) HW_IPCC_Rx_Handler( ) + +/****************************************************************************** + * Low Power + ******************************************************************************/ +/** + * When set to 1, the low power mode is enable + * When set to 0, the device stays in RUN mode + */ +#define CFG_LPM_SUPPORTED 1 + +/****************************************************************************** + * RTC interface + ******************************************************************************/ +#define HAL_RTCEx_WakeUpTimerIRQHandler(...) HW_TS_RTC_Wakeup_Handler( ) + +/****************************************************************************** + * Timer Server + ******************************************************************************/ +/** + * CFG_RTC_WUCKSEL_DIVIDER: This sets the RTCCLK divider to the wakeup timer. + * The lower is the value, the better is the power consumption and the accuracy of the timerserver + * The higher is the value, the finest is the granularity + * + * CFG_RTC_ASYNCH_PRESCALER: This sets the asynchronous prescaler of the RTC. It should as high as possible ( to output + * clock as low as possible) but the output clock should be equal or higher frequency compare to the clock feeding + * the wakeup timer. A lower clock speed would impact the accuracy of the timer server. + * + * CFG_RTC_SYNCH_PRESCALER: This sets the synchronous prescaler of the RTC. + * When the 1Hz calendar clock is required, it shall be sets according to other settings + * When the 1Hz calendar clock is not needed, CFG_RTC_SYNCH_PRESCALER should be set to 0x7FFF (MAX VALUE) + * + * CFG_RTCCLK_DIVIDER_CONF: + * Shall be set to either 0,2,4,8,16 + * When set to either 2,4,8,16, the 1Hhz calendar is supported + * When set to 0, the user sets its own configuration + * + * The following settings are computed with LSI as input to the RTC + */ + +#define CFG_RTCCLK_DIVIDER_CONF 0 + +#if (CFG_RTCCLK_DIVIDER_CONF == 0) +/** + * Custom configuration + * It does not support 1Hz calendar + * It divides the RTC CLK by 16 + */ + +#define CFG_RTCCLK_DIV (16) +#define CFG_RTC_WUCKSEL_DIVIDER (0) +#define CFG_RTC_ASYNCH_PRESCALER (0x0F) +#define CFG_RTC_SYNCH_PRESCALER (0x7FFF) + +#else + +#if (CFG_RTCCLK_DIVIDER_CONF == 2) +/** + * It divides the RTC CLK by 2 + */ +#define CFG_RTC_WUCKSEL_DIVIDER (3) +#endif + +#if (CFG_RTCCLK_DIVIDER_CONF == 4) +/** + * It divides the RTC CLK by 4 + */ +#define CFG_RTC_WUCKSEL_DIVIDER (2) +#endif + +#if (CFG_RTCCLK_DIVIDER_CONF == 8) +/** + * It divides the RTC CLK by 8 + */ +#define CFG_RTC_WUCKSEL_DIVIDER (1) +#endif + +#if (CFG_RTCCLK_DIVIDER_CONF == 16) +/** + * It divides the RTC CLK by 16 + */ +#define CFG_RTC_WUCKSEL_DIVIDER (0) +#endif + +#define CFG_RTCCLK_DIV CFG_RTCCLK_DIVIDER_CONF +#define CFG_RTC_ASYNCH_PRESCALER (CFG_RTCCLK_DIV - 1) +#define CFG_RTC_SYNCH_PRESCALER (DIVR( LSE_VALUE, (CFG_RTC_ASYNCH_PRESCALER+1) ) - 1 ) + +#endif + +/** tick timer values */ +#define CFG_TS_TICK_VAL DIVR( (CFG_RTCCLK_DIV * 1000000), LSE_VALUE ) +#define CFG_TS_TICK_VAL_PS DIVR( ((uint64_t)CFG_RTCCLK_DIV * 1e12), (uint64_t)LSE_VALUE ) + +typedef enum +{ + CFG_TIM_PROC_ID_ISR, + /* USER CODE BEGIN CFG_TimProcID_t */ + + /* USER CODE END CFG_TimProcID_t */ +} CFG_TimProcID_t; + +/****************************************************************************** + * Debug + ******************************************************************************/ +/** + * When set, this resets some hw resources to set the device in the same state than the power up + * The FW resets only register that may prevent the FW to run properly + * + * This shall be set to 0 in a final product + * + */ +#define CFG_HW_RESET_BY_FW 1 + +/** + * keep debugger enabled while in any low power mode when set to 1 + * should be set to 0 in production + */ +#define CFG_DEBUGGER_SUPPORTED 0 + +/** + * When set to 1, the traces are enabled in the BLE services + */ +#define CFG_DEBUG_BLE_TRACE 0 + +/** + * Enable or Disable traces in application + */ +#define CFG_DEBUG_APP_TRACE 0 + +#if (CFG_DEBUG_APP_TRACE != 0) +#define APP_DBG_MSG PRINT_MESG_DBG +#else +#define APP_DBG_MSG PRINT_NO_MESG +#endif + +#if ( (CFG_DEBUG_BLE_TRACE != 0) || (CFG_DEBUG_APP_TRACE != 0) ) +#define CFG_DEBUG_TRACE 1 +#endif + +#if (CFG_DEBUG_TRACE != 0) +#undef CFG_LPM_SUPPORTED +#undef CFG_DEBUGGER_SUPPORTED +#define CFG_LPM_SUPPORTED 0 +#define CFG_DEBUGGER_SUPPORTED 1 +#endif + +/** + * When CFG_DEBUG_TRACE_FULL is set to 1, the trace are output with the API name, the file name and the line number + * When CFG_DEBUG_TRACE_LIGHT is set to 1, only the debug message is output + * + * When both are set to 0, no trace are output + * When both are set to 1, CFG_DEBUG_TRACE_FULL is selected + */ +#define CFG_DEBUG_TRACE_LIGHT 0 +#define CFG_DEBUG_TRACE_FULL 0 + +#if (( CFG_DEBUG_TRACE != 0 ) && ( CFG_DEBUG_TRACE_LIGHT == 0 ) && (CFG_DEBUG_TRACE_FULL == 0)) +#undef CFG_DEBUG_TRACE_FULL +#undef CFG_DEBUG_TRACE_LIGHT +#define CFG_DEBUG_TRACE_FULL 0 +#define CFG_DEBUG_TRACE_LIGHT 1 +#endif + +#if ( CFG_DEBUG_TRACE == 0 ) +#undef CFG_DEBUG_TRACE_FULL +#undef CFG_DEBUG_TRACE_LIGHT +#define CFG_DEBUG_TRACE_FULL 0 +#define CFG_DEBUG_TRACE_LIGHT 0 +#endif + +/** + * When not set, the traces is looping on sending the trace over UART + */ +#define DBG_TRACE_USE_CIRCULAR_QUEUE 1 + +/** + * max buffer Size to queue data traces and max data trace allowed. + * Only Used if DBG_TRACE_USE_CIRCULAR_QUEUE is defined + */ +#define DBG_TRACE_MSG_QUEUE_SIZE 4096 +#define MAX_DBG_TRACE_MSG_SIZE 1024 + +/* USER CODE BEGIN Defines */ +#define CFG_LED_SUPPORTED 1 +#define CFG_BUTTON_SUPPORTED 1 + +#define PUSH_BUTTON_SW1_EXTI_IRQHandler EXTI4_IRQHandler +#define PUSH_BUTTON_SW2_EXTI_IRQHandler EXTI0_IRQHandler +#define PUSH_BUTTON_SW3_EXTI_IRQHandler EXTI1_IRQHandler +/* USER CODE END Defines */ + +/****************************************************************************** + * Scheduler + ******************************************************************************/ + +/** + * These are the lists of task id registered to the scheduler + * Each task id shall be in the range [0:31] + * This mechanism allows to implement a generic code in the API TL_BLE_HCI_StatusNot() to comply with + * the requirement that a HCI/ACI command shall never be sent if there is already one pending + */ + +/**< Add in that list all tasks that may send a ACI/HCI command */ +typedef enum +{ + CFG_TASK_BLE_HCI_CMD_ID, + CFG_TASK_SYS_HCI_CMD_ID, + CFG_TASK_HCI_ACL_DATA_ID, + CFG_TASK_SYS_LOCAL_CMD_ID, + CFG_TASK_TX_TO_HOST_ID, + /* USER CODE BEGIN CFG_Task_Id_With_HCI_Cmd_t */ + CFG_TASK_SW1_BUTTON_PUSHED_ID, + CFG_TASK_SW2_BUTTON_PUSHED_ID, + CFG_TASK_SW3_BUTTON_PUSHED_ID, + /* USER CODE END CFG_Task_Id_With_HCI_Cmd_t */ + CFG_LAST_TASK_ID_WITH_HCICMD, /**< Shall be LAST in the list */ +} CFG_Task_Id_With_HCI_Cmd_t; + +/**< Add in that list all tasks that never send a ACI/HCI command */ +typedef enum +{ + CFG_FIRST_TASK_ID_WITH_NO_HCICMD = CFG_LAST_TASK_ID_WITH_HCICMD - 1, /**< Shall be FIRST in the list */ + CFG_TASK_SYSTEM_HCI_ASYNCH_EVT_ID, + /* USER CODE BEGIN CFG_Task_Id_With_NO_HCI_Cmd_t */ + + /* USER CODE END CFG_Task_Id_With_NO_HCI_Cmd_t */ + CFG_LAST_TASK_ID_WITH_NO_HCICMD /**< Shall be LAST in the list */ +} CFG_Task_Id_With_NO_HCI_Cmd_t; + +#define CFG_TASK_NBR CFG_LAST_TASK_ID_WITH_NO_HCICMD + +/** + * This is the list of priority required by the application + * Each Id shall be in the range 0..31 + */ +typedef enum +{ + CFG_SCH_PRIO_0, + /* USER CODE BEGIN CFG_SCH_Prio_Id_t */ + + /* USER CODE END CFG_SCH_Prio_Id_t */ +} CFG_SCH_Prio_Id_t; + +/** + * This is a bit mapping over 32bits listing all events id supported in the application + */ +typedef enum +{ + CFG_IDLEEVT_SYSTEM_HCI_CMD_EVT_RSP_ID, + /* USER CODE BEGIN CFG_IdleEvt_Id_t */ + + /* USER CODE END CFG_IdleEvt_Id_t */ +} CFG_IdleEvt_Id_t; + +/****************************************************************************** + * LOW POWER + ******************************************************************************/ +/** + * Supported requester to the MCU Low Power Manager - can be increased up to 32 + * It list a bit mapping of all user of the Low Power Manager + */ +typedef enum +{ + CFG_LPM_APP, + CFG_LPM_APP_BLE, + /* USER CODE BEGIN CFG_LPM_Id_t */ + + /* USER CODE END CFG_LPM_Id_t */ +} CFG_LPM_Id_t; + +/****************************************************************************** + * OTP manager + ******************************************************************************/ +#define CFG_OTP_BASE_ADDRESS OTP_AREA_BASE + +#define CFG_OTP_END_ADRESS OTP_AREA_END_ADDR + +#endif /*APP_CONF_H */ diff --git a/src/utility/STM32Cube_FW/ble_bufsize.h b/src/utility/STM32Cube_FW/ble_bufsize.h index cea5da84..7b7c170f 100644 --- a/src/utility/STM32Cube_FW/ble_bufsize.h +++ b/src/utility/STM32Cube_FW/ble_bufsize.h @@ -5,7 +5,7 @@ ***************************************************************************** * @attention * - * Copyright (c) 2018-2022 STMicroelectronics. + * Copyright (c) 2018-2023 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file @@ -75,13 +75,6 @@ ((pw) + MAX(BLE_MEM_BLOCK_X_MTU(mtu, n_link), \ BLE_MBLOCKS_SECURE_CONNECTIONS)) -/* - * BLE_DEFAULT_MBLOCKS_COUNT: default memory blocks count - */ -#define BLE_DEFAULT_MBLOCKS_COUNT(n_link) \ - BLE_MBLOCKS_CALC(BLE_DEFAULT_PREP_WRITE_LIST_SIZE, \ - BLE_DEFAULT_MAX_ATT_MTU, n_link) - /* * BLE_FIXED_BUFFER_SIZE_BYTES: * A part of the RAM, is dynamically allocated by initializing all the pointers @@ -120,11 +113,11 @@ #elif (LL_ONLY != 0) #define BLE_PER_LINK_SIZE_BYTES 244 /* LL only Full */ #elif (SLAVE_ONLY != 0) -#define BLE_PER_LINK_SIZE_BYTES 336 /* Peripheral only */ +#define BLE_PER_LINK_SIZE_BYTES 344 /* Peripheral only */ #elif (BASIC_FEATURES != 0) -#define BLE_PER_LINK_SIZE_BYTES 412 /* Basic Features */ +#define BLE_PER_LINK_SIZE_BYTES 420 /* Basic Features */ #else -#define BLE_PER_LINK_SIZE_BYTES 424 /* Full stack */ +#define BLE_PER_LINK_SIZE_BYTES 432 /* Full stack */ #endif /* diff --git a/src/utility/STM32Cube_FW/hw.h b/src/utility/STM32Cube_FW/hw.h index fcf04517..503fa2ca 100644 --- a/src/utility/STM32Cube_FW/hw.h +++ b/src/utility/STM32Cube_FW/hw.h @@ -26,21 +26,14 @@ extern "C" { #endif /* Includes ------------------------------------------------------------------*/ -#include "stm32_def.h" -#include "stm32wbxx_ll_bus.h" -#include "stm32wbxx_ll_exti.h" -#include "stm32wbxx_ll_system.h" -#include "stm32wbxx_ll_rcc.h" -#include "stm32wbxx_ll_ipcc.h" -#include "stm32wbxx_ll_cortex.h" -#include "stm32wbxx_ll_utils.h" -#include "stm32wbxx_ll_pwr.h" /****************************************************************************** * HW IPCC ******************************************************************************/ void HW_IPCC_Enable( void ); void HW_IPCC_Init( void ); + void HW_IPCC_Rx_Handler( void ); + void HW_IPCC_Tx_Handler( void ); void HW_IPCC_BLE_Init( void ); void HW_IPCC_BLE_SendCmd( void ); @@ -87,6 +80,23 @@ extern "C" { void HW_IPCC_TRACES_Init( void ); void HW_IPCC_TRACES_EvtNot( void ); + void HW_IPCC_MAC_802_15_4_Init( void ); + void HW_IPCC_MAC_802_15_4_SendCmd( void ); + void HW_IPCC_MAC_802_15_4_SendAck( void ); + void HW_IPCC_MAC_802_15_4_CmdEvtNot( void ); + void HW_IPCC_MAC_802_15_4_EvtNot( void ); + + void HW_IPCC_ZIGBEE_Init( void ); + + void HW_IPCC_ZIGBEE_SendM4RequestToM0(void); /* M4 Request to M0 */ + void HW_IPCC_ZIGBEE_RecvAppliAckFromM0(void); /* Request ACK from M0 */ + + void HW_IPCC_ZIGBEE_RecvM0NotifyToM4(void); /* M0 Notify to M4 */ + void HW_IPCC_ZIGBEE_SendM4AckToM0Notify(void); /* Notify ACK from M4 */ + void HW_IPCC_ZIGBEE_RecvM0RequestToM4(void); /* M0 Request to M4 */ + void HW_IPCC_ZIGBEE_SendM4AckToM0Request(void); /* Request ACK from M4 */ + + #ifdef __cplusplus } #endif diff --git a/src/utility/STM32Cube_FW/hw_ipcc.c b/src/utility/STM32Cube_FW/hw_ipcc.c index 0c1868f6..fd620b85 100644 --- a/src/utility/STM32Cube_FW/hw_ipcc.c +++ b/src/utility/STM32Cube_FW/hw_ipcc.c @@ -1,3 +1,4 @@ +/* USER CODE BEGIN Header */ /** ****************************************************************************** * @file hw_ipcc.c @@ -15,10 +16,10 @@ * ****************************************************************************** */ +/* USER CODE END Header */ -#if defined(STM32WBxx) /* Includes ------------------------------------------------------------------*/ -#include "hw.h" +#include "app_common.h" #include "mbox_def.h" /* Global variables ---------------------------------------------------------*/ @@ -55,17 +56,34 @@ static void HW_IPCC_LLD_BLE_ReceiveRspHandler( void ); static void HW_IPCC_LLD_BLE_ReceiveM0CmdHandler( void ); #endif +#ifdef MAC_802_15_4_WB +static void HW_IPCC_MAC_802_15_4_CmdEvtHandler( void ); +static void HW_IPCC_MAC_802_15_4_NotEvtHandler( void ); +#endif + +#ifdef ZIGBEE_WB +static void HW_IPCC_ZIGBEE_CmdEvtHandler( void ); +static void HW_IPCC_ZIGBEE_StackNotifEvtHandler( void ); +static void HW_IPCC_ZIGBEE_StackM0RequestHandler( void ); +#endif + /* Public function definition -----------------------------------------------*/ /****************************************************************************** * INTERRUPT HANDLER ******************************************************************************/ -void IPCC_C1_RX_IRQHandler( void ) +void HW_IPCC_Rx_Handler( void ) { if (HW_IPCC_RX_PENDING( HW_IPCC_SYSTEM_EVENT_CHANNEL )) { HW_IPCC_SYS_EvtHandler(); } +#ifdef MAC_802_15_4_WB + else if (HW_IPCC_RX_PENDING( HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL )) + { + HW_IPCC_MAC_802_15_4_NotEvtHandler(); + } +#endif /* MAC_802_15_4_WB */ #ifdef THREAD_WB else if (HW_IPCC_RX_PENDING( HW_IPCC_THREAD_NOTIFICATION_ACK_CHANNEL )) { @@ -96,6 +114,16 @@ void IPCC_C1_RX_IRQHandler( void ) HW_IPCC_LLD_BLE_ReceiveM0CmdHandler(); } #endif /* LLD_TESTS_WB */ +#ifdef ZIGBEE_WB + else if (HW_IPCC_RX_PENDING( HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL )) + { + HW_IPCC_ZIGBEE_StackNotifEvtHandler(); + } + else if (HW_IPCC_RX_PENDING( HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL )) + { + HW_IPCC_ZIGBEE_StackM0RequestHandler(); + } +#endif /* ZIGBEE_WB */ else if (HW_IPCC_RX_PENDING( HW_IPCC_BLE_EVENT_CHANNEL )) { HW_IPCC_BLE_EvtHandler(); @@ -104,14 +132,22 @@ void IPCC_C1_RX_IRQHandler( void ) { HW_IPCC_TRACES_EvtHandler(); } + + return; } -void IPCC_C1_TX_IRQHandler( void ) +void HW_IPCC_Tx_Handler( void ) { if (HW_IPCC_TX_PENDING( HW_IPCC_SYSTEM_CMD_RSP_CHANNEL )) { HW_IPCC_SYS_CmdEvtHandler(); } +#ifdef MAC_802_15_4_WB + else if (HW_IPCC_TX_PENDING( HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL )) + { + HW_IPCC_MAC_802_15_4_CmdEvtHandler(); + } +#endif /* MAC_802_15_4_WB */ #ifdef THREAD_WB else if (HW_IPCC_TX_PENDING( HW_IPCC_THREAD_OT_CMD_RSP_CHANNEL )) { @@ -121,6 +157,12 @@ void IPCC_C1_TX_IRQHandler( void ) #ifdef LLD_TESTS_WB // No TX handler for LLD tests #endif /* LLD_TESTS_WB */ +#ifdef ZIGBEE_WB + if (HW_IPCC_TX_PENDING( HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL )) + { + HW_IPCC_ZIGBEE_CmdEvtHandler(); + } +#endif /* ZIGBEE_WB */ else if (HW_IPCC_TX_PENDING( HW_IPCC_MM_RELEASE_BUFFER_CHANNEL )) { HW_IPCC_MM_FreeBufHandler(); @@ -129,6 +171,8 @@ void IPCC_C1_TX_IRQHandler( void ) { HW_IPCC_BLE_AclDataEvtHandler(); } + + return; } /****************************************************************************** * GENERAL @@ -160,6 +204,8 @@ void HW_IPCC_Enable( void ) __SEV( ); /* Set the internal event flag and send an event to the CPU2 */ __WFE( ); /* Clear the internal event flag */ LL_PWR_EnableBootC2( ); + + return; } void HW_IPCC_Init( void ) @@ -171,6 +217,8 @@ void HW_IPCC_Init( void ) HAL_NVIC_EnableIRQ(IPCC_C1_RX_IRQn); HAL_NVIC_EnableIRQ(IPCC_C1_TX_IRQn); + + return; } /****************************************************************************** @@ -179,11 +227,15 @@ void HW_IPCC_Init( void ) void HW_IPCC_BLE_Init( void ) { LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_BLE_EVENT_CHANNEL ); + + return; } void HW_IPCC_BLE_SendCmd( void ) { LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_BLE_CMD_CHANNEL ); + + return; } static void HW_IPCC_BLE_EvtHandler( void ) @@ -191,12 +243,16 @@ static void HW_IPCC_BLE_EvtHandler( void ) HW_IPCC_BLE_RxEvtNot(); LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_BLE_EVENT_CHANNEL ); + + return; } void HW_IPCC_BLE_SendAclData( void ) { LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_HCI_ACL_DATA_CHANNEL ); LL_C1_IPCC_EnableTransmitChannel( IPCC, HW_IPCC_HCI_ACL_DATA_CHANNEL ); + + return; } static void HW_IPCC_BLE_AclDataEvtHandler( void ) @@ -204,6 +260,8 @@ static void HW_IPCC_BLE_AclDataEvtHandler( void ) LL_C1_IPCC_DisableTransmitChannel( IPCC, HW_IPCC_HCI_ACL_DATA_CHANNEL ); HW_IPCC_BLE_AclDataAckNot(); + + return; } __weak void HW_IPCC_BLE_AclDataAckNot( void ){}; @@ -215,12 +273,16 @@ __weak void HW_IPCC_BLE_RxEvtNot( void ){}; void HW_IPCC_SYS_Init( void ) { LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_SYSTEM_EVENT_CHANNEL ); + + return; } void HW_IPCC_SYS_SendCmd( void ) { LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_SYSTEM_CMD_RSP_CHANNEL ); LL_C1_IPCC_EnableTransmitChannel( IPCC, HW_IPCC_SYSTEM_CMD_RSP_CHANNEL ); + + return; } static void HW_IPCC_SYS_CmdEvtHandler( void ) @@ -228,6 +290,8 @@ static void HW_IPCC_SYS_CmdEvtHandler( void ) LL_C1_IPCC_DisableTransmitChannel( IPCC, HW_IPCC_SYSTEM_CMD_RSP_CHANNEL ); HW_IPCC_SYS_CmdEvtNot(); + + return; } static void HW_IPCC_SYS_EvtHandler( void ) @@ -235,11 +299,61 @@ static void HW_IPCC_SYS_EvtHandler( void ) HW_IPCC_SYS_EvtNot(); LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_SYSTEM_EVENT_CHANNEL ); + + return; } __weak void HW_IPCC_SYS_CmdEvtNot( void ){}; __weak void HW_IPCC_SYS_EvtNot( void ){}; +/****************************************************************************** + * MAC 802.15.4 + ******************************************************************************/ +#ifdef MAC_802_15_4_WB +void HW_IPCC_MAC_802_15_4_Init( void ) +{ + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL ); + + return; +} + +void HW_IPCC_MAC_802_15_4_SendCmd( void ) +{ + LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL ); + LL_C1_IPCC_EnableTransmitChannel( IPCC, HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL ); + + return; +} + +void HW_IPCC_MAC_802_15_4_SendAck( void ) +{ + LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL ); + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL ); + + return; +} + +static void HW_IPCC_MAC_802_15_4_CmdEvtHandler( void ) +{ + LL_C1_IPCC_DisableTransmitChannel( IPCC, HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL ); + + HW_IPCC_MAC_802_15_4_CmdEvtNot(); + + return; +} + +static void HW_IPCC_MAC_802_15_4_NotEvtHandler( void ) +{ + LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL ); + + HW_IPCC_MAC_802_15_4_EvtNot(); + + return; +} +__weak void HW_IPCC_MAC_802_15_4_CmdEvtNot( void ){}; +__weak void HW_IPCC_MAC_802_15_4_EvtNot( void ){}; +#endif + /****************************************************************************** * THREAD ******************************************************************************/ @@ -279,6 +393,8 @@ void HW_IPCC_THREAD_CliSendAck( void ) { LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_THREAD_CLI_NOTIFICATION_ACK_CHANNEL ); LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_THREAD_CLI_NOTIFICATION_ACK_CHANNEL ); + + return; } static void HW_IPCC_OT_CmdEvtHandler( void ) @@ -286,6 +402,8 @@ static void HW_IPCC_OT_CmdEvtHandler( void ) LL_C1_IPCC_DisableTransmitChannel( IPCC, HW_IPCC_THREAD_OT_CMD_RSP_CHANNEL ); HW_IPCC_OT_CmdEvtNot(); + + return; } static void HW_IPCC_THREAD_NotEvtHandler( void ) @@ -293,6 +411,8 @@ static void HW_IPCC_THREAD_NotEvtHandler( void ) LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_THREAD_NOTIFICATION_ACK_CHANNEL ); HW_IPCC_THREAD_EvtNot(); + + return; } static void HW_IPCC_THREAD_CliNotEvtHandler( void ) @@ -300,6 +420,8 @@ static void HW_IPCC_THREAD_CliNotEvtHandler( void ) LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_THREAD_CLI_NOTIFICATION_ACK_CHANNEL ); HW_IPCC_THREAD_CliEvtNot(); + + return; } __weak void HW_IPCC_OT_CmdEvtNot( void ){}; @@ -316,6 +438,7 @@ void HW_IPCC_LLDTESTS_Init( void ) { LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_LLDTESTS_CLI_RSP_CHANNEL ); LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_LLDTESTS_M0_CMD_CHANNEL ); + return; } void HW_IPCC_LLDTESTS_SendCliCmd( void ) @@ -328,24 +451,28 @@ static void HW_IPCC_LLDTESTS_ReceiveCliRspHandler( void ) { LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_LLDTESTS_CLI_RSP_CHANNEL ); HW_IPCC_LLDTESTS_ReceiveCliRsp(); + return; } void HW_IPCC_LLDTESTS_SendCliRspAck( void ) { LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_LLDTESTS_CLI_RSP_CHANNEL ); LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_LLDTESTS_CLI_RSP_CHANNEL ); + return; } static void HW_IPCC_LLDTESTS_ReceiveM0CmdHandler( void ) { LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_LLDTESTS_M0_CMD_CHANNEL ); HW_IPCC_LLDTESTS_ReceiveM0Cmd(); + return; } void HW_IPCC_LLDTESTS_SendM0CmdAck( void ) { LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_LLDTESTS_M0_CMD_CHANNEL ); LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_LLDTESTS_M0_CMD_CHANNEL ); + return; } __weak void HW_IPCC_LLDTESTS_ReceiveCliRsp( void ){}; __weak void HW_IPCC_LLDTESTS_ReceiveM0Cmd( void ){}; @@ -359,11 +486,13 @@ void HW_IPCC_LLD_BLE_Init( void ) { LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_LLD_BLE_RSP_CHANNEL ); LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_LLD_BLE_M0_CMD_CHANNEL ); + return; } void HW_IPCC_LLD_BLE_SendCliCmd( void ) { LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_LLD_BLE_CLI_CMD_CHANNEL ); + return; } /*static void HW_IPCC_LLD_BLE_ReceiveCliRspHandler( void ) @@ -377,18 +506,21 @@ void HW_IPCC_LLD_BLE_SendCliRspAck( void ) { LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_LLD_BLE_CLI_RSP_CHANNEL ); LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_LLD_BLE_CLI_RSP_CHANNEL ); + return; } static void HW_IPCC_LLD_BLE_ReceiveM0CmdHandler( void ) { //LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_LLD_BLE_M0_CMD_CHANNEL ); HW_IPCC_LLD_BLE_ReceiveM0Cmd(); + return; } void HW_IPCC_LLD_BLE_SendM0CmdAck( void ) { LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_LLD_BLE_M0_CMD_CHANNEL ); //LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_LLD_BLE_M0_CMD_CHANNEL ); + return; } __weak void HW_IPCC_LLD_BLE_ReceiveCliRsp( void ){}; __weak void HW_IPCC_LLD_BLE_ReceiveM0Cmd( void ){}; @@ -397,22 +529,93 @@ __weak void HW_IPCC_LLD_BLE_ReceiveM0Cmd( void ){}; void HW_IPCC_LLD_BLE_SendCmd( void ) { LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_LLD_BLE_CMD_CHANNEL ); + return; } static void HW_IPCC_LLD_BLE_ReceiveRspHandler( void ) { LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_LLD_BLE_RSP_CHANNEL ); HW_IPCC_LLD_BLE_ReceiveRsp(); + return; } void HW_IPCC_LLD_BLE_SendRspAck( void ) { LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_LLD_BLE_RSP_CHANNEL ); LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_LLD_BLE_RSP_CHANNEL ); + return; } #endif /* LLD_BLE_WB */ +/****************************************************************************** + * ZIGBEE + ******************************************************************************/ +#ifdef ZIGBEE_WB +void HW_IPCC_ZIGBEE_Init( void ) +{ + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL ); + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL ); + + return; +} + +void HW_IPCC_ZIGBEE_SendM4RequestToM0( void ) +{ + LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL ); + LL_C1_IPCC_EnableTransmitChannel( IPCC, HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL ); + + return; +} + +void HW_IPCC_ZIGBEE_SendM4AckToM0Notify( void ) +{ + LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL ); + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL ); + + return; +} + +static void HW_IPCC_ZIGBEE_CmdEvtHandler( void ) +{ + LL_C1_IPCC_DisableTransmitChannel( IPCC, HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL ); + + HW_IPCC_ZIGBEE_RecvAppliAckFromM0(); + + return; +} + +static void HW_IPCC_ZIGBEE_StackNotifEvtHandler( void ) +{ + LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL ); + + HW_IPCC_ZIGBEE_RecvM0NotifyToM4(); + + return; +} + +static void HW_IPCC_ZIGBEE_StackM0RequestHandler( void ) +{ + LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL ); + + HW_IPCC_ZIGBEE_RecvM0RequestToM4(); + + return; +} + +void HW_IPCC_ZIGBEE_SendM4AckToM0Request( void ) +{ + LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL ); + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL ); + + return; +} + +__weak void HW_IPCC_ZIGBEE_RecvAppliAckFromM0( void ){}; +__weak void HW_IPCC_ZIGBEE_RecvM0NotifyToM4( void ){}; +__weak void HW_IPCC_ZIGBEE_RecvM0RequestToM4( void ){}; +#endif /* ZIGBEE_WB */ + /****************************************************************************** * MEMORY MANAGER ******************************************************************************/ @@ -429,6 +632,8 @@ void HW_IPCC_MM_SendFreeBuf( void (*cb)( void ) ) LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_MM_RELEASE_BUFFER_CHANNEL ); } + + return; } static void HW_IPCC_MM_FreeBufHandler( void ) @@ -438,6 +643,8 @@ static void HW_IPCC_MM_FreeBufHandler( void ) FreeBufCb(); LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_MM_RELEASE_BUFFER_CHANNEL ); + + return; } /****************************************************************************** @@ -455,7 +662,8 @@ static void HW_IPCC_TRACES_EvtHandler( void ) HW_IPCC_TRACES_EvtNot(); LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_TRACES_CHANNEL ); + + return; } __weak void HW_IPCC_TRACES_EvtNot( void ){}; -#endif /* STM32WBxx */ diff --git a/src/utility/STM32Cube_FW/mbox_def.h b/src/utility/STM32Cube_FW/mbox_def.h index 0c974f8f..68b71f9c 100644 --- a/src/utility/STM32Cube_FW/mbox_def.h +++ b/src/utility/STM32Cube_FW/mbox_def.h @@ -106,6 +106,12 @@ extern "C" { uint8_t *m0cmd_buffer; } MB_BleLldTable_t; + typedef struct + { + uint8_t *notifM0toM4_buffer; + uint8_t *appliCmdM4toM0_buffer; + uint8_t *requestM0toM4_buffer; + } MB_ZigbeeTable_t; /** * msg * [0:7] = cmd/evt @@ -133,6 +139,13 @@ extern "C" { uint8_t *traces_queue; } MB_TracesTable_t; + typedef struct + { + uint8_t *p_cmdrsp_buffer; + uint8_t *p_notack_buffer; + uint8_t *evt_queue; + } MB_Mac_802_15_4_t; + typedef struct { MB_DeviceInfoTable_t *p_device_info_table; @@ -141,6 +154,8 @@ extern "C" { MB_SysTable_t *p_sys_table; MB_MemManagerTable_t *p_mem_manager_table; MB_TracesTable_t *p_traces_table; + MB_Mac_802_15_4_t *p_mac_802_15_4_table; + MB_ZigbeeTable_t *p_zigbee_table; MB_LldTestsTable_t *p_lld_tests_table; MB_BleLldTable_t *p_ble_lld_table; } MB_RefTable_t; @@ -184,6 +199,15 @@ typedef struct * | | * |<---HW_IPCC_SYSTEM_EVENT_CHANNEL-----------------| * | | + * | (ZIGBEE) | + * |----HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL------------>| + * | | + * |----HW_IPCC_ZIGBEE_CMD_CLI_CHANNEL-------------->| + * | | + * |<---HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL-------| + * | | + * |<---HW_IPCC_ZIGBEE_CLI_NOTIF_ACK_CHANNEL---------| + * | | * | (THREAD) | * |----HW_IPCC_THREAD_OT_CMD_RSP_CHANNEL----------->| * | | @@ -207,6 +231,11 @@ typedef struct * | | * |<---HW_IPCC_BLE_LLD_M0_CMD_CHANNEL---------------| * | | + * | (MAC) | + * |----HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL-------->| + * | | + * |<---HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL| + * | | * | (BUFFER) | * |----HW_IPCC_MM_RELEASE_BUFFER_CHANNE------------>| * | | @@ -224,6 +253,8 @@ typedef struct #define HW_IPCC_BLE_CMD_CHANNEL LL_IPCC_CHANNEL_1 #define HW_IPCC_SYSTEM_CMD_RSP_CHANNEL LL_IPCC_CHANNEL_2 #define HW_IPCC_THREAD_OT_CMD_RSP_CHANNEL LL_IPCC_CHANNEL_3 +#define HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL LL_IPCC_CHANNEL_3 +#define HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL LL_IPCC_CHANNEL_3 #define HW_IPCC_MM_RELEASE_BUFFER_CHANNEL LL_IPCC_CHANNEL_4 #define HW_IPCC_THREAD_CLI_CMD_CHANNEL LL_IPCC_CHANNEL_5 #define HW_IPCC_LLDTESTS_CLI_CMD_CHANNEL LL_IPCC_CHANNEL_5 @@ -235,6 +266,8 @@ typedef struct #define HW_IPCC_BLE_EVENT_CHANNEL LL_IPCC_CHANNEL_1 #define HW_IPCC_SYSTEM_EVENT_CHANNEL LL_IPCC_CHANNEL_2 #define HW_IPCC_THREAD_NOTIFICATION_ACK_CHANNEL LL_IPCC_CHANNEL_3 +#define HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL LL_IPCC_CHANNEL_3 +#define HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL LL_IPCC_CHANNEL_3 #define HW_IPCC_LLDTESTS_M0_CMD_CHANNEL LL_IPCC_CHANNEL_3 #define HW_IPCC_BLE_LLD_M0_CMD_CHANNEL LL_IPCC_CHANNEL_3 #define HW_IPCC_TRACES_CHANNEL LL_IPCC_CHANNEL_4 @@ -242,5 +275,6 @@ typedef struct #define HW_IPCC_LLDTESTS_CLI_RSP_CHANNEL LL_IPCC_CHANNEL_5 #define HW_IPCC_BLE_LLD_CLI_RSP_CHANNEL LL_IPCC_CHANNEL_5 #define HW_IPCC_BLE_LLD_RSP_CHANNEL LL_IPCC_CHANNEL_5 +#define HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL LL_IPCC_CHANNEL_5 #endif /*__MBOX_H */ diff --git a/src/utility/STM32Cube_FW/shci.c b/src/utility/STM32Cube_FW/shci.c index 8b241bbe..301db76d 100644 --- a/src/utility/STM32Cube_FW/shci.c +++ b/src/utility/STM32Cube_FW/shci.c @@ -16,7 +16,7 @@ ****************************************************************************** */ -#if defined(STM32WBxx) + /* Includes ------------------------------------------------------------------*/ #include "stm32_wpan_common.h" @@ -42,7 +42,7 @@ uint8_t SHCI_C2_FUS_GetState( SHCI_FUS_GetState_ErrorCode_t *p_error_code ) /** * A command status event + payload has the same size than the expected command complete */ - uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE + 1]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; @@ -66,7 +66,7 @@ SHCI_CmdStatus_t SHCI_C2_FUS_FwUpgrade( uint32_t fw_src_add, uint32_t fw_dest_a * TL_BLEEVT_CS_BUFFER_SIZE is 15 bytes so it is large enough to hold the 8 bytes of command parameters * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; uint32_t *p_cmd; uint8_t cmd_length; @@ -101,7 +101,7 @@ SHCI_CmdStatus_t SHCI_C2_FUS_FwDelete( void ) /** * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; @@ -119,7 +119,7 @@ SHCI_CmdStatus_t SHCI_C2_FUS_UpdateAuthKey( SHCI_C2_FUS_UpdateAuthKey_Cmd_Param_ /** * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; @@ -137,7 +137,7 @@ SHCI_CmdStatus_t SHCI_C2_FUS_LockAuthKey( void ) /** * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; @@ -155,7 +155,7 @@ SHCI_CmdStatus_t SHCI_C2_FUS_StoreUsrKey( SHCI_C2_FUS_StoreUsrKey_Cmd_Param_t *p /** * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE + 1]; TL_EvtPacket_t * p_rsp; uint8_t local_payload_len; @@ -189,7 +189,7 @@ SHCI_CmdStatus_t SHCI_C2_FUS_LoadUsrKey( uint8_t key_index ) /** * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; @@ -209,7 +209,7 @@ SHCI_CmdStatus_t SHCI_C2_FUS_StartWs( void ) /** * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; @@ -227,7 +227,7 @@ SHCI_CmdStatus_t SHCI_C2_FUS_LockUsrKey( uint8_t key_index ) /** * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; @@ -247,7 +247,7 @@ SHCI_CmdStatus_t SHCI_C2_FUS_UnloadUsrKey( uint8_t key_index ) /** * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; @@ -267,7 +267,7 @@ SHCI_CmdStatus_t SHCI_C2_FUS_ActivateAntiRollback( void ) /** * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; @@ -285,7 +285,7 @@ SHCI_CmdStatus_t SHCI_C2_BLE_Init( SHCI_C2_Ble_Init_Cmd_Packet_t *pCmdPacket ) /** * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; @@ -303,7 +303,7 @@ SHCI_CmdStatus_t SHCI_C2_THREAD_Init( void ) /** * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; @@ -321,7 +321,7 @@ SHCI_CmdStatus_t SHCI_C2_LLDTESTS_Init( uint8_t param_size, uint8_t * p_param ) /** * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; @@ -339,7 +339,7 @@ SHCI_CmdStatus_t SHCI_C2_BLE_LLD_Init( uint8_t param_size, uint8_t * p_param ) /** * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; @@ -352,12 +352,30 @@ SHCI_CmdStatus_t SHCI_C2_BLE_LLD_Init( uint8_t param_size, uint8_t * p_param ) return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); } +SHCI_CmdStatus_t SHCI_C2_ZIGBEE_Init( void ) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send( SHCI_OPCODE_C2_ZIGBEE_INIT, + 0, + 0, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + SHCI_CmdStatus_t SHCI_C2_DEBUG_Init( SHCI_C2_DEBUG_Init_Cmd_Packet_t *pCmdPacket ) { /** * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; @@ -375,7 +393,7 @@ SHCI_CmdStatus_t SHCI_C2_FLASH_EraseActivity( SHCI_EraseActivity_t erase_activit /** * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; @@ -395,7 +413,7 @@ SHCI_CmdStatus_t SHCI_C2_CONCURRENT_SetMode( SHCI_C2_CONCURRENT_Mode_Param_t Mod /** * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; @@ -415,7 +433,7 @@ SHCI_CmdStatus_t SHCI_C2_CONCURRENT_GetNextBleEvtTime( SHCI_C2_CONCURRENT_GetNex /** * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE+4]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; @@ -435,7 +453,7 @@ SHCI_CmdStatus_t SHCI_C2_CONCURRENT_EnableNext_802154_EvtNotification( void ) /** * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; @@ -453,7 +471,7 @@ SHCI_CmdStatus_t SHCI_C2_FLASH_StoreData( SHCI_C2_FLASH_Ip_t Ip ) /** * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; @@ -473,7 +491,7 @@ SHCI_CmdStatus_t SHCI_C2_FLASH_EraseData( SHCI_C2_FLASH_Ip_t Ip ) /** * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; @@ -493,7 +511,7 @@ SHCI_CmdStatus_t SHCI_C2_RADIO_AllowLowPower( SHCI_C2_FLASH_Ip_t Ip,uint8_t Fla /** * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; @@ -509,12 +527,30 @@ SHCI_CmdStatus_t SHCI_C2_RADIO_AllowLowPower( SHCI_C2_FLASH_Ip_t Ip,uint8_t Fla return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); } +SHCI_CmdStatus_t SHCI_C2_MAC_802_15_4_Init( void ) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send( SHCI_OPCODE_C2_MAC_802_15_4_INIT, + 0, + 0, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + SHCI_CmdStatus_t SHCI_C2_Reinit( void ) { /** * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; @@ -533,7 +569,7 @@ SHCI_CmdStatus_t SHCI_C2_ExtpaConfig(uint32_t gpio_port, uint16_t gpio_pin_numbe * TL_BLEEVT_CS_BUFFER_SIZE is 15 bytes so it is large enough to hold the 8 bytes of command parameters * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; @@ -557,7 +593,7 @@ SHCI_CmdStatus_t SHCI_C2_SetFlashActivityControl(SHCI_C2_SET_FLASH_ACTIVITY_CONT * TL_BLEEVT_CS_BUFFER_SIZE is 15 bytes so it is large enough to hold the 1 byte of command parameter * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; @@ -577,7 +613,7 @@ SHCI_CmdStatus_t SHCI_C2_Config(SHCI_C2_CONFIG_Cmd_Param_t *pCmdPacket) /** * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; @@ -595,7 +631,7 @@ SHCI_CmdStatus_t SHCI_C2_802_15_4_DeInit( void ) /** * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; @@ -703,4 +739,3 @@ SHCI_CmdStatus_t SHCI_GetWirelessFwInfo( WirelessFwInfo_t* pWirelessInfo ) return (SHCI_Success); } -#endif /* STM32WBxx */ diff --git a/src/utility/STM32Cube_FW/shci.h b/src/utility/STM32Cube_FW/shci.h index a0f1e4d2..d2aa0a58 100644 --- a/src/utility/STM32Cube_FW/shci.h +++ b/src/utility/STM32Cube_FW/shci.h @@ -49,6 +49,7 @@ extern "C" { ERR_BLE_INIT = 0, /* This event is currently not reported by the CPU2 */ ERR_THREAD_LLD_FATAL_ERROR = 125, /* The LLD driver used on 802_15_4 detected a fatal error */ ERR_THREAD_UNKNOWN_CMD = 126, /* The command send by the CPU1 to control the Thread stack is unknown */ + ERR_ZIGBEE_UNKNOWN_CMD = 200, /* The command send by the CPU1 to control the Zigbee stack is unknown */ } SCHI_SystemErrCode_t; #define SHCI_EVTCODE ( 0xFF ) @@ -215,7 +216,9 @@ extern "C" { SHCI_OCF_C2_FLASH_STORE_DATA, SHCI_OCF_C2_FLASH_ERASE_DATA, SHCI_OCF_C2_RADIO_ALLOW_LOW_POWER, + SHCI_OCF_C2_MAC_802_15_4_INIT, SHCI_OCF_C2_REINIT, + SHCI_OCF_C2_ZIGBEE_INIT, SHCI_OCF_C2_LLD_TESTS_INIT, SHCI_OCF_C2_EXTPA_CONFIG, SHCI_OCF_C2_SET_FLASH_ACTIVITY_CONTROL, @@ -433,7 +436,7 @@ extern "C" { * PrWriteListSize * NOTE: This parameter is ignored by the CPU2 when the parameter "Options" is set to "LL_only" ( see Options description in that structure ) * - * Maximum number of supported "prepare write request" + * Maximum number of supported �prepare write request� * - Min value: given by the macro DEFAULT_PREP_WRITE_LIST_SIZE * - Max value: a value higher than the minimum required can be specified, but it is not recommended */ @@ -500,7 +503,7 @@ extern "C" { * MaxConnEventLength * This parameter determines the maximum duration of a slave connection event. When this duration is reached the slave closes * the current connections event (whatever is the CE_length parameter specified by the master in HCI_CREATE_CONNECTION HCI command), - * expressed in units of 625/256 µs (~2.44 µs) + * expressed in units of 625/256 �s (~2.44 �s) * - Min value: 0 (if 0 is specified, the master and slave perform only a single TX-RX exchange per connection event) * - Max value: 1638400 (4000 ms). A higher value can be specified (max 0xFFFFFFFF) but results in a maximum connection time * of 4000 ms as specified. In this case the parameter is not applied, and the predicted CE length calculated on slave is not shortened @@ -509,7 +512,7 @@ extern "C" { /** * HsStartupTime - * Startup time of the high speed (16 or 32 MHz) crystal oscillator in units of 625/256 µs (~2.44 µs). + * Startup time of the high speed (16 or 32 MHz) crystal oscillator in units of 625/256 �s (~2.44 �s). * - Min value: 0 * - Max value: 820 (~2 ms). A higher value can be specified, but the value that implemented in stack is forced to ~2 ms */ @@ -533,9 +536,7 @@ extern "C" { * - bit 5: 1: Reduced GATT database in NVM 0: Full GATT database in NVM * - bit 6: 1: GATT caching is used 0: GATT caching is not used * - bit 7: 1: LE Power Class 1 0: LE Power Classe 2-3 - * - bit 8: 1: appearance Writable 0: appearance Read-Only - * - bit 9: 1: Enhanced ATT supported 0: Enhanced ATT not supported - * - other bits: reserved ( shall be set to 0) + * - other bits: complete with Options_extension flag */ uint8_t Options; @@ -601,6 +602,14 @@ extern "C" { */ uint8_t ble_core_version; + /** + * Options flags extension + * - bit 0: 1: appearance Writable 0: appearance Read-Only + * - bit 1: 1: Enhanced ATT supported 0: Enhanced ATT not supported + * - other bits: reserved ( shall be set to 0) + */ + uint8_t Options_extension; + } SHCI_C2_Ble_Init_Cmd_Param_t; typedef PACKED_STRUCT{ @@ -637,11 +646,16 @@ extern "C" { #define SHCI_C2_BLE_INIT_OPTIONS_POWER_CLASS_1 (1<<7) #define SHCI_C2_BLE_INIT_OPTIONS_POWER_CLASS_2_3 (0<<7) -#define SHCI_C2_BLE_INIT_OPTIONS_APPEARANCE_WRITABLE (1<<8) -#define SHCI_C2_BLE_INIT_OPTIONS_APPEARANCE_READONLY (0<<8) + /** + * Options extension + * Each definition below may be added together to build the Options value + * WARNING : Only one definition per bit shall be added to build the Options value + */ +#define SHCI_C2_BLE_INIT_OPTIONS_APPEARANCE_WRITABLE (1<<0) +#define SHCI_C2_BLE_INIT_OPTIONS_APPEARANCE_READONLY (0<<0) -#define SHCI_C2_BLE_INIT_OPTIONS_ENHANCED_ATT_SUPPORTED (1<<9) -#define SHCI_C2_BLE_INIT_OPTIONS_ENHANCED_ATT_NOTSUPPORTED (0<<9) +#define SHCI_C2_BLE_INIT_OPTIONS_ENHANCED_ATT_SUPPORTED (1<<1) +#define SHCI_C2_BLE_INIT_OPTIONS_ENHANCED_ATT_NOTSUPPORTED (0<<1) /** * RX models configuration @@ -675,6 +689,8 @@ extern "C" { { uint8_t thread_config; uint8_t ble_config; + uint8_t mac_802_15_4_config; + uint8_t zigbee_config; } SHCI_C2_DEBUG_TracesConfig_t; typedef PACKED_STRUCT @@ -738,6 +754,8 @@ extern "C" { { BLE_ENABLE, THREAD_ENABLE, + ZIGBEE_ENABLE, + MAC_ENABLE, } SHCI_C2_CONCURRENT_Mode_Param_t; /** No response parameters*/ @@ -760,13 +778,18 @@ extern "C" { { BLE_IP, THREAD_IP, + ZIGBEE_IP, } SHCI_C2_FLASH_Ip_t; /** No response parameters*/ #define SHCI_OPCODE_C2_RADIO_ALLOW_LOW_POWER (( SHCI_OGF << 10) + SHCI_OCF_C2_RADIO_ALLOW_LOW_POWER) +#define SHCI_OPCODE_C2_MAC_802_15_4_INIT (( SHCI_OGF << 10) + SHCI_OCF_C2_MAC_802_15_4_INIT) + #define SHCI_OPCODE_C2_REINIT (( SHCI_OGF << 10) + SHCI_OCF_C2_REINIT) +#define SHCI_OPCODE_C2_ZIGBEE_INIT (( SHCI_OGF << 10) + SHCI_OCF_C2_ZIGBEE_INIT) + #define SHCI_OPCODE_C2_LLD_TESTS_INIT (( SHCI_OGF << 10) + SHCI_OCF_C2_LLD_TESTS_INIT) #define SHCI_OPCODE_C2_BLE_LLD_INIT (( SHCI_OGF << 10) + SHCI_OCF_C2_BLE_LLD_INIT) @@ -881,7 +904,7 @@ extern "C" { #define FUS_DEVICE_INFO_TABLE_VALIDITY_KEYWORD (0xA94656B9) /* - * At startup, the information relative to the wireless binary are stored in RAM through a structure defined by + * At startup, the informations relative to the wireless binary are stored in RAM trough a structure defined by * MB_WirelessFwInfoTable_t.This structure contains 4 fields (Version,MemorySize, Stack_info and a reserved part) * each of those coded on 32 bits as shown on the table below: * @@ -937,6 +960,9 @@ extern "C" { #define INFO_STACK_TYPE_BLE_HCI_EXT_ADV 0x07 #define INFO_STACK_TYPE_THREAD_FTD 0x10 #define INFO_STACK_TYPE_THREAD_MTD 0x11 +#define INFO_STACK_TYPE_ZIGBEE_FFD 0x30 +#define INFO_STACK_TYPE_ZIGBEE_RFD 0x31 +#define INFO_STACK_TYPE_MAC 0x40 #define INFO_STACK_TYPE_BLE_THREAD_FTD_STATIC 0x50 #define INFO_STACK_TYPE_BLE_THREAD_FTD_DYAMIC 0x51 #define INFO_STACK_TYPE_802154_LLD_TESTS 0x60 @@ -945,7 +971,12 @@ extern "C" { #define INFO_STACK_TYPE_BLE_LLD_TESTS 0x63 #define INFO_STACK_TYPE_BLE_RLV 0x64 #define INFO_STACK_TYPE_802154_RLV 0x65 +#define INFO_STACK_TYPE_BLE_ZIGBEE_FFD_STATIC 0x70 +#define INFO_STACK_TYPE_BLE_ZIGBEE_RFD_STATIC 0x71 +#define INFO_STACK_TYPE_BLE_ZIGBEE_FFD_DYNAMIC 0x78 +#define INFO_STACK_TYPE_BLE_ZIGBEE_RFD_DYNAMIC 0x79 #define INFO_STACK_TYPE_RLV 0x80 +#define INFO_STACK_TYPE_BLE_MAC_STATIC 0x90 typedef struct { /** @@ -1119,7 +1150,7 @@ typedef struct { * @brief Starts the LLD tests CLI * * @param param_size : Nb of bytes - * @param p_param : pointer with data to give from M4 to M0 + * @param p_param : pointeur with data to give from M4 to M0 * @retval Status */ SHCI_CmdStatus_t SHCI_C2_LLDTESTS_Init( uint8_t param_size, uint8_t * p_param ); @@ -1129,11 +1160,20 @@ typedef struct { * @brief Starts the LLD tests BLE * * @param param_size : Nb of bytes - * @param p_param : pointer with data to give from M4 to M0 + * @param p_param : pointeur with data to give from M4 to M0 * @retval Status */ SHCI_CmdStatus_t SHCI_C2_BLE_LLD_Init( uint8_t param_size, uint8_t * p_param ); + /** + * SHCI_C2_ZIGBEE_Init + * @brief Starts the Zigbee Stack + * + * @param None + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_ZIGBEE_Init( void ); + /** * SHCI_C2_DEBUG_Init * @brief Starts the Traces @@ -1208,6 +1248,16 @@ typedef struct { */ SHCI_CmdStatus_t SHCI_C2_RADIO_AllowLowPower( SHCI_C2_FLASH_Ip_t Ip,uint8_t FlagRadioLowPowerOn); + + /** + * SHCI_C2_MAC_802_15_4_Init + * @brief Starts the MAC 802.15.4 on M0 + * + * @param None + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_MAC_802_15_4_Init( void ); + /** * SHCI_GetWirelessFwInfo * @brief This function read back the informations relative to the wireless binary loaded. diff --git a/src/utility/STM32Cube_FW/shci_tl.c b/src/utility/STM32Cube_FW/shci_tl.c index 1abd1be9..2b387b1b 100644 --- a/src/utility/STM32Cube_FW/shci_tl.c +++ b/src/utility/STM32Cube_FW/shci_tl.c @@ -16,14 +16,12 @@ ****************************************************************************** */ -#if defined(STM32WBxx) + /* Includes ------------------------------------------------------------------*/ #include "stm32_wpan_common.h" #include "stm_list.h" #include "shci_tl.h" -#include "stm32_def.h" -#include "wiring_time.h" /* Private typedef -----------------------------------------------------------*/ typedef enum @@ -72,6 +70,8 @@ void shci_init(void(* UserEvtRx)(void* pData), void* pConf) shci_register_io_bus (&shciContext.io); TlInit((TL_CmdPacket_t *)(((SHCI_TL_HciInitConf_t *)pConf)->p_cmdbuffer)); + + return; } void shci_user_evt_proc(void) @@ -127,6 +127,8 @@ void shci_user_evt_proc(void) shci_notify_asynch_evt((void*) &SHciAsynchEventQueue); } + + return; } void shci_resume_flow( void ) @@ -138,6 +140,8 @@ void shci_resume_flow( void ) * be called */ shci_notify_asynch_evt((void*) &SHciAsynchEventQueue); + + return; } void shci_send( uint16_t cmd_code, uint8_t len_cmd_payload, uint8_t * p_cmd_payload, TL_EvtPacket_t * p_rsp ) @@ -160,20 +164,8 @@ void shci_send( uint16_t cmd_code, uint8_t len_cmd_payload, uint8_t * p_cmd_payl memcpy( &(p_rsp->evtserial), pCmdBuffer, ((TL_EvtSerial_t*)pCmdBuffer)->evt.plen + TL_EVT_HDR_SIZE ); Cmd_SetStatus(SHCI_TL_CmdAvailable); -} -void shci_notify_asynch_evt(void *pdata) -{ - UNUSED(pdata); - /* Need to parse data in future version */ - shci_user_evt_proc(); -} - -void shci_register_io_bus(tSHciIO *fops) -{ - /* Register IO bus services */ - fops->Init = TL_SYS_Init; - fops->Send = TL_SYS_SendCmd; + return; } /* Private functions ---------------------------------------------------------*/ @@ -198,6 +190,8 @@ static void TlInit( TL_CmdPacket_t * p_cmdbuffer ) Conf.IoBusCallBackUserEvt = TlUserEvtReceived; shciContext.io.Init(&Conf); } + + return; } static void Cmd_SetStatus(SHCI_TL_CmdStatus_t shcicmdstatus) @@ -218,29 +212,35 @@ static void Cmd_SetStatus(SHCI_TL_CmdStatus_t shcicmdstatus) StatusNotCallBackFunction( SHCI_TL_CmdAvailable ); } } + + return; } static void TlCmdEvtReceived(TL_EvtPacket_t *shcievt) { (void)(shcievt); shci_cmd_resp_release(0); /**< Notify the application the Cmd response has been received */ + + return; } static void TlUserEvtReceived(TL_EvtPacket_t *shcievt) { LST_insert_tail(&SHciAsynchEventQueue, (tListNode *)shcievt); shci_notify_asynch_evt((void*) &SHciAsynchEventQueue); /**< Notify the application a full HCI event has been received */ + + return; } /* Weak implementation ----------------------------------------------------------------*/ __WEAK void shci_cmd_resp_wait(uint32_t timeout) { + (void)timeout; + CmdRspStatusFlag = SHCI_TL_CMD_RESP_WAIT; - for (unsigned long start = millis(); (millis() - start) < timeout;) { - if (CmdRspStatusFlag == SHCI_TL_CMD_RESP_RELEASE) { - break; - } - } + while(CmdRspStatusFlag != SHCI_TL_CMD_RESP_RELEASE); + + return; } __WEAK void shci_cmd_resp_release(uint32_t flag) @@ -248,5 +248,6 @@ __WEAK void shci_cmd_resp_release(uint32_t flag) (void)flag; CmdRspStatusFlag = SHCI_TL_CMD_RESP_RELEASE; + + return; } -#endif /* STM32WBxx */ diff --git a/src/utility/STM32Cube_FW/stm32_wpan_common.h b/src/utility/STM32Cube_FW/stm32_wpan_common.h index 5a2b2a55..f407bb98 100644 --- a/src/utility/STM32Cube_FW/stm32_wpan_common.h +++ b/src/utility/STM32Cube_FW/stm32_wpan_common.h @@ -25,9 +25,19 @@ extern "C" { #endif -#define __ASM __asm /*!< asm keyword for GNU Compiler */ -#define __INLINE inline /*!< inline keyword for GNU Compiler */ -#define __STATIC_INLINE static inline +#if defined ( __CC_ARM )||defined (__ARMCC_VERSION) + #define __ASM __asm /*!< asm keyword for ARM Compiler */ + #define __INLINE __inline /*!< inline keyword for ARM Compiler */ + #define __STATIC_INLINE static __inline +#elif defined ( __ICCARM__ ) + #define __ASM __asm /*!< asm keyword for IAR Compiler */ + #define __INLINE inline /*!< inline keyword for IAR Compiler. Only available in High optimization mode! */ + #define __STATIC_INLINE static inline +#elif defined ( __GNUC__ ) + #define __ASM __asm /*!< asm keyword for GNU Compiler */ + #define __INLINE inline /*!< inline keyword for GNU Compiler */ + #define __STATIC_INLINE static inline +#endif #include <stdint.h> #include <string.h> @@ -130,8 +140,29 @@ extern "C" { /* ----------------------------------- * * Packed usage (compiler dependent) * * ----------------------------------- */ +#undef PACKED__ #undef PACKED_STRUCT -#define PACKED_STRUCT struct __packed + +#if defined ( __CC_ARM ) + #if defined ( __GNUC__ ) + /* GNU extension */ + #define PACKED__ __attribute__((packed)) + #define PACKED_STRUCT struct PACKED__ + #elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050U) + #define PACKED__ __attribute__((packed)) + #define PACKED_STRUCT struct PACKED__ + #else + #define PACKED__(TYPE) __packed TYPE + #define PACKED_STRUCT PACKED__(struct) + #endif +#elif defined ( __GNUC__ ) + #define PACKED__ __attribute__((packed)) + #define PACKED_STRUCT struct PACKED__ +#elif defined (__ICCARM__) + #define PACKED_STRUCT __packed struct +#else + #define PACKED_STRUCT __packed struct +#endif #ifdef __cplusplus } diff --git a/src/utility/STM32Cube_FW/stm_list.c b/src/utility/STM32Cube_FW/stm_list.c index 98924414..4c928647 100644 --- a/src/utility/STM32Cube_FW/stm_list.c +++ b/src/utility/STM32Cube_FW/stm_list.c @@ -16,13 +16,13 @@ ****************************************************************************** */ -#if defined(STM32WBxx) + /****************************************************************************** * Include Files ******************************************************************************/ +#include "utilities_common.h" + #include "stm_list.h" -#include "cmsis_gcc.h" -#include "stm32_wpan_common.h" /****************************************************************************** * Function Definitions @@ -33,20 +33,20 @@ void LST_init_head (tListNode * listHead) listHead->prev = listHead; } -bool LST_is_empty (tListNode * listHead) +uint8_t LST_is_empty (tListNode * listHead) { uint32_t primask_bit; - bool return_value; + uint8_t return_value; primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ if(listHead->next == listHead) { - return_value = true; + return_value = TRUE; } else { - return_value = false; + return_value = FALSE; } __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ @@ -204,4 +204,3 @@ void LST_get_prev_node (tListNode * ref_node, tListNode ** node) __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ } -#endif /* STM32WBxx */ diff --git a/src/utility/STM32Cube_FW/stm_list.h b/src/utility/STM32Cube_FW/stm_list.h index 769c2113..b7c3254c 100644 --- a/src/utility/STM32Cube_FW/stm_list.h +++ b/src/utility/STM32Cube_FW/stm_list.h @@ -21,8 +21,6 @@ #define _STM_LIST_H_ /* Includes ------------------------------------------------------------------*/ -#include "stdint.h" -#include "stdbool.h" #include "stm32_wpan_common.h" typedef PACKED_STRUCT _tListNode { @@ -32,7 +30,7 @@ typedef PACKED_STRUCT _tListNode { void LST_init_head (tListNode * listHead); -bool LST_is_empty (tListNode * listHead); +uint8_t LST_is_empty (tListNode * listHead); void LST_insert_head (tListNode * listHead, tListNode * node); diff --git a/src/utility/STM32Cube_FW/tl.h b/src/utility/STM32Cube_FW/tl.h index 354851ac..6bfa2655 100644 --- a/src/utility/STM32Cube_FW/tl.h +++ b/src/utility/STM32Cube_FW/tl.h @@ -61,9 +61,6 @@ extern "C" { #define TL_BLEEVT_CS_PACKET_SIZE (TL_EVT_HDR_SIZE + sizeof(TL_CsEvt_t)) #define TL_BLEEVT_CS_BUFFER_SIZE (sizeof(TL_PacketHeader_t) + TL_BLEEVT_CS_PACKET_SIZE) -#define TL_BLEEVT_CC_PACKET_SIZE (TL_EVT_HDR_SIZE + sizeof(TL_CcEvt_t)) -#define TL_BLEEVT_CC_BUFFER_SIZE (sizeof(TL_PacketHeader_t) + TL_BLEEVT_CC_PACKET_SIZE) - /* Exported types ------------------------------------------------------------*/ /**< Packet header */ typedef PACKED_STRUCT @@ -205,6 +202,19 @@ typedef struct uint8_t *p_BleLldM0CmdBuffer; } TL_BLE_LLD_Config_t; +typedef struct +{ + uint8_t *p_Mac_802_15_4_CmdRspBuffer; + uint8_t *p_Mac_802_15_4_NotAckBuffer; +} TL_MAC_802_15_4_Config_t; + +typedef struct +{ + uint8_t *p_ZigbeeOtCmdRspBuffer; + uint8_t *p_ZigbeeNotAckBuffer; + uint8_t *p_ZigbeeNotifRequestBuffer; +} TL_ZIGBEE_Config_t; + /** * @brief Contain the BLE HCI Init Configuration * @{ @@ -228,6 +238,43 @@ typedef struct uint8_t *p_cmdbuffer; } TL_SYS_InitConf_t; +/***************************************************************************************** + * Event type copied from ble_legacy.h + */ + +typedef PACKED_STRUCT +{ + uint8_t type; + uint8_t data[1]; +} hci_uart_pckt; + +typedef PACKED_STRUCT +{ + uint8_t evt; + uint8_t plen; + uint8_t data[1]; +} hci_event_pckt; + +typedef PACKED_STRUCT +{ + uint8_t subevent; + uint8_t data[1]; +} evt_le_meta_event; + +/** + * Vendor specific event for BLE core. + */ +typedef PACKED_STRUCT +{ + uint16_t ecode; /**< One of the BLE core event codes. */ + uint8_t data[1]; +} evt_blecore_aci; + +/* Bluetooth 48 bit address (in little-endian order). + */ +typedef uint8_t tBDAddr[6]; + + /* Exported constants --------------------------------------------------------*/ /* External variables --------------------------------------------------------*/ /* Exported macros -----------------------------------------------------------*/ @@ -298,6 +345,26 @@ void TL_MM_EvtDone( TL_EvtPacket_t * hcievt ); void TL_TRACES_Init( void ); void TL_TRACES_EvtReceived( TL_EvtPacket_t * hcievt ); +/****************************************************************************** + * MAC 802.15.4 + ******************************************************************************/ +void TL_MAC_802_15_4_Init( TL_MAC_802_15_4_Config_t *p_Config ); +void TL_MAC_802_15_4_SendCmd( void ); +void TL_MAC_802_15_4_CmdEvtReceived( TL_EvtPacket_t * Otbuffer ); +void TL_MAC_802_15_4_NotReceived( TL_EvtPacket_t * Notbuffer ); +void TL_MAC_802_15_4_SendAck ( void ); + +/****************************************************************************** + * ZIGBEE + ******************************************************************************/ +void TL_ZIGBEE_Init( TL_ZIGBEE_Config_t *p_Config ); +void TL_ZIGBEE_SendM4RequestToM0( void ); +void TL_ZIGBEE_SendM4AckToM0Notify ( void ); +void TL_ZIGBEE_NotReceived( TL_EvtPacket_t * Notbuffer ); +void TL_ZIGBEE_CmdEvtReceived( TL_EvtPacket_t * Otbuffer ); +void TL_ZIGBEE_M0RequestReceived(TL_EvtPacket_t * Otbuffer ); +void TL_ZIGBEE_SendM4AckToM0Request(void); + #ifdef __cplusplus } /* extern "C" */ #endif diff --git a/src/utility/STM32Cube_FW/tl_mbox.c b/src/utility/STM32Cube_FW/tl_mbox.c index a9abb181..27a998a3 100644 --- a/src/utility/STM32Cube_FW/tl_mbox.c +++ b/src/utility/STM32Cube_FW/tl_mbox.c @@ -16,7 +16,6 @@ ****************************************************************************** */ -#if defined(STM32WBxx) /* Includes ------------------------------------------------------------------*/ #include "stm32_wpan_common.h" #include "hw.h" @@ -52,13 +51,15 @@ PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_BleLldTable_t TL_BleLldTable; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_SysTable_t TL_SysTable; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_MemManagerTable_t TL_MemManagerTable; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_TracesTable_t TL_TracesTable; +PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_Mac_802_15_4_t TL_Mac_802_15_4_Table; +PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_ZigbeeTable_t TL_Zigbee_Table; /**< tables */ PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode FreeBufQueue; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode TracesEvtQueue; PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static uint8_t CsBuffer[sizeof(TL_PacketHeader_t) + TL_EVT_HDR_SIZE + sizeof(TL_CsEvt_t)]; -PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static tListNode EvtQueue; -PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static tListNode SystemEvtQueue; +PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode EvtQueue; +PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode SystemEvtQueue; static tListNode LocalFreeBufQueue; @@ -76,7 +77,7 @@ static void OutputDbgTrace(TL_MB_PacketType_t packet_type, uint8_t* buffer); /* Public Functions Definition ------------------------------------------------------*/ /****************************************************************************** - * GENERAL + * GENERAL - refer to AN5289 for functions description. ******************************************************************************/ void TL_Enable( void ) { @@ -96,6 +97,8 @@ void TL_Init( void ) TL_RefTable.p_sys_table = &TL_SysTable; TL_RefTable.p_mem_manager_table = &TL_MemManagerTable; TL_RefTable.p_traces_table = &TL_TracesTable; + TL_RefTable.p_mac_802_15_4_table = &TL_Mac_802_15_4_Table; + TL_RefTable.p_zigbee_table = &TL_Zigbee_Table; HW_IPCC_Init(); return; @@ -449,6 +452,139 @@ void TL_BLE_LLD_SendRspAck( void ) } #endif /* BLE_LLD_WB */ +#ifdef MAC_802_15_4_WB +/****************************************************************************** + * MAC 802.15.4 + ******************************************************************************/ +void TL_MAC_802_15_4_Init( TL_MAC_802_15_4_Config_t *p_Config ) +{ + MB_Mac_802_15_4_t * p_mac_802_15_4_table; + + p_mac_802_15_4_table = TL_RefTable.p_mac_802_15_4_table; + + p_mac_802_15_4_table->p_cmdrsp_buffer = p_Config->p_Mac_802_15_4_CmdRspBuffer; + p_mac_802_15_4_table->p_notack_buffer = p_Config->p_Mac_802_15_4_NotAckBuffer; + + HW_IPCC_MAC_802_15_4_Init(); + + return; +} + +void TL_MAC_802_15_4_SendCmd( void ) +{ + ((TL_CmdPacket_t *)(TL_RefTable.p_mac_802_15_4_table->p_cmdrsp_buffer))->cmdserial.type = TL_OTCMD_PKT_TYPE; + + HW_IPCC_MAC_802_15_4_SendCmd(); + + return; +} + +void TL_MAC_802_15_4_SendAck ( void ) +{ + ((TL_CmdPacket_t *)(TL_RefTable.p_mac_802_15_4_table->p_notack_buffer))->cmdserial.type = TL_OTACK_PKT_TYPE; + + HW_IPCC_MAC_802_15_4_SendAck(); + + return; +} + +void HW_IPCC_MAC_802_15_4_CmdEvtNot(void) +{ + TL_MAC_802_15_4_CmdEvtReceived( (TL_EvtPacket_t*)(TL_RefTable.p_mac_802_15_4_table->p_cmdrsp_buffer) ); + + return; +} + +void HW_IPCC_MAC_802_15_4_EvtNot( void ) +{ + TL_MAC_802_15_4_NotReceived( (TL_EvtPacket_t*)(TL_RefTable.p_mac_802_15_4_table->p_notack_buffer) ); + + return; +} + +__WEAK void TL_MAC_802_15_4_CmdEvtReceived( TL_EvtPacket_t * Otbuffer ){}; +__WEAK void TL_MAC_802_15_4_NotReceived( TL_EvtPacket_t * Notbuffer ){}; +#endif + +#ifdef ZIGBEE_WB +/****************************************************************************** + * ZIGBEE + ******************************************************************************/ +void TL_ZIGBEE_Init( TL_ZIGBEE_Config_t *p_Config ) +{ + MB_ZigbeeTable_t * p_zigbee_table; + + p_zigbee_table = TL_RefTable.p_zigbee_table; + p_zigbee_table->appliCmdM4toM0_buffer = p_Config->p_ZigbeeOtCmdRspBuffer; + p_zigbee_table->notifM0toM4_buffer = p_Config->p_ZigbeeNotAckBuffer; + p_zigbee_table->requestM0toM4_buffer = p_Config->p_ZigbeeNotifRequestBuffer; + + HW_IPCC_ZIGBEE_Init(); + + return; +} + +/* Zigbee M4 to M0 Request */ +void TL_ZIGBEE_SendM4RequestToM0( void ) +{ + ((TL_CmdPacket_t *)(TL_RefTable.p_zigbee_table->appliCmdM4toM0_buffer))->cmdserial.type = TL_OTCMD_PKT_TYPE; + + HW_IPCC_ZIGBEE_SendM4RequestToM0(); + + return; +} + +/* Used to receive an ACK from the M0 */ +void HW_IPCC_ZIGBEE_RecvAppliAckFromM0(void) +{ + TL_ZIGBEE_CmdEvtReceived( (TL_EvtPacket_t*)(TL_RefTable.p_zigbee_table->appliCmdM4toM0_buffer) ); + + return; +} + +/* Zigbee notification from M0 to M4 */ +void HW_IPCC_ZIGBEE_RecvM0NotifyToM4( void ) +{ + TL_ZIGBEE_NotReceived( (TL_EvtPacket_t*)(TL_RefTable.p_zigbee_table->notifM0toM4_buffer) ); + + return; +} + +/* Send an ACK to the M0 for a Notification */ +void TL_ZIGBEE_SendM4AckToM0Notify ( void ) +{ + ((TL_CmdPacket_t *)(TL_RefTable.p_zigbee_table->notifM0toM4_buffer))->cmdserial.type = TL_OTACK_PKT_TYPE; + + HW_IPCC_ZIGBEE_SendM4AckToM0Notify(); + + return; +} + +/* Zigbee M0 to M4 Request */ +void HW_IPCC_ZIGBEE_RecvM0RequestToM4( void ) +{ + TL_ZIGBEE_M0RequestReceived( (TL_EvtPacket_t*)(TL_RefTable.p_zigbee_table->requestM0toM4_buffer) ); + + return; +} + +/* Send an ACK to the M0 for a Request */ +void TL_ZIGBEE_SendM4AckToM0Request(void) +{ + ((TL_CmdPacket_t *)(TL_RefTable.p_zigbee_table->requestM0toM4_buffer))->cmdserial.type = TL_OTACK_PKT_TYPE; + + HW_IPCC_ZIGBEE_SendM4AckToM0Request(); + + return; +} + + +__WEAK void TL_ZIGBEE_CmdEvtReceived( TL_EvtPacket_t * Otbuffer ){}; +__WEAK void TL_ZIGBEE_NotReceived( TL_EvtPacket_t * Notbuffer ){}; +#endif + + + /****************************************************************************** * MEMORY MANAGER ******************************************************************************/ @@ -710,4 +846,3 @@ static void OutputDbgTrace(TL_MB_PacketType_t packet_type, uint8_t* buffer) return; } -#endif /* STM32WBxx */ From d758a661f9f2c033209219a1d86fccad7a2a8ef3 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Wed, 5 Apr 2023 10:18:52 +0200 Subject: [PATCH 129/226] chore: adapt STM32Cube_FW sources Compare to previous patch, do the minimum changes required to ease further update. Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- src/utility/STM32Cube_FW/app_conf_default.h | 47 +++++++++++++++------ src/utility/STM32Cube_FW/ble_bufsize.h | 11 ++++- src/utility/STM32Cube_FW/hw.h | 15 +++++-- src/utility/STM32Cube_FW/hw_ipcc.c | 4 +- src/utility/STM32Cube_FW/shci.c | 3 +- src/utility/STM32Cube_FW/shci_tl.c | 18 +++++++- src/utility/STM32Cube_FW/stm_list.c | 7 ++- src/utility/STM32Cube_FW/tl_mbox.c | 8 +++- 8 files changed, 90 insertions(+), 23 deletions(-) diff --git a/src/utility/STM32Cube_FW/app_conf_default.h b/src/utility/STM32Cube_FW/app_conf_default.h index 51bd33af..e89df140 100644 --- a/src/utility/STM32Cube_FW/app_conf_default.h +++ b/src/utility/STM32Cube_FW/app_conf_default.h @@ -1,9 +1,9 @@ /* USER CODE BEGIN Header */ /** ****************************************************************************** - * @file app_conf.h + * @file app_conf_default.h * @author MCD Application Team - * @brief Application configuration file for STM32WPAN Middleware. + * @brief Default application configuration file for STM32WPAN Middleware. ****************************************************************************** * @attention * @@ -19,18 +19,38 @@ /* USER CODE END Header */ /* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef APP_CONF_H -#define APP_CONF_H - +#ifndef APP_CONF_DEFAULT_H +#define APP_CONF_DEFAULT_H +#if 0 #include "hw.h" #include "hw_conf.h" #include "hw_if.h" #include "ble_bufsize.h" - +#endif /****************************************************************************** * Application Config ******************************************************************************/ +/**< generic parameters ******************************************************/ +/* HCI related defines */ + +#define ACI_HAL_SET_TX_POWER_LEVEL 0xFC0F +#define ACI_WRITE_CONFIG_DATA_OPCODE 0xFC0C +#define ACI_READ_CONFIG_DATA_OPCODE 0xFC0D +#define MAX_HCI_ACL_PACKET_SIZE (sizeof(TL_PacketHeader_t) + 5 + 251) +#define HCI_RESET 0x0C03 + +#ifndef BLE_SHARED_MEM_BYTE_ORDER + #define BLE_SHARED_MEM_BYTE_ORDER MSBFIRST +#endif +#define BLE_MODULE_SHARED_MEM_BUFFER_SIZE 128 + +/** + * Define Tx Power + */ +#define CFG_TX_POWER (0x18) /* -0.15dBm */ + +#if 0 /** * Define Secure Connections Support */ @@ -104,7 +124,7 @@ #define CFG_FW_SUBVERSION (1) #define CFG_FW_BRANCH (0) #define CFG_FW_BUILD (0) - +#endif /****************************************************************************** * BLE Stack ******************************************************************************/ @@ -152,13 +172,15 @@ * Prepare Write List size in terms of number of packet * This parameter is ignored by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set */ -#define CFG_BLE_PREPARE_WRITE_LIST_SIZE BLE_PREP_WRITE_X_ATT(CFG_BLE_MAX_ATT_MTU) +// #define CFG_BLE_PREPARE_WRITE_LIST_SIZE BLE_PREP_WRITE_X_ATT(CFG_BLE_MAX_ATT_MTU) +#define CFG_BLE_PREPARE_WRITE_LIST_SIZE (0x3A) /** * Number of allocated memory blocks * This parameter is overwritten by the CPU2 with an hardcoded optimal value when the parameter CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set */ -#define CFG_BLE_MBLOCK_COUNT (BLE_MBLOCKS_CALC(CFG_BLE_PREPARE_WRITE_LIST_SIZE, CFG_BLE_MAX_ATT_MTU, CFG_BLE_NUM_LINK)) +//#define CFG_BLE_MBLOCK_COUNT (BLE_MBLOCKS_CALC(CFG_BLE_PREPARE_WRITE_LIST_SIZE, CFG_BLE_MAX_ATT_MTU, CFG_BLE_NUM_LINK)) +#define CFG_BLE_MBLOCK_COUNT (0x79) /** * Enable or disable the Extended Packet length feature. Valid values are 0 or 1. @@ -250,7 +272,7 @@ * 0: LE Power Class 2-3 * other bits: complete with Options_extension flag */ -#define CFG_BLE_OPTIONS (SHCI_C2_BLE_INIT_OPTIONS_LL_HOST | SHCI_C2_BLE_INIT_OPTIONS_WITH_SVC_CHANGE_DESC | SHCI_C2_BLE_INIT_OPTIONS_DEVICE_NAME_RW | SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV | SHCI_C2_BLE_INIT_OPTIONS_CS_ALGO2 | SHCI_C2_BLE_INIT_OPTIONS_FULL_GATTDB_NVM | SHCI_C2_BLE_INIT_OPTIONS_GATT_CACHING_NOTUSED | SHCI_C2_BLE_INIT_OPTIONS_POWER_CLASS_2_3) +#define CFG_BLE_OPTIONS (SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY) /** * BLE stack Options_extension flags to be configured with: @@ -323,6 +345,7 @@ #define CFG_BLE_CORE_VERSION (SHCI_C2_BLE_INIT_BLE_CORE_5_3) +#if 0 /****************************************************************************** * Transport Layer ******************************************************************************/ @@ -657,5 +680,5 @@ typedef enum #define CFG_OTP_BASE_ADDRESS OTP_AREA_BASE #define CFG_OTP_END_ADRESS OTP_AREA_END_ADDR - -#endif /*APP_CONF_H */ +#endif +#endif /*APP_CONF_DEFAULT_H */ diff --git a/src/utility/STM32Cube_FW/ble_bufsize.h b/src/utility/STM32Cube_FW/ble_bufsize.h index 7b7c170f..53cf59a8 100644 --- a/src/utility/STM32Cube_FW/ble_bufsize.h +++ b/src/utility/STM32Cube_FW/ble_bufsize.h @@ -75,15 +75,22 @@ ((pw) + MAX(BLE_MEM_BLOCK_X_MTU(mtu, n_link), \ BLE_MBLOCKS_SECURE_CONNECTIONS)) +/* + * BLE_DEFAULT_MBLOCKS_COUNT: default memory blocks count + */ +#define BLE_DEFAULT_MBLOCKS_COUNT(n_link) \ + BLE_MBLOCKS_CALC(BLE_DEFAULT_PREP_WRITE_LIST_SIZE, \ + BLE_DEFAULT_MAX_ATT_MTU, n_link) + /* * BLE_FIXED_BUFFER_SIZE_BYTES: * A part of the RAM, is dynamically allocated by initializing all the pointers * defined in a global context variable "mem_alloc_ctx_p". - * This initialization is made in the Dynamic_allocator functions, which + * This initialization is made in the Dynamic_allocator functions, which * assign a portion of RAM given by the external application to the above * mentioned "global pointers". * - * The size of this Dynamic RAM is made of 2 main components: + * The size of this Dynamic RAM is made of 2 main components: * - a part that is parameters-dependent (num of links, GATT buffers, ...), * and which value is made explicit by the following macro; * - a part, that may be considered "fixed", i.e. independent from the above diff --git a/src/utility/STM32Cube_FW/hw.h b/src/utility/STM32Cube_FW/hw.h index 503fa2ca..1472a5e8 100644 --- a/src/utility/STM32Cube_FW/hw.h +++ b/src/utility/STM32Cube_FW/hw.h @@ -26,14 +26,23 @@ extern "C" { #endif /* Includes ------------------------------------------------------------------*/ +#include "stm32_def.h" +#include "stm32wbxx_ll_bus.h" +#include "stm32wbxx_ll_exti.h" +#include "stm32wbxx_ll_system.h" +#include "stm32wbxx_ll_rcc.h" +#include "stm32wbxx_ll_ipcc.h" +#include "stm32wbxx_ll_cortex.h" +#include "stm32wbxx_ll_utils.h" +#include "stm32wbxx_ll_pwr.h" /****************************************************************************** * HW IPCC ******************************************************************************/ void HW_IPCC_Enable( void ); void HW_IPCC_Init( void ); - void HW_IPCC_Rx_Handler( void ); - void HW_IPCC_Tx_Handler( void ); +#define HW_IPCC_Rx_Handler IPCC_C1_RX_IRQHandler +#define HW_IPCC_Tx_Handler IPCC_C1_TX_IRQHandler void HW_IPCC_BLE_Init( void ); void HW_IPCC_BLE_SendCmd( void ); @@ -76,7 +85,7 @@ extern "C" { void HW_IPCC_BLE_LLD_ReceiveRsp( void ); void HW_IPCC_BLE_LLD_SendRspAck( void ); - + void HW_IPCC_TRACES_Init( void ); void HW_IPCC_TRACES_EvtNot( void ); diff --git a/src/utility/STM32Cube_FW/hw_ipcc.c b/src/utility/STM32Cube_FW/hw_ipcc.c index fd620b85..3461cbed 100644 --- a/src/utility/STM32Cube_FW/hw_ipcc.c +++ b/src/utility/STM32Cube_FW/hw_ipcc.c @@ -18,8 +18,9 @@ */ /* USER CODE END Header */ +#if defined(STM32WBxx) /* Includes ------------------------------------------------------------------*/ -#include "app_common.h" +#include "hw.h" #include "mbox_def.h" /* Global variables ---------------------------------------------------------*/ @@ -667,3 +668,4 @@ static void HW_IPCC_TRACES_EvtHandler( void ) } __weak void HW_IPCC_TRACES_EvtNot( void ){}; +#endif /* STM32WBxx */ diff --git a/src/utility/STM32Cube_FW/shci.c b/src/utility/STM32Cube_FW/shci.c index 301db76d..cb7d7bd2 100644 --- a/src/utility/STM32Cube_FW/shci.c +++ b/src/utility/STM32Cube_FW/shci.c @@ -16,7 +16,7 @@ ****************************************************************************** */ - +#if defined(STM32WBxx) /* Includes ------------------------------------------------------------------*/ #include "stm32_wpan_common.h" @@ -739,3 +739,4 @@ SHCI_CmdStatus_t SHCI_GetWirelessFwInfo( WirelessFwInfo_t* pWirelessInfo ) return (SHCI_Success); } +#endif /* STM32WBxx */ diff --git a/src/utility/STM32Cube_FW/shci_tl.c b/src/utility/STM32Cube_FW/shci_tl.c index 2b387b1b..a336aa6e 100644 --- a/src/utility/STM32Cube_FW/shci_tl.c +++ b/src/utility/STM32Cube_FW/shci_tl.c @@ -16,12 +16,13 @@ ****************************************************************************** */ - +#if defined(STM32WBxx) /* Includes ------------------------------------------------------------------*/ #include "stm32_wpan_common.h" #include "stm_list.h" #include "shci_tl.h" +#include "stm32_def.h" /* Private typedef -----------------------------------------------------------*/ typedef enum @@ -168,6 +169,20 @@ void shci_send( uint16_t cmd_code, uint8_t len_cmd_payload, uint8_t * p_cmd_payl return; } +void shci_notify_asynch_evt(void *pdata) +{ + UNUSED(pdata); + /* Need to parse data in future version */ + shci_user_evt_proc(); +} + +void shci_register_io_bus(tSHciIO *fops) +{ + /* Register IO bus services */ + fops->Init = TL_SYS_Init; + fops->Send = TL_SYS_SendCmd; +} + /* Private functions ---------------------------------------------------------*/ static void TlInit( TL_CmdPacket_t * p_cmdbuffer ) { @@ -251,3 +266,4 @@ __WEAK void shci_cmd_resp_release(uint32_t flag) return; } +#endif /* STM32WBxx */ diff --git a/src/utility/STM32Cube_FW/stm_list.c b/src/utility/STM32Cube_FW/stm_list.c index 4c928647..4e8c3643 100644 --- a/src/utility/STM32Cube_FW/stm_list.c +++ b/src/utility/STM32Cube_FW/stm_list.c @@ -16,11 +16,13 @@ ****************************************************************************** */ - +#if defined(STM32WBxx) /****************************************************************************** * Include Files ******************************************************************************/ -#include "utilities_common.h" +#include "stdint.h" +#include "cmsis_gcc.h" +#include "stm32_wpan_common.h" #include "stm_list.h" @@ -204,3 +206,4 @@ void LST_get_prev_node (tListNode * ref_node, tListNode ** node) __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ } +#endif /* STM32WBxx */ diff --git a/src/utility/STM32Cube_FW/tl_mbox.c b/src/utility/STM32Cube_FW/tl_mbox.c index 27a998a3..ff219b97 100644 --- a/src/utility/STM32Cube_FW/tl_mbox.c +++ b/src/utility/STM32Cube_FW/tl_mbox.c @@ -16,6 +16,7 @@ ****************************************************************************** */ +#if defined(STM32WBxx) /* Includes ------------------------------------------------------------------*/ #include "stm32_wpan_common.h" #include "hw.h" @@ -51,9 +52,10 @@ PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_BleLldTable_t TL_BleLldTable; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_SysTable_t TL_SysTable; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_MemManagerTable_t TL_MemManagerTable; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_TracesTable_t TL_TracesTable; +#if 0 PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_Mac_802_15_4_t TL_Mac_802_15_4_Table; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_ZigbeeTable_t TL_Zigbee_Table; - +#endif /**< tables */ PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode FreeBufQueue; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode TracesEvtQueue; @@ -97,8 +99,11 @@ void TL_Init( void ) TL_RefTable.p_sys_table = &TL_SysTable; TL_RefTable.p_mem_manager_table = &TL_MemManagerTable; TL_RefTable.p_traces_table = &TL_TracesTable; + +#if 0 TL_RefTable.p_mac_802_15_4_table = &TL_Mac_802_15_4_Table; TL_RefTable.p_zigbee_table = &TL_Zigbee_Table; +#endif HW_IPCC_Init(); return; @@ -846,3 +851,4 @@ static void OutputDbgTrace(TL_MB_PacketType_t packet_type, uint8_t* buffer) return; } +#endif /* STM32WBxx */ From 751295300e5fb7fc1f277410e8aa76f4e29f7302 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Mon, 12 Dec 2022 17:17:48 +0100 Subject: [PATCH 130/226] fix: include a timeout when waiting for the cmd_resp Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- src/utility/STM32Cube_FW/shci_tl.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/utility/STM32Cube_FW/shci_tl.c b/src/utility/STM32Cube_FW/shci_tl.c index a336aa6e..d1d35f5b 100644 --- a/src/utility/STM32Cube_FW/shci_tl.c +++ b/src/utility/STM32Cube_FW/shci_tl.c @@ -23,6 +23,7 @@ #include "stm_list.h" #include "shci_tl.h" #include "stm32_def.h" +#include "wiring_time.h" /* Private typedef -----------------------------------------------------------*/ typedef enum @@ -250,11 +251,12 @@ static void TlUserEvtReceived(TL_EvtPacket_t *shcievt) /* Weak implementation ----------------------------------------------------------------*/ __WEAK void shci_cmd_resp_wait(uint32_t timeout) { - (void)timeout; - CmdRspStatusFlag = SHCI_TL_CMD_RESP_WAIT; - while(CmdRspStatusFlag != SHCI_TL_CMD_RESP_RELEASE); - + for (unsigned long start = millis(); (millis() - start) < timeout;) { + if (CmdRspStatusFlag == SHCI_TL_CMD_RESP_RELEASE) { + break; + } + } return; } From 9b421c27d620e27334f6b1cb2e55a6c75ef6055d Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Mon, 12 Dec 2022 17:29:27 +0100 Subject: [PATCH 131/226] chore: add support for customize app_conf_default.h Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- src/utility/STM32Cube_FW/app_conf_default.h | 86 ++++++++++++++++----- 1 file changed, 68 insertions(+), 18 deletions(-) diff --git a/src/utility/STM32Cube_FW/app_conf_default.h b/src/utility/STM32Cube_FW/app_conf_default.h index e89df140..1f17900d 100644 --- a/src/utility/STM32Cube_FW/app_conf_default.h +++ b/src/utility/STM32Cube_FW/app_conf_default.h @@ -48,7 +48,9 @@ /** * Define Tx Power */ -#define CFG_TX_POWER (0x18) /* -0.15dBm */ +#ifndef CFG_TX_POWER + #define CFG_TX_POWER (0x18) /* -0.15dBm */ +#endif #if 0 /** @@ -132,13 +134,25 @@ * Maximum number of simultaneous connections that the device will support. * Valid values are from 1 to 8 */ -#define CFG_BLE_NUM_LINK 8 +#ifndef CFG_BLE_NUM_LINK +#ifdef STM32WB15xx + #define CFG_BLE_NUM_LINK 3 +#else + #define CFG_BLE_NUM_LINK 8 +#endif +#endif /** * Maximum number of Services that can be stored in the GATT database. * Note that the GAP and GATT services are automatically added so this parameter should be 2 plus the number of user services */ -#define CFG_BLE_NUM_GATT_SERVICES 8 +#ifndef CFG_BLE_NUM_GATT_SERVICES +#ifdef STM32WB15xx + #define CFG_BLE_NUM_GATT_SERVICES 4 +#else + #define CFG_BLE_NUM_GATT_SERVICES 8 +#endif +#endif /** * Maximum number of Attributes @@ -147,13 +161,21 @@ * Note that certain characteristics and relative descriptors are added automatically during device initialization * so this parameters should be 9 plus the number of user Attributes */ -#define CFG_BLE_NUM_GATT_ATTRIBUTES 68 +#ifndef CFG_BLE_NUM_GATT_ATTRIBUTES +#ifdef STM32WB15xx + #define CFG_BLE_NUM_GATT_ATTRIBUTES 30 +#else + #define CFG_BLE_NUM_GATT_ATTRIBUTES 68 +#endif +#endif /** * Maximum supported ATT_MTU size * This parameter is ignored by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set */ -#define CFG_BLE_MAX_ATT_MTU (156) +#ifndef CFG_BLE_MAX_ATT_MTU + #define CFG_BLE_MAX_ATT_MTU (156) +#endif /** * Size of the storage area for Attribute values @@ -166,14 +188,22 @@ * The total amount of memory needed is the sum of the above quantities for each attribute. * This parameter is ignored by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set */ -#define CFG_BLE_ATT_VALUE_ARRAY_SIZE (1344) +#ifndef CFG_BLE_ATT_VALUE_ARRAY_SIZE +#ifdef STM32WB15xx + #define CFG_BLE_ATT_VALUE_ARRAY_SIZE (1290) +#else + #define CFG_BLE_ATT_VALUE_ARRAY_SIZE (1344) +#endif +#endif /** * Prepare Write List size in terms of number of packet * This parameter is ignored by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set */ // #define CFG_BLE_PREPARE_WRITE_LIST_SIZE BLE_PREP_WRITE_X_ATT(CFG_BLE_MAX_ATT_MTU) -#define CFG_BLE_PREPARE_WRITE_LIST_SIZE (0x3A) +#ifndef CFG_BLE_PREPARE_WRITE_LIST_SIZE + #define CFG_BLE_PREPARE_WRITE_LIST_SIZE (0x3A) +#endif /** * Number of allocated memory blocks @@ -185,12 +215,16 @@ /** * Enable or disable the Extended Packet length feature. Valid values are 0 or 1. */ -#define CFG_BLE_DATA_LENGTH_EXTENSION 1 +#ifndef CFG_BLE_DATA_LENGTH_EXTENSION + #define CFG_BLE_DATA_LENGTH_EXTENSION 1 +#endif /** * Sleep clock accuracy in Slave mode (ppm value) */ -#define CFG_BLE_SLAVE_SCA 500 +#ifndef CFG_BLE_SLAVE_SCA + #define CFG_BLE_SLAVE_SCA 500 +#endif /** * Sleep clock accuracy in Master mode @@ -203,7 +237,9 @@ * 6 : 21 ppm to 30 ppm * 7 : 0 ppm to 20 ppm */ -#define CFG_BLE_MASTER_SCA 0 +#ifndef CFG_BLE_MASTER_SCA + #define CFG_BLE_MASTER_SCA 0 +#endif /** * LsSource @@ -212,21 +248,27 @@ * - bit 1: 1: STM32WB5M Module device 0: Other devices as STM32WBxx SOC, STM32WB1M module * - bit 2: 1: HSE/1024 Clock config 0: LSE Clock config */ -#if defined(STM32WB5Mxx) - #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_MOD5MM_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) -#else - #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_OTHER_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) +#ifndef CFG_BLE_LS_SOURCE + #if defined(STM32WB5Mxx) + #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_MOD5MM_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) + #else + #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_OTHER_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) + #endif #endif /** * Start up time of the high speed (16 or 32 MHz) crystal oscillator in units of 625/256 us (~2.44 us) */ -#define CFG_BLE_HSE_STARTUP_TIME 0x148 +#ifndef CFG_BLE_HSE_STARTUP_TIME + #define CFG_BLE_HSE_STARTUP_TIME 0x148 +#endif /** * Maximum duration of the connection event when the device is in Slave mode in units of 625/256 us (~2.44 us) */ -#define CFG_BLE_MAX_CONN_EVENT_LENGTH (0xFFFFFFFF) +#ifndef CFG_BLE_MAX_CONN_EVENT_LENGTH + #define CFG_BLE_MAX_CONN_EVENT_LENGTH (0xFFFFFFFF) +#endif /** * Viterbi Mode @@ -314,7 +356,11 @@ * This parameter is considered by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV flag set */ -#define CFG_BLE_MAX_ADV_SET_NBR (8) +#if defined(STM32WB15xx) + #define CFG_BLE_MAX_ADV_SET_NBR (3) +#else + #define CFG_BLE_MAX_ADV_SET_NBR (8) +#endif /* Maximum advertising data length (in bytes) * Range: 31 .. 1650 with limitation: @@ -323,7 +369,11 @@ * This parameter is considered by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV flag set */ -#define CFG_BLE_MAX_ADV_DATA_LEN (207) +#if defined(STM32WB15xx) + #define CFG_BLE_MAX_ADV_DATA_LEN (414) +#else + #define CFG_BLE_MAX_ADV_DATA_LEN (207) +#endif /* RF TX Path Compensation Value (16-bit signed integer). Units: 0.1 dB. * Range: -1280 .. 1280 From 1ec4563f20df1bc36ac489706a3123b0fd1ce653 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Wed, 8 Feb 2023 16:50:46 +0100 Subject: [PATCH 132/226] fix: warning outside array bounds array subscript 'TL_CcEvt_t[0]' is partly outside array bounds Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- src/utility/STM32Cube_FW/shci.c | 60 ++++++++++++++++----------------- src/utility/STM32Cube_FW/tl.h | 3 ++ 2 files changed, 33 insertions(+), 30 deletions(-) diff --git a/src/utility/STM32Cube_FW/shci.c b/src/utility/STM32Cube_FW/shci.c index cb7d7bd2..6348145f 100644 --- a/src/utility/STM32Cube_FW/shci.c +++ b/src/utility/STM32Cube_FW/shci.c @@ -42,7 +42,7 @@ uint8_t SHCI_C2_FUS_GetState( SHCI_FUS_GetState_ErrorCode_t *p_error_code ) /** * A command status event + payload has the same size than the expected command complete */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE + 1]; + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; @@ -66,7 +66,7 @@ SHCI_CmdStatus_t SHCI_C2_FUS_FwUpgrade( uint32_t fw_src_add, uint32_t fw_dest_a * TL_BLEEVT_CS_BUFFER_SIZE is 15 bytes so it is large enough to hold the 8 bytes of command parameters * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; uint32_t *p_cmd; uint8_t cmd_length; @@ -101,7 +101,7 @@ SHCI_CmdStatus_t SHCI_C2_FUS_FwDelete( void ) /** * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; @@ -119,7 +119,7 @@ SHCI_CmdStatus_t SHCI_C2_FUS_UpdateAuthKey( SHCI_C2_FUS_UpdateAuthKey_Cmd_Param_ /** * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; @@ -137,7 +137,7 @@ SHCI_CmdStatus_t SHCI_C2_FUS_LockAuthKey( void ) /** * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; @@ -155,7 +155,7 @@ SHCI_CmdStatus_t SHCI_C2_FUS_StoreUsrKey( SHCI_C2_FUS_StoreUsrKey_Cmd_Param_t *p /** * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE + 1]; + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; uint8_t local_payload_len; @@ -189,7 +189,7 @@ SHCI_CmdStatus_t SHCI_C2_FUS_LoadUsrKey( uint8_t key_index ) /** * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; @@ -209,7 +209,7 @@ SHCI_CmdStatus_t SHCI_C2_FUS_StartWs( void ) /** * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; @@ -227,7 +227,7 @@ SHCI_CmdStatus_t SHCI_C2_FUS_LockUsrKey( uint8_t key_index ) /** * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; @@ -247,7 +247,7 @@ SHCI_CmdStatus_t SHCI_C2_FUS_UnloadUsrKey( uint8_t key_index ) /** * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; @@ -267,7 +267,7 @@ SHCI_CmdStatus_t SHCI_C2_FUS_ActivateAntiRollback( void ) /** * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; @@ -285,7 +285,7 @@ SHCI_CmdStatus_t SHCI_C2_BLE_Init( SHCI_C2_Ble_Init_Cmd_Packet_t *pCmdPacket ) /** * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; @@ -303,7 +303,7 @@ SHCI_CmdStatus_t SHCI_C2_THREAD_Init( void ) /** * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; @@ -321,7 +321,7 @@ SHCI_CmdStatus_t SHCI_C2_LLDTESTS_Init( uint8_t param_size, uint8_t * p_param ) /** * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; @@ -339,7 +339,7 @@ SHCI_CmdStatus_t SHCI_C2_BLE_LLD_Init( uint8_t param_size, uint8_t * p_param ) /** * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; @@ -357,7 +357,7 @@ SHCI_CmdStatus_t SHCI_C2_ZIGBEE_Init( void ) /** * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; @@ -375,7 +375,7 @@ SHCI_CmdStatus_t SHCI_C2_DEBUG_Init( SHCI_C2_DEBUG_Init_Cmd_Packet_t *pCmdPacket /** * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; @@ -393,7 +393,7 @@ SHCI_CmdStatus_t SHCI_C2_FLASH_EraseActivity( SHCI_EraseActivity_t erase_activit /** * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; @@ -413,7 +413,7 @@ SHCI_CmdStatus_t SHCI_C2_CONCURRENT_SetMode( SHCI_C2_CONCURRENT_Mode_Param_t Mod /** * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; @@ -433,7 +433,7 @@ SHCI_CmdStatus_t SHCI_C2_CONCURRENT_GetNextBleEvtTime( SHCI_C2_CONCURRENT_GetNex /** * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE+4]; + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; @@ -453,7 +453,7 @@ SHCI_CmdStatus_t SHCI_C2_CONCURRENT_EnableNext_802154_EvtNotification( void ) /** * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; @@ -471,7 +471,7 @@ SHCI_CmdStatus_t SHCI_C2_FLASH_StoreData( SHCI_C2_FLASH_Ip_t Ip ) /** * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; @@ -491,7 +491,7 @@ SHCI_CmdStatus_t SHCI_C2_FLASH_EraseData( SHCI_C2_FLASH_Ip_t Ip ) /** * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; @@ -511,7 +511,7 @@ SHCI_CmdStatus_t SHCI_C2_RADIO_AllowLowPower( SHCI_C2_FLASH_Ip_t Ip,uint8_t Fla /** * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; @@ -532,7 +532,7 @@ SHCI_CmdStatus_t SHCI_C2_MAC_802_15_4_Init( void ) /** * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; @@ -550,7 +550,7 @@ SHCI_CmdStatus_t SHCI_C2_Reinit( void ) /** * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; @@ -569,7 +569,7 @@ SHCI_CmdStatus_t SHCI_C2_ExtpaConfig(uint32_t gpio_port, uint16_t gpio_pin_numbe * TL_BLEEVT_CS_BUFFER_SIZE is 15 bytes so it is large enough to hold the 8 bytes of command parameters * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; @@ -593,7 +593,7 @@ SHCI_CmdStatus_t SHCI_C2_SetFlashActivityControl(SHCI_C2_SET_FLASH_ACTIVITY_CONT * TL_BLEEVT_CS_BUFFER_SIZE is 15 bytes so it is large enough to hold the 1 byte of command parameter * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; @@ -613,7 +613,7 @@ SHCI_CmdStatus_t SHCI_C2_Config(SHCI_C2_CONFIG_Cmd_Param_t *pCmdPacket) /** * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; @@ -631,7 +631,7 @@ SHCI_CmdStatus_t SHCI_C2_802_15_4_DeInit( void ) /** * Buffer is large enough to hold command complete without payload */ - uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; diff --git a/src/utility/STM32Cube_FW/tl.h b/src/utility/STM32Cube_FW/tl.h index 6bfa2655..63126b3d 100644 --- a/src/utility/STM32Cube_FW/tl.h +++ b/src/utility/STM32Cube_FW/tl.h @@ -61,6 +61,9 @@ extern "C" { #define TL_BLEEVT_CS_PACKET_SIZE (TL_EVT_HDR_SIZE + sizeof(TL_CsEvt_t)) #define TL_BLEEVT_CS_BUFFER_SIZE (sizeof(TL_PacketHeader_t) + TL_BLEEVT_CS_PACKET_SIZE) +#define TL_BLEEVT_CC_PACKET_SIZE (TL_EVT_HDR_SIZE + sizeof(TL_CcEvt_t)) +#define TL_BLEEVT_CC_BUFFER_SIZE (sizeof(TL_PacketHeader_t) + TL_BLEEVT_CC_PACKET_SIZE) + /* Exported types ------------------------------------------------------------*/ /**< Packet header */ typedef PACKED_STRUCT From a9bef0cf0ed3b7ee6a2cabca2bfe82b783be0104 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Wed, 5 Apr 2023 11:40:47 +0200 Subject: [PATCH 133/226] chore: add new field initalizer for SHCI_C2_Ble_Init_Cmd_Packet_t Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- src/utility/HCISharedMemTransport.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/utility/HCISharedMemTransport.cpp b/src/utility/HCISharedMemTransport.cpp index e51b5fa6..0db95041 100644 --- a/src/utility/HCISharedMemTransport.cpp +++ b/src/utility/HCISharedMemTransport.cpp @@ -658,7 +658,8 @@ int HCISharedMemTransportClass::stm32wb_start_ble(void) CFG_BLE_MAX_ADV_DATA_LEN, CFG_BLE_TX_PATH_COMPENS, CFG_BLE_RX_PATH_COMPENS, - CFG_BLE_CORE_VERSION + CFG_BLE_CORE_VERSION, + CFG_BLE_OPTIONS_EXT }; /** * Starts the BLE Stack on CPU2 From bc085c13d09be0c565b2ac1dbb3afdca7e4a6b9c Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Thu, 13 Jul 2023 15:45:56 +0200 Subject: [PATCH 134/226] chore: bump library version to 1.2.5 Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index c8a3119d..35083868 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=STM32duinoBLE -version=1.2.4 +version=1.2.5 author=Arduino, SRA maintainer=stm32duino sentence=Fork of ArduinoBLE library to add the support of STM32WB, SPBTLE-RF, SPBTLE-1S, BLUENRG-M2SP and BLUENRG-M0 BLE modules. From a93bdadef5ed1408a7cdfb7f65eea19568dc0b09 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Thu, 13 Jul 2023 16:49:37 +0200 Subject: [PATCH 135/226] chore(editorconfig): do not apply change to patch files Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- .editorconfig | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.editorconfig b/.editorconfig index c7bf2228..47433680 100644 --- a/.editorconfig +++ b/.editorconfig @@ -5,6 +5,12 @@ indent_style = space indent_size = 2 trim_trailing_whitespace = true +[*.patch] +insert_final_newline = unset +indent_style = unset +indent_size = unset +trim_trailing_whitespace = unset + [*.md] trim_trailing_whitespace = false From 98e8e3f1441509437c7b72cd4f887af09b93967f Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Thu, 13 Jul 2023 18:28:25 +0200 Subject: [PATCH 136/226] fix: regenerate STM32Cube_FW patches Prepare update to version 1.17.0 Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- ...001-chore-adapt-STM32Cube_FW-sources.patch | 78 ++--- ...imeout-when-waiting-for-the-cmd_resp.patch | 11 +- ...ort-for-customize-app_conf_default.h.patch | 6 +- ...004-fix-warning-outside-array-bounds.patch | 304 ------------------ 4 files changed, 35 insertions(+), 364 deletions(-) delete mode 100644 extras/STM32Cube_FW/0004-fix-warning-outside-array-bounds.patch diff --git a/extras/STM32Cube_FW/0001-chore-adapt-STM32Cube_FW-sources.patch b/extras/STM32Cube_FW/0001-chore-adapt-STM32Cube_FW-sources.patch index 246a1257..ce3c8818 100644 --- a/extras/STM32Cube_FW/0001-chore-adapt-STM32Cube_FW-sources.patch +++ b/extras/STM32Cube_FW/0001-chore-adapt-STM32Cube_FW-sources.patch @@ -1,25 +1,22 @@ -From ef2495f6fa746df9f86f0db39fa00244d22feb3b Mon Sep 17 00:00:00 2001 +From fd17a2302d60208768610cb4723eb403c52ff2b1 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> -Date: Wed, 5 Apr 2023 10:18:52 +0200 -Subject: [PATCH 1/4] chore: adapt STM32Cube_FW sources - -Compare to previous patch, do the minimum changes required -to ease further update. +Date: Thu, 13 Jul 2023 17:08:05 +0200 +Subject: [PATCH 1/3] chore: adapt STM32Cube_FW sources Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- - src/utility/STM32Cube_FW/app_conf_default.h | 47 +++++++++++++++------ - src/utility/STM32Cube_FW/ble_bufsize.h | 11 ++++- - src/utility/STM32Cube_FW/hw.h | 15 +++++-- - src/utility/STM32Cube_FW/hw_ipcc.c | 4 +- + src/utility/STM32Cube_FW/app_conf_default.h | 46 ++++++++++++++++----- + src/utility/STM32Cube_FW/ble_bufsize.h | 7 ++++ + src/utility/STM32Cube_FW/hw.h | 13 +++++- + src/utility/STM32Cube_FW/hw_ipcc.c | 5 ++- src/utility/STM32Cube_FW/shci.c | 3 +- src/utility/STM32Cube_FW/shci_tl.c | 18 +++++++- - src/utility/STM32Cube_FW/stm_list.c | 7 ++- - src/utility/STM32Cube_FW/tl_mbox.c | 8 +++- - 8 files changed, 90 insertions(+), 23 deletions(-) + src/utility/STM32Cube_FW/stm_list.c | 7 +++- + src/utility/STM32Cube_FW/tl_mbox.c | 7 +++- + 8 files changed, 86 insertions(+), 20 deletions(-) diff --git a/src/utility/STM32Cube_FW/app_conf_default.h b/src/utility/STM32Cube_FW/app_conf_default.h -index 51bd33a..e89df14 100644 +index 51bd33a..1c6dd91 100644 --- a/src/utility/STM32Cube_FW/app_conf_default.h +++ b/src/utility/STM32Cube_FW/app_conf_default.h @@ -1,9 +1,9 @@ @@ -121,19 +118,18 @@ index 51bd33a..e89df14 100644 /****************************************************************************** * Transport Layer ******************************************************************************/ -@@ -657,5 +680,5 @@ typedef enum - #define CFG_OTP_BASE_ADDRESS OTP_AREA_BASE +@@ -658,4 +681,5 @@ typedef enum #define CFG_OTP_END_ADRESS OTP_AREA_END_ADDR -- + -#endif /*APP_CONF_H */ +#endif +#endif /*APP_CONF_DEFAULT_H */ diff --git a/src/utility/STM32Cube_FW/ble_bufsize.h b/src/utility/STM32Cube_FW/ble_bufsize.h -index 7b7c170..53cf59a 100644 +index b9935c0..d4d2890 100644 --- a/src/utility/STM32Cube_FW/ble_bufsize.h +++ b/src/utility/STM32Cube_FW/ble_bufsize.h -@@ -75,15 +75,22 @@ +@@ -75,6 +75,13 @@ ((pw) + MAX(BLE_MEM_BLOCK_X_MTU(mtu, n_link), \ BLE_MBLOCKS_SECURE_CONNECTIONS)) @@ -147,19 +143,8 @@ index 7b7c170..53cf59a 100644 /* * BLE_FIXED_BUFFER_SIZE_BYTES: * A part of the RAM, is dynamically allocated by initializing all the pointers - * defined in a global context variable "mem_alloc_ctx_p". -- * This initialization is made in the Dynamic_allocator functions, which -+ * This initialization is made in the Dynamic_allocator functions, which - * assign a portion of RAM given by the external application to the above - * mentioned "global pointers". - * -- * The size of this Dynamic RAM is made of 2 main components: -+ * The size of this Dynamic RAM is made of 2 main components: - * - a part that is parameters-dependent (num of links, GATT buffers, ...), - * and which value is made explicit by the following macro; - * - a part, that may be considered "fixed", i.e. independent from the above diff --git a/src/utility/STM32Cube_FW/hw.h b/src/utility/STM32Cube_FW/hw.h -index 503fa2c..1472a5e 100644 +index 651e1f1..1472a5e 100644 --- a/src/utility/STM32Cube_FW/hw.h +++ b/src/utility/STM32Cube_FW/hw.h @@ -26,14 +26,23 @@ extern "C" { @@ -188,23 +173,15 @@ index 503fa2c..1472a5e 100644 void HW_IPCC_BLE_Init( void ); void HW_IPCC_BLE_SendCmd( void ); -@@ -76,7 +85,7 @@ extern "C" { - void HW_IPCC_BLE_LLD_ReceiveRsp( void ); - void HW_IPCC_BLE_LLD_SendRspAck( void ); - -- -+ - void HW_IPCC_TRACES_Init( void ); - void HW_IPCC_TRACES_EvtNot( void ); - diff --git a/src/utility/STM32Cube_FW/hw_ipcc.c b/src/utility/STM32Cube_FW/hw_ipcc.c -index fd620b8..3461cbe 100644 +index fd620b8..c730482 100644 --- a/src/utility/STM32Cube_FW/hw_ipcc.c +++ b/src/utility/STM32Cube_FW/hw_ipcc.c -@@ -18,8 +18,9 @@ +@@ -17,9 +17,9 @@ + ****************************************************************************** */ /* USER CODE END Header */ - +- +#if defined(STM32WBxx) /* Includes ------------------------------------------------------------------*/ -#include "app_common.h" @@ -212,13 +189,13 @@ index fd620b8..3461cbe 100644 #include "mbox_def.h" /* Global variables ---------------------------------------------------------*/ -@@ -667,3 +668,4 @@ static void HW_IPCC_TRACES_EvtHandler( void ) +@@ -667,3 +667,4 @@ static void HW_IPCC_TRACES_EvtHandler( void ) } __weak void HW_IPCC_TRACES_EvtNot( void ){}; +#endif /* STM32WBxx */ diff --git a/src/utility/STM32Cube_FW/shci.c b/src/utility/STM32Cube_FW/shci.c -index 301db76..cb7d7bd 100644 +index eaa35d7..4525656 100644 --- a/src/utility/STM32Cube_FW/shci.c +++ b/src/utility/STM32Cube_FW/shci.c @@ -16,7 +16,7 @@ @@ -236,7 +213,7 @@ index 301db76..cb7d7bd 100644 } +#endif /* STM32WBxx */ diff --git a/src/utility/STM32Cube_FW/shci_tl.c b/src/utility/STM32Cube_FW/shci_tl.c -index 2b387b1..a336aa6 100644 +index 0f60430..e343809 100644 --- a/src/utility/STM32Cube_FW/shci_tl.c +++ b/src/utility/STM32Cube_FW/shci_tl.c @@ -16,12 +16,13 @@ @@ -275,7 +252,7 @@ index 2b387b1..a336aa6 100644 /* Private functions ---------------------------------------------------------*/ static void TlInit( TL_CmdPacket_t * p_cmdbuffer ) { -@@ -251,3 +266,4 @@ __WEAK void shci_cmd_resp_release(uint32_t flag) +@@ -250,3 +265,4 @@ __WEAK void shci_cmd_resp_release(uint32_t flag) return; } @@ -306,7 +283,7 @@ index 4c92864..4e8c364 100644 } +#endif /* STM32WBxx */ diff --git a/src/utility/STM32Cube_FW/tl_mbox.c b/src/utility/STM32Cube_FW/tl_mbox.c -index 27a998a..ff219b9 100644 +index 27a998a..1139316 100644 --- a/src/utility/STM32Cube_FW/tl_mbox.c +++ b/src/utility/STM32Cube_FW/tl_mbox.c @@ -16,6 +16,7 @@ @@ -329,11 +306,10 @@ index 27a998a..ff219b9 100644 /**< tables */ PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode FreeBufQueue; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode TracesEvtQueue; -@@ -97,8 +99,11 @@ void TL_Init( void ) +@@ -97,8 +99,10 @@ void TL_Init( void ) TL_RefTable.p_sys_table = &TL_SysTable; TL_RefTable.p_mem_manager_table = &TL_MemManagerTable; TL_RefTable.p_traces_table = &TL_TracesTable; -+ +#if 0 TL_RefTable.p_mac_802_15_4_table = &TL_Mac_802_15_4_Table; TL_RefTable.p_zigbee_table = &TL_Zigbee_Table; @@ -341,7 +317,7 @@ index 27a998a..ff219b9 100644 HW_IPCC_Init(); return; -@@ -846,3 +851,4 @@ static void OutputDbgTrace(TL_MB_PacketType_t packet_type, uint8_t* buffer) +@@ -846,3 +850,4 @@ static void OutputDbgTrace(TL_MB_PacketType_t packet_type, uint8_t* buffer) return; } diff --git a/extras/STM32Cube_FW/0002-fix-include-a-timeout-when-waiting-for-the-cmd_resp.patch b/extras/STM32Cube_FW/0002-fix-include-a-timeout-when-waiting-for-the-cmd_resp.patch index feeef35a..4afa2128 100644 --- a/extras/STM32Cube_FW/0002-fix-include-a-timeout-when-waiting-for-the-cmd_resp.patch +++ b/extras/STM32Cube_FW/0002-fix-include-a-timeout-when-waiting-for-the-cmd_resp.patch @@ -1,7 +1,7 @@ -From 12683bb7a3f0b0ad1e10400cba0e3694f9b9ee95 Mon Sep 17 00:00:00 2001 +From 598c654f18fc9389be8326610a51052943151f04 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> -Date: Mon, 12 Dec 2022 17:17:48 +0100 -Subject: [PATCH 2/4] fix: include a timeout when waiting for the cmd_resp +Date: Thu, 13 Jul 2023 17:16:40 +0200 +Subject: [PATCH 2/3] fix: include a timeout when waiting for the cmd_resp Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- @@ -9,7 +9,7 @@ Signed-off-by: Frederic Pillon <frederic.pillon@st.com> 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/utility/STM32Cube_FW/shci_tl.c b/src/utility/STM32Cube_FW/shci_tl.c -index a336aa6..d1d35f5 100644 +index e343809..6038025 100644 --- a/src/utility/STM32Cube_FW/shci_tl.c +++ b/src/utility/STM32Cube_FW/shci_tl.c @@ -23,6 +23,7 @@ @@ -20,13 +20,12 @@ index a336aa6..d1d35f5 100644 /* Private typedef -----------------------------------------------------------*/ typedef enum -@@ -250,11 +251,12 @@ static void TlUserEvtReceived(TL_EvtPacket_t *shcievt) +@@ -250,10 +251,11 @@ static void TlUserEvtReceived(TL_EvtPacket_t *shcievt) /* Weak implementation ----------------------------------------------------------------*/ __WEAK void shci_cmd_resp_wait(uint32_t timeout) { - (void)timeout; - - CmdRspStatusFlag = SHCI_TL_CMD_RESP_WAIT; - while(CmdRspStatusFlag != SHCI_TL_CMD_RESP_RELEASE); - + for (unsigned long start = millis(); (millis() - start) < timeout;) { diff --git a/extras/STM32Cube_FW/0003-chore-add-support-for-customize-app_conf_default.h.patch b/extras/STM32Cube_FW/0003-chore-add-support-for-customize-app_conf_default.h.patch index e2da2673..32e10c12 100644 --- a/extras/STM32Cube_FW/0003-chore-add-support-for-customize-app_conf_default.h.patch +++ b/extras/STM32Cube_FW/0003-chore-add-support-for-customize-app_conf_default.h.patch @@ -1,7 +1,7 @@ -From 8575588fedd55cf7238a1a810708100e700e57c0 Mon Sep 17 00:00:00 2001 +From 663ed22fd680de1f32c542df0799c403665ecb2e Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Mon, 12 Dec 2022 17:29:27 +0100 -Subject: [PATCH 3/4] chore: add support for customize app_conf_default.h +Subject: [PATCH 3/3] chore: add support for customize app_conf_default.h Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- @@ -9,7 +9,7 @@ Signed-off-by: Frederic Pillon <frederic.pillon@st.com> 1 file changed, 68 insertions(+), 18 deletions(-) diff --git a/src/utility/STM32Cube_FW/app_conf_default.h b/src/utility/STM32Cube_FW/app_conf_default.h -index e89df14..1f17900 100644 +index 1c6dd91..d39492e 100644 --- a/src/utility/STM32Cube_FW/app_conf_default.h +++ b/src/utility/STM32Cube_FW/app_conf_default.h @@ -48,7 +48,9 @@ diff --git a/extras/STM32Cube_FW/0004-fix-warning-outside-array-bounds.patch b/extras/STM32Cube_FW/0004-fix-warning-outside-array-bounds.patch deleted file mode 100644 index ae4aed42..00000000 --- a/extras/STM32Cube_FW/0004-fix-warning-outside-array-bounds.patch +++ /dev/null @@ -1,304 +0,0 @@ -From 64caac5c39a47cac4ab840ba975bca065aa40efa Mon Sep 17 00:00:00 2001 -From: Frederic Pillon <frederic.pillon@st.com> -Date: Wed, 8 Feb 2023 16:50:46 +0100 -Subject: [PATCH 4/4] fix: warning outside array bounds - -array subscript 'TL_CcEvt_t[0]' is partly outside array bounds - -Signed-off-by: Frederic Pillon <frederic.pillon@st.com> ---- - src/utility/STM32Cube_FW/shci.c | 60 ++++++++++++++++----------------- - src/utility/STM32Cube_FW/tl.h | 3 ++ - 2 files changed, 33 insertions(+), 30 deletions(-) - -diff --git a/src/utility/STM32Cube_FW/shci.c b/src/utility/STM32Cube_FW/shci.c -index cb7d7bd..6348145 100644 ---- a/src/utility/STM32Cube_FW/shci.c -+++ b/src/utility/STM32Cube_FW/shci.c -@@ -42,7 +42,7 @@ uint8_t SHCI_C2_FUS_GetState( SHCI_FUS_GetState_ErrorCode_t *p_error_code ) - /** - * A command status event + payload has the same size than the expected command complete - */ -- uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE + 1]; -+ uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; - TL_EvtPacket_t * p_rsp; - - p_rsp = (TL_EvtPacket_t *)local_buffer; -@@ -66,7 +66,7 @@ SHCI_CmdStatus_t SHCI_C2_FUS_FwUpgrade( uint32_t fw_src_add, uint32_t fw_dest_a - * TL_BLEEVT_CS_BUFFER_SIZE is 15 bytes so it is large enough to hold the 8 bytes of command parameters - * Buffer is large enough to hold command complete without payload - */ -- uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; -+ uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; - TL_EvtPacket_t * p_rsp; - uint32_t *p_cmd; - uint8_t cmd_length; -@@ -101,7 +101,7 @@ SHCI_CmdStatus_t SHCI_C2_FUS_FwDelete( void ) - /** - * Buffer is large enough to hold command complete without payload - */ -- uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; -+ uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; - TL_EvtPacket_t * p_rsp; - - p_rsp = (TL_EvtPacket_t *)local_buffer; -@@ -119,7 +119,7 @@ SHCI_CmdStatus_t SHCI_C2_FUS_UpdateAuthKey( SHCI_C2_FUS_UpdateAuthKey_Cmd_Param_ - /** - * Buffer is large enough to hold command complete without payload - */ -- uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; -+ uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; - TL_EvtPacket_t * p_rsp; - - p_rsp = (TL_EvtPacket_t *)local_buffer; -@@ -137,7 +137,7 @@ SHCI_CmdStatus_t SHCI_C2_FUS_LockAuthKey( void ) - /** - * Buffer is large enough to hold command complete without payload - */ -- uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; -+ uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; - TL_EvtPacket_t * p_rsp; - - p_rsp = (TL_EvtPacket_t *)local_buffer; -@@ -155,7 +155,7 @@ SHCI_CmdStatus_t SHCI_C2_FUS_StoreUsrKey( SHCI_C2_FUS_StoreUsrKey_Cmd_Param_t *p - /** - * Buffer is large enough to hold command complete without payload - */ -- uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE + 1]; -+ uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; - TL_EvtPacket_t * p_rsp; - uint8_t local_payload_len; - -@@ -189,7 +189,7 @@ SHCI_CmdStatus_t SHCI_C2_FUS_LoadUsrKey( uint8_t key_index ) - /** - * Buffer is large enough to hold command complete without payload - */ -- uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; -+ uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; - TL_EvtPacket_t * p_rsp; - - p_rsp = (TL_EvtPacket_t *)local_buffer; -@@ -209,7 +209,7 @@ SHCI_CmdStatus_t SHCI_C2_FUS_StartWs( void ) - /** - * Buffer is large enough to hold command complete without payload - */ -- uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; -+ uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; - TL_EvtPacket_t * p_rsp; - - p_rsp = (TL_EvtPacket_t *)local_buffer; -@@ -227,7 +227,7 @@ SHCI_CmdStatus_t SHCI_C2_FUS_LockUsrKey( uint8_t key_index ) - /** - * Buffer is large enough to hold command complete without payload - */ -- uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; -+ uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; - TL_EvtPacket_t * p_rsp; - - p_rsp = (TL_EvtPacket_t *)local_buffer; -@@ -247,7 +247,7 @@ SHCI_CmdStatus_t SHCI_C2_FUS_UnloadUsrKey( uint8_t key_index ) - /** - * Buffer is large enough to hold command complete without payload - */ -- uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; -+ uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; - TL_EvtPacket_t * p_rsp; - - p_rsp = (TL_EvtPacket_t *)local_buffer; -@@ -267,7 +267,7 @@ SHCI_CmdStatus_t SHCI_C2_FUS_ActivateAntiRollback( void ) - /** - * Buffer is large enough to hold command complete without payload - */ -- uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; -+ uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; - TL_EvtPacket_t * p_rsp; - - p_rsp = (TL_EvtPacket_t *)local_buffer; -@@ -285,7 +285,7 @@ SHCI_CmdStatus_t SHCI_C2_BLE_Init( SHCI_C2_Ble_Init_Cmd_Packet_t *pCmdPacket ) - /** - * Buffer is large enough to hold command complete without payload - */ -- uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; -+ uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; - TL_EvtPacket_t * p_rsp; - - p_rsp = (TL_EvtPacket_t *)local_buffer; -@@ -303,7 +303,7 @@ SHCI_CmdStatus_t SHCI_C2_THREAD_Init( void ) - /** - * Buffer is large enough to hold command complete without payload - */ -- uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; -+ uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; - TL_EvtPacket_t * p_rsp; - - p_rsp = (TL_EvtPacket_t *)local_buffer; -@@ -321,7 +321,7 @@ SHCI_CmdStatus_t SHCI_C2_LLDTESTS_Init( uint8_t param_size, uint8_t * p_param ) - /** - * Buffer is large enough to hold command complete without payload - */ -- uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; -+ uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; - TL_EvtPacket_t * p_rsp; - - p_rsp = (TL_EvtPacket_t *)local_buffer; -@@ -339,7 +339,7 @@ SHCI_CmdStatus_t SHCI_C2_BLE_LLD_Init( uint8_t param_size, uint8_t * p_param ) - /** - * Buffer is large enough to hold command complete without payload - */ -- uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; -+ uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; - TL_EvtPacket_t * p_rsp; - - p_rsp = (TL_EvtPacket_t *)local_buffer; -@@ -357,7 +357,7 @@ SHCI_CmdStatus_t SHCI_C2_ZIGBEE_Init( void ) - /** - * Buffer is large enough to hold command complete without payload - */ -- uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; -+ uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; - TL_EvtPacket_t * p_rsp; - - p_rsp = (TL_EvtPacket_t *)local_buffer; -@@ -375,7 +375,7 @@ SHCI_CmdStatus_t SHCI_C2_DEBUG_Init( SHCI_C2_DEBUG_Init_Cmd_Packet_t *pCmdPacket - /** - * Buffer is large enough to hold command complete without payload - */ -- uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; -+ uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; - TL_EvtPacket_t * p_rsp; - - p_rsp = (TL_EvtPacket_t *)local_buffer; -@@ -393,7 +393,7 @@ SHCI_CmdStatus_t SHCI_C2_FLASH_EraseActivity( SHCI_EraseActivity_t erase_activit - /** - * Buffer is large enough to hold command complete without payload - */ -- uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; -+ uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; - TL_EvtPacket_t * p_rsp; - - p_rsp = (TL_EvtPacket_t *)local_buffer; -@@ -413,7 +413,7 @@ SHCI_CmdStatus_t SHCI_C2_CONCURRENT_SetMode( SHCI_C2_CONCURRENT_Mode_Param_t Mod - /** - * Buffer is large enough to hold command complete without payload - */ -- uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; -+ uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; - TL_EvtPacket_t * p_rsp; - - p_rsp = (TL_EvtPacket_t *)local_buffer; -@@ -433,7 +433,7 @@ SHCI_CmdStatus_t SHCI_C2_CONCURRENT_GetNextBleEvtTime( SHCI_C2_CONCURRENT_GetNex - /** - * Buffer is large enough to hold command complete without payload - */ -- uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE+4]; -+ uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; - TL_EvtPacket_t * p_rsp; - - p_rsp = (TL_EvtPacket_t *)local_buffer; -@@ -453,7 +453,7 @@ SHCI_CmdStatus_t SHCI_C2_CONCURRENT_EnableNext_802154_EvtNotification( void ) - /** - * Buffer is large enough to hold command complete without payload - */ -- uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; -+ uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; - TL_EvtPacket_t * p_rsp; - - p_rsp = (TL_EvtPacket_t *)local_buffer; -@@ -471,7 +471,7 @@ SHCI_CmdStatus_t SHCI_C2_FLASH_StoreData( SHCI_C2_FLASH_Ip_t Ip ) - /** - * Buffer is large enough to hold command complete without payload - */ -- uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; -+ uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; - TL_EvtPacket_t * p_rsp; - - p_rsp = (TL_EvtPacket_t *)local_buffer; -@@ -491,7 +491,7 @@ SHCI_CmdStatus_t SHCI_C2_FLASH_EraseData( SHCI_C2_FLASH_Ip_t Ip ) - /** - * Buffer is large enough to hold command complete without payload - */ -- uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; -+ uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; - TL_EvtPacket_t * p_rsp; - - p_rsp = (TL_EvtPacket_t *)local_buffer; -@@ -511,7 +511,7 @@ SHCI_CmdStatus_t SHCI_C2_RADIO_AllowLowPower( SHCI_C2_FLASH_Ip_t Ip,uint8_t Fla - /** - * Buffer is large enough to hold command complete without payload - */ -- uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; -+ uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; - TL_EvtPacket_t * p_rsp; - - p_rsp = (TL_EvtPacket_t *)local_buffer; -@@ -532,7 +532,7 @@ SHCI_CmdStatus_t SHCI_C2_MAC_802_15_4_Init( void ) - /** - * Buffer is large enough to hold command complete without payload - */ -- uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; -+ uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; - TL_EvtPacket_t * p_rsp; - - p_rsp = (TL_EvtPacket_t *)local_buffer; -@@ -550,7 +550,7 @@ SHCI_CmdStatus_t SHCI_C2_Reinit( void ) - /** - * Buffer is large enough to hold command complete without payload - */ -- uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; -+ uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; - TL_EvtPacket_t * p_rsp; - - p_rsp = (TL_EvtPacket_t *)local_buffer; -@@ -569,7 +569,7 @@ SHCI_CmdStatus_t SHCI_C2_ExtpaConfig(uint32_t gpio_port, uint16_t gpio_pin_numbe - * TL_BLEEVT_CS_BUFFER_SIZE is 15 bytes so it is large enough to hold the 8 bytes of command parameters - * Buffer is large enough to hold command complete without payload - */ -- uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; -+ uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; - TL_EvtPacket_t * p_rsp; - - p_rsp = (TL_EvtPacket_t *)local_buffer; -@@ -593,7 +593,7 @@ SHCI_CmdStatus_t SHCI_C2_SetFlashActivityControl(SHCI_C2_SET_FLASH_ACTIVITY_CONT - * TL_BLEEVT_CS_BUFFER_SIZE is 15 bytes so it is large enough to hold the 1 byte of command parameter - * Buffer is large enough to hold command complete without payload - */ -- uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; -+ uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; - TL_EvtPacket_t * p_rsp; - - p_rsp = (TL_EvtPacket_t *)local_buffer; -@@ -613,7 +613,7 @@ SHCI_CmdStatus_t SHCI_C2_Config(SHCI_C2_CONFIG_Cmd_Param_t *pCmdPacket) - /** - * Buffer is large enough to hold command complete without payload - */ -- uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; -+ uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; - TL_EvtPacket_t * p_rsp; - - p_rsp = (TL_EvtPacket_t *)local_buffer; -@@ -631,7 +631,7 @@ SHCI_CmdStatus_t SHCI_C2_802_15_4_DeInit( void ) - /** - * Buffer is large enough to hold command complete without payload - */ -- uint8_t local_buffer[TL_BLEEVT_CS_BUFFER_SIZE]; -+ uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; - TL_EvtPacket_t * p_rsp; - - p_rsp = (TL_EvtPacket_t *)local_buffer; -diff --git a/src/utility/STM32Cube_FW/tl.h b/src/utility/STM32Cube_FW/tl.h -index 6bfa265..63126b3 100644 ---- a/src/utility/STM32Cube_FW/tl.h -+++ b/src/utility/STM32Cube_FW/tl.h -@@ -61,6 +61,9 @@ extern "C" { - #define TL_BLEEVT_CS_PACKET_SIZE (TL_EVT_HDR_SIZE + sizeof(TL_CsEvt_t)) - #define TL_BLEEVT_CS_BUFFER_SIZE (sizeof(TL_PacketHeader_t) + TL_BLEEVT_CS_PACKET_SIZE) - -+#define TL_BLEEVT_CC_PACKET_SIZE (TL_EVT_HDR_SIZE + sizeof(TL_CcEvt_t)) -+#define TL_BLEEVT_CC_BUFFER_SIZE (sizeof(TL_PacketHeader_t) + TL_BLEEVT_CC_PACKET_SIZE) -+ - /* Exported types ------------------------------------------------------------*/ - /**< Packet header */ - typedef PACKED_STRUCT --- -2.38.0.windows.1 - From eab189123182abdf7dc1f628da54c6952e789f54 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Mon, 17 Jul 2023 11:30:41 +0200 Subject: [PATCH 137/226] fix(doc): wrong version Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- src/utility/STM32Cube_FW/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utility/STM32Cube_FW/README.md b/src/utility/STM32Cube_FW/README.md index 780e2706..e6f6e0ae 100644 --- a/src/utility/STM32Cube_FW/README.md +++ b/src/utility/STM32Cube_FW/README.md @@ -1,6 +1,6 @@ ## Source -[STMicroelectronics/STM32CubeWB Release vvv1.16.0](https://github.com/STMicroelectronics/STM32CubeWB/releases/tag/vvv1.16.0) -- Application: [BLE_TransparentMode](https://github.com/STMicroelectronics/STM32CubeWB/tree/vvv1.16.0/Projects/P-NUCLEO-WB55.Nucleo/Applications/BLE/BLE_TransparentMode) +[STMicroelectronics/STM32CubeWB Release v1.16.0](https://github.com/STMicroelectronics/STM32CubeWB/releases/tag/v1.16.0) +- Application: [BLE_TransparentMode](https://github.com/STMicroelectronics/STM32CubeWB/tree/v1.16.0/Projects/P-NUCLEO-WB55.Nucleo/Applications/BLE/BLE_TransparentMode) From 61b8a3b295f6a01b3efefe937683a89cf0559da4 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Mon, 17 Jul 2023 11:34:26 +0200 Subject: [PATCH 138/226] chore: update STM32Cube_FW from Cube version v1.17.0 Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- src/utility/STM32Cube_FW/README.md | 4 +- src/utility/STM32Cube_FW/app_conf_default.h | 129 +++++--------------- src/utility/STM32Cube_FW/ble_bufsize.h | 13 +- src/utility/STM32Cube_FW/hw.h | 13 +- src/utility/STM32Cube_FW/hw_ipcc.c | 4 +- src/utility/STM32Cube_FW/shci.c | 21 ++-- src/utility/STM32Cube_FW/shci.h | 11 +- src/utility/STM32Cube_FW/shci_tl.c | 31 +---- src/utility/STM32Cube_FW/stm_list.c | 7 +- src/utility/STM32Cube_FW/tl.h | 10 +- src/utility/STM32Cube_FW/tl_mbox.c | 8 +- 11 files changed, 64 insertions(+), 187 deletions(-) diff --git a/src/utility/STM32Cube_FW/README.md b/src/utility/STM32Cube_FW/README.md index e6f6e0ae..0d39a3ef 100644 --- a/src/utility/STM32Cube_FW/README.md +++ b/src/utility/STM32Cube_FW/README.md @@ -1,6 +1,6 @@ ## Source -[STMicroelectronics/STM32CubeWB Release v1.16.0](https://github.com/STMicroelectronics/STM32CubeWB/releases/tag/v1.16.0) -- Application: [BLE_TransparentMode](https://github.com/STMicroelectronics/STM32CubeWB/tree/v1.16.0/Projects/P-NUCLEO-WB55.Nucleo/Applications/BLE/BLE_TransparentMode) +[STMicroelectronics/STM32CubeWB Release v1.17.0](https://github.com/STMicroelectronics/STM32CubeWB/releases/tag/v1.17.0) +- Application: [BLE_TransparentMode](https://github.com/STMicroelectronics/STM32CubeWB/tree/v1.17.0/Projects/P-NUCLEO-WB55.Nucleo/Applications/BLE/BLE_TransparentMode) diff --git a/src/utility/STM32Cube_FW/app_conf_default.h b/src/utility/STM32Cube_FW/app_conf_default.h index 1f17900d..51bd33af 100644 --- a/src/utility/STM32Cube_FW/app_conf_default.h +++ b/src/utility/STM32Cube_FW/app_conf_default.h @@ -1,9 +1,9 @@ /* USER CODE BEGIN Header */ /** ****************************************************************************** - * @file app_conf_default.h + * @file app_conf.h * @author MCD Application Team - * @brief Default application configuration file for STM32WPAN Middleware. + * @brief Application configuration file for STM32WPAN Middleware. ****************************************************************************** * @attention * @@ -19,40 +19,18 @@ /* USER CODE END Header */ /* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef APP_CONF_DEFAULT_H -#define APP_CONF_DEFAULT_H -#if 0 +#ifndef APP_CONF_H +#define APP_CONF_H + #include "hw.h" #include "hw_conf.h" #include "hw_if.h" #include "ble_bufsize.h" -#endif + /****************************************************************************** * Application Config ******************************************************************************/ -/**< generic parameters ******************************************************/ -/* HCI related defines */ - -#define ACI_HAL_SET_TX_POWER_LEVEL 0xFC0F -#define ACI_WRITE_CONFIG_DATA_OPCODE 0xFC0C -#define ACI_READ_CONFIG_DATA_OPCODE 0xFC0D -#define MAX_HCI_ACL_PACKET_SIZE (sizeof(TL_PacketHeader_t) + 5 + 251) -#define HCI_RESET 0x0C03 - -#ifndef BLE_SHARED_MEM_BYTE_ORDER - #define BLE_SHARED_MEM_BYTE_ORDER MSBFIRST -#endif -#define BLE_MODULE_SHARED_MEM_BUFFER_SIZE 128 - -/** - * Define Tx Power - */ -#ifndef CFG_TX_POWER - #define CFG_TX_POWER (0x18) /* -0.15dBm */ -#endif - -#if 0 /** * Define Secure Connections Support */ @@ -126,7 +104,7 @@ #define CFG_FW_SUBVERSION (1) #define CFG_FW_BRANCH (0) #define CFG_FW_BUILD (0) -#endif + /****************************************************************************** * BLE Stack ******************************************************************************/ @@ -134,25 +112,13 @@ * Maximum number of simultaneous connections that the device will support. * Valid values are from 1 to 8 */ -#ifndef CFG_BLE_NUM_LINK -#ifdef STM32WB15xx - #define CFG_BLE_NUM_LINK 3 -#else - #define CFG_BLE_NUM_LINK 8 -#endif -#endif +#define CFG_BLE_NUM_LINK 8 /** * Maximum number of Services that can be stored in the GATT database. * Note that the GAP and GATT services are automatically added so this parameter should be 2 plus the number of user services */ -#ifndef CFG_BLE_NUM_GATT_SERVICES -#ifdef STM32WB15xx - #define CFG_BLE_NUM_GATT_SERVICES 4 -#else - #define CFG_BLE_NUM_GATT_SERVICES 8 -#endif -#endif +#define CFG_BLE_NUM_GATT_SERVICES 8 /** * Maximum number of Attributes @@ -161,21 +127,13 @@ * Note that certain characteristics and relative descriptors are added automatically during device initialization * so this parameters should be 9 plus the number of user Attributes */ -#ifndef CFG_BLE_NUM_GATT_ATTRIBUTES -#ifdef STM32WB15xx - #define CFG_BLE_NUM_GATT_ATTRIBUTES 30 -#else - #define CFG_BLE_NUM_GATT_ATTRIBUTES 68 -#endif -#endif +#define CFG_BLE_NUM_GATT_ATTRIBUTES 68 /** * Maximum supported ATT_MTU size * This parameter is ignored by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set */ -#ifndef CFG_BLE_MAX_ATT_MTU - #define CFG_BLE_MAX_ATT_MTU (156) -#endif +#define CFG_BLE_MAX_ATT_MTU (156) /** * Size of the storage area for Attribute values @@ -188,43 +146,29 @@ * The total amount of memory needed is the sum of the above quantities for each attribute. * This parameter is ignored by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set */ -#ifndef CFG_BLE_ATT_VALUE_ARRAY_SIZE -#ifdef STM32WB15xx - #define CFG_BLE_ATT_VALUE_ARRAY_SIZE (1290) -#else - #define CFG_BLE_ATT_VALUE_ARRAY_SIZE (1344) -#endif -#endif +#define CFG_BLE_ATT_VALUE_ARRAY_SIZE (1344) /** * Prepare Write List size in terms of number of packet * This parameter is ignored by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set */ -// #define CFG_BLE_PREPARE_WRITE_LIST_SIZE BLE_PREP_WRITE_X_ATT(CFG_BLE_MAX_ATT_MTU) -#ifndef CFG_BLE_PREPARE_WRITE_LIST_SIZE - #define CFG_BLE_PREPARE_WRITE_LIST_SIZE (0x3A) -#endif +#define CFG_BLE_PREPARE_WRITE_LIST_SIZE BLE_PREP_WRITE_X_ATT(CFG_BLE_MAX_ATT_MTU) /** * Number of allocated memory blocks * This parameter is overwritten by the CPU2 with an hardcoded optimal value when the parameter CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set */ -//#define CFG_BLE_MBLOCK_COUNT (BLE_MBLOCKS_CALC(CFG_BLE_PREPARE_WRITE_LIST_SIZE, CFG_BLE_MAX_ATT_MTU, CFG_BLE_NUM_LINK)) -#define CFG_BLE_MBLOCK_COUNT (0x79) +#define CFG_BLE_MBLOCK_COUNT (BLE_MBLOCKS_CALC(CFG_BLE_PREPARE_WRITE_LIST_SIZE, CFG_BLE_MAX_ATT_MTU, CFG_BLE_NUM_LINK)) /** * Enable or disable the Extended Packet length feature. Valid values are 0 or 1. */ -#ifndef CFG_BLE_DATA_LENGTH_EXTENSION - #define CFG_BLE_DATA_LENGTH_EXTENSION 1 -#endif +#define CFG_BLE_DATA_LENGTH_EXTENSION 1 /** * Sleep clock accuracy in Slave mode (ppm value) */ -#ifndef CFG_BLE_SLAVE_SCA - #define CFG_BLE_SLAVE_SCA 500 -#endif +#define CFG_BLE_SLAVE_SCA 500 /** * Sleep clock accuracy in Master mode @@ -237,9 +181,7 @@ * 6 : 21 ppm to 30 ppm * 7 : 0 ppm to 20 ppm */ -#ifndef CFG_BLE_MASTER_SCA - #define CFG_BLE_MASTER_SCA 0 -#endif +#define CFG_BLE_MASTER_SCA 0 /** * LsSource @@ -248,27 +190,21 @@ * - bit 1: 1: STM32WB5M Module device 0: Other devices as STM32WBxx SOC, STM32WB1M module * - bit 2: 1: HSE/1024 Clock config 0: LSE Clock config */ -#ifndef CFG_BLE_LS_SOURCE - #if defined(STM32WB5Mxx) - #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_MOD5MM_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) - #else - #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_OTHER_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) - #endif +#if defined(STM32WB5Mxx) + #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_MOD5MM_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) +#else + #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_OTHER_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) #endif /** * Start up time of the high speed (16 or 32 MHz) crystal oscillator in units of 625/256 us (~2.44 us) */ -#ifndef CFG_BLE_HSE_STARTUP_TIME - #define CFG_BLE_HSE_STARTUP_TIME 0x148 -#endif +#define CFG_BLE_HSE_STARTUP_TIME 0x148 /** * Maximum duration of the connection event when the device is in Slave mode in units of 625/256 us (~2.44 us) */ -#ifndef CFG_BLE_MAX_CONN_EVENT_LENGTH - #define CFG_BLE_MAX_CONN_EVENT_LENGTH (0xFFFFFFFF) -#endif +#define CFG_BLE_MAX_CONN_EVENT_LENGTH (0xFFFFFFFF) /** * Viterbi Mode @@ -314,7 +250,7 @@ * 0: LE Power Class 2-3 * other bits: complete with Options_extension flag */ -#define CFG_BLE_OPTIONS (SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY) +#define CFG_BLE_OPTIONS (SHCI_C2_BLE_INIT_OPTIONS_LL_HOST | SHCI_C2_BLE_INIT_OPTIONS_WITH_SVC_CHANGE_DESC | SHCI_C2_BLE_INIT_OPTIONS_DEVICE_NAME_RW | SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV | SHCI_C2_BLE_INIT_OPTIONS_CS_ALGO2 | SHCI_C2_BLE_INIT_OPTIONS_FULL_GATTDB_NVM | SHCI_C2_BLE_INIT_OPTIONS_GATT_CACHING_NOTUSED | SHCI_C2_BLE_INIT_OPTIONS_POWER_CLASS_2_3) /** * BLE stack Options_extension flags to be configured with: @@ -356,11 +292,7 @@ * This parameter is considered by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV flag set */ -#if defined(STM32WB15xx) - #define CFG_BLE_MAX_ADV_SET_NBR (3) -#else - #define CFG_BLE_MAX_ADV_SET_NBR (8) -#endif +#define CFG_BLE_MAX_ADV_SET_NBR (8) /* Maximum advertising data length (in bytes) * Range: 31 .. 1650 with limitation: @@ -369,11 +301,7 @@ * This parameter is considered by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV flag set */ -#if defined(STM32WB15xx) - #define CFG_BLE_MAX_ADV_DATA_LEN (414) -#else - #define CFG_BLE_MAX_ADV_DATA_LEN (207) -#endif +#define CFG_BLE_MAX_ADV_DATA_LEN (207) /* RF TX Path Compensation Value (16-bit signed integer). Units: 0.1 dB. * Range: -1280 .. 1280 @@ -395,7 +323,6 @@ #define CFG_BLE_CORE_VERSION (SHCI_C2_BLE_INIT_BLE_CORE_5_3) -#if 0 /****************************************************************************** * Transport Layer ******************************************************************************/ @@ -730,5 +657,5 @@ typedef enum #define CFG_OTP_BASE_ADDRESS OTP_AREA_BASE #define CFG_OTP_END_ADRESS OTP_AREA_END_ADDR -#endif -#endif /*APP_CONF_DEFAULT_H */ + +#endif /*APP_CONF_H */ diff --git a/src/utility/STM32Cube_FW/ble_bufsize.h b/src/utility/STM32Cube_FW/ble_bufsize.h index 53cf59a8..b9935c0b 100644 --- a/src/utility/STM32Cube_FW/ble_bufsize.h +++ b/src/utility/STM32Cube_FW/ble_bufsize.h @@ -75,13 +75,6 @@ ((pw) + MAX(BLE_MEM_BLOCK_X_MTU(mtu, n_link), \ BLE_MBLOCKS_SECURE_CONNECTIONS)) -/* - * BLE_DEFAULT_MBLOCKS_COUNT: default memory blocks count - */ -#define BLE_DEFAULT_MBLOCKS_COUNT(n_link) \ - BLE_MBLOCKS_CALC(BLE_DEFAULT_PREP_WRITE_LIST_SIZE, \ - BLE_DEFAULT_MAX_ATT_MTU, n_link) - /* * BLE_FIXED_BUFFER_SIZE_BYTES: * A part of the RAM, is dynamically allocated by initializing all the pointers @@ -103,11 +96,11 @@ #elif (LL_ONLY != 0) #define BLE_FIXED_BUFFER_SIZE_BYTES 6036 /* LL only Full */ #elif (SLAVE_ONLY != 0) -#define BLE_FIXED_BUFFER_SIZE_BYTES 6292 /* Peripheral only */ +#define BLE_FIXED_BUFFER_SIZE_BYTES 6300 /* Peripheral only */ #elif (BASIC_FEATURES != 0) -#define BLE_FIXED_BUFFER_SIZE_BYTES 6624 /* Basic Features */ +#define BLE_FIXED_BUFFER_SIZE_BYTES 6632 /* Basic Features */ #else -#define BLE_FIXED_BUFFER_SIZE_BYTES 7144 /* Full stack */ +#define BLE_FIXED_BUFFER_SIZE_BYTES 7152 /* Full stack */ #endif /* diff --git a/src/utility/STM32Cube_FW/hw.h b/src/utility/STM32Cube_FW/hw.h index 1472a5e8..651e1f17 100644 --- a/src/utility/STM32Cube_FW/hw.h +++ b/src/utility/STM32Cube_FW/hw.h @@ -26,23 +26,14 @@ extern "C" { #endif /* Includes ------------------------------------------------------------------*/ -#include "stm32_def.h" -#include "stm32wbxx_ll_bus.h" -#include "stm32wbxx_ll_exti.h" -#include "stm32wbxx_ll_system.h" -#include "stm32wbxx_ll_rcc.h" -#include "stm32wbxx_ll_ipcc.h" -#include "stm32wbxx_ll_cortex.h" -#include "stm32wbxx_ll_utils.h" -#include "stm32wbxx_ll_pwr.h" /****************************************************************************** * HW IPCC ******************************************************************************/ void HW_IPCC_Enable( void ); void HW_IPCC_Init( void ); -#define HW_IPCC_Rx_Handler IPCC_C1_RX_IRQHandler -#define HW_IPCC_Tx_Handler IPCC_C1_TX_IRQHandler + void HW_IPCC_Rx_Handler( void ); + void HW_IPCC_Tx_Handler( void ); void HW_IPCC_BLE_Init( void ); void HW_IPCC_BLE_SendCmd( void ); diff --git a/src/utility/STM32Cube_FW/hw_ipcc.c b/src/utility/STM32Cube_FW/hw_ipcc.c index 3461cbed..fd620b85 100644 --- a/src/utility/STM32Cube_FW/hw_ipcc.c +++ b/src/utility/STM32Cube_FW/hw_ipcc.c @@ -18,9 +18,8 @@ */ /* USER CODE END Header */ -#if defined(STM32WBxx) /* Includes ------------------------------------------------------------------*/ -#include "hw.h" +#include "app_common.h" #include "mbox_def.h" /* Global variables ---------------------------------------------------------*/ @@ -668,4 +667,3 @@ static void HW_IPCC_TRACES_EvtHandler( void ) } __weak void HW_IPCC_TRACES_EvtNot( void ){}; -#endif /* STM32WBxx */ diff --git a/src/utility/STM32Cube_FW/shci.c b/src/utility/STM32Cube_FW/shci.c index 6348145f..eaa35d7c 100644 --- a/src/utility/STM32Cube_FW/shci.c +++ b/src/utility/STM32Cube_FW/shci.c @@ -16,7 +16,7 @@ ****************************************************************************** */ -#if defined(STM32WBxx) + /* Includes ------------------------------------------------------------------*/ #include "stm32_wpan_common.h" @@ -40,9 +40,9 @@ uint8_t SHCI_C2_FUS_GetState( SHCI_FUS_GetState_ErrorCode_t *p_error_code ) { /** - * A command status event + payload has the same size than the expected command complete + * Buffer is large enough to hold command complete with payload */ - uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE + 1]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; @@ -63,7 +63,7 @@ uint8_t SHCI_C2_FUS_GetState( SHCI_FUS_GetState_ErrorCode_t *p_error_code ) SHCI_CmdStatus_t SHCI_C2_FUS_FwUpgrade( uint32_t fw_src_add, uint32_t fw_dest_add ) { /** - * TL_BLEEVT_CS_BUFFER_SIZE is 15 bytes so it is large enough to hold the 8 bytes of command parameters + * TL_BLEEVT_CC_BUFFER_SIZE is 16 bytes so it is large enough to hold the 8 bytes of command parameters * Buffer is large enough to hold command complete without payload */ uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; @@ -153,9 +153,9 @@ SHCI_CmdStatus_t SHCI_C2_FUS_LockAuthKey( void ) SHCI_CmdStatus_t SHCI_C2_FUS_StoreUsrKey( SHCI_C2_FUS_StoreUsrKey_Cmd_Param_t *pParam, uint8_t *p_key_index ) { /** - * Buffer is large enough to hold command complete without payload + * Buffer is large enough to hold command complete with payload */ - uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE + 1]; TL_EvtPacket_t * p_rsp; uint8_t local_payload_len; @@ -431,9 +431,9 @@ SHCI_CmdStatus_t SHCI_C2_CONCURRENT_SetMode( SHCI_C2_CONCURRENT_Mode_Param_t Mod SHCI_CmdStatus_t SHCI_C2_CONCURRENT_GetNextBleEvtTime( SHCI_C2_CONCURRENT_GetNextBleEvtTime_Param_t *pParam ) { /** - * Buffer is large enough to hold command complete without payload + * Buffer is large enough to hold command complete with payload */ - uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE+4]; TL_EvtPacket_t * p_rsp; p_rsp = (TL_EvtPacket_t *)local_buffer; @@ -566,7 +566,7 @@ SHCI_CmdStatus_t SHCI_C2_Reinit( void ) SHCI_CmdStatus_t SHCI_C2_ExtpaConfig(uint32_t gpio_port, uint16_t gpio_pin_number, uint8_t gpio_polarity, uint8_t gpio_status) { /** - * TL_BLEEVT_CS_BUFFER_SIZE is 15 bytes so it is large enough to hold the 8 bytes of command parameters + * TL_BLEEVT_CC_BUFFER_SIZE is 16 bytes so it is large enough to hold the 8 bytes of command parameters * Buffer is large enough to hold command complete without payload */ uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; @@ -590,7 +590,7 @@ SHCI_CmdStatus_t SHCI_C2_ExtpaConfig(uint32_t gpio_port, uint16_t gpio_pin_numbe SHCI_CmdStatus_t SHCI_C2_SetFlashActivityControl(SHCI_C2_SET_FLASH_ACTIVITY_CONTROL_Source_t Source) { /** - * TL_BLEEVT_CS_BUFFER_SIZE is 15 bytes so it is large enough to hold the 1 byte of command parameter + * TL_BLEEVT_CC_BUFFER_SIZE is 16 bytes so it is large enough to hold the 1 byte of command parameter * Buffer is large enough to hold command complete without payload */ uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; @@ -739,4 +739,3 @@ SHCI_CmdStatus_t SHCI_GetWirelessFwInfo( WirelessFwInfo_t* pWirelessInfo ) return (SHCI_Success); } -#endif /* STM32WBxx */ diff --git a/src/utility/STM32Cube_FW/shci.h b/src/utility/STM32Cube_FW/shci.h index d2aa0a58..750fa972 100644 --- a/src/utility/STM32Cube_FW/shci.h +++ b/src/utility/STM32Cube_FW/shci.h @@ -535,7 +535,7 @@ extern "C" { * - bit 4: 1: CS Algo #2 supported 0: CS Algo #2 not supported * - bit 5: 1: Reduced GATT database in NVM 0: Full GATT database in NVM * - bit 6: 1: GATT caching is used 0: GATT caching is not used - * - bit 7: 1: LE Power Class 1 0: LE Power Classe 2-3 + * - bit 7: 1: LE Power Class 1 0: LE Power Class 2-3 * - other bits: complete with Options_extension flag */ uint8_t Options; @@ -668,6 +668,7 @@ extern "C" { */ #define SHCI_C2_BLE_INIT_BLE_CORE_5_2 11 #define SHCI_C2_BLE_INIT_BLE_CORE_5_3 12 +#define SHCI_C2_BLE_INIT_BLE_CORE_5_4 13 /** * LsSource information @@ -904,7 +905,7 @@ extern "C" { #define FUS_DEVICE_INFO_TABLE_VALIDITY_KEYWORD (0xA94656B9) /* - * At startup, the informations relative to the wireless binary are stored in RAM trough a structure defined by + * At startup, the information relative to the wireless binary are stored in RAM through a structure defined by * MB_WirelessFwInfoTable_t.This structure contains 4 fields (Version,MemorySize, Stack_info and a reserved part) * each of those coded on 32 bits as shown on the table below: * @@ -1150,7 +1151,7 @@ typedef struct { * @brief Starts the LLD tests CLI * * @param param_size : Nb of bytes - * @param p_param : pointeur with data to give from M4 to M0 + * @param p_param : pointer with data to give from M4 to M0 * @retval Status */ SHCI_CmdStatus_t SHCI_C2_LLDTESTS_Init( uint8_t param_size, uint8_t * p_param ); @@ -1160,7 +1161,7 @@ typedef struct { * @brief Starts the LLD tests BLE * * @param param_size : Nb of bytes - * @param p_param : pointeur with data to give from M4 to M0 + * @param p_param : pointer with data to give from M4 to M0 * @retval Status */ SHCI_CmdStatus_t SHCI_C2_BLE_LLD_Init( uint8_t param_size, uint8_t * p_param ); @@ -1260,7 +1261,7 @@ typedef struct { /** * SHCI_GetWirelessFwInfo - * @brief This function read back the informations relative to the wireless binary loaded. + * @brief This function read back the information relative to the wireless binary loaded. * Refer yourself to MB_WirelessFwInfoTable_t structure to get the significance * of the different parameters returned. * @param pWirelessInfo : Pointer to WirelessFwInfo_t. diff --git a/src/utility/STM32Cube_FW/shci_tl.c b/src/utility/STM32Cube_FW/shci_tl.c index d1d35f5b..0f604300 100644 --- a/src/utility/STM32Cube_FW/shci_tl.c +++ b/src/utility/STM32Cube_FW/shci_tl.c @@ -16,14 +16,12 @@ ****************************************************************************** */ -#if defined(STM32WBxx) + /* Includes ------------------------------------------------------------------*/ #include "stm32_wpan_common.h" #include "stm_list.h" #include "shci_tl.h" -#include "stm32_def.h" -#include "wiring_time.h" /* Private typedef -----------------------------------------------------------*/ typedef enum @@ -154,7 +152,7 @@ void shci_send( uint16_t cmd_code, uint8_t len_cmd_payload, uint8_t * p_cmd_payl pCmdBuffer->cmdserial.cmd.plen = len_cmd_payload; memcpy(pCmdBuffer->cmdserial.cmd.payload, p_cmd_payload, len_cmd_payload ); - + CmdRspStatusFlag = SHCI_TL_CMD_RESP_WAIT; shciContext.io.Send(0,0); shci_cmd_resp_wait(SHCI_TL_DEFAULT_TIMEOUT); @@ -170,20 +168,6 @@ void shci_send( uint16_t cmd_code, uint8_t len_cmd_payload, uint8_t * p_cmd_payl return; } -void shci_notify_asynch_evt(void *pdata) -{ - UNUSED(pdata); - /* Need to parse data in future version */ - shci_user_evt_proc(); -} - -void shci_register_io_bus(tSHciIO *fops) -{ - /* Register IO bus services */ - fops->Init = TL_SYS_Init; - fops->Send = TL_SYS_SendCmd; -} - /* Private functions ---------------------------------------------------------*/ static void TlInit( TL_CmdPacket_t * p_cmdbuffer ) { @@ -251,12 +235,10 @@ static void TlUserEvtReceived(TL_EvtPacket_t *shcievt) /* Weak implementation ----------------------------------------------------------------*/ __WEAK void shci_cmd_resp_wait(uint32_t timeout) { - CmdRspStatusFlag = SHCI_TL_CMD_RESP_WAIT; - for (unsigned long start = millis(); (millis() - start) < timeout;) { - if (CmdRspStatusFlag == SHCI_TL_CMD_RESP_RELEASE) { - break; - } - } + (void)timeout; + + while(CmdRspStatusFlag != SHCI_TL_CMD_RESP_RELEASE); + return; } @@ -268,4 +250,3 @@ __WEAK void shci_cmd_resp_release(uint32_t flag) return; } -#endif /* STM32WBxx */ diff --git a/src/utility/STM32Cube_FW/stm_list.c b/src/utility/STM32Cube_FW/stm_list.c index 4e8c3643..4c928647 100644 --- a/src/utility/STM32Cube_FW/stm_list.c +++ b/src/utility/STM32Cube_FW/stm_list.c @@ -16,13 +16,11 @@ ****************************************************************************** */ -#if defined(STM32WBxx) + /****************************************************************************** * Include Files ******************************************************************************/ -#include "stdint.h" -#include "cmsis_gcc.h" -#include "stm32_wpan_common.h" +#include "utilities_common.h" #include "stm_list.h" @@ -206,4 +204,3 @@ void LST_get_prev_node (tListNode * ref_node, tListNode ** node) __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ } -#endif /* STM32WBxx */ diff --git a/src/utility/STM32Cube_FW/tl.h b/src/utility/STM32Cube_FW/tl.h index 63126b3d..8e8c6cbc 100644 --- a/src/utility/STM32Cube_FW/tl.h +++ b/src/utility/STM32Cube_FW/tl.h @@ -58,12 +58,8 @@ extern "C" { #define TL_BLEEVT_CS_OPCODE (0x0F) #define TL_BLEEVT_VS_OPCODE (0xFF) -#define TL_BLEEVT_CS_PACKET_SIZE (TL_EVT_HDR_SIZE + sizeof(TL_CsEvt_t)) -#define TL_BLEEVT_CS_BUFFER_SIZE (sizeof(TL_PacketHeader_t) + TL_BLEEVT_CS_PACKET_SIZE) - #define TL_BLEEVT_CC_PACKET_SIZE (TL_EVT_HDR_SIZE + sizeof(TL_CcEvt_t)) #define TL_BLEEVT_CC_BUFFER_SIZE (sizeof(TL_PacketHeader_t) + TL_BLEEVT_CC_PACKET_SIZE) - /* Exported types ------------------------------------------------------------*/ /**< Packet header */ typedef PACKED_STRUCT @@ -93,7 +89,7 @@ typedef PACKED_STRUCT { uint8_t numcmd; uint16_t cmdcode; - uint8_t payload[255]; + uint8_t payload[2]; } TL_CcEvt_t; /** @@ -102,7 +98,7 @@ typedef PACKED_STRUCT typedef PACKED_STRUCT { uint16_t subevtcode; - uint8_t payload[255]; + uint8_t payload[2]; } TL_AsynchEvt_t; /** @@ -112,7 +108,7 @@ typedef PACKED_STRUCT { uint8_t evtcode; uint8_t plen; - uint8_t payload[255]; + uint8_t payload[2]; } TL_Evt_t; typedef PACKED_STRUCT diff --git a/src/utility/STM32Cube_FW/tl_mbox.c b/src/utility/STM32Cube_FW/tl_mbox.c index ff219b97..27a998a3 100644 --- a/src/utility/STM32Cube_FW/tl_mbox.c +++ b/src/utility/STM32Cube_FW/tl_mbox.c @@ -16,7 +16,6 @@ ****************************************************************************** */ -#if defined(STM32WBxx) /* Includes ------------------------------------------------------------------*/ #include "stm32_wpan_common.h" #include "hw.h" @@ -52,10 +51,9 @@ PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_BleLldTable_t TL_BleLldTable; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_SysTable_t TL_SysTable; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_MemManagerTable_t TL_MemManagerTable; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_TracesTable_t TL_TracesTable; -#if 0 PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_Mac_802_15_4_t TL_Mac_802_15_4_Table; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_ZigbeeTable_t TL_Zigbee_Table; -#endif + /**< tables */ PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode FreeBufQueue; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode TracesEvtQueue; @@ -99,11 +97,8 @@ void TL_Init( void ) TL_RefTable.p_sys_table = &TL_SysTable; TL_RefTable.p_mem_manager_table = &TL_MemManagerTable; TL_RefTable.p_traces_table = &TL_TracesTable; - -#if 0 TL_RefTable.p_mac_802_15_4_table = &TL_Mac_802_15_4_Table; TL_RefTable.p_zigbee_table = &TL_Zigbee_Table; -#endif HW_IPCC_Init(); return; @@ -851,4 +846,3 @@ static void OutputDbgTrace(TL_MB_PacketType_t packet_type, uint8_t* buffer) return; } -#endif /* STM32WBxx */ From 542e007fa5a1b53664d2efb5f01d67767123a357 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Thu, 13 Jul 2023 17:08:05 +0200 Subject: [PATCH 139/226] chore: adapt STM32Cube_FW sources Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- src/utility/STM32Cube_FW/app_conf_default.h | 46 ++++++++++++++++----- src/utility/STM32Cube_FW/ble_bufsize.h | 7 ++++ src/utility/STM32Cube_FW/hw.h | 13 +++++- src/utility/STM32Cube_FW/hw_ipcc.c | 5 ++- src/utility/STM32Cube_FW/shci.c | 3 +- src/utility/STM32Cube_FW/shci_tl.c | 18 +++++++- src/utility/STM32Cube_FW/stm_list.c | 7 +++- src/utility/STM32Cube_FW/tl_mbox.c | 7 +++- 8 files changed, 86 insertions(+), 20 deletions(-) diff --git a/src/utility/STM32Cube_FW/app_conf_default.h b/src/utility/STM32Cube_FW/app_conf_default.h index 51bd33af..1c6dd917 100644 --- a/src/utility/STM32Cube_FW/app_conf_default.h +++ b/src/utility/STM32Cube_FW/app_conf_default.h @@ -1,9 +1,9 @@ /* USER CODE BEGIN Header */ /** ****************************************************************************** - * @file app_conf.h + * @file app_conf_default.h * @author MCD Application Team - * @brief Application configuration file for STM32WPAN Middleware. + * @brief Default application configuration file for STM32WPAN Middleware. ****************************************************************************** * @attention * @@ -19,18 +19,38 @@ /* USER CODE END Header */ /* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef APP_CONF_H -#define APP_CONF_H - +#ifndef APP_CONF_DEFAULT_H +#define APP_CONF_DEFAULT_H +#if 0 #include "hw.h" #include "hw_conf.h" #include "hw_if.h" #include "ble_bufsize.h" - +#endif /****************************************************************************** * Application Config ******************************************************************************/ +/**< generic parameters ******************************************************/ +/* HCI related defines */ + +#define ACI_HAL_SET_TX_POWER_LEVEL 0xFC0F +#define ACI_WRITE_CONFIG_DATA_OPCODE 0xFC0C +#define ACI_READ_CONFIG_DATA_OPCODE 0xFC0D +#define MAX_HCI_ACL_PACKET_SIZE (sizeof(TL_PacketHeader_t) + 5 + 251) +#define HCI_RESET 0x0C03 + +#ifndef BLE_SHARED_MEM_BYTE_ORDER + #define BLE_SHARED_MEM_BYTE_ORDER MSBFIRST +#endif +#define BLE_MODULE_SHARED_MEM_BUFFER_SIZE 128 + +/** + * Define Tx Power + */ +#define CFG_TX_POWER (0x18) /* -0.15dBm */ + +#if 0 /** * Define Secure Connections Support */ @@ -104,7 +124,7 @@ #define CFG_FW_SUBVERSION (1) #define CFG_FW_BRANCH (0) #define CFG_FW_BUILD (0) - +#endif /****************************************************************************** * BLE Stack ******************************************************************************/ @@ -152,13 +172,15 @@ * Prepare Write List size in terms of number of packet * This parameter is ignored by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set */ -#define CFG_BLE_PREPARE_WRITE_LIST_SIZE BLE_PREP_WRITE_X_ATT(CFG_BLE_MAX_ATT_MTU) +// #define CFG_BLE_PREPARE_WRITE_LIST_SIZE BLE_PREP_WRITE_X_ATT(CFG_BLE_MAX_ATT_MTU) +#define CFG_BLE_PREPARE_WRITE_LIST_SIZE (0x3A) /** * Number of allocated memory blocks * This parameter is overwritten by the CPU2 with an hardcoded optimal value when the parameter CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set */ -#define CFG_BLE_MBLOCK_COUNT (BLE_MBLOCKS_CALC(CFG_BLE_PREPARE_WRITE_LIST_SIZE, CFG_BLE_MAX_ATT_MTU, CFG_BLE_NUM_LINK)) +//#define CFG_BLE_MBLOCK_COUNT (BLE_MBLOCKS_CALC(CFG_BLE_PREPARE_WRITE_LIST_SIZE, CFG_BLE_MAX_ATT_MTU, CFG_BLE_NUM_LINK)) +#define CFG_BLE_MBLOCK_COUNT (0x79) /** * Enable or disable the Extended Packet length feature. Valid values are 0 or 1. @@ -250,7 +272,7 @@ * 0: LE Power Class 2-3 * other bits: complete with Options_extension flag */ -#define CFG_BLE_OPTIONS (SHCI_C2_BLE_INIT_OPTIONS_LL_HOST | SHCI_C2_BLE_INIT_OPTIONS_WITH_SVC_CHANGE_DESC | SHCI_C2_BLE_INIT_OPTIONS_DEVICE_NAME_RW | SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV | SHCI_C2_BLE_INIT_OPTIONS_CS_ALGO2 | SHCI_C2_BLE_INIT_OPTIONS_FULL_GATTDB_NVM | SHCI_C2_BLE_INIT_OPTIONS_GATT_CACHING_NOTUSED | SHCI_C2_BLE_INIT_OPTIONS_POWER_CLASS_2_3) +#define CFG_BLE_OPTIONS (SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY) /** * BLE stack Options_extension flags to be configured with: @@ -323,6 +345,7 @@ #define CFG_BLE_CORE_VERSION (SHCI_C2_BLE_INIT_BLE_CORE_5_3) +#if 0 /****************************************************************************** * Transport Layer ******************************************************************************/ @@ -658,4 +681,5 @@ typedef enum #define CFG_OTP_END_ADRESS OTP_AREA_END_ADDR -#endif /*APP_CONF_H */ +#endif +#endif /*APP_CONF_DEFAULT_H */ diff --git a/src/utility/STM32Cube_FW/ble_bufsize.h b/src/utility/STM32Cube_FW/ble_bufsize.h index b9935c0b..d4d28907 100644 --- a/src/utility/STM32Cube_FW/ble_bufsize.h +++ b/src/utility/STM32Cube_FW/ble_bufsize.h @@ -75,6 +75,13 @@ ((pw) + MAX(BLE_MEM_BLOCK_X_MTU(mtu, n_link), \ BLE_MBLOCKS_SECURE_CONNECTIONS)) +/* + * BLE_DEFAULT_MBLOCKS_COUNT: default memory blocks count + */ +#define BLE_DEFAULT_MBLOCKS_COUNT(n_link) \ + BLE_MBLOCKS_CALC(BLE_DEFAULT_PREP_WRITE_LIST_SIZE, \ + BLE_DEFAULT_MAX_ATT_MTU, n_link) + /* * BLE_FIXED_BUFFER_SIZE_BYTES: * A part of the RAM, is dynamically allocated by initializing all the pointers diff --git a/src/utility/STM32Cube_FW/hw.h b/src/utility/STM32Cube_FW/hw.h index 651e1f17..1472a5e8 100644 --- a/src/utility/STM32Cube_FW/hw.h +++ b/src/utility/STM32Cube_FW/hw.h @@ -26,14 +26,23 @@ extern "C" { #endif /* Includes ------------------------------------------------------------------*/ +#include "stm32_def.h" +#include "stm32wbxx_ll_bus.h" +#include "stm32wbxx_ll_exti.h" +#include "stm32wbxx_ll_system.h" +#include "stm32wbxx_ll_rcc.h" +#include "stm32wbxx_ll_ipcc.h" +#include "stm32wbxx_ll_cortex.h" +#include "stm32wbxx_ll_utils.h" +#include "stm32wbxx_ll_pwr.h" /****************************************************************************** * HW IPCC ******************************************************************************/ void HW_IPCC_Enable( void ); void HW_IPCC_Init( void ); - void HW_IPCC_Rx_Handler( void ); - void HW_IPCC_Tx_Handler( void ); +#define HW_IPCC_Rx_Handler IPCC_C1_RX_IRQHandler +#define HW_IPCC_Tx_Handler IPCC_C1_TX_IRQHandler void HW_IPCC_BLE_Init( void ); void HW_IPCC_BLE_SendCmd( void ); diff --git a/src/utility/STM32Cube_FW/hw_ipcc.c b/src/utility/STM32Cube_FW/hw_ipcc.c index fd620b85..c7304823 100644 --- a/src/utility/STM32Cube_FW/hw_ipcc.c +++ b/src/utility/STM32Cube_FW/hw_ipcc.c @@ -17,9 +17,9 @@ ****************************************************************************** */ /* USER CODE END Header */ - +#if defined(STM32WBxx) /* Includes ------------------------------------------------------------------*/ -#include "app_common.h" +#include "hw.h" #include "mbox_def.h" /* Global variables ---------------------------------------------------------*/ @@ -667,3 +667,4 @@ static void HW_IPCC_TRACES_EvtHandler( void ) } __weak void HW_IPCC_TRACES_EvtNot( void ){}; +#endif /* STM32WBxx */ diff --git a/src/utility/STM32Cube_FW/shci.c b/src/utility/STM32Cube_FW/shci.c index eaa35d7c..4525656e 100644 --- a/src/utility/STM32Cube_FW/shci.c +++ b/src/utility/STM32Cube_FW/shci.c @@ -16,7 +16,7 @@ ****************************************************************************** */ - +#if defined(STM32WBxx) /* Includes ------------------------------------------------------------------*/ #include "stm32_wpan_common.h" @@ -739,3 +739,4 @@ SHCI_CmdStatus_t SHCI_GetWirelessFwInfo( WirelessFwInfo_t* pWirelessInfo ) return (SHCI_Success); } +#endif /* STM32WBxx */ diff --git a/src/utility/STM32Cube_FW/shci_tl.c b/src/utility/STM32Cube_FW/shci_tl.c index 0f604300..e3438094 100644 --- a/src/utility/STM32Cube_FW/shci_tl.c +++ b/src/utility/STM32Cube_FW/shci_tl.c @@ -16,12 +16,13 @@ ****************************************************************************** */ - +#if defined(STM32WBxx) /* Includes ------------------------------------------------------------------*/ #include "stm32_wpan_common.h" #include "stm_list.h" #include "shci_tl.h" +#include "stm32_def.h" /* Private typedef -----------------------------------------------------------*/ typedef enum @@ -168,6 +169,20 @@ void shci_send( uint16_t cmd_code, uint8_t len_cmd_payload, uint8_t * p_cmd_payl return; } +void shci_notify_asynch_evt(void *pdata) +{ + UNUSED(pdata); + /* Need to parse data in future version */ + shci_user_evt_proc(); +} + +void shci_register_io_bus(tSHciIO *fops) +{ + /* Register IO bus services */ + fops->Init = TL_SYS_Init; + fops->Send = TL_SYS_SendCmd; +} + /* Private functions ---------------------------------------------------------*/ static void TlInit( TL_CmdPacket_t * p_cmdbuffer ) { @@ -250,3 +265,4 @@ __WEAK void shci_cmd_resp_release(uint32_t flag) return; } +#endif /* STM32WBxx */ diff --git a/src/utility/STM32Cube_FW/stm_list.c b/src/utility/STM32Cube_FW/stm_list.c index 4c928647..4e8c3643 100644 --- a/src/utility/STM32Cube_FW/stm_list.c +++ b/src/utility/STM32Cube_FW/stm_list.c @@ -16,11 +16,13 @@ ****************************************************************************** */ - +#if defined(STM32WBxx) /****************************************************************************** * Include Files ******************************************************************************/ -#include "utilities_common.h" +#include "stdint.h" +#include "cmsis_gcc.h" +#include "stm32_wpan_common.h" #include "stm_list.h" @@ -204,3 +206,4 @@ void LST_get_prev_node (tListNode * ref_node, tListNode ** node) __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ } +#endif /* STM32WBxx */ diff --git a/src/utility/STM32Cube_FW/tl_mbox.c b/src/utility/STM32Cube_FW/tl_mbox.c index 27a998a3..11393162 100644 --- a/src/utility/STM32Cube_FW/tl_mbox.c +++ b/src/utility/STM32Cube_FW/tl_mbox.c @@ -16,6 +16,7 @@ ****************************************************************************** */ +#if defined(STM32WBxx) /* Includes ------------------------------------------------------------------*/ #include "stm32_wpan_common.h" #include "hw.h" @@ -51,9 +52,10 @@ PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_BleLldTable_t TL_BleLldTable; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_SysTable_t TL_SysTable; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_MemManagerTable_t TL_MemManagerTable; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_TracesTable_t TL_TracesTable; +#if 0 PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_Mac_802_15_4_t TL_Mac_802_15_4_Table; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_ZigbeeTable_t TL_Zigbee_Table; - +#endif /**< tables */ PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode FreeBufQueue; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode TracesEvtQueue; @@ -97,8 +99,10 @@ void TL_Init( void ) TL_RefTable.p_sys_table = &TL_SysTable; TL_RefTable.p_mem_manager_table = &TL_MemManagerTable; TL_RefTable.p_traces_table = &TL_TracesTable; +#if 0 TL_RefTable.p_mac_802_15_4_table = &TL_Mac_802_15_4_Table; TL_RefTable.p_zigbee_table = &TL_Zigbee_Table; +#endif HW_IPCC_Init(); return; @@ -846,3 +850,4 @@ static void OutputDbgTrace(TL_MB_PacketType_t packet_type, uint8_t* buffer) return; } +#endif /* STM32WBxx */ From 5d07a0e5c0463965f8cf8dde6076b5cf2c779e90 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Thu, 13 Jul 2023 17:16:40 +0200 Subject: [PATCH 140/226] fix: include a timeout when waiting for the cmd_resp Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- src/utility/STM32Cube_FW/shci_tl.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/utility/STM32Cube_FW/shci_tl.c b/src/utility/STM32Cube_FW/shci_tl.c index e3438094..60380251 100644 --- a/src/utility/STM32Cube_FW/shci_tl.c +++ b/src/utility/STM32Cube_FW/shci_tl.c @@ -23,6 +23,7 @@ #include "stm_list.h" #include "shci_tl.h" #include "stm32_def.h" +#include "wiring_time.h" /* Private typedef -----------------------------------------------------------*/ typedef enum @@ -250,10 +251,11 @@ static void TlUserEvtReceived(TL_EvtPacket_t *shcievt) /* Weak implementation ----------------------------------------------------------------*/ __WEAK void shci_cmd_resp_wait(uint32_t timeout) { - (void)timeout; - - while(CmdRspStatusFlag != SHCI_TL_CMD_RESP_RELEASE); - + for (unsigned long start = millis(); (millis() - start) < timeout;) { + if (CmdRspStatusFlag == SHCI_TL_CMD_RESP_RELEASE) { + break; + } + } return; } From 370e1082edae9b69d50f824db85b5cbe3b786e79 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Mon, 12 Dec 2022 17:29:27 +0100 Subject: [PATCH 141/226] chore: add support for customize app_conf_default.h Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- src/utility/STM32Cube_FW/app_conf_default.h | 86 ++++++++++++++++----- 1 file changed, 68 insertions(+), 18 deletions(-) diff --git a/src/utility/STM32Cube_FW/app_conf_default.h b/src/utility/STM32Cube_FW/app_conf_default.h index 1c6dd917..d39492ea 100644 --- a/src/utility/STM32Cube_FW/app_conf_default.h +++ b/src/utility/STM32Cube_FW/app_conf_default.h @@ -48,7 +48,9 @@ /** * Define Tx Power */ -#define CFG_TX_POWER (0x18) /* -0.15dBm */ +#ifndef CFG_TX_POWER + #define CFG_TX_POWER (0x18) /* -0.15dBm */ +#endif #if 0 /** @@ -132,13 +134,25 @@ * Maximum number of simultaneous connections that the device will support. * Valid values are from 1 to 8 */ -#define CFG_BLE_NUM_LINK 8 +#ifndef CFG_BLE_NUM_LINK +#ifdef STM32WB15xx + #define CFG_BLE_NUM_LINK 3 +#else + #define CFG_BLE_NUM_LINK 8 +#endif +#endif /** * Maximum number of Services that can be stored in the GATT database. * Note that the GAP and GATT services are automatically added so this parameter should be 2 plus the number of user services */ -#define CFG_BLE_NUM_GATT_SERVICES 8 +#ifndef CFG_BLE_NUM_GATT_SERVICES +#ifdef STM32WB15xx + #define CFG_BLE_NUM_GATT_SERVICES 4 +#else + #define CFG_BLE_NUM_GATT_SERVICES 8 +#endif +#endif /** * Maximum number of Attributes @@ -147,13 +161,21 @@ * Note that certain characteristics and relative descriptors are added automatically during device initialization * so this parameters should be 9 plus the number of user Attributes */ -#define CFG_BLE_NUM_GATT_ATTRIBUTES 68 +#ifndef CFG_BLE_NUM_GATT_ATTRIBUTES +#ifdef STM32WB15xx + #define CFG_BLE_NUM_GATT_ATTRIBUTES 30 +#else + #define CFG_BLE_NUM_GATT_ATTRIBUTES 68 +#endif +#endif /** * Maximum supported ATT_MTU size * This parameter is ignored by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set */ -#define CFG_BLE_MAX_ATT_MTU (156) +#ifndef CFG_BLE_MAX_ATT_MTU + #define CFG_BLE_MAX_ATT_MTU (156) +#endif /** * Size of the storage area for Attribute values @@ -166,14 +188,22 @@ * The total amount of memory needed is the sum of the above quantities for each attribute. * This parameter is ignored by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set */ -#define CFG_BLE_ATT_VALUE_ARRAY_SIZE (1344) +#ifndef CFG_BLE_ATT_VALUE_ARRAY_SIZE +#ifdef STM32WB15xx + #define CFG_BLE_ATT_VALUE_ARRAY_SIZE (1290) +#else + #define CFG_BLE_ATT_VALUE_ARRAY_SIZE (1344) +#endif +#endif /** * Prepare Write List size in terms of number of packet * This parameter is ignored by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set */ // #define CFG_BLE_PREPARE_WRITE_LIST_SIZE BLE_PREP_WRITE_X_ATT(CFG_BLE_MAX_ATT_MTU) -#define CFG_BLE_PREPARE_WRITE_LIST_SIZE (0x3A) +#ifndef CFG_BLE_PREPARE_WRITE_LIST_SIZE + #define CFG_BLE_PREPARE_WRITE_LIST_SIZE (0x3A) +#endif /** * Number of allocated memory blocks @@ -185,12 +215,16 @@ /** * Enable or disable the Extended Packet length feature. Valid values are 0 or 1. */ -#define CFG_BLE_DATA_LENGTH_EXTENSION 1 +#ifndef CFG_BLE_DATA_LENGTH_EXTENSION + #define CFG_BLE_DATA_LENGTH_EXTENSION 1 +#endif /** * Sleep clock accuracy in Slave mode (ppm value) */ -#define CFG_BLE_SLAVE_SCA 500 +#ifndef CFG_BLE_SLAVE_SCA + #define CFG_BLE_SLAVE_SCA 500 +#endif /** * Sleep clock accuracy in Master mode @@ -203,7 +237,9 @@ * 6 : 21 ppm to 30 ppm * 7 : 0 ppm to 20 ppm */ -#define CFG_BLE_MASTER_SCA 0 +#ifndef CFG_BLE_MASTER_SCA + #define CFG_BLE_MASTER_SCA 0 +#endif /** * LsSource @@ -212,21 +248,27 @@ * - bit 1: 1: STM32WB5M Module device 0: Other devices as STM32WBxx SOC, STM32WB1M module * - bit 2: 1: HSE/1024 Clock config 0: LSE Clock config */ -#if defined(STM32WB5Mxx) - #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_MOD5MM_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) -#else - #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_OTHER_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) +#ifndef CFG_BLE_LS_SOURCE + #if defined(STM32WB5Mxx) + #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_MOD5MM_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) + #else + #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_OTHER_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) + #endif #endif /** * Start up time of the high speed (16 or 32 MHz) crystal oscillator in units of 625/256 us (~2.44 us) */ -#define CFG_BLE_HSE_STARTUP_TIME 0x148 +#ifndef CFG_BLE_HSE_STARTUP_TIME + #define CFG_BLE_HSE_STARTUP_TIME 0x148 +#endif /** * Maximum duration of the connection event when the device is in Slave mode in units of 625/256 us (~2.44 us) */ -#define CFG_BLE_MAX_CONN_EVENT_LENGTH (0xFFFFFFFF) +#ifndef CFG_BLE_MAX_CONN_EVENT_LENGTH + #define CFG_BLE_MAX_CONN_EVENT_LENGTH (0xFFFFFFFF) +#endif /** * Viterbi Mode @@ -314,7 +356,11 @@ * This parameter is considered by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV flag set */ -#define CFG_BLE_MAX_ADV_SET_NBR (8) +#if defined(STM32WB15xx) + #define CFG_BLE_MAX_ADV_SET_NBR (3) +#else + #define CFG_BLE_MAX_ADV_SET_NBR (8) +#endif /* Maximum advertising data length (in bytes) * Range: 31 .. 1650 with limitation: @@ -323,7 +369,11 @@ * This parameter is considered by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV flag set */ -#define CFG_BLE_MAX_ADV_DATA_LEN (207) +#if defined(STM32WB15xx) + #define CFG_BLE_MAX_ADV_DATA_LEN (414) +#else + #define CFG_BLE_MAX_ADV_DATA_LEN (207) +#endif /* RF TX Path Compensation Value (16-bit signed integer). Units: 0.1 dB. * Range: -1280 .. 1280 From 819cebd2bed57448f925d34d50d8df51cbe58c04 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Mon, 24 Jul 2023 10:55:20 +0200 Subject: [PATCH 142/226] fix: TL_Evt_t payload size for reset Within last CubeWB update TL_Evt_t payload size was reduced. This produce a warning -Warray-bounds due to the reset management which require 4 bytes. Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- src/utility/STM32Cube_FW/tl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utility/STM32Cube_FW/tl.h b/src/utility/STM32Cube_FW/tl.h index 8e8c6cbc..74520878 100644 --- a/src/utility/STM32Cube_FW/tl.h +++ b/src/utility/STM32Cube_FW/tl.h @@ -108,7 +108,7 @@ typedef PACKED_STRUCT { uint8_t evtcode; uint8_t plen; - uint8_t payload[2]; + uint8_t payload[4]; } TL_Evt_t; typedef PACKED_STRUCT From 2a070faebcae906ff48c7329b0c2de2b2d64744d Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Mon, 24 Jul 2023 11:19:27 +0200 Subject: [PATCH 143/226] fix: regenerate STM32Cube_FW patches Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- ...001-chore-adapt-STM32Cube_FW-sources.patch | 4 +-- ...imeout-when-waiting-for-the-cmd_resp.patch | 4 +-- ...ort-for-customize-app_conf_default.h.patch | 4 +-- ...-fix-TL_Evt_t-payload-size-for-reset.patch | 30 +++++++++++++++++++ 4 files changed, 36 insertions(+), 6 deletions(-) create mode 100644 extras/STM32Cube_FW/0004-fix-TL_Evt_t-payload-size-for-reset.patch diff --git a/extras/STM32Cube_FW/0001-chore-adapt-STM32Cube_FW-sources.patch b/extras/STM32Cube_FW/0001-chore-adapt-STM32Cube_FW-sources.patch index ce3c8818..48a28137 100644 --- a/extras/STM32Cube_FW/0001-chore-adapt-STM32Cube_FW-sources.patch +++ b/extras/STM32Cube_FW/0001-chore-adapt-STM32Cube_FW-sources.patch @@ -1,7 +1,7 @@ -From fd17a2302d60208768610cb4723eb403c52ff2b1 Mon Sep 17 00:00:00 2001 +From 542e007fa5a1b53664d2efb5f01d67767123a357 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Thu, 13 Jul 2023 17:08:05 +0200 -Subject: [PATCH 1/3] chore: adapt STM32Cube_FW sources +Subject: [PATCH 1/4] chore: adapt STM32Cube_FW sources Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- diff --git a/extras/STM32Cube_FW/0002-fix-include-a-timeout-when-waiting-for-the-cmd_resp.patch b/extras/STM32Cube_FW/0002-fix-include-a-timeout-when-waiting-for-the-cmd_resp.patch index 4afa2128..07ce6e6e 100644 --- a/extras/STM32Cube_FW/0002-fix-include-a-timeout-when-waiting-for-the-cmd_resp.patch +++ b/extras/STM32Cube_FW/0002-fix-include-a-timeout-when-waiting-for-the-cmd_resp.patch @@ -1,7 +1,7 @@ -From 598c654f18fc9389be8326610a51052943151f04 Mon Sep 17 00:00:00 2001 +From 5d07a0e5c0463965f8cf8dde6076b5cf2c779e90 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Thu, 13 Jul 2023 17:16:40 +0200 -Subject: [PATCH 2/3] fix: include a timeout when waiting for the cmd_resp +Subject: [PATCH 2/4] fix: include a timeout when waiting for the cmd_resp Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- diff --git a/extras/STM32Cube_FW/0003-chore-add-support-for-customize-app_conf_default.h.patch b/extras/STM32Cube_FW/0003-chore-add-support-for-customize-app_conf_default.h.patch index 32e10c12..e23d54c8 100644 --- a/extras/STM32Cube_FW/0003-chore-add-support-for-customize-app_conf_default.h.patch +++ b/extras/STM32Cube_FW/0003-chore-add-support-for-customize-app_conf_default.h.patch @@ -1,7 +1,7 @@ -From 663ed22fd680de1f32c542df0799c403665ecb2e Mon Sep 17 00:00:00 2001 +From 370e1082edae9b69d50f824db85b5cbe3b786e79 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Mon, 12 Dec 2022 17:29:27 +0100 -Subject: [PATCH 3/3] chore: add support for customize app_conf_default.h +Subject: [PATCH 3/4] chore: add support for customize app_conf_default.h Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- diff --git a/extras/STM32Cube_FW/0004-fix-TL_Evt_t-payload-size-for-reset.patch b/extras/STM32Cube_FW/0004-fix-TL_Evt_t-payload-size-for-reset.patch new file mode 100644 index 00000000..c239749f --- /dev/null +++ b/extras/STM32Cube_FW/0004-fix-TL_Evt_t-payload-size-for-reset.patch @@ -0,0 +1,30 @@ +From b294edcaee311c15dfb307ea1298ae88b16a92bf Mon Sep 17 00:00:00 2001 +From: Frederic Pillon <frederic.pillon@st.com> +Date: Mon, 24 Jul 2023 10:55:20 +0200 +Subject: [PATCH 4/4] fix: TL_Evt_t payload size for reset + +Within STM32CubeWB v1.17.0 update TL_Evt_t payload size was reduced. +This produce a warning -Warray-bounds due to the reset management +which require 4 bytes. + +Signed-off-by: Frederic Pillon <frederic.pillon@st.com> +--- + src/utility/STM32Cube_FW/tl.h | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/utility/STM32Cube_FW/tl.h b/src/utility/STM32Cube_FW/tl.h +index 8e8c6cb..7452087 100644 +--- a/src/utility/STM32Cube_FW/tl.h ++++ b/src/utility/STM32Cube_FW/tl.h +@@ -108,7 +108,7 @@ typedef PACKED_STRUCT + { + uint8_t evtcode; + uint8_t plen; +- uint8_t payload[2]; ++ uint8_t payload[4]; + } TL_Evt_t; + + typedef PACKED_STRUCT +-- +2.38.0.windows.1 + From 347ff927abfbe29e336087ce184c5858b0364bc6 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Tue, 9 Jan 2024 15:20:47 +0100 Subject: [PATCH 144/226] chore: bump library version to 1.2.6 Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index 35083868..da5c1c4c 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=STM32duinoBLE -version=1.2.5 +version=1.2.6 author=Arduino, SRA maintainer=stm32duino sentence=Fork of ArduinoBLE library to add the support of STM32WB, SPBTLE-RF, SPBTLE-1S, BLUENRG-M2SP and BLUENRG-M0 BLE modules. From b0e78ca824c28af27057d02a808995fe19060d25 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Wed, 10 Jan 2024 18:21:35 +0100 Subject: [PATCH 145/226] chore: rename STM32Cube_FW to STM32_WPAN Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- .github/workflows/codespell.yml | 2 +- ...0001-chore-adapt-STM32_WPAN-sources.patch} | 66 ++-- ...imeout-when-waiting-for-the-cmd_resp.patch | 8 +- ...ort-for-customize-app_conf_default.h.patch | 8 +- ...-fix-TL_Evt_t-payload-size-for-reset.patch | 8 +- patch0.patch | 296 ++++++++++++++++++ src/utility/HCISharedMemTransport.cpp | 2 +- src/utility/HCISharedMemTransport.h | 8 +- .../{STM32Cube_FW => STM32_WPAN}/LICENSE.md | 0 .../{STM32Cube_FW => STM32_WPAN}/README.md | 0 .../{STM32Cube_FW => STM32_WPAN}/app_conf.h | 0 .../app_conf_default.h | 0 .../ble_bufsize.h | 0 src/utility/{STM32Cube_FW => STM32_WPAN}/hw.h | 0 .../{STM32Cube_FW => STM32_WPAN}/hw_ipcc.c | 0 .../{STM32Cube_FW => STM32_WPAN}/mbox_def.h | 0 .../{STM32Cube_FW => STM32_WPAN}/shci.c | 0 .../{STM32Cube_FW => STM32_WPAN}/shci.h | 0 .../{STM32Cube_FW => STM32_WPAN}/shci_tl.c | 0 .../{STM32Cube_FW => STM32_WPAN}/shci_tl.h | 0 .../stm32_wpan_common.h | 0 .../{STM32Cube_FW => STM32_WPAN}/stm_list.c | 0 .../{STM32Cube_FW => STM32_WPAN}/stm_list.h | 0 src/utility/{STM32Cube_FW => STM32_WPAN}/tl.h | 0 .../tl_dbg_conf.h | 0 .../{STM32Cube_FW => STM32_WPAN}/tl_mbox.c | 0 26 files changed, 347 insertions(+), 51 deletions(-) rename extras/{STM32Cube_FW/0001-chore-adapt-STM32Cube_FW-sources.patch => STM32_WPAN/0001-chore-adapt-STM32_WPAN-sources.patch} (84%) rename extras/{STM32Cube_FW => STM32_WPAN}/0002-fix-include-a-timeout-when-waiting-for-the-cmd_resp.patch (83%) rename extras/{STM32Cube_FW => STM32_WPAN}/0003-chore-add-support-for-customize-app_conf_default.h.patch (95%) rename extras/{STM32Cube_FW => STM32_WPAN}/0004-fix-TL_Evt_t-payload-size-for-reset.patch (79%) create mode 100644 patch0.patch rename src/utility/{STM32Cube_FW => STM32_WPAN}/LICENSE.md (100%) rename src/utility/{STM32Cube_FW => STM32_WPAN}/README.md (100%) rename src/utility/{STM32Cube_FW => STM32_WPAN}/app_conf.h (100%) rename src/utility/{STM32Cube_FW => STM32_WPAN}/app_conf_default.h (100%) rename src/utility/{STM32Cube_FW => STM32_WPAN}/ble_bufsize.h (100%) rename src/utility/{STM32Cube_FW => STM32_WPAN}/hw.h (100%) rename src/utility/{STM32Cube_FW => STM32_WPAN}/hw_ipcc.c (100%) rename src/utility/{STM32Cube_FW => STM32_WPAN}/mbox_def.h (100%) rename src/utility/{STM32Cube_FW => STM32_WPAN}/shci.c (100%) rename src/utility/{STM32Cube_FW => STM32_WPAN}/shci.h (100%) rename src/utility/{STM32Cube_FW => STM32_WPAN}/shci_tl.c (100%) rename src/utility/{STM32Cube_FW => STM32_WPAN}/shci_tl.h (100%) rename src/utility/{STM32Cube_FW => STM32_WPAN}/stm32_wpan_common.h (100%) rename src/utility/{STM32Cube_FW => STM32_WPAN}/stm_list.c (100%) rename src/utility/{STM32Cube_FW => STM32_WPAN}/stm_list.h (100%) rename src/utility/{STM32Cube_FW => STM32_WPAN}/tl.h (100%) rename src/utility/{STM32Cube_FW => STM32_WPAN}/tl_dbg_conf.h (100%) rename src/utility/{STM32Cube_FW => STM32_WPAN}/tl_mbox.c (100%) diff --git a/.github/workflows/codespell.yml b/.github/workflows/codespell.yml index 744a6d2e..5c30659f 100644 --- a/.github/workflows/codespell.yml +++ b/.github/workflows/codespell.yml @@ -24,5 +24,5 @@ jobs: check_hidden: true # In the event of a false positive, add the word in all lower case to this file: # ignore_words_file: ./extras/codespell-ignore-words-list.txt - skip: src/utility/STM32Cube_FW + skip: src/utility/STM32_WPAN path: src diff --git a/extras/STM32Cube_FW/0001-chore-adapt-STM32Cube_FW-sources.patch b/extras/STM32_WPAN/0001-chore-adapt-STM32_WPAN-sources.patch similarity index 84% rename from extras/STM32Cube_FW/0001-chore-adapt-STM32Cube_FW-sources.patch rename to extras/STM32_WPAN/0001-chore-adapt-STM32_WPAN-sources.patch index 48a28137..6798e172 100644 --- a/extras/STM32Cube_FW/0001-chore-adapt-STM32Cube_FW-sources.patch +++ b/extras/STM32_WPAN/0001-chore-adapt-STM32_WPAN-sources.patch @@ -1,24 +1,24 @@ From 542e007fa5a1b53664d2efb5f01d67767123a357 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Thu, 13 Jul 2023 17:08:05 +0200 -Subject: [PATCH 1/4] chore: adapt STM32Cube_FW sources +Subject: [PATCH 1/4] chore: adapt STM32_WPAN sources Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- - src/utility/STM32Cube_FW/app_conf_default.h | 46 ++++++++++++++++----- - src/utility/STM32Cube_FW/ble_bufsize.h | 7 ++++ - src/utility/STM32Cube_FW/hw.h | 13 +++++- - src/utility/STM32Cube_FW/hw_ipcc.c | 5 ++- - src/utility/STM32Cube_FW/shci.c | 3 +- - src/utility/STM32Cube_FW/shci_tl.c | 18 +++++++- - src/utility/STM32Cube_FW/stm_list.c | 7 +++- - src/utility/STM32Cube_FW/tl_mbox.c | 7 +++- + src/utility/STM32_WPAN/app_conf_default.h | 46 ++++++++++++++++----- + src/utility/STM32_WPAN/ble_bufsize.h | 7 ++++ + src/utility/STM32_WPAN/hw.h | 13 +++++- + src/utility/STM32_WPAN/hw_ipcc.c | 5 ++- + src/utility/STM32_WPAN/shci.c | 3 +- + src/utility/STM32_WPAN/shci_tl.c | 18 +++++++- + src/utility/STM32_WPAN/stm_list.c | 7 +++- + src/utility/STM32_WPAN/tl_mbox.c | 7 +++- 8 files changed, 86 insertions(+), 20 deletions(-) -diff --git a/src/utility/STM32Cube_FW/app_conf_default.h b/src/utility/STM32Cube_FW/app_conf_default.h +diff --git a/src/utility/STM32_WPAN/app_conf_default.h b/src/utility/STM32_WPAN/app_conf_default.h index 51bd33a..1c6dd91 100644 ---- a/src/utility/STM32Cube_FW/app_conf_default.h -+++ b/src/utility/STM32Cube_FW/app_conf_default.h +--- a/src/utility/STM32_WPAN/app_conf_default.h ++++ b/src/utility/STM32_WPAN/app_conf_default.h @@ -1,9 +1,9 @@ /* USER CODE BEGIN Header */ /** @@ -125,10 +125,10 @@ index 51bd33a..1c6dd91 100644 -#endif /*APP_CONF_H */ +#endif +#endif /*APP_CONF_DEFAULT_H */ -diff --git a/src/utility/STM32Cube_FW/ble_bufsize.h b/src/utility/STM32Cube_FW/ble_bufsize.h +diff --git a/src/utility/STM32_WPAN/ble_bufsize.h b/src/utility/STM32_WPAN/ble_bufsize.h index b9935c0..d4d2890 100644 ---- a/src/utility/STM32Cube_FW/ble_bufsize.h -+++ b/src/utility/STM32Cube_FW/ble_bufsize.h +--- a/src/utility/STM32_WPAN/ble_bufsize.h ++++ b/src/utility/STM32_WPAN/ble_bufsize.h @@ -75,6 +75,13 @@ ((pw) + MAX(BLE_MEM_BLOCK_X_MTU(mtu, n_link), \ BLE_MBLOCKS_SECURE_CONNECTIONS)) @@ -143,10 +143,10 @@ index b9935c0..d4d2890 100644 /* * BLE_FIXED_BUFFER_SIZE_BYTES: * A part of the RAM, is dynamically allocated by initializing all the pointers -diff --git a/src/utility/STM32Cube_FW/hw.h b/src/utility/STM32Cube_FW/hw.h +diff --git a/src/utility/STM32_WPAN/hw.h b/src/utility/STM32_WPAN/hw.h index 651e1f1..1472a5e 100644 ---- a/src/utility/STM32Cube_FW/hw.h -+++ b/src/utility/STM32Cube_FW/hw.h +--- a/src/utility/STM32_WPAN/hw.h ++++ b/src/utility/STM32_WPAN/hw.h @@ -26,14 +26,23 @@ extern "C" { #endif @@ -173,10 +173,10 @@ index 651e1f1..1472a5e 100644 void HW_IPCC_BLE_Init( void ); void HW_IPCC_BLE_SendCmd( void ); -diff --git a/src/utility/STM32Cube_FW/hw_ipcc.c b/src/utility/STM32Cube_FW/hw_ipcc.c +diff --git a/src/utility/STM32_WPAN/hw_ipcc.c b/src/utility/STM32_WPAN/hw_ipcc.c index fd620b8..c730482 100644 ---- a/src/utility/STM32Cube_FW/hw_ipcc.c -+++ b/src/utility/STM32Cube_FW/hw_ipcc.c +--- a/src/utility/STM32_WPAN/hw_ipcc.c ++++ b/src/utility/STM32_WPAN/hw_ipcc.c @@ -17,9 +17,9 @@ ****************************************************************************** */ @@ -194,10 +194,10 @@ index fd620b8..c730482 100644 __weak void HW_IPCC_TRACES_EvtNot( void ){}; +#endif /* STM32WBxx */ -diff --git a/src/utility/STM32Cube_FW/shci.c b/src/utility/STM32Cube_FW/shci.c +diff --git a/src/utility/STM32_WPAN/shci.c b/src/utility/STM32_WPAN/shci.c index eaa35d7..4525656 100644 ---- a/src/utility/STM32Cube_FW/shci.c -+++ b/src/utility/STM32Cube_FW/shci.c +--- a/src/utility/STM32_WPAN/shci.c ++++ b/src/utility/STM32_WPAN/shci.c @@ -16,7 +16,7 @@ ****************************************************************************** */ @@ -212,10 +212,10 @@ index eaa35d7..4525656 100644 return (SHCI_Success); } +#endif /* STM32WBxx */ -diff --git a/src/utility/STM32Cube_FW/shci_tl.c b/src/utility/STM32Cube_FW/shci_tl.c +diff --git a/src/utility/STM32_WPAN/shci_tl.c b/src/utility/STM32_WPAN/shci_tl.c index 0f60430..e343809 100644 ---- a/src/utility/STM32Cube_FW/shci_tl.c -+++ b/src/utility/STM32Cube_FW/shci_tl.c +--- a/src/utility/STM32_WPAN/shci_tl.c ++++ b/src/utility/STM32_WPAN/shci_tl.c @@ -16,12 +16,13 @@ ****************************************************************************** */ @@ -257,10 +257,10 @@ index 0f60430..e343809 100644 return; } +#endif /* STM32WBxx */ -diff --git a/src/utility/STM32Cube_FW/stm_list.c b/src/utility/STM32Cube_FW/stm_list.c +diff --git a/src/utility/STM32_WPAN/stm_list.c b/src/utility/STM32_WPAN/stm_list.c index 4c92864..4e8c364 100644 ---- a/src/utility/STM32Cube_FW/stm_list.c -+++ b/src/utility/STM32Cube_FW/stm_list.c +--- a/src/utility/STM32_WPAN/stm_list.c ++++ b/src/utility/STM32_WPAN/stm_list.c @@ -16,11 +16,13 @@ ****************************************************************************** */ @@ -282,10 +282,10 @@ index 4c92864..4e8c364 100644 __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ } +#endif /* STM32WBxx */ -diff --git a/src/utility/STM32Cube_FW/tl_mbox.c b/src/utility/STM32Cube_FW/tl_mbox.c +diff --git a/src/utility/STM32_WPAN/tl_mbox.c b/src/utility/STM32_WPAN/tl_mbox.c index 27a998a..1139316 100644 ---- a/src/utility/STM32Cube_FW/tl_mbox.c -+++ b/src/utility/STM32Cube_FW/tl_mbox.c +--- a/src/utility/STM32_WPAN/tl_mbox.c ++++ b/src/utility/STM32_WPAN/tl_mbox.c @@ -16,6 +16,7 @@ ****************************************************************************** */ diff --git a/extras/STM32Cube_FW/0002-fix-include-a-timeout-when-waiting-for-the-cmd_resp.patch b/extras/STM32_WPAN/0002-fix-include-a-timeout-when-waiting-for-the-cmd_resp.patch similarity index 83% rename from extras/STM32Cube_FW/0002-fix-include-a-timeout-when-waiting-for-the-cmd_resp.patch rename to extras/STM32_WPAN/0002-fix-include-a-timeout-when-waiting-for-the-cmd_resp.patch index 07ce6e6e..d147a37e 100644 --- a/extras/STM32Cube_FW/0002-fix-include-a-timeout-when-waiting-for-the-cmd_resp.patch +++ b/extras/STM32_WPAN/0002-fix-include-a-timeout-when-waiting-for-the-cmd_resp.patch @@ -5,13 +5,13 @@ Subject: [PATCH 2/4] fix: include a timeout when waiting for the cmd_resp Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- - src/utility/STM32Cube_FW/shci_tl.c | 10 ++++++---- + src/utility/STM32_WPAN/shci_tl.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) -diff --git a/src/utility/STM32Cube_FW/shci_tl.c b/src/utility/STM32Cube_FW/shci_tl.c +diff --git a/src/utility/STM32_WPAN/shci_tl.c b/src/utility/STM32_WPAN/shci_tl.c index e343809..6038025 100644 ---- a/src/utility/STM32Cube_FW/shci_tl.c -+++ b/src/utility/STM32Cube_FW/shci_tl.c +--- a/src/utility/STM32_WPAN/shci_tl.c ++++ b/src/utility/STM32_WPAN/shci_tl.c @@ -23,6 +23,7 @@ #include "stm_list.h" #include "shci_tl.h" diff --git a/extras/STM32Cube_FW/0003-chore-add-support-for-customize-app_conf_default.h.patch b/extras/STM32_WPAN/0003-chore-add-support-for-customize-app_conf_default.h.patch similarity index 95% rename from extras/STM32Cube_FW/0003-chore-add-support-for-customize-app_conf_default.h.patch rename to extras/STM32_WPAN/0003-chore-add-support-for-customize-app_conf_default.h.patch index e23d54c8..93e3e80f 100644 --- a/extras/STM32Cube_FW/0003-chore-add-support-for-customize-app_conf_default.h.patch +++ b/extras/STM32_WPAN/0003-chore-add-support-for-customize-app_conf_default.h.patch @@ -5,13 +5,13 @@ Subject: [PATCH 3/4] chore: add support for customize app_conf_default.h Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- - src/utility/STM32Cube_FW/app_conf_default.h | 86 ++++++++++++++++----- + src/utility/STM32_WPAN/app_conf_default.h | 86 ++++++++++++++++----- 1 file changed, 68 insertions(+), 18 deletions(-) -diff --git a/src/utility/STM32Cube_FW/app_conf_default.h b/src/utility/STM32Cube_FW/app_conf_default.h +diff --git a/src/utility/STM32_WPAN/app_conf_default.h b/src/utility/STM32_WPAN/app_conf_default.h index 1c6dd91..d39492e 100644 ---- a/src/utility/STM32Cube_FW/app_conf_default.h -+++ b/src/utility/STM32Cube_FW/app_conf_default.h +--- a/src/utility/STM32_WPAN/app_conf_default.h ++++ b/src/utility/STM32_WPAN/app_conf_default.h @@ -48,7 +48,9 @@ /** * Define Tx Power diff --git a/extras/STM32Cube_FW/0004-fix-TL_Evt_t-payload-size-for-reset.patch b/extras/STM32_WPAN/0004-fix-TL_Evt_t-payload-size-for-reset.patch similarity index 79% rename from extras/STM32Cube_FW/0004-fix-TL_Evt_t-payload-size-for-reset.patch rename to extras/STM32_WPAN/0004-fix-TL_Evt_t-payload-size-for-reset.patch index c239749f..8ac978ea 100644 --- a/extras/STM32Cube_FW/0004-fix-TL_Evt_t-payload-size-for-reset.patch +++ b/extras/STM32_WPAN/0004-fix-TL_Evt_t-payload-size-for-reset.patch @@ -9,13 +9,13 @@ which require 4 bytes. Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- - src/utility/STM32Cube_FW/tl.h | 2 +- + src/utility/STM32_WPAN/tl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -diff --git a/src/utility/STM32Cube_FW/tl.h b/src/utility/STM32Cube_FW/tl.h +diff --git a/src/utility/STM32_WPAN/tl.h b/src/utility/STM32_WPAN/tl.h index 8e8c6cb..7452087 100644 ---- a/src/utility/STM32Cube_FW/tl.h -+++ b/src/utility/STM32Cube_FW/tl.h +--- a/src/utility/STM32_WPAN/tl.h ++++ b/src/utility/STM32_WPAN/tl.h @@ -108,7 +108,7 @@ typedef PACKED_STRUCT { uint8_t evtcode; diff --git a/patch0.patch b/patch0.patch new file mode 100644 index 00000000..ae067cb6 --- /dev/null +++ b/patch0.patch @@ -0,0 +1,296 @@ +diff --git a/src/utility/STM32Cube_FW/README.md b/src/utility/STM32Cube_FW/README.md +index 0d39a3e..97c4ceb 100644 +--- a/src/utility/STM32Cube_FW/README.md ++++ b/src/utility/STM32Cube_FW/README.md +@@ -1,6 +1,6 @@ + + ## Source + +-[STMicroelectronics/STM32CubeWB Release v1.17.0](https://github.com/STMicroelectronics/STM32CubeWB/releases/tag/v1.17.0) +-- Application: [BLE_TransparentMode](https://github.com/STMicroelectronics/STM32CubeWB/tree/v1.17.0/Projects/P-NUCLEO-WB55.Nucleo/Applications/BLE/BLE_TransparentMode) ++[STMicroelectronics/STM32CubeWB Release v1.18.0](https://github.com/STMicroelectronics/STM32CubeWB/releases/tag/v1.18.0) ++- Application: [BLE_TransparentMode](https://github.com/STMicroelectronics/STM32CubeWB/tree/v1.18.0/Projects/P-NUCLEO-WB55.Nucleo/Applications/BLE/BLE_TransparentMode) + +diff --git a/src/utility/STM32Cube_FW/app_conf_default.h b/src/utility/STM32Cube_FW/app_conf_default.h +index 51bd33a..846be3c 100644 +--- a/src/utility/STM32Cube_FW/app_conf_default.h ++++ b/src/utility/STM32Cube_FW/app_conf_default.h +@@ -61,14 +61,14 @@ + #define CFG_GAP_DEVICE_NAME_LENGTH (8) + + /** +-* Identity root key used to derive LTK and CSRK ++* Identity root key used to derive IRK and DHK(Legacy) + */ +-#define CFG_BLE_IRK {0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0} ++#define CFG_BLE_IR {0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0} + + /** +-* Encryption root key used to derive LTK and CSRK ++* Encryption root key used to derive LTK(Legacy) and CSRK + */ +-#define CFG_BLE_ERK {0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21, 0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21} ++#define CFG_BLE_ER {0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21, 0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21} + + /** + * SMPS supply +@@ -166,12 +166,12 @@ + #define CFG_BLE_DATA_LENGTH_EXTENSION 1 + + /** +- * Sleep clock accuracy in Slave mode (ppm value) ++ * Sleep clock accuracy in Peripheral mode (ppm value) + */ +-#define CFG_BLE_SLAVE_SCA 500 ++#define CFG_BLE_PERIPHERAL_SCA 500 + + /** +- * Sleep clock accuracy in Master mode ++ * Sleep clock accuracy in Central mode + * 0 : 251 ppm to 500 ppm + * 1 : 151 ppm to 250 ppm + * 2 : 101 ppm to 150 ppm +@@ -181,7 +181,7 @@ + * 6 : 21 ppm to 30 ppm + * 7 : 0 ppm to 20 ppm + */ +-#define CFG_BLE_MASTER_SCA 0 ++#define CFG_BLE_CENTRAL_SCA 0 + + /** + * LsSource +@@ -202,7 +202,7 @@ + #define CFG_BLE_HSE_STARTUP_TIME 0x148 + + /** +- * Maximum duration of the connection event when the device is in Slave mode in units of 625/256 us (~2.44 us) ++ * Maximum duration of the connection event when the device is in Peripheral mode in units of 625/256 us (~2.44 us) + */ + #define CFG_BLE_MAX_CONN_EVENT_LENGTH (0xFFFFFFFF) + +@@ -318,10 +318,11 @@ + /* BLE core version (16-bit signed integer). + * - SHCI_C2_BLE_INIT_BLE_CORE_5_2 + * - SHCI_C2_BLE_INIT_BLE_CORE_5_3 +- * which are used to set: 11(5.2), 12(5.3). ++ * - SHCI_C2_BLE_INIT_BLE_CORE_5_4 ++ * which are used to set: 11(5.2), 12(5.3), 13(5.4). + */ + +-#define CFG_BLE_CORE_VERSION (SHCI_C2_BLE_INIT_BLE_CORE_5_3) ++#define CFG_BLE_CORE_VERSION (SHCI_C2_BLE_INIT_BLE_CORE_5_4) + + /****************************************************************************** + * Transport Layer +@@ -486,13 +487,13 @@ typedef enum + * Debug + ******************************************************************************/ + /** +- * When set, this resets some hw resources to set the device in the same state than the power up +- * The FW resets only register that may prevent the FW to run properly ++ * When set, this resets some hw resources to put the device in the same state as at power up. ++ * It resets only register that may prevent the FW to run properly. + * + * This shall be set to 0 in a final product + * + */ +-#define CFG_HW_RESET_BY_FW 1 ++#define CFG_HW_RESET_BY_FW 0 + + /** + * keep debugger enabled while in any low power mode when set to 1 +diff --git a/src/utility/STM32Cube_FW/shci.c b/src/utility/STM32Cube_FW/shci.c +index eaa35d7..5c32555 100644 +--- a/src/utility/STM32Cube_FW/shci.c ++++ b/src/utility/STM32Cube_FW/shci.c +@@ -644,6 +644,26 @@ SHCI_CmdStatus_t SHCI_C2_802_15_4_DeInit( void ) + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); + } + ++SHCI_CmdStatus_t SHCI_C2_SetSystemClock( SHCI_C2_SET_SYSTEM_CLOCK_Cmd_Param_t clockSel ) ++{ ++ /** ++ * Buffer is large enough to hold command complete without payload ++ */ ++ uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; ++ TL_EvtPacket_t * p_rsp; ++ ++ p_rsp = (TL_EvtPacket_t *)local_buffer; ++ ++ local_buffer[0] = (uint8_t)clockSel; ++ ++ shci_send( SHCI_OPCODE_C2_SET_SYSTEM_CLOCK, ++ 1, ++ local_buffer, ++ p_rsp ); ++ ++ return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); ++} ++ + /** + * Local System COMMAND + * These commands are NOT sent to the CPU2 +diff --git a/src/utility/STM32Cube_FW/shci.h b/src/utility/STM32Cube_FW/shci.h +index 750fa97..30ae10c 100644 +--- a/src/utility/STM32Cube_FW/shci.h ++++ b/src/utility/STM32Cube_FW/shci.h +@@ -227,6 +227,7 @@ extern "C" { + SHCI_OCF_C2_CONCURRENT_GET_NEXT_BLE_EVT_TIME, + SHCI_OCF_C2_CONCURRENT_ENABLE_NEXT_802154_EVT_NOTIFICATION, + SHCI_OCF_C2_802_15_4_DEINIT, ++ SHCI_OCF_C2_SET_SYSTEM_CLOCK, + } SHCI_OCF_t; + + #define SHCI_OPCODE_C2_FUS_GET_STATE (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_GET_STATE) +@@ -436,7 +437,7 @@ extern "C" { + * PrWriteListSize + * NOTE: This parameter is ignored by the CPU2 when the parameter "Options" is set to "LL_only" ( see Options description in that structure ) + * +- * Maximum number of supported �prepare write request� ++ * Maximum number of supported "prepare write request" + * - Min value: given by the macro DEFAULT_PREP_WRITE_LIST_SIZE + * - Max value: a value higher than the minimum required can be specified, but it is not recommended + */ +@@ -464,20 +465,20 @@ extern "C" { + uint16_t AttMtu; + + /** +- * SlaveSca +- * The sleep clock accuracy (ppm value) that used in BLE connected slave mode to calculate the window widening ++ * PeripheralSca ++ * The sleep clock accuracy (ppm value) that used in BLE connected Peripheral mode to calculate the window widening + * (in combination with the sleep clock accuracy sent by master in CONNECT_REQ PDU), + * refer to BLE 5.0 specifications - Vol 6 - Part B - chap 4.5.7 and 4.2.2 + * - Min value: 0 + * - Max value: 500 (worst possible admitted by specification) + */ +- uint16_t SlaveSca; ++ uint16_t PeripheralSca; + + /** +- * MasterSca +- * The sleep clock accuracy handled in master mode. It is used to determine the connection and advertising events timing. ++ * CentralSca ++ * The sleep clock accuracy handled in Central mode. It is used to determine the connection and advertising events timing. + * It is transmitted to the slave in CONNEC_REQ PDU used by the slave to calculate the window widening, +- * see SlaveSca and Bluetooth Core Specification v5.0 Vol 6 - Part B - chap 4.5.7 and 4.2.2 ++ * see PeripheralSca and Bluetooth Core Specification v5.0 Vol 6 - Part B - chap 4.5.7 and 4.2.2 + * Possible values: + * - 251 ppm to 500 ppm: 0 + * - 151 ppm to 250 ppm: 1 +@@ -488,7 +489,7 @@ extern "C" { + * - 21 ppm to 30 ppm: 6 + * - 0 ppm to 20 ppm: 7 + */ +- uint8_t MasterSca; ++ uint8_t CentralSca; + + /** + * LsSource +@@ -503,7 +504,7 @@ extern "C" { + * MaxConnEventLength + * This parameter determines the maximum duration of a slave connection event. When this duration is reached the slave closes + * the current connections event (whatever is the CE_length parameter specified by the master in HCI_CREATE_CONNECTION HCI command), +- * expressed in units of 625/256 �s (~2.44 �s) ++ * expressed in units of 625/256 us (~2.44 us) + * - Min value: 0 (if 0 is specified, the master and slave perform only a single TX-RX exchange per connection event) + * - Max value: 1638400 (4000 ms). A higher value can be specified (max 0xFFFFFFFF) but results in a maximum connection time + * of 4000 ms as specified. In this case the parameter is not applied, and the predicted CE length calculated on slave is not shortened +@@ -512,7 +513,7 @@ extern "C" { + + /** + * HsStartupTime +- * Startup time of the high speed (16 or 32 MHz) crystal oscillator in units of 625/256 �s (~2.44 �s). ++ * Startup time of the high speed (16 or 32 MHz) crystal oscillator in units of 625/256 us (~2.44 us). + * - Min value: 0 + * - Max value: 820 (~2 ms). A higher value can be specified, but the value that implemented in stack is forced to ~2 ms + */ +@@ -598,7 +599,7 @@ extern "C" { + int16_t rx_path_compens; + + /* BLE core specification version (8-bit unsigned integer). +- * values as: 11(5.2), 12(5.3) ++ * values as: 11(5.2), 12(5.3), 13(5.4) + */ + uint8_t ble_core_version; + +@@ -829,6 +830,7 @@ extern "C" { + /** No response parameters*/ + + #define SHCI_OPCODE_C2_CONFIG (( SHCI_OGF << 10) + SHCI_OCF_C2_CONFIG) ++ + /** Command parameters */ + typedef PACKED_STRUCT{ + uint8_t PayloadCmdSize; +@@ -843,6 +845,15 @@ extern "C" { + + #define SHCI_OPCODE_C2_802_15_4_DEINIT (( SHCI_OGF << 10) + SHCI_OCF_C2_802_15_4_DEINIT) + ++#define SHCI_OPCODE_C2_SET_SYSTEM_CLOCK (( SHCI_OGF << 10) + SHCI_OCF_C2_SET_SYSTEM_CLOCK) ++ /** Command parameters */ ++ typedef enum ++ { ++ SET_SYSTEM_CLOCK_HSE_TO_PLL, ++ SET_SYSTEM_CLOCK_PLL_ON_TO_HSE, ++ SET_SYSTEM_CLOCK_PLL_OFF_TO_HSE, ++ }SHCI_C2_SET_SYSTEM_CLOCK_Cmd_Param_t; ++ + /** + * PayloadCmdSize + * Value that shall be used +@@ -859,8 +870,8 @@ extern "C" { + /** + * Device ID + */ +-#define SHCI_C2_CONFIG_STM32WB55xx (0x495) +-#define SHCI_C2_CONFIG_STM32WB15xx (0x494) ++#define SHCI_C2_CONFIG_STM32WB55xx (0x495) ++#define SHCI_C2_CONFIG_STM32WB15xx (0x494) + + /** + * Config1 +@@ -878,7 +889,7 @@ extern "C" { + */ + #define SHCI_C2_CONFIG_EVTMASK1_BIT0_ERROR_NOTIF_ENABLE (1<<0) + #define SHCI_C2_CONFIG_EVTMASK1_BIT1_BLE_NVM_RAM_UPDATE_ENABLE (1<<1) +-#define SHCI_C2_CONFIG_EVTMASK1_BIT2_THREAD_NVM_RAM_UPDATE_ENABLE (1<<2) ++#define SHCI_C2_CONFIG_EVTMASK1_BIT2_THREAD_NVM_RAM_UPDATE_ENABLE (1<<2) + #define SHCI_C2_CONFIG_EVTMASK1_BIT3_NVM_START_WRITE_ENABLE (1<<3) + #define SHCI_C2_CONFIG_EVTMASK1_BIT4_NVM_END_WRITE_ENABLE (1<<4) + #define SHCI_C2_CONFIG_EVTMASK1_BIT5_NVM_START_ERASE_ENABLE (1<<5) +@@ -965,7 +976,8 @@ extern "C" { + #define INFO_STACK_TYPE_ZIGBEE_RFD 0x31 + #define INFO_STACK_TYPE_MAC 0x40 + #define INFO_STACK_TYPE_BLE_THREAD_FTD_STATIC 0x50 +-#define INFO_STACK_TYPE_BLE_THREAD_FTD_DYAMIC 0x51 ++#define INFO_STACK_TYPE_BLE_THREAD_FTD_DYNAMIC 0x51 ++#define INFO_STACK_TYPE_BLE_THREAD_LIGHT_DYNAMIC 0x52 + #define INFO_STACK_TYPE_802154_LLD_TESTS 0x60 + #define INFO_STACK_TYPE_802154_PHY_VALID 0x61 + #define INFO_STACK_TYPE_BLE_PHY_VALID 0x62 +@@ -1364,9 +1376,24 @@ typedef struct { + */ + SHCI_CmdStatus_t SHCI_C2_802_15_4_DeInit( void ); + +- #ifdef __cplusplus ++ /** ++ * SHCI_C2_SetSystemClock ++ * @brief Request CPU2 to change system clock ++ * ++ * @param clockSel: It can be one of the following list ++ * - SET_SYSTEM_CLOCK_HSE_TO_PLL : CPU2 set system clock to PLL, PLL must be configured and started before. ++ * - SET_SYSTEM_CLOCK_PLL_ON_TO_HSE : CPU2 set System clock to HSE, PLL is still ON after command execution. ++ * - SET_SYSTEM_CLOCK_PLL_OFF_TO_HSE : CPU2 set System clock to HSE, PLL is turned OFF after command execution. ++ * ++ * @retval Status ++ */ ++ SHCI_CmdStatus_t SHCI_C2_SetSystemClock( SHCI_C2_SET_SYSTEM_CLOCK_Cmd_Param_t clockSel ); ++ ++ ++#ifdef __cplusplus + } + #endif + + #endif /*__SHCI_H */ + ++/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/src/utility/HCISharedMemTransport.cpp b/src/utility/HCISharedMemTransport.cpp index 0db95041..8ced5f67 100644 --- a/src/utility/HCISharedMemTransport.cpp +++ b/src/utility/HCISharedMemTransport.cpp @@ -19,7 +19,7 @@ #if defined(STM32WBxx) #include "HCISharedMemTransport.h" -#include "STM32Cube_FW/hw.h" +#include "STM32_WPAN/hw.h" #include "otp.h" /* Private variables ---------------------------------------------------------*/ diff --git a/src/utility/HCISharedMemTransport.h b/src/utility/HCISharedMemTransport.h index 58fb871d..e739d63f 100644 --- a/src/utility/HCISharedMemTransport.h +++ b/src/utility/HCISharedMemTransport.h @@ -26,10 +26,10 @@ #include "stm32wbxx_ll_rcc.h" #include "stm32wbxx_ll_ipcc.h" #include "stm32wbxx_ll_system.h" -#include "STM32Cube_FW/tl.h" -#include "STM32Cube_FW/shci.h" -#include "STM32Cube_FW/shci_tl.h" -#include "STM32Cube_FW/app_conf.h" +#include "STM32_WPAN/tl.h" +#include "STM32_WPAN/shci.h" +#include "STM32_WPAN/shci_tl.h" +#include "STM32_WPAN/app_conf.h" /* this one is for printing info content when HW serial enabled */ //#define PRINT_IPCC_INFO diff --git a/src/utility/STM32Cube_FW/LICENSE.md b/src/utility/STM32_WPAN/LICENSE.md similarity index 100% rename from src/utility/STM32Cube_FW/LICENSE.md rename to src/utility/STM32_WPAN/LICENSE.md diff --git a/src/utility/STM32Cube_FW/README.md b/src/utility/STM32_WPAN/README.md similarity index 100% rename from src/utility/STM32Cube_FW/README.md rename to src/utility/STM32_WPAN/README.md diff --git a/src/utility/STM32Cube_FW/app_conf.h b/src/utility/STM32_WPAN/app_conf.h similarity index 100% rename from src/utility/STM32Cube_FW/app_conf.h rename to src/utility/STM32_WPAN/app_conf.h diff --git a/src/utility/STM32Cube_FW/app_conf_default.h b/src/utility/STM32_WPAN/app_conf_default.h similarity index 100% rename from src/utility/STM32Cube_FW/app_conf_default.h rename to src/utility/STM32_WPAN/app_conf_default.h diff --git a/src/utility/STM32Cube_FW/ble_bufsize.h b/src/utility/STM32_WPAN/ble_bufsize.h similarity index 100% rename from src/utility/STM32Cube_FW/ble_bufsize.h rename to src/utility/STM32_WPAN/ble_bufsize.h diff --git a/src/utility/STM32Cube_FW/hw.h b/src/utility/STM32_WPAN/hw.h similarity index 100% rename from src/utility/STM32Cube_FW/hw.h rename to src/utility/STM32_WPAN/hw.h diff --git a/src/utility/STM32Cube_FW/hw_ipcc.c b/src/utility/STM32_WPAN/hw_ipcc.c similarity index 100% rename from src/utility/STM32Cube_FW/hw_ipcc.c rename to src/utility/STM32_WPAN/hw_ipcc.c diff --git a/src/utility/STM32Cube_FW/mbox_def.h b/src/utility/STM32_WPAN/mbox_def.h similarity index 100% rename from src/utility/STM32Cube_FW/mbox_def.h rename to src/utility/STM32_WPAN/mbox_def.h diff --git a/src/utility/STM32Cube_FW/shci.c b/src/utility/STM32_WPAN/shci.c similarity index 100% rename from src/utility/STM32Cube_FW/shci.c rename to src/utility/STM32_WPAN/shci.c diff --git a/src/utility/STM32Cube_FW/shci.h b/src/utility/STM32_WPAN/shci.h similarity index 100% rename from src/utility/STM32Cube_FW/shci.h rename to src/utility/STM32_WPAN/shci.h diff --git a/src/utility/STM32Cube_FW/shci_tl.c b/src/utility/STM32_WPAN/shci_tl.c similarity index 100% rename from src/utility/STM32Cube_FW/shci_tl.c rename to src/utility/STM32_WPAN/shci_tl.c diff --git a/src/utility/STM32Cube_FW/shci_tl.h b/src/utility/STM32_WPAN/shci_tl.h similarity index 100% rename from src/utility/STM32Cube_FW/shci_tl.h rename to src/utility/STM32_WPAN/shci_tl.h diff --git a/src/utility/STM32Cube_FW/stm32_wpan_common.h b/src/utility/STM32_WPAN/stm32_wpan_common.h similarity index 100% rename from src/utility/STM32Cube_FW/stm32_wpan_common.h rename to src/utility/STM32_WPAN/stm32_wpan_common.h diff --git a/src/utility/STM32Cube_FW/stm_list.c b/src/utility/STM32_WPAN/stm_list.c similarity index 100% rename from src/utility/STM32Cube_FW/stm_list.c rename to src/utility/STM32_WPAN/stm_list.c diff --git a/src/utility/STM32Cube_FW/stm_list.h b/src/utility/STM32_WPAN/stm_list.h similarity index 100% rename from src/utility/STM32Cube_FW/stm_list.h rename to src/utility/STM32_WPAN/stm_list.h diff --git a/src/utility/STM32Cube_FW/tl.h b/src/utility/STM32_WPAN/tl.h similarity index 100% rename from src/utility/STM32Cube_FW/tl.h rename to src/utility/STM32_WPAN/tl.h diff --git a/src/utility/STM32Cube_FW/tl_dbg_conf.h b/src/utility/STM32_WPAN/tl_dbg_conf.h similarity index 100% rename from src/utility/STM32Cube_FW/tl_dbg_conf.h rename to src/utility/STM32_WPAN/tl_dbg_conf.h diff --git a/src/utility/STM32Cube_FW/tl_mbox.c b/src/utility/STM32_WPAN/tl_mbox.c similarity index 100% rename from src/utility/STM32Cube_FW/tl_mbox.c rename to src/utility/STM32_WPAN/tl_mbox.c From 04bfd7950999ce9b9b916e9518a8603be2752e62 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Wed, 10 Jan 2024 19:00:59 +0100 Subject: [PATCH 146/226] chore: update STM32_WPAN from Cube version v1.18.0 Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- src/utility/STM32_WPAN/README.md | 4 +- src/utility/STM32_WPAN/app_conf_default.h | 153 ++++++---------------- src/utility/STM32_WPAN/ble_bufsize.h | 7 - src/utility/STM32_WPAN/hw.h | 13 +- src/utility/STM32_WPAN/hw_ipcc.c | 5 +- src/utility/STM32_WPAN/shci.c | 23 +++- src/utility/STM32_WPAN/shci.h | 59 ++++++--- src/utility/STM32_WPAN/shci_tl.c | 28 +--- src/utility/STM32_WPAN/stm_list.c | 7 +- src/utility/STM32_WPAN/tl.h | 2 +- src/utility/STM32_WPAN/tl_mbox.c | 7 +- 11 files changed, 119 insertions(+), 189 deletions(-) diff --git a/src/utility/STM32_WPAN/README.md b/src/utility/STM32_WPAN/README.md index 0d39a3ef..97c4ceba 100644 --- a/src/utility/STM32_WPAN/README.md +++ b/src/utility/STM32_WPAN/README.md @@ -1,6 +1,6 @@ ## Source -[STMicroelectronics/STM32CubeWB Release v1.17.0](https://github.com/STMicroelectronics/STM32CubeWB/releases/tag/v1.17.0) -- Application: [BLE_TransparentMode](https://github.com/STMicroelectronics/STM32CubeWB/tree/v1.17.0/Projects/P-NUCLEO-WB55.Nucleo/Applications/BLE/BLE_TransparentMode) +[STMicroelectronics/STM32CubeWB Release v1.18.0](https://github.com/STMicroelectronics/STM32CubeWB/releases/tag/v1.18.0) +- Application: [BLE_TransparentMode](https://github.com/STMicroelectronics/STM32CubeWB/tree/v1.18.0/Projects/P-NUCLEO-WB55.Nucleo/Applications/BLE/BLE_TransparentMode) diff --git a/src/utility/STM32_WPAN/app_conf_default.h b/src/utility/STM32_WPAN/app_conf_default.h index d39492ea..846be3c9 100644 --- a/src/utility/STM32_WPAN/app_conf_default.h +++ b/src/utility/STM32_WPAN/app_conf_default.h @@ -1,9 +1,9 @@ /* USER CODE BEGIN Header */ /** ****************************************************************************** - * @file app_conf_default.h + * @file app_conf.h * @author MCD Application Team - * @brief Default application configuration file for STM32WPAN Middleware. + * @brief Application configuration file for STM32WPAN Middleware. ****************************************************************************** * @attention * @@ -19,40 +19,18 @@ /* USER CODE END Header */ /* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef APP_CONF_DEFAULT_H -#define APP_CONF_DEFAULT_H -#if 0 +#ifndef APP_CONF_H +#define APP_CONF_H + #include "hw.h" #include "hw_conf.h" #include "hw_if.h" #include "ble_bufsize.h" -#endif + /****************************************************************************** * Application Config ******************************************************************************/ -/**< generic parameters ******************************************************/ -/* HCI related defines */ - -#define ACI_HAL_SET_TX_POWER_LEVEL 0xFC0F -#define ACI_WRITE_CONFIG_DATA_OPCODE 0xFC0C -#define ACI_READ_CONFIG_DATA_OPCODE 0xFC0D -#define MAX_HCI_ACL_PACKET_SIZE (sizeof(TL_PacketHeader_t) + 5 + 251) -#define HCI_RESET 0x0C03 - -#ifndef BLE_SHARED_MEM_BYTE_ORDER - #define BLE_SHARED_MEM_BYTE_ORDER MSBFIRST -#endif -#define BLE_MODULE_SHARED_MEM_BUFFER_SIZE 128 - -/** - * Define Tx Power - */ -#ifndef CFG_TX_POWER - #define CFG_TX_POWER (0x18) /* -0.15dBm */ -#endif - -#if 0 /** * Define Secure Connections Support */ @@ -83,14 +61,14 @@ #define CFG_GAP_DEVICE_NAME_LENGTH (8) /** -* Identity root key used to derive LTK and CSRK +* Identity root key used to derive IRK and DHK(Legacy) */ -#define CFG_BLE_IRK {0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0} +#define CFG_BLE_IR {0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0} /** -* Encryption root key used to derive LTK and CSRK +* Encryption root key used to derive LTK(Legacy) and CSRK */ -#define CFG_BLE_ERK {0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21, 0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21} +#define CFG_BLE_ER {0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21, 0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21} /** * SMPS supply @@ -126,7 +104,7 @@ #define CFG_FW_SUBVERSION (1) #define CFG_FW_BRANCH (0) #define CFG_FW_BUILD (0) -#endif + /****************************************************************************** * BLE Stack ******************************************************************************/ @@ -134,25 +112,13 @@ * Maximum number of simultaneous connections that the device will support. * Valid values are from 1 to 8 */ -#ifndef CFG_BLE_NUM_LINK -#ifdef STM32WB15xx - #define CFG_BLE_NUM_LINK 3 -#else - #define CFG_BLE_NUM_LINK 8 -#endif -#endif +#define CFG_BLE_NUM_LINK 8 /** * Maximum number of Services that can be stored in the GATT database. * Note that the GAP and GATT services are automatically added so this parameter should be 2 plus the number of user services */ -#ifndef CFG_BLE_NUM_GATT_SERVICES -#ifdef STM32WB15xx - #define CFG_BLE_NUM_GATT_SERVICES 4 -#else - #define CFG_BLE_NUM_GATT_SERVICES 8 -#endif -#endif +#define CFG_BLE_NUM_GATT_SERVICES 8 /** * Maximum number of Attributes @@ -161,21 +127,13 @@ * Note that certain characteristics and relative descriptors are added automatically during device initialization * so this parameters should be 9 plus the number of user Attributes */ -#ifndef CFG_BLE_NUM_GATT_ATTRIBUTES -#ifdef STM32WB15xx - #define CFG_BLE_NUM_GATT_ATTRIBUTES 30 -#else - #define CFG_BLE_NUM_GATT_ATTRIBUTES 68 -#endif -#endif +#define CFG_BLE_NUM_GATT_ATTRIBUTES 68 /** * Maximum supported ATT_MTU size * This parameter is ignored by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set */ -#ifndef CFG_BLE_MAX_ATT_MTU - #define CFG_BLE_MAX_ATT_MTU (156) -#endif +#define CFG_BLE_MAX_ATT_MTU (156) /** * Size of the storage area for Attribute values @@ -188,46 +146,32 @@ * The total amount of memory needed is the sum of the above quantities for each attribute. * This parameter is ignored by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set */ -#ifndef CFG_BLE_ATT_VALUE_ARRAY_SIZE -#ifdef STM32WB15xx - #define CFG_BLE_ATT_VALUE_ARRAY_SIZE (1290) -#else - #define CFG_BLE_ATT_VALUE_ARRAY_SIZE (1344) -#endif -#endif +#define CFG_BLE_ATT_VALUE_ARRAY_SIZE (1344) /** * Prepare Write List size in terms of number of packet * This parameter is ignored by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set */ -// #define CFG_BLE_PREPARE_WRITE_LIST_SIZE BLE_PREP_WRITE_X_ATT(CFG_BLE_MAX_ATT_MTU) -#ifndef CFG_BLE_PREPARE_WRITE_LIST_SIZE - #define CFG_BLE_PREPARE_WRITE_LIST_SIZE (0x3A) -#endif +#define CFG_BLE_PREPARE_WRITE_LIST_SIZE BLE_PREP_WRITE_X_ATT(CFG_BLE_MAX_ATT_MTU) /** * Number of allocated memory blocks * This parameter is overwritten by the CPU2 with an hardcoded optimal value when the parameter CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set */ -//#define CFG_BLE_MBLOCK_COUNT (BLE_MBLOCKS_CALC(CFG_BLE_PREPARE_WRITE_LIST_SIZE, CFG_BLE_MAX_ATT_MTU, CFG_BLE_NUM_LINK)) -#define CFG_BLE_MBLOCK_COUNT (0x79) +#define CFG_BLE_MBLOCK_COUNT (BLE_MBLOCKS_CALC(CFG_BLE_PREPARE_WRITE_LIST_SIZE, CFG_BLE_MAX_ATT_MTU, CFG_BLE_NUM_LINK)) /** * Enable or disable the Extended Packet length feature. Valid values are 0 or 1. */ -#ifndef CFG_BLE_DATA_LENGTH_EXTENSION - #define CFG_BLE_DATA_LENGTH_EXTENSION 1 -#endif +#define CFG_BLE_DATA_LENGTH_EXTENSION 1 /** - * Sleep clock accuracy in Slave mode (ppm value) + * Sleep clock accuracy in Peripheral mode (ppm value) */ -#ifndef CFG_BLE_SLAVE_SCA - #define CFG_BLE_SLAVE_SCA 500 -#endif +#define CFG_BLE_PERIPHERAL_SCA 500 /** - * Sleep clock accuracy in Master mode + * Sleep clock accuracy in Central mode * 0 : 251 ppm to 500 ppm * 1 : 151 ppm to 250 ppm * 2 : 101 ppm to 150 ppm @@ -237,9 +181,7 @@ * 6 : 21 ppm to 30 ppm * 7 : 0 ppm to 20 ppm */ -#ifndef CFG_BLE_MASTER_SCA - #define CFG_BLE_MASTER_SCA 0 -#endif +#define CFG_BLE_CENTRAL_SCA 0 /** * LsSource @@ -248,27 +190,21 @@ * - bit 1: 1: STM32WB5M Module device 0: Other devices as STM32WBxx SOC, STM32WB1M module * - bit 2: 1: HSE/1024 Clock config 0: LSE Clock config */ -#ifndef CFG_BLE_LS_SOURCE - #if defined(STM32WB5Mxx) - #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_MOD5MM_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) - #else - #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_OTHER_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) - #endif +#if defined(STM32WB5Mxx) + #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_MOD5MM_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) +#else + #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_OTHER_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) #endif /** * Start up time of the high speed (16 or 32 MHz) crystal oscillator in units of 625/256 us (~2.44 us) */ -#ifndef CFG_BLE_HSE_STARTUP_TIME - #define CFG_BLE_HSE_STARTUP_TIME 0x148 -#endif +#define CFG_BLE_HSE_STARTUP_TIME 0x148 /** - * Maximum duration of the connection event when the device is in Slave mode in units of 625/256 us (~2.44 us) + * Maximum duration of the connection event when the device is in Peripheral mode in units of 625/256 us (~2.44 us) */ -#ifndef CFG_BLE_MAX_CONN_EVENT_LENGTH - #define CFG_BLE_MAX_CONN_EVENT_LENGTH (0xFFFFFFFF) -#endif +#define CFG_BLE_MAX_CONN_EVENT_LENGTH (0xFFFFFFFF) /** * Viterbi Mode @@ -314,7 +250,7 @@ * 0: LE Power Class 2-3 * other bits: complete with Options_extension flag */ -#define CFG_BLE_OPTIONS (SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY) +#define CFG_BLE_OPTIONS (SHCI_C2_BLE_INIT_OPTIONS_LL_HOST | SHCI_C2_BLE_INIT_OPTIONS_WITH_SVC_CHANGE_DESC | SHCI_C2_BLE_INIT_OPTIONS_DEVICE_NAME_RW | SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV | SHCI_C2_BLE_INIT_OPTIONS_CS_ALGO2 | SHCI_C2_BLE_INIT_OPTIONS_FULL_GATTDB_NVM | SHCI_C2_BLE_INIT_OPTIONS_GATT_CACHING_NOTUSED | SHCI_C2_BLE_INIT_OPTIONS_POWER_CLASS_2_3) /** * BLE stack Options_extension flags to be configured with: @@ -356,11 +292,7 @@ * This parameter is considered by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV flag set */ -#if defined(STM32WB15xx) - #define CFG_BLE_MAX_ADV_SET_NBR (3) -#else - #define CFG_BLE_MAX_ADV_SET_NBR (8) -#endif +#define CFG_BLE_MAX_ADV_SET_NBR (8) /* Maximum advertising data length (in bytes) * Range: 31 .. 1650 with limitation: @@ -369,11 +301,7 @@ * This parameter is considered by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV flag set */ -#if defined(STM32WB15xx) - #define CFG_BLE_MAX_ADV_DATA_LEN (414) -#else - #define CFG_BLE_MAX_ADV_DATA_LEN (207) -#endif +#define CFG_BLE_MAX_ADV_DATA_LEN (207) /* RF TX Path Compensation Value (16-bit signed integer). Units: 0.1 dB. * Range: -1280 .. 1280 @@ -390,12 +318,12 @@ /* BLE core version (16-bit signed integer). * - SHCI_C2_BLE_INIT_BLE_CORE_5_2 * - SHCI_C2_BLE_INIT_BLE_CORE_5_3 - * which are used to set: 11(5.2), 12(5.3). + * - SHCI_C2_BLE_INIT_BLE_CORE_5_4 + * which are used to set: 11(5.2), 12(5.3), 13(5.4). */ -#define CFG_BLE_CORE_VERSION (SHCI_C2_BLE_INIT_BLE_CORE_5_3) +#define CFG_BLE_CORE_VERSION (SHCI_C2_BLE_INIT_BLE_CORE_5_4) -#if 0 /****************************************************************************** * Transport Layer ******************************************************************************/ @@ -559,13 +487,13 @@ typedef enum * Debug ******************************************************************************/ /** - * When set, this resets some hw resources to set the device in the same state than the power up - * The FW resets only register that may prevent the FW to run properly + * When set, this resets some hw resources to put the device in the same state as at power up. + * It resets only register that may prevent the FW to run properly. * * This shall be set to 0 in a final product * */ -#define CFG_HW_RESET_BY_FW 1 +#define CFG_HW_RESET_BY_FW 0 /** * keep debugger enabled while in any low power mode when set to 1 @@ -731,5 +659,4 @@ typedef enum #define CFG_OTP_END_ADRESS OTP_AREA_END_ADDR -#endif -#endif /*APP_CONF_DEFAULT_H */ +#endif /*APP_CONF_H */ diff --git a/src/utility/STM32_WPAN/ble_bufsize.h b/src/utility/STM32_WPAN/ble_bufsize.h index d4d28907..b9935c0b 100644 --- a/src/utility/STM32_WPAN/ble_bufsize.h +++ b/src/utility/STM32_WPAN/ble_bufsize.h @@ -75,13 +75,6 @@ ((pw) + MAX(BLE_MEM_BLOCK_X_MTU(mtu, n_link), \ BLE_MBLOCKS_SECURE_CONNECTIONS)) -/* - * BLE_DEFAULT_MBLOCKS_COUNT: default memory blocks count - */ -#define BLE_DEFAULT_MBLOCKS_COUNT(n_link) \ - BLE_MBLOCKS_CALC(BLE_DEFAULT_PREP_WRITE_LIST_SIZE, \ - BLE_DEFAULT_MAX_ATT_MTU, n_link) - /* * BLE_FIXED_BUFFER_SIZE_BYTES: * A part of the RAM, is dynamically allocated by initializing all the pointers diff --git a/src/utility/STM32_WPAN/hw.h b/src/utility/STM32_WPAN/hw.h index 1472a5e8..651e1f17 100644 --- a/src/utility/STM32_WPAN/hw.h +++ b/src/utility/STM32_WPAN/hw.h @@ -26,23 +26,14 @@ extern "C" { #endif /* Includes ------------------------------------------------------------------*/ -#include "stm32_def.h" -#include "stm32wbxx_ll_bus.h" -#include "stm32wbxx_ll_exti.h" -#include "stm32wbxx_ll_system.h" -#include "stm32wbxx_ll_rcc.h" -#include "stm32wbxx_ll_ipcc.h" -#include "stm32wbxx_ll_cortex.h" -#include "stm32wbxx_ll_utils.h" -#include "stm32wbxx_ll_pwr.h" /****************************************************************************** * HW IPCC ******************************************************************************/ void HW_IPCC_Enable( void ); void HW_IPCC_Init( void ); -#define HW_IPCC_Rx_Handler IPCC_C1_RX_IRQHandler -#define HW_IPCC_Tx_Handler IPCC_C1_TX_IRQHandler + void HW_IPCC_Rx_Handler( void ); + void HW_IPCC_Tx_Handler( void ); void HW_IPCC_BLE_Init( void ); void HW_IPCC_BLE_SendCmd( void ); diff --git a/src/utility/STM32_WPAN/hw_ipcc.c b/src/utility/STM32_WPAN/hw_ipcc.c index c7304823..fd620b85 100644 --- a/src/utility/STM32_WPAN/hw_ipcc.c +++ b/src/utility/STM32_WPAN/hw_ipcc.c @@ -17,9 +17,9 @@ ****************************************************************************** */ /* USER CODE END Header */ -#if defined(STM32WBxx) + /* Includes ------------------------------------------------------------------*/ -#include "hw.h" +#include "app_common.h" #include "mbox_def.h" /* Global variables ---------------------------------------------------------*/ @@ -667,4 +667,3 @@ static void HW_IPCC_TRACES_EvtHandler( void ) } __weak void HW_IPCC_TRACES_EvtNot( void ){}; -#endif /* STM32WBxx */ diff --git a/src/utility/STM32_WPAN/shci.c b/src/utility/STM32_WPAN/shci.c index 4525656e..5c32555e 100644 --- a/src/utility/STM32_WPAN/shci.c +++ b/src/utility/STM32_WPAN/shci.c @@ -16,7 +16,7 @@ ****************************************************************************** */ -#if defined(STM32WBxx) + /* Includes ------------------------------------------------------------------*/ #include "stm32_wpan_common.h" @@ -644,6 +644,26 @@ SHCI_CmdStatus_t SHCI_C2_802_15_4_DeInit( void ) return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); } +SHCI_CmdStatus_t SHCI_C2_SetSystemClock( SHCI_C2_SET_SYSTEM_CLOCK_Cmd_Param_t clockSel ) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + local_buffer[0] = (uint8_t)clockSel; + + shci_send( SHCI_OPCODE_C2_SET_SYSTEM_CLOCK, + 1, + local_buffer, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + /** * Local System COMMAND * These commands are NOT sent to the CPU2 @@ -739,4 +759,3 @@ SHCI_CmdStatus_t SHCI_GetWirelessFwInfo( WirelessFwInfo_t* pWirelessInfo ) return (SHCI_Success); } -#endif /* STM32WBxx */ diff --git a/src/utility/STM32_WPAN/shci.h b/src/utility/STM32_WPAN/shci.h index 750fa972..30ae10cb 100644 --- a/src/utility/STM32_WPAN/shci.h +++ b/src/utility/STM32_WPAN/shci.h @@ -227,6 +227,7 @@ extern "C" { SHCI_OCF_C2_CONCURRENT_GET_NEXT_BLE_EVT_TIME, SHCI_OCF_C2_CONCURRENT_ENABLE_NEXT_802154_EVT_NOTIFICATION, SHCI_OCF_C2_802_15_4_DEINIT, + SHCI_OCF_C2_SET_SYSTEM_CLOCK, } SHCI_OCF_t; #define SHCI_OPCODE_C2_FUS_GET_STATE (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_GET_STATE) @@ -436,7 +437,7 @@ extern "C" { * PrWriteListSize * NOTE: This parameter is ignored by the CPU2 when the parameter "Options" is set to "LL_only" ( see Options description in that structure ) * - * Maximum number of supported �prepare write request� + * Maximum number of supported "prepare write request" * - Min value: given by the macro DEFAULT_PREP_WRITE_LIST_SIZE * - Max value: a value higher than the minimum required can be specified, but it is not recommended */ @@ -464,20 +465,20 @@ extern "C" { uint16_t AttMtu; /** - * SlaveSca - * The sleep clock accuracy (ppm value) that used in BLE connected slave mode to calculate the window widening + * PeripheralSca + * The sleep clock accuracy (ppm value) that used in BLE connected Peripheral mode to calculate the window widening * (in combination with the sleep clock accuracy sent by master in CONNECT_REQ PDU), * refer to BLE 5.0 specifications - Vol 6 - Part B - chap 4.5.7 and 4.2.2 * - Min value: 0 * - Max value: 500 (worst possible admitted by specification) */ - uint16_t SlaveSca; + uint16_t PeripheralSca; /** - * MasterSca - * The sleep clock accuracy handled in master mode. It is used to determine the connection and advertising events timing. + * CentralSca + * The sleep clock accuracy handled in Central mode. It is used to determine the connection and advertising events timing. * It is transmitted to the slave in CONNEC_REQ PDU used by the slave to calculate the window widening, - * see SlaveSca and Bluetooth Core Specification v5.0 Vol 6 - Part B - chap 4.5.7 and 4.2.2 + * see PeripheralSca and Bluetooth Core Specification v5.0 Vol 6 - Part B - chap 4.5.7 and 4.2.2 * Possible values: * - 251 ppm to 500 ppm: 0 * - 151 ppm to 250 ppm: 1 @@ -488,7 +489,7 @@ extern "C" { * - 21 ppm to 30 ppm: 6 * - 0 ppm to 20 ppm: 7 */ - uint8_t MasterSca; + uint8_t CentralSca; /** * LsSource @@ -503,7 +504,7 @@ extern "C" { * MaxConnEventLength * This parameter determines the maximum duration of a slave connection event. When this duration is reached the slave closes * the current connections event (whatever is the CE_length parameter specified by the master in HCI_CREATE_CONNECTION HCI command), - * expressed in units of 625/256 �s (~2.44 �s) + * expressed in units of 625/256 us (~2.44 us) * - Min value: 0 (if 0 is specified, the master and slave perform only a single TX-RX exchange per connection event) * - Max value: 1638400 (4000 ms). A higher value can be specified (max 0xFFFFFFFF) but results in a maximum connection time * of 4000 ms as specified. In this case the parameter is not applied, and the predicted CE length calculated on slave is not shortened @@ -512,7 +513,7 @@ extern "C" { /** * HsStartupTime - * Startup time of the high speed (16 or 32 MHz) crystal oscillator in units of 625/256 �s (~2.44 �s). + * Startup time of the high speed (16 or 32 MHz) crystal oscillator in units of 625/256 us (~2.44 us). * - Min value: 0 * - Max value: 820 (~2 ms). A higher value can be specified, but the value that implemented in stack is forced to ~2 ms */ @@ -598,7 +599,7 @@ extern "C" { int16_t rx_path_compens; /* BLE core specification version (8-bit unsigned integer). - * values as: 11(5.2), 12(5.3) + * values as: 11(5.2), 12(5.3), 13(5.4) */ uint8_t ble_core_version; @@ -829,6 +830,7 @@ extern "C" { /** No response parameters*/ #define SHCI_OPCODE_C2_CONFIG (( SHCI_OGF << 10) + SHCI_OCF_C2_CONFIG) + /** Command parameters */ typedef PACKED_STRUCT{ uint8_t PayloadCmdSize; @@ -843,6 +845,15 @@ extern "C" { #define SHCI_OPCODE_C2_802_15_4_DEINIT (( SHCI_OGF << 10) + SHCI_OCF_C2_802_15_4_DEINIT) +#define SHCI_OPCODE_C2_SET_SYSTEM_CLOCK (( SHCI_OGF << 10) + SHCI_OCF_C2_SET_SYSTEM_CLOCK) + /** Command parameters */ + typedef enum + { + SET_SYSTEM_CLOCK_HSE_TO_PLL, + SET_SYSTEM_CLOCK_PLL_ON_TO_HSE, + SET_SYSTEM_CLOCK_PLL_OFF_TO_HSE, + }SHCI_C2_SET_SYSTEM_CLOCK_Cmd_Param_t; + /** * PayloadCmdSize * Value that shall be used @@ -859,8 +870,8 @@ extern "C" { /** * Device ID */ -#define SHCI_C2_CONFIG_STM32WB55xx (0x495) -#define SHCI_C2_CONFIG_STM32WB15xx (0x494) +#define SHCI_C2_CONFIG_STM32WB55xx (0x495) +#define SHCI_C2_CONFIG_STM32WB15xx (0x494) /** * Config1 @@ -878,7 +889,7 @@ extern "C" { */ #define SHCI_C2_CONFIG_EVTMASK1_BIT0_ERROR_NOTIF_ENABLE (1<<0) #define SHCI_C2_CONFIG_EVTMASK1_BIT1_BLE_NVM_RAM_UPDATE_ENABLE (1<<1) -#define SHCI_C2_CONFIG_EVTMASK1_BIT2_THREAD_NVM_RAM_UPDATE_ENABLE (1<<2) +#define SHCI_C2_CONFIG_EVTMASK1_BIT2_THREAD_NVM_RAM_UPDATE_ENABLE (1<<2) #define SHCI_C2_CONFIG_EVTMASK1_BIT3_NVM_START_WRITE_ENABLE (1<<3) #define SHCI_C2_CONFIG_EVTMASK1_BIT4_NVM_END_WRITE_ENABLE (1<<4) #define SHCI_C2_CONFIG_EVTMASK1_BIT5_NVM_START_ERASE_ENABLE (1<<5) @@ -965,7 +976,8 @@ extern "C" { #define INFO_STACK_TYPE_ZIGBEE_RFD 0x31 #define INFO_STACK_TYPE_MAC 0x40 #define INFO_STACK_TYPE_BLE_THREAD_FTD_STATIC 0x50 -#define INFO_STACK_TYPE_BLE_THREAD_FTD_DYAMIC 0x51 +#define INFO_STACK_TYPE_BLE_THREAD_FTD_DYNAMIC 0x51 +#define INFO_STACK_TYPE_BLE_THREAD_LIGHT_DYNAMIC 0x52 #define INFO_STACK_TYPE_802154_LLD_TESTS 0x60 #define INFO_STACK_TYPE_802154_PHY_VALID 0x61 #define INFO_STACK_TYPE_BLE_PHY_VALID 0x62 @@ -1364,9 +1376,24 @@ typedef struct { */ SHCI_CmdStatus_t SHCI_C2_802_15_4_DeInit( void ); - #ifdef __cplusplus + /** + * SHCI_C2_SetSystemClock + * @brief Request CPU2 to change system clock + * + * @param clockSel: It can be one of the following list + * - SET_SYSTEM_CLOCK_HSE_TO_PLL : CPU2 set system clock to PLL, PLL must be configured and started before. + * - SET_SYSTEM_CLOCK_PLL_ON_TO_HSE : CPU2 set System clock to HSE, PLL is still ON after command execution. + * - SET_SYSTEM_CLOCK_PLL_OFF_TO_HSE : CPU2 set System clock to HSE, PLL is turned OFF after command execution. + * + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_SetSystemClock( SHCI_C2_SET_SYSTEM_CLOCK_Cmd_Param_t clockSel ); + + +#ifdef __cplusplus } #endif #endif /*__SHCI_H */ +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/src/utility/STM32_WPAN/shci_tl.c b/src/utility/STM32_WPAN/shci_tl.c index 60380251..0f604300 100644 --- a/src/utility/STM32_WPAN/shci_tl.c +++ b/src/utility/STM32_WPAN/shci_tl.c @@ -16,14 +16,12 @@ ****************************************************************************** */ -#if defined(STM32WBxx) + /* Includes ------------------------------------------------------------------*/ #include "stm32_wpan_common.h" #include "stm_list.h" #include "shci_tl.h" -#include "stm32_def.h" -#include "wiring_time.h" /* Private typedef -----------------------------------------------------------*/ typedef enum @@ -170,20 +168,6 @@ void shci_send( uint16_t cmd_code, uint8_t len_cmd_payload, uint8_t * p_cmd_payl return; } -void shci_notify_asynch_evt(void *pdata) -{ - UNUSED(pdata); - /* Need to parse data in future version */ - shci_user_evt_proc(); -} - -void shci_register_io_bus(tSHciIO *fops) -{ - /* Register IO bus services */ - fops->Init = TL_SYS_Init; - fops->Send = TL_SYS_SendCmd; -} - /* Private functions ---------------------------------------------------------*/ static void TlInit( TL_CmdPacket_t * p_cmdbuffer ) { @@ -251,11 +235,10 @@ static void TlUserEvtReceived(TL_EvtPacket_t *shcievt) /* Weak implementation ----------------------------------------------------------------*/ __WEAK void shci_cmd_resp_wait(uint32_t timeout) { - for (unsigned long start = millis(); (millis() - start) < timeout;) { - if (CmdRspStatusFlag == SHCI_TL_CMD_RESP_RELEASE) { - break; - } - } + (void)timeout; + + while(CmdRspStatusFlag != SHCI_TL_CMD_RESP_RELEASE); + return; } @@ -267,4 +250,3 @@ __WEAK void shci_cmd_resp_release(uint32_t flag) return; } -#endif /* STM32WBxx */ diff --git a/src/utility/STM32_WPAN/stm_list.c b/src/utility/STM32_WPAN/stm_list.c index 4e8c3643..4c928647 100644 --- a/src/utility/STM32_WPAN/stm_list.c +++ b/src/utility/STM32_WPAN/stm_list.c @@ -16,13 +16,11 @@ ****************************************************************************** */ -#if defined(STM32WBxx) + /****************************************************************************** * Include Files ******************************************************************************/ -#include "stdint.h" -#include "cmsis_gcc.h" -#include "stm32_wpan_common.h" +#include "utilities_common.h" #include "stm_list.h" @@ -206,4 +204,3 @@ void LST_get_prev_node (tListNode * ref_node, tListNode ** node) __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ } -#endif /* STM32WBxx */ diff --git a/src/utility/STM32_WPAN/tl.h b/src/utility/STM32_WPAN/tl.h index 74520878..8e8c6cbc 100644 --- a/src/utility/STM32_WPAN/tl.h +++ b/src/utility/STM32_WPAN/tl.h @@ -108,7 +108,7 @@ typedef PACKED_STRUCT { uint8_t evtcode; uint8_t plen; - uint8_t payload[4]; + uint8_t payload[2]; } TL_Evt_t; typedef PACKED_STRUCT diff --git a/src/utility/STM32_WPAN/tl_mbox.c b/src/utility/STM32_WPAN/tl_mbox.c index 11393162..27a998a3 100644 --- a/src/utility/STM32_WPAN/tl_mbox.c +++ b/src/utility/STM32_WPAN/tl_mbox.c @@ -16,7 +16,6 @@ ****************************************************************************** */ -#if defined(STM32WBxx) /* Includes ------------------------------------------------------------------*/ #include "stm32_wpan_common.h" #include "hw.h" @@ -52,10 +51,9 @@ PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_BleLldTable_t TL_BleLldTable; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_SysTable_t TL_SysTable; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_MemManagerTable_t TL_MemManagerTable; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_TracesTable_t TL_TracesTable; -#if 0 PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_Mac_802_15_4_t TL_Mac_802_15_4_Table; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_ZigbeeTable_t TL_Zigbee_Table; -#endif + /**< tables */ PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode FreeBufQueue; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode TracesEvtQueue; @@ -99,10 +97,8 @@ void TL_Init( void ) TL_RefTable.p_sys_table = &TL_SysTable; TL_RefTable.p_mem_manager_table = &TL_MemManagerTable; TL_RefTable.p_traces_table = &TL_TracesTable; -#if 0 TL_RefTable.p_mac_802_15_4_table = &TL_Mac_802_15_4_Table; TL_RefTable.p_zigbee_table = &TL_Zigbee_Table; -#endif HW_IPCC_Init(); return; @@ -850,4 +846,3 @@ static void OutputDbgTrace(TL_MB_PacketType_t packet_type, uint8_t* buffer) return; } -#endif /* STM32WBxx */ From 56fcc8eb10d304d3fd2711f6fb6a72eba733bf12 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Thu, 11 Jan 2024 11:36:05 +0100 Subject: [PATCH 147/226] chore: update CFG_BLE_*_SCA name Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- src/utility/HCISharedMemTransport.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utility/HCISharedMemTransport.cpp b/src/utility/HCISharedMemTransport.cpp index 8ced5f67..412d0b06 100644 --- a/src/utility/HCISharedMemTransport.cpp +++ b/src/utility/HCISharedMemTransport.cpp @@ -642,8 +642,8 @@ int HCISharedMemTransportClass::stm32wb_start_ble(void) CFG_BLE_PREPARE_WRITE_LIST_SIZE, CFG_BLE_MBLOCK_COUNT, CFG_BLE_MAX_ATT_MTU, - CFG_BLE_SLAVE_SCA, - CFG_BLE_MASTER_SCA, + CFG_BLE_PERIPHERAL_SCA, + CFG_BLE_CENTRAL_SCA, CFG_BLE_LS_SOURCE, CFG_BLE_MAX_CONN_EVENT_LENGTH, CFG_BLE_HSE_STARTUP_TIME, From fb5d4148420e4f0dcc78005be6a7f723e0ea6f09 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Wed, 10 Jan 2024 18:16:01 +0100 Subject: [PATCH 148/226] chore: adapt STM32_WPAN sources Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- src/utility/STM32_WPAN/app_conf_default.h | 49 +++++++++++++++++++---- src/utility/STM32_WPAN/hw.h | 13 +++++- src/utility/STM32_WPAN/hw_ipcc.c | 4 +- src/utility/STM32_WPAN/shci.c | 2 + src/utility/STM32_WPAN/shci_tl.c | 17 ++++++++ src/utility/STM32_WPAN/stm_list.c | 6 ++- src/utility/STM32_WPAN/tl_mbox.c | 6 +++ 7 files changed, 85 insertions(+), 12 deletions(-) diff --git a/src/utility/STM32_WPAN/app_conf_default.h b/src/utility/STM32_WPAN/app_conf_default.h index 846be3c9..6c9beb3b 100644 --- a/src/utility/STM32_WPAN/app_conf_default.h +++ b/src/utility/STM32_WPAN/app_conf_default.h @@ -1,9 +1,9 @@ /* USER CODE BEGIN Header */ /** ****************************************************************************** - * @file app_conf.h + * @file app_conf_default.h * @author MCD Application Team - * @brief Application configuration file for STM32WPAN Middleware. + * @brief Default application configuration file for STM32WPAN Middleware. ****************************************************************************** * @attention * @@ -19,18 +19,40 @@ /* USER CODE END Header */ /* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef APP_CONF_H -#define APP_CONF_H +#ifndef APP_CONF_DEFAULT_H +#define APP_CONF_DEFAULT_H +#if 0 #include "hw.h" #include "hw_conf.h" #include "hw_if.h" #include "ble_bufsize.h" +#endif /****************************************************************************** * Application Config ******************************************************************************/ +/**< generic parameters ******************************************************/ +/* HCI related defines */ + +#define ACI_HAL_SET_TX_POWER_LEVEL 0xFC0F +#define ACI_WRITE_CONFIG_DATA_OPCODE 0xFC0C +#define ACI_READ_CONFIG_DATA_OPCODE 0xFC0D +#define MAX_HCI_ACL_PACKET_SIZE (sizeof(TL_PacketHeader_t) + 5 + 251) +#define HCI_RESET 0x0C03 + +#ifndef BLE_SHARED_MEM_BYTE_ORDER + #define BLE_SHARED_MEM_BYTE_ORDER MSBFIRST +#endif +#define BLE_MODULE_SHARED_MEM_BUFFER_SIZE 128 + +/** + * Define Tx Power + */ +#define CFG_TX_POWER (0x18) /* -0.15dBm */ + +#if 0 /** * Define Secure Connections Support */ @@ -104,6 +126,7 @@ #define CFG_FW_SUBVERSION (1) #define CFG_FW_BRANCH (0) #define CFG_FW_BUILD (0) +#endif /****************************************************************************** * BLE Stack @@ -250,7 +273,7 @@ * 0: LE Power Class 2-3 * other bits: complete with Options_extension flag */ -#define CFG_BLE_OPTIONS (SHCI_C2_BLE_INIT_OPTIONS_LL_HOST | SHCI_C2_BLE_INIT_OPTIONS_WITH_SVC_CHANGE_DESC | SHCI_C2_BLE_INIT_OPTIONS_DEVICE_NAME_RW | SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV | SHCI_C2_BLE_INIT_OPTIONS_CS_ALGO2 | SHCI_C2_BLE_INIT_OPTIONS_FULL_GATTDB_NVM | SHCI_C2_BLE_INIT_OPTIONS_GATT_CACHING_NOTUSED | SHCI_C2_BLE_INIT_OPTIONS_POWER_CLASS_2_3) +#define CFG_BLE_OPTIONS (SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY | SHCI_C2_BLE_INIT_OPTIONS_WITH_SVC_CHANGE_DESC | SHCI_C2_BLE_INIT_OPTIONS_DEVICE_NAME_RW | SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV | SHCI_C2_BLE_INIT_OPTIONS_CS_ALGO2 | SHCI_C2_BLE_INIT_OPTIONS_FULL_GATTDB_NVM | SHCI_C2_BLE_INIT_OPTIONS_GATT_CACHING_NOTUSED | SHCI_C2_BLE_INIT_OPTIONS_POWER_CLASS_2_3) /** * BLE stack Options_extension flags to be configured with: @@ -292,7 +315,11 @@ * This parameter is considered by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV flag set */ -#define CFG_BLE_MAX_ADV_SET_NBR (8) +#if defined(STM32WB15xx) + #define CFG_BLE_MAX_ADV_SET_NBR (3) +#else + #define CFG_BLE_MAX_ADV_SET_NBR (8) +#endif /* Maximum advertising data length (in bytes) * Range: 31 .. 1650 with limitation: @@ -301,7 +328,11 @@ * This parameter is considered by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV flag set */ -#define CFG_BLE_MAX_ADV_DATA_LEN (207) +#if defined(STM32WB15xx) + #define CFG_BLE_MAX_ADV_DATA_LEN (414) +#else + #define CFG_BLE_MAX_ADV_DATA_LEN (207) +#endif /* RF TX Path Compensation Value (16-bit signed integer). Units: 0.1 dB. * Range: -1280 .. 1280 @@ -324,6 +355,7 @@ #define CFG_BLE_CORE_VERSION (SHCI_C2_BLE_INIT_BLE_CORE_5_4) +#if 0 /****************************************************************************** * Transport Layer ******************************************************************************/ @@ -659,4 +691,5 @@ typedef enum #define CFG_OTP_END_ADRESS OTP_AREA_END_ADDR -#endif /*APP_CONF_H */ +#endif +#endif /*APP_CONF_DEFAULT_H */ diff --git a/src/utility/STM32_WPAN/hw.h b/src/utility/STM32_WPAN/hw.h index 651e1f17..1472a5e8 100644 --- a/src/utility/STM32_WPAN/hw.h +++ b/src/utility/STM32_WPAN/hw.h @@ -26,14 +26,23 @@ extern "C" { #endif /* Includes ------------------------------------------------------------------*/ +#include "stm32_def.h" +#include "stm32wbxx_ll_bus.h" +#include "stm32wbxx_ll_exti.h" +#include "stm32wbxx_ll_system.h" +#include "stm32wbxx_ll_rcc.h" +#include "stm32wbxx_ll_ipcc.h" +#include "stm32wbxx_ll_cortex.h" +#include "stm32wbxx_ll_utils.h" +#include "stm32wbxx_ll_pwr.h" /****************************************************************************** * HW IPCC ******************************************************************************/ void HW_IPCC_Enable( void ); void HW_IPCC_Init( void ); - void HW_IPCC_Rx_Handler( void ); - void HW_IPCC_Tx_Handler( void ); +#define HW_IPCC_Rx_Handler IPCC_C1_RX_IRQHandler +#define HW_IPCC_Tx_Handler IPCC_C1_TX_IRQHandler void HW_IPCC_BLE_Init( void ); void HW_IPCC_BLE_SendCmd( void ); diff --git a/src/utility/STM32_WPAN/hw_ipcc.c b/src/utility/STM32_WPAN/hw_ipcc.c index fd620b85..3461cbed 100644 --- a/src/utility/STM32_WPAN/hw_ipcc.c +++ b/src/utility/STM32_WPAN/hw_ipcc.c @@ -18,8 +18,9 @@ */ /* USER CODE END Header */ +#if defined(STM32WBxx) /* Includes ------------------------------------------------------------------*/ -#include "app_common.h" +#include "hw.h" #include "mbox_def.h" /* Global variables ---------------------------------------------------------*/ @@ -667,3 +668,4 @@ static void HW_IPCC_TRACES_EvtHandler( void ) } __weak void HW_IPCC_TRACES_EvtNot( void ){}; +#endif /* STM32WBxx */ diff --git a/src/utility/STM32_WPAN/shci.c b/src/utility/STM32_WPAN/shci.c index 5c32555e..40110f42 100644 --- a/src/utility/STM32_WPAN/shci.c +++ b/src/utility/STM32_WPAN/shci.c @@ -17,6 +17,7 @@ */ +#if defined(STM32WBxx) /* Includes ------------------------------------------------------------------*/ #include "stm32_wpan_common.h" @@ -759,3 +760,4 @@ SHCI_CmdStatus_t SHCI_GetWirelessFwInfo( WirelessFwInfo_t* pWirelessInfo ) return (SHCI_Success); } +#endif /* STM32WBxx */ diff --git a/src/utility/STM32_WPAN/shci_tl.c b/src/utility/STM32_WPAN/shci_tl.c index 0f604300..daa988c1 100644 --- a/src/utility/STM32_WPAN/shci_tl.c +++ b/src/utility/STM32_WPAN/shci_tl.c @@ -17,11 +17,13 @@ */ +#if defined(STM32WBxx) /* Includes ------------------------------------------------------------------*/ #include "stm32_wpan_common.h" #include "stm_list.h" #include "shci_tl.h" +#include "stm32_def.h" /* Private typedef -----------------------------------------------------------*/ typedef enum @@ -168,6 +170,20 @@ void shci_send( uint16_t cmd_code, uint8_t len_cmd_payload, uint8_t * p_cmd_payl return; } +void shci_notify_asynch_evt(void *pdata) +{ + UNUSED(pdata); + /* Need to parse data in future version */ + shci_user_evt_proc(); +} + +void shci_register_io_bus(tSHciIO *fops) +{ + /* Register IO bus services */ + fops->Init = TL_SYS_Init; + fops->Send = TL_SYS_SendCmd; +} + /* Private functions ---------------------------------------------------------*/ static void TlInit( TL_CmdPacket_t * p_cmdbuffer ) { @@ -250,3 +266,4 @@ __WEAK void shci_cmd_resp_release(uint32_t flag) return; } +#endif /* STM32WBxx */ diff --git a/src/utility/STM32_WPAN/stm_list.c b/src/utility/STM32_WPAN/stm_list.c index 4c928647..df6c2155 100644 --- a/src/utility/STM32_WPAN/stm_list.c +++ b/src/utility/STM32_WPAN/stm_list.c @@ -17,10 +17,13 @@ */ +#if defined(STM32WBxx) /****************************************************************************** * Include Files ******************************************************************************/ -#include "utilities_common.h" +#include "stdint.h" +#include "cmsis_gcc.h" +#include "stm32_wpan_common.h" #include "stm_list.h" @@ -204,3 +207,4 @@ void LST_get_prev_node (tListNode * ref_node, tListNode ** node) __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ } +#endif /* STM32WBxx */ diff --git a/src/utility/STM32_WPAN/tl_mbox.c b/src/utility/STM32_WPAN/tl_mbox.c index 27a998a3..40c96793 100644 --- a/src/utility/STM32_WPAN/tl_mbox.c +++ b/src/utility/STM32_WPAN/tl_mbox.c @@ -16,6 +16,7 @@ ****************************************************************************** */ +#if defined(STM32WBxx) /* Includes ------------------------------------------------------------------*/ #include "stm32_wpan_common.h" #include "hw.h" @@ -51,8 +52,10 @@ PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_BleLldTable_t TL_BleLldTable; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_SysTable_t TL_SysTable; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_MemManagerTable_t TL_MemManagerTable; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_TracesTable_t TL_TracesTable; +#if 0 PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_Mac_802_15_4_t TL_Mac_802_15_4_Table; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_ZigbeeTable_t TL_Zigbee_Table; +#endif /**< tables */ PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode FreeBufQueue; @@ -97,8 +100,10 @@ void TL_Init( void ) TL_RefTable.p_sys_table = &TL_SysTable; TL_RefTable.p_mem_manager_table = &TL_MemManagerTable; TL_RefTable.p_traces_table = &TL_TracesTable; +#if 0 TL_RefTable.p_mac_802_15_4_table = &TL_Mac_802_15_4_Table; TL_RefTable.p_zigbee_table = &TL_Zigbee_Table; +#endif HW_IPCC_Init(); return; @@ -846,3 +851,4 @@ static void OutputDbgTrace(TL_MB_PacketType_t packet_type, uint8_t* buffer) return; } +#endif /* STM32WBxx */ From 545cd735637d98b94953ca752b814107e58f0b8d Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Thu, 13 Jul 2023 17:16:40 +0200 Subject: [PATCH 149/226] fix: include a timeout when waiting for the cmd_resp Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- src/utility/STM32_WPAN/shci_tl.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/utility/STM32_WPAN/shci_tl.c b/src/utility/STM32_WPAN/shci_tl.c index daa988c1..25e1a214 100644 --- a/src/utility/STM32_WPAN/shci_tl.c +++ b/src/utility/STM32_WPAN/shci_tl.c @@ -24,6 +24,7 @@ #include "stm_list.h" #include "shci_tl.h" #include "stm32_def.h" +#include "wiring_time.h" /* Private typedef -----------------------------------------------------------*/ typedef enum @@ -251,10 +252,11 @@ static void TlUserEvtReceived(TL_EvtPacket_t *shcievt) /* Weak implementation ----------------------------------------------------------------*/ __WEAK void shci_cmd_resp_wait(uint32_t timeout) { - (void)timeout; - - while(CmdRspStatusFlag != SHCI_TL_CMD_RESP_RELEASE); - + for (unsigned long start = millis(); (millis() - start) < timeout;) { + if (CmdRspStatusFlag == SHCI_TL_CMD_RESP_RELEASE) { + break; + } + } return; } From 787f3fa8e404bfcf18a897016ebb3644fc92f740 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Wed, 10 Jan 2024 18:45:17 +0100 Subject: [PATCH 150/226] chore: add support for customize app_conf_default.h Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- src/utility/STM32_WPAN/app_conf_default.h | 58 ++++++++++++++++++----- 1 file changed, 45 insertions(+), 13 deletions(-) diff --git a/src/utility/STM32_WPAN/app_conf_default.h b/src/utility/STM32_WPAN/app_conf_default.h index 6c9beb3b..9509a0f5 100644 --- a/src/utility/STM32_WPAN/app_conf_default.h +++ b/src/utility/STM32_WPAN/app_conf_default.h @@ -50,7 +50,9 @@ /** * Define Tx Power */ -#define CFG_TX_POWER (0x18) /* -0.15dBm */ +#ifndef CFG_TX_POWER + #define CFG_TX_POWER (0x18) /* -0.15dBm */ +#endif #if 0 /** @@ -135,13 +137,25 @@ * Maximum number of simultaneous connections that the device will support. * Valid values are from 1 to 8 */ -#define CFG_BLE_NUM_LINK 8 +#ifndef CFG_BLE_NUM_LINK +#ifdef STM32WB15xx + #define CFG_BLE_NUM_LINK 3 +#else + #define CFG_BLE_NUM_LINK 8 +#endif +#endif /** * Maximum number of Services that can be stored in the GATT database. * Note that the GAP and GATT services are automatically added so this parameter should be 2 plus the number of user services */ -#define CFG_BLE_NUM_GATT_SERVICES 8 +#ifndef CFG_BLE_NUM_GATT_SERVICES +#ifdef STM32WB15xx + #define CFG_BLE_NUM_GATT_SERVICES 4 +#else + #define CFG_BLE_NUM_GATT_SERVICES 8 +#endif +#endif /** * Maximum number of Attributes @@ -150,7 +164,13 @@ * Note that certain characteristics and relative descriptors are added automatically during device initialization * so this parameters should be 9 plus the number of user Attributes */ -#define CFG_BLE_NUM_GATT_ATTRIBUTES 68 +#ifndef CFG_BLE_NUM_GATT_ATTRIBUTES +#ifdef STM32WB15xx + #define CFG_BLE_NUM_GATT_ATTRIBUTES 30 +#else + #define CFG_BLE_NUM_GATT_ATTRIBUTES 68 +#endif +#endif /** * Maximum supported ATT_MTU size @@ -186,12 +206,16 @@ /** * Enable or disable the Extended Packet length feature. Valid values are 0 or 1. */ -#define CFG_BLE_DATA_LENGTH_EXTENSION 1 +#ifndef CFG_BLE_DATA_LENGTH_EXTENSION + #define CFG_BLE_DATA_LENGTH_EXTENSION 1 +#endif /** * Sleep clock accuracy in Peripheral mode (ppm value) */ -#define CFG_BLE_PERIPHERAL_SCA 500 +#ifndef CFG_BLE_PERIPHERAL_SCA + #define CFG_BLE_PERIPHERAL_SCA 500 +#endif /** * Sleep clock accuracy in Central mode @@ -204,7 +228,9 @@ * 6 : 21 ppm to 30 ppm * 7 : 0 ppm to 20 ppm */ -#define CFG_BLE_CENTRAL_SCA 0 +#ifndef CFG_BLE_CENTRAL_SCA + #define CFG_BLE_CENTRAL_SCA 0 +#endif /** * LsSource @@ -213,21 +239,27 @@ * - bit 1: 1: STM32WB5M Module device 0: Other devices as STM32WBxx SOC, STM32WB1M module * - bit 2: 1: HSE/1024 Clock config 0: LSE Clock config */ -#if defined(STM32WB5Mxx) - #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_MOD5MM_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) -#else - #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_OTHER_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) +#ifndef CFG_BLE_LS_SOURCE + #if defined(STM32WB5Mxx) + #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_MOD5MM_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) + #else + #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_OTHER_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) + #endif #endif /** * Start up time of the high speed (16 or 32 MHz) crystal oscillator in units of 625/256 us (~2.44 us) */ -#define CFG_BLE_HSE_STARTUP_TIME 0x148 +#ifndef CFG_BLE_HSE_STARTUP_TIME + #define CFG_BLE_HSE_STARTUP_TIME 0x148 +#endif /** * Maximum duration of the connection event when the device is in Peripheral mode in units of 625/256 us (~2.44 us) */ -#define CFG_BLE_MAX_CONN_EVENT_LENGTH (0xFFFFFFFF) +#ifndef CFG_BLE_MAX_CONN_EVENT_LENGTH + #define CFG_BLE_MAX_CONN_EVENT_LENGTH (0xFFFFFFFF) +#endif /** * Viterbi Mode From c8dfa1c0e50c17863d3b79c9e15c37872dce93b8 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Mon, 24 Jul 2023 10:55:20 +0200 Subject: [PATCH 151/226] fix: TL_Evt_t payload size for reset Within STM32CubeWB v1.17.0 update TL_Evt_t payload size was reduced. This produce a warning -Warray-bounds due to the reset management which require 4 bytes. Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- src/utility/STM32_WPAN/tl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utility/STM32_WPAN/tl.h b/src/utility/STM32_WPAN/tl.h index 8e8c6cbc..74520878 100644 --- a/src/utility/STM32_WPAN/tl.h +++ b/src/utility/STM32_WPAN/tl.h @@ -108,7 +108,7 @@ typedef PACKED_STRUCT { uint8_t evtcode; uint8_t plen; - uint8_t payload[2]; + uint8_t payload[4]; } TL_Evt_t; typedef PACKED_STRUCT From 8a6ead5e72102de00127e31d90b5b1e74ca2f2c6 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Wed, 10 Jan 2024 19:00:05 +0100 Subject: [PATCH 152/226] chore: regenerate STM32_WPAN patches Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- .../0001-chore-adapt-STM32_WPAN-sources.patch | 155 ++++++++---------- ...imeout-when-waiting-for-the-cmd_resp.patch | 10 +- ...ort-for-customize-app_conf_default.h.patch | 108 +++--------- ...-fix-TL_Evt_t-payload-size-for-reset.patch | 4 +- 4 files changed, 100 insertions(+), 177 deletions(-) diff --git a/extras/STM32_WPAN/0001-chore-adapt-STM32_WPAN-sources.patch b/extras/STM32_WPAN/0001-chore-adapt-STM32_WPAN-sources.patch index 6798e172..90daace9 100644 --- a/extras/STM32_WPAN/0001-chore-adapt-STM32_WPAN-sources.patch +++ b/extras/STM32_WPAN/0001-chore-adapt-STM32_WPAN-sources.patch @@ -1,22 +1,21 @@ -From 542e007fa5a1b53664d2efb5f01d67767123a357 Mon Sep 17 00:00:00 2001 +From 5587ff466e0276de186103d21e6a4e498820e49f Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> -Date: Thu, 13 Jul 2023 17:08:05 +0200 +Date: Wed, 10 Jan 2024 18:16:01 +0100 Subject: [PATCH 1/4] chore: adapt STM32_WPAN sources Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- - src/utility/STM32_WPAN/app_conf_default.h | 46 ++++++++++++++++----- - src/utility/STM32_WPAN/ble_bufsize.h | 7 ++++ + src/utility/STM32_WPAN/app_conf_default.h | 49 +++++++++++++++++++---- src/utility/STM32_WPAN/hw.h | 13 +++++- - src/utility/STM32_WPAN/hw_ipcc.c | 5 ++- - src/utility/STM32_WPAN/shci.c | 3 +- - src/utility/STM32_WPAN/shci_tl.c | 18 +++++++- - src/utility/STM32_WPAN/stm_list.c | 7 +++- - src/utility/STM32_WPAN/tl_mbox.c | 7 +++- - 8 files changed, 86 insertions(+), 20 deletions(-) + src/utility/STM32_WPAN/hw_ipcc.c | 4 +- + src/utility/STM32_WPAN/shci.c | 2 + + src/utility/STM32_WPAN/shci_tl.c | 17 ++++++++ + src/utility/STM32_WPAN/stm_list.c | 6 ++- + src/utility/STM32_WPAN/tl_mbox.c | 6 +++ + 7 files changed, 85 insertions(+), 12 deletions(-) diff --git a/src/utility/STM32_WPAN/app_conf_default.h b/src/utility/STM32_WPAN/app_conf_default.h -index 51bd33a..1c6dd91 100644 +index 846be3c..6c9beb3 100644 --- a/src/utility/STM32_WPAN/app_conf_default.h +++ b/src/utility/STM32_WPAN/app_conf_default.h @@ -1,9 +1,9 @@ @@ -31,22 +30,22 @@ index 51bd33a..1c6dd91 100644 ****************************************************************************** * @attention * -@@ -19,18 +19,38 @@ +@@ -19,18 +19,40 @@ /* USER CODE END Header */ /* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef APP_CONF_H -#define APP_CONF_H -- +#ifndef APP_CONF_DEFAULT_H +#define APP_CONF_DEFAULT_H + +#if 0 #include "hw.h" #include "hw_conf.h" #include "hw_if.h" #include "ble_bufsize.h" -- +#endif + /****************************************************************************** * Application Config ******************************************************************************/ @@ -74,75 +73,64 @@ index 51bd33a..1c6dd91 100644 /** * Define Secure Connections Support */ -@@ -104,7 +124,7 @@ +@@ -104,6 +126,7 @@ #define CFG_FW_SUBVERSION (1) #define CFG_FW_BRANCH (0) #define CFG_FW_BUILD (0) -- +#endif + /****************************************************************************** * BLE Stack - ******************************************************************************/ -@@ -152,13 +172,15 @@ - * Prepare Write List size in terms of number of packet - * This parameter is ignored by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set - */ --#define CFG_BLE_PREPARE_WRITE_LIST_SIZE BLE_PREP_WRITE_X_ATT(CFG_BLE_MAX_ATT_MTU) -+// #define CFG_BLE_PREPARE_WRITE_LIST_SIZE BLE_PREP_WRITE_X_ATT(CFG_BLE_MAX_ATT_MTU) -+#define CFG_BLE_PREPARE_WRITE_LIST_SIZE (0x3A) - - /** - * Number of allocated memory blocks - * This parameter is overwritten by the CPU2 with an hardcoded optimal value when the parameter CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set - */ --#define CFG_BLE_MBLOCK_COUNT (BLE_MBLOCKS_CALC(CFG_BLE_PREPARE_WRITE_LIST_SIZE, CFG_BLE_MAX_ATT_MTU, CFG_BLE_NUM_LINK)) -+//#define CFG_BLE_MBLOCK_COUNT (BLE_MBLOCKS_CALC(CFG_BLE_PREPARE_WRITE_LIST_SIZE, CFG_BLE_MAX_ATT_MTU, CFG_BLE_NUM_LINK)) -+#define CFG_BLE_MBLOCK_COUNT (0x79) - - /** - * Enable or disable the Extended Packet length feature. Valid values are 0 or 1. -@@ -250,7 +272,7 @@ +@@ -250,7 +273,7 @@ * 0: LE Power Class 2-3 * other bits: complete with Options_extension flag */ -#define CFG_BLE_OPTIONS (SHCI_C2_BLE_INIT_OPTIONS_LL_HOST | SHCI_C2_BLE_INIT_OPTIONS_WITH_SVC_CHANGE_DESC | SHCI_C2_BLE_INIT_OPTIONS_DEVICE_NAME_RW | SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV | SHCI_C2_BLE_INIT_OPTIONS_CS_ALGO2 | SHCI_C2_BLE_INIT_OPTIONS_FULL_GATTDB_NVM | SHCI_C2_BLE_INIT_OPTIONS_GATT_CACHING_NOTUSED | SHCI_C2_BLE_INIT_OPTIONS_POWER_CLASS_2_3) -+#define CFG_BLE_OPTIONS (SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY) ++#define CFG_BLE_OPTIONS (SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY | SHCI_C2_BLE_INIT_OPTIONS_WITH_SVC_CHANGE_DESC | SHCI_C2_BLE_INIT_OPTIONS_DEVICE_NAME_RW | SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV | SHCI_C2_BLE_INIT_OPTIONS_CS_ALGO2 | SHCI_C2_BLE_INIT_OPTIONS_FULL_GATTDB_NVM | SHCI_C2_BLE_INIT_OPTIONS_GATT_CACHING_NOTUSED | SHCI_C2_BLE_INIT_OPTIONS_POWER_CLASS_2_3) /** * BLE stack Options_extension flags to be configured with: -@@ -323,6 +345,7 @@ +@@ -292,7 +315,11 @@ + * This parameter is considered by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV flag set + */ - #define CFG_BLE_CORE_VERSION (SHCI_C2_BLE_INIT_BLE_CORE_5_3) +-#define CFG_BLE_MAX_ADV_SET_NBR (8) ++#if defined(STM32WB15xx) ++ #define CFG_BLE_MAX_ADV_SET_NBR (3) ++#else ++ #define CFG_BLE_MAX_ADV_SET_NBR (8) ++#endif + + /* Maximum advertising data length (in bytes) + * Range: 31 .. 1650 with limitation: +@@ -301,7 +328,11 @@ + * This parameter is considered by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV flag set + */ + +-#define CFG_BLE_MAX_ADV_DATA_LEN (207) ++#if defined(STM32WB15xx) ++ #define CFG_BLE_MAX_ADV_DATA_LEN (414) ++#else ++ #define CFG_BLE_MAX_ADV_DATA_LEN (207) ++#endif + + /* RF TX Path Compensation Value (16-bit signed integer). Units: 0.1 dB. + * Range: -1280 .. 1280 +@@ -324,6 +355,7 @@ + + #define CFG_BLE_CORE_VERSION (SHCI_C2_BLE_INIT_BLE_CORE_5_4) +#if 0 /****************************************************************************** * Transport Layer ******************************************************************************/ -@@ -658,4 +681,5 @@ typedef enum +@@ -659,4 +691,5 @@ typedef enum #define CFG_OTP_END_ADRESS OTP_AREA_END_ADDR -#endif /*APP_CONF_H */ +#endif +#endif /*APP_CONF_DEFAULT_H */ -diff --git a/src/utility/STM32_WPAN/ble_bufsize.h b/src/utility/STM32_WPAN/ble_bufsize.h -index b9935c0..d4d2890 100644 ---- a/src/utility/STM32_WPAN/ble_bufsize.h -+++ b/src/utility/STM32_WPAN/ble_bufsize.h -@@ -75,6 +75,13 @@ - ((pw) + MAX(BLE_MEM_BLOCK_X_MTU(mtu, n_link), \ - BLE_MBLOCKS_SECURE_CONNECTIONS)) - -+/* -+ * BLE_DEFAULT_MBLOCKS_COUNT: default memory blocks count -+ */ -+#define BLE_DEFAULT_MBLOCKS_COUNT(n_link) \ -+ BLE_MBLOCKS_CALC(BLE_DEFAULT_PREP_WRITE_LIST_SIZE, \ -+ BLE_DEFAULT_MAX_ATT_MTU, n_link) -+ - /* - * BLE_FIXED_BUFFER_SIZE_BYTES: - * A part of the RAM, is dynamically allocated by initializing all the pointers diff --git a/src/utility/STM32_WPAN/hw.h b/src/utility/STM32_WPAN/hw.h index 651e1f1..1472a5e 100644 --- a/src/utility/STM32_WPAN/hw.h @@ -174,14 +162,13 @@ index 651e1f1..1472a5e 100644 void HW_IPCC_BLE_Init( void ); void HW_IPCC_BLE_SendCmd( void ); diff --git a/src/utility/STM32_WPAN/hw_ipcc.c b/src/utility/STM32_WPAN/hw_ipcc.c -index fd620b8..c730482 100644 +index fd620b8..3461cbe 100644 --- a/src/utility/STM32_WPAN/hw_ipcc.c +++ b/src/utility/STM32_WPAN/hw_ipcc.c -@@ -17,9 +17,9 @@ - ****************************************************************************** +@@ -18,8 +18,9 @@ */ /* USER CODE END Header */ -- + +#if defined(STM32WBxx) /* Includes ------------------------------------------------------------------*/ -#include "app_common.h" @@ -189,38 +176,36 @@ index fd620b8..c730482 100644 #include "mbox_def.h" /* Global variables ---------------------------------------------------------*/ -@@ -667,3 +667,4 @@ static void HW_IPCC_TRACES_EvtHandler( void ) +@@ -667,3 +668,4 @@ static void HW_IPCC_TRACES_EvtHandler( void ) } __weak void HW_IPCC_TRACES_EvtNot( void ){}; +#endif /* STM32WBxx */ diff --git a/src/utility/STM32_WPAN/shci.c b/src/utility/STM32_WPAN/shci.c -index eaa35d7..4525656 100644 +index 5c32555..40110f4 100644 --- a/src/utility/STM32_WPAN/shci.c +++ b/src/utility/STM32_WPAN/shci.c -@@ -16,7 +16,7 @@ - ****************************************************************************** +@@ -17,6 +17,7 @@ */ -- + +#if defined(STM32WBxx) /* Includes ------------------------------------------------------------------*/ #include "stm32_wpan_common.h" -@@ -739,3 +739,4 @@ SHCI_CmdStatus_t SHCI_GetWirelessFwInfo( WirelessFwInfo_t* pWirelessInfo ) +@@ -759,3 +760,4 @@ SHCI_CmdStatus_t SHCI_GetWirelessFwInfo( WirelessFwInfo_t* pWirelessInfo ) return (SHCI_Success); } +#endif /* STM32WBxx */ diff --git a/src/utility/STM32_WPAN/shci_tl.c b/src/utility/STM32_WPAN/shci_tl.c -index 0f60430..e343809 100644 +index 0f60430..daa988c 100644 --- a/src/utility/STM32_WPAN/shci_tl.c +++ b/src/utility/STM32_WPAN/shci_tl.c -@@ -16,12 +16,13 @@ - ****************************************************************************** +@@ -17,11 +17,13 @@ */ -- + +#if defined(STM32WBxx) /* Includes ------------------------------------------------------------------*/ #include "stm32_wpan_common.h" @@ -231,7 +216,7 @@ index 0f60430..e343809 100644 /* Private typedef -----------------------------------------------------------*/ typedef enum -@@ -168,6 +169,20 @@ void shci_send( uint16_t cmd_code, uint8_t len_cmd_payload, uint8_t * p_cmd_payl +@@ -168,6 +170,20 @@ void shci_send( uint16_t cmd_code, uint8_t len_cmd_payload, uint8_t * p_cmd_payl return; } @@ -252,20 +237,19 @@ index 0f60430..e343809 100644 /* Private functions ---------------------------------------------------------*/ static void TlInit( TL_CmdPacket_t * p_cmdbuffer ) { -@@ -250,3 +265,4 @@ __WEAK void shci_cmd_resp_release(uint32_t flag) +@@ -250,3 +266,4 @@ __WEAK void shci_cmd_resp_release(uint32_t flag) return; } +#endif /* STM32WBxx */ diff --git a/src/utility/STM32_WPAN/stm_list.c b/src/utility/STM32_WPAN/stm_list.c -index 4c92864..4e8c364 100644 +index 4c92864..df6c215 100644 --- a/src/utility/STM32_WPAN/stm_list.c +++ b/src/utility/STM32_WPAN/stm_list.c -@@ -16,11 +16,13 @@ - ****************************************************************************** +@@ -17,10 +17,13 @@ */ -- + +#if defined(STM32WBxx) /****************************************************************************** * Include Files @@ -277,13 +261,13 @@ index 4c92864..4e8c364 100644 #include "stm_list.h" -@@ -204,3 +206,4 @@ void LST_get_prev_node (tListNode * ref_node, tListNode ** node) +@@ -204,3 +207,4 @@ void LST_get_prev_node (tListNode * ref_node, tListNode ** node) __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ } +#endif /* STM32WBxx */ diff --git a/src/utility/STM32_WPAN/tl_mbox.c b/src/utility/STM32_WPAN/tl_mbox.c -index 27a998a..1139316 100644 +index 27a998a..40c9679 100644 --- a/src/utility/STM32_WPAN/tl_mbox.c +++ b/src/utility/STM32_WPAN/tl_mbox.c @@ -16,6 +16,7 @@ @@ -294,19 +278,18 @@ index 27a998a..1139316 100644 /* Includes ------------------------------------------------------------------*/ #include "stm32_wpan_common.h" #include "hw.h" -@@ -51,9 +52,10 @@ PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_BleLldTable_t TL_BleLldTable; +@@ -51,8 +52,10 @@ PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_BleLldTable_t TL_BleLldTable; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_SysTable_t TL_SysTable; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_MemManagerTable_t TL_MemManagerTable; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_TracesTable_t TL_TracesTable; +#if 0 PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_Mac_802_15_4_t TL_Mac_802_15_4_Table; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_ZigbeeTable_t TL_Zigbee_Table; -- +#endif + /**< tables */ PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode FreeBufQueue; - PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode TracesEvtQueue; -@@ -97,8 +99,10 @@ void TL_Init( void ) +@@ -97,8 +100,10 @@ void TL_Init( void ) TL_RefTable.p_sys_table = &TL_SysTable; TL_RefTable.p_mem_manager_table = &TL_MemManagerTable; TL_RefTable.p_traces_table = &TL_TracesTable; @@ -317,11 +300,11 @@ index 27a998a..1139316 100644 HW_IPCC_Init(); return; -@@ -846,3 +850,4 @@ static void OutputDbgTrace(TL_MB_PacketType_t packet_type, uint8_t* buffer) +@@ -846,3 +851,4 @@ static void OutputDbgTrace(TL_MB_PacketType_t packet_type, uint8_t* buffer) return; } +#endif /* STM32WBxx */ -- -2.38.0.windows.1 +2.34.1 diff --git a/extras/STM32_WPAN/0002-fix-include-a-timeout-when-waiting-for-the-cmd_resp.patch b/extras/STM32_WPAN/0002-fix-include-a-timeout-when-waiting-for-the-cmd_resp.patch index d147a37e..e234d198 100644 --- a/extras/STM32_WPAN/0002-fix-include-a-timeout-when-waiting-for-the-cmd_resp.patch +++ b/extras/STM32_WPAN/0002-fix-include-a-timeout-when-waiting-for-the-cmd_resp.patch @@ -1,4 +1,4 @@ -From 5d07a0e5c0463965f8cf8dde6076b5cf2c779e90 Mon Sep 17 00:00:00 2001 +From 2867f96057d7bd5b34cfc3395d78653856f9cc7c Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Thu, 13 Jul 2023 17:16:40 +0200 Subject: [PATCH 2/4] fix: include a timeout when waiting for the cmd_resp @@ -9,10 +9,10 @@ Signed-off-by: Frederic Pillon <frederic.pillon@st.com> 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/utility/STM32_WPAN/shci_tl.c b/src/utility/STM32_WPAN/shci_tl.c -index e343809..6038025 100644 +index daa988c..25e1a21 100644 --- a/src/utility/STM32_WPAN/shci_tl.c +++ b/src/utility/STM32_WPAN/shci_tl.c -@@ -23,6 +23,7 @@ +@@ -24,6 +24,7 @@ #include "stm_list.h" #include "shci_tl.h" #include "stm32_def.h" @@ -20,7 +20,7 @@ index e343809..6038025 100644 /* Private typedef -----------------------------------------------------------*/ typedef enum -@@ -250,10 +251,11 @@ static void TlUserEvtReceived(TL_EvtPacket_t *shcievt) +@@ -251,10 +252,11 @@ static void TlUserEvtReceived(TL_EvtPacket_t *shcievt) /* Weak implementation ----------------------------------------------------------------*/ __WEAK void shci_cmd_resp_wait(uint32_t timeout) { @@ -37,5 +37,5 @@ index e343809..6038025 100644 } -- -2.38.0.windows.1 +2.34.1 diff --git a/extras/STM32_WPAN/0003-chore-add-support-for-customize-app_conf_default.h.patch b/extras/STM32_WPAN/0003-chore-add-support-for-customize-app_conf_default.h.patch index 93e3e80f..bd66679d 100644 --- a/extras/STM32_WPAN/0003-chore-add-support-for-customize-app_conf_default.h.patch +++ b/extras/STM32_WPAN/0003-chore-add-support-for-customize-app_conf_default.h.patch @@ -1,29 +1,29 @@ -From 370e1082edae9b69d50f824db85b5cbe3b786e79 Mon Sep 17 00:00:00 2001 +From ba3df1bd28eb49eab28a99fa88481f45fe565cbf Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> -Date: Mon, 12 Dec 2022 17:29:27 +0100 +Date: Wed, 10 Jan 2024 18:45:17 +0100 Subject: [PATCH 3/4] chore: add support for customize app_conf_default.h Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- - src/utility/STM32_WPAN/app_conf_default.h | 86 ++++++++++++++++----- - 1 file changed, 68 insertions(+), 18 deletions(-) + src/utility/STM32_WPAN/app_conf_default.h | 58 ++++++++++++++++++----- + 1 file changed, 45 insertions(+), 13 deletions(-) diff --git a/src/utility/STM32_WPAN/app_conf_default.h b/src/utility/STM32_WPAN/app_conf_default.h -index 1c6dd91..d39492e 100644 +index 6c9beb3..9509a0f 100644 --- a/src/utility/STM32_WPAN/app_conf_default.h +++ b/src/utility/STM32_WPAN/app_conf_default.h -@@ -48,7 +48,9 @@ +@@ -50,7 +50,9 @@ /** * Define Tx Power */ -#define CFG_TX_POWER (0x18) /* -0.15dBm */ +#ifndef CFG_TX_POWER -+ #define CFG_TX_POWER (0x18) /* -0.15dBm */ ++ #define CFG_TX_POWER (0x18) /* -0.15dBm */ +#endif #if 0 /** -@@ -132,13 +134,25 @@ +@@ -135,13 +137,25 @@ * Maximum number of simultaneous connections that the device will support. * Valid values are from 1 to 8 */ @@ -51,56 +51,22 @@ index 1c6dd91..d39492e 100644 /** * Maximum number of Attributes -@@ -147,13 +161,21 @@ +@@ -150,7 +164,13 @@ * Note that certain characteristics and relative descriptors are added automatically during device initialization * so this parameters should be 9 plus the number of user Attributes */ -#define CFG_BLE_NUM_GATT_ATTRIBUTES 68 +#ifndef CFG_BLE_NUM_GATT_ATTRIBUTES +#ifdef STM32WB15xx -+ #define CFG_BLE_NUM_GATT_ATTRIBUTES 30 ++ #define CFG_BLE_NUM_GATT_ATTRIBUTES 30 +#else -+ #define CFG_BLE_NUM_GATT_ATTRIBUTES 68 ++ #define CFG_BLE_NUM_GATT_ATTRIBUTES 68 +#endif +#endif /** * Maximum supported ATT_MTU size - * This parameter is ignored by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set - */ --#define CFG_BLE_MAX_ATT_MTU (156) -+#ifndef CFG_BLE_MAX_ATT_MTU -+ #define CFG_BLE_MAX_ATT_MTU (156) -+#endif - - /** - * Size of the storage area for Attribute values -@@ -166,14 +188,22 @@ - * The total amount of memory needed is the sum of the above quantities for each attribute. - * This parameter is ignored by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set - */ --#define CFG_BLE_ATT_VALUE_ARRAY_SIZE (1344) -+#ifndef CFG_BLE_ATT_VALUE_ARRAY_SIZE -+#ifdef STM32WB15xx -+ #define CFG_BLE_ATT_VALUE_ARRAY_SIZE (1290) -+#else -+ #define CFG_BLE_ATT_VALUE_ARRAY_SIZE (1344) -+#endif -+#endif - - /** - * Prepare Write List size in terms of number of packet - * This parameter is ignored by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set - */ - // #define CFG_BLE_PREPARE_WRITE_LIST_SIZE BLE_PREP_WRITE_X_ATT(CFG_BLE_MAX_ATT_MTU) --#define CFG_BLE_PREPARE_WRITE_LIST_SIZE (0x3A) -+#ifndef CFG_BLE_PREPARE_WRITE_LIST_SIZE -+ #define CFG_BLE_PREPARE_WRITE_LIST_SIZE (0x3A) -+#endif - - /** - * Number of allocated memory blocks -@@ -185,12 +215,16 @@ +@@ -186,12 +206,16 @@ /** * Enable or disable the Extended Packet length feature. Valid values are 0 or 1. */ @@ -110,27 +76,27 @@ index 1c6dd91..d39492e 100644 +#endif /** - * Sleep clock accuracy in Slave mode (ppm value) + * Sleep clock accuracy in Peripheral mode (ppm value) */ --#define CFG_BLE_SLAVE_SCA 500 -+#ifndef CFG_BLE_SLAVE_SCA -+ #define CFG_BLE_SLAVE_SCA 500 +-#define CFG_BLE_PERIPHERAL_SCA 500 ++#ifndef CFG_BLE_PERIPHERAL_SCA ++ #define CFG_BLE_PERIPHERAL_SCA 500 +#endif /** - * Sleep clock accuracy in Master mode -@@ -203,7 +237,9 @@ + * Sleep clock accuracy in Central mode +@@ -204,7 +228,9 @@ * 6 : 21 ppm to 30 ppm * 7 : 0 ppm to 20 ppm */ --#define CFG_BLE_MASTER_SCA 0 -+#ifndef CFG_BLE_MASTER_SCA -+ #define CFG_BLE_MASTER_SCA 0 +-#define CFG_BLE_CENTRAL_SCA 0 ++#ifndef CFG_BLE_CENTRAL_SCA ++ #define CFG_BLE_CENTRAL_SCA 0 +#endif /** * LsSource -@@ -212,21 +248,27 @@ +@@ -213,21 +239,27 @@ * - bit 1: 1: STM32WB5M Module device 0: Other devices as STM32WBxx SOC, STM32WB1M module * - bit 2: 1: HSE/1024 Clock config 0: LSE Clock config */ @@ -155,7 +121,7 @@ index 1c6dd91..d39492e 100644 +#endif /** - * Maximum duration of the connection event when the device is in Slave mode in units of 625/256 us (~2.44 us) + * Maximum duration of the connection event when the device is in Peripheral mode in units of 625/256 us (~2.44 us) */ -#define CFG_BLE_MAX_CONN_EVENT_LENGTH (0xFFFFFFFF) +#ifndef CFG_BLE_MAX_CONN_EVENT_LENGTH @@ -164,32 +130,6 @@ index 1c6dd91..d39492e 100644 /** * Viterbi Mode -@@ -314,7 +356,11 @@ - * This parameter is considered by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV flag set - */ - --#define CFG_BLE_MAX_ADV_SET_NBR (8) -+#if defined(STM32WB15xx) -+ #define CFG_BLE_MAX_ADV_SET_NBR (3) -+#else -+ #define CFG_BLE_MAX_ADV_SET_NBR (8) -+#endif - - /* Maximum advertising data length (in bytes) - * Range: 31 .. 1650 with limitation: -@@ -323,7 +369,11 @@ - * This parameter is considered by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV flag set - */ - --#define CFG_BLE_MAX_ADV_DATA_LEN (207) -+#if defined(STM32WB15xx) -+ #define CFG_BLE_MAX_ADV_DATA_LEN (414) -+#else -+ #define CFG_BLE_MAX_ADV_DATA_LEN (207) -+#endif - - /* RF TX Path Compensation Value (16-bit signed integer). Units: 0.1 dB. - * Range: -1280 .. 1280 -- -2.38.0.windows.1 +2.34.1 diff --git a/extras/STM32_WPAN/0004-fix-TL_Evt_t-payload-size-for-reset.patch b/extras/STM32_WPAN/0004-fix-TL_Evt_t-payload-size-for-reset.patch index 8ac978ea..035d4b99 100644 --- a/extras/STM32_WPAN/0004-fix-TL_Evt_t-payload-size-for-reset.patch +++ b/extras/STM32_WPAN/0004-fix-TL_Evt_t-payload-size-for-reset.patch @@ -1,4 +1,4 @@ -From b294edcaee311c15dfb307ea1298ae88b16a92bf Mon Sep 17 00:00:00 2001 +From a6ae9acf134d326f74ff04818b4e2c643c826b35 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Mon, 24 Jul 2023 10:55:20 +0200 Subject: [PATCH 4/4] fix: TL_Evt_t payload size for reset @@ -26,5 +26,5 @@ index 8e8c6cb..7452087 100644 typedef PACKED_STRUCT -- -2.38.0.windows.1 +2.34.1 From 466177122fbce155160b7ee149555321d9ee2dc7 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Thu, 11 Jan 2024 15:41:08 +0100 Subject: [PATCH 153/226] fix(examples): wrong board name Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- examples/Central/LedControl/LedControl.ino | 2 +- examples/Central/PeripheralExplorer/PeripheralExplorer.ino | 2 +- examples/Central/Scan/Scan.ino | 2 +- examples/Central/ScanCallback/ScanCallback.ino | 2 +- examples/Central/SensorTagButton/SensorTagButton.ino | 2 +- examples/Peripheral/ButtonLED/ButtonLED.ino | 2 +- examples/Peripheral/CallbackLED/CallbackLED.ino | 2 +- examples/Peripheral/LED/LED.ino | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/examples/Central/LedControl/LedControl.ino b/examples/Central/LedControl/LedControl.ino index 08db7aca..f3441596 100644 --- a/examples/Central/LedControl/LedControl.ino +++ b/examples/Central/LedControl/LedControl.ino @@ -57,7 +57,7 @@ BLELocalDevice BLEObj(&HCISpiTransport); BLELocalDevice& BLE = BLEObj; #endif #elif defined(ARDUINO_NUCLEO_WB15CC) || defined(ARDUINO_P_NUCLEO_WB55RG) ||\ - defined(ARDUINO_STM32WB5MM_DK) || defined(P_NUCLEO_WB55_USB_DONGLE) + defined(ARDUINO_STM32WB5MM_DK) || defined(ARDUINO_P_NUCLEO_WB55_USB_DONGLE) HCISharedMemTransportClass HCISharedMemTransport; #if !defined(FAKE_BLELOCALDEVICE) BLELocalDevice BLEObj(&HCISharedMemTransport); diff --git a/examples/Central/PeripheralExplorer/PeripheralExplorer.ino b/examples/Central/PeripheralExplorer/PeripheralExplorer.ino index 44aa00c4..ad78946c 100644 --- a/examples/Central/PeripheralExplorer/PeripheralExplorer.ino +++ b/examples/Central/PeripheralExplorer/PeripheralExplorer.ino @@ -51,7 +51,7 @@ BLELocalDevice BLEObj(&HCISpiTransport); BLELocalDevice& BLE = BLEObj; #endif #elif defined(ARDUINO_NUCLEO_WB15CC) || defined(ARDUINO_P_NUCLEO_WB55RG) ||\ - defined(ARDUINO_STM32WB5MM_DK) || defined(P_NUCLEO_WB55_USB_DONGLE) + defined(ARDUINO_STM32WB5MM_DK) || defined(ARDUINO_P_NUCLEO_WB55_USB_DONGLE) HCISharedMemTransportClass HCISharedMemTransport; #if !defined(FAKE_BLELOCALDEVICE) BLELocalDevice BLEObj(&HCISharedMemTransport); diff --git a/examples/Central/Scan/Scan.ino b/examples/Central/Scan/Scan.ino index 4c34e563..fbbb7a9e 100644 --- a/examples/Central/Scan/Scan.ino +++ b/examples/Central/Scan/Scan.ino @@ -47,7 +47,7 @@ BLELocalDevice BLEObj(&HCISpiTransport); BLELocalDevice& BLE = BLEObj; #endif #elif defined(ARDUINO_NUCLEO_WB15CC) || defined(ARDUINO_P_NUCLEO_WB55RG) ||\ - defined(ARDUINO_STM32WB5MM_DK) || defined(P_NUCLEO_WB55_USB_DONGLE) + defined(ARDUINO_STM32WB5MM_DK) || defined(ARDUINO_P_NUCLEO_WB55_USB_DONGLE) HCISharedMemTransportClass HCISharedMemTransport; #if !defined(FAKE_BLELOCALDEVICE) BLELocalDevice BLEObj(&HCISharedMemTransport); diff --git a/examples/Central/ScanCallback/ScanCallback.ino b/examples/Central/ScanCallback/ScanCallback.ino index bba10789..6ee70e17 100644 --- a/examples/Central/ScanCallback/ScanCallback.ino +++ b/examples/Central/ScanCallback/ScanCallback.ino @@ -49,7 +49,7 @@ BLELocalDevice BLEObj(&HCISpiTransport); BLELocalDevice& BLE = BLEObj; #endif #elif defined(ARDUINO_NUCLEO_WB15CC) || defined(ARDUINO_P_NUCLEO_WB55RG) ||\ - defined(ARDUINO_STM32WB5MM_DK) || defined(P_NUCLEO_WB55_USB_DONGLE) + defined(ARDUINO_STM32WB5MM_DK) || defined(ARDUINO_P_NUCLEO_WB55_USB_DONGLE) HCISharedMemTransportClass HCISharedMemTransport; #if !defined(FAKE_BLELOCALDEVICE) BLELocalDevice BLEObj(&HCISharedMemTransport); diff --git a/examples/Central/SensorTagButton/SensorTagButton.ino b/examples/Central/SensorTagButton/SensorTagButton.ino index b371617f..6199933b 100644 --- a/examples/Central/SensorTagButton/SensorTagButton.ino +++ b/examples/Central/SensorTagButton/SensorTagButton.ino @@ -51,7 +51,7 @@ BLELocalDevice BLEObj(&HCISpiTransport); BLELocalDevice& BLE = BLEObj; #endif #elif defined(ARDUINO_NUCLEO_WB15CC) || defined(ARDUINO_P_NUCLEO_WB55RG) ||\ - defined(ARDUINO_STM32WB5MM_DK) || defined(P_NUCLEO_WB55_USB_DONGLE) + defined(ARDUINO_STM32WB5MM_DK) || defined(ARDUINO_P_NUCLEO_WB55_USB_DONGLE) HCISharedMemTransportClass HCISharedMemTransport; #if !defined(FAKE_BLELOCALDEVICE) BLELocalDevice BLEObj(&HCISharedMemTransport); diff --git a/examples/Peripheral/ButtonLED/ButtonLED.ino b/examples/Peripheral/ButtonLED/ButtonLED.ino index fb186766..59e19451 100644 --- a/examples/Peripheral/ButtonLED/ButtonLED.ino +++ b/examples/Peripheral/ButtonLED/ButtonLED.ino @@ -58,7 +58,7 @@ BLELocalDevice BLEObj(&HCISpiTransport); BLELocalDevice& BLE = BLEObj; #endif #elif defined(ARDUINO_NUCLEO_WB15CC) || defined(ARDUINO_P_NUCLEO_WB55RG) ||\ - defined(ARDUINO_STM32WB5MM_DK) || defined(P_NUCLEO_WB55_USB_DONGLE) + defined(ARDUINO_STM32WB5MM_DK) || defined(ARDUINO_P_NUCLEO_WB55_USB_DONGLE) HCISharedMemTransportClass HCISharedMemTransport; #if !defined(FAKE_BLELOCALDEVICE) BLELocalDevice BLEObj(&HCISharedMemTransport); diff --git a/examples/Peripheral/CallbackLED/CallbackLED.ino b/examples/Peripheral/CallbackLED/CallbackLED.ino index 0326f732..0a94d092 100644 --- a/examples/Peripheral/CallbackLED/CallbackLED.ino +++ b/examples/Peripheral/CallbackLED/CallbackLED.ino @@ -52,7 +52,7 @@ BLELocalDevice BLEObj(&HCISpiTransport); BLELocalDevice& BLE = BLEObj; #endif #elif defined(ARDUINO_NUCLEO_WB15CC) || defined(ARDUINO_P_NUCLEO_WB55RG) ||\ - defined(ARDUINO_STM32WB5MM_DK) || defined(P_NUCLEO_WB55_USB_DONGLE) + defined(ARDUINO_STM32WB5MM_DK) || defined(ARDUINO_P_NUCLEO_WB55_USB_DONGLE) HCISharedMemTransportClass HCISharedMemTransport; #if !defined(FAKE_BLELOCALDEVICE) BLELocalDevice BLEObj(&HCISharedMemTransport); diff --git a/examples/Peripheral/LED/LED.ino b/examples/Peripheral/LED/LED.ino index 1ba9c9a8..442350d0 100644 --- a/examples/Peripheral/LED/LED.ino +++ b/examples/Peripheral/LED/LED.ino @@ -50,7 +50,7 @@ BLELocalDevice BLEObj(&HCISpiTransport); BLELocalDevice& BLE = BLEObj; #endif #elif defined(ARDUINO_NUCLEO_WB15CC) || defined(ARDUINO_P_NUCLEO_WB55RG) ||\ - defined(ARDUINO_STM32WB5MM_DK) || defined(P_NUCLEO_WB55_USB_DONGLE) + defined(ARDUINO_STM32WB5MM_DK) || defined(ARDUINO_P_NUCLEO_WB55_USB_DONGLE) HCISharedMemTransportClass HCISharedMemTransport; #if !defined(FAKE_BLELOCALDEVICE) BLELocalDevice BLEObj(&HCISharedMemTransport); From ac3cb9b6840182e06bee5ab34609b770a6589054 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Thu, 11 Jan 2024 15:44:23 +0100 Subject: [PATCH 154/226] ci: update deprecated checkout version Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- .github/workflows/compile-examples.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index da41142d..1c280e31 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -16,7 +16,7 @@ jobs: - STMicroelectronics:stm32:Nucleo_64:pnum=P_NUCLEO_WB55RG steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@main - uses: arduino/compile-sketches@v1 with: github-token: ${{ secrets.GITHUB_TOKEN }} From 1c3d6070189e813b4edbc4aaf3aa52717e06c9cf Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Thu, 11 Jan 2024 15:44:46 +0100 Subject: [PATCH 155/226] ci: add P_NUCLEO_WB55_USB_DONGLE to the build Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- .github/workflows/compile-examples.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index 1c280e31..86c4254f 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -14,6 +14,7 @@ jobs: - STMicroelectronics:stm32:Nucleo_64:pnum=NUCLEO_L476RG - STMicroelectronics:stm32:Disco:pnum=B_L475E_IOT01A - STMicroelectronics:stm32:Nucleo_64:pnum=P_NUCLEO_WB55RG + - STMicroelectronics:stm32:Nucleo_64:pnum=P_NUCLEO_WB55_USB_DONGLE steps: - uses: actions/checkout@main From fa71b3f8c99ad84f173743074051a235e395e21a Mon Sep 17 00:00:00 2001 From: Thijs van Liempd <33570639+thijses@users.noreply.github.com> Date: Thu, 30 May 2024 14:06:59 +0200 Subject: [PATCH 156/226] Update library.properties Signed-off-by: Thijs van Liempd <33570639+thijses@users.noreply.github.com> --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index da5c1c4c..bebbdf56 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=STM32duinoBLE -version=1.2.6 +version=1.2.7 author=Arduino, SRA maintainer=stm32duino sentence=Fork of ArduinoBLE library to add the support of STM32WB, SPBTLE-RF, SPBTLE-1S, BLUENRG-M2SP and BLUENRG-M0 BLE modules. From a99760cb10cc7bbd230dc478af13c8b6e6613b0e Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Mon, 29 Apr 2024 17:13:55 +0200 Subject: [PATCH 157/226] chore: update STM32_WPAN from Cube version v1.19.0 Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- src/utility/STM32_WPAN/README.md | 4 +- src/utility/STM32_WPAN/app_conf_default.h | 105 +++++----------------- src/utility/STM32_WPAN/ble_bufsize.h | 51 ++++++----- src/utility/STM32_WPAN/hw.h | 13 +-- src/utility/STM32_WPAN/hw_ipcc.c | 4 +- src/utility/STM32_WPAN/shci.c | 2 - src/utility/STM32_WPAN/shci_tl.c | 27 +----- src/utility/STM32_WPAN/stm_list.c | 6 +- src/utility/STM32_WPAN/tl.h | 2 +- src/utility/STM32_WPAN/tl_mbox.c | 6 -- 10 files changed, 60 insertions(+), 160 deletions(-) diff --git a/src/utility/STM32_WPAN/README.md b/src/utility/STM32_WPAN/README.md index 97c4ceba..b8b7d7ed 100644 --- a/src/utility/STM32_WPAN/README.md +++ b/src/utility/STM32_WPAN/README.md @@ -1,6 +1,6 @@ ## Source -[STMicroelectronics/STM32CubeWB Release v1.18.0](https://github.com/STMicroelectronics/STM32CubeWB/releases/tag/v1.18.0) -- Application: [BLE_TransparentMode](https://github.com/STMicroelectronics/STM32CubeWB/tree/v1.18.0/Projects/P-NUCLEO-WB55.Nucleo/Applications/BLE/BLE_TransparentMode) +[STMicroelectronics/STM32CubeWB Release v1.19.0](https://github.com/STMicroelectronics/STM32CubeWB/releases/tag/v1.19.0) +- Application: [BLE_TransparentMode](https://github.com/STMicroelectronics/STM32CubeWB/tree/v1.19.0/Projects/P-NUCLEO-WB55.Nucleo/Applications/BLE/BLE_TransparentMode) diff --git a/src/utility/STM32_WPAN/app_conf_default.h b/src/utility/STM32_WPAN/app_conf_default.h index 9509a0f5..846be3c9 100644 --- a/src/utility/STM32_WPAN/app_conf_default.h +++ b/src/utility/STM32_WPAN/app_conf_default.h @@ -1,9 +1,9 @@ /* USER CODE BEGIN Header */ /** ****************************************************************************** - * @file app_conf_default.h + * @file app_conf.h * @author MCD Application Team - * @brief Default application configuration file for STM32WPAN Middleware. + * @brief Application configuration file for STM32WPAN Middleware. ****************************************************************************** * @attention * @@ -19,42 +19,18 @@ /* USER CODE END Header */ /* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef APP_CONF_DEFAULT_H -#define APP_CONF_DEFAULT_H +#ifndef APP_CONF_H +#define APP_CONF_H -#if 0 #include "hw.h" #include "hw_conf.h" #include "hw_if.h" #include "ble_bufsize.h" -#endif /****************************************************************************** * Application Config ******************************************************************************/ -/**< generic parameters ******************************************************/ -/* HCI related defines */ - -#define ACI_HAL_SET_TX_POWER_LEVEL 0xFC0F -#define ACI_WRITE_CONFIG_DATA_OPCODE 0xFC0C -#define ACI_READ_CONFIG_DATA_OPCODE 0xFC0D -#define MAX_HCI_ACL_PACKET_SIZE (sizeof(TL_PacketHeader_t) + 5 + 251) -#define HCI_RESET 0x0C03 - -#ifndef BLE_SHARED_MEM_BYTE_ORDER - #define BLE_SHARED_MEM_BYTE_ORDER MSBFIRST -#endif -#define BLE_MODULE_SHARED_MEM_BUFFER_SIZE 128 - -/** - * Define Tx Power - */ -#ifndef CFG_TX_POWER - #define CFG_TX_POWER (0x18) /* -0.15dBm */ -#endif - -#if 0 /** * Define Secure Connections Support */ @@ -128,7 +104,6 @@ #define CFG_FW_SUBVERSION (1) #define CFG_FW_BRANCH (0) #define CFG_FW_BUILD (0) -#endif /****************************************************************************** * BLE Stack @@ -137,25 +112,13 @@ * Maximum number of simultaneous connections that the device will support. * Valid values are from 1 to 8 */ -#ifndef CFG_BLE_NUM_LINK -#ifdef STM32WB15xx - #define CFG_BLE_NUM_LINK 3 -#else - #define CFG_BLE_NUM_LINK 8 -#endif -#endif +#define CFG_BLE_NUM_LINK 8 /** * Maximum number of Services that can be stored in the GATT database. * Note that the GAP and GATT services are automatically added so this parameter should be 2 plus the number of user services */ -#ifndef CFG_BLE_NUM_GATT_SERVICES -#ifdef STM32WB15xx - #define CFG_BLE_NUM_GATT_SERVICES 4 -#else - #define CFG_BLE_NUM_GATT_SERVICES 8 -#endif -#endif +#define CFG_BLE_NUM_GATT_SERVICES 8 /** * Maximum number of Attributes @@ -164,13 +127,7 @@ * Note that certain characteristics and relative descriptors are added automatically during device initialization * so this parameters should be 9 plus the number of user Attributes */ -#ifndef CFG_BLE_NUM_GATT_ATTRIBUTES -#ifdef STM32WB15xx - #define CFG_BLE_NUM_GATT_ATTRIBUTES 30 -#else - #define CFG_BLE_NUM_GATT_ATTRIBUTES 68 -#endif -#endif +#define CFG_BLE_NUM_GATT_ATTRIBUTES 68 /** * Maximum supported ATT_MTU size @@ -206,16 +163,12 @@ /** * Enable or disable the Extended Packet length feature. Valid values are 0 or 1. */ -#ifndef CFG_BLE_DATA_LENGTH_EXTENSION - #define CFG_BLE_DATA_LENGTH_EXTENSION 1 -#endif +#define CFG_BLE_DATA_LENGTH_EXTENSION 1 /** * Sleep clock accuracy in Peripheral mode (ppm value) */ -#ifndef CFG_BLE_PERIPHERAL_SCA - #define CFG_BLE_PERIPHERAL_SCA 500 -#endif +#define CFG_BLE_PERIPHERAL_SCA 500 /** * Sleep clock accuracy in Central mode @@ -228,9 +181,7 @@ * 6 : 21 ppm to 30 ppm * 7 : 0 ppm to 20 ppm */ -#ifndef CFG_BLE_CENTRAL_SCA - #define CFG_BLE_CENTRAL_SCA 0 -#endif +#define CFG_BLE_CENTRAL_SCA 0 /** * LsSource @@ -239,27 +190,21 @@ * - bit 1: 1: STM32WB5M Module device 0: Other devices as STM32WBxx SOC, STM32WB1M module * - bit 2: 1: HSE/1024 Clock config 0: LSE Clock config */ -#ifndef CFG_BLE_LS_SOURCE - #if defined(STM32WB5Mxx) - #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_MOD5MM_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) - #else - #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_OTHER_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) - #endif +#if defined(STM32WB5Mxx) + #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_MOD5MM_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) +#else + #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_OTHER_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) #endif /** * Start up time of the high speed (16 or 32 MHz) crystal oscillator in units of 625/256 us (~2.44 us) */ -#ifndef CFG_BLE_HSE_STARTUP_TIME - #define CFG_BLE_HSE_STARTUP_TIME 0x148 -#endif +#define CFG_BLE_HSE_STARTUP_TIME 0x148 /** * Maximum duration of the connection event when the device is in Peripheral mode in units of 625/256 us (~2.44 us) */ -#ifndef CFG_BLE_MAX_CONN_EVENT_LENGTH - #define CFG_BLE_MAX_CONN_EVENT_LENGTH (0xFFFFFFFF) -#endif +#define CFG_BLE_MAX_CONN_EVENT_LENGTH (0xFFFFFFFF) /** * Viterbi Mode @@ -305,7 +250,7 @@ * 0: LE Power Class 2-3 * other bits: complete with Options_extension flag */ -#define CFG_BLE_OPTIONS (SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY | SHCI_C2_BLE_INIT_OPTIONS_WITH_SVC_CHANGE_DESC | SHCI_C2_BLE_INIT_OPTIONS_DEVICE_NAME_RW | SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV | SHCI_C2_BLE_INIT_OPTIONS_CS_ALGO2 | SHCI_C2_BLE_INIT_OPTIONS_FULL_GATTDB_NVM | SHCI_C2_BLE_INIT_OPTIONS_GATT_CACHING_NOTUSED | SHCI_C2_BLE_INIT_OPTIONS_POWER_CLASS_2_3) +#define CFG_BLE_OPTIONS (SHCI_C2_BLE_INIT_OPTIONS_LL_HOST | SHCI_C2_BLE_INIT_OPTIONS_WITH_SVC_CHANGE_DESC | SHCI_C2_BLE_INIT_OPTIONS_DEVICE_NAME_RW | SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV | SHCI_C2_BLE_INIT_OPTIONS_CS_ALGO2 | SHCI_C2_BLE_INIT_OPTIONS_FULL_GATTDB_NVM | SHCI_C2_BLE_INIT_OPTIONS_GATT_CACHING_NOTUSED | SHCI_C2_BLE_INIT_OPTIONS_POWER_CLASS_2_3) /** * BLE stack Options_extension flags to be configured with: @@ -347,11 +292,7 @@ * This parameter is considered by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV flag set */ -#if defined(STM32WB15xx) - #define CFG_BLE_MAX_ADV_SET_NBR (3) -#else - #define CFG_BLE_MAX_ADV_SET_NBR (8) -#endif +#define CFG_BLE_MAX_ADV_SET_NBR (8) /* Maximum advertising data length (in bytes) * Range: 31 .. 1650 with limitation: @@ -360,11 +301,7 @@ * This parameter is considered by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV flag set */ -#if defined(STM32WB15xx) - #define CFG_BLE_MAX_ADV_DATA_LEN (414) -#else - #define CFG_BLE_MAX_ADV_DATA_LEN (207) -#endif +#define CFG_BLE_MAX_ADV_DATA_LEN (207) /* RF TX Path Compensation Value (16-bit signed integer). Units: 0.1 dB. * Range: -1280 .. 1280 @@ -387,7 +324,6 @@ #define CFG_BLE_CORE_VERSION (SHCI_C2_BLE_INIT_BLE_CORE_5_4) -#if 0 /****************************************************************************** * Transport Layer ******************************************************************************/ @@ -723,5 +659,4 @@ typedef enum #define CFG_OTP_END_ADRESS OTP_AREA_END_ADDR -#endif -#endif /*APP_CONF_DEFAULT_H */ +#endif /*APP_CONF_H */ diff --git a/src/utility/STM32_WPAN/ble_bufsize.h b/src/utility/STM32_WPAN/ble_bufsize.h index b9935c0b..66cc2a5a 100644 --- a/src/utility/STM32_WPAN/ble_bufsize.h +++ b/src/utility/STM32_WPAN/ble_bufsize.h @@ -5,7 +5,7 @@ ***************************************************************************** * @attention * - * Copyright (c) 2018-2023 STMicroelectronics. + * Copyright (c) 2018-2024 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file @@ -35,13 +35,13 @@ * equal to BLE_DEFAULT_ATT_MTU (23). */ #define BLE_PREP_WRITE_X_ATT(max_att) \ - (DIVC(max_att, BLE_DEFAULT_ATT_MTU - 5) * 2) + (DIVC(max_att, BLE_DEFAULT_ATT_MTU - 5) * 2) /* * BLE_DEFAULT_PREP_WRITE_LIST_SIZE: default minimum Prepare Write List size. */ #define BLE_DEFAULT_PREP_WRITE_LIST_SIZE \ - BLE_PREP_WRITE_X_ATT(BLE_DEFAULT_MAX_ATT_SIZE) + BLE_PREP_WRITE_X_ATT(BLE_DEFAULT_MAX_ATT_SIZE) /* * BLE_MEM_BLOCK_X_MTU: compute how many memory blocks are needed to compose @@ -49,14 +49,21 @@ */ #define BLE_MEM_BLOCK_SIZE 32 +#if (SLAVE_ONLY != 0) ||(BASIC_FEATURES != 0) +#define BLE_MEM_BLOCK_X_PTX(n_link) 0 +#else +#define BLE_MEM_BLOCK_X_PTX(n_link) (n_link) +#endif + #define BLE_MEM_BLOCK_X_TX(mtu) \ - (DIVC((mtu) + 4U, BLE_MEM_BLOCK_SIZE) + 1U) + (DIVC((mtu) + 4U, BLE_MEM_BLOCK_SIZE) + 1) #define BLE_MEM_BLOCK_X_RX(mtu, n_link) \ - ((DIVC((mtu) + 4U, BLE_MEM_BLOCK_SIZE) + 2U) * (n_link) + 1) + ((DIVC((mtu) + 4U, BLE_MEM_BLOCK_SIZE) + 2U) * (n_link) + 1) #define BLE_MEM_BLOCK_X_MTU(mtu, n_link) \ - (BLE_MEM_BLOCK_X_TX(mtu) + BLE_MEM_BLOCK_X_RX(mtu, n_link)) + (BLE_MEM_BLOCK_X_TX(mtu) + BLE_MEM_BLOCK_X_PTX(n_link) + \ + BLE_MEM_BLOCK_X_RX(mtu, n_link)) /* * BLE_MBLOCKS_SECURE_CONNECTIONS: minimum number of blocks required for @@ -72,8 +79,8 @@ * - n_link: maximum number of simultaneous connections */ #define BLE_MBLOCKS_CALC(pw, mtu, n_link) \ - ((pw) + MAX(BLE_MEM_BLOCK_X_MTU(mtu, n_link), \ - BLE_MBLOCKS_SECURE_CONNECTIONS)) + ((pw) + MAX(BLE_MEM_BLOCK_X_MTU(mtu, n_link), \ + BLE_MBLOCKS_SECURE_CONNECTIONS)) /* * BLE_FIXED_BUFFER_SIZE_BYTES: @@ -90,30 +97,30 @@ * mentioned parameters. */ #if (BEACON_ONLY != 0) -#define BLE_FIXED_BUFFER_SIZE_BYTES 4092 /* Beacon only */ +#define BLE_FIXED_BUFFER_SIZE_BYTES 4100 /* Beacon only */ #elif (LL_ONLY_BASIC != 0) -#define BLE_FIXED_BUFFER_SIZE_BYTES 5788 /* LL only Basic*/ +#define BLE_FIXED_BUFFER_SIZE_BYTES 6040 /* LL only Basic*/ #elif (LL_ONLY != 0) -#define BLE_FIXED_BUFFER_SIZE_BYTES 6036 /* LL only Full */ +#define BLE_FIXED_BUFFER_SIZE_BYTES 6288 /* LL only Full */ #elif (SLAVE_ONLY != 0) -#define BLE_FIXED_BUFFER_SIZE_BYTES 6300 /* Peripheral only */ +#define BLE_FIXED_BUFFER_SIZE_BYTES 6408 /* Peripheral only */ #elif (BASIC_FEATURES != 0) -#define BLE_FIXED_BUFFER_SIZE_BYTES 6632 /* Basic Features */ +#define BLE_FIXED_BUFFER_SIZE_BYTES 7184 /* Basic Features */ #else -#define BLE_FIXED_BUFFER_SIZE_BYTES 7152 /* Full stack */ +#define BLE_FIXED_BUFFER_SIZE_BYTES 7468 /* Full stack */ #endif /* * BLE_PER_LINK_SIZE_BYTES: additional memory size used per link */ #if (BEACON_ONLY != 0) -#define BLE_PER_LINK_SIZE_BYTES 112 /* Beacon only */ +#define BLE_PER_LINK_SIZE_BYTES 108 /* Beacon only */ #elif (LL_ONLY_BASIC != 0) #define BLE_PER_LINK_SIZE_BYTES 244 /* LL only Basic */ #elif (LL_ONLY != 0) #define BLE_PER_LINK_SIZE_BYTES 244 /* LL only Full */ #elif (SLAVE_ONLY != 0) -#define BLE_PER_LINK_SIZE_BYTES 344 /* Peripheral only */ +#define BLE_PER_LINK_SIZE_BYTES 392 /* Peripheral only */ #elif (BASIC_FEATURES != 0) #define BLE_PER_LINK_SIZE_BYTES 420 /* Basic Features */ #else @@ -131,9 +138,9 @@ * @param mblocks_count: Number of memory blocks allocated for packets. */ #define BLE_TOTAL_BUFFER_SIZE(n_link, mblocks_count) \ - (16 + BLE_FIXED_BUFFER_SIZE_BYTES + \ - (BLE_PER_LINK_SIZE_BYTES * (n_link)) + \ - ((BLE_MEM_BLOCK_SIZE + 12) * (mblocks_count))) + (16 + BLE_FIXED_BUFFER_SIZE_BYTES + \ + (BLE_PER_LINK_SIZE_BYTES * (n_link)) + \ + ((BLE_MEM_BLOCK_SIZE + 8) * (mblocks_count))) /* * BLE_EXT_ADV_BUFFER_SIZE @@ -148,7 +155,7 @@ * Valid values are from 31 to 1650. */ #define BLE_EXT_ADV_BUFFER_SIZE(set_nbr, data_len) \ - (2512 + ((892 + (DIVC(data_len, 207) * 244)) * (set_nbr))) + (2512 + ((892 + (DIVC(data_len, 207) * 244)) * (set_nbr))) /* * BLE_TOTAL_BUFFER_SIZE_GATT: this macro returns the amount of memory, @@ -168,8 +175,8 @@ * @param att_value_array_size: Size of the storage area for Attribute values. */ #define BLE_TOTAL_BUFFER_SIZE_GATT(num_gatt_attributes, num_gatt_services, att_value_array_size) \ - (((((att_value_array_size) - 1) | 3) + 1) + \ - (40 * (num_gatt_attributes)) + (48 * (num_gatt_services))) + (((((att_value_array_size) - 1) | 3) + 1) + \ + (40 * (num_gatt_attributes)) + (48 * (num_gatt_services))) #endif /* BLE_BUFSIZE_H__ */ diff --git a/src/utility/STM32_WPAN/hw.h b/src/utility/STM32_WPAN/hw.h index 1472a5e8..651e1f17 100644 --- a/src/utility/STM32_WPAN/hw.h +++ b/src/utility/STM32_WPAN/hw.h @@ -26,23 +26,14 @@ extern "C" { #endif /* Includes ------------------------------------------------------------------*/ -#include "stm32_def.h" -#include "stm32wbxx_ll_bus.h" -#include "stm32wbxx_ll_exti.h" -#include "stm32wbxx_ll_system.h" -#include "stm32wbxx_ll_rcc.h" -#include "stm32wbxx_ll_ipcc.h" -#include "stm32wbxx_ll_cortex.h" -#include "stm32wbxx_ll_utils.h" -#include "stm32wbxx_ll_pwr.h" /****************************************************************************** * HW IPCC ******************************************************************************/ void HW_IPCC_Enable( void ); void HW_IPCC_Init( void ); -#define HW_IPCC_Rx_Handler IPCC_C1_RX_IRQHandler -#define HW_IPCC_Tx_Handler IPCC_C1_TX_IRQHandler + void HW_IPCC_Rx_Handler( void ); + void HW_IPCC_Tx_Handler( void ); void HW_IPCC_BLE_Init( void ); void HW_IPCC_BLE_SendCmd( void ); diff --git a/src/utility/STM32_WPAN/hw_ipcc.c b/src/utility/STM32_WPAN/hw_ipcc.c index 3461cbed..fd620b85 100644 --- a/src/utility/STM32_WPAN/hw_ipcc.c +++ b/src/utility/STM32_WPAN/hw_ipcc.c @@ -18,9 +18,8 @@ */ /* USER CODE END Header */ -#if defined(STM32WBxx) /* Includes ------------------------------------------------------------------*/ -#include "hw.h" +#include "app_common.h" #include "mbox_def.h" /* Global variables ---------------------------------------------------------*/ @@ -668,4 +667,3 @@ static void HW_IPCC_TRACES_EvtHandler( void ) } __weak void HW_IPCC_TRACES_EvtNot( void ){}; -#endif /* STM32WBxx */ diff --git a/src/utility/STM32_WPAN/shci.c b/src/utility/STM32_WPAN/shci.c index 40110f42..5c32555e 100644 --- a/src/utility/STM32_WPAN/shci.c +++ b/src/utility/STM32_WPAN/shci.c @@ -17,7 +17,6 @@ */ -#if defined(STM32WBxx) /* Includes ------------------------------------------------------------------*/ #include "stm32_wpan_common.h" @@ -760,4 +759,3 @@ SHCI_CmdStatus_t SHCI_GetWirelessFwInfo( WirelessFwInfo_t* pWirelessInfo ) return (SHCI_Success); } -#endif /* STM32WBxx */ diff --git a/src/utility/STM32_WPAN/shci_tl.c b/src/utility/STM32_WPAN/shci_tl.c index 25e1a214..0f604300 100644 --- a/src/utility/STM32_WPAN/shci_tl.c +++ b/src/utility/STM32_WPAN/shci_tl.c @@ -17,14 +17,11 @@ */ -#if defined(STM32WBxx) /* Includes ------------------------------------------------------------------*/ #include "stm32_wpan_common.h" #include "stm_list.h" #include "shci_tl.h" -#include "stm32_def.h" -#include "wiring_time.h" /* Private typedef -----------------------------------------------------------*/ typedef enum @@ -171,20 +168,6 @@ void shci_send( uint16_t cmd_code, uint8_t len_cmd_payload, uint8_t * p_cmd_payl return; } -void shci_notify_asynch_evt(void *pdata) -{ - UNUSED(pdata); - /* Need to parse data in future version */ - shci_user_evt_proc(); -} - -void shci_register_io_bus(tSHciIO *fops) -{ - /* Register IO bus services */ - fops->Init = TL_SYS_Init; - fops->Send = TL_SYS_SendCmd; -} - /* Private functions ---------------------------------------------------------*/ static void TlInit( TL_CmdPacket_t * p_cmdbuffer ) { @@ -252,11 +235,10 @@ static void TlUserEvtReceived(TL_EvtPacket_t *shcievt) /* Weak implementation ----------------------------------------------------------------*/ __WEAK void shci_cmd_resp_wait(uint32_t timeout) { - for (unsigned long start = millis(); (millis() - start) < timeout;) { - if (CmdRspStatusFlag == SHCI_TL_CMD_RESP_RELEASE) { - break; - } - } + (void)timeout; + + while(CmdRspStatusFlag != SHCI_TL_CMD_RESP_RELEASE); + return; } @@ -268,4 +250,3 @@ __WEAK void shci_cmd_resp_release(uint32_t flag) return; } -#endif /* STM32WBxx */ diff --git a/src/utility/STM32_WPAN/stm_list.c b/src/utility/STM32_WPAN/stm_list.c index df6c2155..4c928647 100644 --- a/src/utility/STM32_WPAN/stm_list.c +++ b/src/utility/STM32_WPAN/stm_list.c @@ -17,13 +17,10 @@ */ -#if defined(STM32WBxx) /****************************************************************************** * Include Files ******************************************************************************/ -#include "stdint.h" -#include "cmsis_gcc.h" -#include "stm32_wpan_common.h" +#include "utilities_common.h" #include "stm_list.h" @@ -207,4 +204,3 @@ void LST_get_prev_node (tListNode * ref_node, tListNode ** node) __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ } -#endif /* STM32WBxx */ diff --git a/src/utility/STM32_WPAN/tl.h b/src/utility/STM32_WPAN/tl.h index 74520878..8e8c6cbc 100644 --- a/src/utility/STM32_WPAN/tl.h +++ b/src/utility/STM32_WPAN/tl.h @@ -108,7 +108,7 @@ typedef PACKED_STRUCT { uint8_t evtcode; uint8_t plen; - uint8_t payload[4]; + uint8_t payload[2]; } TL_Evt_t; typedef PACKED_STRUCT diff --git a/src/utility/STM32_WPAN/tl_mbox.c b/src/utility/STM32_WPAN/tl_mbox.c index 40c96793..27a998a3 100644 --- a/src/utility/STM32_WPAN/tl_mbox.c +++ b/src/utility/STM32_WPAN/tl_mbox.c @@ -16,7 +16,6 @@ ****************************************************************************** */ -#if defined(STM32WBxx) /* Includes ------------------------------------------------------------------*/ #include "stm32_wpan_common.h" #include "hw.h" @@ -52,10 +51,8 @@ PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_BleLldTable_t TL_BleLldTable; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_SysTable_t TL_SysTable; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_MemManagerTable_t TL_MemManagerTable; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_TracesTable_t TL_TracesTable; -#if 0 PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_Mac_802_15_4_t TL_Mac_802_15_4_Table; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_ZigbeeTable_t TL_Zigbee_Table; -#endif /**< tables */ PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode FreeBufQueue; @@ -100,10 +97,8 @@ void TL_Init( void ) TL_RefTable.p_sys_table = &TL_SysTable; TL_RefTable.p_mem_manager_table = &TL_MemManagerTable; TL_RefTable.p_traces_table = &TL_TracesTable; -#if 0 TL_RefTable.p_mac_802_15_4_table = &TL_Mac_802_15_4_Table; TL_RefTable.p_zigbee_table = &TL_Zigbee_Table; -#endif HW_IPCC_Init(); return; @@ -851,4 +846,3 @@ static void OutputDbgTrace(TL_MB_PacketType_t packet_type, uint8_t* buffer) return; } -#endif /* STM32WBxx */ From 58702782d85c86009dc697d24b154e1039b0c353 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Wed, 10 Jan 2024 18:16:01 +0100 Subject: [PATCH 158/226] chore: adapt STM32_WPAN sources Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- src/utility/STM32_WPAN/app_conf_default.h | 49 +++++++++++++++++++---- src/utility/STM32_WPAN/hw.h | 13 +++++- src/utility/STM32_WPAN/hw_ipcc.c | 4 +- src/utility/STM32_WPAN/shci.c | 2 + src/utility/STM32_WPAN/shci_tl.c | 17 ++++++++ src/utility/STM32_WPAN/stm_list.c | 6 ++- src/utility/STM32_WPAN/tl_mbox.c | 6 +++ 7 files changed, 85 insertions(+), 12 deletions(-) diff --git a/src/utility/STM32_WPAN/app_conf_default.h b/src/utility/STM32_WPAN/app_conf_default.h index 846be3c9..6c9beb3b 100644 --- a/src/utility/STM32_WPAN/app_conf_default.h +++ b/src/utility/STM32_WPAN/app_conf_default.h @@ -1,9 +1,9 @@ /* USER CODE BEGIN Header */ /** ****************************************************************************** - * @file app_conf.h + * @file app_conf_default.h * @author MCD Application Team - * @brief Application configuration file for STM32WPAN Middleware. + * @brief Default application configuration file for STM32WPAN Middleware. ****************************************************************************** * @attention * @@ -19,18 +19,40 @@ /* USER CODE END Header */ /* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef APP_CONF_H -#define APP_CONF_H +#ifndef APP_CONF_DEFAULT_H +#define APP_CONF_DEFAULT_H +#if 0 #include "hw.h" #include "hw_conf.h" #include "hw_if.h" #include "ble_bufsize.h" +#endif /****************************************************************************** * Application Config ******************************************************************************/ +/**< generic parameters ******************************************************/ +/* HCI related defines */ + +#define ACI_HAL_SET_TX_POWER_LEVEL 0xFC0F +#define ACI_WRITE_CONFIG_DATA_OPCODE 0xFC0C +#define ACI_READ_CONFIG_DATA_OPCODE 0xFC0D +#define MAX_HCI_ACL_PACKET_SIZE (sizeof(TL_PacketHeader_t) + 5 + 251) +#define HCI_RESET 0x0C03 + +#ifndef BLE_SHARED_MEM_BYTE_ORDER + #define BLE_SHARED_MEM_BYTE_ORDER MSBFIRST +#endif +#define BLE_MODULE_SHARED_MEM_BUFFER_SIZE 128 + +/** + * Define Tx Power + */ +#define CFG_TX_POWER (0x18) /* -0.15dBm */ + +#if 0 /** * Define Secure Connections Support */ @@ -104,6 +126,7 @@ #define CFG_FW_SUBVERSION (1) #define CFG_FW_BRANCH (0) #define CFG_FW_BUILD (0) +#endif /****************************************************************************** * BLE Stack @@ -250,7 +273,7 @@ * 0: LE Power Class 2-3 * other bits: complete with Options_extension flag */ -#define CFG_BLE_OPTIONS (SHCI_C2_BLE_INIT_OPTIONS_LL_HOST | SHCI_C2_BLE_INIT_OPTIONS_WITH_SVC_CHANGE_DESC | SHCI_C2_BLE_INIT_OPTIONS_DEVICE_NAME_RW | SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV | SHCI_C2_BLE_INIT_OPTIONS_CS_ALGO2 | SHCI_C2_BLE_INIT_OPTIONS_FULL_GATTDB_NVM | SHCI_C2_BLE_INIT_OPTIONS_GATT_CACHING_NOTUSED | SHCI_C2_BLE_INIT_OPTIONS_POWER_CLASS_2_3) +#define CFG_BLE_OPTIONS (SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY | SHCI_C2_BLE_INIT_OPTIONS_WITH_SVC_CHANGE_DESC | SHCI_C2_BLE_INIT_OPTIONS_DEVICE_NAME_RW | SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV | SHCI_C2_BLE_INIT_OPTIONS_CS_ALGO2 | SHCI_C2_BLE_INIT_OPTIONS_FULL_GATTDB_NVM | SHCI_C2_BLE_INIT_OPTIONS_GATT_CACHING_NOTUSED | SHCI_C2_BLE_INIT_OPTIONS_POWER_CLASS_2_3) /** * BLE stack Options_extension flags to be configured with: @@ -292,7 +315,11 @@ * This parameter is considered by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV flag set */ -#define CFG_BLE_MAX_ADV_SET_NBR (8) +#if defined(STM32WB15xx) + #define CFG_BLE_MAX_ADV_SET_NBR (3) +#else + #define CFG_BLE_MAX_ADV_SET_NBR (8) +#endif /* Maximum advertising data length (in bytes) * Range: 31 .. 1650 with limitation: @@ -301,7 +328,11 @@ * This parameter is considered by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV flag set */ -#define CFG_BLE_MAX_ADV_DATA_LEN (207) +#if defined(STM32WB15xx) + #define CFG_BLE_MAX_ADV_DATA_LEN (414) +#else + #define CFG_BLE_MAX_ADV_DATA_LEN (207) +#endif /* RF TX Path Compensation Value (16-bit signed integer). Units: 0.1 dB. * Range: -1280 .. 1280 @@ -324,6 +355,7 @@ #define CFG_BLE_CORE_VERSION (SHCI_C2_BLE_INIT_BLE_CORE_5_4) +#if 0 /****************************************************************************** * Transport Layer ******************************************************************************/ @@ -659,4 +691,5 @@ typedef enum #define CFG_OTP_END_ADRESS OTP_AREA_END_ADDR -#endif /*APP_CONF_H */ +#endif +#endif /*APP_CONF_DEFAULT_H */ diff --git a/src/utility/STM32_WPAN/hw.h b/src/utility/STM32_WPAN/hw.h index 651e1f17..1472a5e8 100644 --- a/src/utility/STM32_WPAN/hw.h +++ b/src/utility/STM32_WPAN/hw.h @@ -26,14 +26,23 @@ extern "C" { #endif /* Includes ------------------------------------------------------------------*/ +#include "stm32_def.h" +#include "stm32wbxx_ll_bus.h" +#include "stm32wbxx_ll_exti.h" +#include "stm32wbxx_ll_system.h" +#include "stm32wbxx_ll_rcc.h" +#include "stm32wbxx_ll_ipcc.h" +#include "stm32wbxx_ll_cortex.h" +#include "stm32wbxx_ll_utils.h" +#include "stm32wbxx_ll_pwr.h" /****************************************************************************** * HW IPCC ******************************************************************************/ void HW_IPCC_Enable( void ); void HW_IPCC_Init( void ); - void HW_IPCC_Rx_Handler( void ); - void HW_IPCC_Tx_Handler( void ); +#define HW_IPCC_Rx_Handler IPCC_C1_RX_IRQHandler +#define HW_IPCC_Tx_Handler IPCC_C1_TX_IRQHandler void HW_IPCC_BLE_Init( void ); void HW_IPCC_BLE_SendCmd( void ); diff --git a/src/utility/STM32_WPAN/hw_ipcc.c b/src/utility/STM32_WPAN/hw_ipcc.c index fd620b85..3461cbed 100644 --- a/src/utility/STM32_WPAN/hw_ipcc.c +++ b/src/utility/STM32_WPAN/hw_ipcc.c @@ -18,8 +18,9 @@ */ /* USER CODE END Header */ +#if defined(STM32WBxx) /* Includes ------------------------------------------------------------------*/ -#include "app_common.h" +#include "hw.h" #include "mbox_def.h" /* Global variables ---------------------------------------------------------*/ @@ -667,3 +668,4 @@ static void HW_IPCC_TRACES_EvtHandler( void ) } __weak void HW_IPCC_TRACES_EvtNot( void ){}; +#endif /* STM32WBxx */ diff --git a/src/utility/STM32_WPAN/shci.c b/src/utility/STM32_WPAN/shci.c index 5c32555e..40110f42 100644 --- a/src/utility/STM32_WPAN/shci.c +++ b/src/utility/STM32_WPAN/shci.c @@ -17,6 +17,7 @@ */ +#if defined(STM32WBxx) /* Includes ------------------------------------------------------------------*/ #include "stm32_wpan_common.h" @@ -759,3 +760,4 @@ SHCI_CmdStatus_t SHCI_GetWirelessFwInfo( WirelessFwInfo_t* pWirelessInfo ) return (SHCI_Success); } +#endif /* STM32WBxx */ diff --git a/src/utility/STM32_WPAN/shci_tl.c b/src/utility/STM32_WPAN/shci_tl.c index 0f604300..daa988c1 100644 --- a/src/utility/STM32_WPAN/shci_tl.c +++ b/src/utility/STM32_WPAN/shci_tl.c @@ -17,11 +17,13 @@ */ +#if defined(STM32WBxx) /* Includes ------------------------------------------------------------------*/ #include "stm32_wpan_common.h" #include "stm_list.h" #include "shci_tl.h" +#include "stm32_def.h" /* Private typedef -----------------------------------------------------------*/ typedef enum @@ -168,6 +170,20 @@ void shci_send( uint16_t cmd_code, uint8_t len_cmd_payload, uint8_t * p_cmd_payl return; } +void shci_notify_asynch_evt(void *pdata) +{ + UNUSED(pdata); + /* Need to parse data in future version */ + shci_user_evt_proc(); +} + +void shci_register_io_bus(tSHciIO *fops) +{ + /* Register IO bus services */ + fops->Init = TL_SYS_Init; + fops->Send = TL_SYS_SendCmd; +} + /* Private functions ---------------------------------------------------------*/ static void TlInit( TL_CmdPacket_t * p_cmdbuffer ) { @@ -250,3 +266,4 @@ __WEAK void shci_cmd_resp_release(uint32_t flag) return; } +#endif /* STM32WBxx */ diff --git a/src/utility/STM32_WPAN/stm_list.c b/src/utility/STM32_WPAN/stm_list.c index 4c928647..df6c2155 100644 --- a/src/utility/STM32_WPAN/stm_list.c +++ b/src/utility/STM32_WPAN/stm_list.c @@ -17,10 +17,13 @@ */ +#if defined(STM32WBxx) /****************************************************************************** * Include Files ******************************************************************************/ -#include "utilities_common.h" +#include "stdint.h" +#include "cmsis_gcc.h" +#include "stm32_wpan_common.h" #include "stm_list.h" @@ -204,3 +207,4 @@ void LST_get_prev_node (tListNode * ref_node, tListNode ** node) __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ } +#endif /* STM32WBxx */ diff --git a/src/utility/STM32_WPAN/tl_mbox.c b/src/utility/STM32_WPAN/tl_mbox.c index 27a998a3..40c96793 100644 --- a/src/utility/STM32_WPAN/tl_mbox.c +++ b/src/utility/STM32_WPAN/tl_mbox.c @@ -16,6 +16,7 @@ ****************************************************************************** */ +#if defined(STM32WBxx) /* Includes ------------------------------------------------------------------*/ #include "stm32_wpan_common.h" #include "hw.h" @@ -51,8 +52,10 @@ PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_BleLldTable_t TL_BleLldTable; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_SysTable_t TL_SysTable; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_MemManagerTable_t TL_MemManagerTable; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_TracesTable_t TL_TracesTable; +#if 0 PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_Mac_802_15_4_t TL_Mac_802_15_4_Table; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_ZigbeeTable_t TL_Zigbee_Table; +#endif /**< tables */ PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode FreeBufQueue; @@ -97,8 +100,10 @@ void TL_Init( void ) TL_RefTable.p_sys_table = &TL_SysTable; TL_RefTable.p_mem_manager_table = &TL_MemManagerTable; TL_RefTable.p_traces_table = &TL_TracesTable; +#if 0 TL_RefTable.p_mac_802_15_4_table = &TL_Mac_802_15_4_Table; TL_RefTable.p_zigbee_table = &TL_Zigbee_Table; +#endif HW_IPCC_Init(); return; @@ -846,3 +851,4 @@ static void OutputDbgTrace(TL_MB_PacketType_t packet_type, uint8_t* buffer) return; } +#endif /* STM32WBxx */ From 69c51f95d77376311e8cd0a993f9e60851cb4a00 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Thu, 13 Jul 2023 17:16:40 +0200 Subject: [PATCH 159/226] fix: include a timeout when waiting for the cmd_resp Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- src/utility/STM32_WPAN/shci_tl.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/utility/STM32_WPAN/shci_tl.c b/src/utility/STM32_WPAN/shci_tl.c index daa988c1..25e1a214 100644 --- a/src/utility/STM32_WPAN/shci_tl.c +++ b/src/utility/STM32_WPAN/shci_tl.c @@ -24,6 +24,7 @@ #include "stm_list.h" #include "shci_tl.h" #include "stm32_def.h" +#include "wiring_time.h" /* Private typedef -----------------------------------------------------------*/ typedef enum @@ -251,10 +252,11 @@ static void TlUserEvtReceived(TL_EvtPacket_t *shcievt) /* Weak implementation ----------------------------------------------------------------*/ __WEAK void shci_cmd_resp_wait(uint32_t timeout) { - (void)timeout; - - while(CmdRspStatusFlag != SHCI_TL_CMD_RESP_RELEASE); - + for (unsigned long start = millis(); (millis() - start) < timeout;) { + if (CmdRspStatusFlag == SHCI_TL_CMD_RESP_RELEASE) { + break; + } + } return; } From 414683d635c5a08e1f0fe761da6cbeaba82c193a Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Wed, 10 Jan 2024 18:45:17 +0100 Subject: [PATCH 160/226] chore: add support for customize app_conf_default.h Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- src/utility/STM32_WPAN/app_conf_default.h | 58 ++++++++++++++++++----- 1 file changed, 45 insertions(+), 13 deletions(-) diff --git a/src/utility/STM32_WPAN/app_conf_default.h b/src/utility/STM32_WPAN/app_conf_default.h index 6c9beb3b..9509a0f5 100644 --- a/src/utility/STM32_WPAN/app_conf_default.h +++ b/src/utility/STM32_WPAN/app_conf_default.h @@ -50,7 +50,9 @@ /** * Define Tx Power */ -#define CFG_TX_POWER (0x18) /* -0.15dBm */ +#ifndef CFG_TX_POWER + #define CFG_TX_POWER (0x18) /* -0.15dBm */ +#endif #if 0 /** @@ -135,13 +137,25 @@ * Maximum number of simultaneous connections that the device will support. * Valid values are from 1 to 8 */ -#define CFG_BLE_NUM_LINK 8 +#ifndef CFG_BLE_NUM_LINK +#ifdef STM32WB15xx + #define CFG_BLE_NUM_LINK 3 +#else + #define CFG_BLE_NUM_LINK 8 +#endif +#endif /** * Maximum number of Services that can be stored in the GATT database. * Note that the GAP and GATT services are automatically added so this parameter should be 2 plus the number of user services */ -#define CFG_BLE_NUM_GATT_SERVICES 8 +#ifndef CFG_BLE_NUM_GATT_SERVICES +#ifdef STM32WB15xx + #define CFG_BLE_NUM_GATT_SERVICES 4 +#else + #define CFG_BLE_NUM_GATT_SERVICES 8 +#endif +#endif /** * Maximum number of Attributes @@ -150,7 +164,13 @@ * Note that certain characteristics and relative descriptors are added automatically during device initialization * so this parameters should be 9 plus the number of user Attributes */ -#define CFG_BLE_NUM_GATT_ATTRIBUTES 68 +#ifndef CFG_BLE_NUM_GATT_ATTRIBUTES +#ifdef STM32WB15xx + #define CFG_BLE_NUM_GATT_ATTRIBUTES 30 +#else + #define CFG_BLE_NUM_GATT_ATTRIBUTES 68 +#endif +#endif /** * Maximum supported ATT_MTU size @@ -186,12 +206,16 @@ /** * Enable or disable the Extended Packet length feature. Valid values are 0 or 1. */ -#define CFG_BLE_DATA_LENGTH_EXTENSION 1 +#ifndef CFG_BLE_DATA_LENGTH_EXTENSION + #define CFG_BLE_DATA_LENGTH_EXTENSION 1 +#endif /** * Sleep clock accuracy in Peripheral mode (ppm value) */ -#define CFG_BLE_PERIPHERAL_SCA 500 +#ifndef CFG_BLE_PERIPHERAL_SCA + #define CFG_BLE_PERIPHERAL_SCA 500 +#endif /** * Sleep clock accuracy in Central mode @@ -204,7 +228,9 @@ * 6 : 21 ppm to 30 ppm * 7 : 0 ppm to 20 ppm */ -#define CFG_BLE_CENTRAL_SCA 0 +#ifndef CFG_BLE_CENTRAL_SCA + #define CFG_BLE_CENTRAL_SCA 0 +#endif /** * LsSource @@ -213,21 +239,27 @@ * - bit 1: 1: STM32WB5M Module device 0: Other devices as STM32WBxx SOC, STM32WB1M module * - bit 2: 1: HSE/1024 Clock config 0: LSE Clock config */ -#if defined(STM32WB5Mxx) - #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_MOD5MM_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) -#else - #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_OTHER_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) +#ifndef CFG_BLE_LS_SOURCE + #if defined(STM32WB5Mxx) + #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_MOD5MM_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) + #else + #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_OTHER_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) + #endif #endif /** * Start up time of the high speed (16 or 32 MHz) crystal oscillator in units of 625/256 us (~2.44 us) */ -#define CFG_BLE_HSE_STARTUP_TIME 0x148 +#ifndef CFG_BLE_HSE_STARTUP_TIME + #define CFG_BLE_HSE_STARTUP_TIME 0x148 +#endif /** * Maximum duration of the connection event when the device is in Peripheral mode in units of 625/256 us (~2.44 us) */ -#define CFG_BLE_MAX_CONN_EVENT_LENGTH (0xFFFFFFFF) +#ifndef CFG_BLE_MAX_CONN_EVENT_LENGTH + #define CFG_BLE_MAX_CONN_EVENT_LENGTH (0xFFFFFFFF) +#endif /** * Viterbi Mode From 50bd468a924411fb35500003f56918853a3649aa Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Mon, 24 Jul 2023 10:55:20 +0200 Subject: [PATCH 161/226] fix: TL_Evt_t payload size for reset Within STM32CubeWB v1.17.0 update TL_Evt_t payload size was reduced. This produce a warning -Warray-bounds due to the reset management which require 4 bytes. Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- src/utility/STM32_WPAN/tl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utility/STM32_WPAN/tl.h b/src/utility/STM32_WPAN/tl.h index 8e8c6cbc..74520878 100644 --- a/src/utility/STM32_WPAN/tl.h +++ b/src/utility/STM32_WPAN/tl.h @@ -108,7 +108,7 @@ typedef PACKED_STRUCT { uint8_t evtcode; uint8_t plen; - uint8_t payload[2]; + uint8_t payload[4]; } TL_Evt_t; typedef PACKED_STRUCT From da08a10197dfa77f1c25e28808c6db2603c178cf Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Mon, 8 Jul 2024 11:18:40 +0200 Subject: [PATCH 162/226] chore: update library.properties Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index bebbdf56..6f0833c7 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=STM32duinoBLE -version=1.2.7 +version=1.2.8 author=Arduino, SRA maintainer=stm32duino sentence=Fork of ArduinoBLE library to add the support of STM32WB, SPBTLE-RF, SPBTLE-1S, BLUENRG-M2SP and BLUENRG-M0 BLE modules. From 65091a90f3a15557e7adb78be9f2909818cbc245 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Fri, 5 Jul 2024 15:53:04 +0200 Subject: [PATCH 163/226] chore: update STM32_WPAN from Cube version v1.20.0 Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- src/utility/STM32_WPAN/README.md | 4 +- src/utility/STM32_WPAN/app_conf_default.h | 105 +++++----------------- src/utility/STM32_WPAN/ble_bufsize.h | 4 +- src/utility/STM32_WPAN/hw.h | 13 +-- src/utility/STM32_WPAN/hw_ipcc.c | 4 +- src/utility/STM32_WPAN/shci.c | 2 - src/utility/STM32_WPAN/shci.h | 5 +- src/utility/STM32_WPAN/shci_tl.c | 27 +----- src/utility/STM32_WPAN/stm_list.c | 6 +- src/utility/STM32_WPAN/tl.h | 2 +- src/utility/STM32_WPAN/tl_mbox.c | 6 -- 11 files changed, 37 insertions(+), 141 deletions(-) diff --git a/src/utility/STM32_WPAN/README.md b/src/utility/STM32_WPAN/README.md index b8b7d7ed..f50589ee 100644 --- a/src/utility/STM32_WPAN/README.md +++ b/src/utility/STM32_WPAN/README.md @@ -1,6 +1,6 @@ ## Source -[STMicroelectronics/STM32CubeWB Release v1.19.0](https://github.com/STMicroelectronics/STM32CubeWB/releases/tag/v1.19.0) -- Application: [BLE_TransparentMode](https://github.com/STMicroelectronics/STM32CubeWB/tree/v1.19.0/Projects/P-NUCLEO-WB55.Nucleo/Applications/BLE/BLE_TransparentMode) +[STMicroelectronics/STM32CubeWB Release v1.20.0](https://github.com/STMicroelectronics/STM32CubeWB/releases/tag/v1.20.0) +- Application: [BLE_TransparentMode](https://github.com/STMicroelectronics/STM32CubeWB/tree/v1.20.0/Projects/P-NUCLEO-WB55.Nucleo/Applications/BLE/BLE_TransparentMode) diff --git a/src/utility/STM32_WPAN/app_conf_default.h b/src/utility/STM32_WPAN/app_conf_default.h index 9509a0f5..846be3c9 100644 --- a/src/utility/STM32_WPAN/app_conf_default.h +++ b/src/utility/STM32_WPAN/app_conf_default.h @@ -1,9 +1,9 @@ /* USER CODE BEGIN Header */ /** ****************************************************************************** - * @file app_conf_default.h + * @file app_conf.h * @author MCD Application Team - * @brief Default application configuration file for STM32WPAN Middleware. + * @brief Application configuration file for STM32WPAN Middleware. ****************************************************************************** * @attention * @@ -19,42 +19,18 @@ /* USER CODE END Header */ /* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef APP_CONF_DEFAULT_H -#define APP_CONF_DEFAULT_H +#ifndef APP_CONF_H +#define APP_CONF_H -#if 0 #include "hw.h" #include "hw_conf.h" #include "hw_if.h" #include "ble_bufsize.h" -#endif /****************************************************************************** * Application Config ******************************************************************************/ -/**< generic parameters ******************************************************/ -/* HCI related defines */ - -#define ACI_HAL_SET_TX_POWER_LEVEL 0xFC0F -#define ACI_WRITE_CONFIG_DATA_OPCODE 0xFC0C -#define ACI_READ_CONFIG_DATA_OPCODE 0xFC0D -#define MAX_HCI_ACL_PACKET_SIZE (sizeof(TL_PacketHeader_t) + 5 + 251) -#define HCI_RESET 0x0C03 - -#ifndef BLE_SHARED_MEM_BYTE_ORDER - #define BLE_SHARED_MEM_BYTE_ORDER MSBFIRST -#endif -#define BLE_MODULE_SHARED_MEM_BUFFER_SIZE 128 - -/** - * Define Tx Power - */ -#ifndef CFG_TX_POWER - #define CFG_TX_POWER (0x18) /* -0.15dBm */ -#endif - -#if 0 /** * Define Secure Connections Support */ @@ -128,7 +104,6 @@ #define CFG_FW_SUBVERSION (1) #define CFG_FW_BRANCH (0) #define CFG_FW_BUILD (0) -#endif /****************************************************************************** * BLE Stack @@ -137,25 +112,13 @@ * Maximum number of simultaneous connections that the device will support. * Valid values are from 1 to 8 */ -#ifndef CFG_BLE_NUM_LINK -#ifdef STM32WB15xx - #define CFG_BLE_NUM_LINK 3 -#else - #define CFG_BLE_NUM_LINK 8 -#endif -#endif +#define CFG_BLE_NUM_LINK 8 /** * Maximum number of Services that can be stored in the GATT database. * Note that the GAP and GATT services are automatically added so this parameter should be 2 plus the number of user services */ -#ifndef CFG_BLE_NUM_GATT_SERVICES -#ifdef STM32WB15xx - #define CFG_BLE_NUM_GATT_SERVICES 4 -#else - #define CFG_BLE_NUM_GATT_SERVICES 8 -#endif -#endif +#define CFG_BLE_NUM_GATT_SERVICES 8 /** * Maximum number of Attributes @@ -164,13 +127,7 @@ * Note that certain characteristics and relative descriptors are added automatically during device initialization * so this parameters should be 9 plus the number of user Attributes */ -#ifndef CFG_BLE_NUM_GATT_ATTRIBUTES -#ifdef STM32WB15xx - #define CFG_BLE_NUM_GATT_ATTRIBUTES 30 -#else - #define CFG_BLE_NUM_GATT_ATTRIBUTES 68 -#endif -#endif +#define CFG_BLE_NUM_GATT_ATTRIBUTES 68 /** * Maximum supported ATT_MTU size @@ -206,16 +163,12 @@ /** * Enable or disable the Extended Packet length feature. Valid values are 0 or 1. */ -#ifndef CFG_BLE_DATA_LENGTH_EXTENSION - #define CFG_BLE_DATA_LENGTH_EXTENSION 1 -#endif +#define CFG_BLE_DATA_LENGTH_EXTENSION 1 /** * Sleep clock accuracy in Peripheral mode (ppm value) */ -#ifndef CFG_BLE_PERIPHERAL_SCA - #define CFG_BLE_PERIPHERAL_SCA 500 -#endif +#define CFG_BLE_PERIPHERAL_SCA 500 /** * Sleep clock accuracy in Central mode @@ -228,9 +181,7 @@ * 6 : 21 ppm to 30 ppm * 7 : 0 ppm to 20 ppm */ -#ifndef CFG_BLE_CENTRAL_SCA - #define CFG_BLE_CENTRAL_SCA 0 -#endif +#define CFG_BLE_CENTRAL_SCA 0 /** * LsSource @@ -239,27 +190,21 @@ * - bit 1: 1: STM32WB5M Module device 0: Other devices as STM32WBxx SOC, STM32WB1M module * - bit 2: 1: HSE/1024 Clock config 0: LSE Clock config */ -#ifndef CFG_BLE_LS_SOURCE - #if defined(STM32WB5Mxx) - #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_MOD5MM_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) - #else - #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_OTHER_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) - #endif +#if defined(STM32WB5Mxx) + #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_MOD5MM_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) +#else + #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_OTHER_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) #endif /** * Start up time of the high speed (16 or 32 MHz) crystal oscillator in units of 625/256 us (~2.44 us) */ -#ifndef CFG_BLE_HSE_STARTUP_TIME - #define CFG_BLE_HSE_STARTUP_TIME 0x148 -#endif +#define CFG_BLE_HSE_STARTUP_TIME 0x148 /** * Maximum duration of the connection event when the device is in Peripheral mode in units of 625/256 us (~2.44 us) */ -#ifndef CFG_BLE_MAX_CONN_EVENT_LENGTH - #define CFG_BLE_MAX_CONN_EVENT_LENGTH (0xFFFFFFFF) -#endif +#define CFG_BLE_MAX_CONN_EVENT_LENGTH (0xFFFFFFFF) /** * Viterbi Mode @@ -305,7 +250,7 @@ * 0: LE Power Class 2-3 * other bits: complete with Options_extension flag */ -#define CFG_BLE_OPTIONS (SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY | SHCI_C2_BLE_INIT_OPTIONS_WITH_SVC_CHANGE_DESC | SHCI_C2_BLE_INIT_OPTIONS_DEVICE_NAME_RW | SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV | SHCI_C2_BLE_INIT_OPTIONS_CS_ALGO2 | SHCI_C2_BLE_INIT_OPTIONS_FULL_GATTDB_NVM | SHCI_C2_BLE_INIT_OPTIONS_GATT_CACHING_NOTUSED | SHCI_C2_BLE_INIT_OPTIONS_POWER_CLASS_2_3) +#define CFG_BLE_OPTIONS (SHCI_C2_BLE_INIT_OPTIONS_LL_HOST | SHCI_C2_BLE_INIT_OPTIONS_WITH_SVC_CHANGE_DESC | SHCI_C2_BLE_INIT_OPTIONS_DEVICE_NAME_RW | SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV | SHCI_C2_BLE_INIT_OPTIONS_CS_ALGO2 | SHCI_C2_BLE_INIT_OPTIONS_FULL_GATTDB_NVM | SHCI_C2_BLE_INIT_OPTIONS_GATT_CACHING_NOTUSED | SHCI_C2_BLE_INIT_OPTIONS_POWER_CLASS_2_3) /** * BLE stack Options_extension flags to be configured with: @@ -347,11 +292,7 @@ * This parameter is considered by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV flag set */ -#if defined(STM32WB15xx) - #define CFG_BLE_MAX_ADV_SET_NBR (3) -#else - #define CFG_BLE_MAX_ADV_SET_NBR (8) -#endif +#define CFG_BLE_MAX_ADV_SET_NBR (8) /* Maximum advertising data length (in bytes) * Range: 31 .. 1650 with limitation: @@ -360,11 +301,7 @@ * This parameter is considered by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV flag set */ -#if defined(STM32WB15xx) - #define CFG_BLE_MAX_ADV_DATA_LEN (414) -#else - #define CFG_BLE_MAX_ADV_DATA_LEN (207) -#endif +#define CFG_BLE_MAX_ADV_DATA_LEN (207) /* RF TX Path Compensation Value (16-bit signed integer). Units: 0.1 dB. * Range: -1280 .. 1280 @@ -387,7 +324,6 @@ #define CFG_BLE_CORE_VERSION (SHCI_C2_BLE_INIT_BLE_CORE_5_4) -#if 0 /****************************************************************************** * Transport Layer ******************************************************************************/ @@ -723,5 +659,4 @@ typedef enum #define CFG_OTP_END_ADRESS OTP_AREA_END_ADDR -#endif -#endif /*APP_CONF_DEFAULT_H */ +#endif /*APP_CONF_H */ diff --git a/src/utility/STM32_WPAN/ble_bufsize.h b/src/utility/STM32_WPAN/ble_bufsize.h index 66cc2a5a..c5018420 100644 --- a/src/utility/STM32_WPAN/ble_bufsize.h +++ b/src/utility/STM32_WPAN/ble_bufsize.h @@ -1,6 +1,6 @@ /***************************************************************************** * @file ble_bufsize.h - * @author MDG + * * @brief Definition of BLE stack buffers size ***************************************************************************** * @attention @@ -49,7 +49,7 @@ */ #define BLE_MEM_BLOCK_SIZE 32 -#if (SLAVE_ONLY != 0) ||(BASIC_FEATURES != 0) +#if (SLAVE_ONLY != 0) || (BASIC_FEATURES != 0) #define BLE_MEM_BLOCK_X_PTX(n_link) 0 #else #define BLE_MEM_BLOCK_X_PTX(n_link) (n_link) diff --git a/src/utility/STM32_WPAN/hw.h b/src/utility/STM32_WPAN/hw.h index 1472a5e8..651e1f17 100644 --- a/src/utility/STM32_WPAN/hw.h +++ b/src/utility/STM32_WPAN/hw.h @@ -26,23 +26,14 @@ extern "C" { #endif /* Includes ------------------------------------------------------------------*/ -#include "stm32_def.h" -#include "stm32wbxx_ll_bus.h" -#include "stm32wbxx_ll_exti.h" -#include "stm32wbxx_ll_system.h" -#include "stm32wbxx_ll_rcc.h" -#include "stm32wbxx_ll_ipcc.h" -#include "stm32wbxx_ll_cortex.h" -#include "stm32wbxx_ll_utils.h" -#include "stm32wbxx_ll_pwr.h" /****************************************************************************** * HW IPCC ******************************************************************************/ void HW_IPCC_Enable( void ); void HW_IPCC_Init( void ); -#define HW_IPCC_Rx_Handler IPCC_C1_RX_IRQHandler -#define HW_IPCC_Tx_Handler IPCC_C1_TX_IRQHandler + void HW_IPCC_Rx_Handler( void ); + void HW_IPCC_Tx_Handler( void ); void HW_IPCC_BLE_Init( void ); void HW_IPCC_BLE_SendCmd( void ); diff --git a/src/utility/STM32_WPAN/hw_ipcc.c b/src/utility/STM32_WPAN/hw_ipcc.c index 3461cbed..fd620b85 100644 --- a/src/utility/STM32_WPAN/hw_ipcc.c +++ b/src/utility/STM32_WPAN/hw_ipcc.c @@ -18,9 +18,8 @@ */ /* USER CODE END Header */ -#if defined(STM32WBxx) /* Includes ------------------------------------------------------------------*/ -#include "hw.h" +#include "app_common.h" #include "mbox_def.h" /* Global variables ---------------------------------------------------------*/ @@ -668,4 +667,3 @@ static void HW_IPCC_TRACES_EvtHandler( void ) } __weak void HW_IPCC_TRACES_EvtNot( void ){}; -#endif /* STM32WBxx */ diff --git a/src/utility/STM32_WPAN/shci.c b/src/utility/STM32_WPAN/shci.c index 40110f42..5c32555e 100644 --- a/src/utility/STM32_WPAN/shci.c +++ b/src/utility/STM32_WPAN/shci.c @@ -17,7 +17,6 @@ */ -#if defined(STM32WBxx) /* Includes ------------------------------------------------------------------*/ #include "stm32_wpan_common.h" @@ -760,4 +759,3 @@ SHCI_CmdStatus_t SHCI_GetWirelessFwInfo( WirelessFwInfo_t* pWirelessInfo ) return (SHCI_Success); } -#endif /* STM32WBxx */ diff --git a/src/utility/STM32_WPAN/shci.h b/src/utility/STM32_WPAN/shci.h index 30ae10cb..59c6fd46 100644 --- a/src/utility/STM32_WPAN/shci.h +++ b/src/utility/STM32_WPAN/shci.h @@ -882,6 +882,7 @@ extern "C" { #define SHCI_C2_CONFIG_CONFIG1_BIT0_BLE_NVM_DATA_TO_SRAM (1<<0) #define SHCI_C2_CONFIG_CONFIG1_BIT1_THREAD_NVM_DATA_TO_INTERNAL_FLASH (0<<1) #define SHCI_C2_CONFIG_CONFIG1_BIT1_THREAD_NVM_DATA_TO_SRAM (1<<1) +#define SHCI_C2_CONFIG_CONFIG1_BIT2_SET_EUI64_FORMAT (1<<2) /** * EvtMask1 @@ -1340,7 +1341,9 @@ typedef struct { * 1 - BLE NVM Data are written in SRAM cache pointed by BleNvmRamAddress * - bit1 : 0 - THREAD NVM Data data are flushed in internal secure flash * 1 - THREAD NVM Data are written in SRAM cache pointed by ThreadNvmRamAddress - * - bit2 to bit7 : Unused, shall be set to 0 + * - bit2 : 0 - Thread EUI64 is set to new (and current) format + * 1 - Thread EUI64 is set to old format + * - bit3 to bit7 : Unused, shall be set to 0 * uint8_t EvtMask1 : * When a bit is set to 0, the event is not reported * bit0 : Asynchronous Event with Sub Evt Code 0x9201 (= SHCI_SUB_EVT_ERROR_NOTIF) diff --git a/src/utility/STM32_WPAN/shci_tl.c b/src/utility/STM32_WPAN/shci_tl.c index 25e1a214..0f604300 100644 --- a/src/utility/STM32_WPAN/shci_tl.c +++ b/src/utility/STM32_WPAN/shci_tl.c @@ -17,14 +17,11 @@ */ -#if defined(STM32WBxx) /* Includes ------------------------------------------------------------------*/ #include "stm32_wpan_common.h" #include "stm_list.h" #include "shci_tl.h" -#include "stm32_def.h" -#include "wiring_time.h" /* Private typedef -----------------------------------------------------------*/ typedef enum @@ -171,20 +168,6 @@ void shci_send( uint16_t cmd_code, uint8_t len_cmd_payload, uint8_t * p_cmd_payl return; } -void shci_notify_asynch_evt(void *pdata) -{ - UNUSED(pdata); - /* Need to parse data in future version */ - shci_user_evt_proc(); -} - -void shci_register_io_bus(tSHciIO *fops) -{ - /* Register IO bus services */ - fops->Init = TL_SYS_Init; - fops->Send = TL_SYS_SendCmd; -} - /* Private functions ---------------------------------------------------------*/ static void TlInit( TL_CmdPacket_t * p_cmdbuffer ) { @@ -252,11 +235,10 @@ static void TlUserEvtReceived(TL_EvtPacket_t *shcievt) /* Weak implementation ----------------------------------------------------------------*/ __WEAK void shci_cmd_resp_wait(uint32_t timeout) { - for (unsigned long start = millis(); (millis() - start) < timeout;) { - if (CmdRspStatusFlag == SHCI_TL_CMD_RESP_RELEASE) { - break; - } - } + (void)timeout; + + while(CmdRspStatusFlag != SHCI_TL_CMD_RESP_RELEASE); + return; } @@ -268,4 +250,3 @@ __WEAK void shci_cmd_resp_release(uint32_t flag) return; } -#endif /* STM32WBxx */ diff --git a/src/utility/STM32_WPAN/stm_list.c b/src/utility/STM32_WPAN/stm_list.c index df6c2155..4c928647 100644 --- a/src/utility/STM32_WPAN/stm_list.c +++ b/src/utility/STM32_WPAN/stm_list.c @@ -17,13 +17,10 @@ */ -#if defined(STM32WBxx) /****************************************************************************** * Include Files ******************************************************************************/ -#include "stdint.h" -#include "cmsis_gcc.h" -#include "stm32_wpan_common.h" +#include "utilities_common.h" #include "stm_list.h" @@ -207,4 +204,3 @@ void LST_get_prev_node (tListNode * ref_node, tListNode ** node) __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ } -#endif /* STM32WBxx */ diff --git a/src/utility/STM32_WPAN/tl.h b/src/utility/STM32_WPAN/tl.h index 74520878..8e8c6cbc 100644 --- a/src/utility/STM32_WPAN/tl.h +++ b/src/utility/STM32_WPAN/tl.h @@ -108,7 +108,7 @@ typedef PACKED_STRUCT { uint8_t evtcode; uint8_t plen; - uint8_t payload[4]; + uint8_t payload[2]; } TL_Evt_t; typedef PACKED_STRUCT diff --git a/src/utility/STM32_WPAN/tl_mbox.c b/src/utility/STM32_WPAN/tl_mbox.c index 40c96793..27a998a3 100644 --- a/src/utility/STM32_WPAN/tl_mbox.c +++ b/src/utility/STM32_WPAN/tl_mbox.c @@ -16,7 +16,6 @@ ****************************************************************************** */ -#if defined(STM32WBxx) /* Includes ------------------------------------------------------------------*/ #include "stm32_wpan_common.h" #include "hw.h" @@ -52,10 +51,8 @@ PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_BleLldTable_t TL_BleLldTable; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_SysTable_t TL_SysTable; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_MemManagerTable_t TL_MemManagerTable; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_TracesTable_t TL_TracesTable; -#if 0 PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_Mac_802_15_4_t TL_Mac_802_15_4_Table; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_ZigbeeTable_t TL_Zigbee_Table; -#endif /**< tables */ PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode FreeBufQueue; @@ -100,10 +97,8 @@ void TL_Init( void ) TL_RefTable.p_sys_table = &TL_SysTable; TL_RefTable.p_mem_manager_table = &TL_MemManagerTable; TL_RefTable.p_traces_table = &TL_TracesTable; -#if 0 TL_RefTable.p_mac_802_15_4_table = &TL_Mac_802_15_4_Table; TL_RefTable.p_zigbee_table = &TL_Zigbee_Table; -#endif HW_IPCC_Init(); return; @@ -851,4 +846,3 @@ static void OutputDbgTrace(TL_MB_PacketType_t packet_type, uint8_t* buffer) return; } -#endif /* STM32WBxx */ From 8ceb243a658457a9c26e1c23a6f9e2546b0fe6dd Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Wed, 10 Jan 2024 18:16:01 +0100 Subject: [PATCH 164/226] chore: adapt STM32_WPAN sources Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- src/utility/STM32_WPAN/app_conf_default.h | 49 +++++++++++++++++++---- src/utility/STM32_WPAN/hw.h | 13 +++++- src/utility/STM32_WPAN/hw_ipcc.c | 4 +- src/utility/STM32_WPAN/shci.c | 2 + src/utility/STM32_WPAN/shci_tl.c | 17 ++++++++ src/utility/STM32_WPAN/stm_list.c | 6 ++- src/utility/STM32_WPAN/tl_mbox.c | 6 +++ 7 files changed, 85 insertions(+), 12 deletions(-) diff --git a/src/utility/STM32_WPAN/app_conf_default.h b/src/utility/STM32_WPAN/app_conf_default.h index 846be3c9..6c9beb3b 100644 --- a/src/utility/STM32_WPAN/app_conf_default.h +++ b/src/utility/STM32_WPAN/app_conf_default.h @@ -1,9 +1,9 @@ /* USER CODE BEGIN Header */ /** ****************************************************************************** - * @file app_conf.h + * @file app_conf_default.h * @author MCD Application Team - * @brief Application configuration file for STM32WPAN Middleware. + * @brief Default application configuration file for STM32WPAN Middleware. ****************************************************************************** * @attention * @@ -19,18 +19,40 @@ /* USER CODE END Header */ /* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef APP_CONF_H -#define APP_CONF_H +#ifndef APP_CONF_DEFAULT_H +#define APP_CONF_DEFAULT_H +#if 0 #include "hw.h" #include "hw_conf.h" #include "hw_if.h" #include "ble_bufsize.h" +#endif /****************************************************************************** * Application Config ******************************************************************************/ +/**< generic parameters ******************************************************/ +/* HCI related defines */ + +#define ACI_HAL_SET_TX_POWER_LEVEL 0xFC0F +#define ACI_WRITE_CONFIG_DATA_OPCODE 0xFC0C +#define ACI_READ_CONFIG_DATA_OPCODE 0xFC0D +#define MAX_HCI_ACL_PACKET_SIZE (sizeof(TL_PacketHeader_t) + 5 + 251) +#define HCI_RESET 0x0C03 + +#ifndef BLE_SHARED_MEM_BYTE_ORDER + #define BLE_SHARED_MEM_BYTE_ORDER MSBFIRST +#endif +#define BLE_MODULE_SHARED_MEM_BUFFER_SIZE 128 + +/** + * Define Tx Power + */ +#define CFG_TX_POWER (0x18) /* -0.15dBm */ + +#if 0 /** * Define Secure Connections Support */ @@ -104,6 +126,7 @@ #define CFG_FW_SUBVERSION (1) #define CFG_FW_BRANCH (0) #define CFG_FW_BUILD (0) +#endif /****************************************************************************** * BLE Stack @@ -250,7 +273,7 @@ * 0: LE Power Class 2-3 * other bits: complete with Options_extension flag */ -#define CFG_BLE_OPTIONS (SHCI_C2_BLE_INIT_OPTIONS_LL_HOST | SHCI_C2_BLE_INIT_OPTIONS_WITH_SVC_CHANGE_DESC | SHCI_C2_BLE_INIT_OPTIONS_DEVICE_NAME_RW | SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV | SHCI_C2_BLE_INIT_OPTIONS_CS_ALGO2 | SHCI_C2_BLE_INIT_OPTIONS_FULL_GATTDB_NVM | SHCI_C2_BLE_INIT_OPTIONS_GATT_CACHING_NOTUSED | SHCI_C2_BLE_INIT_OPTIONS_POWER_CLASS_2_3) +#define CFG_BLE_OPTIONS (SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY | SHCI_C2_BLE_INIT_OPTIONS_WITH_SVC_CHANGE_DESC | SHCI_C2_BLE_INIT_OPTIONS_DEVICE_NAME_RW | SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV | SHCI_C2_BLE_INIT_OPTIONS_CS_ALGO2 | SHCI_C2_BLE_INIT_OPTIONS_FULL_GATTDB_NVM | SHCI_C2_BLE_INIT_OPTIONS_GATT_CACHING_NOTUSED | SHCI_C2_BLE_INIT_OPTIONS_POWER_CLASS_2_3) /** * BLE stack Options_extension flags to be configured with: @@ -292,7 +315,11 @@ * This parameter is considered by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV flag set */ -#define CFG_BLE_MAX_ADV_SET_NBR (8) +#if defined(STM32WB15xx) + #define CFG_BLE_MAX_ADV_SET_NBR (3) +#else + #define CFG_BLE_MAX_ADV_SET_NBR (8) +#endif /* Maximum advertising data length (in bytes) * Range: 31 .. 1650 with limitation: @@ -301,7 +328,11 @@ * This parameter is considered by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV flag set */ -#define CFG_BLE_MAX_ADV_DATA_LEN (207) +#if defined(STM32WB15xx) + #define CFG_BLE_MAX_ADV_DATA_LEN (414) +#else + #define CFG_BLE_MAX_ADV_DATA_LEN (207) +#endif /* RF TX Path Compensation Value (16-bit signed integer). Units: 0.1 dB. * Range: -1280 .. 1280 @@ -324,6 +355,7 @@ #define CFG_BLE_CORE_VERSION (SHCI_C2_BLE_INIT_BLE_CORE_5_4) +#if 0 /****************************************************************************** * Transport Layer ******************************************************************************/ @@ -659,4 +691,5 @@ typedef enum #define CFG_OTP_END_ADRESS OTP_AREA_END_ADDR -#endif /*APP_CONF_H */ +#endif +#endif /*APP_CONF_DEFAULT_H */ diff --git a/src/utility/STM32_WPAN/hw.h b/src/utility/STM32_WPAN/hw.h index 651e1f17..1472a5e8 100644 --- a/src/utility/STM32_WPAN/hw.h +++ b/src/utility/STM32_WPAN/hw.h @@ -26,14 +26,23 @@ extern "C" { #endif /* Includes ------------------------------------------------------------------*/ +#include "stm32_def.h" +#include "stm32wbxx_ll_bus.h" +#include "stm32wbxx_ll_exti.h" +#include "stm32wbxx_ll_system.h" +#include "stm32wbxx_ll_rcc.h" +#include "stm32wbxx_ll_ipcc.h" +#include "stm32wbxx_ll_cortex.h" +#include "stm32wbxx_ll_utils.h" +#include "stm32wbxx_ll_pwr.h" /****************************************************************************** * HW IPCC ******************************************************************************/ void HW_IPCC_Enable( void ); void HW_IPCC_Init( void ); - void HW_IPCC_Rx_Handler( void ); - void HW_IPCC_Tx_Handler( void ); +#define HW_IPCC_Rx_Handler IPCC_C1_RX_IRQHandler +#define HW_IPCC_Tx_Handler IPCC_C1_TX_IRQHandler void HW_IPCC_BLE_Init( void ); void HW_IPCC_BLE_SendCmd( void ); diff --git a/src/utility/STM32_WPAN/hw_ipcc.c b/src/utility/STM32_WPAN/hw_ipcc.c index fd620b85..3461cbed 100644 --- a/src/utility/STM32_WPAN/hw_ipcc.c +++ b/src/utility/STM32_WPAN/hw_ipcc.c @@ -18,8 +18,9 @@ */ /* USER CODE END Header */ +#if defined(STM32WBxx) /* Includes ------------------------------------------------------------------*/ -#include "app_common.h" +#include "hw.h" #include "mbox_def.h" /* Global variables ---------------------------------------------------------*/ @@ -667,3 +668,4 @@ static void HW_IPCC_TRACES_EvtHandler( void ) } __weak void HW_IPCC_TRACES_EvtNot( void ){}; +#endif /* STM32WBxx */ diff --git a/src/utility/STM32_WPAN/shci.c b/src/utility/STM32_WPAN/shci.c index 5c32555e..40110f42 100644 --- a/src/utility/STM32_WPAN/shci.c +++ b/src/utility/STM32_WPAN/shci.c @@ -17,6 +17,7 @@ */ +#if defined(STM32WBxx) /* Includes ------------------------------------------------------------------*/ #include "stm32_wpan_common.h" @@ -759,3 +760,4 @@ SHCI_CmdStatus_t SHCI_GetWirelessFwInfo( WirelessFwInfo_t* pWirelessInfo ) return (SHCI_Success); } +#endif /* STM32WBxx */ diff --git a/src/utility/STM32_WPAN/shci_tl.c b/src/utility/STM32_WPAN/shci_tl.c index 0f604300..daa988c1 100644 --- a/src/utility/STM32_WPAN/shci_tl.c +++ b/src/utility/STM32_WPAN/shci_tl.c @@ -17,11 +17,13 @@ */ +#if defined(STM32WBxx) /* Includes ------------------------------------------------------------------*/ #include "stm32_wpan_common.h" #include "stm_list.h" #include "shci_tl.h" +#include "stm32_def.h" /* Private typedef -----------------------------------------------------------*/ typedef enum @@ -168,6 +170,20 @@ void shci_send( uint16_t cmd_code, uint8_t len_cmd_payload, uint8_t * p_cmd_payl return; } +void shci_notify_asynch_evt(void *pdata) +{ + UNUSED(pdata); + /* Need to parse data in future version */ + shci_user_evt_proc(); +} + +void shci_register_io_bus(tSHciIO *fops) +{ + /* Register IO bus services */ + fops->Init = TL_SYS_Init; + fops->Send = TL_SYS_SendCmd; +} + /* Private functions ---------------------------------------------------------*/ static void TlInit( TL_CmdPacket_t * p_cmdbuffer ) { @@ -250,3 +266,4 @@ __WEAK void shci_cmd_resp_release(uint32_t flag) return; } +#endif /* STM32WBxx */ diff --git a/src/utility/STM32_WPAN/stm_list.c b/src/utility/STM32_WPAN/stm_list.c index 4c928647..df6c2155 100644 --- a/src/utility/STM32_WPAN/stm_list.c +++ b/src/utility/STM32_WPAN/stm_list.c @@ -17,10 +17,13 @@ */ +#if defined(STM32WBxx) /****************************************************************************** * Include Files ******************************************************************************/ -#include "utilities_common.h" +#include "stdint.h" +#include "cmsis_gcc.h" +#include "stm32_wpan_common.h" #include "stm_list.h" @@ -204,3 +207,4 @@ void LST_get_prev_node (tListNode * ref_node, tListNode ** node) __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ } +#endif /* STM32WBxx */ diff --git a/src/utility/STM32_WPAN/tl_mbox.c b/src/utility/STM32_WPAN/tl_mbox.c index 27a998a3..40c96793 100644 --- a/src/utility/STM32_WPAN/tl_mbox.c +++ b/src/utility/STM32_WPAN/tl_mbox.c @@ -16,6 +16,7 @@ ****************************************************************************** */ +#if defined(STM32WBxx) /* Includes ------------------------------------------------------------------*/ #include "stm32_wpan_common.h" #include "hw.h" @@ -51,8 +52,10 @@ PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_BleLldTable_t TL_BleLldTable; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_SysTable_t TL_SysTable; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_MemManagerTable_t TL_MemManagerTable; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_TracesTable_t TL_TracesTable; +#if 0 PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_Mac_802_15_4_t TL_Mac_802_15_4_Table; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_ZigbeeTable_t TL_Zigbee_Table; +#endif /**< tables */ PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode FreeBufQueue; @@ -97,8 +100,10 @@ void TL_Init( void ) TL_RefTable.p_sys_table = &TL_SysTable; TL_RefTable.p_mem_manager_table = &TL_MemManagerTable; TL_RefTable.p_traces_table = &TL_TracesTable; +#if 0 TL_RefTable.p_mac_802_15_4_table = &TL_Mac_802_15_4_Table; TL_RefTable.p_zigbee_table = &TL_Zigbee_Table; +#endif HW_IPCC_Init(); return; @@ -846,3 +851,4 @@ static void OutputDbgTrace(TL_MB_PacketType_t packet_type, uint8_t* buffer) return; } +#endif /* STM32WBxx */ From 7450369e948219792a971133bbf13d93daa2b955 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Thu, 13 Jul 2023 17:16:40 +0200 Subject: [PATCH 165/226] fix: include a timeout when waiting for the cmd_resp Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- src/utility/STM32_WPAN/shci_tl.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/utility/STM32_WPAN/shci_tl.c b/src/utility/STM32_WPAN/shci_tl.c index daa988c1..25e1a214 100644 --- a/src/utility/STM32_WPAN/shci_tl.c +++ b/src/utility/STM32_WPAN/shci_tl.c @@ -24,6 +24,7 @@ #include "stm_list.h" #include "shci_tl.h" #include "stm32_def.h" +#include "wiring_time.h" /* Private typedef -----------------------------------------------------------*/ typedef enum @@ -251,10 +252,11 @@ static void TlUserEvtReceived(TL_EvtPacket_t *shcievt) /* Weak implementation ----------------------------------------------------------------*/ __WEAK void shci_cmd_resp_wait(uint32_t timeout) { - (void)timeout; - - while(CmdRspStatusFlag != SHCI_TL_CMD_RESP_RELEASE); - + for (unsigned long start = millis(); (millis() - start) < timeout;) { + if (CmdRspStatusFlag == SHCI_TL_CMD_RESP_RELEASE) { + break; + } + } return; } From dac6208ecb4c6fb885a599a68998bcea846c7e5f Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Wed, 10 Jan 2024 18:45:17 +0100 Subject: [PATCH 166/226] chore: add support for customize app_conf_default.h Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- src/utility/STM32_WPAN/app_conf_default.h | 58 ++++++++++++++++++----- 1 file changed, 45 insertions(+), 13 deletions(-) diff --git a/src/utility/STM32_WPAN/app_conf_default.h b/src/utility/STM32_WPAN/app_conf_default.h index 6c9beb3b..9509a0f5 100644 --- a/src/utility/STM32_WPAN/app_conf_default.h +++ b/src/utility/STM32_WPAN/app_conf_default.h @@ -50,7 +50,9 @@ /** * Define Tx Power */ -#define CFG_TX_POWER (0x18) /* -0.15dBm */ +#ifndef CFG_TX_POWER + #define CFG_TX_POWER (0x18) /* -0.15dBm */ +#endif #if 0 /** @@ -135,13 +137,25 @@ * Maximum number of simultaneous connections that the device will support. * Valid values are from 1 to 8 */ -#define CFG_BLE_NUM_LINK 8 +#ifndef CFG_BLE_NUM_LINK +#ifdef STM32WB15xx + #define CFG_BLE_NUM_LINK 3 +#else + #define CFG_BLE_NUM_LINK 8 +#endif +#endif /** * Maximum number of Services that can be stored in the GATT database. * Note that the GAP and GATT services are automatically added so this parameter should be 2 plus the number of user services */ -#define CFG_BLE_NUM_GATT_SERVICES 8 +#ifndef CFG_BLE_NUM_GATT_SERVICES +#ifdef STM32WB15xx + #define CFG_BLE_NUM_GATT_SERVICES 4 +#else + #define CFG_BLE_NUM_GATT_SERVICES 8 +#endif +#endif /** * Maximum number of Attributes @@ -150,7 +164,13 @@ * Note that certain characteristics and relative descriptors are added automatically during device initialization * so this parameters should be 9 plus the number of user Attributes */ -#define CFG_BLE_NUM_GATT_ATTRIBUTES 68 +#ifndef CFG_BLE_NUM_GATT_ATTRIBUTES +#ifdef STM32WB15xx + #define CFG_BLE_NUM_GATT_ATTRIBUTES 30 +#else + #define CFG_BLE_NUM_GATT_ATTRIBUTES 68 +#endif +#endif /** * Maximum supported ATT_MTU size @@ -186,12 +206,16 @@ /** * Enable or disable the Extended Packet length feature. Valid values are 0 or 1. */ -#define CFG_BLE_DATA_LENGTH_EXTENSION 1 +#ifndef CFG_BLE_DATA_LENGTH_EXTENSION + #define CFG_BLE_DATA_LENGTH_EXTENSION 1 +#endif /** * Sleep clock accuracy in Peripheral mode (ppm value) */ -#define CFG_BLE_PERIPHERAL_SCA 500 +#ifndef CFG_BLE_PERIPHERAL_SCA + #define CFG_BLE_PERIPHERAL_SCA 500 +#endif /** * Sleep clock accuracy in Central mode @@ -204,7 +228,9 @@ * 6 : 21 ppm to 30 ppm * 7 : 0 ppm to 20 ppm */ -#define CFG_BLE_CENTRAL_SCA 0 +#ifndef CFG_BLE_CENTRAL_SCA + #define CFG_BLE_CENTRAL_SCA 0 +#endif /** * LsSource @@ -213,21 +239,27 @@ * - bit 1: 1: STM32WB5M Module device 0: Other devices as STM32WBxx SOC, STM32WB1M module * - bit 2: 1: HSE/1024 Clock config 0: LSE Clock config */ -#if defined(STM32WB5Mxx) - #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_MOD5MM_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) -#else - #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_OTHER_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) +#ifndef CFG_BLE_LS_SOURCE + #if defined(STM32WB5Mxx) + #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_MOD5MM_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) + #else + #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_OTHER_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) + #endif #endif /** * Start up time of the high speed (16 or 32 MHz) crystal oscillator in units of 625/256 us (~2.44 us) */ -#define CFG_BLE_HSE_STARTUP_TIME 0x148 +#ifndef CFG_BLE_HSE_STARTUP_TIME + #define CFG_BLE_HSE_STARTUP_TIME 0x148 +#endif /** * Maximum duration of the connection event when the device is in Peripheral mode in units of 625/256 us (~2.44 us) */ -#define CFG_BLE_MAX_CONN_EVENT_LENGTH (0xFFFFFFFF) +#ifndef CFG_BLE_MAX_CONN_EVENT_LENGTH + #define CFG_BLE_MAX_CONN_EVENT_LENGTH (0xFFFFFFFF) +#endif /** * Viterbi Mode From c4c7874909259ad37eb7f7c2527ab3021a53f161 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Mon, 24 Jul 2023 10:55:20 +0200 Subject: [PATCH 167/226] fix: TL_Evt_t payload size for reset Within STM32CubeWB v1.17.0 update TL_Evt_t payload size was reduced. This produce a warning -Warray-bounds due to the reset management which require 4 bytes. Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- src/utility/STM32_WPAN/tl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utility/STM32_WPAN/tl.h b/src/utility/STM32_WPAN/tl.h index 8e8c6cbc..74520878 100644 --- a/src/utility/STM32_WPAN/tl.h +++ b/src/utility/STM32_WPAN/tl.h @@ -108,7 +108,7 @@ typedef PACKED_STRUCT { uint8_t evtcode; uint8_t plen; - uint8_t payload[2]; + uint8_t payload[4]; } TL_Evt_t; typedef PACKED_STRUCT From 5853f23b0fe0e41c7f234e39627b8e21ce1876da Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Thu, 9 Jan 2025 14:27:24 +0100 Subject: [PATCH 168/226] chore: update STM32_WPAN from Cube version v1.21.0 Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- src/utility/STM32_WPAN/LICENSE.md | 28 ++++++ src/utility/STM32_WPAN/README.md | 4 +- src/utility/STM32_WPAN/app_conf_default.h | 106 +++++----------------- src/utility/STM32_WPAN/hw.h | 13 +-- src/utility/STM32_WPAN/hw_ipcc.c | 4 +- src/utility/STM32_WPAN/shci.c | 2 - src/utility/STM32_WPAN/shci_tl.c | 27 +----- src/utility/STM32_WPAN/stm_list.c | 6 +- src/utility/STM32_WPAN/tl.h | 2 +- src/utility/STM32_WPAN/tl_mbox.c | 25 ++--- 10 files changed, 70 insertions(+), 147 deletions(-) diff --git a/src/utility/STM32_WPAN/LICENSE.md b/src/utility/STM32_WPAN/LICENSE.md index 1af52330..4e70ee7c 100644 --- a/src/utility/STM32_WPAN/LICENSE.md +++ b/src/utility/STM32_WPAN/LICENSE.md @@ -1,3 +1,31 @@ +## Overview + + +This Software Bill Of Material (SBOM) lists the software components of this +software package, including the copyright owner and license terms for each +component. + +__SOFTWARE BILL OF MATERIALS__ + +Component | Copyright | License +--------- | ----------------------------------------------------------------- | ------- +Bluetooth Low Energy | STMicroelectronics | SLA +Bluetooth Low Energy LLD | STMicroelectronics | SLA +Interface | STMicroelectronics | SLA +MAC 802.15.4 | STMicroelectronics | SLA +PHY | STMicroelectronics | SLA +OpenThread | The OpenThread Authors | BSD-3-Clause +Utilities | STMicroelectronics, Amazon.com Inc. | SLA, MIT +Zigbee | Exegin Technologies Limited, STMicroelectronics, Dr Brian Gladman | SLA + + +__Notes:__ If the license is an open source license, then you can access the +terms at [www.opensource.org](https://opensource.org/). Otherwise, the full +license terms are below. If a component is not listed in the SBOM, then the SLA +shall apply unless other terms are clearly stated in the package. + + + SLA0044 Rev5/February 2018 ## Software license agreement diff --git a/src/utility/STM32_WPAN/README.md b/src/utility/STM32_WPAN/README.md index f50589ee..a9b3969a 100644 --- a/src/utility/STM32_WPAN/README.md +++ b/src/utility/STM32_WPAN/README.md @@ -1,6 +1,6 @@ ## Source -[STMicroelectronics/STM32CubeWB Release v1.20.0](https://github.com/STMicroelectronics/STM32CubeWB/releases/tag/v1.20.0) -- Application: [BLE_TransparentMode](https://github.com/STMicroelectronics/STM32CubeWB/tree/v1.20.0/Projects/P-NUCLEO-WB55.Nucleo/Applications/BLE/BLE_TransparentMode) +[STMicroelectronics/STM32CubeWB Release v1.21.0](https://github.com/STMicroelectronics/STM32CubeWB/releases/tag/v1.21.0) +- Application: [BLE_TransparentMode](https://github.com/STMicroelectronics/STM32CubeWB/tree/v1.21.0/Projects/P-NUCLEO-WB55.Nucleo/Applications/BLE/BLE_TransparentMode) diff --git a/src/utility/STM32_WPAN/app_conf_default.h b/src/utility/STM32_WPAN/app_conf_default.h index 9509a0f5..71fc107b 100644 --- a/src/utility/STM32_WPAN/app_conf_default.h +++ b/src/utility/STM32_WPAN/app_conf_default.h @@ -1,9 +1,9 @@ /* USER CODE BEGIN Header */ /** ****************************************************************************** - * @file app_conf_default.h + * @file app_conf.h * @author MCD Application Team - * @brief Default application configuration file for STM32WPAN Middleware. + * @brief Application configuration file for STM32WPAN Middleware. ****************************************************************************** * @attention * @@ -19,42 +19,18 @@ /* USER CODE END Header */ /* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef APP_CONF_DEFAULT_H -#define APP_CONF_DEFAULT_H +#ifndef APP_CONF_H +#define APP_CONF_H -#if 0 #include "hw.h" #include "hw_conf.h" #include "hw_if.h" #include "ble_bufsize.h" -#endif /****************************************************************************** * Application Config ******************************************************************************/ -/**< generic parameters ******************************************************/ -/* HCI related defines */ - -#define ACI_HAL_SET_TX_POWER_LEVEL 0xFC0F -#define ACI_WRITE_CONFIG_DATA_OPCODE 0xFC0C -#define ACI_READ_CONFIG_DATA_OPCODE 0xFC0D -#define MAX_HCI_ACL_PACKET_SIZE (sizeof(TL_PacketHeader_t) + 5 + 251) -#define HCI_RESET 0x0C03 - -#ifndef BLE_SHARED_MEM_BYTE_ORDER - #define BLE_SHARED_MEM_BYTE_ORDER MSBFIRST -#endif -#define BLE_MODULE_SHARED_MEM_BUFFER_SIZE 128 - -/** - * Define Tx Power - */ -#ifndef CFG_TX_POWER - #define CFG_TX_POWER (0x18) /* -0.15dBm */ -#endif - -#if 0 /** * Define Secure Connections Support */ @@ -128,7 +104,6 @@ #define CFG_FW_SUBVERSION (1) #define CFG_FW_BRANCH (0) #define CFG_FW_BUILD (0) -#endif /****************************************************************************** * BLE Stack @@ -137,25 +112,13 @@ * Maximum number of simultaneous connections that the device will support. * Valid values are from 1 to 8 */ -#ifndef CFG_BLE_NUM_LINK -#ifdef STM32WB15xx - #define CFG_BLE_NUM_LINK 3 -#else - #define CFG_BLE_NUM_LINK 8 -#endif -#endif +#define CFG_BLE_NUM_LINK 8 /** * Maximum number of Services that can be stored in the GATT database. * Note that the GAP and GATT services are automatically added so this parameter should be 2 plus the number of user services */ -#ifndef CFG_BLE_NUM_GATT_SERVICES -#ifdef STM32WB15xx - #define CFG_BLE_NUM_GATT_SERVICES 4 -#else - #define CFG_BLE_NUM_GATT_SERVICES 8 -#endif -#endif +#define CFG_BLE_NUM_GATT_SERVICES 8 /** * Maximum number of Attributes @@ -164,13 +127,7 @@ * Note that certain characteristics and relative descriptors are added automatically during device initialization * so this parameters should be 9 plus the number of user Attributes */ -#ifndef CFG_BLE_NUM_GATT_ATTRIBUTES -#ifdef STM32WB15xx - #define CFG_BLE_NUM_GATT_ATTRIBUTES 30 -#else - #define CFG_BLE_NUM_GATT_ATTRIBUTES 68 -#endif -#endif +#define CFG_BLE_NUM_GATT_ATTRIBUTES 68 /** * Maximum supported ATT_MTU size @@ -206,16 +163,12 @@ /** * Enable or disable the Extended Packet length feature. Valid values are 0 or 1. */ -#ifndef CFG_BLE_DATA_LENGTH_EXTENSION - #define CFG_BLE_DATA_LENGTH_EXTENSION 1 -#endif +#define CFG_BLE_DATA_LENGTH_EXTENSION 1 /** * Sleep clock accuracy in Peripheral mode (ppm value) */ -#ifndef CFG_BLE_PERIPHERAL_SCA - #define CFG_BLE_PERIPHERAL_SCA 500 -#endif +#define CFG_BLE_PERIPHERAL_SCA 500 /** * Sleep clock accuracy in Central mode @@ -228,9 +181,7 @@ * 6 : 21 ppm to 30 ppm * 7 : 0 ppm to 20 ppm */ -#ifndef CFG_BLE_CENTRAL_SCA - #define CFG_BLE_CENTRAL_SCA 0 -#endif +#define CFG_BLE_CENTRAL_SCA 0 /** * LsSource @@ -239,27 +190,21 @@ * - bit 1: 1: STM32WB5M Module device 0: Other devices as STM32WBxx SOC, STM32WB1M module * - bit 2: 1: HSE/1024 Clock config 0: LSE Clock config */ -#ifndef CFG_BLE_LS_SOURCE - #if defined(STM32WB5Mxx) - #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_MOD5MM_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) - #else - #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_OTHER_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) - #endif +#if defined(STM32WB5Mxx) + #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_MOD5MM_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) +#else + #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_OTHER_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) #endif /** * Start up time of the high speed (16 or 32 MHz) crystal oscillator in units of 625/256 us (~2.44 us) */ -#ifndef CFG_BLE_HSE_STARTUP_TIME - #define CFG_BLE_HSE_STARTUP_TIME 0x148 -#endif +#define CFG_BLE_HSE_STARTUP_TIME 0x148 /** * Maximum duration of the connection event when the device is in Peripheral mode in units of 625/256 us (~2.44 us) */ -#ifndef CFG_BLE_MAX_CONN_EVENT_LENGTH - #define CFG_BLE_MAX_CONN_EVENT_LENGTH (0xFFFFFFFF) -#endif +#define CFG_BLE_MAX_CONN_EVENT_LENGTH (0xFFFFFFFF) /** * Viterbi Mode @@ -305,7 +250,7 @@ * 0: LE Power Class 2-3 * other bits: complete with Options_extension flag */ -#define CFG_BLE_OPTIONS (SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY | SHCI_C2_BLE_INIT_OPTIONS_WITH_SVC_CHANGE_DESC | SHCI_C2_BLE_INIT_OPTIONS_DEVICE_NAME_RW | SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV | SHCI_C2_BLE_INIT_OPTIONS_CS_ALGO2 | SHCI_C2_BLE_INIT_OPTIONS_FULL_GATTDB_NVM | SHCI_C2_BLE_INIT_OPTIONS_GATT_CACHING_NOTUSED | SHCI_C2_BLE_INIT_OPTIONS_POWER_CLASS_2_3) +#define CFG_BLE_OPTIONS (SHCI_C2_BLE_INIT_OPTIONS_LL_HOST | SHCI_C2_BLE_INIT_OPTIONS_WITH_SVC_CHANGE_DESC | SHCI_C2_BLE_INIT_OPTIONS_DEVICE_NAME_RW | SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV | SHCI_C2_BLE_INIT_OPTIONS_CS_ALGO2 | SHCI_C2_BLE_INIT_OPTIONS_FULL_GATTDB_NVM | SHCI_C2_BLE_INIT_OPTIONS_GATT_CACHING_NOTUSED | SHCI_C2_BLE_INIT_OPTIONS_POWER_CLASS_2_3) /** * BLE stack Options_extension flags to be configured with: @@ -347,11 +292,7 @@ * This parameter is considered by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV flag set */ -#if defined(STM32WB15xx) - #define CFG_BLE_MAX_ADV_SET_NBR (3) -#else - #define CFG_BLE_MAX_ADV_SET_NBR (8) -#endif +#define CFG_BLE_MAX_ADV_SET_NBR (8) /* Maximum advertising data length (in bytes) * Range: 31 .. 1650 with limitation: @@ -360,11 +301,7 @@ * This parameter is considered by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV flag set */ -#if defined(STM32WB15xx) - #define CFG_BLE_MAX_ADV_DATA_LEN (414) -#else - #define CFG_BLE_MAX_ADV_DATA_LEN (207) -#endif +#define CFG_BLE_MAX_ADV_DATA_LEN (207) /* RF TX Path Compensation Value (16-bit signed integer). Units: 0.1 dB. * Range: -1280 .. 1280 @@ -387,7 +324,6 @@ #define CFG_BLE_CORE_VERSION (SHCI_C2_BLE_INIT_BLE_CORE_5_4) -#if 0 /****************************************************************************** * Transport Layer ******************************************************************************/ @@ -687,6 +623,7 @@ typedef enum /* USER CODE BEGIN CFG_SCH_Prio_Id_t */ /* USER CODE END CFG_SCH_Prio_Id_t */ + CFG_SCH_PRIO_NBR } CFG_SCH_Prio_Id_t; /** @@ -723,5 +660,4 @@ typedef enum #define CFG_OTP_END_ADRESS OTP_AREA_END_ADDR -#endif -#endif /*APP_CONF_DEFAULT_H */ +#endif /*APP_CONF_H */ diff --git a/src/utility/STM32_WPAN/hw.h b/src/utility/STM32_WPAN/hw.h index 1472a5e8..651e1f17 100644 --- a/src/utility/STM32_WPAN/hw.h +++ b/src/utility/STM32_WPAN/hw.h @@ -26,23 +26,14 @@ extern "C" { #endif /* Includes ------------------------------------------------------------------*/ -#include "stm32_def.h" -#include "stm32wbxx_ll_bus.h" -#include "stm32wbxx_ll_exti.h" -#include "stm32wbxx_ll_system.h" -#include "stm32wbxx_ll_rcc.h" -#include "stm32wbxx_ll_ipcc.h" -#include "stm32wbxx_ll_cortex.h" -#include "stm32wbxx_ll_utils.h" -#include "stm32wbxx_ll_pwr.h" /****************************************************************************** * HW IPCC ******************************************************************************/ void HW_IPCC_Enable( void ); void HW_IPCC_Init( void ); -#define HW_IPCC_Rx_Handler IPCC_C1_RX_IRQHandler -#define HW_IPCC_Tx_Handler IPCC_C1_TX_IRQHandler + void HW_IPCC_Rx_Handler( void ); + void HW_IPCC_Tx_Handler( void ); void HW_IPCC_BLE_Init( void ); void HW_IPCC_BLE_SendCmd( void ); diff --git a/src/utility/STM32_WPAN/hw_ipcc.c b/src/utility/STM32_WPAN/hw_ipcc.c index 3461cbed..fd620b85 100644 --- a/src/utility/STM32_WPAN/hw_ipcc.c +++ b/src/utility/STM32_WPAN/hw_ipcc.c @@ -18,9 +18,8 @@ */ /* USER CODE END Header */ -#if defined(STM32WBxx) /* Includes ------------------------------------------------------------------*/ -#include "hw.h" +#include "app_common.h" #include "mbox_def.h" /* Global variables ---------------------------------------------------------*/ @@ -668,4 +667,3 @@ static void HW_IPCC_TRACES_EvtHandler( void ) } __weak void HW_IPCC_TRACES_EvtNot( void ){}; -#endif /* STM32WBxx */ diff --git a/src/utility/STM32_WPAN/shci.c b/src/utility/STM32_WPAN/shci.c index 40110f42..5c32555e 100644 --- a/src/utility/STM32_WPAN/shci.c +++ b/src/utility/STM32_WPAN/shci.c @@ -17,7 +17,6 @@ */ -#if defined(STM32WBxx) /* Includes ------------------------------------------------------------------*/ #include "stm32_wpan_common.h" @@ -760,4 +759,3 @@ SHCI_CmdStatus_t SHCI_GetWirelessFwInfo( WirelessFwInfo_t* pWirelessInfo ) return (SHCI_Success); } -#endif /* STM32WBxx */ diff --git a/src/utility/STM32_WPAN/shci_tl.c b/src/utility/STM32_WPAN/shci_tl.c index 25e1a214..0f604300 100644 --- a/src/utility/STM32_WPAN/shci_tl.c +++ b/src/utility/STM32_WPAN/shci_tl.c @@ -17,14 +17,11 @@ */ -#if defined(STM32WBxx) /* Includes ------------------------------------------------------------------*/ #include "stm32_wpan_common.h" #include "stm_list.h" #include "shci_tl.h" -#include "stm32_def.h" -#include "wiring_time.h" /* Private typedef -----------------------------------------------------------*/ typedef enum @@ -171,20 +168,6 @@ void shci_send( uint16_t cmd_code, uint8_t len_cmd_payload, uint8_t * p_cmd_payl return; } -void shci_notify_asynch_evt(void *pdata) -{ - UNUSED(pdata); - /* Need to parse data in future version */ - shci_user_evt_proc(); -} - -void shci_register_io_bus(tSHciIO *fops) -{ - /* Register IO bus services */ - fops->Init = TL_SYS_Init; - fops->Send = TL_SYS_SendCmd; -} - /* Private functions ---------------------------------------------------------*/ static void TlInit( TL_CmdPacket_t * p_cmdbuffer ) { @@ -252,11 +235,10 @@ static void TlUserEvtReceived(TL_EvtPacket_t *shcievt) /* Weak implementation ----------------------------------------------------------------*/ __WEAK void shci_cmd_resp_wait(uint32_t timeout) { - for (unsigned long start = millis(); (millis() - start) < timeout;) { - if (CmdRspStatusFlag == SHCI_TL_CMD_RESP_RELEASE) { - break; - } - } + (void)timeout; + + while(CmdRspStatusFlag != SHCI_TL_CMD_RESP_RELEASE); + return; } @@ -268,4 +250,3 @@ __WEAK void shci_cmd_resp_release(uint32_t flag) return; } -#endif /* STM32WBxx */ diff --git a/src/utility/STM32_WPAN/stm_list.c b/src/utility/STM32_WPAN/stm_list.c index df6c2155..4c928647 100644 --- a/src/utility/STM32_WPAN/stm_list.c +++ b/src/utility/STM32_WPAN/stm_list.c @@ -17,13 +17,10 @@ */ -#if defined(STM32WBxx) /****************************************************************************** * Include Files ******************************************************************************/ -#include "stdint.h" -#include "cmsis_gcc.h" -#include "stm32_wpan_common.h" +#include "utilities_common.h" #include "stm_list.h" @@ -207,4 +204,3 @@ void LST_get_prev_node (tListNode * ref_node, tListNode ** node) __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ } -#endif /* STM32WBxx */ diff --git a/src/utility/STM32_WPAN/tl.h b/src/utility/STM32_WPAN/tl.h index 74520878..8e8c6cbc 100644 --- a/src/utility/STM32_WPAN/tl.h +++ b/src/utility/STM32_WPAN/tl.h @@ -108,7 +108,7 @@ typedef PACKED_STRUCT { uint8_t evtcode; uint8_t plen; - uint8_t payload[4]; + uint8_t payload[2]; } TL_Evt_t; typedef PACKED_STRUCT diff --git a/src/utility/STM32_WPAN/tl_mbox.c b/src/utility/STM32_WPAN/tl_mbox.c index 40c96793..df07a197 100644 --- a/src/utility/STM32_WPAN/tl_mbox.c +++ b/src/utility/STM32_WPAN/tl_mbox.c @@ -16,7 +16,6 @@ ****************************************************************************** */ -#if defined(STM32WBxx) /* Includes ------------------------------------------------------------------*/ #include "stm32_wpan_common.h" #include "hw.h" @@ -52,10 +51,8 @@ PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_BleLldTable_t TL_BleLldTable; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_SysTable_t TL_SysTable; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_MemManagerTable_t TL_MemManagerTable; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_TracesTable_t TL_TracesTable; -#if 0 PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_Mac_802_15_4_t TL_Mac_802_15_4_Table; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_ZigbeeTable_t TL_Zigbee_Table; -#endif /**< tables */ PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode FreeBufQueue; @@ -100,10 +97,8 @@ void TL_Init( void ) TL_RefTable.p_sys_table = &TL_SysTable; TL_RefTable.p_mem_manager_table = &TL_MemManagerTable; TL_RefTable.p_traces_table = &TL_TracesTable; -#if 0 TL_RefTable.p_mac_802_15_4_table = &TL_Mac_802_15_4_Table; TL_RefTable.p_zigbee_table = &TL_Zigbee_Table; -#endif HW_IPCC_Init(); return; @@ -676,6 +671,7 @@ static void OutputDbgTrace(TL_MB_PacketType_t packet_type, uint8_t* buffer) { TL_EvtPacket_t *p_evt_packet; TL_CmdPacket_t *p_cmd_packet; + TL_EvtSerial_t *p_cmd_rsp_packet; switch(packet_type) { @@ -799,28 +795,28 @@ static void OutputDbgTrace(TL_MB_PacketType_t packet_type, uint8_t* buffer) break; case TL_MB_SYS_CMD_RSP: - p_evt_packet = (TL_EvtPacket_t*)buffer; - switch(p_evt_packet->evtserial.evt.evtcode) + p_cmd_rsp_packet = (TL_EvtSerial_t*)buffer; + switch(p_cmd_rsp_packet->evt.evtcode) { case TL_BLEEVT_CC_OPCODE: - TL_SHCI_CMD_DBG_MSG("sys rsp: 0x%02X", p_evt_packet->evtserial.evt.evtcode); - TL_SHCI_CMD_DBG_MSG(" cmd opcode: 0x%02X", ((TL_CcEvt_t*)(p_evt_packet->evtserial.evt.payload))->cmdcode); - TL_SHCI_CMD_DBG_MSG(" status: 0x%02X", ((TL_CcEvt_t*)(p_evt_packet->evtserial.evt.payload))->payload[0]); - if((p_evt_packet->evtserial.evt.plen-4) != 0) + TL_SHCI_CMD_DBG_MSG("sys rsp: 0x%02X", p_cmd_rsp_packet->evt.evtcode); + TL_SHCI_CMD_DBG_MSG(" cmd opcode: 0x%02X", ((TL_CcEvt_t*)(p_cmd_rsp_packet->evt.payload))->cmdcode); + TL_SHCI_CMD_DBG_MSG(" status: 0x%02X", ((TL_CcEvt_t*)(p_cmd_rsp_packet->evt.payload))->payload[0]); + if((p_cmd_rsp_packet->evt.plen-4) != 0) { TL_SHCI_CMD_DBG_MSG(" payload:"); - TL_SHCI_CMD_DBG_BUF(&((TL_CcEvt_t*)(p_evt_packet->evtserial.evt.payload))->payload[1], p_evt_packet->evtserial.evt.plen-4, ""); + TL_SHCI_CMD_DBG_BUF(&((TL_CcEvt_t*)(p_cmd_rsp_packet->evt.payload))->payload[1], p_cmd_rsp_packet->evt.plen-4, ""); } break; default: - TL_SHCI_CMD_DBG_MSG("unknown sys rsp received: %02X", p_evt_packet->evtserial.evt.evtcode); + TL_SHCI_CMD_DBG_MSG("unknown sys rsp received: %02X", p_cmd_rsp_packet->evt.evtcode); break; } TL_SHCI_CMD_DBG_MSG("\r\n"); - TL_SHCI_CMD_DBG_RAW(&p_evt_packet->evtserial, p_evt_packet->evtserial.evt.plen+TL_EVT_HDR_SIZE); + TL_SHCI_CMD_DBG_RAW(&p_cmd_rsp_packet->evt, p_cmd_rsp_packet->evt.plen+TL_EVT_HDR_SIZE); break; case TL_MB_SYS_ASYNCH_EVT: @@ -851,4 +847,3 @@ static void OutputDbgTrace(TL_MB_PacketType_t packet_type, uint8_t* buffer) return; } -#endif /* STM32WBxx */ From a5d59623a4510744b4ac4b8cab463800f5f5e742 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Wed, 10 Jan 2024 18:16:01 +0100 Subject: [PATCH 169/226] chore: adapt STM32_WPAN sources Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- src/utility/STM32_WPAN/app_conf_default.h | 49 +++++++++++++++++++---- src/utility/STM32_WPAN/hw.h | 13 +++++- src/utility/STM32_WPAN/hw_ipcc.c | 4 +- src/utility/STM32_WPAN/shci.c | 2 + src/utility/STM32_WPAN/shci_tl.c | 17 ++++++++ src/utility/STM32_WPAN/stm_list.c | 6 ++- src/utility/STM32_WPAN/tl_mbox.c | 6 +++ 7 files changed, 85 insertions(+), 12 deletions(-) diff --git a/src/utility/STM32_WPAN/app_conf_default.h b/src/utility/STM32_WPAN/app_conf_default.h index 71fc107b..bf2274a5 100644 --- a/src/utility/STM32_WPAN/app_conf_default.h +++ b/src/utility/STM32_WPAN/app_conf_default.h @@ -1,9 +1,9 @@ /* USER CODE BEGIN Header */ /** ****************************************************************************** - * @file app_conf.h + * @file app_conf_default.h * @author MCD Application Team - * @brief Application configuration file for STM32WPAN Middleware. + * @brief Default application configuration file for STM32WPAN Middleware. ****************************************************************************** * @attention * @@ -19,18 +19,40 @@ /* USER CODE END Header */ /* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef APP_CONF_H -#define APP_CONF_H +#ifndef APP_CONF_DEFAULT_H +#define APP_CONF_DEFAULT_H +#if 0 #include "hw.h" #include "hw_conf.h" #include "hw_if.h" #include "ble_bufsize.h" +#endif /****************************************************************************** * Application Config ******************************************************************************/ +/**< generic parameters ******************************************************/ +/* HCI related defines */ + +#define ACI_HAL_SET_TX_POWER_LEVEL 0xFC0F +#define ACI_WRITE_CONFIG_DATA_OPCODE 0xFC0C +#define ACI_READ_CONFIG_DATA_OPCODE 0xFC0D +#define MAX_HCI_ACL_PACKET_SIZE (sizeof(TL_PacketHeader_t) + 5 + 251) +#define HCI_RESET 0x0C03 + +#ifndef BLE_SHARED_MEM_BYTE_ORDER + #define BLE_SHARED_MEM_BYTE_ORDER MSBFIRST +#endif +#define BLE_MODULE_SHARED_MEM_BUFFER_SIZE 128 + +/** + * Define Tx Power + */ +#define CFG_TX_POWER (0x18) /* -0.15dBm */ + +#if 0 /** * Define Secure Connections Support */ @@ -104,6 +126,7 @@ #define CFG_FW_SUBVERSION (1) #define CFG_FW_BRANCH (0) #define CFG_FW_BUILD (0) +#endif /****************************************************************************** * BLE Stack @@ -250,7 +273,7 @@ * 0: LE Power Class 2-3 * other bits: complete with Options_extension flag */ -#define CFG_BLE_OPTIONS (SHCI_C2_BLE_INIT_OPTIONS_LL_HOST | SHCI_C2_BLE_INIT_OPTIONS_WITH_SVC_CHANGE_DESC | SHCI_C2_BLE_INIT_OPTIONS_DEVICE_NAME_RW | SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV | SHCI_C2_BLE_INIT_OPTIONS_CS_ALGO2 | SHCI_C2_BLE_INIT_OPTIONS_FULL_GATTDB_NVM | SHCI_C2_BLE_INIT_OPTIONS_GATT_CACHING_NOTUSED | SHCI_C2_BLE_INIT_OPTIONS_POWER_CLASS_2_3) +#define CFG_BLE_OPTIONS (SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY | SHCI_C2_BLE_INIT_OPTIONS_WITH_SVC_CHANGE_DESC | SHCI_C2_BLE_INIT_OPTIONS_DEVICE_NAME_RW | SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV | SHCI_C2_BLE_INIT_OPTIONS_CS_ALGO2 | SHCI_C2_BLE_INIT_OPTIONS_FULL_GATTDB_NVM | SHCI_C2_BLE_INIT_OPTIONS_GATT_CACHING_NOTUSED | SHCI_C2_BLE_INIT_OPTIONS_POWER_CLASS_2_3) /** * BLE stack Options_extension flags to be configured with: @@ -292,7 +315,11 @@ * This parameter is considered by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV flag set */ -#define CFG_BLE_MAX_ADV_SET_NBR (8) +#if defined(STM32WB15xx) + #define CFG_BLE_MAX_ADV_SET_NBR (3) +#else + #define CFG_BLE_MAX_ADV_SET_NBR (8) +#endif /* Maximum advertising data length (in bytes) * Range: 31 .. 1650 with limitation: @@ -301,7 +328,11 @@ * This parameter is considered by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV flag set */ -#define CFG_BLE_MAX_ADV_DATA_LEN (207) +#if defined(STM32WB15xx) + #define CFG_BLE_MAX_ADV_DATA_LEN (414) +#else + #define CFG_BLE_MAX_ADV_DATA_LEN (207) +#endif /* RF TX Path Compensation Value (16-bit signed integer). Units: 0.1 dB. * Range: -1280 .. 1280 @@ -324,6 +355,7 @@ #define CFG_BLE_CORE_VERSION (SHCI_C2_BLE_INIT_BLE_CORE_5_4) +#if 0 /****************************************************************************** * Transport Layer ******************************************************************************/ @@ -660,4 +692,5 @@ typedef enum #define CFG_OTP_END_ADRESS OTP_AREA_END_ADDR -#endif /*APP_CONF_H */ +#endif +#endif /*APP_CONF_DEFAULT_H */ diff --git a/src/utility/STM32_WPAN/hw.h b/src/utility/STM32_WPAN/hw.h index 651e1f17..1472a5e8 100644 --- a/src/utility/STM32_WPAN/hw.h +++ b/src/utility/STM32_WPAN/hw.h @@ -26,14 +26,23 @@ extern "C" { #endif /* Includes ------------------------------------------------------------------*/ +#include "stm32_def.h" +#include "stm32wbxx_ll_bus.h" +#include "stm32wbxx_ll_exti.h" +#include "stm32wbxx_ll_system.h" +#include "stm32wbxx_ll_rcc.h" +#include "stm32wbxx_ll_ipcc.h" +#include "stm32wbxx_ll_cortex.h" +#include "stm32wbxx_ll_utils.h" +#include "stm32wbxx_ll_pwr.h" /****************************************************************************** * HW IPCC ******************************************************************************/ void HW_IPCC_Enable( void ); void HW_IPCC_Init( void ); - void HW_IPCC_Rx_Handler( void ); - void HW_IPCC_Tx_Handler( void ); +#define HW_IPCC_Rx_Handler IPCC_C1_RX_IRQHandler +#define HW_IPCC_Tx_Handler IPCC_C1_TX_IRQHandler void HW_IPCC_BLE_Init( void ); void HW_IPCC_BLE_SendCmd( void ); diff --git a/src/utility/STM32_WPAN/hw_ipcc.c b/src/utility/STM32_WPAN/hw_ipcc.c index fd620b85..3461cbed 100644 --- a/src/utility/STM32_WPAN/hw_ipcc.c +++ b/src/utility/STM32_WPAN/hw_ipcc.c @@ -18,8 +18,9 @@ */ /* USER CODE END Header */ +#if defined(STM32WBxx) /* Includes ------------------------------------------------------------------*/ -#include "app_common.h" +#include "hw.h" #include "mbox_def.h" /* Global variables ---------------------------------------------------------*/ @@ -667,3 +668,4 @@ static void HW_IPCC_TRACES_EvtHandler( void ) } __weak void HW_IPCC_TRACES_EvtNot( void ){}; +#endif /* STM32WBxx */ diff --git a/src/utility/STM32_WPAN/shci.c b/src/utility/STM32_WPAN/shci.c index 5c32555e..40110f42 100644 --- a/src/utility/STM32_WPAN/shci.c +++ b/src/utility/STM32_WPAN/shci.c @@ -17,6 +17,7 @@ */ +#if defined(STM32WBxx) /* Includes ------------------------------------------------------------------*/ #include "stm32_wpan_common.h" @@ -759,3 +760,4 @@ SHCI_CmdStatus_t SHCI_GetWirelessFwInfo( WirelessFwInfo_t* pWirelessInfo ) return (SHCI_Success); } +#endif /* STM32WBxx */ diff --git a/src/utility/STM32_WPAN/shci_tl.c b/src/utility/STM32_WPAN/shci_tl.c index 0f604300..daa988c1 100644 --- a/src/utility/STM32_WPAN/shci_tl.c +++ b/src/utility/STM32_WPAN/shci_tl.c @@ -17,11 +17,13 @@ */ +#if defined(STM32WBxx) /* Includes ------------------------------------------------------------------*/ #include "stm32_wpan_common.h" #include "stm_list.h" #include "shci_tl.h" +#include "stm32_def.h" /* Private typedef -----------------------------------------------------------*/ typedef enum @@ -168,6 +170,20 @@ void shci_send( uint16_t cmd_code, uint8_t len_cmd_payload, uint8_t * p_cmd_payl return; } +void shci_notify_asynch_evt(void *pdata) +{ + UNUSED(pdata); + /* Need to parse data in future version */ + shci_user_evt_proc(); +} + +void shci_register_io_bus(tSHciIO *fops) +{ + /* Register IO bus services */ + fops->Init = TL_SYS_Init; + fops->Send = TL_SYS_SendCmd; +} + /* Private functions ---------------------------------------------------------*/ static void TlInit( TL_CmdPacket_t * p_cmdbuffer ) { @@ -250,3 +266,4 @@ __WEAK void shci_cmd_resp_release(uint32_t flag) return; } +#endif /* STM32WBxx */ diff --git a/src/utility/STM32_WPAN/stm_list.c b/src/utility/STM32_WPAN/stm_list.c index 4c928647..df6c2155 100644 --- a/src/utility/STM32_WPAN/stm_list.c +++ b/src/utility/STM32_WPAN/stm_list.c @@ -17,10 +17,13 @@ */ +#if defined(STM32WBxx) /****************************************************************************** * Include Files ******************************************************************************/ -#include "utilities_common.h" +#include "stdint.h" +#include "cmsis_gcc.h" +#include "stm32_wpan_common.h" #include "stm_list.h" @@ -204,3 +207,4 @@ void LST_get_prev_node (tListNode * ref_node, tListNode ** node) __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ } +#endif /* STM32WBxx */ diff --git a/src/utility/STM32_WPAN/tl_mbox.c b/src/utility/STM32_WPAN/tl_mbox.c index df07a197..9a2a2973 100644 --- a/src/utility/STM32_WPAN/tl_mbox.c +++ b/src/utility/STM32_WPAN/tl_mbox.c @@ -16,6 +16,7 @@ ****************************************************************************** */ +#if defined(STM32WBxx) /* Includes ------------------------------------------------------------------*/ #include "stm32_wpan_common.h" #include "hw.h" @@ -51,8 +52,10 @@ PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_BleLldTable_t TL_BleLldTable; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_SysTable_t TL_SysTable; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_MemManagerTable_t TL_MemManagerTable; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_TracesTable_t TL_TracesTable; +#if 0 PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_Mac_802_15_4_t TL_Mac_802_15_4_Table; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_ZigbeeTable_t TL_Zigbee_Table; +#endif /**< tables */ PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode FreeBufQueue; @@ -97,8 +100,10 @@ void TL_Init( void ) TL_RefTable.p_sys_table = &TL_SysTable; TL_RefTable.p_mem_manager_table = &TL_MemManagerTable; TL_RefTable.p_traces_table = &TL_TracesTable; +#if 0 TL_RefTable.p_mac_802_15_4_table = &TL_Mac_802_15_4_Table; TL_RefTable.p_zigbee_table = &TL_Zigbee_Table; +#endif HW_IPCC_Init(); return; @@ -847,3 +852,4 @@ static void OutputDbgTrace(TL_MB_PacketType_t packet_type, uint8_t* buffer) return; } +#endif /* STM32WBxx */ From faf4e9048be7c450278c6cb227f74d407bb4c480 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Thu, 13 Jul 2023 17:16:40 +0200 Subject: [PATCH 170/226] fix: include a timeout when waiting for the cmd_resp Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- src/utility/STM32_WPAN/shci_tl.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/utility/STM32_WPAN/shci_tl.c b/src/utility/STM32_WPAN/shci_tl.c index daa988c1..25e1a214 100644 --- a/src/utility/STM32_WPAN/shci_tl.c +++ b/src/utility/STM32_WPAN/shci_tl.c @@ -24,6 +24,7 @@ #include "stm_list.h" #include "shci_tl.h" #include "stm32_def.h" +#include "wiring_time.h" /* Private typedef -----------------------------------------------------------*/ typedef enum @@ -251,10 +252,11 @@ static void TlUserEvtReceived(TL_EvtPacket_t *shcievt) /* Weak implementation ----------------------------------------------------------------*/ __WEAK void shci_cmd_resp_wait(uint32_t timeout) { - (void)timeout; - - while(CmdRspStatusFlag != SHCI_TL_CMD_RESP_RELEASE); - + for (unsigned long start = millis(); (millis() - start) < timeout;) { + if (CmdRspStatusFlag == SHCI_TL_CMD_RESP_RELEASE) { + break; + } + } return; } From bae86c445bd4ff3ddbabd21f0ead27a05b0c83d3 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Wed, 10 Jan 2024 18:45:17 +0100 Subject: [PATCH 171/226] chore: add support for customize app_conf_default.h Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- src/utility/STM32_WPAN/app_conf_default.h | 58 ++++++++++++++++++----- 1 file changed, 45 insertions(+), 13 deletions(-) diff --git a/src/utility/STM32_WPAN/app_conf_default.h b/src/utility/STM32_WPAN/app_conf_default.h index bf2274a5..ff2dc017 100644 --- a/src/utility/STM32_WPAN/app_conf_default.h +++ b/src/utility/STM32_WPAN/app_conf_default.h @@ -50,7 +50,9 @@ /** * Define Tx Power */ -#define CFG_TX_POWER (0x18) /* -0.15dBm */ +#ifndef CFG_TX_POWER + #define CFG_TX_POWER (0x18) /* -0.15dBm */ +#endif #if 0 /** @@ -135,13 +137,25 @@ * Maximum number of simultaneous connections that the device will support. * Valid values are from 1 to 8 */ -#define CFG_BLE_NUM_LINK 8 +#ifndef CFG_BLE_NUM_LINK +#ifdef STM32WB15xx + #define CFG_BLE_NUM_LINK 3 +#else + #define CFG_BLE_NUM_LINK 8 +#endif +#endif /** * Maximum number of Services that can be stored in the GATT database. * Note that the GAP and GATT services are automatically added so this parameter should be 2 plus the number of user services */ -#define CFG_BLE_NUM_GATT_SERVICES 8 +#ifndef CFG_BLE_NUM_GATT_SERVICES +#ifdef STM32WB15xx + #define CFG_BLE_NUM_GATT_SERVICES 4 +#else + #define CFG_BLE_NUM_GATT_SERVICES 8 +#endif +#endif /** * Maximum number of Attributes @@ -150,7 +164,13 @@ * Note that certain characteristics and relative descriptors are added automatically during device initialization * so this parameters should be 9 plus the number of user Attributes */ -#define CFG_BLE_NUM_GATT_ATTRIBUTES 68 +#ifndef CFG_BLE_NUM_GATT_ATTRIBUTES +#ifdef STM32WB15xx + #define CFG_BLE_NUM_GATT_ATTRIBUTES 30 +#else + #define CFG_BLE_NUM_GATT_ATTRIBUTES 68 +#endif +#endif /** * Maximum supported ATT_MTU size @@ -186,12 +206,16 @@ /** * Enable or disable the Extended Packet length feature. Valid values are 0 or 1. */ -#define CFG_BLE_DATA_LENGTH_EXTENSION 1 +#ifndef CFG_BLE_DATA_LENGTH_EXTENSION + #define CFG_BLE_DATA_LENGTH_EXTENSION 1 +#endif /** * Sleep clock accuracy in Peripheral mode (ppm value) */ -#define CFG_BLE_PERIPHERAL_SCA 500 +#ifndef CFG_BLE_PERIPHERAL_SCA + #define CFG_BLE_PERIPHERAL_SCA 500 +#endif /** * Sleep clock accuracy in Central mode @@ -204,7 +228,9 @@ * 6 : 21 ppm to 30 ppm * 7 : 0 ppm to 20 ppm */ -#define CFG_BLE_CENTRAL_SCA 0 +#ifndef CFG_BLE_CENTRAL_SCA + #define CFG_BLE_CENTRAL_SCA 0 +#endif /** * LsSource @@ -213,21 +239,27 @@ * - bit 1: 1: STM32WB5M Module device 0: Other devices as STM32WBxx SOC, STM32WB1M module * - bit 2: 1: HSE/1024 Clock config 0: LSE Clock config */ -#if defined(STM32WB5Mxx) - #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_MOD5MM_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) -#else - #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_OTHER_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) +#ifndef CFG_BLE_LS_SOURCE + #if defined(STM32WB5Mxx) + #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_MOD5MM_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) + #else + #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_OTHER_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) + #endif #endif /** * Start up time of the high speed (16 or 32 MHz) crystal oscillator in units of 625/256 us (~2.44 us) */ -#define CFG_BLE_HSE_STARTUP_TIME 0x148 +#ifndef CFG_BLE_HSE_STARTUP_TIME + #define CFG_BLE_HSE_STARTUP_TIME 0x148 +#endif /** * Maximum duration of the connection event when the device is in Peripheral mode in units of 625/256 us (~2.44 us) */ -#define CFG_BLE_MAX_CONN_EVENT_LENGTH (0xFFFFFFFF) +#ifndef CFG_BLE_MAX_CONN_EVENT_LENGTH + #define CFG_BLE_MAX_CONN_EVENT_LENGTH (0xFFFFFFFF) +#endif /** * Viterbi Mode From bf11bf0a0a22919c8b79c48f0300878fad7e5d81 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Mon, 24 Jul 2023 10:55:20 +0200 Subject: [PATCH 172/226] fix: TL_Evt_t payload size for reset Within STM32CubeWB v1.17.0 update TL_Evt_t payload size was reduced. This produce a warning -Warray-bounds due to the reset management which require 4 bytes. Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- src/utility/STM32_WPAN/tl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utility/STM32_WPAN/tl.h b/src/utility/STM32_WPAN/tl.h index 8e8c6cbc..74520878 100644 --- a/src/utility/STM32_WPAN/tl.h +++ b/src/utility/STM32_WPAN/tl.h @@ -108,7 +108,7 @@ typedef PACKED_STRUCT { uint8_t evtcode; uint8_t plen; - uint8_t payload[2]; + uint8_t payload[4]; } TL_Evt_t; typedef PACKED_STRUCT From 433999896e26efed35bfded74699e8f20573be2a Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Wed, 10 Jan 2024 18:16:01 +0100 Subject: [PATCH 173/226] chore: regenerate STM32_WPAN patches Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- .../0001-chore-adapt-STM32_WPAN-sources.patch | 16 ++++++++-------- ...a-timeout-when-waiting-for-the-cmd_resp.patch | 2 +- ...upport-for-customize-app_conf_default.h.patch | 4 ++-- ...004-fix-TL_Evt_t-payload-size-for-reset.patch | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/extras/STM32_WPAN/0001-chore-adapt-STM32_WPAN-sources.patch b/extras/STM32_WPAN/0001-chore-adapt-STM32_WPAN-sources.patch index 90daace9..a3f62011 100644 --- a/extras/STM32_WPAN/0001-chore-adapt-STM32_WPAN-sources.patch +++ b/extras/STM32_WPAN/0001-chore-adapt-STM32_WPAN-sources.patch @@ -1,4 +1,4 @@ -From 5587ff466e0276de186103d21e6a4e498820e49f Mon Sep 17 00:00:00 2001 +From 7f99c89e8a6f834daf4a76bf98307e9ebcd01c91 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Wed, 10 Jan 2024 18:16:01 +0100 Subject: [PATCH 1/4] chore: adapt STM32_WPAN sources @@ -15,7 +15,7 @@ Signed-off-by: Frederic Pillon <frederic.pillon@st.com> 7 files changed, 85 insertions(+), 12 deletions(-) diff --git a/src/utility/STM32_WPAN/app_conf_default.h b/src/utility/STM32_WPAN/app_conf_default.h -index 846be3c..6c9beb3 100644 +index 71fc107..bf2274a 100644 --- a/src/utility/STM32_WPAN/app_conf_default.h +++ b/src/utility/STM32_WPAN/app_conf_default.h @@ -1,9 +1,9 @@ @@ -124,7 +124,7 @@ index 846be3c..6c9beb3 100644 /****************************************************************************** * Transport Layer ******************************************************************************/ -@@ -659,4 +691,5 @@ typedef enum +@@ -660,4 +692,5 @@ typedef enum #define CFG_OTP_END_ADRESS OTP_AREA_END_ADDR @@ -162,7 +162,7 @@ index 651e1f1..1472a5e 100644 void HW_IPCC_BLE_Init( void ); void HW_IPCC_BLE_SendCmd( void ); diff --git a/src/utility/STM32_WPAN/hw_ipcc.c b/src/utility/STM32_WPAN/hw_ipcc.c -index fd620b8..3461cbe 100644 +index 6a311b1..ad3c9d4 100644 --- a/src/utility/STM32_WPAN/hw_ipcc.c +++ b/src/utility/STM32_WPAN/hw_ipcc.c @@ -18,8 +18,9 @@ @@ -174,9 +174,9 @@ index fd620b8..3461cbe 100644 -#include "app_common.h" +#include "hw.h" #include "mbox_def.h" + #include "utilities_conf.h" - /* Global variables ---------------------------------------------------------*/ -@@ -667,3 +668,4 @@ static void HW_IPCC_TRACES_EvtHandler( void ) +@@ -745,3 +746,4 @@ static void HW_IPCC_TRACES_EvtHandler( void ) } __weak void HW_IPCC_TRACES_EvtNot( void ){}; @@ -267,7 +267,7 @@ index 4c92864..df6c215 100644 } +#endif /* STM32WBxx */ diff --git a/src/utility/STM32_WPAN/tl_mbox.c b/src/utility/STM32_WPAN/tl_mbox.c -index 27a998a..40c9679 100644 +index df07a19..9a2a297 100644 --- a/src/utility/STM32_WPAN/tl_mbox.c +++ b/src/utility/STM32_WPAN/tl_mbox.c @@ -16,6 +16,7 @@ @@ -300,7 +300,7 @@ index 27a998a..40c9679 100644 HW_IPCC_Init(); return; -@@ -846,3 +851,4 @@ static void OutputDbgTrace(TL_MB_PacketType_t packet_type, uint8_t* buffer) +@@ -847,3 +852,4 @@ static void OutputDbgTrace(TL_MB_PacketType_t packet_type, uint8_t* buffer) return; } diff --git a/extras/STM32_WPAN/0002-fix-include-a-timeout-when-waiting-for-the-cmd_resp.patch b/extras/STM32_WPAN/0002-fix-include-a-timeout-when-waiting-for-the-cmd_resp.patch index e234d198..bd6f66a2 100644 --- a/extras/STM32_WPAN/0002-fix-include-a-timeout-when-waiting-for-the-cmd_resp.patch +++ b/extras/STM32_WPAN/0002-fix-include-a-timeout-when-waiting-for-the-cmd_resp.patch @@ -1,4 +1,4 @@ -From 2867f96057d7bd5b34cfc3395d78653856f9cc7c Mon Sep 17 00:00:00 2001 +From a33328182e334e1ddedd368a047d75cf1662e330 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Thu, 13 Jul 2023 17:16:40 +0200 Subject: [PATCH 2/4] fix: include a timeout when waiting for the cmd_resp diff --git a/extras/STM32_WPAN/0003-chore-add-support-for-customize-app_conf_default.h.patch b/extras/STM32_WPAN/0003-chore-add-support-for-customize-app_conf_default.h.patch index bd66679d..3c5e66ae 100644 --- a/extras/STM32_WPAN/0003-chore-add-support-for-customize-app_conf_default.h.patch +++ b/extras/STM32_WPAN/0003-chore-add-support-for-customize-app_conf_default.h.patch @@ -1,4 +1,4 @@ -From ba3df1bd28eb49eab28a99fa88481f45fe565cbf Mon Sep 17 00:00:00 2001 +From a973b405bf34a93b0c300c8bbc4aa5d59fa182e5 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Wed, 10 Jan 2024 18:45:17 +0100 Subject: [PATCH 3/4] chore: add support for customize app_conf_default.h @@ -9,7 +9,7 @@ Signed-off-by: Frederic Pillon <frederic.pillon@st.com> 1 file changed, 45 insertions(+), 13 deletions(-) diff --git a/src/utility/STM32_WPAN/app_conf_default.h b/src/utility/STM32_WPAN/app_conf_default.h -index 6c9beb3..9509a0f 100644 +index bf2274a..ff2dc01 100644 --- a/src/utility/STM32_WPAN/app_conf_default.h +++ b/src/utility/STM32_WPAN/app_conf_default.h @@ -50,7 +50,9 @@ diff --git a/extras/STM32_WPAN/0004-fix-TL_Evt_t-payload-size-for-reset.patch b/extras/STM32_WPAN/0004-fix-TL_Evt_t-payload-size-for-reset.patch index 035d4b99..110a8410 100644 --- a/extras/STM32_WPAN/0004-fix-TL_Evt_t-payload-size-for-reset.patch +++ b/extras/STM32_WPAN/0004-fix-TL_Evt_t-payload-size-for-reset.patch @@ -1,4 +1,4 @@ -From a6ae9acf134d326f74ff04818b4e2c643c826b35 Mon Sep 17 00:00:00 2001 +From 324eef795bfd0a754aae4d5f9b528d4c8ad706c8 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Mon, 24 Jul 2023 10:55:20 +0200 Subject: [PATCH 4/4] fix: TL_Evt_t payload size for reset From f7ca0a26ed091f3f253d00bcc7fbbf1642d5515f Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Wed, 5 Mar 2025 09:30:56 +0100 Subject: [PATCH 174/226] chore: update STM32_WPAN from Cube version v1.22.0 Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- src/utility/STM32_WPAN/README.md | 4 +- src/utility/STM32_WPAN/app_conf_default.h | 105 +++++----------------- src/utility/STM32_WPAN/ble_bufsize.h | 6 +- src/utility/STM32_WPAN/hw.h | 13 +-- src/utility/STM32_WPAN/hw_ipcc.c | 82 ++++++++++++++++- src/utility/STM32_WPAN/shci.c | 2 - src/utility/STM32_WPAN/shci_tl.c | 27 +----- src/utility/STM32_WPAN/stm_list.c | 6 +- src/utility/STM32_WPAN/tl.h | 2 +- src/utility/STM32_WPAN/tl_mbox.c | 6 -- src/utility/STM32_WPAN/utilities_conf.h | 66 ++++++++++++++ 11 files changed, 178 insertions(+), 141 deletions(-) create mode 100644 src/utility/STM32_WPAN/utilities_conf.h diff --git a/src/utility/STM32_WPAN/README.md b/src/utility/STM32_WPAN/README.md index a9b3969a..90f96452 100644 --- a/src/utility/STM32_WPAN/README.md +++ b/src/utility/STM32_WPAN/README.md @@ -1,6 +1,6 @@ ## Source -[STMicroelectronics/STM32CubeWB Release v1.21.0](https://github.com/STMicroelectronics/STM32CubeWB/releases/tag/v1.21.0) -- Application: [BLE_TransparentMode](https://github.com/STMicroelectronics/STM32CubeWB/tree/v1.21.0/Projects/P-NUCLEO-WB55.Nucleo/Applications/BLE/BLE_TransparentMode) +[STMicroelectronics/STM32CubeWB Release v1.22.0](https://github.com/STMicroelectronics/STM32CubeWB/releases/tag/v1.22.0) +- Application: [BLE_TransparentMode](https://github.com/STMicroelectronics/STM32CubeWB/tree/v1.22.0/Projects/P-NUCLEO-WB55.Nucleo/Applications/BLE/BLE_TransparentMode) diff --git a/src/utility/STM32_WPAN/app_conf_default.h b/src/utility/STM32_WPAN/app_conf_default.h index ff2dc017..71fc107b 100644 --- a/src/utility/STM32_WPAN/app_conf_default.h +++ b/src/utility/STM32_WPAN/app_conf_default.h @@ -1,9 +1,9 @@ /* USER CODE BEGIN Header */ /** ****************************************************************************** - * @file app_conf_default.h + * @file app_conf.h * @author MCD Application Team - * @brief Default application configuration file for STM32WPAN Middleware. + * @brief Application configuration file for STM32WPAN Middleware. ****************************************************************************** * @attention * @@ -19,42 +19,18 @@ /* USER CODE END Header */ /* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef APP_CONF_DEFAULT_H -#define APP_CONF_DEFAULT_H +#ifndef APP_CONF_H +#define APP_CONF_H -#if 0 #include "hw.h" #include "hw_conf.h" #include "hw_if.h" #include "ble_bufsize.h" -#endif /****************************************************************************** * Application Config ******************************************************************************/ -/**< generic parameters ******************************************************/ -/* HCI related defines */ - -#define ACI_HAL_SET_TX_POWER_LEVEL 0xFC0F -#define ACI_WRITE_CONFIG_DATA_OPCODE 0xFC0C -#define ACI_READ_CONFIG_DATA_OPCODE 0xFC0D -#define MAX_HCI_ACL_PACKET_SIZE (sizeof(TL_PacketHeader_t) + 5 + 251) -#define HCI_RESET 0x0C03 - -#ifndef BLE_SHARED_MEM_BYTE_ORDER - #define BLE_SHARED_MEM_BYTE_ORDER MSBFIRST -#endif -#define BLE_MODULE_SHARED_MEM_BUFFER_SIZE 128 - -/** - * Define Tx Power - */ -#ifndef CFG_TX_POWER - #define CFG_TX_POWER (0x18) /* -0.15dBm */ -#endif - -#if 0 /** * Define Secure Connections Support */ @@ -128,7 +104,6 @@ #define CFG_FW_SUBVERSION (1) #define CFG_FW_BRANCH (0) #define CFG_FW_BUILD (0) -#endif /****************************************************************************** * BLE Stack @@ -137,25 +112,13 @@ * Maximum number of simultaneous connections that the device will support. * Valid values are from 1 to 8 */ -#ifndef CFG_BLE_NUM_LINK -#ifdef STM32WB15xx - #define CFG_BLE_NUM_LINK 3 -#else - #define CFG_BLE_NUM_LINK 8 -#endif -#endif +#define CFG_BLE_NUM_LINK 8 /** * Maximum number of Services that can be stored in the GATT database. * Note that the GAP and GATT services are automatically added so this parameter should be 2 plus the number of user services */ -#ifndef CFG_BLE_NUM_GATT_SERVICES -#ifdef STM32WB15xx - #define CFG_BLE_NUM_GATT_SERVICES 4 -#else - #define CFG_BLE_NUM_GATT_SERVICES 8 -#endif -#endif +#define CFG_BLE_NUM_GATT_SERVICES 8 /** * Maximum number of Attributes @@ -164,13 +127,7 @@ * Note that certain characteristics and relative descriptors are added automatically during device initialization * so this parameters should be 9 plus the number of user Attributes */ -#ifndef CFG_BLE_NUM_GATT_ATTRIBUTES -#ifdef STM32WB15xx - #define CFG_BLE_NUM_GATT_ATTRIBUTES 30 -#else - #define CFG_BLE_NUM_GATT_ATTRIBUTES 68 -#endif -#endif +#define CFG_BLE_NUM_GATT_ATTRIBUTES 68 /** * Maximum supported ATT_MTU size @@ -206,16 +163,12 @@ /** * Enable or disable the Extended Packet length feature. Valid values are 0 or 1. */ -#ifndef CFG_BLE_DATA_LENGTH_EXTENSION - #define CFG_BLE_DATA_LENGTH_EXTENSION 1 -#endif +#define CFG_BLE_DATA_LENGTH_EXTENSION 1 /** * Sleep clock accuracy in Peripheral mode (ppm value) */ -#ifndef CFG_BLE_PERIPHERAL_SCA - #define CFG_BLE_PERIPHERAL_SCA 500 -#endif +#define CFG_BLE_PERIPHERAL_SCA 500 /** * Sleep clock accuracy in Central mode @@ -228,9 +181,7 @@ * 6 : 21 ppm to 30 ppm * 7 : 0 ppm to 20 ppm */ -#ifndef CFG_BLE_CENTRAL_SCA - #define CFG_BLE_CENTRAL_SCA 0 -#endif +#define CFG_BLE_CENTRAL_SCA 0 /** * LsSource @@ -239,27 +190,21 @@ * - bit 1: 1: STM32WB5M Module device 0: Other devices as STM32WBxx SOC, STM32WB1M module * - bit 2: 1: HSE/1024 Clock config 0: LSE Clock config */ -#ifndef CFG_BLE_LS_SOURCE - #if defined(STM32WB5Mxx) - #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_MOD5MM_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) - #else - #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_OTHER_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) - #endif +#if defined(STM32WB5Mxx) + #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_MOD5MM_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) +#else + #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_OTHER_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) #endif /** * Start up time of the high speed (16 or 32 MHz) crystal oscillator in units of 625/256 us (~2.44 us) */ -#ifndef CFG_BLE_HSE_STARTUP_TIME - #define CFG_BLE_HSE_STARTUP_TIME 0x148 -#endif +#define CFG_BLE_HSE_STARTUP_TIME 0x148 /** * Maximum duration of the connection event when the device is in Peripheral mode in units of 625/256 us (~2.44 us) */ -#ifndef CFG_BLE_MAX_CONN_EVENT_LENGTH - #define CFG_BLE_MAX_CONN_EVENT_LENGTH (0xFFFFFFFF) -#endif +#define CFG_BLE_MAX_CONN_EVENT_LENGTH (0xFFFFFFFF) /** * Viterbi Mode @@ -305,7 +250,7 @@ * 0: LE Power Class 2-3 * other bits: complete with Options_extension flag */ -#define CFG_BLE_OPTIONS (SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY | SHCI_C2_BLE_INIT_OPTIONS_WITH_SVC_CHANGE_DESC | SHCI_C2_BLE_INIT_OPTIONS_DEVICE_NAME_RW | SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV | SHCI_C2_BLE_INIT_OPTIONS_CS_ALGO2 | SHCI_C2_BLE_INIT_OPTIONS_FULL_GATTDB_NVM | SHCI_C2_BLE_INIT_OPTIONS_GATT_CACHING_NOTUSED | SHCI_C2_BLE_INIT_OPTIONS_POWER_CLASS_2_3) +#define CFG_BLE_OPTIONS (SHCI_C2_BLE_INIT_OPTIONS_LL_HOST | SHCI_C2_BLE_INIT_OPTIONS_WITH_SVC_CHANGE_DESC | SHCI_C2_BLE_INIT_OPTIONS_DEVICE_NAME_RW | SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV | SHCI_C2_BLE_INIT_OPTIONS_CS_ALGO2 | SHCI_C2_BLE_INIT_OPTIONS_FULL_GATTDB_NVM | SHCI_C2_BLE_INIT_OPTIONS_GATT_CACHING_NOTUSED | SHCI_C2_BLE_INIT_OPTIONS_POWER_CLASS_2_3) /** * BLE stack Options_extension flags to be configured with: @@ -347,11 +292,7 @@ * This parameter is considered by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV flag set */ -#if defined(STM32WB15xx) - #define CFG_BLE_MAX_ADV_SET_NBR (3) -#else - #define CFG_BLE_MAX_ADV_SET_NBR (8) -#endif +#define CFG_BLE_MAX_ADV_SET_NBR (8) /* Maximum advertising data length (in bytes) * Range: 31 .. 1650 with limitation: @@ -360,11 +301,7 @@ * This parameter is considered by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV flag set */ -#if defined(STM32WB15xx) - #define CFG_BLE_MAX_ADV_DATA_LEN (414) -#else - #define CFG_BLE_MAX_ADV_DATA_LEN (207) -#endif +#define CFG_BLE_MAX_ADV_DATA_LEN (207) /* RF TX Path Compensation Value (16-bit signed integer). Units: 0.1 dB. * Range: -1280 .. 1280 @@ -387,7 +324,6 @@ #define CFG_BLE_CORE_VERSION (SHCI_C2_BLE_INIT_BLE_CORE_5_4) -#if 0 /****************************************************************************** * Transport Layer ******************************************************************************/ @@ -724,5 +660,4 @@ typedef enum #define CFG_OTP_END_ADRESS OTP_AREA_END_ADDR -#endif -#endif /*APP_CONF_DEFAULT_H */ +#endif /*APP_CONF_H */ diff --git a/src/utility/STM32_WPAN/ble_bufsize.h b/src/utility/STM32_WPAN/ble_bufsize.h index c5018420..26551c09 100644 --- a/src/utility/STM32_WPAN/ble_bufsize.h +++ b/src/utility/STM32_WPAN/ble_bufsize.h @@ -5,7 +5,7 @@ ***************************************************************************** * @attention * - * Copyright (c) 2018-2024 STMicroelectronics. + * Copyright (c) 2018-2025 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file @@ -97,7 +97,7 @@ * mentioned parameters. */ #if (BEACON_ONLY != 0) -#define BLE_FIXED_BUFFER_SIZE_BYTES 4100 /* Beacon only */ +#define BLE_FIXED_BUFFER_SIZE_BYTES 4200 /* Beacon only */ #elif (LL_ONLY_BASIC != 0) #define BLE_FIXED_BUFFER_SIZE_BYTES 6040 /* LL only Basic*/ #elif (LL_ONLY != 0) @@ -114,7 +114,7 @@ * BLE_PER_LINK_SIZE_BYTES: additional memory size used per link */ #if (BEACON_ONLY != 0) -#define BLE_PER_LINK_SIZE_BYTES 108 /* Beacon only */ +#define BLE_PER_LINK_SIZE_BYTES 76 /* Beacon only */ #elif (LL_ONLY_BASIC != 0) #define BLE_PER_LINK_SIZE_BYTES 244 /* LL only Basic */ #elif (LL_ONLY != 0) diff --git a/src/utility/STM32_WPAN/hw.h b/src/utility/STM32_WPAN/hw.h index 1472a5e8..651e1f17 100644 --- a/src/utility/STM32_WPAN/hw.h +++ b/src/utility/STM32_WPAN/hw.h @@ -26,23 +26,14 @@ extern "C" { #endif /* Includes ------------------------------------------------------------------*/ -#include "stm32_def.h" -#include "stm32wbxx_ll_bus.h" -#include "stm32wbxx_ll_exti.h" -#include "stm32wbxx_ll_system.h" -#include "stm32wbxx_ll_rcc.h" -#include "stm32wbxx_ll_ipcc.h" -#include "stm32wbxx_ll_cortex.h" -#include "stm32wbxx_ll_utils.h" -#include "stm32wbxx_ll_pwr.h" /****************************************************************************** * HW IPCC ******************************************************************************/ void HW_IPCC_Enable( void ); void HW_IPCC_Init( void ); -#define HW_IPCC_Rx_Handler IPCC_C1_RX_IRQHandler -#define HW_IPCC_Tx_Handler IPCC_C1_TX_IRQHandler + void HW_IPCC_Rx_Handler( void ); + void HW_IPCC_Tx_Handler( void ); void HW_IPCC_BLE_Init( void ); void HW_IPCC_BLE_SendCmd( void ); diff --git a/src/utility/STM32_WPAN/hw_ipcc.c b/src/utility/STM32_WPAN/hw_ipcc.c index 3461cbed..6a311b14 100644 --- a/src/utility/STM32_WPAN/hw_ipcc.c +++ b/src/utility/STM32_WPAN/hw_ipcc.c @@ -18,10 +18,10 @@ */ /* USER CODE END Header */ -#if defined(STM32WBxx) /* Includes ------------------------------------------------------------------*/ -#include "hw.h" +#include "app_common.h" #include "mbox_def.h" +#include "utilities_conf.h" /* Global variables ---------------------------------------------------------*/ /* Private defines -----------------------------------------------------------*/ @@ -227,7 +227,9 @@ void HW_IPCC_Init( void ) ******************************************************************************/ void HW_IPCC_BLE_Init( void ) { + UTILS_ENTER_CRITICAL_SECTION(); LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_BLE_EVENT_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); return; } @@ -251,14 +253,18 @@ static void HW_IPCC_BLE_EvtHandler( void ) void HW_IPCC_BLE_SendAclData( void ) { LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_HCI_ACL_DATA_CHANNEL ); + UTILS_ENTER_CRITICAL_SECTION(); LL_C1_IPCC_EnableTransmitChannel( IPCC, HW_IPCC_HCI_ACL_DATA_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); return; } static void HW_IPCC_BLE_AclDataEvtHandler( void ) { + UTILS_ENTER_CRITICAL_SECTION(); LL_C1_IPCC_DisableTransmitChannel( IPCC, HW_IPCC_HCI_ACL_DATA_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); HW_IPCC_BLE_AclDataAckNot(); @@ -273,7 +279,9 @@ __weak void HW_IPCC_BLE_RxEvtNot( void ){}; ******************************************************************************/ void HW_IPCC_SYS_Init( void ) { + UTILS_ENTER_CRITICAL_SECTION(); LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_SYSTEM_EVENT_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); return; } @@ -281,14 +289,18 @@ void HW_IPCC_SYS_Init( void ) void HW_IPCC_SYS_SendCmd( void ) { LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_SYSTEM_CMD_RSP_CHANNEL ); + UTILS_ENTER_CRITICAL_SECTION(); LL_C1_IPCC_EnableTransmitChannel( IPCC, HW_IPCC_SYSTEM_CMD_RSP_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); return; } static void HW_IPCC_SYS_CmdEvtHandler( void ) { + UTILS_ENTER_CRITICAL_SECTION(); LL_C1_IPCC_DisableTransmitChannel( IPCC, HW_IPCC_SYSTEM_CMD_RSP_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); HW_IPCC_SYS_CmdEvtNot(); @@ -313,7 +325,9 @@ __weak void HW_IPCC_SYS_EvtNot( void ){}; #ifdef MAC_802_15_4_WB void HW_IPCC_MAC_802_15_4_Init( void ) { + UTILS_ENTER_CRITICAL_SECTION(); LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); return; } @@ -321,7 +335,9 @@ void HW_IPCC_MAC_802_15_4_Init( void ) void HW_IPCC_MAC_802_15_4_SendCmd( void ) { LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL ); + UTILS_ENTER_CRITICAL_SECTION(); LL_C1_IPCC_EnableTransmitChannel( IPCC, HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); return; } @@ -329,14 +345,18 @@ void HW_IPCC_MAC_802_15_4_SendCmd( void ) void HW_IPCC_MAC_802_15_4_SendAck( void ) { LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL ); + UTILS_ENTER_CRITICAL_SECTION(); LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); return; } static void HW_IPCC_MAC_802_15_4_CmdEvtHandler( void ) { + UTILS_ENTER_CRITICAL_SECTION(); LL_C1_IPCC_DisableTransmitChannel( IPCC, HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); HW_IPCC_MAC_802_15_4_CmdEvtNot(); @@ -345,7 +365,9 @@ static void HW_IPCC_MAC_802_15_4_CmdEvtHandler( void ) static void HW_IPCC_MAC_802_15_4_NotEvtHandler( void ) { + UTILS_ENTER_CRITICAL_SECTION(); LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); HW_IPCC_MAC_802_15_4_EvtNot(); @@ -361,8 +383,10 @@ __weak void HW_IPCC_MAC_802_15_4_EvtNot( void ){}; #ifdef THREAD_WB void HW_IPCC_THREAD_Init( void ) { + UTILS_ENTER_CRITICAL_SECTION(); LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_THREAD_NOTIFICATION_ACK_CHANNEL ); LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_THREAD_CLI_NOTIFICATION_ACK_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); return; } @@ -370,7 +394,9 @@ void HW_IPCC_THREAD_Init( void ) void HW_IPCC_OT_SendCmd( void ) { LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_THREAD_OT_CMD_RSP_CHANNEL ); + UTILS_ENTER_CRITICAL_SECTION(); LL_C1_IPCC_EnableTransmitChannel( IPCC, HW_IPCC_THREAD_OT_CMD_RSP_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); return; } @@ -385,7 +411,9 @@ void HW_IPCC_CLI_SendCmd( void ) void HW_IPCC_THREAD_SendAck( void ) { LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_THREAD_NOTIFICATION_ACK_CHANNEL ); + UTILS_ENTER_CRITICAL_SECTION(); LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_THREAD_NOTIFICATION_ACK_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); return; } @@ -393,14 +421,18 @@ void HW_IPCC_THREAD_SendAck( void ) void HW_IPCC_THREAD_CliSendAck( void ) { LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_THREAD_CLI_NOTIFICATION_ACK_CHANNEL ); + UTILS_ENTER_CRITICAL_SECTION(); LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_THREAD_CLI_NOTIFICATION_ACK_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); return; } static void HW_IPCC_OT_CmdEvtHandler( void ) { + UTILS_ENTER_CRITICAL_SECTION(); LL_C1_IPCC_DisableTransmitChannel( IPCC, HW_IPCC_THREAD_OT_CMD_RSP_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); HW_IPCC_OT_CmdEvtNot(); @@ -409,7 +441,9 @@ static void HW_IPCC_OT_CmdEvtHandler( void ) static void HW_IPCC_THREAD_NotEvtHandler( void ) { + UTILS_ENTER_CRITICAL_SECTION(); LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_THREAD_NOTIFICATION_ACK_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); HW_IPCC_THREAD_EvtNot(); @@ -418,7 +452,9 @@ static void HW_IPCC_THREAD_NotEvtHandler( void ) static void HW_IPCC_THREAD_CliNotEvtHandler( void ) { + UTILS_ENTER_CRITICAL_SECTION(); LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_THREAD_CLI_NOTIFICATION_ACK_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); HW_IPCC_THREAD_CliEvtNot(); @@ -437,8 +473,10 @@ __weak void HW_IPCC_THREAD_EvtNot( void ){}; #ifdef LLD_TESTS_WB void HW_IPCC_LLDTESTS_Init( void ) { + UTILS_ENTER_CRITICAL_SECTION(); LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_LLDTESTS_CLI_RSP_CHANNEL ); LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_LLDTESTS_M0_CMD_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); return; } @@ -450,7 +488,10 @@ void HW_IPCC_LLDTESTS_SendCliCmd( void ) static void HW_IPCC_LLDTESTS_ReceiveCliRspHandler( void ) { + UTILS_ENTER_CRITICAL_SECTION(); LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_LLDTESTS_CLI_RSP_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); + HW_IPCC_LLDTESTS_ReceiveCliRsp(); return; } @@ -458,13 +499,17 @@ static void HW_IPCC_LLDTESTS_ReceiveCliRspHandler( void ) void HW_IPCC_LLDTESTS_SendCliRspAck( void ) { LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_LLDTESTS_CLI_RSP_CHANNEL ); + UTILS_ENTER_CRITICAL_SECTION(); LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_LLDTESTS_CLI_RSP_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); return; } static void HW_IPCC_LLDTESTS_ReceiveM0CmdHandler( void ) { + UTILS_ENTER_CRITICAL_SECTION(); LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_LLDTESTS_M0_CMD_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); HW_IPCC_LLDTESTS_ReceiveM0Cmd(); return; } @@ -472,7 +517,9 @@ static void HW_IPCC_LLDTESTS_ReceiveM0CmdHandler( void ) void HW_IPCC_LLDTESTS_SendM0CmdAck( void ) { LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_LLDTESTS_M0_CMD_CHANNEL ); + UTILS_ENTER_CRITICAL_SECTION(); LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_LLDTESTS_M0_CMD_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); return; } __weak void HW_IPCC_LLDTESTS_ReceiveCliRsp( void ){}; @@ -485,8 +532,10 @@ __weak void HW_IPCC_LLDTESTS_ReceiveM0Cmd( void ){}; #ifdef LLD_BLE_WB void HW_IPCC_LLD_BLE_Init( void ) { + UTILS_ENTER_CRITICAL_SECTION(); LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_LLD_BLE_RSP_CHANNEL ); LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_LLD_BLE_M0_CMD_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); return; } @@ -498,7 +547,9 @@ void HW_IPCC_LLD_BLE_SendCliCmd( void ) /*static void HW_IPCC_LLD_BLE_ReceiveCliRspHandler( void ) { + UTILS_ENTER_CRITICAL_SECTION(); LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_LLD_BLE_CLI_RSP_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); HW_IPCC_LLD_BLE_ReceiveCliRsp(); return; }*/ @@ -506,7 +557,9 @@ void HW_IPCC_LLD_BLE_SendCliCmd( void ) void HW_IPCC_LLD_BLE_SendCliRspAck( void ) { LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_LLD_BLE_CLI_RSP_CHANNEL ); + UTILS_ENTER_CRITICAL_SECTION(); LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_LLD_BLE_CLI_RSP_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); return; } @@ -535,7 +588,9 @@ void HW_IPCC_LLD_BLE_SendCmd( void ) static void HW_IPCC_LLD_BLE_ReceiveRspHandler( void ) { + UTILS_ENTER_CRITICAL_SECTION(); LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_LLD_BLE_RSP_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); HW_IPCC_LLD_BLE_ReceiveRsp(); return; } @@ -543,7 +598,9 @@ static void HW_IPCC_LLD_BLE_ReceiveRspHandler( void ) void HW_IPCC_LLD_BLE_SendRspAck( void ) { LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_LLD_BLE_RSP_CHANNEL ); + UTILS_ENTER_CRITICAL_SECTION(); LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_LLD_BLE_RSP_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); return; } @@ -555,8 +612,10 @@ void HW_IPCC_LLD_BLE_SendRspAck( void ) #ifdef ZIGBEE_WB void HW_IPCC_ZIGBEE_Init( void ) { + UTILS_ENTER_CRITICAL_SECTION(); LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL ); LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); return; } @@ -564,7 +623,9 @@ void HW_IPCC_ZIGBEE_Init( void ) void HW_IPCC_ZIGBEE_SendM4RequestToM0( void ) { LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL ); + UTILS_ENTER_CRITICAL_SECTION(); LL_C1_IPCC_EnableTransmitChannel( IPCC, HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); return; } @@ -572,14 +633,18 @@ void HW_IPCC_ZIGBEE_SendM4RequestToM0( void ) void HW_IPCC_ZIGBEE_SendM4AckToM0Notify( void ) { LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL ); + UTILS_ENTER_CRITICAL_SECTION(); LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); return; } static void HW_IPCC_ZIGBEE_CmdEvtHandler( void ) { + UTILS_ENTER_CRITICAL_SECTION(); LL_C1_IPCC_DisableTransmitChannel( IPCC, HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); HW_IPCC_ZIGBEE_RecvAppliAckFromM0(); @@ -588,7 +653,9 @@ static void HW_IPCC_ZIGBEE_CmdEvtHandler( void ) static void HW_IPCC_ZIGBEE_StackNotifEvtHandler( void ) { + UTILS_ENTER_CRITICAL_SECTION(); LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); HW_IPCC_ZIGBEE_RecvM0NotifyToM4(); @@ -597,7 +664,9 @@ static void HW_IPCC_ZIGBEE_StackNotifEvtHandler( void ) static void HW_IPCC_ZIGBEE_StackM0RequestHandler( void ) { + UTILS_ENTER_CRITICAL_SECTION(); LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); HW_IPCC_ZIGBEE_RecvM0RequestToM4(); @@ -607,7 +676,9 @@ static void HW_IPCC_ZIGBEE_StackM0RequestHandler( void ) void HW_IPCC_ZIGBEE_SendM4AckToM0Request( void ) { LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL ); + UTILS_ENTER_CRITICAL_SECTION(); LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); return; } @@ -625,7 +696,9 @@ void HW_IPCC_MM_SendFreeBuf( void (*cb)( void ) ) if ( LL_C1_IPCC_IsActiveFlag_CHx( IPCC, HW_IPCC_MM_RELEASE_BUFFER_CHANNEL ) ) { FreeBufCb = cb; + UTILS_ENTER_CRITICAL_SECTION(); LL_C1_IPCC_EnableTransmitChannel( IPCC, HW_IPCC_MM_RELEASE_BUFFER_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); } else { @@ -639,7 +712,9 @@ void HW_IPCC_MM_SendFreeBuf( void (*cb)( void ) ) static void HW_IPCC_MM_FreeBufHandler( void ) { + UTILS_ENTER_CRITICAL_SECTION(); LL_C1_IPCC_DisableTransmitChannel( IPCC, HW_IPCC_MM_RELEASE_BUFFER_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); FreeBufCb(); @@ -653,7 +728,9 @@ static void HW_IPCC_MM_FreeBufHandler( void ) ******************************************************************************/ void HW_IPCC_TRACES_Init( void ) { + UTILS_ENTER_CRITICAL_SECTION(); LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_TRACES_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); return; } @@ -668,4 +745,3 @@ static void HW_IPCC_TRACES_EvtHandler( void ) } __weak void HW_IPCC_TRACES_EvtNot( void ){}; -#endif /* STM32WBxx */ diff --git a/src/utility/STM32_WPAN/shci.c b/src/utility/STM32_WPAN/shci.c index 40110f42..5c32555e 100644 --- a/src/utility/STM32_WPAN/shci.c +++ b/src/utility/STM32_WPAN/shci.c @@ -17,7 +17,6 @@ */ -#if defined(STM32WBxx) /* Includes ------------------------------------------------------------------*/ #include "stm32_wpan_common.h" @@ -760,4 +759,3 @@ SHCI_CmdStatus_t SHCI_GetWirelessFwInfo( WirelessFwInfo_t* pWirelessInfo ) return (SHCI_Success); } -#endif /* STM32WBxx */ diff --git a/src/utility/STM32_WPAN/shci_tl.c b/src/utility/STM32_WPAN/shci_tl.c index 25e1a214..0f604300 100644 --- a/src/utility/STM32_WPAN/shci_tl.c +++ b/src/utility/STM32_WPAN/shci_tl.c @@ -17,14 +17,11 @@ */ -#if defined(STM32WBxx) /* Includes ------------------------------------------------------------------*/ #include "stm32_wpan_common.h" #include "stm_list.h" #include "shci_tl.h" -#include "stm32_def.h" -#include "wiring_time.h" /* Private typedef -----------------------------------------------------------*/ typedef enum @@ -171,20 +168,6 @@ void shci_send( uint16_t cmd_code, uint8_t len_cmd_payload, uint8_t * p_cmd_payl return; } -void shci_notify_asynch_evt(void *pdata) -{ - UNUSED(pdata); - /* Need to parse data in future version */ - shci_user_evt_proc(); -} - -void shci_register_io_bus(tSHciIO *fops) -{ - /* Register IO bus services */ - fops->Init = TL_SYS_Init; - fops->Send = TL_SYS_SendCmd; -} - /* Private functions ---------------------------------------------------------*/ static void TlInit( TL_CmdPacket_t * p_cmdbuffer ) { @@ -252,11 +235,10 @@ static void TlUserEvtReceived(TL_EvtPacket_t *shcievt) /* Weak implementation ----------------------------------------------------------------*/ __WEAK void shci_cmd_resp_wait(uint32_t timeout) { - for (unsigned long start = millis(); (millis() - start) < timeout;) { - if (CmdRspStatusFlag == SHCI_TL_CMD_RESP_RELEASE) { - break; - } - } + (void)timeout; + + while(CmdRspStatusFlag != SHCI_TL_CMD_RESP_RELEASE); + return; } @@ -268,4 +250,3 @@ __WEAK void shci_cmd_resp_release(uint32_t flag) return; } -#endif /* STM32WBxx */ diff --git a/src/utility/STM32_WPAN/stm_list.c b/src/utility/STM32_WPAN/stm_list.c index df6c2155..4c928647 100644 --- a/src/utility/STM32_WPAN/stm_list.c +++ b/src/utility/STM32_WPAN/stm_list.c @@ -17,13 +17,10 @@ */ -#if defined(STM32WBxx) /****************************************************************************** * Include Files ******************************************************************************/ -#include "stdint.h" -#include "cmsis_gcc.h" -#include "stm32_wpan_common.h" +#include "utilities_common.h" #include "stm_list.h" @@ -207,4 +204,3 @@ void LST_get_prev_node (tListNode * ref_node, tListNode ** node) __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ } -#endif /* STM32WBxx */ diff --git a/src/utility/STM32_WPAN/tl.h b/src/utility/STM32_WPAN/tl.h index 74520878..8e8c6cbc 100644 --- a/src/utility/STM32_WPAN/tl.h +++ b/src/utility/STM32_WPAN/tl.h @@ -108,7 +108,7 @@ typedef PACKED_STRUCT { uint8_t evtcode; uint8_t plen; - uint8_t payload[4]; + uint8_t payload[2]; } TL_Evt_t; typedef PACKED_STRUCT diff --git a/src/utility/STM32_WPAN/tl_mbox.c b/src/utility/STM32_WPAN/tl_mbox.c index 9a2a2973..df07a197 100644 --- a/src/utility/STM32_WPAN/tl_mbox.c +++ b/src/utility/STM32_WPAN/tl_mbox.c @@ -16,7 +16,6 @@ ****************************************************************************** */ -#if defined(STM32WBxx) /* Includes ------------------------------------------------------------------*/ #include "stm32_wpan_common.h" #include "hw.h" @@ -52,10 +51,8 @@ PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_BleLldTable_t TL_BleLldTable; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_SysTable_t TL_SysTable; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_MemManagerTable_t TL_MemManagerTable; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_TracesTable_t TL_TracesTable; -#if 0 PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_Mac_802_15_4_t TL_Mac_802_15_4_Table; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_ZigbeeTable_t TL_Zigbee_Table; -#endif /**< tables */ PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode FreeBufQueue; @@ -100,10 +97,8 @@ void TL_Init( void ) TL_RefTable.p_sys_table = &TL_SysTable; TL_RefTable.p_mem_manager_table = &TL_MemManagerTable; TL_RefTable.p_traces_table = &TL_TracesTable; -#if 0 TL_RefTable.p_mac_802_15_4_table = &TL_Mac_802_15_4_Table; TL_RefTable.p_zigbee_table = &TL_Zigbee_Table; -#endif HW_IPCC_Init(); return; @@ -852,4 +847,3 @@ static void OutputDbgTrace(TL_MB_PacketType_t packet_type, uint8_t* buffer) return; } -#endif /* STM32WBxx */ diff --git a/src/utility/STM32_WPAN/utilities_conf.h b/src/utility/STM32_WPAN/utilities_conf.h new file mode 100644 index 00000000..d6221a73 --- /dev/null +++ b/src/utility/STM32_WPAN/utilities_conf.h @@ -0,0 +1,66 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file utilities_conf.h + * @author MCD Application Team + * @brief Configuration file for STM32 Utilities. + ****************************************************************************** + * @attention + * + * Copyright (c) 2019-2021 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef UTILITIES_CONF_H +#define UTILITIES_CONF_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "cmsis_compiler.h" +#include "string.h" +#include "app_conf.h" + +/****************************************************************************** + * common + ******************************************************************************/ +#define UTILS_ENTER_CRITICAL_SECTION( ) uint32_t primask_bit = __get_PRIMASK( );\ + __disable_irq( ) + +#define UTILS_EXIT_CRITICAL_SECTION( ) __set_PRIMASK( primask_bit ) + +#define UTILS_MEMSET8( dest, value, size ) memset( dest, value, size); + +/****************************************************************************** + * tiny low power manager + * (any macro that does not need to be modified can be removed) + ******************************************************************************/ +#define UTIL_LPM_INIT_CRITICAL_SECTION( ) +#define UTIL_LPM_ENTER_CRITICAL_SECTION( ) UTILS_ENTER_CRITICAL_SECTION( ) +#define UTIL_LPM_EXIT_CRITICAL_SECTION( ) UTILS_EXIT_CRITICAL_SECTION( ) + +/****************************************************************************** + * sequencer + * (any macro that does not need to be modified can be removed) + ******************************************************************************/ +#define UTIL_SEQ_INIT_CRITICAL_SECTION( ) +#define UTIL_SEQ_ENTER_CRITICAL_SECTION( ) UTILS_ENTER_CRITICAL_SECTION( ) +#define UTIL_SEQ_EXIT_CRITICAL_SECTION( ) UTILS_EXIT_CRITICAL_SECTION( ) +#define UTIL_SEQ_CONF_TASK_NBR (32) +#define UTIL_SEQ_CONF_PRIO_NBR CFG_SCH_PRIO_NBR +#define UTIL_SEQ_MEMSET8( dest, value, size ) UTILS_MEMSET8( dest, value, size ) + +#ifdef __cplusplus +} +#endif + +#endif /*UTILITIES_CONF_H */ From 20b8a4c663e3dde6eb896d60ae2d25c167a03856 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Wed, 10 Jan 2024 18:16:01 +0100 Subject: [PATCH 175/226] chore: adapt STM32_WPAN sources Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- src/utility/STM32_WPAN/app_conf_default.h | 49 +++++++++++++++++++---- src/utility/STM32_WPAN/hw.h | 13 +++++- src/utility/STM32_WPAN/hw_ipcc.c | 4 +- src/utility/STM32_WPAN/shci.c | 2 + src/utility/STM32_WPAN/shci_tl.c | 17 ++++++++ src/utility/STM32_WPAN/stm_list.c | 6 ++- src/utility/STM32_WPAN/tl_mbox.c | 6 +++ 7 files changed, 85 insertions(+), 12 deletions(-) diff --git a/src/utility/STM32_WPAN/app_conf_default.h b/src/utility/STM32_WPAN/app_conf_default.h index 71fc107b..bf2274a5 100644 --- a/src/utility/STM32_WPAN/app_conf_default.h +++ b/src/utility/STM32_WPAN/app_conf_default.h @@ -1,9 +1,9 @@ /* USER CODE BEGIN Header */ /** ****************************************************************************** - * @file app_conf.h + * @file app_conf_default.h * @author MCD Application Team - * @brief Application configuration file for STM32WPAN Middleware. + * @brief Default application configuration file for STM32WPAN Middleware. ****************************************************************************** * @attention * @@ -19,18 +19,40 @@ /* USER CODE END Header */ /* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef APP_CONF_H -#define APP_CONF_H +#ifndef APP_CONF_DEFAULT_H +#define APP_CONF_DEFAULT_H +#if 0 #include "hw.h" #include "hw_conf.h" #include "hw_if.h" #include "ble_bufsize.h" +#endif /****************************************************************************** * Application Config ******************************************************************************/ +/**< generic parameters ******************************************************/ +/* HCI related defines */ + +#define ACI_HAL_SET_TX_POWER_LEVEL 0xFC0F +#define ACI_WRITE_CONFIG_DATA_OPCODE 0xFC0C +#define ACI_READ_CONFIG_DATA_OPCODE 0xFC0D +#define MAX_HCI_ACL_PACKET_SIZE (sizeof(TL_PacketHeader_t) + 5 + 251) +#define HCI_RESET 0x0C03 + +#ifndef BLE_SHARED_MEM_BYTE_ORDER + #define BLE_SHARED_MEM_BYTE_ORDER MSBFIRST +#endif +#define BLE_MODULE_SHARED_MEM_BUFFER_SIZE 128 + +/** + * Define Tx Power + */ +#define CFG_TX_POWER (0x18) /* -0.15dBm */ + +#if 0 /** * Define Secure Connections Support */ @@ -104,6 +126,7 @@ #define CFG_FW_SUBVERSION (1) #define CFG_FW_BRANCH (0) #define CFG_FW_BUILD (0) +#endif /****************************************************************************** * BLE Stack @@ -250,7 +273,7 @@ * 0: LE Power Class 2-3 * other bits: complete with Options_extension flag */ -#define CFG_BLE_OPTIONS (SHCI_C2_BLE_INIT_OPTIONS_LL_HOST | SHCI_C2_BLE_INIT_OPTIONS_WITH_SVC_CHANGE_DESC | SHCI_C2_BLE_INIT_OPTIONS_DEVICE_NAME_RW | SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV | SHCI_C2_BLE_INIT_OPTIONS_CS_ALGO2 | SHCI_C2_BLE_INIT_OPTIONS_FULL_GATTDB_NVM | SHCI_C2_BLE_INIT_OPTIONS_GATT_CACHING_NOTUSED | SHCI_C2_BLE_INIT_OPTIONS_POWER_CLASS_2_3) +#define CFG_BLE_OPTIONS (SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY | SHCI_C2_BLE_INIT_OPTIONS_WITH_SVC_CHANGE_DESC | SHCI_C2_BLE_INIT_OPTIONS_DEVICE_NAME_RW | SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV | SHCI_C2_BLE_INIT_OPTIONS_CS_ALGO2 | SHCI_C2_BLE_INIT_OPTIONS_FULL_GATTDB_NVM | SHCI_C2_BLE_INIT_OPTIONS_GATT_CACHING_NOTUSED | SHCI_C2_BLE_INIT_OPTIONS_POWER_CLASS_2_3) /** * BLE stack Options_extension flags to be configured with: @@ -292,7 +315,11 @@ * This parameter is considered by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV flag set */ -#define CFG_BLE_MAX_ADV_SET_NBR (8) +#if defined(STM32WB15xx) + #define CFG_BLE_MAX_ADV_SET_NBR (3) +#else + #define CFG_BLE_MAX_ADV_SET_NBR (8) +#endif /* Maximum advertising data length (in bytes) * Range: 31 .. 1650 with limitation: @@ -301,7 +328,11 @@ * This parameter is considered by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV flag set */ -#define CFG_BLE_MAX_ADV_DATA_LEN (207) +#if defined(STM32WB15xx) + #define CFG_BLE_MAX_ADV_DATA_LEN (414) +#else + #define CFG_BLE_MAX_ADV_DATA_LEN (207) +#endif /* RF TX Path Compensation Value (16-bit signed integer). Units: 0.1 dB. * Range: -1280 .. 1280 @@ -324,6 +355,7 @@ #define CFG_BLE_CORE_VERSION (SHCI_C2_BLE_INIT_BLE_CORE_5_4) +#if 0 /****************************************************************************** * Transport Layer ******************************************************************************/ @@ -660,4 +692,5 @@ typedef enum #define CFG_OTP_END_ADRESS OTP_AREA_END_ADDR -#endif /*APP_CONF_H */ +#endif +#endif /*APP_CONF_DEFAULT_H */ diff --git a/src/utility/STM32_WPAN/hw.h b/src/utility/STM32_WPAN/hw.h index 651e1f17..1472a5e8 100644 --- a/src/utility/STM32_WPAN/hw.h +++ b/src/utility/STM32_WPAN/hw.h @@ -26,14 +26,23 @@ extern "C" { #endif /* Includes ------------------------------------------------------------------*/ +#include "stm32_def.h" +#include "stm32wbxx_ll_bus.h" +#include "stm32wbxx_ll_exti.h" +#include "stm32wbxx_ll_system.h" +#include "stm32wbxx_ll_rcc.h" +#include "stm32wbxx_ll_ipcc.h" +#include "stm32wbxx_ll_cortex.h" +#include "stm32wbxx_ll_utils.h" +#include "stm32wbxx_ll_pwr.h" /****************************************************************************** * HW IPCC ******************************************************************************/ void HW_IPCC_Enable( void ); void HW_IPCC_Init( void ); - void HW_IPCC_Rx_Handler( void ); - void HW_IPCC_Tx_Handler( void ); +#define HW_IPCC_Rx_Handler IPCC_C1_RX_IRQHandler +#define HW_IPCC_Tx_Handler IPCC_C1_TX_IRQHandler void HW_IPCC_BLE_Init( void ); void HW_IPCC_BLE_SendCmd( void ); diff --git a/src/utility/STM32_WPAN/hw_ipcc.c b/src/utility/STM32_WPAN/hw_ipcc.c index 6a311b14..ad3c9d4c 100644 --- a/src/utility/STM32_WPAN/hw_ipcc.c +++ b/src/utility/STM32_WPAN/hw_ipcc.c @@ -18,8 +18,9 @@ */ /* USER CODE END Header */ +#if defined(STM32WBxx) /* Includes ------------------------------------------------------------------*/ -#include "app_common.h" +#include "hw.h" #include "mbox_def.h" #include "utilities_conf.h" @@ -745,3 +746,4 @@ static void HW_IPCC_TRACES_EvtHandler( void ) } __weak void HW_IPCC_TRACES_EvtNot( void ){}; +#endif /* STM32WBxx */ diff --git a/src/utility/STM32_WPAN/shci.c b/src/utility/STM32_WPAN/shci.c index 5c32555e..40110f42 100644 --- a/src/utility/STM32_WPAN/shci.c +++ b/src/utility/STM32_WPAN/shci.c @@ -17,6 +17,7 @@ */ +#if defined(STM32WBxx) /* Includes ------------------------------------------------------------------*/ #include "stm32_wpan_common.h" @@ -759,3 +760,4 @@ SHCI_CmdStatus_t SHCI_GetWirelessFwInfo( WirelessFwInfo_t* pWirelessInfo ) return (SHCI_Success); } +#endif /* STM32WBxx */ diff --git a/src/utility/STM32_WPAN/shci_tl.c b/src/utility/STM32_WPAN/shci_tl.c index 0f604300..daa988c1 100644 --- a/src/utility/STM32_WPAN/shci_tl.c +++ b/src/utility/STM32_WPAN/shci_tl.c @@ -17,11 +17,13 @@ */ +#if defined(STM32WBxx) /* Includes ------------------------------------------------------------------*/ #include "stm32_wpan_common.h" #include "stm_list.h" #include "shci_tl.h" +#include "stm32_def.h" /* Private typedef -----------------------------------------------------------*/ typedef enum @@ -168,6 +170,20 @@ void shci_send( uint16_t cmd_code, uint8_t len_cmd_payload, uint8_t * p_cmd_payl return; } +void shci_notify_asynch_evt(void *pdata) +{ + UNUSED(pdata); + /* Need to parse data in future version */ + shci_user_evt_proc(); +} + +void shci_register_io_bus(tSHciIO *fops) +{ + /* Register IO bus services */ + fops->Init = TL_SYS_Init; + fops->Send = TL_SYS_SendCmd; +} + /* Private functions ---------------------------------------------------------*/ static void TlInit( TL_CmdPacket_t * p_cmdbuffer ) { @@ -250,3 +266,4 @@ __WEAK void shci_cmd_resp_release(uint32_t flag) return; } +#endif /* STM32WBxx */ diff --git a/src/utility/STM32_WPAN/stm_list.c b/src/utility/STM32_WPAN/stm_list.c index 4c928647..df6c2155 100644 --- a/src/utility/STM32_WPAN/stm_list.c +++ b/src/utility/STM32_WPAN/stm_list.c @@ -17,10 +17,13 @@ */ +#if defined(STM32WBxx) /****************************************************************************** * Include Files ******************************************************************************/ -#include "utilities_common.h" +#include "stdint.h" +#include "cmsis_gcc.h" +#include "stm32_wpan_common.h" #include "stm_list.h" @@ -204,3 +207,4 @@ void LST_get_prev_node (tListNode * ref_node, tListNode ** node) __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ } +#endif /* STM32WBxx */ diff --git a/src/utility/STM32_WPAN/tl_mbox.c b/src/utility/STM32_WPAN/tl_mbox.c index df07a197..9a2a2973 100644 --- a/src/utility/STM32_WPAN/tl_mbox.c +++ b/src/utility/STM32_WPAN/tl_mbox.c @@ -16,6 +16,7 @@ ****************************************************************************** */ +#if defined(STM32WBxx) /* Includes ------------------------------------------------------------------*/ #include "stm32_wpan_common.h" #include "hw.h" @@ -51,8 +52,10 @@ PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_BleLldTable_t TL_BleLldTable; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_SysTable_t TL_SysTable; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_MemManagerTable_t TL_MemManagerTable; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_TracesTable_t TL_TracesTable; +#if 0 PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_Mac_802_15_4_t TL_Mac_802_15_4_Table; PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_ZigbeeTable_t TL_Zigbee_Table; +#endif /**< tables */ PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode FreeBufQueue; @@ -97,8 +100,10 @@ void TL_Init( void ) TL_RefTable.p_sys_table = &TL_SysTable; TL_RefTable.p_mem_manager_table = &TL_MemManagerTable; TL_RefTable.p_traces_table = &TL_TracesTable; +#if 0 TL_RefTable.p_mac_802_15_4_table = &TL_Mac_802_15_4_Table; TL_RefTable.p_zigbee_table = &TL_Zigbee_Table; +#endif HW_IPCC_Init(); return; @@ -847,3 +852,4 @@ static void OutputDbgTrace(TL_MB_PacketType_t packet_type, uint8_t* buffer) return; } +#endif /* STM32WBxx */ From 974ce4cf8389edac59c1f416e7d99e56db2d7ccb Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Thu, 13 Jul 2023 17:16:40 +0200 Subject: [PATCH 176/226] fix: include a timeout when waiting for the cmd_resp Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- src/utility/STM32_WPAN/shci_tl.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/utility/STM32_WPAN/shci_tl.c b/src/utility/STM32_WPAN/shci_tl.c index daa988c1..25e1a214 100644 --- a/src/utility/STM32_WPAN/shci_tl.c +++ b/src/utility/STM32_WPAN/shci_tl.c @@ -24,6 +24,7 @@ #include "stm_list.h" #include "shci_tl.h" #include "stm32_def.h" +#include "wiring_time.h" /* Private typedef -----------------------------------------------------------*/ typedef enum @@ -251,10 +252,11 @@ static void TlUserEvtReceived(TL_EvtPacket_t *shcievt) /* Weak implementation ----------------------------------------------------------------*/ __WEAK void shci_cmd_resp_wait(uint32_t timeout) { - (void)timeout; - - while(CmdRspStatusFlag != SHCI_TL_CMD_RESP_RELEASE); - + for (unsigned long start = millis(); (millis() - start) < timeout;) { + if (CmdRspStatusFlag == SHCI_TL_CMD_RESP_RELEASE) { + break; + } + } return; } From 5a5dc8e921c7b0f7e7854f6ab257abb3be30b18a Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Wed, 10 Jan 2024 18:45:17 +0100 Subject: [PATCH 177/226] chore: add support for customize app_conf_default.h Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- src/utility/STM32_WPAN/app_conf_default.h | 58 ++++++++++++++++++----- 1 file changed, 45 insertions(+), 13 deletions(-) diff --git a/src/utility/STM32_WPAN/app_conf_default.h b/src/utility/STM32_WPAN/app_conf_default.h index bf2274a5..ff2dc017 100644 --- a/src/utility/STM32_WPAN/app_conf_default.h +++ b/src/utility/STM32_WPAN/app_conf_default.h @@ -50,7 +50,9 @@ /** * Define Tx Power */ -#define CFG_TX_POWER (0x18) /* -0.15dBm */ +#ifndef CFG_TX_POWER + #define CFG_TX_POWER (0x18) /* -0.15dBm */ +#endif #if 0 /** @@ -135,13 +137,25 @@ * Maximum number of simultaneous connections that the device will support. * Valid values are from 1 to 8 */ -#define CFG_BLE_NUM_LINK 8 +#ifndef CFG_BLE_NUM_LINK +#ifdef STM32WB15xx + #define CFG_BLE_NUM_LINK 3 +#else + #define CFG_BLE_NUM_LINK 8 +#endif +#endif /** * Maximum number of Services that can be stored in the GATT database. * Note that the GAP and GATT services are automatically added so this parameter should be 2 plus the number of user services */ -#define CFG_BLE_NUM_GATT_SERVICES 8 +#ifndef CFG_BLE_NUM_GATT_SERVICES +#ifdef STM32WB15xx + #define CFG_BLE_NUM_GATT_SERVICES 4 +#else + #define CFG_BLE_NUM_GATT_SERVICES 8 +#endif +#endif /** * Maximum number of Attributes @@ -150,7 +164,13 @@ * Note that certain characteristics and relative descriptors are added automatically during device initialization * so this parameters should be 9 plus the number of user Attributes */ -#define CFG_BLE_NUM_GATT_ATTRIBUTES 68 +#ifndef CFG_BLE_NUM_GATT_ATTRIBUTES +#ifdef STM32WB15xx + #define CFG_BLE_NUM_GATT_ATTRIBUTES 30 +#else + #define CFG_BLE_NUM_GATT_ATTRIBUTES 68 +#endif +#endif /** * Maximum supported ATT_MTU size @@ -186,12 +206,16 @@ /** * Enable or disable the Extended Packet length feature. Valid values are 0 or 1. */ -#define CFG_BLE_DATA_LENGTH_EXTENSION 1 +#ifndef CFG_BLE_DATA_LENGTH_EXTENSION + #define CFG_BLE_DATA_LENGTH_EXTENSION 1 +#endif /** * Sleep clock accuracy in Peripheral mode (ppm value) */ -#define CFG_BLE_PERIPHERAL_SCA 500 +#ifndef CFG_BLE_PERIPHERAL_SCA + #define CFG_BLE_PERIPHERAL_SCA 500 +#endif /** * Sleep clock accuracy in Central mode @@ -204,7 +228,9 @@ * 6 : 21 ppm to 30 ppm * 7 : 0 ppm to 20 ppm */ -#define CFG_BLE_CENTRAL_SCA 0 +#ifndef CFG_BLE_CENTRAL_SCA + #define CFG_BLE_CENTRAL_SCA 0 +#endif /** * LsSource @@ -213,21 +239,27 @@ * - bit 1: 1: STM32WB5M Module device 0: Other devices as STM32WBxx SOC, STM32WB1M module * - bit 2: 1: HSE/1024 Clock config 0: LSE Clock config */ -#if defined(STM32WB5Mxx) - #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_MOD5MM_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) -#else - #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_OTHER_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) +#ifndef CFG_BLE_LS_SOURCE + #if defined(STM32WB5Mxx) + #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_MOD5MM_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) + #else + #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_OTHER_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) + #endif #endif /** * Start up time of the high speed (16 or 32 MHz) crystal oscillator in units of 625/256 us (~2.44 us) */ -#define CFG_BLE_HSE_STARTUP_TIME 0x148 +#ifndef CFG_BLE_HSE_STARTUP_TIME + #define CFG_BLE_HSE_STARTUP_TIME 0x148 +#endif /** * Maximum duration of the connection event when the device is in Peripheral mode in units of 625/256 us (~2.44 us) */ -#define CFG_BLE_MAX_CONN_EVENT_LENGTH (0xFFFFFFFF) +#ifndef CFG_BLE_MAX_CONN_EVENT_LENGTH + #define CFG_BLE_MAX_CONN_EVENT_LENGTH (0xFFFFFFFF) +#endif /** * Viterbi Mode From 6f7c381684aaa14b3241280beedd106732dcd0ab Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Mon, 24 Jul 2023 10:55:20 +0200 Subject: [PATCH 178/226] fix: TL_Evt_t payload size for reset Within STM32CubeWB v1.17.0 update TL_Evt_t payload size was reduced. This produce a warning -Warray-bounds due to the reset management which require 4 bytes. Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- src/utility/STM32_WPAN/tl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utility/STM32_WPAN/tl.h b/src/utility/STM32_WPAN/tl.h index 8e8c6cbc..74520878 100644 --- a/src/utility/STM32_WPAN/tl.h +++ b/src/utility/STM32_WPAN/tl.h @@ -108,7 +108,7 @@ typedef PACKED_STRUCT { uint8_t evtcode; uint8_t plen; - uint8_t payload[2]; + uint8_t payload[4]; } TL_Evt_t; typedef PACKED_STRUCT From 13b3a1a7de1a7b694b02084e450b5fe18a2f12d2 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Wed, 5 Mar 2025 10:12:19 +0100 Subject: [PATCH 179/226] chore: update library.properties Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index 6f0833c7..630fdc92 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=STM32duinoBLE -version=1.2.8 +version=1.2.9 author=Arduino, SRA maintainer=stm32duino sentence=Fork of ArduinoBLE library to add the support of STM32WB, SPBTLE-RF, SPBTLE-1S, BLUENRG-M2SP and BLUENRG-M0 BLE modules. From 3fd5a50fd18c2b0644d1a8e2d74045fa9beafd96 Mon Sep 17 00:00:00 2001 From: Carlo Parata <carlo.parata@st.com> Date: Thu, 19 Sep 2019 10:33:53 +0200 Subject: [PATCH 180/226] feat: add HCISpiTransport To support to STBTLE-RF, STBTLE-1S, BLUENRG-M2SP, BLUENRG-LP and BLUENRG-M0. Signed-off-by: Carlo Parata <carlo.parata@st.com> Co-authored-by: Frederic Pillon <frederic.pillon@st.com> --- keywords.txt | 9 + src/utility/HCISpiTransport.cpp | 1399 +++++++++++++++++++++++++++++++ src/utility/HCISpiTransport.h | 83 ++ 3 files changed, 1491 insertions(+) create mode 100644 src/utility/HCISpiTransport.cpp create mode 100644 src/utility/HCISpiTransport.h diff --git a/keywords.txt b/keywords.txt index effdfbca..ecfbafbf 100644 --- a/keywords.txt +++ b/keywords.txt @@ -30,6 +30,8 @@ BLEFloatCharacteristic KEYWORD1 BLEDoubleCharacteristic KEYWORD1 BLEStringCharacteristic KEYWORD1 +HCISpiTransportClass KEYWORD1 + ####################################### # Methods and Functions (KEYWORD2) ####################################### @@ -136,3 +138,10 @@ BLEUnsubscribed LITERAL1 BLEWritten LITERAL1 BLEUpdated LITERAL1 +SPBTLE_RF LITERAL1 +SPBTLE_1S LITERAL1 +BLUENRG_M2SP LITERAL1 +BLUENRG_M0 LITERAL1 +BLUENRG_LP LITERAL1 +BLEChip_t LITERAL1 + diff --git a/src/utility/HCISpiTransport.cpp b/src/utility/HCISpiTransport.cpp new file mode 100644 index 00000000..91c2c5dc --- /dev/null +++ b/src/utility/HCISpiTransport.cpp @@ -0,0 +1,1399 @@ +/* + This file is part of the STM32duinoBLE library. + Copyright (c) 2019 STMicroelectronics. All rights reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include "HCISpiTransport.h" + +#if defined(ARDUINO_STEVAL_MKBOXPRO) +/* STEVAL-MKBOXPRO */ +SPIClass SpiHCI(PA7, PA6, PA5); +HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_LP, PA2, PB11, PD4, 1000000, SPI_MODE3); +#elif defined(ARDUINO_STEVAL_MKSBOX1V1) +/* STEVAL-MKSBOX1V1 */ +SPIClass SpiHCI(PC3, PD3, PD1); +HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_1S, PD0, PD4, PA8, 1000000, SPI_MODE1); +#elif defined(ARDUINO_B_L475E_IOT01A) || defined(ARDUINO_B_L4S5I_IOT01A) +/* B-L475E-IOT01A1 or B_L4S5I_IOT01A */ +SPIClass SpiHCI(PC12, PC11, PC10); +HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, PD13, PE6, PA8, 8000000, SPI_MODE0); +#elif defined(ARDUINO_STM32L562E_DK) +/* STM32L562E-DK */ +SPIClass SpiHCI(PG4, PG3, PG2); +HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M0, PG5, PG6, PG8, 8000000, SPI_MODE0); +#elif defined(IDB05A2_SPI_CLOCK_D3) +/* Shield IDB05A2 with SPI clock on D3 */ +SPIClass SpiHCI(D11, D12, D3); +HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M0, A1, A0, D7, 8000000, SPI_MODE0); +#elif defined(IDB05A2_SPI_CLOCK_D13) +/* Shield IDB05A2 with SPI clock on D13 */ +#define SpiHCI SPI +HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M0, A1, A0, D7, 8000000, SPI_MODE0); +#elif defined(IDB05A1_SPI_CLOCK_D3) +/* Shield IDB05A1 with SPI clock on D3 */ +SPIClass SpiHCI(D11, D12, D3); +HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI_MODE0); +#elif defined(IDB05A1_SPI_CLOCK_D13) +/* Shield IDB05A1 with SPI clock on D13 */ +#define SpiHCI SPI +HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI_MODE0); +#elif defined(BNRG2A1_CLOCK_D3) +/* Shield BNRG2A1 with SPI clock on D3 */ +SPIClass SpiHCI(D11, D12, D3); +HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1); +#elif defined(BNRG2A1_CLOCK_D13) +/* Shield BNRG2A1 with SPI clock on D13 */ +#define SpiHCI SPI +HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1); +#else +#error "Unsupported board or shield selected!" +#endif + +volatile int data_avail = 0; + +HCISpiTransportClass::HCISpiTransportClass(SPIClass &spi, BLEChip_t ble_chip, uint8_t cs_pin, uint8_t spi_irq, uint8_t ble_rst, uint32_t frequency, uint8_t spi_mode) : + _spi(&spi), + _ble_chip(ble_chip), + _cs_pin(cs_pin), + _spi_irq(spi_irq), + _ble_rst(ble_rst) +{ + _spiSettings = SPISettings(frequency, (BitOrder)BLE_SPI_BYTE_ORDER, spi_mode); + _read_index = 0; + _write_index = 0; + _write_index_initial = 0; + _initial_phase = 1; + _random_addr_done = false; +} + +HCISpiTransportClass::~HCISpiTransportClass() +{ +} + +extern "C" void SPI_Irq_Callback(void) +{ + data_avail = 1; +} + +int HCISpiTransportClass::begin() +{ + _read_index = 0; + _write_index = 0; + _write_index_initial = 0; + _initial_phase = 1; + memset(_rxbuff, 0, sizeof(_rxbuff)); + pinMode(_cs_pin, OUTPUT); + digitalWrite(_cs_pin, HIGH); + + _spi->begin(); + + pinMode(_spi_irq, INPUT); + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + + // Reset chip + pinMode(_ble_rst, OUTPUT); + digitalWrite(_ble_rst, LOW); + delay(5); + digitalWrite(_ble_rst, HIGH); + delay(5); + + if (_ble_chip == SPBTLE_RF || _ble_chip == BLUENRG_M0 || _ble_chip == BLUENRG_LP || _ble_chip == BLUENRG_M2SP) { + // Wait for Blue Initialize + wait_for_blue_initialize(); + } else if (_ble_chip == SPBTLE_1S) { + // Wait a while for the reset of the BLE module + delay(300); + } else { + // BLE chip not supported + return 0; + } + + return 1; +} + +void HCISpiTransportClass::end() +{ + detachInterrupt(_spi_irq); + _spi->end(); +} + +void HCISpiTransportClass::wait(unsigned long timeout) +{ + for (unsigned long start = millis(); (millis() - start) < timeout;) { + if (available()) { + break; + } + } +} + +int HCISpiTransportClass::available() +{ + if (_ble_chip != SPBTLE_RF && _ble_chip != SPBTLE_1S && _ble_chip != BLUENRG_M2SP && _ble_chip != BLUENRG_M0 && _ble_chip != BLUENRG_LP) { + return 0; + } + + if (_read_index != _write_index) { + return 1; + } else if (data_avail) { + int ble_reset = 0; + + if (digitalRead(_spi_irq) == 0) { + return 0; + } + + data_avail = 0; + + // Wait for BlueNRG-LP to be ready (needs to be done after each HCI RESET) + if (_ble_chip == BLUENRG_LP && _initial_phase) { + delay(100); + } + + while (digitalRead(_spi_irq) == 1 && _write_index != BLE_MODULE_SPI_BUFFER_SIZE) { + uint8_t header_master[5] = {0x0b, 0x00, 0x00, 0x00, 0x00}; + + if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { + detachInterrupt(_spi_irq); + } + + _spi->beginTransaction(_spiSettings); + + digitalWrite(_cs_pin, LOW); + + /* Write the header */ + _spi->transfer(header_master, 5); + + if (_ble_chip == SPBTLE_RF || _ble_chip == BLUENRG_M0) { + /* device is ready */ + if (header_master[0] == 0x02) { + uint16_t byte_count = (header_master[4] << 8) | header_master[3]; + + if (byte_count > 0) { + if (_initial_phase) { + /* avoid to read more data that available size of the buffer */ + if (byte_count > (BLE_MODULE_SPI_BUFFER_SIZE - _write_index_initial)) { + byte_count = (BLE_MODULE_SPI_BUFFER_SIZE - _write_index_initial); + } + + /* Read the response */ + for (int j = 0; j < byte_count; j++) { + _rxbuff[_write_index_initial] = _spi->transfer(0x00); + _write_index_initial++; + } + + /* Check if the message is a Blue Initialize */ + /* If so we need to send the command to enable LL_ONLY */ + if (byte_count == 6) { + if (_rxbuff[_write_index_initial - 6] == 0x04 && + _rxbuff[_write_index_initial - 5] == 0xFF && + _rxbuff[_write_index_initial - 4] == 0x03 && + _rxbuff[_write_index_initial - 3] == 0x01 && + _rxbuff[_write_index_initial - 2] == 0x00 && + _rxbuff[_write_index_initial - 1] == 0x01) { + ble_reset = 1; + } + } + } else { + /* avoid to read more data that available size of the buffer */ + if (byte_count > (BLE_MODULE_SPI_BUFFER_SIZE - _write_index)) { + byte_count = (BLE_MODULE_SPI_BUFFER_SIZE - _write_index); + /* SPI buffer is full but we still have data to store, so we set the data_avail flag to true */ + data_avail = 1; + } + + /* Read the response */ + for (int j = 0; j < byte_count; j++) { + _rxbuff[_write_index] = _spi->transfer(0x00); + _write_index++; + } + } + } + } + } else if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { + uint16_t byte_count = (header_master[4] << 8) | header_master[3]; + + if (byte_count > 0) { + if (_initial_phase) { + /* avoid to read more data that available size of the buffer */ + if (byte_count > (BLE_MODULE_SPI_BUFFER_SIZE - _write_index_initial)) { + byte_count = (BLE_MODULE_SPI_BUFFER_SIZE - _write_index_initial); + } + + /* Read the response */ + for (int j = 0; j < byte_count; j++) { + _rxbuff[_write_index_initial] = _spi->transfer(0x00); + _write_index_initial++; + } + + /* Check if the message is a CMD_COMPLETE */ + /* We suppose that the first CMD is always a HCI_RESET */ + if (byte_count == 7) { + if (_rxbuff[_write_index_initial - 7] == 0x04 && + _rxbuff[_write_index_initial - 6] == 0x0E && + _rxbuff[_write_index_initial - 5] == 0x04 && + _rxbuff[_write_index_initial - 4] == 0x01 && + _rxbuff[_write_index_initial - 3] == 0x03 && + _rxbuff[_write_index_initial - 2] == 0x0C && + _rxbuff[_write_index_initial - 1] == 0x00) { + ble_reset = 1; + } + } + } else { + /* avoid to read more data that available size of the buffer */ + if (byte_count > (BLE_MODULE_SPI_BUFFER_SIZE - _write_index)) { + byte_count = (BLE_MODULE_SPI_BUFFER_SIZE - _write_index); + /* SPI buffer is full but we still have data to store, so we set the data_avail flag to true */ + data_avail = 1; + } + + /* Read the response */ + for (int j = 0; j < byte_count; j++) { + _rxbuff[_write_index] = _spi->transfer(0x00); + _write_index++; + } + } + } + } + + digitalWrite(_cs_pin, HIGH); + + _spi->endTransaction(); + + if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + } + } + + if (ble_reset) { + if (_ble_chip == BLUENRG_M2SP) { + wait_for_blue_initialize(); + } + + if (_ble_chip == SPBTLE_RF || _ble_chip == BLUENRG_M0 || _ble_chip == BLUENRG_LP || _ble_chip == BLUENRG_M2SP) { + /* BLE chip was reset: we need to enable LL_ONLY */ + enable_ll_only(); + wait_for_enable_ll_only(); + } else if (_ble_chip == SPBTLE_1S) { + /* BLE chip was reset: we need to wait for a while */ + delay(300); + } + + /* Call Gatt Init and Gap Init to activate the random BLE address */ + if (!_random_addr_done) { + aci_gatt_init(); + wait_for_aci_gatt_init(); + aci_gap_init(); + wait_for_aci_gap_init(); + /* Call Read Config Parameter to retrieve the random BLE address */ + aci_read_config_parameter(); + wait_for_aci_read_config_parameter(); + if (_ble_chip == BLUENRG_LP) { + hci_reset(); + _read_index = _write_index = _write_index_initial = 0; + _initial_phase = 1; + } else { + /* Now we can update the write index and close the initial phase */ + _write_index = _write_index_initial; + _initial_phase = 0; + _write_index_initial = 0; + } + } else { + set_address(); + wait_for_set_address(); + /* Now we can update the write index and close the initial phase */ + _write_index = _write_index_initial; + _initial_phase = 0; + _write_index_initial = 0; + } + } + + if (_read_index != _write_index) { + return 1; + } else { + return 0; + } + } else { + return 0; + } +} + +int HCISpiTransportClass::peek() +{ + int peek_val = -1; + + if (_read_index != _write_index) { + peek_val = _rxbuff[_read_index]; + } + + return peek_val; +} + +int HCISpiTransportClass::read() +{ + int read_val = -1; + + if (_read_index != _write_index) { + read_val = _rxbuff[_read_index]; + _read_index++; + if (_read_index == _write_index) { + /* Reset buffer index */ + _read_index = 0; + _write_index = 0; + } + } + + return read_val; +} + +size_t HCISpiTransportClass::write(const uint8_t *data, size_t length) +{ + uint8_t header_master[5] = {0x0a, 0x00, 0x00, 0x00, 0x00}; + void *my_data = (void *)data; + int result = 0; + uint32_t tickstart = millis(); + + if (_ble_chip != SPBTLE_RF && _ble_chip != SPBTLE_1S && _ble_chip != BLUENRG_M2SP && _ble_chip != BLUENRG_M0 && _ble_chip != BLUENRG_LP) { + return 0; + } + + do { + if (_ble_chip == SPBTLE_RF || _ble_chip == BLUENRG_M0) { + result = 0; + + _spi->beginTransaction(_spiSettings); + + digitalWrite(_cs_pin, LOW); + + /* Write the header */ + _spi->transfer(header_master, 5); + + /* device is ready */ + if (header_master[0] == 0x02) { + if (header_master[1] >= length) { + /* Write the data */ + _spi->transfer(my_data, length); + } else { + result = -2; + } + } else { + result = -1; + } + + digitalWrite(_cs_pin, HIGH); + + _spi->endTransaction(); + + if ((millis() - tickstart) > 1000) { + result = -3; + break; + } + } else if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { + uint32_t tickstart_data_available = millis(); + result = 0; + + detachInterrupt(_spi_irq); + + _spi->beginTransaction(_spiSettings); + + digitalWrite(_cs_pin, LOW); + + /* + * Wait until BlueNRG-1 is ready. + * When ready it will raise the IRQ pin. + */ + while (!(digitalRead(_spi_irq) == 1)) { + if ((millis() - tickstart_data_available) > 1000) { + result = -3; + break; + } + } + + if (result == -3) { + digitalWrite(_cs_pin, HIGH); + _spi->endTransaction(); + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + break; + } + + /* Write the header */ + _spi->transfer(header_master, 5); + + if ((int)((((uint16_t)header_master[2]) << 8) | ((uint16_t)header_master[1])) >= (int)length) { + /* Write the data */ + _spi->transfer(my_data, length); + } else { + result = -2; + } + + digitalWrite(_cs_pin, HIGH); + + _spi->endTransaction(); + + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + + if ((millis() - tickstart) > 1000) { + result = -3; + break; + } + } + } while (result < 0); + + if (result < 0) { + return 0; + } else { + return length; + } +} + +void HCISpiTransportClass::wait_for_blue_initialize() +{ + int event_blue_initialize = 0; + uint8_t event[16]; + + do { + while (!data_avail); + + if (digitalRead(_spi_irq) == 0) { + continue; + } + + data_avail = 0; + while (digitalRead(_spi_irq) == 1) { + uint8_t header_master[5] = {0x0b, 0x00, 0x00, 0x00, 0x00}; + + if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { + detachInterrupt(_spi_irq); + } + + _spi->beginTransaction(_spiSettings); + + digitalWrite(_cs_pin, LOW); + + /* Write the header */ + _spi->transfer(header_master, 5); + + if (_ble_chip == SPBTLE_RF || _ble_chip == BLUENRG_M0) { + /* device is ready */ + if (header_master[0] == 0x02) { + /* device is ready */ + uint16_t byte_count = (header_master[4] << 8) | header_master[3]; + + if (byte_count > 0) { + /* Read the response */ + if (byte_count == 6) { + for (int j = 0; j < byte_count; j++) { + event[j] = _spi->transfer(0x00); + } + + if (event[0] == 0x04 && + event[1] == 0xFF && + event[2] == 0x03 && + event[3] == 0x01 && + event[4] == 0x00 && + event[5] == 0x01) { + event_blue_initialize = 1; + } + } else { + for (int j = 0; j < byte_count; j++) { + _spi->transfer(0x00); + } + } + } + } + } else if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP) { + uint16_t byte_count = (header_master[4] << 8) | header_master[3]; + + if (byte_count > 0) { + /* Read the response */ + if (byte_count == 6) { + for (int j = 0; j < byte_count; j++) { + event[j] = _spi->transfer(0x00); + } + + if (event[0] == 0x04 && + event[1] == 0xFF && + event[2] == 0x03 && + event[3] == 0x01 && + event[4] == 0x00 && + event[5] == 0x01) { + event_blue_initialize = 1; + } + } else { + for (int j = 0; j < byte_count; j++) { + _spi->transfer(0x00); + } + } + } + } else if (_ble_chip == BLUENRG_LP) { + uint8_t byte_count = (header_master[4] << 8) | header_master[3]; + + if (byte_count > 0) { + /* Read the response */ + if (byte_count == 7) { + for (int j = 0; j < byte_count; j++) { + event[j] = _spi->transfer(0x00); + } + + if (event[0] == 0x82 && + event[1] == 0xFF && + event[2] == 0x03 && + event[3] == 0x00 && + event[4] == 0x01 && + event[5] == 0x00 && + event[6] == 0x01) { + event_blue_initialize = 1; + } + } else { + for (int j = 0; j < byte_count; j++) { + _spi->transfer(0x00); + } + } + } + } + + digitalWrite(_cs_pin, HIGH); + + _spi->endTransaction(); + + if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + } + } + } while (!event_blue_initialize); +} + +void HCISpiTransportClass::wait_for_enable_ll_only() +{ + uint8_t data[8]; + int status = 0; + + do { + while (!data_avail); + + if (digitalRead(_spi_irq) == 0) { + continue; + } + + data_avail = 0; + while (digitalRead(_spi_irq) == 1) { + uint8_t header_master[5] = {0x0b, 0x00, 0x00, 0x00, 0x00}; + + if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { + detachInterrupt(_spi_irq); + } + + _spi->beginTransaction(_spiSettings); + + digitalWrite(_cs_pin, LOW); + + /* Write the header */ + _spi->transfer(header_master, 5); + + if (_ble_chip == SPBTLE_RF || _ble_chip == BLUENRG_M0) { + /* device is ready */ + if (header_master[0] == 0x02) { + /* device is ready */ + uint16_t byte_count = (header_master[4] << 8) | header_master[3]; + + if (byte_count > 0) { + /* Read the response */ + for (int j = 0; j < byte_count; j++) { + data[j] = _spi->transfer(0x00); + } + + if (byte_count >= 7) { + if (data[0] == 0x04 && + data[1] == 0x0E && + data[2] == 0x04 && + data[3] == 0x01 && + data[4] == 0x0C && + data[5] == 0xFC && + data[6] == 0x00) { + status = 1; + } + } + } + } + } else if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { + uint16_t byte_count = (header_master[4] << 8) | header_master[3]; + + if (byte_count > 0) { + /* Read the response */ + for (int j = 0; j < byte_count; j++) { + data[j] = _spi->transfer(0x00); + } + + if (byte_count >= 7) { + if (data[0] == 0x04 && + data[1] == 0x0E && + data[2] == 0x04 && + data[3] == 0x01 && + data[4] == 0x0C && + data[5] == 0xFC && + data[6] == 0x00) { + status = 1; + } + } + } + } + + digitalWrite(_cs_pin, HIGH); + + _spi->endTransaction(); + + if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + } + } + } while (!status); +} + +void HCISpiTransportClass::enable_ll_only() +{ + uint8_t header_master[5] = {0x0a, 0x00, 0x00, 0x00, 0x00}; + uint8_t cmd[7] = {0x01, 0x0C, 0xFC, 0x03, 0x2C, 0x01, 0x01}; // Enable LL_ONLY + int result = 0; + + do { + if (_ble_chip == SPBTLE_RF || _ble_chip == BLUENRG_M0) { + result = 0; + + _spi->beginTransaction(_spiSettings); + + digitalWrite(_cs_pin, LOW); + + /* Write the header */ + _spi->transfer(header_master, 5); + + /* device is ready */ + if (header_master[0] == 0x02) { + /* Write the data */ + if (header_master[1] >= 7) { + /* Write the data */ + _spi->transfer((void *)cmd, 7); + } else { + result = -2; + } + } else { + result = -1; + } + + digitalWrite(_cs_pin, HIGH); + + _spi->endTransaction(); + } else if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { + uint32_t tickstart_data_available = millis(); + result = 0; + + detachInterrupt(_spi_irq); + + _spi->beginTransaction(_spiSettings); + + digitalWrite(_cs_pin, LOW); + + while (!(digitalRead(_spi_irq) == 1)) { + if ((millis() - tickstart_data_available) > 1000) { + result = -3; + break; + } + } + + if (result == -3) { + digitalWrite(_cs_pin, HIGH); + _spi->endTransaction(); + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + break; + } + + /* Write the header */ + _spi->transfer(header_master, 5); + + if ((int)((((uint16_t)header_master[2]) << 8) | ((uint16_t)header_master[1])) >= 7) { + /* Write the data */ + _spi->transfer((void *)cmd, 7); + } else { + result = -2; + } + + digitalWrite(_cs_pin, HIGH); + + _spi->endTransaction(); + + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + } + } while (result < 0); +} + +void HCISpiTransportClass::wait_for_aci_gatt_init() +{ + uint8_t data[8]; + int status = 0; + + do { + while (!data_avail); + + if (digitalRead(_spi_irq) == 0) { + continue; + } + + data_avail = 0; + while (digitalRead(_spi_irq) == 1) { + uint8_t header_master[5] = {0x0b, 0x00, 0x00, 0x00, 0x00}; + + if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { + detachInterrupt(_spi_irq); + } + + _spi->beginTransaction(_spiSettings); + + digitalWrite(_cs_pin, LOW); + + /* Write the header */ + _spi->transfer(header_master, 5); + + if (_ble_chip == SPBTLE_RF || _ble_chip == BLUENRG_M0) { + /* device is ready */ + if (header_master[0] == 0x02) { + /* device is ready */ + uint16_t byte_count = (header_master[4] << 8) | header_master[3]; + + if (byte_count > 0) { + /* Read the response */ + for (int j = 0; j < byte_count; j++) { + data[j] = _spi->transfer(0x00); + } + + if (byte_count >= 7) { + if (data[0] == 0x04 && + data[1] == 0x0E && + data[2] == 0x04 && + data[3] == 0x01 && + data[4] == 0x01 && + data[5] == 0xFD && + data[6] == 0x00) { + status = 1; + } + } + } + } + } else if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { + uint16_t byte_count = (header_master[4] << 8) | header_master[3]; + + if (byte_count > 0) { + /* Read the response */ + for (int j = 0; j < byte_count; j++) { + data[j] = _spi->transfer(0x00); + } + + if (byte_count >= 7) { + if (data[0] == 0x04 && + data[1] == 0x0E && + data[2] == 0x04 && + data[3] == 0x01 && + data[4] == 0x01 && + data[5] == 0xFD && + data[6] == 0x00) { + status = 1; + } + } + } + } + + digitalWrite(_cs_pin, HIGH); + + _spi->endTransaction(); + + if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + } + } + } while (!status); +} + +void HCISpiTransportClass::aci_gatt_init() +{ + uint8_t header_master[5] = {0x0a, 0x00, 0x00, 0x00, 0x00}; + uint8_t cmd[4] = {0x01, 0x01, 0xFD, 0x00}; // ACI_GATT_INIT + int result = 0; + + do { + if (_ble_chip == SPBTLE_RF || _ble_chip == BLUENRG_M0) { + result = 0; + + _spi->beginTransaction(_spiSettings); + + digitalWrite(_cs_pin, LOW); + + /* Write the header */ + _spi->transfer(header_master, 5); + + /* device is ready */ + if (header_master[0] == 0x02) { + /* Write the data */ + if (header_master[1] >= 4) { + /* Write the data */ + _spi->transfer((void *)cmd, 4); + } else { + result = -2; + } + } else { + result = -1; + } + + digitalWrite(_cs_pin, HIGH); + + _spi->endTransaction(); + } else if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { + uint32_t tickstart_data_available = millis(); + result = 0; + + detachInterrupt(_spi_irq); + + _spi->beginTransaction(_spiSettings); + + digitalWrite(_cs_pin, LOW); + + while (!(digitalRead(_spi_irq) == 1)) { + if ((millis() - tickstart_data_available) > 1000) { + result = -3; + break; + } + } + + if (result == -3) { + digitalWrite(_cs_pin, HIGH); + _spi->endTransaction(); + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + break; + } + + /* Write the header */ + _spi->transfer(header_master, 5); + + if ((int)((((uint16_t)header_master[2]) << 8) | ((uint16_t)header_master[1])) >= 4) { + /* Write the data */ + _spi->transfer((void *)cmd, 4); + } else { + result = -2; + } + + digitalWrite(_cs_pin, HIGH); + + _spi->endTransaction(); + + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + } + } while (result < 0); +} + +void HCISpiTransportClass::wait_for_aci_gap_init() +{ + uint8_t data[14]; + int status = 0; + + do { + while (!data_avail); + + if (digitalRead(_spi_irq) == 0) { + continue; + } + + data_avail = 0; + while (digitalRead(_spi_irq) == 1) { + uint8_t header_master[5] = {0x0b, 0x00, 0x00, 0x00, 0x00}; + + if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { + detachInterrupt(_spi_irq); + } + + _spi->beginTransaction(_spiSettings); + + digitalWrite(_cs_pin, LOW); + + /* Write the header */ + _spi->transfer(header_master, 5); + + if (_ble_chip == SPBTLE_RF || _ble_chip == BLUENRG_M0) { + /* device is ready */ + if (header_master[0] == 0x02) { + /* device is ready */ + uint16_t byte_count = (header_master[4] << 8) | header_master[3]; + + if (byte_count > 0) { + /* Read the response */ + for (int j = 0; j < byte_count; j++) { + data[j] = _spi->transfer(0x00); + } + + if (byte_count >= 13) { + if (data[0] == 0x04 && + data[1] == 0x0E && + data[2] == 0x0A && + data[3] == 0x01 && + data[4] == 0x8A && + data[5] == 0xFC && + data[6] == 0x00) { + status = 1; + } + } + } + } + } else if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { + uint16_t byte_count = (header_master[4] << 8) | header_master[3]; + + if (byte_count > 0) { + /* Read the response */ + for (int j = 0; j < byte_count; j++) { + data[j] = _spi->transfer(0x00); + } + + if (byte_count >= 13) { + if (data[0] == 0x04 && + data[1] == 0x0E && + data[2] == 0x0A && + data[3] == 0x01 && + data[4] == 0x8A && + data[5] == 0xFC && + data[6] == 0x00) { + status = 1; + } + } + } + } + + digitalWrite(_cs_pin, HIGH); + + _spi->endTransaction(); + + if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + } + } + } while (!status); +} + +void HCISpiTransportClass::aci_gap_init() +{ + uint8_t header_master[5] = {0x0a, 0x00, 0x00, 0x00, 0x00}; + uint8_t cmd_lp[8] = {0x01, 0x8A, 0xFC, 0x04, 0x0F, 0x00, 0x00, 0x00}; // ACI_GAP_INIT + uint8_t cmd_others[7] = {0x01, 0x8A, 0xFC, 0x03, 0x0F, 0x00, 0x00}; // ACI_GAP_INIT + uint8_t *cmd, cmd_size; + if (_ble_chip == BLUENRG_LP) { + cmd = cmd_lp; + cmd_size = 8; + } else { + cmd = cmd_others; + cmd_size = 7; + } + int result = 0; + + do { + if (_ble_chip == SPBTLE_RF || _ble_chip == BLUENRG_M0) { + result = 0; + + _spi->beginTransaction(_spiSettings); + + digitalWrite(_cs_pin, LOW); + + /* Write the header */ + _spi->transfer(header_master, 5); + + /* device is ready */ + if (header_master[0] == 0x02) { + /* Write the data */ + if (header_master[1] >= cmd_size) { + /* Write the data */ + _spi->transfer((void *)cmd, cmd_size); + } else { + result = -2; + } + } else { + result = -1; + } + + digitalWrite(_cs_pin, HIGH); + + _spi->endTransaction(); + } else if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { + uint32_t tickstart_data_available = millis(); + result = 0; + + detachInterrupt(_spi_irq); + + _spi->beginTransaction(_spiSettings); + + digitalWrite(_cs_pin, LOW); + + while (!(digitalRead(_spi_irq) == 1)) { + if ((millis() - tickstart_data_available) > 1000) { + result = -3; + break; + } + } + + if (result == -3) { + digitalWrite(_cs_pin, HIGH); + _spi->endTransaction(); + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + break; + } + + /* Write the header */ + _spi->transfer(header_master, 5); + + if ((int)((((uint16_t)header_master[2]) << 8) | ((uint16_t)header_master[1])) >= cmd_size) { + /* Write the data */ + _spi->transfer((void *)cmd, cmd_size); + } else { + result = -2; + } + + digitalWrite(_cs_pin, HIGH); + + _spi->endTransaction(); + + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + } + } while (result < 0); +} + +void HCISpiTransportClass::wait_for_aci_read_config_parameter() +{ + uint8_t data[15]; + int status = 0; + + do { + while (!data_avail); + + if (digitalRead(_spi_irq) == 0) { + continue; + } + + data_avail = 0; + while (digitalRead(_spi_irq) == 1) { + uint8_t header_master[5] = {0x0b, 0x00, 0x00, 0x00, 0x00}; + + if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { + detachInterrupt(_spi_irq); + } + + _spi->beginTransaction(_spiSettings); + + digitalWrite(_cs_pin, LOW); + + /* Write the header */ + _spi->transfer(header_master, 5); + + if (_ble_chip == SPBTLE_RF || _ble_chip == BLUENRG_M0) { + /* device is ready */ + if (header_master[0] == 0x02) { + /* device is ready */ + uint16_t byte_count = (header_master[4] << 8) | header_master[3]; + + if (byte_count > 0) { + /* Read the response */ + for (int j = 0; j < byte_count; j++) { + data[j] = _spi->transfer(0x00); + } + + if (byte_count >= 13) { + if (data[0] == 0x04 && + data[1] == 0x0E && + data[2] == 0x0A && + data[3] == 0x01 && + data[4] == 0x0D && + data[5] == 0xFC && + data[6] == 0x00) { + memcpy(_random_addr, &data[7], 6); + status = 1; + } + } + } + } + } else if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { + uint16_t byte_count = (header_master[4] << 8) | header_master[3]; + + if (byte_count > 0) { + /* Read the response */ + for (int j = 0; j < byte_count; j++) { + data[j] = _spi->transfer(0x00); + } + + if (byte_count >= 14) { + if (data[0] == 0x04 && + data[1] == 0x0E && + data[2] == 0x0B && + data[3] == 0x01 && + data[4] == 0x0D && + data[5] == 0xFC && + data[6] == 0x00) { + memcpy(_random_addr, &data[8], 6); + status = 1; + _random_addr_done = true; + } + } + } + } + + digitalWrite(_cs_pin, HIGH); + + _spi->endTransaction(); + + if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + } + } + } while (!status); +} + +void HCISpiTransportClass::aci_read_config_parameter() +{ + uint8_t header_master[5] = {0x0a, 0x00, 0x00, 0x00, 0x00}; + uint8_t cmd[5] = {0x01, 0x0D, 0xFC, 0x01, 0x80}; // ACI_READ_CONFIG_PARAMETER + int result = 0; + + do { + if (_ble_chip == SPBTLE_RF || _ble_chip == BLUENRG_M0) { + result = 0; + + _spi->beginTransaction(_spiSettings); + + digitalWrite(_cs_pin, LOW); + + /* Write the header */ + _spi->transfer(header_master, 5); + + /* device is ready */ + if (header_master[0] == 0x02) { + /* Write the data */ + if (header_master[1] >= 5) { + /* Write the data */ + _spi->transfer((void *)cmd, 5); + } else { + result = -2; + } + } else { + result = -1; + } + + digitalWrite(_cs_pin, HIGH); + + _spi->endTransaction(); + } else if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { + uint32_t tickstart_data_available = millis(); + result = 0; + + detachInterrupt(_spi_irq); + + _spi->beginTransaction(_spiSettings); + + digitalWrite(_cs_pin, LOW); + + while (!(digitalRead(_spi_irq) == 1)) { + if ((millis() - tickstart_data_available) > 1000) { + result = -3; + break; + } + } + + if (result == -3) { + digitalWrite(_cs_pin, HIGH); + _spi->endTransaction(); + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + break; + } + + /* Write the header */ + _spi->transfer(header_master, 5); + + if ((int)((((uint16_t)header_master[2]) << 8) | ((uint16_t)header_master[1])) >= 5) { + /* Write the data */ + _spi->transfer((void *)cmd, 5); + } else { + result = -2; + } + + digitalWrite(_cs_pin, HIGH); + + _spi->endTransaction(); + + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + } + } while (result < 0); +} + +void HCISpiTransportClass::hci_reset() +{ + uint8_t header_master[5] = {0x0a, 0x00, 0x00, 0x00, 0x00}; + uint8_t cmd[4] = {0x01, 0x03, 0x0C, 0x00}; // HCI_RESET + int result = 0; + + do { + if (_ble_chip == BLUENRG_LP) { + uint32_t tickstart_data_available = millis(); + result = 0; + + detachInterrupt(_spi_irq); + + _spi->beginTransaction(_spiSettings); + + digitalWrite(_cs_pin, LOW); + + while (!(digitalRead(_spi_irq) == 1)) { + if ((millis() - tickstart_data_available) > 1000) { + result = -3; + break; + } + } + + if (result == -3) { + digitalWrite(_cs_pin, HIGH); + _spi->endTransaction(); + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + break; + } + + /* Write the header */ + _spi->transfer(header_master, 5); + + if ((int)((((uint16_t)header_master[2]) << 8) | ((uint16_t)header_master[1])) >= 4) { + /* Write the data */ + _spi->transfer((void *)cmd, 4); + } else { + result = -2; + } + + digitalWrite(_cs_pin, HIGH); + + _spi->endTransaction(); + + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + } + } while (result < 0); +} + +void HCISpiTransportClass::set_address() +{ + uint8_t header_master[5] = {0x0a, 0x00, 0x00, 0x00, 0x00}; + uint8_t cmd[10] = {0x01, 0x05, 0x20, 0x06}; // SET ADDR + int result = 0; + memcpy(&cmd[4], _random_addr, 6); + + do { + if (_ble_chip == BLUENRG_LP) { + uint32_t tickstart_data_available = millis(); + result = 0; + + detachInterrupt(_spi_irq); + + _spi->beginTransaction(_spiSettings); + + digitalWrite(_cs_pin, LOW); + + while (!(digitalRead(_spi_irq) == 1)) { + if ((millis() - tickstart_data_available) > 1000) { + result = -3; + break; + } + } + + if (result == -3) { + digitalWrite(_cs_pin, HIGH); + _spi->endTransaction(); + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + break; + } + + /* Write the header */ + _spi->transfer(header_master, 5); + + if ((int)((((uint16_t)header_master[2]) << 8) | ((uint16_t)header_master[1])) >= 10) { + /* Write the data */ + _spi->transfer((void *)cmd, 10); + } else { + result = -2; + } + + digitalWrite(_cs_pin, HIGH); + + _spi->endTransaction(); + + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + } + } while (result < 0); +} + +void HCISpiTransportClass::wait_for_set_address() +{ + uint8_t data[15]; + int status = 0; + + if (_ble_chip != BLUENRG_LP) { + return; + } + + do { + while (!data_avail); + + if (digitalRead(_spi_irq) == 0) { + continue; + } + + data_avail = 0; + while (digitalRead(_spi_irq) == 1) { + uint8_t header_master[5] = {0x0b, 0x00, 0x00, 0x00, 0x00}; + uint16_t byte_count = 0; + + detachInterrupt(_spi_irq); + + _spi->beginTransaction(_spiSettings); + + digitalWrite(_cs_pin, LOW); + + /* Write the header */ + _spi->transfer(header_master, 5); + + byte_count = (header_master[4] << 8) | header_master[3]; + + if (byte_count > 0) { + /* Read the response */ + for (int j = 0; j < byte_count; j++) { + data[j] = _spi->transfer(0x00); + } + + if (byte_count >= 7) { // 040E0401052000 + if (data[0] == 0x04 && + data[1] == 0x0E && + data[2] == 0x04 && + data[3] == 0x01 && + data[4] == 0x05 && + data[5] == 0x20 && + data[6] == 0x00) { + status = 1; + } + } + } + + digitalWrite(_cs_pin, HIGH); + + _spi->endTransaction(); + + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + } + } while (!status); +} + +HCITransportInterface& HCITransport = HCISpiTransport; diff --git a/src/utility/HCISpiTransport.h b/src/utility/HCISpiTransport.h new file mode 100644 index 00000000..34af1aa9 --- /dev/null +++ b/src/utility/HCISpiTransport.h @@ -0,0 +1,83 @@ +/* + This file is part of the STM32duinoBLE library. + Copyright (c) 2019 STMicroelectronics. All rights reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef _HCI_SPI_TRANSPORT_H_ +#define _HCI_SPI_TRANSPORT_H_ + +#include "HCITransport.h" +#include "SPI.h" + +typedef enum BLEChip_s { + SPBTLE_RF, + SPBTLE_1S, + BLUENRG_M2SP, + BLUENRG_M0, + BLUENRG_LP +} BLEChip_t; + +#ifndef BLE_SPI_BYTE_ORDER + #define BLE_SPI_BYTE_ORDER MSBFIRST +#endif +#define BLE_MODULE_SPI_BUFFER_SIZE 128 + +class HCISpiTransportClass : public HCITransportInterface { + public: + HCISpiTransportClass(SPIClass &spi, BLEChip_t ble_chip, uint8_t cs_pin, uint8_t spi_irq, uint8_t ble_rst, uint32_t frequency, uint8_t spi_mode); + virtual ~HCISpiTransportClass(); + + virtual int begin(); + virtual void end(); + + virtual void wait(unsigned long timeout); + + virtual int available(); + virtual int peek(); + virtual int read(); + + virtual size_t write(const uint8_t *data, size_t length); + + private: + void wait_for_blue_initialize(); + void wait_for_enable_ll_only(); + void enable_ll_only(); + void wait_for_aci_gatt_init(); + void aci_gatt_init(); + void wait_for_aci_gap_init(); + void aci_gap_init(); + void wait_for_aci_read_config_parameter(); + void aci_read_config_parameter(); + void hci_reset(); + void set_address(); + void wait_for_set_address(); + SPIClass *_spi; + SPISettings _spiSettings; + BLEChip_t _ble_chip; + uint8_t _cs_pin; + uint8_t _spi_irq; + uint8_t _ble_rst; + uint8_t _rxbuff[BLE_MODULE_SPI_BUFFER_SIZE]; + uint16_t _read_index; + uint16_t _write_index; + uint16_t _write_index_initial; + uint8_t _initial_phase; + uint8_t _random_addr[6]; + bool _random_addr_done; +}; + +#endif /* _HCI_SPI_TRANSPORT_H_ */ From f5e86b919317620ab4cc9e88c76bc66d17897948 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Wed, 26 Mar 2025 09:03:20 +0100 Subject: [PATCH 181/226] chore: moved to STM32duinoBLE Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- .github/dependabot.yml | 13 - .github/workflows/compile-examples.yml | 98 - .github/workflows/report-size-deltas.yml | 24 - .github/workflows/sync-labels.yml | 138 - README.md | 28 +- docs/api.md | 3818 ---- docs/assets/ble-bulletin-board-model.png | Bin 41914 -> 0 bytes docs/readme.md | 91 - examples/Central/LedControl/LedControl.ino | 6 +- .../PeripheralExplorer/PeripheralExplorer.ino | 5 +- examples/Central/Scan/Scan.ino | 5 +- .../Central/ScanCallback/ScanCallback.ino | 5 +- .../SensorTagButton/SensorTagButton.ino | 5 +- .../EnhancedAdvertising.ino | 2 +- .../RawDataAdvertising/RawDataAdvertising.ino | 2 +- .../BatteryMonitor/BatteryMonitor.ino | 5 +- examples/Peripheral/ButtonLED/ButtonLED.ino | 6 +- .../Peripheral/CallbackLED/CallbackLED.ino | 5 +- .../EncryptedBatteryMonitor.ino | 265 - examples/Peripheral/LED/LED.ino | 5 +- extras/arduino-ble-parser.py | 85 - extras/test/.gitignore | 1 - extras/test/CMakeLists.txt | 126 - .../external/catch/v2.12.1/include/catch.hpp | 17698 ---------------- extras/test/include/Arduino.h | 45 - .../FakeBLELocalDevice.h | 35 - .../include/test_discovered_device/FakeGAP.h | 33 - extras/test/include/util/Common.h | 167 - extras/test/include/util/HCIFakeTransport.h | 19 - extras/test/include/util/Stream.h | 40 - extras/test/include/util/String.h | 248 - extras/test/include/util/TestUtil.h | 3 - extras/test/include/util/itoa.h | 37 - extras/test/src/Arduino.cpp | 44 - .../FakeBLELocalDevice.cpp | 40 - .../test_advertising_data.cpp | 184 - .../test_advertising_data/test_local_name.cpp | 82 - .../test_manufacturer.cpp | 146 - .../test_advertising_data/test_service.cpp | 149 - .../src/test_discovered_device/FakeGAP.cpp | 31 - .../test_discovered_device.cpp | 52 - extras/test/src/test_main.cpp | 21 - extras/test/src/test_uuid/test_uuid.cpp | 52 - extras/test/src/util/Common.cpp | 34 - extras/test/src/util/HCIFakeTransport.cpp | 23 - extras/test/src/util/String.cpp | 755 - extras/test/src/util/TestUtil.cpp | 3 - extras/test/src/util/itoa.c | 126 - keywords.txt | 4 +- library.properties | 14 +- src/{ArduinoBLE.h => STM32duinoBLE.h} | 4 +- src/utility/CordioHCICustomDriver.h | 17 - src/utility/HCICordioTransport.cpp | 314 - src/utility/HCICordioTransport.h | 54 - src/utility/HCISilabsTransport.cpp | 130 - src/utility/HCISilabsTransport.h | 42 - src/utility/HCIUartTransport.cpp | 109 - src/utility/HCIUartTransport.h | 46 - src/utility/HCIVirtualTransport.cpp | 142 - src/utility/HCIVirtualTransport.h | 50 - src/utility/HCIVirtualTransportAT.cpp | 112 - src/utility/HCIVirtualTransportAT.h | 42 - src/utility/btct.cpp | 2 +- 63 files changed, 53 insertions(+), 25834 deletions(-) delete mode 100644 .github/dependabot.yml delete mode 100644 .github/workflows/report-size-deltas.yml delete mode 100644 .github/workflows/sync-labels.yml delete mode 100644 docs/api.md delete mode 100644 docs/assets/ble-bulletin-board-model.png delete mode 100644 docs/readme.md delete mode 100644 examples/Peripheral/EncryptedBatteryMonitor/EncryptedBatteryMonitor.ino delete mode 100644 extras/arduino-ble-parser.py delete mode 100644 extras/test/.gitignore delete mode 100644 extras/test/CMakeLists.txt delete mode 100644 extras/test/external/catch/v2.12.1/include/catch.hpp delete mode 100644 extras/test/include/Arduino.h delete mode 100644 extras/test/include/test_advertising_data/FakeBLELocalDevice.h delete mode 100644 extras/test/include/test_discovered_device/FakeGAP.h delete mode 100644 extras/test/include/util/Common.h delete mode 100644 extras/test/include/util/HCIFakeTransport.h delete mode 100644 extras/test/include/util/Stream.h delete mode 100644 extras/test/include/util/String.h delete mode 100644 extras/test/include/util/TestUtil.h delete mode 100644 extras/test/include/util/itoa.h delete mode 100644 extras/test/src/Arduino.cpp delete mode 100644 extras/test/src/test_advertising_data/FakeBLELocalDevice.cpp delete mode 100644 extras/test/src/test_advertising_data/test_advertising_data.cpp delete mode 100644 extras/test/src/test_advertising_data/test_local_name.cpp delete mode 100644 extras/test/src/test_advertising_data/test_manufacturer.cpp delete mode 100644 extras/test/src/test_advertising_data/test_service.cpp delete mode 100644 extras/test/src/test_discovered_device/FakeGAP.cpp delete mode 100644 extras/test/src/test_discovered_device/test_discovered_device.cpp delete mode 100644 extras/test/src/test_main.cpp delete mode 100644 extras/test/src/test_uuid/test_uuid.cpp delete mode 100644 extras/test/src/util/Common.cpp delete mode 100644 extras/test/src/util/HCIFakeTransport.cpp delete mode 100644 extras/test/src/util/String.cpp delete mode 100644 extras/test/src/util/TestUtil.cpp delete mode 100644 extras/test/src/util/itoa.c rename src/{ArduinoBLE.h => STM32duinoBLE.h} (94%) delete mode 100644 src/utility/CordioHCICustomDriver.h delete mode 100644 src/utility/HCICordioTransport.cpp delete mode 100644 src/utility/HCICordioTransport.h delete mode 100644 src/utility/HCISilabsTransport.cpp delete mode 100644 src/utility/HCISilabsTransport.h delete mode 100644 src/utility/HCIUartTransport.cpp delete mode 100644 src/utility/HCIUartTransport.h delete mode 100644 src/utility/HCIVirtualTransport.cpp delete mode 100644 src/utility/HCIVirtualTransport.h delete mode 100644 src/utility/HCIVirtualTransportAT.cpp delete mode 100644 src/utility/HCIVirtualTransportAT.h diff --git a/.github/dependabot.yml b/.github/dependabot.yml deleted file mode 100644 index f2bfa724..00000000 --- a/.github/dependabot.yml +++ /dev/null @@ -1,13 +0,0 @@ -# See: https://docs.github.com/en/code-security/supply-chain-security/configuration-options-for-dependency-updates#about-the-dependabotyml-file -version: 2 - -updates: - # Configure check for outdated GitHub Actions actions in workflows. - # Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/dependabot/README.md - # See: https://docs.github.com/en/code-security/supply-chain-security/keeping-your-actions-up-to-date-with-dependabot - - package-ecosystem: github-actions - directory: / # Check the repository's workflows under /.github/workflows/ - schedule: - interval: daily - labels: - - "topic: infrastructure" diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index 706ccb4c..c298c638 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -12,104 +12,6 @@ on: - ".github/workflows/compile-examples.yml" - "examples/**" - "src/**" - schedule: - # Run every Tuesday at 8 AM UTC to catch breakage caused by changes to external resources (libraries, platforms). - - cron: "0 8 * * TUE" workflow_dispatch: - repository_dispatch: jobs: - build: - name: ${{ matrix.board.fqbn }} - runs-on: ubuntu-latest - - env: - SKETCHES_REPORTS_PATH: sketches-reports - - strategy: - fail-fast: false - - matrix: - board: - - fqbn: arduino:samd:mkrwifi1010 - platforms: | - - name: arduino:samd - artifact-name-suffix: arduino-samd-mkrwifi1010 - - fqbn: arduino:samd:nano_33_iot - platforms: | - - name: arduino:samd - artifact-name-suffix: arduino-samd-nano_33_iot - - fqbn: arduino:megaavr:uno2018:mode=on - platforms: | - - name: arduino:megaavr - artifact-name-suffix: arduino-megaavr-uno2018 - - fqbn: arduino:mbed_nano:nano33ble - platforms: | - - name: arduino:mbed_nano - artifact-name-suffix: arduino-mbed_nano-nano33ble - - fqbn: arduino:mbed_nano:nanorp2040connect - platforms: | - - name: arduino:mbed_nano - artifact-name-suffix: arduino-mbed_nano-nanorp2040connect - - fqbn: arduino:renesas_uno:unor4wifi - platforms: | - - name: arduino:renesas_uno - artifact-name-suffix: arduino-renesas_uno-unor4wifi - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Compile examples - uses: arduino/compile-sketches@v1 - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - fqbn: ${{ matrix.board.fqbn }} - platforms: ${{ matrix.board.platforms }} - libraries: | - # Install the library from the local path. - - source-path: ./ - sketch-paths: | - - examples - enable-deltas-report: true - sketches-report-path: ${{ env.SKETCHES_REPORTS_PATH }} - - - name: Save sketches report as workflow artifact - uses: actions/upload-artifact@v4 - with: - if-no-files-found: error - path: ${{ env.SKETCHES_REPORTS_PATH }} - name: sketches-report-${{ matrix.board.artifact-name-suffix }} - - build-for-esp32: - runs-on: ubuntu-latest - - strategy: - matrix: - fqbn: - - esp32:esp32:esp32 - - esp32:esp32:esp32s3 - - esp32:esp32:esp32c3 - # future bluetooth chips - #- esp32:esp32:esp32c2 - #- esp32:esp32:esp32c6 - #- esp32:esp32:esp32h2 - - steps: - - uses: actions/checkout@v4 - - uses: arduino/compile-sketches@v1 - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - fqbn: ${{ matrix.fqbn }} - platforms: | - - name: esp32:esp32 - source-url: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json - sketch-paths: | - - examples/Central/Scan - - examples/Central/PeripheralExplorer - - examples/Central/ScanCallback - - examples/Central/SensorTagButton - - examples/Peripheral/Advertising/EnhancedAdvertising - - examples/Peripheral/Advertising/RawDataAdvertising - cli-compile-flags: | - - --warnings="none" diff --git a/.github/workflows/report-size-deltas.yml b/.github/workflows/report-size-deltas.yml deleted file mode 100644 index 39e2a0ad..00000000 --- a/.github/workflows/report-size-deltas.yml +++ /dev/null @@ -1,24 +0,0 @@ -name: Report Size Deltas - -# See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows -on: - push: - paths: - - ".github/workflows/report-size-deltas.yml" - schedule: - # Run at the minimum interval allowed by GitHub Actions. - # Note: GitHub Actions periodically has outages which result in workflow failures. - # In this event, the workflows will start passing again once the service recovers. - - cron: "*/5 * * * *" - workflow_dispatch: - repository_dispatch: - -jobs: - report: - runs-on: ubuntu-latest - steps: - - name: Comment size deltas reports to PRs - uses: arduino/report-size-deltas@v1 - with: - # Regex matching the names of the workflow artifacts created by the "Compile Examples" workflow - sketches-reports-source: ^sketches-report-.+ diff --git a/.github/workflows/sync-labels.yml b/.github/workflows/sync-labels.yml deleted file mode 100644 index 53a9f54f..00000000 --- a/.github/workflows/sync-labels.yml +++ /dev/null @@ -1,138 +0,0 @@ -# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/sync-labels.md -name: Sync Labels - -# See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows -on: - push: - paths: - - ".github/workflows/sync-labels.ya?ml" - - ".github/label-configuration-files/*.ya?ml" - pull_request: - paths: - - ".github/workflows/sync-labels.ya?ml" - - ".github/label-configuration-files/*.ya?ml" - schedule: - # Run daily at 8 AM UTC to sync with changes to shared label configurations. - - cron: "0 8 * * *" - workflow_dispatch: - repository_dispatch: - -env: - CONFIGURATIONS_FOLDER: .github/label-configuration-files - CONFIGURATIONS_ARTIFACT: label-configuration-files - -jobs: - check: - runs-on: ubuntu-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Download JSON schema for labels configuration file - id: download-schema - uses: carlosperate/download-file-action@v2 - with: - file-url: https://raw.githubusercontent.com/arduino/tooling-project-assets/main/workflow-templates/assets/sync-labels/arduino-tooling-gh-label-configuration-schema.json - location: ${{ runner.temp }}/label-configuration-schema - - - name: Install JSON schema validator - run: | - sudo npm install \ - --global \ - ajv-cli \ - ajv-formats - - - name: Validate local labels configuration - run: | - # See: https://github.com/ajv-validator/ajv-cli#readme - ajv validate \ - --all-errors \ - -c ajv-formats \ - -s "${{ steps.download-schema.outputs.file-path }}" \ - -d "${{ env.CONFIGURATIONS_FOLDER }}/*.{yml,yaml}" - - download: - needs: check - runs-on: ubuntu-latest - - strategy: - matrix: - filename: - # Filenames of the shared configurations to apply to the repository in addition to the local configuration. - # https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/sync-labels - - universal.yml - - steps: - - name: Download - uses: carlosperate/download-file-action@v2 - with: - file-url: https://raw.githubusercontent.com/arduino/tooling-project-assets/main/workflow-templates/assets/sync-labels/${{ matrix.filename }} - - - name: Pass configuration files to next job via workflow artifact - uses: actions/upload-artifact@v4 - with: - path: | - *.yaml - *.yml - if-no-files-found: error - name: ${{ env.CONFIGURATIONS_ARTIFACT }} - - sync: - needs: download - runs-on: ubuntu-latest - - steps: - - name: Set environment variables - run: | - # See: https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable - echo "MERGED_CONFIGURATION_PATH=${{ runner.temp }}/labels.yml" >> "$GITHUB_ENV" - - - name: Determine whether to dry run - id: dry-run - if: > - github.event_name == 'pull_request' || - ( - ( - github.event_name == 'push' || - github.event_name == 'workflow_dispatch' - ) && - github.ref != format('refs/heads/{0}', github.event.repository.default_branch) - ) - run: | - # Use of this flag in the github-label-sync command will cause it to only check the validity of the - # configuration. - echo "::set-output name=flag::--dry-run" - - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Download configuration files artifact - uses: actions/download-artifact@v4 - with: - name: ${{ env.CONFIGURATIONS_ARTIFACT }} - path: ${{ env.CONFIGURATIONS_FOLDER }} - - - name: Remove unneeded artifact - uses: geekyeggo/delete-artifact@v5 - with: - name: ${{ env.CONFIGURATIONS_ARTIFACT }} - - - name: Merge label configuration files - run: | - # Merge all configuration files - shopt -s extglob - cat "${{ env.CONFIGURATIONS_FOLDER }}"/*.@(yml|yaml) > "${{ env.MERGED_CONFIGURATION_PATH }}" - - - name: Install github-label-sync - run: sudo npm install --global github-label-sync - - - name: Sync labels - env: - GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - # See: https://github.com/Financial-Times/github-label-sync - github-label-sync \ - --labels "${{ env.MERGED_CONFIGURATION_PATH }}" \ - ${{ steps.dry-run.outputs.flag }} \ - ${{ github.repository }} diff --git a/README.md b/README.md index b0027583..e9f3a948 100644 --- a/README.md +++ b/README.md @@ -1,22 +1,24 @@ -# ArduinoBLE +# STM32duinoBLE -[](https://github.com/arduino-libraries/ArduinoBLE/actions?workflow=Compile+Examples) [](https://github.com/arduino-libraries/ArduinoBLE/actions?workflow=Spell+Check) +This library is a fork of ArduinoBLE library to add the support of SPBTLE-RF, SPBTLE-1S, BLUENRG-M2SP, BLUENRG-LP and BLUENRG-M0 BLE modules. -Enables Bluetooth® Low Energy connectivity on the Arduino MKR WiFi 1010, Arduino UNO WiFi Rev2, Arduino Nano 33 IoT, Arduino Nano 33 BLE, Arduino Portenta H7, Arduino Giga R1 and Arduino UNO R4 WiFi. +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], [B-L4S5I-IOT01A], [STEVAL-MKSBOX1V1], [STEVAL-MKBOXPRO] and with [STM32L562E-DK]. -This library supports creating a Bluetooth® Low Energy peripheral & central mode. + - 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: -For the Arduino MKR WiFi 1010, Arduino UNO WiFi Rev2, and Arduino Nano 33 IoT boards, it requires the NINA module to be running [Arduino NINA-W102 firmware](https://github.com/arduino/nina-fw) v1.2.0 or later. +https://github.com/stm32duino/Arduino_Core_STM32/wiki/STM32duinoBLE#stm32duinoble-with-steval_mksbox1v1 -For the Arduino UNO R4 WiFi, it requires the ESP32-S3 module to be running [firmware](https://github.com/arduino/uno-r4-wifi-usb-bridge) v0.2.0 or later. +- In order to use this library with X-NUCLEO-BNRG2A1, you need to update the firmware of the BLUENRG-M2SP BLE module mounted on that expansion board as described in the following wiki page: +https://github.com/stm32duino/Arduino_Core_STM32/wiki/STM32duinoBLE#stm32duinoble-with-x-nucleo-bnrg2a1 -For more information about this library please visit us at: +For more information about ArduinoBLE library please visit the official web page at: https://www.arduino.cc/en/Reference/ArduinoBLE ## License ``` +Copyright (c) 2019 STMicroelectronics. All rights reserved. Copyright (c) 2019 Arduino SA. All rights reserved. This library is free software; you can redistribute it and/or @@ -33,3 +35,15 @@ You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ``` + +B-L475E-IOT01A: https://www.st.com/en/evaluation-tools/b-l475e-iot01a.html +B-L4S5I-IOT01A: https://www.st.com/en/evaluation-tools/b-l4s5i-iot01a.html +NUCLEO-F401RE: https://www.st.com/en/evaluation-tools/nucleo-f401re.html +NUCLEO-L053R8: https://www.st.com/en/evaluation-tools/nucleo-l053r8.html +NUCLEO-L476RG: https://www.st.com/en/evaluation-tools/nucleo-l476rg.html +STEVAL-MKSBOX1V1: https://www.st.com/en/evaluation-tools/steval-mksbox1v1.html +STEVAL-MKBOXPRO: https://www.st.com/en/evaluation-tools/steval-mkboxpro.html +STM32L562E-DK: https://www.st.com/en/evaluation-tools/stm32l562e-dk.html +X-NUCLEO-BNRG2A1: https://www.st.com/en/ecosystems/x-nucleo-bnrg2a1.html +X-NUCLEO-IDB05A2: https://www.st.com/en/ecosystems/x-nucleo-idb05a2.html +X-NUCLEO-IDB05A1: https://www.st.com/en/ecosystems/x-nucleo-idb05a1.html \ No newline at end of file diff --git a/docs/api.md b/docs/api.md deleted file mode 100644 index c9f41840..00000000 --- a/docs/api.md +++ /dev/null @@ -1,3818 +0,0 @@ -# ArduinoBLE library - -## BLE class - -Used to enable the Bluetooth® Low Energy module. - -### `BLE.begin()` - -Initializes the Bluetooth® Low Energy device. - -#### Syntax - -``` -BLE.begin() - -``` - -#### Parameters - -None - -#### Returns -- 1 on success -- 0 on failure - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - -``` - -### `BLE.end()` - -Stops the Bluetooth® Low Energy device. - -#### Syntax - -``` -BLE.end() - -``` - -#### Parameters - -None - -#### Returns -Nothing - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - // .... - - BLE.end(); - - -``` - -### `BLE.poll()` - -Poll for Bluetooth® Low Energy radio events and handle them. - -#### Syntax - -``` -BLE.poll() -BLE.poll(timeout) - -``` - -#### Parameters - -**timeout**: optional timeout in ms, to wait for event. If not specified defaults to 0 ms. - -#### Returns -Nothing - -#### Example - -```arduino - - // assign event handlers for connected, disconnected to peripheral - BLE.setEventHandler(BLEConnected, blePeripheralConnectHandler); - BLE.setEventHandler(BLEDisconnected, blePeripheralDisconnectHandler); - - - BLE.poll(); - - -``` - -### `BLE.setEventHandler()` - -Set the event handler (callback) function that will be called when the specified event occurs. - -#### Syntax - -``` -BLE.setEventHandler(eventType, callback) - -``` - -#### Parameters - -- **eventType**: event type (BLEConnected, BLEDisconnected) -- **callback**: function to call when event occurs -#### Returns -Nothing. - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - // ... - - // assign event handlers for connected, disconnected to peripheral - BLE.setEventHandler(BLEConnected, blePeripheralConnectHandler); - BLE.setEventHandler(BLEDisconnected, blePeripheralDisconnectHandler); - - - -void blePeripheralConnectHandler(BLEDevice central) { - // central connected event handler - Serial.print("Connected event, central: "); - Serial.println(central.address()); -} - -void blePeripheralDisconnectHandler(BLEDevice central) { - // central disconnected event handler - Serial.print("Disconnected event, central: "); - Serial.println(central.address()); -} - - -``` - -### `BLE.connected()` - -Query if another Bluetooth® Low Energy device is connected - -#### Syntax - -``` -BLE.connected() - -``` - -#### Parameters - -None - -#### Returns -- **true** if another Bluetooth® Low Energy device is connected, -- otherwise **false**. - -#### Example - -```arduino - - // while the central is still connected to peripheral: - while (BLE.connected()) { - - // ... - } - - -``` - -### `BLE.disconnect()` - -Disconnect any Bluetooth® Low Energy devices that are connected - -#### Syntax - -``` -BLE.disconnect() - -``` - -#### Parameters - -None - -#### Returns -- **true** if any Bluetooth® Low Energy device that was previously connected was disconnected, -- otherwise **false**. - -#### Example - -```arduino - - if (BLE.connected()) { - BLE.disconnect(); - } - - -``` - -### `BLE.address()` - -Query the Bluetooth® address of the Bluetooth® Low Energy device. - -#### Syntax - -``` -BLE.address() - -``` - -#### Parameters - -None - -#### Returns -- The **Bluetooth® address** of the Bluetooth® Low Energy device (as a String). - -#### Example - -```arduino - - String address = BLE.address(); - - Serial.print("Local address is: "); - Serial.println(address); - - -``` - -### `BLE.rssi()` - -Query the RSSI (Received signal strength indication) of the connected Bluetooth® Low Energy device. - -#### Syntax - -``` -BLE.rssi() - -``` - -#### Parameters - -None - -#### Returns -- The **RSSI** of the connected Bluetooth® Low Energy device, 127 if no Bluetooth® Low Energy device is connected. - -#### Example - -```arduino - - if (BLE.connected()) { - Serial.print("RSSI = "); - Serial.println(BLE.rssi()); - } - - -``` - -### `BLE.setAdvertisedServiceUuid()` - -Set the advertised service UUID used when advertising. - -#### Syntax - -``` -BLE.setAdvertisedServiceUuid(uuid) - -``` - -#### Parameters - -- **uuid:** 16-bit or 128-bit Bluetooth® Low Energy UUID in **String** format - -#### Returns -Nothing - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - BLE.setAdvertisedServiceUuid("19B10000-E8F2-537E-4F6C-D104768A1214"); - - // ... - - // start advertising - BLE.advertise(); - - -``` - -### `BLE.setAdvertisedService()` - -Set the advertised service UUID used when advertising to the value of the BLEService provided. - -#### Syntax - -``` -BLE.setAdvertisedService(bleService) - -``` - -#### Parameters - -- **bleService:** BLEService to use UUID from - -#### Returns -Nothing - -#### Example - -```arduino - -BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // Bluetooth® Low Energy LED Service - -// ... - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - BLE.setAdvertisedService(ledService); - - // ... - - // start advertising - BLE.advertise(); - - -``` - -### `BLE.setManufacturerData()` - -Set the manufacturer data value used when advertising. - -#### Syntax - -``` -BLE.setManufacturerData(data, length) - -``` - -#### Parameters - -- **data:** byte array containing manufacturer data -- **length:** length of manufacturer data array - -#### Returns -Nothing - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - byte data[5] = { 0x01, 0x02, 0x03, 0x04, 0x05}; - - BLE.setManufacturerData(data, 5); - - // ... - - // start advertising - BLE.advertise(); - - - -``` - -### `BLE.setLocalName()` - -Set the local value used when advertising. - -#### Syntax - -``` -BLE.setLocalName(name) - -``` - -#### Parameters - -- **name:** local name value to use when advertising - -#### Returns -Nothing - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - BLE.setLocalName("LED"); - - // ... - - // start advertising - BLE.advertise(); - - - -``` - -### `BLE.setDeviceName()` - -Set the device name in the built in device name characteristic. If not set, the value defaults to “Arduino”. - -#### Syntax - -``` -BLE.setDeviceName(name) - -``` - -#### Parameters - -- **name:** device name value - -#### Returns -Nothing - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - BLE.setDeviceName("LED"); - - // ... - - // start advertising - BLE.advertise(); - - - -``` - -### `BLE.setAppearance()` - -Set the appearance in the built in appearance characteristic. If not set, the value defaults to 0x0000. - -#### Syntax - -``` -BLE.setAppearance(appearance) - -``` - -#### Parameters - -- **appearance:** appearance value - -#### Returns -Nothing - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - BLE.setAppearance(0x8000); - - // ... - - // start advertising - BLE.advertise(); - - - -``` - -### `BLE.addService()` - -Add a BLEService to the set of services the Bluetooth® Low Energy device provides - -#### Syntax - -``` -BLE.addService(service) - -``` - -#### Parameters - -- **service:** BLEService to add - -#### Returns -Nothing - -#### Example - -```arduino - -BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // Bluetooth® Low Energy LED Service - - - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - // ... - - BLE.addService(ledService); - - // ... - - -``` - -### `BLE.advertise()` - -Start advertising. - -#### Syntax - -``` -BLE.advertise() - -``` - -#### Parameters - -None - -#### Returns -- 1 on success, -- 0 on failure. - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - // ... - - BLE.advertise(); - - // ... - - -``` - -### `BLE.stopAdvertise()` - -Stop advertising. - -#### Syntax - -``` -BLE.stopAdvertise() - -``` - -#### Parameters - -None - -#### Returns -Nothing - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - // ... - - BLE.advertise(); - - // ... - - BLE.stopAdvertise(); - - -``` - -### `BLE.central()` - -Query the central Bluetooth® Low Energy device connected. - -#### Syntax - -``` -BLE.central() - -``` - -#### Parameters - -None - -#### Returns -- **BLEDevice** representing the central. - -#### Example - -```arduino - - // listen for Bluetooth® Low Energy peripherals to connect: - BLEDevice central = BLE.central(); - - // if a central is connected to peripheral: - if (central) { - Serial.print("Connected to central: "); - // print the central's MAC address: - Serial.println(central.address()); - } - - -``` - -### `BLE.setAdvertisingInterval()` - -Set the advertising interval in units of 0.625 ms. Defaults to 100ms (160 * 0.625 ms) if not provided. - -#### Syntax - -``` -BLE.setAdvertisingInterval(advertisingInterval) - -``` - -#### Parameters - -- **advertisingInterval:** advertising interval in units of 0.625 ms - -#### Returns -Nothing. - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - // ... - - BLE.setAdvertisingInterval(320); // 200 * 0.625 ms - - BLE.advertise(); - - -``` - -### `BLE.setConnectionInterval()` - -Set the minimum and maximum desired connection intervals in units of 1.25 ms. - -#### Syntax - -``` -BLE.setConnectionInterval(minimum, maximum) - -``` - -#### Parameters - -- **minimum:** minimum desired connection interval in units of 1.25 ms -- **maximum:** maximum desired connection interval in units of 1.25 ms - -#### Returns -Nothing. - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - // ... - - BLE.setConnectionInterval(0x0006, 0x0c80); // 7.5 ms minimum, 4 s maximum - - - -``` - -### `BLE.setConnectable()` - -Set if the device is connectable after advertising, defaults to **true**. - -#### Syntax - -``` -BLE.setConnectable(connectable) - -``` - -#### Parameters - -- **true**: the device will be connectable when advertising -- **false**: the device will NOT be connectable when advertising - -#### Returns -Nothing. - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - // ... - - BLE.setConnectable(false); // make the device unconnectable when advertising - - - -``` - -### `BLE.scan()` - -Start scanning for Bluetooth® Low Energy devices that are advertising. - -#### Syntax - -``` -BLE.scan() -BLE.scan(withDuplicates) - -``` - -#### Parameters - -- **withDuplicates:** optional, defaults to **false**. If **true**, advertisements received more than once will not be filtered - -#### Returns -- 1 on success, -- 0 on failure. - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - Serial.println("BLE Central scan"); - - // start scanning for peripheral - BLE.scan(); - - - BLEDevice peripheral = BLE.available(); - - if (peripheral) { - // ... - } - - -``` - -### `BLE.scanForName()` - -Start scanning for Bluetooth® Low Energy devices that are advertising with a particular (local) name. - -#### Syntax - -``` -BLE.scanForName(name) -BLE.scanForName(name, withDuplicates) - -``` - -#### Parameters - -- **name:** (local) name of device (as a **String**) to filter for -- **withDuplicates:** optional, defaults to **false**. If **true**, advertisements received more than once will not be filtered. - -#### Returns -- 1 on success, -- 0 on failure. - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - Serial.println("BLE Central scan"); - - // start scanning for peripheral - BLE.scanForName("LED"); - - - BLEDevice peripheral = BLE.available(); - - if (peripheral) { - // ... - } - - -``` - -### `BLE.scanForAddress()` - -Start scanning for Bluetooth® Low Energy devices that are advertising with a particular (Bluetooth®) address. - -#### Syntax - -``` -BLE.scanForAddress(address) -BLE.scanForAddress(address, withDuplicates) - -``` - -#### Parameters - -- **address:** (Bluetooth®) address (as a String) to filter for -- **withDuplicates:** optional, defaults to **false**. If **true**, advertisements received more than once will not be filtered - -#### Returns -- 1 on success, -- 0 on failure. - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - Serial.println("BLE Central scan"); - - // start scanning for peripheral - BLE.scanForAddress("aa:bb:cc:ee:dd:ff"); - - - BLEDevice peripheral = BLE.available(); - - if (peripheral) { - // ... - } - - -``` - -### `BLE.scanForUuid()` - -Start scanning for Bluetooth® Low Energy devices that are advertising with a particular (service) UUID. - -#### Syntax - -``` -BLE.scanForUuid(uuid) -BLE.scanForUuid(uuid, withDuplicates) - -``` - -#### Parameters - -- **uuid:** (service) UUID (as a **String**) to filter for -- **withDuplicates:** optional, defaults to **false**. If **true**, advertisements received more than once will not be filtered. - -#### Returns -- 1 on success, -- 0 on failure. - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - Serial.println("BLE Central scan"); - - // start scanning for peripheral - BLE.scanForUuid("aa10"); - - - BLEDevice peripheral = BLE.available(); - - if (peripheral) { - // ... - } - - -``` - -### `BLE.stopScan()` - -Stop scanning for Bluetooth® Low Energy devices that are advertising. - -#### Syntax - -``` -BLE.stopScan() - -``` - -#### Parameters - -None - -#### Returns -Nothing - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - Serial.println("BLE Central scan"); - - // start scanning for peripheral - BLE.scan(); - - BLE.stopScan(); - - -``` - -### `BLE.available()` - -Query for a discovered Bluetooth® Low Energy device that was found during scanning. - -#### Syntax - -``` -BLE.available() - -``` - -#### Parameters - -Nothing - -#### Returns -- **BLEDevice** representing the discovered device. - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - Serial.println("BLE Central scan"); - - // start scanning for peripheral - BLE.scan(); - - - BLEDevice peripheral = BLE.available(); - - if (peripheral) { - // ... - } - - -``` - -## BLEDevice Class - -Used to get information about the devices connected or discovered while scanning - -### `bleDevice.poll()` - -Poll for Bluetooth® Low Energy radio events for the specified Bluetooth® Low Energy device and handle them. - -#### Syntax - -``` -bleDevice.poll() -bleDevice.poll(timeout) - -``` - -#### Parameters - -- **timeout**: optional timeout in ms, to wait for event. If not specified defaults to 0 ms. - -#### Returns -Nothing - -#### Example - -```arduino - - // listen for Bluetooth® Low Energy centrals to connect: - BLEDevice central = BLE.central(); - - // if a central is connected to peripheral: - if (central) { - central.poll(); - - // ... - } - - -``` - -### `bleDevice.connected()` - -Query if a Bluetooth® Low Energy device is connected - -#### Syntax - -``` -bleDevice.connected() - -``` - -#### Parameters - -None - -#### Returns -- **true** if the Bluetooth® Low Energy device is connected, -- otherwise **false**. - -#### Example - -```arduino - - // listen for Bluetooth® Low Energy centrals to connect: - BLEDevice central = BLE.central(); - - // while the central is still connected - while (central.connected()) { - - // ... - } - - -``` - -### `bleDevice.disconnect()` - -Disconnect the Bluetooth® Low Energy device, if connected - -#### Syntax - -``` -bleDevice.disconnect() - -``` - -#### Parameters - -None - -#### Returns -- **true** if the Bluetooth® Low Energy device was disconnected, -- otherwise **false**. - -#### Example - -```arduino - - // listen for Bluetooth® Low Energy centrals to connect: - BLEDevice central = BLE.central(); - - - central.disconnect(); - - -``` - -### `bleDevice.address()` - -Query the Bluetooth® address of the Bluetooth® Low Energy device. - -#### Syntax - -``` -bleDevice.address() - -``` - -#### Parameters - -None - -#### Returns -- **Bluetooth® address** of the Bluetooth® Low Energy device (as a String). - -#### Example - -```arduino - - // listen for Bluetooth® Low Energy peripherals to connect: - BLEDevice central = BLE.central(); - - // if a central is connected to peripheral: - if (central) { - Serial.print("Connected to central: "); - // print the central's MAC address: - Serial.println(central.address()); - } - - -``` - -### `bleDevice.rssi()` - -Query the RSSI (Received signal strength indication) of the Bluetooth® Low Energy device. - -#### Syntax - -``` -bleDevice.rssi() - -``` - -#### Parameters - -None - -#### Returns -- **RSSI** of the connected Bluetooth® Low Energy device, 127 if the Bluetooth® Low Energy device is not connected. - -#### Example - -```arduino - - if (bleDevice.connected()) { - Serial.print("RSSI = "); - Serial.println(bleDevice.rssi()); - } - - -``` - -### `bleDevice.characteristic()` - -Get a BLECharacteristic representing a Bluetooth® Low Energy characteristic the device provides. - -#### Syntax - -``` -bleDevice.characteristic(index) -bleDevice.characteristic(uuid) -bleDevice.characteristic(uuid, index) - -``` - -#### Parameters - -- **index**: index of characteristic -- **uuid**: uuid (as a **String**) - -#### Returns -- **BLECharacteristic** for provided parameters - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - Serial.println("BLE Central scan"); - - // start scanning for peripheral - BLE.scan(); - - - BLEDevice peripheral = BLE.available(); - - if (peripheral) { - // ... - - Serial.println("Connecting ..."); - - if (peripheral.connect()) { - Serial.println("Connected"); - } else { - Serial.println("Failed to connect!"); - return; - } - - // discover peripheral attributes - Serial.println("Discovering attributes ..."); - if (peripheral.discoverAttributes()) { - Serial.println("Attributes discovered"); - } else { - Serial.println("Attribute discovery failed!"); - peripheral.disconnect(); - return; - } - - BLECharacteristic batteryLevelCharacteristic = peripheral.characteristic("2a19"); - - if (batteryLevelCharacteristic) { - // use the characteristic - } else { - Serial.println("Peripheral does NOT have battery level characteristic"); - } - - // ... - } - - -``` - -### `bleDevice.discoverAttributes()` - -Discover all of the attributes of Bluetooth® Low Energy device. - -#### Syntax - -``` -bleDevice.discoverAttributes() - -``` - -#### Parameters - -None - -#### Returns -- **true**, if successful, -- **false** on failure. - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - Serial.println("BLE Central scan"); - - // start scanning for peripheral - BLE.scan(); - - - BLEDevice peripheral = BLE.available(); - - if (peripheral) { - // ... - - Serial.println("Connecting ..."); - - if (peripheral.connect()) { - Serial.println("Connected"); - } else { - Serial.println("Failed to connect!"); - return; - } - - // discover peripheral attributes - Serial.println("Discovering attributes ..."); - if (peripheral.discoverAttributes()) { - Serial.println("Attributes discovered"); - } else { - Serial.println("Attribute discovery failed!"); - peripheral.disconnect(); - return; - } - - // ... - } - - -``` - -### `bleDevice.discoverService()` - -Discover the attributes of a particular service on the Bluetooth® Low Energy device. - -#### Syntax - -``` -bleDevice.discoverService(serviceUuid) - -``` - -#### Parameters - -- **serviceUuid:** service UUID to discover (as a **String**) - -#### Returns -- **true**, if successful, -- **false** on failure. - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - Serial.println("BLE Central scan"); - - // start scanning for peripheral - BLE.scan(); - - - BLEDevice peripheral = BLE.available(); - - if (peripheral) { - // ... - - Serial.println("Connecting ..."); - - if (peripheral.connect()) { - Serial.println("Connected"); - } else { - Serial.println("Failed to connect!"); - return; - } - - // discover service attributes - Serial.println("Discovering service attributes ..."); - if (peripheral.serviceUuid("fffe")) { - Serial.println("Service attributes discovered"); - } else { - Serial.println("Service attribute discovery failed!"); - peripheral.disconnect(); - return; - } - - // ... - } - - -``` - -### `bleDevice.deviceName()` - -Query the device name (BLE characteristic UUID 0x2a00) of a Bluetooth® Low Energy device. - -#### Syntax - -``` -bleDevice.deviceName() - -``` - -#### Parameters - -None - -#### Returns -- **Device name** (as a String). - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - Serial.println("BLE Central scan"); - - // start scanning for peripheral - BLE.scan(); - - - BLEDevice peripheral = BLE.available(); - - if (peripheral) { - // ... - - Serial.println("Connecting ..."); - - if (peripheral.connect()) { - Serial.println("Connected"); - } else { - Serial.println("Failed to connect!"); - return; - } - - // discover peripheral attributes - Serial.println("Discovering attributes ..."); - if (peripheral.discoverAttributes()) { - Serial.println("Attributes discovered"); - } else { - Serial.println("Attribute discovery failed!"); - peripheral.disconnect(); - return; - } - - // read and print device name of peripheral - Serial.println(); - Serial.print("Device name: "); - Serial.println(peripheral.deviceName()); - Serial.print("Appearance: 0x"); - Serial.println(peripheral.appearance(), HEX); - Serial.println(); - - // ... - } - - -``` - -### `bleDevice.appearance()` - -Query the appearance (BLE characteristic UUID 0x2a01) of a Bluetooth® Low Energy device. - -#### Syntax - -``` -bleDevice.appearance() - -``` - -#### Parameters - -None - -#### Returns -- **Appearance value** (as a number). - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - Serial.println("BLE Central scan"); - - // start scanning for peripheral - BLE.scan(); - - - BLEDevice peripheral = BLE.available(); - - if (peripheral) { - // ... - - Serial.println("Connecting ..."); - - if (peripheral.connect()) { - Serial.println("Connected"); - } else { - Serial.println("Failed to connect!"); - return; - } - - // discover peripheral attributes - Serial.println("Discovering attributes ..."); - if (peripheral.discoverAttributes()) { - Serial.println("Attributes discovered"); - } else { - Serial.println("Attribute discovery failed!"); - peripheral.disconnect(); - return; - } - - // read and print device name of peripheral - Serial.println(); - Serial.print("Device name: "); - Serial.println(peripheral.deviceName()); - Serial.print("Appearance: 0x"); - Serial.println(peripheral.appearance(), HEX); - Serial.println(); - - // ... - } - - -``` - -### `bleDevice.serviceCount()` - -Query the number of services discovered for the Bluetooth® Low Energy device. - -#### Syntax - -``` -bleDevice.serviceCount() - -``` - -#### Parameters - -None - -#### Returns -- The number of **services discovered** for the Bluetooth® Low Energy device. - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - Serial.println("BLE Central scan"); - - // start scanning for peripheral - BLE.scan(); - - - BLEDevice peripheral = BLE.available(); - - if (peripheral) { - // ... - - Serial.println("Connecting ..."); - - if (peripheral.connect()) { - Serial.println("Connected"); - } else { - Serial.println("Failed to connect!"); - return; - } - - // discover peripheral attributes - Serial.println("Discovering attributes ..."); - if (peripheral.discoverAttributes()) { - Serial.println("Attributes discovered"); - } else { - Serial.println("Attribute discovery failed!"); - peripheral.disconnect(); - return; - } - - int serviceCount = peripheral.serviceCount(); - - Serial.print(serviceCount); - Serial.println(" services discovered"); - - // ... - } - - -``` - -### `bleDevice.hasService()` - -Query if the Bluetooth® Low Energy device has a particular service. - -#### Syntax - -``` -bleDevice.hasService(uuid) -bleDevice.hasService(uuid, index) - -``` - -#### Parameters - -- **uuid**: uuid to check (as a **String**) -- **index**: optional, index of service to check if the device provides more than on. Defaults to 0, if not provided. - -#### Returns -- **true**, if the device provides the service, -- **false** otherwise. - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - Serial.println("BLE Central scan"); - - // start scanning for peripheral - BLE.scan(); - - - BLEDevice peripheral = BLE.available(); - - if (peripheral) { - // ... - - Serial.println("Connecting ..."); - - if (peripheral.connect()) { - Serial.println("Connected"); - } else { - Serial.println("Failed to connect!"); - return; - } - - // discover peripheral attributes - Serial.println("Discovering attributes ..."); - if (peripheral.discoverAttributes()) { - Serial.println("Attributes discovered"); - } else { - Serial.println("Attribute discovery failed!"); - peripheral.disconnect(); - return; - } - - if (peripheral.hasService("180f")) { - Serial.println("Peripheral has battery service"); - } - - // ... - } - - -``` - -### `bleDevice.service()` - -Get a BLEService representing a Bluetooth® Low Energy service the device provides. - -#### Syntax - -``` -bleDevice.service(index) -bleDevice.service(uuid) -bleDevice.service(uuid, index) - -``` - -#### Parameters - -- **index**: index of service -- **uuid**: uuid (as a **String**) - -#### Returns -- **BLEService** for provided parameters - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - Serial.println("BLE Central scan"); - - // start scanning for peripheral - BLE.scan(); - - - BLEDevice peripheral = BLE.available(); - - if (peripheral) { - // ... - - Serial.println("Connecting ..."); - - if (peripheral.connect()) { - Serial.println("Connected"); - } else { - Serial.println("Failed to connect!"); - return; - } - - // discover peripheral attributes - Serial.println("Discovering attributes ..."); - if (peripheral.discoverAttributes()) { - Serial.println("Attributes discovered"); - } else { - Serial.println("Attribute discovery failed!"); - peripheral.disconnect(); - return; - } - - BLEService batteryService = peripheral.service("180f"); - - if (batteryService) { - // use the service - } else { - Serial.println("Peripheral does NOT have battery service"); - } - - // ... - } - - -``` - -### `bleDevice.characteristicCount()` - -Query the number of characteristics discovered for the Bluetooth® Low Energy device. - -#### Syntax - -``` -bleDevice.characteristicCount() - -``` - -#### Parameters - -None - -#### Returns -- The **number of characteristics** discovered for the Bluetooth® Low Energy device. - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - Serial.println("BLE Central scan"); - - // start scanning for peripheral - BLE.scan(); - - - BLEDevice peripheral = BLE.available(); - - if (peripheral) { - // ... - - Serial.println("Connecting ..."); - - if (peripheral.connect()) { - Serial.println("Connected"); - } else { - Serial.println("Failed to connect!"); - return; - } - - // discover peripheral attributes - Serial.println("Discovering attributes ..."); - if (peripheral.discoverAttributes()) { - Serial.println("Attributes discovered"); - } else { - Serial.println("Attribute discovery failed!"); - peripheral.disconnect(); - return; - } - - int characteristicCount = peripheral.characteristicCount(); - - Serial.print(characteristicCount); - Serial.println(" characteristics discovered"); - - // ... - } - - -``` - -### `bleDevice.hasCharacteristic()` - -Query if the Bluetooth® Low Energy device has a particular characteristic. - -#### Syntax - -``` -bleDevice.hasCharacteristic(uuid) -bleDevice.hasCharacteristic(uuid, index) - -``` - -#### Parameters - -- **uuid**: uuid to check (as a **String**) -- **index**: optional, index of characteristic to check if the device provides more than on. Defaults to 0, if not provided. - -#### Returns -- **true**, if the device provides the characteristic, -- **false** otherwise. - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - Serial.println("BLE Central scan"); - - // start scanning for peripheral - BLE.scan(); - - - BLEDevice peripheral = BLE.available(); - - if (peripheral) { - // ... - - Serial.println("Connecting ..."); - - if (peripheral.connect()) { - Serial.println("Connected"); - } else { - Serial.println("Failed to connect!"); - return; - } - - // discover peripheral attributes - Serial.println("Discovering attributes ..."); - if (peripheral.discoverAttributes()) { - Serial.println("Attributes discovered"); - } else { - Serial.println("Attribute discovery failed!"); - peripheral.disconnect(); - return; - } - - if (peripheral.hasCharacteristic("2a19")) { - Serial.println("Peripheral has battery level characteristic"); - } - - // ... - } - - -``` - -### `bleDevice.hasLocalName()` - -Query if a discovered Bluetooth® Low Energy device is advertising a local name. - -#### Syntax - -``` -bleDevice.hasLocalName() - -``` - -#### Parameters - -Nothing - -#### Returns -- **true**, if the device is advertising a local name, -- **false** otherwise. - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - Serial.println("BLE Central scan"); - - // start scanning for peripheral - BLE.scan(); - - - BLEDevice peripheral = BLE.available(); - - if (peripheral) { - // ... - - // print the local name, if present - if (peripheral.hasLocalName()) { - Serial.print("Local Name: "); - Serial.println(peripheral.localName()); - } - - // ... - } - - -``` - -### `bleDevice.hasAdvertisedServiceUuid()` - -Query if a discovered Bluetooth® Low Energy device is advertising a service UUID. - -#### Syntax - -``` -bleDevice.hasAdvertisedServiceUuid() -bleDevice.hasAdvertisedServiceUuid(index) - -``` - -#### Parameters - -- **index**: optional, defaults to 0, the index of the service UUID, if the device is advertising more than one. - -#### Returns -- **true**, if the device is advertising a service UUID, -- **false** otherwise. - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - Serial.println("BLE Central scan"); - - // start scanning for peripheral - BLE.scan(); - - - BLEDevice peripheral = BLE.available(); - - if (peripheral) { - // ... - - // print the advertised service UUIDs, if present - if (peripheral.hasAdvertisedServiceUuid()) { - Serial.print("Service UUIDs: "); - for (int i = 0; i < peripheral.advertisedServiceUuidCount(); i++) { - Serial.print(peripheral.advertisedServiceUuid(i)); - Serial.print(" "); - } - Serial.println(); - } - - // ... - } - - -``` - -### `bleDevice.advertisedServiceUuidCount()` - -Query the number of advertised services a discovered Bluetooth® Low Energy device is advertising. - -#### Syntax - -``` -bleDevice.advertisedServiceUuidCount() - -``` - -#### Parameters - -None - -#### Returns -- The **number of advertised services** a discovered Bluetooth® Low Energy device is advertising. - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - Serial.println("BLE Central scan"); - - // start scanning for peripheral - BLE.scan(); - - - BLEDevice peripheral = BLE.available(); - - if (peripheral) { - // ... - - // print the advertised service UUIDs, if present - if (peripheral.hasAdvertisedServiceUuid()) { - Serial.print("Service UUIDs: "); - for (int i = 0; i < peripheral.advertisedServiceUuidCount(); i++) { - Serial.print(peripheral.advertisedServiceUuid(i)); - Serial.print(" "); - } - Serial.println(); - } - - // ... - } - - -``` - -### `bleDevice.localName()` - -Query the local name a discovered Bluetooth® Low Energy device is advertising with. - -#### Syntax - -``` -bleDevice.localName() - -``` - -#### Parameters - -Nothing - -#### Returns -- **Advertised local name** (as a String). - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - Serial.println("BLE Central scan"); - - // start scanning for peripheral - BLE.scan(); - - - BLEDevice peripheral = BLE.available(); - - if (peripheral) { - // ... - - // print the local name, if present - if (peripheral.hasLocalName()) { - Serial.print("Local Name: "); - Serial.println(peripheral.localName()); - } - - // ... - } - - -``` - -### `bleDevice.advertisedServiceUuid()` - -Query an advertised service UUID discovered Bluetooth® Low Energy device is advertising. - -#### Syntax - -``` -bleDevice.advertisedServiceUuid() -bleDevice.advertisedServiceUuid(index) - -``` - -#### Parameters - -- **index**: optional, defaults to 0, the index of the **service UUID**, if the device is advertising more than one. - -#### Returns -- Advertised service **UUID** (as a String). - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - Serial.println("BLE Central scan"); - - // start scanning for peripheral - BLE.scan(); - - - BLEDevice peripheral = BLE.available(); - - if (peripheral) { - // ... - - // print the advertised service UUIDs, if present - if (peripheral.hasAdvertisedServiceUuid()) { - Serial.print("Service UUIDs: "); - for (int i = 0; i < peripheral.advertisedServiceUuidCount(); i++) { - Serial.print(peripheral.advertisedServiceUuid(i)); - Serial.print(" "); - } - Serial.println(); - } - - // ... - } - - -``` - -### `bleDevice.connect()` - -Connect to a Bluetooth® Low Energy device. - -#### Syntax - -``` -bleDevice.connect() - -``` - -#### Parameters - -None - -#### Returns -- **true**, if the connection was successful, -- **false** otherwise. - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - Serial.println("BLE Central scan"); - - // start scanning for peripheral - BLE.scan(); - - - BLEDevice peripheral = BLE.available(); - - if (peripheral) { - // ... - - Serial.println("Connecting ..."); - - if (peripheral.connect()) { - Serial.println("Connected"); - } else { - Serial.println("Failed to connect!"); - return; - } - - // ... - } - - -``` - -## BLEService Class - -Used to enable the services board provides or interact with services a remote board provides. - -### `BLEService()` - -Create a new Bluetooth® Low Energy service. - -#### Syntax - -``` -BLEService(uuid) - -``` - -#### Parameters - -- **uuid**: 16-bit or 128-bit UUID in **String** format - -#### Returns -- New **BLEService** with the specified **UUID** - -#### Example - -```arduino - -BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // Bluetooth® Low Energy LED Service - - -``` - -### `bleService.uuid()` - -Query the UUID of the specified BLEService. - -#### Syntax - -``` -bleService.uuid() - -``` - -#### Parameters - -None - -#### Returns -- UUID of the Bluetooth® Low Energy service as a **String**. - -#### Example - -```arduino - -BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // Bluetooth® Low Energy LED Service - - -Serial.print("LED service UUID = "); -Serial.println(ledService.uuid()); - - - -``` - -### `bleService.addCharacteristic()` - -Add a BLECharacteristic to the Bluetooth® Low Energy service. - -#### Syntax - -``` -bleService.addCharacteristic(bleCharacteristic) - -``` - -#### Parameters - -None - -#### Returns -Nothing - -#### Example - -```arduino - -BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // Bluetooth® Low Energy LED Service - -// Bluetooth® Low Energy LED Switch Characteristic - custom 128-bit UUID, readable and writable by central -BLECharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite, 1); - - - - -// add the characteristic to the service -ledService.addCharacteristic(switchCharacteristic); - - - -``` - -### `bleService.characteristicCount()` - -Query the number of characteristics discovered for the Bluetooth® Low Energy service. - -#### Syntax - -``` -bleService.characteristicCount() - -``` - -#### Parameters - -None - -#### Returns -- The **number of characteristics** discovered for the Bluetooth® Low Energy service. - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - Serial.println("BLE Central scan"); - - // start scanning for peripheral - BLE.scan(); - - - BLEDevice peripheral = BLE.available(); - - if (peripheral) { - // ... - - Serial.println("Connecting ..."); - - if (peripheral.connect()) { - Serial.println("Connected"); - } else { - Serial.println("Failed to connect!"); - return; - } - - // discover peripheral attributes - Serial.println("Discovering attributes ..."); - if (peripheral.discoverAttributes()) { - Serial.println("Attributes discovered"); - } else { - Serial.println("Attribute discovery failed!"); - peripheral.disconnect(); - return; - } - - BLEService batteryService = peripheral.service("180f"); - - if (batteryService) { - // use the service - int characteristicCount = batteryService.characteristicCount(); - - Serial.print(characteristicCount); - Serial.println(" characteristics discovered in battery service"); - } else { - Serial.println("Peripheral does NOT have battery service"); - } - - // ... - } - - -``` - -### `bleService.hasCharacteristic()` - -Query if the Bluetooth® Low Energy service has a particular characteristic. - -#### Syntax - -``` -bleService.hasCharacteristic(uuid) -bleService.hasCharacteristic(uuid, index) - -``` - -#### Parameters - -- **uuid**: uuid to check (as a **String**) -- **index**: optional, index of characteristic to check if the device provides more than on. Defaults to 0, if not provided. - -#### Returns -- **true**, if the service provides the characteristic, -- **false** otherwise. - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - Serial.println("BLE Central scan"); - - // start scanning for peripheral - BLE.scan(); - - BLEDevice peripheral = BLE.available(); - - if (peripheral) { - // ... - - Serial.println("Connecting ..."); - - if (peripheral.connect()) { - Serial.println("Connected"); - } else { - Serial.println("Failed to connect!"); - return; - } - - // discover peripheral attributes - Serial.println("Discovering attributes ..."); - if (peripheral.discoverAttributes()) { - Serial.println("Attributes discovered"); - } else { - Serial.println("Attribute discovery failed!"); - peripheral.disconnect(); - return; - } - - BLEService batteryService = peripheral.service("180f"); - - if (batteryService) { - // use the service - if (batteryService.hasCharacteristic("2a19")) { - Serial.println("Battery service has battery level characteristic"); - } - } else { - Serial.println("Peripheral does NOT have battery service"); - } - - // ... - } - - -``` - -### `bleService.characteristic()` - -Get a BLECharacteristic representing a Bluetooth® Low Energy characteristic the service provides. - -#### Syntax - -``` -bleService.characteristic(index) -bleService.characteristic(uuid) -bleService.characteristic(uuid, index) - -``` - -#### Parameters - -- **index**: index of characteristic -- **uuid**: uuid (as a **String**) - -#### Returns -- **BLECharacteristic** for provided parameters - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - Serial.println("BLE Central scan"); - - // start scanning for peripheral - BLE.scan(); - - - BLEDevice peripheral = BLE.available(); - - if (peripheral) { - // ... - - Serial.println("Connecting ..."); - - if (peripheral.connect()) { - Serial.println("Connected"); - } else { - Serial.println("Failed to connect!"); - return; - } - - // discover peripheral attributes - Serial.println("Discovering attributes ..."); - if (peripheral.discoverAttributes()) { - Serial.println("Attributes discovered"); - } else { - Serial.println("Attribute discovery failed!"); - peripheral.disconnect(); - return; - } - - BLEService batteryService = peripheral.service("180f"); - - if (batteryService) { - // use the service - BLECharacteristic batteryLevelCharacteristic = peripheral.characteristic("2a19"); - - if (batteryLevelCharacteristic) { - // use the characteristic - } else { - Serial.println("Peripheral does NOT have battery level characteristic"); - } - } else { - Serial.println("Peripheral does NOT have battery service"); - } - - // ... - } - - -``` - -## BLECharacteristic Class - -Used to enable the characteristics board offers in a service or interact with characteristics a remote board provides. - -### `BLECharacteristic()` - -Create a new Bluetooth® Low Energy characteristic. - -#### Syntax - -``` -BLECharacteristic(uuid, properties, value, valueSize) -BLECharacteristic(uuid, properties, stringValue) - -BLEBoolCharacteristic(uuid, properties) -BLEBooleanCharacteristic(uuid, properties) -BLECharCharacteristic(uuid, properties) -BLEUnsignedCharCharacteristic(uuid, properties) -BLEByteCharacteristic(uuid, properties) -BLEShortCharacteristic(uuid, properties) -BLEUnsignedShortCharacteristic(uuid, properties) -BLEWordCharacteristic(uuid, properties) -BLEIntCharacteristic(uuid, properties) -BLEUnsignedIntCharacteristic(uuid, properties) -BLELongCharacteristic(uuid, properties) -BLEUnsignedLongCharacteristic(uuid, properties) -BLEFloatCharacteristic(uuid, properties) -BLEDoubleCharacteristic(uuid, properties) -``` - -#### Parameters - -- **uuid**: 16-bit or 128-bit UUID in **String** format -- **properties**: mask of the properties (BLEBroadcast, BLERead, BLEWriteWithoutResponse, BLEWrite, BLENotify, BLEIndicate) -- **valueSize**: (maximum) size of characteristic value -- **stringValue**: value as a string - -#### Returns -- New **BLECharacteristic** with the specified **UUID** and value - -#### Example - -```arduino - -// Bluetooth® Low Energy Battery Level Characteristic -BLEUnsignedCharCharacteristic batteryLevelChar("2A19", // standard 16-bit characteristic UUID - BLERead | BLENotify); // remote clients will be able to get notifications if this characteristic changes - - - -``` - -### `bleCharacteristic.uuid()` - -Query the UUID of the specified BLECharacteristic. - -#### Syntax - -``` -bleCharacteristic.uuid() - -``` - -#### Parameters - -None - -#### Returns -- **UUID** of the Bluetooth® Low Energy service as a **String**. - -#### Example - -```arduino - -// Bluetooth® Low Energy LED Switch Characteristic - custom 128-bit UUID, read and writable by central -BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite); - - -Serial.print("Switch characteristic UUID = "); -Serial.println(switchCharacteristic.uuid()); - - - -``` - -### `bleCharacteristic.properties()` - -Query the property mask of the specified BLECharacteristic. - -#### Syntax - -``` -bleCharacteristic.properties() - -``` - -#### Parameters - -None - -#### Returns -- **Properties of the characteristic masked** (BLEBroadcast, BLERead, BLEWriteWithoutResponse, BLEWrite, BLENotify, BLEIndicate) - -#### Example - -```arduino - -// Bluetooth® Low Energy LED Switch Characteristic - custom 128-bit UUID, read and writable by central -BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite); - - -byte properties = switchCharacteristic.properties(); - -if (properties & BLERead) { - // characteristic is readable ... -} - -if (properties & (BLEWrite | BLEWriteWithoutResponse)) { - // characteristic is writable ... -} - - -``` - -### `bleCharacteristic.valueSize()` - -Query the maximum value size of the specified BLECharacteristic. - -#### Syntax - -``` -bleCharacteristic.valueSize() - -``` - -#### Parameters - -None - -#### Returns -- The **maximum value** size of the characteristic (in bytes) - -#### Example - -```arduino - -// Bluetooth® Low Energy LED Switch Characteristic - custom 128-bit UUID, read and writable by central -BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite); - - - -Serial.print("value size = "); -Serial.println(switchCharacteristic.valueSize()); - - -``` - -### `bleCharacteristic.value()` - -Query the current value of the specified BLECharacteristic. - -#### Syntax - -``` -bleCharacteristic.value() - -``` - -#### Parameters - -None - -#### Returns -- The **current value** of the characteristic, value type depends on the constructor used - -#### Example - -```arduino - -// Bluetooth® Low Energy LED Switch Characteristic - custom 128-bit UUID, read and writable by central -BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite); - - - - if (switchCharacteristic.value()) { // any value other than 0 - Serial.println("LED on"); - digitalWrite(ledPin, HIGH); // will turn the LED on - } else { // a 0 value - Serial.println(F("LED off")); - digitalWrite(ledPin, LOW); // will turn the LED off - } - - - -``` - -### `bleCharacteristic.valueLength()` - -Query the current value size of the specified BLECharacteristic. - -#### Syntax - -``` -bleCharacteristic.valueLength() - -``` - -#### Parameters - -None - -#### Returns -- The **current value** size of the characteristic (in bytes) - -#### Example - -```arduino - -// Bluetooth® Low Energy LED Switch Characteristic - custom 128-bit UUID, read and writable by central -BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite); - - - -Serial.print("value length = "); -Serial.println(switchCharacteristic.valueLength()); - - -``` - -### `bleCharacteristic.readValue()` - -Read the current value of the characteristic. If the characteristic is on a remote device, a read request will be sent. - -#### Syntax - -``` -bleCharacteristic.readValue(buffer, length) -bleCharacteristic.readValue(value) - -``` - -#### Parameters - -- **buffer:** byte array to read value into length: size of buffer argument in bytes -- **value**: variable to read value into (by reference) - -#### Returns -- **Number of bytes** read - -#### Example - -```arduino - - while (peripheral.connected()) { - // while the peripheral is connected - - // check if the value of the simple key characteristic has been updated - if (simpleKeyCharacteristic.valueUpdated()) { - // yes, get the value, characteristic is 1 byte so use byte value - byte value = 0; - - simpleKeyCharacteristic.readValue(value); - - if (value & 0x01) { - // first bit corresponds to the right button - Serial.println("Right button pressed"); - } - - if (value & 0x02) { - // second bit corresponds to the left button - Serial.println("Left button pressed"); - } - } - } - - -``` - -### `bleCharacteristic.writeValue()` - -Write the value of the characteristic. If the characteristic is on a remote device, a write request or command will be sent. - -#### Syntax - -``` -bleCharacteristic.writeValue(buffer, length) -bleCharacteristic.writeValue(value) - -``` - -#### Parameters - -- **buffer**: byte array to write value with -- **length**: number of bytes of the buffer argument to write -- **value**: value to write - -#### Returns -- 1 on success, -- 0 on failure - -#### Example - -```arduino - - // read the button pin - int buttonState = digitalRead(buttonPin); - - if (oldButtonState != buttonState) { - // button changed - oldButtonState = buttonState; - - if (buttonState) { - Serial.println("button pressed"); - - // button is pressed, write 0x01 to turn the LED on - ledCharacteristic.writeValue((byte)0x01); - } else { - Serial.println("button released"); - - // button is released, write 0x00 to turn the LED off - ledCharacteristic.writeValue((byte)0x00); - } - } - - -``` - -### `bleCharacteristic.setEventHandler()` - -Set the event handler (callback) function that will be called when the specified event occurs. - -#### Syntax - -``` -bleCharacteristic.setEventHandler(eventType, callback) - -``` - -#### Parameters - -- **eventType**: event type (BLESubscribed, BLEUnsubscribed, BLERead, BLEWritten) -- **callback**: function to call when the event occurs - -#### Returns -Nothing - -#### Example - -```arduino - -// create switch characteristic and allow remote device to read and write -BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite); - - - - - // assign event handlers for characteristic - switchCharacteristic.setEventHandler(BLEWritten, switchCharacteristicWritten); - - - -void switchCharacteristicWritten(BLEDevice central, BLECharacteristic characteristic) { - // central wrote new value to characteristic, update LED - Serial.print("Characteristic event, written: "); - - if (switchCharacteristic.value()) { - Serial.println("LED on"); - digitalWrite(ledPin, HIGH); - } else { - Serial.println("LED off"); - digitalWrite(ledPin, LOW); - } -} - - -``` - -### `bleCharacteristic.broadcast()` - -Broadcast the characteristics value as service data when advertising. - -#### Syntax - -``` -bleCharacteristic.broadcast() - -``` - -#### Parameters - -None - -#### Returns -- 1 on success, -- 0 on failure - -#### Example - -```arduino - -// create button characteristic and allow remote device to get notifications -BLEByteCharacteristic buttonCharacteristic("19B10012-E8F2-537E-4F6C-D104768A1214", BLERead | BLENotify | BLEBroadcast); - - - -buttonCharacteristic.broadcast(); - - - -``` - -### `bleCharacteristic.written()` - -Query if the characteristic value has been written by another Bluetooth® Low Energy device. - -#### Syntax - -``` -bleCharacteristic.written() - -``` - -#### Parameters - -None - -#### Returns -- **true** if the characteristic value has been written by another Bluetooth® Low Energy device, -- **false** otherwise - -#### Example - -```arduino - -// Bluetooth® Low Energy LED Switch Characteristic - custom 128-bit UUID, read and writable by central -BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite); - - - - - // listen for Bluetooth® Low Energy peripherals to connect: - BLEDevice central = BLE.central(); - - // if a central is connected to peripheral: - if (central) { - Serial.print("Connected to central: "); - // print the central's MAC address: - Serial.println(central.address()); - - // while the central is still connected to peripheral: - while (central.connected()) { - // if the remote device wrote to the characteristic, - // use the value to control the LED: - if (switchCharacteristic.written()) { - if (switchCharacteristic.value()) { // any value other than 0 - Serial.println("LED on"); - digitalWrite(ledPin, HIGH); // will turn the LED on - } else { // a 0 value - Serial.println(F("LED off")); - digitalWrite(ledPin, LOW); // will turn the LED off - } - } - } - - // when the central disconnects, print it out: - Serial.print(F("Disconnected from central: ")); - Serial.println(central.address()); - } - - - - -``` - -### `bleCharacteristic.subscribed()` - -Query if the characteristic has been subscribed to by another Bluetooth® Low Energy device. - -#### Syntax - -``` -bleCharacteristic.subscribed() - -``` - -#### Parameters - -None - -#### Returns -- **true** if the characteristic value has been subscribed to by another Bluetooth® Low Energy device, -- **false** otherwise - -#### Example - -```arduino - -// Bluetooth® Low Energy Battery Level Characteristic -BLEUnsignedCharCharacteristic batteryLevelChar("2A19", // standard 16-bit characteristic UUID - BLERead | BLENotify); // remote clients will be able to get notifications if this characteristic changes - - - - - - if (batteryLevelChar.subscribed()) { - // set a new value , that well be pushed to subscribed Bluetooth® Low Energy devices - batteryLevelChar.writeValue(0xab); - } - - -``` - -### `bleCharacteristic.addDescriptor()` - -Add a BLEDescriptor to the characteristic. - -#### Syntax - -``` -bleCharacteristic.addDescriptor(bleDescriptor) - -``` - -#### Parameters - -- **bleDescriptor**: descriptor to add to the characteristic - -#### Returns -Nothing - -#### Example - -```arduino - -// Bluetooth® Low Energy Battery Level Characteristic -BLEUnsignedCharCharacteristic batteryLevelChar("2A19", // standard 16-bit characteristic UUID - BLERead | BLENotify); // remote clients will be able to get notifications if this characteristic changes - -BLEDescriptor batteryLevelDescriptor("2901", "millis"); - - - - - - batteryLevelChar.addDescriptor(batteryLevelDescriptor); - - -``` - -### `bleCharacteristic.descriptorCount()` - -Query the number of Bluetooth® Low Energy descriptors discovered for the characteristic. - -#### Syntax - -``` -bleCharacteristic.descriptorCount() - -``` - -#### Parameters - -None - -#### Returns -- The **number of Bluetooth® Low Energy descriptors** discovered for the characteristic - -#### Example - -```arduino - - // loop the descriptors of the characteristic and explore each - for (int i = 0; i < characteristic.descriptorCount(); i++) { - BLEDescriptor descriptor = characteristic.descriptor(i); - - // ... - } - - -``` - -### `bleCharacteristic.hasDescriptor()` - -Check if a characteristic has a particular descriptor. - -#### Syntax - -``` -bleCharacteristic.hasDescriptor(uuid) -bleCharacteristic.hasDescriptor(uuid, index) - -``` - -#### Parameters - -- **index**: index of descriptor -- **uuid**: uuid (as a **String**) - -#### Returns -- **true**, if the characteristic has a matching descriptor, -- otherwise **false**. - -#### Example - -```arduino - - if (characteristic.hasDescriptor("2901")) { - Serial.println("characteristic has description descriptor"); - } - - -``` - -### `bleCharacteristic.descriptor()` - -Get a BLEDescriptor that represents a characteristics Bluetooth® Low Energy descriptor. - -#### Syntax - -``` -bleCharacteristic.descriptor(index) -bleCharacteristic.descriptor(uuid) -bleCharacteristic.descriptor(uuid, index) - -``` - -#### Parameters - -- **index**: index of descriptor -- **uuid**: uuid (as a **String**) - -#### Returns -- BLEDescriptor that represents a characteristics Bluetooth® Low Energy descriptor - -#### Example - -```arduino - - if (characteristic.hasDescriptor("2901")) { - Serial.println("characteristic has description descriptor"); - } - - -``` - -### `bleCharacteristic.canRead()` - -Query if a Bluetooth® Low Energy characteristic is readable. - -#### Syntax - -``` -bleCharacteristic.canRead() - -``` - -#### Parameters - -None - -#### Returns -- **true**, if characteristic is readable, -- **false** otherwise - -#### Example - -```arduino - - if (characteristic.canRead("2901")) { - Serial.println("characteristic is readable"); - } - - -``` - -read - -Perform a read request for the characteristic. - -#### Syntax - -``` -bleCharacteristic.read() - -``` - -#### Parameters - -None - -#### Returns -- **true**, if successful, -- **false** on failure - -#### Example - -```arduino - - if (characteristic.read()) { - Serial.println("characteristic value read"); - - // ... - } else { - Serial.println("error reading characteristic value"); - } - - -``` - -### `bleCharacteristic.canWrite()` - -Query if a Bluetooth® Low Energy characteristic is writable. - -#### Syntax - -``` -bleCharacteristic.canWrite() - -``` - -#### Parameters - -None - -#### Returns -- **true**, if characteristic is writable, -- **false** otherwise - -#### Example - -```arduino - - if (characteristic.canWrite()) { - Serial.println("characteristic is writable"); - } - - -``` - -### `bleCharacteristic.canSubscribe()` - -Query if a Bluetooth® Low Energy characteristic is subscribable. - -#### Syntax - -``` -bleCharacteristic.canSubscribe() - -``` - -#### Parameters - -None - -#### Returns -- **true**, if characteristic is subscribable, -- **false** otherwise - -#### Example - -```arduino - - if (characteristic.canSubscribe()) { - Serial.println("characteristic is subscribable"); - } - - -``` - -### `bleCharacteristic.subscribe()` - -Subscribe to a Bluetooth® Low Energy characteristics notification or indications. - -#### Syntax - -``` -bleCharacteristic.subscribe() - -``` - -#### Parameters - -None - -#### Returns -- **true**, on success, -- **false** on failure - -#### Example - -```arduino - - // ... - - // retrieve the simple key characteristic - BLECharacteristic simpleKeyCharacteristic = peripheral.characteristic("ffe1"); - - // subscribe to the simple key characteristic - Serial.println("Subscribing to simple key characteristic ..."); - if (!simpleKeyCharacteristic) { - Serial.println("no simple key characteristic found!"); - peripheral.disconnect(); - return; - } else if (!simpleKeyCharacteristic.canSubscribe()) { - Serial.println("simple key characteristic is not subscribable!"); - peripheral.disconnect(); - return; - } else if (!simpleKeyCharacteristic.subscribe()) { - Serial.println("subscription failed!"); - peripheral.disconnect(); - return; - } - - // ... - - -``` - -### `bleCharacteristic.canUnsubscribe()` - -Query if a Bluetooth® Low Energy characteristic is unsubscribable. - -#### Syntax - -``` -bleCharacteristic.canUnsubscribe() - -``` - -#### Parameters - -None - -#### Returns -- **true**, if characteristic is unsubscribable, -- **false** otherwise - -#### Example - -```arduino - - if (characteristic.canUnsubscribe()) { - Serial.println("characteristic is unsubscribable"); - } - - -``` - -### `bleCharacteristic.unsubscribe()` - -Unsubscribe to a Bluetooth® Low Energy characteristics notifications or indications. - -#### Syntax - -``` -bleCharacteristic.unsubscribe() - -``` - -#### Parameters - -None - -#### Returns -- **true**, on success, -- **false** on failure - -#### Example - -```arduino - - // ... - - // retrieve the simple key characteristic - BLECharacteristic simpleKeyCharacteristic = peripheral.characteristic("ffe1"); - - // subscribe to the simple key characteristic - Serial.println("Subscribing to simple key characteristic ..."); - if (!simpleKeyCharacteristic) { - Serial.println("no simple key characteristic found!"); - peripheral.disconnect(); - return; - } else if (!simpleKeyCharacteristic.canSubscribe()) { - Serial.println("simple key characteristic is not subscribable!"); - peripheral.disconnect(); - return; - } else if (!simpleKeyCharacteristic.subscribe()) { - Serial.println("subscription failed!"); - peripheral.disconnect(); - return; - } - - // ... - - simpleKeyCharacteristic.unsubscribe(); - - -``` - -### `bleCharacteristic.valueUpdated()` - -Has the characteristics value been updated via a notification or indication. - -#### Syntax - -``` -bleCharacteristic.valueUpdated() - -``` - -#### Parameters - -None - -#### Returns -- **true**, if the characteristics value been updated via a notification or indication - -#### Example - -```arduino - - while (peripheral.connected()) { - // while the peripheral is connected - - // check if the value of the simple key characteristic has been updated - if (simpleKeyCharacteristic.valueUpdated()) { - // yes, get the value, characteristic is 1 byte so use byte value - byte value = 0; - - simpleKeyCharacteristic.readValue(value); - - if (value & 0x01) { - // first bit corresponds to the right button - Serial.println("Right button pressed"); - } - - if (value & 0x02) { - // second bit corresponds to the left button - Serial.println("Left button pressed"); - } - } - } - - -``` - -## BLEDescriptor Class - -Used to describe a characteristic the board offers - -### `BLEDescriptor()` - -Create a new Bluetooth® Low Energy descriptor. - -#### Syntax - -``` -BLEDescriptor(uuid, value, valueSize) -BLEDescriptor(uuid, stringValue) - -``` - -#### Parameters - -- **uuid**: 16-bit or 128-bit UUID in string format -- **value**: byte array value -- **valueSize**: size of byte array value -- **stringValue**: value as a string - -#### Returns -- New **BLEDescriptor** with the specified **UUID** and value - -#### Example - -```arduino - -BLEDescriptor millisLabelDescriptor("2901", "millis"); - - -``` - -### `bleDescriptor.uuid()` - -Query the UUID of the specified BLEDescriptor. - -#### Syntax - -``` -bleDescriptor.uuid() - -``` - -#### Parameters - -None - -#### Returns -- **UUID** of the Bluetooth® Low Energy descriptor (as a String). - -#### Example - -```arduino - -BLEDescriptor millisLabelDescriptor("2901", "millis"); - - -Serial.print("millis label descriptor UUID = "); -Serial.println(millisLabelDescriptor.uuid()); - - - -``` - -### `bleDescriptor.valueSize()` - -Query the value size of the specified BLEDescriptor. - -#### Syntax - -``` -bleDescriptor.valueSize() - -``` - -#### Parameters - -None - -#### Returns -- **Value size** (in bytes) of the Bluetooth® Low Energy descriptor. - -#### Example - -```arduino - -BLEDescriptor millisLabelDescriptor("2901", "millis"); - - -Serial.print("millis label descriptor value size = "); -Serial.println(millisLabelDescriptor.valueSize()); - - - -``` - -### `bleDescriptor.valueLength()` - -Query the length, in bytes, of the descriptor current value. - -#### Syntax - -``` -bleDescriptor.valueLength() - -``` - -#### Parameters - -None - -#### Returns -- **Length of descriptor** value in bytes. - -#### Example - -```arduino - - // read the descriptor value - descriptor.read(); - - // print out the value of the descriptor - Serial.print(", value 0x"); - printData(descriptor.value(), descriptor.valueLength()); - - // ... - - void printData(const unsigned char data[], int length) { - for (int i = 0; i < length; i++) { - unsigned char b = data[i]; - - if (b < 16) { - Serial.print("0"); - } - - Serial.print(b, HEX); - } - } - - -``` - -### `bleDescriptor.value()` - -Query the value of the specified BLEDescriptor. - -#### Syntax - -``` -bleDescriptor.value() - -``` - -#### Parameters - -None - -#### Returns -- Value byte array of the **BLE descriptor**. - -#### Example - -```arduino - -BLEDescriptor millisLabelDescriptor("2901", "millis"); - - - - int descriptorValueSize = millisLabelDescriptor.valueSize(); - byte descriptorValue[descriptorValueSize]; - - for (int i = 0; i < descriptorValueSize; i++) { - descriptorValue[i] = millisLabelDescriptor.value()[i]; - } - - - -``` - -### `bleDescriptor.readValue()` - -Read the current value of the descriptor. If the descriptor is on a remote device, a read request will be sent. - -#### Syntax - -``` -bleDescriptor.readValue(buffer, length) -bleDescriptor.readValue(value) - -``` - -#### Parameters - -- **buffer**: byte array to read value into -- **length**: size of buffer argument in bytes -- **value**: variable to read value into (by reference) - -#### Returns -- **Number of bytes** read - -#### Example - - -```arduino - - byte value = 0; - - // get the value, descriptor is 1 byte so use byte value - descriptor.readValue(value); - - -``` - -### `bleDescriptor.read()` - -Perform a read request for the descriptor. - -#### Syntax - -``` -bleDescriptor.read() - -``` - -#### Parameters - -None - -#### Returns -- **true**, if successful, -- **false** on failure - -#### Example - -```arduino - - if (descriptor.read()) { - Serial.println("descriptor value read"); - - // ... - } else { - Serial.println("error reading descriptor value"); - } - -``` diff --git a/docs/assets/ble-bulletin-board-model.png b/docs/assets/ble-bulletin-board-model.png deleted file mode 100644 index 409ae9e89385b0c27d8331f7d52fff2a8f71e097..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 41914 zcmc$`WmuJ6*Y6Fulu}Akx_f~%NO!1!(%nc)mz2`o9nzqHbayw>B_J)GO3ORf<#pfk zKF{8tw+C|I<UD7LS-<fgV;Q9IQtA=P6BIZ&xJNS5;;-P~5F+8=;IEM$fD#jnj9oZ5 z6cIBqF$EbhF){@^8xu22V>meJM``iSO0Q>e14f#-o4#UEkWrsLaYH5>dnSzoQ4Est zRzUFgrEwC!FNuvwuVSRs3NIBvVJLx(`r*C7H1aWqLU)^@xWxKGs0H#tG3Uu*@=cHW z((Go<^sMQD$8<fM!u5MdyMr3MH%F!#_Wn+r7S`i|&NBpj40tp(_||0;6NuEgIKsqr zlR#2ZfpmApuYIVuQNuh_ivo@P)U8((1-BU012`0kNiKd*8oYIc*w+<Z1Z=mE{?j;m zHvgw=xS7aVMHH)@Uo3y+Z!k9WB_`0UWj;|KCTQeH4{cCbOr~DW4uxcDB~pJk&3=by z+@vIv47YwpH$Hxz`W%iGJ4ttNlP1$Lh)n{UU_a;>0S+m)lef_hE#!jtO*))Qp6OaJ zBuK^}4|6)vZ2d>C$>mYS>kEUYjIkXrmIGa$kDOLM3}?mj{$dj^0Z*-NmGmZRub60W zPkn0R%|*-X5{c*Q8-ZT8E9E1a-H~*W&~)`B%iSWDCS15*R2nJ770q$VaFtdMgx8mg z<PXT;j_<=&E~cK4_*?2kcdk67MGe{AwX}!Nuz)iD;J(UuZ`0r6&wG|Muz#iUEDuk} zhf)TI-B@BhFF#LCd~om~TEd9Y%^Ak+YAdhVP+tdAYDO#Gk>3wx#UHWAzCmvq{P=y; zBB4eozFw2dUie(Jhy<Q#7T9kbb>Texcok}85PNL|;KV5JQCSPQA$aU)Vmw9ZZEk#1 z9QDOMg3ays<|QerR<QN*a}kQy8^0b#7}-&0F%e`h`C7IiU_~N2d_>{!fwCen={+Ly zW`BEckqpk)TN>kD{5_~Nf|)R+TtsjNEWxKU@J=7h-@;A!xP67Ze9!gvffhuy_0e0@ zhu%`cDE@77tniCIW=QW3F>ta(K1Jf@peKn=VGwE{xr&J>@L=ET5(|pNh!(#1N>hN( z@ZnRYn1aA5rNfhYB<&BE9}&NjaXh$z_wdC`L>Sk9Gy_-dJzM&W2uZ4a;JdgBPAVc^ z>-@58Ev_J1O*`H);UOH8pKf~$l5j85y-`UuB*G(c(MUBacuaDOD2g0}LW$%^v>d{^ zFzG1UwR;Z&GW8Sjak~jt1Jpy84OH}}3}jg+6Acqpp5twBnP9N{T)fXUm@Lavqb(A0 zLgvCu31jY5(TmX2EKMl8H>1D%j0ml#m0*SFt!FL17MnF^38V&nI<&!ir{mEw&5=tZ z!y@*<d-OK@LxXqZ%_v?(UL;Eqq}?sFk;obli}&c{@nlq%R7x06kT#KSd@<WO6nzTh z9Vq-UTsyT4=*z-qL>gs?XkNx(%lK2_y`rK|s`OEkF{jX`5uj-zkLlwxlCr~B7uJz4 zp~@iBrAChyQi!Fa!IqaLk`SGJ$tznY>?-Ukmiy{af%Syir^Na+4f!T<4_OZusTlTz zlZ4g2;+W4-7I8ZX?$q+J(+SQAy3h<-U2-qk-+9-y2#RgOZLfW@OI0!@mn+)^{A47O zv*HW_4U!Fl3_h%Ib}3RfM*Bq9V96H>Z<UTw=aN4W9nW<gtF3%d$v0;_$4V^4opUuF zv(<G<`lIO-*_hf`bDeITX#L50MgOY@?W}s|?5_xNLt{c4LL*K%HtI%JN9MV{nCaX$ z(#KseSTnqfqlhz!gO7{&^jz6y5_>Z3lhr5r3089&bA9t!^Q%ed=dh9d5$E)gG+mC{ zwd;WG()u8`+Dr4F9oquiF;9}8G(RDDqWmO*qnnc;**du|c|CcPqo?wX25J>VV_jpj zN{2NrX@5}3gt{VxH?z28FQ0i-FlXVjK(S##g_>#h%ZlO0+R;!=Zjl<Tn%B;v@^UO{ zEV^G54>AQ6Gm0~ETBKSuz4}|flFjLbh@`X?WCmxp=%?#vFB?*RiuydtkgbvZteeNM z+BWz|a8;A0G$>6bS|+UT#p{`gMJ2uZk;;*W78`G9I6iYW^kkKOQ&%sNochSy!QcBX z+co8a5mg{WEhG(h0aur4kLfk@4il+5z50DMtIF-t%Z|CuWD9LWj~;*XRl|zmyoHUb z;zH&nr<OgBXUW>73%Ct08%BPi{i3*{xq6By5a1HfgmyOL;6&Hp>oJMB^JBSo_$YK0 zk=C8IY+NRPDNTKte)!RFHtIvXL%a!Qe7jNG<ys=UD5w!MRM+Kg=7jQm+^WXT<=~6y zuuZ2<tImZPf!UkdD@JrV^eCy2p4j}D%_k$MI)MpaRHIbC)I^^d9GD;E3-SpD35E$i zZgy(^?7?!be}i!2bh&UceYkl!eI*a!ffOPCK*@nfLR1h1QQ45O?mI#{+Thz7-jlM7 z=~8J;;39}#i#hr6BXd5~#<{e|hca;#(d@d`D!X{PI765XB*eu!8>Az8$9kng!f@qq zohAFEx+Es0UP!o0BuL05s4=NmtVxDygp%b6;F1#JxKlaV6`qYP$OWwKuAr>$L)o?B zD|YAXs@4k!MoJ=e+th6tNC-)ZmoRRF9=8{+KQB4et#e+7Ovf|?Tt#noGj4_*X`dTk zM?n&N%Y8@16FRkn3}s4WaAZ~y<VC8!JC^Gn`>YklM#g5-vlosQ4w?B@o>z{GQtJno zGHSC6&^EDjaAdQJ)%TlC?khje5+03uPG_%f(vTSb`}t4lP^uK_59+8D=H-i~QpOqm zii4ONr)$Y;)&s<SCw*6*oF<&kj;75{zx}V<IQK2kiv6ZawC3wxI%~JpFaK=biLfHG zlAb*rkQ@jzCS0-(UYt<;s94&p_om`tqg%92RB^e9c~}$8vda?3a&N(;qS$;sfkJ2W zr@_EV@QOV3x9FWEbr02xg~4CGdri5&a<81fJ0UrLTiB{UQA;vV*O~oV@?E=leegKz zxTZmMw^>DB(^e1NEW#+FlC7Y;N%o7m)MWm4&bH5!h~$l?ZTFhJw7H)7>6RrcuW|UW zdtHcvB-liaUcF}u7R4e~UHadai#kSjvbO76Oucly#P_6+qDG|rq;h-OBOE86O-yqa zaL01Bhedant=jh3+<gBj=KlEemI8Zr-8qDZocCy@=bZE){UQIXYp}<sE!vxmU)5hV zf;BRyzD)&H=Wv<1KX+f+@*Ynk9wufMO1XV^8u}|KxuV}xZX{|LCpCpP!`bs#wA=3} zBnU5nPt`%NzH)6Wt)#SMalj|xi_TG<UEzGw)wOcMXVVg1?Pnfo9!-1xH(^sG4e9Z^ zyPjrSRR>m0TW>3F;#Z5qo9}yUUTR;lEdHwZSP#EVBfJ;#;Bp_@?0&2BO<>Do@n#gU z5M4)T(2eKj&5hyiY8EYuJVW{?q2im#^J$a9rqkVz(|RKnfu<4uwPGx{aTj0YJMNDZ zjxb7AN^VOPOO1qHgf6(1opv1#geHuy`nAyiu0D$!{hZ<HeAQ%X(ARlrF}jl^B)eG9 z%zHWY%WBi;$J)5F*+E`@@Z#rYp<g~XnOBCVJyBb`^5^n#8DT=s?~t#LU1+RKHkQtO zPp;Vb)I9-HBEOYZw}*p6eGK~x50{*Z4{&qROi9f_?ZtCGLmMlozLAZAG1SHCEqEFZ zj^Bk3{AgwDpikyvWod2C=ORGy&l7y$XIL={1=&B3I9Lc!sJ&1i6SJ{1CgX&1Kv^jS zQOL;1`0b2L_+E)i{`)%kmjJ~Z2Zy(OEG*8>&QND|sEwT|%Tr!nUKUn17B)6!@C38H ztF?o^3$wL7<)2FaQ;)c@y`i1iTL&{6Ycg29`UW<R4gwSuu!jEo=TAQ!%uN2aWNrWN zu)qLWV83B`3T0*aZ{6Tkepo4=n2pt2J7ar$P`@B2|36Ru|H}Th^XGYmH#QD7zzTL| zhBDR;#&+Ok2Yp!Y1lj(5`~UvL|Ex>i&deB$`k%L-{`>abvVWiFXMqj;jv@Y7`JYl? zW<eBwmj6zfAWG>f+X5V%Fr19Ih>{EZZW>}E_T)v2ZdrE0jBsd^ej8RpmJ%afaPXxn zrUZu`o<jCU07aPv(+n#vMb?8-{jmFG1_zjrP@E>{DBcU4wT#FtI_{S@I6EI$-lmV3 z?hg*9a*gnw4LUErHu3TIW#`4jfdBi|8zme<bkmoD6zKi;3j(O~6A}d(!hgS9F(bVP zQ4{z>?mQ(e{0Z&uTWb=+2y84`$4q};qacGX<hxT1MI;_Pa&P0?zKXw%1$skrw(nFM zD69jaB0FiP9{F$U;0Ms5dw2i+f9enu6=YIQIOFM;#q!s~62cI1VTc`VX)6Ni+P=D= zoTxBDIaT6`990_YseSVZi{u6FA3ONWkwr4lWVdAZRN2<Vx#M9);wW(yt{e*8UPP2F z*KVYk@=ms7OzXhv17GGr!hHHOSrVwL?;K9tUv4gaF(X9>qjKTt#tjJ($BQU*#|jSa zpTSZQ|F^>m%Mgq(9=wR%Y{K@@8)<Re8dhqukOA(^8Eu~O+n>|AF`A!MitWP1Nd9zM z{38kSyQ{sL>aU`xevc?aPzT+N6hFDgdo$r|5sld%oe!|IK;SRN<%RqdQWGBkXEqZv z;NrV8yngdOJXzU(j|#=FuhNztCKWYZAtQq)K<qN<jxzTU7d{?2>_8XdU^lss_n-08 zww~BUN#G)L2Y)mYlkUff@P-&2&1~S<Ph19iuVsjUY4!bgS{3pk8$&60`$Wq>49Prn z^QD75=dmIsq*65zkfaCqLcKaK&sQUal5fS<a6h~Y`ZKS>9$4R9gSs$Bd)1`Fo1D=V z>G6bs#m<v(v9nbjAXJ8=)MTjb1;T&q<tY9A>YzpbWmYC5;fIGK%5^K4U-KV^^l)t^ zYV+6Me`QE!FG(BmuWd0xp{I)%R7%LbE2=2q8~ZTteP61$#rssZ50kX=U#1P#q&Y9n zzU14Ya^J7pWOE&H^ZefGqyEJ{s-{7w$&GXC3oi+Y$Ejk&_xGq9A@A)|Y?|x#N;}Y| ziZ!{PoqiSDtD4qH8POG_h1RWMT}`+Aj+4i@!1>2=1qukKb9F8`v?KR(iXyuhSsnH9 zBCK?tzMgGrZwOo?rHHxOtr*!|a9(<$<9X0@RwS1I{k8r1%Ut;YG=)E7pe+!SGWoPy zXn8P+J>_(o2t8E)Vk5-{){Fc!r{ukg5y9oTd7Boi9wPhDw0FmS)dSFm!A+rr$5KSL zzEzg9Y<OReDgW7RV2QmdjxbVPDXaCPK{c|y*uZJfB=aD*UCgs{v?#7p!4Ma;zsgIo zE=MEgoAD>Kev>U3hBErr3UsSFfW(b1a0oOckSg@!<A-+7c3)(tMc2()A4HNjDVF6j zhbPMcq+I>&#WjoO4g2+<Z+@S()DT+NlDjf%yJ_t%wX`%H_cK->G+)g{Ns$m-8=8rq zJMPYmUY>3ll6qa+vZZUGP3d}h5I%FV#E9D$(!TuC^1Ghc<8*YNdiU&`{RnIKX;H;+ zx$~kcZK_x;8a`_)*W4S*ozd)o7fEc?1T@->eIa~*j;#VD1b&v;tnS3%UbRQ2qPV>% zj9TJ3s4~AX%j>*uua=hC5Ozx%_RFiS<~16e_I58eGipY&rRKqIA^x58Yu-j^-t%hD zDvWcg)HL0-TSdop{kzvzZo*6d&F>8d%@y<34MY3j2aFNj+e_7F+XdOXzzj&ge_xDv zJrKH<3>_<eH=`dgi^|d%$tBRavzg&#Ef#=Q^|_?Je@fd~JB8geoLs3VjL=k$xhnQ% z&&CVY0K>vSu;fJw*YaX7qUh6w8;Xy#^65kn$`7Bm%5^Nuy4p4Lbv-YPdE}Ej{2x^~ zPO0~l)NMSuS_xqhRlRvE&mZ+vXJ78+Kj+U!J0zDH$J07`Fv$Z_xV<aKL-bBx)}SQF zokBht@_5M8rQ2m;M7(TjPr%eJe#hDQR@Os82$^FWV0tXR2-YHT33K!LiqlaSUP?&M zL@m1D`FAo_^<Uq?ser!9u<)s_?ExV~j(9rIv<pX-L)^0ZH1KwiedOUvl%e2IV4^tx z%M8H<3_GN+qTizBpac-Jywg6~RWVZ6wJ3}mu-6Ef(hJRQR!MJ>C=!fGRW!_U$r3S> zlU80l`m*$A)2>s0ACdD4ua7)ESs&82%7daB-H-dMdOG1z&qNVU;&pxGkno<>{bD^~ zZ_eV&qiI+6ld|_}`?%T;qm|3A<S7cO7u_tb)?(z}m&!Knhg4EP*mI>4l~vSp6~Fe7 zxDP^`PRG6)H*O?bJSh9tD;6%){QJ^EQ{NA#eDUD-)q%~lwsYEE^VR+@FywiGvv1>c zPTfg%8HWxv-|PnbI`Z}hZY)^-Y%3iEC{drEkk~*<_ME&nLivLM{HVa6td3I-<ft(t zY0tRTo>b`f$LiFxzRrJH6#}jAEqy>?lytqSy|#62$|uDwpnY6xxkc$+*6n#ZDzz+F znkq@`swax2qEZyDn83VPAVmD{ohsafsetG7D4yrBNaF4a&AaZCb%rsT7s=RD;|Qn~ zX|6HZ^Smhov;y%<vrh9?F)CldAt{tJVreG+<tc7V-_y->cWa&nrOUKu&eh~%{`iI> z<8}KB4FOLxwG3%=N74m8e6(a(bg<n@{rB#jxCgIJW>Fej#xMAD;<Y{vCwoX)(NhuM zlHEL_g_^<8Zm?pRkw){{jbvH0c}(8wx~|9hQ%AGxAEuQ2$Rip!FLk2KD9D<38%%r( zW@N`t??vv&jl<p?=krRLgke8C9sEve_L8k(5{@?tdQ(b`TPtJ#fsX=21XL=f=a*CR zNpes01J*;JCiS7FBk9EAIFFwvQoVkIS$571t(xZ=-(!nO;wYPXs##AzU}(;Nk<$}u zL(|r|Rh~O?j21XzX+2e>K2`6ybJ1uN;w(7ANB(ExULl0)lL~phV}+KYvBhw>HXrU9 z-bZ_Q&+h1P?{D!iA%QM6QG_~_9tZV)Remff!L2T4k`&n%`XlLchn2EImpUlzzZmmV z5`e>^EdRg_8`o&UZr{p_gg+nvzHg_3n=(z+`^R3z*P8#>6)+Kpgm6V^3PsM&zqiys z2o#1SEzH%PNqV>J1>h>n;K-7@T*U#XX%;EK^DbL~3K7cbMeCveb_!O<S3piilth<* zM*N4ezG8!WH4ka4{tjOWQv!Mld;25cZrN){Wu(h%Uk7c7_(x11(Uze_I;@*FT=31e zjQ<RL9dtq+dW;iU;wyX~Ta*Gdjsh|^i72#r)lZhEm4hW+EH=6{x;pVT_p<o%HN)8K zc%g57q(DHu#tT4ip9?GP1}*Bl=SD6BdkWTyJ0Y(K&wm{JuuYwnEq;6pj?&OaJ)BGY zLrS-vI#**@(yF8ym2WV0qycShGNgI6sQeJr);_dvX5p~*V}$xlTw>f13qY-**zTN< zBfX0@#^n0k%|9@cM<Nu6dgWOZ4Uj_$gmg?_oqY@m?njYOPngXr`QA8O8eu)bau!ok zf`jnF>IL~kKPip&g?rO-vQ7H9!|$8qU$9XcI(qwSi+<!oog_V8{8$lT&9SjhTjIa4 zgL<Xwb;DU#Wj^_dkDOsz24Ttbs+hU*tEj%%wR@AS+nWua>9mQ2N4GCd-L~G)tWn%Q zbL!lIT>Vf9t<ICK$$B#&4Q4I$aP|2dp*^w>PoavWRxSoYU=KL#sgZg!JTK|L@i@wq z@FA1IdH%lGJY?%5W~%-EzO8;uw4B#Dw>ppal;N3W*?e+;v->(!7fj;?)@Qw2C<!%$ zp*He(P=nqN?&pKiBfxWONph}V#1UdwDMFaA$|VI1#H72IC#E_@%F0*hOf+AsJAeAt z2?KO!v~eiyBn26{LU%iz=vXcm!UW-1v^SF|c|3W)>&b?n66S+Z=)i`Ngw+fCAIhFH z2GyK#UT6LK%`hsbR>}OGjSG+LgTkDHP@(*g{JVPQ;@4ssJg%u8aMO?S3!G(pIAVPy zD&wIbAwcabLlqV`&U|V0B6E#FDE0QB=VDCp!nv3TR~A@C!43!arRc|Y6sqoBY&oPz z2|R2h>25(;;cm6J#^Kxlfxr~J`~3}dpbmRv73*_YcigA@)iWWd^c|vo%4$5IGmMe= z6(2D4Iz$7%hP*}+?-CXiBkdLAtTP|5A+mHO_&BUk(pA9iwiTEi%fJ|JP{kSNn9%=1 z3yf%$LcQBXi~l$>NAZg>xq{@Nv0S~HXsb=HM9ws!xD*YyaX<F6^Y0(5611Jl!0oy4 z0G))0DIw_^&kn|seh@jr4R8&XkqEfW3_k-d*TL<LPzs-;xrSGjOSIeS%2Nh1`U6pI zfhtbc&)llJ)p?69Q<pcg!cz*!)1NS0j{9h>mORd?tg2`8{AC%>H0k{@4kui<^g^bH z#|G9ef9+WWmIsh}&g{3`dIC1t+Xe8}yVmsagi<n;j!w&*Y<tKcgxTb5!8t?VxR;X4 za)$NU#ahhkrpes{r5#G{Iie%{`#8lcIj<R6h(Swf#LnMrt3gfbJ>kSw0mM$FFzRyK z;q=fNtj^18o7@_b5uTE6n=Z#tv#Ofht=}oBn5{6KmNr{=ChWpSSnKS9!^Nx7Gws*E z`n6{T5U+0lU~a_CGP;-a@8+$%lp=sb)yw{ba|Mdo(VJIi2R2_Ck7Zpjc|iB}8c&8% z+lK}82>6$MAGeQuK;!F`pVzc$G6wkBWL4IM>(q%Ug}*bgjQ^QauhlzpDqhpt%%=Im zge{cx@Q{?_P2_DQb%GXK=+X1^f}?vy5tgIX<l&m(-91muCi>-ifT`ZxT>h*;Bynj? z_xPnw$ZMCA<}_z!tM@sWCwO5>=|04m%@ph;-t15BBB~f5D%y_977O)`>v+OZc4|!I z7(-CUo*ncovKT_aceTU-M*NZ90Vm*zt2@}DR;NEkf1QrY2UvZpwH1L|**X~!s>u`! znB(0{ee7!t{Eb~;TRH!h)$nKU71lbzrXU(-FAN9(Fr#bD(tMufc(AzeQt0ON?H-JH ztEMytbi8gH8-8Eze5j?mO(J?I&%2Ht5<LFg(_+2RSyO6&oiO{|{``(?ag&2(Y1@Ne zS4+2oK?ZY`X4PY|jMQG!mm>6Y$r`3=@@KT*EX#e-u^;As+7{)OGRXjWb&yTsi6@6t zn|R1~Pi{LjL%zpp`~^2>w+Qfs(z%R!F`gZ^-rLKL5Jb@d%fSNBQxS93#H;E-wgCXS z#3s&59?opZ>?8c+fNd8JQ<jkeg$^#SdxU;tb~Dfj(4t}FsNr!hy*qh(>3t84b)^-P z#SAc4H=&KC)qFK4$*(P<_#NP85v+Ja&)sZw!gZP#NzN}e>;k)YZ1Y1Zp3El;-E7G( zulu?6**4XJo%yr<%i{iPKw7fjNRbvl+RIhZLCilEpw#<K9RCcc%3z@zlO~IxbtFAv zTha$q)4?O{n<S*SHP?JPCf5NWq?u*qvRn4Ud+D!j9H$)JgVX}1zYlPfkprQ@y4h^G z@i8AFyUAeb8~kBr0DPGZ4jY3>Qw`1sMjBuoFUs8sz4jNqZasF!a^-%Qe9147-p@E5 z%zvJyUhTmlC{)r_ZBjAB#jX<%C_1G6$-OP({&eR3Y8uUjv8rv#QiY$!>b%3^WS1im zq_=5(LYtTfmJYNO5d02*443~Pt%xh51V(L$;6%2l_mQn13VcLLnUdh}(8%P~BB4Fc z+N->-m7ie6_?PJ`GA;sUC9RL^Q%&Kr+J#a2RI}Fc*L?X5GPbgZ`!!3RC->Vv;aBO^ z2T0&)bExsszD!NLR?5%~*)QWaAaC0K^m*F}K_ylywMPg2_1WxLL0+|g!eg!J674W$ zc>H)p^l;elc6@^NpRxmb7_>D1C0m8;lgu2*&`<_CAsEV?Gl0MIa6dOe2PNjUOO#$+ zD%i1;zh(?04u8hbrn|In45tyAROU5I7FW+PgytI!uAU#QZl09?oYI_s+C%iXNSLvt z)*#Wh19jLqLEGfneyt%!0+fG5;7se;<&W$SrKf=<jmQ0wPEEs$&S>l3R5dj}xMV>a zvP-<c0V$#+F>>X&C-E^Ixd62RO>W7r_4AkJ<i;xp(bfhQ41_`1!8Hto=LLF=7#8>P z_<UOlZ5lCs;iePA2E-qxqWT<C9wCyGq2`Pi6bYa!6pg8Ua$azpW<@)`J{hS2{ywi! z?7n5uILy;6y<Tux4QqQJvj?TS1>@yos)^bDqWoD!goy&KOoh#MBb0p@X%SlgBa5}p z|FU{o$K8(y-<`lwUf^f!i$qp(CeBVfF-vfsgt(2`Mj<O{YIbO3GTpAB4N$VMU`4zX zcgH*r^Ja={DJw{!#6uViHpaS_!JDng$^daWr+@&rH~a8y3vgY^k42F5WDFLXl<;s6 zn0nfGHR9LX$RVW^<XpXosDk+@@Z!`9ais4KMKIut)&t%|G77-^(<|WGZww+Ysk|hv zaRHm)Nes=~5SC^awhw2E?l#9fZo;#9^*^HdAExQqJ=`MaSQu>@`rru&TEG2eJtF^( zQh!{6a8(uO;JN8B9*g9lv`Nt(*d(uX0%f%!46&^U$T1!pRV)k~<5ls@-S`x1YV+Yx zp>AuBo1fE?XXvPJxRu3+kTYbES`$Y!ma|03Ql(FNisP6yjJV8KX_b*&lxBUsuL^qv z(Dmw_Rn_$GYdXyuf2cJP5bKAuH30<%H#C>`XWn;loKh-Cu(D0^Ytv7K#hJu;v^nYV zhx96G^b&qwHX0M&%a@Hs-Y-`(`b?!$^dU(L+CJK0@;F>kNRcr*!&G-<hhLKShZ@8@ zPMEWbQ;w<3x2z9HQARY8vs$sdp(S_8dg3Wq^L)^E3wMwi8>SUvn4|pBR{kMt$LF9Z z996gG4uSh&M0zv%Cb$2sPM8=*r>pJL#eacbm>ggRYGxkmU+!1v0Yy8thmLpr0|g|| z577ep(7%)py5<p-_ovYz>Q=nK<jV;Y`*DTyQ^@(d6faSZCiFCz66Lc3ya*<e`A@;> zq95ONDG!Ol9nrz7r`L-$6-wq;=e^5S8M1nDQ9!@`9JI?GRakL?g|N<eXpV!hPMH_` zImvr2`8X~ed@K9X70dac99K^HjOwqaAwdNwS-dt_<6i|7CW1x*--9{+)4t5#vS1kP z2EN6qx-$X_FenWs<%O8PW!SJ+F_#(4LC3oxmDc)(B$w2%#wKA*s3BJ}coC05XAiHW zejFk2E75WP+bo~swh`D;6|j5A6P%%M@m6~xY8102<MzV4LkSGW^W|CSZs=d<&HNb6 zPI>75Yu1$enEmbdR>_v1l<e?ToJq4kf{|ilK*PLSs`_(S2v`UgD)R}tp0kpn`1$~d z0t5gv{pzKRn1R7mM*upy;!xVN>E@eX^Y605hHlsTV)npQ&qCKc#5F$%>d&C*SOhv! z*mbKI^ciTu+@gFMLz|f!jMpwf7$=v7T#tr4(#ubRN!x8Jw|cjHz`vEr<Xt~~zFGu{ zKy=g%P)VJ}WN7cB8iRv)Z-{&8;dH5B8qg@)-0Bvb=4ZF^GtwW9w|IHEug9rc!Vr-% zf}btb3#bVHuxL2(GmQ*Ek6j?PzPxNX>L#@M@QACF*lDIsGMtED7@dTF2Hf!^gsghr zd*F^({?_Pv(tZF_{{T@X4Gy3SUF*3YG}Q<IjdLnjE<ph=-EEt`;d1-4SS?WJ=FoW8 zBHuo;*!h4i_-4uLwkhi1Y{^S#ci}(;kvMj6`hOx@tnzbOcIAzGFiZ4n-H&^R29}z= zHx<h*H5oZ@HhOQ{fv9E?SXLk=Zr${As_!+pdqaNiOpla4NOxHYasr6uZ-LH#=*`@6 zeavMxM&-VdWV##1y(sO(ZOBQ)=TMMlKg^qn`ffOtmrK7LLdb2MO1|s%YuC)MC;ZV7 zKadfDEK)NI<TA{a6}}!k-FIbs0CJqbQSbNGMR2F6!m_w(s(f14YoVm&_a)i(xf_Z> zJpc1lp3(jK9q7E*?aiYyUW=)s$OoP>F^v?mWkpbM#gh*vTa*y|T6ElN|COKNiE`!v z7T`QMRNpK#INMM~i*-7lOId}@CG!>iQg$A=jMbmSQNLhI{fzNl#G{Wo!55KP^m{O4 zNofIwF#q9KlW((6EQ&De(J>KJwH@P%ft-qqgYaLeQ1m;HwW<p+)J&3$cfWr?uLcI- zL4vOrDU-DV)Bzuj3g10V&R@FE513nqycEc;h~%Y!d;%KtP~ag5wu0A(9iV(vlJGwH z_uNPZ2uw+we|IwUL9I=ryJ@=N3J9Xbh4KZ&p6AP%MEVjJ<hyUJbB!9QR0{9oX?@iJ z*M@>k?Xa5c_QMiz?`5LdK3}*z9$@*P>q$ukZn+6E$%_|h!ryZ30UOo;rA>}}WTF_T zt$;|!LoY?~kE?%Vg$(0iM@e%Ftnwqr$W8wOJBPF=b%Nj<JR*_av%Sjkcec~>$W@#p ziF3(rpMOp|w_rt1s+t%Nl=%vqoMIs)&60g>x!QlGY1c<h=-Qq&oz-=nMmB1%_8SV^ zW3uZl-0mlRyw0DC%7aP$1y(nHKsT2|KAs@s!?;daRhx4w0WZcOyyP^A-BjaXu_-2j zw<iRGP!0qwvo6Z?GoUIS9*=)kWzqEbIr%})IMj$ss`=G{e%*Tf0B#Pnq_DV8YtY<+ ztztB83=15s%m<%dz7Qp|KaxQ*GO5_Bo}arpTO#eIs{aB!BSbmEio}XKpa-)ean*;~ zh6W6-<-JTZ$J2I*T5#P=BOe6Y43BB)T<Tn3Imd!8rK3EsHYddm1YFG4;`X;K(RSXn zh;#E3s*H(zcyNC?h52E;EK|B&7;-_e*&yYmoYjk1|L_4Bz2DQfb{mprsvPim2&2y_ zAV2IJ<m68^PI(w0FL{=I^@xLYB1jrA^q2@&=Mzi65BquF4p&B?z|#nn3j97_&2;B| zjW2W{>b-vq<Ut7e_i460OazCr{vmnqr(v;_@d8ASeoLW<p&Epn=w|x8?Lb9;0)3hn zX&aKX4J_7VGNE{&BUxFm+f7rh^%a~EPgb6AS*qcG?nP(H7JTQk1j9N?#eg?M#_>EI z9N$P|Y;bj4^bJ=Yg}-yrX%D)+(I=woV1!}wTYni5;2OP~kkcml42-?|zl<#``Y{sa zxii#I<P2cuSI$rzjJAmyn<biTL(4TqDPkNGZc-3G&}SP~)%A$uA`*=``ZV~~MAC5} zo;fUOl&AY!N%fq0bstTNulhXFGq0!mCY<k&YgfZjJ<AN(3XOrkjJ`0Y*1_iJ8US~D zCFbT}$PP_7iWuxQsiPp$UKvC)EmxR$YJCD?HK;85gHKGq?Gu=$V*Y%U&|_{fF*RY_ z^`$&T1<xrCM~%0F5C<W2zFniemZM1K1uq^#s8~mPPti9^(eM3?UpSbe246|wi~GS@ zAX7l*YHUdBsj@}kLO|LX1Wpu=yzQ9TL24g3#v(`@lQ>(VAGI5t^a<h}M7^#1f4pK+ zByY82T1!c4vb&{j9piP_@dVdT=EHb3gCMG8F?0bA*FktgxH8<;L~*eTcADWXwc5yY zdm#Q_>d#P~mMTd0XtEXd6RW(1Jo!0N9IMr_5?D36b03#v8(&3+#{2?8wtfG17MkLq zzv1yiL)J3UJd~FvIFuSPgqs7{wxOj)(P%L}wTQf^hSE2=V&J5EawD%q<8vSD-k29* zlunXs(S_D%areDwMEnH@2UN<$M2Y?<&M$Bj?K|!z1{l5G5=W&-!wA%ociz2tj)Smu zZ3hL8=}jwxGSc?|_wO1?A9GNACTiJkUeZDicSOCR{Yp~Y#?7K+gzhDyKkM637=0bF zF=-s?*a-0zci&TSlGa`SI;N{!jFPNw+>A!NpidR%`qlM`d%b|&+yeJu2l*=tS%7_o zt`S$xW!vuGE{dwojeLr#u$V`0iYmusUGsfs`lJqXhUda)0y*i@vdM#jrLHTj7x>bq zX-0B2qWFcm;0F^0)uU2le^GpWhhT0o#;&9plO8f0AMV{P93Niw3hO^XR}7zI5M5P& z+*OeBH>~b61_Lr;i`+X9#VG>lh9+2%`;J_jO9@`(o07c)QReRfq`bh+wif*hR<csU z1Lv`@R(+BwTgzoE?Q&_!_H#{3utB`o6V!1*7*a17jX|e-q*{R?ede)w9HrDhDJ%@2 zPqr|5KKWSjb$=32pG_!Un{HA=wu@RF8z>ZLz`*(;I(@;ygAk4fY$hLr|Ad(SM7h&I zKZ+Ad_vQcg!+-|Fk=Yd_{-cZoW~+J$Ml~g;c6O)iDPZ7Gf`Y972BtB5G-$y<cc_c5 z?vy1Wzahv-^kLw`ETBbT)~GD?_xE?JUk|QRojM(l=D~SQ)E|g6K@5PZp3!ch6sc1R zMzsW_Bkv5xvc6t?jn)MKS&J+!-2I|bb~T2&@ZEh{xmOo6jO$~M6*OPFZKP+-J)zC? zAOaw=`cdtkZEv(vvuG@MZa2<u3mmTW0`~HXR$(z;1<??a#UCR|blsU6M{zK)a1_lN zhQAza3wS^DL)OZjiROa|$WngAntvj~u;2Lb084j^DB1$IU`<?j2Y16)CLI<r__zW( ztMU$0+2jGxZ!5GII92~|fE&4RwAwQd^t1l>pHB_DXHK`qQDwdQW9hlvPJhsJ0AXu3 z?D`=QPwA-5P49Cs&n8^;6bS1uPJel+oLKGa?JL|o`3pGj)tHo$GeGjwmlwRqfeD1w zfN*CImpjCi>^Fz2Y+7!(mfjei2)P~`T>*C(HP{AVMg^!pzpoTvqdTS0VdTI|VHn`- za*C@CyZ~nTMy(*RC5MzKgS4irk13a+<5tMruv<>fYB8E-*H1r{Efry8B=q|{JI!HC zrcHFV%0kusWQe<ivq&Bmq$<_1u32z$y4=dA?KnMHS^^PRoOu8fdjP*5Zh})?aUO^S zMF8uj^5sdd04T@&wrM<)oY(vC$Py-4Mo~)npL{?>uLiW-^WY)A9>|r@<>9tjY&>j$ zX^-pinlvZJKop-@bU&~{7dVY{+!~{v@XJqk>n~}(+{W17`O;D?hQ>>!)iHMoC~FR& zt<BmMxYW_z&)mO?AX1+I<-%qbM2l@SEzA6fZ96fIamM?e$6fqm2{u&`>Wq6}WfGC~ z4R|3-BS|A+AGaKWu<;WErfrNU0LPBU6Topc08%7-kq?kavb5dzs+Q;Oq4Vp3?2X13 z$sB#@t{VjIt6|*H3qxv;0?>%fH&g9j{y@k80c4;gv~`0JGEzgjfcxA`nV}d=D@g@@ zfz_|h$MU|lAak?}PuCI{ARp**j^sq?BYZndnjq4@3-U>7!1x3M`EXk#2crXm9@EZ& zXN-ZI-a^i0I+Tnv*2-cQttw6*KMCsK_f@wa;_O&#DAAtz4V2C0W|o#~J9kihvHRJ6 zn7CbFE!u5Cv7+YdfXU`<YjxeM!g>luU4MHV1pWe+y0z%Tj}k~)wp};?V*?RM=0cxo z8isL-o{@`w|Ma<}+;LiaI!jcqFgL!u1q8!IkWxV&19)_RsUnp4-C<ib@LUkdg}Lce z3V{SpBWy?Bdd}yIIF)9a;lV`@fraPEAn`hGTanXB<le$$!$9EWq5nrGA%iqxzw&G4 zoYpb~B91EtquN02nVYlF?R5p`&-<ZZ{`q4mi|B-WiHD10LlZg~s(`>S2RIF5`_VLk zoJ?99i0m*-kcSs)!lLho12(>Eh56}EI_X*p9|tx#?1TBN28)}1EvbI8+Da41Z^??f zNMehyK=j3X3aqU>(^Oi0yRA7`@a98Y4Bv-m-@Wfy!g4oQ_T8RkR&Nlz)_iSK)qJ_H zico&pUu4M}kI@^dBTB|j2)P6+-c$}+XGAHlc6tuA`xKJiaqQf79}luDU&A^jJzS>= z^vi43T>@??XI^w&NSb_W;!{Ka;`;4RGA)gXIra{@BdNUOZfE;xjf1>8R2Y#~bCoiT zBu9-fQ7Rz=sIIdh*@OhbXh>DTdmQJ6KEPa~RZZq-3qoNV1}d5{Nns_i@!*&@b5(UT z2h<%R4|<kjRkJV!f(^e}X+}MU(gmKW%_VlF4rv3wK%{ikIMk5eh=$v7Td4t1{w|1k zJk$r9tV!>pTc{oVGlll}EK$5fC-uTa2vfN<<rfE4Q+qY3E9&~?+0tmVCmeK0OP2bj zN(M)<7O-Q>kYrTX+#-v^LF*;LNz3m9c5c~*EaX~@Kocx-;e>2WH-P><isWzGk!c}2 z3a4(TGk$P}v-nHhzW1G>kZb2W4<#hlEuX!k9#Zs$fu#0xS3CrV1aty6DkS)pc(VwM zk0Hv|o(Q34IYec<%LR<rCj5F6b39(ssA9M<$M9{?Q@>EnK_y_ZJ<jZKw==e^Nf73Z zT7T~e6fKPDQvHs0H3?5Wf}hK%*Ne72#Dqb7;ug?~PJ+DU--+)k4%<-)AKScL>o~!B zd3}JsDomgQ+n2uV&r$dQa%byoAFIKPt@^)=jfLO`vd`@aQ0sx_?pvZ?<c*Zq>~Y0K zKx{}E!M9z&+HmnBI|41n7Mxd~E0-~nLsgCa+1Wp7R$H2Z(EQU4r>aSniWgk7RD*Mp zGZ!Jq?4L1Xdx)L24nuHaWSD`k?fxUa`$>G^z%$7C66shrVTx^CsF#r>*8tA)4=htB zo*2KZaN86R)>3ytHk{&FbsFJW4J}Bh=U36puFiupdd4kO)|Y-RYVA*2D8SJBhC7AT zovZ)CyuS`ZkLU@mpvk()V+2(l*IfM|qj-jPG6sm690vJUFo>_z1ULw456d9ra2N<k z$niFr&+InSoY6!-7M4ikA?(dnp$?ShJVtPMEty~tgaRLLNWL_<8+XM5A3vO_c?Qy+ zP>oAFvE-;miQIl<_8Fq#-wUk5@1c6qpYhZd+THHgnE{sEG<pX~W`G|X-(s|k@_y-i z%C7}p*12m>aHWcdbXZCc6?#f#*%Sw8;S^a8@f-sUxQJp*@jnFNuqnS~`;0#-JIAA& z7ij299pjM5-!0IqjxV;&LJULuA6{8($V`#=k-z5yPx}WAhc<()IY}b<TYuzbYvQ+c zGQFCrwfGd6Oi0qoPn9A|tAVlQD}3r!Z#ZK52}61_!CsL(avM>lP!vw++r8;51ZriZ zobI?SXFhUoU9dbA^Z4rNPjC=sXY9jDrg2o%$cwTASu+RXW?KUd@Tdwede>_bq%wbo zbCj<OB=GmjFGI@9SX7$mrP35NEA;TuqBLFuQB-Eg{aZ_j^3v+CX>k`Vs!?&=o1lHu z+&Go~XVjf91>e&;PFZt^6p3sRJ(5x4U&(jenc8aPa)nL?ufdli>vf;@1+V2);`wX< zSc*x{oJ&5{a;SCyAXx5D6c_zhuA6{>doGzya>4g+S!_5sHMZ0kssHAY79fL|8mD4t zJ@Vf&IvBi-m8r<yQ9d678nej4cYJ)Oj1Rn;Ygil$gQP!SA8C-@5QA2`H<lnfwB>zq z>B5}$s!jAB9!J=ps}>7}U6A8Fb&DPIPIF=npfIH=Qwh=Y{F6^A(wdy`Pa0i=<1c*K zAoH|JL|A*KN-?}1^-i}4K)0eZRYdP}fe_ZMY$8XzJ7sL3ThwC3zIVFC1<-Cvl6M<= zr_2bvD(A0({BN!!$aoaC0-#tFW;daIM;Yz|uf{*D!n)%*%#nTc>jbT)c;NlZza~A| zNXN9T)8v)4cE7)2XYs)>RkyCNn4a`X<GDHlP-d&V-9`Cjg>m7a{$!VpY7a4RBqlKc z?>1+>(tIuWt17X)zSN>j$x;5!NW{TNBz!*?{F`11V^LhdqEiNi+y9X1zeW!PBMCuL zRlK8JGXwdfsO#0Fz@5=yf>&`dOS1k=pM@c>28=vIay8z&kJbB8dlyjw`&3GP0%^TU zbimjs%!#r?Q-%=&Ca~nBmuY<JHP#EeAgQbpmI-0xe0_ezWj;|*ZtMY4iMTv2Pv4Ja zuo(x3kqFfHl>!iOq7=G^h-P`JDFo_WA^%t{Y4w7iQ>F|%L|FZP4h!A<M6(+A7nc*t zLm*VmgRIKk@Mrs_v>ETlNL<%20l{@yo*yogXVuwn&H<=R(am{!na=N8?g8%Y`(3rO zCMmOmSG(gzGq50Z6sb!u7;UE<K)s~7WS5;-gOCj2zWYW>Ok<Dw{qHj_`~rCOB;|^- zNb3TLEFNT=y@G`?#AwbxwbAFN8VI<ZN}Fs0d80DsB_F*S9mqm7hefb!B?;31-|4$w z6@);Rm($Nl)quAkt)+_Cu9tlI$<!1g>ASDZx4+#fmkvON!A!#v2+7kWeW_V=8>j~S zKM(Zq-9XB4y3dI(O=J-%6#O6)Qw7C^?dF=!>d+)_hh-#vys*Fykj&Bt!=Td5wqbvy z<wo7r`Vi?~Skdc+`5-N{guFWo4YLkFHLd)D-2n5{7hR!_CqVY4odfB$ge3wX3SE7D zJTRXl6SJFSnqJ1e=t4QW5IXtx$Jb1!Vctz&=pnED#*8oWV@nWt_b=U<t;i1}e#X^# z0<uSE0kW9L^B;)^hU^gOzB}rw25!b2AWyvZ<%|CnWiQCyR|x3s=nQ(i2g?%$(7%L{ zQeiTLV)i|OqmMBQdte(RUXrvI)omo}A81cQEek(?JG&FUZ;Fye!`z7g`}`%a1;3%W zh21BHV<kxh>I>XzR6#r+Yvs=E^HC|%S)l4$s-=Pi%X?RV#4LflSTU)pyHKk4b8miH zMco)j^KIMxjwz5!ZYWk;n!rd5@B8lc(klU=;aUO504-_GB*p4|>1u!`J-vN>KHUhO zj!WB=nqk=YgtFM3k_KxY>&Z`X+K!XT%ZX3J{y;49e<7B@KB!i1bHDk@+8yM#il+Cy zp0Bn7jA&L3RO0~Fz+n(Bc4+>{@y%hJeK>}-&cO<x^GREO9Y{hBI7j384mWR>pSBUA zNegyeGR?<o8g|NmLMgIl$k^J#_3Keh&N7q~rQ6p>5nc~*$(XqL2dC9di7m$SUf}n1 z6VgqQ*F(yTh#e;sr^=1xG~Z<UwQq<@Qj|O3n1Bw!(uIfPwe0#NgN_X%ONg>I>26V> zwf|&o?4<qx67LoZu6Vbc=)_a+^!?*7t~t8KpqK~NAmCFCV%juKP>`t5xB3HKW%oZa zZ$57iK1e_N$&}{Oc><8mSWU$J=QfUx5k^sH)Zj+1>bAfk1r?AgB86Z<p(LR54oa%Z z%6%+A80(@$_Y%)`RzG>W(H72=2r_tF5~Xb1!G+4k#U#w%NMPENSPpWY+kmFI{PliN zqysz_4#TL60}+eQ9b`5H4x3YH<<k(}lm<YDAM{pp;d)$ppNI3=j!NLo!t!I=8$mEu z5|0OMIY2q8WXlrG_J8WZbS#{fYBGqAo?!dhRI{ovl)3bS6Nw`O#OVefPEHw_WHaVc zD^v=8FK}@fpj_?5i1=Jwt&#ZVEy(Q{q9u84L)zvoR8NBbY_}9+u}3o6-#H}TfBfJa zSr6GHl>!L8yB9+)t$E`7hIp_@I0o7d`zr3jC;XR^zZ-weS#;m)WcCeIIUAS}k4MdV zx$OUl5VxDbF4TCU=jpLKfJ{rOZH(f&K`g1FdLf#n!?E@mEv>xEZXShhM^C`NZKN^p z!-4<*wnzwELKm0{04Ql%o=`5WlPM^nQgL_Q!`q=W)Nnz{0Es!vZL()Zg8Lvwg@#K` zV@zZ}_>`P3>%Lr$v+3sJjOz_~Z`(puEnB}mkj9+ZfEy+5%t293-!miaPyY2L)Gwls zC)D}HCPp$KQRC8=C*`d+CX%a(bRAftAf6voWwRuxMv){FW@z#=l3eV4RdgSd+S8<{ zp(3lI$Y%$Q_NB61#y&;`kcAl-mR5WLzp|6yVcHx->)|6v^BJlgg5})fpY<_W9uN7F zfc#aTYj7zmYQ}gKD+a!LtVX8a72;u)TJRHdxp#)WlTthCd7cZP-Q-ICynAhy3*gLS zamXI?>k}i^_YM?~<uJZ4hi6Ki+L8Q#*7wmAZ@nMp^XDY`W+{2W1$E2%-bgkKX>^}Q z1h1F^%c$ekDBSpV$~MQl)Ko@-Lbkd!-SE{EH>`6{Phe<y(aul@GIiE&vV3sZ7Vzb^ z*~|=+o;x<O>KmIrR4su51y$cx8zerrAIq#E$}v6;D7ae7R@huueAC3pq3y>g=wmRM z!n6In`Z7H{bS`<@#$qhaB6TwuVCA48bGPyY)Y8WC+hy-DBlwKK8<7>va|hEiIW<o; z2LAw__K6;q4N6b*GBP<2`B25M;7YAAsogaOk{}kx@|PTsihK)KqINg{(VBzc?cz#Q z?O2f1us!-#C*`zDP@fb(mLw1y$zbu>la>Ne5a-z70}Gp60UJIju><Raw*zL-jNy=A zJweJU(#R9f&Hz?wPkDKYa$X}GmH&{UFvN}$qX9g+8S|(SHHF2sbc0g+>yT{`jx@g- znFre=6=}Svp&(8Dzw84$%oJi}I0AXOiarSXJb>?0<EYPswQ(*y6}A@RR#erKF7ssc zNN;e?#Ngh-$3pGoAsO8}HGEt|2GT16=bT?yF2>V7@dq^Rta-T#QZC(<Pk)EW;0C^0 zF$p5A@ubj5sv9tRaQ&7zB==cS);n`F+dhA|pEiW6h_{B_p)xwA&j~9m*8jq!Fk~>8 zf($caF*g)n>?=8iI$RvV%n)Ye?d5dKdz_Qjd+5)HWxK|tlX=FBRk(1$v9be;Rj*+A z5a1;El0%z)+d1(*M(`g?v+<e8URkO^=+3%UruIv#NkEWW2EPBHhG)YEL{z26@r{P$ z#w>SK+ezV%bO_OeQoVJ7;*n)mwafk>%IaI{q?h?tZOqpNBhNBDJU>aUad2XtkvoZq z-BK!oByGzM;~kO#ULsO=0p+!drd3>Hdi^5#V{h<ro1C}AjP$?NedmY=dP;xk<s~)m z%e&u!a73RhWNGW}uCxQ^8GXcOH>cx!Ahm|>4HMPEG&gm#EW1HxAVy6-=7PNzN{@?N zef2o=?0Y}^R&RKM3ZJeh8_@<ar19c?w1G7cjJE>#VRo)l`}b2?z@`j7!ix8)xC5(3 zxM><K>$mc_Tn@jpcC+fjArie6Mv_lpwVnE8=<#Lpv91UG`Wh)qwuZ4r-<k4&V_kF| zqs=<t%sl>YGRi<jpP4r3mv|hhq~wc1IK}tNp>H2JsokazFN%mWs0YFS`Eb0}N6vKQ zn%X=qBw0c=es%IRXY0#$5zJ-k6azvBKM_s{Qf!Lw?vAjX*l+)>70jprmmCYc&l<PC zZ>%N?6uY@Yx8jF4YJYDE-OiE#VT|>tOK4eA%Q9!#K$(J#P)7TXbnb$L{X#e|SgLtG z<b0L=?Vz3s5mk)Dl#aXAvyDW<U7&_=H@o)F)4O}xr|-bB8vt)``<}?pl!Zowyuyou zYORW7tKD68W0-+WsPhu3n)fkXp(N^1L{uvFMD_kWkdiOLRGu>gqa`4+A!lLv^d(0z zMReE+FkN*R;m{<Ik!4e0G3L~ljpGy#-|-S`kvgGdeR&~LzQhRVm_c0_s8ke@1U-Ui z4}_T3hQ_!8`+<!6z`{_;rCgFCYi#<t1N;`QH24IU5?a?C&3y|A?6l}eXZ;43)B9bR z;Y1C+;(8QNZDB0jo$LTHCW9(*m-@i9)Cj*$QiSO9wY!4~mIq53>**!}rfop4;Vxx6 zCVXFgWU6VldrHY(fwvY&CHb&E*3gU@X{komL`XQ==eQzVbjj1ZLirlyj{CF(0h>}J znSl&5T<y^ff4mf4V4xH!p3Dr6s@78^F<)B!cVgmpq4*NQScrrxig%(Y;vYF6!BDa? zE{fxCb&hPx!fd~z9tGSVD~_>l66Yu<=bN=p=lO;p(`fg%IWmMU+QXD`##b8F#11|I z-wnm!C>|^v<EN>0;8`GTQjFiMEJX;A;N?j4H)s6~JHTT~lPf5}Z)J^2P_0DRUpryS zsB*+hk&?>%P89zjbWKK)O=#=l@{7c|-(xHPuP+}c9EF6fEF5i$7ZoUi7ZE7oS#cIt zVy!zD5X1&WLtaG~8^Oe-J;G=G5rKp)-g?XJp{qcJqJ#sXGh{JcQkCeAlL2>PFf~Ss zcW8y8Ibc7gR*c-A-&30oc9zq3ev;6`p5spN>*-k39ZM$6Z%@d8GnPrZ#FYxqa-<GF z$Cg^h3Y;QjIqM%Pwo^evC`0aj*O`1}Ou7K~eU%~`hieWa{@$yqoUOqbIV2^yLe8|2 zH#cW&)_h9)f{o4Ri_F(`J!Bbi(%yDPAyXN($6G(Y?mRT>RTlDjqkY6y^1ES-82E{n z2y7V--MWkp4A`EeLoJ;5r@bsPlHiIO;q_R^Ba@Ulwdr#)$e3?$$8U8wC!;S;WO>KX zTvEKz!&l#$TdaIkbG5~;C@ySlP!3O)`_7#^^(_(QVa7gr+`g92==2L#(~U<BzQTLh z9%X*Q=4s?jAOtXJGL&pwVLDO`^ITxrH}7wY;#+Ht>y95E+8G*<$6($VqRO!}RaRLq zxHabvuV6=fYs&vpop<d>UP1&~3u252&bLE~)fQGk3*H_^4s$jC03}x-Hr`%WK_mZe zMhPuoNk_!pjqoH6wg|-5wPw^F5pn!lQmjR>m}R`7yL}wN{C22Vc2SZe!MjH+&Gx9E zI<HPi?(yR7Qqyqkc5XI@bH0)+ETl8h84{^eDUyIehwvRsTpiS2BXM(d>RKw^MJbAD z``s``-EKfgYJ0hg1sxvm9&~>JC5TRMm78#yUU%++4I|1>SpY4xiqr2ElMT<UZoc(l zi%xJt`0--dD;Dr^fnI|sX0b*r1Y>U!vFLRSg!H{Pb5QY8w&Mj?qRmnh*hd-FNVl4Q ztylA-?G1>vc4;YLD5yZm=-G9UUKK~$uBlkPAi|a-l{&p$&}D6G#@@-zK6Ng{mV<pP zMkyyG^<|}gBnBPZZelh|4MuCUFH&27Adk_><=V<<3%;MX(wXBR&PRe#31**IQbHAK z7VdCu;gtkCtCEv?k!L{etmBX)Y)-X$VRoQY8228iTl91ZWRGkns3Ed&4M;Mva!BGk zk3>6)L)H*&zqez42A33+#6uT?9n6M~FnXNbhynh)3C)BVKq4)>DXaV>Rh&baYR#qV zZ!G$qYh>#ZVbY3BjkxXjM=3%_WFIV_h^I+!F5+a7B5&T*UrXX&@@`{hjnWR2LF=GL zNQM2jP$Uco%UD7}gXsD-!r#d|1%x_6{LD=b90}%T9Z~~dVqu+q^|!PCA9a5jRaN_i z52LUJDUl8VDG4P76i^X1k^<6_0+LFIBHbX;DM+b=G}0)kgfxOkmxM@nm()8K&+m!< zd&YUk8RyFx=L=)7VXb|yxbJ(;YhKqiLm#K2pOd0kz36R8)5%d?xl#GSb&qfVo_Hbr za5LW$ujO*Z27{V@wMrNd^N^ay@mtHi;CiV=-1Y3dKpzY9$;+C$YQvw^EgGT7t8G=s z8e(uK`RX7~B0j-IrOQ;9UH%`%4pZ;cN}=C5v+*pP@0fhVKoPMQDDd5`S7h04z+(FW zok9YwD^*Z$LYAyo(t)M*o0sf7N<@~K3{lqCtL=o}>f}A@I@l-<j?u0xZCX^lmK!F; z2$Vm5xzwO=^K*{}&2hgNuH7d5BDAn)zH%l_=W6<ACD0qmRZ@K;n4NAC<-mH}*(x+U z)a*<|PvuHQuMc#L8u{sWzL``Y4%%6aE_F=oa@)T#E>m!QcF?&{sZ7QCwfVd0=G#s> z4fk$07VWzDB$cn0+<5n#a8YE`bIWmSut0NiY}M!XbhGGizmxOxdx}{6h|*m$1OG=4 zZs)^;dK7_bZ_rd3`K(XFWNw=Kf<zm`<EbtN3l*`h$>(D-pHyZC+oBGmWGY|DcO_?T ztc@qu81czb)rgI}^IvV1xOvj}O*eo2Cg-lfw@R5|tB%Iq#Mts(kAktph{U8#mxY1f zinmtwx{E%PR>l&M)i7<}yYaUdfWgkZ;O`Coc6R;!JYED{)fgMQx^^~xIPPGT=JWKv zwg16ZC{CPE1l@r%YQH{DwZcjJk4H6aUKiQ%uMHgGgSn<B2PJaGliR_!w>d|pk2$MW zUNyTtSU6E$Sati&k!i3%(XrcG@OX4{e2Ft}<+}gd@!-|BWU+Pqh@PE>XR)`5aodr5 z%w_BAG|^Ko$LgyN++(&?BRvR)_D)4%s4^h;^+D#!zI4LoJ^KPxxvVue$wm62&X~#; zE)fl1a_<G?Wg4B%9LZ#=m3ZebB;Q&1h+E=;`hyI-3^fV`FC4)(Jm(8WhO_SoTIE_R z7xdF#OS<i6#Z*#_U*u#XX$ggyX#H*~2OoEBZRa~SOUfja|FT|;a0cHaNv6~ONervn zcbo$uiqgS>sxc|-v<3a5>{y;-xqR33)a2Ka$$Z{Hq!Eyc8n;|@txjfSN9~gah}IUN zyVvB=GxA0JM?c;Q@tT~Qm>c!4E_g|ovvU8=6>@f>X#L$F+kv3_SjA*nSvUS5y5c<0 zGdMt@`O%M({2=sMlt{yTe*-EIJ0O<i>7f8t*E|Ok`i5%aYtCtT?E?+GvgArlymaMv zBI+)qoE>_c8YC@>$thS<<u;SKj;mu$`ifZiOut^#HG|xV@=g(dz1zvrZqp1Z5)nJ8 zzB|1Whx=Jul~gAeIi*P+zd<+J849#Lfk1Ny%F?=s_GV{ks1*2jLhd*lOsJDfzlffd zq5n9(vz@QY|I|v&(Yueg#$O2KepYsw`;lJiqi<`zSj;Q14piy<&UM`nMd$N2pPRoD zn?p@71<Ix;dX;uX4$H#`HXAbjoEZqo$LqvY5WQ%bK3B_7C;}$vAmE%-KizjnpRE1* z+N%9CzHZ7DkwNXBHSazFRMgrsx5)2al4#Z4nv&n%{^dV%fw+$1AMh(Br?V(o`406; z!I5VYi@n)u&p*S^<-I>KcW3!kYLX<s4m2Z4K3WUi`JQC_$u*nyNphLb7^NWRItry3 zf*onS2tb|KNF8u)9|1O*0}*YRm#%7r3)`;~yDpp?p`L6q7hM;!Gp#_id`_QDA?~5j z$TJ^AmDEDcvWlpsT5c(nVsOb{vzzN=Wc(O7X=S56d3~i1n`JsA^&Mwp-}6y~0Z~tI z-16!YC${6=O_h23g0!ozwU)3_mbE@z6laviX2m<eC$E0Q{GQixW>(HLIv1B9&Cy^L z!6qK=02JAoa8IZdDMHjXrq;Y?y2*dTPhK+53CNmCm)4yCp3#Ov|BG!?i1=F{|M^QA z6|@Z1I)|xOGQ+?Yd<4WagN;9MgO*>CDdN@;-JDCF+W)_!u~!#F!^HobIeQM*{0X3n zJK!3?R-Z=y&Uq$Y@Np-jE=0C!ynS0wJ<o&-7DhYNm+0(PA8yD4G8bC4*>P(J63Iaz z$f}sn1;0tM$a0m!PHqX7u5G-uOtT#lOCji|Uv+YPAn3ODY;mOGBhY4bP8C526IOpl z_{T>A9~7-&DrIYmsW7RH6mAQ^+UyuQ7TM`{`T^0qyEt5uV{`h36T4eZG6+OXCanRD zgNS(z&|b@_<^O8(1#_ox(R7p-a=n255XQtcKl~X8mXQ;yz|~_Uzp)O<jQ{3g)GjcE zdHzF8K<Fd>mX8wbH6An0y#awY$fvgaSe^F9lb~SG4{*M~VjpPA?eyp}E$MprID|rU za$QfrxPWl+FzI+Jvy<m(>5v&B0gt7%Z|yFKsnq0Wq=@T;s)4F^#ka)t$GYMdZ7~B4 zy=PTH8dd*|3}F<nyWP<$t^r`L-Z_NCbHB~N3h2mpN#=P6hZ0?fY@-kQf`}uy#(|KY zBwaBhG&?QHsEOiXJ4}jvc1X6rZ?}%*p-sZFxnmN3=Zb(0(kTl1mtSC(P~@;w)J(%G z_+=kB+=ih|Ge&q10G#s~2U<iEvFD-B<T1dk2zk7&=tMliNN)s4z4h5=&I{KDoN10T z=uTNQL@?tvZA7;HU{g%%iV{$5J0I><xD31AaM^b`Ge6tbTDSSj`4Vr5`fj1e+KKpE zH>d~v1QH?ng5{0)SpMbSjl8r<O}X>Y?=(JmO-UutGrPQ?F1Q6?MbNkEGK${xtUen= za1CMY+DHmJfj2y*Tf=gkdF1^yrr}>-Y(8j~yZe-qQr^$fFbf^>M_!5VsmpsK=|uUF zG56bM?Qzm$&dCDj?|m$yHS7wf!<D3U{c^BsCBE-(S|1b;?VE2|iK7o>jL!f=N+=&Q z#am5UN8i_2uV*|2tdRZfHFH%hDKF2B7;as*0$cPMO2T@0|8;o|dj#%!v*wO;5j*Xc zCe{BAtet)mMJT=xEP6lTfXw~`q4JSOJf=G5=@Scj-AliyON>r7`hOplrhP(=#c$v1 z8g{6|y^`~OrH^^nZN(hmREw#E3UXM|JmxU(nD8AM!HrV-^M1hp{T&5qlb=w3t`BzY zmLMVeBFaRsx5RV^ege025y50uYFM#lenmzr-PPQek0^Eny?tVDxjYL@Dsb2jRxA=N zS9ZXRA9i1ENEsdUr+Xfd)US_abg8zSr^!}|-IDKBu(jzi=Kib*6aj2kc$zFau-*|0 z4%R;YqIxlSDpOa_tAJ;nI8oTfXhY3C+i?G$$0|rP3)kQB#esPQK}<)Kl4!iz^ZR#_ zhZpoYH0Tw+)E4GOzQa{##?=3Pfj1yRZnsr!*xkkVD)|?n78t&}_2koMF?hGc-70HG zfaaSEm12(@F}F`-#-4;?zq&SG+2QDWCPvJ}iM%PyIP3=76k%66IMZNHN^`~EBfC5F zxv<CHz*W>4*HXnM^S%2BR@}=vCkYxNM_#CmIr*e=#`8SZII~t(4m2ocT*ckDm9vC# z>sRayKC&o(`028kw~Vm-713ynZmnN)DFH!kwm)t=iW0D#Z~`yO^Z8E@A|f(Wfxu?< z?&y=x!wU!#<59TipU0$JlMF&bCQ-S(B6ok>B=*K<@w(dZ@EL3aXD6g+>FlZVsWZcf zT@Tlrx$R}U?y@J4SB9M&&Wh32Cm@nF!o+pqzCY9nR}s4GS(13ZXE6le=TTiGhw9hJ zjc-^S9XvkQM*1aL-n0a5wotuu>pkt;>st%yZyQ#154wrbEE`SI16NP1zGNE_eu1)y z#M!v4I#Mx_%k#zc!`<p-s8Hf4vu<rOoe~S6v^m7{=|^f09!6cluz}KxN}<jeh|QQ7 z5FA?1j?nLILA_X?#_rq-;yY9S%iYDFI#X&O{vB>F2c}EpAnYY%hFG;P?kaJRwav*n zID!-eXE90l>V*$=0%!dLBuAv0Mfu%=PWW7^@oiq#<2wW42P+lz<lOIpUEhWw^*C%& zA=OgfUh3TdUp@=xyWg*x8OLa3Pg`3R$lBqpQ`VRN09N-+J8gd4@(`)lI&>6ApKs7z zP?HssStysXj{6ZeK?&ux!XG=$<6Fg{H@*_hr-OK($c$}iO^J7x7Skz&L2OLpA6b`l zi!xh$WtInl-eIasw(BRQPin6vs><aGT(?!v53PJ8Z42OC?7HMzYx4Pb5N92=)3E0- z!HiR<M^~R>IMyW9eC5hJt>R2&nKueFm7v6V637~ZODj!MSsdJzpr=8=qW8So$%*Zu zo$;B}7;KXa*Ma?RlG>Ybt<%hOx2*&xsJEjOMV{YY;S)^E*ol@;ezTA$_L?I$<2f5D zTD-PqnEZPvtq<`l*l%>TDty+1aoa%@(+R}Cs;u2F;o1~0?@LlERls7;ZjjFx7GYLd zl<dq-il;1yIi$W@GOIE=sCefeNYmSb%`3pfxGxNLFP`=<8MA?tcRm*+;7kM(U<OX} zRhB!A{C;(<O)!wHXUP(0!gZ`eTU|s~sO+HcZ(}J0vW)j~H13IBCex>`Y{21oGl{Dt za=h%&q!k$x+&|Nhz+*LpWl}mckbR-gYDt~>5BJ~XROKgF4>~IX8sq{3Oz_?#$_(wY z%>vIOPA$Gb0Sk8)?stywg*acy{wl_mU9H}EY9O-_wG&}&mC;3}_#eFLL$sGJ7KuYO z0{<GOJhWX24D@U8F^&4(!_-mUc*!P43OzIIe($V}ow4J5x72vkG4J`Ke=w*lBNWey z+mFg>Ab|3e)4pA?jOk~lrwYzKD7T4*BYWJJg>s)7-@;q|2aNxafYC;@-!%JJXw*)P zR>bL<c$s}ICeF(>t|F;->CafHBK92&ZeiK~p9e)_pu$<l2jeb&Pc(JZ+JsOb>HK(I z$L!digP<k4*!miR#PY@@b5(e?mmLf<eW3k$_wiqjE+FPp4#gVzJ$H)0n!JD7ue}WZ zMWHm;InMpGw9pV7*nj;S(L4dJuH>QhmFhe@AyrNz@v9;{S+hgnF0!{)?<!!o#XgF= zuNTl`we(-f9-5W-nfPqX9fP&EL>g;&Bk3_Z-#UO*b=BMn<V~f>;;F!V44zPRFKKra zIA%l!Aj&zv__OROZgXs}*2$~yQrW?>RQWdik9Y3;M#TDrKxI2OX0pu0<y+;tTM8ya z7S%uMfS4D0Q0Dh>6t`!H9U@)WjmnTpms2|J+f{i|qKJ<-G)ywld#@w@<4FSYw_sta zS1Ri*zsI#0wYzbA=*BywxvJs)7PR>-c>pnF<gkAUz4ng(s?FvV$!e>nOg)ka6_P;K z;<(Yl@01ZhY4|ew3_NwoL?8_-zYUR#AsdO1EBNVL=g4uZEEsoL<VNH@FX|jH10OGq zRM^Iay03l35efq42IG0um%RP<65-!!bQNUDD%;!No)g`_C3=7Nn`X?m{_Z!K>SI-h z^?*W&UrfwJ)JAJ}u>SlWkNElnam#u@?Kai&>gzByMI!Zbr}Pp@G7sY@O1lX49O~H) z5cdp&s>%>ol-~uO5bfeEgf%x2bra))pjF%`Y%x2lo+m#cd5JX%{VI3EVM&V?JZbg< z_P{N}2w~^i&vkz7fS~c$>O0#GJd7fi?xQMLad3K`K<tMkT8LI}2%_>QzzY;IV?r3g zt$X%R-6UOOrPv^3Kl#p%uGjgYXkXx#Zm<eJrxpcF^(njL0Zso%l5>f-^MA<oQ5%0} z-JiJ$;@|*jyO?0v4kqa?wY^ITMt!Shq26wADKAR=?EPEPZnftjawhO0qeZPjYC$;K ziHNA@Vyc08`9kyX>f~c6hI~DTBrQJ?k0-CA6~`I^k3r+a#?{wX)Q~NcVB8rC_vje+ zz8MeXUIGpE{;mJ1HYIoCChI+5tPC(&x|Bl17ceHyQf%mM;><8!9*gL{4`*m-f(dJ2 z#b}bYV`dCwDEg*xj%0`na~}!Hi(%ir#~(xT;%S0?KVE-5s3~u_nfddqW*IB6j8|sd zdME116%BlCt+f}jBS0gG9Gho5`LkG%hv-{MNzcg6FN^^f#3u>L;k@&jIR8T6%6G9; zu~}m7tky~6GUMu9W2V;r3Ai~^m~qEPCKf$3Gnyn7w`ERY$!OH|V-uR+iOiqk>O$NU zKTyDv)4*Jz=V5x9=h(%`OR3gCXD1ND^gaL)eZA-?L;tNh$;I>H`|vBy;Jco^>+Gpj ze}m!ZbdqP7f%@We6_X;gvxSVz990Kzc&zDCNZL{yRW4DxPtrBxs{VdPz+yvLe-yKc zG8%{dTO#Xj6r1m{D^3xt{C-1sw9b%(fig`lPU`g)y!M=mn+l(VD?b!z0TE-x5c8gy zRT9uyE2J-Z{^xoHQTgr<elhJ05_<)RC%w9upygv4`HY8uw17Zvhd!L3+i3LR$~W$N z=e0Qe*Zu8G1p<Asxr^A2H<M02sVUxI#rQ?ruTTgMTrweiVRqMhrbk}e7AhEK%HQfU zoM?E36GOUTZKKVoc6Yw)pNnNBd1m9^ZzzFVY$(399zp$UkeaI1FZJ^qV}?!Hvg^n5 zrDnG4bL*6wiEmB4S&Tz$SW-cCOB8JI+!~+?r4GMpWYhj`$em{Ck{T+A&zUjF`xXi3 zLW`mm%9#{CAgaSB2=DV_nRZEnR1>g{wjaiuRLTBr0tIS`EOnGh+ok5mSIi7Ap@t6p z4BKOcQ>pqJnG6dhi}!ET{od2FDnm0H6WXxUmCM9zzyCap<0?HleKX1c%8eyo%+46< zHL$eBbgXaFcDLEx){B$7CBynvGW0&^hARx6nY9qP=ETn!J_?oeQHQ1dK%Yw|5&LU1 zNtNU$Sw;09YH>dn&C>8@9~KB`43AekZ|?BCeLfbspnqdtNNm|6-}QUV!9w`^?w>dt zn&v!7vkx-9G_$FgcOsBbCPg?)2jm3?w|UoPg?k+YZOVaJ^QcOZ?m08DkT(!}+iyCq zSS8%FFSZ`790Fd`g(l3X^LKD^oGM0u%WVbbDcGz(RJCEhwC2w(=vko0IZrp|KTH+x zwJ_#6fa}oy!Bz3jfgG!sR-1kO<%vacew(wCq{d7`&z5e?(()GU{kZP2ONEm&h-E?- zuR_PHOo*iwX3-EpGC`XLf)5kw@wRdbQM2&+ppeF@2i6F91i3fWYZ2qP3j-ssKf@A7 z>+J3SU>z@OB|dwFq9*Z*?*>V&PAlbd<c_t)^TwiZ+pYY?=i0)ojBT1qub)SgqE7|Q z?>VD&e<j7<HAcv8V<hstYtbxRuVG@BfEkFugUNfZe7B4KUv(bQSFI*aRUZ4-E*m`k z-6juQKRmL25ex(GVNiF3_#W;zP*?-DG@+Kn)$ybJA)Umfz3)_saSb!h6F+m@ERWy& z)AO@^UVrETG5!*es?JYPOWU+C`M<QB+Wm^daBecLRY?9(kz)<cMLT8OdIq-d>y4ND zpH8<aPm_ayqp!t#A#p)JRNZt``aISHg+Gam9_`gjJcb>)vawDWLg2)h$z+(A*K*hx zpZzkvl8NtY)&!VMSnL5%Kuc<{XD+MtiiTA0eTY)1K=zw3&hudvYh$n{(vse}da3QL zb!9eF5r??M@6ESgm44H%5rTE2f^apgaI~bOKU>!Ve|QM8G-#E_5GNA`uB`bX-aChi zxCMTayALFOM<q-+rdU=?z=}@P9GE}j*T7Qj*C0IPC#fkdVf0%kOW=V*K&c-hjo6!1 z`n{P#h}T8a&7u^DXE7mcc;$&Km)y^1kQE5A^qUbLw=OcA>@`1g15LrT5m1gy#EB>~ zjDBTYI21Z5!<!gf1Dcy(TcA=L+v@EFu~8erod=iPk9qe_!0w2s?nM3$osja%w8ID2 zC<&6RmFUlG{g3`ckBK(i=NKApDerD!PfXEb+<$Y9t-rzNicO90jq0TDTiXrwp9*ow z<*<Szy^7fHRUH-8Rux25f@+>R>8Qaly@95soFb;=_sPrj4<mdrk?GmbdOfSDe(V`G zT?3io(FWnZn$qp-TpaR3XN`HZJ+CKBaw@qozZQwg1dXvD-qSr((r-YqfA@fyna1P$ z^?`H!3Zi6k^q|7nNw3sm#cbZ4uVAlm!p&MSoyn?<1&u=hnh%#tJw!GzD*tBbol)>m zqO4wTdE`1JnH-5*c$O;X%wEb)qR@hC<%OXx+rYA0@>)AwhD_&12i@*_*{*0cGA_hj z6?eQLugx@f=xHJS`{x=GhjnwJcoR~Avo{FdF;k`;U3u+Tp9G%_zbvVbq`HIya-UdM z7tCDE0{v1KBNW|>z8V^e_5QgCxAd_y1moWtCD8V~0y2G7?N)YDSV7{9f&?s+S%o(X zllR5}rjmBPXV*q!DPXk!kc)~)iq5#9@XcC<#0V7P>sJp}KJ$k3R05J$e<s9IOP|`m z(Pybsg6O(gaOEXBf!cjh!O7}wZjlv_5+Hb!CU=0J%~5E|UAuLf7-=e}P#$TI2d8=t zAb;siwA~G;Q?Op>%{IK)Yctt2gjg9hF;^PA9EalMl$gMZwicyL>j~~js#UnyvD2Qx zcj`G$s=}}xfaHMCdV`kVB!H0ST2?mWgy*|J`sa;I$#CB}e^9}-xxuylW+M*v+WNZZ zMn;>{1RB~`?d(LoK$AP$6>$GmL4Rkc%)l1ti!Z)pB*T8@7DoKO1$_d^{pAP7>+21J zwT0^Vqh7GqN3Wx&$^6<Krs-lxxi}!qjACtyyZ)v<qCMceBqJLN!Z;&hJFT5(y*60% zZGn<`q4SXvA<Ga2O^|Ny2C^r%T)s&*Nl{Ng!A$J`*xviw33(fK7e$zH3r-Swqv3^w z>y{eAGe3Yi{MgR;voWa>51B5#(=YEdv19gqIn>Fb@WzDmy3^1mCdM&)4I*NGb64C= z63s)8`r!J(b-kCRks0-!omieqP(Ge<E5B+-$9U(mo?W|K<9h9scO-SoQ_nv=N#|+; z#G0NNb_uVPPuB5YZr^d+oACFE<}3M06U?S(-hQ)@Ig&b#Ax7Dd#75Mx#V4d>b#7+T zux-F5&iu^^f#7$U4C;jh42@^ig|Fi<$SN&K?rJrYyt;RzNtzy*mhTTP5HJX&I*ZHw z#fd}I8OyvL0s=JtQb{MQ)&0HI?yiVVERs^rOv9K@5(D72>90Y7rimvE{p!;Midw8k zw#oC|GY>#XUEg*g#{IZvpTYEhqUhNZzME&>{v{hJY~m+)>$Z7vnTiOr?{;66lSQNv z3Frv|rsc1Ngvzy_Crl!lGW4^5b;NMI=3m$#yM;Na4P;oKWk@y7$4DLal=%HJ=EsOS zM=BtGY792sr`T>mm~xHpqiuD*5PggtPDW*eRri{g(rtslnj&UCVSR%XbN%^-udf2x zy7&U`O$Xo^2k=$Pyvf;gtE9H%cu=_>L+^LfhuEGoJ!zJ{obo%B#@*`F;a)7p@cLaX z&YsYs2AaFWT5M_;dF{V!?eFTU6=WVHgx($~EMJhnR`W`2RBiMiPq24aCB2NuCR(vn zkU#(0Mj$&SK^oB;C9XV@m#L1+uSgisVo*isY@ChX#KUzHq76PrdC@FN8t34%LDT); zUv$H)t-0Rj2G6edxHmr{9p#f&P{azl_wZDmfhS3&o8NJw*}dN^7uV6%2^Dq^oigi$ z4$G)nAjqLi$!hJUXD`veZGS1!E`zpzD#|kPazWpP=O!o0hAhDJ9LuPAd5_{PZnv|c zD*}!Rxf7T#w|{}xE5V&t*0;`XOcICSHUn@uR_VB!Nd9u-_sMamee)TTV3sIMt!Miu z$EznVuKQv~*l6)+kCZ<huQnWs^W2&BRC)X#HW)K8nYR`e3#IJYZvtoX4U81j?Xrnt zt{Ap63rxjLZN%0bvbveqbB8{dmA@G1>qKa2a#Kdj%t~PBY*CQ1<TL)n;1!z&mdUTg z$qG}T5tM&Xu0R$0A9@h5S;Ns>#*DWK+P|1A-OpGtj@dMfaDT674plB2Ki?RVaFyn` z9P^%xp@l%a^VtI_#~kZ}%?;+~Og81%&xb_|Hl;aBe&Do&O{<5xWr5>|#kVKd2dXT7 zKgj)};c`Gc;QlBl(<c3ul1NdA_ZF7gBc%i9aTzMn9ozjSlEnB1_DTIi0{Z=iD>eUy z;RshXAf4b=4a>Cdzx+bU<Tr?J*LMEO>c9W0d=?6_re66h{~#F%(2o=v*A@;Q)Kl~r z<Qg*u$E!4QqtY2`8BGN%y2-K}S3bC=7uY5mRSn#pO?ICq{T1w%D{BiyMgM7hPNq!K zh-hW}ZxW5C67HbZcl@e7Sn9hLl}`4y%$;1Q$)-?(MYE5Osuty*{q?Ute+TnkxM@ta zvnJpw{O<6<*3!^N&foF|G-u*73hm_ny%G-ZTBOeBW?uk-8scv~>BuUK*CKZrds_V8 z|LP`A{^?S4v_qgdxcQm%9hM2}>lYiR9!P&({uQh*2QDC7#?{<=Cono>XB_+UE;{Bj z*6Zs3j^-KYRkdb25}tta6JIm-@1jukh$5mNPTu;@eIvw-S)GT9Nh;^zj9WzlmPv&? zdj3Be6mSPvv8;J;Wpt1<LZ5l~KY#HhmR+vivAQoORNC*oMcSp0MT!MJqK1Toghnc7 zQEr53iBvrrqnr}y2L_R+5QF}eN0-n-+mQVw^%Hz7+UNMr<WCp5<8nn&4juENxI2pm z6(EDxvO%s{<*5kCyvTN#`eM~ebodw54$0cj1<fHBqWTF&2SJW<?QkFK?I-$RCsn<{ z|5IGUXn=~ZEV!Mhk*DK3G&l|AZdA9t#6L(OWIY(Dc{77dvz(FOAbE5~On}FKE-D_^ zX}5%zKJf~zoiV&nlkaJ7MI{*}#(HtF>A~yt&pYT${P@Gca4LtRP$^bg>`SmR{rhjq zW~d4~16Rtnp-^tj`Sj!}Tyk`BVr;?{jMx_qvJiGi#|6n@alAz5j}9b`K6fydN4s1B ze9W2H32IPvyLWH>-~5({>%q<qVJSK{P!?#$xW|dQyNJJ1jOTBZ4yPYA83Z!q=T{6d zQ4ySkr#nG+@3nN*^Qa031J|*+rWG*K)2{w|C{wb({vT!O=RlUu{WIB&|LXrF>9$|q zHjN4Xv=aCUaW74h!e%hGRqA;NGuV?W9~rJsT{iElx=eUc^OiRtP)GW0+fS_UWO*@{ zr5I&UB8C5`b8sn{M5kY?<pOQBmD=NQUFOz&TGYA!xG&8)ARa<K+s^?H{s?a2w=ZOP zo*eIhfyW?Z?v^t2&L+YqpvfHO`MhLw@s`6inm`DLgy&Dd?C=v(p@Fg;4%kha2#W#F zbdBxi!&(eut8><4U!0r%-}o*~5K^k_^{OciK@NGb4lz-i;Kcbd>HwBkKmip;FpE$( zkm4Q~u6iJaU}8V9r&ZfAPhfVIHd5*ilE~1hXz(SptB2BMtz@tC$=>gOlExJAbhkuC zrPO+<VSs4rn*w9k_E3b=RUxF*N66r@XIKyRcwG^N%-2~e@9byj$J=V&Zf*X`M>PiO z21AKExMo<kh(}~Dm?RMvKoqkUH5d6<7>K2H>#)oGjF=l!^i$&M>5L#Yp3u4DCCE}) zPYZ7G32V2y;;yk&`q7$!kFy7RWejZx2uhy4o3pSUgg?_l1-i`-`V&+ztyknIKPrzS zenJR5cdNDLB&b<cFfr*!yqPjz%qu(Jj3;ki51vVbr^yV!2tr@QoDoZL>M&j~0P+L( zQf|5^oQ2d|)RGA&inz0WFP~XCf%2e!8o>MO&Z{aX^I=F{Kfmeu^`sdjPQ=Fsq`%9( zpYxWfjlQJ|LfaRNTrU#sDcIU!8c;<9FSMjaS2b5d4@tt-((MRXYukXzIwj7?H2CIl zYY5!$t>LEG1lYfQQd$JwPr`JcqxqSHLsnY;=b40!h~De$n^ZwkR5=k>#0}<7_l3<A zjPG!rt$9a%%ON+xWg#1pIQcJzR6GEUQoYRrL$&%^w>+=!U%3t9pJWAIU*`>5ex?NT zyrF6De_;E)^IkYb^#7AK2mcZhZNFX62MY*QeblGjbDS37DAxa|8K@?aw`KNc1|J!N zP2ku4v)qF<m4yV-nO@s+5C12?v9A94;~HnFRPgxmchaZ+F@?;2)(hZ^&xVWsM}QuG zReZMr5`{-;i{_xus|Ux_zBGes-%6x1;(36nH!tw0<I`A`tAGBp%6hW?CX=$~pq1|q zlBrvTdcXML_CjA9DP>1z)ylfra8yCBtCn@eG{5t}z6ih$re`xwv$WU#7(W8V4kw68 zAzT<<_1OK~=?6uB-gBIC-$_OXxbPKS$6vbwJEC4WD_bp-t%{UqK&p{X)vCCat+mjX zz6GUy`G#+fE(%_byiv$^3>8u&WbM|^7BzCsSgq6%@Sb~t2)^*gsEOiRyM!OubxAn@ zI^}m2YJZ7{0PX87P_X~jvCNCU;v^hyN@8;ZU~yfOS5h?lrdB3`{`Rk%!U#F%lf`|w zx~?a3%NDA~Z2rvE7SKFHb$^$iidp0NX~L7fg$3dlr_bPkYXwGU0xs#)JsliWUm6Ys zYHg!`ELk?iBf6JTsBj}J9trYKn<4kv6IHdDJOx7c^pHA5M073WD~}OBh{B}_k{rew z?Qd)rPZX$Hp)&di-Z0DZ2CHSHoN9hwVLOSs;4$vmQ)?#dVjyfcJr{?mYl(|k0V4%- z;h86nP_u8Ha~QE{mL}4W<b3-1-i?M22gVzOl!|O)zgqlfS!tAv+|pT_E)N6CfkaW@ zN`SQbe-ay2E7UnMqm)baQN(V6MRSIA%ujX!6`>h^?3c!fwO+q@X*jrHjg?J_{{d1v z$8RQMQ@ENNUL8X7<D%p|`1O(|Qh)(l7;Do{+J2`*1}?s4<#aHo{|P-71_qyMQ??Ag z;;7SMF9g{BC$Opw-7;UV=tz=2^*9s|nsy?%4Q&|i><WPBT$-ItDV@--6Wl^M3FW7h z#E!^cvJ0fz*l8BNBpxOH;%yXYQhF^cz7O~nc>UkNYePhf?*fB_u^$CL-#(ib>)T>< zDbP*9?#bGJXaEZEvRe58*S^TpEt=S!6`U00{k+6)Ji`95uvKVu_4zunGGqk7nQT{L zjL3dTy_vY18!4{48aBr0h;UElf->@CsF{i9?Ng4Vu|xrQp4fkZG39#<o>hcZXgmMS zk#%dE!|sFaAD+iO)TIsI7~Kzc2y+}dMFq%%qJ_0CUgG=O6ZLe*1Ji8j+AT^c2=laF zIgw3xhusfaQGSVvV$<rDl6p-$CM>)W9!s?PuP&%efz8cXRQnb`RkJWnZqPiPy<byn z-s=^_Qt6t37Hh1wS$wWf`E575aEi#4SL*)PBR{1+{l0>;IQ8y^ZCxCL*g&u7|0xh+ zQ=q#;E<-z)(S4=Kp0{V_km%9p6FX-OxC8Q<ybJ3OSWAhhFF=A^e$_jYb+r2i79;P1 zLRK2#`<%Da6T~mHxGrqG%$o9b2hpbZ12&EF!UhZO2|7z@BRa;5-M7H-c?oWV?c*qI zBf>LhY}hpV3mX;~4KI^XDmS6K9gNbg!lJN?Z)}m5uHc;-H3^`XrY<@02g;CUtlyn| ztepCrL@ZCYOmViP)fQAl-k@Wz+=yRe(iDLde17P|O8RWd$8^?TCrNgiG8cKLzC7+0 z^?>T&*N5UiLT@$6NMB@dtlh7y-#Tmhe9KxY32)1($gDugq`g@<@=EBObEtPncW2SR zVeGXiFW$+fLA#iBo91$drq{-jXkoVgPC{m)_ss|k@AE+6Q;P@gy&q|51AK~R&pm~T zSoo5X=O49RU8`o&h@$uEfA;`_;Oyc1w{a!5`!3Xz=jU~r-pKA=GvG0vBb@Aye^@{J z%>AMoTi-PZ7K?8-)tnry?td|!Xz05Co%piZi^<=m=nn+99`-T(E1(Go#~{NcaSa(4 zoeUAU(~z6p#;$J@qHDs%+<&JsLkQZZfPb}9dCW3Vj^5SkS9n4%@7lYyc(+EnJ&z4n zxT?4TJ~2f7-yihHD}?g)JiV9FDw*+ec9Po5pl(USO4a6ByCbtiV_jBVh^etbpwCol z!2R8nYadq2-z@5HcZG>H0~C05<&~+sR*6rbS9aK<!aF^nzihmj3a}@UXVbm8+sdBw za*JP2iHa@BwirDlA@A{@pq~h(AbEJS>Y2ocH6U<Lqn-M)&DUlTvyFP1h(<e_GujH3 zLI26YEFypiN=W&^`ae!tL3csg-<XzDo)d;)Y(6+8r<6Qak+TwA-QgSrvHm-soj!3d zUbmv6nbaRGJTe`o-ds5L>DonDdoS?iFFxkH?PE9IpFbF+`Z6RNIcopJxoV(_S^bez zyf=nHgb`s2*ka%G3C~a>q7~%IW!eX`lWWTr0iq_}T+9!o{u7C-puQAdn@u+bS0e%g zN?q{6N$rX`)S_&OyrlW!pRj!U&MySK?l&_Lx2ZO`Xzw=grsM)BaxEd2`~<ZEt_L#* zLvAI0KQ8`eQ+!A5F%DIHgxEI>no)Da)ptNk`3nTcrN|lyXR-iJCf@9Afct)ySW@-- zD3q-^b=xN5kVZJ8q8$HyQCfU!|MvP^zh@QGw~pP27fgX{6yn#6?oZ`h2MGUaWd>q_ z!ia@<>P57J%=+B>mPf?<B23J$8k=kWEO0LN=e?~0ub$FA4c#G#EUaKBE(1NipDhA( z7IjQ1-dZ*RnEPpfSghOZZy6LnmE8Y&6P@NI&ZLOdy-z1%Fj~(}kUF030rsRXT8u?l z4AQ?6y|4uaT+<`s3!JTw&fCCvpB3_FIOrO8HIO<(T!*tb1FtIs7He?8CZ2@k0u)b{ zATa-gcsRN7lMtBEDWdq#2L(y|o5rf*mSY1=$nl(}%l1O_79Ug^PNDFZclor=+kn=+ zy2QMv32~NvIqN!PXS#WzL0t%VZqGh|g_NP^FK?W)oGjyCcP#CE%Pji7?R{eI=pht) zvn~_$_zk9#_<vqyGE7l}fCIqHb75^4geR3YfKbxth%VmjJ$s%mPGr>}PW&nY&V9XE z0mLb7#F5hD(90&eT>GP$@9ohMEx`lmlth05>i4=wq(1%)3=QUVij*zFmpRV=`ygeR zYOyYifF#=t>P1M47Z&%cMSe=uVL-Y;Ja`z%i&#V<VT8L$G9g=Lx4SYL_2TLU@!t=j zKu>5%l?25G!<2g<I9o<QAgg%Om?9p%O00s^V^3E{6wiIV6Pv@fYNsJ_G+L$os&aj( z0$T7pO59Xs15@Q%@zTVV>)*HtcCm{_NYy4)#7+4axf3OeMz~31AE2aIF+(qI7oQv* zF5Nn*sMj-FNr=BS+kPPO<C$5<yXD<K7vqR(#<gKC<-I|0465IA^pQi<xDi9jCKquT zy)aPl10Ce0!^jR!?a(Ky1Psu03-qf<Z9hHv*$+w@iu~GsDISm)eFWVYn-0zPQLXox zCx9?aI~Z6>Rl4YETIJ;E8r~lr$A3piEBNVS$4$<ccN6@xF+LDDTLbHon1}3^ijR=J zXw9pIL>jIiDcZz?C6=+vgGKeo#{F!%H{;%0D=_TZL8{w6fgEx~7n--;r3l9+lBb-c zmst*U08DrBcp%?85$xn&dS13Kc7AexNO)&U67M*FK#_Z4@55ZRo3F=GUznERlk52Q zP>Nyjtr@4VXIOL)y{S|LeyV+S_o+&G-gQ-k<A=BUge_0E#rpp|O!J5pG00fGfy1xH zHzR|AiS?W@c}>=<9n*>?M;*fu%@~Wy)>O*0wnQqg39q{zVgCrK%RILI@GySan`g-? zxL6d67!Ah}qZwyVSS@jyR~scxe}x~#+-R@%(#wngd|<?b_6l*vRulQ>n4fUW|K}&! zU{vmMC)g}B7xaebMvWQigM3v$L@jvl8Xg_&mXRq6e?3b`V^VWC&08PEp^i0br5Dbf zlQ#hgZ5cvN(s}C%UJ>=FV;^+(AkVujAip8-vd!%)4i<4sHU=ht=9gSLIAu$s7rnm& z<V3?DpHc{CM~HlRP@)ht{r0->6%;rd1fPz*t0FWj&p^E0`t$YPPN*8R=gWKvrRGcd zX37BeLHwI7KA4zT8@zB6YHsLC!caf3CKuX4Qt97(!vfpo#Wyf_e$o=b6u1o(e{K<4 zP43q&VJpCdq^wqp-35CwG9BKU<L!c<KRk9mHt<7eTj&Xu_ld6T@%;|RI=kDtyR_qb ze%tds%>aiyfmVKU?VgZS3~N?zPyo5703o0l{sFfI69P)ELNLP}mky<&$e3Tx{d3w% z3>@;K24lOsRT1utRac6XAV3Fdm)#(8S%zo}w{2b}A2B%|&n`jYNW`7*QN~gKM~~|} z&f8xM7?1`Mw_xHgL-bJ!MWF(X`cJE5##p~O;5l1<SLK0+lTZuZCKv0po_{5024A;? zxGjVO4zSL>JZ~iHT1KqA#-SC1C(=1>7!q=Gh&6MoV7U%lF)N|b2P@uF^AMgjZr##B zp!OiF7^Xo&Sma=aU+CY23~LY}PI(?J8q`;kA8vU-NeRh8K7&(5-Sap5nl*o-fm`|= z@%#G>B`k@oo=F-Cvl1c#DxOcs7#yHF6jzs#IGZEBY4LVg(^s`5ccEfdXC~R_JihU2 z<<7&;u)->@j33Sj?d;Z^AiY=~u(9}4Y~rABP40O;GJF&oNx=k*Nd*OX=E*#^&$Z$N zE0BD|>)0@+z<t@0X>i`BOckgBJ-rnA1^TxUXN)Dd6X!M;9>{s>TZ0eC5(IWcJ@$%| zNbioBJ}m6kq{At8rjUh?9Tn>3oKNG#JgZOJn;qo3FLb{5;Wnrqfo+65MrF>bH>*oO zn1kiRTm8H&9kzu0Wyq%ZK0Qa)enWRit1}Y7^TajpEgmjo#6?V$i36QB0jzuxw%(N7 zI)ebo=B1^jwU_p$XqK&vU6gC>>D_PyROlz9eN>f2eKgtTqIUD$jpKerJpC$;&d~ls zA}7gUyXyJ09O7S1wh8k=WL<PWw6c33SKAo;s$GnVGv?{;VYloo|BR)jzrG0$cNP}d z7ooR_J#^~A(nz?ZJ(PST$1MRVJBRMeRbq7VSy&BdeidCtMyBKq1n&-d*QKIoiYZSW zVf}rdeovE66J#9qgiM9mZCXAZ{<)8xU^*=$Kp4PeEL<Or8u8Vr%Fkkpm2iBptSlDi z4#tmN$gmzPG>q5o)6*MD?(bSpa;#rW*XUk#Uv*{L(<lwm;pqF_3eRqzWbmLScYlaS zR~%VZT9nbV*A_&iN|wx(bCN|D-D;=$n>I9ZY^h-WPpw6FT<LWV9{Uh?^Q73cO~J75 zb1a39yMDskte@E6=)lS40Q?VsTZ(OQ?o<!@R8fEw3KX)`9^aegu<^YQ4fDpYJ?^Zv zn+QF-?7u1>w^k!&N1xTPcnDLej$DuYnt6BHl(thi21=Ve8Jj;iE*D(3iCfaWDs7)u zOjF(hMDdPe-kr#NRgHjLi_VHyWbBIPMt@jL^h9?-$i(T$hy5J@iSNCn*}-aC+M3dq zoxc2)zMX*F8G?T}5%;UgNFAU2T*MSv!ZMx5OocNezoq~FPYYiWz$fqInB3=%075_E z=pbTpS^h^y(`3;>il&z}Kc~L$X1p7AX~)mQ?E=pyH&@j(4J~Wz#fi?KaHph`J7#BV z4^Qr1tr$9MnRf?$5;f4e{zv9M_nC#rZn6HGHtxWuGwo3OV02&V=z7?Co`;@!u0{dq ze|&WZvn<u~^eUYszDjy$3Hn>nxpEk@ozTH<eDh@yEI#bZDF+@d)HxPkH#*9;Ot)5} zN2;Q`Gjq=U;c>3%<$x9|Z5+H98}@rzc@fhI#@YR{PjtDXvVC;e?T^zssO~vtwO4nB zSJ|~u&+ccX4rlA>Fj_Vz<T1m;zfL*_Gq<UY)6SH%RE@X)?pU%8UK{O}aUvc4btPC@ zzr8K_W<KpJ!>z83p`q!)Hc|8~;o(^<;>(&|wv272hRjGH@mDk<1+Q_CNnF_JZ^#ej zd<@Lu2b65c7yb2L>MUrlTv@;QzmLH{P2&^)e{-5zcSg=g!<)#Ak-;1lQ{nYHB>0u+ zX<JI|4%2*VF@hArn{!y-T&r!*1xb;>Hl2a8Gi?53bcOQo0Y`Acf99KL^Zxw-u^N1! zz!_tNtZ1hrtRQ7X&&b7W|8oI+6pZMm|6iVDMlTucybRxpb{w29{Q3niE37Kf{asmT z>_?_?9EMl{f+!>A<eNJ#J2nbI(tN}%vR)YRBvb-2;<YC#1LeSqnxODKGGpMRQr7#R zcyxb%q-2x3S%0~F)+I+pc<1?(+CL<+aE%#3Yd1Df^mOhI;3aH{4MfFd({IZi^YLDz z5}R>rFVcK`UA^iku&zk6Dzb<i)kl?Oa3rNo>Rm_HNmS-H#jy5gyGFSE=yTmq%N=l~ z>q{-W?5ek5`~F<D5}m8B>ZPHd;djJ#iZxaHU!woOYqOOXCxAlzSyw#591uH(O`#Y< z%0VPPgrfKk(2aG>&9jln5#|epcVwd{Rn-{HwZ{*EMqCUNr1{NtOEbjM4JttK896*v z6vYvBsTTgmyp_$5d&8^dzI~ikp=3l$SL_V#@}pYCe&JK$)6z@7xn^zz8R188N%J$^ zO1Kk*ngWpQ2`uxb{f+*^B+9}H`5z-ANiByzWnZ@*5$=tx-dvF^SREefDc0R~U#C<J zt11>%*(2{W=EW~vG8VzcjabheNa2b0Xg_L3dtbUC!f|<_xyrEKuM~Dt;>&muzBc7q zV<LN;Bd(ljI?US}<{!lR3TC!{X;8E7rBFl~7bsg?IywrdFN*ark0<k9!X;+>IN73u zFUh#?&sY(yqW7NW+Pyq&i@uE&OKe%cVXC#ObC?R=D)!Tus`eQt#A&5>`i~Pmi*S(p zOcuW?1DD?}-%g6#`@joB+qRyjK>WnXe9b0QQ>%e<jlss3xP+gBZehCTwusAOYKLdq zLFKdaaZ@}G`;zo6#CKeJT!|va0P1yJZKiJ4f8Q%>c0e+1%=<C2$<z8suUFnDe9~ay zFg5}s-g6VbY!0Wg={Q{5S75VIANAb!*3-s~ektb<+g(1XIt=!rY5p<{t0k&zQ}-Dw zj@1qDBk)7U-1CZXWRo-}hv`2NRg2NNmgv#;{q%T#BsD*nqi;T0_WH!X`-G>d;H9r7 zGs*<BFYx5djPVgMA2gS-$b2~0LoPy2b5wW17d&yC+S`Q(Y!5sW?G9b3)kd!<EclNa zyeWt{E7ozi3a>d+pQ6hFDLkvH?nYOhlU?Q;vQ3{GN(^qIOqK`42hSYsJ(fKt=_X27 zB6zxY2KF5!!rvk7Tund0sr6JMSQd+SUAAjrCx+feDErz>Kba%nU&p@jnh|A}*}}I) zw{2%E%>p;DW_~0+g}jDf*Me*HU_o)ShD>K{{9rKizT;?x4$nSykKkdseB#QgZ3$6s z*$gVXIo`8h%O~8jnzcV7->aPh_vm#@)+oE+=yPdvQMl&bn3Kt=6Iaz|TQw}LWyxLn z3%3$*W=0DSsiO_NSAH9RPv31#YBPw;j>nx7rh`ZW3=VEaHFhTscxG|ZWLBk!bj&r! zg_oFzRf%YzV+8Ma@y+&p{B%Jh%G)ccJ7pYwBq%*CT6BS&PxT`yBSBW>7E#m*wu+a+ z`S3rOs!qMm4?UOylIk_lQkPrw?jAD@oX_y!X-Np{R0J9~Q>N>p*q~^~d{gn4jb3B! zZQB^3=7nOeU(N5rKYnr1i1qebK!<XT1*8zqm+b|8b2k#WY|UcEil&sk&U!MvR>Np9 zI&tiatt!5B7Fl)Cd3bX|s=QB4RJ=mE-Hj{>dHiYF&@;qBQTJWFdJWE(@PDvZ;Z0iE z{kqvNvtkez$g??f2c2hrQ`)|rAK8j3C}l;z%hyD?WM_7GGHmNtIsOs4yScC%#pDPp z&B#zjmD$B9dh#Pr%|C|yzwYhO)Aez*9uf3pm^RVjKLB*a0Su{!ps|f@IfX_j>;!I1 z5r?<tGwt@bQ5LUy+s>r@$l;T)##(S23o2w6$}!7>3bJLG4&}D0vVw=rNu9#Ac%cE* zO+owV?HAYtxlsGB7^7Q6vdkA=Wp_RlHPSvHr-9f~IXhPLzzv3UQTP*jrbBS@`l8pa z$m)q}w*m2y?;6jO)yjT1(WgzcMwnO@mkS?vF(WQ~5YgxPSsK|OspoCXBc4C<HL>)} zM~>ZMi??1FyJTFC55~|YtK#Cx@zL{E_Qc#8J3&3pJ-O%X#UgA*l5qdN?k@niihx7S z%CqrdCrFDJ39!($K872sX&yq`y4kT~mYuGCBlw-Z3A*DU11ot!9_Q0Eeob^~#vCRn z8Hb#1j_48W$TMkUnbqnZb;cfHD3poEyPOgVqNwU;3y+dIs845)w-LGQ`PYqF$HQC# zn8kwILxTV8wc?nHqyZ1pi`sB|W6-d;BO=NXZ~)rzUOwGzd#fRK*je<tjb`LWA-sIB z;$wO+ND-f4CPRYE%VJ2X+izaslw_<%AsYtRwl|b{y*`J0F(Wr-hqpp-U_3GU7uZsN zLYhSmmsr-{b0s;AaWCs*>M#bEtz5Z*x_~!#*vu*)LrgC~(2>rEfkDM~S5jPE)z}O< zPa^6Qy6L0-6^g&d9U%Zm+Df+tosIz(2yZ6{U?#N-UL$epDI(Ak4+-_7Pr20Id$@Ga z&af0Rh&}Rv$kQ;X7dB+=OQMw0jK?VO{VtxzUqadp9s8!gJdHTa@rW6FjEvZ@f;7Ec z#VDVSsy&C(CNo21BE_#DgW=7HND~mspwH=S!9d|*T2DqL|04W*gkI>IFzAfb29bY* zEIc^;#S5W-KbVJYrANhx9xF)sAyf-XA9tlNbKQ`VhWkpKB?m){CLX_}oQ6Vr1tPtY zxVpR5tdQ&T{)SZ^kimbkS|V8%TTWg+5Ax(4$V0S1W*wyNZFC6<ogm61I2~?s05;O< z9ck)~8!qK`PT3B*7=9Ry=}k9(^eg<=uU`*BlXIQ4^vuE2(cQ=E^wmSY{O=G9_cci} zcJVnJhQDqua)&=aRHnh&u>0@jm}22Zm<sQCp=}7juCfcdvtaeyA3XQhKl~GOlE1G7 zx^W&ry8QsCGIQPj>w0B1Ax6q4-(*t8`ujy97r%SuG_XbA!z#!B%;v%sj1Iwq;KCFU z1p(^%V_~3xAvIEk{Pdn!5x^$R{q4`+L-dX#==8m~iJ#&0_Yl#g5E%?nn!5k<K|6fF zSMV^%A08K{X8tD%PK`7H&dt-8gz+Jk?0FQH5l`WxAM`m3*PYfL{wy?<XlK1lf4V}J zVwLyu>qh3{c%w*_A8r`}@Hmkd?p_%l%cDnwnt_(^=5L@g=FN%eae>oEie|hI*T_-# z2#c93f`*O)_xckkSqEy!5=GLJ+i$KxXRjgXZ<Pxc=7AXV<1%qRddPA`-0})uWtqZU zN^ds;Cnt4uul#$JNeGsPp~C+V0O=%d{V&2Jvo>Hi*Pn5Z7LlP}e=^()tp(+N0__nu z0{;~(SA@L2vQ>{x=LVWl+snYugmCN<u?nWIOqGZ*$F&bqHk&iwkq%UgJ(=ME34KSp z`9R!9FmCQvPbj1XA?VU;HN_%?oCZ4NI}yDb^pe-j{y8CSAiL!ny*DmCi@ywHz#<>6 zs~E0<vwj(HUJ+N)M_^r0P-tg4kYCao#r{@@Z58@-S#~CiJIx1Pv+&;1XvNp8r8<2w zQmkk%t`7?tg*Ife=fm;C@FVEyiNKiit*}kX(N0;-z0ZSS%$J3rDnKVa&w1qv9#b(y zcY!=lDnIsQm`KC>z}OGljFu*^Z}4X?9NE=kjk0YZ(wG4yE3gEhRqN{gnGn3DaE7OF zBTK;@zmw*=1-ZUOpgL!o{{LQCV#XV1i375{{AChSvwmgS(#gxq*AssAKX<_h_$V6b zqx}>Vx}!q|#~ZPTO(Q|xt58}Y!IC>J0cjM)%r`QS+0%HbR_a=#+Q92;eklA`3zZsP zz4DkFK-vF<u!nReR3vX|g4GXn07Gjfy~s||&0gmF>+M5(O;Mv6Q&9M}9(^VLvc6RS zYYaoV;S)`?T$>nJE4;t2_EmjxcbSCQQnIZMZXB8mCSXyPG`@-zivIVZ#;q~myiErC zA2Rmh117>#5fXJSy(!tj&p&w}W6W)>)TTULrjgKpZh(pPvMQ$UjjF>1OQKgU8TO`S zOLzU{+bnO>GgcA2b-k03+KjAa=tCsBE-;p(HujzZpTsLxL&fRycjDfh)6rjC-(;Xr zEa4`~yRI$NcDjK`8hBw`IJ%jJCB^Z}yF(&P2akgJmfak2er-Np8&dG=49d1=D-*TQ zr6Fgza5{Bi&Bf6EVz1O{%=nA@1-`@aLRYFkw52PPPJatcBFt|u(C-pF7P<DPT$=Ww z;px<ug{gl@&wWV*W$@{&OGGci?-YcphJ~YX&cPqR%-prY{TqAvR!(29MnHzSR{mse z@sVVyWrpqNz^=E`SK!fy^tZH#UIB;Zb8P^8^W=Wi;WT7A{RS=g24lS{a-J0wey9t7 zh`vjEaud+M3z0@6(4dbj(KjK`J2Bx1;WdGi23a_df__<P^Zyo5%t&Jl?*M$K;8YwD zY*}BK+s~gRx$hL=k+C67PM(0G?Y_gKoS%P?-Vsv4ltUn7%Z1n=u$jujeb~?c{v8uZ zB5DU(WHCsA#Q*_hyxs7flGUDVtz|vZ;5?k)@B98%s0?xK1Tf4BR)#{PcR{I1E2(ak zi+%YoX=C?(J9jYv%4lynSZU?MH13B^D{C9d3ryWUmZELnN>A@TzC2(k?9H}fVRawK zcFuZ#!m{ftS^1HryF2GMu3KhZ0yyYPTCW0w8fcJeJ@OdvGyL~90DhF3eW&TU<|~J- zFuJHxc68%+z@^h>CMi<ESM#6*fOM;0)9)d_Orb!*Q6<Hnmtey7*R93x4L8lcOpcOb zj2J;>D`&>s!4|=;ij0gT<~gbkwRo@2xJBy&BFj8M>yh%pkTM-X%YLqxa-n_LD|wI= zW!pP(nvkriN}irg4(34guQdvkFVC-8F&C$;W*QFRg(`mqYz1F=q6m&y9R~LszEZx@ z*h(b|9Fi_Msi=$@HLu=3)PL<8jOgd*7-3lyqvE?ExiBJwErTtakdV@u8G9$WvLfn? z31q4gj-SfV9O#AgwJgSY?ub8Qx(w#tA#-2rtdS|N4JoeKh1Y#d5lWa(4b^MaIN!fW ztt@n})S<u4$RV=ecK7xh<$563(Y|;e)5CwP8qn+Nt0Ff0YLk9bJI9Iu9`a>3*qkQ@ zNL&NZz9@R~zTvEhS)Ve+jI*+yr6n_J1Zic89FiPY|H!{rTfMHgxJD_P7mEqUL1b`p z()bmHiN(yBoNr1<zec|I<-V$6r!KvHU#WpsDtrIq8$|K=!EZEqJy#dk(KOnO4oJxX z&6op=K<@Kmekd9Idfz3HR+p49|IuI8UMgq1>qmI6{sJ@2_e^JU<|qRlf8K(kf?Fr) z#=)o4$@el$rv@FvBmgaI;lN~n8DA;){y~F<g&j&+y~~pm%56?wTjn|%XD0aSzddw- zuS>?oDu3lfqRuZB67Gf5c!z`J2lM5$;fDsuB^=^*qT(4ImA*i0VDaNwiWW4r@-7D? zQN`2A_H}3dXzeL3?#abE9kl}z8RpAfAx60pIK^!}C8w<7)a}6y<*7dneHkx8oOl{x zG4m+vqq&~yGz7P<oJKWMcYg)DdQO=eTb(_<ai^#IdnNp9Q-i&C18NEFoI<q!6p>P( zpc3M7Q5A*U?9*ck;KqG<{*mvW5B~q*B*{D2Q1760sB12%ky*k#jc0mc=BVWG?NE8s z;3GC1{qH4kT<6~VTa>d=p2i`UHN0=SiZTS1ti7g%oPrue#?WD?5$PJOTmH<Dk5n0n z)-m94Vn$2cmfyINcOODb!6Z@*74-fpSI5(8F)VK?9H@gJB!5xH0635e&00tR-a!wK z5BHH05L9fAtRODP`0>Ae*aUe9>LI{VFRTTUH^Rt$k43X60EjQLRmLMJQa1G_63nbt zYn0i;cRqpi>^*Cw^-_Sw<<Cg=*qegE9Z?eSBZH(Rvlht*f#k|0V)2=kl~wTBFLaOH z*}tA2KM73Ul*TW(l3M7p)eE;>?BYr1K4u8~wI@deV(1OVKjz~_kx(EUY@^Q5Wzvw- zB!nLVWPUR487bJZvquN?&s7%bz2G~&v25^$D13^ef(_vHfcvu4goRb?!_)jNA|K8- zFUQ9K=gZ1E7!Lku+C~XBQBiq1B^);1p`OkE%iuP!9(!{s`I_T4$R?+(Sn?V{u2t7J zIHEoxMSc1@t3$|?D;Kaz5>Spdg|EN%@7Ldidz^_RB9iLKAK+NZ(LtWC|M%&^p?rV0 zgeutjpOJ;ZHgl16MjS3@9$3{~b4?C-O{e$!pX7j8#oO+4L6sBehOmrJpZo_H=3k@8 zLRZ2lMC^@;sIUHCy<Ph|)M+1%H7%>GoJv~R-ff(vrP}g36?s{Qu|rdi(JF0@Z{##7 zW3^$EU0PvDI?Y5O#5-#dx_FgS7)5fbxR~S=!<u#%BM3y{`4+T;_W{*L<Jn^L#${ z=l<OH=_7}XB$xi-6C@9ck0vPMZAuMSh238_7BBxwK3FE>dTkh%sn(8VQkR#BQpH70 zyM4e&Vv|<#Q7kiMd6_g+d3Qv0P_+d3!$%kATTb}_IJ_|a1Uto!;mkPF{~dpnU9^hq zHaEP8!JC0LDvmMWQ+0<`3Eh!97By!Xxh5*<`oWKZfSlvbn?gOe9Jo^l0r0zBVH|ll z-unLrZ)!eDFk9xe7bO)udS?)(FGWn`PCq94B$8^f28h`YwNeM`=m#HNwI(D>7vgb? zNvvYhOo9rKSKs^DvN^3FYHt@5N4UfycNW8(R9<^U#PPAdDpSTGb&K#=^0Z{^d0WK+ z191wqkU9U~-%#zmLc`9GQc0#8Q7LXxfj8{$VAkICs$JQGwx1*`W0)naSBMVu7dF9Y zo4CR!*AFJ|L}BU79O|uYr6wL=>3CIw!`Q8~#lw%NPe|VITzHhmM;o)`f;OWYO$>7O zcpSPqbSVnSZ2i~ynM*b6eN6=V=ExfzYvgESIn5D#B=iuQ+EO%(R^}=(;un5>1^f00 zVK@@*_$O!KXK?5u<MRpPZ9p2pyH4<Zw^Ryp-}QfNT8M6N+;~va^WMRXIU<b(g69KL z%c5i=7rm^L6-<g@Oe-}O0eJv9;XM`69vhTbGgI=+q7R;x%Eu|;2m1`K*P7sT($==< zxN|#TG#Lm&yF>cV&(Lz;e(F7w9wr#=%zK4ovw(Q%da1_M5sK5+McCvXLtm^6<G?LM zISp|`TK88nx_a@*{RGAMhzQZEpfSbYBo;KJu8Z-NVt3MFxp^rcyFbrO^bIj@f*`~? z7tK%=)s0y4NMLO_<{rJCBGb_)dKZn%OK-gf>*9IfIM;naX#^9c9(-r{>&~Hy;oj!Y zL_wwQo6|}S`}b+bC8Sh?ajlv#4KLh`fT5vSy{nFiIowjk4N)^AYj$U|vOPGx4@1YU zFLt>zqK>uh>hR{=p8V8AP#ulFyzr&6C=e(VnJrXlSpI0ywuWsd)~jVTyz!>C5L1$+ znBHvc$Phpt<pI?p+YiwGs+K|?WjmQ}{HosZ-Zu;eV_P_ziQe$;v=gImqchcB#RhD~ z`vH()GpUT*PD4+OTbP(vsp)S)2}!zA^9-Cycs%P#UxVC-0Uu_b(yvK_@E8t&udY*9 z2#%sZ{QI1LxeN8b0h1(d|K0~zWvo66O(iCIC(u6aLH=9Y^ncHY7Z+N;Om99(rFYdI z5xwYe$q5~Pc*no4X~>CX&9QqHNDmnJQ5l2t=6Aj5oiH7%QS69nqTQ1y)w{WwUNE)N z_}$)~yb<BlFJ9|Kk(Wtom0PYhXULHvsrYjX^vjOdG}<f!M*;#Ixt1*<R-$S<9+6Ky zKVKonSJJPq(%8)%Xv4TKUq33IJcTBUAi`p=JRu(QkTPSa-22g#ux~N?rSxK8JfYn_ z-7^I!<>u@z5u#_7BakRR=P=p1b92&9r(I-@J&F`G1xB~e==d9(X8xJ7g;0EBY#9mj zvKlL5a66`tH?dU`OmPGI%#J|*Z%1!t5y)A@6)+0cAvJTR3vK6Z9d5M^$!ybcE7xa6 zgKz_(6^~+cq3gi%m8)!DeP0NbJu;Y%GP5Tev=jZ_G$Z&R)=n2$om=lbey(2LU|N*< z{8cEY5Ckxbm=mNw#`M0;Q<|HPllJr0%X{|tI_2eNyBK`iAWQF>LG`+U)jxPY@uPYW zBJ9i^9rD_Sq!i^srzcU8KLJymkI9Zw7~k+P6XD;tz$@c}Ss~SKZ~Vro{UnummI%pM z18<|cXCq4#?tn9Xc~bkOMb177Vq{fZP8djR-&-kBP16?Q)_O>O?l8P(lw+7-6$7SO z`oPw+D4Wmk?3f@Uc_oB1muE@W{fU0Ve)X+Pocl1zRBn8^suw#s65JseWcMB>RFd<y zPSR9S+F&*bh%d3ASu@yzQb8&5tct!YL9}mDi6-Rg*9gxGL5@GV$ZW%&HsS$AAv|8& z2V)UWMjLsDWa&R3Se~&aG9T;CD;rQtc8~6S{633YlZh5sWJ&JIz5qe>M$w+LBnW^d zy;H$(R6LS-`3%9WFryfN$Y!lT0M~(cV2XRMbqg~0j<mM64lk(wDtNH2b=QHa=#xYs zUVd7jlEvTv-&pOH9}rOLm!xXk&3s3M4#I7{FAhwbD%k&7IXfVf4CWoT+2APVu6AVr zQx>Jl28SP$!Eudvz5JukD*o4$Zcx83fBza*u8Uln&H=fXjt8BBoXTeU@5Rc;=ohhC z`iNEG!2A<1BmK);57&GzHJj-9w#EexY(#mn*#44<amjZ{Dm(Pt&R!AzM+EjuDqO-n zEExS&&dSM5H#voBcL(0;-Qd~WLO_iF`EQfih!uB_-Hu*`8Xs@<r5loFC>}b?G*PfS zs;MEqRaOA%g6%1P?NJlnD`rS`?)dBdS?2DKxj}n}O|<?^{gj)0cz)`|z;;tk-{zM3 zsHF&lqJGG|Dplq~1<=4nK6XIeCvGWP0PUzC5#+X~%?}?U$hYpm@It|R`0zoUD-e#? m3)e!Hzr(|K{*j0DFRr-3DJ~uw56)SEKWj^Si`%;ovi<;}o|3Qt diff --git a/docs/readme.md b/docs/readme.md deleted file mode 100644 index b584d71e..00000000 --- a/docs/readme.md +++ /dev/null @@ -1,91 +0,0 @@ -# ArduinoBLE library - -This library supports all the Arduino boards that have the hardware enabled for Bluetooth® Low Energy and Bluetooth® 4.0 and above; these include Nano 33 BLE, Arduino NANO 33 IoT, Uno WiFi Rev2, MKR WiFi 1010, Nicla Sense ME. - -To use this library -``#include <ArduinoBLE.h>`` - -## A quick introduction to BLE - -Bluetooth® 4.0 includes both traditional Bluetooth®, now labeled "Bluetooth® Classic", and the Bluetooth® Low Energy. Bluetooth® Low Energy is optimized for low power use at low data rates, and was designed to operate from simple lithium coin cell batteries. - -Unlike standard Bluetooth® communication basically based on an asynchronous serial connection (UART) a Bluetooth® LE radio acts like a community bulletin board. The computers that connect to it are like community members that read the bulletin board. Each radio acts as either the bulletin board or the reader. If your radio is a bulletin board (called a peripheral device in Bluetooth® LE parlance) it posts data for all radios in the community to read. If your radio is a reader (called a central device in Bluetooth LE terms) it reads from any of the bulletin boards (peripheral devices) that have information about which it cares. You can also think of peripheral devices as the servers in a client-server transaction, because they contain the information that reader radios ask for. Similarly, central devices are the clients of the Bluetooth® LE world because they read information available from the peripherals. - - - -Think of a Bluetooth® LE peripheral device as a bulletin board and central devices as viewers of the board. Central devices view the services, get the data, then move on. Each transaction is quick (a few milliseconds), so multiple central devices can get data from one peripheral. - -The information presented by a peripheral is structured as **services**, each of which is subdivided into **characteristics**. You can think of services as the notices on a bulletin board, and characteristics as the individual paragraphs of those notices. If you're a peripheral device, you just update each service characteristic when it needs updating and don't worry about whether the central devices read them or not. If you're a central device, you connect to the peripheral then read the boxes you want. If a given characteristic is readable and writable, then the peripheral and central can both change it. - -## Notify - -The Bluetooth® LE specification includes a mechanism known as **notify** that lets you know when data's changed. When notify on a characteristic is enabled and the sender writes to it, the new value is automatically sent to the receiver, without the receiver explicitly issuing a read command. This is commonly used for streaming data such as accelerometer or other sensor readings. There's a variation on this specification called **indicate** which works similarly, but in the indicate specification, the reader sends an acknowledgment of the pushed data. - -The client-server structure of Bluetooth® LE, combined with the notify characteristic, is generally called a **publish-and-subscribe model**. - -## Update a characteristic - -Your peripheral should update characteristics when there's a significant change to them. For example, when a switch changes from off to on, update its characteristic. When an analog sensor changes by a significant amount, update its characteristic. - -Just as with writing to a characteristic, you could update your characteristics on a regular interval, but this wastes processing power and energy if the characteristic has not changed. - -## Central and Peripheral Devices - -**Central** devices are **clients**. They read and write data from peripheral devices. **Peripheral** devices are **servers**. They provide data from sensors as readable characteristics, and provide read/writable characteristics to control actuators like motors, lights, and so forth. - -## Services, characteristics, and UUIDs - -A Bluetooth® Low Energy peripheral will provide **services**, which in turn provide **characteristics**. You can define your own services, or use standard services (see section 3.4 in the [Assigned Numbers document](https://www.bluetooth.com/specifications/assigned-numbers/)). - -Services are identified by unique numbers known as UUIDs. You know about UUIDs from other contexts. Standard services have a 16-bit UUID and custom services have a 128-bit UUID. The ability to define services and characteristics depends on the radio you're using and its firmware. - -## Service design patterns - -A characteristic value can be up to 512 bytes long. This is a key constraint in designing services. Given this limit, you should consider how best to store data about your sensors and actuators most effectively for your application. The simplest design pattern is to store one sensor or actuator value per characteristic, in ASCII encoded values. - -|**Characteristic**|**Value**| -|------------------|---------| -|Accelerometer X|200| -|Accelerometer Y|134| -|Accelerometer Z|150| - -This is also the most expensive in memory terms, and would take the longest to read. But it's the simplest for development and debugging. - -You could also combine readings into a single characteristic, when a given sensor or actuator has multiple values associated with it. - -|**Characteristic**|**Value**| -|------------------|---------| -|Motor Speed, Direction|150,1| -|Accelerometer X, Y, Z|200,133,150| - -This is more efficient, but you need to be careful not to exceed the 512-byte limit. The accelerometer characteristic above, for example, takes 11 bytes as an ASCII-encoded string. - -## Read/write/notify/indicate - -There are 4 things a central device can do with a characteristic: - -- **Read:** ask the peripheral to send back the current value of the characteristic. Often used for characteristics that don't change very often, for example characteristics used for configuration, version numbers, etc. -- **Write:** modify the value of the characteristic. Often used for things that are like commands, for example telling the peripheral to turn a motor on or off. -- **Indicate** and **Notify:** ask the peripheral to continuously send updated values of the characteristic, without the central having to constantly ask for it. - -## Advertising and GAP - -BLE devices let other devices know that they exist by advertising using the **General Advertising Profile (GAP)**. Advertising packets can contain a device name, some other information, and also a list of the services it provides. - -Advertising packets have a limited size. You will only be able to fit a single 128-bit service UUID in the packet. Make sure the device name is not too long, or you won't even be able to fit that. - -You can provide additional services that are not advertised. Central devices will learn about these through the connection/bonding process. Non-advertised services cannot be used to discover devices, though. Sometimes this is not an issue. For example, you may have a custom peripheral device with a custom service, but in your central device app you may know that it also provides the Battery Service and other services. - -## GATT - -The Bluetooth LE protocol operates on multiple layers. **General Attribute Profile (GATT)** is the layer that defines services and characteristics and enables read/write/notify/indicate operations on them. When reading more about GATT, you may encounter GATT concepts of a "server" and "client". These don't always correspond to central and peripherals. In most cases, though, the peripheral is the GATT server (since it provides the services and characteristics), while the central is the GATT client. - -## Library structure - -As the library enables multiple types of functionality, there are a number of different classes. - -- `BLE` used to enable the Bluetooth® Low Energy module. -- `BLEDevice` used to get information about the devices connected or discovered while scanning. -- `BLEService` used to enable the services board provides or interact with services a remote board provides. -- `BLECharacteristic` used to enable the characteristics board offers in a service or interact with characteristics a remote board provides. -- `BLEDescriptor` used to describe a characteristic the board offers. diff --git a/examples/Central/LedControl/LedControl.ino b/examples/Central/LedControl/LedControl.ino index 953de7d8..064bb29e 100644 --- a/examples/Central/LedControl/LedControl.ino +++ b/examples/Central/LedControl/LedControl.ino @@ -6,9 +6,7 @@ it will remotely control the Bluetooth® Low Energy peripheral's LED, when the button is pressed or released. The circuit: - - Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT, - Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board. - - Button with pull-up resistor connected to pin 2. + - Board with supported BLE modules. You can use it with another board that is compatible with this library and the Peripherals -> LED example. @@ -16,7 +14,7 @@ This example code is in the public domain. */ -#include <ArduinoBLE.h> +#include <STM32duinoBLE.h> // variables for button const int buttonPin = 2; diff --git a/examples/Central/PeripheralExplorer/PeripheralExplorer.ino b/examples/Central/PeripheralExplorer/PeripheralExplorer.ino index 919cdde0..4a72a697 100644 --- a/examples/Central/PeripheralExplorer/PeripheralExplorer.ino +++ b/examples/Central/PeripheralExplorer/PeripheralExplorer.ino @@ -5,8 +5,7 @@ is found. Then connects, and discovers + prints all the peripheral's attributes. The circuit: - - Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT, - Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board. + - Board with supported BLE modules. You can use it with another board that is compatible with this library and the Peripherals -> LED example. @@ -14,7 +13,7 @@ This example code is in the public domain. */ -#include <ArduinoBLE.h> +#include <STM32duinoBLE.h> void setup() { Serial.begin(9600); diff --git a/examples/Central/Scan/Scan.ino b/examples/Central/Scan/Scan.ino index 162e3c07..99e13696 100644 --- a/examples/Central/Scan/Scan.ino +++ b/examples/Central/Scan/Scan.ino @@ -5,13 +5,12 @@ address, local name, advertised service UUID's. The circuit: - - Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT, - Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board. + - Board with supported BLE modules. This example code is in the public domain. */ -#include <ArduinoBLE.h> +#include <STM32duinoBLE.h> void setup() { Serial.begin(9600); diff --git a/examples/Central/ScanCallback/ScanCallback.ino b/examples/Central/ScanCallback/ScanCallback.ino index 2687a3b9..63ab2753 100644 --- a/examples/Central/ScanCallback/ScanCallback.ino +++ b/examples/Central/ScanCallback/ScanCallback.ino @@ -7,13 +7,12 @@ reported for every single advertisement it makes. The circuit: - - Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT, - Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board. + - Board with supported BLE modules. This example code is in the public domain. */ -#include <ArduinoBLE.h> +#include <STM32duinoBLE.h> void setup() { Serial.begin(9600); diff --git a/examples/Central/SensorTagButton/SensorTagButton.ino b/examples/Central/SensorTagButton/SensorTagButton.ino index 27c421fe..26ee667d 100644 --- a/examples/Central/SensorTagButton/SensorTagButton.ino +++ b/examples/Central/SensorTagButton/SensorTagButton.ino @@ -8,14 +8,13 @@ outputted to the Serial Monitor when one is pressed. The circuit: - - Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT, - Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board. + - Board with supported BLE modules. - TI SensorTag This example code is in the public domain. */ -#include <ArduinoBLE.h> +#include <STM32duinoBLE.h> void setup() { Serial.begin(9600); diff --git a/examples/Peripheral/Advertising/EnhancedAdvertising/EnhancedAdvertising.ino b/examples/Peripheral/Advertising/EnhancedAdvertising/EnhancedAdvertising.ino index 979b69a8..806c41bd 100644 --- a/examples/Peripheral/Advertising/EnhancedAdvertising/EnhancedAdvertising.ino +++ b/examples/Peripheral/Advertising/EnhancedAdvertising/EnhancedAdvertising.ino @@ -1,4 +1,4 @@ -#include <ArduinoBLE.h> +#include <STM32duinoBLE.h> BLEService myService("fff0"); BLEIntCharacteristic myCharacteristic("fff1", BLERead | BLEBroadcast); diff --git a/examples/Peripheral/Advertising/RawDataAdvertising/RawDataAdvertising.ino b/examples/Peripheral/Advertising/RawDataAdvertising/RawDataAdvertising.ino index 5e7ba7f3..88b17e29 100644 --- a/examples/Peripheral/Advertising/RawDataAdvertising/RawDataAdvertising.ino +++ b/examples/Peripheral/Advertising/RawDataAdvertising/RawDataAdvertising.ino @@ -1,4 +1,4 @@ -#include <ArduinoBLE.h> +#include <STM32duinoBLE.h> BLEService myService("fff0"); BLEIntCharacteristic myCharacteristic("fff1", BLERead | BLEBroadcast); diff --git a/examples/Peripheral/BatteryMonitor/BatteryMonitor.ino b/examples/Peripheral/BatteryMonitor/BatteryMonitor.ino index 0d786627..3413127e 100644 --- a/examples/Peripheral/BatteryMonitor/BatteryMonitor.ino +++ b/examples/Peripheral/BatteryMonitor/BatteryMonitor.ino @@ -5,8 +5,7 @@ level characteristic. The A0 pin is used to calculate the battery level. The circuit: - - Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT, - Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board. + - Board with supported BLE modules. You can use a generic Bluetooth® Low Energy central app, like LightBlue (iOS and Android) or nRF Connect (Android), to interact with the services and characteristics @@ -15,7 +14,7 @@ This example code is in the public domain. */ -#include <ArduinoBLE.h> +#include <STM32duinoBLE.h> // Bluetooth® Low Energy Battery Service BLEService batteryService("180F"); diff --git a/examples/Peripheral/ButtonLED/ButtonLED.ino b/examples/Peripheral/ButtonLED/ButtonLED.ino index cbc14dd8..baa64b87 100644 --- a/examples/Peripheral/ButtonLED/ButtonLED.ino +++ b/examples/Peripheral/ButtonLED/ButtonLED.ino @@ -6,9 +6,7 @@ represents the state of the button. The circuit: - - Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT, - Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board. - - Button connected to pin 4 + - Board with supported BLE modules. You can use a generic Bluetooth® Low Energy central app, like LightBlue (iOS and Android) or nRF Connect (Android), to interact with the services and characteristics @@ -17,7 +15,7 @@ This example code is in the public domain. */ -#include <ArduinoBLE.h> +#include <STM32duinoBLE.h> const int ledPin = LED_BUILTIN; // set ledPin to on-board LED const int buttonPin = 4; // set buttonPin to digital pin 4 diff --git a/examples/Peripheral/CallbackLED/CallbackLED.ino b/examples/Peripheral/CallbackLED/CallbackLED.ino index 59bda5ed..8bb90106 100644 --- a/examples/Peripheral/CallbackLED/CallbackLED.ino +++ b/examples/Peripheral/CallbackLED/CallbackLED.ino @@ -6,8 +6,7 @@ library are used. The circuit: - - Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT, - Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board. + - Board with supported BLE modules. You can use a generic Bluetooth® Low Energy central app, like LightBlue (iOS and Android) or nRF Connect (Android), to interact with the services and characteristics @@ -16,7 +15,7 @@ This example code is in the public domain. */ -#include <ArduinoBLE.h> +#include <STM32duinoBLE.h> BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // create service diff --git a/examples/Peripheral/EncryptedBatteryMonitor/EncryptedBatteryMonitor.ino b/examples/Peripheral/EncryptedBatteryMonitor/EncryptedBatteryMonitor.ino deleted file mode 100644 index dfc9f4a0..00000000 --- a/examples/Peripheral/EncryptedBatteryMonitor/EncryptedBatteryMonitor.ino +++ /dev/null @@ -1,265 +0,0 @@ -/* - Battery Monitor - - This example creates a BLE peripheral with the standard battery service and - level characteristic. The A0 pin is used to calculate the battery level. - - The circuit: - - Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT, - Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board. - - You can use a generic BLE central app, like LightBlue (iOS and Android) or - nRF Connect (Android), to interact with the services and characteristics - created in this sketch. - - This example code is in the public domain. -*/ - -#include <ArduinoBLE.h> - - -#define PAIR_BUTTON 3 // button for pairing -#define PAIR_LED 24 // LED used to signal pairing -#define PAIR_LED_ON LOW // Blue LED on Nano BLE has inverted logic -#define PAIR_INTERVAL 30000 // interval for pairing after button press in ms - -#define CTRL_LED LED_BUILTIN - - - // BLE Battery Service -BLEService batteryService("180F"); - -// BLE Battery Level Characteristic -BLEUnsignedCharCharacteristic batteryLevelChar("2A19", // standard 16-bit characteristic UUID - BLERead | BLENotify); // remote clients will be able to get notifications if this characteristic changes -BLEStringCharacteristic stringcharacteristic("183E", BLERead | BLEWrite, 31); - - -// Add BLEEncryption tag to require pairing. This controls the LED. -BLEUnsignedCharCharacteristic secretValue("2a3F", BLERead | BLEWrite | BLEEncryption); - -int oldBatteryLevel = 0; // last battery level reading from analog input -unsigned long previousMillis = 0; // last time the battery level was checked, in ms -unsigned long pairingStarted = 0; // pairing start time when button is pressed -bool wasConnected = 0; -bool acceptOrReject = true; - -void setup() { - Serial.begin(9600); // initialize serial communication - while (!Serial); - - pinMode(CTRL_LED, OUTPUT); // initialize the built-in LED pin to indicate when a central is connected - pinMode(PAIR_LED, OUTPUT); - pinMode(PAIR_BUTTON, INPUT_PULLUP); - - - Serial.println("Serial connected"); - - // Callback function with confirmation code when new device is pairing. - BLE.setDisplayCode([](uint32_t confirmCode){ - Serial.println("New device pairing request."); - Serial.print("Confirm code matches pairing device: "); - char code[6]; - sprintf(code, "%06d", confirmCode); - Serial.println(code); - }); - - // Callback to allow accepting or rejecting pairing - BLE.setBinaryConfirmPairing([&acceptOrReject](){ - Serial.print("Should we confirm pairing? "); - delay(5000); - if(acceptOrReject){ - acceptOrReject = false; - Serial.println("yes"); - return true; - }else{ - acceptOrReject = true; - Serial.println("no"); - return false; - } - }); - - // IRKs are keys that identify the true owner of a random mac address. - // Add IRKs of devices you are bonded with. - BLE.setGetIRKs([](uint8_t* nIRKs, uint8_t** BDaddrTypes, uint8_t*** BDAddrs, uint8_t*** IRKs){ - // Set to number of devices - *nIRKs = 2; - - *BDAddrs = new uint8_t*[*nIRKs]; - *IRKs = new uint8_t*[*nIRKs]; - *BDaddrTypes = new uint8_t[*nIRKs]; - - // Set these to the mac and IRK for your bonded devices as printed in the serial console after bonding. - uint8_t device1Mac[6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - uint8_t device1IRK[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - - uint8_t device2Mac[6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - uint8_t device2IRK[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - - - (*BDaddrTypes)[0] = 0; // Type 0 is for pubc address, type 1 is for static random - (*BDAddrs)[0] = new uint8_t[6]; - (*IRKs)[0] = new uint8_t[16]; - memcpy((*IRKs)[0] , device1IRK,16); - memcpy((*BDAddrs)[0], device1Mac, 6); - - - (*BDaddrTypes)[1] = 0; - (*BDAddrs)[1] = new uint8_t[6]; - (*IRKs)[1] = new uint8_t[16]; - memcpy((*IRKs)[1] , device2IRK,16); - memcpy((*BDAddrs)[1], device2Mac, 6); - - - return 1; - }); - // The LTK is the secret key which is used to encrypt bluetooth traffic - BLE.setGetLTK([](uint8_t* address, uint8_t* LTK){ - // address is input - Serial.print("Received request for address: "); - btct.printBytes(address,6); - - // Set these to the MAC and LTK of your devices after bonding. - uint8_t device1Mac[6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - uint8_t device1LTK[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - uint8_t device2Mac[6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - uint8_t device2LTK[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - - - if(memcmp(device1Mac, address, 6) == 0) { - memcpy(LTK, device1LTK, 16); - return 1; - }else if(memcmp(device2Mac, address, 6) == 0) { - memcpy(LTK, device2LTK, 16); - return 1; - } - return 0; - }); - BLE.setStoreIRK([](uint8_t* address, uint8_t* IRK){ - Serial.print(F("New device with MAC : ")); - btct.printBytes(address,6); - Serial.print(F("Need to store IRK : ")); - btct.printBytes(IRK,16); - return 1; - }); - BLE.setStoreLTK([](uint8_t* address, uint8_t* LTK){ - Serial.print(F("New device with MAC : ")); - btct.printBytes(address,6); - Serial.print(F("Need to store LTK : ")); - btct.printBytes(LTK,16); - return 1; - }); - - while(1){ - // begin initialization - if (!BLE.begin()) { - Serial.println("starting BLE failed!"); - delay(200); - continue; - } - Serial.println("BT init"); - delay(200); - - /* Set a local name for the BLE device - This name will appear in advertising packets - and can be used by remote devices to identify this BLE device - The name can be changed but maybe be truncated based on space left in advertisement packet - */ - - BLE.setDeviceName("Arduino"); - BLE.setLocalName("BatteryMonitor"); - - BLE.setAdvertisedService(batteryService); // add the service UUID - batteryService.addCharacteristic(batteryLevelChar); // add the battery level characteristic - batteryService.addCharacteristic(stringcharacteristic); - batteryService.addCharacteristic(secretValue); - - BLE.addService(batteryService); // Add the battery service - batteryLevelChar.writeValue(oldBatteryLevel); // set initial value for this characteristic - char* stringCharValue = new char[32]; - stringCharValue = "string"; - stringcharacteristic.writeValue(stringCharValue); - secretValue.writeValue(0); - - delay(1000); - - // prevent pairing until button is pressed (will show a pairing rejected message) - BLE.setPairable(false); - - /* Start advertising BLE. It will start continuously transmitting BLE - advertising packets and will be visible to remote BLE central devices - until it receives a new connection */ - - // start advertising - if(!BLE.advertise()){ - Serial.println("failed to advertise bluetooth."); - BLE.stopAdvertise(); - delay(500); - }else{ - Serial.println("advertising..."); - break; - } - BLE.end(); - delay(100); - } -} - - -void loop() { - // wait for a BLE central - BLEDevice central = BLE.central(); - - - // If button is pressed, allow pairing for 30 sec - if (!BLE.pairable() && digitalRead(PAIR_BUTTON) == LOW){ - pairingStarted = millis(); - BLE.setPairable(Pairable::ONCE); - Serial.println("Accepting pairing for 30 s"); - } else if (BLE.pairable() && millis() > pairingStarted + PAIR_INTERVAL){ - BLE.setPairable(false); - Serial.println("No longer accepting pairing"); - } - // Make LED blink while pairing is allowed - digitalWrite(PAIR_LED, (BLE.pairable() ? (millis()%400)<200 : BLE.paired()) ? PAIR_LED_ON : !PAIR_LED_ON); - - - // if a central is connected to the peripheral: - if (central && central.connected()) { - if (!wasConnected){ - wasConnected = true; - Serial.print("Connected to central: "); - // print the central's BT address: - Serial.println(central.address()); - } - - // check the battery level every 200ms - // while the central is connected: - long currentMillis = millis(); - // if 200ms have passed, check the battery level: - if (currentMillis - previousMillis >= 1000) { - previousMillis = currentMillis; - updateBatteryLevel(); - digitalWrite(CTRL_LED, secretValue.value()>0 ? HIGH : LOW); - } - } else if (wasConnected){ - wasConnected = false; - Serial.print("Disconnected from central: "); - Serial.println(central.address()); - } - -} - -void updateBatteryLevel() { - /* Read the current voltage level on the A0 analog input pin. - This is used here to simulate the charge level of a battery. - */ - int battery = analogRead(A0); - int batteryLevel = map(battery, 0, 1023, 0, 100); - - if (batteryLevel != oldBatteryLevel) { // if the battery level has changed - // Serial.print("Battery Level % is now: "); // print it - // Serial.println(batteryLevel); - batteryLevelChar.writeValue(batteryLevel); // and update the battery level characteristic - oldBatteryLevel = batteryLevel; // save the level for next comparison - } -} \ No newline at end of file diff --git a/examples/Peripheral/LED/LED.ino b/examples/Peripheral/LED/LED.ino index 65b88605..7223365f 100644 --- a/examples/Peripheral/LED/LED.ino +++ b/examples/Peripheral/LED/LED.ino @@ -5,8 +5,7 @@ characteristic to control an LED. The circuit: - - Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT, - Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board. + - Board with supported BLE modules. You can use a generic Bluetooth® Low Energy central app, like LightBlue (iOS and Android) or nRF Connect (Android), to interact with the services and characteristics @@ -15,7 +14,7 @@ This example code is in the public domain. */ -#include <ArduinoBLE.h> +#include <STM32duinoBLE.h> BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // Bluetooth® Low Energy LED Service diff --git a/extras/arduino-ble-parser.py b/extras/arduino-ble-parser.py deleted file mode 100644 index 8f678711..00000000 --- a/extras/arduino-ble-parser.py +++ /dev/null @@ -1,85 +0,0 @@ -''' -Convert ArduinoBLE debug files into Btsnoop files ready to be analyzed using wireshark or hcidump -Btsnoop file format reference - https://www.fte.com/WebHelpII/Sodera/Content/Technical_Information/BT_Snoop_File_Format.htm -''' - -import os -import argparse - -DEBUG = False - -parser = argparse.ArgumentParser() -parser.add_argument('-i', dest='inputPath', type=str, required=True, help='input file containing debug log') -parser.add_argument('-o', dest='outputPath', type=str, required=True, help='result file that will contain the btsnoop encoded debug file') -args = parser.parse_args() - -# Extract only hci debug messages -def extractHCIDebugPrint(inputPath, outputPath): - inputFile = open(inputPath, 'r') - outputFile = open(outputPath, 'w') - for inputLine in inputFile: - lineItems = inputLine.split() - if (len(lineItems) < 7) or (lineItems[1] != "->") or (lineItems[2] != "HCI"): - if (len(lineItems) < 4) or (lineItems[0] != "HCI") or ((lineItems[3] != "<-") and (lineItems[3] != "->")): - continue - outputFile.write(inputLine) - outputFile.close() - -# Return packet in btsnoop format -def buildBinaryPacket(hciMessage, hciDirection, hciType): - commandFlag = 1 if (hciType == "COMMAND" or hciType == "EVENT") else 0 - directionFlag = 0 if (hciDirection == "TX") else 1 - flagHex = ("0" * 7) + str((commandFlag * 2) + directionFlag) - timestampHex = "0" * 16 - packetDropHex = "0" * 8 - dataLengthHex = format( (int(len(hciMessage) / 2)), 'x') - packetLengthHex = ("0" * (8 - len(dataLengthHex))) + dataLengthHex - binaryPacket = bytearray.fromhex(packetLengthHex + packetLengthHex + flagHex + packetDropHex + timestampHex + hciMessage) - if DEBUG: - print(len(hciMessage)) - print(dataLengthHex) - print(packetLengthHex) - print(flagHex) - print('\n') - return binaryPacket - -def buildBinaryHeader(): - defaultHeader = "6274736e6f6f700000000001000003ea" - binaryHeader = bytearray.fromhex(defaultHeader) - return binaryHeader - -def convertToBtsnoop(inputPath, outputPath): - # Open output file and write the Btsnoop header - outputFile = open(outputPath,'wb') - header = buildBinaryHeader() - outputFile.write(header) - - # Open input file containing HCI debug packets - inputFile = open(inputPath, 'r') - for inputLine in inputFile: - lineItems = inputLine.split() - # For a safer script, do not use indexes but look for symbols in the line - baseIndex = lineItems.index("HCI") - hciMessage = lineItems[baseIndex + 4] - hciDirection = lineItems[baseIndex + 2] - hciType = lineItems[baseIndex + 1] - # Build and write the encoded line - btsnoopPacket = buildBinaryPacket(hciMessage, hciDirection, hciType) - outputFile.write(btsnoopPacket) - if DEBUG: - print(hciDirection) - print(hciMessage) - print(hciType) - print('\n') - outputFile.close() - -inputPath = args.inputPath -outputPath = args.outputPath -tempFile = "temp-debug-print.txt" -# Run -extractHCIDebugPrint(inputPath,tempFile) -convertToBtsnoop(tempFile, outputPath) -# Delete temp file -os.remove(tempFile) - diff --git a/extras/test/.gitignore b/extras/test/.gitignore deleted file mode 100644 index c795b054..00000000 --- a/extras/test/.gitignore +++ /dev/null @@ -1 +0,0 @@ -build \ No newline at end of file diff --git a/extras/test/CMakeLists.txt b/extras/test/CMakeLists.txt deleted file mode 100644 index bbba16ca..00000000 --- a/extras/test/CMakeLists.txt +++ /dev/null @@ -1,126 +0,0 @@ -########################################################################## - -set(CMAKE_VERBOSE_MAKEFILE ON) -cmake_minimum_required(VERSION 2.8) - -########################################################################## - -project(testArduinoBLE) - -########################################################################## - -set(CMAKE_CXX_STANDARD 11) -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) - -########################################################################## - -set(COMMON_TEST_SRCS - src/test_main.cpp - src/Arduino.cpp - src/util/itoa.c - src/util/TestUtil.cpp - src/util/String.cpp - src/util/Common.cpp -) - -set(DUT_SRCS - ../../src/utility/BLEUuid.cpp - ../../src/BLEDevice.cpp - ../../src/BLECharacteristic.cpp - ../../src/BLEDescriptor.cpp - ../../src/BLEService.cpp - ../../src/BLEAdvertisingData.cpp - ../../src/utility/ATT.cpp - ../../src/utility/GAP.cpp - ../../src/utility/HCI.cpp - ../../src/utility/GATT.cpp - ../../src/utility/L2CAPSignaling.cpp - ../../src/local/BLELocalAttribute.cpp - ../../src/local/BLELocalCharacteristic.cpp - ../../src/local/BLELocalDescriptor.cpp - ../../src/local/BLELocalDevice.cpp - ../../src/local/BLELocalService.cpp - ../../src/remote/BLERemoteAttribute.cpp - ../../src/remote/BLERemoteCharacteristic.cpp - ../../src/remote/BLERemoteDescriptor.cpp - ../../src/remote/BLERemoteDevice.cpp - ../../src/remote/BLERemoteService.cpp - ../../src/BLEStringCharacteristic.cpp - ../../src/BLETypedCharacteristics.cpp -) - -set(TEST_TARGET_UUID_SRCS - # Test files - ${COMMON_TEST_SRCS} - src/test_uuid/test_uuid.cpp - # DUT files - #${DUT_SRCS} - ../../src/utility/BLEUuid.cpp -) - -set(TEST_TARGET_DISC_DEVICE_SRCS - # Test files - ${COMMON_TEST_SRCS} - src/test_discovered_device/test_discovered_device.cpp - # DUT files - ${DUT_SRCS} - # Fake classes files - src/util/HCIFakeTransport.cpp - src/test_discovered_device/FakeGAP.cpp -) - -set(TEST_TARGET_ADVERTISING_DATA_SRCS - # Test files - ${COMMON_TEST_SRCS} - src/test_advertising_data/test_advertising_data.cpp - src/test_advertising_data/test_service.cpp - src/test_advertising_data/test_local_name.cpp - src/test_advertising_data/test_manufacturer.cpp - # DUT files - ${DUT_SRCS} - # Fake classes files - src/util/HCIFakeTransport.cpp - src/test_advertising_data/FakeBLELocalDevice.cpp -) - -########################################################################## - -set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} "--coverage") -set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "--coverage") - -########################################################################## - -add_executable(TEST_TARGET_UUID ${TEST_TARGET_UUID_SRCS}) -add_executable(TEST_TARGET_DISC_DEVICE ${TEST_TARGET_DISC_DEVICE_SRCS}) -add_executable(TEST_TARGET_ADVERTISING_DATA ${TEST_TARGET_ADVERTISING_DATA_SRCS}) - -########################################################################## - -include_directories(include) -include_directories(include/util) -include_directories(../../src) -include_directories(../../src/local) -include_directories(../../src/remote) -include_directories(../../src/utility) -include_directories(external/catch/v2.12.1/include) - -target_include_directories(TEST_TARGET_DISC_DEVICE PUBLIC include/test_discovered_device) -target_include_directories(TEST_TARGET_ADVERTISING_DATA PUBLIC include/test_advertising_data) - -########################################################################## - -target_compile_definitions(TEST_TARGET_DISC_DEVICE PUBLIC FAKE_GAP) -target_compile_definitions(TEST_TARGET_ADVERTISING_DATA PUBLIC FAKE_BLELOCALDEVICE) - -########################################################################## - -# Build unit tests as a post build step -add_custom_command(TARGET TEST_TARGET_UUID POST_BUILD - COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/TEST_TARGET_UUID -) -add_custom_command(TARGET TEST_TARGET_DISC_DEVICE POST_BUILD - COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/TEST_TARGET_DISC_DEVICE -) -add_custom_command(TARGET TEST_TARGET_ADVERTISING_DATA POST_BUILD - COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/TEST_TARGET_ADVERTISING_DATA -) diff --git a/extras/test/external/catch/v2.12.1/include/catch.hpp b/extras/test/external/catch/v2.12.1/include/catch.hpp deleted file mode 100644 index 1d2c9bb6..00000000 --- a/extras/test/external/catch/v2.12.1/include/catch.hpp +++ /dev/null @@ -1,17698 +0,0 @@ -/* - * Catch v2.12.1 - * Generated: 2020-04-21 19:29:20.964532 - * ---------------------------------------------------------- - * This file has been merged from multiple headers. Please don't edit it directly - * Copyright (c) 2020 Two Blue Cubes Ltd. All rights reserved. - * - * Distributed under the Boost Software License, Version 1.0. (See accompanying - * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - */ -#ifndef TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED -#define TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED -// start catch.hpp - - -#define CATCH_VERSION_MAJOR 2 -#define CATCH_VERSION_MINOR 12 -#define CATCH_VERSION_PATCH 1 - -#ifdef __clang__ -# pragma clang system_header -#elif defined __GNUC__ -# pragma GCC system_header -#endif - -// start catch_suppress_warnings.h - -#ifdef __clang__ -# ifdef __ICC // icpc defines the __clang__ macro -# pragma warning(push) -# pragma warning(disable: 161 1682) -# else // __ICC -# pragma clang diagnostic push -# pragma clang diagnostic ignored "-Wpadded" -# pragma clang diagnostic ignored "-Wswitch-enum" -# pragma clang diagnostic ignored "-Wcovered-switch-default" -# endif -#elif defined __GNUC__ - // Because REQUIREs trigger GCC's -Wparentheses, and because still - // supported version of g++ have only buggy support for _Pragmas, - // Wparentheses have to be suppressed globally. -# pragma GCC diagnostic ignored "-Wparentheses" // See #674 for details - -# pragma GCC diagnostic push -# pragma GCC diagnostic ignored "-Wunused-variable" -# pragma GCC diagnostic ignored "-Wpadded" -#endif -// end catch_suppress_warnings.h -#if defined(CATCH_CONFIG_MAIN) || defined(CATCH_CONFIG_RUNNER) -# define CATCH_IMPL -# define CATCH_CONFIG_ALL_PARTS -#endif - -// In the impl file, we want to have access to all parts of the headers -// Can also be used to sanely support PCHs -#if defined(CATCH_CONFIG_ALL_PARTS) -# define CATCH_CONFIG_EXTERNAL_INTERFACES -# if defined(CATCH_CONFIG_DISABLE_MATCHERS) -# undef CATCH_CONFIG_DISABLE_MATCHERS -# endif -# if !defined(CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER) -# define CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER -# endif -#endif - -#if !defined(CATCH_CONFIG_IMPL_ONLY) -// start catch_platform.h - -#ifdef __APPLE__ -# include <TargetConditionals.h> -# if TARGET_OS_OSX == 1 -# define CATCH_PLATFORM_MAC -# elif TARGET_OS_IPHONE == 1 -# define CATCH_PLATFORM_IPHONE -# endif - -#elif defined(linux) || defined(__linux) || defined(__linux__) -# define CATCH_PLATFORM_LINUX - -#elif defined(WIN32) || defined(__WIN32__) || defined(_WIN32) || defined(_MSC_VER) || defined(__MINGW32__) -# define CATCH_PLATFORM_WINDOWS -#endif - -// end catch_platform.h - -#ifdef CATCH_IMPL -# ifndef CLARA_CONFIG_MAIN -# define CLARA_CONFIG_MAIN_NOT_DEFINED -# define CLARA_CONFIG_MAIN -# endif -#endif - -// start catch_user_interfaces.h - -namespace Catch { - unsigned int rngSeed(); -} - -// end catch_user_interfaces.h -// start catch_tag_alias_autoregistrar.h - -// start catch_common.h - -// start catch_compiler_capabilities.h - -// Detect a number of compiler features - by compiler -// The following features are defined: -// -// CATCH_CONFIG_COUNTER : is the __COUNTER__ macro supported? -// CATCH_CONFIG_WINDOWS_SEH : is Windows SEH supported? -// CATCH_CONFIG_POSIX_SIGNALS : are POSIX signals supported? -// CATCH_CONFIG_DISABLE_EXCEPTIONS : Are exceptions enabled? -// **************** -// Note to maintainers: if new toggles are added please document them -// in configuration.md, too -// **************** - -// In general each macro has a _NO_<feature name> form -// (e.g. CATCH_CONFIG_NO_POSIX_SIGNALS) which disables the feature. -// Many features, at point of detection, define an _INTERNAL_ macro, so they -// can be combined, en-mass, with the _NO_ forms later. - -#ifdef __cplusplus - -# if (__cplusplus >= 201402L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 201402L) -# define CATCH_CPP14_OR_GREATER -# endif - -# if (__cplusplus >= 201703L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) -# define CATCH_CPP17_OR_GREATER -# endif - -#endif - -#if defined(__cpp_lib_uncaught_exceptions) -# define CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS -#endif - -// We have to avoid both ICC and Clang, because they try to mask themselves -// as gcc, and we want only GCC in this block -#if defined(__GNUC__) && !defined(__clang__) && !defined(__ICC) -# define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION _Pragma( "GCC diagnostic push" ) -# define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION _Pragma( "GCC diagnostic pop" ) - -# define CATCH_INTERNAL_IGNORE_BUT_WARN(...) (void)__builtin_constant_p(__VA_ARGS__) - -#endif - -#if defined(__clang__) - -# define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION _Pragma( "clang diagnostic push" ) -# define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION _Pragma( "clang diagnostic pop" ) - -// As of this writing, IBM XL's implementation of __builtin_constant_p has a bug -// which results in calls to destructors being emitted for each temporary, -// without a matching initialization. In practice, this can result in something -// like `std::string::~string` being called on an uninitialized value. -// -// For example, this code will likely segfault under IBM XL: -// ``` -// REQUIRE(std::string("12") + "34" == "1234") -// ``` -// -// Therefore, `CATCH_INTERNAL_IGNORE_BUT_WARN` is not implemented. -# if !defined(__ibmxl__) -# define CATCH_INTERNAL_IGNORE_BUT_WARN(...) (void)__builtin_constant_p(__VA_ARGS__) /* NOLINT(cppcoreguidelines-pro-type-vararg) */ -# endif - -# define CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ - _Pragma( "clang diagnostic ignored \"-Wexit-time-destructors\"" ) \ - _Pragma( "clang diagnostic ignored \"-Wglobal-constructors\"") - -# define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \ - _Pragma( "clang diagnostic ignored \"-Wparentheses\"" ) - -# define CATCH_INTERNAL_SUPPRESS_UNUSED_WARNINGS \ - _Pragma( "clang diagnostic ignored \"-Wunused-variable\"" ) - -# define CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS \ - _Pragma( "clang diagnostic ignored \"-Wgnu-zero-variadic-macro-arguments\"" ) - -# define CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \ - _Pragma( "clang diagnostic ignored \"-Wunused-template\"" ) - -#endif // __clang__ - -//////////////////////////////////////////////////////////////////////////////// -// Assume that non-Windows platforms support posix signals by default -#if !defined(CATCH_PLATFORM_WINDOWS) - #define CATCH_INTERNAL_CONFIG_POSIX_SIGNALS -#endif - -//////////////////////////////////////////////////////////////////////////////// -// We know some environments not to support full POSIX signals -#if defined(__CYGWIN__) || defined(__QNX__) || defined(__EMSCRIPTEN__) || defined(__DJGPP__) - #define CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS -#endif - -#ifdef __OS400__ -# define CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS -# define CATCH_CONFIG_COLOUR_NONE -#endif - -//////////////////////////////////////////////////////////////////////////////// -// Android somehow still does not support std::to_string -#if defined(__ANDROID__) -# define CATCH_INTERNAL_CONFIG_NO_CPP11_TO_STRING -# define CATCH_INTERNAL_CONFIG_ANDROID_LOGWRITE -#endif - -//////////////////////////////////////////////////////////////////////////////// -// Not all Windows environments support SEH properly -#if defined(__MINGW32__) -# define CATCH_INTERNAL_CONFIG_NO_WINDOWS_SEH -#endif - -//////////////////////////////////////////////////////////////////////////////// -// PS4 -#if defined(__ORBIS__) -# define CATCH_INTERNAL_CONFIG_NO_NEW_CAPTURE -#endif - -//////////////////////////////////////////////////////////////////////////////// -// Cygwin -#ifdef __CYGWIN__ - -// Required for some versions of Cygwin to declare gettimeofday -// see: http://stackoverflow.com/questions/36901803/gettimeofday-not-declared-in-this-scope-cygwin -# define _BSD_SOURCE -// some versions of cygwin (most) do not support std::to_string. Use the libstd check. -// https://gcc.gnu.org/onlinedocs/gcc-4.8.2/libstdc++/api/a01053_source.html line 2812-2813 -# if !((__cplusplus >= 201103L) && defined(_GLIBCXX_USE_C99) \ - && !defined(_GLIBCXX_HAVE_BROKEN_VSWPRINTF)) - -# define CATCH_INTERNAL_CONFIG_NO_CPP11_TO_STRING - -# endif -#endif // __CYGWIN__ - -//////////////////////////////////////////////////////////////////////////////// -// Visual C++ -#if defined(_MSC_VER) - -# define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION __pragma( warning(push) ) -# define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION __pragma( warning(pop) ) - -# if _MSC_VER >= 1900 // Visual Studio 2015 or newer -# define CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS -# endif - -// Universal Windows platform does not support SEH -// Or console colours (or console at all...) -# if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_APP) -# define CATCH_CONFIG_COLOUR_NONE -# else -# define CATCH_INTERNAL_CONFIG_WINDOWS_SEH -# endif - -// MSVC traditional preprocessor needs some workaround for __VA_ARGS__ -// _MSVC_TRADITIONAL == 0 means new conformant preprocessor -// _MSVC_TRADITIONAL == 1 means old traditional non-conformant preprocessor -# if !defined(__clang__) // Handle Clang masquerading for msvc -# if !defined(_MSVC_TRADITIONAL) || (defined(_MSVC_TRADITIONAL) && _MSVC_TRADITIONAL) -# define CATCH_INTERNAL_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR -# endif // MSVC_TRADITIONAL -# endif // __clang__ - -#endif // _MSC_VER - -#if defined(_REENTRANT) || defined(_MSC_VER) -// Enable async processing, as -pthread is specified or no additional linking is required -# define CATCH_INTERNAL_CONFIG_USE_ASYNC -#endif // _MSC_VER - -//////////////////////////////////////////////////////////////////////////////// -// Check if we are compiled with -fno-exceptions or equivalent -#if defined(__EXCEPTIONS) || defined(__cpp_exceptions) || defined(_CPPUNWIND) -# define CATCH_INTERNAL_CONFIG_EXCEPTIONS_ENABLED -#endif - -//////////////////////////////////////////////////////////////////////////////// -// DJGPP -#ifdef __DJGPP__ -# define CATCH_INTERNAL_CONFIG_NO_WCHAR -#endif // __DJGPP__ - -//////////////////////////////////////////////////////////////////////////////// -// Embarcadero C++Build -#if defined(__BORLANDC__) - #define CATCH_INTERNAL_CONFIG_POLYFILL_ISNAN -#endif - -//////////////////////////////////////////////////////////////////////////////// - -// Use of __COUNTER__ is suppressed during code analysis in -// CLion/AppCode 2017.2.x and former, because __COUNTER__ is not properly -// handled by it. -// Otherwise all supported compilers support COUNTER macro, -// but user still might want to turn it off -#if ( !defined(__JETBRAINS_IDE__) || __JETBRAINS_IDE__ >= 20170300L ) - #define CATCH_INTERNAL_CONFIG_COUNTER -#endif - -//////////////////////////////////////////////////////////////////////////////// - -// RTX is a special version of Windows that is real time. -// This means that it is detected as Windows, but does not provide -// the same set of capabilities as real Windows does. -#if defined(UNDER_RTSS) || defined(RTX64_BUILD) - #define CATCH_INTERNAL_CONFIG_NO_WINDOWS_SEH - #define CATCH_INTERNAL_CONFIG_NO_ASYNC - #define CATCH_CONFIG_COLOUR_NONE -#endif - -#if !defined(_GLIBCXX_USE_C99_MATH_TR1) -#define CATCH_INTERNAL_CONFIG_GLOBAL_NEXTAFTER -#endif - -// Various stdlib support checks that require __has_include -#if defined(__has_include) - // Check if string_view is available and usable - #if __has_include(<string_view>) && defined(CATCH_CPP17_OR_GREATER) - # define CATCH_INTERNAL_CONFIG_CPP17_STRING_VIEW - #endif - - // Check if optional is available and usable - # if __has_include(<optional>) && defined(CATCH_CPP17_OR_GREATER) - # define CATCH_INTERNAL_CONFIG_CPP17_OPTIONAL - # endif // __has_include(<optional>) && defined(CATCH_CPP17_OR_GREATER) - - // Check if byte is available and usable - # if __has_include(<cstddef>) && defined(CATCH_CPP17_OR_GREATER) - # define CATCH_INTERNAL_CONFIG_CPP17_BYTE - # endif // __has_include(<cstddef>) && defined(CATCH_CPP17_OR_GREATER) - - // Check if variant is available and usable - # if __has_include(<variant>) && defined(CATCH_CPP17_OR_GREATER) - # if defined(__clang__) && (__clang_major__ < 8) - // work around clang bug with libstdc++ https://bugs.llvm.org/show_bug.cgi?id=31852 - // fix should be in clang 8, workaround in libstdc++ 8.2 - # include <ciso646> - # if defined(__GLIBCXX__) && defined(_GLIBCXX_RELEASE) && (_GLIBCXX_RELEASE < 9) - # define CATCH_CONFIG_NO_CPP17_VARIANT - # else - # define CATCH_INTERNAL_CONFIG_CPP17_VARIANT - # endif // defined(__GLIBCXX__) && defined(_GLIBCXX_RELEASE) && (_GLIBCXX_RELEASE < 9) - # else - # define CATCH_INTERNAL_CONFIG_CPP17_VARIANT - # endif // defined(__clang__) && (__clang_major__ < 8) - # endif // __has_include(<variant>) && defined(CATCH_CPP17_OR_GREATER) -#endif // defined(__has_include) - -#if defined(CATCH_INTERNAL_CONFIG_COUNTER) && !defined(CATCH_CONFIG_NO_COUNTER) && !defined(CATCH_CONFIG_COUNTER) -# define CATCH_CONFIG_COUNTER -#endif -#if defined(CATCH_INTERNAL_CONFIG_WINDOWS_SEH) && !defined(CATCH_CONFIG_NO_WINDOWS_SEH) && !defined(CATCH_CONFIG_WINDOWS_SEH) && !defined(CATCH_INTERNAL_CONFIG_NO_WINDOWS_SEH) -# define CATCH_CONFIG_WINDOWS_SEH -#endif -// This is set by default, because we assume that unix compilers are posix-signal-compatible by default. -#if defined(CATCH_INTERNAL_CONFIG_POSIX_SIGNALS) && !defined(CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS) && !defined(CATCH_CONFIG_NO_POSIX_SIGNALS) && !defined(CATCH_CONFIG_POSIX_SIGNALS) -# define CATCH_CONFIG_POSIX_SIGNALS -#endif -// This is set by default, because we assume that compilers with no wchar_t support are just rare exceptions. -#if !defined(CATCH_INTERNAL_CONFIG_NO_WCHAR) && !defined(CATCH_CONFIG_NO_WCHAR) && !defined(CATCH_CONFIG_WCHAR) -# define CATCH_CONFIG_WCHAR -#endif - -#if !defined(CATCH_INTERNAL_CONFIG_NO_CPP11_TO_STRING) && !defined(CATCH_CONFIG_NO_CPP11_TO_STRING) && !defined(CATCH_CONFIG_CPP11_TO_STRING) -# define CATCH_CONFIG_CPP11_TO_STRING -#endif - -#if defined(CATCH_INTERNAL_CONFIG_CPP17_OPTIONAL) && !defined(CATCH_CONFIG_NO_CPP17_OPTIONAL) && !defined(CATCH_CONFIG_CPP17_OPTIONAL) -# define CATCH_CONFIG_CPP17_OPTIONAL -#endif - -#if defined(CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS) && !defined(CATCH_CONFIG_NO_CPP17_UNCAUGHT_EXCEPTIONS) && !defined(CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS) -# define CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS -#endif - -#if defined(CATCH_INTERNAL_CONFIG_CPP17_STRING_VIEW) && !defined(CATCH_CONFIG_NO_CPP17_STRING_VIEW) && !defined(CATCH_CONFIG_CPP17_STRING_VIEW) -# define CATCH_CONFIG_CPP17_STRING_VIEW -#endif - -#if defined(CATCH_INTERNAL_CONFIG_CPP17_VARIANT) && !defined(CATCH_CONFIG_NO_CPP17_VARIANT) && !defined(CATCH_CONFIG_CPP17_VARIANT) -# define CATCH_CONFIG_CPP17_VARIANT -#endif - -#if defined(CATCH_INTERNAL_CONFIG_CPP17_BYTE) && !defined(CATCH_CONFIG_NO_CPP17_BYTE) && !defined(CATCH_CONFIG_CPP17_BYTE) -# define CATCH_CONFIG_CPP17_BYTE -#endif - -#if defined(CATCH_CONFIG_EXPERIMENTAL_REDIRECT) -# define CATCH_INTERNAL_CONFIG_NEW_CAPTURE -#endif - -#if defined(CATCH_INTERNAL_CONFIG_NEW_CAPTURE) && !defined(CATCH_INTERNAL_CONFIG_NO_NEW_CAPTURE) && !defined(CATCH_CONFIG_NO_NEW_CAPTURE) && !defined(CATCH_CONFIG_NEW_CAPTURE) -# define CATCH_CONFIG_NEW_CAPTURE -#endif - -#if !defined(CATCH_INTERNAL_CONFIG_EXCEPTIONS_ENABLED) && !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS) -# define CATCH_CONFIG_DISABLE_EXCEPTIONS -#endif - -#if defined(CATCH_INTERNAL_CONFIG_POLYFILL_ISNAN) && !defined(CATCH_CONFIG_NO_POLYFILL_ISNAN) && !defined(CATCH_CONFIG_POLYFILL_ISNAN) -# define CATCH_CONFIG_POLYFILL_ISNAN -#endif - -#if defined(CATCH_INTERNAL_CONFIG_USE_ASYNC) && !defined(CATCH_INTERNAL_CONFIG_NO_ASYNC) && !defined(CATCH_CONFIG_NO_USE_ASYNC) && !defined(CATCH_CONFIG_USE_ASYNC) -# define CATCH_CONFIG_USE_ASYNC -#endif - -#if defined(CATCH_INTERNAL_CONFIG_ANDROID_LOGWRITE) && !defined(CATCH_CONFIG_NO_ANDROID_LOGWRITE) && !defined(CATCH_CONFIG_ANDROID_LOGWRITE) -# define CATCH_CONFIG_ANDROID_LOGWRITE -#endif - -#if defined(CATCH_INTERNAL_CONFIG_GLOBAL_NEXTAFTER) && !defined(CATCH_CONFIG_NO_GLOBAL_NEXTAFTER) && !defined(CATCH_CONFIG_GLOBAL_NEXTAFTER) -# define CATCH_CONFIG_GLOBAL_NEXTAFTER -#endif - -// Even if we do not think the compiler has that warning, we still have -// to provide a macro that can be used by the code. -#if !defined(CATCH_INTERNAL_START_WARNINGS_SUPPRESSION) -# define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION -#endif -#if !defined(CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION) -# define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION -#endif -#if !defined(CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS) -# define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS -#endif -#if !defined(CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS) -# define CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS -#endif -#if !defined(CATCH_INTERNAL_SUPPRESS_UNUSED_WARNINGS) -# define CATCH_INTERNAL_SUPPRESS_UNUSED_WARNINGS -#endif -#if !defined(CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS) -# define CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS -#endif - -// The goal of this macro is to avoid evaluation of the arguments, but -// still have the compiler warn on problems inside... -#if !defined(CATCH_INTERNAL_IGNORE_BUT_WARN) -# define CATCH_INTERNAL_IGNORE_BUT_WARN(...) -#endif - -#if defined(__APPLE__) && defined(__apple_build_version__) && (__clang_major__ < 10) -# undef CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS -#elif defined(__clang__) && (__clang_major__ < 5) -# undef CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS -#endif - -#if !defined(CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS) -# define CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS -#endif - -#if defined(CATCH_CONFIG_DISABLE_EXCEPTIONS) -#define CATCH_TRY if ((true)) -#define CATCH_CATCH_ALL if ((false)) -#define CATCH_CATCH_ANON(type) if ((false)) -#else -#define CATCH_TRY try -#define CATCH_CATCH_ALL catch (...) -#define CATCH_CATCH_ANON(type) catch (type) -#endif - -#if defined(CATCH_INTERNAL_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR) && !defined(CATCH_CONFIG_NO_TRADITIONAL_MSVC_PREPROCESSOR) && !defined(CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR) -#define CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR -#endif - -// end catch_compiler_capabilities.h -#define INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line ) name##line -#define INTERNAL_CATCH_UNIQUE_NAME_LINE( name, line ) INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line ) -#ifdef CATCH_CONFIG_COUNTER -# define INTERNAL_CATCH_UNIQUE_NAME( name ) INTERNAL_CATCH_UNIQUE_NAME_LINE( name, __COUNTER__ ) -#else -# define INTERNAL_CATCH_UNIQUE_NAME( name ) INTERNAL_CATCH_UNIQUE_NAME_LINE( name, __LINE__ ) -#endif - -#include <iosfwd> -#include <string> -#include <cstdint> - -// We need a dummy global operator<< so we can bring it into Catch namespace later -struct Catch_global_namespace_dummy {}; -std::ostream& operator<<(std::ostream&, Catch_global_namespace_dummy); - -namespace Catch { - - struct CaseSensitive { enum Choice { - Yes, - No - }; }; - - class NonCopyable { - NonCopyable( NonCopyable const& ) = delete; - NonCopyable( NonCopyable && ) = delete; - NonCopyable& operator = ( NonCopyable const& ) = delete; - NonCopyable& operator = ( NonCopyable && ) = delete; - - protected: - NonCopyable(); - virtual ~NonCopyable(); - }; - - struct SourceLineInfo { - - SourceLineInfo() = delete; - SourceLineInfo( char const* _file, std::size_t _line ) noexcept - : file( _file ), - line( _line ) - {} - - SourceLineInfo( SourceLineInfo const& other ) = default; - SourceLineInfo& operator = ( SourceLineInfo const& ) = default; - SourceLineInfo( SourceLineInfo&& ) noexcept = default; - SourceLineInfo& operator = ( SourceLineInfo&& ) noexcept = default; - - bool empty() const noexcept { return file[0] == '\0'; } - bool operator == ( SourceLineInfo const& other ) const noexcept; - bool operator < ( SourceLineInfo const& other ) const noexcept; - - char const* file; - std::size_t line; - }; - - std::ostream& operator << ( std::ostream& os, SourceLineInfo const& info ); - - // Bring in operator<< from global namespace into Catch namespace - // This is necessary because the overload of operator<< above makes - // lookup stop at namespace Catch - using ::operator<<; - - // Use this in variadic streaming macros to allow - // >> +StreamEndStop - // as well as - // >> stuff +StreamEndStop - struct StreamEndStop { - std::string operator+() const; - }; - template<typename T> - T const& operator + ( T const& value, StreamEndStop ) { - return value; - } -} - -#define CATCH_INTERNAL_LINEINFO \ - ::Catch::SourceLineInfo( __FILE__, static_cast<std::size_t>( __LINE__ ) ) - -// end catch_common.h -namespace Catch { - - struct RegistrarForTagAliases { - RegistrarForTagAliases( char const* alias, char const* tag, SourceLineInfo const& lineInfo ); - }; - -} // end namespace Catch - -#define CATCH_REGISTER_TAG_ALIAS( alias, spec ) \ - CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \ - CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ - namespace{ Catch::RegistrarForTagAliases INTERNAL_CATCH_UNIQUE_NAME( AutoRegisterTagAlias )( alias, spec, CATCH_INTERNAL_LINEINFO ); } \ - CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION - -// end catch_tag_alias_autoregistrar.h -// start catch_test_registry.h - -// start catch_interfaces_testcase.h - -#include <vector> - -namespace Catch { - - class TestSpec; - - struct ITestInvoker { - virtual void invoke () const = 0; - virtual ~ITestInvoker(); - }; - - class TestCase; - struct IConfig; - - struct ITestCaseRegistry { - virtual ~ITestCaseRegistry(); - virtual std::vector<TestCase> const& getAllTests() const = 0; - virtual std::vector<TestCase> const& getAllTestsSorted( IConfig const& config ) const = 0; - }; - - bool isThrowSafe( TestCase const& testCase, IConfig const& config ); - bool matchTest( TestCase const& testCase, TestSpec const& testSpec, IConfig const& config ); - std::vector<TestCase> filterTests( std::vector<TestCase> const& testCases, TestSpec const& testSpec, IConfig const& config ); - std::vector<TestCase> const& getAllTestCasesSorted( IConfig const& config ); - -} - -// end catch_interfaces_testcase.h -// start catch_stringref.h - -#include <cstddef> -#include <string> -#include <iosfwd> -#include <cassert> - -namespace Catch { - - /// A non-owning string class (similar to the forthcoming std::string_view) - /// Note that, because a StringRef may be a substring of another string, - /// it may not be null terminated. - class StringRef { - public: - using size_type = std::size_t; - using const_iterator = const char*; - - private: - static constexpr char const* const s_empty = ""; - - char const* m_start = s_empty; - size_type m_size = 0; - - public: // construction - constexpr StringRef() noexcept = default; - - StringRef( char const* rawChars ) noexcept; - - constexpr StringRef( char const* rawChars, size_type size ) noexcept - : m_start( rawChars ), - m_size( size ) - {} - - StringRef( std::string const& stdString ) noexcept - : m_start( stdString.c_str() ), - m_size( stdString.size() ) - {} - - explicit operator std::string() const { - return std::string(m_start, m_size); - } - - public: // operators - auto operator == ( StringRef const& other ) const noexcept -> bool; - auto operator != (StringRef const& other) const noexcept -> bool { - return !(*this == other); - } - - auto operator[] ( size_type index ) const noexcept -> char { - assert(index < m_size); - return m_start[index]; - } - - public: // named queries - constexpr auto empty() const noexcept -> bool { - return m_size == 0; - } - constexpr auto size() const noexcept -> size_type { - return m_size; - } - - // Returns the current start pointer. If the StringRef is not - // null-terminated, throws std::domain_exception - auto c_str() const -> char const*; - - public: // substrings and searches - // Returns a substring of [start, start + length). - // If start + length > size(), then the substring is [start, size()). - // If start > size(), then the substring is empty. - auto substr( size_type start, size_type length ) const noexcept -> StringRef; - - // Returns the current start pointer. May not be null-terminated. - auto data() const noexcept -> char const*; - - constexpr auto isNullTerminated() const noexcept -> bool { - return m_start[m_size] == '\0'; - } - - public: // iterators - constexpr const_iterator begin() const { return m_start; } - constexpr const_iterator end() const { return m_start + m_size; } - }; - - auto operator += ( std::string& lhs, StringRef const& sr ) -> std::string&; - auto operator << ( std::ostream& os, StringRef const& sr ) -> std::ostream&; - - constexpr auto operator "" _sr( char const* rawChars, std::size_t size ) noexcept -> StringRef { - return StringRef( rawChars, size ); - } -} // namespace Catch - -constexpr auto operator "" _catch_sr( char const* rawChars, std::size_t size ) noexcept -> Catch::StringRef { - return Catch::StringRef( rawChars, size ); -} - -// end catch_stringref.h -// start catch_preprocessor.hpp - - -#define CATCH_RECURSION_LEVEL0(...) __VA_ARGS__ -#define CATCH_RECURSION_LEVEL1(...) CATCH_RECURSION_LEVEL0(CATCH_RECURSION_LEVEL0(CATCH_RECURSION_LEVEL0(__VA_ARGS__))) -#define CATCH_RECURSION_LEVEL2(...) CATCH_RECURSION_LEVEL1(CATCH_RECURSION_LEVEL1(CATCH_RECURSION_LEVEL1(__VA_ARGS__))) -#define CATCH_RECURSION_LEVEL3(...) CATCH_RECURSION_LEVEL2(CATCH_RECURSION_LEVEL2(CATCH_RECURSION_LEVEL2(__VA_ARGS__))) -#define CATCH_RECURSION_LEVEL4(...) CATCH_RECURSION_LEVEL3(CATCH_RECURSION_LEVEL3(CATCH_RECURSION_LEVEL3(__VA_ARGS__))) -#define CATCH_RECURSION_LEVEL5(...) CATCH_RECURSION_LEVEL4(CATCH_RECURSION_LEVEL4(CATCH_RECURSION_LEVEL4(__VA_ARGS__))) - -#ifdef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR -#define INTERNAL_CATCH_EXPAND_VARGS(...) __VA_ARGS__ -// MSVC needs more evaluations -#define CATCH_RECURSION_LEVEL6(...) CATCH_RECURSION_LEVEL5(CATCH_RECURSION_LEVEL5(CATCH_RECURSION_LEVEL5(__VA_ARGS__))) -#define CATCH_RECURSE(...) CATCH_RECURSION_LEVEL6(CATCH_RECURSION_LEVEL6(__VA_ARGS__)) -#else -#define CATCH_RECURSE(...) CATCH_RECURSION_LEVEL5(__VA_ARGS__) -#endif - -#define CATCH_REC_END(...) -#define CATCH_REC_OUT - -#define CATCH_EMPTY() -#define CATCH_DEFER(id) id CATCH_EMPTY() - -#define CATCH_REC_GET_END2() 0, CATCH_REC_END -#define CATCH_REC_GET_END1(...) CATCH_REC_GET_END2 -#define CATCH_REC_GET_END(...) CATCH_REC_GET_END1 -#define CATCH_REC_NEXT0(test, next, ...) next CATCH_REC_OUT -#define CATCH_REC_NEXT1(test, next) CATCH_DEFER ( CATCH_REC_NEXT0 ) ( test, next, 0) -#define CATCH_REC_NEXT(test, next) CATCH_REC_NEXT1(CATCH_REC_GET_END test, next) - -#define CATCH_REC_LIST0(f, x, peek, ...) , f(x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST1) ) ( f, peek, __VA_ARGS__ ) -#define CATCH_REC_LIST1(f, x, peek, ...) , f(x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST0) ) ( f, peek, __VA_ARGS__ ) -#define CATCH_REC_LIST2(f, x, peek, ...) f(x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST1) ) ( f, peek, __VA_ARGS__ ) - -#define CATCH_REC_LIST0_UD(f, userdata, x, peek, ...) , f(userdata, x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST1_UD) ) ( f, userdata, peek, __VA_ARGS__ ) -#define CATCH_REC_LIST1_UD(f, userdata, x, peek, ...) , f(userdata, x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST0_UD) ) ( f, userdata, peek, __VA_ARGS__ ) -#define CATCH_REC_LIST2_UD(f, userdata, x, peek, ...) f(userdata, x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST1_UD) ) ( f, userdata, peek, __VA_ARGS__ ) - -// Applies the function macro `f` to each of the remaining parameters, inserts commas between the results, -// and passes userdata as the first parameter to each invocation, -// e.g. CATCH_REC_LIST_UD(f, x, a, b, c) evaluates to f(x, a), f(x, b), f(x, c) -#define CATCH_REC_LIST_UD(f, userdata, ...) CATCH_RECURSE(CATCH_REC_LIST2_UD(f, userdata, __VA_ARGS__, ()()(), ()()(), ()()(), 0)) - -#define CATCH_REC_LIST(f, ...) CATCH_RECURSE(CATCH_REC_LIST2(f, __VA_ARGS__, ()()(), ()()(), ()()(), 0)) - -#define INTERNAL_CATCH_EXPAND1(param) INTERNAL_CATCH_EXPAND2(param) -#define INTERNAL_CATCH_EXPAND2(...) INTERNAL_CATCH_NO## __VA_ARGS__ -#define INTERNAL_CATCH_DEF(...) INTERNAL_CATCH_DEF __VA_ARGS__ -#define INTERNAL_CATCH_NOINTERNAL_CATCH_DEF -#define INTERNAL_CATCH_STRINGIZE(...) INTERNAL_CATCH_STRINGIZE2(__VA_ARGS__) -#ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR -#define INTERNAL_CATCH_STRINGIZE2(...) #__VA_ARGS__ -#define INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS(param) INTERNAL_CATCH_STRINGIZE(INTERNAL_CATCH_REMOVE_PARENS(param)) -#else -// MSVC is adding extra space and needs another indirection to expand INTERNAL_CATCH_NOINTERNAL_CATCH_DEF -#define INTERNAL_CATCH_STRINGIZE2(...) INTERNAL_CATCH_STRINGIZE3(__VA_ARGS__) -#define INTERNAL_CATCH_STRINGIZE3(...) #__VA_ARGS__ -#define INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS(param) (INTERNAL_CATCH_STRINGIZE(INTERNAL_CATCH_REMOVE_PARENS(param)) + 1) -#endif - -#define INTERNAL_CATCH_MAKE_NAMESPACE2(...) ns_##__VA_ARGS__ -#define INTERNAL_CATCH_MAKE_NAMESPACE(name) INTERNAL_CATCH_MAKE_NAMESPACE2(name) - -#define INTERNAL_CATCH_REMOVE_PARENS(...) INTERNAL_CATCH_EXPAND1(INTERNAL_CATCH_DEF __VA_ARGS__) - -#ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR -#define INTERNAL_CATCH_MAKE_TYPE_LIST2(...) decltype(get_wrapper<INTERNAL_CATCH_REMOVE_PARENS_GEN(__VA_ARGS__)>()) -#define INTERNAL_CATCH_MAKE_TYPE_LIST(...) INTERNAL_CATCH_MAKE_TYPE_LIST2(INTERNAL_CATCH_REMOVE_PARENS(__VA_ARGS__)) -#else -#define INTERNAL_CATCH_MAKE_TYPE_LIST2(...) INTERNAL_CATCH_EXPAND_VARGS(decltype(get_wrapper<INTERNAL_CATCH_REMOVE_PARENS_GEN(__VA_ARGS__)>())) -#define INTERNAL_CATCH_MAKE_TYPE_LIST(...) INTERNAL_CATCH_EXPAND_VARGS(INTERNAL_CATCH_MAKE_TYPE_LIST2(INTERNAL_CATCH_REMOVE_PARENS(__VA_ARGS__))) -#endif - -#define INTERNAL_CATCH_MAKE_TYPE_LISTS_FROM_TYPES(...)\ - CATCH_REC_LIST(INTERNAL_CATCH_MAKE_TYPE_LIST,__VA_ARGS__) - -#define INTERNAL_CATCH_REMOVE_PARENS_1_ARG(_0) INTERNAL_CATCH_REMOVE_PARENS(_0) -#define INTERNAL_CATCH_REMOVE_PARENS_2_ARG(_0, _1) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_1_ARG(_1) -#define INTERNAL_CATCH_REMOVE_PARENS_3_ARG(_0, _1, _2) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_2_ARG(_1, _2) -#define INTERNAL_CATCH_REMOVE_PARENS_4_ARG(_0, _1, _2, _3) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_3_ARG(_1, _2, _3) -#define INTERNAL_CATCH_REMOVE_PARENS_5_ARG(_0, _1, _2, _3, _4) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_4_ARG(_1, _2, _3, _4) -#define INTERNAL_CATCH_REMOVE_PARENS_6_ARG(_0, _1, _2, _3, _4, _5) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_5_ARG(_1, _2, _3, _4, _5) -#define INTERNAL_CATCH_REMOVE_PARENS_7_ARG(_0, _1, _2, _3, _4, _5, _6) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_6_ARG(_1, _2, _4, _5, _6) -#define INTERNAL_CATCH_REMOVE_PARENS_8_ARG(_0, _1, _2, _3, _4, _5, _6, _7) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_7_ARG(_1, _2, _3, _4, _5, _6, _7) -#define INTERNAL_CATCH_REMOVE_PARENS_9_ARG(_0, _1, _2, _3, _4, _5, _6, _7, _8) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_8_ARG(_1, _2, _3, _4, _5, _6, _7, _8) -#define INTERNAL_CATCH_REMOVE_PARENS_10_ARG(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_9_ARG(_1, _2, _3, _4, _5, _6, _7, _8, _9) -#define INTERNAL_CATCH_REMOVE_PARENS_11_ARG(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_10_ARG(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10) - -#define INTERNAL_CATCH_VA_NARGS_IMPL(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, N, ...) N - -#define INTERNAL_CATCH_TYPE_GEN\ - template<typename...> struct TypeList {};\ - template<typename...Ts>\ - constexpr auto get_wrapper() noexcept -> TypeList<Ts...> { return {}; }\ - template<template<typename...> class...> struct TemplateTypeList{};\ - template<template<typename...> class...Cs>\ - constexpr auto get_wrapper() noexcept -> TemplateTypeList<Cs...> { return {}; }\ - template<typename...>\ - struct append;\ - template<typename...>\ - struct rewrap;\ - template<template<typename...> class, typename...>\ - struct create;\ - template<template<typename...> class, typename>\ - struct convert;\ - \ - template<typename T> \ - struct append<T> { using type = T; };\ - template< template<typename...> class L1, typename...E1, template<typename...> class L2, typename...E2, typename...Rest>\ - struct append<L1<E1...>, L2<E2...>, Rest...> { using type = typename append<L1<E1...,E2...>, Rest...>::type; };\ - template< template<typename...> class L1, typename...E1, typename...Rest>\ - struct append<L1<E1...>, TypeList<mpl_::na>, Rest...> { using type = L1<E1...>; };\ - \ - template< template<typename...> class Container, template<typename...> class List, typename...elems>\ - struct rewrap<TemplateTypeList<Container>, List<elems...>> { using type = TypeList<Container<elems...>>; };\ - template< template<typename...> class Container, template<typename...> class List, class...Elems, typename...Elements>\ - struct rewrap<TemplateTypeList<Container>, List<Elems...>, Elements...> { using type = typename append<TypeList<Container<Elems...>>, typename rewrap<TemplateTypeList<Container>, Elements...>::type>::type; };\ - \ - template<template <typename...> class Final, template< typename...> class...Containers, typename...Types>\ - struct create<Final, TemplateTypeList<Containers...>, TypeList<Types...>> { using type = typename append<Final<>, typename rewrap<TemplateTypeList<Containers>, Types...>::type...>::type; };\ - template<template <typename...> class Final, template <typename...> class List, typename...Ts>\ - struct convert<Final, List<Ts...>> { using type = typename append<Final<>,TypeList<Ts>...>::type; }; - -#define INTERNAL_CATCH_NTTP_1(signature, ...)\ - template<INTERNAL_CATCH_REMOVE_PARENS(signature)> struct Nttp{};\ - template<INTERNAL_CATCH_REMOVE_PARENS(signature)>\ - constexpr auto get_wrapper() noexcept -> Nttp<__VA_ARGS__> { return {}; } \ - template<template<INTERNAL_CATCH_REMOVE_PARENS(signature)> class...> struct NttpTemplateTypeList{};\ - template<template<INTERNAL_CATCH_REMOVE_PARENS(signature)> class...Cs>\ - constexpr auto get_wrapper() noexcept -> NttpTemplateTypeList<Cs...> { return {}; } \ - \ - template< template<INTERNAL_CATCH_REMOVE_PARENS(signature)> class Container, template<INTERNAL_CATCH_REMOVE_PARENS(signature)> class List, INTERNAL_CATCH_REMOVE_PARENS(signature)>\ - struct rewrap<NttpTemplateTypeList<Container>, List<__VA_ARGS__>> { using type = TypeList<Container<__VA_ARGS__>>; };\ - template< template<INTERNAL_CATCH_REMOVE_PARENS(signature)> class Container, template<INTERNAL_CATCH_REMOVE_PARENS(signature)> class List, INTERNAL_CATCH_REMOVE_PARENS(signature), typename...Elements>\ - struct rewrap<NttpTemplateTypeList<Container>, List<__VA_ARGS__>, Elements...> { using type = typename append<TypeList<Container<__VA_ARGS__>>, typename rewrap<NttpTemplateTypeList<Container>, Elements...>::type>::type; };\ - template<template <typename...> class Final, template<INTERNAL_CATCH_REMOVE_PARENS(signature)> class...Containers, typename...Types>\ - struct create<Final, NttpTemplateTypeList<Containers...>, TypeList<Types...>> { using type = typename append<Final<>, typename rewrap<NttpTemplateTypeList<Containers>, Types...>::type...>::type; }; - -#define INTERNAL_CATCH_DECLARE_SIG_TEST0(TestName) -#define INTERNAL_CATCH_DECLARE_SIG_TEST1(TestName, signature)\ - template<INTERNAL_CATCH_REMOVE_PARENS(signature)>\ - static void TestName() -#define INTERNAL_CATCH_DECLARE_SIG_TEST_X(TestName, signature, ...)\ - template<INTERNAL_CATCH_REMOVE_PARENS(signature)>\ - static void TestName() - -#define INTERNAL_CATCH_DEFINE_SIG_TEST0(TestName) -#define INTERNAL_CATCH_DEFINE_SIG_TEST1(TestName, signature)\ - template<INTERNAL_CATCH_REMOVE_PARENS(signature)>\ - static void TestName() -#define INTERNAL_CATCH_DEFINE_SIG_TEST_X(TestName, signature,...)\ - template<INTERNAL_CATCH_REMOVE_PARENS(signature)>\ - static void TestName() - -#define INTERNAL_CATCH_NTTP_REGISTER0(TestFunc, signature)\ - template<typename Type>\ - void reg_test(TypeList<Type>, Catch::NameAndTags nameAndTags)\ - {\ - Catch::AutoReg( Catch::makeTestInvoker(&TestFunc<Type>), CATCH_INTERNAL_LINEINFO, Catch::StringRef(), nameAndTags);\ - } - -#define INTERNAL_CATCH_NTTP_REGISTER(TestFunc, signature, ...)\ - template<INTERNAL_CATCH_REMOVE_PARENS(signature)>\ - void reg_test(Nttp<__VA_ARGS__>, Catch::NameAndTags nameAndTags)\ - {\ - Catch::AutoReg( Catch::makeTestInvoker(&TestFunc<__VA_ARGS__>), CATCH_INTERNAL_LINEINFO, Catch::StringRef(), nameAndTags);\ - } - -#define INTERNAL_CATCH_NTTP_REGISTER_METHOD0(TestName, signature, ...)\ - template<typename Type>\ - void reg_test(TypeList<Type>, Catch::StringRef className, Catch::NameAndTags nameAndTags)\ - {\ - Catch::AutoReg( Catch::makeTestInvoker(&TestName<Type>::test), CATCH_INTERNAL_LINEINFO, className, nameAndTags);\ - } - -#define INTERNAL_CATCH_NTTP_REGISTER_METHOD(TestName, signature, ...)\ - template<INTERNAL_CATCH_REMOVE_PARENS(signature)>\ - void reg_test(Nttp<__VA_ARGS__>, Catch::StringRef className, Catch::NameAndTags nameAndTags)\ - {\ - Catch::AutoReg( Catch::makeTestInvoker(&TestName<__VA_ARGS__>::test), CATCH_INTERNAL_LINEINFO, className, nameAndTags);\ - } - -#define INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD0(TestName, ClassName) -#define INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD1(TestName, ClassName, signature)\ - template<typename TestType> \ - struct TestName : INTERNAL_CATCH_REMOVE_PARENS(ClassName)<TestType> { \ - void test();\ - } - -#define INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X(TestName, ClassName, signature, ...)\ - template<INTERNAL_CATCH_REMOVE_PARENS(signature)> \ - struct TestName : INTERNAL_CATCH_REMOVE_PARENS(ClassName)<__VA_ARGS__> { \ - void test();\ - } - -#define INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD0(TestName) -#define INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD1(TestName, signature)\ - template<typename TestType> \ - void INTERNAL_CATCH_MAKE_NAMESPACE(TestName)::TestName<TestType>::test() -#define INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X(TestName, signature, ...)\ - template<INTERNAL_CATCH_REMOVE_PARENS(signature)> \ - void INTERNAL_CATCH_MAKE_NAMESPACE(TestName)::TestName<__VA_ARGS__>::test() - -#ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR -#define INTERNAL_CATCH_NTTP_0 -#define INTERNAL_CATCH_NTTP_GEN(...) INTERNAL_CATCH_VA_NARGS_IMPL(__VA_ARGS__, INTERNAL_CATCH_NTTP_1(__VA_ARGS__), INTERNAL_CATCH_NTTP_1(__VA_ARGS__), INTERNAL_CATCH_NTTP_1(__VA_ARGS__), INTERNAL_CATCH_NTTP_1(__VA_ARGS__), INTERNAL_CATCH_NTTP_1(__VA_ARGS__), INTERNAL_CATCH_NTTP_1( __VA_ARGS__), INTERNAL_CATCH_NTTP_1( __VA_ARGS__), INTERNAL_CATCH_NTTP_1( __VA_ARGS__), INTERNAL_CATCH_NTTP_1( __VA_ARGS__),INTERNAL_CATCH_NTTP_1( __VA_ARGS__), INTERNAL_CATCH_NTTP_0) -#define INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD(TestName, ...) INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD1, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD0)(TestName, __VA_ARGS__) -#define INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD(TestName, ClassName, ...) INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD1, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD0)(TestName, ClassName, __VA_ARGS__) -#define INTERNAL_CATCH_NTTP_REG_METHOD_GEN(TestName, ...) INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD0, INTERNAL_CATCH_NTTP_REGISTER_METHOD0)(TestName, __VA_ARGS__) -#define INTERNAL_CATCH_NTTP_REG_GEN(TestFunc, ...) INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER0, INTERNAL_CATCH_NTTP_REGISTER0)(TestFunc, __VA_ARGS__) -#define INTERNAL_CATCH_DEFINE_SIG_TEST(TestName, ...) INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X,INTERNAL_CATCH_DEFINE_SIG_TEST_X,INTERNAL_CATCH_DEFINE_SIG_TEST1, INTERNAL_CATCH_DEFINE_SIG_TEST0)(TestName, __VA_ARGS__) -#define INTERNAL_CATCH_DECLARE_SIG_TEST(TestName, ...) INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_DECLARE_SIG_TEST_X,INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X,INTERNAL_CATCH_DECLARE_SIG_TEST_X,INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DECLARE_SIG_TEST1, INTERNAL_CATCH_DECLARE_SIG_TEST0)(TestName, __VA_ARGS__) -#define INTERNAL_CATCH_REMOVE_PARENS_GEN(...) INTERNAL_CATCH_VA_NARGS_IMPL(__VA_ARGS__, INTERNAL_CATCH_REMOVE_PARENS_11_ARG,INTERNAL_CATCH_REMOVE_PARENS_10_ARG,INTERNAL_CATCH_REMOVE_PARENS_9_ARG,INTERNAL_CATCH_REMOVE_PARENS_8_ARG,INTERNAL_CATCH_REMOVE_PARENS_7_ARG,INTERNAL_CATCH_REMOVE_PARENS_6_ARG,INTERNAL_CATCH_REMOVE_PARENS_5_ARG,INTERNAL_CATCH_REMOVE_PARENS_4_ARG,INTERNAL_CATCH_REMOVE_PARENS_3_ARG,INTERNAL_CATCH_REMOVE_PARENS_2_ARG,INTERNAL_CATCH_REMOVE_PARENS_1_ARG)(__VA_ARGS__) -#else -#define INTERNAL_CATCH_NTTP_0(signature) -#define INTERNAL_CATCH_NTTP_GEN(...) INTERNAL_CATCH_EXPAND_VARGS(INTERNAL_CATCH_VA_NARGS_IMPL(__VA_ARGS__, INTERNAL_CATCH_NTTP_1, INTERNAL_CATCH_NTTP_1, INTERNAL_CATCH_NTTP_1, INTERNAL_CATCH_NTTP_1, INTERNAL_CATCH_NTTP_1, INTERNAL_CATCH_NTTP_1, INTERNAL_CATCH_NTTP_1, INTERNAL_CATCH_NTTP_1, INTERNAL_CATCH_NTTP_1,INTERNAL_CATCH_NTTP_1, INTERNAL_CATCH_NTTP_0)( __VA_ARGS__)) -#define INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD(TestName, ...) INTERNAL_CATCH_EXPAND_VARGS(INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD1, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD0)(TestName, __VA_ARGS__)) -#define INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD(TestName, ClassName, ...) INTERNAL_CATCH_EXPAND_VARGS(INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD1, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD0)(TestName, ClassName, __VA_ARGS__)) -#define INTERNAL_CATCH_NTTP_REG_METHOD_GEN(TestName, ...) INTERNAL_CATCH_EXPAND_VARGS(INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD0, INTERNAL_CATCH_NTTP_REGISTER_METHOD0)(TestName, __VA_ARGS__)) -#define INTERNAL_CATCH_NTTP_REG_GEN(TestFunc, ...) INTERNAL_CATCH_EXPAND_VARGS(INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER0, INTERNAL_CATCH_NTTP_REGISTER0)(TestFunc, __VA_ARGS__)) -#define INTERNAL_CATCH_DEFINE_SIG_TEST(TestName, ...) INTERNAL_CATCH_EXPAND_VARGS(INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X,INTERNAL_CATCH_DEFINE_SIG_TEST_X,INTERNAL_CATCH_DEFINE_SIG_TEST1, INTERNAL_CATCH_DEFINE_SIG_TEST0)(TestName, __VA_ARGS__)) -#define INTERNAL_CATCH_DECLARE_SIG_TEST(TestName, ...) INTERNAL_CATCH_EXPAND_VARGS(INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_DECLARE_SIG_TEST_X,INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X,INTERNAL_CATCH_DECLARE_SIG_TEST_X,INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DECLARE_SIG_TEST1, INTERNAL_CATCH_DECLARE_SIG_TEST0)(TestName, __VA_ARGS__)) -#define INTERNAL_CATCH_REMOVE_PARENS_GEN(...) INTERNAL_CATCH_EXPAND_VARGS(INTERNAL_CATCH_VA_NARGS_IMPL(__VA_ARGS__, INTERNAL_CATCH_REMOVE_PARENS_11_ARG,INTERNAL_CATCH_REMOVE_PARENS_10_ARG,INTERNAL_CATCH_REMOVE_PARENS_9_ARG,INTERNAL_CATCH_REMOVE_PARENS_8_ARG,INTERNAL_CATCH_REMOVE_PARENS_7_ARG,INTERNAL_CATCH_REMOVE_PARENS_6_ARG,INTERNAL_CATCH_REMOVE_PARENS_5_ARG,INTERNAL_CATCH_REMOVE_PARENS_4_ARG,INTERNAL_CATCH_REMOVE_PARENS_3_ARG,INTERNAL_CATCH_REMOVE_PARENS_2_ARG,INTERNAL_CATCH_REMOVE_PARENS_1_ARG)(__VA_ARGS__)) -#endif - -// end catch_preprocessor.hpp -// start catch_meta.hpp - - -#include <type_traits> - -namespace Catch { - template<typename T> - struct always_false : std::false_type {}; - - template <typename> struct true_given : std::true_type {}; - struct is_callable_tester { - template <typename Fun, typename... Args> - true_given<decltype(std::declval<Fun>()(std::declval<Args>()...))> static test(int); - template <typename...> - std::false_type static test(...); - }; - - template <typename T> - struct is_callable; - - template <typename Fun, typename... Args> - struct is_callable<Fun(Args...)> : decltype(is_callable_tester::test<Fun, Args...>(0)) {}; - -#if defined(__cpp_lib_is_invocable) && __cpp_lib_is_invocable >= 201703 - // std::result_of is deprecated in C++17 and removed in C++20. Hence, it is - // replaced with std::invoke_result here. Also *_t format is preferred over - // typename *::type format. - template <typename Func, typename U> - using FunctionReturnType = std::remove_reference_t<std::remove_cv_t<std::invoke_result_t<Func, U>>>; -#else - template <typename Func, typename U> - using FunctionReturnType = typename std::remove_reference<typename std::remove_cv<typename std::result_of<Func(U)>::type>::type>::type; -#endif - -} // namespace Catch - -namespace mpl_{ - struct na; -} - -// end catch_meta.hpp -namespace Catch { - -template<typename C> -class TestInvokerAsMethod : public ITestInvoker { - void (C::*m_testAsMethod)(); -public: - TestInvokerAsMethod( void (C::*testAsMethod)() ) noexcept : m_testAsMethod( testAsMethod ) {} - - void invoke() const override { - C obj; - (obj.*m_testAsMethod)(); - } -}; - -auto makeTestInvoker( void(*testAsFunction)() ) noexcept -> ITestInvoker*; - -template<typename C> -auto makeTestInvoker( void (C::*testAsMethod)() ) noexcept -> ITestInvoker* { - return new(std::nothrow) TestInvokerAsMethod<C>( testAsMethod ); -} - -struct NameAndTags { - NameAndTags( StringRef const& name_ = StringRef(), StringRef const& tags_ = StringRef() ) noexcept; - StringRef name; - StringRef tags; -}; - -struct AutoReg : NonCopyable { - AutoReg( ITestInvoker* invoker, SourceLineInfo const& lineInfo, StringRef const& classOrMethod, NameAndTags const& nameAndTags ) noexcept; - ~AutoReg(); -}; - -} // end namespace Catch - -#if defined(CATCH_CONFIG_DISABLE) - #define INTERNAL_CATCH_TESTCASE_NO_REGISTRATION( TestName, ... ) \ - static void TestName() - #define INTERNAL_CATCH_TESTCASE_METHOD_NO_REGISTRATION( TestName, ClassName, ... ) \ - namespace{ \ - struct TestName : INTERNAL_CATCH_REMOVE_PARENS(ClassName) { \ - void test(); \ - }; \ - } \ - void TestName::test() - #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_NO_REGISTRATION_2( TestName, TestFunc, Name, Tags, Signature, ... ) \ - INTERNAL_CATCH_DEFINE_SIG_TEST(TestFunc, INTERNAL_CATCH_REMOVE_PARENS(Signature)) - #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_NO_REGISTRATION_2( TestNameClass, TestName, ClassName, Name, Tags, Signature, ... ) \ - namespace{ \ - namespace INTERNAL_CATCH_MAKE_NAMESPACE(TestName) { \ - INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD(TestName, ClassName, INTERNAL_CATCH_REMOVE_PARENS(Signature));\ - } \ - } \ - INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD(TestName, INTERNAL_CATCH_REMOVE_PARENS(Signature)) - - #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR - #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_NO_REGISTRATION(Name, Tags, ...) \ - INTERNAL_CATCH_TEMPLATE_TEST_CASE_NO_REGISTRATION_2( INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_M_P_L_A_T_E____T_E_S_T____ ), INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_M_P_L_A_T_E____T_E_S_T____F_U_N_C____ ), Name, Tags, typename TestType, __VA_ARGS__ ) - #else - #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_NO_REGISTRATION(Name, Tags, ...) \ - INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_NO_REGISTRATION_2( INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_M_P_L_A_T_E____T_E_S_T____ ), INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_M_P_L_A_T_E____T_E_S_T____F_U_N_C____ ), Name, Tags, typename TestType, __VA_ARGS__ ) ) - #endif - - #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR - #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG_NO_REGISTRATION(Name, Tags, Signature, ...) \ - INTERNAL_CATCH_TEMPLATE_TEST_CASE_NO_REGISTRATION_2( INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_M_P_L_A_T_E____T_E_S_T____ ), INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_M_P_L_A_T_E____T_E_S_T____F_U_N_C____ ), Name, Tags, Signature, __VA_ARGS__ ) - #else - #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG_NO_REGISTRATION(Name, Tags, Signature, ...) \ - INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_NO_REGISTRATION_2( INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_M_P_L_A_T_E____T_E_S_T____ ), INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_M_P_L_A_T_E____T_E_S_T____F_U_N_C____ ), Name, Tags, Signature, __VA_ARGS__ ) ) - #endif - - #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR - #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_NO_REGISTRATION( ClassName, Name, Tags,... ) \ - INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_NO_REGISTRATION_2( INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_M_P_L_A_T_E____T_E_S_T____C_L_A_S_S____ ), INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_M_P_L_A_T_E____T_E_S_T____ ) , ClassName, Name, Tags, typename T, __VA_ARGS__ ) - #else - #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_NO_REGISTRATION( ClassName, Name, Tags,... ) \ - INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_NO_REGISTRATION_2( INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_M_P_L_A_T_E____T_E_S_T____C_L_A_S_S____ ), INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_M_P_L_A_T_E____T_E_S_T____ ) , ClassName, Name, Tags, typename T, __VA_ARGS__ ) ) - #endif - - #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR - #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG_NO_REGISTRATION( ClassName, Name, Tags, Signature, ... ) \ - INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_NO_REGISTRATION_2( INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_M_P_L_A_T_E____T_E_S_T____C_L_A_S_S____ ), INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_M_P_L_A_T_E____T_E_S_T____ ) , ClassName, Name, Tags, Signature, __VA_ARGS__ ) - #else - #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG_NO_REGISTRATION( ClassName, Name, Tags, Signature, ... ) \ - INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_NO_REGISTRATION_2( INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_M_P_L_A_T_E____T_E_S_T____C_L_A_S_S____ ), INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_M_P_L_A_T_E____T_E_S_T____ ) , ClassName, Name, Tags, Signature, __VA_ARGS__ ) ) - #endif -#endif - - /////////////////////////////////////////////////////////////////////////////// - #define INTERNAL_CATCH_TESTCASE2( TestName, ... ) \ - static void TestName(); \ - CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \ - CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ - namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( Catch::makeTestInvoker( &TestName ), CATCH_INTERNAL_LINEINFO, Catch::StringRef(), Catch::NameAndTags{ __VA_ARGS__ } ); } /* NOLINT */ \ - CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \ - static void TestName() - #define INTERNAL_CATCH_TESTCASE( ... ) \ - INTERNAL_CATCH_TESTCASE2( INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ), __VA_ARGS__ ) - - /////////////////////////////////////////////////////////////////////////////// - #define INTERNAL_CATCH_METHOD_AS_TEST_CASE( QualifiedMethod, ... ) \ - CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \ - CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ - namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( Catch::makeTestInvoker( &QualifiedMethod ), CATCH_INTERNAL_LINEINFO, "&" #QualifiedMethod, Catch::NameAndTags{ __VA_ARGS__ } ); } /* NOLINT */ \ - CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION - - /////////////////////////////////////////////////////////////////////////////// - #define INTERNAL_CATCH_TEST_CASE_METHOD2( TestName, ClassName, ... )\ - CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \ - CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ - namespace{ \ - struct TestName : INTERNAL_CATCH_REMOVE_PARENS(ClassName) { \ - void test(); \ - }; \ - Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar ) ( Catch::makeTestInvoker( &TestName::test ), CATCH_INTERNAL_LINEINFO, #ClassName, Catch::NameAndTags{ __VA_ARGS__ } ); /* NOLINT */ \ - } \ - CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \ - void TestName::test() - #define INTERNAL_CATCH_TEST_CASE_METHOD( ClassName, ... ) \ - INTERNAL_CATCH_TEST_CASE_METHOD2( INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ), ClassName, __VA_ARGS__ ) - - /////////////////////////////////////////////////////////////////////////////// - #define INTERNAL_CATCH_REGISTER_TESTCASE( Function, ... ) \ - CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \ - CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ - Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( Catch::makeTestInvoker( Function ), CATCH_INTERNAL_LINEINFO, Catch::StringRef(), Catch::NameAndTags{ __VA_ARGS__ } ); /* NOLINT */ \ - CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION - - /////////////////////////////////////////////////////////////////////////////// - #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_2(TestName, TestFunc, Name, Tags, Signature, ... )\ - CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \ - CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ - CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS \ - CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \ - INTERNAL_CATCH_DECLARE_SIG_TEST(TestFunc, INTERNAL_CATCH_REMOVE_PARENS(Signature));\ - namespace {\ - namespace INTERNAL_CATCH_MAKE_NAMESPACE(TestName){\ - INTERNAL_CATCH_TYPE_GEN\ - INTERNAL_CATCH_NTTP_GEN(INTERNAL_CATCH_REMOVE_PARENS(Signature))\ - INTERNAL_CATCH_NTTP_REG_GEN(TestFunc,INTERNAL_CATCH_REMOVE_PARENS(Signature))\ - template<typename...Types> \ - struct TestName{\ - TestName(){\ - int index = 0; \ - constexpr char const* tmpl_types[] = {CATCH_REC_LIST(INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS, __VA_ARGS__)};\ - using expander = int[];\ - (void)expander{(reg_test(Types{}, Catch::NameAndTags{ Name " - " + std::string(tmpl_types[index]), Tags } ), index++, 0)... };/* NOLINT */ \ - }\ - };\ - static int INTERNAL_CATCH_UNIQUE_NAME( globalRegistrar ) = [](){\ - TestName<INTERNAL_CATCH_MAKE_TYPE_LISTS_FROM_TYPES(__VA_ARGS__)>();\ - return 0;\ - }();\ - }\ - }\ - CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \ - INTERNAL_CATCH_DEFINE_SIG_TEST(TestFunc,INTERNAL_CATCH_REMOVE_PARENS(Signature)) - -#ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR - #define INTERNAL_CATCH_TEMPLATE_TEST_CASE(Name, Tags, ...) \ - INTERNAL_CATCH_TEMPLATE_TEST_CASE_2( INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_M_P_L_A_T_E____T_E_S_T____ ), INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_M_P_L_A_T_E____T_E_S_T____F_U_N_C____ ), Name, Tags, typename TestType, __VA_ARGS__ ) -#else - #define INTERNAL_CATCH_TEMPLATE_TEST_CASE(Name, Tags, ...) \ - INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_2( INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_M_P_L_A_T_E____T_E_S_T____ ), INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_M_P_L_A_T_E____T_E_S_T____F_U_N_C____ ), Name, Tags, typename TestType, __VA_ARGS__ ) ) -#endif - -#ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR - #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG(Name, Tags, Signature, ...) \ - INTERNAL_CATCH_TEMPLATE_TEST_CASE_2( INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_M_P_L_A_T_E____T_E_S_T____ ), INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_M_P_L_A_T_E____T_E_S_T____F_U_N_C____ ), Name, Tags, Signature, __VA_ARGS__ ) -#else - #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG(Name, Tags, Signature, ...) \ - INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_2( INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_M_P_L_A_T_E____T_E_S_T____ ), INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_M_P_L_A_T_E____T_E_S_T____F_U_N_C____ ), Name, Tags, Signature, __VA_ARGS__ ) ) -#endif - - #define INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE2(TestName, TestFuncName, Name, Tags, Signature, TmplTypes, TypesList) \ - CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \ - CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ - CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS \ - CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \ - template<typename TestType> static void TestFuncName(); \ - namespace {\ - namespace INTERNAL_CATCH_MAKE_NAMESPACE(TestName) { \ - INTERNAL_CATCH_TYPE_GEN \ - INTERNAL_CATCH_NTTP_GEN(INTERNAL_CATCH_REMOVE_PARENS(Signature)) \ - template<typename... Types> \ - struct TestName { \ - void reg_tests() { \ - int index = 0; \ - using expander = int[]; \ - constexpr char const* tmpl_types[] = {CATCH_REC_LIST(INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS, INTERNAL_CATCH_REMOVE_PARENS(TmplTypes))};\ - constexpr char const* types_list[] = {CATCH_REC_LIST(INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS, INTERNAL_CATCH_REMOVE_PARENS(TypesList))};\ - constexpr auto num_types = sizeof(types_list) / sizeof(types_list[0]);\ - (void)expander{(Catch::AutoReg( Catch::makeTestInvoker( &TestFuncName<Types> ), CATCH_INTERNAL_LINEINFO, Catch::StringRef(), Catch::NameAndTags{ Name " - " + std::string(tmpl_types[index / num_types]) + "<" + std::string(types_list[index % num_types]) + ">", Tags } ), index++, 0)... };/* NOLINT */\ - } \ - }; \ - static int INTERNAL_CATCH_UNIQUE_NAME( globalRegistrar ) = [](){ \ - using TestInit = typename create<TestName, decltype(get_wrapper<INTERNAL_CATCH_REMOVE_PARENS(TmplTypes)>()), TypeList<INTERNAL_CATCH_MAKE_TYPE_LISTS_FROM_TYPES(INTERNAL_CATCH_REMOVE_PARENS(TypesList))>>::type; \ - TestInit t; \ - t.reg_tests(); \ - return 0; \ - }(); \ - } \ - } \ - CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \ - template<typename TestType> \ - static void TestFuncName() - -#ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR - #define INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE(Name, Tags, ...)\ - INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE2(INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_M_P_L_A_T_E____T_E_S_T____ ), INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_M_P_L_A_T_E____T_E_S_T____F_U_N_C____ ), Name, Tags, typename T,__VA_ARGS__) -#else - #define INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE(Name, Tags, ...)\ - INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE2( INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_M_P_L_A_T_E____T_E_S_T____ ), INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_M_P_L_A_T_E____T_E_S_T____F_U_N_C____ ), Name, Tags, typename T, __VA_ARGS__ ) ) -#endif - -#ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR - #define INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_SIG(Name, Tags, Signature, ...)\ - INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE2(INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_M_P_L_A_T_E____T_E_S_T____ ), INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_M_P_L_A_T_E____T_E_S_T____F_U_N_C____ ), Name, Tags, Signature, __VA_ARGS__) -#else - #define INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_SIG(Name, Tags, Signature, ...)\ - INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE2( INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_M_P_L_A_T_E____T_E_S_T____ ), INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_M_P_L_A_T_E____T_E_S_T____F_U_N_C____ ), Name, Tags, Signature, __VA_ARGS__ ) ) -#endif - - #define INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE_2(TestName, TestFunc, Name, Tags, TmplList)\ - CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \ - CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ - CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \ - template<typename TestType> static void TestFunc(); \ - namespace {\ - namespace INTERNAL_CATCH_MAKE_NAMESPACE(TestName){\ - INTERNAL_CATCH_TYPE_GEN\ - template<typename... Types> \ - struct TestName { \ - void reg_tests() { \ - int index = 0; \ - using expander = int[]; \ - (void)expander{(Catch::AutoReg( Catch::makeTestInvoker( &TestFunc<Types> ), CATCH_INTERNAL_LINEINFO, Catch::StringRef(), Catch::NameAndTags{ Name " - " + std::string(INTERNAL_CATCH_STRINGIZE(TmplList)) + " - " + std::to_string(index), Tags } ), index++, 0)... };/* NOLINT */\ - } \ - };\ - static int INTERNAL_CATCH_UNIQUE_NAME( globalRegistrar ) = [](){ \ - using TestInit = typename convert<TestName, TmplList>::type; \ - TestInit t; \ - t.reg_tests(); \ - return 0; \ - }(); \ - }}\ - CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \ - template<typename TestType> \ - static void TestFunc() - - #define INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE(Name, Tags, TmplList) \ - INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE_2( INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_M_P_L_A_T_E____T_E_S_T____ ), INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_M_P_L_A_T_E____T_E_S_T____F_U_N_C____ ), Name, Tags, TmplList ) - - #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_2( TestNameClass, TestName, ClassName, Name, Tags, Signature, ... ) \ - CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \ - CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ - CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS \ - CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \ - namespace {\ - namespace INTERNAL_CATCH_MAKE_NAMESPACE(TestName){ \ - INTERNAL_CATCH_TYPE_GEN\ - INTERNAL_CATCH_NTTP_GEN(INTERNAL_CATCH_REMOVE_PARENS(Signature))\ - INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD(TestName, ClassName, INTERNAL_CATCH_REMOVE_PARENS(Signature));\ - INTERNAL_CATCH_NTTP_REG_METHOD_GEN(TestName, INTERNAL_CATCH_REMOVE_PARENS(Signature))\ - template<typename...Types> \ - struct TestNameClass{\ - TestNameClass(){\ - int index = 0; \ - constexpr char const* tmpl_types[] = {CATCH_REC_LIST(INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS, __VA_ARGS__)};\ - using expander = int[];\ - (void)expander{(reg_test(Types{}, #ClassName, Catch::NameAndTags{ Name " - " + std::string(tmpl_types[index]), Tags } ), index++, 0)... };/* NOLINT */ \ - }\ - };\ - static int INTERNAL_CATCH_UNIQUE_NAME( globalRegistrar ) = [](){\ - TestNameClass<INTERNAL_CATCH_MAKE_TYPE_LISTS_FROM_TYPES(__VA_ARGS__)>();\ - return 0;\ - }();\ - }\ - }\ - CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \ - INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD(TestName, INTERNAL_CATCH_REMOVE_PARENS(Signature)) - -#ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR - #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD( ClassName, Name, Tags,... ) \ - INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_2( INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_M_P_L_A_T_E____T_E_S_T____C_L_A_S_S____ ), INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_M_P_L_A_T_E____T_E_S_T____ ) , ClassName, Name, Tags, typename T, __VA_ARGS__ ) -#else - #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD( ClassName, Name, Tags,... ) \ - INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_2( INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_M_P_L_A_T_E____T_E_S_T____C_L_A_S_S____ ), INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_M_P_L_A_T_E____T_E_S_T____ ) , ClassName, Name, Tags, typename T, __VA_ARGS__ ) ) -#endif - -#ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR - #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG( ClassName, Name, Tags, Signature, ... ) \ - INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_2( INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_M_P_L_A_T_E____T_E_S_T____C_L_A_S_S____ ), INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_M_P_L_A_T_E____T_E_S_T____ ) , ClassName, Name, Tags, Signature, __VA_ARGS__ ) -#else - #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG( ClassName, Name, Tags, Signature, ... ) \ - INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_2( INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_M_P_L_A_T_E____T_E_S_T____C_L_A_S_S____ ), INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_M_P_L_A_T_E____T_E_S_T____ ) , ClassName, Name, Tags, Signature, __VA_ARGS__ ) ) -#endif - - #define INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_2(TestNameClass, TestName, ClassName, Name, Tags, Signature, TmplTypes, TypesList)\ - CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \ - CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ - CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS \ - CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \ - template<typename TestType> \ - struct TestName : INTERNAL_CATCH_REMOVE_PARENS(ClassName <TestType>) { \ - void test();\ - };\ - namespace {\ - namespace INTERNAL_CATCH_MAKE_NAMESPACE(TestNameClass) {\ - INTERNAL_CATCH_TYPE_GEN \ - INTERNAL_CATCH_NTTP_GEN(INTERNAL_CATCH_REMOVE_PARENS(Signature))\ - template<typename...Types>\ - struct TestNameClass{\ - void reg_tests(){\ - int index = 0;\ - using expander = int[];\ - constexpr char const* tmpl_types[] = {CATCH_REC_LIST(INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS, INTERNAL_CATCH_REMOVE_PARENS(TmplTypes))};\ - constexpr char const* types_list[] = {CATCH_REC_LIST(INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS, INTERNAL_CATCH_REMOVE_PARENS(TypesList))};\ - constexpr auto num_types = sizeof(types_list) / sizeof(types_list[0]);\ - (void)expander{(Catch::AutoReg( Catch::makeTestInvoker( &TestName<Types>::test ), CATCH_INTERNAL_LINEINFO, #ClassName, Catch::NameAndTags{ Name " - " + std::string(tmpl_types[index / num_types]) + "<" + std::string(types_list[index % num_types]) + ">", Tags } ), index++, 0)... };/* NOLINT */ \ - }\ - };\ - static int INTERNAL_CATCH_UNIQUE_NAME( globalRegistrar ) = [](){\ - using TestInit = typename create<TestNameClass, decltype(get_wrapper<INTERNAL_CATCH_REMOVE_PARENS(TmplTypes)>()), TypeList<INTERNAL_CATCH_MAKE_TYPE_LISTS_FROM_TYPES(INTERNAL_CATCH_REMOVE_PARENS(TypesList))>>::type;\ - TestInit t;\ - t.reg_tests();\ - return 0;\ - }(); \ - }\ - }\ - CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \ - template<typename TestType> \ - void TestName<TestType>::test() - -#ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR - #define INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD( ClassName, Name, Tags, ... )\ - INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_2( INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_M_P_L_A_T_E____T_E_S_T____ ), INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_M_P_L_A_T_E____T_E_S_T____F_U_N_C____ ), ClassName, Name, Tags, typename T, __VA_ARGS__ ) -#else - #define INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD( ClassName, Name, Tags, ... )\ - INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_2( INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_M_P_L_A_T_E____T_E_S_T____ ), INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_M_P_L_A_T_E____T_E_S_T____F_U_N_C____ ), ClassName, Name, Tags, typename T,__VA_ARGS__ ) ) -#endif - -#ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR - #define INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( ClassName, Name, Tags, Signature, ... )\ - INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_2( INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_M_P_L_A_T_E____T_E_S_T____ ), INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_M_P_L_A_T_E____T_E_S_T____F_U_N_C____ ), ClassName, Name, Tags, Signature, __VA_ARGS__ ) -#else - #define INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( ClassName, Name, Tags, Signature, ... )\ - INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_2( INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_M_P_L_A_T_E____T_E_S_T____ ), INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_M_P_L_A_T_E____T_E_S_T____F_U_N_C____ ), ClassName, Name, Tags, Signature,__VA_ARGS__ ) ) -#endif - - #define INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE_METHOD_2( TestNameClass, TestName, ClassName, Name, Tags, TmplList) \ - CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \ - CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ - CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \ - template<typename TestType> \ - struct TestName : INTERNAL_CATCH_REMOVE_PARENS(ClassName <TestType>) { \ - void test();\ - };\ - namespace {\ - namespace INTERNAL_CATCH_MAKE_NAMESPACE(TestName){ \ - INTERNAL_CATCH_TYPE_GEN\ - template<typename...Types>\ - struct TestNameClass{\ - void reg_tests(){\ - int index = 0;\ - using expander = int[];\ - (void)expander{(Catch::AutoReg( Catch::makeTestInvoker( &TestName<Types>::test ), CATCH_INTERNAL_LINEINFO, #ClassName, Catch::NameAndTags{ Name " - " + std::string(INTERNAL_CATCH_STRINGIZE(TmplList)) + " - " + std::to_string(index), Tags } ), index++, 0)... };/* NOLINT */ \ - }\ - };\ - static int INTERNAL_CATCH_UNIQUE_NAME( globalRegistrar ) = [](){\ - using TestInit = typename convert<TestNameClass, TmplList>::type;\ - TestInit t;\ - t.reg_tests();\ - return 0;\ - }(); \ - }}\ - CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \ - template<typename TestType> \ - void TestName<TestType>::test() - -#define INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE_METHOD(ClassName, Name, Tags, TmplList) \ - INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE_METHOD_2( INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_M_P_L_A_T_E____T_E_S_T____ ), INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_M_P_L_A_T_E____T_E_S_T____F_U_N_C____ ), ClassName, Name, Tags, TmplList ) - -// end catch_test_registry.h -// start catch_capture.hpp - -// start catch_assertionhandler.h - -// start catch_assertioninfo.h - -// start catch_result_type.h - -namespace Catch { - - // ResultWas::OfType enum - struct ResultWas { enum OfType { - Unknown = -1, - Ok = 0, - Info = 1, - Warning = 2, - - FailureBit = 0x10, - - ExpressionFailed = FailureBit | 1, - ExplicitFailure = FailureBit | 2, - - Exception = 0x100 | FailureBit, - - ThrewException = Exception | 1, - DidntThrowException = Exception | 2, - - FatalErrorCondition = 0x200 | FailureBit - - }; }; - - bool isOk( ResultWas::OfType resultType ); - bool isJustInfo( int flags ); - - // ResultDisposition::Flags enum - struct ResultDisposition { enum Flags { - Normal = 0x01, - - ContinueOnFailure = 0x02, // Failures fail test, but execution continues - FalseTest = 0x04, // Prefix expression with ! - SuppressFail = 0x08 // Failures are reported but do not fail the test - }; }; - - ResultDisposition::Flags operator | ( ResultDisposition::Flags lhs, ResultDisposition::Flags rhs ); - - bool shouldContinueOnFailure( int flags ); - inline bool isFalseTest( int flags ) { return ( flags & ResultDisposition::FalseTest ) != 0; } - bool shouldSuppressFailure( int flags ); - -} // end namespace Catch - -// end catch_result_type.h -namespace Catch { - - struct AssertionInfo - { - StringRef macroName; - SourceLineInfo lineInfo; - StringRef capturedExpression; - ResultDisposition::Flags resultDisposition; - - // We want to delete this constructor but a compiler bug in 4.8 means - // the struct is then treated as non-aggregate - //AssertionInfo() = delete; - }; - -} // end namespace Catch - -// end catch_assertioninfo.h -// start catch_decomposer.h - -// start catch_tostring.h - -#include <vector> -#include <cstddef> -#include <type_traits> -#include <string> -// start catch_stream.h - -#include <iosfwd> -#include <cstddef> -#include <ostream> - -namespace Catch { - - std::ostream& cout(); - std::ostream& cerr(); - std::ostream& clog(); - - class StringRef; - - struct IStream { - virtual ~IStream(); - virtual std::ostream& stream() const = 0; - }; - - auto makeStream( StringRef const &filename ) -> IStream const*; - - class ReusableStringStream : NonCopyable { - std::size_t m_index; - std::ostream* m_oss; - public: - ReusableStringStream(); - ~ReusableStringStream(); - - auto str() const -> std::string; - - template<typename T> - auto operator << ( T const& value ) -> ReusableStringStream& { - *m_oss << value; - return *this; - } - auto get() -> std::ostream& { return *m_oss; } - }; -} - -// end catch_stream.h -// start catch_interfaces_enum_values_registry.h - -#include <vector> - -namespace Catch { - - namespace Detail { - struct EnumInfo { - StringRef m_name; - std::vector<std::pair<int, StringRef>> m_values; - - ~EnumInfo(); - - StringRef lookup( int value ) const; - }; - } // namespace Detail - - struct IMutableEnumValuesRegistry { - virtual ~IMutableEnumValuesRegistry(); - - virtual Detail::EnumInfo const& registerEnum( StringRef enumName, StringRef allEnums, std::vector<int> const& values ) = 0; - - template<typename E> - Detail::EnumInfo const& registerEnum( StringRef enumName, StringRef allEnums, std::initializer_list<E> values ) { - static_assert(sizeof(int) >= sizeof(E), "Cannot serialize enum to int"); - std::vector<int> intValues; - intValues.reserve( values.size() ); - for( auto enumValue : values ) - intValues.push_back( static_cast<int>( enumValue ) ); - return registerEnum( enumName, allEnums, intValues ); - } - }; - -} // Catch - -// end catch_interfaces_enum_values_registry.h - -#ifdef CATCH_CONFIG_CPP17_STRING_VIEW -#include <string_view> -#endif - -#ifdef __OBJC__ -// start catch_objc_arc.hpp - -#import <Foundation/Foundation.h> - -#ifdef __has_feature -#define CATCH_ARC_ENABLED __has_feature(objc_arc) -#else -#define CATCH_ARC_ENABLED 0 -#endif - -void arcSafeRelease( NSObject* obj ); -id performOptionalSelector( id obj, SEL sel ); - -#if !CATCH_ARC_ENABLED -inline void arcSafeRelease( NSObject* obj ) { - [obj release]; -} -inline id performOptionalSelector( id obj, SEL sel ) { - if( [obj respondsToSelector: sel] ) - return [obj performSelector: sel]; - return nil; -} -#define CATCH_UNSAFE_UNRETAINED -#define CATCH_ARC_STRONG -#else -inline void arcSafeRelease( NSObject* ){} -inline id performOptionalSelector( id obj, SEL sel ) { -#ifdef __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Warc-performSelector-leaks" -#endif - if( [obj respondsToSelector: sel] ) - return [obj performSelector: sel]; -#ifdef __clang__ -#pragma clang diagnostic pop -#endif - return nil; -} -#define CATCH_UNSAFE_UNRETAINED __unsafe_unretained -#define CATCH_ARC_STRONG __strong -#endif - -// end catch_objc_arc.hpp -#endif - -#ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable:4180) // We attempt to stream a function (address) by const&, which MSVC complains about but is harmless -#endif - -namespace Catch { - namespace Detail { - - extern const std::string unprintableString; - - std::string rawMemoryToString( const void *object, std::size_t size ); - - template<typename T> - std::string rawMemoryToString( const T& object ) { - return rawMemoryToString( &object, sizeof(object) ); - } - - template<typename T> - class IsStreamInsertable { - template<typename Stream, typename U> - static auto test(int) - -> decltype(std::declval<Stream&>() << std::declval<U>(), std::true_type()); - - template<typename, typename> - static auto test(...)->std::false_type; - - public: - static const bool value = decltype(test<std::ostream, const T&>(0))::value; - }; - - template<typename E> - std::string convertUnknownEnumToString( E e ); - - template<typename T> - typename std::enable_if< - !std::is_enum<T>::value && !std::is_base_of<std::exception, T>::value, - std::string>::type convertUnstreamable( T const& ) { - return Detail::unprintableString; - } - template<typename T> - typename std::enable_if< - !std::is_enum<T>::value && std::is_base_of<std::exception, T>::value, - std::string>::type convertUnstreamable(T const& ex) { - return ex.what(); - } - - template<typename T> - typename std::enable_if< - std::is_enum<T>::value - , std::string>::type convertUnstreamable( T const& value ) { - return convertUnknownEnumToString( value ); - } - -#if defined(_MANAGED) - //! Convert a CLR string to a utf8 std::string - template<typename T> - std::string clrReferenceToString( T^ ref ) { - if (ref == nullptr) - return std::string("null"); - auto bytes = System::Text::Encoding::UTF8->GetBytes(ref->ToString()); - cli::pin_ptr<System::Byte> p = &bytes[0]; - return std::string(reinterpret_cast<char const *>(p), bytes->Length); - } -#endif - - } // namespace Detail - - // If we decide for C++14, change these to enable_if_ts - template <typename T, typename = void> - struct StringMaker { - template <typename Fake = T> - static - typename std::enable_if<::Catch::Detail::IsStreamInsertable<Fake>::value, std::string>::type - convert(const Fake& value) { - ReusableStringStream rss; - // NB: call using the function-like syntax to avoid ambiguity with - // user-defined templated operator<< under clang. - rss.operator<<(value); - return rss.str(); - } - - template <typename Fake = T> - static - typename std::enable_if<!::Catch::Detail::IsStreamInsertable<Fake>::value, std::string>::type - convert( const Fake& value ) { -#if !defined(CATCH_CONFIG_FALLBACK_STRINGIFIER) - return Detail::convertUnstreamable(value); -#else - return CATCH_CONFIG_FALLBACK_STRINGIFIER(value); -#endif - } - }; - - namespace Detail { - - // This function dispatches all stringification requests inside of Catch. - // Should be preferably called fully qualified, like ::Catch::Detail::stringify - template <typename T> - std::string stringify(const T& e) { - return ::Catch::StringMaker<typename std::remove_cv<typename std::remove_reference<T>::type>::type>::convert(e); - } - - template<typename E> - std::string convertUnknownEnumToString( E e ) { - return ::Catch::Detail::stringify(static_cast<typename std::underlying_type<E>::type>(e)); - } - -#if defined(_MANAGED) - template <typename T> - std::string stringify( T^ e ) { - return ::Catch::StringMaker<T^>::convert(e); - } -#endif - - } // namespace Detail - - // Some predefined specializations - - template<> - struct StringMaker<std::string> { - static std::string convert(const std::string& str); - }; - -#ifdef CATCH_CONFIG_CPP17_STRING_VIEW - template<> - struct StringMaker<std::string_view> { - static std::string convert(std::string_view str); - }; -#endif - - template<> - struct StringMaker<char const *> { - static std::string convert(char const * str); - }; - template<> - struct StringMaker<char *> { - static std::string convert(char * str); - }; - -#ifdef CATCH_CONFIG_WCHAR - template<> - struct StringMaker<std::wstring> { - static std::string convert(const std::wstring& wstr); - }; - -# ifdef CATCH_CONFIG_CPP17_STRING_VIEW - template<> - struct StringMaker<std::wstring_view> { - static std::string convert(std::wstring_view str); - }; -# endif - - template<> - struct StringMaker<wchar_t const *> { - static std::string convert(wchar_t const * str); - }; - template<> - struct StringMaker<wchar_t *> { - static std::string convert(wchar_t * str); - }; -#endif - - // TBD: Should we use `strnlen` to ensure that we don't go out of the buffer, - // while keeping string semantics? - template<int SZ> - struct StringMaker<char[SZ]> { - static std::string convert(char const* str) { - return ::Catch::Detail::stringify(std::string{ str }); - } - }; - template<int SZ> - struct StringMaker<signed char[SZ]> { - static std::string convert(signed char const* str) { - return ::Catch::Detail::stringify(std::string{ reinterpret_cast<char const *>(str) }); - } - }; - template<int SZ> - struct StringMaker<unsigned char[SZ]> { - static std::string convert(unsigned char const* str) { - return ::Catch::Detail::stringify(std::string{ reinterpret_cast<char const *>(str) }); - } - }; - -#if defined(CATCH_CONFIG_CPP17_BYTE) - template<> - struct StringMaker<std::byte> { - static std::string convert(std::byte value); - }; -#endif // defined(CATCH_CONFIG_CPP17_BYTE) - template<> - struct StringMaker<int> { - static std::string convert(int value); - }; - template<> - struct StringMaker<long> { - static std::string convert(long value); - }; - template<> - struct StringMaker<long long> { - static std::string convert(long long value); - }; - template<> - struct StringMaker<unsigned int> { - static std::string convert(unsigned int value); - }; - template<> - struct StringMaker<unsigned long> { - static std::string convert(unsigned long value); - }; - template<> - struct StringMaker<unsigned long long> { - static std::string convert(unsigned long long value); - }; - - template<> - struct StringMaker<bool> { - static std::string convert(bool b); - }; - - template<> - struct StringMaker<char> { - static std::string convert(char c); - }; - template<> - struct StringMaker<signed char> { - static std::string convert(signed char c); - }; - template<> - struct StringMaker<unsigned char> { - static std::string convert(unsigned char c); - }; - - template<> - struct StringMaker<std::nullptr_t> { - static std::string convert(std::nullptr_t); - }; - - template<> - struct StringMaker<float> { - static std::string convert(float value); - static int precision; - }; - - template<> - struct StringMaker<double> { - static std::string convert(double value); - static int precision; - }; - - template <typename T> - struct StringMaker<T*> { - template <typename U> - static std::string convert(U* p) { - if (p) { - return ::Catch::Detail::rawMemoryToString(p); - } else { - return "nullptr"; - } - } - }; - - template <typename R, typename C> - struct StringMaker<R C::*> { - static std::string convert(R C::* p) { - if (p) { - return ::Catch::Detail::rawMemoryToString(p); - } else { - return "nullptr"; - } - } - }; - -#if defined(_MANAGED) - template <typename T> - struct StringMaker<T^> { - static std::string convert( T^ ref ) { - return ::Catch::Detail::clrReferenceToString(ref); - } - }; -#endif - - namespace Detail { - template<typename InputIterator> - std::string rangeToString(InputIterator first, InputIterator last) { - ReusableStringStream rss; - rss << "{ "; - if (first != last) { - rss << ::Catch::Detail::stringify(*first); - for (++first; first != last; ++first) - rss << ", " << ::Catch::Detail::stringify(*first); - } - rss << " }"; - return rss.str(); - } - } - -#ifdef __OBJC__ - template<> - struct StringMaker<NSString*> { - static std::string convert(NSString * nsstring) { - if (!nsstring) - return "nil"; - return std::string("@") + [nsstring UTF8String]; - } - }; - template<> - struct StringMaker<NSObject*> { - static std::string convert(NSObject* nsObject) { - return ::Catch::Detail::stringify([nsObject description]); - } - - }; - namespace Detail { - inline std::string stringify( NSString* nsstring ) { - return StringMaker<NSString*>::convert( nsstring ); - } - - } // namespace Detail -#endif // __OBJC__ - -} // namespace Catch - -////////////////////////////////////////////////////// -// Separate std-lib types stringification, so it can be selectively enabled -// This means that we do not bring in - -#if defined(CATCH_CONFIG_ENABLE_ALL_STRINGMAKERS) -# define CATCH_CONFIG_ENABLE_PAIR_STRINGMAKER -# define CATCH_CONFIG_ENABLE_TUPLE_STRINGMAKER -# define CATCH_CONFIG_ENABLE_VARIANT_STRINGMAKER -# define CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER -# define CATCH_CONFIG_ENABLE_OPTIONAL_STRINGMAKER -#endif - -// Separate std::pair specialization -#if defined(CATCH_CONFIG_ENABLE_PAIR_STRINGMAKER) -#include <utility> -namespace Catch { - template<typename T1, typename T2> - struct StringMaker<std::pair<T1, T2> > { - static std::string convert(const std::pair<T1, T2>& pair) { - ReusableStringStream rss; - rss << "{ " - << ::Catch::Detail::stringify(pair.first) - << ", " - << ::Catch::Detail::stringify(pair.second) - << " }"; - return rss.str(); - } - }; -} -#endif // CATCH_CONFIG_ENABLE_PAIR_STRINGMAKER - -#if defined(CATCH_CONFIG_ENABLE_OPTIONAL_STRINGMAKER) && defined(CATCH_CONFIG_CPP17_OPTIONAL) -#include <optional> -namespace Catch { - template<typename T> - struct StringMaker<std::optional<T> > { - static std::string convert(const std::optional<T>& optional) { - ReusableStringStream rss; - if (optional.has_value()) { - rss << ::Catch::Detail::stringify(*optional); - } else { - rss << "{ }"; - } - return rss.str(); - } - }; -} -#endif // CATCH_CONFIG_ENABLE_OPTIONAL_STRINGMAKER - -// Separate std::tuple specialization -#if defined(CATCH_CONFIG_ENABLE_TUPLE_STRINGMAKER) -#include <tuple> -namespace Catch { - namespace Detail { - template< - typename Tuple, - std::size_t N = 0, - bool = (N < std::tuple_size<Tuple>::value) - > - struct TupleElementPrinter { - static void print(const Tuple& tuple, std::ostream& os) { - os << (N ? ", " : " ") - << ::Catch::Detail::stringify(std::get<N>(tuple)); - TupleElementPrinter<Tuple, N + 1>::print(tuple, os); - } - }; - - template< - typename Tuple, - std::size_t N - > - struct TupleElementPrinter<Tuple, N, false> { - static void print(const Tuple&, std::ostream&) {} - }; - - } - - template<typename ...Types> - struct StringMaker<std::tuple<Types...>> { - static std::string convert(const std::tuple<Types...>& tuple) { - ReusableStringStream rss; - rss << '{'; - Detail::TupleElementPrinter<std::tuple<Types...>>::print(tuple, rss.get()); - rss << " }"; - return rss.str(); - } - }; -} -#endif // CATCH_CONFIG_ENABLE_TUPLE_STRINGMAKER - -#if defined(CATCH_CONFIG_ENABLE_VARIANT_STRINGMAKER) && defined(CATCH_CONFIG_CPP17_VARIANT) -#include <variant> -namespace Catch { - template<> - struct StringMaker<std::monostate> { - static std::string convert(const std::monostate&) { - return "{ }"; - } - }; - - template<typename... Elements> - struct StringMaker<std::variant<Elements...>> { - static std::string convert(const std::variant<Elements...>& variant) { - if (variant.valueless_by_exception()) { - return "{valueless variant}"; - } else { - return std::visit( - [](const auto& value) { - return ::Catch::Detail::stringify(value); - }, - variant - ); - } - } - }; -} -#endif // CATCH_CONFIG_ENABLE_VARIANT_STRINGMAKER - -namespace Catch { - struct not_this_one {}; // Tag type for detecting which begin/ end are being selected - - // Import begin/ end from std here so they are considered alongside the fallback (...) overloads in this namespace - using std::begin; - using std::end; - - not_this_one begin( ... ); - not_this_one end( ... ); - - template <typename T> - struct is_range { - static const bool value = - !std::is_same<decltype(begin(std::declval<T>())), not_this_one>::value && - !std::is_same<decltype(end(std::declval<T>())), not_this_one>::value; - }; - -#if defined(_MANAGED) // Managed types are never ranges - template <typename T> - struct is_range<T^> { - static const bool value = false; - }; -#endif - - template<typename Range> - std::string rangeToString( Range const& range ) { - return ::Catch::Detail::rangeToString( begin( range ), end( range ) ); - } - - // Handle vector<bool> specially - template<typename Allocator> - std::string rangeToString( std::vector<bool, Allocator> const& v ) { - ReusableStringStream rss; - rss << "{ "; - bool first = true; - for( bool b : v ) { - if( first ) - first = false; - else - rss << ", "; - rss << ::Catch::Detail::stringify( b ); - } - rss << " }"; - return rss.str(); - } - - template<typename R> - struct StringMaker<R, typename std::enable_if<is_range<R>::value && !::Catch::Detail::IsStreamInsertable<R>::value>::type> { - static std::string convert( R const& range ) { - return rangeToString( range ); - } - }; - - template <typename T, int SZ> - struct StringMaker<T[SZ]> { - static std::string convert(T const(&arr)[SZ]) { - return rangeToString(arr); - } - }; - -} // namespace Catch - -// Separate std::chrono::duration specialization -#if defined(CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER) -#include <ctime> -#include <ratio> -#include <chrono> - -namespace Catch { - -template <class Ratio> -struct ratio_string { - static std::string symbol(); -}; - -template <class Ratio> -std::string ratio_string<Ratio>::symbol() { - Catch::ReusableStringStream rss; - rss << '[' << Ratio::num << '/' - << Ratio::den << ']'; - return rss.str(); -} -template <> -struct ratio_string<std::atto> { - static std::string symbol(); -}; -template <> -struct ratio_string<std::femto> { - static std::string symbol(); -}; -template <> -struct ratio_string<std::pico> { - static std::string symbol(); -}; -template <> -struct ratio_string<std::nano> { - static std::string symbol(); -}; -template <> -struct ratio_string<std::micro> { - static std::string symbol(); -}; -template <> -struct ratio_string<std::milli> { - static std::string symbol(); -}; - - //////////// - // std::chrono::duration specializations - template<typename Value, typename Ratio> - struct StringMaker<std::chrono::duration<Value, Ratio>> { - static std::string convert(std::chrono::duration<Value, Ratio> const& duration) { - ReusableStringStream rss; - rss << duration.count() << ' ' << ratio_string<Ratio>::symbol() << 's'; - return rss.str(); - } - }; - template<typename Value> - struct StringMaker<std::chrono::duration<Value, std::ratio<1>>> { - static std::string convert(std::chrono::duration<Value, std::ratio<1>> const& duration) { - ReusableStringStream rss; - rss << duration.count() << " s"; - return rss.str(); - } - }; - template<typename Value> - struct StringMaker<std::chrono::duration<Value, std::ratio<60>>> { - static std::string convert(std::chrono::duration<Value, std::ratio<60>> const& duration) { - ReusableStringStream rss; - rss << duration.count() << " m"; - return rss.str(); - } - }; - template<typename Value> - struct StringMaker<std::chrono::duration<Value, std::ratio<3600>>> { - static std::string convert(std::chrono::duration<Value, std::ratio<3600>> const& duration) { - ReusableStringStream rss; - rss << duration.count() << " h"; - return rss.str(); - } - }; - - //////////// - // std::chrono::time_point specialization - // Generic time_point cannot be specialized, only std::chrono::time_point<system_clock> - template<typename Clock, typename Duration> - struct StringMaker<std::chrono::time_point<Clock, Duration>> { - static std::string convert(std::chrono::time_point<Clock, Duration> const& time_point) { - return ::Catch::Detail::stringify(time_point.time_since_epoch()) + " since epoch"; - } - }; - // std::chrono::time_point<system_clock> specialization - template<typename Duration> - struct StringMaker<std::chrono::time_point<std::chrono::system_clock, Duration>> { - static std::string convert(std::chrono::time_point<std::chrono::system_clock, Duration> const& time_point) { - auto converted = std::chrono::system_clock::to_time_t(time_point); - -#ifdef _MSC_VER - std::tm timeInfo = {}; - gmtime_s(&timeInfo, &converted); -#else - std::tm* timeInfo = std::gmtime(&converted); -#endif - - auto const timeStampSize = sizeof("2017-01-16T17:06:45Z"); - char timeStamp[timeStampSize]; - const char * const fmt = "%Y-%m-%dT%H:%M:%SZ"; - -#ifdef _MSC_VER - std::strftime(timeStamp, timeStampSize, fmt, &timeInfo); -#else - std::strftime(timeStamp, timeStampSize, fmt, timeInfo); -#endif - return std::string(timeStamp); - } - }; -} -#endif // CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER - -#define INTERNAL_CATCH_REGISTER_ENUM( enumName, ... ) \ -namespace Catch { \ - template<> struct StringMaker<enumName> { \ - static std::string convert( enumName value ) { \ - static const auto& enumInfo = ::Catch::getMutableRegistryHub().getMutableEnumValuesRegistry().registerEnum( #enumName, #__VA_ARGS__, { __VA_ARGS__ } ); \ - return static_cast<std::string>(enumInfo.lookup( static_cast<int>( value ) )); \ - } \ - }; \ -} - -#define CATCH_REGISTER_ENUM( enumName, ... ) INTERNAL_CATCH_REGISTER_ENUM( enumName, __VA_ARGS__ ) - -#ifdef _MSC_VER -#pragma warning(pop) -#endif - -// end catch_tostring.h -#include <iosfwd> - -#ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable:4389) // '==' : signed/unsigned mismatch -#pragma warning(disable:4018) // more "signed/unsigned mismatch" -#pragma warning(disable:4312) // Converting int to T* using reinterpret_cast (issue on x64 platform) -#pragma warning(disable:4180) // qualifier applied to function type has no meaning -#pragma warning(disable:4800) // Forcing result to true or false -#endif - -namespace Catch { - - struct ITransientExpression { - auto isBinaryExpression() const -> bool { return m_isBinaryExpression; } - auto getResult() const -> bool { return m_result; } - virtual void streamReconstructedExpression( std::ostream &os ) const = 0; - - ITransientExpression( bool isBinaryExpression, bool result ) - : m_isBinaryExpression( isBinaryExpression ), - m_result( result ) - {} - - // We don't actually need a virtual destructor, but many static analyzers - // complain if it's not here :-( - virtual ~ITransientExpression(); - - bool m_isBinaryExpression; - bool m_result; - - }; - - void formatReconstructedExpression( std::ostream &os, std::string const& lhs, StringRef op, std::string const& rhs ); - - template<typename LhsT, typename RhsT> - class BinaryExpr : public ITransientExpression { - LhsT m_lhs; - StringRef m_op; - RhsT m_rhs; - - void streamReconstructedExpression( std::ostream &os ) const override { - formatReconstructedExpression - ( os, Catch::Detail::stringify( m_lhs ), m_op, Catch::Detail::stringify( m_rhs ) ); - } - - public: - BinaryExpr( bool comparisonResult, LhsT lhs, StringRef op, RhsT rhs ) - : ITransientExpression{ true, comparisonResult }, - m_lhs( lhs ), - m_op( op ), - m_rhs( rhs ) - {} - - template<typename T> - auto operator && ( T ) const -> BinaryExpr<LhsT, RhsT const&> const { - static_assert(always_false<T>::value, - "chained comparisons are not supported inside assertions, " - "wrap the expression inside parentheses, or decompose it"); - } - - template<typename T> - auto operator || ( T ) const -> BinaryExpr<LhsT, RhsT const&> const { - static_assert(always_false<T>::value, - "chained comparisons are not supported inside assertions, " - "wrap the expression inside parentheses, or decompose it"); - } - - template<typename T> - auto operator == ( T ) const -> BinaryExpr<LhsT, RhsT const&> const { - static_assert(always_false<T>::value, - "chained comparisons are not supported inside assertions, " - "wrap the expression inside parentheses, or decompose it"); - } - - template<typename T> - auto operator != ( T ) const -> BinaryExpr<LhsT, RhsT const&> const { - static_assert(always_false<T>::value, - "chained comparisons are not supported inside assertions, " - "wrap the expression inside parentheses, or decompose it"); - } - - template<typename T> - auto operator > ( T ) const -> BinaryExpr<LhsT, RhsT const&> const { - static_assert(always_false<T>::value, - "chained comparisons are not supported inside assertions, " - "wrap the expression inside parentheses, or decompose it"); - } - - template<typename T> - auto operator < ( T ) const -> BinaryExpr<LhsT, RhsT const&> const { - static_assert(always_false<T>::value, - "chained comparisons are not supported inside assertions, " - "wrap the expression inside parentheses, or decompose it"); - } - - template<typename T> - auto operator >= ( T ) const -> BinaryExpr<LhsT, RhsT const&> const { - static_assert(always_false<T>::value, - "chained comparisons are not supported inside assertions, " - "wrap the expression inside parentheses, or decompose it"); - } - - template<typename T> - auto operator <= ( T ) const -> BinaryExpr<LhsT, RhsT const&> const { - static_assert(always_false<T>::value, - "chained comparisons are not supported inside assertions, " - "wrap the expression inside parentheses, or decompose it"); - } - }; - - template<typename LhsT> - class UnaryExpr : public ITransientExpression { - LhsT m_lhs; - - void streamReconstructedExpression( std::ostream &os ) const override { - os << Catch::Detail::stringify( m_lhs ); - } - - public: - explicit UnaryExpr( LhsT lhs ) - : ITransientExpression{ false, static_cast<bool>(lhs) }, - m_lhs( lhs ) - {} - }; - - // Specialised comparison functions to handle equality comparisons between ints and pointers (NULL deduces as an int) - template<typename LhsT, typename RhsT> - auto compareEqual( LhsT const& lhs, RhsT const& rhs ) -> bool { return static_cast<bool>(lhs == rhs); } - template<typename T> - auto compareEqual( T* const& lhs, int rhs ) -> bool { return lhs == reinterpret_cast<void const*>( rhs ); } - template<typename T> - auto compareEqual( T* const& lhs, long rhs ) -> bool { return lhs == reinterpret_cast<void const*>( rhs ); } - template<typename T> - auto compareEqual( int lhs, T* const& rhs ) -> bool { return reinterpret_cast<void const*>( lhs ) == rhs; } - template<typename T> - auto compareEqual( long lhs, T* const& rhs ) -> bool { return reinterpret_cast<void const*>( lhs ) == rhs; } - - template<typename LhsT, typename RhsT> - auto compareNotEqual( LhsT const& lhs, RhsT&& rhs ) -> bool { return static_cast<bool>(lhs != rhs); } - template<typename T> - auto compareNotEqual( T* const& lhs, int rhs ) -> bool { return lhs != reinterpret_cast<void const*>( rhs ); } - template<typename T> - auto compareNotEqual( T* const& lhs, long rhs ) -> bool { return lhs != reinterpret_cast<void const*>( rhs ); } - template<typename T> - auto compareNotEqual( int lhs, T* const& rhs ) -> bool { return reinterpret_cast<void const*>( lhs ) != rhs; } - template<typename T> - auto compareNotEqual( long lhs, T* const& rhs ) -> bool { return reinterpret_cast<void const*>( lhs ) != rhs; } - - template<typename LhsT> - class ExprLhs { - LhsT m_lhs; - public: - explicit ExprLhs( LhsT lhs ) : m_lhs( lhs ) {} - - template<typename RhsT> - auto operator == ( RhsT const& rhs ) -> BinaryExpr<LhsT, RhsT const&> const { - return { compareEqual( m_lhs, rhs ), m_lhs, "==", rhs }; - } - auto operator == ( bool rhs ) -> BinaryExpr<LhsT, bool> const { - return { m_lhs == rhs, m_lhs, "==", rhs }; - } - - template<typename RhsT> - auto operator != ( RhsT const& rhs ) -> BinaryExpr<LhsT, RhsT const&> const { - return { compareNotEqual( m_lhs, rhs ), m_lhs, "!=", rhs }; - } - auto operator != ( bool rhs ) -> BinaryExpr<LhsT, bool> const { - return { m_lhs != rhs, m_lhs, "!=", rhs }; - } - - template<typename RhsT> - auto operator > ( RhsT const& rhs ) -> BinaryExpr<LhsT, RhsT const&> const { - return { static_cast<bool>(m_lhs > rhs), m_lhs, ">", rhs }; - } - template<typename RhsT> - auto operator < ( RhsT const& rhs ) -> BinaryExpr<LhsT, RhsT const&> const { - return { static_cast<bool>(m_lhs < rhs), m_lhs, "<", rhs }; - } - template<typename RhsT> - auto operator >= ( RhsT const& rhs ) -> BinaryExpr<LhsT, RhsT const&> const { - return { static_cast<bool>(m_lhs >= rhs), m_lhs, ">=", rhs }; - } - template<typename RhsT> - auto operator <= ( RhsT const& rhs ) -> BinaryExpr<LhsT, RhsT const&> const { - return { static_cast<bool>(m_lhs <= rhs), m_lhs, "<=", rhs }; - } - template <typename RhsT> - auto operator | (RhsT const& rhs) -> BinaryExpr<LhsT, RhsT const&> const { - return { static_cast<bool>(m_lhs | rhs), m_lhs, "|", rhs }; - } - template <typename RhsT> - auto operator & (RhsT const& rhs) -> BinaryExpr<LhsT, RhsT const&> const { - return { static_cast<bool>(m_lhs & rhs), m_lhs, "&", rhs }; - } - template <typename RhsT> - auto operator ^ (RhsT const& rhs) -> BinaryExpr<LhsT, RhsT const&> const { - return { static_cast<bool>(m_lhs ^ rhs), m_lhs, "^", rhs }; - } - - template<typename RhsT> - auto operator && ( RhsT const& ) -> BinaryExpr<LhsT, RhsT const&> const { - static_assert(always_false<RhsT>::value, - "operator&& is not supported inside assertions, " - "wrap the expression inside parentheses, or decompose it"); - } - - template<typename RhsT> - auto operator || ( RhsT const& ) -> BinaryExpr<LhsT, RhsT const&> const { - static_assert(always_false<RhsT>::value, - "operator|| is not supported inside assertions, " - "wrap the expression inside parentheses, or decompose it"); - } - - auto makeUnaryExpr() const -> UnaryExpr<LhsT> { - return UnaryExpr<LhsT>{ m_lhs }; - } - }; - - void handleExpression( ITransientExpression const& expr ); - - template<typename T> - void handleExpression( ExprLhs<T> const& expr ) { - handleExpression( expr.makeUnaryExpr() ); - } - - struct Decomposer { - template<typename T> - auto operator <= ( T const& lhs ) -> ExprLhs<T const&> { - return ExprLhs<T const&>{ lhs }; - } - - auto operator <=( bool value ) -> ExprLhs<bool> { - return ExprLhs<bool>{ value }; - } - }; - -} // end namespace Catch - -#ifdef _MSC_VER -#pragma warning(pop) -#endif - -// end catch_decomposer.h -// start catch_interfaces_capture.h - -#include <string> -#include <chrono> - -namespace Catch { - - class AssertionResult; - struct AssertionInfo; - struct SectionInfo; - struct SectionEndInfo; - struct MessageInfo; - struct MessageBuilder; - struct Counts; - struct AssertionReaction; - struct SourceLineInfo; - - struct ITransientExpression; - struct IGeneratorTracker; - -#if defined(CATCH_CONFIG_ENABLE_BENCHMARKING) - struct BenchmarkInfo; - template <typename Duration = std::chrono::duration<double, std::nano>> - struct BenchmarkStats; -#endif // CATCH_CONFIG_ENABLE_BENCHMARKING - - struct IResultCapture { - - virtual ~IResultCapture(); - - virtual bool sectionStarted( SectionInfo const& sectionInfo, - Counts& assertions ) = 0; - virtual void sectionEnded( SectionEndInfo const& endInfo ) = 0; - virtual void sectionEndedEarly( SectionEndInfo const& endInfo ) = 0; - - virtual auto acquireGeneratorTracker( SourceLineInfo const& lineInfo ) -> IGeneratorTracker& = 0; - -#if defined(CATCH_CONFIG_ENABLE_BENCHMARKING) - virtual void benchmarkPreparing( std::string const& name ) = 0; - virtual void benchmarkStarting( BenchmarkInfo const& info ) = 0; - virtual void benchmarkEnded( BenchmarkStats<> const& stats ) = 0; - virtual void benchmarkFailed( std::string const& error ) = 0; -#endif // CATCH_CONFIG_ENABLE_BENCHMARKING - - virtual void pushScopedMessage( MessageInfo const& message ) = 0; - virtual void popScopedMessage( MessageInfo const& message ) = 0; - - virtual void emplaceUnscopedMessage( MessageBuilder const& builder ) = 0; - - virtual void handleFatalErrorCondition( StringRef message ) = 0; - - virtual void handleExpr - ( AssertionInfo const& info, - ITransientExpression const& expr, - AssertionReaction& reaction ) = 0; - virtual void handleMessage - ( AssertionInfo const& info, - ResultWas::OfType resultType, - StringRef const& message, - AssertionReaction& reaction ) = 0; - virtual void handleUnexpectedExceptionNotThrown - ( AssertionInfo const& info, - AssertionReaction& reaction ) = 0; - virtual void handleUnexpectedInflightException - ( AssertionInfo const& info, - std::string const& message, - AssertionReaction& reaction ) = 0; - virtual void handleIncomplete - ( AssertionInfo const& info ) = 0; - virtual void handleNonExpr - ( AssertionInfo const &info, - ResultWas::OfType resultType, - AssertionReaction &reaction ) = 0; - - virtual bool lastAssertionPassed() = 0; - virtual void assertionPassed() = 0; - - // Deprecated, do not use: - virtual std::string getCurrentTestName() const = 0; - virtual const AssertionResult* getLastResult() const = 0; - virtual void exceptionEarlyReported() = 0; - }; - - IResultCapture& getResultCapture(); -} - -// end catch_interfaces_capture.h -namespace Catch { - - struct TestFailureException{}; - struct AssertionResultData; - struct IResultCapture; - class RunContext; - - class LazyExpression { - friend class AssertionHandler; - friend struct AssertionStats; - friend class RunContext; - - ITransientExpression const* m_transientExpression = nullptr; - bool m_isNegated; - public: - LazyExpression( bool isNegated ); - LazyExpression( LazyExpression const& other ); - LazyExpression& operator = ( LazyExpression const& ) = delete; - - explicit operator bool() const; - - friend auto operator << ( std::ostream& os, LazyExpression const& lazyExpr ) -> std::ostream&; - }; - - struct AssertionReaction { - bool shouldDebugBreak = false; - bool shouldThrow = false; - }; - - class AssertionHandler { - AssertionInfo m_assertionInfo; - AssertionReaction m_reaction; - bool m_completed = false; - IResultCapture& m_resultCapture; - - public: - AssertionHandler - ( StringRef const& macroName, - SourceLineInfo const& lineInfo, - StringRef capturedExpression, - ResultDisposition::Flags resultDisposition ); - ~AssertionHandler() { - if ( !m_completed ) { - m_resultCapture.handleIncomplete( m_assertionInfo ); - } - } - - template<typename T> - void handleExpr( ExprLhs<T> const& expr ) { - handleExpr( expr.makeUnaryExpr() ); - } - void handleExpr( ITransientExpression const& expr ); - - void handleMessage(ResultWas::OfType resultType, StringRef const& message); - - void handleExceptionThrownAsExpected(); - void handleUnexpectedExceptionNotThrown(); - void handleExceptionNotThrownAsExpected(); - void handleThrowingCallSkipped(); - void handleUnexpectedInflightException(); - - void complete(); - void setCompleted(); - - // query - auto allowThrows() const -> bool; - }; - - void handleExceptionMatchExpr( AssertionHandler& handler, std::string const& str, StringRef const& matcherString ); - -} // namespace Catch - -// end catch_assertionhandler.h -// start catch_message.h - -#include <string> -#include <vector> - -namespace Catch { - - struct MessageInfo { - MessageInfo( StringRef const& _macroName, - SourceLineInfo const& _lineInfo, - ResultWas::OfType _type ); - - StringRef macroName; - std::string message; - SourceLineInfo lineInfo; - ResultWas::OfType type; - unsigned int sequence; - - bool operator == ( MessageInfo const& other ) const; - bool operator < ( MessageInfo const& other ) const; - private: - static unsigned int globalCount; - }; - - struct MessageStream { - - template<typename T> - MessageStream& operator << ( T const& value ) { - m_stream << value; - return *this; - } - - ReusableStringStream m_stream; - }; - - struct MessageBuilder : MessageStream { - MessageBuilder( StringRef const& macroName, - SourceLineInfo const& lineInfo, - ResultWas::OfType type ); - - template<typename T> - MessageBuilder& operator << ( T const& value ) { - m_stream << value; - return *this; - } - - MessageInfo m_info; - }; - - class ScopedMessage { - public: - explicit ScopedMessage( MessageBuilder const& builder ); - ScopedMessage( ScopedMessage& duplicate ) = delete; - ScopedMessage( ScopedMessage&& old ); - ~ScopedMessage(); - - MessageInfo m_info; - bool m_moved; - }; - - class Capturer { - std::vector<MessageInfo> m_messages; - IResultCapture& m_resultCapture = getResultCapture(); - size_t m_captured = 0; - public: - Capturer( StringRef macroName, SourceLineInfo const& lineInfo, ResultWas::OfType resultType, StringRef names ); - ~Capturer(); - - void captureValue( size_t index, std::string const& value ); - - template<typename T> - void captureValues( size_t index, T const& value ) { - captureValue( index, Catch::Detail::stringify( value ) ); - } - - template<typename T, typename... Ts> - void captureValues( size_t index, T const& value, Ts const&... values ) { - captureValue( index, Catch::Detail::stringify(value) ); - captureValues( index+1, values... ); - } - }; - -} // end namespace Catch - -// end catch_message.h -#if !defined(CATCH_CONFIG_DISABLE) - -#if !defined(CATCH_CONFIG_DISABLE_STRINGIFICATION) - #define CATCH_INTERNAL_STRINGIFY(...) #__VA_ARGS__ -#else - #define CATCH_INTERNAL_STRINGIFY(...) "Disabled by CATCH_CONFIG_DISABLE_STRINGIFICATION" -#endif - -#if defined(CATCH_CONFIG_FAST_COMPILE) || defined(CATCH_CONFIG_DISABLE_EXCEPTIONS) - -/////////////////////////////////////////////////////////////////////////////// -// Another way to speed-up compilation is to omit local try-catch for REQUIRE* -// macros. -#define INTERNAL_CATCH_TRY -#define INTERNAL_CATCH_CATCH( capturer ) - -#else // CATCH_CONFIG_FAST_COMPILE - -#define INTERNAL_CATCH_TRY try -#define INTERNAL_CATCH_CATCH( handler ) catch(...) { handler.handleUnexpectedInflightException(); } - -#endif - -#define INTERNAL_CATCH_REACT( handler ) handler.complete(); - -/////////////////////////////////////////////////////////////////////////////// -#define INTERNAL_CATCH_TEST( macroName, resultDisposition, ... ) \ - do { \ - CATCH_INTERNAL_IGNORE_BUT_WARN(__VA_ARGS__); \ - Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__), resultDisposition ); \ - INTERNAL_CATCH_TRY { \ - CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \ - CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \ - catchAssertionHandler.handleExpr( Catch::Decomposer() <= __VA_ARGS__ ); \ - CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \ - } INTERNAL_CATCH_CATCH( catchAssertionHandler ) \ - INTERNAL_CATCH_REACT( catchAssertionHandler ) \ - } while( (void)0, (false) && static_cast<bool>( !!(__VA_ARGS__) ) ) - -/////////////////////////////////////////////////////////////////////////////// -#define INTERNAL_CATCH_IF( macroName, resultDisposition, ... ) \ - INTERNAL_CATCH_TEST( macroName, resultDisposition, __VA_ARGS__ ); \ - if( Catch::getResultCapture().lastAssertionPassed() ) - -/////////////////////////////////////////////////////////////////////////////// -#define INTERNAL_CATCH_ELSE( macroName, resultDisposition, ... ) \ - INTERNAL_CATCH_TEST( macroName, resultDisposition, __VA_ARGS__ ); \ - if( !Catch::getResultCapture().lastAssertionPassed() ) - -/////////////////////////////////////////////////////////////////////////////// -#define INTERNAL_CATCH_NO_THROW( macroName, resultDisposition, ... ) \ - do { \ - Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__), resultDisposition ); \ - try { \ - static_cast<void>(__VA_ARGS__); \ - catchAssertionHandler.handleExceptionNotThrownAsExpected(); \ - } \ - catch( ... ) { \ - catchAssertionHandler.handleUnexpectedInflightException(); \ - } \ - INTERNAL_CATCH_REACT( catchAssertionHandler ) \ - } while( false ) - -/////////////////////////////////////////////////////////////////////////////// -#define INTERNAL_CATCH_THROWS( macroName, resultDisposition, ... ) \ - do { \ - Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__), resultDisposition); \ - if( catchAssertionHandler.allowThrows() ) \ - try { \ - static_cast<void>(__VA_ARGS__); \ - catchAssertionHandler.handleUnexpectedExceptionNotThrown(); \ - } \ - catch( ... ) { \ - catchAssertionHandler.handleExceptionThrownAsExpected(); \ - } \ - else \ - catchAssertionHandler.handleThrowingCallSkipped(); \ - INTERNAL_CATCH_REACT( catchAssertionHandler ) \ - } while( false ) - -/////////////////////////////////////////////////////////////////////////////// -#define INTERNAL_CATCH_THROWS_AS( macroName, exceptionType, resultDisposition, expr ) \ - do { \ - Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(expr) ", " CATCH_INTERNAL_STRINGIFY(exceptionType), resultDisposition ); \ - if( catchAssertionHandler.allowThrows() ) \ - try { \ - static_cast<void>(expr); \ - catchAssertionHandler.handleUnexpectedExceptionNotThrown(); \ - } \ - catch( exceptionType const& ) { \ - catchAssertionHandler.handleExceptionThrownAsExpected(); \ - } \ - catch( ... ) { \ - catchAssertionHandler.handleUnexpectedInflightException(); \ - } \ - else \ - catchAssertionHandler.handleThrowingCallSkipped(); \ - INTERNAL_CATCH_REACT( catchAssertionHandler ) \ - } while( false ) - -/////////////////////////////////////////////////////////////////////////////// -#define INTERNAL_CATCH_MSG( macroName, messageType, resultDisposition, ... ) \ - do { \ - Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, Catch::StringRef(), resultDisposition ); \ - catchAssertionHandler.handleMessage( messageType, ( Catch::MessageStream() << __VA_ARGS__ + ::Catch::StreamEndStop() ).m_stream.str() ); \ - INTERNAL_CATCH_REACT( catchAssertionHandler ) \ - } while( false ) - -/////////////////////////////////////////////////////////////////////////////// -#define INTERNAL_CATCH_CAPTURE( varName, macroName, ... ) \ - auto varName = Catch::Capturer( macroName, CATCH_INTERNAL_LINEINFO, Catch::ResultWas::Info, #__VA_ARGS__ ); \ - varName.captureValues( 0, __VA_ARGS__ ) - -/////////////////////////////////////////////////////////////////////////////// -#define INTERNAL_CATCH_INFO( macroName, log ) \ - Catch::ScopedMessage INTERNAL_CATCH_UNIQUE_NAME( scopedMessage )( Catch::MessageBuilder( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, Catch::ResultWas::Info ) << log ); - -/////////////////////////////////////////////////////////////////////////////// -#define INTERNAL_CATCH_UNSCOPED_INFO( macroName, log ) \ - Catch::getResultCapture().emplaceUnscopedMessage( Catch::MessageBuilder( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, Catch::ResultWas::Info ) << log ) - -/////////////////////////////////////////////////////////////////////////////// -// Although this is matcher-based, it can be used with just a string -#define INTERNAL_CATCH_THROWS_STR_MATCHES( macroName, resultDisposition, matcher, ... ) \ - do { \ - Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__) ", " CATCH_INTERNAL_STRINGIFY(matcher), resultDisposition ); \ - if( catchAssertionHandler.allowThrows() ) \ - try { \ - static_cast<void>(__VA_ARGS__); \ - catchAssertionHandler.handleUnexpectedExceptionNotThrown(); \ - } \ - catch( ... ) { \ - Catch::handleExceptionMatchExpr( catchAssertionHandler, matcher, #matcher##_catch_sr ); \ - } \ - else \ - catchAssertionHandler.handleThrowingCallSkipped(); \ - INTERNAL_CATCH_REACT( catchAssertionHandler ) \ - } while( false ) - -#endif // CATCH_CONFIG_DISABLE - -// end catch_capture.hpp -// start catch_section.h - -// start catch_section_info.h - -// start catch_totals.h - -#include <cstddef> - -namespace Catch { - - struct Counts { - Counts operator - ( Counts const& other ) const; - Counts& operator += ( Counts const& other ); - - std::size_t total() const; - bool allPassed() const; - bool allOk() const; - - std::size_t passed = 0; - std::size_t failed = 0; - std::size_t failedButOk = 0; - }; - - struct Totals { - - Totals operator - ( Totals const& other ) const; - Totals& operator += ( Totals const& other ); - - Totals delta( Totals const& prevTotals ) const; - - int error = 0; - Counts assertions; - Counts testCases; - }; -} - -// end catch_totals.h -#include <string> - -namespace Catch { - - struct SectionInfo { - SectionInfo - ( SourceLineInfo const& _lineInfo, - std::string const& _name ); - - // Deprecated - SectionInfo - ( SourceLineInfo const& _lineInfo, - std::string const& _name, - std::string const& ) : SectionInfo( _lineInfo, _name ) {} - - std::string name; - std::string description; // !Deprecated: this will always be empty - SourceLineInfo lineInfo; - }; - - struct SectionEndInfo { - SectionInfo sectionInfo; - Counts prevAssertions; - double durationInSeconds; - }; - -} // end namespace Catch - -// end catch_section_info.h -// start catch_timer.h - -#include <cstdint> - -namespace Catch { - - auto getCurrentNanosecondsSinceEpoch() -> uint64_t; - auto getEstimatedClockResolution() -> uint64_t; - - class Timer { - uint64_t m_nanoseconds = 0; - public: - void start(); - auto getElapsedNanoseconds() const -> uint64_t; - auto getElapsedMicroseconds() const -> uint64_t; - auto getElapsedMilliseconds() const -> unsigned int; - auto getElapsedSeconds() const -> double; - }; - -} // namespace Catch - -// end catch_timer.h -#include <string> - -namespace Catch { - - class Section : NonCopyable { - public: - Section( SectionInfo const& info ); - ~Section(); - - // This indicates whether the section should be executed or not - explicit operator bool() const; - - private: - SectionInfo m_info; - - std::string m_name; - Counts m_assertions; - bool m_sectionIncluded; - Timer m_timer; - }; - -} // end namespace Catch - -#define INTERNAL_CATCH_SECTION( ... ) \ - CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \ - CATCH_INTERNAL_SUPPRESS_UNUSED_WARNINGS \ - if( Catch::Section const& INTERNAL_CATCH_UNIQUE_NAME( catch_internal_Section ) = Catch::SectionInfo( CATCH_INTERNAL_LINEINFO, __VA_ARGS__ ) ) \ - CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION - -#define INTERNAL_CATCH_DYNAMIC_SECTION( ... ) \ - CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \ - CATCH_INTERNAL_SUPPRESS_UNUSED_WARNINGS \ - if( Catch::Section const& INTERNAL_CATCH_UNIQUE_NAME( catch_internal_Section ) = Catch::SectionInfo( CATCH_INTERNAL_LINEINFO, (Catch::ReusableStringStream() << __VA_ARGS__).str() ) ) \ - CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION - -// end catch_section.h -// start catch_interfaces_exception.h - -// start catch_interfaces_registry_hub.h - -#include <string> -#include <memory> - -namespace Catch { - - class TestCase; - struct ITestCaseRegistry; - struct IExceptionTranslatorRegistry; - struct IExceptionTranslator; - struct IReporterRegistry; - struct IReporterFactory; - struct ITagAliasRegistry; - struct IMutableEnumValuesRegistry; - - class StartupExceptionRegistry; - - using IReporterFactoryPtr = std::shared_ptr<IReporterFactory>; - - struct IRegistryHub { - virtual ~IRegistryHub(); - - virtual IReporterRegistry const& getReporterRegistry() const = 0; - virtual ITestCaseRegistry const& getTestCaseRegistry() const = 0; - virtual ITagAliasRegistry const& getTagAliasRegistry() const = 0; - virtual IExceptionTranslatorRegistry const& getExceptionTranslatorRegistry() const = 0; - - virtual StartupExceptionRegistry const& getStartupExceptionRegistry() const = 0; - }; - - struct IMutableRegistryHub { - virtual ~IMutableRegistryHub(); - virtual void registerReporter( std::string const& name, IReporterFactoryPtr const& factory ) = 0; - virtual void registerListener( IReporterFactoryPtr const& factory ) = 0; - virtual void registerTest( TestCase const& testInfo ) = 0; - virtual void registerTranslator( const IExceptionTranslator* translator ) = 0; - virtual void registerTagAlias( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo ) = 0; - virtual void registerStartupException() noexcept = 0; - virtual IMutableEnumValuesRegistry& getMutableEnumValuesRegistry() = 0; - }; - - IRegistryHub const& getRegistryHub(); - IMutableRegistryHub& getMutableRegistryHub(); - void cleanUp(); - std::string translateActiveException(); - -} - -// end catch_interfaces_registry_hub.h -#if defined(CATCH_CONFIG_DISABLE) - #define INTERNAL_CATCH_TRANSLATE_EXCEPTION_NO_REG( translatorName, signature) \ - static std::string translatorName( signature ) -#endif - -#include <exception> -#include <string> -#include <vector> - -namespace Catch { - using exceptionTranslateFunction = std::string(*)(); - - struct IExceptionTranslator; - using ExceptionTranslators = std::vector<std::unique_ptr<IExceptionTranslator const>>; - - struct IExceptionTranslator { - virtual ~IExceptionTranslator(); - virtual std::string translate( ExceptionTranslators::const_iterator it, ExceptionTranslators::const_iterator itEnd ) const = 0; - }; - - struct IExceptionTranslatorRegistry { - virtual ~IExceptionTranslatorRegistry(); - - virtual std::string translateActiveException() const = 0; - }; - - class ExceptionTranslatorRegistrar { - template<typename T> - class ExceptionTranslator : public IExceptionTranslator { - public: - - ExceptionTranslator( std::string(*translateFunction)( T& ) ) - : m_translateFunction( translateFunction ) - {} - - std::string translate( ExceptionTranslators::const_iterator it, ExceptionTranslators::const_iterator itEnd ) const override { -#if defined(CATCH_CONFIG_DISABLE_EXCEPTIONS) - return ""; -#else - try { - if( it == itEnd ) - std::rethrow_exception(std::current_exception()); - else - return (*it)->translate( it+1, itEnd ); - } - catch( T& ex ) { - return m_translateFunction( ex ); - } -#endif - } - - protected: - std::string(*m_translateFunction)( T& ); - }; - - public: - template<typename T> - ExceptionTranslatorRegistrar( std::string(*translateFunction)( T& ) ) { - getMutableRegistryHub().registerTranslator - ( new ExceptionTranslator<T>( translateFunction ) ); - } - }; -} - -/////////////////////////////////////////////////////////////////////////////// -#define INTERNAL_CATCH_TRANSLATE_EXCEPTION2( translatorName, signature ) \ - static std::string translatorName( signature ); \ - CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \ - CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ - namespace{ Catch::ExceptionTranslatorRegistrar INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionRegistrar )( &translatorName ); } \ - CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \ - static std::string translatorName( signature ) - -#define INTERNAL_CATCH_TRANSLATE_EXCEPTION( signature ) INTERNAL_CATCH_TRANSLATE_EXCEPTION2( INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionTranslator ), signature ) - -// end catch_interfaces_exception.h -// start catch_approx.h - -#include <type_traits> - -namespace Catch { -namespace Detail { - - class Approx { - private: - bool equalityComparisonImpl(double other) const; - // Validates the new margin (margin >= 0) - // out-of-line to avoid including stdexcept in the header - void setMargin(double margin); - // Validates the new epsilon (0 < epsilon < 1) - // out-of-line to avoid including stdexcept in the header - void setEpsilon(double epsilon); - - public: - explicit Approx ( double value ); - - static Approx custom(); - - Approx operator-() const; - - template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type> - Approx operator()( T const& value ) { - Approx approx( static_cast<double>(value) ); - approx.m_epsilon = m_epsilon; - approx.m_margin = m_margin; - approx.m_scale = m_scale; - return approx; - } - - template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type> - explicit Approx( T const& value ): Approx(static_cast<double>(value)) - {} - - template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type> - friend bool operator == ( const T& lhs, Approx const& rhs ) { - auto lhs_v = static_cast<double>(lhs); - return rhs.equalityComparisonImpl(lhs_v); - } - - template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type> - friend bool operator == ( Approx const& lhs, const T& rhs ) { - return operator==( rhs, lhs ); - } - - template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type> - friend bool operator != ( T const& lhs, Approx const& rhs ) { - return !operator==( lhs, rhs ); - } - - template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type> - friend bool operator != ( Approx const& lhs, T const& rhs ) { - return !operator==( rhs, lhs ); - } - - template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type> - friend bool operator <= ( T const& lhs, Approx const& rhs ) { - return static_cast<double>(lhs) < rhs.m_value || lhs == rhs; - } - - template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type> - friend bool operator <= ( Approx const& lhs, T const& rhs ) { - return lhs.m_value < static_cast<double>(rhs) || lhs == rhs; - } - - template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type> - friend bool operator >= ( T const& lhs, Approx const& rhs ) { - return static_cast<double>(lhs) > rhs.m_value || lhs == rhs; - } - - template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type> - friend bool operator >= ( Approx const& lhs, T const& rhs ) { - return lhs.m_value > static_cast<double>(rhs) || lhs == rhs; - } - - template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type> - Approx& epsilon( T const& newEpsilon ) { - double epsilonAsDouble = static_cast<double>(newEpsilon); - setEpsilon(epsilonAsDouble); - return *this; - } - - template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type> - Approx& margin( T const& newMargin ) { - double marginAsDouble = static_cast<double>(newMargin); - setMargin(marginAsDouble); - return *this; - } - - template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type> - Approx& scale( T const& newScale ) { - m_scale = static_cast<double>(newScale); - return *this; - } - - std::string toString() const; - - private: - double m_epsilon; - double m_margin; - double m_scale; - double m_value; - }; -} // end namespace Detail - -namespace literals { - Detail::Approx operator "" _a(long double val); - Detail::Approx operator "" _a(unsigned long long val); -} // end namespace literals - -template<> -struct StringMaker<Catch::Detail::Approx> { - static std::string convert(Catch::Detail::Approx const& value); -}; - -} // end namespace Catch - -// end catch_approx.h -// start catch_string_manip.h - -#include <string> -#include <iosfwd> -#include <vector> - -namespace Catch { - - bool startsWith( std::string const& s, std::string const& prefix ); - bool startsWith( std::string const& s, char prefix ); - bool endsWith( std::string const& s, std::string const& suffix ); - bool endsWith( std::string const& s, char suffix ); - bool contains( std::string const& s, std::string const& infix ); - void toLowerInPlace( std::string& s ); - std::string toLower( std::string const& s ); - //! Returns a new string without whitespace at the start/end - std::string trim( std::string const& str ); - //! Returns a substring of the original ref without whitespace. Beware lifetimes! - StringRef trim(StringRef ref); - - // !!! Be aware, returns refs into original string - make sure original string outlives them - std::vector<StringRef> splitStringRef( StringRef str, char delimiter ); - bool replaceInPlace( std::string& str, std::string const& replaceThis, std::string const& withThis ); - - struct pluralise { - pluralise( std::size_t count, std::string const& label ); - - friend std::ostream& operator << ( std::ostream& os, pluralise const& pluraliser ); - - std::size_t m_count; - std::string m_label; - }; -} - -// end catch_string_manip.h -#ifndef CATCH_CONFIG_DISABLE_MATCHERS -// start catch_capture_matchers.h - -// start catch_matchers.h - -#include <string> -#include <vector> - -namespace Catch { -namespace Matchers { - namespace Impl { - - template<typename ArgT> struct MatchAllOf; - template<typename ArgT> struct MatchAnyOf; - template<typename ArgT> struct MatchNotOf; - - class MatcherUntypedBase { - public: - MatcherUntypedBase() = default; - MatcherUntypedBase ( MatcherUntypedBase const& ) = default; - MatcherUntypedBase& operator = ( MatcherUntypedBase const& ) = delete; - std::string toString() const; - - protected: - virtual ~MatcherUntypedBase(); - virtual std::string describe() const = 0; - mutable std::string m_cachedToString; - }; - -#ifdef __clang__ -# pragma clang diagnostic push -# pragma clang diagnostic ignored "-Wnon-virtual-dtor" -#endif - - template<typename ObjectT> - struct MatcherMethod { - virtual bool match( ObjectT const& arg ) const = 0; - }; - -#if defined(__OBJC__) - // Hack to fix Catch GH issue #1661. Could use id for generic Object support. - // use of const for Object pointers is very uncommon and under ARC it causes some kind of signature mismatch that breaks compilation - template<> - struct MatcherMethod<NSString*> { - virtual bool match( NSString* arg ) const = 0; - }; -#endif - -#ifdef __clang__ -# pragma clang diagnostic pop -#endif - - template<typename T> - struct MatcherBase : MatcherUntypedBase, MatcherMethod<T> { - - MatchAllOf<T> operator && ( MatcherBase const& other ) const; - MatchAnyOf<T> operator || ( MatcherBase const& other ) const; - MatchNotOf<T> operator ! () const; - }; - - template<typename ArgT> - struct MatchAllOf : MatcherBase<ArgT> { - bool match( ArgT const& arg ) const override { - for( auto matcher : m_matchers ) { - if (!matcher->match(arg)) - return false; - } - return true; - } - std::string describe() const override { - std::string description; - description.reserve( 4 + m_matchers.size()*32 ); - description += "( "; - bool first = true; - for( auto matcher : m_matchers ) { - if( first ) - first = false; - else - description += " and "; - description += matcher->toString(); - } - description += " )"; - return description; - } - - MatchAllOf<ArgT> operator && ( MatcherBase<ArgT> const& other ) { - auto copy(*this); - copy.m_matchers.push_back( &other ); - return copy; - } - - std::vector<MatcherBase<ArgT> const*> m_matchers; - }; - template<typename ArgT> - struct MatchAnyOf : MatcherBase<ArgT> { - - bool match( ArgT const& arg ) const override { - for( auto matcher : m_matchers ) { - if (matcher->match(arg)) - return true; - } - return false; - } - std::string describe() const override { - std::string description; - description.reserve( 4 + m_matchers.size()*32 ); - description += "( "; - bool first = true; - for( auto matcher : m_matchers ) { - if( first ) - first = false; - else - description += " or "; - description += matcher->toString(); - } - description += " )"; - return description; - } - - MatchAnyOf<ArgT> operator || ( MatcherBase<ArgT> const& other ) { - auto copy(*this); - copy.m_matchers.push_back( &other ); - return copy; - } - - std::vector<MatcherBase<ArgT> const*> m_matchers; - }; - - template<typename ArgT> - struct MatchNotOf : MatcherBase<ArgT> { - - MatchNotOf( MatcherBase<ArgT> const& underlyingMatcher ) : m_underlyingMatcher( underlyingMatcher ) {} - - bool match( ArgT const& arg ) const override { - return !m_underlyingMatcher.match( arg ); - } - - std::string describe() const override { - return "not " + m_underlyingMatcher.toString(); - } - MatcherBase<ArgT> const& m_underlyingMatcher; - }; - - template<typename T> - MatchAllOf<T> MatcherBase<T>::operator && ( MatcherBase const& other ) const { - return MatchAllOf<T>() && *this && other; - } - template<typename T> - MatchAnyOf<T> MatcherBase<T>::operator || ( MatcherBase const& other ) const { - return MatchAnyOf<T>() || *this || other; - } - template<typename T> - MatchNotOf<T> MatcherBase<T>::operator ! () const { - return MatchNotOf<T>( *this ); - } - - } // namespace Impl - -} // namespace Matchers - -using namespace Matchers; -using Matchers::Impl::MatcherBase; - -} // namespace Catch - -// end catch_matchers.h -// start catch_matchers_exception.hpp - -namespace Catch { -namespace Matchers { -namespace Exception { - -class ExceptionMessageMatcher : public MatcherBase<std::exception> { - std::string m_message; -public: - - ExceptionMessageMatcher(std::string const& message): - m_message(message) - {} - - bool match(std::exception const& ex) const override; - - std::string describe() const override; -}; - -} // namespace Exception - -Exception::ExceptionMessageMatcher Message(std::string const& message); - -} // namespace Matchers -} // namespace Catch - -// end catch_matchers_exception.hpp -// start catch_matchers_floating.h - -namespace Catch { -namespace Matchers { - - namespace Floating { - - enum class FloatingPointKind : uint8_t; - - struct WithinAbsMatcher : MatcherBase<double> { - WithinAbsMatcher(double target, double margin); - bool match(double const& matchee) const override; - std::string describe() const override; - private: - double m_target; - double m_margin; - }; - - struct WithinUlpsMatcher : MatcherBase<double> { - WithinUlpsMatcher(double target, uint64_t ulps, FloatingPointKind baseType); - bool match(double const& matchee) const override; - std::string describe() const override; - private: - double m_target; - uint64_t m_ulps; - FloatingPointKind m_type; - }; - - // Given IEEE-754 format for floats and doubles, we can assume - // that float -> double promotion is lossless. Given this, we can - // assume that if we do the standard relative comparison of - // |lhs - rhs| <= epsilon * max(fabs(lhs), fabs(rhs)), then we get - // the same result if we do this for floats, as if we do this for - // doubles that were promoted from floats. - struct WithinRelMatcher : MatcherBase<double> { - WithinRelMatcher(double target, double epsilon); - bool match(double const& matchee) const override; - std::string describe() const override; - private: - double m_target; - double m_epsilon; - }; - - } // namespace Floating - - // The following functions create the actual matcher objects. - // This allows the types to be inferred - Floating::WithinUlpsMatcher WithinULP(double target, uint64_t maxUlpDiff); - Floating::WithinUlpsMatcher WithinULP(float target, uint64_t maxUlpDiff); - Floating::WithinAbsMatcher WithinAbs(double target, double margin); - Floating::WithinRelMatcher WithinRel(double target, double eps); - // defaults epsilon to 100*numeric_limits<double>::epsilon() - Floating::WithinRelMatcher WithinRel(double target); - Floating::WithinRelMatcher WithinRel(float target, float eps); - // defaults epsilon to 100*numeric_limits<float>::epsilon() - Floating::WithinRelMatcher WithinRel(float target); - -} // namespace Matchers -} // namespace Catch - -// end catch_matchers_floating.h -// start catch_matchers_generic.hpp - -#include <functional> -#include <string> - -namespace Catch { -namespace Matchers { -namespace Generic { - -namespace Detail { - std::string finalizeDescription(const std::string& desc); -} - -template <typename T> -class PredicateMatcher : public MatcherBase<T> { - std::function<bool(T const&)> m_predicate; - std::string m_description; -public: - - PredicateMatcher(std::function<bool(T const&)> const& elem, std::string const& descr) - :m_predicate(std::move(elem)), - m_description(Detail::finalizeDescription(descr)) - {} - - bool match( T const& item ) const override { - return m_predicate(item); - } - - std::string describe() const override { - return m_description; - } -}; - -} // namespace Generic - - // The following functions create the actual matcher objects. - // The user has to explicitly specify type to the function, because - // inferring std::function<bool(T const&)> is hard (but possible) and - // requires a lot of TMP. - template<typename T> - Generic::PredicateMatcher<T> Predicate(std::function<bool(T const&)> const& predicate, std::string const& description = "") { - return Generic::PredicateMatcher<T>(predicate, description); - } - -} // namespace Matchers -} // namespace Catch - -// end catch_matchers_generic.hpp -// start catch_matchers_string.h - -#include <string> - -namespace Catch { -namespace Matchers { - - namespace StdString { - - struct CasedString - { - CasedString( std::string const& str, CaseSensitive::Choice caseSensitivity ); - std::string adjustString( std::string const& str ) const; - std::string caseSensitivitySuffix() const; - - CaseSensitive::Choice m_caseSensitivity; - std::string m_str; - }; - - struct StringMatcherBase : MatcherBase<std::string> { - StringMatcherBase( std::string const& operation, CasedString const& comparator ); - std::string describe() const override; - - CasedString m_comparator; - std::string m_operation; - }; - - struct EqualsMatcher : StringMatcherBase { - EqualsMatcher( CasedString const& comparator ); - bool match( std::string const& source ) const override; - }; - struct ContainsMatcher : StringMatcherBase { - ContainsMatcher( CasedString const& comparator ); - bool match( std::string const& source ) const override; - }; - struct StartsWithMatcher : StringMatcherBase { - StartsWithMatcher( CasedString const& comparator ); - bool match( std::string const& source ) const override; - }; - struct EndsWithMatcher : StringMatcherBase { - EndsWithMatcher( CasedString const& comparator ); - bool match( std::string const& source ) const override; - }; - - struct RegexMatcher : MatcherBase<std::string> { - RegexMatcher( std::string regex, CaseSensitive::Choice caseSensitivity ); - bool match( std::string const& matchee ) const override; - std::string describe() const override; - - private: - std::string m_regex; - CaseSensitive::Choice m_caseSensitivity; - }; - - } // namespace StdString - - // The following functions create the actual matcher objects. - // This allows the types to be inferred - - StdString::EqualsMatcher Equals( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes ); - StdString::ContainsMatcher Contains( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes ); - StdString::EndsWithMatcher EndsWith( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes ); - StdString::StartsWithMatcher StartsWith( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes ); - StdString::RegexMatcher Matches( std::string const& regex, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes ); - -} // namespace Matchers -} // namespace Catch - -// end catch_matchers_string.h -// start catch_matchers_vector.h - -#include <algorithm> - -namespace Catch { -namespace Matchers { - - namespace Vector { - template<typename T, typename Alloc> - struct ContainsElementMatcher : MatcherBase<std::vector<T, Alloc>> { - - ContainsElementMatcher(T const &comparator) : m_comparator( comparator) {} - - bool match(std::vector<T, Alloc> const &v) const override { - for (auto const& el : v) { - if (el == m_comparator) { - return true; - } - } - return false; - } - - std::string describe() const override { - return "Contains: " + ::Catch::Detail::stringify( m_comparator ); - } - - T const& m_comparator; - }; - - template<typename T, typename AllocComp, typename AllocMatch> - struct ContainsMatcher : MatcherBase<std::vector<T, AllocMatch>> { - - ContainsMatcher(std::vector<T, AllocComp> const &comparator) : m_comparator( comparator ) {} - - bool match(std::vector<T, AllocMatch> const &v) const override { - // !TBD: see note in EqualsMatcher - if (m_comparator.size() > v.size()) - return false; - for (auto const& comparator : m_comparator) { - auto present = false; - for (const auto& el : v) { - if (el == comparator) { - present = true; - break; - } - } - if (!present) { - return false; - } - } - return true; - } - std::string describe() const override { - return "Contains: " + ::Catch::Detail::stringify( m_comparator ); - } - - std::vector<T, AllocComp> const& m_comparator; - }; - - template<typename T, typename AllocComp, typename AllocMatch> - struct EqualsMatcher : MatcherBase<std::vector<T, AllocMatch>> { - - EqualsMatcher(std::vector<T, AllocComp> const &comparator) : m_comparator( comparator ) {} - - bool match(std::vector<T, AllocMatch> const &v) const override { - // !TBD: This currently works if all elements can be compared using != - // - a more general approach would be via a compare template that defaults - // to using !=. but could be specialised for, e.g. std::vector<T, Alloc> etc - // - then just call that directly - if (m_comparator.size() != v.size()) - return false; - for (std::size_t i = 0; i < v.size(); ++i) - if (m_comparator[i] != v[i]) - return false; - return true; - } - std::string describe() const override { - return "Equals: " + ::Catch::Detail::stringify( m_comparator ); - } - std::vector<T, AllocComp> const& m_comparator; - }; - - template<typename T, typename AllocComp, typename AllocMatch> - struct ApproxMatcher : MatcherBase<std::vector<T, AllocMatch>> { - - ApproxMatcher(std::vector<T, AllocComp> const& comparator) : m_comparator( comparator ) {} - - bool match(std::vector<T, AllocMatch> const &v) const override { - if (m_comparator.size() != v.size()) - return false; - for (std::size_t i = 0; i < v.size(); ++i) - if (m_comparator[i] != approx(v[i])) - return false; - return true; - } - std::string describe() const override { - return "is approx: " + ::Catch::Detail::stringify( m_comparator ); - } - template <typename = typename std::enable_if<std::is_constructible<double, T>::value>::type> - ApproxMatcher& epsilon( T const& newEpsilon ) { - approx.epsilon(newEpsilon); - return *this; - } - template <typename = typename std::enable_if<std::is_constructible<double, T>::value>::type> - ApproxMatcher& margin( T const& newMargin ) { - approx.margin(newMargin); - return *this; - } - template <typename = typename std::enable_if<std::is_constructible<double, T>::value>::type> - ApproxMatcher& scale( T const& newScale ) { - approx.scale(newScale); - return *this; - } - - std::vector<T, AllocComp> const& m_comparator; - mutable Catch::Detail::Approx approx = Catch::Detail::Approx::custom(); - }; - - template<typename T, typename AllocComp, typename AllocMatch> - struct UnorderedEqualsMatcher : MatcherBase<std::vector<T, AllocMatch>> { - UnorderedEqualsMatcher(std::vector<T, AllocComp> const& target) : m_target(target) {} - bool match(std::vector<T, AllocMatch> const& vec) const override { - // Note: This is a reimplementation of std::is_permutation, - // because I don't want to include <algorithm> inside the common path - if (m_target.size() != vec.size()) { - return false; - } - return std::is_permutation(m_target.begin(), m_target.end(), vec.begin()); - } - - std::string describe() const override { - return "UnorderedEquals: " + ::Catch::Detail::stringify(m_target); - } - private: - std::vector<T, AllocComp> const& m_target; - }; - - } // namespace Vector - - // The following functions create the actual matcher objects. - // This allows the types to be inferred - - template<typename T, typename AllocComp = std::allocator<T>, typename AllocMatch = AllocComp> - Vector::ContainsMatcher<T, AllocComp, AllocMatch> Contains( std::vector<T, AllocComp> const& comparator ) { - return Vector::ContainsMatcher<T, AllocComp, AllocMatch>( comparator ); - } - - template<typename T, typename Alloc = std::allocator<T>> - Vector::ContainsElementMatcher<T, Alloc> VectorContains( T const& comparator ) { - return Vector::ContainsElementMatcher<T, Alloc>( comparator ); - } - - template<typename T, typename AllocComp = std::allocator<T>, typename AllocMatch = AllocComp> - Vector::EqualsMatcher<T, AllocComp, AllocMatch> Equals( std::vector<T, AllocComp> const& comparator ) { - return Vector::EqualsMatcher<T, AllocComp, AllocMatch>( comparator ); - } - - template<typename T, typename AllocComp = std::allocator<T>, typename AllocMatch = AllocComp> - Vector::ApproxMatcher<T, AllocComp, AllocMatch> Approx( std::vector<T, AllocComp> const& comparator ) { - return Vector::ApproxMatcher<T, AllocComp, AllocMatch>( comparator ); - } - - template<typename T, typename AllocComp = std::allocator<T>, typename AllocMatch = AllocComp> - Vector::UnorderedEqualsMatcher<T, AllocComp, AllocMatch> UnorderedEquals(std::vector<T, AllocComp> const& target) { - return Vector::UnorderedEqualsMatcher<T, AllocComp, AllocMatch>( target ); - } - -} // namespace Matchers -} // namespace Catch - -// end catch_matchers_vector.h -namespace Catch { - - template<typename ArgT, typename MatcherT> - class MatchExpr : public ITransientExpression { - ArgT const& m_arg; - MatcherT m_matcher; - StringRef m_matcherString; - public: - MatchExpr( ArgT const& arg, MatcherT const& matcher, StringRef const& matcherString ) - : ITransientExpression{ true, matcher.match( arg ) }, - m_arg( arg ), - m_matcher( matcher ), - m_matcherString( matcherString ) - {} - - void streamReconstructedExpression( std::ostream &os ) const override { - auto matcherAsString = m_matcher.toString(); - os << Catch::Detail::stringify( m_arg ) << ' '; - if( matcherAsString == Detail::unprintableString ) - os << m_matcherString; - else - os << matcherAsString; - } - }; - - using StringMatcher = Matchers::Impl::MatcherBase<std::string>; - - void handleExceptionMatchExpr( AssertionHandler& handler, StringMatcher const& matcher, StringRef const& matcherString ); - - template<typename ArgT, typename MatcherT> - auto makeMatchExpr( ArgT const& arg, MatcherT const& matcher, StringRef const& matcherString ) -> MatchExpr<ArgT, MatcherT> { - return MatchExpr<ArgT, MatcherT>( arg, matcher, matcherString ); - } - -} // namespace Catch - -/////////////////////////////////////////////////////////////////////////////// -#define INTERNAL_CHECK_THAT( macroName, matcher, resultDisposition, arg ) \ - do { \ - Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(arg) ", " CATCH_INTERNAL_STRINGIFY(matcher), resultDisposition ); \ - INTERNAL_CATCH_TRY { \ - catchAssertionHandler.handleExpr( Catch::makeMatchExpr( arg, matcher, #matcher##_catch_sr ) ); \ - } INTERNAL_CATCH_CATCH( catchAssertionHandler ) \ - INTERNAL_CATCH_REACT( catchAssertionHandler ) \ - } while( false ) - -/////////////////////////////////////////////////////////////////////////////// -#define INTERNAL_CATCH_THROWS_MATCHES( macroName, exceptionType, resultDisposition, matcher, ... ) \ - do { \ - Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__) ", " CATCH_INTERNAL_STRINGIFY(exceptionType) ", " CATCH_INTERNAL_STRINGIFY(matcher), resultDisposition ); \ - if( catchAssertionHandler.allowThrows() ) \ - try { \ - static_cast<void>(__VA_ARGS__ ); \ - catchAssertionHandler.handleUnexpectedExceptionNotThrown(); \ - } \ - catch( exceptionType const& ex ) { \ - catchAssertionHandler.handleExpr( Catch::makeMatchExpr( ex, matcher, #matcher##_catch_sr ) ); \ - } \ - catch( ... ) { \ - catchAssertionHandler.handleUnexpectedInflightException(); \ - } \ - else \ - catchAssertionHandler.handleThrowingCallSkipped(); \ - INTERNAL_CATCH_REACT( catchAssertionHandler ) \ - } while( false ) - -// end catch_capture_matchers.h -#endif -// start catch_generators.hpp - -// start catch_interfaces_generatortracker.h - - -#include <memory> - -namespace Catch { - - namespace Generators { - class GeneratorUntypedBase { - public: - GeneratorUntypedBase() = default; - virtual ~GeneratorUntypedBase(); - // Attempts to move the generator to the next element - // - // Returns true if the move succeeded (and a valid element - // can be retrieved). - virtual bool next() = 0; - }; - using GeneratorBasePtr = std::unique_ptr<GeneratorUntypedBase>; - - } // namespace Generators - - struct IGeneratorTracker { - virtual ~IGeneratorTracker(); - virtual auto hasGenerator() const -> bool = 0; - virtual auto getGenerator() const -> Generators::GeneratorBasePtr const& = 0; - virtual void setGenerator( Generators::GeneratorBasePtr&& generator ) = 0; - }; - -} // namespace Catch - -// end catch_interfaces_generatortracker.h -// start catch_enforce.h - -#include <exception> - -namespace Catch { -#if !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS) - template <typename Ex> - [[noreturn]] - void throw_exception(Ex const& e) { - throw e; - } -#else // ^^ Exceptions are enabled // Exceptions are disabled vv - [[noreturn]] - void throw_exception(std::exception const& e); -#endif - - [[noreturn]] - void throw_logic_error(std::string const& msg); - [[noreturn]] - void throw_domain_error(std::string const& msg); - [[noreturn]] - void throw_runtime_error(std::string const& msg); - -} // namespace Catch; - -#define CATCH_MAKE_MSG(...) \ - (Catch::ReusableStringStream() << __VA_ARGS__).str() - -#define CATCH_INTERNAL_ERROR(...) \ - Catch::throw_logic_error(CATCH_MAKE_MSG( CATCH_INTERNAL_LINEINFO << ": Internal Catch2 error: " << __VA_ARGS__)) - -#define CATCH_ERROR(...) \ - Catch::throw_domain_error(CATCH_MAKE_MSG( __VA_ARGS__ )) - -#define CATCH_RUNTIME_ERROR(...) \ - Catch::throw_runtime_error(CATCH_MAKE_MSG( __VA_ARGS__ )) - -#define CATCH_ENFORCE( condition, ... ) \ - do{ if( !(condition) ) CATCH_ERROR( __VA_ARGS__ ); } while(false) - -// end catch_enforce.h -#include <memory> -#include <vector> -#include <cassert> - -#include <utility> -#include <exception> - -namespace Catch { - -class GeneratorException : public std::exception { - const char* const m_msg = ""; - -public: - GeneratorException(const char* msg): - m_msg(msg) - {} - - const char* what() const noexcept override final; -}; - -namespace Generators { - - // !TBD move this into its own location? - namespace pf{ - template<typename T, typename... Args> - std::unique_ptr<T> make_unique( Args&&... args ) { - return std::unique_ptr<T>(new T(std::forward<Args>(args)...)); - } - } - - template<typename T> - struct IGenerator : GeneratorUntypedBase { - virtual ~IGenerator() = default; - - // Returns the current element of the generator - // - // \Precondition The generator is either freshly constructed, - // or the last call to `next()` returned true - virtual T const& get() const = 0; - using type = T; - }; - - template<typename T> - class SingleValueGenerator final : public IGenerator<T> { - T m_value; - public: - SingleValueGenerator(T&& value) : m_value(std::move(value)) {} - - T const& get() const override { - return m_value; - } - bool next() override { - return false; - } - }; - - template<typename T> - class FixedValuesGenerator final : public IGenerator<T> { - static_assert(!std::is_same<T, bool>::value, - "FixedValuesGenerator does not support bools because of std::vector<bool>" - "specialization, use SingleValue Generator instead."); - std::vector<T> m_values; - size_t m_idx = 0; - public: - FixedValuesGenerator( std::initializer_list<T> values ) : m_values( values ) {} - - T const& get() const override { - return m_values[m_idx]; - } - bool next() override { - ++m_idx; - return m_idx < m_values.size(); - } - }; - - template <typename T> - class GeneratorWrapper final { - std::unique_ptr<IGenerator<T>> m_generator; - public: - GeneratorWrapper(std::unique_ptr<IGenerator<T>> generator): - m_generator(std::move(generator)) - {} - T const& get() const { - return m_generator->get(); - } - bool next() { - return m_generator->next(); - } - }; - - template <typename T> - GeneratorWrapper<T> value(T&& value) { - return GeneratorWrapper<T>(pf::make_unique<SingleValueGenerator<T>>(std::forward<T>(value))); - } - template <typename T> - GeneratorWrapper<T> values(std::initializer_list<T> values) { - return GeneratorWrapper<T>(pf::make_unique<FixedValuesGenerator<T>>(values)); - } - - template<typename T> - class Generators : public IGenerator<T> { - std::vector<GeneratorWrapper<T>> m_generators; - size_t m_current = 0; - - void populate(GeneratorWrapper<T>&& generator) { - m_generators.emplace_back(std::move(generator)); - } - void populate(T&& val) { - m_generators.emplace_back(value(std::forward<T>(val))); - } - template<typename U> - void populate(U&& val) { - populate(T(std::forward<U>(val))); - } - template<typename U, typename... Gs> - void populate(U&& valueOrGenerator, Gs &&... moreGenerators) { - populate(std::forward<U>(valueOrGenerator)); - populate(std::forward<Gs>(moreGenerators)...); - } - - public: - template <typename... Gs> - Generators(Gs &&... moreGenerators) { - m_generators.reserve(sizeof...(Gs)); - populate(std::forward<Gs>(moreGenerators)...); - } - - T const& get() const override { - return m_generators[m_current].get(); - } - - bool next() override { - if (m_current >= m_generators.size()) { - return false; - } - const bool current_status = m_generators[m_current].next(); - if (!current_status) { - ++m_current; - } - return m_current < m_generators.size(); - } - }; - - template<typename... Ts> - GeneratorWrapper<std::tuple<Ts...>> table( std::initializer_list<std::tuple<typename std::decay<Ts>::type...>> tuples ) { - return values<std::tuple<Ts...>>( tuples ); - } - - // Tag type to signal that a generator sequence should convert arguments to a specific type - template <typename T> - struct as {}; - - template<typename T, typename... Gs> - auto makeGenerators( GeneratorWrapper<T>&& generator, Gs &&... moreGenerators ) -> Generators<T> { - return Generators<T>(std::move(generator), std::forward<Gs>(moreGenerators)...); - } - template<typename T> - auto makeGenerators( GeneratorWrapper<T>&& generator ) -> Generators<T> { - return Generators<T>(std::move(generator)); - } - template<typename T, typename... Gs> - auto makeGenerators( T&& val, Gs &&... moreGenerators ) -> Generators<T> { - return makeGenerators( value( std::forward<T>( val ) ), std::forward<Gs>( moreGenerators )... ); - } - template<typename T, typename U, typename... Gs> - auto makeGenerators( as<T>, U&& val, Gs &&... moreGenerators ) -> Generators<T> { - return makeGenerators( value( T( std::forward<U>( val ) ) ), std::forward<Gs>( moreGenerators )... ); - } - - auto acquireGeneratorTracker( SourceLineInfo const& lineInfo ) -> IGeneratorTracker&; - - template<typename L> - // Note: The type after -> is weird, because VS2015 cannot parse - // the expression used in the typedef inside, when it is in - // return type. Yeah. - auto generate( SourceLineInfo const& lineInfo, L const& generatorExpression ) -> decltype(std::declval<decltype(generatorExpression())>().get()) { - using UnderlyingType = typename decltype(generatorExpression())::type; - - IGeneratorTracker& tracker = acquireGeneratorTracker( lineInfo ); - if (!tracker.hasGenerator()) { - tracker.setGenerator(pf::make_unique<Generators<UnderlyingType>>(generatorExpression())); - } - - auto const& generator = static_cast<IGenerator<UnderlyingType> const&>( *tracker.getGenerator() ); - return generator.get(); - } - -} // namespace Generators -} // namespace Catch - -#define GENERATE( ... ) \ - Catch::Generators::generate( CATCH_INTERNAL_LINEINFO, [ ]{ using namespace Catch::Generators; return makeGenerators( __VA_ARGS__ ); } ) //NOLINT(google-build-using-namespace) -#define GENERATE_COPY( ... ) \ - Catch::Generators::generate( CATCH_INTERNAL_LINEINFO, [=]{ using namespace Catch::Generators; return makeGenerators( __VA_ARGS__ ); } ) //NOLINT(google-build-using-namespace) -#define GENERATE_REF( ... ) \ - Catch::Generators::generate( CATCH_INTERNAL_LINEINFO, [&]{ using namespace Catch::Generators; return makeGenerators( __VA_ARGS__ ); } ) //NOLINT(google-build-using-namespace) - -// end catch_generators.hpp -// start catch_generators_generic.hpp - -namespace Catch { -namespace Generators { - - template <typename T> - class TakeGenerator : public IGenerator<T> { - GeneratorWrapper<T> m_generator; - size_t m_returned = 0; - size_t m_target; - public: - TakeGenerator(size_t target, GeneratorWrapper<T>&& generator): - m_generator(std::move(generator)), - m_target(target) - { - assert(target != 0 && "Empty generators are not allowed"); - } - T const& get() const override { - return m_generator.get(); - } - bool next() override { - ++m_returned; - if (m_returned >= m_target) { - return false; - } - - const auto success = m_generator.next(); - // If the underlying generator does not contain enough values - // then we cut short as well - if (!success) { - m_returned = m_target; - } - return success; - } - }; - - template <typename T> - GeneratorWrapper<T> take(size_t target, GeneratorWrapper<T>&& generator) { - return GeneratorWrapper<T>(pf::make_unique<TakeGenerator<T>>(target, std::move(generator))); - } - - template <typename T, typename Predicate> - class FilterGenerator : public IGenerator<T> { - GeneratorWrapper<T> m_generator; - Predicate m_predicate; - public: - template <typename P = Predicate> - FilterGenerator(P&& pred, GeneratorWrapper<T>&& generator): - m_generator(std::move(generator)), - m_predicate(std::forward<P>(pred)) - { - if (!m_predicate(m_generator.get())) { - // It might happen that there are no values that pass the - // filter. In that case we throw an exception. - auto has_initial_value = next(); - if (!has_initial_value) { - Catch::throw_exception(GeneratorException("No valid value found in filtered generator")); - } - } - } - - T const& get() const override { - return m_generator.get(); - } - - bool next() override { - bool success = m_generator.next(); - if (!success) { - return false; - } - while (!m_predicate(m_generator.get()) && (success = m_generator.next()) == true); - return success; - } - }; - - template <typename T, typename Predicate> - GeneratorWrapper<T> filter(Predicate&& pred, GeneratorWrapper<T>&& generator) { - return GeneratorWrapper<T>(std::unique_ptr<IGenerator<T>>(pf::make_unique<FilterGenerator<T, Predicate>>(std::forward<Predicate>(pred), std::move(generator)))); - } - - template <typename T> - class RepeatGenerator : public IGenerator<T> { - static_assert(!std::is_same<T, bool>::value, - "RepeatGenerator currently does not support bools" - "because of std::vector<bool> specialization"); - GeneratorWrapper<T> m_generator; - mutable std::vector<T> m_returned; - size_t m_target_repeats; - size_t m_current_repeat = 0; - size_t m_repeat_index = 0; - public: - RepeatGenerator(size_t repeats, GeneratorWrapper<T>&& generator): - m_generator(std::move(generator)), - m_target_repeats(repeats) - { - assert(m_target_repeats > 0 && "Repeat generator must repeat at least once"); - } - - T const& get() const override { - if (m_current_repeat == 0) { - m_returned.push_back(m_generator.get()); - return m_returned.back(); - } - return m_returned[m_repeat_index]; - } - - bool next() override { - // There are 2 basic cases: - // 1) We are still reading the generator - // 2) We are reading our own cache - - // In the first case, we need to poke the underlying generator. - // If it happily moves, we are left in that state, otherwise it is time to start reading from our cache - if (m_current_repeat == 0) { - const auto success = m_generator.next(); - if (!success) { - ++m_current_repeat; - } - return m_current_repeat < m_target_repeats; - } - - // In the second case, we need to move indices forward and check that we haven't run up against the end - ++m_repeat_index; - if (m_repeat_index == m_returned.size()) { - m_repeat_index = 0; - ++m_current_repeat; - } - return m_current_repeat < m_target_repeats; - } - }; - - template <typename T> - GeneratorWrapper<T> repeat(size_t repeats, GeneratorWrapper<T>&& generator) { - return GeneratorWrapper<T>(pf::make_unique<RepeatGenerator<T>>(repeats, std::move(generator))); - } - - template <typename T, typename U, typename Func> - class MapGenerator : public IGenerator<T> { - // TBD: provide static assert for mapping function, for friendly error message - GeneratorWrapper<U> m_generator; - Func m_function; - // To avoid returning dangling reference, we have to save the values - T m_cache; - public: - template <typename F2 = Func> - MapGenerator(F2&& function, GeneratorWrapper<U>&& generator) : - m_generator(std::move(generator)), - m_function(std::forward<F2>(function)), - m_cache(m_function(m_generator.get())) - {} - - T const& get() const override { - return m_cache; - } - bool next() override { - const auto success = m_generator.next(); - if (success) { - m_cache = m_function(m_generator.get()); - } - return success; - } - }; - - template <typename Func, typename U, typename T = FunctionReturnType<Func, U>> - GeneratorWrapper<T> map(Func&& function, GeneratorWrapper<U>&& generator) { - return GeneratorWrapper<T>( - pf::make_unique<MapGenerator<T, U, Func>>(std::forward<Func>(function), std::move(generator)) - ); - } - - template <typename T, typename U, typename Func> - GeneratorWrapper<T> map(Func&& function, GeneratorWrapper<U>&& generator) { - return GeneratorWrapper<T>( - pf::make_unique<MapGenerator<T, U, Func>>(std::forward<Func>(function), std::move(generator)) - ); - } - - template <typename T> - class ChunkGenerator final : public IGenerator<std::vector<T>> { - std::vector<T> m_chunk; - size_t m_chunk_size; - GeneratorWrapper<T> m_generator; - bool m_used_up = false; - public: - ChunkGenerator(size_t size, GeneratorWrapper<T> generator) : - m_chunk_size(size), m_generator(std::move(generator)) - { - m_chunk.reserve(m_chunk_size); - if (m_chunk_size != 0) { - m_chunk.push_back(m_generator.get()); - for (size_t i = 1; i < m_chunk_size; ++i) { - if (!m_generator.next()) { - Catch::throw_exception(GeneratorException("Not enough values to initialize the first chunk")); - } - m_chunk.push_back(m_generator.get()); - } - } - } - std::vector<T> const& get() const override { - return m_chunk; - } - bool next() override { - m_chunk.clear(); - for (size_t idx = 0; idx < m_chunk_size; ++idx) { - if (!m_generator.next()) { - return false; - } - m_chunk.push_back(m_generator.get()); - } - return true; - } - }; - - template <typename T> - GeneratorWrapper<std::vector<T>> chunk(size_t size, GeneratorWrapper<T>&& generator) { - return GeneratorWrapper<std::vector<T>>( - pf::make_unique<ChunkGenerator<T>>(size, std::move(generator)) - ); - } - -} // namespace Generators -} // namespace Catch - -// end catch_generators_generic.hpp -// start catch_generators_specific.hpp - -// start catch_context.h - -#include <memory> - -namespace Catch { - - struct IResultCapture; - struct IRunner; - struct IConfig; - struct IMutableContext; - - using IConfigPtr = std::shared_ptr<IConfig const>; - - struct IContext - { - virtual ~IContext(); - - virtual IResultCapture* getResultCapture() = 0; - virtual IRunner* getRunner() = 0; - virtual IConfigPtr const& getConfig() const = 0; - }; - - struct IMutableContext : IContext - { - virtual ~IMutableContext(); - virtual void setResultCapture( IResultCapture* resultCapture ) = 0; - virtual void setRunner( IRunner* runner ) = 0; - virtual void setConfig( IConfigPtr const& config ) = 0; - - private: - static IMutableContext *currentContext; - friend IMutableContext& getCurrentMutableContext(); - friend void cleanUpContext(); - static void createContext(); - }; - - inline IMutableContext& getCurrentMutableContext() - { - if( !IMutableContext::currentContext ) - IMutableContext::createContext(); - // NOLINTNEXTLINE(clang-analyzer-core.uninitialized.UndefReturn) - return *IMutableContext::currentContext; - } - - inline IContext& getCurrentContext() - { - return getCurrentMutableContext(); - } - - void cleanUpContext(); - - class SimplePcg32; - SimplePcg32& rng(); -} - -// end catch_context.h -// start catch_interfaces_config.h - -// start catch_option.hpp - -namespace Catch { - - // An optional type - template<typename T> - class Option { - public: - Option() : nullableValue( nullptr ) {} - Option( T const& _value ) - : nullableValue( new( storage ) T( _value ) ) - {} - Option( Option const& _other ) - : nullableValue( _other ? new( storage ) T( *_other ) : nullptr ) - {} - - ~Option() { - reset(); - } - - Option& operator= ( Option const& _other ) { - if( &_other != this ) { - reset(); - if( _other ) - nullableValue = new( storage ) T( *_other ); - } - return *this; - } - Option& operator = ( T const& _value ) { - reset(); - nullableValue = new( storage ) T( _value ); - return *this; - } - - void reset() { - if( nullableValue ) - nullableValue->~T(); - nullableValue = nullptr; - } - - T& operator*() { return *nullableValue; } - T const& operator*() const { return *nullableValue; } - T* operator->() { return nullableValue; } - const T* operator->() const { return nullableValue; } - - T valueOr( T const& defaultValue ) const { - return nullableValue ? *nullableValue : defaultValue; - } - - bool some() const { return nullableValue != nullptr; } - bool none() const { return nullableValue == nullptr; } - - bool operator !() const { return nullableValue == nullptr; } - explicit operator bool() const { - return some(); - } - - private: - T *nullableValue; - alignas(alignof(T)) char storage[sizeof(T)]; - }; - -} // end namespace Catch - -// end catch_option.hpp -#include <chrono> -#include <iosfwd> -#include <string> -#include <vector> -#include <memory> - -namespace Catch { - - enum class Verbosity { - Quiet = 0, - Normal, - High - }; - - struct WarnAbout { enum What { - Nothing = 0x00, - NoAssertions = 0x01, - NoTests = 0x02 - }; }; - - struct ShowDurations { enum OrNot { - DefaultForReporter, - Always, - Never - }; }; - struct RunTests { enum InWhatOrder { - InDeclarationOrder, - InLexicographicalOrder, - InRandomOrder - }; }; - struct UseColour { enum YesOrNo { - Auto, - Yes, - No - }; }; - struct WaitForKeypress { enum When { - Never, - BeforeStart = 1, - BeforeExit = 2, - BeforeStartAndExit = BeforeStart | BeforeExit - }; }; - - class TestSpec; - - struct IConfig : NonCopyable { - - virtual ~IConfig(); - - virtual bool allowThrows() const = 0; - virtual std::ostream& stream() const = 0; - virtual std::string name() const = 0; - virtual bool includeSuccessfulResults() const = 0; - virtual bool shouldDebugBreak() const = 0; - virtual bool warnAboutMissingAssertions() const = 0; - virtual bool warnAboutNoTests() const = 0; - virtual int abortAfter() const = 0; - virtual bool showInvisibles() const = 0; - virtual ShowDurations::OrNot showDurations() const = 0; - virtual TestSpec const& testSpec() const = 0; - virtual bool hasTestFilters() const = 0; - virtual std::vector<std::string> const& getTestsOrTags() const = 0; - virtual RunTests::InWhatOrder runOrder() const = 0; - virtual unsigned int rngSeed() const = 0; - virtual UseColour::YesOrNo useColour() const = 0; - virtual std::vector<std::string> const& getSectionsToRun() const = 0; - virtual Verbosity verbosity() const = 0; - - virtual bool benchmarkNoAnalysis() const = 0; - virtual int benchmarkSamples() const = 0; - virtual double benchmarkConfidenceInterval() const = 0; - virtual unsigned int benchmarkResamples() const = 0; - virtual std::chrono::milliseconds benchmarkWarmupTime() const = 0; - }; - - using IConfigPtr = std::shared_ptr<IConfig const>; -} - -// end catch_interfaces_config.h -// start catch_random_number_generator.h - -#include <cstdint> - -namespace Catch { - - // This is a simple implementation of C++11 Uniform Random Number - // Generator. It does not provide all operators, because Catch2 - // does not use it, but it should behave as expected inside stdlib's - // distributions. - // The implementation is based on the PCG family (http://pcg-random.org) - class SimplePcg32 { - using state_type = std::uint64_t; - public: - using result_type = std::uint32_t; - static constexpr result_type (min)() { - return 0; - } - static constexpr result_type (max)() { - return static_cast<result_type>(-1); - } - - // Provide some default initial state for the default constructor - SimplePcg32():SimplePcg32(0xed743cc4U) {} - - explicit SimplePcg32(result_type seed_); - - void seed(result_type seed_); - void discard(uint64_t skip); - - result_type operator()(); - - private: - friend bool operator==(SimplePcg32 const& lhs, SimplePcg32 const& rhs); - friend bool operator!=(SimplePcg32 const& lhs, SimplePcg32 const& rhs); - - // In theory we also need operator<< and operator>> - // In practice we do not use them, so we will skip them for now - - std::uint64_t m_state; - // This part of the state determines which "stream" of the numbers - // is chosen -- we take it as a constant for Catch2, so we only - // need to deal with seeding the main state. - // Picked by reading 8 bytes from `/dev/random` :-) - static const std::uint64_t s_inc = (0x13ed0cc53f939476ULL << 1ULL) | 1ULL; - }; - -} // end namespace Catch - -// end catch_random_number_generator.h -#include <random> - -namespace Catch { -namespace Generators { - -template <typename Float> -class RandomFloatingGenerator final : public IGenerator<Float> { - Catch::SimplePcg32& m_rng; - std::uniform_real_distribution<Float> m_dist; - Float m_current_number; -public: - - RandomFloatingGenerator(Float a, Float b): - m_rng(rng()), - m_dist(a, b) { - static_cast<void>(next()); - } - - Float const& get() const override { - return m_current_number; - } - bool next() override { - m_current_number = m_dist(m_rng); - return true; - } -}; - -template <typename Integer> -class RandomIntegerGenerator final : public IGenerator<Integer> { - Catch::SimplePcg32& m_rng; - std::uniform_int_distribution<Integer> m_dist; - Integer m_current_number; -public: - - RandomIntegerGenerator(Integer a, Integer b): - m_rng(rng()), - m_dist(a, b) { - static_cast<void>(next()); - } - - Integer const& get() const override { - return m_current_number; - } - bool next() override { - m_current_number = m_dist(m_rng); - return true; - } -}; - -// TODO: Ideally this would be also constrained against the various char types, -// but I don't expect users to run into that in practice. -template <typename T> -typename std::enable_if<std::is_integral<T>::value && !std::is_same<T, bool>::value, -GeneratorWrapper<T>>::type -random(T a, T b) { - return GeneratorWrapper<T>( - pf::make_unique<RandomIntegerGenerator<T>>(a, b) - ); -} - -template <typename T> -typename std::enable_if<std::is_floating_point<T>::value, -GeneratorWrapper<T>>::type -random(T a, T b) { - return GeneratorWrapper<T>( - pf::make_unique<RandomFloatingGenerator<T>>(a, b) - ); -} - -template <typename T> -class RangeGenerator final : public IGenerator<T> { - T m_current; - T m_end; - T m_step; - bool m_positive; - -public: - RangeGenerator(T const& start, T const& end, T const& step): - m_current(start), - m_end(end), - m_step(step), - m_positive(m_step > T(0)) - { - assert(m_current != m_end && "Range start and end cannot be equal"); - assert(m_step != T(0) && "Step size cannot be zero"); - assert(((m_positive && m_current <= m_end) || (!m_positive && m_current >= m_end)) && "Step moves away from end"); - } - - RangeGenerator(T const& start, T const& end): - RangeGenerator(start, end, (start < end) ? T(1) : T(-1)) - {} - - T const& get() const override { - return m_current; - } - - bool next() override { - m_current += m_step; - return (m_positive) ? (m_current < m_end) : (m_current > m_end); - } -}; - -template <typename T> -GeneratorWrapper<T> range(T const& start, T const& end, T const& step) { - static_assert(std::is_arithmetic<T>::value && !std::is_same<T, bool>::value, "Type must be numeric"); - return GeneratorWrapper<T>(pf::make_unique<RangeGenerator<T>>(start, end, step)); -} - -template <typename T> -GeneratorWrapper<T> range(T const& start, T const& end) { - static_assert(std::is_integral<T>::value && !std::is_same<T, bool>::value, "Type must be an integer"); - return GeneratorWrapper<T>(pf::make_unique<RangeGenerator<T>>(start, end)); -} - -template <typename T> -class IteratorGenerator final : public IGenerator<T> { - static_assert(!std::is_same<T, bool>::value, - "IteratorGenerator currently does not support bools" - "because of std::vector<bool> specialization"); - - std::vector<T> m_elems; - size_t m_current = 0; -public: - template <typename InputIterator, typename InputSentinel> - IteratorGenerator(InputIterator first, InputSentinel last):m_elems(first, last) { - if (m_elems.empty()) { - Catch::throw_exception(GeneratorException("IteratorGenerator received no valid values")); - } - } - - T const& get() const override { - return m_elems[m_current]; - } - - bool next() override { - ++m_current; - return m_current != m_elems.size(); - } -}; - -template <typename InputIterator, - typename InputSentinel, - typename ResultType = typename std::iterator_traits<InputIterator>::value_type> -GeneratorWrapper<ResultType> from_range(InputIterator from, InputSentinel to) { - return GeneratorWrapper<ResultType>(pf::make_unique<IteratorGenerator<ResultType>>(from, to)); -} - -template <typename Container, - typename ResultType = typename Container::value_type> -GeneratorWrapper<ResultType> from_range(Container const& cnt) { - return GeneratorWrapper<ResultType>(pf::make_unique<IteratorGenerator<ResultType>>(cnt.begin(), cnt.end())); -} - -} // namespace Generators -} // namespace Catch - -// end catch_generators_specific.hpp - -// These files are included here so the single_include script doesn't put them -// in the conditionally compiled sections -// start catch_test_case_info.h - -#include <string> -#include <vector> -#include <memory> - -#ifdef __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wpadded" -#endif - -namespace Catch { - - struct ITestInvoker; - - struct TestCaseInfo { - enum SpecialProperties{ - None = 0, - IsHidden = 1 << 1, - ShouldFail = 1 << 2, - MayFail = 1 << 3, - Throws = 1 << 4, - NonPortable = 1 << 5, - Benchmark = 1 << 6 - }; - - TestCaseInfo( std::string const& _name, - std::string const& _className, - std::string const& _description, - std::vector<std::string> const& _tags, - SourceLineInfo const& _lineInfo ); - - friend void setTags( TestCaseInfo& testCaseInfo, std::vector<std::string> tags ); - - bool isHidden() const; - bool throws() const; - bool okToFail() const; - bool expectedToFail() const; - - std::string tagsAsString() const; - - std::string name; - std::string className; - std::string description; - std::vector<std::string> tags; - std::vector<std::string> lcaseTags; - SourceLineInfo lineInfo; - SpecialProperties properties; - }; - - class TestCase : public TestCaseInfo { - public: - - TestCase( ITestInvoker* testCase, TestCaseInfo&& info ); - - TestCase withName( std::string const& _newName ) const; - - void invoke() const; - - TestCaseInfo const& getTestCaseInfo() const; - - bool operator == ( TestCase const& other ) const; - bool operator < ( TestCase const& other ) const; - - private: - std::shared_ptr<ITestInvoker> test; - }; - - TestCase makeTestCase( ITestInvoker* testCase, - std::string const& className, - NameAndTags const& nameAndTags, - SourceLineInfo const& lineInfo ); -} - -#ifdef __clang__ -#pragma clang diagnostic pop -#endif - -// end catch_test_case_info.h -// start catch_interfaces_runner.h - -namespace Catch { - - struct IRunner { - virtual ~IRunner(); - virtual bool aborting() const = 0; - }; -} - -// end catch_interfaces_runner.h - -#ifdef __OBJC__ -// start catch_objc.hpp - -#import <objc/runtime.h> - -#include <string> - -// NB. Any general catch headers included here must be included -// in catch.hpp first to make sure they are included by the single -// header for non obj-usage - -/////////////////////////////////////////////////////////////////////////////// -// This protocol is really only here for (self) documenting purposes, since -// all its methods are optional. -@protocol OcFixture - -@optional - --(void) setUp; --(void) tearDown; - -@end - -namespace Catch { - - class OcMethod : public ITestInvoker { - - public: - OcMethod( Class cls, SEL sel ) : m_cls( cls ), m_sel( sel ) {} - - virtual void invoke() const { - id obj = [[m_cls alloc] init]; - - performOptionalSelector( obj, @selector(setUp) ); - performOptionalSelector( obj, m_sel ); - performOptionalSelector( obj, @selector(tearDown) ); - - arcSafeRelease( obj ); - } - private: - virtual ~OcMethod() {} - - Class m_cls; - SEL m_sel; - }; - - namespace Detail{ - - inline std::string getAnnotation( Class cls, - std::string const& annotationName, - std::string const& testCaseName ) { - NSString* selStr = [[NSString alloc] initWithFormat:@"Catch_%s_%s", annotationName.c_str(), testCaseName.c_str()]; - SEL sel = NSSelectorFromString( selStr ); - arcSafeRelease( selStr ); - id value = performOptionalSelector( cls, sel ); - if( value ) - return [(NSString*)value UTF8String]; - return ""; - } - } - - inline std::size_t registerTestMethods() { - std::size_t noTestMethods = 0; - int noClasses = objc_getClassList( nullptr, 0 ); - - Class* classes = (CATCH_UNSAFE_UNRETAINED Class *)malloc( sizeof(Class) * noClasses); - objc_getClassList( classes, noClasses ); - - for( int c = 0; c < noClasses; c++ ) { - Class cls = classes[c]; - { - u_int count; - Method* methods = class_copyMethodList( cls, &count ); - for( u_int m = 0; m < count ; m++ ) { - SEL selector = method_getName(methods[m]); - std::string methodName = sel_getName(selector); - if( startsWith( methodName, "Catch_TestCase_" ) ) { - std::string testCaseName = methodName.substr( 15 ); - std::string name = Detail::getAnnotation( cls, "Name", testCaseName ); - std::string desc = Detail::getAnnotation( cls, "Description", testCaseName ); - const char* className = class_getName( cls ); - - getMutableRegistryHub().registerTest( makeTestCase( new OcMethod( cls, selector ), className, NameAndTags( name.c_str(), desc.c_str() ), SourceLineInfo("",0) ) ); - noTestMethods++; - } - } - free(methods); - } - } - return noTestMethods; - } - -#if !defined(CATCH_CONFIG_DISABLE_MATCHERS) - - namespace Matchers { - namespace Impl { - namespace NSStringMatchers { - - struct StringHolder : MatcherBase<NSString*>{ - StringHolder( NSString* substr ) : m_substr( [substr copy] ){} - StringHolder( StringHolder const& other ) : m_substr( [other.m_substr copy] ){} - StringHolder() { - arcSafeRelease( m_substr ); - } - - bool match( NSString* str ) const override { - return false; - } - - NSString* CATCH_ARC_STRONG m_substr; - }; - - struct Equals : StringHolder { - Equals( NSString* substr ) : StringHolder( substr ){} - - bool match( NSString* str ) const override { - return (str != nil || m_substr == nil ) && - [str isEqualToString:m_substr]; - } - - std::string describe() const override { - return "equals string: " + Catch::Detail::stringify( m_substr ); - } - }; - - struct Contains : StringHolder { - Contains( NSString* substr ) : StringHolder( substr ){} - - bool match( NSString* str ) const override { - return (str != nil || m_substr == nil ) && - [str rangeOfString:m_substr].location != NSNotFound; - } - - std::string describe() const override { - return "contains string: " + Catch::Detail::stringify( m_substr ); - } - }; - - struct StartsWith : StringHolder { - StartsWith( NSString* substr ) : StringHolder( substr ){} - - bool match( NSString* str ) const override { - return (str != nil || m_substr == nil ) && - [str rangeOfString:m_substr].location == 0; - } - - std::string describe() const override { - return "starts with: " + Catch::Detail::stringify( m_substr ); - } - }; - struct EndsWith : StringHolder { - EndsWith( NSString* substr ) : StringHolder( substr ){} - - bool match( NSString* str ) const override { - return (str != nil || m_substr == nil ) && - [str rangeOfString:m_substr].location == [str length] - [m_substr length]; - } - - std::string describe() const override { - return "ends with: " + Catch::Detail::stringify( m_substr ); - } - }; - - } // namespace NSStringMatchers - } // namespace Impl - - inline Impl::NSStringMatchers::Equals - Equals( NSString* substr ){ return Impl::NSStringMatchers::Equals( substr ); } - - inline Impl::NSStringMatchers::Contains - Contains( NSString* substr ){ return Impl::NSStringMatchers::Contains( substr ); } - - inline Impl::NSStringMatchers::StartsWith - StartsWith( NSString* substr ){ return Impl::NSStringMatchers::StartsWith( substr ); } - - inline Impl::NSStringMatchers::EndsWith - EndsWith( NSString* substr ){ return Impl::NSStringMatchers::EndsWith( substr ); } - - } // namespace Matchers - - using namespace Matchers; - -#endif // CATCH_CONFIG_DISABLE_MATCHERS - -} // namespace Catch - -/////////////////////////////////////////////////////////////////////////////// -#define OC_MAKE_UNIQUE_NAME( root, uniqueSuffix ) root##uniqueSuffix -#define OC_TEST_CASE2( name, desc, uniqueSuffix ) \ -+(NSString*) OC_MAKE_UNIQUE_NAME( Catch_Name_test_, uniqueSuffix ) \ -{ \ -return @ name; \ -} \ -+(NSString*) OC_MAKE_UNIQUE_NAME( Catch_Description_test_, uniqueSuffix ) \ -{ \ -return @ desc; \ -} \ --(void) OC_MAKE_UNIQUE_NAME( Catch_TestCase_test_, uniqueSuffix ) - -#define OC_TEST_CASE( name, desc ) OC_TEST_CASE2( name, desc, __LINE__ ) - -// end catch_objc.hpp -#endif - -// Benchmarking needs the externally-facing parts of reporters to work -#if defined(CATCH_CONFIG_EXTERNAL_INTERFACES) || defined(CATCH_CONFIG_ENABLE_BENCHMARKING) -// start catch_external_interfaces.h - -// start catch_reporter_bases.hpp - -// start catch_interfaces_reporter.h - -// start catch_config.hpp - -// start catch_test_spec_parser.h - -#ifdef __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wpadded" -#endif - -// start catch_test_spec.h - -#ifdef __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wpadded" -#endif - -// start catch_wildcard_pattern.h - -namespace Catch -{ - class WildcardPattern { - enum WildcardPosition { - NoWildcard = 0, - WildcardAtStart = 1, - WildcardAtEnd = 2, - WildcardAtBothEnds = WildcardAtStart | WildcardAtEnd - }; - - public: - - WildcardPattern( std::string const& pattern, CaseSensitive::Choice caseSensitivity ); - virtual ~WildcardPattern() = default; - virtual bool matches( std::string const& str ) const; - - private: - std::string normaliseString( std::string const& str ) const; - CaseSensitive::Choice m_caseSensitivity; - WildcardPosition m_wildcard = NoWildcard; - std::string m_pattern; - }; -} - -// end catch_wildcard_pattern.h -#include <string> -#include <vector> -#include <memory> - -namespace Catch { - - struct IConfig; - - class TestSpec { - class Pattern { - public: - explicit Pattern( std::string const& name ); - virtual ~Pattern(); - virtual bool matches( TestCaseInfo const& testCase ) const = 0; - std::string const& name() const; - private: - std::string const m_name; - }; - using PatternPtr = std::shared_ptr<Pattern>; - - class NamePattern : public Pattern { - public: - explicit NamePattern( std::string const& name, std::string const& filterString ); - bool matches( TestCaseInfo const& testCase ) const override; - private: - WildcardPattern m_wildcardPattern; - }; - - class TagPattern : public Pattern { - public: - explicit TagPattern( std::string const& tag, std::string const& filterString ); - bool matches( TestCaseInfo const& testCase ) const override; - private: - std::string m_tag; - }; - - class ExcludedPattern : public Pattern { - public: - explicit ExcludedPattern( PatternPtr const& underlyingPattern ); - bool matches( TestCaseInfo const& testCase ) const override; - private: - PatternPtr m_underlyingPattern; - }; - - struct Filter { - std::vector<PatternPtr> m_patterns; - - bool matches( TestCaseInfo const& testCase ) const; - std::string name() const; - }; - - public: - struct FilterMatch { - std::string name; - std::vector<TestCase const*> tests; - }; - using Matches = std::vector<FilterMatch>; - using vectorStrings = std::vector<std::string>; - - bool hasFilters() const; - bool matches( TestCaseInfo const& testCase ) const; - Matches matchesByFilter( std::vector<TestCase> const& testCases, IConfig const& config ) const; - const vectorStrings & getInvalidArgs() const; - - private: - std::vector<Filter> m_filters; - std::vector<std::string> m_invalidArgs; - friend class TestSpecParser; - }; -} - -#ifdef __clang__ -#pragma clang diagnostic pop -#endif - -// end catch_test_spec.h -// start catch_interfaces_tag_alias_registry.h - -#include <string> - -namespace Catch { - - struct TagAlias; - - struct ITagAliasRegistry { - virtual ~ITagAliasRegistry(); - // Nullptr if not present - virtual TagAlias const* find( std::string const& alias ) const = 0; - virtual std::string expandAliases( std::string const& unexpandedTestSpec ) const = 0; - - static ITagAliasRegistry const& get(); - }; - -} // end namespace Catch - -// end catch_interfaces_tag_alias_registry.h -namespace Catch { - - class TestSpecParser { - enum Mode{ None, Name, QuotedName, Tag, EscapedName }; - Mode m_mode = None; - Mode lastMode = None; - bool m_exclusion = false; - std::size_t m_pos = 0; - std::size_t m_realPatternPos = 0; - std::string m_arg; - std::string m_substring; - std::string m_patternName; - std::vector<std::size_t> m_escapeChars; - TestSpec::Filter m_currentFilter; - TestSpec m_testSpec; - ITagAliasRegistry const* m_tagAliases = nullptr; - - public: - TestSpecParser( ITagAliasRegistry const& tagAliases ); - - TestSpecParser& parse( std::string const& arg ); - TestSpec testSpec(); - - private: - bool visitChar( char c ); - void startNewMode( Mode mode ); - bool processNoneChar( char c ); - void processNameChar( char c ); - bool processOtherChar( char c ); - void endMode(); - void escape(); - bool isControlChar( char c ) const; - void saveLastMode(); - void revertBackToLastMode(); - void addFilter(); - bool separate(); - - // Handles common preprocessing of the pattern for name/tag patterns - std::string preprocessPattern(); - // Adds the current pattern as a test name - void addNamePattern(); - // Adds the current pattern as a tag - void addTagPattern(); - - inline void addCharToPattern(char c) { - m_substring += c; - m_patternName += c; - m_realPatternPos++; - } - - }; - TestSpec parseTestSpec( std::string const& arg ); - -} // namespace Catch - -#ifdef __clang__ -#pragma clang diagnostic pop -#endif - -// end catch_test_spec_parser.h -// Libstdc++ doesn't like incomplete classes for unique_ptr - -#include <memory> -#include <vector> -#include <string> - -#ifndef CATCH_CONFIG_CONSOLE_WIDTH -#define CATCH_CONFIG_CONSOLE_WIDTH 80 -#endif - -namespace Catch { - - struct IStream; - - struct ConfigData { - bool listTests = false; - bool listTags = false; - bool listReporters = false; - bool listTestNamesOnly = false; - - bool showSuccessfulTests = false; - bool shouldDebugBreak = false; - bool noThrow = false; - bool showHelp = false; - bool showInvisibles = false; - bool filenamesAsTags = false; - bool libIdentify = false; - - int abortAfter = -1; - unsigned int rngSeed = 0; - - bool benchmarkNoAnalysis = false; - unsigned int benchmarkSamples = 100; - double benchmarkConfidenceInterval = 0.95; - unsigned int benchmarkResamples = 100000; - std::chrono::milliseconds::rep benchmarkWarmupTime = 100; - - Verbosity verbosity = Verbosity::Normal; - WarnAbout::What warnings = WarnAbout::Nothing; - ShowDurations::OrNot showDurations = ShowDurations::DefaultForReporter; - RunTests::InWhatOrder runOrder = RunTests::InDeclarationOrder; - UseColour::YesOrNo useColour = UseColour::Auto; - WaitForKeypress::When waitForKeypress = WaitForKeypress::Never; - - std::string outputFilename; - std::string name; - std::string processName; -#ifndef CATCH_CONFIG_DEFAULT_REPORTER -#define CATCH_CONFIG_DEFAULT_REPORTER "console" -#endif - std::string reporterName = CATCH_CONFIG_DEFAULT_REPORTER; -#undef CATCH_CONFIG_DEFAULT_REPORTER - - std::vector<std::string> testsOrTags; - std::vector<std::string> sectionsToRun; - }; - - class Config : public IConfig { - public: - - Config() = default; - Config( ConfigData const& data ); - virtual ~Config() = default; - - std::string const& getFilename() const; - - bool listTests() const; - bool listTestNamesOnly() const; - bool listTags() const; - bool listReporters() const; - - std::string getProcessName() const; - std::string const& getReporterName() const; - - std::vector<std::string> const& getTestsOrTags() const override; - std::vector<std::string> const& getSectionsToRun() const override; - - TestSpec const& testSpec() const override; - bool hasTestFilters() const override; - - bool showHelp() const; - - // IConfig interface - bool allowThrows() const override; - std::ostream& stream() const override; - std::string name() const override; - bool includeSuccessfulResults() const override; - bool warnAboutMissingAssertions() const override; - bool warnAboutNoTests() const override; - ShowDurations::OrNot showDurations() const override; - RunTests::InWhatOrder runOrder() const override; - unsigned int rngSeed() const override; - UseColour::YesOrNo useColour() const override; - bool shouldDebugBreak() const override; - int abortAfter() const override; - bool showInvisibles() const override; - Verbosity verbosity() const override; - bool benchmarkNoAnalysis() const override; - int benchmarkSamples() const override; - double benchmarkConfidenceInterval() const override; - unsigned int benchmarkResamples() const override; - std::chrono::milliseconds benchmarkWarmupTime() const override; - - private: - - IStream const* openStream(); - ConfigData m_data; - - std::unique_ptr<IStream const> m_stream; - TestSpec m_testSpec; - bool m_hasTestFilters = false; - }; - -} // end namespace Catch - -// end catch_config.hpp -// start catch_assertionresult.h - -#include <string> - -namespace Catch { - - struct AssertionResultData - { - AssertionResultData() = delete; - - AssertionResultData( ResultWas::OfType _resultType, LazyExpression const& _lazyExpression ); - - std::string message; - mutable std::string reconstructedExpression; - LazyExpression lazyExpression; - ResultWas::OfType resultType; - - std::string reconstructExpression() const; - }; - - class AssertionResult { - public: - AssertionResult() = delete; - AssertionResult( AssertionInfo const& info, AssertionResultData const& data ); - - bool isOk() const; - bool succeeded() const; - ResultWas::OfType getResultType() const; - bool hasExpression() const; - bool hasMessage() const; - std::string getExpression() const; - std::string getExpressionInMacro() const; - bool hasExpandedExpression() const; - std::string getExpandedExpression() const; - std::string getMessage() const; - SourceLineInfo getSourceInfo() const; - StringRef getTestMacroName() const; - - //protected: - AssertionInfo m_info; - AssertionResultData m_resultData; - }; - -} // end namespace Catch - -// end catch_assertionresult.h -#if defined(CATCH_CONFIG_ENABLE_BENCHMARKING) -// start catch_estimate.hpp - - // Statistics estimates - - -namespace Catch { - namespace Benchmark { - template <typename Duration> - struct Estimate { - Duration point; - Duration lower_bound; - Duration upper_bound; - double confidence_interval; - - template <typename Duration2> - operator Estimate<Duration2>() const { - return { point, lower_bound, upper_bound, confidence_interval }; - } - }; - } // namespace Benchmark -} // namespace Catch - -// end catch_estimate.hpp -// start catch_outlier_classification.hpp - -// Outlier information - -namespace Catch { - namespace Benchmark { - struct OutlierClassification { - int samples_seen = 0; - int low_severe = 0; // more than 3 times IQR below Q1 - int low_mild = 0; // 1.5 to 3 times IQR below Q1 - int high_mild = 0; // 1.5 to 3 times IQR above Q3 - int high_severe = 0; // more than 3 times IQR above Q3 - - int total() const { - return low_severe + low_mild + high_mild + high_severe; - } - }; - } // namespace Benchmark -} // namespace Catch - -// end catch_outlier_classification.hpp -#endif // CATCH_CONFIG_ENABLE_BENCHMARKING - -#include <string> -#include <iosfwd> -#include <map> -#include <set> -#include <memory> -#include <algorithm> - -namespace Catch { - - struct ReporterConfig { - explicit ReporterConfig( IConfigPtr const& _fullConfig ); - - ReporterConfig( IConfigPtr const& _fullConfig, std::ostream& _stream ); - - std::ostream& stream() const; - IConfigPtr fullConfig() const; - - private: - std::ostream* m_stream; - IConfigPtr m_fullConfig; - }; - - struct ReporterPreferences { - bool shouldRedirectStdOut = false; - bool shouldReportAllAssertions = false; - }; - - template<typename T> - struct LazyStat : Option<T> { - LazyStat& operator=( T const& _value ) { - Option<T>::operator=( _value ); - used = false; - return *this; - } - void reset() { - Option<T>::reset(); - used = false; - } - bool used = false; - }; - - struct TestRunInfo { - TestRunInfo( std::string const& _name ); - std::string name; - }; - struct GroupInfo { - GroupInfo( std::string const& _name, - std::size_t _groupIndex, - std::size_t _groupsCount ); - - std::string name; - std::size_t groupIndex; - std::size_t groupsCounts; - }; - - struct AssertionStats { - AssertionStats( AssertionResult const& _assertionResult, - std::vector<MessageInfo> const& _infoMessages, - Totals const& _totals ); - - AssertionStats( AssertionStats const& ) = default; - AssertionStats( AssertionStats && ) = default; - AssertionStats& operator = ( AssertionStats const& ) = delete; - AssertionStats& operator = ( AssertionStats && ) = delete; - virtual ~AssertionStats(); - - AssertionResult assertionResult; - std::vector<MessageInfo> infoMessages; - Totals totals; - }; - - struct SectionStats { - SectionStats( SectionInfo const& _sectionInfo, - Counts const& _assertions, - double _durationInSeconds, - bool _missingAssertions ); - SectionStats( SectionStats const& ) = default; - SectionStats( SectionStats && ) = default; - SectionStats& operator = ( SectionStats const& ) = default; - SectionStats& operator = ( SectionStats && ) = default; - virtual ~SectionStats(); - - SectionInfo sectionInfo; - Counts assertions; - double durationInSeconds; - bool missingAssertions; - }; - - struct TestCaseStats { - TestCaseStats( TestCaseInfo const& _testInfo, - Totals const& _totals, - std::string const& _stdOut, - std::string const& _stdErr, - bool _aborting ); - - TestCaseStats( TestCaseStats const& ) = default; - TestCaseStats( TestCaseStats && ) = default; - TestCaseStats& operator = ( TestCaseStats const& ) = default; - TestCaseStats& operator = ( TestCaseStats && ) = default; - virtual ~TestCaseStats(); - - TestCaseInfo testInfo; - Totals totals; - std::string stdOut; - std::string stdErr; - bool aborting; - }; - - struct TestGroupStats { - TestGroupStats( GroupInfo const& _groupInfo, - Totals const& _totals, - bool _aborting ); - TestGroupStats( GroupInfo const& _groupInfo ); - - TestGroupStats( TestGroupStats const& ) = default; - TestGroupStats( TestGroupStats && ) = default; - TestGroupStats& operator = ( TestGroupStats const& ) = default; - TestGroupStats& operator = ( TestGroupStats && ) = default; - virtual ~TestGroupStats(); - - GroupInfo groupInfo; - Totals totals; - bool aborting; - }; - - struct TestRunStats { - TestRunStats( TestRunInfo const& _runInfo, - Totals const& _totals, - bool _aborting ); - - TestRunStats( TestRunStats const& ) = default; - TestRunStats( TestRunStats && ) = default; - TestRunStats& operator = ( TestRunStats const& ) = default; - TestRunStats& operator = ( TestRunStats && ) = default; - virtual ~TestRunStats(); - - TestRunInfo runInfo; - Totals totals; - bool aborting; - }; - -#if defined(CATCH_CONFIG_ENABLE_BENCHMARKING) - struct BenchmarkInfo { - std::string name; - double estimatedDuration; - int iterations; - int samples; - unsigned int resamples; - double clockResolution; - double clockCost; - }; - - template <class Duration> - struct BenchmarkStats { - BenchmarkInfo info; - - std::vector<Duration> samples; - Benchmark::Estimate<Duration> mean; - Benchmark::Estimate<Duration> standardDeviation; - Benchmark::OutlierClassification outliers; - double outlierVariance; - - template <typename Duration2> - operator BenchmarkStats<Duration2>() const { - std::vector<Duration2> samples2; - samples2.reserve(samples.size()); - std::transform(samples.begin(), samples.end(), std::back_inserter(samples2), [](Duration d) { return Duration2(d); }); - return { - info, - std::move(samples2), - mean, - standardDeviation, - outliers, - outlierVariance, - }; - } - }; -#endif // CATCH_CONFIG_ENABLE_BENCHMARKING - - struct IStreamingReporter { - virtual ~IStreamingReporter() = default; - - // Implementing class must also provide the following static methods: - // static std::string getDescription(); - // static std::set<Verbosity> getSupportedVerbosities() - - virtual ReporterPreferences getPreferences() const = 0; - - virtual void noMatchingTestCases( std::string const& spec ) = 0; - - virtual void reportInvalidArguments(std::string const&) {} - - virtual void testRunStarting( TestRunInfo const& testRunInfo ) = 0; - virtual void testGroupStarting( GroupInfo const& groupInfo ) = 0; - - virtual void testCaseStarting( TestCaseInfo const& testInfo ) = 0; - virtual void sectionStarting( SectionInfo const& sectionInfo ) = 0; - -#if defined(CATCH_CONFIG_ENABLE_BENCHMARKING) - virtual void benchmarkPreparing( std::string const& ) {} - virtual void benchmarkStarting( BenchmarkInfo const& ) {} - virtual void benchmarkEnded( BenchmarkStats<> const& ) {} - virtual void benchmarkFailed( std::string const& ) {} -#endif // CATCH_CONFIG_ENABLE_BENCHMARKING - - virtual void assertionStarting( AssertionInfo const& assertionInfo ) = 0; - - // The return value indicates if the messages buffer should be cleared: - virtual bool assertionEnded( AssertionStats const& assertionStats ) = 0; - - virtual void sectionEnded( SectionStats const& sectionStats ) = 0; - virtual void testCaseEnded( TestCaseStats const& testCaseStats ) = 0; - virtual void testGroupEnded( TestGroupStats const& testGroupStats ) = 0; - virtual void testRunEnded( TestRunStats const& testRunStats ) = 0; - - virtual void skipTest( TestCaseInfo const& testInfo ) = 0; - - // Default empty implementation provided - virtual void fatalErrorEncountered( StringRef name ); - - virtual bool isMulti() const; - }; - using IStreamingReporterPtr = std::unique_ptr<IStreamingReporter>; - - struct IReporterFactory { - virtual ~IReporterFactory(); - virtual IStreamingReporterPtr create( ReporterConfig const& config ) const = 0; - virtual std::string getDescription() const = 0; - }; - using IReporterFactoryPtr = std::shared_ptr<IReporterFactory>; - - struct IReporterRegistry { - using FactoryMap = std::map<std::string, IReporterFactoryPtr>; - using Listeners = std::vector<IReporterFactoryPtr>; - - virtual ~IReporterRegistry(); - virtual IStreamingReporterPtr create( std::string const& name, IConfigPtr const& config ) const = 0; - virtual FactoryMap const& getFactories() const = 0; - virtual Listeners const& getListeners() const = 0; - }; - -} // end namespace Catch - -// end catch_interfaces_reporter.h -#include <algorithm> -#include <cstring> -#include <cfloat> -#include <cstdio> -#include <cassert> -#include <memory> -#include <ostream> - -namespace Catch { - void prepareExpandedExpression(AssertionResult& result); - - // Returns double formatted as %.3f (format expected on output) - std::string getFormattedDuration( double duration ); - - std::string serializeFilters( std::vector<std::string> const& container ); - - template<typename DerivedT> - struct StreamingReporterBase : IStreamingReporter { - - StreamingReporterBase( ReporterConfig const& _config ) - : m_config( _config.fullConfig() ), - stream( _config.stream() ) - { - m_reporterPrefs.shouldRedirectStdOut = false; - if( !DerivedT::getSupportedVerbosities().count( m_config->verbosity() ) ) - CATCH_ERROR( "Verbosity level not supported by this reporter" ); - } - - ReporterPreferences getPreferences() const override { - return m_reporterPrefs; - } - - static std::set<Verbosity> getSupportedVerbosities() { - return { Verbosity::Normal }; - } - - ~StreamingReporterBase() override = default; - - void noMatchingTestCases(std::string const&) override {} - - void reportInvalidArguments(std::string const&) override {} - - void testRunStarting(TestRunInfo const& _testRunInfo) override { - currentTestRunInfo = _testRunInfo; - } - - void testGroupStarting(GroupInfo const& _groupInfo) override { - currentGroupInfo = _groupInfo; - } - - void testCaseStarting(TestCaseInfo const& _testInfo) override { - currentTestCaseInfo = _testInfo; - } - void sectionStarting(SectionInfo const& _sectionInfo) override { - m_sectionStack.push_back(_sectionInfo); - } - - void sectionEnded(SectionStats const& /* _sectionStats */) override { - m_sectionStack.pop_back(); - } - void testCaseEnded(TestCaseStats const& /* _testCaseStats */) override { - currentTestCaseInfo.reset(); - } - void testGroupEnded(TestGroupStats const& /* _testGroupStats */) override { - currentGroupInfo.reset(); - } - void testRunEnded(TestRunStats const& /* _testRunStats */) override { - currentTestCaseInfo.reset(); - currentGroupInfo.reset(); - currentTestRunInfo.reset(); - } - - void skipTest(TestCaseInfo const&) override { - // Don't do anything with this by default. - // It can optionally be overridden in the derived class. - } - - IConfigPtr m_config; - std::ostream& stream; - - LazyStat<TestRunInfo> currentTestRunInfo; - LazyStat<GroupInfo> currentGroupInfo; - LazyStat<TestCaseInfo> currentTestCaseInfo; - - std::vector<SectionInfo> m_sectionStack; - ReporterPreferences m_reporterPrefs; - }; - - template<typename DerivedT> - struct CumulativeReporterBase : IStreamingReporter { - template<typename T, typename ChildNodeT> - struct Node { - explicit Node( T const& _value ) : value( _value ) {} - virtual ~Node() {} - - using ChildNodes = std::vector<std::shared_ptr<ChildNodeT>>; - T value; - ChildNodes children; - }; - struct SectionNode { - explicit SectionNode(SectionStats const& _stats) : stats(_stats) {} - virtual ~SectionNode() = default; - - bool operator == (SectionNode const& other) const { - return stats.sectionInfo.lineInfo == other.stats.sectionInfo.lineInfo; - } - bool operator == (std::shared_ptr<SectionNode> const& other) const { - return operator==(*other); - } - - SectionStats stats; - using ChildSections = std::vector<std::shared_ptr<SectionNode>>; - using Assertions = std::vector<AssertionStats>; - ChildSections childSections; - Assertions assertions; - std::string stdOut; - std::string stdErr; - }; - - struct BySectionInfo { - BySectionInfo( SectionInfo const& other ) : m_other( other ) {} - BySectionInfo( BySectionInfo const& other ) : m_other( other.m_other ) {} - bool operator() (std::shared_ptr<SectionNode> const& node) const { - return ((node->stats.sectionInfo.name == m_other.name) && - (node->stats.sectionInfo.lineInfo == m_other.lineInfo)); - } - void operator=(BySectionInfo const&) = delete; - - private: - SectionInfo const& m_other; - }; - - using TestCaseNode = Node<TestCaseStats, SectionNode>; - using TestGroupNode = Node<TestGroupStats, TestCaseNode>; - using TestRunNode = Node<TestRunStats, TestGroupNode>; - - CumulativeReporterBase( ReporterConfig const& _config ) - : m_config( _config.fullConfig() ), - stream( _config.stream() ) - { - m_reporterPrefs.shouldRedirectStdOut = false; - if( !DerivedT::getSupportedVerbosities().count( m_config->verbosity() ) ) - CATCH_ERROR( "Verbosity level not supported by this reporter" ); - } - ~CumulativeReporterBase() override = default; - - ReporterPreferences getPreferences() const override { - return m_reporterPrefs; - } - - static std::set<Verbosity> getSupportedVerbosities() { - return { Verbosity::Normal }; - } - - void testRunStarting( TestRunInfo const& ) override {} - void testGroupStarting( GroupInfo const& ) override {} - - void testCaseStarting( TestCaseInfo const& ) override {} - - void sectionStarting( SectionInfo const& sectionInfo ) override { - SectionStats incompleteStats( sectionInfo, Counts(), 0, false ); - std::shared_ptr<SectionNode> node; - if( m_sectionStack.empty() ) { - if( !m_rootSection ) - m_rootSection = std::make_shared<SectionNode>( incompleteStats ); - node = m_rootSection; - } - else { - SectionNode& parentNode = *m_sectionStack.back(); - auto it = - std::find_if( parentNode.childSections.begin(), - parentNode.childSections.end(), - BySectionInfo( sectionInfo ) ); - if( it == parentNode.childSections.end() ) { - node = std::make_shared<SectionNode>( incompleteStats ); - parentNode.childSections.push_back( node ); - } - else - node = *it; - } - m_sectionStack.push_back( node ); - m_deepestSection = std::move(node); - } - - void assertionStarting(AssertionInfo const&) override {} - - bool assertionEnded(AssertionStats const& assertionStats) override { - assert(!m_sectionStack.empty()); - // AssertionResult holds a pointer to a temporary DecomposedExpression, - // which getExpandedExpression() calls to build the expression string. - // Our section stack copy of the assertionResult will likely outlive the - // temporary, so it must be expanded or discarded now to avoid calling - // a destroyed object later. - prepareExpandedExpression(const_cast<AssertionResult&>( assertionStats.assertionResult ) ); - SectionNode& sectionNode = *m_sectionStack.back(); - sectionNode.assertions.push_back(assertionStats); - return true; - } - void sectionEnded(SectionStats const& sectionStats) override { - assert(!m_sectionStack.empty()); - SectionNode& node = *m_sectionStack.back(); - node.stats = sectionStats; - m_sectionStack.pop_back(); - } - void testCaseEnded(TestCaseStats const& testCaseStats) override { - auto node = std::make_shared<TestCaseNode>(testCaseStats); - assert(m_sectionStack.size() == 0); - node->children.push_back(m_rootSection); - m_testCases.push_back(node); - m_rootSection.reset(); - - assert(m_deepestSection); - m_deepestSection->stdOut = testCaseStats.stdOut; - m_deepestSection->stdErr = testCaseStats.stdErr; - } - void testGroupEnded(TestGroupStats const& testGroupStats) override { - auto node = std::make_shared<TestGroupNode>(testGroupStats); - node->children.swap(m_testCases); - m_testGroups.push_back(node); - } - void testRunEnded(TestRunStats const& testRunStats) override { - auto node = std::make_shared<TestRunNode>(testRunStats); - node->children.swap(m_testGroups); - m_testRuns.push_back(node); - testRunEndedCumulative(); - } - virtual void testRunEndedCumulative() = 0; - - void skipTest(TestCaseInfo const&) override {} - - IConfigPtr m_config; - std::ostream& stream; - std::vector<AssertionStats> m_assertions; - std::vector<std::vector<std::shared_ptr<SectionNode>>> m_sections; - std::vector<std::shared_ptr<TestCaseNode>> m_testCases; - std::vector<std::shared_ptr<TestGroupNode>> m_testGroups; - - std::vector<std::shared_ptr<TestRunNode>> m_testRuns; - - std::shared_ptr<SectionNode> m_rootSection; - std::shared_ptr<SectionNode> m_deepestSection; - std::vector<std::shared_ptr<SectionNode>> m_sectionStack; - ReporterPreferences m_reporterPrefs; - }; - - template<char C> - char const* getLineOfChars() { - static char line[CATCH_CONFIG_CONSOLE_WIDTH] = {0}; - if( !*line ) { - std::memset( line, C, CATCH_CONFIG_CONSOLE_WIDTH-1 ); - line[CATCH_CONFIG_CONSOLE_WIDTH-1] = 0; - } - return line; - } - - struct TestEventListenerBase : StreamingReporterBase<TestEventListenerBase> { - TestEventListenerBase( ReporterConfig const& _config ); - - static std::set<Verbosity> getSupportedVerbosities(); - - void assertionStarting(AssertionInfo const&) override; - bool assertionEnded(AssertionStats const&) override; - }; - -} // end namespace Catch - -// end catch_reporter_bases.hpp -// start catch_console_colour.h - -namespace Catch { - - struct Colour { - enum Code { - None = 0, - - White, - Red, - Green, - Blue, - Cyan, - Yellow, - Grey, - - Bright = 0x10, - - BrightRed = Bright | Red, - BrightGreen = Bright | Green, - LightGrey = Bright | Grey, - BrightWhite = Bright | White, - BrightYellow = Bright | Yellow, - - // By intention - FileName = LightGrey, - Warning = BrightYellow, - ResultError = BrightRed, - ResultSuccess = BrightGreen, - ResultExpectedFailure = Warning, - - Error = BrightRed, - Success = Green, - - OriginalExpression = Cyan, - ReconstructedExpression = BrightYellow, - - SecondaryText = LightGrey, - Headers = White - }; - - // Use constructed object for RAII guard - Colour( Code _colourCode ); - Colour( Colour&& other ) noexcept; - Colour& operator=( Colour&& other ) noexcept; - ~Colour(); - - // Use static method for one-shot changes - static void use( Code _colourCode ); - - private: - bool m_moved = false; - }; - - std::ostream& operator << ( std::ostream& os, Colour const& ); - -} // end namespace Catch - -// end catch_console_colour.h -// start catch_reporter_registrars.hpp - - -namespace Catch { - - template<typename T> - class ReporterRegistrar { - - class ReporterFactory : public IReporterFactory { - - IStreamingReporterPtr create( ReporterConfig const& config ) const override { - return std::unique_ptr<T>( new T( config ) ); - } - - std::string getDescription() const override { - return T::getDescription(); - } - }; - - public: - - explicit ReporterRegistrar( std::string const& name ) { - getMutableRegistryHub().registerReporter( name, std::make_shared<ReporterFactory>() ); - } - }; - - template<typename T> - class ListenerRegistrar { - - class ListenerFactory : public IReporterFactory { - - IStreamingReporterPtr create( ReporterConfig const& config ) const override { - return std::unique_ptr<T>( new T( config ) ); - } - std::string getDescription() const override { - return std::string(); - } - }; - - public: - - ListenerRegistrar() { - getMutableRegistryHub().registerListener( std::make_shared<ListenerFactory>() ); - } - }; -} - -#if !defined(CATCH_CONFIG_DISABLE) - -#define CATCH_REGISTER_REPORTER( name, reporterType ) \ - CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \ - CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ - namespace{ Catch::ReporterRegistrar<reporterType> catch_internal_RegistrarFor##reporterType( name ); } \ - CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION - -#define CATCH_REGISTER_LISTENER( listenerType ) \ - CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \ - CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ - namespace{ Catch::ListenerRegistrar<listenerType> catch_internal_RegistrarFor##listenerType; } \ - CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION -#else // CATCH_CONFIG_DISABLE - -#define CATCH_REGISTER_REPORTER(name, reporterType) -#define CATCH_REGISTER_LISTENER(listenerType) - -#endif // CATCH_CONFIG_DISABLE - -// end catch_reporter_registrars.hpp -// Allow users to base their work off existing reporters -// start catch_reporter_compact.h - -namespace Catch { - - struct CompactReporter : StreamingReporterBase<CompactReporter> { - - using StreamingReporterBase::StreamingReporterBase; - - ~CompactReporter() override; - - static std::string getDescription(); - - ReporterPreferences getPreferences() const override; - - void noMatchingTestCases(std::string const& spec) override; - - void assertionStarting(AssertionInfo const&) override; - - bool assertionEnded(AssertionStats const& _assertionStats) override; - - void sectionEnded(SectionStats const& _sectionStats) override; - - void testRunEnded(TestRunStats const& _testRunStats) override; - - }; - -} // end namespace Catch - -// end catch_reporter_compact.h -// start catch_reporter_console.h - -#if defined(_MSC_VER) -#pragma warning(push) -#pragma warning(disable:4061) // Not all labels are EXPLICITLY handled in switch - // Note that 4062 (not all labels are handled - // and default is missing) is enabled -#endif - -namespace Catch { - // Fwd decls - struct SummaryColumn; - class TablePrinter; - - struct ConsoleReporter : StreamingReporterBase<ConsoleReporter> { - std::unique_ptr<TablePrinter> m_tablePrinter; - - ConsoleReporter(ReporterConfig const& config); - ~ConsoleReporter() override; - static std::string getDescription(); - - void noMatchingTestCases(std::string const& spec) override; - - void reportInvalidArguments(std::string const&arg) override; - - void assertionStarting(AssertionInfo const&) override; - - bool assertionEnded(AssertionStats const& _assertionStats) override; - - void sectionStarting(SectionInfo const& _sectionInfo) override; - void sectionEnded(SectionStats const& _sectionStats) override; - -#if defined(CATCH_CONFIG_ENABLE_BENCHMARKING) - void benchmarkPreparing(std::string const& name) override; - void benchmarkStarting(BenchmarkInfo const& info) override; - void benchmarkEnded(BenchmarkStats<> const& stats) override; - void benchmarkFailed(std::string const& error) override; -#endif // CATCH_CONFIG_ENABLE_BENCHMARKING - - void testCaseEnded(TestCaseStats const& _testCaseStats) override; - void testGroupEnded(TestGroupStats const& _testGroupStats) override; - void testRunEnded(TestRunStats const& _testRunStats) override; - void testRunStarting(TestRunInfo const& _testRunInfo) override; - private: - - void lazyPrint(); - - void lazyPrintWithoutClosingBenchmarkTable(); - void lazyPrintRunInfo(); - void lazyPrintGroupInfo(); - void printTestCaseAndSectionHeader(); - - void printClosedHeader(std::string const& _name); - void printOpenHeader(std::string const& _name); - - // if string has a : in first line will set indent to follow it on - // subsequent lines - void printHeaderString(std::string const& _string, std::size_t indent = 0); - - void printTotals(Totals const& totals); - void printSummaryRow(std::string const& label, std::vector<SummaryColumn> const& cols, std::size_t row); - - void printTotalsDivider(Totals const& totals); - void printSummaryDivider(); - void printTestFilters(); - - private: - bool m_headerPrinted = false; - }; - -} // end namespace Catch - -#if defined(_MSC_VER) -#pragma warning(pop) -#endif - -// end catch_reporter_console.h -// start catch_reporter_junit.h - -// start catch_xmlwriter.h - -#include <vector> - -namespace Catch { - enum class XmlFormatting { - None = 0x00, - Indent = 0x01, - Newline = 0x02, - }; - - XmlFormatting operator | (XmlFormatting lhs, XmlFormatting rhs); - XmlFormatting operator & (XmlFormatting lhs, XmlFormatting rhs); - - class XmlEncode { - public: - enum ForWhat { ForTextNodes, ForAttributes }; - - XmlEncode( std::string const& str, ForWhat forWhat = ForTextNodes ); - - void encodeTo( std::ostream& os ) const; - - friend std::ostream& operator << ( std::ostream& os, XmlEncode const& xmlEncode ); - - private: - std::string m_str; - ForWhat m_forWhat; - }; - - class XmlWriter { - public: - - class ScopedElement { - public: - ScopedElement( XmlWriter* writer, XmlFormatting fmt ); - - ScopedElement( ScopedElement&& other ) noexcept; - ScopedElement& operator=( ScopedElement&& other ) noexcept; - - ~ScopedElement(); - - ScopedElement& writeText( std::string const& text, XmlFormatting fmt = XmlFormatting::Newline | XmlFormatting::Indent ); - - template<typename T> - ScopedElement& writeAttribute( std::string const& name, T const& attribute ) { - m_writer->writeAttribute( name, attribute ); - return *this; - } - - private: - mutable XmlWriter* m_writer = nullptr; - XmlFormatting m_fmt; - }; - - XmlWriter( std::ostream& os = Catch::cout() ); - ~XmlWriter(); - - XmlWriter( XmlWriter const& ) = delete; - XmlWriter& operator=( XmlWriter const& ) = delete; - - XmlWriter& startElement( std::string const& name, XmlFormatting fmt = XmlFormatting::Newline | XmlFormatting::Indent); - - ScopedElement scopedElement( std::string const& name, XmlFormatting fmt = XmlFormatting::Newline | XmlFormatting::Indent); - - XmlWriter& endElement(XmlFormatting fmt = XmlFormatting::Newline | XmlFormatting::Indent); - - XmlWriter& writeAttribute( std::string const& name, std::string const& attribute ); - - XmlWriter& writeAttribute( std::string const& name, bool attribute ); - - template<typename T> - XmlWriter& writeAttribute( std::string const& name, T const& attribute ) { - ReusableStringStream rss; - rss << attribute; - return writeAttribute( name, rss.str() ); - } - - XmlWriter& writeText( std::string const& text, XmlFormatting fmt = XmlFormatting::Newline | XmlFormatting::Indent); - - XmlWriter& writeComment(std::string const& text, XmlFormatting fmt = XmlFormatting::Newline | XmlFormatting::Indent); - - void writeStylesheetRef( std::string const& url ); - - XmlWriter& writeBlankLine(); - - void ensureTagClosed(); - - private: - - void applyFormatting(XmlFormatting fmt); - - void writeDeclaration(); - - void newlineIfNecessary(); - - bool m_tagIsOpen = false; - bool m_needsNewline = false; - std::vector<std::string> m_tags; - std::string m_indent; - std::ostream& m_os; - }; - -} - -// end catch_xmlwriter.h -namespace Catch { - - class JunitReporter : public CumulativeReporterBase<JunitReporter> { - public: - JunitReporter(ReporterConfig const& _config); - - ~JunitReporter() override; - - static std::string getDescription(); - - void noMatchingTestCases(std::string const& /*spec*/) override; - - void testRunStarting(TestRunInfo const& runInfo) override; - - void testGroupStarting(GroupInfo const& groupInfo) override; - - void testCaseStarting(TestCaseInfo const& testCaseInfo) override; - bool assertionEnded(AssertionStats const& assertionStats) override; - - void testCaseEnded(TestCaseStats const& testCaseStats) override; - - void testGroupEnded(TestGroupStats const& testGroupStats) override; - - void testRunEndedCumulative() override; - - void writeGroup(TestGroupNode const& groupNode, double suiteTime); - - void writeTestCase(TestCaseNode const& testCaseNode); - - void writeSection(std::string const& className, - std::string const& rootName, - SectionNode const& sectionNode); - - void writeAssertions(SectionNode const& sectionNode); - void writeAssertion(AssertionStats const& stats); - - XmlWriter xml; - Timer suiteTimer; - std::string stdOutForSuite; - std::string stdErrForSuite; - unsigned int unexpectedExceptions = 0; - bool m_okToFail = false; - }; - -} // end namespace Catch - -// end catch_reporter_junit.h -// start catch_reporter_xml.h - -namespace Catch { - class XmlReporter : public StreamingReporterBase<XmlReporter> { - public: - XmlReporter(ReporterConfig const& _config); - - ~XmlReporter() override; - - static std::string getDescription(); - - virtual std::string getStylesheetRef() const; - - void writeSourceInfo(SourceLineInfo const& sourceInfo); - - public: // StreamingReporterBase - - void noMatchingTestCases(std::string const& s) override; - - void testRunStarting(TestRunInfo const& testInfo) override; - - void testGroupStarting(GroupInfo const& groupInfo) override; - - void testCaseStarting(TestCaseInfo const& testInfo) override; - - void sectionStarting(SectionInfo const& sectionInfo) override; - - void assertionStarting(AssertionInfo const&) override; - - bool assertionEnded(AssertionStats const& assertionStats) override; - - void sectionEnded(SectionStats const& sectionStats) override; - - void testCaseEnded(TestCaseStats const& testCaseStats) override; - - void testGroupEnded(TestGroupStats const& testGroupStats) override; - - void testRunEnded(TestRunStats const& testRunStats) override; - -#if defined(CATCH_CONFIG_ENABLE_BENCHMARKING) - void benchmarkPreparing(std::string const& name) override; - void benchmarkStarting(BenchmarkInfo const&) override; - void benchmarkEnded(BenchmarkStats<> const&) override; - void benchmarkFailed(std::string const&) override; -#endif // CATCH_CONFIG_ENABLE_BENCHMARKING - - private: - Timer m_testCaseTimer; - XmlWriter m_xml; - int m_sectionDepth = 0; - }; - -} // end namespace Catch - -// end catch_reporter_xml.h - -// end catch_external_interfaces.h -#endif - -#if defined(CATCH_CONFIG_ENABLE_BENCHMARKING) -// start catch_benchmarking_all.hpp - -// A proxy header that includes all of the benchmarking headers to allow -// concise include of the benchmarking features. You should prefer the -// individual includes in standard use. - -// start catch_benchmark.hpp - - // Benchmark - -// start catch_chronometer.hpp - -// User-facing chronometer - - -// start catch_clock.hpp - -// Clocks - - -#include <chrono> -#include <ratio> - -namespace Catch { - namespace Benchmark { - template <typename Clock> - using ClockDuration = typename Clock::duration; - template <typename Clock> - using FloatDuration = std::chrono::duration<double, typename Clock::period>; - - template <typename Clock> - using TimePoint = typename Clock::time_point; - - using default_clock = std::chrono::steady_clock; - - template <typename Clock> - struct now { - TimePoint<Clock> operator()() const { - return Clock::now(); - } - }; - - using fp_seconds = std::chrono::duration<double, std::ratio<1>>; - } // namespace Benchmark -} // namespace Catch - -// end catch_clock.hpp -// start catch_optimizer.hpp - - // Hinting the optimizer - - -#if defined(_MSC_VER) -# include <atomic> // atomic_thread_fence -#endif - -namespace Catch { - namespace Benchmark { -#if defined(__GNUC__) || defined(__clang__) - template <typename T> - inline void keep_memory(T* p) { - asm volatile("" : : "g"(p) : "memory"); - } - inline void keep_memory() { - asm volatile("" : : : "memory"); - } - - namespace Detail { - inline void optimizer_barrier() { keep_memory(); } - } // namespace Detail -#elif defined(_MSC_VER) - -#pragma optimize("", off) - template <typename T> - inline void keep_memory(T* p) { - // thanks @milleniumbug - *reinterpret_cast<char volatile*>(p) = *reinterpret_cast<char const volatile*>(p); - } - // TODO equivalent keep_memory() -#pragma optimize("", on) - - namespace Detail { - inline void optimizer_barrier() { - std::atomic_thread_fence(std::memory_order_seq_cst); - } - } // namespace Detail - -#endif - - template <typename T> - inline void deoptimize_value(T&& x) { - keep_memory(&x); - } - - template <typename Fn, typename... Args> - inline auto invoke_deoptimized(Fn&& fn, Args&&... args) -> typename std::enable_if<!std::is_same<void, decltype(fn(args...))>::value>::type { - deoptimize_value(std::forward<Fn>(fn) (std::forward<Args...>(args...))); - } - - template <typename Fn, typename... Args> - inline auto invoke_deoptimized(Fn&& fn, Args&&... args) -> typename std::enable_if<std::is_same<void, decltype(fn(args...))>::value>::type { - std::forward<Fn>(fn) (std::forward<Args...>(args...)); - } - } // namespace Benchmark -} // namespace Catch - -// end catch_optimizer.hpp -// start catch_complete_invoke.hpp - -// Invoke with a special case for void - - -#include <type_traits> -#include <utility> - -namespace Catch { - namespace Benchmark { - namespace Detail { - template <typename T> - struct CompleteType { using type = T; }; - template <> - struct CompleteType<void> { struct type {}; }; - - template <typename T> - using CompleteType_t = typename CompleteType<T>::type; - - template <typename Result> - struct CompleteInvoker { - template <typename Fun, typename... Args> - static Result invoke(Fun&& fun, Args&&... args) { - return std::forward<Fun>(fun)(std::forward<Args>(args)...); - } - }; - template <> - struct CompleteInvoker<void> { - template <typename Fun, typename... Args> - static CompleteType_t<void> invoke(Fun&& fun, Args&&... args) { - std::forward<Fun>(fun)(std::forward<Args>(args)...); - return {}; - } - }; - template <typename Sig> - using ResultOf_t = typename std::result_of<Sig>::type; - - // invoke and not return void :( - template <typename Fun, typename... Args> - CompleteType_t<ResultOf_t<Fun(Args...)>> complete_invoke(Fun&& fun, Args&&... args) { - return CompleteInvoker<ResultOf_t<Fun(Args...)>>::invoke(std::forward<Fun>(fun), std::forward<Args>(args)...); - } - - const std::string benchmarkErrorMsg = "a benchmark failed to run successfully"; - } // namespace Detail - - template <typename Fun> - Detail::CompleteType_t<Detail::ResultOf_t<Fun()>> user_code(Fun&& fun) { - CATCH_TRY{ - return Detail::complete_invoke(std::forward<Fun>(fun)); - } CATCH_CATCH_ALL{ - getResultCapture().benchmarkFailed(translateActiveException()); - CATCH_RUNTIME_ERROR(Detail::benchmarkErrorMsg); - } - } - } // namespace Benchmark -} // namespace Catch - -// end catch_complete_invoke.hpp -namespace Catch { - namespace Benchmark { - namespace Detail { - struct ChronometerConcept { - virtual void start() = 0; - virtual void finish() = 0; - virtual ~ChronometerConcept() = default; - }; - template <typename Clock> - struct ChronometerModel final : public ChronometerConcept { - void start() override { started = Clock::now(); } - void finish() override { finished = Clock::now(); } - - ClockDuration<Clock> elapsed() const { return finished - started; } - - TimePoint<Clock> started; - TimePoint<Clock> finished; - }; - } // namespace Detail - - struct Chronometer { - public: - template <typename Fun> - void measure(Fun&& fun) { measure(std::forward<Fun>(fun), is_callable<Fun(int)>()); } - - int runs() const { return k; } - - Chronometer(Detail::ChronometerConcept& meter, int k) - : impl(&meter) - , k(k) {} - - private: - template <typename Fun> - void measure(Fun&& fun, std::false_type) { - measure([&fun](int) { return fun(); }, std::true_type()); - } - - template <typename Fun> - void measure(Fun&& fun, std::true_type) { - Detail::optimizer_barrier(); - impl->start(); - for (int i = 0; i < k; ++i) invoke_deoptimized(fun, i); - impl->finish(); - Detail::optimizer_barrier(); - } - - Detail::ChronometerConcept* impl; - int k; - }; - } // namespace Benchmark -} // namespace Catch - -// end catch_chronometer.hpp -// start catch_environment.hpp - -// Environment information - - -namespace Catch { - namespace Benchmark { - template <typename Duration> - struct EnvironmentEstimate { - Duration mean; - OutlierClassification outliers; - - template <typename Duration2> - operator EnvironmentEstimate<Duration2>() const { - return { mean, outliers }; - } - }; - template <typename Clock> - struct Environment { - using clock_type = Clock; - EnvironmentEstimate<FloatDuration<Clock>> clock_resolution; - EnvironmentEstimate<FloatDuration<Clock>> clock_cost; - }; - } // namespace Benchmark -} // namespace Catch - -// end catch_environment.hpp -// start catch_execution_plan.hpp - - // Execution plan - - -// start catch_benchmark_function.hpp - - // Dumb std::function implementation for consistent call overhead - - -#include <cassert> -#include <type_traits> -#include <utility> -#include <memory> - -namespace Catch { - namespace Benchmark { - namespace Detail { - template <typename T> - using Decay = typename std::decay<T>::type; - template <typename T, typename U> - struct is_related - : std::is_same<Decay<T>, Decay<U>> {}; - - /// We need to reinvent std::function because every piece of code that might add overhead - /// in a measurement context needs to have consistent performance characteristics so that we - /// can account for it in the measurement. - /// Implementations of std::function with optimizations that aren't always applicable, like - /// small buffer optimizations, are not uncommon. - /// This is effectively an implementation of std::function without any such optimizations; - /// it may be slow, but it is consistently slow. - struct BenchmarkFunction { - private: - struct callable { - virtual void call(Chronometer meter) const = 0; - virtual callable* clone() const = 0; - virtual ~callable() = default; - }; - template <typename Fun> - struct model : public callable { - model(Fun&& fun) : fun(std::move(fun)) {} - model(Fun const& fun) : fun(fun) {} - - model<Fun>* clone() const override { return new model<Fun>(*this); } - - void call(Chronometer meter) const override { - call(meter, is_callable<Fun(Chronometer)>()); - } - void call(Chronometer meter, std::true_type) const { - fun(meter); - } - void call(Chronometer meter, std::false_type) const { - meter.measure(fun); - } - - Fun fun; - }; - - struct do_nothing { void operator()() const {} }; - - template <typename T> - BenchmarkFunction(model<T>* c) : f(c) {} - - public: - BenchmarkFunction() - : f(new model<do_nothing>{ {} }) {} - - template <typename Fun, - typename std::enable_if<!is_related<Fun, BenchmarkFunction>::value, int>::type = 0> - BenchmarkFunction(Fun&& fun) - : f(new model<typename std::decay<Fun>::type>(std::forward<Fun>(fun))) {} - - BenchmarkFunction(BenchmarkFunction&& that) - : f(std::move(that.f)) {} - - BenchmarkFunction(BenchmarkFunction const& that) - : f(that.f->clone()) {} - - BenchmarkFunction& operator=(BenchmarkFunction&& that) { - f = std::move(that.f); - return *this; - } - - BenchmarkFunction& operator=(BenchmarkFunction const& that) { - f.reset(that.f->clone()); - return *this; - } - - void operator()(Chronometer meter) const { f->call(meter); } - - private: - std::unique_ptr<callable> f; - }; - } // namespace Detail - } // namespace Benchmark -} // namespace Catch - -// end catch_benchmark_function.hpp -// start catch_repeat.hpp - -// repeat algorithm - - -#include <type_traits> -#include <utility> - -namespace Catch { - namespace Benchmark { - namespace Detail { - template <typename Fun> - struct repeater { - void operator()(int k) const { - for (int i = 0; i < k; ++i) { - fun(); - } - } - Fun fun; - }; - template <typename Fun> - repeater<typename std::decay<Fun>::type> repeat(Fun&& fun) { - return { std::forward<Fun>(fun) }; - } - } // namespace Detail - } // namespace Benchmark -} // namespace Catch - -// end catch_repeat.hpp -// start catch_run_for_at_least.hpp - -// Run a function for a minimum amount of time - - -// start catch_measure.hpp - -// Measure - - -// start catch_timing.hpp - -// Timing - - -#include <tuple> -#include <type_traits> - -namespace Catch { - namespace Benchmark { - template <typename Duration, typename Result> - struct Timing { - Duration elapsed; - Result result; - int iterations; - }; - template <typename Clock, typename Sig> - using TimingOf = Timing<ClockDuration<Clock>, Detail::CompleteType_t<Detail::ResultOf_t<Sig>>>; - } // namespace Benchmark -} // namespace Catch - -// end catch_timing.hpp -#include <utility> - -namespace Catch { - namespace Benchmark { - namespace Detail { - template <typename Clock, typename Fun, typename... Args> - TimingOf<Clock, Fun(Args...)> measure(Fun&& fun, Args&&... args) { - auto start = Clock::now(); - auto&& r = Detail::complete_invoke(fun, std::forward<Args>(args)...); - auto end = Clock::now(); - auto delta = end - start; - return { delta, std::forward<decltype(r)>(r), 1 }; - } - } // namespace Detail - } // namespace Benchmark -} // namespace Catch - -// end catch_measure.hpp -#include <utility> -#include <type_traits> - -namespace Catch { - namespace Benchmark { - namespace Detail { - template <typename Clock, typename Fun> - TimingOf<Clock, Fun(int)> measure_one(Fun&& fun, int iters, std::false_type) { - return Detail::measure<Clock>(fun, iters); - } - template <typename Clock, typename Fun> - TimingOf<Clock, Fun(Chronometer)> measure_one(Fun&& fun, int iters, std::true_type) { - Detail::ChronometerModel<Clock> meter; - auto&& result = Detail::complete_invoke(fun, Chronometer(meter, iters)); - - return { meter.elapsed(), std::move(result), iters }; - } - - template <typename Clock, typename Fun> - using run_for_at_least_argument_t = typename std::conditional<is_callable<Fun(Chronometer)>::value, Chronometer, int>::type; - - struct optimized_away_error : std::exception { - const char* what() const noexcept override { - return "could not measure benchmark, maybe it was optimized away"; - } - }; - - template <typename Clock, typename Fun> - TimingOf<Clock, Fun(run_for_at_least_argument_t<Clock, Fun>)> run_for_at_least(ClockDuration<Clock> how_long, int seed, Fun&& fun) { - auto iters = seed; - while (iters < (1 << 30)) { - auto&& Timing = measure_one<Clock>(fun, iters, is_callable<Fun(Chronometer)>()); - - if (Timing.elapsed >= how_long) { - return { Timing.elapsed, std::move(Timing.result), iters }; - } - iters *= 2; - } - throw optimized_away_error{}; - } - } // namespace Detail - } // namespace Benchmark -} // namespace Catch - -// end catch_run_for_at_least.hpp -#include <algorithm> - -namespace Catch { - namespace Benchmark { - template <typename Duration> - struct ExecutionPlan { - int iterations_per_sample; - Duration estimated_duration; - Detail::BenchmarkFunction benchmark; - Duration warmup_time; - int warmup_iterations; - - template <typename Duration2> - operator ExecutionPlan<Duration2>() const { - return { iterations_per_sample, estimated_duration, benchmark, warmup_time, warmup_iterations }; - } - - template <typename Clock> - std::vector<FloatDuration<Clock>> run(const IConfig &cfg, Environment<FloatDuration<Clock>> env) const { - // warmup a bit - Detail::run_for_at_least<Clock>(std::chrono::duration_cast<ClockDuration<Clock>>(warmup_time), warmup_iterations, Detail::repeat(now<Clock>{})); - - std::vector<FloatDuration<Clock>> times; - times.reserve(cfg.benchmarkSamples()); - std::generate_n(std::back_inserter(times), cfg.benchmarkSamples(), [this, env] { - Detail::ChronometerModel<Clock> model; - this->benchmark(Chronometer(model, iterations_per_sample)); - auto sample_time = model.elapsed() - env.clock_cost.mean; - if (sample_time < FloatDuration<Clock>::zero()) sample_time = FloatDuration<Clock>::zero(); - return sample_time / iterations_per_sample; - }); - return times; - } - }; - } // namespace Benchmark -} // namespace Catch - -// end catch_execution_plan.hpp -// start catch_estimate_clock.hpp - - // Environment measurement - - -// start catch_stats.hpp - -// Statistical analysis tools - - -#include <algorithm> -#include <functional> -#include <vector> -#include <iterator> -#include <numeric> -#include <tuple> -#include <cmath> -#include <utility> -#include <cstddef> -#include <random> - -namespace Catch { - namespace Benchmark { - namespace Detail { - using sample = std::vector<double>; - - double weighted_average_quantile(int k, int q, std::vector<double>::iterator first, std::vector<double>::iterator last); - - template <typename Iterator> - OutlierClassification classify_outliers(Iterator first, Iterator last) { - std::vector<double> copy(first, last); - - auto q1 = weighted_average_quantile(1, 4, copy.begin(), copy.end()); - auto q3 = weighted_average_quantile(3, 4, copy.begin(), copy.end()); - auto iqr = q3 - q1; - auto los = q1 - (iqr * 3.); - auto lom = q1 - (iqr * 1.5); - auto him = q3 + (iqr * 1.5); - auto his = q3 + (iqr * 3.); - - OutlierClassification o; - for (; first != last; ++first) { - auto&& t = *first; - if (t < los) ++o.low_severe; - else if (t < lom) ++o.low_mild; - else if (t > his) ++o.high_severe; - else if (t > him) ++o.high_mild; - ++o.samples_seen; - } - return o; - } - - template <typename Iterator> - double mean(Iterator first, Iterator last) { - auto count = last - first; - double sum = std::accumulate(first, last, 0.); - return sum / count; - } - - template <typename URng, typename Iterator, typename Estimator> - sample resample(URng& rng, int resamples, Iterator first, Iterator last, Estimator& estimator) { - auto n = last - first; - std::uniform_int_distribution<decltype(n)> dist(0, n - 1); - - sample out; - out.reserve(resamples); - std::generate_n(std::back_inserter(out), resamples, [n, first, &estimator, &dist, &rng] { - std::vector<double> resampled; - resampled.reserve(n); - std::generate_n(std::back_inserter(resampled), n, [first, &dist, &rng] { return first[dist(rng)]; }); - return estimator(resampled.begin(), resampled.end()); - }); - std::sort(out.begin(), out.end()); - return out; - } - - template <typename Estimator, typename Iterator> - sample jackknife(Estimator&& estimator, Iterator first, Iterator last) { - auto n = last - first; - auto second = std::next(first); - sample results; - results.reserve(n); - - for (auto it = first; it != last; ++it) { - std::iter_swap(it, first); - results.push_back(estimator(second, last)); - } - - return results; - } - - inline double normal_cdf(double x) { - return std::erfc(-x / std::sqrt(2.0)) / 2.0; - } - - double erfc_inv(double x); - - double normal_quantile(double p); - - template <typename Iterator, typename Estimator> - Estimate<double> bootstrap(double confidence_level, Iterator first, Iterator last, sample const& resample, Estimator&& estimator) { - auto n_samples = last - first; - - double point = estimator(first, last); - // Degenerate case with a single sample - if (n_samples == 1) return { point, point, point, confidence_level }; - - sample jack = jackknife(estimator, first, last); - double jack_mean = mean(jack.begin(), jack.end()); - double sum_squares, sum_cubes; - std::tie(sum_squares, sum_cubes) = std::accumulate(jack.begin(), jack.end(), std::make_pair(0., 0.), [jack_mean](std::pair<double, double> sqcb, double x) -> std::pair<double, double> { - auto d = jack_mean - x; - auto d2 = d * d; - auto d3 = d2 * d; - return { sqcb.first + d2, sqcb.second + d3 }; - }); - - double accel = sum_cubes / (6 * std::pow(sum_squares, 1.5)); - int n = static_cast<int>(resample.size()); - double prob_n = std::count_if(resample.begin(), resample.end(), [point](double x) { return x < point; }) / (double)n; - // degenerate case with uniform samples - if (prob_n == 0) return { point, point, point, confidence_level }; - - double bias = normal_quantile(prob_n); - double z1 = normal_quantile((1. - confidence_level) / 2.); - - auto cumn = [n](double x) -> int { - return std::lround(normal_cdf(x) * n); }; - auto a = [bias, accel](double b) { return bias + b / (1. - accel * b); }; - double b1 = bias + z1; - double b2 = bias - z1; - double a1 = a(b1); - double a2 = a(b2); - auto lo = std::max(cumn(a1), 0); - auto hi = std::min(cumn(a2), n - 1); - - return { point, resample[lo], resample[hi], confidence_level }; - } - - double outlier_variance(Estimate<double> mean, Estimate<double> stddev, int n); - - struct bootstrap_analysis { - Estimate<double> mean; - Estimate<double> standard_deviation; - double outlier_variance; - }; - - bootstrap_analysis analyse_samples(double confidence_level, int n_resamples, std::vector<double>::iterator first, std::vector<double>::iterator last); - } // namespace Detail - } // namespace Benchmark -} // namespace Catch - -// end catch_stats.hpp -#include <algorithm> -#include <iterator> -#include <tuple> -#include <vector> -#include <cmath> - -namespace Catch { - namespace Benchmark { - namespace Detail { - template <typename Clock> - std::vector<double> resolution(int k) { - std::vector<TimePoint<Clock>> times; - times.reserve(k + 1); - std::generate_n(std::back_inserter(times), k + 1, now<Clock>{}); - - std::vector<double> deltas; - deltas.reserve(k); - std::transform(std::next(times.begin()), times.end(), times.begin(), - std::back_inserter(deltas), - [](TimePoint<Clock> a, TimePoint<Clock> b) { return static_cast<double>((a - b).count()); }); - - return deltas; - } - - const auto warmup_iterations = 10000; - const auto warmup_time = std::chrono::milliseconds(100); - const auto minimum_ticks = 1000; - const auto warmup_seed = 10000; - const auto clock_resolution_estimation_time = std::chrono::milliseconds(500); - const auto clock_cost_estimation_time_limit = std::chrono::seconds(1); - const auto clock_cost_estimation_tick_limit = 100000; - const auto clock_cost_estimation_time = std::chrono::milliseconds(10); - const auto clock_cost_estimation_iterations = 10000; - - template <typename Clock> - int warmup() { - return run_for_at_least<Clock>(std::chrono::duration_cast<ClockDuration<Clock>>(warmup_time), warmup_seed, &resolution<Clock>) - .iterations; - } - template <typename Clock> - EnvironmentEstimate<FloatDuration<Clock>> estimate_clock_resolution(int iterations) { - auto r = run_for_at_least<Clock>(std::chrono::duration_cast<ClockDuration<Clock>>(clock_resolution_estimation_time), iterations, &resolution<Clock>) - .result; - return { - FloatDuration<Clock>(mean(r.begin(), r.end())), - classify_outliers(r.begin(), r.end()), - }; - } - template <typename Clock> - EnvironmentEstimate<FloatDuration<Clock>> estimate_clock_cost(FloatDuration<Clock> resolution) { - auto time_limit = std::min(resolution * clock_cost_estimation_tick_limit, FloatDuration<Clock>(clock_cost_estimation_time_limit)); - auto time_clock = [](int k) { - return Detail::measure<Clock>([k] { - for (int i = 0; i < k; ++i) { - volatile auto ignored = Clock::now(); - (void)ignored; - } - }).elapsed; - }; - time_clock(1); - int iters = clock_cost_estimation_iterations; - auto&& r = run_for_at_least<Clock>(std::chrono::duration_cast<ClockDuration<Clock>>(clock_cost_estimation_time), iters, time_clock); - std::vector<double> times; - int nsamples = static_cast<int>(std::ceil(time_limit / r.elapsed)); - times.reserve(nsamples); - std::generate_n(std::back_inserter(times), nsamples, [time_clock, &r] { - return static_cast<double>((time_clock(r.iterations) / r.iterations).count()); - }); - return { - FloatDuration<Clock>(mean(times.begin(), times.end())), - classify_outliers(times.begin(), times.end()), - }; - } - - template <typename Clock> - Environment<FloatDuration<Clock>> measure_environment() { - static Environment<FloatDuration<Clock>>* env = nullptr; - if (env) { - return *env; - } - - auto iters = Detail::warmup<Clock>(); - auto resolution = Detail::estimate_clock_resolution<Clock>(iters); - auto cost = Detail::estimate_clock_cost<Clock>(resolution.mean); - - env = new Environment<FloatDuration<Clock>>{ resolution, cost }; - return *env; - } - } // namespace Detail - } // namespace Benchmark -} // namespace Catch - -// end catch_estimate_clock.hpp -// start catch_analyse.hpp - - // Run and analyse one benchmark - - -// start catch_sample_analysis.hpp - -// Benchmark results - - -#include <algorithm> -#include <vector> -#include <string> -#include <iterator> - -namespace Catch { - namespace Benchmark { - template <typename Duration> - struct SampleAnalysis { - std::vector<Duration> samples; - Estimate<Duration> mean; - Estimate<Duration> standard_deviation; - OutlierClassification outliers; - double outlier_variance; - - template <typename Duration2> - operator SampleAnalysis<Duration2>() const { - std::vector<Duration2> samples2; - samples2.reserve(samples.size()); - std::transform(samples.begin(), samples.end(), std::back_inserter(samples2), [](Duration d) { return Duration2(d); }); - return { - std::move(samples2), - mean, - standard_deviation, - outliers, - outlier_variance, - }; - } - }; - } // namespace Benchmark -} // namespace Catch - -// end catch_sample_analysis.hpp -#include <algorithm> -#include <iterator> -#include <vector> - -namespace Catch { - namespace Benchmark { - namespace Detail { - template <typename Duration, typename Iterator> - SampleAnalysis<Duration> analyse(const IConfig &cfg, Environment<Duration>, Iterator first, Iterator last) { - if (!cfg.benchmarkNoAnalysis()) { - std::vector<double> samples; - samples.reserve(last - first); - std::transform(first, last, std::back_inserter(samples), [](Duration d) { return d.count(); }); - - auto analysis = Catch::Benchmark::Detail::analyse_samples(cfg.benchmarkConfidenceInterval(), cfg.benchmarkResamples(), samples.begin(), samples.end()); - auto outliers = Catch::Benchmark::Detail::classify_outliers(samples.begin(), samples.end()); - - auto wrap_estimate = [](Estimate<double> e) { - return Estimate<Duration> { - Duration(e.point), - Duration(e.lower_bound), - Duration(e.upper_bound), - e.confidence_interval, - }; - }; - std::vector<Duration> samples2; - samples2.reserve(samples.size()); - std::transform(samples.begin(), samples.end(), std::back_inserter(samples2), [](double d) { return Duration(d); }); - return { - std::move(samples2), - wrap_estimate(analysis.mean), - wrap_estimate(analysis.standard_deviation), - outliers, - analysis.outlier_variance, - }; - } else { - std::vector<Duration> samples; - samples.reserve(last - first); - - Duration mean = Duration(0); - int i = 0; - for (auto it = first; it < last; ++it, ++i) { - samples.push_back(Duration(*it)); - mean += Duration(*it); - } - mean /= i; - - return { - std::move(samples), - Estimate<Duration>{mean, mean, mean, 0.0}, - Estimate<Duration>{Duration(0), Duration(0), Duration(0), 0.0}, - OutlierClassification{}, - 0.0 - }; - } - } - } // namespace Detail - } // namespace Benchmark -} // namespace Catch - -// end catch_analyse.hpp -#include <algorithm> -#include <functional> -#include <string> -#include <vector> -#include <cmath> - -namespace Catch { - namespace Benchmark { - struct Benchmark { - Benchmark(std::string &&name) - : name(std::move(name)) {} - - template <class FUN> - Benchmark(std::string &&name, FUN &&func) - : fun(std::move(func)), name(std::move(name)) {} - - template <typename Clock> - ExecutionPlan<FloatDuration<Clock>> prepare(const IConfig &cfg, Environment<FloatDuration<Clock>> env) const { - auto min_time = env.clock_resolution.mean * Detail::minimum_ticks; - auto run_time = std::max(min_time, std::chrono::duration_cast<decltype(min_time)>(cfg.benchmarkWarmupTime())); - auto&& test = Detail::run_for_at_least<Clock>(std::chrono::duration_cast<ClockDuration<Clock>>(run_time), 1, fun); - int new_iters = static_cast<int>(std::ceil(min_time * test.iterations / test.elapsed)); - return { new_iters, test.elapsed / test.iterations * new_iters * cfg.benchmarkSamples(), fun, std::chrono::duration_cast<FloatDuration<Clock>>(cfg.benchmarkWarmupTime()), Detail::warmup_iterations }; - } - - template <typename Clock = default_clock> - void run() { - IConfigPtr cfg = getCurrentContext().getConfig(); - - auto env = Detail::measure_environment<Clock>(); - - getResultCapture().benchmarkPreparing(name); - CATCH_TRY{ - auto plan = user_code([&] { - return prepare<Clock>(*cfg, env); - }); - - BenchmarkInfo info { - name, - plan.estimated_duration.count(), - plan.iterations_per_sample, - cfg->benchmarkSamples(), - cfg->benchmarkResamples(), - env.clock_resolution.mean.count(), - env.clock_cost.mean.count() - }; - - getResultCapture().benchmarkStarting(info); - - auto samples = user_code([&] { - return plan.template run<Clock>(*cfg, env); - }); - - auto analysis = Detail::analyse(*cfg, env, samples.begin(), samples.end()); - BenchmarkStats<FloatDuration<Clock>> stats{ info, analysis.samples, analysis.mean, analysis.standard_deviation, analysis.outliers, analysis.outlier_variance }; - getResultCapture().benchmarkEnded(stats); - - } CATCH_CATCH_ALL{ - if (translateActiveException() != Detail::benchmarkErrorMsg) // benchmark errors have been reported, otherwise rethrow. - std::rethrow_exception(std::current_exception()); - } - } - - // sets lambda to be used in fun *and* executes benchmark! - template <typename Fun, - typename std::enable_if<!Detail::is_related<Fun, Benchmark>::value, int>::type = 0> - Benchmark & operator=(Fun func) { - fun = Detail::BenchmarkFunction(func); - run(); - return *this; - } - - explicit operator bool() { - return true; - } - - private: - Detail::BenchmarkFunction fun; - std::string name; - }; - } -} // namespace Catch - -#define INTERNAL_CATCH_GET_1_ARG(arg1, arg2, ...) arg1 -#define INTERNAL_CATCH_GET_2_ARG(arg1, arg2, ...) arg2 - -#define INTERNAL_CATCH_BENCHMARK(BenchmarkName, name, benchmarkIndex)\ - if( Catch::Benchmark::Benchmark BenchmarkName{name} ) \ - BenchmarkName = [&](int benchmarkIndex) - -#define INTERNAL_CATCH_BENCHMARK_ADVANCED(BenchmarkName, name)\ - if( Catch::Benchmark::Benchmark BenchmarkName{name} ) \ - BenchmarkName = [&] - -// end catch_benchmark.hpp -// start catch_constructor.hpp - -// Constructor and destructor helpers - - -#include <type_traits> - -namespace Catch { - namespace Benchmark { - namespace Detail { - template <typename T, bool Destruct> - struct ObjectStorage - { - using TStorage = typename std::aligned_storage<sizeof(T), std::alignment_of<T>::value>::type; - - ObjectStorage() : data() {} - - ObjectStorage(const ObjectStorage& other) - { - new(&data) T(other.stored_object()); - } - - ObjectStorage(ObjectStorage&& other) - { - new(&data) T(std::move(other.stored_object())); - } - - ~ObjectStorage() { destruct_on_exit<T>(); } - - template <typename... Args> - void construct(Args&&... args) - { - new (&data) T(std::forward<Args>(args)...); - } - - template <bool AllowManualDestruction = !Destruct> - typename std::enable_if<AllowManualDestruction>::type destruct() - { - stored_object().~T(); - } - - private: - // If this is a constructor benchmark, destruct the underlying object - template <typename U> - void destruct_on_exit(typename std::enable_if<Destruct, U>::type* = 0) { destruct<true>(); } - // Otherwise, don't - template <typename U> - void destruct_on_exit(typename std::enable_if<!Destruct, U>::type* = 0) { } - - T& stored_object() { - return *static_cast<T*>(static_cast<void*>(&data)); - } - - T const& stored_object() const { - return *static_cast<T*>(static_cast<void*>(&data)); - } - - TStorage data; - }; - } - - template <typename T> - using storage_for = Detail::ObjectStorage<T, true>; - - template <typename T> - using destructable_object = Detail::ObjectStorage<T, false>; - } -} - -// end catch_constructor.hpp -// end catch_benchmarking_all.hpp -#endif - -#endif // ! CATCH_CONFIG_IMPL_ONLY - -#ifdef CATCH_IMPL -// start catch_impl.hpp - -#ifdef __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wweak-vtables" -#endif - -// Keep these here for external reporters -// start catch_test_case_tracker.h - -#include <string> -#include <vector> -#include <memory> - -namespace Catch { -namespace TestCaseTracking { - - struct NameAndLocation { - std::string name; - SourceLineInfo location; - - NameAndLocation( std::string const& _name, SourceLineInfo const& _location ); - }; - - struct ITracker; - - using ITrackerPtr = std::shared_ptr<ITracker>; - - struct ITracker { - virtual ~ITracker(); - - // static queries - virtual NameAndLocation const& nameAndLocation() const = 0; - - // dynamic queries - virtual bool isComplete() const = 0; // Successfully completed or failed - virtual bool isSuccessfullyCompleted() const = 0; - virtual bool isOpen() const = 0; // Started but not complete - virtual bool hasChildren() const = 0; - - virtual ITracker& parent() = 0; - - // actions - virtual void close() = 0; // Successfully complete - virtual void fail() = 0; - virtual void markAsNeedingAnotherRun() = 0; - - virtual void addChild( ITrackerPtr const& child ) = 0; - virtual ITrackerPtr findChild( NameAndLocation const& nameAndLocation ) = 0; - virtual void openChild() = 0; - - // Debug/ checking - virtual bool isSectionTracker() const = 0; - virtual bool isGeneratorTracker() const = 0; - }; - - class TrackerContext { - - enum RunState { - NotStarted, - Executing, - CompletedCycle - }; - - ITrackerPtr m_rootTracker; - ITracker* m_currentTracker = nullptr; - RunState m_runState = NotStarted; - - public: - - ITracker& startRun(); - void endRun(); - - void startCycle(); - void completeCycle(); - - bool completedCycle() const; - ITracker& currentTracker(); - void setCurrentTracker( ITracker* tracker ); - }; - - class TrackerBase : public ITracker { - protected: - enum CycleState { - NotStarted, - Executing, - ExecutingChildren, - NeedsAnotherRun, - CompletedSuccessfully, - Failed - }; - - using Children = std::vector<ITrackerPtr>; - NameAndLocation m_nameAndLocation; - TrackerContext& m_ctx; - ITracker* m_parent; - Children m_children; - CycleState m_runState = NotStarted; - - public: - TrackerBase( NameAndLocation const& nameAndLocation, TrackerContext& ctx, ITracker* parent ); - - NameAndLocation const& nameAndLocation() const override; - bool isComplete() const override; - bool isSuccessfullyCompleted() const override; - bool isOpen() const override; - bool hasChildren() const override; - - void addChild( ITrackerPtr const& child ) override; - - ITrackerPtr findChild( NameAndLocation const& nameAndLocation ) override; - ITracker& parent() override; - - void openChild() override; - - bool isSectionTracker() const override; - bool isGeneratorTracker() const override; - - void open(); - - void close() override; - void fail() override; - void markAsNeedingAnotherRun() override; - - private: - void moveToParent(); - void moveToThis(); - }; - - class SectionTracker : public TrackerBase { - std::vector<std::string> m_filters; - std::string m_trimmed_name; - public: - SectionTracker( NameAndLocation const& nameAndLocation, TrackerContext& ctx, ITracker* parent ); - - bool isSectionTracker() const override; - - bool isComplete() const override; - - static SectionTracker& acquire( TrackerContext& ctx, NameAndLocation const& nameAndLocation ); - - void tryOpen(); - - void addInitialFilters( std::vector<std::string> const& filters ); - void addNextFilters( std::vector<std::string> const& filters ); - }; - -} // namespace TestCaseTracking - -using TestCaseTracking::ITracker; -using TestCaseTracking::TrackerContext; -using TestCaseTracking::SectionTracker; - -} // namespace Catch - -// end catch_test_case_tracker.h - -// start catch_leak_detector.h - -namespace Catch { - - struct LeakDetector { - LeakDetector(); - ~LeakDetector(); - }; - -} -// end catch_leak_detector.h -// Cpp files will be included in the single-header file here -// start catch_stats.cpp - -// Statistical analysis tools - -#if defined(CATCH_CONFIG_ENABLE_BENCHMARKING) - -#include <cassert> -#include <random> - -#if defined(CATCH_CONFIG_USE_ASYNC) -#include <future> -#endif - -namespace { - double erf_inv(double x) { - // Code accompanying the article "Approximating the erfinv function" in GPU Computing Gems, Volume 2 - double w, p; - - w = -log((1.0 - x) * (1.0 + x)); - - if (w < 6.250000) { - w = w - 3.125000; - p = -3.6444120640178196996e-21; - p = -1.685059138182016589e-19 + p * w; - p = 1.2858480715256400167e-18 + p * w; - p = 1.115787767802518096e-17 + p * w; - p = -1.333171662854620906e-16 + p * w; - p = 2.0972767875968561637e-17 + p * w; - p = 6.6376381343583238325e-15 + p * w; - p = -4.0545662729752068639e-14 + p * w; - p = -8.1519341976054721522e-14 + p * w; - p = 2.6335093153082322977e-12 + p * w; - p = -1.2975133253453532498e-11 + p * w; - p = -5.4154120542946279317e-11 + p * w; - p = 1.051212273321532285e-09 + p * w; - p = -4.1126339803469836976e-09 + p * w; - p = -2.9070369957882005086e-08 + p * w; - p = 4.2347877827932403518e-07 + p * w; - p = -1.3654692000834678645e-06 + p * w; - p = -1.3882523362786468719e-05 + p * w; - p = 0.0001867342080340571352 + p * w; - p = -0.00074070253416626697512 + p * w; - p = -0.0060336708714301490533 + p * w; - p = 0.24015818242558961693 + p * w; - p = 1.6536545626831027356 + p * w; - } else if (w < 16.000000) { - w = sqrt(w) - 3.250000; - p = 2.2137376921775787049e-09; - p = 9.0756561938885390979e-08 + p * w; - p = -2.7517406297064545428e-07 + p * w; - p = 1.8239629214389227755e-08 + p * w; - p = 1.5027403968909827627e-06 + p * w; - p = -4.013867526981545969e-06 + p * w; - p = 2.9234449089955446044e-06 + p * w; - p = 1.2475304481671778723e-05 + p * w; - p = -4.7318229009055733981e-05 + p * w; - p = 6.8284851459573175448e-05 + p * w; - p = 2.4031110387097893999e-05 + p * w; - p = -0.0003550375203628474796 + p * w; - p = 0.00095328937973738049703 + p * w; - p = -0.0016882755560235047313 + p * w; - p = 0.0024914420961078508066 + p * w; - p = -0.0037512085075692412107 + p * w; - p = 0.005370914553590063617 + p * w; - p = 1.0052589676941592334 + p * w; - p = 3.0838856104922207635 + p * w; - } else { - w = sqrt(w) - 5.000000; - p = -2.7109920616438573243e-11; - p = -2.5556418169965252055e-10 + p * w; - p = 1.5076572693500548083e-09 + p * w; - p = -3.7894654401267369937e-09 + p * w; - p = 7.6157012080783393804e-09 + p * w; - p = -1.4960026627149240478e-08 + p * w; - p = 2.9147953450901080826e-08 + p * w; - p = -6.7711997758452339498e-08 + p * w; - p = 2.2900482228026654717e-07 + p * w; - p = -9.9298272942317002539e-07 + p * w; - p = 4.5260625972231537039e-06 + p * w; - p = -1.9681778105531670567e-05 + p * w; - p = 7.5995277030017761139e-05 + p * w; - p = -0.00021503011930044477347 + p * w; - p = -0.00013871931833623122026 + p * w; - p = 1.0103004648645343977 + p * w; - p = 4.8499064014085844221 + p * w; - } - return p * x; - } - - double standard_deviation(std::vector<double>::iterator first, std::vector<double>::iterator last) { - auto m = Catch::Benchmark::Detail::mean(first, last); - double variance = std::accumulate(first, last, 0., [m](double a, double b) { - double diff = b - m; - return a + diff * diff; - }) / (last - first); - return std::sqrt(variance); - } - -} - -namespace Catch { - namespace Benchmark { - namespace Detail { - - double weighted_average_quantile(int k, int q, std::vector<double>::iterator first, std::vector<double>::iterator last) { - auto count = last - first; - double idx = (count - 1) * k / static_cast<double>(q); - int j = static_cast<int>(idx); - double g = idx - j; - std::nth_element(first, first + j, last); - auto xj = first[j]; - if (g == 0) return xj; - - auto xj1 = *std::min_element(first + (j + 1), last); - return xj + g * (xj1 - xj); - } - - double erfc_inv(double x) { - return erf_inv(1.0 - x); - } - - double normal_quantile(double p) { - static const double ROOT_TWO = std::sqrt(2.0); - - double result = 0.0; - assert(p >= 0 && p <= 1); - if (p < 0 || p > 1) { - return result; - } - - result = -erfc_inv(2.0 * p); - // result *= normal distribution standard deviation (1.0) * sqrt(2) - result *= /*sd * */ ROOT_TWO; - // result += normal disttribution mean (0) - return result; - } - - double outlier_variance(Estimate<double> mean, Estimate<double> stddev, int n) { - double sb = stddev.point; - double mn = mean.point / n; - double mg_min = mn / 2.; - double sg = std::min(mg_min / 4., sb / std::sqrt(n)); - double sg2 = sg * sg; - double sb2 = sb * sb; - - auto c_max = [n, mn, sb2, sg2](double x) -> double { - double k = mn - x; - double d = k * k; - double nd = n * d; - double k0 = -n * nd; - double k1 = sb2 - n * sg2 + nd; - double det = k1 * k1 - 4 * sg2 * k0; - return (int)(-2. * k0 / (k1 + std::sqrt(det))); - }; - - auto var_out = [n, sb2, sg2](double c) { - double nc = n - c; - return (nc / n) * (sb2 - nc * sg2); - }; - - return std::min(var_out(1), var_out(std::min(c_max(0.), c_max(mg_min)))) / sb2; - } - - bootstrap_analysis analyse_samples(double confidence_level, int n_resamples, std::vector<double>::iterator first, std::vector<double>::iterator last) { - CATCH_INTERNAL_START_WARNINGS_SUPPRESSION - CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS - static std::random_device entropy; - CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION - - auto n = static_cast<int>(last - first); // seriously, one can't use integral types without hell in C++ - - auto mean = &Detail::mean<std::vector<double>::iterator>; - auto stddev = &standard_deviation; - -#if defined(CATCH_CONFIG_USE_ASYNC) - auto Estimate = [=](double(*f)(std::vector<double>::iterator, std::vector<double>::iterator)) { - auto seed = entropy(); - return std::async(std::launch::async, [=] { - std::mt19937 rng(seed); - auto resampled = resample(rng, n_resamples, first, last, f); - return bootstrap(confidence_level, first, last, resampled, f); - }); - }; - - auto mean_future = Estimate(mean); - auto stddev_future = Estimate(stddev); - - auto mean_estimate = mean_future.get(); - auto stddev_estimate = stddev_future.get(); -#else - auto Estimate = [=](double(*f)(std::vector<double>::iterator, std::vector<double>::iterator)) { - auto seed = entropy(); - std::mt19937 rng(seed); - auto resampled = resample(rng, n_resamples, first, last, f); - return bootstrap(confidence_level, first, last, resampled, f); - }; - - auto mean_estimate = Estimate(mean); - auto stddev_estimate = Estimate(stddev); -#endif // CATCH_USE_ASYNC - - double outlier_variance = Detail::outlier_variance(mean_estimate, stddev_estimate, n); - - return { mean_estimate, stddev_estimate, outlier_variance }; - } - } // namespace Detail - } // namespace Benchmark -} // namespace Catch - -#endif // CATCH_CONFIG_ENABLE_BENCHMARKING -// end catch_stats.cpp -// start catch_approx.cpp - -#include <cmath> -#include <limits> - -namespace { - -// Performs equivalent check of std::fabs(lhs - rhs) <= margin -// But without the subtraction to allow for INFINITY in comparison -bool marginComparison(double lhs, double rhs, double margin) { - return (lhs + margin >= rhs) && (rhs + margin >= lhs); -} - -} - -namespace Catch { -namespace Detail { - - Approx::Approx ( double value ) - : m_epsilon( std::numeric_limits<float>::epsilon()*100 ), - m_margin( 0.0 ), - m_scale( 0.0 ), - m_value( value ) - {} - - Approx Approx::custom() { - return Approx( 0 ); - } - - Approx Approx::operator-() const { - auto temp(*this); - temp.m_value = -temp.m_value; - return temp; - } - - std::string Approx::toString() const { - ReusableStringStream rss; - rss << "Approx( " << ::Catch::Detail::stringify( m_value ) << " )"; - return rss.str(); - } - - bool Approx::equalityComparisonImpl(const double other) const { - // First try with fixed margin, then compute margin based on epsilon, scale and Approx's value - // Thanks to Richard Harris for his help refining the scaled margin value - return marginComparison(m_value, other, m_margin) - || marginComparison(m_value, other, m_epsilon * (m_scale + std::fabs(std::isinf(m_value)? 0 : m_value))); - } - - void Approx::setMargin(double newMargin) { - CATCH_ENFORCE(newMargin >= 0, - "Invalid Approx::margin: " << newMargin << '.' - << " Approx::Margin has to be non-negative."); - m_margin = newMargin; - } - - void Approx::setEpsilon(double newEpsilon) { - CATCH_ENFORCE(newEpsilon >= 0 && newEpsilon <= 1.0, - "Invalid Approx::epsilon: " << newEpsilon << '.' - << " Approx::epsilon has to be in [0, 1]"); - m_epsilon = newEpsilon; - } - -} // end namespace Detail - -namespace literals { - Detail::Approx operator "" _a(long double val) { - return Detail::Approx(val); - } - Detail::Approx operator "" _a(unsigned long long val) { - return Detail::Approx(val); - } -} // end namespace literals - -std::string StringMaker<Catch::Detail::Approx>::convert(Catch::Detail::Approx const& value) { - return value.toString(); -} - -} // end namespace Catch -// end catch_approx.cpp -// start catch_assertionhandler.cpp - -// start catch_debugger.h - -namespace Catch { - bool isDebuggerActive(); -} - -#ifdef CATCH_PLATFORM_MAC - - #define CATCH_TRAP() __asm__("int $3\n" : : ) /* NOLINT */ - -#elif defined(CATCH_PLATFORM_IPHONE) - - // use inline assembler - #if defined(__i386__) || defined(__x86_64__) - #define CATCH_TRAP() __asm__("int $3") - #elif defined(__aarch64__) - #define CATCH_TRAP() __asm__(".inst 0xd4200000") - #elif defined(__arm__) && !defined(__thumb__) - #define CATCH_TRAP() __asm__(".inst 0xe7f001f0") - #elif defined(__arm__) && defined(__thumb__) - #define CATCH_TRAP() __asm__(".inst 0xde01") - #endif - -#elif defined(CATCH_PLATFORM_LINUX) - // If we can use inline assembler, do it because this allows us to break - // directly at the location of the failing check instead of breaking inside - // raise() called from it, i.e. one stack frame below. - #if defined(__GNUC__) && (defined(__i386) || defined(__x86_64)) - #define CATCH_TRAP() asm volatile ("int $3") /* NOLINT */ - #else // Fall back to the generic way. - #include <signal.h> - - #define CATCH_TRAP() raise(SIGTRAP) - #endif -#elif defined(_MSC_VER) - #define CATCH_TRAP() __debugbreak() -#elif defined(__MINGW32__) - extern "C" __declspec(dllimport) void __stdcall DebugBreak(); - #define CATCH_TRAP() DebugBreak() -#endif - -#ifndef CATCH_BREAK_INTO_DEBUGGER - #ifdef CATCH_TRAP - #define CATCH_BREAK_INTO_DEBUGGER() []{ if( Catch::isDebuggerActive() ) { CATCH_TRAP(); } }() - #else - #define CATCH_BREAK_INTO_DEBUGGER() []{}() - #endif -#endif - -// end catch_debugger.h -// start catch_run_context.h - -// start catch_fatal_condition.h - -// start catch_windows_h_proxy.h - - -#if defined(CATCH_PLATFORM_WINDOWS) - -#if !defined(NOMINMAX) && !defined(CATCH_CONFIG_NO_NOMINMAX) -# define CATCH_DEFINED_NOMINMAX -# define NOMINMAX -#endif -#if !defined(WIN32_LEAN_AND_MEAN) && !defined(CATCH_CONFIG_NO_WIN32_LEAN_AND_MEAN) -# define CATCH_DEFINED_WIN32_LEAN_AND_MEAN -# define WIN32_LEAN_AND_MEAN -#endif - -#ifdef __AFXDLL -#include <AfxWin.h> -#else -#include <windows.h> -#endif - -#ifdef CATCH_DEFINED_NOMINMAX -# undef NOMINMAX -#endif -#ifdef CATCH_DEFINED_WIN32_LEAN_AND_MEAN -# undef WIN32_LEAN_AND_MEAN -#endif - -#endif // defined(CATCH_PLATFORM_WINDOWS) - -// end catch_windows_h_proxy.h -#if defined( CATCH_CONFIG_WINDOWS_SEH ) - -namespace Catch { - - struct FatalConditionHandler { - - static LONG CALLBACK handleVectoredException(PEXCEPTION_POINTERS ExceptionInfo); - FatalConditionHandler(); - static void reset(); - ~FatalConditionHandler(); - - private: - static bool isSet; - static ULONG guaranteeSize; - static PVOID exceptionHandlerHandle; - }; - -} // namespace Catch - -#elif defined ( CATCH_CONFIG_POSIX_SIGNALS ) - -#include <signal.h> - -namespace Catch { - - struct FatalConditionHandler { - - static bool isSet; - static struct sigaction oldSigActions[]; - static stack_t oldSigStack; - static char altStackMem[]; - - static void handleSignal( int sig ); - - FatalConditionHandler(); - ~FatalConditionHandler(); - static void reset(); - }; - -} // namespace Catch - -#else - -namespace Catch { - struct FatalConditionHandler { - void reset(); - }; -} - -#endif - -// end catch_fatal_condition.h -#include <string> - -namespace Catch { - - struct IMutableContext; - - /////////////////////////////////////////////////////////////////////////// - - class RunContext : public IResultCapture, public IRunner { - - public: - RunContext( RunContext const& ) = delete; - RunContext& operator =( RunContext const& ) = delete; - - explicit RunContext( IConfigPtr const& _config, IStreamingReporterPtr&& reporter ); - - ~RunContext() override; - - void testGroupStarting( std::string const& testSpec, std::size_t groupIndex, std::size_t groupsCount ); - void testGroupEnded( std::string const& testSpec, Totals const& totals, std::size_t groupIndex, std::size_t groupsCount ); - - Totals runTest(TestCase const& testCase); - - IConfigPtr config() const; - IStreamingReporter& reporter() const; - - public: // IResultCapture - - // Assertion handlers - void handleExpr - ( AssertionInfo const& info, - ITransientExpression const& expr, - AssertionReaction& reaction ) override; - void handleMessage - ( AssertionInfo const& info, - ResultWas::OfType resultType, - StringRef const& message, - AssertionReaction& reaction ) override; - void handleUnexpectedExceptionNotThrown - ( AssertionInfo const& info, - AssertionReaction& reaction ) override; - void handleUnexpectedInflightException - ( AssertionInfo const& info, - std::string const& message, - AssertionReaction& reaction ) override; - void handleIncomplete - ( AssertionInfo const& info ) override; - void handleNonExpr - ( AssertionInfo const &info, - ResultWas::OfType resultType, - AssertionReaction &reaction ) override; - - bool sectionStarted( SectionInfo const& sectionInfo, Counts& assertions ) override; - - void sectionEnded( SectionEndInfo const& endInfo ) override; - void sectionEndedEarly( SectionEndInfo const& endInfo ) override; - - auto acquireGeneratorTracker( SourceLineInfo const& lineInfo ) -> IGeneratorTracker& override; - -#if defined(CATCH_CONFIG_ENABLE_BENCHMARKING) - void benchmarkPreparing( std::string const& name ) override; - void benchmarkStarting( BenchmarkInfo const& info ) override; - void benchmarkEnded( BenchmarkStats<> const& stats ) override; - void benchmarkFailed( std::string const& error ) override; -#endif // CATCH_CONFIG_ENABLE_BENCHMARKING - - void pushScopedMessage( MessageInfo const& message ) override; - void popScopedMessage( MessageInfo const& message ) override; - - void emplaceUnscopedMessage( MessageBuilder const& builder ) override; - - std::string getCurrentTestName() const override; - - const AssertionResult* getLastResult() const override; - - void exceptionEarlyReported() override; - - void handleFatalErrorCondition( StringRef message ) override; - - bool lastAssertionPassed() override; - - void assertionPassed() override; - - public: - // !TBD We need to do this another way! - bool aborting() const final; - - private: - - void runCurrentTest( std::string& redirectedCout, std::string& redirectedCerr ); - void invokeActiveTestCase(); - - void resetAssertionInfo(); - bool testForMissingAssertions( Counts& assertions ); - - void assertionEnded( AssertionResult const& result ); - void reportExpr - ( AssertionInfo const &info, - ResultWas::OfType resultType, - ITransientExpression const *expr, - bool negated ); - - void populateReaction( AssertionReaction& reaction ); - - private: - - void handleUnfinishedSections(); - - TestRunInfo m_runInfo; - IMutableContext& m_context; - TestCase const* m_activeTestCase = nullptr; - ITracker* m_testCaseTracker = nullptr; - Option<AssertionResult> m_lastResult; - - IConfigPtr m_config; - Totals m_totals; - IStreamingReporterPtr m_reporter; - std::vector<MessageInfo> m_messages; - std::vector<ScopedMessage> m_messageScopes; /* Keeps owners of so-called unscoped messages. */ - AssertionInfo m_lastAssertionInfo; - std::vector<SectionEndInfo> m_unfinishedSections; - std::vector<ITracker*> m_activeSections; - TrackerContext m_trackerContext; - bool m_lastAssertionPassed = false; - bool m_shouldReportUnexpected = true; - bool m_includeSuccessfulResults; - }; - - void seedRng(IConfig const& config); - unsigned int rngSeed(); -} // end namespace Catch - -// end catch_run_context.h -namespace Catch { - - namespace { - auto operator <<( std::ostream& os, ITransientExpression const& expr ) -> std::ostream& { - expr.streamReconstructedExpression( os ); - return os; - } - } - - LazyExpression::LazyExpression( bool isNegated ) - : m_isNegated( isNegated ) - {} - - LazyExpression::LazyExpression( LazyExpression const& other ) : m_isNegated( other.m_isNegated ) {} - - LazyExpression::operator bool() const { - return m_transientExpression != nullptr; - } - - auto operator << ( std::ostream& os, LazyExpression const& lazyExpr ) -> std::ostream& { - if( lazyExpr.m_isNegated ) - os << "!"; - - if( lazyExpr ) { - if( lazyExpr.m_isNegated && lazyExpr.m_transientExpression->isBinaryExpression() ) - os << "(" << *lazyExpr.m_transientExpression << ")"; - else - os << *lazyExpr.m_transientExpression; - } - else { - os << "{** error - unchecked empty expression requested **}"; - } - return os; - } - - AssertionHandler::AssertionHandler - ( StringRef const& macroName, - SourceLineInfo const& lineInfo, - StringRef capturedExpression, - ResultDisposition::Flags resultDisposition ) - : m_assertionInfo{ macroName, lineInfo, capturedExpression, resultDisposition }, - m_resultCapture( getResultCapture() ) - {} - - void AssertionHandler::handleExpr( ITransientExpression const& expr ) { - m_resultCapture.handleExpr( m_assertionInfo, expr, m_reaction ); - } - void AssertionHandler::handleMessage(ResultWas::OfType resultType, StringRef const& message) { - m_resultCapture.handleMessage( m_assertionInfo, resultType, message, m_reaction ); - } - - auto AssertionHandler::allowThrows() const -> bool { - return getCurrentContext().getConfig()->allowThrows(); - } - - void AssertionHandler::complete() { - setCompleted(); - if( m_reaction.shouldDebugBreak ) { - - // If you find your debugger stopping you here then go one level up on the - // call-stack for the code that caused it (typically a failed assertion) - - // (To go back to the test and change execution, jump over the throw, next) - CATCH_BREAK_INTO_DEBUGGER(); - } - if (m_reaction.shouldThrow) { -#if !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS) - throw Catch::TestFailureException(); -#else - CATCH_ERROR( "Test failure requires aborting test!" ); -#endif - } - } - void AssertionHandler::setCompleted() { - m_completed = true; - } - - void AssertionHandler::handleUnexpectedInflightException() { - m_resultCapture.handleUnexpectedInflightException( m_assertionInfo, Catch::translateActiveException(), m_reaction ); - } - - void AssertionHandler::handleExceptionThrownAsExpected() { - m_resultCapture.handleNonExpr(m_assertionInfo, ResultWas::Ok, m_reaction); - } - void AssertionHandler::handleExceptionNotThrownAsExpected() { - m_resultCapture.handleNonExpr(m_assertionInfo, ResultWas::Ok, m_reaction); - } - - void AssertionHandler::handleUnexpectedExceptionNotThrown() { - m_resultCapture.handleUnexpectedExceptionNotThrown( m_assertionInfo, m_reaction ); - } - - void AssertionHandler::handleThrowingCallSkipped() { - m_resultCapture.handleNonExpr(m_assertionInfo, ResultWas::Ok, m_reaction); - } - - // This is the overload that takes a string and infers the Equals matcher from it - // The more general overload, that takes any string matcher, is in catch_capture_matchers.cpp - void handleExceptionMatchExpr( AssertionHandler& handler, std::string const& str, StringRef const& matcherString ) { - handleExceptionMatchExpr( handler, Matchers::Equals( str ), matcherString ); - } - -} // namespace Catch -// end catch_assertionhandler.cpp -// start catch_assertionresult.cpp - -namespace Catch { - AssertionResultData::AssertionResultData(ResultWas::OfType _resultType, LazyExpression const & _lazyExpression): - lazyExpression(_lazyExpression), - resultType(_resultType) {} - - std::string AssertionResultData::reconstructExpression() const { - - if( reconstructedExpression.empty() ) { - if( lazyExpression ) { - ReusableStringStream rss; - rss << lazyExpression; - reconstructedExpression = rss.str(); - } - } - return reconstructedExpression; - } - - AssertionResult::AssertionResult( AssertionInfo const& info, AssertionResultData const& data ) - : m_info( info ), - m_resultData( data ) - {} - - // Result was a success - bool AssertionResult::succeeded() const { - return Catch::isOk( m_resultData.resultType ); - } - - // Result was a success, or failure is suppressed - bool AssertionResult::isOk() const { - return Catch::isOk( m_resultData.resultType ) || shouldSuppressFailure( m_info.resultDisposition ); - } - - ResultWas::OfType AssertionResult::getResultType() const { - return m_resultData.resultType; - } - - bool AssertionResult::hasExpression() const { - return !m_info.capturedExpression.empty(); - } - - bool AssertionResult::hasMessage() const { - return !m_resultData.message.empty(); - } - - std::string AssertionResult::getExpression() const { - // Possibly overallocating by 3 characters should be basically free - std::string expr; expr.reserve(m_info.capturedExpression.size() + 3); - if (isFalseTest(m_info.resultDisposition)) { - expr += "!("; - } - expr += m_info.capturedExpression; - if (isFalseTest(m_info.resultDisposition)) { - expr += ')'; - } - return expr; - } - - std::string AssertionResult::getExpressionInMacro() const { - std::string expr; - if( m_info.macroName.empty() ) - expr = static_cast<std::string>(m_info.capturedExpression); - else { - expr.reserve( m_info.macroName.size() + m_info.capturedExpression.size() + 4 ); - expr += m_info.macroName; - expr += "( "; - expr += m_info.capturedExpression; - expr += " )"; - } - return expr; - } - - bool AssertionResult::hasExpandedExpression() const { - return hasExpression() && getExpandedExpression() != getExpression(); - } - - std::string AssertionResult::getExpandedExpression() const { - std::string expr = m_resultData.reconstructExpression(); - return expr.empty() - ? getExpression() - : expr; - } - - std::string AssertionResult::getMessage() const { - return m_resultData.message; - } - SourceLineInfo AssertionResult::getSourceInfo() const { - return m_info.lineInfo; - } - - StringRef AssertionResult::getTestMacroName() const { - return m_info.macroName; - } - -} // end namespace Catch -// end catch_assertionresult.cpp -// start catch_capture_matchers.cpp - -namespace Catch { - - using StringMatcher = Matchers::Impl::MatcherBase<std::string>; - - // This is the general overload that takes a any string matcher - // There is another overload, in catch_assertionhandler.h/.cpp, that only takes a string and infers - // the Equals matcher (so the header does not mention matchers) - void handleExceptionMatchExpr( AssertionHandler& handler, StringMatcher const& matcher, StringRef const& matcherString ) { - std::string exceptionMessage = Catch::translateActiveException(); - MatchExpr<std::string, StringMatcher const&> expr( exceptionMessage, matcher, matcherString ); - handler.handleExpr( expr ); - } - -} // namespace Catch -// end catch_capture_matchers.cpp -// start catch_commandline.cpp - -// start catch_commandline.h - -// start catch_clara.h - -// Use Catch's value for console width (store Clara's off to the side, if present) -#ifdef CLARA_CONFIG_CONSOLE_WIDTH -#define CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH -#undef CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH -#endif -#define CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH CATCH_CONFIG_CONSOLE_WIDTH-1 - -#ifdef __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wweak-vtables" -#pragma clang diagnostic ignored "-Wexit-time-destructors" -#pragma clang diagnostic ignored "-Wshadow" -#endif - -// start clara.hpp -// Copyright 2017 Two Blue Cubes Ltd. All rights reserved. -// -// Distributed under the Boost Software License, Version 1.0. (See accompanying -// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -// -// See https://github.com/philsquared/Clara for more details - -// Clara v1.1.5 - - -#ifndef CATCH_CLARA_CONFIG_CONSOLE_WIDTH -#define CATCH_CLARA_CONFIG_CONSOLE_WIDTH 80 -#endif - -#ifndef CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH -#define CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH CATCH_CLARA_CONFIG_CONSOLE_WIDTH -#endif - -#ifndef CLARA_CONFIG_OPTIONAL_TYPE -#ifdef __has_include -#if __has_include(<optional>) && __cplusplus >= 201703L -#include <optional> -#define CLARA_CONFIG_OPTIONAL_TYPE std::optional -#endif -#endif -#endif - -// ----------- #included from clara_textflow.hpp ----------- - -// TextFlowCpp -// -// A single-header library for wrapping and laying out basic text, by Phil Nash -// -// Distributed under the Boost Software License, Version 1.0. (See accompanying -// file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -// -// This project is hosted at https://github.com/philsquared/textflowcpp - - -#include <cassert> -#include <ostream> -#include <sstream> -#include <vector> - -#ifndef CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH -#define CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH 80 -#endif - -namespace Catch { -namespace clara { -namespace TextFlow { - -inline auto isWhitespace(char c) -> bool { - static std::string chars = " \t\n\r"; - return chars.find(c) != std::string::npos; -} -inline auto isBreakableBefore(char c) -> bool { - static std::string chars = "[({<|"; - return chars.find(c) != std::string::npos; -} -inline auto isBreakableAfter(char c) -> bool { - static std::string chars = "])}>.,:;*+-=&/\\"; - return chars.find(c) != std::string::npos; -} - -class Columns; - -class Column { - std::vector<std::string> m_strings; - size_t m_width = CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH; - size_t m_indent = 0; - size_t m_initialIndent = std::string::npos; - -public: - class iterator { - friend Column; - - Column const& m_column; - size_t m_stringIndex = 0; - size_t m_pos = 0; - - size_t m_len = 0; - size_t m_end = 0; - bool m_suffix = false; - - iterator(Column const& column, size_t stringIndex) - : m_column(column), - m_stringIndex(stringIndex) {} - - auto line() const -> std::string const& { return m_column.m_strings[m_stringIndex]; } - - auto isBoundary(size_t at) const -> bool { - assert(at > 0); - assert(at <= line().size()); - - return at == line().size() || - (isWhitespace(line()[at]) && !isWhitespace(line()[at - 1])) || - isBreakableBefore(line()[at]) || - isBreakableAfter(line()[at - 1]); - } - - void calcLength() { - assert(m_stringIndex < m_column.m_strings.size()); - - m_suffix = false; - auto width = m_column.m_width - indent(); - m_end = m_pos; - if (line()[m_pos] == '\n') { - ++m_end; - } - while (m_end < line().size() && line()[m_end] != '\n') - ++m_end; - - if (m_end < m_pos + width) { - m_len = m_end - m_pos; - } else { - size_t len = width; - while (len > 0 && !isBoundary(m_pos + len)) - --len; - while (len > 0 && isWhitespace(line()[m_pos + len - 1])) - --len; - - if (len > 0) { - m_len = len; - } else { - m_suffix = true; - m_len = width - 1; - } - } - } - - auto indent() const -> size_t { - auto initial = m_pos == 0 && m_stringIndex == 0 ? m_column.m_initialIndent : std::string::npos; - return initial == std::string::npos ? m_column.m_indent : initial; - } - - auto addIndentAndSuffix(std::string const &plain) const -> std::string { - return std::string(indent(), ' ') + (m_suffix ? plain + "-" : plain); - } - - public: - using difference_type = std::ptrdiff_t; - using value_type = std::string; - using pointer = value_type * ; - using reference = value_type & ; - using iterator_category = std::forward_iterator_tag; - - explicit iterator(Column const& column) : m_column(column) { - assert(m_column.m_width > m_column.m_indent); - assert(m_column.m_initialIndent == std::string::npos || m_column.m_width > m_column.m_initialIndent); - calcLength(); - if (m_len == 0) - m_stringIndex++; // Empty string - } - - auto operator *() const -> std::string { - assert(m_stringIndex < m_column.m_strings.size()); - assert(m_pos <= m_end); - return addIndentAndSuffix(line().substr(m_pos, m_len)); - } - - auto operator ++() -> iterator& { - m_pos += m_len; - if (m_pos < line().size() && line()[m_pos] == '\n') - m_pos += 1; - else - while (m_pos < line().size() && isWhitespace(line()[m_pos])) - ++m_pos; - - if (m_pos == line().size()) { - m_pos = 0; - ++m_stringIndex; - } - if (m_stringIndex < m_column.m_strings.size()) - calcLength(); - return *this; - } - auto operator ++(int) -> iterator { - iterator prev(*this); - operator++(); - return prev; - } - - auto operator ==(iterator const& other) const -> bool { - return - m_pos == other.m_pos && - m_stringIndex == other.m_stringIndex && - &m_column == &other.m_column; - } - auto operator !=(iterator const& other) const -> bool { - return !operator==(other); - } - }; - using const_iterator = iterator; - - explicit Column(std::string const& text) { m_strings.push_back(text); } - - auto width(size_t newWidth) -> Column& { - assert(newWidth > 0); - m_width = newWidth; - return *this; - } - auto indent(size_t newIndent) -> Column& { - m_indent = newIndent; - return *this; - } - auto initialIndent(size_t newIndent) -> Column& { - m_initialIndent = newIndent; - return *this; - } - - auto width() const -> size_t { return m_width; } - auto begin() const -> iterator { return iterator(*this); } - auto end() const -> iterator { return { *this, m_strings.size() }; } - - inline friend std::ostream& operator << (std::ostream& os, Column const& col) { - bool first = true; - for (auto line : col) { - if (first) - first = false; - else - os << "\n"; - os << line; - } - return os; - } - - auto operator + (Column const& other)->Columns; - - auto toString() const -> std::string { - std::ostringstream oss; - oss << *this; - return oss.str(); - } -}; - -class Spacer : public Column { - -public: - explicit Spacer(size_t spaceWidth) : Column("") { - width(spaceWidth); - } -}; - -class Columns { - std::vector<Column> m_columns; - -public: - - class iterator { - friend Columns; - struct EndTag {}; - - std::vector<Column> const& m_columns; - std::vector<Column::iterator> m_iterators; - size_t m_activeIterators; - - iterator(Columns const& columns, EndTag) - : m_columns(columns.m_columns), - m_activeIterators(0) { - m_iterators.reserve(m_columns.size()); - - for (auto const& col : m_columns) - m_iterators.push_back(col.end()); - } - - public: - using difference_type = std::ptrdiff_t; - using value_type = std::string; - using pointer = value_type * ; - using reference = value_type & ; - using iterator_category = std::forward_iterator_tag; - - explicit iterator(Columns const& columns) - : m_columns(columns.m_columns), - m_activeIterators(m_columns.size()) { - m_iterators.reserve(m_columns.size()); - - for (auto const& col : m_columns) - m_iterators.push_back(col.begin()); - } - - auto operator ==(iterator const& other) const -> bool { - return m_iterators == other.m_iterators; - } - auto operator !=(iterator const& other) const -> bool { - return m_iterators != other.m_iterators; - } - auto operator *() const -> std::string { - std::string row, padding; - - for (size_t i = 0; i < m_columns.size(); ++i) { - auto width = m_columns[i].width(); - if (m_iterators[i] != m_columns[i].end()) { - std::string col = *m_iterators[i]; - row += padding + col; - if (col.size() < width) - padding = std::string(width - col.size(), ' '); - else - padding = ""; - } else { - padding += std::string(width, ' '); - } - } - return row; - } - auto operator ++() -> iterator& { - for (size_t i = 0; i < m_columns.size(); ++i) { - if (m_iterators[i] != m_columns[i].end()) - ++m_iterators[i]; - } - return *this; - } - auto operator ++(int) -> iterator { - iterator prev(*this); - operator++(); - return prev; - } - }; - using const_iterator = iterator; - - auto begin() const -> iterator { return iterator(*this); } - auto end() const -> iterator { return { *this, iterator::EndTag() }; } - - auto operator += (Column const& col) -> Columns& { - m_columns.push_back(col); - return *this; - } - auto operator + (Column const& col) -> Columns { - Columns combined = *this; - combined += col; - return combined; - } - - inline friend std::ostream& operator << (std::ostream& os, Columns const& cols) { - - bool first = true; - for (auto line : cols) { - if (first) - first = false; - else - os << "\n"; - os << line; - } - return os; - } - - auto toString() const -> std::string { - std::ostringstream oss; - oss << *this; - return oss.str(); - } -}; - -inline auto Column::operator + (Column const& other) -> Columns { - Columns cols; - cols += *this; - cols += other; - return cols; -} -} - -} -} - -// ----------- end of #include from clara_textflow.hpp ----------- -// ........... back in clara.hpp - -#include <cctype> -#include <string> -#include <memory> -#include <set> -#include <algorithm> - -#if !defined(CATCH_PLATFORM_WINDOWS) && ( defined(WIN32) || defined(__WIN32__) || defined(_WIN32) || defined(_MSC_VER) ) -#define CATCH_PLATFORM_WINDOWS -#endif - -namespace Catch { namespace clara { -namespace detail { - - // Traits for extracting arg and return type of lambdas (for single argument lambdas) - template<typename L> - struct UnaryLambdaTraits : UnaryLambdaTraits<decltype( &L::operator() )> {}; - - template<typename ClassT, typename ReturnT, typename... Args> - struct UnaryLambdaTraits<ReturnT( ClassT::* )( Args... ) const> { - static const bool isValid = false; - }; - - template<typename ClassT, typename ReturnT, typename ArgT> - struct UnaryLambdaTraits<ReturnT( ClassT::* )( ArgT ) const> { - static const bool isValid = true; - using ArgType = typename std::remove_const<typename std::remove_reference<ArgT>::type>::type; - using ReturnType = ReturnT; - }; - - class TokenStream; - - // Transport for raw args (copied from main args, or supplied via init list for testing) - class Args { - friend TokenStream; - std::string m_exeName; - std::vector<std::string> m_args; - - public: - Args( int argc, char const* const* argv ) - : m_exeName(argv[0]), - m_args(argv + 1, argv + argc) {} - - Args( std::initializer_list<std::string> args ) - : m_exeName( *args.begin() ), - m_args( args.begin()+1, args.end() ) - {} - - auto exeName() const -> std::string { - return m_exeName; - } - }; - - // Wraps a token coming from a token stream. These may not directly correspond to strings as a single string - // may encode an option + its argument if the : or = form is used - enum class TokenType { - Option, Argument - }; - struct Token { - TokenType type; - std::string token; - }; - - inline auto isOptPrefix( char c ) -> bool { - return c == '-' -#ifdef CATCH_PLATFORM_WINDOWS - || c == '/' -#endif - ; - } - - // Abstracts iterators into args as a stream of tokens, with option arguments uniformly handled - class TokenStream { - using Iterator = std::vector<std::string>::const_iterator; - Iterator it; - Iterator itEnd; - std::vector<Token> m_tokenBuffer; - - void loadBuffer() { - m_tokenBuffer.resize( 0 ); - - // Skip any empty strings - while( it != itEnd && it->empty() ) - ++it; - - if( it != itEnd ) { - auto const &next = *it; - if( isOptPrefix( next[0] ) ) { - auto delimiterPos = next.find_first_of( " :=" ); - if( delimiterPos != std::string::npos ) { - m_tokenBuffer.push_back( { TokenType::Option, next.substr( 0, delimiterPos ) } ); - m_tokenBuffer.push_back( { TokenType::Argument, next.substr( delimiterPos + 1 ) } ); - } else { - if( next[1] != '-' && next.size() > 2 ) { - std::string opt = "- "; - for( size_t i = 1; i < next.size(); ++i ) { - opt[1] = next[i]; - m_tokenBuffer.push_back( { TokenType::Option, opt } ); - } - } else { - m_tokenBuffer.push_back( { TokenType::Option, next } ); - } - } - } else { - m_tokenBuffer.push_back( { TokenType::Argument, next } ); - } - } - } - - public: - explicit TokenStream( Args const &args ) : TokenStream( args.m_args.begin(), args.m_args.end() ) {} - - TokenStream( Iterator it, Iterator itEnd ) : it( it ), itEnd( itEnd ) { - loadBuffer(); - } - - explicit operator bool() const { - return !m_tokenBuffer.empty() || it != itEnd; - } - - auto count() const -> size_t { return m_tokenBuffer.size() + (itEnd - it); } - - auto operator*() const -> Token { - assert( !m_tokenBuffer.empty() ); - return m_tokenBuffer.front(); - } - - auto operator->() const -> Token const * { - assert( !m_tokenBuffer.empty() ); - return &m_tokenBuffer.front(); - } - - auto operator++() -> TokenStream & { - if( m_tokenBuffer.size() >= 2 ) { - m_tokenBuffer.erase( m_tokenBuffer.begin() ); - } else { - if( it != itEnd ) - ++it; - loadBuffer(); - } - return *this; - } - }; - - class ResultBase { - public: - enum Type { - Ok, LogicError, RuntimeError - }; - - protected: - ResultBase( Type type ) : m_type( type ) {} - virtual ~ResultBase() = default; - - virtual void enforceOk() const = 0; - - Type m_type; - }; - - template<typename T> - class ResultValueBase : public ResultBase { - public: - auto value() const -> T const & { - enforceOk(); - return m_value; - } - - protected: - ResultValueBase( Type type ) : ResultBase( type ) {} - - ResultValueBase( ResultValueBase const &other ) : ResultBase( other ) { - if( m_type == ResultBase::Ok ) - new( &m_value ) T( other.m_value ); - } - - ResultValueBase( Type, T const &value ) : ResultBase( Ok ) { - new( &m_value ) T( value ); - } - - auto operator=( ResultValueBase const &other ) -> ResultValueBase & { - if( m_type == ResultBase::Ok ) - m_value.~T(); - ResultBase::operator=(other); - if( m_type == ResultBase::Ok ) - new( &m_value ) T( other.m_value ); - return *this; - } - - ~ResultValueBase() override { - if( m_type == Ok ) - m_value.~T(); - } - - union { - T m_value; - }; - }; - - template<> - class ResultValueBase<void> : public ResultBase { - protected: - using ResultBase::ResultBase; - }; - - template<typename T = void> - class BasicResult : public ResultValueBase<T> { - public: - template<typename U> - explicit BasicResult( BasicResult<U> const &other ) - : ResultValueBase<T>( other.type() ), - m_errorMessage( other.errorMessage() ) - { - assert( type() != ResultBase::Ok ); - } - - template<typename U> - static auto ok( U const &value ) -> BasicResult { return { ResultBase::Ok, value }; } - static auto ok() -> BasicResult { return { ResultBase::Ok }; } - static auto logicError( std::string const &message ) -> BasicResult { return { ResultBase::LogicError, message }; } - static auto runtimeError( std::string const &message ) -> BasicResult { return { ResultBase::RuntimeError, message }; } - - explicit operator bool() const { return m_type == ResultBase::Ok; } - auto type() const -> ResultBase::Type { return m_type; } - auto errorMessage() const -> std::string { return m_errorMessage; } - - protected: - void enforceOk() const override { - - // Errors shouldn't reach this point, but if they do - // the actual error message will be in m_errorMessage - assert( m_type != ResultBase::LogicError ); - assert( m_type != ResultBase::RuntimeError ); - if( m_type != ResultBase::Ok ) - std::abort(); - } - - std::string m_errorMessage; // Only populated if resultType is an error - - BasicResult( ResultBase::Type type, std::string const &message ) - : ResultValueBase<T>(type), - m_errorMessage(message) - { - assert( m_type != ResultBase::Ok ); - } - - using ResultValueBase<T>::ResultValueBase; - using ResultBase::m_type; - }; - - enum class ParseResultType { - Matched, NoMatch, ShortCircuitAll, ShortCircuitSame - }; - - class ParseState { - public: - - ParseState( ParseResultType type, TokenStream const &remainingTokens ) - : m_type(type), - m_remainingTokens( remainingTokens ) - {} - - auto type() const -> ParseResultType { return m_type; } - auto remainingTokens() const -> TokenStream { return m_remainingTokens; } - - private: - ParseResultType m_type; - TokenStream m_remainingTokens; - }; - - using Result = BasicResult<void>; - using ParserResult = BasicResult<ParseResultType>; - using InternalParseResult = BasicResult<ParseState>; - - struct HelpColumns { - std::string left; - std::string right; - }; - - template<typename T> - inline auto convertInto( std::string const &source, T& target ) -> ParserResult { - std::stringstream ss; - ss << source; - ss >> target; - if( ss.fail() ) - return ParserResult::runtimeError( "Unable to convert '" + source + "' to destination type" ); - else - return ParserResult::ok( ParseResultType::Matched ); - } - inline auto convertInto( std::string const &source, std::string& target ) -> ParserResult { - target = source; - return ParserResult::ok( ParseResultType::Matched ); - } - inline auto convertInto( std::string const &source, bool &target ) -> ParserResult { - std::string srcLC = source; - std::transform( srcLC.begin(), srcLC.end(), srcLC.begin(), []( char c ) { return static_cast<char>( std::tolower(c) ); } ); - if (srcLC == "y" || srcLC == "1" || srcLC == "true" || srcLC == "yes" || srcLC == "on") - target = true; - else if (srcLC == "n" || srcLC == "0" || srcLC == "false" || srcLC == "no" || srcLC == "off") - target = false; - else - return ParserResult::runtimeError( "Expected a boolean value but did not recognise: '" + source + "'" ); - return ParserResult::ok( ParseResultType::Matched ); - } -#ifdef CLARA_CONFIG_OPTIONAL_TYPE - template<typename T> - inline auto convertInto( std::string const &source, CLARA_CONFIG_OPTIONAL_TYPE<T>& target ) -> ParserResult { - T temp; - auto result = convertInto( source, temp ); - if( result ) - target = std::move(temp); - return result; - } -#endif // CLARA_CONFIG_OPTIONAL_TYPE - - struct NonCopyable { - NonCopyable() = default; - NonCopyable( NonCopyable const & ) = delete; - NonCopyable( NonCopyable && ) = delete; - NonCopyable &operator=( NonCopyable const & ) = delete; - NonCopyable &operator=( NonCopyable && ) = delete; - }; - - struct BoundRef : NonCopyable { - virtual ~BoundRef() = default; - virtual auto isContainer() const -> bool { return false; } - virtual auto isFlag() const -> bool { return false; } - }; - struct BoundValueRefBase : BoundRef { - virtual auto setValue( std::string const &arg ) -> ParserResult = 0; - }; - struct BoundFlagRefBase : BoundRef { - virtual auto setFlag( bool flag ) -> ParserResult = 0; - virtual auto isFlag() const -> bool { return true; } - }; - - template<typename T> - struct BoundValueRef : BoundValueRefBase { - T &m_ref; - - explicit BoundValueRef( T &ref ) : m_ref( ref ) {} - - auto setValue( std::string const &arg ) -> ParserResult override { - return convertInto( arg, m_ref ); - } - }; - - template<typename T> - struct BoundValueRef<std::vector<T>> : BoundValueRefBase { - std::vector<T> &m_ref; - - explicit BoundValueRef( std::vector<T> &ref ) : m_ref( ref ) {} - - auto isContainer() const -> bool override { return true; } - - auto setValue( std::string const &arg ) -> ParserResult override { - T temp; - auto result = convertInto( arg, temp ); - if( result ) - m_ref.push_back( temp ); - return result; - } - }; - - struct BoundFlagRef : BoundFlagRefBase { - bool &m_ref; - - explicit BoundFlagRef( bool &ref ) : m_ref( ref ) {} - - auto setFlag( bool flag ) -> ParserResult override { - m_ref = flag; - return ParserResult::ok( ParseResultType::Matched ); - } - }; - - template<typename ReturnType> - struct LambdaInvoker { - static_assert( std::is_same<ReturnType, ParserResult>::value, "Lambda must return void or clara::ParserResult" ); - - template<typename L, typename ArgType> - static auto invoke( L const &lambda, ArgType const &arg ) -> ParserResult { - return lambda( arg ); - } - }; - - template<> - struct LambdaInvoker<void> { - template<typename L, typename ArgType> - static auto invoke( L const &lambda, ArgType const &arg ) -> ParserResult { - lambda( arg ); - return ParserResult::ok( ParseResultType::Matched ); - } - }; - - template<typename ArgType, typename L> - inline auto invokeLambda( L const &lambda, std::string const &arg ) -> ParserResult { - ArgType temp{}; - auto result = convertInto( arg, temp ); - return !result - ? result - : LambdaInvoker<typename UnaryLambdaTraits<L>::ReturnType>::invoke( lambda, temp ); - } - - template<typename L> - struct BoundLambda : BoundValueRefBase { - L m_lambda; - - static_assert( UnaryLambdaTraits<L>::isValid, "Supplied lambda must take exactly one argument" ); - explicit BoundLambda( L const &lambda ) : m_lambda( lambda ) {} - - auto setValue( std::string const &arg ) -> ParserResult override { - return invokeLambda<typename UnaryLambdaTraits<L>::ArgType>( m_lambda, arg ); - } - }; - - template<typename L> - struct BoundFlagLambda : BoundFlagRefBase { - L m_lambda; - - static_assert( UnaryLambdaTraits<L>::isValid, "Supplied lambda must take exactly one argument" ); - static_assert( std::is_same<typename UnaryLambdaTraits<L>::ArgType, bool>::value, "flags must be boolean" ); - - explicit BoundFlagLambda( L const &lambda ) : m_lambda( lambda ) {} - - auto setFlag( bool flag ) -> ParserResult override { - return LambdaInvoker<typename UnaryLambdaTraits<L>::ReturnType>::invoke( m_lambda, flag ); - } - }; - - enum class Optionality { Optional, Required }; - - struct Parser; - - class ParserBase { - public: - virtual ~ParserBase() = default; - virtual auto validate() const -> Result { return Result::ok(); } - virtual auto parse( std::string const& exeName, TokenStream const &tokens) const -> InternalParseResult = 0; - virtual auto cardinality() const -> size_t { return 1; } - - auto parse( Args const &args ) const -> InternalParseResult { - return parse( args.exeName(), TokenStream( args ) ); - } - }; - - template<typename DerivedT> - class ComposableParserImpl : public ParserBase { - public: - template<typename T> - auto operator|( T const &other ) const -> Parser; - - template<typename T> - auto operator+( T const &other ) const -> Parser; - }; - - // Common code and state for Args and Opts - template<typename DerivedT> - class ParserRefImpl : public ComposableParserImpl<DerivedT> { - protected: - Optionality m_optionality = Optionality::Optional; - std::shared_ptr<BoundRef> m_ref; - std::string m_hint; - std::string m_description; - - explicit ParserRefImpl( std::shared_ptr<BoundRef> const &ref ) : m_ref( ref ) {} - - public: - template<typename T> - ParserRefImpl( T &ref, std::string const &hint ) - : m_ref( std::make_shared<BoundValueRef<T>>( ref ) ), - m_hint( hint ) - {} - - template<typename LambdaT> - ParserRefImpl( LambdaT const &ref, std::string const &hint ) - : m_ref( std::make_shared<BoundLambda<LambdaT>>( ref ) ), - m_hint(hint) - {} - - auto operator()( std::string const &description ) -> DerivedT & { - m_description = description; - return static_cast<DerivedT &>( *this ); - } - - auto optional() -> DerivedT & { - m_optionality = Optionality::Optional; - return static_cast<DerivedT &>( *this ); - }; - - auto required() -> DerivedT & { - m_optionality = Optionality::Required; - return static_cast<DerivedT &>( *this ); - }; - - auto isOptional() const -> bool { - return m_optionality == Optionality::Optional; - } - - auto cardinality() const -> size_t override { - if( m_ref->isContainer() ) - return 0; - else - return 1; - } - - auto hint() const -> std::string { return m_hint; } - }; - - class ExeName : public ComposableParserImpl<ExeName> { - std::shared_ptr<std::string> m_name; - std::shared_ptr<BoundValueRefBase> m_ref; - - template<typename LambdaT> - static auto makeRef(LambdaT const &lambda) -> std::shared_ptr<BoundValueRefBase> { - return std::make_shared<BoundLambda<LambdaT>>( lambda) ; - } - - public: - ExeName() : m_name( std::make_shared<std::string>( "<executable>" ) ) {} - - explicit ExeName( std::string &ref ) : ExeName() { - m_ref = std::make_shared<BoundValueRef<std::string>>( ref ); - } - - template<typename LambdaT> - explicit ExeName( LambdaT const& lambda ) : ExeName() { - m_ref = std::make_shared<BoundLambda<LambdaT>>( lambda ); - } - - // The exe name is not parsed out of the normal tokens, but is handled specially - auto parse( std::string const&, TokenStream const &tokens ) const -> InternalParseResult override { - return InternalParseResult::ok( ParseState( ParseResultType::NoMatch, tokens ) ); - } - - auto name() const -> std::string { return *m_name; } - auto set( std::string const& newName ) -> ParserResult { - - auto lastSlash = newName.find_last_of( "\\/" ); - auto filename = ( lastSlash == std::string::npos ) - ? newName - : newName.substr( lastSlash+1 ); - - *m_name = filename; - if( m_ref ) - return m_ref->setValue( filename ); - else - return ParserResult::ok( ParseResultType::Matched ); - } - }; - - class Arg : public ParserRefImpl<Arg> { - public: - using ParserRefImpl::ParserRefImpl; - - auto parse( std::string const &, TokenStream const &tokens ) const -> InternalParseResult override { - auto validationResult = validate(); - if( !validationResult ) - return InternalParseResult( validationResult ); - - auto remainingTokens = tokens; - auto const &token = *remainingTokens; - if( token.type != TokenType::Argument ) - return InternalParseResult::ok( ParseState( ParseResultType::NoMatch, remainingTokens ) ); - - assert( !m_ref->isFlag() ); - auto valueRef = static_cast<detail::BoundValueRefBase*>( m_ref.get() ); - - auto result = valueRef->setValue( remainingTokens->token ); - if( !result ) - return InternalParseResult( result ); - else - return InternalParseResult::ok( ParseState( ParseResultType::Matched, ++remainingTokens ) ); - } - }; - - inline auto normaliseOpt( std::string const &optName ) -> std::string { -#ifdef CATCH_PLATFORM_WINDOWS - if( optName[0] == '/' ) - return "-" + optName.substr( 1 ); - else -#endif - return optName; - } - - class Opt : public ParserRefImpl<Opt> { - protected: - std::vector<std::string> m_optNames; - - public: - template<typename LambdaT> - explicit Opt( LambdaT const &ref ) : ParserRefImpl( std::make_shared<BoundFlagLambda<LambdaT>>( ref ) ) {} - - explicit Opt( bool &ref ) : ParserRefImpl( std::make_shared<BoundFlagRef>( ref ) ) {} - - template<typename LambdaT> - Opt( LambdaT const &ref, std::string const &hint ) : ParserRefImpl( ref, hint ) {} - - template<typename T> - Opt( T &ref, std::string const &hint ) : ParserRefImpl( ref, hint ) {} - - auto operator[]( std::string const &optName ) -> Opt & { - m_optNames.push_back( optName ); - return *this; - } - - auto getHelpColumns() const -> std::vector<HelpColumns> { - std::ostringstream oss; - bool first = true; - for( auto const &opt : m_optNames ) { - if (first) - first = false; - else - oss << ", "; - oss << opt; - } - if( !m_hint.empty() ) - oss << " <" << m_hint << ">"; - return { { oss.str(), m_description } }; - } - - auto isMatch( std::string const &optToken ) const -> bool { - auto normalisedToken = normaliseOpt( optToken ); - for( auto const &name : m_optNames ) { - if( normaliseOpt( name ) == normalisedToken ) - return true; - } - return false; - } - - using ParserBase::parse; - - auto parse( std::string const&, TokenStream const &tokens ) const -> InternalParseResult override { - auto validationResult = validate(); - if( !validationResult ) - return InternalParseResult( validationResult ); - - auto remainingTokens = tokens; - if( remainingTokens && remainingTokens->type == TokenType::Option ) { - auto const &token = *remainingTokens; - if( isMatch(token.token ) ) { - if( m_ref->isFlag() ) { - auto flagRef = static_cast<detail::BoundFlagRefBase*>( m_ref.get() ); - auto result = flagRef->setFlag( true ); - if( !result ) - return InternalParseResult( result ); - if( result.value() == ParseResultType::ShortCircuitAll ) - return InternalParseResult::ok( ParseState( result.value(), remainingTokens ) ); - } else { - auto valueRef = static_cast<detail::BoundValueRefBase*>( m_ref.get() ); - ++remainingTokens; - if( !remainingTokens ) - return InternalParseResult::runtimeError( "Expected argument following " + token.token ); - auto const &argToken = *remainingTokens; - if( argToken.type != TokenType::Argument ) - return InternalParseResult::runtimeError( "Expected argument following " + token.token ); - auto result = valueRef->setValue( argToken.token ); - if( !result ) - return InternalParseResult( result ); - if( result.value() == ParseResultType::ShortCircuitAll ) - return InternalParseResult::ok( ParseState( result.value(), remainingTokens ) ); - } - return InternalParseResult::ok( ParseState( ParseResultType::Matched, ++remainingTokens ) ); - } - } - return InternalParseResult::ok( ParseState( ParseResultType::NoMatch, remainingTokens ) ); - } - - auto validate() const -> Result override { - if( m_optNames.empty() ) - return Result::logicError( "No options supplied to Opt" ); - for( auto const &name : m_optNames ) { - if( name.empty() ) - return Result::logicError( "Option name cannot be empty" ); -#ifdef CATCH_PLATFORM_WINDOWS - if( name[0] != '-' && name[0] != '/' ) - return Result::logicError( "Option name must begin with '-' or '/'" ); -#else - if( name[0] != '-' ) - return Result::logicError( "Option name must begin with '-'" ); -#endif - } - return ParserRefImpl::validate(); - } - }; - - struct Help : Opt { - Help( bool &showHelpFlag ) - : Opt([&]( bool flag ) { - showHelpFlag = flag; - return ParserResult::ok( ParseResultType::ShortCircuitAll ); - }) - { - static_cast<Opt &>( *this ) - ("display usage information") - ["-?"]["-h"]["--help"] - .optional(); - } - }; - - struct Parser : ParserBase { - - mutable ExeName m_exeName; - std::vector<Opt> m_options; - std::vector<Arg> m_args; - - auto operator|=( ExeName const &exeName ) -> Parser & { - m_exeName = exeName; - return *this; - } - - auto operator|=( Arg const &arg ) -> Parser & { - m_args.push_back(arg); - return *this; - } - - auto operator|=( Opt const &opt ) -> Parser & { - m_options.push_back(opt); - return *this; - } - - auto operator|=( Parser const &other ) -> Parser & { - m_options.insert(m_options.end(), other.m_options.begin(), other.m_options.end()); - m_args.insert(m_args.end(), other.m_args.begin(), other.m_args.end()); - return *this; - } - - template<typename T> - auto operator|( T const &other ) const -> Parser { - return Parser( *this ) |= other; - } - - // Forward deprecated interface with '+' instead of '|' - template<typename T> - auto operator+=( T const &other ) -> Parser & { return operator|=( other ); } - template<typename T> - auto operator+( T const &other ) const -> Parser { return operator|( other ); } - - auto getHelpColumns() const -> std::vector<HelpColumns> { - std::vector<HelpColumns> cols; - for (auto const &o : m_options) { - auto childCols = o.getHelpColumns(); - cols.insert( cols.end(), childCols.begin(), childCols.end() ); - } - return cols; - } - - void writeToStream( std::ostream &os ) const { - if (!m_exeName.name().empty()) { - os << "usage:\n" << " " << m_exeName.name() << " "; - bool required = true, first = true; - for( auto const &arg : m_args ) { - if (first) - first = false; - else - os << " "; - if( arg.isOptional() && required ) { - os << "["; - required = false; - } - os << "<" << arg.hint() << ">"; - if( arg.cardinality() == 0 ) - os << " ... "; - } - if( !required ) - os << "]"; - if( !m_options.empty() ) - os << " options"; - os << "\n\nwhere options are:" << std::endl; - } - - auto rows = getHelpColumns(); - size_t consoleWidth = CATCH_CLARA_CONFIG_CONSOLE_WIDTH; - size_t optWidth = 0; - for( auto const &cols : rows ) - optWidth = (std::max)(optWidth, cols.left.size() + 2); - - optWidth = (std::min)(optWidth, consoleWidth/2); - - for( auto const &cols : rows ) { - auto row = - TextFlow::Column( cols.left ).width( optWidth ).indent( 2 ) + - TextFlow::Spacer(4) + - TextFlow::Column( cols.right ).width( consoleWidth - 7 - optWidth ); - os << row << std::endl; - } - } - - friend auto operator<<( std::ostream &os, Parser const &parser ) -> std::ostream& { - parser.writeToStream( os ); - return os; - } - - auto validate() const -> Result override { - for( auto const &opt : m_options ) { - auto result = opt.validate(); - if( !result ) - return result; - } - for( auto const &arg : m_args ) { - auto result = arg.validate(); - if( !result ) - return result; - } - return Result::ok(); - } - - using ParserBase::parse; - - auto parse( std::string const& exeName, TokenStream const &tokens ) const -> InternalParseResult override { - - struct ParserInfo { - ParserBase const* parser = nullptr; - size_t count = 0; - }; - const size_t totalParsers = m_options.size() + m_args.size(); - assert( totalParsers < 512 ); - // ParserInfo parseInfos[totalParsers]; // <-- this is what we really want to do - ParserInfo parseInfos[512]; - - { - size_t i = 0; - for (auto const &opt : m_options) parseInfos[i++].parser = &opt; - for (auto const &arg : m_args) parseInfos[i++].parser = &arg; - } - - m_exeName.set( exeName ); - - auto result = InternalParseResult::ok( ParseState( ParseResultType::NoMatch, tokens ) ); - while( result.value().remainingTokens() ) { - bool tokenParsed = false; - - for( size_t i = 0; i < totalParsers; ++i ) { - auto& parseInfo = parseInfos[i]; - if( parseInfo.parser->cardinality() == 0 || parseInfo.count < parseInfo.parser->cardinality() ) { - result = parseInfo.parser->parse(exeName, result.value().remainingTokens()); - if (!result) - return result; - if (result.value().type() != ParseResultType::NoMatch) { - tokenParsed = true; - ++parseInfo.count; - break; - } - } - } - - if( result.value().type() == ParseResultType::ShortCircuitAll ) - return result; - if( !tokenParsed ) - return InternalParseResult::runtimeError( "Unrecognised token: " + result.value().remainingTokens()->token ); - } - // !TBD Check missing required options - return result; - } - }; - - template<typename DerivedT> - template<typename T> - auto ComposableParserImpl<DerivedT>::operator|( T const &other ) const -> Parser { - return Parser() | static_cast<DerivedT const &>( *this ) | other; - } -} // namespace detail - -// A Combined parser -using detail::Parser; - -// A parser for options -using detail::Opt; - -// A parser for arguments -using detail::Arg; - -// Wrapper for argc, argv from main() -using detail::Args; - -// Specifies the name of the executable -using detail::ExeName; - -// Convenience wrapper for option parser that specifies the help option -using detail::Help; - -// enum of result types from a parse -using detail::ParseResultType; - -// Result type for parser operation -using detail::ParserResult; - -}} // namespace Catch::clara - -// end clara.hpp -#ifdef __clang__ -#pragma clang diagnostic pop -#endif - -// Restore Clara's value for console width, if present -#ifdef CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH -#define CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH -#undef CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH -#endif - -// end catch_clara.h -namespace Catch { - - clara::Parser makeCommandLineParser( ConfigData& config ); - -} // end namespace Catch - -// end catch_commandline.h -#include <fstream> -#include <ctime> - -namespace Catch { - - clara::Parser makeCommandLineParser( ConfigData& config ) { - - using namespace clara; - - auto const setWarning = [&]( std::string const& warning ) { - auto warningSet = [&]() { - if( warning == "NoAssertions" ) - return WarnAbout::NoAssertions; - - if ( warning == "NoTests" ) - return WarnAbout::NoTests; - - return WarnAbout::Nothing; - }(); - - if (warningSet == WarnAbout::Nothing) - return ParserResult::runtimeError( "Unrecognised warning: '" + warning + "'" ); - config.warnings = static_cast<WarnAbout::What>( config.warnings | warningSet ); - return ParserResult::ok( ParseResultType::Matched ); - }; - auto const loadTestNamesFromFile = [&]( std::string const& filename ) { - std::ifstream f( filename.c_str() ); - if( !f.is_open() ) - return ParserResult::runtimeError( "Unable to load input file: '" + filename + "'" ); - - std::string line; - while( std::getline( f, line ) ) { - line = trim(line); - if( !line.empty() && !startsWith( line, '#' ) ) { - if( !startsWith( line, '"' ) ) - line = '"' + line + '"'; - config.testsOrTags.push_back( line ); - config.testsOrTags.emplace_back( "," ); - } - } - //Remove comma in the end - if(!config.testsOrTags.empty()) - config.testsOrTags.erase( config.testsOrTags.end()-1 ); - - return ParserResult::ok( ParseResultType::Matched ); - }; - auto const setTestOrder = [&]( std::string const& order ) { - if( startsWith( "declared", order ) ) - config.runOrder = RunTests::InDeclarationOrder; - else if( startsWith( "lexical", order ) ) - config.runOrder = RunTests::InLexicographicalOrder; - else if( startsWith( "random", order ) ) - config.runOrder = RunTests::InRandomOrder; - else - return clara::ParserResult::runtimeError( "Unrecognised ordering: '" + order + "'" ); - return ParserResult::ok( ParseResultType::Matched ); - }; - auto const setRngSeed = [&]( std::string const& seed ) { - if( seed != "time" ) - return clara::detail::convertInto( seed, config.rngSeed ); - config.rngSeed = static_cast<unsigned int>( std::time(nullptr) ); - return ParserResult::ok( ParseResultType::Matched ); - }; - auto const setColourUsage = [&]( std::string const& useColour ) { - auto mode = toLower( useColour ); - - if( mode == "yes" ) - config.useColour = UseColour::Yes; - else if( mode == "no" ) - config.useColour = UseColour::No; - else if( mode == "auto" ) - config.useColour = UseColour::Auto; - else - return ParserResult::runtimeError( "colour mode must be one of: auto, yes or no. '" + useColour + "' not recognised" ); - return ParserResult::ok( ParseResultType::Matched ); - }; - auto const setWaitForKeypress = [&]( std::string const& keypress ) { - auto keypressLc = toLower( keypress ); - if (keypressLc == "never") - config.waitForKeypress = WaitForKeypress::Never; - else if( keypressLc == "start" ) - config.waitForKeypress = WaitForKeypress::BeforeStart; - else if( keypressLc == "exit" ) - config.waitForKeypress = WaitForKeypress::BeforeExit; - else if( keypressLc == "both" ) - config.waitForKeypress = WaitForKeypress::BeforeStartAndExit; - else - return ParserResult::runtimeError( "keypress argument must be one of: never, start, exit or both. '" + keypress + "' not recognised" ); - return ParserResult::ok( ParseResultType::Matched ); - }; - auto const setVerbosity = [&]( std::string const& verbosity ) { - auto lcVerbosity = toLower( verbosity ); - if( lcVerbosity == "quiet" ) - config.verbosity = Verbosity::Quiet; - else if( lcVerbosity == "normal" ) - config.verbosity = Verbosity::Normal; - else if( lcVerbosity == "high" ) - config.verbosity = Verbosity::High; - else - return ParserResult::runtimeError( "Unrecognised verbosity, '" + verbosity + "'" ); - return ParserResult::ok( ParseResultType::Matched ); - }; - auto const setReporter = [&]( std::string const& reporter ) { - IReporterRegistry::FactoryMap const& factories = getRegistryHub().getReporterRegistry().getFactories(); - - auto lcReporter = toLower( reporter ); - auto result = factories.find( lcReporter ); - - if( factories.end() != result ) - config.reporterName = lcReporter; - else - return ParserResult::runtimeError( "Unrecognized reporter, '" + reporter + "'. Check available with --list-reporters" ); - return ParserResult::ok( ParseResultType::Matched ); - }; - - auto cli - = ExeName( config.processName ) - | Help( config.showHelp ) - | Opt( config.listTests ) - ["-l"]["--list-tests"] - ( "list all/matching test cases" ) - | Opt( config.listTags ) - ["-t"]["--list-tags"] - ( "list all/matching tags" ) - | Opt( config.showSuccessfulTests ) - ["-s"]["--success"] - ( "include successful tests in output" ) - | Opt( config.shouldDebugBreak ) - ["-b"]["--break"] - ( "break into debugger on failure" ) - | Opt( config.noThrow ) - ["-e"]["--nothrow"] - ( "skip exception tests" ) - | Opt( config.showInvisibles ) - ["-i"]["--invisibles"] - ( "show invisibles (tabs, newlines)" ) - | Opt( config.outputFilename, "filename" ) - ["-o"]["--out"] - ( "output filename" ) - | Opt( setReporter, "name" ) - ["-r"]["--reporter"] - ( "reporter to use (defaults to console)" ) - | Opt( config.name, "name" ) - ["-n"]["--name"] - ( "suite name" ) - | Opt( [&]( bool ){ config.abortAfter = 1; } ) - ["-a"]["--abort"] - ( "abort at first failure" ) - | Opt( [&]( int x ){ config.abortAfter = x; }, "no. failures" ) - ["-x"]["--abortx"] - ( "abort after x failures" ) - | Opt( setWarning, "warning name" ) - ["-w"]["--warn"] - ( "enable warnings" ) - | Opt( [&]( bool flag ) { config.showDurations = flag ? ShowDurations::Always : ShowDurations::Never; }, "yes|no" ) - ["-d"]["--durations"] - ( "show test durations" ) - | Opt( loadTestNamesFromFile, "filename" ) - ["-f"]["--input-file"] - ( "load test names to run from a file" ) - | Opt( config.filenamesAsTags ) - ["-#"]["--filenames-as-tags"] - ( "adds a tag for the filename" ) - | Opt( config.sectionsToRun, "section name" ) - ["-c"]["--section"] - ( "specify section to run" ) - | Opt( setVerbosity, "quiet|normal|high" ) - ["-v"]["--verbosity"] - ( "set output verbosity" ) - | Opt( config.listTestNamesOnly ) - ["--list-test-names-only"] - ( "list all/matching test cases names only" ) - | Opt( config.listReporters ) - ["--list-reporters"] - ( "list all reporters" ) - | Opt( setTestOrder, "decl|lex|rand" ) - ["--order"] - ( "test case order (defaults to decl)" ) - | Opt( setRngSeed, "'time'|number" ) - ["--rng-seed"] - ( "set a specific seed for random numbers" ) - | Opt( setColourUsage, "yes|no" ) - ["--use-colour"] - ( "should output be colourised" ) - | Opt( config.libIdentify ) - ["--libidentify"] - ( "report name and version according to libidentify standard" ) - | Opt( setWaitForKeypress, "never|start|exit|both" ) - ["--wait-for-keypress"] - ( "waits for a keypress before exiting" ) - | Opt( config.benchmarkSamples, "samples" ) - ["--benchmark-samples"] - ( "number of samples to collect (default: 100)" ) - | Opt( config.benchmarkResamples, "resamples" ) - ["--benchmark-resamples"] - ( "number of resamples for the bootstrap (default: 100000)" ) - | Opt( config.benchmarkConfidenceInterval, "confidence interval" ) - ["--benchmark-confidence-interval"] - ( "confidence interval for the bootstrap (between 0 and 1, default: 0.95)" ) - | Opt( config.benchmarkNoAnalysis ) - ["--benchmark-no-analysis"] - ( "perform only measurements; do not perform any analysis" ) - | Opt( config.benchmarkWarmupTime, "benchmarkWarmupTime" ) - ["--benchmark-warmup-time"] - ( "amount of time in milliseconds spent on warming up each test (default: 100)" ) - | Arg( config.testsOrTags, "test name|pattern|tags" ) - ( "which test or tests to use" ); - - return cli; - } - -} // end namespace Catch -// end catch_commandline.cpp -// start catch_common.cpp - -#include <cstring> -#include <ostream> - -namespace Catch { - - bool SourceLineInfo::operator == ( SourceLineInfo const& other ) const noexcept { - return line == other.line && (file == other.file || std::strcmp(file, other.file) == 0); - } - bool SourceLineInfo::operator < ( SourceLineInfo const& other ) const noexcept { - // We can assume that the same file will usually have the same pointer. - // Thus, if the pointers are the same, there is no point in calling the strcmp - return line < other.line || ( line == other.line && file != other.file && (std::strcmp(file, other.file) < 0)); - } - - std::ostream& operator << ( std::ostream& os, SourceLineInfo const& info ) { -#ifndef __GNUG__ - os << info.file << '(' << info.line << ')'; -#else - os << info.file << ':' << info.line; -#endif - return os; - } - - std::string StreamEndStop::operator+() const { - return std::string(); - } - - NonCopyable::NonCopyable() = default; - NonCopyable::~NonCopyable() = default; - -} -// end catch_common.cpp -// start catch_config.cpp - -namespace Catch { - - Config::Config( ConfigData const& data ) - : m_data( data ), - m_stream( openStream() ) - { - // We need to trim filter specs to avoid trouble with superfluous - // whitespace (esp. important for bdd macros, as those are manually - // aligned with whitespace). - - for (auto& elem : m_data.testsOrTags) { - elem = trim(elem); - } - for (auto& elem : m_data.sectionsToRun) { - elem = trim(elem); - } - - TestSpecParser parser(ITagAliasRegistry::get()); - if (!m_data.testsOrTags.empty()) { - m_hasTestFilters = true; - for (auto const& testOrTags : m_data.testsOrTags) { - parser.parse(testOrTags); - } - } - m_testSpec = parser.testSpec(); - } - - std::string const& Config::getFilename() const { - return m_data.outputFilename ; - } - - bool Config::listTests() const { return m_data.listTests; } - bool Config::listTestNamesOnly() const { return m_data.listTestNamesOnly; } - bool Config::listTags() const { return m_data.listTags; } - bool Config::listReporters() const { return m_data.listReporters; } - - std::string Config::getProcessName() const { return m_data.processName; } - std::string const& Config::getReporterName() const { return m_data.reporterName; } - - std::vector<std::string> const& Config::getTestsOrTags() const { return m_data.testsOrTags; } - std::vector<std::string> const& Config::getSectionsToRun() const { return m_data.sectionsToRun; } - - TestSpec const& Config::testSpec() const { return m_testSpec; } - bool Config::hasTestFilters() const { return m_hasTestFilters; } - - bool Config::showHelp() const { return m_data.showHelp; } - - // IConfig interface - bool Config::allowThrows() const { return !m_data.noThrow; } - std::ostream& Config::stream() const { return m_stream->stream(); } - std::string Config::name() const { return m_data.name.empty() ? m_data.processName : m_data.name; } - bool Config::includeSuccessfulResults() const { return m_data.showSuccessfulTests; } - bool Config::warnAboutMissingAssertions() const { return !!(m_data.warnings & WarnAbout::NoAssertions); } - bool Config::warnAboutNoTests() const { return !!(m_data.warnings & WarnAbout::NoTests); } - ShowDurations::OrNot Config::showDurations() const { return m_data.showDurations; } - RunTests::InWhatOrder Config::runOrder() const { return m_data.runOrder; } - unsigned int Config::rngSeed() const { return m_data.rngSeed; } - UseColour::YesOrNo Config::useColour() const { return m_data.useColour; } - bool Config::shouldDebugBreak() const { return m_data.shouldDebugBreak; } - int Config::abortAfter() const { return m_data.abortAfter; } - bool Config::showInvisibles() const { return m_data.showInvisibles; } - Verbosity Config::verbosity() const { return m_data.verbosity; } - - bool Config::benchmarkNoAnalysis() const { return m_data.benchmarkNoAnalysis; } - int Config::benchmarkSamples() const { return m_data.benchmarkSamples; } - double Config::benchmarkConfidenceInterval() const { return m_data.benchmarkConfidenceInterval; } - unsigned int Config::benchmarkResamples() const { return m_data.benchmarkResamples; } - std::chrono::milliseconds Config::benchmarkWarmupTime() const { return std::chrono::milliseconds(m_data.benchmarkWarmupTime); } - - IStream const* Config::openStream() { - return Catch::makeStream(m_data.outputFilename); - } - -} // end namespace Catch -// end catch_config.cpp -// start catch_console_colour.cpp - -#if defined(__clang__) -# pragma clang diagnostic push -# pragma clang diagnostic ignored "-Wexit-time-destructors" -#endif - -// start catch_errno_guard.h - -namespace Catch { - - class ErrnoGuard { - public: - ErrnoGuard(); - ~ErrnoGuard(); - private: - int m_oldErrno; - }; - -} - -// end catch_errno_guard.h -#include <sstream> - -namespace Catch { - namespace { - - struct IColourImpl { - virtual ~IColourImpl() = default; - virtual void use( Colour::Code _colourCode ) = 0; - }; - - struct NoColourImpl : IColourImpl { - void use( Colour::Code ) override {} - - static IColourImpl* instance() { - static NoColourImpl s_instance; - return &s_instance; - } - }; - - } // anon namespace -} // namespace Catch - -#if !defined( CATCH_CONFIG_COLOUR_NONE ) && !defined( CATCH_CONFIG_COLOUR_WINDOWS ) && !defined( CATCH_CONFIG_COLOUR_ANSI ) -# ifdef CATCH_PLATFORM_WINDOWS -# define CATCH_CONFIG_COLOUR_WINDOWS -# else -# define CATCH_CONFIG_COLOUR_ANSI -# endif -#endif - -#if defined ( CATCH_CONFIG_COLOUR_WINDOWS ) ///////////////////////////////////////// - -namespace Catch { -namespace { - - class Win32ColourImpl : public IColourImpl { - public: - Win32ColourImpl() : stdoutHandle( GetStdHandle(STD_OUTPUT_HANDLE) ) - { - CONSOLE_SCREEN_BUFFER_INFO csbiInfo; - GetConsoleScreenBufferInfo( stdoutHandle, &csbiInfo ); - originalForegroundAttributes = csbiInfo.wAttributes & ~( BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_BLUE | BACKGROUND_INTENSITY ); - originalBackgroundAttributes = csbiInfo.wAttributes & ~( FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY ); - } - - void use( Colour::Code _colourCode ) override { - switch( _colourCode ) { - case Colour::None: return setTextAttribute( originalForegroundAttributes ); - case Colour::White: return setTextAttribute( FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE ); - case Colour::Red: return setTextAttribute( FOREGROUND_RED ); - case Colour::Green: return setTextAttribute( FOREGROUND_GREEN ); - case Colour::Blue: return setTextAttribute( FOREGROUND_BLUE ); - case Colour::Cyan: return setTextAttribute( FOREGROUND_BLUE | FOREGROUND_GREEN ); - case Colour::Yellow: return setTextAttribute( FOREGROUND_RED | FOREGROUND_GREEN ); - case Colour::Grey: return setTextAttribute( 0 ); - - case Colour::LightGrey: return setTextAttribute( FOREGROUND_INTENSITY ); - case Colour::BrightRed: return setTextAttribute( FOREGROUND_INTENSITY | FOREGROUND_RED ); - case Colour::BrightGreen: return setTextAttribute( FOREGROUND_INTENSITY | FOREGROUND_GREEN ); - case Colour::BrightWhite: return setTextAttribute( FOREGROUND_INTENSITY | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE ); - case Colour::BrightYellow: return setTextAttribute( FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN ); - - case Colour::Bright: CATCH_INTERNAL_ERROR( "not a colour" ); - - default: - CATCH_ERROR( "Unknown colour requested" ); - } - } - - private: - void setTextAttribute( WORD _textAttribute ) { - SetConsoleTextAttribute( stdoutHandle, _textAttribute | originalBackgroundAttributes ); - } - HANDLE stdoutHandle; - WORD originalForegroundAttributes; - WORD originalBackgroundAttributes; - }; - - IColourImpl* platformColourInstance() { - static Win32ColourImpl s_instance; - - IConfigPtr config = getCurrentContext().getConfig(); - UseColour::YesOrNo colourMode = config - ? config->useColour() - : UseColour::Auto; - if( colourMode == UseColour::Auto ) - colourMode = UseColour::Yes; - return colourMode == UseColour::Yes - ? &s_instance - : NoColourImpl::instance(); - } - -} // end anon namespace -} // end namespace Catch - -#elif defined( CATCH_CONFIG_COLOUR_ANSI ) ////////////////////////////////////// - -#include <unistd.h> - -namespace Catch { -namespace { - - // use POSIX/ ANSI console terminal codes - // Thanks to Adam Strzelecki for original contribution - // (http://github.com/nanoant) - // https://github.com/philsquared/Catch/pull/131 - class PosixColourImpl : public IColourImpl { - public: - void use( Colour::Code _colourCode ) override { - switch( _colourCode ) { - case Colour::None: - case Colour::White: return setColour( "[0m" ); - case Colour::Red: return setColour( "[0;31m" ); - case Colour::Green: return setColour( "[0;32m" ); - case Colour::Blue: return setColour( "[0;34m" ); - case Colour::Cyan: return setColour( "[0;36m" ); - case Colour::Yellow: return setColour( "[0;33m" ); - case Colour::Grey: return setColour( "[1;30m" ); - - case Colour::LightGrey: return setColour( "[0;37m" ); - case Colour::BrightRed: return setColour( "[1;31m" ); - case Colour::BrightGreen: return setColour( "[1;32m" ); - case Colour::BrightWhite: return setColour( "[1;37m" ); - case Colour::BrightYellow: return setColour( "[1;33m" ); - - case Colour::Bright: CATCH_INTERNAL_ERROR( "not a colour" ); - default: CATCH_INTERNAL_ERROR( "Unknown colour requested" ); - } - } - static IColourImpl* instance() { - static PosixColourImpl s_instance; - return &s_instance; - } - - private: - void setColour( const char* _escapeCode ) { - getCurrentContext().getConfig()->stream() - << '\033' << _escapeCode; - } - }; - - bool useColourOnPlatform() { - return -#if defined(CATCH_PLATFORM_MAC) || defined(CATCH_PLATFORM_IPHONE) - !isDebuggerActive() && -#endif -#if !(defined(__DJGPP__) && defined(__STRICT_ANSI__)) - isatty(STDOUT_FILENO) -#else - false -#endif - ; - } - IColourImpl* platformColourInstance() { - ErrnoGuard guard; - IConfigPtr config = getCurrentContext().getConfig(); - UseColour::YesOrNo colourMode = config - ? config->useColour() - : UseColour::Auto; - if( colourMode == UseColour::Auto ) - colourMode = useColourOnPlatform() - ? UseColour::Yes - : UseColour::No; - return colourMode == UseColour::Yes - ? PosixColourImpl::instance() - : NoColourImpl::instance(); - } - -} // end anon namespace -} // end namespace Catch - -#else // not Windows or ANSI /////////////////////////////////////////////// - -namespace Catch { - - static IColourImpl* platformColourInstance() { return NoColourImpl::instance(); } - -} // end namespace Catch - -#endif // Windows/ ANSI/ None - -namespace Catch { - - Colour::Colour( Code _colourCode ) { use( _colourCode ); } - Colour::Colour( Colour&& other ) noexcept { - m_moved = other.m_moved; - other.m_moved = true; - } - Colour& Colour::operator=( Colour&& other ) noexcept { - m_moved = other.m_moved; - other.m_moved = true; - return *this; - } - - Colour::~Colour(){ if( !m_moved ) use( None ); } - - void Colour::use( Code _colourCode ) { - static IColourImpl* impl = platformColourInstance(); - // Strictly speaking, this cannot possibly happen. - // However, under some conditions it does happen (see #1626), - // and this change is small enough that we can let practicality - // triumph over purity in this case. - if (impl != nullptr) { - impl->use( _colourCode ); - } - } - - std::ostream& operator << ( std::ostream& os, Colour const& ) { - return os; - } - -} // end namespace Catch - -#if defined(__clang__) -# pragma clang diagnostic pop -#endif - -// end catch_console_colour.cpp -// start catch_context.cpp - -namespace Catch { - - class Context : public IMutableContext, NonCopyable { - - public: // IContext - IResultCapture* getResultCapture() override { - return m_resultCapture; - } - IRunner* getRunner() override { - return m_runner; - } - - IConfigPtr const& getConfig() const override { - return m_config; - } - - ~Context() override; - - public: // IMutableContext - void setResultCapture( IResultCapture* resultCapture ) override { - m_resultCapture = resultCapture; - } - void setRunner( IRunner* runner ) override { - m_runner = runner; - } - void setConfig( IConfigPtr const& config ) override { - m_config = config; - } - - friend IMutableContext& getCurrentMutableContext(); - - private: - IConfigPtr m_config; - IRunner* m_runner = nullptr; - IResultCapture* m_resultCapture = nullptr; - }; - - IMutableContext *IMutableContext::currentContext = nullptr; - - void IMutableContext::createContext() - { - currentContext = new Context(); - } - - void cleanUpContext() { - delete IMutableContext::currentContext; - IMutableContext::currentContext = nullptr; - } - IContext::~IContext() = default; - IMutableContext::~IMutableContext() = default; - Context::~Context() = default; - - SimplePcg32& rng() { - static SimplePcg32 s_rng; - return s_rng; - } - -} -// end catch_context.cpp -// start catch_debug_console.cpp - -// start catch_debug_console.h - -#include <string> - -namespace Catch { - void writeToDebugConsole( std::string const& text ); -} - -// end catch_debug_console.h -#if defined(CATCH_CONFIG_ANDROID_LOGWRITE) -#include <android/log.h> - - namespace Catch { - void writeToDebugConsole( std::string const& text ) { - __android_log_write( ANDROID_LOG_DEBUG, "Catch", text.c_str() ); - } - } - -#elif defined(CATCH_PLATFORM_WINDOWS) - - namespace Catch { - void writeToDebugConsole( std::string const& text ) { - ::OutputDebugStringA( text.c_str() ); - } - } - -#else - - namespace Catch { - void writeToDebugConsole( std::string const& text ) { - // !TBD: Need a version for Mac/ XCode and other IDEs - Catch::cout() << text; - } - } - -#endif // Platform -// end catch_debug_console.cpp -// start catch_debugger.cpp - -#if defined(CATCH_PLATFORM_MAC) || defined(CATCH_PLATFORM_IPHONE) - -# include <cassert> -# include <sys/types.h> -# include <unistd.h> -# include <cstddef> -# include <ostream> - -#ifdef __apple_build_version__ - // These headers will only compile with AppleClang (XCode) - // For other compilers (Clang, GCC, ... ) we need to exclude them -# include <sys/sysctl.h> -#endif - - namespace Catch { - #ifdef __apple_build_version__ - // The following function is taken directly from the following technical note: - // https://developer.apple.com/library/archive/qa/qa1361/_index.html - - // Returns true if the current process is being debugged (either - // running under the debugger or has a debugger attached post facto). - bool isDebuggerActive(){ - int mib[4]; - struct kinfo_proc info; - std::size_t size; - - // Initialize the flags so that, if sysctl fails for some bizarre - // reason, we get a predictable result. - - info.kp_proc.p_flag = 0; - - // Initialize mib, which tells sysctl the info we want, in this case - // we're looking for information about a specific process ID. - - mib[0] = CTL_KERN; - mib[1] = KERN_PROC; - mib[2] = KERN_PROC_PID; - mib[3] = getpid(); - - // Call sysctl. - - size = sizeof(info); - if( sysctl(mib, sizeof(mib) / sizeof(*mib), &info, &size, nullptr, 0) != 0 ) { - Catch::cerr() << "\n** Call to sysctl failed - unable to determine if debugger is active **\n" << std::endl; - return false; - } - - // We're being debugged if the P_TRACED flag is set. - - return ( (info.kp_proc.p_flag & P_TRACED) != 0 ); - } - #else - bool isDebuggerActive() { - // We need to find another way to determine this for non-appleclang compilers on macOS - return false; - } - #endif - } // namespace Catch - -#elif defined(CATCH_PLATFORM_LINUX) - #include <fstream> - #include <string> - - namespace Catch{ - // The standard POSIX way of detecting a debugger is to attempt to - // ptrace() the process, but this needs to be done from a child and not - // this process itself to still allow attaching to this process later - // if wanted, so is rather heavy. Under Linux we have the PID of the - // "debugger" (which doesn't need to be gdb, of course, it could also - // be strace, for example) in /proc/$PID/status, so just get it from - // there instead. - bool isDebuggerActive(){ - // Libstdc++ has a bug, where std::ifstream sets errno to 0 - // This way our users can properly assert over errno values - ErrnoGuard guard; - std::ifstream in("/proc/self/status"); - for( std::string line; std::getline(in, line); ) { - static const int PREFIX_LEN = 11; - if( line.compare(0, PREFIX_LEN, "TracerPid:\t") == 0 ) { - // We're traced if the PID is not 0 and no other PID starts - // with 0 digit, so it's enough to check for just a single - // character. - return line.length() > PREFIX_LEN && line[PREFIX_LEN] != '0'; - } - } - - return false; - } - } // namespace Catch -#elif defined(_MSC_VER) - extern "C" __declspec(dllimport) int __stdcall IsDebuggerPresent(); - namespace Catch { - bool isDebuggerActive() { - return IsDebuggerPresent() != 0; - } - } -#elif defined(__MINGW32__) - extern "C" __declspec(dllimport) int __stdcall IsDebuggerPresent(); - namespace Catch { - bool isDebuggerActive() { - return IsDebuggerPresent() != 0; - } - } -#else - namespace Catch { - bool isDebuggerActive() { return false; } - } -#endif // Platform -// end catch_debugger.cpp -// start catch_decomposer.cpp - -namespace Catch { - - ITransientExpression::~ITransientExpression() = default; - - void formatReconstructedExpression( std::ostream &os, std::string const& lhs, StringRef op, std::string const& rhs ) { - if( lhs.size() + rhs.size() < 40 && - lhs.find('\n') == std::string::npos && - rhs.find('\n') == std::string::npos ) - os << lhs << " " << op << " " << rhs; - else - os << lhs << "\n" << op << "\n" << rhs; - } -} -// end catch_decomposer.cpp -// start catch_enforce.cpp - -#include <stdexcept> - -namespace Catch { -#if defined(CATCH_CONFIG_DISABLE_EXCEPTIONS) && !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS_CUSTOM_HANDLER) - [[noreturn]] - void throw_exception(std::exception const& e) { - Catch::cerr() << "Catch will terminate because it needed to throw an exception.\n" - << "The message was: " << e.what() << '\n'; - std::terminate(); - } -#endif - - [[noreturn]] - void throw_logic_error(std::string const& msg) { - throw_exception(std::logic_error(msg)); - } - - [[noreturn]] - void throw_domain_error(std::string const& msg) { - throw_exception(std::domain_error(msg)); - } - - [[noreturn]] - void throw_runtime_error(std::string const& msg) { - throw_exception(std::runtime_error(msg)); - } - -} // namespace Catch; -// end catch_enforce.cpp -// start catch_enum_values_registry.cpp -// start catch_enum_values_registry.h - -#include <vector> -#include <memory> - -namespace Catch { - - namespace Detail { - - std::unique_ptr<EnumInfo> makeEnumInfo( StringRef enumName, StringRef allValueNames, std::vector<int> const& values ); - - class EnumValuesRegistry : public IMutableEnumValuesRegistry { - - std::vector<std::unique_ptr<EnumInfo>> m_enumInfos; - - EnumInfo const& registerEnum( StringRef enumName, StringRef allEnums, std::vector<int> const& values) override; - }; - - std::vector<StringRef> parseEnums( StringRef enums ); - - } // Detail - -} // Catch - -// end catch_enum_values_registry.h - -#include <map> -#include <cassert> - -namespace Catch { - - IMutableEnumValuesRegistry::~IMutableEnumValuesRegistry() {} - - namespace Detail { - - namespace { - // Extracts the actual name part of an enum instance - // In other words, it returns the Blue part of Bikeshed::Colour::Blue - StringRef extractInstanceName(StringRef enumInstance) { - // Find last occurrence of ":" - size_t name_start = enumInstance.size(); - while (name_start > 0 && enumInstance[name_start - 1] != ':') { - --name_start; - } - return enumInstance.substr(name_start, enumInstance.size() - name_start); - } - } - - std::vector<StringRef> parseEnums( StringRef enums ) { - auto enumValues = splitStringRef( enums, ',' ); - std::vector<StringRef> parsed; - parsed.reserve( enumValues.size() ); - for( auto const& enumValue : enumValues ) { - parsed.push_back(trim(extractInstanceName(enumValue))); - } - return parsed; - } - - EnumInfo::~EnumInfo() {} - - StringRef EnumInfo::lookup( int value ) const { - for( auto const& valueToName : m_values ) { - if( valueToName.first == value ) - return valueToName.second; - } - return "{** unexpected enum value **}"_sr; - } - - std::unique_ptr<EnumInfo> makeEnumInfo( StringRef enumName, StringRef allValueNames, std::vector<int> const& values ) { - std::unique_ptr<EnumInfo> enumInfo( new EnumInfo ); - enumInfo->m_name = enumName; - enumInfo->m_values.reserve( values.size() ); - - const auto valueNames = Catch::Detail::parseEnums( allValueNames ); - assert( valueNames.size() == values.size() ); - std::size_t i = 0; - for( auto value : values ) - enumInfo->m_values.emplace_back(value, valueNames[i++]); - - return enumInfo; - } - - EnumInfo const& EnumValuesRegistry::registerEnum( StringRef enumName, StringRef allValueNames, std::vector<int> const& values ) { - m_enumInfos.push_back(makeEnumInfo(enumName, allValueNames, values)); - return *m_enumInfos.back(); - } - - } // Detail -} // Catch - -// end catch_enum_values_registry.cpp -// start catch_errno_guard.cpp - -#include <cerrno> - -namespace Catch { - ErrnoGuard::ErrnoGuard():m_oldErrno(errno){} - ErrnoGuard::~ErrnoGuard() { errno = m_oldErrno; } -} -// end catch_errno_guard.cpp -// start catch_exception_translator_registry.cpp - -// start catch_exception_translator_registry.h - -#include <vector> -#include <string> -#include <memory> - -namespace Catch { - - class ExceptionTranslatorRegistry : public IExceptionTranslatorRegistry { - public: - ~ExceptionTranslatorRegistry(); - virtual void registerTranslator( const IExceptionTranslator* translator ); - std::string translateActiveException() const override; - std::string tryTranslators() const; - - private: - std::vector<std::unique_ptr<IExceptionTranslator const>> m_translators; - }; -} - -// end catch_exception_translator_registry.h -#ifdef __OBJC__ -#import "Foundation/Foundation.h" -#endif - -namespace Catch { - - ExceptionTranslatorRegistry::~ExceptionTranslatorRegistry() { - } - - void ExceptionTranslatorRegistry::registerTranslator( const IExceptionTranslator* translator ) { - m_translators.push_back( std::unique_ptr<const IExceptionTranslator>( translator ) ); - } - -#if !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS) - std::string ExceptionTranslatorRegistry::translateActiveException() const { - try { -#ifdef __OBJC__ - // In Objective-C try objective-c exceptions first - @try { - return tryTranslators(); - } - @catch (NSException *exception) { - return Catch::Detail::stringify( [exception description] ); - } -#else - // Compiling a mixed mode project with MSVC means that CLR - // exceptions will be caught in (...) as well. However, these - // do not fill-in std::current_exception and thus lead to crash - // when attempting rethrow. - // /EHa switch also causes structured exceptions to be caught - // here, but they fill-in current_exception properly, so - // at worst the output should be a little weird, instead of - // causing a crash. - if (std::current_exception() == nullptr) { - return "Non C++ exception. Possibly a CLR exception."; - } - return tryTranslators(); -#endif - } - catch( TestFailureException& ) { - std::rethrow_exception(std::current_exception()); - } - catch( std::exception& ex ) { - return ex.what(); - } - catch( std::string& msg ) { - return msg; - } - catch( const char* msg ) { - return msg; - } - catch(...) { - return "Unknown exception"; - } - } - - std::string ExceptionTranslatorRegistry::tryTranslators() const { - if (m_translators.empty()) { - std::rethrow_exception(std::current_exception()); - } else { - return m_translators[0]->translate(m_translators.begin() + 1, m_translators.end()); - } - } - -#else // ^^ Exceptions are enabled // Exceptions are disabled vv - std::string ExceptionTranslatorRegistry::translateActiveException() const { - CATCH_INTERNAL_ERROR("Attempted to translate active exception under CATCH_CONFIG_DISABLE_EXCEPTIONS!"); - } - - std::string ExceptionTranslatorRegistry::tryTranslators() const { - CATCH_INTERNAL_ERROR("Attempted to use exception translators under CATCH_CONFIG_DISABLE_EXCEPTIONS!"); - } -#endif - -} -// end catch_exception_translator_registry.cpp -// start catch_fatal_condition.cpp - -#if defined(__GNUC__) -# pragma GCC diagnostic push -# pragma GCC diagnostic ignored "-Wmissing-field-initializers" -#endif - -#if defined( CATCH_CONFIG_WINDOWS_SEH ) || defined( CATCH_CONFIG_POSIX_SIGNALS ) - -namespace { - // Report the error condition - void reportFatal( char const * const message ) { - Catch::getCurrentContext().getResultCapture()->handleFatalErrorCondition( message ); - } -} - -#endif // signals/SEH handling - -#if defined( CATCH_CONFIG_WINDOWS_SEH ) - -namespace Catch { - struct SignalDefs { DWORD id; const char* name; }; - - // There is no 1-1 mapping between signals and windows exceptions. - // Windows can easily distinguish between SO and SigSegV, - // but SigInt, SigTerm, etc are handled differently. - static SignalDefs signalDefs[] = { - { static_cast<DWORD>(EXCEPTION_ILLEGAL_INSTRUCTION), "SIGILL - Illegal instruction signal" }, - { static_cast<DWORD>(EXCEPTION_STACK_OVERFLOW), "SIGSEGV - Stack overflow" }, - { static_cast<DWORD>(EXCEPTION_ACCESS_VIOLATION), "SIGSEGV - Segmentation violation signal" }, - { static_cast<DWORD>(EXCEPTION_INT_DIVIDE_BY_ZERO), "Divide by zero error" }, - }; - - LONG CALLBACK FatalConditionHandler::handleVectoredException(PEXCEPTION_POINTERS ExceptionInfo) { - for (auto const& def : signalDefs) { - if (ExceptionInfo->ExceptionRecord->ExceptionCode == def.id) { - reportFatal(def.name); - } - } - // If its not an exception we care about, pass it along. - // This stops us from eating debugger breaks etc. - return EXCEPTION_CONTINUE_SEARCH; - } - - FatalConditionHandler::FatalConditionHandler() { - isSet = true; - // 32k seems enough for Catch to handle stack overflow, - // but the value was found experimentally, so there is no strong guarantee - guaranteeSize = 32 * 1024; - exceptionHandlerHandle = nullptr; - // Register as first handler in current chain - exceptionHandlerHandle = AddVectoredExceptionHandler(1, handleVectoredException); - // Pass in guarantee size to be filled - SetThreadStackGuarantee(&guaranteeSize); - } - - void FatalConditionHandler::reset() { - if (isSet) { - RemoveVectoredExceptionHandler(exceptionHandlerHandle); - SetThreadStackGuarantee(&guaranteeSize); - exceptionHandlerHandle = nullptr; - isSet = false; - } - } - - FatalConditionHandler::~FatalConditionHandler() { - reset(); - } - -bool FatalConditionHandler::isSet = false; -ULONG FatalConditionHandler::guaranteeSize = 0; -PVOID FatalConditionHandler::exceptionHandlerHandle = nullptr; - -} // namespace Catch - -#elif defined( CATCH_CONFIG_POSIX_SIGNALS ) - -namespace Catch { - - struct SignalDefs { - int id; - const char* name; - }; - - // 32kb for the alternate stack seems to be sufficient. However, this value - // is experimentally determined, so that's not guaranteed. - static constexpr std::size_t sigStackSize = 32768 >= MINSIGSTKSZ ? 32768 : MINSIGSTKSZ; - - static SignalDefs signalDefs[] = { - { SIGINT, "SIGINT - Terminal interrupt signal" }, - { SIGILL, "SIGILL - Illegal instruction signal" }, - { SIGFPE, "SIGFPE - Floating point error signal" }, - { SIGSEGV, "SIGSEGV - Segmentation violation signal" }, - { SIGTERM, "SIGTERM - Termination request signal" }, - { SIGABRT, "SIGABRT - Abort (abnormal termination) signal" } - }; - - void FatalConditionHandler::handleSignal( int sig ) { - char const * name = "<unknown signal>"; - for (auto const& def : signalDefs) { - if (sig == def.id) { - name = def.name; - break; - } - } - reset(); - reportFatal(name); - raise( sig ); - } - - FatalConditionHandler::FatalConditionHandler() { - isSet = true; - stack_t sigStack; - sigStack.ss_sp = altStackMem; - sigStack.ss_size = sigStackSize; - sigStack.ss_flags = 0; - sigaltstack(&sigStack, &oldSigStack); - struct sigaction sa = { }; - - sa.sa_handler = handleSignal; - sa.sa_flags = SA_ONSTACK; - for (std::size_t i = 0; i < sizeof(signalDefs)/sizeof(SignalDefs); ++i) { - sigaction(signalDefs[i].id, &sa, &oldSigActions[i]); - } - } - - FatalConditionHandler::~FatalConditionHandler() { - reset(); - } - - void FatalConditionHandler::reset() { - if( isSet ) { - // Set signals back to previous values -- hopefully nobody overwrote them in the meantime - for( std::size_t i = 0; i < sizeof(signalDefs)/sizeof(SignalDefs); ++i ) { - sigaction(signalDefs[i].id, &oldSigActions[i], nullptr); - } - // Return the old stack - sigaltstack(&oldSigStack, nullptr); - isSet = false; - } - } - - bool FatalConditionHandler::isSet = false; - struct sigaction FatalConditionHandler::oldSigActions[sizeof(signalDefs)/sizeof(SignalDefs)] = {}; - stack_t FatalConditionHandler::oldSigStack = {}; - char FatalConditionHandler::altStackMem[sigStackSize] = {}; - -} // namespace Catch - -#else - -namespace Catch { - void FatalConditionHandler::reset() {} -} - -#endif // signals/SEH handling - -#if defined(__GNUC__) -# pragma GCC diagnostic pop -#endif -// end catch_fatal_condition.cpp -// start catch_generators.cpp - -#include <limits> -#include <set> - -namespace Catch { - -IGeneratorTracker::~IGeneratorTracker() {} - -const char* GeneratorException::what() const noexcept { - return m_msg; -} - -namespace Generators { - - GeneratorUntypedBase::~GeneratorUntypedBase() {} - - auto acquireGeneratorTracker( SourceLineInfo const& lineInfo ) -> IGeneratorTracker& { - return getResultCapture().acquireGeneratorTracker( lineInfo ); - } - -} // namespace Generators -} // namespace Catch -// end catch_generators.cpp -// start catch_interfaces_capture.cpp - -namespace Catch { - IResultCapture::~IResultCapture() = default; -} -// end catch_interfaces_capture.cpp -// start catch_interfaces_config.cpp - -namespace Catch { - IConfig::~IConfig() = default; -} -// end catch_interfaces_config.cpp -// start catch_interfaces_exception.cpp - -namespace Catch { - IExceptionTranslator::~IExceptionTranslator() = default; - IExceptionTranslatorRegistry::~IExceptionTranslatorRegistry() = default; -} -// end catch_interfaces_exception.cpp -// start catch_interfaces_registry_hub.cpp - -namespace Catch { - IRegistryHub::~IRegistryHub() = default; - IMutableRegistryHub::~IMutableRegistryHub() = default; -} -// end catch_interfaces_registry_hub.cpp -// start catch_interfaces_reporter.cpp - -// start catch_reporter_listening.h - -namespace Catch { - - class ListeningReporter : public IStreamingReporter { - using Reporters = std::vector<IStreamingReporterPtr>; - Reporters m_listeners; - IStreamingReporterPtr m_reporter = nullptr; - ReporterPreferences m_preferences; - - public: - ListeningReporter(); - - void addListener( IStreamingReporterPtr&& listener ); - void addReporter( IStreamingReporterPtr&& reporter ); - - public: // IStreamingReporter - - ReporterPreferences getPreferences() const override; - - void noMatchingTestCases( std::string const& spec ) override; - - void reportInvalidArguments(std::string const&arg) override; - - static std::set<Verbosity> getSupportedVerbosities(); - -#if defined(CATCH_CONFIG_ENABLE_BENCHMARKING) - void benchmarkPreparing(std::string const& name) override; - void benchmarkStarting( BenchmarkInfo const& benchmarkInfo ) override; - void benchmarkEnded( BenchmarkStats<> const& benchmarkStats ) override; - void benchmarkFailed(std::string const&) override; -#endif // CATCH_CONFIG_ENABLE_BENCHMARKING - - void testRunStarting( TestRunInfo const& testRunInfo ) override; - void testGroupStarting( GroupInfo const& groupInfo ) override; - void testCaseStarting( TestCaseInfo const& testInfo ) override; - void sectionStarting( SectionInfo const& sectionInfo ) override; - void assertionStarting( AssertionInfo const& assertionInfo ) override; - - // The return value indicates if the messages buffer should be cleared: - bool assertionEnded( AssertionStats const& assertionStats ) override; - void sectionEnded( SectionStats const& sectionStats ) override; - void testCaseEnded( TestCaseStats const& testCaseStats ) override; - void testGroupEnded( TestGroupStats const& testGroupStats ) override; - void testRunEnded( TestRunStats const& testRunStats ) override; - - void skipTest( TestCaseInfo const& testInfo ) override; - bool isMulti() const override; - - }; - -} // end namespace Catch - -// end catch_reporter_listening.h -namespace Catch { - - ReporterConfig::ReporterConfig( IConfigPtr const& _fullConfig ) - : m_stream( &_fullConfig->stream() ), m_fullConfig( _fullConfig ) {} - - ReporterConfig::ReporterConfig( IConfigPtr const& _fullConfig, std::ostream& _stream ) - : m_stream( &_stream ), m_fullConfig( _fullConfig ) {} - - std::ostream& ReporterConfig::stream() const { return *m_stream; } - IConfigPtr ReporterConfig::fullConfig() const { return m_fullConfig; } - - TestRunInfo::TestRunInfo( std::string const& _name ) : name( _name ) {} - - GroupInfo::GroupInfo( std::string const& _name, - std::size_t _groupIndex, - std::size_t _groupsCount ) - : name( _name ), - groupIndex( _groupIndex ), - groupsCounts( _groupsCount ) - {} - - AssertionStats::AssertionStats( AssertionResult const& _assertionResult, - std::vector<MessageInfo> const& _infoMessages, - Totals const& _totals ) - : assertionResult( _assertionResult ), - infoMessages( _infoMessages ), - totals( _totals ) - { - assertionResult.m_resultData.lazyExpression.m_transientExpression = _assertionResult.m_resultData.lazyExpression.m_transientExpression; - - if( assertionResult.hasMessage() ) { - // Copy message into messages list. - // !TBD This should have been done earlier, somewhere - MessageBuilder builder( assertionResult.getTestMacroName(), assertionResult.getSourceInfo(), assertionResult.getResultType() ); - builder << assertionResult.getMessage(); - builder.m_info.message = builder.m_stream.str(); - - infoMessages.push_back( builder.m_info ); - } - } - - AssertionStats::~AssertionStats() = default; - - SectionStats::SectionStats( SectionInfo const& _sectionInfo, - Counts const& _assertions, - double _durationInSeconds, - bool _missingAssertions ) - : sectionInfo( _sectionInfo ), - assertions( _assertions ), - durationInSeconds( _durationInSeconds ), - missingAssertions( _missingAssertions ) - {} - - SectionStats::~SectionStats() = default; - - TestCaseStats::TestCaseStats( TestCaseInfo const& _testInfo, - Totals const& _totals, - std::string const& _stdOut, - std::string const& _stdErr, - bool _aborting ) - : testInfo( _testInfo ), - totals( _totals ), - stdOut( _stdOut ), - stdErr( _stdErr ), - aborting( _aborting ) - {} - - TestCaseStats::~TestCaseStats() = default; - - TestGroupStats::TestGroupStats( GroupInfo const& _groupInfo, - Totals const& _totals, - bool _aborting ) - : groupInfo( _groupInfo ), - totals( _totals ), - aborting( _aborting ) - {} - - TestGroupStats::TestGroupStats( GroupInfo const& _groupInfo ) - : groupInfo( _groupInfo ), - aborting( false ) - {} - - TestGroupStats::~TestGroupStats() = default; - - TestRunStats::TestRunStats( TestRunInfo const& _runInfo, - Totals const& _totals, - bool _aborting ) - : runInfo( _runInfo ), - totals( _totals ), - aborting( _aborting ) - {} - - TestRunStats::~TestRunStats() = default; - - void IStreamingReporter::fatalErrorEncountered( StringRef ) {} - bool IStreamingReporter::isMulti() const { return false; } - - IReporterFactory::~IReporterFactory() = default; - IReporterRegistry::~IReporterRegistry() = default; - -} // end namespace Catch -// end catch_interfaces_reporter.cpp -// start catch_interfaces_runner.cpp - -namespace Catch { - IRunner::~IRunner() = default; -} -// end catch_interfaces_runner.cpp -// start catch_interfaces_testcase.cpp - -namespace Catch { - ITestInvoker::~ITestInvoker() = default; - ITestCaseRegistry::~ITestCaseRegistry() = default; -} -// end catch_interfaces_testcase.cpp -// start catch_leak_detector.cpp - -#ifdef CATCH_CONFIG_WINDOWS_CRTDBG -#include <crtdbg.h> - -namespace Catch { - - LeakDetector::LeakDetector() { - int flag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG); - flag |= _CRTDBG_LEAK_CHECK_DF; - flag |= _CRTDBG_ALLOC_MEM_DF; - _CrtSetDbgFlag(flag); - _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG); - _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR); - // Change this to leaking allocation's number to break there - _CrtSetBreakAlloc(-1); - } -} - -#else - - Catch::LeakDetector::LeakDetector() {} - -#endif - -Catch::LeakDetector::~LeakDetector() { - Catch::cleanUp(); -} -// end catch_leak_detector.cpp -// start catch_list.cpp - -// start catch_list.h - -#include <set> - -namespace Catch { - - std::size_t listTests( Config const& config ); - - std::size_t listTestsNamesOnly( Config const& config ); - - struct TagInfo { - void add( std::string const& spelling ); - std::string all() const; - - std::set<std::string> spellings; - std::size_t count = 0; - }; - - std::size_t listTags( Config const& config ); - - std::size_t listReporters(); - - Option<std::size_t> list( std::shared_ptr<Config> const& config ); - -} // end namespace Catch - -// end catch_list.h -// start catch_text.h - -namespace Catch { - using namespace clara::TextFlow; -} - -// end catch_text.h -#include <limits> -#include <algorithm> -#include <iomanip> - -namespace Catch { - - std::size_t listTests( Config const& config ) { - TestSpec const& testSpec = config.testSpec(); - if( config.hasTestFilters() ) - Catch::cout() << "Matching test cases:\n"; - else { - Catch::cout() << "All available test cases:\n"; - } - - auto matchedTestCases = filterTests( getAllTestCasesSorted( config ), testSpec, config ); - for( auto const& testCaseInfo : matchedTestCases ) { - Colour::Code colour = testCaseInfo.isHidden() - ? Colour::SecondaryText - : Colour::None; - Colour colourGuard( colour ); - - Catch::cout() << Column( testCaseInfo.name ).initialIndent( 2 ).indent( 4 ) << "\n"; - if( config.verbosity() >= Verbosity::High ) { - Catch::cout() << Column( Catch::Detail::stringify( testCaseInfo.lineInfo ) ).indent(4) << std::endl; - std::string description = testCaseInfo.description; - if( description.empty() ) - description = "(NO DESCRIPTION)"; - Catch::cout() << Column( description ).indent(4) << std::endl; - } - if( !testCaseInfo.tags.empty() ) - Catch::cout() << Column( testCaseInfo.tagsAsString() ).indent( 6 ) << "\n"; - } - - if( !config.hasTestFilters() ) - Catch::cout() << pluralise( matchedTestCases.size(), "test case" ) << '\n' << std::endl; - else - Catch::cout() << pluralise( matchedTestCases.size(), "matching test case" ) << '\n' << std::endl; - return matchedTestCases.size(); - } - - std::size_t listTestsNamesOnly( Config const& config ) { - TestSpec const& testSpec = config.testSpec(); - std::size_t matchedTests = 0; - std::vector<TestCase> matchedTestCases = filterTests( getAllTestCasesSorted( config ), testSpec, config ); - for( auto const& testCaseInfo : matchedTestCases ) { - matchedTests++; - if( startsWith( testCaseInfo.name, '#' ) ) - Catch::cout() << '"' << testCaseInfo.name << '"'; - else - Catch::cout() << testCaseInfo.name; - if ( config.verbosity() >= Verbosity::High ) - Catch::cout() << "\t@" << testCaseInfo.lineInfo; - Catch::cout() << std::endl; - } - return matchedTests; - } - - void TagInfo::add( std::string const& spelling ) { - ++count; - spellings.insert( spelling ); - } - - std::string TagInfo::all() const { - size_t size = 0; - for (auto const& spelling : spellings) { - // Add 2 for the brackes - size += spelling.size() + 2; - } - - std::string out; out.reserve(size); - for (auto const& spelling : spellings) { - out += '['; - out += spelling; - out += ']'; - } - return out; - } - - std::size_t listTags( Config const& config ) { - TestSpec const& testSpec = config.testSpec(); - if( config.hasTestFilters() ) - Catch::cout() << "Tags for matching test cases:\n"; - else { - Catch::cout() << "All available tags:\n"; - } - - std::map<std::string, TagInfo> tagCounts; - - std::vector<TestCase> matchedTestCases = filterTests( getAllTestCasesSorted( config ), testSpec, config ); - for( auto const& testCase : matchedTestCases ) { - for( auto const& tagName : testCase.getTestCaseInfo().tags ) { - std::string lcaseTagName = toLower( tagName ); - auto countIt = tagCounts.find( lcaseTagName ); - if( countIt == tagCounts.end() ) - countIt = tagCounts.insert( std::make_pair( lcaseTagName, TagInfo() ) ).first; - countIt->second.add( tagName ); - } - } - - for( auto const& tagCount : tagCounts ) { - ReusableStringStream rss; - rss << " " << std::setw(2) << tagCount.second.count << " "; - auto str = rss.str(); - auto wrapper = Column( tagCount.second.all() ) - .initialIndent( 0 ) - .indent( str.size() ) - .width( CATCH_CONFIG_CONSOLE_WIDTH-10 ); - Catch::cout() << str << wrapper << '\n'; - } - Catch::cout() << pluralise( tagCounts.size(), "tag" ) << '\n' << std::endl; - return tagCounts.size(); - } - - std::size_t listReporters() { - Catch::cout() << "Available reporters:\n"; - IReporterRegistry::FactoryMap const& factories = getRegistryHub().getReporterRegistry().getFactories(); - std::size_t maxNameLen = 0; - for( auto const& factoryKvp : factories ) - maxNameLen = (std::max)( maxNameLen, factoryKvp.first.size() ); - - for( auto const& factoryKvp : factories ) { - Catch::cout() - << Column( factoryKvp.first + ":" ) - .indent(2) - .width( 5+maxNameLen ) - + Column( factoryKvp.second->getDescription() ) - .initialIndent(0) - .indent(2) - .width( CATCH_CONFIG_CONSOLE_WIDTH - maxNameLen-8 ) - << "\n"; - } - Catch::cout() << std::endl; - return factories.size(); - } - - Option<std::size_t> list( std::shared_ptr<Config> const& config ) { - Option<std::size_t> listedCount; - getCurrentMutableContext().setConfig( config ); - if( config->listTests() ) - listedCount = listedCount.valueOr(0) + listTests( *config ); - if( config->listTestNamesOnly() ) - listedCount = listedCount.valueOr(0) + listTestsNamesOnly( *config ); - if( config->listTags() ) - listedCount = listedCount.valueOr(0) + listTags( *config ); - if( config->listReporters() ) - listedCount = listedCount.valueOr(0) + listReporters(); - return listedCount; - } - -} // end namespace Catch -// end catch_list.cpp -// start catch_matchers.cpp - -namespace Catch { -namespace Matchers { - namespace Impl { - - std::string MatcherUntypedBase::toString() const { - if( m_cachedToString.empty() ) - m_cachedToString = describe(); - return m_cachedToString; - } - - MatcherUntypedBase::~MatcherUntypedBase() = default; - - } // namespace Impl -} // namespace Matchers - -using namespace Matchers; -using Matchers::Impl::MatcherBase; - -} // namespace Catch -// end catch_matchers.cpp -// start catch_matchers_exception.cpp - -namespace Catch { -namespace Matchers { -namespace Exception { - -bool ExceptionMessageMatcher::match(std::exception const& ex) const { - return ex.what() == m_message; -} - -std::string ExceptionMessageMatcher::describe() const { - return "exception message matches \"" + m_message + "\""; -} - -} -Exception::ExceptionMessageMatcher Message(std::string const& message) { - return Exception::ExceptionMessageMatcher(message); -} - -// namespace Exception -} // namespace Matchers -} // namespace Catch -// end catch_matchers_exception.cpp -// start catch_matchers_floating.cpp - -// start catch_polyfills.hpp - -namespace Catch { - bool isnan(float f); - bool isnan(double d); -} - -// end catch_polyfills.hpp -// start catch_to_string.hpp - -#include <string> - -namespace Catch { - template <typename T> - std::string to_string(T const& t) { -#if defined(CATCH_CONFIG_CPP11_TO_STRING) - return std::to_string(t); -#else - ReusableStringStream rss; - rss << t; - return rss.str(); -#endif - } -} // end namespace Catch - -// end catch_to_string.hpp -#include <algorithm> -#include <cmath> -#include <cstdlib> -#include <cstdint> -#include <cstring> -#include <sstream> -#include <type_traits> -#include <iomanip> -#include <limits> - -namespace Catch { -namespace { - - int32_t convert(float f) { - static_assert(sizeof(float) == sizeof(int32_t), "Important ULP matcher assumption violated"); - int32_t i; - std::memcpy(&i, &f, sizeof(f)); - return i; - } - - int64_t convert(double d) { - static_assert(sizeof(double) == sizeof(int64_t), "Important ULP matcher assumption violated"); - int64_t i; - std::memcpy(&i, &d, sizeof(d)); - return i; - } - - template <typename FP> - bool almostEqualUlps(FP lhs, FP rhs, uint64_t maxUlpDiff) { - // Comparison with NaN should always be false. - // This way we can rule it out before getting into the ugly details - if (Catch::isnan(lhs) || Catch::isnan(rhs)) { - return false; - } - - auto lc = convert(lhs); - auto rc = convert(rhs); - - if ((lc < 0) != (rc < 0)) { - // Potentially we can have +0 and -0 - return lhs == rhs; - } - - auto ulpDiff = std::abs(lc - rc); - return static_cast<uint64_t>(ulpDiff) <= maxUlpDiff; - } - -#if defined(CATCH_CONFIG_GLOBAL_NEXTAFTER) - - float nextafter(float x, float y) { - return ::nextafterf(x, y); - } - - double nextafter(double x, double y) { - return ::nextafter(x, y); - } - -#endif // ^^^ CATCH_CONFIG_GLOBAL_NEXTAFTER ^^^ - -template <typename FP> -FP step(FP start, FP direction, uint64_t steps) { - for (uint64_t i = 0; i < steps; ++i) { -#if defined(CATCH_CONFIG_GLOBAL_NEXTAFTER) - start = Catch::nextafter(start, direction); -#else - start = std::nextafter(start, direction); -#endif - } - return start; -} - -// Performs equivalent check of std::fabs(lhs - rhs) <= margin -// But without the subtraction to allow for INFINITY in comparison -bool marginComparison(double lhs, double rhs, double margin) { - return (lhs + margin >= rhs) && (rhs + margin >= lhs); -} - -template <typename FloatingPoint> -void write(std::ostream& out, FloatingPoint num) { - out << std::scientific - << std::setprecision(std::numeric_limits<FloatingPoint>::max_digits10 - 1) - << num; -} - -} // end anonymous namespace - -namespace Matchers { -namespace Floating { - - enum class FloatingPointKind : uint8_t { - Float, - Double - }; - - WithinAbsMatcher::WithinAbsMatcher(double target, double margin) - :m_target{ target }, m_margin{ margin } { - CATCH_ENFORCE(margin >= 0, "Invalid margin: " << margin << '.' - << " Margin has to be non-negative."); - } - - // Performs equivalent check of std::fabs(lhs - rhs) <= margin - // But without the subtraction to allow for INFINITY in comparison - bool WithinAbsMatcher::match(double const& matchee) const { - return (matchee + m_margin >= m_target) && (m_target + m_margin >= matchee); - } - - std::string WithinAbsMatcher::describe() const { - return "is within " + ::Catch::Detail::stringify(m_margin) + " of " + ::Catch::Detail::stringify(m_target); - } - - WithinUlpsMatcher::WithinUlpsMatcher(double target, uint64_t ulps, FloatingPointKind baseType) - :m_target{ target }, m_ulps{ ulps }, m_type{ baseType } { - CATCH_ENFORCE(m_type == FloatingPointKind::Double - || m_ulps < (std::numeric_limits<uint32_t>::max)(), - "Provided ULP is impossibly large for a float comparison."); - } - -#if defined(__clang__) -#pragma clang diagnostic push -// Clang <3.5 reports on the default branch in the switch below -#pragma clang diagnostic ignored "-Wunreachable-code" -#endif - - bool WithinUlpsMatcher::match(double const& matchee) const { - switch (m_type) { - case FloatingPointKind::Float: - return almostEqualUlps<float>(static_cast<float>(matchee), static_cast<float>(m_target), m_ulps); - case FloatingPointKind::Double: - return almostEqualUlps<double>(matchee, m_target, m_ulps); - default: - CATCH_INTERNAL_ERROR( "Unknown FloatingPointKind value" ); - } - } - -#if defined(__clang__) -#pragma clang diagnostic pop -#endif - - std::string WithinUlpsMatcher::describe() const { - std::stringstream ret; - - ret << "is within " << m_ulps << " ULPs of "; - - if (m_type == FloatingPointKind::Float) { - write(ret, static_cast<float>(m_target)); - ret << 'f'; - } else { - write(ret, m_target); - } - - ret << " (["; - if (m_type == FloatingPointKind::Double) { - write(ret, step(m_target, static_cast<double>(-INFINITY), m_ulps)); - ret << ", "; - write(ret, step(m_target, static_cast<double>( INFINITY), m_ulps)); - } else { - // We have to cast INFINITY to float because of MinGW, see #1782 - write(ret, step(static_cast<float>(m_target), static_cast<float>(-INFINITY), m_ulps)); - ret << ", "; - write(ret, step(static_cast<float>(m_target), static_cast<float>( INFINITY), m_ulps)); - } - ret << "])"; - - return ret.str(); - } - - WithinRelMatcher::WithinRelMatcher(double target, double epsilon): - m_target(target), - m_epsilon(epsilon){ - CATCH_ENFORCE(m_epsilon >= 0., "Relative comparison with epsilon < 0 does not make sense."); - CATCH_ENFORCE(m_epsilon < 1., "Relative comparison with epsilon >= 1 does not make sense."); - } - - bool WithinRelMatcher::match(double const& matchee) const { - const auto relMargin = m_epsilon * (std::max)(std::fabs(matchee), std::fabs(m_target)); - return marginComparison(matchee, m_target, - std::isinf(relMargin)? 0 : relMargin); - } - - std::string WithinRelMatcher::describe() const { - Catch::ReusableStringStream sstr; - sstr << "and " << m_target << " are within " << m_epsilon * 100. << "% of each other"; - return sstr.str(); - } - -}// namespace Floating - -Floating::WithinUlpsMatcher WithinULP(double target, uint64_t maxUlpDiff) { - return Floating::WithinUlpsMatcher(target, maxUlpDiff, Floating::FloatingPointKind::Double); -} - -Floating::WithinUlpsMatcher WithinULP(float target, uint64_t maxUlpDiff) { - return Floating::WithinUlpsMatcher(target, maxUlpDiff, Floating::FloatingPointKind::Float); -} - -Floating::WithinAbsMatcher WithinAbs(double target, double margin) { - return Floating::WithinAbsMatcher(target, margin); -} - -Floating::WithinRelMatcher WithinRel(double target, double eps) { - return Floating::WithinRelMatcher(target, eps); -} - -Floating::WithinRelMatcher WithinRel(double target) { - return Floating::WithinRelMatcher(target, std::numeric_limits<double>::epsilon() * 100); -} - -Floating::WithinRelMatcher WithinRel(float target, float eps) { - return Floating::WithinRelMatcher(target, eps); -} - -Floating::WithinRelMatcher WithinRel(float target) { - return Floating::WithinRelMatcher(target, std::numeric_limits<float>::epsilon() * 100); -} - -} // namespace Matchers -} // namespace Catch - -// end catch_matchers_floating.cpp -// start catch_matchers_generic.cpp - -std::string Catch::Matchers::Generic::Detail::finalizeDescription(const std::string& desc) { - if (desc.empty()) { - return "matches undescribed predicate"; - } else { - return "matches predicate: \"" + desc + '"'; - } -} -// end catch_matchers_generic.cpp -// start catch_matchers_string.cpp - -#include <regex> - -namespace Catch { -namespace Matchers { - - namespace StdString { - - CasedString::CasedString( std::string const& str, CaseSensitive::Choice caseSensitivity ) - : m_caseSensitivity( caseSensitivity ), - m_str( adjustString( str ) ) - {} - std::string CasedString::adjustString( std::string const& str ) const { - return m_caseSensitivity == CaseSensitive::No - ? toLower( str ) - : str; - } - std::string CasedString::caseSensitivitySuffix() const { - return m_caseSensitivity == CaseSensitive::No - ? " (case insensitive)" - : std::string(); - } - - StringMatcherBase::StringMatcherBase( std::string const& operation, CasedString const& comparator ) - : m_comparator( comparator ), - m_operation( operation ) { - } - - std::string StringMatcherBase::describe() const { - std::string description; - description.reserve(5 + m_operation.size() + m_comparator.m_str.size() + - m_comparator.caseSensitivitySuffix().size()); - description += m_operation; - description += ": \""; - description += m_comparator.m_str; - description += "\""; - description += m_comparator.caseSensitivitySuffix(); - return description; - } - - EqualsMatcher::EqualsMatcher( CasedString const& comparator ) : StringMatcherBase( "equals", comparator ) {} - - bool EqualsMatcher::match( std::string const& source ) const { - return m_comparator.adjustString( source ) == m_comparator.m_str; - } - - ContainsMatcher::ContainsMatcher( CasedString const& comparator ) : StringMatcherBase( "contains", comparator ) {} - - bool ContainsMatcher::match( std::string const& source ) const { - return contains( m_comparator.adjustString( source ), m_comparator.m_str ); - } - - StartsWithMatcher::StartsWithMatcher( CasedString const& comparator ) : StringMatcherBase( "starts with", comparator ) {} - - bool StartsWithMatcher::match( std::string const& source ) const { - return startsWith( m_comparator.adjustString( source ), m_comparator.m_str ); - } - - EndsWithMatcher::EndsWithMatcher( CasedString const& comparator ) : StringMatcherBase( "ends with", comparator ) {} - - bool EndsWithMatcher::match( std::string const& source ) const { - return endsWith( m_comparator.adjustString( source ), m_comparator.m_str ); - } - - RegexMatcher::RegexMatcher(std::string regex, CaseSensitive::Choice caseSensitivity): m_regex(std::move(regex)), m_caseSensitivity(caseSensitivity) {} - - bool RegexMatcher::match(std::string const& matchee) const { - auto flags = std::regex::ECMAScript; // ECMAScript is the default syntax option anyway - if (m_caseSensitivity == CaseSensitive::Choice::No) { - flags |= std::regex::icase; - } - auto reg = std::regex(m_regex, flags); - return std::regex_match(matchee, reg); - } - - std::string RegexMatcher::describe() const { - return "matches " + ::Catch::Detail::stringify(m_regex) + ((m_caseSensitivity == CaseSensitive::Choice::Yes)? " case sensitively" : " case insensitively"); - } - - } // namespace StdString - - StdString::EqualsMatcher Equals( std::string const& str, CaseSensitive::Choice caseSensitivity ) { - return StdString::EqualsMatcher( StdString::CasedString( str, caseSensitivity) ); - } - StdString::ContainsMatcher Contains( std::string const& str, CaseSensitive::Choice caseSensitivity ) { - return StdString::ContainsMatcher( StdString::CasedString( str, caseSensitivity) ); - } - StdString::EndsWithMatcher EndsWith( std::string const& str, CaseSensitive::Choice caseSensitivity ) { - return StdString::EndsWithMatcher( StdString::CasedString( str, caseSensitivity) ); - } - StdString::StartsWithMatcher StartsWith( std::string const& str, CaseSensitive::Choice caseSensitivity ) { - return StdString::StartsWithMatcher( StdString::CasedString( str, caseSensitivity) ); - } - - StdString::RegexMatcher Matches(std::string const& regex, CaseSensitive::Choice caseSensitivity) { - return StdString::RegexMatcher(regex, caseSensitivity); - } - -} // namespace Matchers -} // namespace Catch -// end catch_matchers_string.cpp -// start catch_message.cpp - -// start catch_uncaught_exceptions.h - -namespace Catch { - bool uncaught_exceptions(); -} // end namespace Catch - -// end catch_uncaught_exceptions.h -#include <cassert> -#include <stack> - -namespace Catch { - - MessageInfo::MessageInfo( StringRef const& _macroName, - SourceLineInfo const& _lineInfo, - ResultWas::OfType _type ) - : macroName( _macroName ), - lineInfo( _lineInfo ), - type( _type ), - sequence( ++globalCount ) - {} - - bool MessageInfo::operator==( MessageInfo const& other ) const { - return sequence == other.sequence; - } - - bool MessageInfo::operator<( MessageInfo const& other ) const { - return sequence < other.sequence; - } - - // This may need protecting if threading support is added - unsigned int MessageInfo::globalCount = 0; - - //////////////////////////////////////////////////////////////////////////// - - Catch::MessageBuilder::MessageBuilder( StringRef const& macroName, - SourceLineInfo const& lineInfo, - ResultWas::OfType type ) - :m_info(macroName, lineInfo, type) {} - - //////////////////////////////////////////////////////////////////////////// - - ScopedMessage::ScopedMessage( MessageBuilder const& builder ) - : m_info( builder.m_info ), m_moved() - { - m_info.message = builder.m_stream.str(); - getResultCapture().pushScopedMessage( m_info ); - } - - ScopedMessage::ScopedMessage( ScopedMessage&& old ) - : m_info( old.m_info ), m_moved() - { - old.m_moved = true; - } - - ScopedMessage::~ScopedMessage() { - if ( !uncaught_exceptions() && !m_moved ){ - getResultCapture().popScopedMessage(m_info); - } - } - - Capturer::Capturer( StringRef macroName, SourceLineInfo const& lineInfo, ResultWas::OfType resultType, StringRef names ) { - auto trimmed = [&] (size_t start, size_t end) { - while (names[start] == ',' || isspace(names[start])) { - ++start; - } - while (names[end] == ',' || isspace(names[end])) { - --end; - } - return names.substr(start, end - start + 1); - }; - auto skipq = [&] (size_t start, char quote) { - for (auto i = start + 1; i < names.size() ; ++i) { - if (names[i] == quote) - return i; - if (names[i] == '\\') - ++i; - } - CATCH_INTERNAL_ERROR("CAPTURE parsing encountered unmatched quote"); - }; - - size_t start = 0; - std::stack<char> openings; - for (size_t pos = 0; pos < names.size(); ++pos) { - char c = names[pos]; - switch (c) { - case '[': - case '{': - case '(': - // It is basically impossible to disambiguate between - // comparison and start of template args in this context -// case '<': - openings.push(c); - break; - case ']': - case '}': - case ')': -// case '>': - openings.pop(); - break; - case '"': - case '\'': - pos = skipq(pos, c); - break; - case ',': - if (start != pos && openings.empty()) { - m_messages.emplace_back(macroName, lineInfo, resultType); - m_messages.back().message = static_cast<std::string>(trimmed(start, pos)); - m_messages.back().message += " := "; - start = pos; - } - } - } - assert(openings.empty() && "Mismatched openings"); - m_messages.emplace_back(macroName, lineInfo, resultType); - m_messages.back().message = static_cast<std::string>(trimmed(start, names.size() - 1)); - m_messages.back().message += " := "; - } - Capturer::~Capturer() { - if ( !uncaught_exceptions() ){ - assert( m_captured == m_messages.size() ); - for( size_t i = 0; i < m_captured; ++i ) - m_resultCapture.popScopedMessage( m_messages[i] ); - } - } - - void Capturer::captureValue( size_t index, std::string const& value ) { - assert( index < m_messages.size() ); - m_messages[index].message += value; - m_resultCapture.pushScopedMessage( m_messages[index] ); - m_captured++; - } - -} // end namespace Catch -// end catch_message.cpp -// start catch_output_redirect.cpp - -// start catch_output_redirect.h -#ifndef TWOBLUECUBES_CATCH_OUTPUT_REDIRECT_H -#define TWOBLUECUBES_CATCH_OUTPUT_REDIRECT_H - -#include <cstdio> -#include <iosfwd> -#include <string> - -namespace Catch { - - class RedirectedStream { - std::ostream& m_originalStream; - std::ostream& m_redirectionStream; - std::streambuf* m_prevBuf; - - public: - RedirectedStream( std::ostream& originalStream, std::ostream& redirectionStream ); - ~RedirectedStream(); - }; - - class RedirectedStdOut { - ReusableStringStream m_rss; - RedirectedStream m_cout; - public: - RedirectedStdOut(); - auto str() const -> std::string; - }; - - // StdErr has two constituent streams in C++, std::cerr and std::clog - // This means that we need to redirect 2 streams into 1 to keep proper - // order of writes - class RedirectedStdErr { - ReusableStringStream m_rss; - RedirectedStream m_cerr; - RedirectedStream m_clog; - public: - RedirectedStdErr(); - auto str() const -> std::string; - }; - - class RedirectedStreams { - public: - RedirectedStreams(RedirectedStreams const&) = delete; - RedirectedStreams& operator=(RedirectedStreams const&) = delete; - RedirectedStreams(RedirectedStreams&&) = delete; - RedirectedStreams& operator=(RedirectedStreams&&) = delete; - - RedirectedStreams(std::string& redirectedCout, std::string& redirectedCerr); - ~RedirectedStreams(); - private: - std::string& m_redirectedCout; - std::string& m_redirectedCerr; - RedirectedStdOut m_redirectedStdOut; - RedirectedStdErr m_redirectedStdErr; - }; - -#if defined(CATCH_CONFIG_NEW_CAPTURE) - - // Windows's implementation of std::tmpfile is terrible (it tries - // to create a file inside system folder, thus requiring elevated - // privileges for the binary), so we have to use tmpnam(_s) and - // create the file ourselves there. - class TempFile { - public: - TempFile(TempFile const&) = delete; - TempFile& operator=(TempFile const&) = delete; - TempFile(TempFile&&) = delete; - TempFile& operator=(TempFile&&) = delete; - - TempFile(); - ~TempFile(); - - std::FILE* getFile(); - std::string getContents(); - - private: - std::FILE* m_file = nullptr; - #if defined(_MSC_VER) - char m_buffer[L_tmpnam] = { 0 }; - #endif - }; - - class OutputRedirect { - public: - OutputRedirect(OutputRedirect const&) = delete; - OutputRedirect& operator=(OutputRedirect const&) = delete; - OutputRedirect(OutputRedirect&&) = delete; - OutputRedirect& operator=(OutputRedirect&&) = delete; - - OutputRedirect(std::string& stdout_dest, std::string& stderr_dest); - ~OutputRedirect(); - - private: - int m_originalStdout = -1; - int m_originalStderr = -1; - TempFile m_stdoutFile; - TempFile m_stderrFile; - std::string& m_stdoutDest; - std::string& m_stderrDest; - }; - -#endif - -} // end namespace Catch - -#endif // TWOBLUECUBES_CATCH_OUTPUT_REDIRECT_H -// end catch_output_redirect.h -#include <cstdio> -#include <cstring> -#include <fstream> -#include <sstream> -#include <stdexcept> - -#if defined(CATCH_CONFIG_NEW_CAPTURE) - #if defined(_MSC_VER) - #include <io.h> //_dup and _dup2 - #define dup _dup - #define dup2 _dup2 - #define fileno _fileno - #else - #include <unistd.h> // dup and dup2 - #endif -#endif - -namespace Catch { - - RedirectedStream::RedirectedStream( std::ostream& originalStream, std::ostream& redirectionStream ) - : m_originalStream( originalStream ), - m_redirectionStream( redirectionStream ), - m_prevBuf( m_originalStream.rdbuf() ) - { - m_originalStream.rdbuf( m_redirectionStream.rdbuf() ); - } - - RedirectedStream::~RedirectedStream() { - m_originalStream.rdbuf( m_prevBuf ); - } - - RedirectedStdOut::RedirectedStdOut() : m_cout( Catch::cout(), m_rss.get() ) {} - auto RedirectedStdOut::str() const -> std::string { return m_rss.str(); } - - RedirectedStdErr::RedirectedStdErr() - : m_cerr( Catch::cerr(), m_rss.get() ), - m_clog( Catch::clog(), m_rss.get() ) - {} - auto RedirectedStdErr::str() const -> std::string { return m_rss.str(); } - - RedirectedStreams::RedirectedStreams(std::string& redirectedCout, std::string& redirectedCerr) - : m_redirectedCout(redirectedCout), - m_redirectedCerr(redirectedCerr) - {} - - RedirectedStreams::~RedirectedStreams() { - m_redirectedCout += m_redirectedStdOut.str(); - m_redirectedCerr += m_redirectedStdErr.str(); - } - -#if defined(CATCH_CONFIG_NEW_CAPTURE) - -#if defined(_MSC_VER) - TempFile::TempFile() { - if (tmpnam_s(m_buffer)) { - CATCH_RUNTIME_ERROR("Could not get a temp filename"); - } - if (fopen_s(&m_file, m_buffer, "w")) { - char buffer[100]; - if (strerror_s(buffer, errno)) { - CATCH_RUNTIME_ERROR("Could not translate errno to a string"); - } - CATCH_RUNTIME_ERROR("Could not open the temp file: '" << m_buffer << "' because: " << buffer); - } - } -#else - TempFile::TempFile() { - m_file = std::tmpfile(); - if (!m_file) { - CATCH_RUNTIME_ERROR("Could not create a temp file."); - } - } - -#endif - - TempFile::~TempFile() { - // TBD: What to do about errors here? - std::fclose(m_file); - // We manually create the file on Windows only, on Linux - // it will be autodeleted -#if defined(_MSC_VER) - std::remove(m_buffer); -#endif - } - - FILE* TempFile::getFile() { - return m_file; - } - - std::string TempFile::getContents() { - std::stringstream sstr; - char buffer[100] = {}; - std::rewind(m_file); - while (std::fgets(buffer, sizeof(buffer), m_file)) { - sstr << buffer; - } - return sstr.str(); - } - - OutputRedirect::OutputRedirect(std::string& stdout_dest, std::string& stderr_dest) : - m_originalStdout(dup(1)), - m_originalStderr(dup(2)), - m_stdoutDest(stdout_dest), - m_stderrDest(stderr_dest) { - dup2(fileno(m_stdoutFile.getFile()), 1); - dup2(fileno(m_stderrFile.getFile()), 2); - } - - OutputRedirect::~OutputRedirect() { - Catch::cout() << std::flush; - fflush(stdout); - // Since we support overriding these streams, we flush cerr - // even though std::cerr is unbuffered - Catch::cerr() << std::flush; - Catch::clog() << std::flush; - fflush(stderr); - - dup2(m_originalStdout, 1); - dup2(m_originalStderr, 2); - - m_stdoutDest += m_stdoutFile.getContents(); - m_stderrDest += m_stderrFile.getContents(); - } - -#endif // CATCH_CONFIG_NEW_CAPTURE - -} // namespace Catch - -#if defined(CATCH_CONFIG_NEW_CAPTURE) - #if defined(_MSC_VER) - #undef dup - #undef dup2 - #undef fileno - #endif -#endif -// end catch_output_redirect.cpp -// start catch_polyfills.cpp - -#include <cmath> - -namespace Catch { - -#if !defined(CATCH_CONFIG_POLYFILL_ISNAN) - bool isnan(float f) { - return std::isnan(f); - } - bool isnan(double d) { - return std::isnan(d); - } -#else - // For now we only use this for embarcadero - bool isnan(float f) { - return std::_isnan(f); - } - bool isnan(double d) { - return std::_isnan(d); - } -#endif - -} // end namespace Catch -// end catch_polyfills.cpp -// start catch_random_number_generator.cpp - -namespace Catch { - -namespace { - -#if defined(_MSC_VER) -#pragma warning(push) -#pragma warning(disable:4146) // we negate uint32 during the rotate -#endif - // Safe rotr implementation thanks to John Regehr - uint32_t rotate_right(uint32_t val, uint32_t count) { - const uint32_t mask = 31; - count &= mask; - return (val >> count) | (val << (-count & mask)); - } - -#if defined(_MSC_VER) -#pragma warning(pop) -#endif - -} - - SimplePcg32::SimplePcg32(result_type seed_) { - seed(seed_); - } - - void SimplePcg32::seed(result_type seed_) { - m_state = 0; - (*this)(); - m_state += seed_; - (*this)(); - } - - void SimplePcg32::discard(uint64_t skip) { - // We could implement this to run in O(log n) steps, but this - // should suffice for our use case. - for (uint64_t s = 0; s < skip; ++s) { - static_cast<void>((*this)()); - } - } - - SimplePcg32::result_type SimplePcg32::operator()() { - // prepare the output value - const uint32_t xorshifted = static_cast<uint32_t>(((m_state >> 18u) ^ m_state) >> 27u); - const auto output = rotate_right(xorshifted, m_state >> 59u); - - // advance state - m_state = m_state * 6364136223846793005ULL + s_inc; - - return output; - } - - bool operator==(SimplePcg32 const& lhs, SimplePcg32 const& rhs) { - return lhs.m_state == rhs.m_state; - } - - bool operator!=(SimplePcg32 const& lhs, SimplePcg32 const& rhs) { - return lhs.m_state != rhs.m_state; - } -} -// end catch_random_number_generator.cpp -// start catch_registry_hub.cpp - -// start catch_test_case_registry_impl.h - -#include <vector> -#include <set> -#include <algorithm> -#include <ios> - -namespace Catch { - - class TestCase; - struct IConfig; - - std::vector<TestCase> sortTests( IConfig const& config, std::vector<TestCase> const& unsortedTestCases ); - - bool isThrowSafe( TestCase const& testCase, IConfig const& config ); - bool matchTest( TestCase const& testCase, TestSpec const& testSpec, IConfig const& config ); - - void enforceNoDuplicateTestCases( std::vector<TestCase> const& functions ); - - std::vector<TestCase> filterTests( std::vector<TestCase> const& testCases, TestSpec const& testSpec, IConfig const& config ); - std::vector<TestCase> const& getAllTestCasesSorted( IConfig const& config ); - - class TestRegistry : public ITestCaseRegistry { - public: - virtual ~TestRegistry() = default; - - virtual void registerTest( TestCase const& testCase ); - - std::vector<TestCase> const& getAllTests() const override; - std::vector<TestCase> const& getAllTestsSorted( IConfig const& config ) const override; - - private: - std::vector<TestCase> m_functions; - mutable RunTests::InWhatOrder m_currentSortOrder = RunTests::InDeclarationOrder; - mutable std::vector<TestCase> m_sortedFunctions; - std::size_t m_unnamedCount = 0; - std::ios_base::Init m_ostreamInit; // Forces cout/ cerr to be initialised - }; - - /////////////////////////////////////////////////////////////////////////// - - class TestInvokerAsFunction : public ITestInvoker { - void(*m_testAsFunction)(); - public: - TestInvokerAsFunction( void(*testAsFunction)() ) noexcept; - - void invoke() const override; - }; - - std::string extractClassName( StringRef const& classOrQualifiedMethodName ); - - /////////////////////////////////////////////////////////////////////////// - -} // end namespace Catch - -// end catch_test_case_registry_impl.h -// start catch_reporter_registry.h - -#include <map> - -namespace Catch { - - class ReporterRegistry : public IReporterRegistry { - - public: - - ~ReporterRegistry() override; - - IStreamingReporterPtr create( std::string const& name, IConfigPtr const& config ) const override; - - void registerReporter( std::string const& name, IReporterFactoryPtr const& factory ); - void registerListener( IReporterFactoryPtr const& factory ); - - FactoryMap const& getFactories() const override; - Listeners const& getListeners() const override; - - private: - FactoryMap m_factories; - Listeners m_listeners; - }; -} - -// end catch_reporter_registry.h -// start catch_tag_alias_registry.h - -// start catch_tag_alias.h - -#include <string> - -namespace Catch { - - struct TagAlias { - TagAlias(std::string const& _tag, SourceLineInfo _lineInfo); - - std::string tag; - SourceLineInfo lineInfo; - }; - -} // end namespace Catch - -// end catch_tag_alias.h -#include <map> - -namespace Catch { - - class TagAliasRegistry : public ITagAliasRegistry { - public: - ~TagAliasRegistry() override; - TagAlias const* find( std::string const& alias ) const override; - std::string expandAliases( std::string const& unexpandedTestSpec ) const override; - void add( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo ); - - private: - std::map<std::string, TagAlias> m_registry; - }; - -} // end namespace Catch - -// end catch_tag_alias_registry.h -// start catch_startup_exception_registry.h - -#include <vector> -#include <exception> - -namespace Catch { - - class StartupExceptionRegistry { - public: - void add(std::exception_ptr const& exception) noexcept; - std::vector<std::exception_ptr> const& getExceptions() const noexcept; - private: - std::vector<std::exception_ptr> m_exceptions; - }; - -} // end namespace Catch - -// end catch_startup_exception_registry.h -// start catch_singletons.hpp - -namespace Catch { - - struct ISingleton { - virtual ~ISingleton(); - }; - - void addSingleton( ISingleton* singleton ); - void cleanupSingletons(); - - template<typename SingletonImplT, typename InterfaceT = SingletonImplT, typename MutableInterfaceT = InterfaceT> - class Singleton : SingletonImplT, public ISingleton { - - static auto getInternal() -> Singleton* { - static Singleton* s_instance = nullptr; - if( !s_instance ) { - s_instance = new Singleton; - addSingleton( s_instance ); - } - return s_instance; - } - - public: - static auto get() -> InterfaceT const& { - return *getInternal(); - } - static auto getMutable() -> MutableInterfaceT& { - return *getInternal(); - } - }; - -} // namespace Catch - -// end catch_singletons.hpp -namespace Catch { - - namespace { - - class RegistryHub : public IRegistryHub, public IMutableRegistryHub, - private NonCopyable { - - public: // IRegistryHub - RegistryHub() = default; - IReporterRegistry const& getReporterRegistry() const override { - return m_reporterRegistry; - } - ITestCaseRegistry const& getTestCaseRegistry() const override { - return m_testCaseRegistry; - } - IExceptionTranslatorRegistry const& getExceptionTranslatorRegistry() const override { - return m_exceptionTranslatorRegistry; - } - ITagAliasRegistry const& getTagAliasRegistry() const override { - return m_tagAliasRegistry; - } - StartupExceptionRegistry const& getStartupExceptionRegistry() const override { - return m_exceptionRegistry; - } - - public: // IMutableRegistryHub - void registerReporter( std::string const& name, IReporterFactoryPtr const& factory ) override { - m_reporterRegistry.registerReporter( name, factory ); - } - void registerListener( IReporterFactoryPtr const& factory ) override { - m_reporterRegistry.registerListener( factory ); - } - void registerTest( TestCase const& testInfo ) override { - m_testCaseRegistry.registerTest( testInfo ); - } - void registerTranslator( const IExceptionTranslator* translator ) override { - m_exceptionTranslatorRegistry.registerTranslator( translator ); - } - void registerTagAlias( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo ) override { - m_tagAliasRegistry.add( alias, tag, lineInfo ); - } - void registerStartupException() noexcept override { - m_exceptionRegistry.add(std::current_exception()); - } - IMutableEnumValuesRegistry& getMutableEnumValuesRegistry() override { - return m_enumValuesRegistry; - } - - private: - TestRegistry m_testCaseRegistry; - ReporterRegistry m_reporterRegistry; - ExceptionTranslatorRegistry m_exceptionTranslatorRegistry; - TagAliasRegistry m_tagAliasRegistry; - StartupExceptionRegistry m_exceptionRegistry; - Detail::EnumValuesRegistry m_enumValuesRegistry; - }; - } - - using RegistryHubSingleton = Singleton<RegistryHub, IRegistryHub, IMutableRegistryHub>; - - IRegistryHub const& getRegistryHub() { - return RegistryHubSingleton::get(); - } - IMutableRegistryHub& getMutableRegistryHub() { - return RegistryHubSingleton::getMutable(); - } - void cleanUp() { - cleanupSingletons(); - cleanUpContext(); - } - std::string translateActiveException() { - return getRegistryHub().getExceptionTranslatorRegistry().translateActiveException(); - } - -} // end namespace Catch -// end catch_registry_hub.cpp -// start catch_reporter_registry.cpp - -namespace Catch { - - ReporterRegistry::~ReporterRegistry() = default; - - IStreamingReporterPtr ReporterRegistry::create( std::string const& name, IConfigPtr const& config ) const { - auto it = m_factories.find( name ); - if( it == m_factories.end() ) - return nullptr; - return it->second->create( ReporterConfig( config ) ); - } - - void ReporterRegistry::registerReporter( std::string const& name, IReporterFactoryPtr const& factory ) { - m_factories.emplace(name, factory); - } - void ReporterRegistry::registerListener( IReporterFactoryPtr const& factory ) { - m_listeners.push_back( factory ); - } - - IReporterRegistry::FactoryMap const& ReporterRegistry::getFactories() const { - return m_factories; - } - IReporterRegistry::Listeners const& ReporterRegistry::getListeners() const { - return m_listeners; - } - -} -// end catch_reporter_registry.cpp -// start catch_result_type.cpp - -namespace Catch { - - bool isOk( ResultWas::OfType resultType ) { - return ( resultType & ResultWas::FailureBit ) == 0; - } - bool isJustInfo( int flags ) { - return flags == ResultWas::Info; - } - - ResultDisposition::Flags operator | ( ResultDisposition::Flags lhs, ResultDisposition::Flags rhs ) { - return static_cast<ResultDisposition::Flags>( static_cast<int>( lhs ) | static_cast<int>( rhs ) ); - } - - bool shouldContinueOnFailure( int flags ) { return ( flags & ResultDisposition::ContinueOnFailure ) != 0; } - bool shouldSuppressFailure( int flags ) { return ( flags & ResultDisposition::SuppressFail ) != 0; } - -} // end namespace Catch -// end catch_result_type.cpp -// start catch_run_context.cpp - -#include <cassert> -#include <algorithm> -#include <sstream> - -namespace Catch { - - namespace Generators { - struct GeneratorTracker : TestCaseTracking::TrackerBase, IGeneratorTracker { - GeneratorBasePtr m_generator; - - GeneratorTracker( TestCaseTracking::NameAndLocation const& nameAndLocation, TrackerContext& ctx, ITracker* parent ) - : TrackerBase( nameAndLocation, ctx, parent ) - {} - ~GeneratorTracker(); - - static GeneratorTracker& acquire( TrackerContext& ctx, TestCaseTracking::NameAndLocation const& nameAndLocation ) { - std::shared_ptr<GeneratorTracker> tracker; - - ITracker& currentTracker = ctx.currentTracker(); - if( TestCaseTracking::ITrackerPtr childTracker = currentTracker.findChild( nameAndLocation ) ) { - assert( childTracker ); - assert( childTracker->isGeneratorTracker() ); - tracker = std::static_pointer_cast<GeneratorTracker>( childTracker ); - } - else { - tracker = std::make_shared<GeneratorTracker>( nameAndLocation, ctx, ¤tTracker ); - currentTracker.addChild( tracker ); - } - - if( !ctx.completedCycle() && !tracker->isComplete() ) { - tracker->open(); - } - - return *tracker; - } - - // TrackerBase interface - bool isGeneratorTracker() const override { return true; } - auto hasGenerator() const -> bool override { - return !!m_generator; - } - void close() override { - TrackerBase::close(); - // Generator interface only finds out if it has another item on atual move - if (m_runState == CompletedSuccessfully && m_generator->next()) { - m_children.clear(); - m_runState = Executing; - } - } - - // IGeneratorTracker interface - auto getGenerator() const -> GeneratorBasePtr const& override { - return m_generator; - } - void setGenerator( GeneratorBasePtr&& generator ) override { - m_generator = std::move( generator ); - } - }; - GeneratorTracker::~GeneratorTracker() {} - } - - RunContext::RunContext(IConfigPtr const& _config, IStreamingReporterPtr&& reporter) - : m_runInfo(_config->name()), - m_context(getCurrentMutableContext()), - m_config(_config), - m_reporter(std::move(reporter)), - m_lastAssertionInfo{ StringRef(), SourceLineInfo("",0), StringRef(), ResultDisposition::Normal }, - m_includeSuccessfulResults( m_config->includeSuccessfulResults() || m_reporter->getPreferences().shouldReportAllAssertions ) - { - m_context.setRunner(this); - m_context.setConfig(m_config); - m_context.setResultCapture(this); - m_reporter->testRunStarting(m_runInfo); - } - - RunContext::~RunContext() { - m_reporter->testRunEnded(TestRunStats(m_runInfo, m_totals, aborting())); - } - - void RunContext::testGroupStarting(std::string const& testSpec, std::size_t groupIndex, std::size_t groupsCount) { - m_reporter->testGroupStarting(GroupInfo(testSpec, groupIndex, groupsCount)); - } - - void RunContext::testGroupEnded(std::string const& testSpec, Totals const& totals, std::size_t groupIndex, std::size_t groupsCount) { - m_reporter->testGroupEnded(TestGroupStats(GroupInfo(testSpec, groupIndex, groupsCount), totals, aborting())); - } - - Totals RunContext::runTest(TestCase const& testCase) { - Totals prevTotals = m_totals; - - std::string redirectedCout; - std::string redirectedCerr; - - auto const& testInfo = testCase.getTestCaseInfo(); - - m_reporter->testCaseStarting(testInfo); - - m_activeTestCase = &testCase; - - ITracker& rootTracker = m_trackerContext.startRun(); - assert(rootTracker.isSectionTracker()); - static_cast<SectionTracker&>(rootTracker).addInitialFilters(m_config->getSectionsToRun()); - do { - m_trackerContext.startCycle(); - m_testCaseTracker = &SectionTracker::acquire(m_trackerContext, TestCaseTracking::NameAndLocation(testInfo.name, testInfo.lineInfo)); - runCurrentTest(redirectedCout, redirectedCerr); - } while (!m_testCaseTracker->isSuccessfullyCompleted() && !aborting()); - - Totals deltaTotals = m_totals.delta(prevTotals); - if (testInfo.expectedToFail() && deltaTotals.testCases.passed > 0) { - deltaTotals.assertions.failed++; - deltaTotals.testCases.passed--; - deltaTotals.testCases.failed++; - } - m_totals.testCases += deltaTotals.testCases; - m_reporter->testCaseEnded(TestCaseStats(testInfo, - deltaTotals, - redirectedCout, - redirectedCerr, - aborting())); - - m_activeTestCase = nullptr; - m_testCaseTracker = nullptr; - - return deltaTotals; - } - - IConfigPtr RunContext::config() const { - return m_config; - } - - IStreamingReporter& RunContext::reporter() const { - return *m_reporter; - } - - void RunContext::assertionEnded(AssertionResult const & result) { - if (result.getResultType() == ResultWas::Ok) { - m_totals.assertions.passed++; - m_lastAssertionPassed = true; - } else if (!result.isOk()) { - m_lastAssertionPassed = false; - if( m_activeTestCase->getTestCaseInfo().okToFail() ) - m_totals.assertions.failedButOk++; - else - m_totals.assertions.failed++; - } - else { - m_lastAssertionPassed = true; - } - - // We have no use for the return value (whether messages should be cleared), because messages were made scoped - // and should be let to clear themselves out. - static_cast<void>(m_reporter->assertionEnded(AssertionStats(result, m_messages, m_totals))); - - if (result.getResultType() != ResultWas::Warning) - m_messageScopes.clear(); - - // Reset working state - resetAssertionInfo(); - m_lastResult = result; - } - void RunContext::resetAssertionInfo() { - m_lastAssertionInfo.macroName = StringRef(); - m_lastAssertionInfo.capturedExpression = "{Unknown expression after the reported line}"_sr; - } - - bool RunContext::sectionStarted(SectionInfo const & sectionInfo, Counts & assertions) { - ITracker& sectionTracker = SectionTracker::acquire(m_trackerContext, TestCaseTracking::NameAndLocation(sectionInfo.name, sectionInfo.lineInfo)); - if (!sectionTracker.isOpen()) - return false; - m_activeSections.push_back(§ionTracker); - - m_lastAssertionInfo.lineInfo = sectionInfo.lineInfo; - - m_reporter->sectionStarting(sectionInfo); - - assertions = m_totals.assertions; - - return true; - } - auto RunContext::acquireGeneratorTracker( SourceLineInfo const& lineInfo ) -> IGeneratorTracker& { - using namespace Generators; - GeneratorTracker& tracker = GeneratorTracker::acquire( m_trackerContext, TestCaseTracking::NameAndLocation( "generator", lineInfo ) ); - assert( tracker.isOpen() ); - m_lastAssertionInfo.lineInfo = lineInfo; - return tracker; - } - - bool RunContext::testForMissingAssertions(Counts& assertions) { - if (assertions.total() != 0) - return false; - if (!m_config->warnAboutMissingAssertions()) - return false; - if (m_trackerContext.currentTracker().hasChildren()) - return false; - m_totals.assertions.failed++; - assertions.failed++; - return true; - } - - void RunContext::sectionEnded(SectionEndInfo const & endInfo) { - Counts assertions = m_totals.assertions - endInfo.prevAssertions; - bool missingAssertions = testForMissingAssertions(assertions); - - if (!m_activeSections.empty()) { - m_activeSections.back()->close(); - m_activeSections.pop_back(); - } - - m_reporter->sectionEnded(SectionStats(endInfo.sectionInfo, assertions, endInfo.durationInSeconds, missingAssertions)); - m_messages.clear(); - m_messageScopes.clear(); - } - - void RunContext::sectionEndedEarly(SectionEndInfo const & endInfo) { - if (m_unfinishedSections.empty()) - m_activeSections.back()->fail(); - else - m_activeSections.back()->close(); - m_activeSections.pop_back(); - - m_unfinishedSections.push_back(endInfo); - } - -#if defined(CATCH_CONFIG_ENABLE_BENCHMARKING) - void RunContext::benchmarkPreparing(std::string const& name) { - m_reporter->benchmarkPreparing(name); - } - void RunContext::benchmarkStarting( BenchmarkInfo const& info ) { - m_reporter->benchmarkStarting( info ); - } - void RunContext::benchmarkEnded( BenchmarkStats<> const& stats ) { - m_reporter->benchmarkEnded( stats ); - } - void RunContext::benchmarkFailed(std::string const & error) { - m_reporter->benchmarkFailed(error); - } -#endif // CATCH_CONFIG_ENABLE_BENCHMARKING - - void RunContext::pushScopedMessage(MessageInfo const & message) { - m_messages.push_back(message); - } - - void RunContext::popScopedMessage(MessageInfo const & message) { - m_messages.erase(std::remove(m_messages.begin(), m_messages.end(), message), m_messages.end()); - } - - void RunContext::emplaceUnscopedMessage( MessageBuilder const& builder ) { - m_messageScopes.emplace_back( builder ); - } - - std::string RunContext::getCurrentTestName() const { - return m_activeTestCase - ? m_activeTestCase->getTestCaseInfo().name - : std::string(); - } - - const AssertionResult * RunContext::getLastResult() const { - return &(*m_lastResult); - } - - void RunContext::exceptionEarlyReported() { - m_shouldReportUnexpected = false; - } - - void RunContext::handleFatalErrorCondition( StringRef message ) { - // First notify reporter that bad things happened - m_reporter->fatalErrorEncountered(message); - - // Don't rebuild the result -- the stringification itself can cause more fatal errors - // Instead, fake a result data. - AssertionResultData tempResult( ResultWas::FatalErrorCondition, { false } ); - tempResult.message = static_cast<std::string>(message); - AssertionResult result(m_lastAssertionInfo, tempResult); - - assertionEnded(result); - - handleUnfinishedSections(); - - // Recreate section for test case (as we will lose the one that was in scope) - auto const& testCaseInfo = m_activeTestCase->getTestCaseInfo(); - SectionInfo testCaseSection(testCaseInfo.lineInfo, testCaseInfo.name); - - Counts assertions; - assertions.failed = 1; - SectionStats testCaseSectionStats(testCaseSection, assertions, 0, false); - m_reporter->sectionEnded(testCaseSectionStats); - - auto const& testInfo = m_activeTestCase->getTestCaseInfo(); - - Totals deltaTotals; - deltaTotals.testCases.failed = 1; - deltaTotals.assertions.failed = 1; - m_reporter->testCaseEnded(TestCaseStats(testInfo, - deltaTotals, - std::string(), - std::string(), - false)); - m_totals.testCases.failed++; - testGroupEnded(std::string(), m_totals, 1, 1); - m_reporter->testRunEnded(TestRunStats(m_runInfo, m_totals, false)); - } - - bool RunContext::lastAssertionPassed() { - return m_lastAssertionPassed; - } - - void RunContext::assertionPassed() { - m_lastAssertionPassed = true; - ++m_totals.assertions.passed; - resetAssertionInfo(); - m_messageScopes.clear(); - } - - bool RunContext::aborting() const { - return m_totals.assertions.failed >= static_cast<std::size_t>(m_config->abortAfter()); - } - - void RunContext::runCurrentTest(std::string & redirectedCout, std::string & redirectedCerr) { - auto const& testCaseInfo = m_activeTestCase->getTestCaseInfo(); - SectionInfo testCaseSection(testCaseInfo.lineInfo, testCaseInfo.name); - m_reporter->sectionStarting(testCaseSection); - Counts prevAssertions = m_totals.assertions; - double duration = 0; - m_shouldReportUnexpected = true; - m_lastAssertionInfo = { "TEST_CASE"_sr, testCaseInfo.lineInfo, StringRef(), ResultDisposition::Normal }; - - seedRng(*m_config); - - Timer timer; - CATCH_TRY { - if (m_reporter->getPreferences().shouldRedirectStdOut) { -#if !defined(CATCH_CONFIG_EXPERIMENTAL_REDIRECT) - RedirectedStreams redirectedStreams(redirectedCout, redirectedCerr); - - timer.start(); - invokeActiveTestCase(); -#else - OutputRedirect r(redirectedCout, redirectedCerr); - timer.start(); - invokeActiveTestCase(); -#endif - } else { - timer.start(); - invokeActiveTestCase(); - } - duration = timer.getElapsedSeconds(); - } CATCH_CATCH_ANON (TestFailureException&) { - // This just means the test was aborted due to failure - } CATCH_CATCH_ALL { - // Under CATCH_CONFIG_FAST_COMPILE, unexpected exceptions under REQUIRE assertions - // are reported without translation at the point of origin. - if( m_shouldReportUnexpected ) { - AssertionReaction dummyReaction; - handleUnexpectedInflightException( m_lastAssertionInfo, translateActiveException(), dummyReaction ); - } - } - Counts assertions = m_totals.assertions - prevAssertions; - bool missingAssertions = testForMissingAssertions(assertions); - - m_testCaseTracker->close(); - handleUnfinishedSections(); - m_messages.clear(); - m_messageScopes.clear(); - - SectionStats testCaseSectionStats(testCaseSection, assertions, duration, missingAssertions); - m_reporter->sectionEnded(testCaseSectionStats); - } - - void RunContext::invokeActiveTestCase() { - FatalConditionHandler fatalConditionHandler; // Handle signals - m_activeTestCase->invoke(); - fatalConditionHandler.reset(); - } - - void RunContext::handleUnfinishedSections() { - // If sections ended prematurely due to an exception we stored their - // infos here so we can tear them down outside the unwind process. - for (auto it = m_unfinishedSections.rbegin(), - itEnd = m_unfinishedSections.rend(); - it != itEnd; - ++it) - sectionEnded(*it); - m_unfinishedSections.clear(); - } - - void RunContext::handleExpr( - AssertionInfo const& info, - ITransientExpression const& expr, - AssertionReaction& reaction - ) { - m_reporter->assertionStarting( info ); - - bool negated = isFalseTest( info.resultDisposition ); - bool result = expr.getResult() != negated; - - if( result ) { - if (!m_includeSuccessfulResults) { - assertionPassed(); - } - else { - reportExpr(info, ResultWas::Ok, &expr, negated); - } - } - else { - reportExpr(info, ResultWas::ExpressionFailed, &expr, negated ); - populateReaction( reaction ); - } - } - void RunContext::reportExpr( - AssertionInfo const &info, - ResultWas::OfType resultType, - ITransientExpression const *expr, - bool negated ) { - - m_lastAssertionInfo = info; - AssertionResultData data( resultType, LazyExpression( negated ) ); - - AssertionResult assertionResult{ info, data }; - assertionResult.m_resultData.lazyExpression.m_transientExpression = expr; - - assertionEnded( assertionResult ); - } - - void RunContext::handleMessage( - AssertionInfo const& info, - ResultWas::OfType resultType, - StringRef const& message, - AssertionReaction& reaction - ) { - m_reporter->assertionStarting( info ); - - m_lastAssertionInfo = info; - - AssertionResultData data( resultType, LazyExpression( false ) ); - data.message = static_cast<std::string>(message); - AssertionResult assertionResult{ m_lastAssertionInfo, data }; - assertionEnded( assertionResult ); - if( !assertionResult.isOk() ) - populateReaction( reaction ); - } - void RunContext::handleUnexpectedExceptionNotThrown( - AssertionInfo const& info, - AssertionReaction& reaction - ) { - handleNonExpr(info, Catch::ResultWas::DidntThrowException, reaction); - } - - void RunContext::handleUnexpectedInflightException( - AssertionInfo const& info, - std::string const& message, - AssertionReaction& reaction - ) { - m_lastAssertionInfo = info; - - AssertionResultData data( ResultWas::ThrewException, LazyExpression( false ) ); - data.message = message; - AssertionResult assertionResult{ info, data }; - assertionEnded( assertionResult ); - populateReaction( reaction ); - } - - void RunContext::populateReaction( AssertionReaction& reaction ) { - reaction.shouldDebugBreak = m_config->shouldDebugBreak(); - reaction.shouldThrow = aborting() || (m_lastAssertionInfo.resultDisposition & ResultDisposition::Normal); - } - - void RunContext::handleIncomplete( - AssertionInfo const& info - ) { - m_lastAssertionInfo = info; - - AssertionResultData data( ResultWas::ThrewException, LazyExpression( false ) ); - data.message = "Exception translation was disabled by CATCH_CONFIG_FAST_COMPILE"; - AssertionResult assertionResult{ info, data }; - assertionEnded( assertionResult ); - } - void RunContext::handleNonExpr( - AssertionInfo const &info, - ResultWas::OfType resultType, - AssertionReaction &reaction - ) { - m_lastAssertionInfo = info; - - AssertionResultData data( resultType, LazyExpression( false ) ); - AssertionResult assertionResult{ info, data }; - assertionEnded( assertionResult ); - - if( !assertionResult.isOk() ) - populateReaction( reaction ); - } - - IResultCapture& getResultCapture() { - if (auto* capture = getCurrentContext().getResultCapture()) - return *capture; - else - CATCH_INTERNAL_ERROR("No result capture instance"); - } - - void seedRng(IConfig const& config) { - if (config.rngSeed() != 0) { - std::srand(config.rngSeed()); - rng().seed(config.rngSeed()); - } - } - - unsigned int rngSeed() { - return getCurrentContext().getConfig()->rngSeed(); - } - -} -// end catch_run_context.cpp -// start catch_section.cpp - -namespace Catch { - - Section::Section( SectionInfo const& info ) - : m_info( info ), - m_sectionIncluded( getResultCapture().sectionStarted( m_info, m_assertions ) ) - { - m_timer.start(); - } - - Section::~Section() { - if( m_sectionIncluded ) { - SectionEndInfo endInfo{ m_info, m_assertions, m_timer.getElapsedSeconds() }; - if( uncaught_exceptions() ) - getResultCapture().sectionEndedEarly( endInfo ); - else - getResultCapture().sectionEnded( endInfo ); - } - } - - // This indicates whether the section should be executed or not - Section::operator bool() const { - return m_sectionIncluded; - } - -} // end namespace Catch -// end catch_section.cpp -// start catch_section_info.cpp - -namespace Catch { - - SectionInfo::SectionInfo - ( SourceLineInfo const& _lineInfo, - std::string const& _name ) - : name( _name ), - lineInfo( _lineInfo ) - {} - -} // end namespace Catch -// end catch_section_info.cpp -// start catch_session.cpp - -// start catch_session.h - -#include <memory> - -namespace Catch { - - class Session : NonCopyable { - public: - - Session(); - ~Session() override; - - void showHelp() const; - void libIdentify(); - - int applyCommandLine( int argc, char const * const * argv ); - #if defined(CATCH_CONFIG_WCHAR) && defined(_WIN32) && defined(UNICODE) - int applyCommandLine( int argc, wchar_t const * const * argv ); - #endif - - void useConfigData( ConfigData const& configData ); - - template<typename CharT> - int run(int argc, CharT const * const argv[]) { - if (m_startupExceptions) - return 1; - int returnCode = applyCommandLine(argc, argv); - if (returnCode == 0) - returnCode = run(); - return returnCode; - } - - int run(); - - clara::Parser const& cli() const; - void cli( clara::Parser const& newParser ); - ConfigData& configData(); - Config& config(); - private: - int runInternal(); - - clara::Parser m_cli; - ConfigData m_configData; - std::shared_ptr<Config> m_config; - bool m_startupExceptions = false; - }; - -} // end namespace Catch - -// end catch_session.h -// start catch_version.h - -#include <iosfwd> - -namespace Catch { - - // Versioning information - struct Version { - Version( Version const& ) = delete; - Version& operator=( Version const& ) = delete; - Version( unsigned int _majorVersion, - unsigned int _minorVersion, - unsigned int _patchNumber, - char const * const _branchName, - unsigned int _buildNumber ); - - unsigned int const majorVersion; - unsigned int const minorVersion; - unsigned int const patchNumber; - - // buildNumber is only used if branchName is not null - char const * const branchName; - unsigned int const buildNumber; - - friend std::ostream& operator << ( std::ostream& os, Version const& version ); - }; - - Version const& libraryVersion(); -} - -// end catch_version.h -#include <cstdlib> -#include <iomanip> -#include <set> -#include <iterator> - -namespace Catch { - - namespace { - const int MaxExitCode = 255; - - IStreamingReporterPtr createReporter(std::string const& reporterName, IConfigPtr const& config) { - auto reporter = Catch::getRegistryHub().getReporterRegistry().create(reporterName, config); - CATCH_ENFORCE(reporter, "No reporter registered with name: '" << reporterName << "'"); - - return reporter; - } - - IStreamingReporterPtr makeReporter(std::shared_ptr<Config> const& config) { - if (Catch::getRegistryHub().getReporterRegistry().getListeners().empty()) { - return createReporter(config->getReporterName(), config); - } - - // On older platforms, returning std::unique_ptr<ListeningReporter> - // when the return type is std::unique_ptr<IStreamingReporter> - // doesn't compile without a std::move call. However, this causes - // a warning on newer platforms. Thus, we have to work around - // it a bit and downcast the pointer manually. - auto ret = std::unique_ptr<IStreamingReporter>(new ListeningReporter); - auto& multi = static_cast<ListeningReporter&>(*ret); - auto const& listeners = Catch::getRegistryHub().getReporterRegistry().getListeners(); - for (auto const& listener : listeners) { - multi.addListener(listener->create(Catch::ReporterConfig(config))); - } - multi.addReporter(createReporter(config->getReporterName(), config)); - return ret; - } - - class TestGroup { - public: - explicit TestGroup(std::shared_ptr<Config> const& config) - : m_config{config} - , m_context{config, makeReporter(config)} - { - auto const& allTestCases = getAllTestCasesSorted(*m_config); - m_matches = m_config->testSpec().matchesByFilter(allTestCases, *m_config); - auto const& invalidArgs = m_config->testSpec().getInvalidArgs(); - - if (m_matches.empty() && invalidArgs.empty()) { - for (auto const& test : allTestCases) - if (!test.isHidden()) - m_tests.emplace(&test); - } else { - for (auto const& match : m_matches) - m_tests.insert(match.tests.begin(), match.tests.end()); - } - } - - Totals execute() { - auto const& invalidArgs = m_config->testSpec().getInvalidArgs(); - Totals totals; - m_context.testGroupStarting(m_config->name(), 1, 1); - for (auto const& testCase : m_tests) { - if (!m_context.aborting()) - totals += m_context.runTest(*testCase); - else - m_context.reporter().skipTest(*testCase); - } - - for (auto const& match : m_matches) { - if (match.tests.empty()) { - m_context.reporter().noMatchingTestCases(match.name); - totals.error = -1; - } - } - - if (!invalidArgs.empty()) { - for (auto const& invalidArg: invalidArgs) - m_context.reporter().reportInvalidArguments(invalidArg); - } - - m_context.testGroupEnded(m_config->name(), totals, 1, 1); - return totals; - } - - private: - using Tests = std::set<TestCase const*>; - - std::shared_ptr<Config> m_config; - RunContext m_context; - Tests m_tests; - TestSpec::Matches m_matches; - }; - - void applyFilenamesAsTags(Catch::IConfig const& config) { - auto& tests = const_cast<std::vector<TestCase>&>(getAllTestCasesSorted(config)); - for (auto& testCase : tests) { - auto tags = testCase.tags; - - std::string filename = testCase.lineInfo.file; - auto lastSlash = filename.find_last_of("\\/"); - if (lastSlash != std::string::npos) { - filename.erase(0, lastSlash); - filename[0] = '#'; - } - - auto lastDot = filename.find_last_of('.'); - if (lastDot != std::string::npos) { - filename.erase(lastDot); - } - - tags.push_back(std::move(filename)); - setTags(testCase, tags); - } - } - - } // anon namespace - - Session::Session() { - static bool alreadyInstantiated = false; - if( alreadyInstantiated ) { - CATCH_TRY { CATCH_INTERNAL_ERROR( "Only one instance of Catch::Session can ever be used" ); } - CATCH_CATCH_ALL { getMutableRegistryHub().registerStartupException(); } - } - - // There cannot be exceptions at startup in no-exception mode. -#if !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS) - const auto& exceptions = getRegistryHub().getStartupExceptionRegistry().getExceptions(); - if ( !exceptions.empty() ) { - config(); - getCurrentMutableContext().setConfig(m_config); - - m_startupExceptions = true; - Colour colourGuard( Colour::Red ); - Catch::cerr() << "Errors occurred during startup!" << '\n'; - // iterate over all exceptions and notify user - for ( const auto& ex_ptr : exceptions ) { - try { - std::rethrow_exception(ex_ptr); - } catch ( std::exception const& ex ) { - Catch::cerr() << Column( ex.what() ).indent(2) << '\n'; - } - } - } -#endif - - alreadyInstantiated = true; - m_cli = makeCommandLineParser( m_configData ); - } - Session::~Session() { - Catch::cleanUp(); - } - - void Session::showHelp() const { - Catch::cout() - << "\nCatch v" << libraryVersion() << "\n" - << m_cli << std::endl - << "For more detailed usage please see the project docs\n" << std::endl; - } - void Session::libIdentify() { - Catch::cout() - << std::left << std::setw(16) << "description: " << "A Catch2 test executable\n" - << std::left << std::setw(16) << "category: " << "testframework\n" - << std::left << std::setw(16) << "framework: " << "Catch Test\n" - << std::left << std::setw(16) << "version: " << libraryVersion() << std::endl; - } - - int Session::applyCommandLine( int argc, char const * const * argv ) { - if( m_startupExceptions ) - return 1; - - auto result = m_cli.parse( clara::Args( argc, argv ) ); - if( !result ) { - config(); - getCurrentMutableContext().setConfig(m_config); - Catch::cerr() - << Colour( Colour::Red ) - << "\nError(s) in input:\n" - << Column( result.errorMessage() ).indent( 2 ) - << "\n\n"; - Catch::cerr() << "Run with -? for usage\n" << std::endl; - return MaxExitCode; - } - - if( m_configData.showHelp ) - showHelp(); - if( m_configData.libIdentify ) - libIdentify(); - m_config.reset(); - return 0; - } - -#if defined(CATCH_CONFIG_WCHAR) && defined(_WIN32) && defined(UNICODE) - int Session::applyCommandLine( int argc, wchar_t const * const * argv ) { - - char **utf8Argv = new char *[ argc ]; - - for ( int i = 0; i < argc; ++i ) { - int bufSize = WideCharToMultiByte( CP_UTF8, 0, argv[i], -1, nullptr, 0, nullptr, nullptr ); - - utf8Argv[ i ] = new char[ bufSize ]; - - WideCharToMultiByte( CP_UTF8, 0, argv[i], -1, utf8Argv[i], bufSize, nullptr, nullptr ); - } - - int returnCode = applyCommandLine( argc, utf8Argv ); - - for ( int i = 0; i < argc; ++i ) - delete [] utf8Argv[ i ]; - - delete [] utf8Argv; - - return returnCode; - } -#endif - - void Session::useConfigData( ConfigData const& configData ) { - m_configData = configData; - m_config.reset(); - } - - int Session::run() { - if( ( m_configData.waitForKeypress & WaitForKeypress::BeforeStart ) != 0 ) { - Catch::cout() << "...waiting for enter/ return before starting" << std::endl; - static_cast<void>(std::getchar()); - } - int exitCode = runInternal(); - if( ( m_configData.waitForKeypress & WaitForKeypress::BeforeExit ) != 0 ) { - Catch::cout() << "...waiting for enter/ return before exiting, with code: " << exitCode << std::endl; - static_cast<void>(std::getchar()); - } - return exitCode; - } - - clara::Parser const& Session::cli() const { - return m_cli; - } - void Session::cli( clara::Parser const& newParser ) { - m_cli = newParser; - } - ConfigData& Session::configData() { - return m_configData; - } - Config& Session::config() { - if( !m_config ) - m_config = std::make_shared<Config>( m_configData ); - return *m_config; - } - - int Session::runInternal() { - if( m_startupExceptions ) - return 1; - - if (m_configData.showHelp || m_configData.libIdentify) { - return 0; - } - - CATCH_TRY { - config(); // Force config to be constructed - - seedRng( *m_config ); - - if( m_configData.filenamesAsTags ) - applyFilenamesAsTags( *m_config ); - - // Handle list request - if( Option<std::size_t> listed = list( m_config ) ) - return static_cast<int>( *listed ); - - TestGroup tests { m_config }; - auto const totals = tests.execute(); - - if( m_config->warnAboutNoTests() && totals.error == -1 ) - return 2; - - // Note that on unices only the lower 8 bits are usually used, clamping - // the return value to 255 prevents false negative when some multiple - // of 256 tests has failed - return (std::min) (MaxExitCode, (std::max) (totals.error, static_cast<int>(totals.assertions.failed))); - } -#if !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS) - catch( std::exception& ex ) { - Catch::cerr() << ex.what() << std::endl; - return MaxExitCode; - } -#endif - } - -} // end namespace Catch -// end catch_session.cpp -// start catch_singletons.cpp - -#include <vector> - -namespace Catch { - - namespace { - static auto getSingletons() -> std::vector<ISingleton*>*& { - static std::vector<ISingleton*>* g_singletons = nullptr; - if( !g_singletons ) - g_singletons = new std::vector<ISingleton*>(); - return g_singletons; - } - } - - ISingleton::~ISingleton() {} - - void addSingleton(ISingleton* singleton ) { - getSingletons()->push_back( singleton ); - } - void cleanupSingletons() { - auto& singletons = getSingletons(); - for( auto singleton : *singletons ) - delete singleton; - delete singletons; - singletons = nullptr; - } - -} // namespace Catch -// end catch_singletons.cpp -// start catch_startup_exception_registry.cpp - -namespace Catch { -void StartupExceptionRegistry::add( std::exception_ptr const& exception ) noexcept { - CATCH_TRY { - m_exceptions.push_back(exception); - } CATCH_CATCH_ALL { - // If we run out of memory during start-up there's really not a lot more we can do about it - std::terminate(); - } - } - - std::vector<std::exception_ptr> const& StartupExceptionRegistry::getExceptions() const noexcept { - return m_exceptions; - } - -} // end namespace Catch -// end catch_startup_exception_registry.cpp -// start catch_stream.cpp - -#include <cstdio> -#include <iostream> -#include <fstream> -#include <sstream> -#include <vector> -#include <memory> - -namespace Catch { - - Catch::IStream::~IStream() = default; - - namespace Detail { namespace { - template<typename WriterF, std::size_t bufferSize=256> - class StreamBufImpl : public std::streambuf { - char data[bufferSize]; - WriterF m_writer; - - public: - StreamBufImpl() { - setp( data, data + sizeof(data) ); - } - - ~StreamBufImpl() noexcept { - StreamBufImpl::sync(); - } - - private: - int overflow( int c ) override { - sync(); - - if( c != EOF ) { - if( pbase() == epptr() ) - m_writer( std::string( 1, static_cast<char>( c ) ) ); - else - sputc( static_cast<char>( c ) ); - } - return 0; - } - - int sync() override { - if( pbase() != pptr() ) { - m_writer( std::string( pbase(), static_cast<std::string::size_type>( pptr() - pbase() ) ) ); - setp( pbase(), epptr() ); - } - return 0; - } - }; - - /////////////////////////////////////////////////////////////////////////// - - struct OutputDebugWriter { - - void operator()( std::string const&str ) { - writeToDebugConsole( str ); - } - }; - - /////////////////////////////////////////////////////////////////////////// - - class FileStream : public IStream { - mutable std::ofstream m_ofs; - public: - FileStream( StringRef filename ) { - m_ofs.open( filename.c_str() ); - CATCH_ENFORCE( !m_ofs.fail(), "Unable to open file: '" << filename << "'" ); - } - ~FileStream() override = default; - public: // IStream - std::ostream& stream() const override { - return m_ofs; - } - }; - - /////////////////////////////////////////////////////////////////////////// - - class CoutStream : public IStream { - mutable std::ostream m_os; - public: - // Store the streambuf from cout up-front because - // cout may get redirected when running tests - CoutStream() : m_os( Catch::cout().rdbuf() ) {} - ~CoutStream() override = default; - - public: // IStream - std::ostream& stream() const override { return m_os; } - }; - - /////////////////////////////////////////////////////////////////////////// - - class DebugOutStream : public IStream { - std::unique_ptr<StreamBufImpl<OutputDebugWriter>> m_streamBuf; - mutable std::ostream m_os; - public: - DebugOutStream() - : m_streamBuf( new StreamBufImpl<OutputDebugWriter>() ), - m_os( m_streamBuf.get() ) - {} - - ~DebugOutStream() override = default; - - public: // IStream - std::ostream& stream() const override { return m_os; } - }; - - }} // namespace anon::detail - - /////////////////////////////////////////////////////////////////////////// - - auto makeStream( StringRef const &filename ) -> IStream const* { - if( filename.empty() ) - return new Detail::CoutStream(); - else if( filename[0] == '%' ) { - if( filename == "%debug" ) - return new Detail::DebugOutStream(); - else - CATCH_ERROR( "Unrecognised stream: '" << filename << "'" ); - } - else - return new Detail::FileStream( filename ); - } - - // This class encapsulates the idea of a pool of ostringstreams that can be reused. - struct StringStreams { - std::vector<std::unique_ptr<std::ostringstream>> m_streams; - std::vector<std::size_t> m_unused; - std::ostringstream m_referenceStream; // Used for copy state/ flags from - - auto add() -> std::size_t { - if( m_unused.empty() ) { - m_streams.push_back( std::unique_ptr<std::ostringstream>( new std::ostringstream ) ); - return m_streams.size()-1; - } - else { - auto index = m_unused.back(); - m_unused.pop_back(); - return index; - } - } - - void release( std::size_t index ) { - m_streams[index]->copyfmt( m_referenceStream ); // Restore initial flags and other state - m_unused.push_back(index); - } - }; - - ReusableStringStream::ReusableStringStream() - : m_index( Singleton<StringStreams>::getMutable().add() ), - m_oss( Singleton<StringStreams>::getMutable().m_streams[m_index].get() ) - {} - - ReusableStringStream::~ReusableStringStream() { - static_cast<std::ostringstream*>( m_oss )->str(""); - m_oss->clear(); - Singleton<StringStreams>::getMutable().release( m_index ); - } - - auto ReusableStringStream::str() const -> std::string { - return static_cast<std::ostringstream*>( m_oss )->str(); - } - - /////////////////////////////////////////////////////////////////////////// - -#ifndef CATCH_CONFIG_NOSTDOUT // If you #define this you must implement these functions - std::ostream& cout() { return std::cout; } - std::ostream& cerr() { return std::cerr; } - std::ostream& clog() { return std::clog; } -#endif -} -// end catch_stream.cpp -// start catch_string_manip.cpp - -#include <algorithm> -#include <ostream> -#include <cstring> -#include <cctype> -#include <vector> - -namespace Catch { - - namespace { - char toLowerCh(char c) { - return static_cast<char>( std::tolower( c ) ); - } - } - - bool startsWith( std::string const& s, std::string const& prefix ) { - return s.size() >= prefix.size() && std::equal(prefix.begin(), prefix.end(), s.begin()); - } - bool startsWith( std::string const& s, char prefix ) { - return !s.empty() && s[0] == prefix; - } - bool endsWith( std::string const& s, std::string const& suffix ) { - return s.size() >= suffix.size() && std::equal(suffix.rbegin(), suffix.rend(), s.rbegin()); - } - bool endsWith( std::string const& s, char suffix ) { - return !s.empty() && s[s.size()-1] == suffix; - } - bool contains( std::string const& s, std::string const& infix ) { - return s.find( infix ) != std::string::npos; - } - void toLowerInPlace( std::string& s ) { - std::transform( s.begin(), s.end(), s.begin(), toLowerCh ); - } - std::string toLower( std::string const& s ) { - std::string lc = s; - toLowerInPlace( lc ); - return lc; - } - std::string trim( std::string const& str ) { - static char const* whitespaceChars = "\n\r\t "; - std::string::size_type start = str.find_first_not_of( whitespaceChars ); - std::string::size_type end = str.find_last_not_of( whitespaceChars ); - - return start != std::string::npos ? str.substr( start, 1+end-start ) : std::string(); - } - - StringRef trim(StringRef ref) { - const auto is_ws = [](char c) { - return c == ' ' || c == '\t' || c == '\n' || c == '\r'; - }; - size_t real_begin = 0; - while (real_begin < ref.size() && is_ws(ref[real_begin])) { ++real_begin; } - size_t real_end = ref.size(); - while (real_end > real_begin && is_ws(ref[real_end - 1])) { --real_end; } - - return ref.substr(real_begin, real_end - real_begin); - } - - bool replaceInPlace( std::string& str, std::string const& replaceThis, std::string const& withThis ) { - bool replaced = false; - std::size_t i = str.find( replaceThis ); - while( i != std::string::npos ) { - replaced = true; - str = str.substr( 0, i ) + withThis + str.substr( i+replaceThis.size() ); - if( i < str.size()-withThis.size() ) - i = str.find( replaceThis, i+withThis.size() ); - else - i = std::string::npos; - } - return replaced; - } - - std::vector<StringRef> splitStringRef( StringRef str, char delimiter ) { - std::vector<StringRef> subStrings; - std::size_t start = 0; - for(std::size_t pos = 0; pos < str.size(); ++pos ) { - if( str[pos] == delimiter ) { - if( pos - start > 1 ) - subStrings.push_back( str.substr( start, pos-start ) ); - start = pos+1; - } - } - if( start < str.size() ) - subStrings.push_back( str.substr( start, str.size()-start ) ); - return subStrings; - } - - pluralise::pluralise( std::size_t count, std::string const& label ) - : m_count( count ), - m_label( label ) - {} - - std::ostream& operator << ( std::ostream& os, pluralise const& pluraliser ) { - os << pluraliser.m_count << ' ' << pluraliser.m_label; - if( pluraliser.m_count != 1 ) - os << 's'; - return os; - } - -} -// end catch_string_manip.cpp -// start catch_stringref.cpp - -#include <algorithm> -#include <ostream> -#include <cstring> -#include <cstdint> - -namespace Catch { - StringRef::StringRef( char const* rawChars ) noexcept - : StringRef( rawChars, static_cast<StringRef::size_type>(std::strlen(rawChars) ) ) - {} - - auto StringRef::c_str() const -> char const* { - CATCH_ENFORCE(isNullTerminated(), "Called StringRef::c_str() on a non-null-terminated instance"); - return m_start; - } - auto StringRef::data() const noexcept -> char const* { - return m_start; - } - - auto StringRef::substr( size_type start, size_type size ) const noexcept -> StringRef { - if (start < m_size) { - return StringRef(m_start + start, (std::min)(m_size - start, size)); - } else { - return StringRef(); - } - } - auto StringRef::operator == ( StringRef const& other ) const noexcept -> bool { - return m_size == other.m_size - && (std::memcmp( m_start, other.m_start, m_size ) == 0); - } - - auto operator << ( std::ostream& os, StringRef const& str ) -> std::ostream& { - return os.write(str.data(), str.size()); - } - - auto operator+=( std::string& lhs, StringRef const& rhs ) -> std::string& { - lhs.append(rhs.data(), rhs.size()); - return lhs; - } - -} // namespace Catch -// end catch_stringref.cpp -// start catch_tag_alias.cpp - -namespace Catch { - TagAlias::TagAlias(std::string const & _tag, SourceLineInfo _lineInfo): tag(_tag), lineInfo(_lineInfo) {} -} -// end catch_tag_alias.cpp -// start catch_tag_alias_autoregistrar.cpp - -namespace Catch { - - RegistrarForTagAliases::RegistrarForTagAliases(char const* alias, char const* tag, SourceLineInfo const& lineInfo) { - CATCH_TRY { - getMutableRegistryHub().registerTagAlias(alias, tag, lineInfo); - } CATCH_CATCH_ALL { - // Do not throw when constructing global objects, instead register the exception to be processed later - getMutableRegistryHub().registerStartupException(); - } - } - -} -// end catch_tag_alias_autoregistrar.cpp -// start catch_tag_alias_registry.cpp - -#include <sstream> - -namespace Catch { - - TagAliasRegistry::~TagAliasRegistry() {} - - TagAlias const* TagAliasRegistry::find( std::string const& alias ) const { - auto it = m_registry.find( alias ); - if( it != m_registry.end() ) - return &(it->second); - else - return nullptr; - } - - std::string TagAliasRegistry::expandAliases( std::string const& unexpandedTestSpec ) const { - std::string expandedTestSpec = unexpandedTestSpec; - for( auto const& registryKvp : m_registry ) { - std::size_t pos = expandedTestSpec.find( registryKvp.first ); - if( pos != std::string::npos ) { - expandedTestSpec = expandedTestSpec.substr( 0, pos ) + - registryKvp.second.tag + - expandedTestSpec.substr( pos + registryKvp.first.size() ); - } - } - return expandedTestSpec; - } - - void TagAliasRegistry::add( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo ) { - CATCH_ENFORCE( startsWith(alias, "[@") && endsWith(alias, ']'), - "error: tag alias, '" << alias << "' is not of the form [@alias name].\n" << lineInfo ); - - CATCH_ENFORCE( m_registry.insert(std::make_pair(alias, TagAlias(tag, lineInfo))).second, - "error: tag alias, '" << alias << "' already registered.\n" - << "\tFirst seen at: " << find(alias)->lineInfo << "\n" - << "\tRedefined at: " << lineInfo ); - } - - ITagAliasRegistry::~ITagAliasRegistry() {} - - ITagAliasRegistry const& ITagAliasRegistry::get() { - return getRegistryHub().getTagAliasRegistry(); - } - -} // end namespace Catch -// end catch_tag_alias_registry.cpp -// start catch_test_case_info.cpp - -#include <cctype> -#include <exception> -#include <algorithm> -#include <sstream> - -namespace Catch { - - namespace { - TestCaseInfo::SpecialProperties parseSpecialTag( std::string const& tag ) { - if( startsWith( tag, '.' ) || - tag == "!hide" ) - return TestCaseInfo::IsHidden; - else if( tag == "!throws" ) - return TestCaseInfo::Throws; - else if( tag == "!shouldfail" ) - return TestCaseInfo::ShouldFail; - else if( tag == "!mayfail" ) - return TestCaseInfo::MayFail; - else if( tag == "!nonportable" ) - return TestCaseInfo::NonPortable; - else if( tag == "!benchmark" ) - return static_cast<TestCaseInfo::SpecialProperties>( TestCaseInfo::Benchmark | TestCaseInfo::IsHidden ); - else - return TestCaseInfo::None; - } - bool isReservedTag( std::string const& tag ) { - return parseSpecialTag( tag ) == TestCaseInfo::None && tag.size() > 0 && !std::isalnum( static_cast<unsigned char>(tag[0]) ); - } - void enforceNotReservedTag( std::string const& tag, SourceLineInfo const& _lineInfo ) { - CATCH_ENFORCE( !isReservedTag(tag), - "Tag name: [" << tag << "] is not allowed.\n" - << "Tag names starting with non alphanumeric characters are reserved\n" - << _lineInfo ); - } - } - - TestCase makeTestCase( ITestInvoker* _testCase, - std::string const& _className, - NameAndTags const& nameAndTags, - SourceLineInfo const& _lineInfo ) - { - bool isHidden = false; - - // Parse out tags - std::vector<std::string> tags; - std::string desc, tag; - bool inTag = false; - for (char c : nameAndTags.tags) { - if( !inTag ) { - if( c == '[' ) - inTag = true; - else - desc += c; - } - else { - if( c == ']' ) { - TestCaseInfo::SpecialProperties prop = parseSpecialTag( tag ); - if( ( prop & TestCaseInfo::IsHidden ) != 0 ) - isHidden = true; - else if( prop == TestCaseInfo::None ) - enforceNotReservedTag( tag, _lineInfo ); - - // Merged hide tags like `[.approvals]` should be added as - // `[.][approvals]`. The `[.]` is added at later point, so - // we only strip the prefix - if (startsWith(tag, '.') && tag.size() > 1) { - tag.erase(0, 1); - } - tags.push_back( tag ); - tag.clear(); - inTag = false; - } - else - tag += c; - } - } - if( isHidden ) { - // Add all "hidden" tags to make them behave identically - tags.insert( tags.end(), { ".", "!hide" } ); - } - - TestCaseInfo info( static_cast<std::string>(nameAndTags.name), _className, desc, tags, _lineInfo ); - return TestCase( _testCase, std::move(info) ); - } - - void setTags( TestCaseInfo& testCaseInfo, std::vector<std::string> tags ) { - std::sort(begin(tags), end(tags)); - tags.erase(std::unique(begin(tags), end(tags)), end(tags)); - testCaseInfo.lcaseTags.clear(); - - for( auto const& tag : tags ) { - std::string lcaseTag = toLower( tag ); - testCaseInfo.properties = static_cast<TestCaseInfo::SpecialProperties>( testCaseInfo.properties | parseSpecialTag( lcaseTag ) ); - testCaseInfo.lcaseTags.push_back( lcaseTag ); - } - testCaseInfo.tags = std::move(tags); - } - - TestCaseInfo::TestCaseInfo( std::string const& _name, - std::string const& _className, - std::string const& _description, - std::vector<std::string> const& _tags, - SourceLineInfo const& _lineInfo ) - : name( _name ), - className( _className ), - description( _description ), - lineInfo( _lineInfo ), - properties( None ) - { - setTags( *this, _tags ); - } - - bool TestCaseInfo::isHidden() const { - return ( properties & IsHidden ) != 0; - } - bool TestCaseInfo::throws() const { - return ( properties & Throws ) != 0; - } - bool TestCaseInfo::okToFail() const { - return ( properties & (ShouldFail | MayFail ) ) != 0; - } - bool TestCaseInfo::expectedToFail() const { - return ( properties & (ShouldFail ) ) != 0; - } - - std::string TestCaseInfo::tagsAsString() const { - std::string ret; - // '[' and ']' per tag - std::size_t full_size = 2 * tags.size(); - for (const auto& tag : tags) { - full_size += tag.size(); - } - ret.reserve(full_size); - for (const auto& tag : tags) { - ret.push_back('['); - ret.append(tag); - ret.push_back(']'); - } - - return ret; - } - - TestCase::TestCase( ITestInvoker* testCase, TestCaseInfo&& info ) : TestCaseInfo( std::move(info) ), test( testCase ) {} - - TestCase TestCase::withName( std::string const& _newName ) const { - TestCase other( *this ); - other.name = _newName; - return other; - } - - void TestCase::invoke() const { - test->invoke(); - } - - bool TestCase::operator == ( TestCase const& other ) const { - return test.get() == other.test.get() && - name == other.name && - className == other.className; - } - - bool TestCase::operator < ( TestCase const& other ) const { - return name < other.name; - } - - TestCaseInfo const& TestCase::getTestCaseInfo() const - { - return *this; - } - -} // end namespace Catch -// end catch_test_case_info.cpp -// start catch_test_case_registry_impl.cpp - -#include <algorithm> -#include <sstream> - -namespace Catch { - - namespace { - struct TestHasher { - explicit TestHasher(Catch::SimplePcg32& rng) { - basis = rng(); - basis <<= 32; - basis |= rng(); - } - - uint64_t basis; - - uint64_t operator()(TestCase const& t) const { - // Modified FNV-1a hash - static constexpr uint64_t prime = 1099511628211; - uint64_t hash = basis; - for (const char c : t.name) { - hash ^= c; - hash *= prime; - } - return hash; - } - }; - } // end unnamed namespace - - std::vector<TestCase> sortTests( IConfig const& config, std::vector<TestCase> const& unsortedTestCases ) { - switch( config.runOrder() ) { - case RunTests::InDeclarationOrder: - // already in declaration order - break; - - case RunTests::InLexicographicalOrder: { - std::vector<TestCase> sorted = unsortedTestCases; - std::sort( sorted.begin(), sorted.end() ); - return sorted; - } - - case RunTests::InRandomOrder: { - seedRng( config ); - TestHasher h( rng() ); - - using hashedTest = std::pair<uint64_t, TestCase const*>; - std::vector<hashedTest> indexed_tests; - indexed_tests.reserve( unsortedTestCases.size() ); - - for (auto const& testCase : unsortedTestCases) { - indexed_tests.emplace_back(h(testCase), &testCase); - } - - std::sort(indexed_tests.begin(), indexed_tests.end(), - [](hashedTest const& lhs, hashedTest const& rhs) { - if (lhs.first == rhs.first) { - return lhs.second->name < rhs.second->name; - } - return lhs.first < rhs.first; - }); - - std::vector<TestCase> sorted; - sorted.reserve( indexed_tests.size() ); - - for (auto const& hashed : indexed_tests) { - sorted.emplace_back(*hashed.second); - } - - return sorted; - } - } - return unsortedTestCases; - } - - bool isThrowSafe( TestCase const& testCase, IConfig const& config ) { - return !testCase.throws() || config.allowThrows(); - } - - bool matchTest( TestCase const& testCase, TestSpec const& testSpec, IConfig const& config ) { - return testSpec.matches( testCase ) && isThrowSafe( testCase, config ); - } - - void enforceNoDuplicateTestCases( std::vector<TestCase> const& functions ) { - std::set<TestCase> seenFunctions; - for( auto const& function : functions ) { - auto prev = seenFunctions.insert( function ); - CATCH_ENFORCE( prev.second, - "error: TEST_CASE( \"" << function.name << "\" ) already defined.\n" - << "\tFirst seen at " << prev.first->getTestCaseInfo().lineInfo << "\n" - << "\tRedefined at " << function.getTestCaseInfo().lineInfo ); - } - } - - std::vector<TestCase> filterTests( std::vector<TestCase> const& testCases, TestSpec const& testSpec, IConfig const& config ) { - std::vector<TestCase> filtered; - filtered.reserve( testCases.size() ); - for (auto const& testCase : testCases) { - if ((!testSpec.hasFilters() && !testCase.isHidden()) || - (testSpec.hasFilters() && matchTest(testCase, testSpec, config))) { - filtered.push_back(testCase); - } - } - return filtered; - } - std::vector<TestCase> const& getAllTestCasesSorted( IConfig const& config ) { - return getRegistryHub().getTestCaseRegistry().getAllTestsSorted( config ); - } - - void TestRegistry::registerTest( TestCase const& testCase ) { - std::string name = testCase.getTestCaseInfo().name; - if( name.empty() ) { - ReusableStringStream rss; - rss << "Anonymous test case " << ++m_unnamedCount; - return registerTest( testCase.withName( rss.str() ) ); - } - m_functions.push_back( testCase ); - } - - std::vector<TestCase> const& TestRegistry::getAllTests() const { - return m_functions; - } - std::vector<TestCase> const& TestRegistry::getAllTestsSorted( IConfig const& config ) const { - if( m_sortedFunctions.empty() ) - enforceNoDuplicateTestCases( m_functions ); - - if( m_currentSortOrder != config.runOrder() || m_sortedFunctions.empty() ) { - m_sortedFunctions = sortTests( config, m_functions ); - m_currentSortOrder = config.runOrder(); - } - return m_sortedFunctions; - } - - /////////////////////////////////////////////////////////////////////////// - TestInvokerAsFunction::TestInvokerAsFunction( void(*testAsFunction)() ) noexcept : m_testAsFunction( testAsFunction ) {} - - void TestInvokerAsFunction::invoke() const { - m_testAsFunction(); - } - - std::string extractClassName( StringRef const& classOrQualifiedMethodName ) { - std::string className(classOrQualifiedMethodName); - if( startsWith( className, '&' ) ) - { - std::size_t lastColons = className.rfind( "::" ); - std::size_t penultimateColons = className.rfind( "::", lastColons-1 ); - if( penultimateColons == std::string::npos ) - penultimateColons = 1; - className = className.substr( penultimateColons, lastColons-penultimateColons ); - } - return className; - } - -} // end namespace Catch -// end catch_test_case_registry_impl.cpp -// start catch_test_case_tracker.cpp - -#include <algorithm> -#include <cassert> -#include <stdexcept> -#include <memory> -#include <sstream> - -#if defined(__clang__) -# pragma clang diagnostic push -# pragma clang diagnostic ignored "-Wexit-time-destructors" -#endif - -namespace Catch { -namespace TestCaseTracking { - - NameAndLocation::NameAndLocation( std::string const& _name, SourceLineInfo const& _location ) - : name( _name ), - location( _location ) - {} - - ITracker::~ITracker() = default; - - ITracker& TrackerContext::startRun() { - m_rootTracker = std::make_shared<SectionTracker>( NameAndLocation( "{root}", CATCH_INTERNAL_LINEINFO ), *this, nullptr ); - m_currentTracker = nullptr; - m_runState = Executing; - return *m_rootTracker; - } - - void TrackerContext::endRun() { - m_rootTracker.reset(); - m_currentTracker = nullptr; - m_runState = NotStarted; - } - - void TrackerContext::startCycle() { - m_currentTracker = m_rootTracker.get(); - m_runState = Executing; - } - void TrackerContext::completeCycle() { - m_runState = CompletedCycle; - } - - bool TrackerContext::completedCycle() const { - return m_runState == CompletedCycle; - } - ITracker& TrackerContext::currentTracker() { - return *m_currentTracker; - } - void TrackerContext::setCurrentTracker( ITracker* tracker ) { - m_currentTracker = tracker; - } - - TrackerBase::TrackerBase( NameAndLocation const& nameAndLocation, TrackerContext& ctx, ITracker* parent ) - : m_nameAndLocation( nameAndLocation ), - m_ctx( ctx ), - m_parent( parent ) - {} - - NameAndLocation const& TrackerBase::nameAndLocation() const { - return m_nameAndLocation; - } - bool TrackerBase::isComplete() const { - return m_runState == CompletedSuccessfully || m_runState == Failed; - } - bool TrackerBase::isSuccessfullyCompleted() const { - return m_runState == CompletedSuccessfully; - } - bool TrackerBase::isOpen() const { - return m_runState != NotStarted && !isComplete(); - } - bool TrackerBase::hasChildren() const { - return !m_children.empty(); - } - - void TrackerBase::addChild( ITrackerPtr const& child ) { - m_children.push_back( child ); - } - - ITrackerPtr TrackerBase::findChild( NameAndLocation const& nameAndLocation ) { - auto it = std::find_if( m_children.begin(), m_children.end(), - [&nameAndLocation]( ITrackerPtr const& tracker ){ - return - tracker->nameAndLocation().location == nameAndLocation.location && - tracker->nameAndLocation().name == nameAndLocation.name; - } ); - return( it != m_children.end() ) - ? *it - : nullptr; - } - ITracker& TrackerBase::parent() { - assert( m_parent ); // Should always be non-null except for root - return *m_parent; - } - - void TrackerBase::openChild() { - if( m_runState != ExecutingChildren ) { - m_runState = ExecutingChildren; - if( m_parent ) - m_parent->openChild(); - } - } - - bool TrackerBase::isSectionTracker() const { return false; } - bool TrackerBase::isGeneratorTracker() const { return false; } - - void TrackerBase::open() { - m_runState = Executing; - moveToThis(); - if( m_parent ) - m_parent->openChild(); - } - - void TrackerBase::close() { - - // Close any still open children (e.g. generators) - while( &m_ctx.currentTracker() != this ) - m_ctx.currentTracker().close(); - - switch( m_runState ) { - case NeedsAnotherRun: - break; - - case Executing: - m_runState = CompletedSuccessfully; - break; - case ExecutingChildren: - if( std::all_of(m_children.begin(), m_children.end(), [](ITrackerPtr const& t){ return t->isComplete(); }) ) - m_runState = CompletedSuccessfully; - break; - - case NotStarted: - case CompletedSuccessfully: - case Failed: - CATCH_INTERNAL_ERROR( "Illogical state: " << m_runState ); - - default: - CATCH_INTERNAL_ERROR( "Unknown state: " << m_runState ); - } - moveToParent(); - m_ctx.completeCycle(); - } - void TrackerBase::fail() { - m_runState = Failed; - if( m_parent ) - m_parent->markAsNeedingAnotherRun(); - moveToParent(); - m_ctx.completeCycle(); - } - void TrackerBase::markAsNeedingAnotherRun() { - m_runState = NeedsAnotherRun; - } - - void TrackerBase::moveToParent() { - assert( m_parent ); - m_ctx.setCurrentTracker( m_parent ); - } - void TrackerBase::moveToThis() { - m_ctx.setCurrentTracker( this ); - } - - SectionTracker::SectionTracker( NameAndLocation const& nameAndLocation, TrackerContext& ctx, ITracker* parent ) - : TrackerBase( nameAndLocation, ctx, parent ), - m_trimmed_name(trim(nameAndLocation.name)) - { - if( parent ) { - while( !parent->isSectionTracker() ) - parent = &parent->parent(); - - SectionTracker& parentSection = static_cast<SectionTracker&>( *parent ); - addNextFilters( parentSection.m_filters ); - } - } - - bool SectionTracker::isComplete() const { - bool complete = true; - - if ((m_filters.empty() || m_filters[0] == "") - || std::find(m_filters.begin(), m_filters.end(), m_trimmed_name) != m_filters.end()) { - complete = TrackerBase::isComplete(); - } - return complete; - } - - bool SectionTracker::isSectionTracker() const { return true; } - - SectionTracker& SectionTracker::acquire( TrackerContext& ctx, NameAndLocation const& nameAndLocation ) { - std::shared_ptr<SectionTracker> section; - - ITracker& currentTracker = ctx.currentTracker(); - if( ITrackerPtr childTracker = currentTracker.findChild( nameAndLocation ) ) { - assert( childTracker ); - assert( childTracker->isSectionTracker() ); - section = std::static_pointer_cast<SectionTracker>( childTracker ); - } - else { - section = std::make_shared<SectionTracker>( nameAndLocation, ctx, ¤tTracker ); - currentTracker.addChild( section ); - } - if( !ctx.completedCycle() ) - section->tryOpen(); - return *section; - } - - void SectionTracker::tryOpen() { - if( !isComplete() ) - open(); - } - - void SectionTracker::addInitialFilters( std::vector<std::string> const& filters ) { - if( !filters.empty() ) { - m_filters.reserve( m_filters.size() + filters.size() + 2 ); - m_filters.emplace_back(""); // Root - should never be consulted - m_filters.emplace_back(""); // Test Case - not a section filter - m_filters.insert( m_filters.end(), filters.begin(), filters.end() ); - } - } - void SectionTracker::addNextFilters( std::vector<std::string> const& filters ) { - if( filters.size() > 1 ) - m_filters.insert( m_filters.end(), filters.begin()+1, filters.end() ); - } - -} // namespace TestCaseTracking - -using TestCaseTracking::ITracker; -using TestCaseTracking::TrackerContext; -using TestCaseTracking::SectionTracker; - -} // namespace Catch - -#if defined(__clang__) -# pragma clang diagnostic pop -#endif -// end catch_test_case_tracker.cpp -// start catch_test_registry.cpp - -namespace Catch { - - auto makeTestInvoker( void(*testAsFunction)() ) noexcept -> ITestInvoker* { - return new(std::nothrow) TestInvokerAsFunction( testAsFunction ); - } - - NameAndTags::NameAndTags( StringRef const& name_ , StringRef const& tags_ ) noexcept : name( name_ ), tags( tags_ ) {} - - AutoReg::AutoReg( ITestInvoker* invoker, SourceLineInfo const& lineInfo, StringRef const& classOrMethod, NameAndTags const& nameAndTags ) noexcept { - CATCH_TRY { - getMutableRegistryHub() - .registerTest( - makeTestCase( - invoker, - extractClassName( classOrMethod ), - nameAndTags, - lineInfo)); - } CATCH_CATCH_ALL { - // Do not throw when constructing global objects, instead register the exception to be processed later - getMutableRegistryHub().registerStartupException(); - } - } - - AutoReg::~AutoReg() = default; -} -// end catch_test_registry.cpp -// start catch_test_spec.cpp - -#include <algorithm> -#include <string> -#include <vector> -#include <memory> - -namespace Catch { - - TestSpec::Pattern::Pattern( std::string const& name ) - : m_name( name ) - {} - - TestSpec::Pattern::~Pattern() = default; - - std::string const& TestSpec::Pattern::name() const { - return m_name; - } - - TestSpec::NamePattern::NamePattern( std::string const& name, std::string const& filterString ) - : Pattern( filterString ) - , m_wildcardPattern( toLower( name ), CaseSensitive::No ) - {} - - bool TestSpec::NamePattern::matches( TestCaseInfo const& testCase ) const { - return m_wildcardPattern.matches( testCase.name ); - } - - TestSpec::TagPattern::TagPattern( std::string const& tag, std::string const& filterString ) - : Pattern( filterString ) - , m_tag( toLower( tag ) ) - {} - - bool TestSpec::TagPattern::matches( TestCaseInfo const& testCase ) const { - return std::find(begin(testCase.lcaseTags), - end(testCase.lcaseTags), - m_tag) != end(testCase.lcaseTags); - } - - TestSpec::ExcludedPattern::ExcludedPattern( PatternPtr const& underlyingPattern ) - : Pattern( underlyingPattern->name() ) - , m_underlyingPattern( underlyingPattern ) - {} - - bool TestSpec::ExcludedPattern::matches( TestCaseInfo const& testCase ) const { - return !m_underlyingPattern->matches( testCase ); - } - - bool TestSpec::Filter::matches( TestCaseInfo const& testCase ) const { - return std::all_of( m_patterns.begin(), m_patterns.end(), [&]( PatternPtr const& p ){ return p->matches( testCase ); } ); - } - - std::string TestSpec::Filter::name() const { - std::string name; - for( auto const& p : m_patterns ) - name += p->name(); - return name; - } - - bool TestSpec::hasFilters() const { - return !m_filters.empty(); - } - - bool TestSpec::matches( TestCaseInfo const& testCase ) const { - return std::any_of( m_filters.begin(), m_filters.end(), [&]( Filter const& f ){ return f.matches( testCase ); } ); - } - - TestSpec::Matches TestSpec::matchesByFilter( std::vector<TestCase> const& testCases, IConfig const& config ) const - { - Matches matches( m_filters.size() ); - std::transform( m_filters.begin(), m_filters.end(), matches.begin(), [&]( Filter const& filter ){ - std::vector<TestCase const*> currentMatches; - for( auto const& test : testCases ) - if( isThrowSafe( test, config ) && filter.matches( test ) ) - currentMatches.emplace_back( &test ); - return FilterMatch{ filter.name(), currentMatches }; - } ); - return matches; - } - - const TestSpec::vectorStrings& TestSpec::getInvalidArgs() const{ - return (m_invalidArgs); - } - -} -// end catch_test_spec.cpp -// start catch_test_spec_parser.cpp - -namespace Catch { - - TestSpecParser::TestSpecParser( ITagAliasRegistry const& tagAliases ) : m_tagAliases( &tagAliases ) {} - - TestSpecParser& TestSpecParser::parse( std::string const& arg ) { - m_mode = None; - m_exclusion = false; - m_arg = m_tagAliases->expandAliases( arg ); - m_escapeChars.clear(); - m_substring.reserve(m_arg.size()); - m_patternName.reserve(m_arg.size()); - m_realPatternPos = 0; - - for( m_pos = 0; m_pos < m_arg.size(); ++m_pos ) - //if visitChar fails - if( !visitChar( m_arg[m_pos] ) ){ - m_testSpec.m_invalidArgs.push_back(arg); - break; - } - endMode(); - return *this; - } - TestSpec TestSpecParser::testSpec() { - addFilter(); - return m_testSpec; - } - bool TestSpecParser::visitChar( char c ) { - if( (m_mode != EscapedName) && (c == '\\') ) { - escape(); - addCharToPattern(c); - return true; - }else if((m_mode != EscapedName) && (c == ',') ) { - return separate(); - } - - switch( m_mode ) { - case None: - if( processNoneChar( c ) ) - return true; - break; - case Name: - processNameChar( c ); - break; - case EscapedName: - endMode(); - addCharToPattern(c); - return true; - default: - case Tag: - case QuotedName: - if( processOtherChar( c ) ) - return true; - break; - } - - m_substring += c; - if( !isControlChar( c ) ) { - m_patternName += c; - m_realPatternPos++; - } - return true; - } - // Two of the processing methods return true to signal the caller to return - // without adding the given character to the current pattern strings - bool TestSpecParser::processNoneChar( char c ) { - switch( c ) { - case ' ': - return true; - case '~': - m_exclusion = true; - return false; - case '[': - startNewMode( Tag ); - return false; - case '"': - startNewMode( QuotedName ); - return false; - default: - startNewMode( Name ); - return false; - } - } - void TestSpecParser::processNameChar( char c ) { - if( c == '[' ) { - if( m_substring == "exclude:" ) - m_exclusion = true; - else - endMode(); - startNewMode( Tag ); - } - } - bool TestSpecParser::processOtherChar( char c ) { - if( !isControlChar( c ) ) - return false; - m_substring += c; - endMode(); - return true; - } - void TestSpecParser::startNewMode( Mode mode ) { - m_mode = mode; - } - void TestSpecParser::endMode() { - switch( m_mode ) { - case Name: - case QuotedName: - return addNamePattern(); - case Tag: - return addTagPattern(); - case EscapedName: - revertBackToLastMode(); - return; - case None: - default: - return startNewMode( None ); - } - } - void TestSpecParser::escape() { - saveLastMode(); - m_mode = EscapedName; - m_escapeChars.push_back(m_realPatternPos); - } - bool TestSpecParser::isControlChar( char c ) const { - switch( m_mode ) { - default: - return false; - case None: - return c == '~'; - case Name: - return c == '['; - case EscapedName: - return true; - case QuotedName: - return c == '"'; - case Tag: - return c == '[' || c == ']'; - } - } - - void TestSpecParser::addFilter() { - if( !m_currentFilter.m_patterns.empty() ) { - m_testSpec.m_filters.push_back( m_currentFilter ); - m_currentFilter = TestSpec::Filter(); - } - } - - void TestSpecParser::saveLastMode() { - lastMode = m_mode; - } - - void TestSpecParser::revertBackToLastMode() { - m_mode = lastMode; - } - - bool TestSpecParser::separate() { - if( (m_mode==QuotedName) || (m_mode==Tag) ){ - //invalid argument, signal failure to previous scope. - m_mode = None; - m_pos = m_arg.size(); - m_substring.clear(); - m_patternName.clear(); - m_realPatternPos = 0; - return false; - } - endMode(); - addFilter(); - return true; //success - } - - std::string TestSpecParser::preprocessPattern() { - std::string token = m_patternName; - for (std::size_t i = 0; i < m_escapeChars.size(); ++i) - token = token.substr(0, m_escapeChars[i] - i) + token.substr(m_escapeChars[i] - i + 1); - m_escapeChars.clear(); - if (startsWith(token, "exclude:")) { - m_exclusion = true; - token = token.substr(8); - } - - m_patternName.clear(); - m_realPatternPos = 0; - - return token; - } - - void TestSpecParser::addNamePattern() { - auto token = preprocessPattern(); - - if (!token.empty()) { - TestSpec::PatternPtr pattern = std::make_shared<TestSpec::NamePattern>(token, m_substring); - if (m_exclusion) - pattern = std::make_shared<TestSpec::ExcludedPattern>(pattern); - m_currentFilter.m_patterns.push_back(pattern); - } - m_substring.clear(); - m_exclusion = false; - m_mode = None; - } - - void TestSpecParser::addTagPattern() { - auto token = preprocessPattern(); - - if (!token.empty()) { - // If the tag pattern is the "hide and tag" shorthand (e.g. [.foo]) - // we have to create a separate hide tag and shorten the real one - if (token.size() > 1 && token[0] == '.') { - token.erase(token.begin()); - TestSpec::PatternPtr pattern = std::make_shared<TestSpec::TagPattern>(".", m_substring); - if (m_exclusion) { - pattern = std::make_shared<TestSpec::ExcludedPattern>(pattern); - } - m_currentFilter.m_patterns.push_back(pattern); - } - - TestSpec::PatternPtr pattern = std::make_shared<TestSpec::TagPattern>(token, m_substring); - - if (m_exclusion) { - pattern = std::make_shared<TestSpec::ExcludedPattern>(pattern); - } - m_currentFilter.m_patterns.push_back(pattern); - } - m_substring.clear(); - m_exclusion = false; - m_mode = None; - } - - TestSpec parseTestSpec( std::string const& arg ) { - return TestSpecParser( ITagAliasRegistry::get() ).parse( arg ).testSpec(); - } - -} // namespace Catch -// end catch_test_spec_parser.cpp -// start catch_timer.cpp - -#include <chrono> - -static const uint64_t nanosecondsInSecond = 1000000000; - -namespace Catch { - - auto getCurrentNanosecondsSinceEpoch() -> uint64_t { - return std::chrono::duration_cast<std::chrono::nanoseconds>( std::chrono::high_resolution_clock::now().time_since_epoch() ).count(); - } - - namespace { - auto estimateClockResolution() -> uint64_t { - uint64_t sum = 0; - static const uint64_t iterations = 1000000; - - auto startTime = getCurrentNanosecondsSinceEpoch(); - - for( std::size_t i = 0; i < iterations; ++i ) { - - uint64_t ticks; - uint64_t baseTicks = getCurrentNanosecondsSinceEpoch(); - do { - ticks = getCurrentNanosecondsSinceEpoch(); - } while( ticks == baseTicks ); - - auto delta = ticks - baseTicks; - sum += delta; - - // If we have been calibrating for over 3 seconds -- the clock - // is terrible and we should move on. - // TBD: How to signal that the measured resolution is probably wrong? - if (ticks > startTime + 3 * nanosecondsInSecond) { - return sum / ( i + 1u ); - } - } - - // We're just taking the mean, here. To do better we could take the std. dev and exclude outliers - // - and potentially do more iterations if there's a high variance. - return sum/iterations; - } - } - auto getEstimatedClockResolution() -> uint64_t { - static auto s_resolution = estimateClockResolution(); - return s_resolution; - } - - void Timer::start() { - m_nanoseconds = getCurrentNanosecondsSinceEpoch(); - } - auto Timer::getElapsedNanoseconds() const -> uint64_t { - return getCurrentNanosecondsSinceEpoch() - m_nanoseconds; - } - auto Timer::getElapsedMicroseconds() const -> uint64_t { - return getElapsedNanoseconds()/1000; - } - auto Timer::getElapsedMilliseconds() const -> unsigned int { - return static_cast<unsigned int>(getElapsedMicroseconds()/1000); - } - auto Timer::getElapsedSeconds() const -> double { - return getElapsedMicroseconds()/1000000.0; - } - -} // namespace Catch -// end catch_timer.cpp -// start catch_tostring.cpp - -#if defined(__clang__) -# pragma clang diagnostic push -# pragma clang diagnostic ignored "-Wexit-time-destructors" -# pragma clang diagnostic ignored "-Wglobal-constructors" -#endif - -// Enable specific decls locally -#if !defined(CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER) -#define CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER -#endif - -#include <cmath> -#include <iomanip> - -namespace Catch { - -namespace Detail { - - const std::string unprintableString = "{?}"; - - namespace { - const int hexThreshold = 255; - - struct Endianness { - enum Arch { Big, Little }; - - static Arch which() { - int one = 1; - // If the lowest byte we read is non-zero, we can assume - // that little endian format is used. - auto value = *reinterpret_cast<char*>(&one); - return value ? Little : Big; - } - }; - } - - std::string rawMemoryToString( const void *object, std::size_t size ) { - // Reverse order for little endian architectures - int i = 0, end = static_cast<int>( size ), inc = 1; - if( Endianness::which() == Endianness::Little ) { - i = end-1; - end = inc = -1; - } - - unsigned char const *bytes = static_cast<unsigned char const *>(object); - ReusableStringStream rss; - rss << "0x" << std::setfill('0') << std::hex; - for( ; i != end; i += inc ) - rss << std::setw(2) << static_cast<unsigned>(bytes[i]); - return rss.str(); - } -} - -template<typename T> -std::string fpToString( T value, int precision ) { - if (Catch::isnan(value)) { - return "nan"; - } - - ReusableStringStream rss; - rss << std::setprecision( precision ) - << std::fixed - << value; - std::string d = rss.str(); - std::size_t i = d.find_last_not_of( '0' ); - if( i != std::string::npos && i != d.size()-1 ) { - if( d[i] == '.' ) - i++; - d = d.substr( 0, i+1 ); - } - return d; -} - -//// ======================================================= //// -// -// Out-of-line defs for full specialization of StringMaker -// -//// ======================================================= //// - -std::string StringMaker<std::string>::convert(const std::string& str) { - if (!getCurrentContext().getConfig()->showInvisibles()) { - return '"' + str + '"'; - } - - std::string s("\""); - for (char c : str) { - switch (c) { - case '\n': - s.append("\\n"); - break; - case '\t': - s.append("\\t"); - break; - default: - s.push_back(c); - break; - } - } - s.append("\""); - return s; -} - -#ifdef CATCH_CONFIG_CPP17_STRING_VIEW -std::string StringMaker<std::string_view>::convert(std::string_view str) { - return ::Catch::Detail::stringify(std::string{ str }); -} -#endif - -std::string StringMaker<char const*>::convert(char const* str) { - if (str) { - return ::Catch::Detail::stringify(std::string{ str }); - } else { - return{ "{null string}" }; - } -} -std::string StringMaker<char*>::convert(char* str) { - if (str) { - return ::Catch::Detail::stringify(std::string{ str }); - } else { - return{ "{null string}" }; - } -} - -#ifdef CATCH_CONFIG_WCHAR -std::string StringMaker<std::wstring>::convert(const std::wstring& wstr) { - std::string s; - s.reserve(wstr.size()); - for (auto c : wstr) { - s += (c <= 0xff) ? static_cast<char>(c) : '?'; - } - return ::Catch::Detail::stringify(s); -} - -# ifdef CATCH_CONFIG_CPP17_STRING_VIEW -std::string StringMaker<std::wstring_view>::convert(std::wstring_view str) { - return StringMaker<std::wstring>::convert(std::wstring(str)); -} -# endif - -std::string StringMaker<wchar_t const*>::convert(wchar_t const * str) { - if (str) { - return ::Catch::Detail::stringify(std::wstring{ str }); - } else { - return{ "{null string}" }; - } -} -std::string StringMaker<wchar_t *>::convert(wchar_t * str) { - if (str) { - return ::Catch::Detail::stringify(std::wstring{ str }); - } else { - return{ "{null string}" }; - } -} -#endif - -#if defined(CATCH_CONFIG_CPP17_BYTE) -#include <cstddef> -std::string StringMaker<std::byte>::convert(std::byte value) { - return ::Catch::Detail::stringify(std::to_integer<unsigned long long>(value)); -} -#endif // defined(CATCH_CONFIG_CPP17_BYTE) - -std::string StringMaker<int>::convert(int value) { - return ::Catch::Detail::stringify(static_cast<long long>(value)); -} -std::string StringMaker<long>::convert(long value) { - return ::Catch::Detail::stringify(static_cast<long long>(value)); -} -std::string StringMaker<long long>::convert(long long value) { - ReusableStringStream rss; - rss << value; - if (value > Detail::hexThreshold) { - rss << " (0x" << std::hex << value << ')'; - } - return rss.str(); -} - -std::string StringMaker<unsigned int>::convert(unsigned int value) { - return ::Catch::Detail::stringify(static_cast<unsigned long long>(value)); -} -std::string StringMaker<unsigned long>::convert(unsigned long value) { - return ::Catch::Detail::stringify(static_cast<unsigned long long>(value)); -} -std::string StringMaker<unsigned long long>::convert(unsigned long long value) { - ReusableStringStream rss; - rss << value; - if (value > Detail::hexThreshold) { - rss << " (0x" << std::hex << value << ')'; - } - return rss.str(); -} - -std::string StringMaker<bool>::convert(bool b) { - return b ? "true" : "false"; -} - -std::string StringMaker<signed char>::convert(signed char value) { - if (value == '\r') { - return "'\\r'"; - } else if (value == '\f') { - return "'\\f'"; - } else if (value == '\n') { - return "'\\n'"; - } else if (value == '\t') { - return "'\\t'"; - } else if ('\0' <= value && value < ' ') { - return ::Catch::Detail::stringify(static_cast<unsigned int>(value)); - } else { - char chstr[] = "' '"; - chstr[1] = value; - return chstr; - } -} -std::string StringMaker<char>::convert(char c) { - return ::Catch::Detail::stringify(static_cast<signed char>(c)); -} -std::string StringMaker<unsigned char>::convert(unsigned char c) { - return ::Catch::Detail::stringify(static_cast<char>(c)); -} - -std::string StringMaker<std::nullptr_t>::convert(std::nullptr_t) { - return "nullptr"; -} - -int StringMaker<float>::precision = 5; - -std::string StringMaker<float>::convert(float value) { - return fpToString(value, precision) + 'f'; -} - -int StringMaker<double>::precision = 10; - -std::string StringMaker<double>::convert(double value) { - return fpToString(value, precision); -} - -std::string ratio_string<std::atto>::symbol() { return "a"; } -std::string ratio_string<std::femto>::symbol() { return "f"; } -std::string ratio_string<std::pico>::symbol() { return "p"; } -std::string ratio_string<std::nano>::symbol() { return "n"; } -std::string ratio_string<std::micro>::symbol() { return "u"; } -std::string ratio_string<std::milli>::symbol() { return "m"; } - -} // end namespace Catch - -#if defined(__clang__) -# pragma clang diagnostic pop -#endif - -// end catch_tostring.cpp -// start catch_totals.cpp - -namespace Catch { - - Counts Counts::operator - ( Counts const& other ) const { - Counts diff; - diff.passed = passed - other.passed; - diff.failed = failed - other.failed; - diff.failedButOk = failedButOk - other.failedButOk; - return diff; - } - - Counts& Counts::operator += ( Counts const& other ) { - passed += other.passed; - failed += other.failed; - failedButOk += other.failedButOk; - return *this; - } - - std::size_t Counts::total() const { - return passed + failed + failedButOk; - } - bool Counts::allPassed() const { - return failed == 0 && failedButOk == 0; - } - bool Counts::allOk() const { - return failed == 0; - } - - Totals Totals::operator - ( Totals const& other ) const { - Totals diff; - diff.assertions = assertions - other.assertions; - diff.testCases = testCases - other.testCases; - return diff; - } - - Totals& Totals::operator += ( Totals const& other ) { - assertions += other.assertions; - testCases += other.testCases; - return *this; - } - - Totals Totals::delta( Totals const& prevTotals ) const { - Totals diff = *this - prevTotals; - if( diff.assertions.failed > 0 ) - ++diff.testCases.failed; - else if( diff.assertions.failedButOk > 0 ) - ++diff.testCases.failedButOk; - else - ++diff.testCases.passed; - return diff; - } - -} -// end catch_totals.cpp -// start catch_uncaught_exceptions.cpp - -#include <exception> - -namespace Catch { - bool uncaught_exceptions() { -#if defined(CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS) - return std::uncaught_exceptions() > 0; -#else - return std::uncaught_exception(); -#endif - } -} // end namespace Catch -// end catch_uncaught_exceptions.cpp -// start catch_version.cpp - -#include <ostream> - -namespace Catch { - - Version::Version - ( unsigned int _majorVersion, - unsigned int _minorVersion, - unsigned int _patchNumber, - char const * const _branchName, - unsigned int _buildNumber ) - : majorVersion( _majorVersion ), - minorVersion( _minorVersion ), - patchNumber( _patchNumber ), - branchName( _branchName ), - buildNumber( _buildNumber ) - {} - - std::ostream& operator << ( std::ostream& os, Version const& version ) { - os << version.majorVersion << '.' - << version.minorVersion << '.' - << version.patchNumber; - // branchName is never null -> 0th char is \0 if it is empty - if (version.branchName[0]) { - os << '-' << version.branchName - << '.' << version.buildNumber; - } - return os; - } - - Version const& libraryVersion() { - static Version version( 2, 12, 1, "", 0 ); - return version; - } - -} -// end catch_version.cpp -// start catch_wildcard_pattern.cpp - -namespace Catch { - - WildcardPattern::WildcardPattern( std::string const& pattern, - CaseSensitive::Choice caseSensitivity ) - : m_caseSensitivity( caseSensitivity ), - m_pattern( normaliseString( pattern ) ) - { - if( startsWith( m_pattern, '*' ) ) { - m_pattern = m_pattern.substr( 1 ); - m_wildcard = WildcardAtStart; - } - if( endsWith( m_pattern, '*' ) ) { - m_pattern = m_pattern.substr( 0, m_pattern.size()-1 ); - m_wildcard = static_cast<WildcardPosition>( m_wildcard | WildcardAtEnd ); - } - } - - bool WildcardPattern::matches( std::string const& str ) const { - switch( m_wildcard ) { - case NoWildcard: - return m_pattern == normaliseString( str ); - case WildcardAtStart: - return endsWith( normaliseString( str ), m_pattern ); - case WildcardAtEnd: - return startsWith( normaliseString( str ), m_pattern ); - case WildcardAtBothEnds: - return contains( normaliseString( str ), m_pattern ); - default: - CATCH_INTERNAL_ERROR( "Unknown enum" ); - } - } - - std::string WildcardPattern::normaliseString( std::string const& str ) const { - return trim( m_caseSensitivity == CaseSensitive::No ? toLower( str ) : str ); - } -} -// end catch_wildcard_pattern.cpp -// start catch_xmlwriter.cpp - -#include <iomanip> -#include <type_traits> - -namespace Catch { - -namespace { - - size_t trailingBytes(unsigned char c) { - if ((c & 0xE0) == 0xC0) { - return 2; - } - if ((c & 0xF0) == 0xE0) { - return 3; - } - if ((c & 0xF8) == 0xF0) { - return 4; - } - CATCH_INTERNAL_ERROR("Invalid multibyte utf-8 start byte encountered"); - } - - uint32_t headerValue(unsigned char c) { - if ((c & 0xE0) == 0xC0) { - return c & 0x1F; - } - if ((c & 0xF0) == 0xE0) { - return c & 0x0F; - } - if ((c & 0xF8) == 0xF0) { - return c & 0x07; - } - CATCH_INTERNAL_ERROR("Invalid multibyte utf-8 start byte encountered"); - } - - void hexEscapeChar(std::ostream& os, unsigned char c) { - std::ios_base::fmtflags f(os.flags()); - os << "\\x" - << std::uppercase << std::hex << std::setfill('0') << std::setw(2) - << static_cast<int>(c); - os.flags(f); - } - - bool shouldNewline(XmlFormatting fmt) { - return !!(static_cast<std::underlying_type<XmlFormatting>::type>(fmt & XmlFormatting::Newline)); - } - - bool shouldIndent(XmlFormatting fmt) { - return !!(static_cast<std::underlying_type<XmlFormatting>::type>(fmt & XmlFormatting::Indent)); - } - -} // anonymous namespace - - XmlFormatting operator | (XmlFormatting lhs, XmlFormatting rhs) { - return static_cast<XmlFormatting>( - static_cast<std::underlying_type<XmlFormatting>::type>(lhs) | - static_cast<std::underlying_type<XmlFormatting>::type>(rhs) - ); - } - - XmlFormatting operator & (XmlFormatting lhs, XmlFormatting rhs) { - return static_cast<XmlFormatting>( - static_cast<std::underlying_type<XmlFormatting>::type>(lhs) & - static_cast<std::underlying_type<XmlFormatting>::type>(rhs) - ); - } - - XmlEncode::XmlEncode( std::string const& str, ForWhat forWhat ) - : m_str( str ), - m_forWhat( forWhat ) - {} - - void XmlEncode::encodeTo( std::ostream& os ) const { - // Apostrophe escaping not necessary if we always use " to write attributes - // (see: http://www.w3.org/TR/xml/#syntax) - - for( std::size_t idx = 0; idx < m_str.size(); ++ idx ) { - unsigned char c = m_str[idx]; - switch (c) { - case '<': os << "<"; break; - case '&': os << "&"; break; - - case '>': - // See: http://www.w3.org/TR/xml/#syntax - if (idx > 2 && m_str[idx - 1] == ']' && m_str[idx - 2] == ']') - os << ">"; - else - os << c; - break; - - case '\"': - if (m_forWhat == ForAttributes) - os << """; - else - os << c; - break; - - default: - // Check for control characters and invalid utf-8 - - // Escape control characters in standard ascii - // see http://stackoverflow.com/questions/404107/why-are-control-characters-illegal-in-xml-1-0 - if (c < 0x09 || (c > 0x0D && c < 0x20) || c == 0x7F) { - hexEscapeChar(os, c); - break; - } - - // Plain ASCII: Write it to stream - if (c < 0x7F) { - os << c; - break; - } - - // UTF-8 territory - // Check if the encoding is valid and if it is not, hex escape bytes. - // Important: We do not check the exact decoded values for validity, only the encoding format - // First check that this bytes is a valid lead byte: - // This means that it is not encoded as 1111 1XXX - // Or as 10XX XXXX - if (c < 0xC0 || - c >= 0xF8) { - hexEscapeChar(os, c); - break; - } - - auto encBytes = trailingBytes(c); - // Are there enough bytes left to avoid accessing out-of-bounds memory? - if (idx + encBytes - 1 >= m_str.size()) { - hexEscapeChar(os, c); - break; - } - // The header is valid, check data - // The next encBytes bytes must together be a valid utf-8 - // This means: bitpattern 10XX XXXX and the extracted value is sane (ish) - bool valid = true; - uint32_t value = headerValue(c); - for (std::size_t n = 1; n < encBytes; ++n) { - unsigned char nc = m_str[idx + n]; - valid &= ((nc & 0xC0) == 0x80); - value = (value << 6) | (nc & 0x3F); - } - - if ( - // Wrong bit pattern of following bytes - (!valid) || - // Overlong encodings - (value < 0x80) || - (0x80 <= value && value < 0x800 && encBytes > 2) || - (0x800 < value && value < 0x10000 && encBytes > 3) || - // Encoded value out of range - (value >= 0x110000) - ) { - hexEscapeChar(os, c); - break; - } - - // If we got here, this is in fact a valid(ish) utf-8 sequence - for (std::size_t n = 0; n < encBytes; ++n) { - os << m_str[idx + n]; - } - idx += encBytes - 1; - break; - } - } - } - - std::ostream& operator << ( std::ostream& os, XmlEncode const& xmlEncode ) { - xmlEncode.encodeTo( os ); - return os; - } - - XmlWriter::ScopedElement::ScopedElement( XmlWriter* writer, XmlFormatting fmt ) - : m_writer( writer ), - m_fmt(fmt) - {} - - XmlWriter::ScopedElement::ScopedElement( ScopedElement&& other ) noexcept - : m_writer( other.m_writer ), - m_fmt(other.m_fmt) - { - other.m_writer = nullptr; - other.m_fmt = XmlFormatting::None; - } - XmlWriter::ScopedElement& XmlWriter::ScopedElement::operator=( ScopedElement&& other ) noexcept { - if ( m_writer ) { - m_writer->endElement(); - } - m_writer = other.m_writer; - other.m_writer = nullptr; - m_fmt = other.m_fmt; - other.m_fmt = XmlFormatting::None; - return *this; - } - - XmlWriter::ScopedElement::~ScopedElement() { - if (m_writer) { - m_writer->endElement(m_fmt); - } - } - - XmlWriter::ScopedElement& XmlWriter::ScopedElement::writeText( std::string const& text, XmlFormatting fmt ) { - m_writer->writeText( text, fmt ); - return *this; - } - - XmlWriter::XmlWriter( std::ostream& os ) : m_os( os ) - { - writeDeclaration(); - } - - XmlWriter::~XmlWriter() { - while (!m_tags.empty()) { - endElement(); - } - newlineIfNecessary(); - } - - XmlWriter& XmlWriter::startElement( std::string const& name, XmlFormatting fmt ) { - ensureTagClosed(); - newlineIfNecessary(); - if (shouldIndent(fmt)) { - m_os << m_indent; - m_indent += " "; - } - m_os << '<' << name; - m_tags.push_back( name ); - m_tagIsOpen = true; - applyFormatting(fmt); - return *this; - } - - XmlWriter::ScopedElement XmlWriter::scopedElement( std::string const& name, XmlFormatting fmt ) { - ScopedElement scoped( this, fmt ); - startElement( name, fmt ); - return scoped; - } - - XmlWriter& XmlWriter::endElement(XmlFormatting fmt) { - m_indent = m_indent.substr(0, m_indent.size() - 2); - - if( m_tagIsOpen ) { - m_os << "/>"; - m_tagIsOpen = false; - } else { - newlineIfNecessary(); - if (shouldIndent(fmt)) { - m_os << m_indent; - } - m_os << "</" << m_tags.back() << ">"; - } - m_os << std::flush; - applyFormatting(fmt); - m_tags.pop_back(); - return *this; - } - - XmlWriter& XmlWriter::writeAttribute( std::string const& name, std::string const& attribute ) { - if( !name.empty() && !attribute.empty() ) - m_os << ' ' << name << "=\"" << XmlEncode( attribute, XmlEncode::ForAttributes ) << '"'; - return *this; - } - - XmlWriter& XmlWriter::writeAttribute( std::string const& name, bool attribute ) { - m_os << ' ' << name << "=\"" << ( attribute ? "true" : "false" ) << '"'; - return *this; - } - - XmlWriter& XmlWriter::writeText( std::string const& text, XmlFormatting fmt) { - if( !text.empty() ){ - bool tagWasOpen = m_tagIsOpen; - ensureTagClosed(); - if (tagWasOpen && shouldIndent(fmt)) { - m_os << m_indent; - } - m_os << XmlEncode( text ); - applyFormatting(fmt); - } - return *this; - } - - XmlWriter& XmlWriter::writeComment( std::string const& text, XmlFormatting fmt) { - ensureTagClosed(); - if (shouldIndent(fmt)) { - m_os << m_indent; - } - m_os << "<!--" << text << "-->"; - applyFormatting(fmt); - return *this; - } - - void XmlWriter::writeStylesheetRef( std::string const& url ) { - m_os << "<?xml-stylesheet type=\"text/xsl\" href=\"" << url << "\"?>\n"; - } - - XmlWriter& XmlWriter::writeBlankLine() { - ensureTagClosed(); - m_os << '\n'; - return *this; - } - - void XmlWriter::ensureTagClosed() { - if( m_tagIsOpen ) { - m_os << '>' << std::flush; - newlineIfNecessary(); - m_tagIsOpen = false; - } - } - - void XmlWriter::applyFormatting(XmlFormatting fmt) { - m_needsNewline = shouldNewline(fmt); - } - - void XmlWriter::writeDeclaration() { - m_os << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; - } - - void XmlWriter::newlineIfNecessary() { - if( m_needsNewline ) { - m_os << std::endl; - m_needsNewline = false; - } - } -} -// end catch_xmlwriter.cpp -// start catch_reporter_bases.cpp - -#include <cstring> -#include <cfloat> -#include <cstdio> -#include <cassert> -#include <memory> - -namespace Catch { - void prepareExpandedExpression(AssertionResult& result) { - result.getExpandedExpression(); - } - - // Because formatting using c++ streams is stateful, drop down to C is required - // Alternatively we could use stringstream, but its performance is... not good. - std::string getFormattedDuration( double duration ) { - // Max exponent + 1 is required to represent the whole part - // + 1 for decimal point - // + 3 for the 3 decimal places - // + 1 for null terminator - const std::size_t maxDoubleSize = DBL_MAX_10_EXP + 1 + 1 + 3 + 1; - char buffer[maxDoubleSize]; - - // Save previous errno, to prevent sprintf from overwriting it - ErrnoGuard guard; -#ifdef _MSC_VER - sprintf_s(buffer, "%.3f", duration); -#else - std::sprintf(buffer, "%.3f", duration); -#endif - return std::string(buffer); - } - - std::string serializeFilters( std::vector<std::string> const& container ) { - ReusableStringStream oss; - bool first = true; - for (auto&& filter : container) - { - if (!first) - oss << ' '; - else - first = false; - - oss << filter; - } - return oss.str(); - } - - TestEventListenerBase::TestEventListenerBase(ReporterConfig const & _config) - :StreamingReporterBase(_config) {} - - std::set<Verbosity> TestEventListenerBase::getSupportedVerbosities() { - return { Verbosity::Quiet, Verbosity::Normal, Verbosity::High }; - } - - void TestEventListenerBase::assertionStarting(AssertionInfo const &) {} - - bool TestEventListenerBase::assertionEnded(AssertionStats const &) { - return false; - } - -} // end namespace Catch -// end catch_reporter_bases.cpp -// start catch_reporter_compact.cpp - -namespace { - -#ifdef CATCH_PLATFORM_MAC - const char* failedString() { return "FAILED"; } - const char* passedString() { return "PASSED"; } -#else - const char* failedString() { return "failed"; } - const char* passedString() { return "passed"; } -#endif - - // Colour::LightGrey - Catch::Colour::Code dimColour() { return Catch::Colour::FileName; } - - std::string bothOrAll( std::size_t count ) { - return count == 1 ? std::string() : - count == 2 ? "both " : "all " ; - } - -} // anon namespace - -namespace Catch { -namespace { -// Colour, message variants: -// - white: No tests ran. -// - red: Failed [both/all] N test cases, failed [both/all] M assertions. -// - white: Passed [both/all] N test cases (no assertions). -// - red: Failed N tests cases, failed M assertions. -// - green: Passed [both/all] N tests cases with M assertions. -void printTotals(std::ostream& out, const Totals& totals) { - if (totals.testCases.total() == 0) { - out << "No tests ran."; - } else if (totals.testCases.failed == totals.testCases.total()) { - Colour colour(Colour::ResultError); - const std::string qualify_assertions_failed = - totals.assertions.failed == totals.assertions.total() ? - bothOrAll(totals.assertions.failed) : std::string(); - out << - "Failed " << bothOrAll(totals.testCases.failed) - << pluralise(totals.testCases.failed, "test case") << ", " - "failed " << qualify_assertions_failed << - pluralise(totals.assertions.failed, "assertion") << '.'; - } else if (totals.assertions.total() == 0) { - out << - "Passed " << bothOrAll(totals.testCases.total()) - << pluralise(totals.testCases.total(), "test case") - << " (no assertions)."; - } else if (totals.assertions.failed) { - Colour colour(Colour::ResultError); - out << - "Failed " << pluralise(totals.testCases.failed, "test case") << ", " - "failed " << pluralise(totals.assertions.failed, "assertion") << '.'; - } else { - Colour colour(Colour::ResultSuccess); - out << - "Passed " << bothOrAll(totals.testCases.passed) - << pluralise(totals.testCases.passed, "test case") << - " with " << pluralise(totals.assertions.passed, "assertion") << '.'; - } -} - -// Implementation of CompactReporter formatting -class AssertionPrinter { -public: - AssertionPrinter& operator= (AssertionPrinter const&) = delete; - AssertionPrinter(AssertionPrinter const&) = delete; - AssertionPrinter(std::ostream& _stream, AssertionStats const& _stats, bool _printInfoMessages) - : stream(_stream) - , result(_stats.assertionResult) - , messages(_stats.infoMessages) - , itMessage(_stats.infoMessages.begin()) - , printInfoMessages(_printInfoMessages) {} - - void print() { - printSourceInfo(); - - itMessage = messages.begin(); - - switch (result.getResultType()) { - case ResultWas::Ok: - printResultType(Colour::ResultSuccess, passedString()); - printOriginalExpression(); - printReconstructedExpression(); - if (!result.hasExpression()) - printRemainingMessages(Colour::None); - else - printRemainingMessages(); - break; - case ResultWas::ExpressionFailed: - if (result.isOk()) - printResultType(Colour::ResultSuccess, failedString() + std::string(" - but was ok")); - else - printResultType(Colour::Error, failedString()); - printOriginalExpression(); - printReconstructedExpression(); - printRemainingMessages(); - break; - case ResultWas::ThrewException: - printResultType(Colour::Error, failedString()); - printIssue("unexpected exception with message:"); - printMessage(); - printExpressionWas(); - printRemainingMessages(); - break; - case ResultWas::FatalErrorCondition: - printResultType(Colour::Error, failedString()); - printIssue("fatal error condition with message:"); - printMessage(); - printExpressionWas(); - printRemainingMessages(); - break; - case ResultWas::DidntThrowException: - printResultType(Colour::Error, failedString()); - printIssue("expected exception, got none"); - printExpressionWas(); - printRemainingMessages(); - break; - case ResultWas::Info: - printResultType(Colour::None, "info"); - printMessage(); - printRemainingMessages(); - break; - case ResultWas::Warning: - printResultType(Colour::None, "warning"); - printMessage(); - printRemainingMessages(); - break; - case ResultWas::ExplicitFailure: - printResultType(Colour::Error, failedString()); - printIssue("explicitly"); - printRemainingMessages(Colour::None); - break; - // These cases are here to prevent compiler warnings - case ResultWas::Unknown: - case ResultWas::FailureBit: - case ResultWas::Exception: - printResultType(Colour::Error, "** internal error **"); - break; - } - } - -private: - void printSourceInfo() const { - Colour colourGuard(Colour::FileName); - stream << result.getSourceInfo() << ':'; - } - - void printResultType(Colour::Code colour, std::string const& passOrFail) const { - if (!passOrFail.empty()) { - { - Colour colourGuard(colour); - stream << ' ' << passOrFail; - } - stream << ':'; - } - } - - void printIssue(std::string const& issue) const { - stream << ' ' << issue; - } - - void printExpressionWas() { - if (result.hasExpression()) { - stream << ';'; - { - Colour colour(dimColour()); - stream << " expression was:"; - } - printOriginalExpression(); - } - } - - void printOriginalExpression() const { - if (result.hasExpression()) { - stream << ' ' << result.getExpression(); - } - } - - void printReconstructedExpression() const { - if (result.hasExpandedExpression()) { - { - Colour colour(dimColour()); - stream << " for: "; - } - stream << result.getExpandedExpression(); - } - } - - void printMessage() { - if (itMessage != messages.end()) { - stream << " '" << itMessage->message << '\''; - ++itMessage; - } - } - - void printRemainingMessages(Colour::Code colour = dimColour()) { - if (itMessage == messages.end()) - return; - - const auto itEnd = messages.cend(); - const auto N = static_cast<std::size_t>(std::distance(itMessage, itEnd)); - - { - Colour colourGuard(colour); - stream << " with " << pluralise(N, "message") << ':'; - } - - while (itMessage != itEnd) { - // If this assertion is a warning ignore any INFO messages - if (printInfoMessages || itMessage->type != ResultWas::Info) { - printMessage(); - if (itMessage != itEnd) { - Colour colourGuard(dimColour()); - stream << " and"; - } - continue; - } - ++itMessage; - } - } - -private: - std::ostream& stream; - AssertionResult const& result; - std::vector<MessageInfo> messages; - std::vector<MessageInfo>::const_iterator itMessage; - bool printInfoMessages; -}; - -} // anon namespace - - std::string CompactReporter::getDescription() { - return "Reports test results on a single line, suitable for IDEs"; - } - - ReporterPreferences CompactReporter::getPreferences() const { - return m_reporterPrefs; - } - - void CompactReporter::noMatchingTestCases( std::string const& spec ) { - stream << "No test cases matched '" << spec << '\'' << std::endl; - } - - void CompactReporter::assertionStarting( AssertionInfo const& ) {} - - bool CompactReporter::assertionEnded( AssertionStats const& _assertionStats ) { - AssertionResult const& result = _assertionStats.assertionResult; - - bool printInfoMessages = true; - - // Drop out if result was successful and we're not printing those - if( !m_config->includeSuccessfulResults() && result.isOk() ) { - if( result.getResultType() != ResultWas::Warning ) - return false; - printInfoMessages = false; - } - - AssertionPrinter printer( stream, _assertionStats, printInfoMessages ); - printer.print(); - - stream << std::endl; - return true; - } - - void CompactReporter::sectionEnded(SectionStats const& _sectionStats) { - if (m_config->showDurations() == ShowDurations::Always) { - stream << getFormattedDuration(_sectionStats.durationInSeconds) << " s: " << _sectionStats.sectionInfo.name << std::endl; - } - } - - void CompactReporter::testRunEnded( TestRunStats const& _testRunStats ) { - printTotals( stream, _testRunStats.totals ); - stream << '\n' << std::endl; - StreamingReporterBase::testRunEnded( _testRunStats ); - } - - CompactReporter::~CompactReporter() {} - - CATCH_REGISTER_REPORTER( "compact", CompactReporter ) - -} // end namespace Catch -// end catch_reporter_compact.cpp -// start catch_reporter_console.cpp - -#include <cfloat> -#include <cstdio> - -#if defined(_MSC_VER) -#pragma warning(push) -#pragma warning(disable:4061) // Not all labels are EXPLICITLY handled in switch - // Note that 4062 (not all labels are handled and default is missing) is enabled -#endif - -#if defined(__clang__) -# pragma clang diagnostic push -// For simplicity, benchmarking-only helpers are always enabled -# pragma clang diagnostic ignored "-Wunused-function" -#endif - -namespace Catch { - -namespace { - -// Formatter impl for ConsoleReporter -class ConsoleAssertionPrinter { -public: - ConsoleAssertionPrinter& operator= (ConsoleAssertionPrinter const&) = delete; - ConsoleAssertionPrinter(ConsoleAssertionPrinter const&) = delete; - ConsoleAssertionPrinter(std::ostream& _stream, AssertionStats const& _stats, bool _printInfoMessages) - : stream(_stream), - stats(_stats), - result(_stats.assertionResult), - colour(Colour::None), - message(result.getMessage()), - messages(_stats.infoMessages), - printInfoMessages(_printInfoMessages) { - switch (result.getResultType()) { - case ResultWas::Ok: - colour = Colour::Success; - passOrFail = "PASSED"; - //if( result.hasMessage() ) - if (_stats.infoMessages.size() == 1) - messageLabel = "with message"; - if (_stats.infoMessages.size() > 1) - messageLabel = "with messages"; - break; - case ResultWas::ExpressionFailed: - if (result.isOk()) { - colour = Colour::Success; - passOrFail = "FAILED - but was ok"; - } else { - colour = Colour::Error; - passOrFail = "FAILED"; - } - if (_stats.infoMessages.size() == 1) - messageLabel = "with message"; - if (_stats.infoMessages.size() > 1) - messageLabel = "with messages"; - break; - case ResultWas::ThrewException: - colour = Colour::Error; - passOrFail = "FAILED"; - messageLabel = "due to unexpected exception with "; - if (_stats.infoMessages.size() == 1) - messageLabel += "message"; - if (_stats.infoMessages.size() > 1) - messageLabel += "messages"; - break; - case ResultWas::FatalErrorCondition: - colour = Colour::Error; - passOrFail = "FAILED"; - messageLabel = "due to a fatal error condition"; - break; - case ResultWas::DidntThrowException: - colour = Colour::Error; - passOrFail = "FAILED"; - messageLabel = "because no exception was thrown where one was expected"; - break; - case ResultWas::Info: - messageLabel = "info"; - break; - case ResultWas::Warning: - messageLabel = "warning"; - break; - case ResultWas::ExplicitFailure: - passOrFail = "FAILED"; - colour = Colour::Error; - if (_stats.infoMessages.size() == 1) - messageLabel = "explicitly with message"; - if (_stats.infoMessages.size() > 1) - messageLabel = "explicitly with messages"; - break; - // These cases are here to prevent compiler warnings - case ResultWas::Unknown: - case ResultWas::FailureBit: - case ResultWas::Exception: - passOrFail = "** internal error **"; - colour = Colour::Error; - break; - } - } - - void print() const { - printSourceInfo(); - if (stats.totals.assertions.total() > 0) { - printResultType(); - printOriginalExpression(); - printReconstructedExpression(); - } else { - stream << '\n'; - } - printMessage(); - } - -private: - void printResultType() const { - if (!passOrFail.empty()) { - Colour colourGuard(colour); - stream << passOrFail << ":\n"; - } - } - void printOriginalExpression() const { - if (result.hasExpression()) { - Colour colourGuard(Colour::OriginalExpression); - stream << " "; - stream << result.getExpressionInMacro(); - stream << '\n'; - } - } - void printReconstructedExpression() const { - if (result.hasExpandedExpression()) { - stream << "with expansion:\n"; - Colour colourGuard(Colour::ReconstructedExpression); - stream << Column(result.getExpandedExpression()).indent(2) << '\n'; - } - } - void printMessage() const { - if (!messageLabel.empty()) - stream << messageLabel << ':' << '\n'; - for (auto const& msg : messages) { - // If this assertion is a warning ignore any INFO messages - if (printInfoMessages || msg.type != ResultWas::Info) - stream << Column(msg.message).indent(2) << '\n'; - } - } - void printSourceInfo() const { - Colour colourGuard(Colour::FileName); - stream << result.getSourceInfo() << ": "; - } - - std::ostream& stream; - AssertionStats const& stats; - AssertionResult const& result; - Colour::Code colour; - std::string passOrFail; - std::string messageLabel; - std::string message; - std::vector<MessageInfo> messages; - bool printInfoMessages; -}; - -std::size_t makeRatio(std::size_t number, std::size_t total) { - std::size_t ratio = total > 0 ? CATCH_CONFIG_CONSOLE_WIDTH * number / total : 0; - return (ratio == 0 && number > 0) ? 1 : ratio; -} - -std::size_t& findMax(std::size_t& i, std::size_t& j, std::size_t& k) { - if (i > j && i > k) - return i; - else if (j > k) - return j; - else - return k; -} - -struct ColumnInfo { - enum Justification { Left, Right }; - std::string name; - int width; - Justification justification; -}; -struct ColumnBreak {}; -struct RowBreak {}; - -class Duration { - enum class Unit { - Auto, - Nanoseconds, - Microseconds, - Milliseconds, - Seconds, - Minutes - }; - static const uint64_t s_nanosecondsInAMicrosecond = 1000; - static const uint64_t s_nanosecondsInAMillisecond = 1000 * s_nanosecondsInAMicrosecond; - static const uint64_t s_nanosecondsInASecond = 1000 * s_nanosecondsInAMillisecond; - static const uint64_t s_nanosecondsInAMinute = 60 * s_nanosecondsInASecond; - - double m_inNanoseconds; - Unit m_units; - -public: - explicit Duration(double inNanoseconds, Unit units = Unit::Auto) - : m_inNanoseconds(inNanoseconds), - m_units(units) { - if (m_units == Unit::Auto) { - if (m_inNanoseconds < s_nanosecondsInAMicrosecond) - m_units = Unit::Nanoseconds; - else if (m_inNanoseconds < s_nanosecondsInAMillisecond) - m_units = Unit::Microseconds; - else if (m_inNanoseconds < s_nanosecondsInASecond) - m_units = Unit::Milliseconds; - else if (m_inNanoseconds < s_nanosecondsInAMinute) - m_units = Unit::Seconds; - else - m_units = Unit::Minutes; - } - - } - - auto value() const -> double { - switch (m_units) { - case Unit::Microseconds: - return m_inNanoseconds / static_cast<double>(s_nanosecondsInAMicrosecond); - case Unit::Milliseconds: - return m_inNanoseconds / static_cast<double>(s_nanosecondsInAMillisecond); - case Unit::Seconds: - return m_inNanoseconds / static_cast<double>(s_nanosecondsInASecond); - case Unit::Minutes: - return m_inNanoseconds / static_cast<double>(s_nanosecondsInAMinute); - default: - return m_inNanoseconds; - } - } - auto unitsAsString() const -> std::string { - switch (m_units) { - case Unit::Nanoseconds: - return "ns"; - case Unit::Microseconds: - return "us"; - case Unit::Milliseconds: - return "ms"; - case Unit::Seconds: - return "s"; - case Unit::Minutes: - return "m"; - default: - return "** internal error **"; - } - - } - friend auto operator << (std::ostream& os, Duration const& duration) -> std::ostream& { - return os << duration.value() << ' ' << duration.unitsAsString(); - } -}; -} // end anon namespace - -class TablePrinter { - std::ostream& m_os; - std::vector<ColumnInfo> m_columnInfos; - std::ostringstream m_oss; - int m_currentColumn = -1; - bool m_isOpen = false; - -public: - TablePrinter( std::ostream& os, std::vector<ColumnInfo> columnInfos ) - : m_os( os ), - m_columnInfos( std::move( columnInfos ) ) {} - - auto columnInfos() const -> std::vector<ColumnInfo> const& { - return m_columnInfos; - } - - void open() { - if (!m_isOpen) { - m_isOpen = true; - *this << RowBreak(); - - Columns headerCols; - Spacer spacer(2); - for (auto const& info : m_columnInfos) { - headerCols += Column(info.name).width(static_cast<std::size_t>(info.width - 2)); - headerCols += spacer; - } - m_os << headerCols << '\n'; - - m_os << Catch::getLineOfChars<'-'>() << '\n'; - } - } - void close() { - if (m_isOpen) { - *this << RowBreak(); - m_os << std::endl; - m_isOpen = false; - } - } - - template<typename T> - friend TablePrinter& operator << (TablePrinter& tp, T const& value) { - tp.m_oss << value; - return tp; - } - - friend TablePrinter& operator << (TablePrinter& tp, ColumnBreak) { - auto colStr = tp.m_oss.str(); - const auto strSize = colStr.size(); - tp.m_oss.str(""); - tp.open(); - if (tp.m_currentColumn == static_cast<int>(tp.m_columnInfos.size() - 1)) { - tp.m_currentColumn = -1; - tp.m_os << '\n'; - } - tp.m_currentColumn++; - - auto colInfo = tp.m_columnInfos[tp.m_currentColumn]; - auto padding = (strSize + 1 < static_cast<std::size_t>(colInfo.width)) - ? std::string(colInfo.width - (strSize + 1), ' ') - : std::string(); - if (colInfo.justification == ColumnInfo::Left) - tp.m_os << colStr << padding << ' '; - else - tp.m_os << padding << colStr << ' '; - return tp; - } - - friend TablePrinter& operator << (TablePrinter& tp, RowBreak) { - if (tp.m_currentColumn > 0) { - tp.m_os << '\n'; - tp.m_currentColumn = -1; - } - return tp; - } -}; - -ConsoleReporter::ConsoleReporter(ReporterConfig const& config) - : StreamingReporterBase(config), - m_tablePrinter(new TablePrinter(config.stream(), - [&config]() -> std::vector<ColumnInfo> { - if (config.fullConfig()->benchmarkNoAnalysis()) - { - return{ - { "benchmark name", CATCH_CONFIG_CONSOLE_WIDTH - 43, ColumnInfo::Left }, - { " samples", 14, ColumnInfo::Right }, - { " iterations", 14, ColumnInfo::Right }, - { " mean", 14, ColumnInfo::Right } - }; - } - else - { - return{ - { "benchmark name", CATCH_CONFIG_CONSOLE_WIDTH - 43, ColumnInfo::Left }, - { "samples mean std dev", 14, ColumnInfo::Right }, - { "iterations low mean low std dev", 14, ColumnInfo::Right }, - { "estimated high mean high std dev", 14, ColumnInfo::Right } - }; - } - }())) {} -ConsoleReporter::~ConsoleReporter() = default; - -std::string ConsoleReporter::getDescription() { - return "Reports test results as plain lines of text"; -} - -void ConsoleReporter::noMatchingTestCases(std::string const& spec) { - stream << "No test cases matched '" << spec << '\'' << std::endl; -} - -void ConsoleReporter::reportInvalidArguments(std::string const&arg){ - stream << "Invalid Filter: " << arg << std::endl; -} - -void ConsoleReporter::assertionStarting(AssertionInfo const&) {} - -bool ConsoleReporter::assertionEnded(AssertionStats const& _assertionStats) { - AssertionResult const& result = _assertionStats.assertionResult; - - bool includeResults = m_config->includeSuccessfulResults() || !result.isOk(); - - // Drop out if result was successful but we're not printing them. - if (!includeResults && result.getResultType() != ResultWas::Warning) - return false; - - lazyPrint(); - - ConsoleAssertionPrinter printer(stream, _assertionStats, includeResults); - printer.print(); - stream << std::endl; - return true; -} - -void ConsoleReporter::sectionStarting(SectionInfo const& _sectionInfo) { - m_tablePrinter->close(); - m_headerPrinted = false; - StreamingReporterBase::sectionStarting(_sectionInfo); -} -void ConsoleReporter::sectionEnded(SectionStats const& _sectionStats) { - m_tablePrinter->close(); - if (_sectionStats.missingAssertions) { - lazyPrint(); - Colour colour(Colour::ResultError); - if (m_sectionStack.size() > 1) - stream << "\nNo assertions in section"; - else - stream << "\nNo assertions in test case"; - stream << " '" << _sectionStats.sectionInfo.name << "'\n" << std::endl; - } - if (m_config->showDurations() == ShowDurations::Always) { - stream << getFormattedDuration(_sectionStats.durationInSeconds) << " s: " << _sectionStats.sectionInfo.name << std::endl; - } - if (m_headerPrinted) { - m_headerPrinted = false; - } - StreamingReporterBase::sectionEnded(_sectionStats); -} - -#if defined(CATCH_CONFIG_ENABLE_BENCHMARKING) -void ConsoleReporter::benchmarkPreparing(std::string const& name) { - lazyPrintWithoutClosingBenchmarkTable(); - - auto nameCol = Column(name).width(static_cast<std::size_t>(m_tablePrinter->columnInfos()[0].width - 2)); - - bool firstLine = true; - for (auto line : nameCol) { - if (!firstLine) - (*m_tablePrinter) << ColumnBreak() << ColumnBreak() << ColumnBreak(); - else - firstLine = false; - - (*m_tablePrinter) << line << ColumnBreak(); - } -} - -void ConsoleReporter::benchmarkStarting(BenchmarkInfo const& info) { - (*m_tablePrinter) << info.samples << ColumnBreak() - << info.iterations << ColumnBreak(); - if (!m_config->benchmarkNoAnalysis()) - (*m_tablePrinter) << Duration(info.estimatedDuration) << ColumnBreak(); -} -void ConsoleReporter::benchmarkEnded(BenchmarkStats<> const& stats) { - if (m_config->benchmarkNoAnalysis()) - { - (*m_tablePrinter) << Duration(stats.mean.point.count()) << ColumnBreak(); - } - else - { - (*m_tablePrinter) << ColumnBreak() - << Duration(stats.mean.point.count()) << ColumnBreak() - << Duration(stats.mean.lower_bound.count()) << ColumnBreak() - << Duration(stats.mean.upper_bound.count()) << ColumnBreak() << ColumnBreak() - << Duration(stats.standardDeviation.point.count()) << ColumnBreak() - << Duration(stats.standardDeviation.lower_bound.count()) << ColumnBreak() - << Duration(stats.standardDeviation.upper_bound.count()) << ColumnBreak() << ColumnBreak() << ColumnBreak() << ColumnBreak() << ColumnBreak(); - } -} - -void ConsoleReporter::benchmarkFailed(std::string const& error) { - Colour colour(Colour::Red); - (*m_tablePrinter) - << "Benchmark failed (" << error << ')' - << ColumnBreak() << RowBreak(); -} -#endif // CATCH_CONFIG_ENABLE_BENCHMARKING - -void ConsoleReporter::testCaseEnded(TestCaseStats const& _testCaseStats) { - m_tablePrinter->close(); - StreamingReporterBase::testCaseEnded(_testCaseStats); - m_headerPrinted = false; -} -void ConsoleReporter::testGroupEnded(TestGroupStats const& _testGroupStats) { - if (currentGroupInfo.used) { - printSummaryDivider(); - stream << "Summary for group '" << _testGroupStats.groupInfo.name << "':\n"; - printTotals(_testGroupStats.totals); - stream << '\n' << std::endl; - } - StreamingReporterBase::testGroupEnded(_testGroupStats); -} -void ConsoleReporter::testRunEnded(TestRunStats const& _testRunStats) { - printTotalsDivider(_testRunStats.totals); - printTotals(_testRunStats.totals); - stream << std::endl; - StreamingReporterBase::testRunEnded(_testRunStats); -} -void ConsoleReporter::testRunStarting(TestRunInfo const& _testInfo) { - StreamingReporterBase::testRunStarting(_testInfo); - printTestFilters(); -} - -void ConsoleReporter::lazyPrint() { - - m_tablePrinter->close(); - lazyPrintWithoutClosingBenchmarkTable(); -} - -void ConsoleReporter::lazyPrintWithoutClosingBenchmarkTable() { - - if (!currentTestRunInfo.used) - lazyPrintRunInfo(); - if (!currentGroupInfo.used) - lazyPrintGroupInfo(); - - if (!m_headerPrinted) { - printTestCaseAndSectionHeader(); - m_headerPrinted = true; - } -} -void ConsoleReporter::lazyPrintRunInfo() { - stream << '\n' << getLineOfChars<'~'>() << '\n'; - Colour colour(Colour::SecondaryText); - stream << currentTestRunInfo->name - << " is a Catch v" << libraryVersion() << " host application.\n" - << "Run with -? for options\n\n"; - - if (m_config->rngSeed() != 0) - stream << "Randomness seeded to: " << m_config->rngSeed() << "\n\n"; - - currentTestRunInfo.used = true; -} -void ConsoleReporter::lazyPrintGroupInfo() { - if (!currentGroupInfo->name.empty() && currentGroupInfo->groupsCounts > 1) { - printClosedHeader("Group: " + currentGroupInfo->name); - currentGroupInfo.used = true; - } -} -void ConsoleReporter::printTestCaseAndSectionHeader() { - assert(!m_sectionStack.empty()); - printOpenHeader(currentTestCaseInfo->name); - - if (m_sectionStack.size() > 1) { - Colour colourGuard(Colour::Headers); - - auto - it = m_sectionStack.begin() + 1, // Skip first section (test case) - itEnd = m_sectionStack.end(); - for (; it != itEnd; ++it) - printHeaderString(it->name, 2); - } - - SourceLineInfo lineInfo = m_sectionStack.back().lineInfo; - - stream << getLineOfChars<'-'>() << '\n'; - Colour colourGuard(Colour::FileName); - stream << lineInfo << '\n'; - stream << getLineOfChars<'.'>() << '\n' << std::endl; -} - -void ConsoleReporter::printClosedHeader(std::string const& _name) { - printOpenHeader(_name); - stream << getLineOfChars<'.'>() << '\n'; -} -void ConsoleReporter::printOpenHeader(std::string const& _name) { - stream << getLineOfChars<'-'>() << '\n'; - { - Colour colourGuard(Colour::Headers); - printHeaderString(_name); - } -} - -// if string has a : in first line will set indent to follow it on -// subsequent lines -void ConsoleReporter::printHeaderString(std::string const& _string, std::size_t indent) { - std::size_t i = _string.find(": "); - if (i != std::string::npos) - i += 2; - else - i = 0; - stream << Column(_string).indent(indent + i).initialIndent(indent) << '\n'; -} - -struct SummaryColumn { - - SummaryColumn( std::string _label, Colour::Code _colour ) - : label( std::move( _label ) ), - colour( _colour ) {} - SummaryColumn addRow( std::size_t count ) { - ReusableStringStream rss; - rss << count; - std::string row = rss.str(); - for (auto& oldRow : rows) { - while (oldRow.size() < row.size()) - oldRow = ' ' + oldRow; - while (oldRow.size() > row.size()) - row = ' ' + row; - } - rows.push_back(row); - return *this; - } - - std::string label; - Colour::Code colour; - std::vector<std::string> rows; - -}; - -void ConsoleReporter::printTotals( Totals const& totals ) { - if (totals.testCases.total() == 0) { - stream << Colour(Colour::Warning) << "No tests ran\n"; - } else if (totals.assertions.total() > 0 && totals.testCases.allPassed()) { - stream << Colour(Colour::ResultSuccess) << "All tests passed"; - stream << " (" - << pluralise(totals.assertions.passed, "assertion") << " in " - << pluralise(totals.testCases.passed, "test case") << ')' - << '\n'; - } else { - - std::vector<SummaryColumn> columns; - columns.push_back(SummaryColumn("", Colour::None) - .addRow(totals.testCases.total()) - .addRow(totals.assertions.total())); - columns.push_back(SummaryColumn("passed", Colour::Success) - .addRow(totals.testCases.passed) - .addRow(totals.assertions.passed)); - columns.push_back(SummaryColumn("failed", Colour::ResultError) - .addRow(totals.testCases.failed) - .addRow(totals.assertions.failed)); - columns.push_back(SummaryColumn("failed as expected", Colour::ResultExpectedFailure) - .addRow(totals.testCases.failedButOk) - .addRow(totals.assertions.failedButOk)); - - printSummaryRow("test cases", columns, 0); - printSummaryRow("assertions", columns, 1); - } -} -void ConsoleReporter::printSummaryRow(std::string const& label, std::vector<SummaryColumn> const& cols, std::size_t row) { - for (auto col : cols) { - std::string value = col.rows[row]; - if (col.label.empty()) { - stream << label << ": "; - if (value != "0") - stream << value; - else - stream << Colour(Colour::Warning) << "- none -"; - } else if (value != "0") { - stream << Colour(Colour::LightGrey) << " | "; - stream << Colour(col.colour) - << value << ' ' << col.label; - } - } - stream << '\n'; -} - -void ConsoleReporter::printTotalsDivider(Totals const& totals) { - if (totals.testCases.total() > 0) { - std::size_t failedRatio = makeRatio(totals.testCases.failed, totals.testCases.total()); - std::size_t failedButOkRatio = makeRatio(totals.testCases.failedButOk, totals.testCases.total()); - std::size_t passedRatio = makeRatio(totals.testCases.passed, totals.testCases.total()); - while (failedRatio + failedButOkRatio + passedRatio < CATCH_CONFIG_CONSOLE_WIDTH - 1) - findMax(failedRatio, failedButOkRatio, passedRatio)++; - while (failedRatio + failedButOkRatio + passedRatio > CATCH_CONFIG_CONSOLE_WIDTH - 1) - findMax(failedRatio, failedButOkRatio, passedRatio)--; - - stream << Colour(Colour::Error) << std::string(failedRatio, '='); - stream << Colour(Colour::ResultExpectedFailure) << std::string(failedButOkRatio, '='); - if (totals.testCases.allPassed()) - stream << Colour(Colour::ResultSuccess) << std::string(passedRatio, '='); - else - stream << Colour(Colour::Success) << std::string(passedRatio, '='); - } else { - stream << Colour(Colour::Warning) << std::string(CATCH_CONFIG_CONSOLE_WIDTH - 1, '='); - } - stream << '\n'; -} -void ConsoleReporter::printSummaryDivider() { - stream << getLineOfChars<'-'>() << '\n'; -} - -void ConsoleReporter::printTestFilters() { - if (m_config->testSpec().hasFilters()) { - Colour guard(Colour::BrightYellow); - stream << "Filters: " << serializeFilters(m_config->getTestsOrTags()) << '\n'; - } -} - -CATCH_REGISTER_REPORTER("console", ConsoleReporter) - -} // end namespace Catch - -#if defined(_MSC_VER) -#pragma warning(pop) -#endif - -#if defined(__clang__) -# pragma clang diagnostic pop -#endif -// end catch_reporter_console.cpp -// start catch_reporter_junit.cpp - -#include <cassert> -#include <sstream> -#include <ctime> -#include <algorithm> - -namespace Catch { - - namespace { - std::string getCurrentTimestamp() { - // Beware, this is not reentrant because of backward compatibility issues - // Also, UTC only, again because of backward compatibility (%z is C++11) - time_t rawtime; - std::time(&rawtime); - auto const timeStampSize = sizeof("2017-01-16T17:06:45Z"); - -#ifdef _MSC_VER - std::tm timeInfo = {}; - gmtime_s(&timeInfo, &rawtime); -#else - std::tm* timeInfo; - timeInfo = std::gmtime(&rawtime); -#endif - - char timeStamp[timeStampSize]; - const char * const fmt = "%Y-%m-%dT%H:%M:%SZ"; - -#ifdef _MSC_VER - std::strftime(timeStamp, timeStampSize, fmt, &timeInfo); -#else - std::strftime(timeStamp, timeStampSize, fmt, timeInfo); -#endif - return std::string(timeStamp); - } - - std::string fileNameTag(const std::vector<std::string> &tags) { - auto it = std::find_if(begin(tags), - end(tags), - [] (std::string const& tag) {return tag.front() == '#'; }); - if (it != tags.end()) - return it->substr(1); - return std::string(); - } - } // anonymous namespace - - JunitReporter::JunitReporter( ReporterConfig const& _config ) - : CumulativeReporterBase( _config ), - xml( _config.stream() ) - { - m_reporterPrefs.shouldRedirectStdOut = true; - m_reporterPrefs.shouldReportAllAssertions = true; - } - - JunitReporter::~JunitReporter() {} - - std::string JunitReporter::getDescription() { - return "Reports test results in an XML format that looks like Ant's junitreport target"; - } - - void JunitReporter::noMatchingTestCases( std::string const& /*spec*/ ) {} - - void JunitReporter::testRunStarting( TestRunInfo const& runInfo ) { - CumulativeReporterBase::testRunStarting( runInfo ); - xml.startElement( "testsuites" ); - } - - void JunitReporter::testGroupStarting( GroupInfo const& groupInfo ) { - suiteTimer.start(); - stdOutForSuite.clear(); - stdErrForSuite.clear(); - unexpectedExceptions = 0; - CumulativeReporterBase::testGroupStarting( groupInfo ); - } - - void JunitReporter::testCaseStarting( TestCaseInfo const& testCaseInfo ) { - m_okToFail = testCaseInfo.okToFail(); - } - - bool JunitReporter::assertionEnded( AssertionStats const& assertionStats ) { - if( assertionStats.assertionResult.getResultType() == ResultWas::ThrewException && !m_okToFail ) - unexpectedExceptions++; - return CumulativeReporterBase::assertionEnded( assertionStats ); - } - - void JunitReporter::testCaseEnded( TestCaseStats const& testCaseStats ) { - stdOutForSuite += testCaseStats.stdOut; - stdErrForSuite += testCaseStats.stdErr; - CumulativeReporterBase::testCaseEnded( testCaseStats ); - } - - void JunitReporter::testGroupEnded( TestGroupStats const& testGroupStats ) { - double suiteTime = suiteTimer.getElapsedSeconds(); - CumulativeReporterBase::testGroupEnded( testGroupStats ); - writeGroup( *m_testGroups.back(), suiteTime ); - } - - void JunitReporter::testRunEndedCumulative() { - xml.endElement(); - } - - void JunitReporter::writeGroup( TestGroupNode const& groupNode, double suiteTime ) { - XmlWriter::ScopedElement e = xml.scopedElement( "testsuite" ); - - TestGroupStats const& stats = groupNode.value; - xml.writeAttribute( "name", stats.groupInfo.name ); - xml.writeAttribute( "errors", unexpectedExceptions ); - xml.writeAttribute( "failures", stats.totals.assertions.failed-unexpectedExceptions ); - xml.writeAttribute( "tests", stats.totals.assertions.total() ); - xml.writeAttribute( "hostname", "tbd" ); // !TBD - if( m_config->showDurations() == ShowDurations::Never ) - xml.writeAttribute( "time", "" ); - else - xml.writeAttribute( "time", suiteTime ); - xml.writeAttribute( "timestamp", getCurrentTimestamp() ); - - // Write properties if there are any - if (m_config->hasTestFilters() || m_config->rngSeed() != 0) { - auto properties = xml.scopedElement("properties"); - if (m_config->hasTestFilters()) { - xml.scopedElement("property") - .writeAttribute("name", "filters") - .writeAttribute("value", serializeFilters(m_config->getTestsOrTags())); - } - if (m_config->rngSeed() != 0) { - xml.scopedElement("property") - .writeAttribute("name", "random-seed") - .writeAttribute("value", m_config->rngSeed()); - } - } - - // Write test cases - for( auto const& child : groupNode.children ) - writeTestCase( *child ); - - xml.scopedElement( "system-out" ).writeText( trim( stdOutForSuite ), XmlFormatting::Newline ); - xml.scopedElement( "system-err" ).writeText( trim( stdErrForSuite ), XmlFormatting::Newline ); - } - - void JunitReporter::writeTestCase( TestCaseNode const& testCaseNode ) { - TestCaseStats const& stats = testCaseNode.value; - - // All test cases have exactly one section - which represents the - // test case itself. That section may have 0-n nested sections - assert( testCaseNode.children.size() == 1 ); - SectionNode const& rootSection = *testCaseNode.children.front(); - - std::string className = stats.testInfo.className; - - if( className.empty() ) { - className = fileNameTag(stats.testInfo.tags); - if ( className.empty() ) - className = "global"; - } - - if ( !m_config->name().empty() ) - className = m_config->name() + "." + className; - - writeSection( className, "", rootSection ); - } - - void JunitReporter::writeSection( std::string const& className, - std::string const& rootName, - SectionNode const& sectionNode ) { - std::string name = trim( sectionNode.stats.sectionInfo.name ); - if( !rootName.empty() ) - name = rootName + '/' + name; - - if( !sectionNode.assertions.empty() || - !sectionNode.stdOut.empty() || - !sectionNode.stdErr.empty() ) { - XmlWriter::ScopedElement e = xml.scopedElement( "testcase" ); - if( className.empty() ) { - xml.writeAttribute( "classname", name ); - xml.writeAttribute( "name", "root" ); - } - else { - xml.writeAttribute( "classname", className ); - xml.writeAttribute( "name", name ); - } - xml.writeAttribute( "time", ::Catch::Detail::stringify( sectionNode.stats.durationInSeconds ) ); - - writeAssertions( sectionNode ); - - if( !sectionNode.stdOut.empty() ) - xml.scopedElement( "system-out" ).writeText( trim( sectionNode.stdOut ), XmlFormatting::Newline ); - if( !sectionNode.stdErr.empty() ) - xml.scopedElement( "system-err" ).writeText( trim( sectionNode.stdErr ), XmlFormatting::Newline ); - } - for( auto const& childNode : sectionNode.childSections ) - if( className.empty() ) - writeSection( name, "", *childNode ); - else - writeSection( className, name, *childNode ); - } - - void JunitReporter::writeAssertions( SectionNode const& sectionNode ) { - for( auto const& assertion : sectionNode.assertions ) - writeAssertion( assertion ); - } - - void JunitReporter::writeAssertion( AssertionStats const& stats ) { - AssertionResult const& result = stats.assertionResult; - if( !result.isOk() ) { - std::string elementName; - switch( result.getResultType() ) { - case ResultWas::ThrewException: - case ResultWas::FatalErrorCondition: - elementName = "error"; - break; - case ResultWas::ExplicitFailure: - case ResultWas::ExpressionFailed: - case ResultWas::DidntThrowException: - elementName = "failure"; - break; - - // We should never see these here: - case ResultWas::Info: - case ResultWas::Warning: - case ResultWas::Ok: - case ResultWas::Unknown: - case ResultWas::FailureBit: - case ResultWas::Exception: - elementName = "internalError"; - break; - } - - XmlWriter::ScopedElement e = xml.scopedElement( elementName ); - - xml.writeAttribute( "message", result.getExpression() ); - xml.writeAttribute( "type", result.getTestMacroName() ); - - ReusableStringStream rss; - if (stats.totals.assertions.total() > 0) { - rss << "FAILED" << ":\n"; - if (result.hasExpression()) { - rss << " "; - rss << result.getExpressionInMacro(); - rss << '\n'; - } - if (result.hasExpandedExpression()) { - rss << "with expansion:\n"; - rss << Column(result.getExpandedExpression()).indent(2) << '\n'; - } - } else { - rss << '\n'; - } - - if( !result.getMessage().empty() ) - rss << result.getMessage() << '\n'; - for( auto const& msg : stats.infoMessages ) - if( msg.type == ResultWas::Info ) - rss << msg.message << '\n'; - - rss << "at " << result.getSourceInfo(); - xml.writeText( rss.str(), XmlFormatting::Newline ); - } - } - - CATCH_REGISTER_REPORTER( "junit", JunitReporter ) - -} // end namespace Catch -// end catch_reporter_junit.cpp -// start catch_reporter_listening.cpp - -#include <cassert> - -namespace Catch { - - ListeningReporter::ListeningReporter() { - // We will assume that listeners will always want all assertions - m_preferences.shouldReportAllAssertions = true; - } - - void ListeningReporter::addListener( IStreamingReporterPtr&& listener ) { - m_listeners.push_back( std::move( listener ) ); - } - - void ListeningReporter::addReporter(IStreamingReporterPtr&& reporter) { - assert(!m_reporter && "Listening reporter can wrap only 1 real reporter"); - m_reporter = std::move( reporter ); - m_preferences.shouldRedirectStdOut = m_reporter->getPreferences().shouldRedirectStdOut; - } - - ReporterPreferences ListeningReporter::getPreferences() const { - return m_preferences; - } - - std::set<Verbosity> ListeningReporter::getSupportedVerbosities() { - return std::set<Verbosity>{ }; - } - - void ListeningReporter::noMatchingTestCases( std::string const& spec ) { - for ( auto const& listener : m_listeners ) { - listener->noMatchingTestCases( spec ); - } - m_reporter->noMatchingTestCases( spec ); - } - - void ListeningReporter::reportInvalidArguments(std::string const&arg){ - for ( auto const& listener : m_listeners ) { - listener->reportInvalidArguments( arg ); - } - m_reporter->reportInvalidArguments( arg ); - } - -#if defined(CATCH_CONFIG_ENABLE_BENCHMARKING) - void ListeningReporter::benchmarkPreparing( std::string const& name ) { - for (auto const& listener : m_listeners) { - listener->benchmarkPreparing(name); - } - m_reporter->benchmarkPreparing(name); - } - void ListeningReporter::benchmarkStarting( BenchmarkInfo const& benchmarkInfo ) { - for ( auto const& listener : m_listeners ) { - listener->benchmarkStarting( benchmarkInfo ); - } - m_reporter->benchmarkStarting( benchmarkInfo ); - } - void ListeningReporter::benchmarkEnded( BenchmarkStats<> const& benchmarkStats ) { - for ( auto const& listener : m_listeners ) { - listener->benchmarkEnded( benchmarkStats ); - } - m_reporter->benchmarkEnded( benchmarkStats ); - } - - void ListeningReporter::benchmarkFailed( std::string const& error ) { - for (auto const& listener : m_listeners) { - listener->benchmarkFailed(error); - } - m_reporter->benchmarkFailed(error); - } -#endif // CATCH_CONFIG_ENABLE_BENCHMARKING - - void ListeningReporter::testRunStarting( TestRunInfo const& testRunInfo ) { - for ( auto const& listener : m_listeners ) { - listener->testRunStarting( testRunInfo ); - } - m_reporter->testRunStarting( testRunInfo ); - } - - void ListeningReporter::testGroupStarting( GroupInfo const& groupInfo ) { - for ( auto const& listener : m_listeners ) { - listener->testGroupStarting( groupInfo ); - } - m_reporter->testGroupStarting( groupInfo ); - } - - void ListeningReporter::testCaseStarting( TestCaseInfo const& testInfo ) { - for ( auto const& listener : m_listeners ) { - listener->testCaseStarting( testInfo ); - } - m_reporter->testCaseStarting( testInfo ); - } - - void ListeningReporter::sectionStarting( SectionInfo const& sectionInfo ) { - for ( auto const& listener : m_listeners ) { - listener->sectionStarting( sectionInfo ); - } - m_reporter->sectionStarting( sectionInfo ); - } - - void ListeningReporter::assertionStarting( AssertionInfo const& assertionInfo ) { - for ( auto const& listener : m_listeners ) { - listener->assertionStarting( assertionInfo ); - } - m_reporter->assertionStarting( assertionInfo ); - } - - // The return value indicates if the messages buffer should be cleared: - bool ListeningReporter::assertionEnded( AssertionStats const& assertionStats ) { - for( auto const& listener : m_listeners ) { - static_cast<void>( listener->assertionEnded( assertionStats ) ); - } - return m_reporter->assertionEnded( assertionStats ); - } - - void ListeningReporter::sectionEnded( SectionStats const& sectionStats ) { - for ( auto const& listener : m_listeners ) { - listener->sectionEnded( sectionStats ); - } - m_reporter->sectionEnded( sectionStats ); - } - - void ListeningReporter::testCaseEnded( TestCaseStats const& testCaseStats ) { - for ( auto const& listener : m_listeners ) { - listener->testCaseEnded( testCaseStats ); - } - m_reporter->testCaseEnded( testCaseStats ); - } - - void ListeningReporter::testGroupEnded( TestGroupStats const& testGroupStats ) { - for ( auto const& listener : m_listeners ) { - listener->testGroupEnded( testGroupStats ); - } - m_reporter->testGroupEnded( testGroupStats ); - } - - void ListeningReporter::testRunEnded( TestRunStats const& testRunStats ) { - for ( auto const& listener : m_listeners ) { - listener->testRunEnded( testRunStats ); - } - m_reporter->testRunEnded( testRunStats ); - } - - void ListeningReporter::skipTest( TestCaseInfo const& testInfo ) { - for ( auto const& listener : m_listeners ) { - listener->skipTest( testInfo ); - } - m_reporter->skipTest( testInfo ); - } - - bool ListeningReporter::isMulti() const { - return true; - } - -} // end namespace Catch -// end catch_reporter_listening.cpp -// start catch_reporter_xml.cpp - -#if defined(_MSC_VER) -#pragma warning(push) -#pragma warning(disable:4061) // Not all labels are EXPLICITLY handled in switch - // Note that 4062 (not all labels are handled - // and default is missing) is enabled -#endif - -namespace Catch { - XmlReporter::XmlReporter( ReporterConfig const& _config ) - : StreamingReporterBase( _config ), - m_xml(_config.stream()) - { - m_reporterPrefs.shouldRedirectStdOut = true; - m_reporterPrefs.shouldReportAllAssertions = true; - } - - XmlReporter::~XmlReporter() = default; - - std::string XmlReporter::getDescription() { - return "Reports test results as an XML document"; - } - - std::string XmlReporter::getStylesheetRef() const { - return std::string(); - } - - void XmlReporter::writeSourceInfo( SourceLineInfo const& sourceInfo ) { - m_xml - .writeAttribute( "filename", sourceInfo.file ) - .writeAttribute( "line", sourceInfo.line ); - } - - void XmlReporter::noMatchingTestCases( std::string const& s ) { - StreamingReporterBase::noMatchingTestCases( s ); - } - - void XmlReporter::testRunStarting( TestRunInfo const& testInfo ) { - StreamingReporterBase::testRunStarting( testInfo ); - std::string stylesheetRef = getStylesheetRef(); - if( !stylesheetRef.empty() ) - m_xml.writeStylesheetRef( stylesheetRef ); - m_xml.startElement( "Catch" ); - if( !m_config->name().empty() ) - m_xml.writeAttribute( "name", m_config->name() ); - if (m_config->testSpec().hasFilters()) - m_xml.writeAttribute( "filters", serializeFilters( m_config->getTestsOrTags() ) ); - if( m_config->rngSeed() != 0 ) - m_xml.scopedElement( "Randomness" ) - .writeAttribute( "seed", m_config->rngSeed() ); - } - - void XmlReporter::testGroupStarting( GroupInfo const& groupInfo ) { - StreamingReporterBase::testGroupStarting( groupInfo ); - m_xml.startElement( "Group" ) - .writeAttribute( "name", groupInfo.name ); - } - - void XmlReporter::testCaseStarting( TestCaseInfo const& testInfo ) { - StreamingReporterBase::testCaseStarting(testInfo); - m_xml.startElement( "TestCase" ) - .writeAttribute( "name", trim( testInfo.name ) ) - .writeAttribute( "description", testInfo.description ) - .writeAttribute( "tags", testInfo.tagsAsString() ); - - writeSourceInfo( testInfo.lineInfo ); - - if ( m_config->showDurations() == ShowDurations::Always ) - m_testCaseTimer.start(); - m_xml.ensureTagClosed(); - } - - void XmlReporter::sectionStarting( SectionInfo const& sectionInfo ) { - StreamingReporterBase::sectionStarting( sectionInfo ); - if( m_sectionDepth++ > 0 ) { - m_xml.startElement( "Section" ) - .writeAttribute( "name", trim( sectionInfo.name ) ); - writeSourceInfo( sectionInfo.lineInfo ); - m_xml.ensureTagClosed(); - } - } - - void XmlReporter::assertionStarting( AssertionInfo const& ) { } - - bool XmlReporter::assertionEnded( AssertionStats const& assertionStats ) { - - AssertionResult const& result = assertionStats.assertionResult; - - bool includeResults = m_config->includeSuccessfulResults() || !result.isOk(); - - if( includeResults || result.getResultType() == ResultWas::Warning ) { - // Print any info messages in <Info> tags. - for( auto const& msg : assertionStats.infoMessages ) { - if( msg.type == ResultWas::Info && includeResults ) { - m_xml.scopedElement( "Info" ) - .writeText( msg.message ); - } else if ( msg.type == ResultWas::Warning ) { - m_xml.scopedElement( "Warning" ) - .writeText( msg.message ); - } - } - } - - // Drop out if result was successful but we're not printing them. - if( !includeResults && result.getResultType() != ResultWas::Warning ) - return true; - - // Print the expression if there is one. - if( result.hasExpression() ) { - m_xml.startElement( "Expression" ) - .writeAttribute( "success", result.succeeded() ) - .writeAttribute( "type", result.getTestMacroName() ); - - writeSourceInfo( result.getSourceInfo() ); - - m_xml.scopedElement( "Original" ) - .writeText( result.getExpression() ); - m_xml.scopedElement( "Expanded" ) - .writeText( result.getExpandedExpression() ); - } - - // And... Print a result applicable to each result type. - switch( result.getResultType() ) { - case ResultWas::ThrewException: - m_xml.startElement( "Exception" ); - writeSourceInfo( result.getSourceInfo() ); - m_xml.writeText( result.getMessage() ); - m_xml.endElement(); - break; - case ResultWas::FatalErrorCondition: - m_xml.startElement( "FatalErrorCondition" ); - writeSourceInfo( result.getSourceInfo() ); - m_xml.writeText( result.getMessage() ); - m_xml.endElement(); - break; - case ResultWas::Info: - m_xml.scopedElement( "Info" ) - .writeText( result.getMessage() ); - break; - case ResultWas::Warning: - // Warning will already have been written - break; - case ResultWas::ExplicitFailure: - m_xml.startElement( "Failure" ); - writeSourceInfo( result.getSourceInfo() ); - m_xml.writeText( result.getMessage() ); - m_xml.endElement(); - break; - default: - break; - } - - if( result.hasExpression() ) - m_xml.endElement(); - - return true; - } - - void XmlReporter::sectionEnded( SectionStats const& sectionStats ) { - StreamingReporterBase::sectionEnded( sectionStats ); - if( --m_sectionDepth > 0 ) { - XmlWriter::ScopedElement e = m_xml.scopedElement( "OverallResults" ); - e.writeAttribute( "successes", sectionStats.assertions.passed ); - e.writeAttribute( "failures", sectionStats.assertions.failed ); - e.writeAttribute( "expectedFailures", sectionStats.assertions.failedButOk ); - - if ( m_config->showDurations() == ShowDurations::Always ) - e.writeAttribute( "durationInSeconds", sectionStats.durationInSeconds ); - - m_xml.endElement(); - } - } - - void XmlReporter::testCaseEnded( TestCaseStats const& testCaseStats ) { - StreamingReporterBase::testCaseEnded( testCaseStats ); - XmlWriter::ScopedElement e = m_xml.scopedElement( "OverallResult" ); - e.writeAttribute( "success", testCaseStats.totals.assertions.allOk() ); - - if ( m_config->showDurations() == ShowDurations::Always ) - e.writeAttribute( "durationInSeconds", m_testCaseTimer.getElapsedSeconds() ); - - if( !testCaseStats.stdOut.empty() ) - m_xml.scopedElement( "StdOut" ).writeText( trim( testCaseStats.stdOut ), XmlFormatting::Newline ); - if( !testCaseStats.stdErr.empty() ) - m_xml.scopedElement( "StdErr" ).writeText( trim( testCaseStats.stdErr ), XmlFormatting::Newline ); - - m_xml.endElement(); - } - - void XmlReporter::testGroupEnded( TestGroupStats const& testGroupStats ) { - StreamingReporterBase::testGroupEnded( testGroupStats ); - // TODO: Check testGroupStats.aborting and act accordingly. - m_xml.scopedElement( "OverallResults" ) - .writeAttribute( "successes", testGroupStats.totals.assertions.passed ) - .writeAttribute( "failures", testGroupStats.totals.assertions.failed ) - .writeAttribute( "expectedFailures", testGroupStats.totals.assertions.failedButOk ); - m_xml.endElement(); - } - - void XmlReporter::testRunEnded( TestRunStats const& testRunStats ) { - StreamingReporterBase::testRunEnded( testRunStats ); - m_xml.scopedElement( "OverallResults" ) - .writeAttribute( "successes", testRunStats.totals.assertions.passed ) - .writeAttribute( "failures", testRunStats.totals.assertions.failed ) - .writeAttribute( "expectedFailures", testRunStats.totals.assertions.failedButOk ); - m_xml.endElement(); - } - -#if defined(CATCH_CONFIG_ENABLE_BENCHMARKING) - void XmlReporter::benchmarkPreparing(std::string const& name) { - m_xml.startElement("BenchmarkResults") - .writeAttribute("name", name); - } - - void XmlReporter::benchmarkStarting(BenchmarkInfo const &info) { - m_xml.writeAttribute("samples", info.samples) - .writeAttribute("resamples", info.resamples) - .writeAttribute("iterations", info.iterations) - .writeAttribute("clockResolution", info.clockResolution) - .writeAttribute("estimatedDuration", info.estimatedDuration) - .writeComment("All values in nano seconds"); - } - - void XmlReporter::benchmarkEnded(BenchmarkStats<> const& benchmarkStats) { - m_xml.startElement("mean") - .writeAttribute("value", benchmarkStats.mean.point.count()) - .writeAttribute("lowerBound", benchmarkStats.mean.lower_bound.count()) - .writeAttribute("upperBound", benchmarkStats.mean.upper_bound.count()) - .writeAttribute("ci", benchmarkStats.mean.confidence_interval); - m_xml.endElement(); - m_xml.startElement("standardDeviation") - .writeAttribute("value", benchmarkStats.standardDeviation.point.count()) - .writeAttribute("lowerBound", benchmarkStats.standardDeviation.lower_bound.count()) - .writeAttribute("upperBound", benchmarkStats.standardDeviation.upper_bound.count()) - .writeAttribute("ci", benchmarkStats.standardDeviation.confidence_interval); - m_xml.endElement(); - m_xml.startElement("outliers") - .writeAttribute("variance", benchmarkStats.outlierVariance) - .writeAttribute("lowMild", benchmarkStats.outliers.low_mild) - .writeAttribute("lowSevere", benchmarkStats.outliers.low_severe) - .writeAttribute("highMild", benchmarkStats.outliers.high_mild) - .writeAttribute("highSevere", benchmarkStats.outliers.high_severe); - m_xml.endElement(); - m_xml.endElement(); - } - - void XmlReporter::benchmarkFailed(std::string const &error) { - m_xml.scopedElement("failed"). - writeAttribute("message", error); - m_xml.endElement(); - } -#endif // CATCH_CONFIG_ENABLE_BENCHMARKING - - CATCH_REGISTER_REPORTER( "xml", XmlReporter ) - -} // end namespace Catch - -#if defined(_MSC_VER) -#pragma warning(pop) -#endif -// end catch_reporter_xml.cpp - -namespace Catch { - LeakDetector leakDetector; -} - -#ifdef __clang__ -#pragma clang diagnostic pop -#endif - -// end catch_impl.hpp -#endif - -#ifdef CATCH_CONFIG_MAIN -// start catch_default_main.hpp - -#ifndef __OBJC__ - -#if defined(CATCH_CONFIG_WCHAR) && defined(CATCH_PLATFORM_WINDOWS) && defined(_UNICODE) && !defined(DO_NOT_USE_WMAIN) -// Standard C/C++ Win32 Unicode wmain entry point -extern "C" int wmain (int argc, wchar_t * argv[], wchar_t * []) { -#else -// Standard C/C++ main entry point -int main (int argc, char * argv[]) { -#endif - - return Catch::Session().run( argc, argv ); -} - -#else // __OBJC__ - -// Objective-C entry point -int main (int argc, char * const argv[]) { -#if !CATCH_ARC_ENABLED - NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; -#endif - - Catch::registerTestMethods(); - int result = Catch::Session().run( argc, (char**)argv ); - -#if !CATCH_ARC_ENABLED - [pool drain]; -#endif - - return result; -} - -#endif // __OBJC__ - -// end catch_default_main.hpp -#endif - -#if !defined(CATCH_CONFIG_IMPL_ONLY) - -#ifdef CLARA_CONFIG_MAIN_NOT_DEFINED -# undef CLARA_CONFIG_MAIN -#endif - -#if !defined(CATCH_CONFIG_DISABLE) -////// -// If this config identifier is defined then all CATCH macros are prefixed with CATCH_ -#ifdef CATCH_CONFIG_PREFIX_ALL - -#define CATCH_REQUIRE( ... ) INTERNAL_CATCH_TEST( "CATCH_REQUIRE", Catch::ResultDisposition::Normal, __VA_ARGS__ ) -#define CATCH_REQUIRE_FALSE( ... ) INTERNAL_CATCH_TEST( "CATCH_REQUIRE_FALSE", Catch::ResultDisposition::Normal | Catch::ResultDisposition::FalseTest, __VA_ARGS__ ) - -#define CATCH_REQUIRE_THROWS( ... ) INTERNAL_CATCH_THROWS( "CATCH_REQUIRE_THROWS", Catch::ResultDisposition::Normal, __VA_ARGS__ ) -#define CATCH_REQUIRE_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( "CATCH_REQUIRE_THROWS_AS", exceptionType, Catch::ResultDisposition::Normal, expr ) -#define CATCH_REQUIRE_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS_STR_MATCHES( "CATCH_REQUIRE_THROWS_WITH", Catch::ResultDisposition::Normal, matcher, expr ) -#if !defined(CATCH_CONFIG_DISABLE_MATCHERS) -#define CATCH_REQUIRE_THROWS_MATCHES( expr, exceptionType, matcher ) INTERNAL_CATCH_THROWS_MATCHES( "CATCH_REQUIRE_THROWS_MATCHES", exceptionType, Catch::ResultDisposition::Normal, matcher, expr ) -#endif// CATCH_CONFIG_DISABLE_MATCHERS -#define CATCH_REQUIRE_NOTHROW( ... ) INTERNAL_CATCH_NO_THROW( "CATCH_REQUIRE_NOTHROW", Catch::ResultDisposition::Normal, __VA_ARGS__ ) - -#define CATCH_CHECK( ... ) INTERNAL_CATCH_TEST( "CATCH_CHECK", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) -#define CATCH_CHECK_FALSE( ... ) INTERNAL_CATCH_TEST( "CATCH_CHECK_FALSE", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::FalseTest, __VA_ARGS__ ) -#define CATCH_CHECKED_IF( ... ) INTERNAL_CATCH_IF( "CATCH_CHECKED_IF", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) -#define CATCH_CHECKED_ELSE( ... ) INTERNAL_CATCH_ELSE( "CATCH_CHECKED_ELSE", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) -#define CATCH_CHECK_NOFAIL( ... ) INTERNAL_CATCH_TEST( "CATCH_CHECK_NOFAIL", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::SuppressFail, __VA_ARGS__ ) - -#define CATCH_CHECK_THROWS( ... ) INTERNAL_CATCH_THROWS( "CATCH_CHECK_THROWS", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) -#define CATCH_CHECK_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( "CATCH_CHECK_THROWS_AS", exceptionType, Catch::ResultDisposition::ContinueOnFailure, expr ) -#define CATCH_CHECK_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS_STR_MATCHES( "CATCH_CHECK_THROWS_WITH", Catch::ResultDisposition::ContinueOnFailure, matcher, expr ) -#if !defined(CATCH_CONFIG_DISABLE_MATCHERS) -#define CATCH_CHECK_THROWS_MATCHES( expr, exceptionType, matcher ) INTERNAL_CATCH_THROWS_MATCHES( "CATCH_CHECK_THROWS_MATCHES", exceptionType, Catch::ResultDisposition::ContinueOnFailure, matcher, expr ) -#endif // CATCH_CONFIG_DISABLE_MATCHERS -#define CATCH_CHECK_NOTHROW( ... ) INTERNAL_CATCH_NO_THROW( "CATCH_CHECK_NOTHROW", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) - -#if !defined(CATCH_CONFIG_DISABLE_MATCHERS) -#define CATCH_CHECK_THAT( arg, matcher ) INTERNAL_CHECK_THAT( "CATCH_CHECK_THAT", matcher, Catch::ResultDisposition::ContinueOnFailure, arg ) - -#define CATCH_REQUIRE_THAT( arg, matcher ) INTERNAL_CHECK_THAT( "CATCH_REQUIRE_THAT", matcher, Catch::ResultDisposition::Normal, arg ) -#endif // CATCH_CONFIG_DISABLE_MATCHERS - -#define CATCH_INFO( msg ) INTERNAL_CATCH_INFO( "CATCH_INFO", msg ) -#define CATCH_UNSCOPED_INFO( msg ) INTERNAL_CATCH_UNSCOPED_INFO( "CATCH_UNSCOPED_INFO", msg ) -#define CATCH_WARN( msg ) INTERNAL_CATCH_MSG( "CATCH_WARN", Catch::ResultWas::Warning, Catch::ResultDisposition::ContinueOnFailure, msg ) -#define CATCH_CAPTURE( ... ) INTERNAL_CATCH_CAPTURE( INTERNAL_CATCH_UNIQUE_NAME(capturer), "CATCH_CAPTURE",__VA_ARGS__ ) - -#define CATCH_TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE( __VA_ARGS__ ) -#define CATCH_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, __VA_ARGS__ ) -#define CATCH_METHOD_AS_TEST_CASE( method, ... ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, __VA_ARGS__ ) -#define CATCH_REGISTER_TEST_CASE( Function, ... ) INTERNAL_CATCH_REGISTER_TESTCASE( Function, __VA_ARGS__ ) -#define CATCH_SECTION( ... ) INTERNAL_CATCH_SECTION( __VA_ARGS__ ) -#define CATCH_DYNAMIC_SECTION( ... ) INTERNAL_CATCH_DYNAMIC_SECTION( __VA_ARGS__ ) -#define CATCH_FAIL( ... ) INTERNAL_CATCH_MSG( "CATCH_FAIL", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, __VA_ARGS__ ) -#define CATCH_FAIL_CHECK( ... ) INTERNAL_CATCH_MSG( "CATCH_FAIL_CHECK", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) -#define CATCH_SUCCEED( ... ) INTERNAL_CATCH_MSG( "CATCH_SUCCEED", Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) - -#define CATCH_ANON_TEST_CASE() INTERNAL_CATCH_TESTCASE() - -#ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR -#define CATCH_TEMPLATE_TEST_CASE( ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE( __VA_ARGS__ ) -#define CATCH_TEMPLATE_TEST_CASE_SIG( ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG( __VA_ARGS__ ) -#define CATCH_TEMPLATE_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ ) -#define CATCH_TEMPLATE_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG( className, __VA_ARGS__ ) -#define CATCH_TEMPLATE_PRODUCT_TEST_CASE( ... ) INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE( __VA_ARGS__ ) -#define CATCH_TEMPLATE_PRODUCT_TEST_CASE_SIG( ... ) INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_SIG( __VA_ARGS__ ) -#define CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, __VA_ARGS__ ) -#define CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, __VA_ARGS__ ) -#else -#define CATCH_TEMPLATE_TEST_CASE( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE( __VA_ARGS__ ) ) -#define CATCH_TEMPLATE_TEST_CASE_SIG( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG( __VA_ARGS__ ) ) -#define CATCH_TEMPLATE_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ ) ) -#define CATCH_TEMPLATE_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG( className, __VA_ARGS__ ) ) -#define CATCH_TEMPLATE_PRODUCT_TEST_CASE( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE( __VA_ARGS__ ) ) -#define CATCH_TEMPLATE_PRODUCT_TEST_CASE_SIG( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_SIG( __VA_ARGS__ ) ) -#define CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, __VA_ARGS__ ) ) -#define CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, __VA_ARGS__ ) ) -#endif - -#if !defined(CATCH_CONFIG_RUNTIME_STATIC_REQUIRE) -#define CATCH_STATIC_REQUIRE( ... ) static_assert( __VA_ARGS__ , #__VA_ARGS__ ); CATCH_SUCCEED( #__VA_ARGS__ ) -#define CATCH_STATIC_REQUIRE_FALSE( ... ) static_assert( !(__VA_ARGS__), "!(" #__VA_ARGS__ ")" ); CATCH_SUCCEED( #__VA_ARGS__ ) -#else -#define CATCH_STATIC_REQUIRE( ... ) CATCH_REQUIRE( __VA_ARGS__ ) -#define CATCH_STATIC_REQUIRE_FALSE( ... ) CATCH_REQUIRE_FALSE( __VA_ARGS__ ) -#endif - -// "BDD-style" convenience wrappers -#define CATCH_SCENARIO( ... ) CATCH_TEST_CASE( "Scenario: " __VA_ARGS__ ) -#define CATCH_SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " __VA_ARGS__ ) -#define CATCH_GIVEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " Given: " << desc ) -#define CATCH_AND_GIVEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( "And given: " << desc ) -#define CATCH_WHEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " When: " << desc ) -#define CATCH_AND_WHEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " And when: " << desc ) -#define CATCH_THEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " Then: " << desc ) -#define CATCH_AND_THEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " And: " << desc ) - -#if defined(CATCH_CONFIG_ENABLE_BENCHMARKING) -#define CATCH_BENCHMARK(...) \ - INTERNAL_CATCH_BENCHMARK(INTERNAL_CATCH_UNIQUE_NAME(____C_A_T_C_H____B_E_N_C_H____), INTERNAL_CATCH_GET_1_ARG(__VA_ARGS__,,), INTERNAL_CATCH_GET_2_ARG(__VA_ARGS__,,)) -#define CATCH_BENCHMARK_ADVANCED(name) \ - INTERNAL_CATCH_BENCHMARK_ADVANCED(INTERNAL_CATCH_UNIQUE_NAME(____C_A_T_C_H____B_E_N_C_H____), name) -#endif // CATCH_CONFIG_ENABLE_BENCHMARKING - -// If CATCH_CONFIG_PREFIX_ALL is not defined then the CATCH_ prefix is not required -#else - -#define REQUIRE( ... ) INTERNAL_CATCH_TEST( "REQUIRE", Catch::ResultDisposition::Normal, __VA_ARGS__ ) -#define REQUIRE_FALSE( ... ) INTERNAL_CATCH_TEST( "REQUIRE_FALSE", Catch::ResultDisposition::Normal | Catch::ResultDisposition::FalseTest, __VA_ARGS__ ) - -#define REQUIRE_THROWS( ... ) INTERNAL_CATCH_THROWS( "REQUIRE_THROWS", Catch::ResultDisposition::Normal, __VA_ARGS__ ) -#define REQUIRE_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( "REQUIRE_THROWS_AS", exceptionType, Catch::ResultDisposition::Normal, expr ) -#define REQUIRE_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS_STR_MATCHES( "REQUIRE_THROWS_WITH", Catch::ResultDisposition::Normal, matcher, expr ) -#if !defined(CATCH_CONFIG_DISABLE_MATCHERS) -#define REQUIRE_THROWS_MATCHES( expr, exceptionType, matcher ) INTERNAL_CATCH_THROWS_MATCHES( "REQUIRE_THROWS_MATCHES", exceptionType, Catch::ResultDisposition::Normal, matcher, expr ) -#endif // CATCH_CONFIG_DISABLE_MATCHERS -#define REQUIRE_NOTHROW( ... ) INTERNAL_CATCH_NO_THROW( "REQUIRE_NOTHROW", Catch::ResultDisposition::Normal, __VA_ARGS__ ) - -#define CHECK( ... ) INTERNAL_CATCH_TEST( "CHECK", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) -#define CHECK_FALSE( ... ) INTERNAL_CATCH_TEST( "CHECK_FALSE", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::FalseTest, __VA_ARGS__ ) -#define CHECKED_IF( ... ) INTERNAL_CATCH_IF( "CHECKED_IF", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) -#define CHECKED_ELSE( ... ) INTERNAL_CATCH_ELSE( "CHECKED_ELSE", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) -#define CHECK_NOFAIL( ... ) INTERNAL_CATCH_TEST( "CHECK_NOFAIL", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::SuppressFail, __VA_ARGS__ ) - -#define CHECK_THROWS( ... ) INTERNAL_CATCH_THROWS( "CHECK_THROWS", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) -#define CHECK_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( "CHECK_THROWS_AS", exceptionType, Catch::ResultDisposition::ContinueOnFailure, expr ) -#define CHECK_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS_STR_MATCHES( "CHECK_THROWS_WITH", Catch::ResultDisposition::ContinueOnFailure, matcher, expr ) -#if !defined(CATCH_CONFIG_DISABLE_MATCHERS) -#define CHECK_THROWS_MATCHES( expr, exceptionType, matcher ) INTERNAL_CATCH_THROWS_MATCHES( "CHECK_THROWS_MATCHES", exceptionType, Catch::ResultDisposition::ContinueOnFailure, matcher, expr ) -#endif // CATCH_CONFIG_DISABLE_MATCHERS -#define CHECK_NOTHROW( ... ) INTERNAL_CATCH_NO_THROW( "CHECK_NOTHROW", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) - -#if !defined(CATCH_CONFIG_DISABLE_MATCHERS) -#define CHECK_THAT( arg, matcher ) INTERNAL_CHECK_THAT( "CHECK_THAT", matcher, Catch::ResultDisposition::ContinueOnFailure, arg ) - -#define REQUIRE_THAT( arg, matcher ) INTERNAL_CHECK_THAT( "REQUIRE_THAT", matcher, Catch::ResultDisposition::Normal, arg ) -#endif // CATCH_CONFIG_DISABLE_MATCHERS - -#define INFO( msg ) INTERNAL_CATCH_INFO( "INFO", msg ) -#define UNSCOPED_INFO( msg ) INTERNAL_CATCH_UNSCOPED_INFO( "UNSCOPED_INFO", msg ) -#define WARN( msg ) INTERNAL_CATCH_MSG( "WARN", Catch::ResultWas::Warning, Catch::ResultDisposition::ContinueOnFailure, msg ) -#define CAPTURE( ... ) INTERNAL_CATCH_CAPTURE( INTERNAL_CATCH_UNIQUE_NAME(capturer), "CAPTURE",__VA_ARGS__ ) - -#define TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE( __VA_ARGS__ ) -#define TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, __VA_ARGS__ ) -#define METHOD_AS_TEST_CASE( method, ... ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, __VA_ARGS__ ) -#define REGISTER_TEST_CASE( Function, ... ) INTERNAL_CATCH_REGISTER_TESTCASE( Function, __VA_ARGS__ ) -#define SECTION( ... ) INTERNAL_CATCH_SECTION( __VA_ARGS__ ) -#define DYNAMIC_SECTION( ... ) INTERNAL_CATCH_DYNAMIC_SECTION( __VA_ARGS__ ) -#define FAIL( ... ) INTERNAL_CATCH_MSG( "FAIL", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, __VA_ARGS__ ) -#define FAIL_CHECK( ... ) INTERNAL_CATCH_MSG( "FAIL_CHECK", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) -#define SUCCEED( ... ) INTERNAL_CATCH_MSG( "SUCCEED", Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) -#define ANON_TEST_CASE() INTERNAL_CATCH_TESTCASE() - -#ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR -#define TEMPLATE_TEST_CASE( ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE( __VA_ARGS__ ) -#define TEMPLATE_TEST_CASE_SIG( ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG( __VA_ARGS__ ) -#define TEMPLATE_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ ) -#define TEMPLATE_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG( className, __VA_ARGS__ ) -#define TEMPLATE_PRODUCT_TEST_CASE( ... ) INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE( __VA_ARGS__ ) -#define TEMPLATE_PRODUCT_TEST_CASE_SIG( ... ) INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_SIG( __VA_ARGS__ ) -#define TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, __VA_ARGS__ ) -#define TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, __VA_ARGS__ ) -#define TEMPLATE_LIST_TEST_CASE( ... ) INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE(__VA_ARGS__) -#define TEMPLATE_LIST_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE_METHOD( className, __VA_ARGS__ ) -#else -#define TEMPLATE_TEST_CASE( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE( __VA_ARGS__ ) ) -#define TEMPLATE_TEST_CASE_SIG( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG( __VA_ARGS__ ) ) -#define TEMPLATE_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ ) ) -#define TEMPLATE_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG( className, __VA_ARGS__ ) ) -#define TEMPLATE_PRODUCT_TEST_CASE( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE( __VA_ARGS__ ) ) -#define TEMPLATE_PRODUCT_TEST_CASE_SIG( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_SIG( __VA_ARGS__ ) ) -#define TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, __VA_ARGS__ ) ) -#define TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, __VA_ARGS__ ) ) -#define TEMPLATE_LIST_TEST_CASE( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE( __VA_ARGS__ ) ) -#define TEMPLATE_LIST_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE_METHOD( className, __VA_ARGS__ ) ) -#endif - -#if !defined(CATCH_CONFIG_RUNTIME_STATIC_REQUIRE) -#define STATIC_REQUIRE( ... ) static_assert( __VA_ARGS__, #__VA_ARGS__ ); SUCCEED( #__VA_ARGS__ ) -#define STATIC_REQUIRE_FALSE( ... ) static_assert( !(__VA_ARGS__), "!(" #__VA_ARGS__ ")" ); SUCCEED( "!(" #__VA_ARGS__ ")" ) -#else -#define STATIC_REQUIRE( ... ) REQUIRE( __VA_ARGS__ ) -#define STATIC_REQUIRE_FALSE( ... ) REQUIRE_FALSE( __VA_ARGS__ ) -#endif - -#endif - -#define CATCH_TRANSLATE_EXCEPTION( signature ) INTERNAL_CATCH_TRANSLATE_EXCEPTION( signature ) - -// "BDD-style" convenience wrappers -#define SCENARIO( ... ) TEST_CASE( "Scenario: " __VA_ARGS__ ) -#define SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " __VA_ARGS__ ) - -#define GIVEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " Given: " << desc ) -#define AND_GIVEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( "And given: " << desc ) -#define WHEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " When: " << desc ) -#define AND_WHEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " And when: " << desc ) -#define THEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " Then: " << desc ) -#define AND_THEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " And: " << desc ) - -#if defined(CATCH_CONFIG_ENABLE_BENCHMARKING) -#define BENCHMARK(...) \ - INTERNAL_CATCH_BENCHMARK(INTERNAL_CATCH_UNIQUE_NAME(____C_A_T_C_H____B_E_N_C_H____), INTERNAL_CATCH_GET_1_ARG(__VA_ARGS__,,), INTERNAL_CATCH_GET_2_ARG(__VA_ARGS__,,)) -#define BENCHMARK_ADVANCED(name) \ - INTERNAL_CATCH_BENCHMARK_ADVANCED(INTERNAL_CATCH_UNIQUE_NAME(____C_A_T_C_H____B_E_N_C_H____), name) -#endif // CATCH_CONFIG_ENABLE_BENCHMARKING - -using Catch::Detail::Approx; - -#else // CATCH_CONFIG_DISABLE - -////// -// If this config identifier is defined then all CATCH macros are prefixed with CATCH_ -#ifdef CATCH_CONFIG_PREFIX_ALL - -#define CATCH_REQUIRE( ... ) (void)(0) -#define CATCH_REQUIRE_FALSE( ... ) (void)(0) - -#define CATCH_REQUIRE_THROWS( ... ) (void)(0) -#define CATCH_REQUIRE_THROWS_AS( expr, exceptionType ) (void)(0) -#define CATCH_REQUIRE_THROWS_WITH( expr, matcher ) (void)(0) -#if !defined(CATCH_CONFIG_DISABLE_MATCHERS) -#define CATCH_REQUIRE_THROWS_MATCHES( expr, exceptionType, matcher ) (void)(0) -#endif// CATCH_CONFIG_DISABLE_MATCHERS -#define CATCH_REQUIRE_NOTHROW( ... ) (void)(0) - -#define CATCH_CHECK( ... ) (void)(0) -#define CATCH_CHECK_FALSE( ... ) (void)(0) -#define CATCH_CHECKED_IF( ... ) if (__VA_ARGS__) -#define CATCH_CHECKED_ELSE( ... ) if (!(__VA_ARGS__)) -#define CATCH_CHECK_NOFAIL( ... ) (void)(0) - -#define CATCH_CHECK_THROWS( ... ) (void)(0) -#define CATCH_CHECK_THROWS_AS( expr, exceptionType ) (void)(0) -#define CATCH_CHECK_THROWS_WITH( expr, matcher ) (void)(0) -#if !defined(CATCH_CONFIG_DISABLE_MATCHERS) -#define CATCH_CHECK_THROWS_MATCHES( expr, exceptionType, matcher ) (void)(0) -#endif // CATCH_CONFIG_DISABLE_MATCHERS -#define CATCH_CHECK_NOTHROW( ... ) (void)(0) - -#if !defined(CATCH_CONFIG_DISABLE_MATCHERS) -#define CATCH_CHECK_THAT( arg, matcher ) (void)(0) - -#define CATCH_REQUIRE_THAT( arg, matcher ) (void)(0) -#endif // CATCH_CONFIG_DISABLE_MATCHERS - -#define CATCH_INFO( msg ) (void)(0) -#define CATCH_UNSCOPED_INFO( msg ) (void)(0) -#define CATCH_WARN( msg ) (void)(0) -#define CATCH_CAPTURE( msg ) (void)(0) - -#define CATCH_TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ )) -#define CATCH_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ )) -#define CATCH_METHOD_AS_TEST_CASE( method, ... ) -#define CATCH_REGISTER_TEST_CASE( Function, ... ) (void)(0) -#define CATCH_SECTION( ... ) -#define CATCH_DYNAMIC_SECTION( ... ) -#define CATCH_FAIL( ... ) (void)(0) -#define CATCH_FAIL_CHECK( ... ) (void)(0) -#define CATCH_SUCCEED( ... ) (void)(0) - -#define CATCH_ANON_TEST_CASE() INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ )) - -#ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR -#define CATCH_TEMPLATE_TEST_CASE( ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_NO_REGISTRATION(__VA_ARGS__) -#define CATCH_TEMPLATE_TEST_CASE_SIG( ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG_NO_REGISTRATION(__VA_ARGS__) -#define CATCH_TEMPLATE_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_NO_REGISTRATION(className, __VA_ARGS__) -#define CATCH_TEMPLATE_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG_NO_REGISTRATION(className, __VA_ARGS__ ) -#define CATCH_TEMPLATE_PRODUCT_TEST_CASE( ... ) CATCH_TEMPLATE_TEST_CASE( __VA_ARGS__ ) -#define CATCH_TEMPLATE_PRODUCT_TEST_CASE_SIG( ... ) CATCH_TEMPLATE_TEST_CASE( __VA_ARGS__ ) -#define CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, ... ) CATCH_TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ ) -#define CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, ... ) CATCH_TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ ) -#else -#define CATCH_TEMPLATE_TEST_CASE( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_NO_REGISTRATION(__VA_ARGS__) ) -#define CATCH_TEMPLATE_TEST_CASE_SIG( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG_NO_REGISTRATION(__VA_ARGS__) ) -#define CATCH_TEMPLATE_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_NO_REGISTRATION(className, __VA_ARGS__ ) ) -#define CATCH_TEMPLATE_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG_NO_REGISTRATION(className, __VA_ARGS__ ) ) -#define CATCH_TEMPLATE_PRODUCT_TEST_CASE( ... ) CATCH_TEMPLATE_TEST_CASE( __VA_ARGS__ ) -#define CATCH_TEMPLATE_PRODUCT_TEST_CASE_SIG( ... ) CATCH_TEMPLATE_TEST_CASE( __VA_ARGS__ ) -#define CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, ... ) CATCH_TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ ) -#define CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, ... ) CATCH_TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ ) -#endif - -// "BDD-style" convenience wrappers -#define CATCH_SCENARIO( ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ )) -#define CATCH_SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TESTCASE_METHOD_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ), className ) -#define CATCH_GIVEN( desc ) -#define CATCH_AND_GIVEN( desc ) -#define CATCH_WHEN( desc ) -#define CATCH_AND_WHEN( desc ) -#define CATCH_THEN( desc ) -#define CATCH_AND_THEN( desc ) - -#define CATCH_STATIC_REQUIRE( ... ) (void)(0) -#define CATCH_STATIC_REQUIRE_FALSE( ... ) (void)(0) - -// If CATCH_CONFIG_PREFIX_ALL is not defined then the CATCH_ prefix is not required -#else - -#define REQUIRE( ... ) (void)(0) -#define REQUIRE_FALSE( ... ) (void)(0) - -#define REQUIRE_THROWS( ... ) (void)(0) -#define REQUIRE_THROWS_AS( expr, exceptionType ) (void)(0) -#define REQUIRE_THROWS_WITH( expr, matcher ) (void)(0) -#if !defined(CATCH_CONFIG_DISABLE_MATCHERS) -#define REQUIRE_THROWS_MATCHES( expr, exceptionType, matcher ) (void)(0) -#endif // CATCH_CONFIG_DISABLE_MATCHERS -#define REQUIRE_NOTHROW( ... ) (void)(0) - -#define CHECK( ... ) (void)(0) -#define CHECK_FALSE( ... ) (void)(0) -#define CHECKED_IF( ... ) if (__VA_ARGS__) -#define CHECKED_ELSE( ... ) if (!(__VA_ARGS__)) -#define CHECK_NOFAIL( ... ) (void)(0) - -#define CHECK_THROWS( ... ) (void)(0) -#define CHECK_THROWS_AS( expr, exceptionType ) (void)(0) -#define CHECK_THROWS_WITH( expr, matcher ) (void)(0) -#if !defined(CATCH_CONFIG_DISABLE_MATCHERS) -#define CHECK_THROWS_MATCHES( expr, exceptionType, matcher ) (void)(0) -#endif // CATCH_CONFIG_DISABLE_MATCHERS -#define CHECK_NOTHROW( ... ) (void)(0) - -#if !defined(CATCH_CONFIG_DISABLE_MATCHERS) -#define CHECK_THAT( arg, matcher ) (void)(0) - -#define REQUIRE_THAT( arg, matcher ) (void)(0) -#endif // CATCH_CONFIG_DISABLE_MATCHERS - -#define INFO( msg ) (void)(0) -#define UNSCOPED_INFO( msg ) (void)(0) -#define WARN( msg ) (void)(0) -#define CAPTURE( msg ) (void)(0) - -#define TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ )) -#define TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ )) -#define METHOD_AS_TEST_CASE( method, ... ) -#define REGISTER_TEST_CASE( Function, ... ) (void)(0) -#define SECTION( ... ) -#define DYNAMIC_SECTION( ... ) -#define FAIL( ... ) (void)(0) -#define FAIL_CHECK( ... ) (void)(0) -#define SUCCEED( ... ) (void)(0) -#define ANON_TEST_CASE() INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ )) - -#ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR -#define TEMPLATE_TEST_CASE( ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_NO_REGISTRATION(__VA_ARGS__) -#define TEMPLATE_TEST_CASE_SIG( ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG_NO_REGISTRATION(__VA_ARGS__) -#define TEMPLATE_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_NO_REGISTRATION(className, __VA_ARGS__) -#define TEMPLATE_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG_NO_REGISTRATION(className, __VA_ARGS__ ) -#define TEMPLATE_PRODUCT_TEST_CASE( ... ) TEMPLATE_TEST_CASE( __VA_ARGS__ ) -#define TEMPLATE_PRODUCT_TEST_CASE_SIG( ... ) TEMPLATE_TEST_CASE( __VA_ARGS__ ) -#define TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, ... ) TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ ) -#define TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, ... ) TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ ) -#else -#define TEMPLATE_TEST_CASE( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_NO_REGISTRATION(__VA_ARGS__) ) -#define TEMPLATE_TEST_CASE_SIG( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG_NO_REGISTRATION(__VA_ARGS__) ) -#define TEMPLATE_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_NO_REGISTRATION(className, __VA_ARGS__ ) ) -#define TEMPLATE_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG_NO_REGISTRATION(className, __VA_ARGS__ ) ) -#define TEMPLATE_PRODUCT_TEST_CASE( ... ) TEMPLATE_TEST_CASE( __VA_ARGS__ ) -#define TEMPLATE_PRODUCT_TEST_CASE_SIG( ... ) TEMPLATE_TEST_CASE( __VA_ARGS__ ) -#define TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, ... ) TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ ) -#define TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, ... ) TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ ) -#endif - -#define STATIC_REQUIRE( ... ) (void)(0) -#define STATIC_REQUIRE_FALSE( ... ) (void)(0) - -#endif - -#define CATCH_TRANSLATE_EXCEPTION( signature ) INTERNAL_CATCH_TRANSLATE_EXCEPTION_NO_REG( INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionTranslator ), signature ) - -// "BDD-style" convenience wrappers -#define SCENARIO( ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ) ) -#define SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TESTCASE_METHOD_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ), className ) - -#define GIVEN( desc ) -#define AND_GIVEN( desc ) -#define WHEN( desc ) -#define AND_WHEN( desc ) -#define THEN( desc ) -#define AND_THEN( desc ) - -using Catch::Detail::Approx; - -#endif - -#endif // ! CATCH_CONFIG_IMPL_ONLY - -// start catch_reenable_warnings.h - - -#ifdef __clang__ -# ifdef __ICC // icpc defines the __clang__ macro -# pragma warning(pop) -# else -# pragma clang diagnostic pop -# endif -#elif defined __GNUC__ -# pragma GCC diagnostic pop -#endif - -// end catch_reenable_warnings.h -// end catch.hpp -#endif // TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED - diff --git a/extras/test/include/Arduino.h b/extras/test/include/Arduino.h deleted file mode 100644 index f4daa589..00000000 --- a/extras/test/include/Arduino.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - This file is part of the ArduinoBLE library. - Copyright (c) 2018 Arduino SA. All rights reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#ifndef TEST_ARDUINO_H_ -#define TEST_ARDUINO_H_ - -/****************************************************************************** - INCLUDE - ******************************************************************************/ - -#include <stdio.h> -#include <stdlib.h> -#include "String.h" -#include "Stream.h" -#include "itoa.h" -#include "Common.h" - -/****************************************************************************** - TYPEDEF - ******************************************************************************/ - -typedef arduino::String String; -typedef bool boolean; - -/****************************************************************************** - FUNCTION PROTOTYPES - ******************************************************************************/ - -#endif /* TEST_ARDUINO_H_ */ diff --git a/extras/test/include/test_advertising_data/FakeBLELocalDevice.h b/extras/test/include/test_advertising_data/FakeBLELocalDevice.h deleted file mode 100644 index 94e97730..00000000 --- a/extras/test/include/test_advertising_data/FakeBLELocalDevice.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - This file is part of the ArduinoBLE library. - Copyright (c) 2018 Arduino SA. All rights reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#ifndef _FAKE_BLELOCALDEVICE_H_ -#define _FAKE_BLELOCALDEVICE_H_ - -#define private public -#define protected public -#include "BLELocalDevice.h" - -class FakeBLELocalDevice : public BLELocalDevice { - public: - FakeBLELocalDevice(); - virtual ~FakeBLELocalDevice(); - - int advertise(); -}; - -#endif diff --git a/extras/test/include/test_discovered_device/FakeGAP.h b/extras/test/include/test_discovered_device/FakeGAP.h deleted file mode 100644 index 35b3233b..00000000 --- a/extras/test/include/test_discovered_device/FakeGAP.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - This file is part of the ArduinoBLE library. - Copyright (c) 2018 Arduino SA. All rights reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#ifndef _FAKE_GAP_H_ -#define _FAKE_GAP_H_ - -#define private public -#define protected public -#include "GAP.h" - -class FakeGAPClass : public GAPClass { - public: - FakeGAPClass(); - virtual ~FakeGAPClass(); -}; - -#endif diff --git a/extras/test/include/util/Common.h b/extras/test/include/util/Common.h deleted file mode 100644 index 8d288e18..00000000 --- a/extras/test/include/util/Common.h +++ /dev/null @@ -1,167 +0,0 @@ -#pragma once -#include <stdint.h> - -#ifdef __cplusplus -extern "C"{ -#endif - -void yield(void); - -typedef enum { - LOW = 0, - HIGH = 1, - CHANGE = 2, - FALLING = 3, - RISING = 4, -} PinStatus; - -typedef enum { - INPUT = 0x0, - OUTPUT = 0x1, - INPUT_PULLUP = 0x2, - INPUT_PULLDOWN = 0x3, -} PinMode; - -typedef enum { - LSBFIRST = 0, - MSBFIRST = 1, -} BitOrder; - -#define PI 3.1415926535897932384626433832795 -#define HALF_PI 1.5707963267948966192313216916398 -#define TWO_PI 6.283185307179586476925286766559 -#define DEG_TO_RAD 0.017453292519943295769236907684886 -#define RAD_TO_DEG 57.295779513082320876798154814105 -#define EULER 2.718281828459045235360287471352 - -#define SERIAL 0x0 -#define DISPLAY 0x1 - -#ifndef constrain -#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt))) -#endif - -#ifndef radians -#define radians(deg) ((deg)*DEG_TO_RAD) -#endif - -#ifndef degrees -#define degrees(rad) ((rad)*RAD_TO_DEG) -#endif - -#ifndef sq -#define sq(x) ((x)*(x)) -#endif - -typedef void (*voidFuncPtr)(void); -typedef void (*voidFuncPtrParam)(void*); - -// interrupts() / noInterrupts() must be defined by the core - -#define lowByte(w) ((uint8_t) ((w) & 0xff)) -#define highByte(w) ((uint8_t) ((w) >> 8)) - -#define bitRead(value, bit) (((value) >> (bit)) & 0x01) -#define bitSet(value, bit) ((value) |= (1UL << (bit))) -#define bitClear(value, bit) ((value) &= ~(1UL << (bit))) -#define bitToggle(value, bit) ((value) ^= (1UL << (bit))) -#define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit)) - -#ifndef bit -#define bit(b) (1UL << (b)) -#endif - -/* TODO: request for removal */ -typedef bool boolean; -typedef uint8_t byte; -typedef uint16_t word; - -void init(void); -void initVariant(void); - -int atexit(void (*func)()) __attribute__((weak)); -int main() __attribute__((weak)); - -#ifdef EXTENDED_PIN_MODE -// Platforms who wnat to declare more than 256 pins need to define EXTENDED_PIN_MODE globally -typedef uint32_t pin_size_t; -#else -typedef uint8_t pin_size_t; -#endif - -void pinMode(pin_size_t pinNumber, PinMode pinMode); -void digitalWrite(pin_size_t pinNumber, PinStatus status); -PinStatus digitalRead(pin_size_t pinNumber); -int analogRead(pin_size_t pinNumber); -void analogReference(uint8_t mode); -void analogWrite(pin_size_t pinNumber, int value); - -unsigned long millis(void); -unsigned long micros(void); -void delay(unsigned long); -void delayMicroseconds(unsigned int us); -unsigned long pulseIn(pin_size_t pin, uint8_t state, unsigned long timeout); -unsigned long pulseInLong(pin_size_t pin, uint8_t state, unsigned long timeout); - -void shiftOut(pin_size_t dataPin, pin_size_t clockPin, BitOrder bitOrder, uint8_t val); -pin_size_t shiftIn(pin_size_t dataPin, pin_size_t clockPin, BitOrder bitOrder); - -void attachInterrupt(pin_size_t interruptNumber, voidFuncPtr callback, PinStatus mode); -void attachInterruptParam(pin_size_t interruptNumber, voidFuncPtrParam callback, PinStatus mode, void* param); -void detachInterrupt(pin_size_t interruptNumber); - -void setup(void); -void loop(void); - -#ifdef __cplusplus -} // extern "C" -#endif - -#ifdef __cplusplus - template<class T, class L> - auto min(const T& a, const L& b) -> decltype((b < a) ? b : a) - { - return (b < a) ? b : a; - } - - template<class T, class L> - auto max(const T& a, const L& b) -> decltype((b < a) ? b : a) - { - return (a < b) ? b : a; - } -#else -#ifndef min -#define min(a,b) \ - ({ __typeof__ (a) _a = (a); \ - __typeof__ (b) _b = (b); \ - _a < _b ? _a : _b; }) -#endif -#ifndef max -#define max(a,b) \ - ({ __typeof__ (a) _a = (a); \ - __typeof__ (b) _b = (b); \ - _a > _b ? _a : _b; }) -#endif -#endif - -#ifdef __cplusplus - -/* C++ prototypes */ -uint16_t makeWord(uint16_t w); -uint16_t makeWord(byte h, byte l); - -#define word(...) makeWord(__VA_ARGS__) - -unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L); -unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L); - -void tone(uint8_t _pin, unsigned int frequency, unsigned long duration = 0); -void noTone(uint8_t _pin); - -// WMath prototypes -long random(long); -long random(long, long); -void randomSeed(unsigned long); -long map(long, long, long, long, long); - -#endif // __cplusplus diff --git a/extras/test/include/util/HCIFakeTransport.h b/extras/test/include/util/HCIFakeTransport.h deleted file mode 100644 index 6c8ac08c..00000000 --- a/extras/test/include/util/HCIFakeTransport.h +++ /dev/null @@ -1,19 +0,0 @@ -//#include "Common.h" -#pragma once - -#include "HCITransport.h" - -class HCIFakeTransportClass : public HCITransportInterface -{ -public: - HCIFakeTransportClass() {}; - ~HCIFakeTransportClass() {}; - - int begin() {return 0;} - void end() {return;} - void wait(unsigned long timeout) {return;} - int available() {return 0;} - int peek() {return 0;} - int read() {return 0;} - size_t write(const uint8_t* data, size_t length) {return 0;} -}; \ No newline at end of file diff --git a/extras/test/include/util/Stream.h b/extras/test/include/util/Stream.h deleted file mode 100644 index f367e34c..00000000 --- a/extras/test/include/util/Stream.h +++ /dev/null @@ -1,40 +0,0 @@ -//#include "Common.h" -#pragma once - -#define DEC 10 -#define HEX 16 -#define OCT 8 -#define BIN 2 - -class Stream -{ -public: - Stream(const char *name = NULL); - ~Stream(); - - void flush() {} - - size_t print(const char[]) { return 0; } - size_t print(char) { return 0; } - size_t print(unsigned char, int) { return 0; } - size_t print(int, int) { return 0; } - size_t print(unsigned int, int) { return 0; } - size_t print(long, int) { return 0; } - size_t print(unsigned long, int) { return 0; } - size_t print(long long, int) { return 0; } - size_t print(unsigned long long, int) { return 0; } - size_t print(double, int) { return 0; } - size_t print(void) { return 0; } - - size_t println(const char[]) { return 0; } - size_t println(char) { return 0; } - size_t println(unsigned char, int) { return 0; } - size_t println(int, int) { return 0; } - size_t println(unsigned int, int) { return 0; } - size_t println(long, int) { return 0; } - size_t println(unsigned long, int) { return 0; } - size_t println(long long, int) { return 0; } - size_t println(unsigned long long, int) { return 0; } - size_t println(double, int) { return 0; } - size_t println(void) { return 0; } -}; diff --git a/extras/test/include/util/String.h b/extras/test/include/util/String.h deleted file mode 100644 index 3021a31e..00000000 --- a/extras/test/include/util/String.h +++ /dev/null @@ -1,248 +0,0 @@ -/* - String library for Wiring & Arduino - ...mostly rewritten by Paul Stoffregen... - Copyright (c) 2009-10 Hernando Barragan. All right reserved. - Copyright 2011, Paul Stoffregen, paul@pjrc.com - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#ifdef __cplusplus - -#ifndef __ARDUINO_STRINGS__ -#define __ARDUINO_STRINGS__ - -#include <stdlib.h> -#include <string.h> -#include <ctype.h> - -namespace arduino { - -// When compiling programs with this class, the following gcc parameters -// dramatically increase performance and memory (RAM) efficiency, typically -// with little or no increase in code size. -// -felide-constructors -// -std=c++0x - -class __FlashStringHelper; -#define F(string_literal) (reinterpret_cast<const __FlashStringHelper *>(PSTR(string_literal))) - -// An inherited class for holding the result of a concatenation. These -// result objects are assumed to be writable by subsequent concatenations. -class StringSumHelper; - -// The string class -class String -{ - friend class StringSumHelper; - // use a function pointer to allow for "if (s)" without the - // complications of an operator bool(). for more information, see: - // http://www.artima.com/cppsource/safebool.html - typedef void (String::*StringIfHelperType)() const; - void StringIfHelper() const {} - -public: - // constructors - // creates a copy of the initial value. - // if the initial value is null or invalid, or if memory allocation - // fails, the string will be marked as invalid (i.e. "if (s)" will - // be false). - String(const char *cstr = ""); - String(const String &str); - String(const __FlashStringHelper *str); - #if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) - String(String &&rval); - String(StringSumHelper &&rval); - #endif - explicit String(char c); - explicit String(unsigned char, unsigned char base=10); - explicit String(int, unsigned char base=10); - explicit String(unsigned int, unsigned char base=10); - explicit String(long, unsigned char base=10); - explicit String(unsigned long, unsigned char base=10); - //explicit String(float, unsigned char decimalPlaces=2); - //explicit String(double, unsigned char decimalPlaces=2); - ~String(void); - - // memory management - // return true on success, false on failure (in which case, the string - // is left unchanged). reserve(0), if successful, will validate an - // invalid string (i.e., "if (s)" will be true afterwards) - unsigned char reserve(unsigned int size); - inline unsigned int length(void) const {return len;} - - // creates a copy of the assigned value. if the value is null or - // invalid, or if the memory allocation fails, the string will be - // marked as invalid ("if (s)" will be false). - String & operator = (const String &rhs); - String & operator = (const char *cstr); - //String & operator = (const __FlashStringHelper *str); - #if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) - String & operator = (String &&rval); - String & operator = (StringSumHelper &&rval); - #endif - - // concatenate (works w/ built-in types) - - // returns true on success, false on failure (in which case, the string - // is left unchanged). if the argument is null or invalid, the - // concatenation is considered unsucessful. - unsigned char concat(const String &str); - unsigned char concat(const char *cstr); - unsigned char concat(char c); - unsigned char concat(unsigned char c); - unsigned char concat(int num); - unsigned char concat(unsigned int num); - unsigned char concat(long num); - unsigned char concat(unsigned long num); - unsigned char concat(float num); - //unsigned char concat(double num); - unsigned char concat(const __FlashStringHelper * str); - - // if there's not enough memory for the concatenated value, the string - // will be left unchanged (but this isn't signalled in any way) - String & operator += (const String &rhs) {concat(rhs); return (*this);} - String & operator += (const char *cstr) {concat(cstr); return (*this);} - String & operator += (char c) {concat(c); return (*this);} - String & operator += (unsigned char num) {concat(num); return (*this);} - String & operator += (int num) {concat(num); return (*this);} - String & operator += (unsigned int num) {concat(num); return (*this);} - String & operator += (long num) {concat(num); return (*this);} - String & operator += (unsigned long num) {concat(num); return (*this);} - String & operator += (float num) {concat(num); return (*this);} - //String & operator += (double num) {concat(num); return (*this);} - String & operator += (const __FlashStringHelper *str){concat(str); return (*this);} - - friend StringSumHelper & operator + (const StringSumHelper &lhs, const String &rhs); - friend StringSumHelper & operator + (const StringSumHelper &lhs, const char *cstr); - friend StringSumHelper & operator + (const StringSumHelper &lhs, char c); - friend StringSumHelper & operator + (const StringSumHelper &lhs, unsigned char num); - friend StringSumHelper & operator + (const StringSumHelper &lhs, int num); - friend StringSumHelper & operator + (const StringSumHelper &lhs, unsigned int num); - friend StringSumHelper & operator + (const StringSumHelper &lhs, long num); - friend StringSumHelper & operator + (const StringSumHelper &lhs, unsigned long num); - friend StringSumHelper & operator + (const StringSumHelper &lhs, float num); - //friend StringSumHelper & operator + (const StringSumHelper &lhs, double num); - //friend StringSumHelper & operator + (const StringSumHelper &lhs, const __FlashStringHelper *rhs); - - // comparison (only works w/ Strings and "strings") - operator StringIfHelperType() const { return buffer ? &String::StringIfHelper : 0; } - int compareTo(const String &s) const; - int compareTo(const char *cstr) const; - unsigned char equals(const String &s) const; - unsigned char equals(const char *cstr) const; - - friend unsigned char operator == (const String &a, const String &b) { return a.equals(b); } - friend unsigned char operator == (const String &a, const char *b) { return a.equals(b); } - friend unsigned char operator == (const char *a, const String &b) { return b == a; } - friend unsigned char operator < (const String &a, const String &b) { return a.compareTo(b) < 0; } - friend unsigned char operator < (const String &a, const char *b) { return a.compareTo(b) < 0; } - friend unsigned char operator < (const char *a, const String &b) { return b.compareTo(a) > 0; } - - friend unsigned char operator != (const String &a, const String &b) { return !(a == b); } - friend unsigned char operator != (const String &a, const char *b) { return !(a == b); } - friend unsigned char operator != (const char *a, const String &b) { return !(a == b); } - friend unsigned char operator > (const String &a, const String &b) { return b < a; } - friend unsigned char operator > (const String &a, const char *b) { return b < a; } - friend unsigned char operator > (const char *a, const String &b) { return b < a; } - friend unsigned char operator <= (const String &a, const String &b) { return !(b < a); } - friend unsigned char operator <= (const String &a, const char *b) { return !(b < a); } - friend unsigned char operator <= (const char *a, const String &b) { return !(b < a); } - friend unsigned char operator >= (const String &a, const String &b) { return !(a < b); } - friend unsigned char operator >= (const String &a, const char *b) { return !(a < b); } - friend unsigned char operator >= (const char *a, const String &b) { return !(a < b); } - - unsigned char equalsIgnoreCase(const String &s) const; - unsigned char startsWith( const String &prefix) const; - unsigned char startsWith(const String &prefix, unsigned int offset) const; - unsigned char endsWith(const String &suffix) const; - - // character acccess - char charAt(unsigned int index) const; - void setCharAt(unsigned int index, char c); - char operator [] (unsigned int index) const; - char& operator [] (unsigned int index); - void getBytes(unsigned char *buf, unsigned int bufsize, unsigned int index=0) const; - void toCharArray(char *buf, unsigned int bufsize, unsigned int index=0) const - { getBytes((unsigned char *)buf, bufsize, index); } - const char* c_str() const { return buffer; } - char* begin() { return buffer; } - char* end() { return buffer + length(); } - const char* begin() const { return c_str(); } - const char* end() const { return c_str() + length(); } - - // search - int indexOf( char ch ) const; - int indexOf( char ch, unsigned int fromIndex ) const; - int indexOf( const String &str ) const; - int indexOf( const String &str, unsigned int fromIndex ) const; - int lastIndexOf( char ch ) const; - int lastIndexOf( char ch, unsigned int fromIndex ) const; - int lastIndexOf( const String &str ) const; - int lastIndexOf( const String &str, unsigned int fromIndex ) const; - String substring( unsigned int beginIndex ) const { return substring(beginIndex, len); }; - String substring( unsigned int beginIndex, unsigned int endIndex ) const; - - // modification - void replace(char find, char replace); - void replace(const String& find, const String& replace); - void remove(unsigned int index); - void remove(unsigned int index, unsigned int count); - void toLowerCase(void); - void toUpperCase(void); - void trim(void); - - // parsing/conversion - long toInt(void) const; - float toFloat(void) const; - double toDouble(void) const; - -protected: - char *buffer; // the actual char array - unsigned int capacity; // the array length minus one (for the '\0') - unsigned int len; // the String length (not counting the '\0') -protected: - void init(void); - void invalidate(void); - unsigned char changeBuffer(unsigned int maxStrLen); - unsigned char concat(const char *cstr, unsigned int length); - - // copy and move - String & copy(const char *cstr, unsigned int length); - String & copy(const __FlashStringHelper *pstr, unsigned int length); - #if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) - void move(String &rhs); - #endif -}; - -class StringSumHelper : public String -{ -public: - StringSumHelper(const String &s) : String(s) {} - StringSumHelper(const char *p) : String(p) {} - StringSumHelper(char c) : String(c) {} - StringSumHelper(unsigned char num) : String(num) {} - StringSumHelper(int num) : String(num) {} - StringSumHelper(unsigned int num) : String(num) {} - StringSumHelper(long num) : String(num) {} - StringSumHelper(unsigned long num) : String(num) {} - //StringSumHelper(float num) : String(num) {} - //StringSumHelper(double num) : String(num) {} -}; - -} // namespace arduino - -#endif // __cplusplus -#endif // __ARDUINO_STRINGS__ diff --git a/extras/test/include/util/TestUtil.h b/extras/test/include/util/TestUtil.h deleted file mode 100644 index 111607ec..00000000 --- a/extras/test/include/util/TestUtil.h +++ /dev/null @@ -1,3 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - */ diff --git a/extras/test/include/util/itoa.h b/extras/test/include/util/itoa.h deleted file mode 100644 index 55b28493..00000000 --- a/extras/test/include/util/itoa.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - Copyright (c) 2016 Arduino LLC. All right reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#pragma once - -// Standard C functions required in Arduino API -// If these functions are not provided by the standard library, the -// core should supply an implementation of them. - -#ifdef __cplusplus -extern "C" { -#endif - -extern char* itoa(int value, char *string, int radix); -extern char* ltoa(long value, char *string, int radix); -extern char* utoa(unsigned value, char *string, int radix); -extern char* ultoa(unsigned long value, char *string, int radix); - -#ifdef __cplusplus -} // extern "C" -#endif - diff --git a/extras/test/src/Arduino.cpp b/extras/test/src/Arduino.cpp deleted file mode 100644 index 6a6ab4e5..00000000 --- a/extras/test/src/Arduino.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/* - This file is part of the ArduinoBLE library. - Copyright (c) 2018 Arduino SA. All rights reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -/****************************************************************************** - INCLUDE - ******************************************************************************/ - -#include <Arduino.h> - -/****************************************************************************** - GLOBAL VARIABLES - ******************************************************************************/ - -static unsigned long current_millis = 0; - -/****************************************************************************** - PUBLIC FUNCTIONS - ******************************************************************************/ - -void set_millis(unsigned long const millis) -{ - current_millis = millis; -} - -unsigned long millis() -{ - return current_millis; -} diff --git a/extras/test/src/test_advertising_data/FakeBLELocalDevice.cpp b/extras/test/src/test_advertising_data/FakeBLELocalDevice.cpp deleted file mode 100644 index 7f5a71ad..00000000 --- a/extras/test/src/test_advertising_data/FakeBLELocalDevice.cpp +++ /dev/null @@ -1,40 +0,0 @@ -/* - This file is part of the ArduinoBLE library. - Copyright (c) 2018 Arduino SA. All rights reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#include "FakeBLELocalDevice.h" - -FakeBLELocalDevice::FakeBLELocalDevice() -{ - -} - -FakeBLELocalDevice::~FakeBLELocalDevice() -{ - -} - -int FakeBLELocalDevice::advertise() -{ - _advertisingData.updateData(); - _scanResponseData.updateData(); - return 1; -} - -FakeBLELocalDevice FakeBLEObj; -BLELocalDevice& BLE = FakeBLEObj; diff --git a/extras/test/src/test_advertising_data/test_advertising_data.cpp b/extras/test/src/test_advertising_data/test_advertising_data.cpp deleted file mode 100644 index 67fa1d25..00000000 --- a/extras/test/src/test_advertising_data/test_advertising_data.cpp +++ /dev/null @@ -1,184 +0,0 @@ -/* - This file is part of the ArduinoBLE library. - Copyright (c) 2018 Arduino SA. All rights reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#include <catch.hpp> - -#define private public -#define protected public - -#include "FakeBLELocalDevice.h" -#include "BLEAdvertisingData.h" - -TEST_CASE("Test flags override", "[ArduinoBLE::BLEAdvertisingData]") -{ - // Mocking advertisement packet - BLEAdvertisingData advData; - // Expected results - uint8_t defaultData[] = {0x02, BLEFieldFlags, 0x06}; - uint8_t goldenFlags[] = {0x02, 0x01, BLEFlagsBREDRNotSupported}; - - WHEN("Default options for flags") - { - BLE.advertise(); - REQUIRE( 0 == (memcmp(defaultData, BLE.getAdvertisingData().data(), sizeof(defaultData))) ); - REQUIRE( BLE.getScanResponseData().dataLength() == 0 ); - } - - WHEN("Setting external advertising data which has flags") - { - advData.setFlags(BLEFlagsBREDRNotSupported); - advData.updateData(); - BLE.setAdvertisingData(advData); - BLE.advertise(); - REQUIRE( 3 == BLE.getAdvertisingData().dataLength()); - REQUIRE( 0 == (memcmp(goldenFlags, advData.data(), sizeof(goldenFlags))) ); - REQUIRE( 0 == (memcmp(goldenFlags, BLE.getAdvertisingData().data(), sizeof(goldenFlags))) ); - REQUIRE( 0 != (memcmp(defaultData, BLE.getAdvertisingData().data(), sizeof(defaultData))) ); - } - - WHEN("Setting external advertising data without flags") - { - advData.clear(); - BLE.setAdvertisingData(advData); - BLE.advertise(); - REQUIRE( 0 == (memcmp(defaultData, BLE.getAdvertisingData().data(), sizeof(defaultData))) ); - } - - // Clear BLE advertising data - advData.clear(); - BLE.setAdvertisingData(advData); -} - -TEST_CASE("Set default flags in an already full advertising data packet", "[ArduinoBLE::BLEAdvertisingData]") -{ - BLEAdvertisingData advData; - bool retVal; - - const char* name = "tes"; - const uint8_t manufacturerData[24] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, - 17, 18, 19, 20, 21, 22, 23}; - - uint8_t defaultFlags[3] = {0x02, 0x01, 0x06}; - - uint8_t goldenData[31] = { - (sizeof(manufacturerData) + 1), BLEFieldManufacturerData, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, - 17, 18, 19, 20, 21, 22, 23, - ((uint8_t)(strlen(name) + 1)), BLEFieldCompleteLocalName, 't', 'e', 's' - }; - - WHEN("Test flags when advertising data is full") - { - retVal = advData.setLocalName("tes"); - retVal = advData.setManufacturerData(manufacturerData, sizeof(manufacturerData)); - - BLE.setAdvertisingData(advData); - BLE.advertise(); - REQUIRE(0 != memcmp(defaultFlags, BLE.getAdvertisingData().data(), sizeof(defaultFlags))); - REQUIRE(0 == memcmp(goldenData, BLE.getAdvertisingData().data(), sizeof(goldenData))); - } - - // Clear BLE advertising data - advData.clear(); - BLE.setAdvertisingData(advData); -} - -TEST_CASE("BLE overwrite a full internal advertising data with an external built one", "[ArduinoBLE::BLEAdvertisingData]") -{ - bool verify; - BLEAdvertisingData advData; - BLEAdvertisingData internalData; - - WHEN("Copy empty external advertising data") - { - BLE.setLocalName("test"); - BLE.setAdvertisedServiceUuid("1818"); - BLE.advertise(); - //WARN("data length: " << BLE.getAdvertisingData().dataLength()); - verify = (BLE.getAdvertisingData().dataLength() == (3 + (2+2))); - REQUIRE(verify); - verify = (BLE.getScanResponseData().dataLength() == (4+2)); - REQUIRE(verify); - - BLE.setAdvertisingData(advData); - BLE.advertise(); - //WARN(BLE.getAdvertisingData().dataLength()); - verify = (BLE.getAdvertisingData().dataLength() == 3); - REQUIRE(verify); - - BLE.setScanResponseData(advData); - BLE.advertise(); - verify = (BLE.getScanResponseData().dataLength() == 0); - REQUIRE(verify); - } - - // Clear BLE advertising data - advData.clear(); - BLE.setAdvertisingData(advData); -} - -TEST_CASE("BLE test raw data", "[ArduinoBLE::BLEAdvertisingData]") -{ - BLEAdvertisingData advData; - bool retVal; - - WHEN("Set too large raw data") - { - uint8_t data[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, - 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, - 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32 }; - advData.setRawData(data, sizeof(data)); - REQUIRE(!retVal); - advData.clear(); - } - - WHEN("Set correct raw data") - { - uint8_t data[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, - 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, - 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31}; - retVal = advData.setRawData(data, sizeof(data)); - REQUIRE(retVal); - advData.updateData(); - REQUIRE( 0 == memcmp(data, advData.data(), sizeof(data)) ); - advData.clear(); - } - - WHEN("Hide other parameters by setting raw data") - { - uint8_t data[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; - advData.setLocalName("test"); - advData.setRawData(data, sizeof(data)); - - advData.updateData(); - REQUIRE( 0 == memcmp(data, advData.data(), sizeof(data)) ); - - advData.setLocalName("test"); - advData.updateData(); - REQUIRE( 0 == memcmp(data, advData.data(), sizeof(data)) ); - - advData.clear(); - advData.setLocalName("test"); - advData.updateData(); - REQUIRE( 0 != memcmp(data, advData.data(), sizeof(data)) ); - } - - // Clear BLE advertising data - advData.clear(); - BLE.setAdvertisingData(advData); -} diff --git a/extras/test/src/test_advertising_data/test_local_name.cpp b/extras/test/src/test_advertising_data/test_local_name.cpp deleted file mode 100644 index 947224cc..00000000 --- a/extras/test/src/test_advertising_data/test_local_name.cpp +++ /dev/null @@ -1,82 +0,0 @@ -/* - This file is part of the ArduinoBLE library. - Copyright (c) 2018 Arduino SA. All rights reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#include <catch.hpp> - -#define private public -#define protected public - -#include "FakeBLELocalDevice.h" -#include "BLEAdvertisingData.h" - -TEST_CASE("Test local name setting", "[ArduinoBLE::BLEAdvertisingData]") -{ - BLEAdvertisingData advData; - int oldRemainingLength = advData.remainingLength(); - bool retVal; - - WHEN("Set correct local name") - { - const char* name = "test"; - retVal = advData.setLocalName(name); - REQUIRE(retVal); - REQUIRE( (strlen(name) + 2) == (oldRemainingLength - advData.remainingLength()) ); - oldRemainingLength = advData.remainingLength(); - - advData.updateData(); - REQUIRE(advData.dataLength() == (strlen(name) + 2)); - } - - WHEN("Set too long local name") - { - const char* name = "way too long local name (len 32)"; - retVal = advData.setLocalName(name); - REQUIRE(!retVal); - REQUIRE( oldRemainingLength == advData.remainingLength() ); - advData.updateData(); - REQUIRE( advData.dataLength() == (MAX_AD_DATA_LENGTH - oldRemainingLength) ); - } - - WHEN("Overwrite local name with a name as long as max data length") - { - const char* name = "local name with full length "; - retVal = advData.setLocalName(name); - REQUIRE(retVal); - REQUIRE( (strlen(name) + 2) == (oldRemainingLength - advData.remainingLength()) ); - oldRemainingLength = advData.remainingLength(); - - advData.updateData(); - REQUIRE(advData.dataLength() == (strlen(name) + 2)); - // advData should be full now - REQUIRE( 0 == advData.remainingLength() ); - REQUIRE( 0 == advData.availableForWrite() ); - } - - WHEN("Check consistency when setting the external advertising data") - { - auto goldenData = advData.data(); - BLE.setAdvertisingData(advData); - BLE.advertise(); - REQUIRE( 0 == memcmp(goldenData, BLE.getAdvertisingData().data(), advData.dataLength()) ); - } - - // Clear BLE advertising data - advData.clear(); - BLE.setAdvertisingData(advData); -} diff --git a/extras/test/src/test_advertising_data/test_manufacturer.cpp b/extras/test/src/test_advertising_data/test_manufacturer.cpp deleted file mode 100644 index 39f7e955..00000000 --- a/extras/test/src/test_advertising_data/test_manufacturer.cpp +++ /dev/null @@ -1,146 +0,0 @@ -/* - This file is part of the ArduinoBLE library. - Copyright (c) 2018 Arduino SA. All rights reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#include <catch.hpp> - -#define private public -#define protected public - -#include "FakeBLELocalDevice.h" -#include "BLEAdvertisingData.h" - -TEST_CASE("Test manufacturer data setting", "[ArduinoBLE::BLEAdvertisingData]") -{ - BLEAdvertisingData advData; - int oldRemainingLength = advData.remainingLength(); - uint16_t companyId = 0x1100; - bool retVal; - - WHEN("Set correct manufacturer data without id") - { - const uint8_t data[] = {0x00, 0x11, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; - const uint8_t goldenData[] = {(sizeof(data) + 1), BLEFieldManufacturerData, - 0x00, 0x11, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; - retVal = advData.setManufacturerData(data, sizeof(data)); - REQUIRE(retVal); - REQUIRE( (sizeof(data) + 2) == (oldRemainingLength - advData.remainingLength()) ); - oldRemainingLength = advData.remainingLength(); - - advData.updateData(); - REQUIRE(advData.dataLength() == sizeof(goldenData)); - REQUIRE( 0 == memcmp(goldenData, advData.data(), sizeof(goldenData)) ); - } - - WHEN("Set correct manufacturer data given a manufacturer id") - { - const uint8_t data[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; - const uint8_t goldenData[] = {(sizeof(data) + sizeof(companyId) + 1), BLEFieldManufacturerData, - 0x00, 0x11, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; - retVal = advData.setManufacturerData(companyId, data, sizeof(data)); - REQUIRE(retVal); - REQUIRE( (sizeof(data) + sizeof(companyId) + 2) == (oldRemainingLength - advData.remainingLength()) ); - oldRemainingLength = advData.remainingLength(); - - advData.updateData(); - REQUIRE(advData.dataLength() == sizeof(goldenData)); - REQUIRE( 0 == memcmp(goldenData, advData.data(), sizeof(goldenData)) ); - } - - WHEN("Set too long manufacturer data given id") - { - // extreme case, 1 byte more than the maximum - const uint8_t data[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27}; - retVal = advData.setManufacturerData(companyId, data, sizeof(data)); - REQUIRE(!retVal); - REQUIRE( oldRemainingLength == advData.remainingLength() ); - advData.updateData(); - REQUIRE( advData.dataLength() == (MAX_AD_DATA_LENGTH - oldRemainingLength) ); - } - - WHEN("Set too long manufacturer data without id") - { - // extreme case, 1 byte more than the maximum - const uint8_t data[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29}; - retVal = advData.setManufacturerData(data, sizeof(data)); - REQUIRE(!retVal); - REQUIRE( oldRemainingLength == advData.remainingLength() ); - advData.updateData(); - REQUIRE( advData.dataLength() == (MAX_AD_DATA_LENGTH - oldRemainingLength) ); - } - - WHEN("Set manufacturer data without id after setting manufacturer data given id") - { - advData.clear(); - const uint8_t dataGivenId[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26}; - const uint8_t data[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28}; - retVal = advData.setManufacturerData(companyId, dataGivenId, sizeof(dataGivenId)); - REQUIRE(retVal); - retVal = advData.setManufacturerData(data, sizeof(data)); - REQUIRE(retVal); - REQUIRE( 0 == advData.remainingLength() ); - advData.updateData(); - REQUIRE( advData.dataLength() == (MAX_AD_DATA_LENGTH) ); - } - - WHEN("Set manufacturer data given id after setting manufacturer data without id") - { - advData.clear(); - // dataGivenId is too long!! it should not pass - const uint8_t dataGivenId[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27}; - const uint8_t data[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28}; - retVal = advData.setManufacturerData(data, sizeof(data)); - REQUIRE(retVal); - retVal = advData.setManufacturerData(companyId, dataGivenId, sizeof(dataGivenId)); - REQUIRE(!retVal); - } - - WHEN("Overwrite manufacturer data with one as long as max data length") - { - const uint8_t data[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26}; - const uint8_t goldenData[] = {(sizeof(data) + sizeof(companyId) + 1), BLEFieldManufacturerData, - 0x00, 0x11, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, - 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26}; - retVal = advData.setManufacturerData(companyId, data, sizeof(data)); - REQUIRE(retVal); - - advData.updateData(); - REQUIRE( 0 == advData.remainingLength() ); - REQUIRE( 0 == advData.availableForWrite() ); - REQUIRE( 0 == memcmp(goldenData, advData.data(), sizeof(goldenData)) ); - } - - WHEN("Check consistency when setting the external advertising data") - { - auto goldenData = advData.data(); - BLE.setAdvertisingData(advData); - BLE.advertise(); - REQUIRE( 0 == memcmp(goldenData, BLE.getAdvertisingData().data(), advData.dataLength()) ); - } - - // Clear BLE advertising data - advData.clear(); - BLE.setAdvertisingData(advData); -} diff --git a/extras/test/src/test_advertising_data/test_service.cpp b/extras/test/src/test_advertising_data/test_service.cpp deleted file mode 100644 index 5c212c1f..00000000 --- a/extras/test/src/test_advertising_data/test_service.cpp +++ /dev/null @@ -1,149 +0,0 @@ -/* - This file is part of the ArduinoBLE library. - Copyright (c) 2018 Arduino SA. All rights reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#include <catch.hpp> - -#define private public -#define protected public - -#include "FakeBLELocalDevice.h" -#include "BLEAdvertisingData.h" - -TEST_CASE("Test advertised service id setting", "[ArduinoBLE::BLEAdvertisingData]") -{ - BLEAdvertisingData advData; - int oldRemainingLength = advData.remainingLength(); - bool retVal; - - WHEN("Set correct advertised service") - { - const char* service = "00112233445566770011223344556677"; - retVal = advData.setAdvertisedServiceUuid(service); - REQUIRE(retVal); - REQUIRE( (16 + 2) == (oldRemainingLength - advData.remainingLength()) ); - oldRemainingLength = advData.remainingLength(); - - advData.updateData(); - REQUIRE(advData.dataLength() == (16 + 2)); - } - - WHEN("Set an advertised id too long with respect to the remaining length") - { - advData.clear(); - const char* name = "12 chars str"; - const char* service = "00112233445566770011223344556677"; - advData.setLocalName(name); - oldRemainingLength = advData.remainingLength(); - retVal = advData.setAdvertisedServiceUuid(service); - REQUIRE(!retVal); - - REQUIRE( oldRemainingLength == advData.remainingLength() ); - advData.updateData(); - REQUIRE( advData.dataLength() == (MAX_AD_DATA_LENGTH - oldRemainingLength) ); - } - - WHEN("Fill to maximum an advertising packet with a service id") - { - advData.clear(); - const char* name = "11 char str"; - const char* service = "00112233445566770011223344556677"; - advData.setLocalName(name); - retVal = advData.setAdvertisedServiceUuid(service); - REQUIRE(retVal); - - advData.updateData(); - REQUIRE(advData.dataLength() == (MAX_AD_DATA_LENGTH)); - // advData should be full now - REQUIRE( 0 == advData.remainingLength() ); - REQUIRE( 0 == advData.availableForWrite() ); - } - - WHEN("Check consistency when setting the external advertising data") - { - auto goldenData = advData.data(); - BLE.setAdvertisingData(advData); - BLE.advertise(); - REQUIRE( 0 == memcmp(goldenData, BLE.getAdvertisingData().data(), advData.dataLength()) ); - } - - // Clear BLE advertising data - advData.clear(); - BLE.setAdvertisingData(advData); -} - -TEST_CASE("Test service data setting", "[ArduinoBLE::BLEAdvertisingData]") -{ - BLEAdvertisingData advData; - int oldRemainingLength = advData.remainingLength(); - uint16_t uuid = 0x1100; - bool retVal; - - WHEN("Set correct service data") - { - const uint8_t data[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; - const uint8_t goldenData[] = {(sizeof(data) + sizeof(uuid) + 1), BLEFieldServiceData, - 0x00, 0x11, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; - retVal = advData.setAdvertisedServiceData(uuid, data, sizeof(data)); - REQUIRE(retVal); - REQUIRE( (sizeof(data) + 2 + sizeof(uuid)) == (oldRemainingLength - advData.remainingLength()) ); - oldRemainingLength = advData.remainingLength(); - - advData.updateData(); - REQUIRE(advData.dataLength() == (sizeof(data) + 2 + sizeof(uuid))); - REQUIRE(advData.dataLength() == sizeof(goldenData)); - REQUIRE( 0 == memcmp(goldenData, advData.data(), sizeof(goldenData)) ); - } - - WHEN("Set too long service data") - { - // extreme case, 1 byte more than the maximum - const uint8_t data[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27}; - retVal = advData.setAdvertisedServiceData(uuid, data, sizeof(data)); - REQUIRE(!retVal); - REQUIRE( oldRemainingLength == advData.remainingLength() ); - advData.updateData(); - REQUIRE( advData.dataLength() == (MAX_AD_DATA_LENGTH - oldRemainingLength) ); - } - - WHEN("Overwrite service data with one as long as max data length") - { - const uint8_t data[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26}; - retVal = advData.setAdvertisedServiceData(uuid, data, sizeof(data)); - REQUIRE(retVal); - - advData.updateData(); - // advData should be full now - REQUIRE( 0 == advData.remainingLength() ); - REQUIRE( 0 == advData.availableForWrite() ); - } - - WHEN("Check consistency when setting the external advertising data") - { - auto goldenData = advData.data(); - BLE.setAdvertisingData(advData); - BLE.advertise(); - REQUIRE( 0 == memcmp(goldenData, BLE.getAdvertisingData().data(), advData.dataLength()) ); - } - - // Clear BLE advertising data - advData.clear(); - BLE.setAdvertisingData(advData); -} diff --git a/extras/test/src/test_discovered_device/FakeGAP.cpp b/extras/test/src/test_discovered_device/FakeGAP.cpp deleted file mode 100644 index bbf78206..00000000 --- a/extras/test/src/test_discovered_device/FakeGAP.cpp +++ /dev/null @@ -1,31 +0,0 @@ -/* - This file is part of the ArduinoBLE library. - Copyright (c) 2018 Arduino SA. All rights reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#include "FakeGAP.h" - -FakeGAPClass::FakeGAPClass() -{ -} - -FakeGAPClass::~FakeGAPClass() -{ -} - -FakeGAPClass GAPFakeObj; -GAPClass& GAP = GAPFakeObj; diff --git a/extras/test/src/test_discovered_device/test_discovered_device.cpp b/extras/test/src/test_discovered_device/test_discovered_device.cpp deleted file mode 100644 index a6b54eb4..00000000 --- a/extras/test/src/test_discovered_device/test_discovered_device.cpp +++ /dev/null @@ -1,52 +0,0 @@ -/* - This file is part of the ArduinoBLE library. - Copyright (c) 2018 Arduino SA. All rights reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#include <catch.hpp> - -#define private public -#define protected public -#include "BLEDevice.h" - -TEST_CASE("BLE discovered device test", "[ArduinoBLE::BLEDevice]") -{ - - WHEN("Retrieve local name from advertisement packet") - { - // Mocking advertisement packet - uint8_t advType = 0x03; - uint8_t eirLength = 6; - uint8_t eirData[] = {0x05, 0x09, 't', 'e', 's', 't'}; - uint8_t rssi = 0; - - // Expected results - String goldenName = "test"; - - // Simulate device discovery - BLEDevice device = BLEDevice(); - device.setAdvertisementData(0x03, eirLength, eirData, rssi); - - bool hasName = device.hasLocalName(); - REQUIRE(hasName); - - String name = device.localName(); - REQUIRE(goldenName == name); - - } - -} diff --git a/extras/test/src/test_main.cpp b/extras/test/src/test_main.cpp deleted file mode 100644 index 16dbfb81..00000000 --- a/extras/test/src/test_main.cpp +++ /dev/null @@ -1,21 +0,0 @@ -/* - This file is part of the ArduinoBLE library. - Copyright (c) 2018 Arduino SA. All rights reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#define CATCH_CONFIG_MAIN /* This tells Catch to provide a main() - only do this in one cpp file */ -#include <catch.hpp> diff --git a/extras/test/src/test_uuid/test_uuid.cpp b/extras/test/src/test_uuid/test_uuid.cpp deleted file mode 100644 index 13b655e6..00000000 --- a/extras/test/src/test_uuid/test_uuid.cpp +++ /dev/null @@ -1,52 +0,0 @@ -/* - This file is part of the ArduinoBLE library. - Copyright (c) 2018 Arduino SA. All rights reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#include <catch.hpp> - -#include "utility/BLEUuid.h" - -TEST_CASE("BLE uuid test", "[ArduinoBLE::BLEUuid]") -{ - WHEN("Set and retrieve uuid") - { - bool verify; - - const char* goldenUuid = "19b10010-e8f2-537e-4f6c-d104768a1214"; - // little-endian order - const uint8_t goldenData[] = {0x14,0x12,0x8A,0x76,0x04,0xD1,0x6C,0x4F,0x7E,0x53,0xF2,0xE8,0x10,0x00,0xB1,0x19}; - uint8_t goldenLength = 16; - - BLEUuid test(goldenUuid); - - uint8_t testLength = test.length(); - verify = (goldenLength == testLength); - REQUIRE(verify); - - const uint8_t *testData = test.data(); - verify = ( 0 == (memcmp(goldenData, testData, sizeof(goldenData))) ); - REQUIRE(verify); - - const char *testUuid = test.uuidToString(testData, testLength); - verify = ( 0 == strcmp(testUuid, goldenUuid) ); - REQUIRE(verify); - - // print the uuid - WARN("test: " << testUuid << ", golden: " << goldenUuid); - } -} \ No newline at end of file diff --git a/extras/test/src/util/Common.cpp b/extras/test/src/util/Common.cpp deleted file mode 100644 index e2e1eeb5..00000000 --- a/extras/test/src/util/Common.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/* - This file is part of the ArduinoBLE library. - Copyright (c) 2018 Arduino SA. All rights reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#include "Common.h" - -void delay(unsigned long) -{ - -} - -/* C++ prototypes */ -long map(long x, long in_min, long in_max, long out_min, long out_max) -{ - return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; -} - -uint16_t makeWord(uint16_t w) { return w; } -uint16_t makeWord(uint8_t h, uint8_t l) { return (h << 8) | l; } \ No newline at end of file diff --git a/extras/test/src/util/HCIFakeTransport.cpp b/extras/test/src/util/HCIFakeTransport.cpp deleted file mode 100644 index 26645f5e..00000000 --- a/extras/test/src/util/HCIFakeTransport.cpp +++ /dev/null @@ -1,23 +0,0 @@ -/* - This file is part of the ArduinoBLE library. - Copyright (c) 2018 Arduino SA. All rights reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#include "HCIFakeTransport.h" - -HCIFakeTransportClass HCIFakeTransport; -HCITransportInterface& HCITransport = HCIFakeTransport; \ No newline at end of file diff --git a/extras/test/src/util/String.cpp b/extras/test/src/util/String.cpp deleted file mode 100644 index 618973b6..00000000 --- a/extras/test/src/util/String.cpp +++ /dev/null @@ -1,755 +0,0 @@ -/* - String library for Wiring & Arduino - ...mostly rewritten by Paul Stoffregen... - Copyright (c) 2009-10 Hernando Barragan. All rights reserved. - Copyright 2011, Paul Stoffregen, paul@pjrc.com - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#include "String.h" -#include "itoa.h" - -/*********************************************/ -/* Constructors */ -/*********************************************/ - -namespace arduino { - -String::String(const char *cstr) -{ - init(); - if (cstr) copy(cstr, strlen(cstr)); -} - -String::String(const String &value) -{ - init(); - *this = value; -} - -String::String(const __FlashStringHelper *pstr) -{ - init(); - *this = pstr; -} - -#if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) -String::String(String &&rval) -{ - init(); - move(rval); -} -String::String(StringSumHelper &&rval) -{ - init(); - move(rval); -} -#endif - -String::String(char c) -{ - init(); - char buf[2]; - buf[0] = c; - buf[1] = 0; - *this = buf; -} - -String::String(unsigned char value, unsigned char base) -{ - init(); - char buf[1 + 8 * sizeof(unsigned char)]; - utoa(value, buf, base); - *this = buf; -} - -String::String(int value, unsigned char base) -{ - init(); - char buf[2 + 8 * sizeof(int)]; - itoa(value, buf, base); - *this = buf; -} - -String::String(unsigned int value, unsigned char base) -{ - init(); - char buf[1 + 8 * sizeof(unsigned int)]; - utoa(value, buf, base); - *this = buf; -} - -String::String(long value, unsigned char base) -{ - init(); - char buf[2 + 8 * sizeof(long)]; - ltoa(value, buf, base); - *this = buf; -} - -String::String(unsigned long value, unsigned char base) -{ - init(); - char buf[1 + 8 * sizeof(unsigned long)]; - ultoa(value, buf, base); - *this = buf; -} - -/* -String::String(float value, unsigned char decimalPlaces) -{ - init(); - char buf[33]; - *this = dtostrf(value, (decimalPlaces + 2), decimalPlaces, buf); -} - -String::String(double value, unsigned char decimalPlaces) -{ - init(); - char buf[33]; - *this = dtostrf(value, (decimalPlaces + 2), decimalPlaces, buf); -} -*/ - -String::~String() -{ - if (buffer) free(buffer); -} - -/*********************************************/ -/* Memory Management */ -/*********************************************/ - -inline void String::init(void) -{ - buffer = NULL; - capacity = 0; - len = 0; -} - -void String::invalidate(void) -{ - if (buffer) free(buffer); - buffer = NULL; - capacity = len = 0; -} - -unsigned char String::reserve(unsigned int size) -{ - if (buffer && capacity >= size) return 1; - if (changeBuffer(size)) { - if (len == 0) buffer[0] = 0; - return 1; - } - return 0; -} - -unsigned char String::changeBuffer(unsigned int maxStrLen) -{ - char *newbuffer = (char *)realloc(buffer, maxStrLen + 1); - if (newbuffer) { - buffer = newbuffer; - capacity = maxStrLen; - return 1; - } - return 0; -} - -/*********************************************/ -/* Copy and Move */ -/*********************************************/ - -String & String::copy(const char *cstr, unsigned int length) -{ - if (!reserve(length)) { - invalidate(); - return *this; - } - len = length; - strcpy(buffer, cstr); - return *this; -} - -/* -String & String::copy(const __FlashStringHelper *pstr, unsigned int length) -{ - if (!reserve(length)) { - invalidate(); - return *this; - } - len = length; - strcpy_P(buffer, (PGM_P)pstr); - return *this; -} -*/ - -#if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) -void String::move(String &rhs) -{ - if (buffer) { - if (rhs && capacity >= rhs.len) { - strcpy(buffer, rhs.buffer); - len = rhs.len; - rhs.len = 0; - return; - } else { - free(buffer); - } - } - buffer = rhs.buffer; - capacity = rhs.capacity; - len = rhs.len; - rhs.buffer = NULL; - rhs.capacity = 0; - rhs.len = 0; -} -#endif - -String & String::operator = (const String &rhs) -{ - if (this == &rhs) return *this; - - if (rhs.buffer) copy(rhs.buffer, rhs.len); - else invalidate(); - - return *this; -} - -#if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) -String & String::operator = (String &&rval) -{ - if (this != &rval) move(rval); - return *this; -} - -String & String::operator = (StringSumHelper &&rval) -{ - if (this != &rval) move(rval); - return *this; -} -#endif - -String & String::operator = (const char *cstr) -{ - if (cstr) copy(cstr, strlen(cstr)); - else invalidate(); - - return *this; -} - -/* -String & String::operator = (const __FlashStringHelper *pstr) -{ - if (pstr) copy(pstr, strlen_P((PGM_P)pstr)); - else invalidate(); - - return *this; -} -*/ - -/*********************************************/ -/* concat */ -/*********************************************/ - -unsigned char String::concat(const String &s) -{ - return concat(s.buffer, s.len); -} - -unsigned char String::concat(const char *cstr, unsigned int length) -{ - unsigned int newlen = len + length; - if (!cstr) return 0; - if (length == 0) return 1; - if (!reserve(newlen)) return 0; - strcpy(buffer + len, cstr); - len = newlen; - return 1; -} - -unsigned char String::concat(const char *cstr) -{ - if (!cstr) return 0; - return concat(cstr, strlen(cstr)); -} - -unsigned char String::concat(char c) -{ - char buf[2]; - buf[0] = c; - buf[1] = 0; - return concat(buf, 1); -} - -unsigned char String::concat(unsigned char num) -{ - char buf[1 + 3 * sizeof(unsigned char)]; - itoa(num, buf, 10); - return concat(buf, strlen(buf)); -} - -unsigned char String::concat(int num) -{ - char buf[2 + 3 * sizeof(int)]; - itoa(num, buf, 10); - return concat(buf, strlen(buf)); -} - -unsigned char String::concat(unsigned int num) -{ - char buf[1 + 3 * sizeof(unsigned int)]; - utoa(num, buf, 10); - return concat(buf, strlen(buf)); -} - -unsigned char String::concat(long num) -{ - char buf[2 + 3 * sizeof(long)]; - ltoa(num, buf, 10); - return concat(buf, strlen(buf)); -} - -unsigned char String::concat(unsigned long num) -{ - char buf[1 + 3 * sizeof(unsigned long)]; - ultoa(num, buf, 10); - return concat(buf, strlen(buf)); -} - -/* -unsigned char String::concat(float num) -{ - char buf[20]; - char* string = dtostrf(num, 4, 2, buf); - return concat(string, strlen(string)); -} - -unsigned char String::concat(double num) -{ - char buf[20]; - char* string = dtostrf(num, 4, 2, buf); - return concat(string, strlen(string)); -} - -unsigned char String::concat(const __FlashStringHelper * str) -{ - if (!str) return 0; - int length = strlen_P((const char *) str); - if (length == 0) return 1; - unsigned int newlen = len + length; - if (!reserve(newlen)) return 0; - strcpy_P(buffer + len, (const char *) str); - len = newlen; - return 1; -} -*/ - -/*********************************************/ -/* Concatenate */ -/*********************************************/ - -StringSumHelper & operator + (const StringSumHelper &lhs, const String &rhs) -{ - StringSumHelper &a = const_cast<StringSumHelper&>(lhs); - if (!a.concat(rhs.buffer, rhs.len)) a.invalidate(); - return a; -} - -StringSumHelper & operator + (const StringSumHelper &lhs, const char *cstr) -{ - StringSumHelper &a = const_cast<StringSumHelper&>(lhs); - if (!cstr || !a.concat(cstr, strlen(cstr))) a.invalidate(); - return a; -} - -StringSumHelper & operator + (const StringSumHelper &lhs, char c) -{ - StringSumHelper &a = const_cast<StringSumHelper&>(lhs); - if (!a.concat(c)) a.invalidate(); - return a; -} - -StringSumHelper & operator + (const StringSumHelper &lhs, unsigned char num) -{ - StringSumHelper &a = const_cast<StringSumHelper&>(lhs); - if (!a.concat(num)) a.invalidate(); - return a; -} - -StringSumHelper & operator + (const StringSumHelper &lhs, int num) -{ - StringSumHelper &a = const_cast<StringSumHelper&>(lhs); - if (!a.concat(num)) a.invalidate(); - return a; -} - -StringSumHelper & operator + (const StringSumHelper &lhs, unsigned int num) -{ - StringSumHelper &a = const_cast<StringSumHelper&>(lhs); - if (!a.concat(num)) a.invalidate(); - return a; -} - -StringSumHelper & operator + (const StringSumHelper &lhs, long num) -{ - StringSumHelper &a = const_cast<StringSumHelper&>(lhs); - if (!a.concat(num)) a.invalidate(); - return a; -} - -StringSumHelper & operator + (const StringSumHelper &lhs, unsigned long num) -{ - StringSumHelper &a = const_cast<StringSumHelper&>(lhs); - if (!a.concat(num)) a.invalidate(); - return a; -} - -/* -StringSumHelper & operator + (const StringSumHelper &lhs, float num) -{ - StringSumHelper &a = const_cast<StringSumHelper&>(lhs); - if (!a.concat(num)) a.invalidate(); - return a; -} - -StringSumHelper & operator + (const StringSumHelper &lhs, double num) -{ - StringSumHelper &a = const_cast<StringSumHelper&>(lhs); - if (!a.concat(num)) a.invalidate(); - return a; -} - -StringSumHelper & operator + (const StringSumHelper &lhs, const __FlashStringHelper *rhs) -{ - StringSumHelper &a = const_cast<StringSumHelper&>(lhs); - if (!a.concat(rhs)) a.invalidate(); - return a; -} -*/ - -/*********************************************/ -/* Comparison */ -/*********************************************/ - -int String::compareTo(const String &s) const -{ - if (!buffer || !s.buffer) { - if (s.buffer && s.len > 0) return 0 - *(unsigned char *)s.buffer; - if (buffer && len > 0) return *(unsigned char *)buffer; - return 0; - } - return strcmp(buffer, s.buffer); -} - -int String::compareTo(const char *cstr) const -{ - if (!buffer || !cstr) { - if (cstr && !*cstr) return 0 - *(unsigned char *)cstr; - if (buffer && len > 0) return *(unsigned char *)buffer; - return 0; - } - return strcmp(buffer, cstr); -} - -unsigned char String::equals(const String &s2) const -{ - return (len == s2.len && compareTo(s2) == 0); -} - -unsigned char String::equals(const char *cstr) const -{ - if (len == 0) return (cstr == NULL || *cstr == 0); - if (cstr == NULL) return buffer[0] == 0; - return strcmp(buffer, cstr) == 0; -} - -unsigned char String::equalsIgnoreCase( const String &s2 ) const -{ - if (this == &s2) return 1; - if (len != s2.len) return 0; - if (len == 0) return 1; - const char *p1 = buffer; - const char *p2 = s2.buffer; - while (*p1) { - if (tolower(*p1++) != tolower(*p2++)) return 0; - } - return 1; -} - -unsigned char String::startsWith( const String &s2 ) const -{ - if (len < s2.len) return 0; - return startsWith(s2, 0); -} - -unsigned char String::startsWith( const String &s2, unsigned int offset ) const -{ - if (offset > len - s2.len || !buffer || !s2.buffer) return 0; - return strncmp( &buffer[offset], s2.buffer, s2.len ) == 0; -} - -unsigned char String::endsWith( const String &s2 ) const -{ - if ( len < s2.len || !buffer || !s2.buffer) return 0; - return strcmp(&buffer[len - s2.len], s2.buffer) == 0; -} - -/*********************************************/ -/* Character Access */ -/*********************************************/ - -char String::charAt(unsigned int loc) const -{ - return operator[](loc); -} - -void String::setCharAt(unsigned int loc, char c) -{ - if (loc < len) buffer[loc] = c; -} - -char & String::operator[](unsigned int index) -{ - static char dummy_writable_char; - if (index >= len || !buffer) { - dummy_writable_char = 0; - return dummy_writable_char; - } - return buffer[index]; -} - -char String::operator[]( unsigned int index ) const -{ - if (index >= len || !buffer) return 0; - return buffer[index]; -} - -void String::getBytes(unsigned char *buf, unsigned int bufsize, unsigned int index) const -{ - if (!bufsize || !buf) return; - if (index >= len) { - buf[0] = 0; - return; - } - unsigned int n = bufsize - 1; - if (n > len - index) n = len - index; - strncpy((char *)buf, buffer + index, n); - buf[n] = 0; -} - -/*********************************************/ -/* Search */ -/*********************************************/ - -int String::indexOf(char c) const -{ - return indexOf(c, 0); -} - -int String::indexOf( char ch, unsigned int fromIndex ) const -{ - if (fromIndex >= len) return -1; - const char* temp = strchr(buffer + fromIndex, ch); - if (temp == NULL) return -1; - return temp - buffer; -} - -int String::indexOf(const String &s2) const -{ - return indexOf(s2, 0); -} - -int String::indexOf(const String &s2, unsigned int fromIndex) const -{ - if (fromIndex >= len) return -1; - const char *found = strstr(buffer + fromIndex, s2.buffer); - if (found == NULL) return -1; - return found - buffer; -} - -int String::lastIndexOf( char theChar ) const -{ - return lastIndexOf(theChar, len - 1); -} - -int String::lastIndexOf(char ch, unsigned int fromIndex) const -{ - if (fromIndex >= len) return -1; - char tempchar = buffer[fromIndex + 1]; - buffer[fromIndex + 1] = '\0'; - char* temp = strrchr( buffer, ch ); - buffer[fromIndex + 1] = tempchar; - if (temp == NULL) return -1; - return temp - buffer; -} - -int String::lastIndexOf(const String &s2) const -{ - return lastIndexOf(s2, len - s2.len); -} - -int String::lastIndexOf(const String &s2, unsigned int fromIndex) const -{ - if (s2.len == 0 || len == 0 || s2.len > len) return -1; - if (fromIndex >= len) fromIndex = len - 1; - int found = -1; - for (char *p = buffer; p <= buffer + fromIndex; p++) { - p = strstr(p, s2.buffer); - if (!p) break; - if ((unsigned int)(p - buffer) <= fromIndex) found = p - buffer; - } - return found; -} - -String String::substring(unsigned int left, unsigned int right) const -{ - if (left > right) { - unsigned int temp = right; - right = left; - left = temp; - } - String out; - if (left >= len) return out; - if (right > len) right = len; - char temp = buffer[right]; // save the replaced character - buffer[right] = '\0'; - out = buffer + left; // pointer arithmetic - buffer[right] = temp; //restore character - return out; -} - -/*********************************************/ -/* Modification */ -/*********************************************/ - -void String::replace(char find, char replace) -{ - if (!buffer) return; - for (char *p = buffer; *p; p++) { - if (*p == find) *p = replace; - } -} - -void String::replace(const String& find, const String& replace) -{ - if (len == 0 || find.len == 0) return; - int diff = replace.len - find.len; - char *readFrom = buffer; - char *foundAt; - if (diff == 0) { - while ((foundAt = strstr(readFrom, find.buffer)) != NULL) { - memcpy(foundAt, replace.buffer, replace.len); - readFrom = foundAt + replace.len; - } - } else if (diff < 0) { - char *writeTo = buffer; - while ((foundAt = strstr(readFrom, find.buffer)) != NULL) { - unsigned int n = foundAt - readFrom; - memcpy(writeTo, readFrom, n); - writeTo += n; - memcpy(writeTo, replace.buffer, replace.len); - writeTo += replace.len; - readFrom = foundAt + find.len; - len += diff; - } - strcpy(writeTo, readFrom); - } else { - unsigned int size = len; // compute size needed for result - while ((foundAt = strstr(readFrom, find.buffer)) != NULL) { - readFrom = foundAt + find.len; - size += diff; - } - if (size == len) return; - if (size > capacity && !changeBuffer(size)) return; // XXX: tell user! - int index = len - 1; - while (index >= 0 && (index = lastIndexOf(find, index)) >= 0) { - readFrom = buffer + index + find.len; - memmove(readFrom + diff, readFrom, len - (readFrom - buffer)); - len += diff; - buffer[len] = 0; - memcpy(buffer + index, replace.buffer, replace.len); - index--; - } - } -} - -void String::remove(unsigned int index){ - // Pass the biggest integer as the count. The remove method - // below will take care of truncating it at the end of the - // string. - remove(index, (unsigned int)-1); -} - -void String::remove(unsigned int index, unsigned int count){ - if (index >= len) { return; } - if (count <= 0) { return; } - if (count > len - index) { count = len - index; } - char *writeTo = buffer + index; - len = len - count; - memmove(writeTo, buffer + index + count,len - index); - buffer[len] = 0; -} - -void String::toLowerCase(void) -{ - if (!buffer) return; - for (char *p = buffer; *p; p++) { - *p = tolower(*p); - } -} - -void String::toUpperCase(void) -{ - if (!buffer) return; - for (char *p = buffer; *p; p++) { - *p = toupper(*p); - } -} - -void String::trim(void) -{ - if (!buffer || len == 0) return; - char *begin = buffer; - while (isspace(*begin)) begin++; - char *end = buffer + len - 1; - while (isspace(*end) && end >= begin) end--; - len = end + 1 - begin; - if (begin > buffer) memmove(buffer, begin, len); - buffer[len] = 0; -} - -/*********************************************/ -/* Parsing / Conversion */ -/*********************************************/ - -long String::toInt(void) const -{ - if (buffer) return atol(buffer); - return 0; -} - -float String::toFloat(void) const -{ - return float(toDouble()); -} - -double String::toDouble(void) const -{ - if (buffer) return atof(buffer); - return 0; -} - -} // namespace arduino diff --git a/extras/test/src/util/TestUtil.cpp b/extras/test/src/util/TestUtil.cpp deleted file mode 100644 index 111607ec..00000000 --- a/extras/test/src/util/TestUtil.cpp +++ /dev/null @@ -1,3 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - */ diff --git a/extras/test/src/util/itoa.c b/extras/test/src/util/itoa.c deleted file mode 100644 index c9a275f6..00000000 --- a/extras/test/src/util/itoa.c +++ /dev/null @@ -1,126 +0,0 @@ -/* - Copyright (c) 2014 Arduino LLC. All right reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#include <itoa.h> -#include <string.h> - -#ifdef __cplusplus -extern "C" { -#endif - -extern char* itoa( int value, char *string, int radix ) -{ - return ltoa( value, string, radix ) ; -} - -extern char* ltoa( long value, char *string, int radix ) -{ - char tmp[33]; - char *tp = tmp; - long i; - unsigned long v; - int sign; - char *sp; - - if ( string == NULL ) - { - return 0 ; - } - - if (radix > 36 || radix <= 1) - { - return 0 ; - } - - sign = (radix == 10 && value < 0); - if (sign) - { - v = -value; - } - else - { - v = (unsigned long)value; - } - - while (v || tp == tmp) - { - i = v % radix; - v = v / radix; - if (i < 10) - *tp++ = i+'0'; - else - *tp++ = i + 'a' - 10; - } - - sp = string; - - if (sign) - *sp++ = '-'; - while (tp > tmp) - *sp++ = *--tp; - *sp = 0; - - return string; -} - -extern char* utoa( unsigned int value, char *string, int radix ) -{ - return ultoa( value, string, radix ) ; -} - -extern char* ultoa( unsigned long value, char *string, int radix ) -{ - char tmp[33]; - char *tp = tmp; - long i; - unsigned long v = value; - char *sp; - - if ( string == NULL ) - { - return 0; - } - - if (radix > 36 || radix <= 1) - { - return 0; - } - - while (v || tp == tmp) - { - i = v % radix; - v = v / radix; - if (i < 10) - *tp++ = i+'0'; - else - *tp++ = i + 'a' - 10; - } - - sp = string; - - - while (tp > tmp) - *sp++ = *--tp; - *sp = 0; - - return string; -} - -#ifdef __cplusplus -} // extern "C" -#endif diff --git a/keywords.txt b/keywords.txt index ecfbafbf..04ef0505 100644 --- a/keywords.txt +++ b/keywords.txt @@ -1,12 +1,12 @@ ####################################### -# Syntax Coloring Map For ArduinoBLE +# Syntax Coloring Map For STM32duinoBLE ####################################### ####################################### # Datatypes (KEYWORD1) ####################################### -ArduinoBLE KEYWORD1 +STM32duinoBLE KEYWORD1 BLE KEYWORD1 BLEDevice KEYWORD1 diff --git a/library.properties b/library.properties index 6e248f5f..94860ca4 100644 --- a/library.properties +++ b/library.properties @@ -1,10 +1,10 @@ -name=ArduinoBLE +name=STM32duinoBLE version=1.3.7 -author=Arduino -maintainer=Arduino <info@arduino.cc> -sentence=Enables Bluetooth® Low Energy connectivity on the Arduino MKR WiFi 1010, Arduino UNO WiFi Rev2, Arduino Nano 33 IoT, Arduino Nano 33 BLE, Nicla Sense ME and UNO R4 WiFi. +author=Arduino, SRA +maintainer=stm32duino +sentence=Fork of ArduinoBLE library to add the support of SPBTLE-RF, SPBTLE-1S, BLUENRG-M2SP, BLUENRG-LP and BLUENRG-M0 BLE modules. paragraph=This library supports creating a Bluetooth® Low Energy peripheral & central mode. category=Communication -url=https://www.arduino.cc/en/Reference/ArduinoBLE -architectures=samd,megaavr,mbed,apollo3,mbed_nano,mbed_portenta,mbed_nicla,esp32,mbed_giga,renesas,renesas_portenta,mbed_opta,renesas_uno,silabs -includes=ArduinoBLE.h +url=https://github.com/stm32duino/STM32duinoBLE +architectures=stm32 +includes=STM32duinoBLE.h diff --git a/src/ArduinoBLE.h b/src/STM32duinoBLE.h similarity index 94% rename from src/ArduinoBLE.h rename to src/STM32duinoBLE.h index 588d5cb1..c603e3da 100644 --- a/src/ArduinoBLE.h +++ b/src/STM32duinoBLE.h @@ -17,8 +17,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef _ARDUINO_BLE_H_ -#define _ARDUINO_BLE_H_ +#ifndef _STM32DUINO_BLE_H_ +#define _STM32DUINO_BLE_H_ #include "local/BLELocalDevice.h" #include "BLEProperty.h" diff --git a/src/utility/CordioHCICustomDriver.h b/src/utility/CordioHCICustomDriver.h deleted file mode 100644 index fc062ee8..00000000 --- a/src/utility/CordioHCICustomDriver.h +++ /dev/null @@ -1,17 +0,0 @@ -#if defined(CORE_CM4) - -#include "CyH4TransportDriver.h" - -ble::vendor::cypress_ble::CyH4TransportDriver& ble_cordio_get_h4_transport_driver() -{ - static ble::vendor::cypress_ble::CyH4TransportDriver s_transport_driver( - /* TX */ CYBSP_BT_UART_TX, /* RX */ CYBSP_BT_UART_RX, - /* cts */ CYBSP_BT_UART_CTS, /* rts */ CYBSP_BT_UART_RTS, NC, DEF_BT_BAUD_RATE, - CYBSP_BT_HOST_WAKE, CYBSP_BT_DEVICE_WAKE - ); - return s_transport_driver; -} - -#define CUSTOM_HCI_DRIVER - -#endif \ No newline at end of file diff --git a/src/utility/HCICordioTransport.cpp b/src/utility/HCICordioTransport.cpp deleted file mode 100644 index 7848712f..00000000 --- a/src/utility/HCICordioTransport.cpp +++ /dev/null @@ -1,314 +0,0 @@ -/* - This file is part of the ArduinoBLE library. - Copyright (c) 2019 Arduino SA. All rights reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#if defined(ARDUINO_ARCH_MBED) && !defined(TARGET_NANO_RP2040_CONNECT) // && !defined(CORE_CM4) -#include <Arduino.h> -#include <mbed.h> - -#include <driver/CordioHCITransportDriver.h> -#include <driver/CordioHCIDriver.h> - -#if defined(ARDUINO_PORTENTA_H7_M4) || defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_NICLA_VISION) || defined(ARDUINO_GIGA) || defined(ARDUINO_OPTA) -#include "ble/BLE.h" -#include <events/mbed_events.h> -#endif - -// Parts of this file are based on: https://github.com/ARMmbed/mbed-os-cordio-hci-passthrough/pull/2 -// With permission from the Arm Mbed team to re-license - -#if CORDIO_ZERO_COPY_HCI -#include <wsf_types.h> -#include <wsf_buf.h> -#include <wsf_msg.h> -#include <wsf_os.h> -#include <wsf_buf.h> -#include <wsf_timer.h> - -/* avoid many small allocs (and WSF doesn't have smaller buffers) */ -#define MIN_WSF_ALLOC (16) -#endif //CORDIO_ZERO_COPY_HCI - -#include "HCICordioTransport.h" - -#if (MBED_VERSION > MBED_ENCODE_VERSION(6, 2, 0)) -#define BLE_NAMESPACE ble -#else -#define BLE_NAMESPACE ble::vendor::cordio -#endif - -#include "CordioHCICustomDriver.h" - -extern BLE_NAMESPACE::CordioHCIDriver& ble_cordio_get_hci_driver(); - -namespace BLE_NAMESPACE { - struct CordioHCIHook { - static CordioHCIDriver& getDriver() { - return ble_cordio_get_hci_driver(); - } - - static CordioHCITransportDriver& getTransportDriver() { - return getDriver()._transport_driver; - } - - static void setDataReceivedHandler(void (*handler)(uint8_t*, uint8_t)) { - getTransportDriver().set_data_received_handler(handler); - } - }; -} - -using BLE_NAMESPACE::CordioHCIHook; - -#if CORDIO_ZERO_COPY_HCI -extern uint8_t *SystemHeapStart; -extern uint32_t SystemHeapSize; - -void init_wsf(BLE_NAMESPACE::buf_pool_desc_t& buf_pool_desc) { - static bool init = false; - - if (init) { - return; - } - init = true; - - // use the buffer for the WSF heap - SystemHeapStart = buf_pool_desc.buffer_memory; - SystemHeapSize = buf_pool_desc.buffer_size; - - // Initialize buffers with the ones provided by the HCI driver - uint16_t bytes_used = WsfBufInit( - buf_pool_desc.pool_count, - (wsfBufPoolDesc_t*)buf_pool_desc.pool_description - ); - - // Raise assert if not enough memory was allocated - MBED_ASSERT(bytes_used != 0); - - SystemHeapStart += bytes_used; - SystemHeapSize -= bytes_used; - - WsfTimerInit(); -} - - -extern "C" void wsf_mbed_ble_signal_event(void) -{ - // do nothing -} -#endif //CORDIO_ZERO_COPY_HCI - -static void bleLoop() -{ -#if CORDIO_ZERO_COPY_HCI - uint64_t last_update_us = 0; - mbed::LowPowerTimer timer; - - timer.start(); - - while (true) { - last_update_us += (uint64_t) timer.read_high_resolution_us(); - timer.reset(); - - uint64_t last_update_ms = (last_update_us / 1000); - wsfTimerTicks_t wsf_ticks = (last_update_ms / WSF_MS_PER_TICK); - - if (wsf_ticks > 0) { - WsfTimerUpdate(wsf_ticks); - last_update_us -= (last_update_ms * 1000); - } - - wsfOsDispatcher(); - - bool sleep = false; - { - /* call needs interrupts disabled */ - mbed::CriticalSectionLock critical_section; - if (wsfOsReadyToSleep()) { - sleep = true; - } - } - - uint64_t time_spent = (uint64_t) timer.read_high_resolution_us(); - - /* don't bother sleeping if we're already past tick */ - if (sleep && (WSF_MS_PER_TICK * 1000 > time_spent)) { - /* sleep to maintain constant tick rate */ - uint64_t wait_time_us = WSF_MS_PER_TICK * 1000 - time_spent; - uint64_t wait_time_ms = wait_time_us / 1000; - - wait_time_us = wait_time_us % 1000; - - if (wait_time_ms) { - rtos::ThisThread::sleep_for(wait_time_ms); - } - - if (wait_time_us) { - wait_us(wait_time_us); - } - } - } -#else - while(true) { - rtos::ThisThread::sleep_for(osWaitForever); - } -#endif // CORDIO_ZERO_COPY_HCI -} - -static rtos::EventFlags bleEventFlags; -static rtos::Thread* bleLoopThread = NULL; - - -HCICordioTransportClass::HCICordioTransportClass() : - _begun(false) -{ -} - -HCICordioTransportClass::~HCICordioTransportClass() -{ -} - -#if (defined(ARDUINO_PORTENTA_H7_M4) || defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_NICLA_VISION) || defined(ARDUINO_GIGA) || defined(ARDUINO_OPTA)) && !defined(CUSTOM_HCI_DRIVER) -events::EventQueue eventQueue(10 * EVENTS_EVENT_SIZE); -void scheduleMbedBleEvents(BLE::OnEventsToProcessCallbackContext *context) { - eventQueue.call(mbed::Callback<void()>(&context->ble, &BLE::processEvents)); -} - -void completeCallback(BLE::InitializationCompleteCallbackContext *context) { - eventQueue.break_dispatch(); -} -#endif - -int HCICordioTransportClass::begin() -{ - _rxBuf.clear(); - -#if CORDIO_ZERO_COPY_HCI - BLE_NAMESPACE::buf_pool_desc_t bufPoolDesc = CordioHCIHook::getDriver().get_buffer_pool_description(); - init_wsf(bufPoolDesc); -#endif - -#if (defined(ARDUINO_PORTENTA_H7_M4) || defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_NICLA_VISION) || defined(ARDUINO_GIGA) || defined(ARDUINO_OPTA)) && !defined(CUSTOM_HCI_DRIVER) - - BLE &ble = BLE::Instance(); - ble.onEventsToProcess(scheduleMbedBleEvents); - - ble.init(completeCallback); - eventQueue.dispatch(10000); - - if (!ble.hasInitialized()){ - return 0; - } -#else - CordioHCIHook::getDriver().initialize(); -#endif - - if (bleLoopThread == NULL) { - bleLoopThread = new rtos::Thread(); - bleLoopThread->start(bleLoop); - } - - CordioHCIHook::setDataReceivedHandler(HCICordioTransportClass::onDataReceived); - - _begun = true; - - return 1; -} - -void HCICordioTransportClass::end() -{ - if (bleLoopThread != NULL) { - bleLoopThread->terminate(); - delete bleLoopThread; - bleLoopThread = NULL; - } - -#if !defined(TARGET_STM32H7) - CordioHCIHook::getDriver().terminate(); -#endif - - _begun = false; -} - -void HCICordioTransportClass::wait(unsigned long timeout) -{ - if (available()) { - return; - } - - // wait for handleRxData to signal - bleEventFlags.wait_all(0x01, timeout, true); -} - -int HCICordioTransportClass::available() -{ - return _rxBuf.available(); -} - -int HCICordioTransportClass::peek() -{ - return _rxBuf.peek(); -} - -int HCICordioTransportClass::read() -{ - return _rxBuf.read_char(); -} - -size_t HCICordioTransportClass::write(const uint8_t* data, size_t length) -{ - if (!_begun) { - return 0; - } - - uint8_t packetLength = length - 1; - uint8_t packetType = data[0]; - -#if CORDIO_ZERO_COPY_HCI - uint8_t* packet = (uint8_t*)WsfMsgAlloc(max(packetLength, MIN_WSF_ALLOC)); - - memcpy(packet, &data[1], packetLength); - - return CordioHCIHook::getTransportDriver().write(packetType, packetLength, packet); -#else - return CordioHCIHook::getTransportDriver().write(packetType, packetLength, (uint8_t*)&data[1]); -#endif -} - -void HCICordioTransportClass::handleRxData(uint8_t* data, uint8_t len) -{ - if (_rxBuf.availableForStore() < len) { - // drop! - return; - } - - for (int i = 0; i < len; i++) { - _rxBuf.store_char(data[i]); - } - - bleEventFlags.set(0x01); -} - -HCICordioTransportClass HCICordioTransport; -HCITransportInterface& HCITransport = HCICordioTransport; - -void HCICordioTransportClass::onDataReceived(uint8_t* data, uint8_t len) -{ - HCICordioTransport.handleRxData(data, len); -} - -#endif diff --git a/src/utility/HCICordioTransport.h b/src/utility/HCICordioTransport.h deleted file mode 100644 index b8d0596a..00000000 --- a/src/utility/HCICordioTransport.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - This file is part of the ArduinoBLE library. - Copyright (c) 2019 Arduino SA. All rights reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#ifndef _HCI_CORDIO_TRANSPORT_H_ -#define _HCI_CORDIO_TRANSPORT_H_ - -#include <string.h> - -#include "api/RingBuffer.h" - -#include "HCITransport.h" - -class HCICordioTransportClass : public HCITransportInterface { -public: - HCICordioTransportClass(); - virtual ~HCICordioTransportClass(); - - virtual int begin(); - virtual void end(); - - virtual void wait(unsigned long timeout); - - virtual int available(); - virtual int peek(); - virtual int read(); - - virtual size_t write(const uint8_t* data, size_t length); - -private: - static void onDataReceived(uint8_t* data, uint8_t len); - void handleRxData(uint8_t* data, uint8_t len); - -private: - bool _begun; - RingBufferN<256> _rxBuf; -}; - -#endif diff --git a/src/utility/HCISilabsTransport.cpp b/src/utility/HCISilabsTransport.cpp deleted file mode 100644 index 135fd020..00000000 --- a/src/utility/HCISilabsTransport.cpp +++ /dev/null @@ -1,130 +0,0 @@ -/* - This file is part of the ArduinoBLE library. - Copyright (c) 2024 Arduino SA. All rights reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#if defined(ARDUINO_SILABS) - -#include "HCISilabsTransport.h" -#include "sl_string.h" - -extern "C" { -#include "sl_btctrl_linklayer.h" -#include "sl_hci_common_transport.h" -} - -extern "C" int strcasecmp(char const *a, char const *b) { - return sl_strcasecmp(a, b); -} - -static RingBufferN<512> buf; - -HCISilabsTransportClass::HCISilabsTransportClass() -{ -} - -HCISilabsTransportClass::~HCISilabsTransportClass() -{ -} - -int HCISilabsTransportClass::begin() -{ - if(!sl_btctrl_is_initialized()) { - sl_bt_controller_init(); - } - - /* Initialize adv & scan components */ - sl_btctrl_init_adv(); - sl_btctrl_init_scan(); - sl_btctrl_init_conn(); - sl_btctrl_init_adv_ext(); - sl_btctrl_init_scan_ext(); - - /* Initialize HCI controller */ - sl_bthci_init_upper(); - sl_btctrl_hci_parser_init_default(); - sl_btctrl_hci_parser_init_conn(); - sl_btctrl_hci_parser_init_adv(); - sl_btctrl_hci_parser_init_phy(); - - return 1; -} - -void HCISilabsTransportClass::end() -{ - sl_bt_controller_deinit(); -} - -void HCISilabsTransportClass::wait(unsigned long timeout) -{ - for (unsigned long start = millis(); (millis() - start) < timeout;) { - if (available()) { - break; - } - } -} - -int HCISilabsTransportClass::available() -{ - return buf.available(); -} - -int HCISilabsTransportClass::peek() -{ - return buf.peek(); -} - -int HCISilabsTransportClass::read() -{ - return buf.read_char(); -} - -size_t HCISilabsTransportClass::write(const uint8_t* data, size_t len) -{ - int ret = 0; - ret = hci_common_transport_receive((uint8_t *)data, len, true); - - if (ret == 0) return len; - - return 0; -} - -extern "C" { - /** - * @brief Transmit HCI message using the currently used transport layer. - * The HCI calls this function to transmit a full HCI message. - * @param[in] data Packet type followed by HCI packet data. - * @param[in] len Length of the `data` parameter - * @return 0 - on success, or non-zero on failure. - */ - uint32_t hci_common_transport_transmit(uint8_t *data, int16_t len) - { - for (int i = 0; i < len; i++) { - buf.store_char(data[i]); - if (buf.isFull()) return SL_STATUS_FAIL; - } - - sl_btctrl_hci_transmit_complete(0); - return 0; - } -} - -HCISilabsTransportClass HCISilabsTransport; - -HCITransportInterface& HCITransport = HCISilabsTransport; - -#endif diff --git a/src/utility/HCISilabsTransport.h b/src/utility/HCISilabsTransport.h deleted file mode 100644 index 2061e782..00000000 --- a/src/utility/HCISilabsTransport.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - This file is part of the ArduinoBLE library. - Copyright (c) 2018 Arduino SA. All rights reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#ifndef _HCI_SILABS_TRANSPORT_H_ -#define _HCI_SILABS_TRANSPORT_H_ - -#include "HCITransport.h" - -class HCISilabsTransportClass : public HCITransportInterface { -public: - HCISilabsTransportClass(); - virtual ~HCISilabsTransportClass(); - - virtual int begin(); - virtual void end(); - - virtual void wait(unsigned long timeout); - - virtual int available(); - virtual int peek(); - virtual int read(); - - virtual size_t write(const uint8_t* data, size_t length); -}; - -#endif \ No newline at end of file diff --git a/src/utility/HCIUartTransport.cpp b/src/utility/HCIUartTransport.cpp deleted file mode 100644 index 191811a7..00000000 --- a/src/utility/HCIUartTransport.cpp +++ /dev/null @@ -1,109 +0,0 @@ -/* - This file is part of the ArduinoBLE library. - Copyright (c) 2018 Arduino SA. All rights reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#if !defined(ARDUINO_ARCH_MBED) && !defined(ESP32) && !defined(ARDUINO_SILABS) && !defined(ARDUINO_UNOR4_WIFI) || defined(TARGET_NANO_RP2040_CONNECT) //|| defined(CORE_CM4) - -#include "HCIUartTransport.h" - -#if defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_AVR_UNO_WIFI_REV2) -#define SerialHCI Serial2 -#elif defined(ARDUINO_SAMD_NANO_33_IOT) || defined(ARDUINO_NANO_RP2040_CONNECT) -// SerialHCI is already defined in the variant -#elif defined(ARDUINO_PORTENTA_H7_M4) -// SerialHCI is already defined in the variant -#elif defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_NICLA_VISION) -#define SerialHCI Serial2 -#elif defined(ARDUINO_OPTA) -#define SerialHCI Serial3 -#elif defined(ARDUINO_PORTENTA_C33) -#define SerialHCI Serial5 -#elif defined(ARDUINO_GIGA) -arduino::UART SerialHCI(CYBSP_BT_UART_TX, CYBSP_BT_UART_RX, CYBSP_BT_UART_RTS, CYBSP_BT_UART_CTS); -#else -#error "Unsupported board selected!" -#endif - -HCIUartTransportClass::HCIUartTransportClass(HardwareSerial& uart, unsigned long baudrate) : - _uart(&uart), - _baudrate(baudrate) -{ -} - -HCIUartTransportClass::~HCIUartTransportClass() -{ -} - -int HCIUartTransportClass::begin() -{ - _uart->begin(_baudrate); - - return 1; -} - -void HCIUartTransportClass::end() -{ - _uart->end(); -} - -void HCIUartTransportClass::wait(unsigned long timeout) -{ - for (unsigned long start = millis(); (millis() - start) < timeout;) { - if (available()) { - break; - } - } -} - -int HCIUartTransportClass::available() -{ - return _uart->available(); -} - -int HCIUartTransportClass::peek() -{ - return _uart->peek(); -} - -int HCIUartTransportClass::read() -{ - return _uart->read(); -} - -size_t HCIUartTransportClass::write(const uint8_t* data, size_t length) -{ -#ifdef ARDUINO_AVR_UNO_WIFI_REV2 - // wait while the CTS pin is low - while (digitalRead(NINA_CTS) == HIGH); -#endif - - size_t result = _uart->write(data, length); - - _uart->flush(); - - return result; -} - -#if defined(ARDUINO_AVR_UNO_WIFI_REV2) || defined(ARDUINO_NANO_RP2040_CONNECT) -HCIUartTransportClass HCIUartTransport(SerialHCI, 119600); -#else -HCIUartTransportClass HCIUartTransport(SerialHCI, 912600); -#endif -HCITransportInterface& HCITransport = HCIUartTransport; - -#endif diff --git a/src/utility/HCIUartTransport.h b/src/utility/HCIUartTransport.h deleted file mode 100644 index ba70dff4..00000000 --- a/src/utility/HCIUartTransport.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - This file is part of the ArduinoBLE library. - Copyright (c) 2018 Arduino SA. All rights reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#ifndef _HCI_UART_TRANSPORT_H_ -#define _HCI_UART_TRANSPORT_H_ - -#include "HCITransport.h" - -class HCIUartTransportClass : public HCITransportInterface { -public: - HCIUartTransportClass(HardwareSerial& uart, unsigned long baudrate); - virtual ~HCIUartTransportClass(); - - virtual int begin(); - virtual void end(); - - virtual void wait(unsigned long timeout); - - virtual int available(); - virtual int peek(); - virtual int read(); - - virtual size_t write(const uint8_t* data, size_t length); - -private: - HardwareSerial* _uart; - unsigned long _baudrate; -}; - -#endif diff --git a/src/utility/HCIVirtualTransport.cpp b/src/utility/HCIVirtualTransport.cpp deleted file mode 100644 index 046a0e72..00000000 --- a/src/utility/HCIVirtualTransport.cpp +++ /dev/null @@ -1,142 +0,0 @@ -/* - This file is part of the ArduinoBLE library. - Copyright (c) 2018 Arduino SA. All rights reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#if defined(ESP32) - -#include "HCIVirtualTransport.h" - -StreamBufferHandle_t rec_buffer; -StreamBufferHandle_t send_buffer; -TaskHandle_t bleHandle; - - -static void notify_host_send_available(void) -{ -} - -static int notify_host_recv(uint8_t *data, uint16_t length) -{ - xStreamBufferSend(rec_buffer,data,length,portMAX_DELAY); // !!!potentially waiting forever - return 0; -} - -static esp_vhci_host_callback_t vhci_host_cb = { - notify_host_send_available, - notify_host_recv -}; - -void bleTask(void *pvParameters) -{ - esp_vhci_host_register_callback(&vhci_host_cb); - size_t length; - uint8_t mybuf[258]; - - while(true){ - length = xStreamBufferReceive(send_buffer,mybuf,258,portMAX_DELAY); - while (!esp_vhci_host_check_send_available()) {} - esp_vhci_host_send_packet(mybuf, length); - } -} - - -HCIVirtualTransportClass::HCIVirtualTransportClass() -{ -} - -HCIVirtualTransportClass::~HCIVirtualTransportClass() -{ -} - -int HCIVirtualTransportClass::begin() -{ - btStarted(); // this somehow stops the arduino ide from initializing bluedroid - - rec_buffer = xStreamBufferCreate(258, 1); - send_buffer = xStreamBufferCreate(258, 1); - - esp_err_t ret = nvs_flash_init(); - if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) { - ESP_ERROR_CHECK(nvs_flash_erase()); - ret = nvs_flash_init(); - } - esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT(); - -#if CONFIG_IDF_TARGET_ESP32 - bt_cfg.mode = ESP_BT_MODE_BLE; //original esp32 chip -#else - bt_cfg.bluetooth_mode = ESP_BT_MODE_BLE; //different api for newer models -#endif - - esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT); - esp_bt_controller_init(&bt_cfg); - esp_bt_controller_enable(ESP_BT_MODE_BLE); - xTaskCreatePinnedToCore(&bleTask, "bleTask", 2048, NULL, 5, &bleHandle, 0); - return 1; -} - -void HCIVirtualTransportClass::end() -{ - vStreamBufferDelete(rec_buffer); - vStreamBufferDelete(send_buffer); - esp_bt_controller_disable(); - esp_bt_controller_deinit(); - vTaskDelete(bleHandle); -} - -void HCIVirtualTransportClass::wait(unsigned long timeout) -{ - for (unsigned long start = (esp_timer_get_time() / 1000ULL); ((esp_timer_get_time() / 1000ULL) - start) < timeout;) { - if (available()) { - break; - } - } -} - -int HCIVirtualTransportClass::available() -{ - size_t bytes = xStreamBufferBytesAvailable(rec_buffer); - return bytes; -} - -// never called -int HCIVirtualTransportClass::peek() -{ - return -1; -} - -int HCIVirtualTransportClass::read() -{ - uint8_t c; - if(xStreamBufferReceive(rec_buffer, &c, 1, portMAX_DELAY)) { - return c; - } - return -1; -} - -size_t HCIVirtualTransportClass::write(const uint8_t* data, size_t length) -{ - size_t result = xStreamBufferSend(send_buffer,data,length,portMAX_DELAY); - return result; -} - -HCIVirtualTransportClass HCIVirtualTransport; - -HCITransportInterface& HCITransport = HCIVirtualTransport; - -#endif diff --git a/src/utility/HCIVirtualTransport.h b/src/utility/HCIVirtualTransport.h deleted file mode 100644 index 0da43cac..00000000 --- a/src/utility/HCIVirtualTransport.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - This file is part of the ArduinoBLE library. - Copyright (c) 2018 Arduino SA. All rights reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#include "HCITransport.h" -#include <stdint.h> -#include <stdio.h> -#include <string.h> - -#include "freertos/FreeRTOS.h" -#include "freertos/task.h" -#include "freertos/stream_buffer.h" - -#include "esp_bt.h" -#include "nvs_flash.h" - -#include "esp32-hal-bt.h" // this is needed to disable bluedroid - - -class HCIVirtualTransportClass : public HCITransportInterface { -public: - HCIVirtualTransportClass(); - virtual ~HCIVirtualTransportClass(); - - virtual int begin(); - virtual void end(); - - virtual void wait(unsigned long timeout); - - virtual int available(); - virtual int peek(); - virtual int read(); - - virtual size_t write(const uint8_t* data, size_t length); -}; \ No newline at end of file diff --git a/src/utility/HCIVirtualTransportAT.cpp b/src/utility/HCIVirtualTransportAT.cpp deleted file mode 100644 index 7b3a24a9..00000000 --- a/src/utility/HCIVirtualTransportAT.cpp +++ /dev/null @@ -1,112 +0,0 @@ -/* - This file is part of the ArduinoBLE library. - Copyright (c) 2018 Arduino SA. All rights reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#if defined(ARDUINO_UNOR4_WIFI) - -#include "HCIVirtualTransportAT.h" - -extern ModemClass modem; - -HCIVirtualTransportATClass::HCIVirtualTransportATClass() -{ -} - -HCIVirtualTransportATClass::~HCIVirtualTransportATClass() -{ -} - -static RingBufferN<258> buf; - -int HCIVirtualTransportATClass::begin() -{ - // TODO: add this helper - //modem.debug(Serial); - buf.clear(); - //modem.debug(true); - std::string res = ""; - modem.begin(); - if (modem.write(std::string(PROMPT(_HCI_BEGIN)), res, CMD(_HCI_BEGIN))) { - return 1; - } - return 0; -} - -void HCIVirtualTransportATClass::end() -{ -} - -void HCIVirtualTransportATClass::wait(unsigned long timeout) -{ - std::string res = ""; - modem.write(std::string(PROMPT(_HCI_WAIT)), res, "%d\n\r", CMD_WRITE(_HCI_WAIT), timeout); -} - -int HCIVirtualTransportATClass::available() -{ - std::string res = ""; - if (buf.available()) { - return buf.available(); - } - if (modem.write(std::string(PROMPT(_HCI_AVAILABLE)), res, CMD_READ(_HCI_AVAILABLE))) { - return atoi(res.c_str()); - } - - return 0; -} - -// never called -int HCIVirtualTransportATClass::peek() -{ - return -1; -} - -int HCIVirtualTransportATClass::read() -{ - uint8_t c; - std::string res = ""; - if (buf.available()) { - return buf.read_char(); - } - modem.avoid_trim_results(); - modem.read_using_size(); - if (modem.write(std::string(PROMPT(_HCI_READ)), res, CMD(_HCI_READ))) { - for(int i = 0; i < res.size(); i++) { - buf.store_char((uint8_t)res[i]); - } - return buf.read_char(); - } - - return -1; -} - -size_t HCIVirtualTransportATClass::write(const uint8_t* data, size_t length) -{ - std::string res = ""; - modem.write_nowait(std::string(PROMPT(_HCI_WRITE)), res, "%s%d\r\n" , CMD_WRITE(_HCI_WRITE), length); - if(modem.passthrough(data, length)) { - return length; - } - return 0; -} - -HCIVirtualTransportATClass HCIVirtualTransportAT; - -HCITransportInterface& HCITransport = HCIVirtualTransportAT; - -#endif diff --git a/src/utility/HCIVirtualTransportAT.h b/src/utility/HCIVirtualTransportAT.h deleted file mode 100644 index 8e29801d..00000000 --- a/src/utility/HCIVirtualTransportAT.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - This file is part of the ArduinoBLE library. - Copyright (c) 2018 Arduino SA. All rights reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#include "HCITransport.h" -#include <stdint.h> -#include <stdio.h> -#include <string.h> - -#include "WiFiS3.h" - -class HCIVirtualTransportATClass : public HCITransportInterface { -public: - HCIVirtualTransportATClass(); - virtual ~HCIVirtualTransportATClass(); - - virtual int begin(); - virtual void end(); - - virtual void wait(unsigned long timeout); - - virtual int available(); - virtual int peek(); - virtual int read(); - - virtual size_t write(const uint8_t* data, size_t length); -}; \ No newline at end of file diff --git a/src/utility/btct.cpp b/src/utility/btct.cpp index 6829494c..199c9e0d 100644 --- a/src/utility/btct.cpp +++ b/src/utility/btct.cpp @@ -1,7 +1,7 @@ #include "btct.h" #include <Arduino.h> #include "HCI.h" -#include "ArduinoBLE.h" +#include "STM32duinoBLE.h" BluetoothCryptoToolbox::BluetoothCryptoToolbox(){} // In step 1, AES-128 with key K is applied to an all-zero input block. // In step 2, K1 is derived through the following operation: From 197b2a51a831c0476924e1a6952d9aaf44408ac1 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Tue, 18 Mar 2025 16:38:00 +0100 Subject: [PATCH 182/226] feat: ability to define HCI SPI transport configuration Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- README.md | 55 +++++++++++++++++++++++++++++++++ src/utility/HCISpiTransport.cpp | 13 ++++++-- 2 files changed, 65 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e9f3a948..62186871 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,61 @@ https://github.com/stm32duino/Arduino_Core_STM32/wiki/STM32duinoBLE#stm32duinobl For more information about ArduinoBLE library please visit the official web page at: https://www.arduino.cc/en/Reference/ArduinoBLE +# Configuration + +### Shield + +The user can include the file `ble_spi_conf.h` to define which shield and configuration to use from the following list: + + * [X-NUCLEO-IDB05A2] + * `IDB05A2_SPI_CLOCK_D3`: SPI clock on D3 + * `IDB05A2_SPI_CLOCK_D13` SPI clock on D13 + * [X-NUCLEO-IDB05A1] + * `IDB05A1_SPI_CLOCK_D3`: SPI clock on D3 + * `IDB05A1_SPI_CLOCK_D13`: SPI clock on D13 + * [X-NUCLEO-BNRG2A1] + * `BNRG2A1_SPI_CLOCK_D3`: SPI clock on D3 + * `BNRG2A1_SPI_CLOCK_D13`: SPI clock on D13 + * `CUSTOM_BLE_SPI`: define a custom configuration, it requires below definition: + * `BLE_SPI_MISO`: SPI MISO pin + * `BLE_SPI_MOSI`: SPI MOSI pin + * `BLE_SPI_CLK`: SPI CLocK pin + * `BLE_SPI_CS`: SPI Chip Select pin + * `BLE_SPI_IRQ`: SPI IRQ pin + * `BLE_SPI_FREQ`: SPI bus frequency + * `BLE_SPI_MODE`: can be one of the below `SPIMode`: + * `SPI_MODE0` + * `SPI_MODE1` + * `SPI_MODE2` + * `SPI_MODE0` + * `BLE_CHIP_TYPE`: can be one of the below `BLEChip_t`: + * `SPBTLE_RF` + * `SPBTLE_1S` + * `BLUENRG_M2SP` + * `BLUENRG_M0` + * `BLUENRG_LP` + * `BLE_RESET`: BLE reset pin + +#### Examples + +To use the [X-NUCLEO-IDB05A2] with SPI clock on D3, define in `ble_spi_conf.h`: +```C +#define IDB05A2_SPI_CLOCK_D3 +``` +This is equivalent to the below configuration using the `CUSTOM_BLE_SPI`: +```C +#define CUSTOM_BLE_SPI +#define BLE_SPI_MISO D12 +#define BLE_SPI_MOSI D11 +#define BLE_SPI_CLK D3 +#define BLE_SPI_CS A1 +#define BLE_SPI_IRQ A0 +#define BLE_SPI_FREQ 8000000 +#define BLE_SPI_MODE SPI_MODE0 +#define BLE_CHIP_TYPE BLUENRG_M0 +#define BLE_RESET D7 +``` + ## License ``` diff --git a/src/utility/HCISpiTransport.cpp b/src/utility/HCISpiTransport.cpp index 91c2c5dc..9a3709da 100644 --- a/src/utility/HCISpiTransport.cpp +++ b/src/utility/HCISpiTransport.cpp @@ -19,7 +19,14 @@ #include "HCISpiTransport.h" -#if defined(ARDUINO_STEVAL_MKBOXPRO) +#if __has_include("ble_spi_conf.h") + #include "ble_spi_conf.h" +#endif + +#if defined(CUSTOM_BLE_SPI) +SPIClass SpiHCI(BLE_SPI_MOSI, BLE_SPI_MISO, BLE_SPI_CLK); +HCISpiTransportClass HCISpiTransport(SpiHCI, BLE_CHIP_TYPE, BLE_SPI_CS, BLE_SPI_IRQ, BLE_RESET, BLE_SPI_FREQ, BLE_SPI_MODE); +#elif defined(ARDUINO_STEVAL_MKBOXPRO) /* STEVAL-MKBOXPRO */ SPIClass SpiHCI(PA7, PA6, PA5); HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_LP, PA2, PB11, PD4, 1000000, SPI_MODE3); @@ -51,11 +58,11 @@ HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI /* Shield IDB05A1 with SPI clock on D13 */ #define SpiHCI SPI HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI_MODE0); -#elif defined(BNRG2A1_CLOCK_D3) +#elif defined(BNRG2A1_SPI_CLOCK_D3) /* Shield BNRG2A1 with SPI clock on D3 */ SPIClass SpiHCI(D11, D12, D3); HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1); -#elif defined(BNRG2A1_CLOCK_D13) +#elif defined(BNRG2A1_SPI_CLOCK_D13) /* Shield BNRG2A1 with SPI clock on D13 */ #define SpiHCI SPI HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1); From 5c49886c5b571313528a4ad527a2ee8b8dd59e1c Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Mon, 17 Feb 2020 10:08:13 +0100 Subject: [PATCH 183/226] chore(ci): add build-for-stm32 step Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- .github/workflows/compile-examples.yml | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index c298c638..f90e4784 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -15,3 +15,28 @@ on: workflow_dispatch: jobs: + build-for-stm32: + runs-on: ubuntu-latest + + strategy: + matrix: + fqbn: + - STMicroelectronics:stm32:Eval:pnum=STEVAL_MKSBOX1V1,usb=CDCgen + - STMicroelectronics:stm32:Nucleo_64:pnum=NUCLEO_L476RG + - STMicroelectronics:stm32:Disco:pnum=B_L475E_IOT01A + + steps: + - uses: actions/checkout@v4 + - uses: arduino/compile-sketches@v1 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + fqbn: ${{ matrix.fqbn }} + platforms: | + - name: STMicroelectronics:stm32 + source-url: https://github.com/stm32duino/BoardManagerFiles/raw/main/package_stmicroelectronics_index.json + sketch-paths: | + - examples + cli-compile-flags: | + - --build-property + - build.extra_flags=-DIDB05A2_SPI_CLOCK_D3 + From 94ab67e28e58e39d80480eebe3a55b112f050c9a Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Tue, 18 Mar 2025 09:27:33 +0100 Subject: [PATCH 184/226] feat: add editor config Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- .editorconfig | 26 ++++++++++++++++++++++++++ .gitattributes | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 .editorconfig create mode 100644 .gitattributes diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..47433680 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,26 @@ +[*] +end_of_line = lf +insert_final_newline = true +indent_style = space +indent_size = 2 +trim_trailing_whitespace = true + +[*.patch] +insert_final_newline = unset +indent_style = unset +indent_size = unset +trim_trailing_whitespace = unset + +[*.md] +trim_trailing_whitespace = false + +[*.sh] +# like -i=2 +indent_style = space +indent_size = 2 + +#shell_variant = posix # like -ln=posix +#binary_next_line = true # like -bn +switch_case_indent = true # like -ci +space_redirects = true # like -sr +#keep_padding = true # like -kp diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..422ae6f5 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,42 @@ +# Set the default behavior, in case people don't have core.autocrlf set. +* text=auto + +# Explicitly declare text files you want to always be normalized and converted +# to native line endings on checkout. +.editorconfig text eol=lf +.flake8 text eol=lf +.gitattributes text eol=lf +.gitignore text eol=lf + +*.adoc text eol=lf +*.c text eol=lf +*.cmake text eol=lf +*.cpp text eol=lf +*.css text eol=lf +*.dtsi text eol=lf +*.gv text eol=lf +*.h text eol=lf +*.html text eol=lf +*.in text eol=lf +*.ino text eol=lf +*.json text eol=lf +*.ld text eol=lf +*.md text eol=lf +*.MD text eol=lf +*.old text eol=lf +*.patch text eol=lf +*.pde text eol=lf +*.properties text eol=lf +*.py text eol=lf +*.s text eol=lf +*.S text eol=lf +*.sh text eol=lf +*.spec text eol=lf +*.txt text eol=lf +*.yml text eol=lf + +# Denote all files that are truly binary and should not be modified. +*.jpg binary +*.pdf binary +*.png binary + From dd9eaa91a40244dc39dea45b51b370504c129bdc Mon Sep 17 00:00:00 2001 From: Francois Ramu <francois.ramu@st.com> Date: Tue, 18 Mar 2025 09:33:50 +0100 Subject: [PATCH 185/226] feat: add HCISharedMemTransport to support the shared memory transport layer for the STM32WB built-in chip. It also Allows HCI SPI Transport with STM32WBxx Signed-off-by: Francois Ramu <francois.ramu@st.com> Co-Authored-by: Frederic Pillon <frederic.pillon@st.com> --- keywords.txt | 1 + src/utility/HCISharedMemTransport.cpp | 782 ++++++++++++++++++++++++++ src/utility/HCISharedMemTransport.h | 93 +++ 3 files changed, 876 insertions(+) create mode 100644 src/utility/HCISharedMemTransport.cpp create mode 100644 src/utility/HCISharedMemTransport.h diff --git a/keywords.txt b/keywords.txt index 04ef0505..6e761812 100644 --- a/keywords.txt +++ b/keywords.txt @@ -31,6 +31,7 @@ BLEDoubleCharacteristic KEYWORD1 BLEStringCharacteristic KEYWORD1 HCISpiTransportClass KEYWORD1 +HCISharedMemTransportClass KEYWORD1 ####################################### # Methods and Functions (KEYWORD2) diff --git a/src/utility/HCISharedMemTransport.cpp b/src/utility/HCISharedMemTransport.cpp new file mode 100644 index 00000000..ab462dfa --- /dev/null +++ b/src/utility/HCISharedMemTransport.cpp @@ -0,0 +1,782 @@ +/* + This file is part of the STM32duinoBLE library. + Copyright (c) 2019 STMicroelectronics. All rights reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ +#if defined(STM32WBxx) + +#include "HCISharedMemTransport.h" +#include "STM32_WPAN/hw.h" +#include "otp.h" + +#if defined(ARDUINO_NUCLEO_WB15CC) || defined(ARDUINO_P_NUCLEO_WB55RG) ||\ + defined(ARDUINO_STM32WB5MM_DK) || defined(ARDUINO_P_NUCLEO_WB55_USB_DONGLE) +HCISharedMemTransportClass HCISharedMemTransport; +#else +#error "Unsupported board or shield selected!" +#endif + +/* Private variables ---------------------------------------------------------*/ +PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static TL_CmdPacket_t BleCmdBuffer; + +PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static uint8_t EvtPool[POOL_SIZE]; +PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static TL_CmdPacket_t SystemCmdBuffer; +PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static uint8_t +SystemSpareEvtBuffer[sizeof(TL_PacketHeader_t) + TL_EVT_HDR_SIZE + 255]; +PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static uint8_t +BleSpareEvtBuffer[sizeof(TL_PacketHeader_t) + TL_EVT_HDR_SIZE + 255]; +PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static uint8_t +HciAclDataBuffer[sizeof(TL_PacketHeader_t) + 5 + 251]; + + +/* global var used as semaphore to control incoming events */ +volatile bool sys_event; /* true : M0 core is already up and running */ +volatile bool acl_data_on; /* true : sending ACL data in progress, false : send is possible */ +volatile bool data_overflow; + +/* buffer to store the received packets */ +volatile uint8_t _rxbuff[BLE_MODULE_SHARED_MEM_BUFFER_SIZE]; +volatile uint16_t _read_index; /* fifo position when reading */ +volatile uint16_t _write_index; /* fifo position when receiving */ + +/* var of different device steps during init and receiving */ +volatile bool phase_bd_addr; +volatile bool phase_tx_power; +volatile bool phase_reset; +volatile bool phase_running; + + +/** Bluetooth Device Address */ +static uint8_t bd_addr_udn[CONFIG_DATA_PUBADDR_LEN]; + +/* Private functions ---------------------------------------------------------*/ +/** + * TL Mailbox synchronization means + */ + +/* returns true if sys_event was received, false otherwise */ +static bool sysevt_wait(void) +{ + /* sys_event remains false until event is received */ + for (unsigned long start = millis(); (millis() - start) < BLE_IPCC_TIMEOUT;) { + /* Wait for 10sec max - if not return an error */ + if (sys_event) { + break; + } + } + + if (!sys_event) { +#if defined(PRINT_IPCC_INFO) + printf("ERROR: sys_evt timeout\r\n"); +#endif /*(PRINT_IPCC_INFO)*/ + /* no event received, timeout occurs */ + return false; + } + /* release immediately, now that M0 runs */ + return true; +} + +/* WEAK callbacks from the BLE TL driver - will be called under Interrupt */ +static void sysevt_received(void *pdata) +{ + UNUSED(pdata); + /* For now only READY event is received, so we know this is it */ + __disable_irq(); + sys_event = true; + __enable_irq(); + /* But later on ... we'll have to parse the answer */ +} + +/* returns true if sysevt was already received, which means M0 core is + * already up and running */ +static bool sysevt_check(void) +{ + /* Check if system is UP and running already */ + for (unsigned long start = millis(); (millis() - start) < 10;) { + /* Wait for 10ms max - if not return an error */ + if (sys_event) { + break; + } + } + if (sys_event) { + /* release immediately as M0 already runs */ + return true; + } + return false; +} + +static void acl_data_ack(void) +{ + /** + * The current implementation assumes the taskGUI will not send a new HCI ACL DATA packet before this ack is received + * ( which means the CPU2 has handled the previous packet ) + * In order to implement a secure mechanism, it is required either + * - a flow control with the stack + * - a local pool of buffer to store packets received from the stack + */ + __disable_irq(); + acl_data_on = false; + __enable_irq(); +} + +static bool acl_data_wait(void) +{ + /* Wait 10 sec for previous ACL command to be ack'ed by Low Layers + * before sending the next one */ + for (unsigned long start = millis(); (millis() - start) < BLE_IPCC_TIMEOUT;) { + /* Wait for 10sec max - if not return an error */ + if (!acl_data_on) { + break; + } + } + if (acl_data_on) { + /* no event received, timeout occurs */ +#if defined(PRINT_IPCC_INFO) + printf("ERROR: acl data timeout\r\n"); +#endif /*(PRINT_IPCC_INFO)*/ + return false; + } + /* release immediately, now that M0 runs */ + __disable_irq(); + acl_data_on = false; + __enable_irq(); + return true; +} + +static void syscmd_status_not(SHCI_TL_CmdStatus_t status) +{ +#if defined(PRINT_IPCC_INFO) + printf("syscmd_status_not, status:%d\r\n", status); +#else + UNUSED(status); +#endif /*(PRINT_IPCC_INFO)*/ +} + +/* to received BLE packet from the SharedMem */ +void evt_received(TL_EvtPacket_t *hcievt) +{ + uint16_t len = 0; + + /* We need to memcpy the data before passing to higher layers. + * The received packet is copied in the _rxbuff + * but it must not exceed the BLE_MODULE_SHARED_MEM_BUFFER_SIZE + */ + switch (hcievt->evtserial.type) { + case TL_BLEEVT_PKT_TYPE: { + /* before starting the running_phase', a RESET command (0x0C03) is sent + * by the HCI. Then this evt packet is temporarily kept in the _rxbuff + * the set_bd_address (0xFC0C) and the set_tw_power (0xFC0F) commands are sent. + * Only when both evt are received (not store in the _rxbuffer), + * the Reset packet is handled at HCI layer : the running_phase begins + */ + if (phase_running == false) { + /* check the Rx event of complete the previous bd_addr or random address opcode 0xFC0C */ + if ((hcievt->evtserial.evt.evtcode == TL_BLEEVT_CC_OPCODE) && + (hcievt->evtserial.evt.payload[0] == 0x01) && + (hcievt->evtserial.evt.payload[1] == 0x0C) && + (hcievt->evtserial.evt.payload[2] == 0xFC)) { + /* First setting must be global address + */ + phase_bd_addr = true; + + if (hcievt->evtserial.evt.payload[3] != 0) { +#if defined(PRINT_IPCC_INFO) + printf("Error: wrong BD Addr\r\n"); +#endif /*(PRINT_IPCC_INFO)*/ + } + /* rx data is no more useful : not stored in the _rxbuff */ + break; + } + /* check the Rx event of complete the previous tx power opcode 0xFC0F */ + if ((hcievt->evtserial.evt.evtcode == TL_BLEEVT_CC_OPCODE) && + (hcievt->evtserial.evt.payload[0] == 0x01) && + (hcievt->evtserial.evt.payload[1] == 0x0F) && + (hcievt->evtserial.evt.payload[2] == 0xFC)) { + phase_tx_power = true; + if (hcievt->evtserial.evt.payload[3] != 0) { +#if defined(PRINT_IPCC_INFO) + printf("Error: wrong Tx power\r\n"); +#endif /*(PRINT_IPCC_INFO)*/ + } + /* rx data is no more useful : not stored in the _rxbuff */ + break; + } + + /* check if the reset phase is in progress (opcode is 0x0C03) */ + if ((hcievt->evtserial.evt.evtcode == TL_BLEEVT_CC_OPCODE) && + (hcievt->evtserial.evt.payload[0] == 0x01) && + (hcievt->evtserial.evt.payload[1] == 0x03) && + (hcievt->evtserial.evt.payload[2] == 0x0C)) { + phase_reset = true; +#if defined(PRINT_IPCC_INFO) + if (hcievt->evtserial.evt.payload[3] != 0) { + printf("Error: wrong reset\r\n"); + } +#endif /*(PRINT_IPCC_INFO)*/ + } + } + __disable_irq(); + /* store received data in the _rxbuff buffer */ + len = hcievt->evtserial.evt.plen + TL_EVT_HDR_SIZE; + if (len < BLE_MODULE_SHARED_MEM_BUFFER_SIZE - _write_index) { + /* at the position of the _write_index */ + memcpy((uint8_t *)&_rxbuff[_write_index], (uint8_t *)&hcievt->evtserial, len); + /* move index */ + _write_index += len; + } else { + data_overflow = true; + } + __enable_irq(); + } + break; + case TL_ACL_DATA_PKT_TYPE: { + TL_AclDataSerial_t *acl = &(((TL_AclDataPacket_t *)hcievt)->AclDataSerial); + __disable_irq(); + len = acl->length + 5; + if (len < BLE_MODULE_SHARED_MEM_BUFFER_SIZE - _write_index) { + memcpy((uint8_t *)&_rxbuff[_write_index], (uint8_t *)acl, len); + /* move index */ + _write_index += len; + } else { + data_overflow = true; + } + __enable_irq(); + } + break; + default: + /* should not happen */ +#if defined(PRINT_IPCC_INFO) + printf("BLE TL evt_received, wrong type:%d\r\n", hcievt->evtserial.type); + while (1); /* let's block to check */ +#endif /*(PRINT_IPCC_INFO)*/ + break; + } +#if defined(PRINT_IPCC_INFO) + if (data_overflow) { + printf("Error: data read overflow\r\n"); + } +#endif /*(PRINT_IPCC_INFO)*/ + + /* In case Event belongs to the Evt Pool we need to inform */ + if (((uint8_t *)hcievt >= EvtPool) && ((uint8_t *)hcievt < (EvtPool + POOL_SIZE))) { + /* Free the message from shared memory */ + TL_MM_EvtDone(hcievt); + } +} + +/* to send BLE packet to the SharedMem : return nb of bytes actually written */ +uint16_t mbox_write(uint8_t type, uint16_t len, const uint8_t *pData) +{ + TL_CmdPacket_t *bleCmdBuf = &BleCmdBuffer; + // Note: Until enum is available + // type 01 Command + // type 02 ACL DATA + // type 03 SCO Voice (not supported) + // type 04 event - uplink (not supported) + switch (type) { + case 1: { //BLE command + bleCmdBuf->cmdserial.type = type; // for now this param is overwritten in TL_BLE_SendCmd + bleCmdBuf->cmdserial.cmd.plen = len; + memcpy((void *) &bleCmdBuf->cmdserial.cmd, pData, len); + /* We're tracing here the command, after copy in shared mem but before M0 trigger. */ + TL_BLE_SendCmd(NULL, 0); // unused parameters for now + } + break; + case 2: { //ACL DATA + if (!acl_data_wait()) { +#if defined(PRINT_IPCC_INFO) + printf("ERROR: previous ACL message not ACK'd\r\n"); +#endif /*(PRINT_IPCC_INFO)*/ + /* return number of bytes sent, 0 in this error case */ + return 0; + } + TL_AclDataSerial_t *aclDataSerial = (TL_AclDataSerial_t *)(HciAclDataBuffer + sizeof(TL_PacketHeader_t)); + aclDataSerial->type = type; // for now this param is overwritten in TL_BLE_SendCmd + memcpy(HciAclDataBuffer + sizeof(TL_PacketHeader_t) + sizeof(type), pData, len); + TL_BLE_SendAclData(NULL, 0); // unused parameters for now + __disable_irq(); + acl_data_on = true; /* data being send */ + __enable_irq(); + } + break; + default: +#if defined(PRINT_IPCC_INFO) + printf("ERROR: not supported type\r\n"); +#endif /*(PRINT_IPCC_INFO)*/ + /* return number of bytes sent, 0 in this error case */ + len = 0; + break; + } + return len; +} + +/** + * Few utilities functions + */ +/* This function fills in a BD address table */ +static bool get_bd_address(uint8_t *bd_addr) +{ + uint32_t udn; + uint32_t company_id; + uint32_t device_id; + bool bd_found; + + udn = LL_FLASH_GetUDN(); + + if (udn != 0xFFFFFFFF) { + /* "Found Unique Device Number: %#06x", udn) */ + + company_id = LL_FLASH_GetSTCompanyID(); + device_id = LL_FLASH_GetDeviceID(); + + bd_addr[0] = (uint8_t)(udn & 0x000000FF); + bd_addr[1] = (uint8_t)((udn & 0x0000FF00) >> 8); + bd_addr[2] = (uint8_t)device_id; + bd_addr[3] = (uint8_t)(company_id & 0x000000FF); + bd_addr[4] = (uint8_t)((company_id & 0x0000FF00) >> 8); + bd_addr[5] = (uint8_t)((company_id & 0x00FF0000) >> 16); + + bd_found = true; + } else { + OTP_BT_t *p_otp = (OTP_BT_t *)OTP_Read(0); + if (p_otp) { + memcpy(bd_addr, p_otp->bd_address, CONFIG_DATA_PUBADDR_LEN); + bd_found = true; + } else { + bd_found = false; + } + } + + return bd_found; +} + +static void init_debug(void) +{ + /* In case of debug profile, configure debugger support */ + +#if defined(CONFIG_DEBUG) +#if defined(PRINT_IPCC_INFO) + printf("init_debug ENABLED\r\n"); +#endif /*(PRINT_IPCC_INFO)*/ + /** + * Keep debugger enabled while in any low power mode + */ + HAL_DBGMCU_EnableDBGSleepMode(); + HAL_DBGMCU_EnableDBGStopMode(); + HAL_DBGMCU_EnableDBGStandbyMode(); + + /* Enable debugger: Debug power up request wakeup EXTI line 48 */ + LL_EXTI_EnableIT_32_63(LL_EXTI_LINE_48); + LL_C2_EXTI_EnableIT_32_63(LL_EXTI_LINE_48); + +#endif /* CONFIG_DEBUG */ +} + +/* Class definition ----------------------------------------------------------*/ + +HCISharedMemTransportClass::HCISharedMemTransportClass() +{ + _read_index = 0; /* fifo position when reading */ + _write_index = 0; /* fifo position when receiving */ + + memset((void *)_rxbuff, 0, sizeof(_rxbuff)); + + sys_event = false; + acl_data_on = false; + + data_overflow = false; + + phase_bd_addr = false; + phase_tx_power = false; + phase_reset = false; + phase_running = false; +} + +HCISharedMemTransportClass::~HCISharedMemTransportClass() +{ +} + +int HCISharedMemTransportClass::begin() +{ + int status = 1; + /* clean data Rx variables */ + _read_index = 0; + _write_index = 0; + + memset((void *)_rxbuff, 0, sizeof(_rxbuff)); + + /* Check whether M0 sub-system was started already by + * checking if the system event was already received + * before. If it was not, then go through all init. */ + if (!sysevt_check()) { + start_ble_rf(); + init_debug(); + /* Take BLE out of reset */ + stm32wb_reset(); + /* "C2 unlocking" */ + transport_init(); + /* At this stage, we got the ready event, + * passed through TL_SYS_EvtReceived */ + + WirelessFwInfo_t wireless_info_instance; + WirelessFwInfo_t *p_wireless_info = &wireless_info_instance; + SHCI_GetWirelessFwInfo(p_wireless_info); +#if defined(PRINT_IPCC_INFO) + printf("WB copro FW version = %d.%d.%d\r\n", p_wireless_info->VersionMajor, p_wireless_info->VersionMinor, p_wireless_info->VersionSub); +#endif /*(PRINT_IPCC_INFO)*/ + + /* Now start BLE service on firmware side, using Vendor specific + * command on the System Channel + */ + status = stm32wb_start_ble(); + + /* Once reset complete event is received we will need + * to send a few more commands: + * set bd addr with bt_ipm_set_addr(); + * during the HCI rest command */ + } + /* IPM Channel is now open */ +#if defined(PRINT_IPCC_INFO) + printf("IPM Channel Open Completed\r\n"); +#endif /*(PRINT_IPCC_INFO)*/ + + return status; +} + +void HCISharedMemTransportClass::end() +{ + /* M0 sub-system is already on (sys_event) */ + acl_data_on = false; + data_overflow = false; + + /* the HCI RESET command ready to be processed again */ + phase_bd_addr = false; + phase_tx_power = false; + phase_reset = false; + phase_running = false; +} + +void HCISharedMemTransportClass::wait(unsigned long timeout) +{ + for (unsigned long start = millis(); (millis() - start) < timeout;) { + if (available()) { + break; + } + } +} + +int HCISharedMemTransportClass::available() +{ + /* assuming the reset is already achieved, + * the LL-only mode is already configured. */ + + if (_read_index != _write_index) { + return 1; + } else if (data_overflow) { + __disable_irq(); + data_overflow = false; + __enable_irq(); + if (_read_index != _write_index) { + return 1; + } + } + + return 0; +} + +int HCISharedMemTransportClass::peek() +{ + int peek_val = -1; + __disable_irq(); + if (_read_index != _write_index) { + peek_val = _rxbuff[_read_index]; + } + __enable_irq(); + return peek_val; +} + +int HCISharedMemTransportClass::read() +{ + int read_val = -1; + __disable_irq(); + if (_read_index != _write_index) { + read_val = _rxbuff[_read_index]; + _read_index++; + if (_read_index == _write_index) { + /* Reset buffer index */ + _read_index = 0; + _write_index = 0; + } + } + __enable_irq(); + return read_val; +} + +size_t HCISharedMemTransportClass::write(const uint8_t *data, size_t length) +{ + const uint8_t *msg_data; + msg_data = &data[1]; + + /* capture the HCI reset send command opcode = 0x0C03 + * After HCI reset event complete in the evt_received(), + * the bd_addr and tx_power must be sent + * before the phase_running begins. + */ + if (phase_running) { + return mbox_write(data[0], (length - 1), msg_data);; + } + if ((data[1] == 0x03) && (data[2] == 0x0C)) { + phase_reset = false; + + if (mbox_write(data[0], (length - 1), msg_data) != (length - 1)) { + /* Error: no data are written */ + return 0; + } + /* capture event after HCI_RESET */ + while (!phase_reset); + + /* set the bd add */ + if (!bt_ipm_set_addr()) { + /* in case of error, no data are written */ + return 0; + } + /* wait for the Rx complete */ + while (!phase_bd_addr); + /* this sequence is now complete */ + + /* set the Tx power */ + bt_ipm_set_power(); + /* wait for the Rx complete */ + while (!phase_tx_power); + + /* this sequence is now complete */ + phase_running = true; + + return (length - 1); /* mbox_size of the HCI reset command */ + } + return 0; /* Error: no data written */ +} + +//private: +void HCISharedMemTransportClass::start_ble_rf(void) +{ + /* Set the DBP bit in the Power control register 1 (PWR_CR1) */ + LL_PWR_EnableBkUpAccess(); + + /* LSE belongs to the back-up domain, enable access.*/ + while (!LL_PWR_IsEnabledBkUpAccess()) { + /* Wait for Backup domain access */ + } + LL_RCC_ForceBackupDomainReset(); + LL_RCC_ReleaseBackupDomainReset(); + + /* Enable LSE Oscillator (32.768 kHz) */ + LL_RCC_LSE_Enable(); + while (!LL_RCC_LSE_IsReady()) { + /* Wait for LSE ready */ + } + + LL_PWR_DisableBkUpAccess(); + + /* Switch OFF LSI as LSE is the source clock */ + LL_RCC_LSI2_Disable(); +} + +void HCISharedMemTransportClass::stm32wb_reset(void) +{ + // Reset IPCC + LL_AHB3_GRP1_EnableClock(LL_AHB3_GRP1_PERIPH_IPCC); + + LL_C1_IPCC_ClearFlag_CHx( + IPCC, + LL_IPCC_CHANNEL_1 | LL_IPCC_CHANNEL_2 | LL_IPCC_CHANNEL_3 | LL_IPCC_CHANNEL_4 + | LL_IPCC_CHANNEL_5 | LL_IPCC_CHANNEL_6); + + LL_C2_IPCC_ClearFlag_CHx( + IPCC, + LL_IPCC_CHANNEL_1 | LL_IPCC_CHANNEL_2 | LL_IPCC_CHANNEL_3 | LL_IPCC_CHANNEL_4 + | LL_IPCC_CHANNEL_5 | LL_IPCC_CHANNEL_6); + + LL_C1_IPCC_DisableTransmitChannel( + IPCC, + LL_IPCC_CHANNEL_1 | LL_IPCC_CHANNEL_2 | LL_IPCC_CHANNEL_3 | LL_IPCC_CHANNEL_4 + | LL_IPCC_CHANNEL_5 | LL_IPCC_CHANNEL_6); + + LL_C2_IPCC_DisableTransmitChannel( + IPCC, + LL_IPCC_CHANNEL_1 | LL_IPCC_CHANNEL_2 | LL_IPCC_CHANNEL_3 | LL_IPCC_CHANNEL_4 + | LL_IPCC_CHANNEL_5 | LL_IPCC_CHANNEL_6); + + LL_C1_IPCC_DisableReceiveChannel( + IPCC, + LL_IPCC_CHANNEL_1 | LL_IPCC_CHANNEL_2 | LL_IPCC_CHANNEL_3 | LL_IPCC_CHANNEL_4 + | LL_IPCC_CHANNEL_5 | LL_IPCC_CHANNEL_6); + + LL_C2_IPCC_DisableReceiveChannel( + IPCC, + LL_IPCC_CHANNEL_1 | LL_IPCC_CHANNEL_2 | LL_IPCC_CHANNEL_3 | LL_IPCC_CHANNEL_4 + | LL_IPCC_CHANNEL_5 | LL_IPCC_CHANNEL_6); + + /* IPCC default IRQ handlers: IPCC_C1_TX_IRQHandler & IPCC_C1_RX_IRQHandler + * are mapped in the flash mem area, so that NVIC does not need to SetVector + */ +} + +int HCISharedMemTransportClass::stm32wb_start_ble(void) +{ + SHCI_C2_Ble_Init_Cmd_Packet_t ble_init_cmd_packet = { + 0, 0, 0, /**< Header unused */ + 0, /** pBleBufferAddress not used */ + 0, /** BleBufferSize not used */ + CFG_BLE_NUM_GATT_ATTRIBUTES, + CFG_BLE_NUM_GATT_SERVICES, + CFG_BLE_ATT_VALUE_ARRAY_SIZE, + CFG_BLE_NUM_LINK, + CFG_BLE_DATA_LENGTH_EXTENSION, + CFG_BLE_PREPARE_WRITE_LIST_SIZE, + CFG_BLE_MBLOCK_COUNT, + CFG_BLE_MAX_ATT_MTU, + CFG_BLE_PERIPHERAL_SCA, + CFG_BLE_CENTRAL_SCA, + CFG_BLE_LS_SOURCE, + CFG_BLE_MAX_CONN_EVENT_LENGTH, + CFG_BLE_HSE_STARTUP_TIME, + CFG_BLE_VITERBI_MODE, + CFG_BLE_OPTIONS, + 0, /** TODO Should be read from HW */ + CFG_BLE_MAX_COC_INITIATOR_NBR, + CFG_BLE_MIN_TX_POWER, + CFG_BLE_MAX_TX_POWER, + CFG_BLE_RX_MODEL_CONFIG, + CFG_BLE_MAX_ADV_SET_NBR, + CFG_BLE_MAX_ADV_DATA_LEN, + CFG_BLE_TX_PATH_COMPENS, + CFG_BLE_RX_PATH_COMPENS, + CFG_BLE_CORE_VERSION, + CFG_BLE_OPTIONS_EXT + }; + /** + * Starts the BLE Stack on CPU2 + */ + if (SHCI_C2_BLE_Init(&ble_init_cmd_packet) == SHCI_Success) { + return 1; + } + return 0; +} + +void HCISharedMemTransportClass::transport_init(void) +{ + TL_MM_Config_t tl_mm_config; + TL_BLE_InitConf_t tl_ble_config; + /* STM32WB offers a System Channel HCI interface for + offering system services, with proprietary commands. + System Channel must be used as well for starting up + BLE service so we need to initialize it. */ + SHCI_TL_HciInitConf_t shci_init_config; + + /**< Reference table initialization */ + TL_Init(); + + /**< System channel initialization */ + shci_init_config.p_cmdbuffer = (uint8_t *)&SystemCmdBuffer; + shci_init_config.StatusNotCallBack = syscmd_status_not; + shci_init(sysevt_received, (void *) &shci_init_config); + + /**< Memory Manager channel initialization */ + tl_mm_config.p_BleSpareEvtBuffer = BleSpareEvtBuffer; + tl_mm_config.p_SystemSpareEvtBuffer = SystemSpareEvtBuffer; + tl_mm_config.p_AsynchEvtPool = EvtPool; + tl_mm_config.AsynchEvtPoolSize = POOL_SIZE; + TL_MM_Init(&tl_mm_config); + + TL_Enable(); + + /* At this stage, we'll need to wait for ready event, + * passed through TL_SYS_EvtReceived */ + if (!sysevt_wait()) { +#if defined(PRINT_IPCC_INFO) + printf("ERROR booting WB controller\r\n"); +#endif /*(PRINT_IPCC_INFO)*/ + } else { + /**< BLE channel initialization */ + tl_ble_config.p_cmdbuffer = (uint8_t *)&BleCmdBuffer; + tl_ble_config.p_AclDataBuffer = HciAclDataBuffer; + tl_ble_config.IoBusEvtCallBack = evt_received; + tl_ble_config.IoBusAclDataTxAck = acl_data_ack; + TL_BLE_Init((void *)&tl_ble_config); + } +} + +int HCISharedMemTransportClass::bt_ipm_set_addr(void) +{ + /* the specific table for set addr is 8 bytes: + * one byte for config_offset + * one byte for length + * 6 bytes for payload */ + uint8_t data[4 + 8]; + + phase_bd_addr = false; + + if (get_bd_address(bd_addr_udn)) { + /* create ACI_HAL_WRITE_CONFIG_DATA */ + + data[0] = BT_BUF_CMD; + data[1] = uint8_t(ACI_WRITE_CONFIG_DATA_OPCODE & 0x000000FF); /* OCF */ + data[2] = uint8_t((ACI_WRITE_CONFIG_DATA_OPCODE & 0x0000FF00) >> 8); /* OGF */ + data[3] = 8; /* length of parameters */ + /* fill the ACI_HAL_WRITE_CONFIG_DATA with the addr*/ + data[4] = CONFIG_DATA_PUBADDR_OFFSET; /* the offset */ + data[5] = 6; /* is the length of the bd_addr table */ + memcpy(data + 6, bd_addr_udn, 6); + /* send the ACI_HAL_WRITE_CONFIG_DATA */ + if (mbox_write(data[0], 11, &data[1]) != 11) { + /* Error: no data are written */ + return 0; + } + /* now wait for the corresponding Rx event */ + return 1; /* success */ + } + return 0; /* Error */ +} + + +int HCISharedMemTransportClass::bt_ipm_set_power(void) +{ + /* the specific table for power is 2 bytes: + * En_High_Power byte, PA_level byte */ + uint8_t data[4 + 2]; + + phase_tx_power = false; + + data[0] = BT_BUF_CMD; /* the type */ + data[1] = (uint8_t)(ACI_HAL_SET_TX_POWER_LEVEL & 0x000000FF); /* the OPCODE */ + data[2] = (uint8_t)((ACI_HAL_SET_TX_POWER_LEVEL & 0x0000FF00) >> 8); + data[3] = 2; /* the length */ + /* fill the SET_POWER */ + data[4] = 0x01; /* En_High_Power */ + data[5] = CFG_TX_POWER; /* PA_level */ + + /* send the SET_POWER */ + if (mbox_write(data[0], 5, &data[1]) != 5) { + /* Error: no data are written */ + return 0; + } + /* now wait for the corresponding Rx event */ + return 1; /* success */ +} + +HCITransportInterface& HCITransport = HCISharedMemTransport; +#endif /* STM32WBxx */ diff --git a/src/utility/HCISharedMemTransport.h b/src/utility/HCISharedMemTransport.h new file mode 100644 index 00000000..e739d63f --- /dev/null +++ b/src/utility/HCISharedMemTransport.h @@ -0,0 +1,93 @@ +/* + This file is part of the STM32duinoBLE library. + Copyright (c) 2019 STMicroelectronics. All rights reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef _HCI_SHARED_MEM_TRANSPORT_H_ +#define _HCI_SHARED_MEM_TRANSPORT_H_ + +#include "HCITransport.h" + +/* STM32WB include files */ +#include "stm32wbxx_ll_rcc.h" +#include "stm32wbxx_ll_ipcc.h" +#include "stm32wbxx_ll_system.h" +#include "STM32_WPAN/tl.h" +#include "STM32_WPAN/shci.h" +#include "STM32_WPAN/shci_tl.h" +#include "STM32_WPAN/app_conf.h" + +/* this one is for printing info content when HW serial enabled */ +//#define PRINT_IPCC_INFO + +/* this CONFIG_DEBUG must be defined for -Og option */ +//#define CONFIG_DEBUG + +/****************************************************************************** + * BLE config parameters + ******************************************************************************/ +/* Defined from WB Cube reference SW */ +#define CFG_TLBLE_EVT_QUEUE_LENGTH 5 +#define CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE 255 /**< Set to 255 with the memory manager and the mailbox */ +#define TL_BLE_EVENT_FRAME_SIZE ( TL_EVT_HDR_SIZE + CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE ) +#define POOL_SIZE (CFG_TLBLE_EVT_QUEUE_LENGTH*4*DIVC(( sizeof(TL_PacketHeader_t) + TL_BLE_EVENT_FRAME_SIZE ), 4)) + +#define CONFIG_DATA_PUBADDR_OFFSET (0x00) /**< Bluetooth public address */ +#define CONFIG_DATA_PUBADDR_LEN (6) + +#define BT_BUF_CMD 1 +#define BT_BUF_ACL_OUT 2 + +/* timeout (in ms) to wait for an incoming event */ +#define BLE_IPCC_TIMEOUT 10000 + +/* to received BLE packet from the SharedMem */ +void evt_received(TL_EvtPacket_t *hcievt); + +/* to send BLE packet to the SharedMem */ +uint16_t mbox_write(uint8_t type, uint16_t len, const uint8_t *pData); + +class HCISharedMemTransportClass : public HCITransportInterface { + public: + HCISharedMemTransportClass(); + virtual ~HCISharedMemTransportClass(); + + virtual int begin(); + virtual void end(); + + virtual void wait(unsigned long timeout); + + virtual int available(); + virtual int peek(); + virtual int read(); + + virtual size_t write(const uint8_t *data, size_t length); + + private: + + /* method to initialize the BLE device */ + void transport_init(void); + void start_ble_rf(void); + void stm32wb_reset(void); + int stm32wb_start_ble(void); + int bt_ipm_set_addr(void); + int bt_ipm_set_power(void); + + uint8_t _random_addr[6]; +}; + +#endif /* _HCI_SHARED_MEM_TRANSPORT_H_ */ From 93a265211bdd168f399ffb1d9691bac84473c427 Mon Sep 17 00:00:00 2001 From: Francois Ramu <francois.ramu@st.com> Date: Tue, 18 Mar 2025 09:40:37 +0100 Subject: [PATCH 186/226] feat: add the STM32Cube_FW to support stm32wb Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- src/utility/STM32_WPAN/LICENSE.md | 108 ++ src/utility/STM32_WPAN/README.md | 6 + src/utility/STM32_WPAN/app_conf.h | 20 + src/utility/STM32_WPAN/app_conf_default.h | 728 ++++++++++ src/utility/STM32_WPAN/ble_bufsize.h | 182 +++ src/utility/STM32_WPAN/hw.h | 114 ++ src/utility/STM32_WPAN/hw_ipcc.c | 749 +++++++++++ src/utility/STM32_WPAN/mbox_def.h | 280 ++++ src/utility/STM32_WPAN/shci.c | 763 +++++++++++ src/utility/STM32_WPAN/shci.h | 1402 ++++++++++++++++++++ src/utility/STM32_WPAN/shci_tl.c | 271 ++++ src/utility/STM32_WPAN/shci_tl.h | 173 +++ src/utility/STM32_WPAN/stm32_wpan_common.h | 171 +++ src/utility/STM32_WPAN/stm_list.c | 210 +++ src/utility/STM32_WPAN/stm_list.h | 55 + src/utility/STM32_WPAN/tl.h | 372 ++++++ src/utility/STM32_WPAN/tl_dbg_conf.h | 140 ++ src/utility/STM32_WPAN/tl_mbox.c | 855 ++++++++++++ src/utility/STM32_WPAN/utilities_conf.h | 66 + 19 files changed, 6665 insertions(+) create mode 100644 src/utility/STM32_WPAN/LICENSE.md create mode 100644 src/utility/STM32_WPAN/README.md create mode 100644 src/utility/STM32_WPAN/app_conf.h create mode 100644 src/utility/STM32_WPAN/app_conf_default.h create mode 100644 src/utility/STM32_WPAN/ble_bufsize.h create mode 100644 src/utility/STM32_WPAN/hw.h create mode 100644 src/utility/STM32_WPAN/hw_ipcc.c create mode 100644 src/utility/STM32_WPAN/mbox_def.h create mode 100644 src/utility/STM32_WPAN/shci.c create mode 100644 src/utility/STM32_WPAN/shci.h create mode 100644 src/utility/STM32_WPAN/shci_tl.c create mode 100644 src/utility/STM32_WPAN/shci_tl.h create mode 100644 src/utility/STM32_WPAN/stm32_wpan_common.h create mode 100644 src/utility/STM32_WPAN/stm_list.c create mode 100644 src/utility/STM32_WPAN/stm_list.h create mode 100644 src/utility/STM32_WPAN/tl.h create mode 100644 src/utility/STM32_WPAN/tl_dbg_conf.h create mode 100644 src/utility/STM32_WPAN/tl_mbox.c create mode 100644 src/utility/STM32_WPAN/utilities_conf.h diff --git a/src/utility/STM32_WPAN/LICENSE.md b/src/utility/STM32_WPAN/LICENSE.md new file mode 100644 index 00000000..4e70ee7c --- /dev/null +++ b/src/utility/STM32_WPAN/LICENSE.md @@ -0,0 +1,108 @@ +## Overview + + +This Software Bill Of Material (SBOM) lists the software components of this +software package, including the copyright owner and license terms for each +component. + +__SOFTWARE BILL OF MATERIALS__ + +Component | Copyright | License +--------- | ----------------------------------------------------------------- | ------- +Bluetooth Low Energy | STMicroelectronics | SLA +Bluetooth Low Energy LLD | STMicroelectronics | SLA +Interface | STMicroelectronics | SLA +MAC 802.15.4 | STMicroelectronics | SLA +PHY | STMicroelectronics | SLA +OpenThread | The OpenThread Authors | BSD-3-Clause +Utilities | STMicroelectronics, Amazon.com Inc. | SLA, MIT +Zigbee | Exegin Technologies Limited, STMicroelectronics, Dr Brian Gladman | SLA + + +__Notes:__ If the license is an open source license, then you can access the +terms at [www.opensource.org](https://opensource.org/). Otherwise, the full +license terms are below. If a component is not listed in the SBOM, then the SLA +shall apply unless other terms are clearly stated in the package. + + + +SLA0044 Rev5/February 2018 + +## Software license agreement + +### __ULTIMATE LIBERTY SOFTWARE LICENSE AGREEMENT__ + +BY INSTALLING, COPYING, DOWNLOADING, ACCESSING OR OTHERWISE USING THIS SOFTWARE +OR ANY PART THEREOF (AND THE RELATED DOCUMENTATION) FROM STMICROELECTRONICS +INTERNATIONAL N.V, SWISS BRANCH AND/OR ITS AFFILIATED COMPANIES +(STMICROELECTRONICS), THE RECIPIENT, ON BEHALF OF HIMSELF OR HERSELF, OR ON +BEHALF OF ANY ENTITY BY WHICH SUCH RECIPIENT IS EMPLOYED AND/OR ENGAGED AGREES +TO BE BOUND BY THIS SOFTWARE LICENSE AGREEMENT. + +Under STMicroelectronics’ intellectual property rights, the redistribution, +reproduction and use in source and binary forms of the software or any part +thereof, with or without modification, are permitted provided that the following +conditions are met: + +1. Redistribution of source code (modified or not) must retain any copyright +notice, this list of conditions and the disclaimer set forth below as items 10 +and 11. + +2. Redistributions in binary form, except as embedded into microcontroller or +microprocessor device manufactured by or for STMicroelectronics or a software +update for such device, must reproduce any copyright notice provided with the +binary code, this list of conditions, and the disclaimer set forth below as +items 10 and 11, in documentation and/or other materials provided with the +distribution. + +3. Neither the name of STMicroelectronics nor the names of other contributors to +this software may be used to endorse or promote products derived from this +software or part thereof without specific written permission. + +4. This software or any part thereof, including modifications and/or derivative +works of this software, must be used and execute solely and exclusively on or in +combination with a microcontroller or microprocessor device manufactured by or +for STMicroelectronics. + +5. No use, reproduction or redistribution of this software partially or totally +may be done in any manner that would subject this software to any Open Source +Terms. “Open Source Terms” shall mean any open source license which requires as +part of distribution of software that the source code of such software is +distributed therewith or otherwise made available, or open source license that +substantially complies with the Open Source definition specified at +www.opensource.org and any other comparable open source license such as for +example GNU General Public License (GPL), Eclipse Public License (EPL), Apache +Software License, BSD license or MIT license. + +6. STMicroelectronics has no obligation to provide any maintenance, support or +updates for the software. + +7. The software is and will remain the exclusive property of STMicroelectronics +and its licensors. The recipient will not take any action that jeopardizes +STMicroelectronics and its licensors' proprietary rights or acquire any rights +in the software, except the limited rights specified hereunder. + +8. The recipient shall comply with all applicable laws and regulations affecting +the use of the software or any part thereof including any applicable export +control law or regulation. + +9. Redistribution and use of this software or any part thereof other than as +permitted under this license is void and will automatically terminate your +rights under this license. + +10. THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY RIGHTS, WHICH ARE +DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT SHALL +STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +11. EXCEPT AS EXPRESSLY PERMITTED HEREUNDER, NO LICENSE OR OTHER RIGHTS, WHETHER +EXPRESS OR IMPLIED, ARE GRANTED UNDER ANY PATENT OR OTHER INTELLECTUAL PROPERTY +RIGHTS OF STMICROELECTRONICS OR ANY THIRD PARTY. diff --git a/src/utility/STM32_WPAN/README.md b/src/utility/STM32_WPAN/README.md new file mode 100644 index 00000000..90f96452 --- /dev/null +++ b/src/utility/STM32_WPAN/README.md @@ -0,0 +1,6 @@ + +## Source + +[STMicroelectronics/STM32CubeWB Release v1.22.0](https://github.com/STMicroelectronics/STM32CubeWB/releases/tag/v1.22.0) +- Application: [BLE_TransparentMode](https://github.com/STMicroelectronics/STM32CubeWB/tree/v1.22.0/Projects/P-NUCLEO-WB55.Nucleo/Applications/BLE/BLE_TransparentMode) + diff --git a/src/utility/STM32_WPAN/app_conf.h b/src/utility/STM32_WPAN/app_conf.h new file mode 100644 index 00000000..3246393f --- /dev/null +++ b/src/utility/STM32_WPAN/app_conf.h @@ -0,0 +1,20 @@ +//----------------------------- +// @file app_conf.h +// @author Kasper Meldgaard +// @brief Wrapper for BLE app configuration based on comment by fpistm +// (https://github.com/stm32duino/STM32duinoBLE/issues/34). +// @date 15-11-2021 +// @copyright Copyright (c) 2021 + +#ifndef APP_CONF_H +#define APP_CONF_H + +#include "hw.h" +#include "ble_bufsize.h" + +#if __has_include("app_conf_custom.h") + #include "app_conf_custom.h" +#endif +#include "app_conf_default.h" + +#endif /* APP_CONF_H */ diff --git a/src/utility/STM32_WPAN/app_conf_default.h b/src/utility/STM32_WPAN/app_conf_default.h new file mode 100644 index 00000000..ff2dc017 --- /dev/null +++ b/src/utility/STM32_WPAN/app_conf_default.h @@ -0,0 +1,728 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file app_conf_default.h + * @author MCD Application Team + * @brief Default application configuration file for STM32WPAN Middleware. + ****************************************************************************** + * @attention + * + * Copyright (c) 2020-2021 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef APP_CONF_DEFAULT_H +#define APP_CONF_DEFAULT_H + +#if 0 +#include "hw.h" +#include "hw_conf.h" +#include "hw_if.h" +#include "ble_bufsize.h" +#endif + +/****************************************************************************** + * Application Config + ******************************************************************************/ + +/**< generic parameters ******************************************************/ +/* HCI related defines */ + +#define ACI_HAL_SET_TX_POWER_LEVEL 0xFC0F +#define ACI_WRITE_CONFIG_DATA_OPCODE 0xFC0C +#define ACI_READ_CONFIG_DATA_OPCODE 0xFC0D +#define MAX_HCI_ACL_PACKET_SIZE (sizeof(TL_PacketHeader_t) + 5 + 251) +#define HCI_RESET 0x0C03 + +#ifndef BLE_SHARED_MEM_BYTE_ORDER + #define BLE_SHARED_MEM_BYTE_ORDER MSBFIRST +#endif +#define BLE_MODULE_SHARED_MEM_BUFFER_SIZE 128 + +/** + * Define Tx Power + */ +#ifndef CFG_TX_POWER + #define CFG_TX_POWER (0x18) /* -0.15dBm */ +#endif + +#if 0 +/** + * Define Secure Connections Support + */ +#define CFG_SECURE_NOT_SUPPORTED (0x00) +#define CFG_SECURE_OPTIONAL (0x01) +#define CFG_SECURE_MANDATORY (0x02) + +#define CFG_SC_SUPPORT CFG_SECURE_OPTIONAL + +/** + * Define Keypress Notification Support + */ +#define CFG_KEYPRESS_NOT_SUPPORTED (0x00) +#define CFG_KEYPRESS_SUPPORTED (0x01) + +#define CFG_KEYPRESS_NOTIFICATION_SUPPORT CFG_KEYPRESS_NOT_SUPPORTED + +/** + * Numeric Comparison Answers + */ +#define YES (0x01) +#define NO (0x00) + +/** + * Device name configuration for Generic Access Service + */ +#define CFG_GAP_DEVICE_NAME "TEMPLATE" +#define CFG_GAP_DEVICE_NAME_LENGTH (8) + +/** +* Identity root key used to derive IRK and DHK(Legacy) +*/ +#define CFG_BLE_IR {0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0} + +/** +* Encryption root key used to derive LTK(Legacy) and CSRK +*/ +#define CFG_BLE_ER {0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21, 0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21} + +/** + * SMPS supply + * SMPS not used when Set to 0 + * SMPS used when Set to 1 + */ +#define CFG_USE_SMPS 0 + +/* USER CODE BEGIN Generic_Parameters */ +/* USER CODE END Generic_Parameters */ + +/**< specific parameters */ +/*****************************************************/ + +/* USER CODE BEGIN Specific_Parameters */ +#define PUSH_BUTTON_SW1_EXTI_IRQHandler EXTI4_IRQHandler + +/* USER CODE END Specific_Parameters */ + +/****************************************************************************** + * Information Table + * + * Version + * [0:3] = Build - 0: Untracked - 15:Released - x: Tracked version + * [4:7] = branch - 0: Mass Market - x: ... + * [8:15] = Subversion + * [16:23] = Version minor + * [24:31] = Version major + * + ******************************************************************************/ +#define CFG_FW_MAJOR_VERSION (0) +#define CFG_FW_MINOR_VERSION (0) +#define CFG_FW_SUBVERSION (1) +#define CFG_FW_BRANCH (0) +#define CFG_FW_BUILD (0) +#endif + +/****************************************************************************** + * BLE Stack + ******************************************************************************/ +/** + * Maximum number of simultaneous connections that the device will support. + * Valid values are from 1 to 8 + */ +#ifndef CFG_BLE_NUM_LINK +#ifdef STM32WB15xx + #define CFG_BLE_NUM_LINK 3 +#else + #define CFG_BLE_NUM_LINK 8 +#endif +#endif + +/** + * Maximum number of Services that can be stored in the GATT database. + * Note that the GAP and GATT services are automatically added so this parameter should be 2 plus the number of user services + */ +#ifndef CFG_BLE_NUM_GATT_SERVICES +#ifdef STM32WB15xx + #define CFG_BLE_NUM_GATT_SERVICES 4 +#else + #define CFG_BLE_NUM_GATT_SERVICES 8 +#endif +#endif + +/** + * Maximum number of Attributes + * (i.e. the number of characteristic + the number of characteristic values + the number of descriptors, excluding the services) + * that can be stored in the GATT database. + * Note that certain characteristics and relative descriptors are added automatically during device initialization + * so this parameters should be 9 plus the number of user Attributes + */ +#ifndef CFG_BLE_NUM_GATT_ATTRIBUTES +#ifdef STM32WB15xx + #define CFG_BLE_NUM_GATT_ATTRIBUTES 30 +#else + #define CFG_BLE_NUM_GATT_ATTRIBUTES 68 +#endif +#endif + +/** + * Maximum supported ATT_MTU size + * This parameter is ignored by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set + */ +#define CFG_BLE_MAX_ATT_MTU (156) + +/** + * Size of the storage area for Attribute values + * This value depends on the number of attributes used by application. In particular the sum of the following quantities (in octets) should be made for each attribute: + * - attribute value length + * - 5, if UUID is 16 bit; 19, if UUID is 128 bit + * - 2, if server configuration descriptor is used + * - 2*DTM_NUM_LINK, if client configuration descriptor is used + * - 2, if extended properties is used + * The total amount of memory needed is the sum of the above quantities for each attribute. + * This parameter is ignored by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set + */ +#define CFG_BLE_ATT_VALUE_ARRAY_SIZE (1344) + +/** + * Prepare Write List size in terms of number of packet + * This parameter is ignored by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set + */ +#define CFG_BLE_PREPARE_WRITE_LIST_SIZE BLE_PREP_WRITE_X_ATT(CFG_BLE_MAX_ATT_MTU) + +/** + * Number of allocated memory blocks + * This parameter is overwritten by the CPU2 with an hardcoded optimal value when the parameter CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set + */ +#define CFG_BLE_MBLOCK_COUNT (BLE_MBLOCKS_CALC(CFG_BLE_PREPARE_WRITE_LIST_SIZE, CFG_BLE_MAX_ATT_MTU, CFG_BLE_NUM_LINK)) + +/** + * Enable or disable the Extended Packet length feature. Valid values are 0 or 1. + */ +#ifndef CFG_BLE_DATA_LENGTH_EXTENSION + #define CFG_BLE_DATA_LENGTH_EXTENSION 1 +#endif + +/** + * Sleep clock accuracy in Peripheral mode (ppm value) + */ +#ifndef CFG_BLE_PERIPHERAL_SCA + #define CFG_BLE_PERIPHERAL_SCA 500 +#endif + +/** + * Sleep clock accuracy in Central mode + * 0 : 251 ppm to 500 ppm + * 1 : 151 ppm to 250 ppm + * 2 : 101 ppm to 150 ppm + * 3 : 76 ppm to 100 ppm + * 4 : 51 ppm to 75 ppm + * 5 : 31 ppm to 50 ppm + * 6 : 21 ppm to 30 ppm + * 7 : 0 ppm to 20 ppm + */ +#ifndef CFG_BLE_CENTRAL_SCA + #define CFG_BLE_CENTRAL_SCA 0 +#endif + +/** + * LsSource + * Some information for Low speed clock mapped in bits field + * - bit 0: 1: Calibration for the RF system wakeup clock source 0: No calibration for the RF system wakeup clock source + * - bit 1: 1: STM32WB5M Module device 0: Other devices as STM32WBxx SOC, STM32WB1M module + * - bit 2: 1: HSE/1024 Clock config 0: LSE Clock config + */ +#ifndef CFG_BLE_LS_SOURCE + #if defined(STM32WB5Mxx) + #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_MOD5MM_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) + #else + #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_OTHER_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) + #endif +#endif + +/** + * Start up time of the high speed (16 or 32 MHz) crystal oscillator in units of 625/256 us (~2.44 us) + */ +#ifndef CFG_BLE_HSE_STARTUP_TIME + #define CFG_BLE_HSE_STARTUP_TIME 0x148 +#endif + +/** + * Maximum duration of the connection event when the device is in Peripheral mode in units of 625/256 us (~2.44 us) + */ +#ifndef CFG_BLE_MAX_CONN_EVENT_LENGTH + #define CFG_BLE_MAX_CONN_EVENT_LENGTH (0xFFFFFFFF) +#endif + +/** + * Viterbi Mode + * 1 : enabled + * 0 : disabled + */ +#define CFG_BLE_VITERBI_MODE 1 + +/** + * BLE stack Options flags to be configured with: + * - SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY + * - SHCI_C2_BLE_INIT_OPTIONS_LL_HOST + * - SHCI_C2_BLE_INIT_OPTIONS_NO_SVC_CHANGE_DESC + * - SHCI_C2_BLE_INIT_OPTIONS_WITH_SVC_CHANGE_DESC + * - SHCI_C2_BLE_INIT_OPTIONS_DEVICE_NAME_RO + * - SHCI_C2_BLE_INIT_OPTIONS_DEVICE_NAME_RW + * - SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV + * - SHCI_C2_BLE_INIT_OPTIONS_NO_EXT_ADV + * - SHCI_C2_BLE_INIT_OPTIONS_CS_ALGO2 + * - SHCI_C2_BLE_INIT_OPTIONS_NO_CS_ALGO2 + * - SHCI_C2_BLE_INIT_OPTIONS_REDUC_GATTDB_NVM + * - SHCI_C2_BLE_INIT_OPTIONS_FULL_GATTDB_NVM + * - SHCI_C2_BLE_INIT_OPTIONS_GATT_CACHING_USED + * - SHCI_C2_BLE_INIT_OPTIONS_GATT_CACHING_NOTUSED + * - SHCI_C2_BLE_INIT_OPTIONS_POWER_CLASS_1 + * - SHCI_C2_BLE_INIT_OPTIONS_POWER_CLASS_2_3 + * which are used to set following configuration bits: + * (bit 0): 1: LL only + * 0: LL + host + * (bit 1): 1: no service change desc. + * 0: with service change desc. + * (bit 2): 1: device name Read-Only + * 0: device name R/W + * (bit 3): 1: extended advertizing supported + * 0: extended advertizing not supported + * (bit 4): 1: CS Algo #2 supported + * 0: CS Algo #2 not supported + * (bit 5): 1: Reduced GATT database in NVM + * 0: Full GATT database in NVM + * (bit 6): 1: GATT caching is used + * 0: GATT caching is not used + * (bit 7): 1: LE Power Class 1 + * 0: LE Power Class 2-3 + * other bits: complete with Options_extension flag + */ +#define CFG_BLE_OPTIONS (SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY | SHCI_C2_BLE_INIT_OPTIONS_WITH_SVC_CHANGE_DESC | SHCI_C2_BLE_INIT_OPTIONS_DEVICE_NAME_RW | SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV | SHCI_C2_BLE_INIT_OPTIONS_CS_ALGO2 | SHCI_C2_BLE_INIT_OPTIONS_FULL_GATTDB_NVM | SHCI_C2_BLE_INIT_OPTIONS_GATT_CACHING_NOTUSED | SHCI_C2_BLE_INIT_OPTIONS_POWER_CLASS_2_3) + +/** + * BLE stack Options_extension flags to be configured with: + * - SHCI_C2_BLE_INIT_OPTIONS_APPEARANCE_WRITABLE + * - SHCI_C2_BLE_INIT_OPTIONS_APPEARANCE_READONLY + * - SHCI_C2_BLE_INIT_OPTIONS_ENHANCED_ATT_SUPPORTED + * - SHCI_C2_BLE_INIT_OPTIONS_ENHANCED_ATT_NOTSUPPORTED + * which are used to set following configuration bits: + * (bit 0): 1: appearance Writable + * 0: appearance Read-Only + * (bit 1): 1: Enhanced ATT supported + * 0: Enhanced ATT not supported + * other bits: reserved (shall be set to 0) + */ +#define CFG_BLE_OPTIONS_EXT (SHCI_C2_BLE_INIT_OPTIONS_APPEARANCE_READONLY | SHCI_C2_BLE_INIT_OPTIONS_ENHANCED_ATT_NOTSUPPORTED) + +#define CFG_BLE_MAX_COC_INITIATOR_NBR (32) + +#define CFG_BLE_MIN_TX_POWER (-40) + +#define CFG_BLE_MAX_TX_POWER (6) + +/** + * BLE Rx model configuration flags to be configured with: + * - SHCI_C2_BLE_INIT_RX_MODEL_AGC_RSSI_LEGACY + * - SHCI_C2_BLE_INIT_RX_MODEL_AGC_RSSI_BLOCKER + * which are used to set following configuration bits: + * (bit 0): 1: agc_rssi model improved vs RF blockers + * 0: Legacy agc_rssi model + * other bits: reserved (shall be set to 0) + */ + +#define CFG_BLE_RX_MODEL_CONFIG (SHCI_C2_BLE_INIT_RX_MODEL_AGC_RSSI_LEGACY) + +/* Maximum number of advertising sets. + * Range: 1 .. 8 with limitation: + * This parameter is linked to CFG_BLE_MAX_ADV_DATA_LEN such as both compliant with allocated Total memory computed with BLE_EXT_ADV_BUFFER_SIZE based + * on Max Extended advertising configuration supported. + * This parameter is considered by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV flag set + */ + +#if defined(STM32WB15xx) + #define CFG_BLE_MAX_ADV_SET_NBR (3) +#else + #define CFG_BLE_MAX_ADV_SET_NBR (8) +#endif + + /* Maximum advertising data length (in bytes) + * Range: 31 .. 1650 with limitation: + * This parameter is linked to CFG_BLE_MAX_ADV_SET_NBR such as both compliant with allocated Total memory computed with BLE_EXT_ADV_BUFFER_SIZE based + * on Max Extended advertising configuration supported. + * This parameter is considered by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV flag set + */ + +#if defined(STM32WB15xx) + #define CFG_BLE_MAX_ADV_DATA_LEN (414) +#else + #define CFG_BLE_MAX_ADV_DATA_LEN (207) +#endif + + /* RF TX Path Compensation Value (16-bit signed integer). Units: 0.1 dB. + * Range: -1280 .. 1280 + */ + +#define CFG_BLE_TX_PATH_COMPENS (0) + + /* RF RX Path Compensation Value (16-bit signed integer). Units: 0.1 dB. + * Range: -1280 .. 1280 + */ + +#define CFG_BLE_RX_PATH_COMPENS (0) + + /* BLE core version (16-bit signed integer). + * - SHCI_C2_BLE_INIT_BLE_CORE_5_2 + * - SHCI_C2_BLE_INIT_BLE_CORE_5_3 + * - SHCI_C2_BLE_INIT_BLE_CORE_5_4 + * which are used to set: 11(5.2), 12(5.3), 13(5.4). + */ + +#define CFG_BLE_CORE_VERSION (SHCI_C2_BLE_INIT_BLE_CORE_5_4) + +#if 0 +/****************************************************************************** + * Transport Layer + ******************************************************************************/ +/** + * Queue length of BLE Event + * This parameter defines the number of asynchronous events that can be stored in the HCI layer before + * being reported to the application. When a command is sent to the BLE core coprocessor, the HCI layer + * is waiting for the event with the Num_HCI_Command_Packets set to 1. The receive queue shall be large + * enough to store all asynchronous events received in between. + * When CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE is set to 27, this allow to store three 255 bytes long asynchronous events + * between the HCI command and its event. + * This parameter depends on the value given to CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE. When the queue size is to small, + * the system may hang if the queue is full with asynchronous events and the HCI layer is still waiting + * for a CC/CS event, In that case, the notification TL_BLE_HCI_ToNot() is called to indicate + * to the application a HCI command did not receive its command event within 30s (Default HCI Timeout). + */ +#define CFG_TLBLE_EVT_QUEUE_LENGTH 5 +/** + * This parameter should be set to fit most events received by the HCI layer. It defines the buffer size of each element + * allocated in the queue of received events and can be used to optimize the amount of RAM allocated by the Memory Manager. + * It should not exceed 255 which is the maximum HCI packet payload size (a greater value is a lost of memory as it will + * never be used) + * It shall be at least 4 to receive the command status event in one frame. + * The default value is set to 27 to allow receiving an event of MTU size in a single buffer. This value maybe reduced + * further depending on the application. + */ +#define CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE 255 /**< Set to 255 with the memory manager and the mailbox */ + +#define TL_BLE_EVENT_FRAME_SIZE ( TL_EVT_HDR_SIZE + CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE ) +/****************************************************************************** + * UART interfaces + ******************************************************************************/ + +/** + * Select UART interfaces + */ +#define CFG_UART_GUI hw_uart1 +#define CFG_DEBUG_TRACE_UART 0 +/****************************************************************************** + * USB interface + ******************************************************************************/ + +/** + * Enable/Disable USB interface + */ +#define CFG_USB_INTERFACE_ENABLE 0 + +/****************************************************************************** + * IPCC interface + ******************************************************************************/ + +/** + * The IPCC is dedicated to the communication between the CPU2 and the CPU1 + * and shall not be modified by the application + * The two following definitions shall not be modified + */ +#define HAL_IPCC_TX_IRQHandler(...) HW_IPCC_Tx_Handler( ) +#define HAL_IPCC_RX_IRQHandler(...) HW_IPCC_Rx_Handler( ) + +/****************************************************************************** + * Low Power + ******************************************************************************/ +/** + * When set to 1, the low power mode is enable + * When set to 0, the device stays in RUN mode + */ +#define CFG_LPM_SUPPORTED 1 + +/****************************************************************************** + * RTC interface + ******************************************************************************/ +#define HAL_RTCEx_WakeUpTimerIRQHandler(...) HW_TS_RTC_Wakeup_Handler( ) + +/****************************************************************************** + * Timer Server + ******************************************************************************/ +/** + * CFG_RTC_WUCKSEL_DIVIDER: This sets the RTCCLK divider to the wakeup timer. + * The lower is the value, the better is the power consumption and the accuracy of the timerserver + * The higher is the value, the finest is the granularity + * + * CFG_RTC_ASYNCH_PRESCALER: This sets the asynchronous prescaler of the RTC. It should as high as possible ( to output + * clock as low as possible) but the output clock should be equal or higher frequency compare to the clock feeding + * the wakeup timer. A lower clock speed would impact the accuracy of the timer server. + * + * CFG_RTC_SYNCH_PRESCALER: This sets the synchronous prescaler of the RTC. + * When the 1Hz calendar clock is required, it shall be sets according to other settings + * When the 1Hz calendar clock is not needed, CFG_RTC_SYNCH_PRESCALER should be set to 0x7FFF (MAX VALUE) + * + * CFG_RTCCLK_DIVIDER_CONF: + * Shall be set to either 0,2,4,8,16 + * When set to either 2,4,8,16, the 1Hhz calendar is supported + * When set to 0, the user sets its own configuration + * + * The following settings are computed with LSI as input to the RTC + */ + +#define CFG_RTCCLK_DIVIDER_CONF 0 + +#if (CFG_RTCCLK_DIVIDER_CONF == 0) +/** + * Custom configuration + * It does not support 1Hz calendar + * It divides the RTC CLK by 16 + */ + +#define CFG_RTCCLK_DIV (16) +#define CFG_RTC_WUCKSEL_DIVIDER (0) +#define CFG_RTC_ASYNCH_PRESCALER (0x0F) +#define CFG_RTC_SYNCH_PRESCALER (0x7FFF) + +#else + +#if (CFG_RTCCLK_DIVIDER_CONF == 2) +/** + * It divides the RTC CLK by 2 + */ +#define CFG_RTC_WUCKSEL_DIVIDER (3) +#endif + +#if (CFG_RTCCLK_DIVIDER_CONF == 4) +/** + * It divides the RTC CLK by 4 + */ +#define CFG_RTC_WUCKSEL_DIVIDER (2) +#endif + +#if (CFG_RTCCLK_DIVIDER_CONF == 8) +/** + * It divides the RTC CLK by 8 + */ +#define CFG_RTC_WUCKSEL_DIVIDER (1) +#endif + +#if (CFG_RTCCLK_DIVIDER_CONF == 16) +/** + * It divides the RTC CLK by 16 + */ +#define CFG_RTC_WUCKSEL_DIVIDER (0) +#endif + +#define CFG_RTCCLK_DIV CFG_RTCCLK_DIVIDER_CONF +#define CFG_RTC_ASYNCH_PRESCALER (CFG_RTCCLK_DIV - 1) +#define CFG_RTC_SYNCH_PRESCALER (DIVR( LSE_VALUE, (CFG_RTC_ASYNCH_PRESCALER+1) ) - 1 ) + +#endif + +/** tick timer values */ +#define CFG_TS_TICK_VAL DIVR( (CFG_RTCCLK_DIV * 1000000), LSE_VALUE ) +#define CFG_TS_TICK_VAL_PS DIVR( ((uint64_t)CFG_RTCCLK_DIV * 1e12), (uint64_t)LSE_VALUE ) + +typedef enum +{ + CFG_TIM_PROC_ID_ISR, + /* USER CODE BEGIN CFG_TimProcID_t */ + + /* USER CODE END CFG_TimProcID_t */ +} CFG_TimProcID_t; + +/****************************************************************************** + * Debug + ******************************************************************************/ +/** + * When set, this resets some hw resources to put the device in the same state as at power up. + * It resets only register that may prevent the FW to run properly. + * + * This shall be set to 0 in a final product + * + */ +#define CFG_HW_RESET_BY_FW 0 + +/** + * keep debugger enabled while in any low power mode when set to 1 + * should be set to 0 in production + */ +#define CFG_DEBUGGER_SUPPORTED 0 + +/** + * When set to 1, the traces are enabled in the BLE services + */ +#define CFG_DEBUG_BLE_TRACE 0 + +/** + * Enable or Disable traces in application + */ +#define CFG_DEBUG_APP_TRACE 0 + +#if (CFG_DEBUG_APP_TRACE != 0) +#define APP_DBG_MSG PRINT_MESG_DBG +#else +#define APP_DBG_MSG PRINT_NO_MESG +#endif + +#if ( (CFG_DEBUG_BLE_TRACE != 0) || (CFG_DEBUG_APP_TRACE != 0) ) +#define CFG_DEBUG_TRACE 1 +#endif + +#if (CFG_DEBUG_TRACE != 0) +#undef CFG_LPM_SUPPORTED +#undef CFG_DEBUGGER_SUPPORTED +#define CFG_LPM_SUPPORTED 0 +#define CFG_DEBUGGER_SUPPORTED 1 +#endif + +/** + * When CFG_DEBUG_TRACE_FULL is set to 1, the trace are output with the API name, the file name and the line number + * When CFG_DEBUG_TRACE_LIGHT is set to 1, only the debug message is output + * + * When both are set to 0, no trace are output + * When both are set to 1, CFG_DEBUG_TRACE_FULL is selected + */ +#define CFG_DEBUG_TRACE_LIGHT 0 +#define CFG_DEBUG_TRACE_FULL 0 + +#if (( CFG_DEBUG_TRACE != 0 ) && ( CFG_DEBUG_TRACE_LIGHT == 0 ) && (CFG_DEBUG_TRACE_FULL == 0)) +#undef CFG_DEBUG_TRACE_FULL +#undef CFG_DEBUG_TRACE_LIGHT +#define CFG_DEBUG_TRACE_FULL 0 +#define CFG_DEBUG_TRACE_LIGHT 1 +#endif + +#if ( CFG_DEBUG_TRACE == 0 ) +#undef CFG_DEBUG_TRACE_FULL +#undef CFG_DEBUG_TRACE_LIGHT +#define CFG_DEBUG_TRACE_FULL 0 +#define CFG_DEBUG_TRACE_LIGHT 0 +#endif + +/** + * When not set, the traces is looping on sending the trace over UART + */ +#define DBG_TRACE_USE_CIRCULAR_QUEUE 1 + +/** + * max buffer Size to queue data traces and max data trace allowed. + * Only Used if DBG_TRACE_USE_CIRCULAR_QUEUE is defined + */ +#define DBG_TRACE_MSG_QUEUE_SIZE 4096 +#define MAX_DBG_TRACE_MSG_SIZE 1024 + +/* USER CODE BEGIN Defines */ +#define CFG_LED_SUPPORTED 1 +#define CFG_BUTTON_SUPPORTED 1 + +#define PUSH_BUTTON_SW1_EXTI_IRQHandler EXTI4_IRQHandler +#define PUSH_BUTTON_SW2_EXTI_IRQHandler EXTI0_IRQHandler +#define PUSH_BUTTON_SW3_EXTI_IRQHandler EXTI1_IRQHandler +/* USER CODE END Defines */ + +/****************************************************************************** + * Scheduler + ******************************************************************************/ + +/** + * These are the lists of task id registered to the scheduler + * Each task id shall be in the range [0:31] + * This mechanism allows to implement a generic code in the API TL_BLE_HCI_StatusNot() to comply with + * the requirement that a HCI/ACI command shall never be sent if there is already one pending + */ + +/**< Add in that list all tasks that may send a ACI/HCI command */ +typedef enum +{ + CFG_TASK_BLE_HCI_CMD_ID, + CFG_TASK_SYS_HCI_CMD_ID, + CFG_TASK_HCI_ACL_DATA_ID, + CFG_TASK_SYS_LOCAL_CMD_ID, + CFG_TASK_TX_TO_HOST_ID, + /* USER CODE BEGIN CFG_Task_Id_With_HCI_Cmd_t */ + CFG_TASK_SW1_BUTTON_PUSHED_ID, + CFG_TASK_SW2_BUTTON_PUSHED_ID, + CFG_TASK_SW3_BUTTON_PUSHED_ID, + /* USER CODE END CFG_Task_Id_With_HCI_Cmd_t */ + CFG_LAST_TASK_ID_WITH_HCICMD, /**< Shall be LAST in the list */ +} CFG_Task_Id_With_HCI_Cmd_t; + +/**< Add in that list all tasks that never send a ACI/HCI command */ +typedef enum +{ + CFG_FIRST_TASK_ID_WITH_NO_HCICMD = CFG_LAST_TASK_ID_WITH_HCICMD - 1, /**< Shall be FIRST in the list */ + CFG_TASK_SYSTEM_HCI_ASYNCH_EVT_ID, + /* USER CODE BEGIN CFG_Task_Id_With_NO_HCI_Cmd_t */ + + /* USER CODE END CFG_Task_Id_With_NO_HCI_Cmd_t */ + CFG_LAST_TASK_ID_WITH_NO_HCICMD /**< Shall be LAST in the list */ +} CFG_Task_Id_With_NO_HCI_Cmd_t; + +#define CFG_TASK_NBR CFG_LAST_TASK_ID_WITH_NO_HCICMD + +/** + * This is the list of priority required by the application + * Each Id shall be in the range 0..31 + */ +typedef enum +{ + CFG_SCH_PRIO_0, + /* USER CODE BEGIN CFG_SCH_Prio_Id_t */ + + /* USER CODE END CFG_SCH_Prio_Id_t */ + CFG_SCH_PRIO_NBR +} CFG_SCH_Prio_Id_t; + +/** + * This is a bit mapping over 32bits listing all events id supported in the application + */ +typedef enum +{ + CFG_IDLEEVT_SYSTEM_HCI_CMD_EVT_RSP_ID, + /* USER CODE BEGIN CFG_IdleEvt_Id_t */ + + /* USER CODE END CFG_IdleEvt_Id_t */ +} CFG_IdleEvt_Id_t; + +/****************************************************************************** + * LOW POWER + ******************************************************************************/ +/** + * Supported requester to the MCU Low Power Manager - can be increased up to 32 + * It list a bit mapping of all user of the Low Power Manager + */ +typedef enum +{ + CFG_LPM_APP, + CFG_LPM_APP_BLE, + /* USER CODE BEGIN CFG_LPM_Id_t */ + + /* USER CODE END CFG_LPM_Id_t */ +} CFG_LPM_Id_t; + +/****************************************************************************** + * OTP manager + ******************************************************************************/ +#define CFG_OTP_BASE_ADDRESS OTP_AREA_BASE + +#define CFG_OTP_END_ADRESS OTP_AREA_END_ADDR + +#endif +#endif /*APP_CONF_DEFAULT_H */ diff --git a/src/utility/STM32_WPAN/ble_bufsize.h b/src/utility/STM32_WPAN/ble_bufsize.h new file mode 100644 index 00000000..26551c09 --- /dev/null +++ b/src/utility/STM32_WPAN/ble_bufsize.h @@ -0,0 +1,182 @@ +/***************************************************************************** + * @file ble_bufsize.h + * + * @brief Definition of BLE stack buffers size + ***************************************************************************** + * @attention + * + * Copyright (c) 2018-2025 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ***************************************************************************** + */ + +#ifndef BLE_BUFSIZE_H__ +#define BLE_BUFSIZE_H__ + + +/* + * BLE_DEFAULT_ATT_MTU: minimum MTU value that GATT must support. + */ +#define BLE_DEFAULT_ATT_MTU 23 + +/* + * BLE_DEFAULT_MAX_ATT_SIZE: maximum attribute size. + */ +#define BLE_DEFAULT_MAX_ATT_SIZE 512 + +/* + * BLE_PREP_WRITE_X_ATT: compute how many Prepare Write Request are needed to + * write a characteristic with size 'max_att' when the used ATT_MTU value is + * equal to BLE_DEFAULT_ATT_MTU (23). + */ +#define BLE_PREP_WRITE_X_ATT(max_att) \ + (DIVC(max_att, BLE_DEFAULT_ATT_MTU - 5) * 2) + +/* + * BLE_DEFAULT_PREP_WRITE_LIST_SIZE: default minimum Prepare Write List size. + */ +#define BLE_DEFAULT_PREP_WRITE_LIST_SIZE \ + BLE_PREP_WRITE_X_ATT(BLE_DEFAULT_MAX_ATT_SIZE) + +/* + * BLE_MEM_BLOCK_X_MTU: compute how many memory blocks are needed to compose + * an ATT packet with ATT_MTU=mtu. + */ +#define BLE_MEM_BLOCK_SIZE 32 + +#if (SLAVE_ONLY != 0) || (BASIC_FEATURES != 0) +#define BLE_MEM_BLOCK_X_PTX(n_link) 0 +#else +#define BLE_MEM_BLOCK_X_PTX(n_link) (n_link) +#endif + +#define BLE_MEM_BLOCK_X_TX(mtu) \ + (DIVC((mtu) + 4U, BLE_MEM_BLOCK_SIZE) + 1) + +#define BLE_MEM_BLOCK_X_RX(mtu, n_link) \ + ((DIVC((mtu) + 4U, BLE_MEM_BLOCK_SIZE) + 2U) * (n_link) + 1) + +#define BLE_MEM_BLOCK_X_MTU(mtu, n_link) \ + (BLE_MEM_BLOCK_X_TX(mtu) + BLE_MEM_BLOCK_X_PTX(n_link) + \ + BLE_MEM_BLOCK_X_RX(mtu, n_link)) + +/* + * BLE_MBLOCKS_SECURE_CONNECTIONS: minimum number of blocks required for + * secure connections + */ +#define BLE_MBLOCKS_SECURE_CONNECTIONS 4 + +/* + * BLE_MBLOCKS_CALC: minimum number of buffers needed by the stack. + * This is the minimum racomanded value and depends on: + * - pw: size of Prepare Write List + * - mtu: ATT_MTU size + * - n_link: maximum number of simultaneous connections + */ +#define BLE_MBLOCKS_CALC(pw, mtu, n_link) \ + ((pw) + MAX(BLE_MEM_BLOCK_X_MTU(mtu, n_link), \ + BLE_MBLOCKS_SECURE_CONNECTIONS)) + +/* + * BLE_FIXED_BUFFER_SIZE_BYTES: + * A part of the RAM, is dynamically allocated by initializing all the pointers + * defined in a global context variable "mem_alloc_ctx_p". + * This initialization is made in the Dynamic_allocator functions, which + * assign a portion of RAM given by the external application to the above + * mentioned "global pointers". + * + * The size of this Dynamic RAM is made of 2 main components: + * - a part that is parameters-dependent (num of links, GATT buffers, ...), + * and which value is made explicit by the following macro; + * - a part, that may be considered "fixed", i.e. independent from the above + * mentioned parameters. +*/ +#if (BEACON_ONLY != 0) +#define BLE_FIXED_BUFFER_SIZE_BYTES 4200 /* Beacon only */ +#elif (LL_ONLY_BASIC != 0) +#define BLE_FIXED_BUFFER_SIZE_BYTES 6040 /* LL only Basic*/ +#elif (LL_ONLY != 0) +#define BLE_FIXED_BUFFER_SIZE_BYTES 6288 /* LL only Full */ +#elif (SLAVE_ONLY != 0) +#define BLE_FIXED_BUFFER_SIZE_BYTES 6408 /* Peripheral only */ +#elif (BASIC_FEATURES != 0) +#define BLE_FIXED_BUFFER_SIZE_BYTES 7184 /* Basic Features */ +#else +#define BLE_FIXED_BUFFER_SIZE_BYTES 7468 /* Full stack */ +#endif + +/* + * BLE_PER_LINK_SIZE_BYTES: additional memory size used per link + */ +#if (BEACON_ONLY != 0) +#define BLE_PER_LINK_SIZE_BYTES 76 /* Beacon only */ +#elif (LL_ONLY_BASIC != 0) +#define BLE_PER_LINK_SIZE_BYTES 244 /* LL only Basic */ +#elif (LL_ONLY != 0) +#define BLE_PER_LINK_SIZE_BYTES 244 /* LL only Full */ +#elif (SLAVE_ONLY != 0) +#define BLE_PER_LINK_SIZE_BYTES 392 /* Peripheral only */ +#elif (BASIC_FEATURES != 0) +#define BLE_PER_LINK_SIZE_BYTES 420 /* Basic Features */ +#else +#define BLE_PER_LINK_SIZE_BYTES 432 /* Full stack */ +#endif + +/* + * BLE_TOTAL_BUFFER_SIZE: this macro returns the amount of memory, in bytes, + * needed for the storage of data structures (except GATT database elements) + * whose size depends on the number of supported connections. + * + * @param n_link: Maximum number of simultaneous connections that the device + * will support. Valid values are from 1 to 8. + * + * @param mblocks_count: Number of memory blocks allocated for packets. + */ +#define BLE_TOTAL_BUFFER_SIZE(n_link, mblocks_count) \ + (16 + BLE_FIXED_BUFFER_SIZE_BYTES + \ + (BLE_PER_LINK_SIZE_BYTES * (n_link)) + \ + ((BLE_MEM_BLOCK_SIZE + 8) * (mblocks_count))) + +/* + * BLE_EXT_ADV_BUFFER_SIZE + * additional memory size used for Extended advertising; + * It has to be added to BLE_TOTAL_BUFFER_SIZE() if the Extended advertising + * feature is used. + * + * @param set_nbr: Maximum number of advertising sets. + * Valid values are from 1 to 8. + * + * @param data_len: Maximum size of advertising data. + * Valid values are from 31 to 1650. + */ +#define BLE_EXT_ADV_BUFFER_SIZE(set_nbr, data_len) \ + (2512 + ((892 + (DIVC(data_len, 207) * 244)) * (set_nbr))) + +/* + * BLE_TOTAL_BUFFER_SIZE_GATT: this macro returns the amount of memory, + * in bytes, needed for the storage of GATT database elements. + * + * @param num_gatt_attributes: Maximum number of Attributes (i.e. the number + * of characteristic + the number of characteristic values + the number of + * descriptors, excluding the services) that can be stored in the GATT + * database. Note that certain characteristics and relative descriptors are + * added automatically during device initialization so this parameters should + * be 9 plus the number of user Attributes + * + * @param num_gatt_services: Maximum number of Services that can be stored in + * the GATT database. Note that the GAP and GATT services are automatically + * added so this parameter should be 2 plus the number of user services + * + * @param att_value_array_size: Size of the storage area for Attribute values. + */ +#define BLE_TOTAL_BUFFER_SIZE_GATT(num_gatt_attributes, num_gatt_services, att_value_array_size) \ + (((((att_value_array_size) - 1) | 3) + 1) + \ + (40 * (num_gatt_attributes)) + (48 * (num_gatt_services))) + + +#endif /* BLE_BUFSIZE_H__ */ diff --git a/src/utility/STM32_WPAN/hw.h b/src/utility/STM32_WPAN/hw.h new file mode 100644 index 00000000..1472a5e8 --- /dev/null +++ b/src/utility/STM32_WPAN/hw.h @@ -0,0 +1,114 @@ +/** + ****************************************************************************** + * @file hw.h + * @author MCD Application Team + * @brief Hardware + ****************************************************************************** + * @attention + * + * Copyright (c) 2018-2021 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ + + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __HW_H +#define __HW_H + +#ifdef __cplusplus +extern "C" { +#endif + + /* Includes ------------------------------------------------------------------*/ +#include "stm32_def.h" +#include "stm32wbxx_ll_bus.h" +#include "stm32wbxx_ll_exti.h" +#include "stm32wbxx_ll_system.h" +#include "stm32wbxx_ll_rcc.h" +#include "stm32wbxx_ll_ipcc.h" +#include "stm32wbxx_ll_cortex.h" +#include "stm32wbxx_ll_utils.h" +#include "stm32wbxx_ll_pwr.h" + + /****************************************************************************** + * HW IPCC + ******************************************************************************/ + void HW_IPCC_Enable( void ); + void HW_IPCC_Init( void ); +#define HW_IPCC_Rx_Handler IPCC_C1_RX_IRQHandler +#define HW_IPCC_Tx_Handler IPCC_C1_TX_IRQHandler + + void HW_IPCC_BLE_Init( void ); + void HW_IPCC_BLE_SendCmd( void ); + void HW_IPCC_MM_SendFreeBuf( void (*cb)( void ) ); + void HW_IPCC_BLE_RxEvtNot( void ); + void HW_IPCC_BLE_SendAclData( void ); + void HW_IPCC_BLE_AclDataAckNot( void ); + + void HW_IPCC_SYS_Init( void ); + void HW_IPCC_SYS_SendCmd( void ); + void HW_IPCC_SYS_CmdEvtNot( void ); + void HW_IPCC_SYS_EvtNot( void ); + + void HW_IPCC_THREAD_Init( void ); + void HW_IPCC_OT_SendCmd( void ); + void HW_IPCC_CLI_SendCmd( void ); + void HW_IPCC_THREAD_SendAck( void ); + void HW_IPCC_OT_CmdEvtNot( void ); + void HW_IPCC_CLI_CmdEvtNot( void ); + void HW_IPCC_THREAD_EvtNot( void ); + void HW_IPCC_THREAD_CliSendAck( void ); + void HW_IPCC_THREAD_CliEvtNot( void ); + + + void HW_IPCC_LLDTESTS_Init( void ); + void HW_IPCC_LLDTESTS_SendCliCmd( void ); + void HW_IPCC_LLDTESTS_ReceiveCliRsp( void ); + void HW_IPCC_LLDTESTS_SendCliRspAck( void ); + void HW_IPCC_LLDTESTS_ReceiveM0Cmd( void ); + void HW_IPCC_LLDTESTS_SendM0CmdAck( void ); + + + void HW_IPCC_BLE_LLD_Init( void ); + void HW_IPCC_BLE_LLD_SendCliCmd( void ); + void HW_IPCC_BLE_LLD_ReceiveCliRsp( void ); + void HW_IPCC_BLE_LLD_SendCliRspAck( void ); + void HW_IPCC_BLE_LLD_ReceiveM0Cmd( void ); + void HW_IPCC_BLE_LLD_SendM0CmdAck( void ); + void HW_IPCC_BLE_LLD_SendCmd( void ); + void HW_IPCC_BLE_LLD_ReceiveRsp( void ); + void HW_IPCC_BLE_LLD_SendRspAck( void ); + + + void HW_IPCC_TRACES_Init( void ); + void HW_IPCC_TRACES_EvtNot( void ); + + void HW_IPCC_MAC_802_15_4_Init( void ); + void HW_IPCC_MAC_802_15_4_SendCmd( void ); + void HW_IPCC_MAC_802_15_4_SendAck( void ); + void HW_IPCC_MAC_802_15_4_CmdEvtNot( void ); + void HW_IPCC_MAC_802_15_4_EvtNot( void ); + + void HW_IPCC_ZIGBEE_Init( void ); + + void HW_IPCC_ZIGBEE_SendM4RequestToM0(void); /* M4 Request to M0 */ + void HW_IPCC_ZIGBEE_RecvAppliAckFromM0(void); /* Request ACK from M0 */ + + void HW_IPCC_ZIGBEE_RecvM0NotifyToM4(void); /* M0 Notify to M4 */ + void HW_IPCC_ZIGBEE_SendM4AckToM0Notify(void); /* Notify ACK from M4 */ + void HW_IPCC_ZIGBEE_RecvM0RequestToM4(void); /* M0 Request to M4 */ + void HW_IPCC_ZIGBEE_SendM4AckToM0Request(void); /* Request ACK from M4 */ + + +#ifdef __cplusplus +} +#endif + +#endif /*__HW_H */ + diff --git a/src/utility/STM32_WPAN/hw_ipcc.c b/src/utility/STM32_WPAN/hw_ipcc.c new file mode 100644 index 00000000..ad3c9d4c --- /dev/null +++ b/src/utility/STM32_WPAN/hw_ipcc.c @@ -0,0 +1,749 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file hw_ipcc.c + * @author MCD Application Team + * @brief Hardware IPCC source file for STM32WPAN Middleware. + ****************************************************************************** + * @attention + * + * Copyright (c) 2020-2021 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ + +#if defined(STM32WBxx) +/* Includes ------------------------------------------------------------------*/ +#include "hw.h" +#include "mbox_def.h" +#include "utilities_conf.h" + +/* Global variables ---------------------------------------------------------*/ +/* Private defines -----------------------------------------------------------*/ +#define HW_IPCC_TX_PENDING( channel ) ( !(LL_C1_IPCC_IsActiveFlag_CHx( IPCC, channel )) ) && (((~(IPCC->C1MR)) & (channel << 16U))) +#define HW_IPCC_RX_PENDING( channel ) (LL_C2_IPCC_IsActiveFlag_CHx( IPCC, channel )) && (((~(IPCC->C1MR)) & (channel << 0U))) + +/* Private macros ------------------------------------------------------------*/ +/* Private typedef -----------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +static void (*FreeBufCb)( void ); + +/* Private function prototypes -----------------------------------------------*/ +static void HW_IPCC_BLE_EvtHandler( void ); +static void HW_IPCC_BLE_AclDataEvtHandler( void ); +static void HW_IPCC_MM_FreeBufHandler( void ); +static void HW_IPCC_SYS_CmdEvtHandler( void ); +static void HW_IPCC_SYS_EvtHandler( void ); +static void HW_IPCC_TRACES_EvtHandler( void ); + +#ifdef THREAD_WB +static void HW_IPCC_OT_CmdEvtHandler( void ); +static void HW_IPCC_THREAD_NotEvtHandler( void ); +static void HW_IPCC_THREAD_CliNotEvtHandler( void ); +#endif + +#ifdef LLD_TESTS_WB +static void HW_IPCC_LLDTESTS_ReceiveCliRspHandler( void ); +static void HW_IPCC_LLDTESTS_ReceiveM0CmdHandler( void ); +#endif +#ifdef LLD_BLE_WB +/*static void HW_IPCC_LLD_BLE_ReceiveCliRspHandler( void );*/ +static void HW_IPCC_LLD_BLE_ReceiveRspHandler( void ); +static void HW_IPCC_LLD_BLE_ReceiveM0CmdHandler( void ); +#endif + +#ifdef MAC_802_15_4_WB +static void HW_IPCC_MAC_802_15_4_CmdEvtHandler( void ); +static void HW_IPCC_MAC_802_15_4_NotEvtHandler( void ); +#endif + +#ifdef ZIGBEE_WB +static void HW_IPCC_ZIGBEE_CmdEvtHandler( void ); +static void HW_IPCC_ZIGBEE_StackNotifEvtHandler( void ); +static void HW_IPCC_ZIGBEE_StackM0RequestHandler( void ); +#endif + +/* Public function definition -----------------------------------------------*/ + +/****************************************************************************** + * INTERRUPT HANDLER + ******************************************************************************/ +void HW_IPCC_Rx_Handler( void ) +{ + if (HW_IPCC_RX_PENDING( HW_IPCC_SYSTEM_EVENT_CHANNEL )) + { + HW_IPCC_SYS_EvtHandler(); + } +#ifdef MAC_802_15_4_WB + else if (HW_IPCC_RX_PENDING( HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL )) + { + HW_IPCC_MAC_802_15_4_NotEvtHandler(); + } +#endif /* MAC_802_15_4_WB */ +#ifdef THREAD_WB + else if (HW_IPCC_RX_PENDING( HW_IPCC_THREAD_NOTIFICATION_ACK_CHANNEL )) + { + HW_IPCC_THREAD_NotEvtHandler(); + } + else if (HW_IPCC_RX_PENDING( HW_IPCC_THREAD_CLI_NOTIFICATION_ACK_CHANNEL )) + { + HW_IPCC_THREAD_CliNotEvtHandler(); + } +#endif /* THREAD_WB */ +#ifdef LLD_TESTS_WB + else if (HW_IPCC_RX_PENDING( HW_IPCC_LLDTESTS_CLI_RSP_CHANNEL )) + { + HW_IPCC_LLDTESTS_ReceiveCliRspHandler(); + } + else if (HW_IPCC_RX_PENDING( HW_IPCC_LLDTESTS_M0_CMD_CHANNEL )) + { + HW_IPCC_LLDTESTS_ReceiveM0CmdHandler(); + } +#endif /* LLD_TESTS_WB */ +#ifdef LLD_BLE_WB + else if (HW_IPCC_RX_PENDING( HW_IPCC_LLD_BLE_RSP_CHANNEL )) + { + HW_IPCC_LLD_BLE_ReceiveRspHandler(); + } + else if (HW_IPCC_RX_PENDING( HW_IPCC_LLD_BLE_M0_CMD_CHANNEL )) + { + HW_IPCC_LLD_BLE_ReceiveM0CmdHandler(); + } +#endif /* LLD_TESTS_WB */ +#ifdef ZIGBEE_WB + else if (HW_IPCC_RX_PENDING( HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL )) + { + HW_IPCC_ZIGBEE_StackNotifEvtHandler(); + } + else if (HW_IPCC_RX_PENDING( HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL )) + { + HW_IPCC_ZIGBEE_StackM0RequestHandler(); + } +#endif /* ZIGBEE_WB */ + else if (HW_IPCC_RX_PENDING( HW_IPCC_BLE_EVENT_CHANNEL )) + { + HW_IPCC_BLE_EvtHandler(); + } + else if (HW_IPCC_RX_PENDING( HW_IPCC_TRACES_CHANNEL )) + { + HW_IPCC_TRACES_EvtHandler(); + } + + return; +} + +void HW_IPCC_Tx_Handler( void ) +{ + if (HW_IPCC_TX_PENDING( HW_IPCC_SYSTEM_CMD_RSP_CHANNEL )) + { + HW_IPCC_SYS_CmdEvtHandler(); + } +#ifdef MAC_802_15_4_WB + else if (HW_IPCC_TX_PENDING( HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL )) + { + HW_IPCC_MAC_802_15_4_CmdEvtHandler(); + } +#endif /* MAC_802_15_4_WB */ +#ifdef THREAD_WB + else if (HW_IPCC_TX_PENDING( HW_IPCC_THREAD_OT_CMD_RSP_CHANNEL )) + { + HW_IPCC_OT_CmdEvtHandler(); + } +#endif /* THREAD_WB */ +#ifdef LLD_TESTS_WB +// No TX handler for LLD tests +#endif /* LLD_TESTS_WB */ +#ifdef ZIGBEE_WB + if (HW_IPCC_TX_PENDING( HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL )) + { + HW_IPCC_ZIGBEE_CmdEvtHandler(); + } +#endif /* ZIGBEE_WB */ + else if (HW_IPCC_TX_PENDING( HW_IPCC_MM_RELEASE_BUFFER_CHANNEL )) + { + HW_IPCC_MM_FreeBufHandler(); + } + else if (HW_IPCC_TX_PENDING( HW_IPCC_HCI_ACL_DATA_CHANNEL )) + { + HW_IPCC_BLE_AclDataEvtHandler(); + } + + return; +} +/****************************************************************************** + * GENERAL + ******************************************************************************/ +void HW_IPCC_Enable( void ) +{ + /** + * Such as IPCC IP available to the CPU2, it is required to keep the IPCC clock running + * when FUS is running on CPU2 and CPU1 enters deep sleep mode + */ + LL_C2_AHB3_GRP1_EnableClock(LL_C2_AHB3_GRP1_PERIPH_IPCC); + + /** + * When the device is out of standby, it is required to use the EXTI mechanism to wakeup CPU2 + */ + LL_EXTI_EnableRisingTrig_32_63( LL_EXTI_LINE_41 ); + /* It is required to have at least a system clock cycle before a SEV after LL_EXTI_EnableRisingTrig_32_63() */ + LL_C2_EXTI_EnableEvent_32_63( LL_EXTI_LINE_41 ); + + /** + * In case the SBSFU is implemented, it may have already set the C2BOOT bit to startup the CPU2. + * In that case, to keep the mechanism transparent to the user application, it shall call the system command + * SHCI_C2_Reinit( ) before jumping to the application. + * When the CPU2 receives that command, it waits for its event input to be set to restart the CPU2 firmware. + * This is required because once C2BOOT has been set once, a clear/set on C2BOOT has no effect. + * When SHCI_C2_Reinit( ) is not called, generating an event to the CPU2 does not have any effect + * So, by default, the application shall both set the event flag and set the C2BOOT bit. + */ + __SEV( ); /* Set the internal event flag and send an event to the CPU2 */ + __WFE( ); /* Clear the internal event flag */ + LL_PWR_EnableBootC2( ); + + return; +} + +void HW_IPCC_Init( void ) +{ + LL_AHB3_GRP1_EnableClock( LL_AHB3_GRP1_PERIPH_IPCC ); + + LL_C1_IPCC_EnableIT_RXO( IPCC ); + LL_C1_IPCC_EnableIT_TXF( IPCC ); + + HAL_NVIC_EnableIRQ(IPCC_C1_RX_IRQn); + HAL_NVIC_EnableIRQ(IPCC_C1_TX_IRQn); + + return; +} + +/****************************************************************************** + * BLE + ******************************************************************************/ +void HW_IPCC_BLE_Init( void ) +{ + UTILS_ENTER_CRITICAL_SECTION(); + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_BLE_EVENT_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); + + return; +} + +void HW_IPCC_BLE_SendCmd( void ) +{ + LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_BLE_CMD_CHANNEL ); + + return; +} + +static void HW_IPCC_BLE_EvtHandler( void ) +{ + HW_IPCC_BLE_RxEvtNot(); + + LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_BLE_EVENT_CHANNEL ); + + return; +} + +void HW_IPCC_BLE_SendAclData( void ) +{ + LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_HCI_ACL_DATA_CHANNEL ); + UTILS_ENTER_CRITICAL_SECTION(); + LL_C1_IPCC_EnableTransmitChannel( IPCC, HW_IPCC_HCI_ACL_DATA_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); + + return; +} + +static void HW_IPCC_BLE_AclDataEvtHandler( void ) +{ + UTILS_ENTER_CRITICAL_SECTION(); + LL_C1_IPCC_DisableTransmitChannel( IPCC, HW_IPCC_HCI_ACL_DATA_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); + + HW_IPCC_BLE_AclDataAckNot(); + + return; +} + +__weak void HW_IPCC_BLE_AclDataAckNot( void ){}; +__weak void HW_IPCC_BLE_RxEvtNot( void ){}; + +/****************************************************************************** + * SYSTEM + ******************************************************************************/ +void HW_IPCC_SYS_Init( void ) +{ + UTILS_ENTER_CRITICAL_SECTION(); + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_SYSTEM_EVENT_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); + + return; +} + +void HW_IPCC_SYS_SendCmd( void ) +{ + LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_SYSTEM_CMD_RSP_CHANNEL ); + UTILS_ENTER_CRITICAL_SECTION(); + LL_C1_IPCC_EnableTransmitChannel( IPCC, HW_IPCC_SYSTEM_CMD_RSP_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); + + return; +} + +static void HW_IPCC_SYS_CmdEvtHandler( void ) +{ + UTILS_ENTER_CRITICAL_SECTION(); + LL_C1_IPCC_DisableTransmitChannel( IPCC, HW_IPCC_SYSTEM_CMD_RSP_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); + + HW_IPCC_SYS_CmdEvtNot(); + + return; +} + +static void HW_IPCC_SYS_EvtHandler( void ) +{ + HW_IPCC_SYS_EvtNot(); + + LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_SYSTEM_EVENT_CHANNEL ); + + return; +} + +__weak void HW_IPCC_SYS_CmdEvtNot( void ){}; +__weak void HW_IPCC_SYS_EvtNot( void ){}; + +/****************************************************************************** + * MAC 802.15.4 + ******************************************************************************/ +#ifdef MAC_802_15_4_WB +void HW_IPCC_MAC_802_15_4_Init( void ) +{ + UTILS_ENTER_CRITICAL_SECTION(); + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); + + return; +} + +void HW_IPCC_MAC_802_15_4_SendCmd( void ) +{ + LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL ); + UTILS_ENTER_CRITICAL_SECTION(); + LL_C1_IPCC_EnableTransmitChannel( IPCC, HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); + + return; +} + +void HW_IPCC_MAC_802_15_4_SendAck( void ) +{ + LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL ); + UTILS_ENTER_CRITICAL_SECTION(); + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); + + return; +} + +static void HW_IPCC_MAC_802_15_4_CmdEvtHandler( void ) +{ + UTILS_ENTER_CRITICAL_SECTION(); + LL_C1_IPCC_DisableTransmitChannel( IPCC, HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); + + HW_IPCC_MAC_802_15_4_CmdEvtNot(); + + return; +} + +static void HW_IPCC_MAC_802_15_4_NotEvtHandler( void ) +{ + UTILS_ENTER_CRITICAL_SECTION(); + LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); + + HW_IPCC_MAC_802_15_4_EvtNot(); + + return; +} +__weak void HW_IPCC_MAC_802_15_4_CmdEvtNot( void ){}; +__weak void HW_IPCC_MAC_802_15_4_EvtNot( void ){}; +#endif + +/****************************************************************************** + * THREAD + ******************************************************************************/ +#ifdef THREAD_WB +void HW_IPCC_THREAD_Init( void ) +{ + UTILS_ENTER_CRITICAL_SECTION(); + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_THREAD_NOTIFICATION_ACK_CHANNEL ); + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_THREAD_CLI_NOTIFICATION_ACK_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); + + return; +} + +void HW_IPCC_OT_SendCmd( void ) +{ + LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_THREAD_OT_CMD_RSP_CHANNEL ); + UTILS_ENTER_CRITICAL_SECTION(); + LL_C1_IPCC_EnableTransmitChannel( IPCC, HW_IPCC_THREAD_OT_CMD_RSP_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); + + return; +} + +void HW_IPCC_CLI_SendCmd( void ) +{ + LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_THREAD_CLI_CMD_CHANNEL ); + + return; +} + +void HW_IPCC_THREAD_SendAck( void ) +{ + LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_THREAD_NOTIFICATION_ACK_CHANNEL ); + UTILS_ENTER_CRITICAL_SECTION(); + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_THREAD_NOTIFICATION_ACK_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); + + return; +} + +void HW_IPCC_THREAD_CliSendAck( void ) +{ + LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_THREAD_CLI_NOTIFICATION_ACK_CHANNEL ); + UTILS_ENTER_CRITICAL_SECTION(); + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_THREAD_CLI_NOTIFICATION_ACK_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); + + return; +} + +static void HW_IPCC_OT_CmdEvtHandler( void ) +{ + UTILS_ENTER_CRITICAL_SECTION(); + LL_C1_IPCC_DisableTransmitChannel( IPCC, HW_IPCC_THREAD_OT_CMD_RSP_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); + + HW_IPCC_OT_CmdEvtNot(); + + return; +} + +static void HW_IPCC_THREAD_NotEvtHandler( void ) +{ + UTILS_ENTER_CRITICAL_SECTION(); + LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_THREAD_NOTIFICATION_ACK_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); + + HW_IPCC_THREAD_EvtNot(); + + return; +} + +static void HW_IPCC_THREAD_CliNotEvtHandler( void ) +{ + UTILS_ENTER_CRITICAL_SECTION(); + LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_THREAD_CLI_NOTIFICATION_ACK_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); + + HW_IPCC_THREAD_CliEvtNot(); + + return; +} + +__weak void HW_IPCC_OT_CmdEvtNot( void ){}; +__weak void HW_IPCC_CLI_CmdEvtNot( void ){}; +__weak void HW_IPCC_THREAD_EvtNot( void ){}; + +#endif /* THREAD_WB */ + +/****************************************************************************** + * LLD TESTS + ******************************************************************************/ +#ifdef LLD_TESTS_WB +void HW_IPCC_LLDTESTS_Init( void ) +{ + UTILS_ENTER_CRITICAL_SECTION(); + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_LLDTESTS_CLI_RSP_CHANNEL ); + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_LLDTESTS_M0_CMD_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); + return; +} + +void HW_IPCC_LLDTESTS_SendCliCmd( void ) +{ + LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_LLDTESTS_CLI_CMD_CHANNEL ); + return; +} + +static void HW_IPCC_LLDTESTS_ReceiveCliRspHandler( void ) +{ + UTILS_ENTER_CRITICAL_SECTION(); + LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_LLDTESTS_CLI_RSP_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); + + HW_IPCC_LLDTESTS_ReceiveCliRsp(); + return; +} + +void HW_IPCC_LLDTESTS_SendCliRspAck( void ) +{ + LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_LLDTESTS_CLI_RSP_CHANNEL ); + UTILS_ENTER_CRITICAL_SECTION(); + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_LLDTESTS_CLI_RSP_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); + return; +} + +static void HW_IPCC_LLDTESTS_ReceiveM0CmdHandler( void ) +{ + UTILS_ENTER_CRITICAL_SECTION(); + LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_LLDTESTS_M0_CMD_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); + HW_IPCC_LLDTESTS_ReceiveM0Cmd(); + return; +} + +void HW_IPCC_LLDTESTS_SendM0CmdAck( void ) +{ + LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_LLDTESTS_M0_CMD_CHANNEL ); + UTILS_ENTER_CRITICAL_SECTION(); + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_LLDTESTS_M0_CMD_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); + return; +} +__weak void HW_IPCC_LLDTESTS_ReceiveCliRsp( void ){}; +__weak void HW_IPCC_LLDTESTS_ReceiveM0Cmd( void ){}; +#endif /* LLD_TESTS_WB */ + +/****************************************************************************** + * LLD BLE + ******************************************************************************/ +#ifdef LLD_BLE_WB +void HW_IPCC_LLD_BLE_Init( void ) +{ + UTILS_ENTER_CRITICAL_SECTION(); + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_LLD_BLE_RSP_CHANNEL ); + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_LLD_BLE_M0_CMD_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); + return; +} + +void HW_IPCC_LLD_BLE_SendCliCmd( void ) +{ + LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_LLD_BLE_CLI_CMD_CHANNEL ); + return; +} + +/*static void HW_IPCC_LLD_BLE_ReceiveCliRspHandler( void ) +{ + UTILS_ENTER_CRITICAL_SECTION(); + LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_LLD_BLE_CLI_RSP_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); + HW_IPCC_LLD_BLE_ReceiveCliRsp(); + return; +}*/ + +void HW_IPCC_LLD_BLE_SendCliRspAck( void ) +{ + LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_LLD_BLE_CLI_RSP_CHANNEL ); + UTILS_ENTER_CRITICAL_SECTION(); + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_LLD_BLE_CLI_RSP_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); + return; +} + +static void HW_IPCC_LLD_BLE_ReceiveM0CmdHandler( void ) +{ + //LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_LLD_BLE_M0_CMD_CHANNEL ); + HW_IPCC_LLD_BLE_ReceiveM0Cmd(); + return; +} + +void HW_IPCC_LLD_BLE_SendM0CmdAck( void ) +{ + LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_LLD_BLE_M0_CMD_CHANNEL ); + //LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_LLD_BLE_M0_CMD_CHANNEL ); + return; +} +__weak void HW_IPCC_LLD_BLE_ReceiveCliRsp( void ){}; +__weak void HW_IPCC_LLD_BLE_ReceiveM0Cmd( void ){}; + +/* Transparent Mode */ +void HW_IPCC_LLD_BLE_SendCmd( void ) +{ + LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_LLD_BLE_CMD_CHANNEL ); + return; +} + +static void HW_IPCC_LLD_BLE_ReceiveRspHandler( void ) +{ + UTILS_ENTER_CRITICAL_SECTION(); + LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_LLD_BLE_RSP_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); + HW_IPCC_LLD_BLE_ReceiveRsp(); + return; +} + +void HW_IPCC_LLD_BLE_SendRspAck( void ) +{ + LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_LLD_BLE_RSP_CHANNEL ); + UTILS_ENTER_CRITICAL_SECTION(); + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_LLD_BLE_RSP_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); + return; +} + +#endif /* LLD_BLE_WB */ + +/****************************************************************************** + * ZIGBEE + ******************************************************************************/ +#ifdef ZIGBEE_WB +void HW_IPCC_ZIGBEE_Init( void ) +{ + UTILS_ENTER_CRITICAL_SECTION(); + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL ); + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); + + return; +} + +void HW_IPCC_ZIGBEE_SendM4RequestToM0( void ) +{ + LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL ); + UTILS_ENTER_CRITICAL_SECTION(); + LL_C1_IPCC_EnableTransmitChannel( IPCC, HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); + + return; +} + +void HW_IPCC_ZIGBEE_SendM4AckToM0Notify( void ) +{ + LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL ); + UTILS_ENTER_CRITICAL_SECTION(); + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); + + return; +} + +static void HW_IPCC_ZIGBEE_CmdEvtHandler( void ) +{ + UTILS_ENTER_CRITICAL_SECTION(); + LL_C1_IPCC_DisableTransmitChannel( IPCC, HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); + + HW_IPCC_ZIGBEE_RecvAppliAckFromM0(); + + return; +} + +static void HW_IPCC_ZIGBEE_StackNotifEvtHandler( void ) +{ + UTILS_ENTER_CRITICAL_SECTION(); + LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); + + HW_IPCC_ZIGBEE_RecvM0NotifyToM4(); + + return; +} + +static void HW_IPCC_ZIGBEE_StackM0RequestHandler( void ) +{ + UTILS_ENTER_CRITICAL_SECTION(); + LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); + + HW_IPCC_ZIGBEE_RecvM0RequestToM4(); + + return; +} + +void HW_IPCC_ZIGBEE_SendM4AckToM0Request( void ) +{ + LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL ); + UTILS_ENTER_CRITICAL_SECTION(); + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); + + return; +} + +__weak void HW_IPCC_ZIGBEE_RecvAppliAckFromM0( void ){}; +__weak void HW_IPCC_ZIGBEE_RecvM0NotifyToM4( void ){}; +__weak void HW_IPCC_ZIGBEE_RecvM0RequestToM4( void ){}; +#endif /* ZIGBEE_WB */ + +/****************************************************************************** + * MEMORY MANAGER + ******************************************************************************/ +void HW_IPCC_MM_SendFreeBuf( void (*cb)( void ) ) +{ + if ( LL_C1_IPCC_IsActiveFlag_CHx( IPCC, HW_IPCC_MM_RELEASE_BUFFER_CHANNEL ) ) + { + FreeBufCb = cb; + UTILS_ENTER_CRITICAL_SECTION(); + LL_C1_IPCC_EnableTransmitChannel( IPCC, HW_IPCC_MM_RELEASE_BUFFER_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); + } + else + { + cb(); + + LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_MM_RELEASE_BUFFER_CHANNEL ); + } + + return; +} + +static void HW_IPCC_MM_FreeBufHandler( void ) +{ + UTILS_ENTER_CRITICAL_SECTION(); + LL_C1_IPCC_DisableTransmitChannel( IPCC, HW_IPCC_MM_RELEASE_BUFFER_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); + + FreeBufCb(); + + LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_MM_RELEASE_BUFFER_CHANNEL ); + + return; +} + +/****************************************************************************** + * TRACES + ******************************************************************************/ +void HW_IPCC_TRACES_Init( void ) +{ + UTILS_ENTER_CRITICAL_SECTION(); + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_TRACES_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); + + return; +} + +static void HW_IPCC_TRACES_EvtHandler( void ) +{ + HW_IPCC_TRACES_EvtNot(); + + LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_TRACES_CHANNEL ); + + return; +} + +__weak void HW_IPCC_TRACES_EvtNot( void ){}; +#endif /* STM32WBxx */ diff --git a/src/utility/STM32_WPAN/mbox_def.h b/src/utility/STM32_WPAN/mbox_def.h new file mode 100644 index 00000000..68b71f9c --- /dev/null +++ b/src/utility/STM32_WPAN/mbox_def.h @@ -0,0 +1,280 @@ +/** + ****************************************************************************** + * @file mbox_def.h + * @author MCD Application Team + * @brief Mailbox definition + ****************************************************************************** + * @attention + * + * Copyright (c) 2018-2021 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ + + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __MBOX_H +#define __MBOX_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "stm32_wpan_common.h" + + /** + * This file shall be identical between the CPU1 and the CPU2 + */ + + /** + ********************************************************************************* + * TABLES + ********************************************************************************* + */ + + /** + * Version + * [0:3] = Build - 0: Untracked - 15:Released - x: Tracked version + * [4:7] = branch - 0: Mass Market - x: ... + * [8:15] = Subversion + * [16:23] = Version minor + * [24:31] = Version major + * + * Memory Size + * [0:7] = Flash ( Number of 4k sector) + * [8:15] = Reserved ( Shall be set to 0 - may be used as flash extension ) + * [16:23] = SRAM2b ( Number of 1k sector) + * [24:31] = SRAM2a ( Number of 1k sector) + */ + typedef PACKED_STRUCT + { + uint32_t Version; + } MB_SafeBootInfoTable_t; + + typedef PACKED_STRUCT + { + uint32_t Version; + uint32_t MemorySize; + uint32_t FusInfo; + } MB_FusInfoTable_t; + + typedef PACKED_STRUCT + { + uint32_t Version; + uint32_t MemorySize; + uint32_t InfoStack; + uint32_t Reserved; + } MB_WirelessFwInfoTable_t; + + typedef struct + { + MB_SafeBootInfoTable_t SafeBootInfoTable; + MB_FusInfoTable_t FusInfoTable; + MB_WirelessFwInfoTable_t WirelessFwInfoTable; + } MB_DeviceInfoTable_t; + + typedef struct + { + uint8_t *pcmd_buffer; + uint8_t *pcs_buffer; + uint8_t *pevt_queue; + uint8_t *phci_acl_data_buffer; + } MB_BleTable_t; + + typedef struct + { + uint8_t *notack_buffer; + uint8_t *clicmdrsp_buffer; + uint8_t *otcmdrsp_buffer; + uint8_t *clinot_buffer; + } MB_ThreadTable_t; + + typedef struct + { + uint8_t *clicmdrsp_buffer; + uint8_t *m0cmd_buffer; + } MB_LldTestsTable_t; + + typedef struct + { + uint8_t *cmdrsp_buffer; + uint8_t *m0cmd_buffer; + } MB_BleLldTable_t; + + typedef struct + { + uint8_t *notifM0toM4_buffer; + uint8_t *appliCmdM4toM0_buffer; + uint8_t *requestM0toM4_buffer; + } MB_ZigbeeTable_t; + /** + * msg + * [0:7] = cmd/evt + * [8:31] = Reserved + */ + typedef struct + { + uint8_t *pcmd_buffer; + uint8_t *sys_queue; + } MB_SysTable_t; + + typedef struct + { + uint8_t *spare_ble_buffer; + uint8_t *spare_sys_buffer; + uint8_t *blepool; + uint32_t blepoolsize; + uint8_t *pevt_free_buffer_queue; + uint8_t *traces_evt_pool; + uint32_t tracespoolsize; + } MB_MemManagerTable_t; + + typedef struct + { + uint8_t *traces_queue; + } MB_TracesTable_t; + + typedef struct + { + uint8_t *p_cmdrsp_buffer; + uint8_t *p_notack_buffer; + uint8_t *evt_queue; + } MB_Mac_802_15_4_t; + + typedef struct + { + MB_DeviceInfoTable_t *p_device_info_table; + MB_BleTable_t *p_ble_table; + MB_ThreadTable_t *p_thread_table; + MB_SysTable_t *p_sys_table; + MB_MemManagerTable_t *p_mem_manager_table; + MB_TracesTable_t *p_traces_table; + MB_Mac_802_15_4_t *p_mac_802_15_4_table; + MB_ZigbeeTable_t *p_zigbee_table; + MB_LldTestsTable_t *p_lld_tests_table; + MB_BleLldTable_t *p_ble_lld_table; +} MB_RefTable_t; + +/** + * This table shall be used only in the case the CPU2 runs the FUS. + * It is used by the command SHCI_GetWirelessFwInfo() + */ +typedef struct +{ + uint32_t DeviceInfoTableState; + uint8_t Reserved1; + uint8_t LastFusActiveState; + uint8_t LastWirelessStackState; + uint8_t CurrentWirelessStackType; + uint32_t SafeBootVersion; + uint32_t FusVersion; + uint32_t FusMemorySize; + uint32_t WirelessStackVersion; + uint32_t WirelessStackMemorySize; + uint32_t WirelessFirmwareBleInfo; + uint32_t WirelessFirmwareThreadInfo; + uint32_t Reserved2; + uint64_t UID64; + uint16_t DeviceId; +} MB_FUS_DeviceInfoTable_t ; + +#ifdef __cplusplus +} +#endif + +/** + ********************************************************************************* + * IPCC CHANNELS + ********************************************************************************* + */ + +/* CPU1 CPU2 + * | (SYSTEM) | + * |----HW_IPCC_SYSTEM_CMD_RSP_CHANNEL-------------->| + * | | + * |<---HW_IPCC_SYSTEM_EVENT_CHANNEL-----------------| + * | | + * | (ZIGBEE) | + * |----HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL------------>| + * | | + * |----HW_IPCC_ZIGBEE_CMD_CLI_CHANNEL-------------->| + * | | + * |<---HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL-------| + * | | + * |<---HW_IPCC_ZIGBEE_CLI_NOTIF_ACK_CHANNEL---------| + * | | + * | (THREAD) | + * |----HW_IPCC_THREAD_OT_CMD_RSP_CHANNEL----------->| + * | | + * |----HW_IPCC_THREAD_CLI_CMD_CHANNEL-------------->| + * | | + * |<---HW_IPCC_THREAD_NOTIFICATION_ACK_CHANNEL------| + * | | + * |<---HW_IPCC_THREAD_CLI_NOTIFICATION_ACK_CHANNEL--| + * | | + * | (BLE) | + * |----HW_IPCC_BLE_CMD_CHANNEL--------------------->| + * | | + * |----HW_IPCC_HCI_ACL_DATA_CHANNEL---------------->| + * | | + * |<---HW_IPCC_BLE_EVENT_CHANNEL--------------------| + * | | + * | (BLE LLD) | + * |----HW_IPCC_BLE_LLD_CMD_CHANNEL----------------->| + * | | + * |<---HW_IPCC_BLE_LLD_RSP_CHANNEL------------------| + * | | + * |<---HW_IPCC_BLE_LLD_M0_CMD_CHANNEL---------------| + * | | + * | (MAC) | + * |----HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL-------->| + * | | + * |<---HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL| + * | | + * | (BUFFER) | + * |----HW_IPCC_MM_RELEASE_BUFFER_CHANNE------------>| + * | | + * | (TRACE) | + * |<----HW_IPCC_TRACES_CHANNEL----------------------| + * | | + * + * + * + */ + + + +/** CPU1 */ +#define HW_IPCC_BLE_CMD_CHANNEL LL_IPCC_CHANNEL_1 +#define HW_IPCC_SYSTEM_CMD_RSP_CHANNEL LL_IPCC_CHANNEL_2 +#define HW_IPCC_THREAD_OT_CMD_RSP_CHANNEL LL_IPCC_CHANNEL_3 +#define HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL LL_IPCC_CHANNEL_3 +#define HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL LL_IPCC_CHANNEL_3 +#define HW_IPCC_MM_RELEASE_BUFFER_CHANNEL LL_IPCC_CHANNEL_4 +#define HW_IPCC_THREAD_CLI_CMD_CHANNEL LL_IPCC_CHANNEL_5 +#define HW_IPCC_LLDTESTS_CLI_CMD_CHANNEL LL_IPCC_CHANNEL_5 +#define HW_IPCC_BLE_LLD_CLI_CMD_CHANNEL LL_IPCC_CHANNEL_5 +#define HW_IPCC_BLE_LLD_CMD_CHANNEL LL_IPCC_CHANNEL_5 +#define HW_IPCC_HCI_ACL_DATA_CHANNEL LL_IPCC_CHANNEL_6 + +/** CPU2 */ +#define HW_IPCC_BLE_EVENT_CHANNEL LL_IPCC_CHANNEL_1 +#define HW_IPCC_SYSTEM_EVENT_CHANNEL LL_IPCC_CHANNEL_2 +#define HW_IPCC_THREAD_NOTIFICATION_ACK_CHANNEL LL_IPCC_CHANNEL_3 +#define HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL LL_IPCC_CHANNEL_3 +#define HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL LL_IPCC_CHANNEL_3 +#define HW_IPCC_LLDTESTS_M0_CMD_CHANNEL LL_IPCC_CHANNEL_3 +#define HW_IPCC_BLE_LLD_M0_CMD_CHANNEL LL_IPCC_CHANNEL_3 +#define HW_IPCC_TRACES_CHANNEL LL_IPCC_CHANNEL_4 +#define HW_IPCC_THREAD_CLI_NOTIFICATION_ACK_CHANNEL LL_IPCC_CHANNEL_5 +#define HW_IPCC_LLDTESTS_CLI_RSP_CHANNEL LL_IPCC_CHANNEL_5 +#define HW_IPCC_BLE_LLD_CLI_RSP_CHANNEL LL_IPCC_CHANNEL_5 +#define HW_IPCC_BLE_LLD_RSP_CHANNEL LL_IPCC_CHANNEL_5 +#define HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL LL_IPCC_CHANNEL_5 +#endif /*__MBOX_H */ + diff --git a/src/utility/STM32_WPAN/shci.c b/src/utility/STM32_WPAN/shci.c new file mode 100644 index 00000000..40110f42 --- /dev/null +++ b/src/utility/STM32_WPAN/shci.c @@ -0,0 +1,763 @@ +/** + ****************************************************************************** + * @file shci.c + * @author MCD Application Team + * @brief HCI command for the system channel + ****************************************************************************** + * @attention + * + * Copyright (c) 2018-2021 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ + + +#if defined(STM32WBxx) +/* Includes ------------------------------------------------------------------*/ +#include "stm32_wpan_common.h" + +#include "shci_tl.h" +#include "shci.h" +#include "stm32wbxx.h" + +/* Private typedef -----------------------------------------------------------*/ +/* Private defines -----------------------------------------------------------*/ +/* Private macros ------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +/* Global variables ----------------------------------------------------------*/ +/* Private function prototypes -----------------------------------------------*/ +/* Local Functions Definition ------------------------------------------------------*/ +/* Public Functions Definition ------------------------------------------------------*/ + +/** + * C2 COMMAND + * These commands are sent to the CPU2 + */ +uint8_t SHCI_C2_FUS_GetState( SHCI_FUS_GetState_ErrorCode_t *p_error_code ) +{ + /** + * Buffer is large enough to hold command complete with payload + */ + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE + 1]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send( SHCI_OPCODE_C2_FUS_GET_STATE, + 0, + 0, + p_rsp ); + + if(p_error_code != 0) + { + *p_error_code = (SHCI_FUS_GetState_ErrorCode_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[1]); + } + + return (((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_FUS_FwUpgrade( uint32_t fw_src_add, uint32_t fw_dest_add ) +{ + /** + * TL_BLEEVT_CC_BUFFER_SIZE is 16 bytes so it is large enough to hold the 8 bytes of command parameters + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + uint32_t *p_cmd; + uint8_t cmd_length; + + p_cmd = (uint32_t*)local_buffer; + cmd_length = 0; + + if(fw_src_add != 0) + { + *p_cmd = fw_src_add; + cmd_length += 4; + } + + if(fw_dest_add != 0) + { + *(p_cmd+1) = fw_dest_add; + cmd_length += 4; + } + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send( SHCI_OPCODE_C2_FUS_FW_UPGRADE, + cmd_length, + local_buffer, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_FUS_FwDelete( void ) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send( SHCI_OPCODE_C2_FUS_FW_DELETE, + 0, + 0, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_FUS_UpdateAuthKey( SHCI_C2_FUS_UpdateAuthKey_Cmd_Param_t *pParam ) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send( SHCI_OPCODE_C2_FUS_UPDATE_AUTH_KEY, + sizeof( SHCI_C2_FUS_UpdateAuthKey_Cmd_Param_t ), + (uint8_t*)pParam, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_FUS_LockAuthKey( void ) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send( SHCI_OPCODE_C2_FUS_LOCK_AUTH_KEY, + 0, + 0, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_FUS_StoreUsrKey( SHCI_C2_FUS_StoreUsrKey_Cmd_Param_t *pParam, uint8_t *p_key_index ) +{ + /** + * Buffer is large enough to hold command complete with payload + */ + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE + 1]; + TL_EvtPacket_t * p_rsp; + uint8_t local_payload_len; + + if(pParam->KeyType == KEYTYPE_ENCRYPTED) + { + /** + * When the key is encrypted, the 12 bytes IV Key is included in the payload as well + * The IV key is always 12 bytes + */ + local_payload_len = pParam->KeySize + 2 + 12; + } + else + { + local_payload_len = pParam->KeySize + 2; + } + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send( SHCI_OPCODE_C2_FUS_STORE_USR_KEY, + local_payload_len , + (uint8_t*)pParam, + p_rsp ); + + *p_key_index = (((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[1]); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_FUS_LoadUsrKey( uint8_t key_index ) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + local_buffer[0] = key_index; + + shci_send( SHCI_OPCODE_C2_FUS_LOAD_USR_KEY, + 1, + local_buffer, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_FUS_StartWs( void ) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send( SHCI_OPCODE_C2_FUS_START_WS, + 0, + 0, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_FUS_LockUsrKey( uint8_t key_index ) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + local_buffer[0] = key_index; + + shci_send( SHCI_OPCODE_C2_FUS_LOCK_USR_KEY, + 1, + local_buffer, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_FUS_UnloadUsrKey( uint8_t key_index ) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + local_buffer[0] = key_index; + + shci_send( SHCI_OPCODE_C2_FUS_UNLOAD_USR_KEY, + 1, + local_buffer, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_FUS_ActivateAntiRollback( void ) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send( SHCI_OPCODE_C2_FUS_ACTIVATE_ANTIROLLBACK, + 0, + 0, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_BLE_Init( SHCI_C2_Ble_Init_Cmd_Packet_t *pCmdPacket ) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send( SHCI_OPCODE_C2_BLE_INIT, + sizeof( SHCI_C2_Ble_Init_Cmd_Param_t ), + (uint8_t*)&pCmdPacket->Param, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_THREAD_Init( void ) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send( SHCI_OPCODE_C2_THREAD_INIT, + 0, + 0, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_LLDTESTS_Init( uint8_t param_size, uint8_t * p_param ) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send( SHCI_OPCODE_C2_LLD_TESTS_INIT, + param_size, + p_param, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_BLE_LLD_Init( uint8_t param_size, uint8_t * p_param ) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send( SHCI_OPCODE_C2_BLE_LLD_INIT, + param_size, + p_param, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_ZIGBEE_Init( void ) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send( SHCI_OPCODE_C2_ZIGBEE_INIT, + 0, + 0, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_DEBUG_Init( SHCI_C2_DEBUG_Init_Cmd_Packet_t *pCmdPacket ) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send( SHCI_OPCODE_C2_DEBUG_INIT, + sizeof( SHCI_C2_DEBUG_init_Cmd_Param_t ), + (uint8_t*)&pCmdPacket->Param, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_FLASH_EraseActivity( SHCI_EraseActivity_t erase_activity ) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + local_buffer[0] = erase_activity; + + shci_send( SHCI_OPCODE_C2_FLASH_ERASE_ACTIVITY, + 1, + local_buffer, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_CONCURRENT_SetMode( SHCI_C2_CONCURRENT_Mode_Param_t Mode ) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + local_buffer[0] = Mode; + + shci_send( SHCI_OPCODE_C2_CONCURRENT_SET_MODE, + 1, + local_buffer, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_CONCURRENT_GetNextBleEvtTime( SHCI_C2_CONCURRENT_GetNextBleEvtTime_Param_t *pParam ) +{ + /** + * Buffer is large enough to hold command complete with payload + */ + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE+4]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send( SHCI_OPCODE_C2_CONCURRENT_GET_NEXT_BLE_EVT_TIME, + 0, + 0, + p_rsp ); + + memcpy((void*)&(pParam->relative_time), (void*)&((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[1], sizeof(pParam->relative_time)); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_CONCURRENT_EnableNext_802154_EvtNotification( void ) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send( SHCI_OPCODE_C2_CONCURRENT_ENABLE_NEXT_802154_EVT_NOTIFICATION, + 0, + 0, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_FLASH_StoreData( SHCI_C2_FLASH_Ip_t Ip ) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + local_buffer[0] = Ip; + + shci_send( SHCI_OPCODE_C2_FLASH_STORE_DATA, + 1, + local_buffer, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_FLASH_EraseData( SHCI_C2_FLASH_Ip_t Ip ) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + local_buffer[0] = Ip; + + shci_send( SHCI_OPCODE_C2_FLASH_ERASE_DATA, + 1, + local_buffer, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_RADIO_AllowLowPower( SHCI_C2_FLASH_Ip_t Ip,uint8_t FlagRadioLowPowerOn) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + local_buffer[0] = Ip; + local_buffer[1] = FlagRadioLowPowerOn; + + shci_send( SHCI_OPCODE_C2_RADIO_ALLOW_LOW_POWER, + 2, + local_buffer, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_MAC_802_15_4_Init( void ) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send( SHCI_OPCODE_C2_MAC_802_15_4_INIT, + 0, + 0, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_Reinit( void ) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send( SHCI_OPCODE_C2_REINIT, + 0, + 0, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_ExtpaConfig(uint32_t gpio_port, uint16_t gpio_pin_number, uint8_t gpio_polarity, uint8_t gpio_status) +{ + /** + * TL_BLEEVT_CC_BUFFER_SIZE is 16 bytes so it is large enough to hold the 8 bytes of command parameters + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + ((SHCI_C2_EXTPA_CONFIG_Cmd_Param_t*)local_buffer)->gpio_port = gpio_port; + ((SHCI_C2_EXTPA_CONFIG_Cmd_Param_t*)local_buffer)->gpio_pin_number = gpio_pin_number; + ((SHCI_C2_EXTPA_CONFIG_Cmd_Param_t*)local_buffer)->gpio_polarity = gpio_polarity; + ((SHCI_C2_EXTPA_CONFIG_Cmd_Param_t*)local_buffer)->gpio_status = gpio_status; + + shci_send( SHCI_OPCODE_C2_EXTPA_CONFIG, + 8, + local_buffer, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_SetFlashActivityControl(SHCI_C2_SET_FLASH_ACTIVITY_CONTROL_Source_t Source) +{ + /** + * TL_BLEEVT_CC_BUFFER_SIZE is 16 bytes so it is large enough to hold the 1 byte of command parameter + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + local_buffer[0] = (uint8_t)Source; + + shci_send( SHCI_OPCODE_C2_SET_FLASH_ACTIVITY_CONTROL, + 1, + local_buffer, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_Config(SHCI_C2_CONFIG_Cmd_Param_t *pCmdPacket) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send( SHCI_OPCODE_C2_CONFIG, + sizeof(SHCI_C2_CONFIG_Cmd_Param_t), + (uint8_t*)pCmdPacket, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_802_15_4_DeInit( void ) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send( SHCI_OPCODE_C2_802_15_4_DEINIT, + 0, + 0, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_SetSystemClock( SHCI_C2_SET_SYSTEM_CLOCK_Cmd_Param_t clockSel ) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + local_buffer[0] = (uint8_t)clockSel; + + shci_send( SHCI_OPCODE_C2_SET_SYSTEM_CLOCK, + 1, + local_buffer, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +/** + * Local System COMMAND + * These commands are NOT sent to the CPU2 + */ + +SHCI_CmdStatus_t SHCI_GetWirelessFwInfo( WirelessFwInfo_t* pWirelessInfo ) +{ + uint32_t ipccdba = 0; + MB_RefTable_t * p_RefTable = NULL; + uint32_t wireless_firmware_version = 0; + uint32_t wireless_firmware_memorySize = 0; + uint32_t wireless_firmware_infoStack = 0; + MB_FUS_DeviceInfoTable_t * p_fus_device_info_table = NULL; + uint32_t fus_version = 0; + uint32_t fus_memorySize = 0; + + ipccdba = READ_BIT( FLASH->IPCCBR, FLASH_IPCCBR_IPCCDBA ); + + /** + * The Device Info Table mapping depends on which firmware is running on CPU2. + * If the FUS is running on CPU2, FUS_DEVICE_INFO_TABLE_VALIDITY_KEYWORD shall be written in the table. + * Otherwise, it means the Wireless Firmware is running on the CPU2 + */ + p_fus_device_info_table = (MB_FUS_DeviceInfoTable_t*)(*(uint32_t*)((ipccdba<<2) + SRAM2A_BASE)); + + if(p_fus_device_info_table->DeviceInfoTableState == FUS_DEVICE_INFO_TABLE_VALIDITY_KEYWORD) + { + /* The FUS is running on CPU2 */ + /** + * Retrieve the WirelessFwInfoTable + * This table is stored in RAM at startup during the TL (transport layer) initialization + */ + wireless_firmware_version = p_fus_device_info_table->WirelessStackVersion; + wireless_firmware_memorySize = p_fus_device_info_table->WirelessStackMemorySize; + wireless_firmware_infoStack = p_fus_device_info_table->WirelessFirmwareBleInfo; + + /** + * Retrieve the FusInfoTable + * This table is stored in RAM at startup during the TL (transport layer) initialization + */ + fus_version = p_fus_device_info_table->FusVersion; + fus_memorySize = p_fus_device_info_table->FusMemorySize; + } + else + { + /* The Wireless Firmware is running on CPU2 */ + p_RefTable = (MB_RefTable_t*)((ipccdba<<2) + SRAM2A_BASE); + + /** + * Retrieve the WirelessFwInfoTable + * This table is stored in RAM at startup during the TL (transport layer) initialization + */ + wireless_firmware_version = p_RefTable->p_device_info_table->WirelessFwInfoTable.Version; + wireless_firmware_memorySize = p_RefTable->p_device_info_table->WirelessFwInfoTable.MemorySize; + wireless_firmware_infoStack = p_RefTable->p_device_info_table->WirelessFwInfoTable.InfoStack; + + /** + * Retrieve the FusInfoTable + * This table is stored in RAM at startup during the TL (transport layer) initialization + */ + fus_version = p_RefTable->p_device_info_table->FusInfoTable.Version; + fus_memorySize = p_RefTable->p_device_info_table->FusInfoTable.MemorySize; + } + + /** + * Retrieve the WirelessFwInfoTable + * This table is stored in RAM at startup during the TL (transport layer) initialization + */ + pWirelessInfo->VersionMajor = ((wireless_firmware_version & INFO_VERSION_MAJOR_MASK) >> INFO_VERSION_MAJOR_OFFSET); + pWirelessInfo->VersionMinor = ((wireless_firmware_version & INFO_VERSION_MINOR_MASK) >> INFO_VERSION_MINOR_OFFSET); + pWirelessInfo->VersionSub = ((wireless_firmware_version & INFO_VERSION_SUB_MASK) >> INFO_VERSION_SUB_OFFSET); + pWirelessInfo->VersionBranch = ((wireless_firmware_version & INFO_VERSION_BRANCH_MASK) >> INFO_VERSION_BRANCH_OFFSET); + pWirelessInfo->VersionReleaseType = ((wireless_firmware_version & INFO_VERSION_TYPE_MASK) >> INFO_VERSION_TYPE_OFFSET); + + pWirelessInfo->MemorySizeSram2B = ((wireless_firmware_memorySize & INFO_SIZE_SRAM2B_MASK) >> INFO_SIZE_SRAM2B_OFFSET); + pWirelessInfo->MemorySizeSram2A = ((wireless_firmware_memorySize & INFO_SIZE_SRAM2A_MASK) >> INFO_SIZE_SRAM2A_OFFSET); + pWirelessInfo->MemorySizeSram1 = ((wireless_firmware_memorySize & INFO_SIZE_SRAM1_MASK) >> INFO_SIZE_SRAM1_OFFSET); + pWirelessInfo->MemorySizeFlash = ((wireless_firmware_memorySize & INFO_SIZE_FLASH_MASK) >> INFO_SIZE_FLASH_OFFSET); + + pWirelessInfo->StackType = ((wireless_firmware_infoStack & INFO_STACK_TYPE_MASK) >> INFO_STACK_TYPE_OFFSET); + + /** + * Retrieve the FusInfoTable + * This table is stored in RAM at startup during the TL (transport layer) initialization + */ + pWirelessInfo->FusVersionMajor = ((fus_version & INFO_VERSION_MAJOR_MASK) >> INFO_VERSION_MAJOR_OFFSET); + pWirelessInfo->FusVersionMinor = ((fus_version & INFO_VERSION_MINOR_MASK) >> INFO_VERSION_MINOR_OFFSET); + pWirelessInfo->FusVersionSub = ((fus_version & INFO_VERSION_SUB_MASK) >> INFO_VERSION_SUB_OFFSET); + + pWirelessInfo->FusMemorySizeSram2B = ((fus_memorySize & INFO_SIZE_SRAM2B_MASK) >> INFO_SIZE_SRAM2B_OFFSET); + pWirelessInfo->FusMemorySizeSram2A = ((fus_memorySize & INFO_SIZE_SRAM2A_MASK) >> INFO_SIZE_SRAM2A_OFFSET); + pWirelessInfo->FusMemorySizeFlash = ((fus_memorySize & INFO_SIZE_FLASH_MASK) >> INFO_SIZE_FLASH_OFFSET); + + return (SHCI_Success); +} +#endif /* STM32WBxx */ diff --git a/src/utility/STM32_WPAN/shci.h b/src/utility/STM32_WPAN/shci.h new file mode 100644 index 00000000..59c6fd46 --- /dev/null +++ b/src/utility/STM32_WPAN/shci.h @@ -0,0 +1,1402 @@ +/** + ****************************************************************************** + * @file shci.h + * @author MCD Application Team + * @brief HCI command for the system channel + ****************************************************************************** + * @attention + * + * Copyright (c) 2018-2021 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ + + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __SHCI_H +#define __SHCI_H + +#ifdef __cplusplus +extern "C" { +#endif + + /* Includes ------------------------------------------------------------------*/ +#include "mbox_def.h" /* Requested to expose the MB_WirelessFwInfoTable_t structure */ + + /* Exported types ------------------------------------------------------------*/ + + /* SYSTEM EVENT */ + typedef enum + { + WIRELESS_FW_RUNNING = 0x00, + FUS_FW_RUNNING = 0x01, + } SHCI_SysEvt_Ready_Rsp_t; + + /* ERROR CODES + * + * These error codes are detected on CPU2 side and are send back to the CPU1 via a system + * notification message. It is up to the application running on CPU1 to manage these errors + * + * These errors can be generated by all layers (low level driver, stack, framework infrastructure, etc..) + */ + typedef enum + { + ERR_BLE_INIT = 0, /* This event is currently not reported by the CPU2 */ + ERR_THREAD_LLD_FATAL_ERROR = 125, /* The LLD driver used on 802_15_4 detected a fatal error */ + ERR_THREAD_UNKNOWN_CMD = 126, /* The command send by the CPU1 to control the Thread stack is unknown */ + ERR_ZIGBEE_UNKNOWN_CMD = 200, /* The command send by the CPU1 to control the Zigbee stack is unknown */ + } SCHI_SystemErrCode_t; + +#define SHCI_EVTCODE ( 0xFF ) +#define SHCI_SUB_EVT_CODE_BASE ( 0x9200 ) + + /** + * THE ORDER SHALL NOT BE CHANGED TO GUARANTEE COMPATIBILITY WITH THE CPU1 DEFINITION + */ + typedef enum + { + SHCI_SUB_EVT_CODE_READY = SHCI_SUB_EVT_CODE_BASE, + SHCI_SUB_EVT_ERROR_NOTIF, + SHCI_SUB_EVT_BLE_NVM_RAM_UPDATE, + SHCI_SUB_EVT_THREAD_NVM_RAM_UPDATE, + SHCI_SUB_EVT_NVM_START_WRITE, + SHCI_SUB_EVT_NVM_END_WRITE, + SHCI_SUB_EVT_NVM_START_ERASE, + SHCI_SUB_EVT_NVM_END_ERASE, + SHCI_SUB_EVT_CODE_CONCURRENT_802154_EVT, + } SHCI_SUB_EVT_CODE_t; + + /** + * SHCI_SUB_EVT_CODE_READY + * This notifies the CPU1 that the CPU2 is now ready to receive commands + * It reports as well which firmware is running on CPU2 : The wireless stack of the FUS (previously named RSS) + */ + typedef PACKED_STRUCT{ + SHCI_SysEvt_Ready_Rsp_t sysevt_ready_rsp; + } SHCI_C2_Ready_Evt_t; + + /** + * SHCI_SUB_EVT_ERROR_NOTIF + * This reports to the CPU1 some error form the CPU2 + */ + typedef PACKED_STRUCT{ + SCHI_SystemErrCode_t errorCode; + } SHCI_C2_ErrorNotif_Evt_t; + + /** + * SHCI_SUB_EVT_BLE_NVM_RAM_UPDATE + * This notifies the CPU1 which part of the BLE NVM RAM has been updated so that only the modified + * section could be written in Flash/NVM + * StartAddress : Start address of the section that has been modified + * Size : Size (in bytes) of the section that has been modified + */ + typedef PACKED_STRUCT{ + uint32_t StartAddress; + uint32_t Size; + } SHCI_C2_BleNvmRamUpdate_Evt_t; + + /** + * SHCI_SUB_EVT_THREAD_NVM_RAM_UPDATE + * This notifies the CPU1 which part of the OT NVM RAM has been updated so that only the modified + * section could be written in Flash/NVM + * StartAddress : Start address of the section that has been modified + * Size : Size (in bytes) of the section that has been modified + */ + typedef PACKED_STRUCT{ + uint32_t StartAddress; + uint32_t Size; + } SHCI_C2_ThreadNvmRamUpdate_Evt_t; + + /** + * SHCI_SUB_EVT_NVM_START_WRITE + * This notifies the CPU1 that the CPU2 has started a write procedure in Flash + * NumberOfWords : The number of 64bits data the CPU2 needs to write in Flash. + * For each 64bits data, the algorithm as described in AN5289 is executed. + * When this number is reported to 0, it means the Number of 64bits to be written + * was unknown when the procedure has started. + * When all data are written, the SHCI_SUB_EVT_NVM_END_WRITE event is reported + */ + typedef PACKED_STRUCT{ + uint32_t NumberOfWords; + } SHCI_C2_NvmStartWrite_Evt_t; + + /** + * SHCI_SUB_EVT_NVM_END_WRITE + * This notifies the CPU1 that the CPU2 has written all expected data in Flash + */ + + /** + * SHCI_SUB_EVT_NVM_START_ERASE + * This notifies the CPU1 that the CPU2 has started a erase procedure in Flash + * NumberOfSectors : The number of sectors the CPU2 needs to erase in Flash. + * For each sector, the algorithm as described in AN5289 is executed. + * When this number is reported to 0, it means the Number of sectors to be erased + * was unknown when the procedure has started. + * When all sectors are erased, the SHCI_SUB_EVT_NVM_END_ERASE event is reported + */ + typedef PACKED_STRUCT{ + uint32_t NumberOfSectors; + } SHCI_C2_NvmStartErase_Evt_t; + + /** + * SHCI_SUB_EVT_NVM_END_ERASE + * This notifies the CPU1 that the CPU2 has erased all expected flash sectors + */ + + /* SYSTEM COMMAND */ + typedef PACKED_STRUCT + { + /** + * MetaData holds : + * 2*32bits for chaining list + * 1*32bits with BLE header (type + Opcode + Length) + */ + uint32_t MetaData[3]; + } SHCI_Header_t; + + typedef enum + { + SHCI_Success = 0x00, + SHCI_UNKNOWN_CMD = 0x01, + SHCI_MEMORY_CAPACITY_EXCEEDED_ERR_CODE= 0x07, + SHCI_ERR_UNSUPPORTED_FEATURE = 0x11, + SHCI_ERR_INVALID_HCI_CMD_PARAMS = 0x12, + SHCI_ERR_INVALID_PARAMS = 0x42, /* only used for release < v1.13.0 */ + SHCI_ERR_INVALID_PARAMS_V2 = 0x92, /* available for release >= v1.13.0 */ + SHCI_FUS_CMD_NOT_SUPPORTED = 0xFF, + } SHCI_CmdStatus_t; + + typedef enum + { + SHCI_8BITS = 0x01, + SHCI_16BITS = 0x02, + SHCI_32BITS = 0x04, + } SHCI_Busw_t; + +#define SHCI_OGF ( 0x3F ) +#define SHCI_OCF_BASE ( 0x50 ) + + /** + * THE ORDER SHALL NOT BE CHANGED TO GUARANTEE COMPATIBILITY WITH THE CPU2 DEFINITION + */ + typedef enum + { + SHCI_OCF_C2_RESERVED1 = SHCI_OCF_BASE, + SHCI_OCF_C2_RESERVED2, + SHCI_OCF_C2_FUS_GET_STATE, + SHCI_OCF_C2_FUS_RESERVED1, + SHCI_OCF_C2_FUS_FW_UPGRADE, + SHCI_OCF_C2_FUS_FW_DELETE, + SHCI_OCF_C2_FUS_UPDATE_AUTH_KEY, + SHCI_OCF_C2_FUS_LOCK_AUTH_KEY, + SHCI_OCF_C2_FUS_STORE_USR_KEY, + SHCI_OCF_C2_FUS_LOAD_USR_KEY, + SHCI_OCF_C2_FUS_START_WS, + SHCI_OCF_C2_FUS_RESERVED2, + SHCI_OCF_C2_FUS_RESERVED3, + SHCI_OCF_C2_FUS_LOCK_USR_KEY, + SHCI_OCF_C2_FUS_UNLOAD_USR_KEY, + SHCI_OCF_C2_FUS_ACTIVATE_ANTIROLLBACK, + SHCI_OCF_C2_FUS_RESERVED7, + SHCI_OCF_C2_FUS_RESERVED8, + SHCI_OCF_C2_FUS_RESERVED9, + SHCI_OCF_C2_FUS_RESERVED10, + SHCI_OCF_C2_FUS_RESERVED11, + SHCI_OCF_C2_FUS_RESERVED12, + SHCI_OCF_C2_BLE_INIT, + SHCI_OCF_C2_THREAD_INIT, + SHCI_OCF_C2_DEBUG_INIT, + SHCI_OCF_C2_FLASH_ERASE_ACTIVITY, + SHCI_OCF_C2_CONCURRENT_SET_MODE, + SHCI_OCF_C2_FLASH_STORE_DATA, + SHCI_OCF_C2_FLASH_ERASE_DATA, + SHCI_OCF_C2_RADIO_ALLOW_LOW_POWER, + SHCI_OCF_C2_MAC_802_15_4_INIT, + SHCI_OCF_C2_REINIT, + SHCI_OCF_C2_ZIGBEE_INIT, + SHCI_OCF_C2_LLD_TESTS_INIT, + SHCI_OCF_C2_EXTPA_CONFIG, + SHCI_OCF_C2_SET_FLASH_ACTIVITY_CONTROL, + SHCI_OCF_C2_BLE_LLD_INIT, + SHCI_OCF_C2_CONFIG, + SHCI_OCF_C2_CONCURRENT_GET_NEXT_BLE_EVT_TIME, + SHCI_OCF_C2_CONCURRENT_ENABLE_NEXT_802154_EVT_NOTIFICATION, + SHCI_OCF_C2_802_15_4_DEINIT, + SHCI_OCF_C2_SET_SYSTEM_CLOCK, + } SHCI_OCF_t; + +#define SHCI_OPCODE_C2_FUS_GET_STATE (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_GET_STATE) +/** No command parameters */ +/** Response parameters*/ +/** It responds a 1 byte value holding FUS State error code when the FUS State value is 0xFF (FUS_STATE_VALUE_ERROR) */ + typedef enum + { + FUS_STATE_ERROR_NO_ERROR = 0x00, + FUS_STATE_ERROR_IMG_NOT_FOUND = 0x01, + FUS_STATE_ERROR_IMG_CORRUPT = 0x02, + FUS_STATE_ERROR_IMG_NOT_AUTHENTIC = 0x03, + FUS_STATE_ERROR_IMG_NOT_ENOUGH_SPACE = 0x04, + FUS_STATE_ERROR_IMAGE_USRABORT = 0x05, + FUS_STATE_ERROR_IMAGE_ERSERROR = 0x06, + FUS_STATE_ERROR_IMAGE_WRTERROR = 0x07, + FUS_STATE_ERROR_AUTH_TAG_ST_NOTFOUND = 0x08, + FUS_STATE_ERROR_AUTH_TAG_CUST_NOTFOUND = 0x09, + FUS_STATE_ERROR_AUTH_KEY_LOCKED = 0x0A, + FUS_STATE_ERROR_FW_ROLLBACK_ERROR = 0x11, + FUS_STATE_ERROR_STATE_NOT_RUNNING = 0xFE, + FUS_STATE_ERROR_ERR_UNKNOWN = 0xFF, + } SHCI_FUS_GetState_ErrorCode_t; + + enum + { + FUS_STATE_VALUE_IDLE = 0x00, + FUS_STATE_VALUE_FW_UPGRD_ONGOING = 0x10, + FUS_STATE_VALUE_FW_UPGRD_ONGOING_END = 0x1F, /* All values between 0x10 and 0x1F has the same meaning */ + FUS_STATE_VALUE_FUS_UPGRD_ONGOING = 0x20, + FUS_STATE_VALUE_FUS_UPGRD_ONGOING_END = 0x2F, /* All values between 0x20 and 0x2F has the same meaning */ + FUS_STATE_VALUE_SERVICE_ONGOING = 0x30, + FUS_STATE_VALUE_SERVICE_ONGOING_END = 0x3F, /* All values between 0x30 and 0x3F has the same meaning */ + FUS_STATE_VALUE_ERROR = 0xFF, + }; + +#define SHCI_OPCODE_C2_FUS_RESERVED1 (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_RESERVED1) +/** No command parameters */ +/** No response parameters*/ + +#define SHCI_OPCODE_C2_FUS_FW_UPGRADE (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_FW_UPGRADE) + /** No structure for command parameters */ + /** No response parameters*/ + +#define SHCI_OPCODE_C2_FUS_FW_DELETE (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_FW_DELETE) +/** No command parameters */ +/** No response parameters*/ + +#define SHCI_OPCODE_C2_FUS_UPDATE_AUTH_KEY (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_UPDATE_AUTH_KEY) + typedef PACKED_STRUCT{ + uint8_t KeySize; + uint8_t KeyData[64]; + } SHCI_C2_FUS_UpdateAuthKey_Cmd_Param_t; + + /** No response parameters*/ + +#define SHCI_OPCODE_C2_FUS_LOCK_AUTH_KEY (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_LOCK_AUTH_KEY) +/** No command parameters */ +/** No response parameters*/ + +#define SHCI_OPCODE_C2_FUS_STORE_USR_KEY (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_STORE_USR_KEY) + /** Command parameters */ + /* List of supported key type */ + enum + { + KEYTYPE_NONE = 0x00, + KEYTYPE_SIMPLE = 0x01, + KEYTYPE_MASTER = 0x02, + KEYTYPE_ENCRYPTED = 0x03, + }; + + /* List of supported key size */ + enum + { + KEYSIZE_16 = 16, + KEYSIZE_32 = 32, + }; + + typedef PACKED_STRUCT{ + uint8_t KeyType; + uint8_t KeySize; + uint8_t KeyData[32 + 12]; + } SHCI_C2_FUS_StoreUsrKey_Cmd_Param_t; + + /** Response parameters*/ + /** It responds a 1 byte value holding the index given for the stored key */ + +#define SHCI_OPCODE_C2_FUS_LOAD_USR_KEY (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_LOAD_USR_KEY) + /** Command parameters */ + /** 1 byte holding the key index value */ + + /** No response parameters*/ + +#define SHCI_OPCODE_C2_FUS_START_WS (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_START_WS) +/** No command parameters */ +/** No response parameters*/ + +#define SHCI_OPCODE_C2_FUS_RESERVED2 (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_RESERVED2) +/** No command parameters */ +/** No response parameters*/ + +#define SHCI_OPCODE_C2_FUS_RESERVED3 (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_RESERVED3) +/** No command parameters */ +/** No response parameters*/ + +#define SHCI_OPCODE_C2_FUS_LOCK_USR_KEY (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_LOCK_USR_KEY) + /** Command parameters */ + /** 1 byte holding the key index value */ + + /** No response parameters*/ + +#define SHCI_OPCODE_C2_FUS_UNLOAD_USR_KEY (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_UNLOAD_USR_KEY) +/** No command parameters */ +/** 1 byte holding the key index value */ + +#define SHCI_OPCODE_C2_FUS_ACTIVATE_ANTIROLLBACK (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_ACTIVATE_ANTIROLLBACK) +/** No command parameters */ +/** No response parameters*/ + +#define SHCI_OPCODE_C2_FUS_RESERVED7 (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_RESERVED7) +/** No command parameters */ +/** No response parameters*/ + +#define SHCI_OPCODE_C2_FUS_RESERVED8 (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_RESERVED8) +/** No command parameters */ +/** No response parameters*/ + +#define SHCI_OPCODE_C2_FUS_RESERVED9 (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_RESERVED9) +/** No command parameters */ +/** No response parameters*/ + +#define SHCI_OPCODE_C2_FUS_RESERVED10 (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_RESERVED10) +/** No command parameters */ +/** No response parameters*/ + +#define SHCI_OPCODE_C2_FUS_RESERVED11 (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_RESERVED11) +/** No command parameters */ +/** No response parameters*/ + +#define SHCI_OPCODE_C2_FUS_RESERVED12 (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_RESERVED12) +/** No command parameters */ +/** No response parameters*/ + +#define SHCI_OPCODE_C2_BLE_INIT (( SHCI_OGF << 10) + SHCI_OCF_C2_BLE_INIT) + /** THE ORDER SHALL NOT BE CHANGED */ + typedef PACKED_STRUCT{ + uint8_t* pBleBufferAddress; /**< NOT USED - shall be set to 0 */ + uint32_t BleBufferSize; /**< NOT USED - shall be set to 0 */ + + /** + * NumAttrRecord + * Maximum number of attribute records related to all the required characteristics (excluding the services) + * that can be stored in the GATT database, for the specific BLE user application. + * For each characteristic, the number of attribute records goes from two to five depending on the characteristic properties: + * - minimum of two (one for declaration and one for the value) + * - add one more record for each additional property: notify or indicate, broadcast, extended property. + * The total calculated value must be increased by 9, due to the records related to the standard attribute profile and + * GAP service characteristics, and automatically added when initializing GATT and GAP layers + * - Min value: <number of user attributes> + 9 + * - Max value: depending on the GATT database defined by user application + */ + uint16_t NumAttrRecord; + + /** + * NumAttrServ + * Defines the maximum number of services that can be stored in the GATT database. Note that the GAP and GATT services + * are automatically added at initialization so this parameter must be the number of user services increased by two. + * - Min value: <number of user service> + 2 + * - Max value: depending GATT database defined by user application + */ + uint16_t NumAttrServ; + + /** + * AttrValueArrSize + * NOTE: This parameter is ignored by the CPU2 when the parameter "Options" is set to "LL_only" ( see Options description in that structure ) + * + * Size of the storage area for the attribute values. + * Each characteristic contributes to the attrValueArrSize value as follows: + * - Characteristic value length plus: + * + 5 bytes if characteristic UUID is 16 bits + * + 19 bytes if characteristic UUID is 128 bits + * + 2 bytes if characteristic has a server configuration descriptor + * + 2 bytes * NumOfLinks if the characteristic has a client configuration descriptor + * + 2 bytes if the characteristic has extended properties + * Each descriptor contributes to the attrValueArrSize value as follows: + * - Descriptor length + */ + uint16_t AttrValueArrSize; + + /** + * NumOfLinks + * Maximum number of BLE links supported + * - Min value: 1 + * - Max value: 8 + */ + uint8_t NumOfLinks; + + /** + * ExtendedPacketLengthEnable + * Disable/enable the extended packet length BLE 5.0 feature + * - Disable: 0 + * - Enable: 1 + */ + uint8_t ExtendedPacketLengthEnable; + + /** + * PrWriteListSize + * NOTE: This parameter is ignored by the CPU2 when the parameter "Options" is set to "LL_only" ( see Options description in that structure ) + * + * Maximum number of supported "prepare write request" + * - Min value: given by the macro DEFAULT_PREP_WRITE_LIST_SIZE + * - Max value: a value higher than the minimum required can be specified, but it is not recommended + */ + uint8_t PrWriteListSize; + + /** + * MblockCount + * NOTE: This parameter is overwritten by the CPU2 with an hardcoded optimal value when the parameter "Options" is set to "LL_only" + * ( see Options description in that structure ) + * + * Number of allocated memory blocks for the BLE stack + * - Min value: given by the macro MBLOCKS_CALC + * - Max value: a higher value can improve data throughput performance, but uses more memory + */ + uint8_t MblockCount; + + /** + * AttMtu + * NOTE: This parameter is ignored by the CPU2 when the parameter "Options" is set to "LL_only" ( see Options description in that structure ) + * + * Maximum ATT MTU size supported + * - Min value: 23 + * - Max value: 512 + */ + uint16_t AttMtu; + + /** + * PeripheralSca + * The sleep clock accuracy (ppm value) that used in BLE connected Peripheral mode to calculate the window widening + * (in combination with the sleep clock accuracy sent by master in CONNECT_REQ PDU), + * refer to BLE 5.0 specifications - Vol 6 - Part B - chap 4.5.7 and 4.2.2 + * - Min value: 0 + * - Max value: 500 (worst possible admitted by specification) + */ + uint16_t PeripheralSca; + + /** + * CentralSca + * The sleep clock accuracy handled in Central mode. It is used to determine the connection and advertising events timing. + * It is transmitted to the slave in CONNEC_REQ PDU used by the slave to calculate the window widening, + * see PeripheralSca and Bluetooth Core Specification v5.0 Vol 6 - Part B - chap 4.5.7 and 4.2.2 + * Possible values: + * - 251 ppm to 500 ppm: 0 + * - 151 ppm to 250 ppm: 1 + * - 101 ppm to 150 ppm: 2 + * - 76 ppm to 100 ppm: 3 + * - 51 ppm to 75 ppm: 4 + * - 31 ppm to 50 ppm: 5 + * - 21 ppm to 30 ppm: 6 + * - 0 ppm to 20 ppm: 7 + */ + uint8_t CentralSca; + + /** + * LsSource + * Some information for Low speed clock mapped in bits field + * - bit 0: 1: Calibration for the RF system wakeup clock source 0: No calibration for the RF system wakeup clock source + * - bit 1: 1: STM32W5M Module device 0: Other devices as STM32WBxx SOC, STM32WB1M module + * - bit 2: 1: HSE/1024 Clock config 0: LSE Clock config + */ + uint8_t LsSource; + + /** + * MaxConnEventLength + * This parameter determines the maximum duration of a slave connection event. When this duration is reached the slave closes + * the current connections event (whatever is the CE_length parameter specified by the master in HCI_CREATE_CONNECTION HCI command), + * expressed in units of 625/256 us (~2.44 us) + * - Min value: 0 (if 0 is specified, the master and slave perform only a single TX-RX exchange per connection event) + * - Max value: 1638400 (4000 ms). A higher value can be specified (max 0xFFFFFFFF) but results in a maximum connection time + * of 4000 ms as specified. In this case the parameter is not applied, and the predicted CE length calculated on slave is not shortened + */ + uint32_t MaxConnEventLength; + + /** + * HsStartupTime + * Startup time of the high speed (16 or 32 MHz) crystal oscillator in units of 625/256 us (~2.44 us). + * - Min value: 0 + * - Max value: 820 (~2 ms). A higher value can be specified, but the value that implemented in stack is forced to ~2 ms + */ + uint16_t HsStartupTime; + + /** + * ViterbiEnable + * Viterbi implementation in BLE LL reception. + * - 0: Enable + * - 1: Disable + */ + uint8_t ViterbiEnable; + + /** + * Options flags + * - bit 0: 1: LL only 0: LL + host + * - bit 1: 1: no service change desc. 0: with service change desc. + * - bit 2: 1: device name Read-Only 0: device name R/W + * - bit 3: 1: extended advertizing supported 0: extended advertizing not supported + * - bit 4: 1: CS Algo #2 supported 0: CS Algo #2 not supported + * - bit 5: 1: Reduced GATT database in NVM 0: Full GATT database in NVM + * - bit 6: 1: GATT caching is used 0: GATT caching is not used + * - bit 7: 1: LE Power Class 1 0: LE Power Class 2-3 + * - other bits: complete with Options_extension flag + */ + uint8_t Options; + + /** + * HwVersion + * Reserved for future use - shall be set to 0 + */ + uint8_t HwVersion; + + /** + * Maximum number of connection-oriented channels in initiator mode. + * Range: 0 .. 64 + */ + uint8_t max_coc_initiator_nbr; + + /** + * Minimum transmit power in dBm supported by the Controller. + * Range: -127 .. 20 + */ + int8_t min_tx_power; + + /** + * Maximum transmit power in dBm supported by the Controller. + * Range: -127 .. 20 + */ + int8_t max_tx_power; + + /** + * RX model configuration + * - bit 0: 1: agc_rssi model improved vs RF blockers 0: Legacy agc_rssi model + * - other bits: reserved ( shall be set to 0) + */ + uint8_t rx_model_config; + + /* Maximum number of advertising sets. + * Range: 1 .. 8 with limitation: + * This parameter is linked to max_adv_data_len such as both compliant with allocated Total memory computed with BLE_EXT_ADV_BUFFER_SIZE based + * on Max Extended advertising configuration supported. + * This parameter is considered by the CPU2 when Options has SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV flag set + */ + uint8_t max_adv_set_nbr; + + /* Maximum advertising data length (in bytes) + * Range: 31 .. 1650 with limitation: + * This parameter is linked to max_adv_set_nbr such as both compliant with allocated Total memory computed with BLE_EXT_ADV_BUFFER_SIZE based + * on Max Extended advertising configuration supported. + * This parameter is considered by the CPU2 when Options has SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV flag set + */ + uint16_t max_adv_data_len; + + /* RF TX Path Compensation Value (16-bit signed integer). Units: 0.1 dB. + * Range: -1280 .. 1280 + */ + int16_t tx_path_compens; + + /* RF RX Path Compensation Value (16-bit signed integer). Units: 0.1 dB. + * Range: -1280 .. 1280 + */ + int16_t rx_path_compens; + + /* BLE core specification version (8-bit unsigned integer). + * values as: 11(5.2), 12(5.3), 13(5.4) + */ + uint8_t ble_core_version; + + /** + * Options flags extension + * - bit 0: 1: appearance Writable 0: appearance Read-Only + * - bit 1: 1: Enhanced ATT supported 0: Enhanced ATT not supported + * - other bits: reserved ( shall be set to 0) + */ + uint8_t Options_extension; + + } SHCI_C2_Ble_Init_Cmd_Param_t; + + typedef PACKED_STRUCT{ + SHCI_Header_t Header; /** Does not need to be initialized by the user */ + SHCI_C2_Ble_Init_Cmd_Param_t Param; + } SHCI_C2_Ble_Init_Cmd_Packet_t; + + /** + * Options + * Each definition below may be added together to build the Options value + * WARNING : Only one definition per bit shall be added to build the Options value + */ +#define SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY (1<<0) +#define SHCI_C2_BLE_INIT_OPTIONS_LL_HOST (0<<0) + +#define SHCI_C2_BLE_INIT_OPTIONS_NO_SVC_CHANGE_DESC (1<<1) +#define SHCI_C2_BLE_INIT_OPTIONS_WITH_SVC_CHANGE_DESC (0<<1) + +#define SHCI_C2_BLE_INIT_OPTIONS_DEVICE_NAME_RO (1<<2) +#define SHCI_C2_BLE_INIT_OPTIONS_DEVICE_NAME_RW (0<<2) + +#define SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV (1<<3) +#define SHCI_C2_BLE_INIT_OPTIONS_NO_EXT_ADV (0<<3) + +#define SHCI_C2_BLE_INIT_OPTIONS_CS_ALGO2 (1<<4) +#define SHCI_C2_BLE_INIT_OPTIONS_NO_CS_ALGO2 (0<<4) + +#define SHCI_C2_BLE_INIT_OPTIONS_REDUC_GATTDB_NVM (1<<5) +#define SHCI_C2_BLE_INIT_OPTIONS_FULL_GATTDB_NVM (0<<5) + +#define SHCI_C2_BLE_INIT_OPTIONS_GATT_CACHING_USED (1<<6) +#define SHCI_C2_BLE_INIT_OPTIONS_GATT_CACHING_NOTUSED (0<<6) + +#define SHCI_C2_BLE_INIT_OPTIONS_POWER_CLASS_1 (1<<7) +#define SHCI_C2_BLE_INIT_OPTIONS_POWER_CLASS_2_3 (0<<7) + + /** + * Options extension + * Each definition below may be added together to build the Options value + * WARNING : Only one definition per bit shall be added to build the Options value + */ +#define SHCI_C2_BLE_INIT_OPTIONS_APPEARANCE_WRITABLE (1<<0) +#define SHCI_C2_BLE_INIT_OPTIONS_APPEARANCE_READONLY (0<<0) + +#define SHCI_C2_BLE_INIT_OPTIONS_ENHANCED_ATT_SUPPORTED (1<<1) +#define SHCI_C2_BLE_INIT_OPTIONS_ENHANCED_ATT_NOTSUPPORTED (0<<1) + + /** + * RX models configuration + */ +#define SHCI_C2_BLE_INIT_RX_MODEL_AGC_RSSI_LEGACY (0<<0) +#define SHCI_C2_BLE_INIT_RX_MODEL_AGC_RSSI_BLOCKER (1<<0) + + /** + * BLE core version + */ +#define SHCI_C2_BLE_INIT_BLE_CORE_5_2 11 +#define SHCI_C2_BLE_INIT_BLE_CORE_5_3 12 +#define SHCI_C2_BLE_INIT_BLE_CORE_5_4 13 + + /** + * LsSource information + */ +#define SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB (0<<0) +#define SHCI_C2_BLE_INIT_CFG_BLE_LS_CALIB (1<<0) +#define SHCI_C2_BLE_INIT_CFG_BLE_LS_OTHER_DEV (0<<1) +#define SHCI_C2_BLE_INIT_CFG_BLE_LS_MOD5MM_DEV (1<<1) +#define SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE (0<<2) +#define SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_HSE_1024 (1<<2) + +#define SHCI_OPCODE_C2_THREAD_INIT (( SHCI_OGF << 10) + SHCI_OCF_C2_THREAD_INIT) +/** No command parameters */ +/** No response parameters*/ + +#define SHCI_OPCODE_C2_DEBUG_INIT (( SHCI_OGF << 10) + SHCI_OCF_C2_DEBUG_INIT) + /** Command parameters */ + typedef PACKED_STRUCT + { + uint8_t thread_config; + uint8_t ble_config; + uint8_t mac_802_15_4_config; + uint8_t zigbee_config; + } SHCI_C2_DEBUG_TracesConfig_t; + + typedef PACKED_STRUCT + { + uint8_t ble_dtb_cfg; + /** + * sys_dbg_cfg1 options flag + * - bit 0: 0: IP BLE core in LP mode 1: IP BLE core in run mode (no LP supported) + * - bit 1: 0: CPU2 STOP mode Enable 1: CPU2 STOP mode Disable + * - bit [2-7]: bits reserved ( shall be set to 0) + */ + uint8_t sys_dbg_cfg1; + uint8_t reserved[2]; + uint16_t STBY_DebugGpioaPinList; + uint16_t STBY_DebugGpiobPinList; + uint16_t STBY_DebugGpiocPinList; + uint16_t STBY_DtbGpioaPinList; + uint16_t STBY_DtbGpiobPinList; + } SHCI_C2_DEBUG_GeneralConfig_t; + + typedef PACKED_STRUCT{ + uint8_t *pGpioConfig; + uint8_t *pTracesConfig; + uint8_t *pGeneralConfig; + uint8_t GpioConfigSize; + uint8_t TracesConfigSize; + uint8_t GeneralConfigSize; + } SHCI_C2_DEBUG_init_Cmd_Param_t; + + typedef PACKED_STRUCT{ + SHCI_Header_t Header; /** Does not need to be initialized by the user */ + SHCI_C2_DEBUG_init_Cmd_Param_t Param; + } SHCI_C2_DEBUG_Init_Cmd_Packet_t; + /** No response parameters*/ + + /** + * Options + * Each definition below may be added together to build the Options value + * WARNING : Only one definition per bit shall be added to build the Options value + */ +#define SHCI_C2_DEBUG_OPTIONS_IPCORE_LP (0<<0) +#define SHCI_C2_DEBUG_OPTIONS_IPCORE_NO_LP (1<<0) + +#define SHCI_C2_DEBUG_OPTIONS_CPU2_STOP_EN (0<<1) +#define SHCI_C2_DEBUG_OPTIONS_CPU2_STOP_DIS (1<<1) + + +#define SHCI_OPCODE_C2_FLASH_ERASE_ACTIVITY (( SHCI_OGF << 10) + SHCI_OCF_C2_FLASH_ERASE_ACTIVITY) + /** Command parameters */ + typedef enum + { + ERASE_ACTIVITY_OFF = 0x00, + ERASE_ACTIVITY_ON = 0x01, + } SHCI_EraseActivity_t; + + /** No response parameters*/ + +#define SHCI_OPCODE_C2_CONCURRENT_SET_MODE (( SHCI_OGF << 10) + SHCI_OCF_C2_CONCURRENT_SET_MODE) +/** command parameters */ + typedef enum + { + BLE_ENABLE, + THREAD_ENABLE, + ZIGBEE_ENABLE, + MAC_ENABLE, + } SHCI_C2_CONCURRENT_Mode_Param_t; + /** No response parameters*/ + +#define SHCI_OPCODE_C2_CONCURRENT_GET_NEXT_BLE_EVT_TIME (( SHCI_OGF << 10) + SHCI_OCF_C2_CONCURRENT_GET_NEXT_BLE_EVT_TIME) +/** command parameters */ + typedef PACKED_STRUCT + { + uint32_t relative_time; + } SHCI_C2_CONCURRENT_GetNextBleEvtTime_Param_t; + /** No response parameters*/ + +#define SHCI_OPCODE_C2_CONCURRENT_ENABLE_NEXT_802154_EVT_NOTIFICATION (( SHCI_OGF << 10) + SHCI_OCF_C2_CONCURRENT_ENABLE_NEXT_802154_EVT_NOTIFICATION) + /** No command parameters */ + /** No response parameters*/ + +#define SHCI_OPCODE_C2_FLASH_STORE_DATA (( SHCI_OGF << 10) + SHCI_OCF_C2_FLASH_STORE_DATA) +#define SHCI_OPCODE_C2_FLASH_ERASE_DATA (( SHCI_OGF << 10) + SHCI_OCF_C2_FLASH_ERASE_DATA) +/** command parameters */ + typedef enum + { + BLE_IP, + THREAD_IP, + ZIGBEE_IP, + } SHCI_C2_FLASH_Ip_t; + /** No response parameters*/ + +#define SHCI_OPCODE_C2_RADIO_ALLOW_LOW_POWER (( SHCI_OGF << 10) + SHCI_OCF_C2_RADIO_ALLOW_LOW_POWER) + +#define SHCI_OPCODE_C2_MAC_802_15_4_INIT (( SHCI_OGF << 10) + SHCI_OCF_C2_MAC_802_15_4_INIT) + +#define SHCI_OPCODE_C2_REINIT (( SHCI_OGF << 10) + SHCI_OCF_C2_REINIT) + +#define SHCI_OPCODE_C2_ZIGBEE_INIT (( SHCI_OGF << 10) + SHCI_OCF_C2_ZIGBEE_INIT) + +#define SHCI_OPCODE_C2_LLD_TESTS_INIT (( SHCI_OGF << 10) + SHCI_OCF_C2_LLD_TESTS_INIT) + +#define SHCI_OPCODE_C2_BLE_LLD_INIT (( SHCI_OGF << 10) + SHCI_OCF_C2_BLE_LLD_INIT) + +#define SHCI_OPCODE_C2_EXTPA_CONFIG (( SHCI_OGF << 10) + SHCI_OCF_C2_EXTPA_CONFIG) + /** Command parameters */ + enum + { + EXT_PA_ENABLED_LOW, + EXT_PA_ENABLED_HIGH, + }/* gpio_polarity */; + + enum + { + EXT_PA_DISABLED, + EXT_PA_ENABLED, + }/* gpio_status */; + + typedef PACKED_STRUCT{ + uint32_t gpio_port; + uint16_t gpio_pin_number; + uint8_t gpio_polarity; + uint8_t gpio_status; + } SHCI_C2_EXTPA_CONFIG_Cmd_Param_t; + + /** No response parameters*/ + +#define SHCI_OPCODE_C2_SET_FLASH_ACTIVITY_CONTROL (( SHCI_OGF << 10) + SHCI_OCF_C2_SET_FLASH_ACTIVITY_CONTROL) + /** Command parameters */ + typedef enum + { + FLASH_ACTIVITY_CONTROL_PES, + FLASH_ACTIVITY_CONTROL_SEM7, + }SHCI_C2_SET_FLASH_ACTIVITY_CONTROL_Source_t; + + /** No response parameters*/ + +#define SHCI_OPCODE_C2_CONFIG (( SHCI_OGF << 10) + SHCI_OCF_C2_CONFIG) + + /** Command parameters */ + typedef PACKED_STRUCT{ + uint8_t PayloadCmdSize; + uint8_t Config1; + uint8_t EvtMask1; + uint8_t Spare1; + uint32_t BleNvmRamAddress; + uint32_t ThreadNvmRamAddress; + uint16_t RevisionID; + uint16_t DeviceID; + } SHCI_C2_CONFIG_Cmd_Param_t; + +#define SHCI_OPCODE_C2_802_15_4_DEINIT (( SHCI_OGF << 10) + SHCI_OCF_C2_802_15_4_DEINIT) + +#define SHCI_OPCODE_C2_SET_SYSTEM_CLOCK (( SHCI_OGF << 10) + SHCI_OCF_C2_SET_SYSTEM_CLOCK) + /** Command parameters */ + typedef enum + { + SET_SYSTEM_CLOCK_HSE_TO_PLL, + SET_SYSTEM_CLOCK_PLL_ON_TO_HSE, + SET_SYSTEM_CLOCK_PLL_OFF_TO_HSE, + }SHCI_C2_SET_SYSTEM_CLOCK_Cmd_Param_t; + +/** + * PayloadCmdSize + * Value that shall be used + */ +#define SHCI_C2_CONFIG_PAYLOAD_CMD_SIZE (sizeof(SHCI_C2_CONFIG_Cmd_Param_t) - 1) + +/** + * Device revision ID + */ +#define SHCI_C2_CONFIG_CUT2_0 (0x2000) +#define SHCI_C2_CONFIG_CUT2_1 (0x2001) +#define SHCI_C2_CONFIG_CUT2_2 (0x2003) + +/** + * Device ID + */ +#define SHCI_C2_CONFIG_STM32WB55xx (0x495) +#define SHCI_C2_CONFIG_STM32WB15xx (0x494) + +/** + * Config1 + * Each definition below may be added together to build the Config1 value + * WARNING : Only one definition per bit shall be added to build the Config1 value + */ +#define SHCI_C2_CONFIG_CONFIG1_BIT0_BLE_NVM_DATA_TO_INTERNAL_FLASH (0<<0) +#define SHCI_C2_CONFIG_CONFIG1_BIT0_BLE_NVM_DATA_TO_SRAM (1<<0) +#define SHCI_C2_CONFIG_CONFIG1_BIT1_THREAD_NVM_DATA_TO_INTERNAL_FLASH (0<<1) +#define SHCI_C2_CONFIG_CONFIG1_BIT1_THREAD_NVM_DATA_TO_SRAM (1<<1) +#define SHCI_C2_CONFIG_CONFIG1_BIT2_SET_EUI64_FORMAT (1<<2) + +/** + * EvtMask1 + * Each definition below may be added together to build the EvtMask1 value + */ +#define SHCI_C2_CONFIG_EVTMASK1_BIT0_ERROR_NOTIF_ENABLE (1<<0) +#define SHCI_C2_CONFIG_EVTMASK1_BIT1_BLE_NVM_RAM_UPDATE_ENABLE (1<<1) +#define SHCI_C2_CONFIG_EVTMASK1_BIT2_THREAD_NVM_RAM_UPDATE_ENABLE (1<<2) +#define SHCI_C2_CONFIG_EVTMASK1_BIT3_NVM_START_WRITE_ENABLE (1<<3) +#define SHCI_C2_CONFIG_EVTMASK1_BIT4_NVM_END_WRITE_ENABLE (1<<4) +#define SHCI_C2_CONFIG_EVTMASK1_BIT5_NVM_START_ERASE_ENABLE (1<<5) +#define SHCI_C2_CONFIG_EVTMASK1_BIT6_NVM_END_ERASE_ENABLE (1<<6) + +/** + * BleNvmRamAddress + * The buffer shall have a size of BLE_NVM_SRAM_SIZE number of 32bits + * The buffer shall be allocated in SRAM2 + */ +#define BLE_NVM_SRAM_SIZE (507) + +/** + * ThreadNvmRamAddress + * The buffer shall have a size of THREAD_NVM_SRAM_SIZE number of 32bits + * The buffer shall be allocated in SRAM2 + */ +#define THREAD_NVM_SRAM_SIZE (1016) + + + /** No response parameters*/ + + /* Exported type --------------------------------------------------------*/ +#define FUS_DEVICE_INFO_TABLE_VALIDITY_KEYWORD (0xA94656B9) + +/* + * At startup, the information relative to the wireless binary are stored in RAM through a structure defined by + * MB_WirelessFwInfoTable_t.This structure contains 4 fields (Version,MemorySize, Stack_info and a reserved part) + * each of those coded on 32 bits as shown on the table below: + * + * + * |7 |6 |5 |4 |3 |2 |1 |0 |7 |6 |5 |4 |3 |2 |1 |0 |7 |6 |5 |4 |3 |2 |1 |0 |7 |6 |5 |4 |3 |2 |1 |0 | + * ------------------------------------------------------------------------------------------------- + * Version | Major version | Minor version | Sub version | Branch |ReleaseType| + * ------------------------------------------------------------------------------------------------- + * MemorySize | SRAM2B (kB) | SRAM2A (kB) | SRAM1 (kB) | FLASH (4kb) | + * ------------------------------------------------------------------------------------------------- + * Info stack | Reserved | Reserved | Reserved | Type (MAC,Thread,BLE) | + * ------------------------------------------------------------------------------------------------- + * Reserved | Reserved | Reserved | Reserved | Reserved | + * ------------------------------------------------------------------------------------------------- + * + */ + +/* Field Version */ +#define INFO_VERSION_MAJOR_OFFSET 24 +#define INFO_VERSION_MAJOR_MASK 0xff000000 +#define INFO_VERSION_MINOR_OFFSET 16 +#define INFO_VERSION_MINOR_MASK 0x00ff0000 +#define INFO_VERSION_SUB_OFFSET 8 +#define INFO_VERSION_SUB_MASK 0x0000ff00 +#define INFO_VERSION_BRANCH_OFFSET 4 +#define INFO_VERSION_BRANCH_MASK 0x0000000f0 +#define INFO_VERSION_TYPE_OFFSET 0 +#define INFO_VERSION_TYPE_MASK 0x00000000f + +#define INFO_VERSION_TYPE_RELEASE 1 + +/* Field Memory */ +#define INFO_SIZE_SRAM2B_OFFSET 24 +#define INFO_SIZE_SRAM2B_MASK 0xff000000 +#define INFO_SIZE_SRAM2A_OFFSET 16 +#define INFO_SIZE_SRAM2A_MASK 0x00ff0000 +#define INFO_SIZE_SRAM1_OFFSET 8 +#define INFO_SIZE_SRAM1_MASK 0x0000ff00 +#define INFO_SIZE_FLASH_OFFSET 0 +#define INFO_SIZE_FLASH_MASK 0x000000ff + +/* Field stack information */ +#define INFO_STACK_TYPE_OFFSET 0 +#define INFO_STACK_TYPE_MASK 0x000000ff +#define INFO_STACK_TYPE_NONE 0 + +#define INFO_STACK_TYPE_BLE_FULL 0x01 +#define INFO_STACK_TYPE_BLE_HCI 0x02 +#define INFO_STACK_TYPE_BLE_LIGHT 0x03 +#define INFO_STACK_TYPE_BLE_BEACON 0x04 +#define INFO_STACK_TYPE_BLE_BASIC 0x05 +#define INFO_STACK_TYPE_BLE_FULL_EXT_ADV 0x06 +#define INFO_STACK_TYPE_BLE_HCI_EXT_ADV 0x07 +#define INFO_STACK_TYPE_THREAD_FTD 0x10 +#define INFO_STACK_TYPE_THREAD_MTD 0x11 +#define INFO_STACK_TYPE_ZIGBEE_FFD 0x30 +#define INFO_STACK_TYPE_ZIGBEE_RFD 0x31 +#define INFO_STACK_TYPE_MAC 0x40 +#define INFO_STACK_TYPE_BLE_THREAD_FTD_STATIC 0x50 +#define INFO_STACK_TYPE_BLE_THREAD_FTD_DYNAMIC 0x51 +#define INFO_STACK_TYPE_BLE_THREAD_LIGHT_DYNAMIC 0x52 +#define INFO_STACK_TYPE_802154_LLD_TESTS 0x60 +#define INFO_STACK_TYPE_802154_PHY_VALID 0x61 +#define INFO_STACK_TYPE_BLE_PHY_VALID 0x62 +#define INFO_STACK_TYPE_BLE_LLD_TESTS 0x63 +#define INFO_STACK_TYPE_BLE_RLV 0x64 +#define INFO_STACK_TYPE_802154_RLV 0x65 +#define INFO_STACK_TYPE_BLE_ZIGBEE_FFD_STATIC 0x70 +#define INFO_STACK_TYPE_BLE_ZIGBEE_RFD_STATIC 0x71 +#define INFO_STACK_TYPE_BLE_ZIGBEE_FFD_DYNAMIC 0x78 +#define INFO_STACK_TYPE_BLE_ZIGBEE_RFD_DYNAMIC 0x79 +#define INFO_STACK_TYPE_RLV 0x80 +#define INFO_STACK_TYPE_BLE_MAC_STATIC 0x90 + +typedef struct { +/** + * Wireless Info + */ + uint8_t VersionMajor; + uint8_t VersionMinor; + uint8_t VersionSub; + uint8_t VersionBranch; + uint8_t VersionReleaseType; + uint8_t MemorySizeSram2B; /*< Multiple of 1K */ + uint8_t MemorySizeSram2A; /*< Multiple of 1K */ + uint8_t MemorySizeSram1; /*< Multiple of 1K */ + uint8_t MemorySizeFlash; /*< Multiple of 4K */ + uint8_t StackType; +/** + * Fus Info + */ + uint8_t FusVersionMajor; + uint8_t FusVersionMinor; + uint8_t FusVersionSub; + uint8_t FusMemorySizeSram2B; /*< Multiple of 1K */ + uint8_t FusMemorySizeSram2A; /*< Multiple of 1K */ + uint8_t FusMemorySizeFlash; /*< Multiple of 4K */ +}WirelessFwInfo_t; + + +/* Exported functions ------------------------------------------------------- */ + + /** + * SHCI_C2_FUS_GetState + * @brief Read the FUS State + * If the user is not interested by the Error code response, a null value may + * be passed as parameter + * + * Note: This command is fully supported only by the FUS. + * When the wireless firmware receives that command, it responds SHCI_FUS_CMD_NOT_SUPPORTED the first time. + * When the wireless firmware receives that command a second time, it reboots the full device with the FUS running on CPU2 + * + * @param p_rsp : return the error code when the FUS State Value = 0xFF + * @retval FUS State Values + */ + uint8_t SHCI_C2_FUS_GetState( SHCI_FUS_GetState_ErrorCode_t *p_rsp ); + + /** + * SHCI_C2_FUS_FwUpgrade + * @brief Request the FUS to install the CPU2 firmware update + * Note: This command is only supported by the FUS. + * + * @param fw_src_add: Address of the firmware image location + * @param fw_dest_add: Address of the firmware destination + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_FUS_FwUpgrade( uint32_t fw_src_add, uint32_t fw_dest_add ); + + /** + * SHCI_C2_FUS_FwDelete + * @brief Delete the wireless stack on CPU2 + * Note: This command is only supported by the FUS. + * + * @param None + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_FUS_FwDelete( void ); + + /** + * SHCI_C2_FUS_UpdateAuthKey + * @brief Request the FUS to update the authentication key + * Note: This command is only supported by the FUS. + * + * @param pCmdPacket + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_FUS_UpdateAuthKey( SHCI_C2_FUS_UpdateAuthKey_Cmd_Param_t *pParam ); + + /** + * SHCI_C2_FUS_LockAuthKey + * @brief Request the FUS to prevent any future update of the authentication key + * Note: This command is only supported by the FUS. + * + * @param None + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_FUS_LockAuthKey( void ); + + /** + * SHCI_C2_FUS_StoreUsrKey + * @brief Request the FUS to store the user key + * Note: This command is supported by both the FUS and the wireless stack. + * + * @param pParam : command parameter + * @param p_key_index : Index allocated by the FUS to the stored key + * + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_FUS_StoreUsrKey( SHCI_C2_FUS_StoreUsrKey_Cmd_Param_t *pParam, uint8_t *p_key_index ); + + /** + * SHCI_C2_FUS_LoadUsrKey + * @brief Request the FUS to load the user key into the AES + * Note: This command is supported by both the FUS and the wireless stack. + * + * @param key_index : index of the user key to load in AES1 + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_FUS_LoadUsrKey( uint8_t key_index ); + + /** + * SHCI_C2_FUS_StartWs + * @brief Request the FUS to reboot on the wireless stack + * Note: This command is only supported by the FUS. + * + * @param None + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_FUS_StartWs( void ); + + /** + * SHCI_C2_FUS_LockUsrKey + * @brief Request the FUS to lock the user key so that it cannot be updated later on + * Note: This command is supported by both the FUS and the wireless stack. + * + * @param key_index : index of the user key to lock + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_FUS_LockUsrKey( uint8_t key_index ); + + /** + * SHCI_C2_FUS_UnloadUsrKey + * @brief Request the FUS to Unload the user key so that the CPU1 may use the AES with another Key + * Note: This command is supported by both the FUS and the wireless stack. + * + * @param key_index : index of the user key to unload + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_FUS_UnloadUsrKey( uint8_t key_index ); + + /** + * SHCI_C2_FUS_ActivateAntiRollback + * @brief Request the FUS to enable the AntiRollback feature so that it is not possible to update the wireless firmware + * with an older version than the current one. + * Note: + * - This command is only supported by the FUS. + * - Once this feature is enabled, it is not possible anymore to disable it. + * + * @param None + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_FUS_ActivateAntiRollback( void ); + + /** + * SHCI_C2_BLE_Init + * @brief Provides parameters and starts the BLE Stack + * + * @param pCmdPacket : Parameters are described SHCI_C2_Ble_Init_Cmd_Packet_t declaration + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_BLE_Init( SHCI_C2_Ble_Init_Cmd_Packet_t *pCmdPacket ); + + /** + * SHCI_C2_THREAD_Init + * @brief Starts the THREAD Stack + * + * @param None + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_THREAD_Init( void ); + + /** + * SHCI_C2_LLDTESTS_Init + * @brief Starts the LLD tests CLI + * + * @param param_size : Nb of bytes + * @param p_param : pointer with data to give from M4 to M0 + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_LLDTESTS_Init( uint8_t param_size, uint8_t * p_param ); + + /** + * SHCI_C2_BLE_LLD_Init + * @brief Starts the LLD tests BLE + * + * @param param_size : Nb of bytes + * @param p_param : pointer with data to give from M4 to M0 + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_BLE_LLD_Init( uint8_t param_size, uint8_t * p_param ); + + /** + * SHCI_C2_ZIGBEE_Init + * @brief Starts the Zigbee Stack + * + * @param None + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_ZIGBEE_Init( void ); + + /** + * SHCI_C2_DEBUG_Init + * @brief Starts the Traces + * + * @param None + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_DEBUG_Init( SHCI_C2_DEBUG_Init_Cmd_Packet_t *pCmdPacket ); + + /** + * SHCI_C2_FLASH_EraseActivity + * @brief Provides the information of the start and the end of a flash erase window on the CPU1 + * The protection will be active until next end of radio event. + * + * @param erase_activity: Start/End of erase activity + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_FLASH_EraseActivity( SHCI_EraseActivity_t erase_activity ); + + /** + * SHCI_C2_CONCURRENT_SetMode + * @brief Enable/Disable Thread on CPU2 (M0+) + * + * @param Mode: BLE or Thread enable flag + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_CONCURRENT_SetMode( SHCI_C2_CONCURRENT_Mode_Param_t Mode ); + + /** + * SHCI_C2_CONCURRENT_GetNextBleEvtTime + * @brief Get the next BLE event date (relative time) + * + * @param Command Packet + * @retval None + */ + SHCI_CmdStatus_t SHCI_C2_CONCURRENT_GetNextBleEvtTime( SHCI_C2_CONCURRENT_GetNextBleEvtTime_Param_t *pParam ); + + /** + * SHCI_C2_CONCURRENT_EnableNext_802154_EvtNotification + * @brief Activate the next 802.15.4 event notification (one shot) + * + * @param None + * @retval None + */ + SHCI_CmdStatus_t SHCI_C2_CONCURRENT_EnableNext_802154_EvtNotification( void ); + + /** + * SHCI_C2_FLASH_StoreData + * @brief Store Data in Flash + * + * @param Ip: BLE or THREAD + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_FLASH_StoreData( SHCI_C2_FLASH_Ip_t Ip ); + + /** + * SHCI_C2_FLASH_EraseData + * @brief Erase Data in Flash + * + * @param Ip: BLE or THREAD + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_FLASH_EraseData( SHCI_C2_FLASH_Ip_t Ip ); + + /** + * SHCI_C2_RADIO_AllowLowPower + * @brief Allow or forbid IP_radio (802_15_4 or BLE) to enter in low power mode. + * + * @param Ip: BLE or 802_15_5 + * @param FlagRadioLowPowerOn: True or false + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_RADIO_AllowLowPower( SHCI_C2_FLASH_Ip_t Ip,uint8_t FlagRadioLowPowerOn); + + + /** + * SHCI_C2_MAC_802_15_4_Init + * @brief Starts the MAC 802.15.4 on M0 + * + * @param None + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_MAC_802_15_4_Init( void ); + + /** + * SHCI_GetWirelessFwInfo + * @brief This function read back the information relative to the wireless binary loaded. + * Refer yourself to MB_WirelessFwInfoTable_t structure to get the significance + * of the different parameters returned. + * @param pWirelessInfo : Pointer to WirelessFwInfo_t. + * + * @retval SHCI_Success + */ + SHCI_CmdStatus_t SHCI_GetWirelessFwInfo( WirelessFwInfo_t* pWirelessInfo ); + + /** + * SHCI_C2_Reinit + * @brief This is required to allow the CPU1 to fake a set C2BOOT when it has already been set. + * In order to fake a C2BOOT, the CPU1 shall : + * - Send SHCI_C2_Reinit() + * - call SEV instruction + * WARNING: + * This function is intended to be used by the SBSFU + * + * @param None + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_Reinit( void ); + + /** + * SHCI_C2_ExtpaConfig + * @brief Send the Ext PA configuration + * When the CPU2 receives the command, it controls the Ext PA as requested by the configuration + * This configures only which IO is used to enable/disable the ExtPA and the associated polarity + * This command has no effect on the other IO that is used to control the mode of the Ext PA (Rx/Tx) + * + * @param gpio_port: GPIOx where x can be (A..F) to select the GPIO peripheral for STM32WBxx family + * @param gpio_pin_number: This parameter can be one of GPIO_PIN_x (= LL_GPIO_PIN_x) where x can be (0..15). + * @param gpio_polarity: This parameter can be either + * - EXT_PA_ENABLED_LOW: ExtPA is enabled when GPIO is low + * - EXT_PA_ENABLED_HIGH: ExtPA is enabled when GPIO is high + * @param gpio_status: This parameter can be either + * - EXT_PA_DISABLED: Stop driving the ExtPA + * - EXT_PA_ENABLED: Drive the ExtPA according to radio activity + * (ON before the Event and OFF at the end of the event) + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_ExtpaConfig(uint32_t gpio_port, uint16_t gpio_pin_number, uint8_t gpio_polarity, uint8_t gpio_status); + + /** + * SHCI_C2_SetFlashActivityControl + * @brief Set the mechanism to be used on CPU2 to prevent the CPU1 to either write or erase in flash + * + * @param Source: It can be one of the following list + * - FLASH_ACTIVITY_CONTROL_PES : The CPU2 set the PES bit to prevent the CPU1 to either read or write in flash + * - FLASH_ACTIVITY_CONTROL_SEM7 : The CPU2 gets the semaphore 7 to prevent the CPU1 to either read or write in flash. + * This requires the CPU1 to first get semaphore 7 before erasing or writing the flash. + * + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_SetFlashActivityControl(SHCI_C2_SET_FLASH_ACTIVITY_CONTROL_Source_t Source); + + /** + * SHCI_C2_Config + * @brief Send the system configuration to the CPU2 + * + * @param pCmdPacket: address of the buffer holding following parameters + * uint8_t PayloadCmdSize : Size of the payload - shall be SHCI_C2_CONFIG_PAYLOAD_CMD_SIZE + * uint8_t Config1 : + * - bit0 : 0 - BLE NVM Data data are flushed in internal secure flash + * 1 - BLE NVM Data are written in SRAM cache pointed by BleNvmRamAddress + * - bit1 : 0 - THREAD NVM Data data are flushed in internal secure flash + * 1 - THREAD NVM Data are written in SRAM cache pointed by ThreadNvmRamAddress + * - bit2 : 0 - Thread EUI64 is set to new (and current) format + * 1 - Thread EUI64 is set to old format + * - bit3 to bit7 : Unused, shall be set to 0 + * uint8_t EvtMask1 : + * When a bit is set to 0, the event is not reported + * bit0 : Asynchronous Event with Sub Evt Code 0x9201 (= SHCI_SUB_EVT_ERROR_NOTIF) + * ... + * bit31 : Asynchronous Event with Sub Evt Code 0x9220 + * uint8_t Spare1 : Unused, shall be set to 0 + * uint32_t BleNvmRamAddress : + * Only considered when Config1.bit0 = 1 + * When set to 0, data are kept in internal SRAM on CPU2 + * Otherwise, data are copied in the cache pointed by BleNvmRamAddress + * The size of the buffer shall be BLE_NVM_SRAM_SIZE (number of 32bits) + * The buffer shall be allocated in SRAM2 + * uint32_t ThreadNvmRamAddress : + * Only considered when Config1.bit1 = 1 + * When set to 0, data are kept in internal SRAM on CPU2 + * Otherwise, data are copied in the cache pointed by ThreadNvmRamAddress + * The size of the buffer shall be THREAD_NVM_SRAM_SIZE (number of 32bits) + * The buffer shall be allocated in SRAM1 + * + * Please check macro definition to be used for this function + * They are defined in this file next to the definition of SHCI_OPCODE_C2_CONFIG + * + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_Config(SHCI_C2_CONFIG_Cmd_Param_t *pCmdPacket); + + /** + * SHCI_C2_802_15_4_DeInit + * @brief Deinit 802.15.4 layer (to be used before entering StandBy mode) + * + * @param None + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_802_15_4_DeInit( void ); + + /** + * SHCI_C2_SetSystemClock + * @brief Request CPU2 to change system clock + * + * @param clockSel: It can be one of the following list + * - SET_SYSTEM_CLOCK_HSE_TO_PLL : CPU2 set system clock to PLL, PLL must be configured and started before. + * - SET_SYSTEM_CLOCK_PLL_ON_TO_HSE : CPU2 set System clock to HSE, PLL is still ON after command execution. + * - SET_SYSTEM_CLOCK_PLL_OFF_TO_HSE : CPU2 set System clock to HSE, PLL is turned OFF after command execution. + * + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_SetSystemClock( SHCI_C2_SET_SYSTEM_CLOCK_Cmd_Param_t clockSel ); + + +#ifdef __cplusplus +} +#endif + +#endif /*__SHCI_H */ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/src/utility/STM32_WPAN/shci_tl.c b/src/utility/STM32_WPAN/shci_tl.c new file mode 100644 index 00000000..25e1a214 --- /dev/null +++ b/src/utility/STM32_WPAN/shci_tl.c @@ -0,0 +1,271 @@ +/** + ****************************************************************************** + * @file shci.c + * @author MCD Application Team + * @brief System HCI command implementation + ****************************************************************************** + * @attention + * + * Copyright (c) 2018-2021 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ + + +#if defined(STM32WBxx) +/* Includes ------------------------------------------------------------------*/ +#include "stm32_wpan_common.h" + +#include "stm_list.h" +#include "shci_tl.h" +#include "stm32_def.h" +#include "wiring_time.h" + +/* Private typedef -----------------------------------------------------------*/ +typedef enum +{ + SHCI_TL_CMD_RESP_RELEASE, + SHCI_TL_CMD_RESP_WAIT, +} SHCI_TL_CmdRespStatus_t; + +/* Private defines -----------------------------------------------------------*/ +/** + * The default System HCI layer timeout is set to 33s + */ +#define SHCI_TL_DEFAULT_TIMEOUT (33000) + +/* Private macros ------------------------------------------------------------*/ +/* Public variables ---------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +/** + * START of Section SYSTEM_DRIVER_CONTEXT + */ +PLACE_IN_SECTION("SYSTEM_DRIVER_CONTEXT") static tListNode SHciAsynchEventQueue; +PLACE_IN_SECTION("SYSTEM_DRIVER_CONTEXT") static volatile SHCI_TL_CmdStatus_t SHCICmdStatus; +PLACE_IN_SECTION("SYSTEM_DRIVER_CONTEXT") static TL_CmdPacket_t *pCmdBuffer; +PLACE_IN_SECTION("SYSTEM_DRIVER_CONTEXT") SHCI_TL_UserEventFlowStatus_t SHCI_TL_UserEventFlow; +/** + * END of Section SYSTEM_DRIVER_CONTEXT + */ + +static tSHciContext shciContext; +static void (* StatusNotCallBackFunction) (SHCI_TL_CmdStatus_t status); + +static volatile SHCI_TL_CmdRespStatus_t CmdRspStatusFlag; + +/* Private function prototypes -----------------------------------------------*/ +static void Cmd_SetStatus(SHCI_TL_CmdStatus_t shcicmdstatus); +static void TlCmdEvtReceived(TL_EvtPacket_t *shcievt); +static void TlUserEvtReceived(TL_EvtPacket_t *shcievt); +static void TlInit( TL_CmdPacket_t * p_cmdbuffer ); + +/* Interface ------- ---------------------------------------------------------*/ +void shci_init(void(* UserEvtRx)(void* pData), void* pConf) +{ + StatusNotCallBackFunction = ((SHCI_TL_HciInitConf_t *)pConf)->StatusNotCallBack; + shciContext.UserEvtRx = UserEvtRx; + + shci_register_io_bus (&shciContext.io); + + TlInit((TL_CmdPacket_t *)(((SHCI_TL_HciInitConf_t *)pConf)->p_cmdbuffer)); + + return; +} + +void shci_user_evt_proc(void) +{ + TL_EvtPacket_t *phcievtbuffer; + tSHCI_UserEvtRxParam UserEvtRxParam; + + /** + * Up to release version v1.2.0, a while loop was implemented to read out events from the queue as long as + * it is not empty. However, in a bare metal implementation, this leads to calling in a "blocking" mode + * shci_user_evt_proc() as long as events are received without giving the opportunity to run other tasks + * in the background. + * From now, the events are reported one by one. When it is checked there is still an event pending in the queue, + * a request to the user is made to call again shci_user_evt_proc(). + * This gives the opportunity to the application to run other background tasks between each event. + */ + + /** + * It is more secure to use LST_remove_head()/LST_insert_head() compare to LST_get_next_node()/LST_remove_node() + * in case the user overwrite the header where the next/prev pointers are located + */ + if((LST_is_empty(&SHciAsynchEventQueue) == FALSE) && (SHCI_TL_UserEventFlow != SHCI_TL_UserEventFlow_Disable)) + { + LST_remove_head ( &SHciAsynchEventQueue, (tListNode **)&phcievtbuffer ); + + if (shciContext.UserEvtRx != NULL) + { + UserEvtRxParam.pckt = phcievtbuffer; + UserEvtRxParam.status = SHCI_TL_UserEventFlow_Enable; + shciContext.UserEvtRx((void *)&UserEvtRxParam); + SHCI_TL_UserEventFlow = UserEvtRxParam.status; + } + else + { + SHCI_TL_UserEventFlow = SHCI_TL_UserEventFlow_Enable; + } + + if(SHCI_TL_UserEventFlow != SHCI_TL_UserEventFlow_Disable) + { + TL_MM_EvtDone( phcievtbuffer ); + } + else + { + /** + * put back the event in the queue + */ + LST_insert_head ( &SHciAsynchEventQueue, (tListNode *)phcievtbuffer ); + } + } + + if((LST_is_empty(&SHciAsynchEventQueue) == FALSE) && (SHCI_TL_UserEventFlow != SHCI_TL_UserEventFlow_Disable)) + { + shci_notify_asynch_evt((void*) &SHciAsynchEventQueue); + } + + + return; +} + +void shci_resume_flow( void ) +{ + SHCI_TL_UserEventFlow = SHCI_TL_UserEventFlow_Enable; + + /** + * It is better to go through the background process as it is not sure from which context this API may + * be called + */ + shci_notify_asynch_evt((void*) &SHciAsynchEventQueue); + + return; +} + +void shci_send( uint16_t cmd_code, uint8_t len_cmd_payload, uint8_t * p_cmd_payload, TL_EvtPacket_t * p_rsp ) +{ + Cmd_SetStatus(SHCI_TL_CmdBusy); + + pCmdBuffer->cmdserial.cmd.cmdcode = cmd_code; + pCmdBuffer->cmdserial.cmd.plen = len_cmd_payload; + + memcpy(pCmdBuffer->cmdserial.cmd.payload, p_cmd_payload, len_cmd_payload ); + CmdRspStatusFlag = SHCI_TL_CMD_RESP_WAIT; + shciContext.io.Send(0,0); + + shci_cmd_resp_wait(SHCI_TL_DEFAULT_TIMEOUT); + + /** + * The command complete of a system command does not have the header + * It starts immediately with the evtserial field + */ + memcpy( &(p_rsp->evtserial), pCmdBuffer, ((TL_EvtSerial_t*)pCmdBuffer)->evt.plen + TL_EVT_HDR_SIZE ); + + Cmd_SetStatus(SHCI_TL_CmdAvailable); + + return; +} + +void shci_notify_asynch_evt(void *pdata) +{ + UNUSED(pdata); + /* Need to parse data in future version */ + shci_user_evt_proc(); +} + +void shci_register_io_bus(tSHciIO *fops) +{ + /* Register IO bus services */ + fops->Init = TL_SYS_Init; + fops->Send = TL_SYS_SendCmd; +} + +/* Private functions ---------------------------------------------------------*/ +static void TlInit( TL_CmdPacket_t * p_cmdbuffer ) +{ + TL_SYS_InitConf_t Conf; + + pCmdBuffer = p_cmdbuffer; + + LST_init_head (&SHciAsynchEventQueue); + + Cmd_SetStatus(SHCI_TL_CmdAvailable); + + SHCI_TL_UserEventFlow = SHCI_TL_UserEventFlow_Enable; + + /* Initialize low level driver */ + if (shciContext.io.Init) + { + + Conf.p_cmdbuffer = (uint8_t *)p_cmdbuffer; + Conf.IoBusCallBackCmdEvt = TlCmdEvtReceived; + Conf.IoBusCallBackUserEvt = TlUserEvtReceived; + shciContext.io.Init(&Conf); + } + + return; +} + +static void Cmd_SetStatus(SHCI_TL_CmdStatus_t shcicmdstatus) +{ + if(shcicmdstatus == SHCI_TL_CmdBusy) + { + if(StatusNotCallBackFunction != 0) + { + StatusNotCallBackFunction( SHCI_TL_CmdBusy ); + } + SHCICmdStatus = SHCI_TL_CmdBusy; + } + else + { + SHCICmdStatus = SHCI_TL_CmdAvailable; + if(StatusNotCallBackFunction != 0) + { + StatusNotCallBackFunction( SHCI_TL_CmdAvailable ); + } + } + + return; +} + +static void TlCmdEvtReceived(TL_EvtPacket_t *shcievt) +{ + (void)(shcievt); + shci_cmd_resp_release(0); /**< Notify the application the Cmd response has been received */ + + return; +} + +static void TlUserEvtReceived(TL_EvtPacket_t *shcievt) +{ + LST_insert_tail(&SHciAsynchEventQueue, (tListNode *)shcievt); + shci_notify_asynch_evt((void*) &SHciAsynchEventQueue); /**< Notify the application a full HCI event has been received */ + + return; +} + +/* Weak implementation ----------------------------------------------------------------*/ +__WEAK void shci_cmd_resp_wait(uint32_t timeout) +{ + for (unsigned long start = millis(); (millis() - start) < timeout;) { + if (CmdRspStatusFlag == SHCI_TL_CMD_RESP_RELEASE) { + break; + } + } + return; +} + +__WEAK void shci_cmd_resp_release(uint32_t flag) +{ + (void)flag; + + CmdRspStatusFlag = SHCI_TL_CMD_RESP_RELEASE; + + return; +} +#endif /* STM32WBxx */ diff --git a/src/utility/STM32_WPAN/shci_tl.h b/src/utility/STM32_WPAN/shci_tl.h new file mode 100644 index 00000000..74d0ff38 --- /dev/null +++ b/src/utility/STM32_WPAN/shci_tl.h @@ -0,0 +1,173 @@ +/** + ****************************************************************************** + * @file shci_tl.h + * @author MCD Application Team + * @brief System HCI command header for the system channel + ****************************************************************************** + * @attention + * + * Copyright (c) 2018-2021 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ + +#ifndef __SHCI_TL_H_ +#define __SHCI_TL_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "tl.h" + +/* Exported defines -----------------------------------------------------------*/ +typedef enum +{ + SHCI_TL_UserEventFlow_Disable, + SHCI_TL_UserEventFlow_Enable, +} SHCI_TL_UserEventFlowStatus_t; + +typedef enum +{ + SHCI_TL_CmdBusy, + SHCI_TL_CmdAvailable +} SHCI_TL_CmdStatus_t; + +/** + * @brief Structure used to manage the BUS IO operations. + * All the structure fields will point to functions defined at user level. + * @{ + */ +typedef struct +{ + int32_t (* Init) (void* pConf); /**< Pointer to SHCI TL function for the IO Bus initialization */ + int32_t (* DeInit) (void); /**< Pointer to SHCI TL function for the IO Bus de-initialization */ + int32_t (* Reset) (void); /**< Pointer to SHCI TL function for the IO Bus reset */ + int32_t (* Receive) (uint8_t*, uint16_t); /**< Pointer to SHCI TL function for the IO Bus data reception */ + int32_t (* Send) (uint8_t*, uint16_t); /**< Pointer to SHCI TL function for the IO Bus data transmission */ + int32_t (* DataAck) (uint8_t*, uint16_t* len); /**< Pointer to SHCI TL function for the IO Bus data ack reception */ + int32_t (* GetTick) (void); /**< Pointer to BSP function for getting the HAL time base timestamp */ +} tSHciIO; +/** + * @} + */ + +/** + * @brief Contain the SHCI context + * @{ + */ +typedef struct +{ + tSHciIO io; /**< Manage the BUS IO operations */ + void (* UserEvtRx) (void * pData); /**< User System events callback function pointer */ +} tSHciContext; + +typedef struct +{ + SHCI_TL_UserEventFlowStatus_t status; + TL_EvtPacket_t *pckt; +} tSHCI_UserEvtRxParam; + +typedef struct +{ + uint8_t *p_cmdbuffer; + void (* StatusNotCallBack) (SHCI_TL_CmdStatus_t status); +} SHCI_TL_HciInitConf_t; + +/** + * shci_send + * @brief Send an System HCI Command + * + * @param : cmd_code = Opcode of the command + * @param : len_cmd_payload = Length of the command payload + * @param : p_cmd_payload = Address of the command payload + * @param : p_rsp_status = Address of the full buffer holding the command complete event + * @retval : None + */ +void shci_send( uint16_t cmd_code, uint8_t len_cmd_payload, uint8_t * p_cmd_payload, TL_EvtPacket_t * p_rsp_status ); + +/** + * @brief Register IO bus services. + * @param fops The SHCI IO structure managing the IO BUS + * @retval None + */ +void shci_register_io_bus(tSHciIO* fops); + +/** + * @brief Interrupt service routine that must be called when the system channel + * reports a packet has been received + * + * @param pdata Packet or event pointer + * @retval None + */ +void shci_notify_asynch_evt(void* pdata); + +/** + * @brief This function resume the User Event Flow which has been stopped on return + * from UserEvtRx() when the User Event has not been processed. + * + * @param None + * @retval None + */ +void shci_resume_flow(void); + + +/** + * @brief This function is called when an System HCI Command is sent to the CPU2 and the response is waited. + * It is called from the same context the System HCI command has been sent. + * It shall not return until the command response notified by shci_cmd_resp_release() is received. + * A weak implementation is available in shci_tl.c based on polling mechanism + * The user may re-implement this function in the application to improve performance : + * - It may use UTIL_SEQ_WaitEvt() API when using the Sequencer + * - It may use a semaphore when using cmsis_os interface + * + * @param timeout: Waiting timeout + * @retval None + */ +void shci_cmd_resp_wait(uint32_t timeout); + +/** + * @brief This function is called when an System HCI command is received from the CPU2. + * A weak implementation is available in shci_tl.c based on polling mechanism + * The user may re-implement this function in the application to improve performance : + * - It may use UTIL_SEQ_SetEvt() API when using the Sequencer + * - It may use a semaphore when using cmsis_os interface + * + * + * @param flag: Release flag + * @retval None + */ +void shci_cmd_resp_release(uint32_t flag); + + +/** + * @brief This process shall be called each time the shci_notify_asynch_evt notification is received + * + * @param None + * @retval None + */ + +void shci_user_evt_proc(void); + +/** + * @brief Initialize the System Host Controller Interface. + * This function must be called before any communication on the System Channel + * + * @param UserEvtRx: System events callback function pointer + * This callback is triggered when an user event is received on + * the System Channel from CPU2. + * @param pConf: Configuration structure pointer + * @retval None + */ +void shci_init(void(* UserEvtRx)(void* pData), void* pConf); + +#ifdef __cplusplus +} +#endif + +#endif /* __SHCI_TL_H_ */ diff --git a/src/utility/STM32_WPAN/stm32_wpan_common.h b/src/utility/STM32_WPAN/stm32_wpan_common.h new file mode 100644 index 00000000..f407bb98 --- /dev/null +++ b/src/utility/STM32_WPAN/stm32_wpan_common.h @@ -0,0 +1,171 @@ +/** + ****************************************************************************** + * @file stm32_wpan_common.h + * @author MCD Application Team + * @brief Common file to utilities + ****************************************************************************** + * @attention + * + * Copyright (c) 2018-2021 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ + + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __STM32_WPAN_COMMON_H +#define __STM32_WPAN_COMMON_H + +#ifdef __cplusplus +extern "C" { +#endif + +#if defined ( __CC_ARM )||defined (__ARMCC_VERSION) + #define __ASM __asm /*!< asm keyword for ARM Compiler */ + #define __INLINE __inline /*!< inline keyword for ARM Compiler */ + #define __STATIC_INLINE static __inline +#elif defined ( __ICCARM__ ) + #define __ASM __asm /*!< asm keyword for IAR Compiler */ + #define __INLINE inline /*!< inline keyword for IAR Compiler. Only available in High optimization mode! */ + #define __STATIC_INLINE static inline +#elif defined ( __GNUC__ ) + #define __ASM __asm /*!< asm keyword for GNU Compiler */ + #define __INLINE inline /*!< inline keyword for GNU Compiler */ + #define __STATIC_INLINE static inline +#endif + +#include <stdint.h> +#include <string.h> +#include <stdio.h> +#include <stdlib.h> +#include <stdarg.h> +#include "cmsis_compiler.h" + + /* -------------------------------- * + * Basic definitions * + * -------------------------------- */ + +#undef NULL +#define NULL 0U + +#undef FALSE +#define FALSE 0U + +#undef TRUE +#define TRUE (!0U) + + /* -------------------------------- * + * Critical Section definition * + * -------------------------------- */ +#undef BACKUP_PRIMASK +#define BACKUP_PRIMASK() uint32_t primask_bit= __get_PRIMASK() + +#undef DISABLE_IRQ +#define DISABLE_IRQ() __disable_irq() + +#undef RESTORE_PRIMASK +#define RESTORE_PRIMASK() __set_PRIMASK(primask_bit) + + /* -------------------------------- * + * Macro delimiters * + * -------------------------------- */ +#undef M_BEGIN +#define M_BEGIN do { + +#undef M_END +#define M_END } while(0) + + /* -------------------------------- * + * Some useful macro definitions * + * -------------------------------- */ +#undef MAX +#define MAX(a, b) (((a) > (b)) ? (a) : (b)) + +#undef MIN +#define MIN(a, b) (((a) < (b)) ? (a) : (b)) + +#undef MODINC +#define MODINC( a, m ) M_BEGIN (a)++; if ((a)>=(m)) (a)=0; M_END + +#undef MODDEC +#define MODDEC( a, m ) M_BEGIN if ((a)==0) (a)=(m); (a)--; M_END + +#undef MODADD +#define MODADD( a, b, m ) M_BEGIN (a)+=(b); if ((a)>=(m)) (a)-=(m); M_END + +#undef MODSUB +#define MODSUB( a, b, m ) MODADD( a, (m)-(b), m ) + +#undef ALIGN +#ifdef WIN32 +#define ALIGN(n) +#else +#define ALIGN(n) __attribute__((aligned(n))) +#endif + +#undef PAUSE +#define PAUSE( t ) M_BEGIN \ + volatile int _i; \ + for ( _i = t; _i > 0; _i -- ); \ + M_END +#undef DIVF +#define DIVF( x, y ) ((x)/(y)) + +#undef DIVC +#define DIVC( x, y ) (((x)+(y)-1)/(y)) + +#undef DIVR +#define DIVR( x, y ) (((x)+((y)/2))/(y)) + +#undef SHRR +#define SHRR( x, n ) ((((x)>>((n)-1))+1)>>1) + +#undef BITN +#define BITN( w, n ) (((w)[(n)/32] >> ((n)%32)) & 1) + +#undef BITNSET +#define BITNSET( w, n, b ) M_BEGIN (w)[(n)/32] |= ((U32)(b))<<((n)%32); M_END + +/* -------------------------------- * + * Section attribute * + * -------------------------------- */ +#undef PLACE_IN_SECTION +#define PLACE_IN_SECTION( __x__ ) __attribute__((section (__x__))) + +/* ----------------------------------- * + * Packed usage (compiler dependent) * + * ----------------------------------- */ +#undef PACKED__ +#undef PACKED_STRUCT + +#if defined ( __CC_ARM ) + #if defined ( __GNUC__ ) + /* GNU extension */ + #define PACKED__ __attribute__((packed)) + #define PACKED_STRUCT struct PACKED__ + #elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050U) + #define PACKED__ __attribute__((packed)) + #define PACKED_STRUCT struct PACKED__ + #else + #define PACKED__(TYPE) __packed TYPE + #define PACKED_STRUCT PACKED__(struct) + #endif +#elif defined ( __GNUC__ ) + #define PACKED__ __attribute__((packed)) + #define PACKED_STRUCT struct PACKED__ +#elif defined (__ICCARM__) + #define PACKED_STRUCT __packed struct +#else + #define PACKED_STRUCT __packed struct +#endif + +#ifdef __cplusplus +} +#endif + +#endif /*__STM32_WPAN_COMMON_H */ diff --git a/src/utility/STM32_WPAN/stm_list.c b/src/utility/STM32_WPAN/stm_list.c new file mode 100644 index 00000000..df6c2155 --- /dev/null +++ b/src/utility/STM32_WPAN/stm_list.c @@ -0,0 +1,210 @@ +/** + ****************************************************************************** + * @file stm_list.c + * @author MCD Application Team + * @brief TCircular Linked List Implementation. + ****************************************************************************** + * @attention + * + * Copyright (c) 2018-2021 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ + + +#if defined(STM32WBxx) +/****************************************************************************** + * Include Files + ******************************************************************************/ +#include "stdint.h" +#include "cmsis_gcc.h" +#include "stm32_wpan_common.h" + +#include "stm_list.h" + +/****************************************************************************** + * Function Definitions + ******************************************************************************/ +void LST_init_head (tListNode * listHead) +{ + listHead->next = listHead; + listHead->prev = listHead; +} + +uint8_t LST_is_empty (tListNode * listHead) +{ + uint32_t primask_bit; + uint8_t return_value; + + primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ + __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ + if(listHead->next == listHead) + { + return_value = TRUE; + } + else + { + return_value = FALSE; + } + __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ + + return return_value; +} + +void LST_insert_head (tListNode * listHead, tListNode * node) +{ + uint32_t primask_bit; + + primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ + __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ + + node->next = listHead->next; + node->prev = listHead; + listHead->next = node; + (node->next)->prev = node; + + __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ +} + + +void LST_insert_tail (tListNode * listHead, tListNode * node) +{ + uint32_t primask_bit; + + primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ + __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ + + node->next = listHead; + node->prev = listHead->prev; + listHead->prev = node; + (node->prev)->next = node; + + __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ +} + + +void LST_remove_node (tListNode * node) +{ + uint32_t primask_bit; + + primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ + __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ + + (node->prev)->next = node->next; + (node->next)->prev = node->prev; + + __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ +} + + +void LST_remove_head (tListNode * listHead, tListNode ** node ) +{ + uint32_t primask_bit; + + primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ + __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ + + *node = listHead->next; + LST_remove_node (listHead->next); + + __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ +} + + +void LST_remove_tail (tListNode * listHead, tListNode ** node ) +{ + uint32_t primask_bit; + + primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ + __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ + + *node = listHead->prev; + LST_remove_node (listHead->prev); + + __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ +} + + +void LST_insert_node_after (tListNode * node, tListNode * ref_node) +{ + uint32_t primask_bit; + + primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ + __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ + + node->next = ref_node->next; + node->prev = ref_node; + ref_node->next = node; + (node->next)->prev = node; + + __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ +} + + +void LST_insert_node_before (tListNode * node, tListNode * ref_node) +{ + uint32_t primask_bit; + + primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ + __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ + + node->next = ref_node; + node->prev = ref_node->prev; + ref_node->prev = node; + (node->prev)->next = node; + + __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ +} + + +int LST_get_size (tListNode * listHead) +{ + int size = 0; + tListNode * temp; + uint32_t primask_bit; + + primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ + __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ + + temp = listHead->next; + while (temp != listHead) + { + size++; + temp = temp->next; + } + + __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ + + return (size); +} + +void LST_get_next_node (tListNode * ref_node, tListNode ** node) +{ + uint32_t primask_bit; + + primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ + __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ + + *node = ref_node->next; + + __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ +} + + +void LST_get_prev_node (tListNode * ref_node, tListNode ** node) +{ + uint32_t primask_bit; + + primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ + __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ + + *node = ref_node->prev; + + __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ +} +#endif /* STM32WBxx */ diff --git a/src/utility/STM32_WPAN/stm_list.h b/src/utility/STM32_WPAN/stm_list.h new file mode 100644 index 00000000..b7c3254c --- /dev/null +++ b/src/utility/STM32_WPAN/stm_list.h @@ -0,0 +1,55 @@ +/** + ****************************************************************************** + * @file stm_list.h + * @author MCD Application Team + * @brief Header file for linked list library. + ****************************************************************************** + * @attention + * + * Copyright (c) 2018-2021 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ + + +#ifndef _STM_LIST_H_ +#define _STM_LIST_H_ + +/* Includes ------------------------------------------------------------------*/ +#include "stm32_wpan_common.h" + +typedef PACKED_STRUCT _tListNode { + struct _tListNode * next; + struct _tListNode * prev; +} tListNode; + +void LST_init_head (tListNode * listHead); + +uint8_t LST_is_empty (tListNode * listHead); + +void LST_insert_head (tListNode * listHead, tListNode * node); + +void LST_insert_tail (tListNode * listHead, tListNode * node); + +void LST_remove_node (tListNode * node); + +void LST_remove_head (tListNode * listHead, tListNode ** node ); + +void LST_remove_tail (tListNode * listHead, tListNode ** node ); + +void LST_insert_node_after (tListNode * node, tListNode * ref_node); + +void LST_insert_node_before (tListNode * node, tListNode * ref_node); + +int LST_get_size (tListNode * listHead); + +void LST_get_next_node (tListNode * ref_node, tListNode ** node); + +void LST_get_prev_node (tListNode * ref_node, tListNode ** node); + +#endif /* _STM_LIST_H_ */ diff --git a/src/utility/STM32_WPAN/tl.h b/src/utility/STM32_WPAN/tl.h new file mode 100644 index 00000000..74520878 --- /dev/null +++ b/src/utility/STM32_WPAN/tl.h @@ -0,0 +1,372 @@ +/** + ****************************************************************************** + * @file tl.h + * @author MCD Application Team + * @brief Header for tl module + ****************************************************************************** + * @attention + * + * Copyright (c) 2018-2021 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ + + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __TL_H +#define __TL_H + +#ifdef __cplusplus +extern "C" { +#endif + + +/* Includes ------------------------------------------------------------------*/ +#include "stm32_wpan_common.h" + +/* Exported defines -----------------------------------------------------------*/ +#define TL_BLECMD_PKT_TYPE ( 0x01 ) +#define TL_ACL_DATA_PKT_TYPE ( 0x02 ) +#define TL_BLEEVT_PKT_TYPE ( 0x04 ) +#define TL_OTCMD_PKT_TYPE ( 0x08 ) +#define TL_OTRSP_PKT_TYPE ( 0x09 ) +#define TL_CLICMD_PKT_TYPE ( 0x0A ) +#define TL_OTNOT_PKT_TYPE ( 0x0C ) +#define TL_OTACK_PKT_TYPE ( 0x0D ) +#define TL_CLINOT_PKT_TYPE ( 0x0E ) +#define TL_CLIACK_PKT_TYPE ( 0x0F ) +#define TL_SYSCMD_PKT_TYPE ( 0x10 ) +#define TL_SYSRSP_PKT_TYPE ( 0x11 ) +#define TL_SYSEVT_PKT_TYPE ( 0x12 ) +#define TL_CLIRESP_PKT_TYPE ( 0x15 ) +#define TL_M0CMD_PKT_TYPE ( 0x16 ) +#define TL_LOCCMD_PKT_TYPE ( 0x20 ) +#define TL_LOCRSP_PKT_TYPE ( 0x21 ) +#define TL_TRACES_APP_PKT_TYPE ( 0x40 ) +#define TL_TRACES_WL_PKT_TYPE ( 0x41 ) + +#define TL_CMD_HDR_SIZE (4) +#define TL_EVT_HDR_SIZE (3) +#define TL_EVT_CS_PAYLOAD_SIZE (4) + +#define TL_BLEEVT_CC_OPCODE (0x0E) +#define TL_BLEEVT_CS_OPCODE (0x0F) +#define TL_BLEEVT_VS_OPCODE (0xFF) + +#define TL_BLEEVT_CC_PACKET_SIZE (TL_EVT_HDR_SIZE + sizeof(TL_CcEvt_t)) +#define TL_BLEEVT_CC_BUFFER_SIZE (sizeof(TL_PacketHeader_t) + TL_BLEEVT_CC_PACKET_SIZE) +/* Exported types ------------------------------------------------------------*/ +/**< Packet header */ +typedef PACKED_STRUCT +{ + uint32_t *next; + uint32_t *prev; +} TL_PacketHeader_t; + +/******************************************************************************* + * Event type + */ + +/** + * This the payload of TL_Evt_t for a command status event + */ +typedef PACKED_STRUCT +{ + uint8_t status; + uint8_t numcmd; + uint16_t cmdcode; +} TL_CsEvt_t; + +/** + * This the payload of TL_Evt_t for a command complete event, only used a pointer + */ +typedef PACKED_STRUCT +{ + uint8_t numcmd; + uint16_t cmdcode; + uint8_t payload[2]; +} TL_CcEvt_t; + +/** + * This the payload of TL_Evt_t for an asynchronous event, only used a pointer + */ +typedef PACKED_STRUCT +{ + uint16_t subevtcode; + uint8_t payload[2]; +} TL_AsynchEvt_t; + +/** + * This the payload of TL_Evt_t, only used a pointer + */ +typedef PACKED_STRUCT +{ + uint8_t evtcode; + uint8_t plen; + uint8_t payload[4]; +} TL_Evt_t; + +typedef PACKED_STRUCT +{ + uint8_t type; + TL_Evt_t evt; +} TL_EvtSerial_t; + +/** + * This format shall be used for all events (asynchronous and command response) reported + * by the CPU2 except for the command response of a system command where the header is not there + * and the format to be used shall be TL_EvtSerial_t. + * Note: Be careful that the asynchronous events reported by the CPU2 on the system channel do + * include the header and shall use TL_EvtPacket_t format. Only the command response format on the + * system channel is different. + */ +typedef PACKED_STRUCT +{ + TL_PacketHeader_t header; + TL_EvtSerial_t evtserial; +} TL_EvtPacket_t; + +/***************************************************************************************** + * Command type + */ + +typedef PACKED_STRUCT +{ + uint16_t cmdcode; + uint8_t plen; + uint8_t payload[255]; +} TL_Cmd_t; + +typedef PACKED_STRUCT +{ + uint8_t type; + TL_Cmd_t cmd; +} TL_CmdSerial_t; + +typedef PACKED_STRUCT +{ + TL_PacketHeader_t header; + TL_CmdSerial_t cmdserial; +} TL_CmdPacket_t; + +/***************************************************************************************** + * HCI ACL DATA type + */ +typedef PACKED_STRUCT +{ + uint8_t type; + uint16_t handle; + uint16_t length; + uint8_t acl_data[1]; +} TL_AclDataSerial_t; + +typedef PACKED_STRUCT +{ + TL_PacketHeader_t header; + TL_AclDataSerial_t AclDataSerial; +} TL_AclDataPacket_t; + +typedef struct +{ + uint8_t *p_BleSpareEvtBuffer; + uint8_t *p_SystemSpareEvtBuffer; + uint8_t *p_AsynchEvtPool; + uint32_t AsynchEvtPoolSize; + uint8_t *p_TracesEvtPool; + uint32_t TracesEvtPoolSize; +} TL_MM_Config_t; + +typedef struct +{ + uint8_t *p_ThreadOtCmdRspBuffer; + uint8_t *p_ThreadCliRspBuffer; + uint8_t *p_ThreadNotAckBuffer; + uint8_t *p_ThreadCliNotBuffer; +} TL_TH_Config_t; + +typedef struct +{ + uint8_t *p_LldTestsCliCmdRspBuffer; + uint8_t *p_LldTestsM0CmdBuffer; +} TL_LLD_tests_Config_t; + +typedef struct +{ + uint8_t *p_BleLldCmdRspBuffer; + uint8_t *p_BleLldM0CmdBuffer; +} TL_BLE_LLD_Config_t; + +typedef struct +{ + uint8_t *p_Mac_802_15_4_CmdRspBuffer; + uint8_t *p_Mac_802_15_4_NotAckBuffer; +} TL_MAC_802_15_4_Config_t; + +typedef struct +{ + uint8_t *p_ZigbeeOtCmdRspBuffer; + uint8_t *p_ZigbeeNotAckBuffer; + uint8_t *p_ZigbeeNotifRequestBuffer; +} TL_ZIGBEE_Config_t; + +/** + * @brief Contain the BLE HCI Init Configuration + * @{ + */ +typedef struct +{ + void (* IoBusEvtCallBack) ( TL_EvtPacket_t *phcievt ); + void (* IoBusAclDataTxAck) ( void ); + uint8_t *p_cmdbuffer; + uint8_t *p_AclDataBuffer; +} TL_BLE_InitConf_t; + +/** + * @brief Contain the SYSTEM HCI Init Configuration + * @{ + */ +typedef struct +{ + void (* IoBusCallBackCmdEvt) (TL_EvtPacket_t *phcievt); + void (* IoBusCallBackUserEvt) (TL_EvtPacket_t *phcievt); + uint8_t *p_cmdbuffer; +} TL_SYS_InitConf_t; + +/***************************************************************************************** + * Event type copied from ble_legacy.h + */ + +typedef PACKED_STRUCT +{ + uint8_t type; + uint8_t data[1]; +} hci_uart_pckt; + +typedef PACKED_STRUCT +{ + uint8_t evt; + uint8_t plen; + uint8_t data[1]; +} hci_event_pckt; + +typedef PACKED_STRUCT +{ + uint8_t subevent; + uint8_t data[1]; +} evt_le_meta_event; + +/** + * Vendor specific event for BLE core. + */ +typedef PACKED_STRUCT +{ + uint16_t ecode; /**< One of the BLE core event codes. */ + uint8_t data[1]; +} evt_blecore_aci; + +/* Bluetooth 48 bit address (in little-endian order). + */ +typedef uint8_t tBDAddr[6]; + + +/* Exported constants --------------------------------------------------------*/ +/* External variables --------------------------------------------------------*/ +/* Exported macros -----------------------------------------------------------*/ +/* Exported functions ------------------------------------------------------- */ + +/****************************************************************************** + * GENERAL + ******************************************************************************/ +void TL_Enable( void ); +void TL_Init( void ); + +/****************************************************************************** + * BLE + ******************************************************************************/ +int32_t TL_BLE_Init( void* pConf ); +int32_t TL_BLE_SendCmd( uint8_t* buffer, uint16_t size ); +int32_t TL_BLE_SendAclData( uint8_t* buffer, uint16_t size ); + +/****************************************************************************** + * SYSTEM + ******************************************************************************/ +int32_t TL_SYS_Init( void* pConf ); +int32_t TL_SYS_SendCmd( uint8_t* buffer, uint16_t size ); + +/****************************************************************************** + * THREAD + ******************************************************************************/ +void TL_THREAD_Init( TL_TH_Config_t *p_Config ); +void TL_OT_SendCmd( void ); +void TL_CLI_SendCmd( void ); +void TL_OT_CmdEvtReceived( TL_EvtPacket_t * Otbuffer ); +void TL_THREAD_NotReceived( TL_EvtPacket_t * Notbuffer ); +void TL_THREAD_SendAck ( void ); +void TL_THREAD_CliSendAck ( void ); +void TL_THREAD_CliNotReceived( TL_EvtPacket_t * Notbuffer ); + +/****************************************************************************** + * LLD TESTS + ******************************************************************************/ +void TL_LLDTESTS_Init( TL_LLD_tests_Config_t *p_Config ); +void TL_LLDTESTS_SendCliCmd( void ); +void TL_LLDTESTS_ReceiveCliRsp( TL_CmdPacket_t * Notbuffer ); +void TL_LLDTESTS_SendCliRspAck( void ); +void TL_LLDTESTS_ReceiveM0Cmd( TL_CmdPacket_t * Notbuffer ); +void TL_LLDTESTS_SendM0CmdAck( void ); + +/****************************************************************************** + * BLE LLD + ******************************************************************************/ +void TL_BLE_LLD_Init( TL_BLE_LLD_Config_t *p_Config ); +void TL_BLE_LLD_SendCliCmd( void ); +void TL_BLE_LLD_ReceiveCliRsp( TL_CmdPacket_t * Notbuffer ); +void TL_BLE_LLD_SendCliRspAck( void ); +void TL_BLE_LLD_ReceiveM0Cmd( TL_CmdPacket_t * Notbuffer ); +void TL_BLE_LLD_SendM0CmdAck( void ); +void TL_BLE_LLD_SendCmd( void ); +void TL_BLE_LLD_ReceiveRsp( TL_CmdPacket_t * Notbuffer ); +void TL_BLE_LLD_SendRspAck( void ); +/****************************************************************************** + * MEMORY MANAGER + ******************************************************************************/ +void TL_MM_Init( TL_MM_Config_t *p_Config ); +void TL_MM_EvtDone( TL_EvtPacket_t * hcievt ); + +/****************************************************************************** + * TRACES + ******************************************************************************/ +void TL_TRACES_Init( void ); +void TL_TRACES_EvtReceived( TL_EvtPacket_t * hcievt ); + +/****************************************************************************** + * MAC 802.15.4 + ******************************************************************************/ +void TL_MAC_802_15_4_Init( TL_MAC_802_15_4_Config_t *p_Config ); +void TL_MAC_802_15_4_SendCmd( void ); +void TL_MAC_802_15_4_CmdEvtReceived( TL_EvtPacket_t * Otbuffer ); +void TL_MAC_802_15_4_NotReceived( TL_EvtPacket_t * Notbuffer ); +void TL_MAC_802_15_4_SendAck ( void ); + +/****************************************************************************** + * ZIGBEE + ******************************************************************************/ +void TL_ZIGBEE_Init( TL_ZIGBEE_Config_t *p_Config ); +void TL_ZIGBEE_SendM4RequestToM0( void ); +void TL_ZIGBEE_SendM4AckToM0Notify ( void ); +void TL_ZIGBEE_NotReceived( TL_EvtPacket_t * Notbuffer ); +void TL_ZIGBEE_CmdEvtReceived( TL_EvtPacket_t * Otbuffer ); +void TL_ZIGBEE_M0RequestReceived(TL_EvtPacket_t * Otbuffer ); +void TL_ZIGBEE_SendM4AckToM0Request(void); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*__TL_H */ + diff --git a/src/utility/STM32_WPAN/tl_dbg_conf.h b/src/utility/STM32_WPAN/tl_dbg_conf.h new file mode 100644 index 00000000..841d1968 --- /dev/null +++ b/src/utility/STM32_WPAN/tl_dbg_conf.h @@ -0,0 +1,140 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * File Name : tl_dbg_conf.h + * Description : Debug configuration file for stm32wpan transport layer interface. + * + ****************************************************************************** + * @attention + * + * Copyright (c) 2019-2021 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef TL_DBG_CONF_H +#define TL_DBG_CONF_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* USER CODE BEGIN Tl_Conf */ + +/* Includes ------------------------------------------------------------------*/ +#include "core_debug.h" + +/** + * Enable or Disable traces + * The raw data output is the hci binary packet format as specified by the BT specification * + */ +#ifndef TL_SHCI_CMD_DBG_EN +#define TL_SHCI_CMD_DBG_EN 1 /* Reports System commands sent to CPU2 and the command response */ +#endif + +#ifndef TL_SHCI_EVT_DBG_EN +#define TL_SHCI_EVT_DBG_EN 1 /* Reports System Asynchronous Events received from CPU2 */ +#endif + +#ifndef TL_HCI_CMD_DBG_EN +#define TL_HCI_CMD_DBG_EN 1 /* Reports BLE command sent to CPU2 and the command response */ +#endif + +#ifndef TL_HCI_EVT_DBG_EN +#define TL_HCI_EVT_DBG_EN 1 /* Reports BLE Asynchronous Events received from CPU2 */ +#endif + +#ifndef TL_MM_DBG_EN +#define TL_MM_DBG_EN 1 /* Reports the information of the buffer released to CPU2 */ +#endif + +/** + * Macro definition + */ + +/** + * System Transport Layer + */ +#if (TL_SHCI_CMD_DBG_EN != 0) +#define TL_SHCI_CMD_DBG_MSG core_debug +#define TL_SHCI_CMD_DBG_BUF PRINT_LOG_BUFF_DBG +#else +#define TL_SHCI_CMD_DBG_MSG(...) +#define TL_SHCI_CMD_DBG_BUF(...) +#endif + +#define TL_SHCI_CMD_DBG_RAW(...) + +#if (TL_SHCI_EVT_DBG_EN != 0) +#define TL_SHCI_EVT_DBG_MSG core_debug +#define TL_SHCI_EVT_DBG_BUF PRINT_LOG_BUFF_DBG +#else +#define TL_SHCI_EVT_DBG_MSG(...) +#define TL_SHCI_EVT_DBG_BUF(...) +#endif + +#define TL_SHCI_EVT_DBG_RAW(...) + +/** + * BLE Transport Layer + */ +#if (TL_HCI_CMD_DBG_EN != 0) +#define TL_HCI_CMD_DBG_MSG core_debug +#define TL_HCI_CMD_DBG_BUF PRINT_LOG_BUFF_DBG +#else +#define TL_HCI_CMD_DBG_MSG(...) +#define TL_HCI_CMD_DBG_BUF(...) +#endif + +#define TL_HCI_CMD_DBG_RAW(...) + +#if (TL_HCI_EVT_DBG_EN != 0) +#define TL_HCI_EVT_DBG_MSG core_debug +#define TL_HCI_EVT_DBG_BUF PRINT_LOG_BUFF_DBG +#else +#define TL_HCI_EVT_DBG_MSG(...) +#define TL_HCI_EVT_DBG_BUF(...) +#endif + +#define TL_HCI_EVT_DBG_RAW(...) + +/** + * Memory Manager - Released buffer tracing + */ +#if (TL_MM_DBG_EN != 0) +#define TL_MM_DBG_MSG core_debug +#else +#define TL_MM_DBG_MSG(...) +#endif + + +#define PRINT_LOG_BUFF_DBG(...) DbgTraceBuffer(__VA_ARGS__) + +void DbgTraceBuffer(const void *pBuffer, uint32_t u32Length, const char *strFormat, ...) +{ + va_list vaArgs; + uint32_t u32Index; + va_start(vaArgs, strFormat); + vprintf(strFormat, vaArgs); + va_end(vaArgs); + for (u32Index = 0; u32Index < u32Length; u32Index ++) + { + core_debug(" %02X", ((const uint8_t *) pBuffer)[u32Index]); + } +} + +/* USER CODE END Tl_Conf */ + +#ifdef __cplusplus +} +#endif + +#endif /* TL_DBG_CONF_H */ + diff --git a/src/utility/STM32_WPAN/tl_mbox.c b/src/utility/STM32_WPAN/tl_mbox.c new file mode 100644 index 00000000..9a2a2973 --- /dev/null +++ b/src/utility/STM32_WPAN/tl_mbox.c @@ -0,0 +1,855 @@ +/** + ****************************************************************************** + * @file tl_mbox.c + * @author MCD Application Team + * @brief Transport layer for the mailbox interface + ****************************************************************************** + * @attention + * + * Copyright (c) 2018-2021 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ + +#if defined(STM32WBxx) +/* Includes ------------------------------------------------------------------*/ +#include "stm32_wpan_common.h" +#include "hw.h" + +#include "stm_list.h" +#include "tl.h" +#include "mbox_def.h" +#include "tl_dbg_conf.h" + +/* Private typedef -----------------------------------------------------------*/ +typedef enum +{ + TL_MB_MM_RELEASE_BUFFER, + TL_MB_BLE_CMD, + TL_MB_BLE_CMD_RSP, + TL_MB_BLE_ASYNCH_EVT, + TL_MB_SYS_CMD, + TL_MB_SYS_CMD_RSP, + TL_MB_SYS_ASYNCH_EVT, +} TL_MB_PacketType_t; + +/* Private defines -----------------------------------------------------------*/ +/* Private macros ------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ + +/**< reference table */ +PLACE_IN_SECTION("MAPPING_TABLE") static volatile MB_RefTable_t TL_RefTable; +PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_DeviceInfoTable_t TL_DeviceInfoTable; +PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_BleTable_t TL_BleTable; +PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_ThreadTable_t TL_ThreadTable; +PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_LldTestsTable_t TL_LldTestsTable; +PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_BleLldTable_t TL_BleLldTable; +PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_SysTable_t TL_SysTable; +PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_MemManagerTable_t TL_MemManagerTable; +PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_TracesTable_t TL_TracesTable; +#if 0 +PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_Mac_802_15_4_t TL_Mac_802_15_4_Table; +PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_ZigbeeTable_t TL_Zigbee_Table; +#endif + +/**< tables */ +PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode FreeBufQueue; +PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode TracesEvtQueue; +PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static uint8_t CsBuffer[sizeof(TL_PacketHeader_t) + TL_EVT_HDR_SIZE + sizeof(TL_CsEvt_t)]; +PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode EvtQueue; +PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode SystemEvtQueue; + + +static tListNode LocalFreeBufQueue; +static void (* BLE_IoBusEvtCallBackFunction) (TL_EvtPacket_t *phcievt); +static void (* BLE_IoBusAclDataTxAck) ( void ); +static void (* SYS_CMD_IoBusCallBackFunction) (TL_EvtPacket_t *phcievt); +static void (* SYS_EVT_IoBusCallBackFunction) (TL_EvtPacket_t *phcievt); + + +/* Global variables ----------------------------------------------------------*/ +/* Private function prototypes -----------------------------------------------*/ +static void SendFreeBuf( void ); +static void OutputDbgTrace(TL_MB_PacketType_t packet_type, uint8_t* buffer); + +/* Public Functions Definition ------------------------------------------------------*/ + +/****************************************************************************** + * GENERAL - refer to AN5289 for functions description. + ******************************************************************************/ +void TL_Enable( void ) +{ + HW_IPCC_Enable(); + + return; +} + + +void TL_Init( void ) +{ + TL_RefTable.p_device_info_table = &TL_DeviceInfoTable; + TL_RefTable.p_ble_table = &TL_BleTable; + TL_RefTable.p_thread_table = &TL_ThreadTable; + TL_RefTable.p_lld_tests_table = &TL_LldTestsTable; + TL_RefTable.p_ble_lld_table = &TL_BleLldTable; + TL_RefTable.p_sys_table = &TL_SysTable; + TL_RefTable.p_mem_manager_table = &TL_MemManagerTable; + TL_RefTable.p_traces_table = &TL_TracesTable; +#if 0 + TL_RefTable.p_mac_802_15_4_table = &TL_Mac_802_15_4_Table; + TL_RefTable.p_zigbee_table = &TL_Zigbee_Table; +#endif + HW_IPCC_Init(); + + return; +} + +/****************************************************************************** + * BLE + ******************************************************************************/ +int32_t TL_BLE_Init( void* pConf ) +{ + MB_BleTable_t * p_bletable; + + TL_BLE_InitConf_t *pInitHciConf = (TL_BLE_InitConf_t *) pConf; + + LST_init_head (&EvtQueue); + + p_bletable = TL_RefTable.p_ble_table; + + p_bletable->pcmd_buffer = pInitHciConf->p_cmdbuffer; + p_bletable->phci_acl_data_buffer = pInitHciConf->p_AclDataBuffer; + p_bletable->pcs_buffer = (uint8_t*)CsBuffer; + p_bletable->pevt_queue = (uint8_t*)&EvtQueue; + + HW_IPCC_BLE_Init(); + + BLE_IoBusEvtCallBackFunction = pInitHciConf->IoBusEvtCallBack; + BLE_IoBusAclDataTxAck = pInitHciConf->IoBusAclDataTxAck; + + return 0; +} + +int32_t TL_BLE_SendCmd( uint8_t* buffer, uint16_t size ) +{ + (void)(buffer); + (void)(size); + + ((TL_CmdPacket_t*)(TL_RefTable.p_ble_table->pcmd_buffer))->cmdserial.type = TL_BLECMD_PKT_TYPE; + + OutputDbgTrace(TL_MB_BLE_CMD, TL_RefTable.p_ble_table->pcmd_buffer); + + HW_IPCC_BLE_SendCmd(); + + return 0; +} + +void HW_IPCC_BLE_RxEvtNot(void) +{ + TL_EvtPacket_t *phcievt; + + while(LST_is_empty(&EvtQueue) == FALSE) + { + LST_remove_head (&EvtQueue, (tListNode **)&phcievt); + + if ( ((phcievt->evtserial.evt.evtcode) == TL_BLEEVT_CS_OPCODE) || ((phcievt->evtserial.evt.evtcode) == TL_BLEEVT_CC_OPCODE ) ) + { + OutputDbgTrace(TL_MB_BLE_CMD_RSP, (uint8_t*)phcievt); + } + else + { + OutputDbgTrace(TL_MB_BLE_ASYNCH_EVT, (uint8_t*)phcievt); + } + + BLE_IoBusEvtCallBackFunction(phcievt); + } + + return; +} + +int32_t TL_BLE_SendAclData( uint8_t* buffer, uint16_t size ) +{ + (void)(buffer); + (void)(size); + + ((TL_AclDataPacket_t *)(TL_RefTable.p_ble_table->phci_acl_data_buffer))->AclDataSerial.type = TL_ACL_DATA_PKT_TYPE; + + HW_IPCC_BLE_SendAclData(); + + return 0; +} + +void HW_IPCC_BLE_AclDataAckNot(void) +{ + BLE_IoBusAclDataTxAck( ); + + return; +} + +/****************************************************************************** + * SYSTEM + ******************************************************************************/ +int32_t TL_SYS_Init( void* pConf ) +{ + MB_SysTable_t * p_systable; + + TL_SYS_InitConf_t *pInitHciConf = (TL_SYS_InitConf_t *) pConf; + + LST_init_head (&SystemEvtQueue); + p_systable = TL_RefTable.p_sys_table; + p_systable->pcmd_buffer = pInitHciConf->p_cmdbuffer; + p_systable->sys_queue = (uint8_t*)&SystemEvtQueue; + + HW_IPCC_SYS_Init(); + + SYS_CMD_IoBusCallBackFunction = pInitHciConf->IoBusCallBackCmdEvt; + SYS_EVT_IoBusCallBackFunction = pInitHciConf->IoBusCallBackUserEvt; + + return 0; +} + +int32_t TL_SYS_SendCmd( uint8_t* buffer, uint16_t size ) +{ + (void)(buffer); + (void)(size); + + ((TL_CmdPacket_t *)(TL_RefTable.p_sys_table->pcmd_buffer))->cmdserial.type = TL_SYSCMD_PKT_TYPE; + + OutputDbgTrace(TL_MB_SYS_CMD, TL_RefTable.p_sys_table->pcmd_buffer); + + HW_IPCC_SYS_SendCmd(); + + return 0; +} + +void HW_IPCC_SYS_CmdEvtNot(void) +{ + OutputDbgTrace(TL_MB_SYS_CMD_RSP, (uint8_t*)(TL_RefTable.p_sys_table->pcmd_buffer) ); + + SYS_CMD_IoBusCallBackFunction( (TL_EvtPacket_t*)(TL_RefTable.p_sys_table->pcmd_buffer) ); + + return; +} + +void HW_IPCC_SYS_EvtNot( void ) +{ + TL_EvtPacket_t *p_evt; + + while(LST_is_empty(&SystemEvtQueue) == FALSE) + { + LST_remove_head (&SystemEvtQueue, (tListNode **)&p_evt); + + OutputDbgTrace(TL_MB_SYS_ASYNCH_EVT, (uint8_t*)p_evt ); + + SYS_EVT_IoBusCallBackFunction( p_evt ); + } + + return; +} + +/****************************************************************************** + * THREAD + ******************************************************************************/ +#ifdef THREAD_WB +void TL_THREAD_Init( TL_TH_Config_t *p_Config ) +{ + MB_ThreadTable_t * p_thread_table; + + p_thread_table = TL_RefTable.p_thread_table; + + p_thread_table->clicmdrsp_buffer = p_Config->p_ThreadCliRspBuffer; + p_thread_table->otcmdrsp_buffer = p_Config->p_ThreadOtCmdRspBuffer; + p_thread_table->notack_buffer = p_Config->p_ThreadNotAckBuffer; + p_thread_table->clinot_buffer = p_Config->p_ThreadCliNotBuffer; + + HW_IPCC_THREAD_Init(); + + return; +} + +void TL_OT_SendCmd( void ) +{ + ((TL_CmdPacket_t *)(TL_RefTable.p_thread_table->otcmdrsp_buffer))->cmdserial.type = TL_OTCMD_PKT_TYPE; + + HW_IPCC_OT_SendCmd(); + + return; +} + +void TL_CLI_SendCmd( void ) +{ + ((TL_CmdPacket_t *)(TL_RefTable.p_thread_table->clicmdrsp_buffer))->cmdserial.type = TL_CLICMD_PKT_TYPE; + + HW_IPCC_CLI_SendCmd(); + + return; +} + +void TL_THREAD_SendAck ( void ) +{ + ((TL_CmdPacket_t *)(TL_RefTable.p_thread_table->notack_buffer))->cmdserial.type = TL_OTACK_PKT_TYPE; + + HW_IPCC_THREAD_SendAck(); + + return; +} + +void TL_THREAD_CliSendAck ( void ) +{ + ((TL_CmdPacket_t *)(TL_RefTable.p_thread_table->notack_buffer))->cmdserial.type = TL_OTACK_PKT_TYPE; + + HW_IPCC_THREAD_CliSendAck(); + + return; +} + +void HW_IPCC_OT_CmdEvtNot(void) +{ + TL_OT_CmdEvtReceived( (TL_EvtPacket_t*)(TL_RefTable.p_thread_table->otcmdrsp_buffer) ); + + return; +} + +void HW_IPCC_THREAD_EvtNot( void ) +{ + TL_THREAD_NotReceived( (TL_EvtPacket_t*)(TL_RefTable.p_thread_table->notack_buffer) ); + + return; +} + +void HW_IPCC_THREAD_CliEvtNot( void ) +{ + TL_THREAD_CliNotReceived( (TL_EvtPacket_t*)(TL_RefTable.p_thread_table->clinot_buffer) ); + + return; +} + +__WEAK void TL_OT_CmdEvtReceived( TL_EvtPacket_t * Otbuffer ){}; +__WEAK void TL_THREAD_NotReceived( TL_EvtPacket_t * Notbuffer ){}; +__WEAK void TL_THREAD_CliNotReceived( TL_EvtPacket_t * Notbuffer ){}; + +#endif /* THREAD_WB */ + +/****************************************************************************** + * LLD TESTS + ******************************************************************************/ +#ifdef LLD_TESTS_WB +void TL_LLDTESTS_Init( TL_LLD_tests_Config_t *p_Config ) +{ + MB_LldTestsTable_t * p_lld_tests_table; + + p_lld_tests_table = TL_RefTable.p_lld_tests_table; + p_lld_tests_table->clicmdrsp_buffer = p_Config->p_LldTestsCliCmdRspBuffer; + p_lld_tests_table->m0cmd_buffer = p_Config->p_LldTestsM0CmdBuffer; + HW_IPCC_LLDTESTS_Init(); + return; +} + +void TL_LLDTESTS_SendCliCmd( void ) +{ + ((TL_CmdPacket_t *)(TL_RefTable.p_lld_tests_table->clicmdrsp_buffer))->cmdserial.type = TL_CLICMD_PKT_TYPE; + HW_IPCC_LLDTESTS_SendCliCmd(); + return; +} + +void HW_IPCC_LLDTESTS_ReceiveCliRsp( void ) +{ + TL_LLDTESTS_ReceiveCliRsp( (TL_CmdPacket_t*)(TL_RefTable.p_lld_tests_table->clicmdrsp_buffer) ); + return; +} + +void TL_LLDTESTS_SendCliRspAck( void ) +{ + HW_IPCC_LLDTESTS_SendCliRspAck(); + return; +} + +void HW_IPCC_LLDTESTS_ReceiveM0Cmd( void ) +{ + TL_LLDTESTS_ReceiveM0Cmd( (TL_CmdPacket_t*)(TL_RefTable.p_lld_tests_table->m0cmd_buffer) ); + return; +} + + +void TL_LLDTESTS_SendM0CmdAck( void ) +{ + HW_IPCC_LLDTESTS_SendM0CmdAck(); + return; +} + +__WEAK void TL_LLDTESTS_ReceiveCliRsp( TL_CmdPacket_t * Notbuffer ){}; +__WEAK void TL_LLDTESTS_ReceiveM0Cmd( TL_CmdPacket_t * Notbuffer ){}; +#endif /* LLD_TESTS_WB */ + +/****************************************************************************** + * BLE LLD + ******************************************************************************/ +#ifdef BLE_LLD_WB +void TL_BLE_LLD_Init( TL_BLE_LLD_Config_t *p_Config ) +{ + MB_BleLldTable_t * p_ble_lld_table; + + p_ble_lld_table = TL_RefTable.p_ble_lld_table; + p_ble_lld_table->cmdrsp_buffer = p_Config->p_BleLldCmdRspBuffer; + p_ble_lld_table->m0cmd_buffer = p_Config->p_BleLldM0CmdBuffer; + HW_IPCC_BLE_LLD_Init(); + return; +} + +void TL_BLE_LLD_SendCliCmd( void ) +{ + ((TL_CmdPacket_t *)(TL_RefTable.p_ble_lld_table->cmdrsp_buffer))->cmdserial.type = TL_CLICMD_PKT_TYPE; + HW_IPCC_BLE_LLD_SendCliCmd(); + return; +} + +void HW_IPCC_BLE_LLD_ReceiveCliRsp( void ) +{ + TL_BLE_LLD_ReceiveCliRsp( (TL_CmdPacket_t*)(TL_RefTable.p_ble_lld_table->cmdrsp_buffer) ); + return; +} + +void TL_BLE_LLD_SendCliRspAck( void ) +{ + HW_IPCC_BLE_LLD_SendCliRspAck(); + return; +} + +void HW_IPCC_BLE_LLD_ReceiveM0Cmd( void ) +{ + TL_BLE_LLD_ReceiveM0Cmd( (TL_CmdPacket_t*)(TL_RefTable.p_ble_lld_table->m0cmd_buffer) ); + return; +} + + +void TL_BLE_LLD_SendM0CmdAck( void ) +{ + HW_IPCC_BLE_LLD_SendM0CmdAck(); + return; +} + +__WEAK void TL_BLE_LLD_ReceiveCliRsp( TL_CmdPacket_t * Notbuffer ){}; +__WEAK void TL_BLE_LLD_ReceiveM0Cmd( TL_CmdPacket_t * Notbuffer ){}; + +/* Transparent Mode */ +void TL_BLE_LLD_SendCmd( void ) +{ + ((TL_CmdPacket_t *)(TL_RefTable.p_ble_lld_table->cmdrsp_buffer))->cmdserial.type = TL_CLICMD_PKT_TYPE; + HW_IPCC_BLE_LLD_SendCmd(); + return; +} + +void HW_IPCC_BLE_LLD_ReceiveRsp( void ) +{ + TL_BLE_LLD_ReceiveRsp( (TL_CmdPacket_t*)(TL_RefTable.p_ble_lld_table->cmdrsp_buffer) ); + return; +} + +void TL_BLE_LLD_SendRspAck( void ) +{ + HW_IPCC_BLE_LLD_SendRspAck(); + return; +} +#endif /* BLE_LLD_WB */ + +#ifdef MAC_802_15_4_WB +/****************************************************************************** + * MAC 802.15.4 + ******************************************************************************/ +void TL_MAC_802_15_4_Init( TL_MAC_802_15_4_Config_t *p_Config ) +{ + MB_Mac_802_15_4_t * p_mac_802_15_4_table; + + p_mac_802_15_4_table = TL_RefTable.p_mac_802_15_4_table; + + p_mac_802_15_4_table->p_cmdrsp_buffer = p_Config->p_Mac_802_15_4_CmdRspBuffer; + p_mac_802_15_4_table->p_notack_buffer = p_Config->p_Mac_802_15_4_NotAckBuffer; + + HW_IPCC_MAC_802_15_4_Init(); + + return; +} + +void TL_MAC_802_15_4_SendCmd( void ) +{ + ((TL_CmdPacket_t *)(TL_RefTable.p_mac_802_15_4_table->p_cmdrsp_buffer))->cmdserial.type = TL_OTCMD_PKT_TYPE; + + HW_IPCC_MAC_802_15_4_SendCmd(); + + return; +} + +void TL_MAC_802_15_4_SendAck ( void ) +{ + ((TL_CmdPacket_t *)(TL_RefTable.p_mac_802_15_4_table->p_notack_buffer))->cmdserial.type = TL_OTACK_PKT_TYPE; + + HW_IPCC_MAC_802_15_4_SendAck(); + + return; +} + +void HW_IPCC_MAC_802_15_4_CmdEvtNot(void) +{ + TL_MAC_802_15_4_CmdEvtReceived( (TL_EvtPacket_t*)(TL_RefTable.p_mac_802_15_4_table->p_cmdrsp_buffer) ); + + return; +} + +void HW_IPCC_MAC_802_15_4_EvtNot( void ) +{ + TL_MAC_802_15_4_NotReceived( (TL_EvtPacket_t*)(TL_RefTable.p_mac_802_15_4_table->p_notack_buffer) ); + + return; +} + +__WEAK void TL_MAC_802_15_4_CmdEvtReceived( TL_EvtPacket_t * Otbuffer ){}; +__WEAK void TL_MAC_802_15_4_NotReceived( TL_EvtPacket_t * Notbuffer ){}; +#endif + +#ifdef ZIGBEE_WB +/****************************************************************************** + * ZIGBEE + ******************************************************************************/ +void TL_ZIGBEE_Init( TL_ZIGBEE_Config_t *p_Config ) +{ + MB_ZigbeeTable_t * p_zigbee_table; + + p_zigbee_table = TL_RefTable.p_zigbee_table; + p_zigbee_table->appliCmdM4toM0_buffer = p_Config->p_ZigbeeOtCmdRspBuffer; + p_zigbee_table->notifM0toM4_buffer = p_Config->p_ZigbeeNotAckBuffer; + p_zigbee_table->requestM0toM4_buffer = p_Config->p_ZigbeeNotifRequestBuffer; + + HW_IPCC_ZIGBEE_Init(); + + return; +} + +/* Zigbee M4 to M0 Request */ +void TL_ZIGBEE_SendM4RequestToM0( void ) +{ + ((TL_CmdPacket_t *)(TL_RefTable.p_zigbee_table->appliCmdM4toM0_buffer))->cmdserial.type = TL_OTCMD_PKT_TYPE; + + HW_IPCC_ZIGBEE_SendM4RequestToM0(); + + return; +} + +/* Used to receive an ACK from the M0 */ +void HW_IPCC_ZIGBEE_RecvAppliAckFromM0(void) +{ + TL_ZIGBEE_CmdEvtReceived( (TL_EvtPacket_t*)(TL_RefTable.p_zigbee_table->appliCmdM4toM0_buffer) ); + + return; +} + +/* Zigbee notification from M0 to M4 */ +void HW_IPCC_ZIGBEE_RecvM0NotifyToM4( void ) +{ + TL_ZIGBEE_NotReceived( (TL_EvtPacket_t*)(TL_RefTable.p_zigbee_table->notifM0toM4_buffer) ); + + return; +} + +/* Send an ACK to the M0 for a Notification */ +void TL_ZIGBEE_SendM4AckToM0Notify ( void ) +{ + ((TL_CmdPacket_t *)(TL_RefTable.p_zigbee_table->notifM0toM4_buffer))->cmdserial.type = TL_OTACK_PKT_TYPE; + + HW_IPCC_ZIGBEE_SendM4AckToM0Notify(); + + return; +} + +/* Zigbee M0 to M4 Request */ +void HW_IPCC_ZIGBEE_RecvM0RequestToM4( void ) +{ + TL_ZIGBEE_M0RequestReceived( (TL_EvtPacket_t*)(TL_RefTable.p_zigbee_table->requestM0toM4_buffer) ); + + return; +} + +/* Send an ACK to the M0 for a Request */ +void TL_ZIGBEE_SendM4AckToM0Request(void) +{ + ((TL_CmdPacket_t *)(TL_RefTable.p_zigbee_table->requestM0toM4_buffer))->cmdserial.type = TL_OTACK_PKT_TYPE; + + HW_IPCC_ZIGBEE_SendM4AckToM0Request(); + + return; +} + + +__WEAK void TL_ZIGBEE_CmdEvtReceived( TL_EvtPacket_t * Otbuffer ){}; +__WEAK void TL_ZIGBEE_NotReceived( TL_EvtPacket_t * Notbuffer ){}; +#endif + + + +/****************************************************************************** + * MEMORY MANAGER + ******************************************************************************/ +void TL_MM_Init( TL_MM_Config_t *p_Config ) +{ + static MB_MemManagerTable_t * p_mem_manager_table; + + LST_init_head (&FreeBufQueue); + LST_init_head (&LocalFreeBufQueue); + + p_mem_manager_table = TL_RefTable.p_mem_manager_table; + + p_mem_manager_table->blepool = p_Config->p_AsynchEvtPool; + p_mem_manager_table->blepoolsize = p_Config->AsynchEvtPoolSize; + p_mem_manager_table->pevt_free_buffer_queue = (uint8_t*)&FreeBufQueue; + p_mem_manager_table->spare_ble_buffer = p_Config->p_BleSpareEvtBuffer; + p_mem_manager_table->spare_sys_buffer = p_Config->p_SystemSpareEvtBuffer; + p_mem_manager_table->traces_evt_pool = p_Config->p_TracesEvtPool; + p_mem_manager_table->tracespoolsize = p_Config->TracesEvtPoolSize; + + return; +} + +void TL_MM_EvtDone(TL_EvtPacket_t * phcievt) +{ + LST_insert_tail(&LocalFreeBufQueue, (tListNode *)phcievt); + + OutputDbgTrace(TL_MB_MM_RELEASE_BUFFER, (uint8_t*)phcievt); + + HW_IPCC_MM_SendFreeBuf( SendFreeBuf ); + + return; +} + +static void SendFreeBuf( void ) +{ + tListNode *p_node; + + while ( FALSE == LST_is_empty (&LocalFreeBufQueue) ) + { + LST_remove_head( &LocalFreeBufQueue, (tListNode **)&p_node ); + LST_insert_tail( (tListNode*)(TL_RefTable.p_mem_manager_table->pevt_free_buffer_queue), p_node ); + } + + return; +} + +/****************************************************************************** + * TRACES + ******************************************************************************/ +void TL_TRACES_Init( void ) +{ + LST_init_head (&TracesEvtQueue); + + TL_RefTable.p_traces_table->traces_queue = (uint8_t*)&TracesEvtQueue; + + HW_IPCC_TRACES_Init(); + + return; +} + +void HW_IPCC_TRACES_EvtNot(void) +{ + TL_EvtPacket_t *phcievt; + + while(LST_is_empty(&TracesEvtQueue) == FALSE) + { + LST_remove_head (&TracesEvtQueue, (tListNode **)&phcievt); + TL_TRACES_EvtReceived( phcievt ); + } + + return; +} + +__WEAK void TL_TRACES_EvtReceived( TL_EvtPacket_t * hcievt ) +{ + (void)(hcievt); +} + +/****************************************************************************** + * DEBUG INFORMATION + ******************************************************************************/ +static void OutputDbgTrace(TL_MB_PacketType_t packet_type, uint8_t* buffer) +{ + TL_EvtPacket_t *p_evt_packet; + TL_CmdPacket_t *p_cmd_packet; + TL_EvtSerial_t *p_cmd_rsp_packet; + + switch(packet_type) + { + case TL_MB_MM_RELEASE_BUFFER: + p_evt_packet = (TL_EvtPacket_t*)buffer; + switch(p_evt_packet->evtserial.evt.evtcode) + { + case TL_BLEEVT_CS_OPCODE: + TL_MM_DBG_MSG("mm evt released: 0x%02X", p_evt_packet->evtserial.evt.evtcode); + TL_MM_DBG_MSG(" cmd opcode: 0x%04X", ((TL_CsEvt_t*)(p_evt_packet->evtserial.evt.payload))->cmdcode); + TL_MM_DBG_MSG(" buffer addr: 0x%08X", p_evt_packet); + break; + + case TL_BLEEVT_CC_OPCODE: + TL_MM_DBG_MSG("mm evt released: 0x%02X", p_evt_packet->evtserial.evt.evtcode); + TL_MM_DBG_MSG(" cmd opcode: 0x%04X", ((TL_CcEvt_t*)(p_evt_packet->evtserial.evt.payload))->cmdcode); + TL_MM_DBG_MSG(" buffer addr: 0x%08X", p_evt_packet); + break; + + case TL_BLEEVT_VS_OPCODE: + TL_MM_DBG_MSG("mm evt released: 0x%02X", p_evt_packet->evtserial.evt.evtcode); + TL_MM_DBG_MSG(" subevtcode: 0x%04X", ((TL_AsynchEvt_t*)(p_evt_packet->evtserial.evt.payload))->subevtcode); + TL_MM_DBG_MSG(" buffer addr: 0x%08X", p_evt_packet); + break; + + default: + TL_MM_DBG_MSG("mm evt released: 0x%02X", p_evt_packet->evtserial.evt.evtcode); + TL_MM_DBG_MSG(" buffer addr: 0x%08X", p_evt_packet); + break; + } + + TL_MM_DBG_MSG("\r\n"); + break; + + case TL_MB_BLE_CMD: + p_cmd_packet = (TL_CmdPacket_t*)buffer; + TL_HCI_CMD_DBG_MSG("ble cmd: 0x%04X", p_cmd_packet->cmdserial.cmd.cmdcode); + if(p_cmd_packet->cmdserial.cmd.plen != 0) + { + TL_HCI_CMD_DBG_MSG(" payload:"); + TL_HCI_CMD_DBG_BUF(p_cmd_packet->cmdserial.cmd.payload, p_cmd_packet->cmdserial.cmd.plen, ""); + } + TL_HCI_CMD_DBG_MSG("\r\n"); + + TL_HCI_CMD_DBG_RAW(&p_cmd_packet->cmdserial, p_cmd_packet->cmdserial.cmd.plen+TL_CMD_HDR_SIZE); + break; + + case TL_MB_BLE_CMD_RSP: + p_evt_packet = (TL_EvtPacket_t*)buffer; + switch(p_evt_packet->evtserial.evt.evtcode) + { + case TL_BLEEVT_CS_OPCODE: + TL_HCI_CMD_DBG_MSG("ble rsp: 0x%02X", p_evt_packet->evtserial.evt.evtcode); + TL_HCI_CMD_DBG_MSG(" cmd opcode: 0x%04X", ((TL_CsEvt_t*)(p_evt_packet->evtserial.evt.payload))->cmdcode); + TL_HCI_CMD_DBG_MSG(" numhci: 0x%02X", ((TL_CsEvt_t*)(p_evt_packet->evtserial.evt.payload))->numcmd); + TL_HCI_CMD_DBG_MSG(" status: 0x%02X", ((TL_CsEvt_t*)(p_evt_packet->evtserial.evt.payload))->status); + break; + + case TL_BLEEVT_CC_OPCODE: + TL_HCI_CMD_DBG_MSG("ble rsp: 0x%02X", p_evt_packet->evtserial.evt.evtcode); + TL_HCI_CMD_DBG_MSG(" cmd opcode: 0x%04X", ((TL_CcEvt_t*)(p_evt_packet->evtserial.evt.payload))->cmdcode); + TL_HCI_CMD_DBG_MSG(" numhci: 0x%02X", ((TL_CcEvt_t*)(p_evt_packet->evtserial.evt.payload))->numcmd); + TL_HCI_CMD_DBG_MSG(" status: 0x%02X", ((TL_CcEvt_t*)(p_evt_packet->evtserial.evt.payload))->payload[0]); + if((p_evt_packet->evtserial.evt.plen-4) != 0) + { + TL_HCI_CMD_DBG_MSG(" payload:"); + TL_HCI_CMD_DBG_BUF(&((TL_CcEvt_t*)(p_evt_packet->evtserial.evt.payload))->payload[1], p_evt_packet->evtserial.evt.plen-4, ""); + } + break; + + default: + TL_HCI_CMD_DBG_MSG("unknown ble rsp received: %02X", p_evt_packet->evtserial.evt.evtcode); + break; + } + + TL_HCI_CMD_DBG_MSG("\r\n"); + + TL_HCI_CMD_DBG_RAW(&p_evt_packet->evtserial, p_evt_packet->evtserial.evt.plen+TL_EVT_HDR_SIZE); + break; + + case TL_MB_BLE_ASYNCH_EVT: + p_evt_packet = (TL_EvtPacket_t*)buffer; + if(p_evt_packet->evtserial.evt.evtcode != TL_BLEEVT_VS_OPCODE) + { + TL_HCI_EVT_DBG_MSG("ble evt: 0x%02X", p_evt_packet->evtserial.evt.evtcode); + if((p_evt_packet->evtserial.evt.plen) != 0) + { + TL_HCI_EVT_DBG_MSG(" payload:"); + TL_HCI_EVT_DBG_BUF(p_evt_packet->evtserial.evt.payload, p_evt_packet->evtserial.evt.plen, ""); + } + } + else + { + TL_HCI_EVT_DBG_MSG("ble evt: 0x%02X", p_evt_packet->evtserial.evt.evtcode); + TL_HCI_EVT_DBG_MSG(" subevtcode: 0x%04X", ((TL_AsynchEvt_t*)(p_evt_packet->evtserial.evt.payload))->subevtcode); + if((p_evt_packet->evtserial.evt.plen-2) != 0) + { + TL_HCI_EVT_DBG_MSG(" payload:"); + TL_HCI_EVT_DBG_BUF(((TL_AsynchEvt_t*)(p_evt_packet->evtserial.evt.payload))->payload, p_evt_packet->evtserial.evt.plen-2, ""); + } + } + + TL_HCI_EVT_DBG_MSG("\r\n"); + + TL_HCI_EVT_DBG_RAW(&p_evt_packet->evtserial, p_evt_packet->evtserial.evt.plen+TL_EVT_HDR_SIZE); + break; + + case TL_MB_SYS_CMD: + p_cmd_packet = (TL_CmdPacket_t*)buffer; + + TL_SHCI_CMD_DBG_MSG("sys cmd: 0x%04X", p_cmd_packet->cmdserial.cmd.cmdcode); + + if(p_cmd_packet->cmdserial.cmd.plen != 0) + { + TL_SHCI_CMD_DBG_MSG(" payload:"); + TL_SHCI_CMD_DBG_BUF(p_cmd_packet->cmdserial.cmd.payload, p_cmd_packet->cmdserial.cmd.plen, ""); + } + TL_SHCI_CMD_DBG_MSG("\r\n"); + + TL_SHCI_CMD_DBG_RAW(&p_cmd_packet->cmdserial, p_cmd_packet->cmdserial.cmd.plen+TL_CMD_HDR_SIZE); + break; + + case TL_MB_SYS_CMD_RSP: + p_cmd_rsp_packet = (TL_EvtSerial_t*)buffer; + switch(p_cmd_rsp_packet->evt.evtcode) + { + case TL_BLEEVT_CC_OPCODE: + TL_SHCI_CMD_DBG_MSG("sys rsp: 0x%02X", p_cmd_rsp_packet->evt.evtcode); + TL_SHCI_CMD_DBG_MSG(" cmd opcode: 0x%02X", ((TL_CcEvt_t*)(p_cmd_rsp_packet->evt.payload))->cmdcode); + TL_SHCI_CMD_DBG_MSG(" status: 0x%02X", ((TL_CcEvt_t*)(p_cmd_rsp_packet->evt.payload))->payload[0]); + if((p_cmd_rsp_packet->evt.plen-4) != 0) + { + TL_SHCI_CMD_DBG_MSG(" payload:"); + TL_SHCI_CMD_DBG_BUF(&((TL_CcEvt_t*)(p_cmd_rsp_packet->evt.payload))->payload[1], p_cmd_rsp_packet->evt.plen-4, ""); + } + break; + + default: + TL_SHCI_CMD_DBG_MSG("unknown sys rsp received: %02X", p_cmd_rsp_packet->evt.evtcode); + break; + } + + TL_SHCI_CMD_DBG_MSG("\r\n"); + + TL_SHCI_CMD_DBG_RAW(&p_cmd_rsp_packet->evt, p_cmd_rsp_packet->evt.plen+TL_EVT_HDR_SIZE); + break; + + case TL_MB_SYS_ASYNCH_EVT: + p_evt_packet = (TL_EvtPacket_t*)buffer; + if(p_evt_packet->evtserial.evt.evtcode != TL_BLEEVT_VS_OPCODE) + { + TL_SHCI_EVT_DBG_MSG("unknown sys evt received: %02X", p_evt_packet->evtserial.evt.evtcode); + } + else + { + TL_SHCI_EVT_DBG_MSG("sys evt: 0x%02X", p_evt_packet->evtserial.evt.evtcode); + TL_SHCI_EVT_DBG_MSG(" subevtcode: 0x%04X", ((TL_AsynchEvt_t*)(p_evt_packet->evtserial.evt.payload))->subevtcode); + if((p_evt_packet->evtserial.evt.plen-2) != 0) + { + TL_SHCI_EVT_DBG_MSG(" payload:"); + TL_SHCI_EVT_DBG_BUF(((TL_AsynchEvt_t*)(p_evt_packet->evtserial.evt.payload))->payload, p_evt_packet->evtserial.evt.plen-2, ""); + } + } + + TL_SHCI_EVT_DBG_MSG("\r\n"); + + TL_SHCI_EVT_DBG_RAW(&p_evt_packet->evtserial, p_evt_packet->evtserial.evt.plen+TL_EVT_HDR_SIZE); + break; + + default: + break; + } + + return; +} +#endif /* STM32WBxx */ diff --git a/src/utility/STM32_WPAN/utilities_conf.h b/src/utility/STM32_WPAN/utilities_conf.h new file mode 100644 index 00000000..d6221a73 --- /dev/null +++ b/src/utility/STM32_WPAN/utilities_conf.h @@ -0,0 +1,66 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file utilities_conf.h + * @author MCD Application Team + * @brief Configuration file for STM32 Utilities. + ****************************************************************************** + * @attention + * + * Copyright (c) 2019-2021 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef UTILITIES_CONF_H +#define UTILITIES_CONF_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "cmsis_compiler.h" +#include "string.h" +#include "app_conf.h" + +/****************************************************************************** + * common + ******************************************************************************/ +#define UTILS_ENTER_CRITICAL_SECTION( ) uint32_t primask_bit = __get_PRIMASK( );\ + __disable_irq( ) + +#define UTILS_EXIT_CRITICAL_SECTION( ) __set_PRIMASK( primask_bit ) + +#define UTILS_MEMSET8( dest, value, size ) memset( dest, value, size); + +/****************************************************************************** + * tiny low power manager + * (any macro that does not need to be modified can be removed) + ******************************************************************************/ +#define UTIL_LPM_INIT_CRITICAL_SECTION( ) +#define UTIL_LPM_ENTER_CRITICAL_SECTION( ) UTILS_ENTER_CRITICAL_SECTION( ) +#define UTIL_LPM_EXIT_CRITICAL_SECTION( ) UTILS_EXIT_CRITICAL_SECTION( ) + +/****************************************************************************** + * sequencer + * (any macro that does not need to be modified can be removed) + ******************************************************************************/ +#define UTIL_SEQ_INIT_CRITICAL_SECTION( ) +#define UTIL_SEQ_ENTER_CRITICAL_SECTION( ) UTILS_ENTER_CRITICAL_SECTION( ) +#define UTIL_SEQ_EXIT_CRITICAL_SECTION( ) UTILS_EXIT_CRITICAL_SECTION( ) +#define UTIL_SEQ_CONF_TASK_NBR (32) +#define UTIL_SEQ_CONF_PRIO_NBR CFG_SCH_PRIO_NBR +#define UTIL_SEQ_MEMSET8( dest, value, size ) UTILS_MEMSET8( dest, value, size ) + +#ifdef __cplusplus +} +#endif + +#endif /*UTILITIES_CONF_H */ From 5293858c42ff57748d672a64ad80d9abf95f1f36 Mon Sep 17 00:00:00 2001 From: Alexandre Bourdiol <alexandre.bourdiol@st.com> Date: Tue, 18 Mar 2025 09:42:32 +0100 Subject: [PATCH 187/226] feat: add patch files to be applied on stm32wb Cube update Signed-off-by: Alexandre Bourdiol <alexandre.bourdiol@st.com> --- .../0001-chore-adapt-STM32_WPAN-sources.patch | 310 ++++++++++++++++++ ...imeout-when-waiting-for-the-cmd_resp.patch | 41 +++ ...ort-for-customize-app_conf_default.h.patch | 135 ++++++++ ...-fix-TL_Evt_t-payload-size-for-reset.patch | 30 ++ 4 files changed, 516 insertions(+) create mode 100644 extras/STM32_WPAN/0001-chore-adapt-STM32_WPAN-sources.patch create mode 100644 extras/STM32_WPAN/0002-fix-include-a-timeout-when-waiting-for-the-cmd_resp.patch create mode 100644 extras/STM32_WPAN/0003-chore-add-support-for-customize-app_conf_default.h.patch create mode 100644 extras/STM32_WPAN/0004-fix-TL_Evt_t-payload-size-for-reset.patch diff --git a/extras/STM32_WPAN/0001-chore-adapt-STM32_WPAN-sources.patch b/extras/STM32_WPAN/0001-chore-adapt-STM32_WPAN-sources.patch new file mode 100644 index 00000000..a3f62011 --- /dev/null +++ b/extras/STM32_WPAN/0001-chore-adapt-STM32_WPAN-sources.patch @@ -0,0 +1,310 @@ +From 7f99c89e8a6f834daf4a76bf98307e9ebcd01c91 Mon Sep 17 00:00:00 2001 +From: Frederic Pillon <frederic.pillon@st.com> +Date: Wed, 10 Jan 2024 18:16:01 +0100 +Subject: [PATCH 1/4] chore: adapt STM32_WPAN sources + +Signed-off-by: Frederic Pillon <frederic.pillon@st.com> +--- + src/utility/STM32_WPAN/app_conf_default.h | 49 +++++++++++++++++++---- + src/utility/STM32_WPAN/hw.h | 13 +++++- + src/utility/STM32_WPAN/hw_ipcc.c | 4 +- + src/utility/STM32_WPAN/shci.c | 2 + + src/utility/STM32_WPAN/shci_tl.c | 17 ++++++++ + src/utility/STM32_WPAN/stm_list.c | 6 ++- + src/utility/STM32_WPAN/tl_mbox.c | 6 +++ + 7 files changed, 85 insertions(+), 12 deletions(-) + +diff --git a/src/utility/STM32_WPAN/app_conf_default.h b/src/utility/STM32_WPAN/app_conf_default.h +index 71fc107..bf2274a 100644 +--- a/src/utility/STM32_WPAN/app_conf_default.h ++++ b/src/utility/STM32_WPAN/app_conf_default.h +@@ -1,9 +1,9 @@ + /* USER CODE BEGIN Header */ + /** + ****************************************************************************** +- * @file app_conf.h ++ * @file app_conf_default.h + * @author MCD Application Team +- * @brief Application configuration file for STM32WPAN Middleware. ++ * @brief Default application configuration file for STM32WPAN Middleware. + ****************************************************************************** + * @attention + * +@@ -19,18 +19,40 @@ + /* USER CODE END Header */ + + /* Define to prevent recursive inclusion -------------------------------------*/ +-#ifndef APP_CONF_H +-#define APP_CONF_H ++#ifndef APP_CONF_DEFAULT_H ++#define APP_CONF_DEFAULT_H + ++#if 0 + #include "hw.h" + #include "hw_conf.h" + #include "hw_if.h" + #include "ble_bufsize.h" ++#endif + + /****************************************************************************** + * Application Config + ******************************************************************************/ + ++/**< generic parameters ******************************************************/ ++/* HCI related defines */ ++ ++#define ACI_HAL_SET_TX_POWER_LEVEL 0xFC0F ++#define ACI_WRITE_CONFIG_DATA_OPCODE 0xFC0C ++#define ACI_READ_CONFIG_DATA_OPCODE 0xFC0D ++#define MAX_HCI_ACL_PACKET_SIZE (sizeof(TL_PacketHeader_t) + 5 + 251) ++#define HCI_RESET 0x0C03 ++ ++#ifndef BLE_SHARED_MEM_BYTE_ORDER ++ #define BLE_SHARED_MEM_BYTE_ORDER MSBFIRST ++#endif ++#define BLE_MODULE_SHARED_MEM_BUFFER_SIZE 128 ++ ++/** ++ * Define Tx Power ++ */ ++#define CFG_TX_POWER (0x18) /* -0.15dBm */ ++ ++#if 0 + /** + * Define Secure Connections Support + */ +@@ -104,6 +126,7 @@ + #define CFG_FW_SUBVERSION (1) + #define CFG_FW_BRANCH (0) + #define CFG_FW_BUILD (0) ++#endif + + /****************************************************************************** + * BLE Stack +@@ -250,7 +273,7 @@ + * 0: LE Power Class 2-3 + * other bits: complete with Options_extension flag + */ +-#define CFG_BLE_OPTIONS (SHCI_C2_BLE_INIT_OPTIONS_LL_HOST | SHCI_C2_BLE_INIT_OPTIONS_WITH_SVC_CHANGE_DESC | SHCI_C2_BLE_INIT_OPTIONS_DEVICE_NAME_RW | SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV | SHCI_C2_BLE_INIT_OPTIONS_CS_ALGO2 | SHCI_C2_BLE_INIT_OPTIONS_FULL_GATTDB_NVM | SHCI_C2_BLE_INIT_OPTIONS_GATT_CACHING_NOTUSED | SHCI_C2_BLE_INIT_OPTIONS_POWER_CLASS_2_3) ++#define CFG_BLE_OPTIONS (SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY | SHCI_C2_BLE_INIT_OPTIONS_WITH_SVC_CHANGE_DESC | SHCI_C2_BLE_INIT_OPTIONS_DEVICE_NAME_RW | SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV | SHCI_C2_BLE_INIT_OPTIONS_CS_ALGO2 | SHCI_C2_BLE_INIT_OPTIONS_FULL_GATTDB_NVM | SHCI_C2_BLE_INIT_OPTIONS_GATT_CACHING_NOTUSED | SHCI_C2_BLE_INIT_OPTIONS_POWER_CLASS_2_3) + + /** + * BLE stack Options_extension flags to be configured with: +@@ -292,7 +315,11 @@ + * This parameter is considered by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV flag set + */ + +-#define CFG_BLE_MAX_ADV_SET_NBR (8) ++#if defined(STM32WB15xx) ++ #define CFG_BLE_MAX_ADV_SET_NBR (3) ++#else ++ #define CFG_BLE_MAX_ADV_SET_NBR (8) ++#endif + + /* Maximum advertising data length (in bytes) + * Range: 31 .. 1650 with limitation: +@@ -301,7 +328,11 @@ + * This parameter is considered by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV flag set + */ + +-#define CFG_BLE_MAX_ADV_DATA_LEN (207) ++#if defined(STM32WB15xx) ++ #define CFG_BLE_MAX_ADV_DATA_LEN (414) ++#else ++ #define CFG_BLE_MAX_ADV_DATA_LEN (207) ++#endif + + /* RF TX Path Compensation Value (16-bit signed integer). Units: 0.1 dB. + * Range: -1280 .. 1280 +@@ -324,6 +355,7 @@ + + #define CFG_BLE_CORE_VERSION (SHCI_C2_BLE_INIT_BLE_CORE_5_4) + ++#if 0 + /****************************************************************************** + * Transport Layer + ******************************************************************************/ +@@ -660,4 +692,5 @@ typedef enum + + #define CFG_OTP_END_ADRESS OTP_AREA_END_ADDR + +-#endif /*APP_CONF_H */ ++#endif ++#endif /*APP_CONF_DEFAULT_H */ +diff --git a/src/utility/STM32_WPAN/hw.h b/src/utility/STM32_WPAN/hw.h +index 651e1f1..1472a5e 100644 +--- a/src/utility/STM32_WPAN/hw.h ++++ b/src/utility/STM32_WPAN/hw.h +@@ -26,14 +26,23 @@ extern "C" { + #endif + + /* Includes ------------------------------------------------------------------*/ ++#include "stm32_def.h" ++#include "stm32wbxx_ll_bus.h" ++#include "stm32wbxx_ll_exti.h" ++#include "stm32wbxx_ll_system.h" ++#include "stm32wbxx_ll_rcc.h" ++#include "stm32wbxx_ll_ipcc.h" ++#include "stm32wbxx_ll_cortex.h" ++#include "stm32wbxx_ll_utils.h" ++#include "stm32wbxx_ll_pwr.h" + + /****************************************************************************** + * HW IPCC + ******************************************************************************/ + void HW_IPCC_Enable( void ); + void HW_IPCC_Init( void ); +- void HW_IPCC_Rx_Handler( void ); +- void HW_IPCC_Tx_Handler( void ); ++#define HW_IPCC_Rx_Handler IPCC_C1_RX_IRQHandler ++#define HW_IPCC_Tx_Handler IPCC_C1_TX_IRQHandler + + void HW_IPCC_BLE_Init( void ); + void HW_IPCC_BLE_SendCmd( void ); +diff --git a/src/utility/STM32_WPAN/hw_ipcc.c b/src/utility/STM32_WPAN/hw_ipcc.c +index 6a311b1..ad3c9d4 100644 +--- a/src/utility/STM32_WPAN/hw_ipcc.c ++++ b/src/utility/STM32_WPAN/hw_ipcc.c +@@ -18,8 +18,9 @@ + */ + /* USER CODE END Header */ + ++#if defined(STM32WBxx) + /* Includes ------------------------------------------------------------------*/ +-#include "app_common.h" ++#include "hw.h" + #include "mbox_def.h" + #include "utilities_conf.h" + +@@ -745,3 +746,4 @@ static void HW_IPCC_TRACES_EvtHandler( void ) + } + + __weak void HW_IPCC_TRACES_EvtNot( void ){}; ++#endif /* STM32WBxx */ +diff --git a/src/utility/STM32_WPAN/shci.c b/src/utility/STM32_WPAN/shci.c +index 5c32555..40110f4 100644 +--- a/src/utility/STM32_WPAN/shci.c ++++ b/src/utility/STM32_WPAN/shci.c +@@ -17,6 +17,7 @@ + */ + + ++#if defined(STM32WBxx) + /* Includes ------------------------------------------------------------------*/ + #include "stm32_wpan_common.h" + +@@ -759,3 +760,4 @@ SHCI_CmdStatus_t SHCI_GetWirelessFwInfo( WirelessFwInfo_t* pWirelessInfo ) + + return (SHCI_Success); + } ++#endif /* STM32WBxx */ +diff --git a/src/utility/STM32_WPAN/shci_tl.c b/src/utility/STM32_WPAN/shci_tl.c +index 0f60430..daa988c 100644 +--- a/src/utility/STM32_WPAN/shci_tl.c ++++ b/src/utility/STM32_WPAN/shci_tl.c +@@ -17,11 +17,13 @@ + */ + + ++#if defined(STM32WBxx) + /* Includes ------------------------------------------------------------------*/ + #include "stm32_wpan_common.h" + + #include "stm_list.h" + #include "shci_tl.h" ++#include "stm32_def.h" + + /* Private typedef -----------------------------------------------------------*/ + typedef enum +@@ -168,6 +170,20 @@ void shci_send( uint16_t cmd_code, uint8_t len_cmd_payload, uint8_t * p_cmd_payl + return; + } + ++void shci_notify_asynch_evt(void *pdata) ++{ ++ UNUSED(pdata); ++ /* Need to parse data in future version */ ++ shci_user_evt_proc(); ++} ++ ++void shci_register_io_bus(tSHciIO *fops) ++{ ++ /* Register IO bus services */ ++ fops->Init = TL_SYS_Init; ++ fops->Send = TL_SYS_SendCmd; ++} ++ + /* Private functions ---------------------------------------------------------*/ + static void TlInit( TL_CmdPacket_t * p_cmdbuffer ) + { +@@ -250,3 +266,4 @@ __WEAK void shci_cmd_resp_release(uint32_t flag) + + return; + } ++#endif /* STM32WBxx */ +diff --git a/src/utility/STM32_WPAN/stm_list.c b/src/utility/STM32_WPAN/stm_list.c +index 4c92864..df6c215 100644 +--- a/src/utility/STM32_WPAN/stm_list.c ++++ b/src/utility/STM32_WPAN/stm_list.c +@@ -17,10 +17,13 @@ + */ + + ++#if defined(STM32WBxx) + /****************************************************************************** + * Include Files + ******************************************************************************/ +-#include "utilities_common.h" ++#include "stdint.h" ++#include "cmsis_gcc.h" ++#include "stm32_wpan_common.h" + + #include "stm_list.h" + +@@ -204,3 +207,4 @@ void LST_get_prev_node (tListNode * ref_node, tListNode ** node) + + __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ + } ++#endif /* STM32WBxx */ +diff --git a/src/utility/STM32_WPAN/tl_mbox.c b/src/utility/STM32_WPAN/tl_mbox.c +index df07a19..9a2a297 100644 +--- a/src/utility/STM32_WPAN/tl_mbox.c ++++ b/src/utility/STM32_WPAN/tl_mbox.c +@@ -16,6 +16,7 @@ + ****************************************************************************** + */ + ++#if defined(STM32WBxx) + /* Includes ------------------------------------------------------------------*/ + #include "stm32_wpan_common.h" + #include "hw.h" +@@ -51,8 +52,10 @@ PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_BleLldTable_t TL_BleLldTable; + PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_SysTable_t TL_SysTable; + PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_MemManagerTable_t TL_MemManagerTable; + PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_TracesTable_t TL_TracesTable; ++#if 0 + PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_Mac_802_15_4_t TL_Mac_802_15_4_Table; + PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_ZigbeeTable_t TL_Zigbee_Table; ++#endif + + /**< tables */ + PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode FreeBufQueue; +@@ -97,8 +100,10 @@ void TL_Init( void ) + TL_RefTable.p_sys_table = &TL_SysTable; + TL_RefTable.p_mem_manager_table = &TL_MemManagerTable; + TL_RefTable.p_traces_table = &TL_TracesTable; ++#if 0 + TL_RefTable.p_mac_802_15_4_table = &TL_Mac_802_15_4_Table; + TL_RefTable.p_zigbee_table = &TL_Zigbee_Table; ++#endif + HW_IPCC_Init(); + + return; +@@ -847,3 +852,4 @@ static void OutputDbgTrace(TL_MB_PacketType_t packet_type, uint8_t* buffer) + + return; + } ++#endif /* STM32WBxx */ +-- +2.34.1 + diff --git a/extras/STM32_WPAN/0002-fix-include-a-timeout-when-waiting-for-the-cmd_resp.patch b/extras/STM32_WPAN/0002-fix-include-a-timeout-when-waiting-for-the-cmd_resp.patch new file mode 100644 index 00000000..bd6f66a2 --- /dev/null +++ b/extras/STM32_WPAN/0002-fix-include-a-timeout-when-waiting-for-the-cmd_resp.patch @@ -0,0 +1,41 @@ +From a33328182e334e1ddedd368a047d75cf1662e330 Mon Sep 17 00:00:00 2001 +From: Frederic Pillon <frederic.pillon@st.com> +Date: Thu, 13 Jul 2023 17:16:40 +0200 +Subject: [PATCH 2/4] fix: include a timeout when waiting for the cmd_resp + +Signed-off-by: Frederic Pillon <frederic.pillon@st.com> +--- + src/utility/STM32_WPAN/shci_tl.c | 10 ++++++---- + 1 file changed, 6 insertions(+), 4 deletions(-) + +diff --git a/src/utility/STM32_WPAN/shci_tl.c b/src/utility/STM32_WPAN/shci_tl.c +index daa988c..25e1a21 100644 +--- a/src/utility/STM32_WPAN/shci_tl.c ++++ b/src/utility/STM32_WPAN/shci_tl.c +@@ -24,6 +24,7 @@ + #include "stm_list.h" + #include "shci_tl.h" + #include "stm32_def.h" ++#include "wiring_time.h" + + /* Private typedef -----------------------------------------------------------*/ + typedef enum +@@ -251,10 +252,11 @@ static void TlUserEvtReceived(TL_EvtPacket_t *shcievt) + /* Weak implementation ----------------------------------------------------------------*/ + __WEAK void shci_cmd_resp_wait(uint32_t timeout) + { +- (void)timeout; +- +- while(CmdRspStatusFlag != SHCI_TL_CMD_RESP_RELEASE); +- ++ for (unsigned long start = millis(); (millis() - start) < timeout;) { ++ if (CmdRspStatusFlag == SHCI_TL_CMD_RESP_RELEASE) { ++ break; ++ } ++ } + return; + } + +-- +2.34.1 + diff --git a/extras/STM32_WPAN/0003-chore-add-support-for-customize-app_conf_default.h.patch b/extras/STM32_WPAN/0003-chore-add-support-for-customize-app_conf_default.h.patch new file mode 100644 index 00000000..3c5e66ae --- /dev/null +++ b/extras/STM32_WPAN/0003-chore-add-support-for-customize-app_conf_default.h.patch @@ -0,0 +1,135 @@ +From a973b405bf34a93b0c300c8bbc4aa5d59fa182e5 Mon Sep 17 00:00:00 2001 +From: Frederic Pillon <frederic.pillon@st.com> +Date: Wed, 10 Jan 2024 18:45:17 +0100 +Subject: [PATCH 3/4] chore: add support for customize app_conf_default.h + +Signed-off-by: Frederic Pillon <frederic.pillon@st.com> +--- + src/utility/STM32_WPAN/app_conf_default.h | 58 ++++++++++++++++++----- + 1 file changed, 45 insertions(+), 13 deletions(-) + +diff --git a/src/utility/STM32_WPAN/app_conf_default.h b/src/utility/STM32_WPAN/app_conf_default.h +index bf2274a..ff2dc01 100644 +--- a/src/utility/STM32_WPAN/app_conf_default.h ++++ b/src/utility/STM32_WPAN/app_conf_default.h +@@ -50,7 +50,9 @@ + /** + * Define Tx Power + */ +-#define CFG_TX_POWER (0x18) /* -0.15dBm */ ++#ifndef CFG_TX_POWER ++ #define CFG_TX_POWER (0x18) /* -0.15dBm */ ++#endif + + #if 0 + /** +@@ -135,13 +137,25 @@ + * Maximum number of simultaneous connections that the device will support. + * Valid values are from 1 to 8 + */ +-#define CFG_BLE_NUM_LINK 8 ++#ifndef CFG_BLE_NUM_LINK ++#ifdef STM32WB15xx ++ #define CFG_BLE_NUM_LINK 3 ++#else ++ #define CFG_BLE_NUM_LINK 8 ++#endif ++#endif + + /** + * Maximum number of Services that can be stored in the GATT database. + * Note that the GAP and GATT services are automatically added so this parameter should be 2 plus the number of user services + */ +-#define CFG_BLE_NUM_GATT_SERVICES 8 ++#ifndef CFG_BLE_NUM_GATT_SERVICES ++#ifdef STM32WB15xx ++ #define CFG_BLE_NUM_GATT_SERVICES 4 ++#else ++ #define CFG_BLE_NUM_GATT_SERVICES 8 ++#endif ++#endif + + /** + * Maximum number of Attributes +@@ -150,7 +164,13 @@ + * Note that certain characteristics and relative descriptors are added automatically during device initialization + * so this parameters should be 9 plus the number of user Attributes + */ +-#define CFG_BLE_NUM_GATT_ATTRIBUTES 68 ++#ifndef CFG_BLE_NUM_GATT_ATTRIBUTES ++#ifdef STM32WB15xx ++ #define CFG_BLE_NUM_GATT_ATTRIBUTES 30 ++#else ++ #define CFG_BLE_NUM_GATT_ATTRIBUTES 68 ++#endif ++#endif + + /** + * Maximum supported ATT_MTU size +@@ -186,12 +206,16 @@ + /** + * Enable or disable the Extended Packet length feature. Valid values are 0 or 1. + */ +-#define CFG_BLE_DATA_LENGTH_EXTENSION 1 ++#ifndef CFG_BLE_DATA_LENGTH_EXTENSION ++ #define CFG_BLE_DATA_LENGTH_EXTENSION 1 ++#endif + + /** + * Sleep clock accuracy in Peripheral mode (ppm value) + */ +-#define CFG_BLE_PERIPHERAL_SCA 500 ++#ifndef CFG_BLE_PERIPHERAL_SCA ++ #define CFG_BLE_PERIPHERAL_SCA 500 ++#endif + + /** + * Sleep clock accuracy in Central mode +@@ -204,7 +228,9 @@ + * 6 : 21 ppm to 30 ppm + * 7 : 0 ppm to 20 ppm + */ +-#define CFG_BLE_CENTRAL_SCA 0 ++#ifndef CFG_BLE_CENTRAL_SCA ++ #define CFG_BLE_CENTRAL_SCA 0 ++#endif + + /** + * LsSource +@@ -213,21 +239,27 @@ + * - bit 1: 1: STM32WB5M Module device 0: Other devices as STM32WBxx SOC, STM32WB1M module + * - bit 2: 1: HSE/1024 Clock config 0: LSE Clock config + */ +-#if defined(STM32WB5Mxx) +- #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_MOD5MM_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) +-#else +- #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_OTHER_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) ++#ifndef CFG_BLE_LS_SOURCE ++ #if defined(STM32WB5Mxx) ++ #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_MOD5MM_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) ++ #else ++ #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_OTHER_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) ++ #endif + #endif + + /** + * Start up time of the high speed (16 or 32 MHz) crystal oscillator in units of 625/256 us (~2.44 us) + */ +-#define CFG_BLE_HSE_STARTUP_TIME 0x148 ++#ifndef CFG_BLE_HSE_STARTUP_TIME ++ #define CFG_BLE_HSE_STARTUP_TIME 0x148 ++#endif + + /** + * Maximum duration of the connection event when the device is in Peripheral mode in units of 625/256 us (~2.44 us) + */ +-#define CFG_BLE_MAX_CONN_EVENT_LENGTH (0xFFFFFFFF) ++#ifndef CFG_BLE_MAX_CONN_EVENT_LENGTH ++ #define CFG_BLE_MAX_CONN_EVENT_LENGTH (0xFFFFFFFF) ++#endif + + /** + * Viterbi Mode +-- +2.34.1 + diff --git a/extras/STM32_WPAN/0004-fix-TL_Evt_t-payload-size-for-reset.patch b/extras/STM32_WPAN/0004-fix-TL_Evt_t-payload-size-for-reset.patch new file mode 100644 index 00000000..110a8410 --- /dev/null +++ b/extras/STM32_WPAN/0004-fix-TL_Evt_t-payload-size-for-reset.patch @@ -0,0 +1,30 @@ +From 324eef795bfd0a754aae4d5f9b528d4c8ad706c8 Mon Sep 17 00:00:00 2001 +From: Frederic Pillon <frederic.pillon@st.com> +Date: Mon, 24 Jul 2023 10:55:20 +0200 +Subject: [PATCH 4/4] fix: TL_Evt_t payload size for reset + +Within STM32CubeWB v1.17.0 update TL_Evt_t payload size was reduced. +This produce a warning -Warray-bounds due to the reset management +which require 4 bytes. + +Signed-off-by: Frederic Pillon <frederic.pillon@st.com> +--- + src/utility/STM32_WPAN/tl.h | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/utility/STM32_WPAN/tl.h b/src/utility/STM32_WPAN/tl.h +index 8e8c6cb..7452087 100644 +--- a/src/utility/STM32_WPAN/tl.h ++++ b/src/utility/STM32_WPAN/tl.h +@@ -108,7 +108,7 @@ typedef PACKED_STRUCT + { + uint8_t evtcode; + uint8_t plen; +- uint8_t payload[2]; ++ uint8_t payload[4]; + } TL_Evt_t; + + typedef PACKED_STRUCT +-- +2.34.1 + From 0f5ca9f32d824030496d1960837e75bd79f32d92 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Wed, 26 Mar 2025 10:14:02 +0100 Subject: [PATCH 188/226] chore: update with stm32wb Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- .github/workflows/compile-examples.yml | 2 ++ .github/workflows/spell-check.yml | 7 ++++++ README.md | 30 +++++++++++++++++++++++--- library.properties | 2 +- src/utility/HCISharedMemTransport.cpp | 4 ++-- src/utility/HCISpiTransport.cpp | 6 ++---- src/utility/HCITransport.h | 4 ++++ 7 files changed, 45 insertions(+), 10 deletions(-) diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index f90e4784..903abc44 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -24,6 +24,8 @@ jobs: - STMicroelectronics:stm32:Eval:pnum=STEVAL_MKSBOX1V1,usb=CDCgen - STMicroelectronics:stm32:Nucleo_64:pnum=NUCLEO_L476RG - STMicroelectronics:stm32:Disco:pnum=B_L475E_IOT01A + - STMicroelectronics:stm32:Nucleo_64:pnum=P_NUCLEO_WB55RG + - STMicroelectronics:stm32:Nucleo_64:pnum=P_NUCLEO_WB55_USB_DONGLE steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/spell-check.yml b/.github/workflows/spell-check.yml index 6faf09c8..61af09cd 100644 --- a/.github/workflows/spell-check.yml +++ b/.github/workflows/spell-check.yml @@ -23,3 +23,10 @@ jobs: - name: Spell check uses: codespell-project/actions-codespell@v2 + with: + check_filenames: true + check_hidden: true + # In the event of a false positive, add the word in all lower case to this file: + # ignore_words_file: ./extras/codespell-ignore-words-list.txt + skip: src/utility/STM32_WPAN + path: src diff --git a/README.md b/README.md index 62186871..94d95daa 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,14 @@ # STM32duinoBLE -This library is a fork of ArduinoBLE library to add the support of SPBTLE-RF, SPBTLE-1S, BLUENRG-M2SP, BLUENRG-LP and BLUENRG-M0 BLE modules. +This library is a fork of ArduinoBLE library to add the support of STM32WB, SPBTLE-RF, SPBTLE-1S, BLUENRG-M2SP, BLUENRG-LP and BLUENRG-M0 BLE modules. -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], [B-L4S5I-IOT01A], [STEVAL-MKSBOX1V1], [STEVAL-MKBOXPRO] and with [STM32L562E-DK]. +It was successfully tested with the [NUCLEO-WB15CC], [P-NUCLEO-WB55RG], [STM32WB5MM-DK], [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], [B-L4S5I-IOT01A], [STEVAL-MKSBOX1V1], [STEVAL-MKBOXPRO] and with [STM32L562E-DK]. + + - In order to use this library with SM32WBxx series, you need to update the STM32WB Copro Wireless Binaries with stm32wbxx_BLE_HCILayer_fw.bin depending of your mcu: + +https://github.com/STMicroelectronics/STM32CubeWB/tree/master/Projects/STM32WB_Copro_Wireless_Binaries + + Each subdirectories contains binaries and Release_Notes.html which explain how to update it. - 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: @@ -17,6 +23,14 @@ https://www.arduino.cc/en/Reference/ArduinoBLE # Configuration +### STM32WB + +STM32Cube_WPAN has several configuration options, which are set in the `app_conf.h`. +This package has a default configuration named `app_conf_default.h`. +The user can include the file `app_conf_custom.h` to customize the BLE application. +Options wrapped in `#ifndef`, `#endif` in `app_conf_default.h` can be overwritten. +Additional options can be added. + ### Shield The user can include the file `ble_spi_conf.h` to define which shield and configuration to use from the following list: @@ -70,6 +84,12 @@ This is equivalent to the below configuration using the `CUSTOM_BLE_SPI`: #define BLE_RESET D7 ``` +#### Using a SPI BLE module on STM32WB + +If required, user can use a compatible BLE module over SPI. + +In the `ble_spi_conf.h`, define `USE_BLE_SPI`. + ## License ``` @@ -91,14 +111,18 @@ License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ``` + B-L475E-IOT01A: https://www.st.com/en/evaluation-tools/b-l475e-iot01a.html B-L4S5I-IOT01A: https://www.st.com/en/evaluation-tools/b-l4s5i-iot01a.html NUCLEO-F401RE: https://www.st.com/en/evaluation-tools/nucleo-f401re.html NUCLEO-L053R8: https://www.st.com/en/evaluation-tools/nucleo-l053r8.html NUCLEO-L476RG: https://www.st.com/en/evaluation-tools/nucleo-l476rg.html +NUCLEO-WB15CC: https://www.st.com/en/evaluation-tools/nucleo-wb15cc.html +P-NUCLEO-WB55RG: https://www.st.com/en/evaluation-tools/p-nucleo-wb55.html STEVAL-MKSBOX1V1: https://www.st.com/en/evaluation-tools/steval-mksbox1v1.html STEVAL-MKBOXPRO: https://www.st.com/en/evaluation-tools/steval-mkboxpro.html STM32L562E-DK: https://www.st.com/en/evaluation-tools/stm32l562e-dk.html +STM32WB5MM-DK: https://www.st.com/en/evaluation-tools/stm32wb5mm-dk.html X-NUCLEO-BNRG2A1: https://www.st.com/en/ecosystems/x-nucleo-bnrg2a1.html X-NUCLEO-IDB05A2: https://www.st.com/en/ecosystems/x-nucleo-idb05a2.html -X-NUCLEO-IDB05A1: https://www.st.com/en/ecosystems/x-nucleo-idb05a1.html \ No newline at end of file +X-NUCLEO-IDB05A1: https://www.st.com/en/ecosystems/x-nucleo-idb05a1.html diff --git a/library.properties b/library.properties index 94860ca4..1842c0ee 100644 --- a/library.properties +++ b/library.properties @@ -2,7 +2,7 @@ name=STM32duinoBLE version=1.3.7 author=Arduino, SRA maintainer=stm32duino -sentence=Fork of ArduinoBLE library to add the support of SPBTLE-RF, SPBTLE-1S, BLUENRG-M2SP, BLUENRG-LP and BLUENRG-M0 BLE modules. +sentence=Fork of ArduinoBLE library to add the support of STM32WB, SPBTLE-RF, SPBTLE-1S, BLUENRG-M2SP, BLUENRG-LP and BLUENRG-M0 BLE modules. paragraph=This library supports creating a Bluetooth® Low Energy peripheral & central mode. category=Communication url=https://github.com/stm32duino/STM32duinoBLE diff --git a/src/utility/HCISharedMemTransport.cpp b/src/utility/HCISharedMemTransport.cpp index ab462dfa..f4ce1d0b 100644 --- a/src/utility/HCISharedMemTransport.cpp +++ b/src/utility/HCISharedMemTransport.cpp @@ -16,7 +16,7 @@ License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#if defined(STM32WBxx) +#if defined(STM32WBxx) && !defined(USE_BLE_SPI) #include "HCISharedMemTransport.h" #include "STM32_WPAN/hw.h" @@ -779,4 +779,4 @@ int HCISharedMemTransportClass::bt_ipm_set_power(void) } HCITransportInterface& HCITransport = HCISharedMemTransport; -#endif /* STM32WBxx */ +#endif /* STM32WBxx && !USE_BLE_SPI */ diff --git a/src/utility/HCISpiTransport.cpp b/src/utility/HCISpiTransport.cpp index 9a3709da..16b81623 100644 --- a/src/utility/HCISpiTransport.cpp +++ b/src/utility/HCISpiTransport.cpp @@ -17,12 +17,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#if !defined(STM32WBxx) || defined(USE_BLE_SPI) #include "HCISpiTransport.h" -#if __has_include("ble_spi_conf.h") - #include "ble_spi_conf.h" -#endif - #if defined(CUSTOM_BLE_SPI) SPIClass SpiHCI(BLE_SPI_MOSI, BLE_SPI_MISO, BLE_SPI_CLK); HCISpiTransportClass HCISpiTransport(SpiHCI, BLE_CHIP_TYPE, BLE_SPI_CS, BLE_SPI_IRQ, BLE_RESET, BLE_SPI_FREQ, BLE_SPI_MODE); @@ -1404,3 +1401,4 @@ void HCISpiTransportClass::wait_for_set_address() } HCITransportInterface& HCITransport = HCISpiTransport; +#endif // !STM32WBxx || USE_BLE_SPI diff --git a/src/utility/HCITransport.h b/src/utility/HCITransport.h index d8aa6a95..02e7962f 100644 --- a/src/utility/HCITransport.h +++ b/src/utility/HCITransport.h @@ -22,6 +22,10 @@ #include <Arduino.h> +#if __has_include("ble_spi_conf.h") + #include "ble_spi_conf.h" +#endif + class HCITransportInterface { public: virtual int begin() = 0; From da833f61ce793fa7eddb68e9f3ecfa9940cf803e Mon Sep 17 00:00:00 2001 From: Carlo Parata <carlo.parata@st.com> Date: Tue, 9 Feb 2021 15:35:13 +0100 Subject: [PATCH 189/226] feat: add possibility to choose the ownAddressType in the Arduino stack Signed-off-by: Carlo Parata <carlo.parata@st.com> --- src/local/BLELocalDevice.cpp | 6 +++++- src/local/BLELocalDevice.h | 11 ++++++++++- src/utility/ATT.cpp | 12 +++++++++++- src/utility/ATT.h | 6 ++++++ src/utility/GAP.cpp | 9 +++++++-- src/utility/GAP.h | 3 +++ 6 files changed, 42 insertions(+), 5 deletions(-) diff --git a/src/local/BLELocalDevice.cpp b/src/local/BLELocalDevice.cpp index 5792353f..3a620e32 100644 --- a/src/local/BLELocalDevice.cpp +++ b/src/local/BLELocalDevice.cpp @@ -39,7 +39,7 @@ #endif #endif -BLELocalDevice::BLELocalDevice() +BLELocalDevice::BLELocalDevice(uint8_t ownBdaddrType): _ownBdaddrType(ownBdaddrType) { _advertisingData.setFlags(BLEFlagsGeneralDiscoverable | BLEFlagsBREDRNotSupported); } @@ -207,6 +207,10 @@ int BLELocalDevice::begin() GATT.begin(); + GAP.setOwnBdaddrType(_ownBdaddrType); + + ATT.setOwnBdaddrType(_ownBdaddrType); + return 1; } diff --git a/src/local/BLELocalDevice.h b/src/local/BLELocalDevice.h index 6c45c063..4c39fb16 100644 --- a/src/local/BLELocalDevice.h +++ b/src/local/BLELocalDevice.h @@ -30,9 +30,16 @@ enum Pairable { ONCE = 2, }; +enum AddressType { + PUBLIC_ADDR = 0, + STATIC_RANDOM_ADDR = 1, + RESOLVABLE_PRIVATE_ADDR = 2, + NON_RESOLVABLE_PRIVATE_ADDR = 3, +}; + class BLELocalDevice { public: - BLELocalDevice(); + BLELocalDevice(uint8_t ownBdaddrType = STATIC_RANDOM_ADDR); virtual ~BLELocalDevice(); virtual int begin(); @@ -107,6 +114,7 @@ class BLELocalDevice { virtual void setDisplayCode(void (*displayCode)(uint32_t confirmationCode)); virtual void setBinaryConfirmPairing(bool (*binaryConfirmPairing)()); + uint8_t BDaddress[6]; protected: @@ -116,6 +124,7 @@ class BLELocalDevice { private: BLEAdvertisingData _advertisingData; BLEAdvertisingData _scanResponseData; + uint8_t _ownBdaddrType; }; extern BLELocalDevice& BLE; diff --git a/src/utility/ATT.cpp b/src/utility/ATT.cpp index 9367cfbf..193ad1ef 100644 --- a/src/utility/ATT.cpp +++ b/src/utility/ATT.cpp @@ -114,7 +114,7 @@ ATTClass::~ATTClass() bool ATTClass::connect(uint8_t peerBdaddrType, uint8_t peerBdaddr[6]) { - if (HCI.leCreateConn(0x0060, 0x0030, 0x00, peerBdaddrType, peerBdaddr, 0x00, + if (HCI.leCreateConn(0x0060, 0x0030, 0x00, peerBdaddrType, peerBdaddr, _ownBdaddrType, 0x0006, 0x000c, 0x0000, 0x00c8, 0x0004, 0x0006) != 0) { return false; } @@ -1941,6 +1941,16 @@ int ATTClass::getPeerResolvedAddress(uint16_t connectionHandle, uint8_t resolved return 0; } +void ATTClass::setOwnBdaddrType(uint8_t ownBdaddrType) +{ + _ownBdaddrType = ownBdaddrType; +} + +uint8_t ATTClass::getOwnBdaddrType(void) +{ + return _ownBdaddrType; +} + #if !defined(FAKE_ATT) ATTClass ATTObj; ATTClass& ATT = ATTObj; diff --git a/src/utility/ATT.h b/src/utility/ATT.h index c9f007f9..5e41e1fa 100644 --- a/src/utility/ATT.h +++ b/src/utility/ATT.h @@ -109,6 +109,10 @@ class ATTClass { uint8_t peerIRK[16]; /// This is just a random number... Not sure it has use unless privacy mode is active. uint8_t localIRK[16] = {0x54,0x83,0x63,0x7c,0xc5,0x1e,0xf7,0xec,0x32,0xdd,0xad,0x51,0x89,0x4b,0x9e,0x07}; + + void setOwnBdaddrType(uint8_t ownBdaddrType); + uint8_t getOwnBdaddrType(); // Used in L2CAPSignaling to encryption + private: virtual void error(uint16_t connectionHandle, uint8_t dlen, uint8_t data[]); virtual void mtuReq(uint16_t connectionHandle, uint8_t dlen, uint8_t data[]); @@ -170,6 +174,8 @@ class ATTClass { } _pendingResp; BLEDeviceEventHandler _eventHandlers[2]; + + uint8_t _ownBdaddrType; }; extern ATTClass& ATT; diff --git a/src/utility/GAP.cpp b/src/utility/GAP.cpp index f1bf02fe..fac04a67 100644 --- a/src/utility/GAP.cpp +++ b/src/utility/GAP.cpp @@ -54,7 +54,7 @@ int GAPClass::advertise(uint8_t* advData, uint8_t advDataLen, uint8_t* scanData, stopAdvertise(); - if (HCI.leSetAdvertisingParameters(_advertisingInterval, _advertisingInterval, type, 0x00, 0x00, directBdaddr, 0x07, 0) != 0) { + if (HCI.leSetAdvertisingParameters(_advertisingInterval, _advertisingInterval, type, _ownBdaddrType, 0x00, directBdaddr, 0x07, 0) != 0) { return 0; } @@ -93,7 +93,7 @@ int GAPClass::scan(bool withDuplicates) - scan window: mandatory range from 0x0011 to 0x1000 - The scan window can only be less than or equal to the scan interval */ - if (HCI.leSetScanParameters(0x01, 0x0020, 0x0020, 0x00, 0x00) != 0) { + if (HCI.leSetScanParameters(0x01, 0x0020, 0x0020, _ownBdaddrType, 0x00) != 0) { return false; } @@ -266,6 +266,11 @@ bool GAPClass::matchesScanFilter(const BLEDevice& device) return true; } +void GAPClass::setOwnBdaddrType(uint8_t ownBdaddrType) +{ + _ownBdaddrType = ownBdaddrType; +} + #if !defined(FAKE_GAP) GAPClass GAPObj; GAPClass& GAP = GAPObj; diff --git a/src/utility/GAP.h b/src/utility/GAP.h index 2ea22938..cadd0cba 100644 --- a/src/utility/GAP.h +++ b/src/utility/GAP.h @@ -45,6 +45,8 @@ class GAPClass { virtual void setEventHandler(BLEDeviceEvent event, BLEDeviceEventHandler eventHandler); + void setOwnBdaddrType(uint8_t ownBdaddrType); + protected: friend class HCIClass; @@ -67,6 +69,7 @@ class GAPClass { String _scanNameFilter; String _scanUuidFilter; String _scanAddressFilter; + uint8_t _ownBdaddrType; }; extern GAPClass& GAP; From 622497cd7b39f1cff1d325412ec1a9b936d9dbb2 Mon Sep 17 00:00:00 2001 From: Alexandre Bourdiol <alexandre.bourdiol@st.com> Date: Mon, 24 Oct 2022 11:35:21 +0200 Subject: [PATCH 190/226] fix: HCI only Firmware not supporting ACI_GAP_INIT ACI_GATT_INIT On STM32WB, Cube FW version 1.14.1, messages ACI_GATT_INIT and ACI_GAP_INIT are not available on HCI only BLE firmware (stm32wb5x_BLE_HCILayer_fw.bin) This imply to move Random Address to host instead of relying on controller Signed-off-by: Alexandre Bourdiol <alexandre.bourdiol@st.com> --- src/local/BLELocalDevice.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/local/BLELocalDevice.cpp b/src/local/BLELocalDevice.cpp index 3a620e32..e333b22f 100644 --- a/src/local/BLELocalDevice.cpp +++ b/src/local/BLELocalDevice.cpp @@ -124,6 +124,20 @@ int BLELocalDevice::begin() return 0; } + uint8_t randomNumber[8]; + if (HCI.leRand(randomNumber) != 0) { + end(); + return 0; + } + /* Random address only requires 6 bytes (48 bits) + * Force both MSB bits to b00 in order to define Static Random Address + */ + randomNumber[5] |= 0xC0; + if (HCI.leSetRandomAddress((uint8_t*)randomNumber) != 0) { + end(); + return 0; + } + uint8_t hciVer; uint16_t hciRev; uint8_t lmpVer; From a44c940a58f5b05ede02e0cf7af2b31b4deffa89 Mon Sep 17 00:00:00 2001 From: Lorenzo Bini <lorenzo.bini@studenti.unimi.it> Date: Tue, 14 Mar 2023 17:19:12 +0100 Subject: [PATCH 191/226] feat: add API to get random address Signed-off-by: Lorenzo Bini <lorenzo.bini@studenti.unimi.it> --- src/local/BLELocalDevice.cpp | 19 +++++++++++++++++++ src/local/BLELocalDevice.h | 3 +++ 2 files changed, 22 insertions(+) diff --git a/src/local/BLELocalDevice.cpp b/src/local/BLELocalDevice.cpp index e333b22f..a888963a 100644 --- a/src/local/BLELocalDevice.cpp +++ b/src/local/BLELocalDevice.cpp @@ -133,6 +133,15 @@ int BLELocalDevice::begin() * Force both MSB bits to b00 in order to define Static Random Address */ randomNumber[5] |= 0xC0; + + // Copy the random address in private variable as it will be sent to the BLE chip + randomAddress [0] = randomNumber[0]; + randomAddress [1] = randomNumber[1]; + randomAddress [2] = randomNumber[2]; + randomAddress [3] = randomNumber[3]; + randomAddress [4] = randomNumber[4]; + randomAddress [5] = randomNumber[5]; + if (HCI.leSetRandomAddress((uint8_t*)randomNumber) != 0) { end(); return 0; @@ -247,6 +256,16 @@ void BLELocalDevice::end() _scanResponseData.clear(); } +void BLELocalDevice::getRandomAddress(uint8_t buff[6]) +{ + buff [0] = randomAddress[0]; + buff [1] = randomAddress[1]; + buff [2] = randomAddress[2]; + buff [3] = randomAddress[3]; + buff [4] = randomAddress[4]; + buff [5] = randomAddress[5]; +} + void BLELocalDevice::poll() { HCI.poll(); diff --git a/src/local/BLELocalDevice.h b/src/local/BLELocalDevice.h index 4c39fb16..137ab69f 100644 --- a/src/local/BLELocalDevice.h +++ b/src/local/BLELocalDevice.h @@ -91,6 +91,8 @@ class BLELocalDevice { virtual void setTimeout(unsigned long timeout); + virtual void getRandomAddress(uint8_t buff[6]); + virtual void debug(Stream& stream); virtual void noDebug(); @@ -122,6 +124,7 @@ class BLELocalDevice { virtual BLEAdvertisingData& getScanResponseData(); private: + uint8_t randomAddress[6]; BLEAdvertisingData _advertisingData; BLEAdvertisingData _scanResponseData; uint8_t _ownBdaddrType; From 107c7c963c7d01bbb5f5a7a3f81c11479ede522b Mon Sep 17 00:00:00 2001 From: Carlo Parata <carlo.parata@st.com> Date: Fri, 7 Feb 2020 11:20:49 +0100 Subject: [PATCH 192/226] chore(GAP): improve scan Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- src/local/BLELocalDevice.cpp | 4 ++-- src/local/BLELocalDevice.h | 2 +- src/utility/GAP.cpp | 18 +++++++++++++++--- src/utility/GAP.h | 2 +- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/local/BLELocalDevice.cpp b/src/local/BLELocalDevice.cpp index a888963a..d1128788 100644 --- a/src/local/BLELocalDevice.cpp +++ b/src/local/BLELocalDevice.cpp @@ -421,9 +421,9 @@ int BLELocalDevice::scanForAddress(String address, bool withDuplicates) return GAP.scanForAddress(address, withDuplicates); } -void BLELocalDevice::stopScan() +int BLELocalDevice::stopScan() { - GAP.stopScan(); + return GAP.stopScan(); } BLEDevice BLELocalDevice::central() diff --git a/src/local/BLELocalDevice.h b/src/local/BLELocalDevice.h index 137ab69f..8217669f 100644 --- a/src/local/BLELocalDevice.h +++ b/src/local/BLELocalDevice.h @@ -77,7 +77,7 @@ class BLELocalDevice { virtual int scanForName(String name, bool withDuplicates = false); virtual int scanForUuid(String uuid, bool withDuplicates = false); virtual int scanForAddress(String address, bool withDuplicates = false); - virtual void stopScan(); + virtual int stopScan(); virtual BLEDevice central(); virtual BLEDevice available(); diff --git a/src/utility/GAP.cpp b/src/utility/GAP.cpp index fac04a67..ed001a96 100644 --- a/src/utility/GAP.cpp +++ b/src/utility/GAP.cpp @@ -84,7 +84,12 @@ void GAPClass::stopAdvertise() int GAPClass::scan(bool withDuplicates) { - HCI.leSetScanEnable(false, true); + if(_scanning) { + // Check if the HCI command fails + if (HCI.leSetScanEnable(false, true) != 0) { + return 0; + } + } // active scan, 20 ms scan interval (N * 0.625), 20 ms scan window (N * 0.625), public own address type, no filter /* @@ -133,9 +138,14 @@ int GAPClass::scanForAddress(String address, bool withDuplicates) return scan(withDuplicates); } -void GAPClass::stopScan() +int GAPClass::stopScan() { - HCI.leSetScanEnable(false, false); + if(_scanning) { + // Check if the HCI command fails + if (HCI.leSetScanEnable(false, false) != 0) { + return 0; + } + } _scanning = false; @@ -146,6 +156,8 @@ void GAPClass::stopScan() } _discoveredDevices.clear(); + + return 1; } BLEDevice GAPClass::available() diff --git a/src/utility/GAP.h b/src/utility/GAP.h index cadd0cba..c79a2aa7 100644 --- a/src/utility/GAP.h +++ b/src/utility/GAP.h @@ -37,7 +37,7 @@ class GAPClass { virtual int scanForName(String name, bool withDuplicates); virtual int scanForUuid(String uuid, bool withDuplicates); virtual int scanForAddress(String address, bool withDuplicates); - virtual void stopScan(); + virtual int stopScan(); virtual BLEDevice available(); virtual void setAdvertisingInterval(uint16_t advertisingInterval); From e24f12cff211b774a5e8dca25a70e396c7a968fe Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Thu, 20 Mar 2025 11:29:22 +0100 Subject: [PATCH 193/226] chore(examples): enhance button support Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- examples/Central/LedControl/LedControl.ino | 15 ++++++++++++--- examples/Peripheral/ButtonLED/ButtonLED.ino | 8 ++++++-- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/examples/Central/LedControl/LedControl.ino b/examples/Central/LedControl/LedControl.ino index 064bb29e..fa4ebfc3 100644 --- a/examples/Central/LedControl/LedControl.ino +++ b/examples/Central/LedControl/LedControl.ino @@ -17,19 +17,28 @@ #include <STM32duinoBLE.h> // variables for button -const int buttonPin = 2; +#ifdef USER_BTN +const int buttonPin = USER_BTN; // set buttonPin to on-board button +#else +const int buttonPin = PC13; // set buttonPin to digital pin PC13 */ +#endif int oldButtonState = LOW; +int initialButtonState = LOW; void setup() { Serial.begin(9600); while (!Serial); // configure the button pin as input - pinMode(buttonPin, INPUT); + pinMode(buttonPin, INPUT_PULLUP); // initialize the Bluetooth® Low Energy hardware BLE.begin(); + // Get initial button state + initialButtonState = digitalRead(buttonPin); + oldButtonState = initialButtonState; + Serial.println("Bluetooth® Low Energy Central - LED control"); // start scanning for peripherals @@ -108,7 +117,7 @@ void controlLed(BLEDevice peripheral) { // button changed oldButtonState = buttonState; - if (buttonState) { + if (buttonState != initialButtonState) { Serial.println("button pressed"); // button is pressed, write 0x01 to turn the LED on diff --git a/examples/Peripheral/ButtonLED/ButtonLED.ino b/examples/Peripheral/ButtonLED/ButtonLED.ino index baa64b87..8ae7d665 100644 --- a/examples/Peripheral/ButtonLED/ButtonLED.ino +++ b/examples/Peripheral/ButtonLED/ButtonLED.ino @@ -18,7 +18,11 @@ #include <STM32duinoBLE.h> const int ledPin = LED_BUILTIN; // set ledPin to on-board LED -const int buttonPin = 4; // set buttonPin to digital pin 4 +#ifdef USER_BTN +const int buttonPin = USER_BTN; // set buttonPin to on-board button +#else +const int buttonPin = PC13; // set buttonPin to digital pin PC13 */ +#endif BLEService ledService("19B10010-E8F2-537E-4F6C-D104768A1214"); // create service @@ -32,7 +36,7 @@ void setup() { while (!Serial); pinMode(ledPin, OUTPUT); // use the LED as an output - pinMode(buttonPin, INPUT); // use button pin as an input + pinMode(buttonPin, INPUT_PULLUP); // use button pin as an input // begin initialization if (!BLE.begin()) { From 7d735c7a97b66cd7e1478d74dd8ca4cad1b6538b Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Thu, 20 Mar 2025 11:32:00 +0100 Subject: [PATCH 194/226] chore(examples): enhance scan management Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- examples/Central/LedControl/LedControl.ino | 33 +++++++++++++++-- .../PeripheralExplorer/PeripheralExplorer.ino | 22 ++++++++++-- examples/Central/Scan/Scan.ino | 13 +++++-- .../Central/ScanCallback/ScanCallback.ino | 11 +++++- .../SensorTagButton/SensorTagButton.ino | 35 ++++++++++++++++--- 5 files changed, 102 insertions(+), 12 deletions(-) diff --git a/examples/Central/LedControl/LedControl.ino b/examples/Central/LedControl/LedControl.ino index fa4ebfc3..cbda07d1 100644 --- a/examples/Central/LedControl/LedControl.ino +++ b/examples/Central/LedControl/LedControl.ino @@ -42,7 +42,16 @@ void setup() { Serial.println("Bluetooth® Low Energy Central - LED control"); // start scanning for peripherals - BLE.scanForUuid("19b10000-e8f2-537e-4f6c-d104768a1214"); + int ret = 1; + do + { + ret = BLE.scanForUuid("19b10000-e8f2-537e-4f6c-d104768a1214"); + if (ret == 0) + { + BLE.end(); + BLE.begin(); + } + } while(ret == 0); } void loop() { @@ -64,12 +73,30 @@ void loop() { } // stop scanning - BLE.stopScan(); + int ret = 1; + do + { + ret = BLE.stopScan(); + if (ret == 0) + { + BLE.end(); + BLE.begin(); + } + } while(ret == 0); controlLed(peripheral); // peripheral disconnected, start scanning again - BLE.scanForUuid("19b10000-e8f2-537e-4f6c-d104768a1214"); + ret = 1; + do + { + ret = BLE.scanForUuid("19b10000-e8f2-537e-4f6c-d104768a1214"); + if (ret == 0) + { + BLE.end(); + BLE.begin(); + } + } while(ret == 0); } } diff --git a/examples/Central/PeripheralExplorer/PeripheralExplorer.ino b/examples/Central/PeripheralExplorer/PeripheralExplorer.ino index 4a72a697..7d4841ae 100644 --- a/examples/Central/PeripheralExplorer/PeripheralExplorer.ino +++ b/examples/Central/PeripheralExplorer/PeripheralExplorer.ino @@ -29,7 +29,16 @@ void setup() { Serial.println("Bluetooth® Low Energy Central - Peripheral Explorer"); // start scanning for peripherals - BLE.scan(); + int ret = 1; + do + { + ret = BLE.scan(); + if (ret == 0) + { + BLE.end(); + BLE.begin(); + } + } while(ret == 0); } void loop() { @@ -49,7 +58,16 @@ void loop() { // see if peripheral is a LED if (peripheral.localName() == "LED") { // stop scanning - BLE.stopScan(); + int ret = 1; + do + { + ret = BLE.stopScan(); + if (ret == 0) + { + BLE.end(); + BLE.begin(); + } + } while(ret == 0); explorerPeripheral(peripheral); diff --git a/examples/Central/Scan/Scan.ino b/examples/Central/Scan/Scan.ino index 99e13696..ca6b2b9a 100644 --- a/examples/Central/Scan/Scan.ino +++ b/examples/Central/Scan/Scan.ino @@ -25,8 +25,17 @@ void setup() { Serial.println("Bluetooth® Low Energy Central scan"); - // start scanning for peripheral - BLE.scan(); + // start scanning for peripherals + int ret = 1; + do + { + ret = BLE.scan(); + if (ret == 0) + { + BLE.end(); + BLE.begin(); + } + } while(ret == 0); } void loop() { diff --git a/examples/Central/ScanCallback/ScanCallback.ino b/examples/Central/ScanCallback/ScanCallback.ino index 63ab2753..cc33ee85 100644 --- a/examples/Central/ScanCallback/ScanCallback.ino +++ b/examples/Central/ScanCallback/ScanCallback.ino @@ -31,7 +31,16 @@ void setup() { BLE.setEventHandler(BLEDiscovered, bleCentralDiscoverHandler); // start scanning for peripherals with duplicates - BLE.scan(true); + int ret = 1; + do + { + ret = BLE.scan(true); + if (ret == 0) + { + BLE.end(); + BLE.begin(); + } + } while(ret == 0); } void loop() { diff --git a/examples/Central/SensorTagButton/SensorTagButton.ino b/examples/Central/SensorTagButton/SensorTagButton.ino index 26ee667d..f063ac68 100644 --- a/examples/Central/SensorTagButton/SensorTagButton.ino +++ b/examples/Central/SensorTagButton/SensorTagButton.ino @@ -30,8 +30,17 @@ void setup() { Serial.println("Bluetooth® Low Energy Central - SensorTag button"); Serial.println("Make sure to turn on the device."); - // start scanning for peripheral - BLE.scan(); + // start scanning for peripherals + int ret = 1; + do + { + ret = BLE.scan(); + if (ret == 0) + { + BLE.end(); + BLE.begin(); + } + } while(ret == 0); } void loop() { @@ -52,12 +61,30 @@ void loop() { // "CC2650 SensorTag" if (peripheral.localName() == "CC2650 SensorTag") { // stop scanning - BLE.stopScan(); + int ret = 1; + do + { + ret = BLE.stopScan(); + if (ret == 0) + { + BLE.end(); + BLE.begin(); + } + } while(ret == 0); monitorSensorTagButtons(peripheral); // peripheral disconnected, start scanning again - BLE.scan(); + ret = 1; + do + { + ret = BLE.scan(); + if (ret == 0) + { + BLE.end(); + BLE.begin(); + } + } while(ret == 0); } } } From ae6881e35cc3b1b328b8cf6683bcaeda638997d5 Mon Sep 17 00:00:00 2001 From: Carlo Parata <carlo.parata@st.com> Date: Wed, 19 Mar 2025 17:54:37 +0100 Subject: [PATCH 195/226] fix(HCI): SetAdvertise only if enabled Signed-off-by: Carlo Parata <carlo.parata@st.com> Co-Auhthored-by: Frederic Pillon <frederic.pillon@st.com> --- src/utility/HCI.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/utility/HCI.cpp b/src/utility/HCI.cpp index fb30b3ca..c95f76d2 100644 --- a/src/utility/HCI.cpp +++ b/src/utility/HCI.cpp @@ -820,7 +820,10 @@ void HCIClass::handleEventPkt(uint8_t /*plen*/, uint8_t pdata[]) ATT.removeConnection(disconnComplete->handle, disconnComplete->reason); L2CAPSignaling.removeConnection(disconnComplete->handle, disconnComplete->reason); - HCI.leSetAdvertiseEnable(0x01); + if (GAP.advertising()) + { + HCI.leSetAdvertiseEnable(0x01); + } } else if (eventHdr->evt == EVT_ENCRYPTION_CHANGE) { From c8997be5a11ac65779eb504d76758c36fea718bf Mon Sep 17 00:00:00 2001 From: Arkadiusz Ambroziak <arekambroziak@op.pl> Date: Tue, 18 Mar 2025 15:36:06 +0100 Subject: [PATCH 196/226] fix: for pairing with Static Random Address Signed-off-by: Arkadiusz Ambroziak <arekambroziak@op.pl> Co-Auhthored-by: Frederic Pillon <frederic.pillon@st.com> --- src/local/BLELocalDevice.cpp | 23 +++++++++++++++++++++-- src/utility/L2CAPSignaling.cpp | 8 +++++--- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/local/BLELocalDevice.cpp b/src/local/BLELocalDevice.cpp index d1128788..6137e14b 100644 --- a/src/local/BLELocalDevice.cpp +++ b/src/local/BLELocalDevice.cpp @@ -142,10 +142,22 @@ int BLELocalDevice::begin() randomAddress [4] = randomNumber[4]; randomAddress [5] = randomNumber[5]; - if (HCI.leSetRandomAddress((uint8_t*)randomNumber) != 0) { + // Set Random address only when type is STATIC_RANDOM_ADDR + if ((_ownBdaddrType == STATIC_RANDOM_ADDR) && (HCI.leSetRandomAddress((uint8_t*)randomNumber) != 0)) { end(); return 0; } + // Save address to HCI.localAddr variable, which is used to encryption in pairing + if(_ownBdaddrType == PUBLIC_ADDR){ + if (HCI.readBdAddr() != 0) { + end(); + return 0; + } + } else { + for(int k=0; k<6; k++){ + HCI.localAddr[5-k] = randomAddress[k]; + } + } uint8_t hciVer; uint16_t hciRev; @@ -301,7 +313,14 @@ bool BLELocalDevice::disconnect() String BLELocalDevice::address() const { uint8_t addr[6] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - HCI.readBdAddr(addr); + // return correct device address when is set to STATIC RANDOM (set by HCI) + if(_ownBdaddrType == PUBLIC_ADDR) { + HCI.readBdAddr(addr); + } else { + for(int k=0; k<6; k++) { + addr[k]=HCI.localAddr[5-k]; + } + } char result[18]; sprintf(result, "%02x:%02x:%02x:%02x:%02x:%02x", addr[5], addr[4], addr[3], addr[2], addr[1], addr[0]); diff --git a/src/utility/L2CAPSignaling.cpp b/src/utility/L2CAPSignaling.cpp index 7af170df..1d2fa426 100644 --- a/src/utility/L2CAPSignaling.cpp +++ b/src/utility/L2CAPSignaling.cpp @@ -369,10 +369,12 @@ void L2CAPSignalingClass::smCalculateLTKandConfirm(uint16_t handle, uint8_t expe uint8_t localAddress[7]; uint8_t remoteAddress[7]; ATT.getPeerAddrWithType(handle, remoteAddress); - - HCI.readBdAddr(); + + // Address is taken directly from HCI.localaddress, + // which is set when object DeviceLocal is created + // HCI.readBdAddr(); memcpy(&localAddress[1],HCI.localAddr,6); - localAddress[0] = 0; // IOT 33 uses a static address // TODO: confirm for Nano BLE + localAddress[0] = ATT.getOwnBdaddrType(); // Adding bit with address type (e.g. Static random or public address) // Compute the LTK and MacKey uint8_t MacKey[16]; From 33348de697c66fbb8a2e26586857b99931e1458b Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Thu, 20 Mar 2025 10:35:12 +0100 Subject: [PATCH 197/226] fix(HCI): missing LE_Event_Mask Linked to: https://github.com/arduino-libraries/ArduinoBLE/issues/310 Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- src/utility/HCI.cpp | 3 ++- src/utility/HCI.h | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/utility/HCI.cpp b/src/utility/HCI.cpp index c95f76d2..d53c8e3e 100644 --- a/src/utility/HCI.cpp +++ b/src/utility/HCI.cpp @@ -82,6 +82,7 @@ String metaEventToString(LE_META_EVENT event) case LONG_TERM_KEY_REQUEST: return F("LE_LONG_TERM_KEY_REQUEST"); case READ_LOCAL_P256_COMPLETE: return F("READ_LOCAL_P256_COMPLETE"); case GENERATE_DH_KEY_COMPLETE: return F("GENERATE_DH_KEY_COMPLETE"); + case ENHANCED_CONN_COMPLETE: return F("ENHANCED_CONN_COMPLETE"); default: return "event unknown"; } } @@ -990,7 +991,7 @@ void HCIClass::handleEventPkt(uint8_t /*plen*/, uint8_t pdata[]) Serial.println(leMetaHeader->subevent,HEX); #endif switch((LE_META_EVENT)leMetaHeader->subevent){ - case 0x0A:{ + case ENHANCED_CONN_COMPLETE:{ struct __attribute__ ((packed)) EvtLeConnectionComplete { uint8_t status; uint16_t handle; diff --git a/src/utility/HCI.h b/src/utility/HCI.h index 0a530ceb..a6fa66e8 100644 --- a/src/utility/HCI.h +++ b/src/utility/HCI.h @@ -46,7 +46,8 @@ enum LE_META_EVENT { LONG_TERM_KEY_REQUEST = 0x05, REMOTE_CONN_PARAM_REQ = 0x06, READ_LOCAL_P256_COMPLETE = 0x08, - GENERATE_DH_KEY_COMPLETE = 0x09 + GENERATE_DH_KEY_COMPLETE = 0x09, + ENHANCED_CONN_COMPLETE = 0x0A, }; String metaEventToString(LE_META_EVENT event); String commandToString(LE_COMMAND command); From 348dc55733eeec41a960f35b59a1f406b8ca6343 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Thu, 20 Mar 2025 10:36:52 +0100 Subject: [PATCH 198/226] fix: wrong Le Event Mask set See LE_META_EVENT supported. Note: Value should be 0x3B3 but set to 0x1B3 to explicitly ignore ENHANCED_CONN_COMPLETE event Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- src/local/BLELocalDevice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/local/BLELocalDevice.cpp b/src/local/BLELocalDevice.cpp index 6137e14b..0aa30313 100644 --- a/src/local/BLELocalDevice.cpp +++ b/src/local/BLELocalDevice.cpp @@ -174,7 +174,7 @@ int BLELocalDevice::begin() end(); return 0; } - if (HCI.setLeEventMask(0x00000000000003FF) != 0) { + if (HCI.setLeEventMask(0x00000000000001B3) != 0) { end(); return 0; } From a35e40b7460cef694a1aa0310510fd79be9053c7 Mon Sep 17 00:00:00 2001 From: Andrew Childs <tidy.desk9426@fastmail.com> Date: Sun, 4 Feb 2024 21:03:55 -0500 Subject: [PATCH 199/226] Reset scan filters when stopScan is called [Fixes #350] --- src/utility/GAP.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/utility/GAP.cpp b/src/utility/GAP.cpp index ed001a96..649b7e5d 100644 --- a/src/utility/GAP.cpp +++ b/src/utility/GAP.cpp @@ -147,6 +147,9 @@ int GAPClass::stopScan() } } + _scanNameFilter = ""; + _scanUuidFilter = ""; + _scanAddressFilter = ""; _scanning = false; for (unsigned int i = 0; i < _discoveredDevices.size(); i++) { From e76c7d9120d2403c79de1fc517f75c6ea5998893 Mon Sep 17 00:00:00 2001 From: Derek Carter <carter_derek@live.com> Date: Sun, 25 Sep 2022 15:29:12 +0100 Subject: [PATCH 200/226] Fix for issue #245 - ATT_OP_FIND_INFO_RESP incorrect processing during ATTClass::discoverDescriptors causes crashing I've highlighted this issue on 9th July ... this is an issue of causing __CRASHES__ if using ArduinoBLE to connect as central and the response to ATT_OP_FIND_INFO_RESP includes 128-bit UUIDs. --- src/utility/ATT.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/utility/ATT.cpp b/src/utility/ATT.cpp index 193ad1ef..d19b9b92 100644 --- a/src/utility/ATT.cpp +++ b/src/utility/ATT.cpp @@ -1729,8 +1729,19 @@ bool ATTClass::discoverDescriptors(uint16_t connectionHandle, BLERemoteDevice* d } if (responseBuffer[0] == ATT_OP_FIND_INFO_RESP) { - uint16_t lengthPerDescriptor = responseBuffer[1] * 4; - uint8_t uuidLen = 2; + // + // Format parameter (responseBuffer[1]) either 0x01 - 16-bit Bluetooth UUID(s), or 0x02 - 128 bit UUID(s) + // + // Therefore for: + // 0x01 - uuidLen = 2 (octets) + // lengthPerDescriptor = 4 (Handle 2 octets + UUID 2 octets) + // 0x02 - uuidLen = 16 (octets) + // lengthPerDescriptor = 18 (Handle 2 octets + UUID 16 octets) + // + // See section 3.4.3.2 ATT_FIND_INFORMATION_RSP of Bluetooth Core Specification 5.3. + // + uint16_t lengthPerDescriptor = responseBuffer[1] * 14 - 10; + uint8_t uuidLen = lengthPerDescriptor - 2; for (int i = 2; i < respLength; i += lengthPerDescriptor) { struct __attribute__ ((packed)) RawDescriptor { From 45c96af0953240aa91bf215067350c23e8fe4df9 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Tue, 18 Mar 2025 10:27:57 +0100 Subject: [PATCH 201/226] fix: keywords.txt Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- keywords.txt | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/keywords.txt b/keywords.txt index 6e761812..b908b573 100644 --- a/keywords.txt +++ b/keywords.txt @@ -97,7 +97,7 @@ setValue KEYWORD2 broadcast KEYWORD2 written KEYWORD2 subscribed KEYWORD2 -valueUpdated KEYWORD2 +valueUpdated KEYWORD2 addDescriptor KEYWORD2 descriptorCount KEYWORD2 hasDescriptor KEYWORD2 @@ -108,7 +108,7 @@ canWrite KEYWORD2 canSubscribe KEYWORD2 subscribe KEYWORD2 canUnsubscribe KEYWORD2 -unsubscribe KEYWORD2 +unsubscribe KEYWORD2 writeValueLE KEYWORD2 setValueLE KEYWORD2 valueLE KEYWORD2 @@ -117,7 +117,11 @@ setValueBE KEYWORD2 valueBE KEYWORD2 uuid KEYWORD2 -addCharacteristic KEYWORD +addCharacteristic KEYWORD2 + +wait KEYWORD2 +peek KEYWORD2 +write KEYWORD2 ####################################### # Constants (LITERAL1) @@ -137,7 +141,7 @@ BLEIndicate LITERAL1 BLESubscribed LITERAL1 BLEUnsubscribed LITERAL1 BLEWritten LITERAL1 -BLEUpdated LITERAL1 +BLEUpdated LITERAL1 SPBTLE_RF LITERAL1 SPBTLE_1S LITERAL1 From 1a2c1aefc688a1316aa6afb058799dac511584d0 Mon Sep 17 00:00:00 2001 From: FidelSch <honoratofidel@protonmail.com> Date: Wed, 19 Feb 2025 17:28:07 -0300 Subject: [PATCH 202/226] fix: compilation error when using _BLE_TRACE Now correctly acceses the existing variables and uses an unsigned int for size comparison fpistm: changed the uint type to uint32_t to avoid build issue with below target: - arduino:megaavr:uno2018 - arduino:renesas_uno:unor4wif --- src/utility/L2CAPSignaling.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/utility/L2CAPSignaling.cpp b/src/utility/L2CAPSignaling.cpp index 1d2fa426..0a5807cf 100644 --- a/src/utility/L2CAPSignaling.cpp +++ b/src/utility/L2CAPSignaling.cpp @@ -230,9 +230,9 @@ void L2CAPSignalingClass::handleSecurityData(uint16_t connectionHandle, uint8_t Serial.print("V : "); btct.printBytes(V,32); Serial.print("X : "); - btct.printBytes(X,16); + btct.printBytes(HCI.Na,16); Serial.print("Y : "); - btct.printBytes(Y,16); + btct.printBytes(HCI.Nb,16); Serial.print("g2res : "); btct.printBytes(g2Result,4); Serial.print("Result : "); @@ -415,7 +415,7 @@ void L2CAPSignalingClass::smCalculateLTKandConfirm(uint16_t handle, uint8_t expe // Send our confirmation value to complete authentication stage 2 uint8_t ret[17]; ret[0] = CONNECTION_PAIRING_DHKEY_CHECK; - for(int i=0; i<sizeof(Eb); i++){ + for(uint32_t i=0; i<sizeof(Eb); i++){ ret[sizeof(Eb)-i] = Eb[i]; } HCI.sendAclPkt(handle, SECURITY_CID, sizeof(ret), ret ); From f892330866a5eaf56bfec43e55b816d30bc601ff Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Wed, 5 Mar 2025 18:53:08 +0100 Subject: [PATCH 203/226] fix: signed and init field warnings Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- src/utility/HCI.cpp | 14 +++++++++----- src/utility/L2CAPSignaling.cpp | 6 ++++-- src/utility/btct.cpp | 6 +++--- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/utility/HCI.cpp b/src/utility/HCI.cpp index d53c8e3e..8ac2419a 100644 --- a/src/utility/HCI.cpp +++ b/src/utility/HCI.cpp @@ -139,7 +139,7 @@ void HCIClass::poll(unsigned long timeout) while (HCITransport.available()) { byte b = HCITransport.read(); - if (_recvIndex >= sizeof(_recvBuffer)) { + if (_recvIndex >= (int)sizeof(_recvBuffer)) { _recvIndex = 0; if (_debug) { _debug->println("_recvBuffer overflow"); @@ -462,6 +462,8 @@ int HCIClass::leConnUpdate(uint16_t handle, uint16_t minInterval, uint16_t maxIn return sendCommand(OGF_LE_CTL << 10 | OCF_LE_CONN_UPDATE, sizeof(leConnUpdateData), &leConnUpdateData); } void HCIClass::saveNewAddress(uint8_t addressType, uint8_t* address, uint8_t* peerIrk, uint8_t* localIrk){ + (void)addressType; + (void)localIrk; if(_storeIRK!=0){ _storeIRK(address, peerIrk); } @@ -504,6 +506,7 @@ int HCIClass::leStartResolvingAddresses(){ return HCI.sendCommand(OGF_LE_CTL << 10 | 0x2D, 1,&enable); // Disable address resolution } int HCIClass::leReadPeerResolvableAddress(uint8_t peerAddressType, uint8_t* peerIdentityAddress, uint8_t* peerResolvableAddress){ + (void)peerResolvableAddress; struct __attribute__ ((packed)) Request { uint8_t addressType; uint8_t identityAddress[6]; @@ -547,7 +550,7 @@ int HCIClass::readStoredLK(uint8_t BD_ADDR[], uint8_t read_all ){ struct __attribute__ ((packed)) Request { uint8_t BD_ADDR[6]; uint8_t read_a; - } request = {0,0}; + } request = {{0},0}; for(int i=0; i<6; i++) request.BD_ADDR[5-i] = BD_ADDR[i]; request.read_a = read_all; return sendCommand(OGF_HOST_CTL << 10 | 0xD, sizeof(request), &request); @@ -1272,7 +1275,7 @@ void HCIClass::handleEventPkt(uint8_t /*plen*/, uint8_t pdata[]) uint8_t U[32]; uint8_t V[32]; uint8_t Z; - } f4Params = {0,0,Z}; + } f4Params = {{0},{0},Z}; for(int i=0; i<32; i++){ f4Params.U[31-i] = pairingPublicKey.publicKey[i]; f4Params.V[31-i] = HCI.remotePublicKeyBuffer[i]; @@ -1292,7 +1295,7 @@ void HCIClass::handleEventPkt(uint8_t /*plen*/, uint8_t pdata[]) #endif uint8_t cb_temp[sizeof(pairingConfirm.cb)]; - for(int i=0; i<sizeof(pairingConfirm.cb);i++){ + for(unsigned int i=0; i<sizeof(pairingConfirm.cb);i++){ cb_temp[sizeof(pairingConfirm.cb)-1-i] = pairingConfirm.cb[i]; } /// cb wa back to front. @@ -1376,11 +1379,12 @@ void HCIClass::handleEventPkt(uint8_t /*plen*/, uint8_t pdata[]) } } int HCIClass::leEncrypt(uint8_t* key, uint8_t* plaintext, uint8_t* status, uint8_t* ciphertext){ + (void)status; struct __attribute__ ((packed)) LeEncryptCommand { uint8_t key[16]; uint8_t plaintext[16]; - } leEncryptCommand = {0,0}; + } leEncryptCommand = {{0},{0}}; for(int i=0; i<16; i++){ leEncryptCommand.key[15-i] = key[i]; leEncryptCommand.plaintext[15-i] = plaintext[i]; diff --git a/src/utility/L2CAPSignaling.cpp b/src/utility/L2CAPSignaling.cpp index 0a5807cf..e88189cf 100644 --- a/src/utility/L2CAPSignaling.cpp +++ b/src/utility/L2CAPSignaling.cpp @@ -122,6 +122,8 @@ void L2CAPSignalingClass::handleSecurityData(uint16_t connectionHandle, uint8_t #ifdef _BLE_TRACE_ Serial.print("dlen: "); Serial.println(dlen); +#else + (void)dlen; #endif uint8_t code = l2capSignalingHdr->code; @@ -310,8 +312,8 @@ void L2CAPSignalingClass::handleSecurityData(uint16_t connectionHandle, uint8_t uint8_t x[32]; uint8_t y[32]; } generateDHKeyCommand = { - 0x00, - 0x00, + {0x00}, + {0x00}, }; memcpy(generateDHKeyCommand.x,connectionPairingPublicKey->x,32); memcpy(generateDHKeyCommand.y,connectionPairingPublicKey->y,32); diff --git a/src/utility/btct.cpp b/src/utility/btct.cpp index 199c9e0d..eeb7a8cd 100644 --- a/src/utility/btct.cpp +++ b/src/utility/btct.cpp @@ -71,7 +71,7 @@ int BluetoothCryptoToolbox::f5(uint8_t DHKey[],uint8_t N_master[], uint8_t N_sla uint8_t A1[7]; uint8_t A2[7]; uint8_t length[2]; - } cmacInput = {0,0,0,0,0,0,0}; + } cmacInput = {0,{0},{0},{0},{0},{0},{0}}; cmacInput.counter = 0; memcpy(cmacInput.keyID, keyID, 4); memcpy(cmacInput.N1,N_master,16); @@ -97,7 +97,7 @@ int BluetoothCryptoToolbox::f6(uint8_t W[], uint8_t N1[],uint8_t N2[],uint8_t R[ uint8_t IOCap[3]; uint8_t A1[7]; uint8_t A2[7]; - } f6Input = {0,0,0,0,0,0}; + } f6Input = {{0},{0},{0},{0},{0},{0}}; memcpy(f6Input.N1, N1, 16); memcpy(f6Input.N2, N2, 16); @@ -145,7 +145,7 @@ int BluetoothCryptoToolbox::g2(uint8_t U[], uint8_t V[], uint8_t X[], uint8_t Y[ uint8_t U[32]; uint8_t V[32]; uint8_t Y[16]; - } cmacInput= {0,0,0}; + } cmacInput= {{0},{0},{0}}; memcpy(cmacInput.U,U,32); memcpy(cmacInput.V,V,32); memcpy(cmacInput.Y,Y,16); From fb3da3bf5ea9e5d698611606dabffcf80880f3c4 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Mon, 7 Apr 2025 11:23:19 +0200 Subject: [PATCH 204/226] chore(wb): warn user about untested board Fixes #75 Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- src/utility/HCISharedMemTransport.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/utility/HCISharedMemTransport.cpp b/src/utility/HCISharedMemTransport.cpp index f4ce1d0b..1544871a 100644 --- a/src/utility/HCISharedMemTransport.cpp +++ b/src/utility/HCISharedMemTransport.cpp @@ -22,11 +22,10 @@ #include "STM32_WPAN/hw.h" #include "otp.h" -#if defined(ARDUINO_NUCLEO_WB15CC) || defined(ARDUINO_P_NUCLEO_WB55RG) ||\ - defined(ARDUINO_STM32WB5MM_DK) || defined(ARDUINO_P_NUCLEO_WB55_USB_DONGLE) HCISharedMemTransportClass HCISharedMemTransport; -#else -#error "Unsupported board or shield selected!" +#if !defined(ARDUINO_NUCLEO_WB15CC) && !defined(ARDUINO_P_NUCLEO_WB55RG) &&\ + !defined(ARDUINO_STM32WB5MM_DK) && !defined(ARDUINO_P_NUCLEO_WB55_USB_DONGLE) +#warning "Selected board has never been tested with this library, ensure to have a correct configuration!" #endif /* Private variables ---------------------------------------------------------*/ From 6c9aa25acc4639eda35213a7e178af5e8ed409c7 Mon Sep 17 00:00:00 2001 From: Carlo Parata <carlo.parata@st.com> Date: Thu, 19 Sep 2019 10:33:53 +0200 Subject: [PATCH 205/226] feat: add HCISpiTransport To support to STBTLE-RF, STBTLE-1S, BLUENRG-M2SP, BLUENRG-LP and BLUENRG-M0. Signed-off-by: Carlo Parata <carlo.parata@st.com> Co-authored-by: Frederic Pillon <frederic.pillon@st.com> --- keywords.txt | 9 + src/utility/HCISpiTransport.cpp | 1399 +++++++++++++++++++++++++++++++ src/utility/HCISpiTransport.h | 83 ++ 3 files changed, 1491 insertions(+) create mode 100644 src/utility/HCISpiTransport.cpp create mode 100644 src/utility/HCISpiTransport.h diff --git a/keywords.txt b/keywords.txt index aa35c72d..481fd3eb 100644 --- a/keywords.txt +++ b/keywords.txt @@ -30,6 +30,8 @@ BLEFloatCharacteristic KEYWORD1 BLEDoubleCharacteristic KEYWORD1 BLEStringCharacteristic KEYWORD1 +HCISpiTransportClass KEYWORD1 + ####################################### # Methods and Functions (KEYWORD2) ####################################### @@ -136,3 +138,10 @@ BLEUnsubscribed LITERAL1 BLEWritten LITERAL1 BLEUpdated LITERAL1 +SPBTLE_RF LITERAL1 +SPBTLE_1S LITERAL1 +BLUENRG_M2SP LITERAL1 +BLUENRG_M0 LITERAL1 +BLUENRG_LP LITERAL1 +BLEChip_t LITERAL1 + diff --git a/src/utility/HCISpiTransport.cpp b/src/utility/HCISpiTransport.cpp new file mode 100644 index 00000000..91c2c5dc --- /dev/null +++ b/src/utility/HCISpiTransport.cpp @@ -0,0 +1,1399 @@ +/* + This file is part of the STM32duinoBLE library. + Copyright (c) 2019 STMicroelectronics. All rights reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include "HCISpiTransport.h" + +#if defined(ARDUINO_STEVAL_MKBOXPRO) +/* STEVAL-MKBOXPRO */ +SPIClass SpiHCI(PA7, PA6, PA5); +HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_LP, PA2, PB11, PD4, 1000000, SPI_MODE3); +#elif defined(ARDUINO_STEVAL_MKSBOX1V1) +/* STEVAL-MKSBOX1V1 */ +SPIClass SpiHCI(PC3, PD3, PD1); +HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_1S, PD0, PD4, PA8, 1000000, SPI_MODE1); +#elif defined(ARDUINO_B_L475E_IOT01A) || defined(ARDUINO_B_L4S5I_IOT01A) +/* B-L475E-IOT01A1 or B_L4S5I_IOT01A */ +SPIClass SpiHCI(PC12, PC11, PC10); +HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, PD13, PE6, PA8, 8000000, SPI_MODE0); +#elif defined(ARDUINO_STM32L562E_DK) +/* STM32L562E-DK */ +SPIClass SpiHCI(PG4, PG3, PG2); +HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M0, PG5, PG6, PG8, 8000000, SPI_MODE0); +#elif defined(IDB05A2_SPI_CLOCK_D3) +/* Shield IDB05A2 with SPI clock on D3 */ +SPIClass SpiHCI(D11, D12, D3); +HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M0, A1, A0, D7, 8000000, SPI_MODE0); +#elif defined(IDB05A2_SPI_CLOCK_D13) +/* Shield IDB05A2 with SPI clock on D13 */ +#define SpiHCI SPI +HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M0, A1, A0, D7, 8000000, SPI_MODE0); +#elif defined(IDB05A1_SPI_CLOCK_D3) +/* Shield IDB05A1 with SPI clock on D3 */ +SPIClass SpiHCI(D11, D12, D3); +HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI_MODE0); +#elif defined(IDB05A1_SPI_CLOCK_D13) +/* Shield IDB05A1 with SPI clock on D13 */ +#define SpiHCI SPI +HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI_MODE0); +#elif defined(BNRG2A1_CLOCK_D3) +/* Shield BNRG2A1 with SPI clock on D3 */ +SPIClass SpiHCI(D11, D12, D3); +HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1); +#elif defined(BNRG2A1_CLOCK_D13) +/* Shield BNRG2A1 with SPI clock on D13 */ +#define SpiHCI SPI +HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1); +#else +#error "Unsupported board or shield selected!" +#endif + +volatile int data_avail = 0; + +HCISpiTransportClass::HCISpiTransportClass(SPIClass &spi, BLEChip_t ble_chip, uint8_t cs_pin, uint8_t spi_irq, uint8_t ble_rst, uint32_t frequency, uint8_t spi_mode) : + _spi(&spi), + _ble_chip(ble_chip), + _cs_pin(cs_pin), + _spi_irq(spi_irq), + _ble_rst(ble_rst) +{ + _spiSettings = SPISettings(frequency, (BitOrder)BLE_SPI_BYTE_ORDER, spi_mode); + _read_index = 0; + _write_index = 0; + _write_index_initial = 0; + _initial_phase = 1; + _random_addr_done = false; +} + +HCISpiTransportClass::~HCISpiTransportClass() +{ +} + +extern "C" void SPI_Irq_Callback(void) +{ + data_avail = 1; +} + +int HCISpiTransportClass::begin() +{ + _read_index = 0; + _write_index = 0; + _write_index_initial = 0; + _initial_phase = 1; + memset(_rxbuff, 0, sizeof(_rxbuff)); + pinMode(_cs_pin, OUTPUT); + digitalWrite(_cs_pin, HIGH); + + _spi->begin(); + + pinMode(_spi_irq, INPUT); + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + + // Reset chip + pinMode(_ble_rst, OUTPUT); + digitalWrite(_ble_rst, LOW); + delay(5); + digitalWrite(_ble_rst, HIGH); + delay(5); + + if (_ble_chip == SPBTLE_RF || _ble_chip == BLUENRG_M0 || _ble_chip == BLUENRG_LP || _ble_chip == BLUENRG_M2SP) { + // Wait for Blue Initialize + wait_for_blue_initialize(); + } else if (_ble_chip == SPBTLE_1S) { + // Wait a while for the reset of the BLE module + delay(300); + } else { + // BLE chip not supported + return 0; + } + + return 1; +} + +void HCISpiTransportClass::end() +{ + detachInterrupt(_spi_irq); + _spi->end(); +} + +void HCISpiTransportClass::wait(unsigned long timeout) +{ + for (unsigned long start = millis(); (millis() - start) < timeout;) { + if (available()) { + break; + } + } +} + +int HCISpiTransportClass::available() +{ + if (_ble_chip != SPBTLE_RF && _ble_chip != SPBTLE_1S && _ble_chip != BLUENRG_M2SP && _ble_chip != BLUENRG_M0 && _ble_chip != BLUENRG_LP) { + return 0; + } + + if (_read_index != _write_index) { + return 1; + } else if (data_avail) { + int ble_reset = 0; + + if (digitalRead(_spi_irq) == 0) { + return 0; + } + + data_avail = 0; + + // Wait for BlueNRG-LP to be ready (needs to be done after each HCI RESET) + if (_ble_chip == BLUENRG_LP && _initial_phase) { + delay(100); + } + + while (digitalRead(_spi_irq) == 1 && _write_index != BLE_MODULE_SPI_BUFFER_SIZE) { + uint8_t header_master[5] = {0x0b, 0x00, 0x00, 0x00, 0x00}; + + if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { + detachInterrupt(_spi_irq); + } + + _spi->beginTransaction(_spiSettings); + + digitalWrite(_cs_pin, LOW); + + /* Write the header */ + _spi->transfer(header_master, 5); + + if (_ble_chip == SPBTLE_RF || _ble_chip == BLUENRG_M0) { + /* device is ready */ + if (header_master[0] == 0x02) { + uint16_t byte_count = (header_master[4] << 8) | header_master[3]; + + if (byte_count > 0) { + if (_initial_phase) { + /* avoid to read more data that available size of the buffer */ + if (byte_count > (BLE_MODULE_SPI_BUFFER_SIZE - _write_index_initial)) { + byte_count = (BLE_MODULE_SPI_BUFFER_SIZE - _write_index_initial); + } + + /* Read the response */ + for (int j = 0; j < byte_count; j++) { + _rxbuff[_write_index_initial] = _spi->transfer(0x00); + _write_index_initial++; + } + + /* Check if the message is a Blue Initialize */ + /* If so we need to send the command to enable LL_ONLY */ + if (byte_count == 6) { + if (_rxbuff[_write_index_initial - 6] == 0x04 && + _rxbuff[_write_index_initial - 5] == 0xFF && + _rxbuff[_write_index_initial - 4] == 0x03 && + _rxbuff[_write_index_initial - 3] == 0x01 && + _rxbuff[_write_index_initial - 2] == 0x00 && + _rxbuff[_write_index_initial - 1] == 0x01) { + ble_reset = 1; + } + } + } else { + /* avoid to read more data that available size of the buffer */ + if (byte_count > (BLE_MODULE_SPI_BUFFER_SIZE - _write_index)) { + byte_count = (BLE_MODULE_SPI_BUFFER_SIZE - _write_index); + /* SPI buffer is full but we still have data to store, so we set the data_avail flag to true */ + data_avail = 1; + } + + /* Read the response */ + for (int j = 0; j < byte_count; j++) { + _rxbuff[_write_index] = _spi->transfer(0x00); + _write_index++; + } + } + } + } + } else if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { + uint16_t byte_count = (header_master[4] << 8) | header_master[3]; + + if (byte_count > 0) { + if (_initial_phase) { + /* avoid to read more data that available size of the buffer */ + if (byte_count > (BLE_MODULE_SPI_BUFFER_SIZE - _write_index_initial)) { + byte_count = (BLE_MODULE_SPI_BUFFER_SIZE - _write_index_initial); + } + + /* Read the response */ + for (int j = 0; j < byte_count; j++) { + _rxbuff[_write_index_initial] = _spi->transfer(0x00); + _write_index_initial++; + } + + /* Check if the message is a CMD_COMPLETE */ + /* We suppose that the first CMD is always a HCI_RESET */ + if (byte_count == 7) { + if (_rxbuff[_write_index_initial - 7] == 0x04 && + _rxbuff[_write_index_initial - 6] == 0x0E && + _rxbuff[_write_index_initial - 5] == 0x04 && + _rxbuff[_write_index_initial - 4] == 0x01 && + _rxbuff[_write_index_initial - 3] == 0x03 && + _rxbuff[_write_index_initial - 2] == 0x0C && + _rxbuff[_write_index_initial - 1] == 0x00) { + ble_reset = 1; + } + } + } else { + /* avoid to read more data that available size of the buffer */ + if (byte_count > (BLE_MODULE_SPI_BUFFER_SIZE - _write_index)) { + byte_count = (BLE_MODULE_SPI_BUFFER_SIZE - _write_index); + /* SPI buffer is full but we still have data to store, so we set the data_avail flag to true */ + data_avail = 1; + } + + /* Read the response */ + for (int j = 0; j < byte_count; j++) { + _rxbuff[_write_index] = _spi->transfer(0x00); + _write_index++; + } + } + } + } + + digitalWrite(_cs_pin, HIGH); + + _spi->endTransaction(); + + if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + } + } + + if (ble_reset) { + if (_ble_chip == BLUENRG_M2SP) { + wait_for_blue_initialize(); + } + + if (_ble_chip == SPBTLE_RF || _ble_chip == BLUENRG_M0 || _ble_chip == BLUENRG_LP || _ble_chip == BLUENRG_M2SP) { + /* BLE chip was reset: we need to enable LL_ONLY */ + enable_ll_only(); + wait_for_enable_ll_only(); + } else if (_ble_chip == SPBTLE_1S) { + /* BLE chip was reset: we need to wait for a while */ + delay(300); + } + + /* Call Gatt Init and Gap Init to activate the random BLE address */ + if (!_random_addr_done) { + aci_gatt_init(); + wait_for_aci_gatt_init(); + aci_gap_init(); + wait_for_aci_gap_init(); + /* Call Read Config Parameter to retrieve the random BLE address */ + aci_read_config_parameter(); + wait_for_aci_read_config_parameter(); + if (_ble_chip == BLUENRG_LP) { + hci_reset(); + _read_index = _write_index = _write_index_initial = 0; + _initial_phase = 1; + } else { + /* Now we can update the write index and close the initial phase */ + _write_index = _write_index_initial; + _initial_phase = 0; + _write_index_initial = 0; + } + } else { + set_address(); + wait_for_set_address(); + /* Now we can update the write index and close the initial phase */ + _write_index = _write_index_initial; + _initial_phase = 0; + _write_index_initial = 0; + } + } + + if (_read_index != _write_index) { + return 1; + } else { + return 0; + } + } else { + return 0; + } +} + +int HCISpiTransportClass::peek() +{ + int peek_val = -1; + + if (_read_index != _write_index) { + peek_val = _rxbuff[_read_index]; + } + + return peek_val; +} + +int HCISpiTransportClass::read() +{ + int read_val = -1; + + if (_read_index != _write_index) { + read_val = _rxbuff[_read_index]; + _read_index++; + if (_read_index == _write_index) { + /* Reset buffer index */ + _read_index = 0; + _write_index = 0; + } + } + + return read_val; +} + +size_t HCISpiTransportClass::write(const uint8_t *data, size_t length) +{ + uint8_t header_master[5] = {0x0a, 0x00, 0x00, 0x00, 0x00}; + void *my_data = (void *)data; + int result = 0; + uint32_t tickstart = millis(); + + if (_ble_chip != SPBTLE_RF && _ble_chip != SPBTLE_1S && _ble_chip != BLUENRG_M2SP && _ble_chip != BLUENRG_M0 && _ble_chip != BLUENRG_LP) { + return 0; + } + + do { + if (_ble_chip == SPBTLE_RF || _ble_chip == BLUENRG_M0) { + result = 0; + + _spi->beginTransaction(_spiSettings); + + digitalWrite(_cs_pin, LOW); + + /* Write the header */ + _spi->transfer(header_master, 5); + + /* device is ready */ + if (header_master[0] == 0x02) { + if (header_master[1] >= length) { + /* Write the data */ + _spi->transfer(my_data, length); + } else { + result = -2; + } + } else { + result = -1; + } + + digitalWrite(_cs_pin, HIGH); + + _spi->endTransaction(); + + if ((millis() - tickstart) > 1000) { + result = -3; + break; + } + } else if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { + uint32_t tickstart_data_available = millis(); + result = 0; + + detachInterrupt(_spi_irq); + + _spi->beginTransaction(_spiSettings); + + digitalWrite(_cs_pin, LOW); + + /* + * Wait until BlueNRG-1 is ready. + * When ready it will raise the IRQ pin. + */ + while (!(digitalRead(_spi_irq) == 1)) { + if ((millis() - tickstart_data_available) > 1000) { + result = -3; + break; + } + } + + if (result == -3) { + digitalWrite(_cs_pin, HIGH); + _spi->endTransaction(); + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + break; + } + + /* Write the header */ + _spi->transfer(header_master, 5); + + if ((int)((((uint16_t)header_master[2]) << 8) | ((uint16_t)header_master[1])) >= (int)length) { + /* Write the data */ + _spi->transfer(my_data, length); + } else { + result = -2; + } + + digitalWrite(_cs_pin, HIGH); + + _spi->endTransaction(); + + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + + if ((millis() - tickstart) > 1000) { + result = -3; + break; + } + } + } while (result < 0); + + if (result < 0) { + return 0; + } else { + return length; + } +} + +void HCISpiTransportClass::wait_for_blue_initialize() +{ + int event_blue_initialize = 0; + uint8_t event[16]; + + do { + while (!data_avail); + + if (digitalRead(_spi_irq) == 0) { + continue; + } + + data_avail = 0; + while (digitalRead(_spi_irq) == 1) { + uint8_t header_master[5] = {0x0b, 0x00, 0x00, 0x00, 0x00}; + + if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { + detachInterrupt(_spi_irq); + } + + _spi->beginTransaction(_spiSettings); + + digitalWrite(_cs_pin, LOW); + + /* Write the header */ + _spi->transfer(header_master, 5); + + if (_ble_chip == SPBTLE_RF || _ble_chip == BLUENRG_M0) { + /* device is ready */ + if (header_master[0] == 0x02) { + /* device is ready */ + uint16_t byte_count = (header_master[4] << 8) | header_master[3]; + + if (byte_count > 0) { + /* Read the response */ + if (byte_count == 6) { + for (int j = 0; j < byte_count; j++) { + event[j] = _spi->transfer(0x00); + } + + if (event[0] == 0x04 && + event[1] == 0xFF && + event[2] == 0x03 && + event[3] == 0x01 && + event[4] == 0x00 && + event[5] == 0x01) { + event_blue_initialize = 1; + } + } else { + for (int j = 0; j < byte_count; j++) { + _spi->transfer(0x00); + } + } + } + } + } else if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP) { + uint16_t byte_count = (header_master[4] << 8) | header_master[3]; + + if (byte_count > 0) { + /* Read the response */ + if (byte_count == 6) { + for (int j = 0; j < byte_count; j++) { + event[j] = _spi->transfer(0x00); + } + + if (event[0] == 0x04 && + event[1] == 0xFF && + event[2] == 0x03 && + event[3] == 0x01 && + event[4] == 0x00 && + event[5] == 0x01) { + event_blue_initialize = 1; + } + } else { + for (int j = 0; j < byte_count; j++) { + _spi->transfer(0x00); + } + } + } + } else if (_ble_chip == BLUENRG_LP) { + uint8_t byte_count = (header_master[4] << 8) | header_master[3]; + + if (byte_count > 0) { + /* Read the response */ + if (byte_count == 7) { + for (int j = 0; j < byte_count; j++) { + event[j] = _spi->transfer(0x00); + } + + if (event[0] == 0x82 && + event[1] == 0xFF && + event[2] == 0x03 && + event[3] == 0x00 && + event[4] == 0x01 && + event[5] == 0x00 && + event[6] == 0x01) { + event_blue_initialize = 1; + } + } else { + for (int j = 0; j < byte_count; j++) { + _spi->transfer(0x00); + } + } + } + } + + digitalWrite(_cs_pin, HIGH); + + _spi->endTransaction(); + + if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + } + } + } while (!event_blue_initialize); +} + +void HCISpiTransportClass::wait_for_enable_ll_only() +{ + uint8_t data[8]; + int status = 0; + + do { + while (!data_avail); + + if (digitalRead(_spi_irq) == 0) { + continue; + } + + data_avail = 0; + while (digitalRead(_spi_irq) == 1) { + uint8_t header_master[5] = {0x0b, 0x00, 0x00, 0x00, 0x00}; + + if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { + detachInterrupt(_spi_irq); + } + + _spi->beginTransaction(_spiSettings); + + digitalWrite(_cs_pin, LOW); + + /* Write the header */ + _spi->transfer(header_master, 5); + + if (_ble_chip == SPBTLE_RF || _ble_chip == BLUENRG_M0) { + /* device is ready */ + if (header_master[0] == 0x02) { + /* device is ready */ + uint16_t byte_count = (header_master[4] << 8) | header_master[3]; + + if (byte_count > 0) { + /* Read the response */ + for (int j = 0; j < byte_count; j++) { + data[j] = _spi->transfer(0x00); + } + + if (byte_count >= 7) { + if (data[0] == 0x04 && + data[1] == 0x0E && + data[2] == 0x04 && + data[3] == 0x01 && + data[4] == 0x0C && + data[5] == 0xFC && + data[6] == 0x00) { + status = 1; + } + } + } + } + } else if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { + uint16_t byte_count = (header_master[4] << 8) | header_master[3]; + + if (byte_count > 0) { + /* Read the response */ + for (int j = 0; j < byte_count; j++) { + data[j] = _spi->transfer(0x00); + } + + if (byte_count >= 7) { + if (data[0] == 0x04 && + data[1] == 0x0E && + data[2] == 0x04 && + data[3] == 0x01 && + data[4] == 0x0C && + data[5] == 0xFC && + data[6] == 0x00) { + status = 1; + } + } + } + } + + digitalWrite(_cs_pin, HIGH); + + _spi->endTransaction(); + + if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + } + } + } while (!status); +} + +void HCISpiTransportClass::enable_ll_only() +{ + uint8_t header_master[5] = {0x0a, 0x00, 0x00, 0x00, 0x00}; + uint8_t cmd[7] = {0x01, 0x0C, 0xFC, 0x03, 0x2C, 0x01, 0x01}; // Enable LL_ONLY + int result = 0; + + do { + if (_ble_chip == SPBTLE_RF || _ble_chip == BLUENRG_M0) { + result = 0; + + _spi->beginTransaction(_spiSettings); + + digitalWrite(_cs_pin, LOW); + + /* Write the header */ + _spi->transfer(header_master, 5); + + /* device is ready */ + if (header_master[0] == 0x02) { + /* Write the data */ + if (header_master[1] >= 7) { + /* Write the data */ + _spi->transfer((void *)cmd, 7); + } else { + result = -2; + } + } else { + result = -1; + } + + digitalWrite(_cs_pin, HIGH); + + _spi->endTransaction(); + } else if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { + uint32_t tickstart_data_available = millis(); + result = 0; + + detachInterrupt(_spi_irq); + + _spi->beginTransaction(_spiSettings); + + digitalWrite(_cs_pin, LOW); + + while (!(digitalRead(_spi_irq) == 1)) { + if ((millis() - tickstart_data_available) > 1000) { + result = -3; + break; + } + } + + if (result == -3) { + digitalWrite(_cs_pin, HIGH); + _spi->endTransaction(); + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + break; + } + + /* Write the header */ + _spi->transfer(header_master, 5); + + if ((int)((((uint16_t)header_master[2]) << 8) | ((uint16_t)header_master[1])) >= 7) { + /* Write the data */ + _spi->transfer((void *)cmd, 7); + } else { + result = -2; + } + + digitalWrite(_cs_pin, HIGH); + + _spi->endTransaction(); + + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + } + } while (result < 0); +} + +void HCISpiTransportClass::wait_for_aci_gatt_init() +{ + uint8_t data[8]; + int status = 0; + + do { + while (!data_avail); + + if (digitalRead(_spi_irq) == 0) { + continue; + } + + data_avail = 0; + while (digitalRead(_spi_irq) == 1) { + uint8_t header_master[5] = {0x0b, 0x00, 0x00, 0x00, 0x00}; + + if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { + detachInterrupt(_spi_irq); + } + + _spi->beginTransaction(_spiSettings); + + digitalWrite(_cs_pin, LOW); + + /* Write the header */ + _spi->transfer(header_master, 5); + + if (_ble_chip == SPBTLE_RF || _ble_chip == BLUENRG_M0) { + /* device is ready */ + if (header_master[0] == 0x02) { + /* device is ready */ + uint16_t byte_count = (header_master[4] << 8) | header_master[3]; + + if (byte_count > 0) { + /* Read the response */ + for (int j = 0; j < byte_count; j++) { + data[j] = _spi->transfer(0x00); + } + + if (byte_count >= 7) { + if (data[0] == 0x04 && + data[1] == 0x0E && + data[2] == 0x04 && + data[3] == 0x01 && + data[4] == 0x01 && + data[5] == 0xFD && + data[6] == 0x00) { + status = 1; + } + } + } + } + } else if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { + uint16_t byte_count = (header_master[4] << 8) | header_master[3]; + + if (byte_count > 0) { + /* Read the response */ + for (int j = 0; j < byte_count; j++) { + data[j] = _spi->transfer(0x00); + } + + if (byte_count >= 7) { + if (data[0] == 0x04 && + data[1] == 0x0E && + data[2] == 0x04 && + data[3] == 0x01 && + data[4] == 0x01 && + data[5] == 0xFD && + data[6] == 0x00) { + status = 1; + } + } + } + } + + digitalWrite(_cs_pin, HIGH); + + _spi->endTransaction(); + + if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + } + } + } while (!status); +} + +void HCISpiTransportClass::aci_gatt_init() +{ + uint8_t header_master[5] = {0x0a, 0x00, 0x00, 0x00, 0x00}; + uint8_t cmd[4] = {0x01, 0x01, 0xFD, 0x00}; // ACI_GATT_INIT + int result = 0; + + do { + if (_ble_chip == SPBTLE_RF || _ble_chip == BLUENRG_M0) { + result = 0; + + _spi->beginTransaction(_spiSettings); + + digitalWrite(_cs_pin, LOW); + + /* Write the header */ + _spi->transfer(header_master, 5); + + /* device is ready */ + if (header_master[0] == 0x02) { + /* Write the data */ + if (header_master[1] >= 4) { + /* Write the data */ + _spi->transfer((void *)cmd, 4); + } else { + result = -2; + } + } else { + result = -1; + } + + digitalWrite(_cs_pin, HIGH); + + _spi->endTransaction(); + } else if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { + uint32_t tickstart_data_available = millis(); + result = 0; + + detachInterrupt(_spi_irq); + + _spi->beginTransaction(_spiSettings); + + digitalWrite(_cs_pin, LOW); + + while (!(digitalRead(_spi_irq) == 1)) { + if ((millis() - tickstart_data_available) > 1000) { + result = -3; + break; + } + } + + if (result == -3) { + digitalWrite(_cs_pin, HIGH); + _spi->endTransaction(); + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + break; + } + + /* Write the header */ + _spi->transfer(header_master, 5); + + if ((int)((((uint16_t)header_master[2]) << 8) | ((uint16_t)header_master[1])) >= 4) { + /* Write the data */ + _spi->transfer((void *)cmd, 4); + } else { + result = -2; + } + + digitalWrite(_cs_pin, HIGH); + + _spi->endTransaction(); + + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + } + } while (result < 0); +} + +void HCISpiTransportClass::wait_for_aci_gap_init() +{ + uint8_t data[14]; + int status = 0; + + do { + while (!data_avail); + + if (digitalRead(_spi_irq) == 0) { + continue; + } + + data_avail = 0; + while (digitalRead(_spi_irq) == 1) { + uint8_t header_master[5] = {0x0b, 0x00, 0x00, 0x00, 0x00}; + + if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { + detachInterrupt(_spi_irq); + } + + _spi->beginTransaction(_spiSettings); + + digitalWrite(_cs_pin, LOW); + + /* Write the header */ + _spi->transfer(header_master, 5); + + if (_ble_chip == SPBTLE_RF || _ble_chip == BLUENRG_M0) { + /* device is ready */ + if (header_master[0] == 0x02) { + /* device is ready */ + uint16_t byte_count = (header_master[4] << 8) | header_master[3]; + + if (byte_count > 0) { + /* Read the response */ + for (int j = 0; j < byte_count; j++) { + data[j] = _spi->transfer(0x00); + } + + if (byte_count >= 13) { + if (data[0] == 0x04 && + data[1] == 0x0E && + data[2] == 0x0A && + data[3] == 0x01 && + data[4] == 0x8A && + data[5] == 0xFC && + data[6] == 0x00) { + status = 1; + } + } + } + } + } else if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { + uint16_t byte_count = (header_master[4] << 8) | header_master[3]; + + if (byte_count > 0) { + /* Read the response */ + for (int j = 0; j < byte_count; j++) { + data[j] = _spi->transfer(0x00); + } + + if (byte_count >= 13) { + if (data[0] == 0x04 && + data[1] == 0x0E && + data[2] == 0x0A && + data[3] == 0x01 && + data[4] == 0x8A && + data[5] == 0xFC && + data[6] == 0x00) { + status = 1; + } + } + } + } + + digitalWrite(_cs_pin, HIGH); + + _spi->endTransaction(); + + if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + } + } + } while (!status); +} + +void HCISpiTransportClass::aci_gap_init() +{ + uint8_t header_master[5] = {0x0a, 0x00, 0x00, 0x00, 0x00}; + uint8_t cmd_lp[8] = {0x01, 0x8A, 0xFC, 0x04, 0x0F, 0x00, 0x00, 0x00}; // ACI_GAP_INIT + uint8_t cmd_others[7] = {0x01, 0x8A, 0xFC, 0x03, 0x0F, 0x00, 0x00}; // ACI_GAP_INIT + uint8_t *cmd, cmd_size; + if (_ble_chip == BLUENRG_LP) { + cmd = cmd_lp; + cmd_size = 8; + } else { + cmd = cmd_others; + cmd_size = 7; + } + int result = 0; + + do { + if (_ble_chip == SPBTLE_RF || _ble_chip == BLUENRG_M0) { + result = 0; + + _spi->beginTransaction(_spiSettings); + + digitalWrite(_cs_pin, LOW); + + /* Write the header */ + _spi->transfer(header_master, 5); + + /* device is ready */ + if (header_master[0] == 0x02) { + /* Write the data */ + if (header_master[1] >= cmd_size) { + /* Write the data */ + _spi->transfer((void *)cmd, cmd_size); + } else { + result = -2; + } + } else { + result = -1; + } + + digitalWrite(_cs_pin, HIGH); + + _spi->endTransaction(); + } else if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { + uint32_t tickstart_data_available = millis(); + result = 0; + + detachInterrupt(_spi_irq); + + _spi->beginTransaction(_spiSettings); + + digitalWrite(_cs_pin, LOW); + + while (!(digitalRead(_spi_irq) == 1)) { + if ((millis() - tickstart_data_available) > 1000) { + result = -3; + break; + } + } + + if (result == -3) { + digitalWrite(_cs_pin, HIGH); + _spi->endTransaction(); + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + break; + } + + /* Write the header */ + _spi->transfer(header_master, 5); + + if ((int)((((uint16_t)header_master[2]) << 8) | ((uint16_t)header_master[1])) >= cmd_size) { + /* Write the data */ + _spi->transfer((void *)cmd, cmd_size); + } else { + result = -2; + } + + digitalWrite(_cs_pin, HIGH); + + _spi->endTransaction(); + + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + } + } while (result < 0); +} + +void HCISpiTransportClass::wait_for_aci_read_config_parameter() +{ + uint8_t data[15]; + int status = 0; + + do { + while (!data_avail); + + if (digitalRead(_spi_irq) == 0) { + continue; + } + + data_avail = 0; + while (digitalRead(_spi_irq) == 1) { + uint8_t header_master[5] = {0x0b, 0x00, 0x00, 0x00, 0x00}; + + if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { + detachInterrupt(_spi_irq); + } + + _spi->beginTransaction(_spiSettings); + + digitalWrite(_cs_pin, LOW); + + /* Write the header */ + _spi->transfer(header_master, 5); + + if (_ble_chip == SPBTLE_RF || _ble_chip == BLUENRG_M0) { + /* device is ready */ + if (header_master[0] == 0x02) { + /* device is ready */ + uint16_t byte_count = (header_master[4] << 8) | header_master[3]; + + if (byte_count > 0) { + /* Read the response */ + for (int j = 0; j < byte_count; j++) { + data[j] = _spi->transfer(0x00); + } + + if (byte_count >= 13) { + if (data[0] == 0x04 && + data[1] == 0x0E && + data[2] == 0x0A && + data[3] == 0x01 && + data[4] == 0x0D && + data[5] == 0xFC && + data[6] == 0x00) { + memcpy(_random_addr, &data[7], 6); + status = 1; + } + } + } + } + } else if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { + uint16_t byte_count = (header_master[4] << 8) | header_master[3]; + + if (byte_count > 0) { + /* Read the response */ + for (int j = 0; j < byte_count; j++) { + data[j] = _spi->transfer(0x00); + } + + if (byte_count >= 14) { + if (data[0] == 0x04 && + data[1] == 0x0E && + data[2] == 0x0B && + data[3] == 0x01 && + data[4] == 0x0D && + data[5] == 0xFC && + data[6] == 0x00) { + memcpy(_random_addr, &data[8], 6); + status = 1; + _random_addr_done = true; + } + } + } + } + + digitalWrite(_cs_pin, HIGH); + + _spi->endTransaction(); + + if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + } + } + } while (!status); +} + +void HCISpiTransportClass::aci_read_config_parameter() +{ + uint8_t header_master[5] = {0x0a, 0x00, 0x00, 0x00, 0x00}; + uint8_t cmd[5] = {0x01, 0x0D, 0xFC, 0x01, 0x80}; // ACI_READ_CONFIG_PARAMETER + int result = 0; + + do { + if (_ble_chip == SPBTLE_RF || _ble_chip == BLUENRG_M0) { + result = 0; + + _spi->beginTransaction(_spiSettings); + + digitalWrite(_cs_pin, LOW); + + /* Write the header */ + _spi->transfer(header_master, 5); + + /* device is ready */ + if (header_master[0] == 0x02) { + /* Write the data */ + if (header_master[1] >= 5) { + /* Write the data */ + _spi->transfer((void *)cmd, 5); + } else { + result = -2; + } + } else { + result = -1; + } + + digitalWrite(_cs_pin, HIGH); + + _spi->endTransaction(); + } else if (_ble_chip == SPBTLE_1S || _ble_chip == BLUENRG_M2SP || _ble_chip == BLUENRG_LP) { + uint32_t tickstart_data_available = millis(); + result = 0; + + detachInterrupt(_spi_irq); + + _spi->beginTransaction(_spiSettings); + + digitalWrite(_cs_pin, LOW); + + while (!(digitalRead(_spi_irq) == 1)) { + if ((millis() - tickstart_data_available) > 1000) { + result = -3; + break; + } + } + + if (result == -3) { + digitalWrite(_cs_pin, HIGH); + _spi->endTransaction(); + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + break; + } + + /* Write the header */ + _spi->transfer(header_master, 5); + + if ((int)((((uint16_t)header_master[2]) << 8) | ((uint16_t)header_master[1])) >= 5) { + /* Write the data */ + _spi->transfer((void *)cmd, 5); + } else { + result = -2; + } + + digitalWrite(_cs_pin, HIGH); + + _spi->endTransaction(); + + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + } + } while (result < 0); +} + +void HCISpiTransportClass::hci_reset() +{ + uint8_t header_master[5] = {0x0a, 0x00, 0x00, 0x00, 0x00}; + uint8_t cmd[4] = {0x01, 0x03, 0x0C, 0x00}; // HCI_RESET + int result = 0; + + do { + if (_ble_chip == BLUENRG_LP) { + uint32_t tickstart_data_available = millis(); + result = 0; + + detachInterrupt(_spi_irq); + + _spi->beginTransaction(_spiSettings); + + digitalWrite(_cs_pin, LOW); + + while (!(digitalRead(_spi_irq) == 1)) { + if ((millis() - tickstart_data_available) > 1000) { + result = -3; + break; + } + } + + if (result == -3) { + digitalWrite(_cs_pin, HIGH); + _spi->endTransaction(); + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + break; + } + + /* Write the header */ + _spi->transfer(header_master, 5); + + if ((int)((((uint16_t)header_master[2]) << 8) | ((uint16_t)header_master[1])) >= 4) { + /* Write the data */ + _spi->transfer((void *)cmd, 4); + } else { + result = -2; + } + + digitalWrite(_cs_pin, HIGH); + + _spi->endTransaction(); + + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + } + } while (result < 0); +} + +void HCISpiTransportClass::set_address() +{ + uint8_t header_master[5] = {0x0a, 0x00, 0x00, 0x00, 0x00}; + uint8_t cmd[10] = {0x01, 0x05, 0x20, 0x06}; // SET ADDR + int result = 0; + memcpy(&cmd[4], _random_addr, 6); + + do { + if (_ble_chip == BLUENRG_LP) { + uint32_t tickstart_data_available = millis(); + result = 0; + + detachInterrupt(_spi_irq); + + _spi->beginTransaction(_spiSettings); + + digitalWrite(_cs_pin, LOW); + + while (!(digitalRead(_spi_irq) == 1)) { + if ((millis() - tickstart_data_available) > 1000) { + result = -3; + break; + } + } + + if (result == -3) { + digitalWrite(_cs_pin, HIGH); + _spi->endTransaction(); + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + break; + } + + /* Write the header */ + _spi->transfer(header_master, 5); + + if ((int)((((uint16_t)header_master[2]) << 8) | ((uint16_t)header_master[1])) >= 10) { + /* Write the data */ + _spi->transfer((void *)cmd, 10); + } else { + result = -2; + } + + digitalWrite(_cs_pin, HIGH); + + _spi->endTransaction(); + + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + } + } while (result < 0); +} + +void HCISpiTransportClass::wait_for_set_address() +{ + uint8_t data[15]; + int status = 0; + + if (_ble_chip != BLUENRG_LP) { + return; + } + + do { + while (!data_avail); + + if (digitalRead(_spi_irq) == 0) { + continue; + } + + data_avail = 0; + while (digitalRead(_spi_irq) == 1) { + uint8_t header_master[5] = {0x0b, 0x00, 0x00, 0x00, 0x00}; + uint16_t byte_count = 0; + + detachInterrupt(_spi_irq); + + _spi->beginTransaction(_spiSettings); + + digitalWrite(_cs_pin, LOW); + + /* Write the header */ + _spi->transfer(header_master, 5); + + byte_count = (header_master[4] << 8) | header_master[3]; + + if (byte_count > 0) { + /* Read the response */ + for (int j = 0; j < byte_count; j++) { + data[j] = _spi->transfer(0x00); + } + + if (byte_count >= 7) { // 040E0401052000 + if (data[0] == 0x04 && + data[1] == 0x0E && + data[2] == 0x04 && + data[3] == 0x01 && + data[4] == 0x05 && + data[5] == 0x20 && + data[6] == 0x00) { + status = 1; + } + } + } + + digitalWrite(_cs_pin, HIGH); + + _spi->endTransaction(); + + attachInterrupt(_spi_irq, SPI_Irq_Callback, RISING); + } + } while (!status); +} + +HCITransportInterface& HCITransport = HCISpiTransport; diff --git a/src/utility/HCISpiTransport.h b/src/utility/HCISpiTransport.h new file mode 100644 index 00000000..34af1aa9 --- /dev/null +++ b/src/utility/HCISpiTransport.h @@ -0,0 +1,83 @@ +/* + This file is part of the STM32duinoBLE library. + Copyright (c) 2019 STMicroelectronics. All rights reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef _HCI_SPI_TRANSPORT_H_ +#define _HCI_SPI_TRANSPORT_H_ + +#include "HCITransport.h" +#include "SPI.h" + +typedef enum BLEChip_s { + SPBTLE_RF, + SPBTLE_1S, + BLUENRG_M2SP, + BLUENRG_M0, + BLUENRG_LP +} BLEChip_t; + +#ifndef BLE_SPI_BYTE_ORDER + #define BLE_SPI_BYTE_ORDER MSBFIRST +#endif +#define BLE_MODULE_SPI_BUFFER_SIZE 128 + +class HCISpiTransportClass : public HCITransportInterface { + public: + HCISpiTransportClass(SPIClass &spi, BLEChip_t ble_chip, uint8_t cs_pin, uint8_t spi_irq, uint8_t ble_rst, uint32_t frequency, uint8_t spi_mode); + virtual ~HCISpiTransportClass(); + + virtual int begin(); + virtual void end(); + + virtual void wait(unsigned long timeout); + + virtual int available(); + virtual int peek(); + virtual int read(); + + virtual size_t write(const uint8_t *data, size_t length); + + private: + void wait_for_blue_initialize(); + void wait_for_enable_ll_only(); + void enable_ll_only(); + void wait_for_aci_gatt_init(); + void aci_gatt_init(); + void wait_for_aci_gap_init(); + void aci_gap_init(); + void wait_for_aci_read_config_parameter(); + void aci_read_config_parameter(); + void hci_reset(); + void set_address(); + void wait_for_set_address(); + SPIClass *_spi; + SPISettings _spiSettings; + BLEChip_t _ble_chip; + uint8_t _cs_pin; + uint8_t _spi_irq; + uint8_t _ble_rst; + uint8_t _rxbuff[BLE_MODULE_SPI_BUFFER_SIZE]; + uint16_t _read_index; + uint16_t _write_index; + uint16_t _write_index_initial; + uint8_t _initial_phase; + uint8_t _random_addr[6]; + bool _random_addr_done; +}; + +#endif /* _HCI_SPI_TRANSPORT_H_ */ From 6f53cbe994c1d23a770313739d596e9b3e75fbe4 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Wed, 26 Mar 2025 09:03:20 +0100 Subject: [PATCH 206/226] chore: moved to STM32duinoBLE Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- .github/dependabot.yml | 13 - .github/workflows/compile-examples.yml | 95 - .github/workflows/report-size-deltas.yml | 24 - .github/workflows/sync-labels.yml | 138 - .github/workflows/unit-tests.yml | 58 - README.md | 28 +- docs/api.md | 3820 ----------------- docs/assets/ble-bulletin-board-model.png | Bin 41914 -> 0 bytes docs/readme.md | 91 - examples/Central/LedControl/LedControl.ino | 6 +- .../PeripheralExplorer/PeripheralExplorer.ino | 5 +- examples/Central/Scan/Scan.ino | 5 +- .../Central/ScanCallback/ScanCallback.ino | 5 +- .../SensorTagButton/SensorTagButton.ino | 5 +- .../EnhancedAdvertising.ino | 2 +- .../RawDataAdvertising/RawDataAdvertising.ino | 2 +- .../BatteryMonitor/BatteryMonitor.ino | 5 +- examples/Peripheral/ButtonLED/ButtonLED.ino | 6 +- .../Peripheral/CallbackLED/CallbackLED.ino | 5 +- .../EncryptedBatteryMonitor.ino | 265 -- examples/Peripheral/LED/LED.ino | 5 +- extras/arduino-ble-parser.py | 85 - extras/test/.gitignore | 17 - extras/test/CMakeLists.txt | 164 - extras/test/include/Arduino.h | 58 - .../FakeBLELocalDevice.h | 35 - .../include/test_discovered_device/FakeGAP.h | 33 - extras/test/include/util/Common.h | 167 - extras/test/include/util/HCIFakeTransport.h | 19 - extras/test/include/util/Stream.h | 40 - extras/test/include/util/String.h | 248 -- extras/test/include/util/TestUtil.h | 3 - extras/test/include/util/itoa.h | 37 - extras/test/src/Arduino.cpp | 44 - .../FakeBLELocalDevice.cpp | 40 - .../test_advertising_data.cpp | 204 - .../test_advertising_data/test_local_name.cpp | 95 - .../test_manufacturer.cpp | 173 - .../test_advertising_data/test_service.cpp | 164 - .../src/test_discovered_device/FakeGAP.cpp | 31 - .../test_discovered_device.cpp | 52 - extras/test/src/test_main.cpp | 21 - extras/test/src/test_uuid/test_uuid.cpp | 52 - extras/test/src/util/Common.cpp | 34 - extras/test/src/util/HCIFakeTransport.cpp | 23 - extras/test/src/util/String.cpp | 755 ---- extras/test/src/util/TestUtil.cpp | 3 - extras/test/src/util/itoa.c | 126 - keywords.txt | 4 +- library.properties | 14 +- src/{ArduinoBLE.h => STM32duinoBLE.h} | 4 +- src/utility/CordioHCICustomDriver.h | 17 - src/utility/HCICordioTransport.cpp | 322 -- src/utility/HCICordioTransport.h | 54 - src/utility/HCISilabsTransport.cpp | 130 - src/utility/HCISilabsTransport.h | 42 - src/utility/HCIUartTransport.cpp | 109 - src/utility/HCIUartTransport.h | 46 - src/utility/HCIVirtualTransport.cpp | 144 - src/utility/HCIVirtualTransport.h | 50 - src/utility/HCIVirtualTransportAT.cpp | 112 - src/utility/HCIVirtualTransportAT.h | 42 - src/utility/btct.cpp | 2 +- 63 files changed, 53 insertions(+), 8345 deletions(-) delete mode 100644 .github/dependabot.yml delete mode 100644 .github/workflows/report-size-deltas.yml delete mode 100644 .github/workflows/sync-labels.yml delete mode 100644 .github/workflows/unit-tests.yml delete mode 100644 docs/api.md delete mode 100644 docs/assets/ble-bulletin-board-model.png delete mode 100644 docs/readme.md delete mode 100644 examples/Peripheral/EncryptedBatteryMonitor/EncryptedBatteryMonitor.ino delete mode 100644 extras/arduino-ble-parser.py delete mode 100644 extras/test/.gitignore delete mode 100644 extras/test/CMakeLists.txt delete mode 100644 extras/test/include/Arduino.h delete mode 100644 extras/test/include/test_advertising_data/FakeBLELocalDevice.h delete mode 100644 extras/test/include/test_discovered_device/FakeGAP.h delete mode 100644 extras/test/include/util/Common.h delete mode 100644 extras/test/include/util/HCIFakeTransport.h delete mode 100644 extras/test/include/util/Stream.h delete mode 100644 extras/test/include/util/String.h delete mode 100644 extras/test/include/util/TestUtil.h delete mode 100644 extras/test/include/util/itoa.h delete mode 100644 extras/test/src/Arduino.cpp delete mode 100644 extras/test/src/test_advertising_data/FakeBLELocalDevice.cpp delete mode 100644 extras/test/src/test_advertising_data/test_advertising_data.cpp delete mode 100644 extras/test/src/test_advertising_data/test_local_name.cpp delete mode 100644 extras/test/src/test_advertising_data/test_manufacturer.cpp delete mode 100644 extras/test/src/test_advertising_data/test_service.cpp delete mode 100644 extras/test/src/test_discovered_device/FakeGAP.cpp delete mode 100644 extras/test/src/test_discovered_device/test_discovered_device.cpp delete mode 100644 extras/test/src/test_main.cpp delete mode 100644 extras/test/src/test_uuid/test_uuid.cpp delete mode 100644 extras/test/src/util/Common.cpp delete mode 100644 extras/test/src/util/HCIFakeTransport.cpp delete mode 100644 extras/test/src/util/String.cpp delete mode 100644 extras/test/src/util/TestUtil.cpp delete mode 100644 extras/test/src/util/itoa.c rename src/{ArduinoBLE.h => STM32duinoBLE.h} (94%) delete mode 100644 src/utility/CordioHCICustomDriver.h delete mode 100644 src/utility/HCICordioTransport.cpp delete mode 100644 src/utility/HCICordioTransport.h delete mode 100644 src/utility/HCISilabsTransport.cpp delete mode 100644 src/utility/HCISilabsTransport.h delete mode 100644 src/utility/HCIUartTransport.cpp delete mode 100644 src/utility/HCIUartTransport.h delete mode 100644 src/utility/HCIVirtualTransport.cpp delete mode 100644 src/utility/HCIVirtualTransport.h delete mode 100644 src/utility/HCIVirtualTransportAT.cpp delete mode 100644 src/utility/HCIVirtualTransportAT.h diff --git a/.github/dependabot.yml b/.github/dependabot.yml deleted file mode 100644 index f2bfa724..00000000 --- a/.github/dependabot.yml +++ /dev/null @@ -1,13 +0,0 @@ -# See: https://docs.github.com/en/code-security/supply-chain-security/configuration-options-for-dependency-updates#about-the-dependabotyml-file -version: 2 - -updates: - # Configure check for outdated GitHub Actions actions in workflows. - # Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/dependabot/README.md - # See: https://docs.github.com/en/code-security/supply-chain-security/keeping-your-actions-up-to-date-with-dependabot - - package-ecosystem: github-actions - directory: / # Check the repository's workflows under /.github/workflows/ - schedule: - interval: daily - labels: - - "topic: infrastructure" diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index d97458e6..b82efaec 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -16,100 +16,5 @@ on: # Run every Tuesday at 8 AM UTC to catch breakage caused by changes to external resources (libraries, platforms). - cron: "0 8 * * TUE" workflow_dispatch: - repository_dispatch: jobs: - build: - name: ${{ matrix.board.fqbn }} - runs-on: ubuntu-latest - - env: - SKETCHES_REPORTS_PATH: sketches-reports - - strategy: - fail-fast: false - - matrix: - board: - - fqbn: arduino:samd:mkrwifi1010 - platforms: | - - name: arduino:samd - artifact-name-suffix: arduino-samd-mkrwifi1010 - - fqbn: arduino:samd:nano_33_iot - platforms: | - - name: arduino:samd - artifact-name-suffix: arduino-samd-nano_33_iot - - fqbn: arduino:megaavr:uno2018:mode=on - platforms: | - - name: arduino:megaavr - artifact-name-suffix: arduino-megaavr-uno2018 - - fqbn: arduino:mbed_nano:nano33ble - platforms: | - - name: arduino:mbed_nano - artifact-name-suffix: arduino-mbed_nano-nano33ble - - fqbn: arduino:mbed_nano:nanorp2040connect - platforms: | - - name: arduino:mbed_nano - artifact-name-suffix: arduino-mbed_nano-nanorp2040connect - - fqbn: arduino:renesas_uno:unor4wifi - platforms: | - - name: arduino:renesas_uno - artifact-name-suffix: arduino-renesas_uno-unor4wifi - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Compile examples - uses: arduino/compile-sketches@v1 - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - fqbn: ${{ matrix.board.fqbn }} - platforms: ${{ matrix.board.platforms }} - libraries: | - # Install the library from the local path. - - source-path: ./ - sketch-paths: | - - examples - enable-deltas-report: true - sketches-report-path: ${{ env.SKETCHES_REPORTS_PATH }} - - - name: Save sketches report as workflow artifact - uses: actions/upload-artifact@v4 - with: - if-no-files-found: error - path: ${{ env.SKETCHES_REPORTS_PATH }} - name: sketches-report-${{ matrix.board.artifact-name-suffix }} - - build-for-esp32: - runs-on: ubuntu-latest - - strategy: - matrix: - fqbn: - - esp32:esp32:esp32 - - esp32:esp32:esp32s3 - - esp32:esp32:esp32c3 - - esp32:esp32:esp32c6 - - esp32:esp32:esp32h2 - # Not supported out of the box by ESP32 Arduino core - #- esp32:esp32:esp32c2 - - steps: - - uses: actions/checkout@v4 - - uses: arduino/compile-sketches@v1 - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - fqbn: ${{ matrix.fqbn }} - platforms: | - - name: esp32:esp32 - source-url: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json - sketch-paths: | - - examples/Central/Scan - - examples/Central/PeripheralExplorer - - examples/Central/ScanCallback - - examples/Central/SensorTagButton - - examples/Peripheral/Advertising/EnhancedAdvertising - - examples/Peripheral/Advertising/RawDataAdvertising - cli-compile-flags: | - - --warnings="none" diff --git a/.github/workflows/report-size-deltas.yml b/.github/workflows/report-size-deltas.yml deleted file mode 100644 index 39e2a0ad..00000000 --- a/.github/workflows/report-size-deltas.yml +++ /dev/null @@ -1,24 +0,0 @@ -name: Report Size Deltas - -# See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows -on: - push: - paths: - - ".github/workflows/report-size-deltas.yml" - schedule: - # Run at the minimum interval allowed by GitHub Actions. - # Note: GitHub Actions periodically has outages which result in workflow failures. - # In this event, the workflows will start passing again once the service recovers. - - cron: "*/5 * * * *" - workflow_dispatch: - repository_dispatch: - -jobs: - report: - runs-on: ubuntu-latest - steps: - - name: Comment size deltas reports to PRs - uses: arduino/report-size-deltas@v1 - with: - # Regex matching the names of the workflow artifacts created by the "Compile Examples" workflow - sketches-reports-source: ^sketches-report-.+ diff --git a/.github/workflows/sync-labels.yml b/.github/workflows/sync-labels.yml deleted file mode 100644 index 53a9f54f..00000000 --- a/.github/workflows/sync-labels.yml +++ /dev/null @@ -1,138 +0,0 @@ -# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/sync-labels.md -name: Sync Labels - -# See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows -on: - push: - paths: - - ".github/workflows/sync-labels.ya?ml" - - ".github/label-configuration-files/*.ya?ml" - pull_request: - paths: - - ".github/workflows/sync-labels.ya?ml" - - ".github/label-configuration-files/*.ya?ml" - schedule: - # Run daily at 8 AM UTC to sync with changes to shared label configurations. - - cron: "0 8 * * *" - workflow_dispatch: - repository_dispatch: - -env: - CONFIGURATIONS_FOLDER: .github/label-configuration-files - CONFIGURATIONS_ARTIFACT: label-configuration-files - -jobs: - check: - runs-on: ubuntu-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Download JSON schema for labels configuration file - id: download-schema - uses: carlosperate/download-file-action@v2 - with: - file-url: https://raw.githubusercontent.com/arduino/tooling-project-assets/main/workflow-templates/assets/sync-labels/arduino-tooling-gh-label-configuration-schema.json - location: ${{ runner.temp }}/label-configuration-schema - - - name: Install JSON schema validator - run: | - sudo npm install \ - --global \ - ajv-cli \ - ajv-formats - - - name: Validate local labels configuration - run: | - # See: https://github.com/ajv-validator/ajv-cli#readme - ajv validate \ - --all-errors \ - -c ajv-formats \ - -s "${{ steps.download-schema.outputs.file-path }}" \ - -d "${{ env.CONFIGURATIONS_FOLDER }}/*.{yml,yaml}" - - download: - needs: check - runs-on: ubuntu-latest - - strategy: - matrix: - filename: - # Filenames of the shared configurations to apply to the repository in addition to the local configuration. - # https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/sync-labels - - universal.yml - - steps: - - name: Download - uses: carlosperate/download-file-action@v2 - with: - file-url: https://raw.githubusercontent.com/arduino/tooling-project-assets/main/workflow-templates/assets/sync-labels/${{ matrix.filename }} - - - name: Pass configuration files to next job via workflow artifact - uses: actions/upload-artifact@v4 - with: - path: | - *.yaml - *.yml - if-no-files-found: error - name: ${{ env.CONFIGURATIONS_ARTIFACT }} - - sync: - needs: download - runs-on: ubuntu-latest - - steps: - - name: Set environment variables - run: | - # See: https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable - echo "MERGED_CONFIGURATION_PATH=${{ runner.temp }}/labels.yml" >> "$GITHUB_ENV" - - - name: Determine whether to dry run - id: dry-run - if: > - github.event_name == 'pull_request' || - ( - ( - github.event_name == 'push' || - github.event_name == 'workflow_dispatch' - ) && - github.ref != format('refs/heads/{0}', github.event.repository.default_branch) - ) - run: | - # Use of this flag in the github-label-sync command will cause it to only check the validity of the - # configuration. - echo "::set-output name=flag::--dry-run" - - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Download configuration files artifact - uses: actions/download-artifact@v4 - with: - name: ${{ env.CONFIGURATIONS_ARTIFACT }} - path: ${{ env.CONFIGURATIONS_FOLDER }} - - - name: Remove unneeded artifact - uses: geekyeggo/delete-artifact@v5 - with: - name: ${{ env.CONFIGURATIONS_ARTIFACT }} - - - name: Merge label configuration files - run: | - # Merge all configuration files - shopt -s extglob - cat "${{ env.CONFIGURATIONS_FOLDER }}"/*.@(yml|yaml) > "${{ env.MERGED_CONFIGURATION_PATH }}" - - - name: Install github-label-sync - run: sudo npm install --global github-label-sync - - - name: Sync labels - env: - GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - # See: https://github.com/Financial-Times/github-label-sync - github-label-sync \ - --labels "${{ env.MERGED_CONFIGURATION_PATH }}" \ - ${{ steps.dry-run.outputs.flag }} \ - ${{ github.repository }} diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml deleted file mode 100644 index 2a96b8a5..00000000 --- a/.github/workflows/unit-tests.yml +++ /dev/null @@ -1,58 +0,0 @@ -name: Unit Tests - -on: - pull_request: - paths: - - ".github/workflows/unit-tests.yml" - - 'extras/test/**' - - 'src/**' - - push: - paths: - - ".github/workflows/unit-tests.yml" - - 'extras/test/**' - - 'src/**' - -jobs: - test: - name: Run unit tests - runs-on: ubuntu-latest - - env: - COVERAGE_DATA_PATH: extras/coverage-data/coverage.info - - steps: - - name: Checkout - uses: actions/checkout@v4 - - - uses: arduino/cpp-test-action@main - with: - runtime-paths: | - - extras/test/build/bin/TEST_TARGET_UUID - - extras/test/build/bin/TEST_TARGET_DISC_DEVICE - - extras/test/build/bin/TEST_TARGET_ADVERTISING_DATA - coverage-exclude-paths: | - - '*/extras/test/*' - - '/usr/*' - coverage-data-path: ${{ env.COVERAGE_DATA_PATH }} - - # A token is used to avoid intermittent spurious job failures caused by rate limiting. - - name: Set up Codecov upload token - run: | - if [[ "${{ github.repository }}" == "arduino-libraries/ArduinoBLE" ]]; then - # In order to avoid uploads of data from forks, only use the token for runs in the parent repo. - # Token is intentionally exposed. - # See: https://community.codecov.com/t/upload-issues-unable-to-locate-build-via-github-actions-api/3954 - CODECOV_TOKEN="8118de48-b2af-48b4-a66a-26026847bfc5" - else - # codecov/codecov-action does unauthenticated upload if empty string is passed via the `token` input. - CODECOV_TOKEN="" - fi - echo "CODECOV_TOKEN=$CODECOV_TOKEN" >> "$GITHUB_ENV" - - - name: Upload coverage report to Codecov - uses: codecov/codecov-action@v3 - with: - file: "${{ env.COVERAGE_DATA_PATH }}" - fail_ci_if_error: true - token: ${{ env.CODECOV_TOKEN }} diff --git a/README.md b/README.md index b0027583..e9f3a948 100644 --- a/README.md +++ b/README.md @@ -1,22 +1,24 @@ -# ArduinoBLE +# STM32duinoBLE -[](https://github.com/arduino-libraries/ArduinoBLE/actions?workflow=Compile+Examples) [](https://github.com/arduino-libraries/ArduinoBLE/actions?workflow=Spell+Check) +This library is a fork of ArduinoBLE library to add the support of SPBTLE-RF, SPBTLE-1S, BLUENRG-M2SP, BLUENRG-LP and BLUENRG-M0 BLE modules. -Enables Bluetooth® Low Energy connectivity on the Arduino MKR WiFi 1010, Arduino UNO WiFi Rev2, Arduino Nano 33 IoT, Arduino Nano 33 BLE, Arduino Portenta H7, Arduino Giga R1 and Arduino UNO R4 WiFi. +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], [B-L4S5I-IOT01A], [STEVAL-MKSBOX1V1], [STEVAL-MKBOXPRO] and with [STM32L562E-DK]. -This library supports creating a Bluetooth® Low Energy peripheral & central mode. + - 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: -For the Arduino MKR WiFi 1010, Arduino UNO WiFi Rev2, and Arduino Nano 33 IoT boards, it requires the NINA module to be running [Arduino NINA-W102 firmware](https://github.com/arduino/nina-fw) v1.2.0 or later. +https://github.com/stm32duino/Arduino_Core_STM32/wiki/STM32duinoBLE#stm32duinoble-with-steval_mksbox1v1 -For the Arduino UNO R4 WiFi, it requires the ESP32-S3 module to be running [firmware](https://github.com/arduino/uno-r4-wifi-usb-bridge) v0.2.0 or later. +- In order to use this library with X-NUCLEO-BNRG2A1, you need to update the firmware of the BLUENRG-M2SP BLE module mounted on that expansion board as described in the following wiki page: +https://github.com/stm32duino/Arduino_Core_STM32/wiki/STM32duinoBLE#stm32duinoble-with-x-nucleo-bnrg2a1 -For more information about this library please visit us at: +For more information about ArduinoBLE library please visit the official web page at: https://www.arduino.cc/en/Reference/ArduinoBLE ## License ``` +Copyright (c) 2019 STMicroelectronics. All rights reserved. Copyright (c) 2019 Arduino SA. All rights reserved. This library is free software; you can redistribute it and/or @@ -33,3 +35,15 @@ You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ``` + +B-L475E-IOT01A: https://www.st.com/en/evaluation-tools/b-l475e-iot01a.html +B-L4S5I-IOT01A: https://www.st.com/en/evaluation-tools/b-l4s5i-iot01a.html +NUCLEO-F401RE: https://www.st.com/en/evaluation-tools/nucleo-f401re.html +NUCLEO-L053R8: https://www.st.com/en/evaluation-tools/nucleo-l053r8.html +NUCLEO-L476RG: https://www.st.com/en/evaluation-tools/nucleo-l476rg.html +STEVAL-MKSBOX1V1: https://www.st.com/en/evaluation-tools/steval-mksbox1v1.html +STEVAL-MKBOXPRO: https://www.st.com/en/evaluation-tools/steval-mkboxpro.html +STM32L562E-DK: https://www.st.com/en/evaluation-tools/stm32l562e-dk.html +X-NUCLEO-BNRG2A1: https://www.st.com/en/ecosystems/x-nucleo-bnrg2a1.html +X-NUCLEO-IDB05A2: https://www.st.com/en/ecosystems/x-nucleo-idb05a2.html +X-NUCLEO-IDB05A1: https://www.st.com/en/ecosystems/x-nucleo-idb05a1.html \ No newline at end of file diff --git a/docs/api.md b/docs/api.md deleted file mode 100644 index d80d0cdc..00000000 --- a/docs/api.md +++ /dev/null @@ -1,3820 +0,0 @@ -# ArduinoBLE library - -## BLE class - -Used to enable the Bluetooth® Low Energy module. - -### `BLE.begin()` - -Initializes the Bluetooth® Low Energy device. - -#### Syntax - -``` -BLE.begin() - -``` - -#### Parameters - -None - -#### Returns -- 1 on success -- 0 on failure - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - -``` - -### `BLE.end()` - -Stops the Bluetooth® Low Energy device. - -#### Syntax - -``` -BLE.end() - -``` - -#### Parameters - -None - -#### Returns -Nothing - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - // .... - - BLE.end(); - - -``` - -### `BLE.poll()` - -Poll for Bluetooth® Low Energy radio events and handle them. - -#### Syntax - -``` -BLE.poll() -BLE.poll(timeout) - -``` - -#### Parameters - -**timeout**: optional timeout in ms, to wait for event. If not specified defaults to 0 ms. - -#### Returns -Nothing - -#### Example - -```arduino - - // assign event handlers for connected, disconnected to peripheral - BLE.setEventHandler(BLEConnected, blePeripheralConnectHandler); - BLE.setEventHandler(BLEDisconnected, blePeripheralDisconnectHandler); - - - BLE.poll(); - - -``` - -### `BLE.setEventHandler()` - -Set the event handler (callback) function that will be called when the specified event occurs. - -#### Syntax - -``` -BLE.setEventHandler(eventType, callback) - -``` - -#### Parameters - -- **eventType**: event type (BLEConnected, BLEDisconnected) -- **callback**: function to call when event occurs -#### Returns -Nothing. - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - // ... - - // assign event handlers for connected, disconnected to peripheral - BLE.setEventHandler(BLEConnected, blePeripheralConnectHandler); - BLE.setEventHandler(BLEDisconnected, blePeripheralDisconnectHandler); - - - -void blePeripheralConnectHandler(BLEDevice central) { - // central connected event handler - Serial.print("Connected event, central: "); - Serial.println(central.address()); -} - -void blePeripheralDisconnectHandler(BLEDevice central) { - // central disconnected event handler - Serial.print("Disconnected event, central: "); - Serial.println(central.address()); -} - - -``` - -### `BLE.connected()` - -Query if another Bluetooth® Low Energy device is connected - -#### Syntax - -``` -BLE.connected() - -``` - -#### Parameters - -None - -#### Returns -- **true** if another Bluetooth® Low Energy device is connected, -- otherwise **false**. - -#### Example - -```arduino - - // while the central is still connected to peripheral: - while (BLE.connected()) { - - // ... - } - - -``` - -### `BLE.disconnect()` - -Disconnect any Bluetooth® Low Energy devices that are connected - -#### Syntax - -``` -BLE.disconnect() - -``` - -#### Parameters - -None - -#### Returns -- **true** if any Bluetooth® Low Energy device that was previously connected was disconnected, -- otherwise **false**. - -#### Example - -```arduino - - if (BLE.connected()) { - BLE.disconnect(); - } - - -``` - -### `BLE.address()` - -Query the Bluetooth® address of the Bluetooth® Low Energy device. - -#### Syntax - -``` -BLE.address() - -``` - -#### Parameters - -None - -#### Returns -- The **Bluetooth® address** of the Bluetooth® Low Energy device (as a String). - -#### Example - -```arduino - - String address = BLE.address(); - - Serial.print("Local address is: "); - Serial.println(address); - - -``` - -### `BLE.rssi()` - -Query the RSSI (Received signal strength indication) of the connected Bluetooth® Low Energy device. - -#### Syntax - -``` -BLE.rssi() - -``` - -#### Parameters - -None - -#### Returns -- The **RSSI** of the connected Bluetooth® Low Energy device, 127 if no Bluetooth® Low Energy device is connected. - -#### Example - -```arduino - - if (BLE.connected()) { - Serial.print("RSSI = "); - Serial.println(BLE.rssi()); - } - - -``` - -### `BLE.setAdvertisedServiceUuid()` - -Set the advertised service UUID used when advertising. - -#### Syntax - -``` -BLE.setAdvertisedServiceUuid(uuid) - -``` - -#### Parameters - -- **uuid:** 16-bit or 128-bit Bluetooth® Low Energy UUID in **String** format - -#### Returns -Nothing - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - BLE.setAdvertisedServiceUuid("19B10000-E8F2-537E-4F6C-D104768A1214"); - - // ... - - // start advertising - BLE.advertise(); - - -``` - -### `BLE.setAdvertisedService()` - -Set the advertised service UUID used when advertising to the value of the BLEService provided. - -#### Syntax - -``` -BLE.setAdvertisedService(bleService) - -``` - -#### Parameters - -- **bleService:** BLEService to use UUID from - -#### Returns -Nothing - -#### Example - -```arduino - -BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // Bluetooth® Low Energy LED Service - -// ... - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - BLE.setAdvertisedService(ledService); - - // ... - - // start advertising - BLE.advertise(); - - -``` - -### `BLE.setManufacturerData()` - -Set the manufacturer data value used when advertising. - -#### Syntax - -``` -BLE.setManufacturerData(data, length) - -``` - -#### Parameters - -- **data:** byte array containing manufacturer data -- **length:** length of manufacturer data array - -#### Returns -Nothing - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - byte data[5] = { 0x01, 0x02, 0x03, 0x04, 0x05}; - - BLE.setManufacturerData(data, 5); - - // ... - - // start advertising - BLE.advertise(); - - - -``` - -### `BLE.setLocalName()` - -Set the local value used when advertising. - -#### Syntax - -``` -BLE.setLocalName(name) - -``` - -#### Parameters - -- **name:** local name value to use when advertising - -#### Returns -Nothing - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - BLE.setLocalName("LED"); - - // ... - - // start advertising - BLE.advertise(); - - - -``` - -### `BLE.setDeviceName()` - -Set the device name in the built in device name characteristic. If not set, the value defaults to “Arduino”. - -#### Syntax - -``` -BLE.setDeviceName(name) - -``` - -#### Parameters - -- **name:** device name value - -#### Returns -Nothing - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - BLE.setDeviceName("LED"); - - // ... - - // start advertising - BLE.advertise(); - - - -``` - -### `BLE.setAppearance()` - -Set the appearance in the built in appearance characteristic. If not set, the value defaults to 0x0000. - -#### Syntax - -``` -BLE.setAppearance(appearance) - -``` - -#### Parameters - -- **appearance:** appearance value - -#### Returns -Nothing - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - BLE.setAppearance(0x8000); - - // ... - - // start advertising - BLE.advertise(); - - - -``` - -### `BLE.addService()` - -Add a BLEService to the set of services the Bluetooth® Low Energy device provides - -#### Syntax - -``` -BLE.addService(service) - -``` - -#### Parameters - -- **service:** BLEService to add - -#### Returns -Nothing - -#### Example - -```arduino - -BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // Bluetooth® Low Energy LED Service - - - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - // ... - - BLE.addService(ledService); - - // ... - - -``` - -### `BLE.advertise()` - -Start advertising. - -#### Syntax - -``` -BLE.advertise() - -``` - -#### Parameters - -None - -#### Returns -- 1 on success, -- 0 on failure. - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - // ... - - BLE.advertise(); - - // ... - - -``` - -### `BLE.stopAdvertise()` - -Stop advertising. - -#### Syntax - -``` -BLE.stopAdvertise() - -``` - -#### Parameters - -None - -#### Returns -Nothing - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - // ... - - BLE.advertise(); - - // ... - - BLE.stopAdvertise(); - - -``` - -### `BLE.central()` - -Query the central Bluetooth® Low Energy device connected. - -#### Syntax - -``` -BLE.central() - -``` - -#### Parameters - -None - -#### Returns -- **BLEDevice** representing the central. - -#### Example - -```arduino - - // listen for Bluetooth® Low Energy peripherals to connect: - BLEDevice central = BLE.central(); - - // if a central is connected to peripheral: - if (central) { - Serial.print("Connected to central: "); - // print the central's MAC address: - Serial.println(central.address()); - } - - -``` - -### `BLE.setAdvertisingInterval()` - -Set the advertising interval in units of 0.625 ms. Defaults to 100ms (160 * 0.625 ms) if not provided. - -#### Syntax - -``` -BLE.setAdvertisingInterval(advertisingInterval) - -``` - -#### Parameters - -- **advertisingInterval:** advertising interval in units of 0.625 ms - -#### Returns -Nothing. - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - // ... - - BLE.setAdvertisingInterval(320); // 200 * 0.625 ms - - BLE.advertise(); - - -``` - -### `BLE.setConnectionInterval()` - -Set the minimum and maximum desired connection intervals in units of 1.25 ms. - -#### Syntax - -``` -BLE.setConnectionInterval(minimum, maximum) - -``` - -#### Parameters - -- **minimum:** minimum desired connection interval in units of 1.25 ms -- **maximum:** maximum desired connection interval in units of 1.25 ms - -#### Returns -Nothing. - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - // ... - - BLE.setConnectionInterval(0x0006, 0x0c80); // 7.5 ms minimum, 4 s maximum - - - -``` - -### `BLE.setConnectable()` - -Set if the device is connectable after advertising, defaults to **true**. - -#### Syntax - -``` -BLE.setConnectable(connectable) - -``` - -#### Parameters - -- **true**: the device will be connectable when advertising -- **false**: the device will NOT be connectable when advertising - -#### Returns -Nothing. - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - // ... - - BLE.setConnectable(false); // make the device unconnectable when advertising - - - -``` - -### `BLE.scan()` - -Start scanning for Bluetooth® Low Energy devices that are advertising. - -#### Syntax - -``` -BLE.scan() -BLE.scan(withDuplicates) - -``` - -#### Parameters - -- **withDuplicates:** optional, defaults to **false**. If **true**, advertisements received more than once will not be filtered - -#### Returns -- 1 on success, -- 0 on failure. - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - Serial.println("BLE Central scan"); - - // start scanning for peripheral - BLE.scan(); - - - BLEDevice peripheral = BLE.available(); - - if (peripheral) { - // ... - } - - -``` - -### `BLE.scanForName()` - -Start scanning for Bluetooth® Low Energy devices that are advertising with a particular (local) name. - -#### Syntax - -``` -BLE.scanForName(name) -BLE.scanForName(name, withDuplicates) - -``` - -#### Parameters - -- **name:** (local) name of device (as a **String**) to filter for -- **withDuplicates:** optional, defaults to **false**. If **true**, advertisements received more than once will not be filtered. - -#### Returns -- 1 on success, -- 0 on failure. - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - Serial.println("BLE Central scan"); - - // start scanning for peripheral - BLE.scanForName("LED"); - - - BLEDevice peripheral = BLE.available(); - - if (peripheral) { - // ... - } - - -``` - -### `BLE.scanForAddress()` - -Start scanning for Bluetooth® Low Energy devices that are advertising with a particular (Bluetooth®) address. - -#### Syntax - -``` -BLE.scanForAddress(address) -BLE.scanForAddress(address, withDuplicates) - -``` - -#### Parameters - -- **address:** (Bluetooth®) address (as a String) to filter for -- **withDuplicates:** optional, defaults to **false**. If **true**, advertisements received more than once will not be filtered - -#### Returns -- 1 on success, -- 0 on failure. - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - Serial.println("BLE Central scan"); - - // start scanning for peripheral - BLE.scanForAddress("aa:bb:cc:ee:dd:ff"); - - - BLEDevice peripheral = BLE.available(); - - if (peripheral) { - // ... - } - - -``` - -### `BLE.scanForUuid()` - -Start scanning for Bluetooth® Low Energy devices that are advertising with a particular (service) UUID. - -#### Syntax - -``` -BLE.scanForUuid(uuid) -BLE.scanForUuid(uuid, withDuplicates) - -``` - -#### Parameters - -- **uuid:** (service) UUID (as a **String**) to filter for -- **withDuplicates:** optional, defaults to **false**. If **true**, advertisements received more than once will not be filtered. - -#### Returns -- 1 on success, -- 0 on failure. - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - Serial.println("BLE Central scan"); - - // start scanning for peripheral - BLE.scanForUuid("aa10"); - - - BLEDevice peripheral = BLE.available(); - - if (peripheral) { - // ... - } - - -``` - -### `BLE.stopScan()` - -Stop scanning for Bluetooth® Low Energy devices that are advertising. - -#### Syntax - -``` -BLE.stopScan() - -``` - -#### Parameters - -None - -#### Returns -Nothing - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - Serial.println("BLE Central scan"); - - // start scanning for peripheral - BLE.scan(); - - BLE.stopScan(); - - -``` - -### `BLE.available()` - -Query for a discovered Bluetooth® Low Energy device that was found during scanning. - -#### Syntax - -``` -BLE.available() - -``` - -#### Parameters - -Nothing - -#### Returns -- **BLEDevice** representing the discovered device. - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - Serial.println("BLE Central scan"); - - // start scanning for peripheral - BLE.scan(); - - - BLEDevice peripheral = BLE.available(); - - if (peripheral) { - // ... - } - - -``` - -## BLEDevice Class - -Used to get information about the devices connected or discovered while scanning - -### `bleDevice.poll()` - -Poll for Bluetooth® Low Energy radio events for the specified Bluetooth® Low Energy device and handle them. - -#### Syntax - -``` -bleDevice.poll() -bleDevice.poll(timeout) - -``` - -#### Parameters - -- **timeout**: optional timeout in ms, to wait for event. If not specified defaults to 0 ms. - -#### Returns -Nothing - -#### Example - -```arduino - - // listen for Bluetooth® Low Energy centrals to connect: - BLEDevice central = BLE.central(); - - // if a central is connected to peripheral: - if (central) { - central.poll(); - - // ... - } - - -``` - -### `bleDevice.connected()` - -Query if a Bluetooth® Low Energy device is connected - -#### Syntax - -``` -bleDevice.connected() - -``` - -#### Parameters - -None - -#### Returns -- **true** if the Bluetooth® Low Energy device is connected, -- otherwise **false**. - -#### Example - -```arduino - - // listen for Bluetooth® Low Energy centrals to connect: - BLEDevice central = BLE.central(); - - // while the central is still connected - while (central.connected()) { - - // ... - } - - -``` - -### `bleDevice.disconnect()` - -Disconnect the Bluetooth® Low Energy device, if connected - -#### Syntax - -``` -bleDevice.disconnect() - -``` - -#### Parameters - -None - -#### Returns -- **true** if the Bluetooth® Low Energy device was disconnected, -- otherwise **false**. - -#### Example - -```arduino - - // listen for Bluetooth® Low Energy centrals to connect: - BLEDevice central = BLE.central(); - - - central.disconnect(); - - -``` - -### `bleDevice.address()` - -Query the Bluetooth® address of the Bluetooth® Low Energy device. - -#### Syntax - -``` -bleDevice.address() - -``` - -#### Parameters - -None - -#### Returns -- **Bluetooth® address** of the Bluetooth® Low Energy device (as a String). - -#### Example - -```arduino - - // listen for Bluetooth® Low Energy peripherals to connect: - BLEDevice central = BLE.central(); - - // if a central is connected to peripheral: - if (central) { - Serial.print("Connected to central: "); - // print the central's MAC address: - Serial.println(central.address()); - } - - -``` - -### `bleDevice.rssi()` - -Query the RSSI (Received signal strength indication) of the Bluetooth® Low Energy device. - -#### Syntax - -``` -bleDevice.rssi() - -``` - -#### Parameters - -None - -#### Returns -- **RSSI** of the connected Bluetooth® Low Energy device, 127 if the Bluetooth® Low Energy device is not connected. - -#### Example - -```arduino - - if (bleDevice.connected()) { - Serial.print("RSSI = "); - Serial.println(bleDevice.rssi()); - } - - -``` - -### `bleDevice.characteristic()` - -Get a BLECharacteristic representing a Bluetooth® Low Energy characteristic the device provides. - -#### Syntax - -``` -bleDevice.characteristic(index) -bleDevice.characteristic(uuid) -bleDevice.characteristic(uuid, index) - -``` - -#### Parameters - -- **index**: index of characteristic -- **uuid**: uuid (as a **String**) - -#### Returns -- **BLECharacteristic** for provided parameters - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - Serial.println("BLE Central scan"); - - // start scanning for peripheral - BLE.scan(); - - - BLEDevice peripheral = BLE.available(); - - if (peripheral) { - // ... - - Serial.println("Connecting ..."); - - if (peripheral.connect()) { - Serial.println("Connected"); - } else { - Serial.println("Failed to connect!"); - return; - } - - // discover peripheral attributes - Serial.println("Discovering attributes ..."); - if (peripheral.discoverAttributes()) { - Serial.println("Attributes discovered"); - } else { - Serial.println("Attribute discovery failed!"); - peripheral.disconnect(); - return; - } - - BLECharacteristic batteryLevelCharacteristic = peripheral.characteristic("2a19"); - - if (batteryLevelCharacteristic) { - // use the characteristic - } else { - Serial.println("Peripheral does NOT have battery level characteristic"); - } - - // ... - } - - -``` - -### `bleDevice.discoverAttributes()` - -Discover all of the attributes of Bluetooth® Low Energy device. - -#### Syntax - -``` -bleDevice.discoverAttributes() - -``` - -#### Parameters - -None - -#### Returns -- **true**, if successful, -- **false** on failure. - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - Serial.println("BLE Central scan"); - - // start scanning for peripheral - BLE.scan(); - - - BLEDevice peripheral = BLE.available(); - - if (peripheral) { - // ... - - Serial.println("Connecting ..."); - - if (peripheral.connect()) { - Serial.println("Connected"); - } else { - Serial.println("Failed to connect!"); - return; - } - - // discover peripheral attributes - Serial.println("Discovering attributes ..."); - if (peripheral.discoverAttributes()) { - Serial.println("Attributes discovered"); - } else { - Serial.println("Attribute discovery failed!"); - peripheral.disconnect(); - return; - } - - // ... - } - - -``` - -### `bleDevice.discoverService()` - -Discover the attributes of a particular service on the Bluetooth® Low Energy device. - -#### Syntax - -``` -bleDevice.discoverService(serviceUuid) - -``` - -#### Parameters - -- **serviceUuid:** service UUID to discover (as a **String**) - -#### Returns -- **true**, if successful, -- **false** on failure. - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - Serial.println("BLE Central scan"); - - // start scanning for peripheral - BLE.scan(); - - - BLEDevice peripheral = BLE.available(); - - if (peripheral) { - // ... - - Serial.println("Connecting ..."); - - if (peripheral.connect()) { - Serial.println("Connected"); - } else { - Serial.println("Failed to connect!"); - return; - } - - // discover service attributes - Serial.println("Discovering service attributes ..."); - if (peripheral.serviceUuid("fffe")) { - Serial.println("Service attributes discovered"); - } else { - Serial.println("Service attribute discovery failed!"); - peripheral.disconnect(); - return; - } - - // ... - } - - -``` - -### `bleDevice.deviceName()` - -Query the device name (BLE characteristic UUID 0x2a00) of a Bluetooth® Low Energy device. - -#### Syntax - -``` -bleDevice.deviceName() - -``` - -#### Parameters - -None - -#### Returns -- **Device name** (as a String). - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - Serial.println("BLE Central scan"); - - // start scanning for peripheral - BLE.scan(); - - - BLEDevice peripheral = BLE.available(); - - if (peripheral) { - // ... - - Serial.println("Connecting ..."); - - if (peripheral.connect()) { - Serial.println("Connected"); - } else { - Serial.println("Failed to connect!"); - return; - } - - // discover peripheral attributes - Serial.println("Discovering attributes ..."); - if (peripheral.discoverAttributes()) { - Serial.println("Attributes discovered"); - } else { - Serial.println("Attribute discovery failed!"); - peripheral.disconnect(); - return; - } - - // read and print device name of peripheral - Serial.println(); - Serial.print("Device name: "); - Serial.println(peripheral.deviceName()); - Serial.print("Appearance: 0x"); - Serial.println(peripheral.appearance(), HEX); - Serial.println(); - - // ... - } - - -``` - -### `bleDevice.appearance()` - -Query the appearance (BLE characteristic UUID 0x2a01) of a Bluetooth® Low Energy device. - -#### Syntax - -``` -bleDevice.appearance() - -``` - -#### Parameters - -None - -#### Returns -- **Appearance value** (as a number). - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - Serial.println("BLE Central scan"); - - // start scanning for peripheral - BLE.scan(); - - - BLEDevice peripheral = BLE.available(); - - if (peripheral) { - // ... - - Serial.println("Connecting ..."); - - if (peripheral.connect()) { - Serial.println("Connected"); - } else { - Serial.println("Failed to connect!"); - return; - } - - // discover peripheral attributes - Serial.println("Discovering attributes ..."); - if (peripheral.discoverAttributes()) { - Serial.println("Attributes discovered"); - } else { - Serial.println("Attribute discovery failed!"); - peripheral.disconnect(); - return; - } - - // read and print device name of peripheral - Serial.println(); - Serial.print("Device name: "); - Serial.println(peripheral.deviceName()); - Serial.print("Appearance: 0x"); - Serial.println(peripheral.appearance(), HEX); - Serial.println(); - - // ... - } - - -``` - -### `bleDevice.serviceCount()` - -Query the number of services discovered for the Bluetooth® Low Energy device. - -#### Syntax - -``` -bleDevice.serviceCount() - -``` - -#### Parameters - -None - -#### Returns -- The number of **services discovered** for the Bluetooth® Low Energy device. - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - Serial.println("BLE Central scan"); - - // start scanning for peripheral - BLE.scan(); - - - BLEDevice peripheral = BLE.available(); - - if (peripheral) { - // ... - - Serial.println("Connecting ..."); - - if (peripheral.connect()) { - Serial.println("Connected"); - } else { - Serial.println("Failed to connect!"); - return; - } - - // discover peripheral attributes - Serial.println("Discovering attributes ..."); - if (peripheral.discoverAttributes()) { - Serial.println("Attributes discovered"); - } else { - Serial.println("Attribute discovery failed!"); - peripheral.disconnect(); - return; - } - - int serviceCount = peripheral.serviceCount(); - - Serial.print(serviceCount); - Serial.println(" services discovered"); - - // ... - } - - -``` - -### `bleDevice.hasService()` - -Query if the Bluetooth® Low Energy device has a particular service. - -#### Syntax - -``` -bleDevice.hasService(uuid) -bleDevice.hasService(uuid, index) - -``` - -#### Parameters - -- **uuid**: uuid to check (as a **String**) -- **index**: optional, index of service to check if the device provides more than on. Defaults to 0, if not provided. - -#### Returns -- **true**, if the device provides the service, -- **false** otherwise. - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - Serial.println("BLE Central scan"); - - // start scanning for peripheral - BLE.scan(); - - - BLEDevice peripheral = BLE.available(); - - if (peripheral) { - // ... - - Serial.println("Connecting ..."); - - if (peripheral.connect()) { - Serial.println("Connected"); - } else { - Serial.println("Failed to connect!"); - return; - } - - // discover peripheral attributes - Serial.println("Discovering attributes ..."); - if (peripheral.discoverAttributes()) { - Serial.println("Attributes discovered"); - } else { - Serial.println("Attribute discovery failed!"); - peripheral.disconnect(); - return; - } - - if (peripheral.hasService("180f")) { - Serial.println("Peripheral has battery service"); - } - - // ... - } - - -``` - -### `bleDevice.service()` - -Get a BLEService representing a Bluetooth® Low Energy service the device provides. - -#### Syntax - -``` -bleDevice.service(index) -bleDevice.service(uuid) -bleDevice.service(uuid, index) - -``` - -#### Parameters - -- **index**: index of service -- **uuid**: uuid (as a **String**) - -#### Returns -- **BLEService** for provided parameters - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - Serial.println("BLE Central scan"); - - // start scanning for peripheral - BLE.scan(); - - - BLEDevice peripheral = BLE.available(); - - if (peripheral) { - // ... - - Serial.println("Connecting ..."); - - if (peripheral.connect()) { - Serial.println("Connected"); - } else { - Serial.println("Failed to connect!"); - return; - } - - // discover peripheral attributes - Serial.println("Discovering attributes ..."); - if (peripheral.discoverAttributes()) { - Serial.println("Attributes discovered"); - } else { - Serial.println("Attribute discovery failed!"); - peripheral.disconnect(); - return; - } - - BLEService batteryService = peripheral.service("180f"); - - if (batteryService) { - // use the service - } else { - Serial.println("Peripheral does NOT have battery service"); - } - - // ... - } - - -``` - -### `bleDevice.characteristicCount()` - -Query the number of characteristics discovered for the Bluetooth® Low Energy device. - -#### Syntax - -``` -bleDevice.characteristicCount() - -``` - -#### Parameters - -None - -#### Returns -- The **number of characteristics** discovered for the Bluetooth® Low Energy device. - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - Serial.println("BLE Central scan"); - - // start scanning for peripheral - BLE.scan(); - - - BLEDevice peripheral = BLE.available(); - - if (peripheral) { - // ... - - Serial.println("Connecting ..."); - - if (peripheral.connect()) { - Serial.println("Connected"); - } else { - Serial.println("Failed to connect!"); - return; - } - - // discover peripheral attributes - Serial.println("Discovering attributes ..."); - if (peripheral.discoverAttributes()) { - Serial.println("Attributes discovered"); - } else { - Serial.println("Attribute discovery failed!"); - peripheral.disconnect(); - return; - } - - int characteristicCount = peripheral.characteristicCount(); - - Serial.print(characteristicCount); - Serial.println(" characteristics discovered"); - - // ... - } - - -``` - -### `bleDevice.hasCharacteristic()` - -Query if the Bluetooth® Low Energy device has a particular characteristic. - -#### Syntax - -``` -bleDevice.hasCharacteristic(uuid) -bleDevice.hasCharacteristic(uuid, index) - -``` - -#### Parameters - -- **uuid**: uuid to check (as a **String**) -- **index**: optional, index of characteristic to check if the device provides more than on. Defaults to 0, if not provided. - -#### Returns -- **true**, if the device provides the characteristic, -- **false** otherwise. - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - Serial.println("BLE Central scan"); - - // start scanning for peripheral - BLE.scan(); - - - BLEDevice peripheral = BLE.available(); - - if (peripheral) { - // ... - - Serial.println("Connecting ..."); - - if (peripheral.connect()) { - Serial.println("Connected"); - } else { - Serial.println("Failed to connect!"); - return; - } - - // discover peripheral attributes - Serial.println("Discovering attributes ..."); - if (peripheral.discoverAttributes()) { - Serial.println("Attributes discovered"); - } else { - Serial.println("Attribute discovery failed!"); - peripheral.disconnect(); - return; - } - - if (peripheral.hasCharacteristic("2a19")) { - Serial.println("Peripheral has battery level characteristic"); - } - - // ... - } - - -``` - -### `bleDevice.hasLocalName()` - -Query if a discovered Bluetooth® Low Energy device is advertising a local name. - -#### Syntax - -``` -bleDevice.hasLocalName() - -``` - -#### Parameters - -Nothing - -#### Returns -- **true**, if the device is advertising a local name, -- **false** otherwise. - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - Serial.println("BLE Central scan"); - - // start scanning for peripheral - BLE.scan(); - - - BLEDevice peripheral = BLE.available(); - - if (peripheral) { - // ... - - // print the local name, if present - if (peripheral.hasLocalName()) { - Serial.print("Local Name: "); - Serial.println(peripheral.localName()); - } - - // ... - } - - -``` - -### `bleDevice.hasAdvertisedServiceUuid()` - -Query if a discovered Bluetooth® Low Energy device is advertising a service UUID. - -#### Syntax - -``` -bleDevice.hasAdvertisedServiceUuid() -bleDevice.hasAdvertisedServiceUuid(index) - -``` - -#### Parameters - -- **index**: optional, defaults to 0, the index of the service UUID, if the device is advertising more than one. - -#### Returns -- **true**, if the device is advertising a service UUID, -- **false** otherwise. - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - Serial.println("BLE Central scan"); - - // start scanning for peripheral - BLE.scan(); - - - BLEDevice peripheral = BLE.available(); - - if (peripheral) { - // ... - - // print the advertised service UUIDs, if present - if (peripheral.hasAdvertisedServiceUuid()) { - Serial.print("Service UUIDs: "); - for (int i = 0; i < peripheral.advertisedServiceUuidCount(); i++) { - Serial.print(peripheral.advertisedServiceUuid(i)); - Serial.print(" "); - } - Serial.println(); - } - - // ... - } - - -``` - -### `bleDevice.advertisedServiceUuidCount()` - -Query the number of advertised services a discovered Bluetooth® Low Energy device is advertising. - -#### Syntax - -``` -bleDevice.advertisedServiceUuidCount() - -``` - -#### Parameters - -None - -#### Returns -- The **number of advertised services** a discovered Bluetooth® Low Energy device is advertising. - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - Serial.println("BLE Central scan"); - - // start scanning for peripheral - BLE.scan(); - - - BLEDevice peripheral = BLE.available(); - - if (peripheral) { - // ... - - // print the advertised service UUIDs, if present - if (peripheral.hasAdvertisedServiceUuid()) { - Serial.print("Service UUIDs: "); - for (int i = 0; i < peripheral.advertisedServiceUuidCount(); i++) { - Serial.print(peripheral.advertisedServiceUuid(i)); - Serial.print(" "); - } - Serial.println(); - } - - // ... - } - - -``` - -### `bleDevice.localName()` - -Query the local name a discovered Bluetooth® Low Energy device is advertising with. - -#### Syntax - -``` -bleDevice.localName() - -``` - -#### Parameters - -Nothing - -#### Returns -- **Advertised local name** (as a String). - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - Serial.println("BLE Central scan"); - - // start scanning for peripheral - BLE.scan(); - - - BLEDevice peripheral = BLE.available(); - - if (peripheral) { - // ... - - // print the local name, if present - if (peripheral.hasLocalName()) { - Serial.print("Local Name: "); - Serial.println(peripheral.localName()); - } - - // ... - } - - -``` - -### `bleDevice.advertisedServiceUuid()` - -Query an advertised service UUID discovered Bluetooth® Low Energy device is advertising. - -#### Syntax - -``` -bleDevice.advertisedServiceUuid() -bleDevice.advertisedServiceUuid(index) - -``` - -#### Parameters - -- **index**: optional, defaults to 0, the index of the **service UUID**, if the device is advertising more than one. - -#### Returns -- Advertised service **UUID** (as a String). - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - Serial.println("BLE Central scan"); - - // start scanning for peripheral - BLE.scan(); - - - BLEDevice peripheral = BLE.available(); - - if (peripheral) { - // ... - - // print the advertised service UUIDs, if present - if (peripheral.hasAdvertisedServiceUuid()) { - Serial.print("Service UUIDs: "); - for (int i = 0; i < peripheral.advertisedServiceUuidCount(); i++) { - Serial.print(peripheral.advertisedServiceUuid(i)); - Serial.print(" "); - } - Serial.println(); - } - - // ... - } - - -``` - -### `bleDevice.connect()` - -Connect to a Bluetooth® Low Energy device. - -#### Syntax - -``` -bleDevice.connect() - -``` - -#### Parameters - -None - -#### Returns -- **true**, if the connection was successful, -- **false** otherwise. - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - Serial.println("BLE Central scan"); - - // start scanning for peripheral - BLE.scan(); - - - BLEDevice peripheral = BLE.available(); - - if (peripheral) { - // ... - - Serial.println("Connecting ..."); - - if (peripheral.connect()) { - Serial.println("Connected"); - } else { - Serial.println("Failed to connect!"); - return; - } - - // ... - } - - -``` - -## BLEService Class - -Used to enable the services board provides or interact with services a remote board provides. - -### `BLEService()` - -Create a new Bluetooth® Low Energy service. - -#### Syntax - -``` -BLEService(uuid) - -``` - -#### Parameters - -- **uuid**: 16-bit or 128-bit UUID in **String** format - -#### Returns -- New **BLEService** with the specified **UUID** - -#### Example - -```arduino - -BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // Bluetooth® Low Energy LED Service - - -``` - -### `bleService.uuid()` - -Query the UUID of the specified BLEService. - -#### Syntax - -``` -bleService.uuid() - -``` - -#### Parameters - -None - -#### Returns -- UUID of the Bluetooth® Low Energy service as a **String**. - -#### Example - -```arduino - -BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // Bluetooth® Low Energy LED Service - - -Serial.print("LED service UUID = "); -Serial.println(ledService.uuid()); - - - -``` - -### `bleService.addCharacteristic()` - -Add a BLECharacteristic to the Bluetooth® Low Energy service. - -#### Syntax - -``` -bleService.addCharacteristic(bleCharacteristic) - -``` - -#### Parameters - -None - -#### Returns -Nothing - -#### Example - -```arduino - -BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // Bluetooth® Low Energy LED Service - -// Bluetooth® Low Energy LED Switch Characteristic - custom 128-bit UUID, readable and writable by central -BLECharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite, 1); - - - - -// add the characteristic to the service -ledService.addCharacteristic(switchCharacteristic); - - - -``` - -### `bleService.characteristicCount()` - -Query the number of characteristics discovered for the Bluetooth® Low Energy service. - -#### Syntax - -``` -bleService.characteristicCount() - -``` - -#### Parameters - -None - -#### Returns -- The **number of characteristics** discovered for the Bluetooth® Low Energy service. - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - Serial.println("BLE Central scan"); - - // start scanning for peripheral - BLE.scan(); - - - BLEDevice peripheral = BLE.available(); - - if (peripheral) { - // ... - - Serial.println("Connecting ..."); - - if (peripheral.connect()) { - Serial.println("Connected"); - } else { - Serial.println("Failed to connect!"); - return; - } - - // discover peripheral attributes - Serial.println("Discovering attributes ..."); - if (peripheral.discoverAttributes()) { - Serial.println("Attributes discovered"); - } else { - Serial.println("Attribute discovery failed!"); - peripheral.disconnect(); - return; - } - - BLEService batteryService = peripheral.service("180f"); - - if (batteryService) { - // use the service - int characteristicCount = batteryService.characteristicCount(); - - Serial.print(characteristicCount); - Serial.println(" characteristics discovered in battery service"); - } else { - Serial.println("Peripheral does NOT have battery service"); - } - - // ... - } - - -``` - -### `bleService.hasCharacteristic()` - -Query if the Bluetooth® Low Energy service has a particular characteristic. - -#### Syntax - -``` -bleService.hasCharacteristic(uuid) -bleService.hasCharacteristic(uuid, index) - -``` - -#### Parameters - -- **uuid**: uuid to check (as a **String**) -- **index**: optional, index of characteristic to check if the device provides more than on. Defaults to 0, if not provided. - -#### Returns -- **true**, if the service provides the characteristic, -- **false** otherwise. - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - Serial.println("BLE Central scan"); - - // start scanning for peripheral - BLE.scan(); - - BLEDevice peripheral = BLE.available(); - - if (peripheral) { - // ... - - Serial.println("Connecting ..."); - - if (peripheral.connect()) { - Serial.println("Connected"); - } else { - Serial.println("Failed to connect!"); - return; - } - - // discover peripheral attributes - Serial.println("Discovering attributes ..."); - if (peripheral.discoverAttributes()) { - Serial.println("Attributes discovered"); - } else { - Serial.println("Attribute discovery failed!"); - peripheral.disconnect(); - return; - } - - BLEService batteryService = peripheral.service("180f"); - - if (batteryService) { - // use the service - if (batteryService.hasCharacteristic("2a19")) { - Serial.println("Battery service has battery level characteristic"); - } - } else { - Serial.println("Peripheral does NOT have battery service"); - } - - // ... - } - - -``` - -### `bleService.characteristic()` - -Get a BLECharacteristic representing a Bluetooth® Low Energy characteristic the service provides. - -#### Syntax - -``` -bleService.characteristic(index) -bleService.characteristic(uuid) -bleService.characteristic(uuid, index) - -``` - -#### Parameters - -- **index**: index of characteristic -- **uuid**: uuid (as a **String**) - -#### Returns -- **BLECharacteristic** for provided parameters - -#### Example - -```arduino - - // begin initialization - if (!BLE.begin()) { - Serial.println("starting Bluetooth® Low Energy module failed!"); - - while (1); - } - - Serial.println("BLE Central scan"); - - // start scanning for peripheral - BLE.scan(); - - - BLEDevice peripheral = BLE.available(); - - if (peripheral) { - // ... - - Serial.println("Connecting ..."); - - if (peripheral.connect()) { - Serial.println("Connected"); - } else { - Serial.println("Failed to connect!"); - return; - } - - // discover peripheral attributes - Serial.println("Discovering attributes ..."); - if (peripheral.discoverAttributes()) { - Serial.println("Attributes discovered"); - } else { - Serial.println("Attribute discovery failed!"); - peripheral.disconnect(); - return; - } - - BLEService batteryService = peripheral.service("180f"); - - if (batteryService) { - // use the service - BLECharacteristic batteryLevelCharacteristic = peripheral.characteristic("2a19"); - - if (batteryLevelCharacteristic) { - // use the characteristic - } else { - Serial.println("Peripheral does NOT have battery level characteristic"); - } - } else { - Serial.println("Peripheral does NOT have battery service"); - } - - // ... - } - - -``` - -## BLECharacteristic Class - -Used to enable the characteristics board offers in a service or interact with characteristics a remote board provides. - -### `BLECharacteristic()` - -Create a new Bluetooth® Low Energy characteristic. - -#### Syntax - -``` -BLECharacteristic(uuid, properties, valueSize) -BLECharacteristic(uuid, properties, valueSize, fixedLength) -BLECharacteristic(uuid, properties, stringValue) - -BLEBoolCharacteristic(uuid, properties) -BLEBooleanCharacteristic(uuid, properties) -BLECharCharacteristic(uuid, properties) -BLEUnsignedCharCharacteristic(uuid, properties) -BLEByteCharacteristic(uuid, properties) -BLEShortCharacteristic(uuid, properties) -BLEUnsignedShortCharacteristic(uuid, properties) -BLEWordCharacteristic(uuid, properties) -BLEIntCharacteristic(uuid, properties) -BLEUnsignedIntCharacteristic(uuid, properties) -BLELongCharacteristic(uuid, properties) -BLEUnsignedLongCharacteristic(uuid, properties) -BLEFloatCharacteristic(uuid, properties) -BLEDoubleCharacteristic(uuid, properties) -``` - -#### Parameters - -- **uuid**: 16-bit or 128-bit UUID in **String** format -- **properties**: mask of the properties (BLEBroadcast, BLERead, BLEWriteWithoutResponse, BLEWrite, BLENotify, BLEIndicate) -- **valueSize**: (maximum) size of characteristic value -- **fixedLength**: if true, size of characteristic value is fixed -- **stringValue**: value as a string - -#### Returns -- New **BLECharacteristic** with the specified **UUID** and value - -#### Example - -```arduino - -// Bluetooth® Low Energy Battery Level Characteristic -BLEUnsignedCharCharacteristic batteryLevelChar("2A19", // standard 16-bit characteristic UUID - BLERead | BLENotify); // remote clients will be able to get notifications if this characteristic changes - - - -``` - -### `bleCharacteristic.uuid()` - -Query the UUID of the specified BLECharacteristic. - -#### Syntax - -``` -bleCharacteristic.uuid() - -``` - -#### Parameters - -None - -#### Returns -- **UUID** of the Bluetooth® Low Energy service as a **String**. - -#### Example - -```arduino - -// Bluetooth® Low Energy LED Switch Characteristic - custom 128-bit UUID, read and writable by central -BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite); - - -Serial.print("Switch characteristic UUID = "); -Serial.println(switchCharacteristic.uuid()); - - - -``` - -### `bleCharacteristic.properties()` - -Query the property mask of the specified BLECharacteristic. - -#### Syntax - -``` -bleCharacteristic.properties() - -``` - -#### Parameters - -None - -#### Returns -- **Properties of the characteristic masked** (BLEBroadcast, BLERead, BLEWriteWithoutResponse, BLEWrite, BLENotify, BLEIndicate) - -#### Example - -```arduino - -// Bluetooth® Low Energy LED Switch Characteristic - custom 128-bit UUID, read and writable by central -BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite); - - -byte properties = switchCharacteristic.properties(); - -if (properties & BLERead) { - // characteristic is readable ... -} - -if (properties & (BLEWrite | BLEWriteWithoutResponse)) { - // characteristic is writable ... -} - - -``` - -### `bleCharacteristic.valueSize()` - -Query the maximum value size of the specified BLECharacteristic. - -#### Syntax - -``` -bleCharacteristic.valueSize() - -``` - -#### Parameters - -None - -#### Returns -- The **maximum value** size of the characteristic (in bytes) - -#### Example - -```arduino - -// Bluetooth® Low Energy LED Switch Characteristic - custom 128-bit UUID, read and writable by central -BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite); - - - -Serial.print("value size = "); -Serial.println(switchCharacteristic.valueSize()); - - -``` - -### `bleCharacteristic.value()` - -Query the current value of the specified BLECharacteristic. - -#### Syntax - -``` -bleCharacteristic.value() - -``` - -#### Parameters - -None - -#### Returns -- The **current value** of the characteristic, value type depends on the constructor used - -#### Example - -```arduino - -// Bluetooth® Low Energy LED Switch Characteristic - custom 128-bit UUID, read and writable by central -BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite); - - - - if (switchCharacteristic.value()) { // any value other than 0 - Serial.println("LED on"); - digitalWrite(ledPin, HIGH); // will turn the LED on - } else { // a 0 value - Serial.println(F("LED off")); - digitalWrite(ledPin, LOW); // will turn the LED off - } - - - -``` - -### `bleCharacteristic.valueLength()` - -Query the current value size of the specified BLECharacteristic. - -#### Syntax - -``` -bleCharacteristic.valueLength() - -``` - -#### Parameters - -None - -#### Returns -- The **current value** size of the characteristic (in bytes) - -#### Example - -```arduino - -// Bluetooth® Low Energy LED Switch Characteristic - custom 128-bit UUID, read and writable by central -BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite); - - - -Serial.print("value length = "); -Serial.println(switchCharacteristic.valueLength()); - - -``` - -### `bleCharacteristic.readValue()` - -Read the current value of the characteristic. If the characteristic is on a remote device, a read request will be sent. - -#### Syntax - -``` -bleCharacteristic.readValue(buffer, length) -bleCharacteristic.readValue(value) - -``` - -#### Parameters - -- **buffer:** byte array to read value into length: size of buffer argument in bytes -- **value**: variable to read value into (by reference) - -#### Returns -- **Number of bytes** read - -#### Example - -```arduino - - while (peripheral.connected()) { - // while the peripheral is connected - - // check if the value of the simple key characteristic has been updated - if (simpleKeyCharacteristic.valueUpdated()) { - // yes, get the value, characteristic is 1 byte so use byte value - byte value = 0; - - simpleKeyCharacteristic.readValue(value); - - if (value & 0x01) { - // first bit corresponds to the right button - Serial.println("Right button pressed"); - } - - if (value & 0x02) { - // second bit corresponds to the left button - Serial.println("Left button pressed"); - } - } - } - - -``` - -### `bleCharacteristic.writeValue()` - -Write the value of the characteristic. If the characteristic is on a remote device, a write request or command will be sent. - -#### Syntax - -``` -bleCharacteristic.writeValue(buffer, length) -bleCharacteristic.writeValue(value) - -``` - -#### Parameters - -- **buffer**: byte array to write value with -- **length**: number of bytes of the buffer argument to write -- **value**: value to write - -#### Returns -- 1 on success, -- 0 on failure - -#### Example - -```arduino - - // read the button pin - int buttonState = digitalRead(buttonPin); - - if (oldButtonState != buttonState) { - // button changed - oldButtonState = buttonState; - - if (buttonState) { - Serial.println("button pressed"); - - // button is pressed, write 0x01 to turn the LED on - ledCharacteristic.writeValue((byte)0x01); - } else { - Serial.println("button released"); - - // button is released, write 0x00 to turn the LED off - ledCharacteristic.writeValue((byte)0x00); - } - } - - -``` - -### `bleCharacteristic.setEventHandler()` - -Set the event handler (callback) function that will be called when the specified event occurs. - -#### Syntax - -``` -bleCharacteristic.setEventHandler(eventType, callback) - -``` - -#### Parameters - -- **eventType**: event type (BLESubscribed, BLEUnsubscribed, BLERead, BLEWritten) -- **callback**: function to call when the event occurs - -#### Returns -Nothing - -#### Example - -```arduino - -// create switch characteristic and allow remote device to read and write -BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite); - - - - - // assign event handlers for characteristic - switchCharacteristic.setEventHandler(BLEWritten, switchCharacteristicWritten); - - - -void switchCharacteristicWritten(BLEDevice central, BLECharacteristic characteristic) { - // central wrote new value to characteristic, update LED - Serial.print("Characteristic event, written: "); - - if (switchCharacteristic.value()) { - Serial.println("LED on"); - digitalWrite(ledPin, HIGH); - } else { - Serial.println("LED off"); - digitalWrite(ledPin, LOW); - } -} - - -``` - -### `bleCharacteristic.broadcast()` - -Broadcast the characteristics value as service data when advertising. - -#### Syntax - -``` -bleCharacteristic.broadcast() - -``` - -#### Parameters - -None - -#### Returns -- 1 on success, -- 0 on failure - -#### Example - -```arduino - -// create button characteristic and allow remote device to get notifications -BLEByteCharacteristic buttonCharacteristic("19B10012-E8F2-537E-4F6C-D104768A1214", BLERead | BLENotify | BLEBroadcast); - - - -buttonCharacteristic.broadcast(); - - - -``` - -### `bleCharacteristic.written()` - -Query if the characteristic value has been written by another Bluetooth® Low Energy device. - -#### Syntax - -``` -bleCharacteristic.written() - -``` - -#### Parameters - -None - -#### Returns -- **true** if the characteristic value has been written by another Bluetooth® Low Energy device, -- **false** otherwise - -#### Example - -```arduino - -// Bluetooth® Low Energy LED Switch Characteristic - custom 128-bit UUID, read and writable by central -BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite); - - - - - // listen for Bluetooth® Low Energy peripherals to connect: - BLEDevice central = BLE.central(); - - // if a central is connected to peripheral: - if (central) { - Serial.print("Connected to central: "); - // print the central's MAC address: - Serial.println(central.address()); - - // while the central is still connected to peripheral: - while (central.connected()) { - // if the remote device wrote to the characteristic, - // use the value to control the LED: - if (switchCharacteristic.written()) { - if (switchCharacteristic.value()) { // any value other than 0 - Serial.println("LED on"); - digitalWrite(ledPin, HIGH); // will turn the LED on - } else { // a 0 value - Serial.println(F("LED off")); - digitalWrite(ledPin, LOW); // will turn the LED off - } - } - } - - // when the central disconnects, print it out: - Serial.print(F("Disconnected from central: ")); - Serial.println(central.address()); - } - - - - -``` - -### `bleCharacteristic.subscribed()` - -Query if the characteristic has been subscribed to by another Bluetooth® Low Energy device. - -#### Syntax - -``` -bleCharacteristic.subscribed() - -``` - -#### Parameters - -None - -#### Returns -- **true** if the characteristic value has been subscribed to by another Bluetooth® Low Energy device, -- **false** otherwise - -#### Example - -```arduino - -// Bluetooth® Low Energy Battery Level Characteristic -BLEUnsignedCharCharacteristic batteryLevelChar("2A19", // standard 16-bit characteristic UUID - BLERead | BLENotify); // remote clients will be able to get notifications if this characteristic changes - - - - - - if (batteryLevelChar.subscribed()) { - // set a new value , that well be pushed to subscribed Bluetooth® Low Energy devices - batteryLevelChar.writeValue(0xab); - } - - -``` - -### `bleCharacteristic.addDescriptor()` - -Add a BLEDescriptor to the characteristic. - -#### Syntax - -``` -bleCharacteristic.addDescriptor(bleDescriptor) - -``` - -#### Parameters - -- **bleDescriptor**: descriptor to add to the characteristic - -#### Returns -Nothing - -#### Example - -```arduino - -// Bluetooth® Low Energy Battery Level Characteristic -BLEUnsignedCharCharacteristic batteryLevelChar("2A19", // standard 16-bit characteristic UUID - BLERead | BLENotify); // remote clients will be able to get notifications if this characteristic changes - -BLEDescriptor batteryLevelDescriptor("2901", "millis"); - - - - - - batteryLevelChar.addDescriptor(batteryLevelDescriptor); - - -``` - -### `bleCharacteristic.descriptorCount()` - -Query the number of Bluetooth® Low Energy descriptors discovered for the characteristic. - -#### Syntax - -``` -bleCharacteristic.descriptorCount() - -``` - -#### Parameters - -None - -#### Returns -- The **number of Bluetooth® Low Energy descriptors** discovered for the characteristic - -#### Example - -```arduino - - // loop the descriptors of the characteristic and explore each - for (int i = 0; i < characteristic.descriptorCount(); i++) { - BLEDescriptor descriptor = characteristic.descriptor(i); - - // ... - } - - -``` - -### `bleCharacteristic.hasDescriptor()` - -Check if a characteristic has a particular descriptor. - -#### Syntax - -``` -bleCharacteristic.hasDescriptor(uuid) -bleCharacteristic.hasDescriptor(uuid, index) - -``` - -#### Parameters - -- **index**: index of descriptor -- **uuid**: uuid (as a **String**) - -#### Returns -- **true**, if the characteristic has a matching descriptor, -- otherwise **false**. - -#### Example - -```arduino - - if (characteristic.hasDescriptor("2901")) { - Serial.println("characteristic has description descriptor"); - } - - -``` - -### `bleCharacteristic.descriptor()` - -Get a BLEDescriptor that represents a characteristics Bluetooth® Low Energy descriptor. - -#### Syntax - -``` -bleCharacteristic.descriptor(index) -bleCharacteristic.descriptor(uuid) -bleCharacteristic.descriptor(uuid, index) - -``` - -#### Parameters - -- **index**: index of descriptor -- **uuid**: uuid (as a **String**) - -#### Returns -- BLEDescriptor that represents a characteristics Bluetooth® Low Energy descriptor - -#### Example - -```arduino - - if (characteristic.hasDescriptor("2901")) { - Serial.println("characteristic has description descriptor"); - } - - -``` - -### `bleCharacteristic.canRead()` - -Query if a Bluetooth® Low Energy characteristic is readable. - -#### Syntax - -``` -bleCharacteristic.canRead() - -``` - -#### Parameters - -None - -#### Returns -- **true**, if characteristic is readable, -- **false** otherwise - -#### Example - -```arduino - - if (characteristic.canRead("2901")) { - Serial.println("characteristic is readable"); - } - - -``` - -read - -Perform a read request for the characteristic. - -#### Syntax - -``` -bleCharacteristic.read() - -``` - -#### Parameters - -None - -#### Returns -- **true**, if successful, -- **false** on failure - -#### Example - -```arduino - - if (characteristic.read()) { - Serial.println("characteristic value read"); - - // ... - } else { - Serial.println("error reading characteristic value"); - } - - -``` - -### `bleCharacteristic.canWrite()` - -Query if a Bluetooth® Low Energy characteristic is writable. - -#### Syntax - -``` -bleCharacteristic.canWrite() - -``` - -#### Parameters - -None - -#### Returns -- **true**, if characteristic is writable, -- **false** otherwise - -#### Example - -```arduino - - if (characteristic.canWrite()) { - Serial.println("characteristic is writable"); - } - - -``` - -### `bleCharacteristic.canSubscribe()` - -Query if a Bluetooth® Low Energy characteristic is subscribable. - -#### Syntax - -``` -bleCharacteristic.canSubscribe() - -``` - -#### Parameters - -None - -#### Returns -- **true**, if characteristic is subscribable, -- **false** otherwise - -#### Example - -```arduino - - if (characteristic.canSubscribe()) { - Serial.println("characteristic is subscribable"); - } - - -``` - -### `bleCharacteristic.subscribe()` - -Subscribe to a Bluetooth® Low Energy characteristics notification or indications. - -#### Syntax - -``` -bleCharacteristic.subscribe() - -``` - -#### Parameters - -None - -#### Returns -- **true**, on success, -- **false** on failure - -#### Example - -```arduino - - // ... - - // retrieve the simple key characteristic - BLECharacteristic simpleKeyCharacteristic = peripheral.characteristic("ffe1"); - - // subscribe to the simple key characteristic - Serial.println("Subscribing to simple key characteristic ..."); - if (!simpleKeyCharacteristic) { - Serial.println("no simple key characteristic found!"); - peripheral.disconnect(); - return; - } else if (!simpleKeyCharacteristic.canSubscribe()) { - Serial.println("simple key characteristic is not subscribable!"); - peripheral.disconnect(); - return; - } else if (!simpleKeyCharacteristic.subscribe()) { - Serial.println("subscription failed!"); - peripheral.disconnect(); - return; - } - - // ... - - -``` - -### `bleCharacteristic.canUnsubscribe()` - -Query if a Bluetooth® Low Energy characteristic is unsubscribable. - -#### Syntax - -``` -bleCharacteristic.canUnsubscribe() - -``` - -#### Parameters - -None - -#### Returns -- **true**, if characteristic is unsubscribable, -- **false** otherwise - -#### Example - -```arduino - - if (characteristic.canUnsubscribe()) { - Serial.println("characteristic is unsubscribable"); - } - - -``` - -### `bleCharacteristic.unsubscribe()` - -Unsubscribe to a Bluetooth® Low Energy characteristics notifications or indications. - -#### Syntax - -``` -bleCharacteristic.unsubscribe() - -``` - -#### Parameters - -None - -#### Returns -- **true**, on success, -- **false** on failure - -#### Example - -```arduino - - // ... - - // retrieve the simple key characteristic - BLECharacteristic simpleKeyCharacteristic = peripheral.characteristic("ffe1"); - - // subscribe to the simple key characteristic - Serial.println("Subscribing to simple key characteristic ..."); - if (!simpleKeyCharacteristic) { - Serial.println("no simple key characteristic found!"); - peripheral.disconnect(); - return; - } else if (!simpleKeyCharacteristic.canSubscribe()) { - Serial.println("simple key characteristic is not subscribable!"); - peripheral.disconnect(); - return; - } else if (!simpleKeyCharacteristic.subscribe()) { - Serial.println("subscription failed!"); - peripheral.disconnect(); - return; - } - - // ... - - simpleKeyCharacteristic.unsubscribe(); - - -``` - -### `bleCharacteristic.valueUpdated()` - -Has the characteristics value been updated via a notification or indication. - -#### Syntax - -``` -bleCharacteristic.valueUpdated() - -``` - -#### Parameters - -None - -#### Returns -- **true**, if the characteristics value been updated via a notification or indication - -#### Example - -```arduino - - while (peripheral.connected()) { - // while the peripheral is connected - - // check if the value of the simple key characteristic has been updated - if (simpleKeyCharacteristic.valueUpdated()) { - // yes, get the value, characteristic is 1 byte so use byte value - byte value = 0; - - simpleKeyCharacteristic.readValue(value); - - if (value & 0x01) { - // first bit corresponds to the right button - Serial.println("Right button pressed"); - } - - if (value & 0x02) { - // second bit corresponds to the left button - Serial.println("Left button pressed"); - } - } - } - - -``` - -## BLEDescriptor Class - -Used to describe a characteristic the board offers - -### `BLEDescriptor()` - -Create a new Bluetooth® Low Energy descriptor. - -#### Syntax - -``` -BLEDescriptor(uuid, value, valueSize) -BLEDescriptor(uuid, stringValue) - -``` - -#### Parameters - -- **uuid**: 16-bit or 128-bit UUID in string format -- **value**: byte array value -- **valueSize**: size of byte array value -- **stringValue**: value as a string - -#### Returns -- New **BLEDescriptor** with the specified **UUID** and value - -#### Example - -```arduino - -BLEDescriptor millisLabelDescriptor("2901", "millis"); - - -``` - -### `bleDescriptor.uuid()` - -Query the UUID of the specified BLEDescriptor. - -#### Syntax - -``` -bleDescriptor.uuid() - -``` - -#### Parameters - -None - -#### Returns -- **UUID** of the Bluetooth® Low Energy descriptor (as a String). - -#### Example - -```arduino - -BLEDescriptor millisLabelDescriptor("2901", "millis"); - - -Serial.print("millis label descriptor UUID = "); -Serial.println(millisLabelDescriptor.uuid()); - - - -``` - -### `bleDescriptor.valueSize()` - -Query the value size of the specified BLEDescriptor. - -#### Syntax - -``` -bleDescriptor.valueSize() - -``` - -#### Parameters - -None - -#### Returns -- **Value size** (in bytes) of the Bluetooth® Low Energy descriptor. - -#### Example - -```arduino - -BLEDescriptor millisLabelDescriptor("2901", "millis"); - - -Serial.print("millis label descriptor value size = "); -Serial.println(millisLabelDescriptor.valueSize()); - - - -``` - -### `bleDescriptor.valueLength()` - -Query the length, in bytes, of the descriptor current value. - -#### Syntax - -``` -bleDescriptor.valueLength() - -``` - -#### Parameters - -None - -#### Returns -- **Length of descriptor** value in bytes. - -#### Example - -```arduino - - // read the descriptor value - descriptor.read(); - - // print out the value of the descriptor - Serial.print(", value 0x"); - printData(descriptor.value(), descriptor.valueLength()); - - // ... - - void printData(const unsigned char data[], int length) { - for (int i = 0; i < length; i++) { - unsigned char b = data[i]; - - if (b < 16) { - Serial.print("0"); - } - - Serial.print(b, HEX); - } - } - - -``` - -### `bleDescriptor.value()` - -Query the value of the specified BLEDescriptor. - -#### Syntax - -``` -bleDescriptor.value() - -``` - -#### Parameters - -None - -#### Returns -- Value byte array of the **BLE descriptor**. - -#### Example - -```arduino - -BLEDescriptor millisLabelDescriptor("2901", "millis"); - - - - int descriptorValueSize = millisLabelDescriptor.valueSize(); - byte descriptorValue[descriptorValueSize]; - - for (int i = 0; i < descriptorValueSize; i++) { - descriptorValue[i] = millisLabelDescriptor.value()[i]; - } - - - -``` - -### `bleDescriptor.readValue()` - -Read the current value of the descriptor. If the descriptor is on a remote device, a read request will be sent. - -#### Syntax - -``` -bleDescriptor.readValue(buffer, length) -bleDescriptor.readValue(value) - -``` - -#### Parameters - -- **buffer**: byte array to read value into -- **length**: size of buffer argument in bytes -- **value**: variable to read value into (by reference) - -#### Returns -- **Number of bytes** read - -#### Example - - -```arduino - - byte value = 0; - - // get the value, descriptor is 1 byte so use byte value - descriptor.readValue(value); - - -``` - -### `bleDescriptor.read()` - -Perform a read request for the descriptor. - -#### Syntax - -``` -bleDescriptor.read() - -``` - -#### Parameters - -None - -#### Returns -- **true**, if successful, -- **false** on failure - -#### Example - -```arduino - - if (descriptor.read()) { - Serial.println("descriptor value read"); - - // ... - } else { - Serial.println("error reading descriptor value"); - } - -``` diff --git a/docs/assets/ble-bulletin-board-model.png b/docs/assets/ble-bulletin-board-model.png deleted file mode 100644 index 409ae9e89385b0c27d8331f7d52fff2a8f71e097..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 41914 zcmc$`WmuJ6*Y6Fulu}Akx_f~%NO!1!(%nc)mz2`o9nzqHbayw>B_J)GO3ORf<#pfk zKF{8tw+C|I<UD7LS-<fgV;Q9IQtA=P6BIZ&xJNS5;;-P~5F+8=;IEM$fD#jnj9oZ5 z6cIBqF$EbhF){@^8xu22V>meJM``iSO0Q>e14f#-o4#UEkWrsLaYH5>dnSzoQ4Est zRzUFgrEwC!FNuvwuVSRs3NIBvVJLx(`r*C7H1aWqLU)^@xWxKGs0H#tG3Uu*@=cHW z((Go<^sMQD$8<fM!u5MdyMr3MH%F!#_Wn+r7S`i|&NBpj40tp(_||0;6NuEgIKsqr zlR#2ZfpmApuYIVuQNuh_ivo@P)U8((1-BU012`0kNiKd*8oYIc*w+<Z1Z=mE{?j;m zHvgw=xS7aVMHH)@Uo3y+Z!k9WB_`0UWj;|KCTQeH4{cCbOr~DW4uxcDB~pJk&3=by z+@vIv47YwpH$Hxz`W%iGJ4ttNlP1$Lh)n{UU_a;>0S+m)lef_hE#!jtO*))Qp6OaJ zBuK^}4|6)vZ2d>C$>mYS>kEUYjIkXrmIGa$kDOLM3}?mj{$dj^0Z*-NmGmZRub60W zPkn0R%|*-X5{c*Q8-ZT8E9E1a-H~*W&~)`B%iSWDCS15*R2nJ770q$VaFtdMgx8mg z<PXT;j_<=&E~cK4_*?2kcdk67MGe{AwX}!Nuz)iD;J(UuZ`0r6&wG|Muz#iUEDuk} zhf)TI-B@BhFF#LCd~om~TEd9Y%^Ak+YAdhVP+tdAYDO#Gk>3wx#UHWAzCmvq{P=y; zBB4eozFw2dUie(Jhy<Q#7T9kbb>Texcok}85PNL|;KV5JQCSPQA$aU)Vmw9ZZEk#1 z9QDOMg3ays<|QerR<QN*a}kQy8^0b#7}-&0F%e`h`C7IiU_~N2d_>{!fwCen={+Ly zW`BEckqpk)TN>kD{5_~Nf|)R+TtsjNEWxKU@J=7h-@;A!xP67Ze9!gvffhuy_0e0@ zhu%`cDE@77tniCIW=QW3F>ta(K1Jf@peKn=VGwE{xr&J>@L=ET5(|pNh!(#1N>hN( z@ZnRYn1aA5rNfhYB<&BE9}&NjaXh$z_wdC`L>Sk9Gy_-dJzM&W2uZ4a;JdgBPAVc^ z>-@58Ev_J1O*`H);UOH8pKf~$l5j85y-`UuB*G(c(MUBacuaDOD2g0}LW$%^v>d{^ zFzG1UwR;Z&GW8Sjak~jt1Jpy84OH}}3}jg+6Acqpp5twBnP9N{T)fXUm@Lavqb(A0 zLgvCu31jY5(TmX2EKMl8H>1D%j0ml#m0*SFt!FL17MnF^38V&nI<&!ir{mEw&5=tZ z!y@*<d-OK@LxXqZ%_v?(UL;Eqq}?sFk;obli}&c{@nlq%R7x06kT#KSd@<WO6nzTh z9Vq-UTsyT4=*z-qL>gs?XkNx(%lK2_y`rK|s`OEkF{jX`5uj-zkLlwxlCr~B7uJz4 zp~@iBrAChyQi!Fa!IqaLk`SGJ$tznY>?-Ukmiy{af%Syir^Na+4f!T<4_OZusTlTz zlZ4g2;+W4-7I8ZX?$q+J(+SQAy3h<-U2-qk-+9-y2#RgOZLfW@OI0!@mn+)^{A47O zv*HW_4U!Fl3_h%Ib}3RfM*Bq9V96H>Z<UTw=aN4W9nW<gtF3%d$v0;_$4V^4opUuF zv(<G<`lIO-*_hf`bDeITX#L50MgOY@?W}s|?5_xNLt{c4LL*K%HtI%JN9MV{nCaX$ z(#KseSTnqfqlhz!gO7{&^jz6y5_>Z3lhr5r3089&bA9t!^Q%ed=dh9d5$E)gG+mC{ zwd;WG()u8`+Dr4F9oquiF;9}8G(RDDqWmO*qnnc;**du|c|CcPqo?wX25J>VV_jpj zN{2NrX@5}3gt{VxH?z28FQ0i-FlXVjK(S##g_>#h%ZlO0+R;!=Zjl<Tn%B;v@^UO{ zEV^G54>AQ6Gm0~ETBKSuz4}|flFjLbh@`X?WCmxp=%?#vFB?*RiuydtkgbvZteeNM z+BWz|a8;A0G$>6bS|+UT#p{`gMJ2uZk;;*W78`G9I6iYW^kkKOQ&%sNochSy!QcBX z+co8a5mg{WEhG(h0aur4kLfk@4il+5z50DMtIF-t%Z|CuWD9LWj~;*XRl|zmyoHUb z;zH&nr<OgBXUW>73%Ct08%BPi{i3*{xq6By5a1HfgmyOL;6&Hp>oJMB^JBSo_$YK0 zk=C8IY+NRPDNTKte)!RFHtIvXL%a!Qe7jNG<ys=UD5w!MRM+Kg=7jQm+^WXT<=~6y zuuZ2<tImZPf!UkdD@JrV^eCy2p4j}D%_k$MI)MpaRHIbC)I^^d9GD;E3-SpD35E$i zZgy(^?7?!be}i!2bh&UceYkl!eI*a!ffOPCK*@nfLR1h1QQ45O?mI#{+Thz7-jlM7 z=~8J;;39}#i#hr6BXd5~#<{e|hca;#(d@d`D!X{PI765XB*eu!8>Az8$9kng!f@qq zohAFEx+Es0UP!o0BuL05s4=NmtVxDygp%b6;F1#JxKlaV6`qYP$OWwKuAr>$L)o?B zD|YAXs@4k!MoJ=e+th6tNC-)ZmoRRF9=8{+KQB4et#e+7Ovf|?Tt#noGj4_*X`dTk zM?n&N%Y8@16FRkn3}s4WaAZ~y<VC8!JC^Gn`>YklM#g5-vlosQ4w?B@o>z{GQtJno zGHSC6&^EDjaAdQJ)%TlC?khje5+03uPG_%f(vTSb`}t4lP^uK_59+8D=H-i~QpOqm zii4ONr)$Y;)&s<SCw*6*oF<&kj;75{zx}V<IQK2kiv6ZawC3wxI%~JpFaK=biLfHG zlAb*rkQ@jzCS0-(UYt<;s94&p_om`tqg%92RB^e9c~}$8vda?3a&N(;qS$;sfkJ2W zr@_EV@QOV3x9FWEbr02xg~4CGdri5&a<81fJ0UrLTiB{UQA;vV*O~oV@?E=leegKz zxTZmMw^>DB(^e1NEW#+FlC7Y;N%o7m)MWm4&bH5!h~$l?ZTFhJw7H)7>6RrcuW|UW zdtHcvB-liaUcF}u7R4e~UHadai#kSjvbO76Oucly#P_6+qDG|rq;h-OBOE86O-yqa zaL01Bhedant=jh3+<gBj=KlEemI8Zr-8qDZocCy@=bZE){UQIXYp}<sE!vxmU)5hV zf;BRyzD)&H=Wv<1KX+f+@*Ynk9wufMO1XV^8u}|KxuV}xZX{|LCpCpP!`bs#wA=3} zBnU5nPt`%NzH)6Wt)#SMalj|xi_TG<UEzGw)wOcMXVVg1?Pnfo9!-1xH(^sG4e9Z^ zyPjrSRR>m0TW>3F;#Z5qo9}yUUTR;lEdHwZSP#EVBfJ;#;Bp_@?0&2BO<>Do@n#gU z5M4)T(2eKj&5hyiY8EYuJVW{?q2im#^J$a9rqkVz(|RKnfu<4uwPGx{aTj0YJMNDZ zjxb7AN^VOPOO1qHgf6(1opv1#geHuy`nAyiu0D$!{hZ<HeAQ%X(ARlrF}jl^B)eG9 z%zHWY%WBi;$J)5F*+E`@@Z#rYp<g~XnOBCVJyBb`^5^n#8DT=s?~t#LU1+RKHkQtO zPp;Vb)I9-HBEOYZw}*p6eGK~x50{*Z4{&qROi9f_?ZtCGLmMlozLAZAG1SHCEqEFZ zj^Bk3{AgwDpikyvWod2C=ORGy&l7y$XIL={1=&B3I9Lc!sJ&1i6SJ{1CgX&1Kv^jS zQOL;1`0b2L_+E)i{`)%kmjJ~Z2Zy(OEG*8>&QND|sEwT|%Tr!nUKUn17B)6!@C38H ztF?o^3$wL7<)2FaQ;)c@y`i1iTL&{6Ycg29`UW<R4gwSuu!jEo=TAQ!%uN2aWNrWN zu)qLWV83B`3T0*aZ{6Tkepo4=n2pt2J7ar$P`@B2|36Ru|H}Th^XGYmH#QD7zzTL| zhBDR;#&+Ok2Yp!Y1lj(5`~UvL|Ex>i&deB$`k%L-{`>abvVWiFXMqj;jv@Y7`JYl? zW<eBwmj6zfAWG>f+X5V%Fr19Ih>{EZZW>}E_T)v2ZdrE0jBsd^ej8RpmJ%afaPXxn zrUZu`o<jCU07aPv(+n#vMb?8-{jmFG1_zjrP@E>{DBcU4wT#FtI_{S@I6EI$-lmV3 z?hg*9a*gnw4LUErHu3TIW#`4jfdBi|8zme<bkmoD6zKi;3j(O~6A}d(!hgS9F(bVP zQ4{z>?mQ(e{0Z&uTWb=+2y84`$4q};qacGX<hxT1MI;_Pa&P0?zKXw%1$skrw(nFM zD69jaB0FiP9{F$U;0Ms5dw2i+f9enu6=YIQIOFM;#q!s~62cI1VTc`VX)6Ni+P=D= zoTxBDIaT6`990_YseSVZi{u6FA3ONWkwr4lWVdAZRN2<Vx#M9);wW(yt{e*8UPP2F z*KVYk@=ms7OzXhv17GGr!hHHOSrVwL?;K9tUv4gaF(X9>qjKTt#tjJ($BQU*#|jSa zpTSZQ|F^>m%Mgq(9=wR%Y{K@@8)<Re8dhqukOA(^8Eu~O+n>|AF`A!MitWP1Nd9zM z{38kSyQ{sL>aU`xevc?aPzT+N6hFDgdo$r|5sld%oe!|IK;SRN<%RqdQWGBkXEqZv z;NrV8yngdOJXzU(j|#=FuhNztCKWYZAtQq)K<qN<jxzTU7d{?2>_8XdU^lss_n-08 zww~BUN#G)L2Y)mYlkUff@P-&2&1~S<Ph19iuVsjUY4!bgS{3pk8$&60`$Wq>49Prn z^QD75=dmIsq*65zkfaCqLcKaK&sQUal5fS<a6h~Y`ZKS>9$4R9gSs$Bd)1`Fo1D=V z>G6bs#m<v(v9nbjAXJ8=)MTjb1;T&q<tY9A>YzpbWmYC5;fIGK%5^K4U-KV^^l)t^ zYV+6Me`QE!FG(BmuWd0xp{I)%R7%LbE2=2q8~ZTteP61$#rssZ50kX=U#1P#q&Y9n zzU14Ya^J7pWOE&H^ZefGqyEJ{s-{7w$&GXC3oi+Y$Ejk&_xGq9A@A)|Y?|x#N;}Y| ziZ!{PoqiSDtD4qH8POG_h1RWMT}`+Aj+4i@!1>2=1qukKb9F8`v?KR(iXyuhSsnH9 zBCK?tzMgGrZwOo?rHHxOtr*!|a9(<$<9X0@RwS1I{k8r1%Ut;YG=)E7pe+!SGWoPy zXn8P+J>_(o2t8E)Vk5-{){Fc!r{ukg5y9oTd7Boi9wPhDw0FmS)dSFm!A+rr$5KSL zzEzg9Y<OReDgW7RV2QmdjxbVPDXaCPK{c|y*uZJfB=aD*UCgs{v?#7p!4Ma;zsgIo zE=MEgoAD>Kev>U3hBErr3UsSFfW(b1a0oOckSg@!<A-+7c3)(tMc2()A4HNjDVF6j zhbPMcq+I>&#WjoO4g2+<Z+@S()DT+NlDjf%yJ_t%wX`%H_cK->G+)g{Ns$m-8=8rq zJMPYmUY>3ll6qa+vZZUGP3d}h5I%FV#E9D$(!TuC^1Ghc<8*YNdiU&`{RnIKX;H;+ zx$~kcZK_x;8a`_)*W4S*ozd)o7fEc?1T@->eIa~*j;#VD1b&v;tnS3%UbRQ2qPV>% zj9TJ3s4~AX%j>*uua=hC5Ozx%_RFiS<~16e_I58eGipY&rRKqIA^x58Yu-j^-t%hD zDvWcg)HL0-TSdop{kzvzZo*6d&F>8d%@y<34MY3j2aFNj+e_7F+XdOXzzj&ge_xDv zJrKH<3>_<eH=`dgi^|d%$tBRavzg&#Ef#=Q^|_?Je@fd~JB8geoLs3VjL=k$xhnQ% z&&CVY0K>vSu;fJw*YaX7qUh6w8;Xy#^65kn$`7Bm%5^Nuy4p4Lbv-YPdE}Ej{2x^~ zPO0~l)NMSuS_xqhRlRvE&mZ+vXJ78+Kj+U!J0zDH$J07`Fv$Z_xV<aKL-bBx)}SQF zokBht@_5M8rQ2m;M7(TjPr%eJe#hDQR@Os82$^FWV0tXR2-YHT33K!LiqlaSUP?&M zL@m1D`FAo_^<Uq?ser!9u<)s_?ExV~j(9rIv<pX-L)^0ZH1KwiedOUvl%e2IV4^tx z%M8H<3_GN+qTizBpac-Jywg6~RWVZ6wJ3}mu-6Ef(hJRQR!MJ>C=!fGRW!_U$r3S> zlU80l`m*$A)2>s0ACdD4ua7)ESs&82%7daB-H-dMdOG1z&qNVU;&pxGkno<>{bD^~ zZ_eV&qiI+6ld|_}`?%T;qm|3A<S7cO7u_tb)?(z}m&!Knhg4EP*mI>4l~vSp6~Fe7 zxDP^`PRG6)H*O?bJSh9tD;6%){QJ^EQ{NA#eDUD-)q%~lwsYEE^VR+@FywiGvv1>c zPTfg%8HWxv-|PnbI`Z}hZY)^-Y%3iEC{drEkk~*<_ME&nLivLM{HVa6td3I-<ft(t zY0tRTo>b`f$LiFxzRrJH6#}jAEqy>?lytqSy|#62$|uDwpnY6xxkc$+*6n#ZDzz+F znkq@`swax2qEZyDn83VPAVmD{ohsafsetG7D4yrBNaF4a&AaZCb%rsT7s=RD;|Qn~ zX|6HZ^Smhov;y%<vrh9?F)CldAt{tJVreG+<tc7V-_y->cWa&nrOUKu&eh~%{`iI> z<8}KB4FOLxwG3%=N74m8e6(a(bg<n@{rB#jxCgIJW>Fej#xMAD;<Y{vCwoX)(NhuM zlHEL_g_^<8Zm?pRkw){{jbvH0c}(8wx~|9hQ%AGxAEuQ2$Rip!FLk2KD9D<38%%r( zW@N`t??vv&jl<p?=krRLgke8C9sEve_L8k(5{@?tdQ(b`TPtJ#fsX=21XL=f=a*CR zNpes01J*;JCiS7FBk9EAIFFwvQoVkIS$571t(xZ=-(!nO;wYPXs##AzU}(;Nk<$}u zL(|r|Rh~O?j21XzX+2e>K2`6ybJ1uN;w(7ANB(ExULl0)lL~phV}+KYvBhw>HXrU9 z-bZ_Q&+h1P?{D!iA%QM6QG_~_9tZV)Remff!L2T4k`&n%`XlLchn2EImpUlzzZmmV z5`e>^EdRg_8`o&UZr{p_gg+nvzHg_3n=(z+`^R3z*P8#>6)+Kpgm6V^3PsM&zqiys z2o#1SEzH%PNqV>J1>h>n;K-7@T*U#XX%;EK^DbL~3K7cbMeCveb_!O<S3piilth<* zM*N4ezG8!WH4ka4{tjOWQv!Mld;25cZrN){Wu(h%Uk7c7_(x11(Uze_I;@*FT=31e zjQ<RL9dtq+dW;iU;wyX~Ta*Gdjsh|^i72#r)lZhEm4hW+EH=6{x;pVT_p<o%HN)8K zc%g57q(DHu#tT4ip9?GP1}*Bl=SD6BdkWTyJ0Y(K&wm{JuuYwnEq;6pj?&OaJ)BGY zLrS-vI#**@(yF8ym2WV0qycShGNgI6sQeJr);_dvX5p~*V}$xlTw>f13qY-**zTN< zBfX0@#^n0k%|9@cM<Nu6dgWOZ4Uj_$gmg?_oqY@m?njYOPngXr`QA8O8eu)bau!ok zf`jnF>IL~kKPip&g?rO-vQ7H9!|$8qU$9XcI(qwSi+<!oog_V8{8$lT&9SjhTjIa4 zgL<Xwb;DU#Wj^_dkDOsz24Ttbs+hU*tEj%%wR@AS+nWua>9mQ2N4GCd-L~G)tWn%Q zbL!lIT>Vf9t<ICK$$B#&4Q4I$aP|2dp*^w>PoavWRxSoYU=KL#sgZg!JTK|L@i@wq z@FA1IdH%lGJY?%5W~%-EzO8;uw4B#Dw>ppal;N3W*?e+;v->(!7fj;?)@Qw2C<!%$ zp*He(P=nqN?&pKiBfxWONph}V#1UdwDMFaA$|VI1#H72IC#E_@%F0*hOf+AsJAeAt z2?KO!v~eiyBn26{LU%iz=vXcm!UW-1v^SF|c|3W)>&b?n66S+Z=)i`Ngw+fCAIhFH z2GyK#UT6LK%`hsbR>}OGjSG+LgTkDHP@(*g{JVPQ;@4ssJg%u8aMO?S3!G(pIAVPy zD&wIbAwcabLlqV`&U|V0B6E#FDE0QB=VDCp!nv3TR~A@C!43!arRc|Y6sqoBY&oPz z2|R2h>25(;;cm6J#^Kxlfxr~J`~3}dpbmRv73*_YcigA@)iWWd^c|vo%4$5IGmMe= z6(2D4Iz$7%hP*}+?-CXiBkdLAtTP|5A+mHO_&BUk(pA9iwiTEi%fJ|JP{kSNn9%=1 z3yf%$LcQBXi~l$>NAZg>xq{@Nv0S~HXsb=HM9ws!xD*YyaX<F6^Y0(5611Jl!0oy4 z0G))0DIw_^&kn|seh@jr4R8&XkqEfW3_k-d*TL<LPzs-;xrSGjOSIeS%2Nh1`U6pI zfhtbc&)llJ)p?69Q<pcg!cz*!)1NS0j{9h>mORd?tg2`8{AC%>H0k{@4kui<^g^bH z#|G9ef9+WWmIsh}&g{3`dIC1t+Xe8}yVmsagi<n;j!w&*Y<tKcgxTb5!8t?VxR;X4 za)$NU#ahhkrpes{r5#G{Iie%{`#8lcIj<R6h(Swf#LnMrt3gfbJ>kSw0mM$FFzRyK z;q=fNtj^18o7@_b5uTE6n=Z#tv#Ofht=}oBn5{6KmNr{=ChWpSSnKS9!^Nx7Gws*E z`n6{T5U+0lU~a_CGP;-a@8+$%lp=sb)yw{ba|Mdo(VJIi2R2_Ck7Zpjc|iB}8c&8% z+lK}82>6$MAGeQuK;!F`pVzc$G6wkBWL4IM>(q%Ug}*bgjQ^QauhlzpDqhpt%%=Im zge{cx@Q{?_P2_DQb%GXK=+X1^f}?vy5tgIX<l&m(-91muCi>-ifT`ZxT>h*;Bynj? z_xPnw$ZMCA<}_z!tM@sWCwO5>=|04m%@ph;-t15BBB~f5D%y_977O)`>v+OZc4|!I z7(-CUo*ncovKT_aceTU-M*NZ90Vm*zt2@}DR;NEkf1QrY2UvZpwH1L|**X~!s>u`! znB(0{ee7!t{Eb~;TRH!h)$nKU71lbzrXU(-FAN9(Fr#bD(tMufc(AzeQt0ON?H-JH ztEMytbi8gH8-8Eze5j?mO(J?I&%2Ht5<LFg(_+2RSyO6&oiO{|{``(?ag&2(Y1@Ne zS4+2oK?ZY`X4PY|jMQG!mm>6Y$r`3=@@KT*EX#e-u^;As+7{)OGRXjWb&yTsi6@6t zn|R1~Pi{LjL%zpp`~^2>w+Qfs(z%R!F`gZ^-rLKL5Jb@d%fSNBQxS93#H;E-wgCXS z#3s&59?opZ>?8c+fNd8JQ<jkeg$^#SdxU;tb~Dfj(4t}FsNr!hy*qh(>3t84b)^-P z#SAc4H=&KC)qFK4$*(P<_#NP85v+Ja&)sZw!gZP#NzN}e>;k)YZ1Y1Zp3El;-E7G( zulu?6**4XJo%yr<%i{iPKw7fjNRbvl+RIhZLCilEpw#<K9RCcc%3z@zlO~IxbtFAv zTha$q)4?O{n<S*SHP?JPCf5NWq?u*qvRn4Ud+D!j9H$)JgVX}1zYlPfkprQ@y4h^G z@i8AFyUAeb8~kBr0DPGZ4jY3>Qw`1sMjBuoFUs8sz4jNqZasF!a^-%Qe9147-p@E5 z%zvJyUhTmlC{)r_ZBjAB#jX<%C_1G6$-OP({&eR3Y8uUjv8rv#QiY$!>b%3^WS1im zq_=5(LYtTfmJYNO5d02*443~Pt%xh51V(L$;6%2l_mQn13VcLLnUdh}(8%P~BB4Fc z+N->-m7ie6_?PJ`GA;sUC9RL^Q%&Kr+J#a2RI}Fc*L?X5GPbgZ`!!3RC->Vv;aBO^ z2T0&)bExsszD!NLR?5%~*)QWaAaC0K^m*F}K_ylywMPg2_1WxLL0+|g!eg!J674W$ zc>H)p^l;elc6@^NpRxmb7_>D1C0m8;lgu2*&`<_CAsEV?Gl0MIa6dOe2PNjUOO#$+ zD%i1;zh(?04u8hbrn|In45tyAROU5I7FW+PgytI!uAU#QZl09?oYI_s+C%iXNSLvt z)*#Wh19jLqLEGfneyt%!0+fG5;7se;<&W$SrKf=<jmQ0wPEEs$&S>l3R5dj}xMV>a zvP-<c0V$#+F>>X&C-E^Ixd62RO>W7r_4AkJ<i;xp(bfhQ41_`1!8Hto=LLF=7#8>P z_<UOlZ5lCs;iePA2E-qxqWT<C9wCyGq2`Pi6bYa!6pg8Ua$azpW<@)`J{hS2{ywi! z?7n5uILy;6y<Tux4QqQJvj?TS1>@yos)^bDqWoD!goy&KOoh#MBb0p@X%SlgBa5}p z|FU{o$K8(y-<`lwUf^f!i$qp(CeBVfF-vfsgt(2`Mj<O{YIbO3GTpAB4N$VMU`4zX zcgH*r^Ja={DJw{!#6uViHpaS_!JDng$^daWr+@&rH~a8y3vgY^k42F5WDFLXl<;s6 zn0nfGHR9LX$RVW^<XpXosDk+@@Z!`9ais4KMKIut)&t%|G77-^(<|WGZww+Ysk|hv zaRHm)Nes=~5SC^awhw2E?l#9fZo;#9^*^HdAExQqJ=`MaSQu>@`rru&TEG2eJtF^( zQh!{6a8(uO;JN8B9*g9lv`Nt(*d(uX0%f%!46&^U$T1!pRV)k~<5ls@-S`x1YV+Yx zp>AuBo1fE?XXvPJxRu3+kTYbES`$Y!ma|03Ql(FNisP6yjJV8KX_b*&lxBUsuL^qv z(Dmw_Rn_$GYdXyuf2cJP5bKAuH30<%H#C>`XWn;loKh-Cu(D0^Ytv7K#hJu;v^nYV zhx96G^b&qwHX0M&%a@Hs-Y-`(`b?!$^dU(L+CJK0@;F>kNRcr*!&G-<hhLKShZ@8@ zPMEWbQ;w<3x2z9HQARY8vs$sdp(S_8dg3Wq^L)^E3wMwi8>SUvn4|pBR{kMt$LF9Z z996gG4uSh&M0zv%Cb$2sPM8=*r>pJL#eacbm>ggRYGxkmU+!1v0Yy8thmLpr0|g|| z577ep(7%)py5<p-_ovYz>Q=nK<jV;Y`*DTyQ^@(d6faSZCiFCz66Lc3ya*<e`A@;> zq95ONDG!Ol9nrz7r`L-$6-wq;=e^5S8M1nDQ9!@`9JI?GRakL?g|N<eXpV!hPMH_` zImvr2`8X~ed@K9X70dac99K^HjOwqaAwdNwS-dt_<6i|7CW1x*--9{+)4t5#vS1kP z2EN6qx-$X_FenWs<%O8PW!SJ+F_#(4LC3oxmDc)(B$w2%#wKA*s3BJ}coC05XAiHW zejFk2E75WP+bo~swh`D;6|j5A6P%%M@m6~xY8102<MzV4LkSGW^W|CSZs=d<&HNb6 zPI>75Yu1$enEmbdR>_v1l<e?ToJq4kf{|ilK*PLSs`_(S2v`UgD)R}tp0kpn`1$~d z0t5gv{pzKRn1R7mM*upy;!xVN>E@eX^Y605hHlsTV)npQ&qCKc#5F$%>d&C*SOhv! z*mbKI^ciTu+@gFMLz|f!jMpwf7$=v7T#tr4(#ubRN!x8Jw|cjHz`vEr<Xt~~zFGu{ zKy=g%P)VJ}WN7cB8iRv)Z-{&8;dH5B8qg@)-0Bvb=4ZF^GtwW9w|IHEug9rc!Vr-% zf}btb3#bVHuxL2(GmQ*Ek6j?PzPxNX>L#@M@QACF*lDIsGMtED7@dTF2Hf!^gsghr zd*F^({?_Pv(tZF_{{T@X4Gy3SUF*3YG}Q<IjdLnjE<ph=-EEt`;d1-4SS?WJ=FoW8 zBHuo;*!h4i_-4uLwkhi1Y{^S#ci}(;kvMj6`hOx@tnzbOcIAzGFiZ4n-H&^R29}z= zHx<h*H5oZ@HhOQ{fv9E?SXLk=Zr${As_!+pdqaNiOpla4NOxHYasr6uZ-LH#=*`@6 zeavMxM&-VdWV##1y(sO(ZOBQ)=TMMlKg^qn`ffOtmrK7LLdb2MO1|s%YuC)MC;ZV7 zKadfDEK)NI<TA{a6}}!k-FIbs0CJqbQSbNGMR2F6!m_w(s(f14YoVm&_a)i(xf_Z> zJpc1lp3(jK9q7E*?aiYyUW=)s$OoP>F^v?mWkpbM#gh*vTa*y|T6ElN|COKNiE`!v z7T`QMRNpK#INMM~i*-7lOId}@CG!>iQg$A=jMbmSQNLhI{fzNl#G{Wo!55KP^m{O4 zNofIwF#q9KlW((6EQ&De(J>KJwH@P%ft-qqgYaLeQ1m;HwW<p+)J&3$cfWr?uLcI- zL4vOrDU-DV)Bzuj3g10V&R@FE513nqycEc;h~%Y!d;%KtP~ag5wu0A(9iV(vlJGwH z_uNPZ2uw+we|IwUL9I=ryJ@=N3J9Xbh4KZ&p6AP%MEVjJ<hyUJbB!9QR0{9oX?@iJ z*M@>k?Xa5c_QMiz?`5LdK3}*z9$@*P>q$ukZn+6E$%_|h!ryZ30UOo;rA>}}WTF_T zt$;|!LoY?~kE?%Vg$(0iM@e%Ftnwqr$W8wOJBPF=b%Nj<JR*_av%Sjkcec~>$W@#p ziF3(rpMOp|w_rt1s+t%Nl=%vqoMIs)&60g>x!QlGY1c<h=-Qq&oz-=nMmB1%_8SV^ zW3uZl-0mlRyw0DC%7aP$1y(nHKsT2|KAs@s!?;daRhx4w0WZcOyyP^A-BjaXu_-2j zw<iRGP!0qwvo6Z?GoUIS9*=)kWzqEbIr%})IMj$ss`=G{e%*Tf0B#Pnq_DV8YtY<+ ztztB83=15s%m<%dz7Qp|KaxQ*GO5_Bo}arpTO#eIs{aB!BSbmEio}XKpa-)ean*;~ zh6W6-<-JTZ$J2I*T5#P=BOe6Y43BB)T<Tn3Imd!8rK3EsHYddm1YFG4;`X;K(RSXn zh;#E3s*H(zcyNC?h52E;EK|B&7;-_e*&yYmoYjk1|L_4Bz2DQfb{mprsvPim2&2y_ zAV2IJ<m68^PI(w0FL{=I^@xLYB1jrA^q2@&=Mzi65BquF4p&B?z|#nn3j97_&2;B| zjW2W{>b-vq<Ut7e_i460OazCr{vmnqr(v;_@d8ASeoLW<p&Epn=w|x8?Lb9;0)3hn zX&aKX4J_7VGNE{&BUxFm+f7rh^%a~EPgb6AS*qcG?nP(H7JTQk1j9N?#eg?M#_>EI z9N$P|Y;bj4^bJ=Yg}-yrX%D)+(I=woV1!}wTYni5;2OP~kkcml42-?|zl<#``Y{sa zxii#I<P2cuSI$rzjJAmyn<biTL(4TqDPkNGZc-3G&}SP~)%A$uA`*=``ZV~~MAC5} zo;fUOl&AY!N%fq0bstTNulhXFGq0!mCY<k&YgfZjJ<AN(3XOrkjJ`0Y*1_iJ8US~D zCFbT}$PP_7iWuxQsiPp$UKvC)EmxR$YJCD?HK;85gHKGq?Gu=$V*Y%U&|_{fF*RY_ z^`$&T1<xrCM~%0F5C<W2zFniemZM1K1uq^#s8~mPPti9^(eM3?UpSbe246|wi~GS@ zAX7l*YHUdBsj@}kLO|LX1Wpu=yzQ9TL24g3#v(`@lQ>(VAGI5t^a<h}M7^#1f4pK+ zByY82T1!c4vb&{j9piP_@dVdT=EHb3gCMG8F?0bA*FktgxH8<;L~*eTcADWXwc5yY zdm#Q_>d#P~mMTd0XtEXd6RW(1Jo!0N9IMr_5?D36b03#v8(&3+#{2?8wtfG17MkLq zzv1yiL)J3UJd~FvIFuSPgqs7{wxOj)(P%L}wTQf^hSE2=V&J5EawD%q<8vSD-k29* zlunXs(S_D%areDwMEnH@2UN<$M2Y?<&M$Bj?K|!z1{l5G5=W&-!wA%ociz2tj)Smu zZ3hL8=}jwxGSc?|_wO1?A9GNACTiJkUeZDicSOCR{Yp~Y#?7K+gzhDyKkM637=0bF zF=-s?*a-0zci&TSlGa`SI;N{!jFPNw+>A!NpidR%`qlM`d%b|&+yeJu2l*=tS%7_o zt`S$xW!vuGE{dwojeLr#u$V`0iYmusUGsfs`lJqXhUda)0y*i@vdM#jrLHTj7x>bq zX-0B2qWFcm;0F^0)uU2le^GpWhhT0o#;&9plO8f0AMV{P93Niw3hO^XR}7zI5M5P& z+*OeBH>~b61_Lr;i`+X9#VG>lh9+2%`;J_jO9@`(o07c)QReRfq`bh+wif*hR<csU z1Lv`@R(+BwTgzoE?Q&_!_H#{3utB`o6V!1*7*a17jX|e-q*{R?ede)w9HrDhDJ%@2 zPqr|5KKWSjb$=32pG_!Un{HA=wu@RF8z>ZLz`*(;I(@;ygAk4fY$hLr|Ad(SM7h&I zKZ+Ad_vQcg!+-|Fk=Yd_{-cZoW~+J$Ml~g;c6O)iDPZ7Gf`Y972BtB5G-$y<cc_c5 z?vy1Wzahv-^kLw`ETBbT)~GD?_xE?JUk|QRojM(l=D~SQ)E|g6K@5PZp3!ch6sc1R zMzsW_Bkv5xvc6t?jn)MKS&J+!-2I|bb~T2&@ZEh{xmOo6jO$~M6*OPFZKP+-J)zC? zAOaw=`cdtkZEv(vvuG@MZa2<u3mmTW0`~HXR$(z;1<??a#UCR|blsU6M{zK)a1_lN zhQAza3wS^DL)OZjiROa|$WngAntvj~u;2Lb084j^DB1$IU`<?j2Y16)CLI<r__zW( ztMU$0+2jGxZ!5GII92~|fE&4RwAwQd^t1l>pHB_DXHK`qQDwdQW9hlvPJhsJ0AXu3 z?D`=QPwA-5P49Cs&n8^;6bS1uPJel+oLKGa?JL|o`3pGj)tHo$GeGjwmlwRqfeD1w zfN*CImpjCi>^Fz2Y+7!(mfjei2)P~`T>*C(HP{AVMg^!pzpoTvqdTS0VdTI|VHn`- za*C@CyZ~nTMy(*RC5MzKgS4irk13a+<5tMruv<>fYB8E-*H1r{Efry8B=q|{JI!HC zrcHFV%0kusWQe<ivq&Bmq$<_1u32z$y4=dA?KnMHS^^PRoOu8fdjP*5Zh})?aUO^S zMF8uj^5sdd04T@&wrM<)oY(vC$Py-4Mo~)npL{?>uLiW-^WY)A9>|r@<>9tjY&>j$ zX^-pinlvZJKop-@bU&~{7dVY{+!~{v@XJqk>n~}(+{W17`O;D?hQ>>!)iHMoC~FR& zt<BmMxYW_z&)mO?AX1+I<-%qbM2l@SEzA6fZ96fIamM?e$6fqm2{u&`>Wq6}WfGC~ z4R|3-BS|A+AGaKWu<;WErfrNU0LPBU6Topc08%7-kq?kavb5dzs+Q;Oq4Vp3?2X13 z$sB#@t{VjIt6|*H3qxv;0?>%fH&g9j{y@k80c4;gv~`0JGEzgjfcxA`nV}d=D@g@@ zfz_|h$MU|lAak?}PuCI{ARp**j^sq?BYZndnjq4@3-U>7!1x3M`EXk#2crXm9@EZ& zXN-ZI-a^i0I+Tnv*2-cQttw6*KMCsK_f@wa;_O&#DAAtz4V2C0W|o#~J9kihvHRJ6 zn7CbFE!u5Cv7+YdfXU`<YjxeM!g>luU4MHV1pWe+y0z%Tj}k~)wp};?V*?RM=0cxo z8isL-o{@`w|Ma<}+;LiaI!jcqFgL!u1q8!IkWxV&19)_RsUnp4-C<ib@LUkdg}Lce z3V{SpBWy?Bdd}yIIF)9a;lV`@fraPEAn`hGTanXB<le$$!$9EWq5nrGA%iqxzw&G4 zoYpb~B91EtquN02nVYlF?R5p`&-<ZZ{`q4mi|B-WiHD10LlZg~s(`>S2RIF5`_VLk zoJ?99i0m*-kcSs)!lLho12(>Eh56}EI_X*p9|tx#?1TBN28)}1EvbI8+Da41Z^??f zNMehyK=j3X3aqU>(^Oi0yRA7`@a98Y4Bv-m-@Wfy!g4oQ_T8RkR&Nlz)_iSK)qJ_H zico&pUu4M}kI@^dBTB|j2)P6+-c$}+XGAHlc6tuA`xKJiaqQf79}luDU&A^jJzS>= z^vi43T>@??XI^w&NSb_W;!{Ka;`;4RGA)gXIra{@BdNUOZfE;xjf1>8R2Y#~bCoiT zBu9-fQ7Rz=sIIdh*@OhbXh>DTdmQJ6KEPa~RZZq-3qoNV1}d5{Nns_i@!*&@b5(UT z2h<%R4|<kjRkJV!f(^e}X+}MU(gmKW%_VlF4rv3wK%{ikIMk5eh=$v7Td4t1{w|1k zJk$r9tV!>pTc{oVGlll}EK$5fC-uTa2vfN<<rfE4Q+qY3E9&~?+0tmVCmeK0OP2bj zN(M)<7O-Q>kYrTX+#-v^LF*;LNz3m9c5c~*EaX~@Kocx-;e>2WH-P><isWzGk!c}2 z3a4(TGk$P}v-nHhzW1G>kZb2W4<#hlEuX!k9#Zs$fu#0xS3CrV1aty6DkS)pc(VwM zk0Hv|o(Q34IYec<%LR<rCj5F6b39(ssA9M<$M9{?Q@>EnK_y_ZJ<jZKw==e^Nf73Z zT7T~e6fKPDQvHs0H3?5Wf}hK%*Ne72#Dqb7;ug?~PJ+DU--+)k4%<-)AKScL>o~!B zd3}JsDomgQ+n2uV&r$dQa%byoAFIKPt@^)=jfLO`vd`@aQ0sx_?pvZ?<c*Zq>~Y0K zKx{}E!M9z&+HmnBI|41n7Mxd~E0-~nLsgCa+1Wp7R$H2Z(EQU4r>aSniWgk7RD*Mp zGZ!Jq?4L1Xdx)L24nuHaWSD`k?fxUa`$>G^z%$7C66shrVTx^CsF#r>*8tA)4=htB zo*2KZaN86R)>3ytHk{&FbsFJW4J}Bh=U36puFiupdd4kO)|Y-RYVA*2D8SJBhC7AT zovZ)CyuS`ZkLU@mpvk()V+2(l*IfM|qj-jPG6sm690vJUFo>_z1ULw456d9ra2N<k z$niFr&+InSoY6!-7M4ikA?(dnp$?ShJVtPMEty~tgaRLLNWL_<8+XM5A3vO_c?Qy+ zP>oAFvE-;miQIl<_8Fq#-wUk5@1c6qpYhZd+THHgnE{sEG<pX~W`G|X-(s|k@_y-i z%C7}p*12m>aHWcdbXZCc6?#f#*%Sw8;S^a8@f-sUxQJp*@jnFNuqnS~`;0#-JIAA& z7ij299pjM5-!0IqjxV;&LJULuA6{8($V`#=k-z5yPx}WAhc<()IY}b<TYuzbYvQ+c zGQFCrwfGd6Oi0qoPn9A|tAVlQD}3r!Z#ZK52}61_!CsL(avM>lP!vw++r8;51ZriZ zobI?SXFhUoU9dbA^Z4rNPjC=sXY9jDrg2o%$cwTASu+RXW?KUd@Tdwede>_bq%wbo zbCj<OB=GmjFGI@9SX7$mrP35NEA;TuqBLFuQB-Eg{aZ_j^3v+CX>k`Vs!?&=o1lHu z+&Go~XVjf91>e&;PFZt^6p3sRJ(5x4U&(jenc8aPa)nL?ufdli>vf;@1+V2);`wX< zSc*x{oJ&5{a;SCyAXx5D6c_zhuA6{>doGzya>4g+S!_5sHMZ0kssHAY79fL|8mD4t zJ@Vf&IvBi-m8r<yQ9d678nej4cYJ)Oj1Rn;Ygil$gQP!SA8C-@5QA2`H<lnfwB>zq z>B5}$s!jAB9!J=ps}>7}U6A8Fb&DPIPIF=npfIH=Qwh=Y{F6^A(wdy`Pa0i=<1c*K zAoH|JL|A*KN-?}1^-i}4K)0eZRYdP}fe_ZMY$8XzJ7sL3ThwC3zIVFC1<-Cvl6M<= zr_2bvD(A0({BN!!$aoaC0-#tFW;daIM;Yz|uf{*D!n)%*%#nTc>jbT)c;NlZza~A| zNXN9T)8v)4cE7)2XYs)>RkyCNn4a`X<GDHlP-d&V-9`Cjg>m7a{$!VpY7a4RBqlKc z?>1+>(tIuWt17X)zSN>j$x;5!NW{TNBz!*?{F`11V^LhdqEiNi+y9X1zeW!PBMCuL zRlK8JGXwdfsO#0Fz@5=yf>&`dOS1k=pM@c>28=vIay8z&kJbB8dlyjw`&3GP0%^TU zbimjs%!#r?Q-%=&Ca~nBmuY<JHP#EeAgQbpmI-0xe0_ezWj;|*ZtMY4iMTv2Pv4Ja zuo(x3kqFfHl>!iOq7=G^h-P`JDFo_WA^%t{Y4w7iQ>F|%L|FZP4h!A<M6(+A7nc*t zLm*VmgRIKk@Mrs_v>ETlNL<%20l{@yo*yogXVuwn&H<=R(am{!na=N8?g8%Y`(3rO zCMmOmSG(gzGq50Z6sb!u7;UE<K)s~7WS5;-gOCj2zWYW>Ok<Dw{qHj_`~rCOB;|^- zNb3TLEFNT=y@G`?#AwbxwbAFN8VI<ZN}Fs0d80DsB_F*S9mqm7hefb!B?;31-|4$w z6@);Rm($Nl)quAkt)+_Cu9tlI$<!1g>ASDZx4+#fmkvON!A!#v2+7kWeW_V=8>j~S zKM(Zq-9XB4y3dI(O=J-%6#O6)Qw7C^?dF=!>d+)_hh-#vys*Fykj&Bt!=Td5wqbvy z<wo7r`Vi?~Skdc+`5-N{guFWo4YLkFHLd)D-2n5{7hR!_CqVY4odfB$ge3wX3SE7D zJTRXl6SJFSnqJ1e=t4QW5IXtx$Jb1!Vctz&=pnED#*8oWV@nWt_b=U<t;i1}e#X^# z0<uSE0kW9L^B;)^hU^gOzB}rw25!b2AWyvZ<%|CnWiQCyR|x3s=nQ(i2g?%$(7%L{ zQeiTLV)i|OqmMBQdte(RUXrvI)omo}A81cQEek(?JG&FUZ;Fye!`z7g`}`%a1;3%W zh21BHV<kxh>I>XzR6#r+Yvs=E^HC|%S)l4$s-=Pi%X?RV#4LflSTU)pyHKk4b8miH zMco)j^KIMxjwz5!ZYWk;n!rd5@B8lc(klU=;aUO504-_GB*p4|>1u!`J-vN>KHUhO zj!WB=nqk=YgtFM3k_KxY>&Z`X+K!XT%ZX3J{y;49e<7B@KB!i1bHDk@+8yM#il+Cy zp0Bn7jA&L3RO0~Fz+n(Bc4+>{@y%hJeK>}-&cO<x^GREO9Y{hBI7j384mWR>pSBUA zNegyeGR?<o8g|NmLMgIl$k^J#_3Keh&N7q~rQ6p>5nc~*$(XqL2dC9di7m$SUf}n1 z6VgqQ*F(yTh#e;sr^=1xG~Z<UwQq<@Qj|O3n1Bw!(uIfPwe0#NgN_X%ONg>I>26V> zwf|&o?4<qx67LoZu6Vbc=)_a+^!?*7t~t8KpqK~NAmCFCV%juKP>`t5xB3HKW%oZa zZ$57iK1e_N$&}{Oc><8mSWU$J=QfUx5k^sH)Zj+1>bAfk1r?AgB86Z<p(LR54oa%Z z%6%+A80(@$_Y%)`RzG>W(H72=2r_tF5~Xb1!G+4k#U#w%NMPENSPpWY+kmFI{PliN zqysz_4#TL60}+eQ9b`5H4x3YH<<k(}lm<YDAM{pp;d)$ppNI3=j!NLo!t!I=8$mEu z5|0OMIY2q8WXlrG_J8WZbS#{fYBGqAo?!dhRI{ovl)3bS6Nw`O#OVefPEHw_WHaVc zD^v=8FK}@fpj_?5i1=Jwt&#ZVEy(Q{q9u84L)zvoR8NBbY_}9+u}3o6-#H}TfBfJa zSr6GHl>!L8yB9+)t$E`7hIp_@I0o7d`zr3jC;XR^zZ-weS#;m)WcCeIIUAS}k4MdV zx$OUl5VxDbF4TCU=jpLKfJ{rOZH(f&K`g1FdLf#n!?E@mEv>xEZXShhM^C`NZKN^p z!-4<*wnzwELKm0{04Ql%o=`5WlPM^nQgL_Q!`q=W)Nnz{0Es!vZL()Zg8Lvwg@#K` zV@zZ}_>`P3>%Lr$v+3sJjOz_~Z`(puEnB}mkj9+ZfEy+5%t293-!miaPyY2L)Gwls zC)D}HCPp$KQRC8=C*`d+CX%a(bRAftAf6voWwRuxMv){FW@z#=l3eV4RdgSd+S8<{ zp(3lI$Y%$Q_NB61#y&;`kcAl-mR5WLzp|6yVcHx->)|6v^BJlgg5})fpY<_W9uN7F zfc#aTYj7zmYQ}gKD+a!LtVX8a72;u)TJRHdxp#)WlTthCd7cZP-Q-ICynAhy3*gLS zamXI?>k}i^_YM?~<uJZ4hi6Ki+L8Q#*7wmAZ@nMp^XDY`W+{2W1$E2%-bgkKX>^}Q z1h1F^%c$ekDBSpV$~MQl)Ko@-Lbkd!-SE{EH>`6{Phe<y(aul@GIiE&vV3sZ7Vzb^ z*~|=+o;x<O>KmIrR4su51y$cx8zerrAIq#E$}v6;D7ae7R@huueAC3pq3y>g=wmRM z!n6In`Z7H{bS`<@#$qhaB6TwuVCA48bGPyY)Y8WC+hy-DBlwKK8<7>va|hEiIW<o; z2LAw__K6;q4N6b*GBP<2`B25M;7YAAsogaOk{}kx@|PTsihK)KqINg{(VBzc?cz#Q z?O2f1us!-#C*`zDP@fb(mLw1y$zbu>la>Ne5a-z70}Gp60UJIju><Raw*zL-jNy=A zJweJU(#R9f&Hz?wPkDKYa$X}GmH&{UFvN}$qX9g+8S|(SHHF2sbc0g+>yT{`jx@g- znFre=6=}Svp&(8Dzw84$%oJi}I0AXOiarSXJb>?0<EYPswQ(*y6}A@RR#erKF7ssc zNN;e?#Ngh-$3pGoAsO8}HGEt|2GT16=bT?yF2>V7@dq^Rta-T#QZC(<Pk)EW;0C^0 zF$p5A@ubj5sv9tRaQ&7zB==cS);n`F+dhA|pEiW6h_{B_p)xwA&j~9m*8jq!Fk~>8 zf($caF*g)n>?=8iI$RvV%n)Ye?d5dKdz_Qjd+5)HWxK|tlX=FBRk(1$v9be;Rj*+A z5a1;El0%z)+d1(*M(`g?v+<e8URkO^=+3%UruIv#NkEWW2EPBHhG)YEL{z26@r{P$ z#w>SK+ezV%bO_OeQoVJ7;*n)mwafk>%IaI{q?h?tZOqpNBhNBDJU>aUad2XtkvoZq z-BK!oByGzM;~kO#ULsO=0p+!drd3>Hdi^5#V{h<ro1C}AjP$?NedmY=dP;xk<s~)m z%e&u!a73RhWNGW}uCxQ^8GXcOH>cx!Ahm|>4HMPEG&gm#EW1HxAVy6-=7PNzN{@?N zef2o=?0Y}^R&RKM3ZJeh8_@<ar19c?w1G7cjJE>#VRo)l`}b2?z@`j7!ix8)xC5(3 zxM><K>$mc_Tn@jpcC+fjArie6Mv_lpwVnE8=<#Lpv91UG`Wh)qwuZ4r-<k4&V_kF| zqs=<t%sl>YGRi<jpP4r3mv|hhq~wc1IK}tNp>H2JsokazFN%mWs0YFS`Eb0}N6vKQ zn%X=qBw0c=es%IRXY0#$5zJ-k6azvBKM_s{Qf!Lw?vAjX*l+)>70jprmmCYc&l<PC zZ>%N?6uY@Yx8jF4YJYDE-OiE#VT|>tOK4eA%Q9!#K$(J#P)7TXbnb$L{X#e|SgLtG z<b0L=?Vz3s5mk)Dl#aXAvyDW<U7&_=H@o)F)4O}xr|-bB8vt)``<}?pl!Zowyuyou zYORW7tKD68W0-+WsPhu3n)fkXp(N^1L{uvFMD_kWkdiOLRGu>gqa`4+A!lLv^d(0z zMReE+FkN*R;m{<Ik!4e0G3L~ljpGy#-|-S`kvgGdeR&~LzQhRVm_c0_s8ke@1U-Ui z4}_T3hQ_!8`+<!6z`{_;rCgFCYi#<t1N;`QH24IU5?a?C&3y|A?6l}eXZ;43)B9bR z;Y1C+;(8QNZDB0jo$LTHCW9(*m-@i9)Cj*$QiSO9wY!4~mIq53>**!}rfop4;Vxx6 zCVXFgWU6VldrHY(fwvY&CHb&E*3gU@X{komL`XQ==eQzVbjj1ZLirlyj{CF(0h>}J znSl&5T<y^ff4mf4V4xH!p3Dr6s@78^F<)B!cVgmpq4*NQScrrxig%(Y;vYF6!BDa? zE{fxCb&hPx!fd~z9tGSVD~_>l66Yu<=bN=p=lO;p(`fg%IWmMU+QXD`##b8F#11|I z-wnm!C>|^v<EN>0;8`GTQjFiMEJX;A;N?j4H)s6~JHTT~lPf5}Z)J^2P_0DRUpryS zsB*+hk&?>%P89zjbWKK)O=#=l@{7c|-(xHPuP+}c9EF6fEF5i$7ZoUi7ZE7oS#cIt zVy!zD5X1&WLtaG~8^Oe-J;G=G5rKp)-g?XJp{qcJqJ#sXGh{JcQkCeAlL2>PFf~Ss zcW8y8Ibc7gR*c-A-&30oc9zq3ev;6`p5spN>*-k39ZM$6Z%@d8GnPrZ#FYxqa-<GF z$Cg^h3Y;QjIqM%Pwo^evC`0aj*O`1}Ou7K~eU%~`hieWa{@$yqoUOqbIV2^yLe8|2 zH#cW&)_h9)f{o4Ri_F(`J!Bbi(%yDPAyXN($6G(Y?mRT>RTlDjqkY6y^1ES-82E{n z2y7V--MWkp4A`EeLoJ;5r@bsPlHiIO;q_R^Ba@Ulwdr#)$e3?$$8U8wC!;S;WO>KX zTvEKz!&l#$TdaIkbG5~;C@ySlP!3O)`_7#^^(_(QVa7gr+`g92==2L#(~U<BzQTLh z9%X*Q=4s?jAOtXJGL&pwVLDO`^ITxrH}7wY;#+Ht>y95E+8G*<$6($VqRO!}RaRLq zxHabvuV6=fYs&vpop<d>UP1&~3u252&bLE~)fQGk3*H_^4s$jC03}x-Hr`%WK_mZe zMhPuoNk_!pjqoH6wg|-5wPw^F5pn!lQmjR>m}R`7yL}wN{C22Vc2SZe!MjH+&Gx9E zI<HPi?(yR7Qqyqkc5XI@bH0)+ETl8h84{^eDUyIehwvRsTpiS2BXM(d>RKw^MJbAD z``s``-EKfgYJ0hg1sxvm9&~>JC5TRMm78#yUU%++4I|1>SpY4xiqr2ElMT<UZoc(l zi%xJt`0--dD;Dr^fnI|sX0b*r1Y>U!vFLRSg!H{Pb5QY8w&Mj?qRmnh*hd-FNVl4Q ztylA-?G1>vc4;YLD5yZm=-G9UUKK~$uBlkPAi|a-l{&p$&}D6G#@@-zK6Ng{mV<pP zMkyyG^<|}gBnBPZZelh|4MuCUFH&27Adk_><=V<<3%;MX(wXBR&PRe#31**IQbHAK z7VdCu;gtkCtCEv?k!L{etmBX)Y)-X$VRoQY8228iTl91ZWRGkns3Ed&4M;Mva!BGk zk3>6)L)H*&zqez42A33+#6uT?9n6M~FnXNbhynh)3C)BVKq4)>DXaV>Rh&baYR#qV zZ!G$qYh>#ZVbY3BjkxXjM=3%_WFIV_h^I+!F5+a7B5&T*UrXX&@@`{hjnWR2LF=GL zNQM2jP$Uco%UD7}gXsD-!r#d|1%x_6{LD=b90}%T9Z~~dVqu+q^|!PCA9a5jRaN_i z52LUJDUl8VDG4P76i^X1k^<6_0+LFIBHbX;DM+b=G}0)kgfxOkmxM@nm()8K&+m!< zd&YUk8RyFx=L=)7VXb|yxbJ(;YhKqiLm#K2pOd0kz36R8)5%d?xl#GSb&qfVo_Hbr za5LW$ujO*Z27{V@wMrNd^N^ay@mtHi;CiV=-1Y3dKpzY9$;+C$YQvw^EgGT7t8G=s z8e(uK`RX7~B0j-IrOQ;9UH%`%4pZ;cN}=C5v+*pP@0fhVKoPMQDDd5`S7h04z+(FW zok9YwD^*Z$LYAyo(t)M*o0sf7N<@~K3{lqCtL=o}>f}A@I@l-<j?u0xZCX^lmK!F; z2$Vm5xzwO=^K*{}&2hgNuH7d5BDAn)zH%l_=W6<ACD0qmRZ@K;n4NAC<-mH}*(x+U z)a*<|PvuHQuMc#L8u{sWzL``Y4%%6aE_F=oa@)T#E>m!QcF?&{sZ7QCwfVd0=G#s> z4fk$07VWzDB$cn0+<5n#a8YE`bIWmSut0NiY}M!XbhGGizmxOxdx}{6h|*m$1OG=4 zZs)^;dK7_bZ_rd3`K(XFWNw=Kf<zm`<EbtN3l*`h$>(D-pHyZC+oBGmWGY|DcO_?T ztc@qu81czb)rgI}^IvV1xOvj}O*eo2Cg-lfw@R5|tB%Iq#Mts(kAktph{U8#mxY1f zinmtwx{E%PR>l&M)i7<}yYaUdfWgkZ;O`Coc6R;!JYED{)fgMQx^^~xIPPGT=JWKv zwg16ZC{CPE1l@r%YQH{DwZcjJk4H6aUKiQ%uMHgGgSn<B2PJaGliR_!w>d|pk2$MW zUNyTtSU6E$Sati&k!i3%(XrcG@OX4{e2Ft}<+}gd@!-|BWU+Pqh@PE>XR)`5aodr5 z%w_BAG|^Ko$LgyN++(&?BRvR)_D)4%s4^h;^+D#!zI4LoJ^KPxxvVue$wm62&X~#; zE)fl1a_<G?Wg4B%9LZ#=m3ZebB;Q&1h+E=;`hyI-3^fV`FC4)(Jm(8WhO_SoTIE_R z7xdF#OS<i6#Z*#_U*u#XX$ggyX#H*~2OoEBZRa~SOUfja|FT|;a0cHaNv6~ONervn zcbo$uiqgS>sxc|-v<3a5>{y;-xqR33)a2Ka$$Z{Hq!Eyc8n;|@txjfSN9~gah}IUN zyVvB=GxA0JM?c;Q@tT~Qm>c!4E_g|ovvU8=6>@f>X#L$F+kv3_SjA*nSvUS5y5c<0 zGdMt@`O%M({2=sMlt{yTe*-EIJ0O<i>7f8t*E|Ok`i5%aYtCtT?E?+GvgArlymaMv zBI+)qoE>_c8YC@>$thS<<u;SKj;mu$`ifZiOut^#HG|xV@=g(dz1zvrZqp1Z5)nJ8 zzB|1Whx=Jul~gAeIi*P+zd<+J849#Lfk1Ny%F?=s_GV{ks1*2jLhd*lOsJDfzlffd zq5n9(vz@QY|I|v&(Yueg#$O2KepYsw`;lJiqi<`zSj;Q14piy<&UM`nMd$N2pPRoD zn?p@71<Ix;dX;uX4$H#`HXAbjoEZqo$LqvY5WQ%bK3B_7C;}$vAmE%-KizjnpRE1* z+N%9CzHZ7DkwNXBHSazFRMgrsx5)2al4#Z4nv&n%{^dV%fw+$1AMh(Br?V(o`406; z!I5VYi@n)u&p*S^<-I>KcW3!kYLX<s4m2Z4K3WUi`JQC_$u*nyNphLb7^NWRItry3 zf*onS2tb|KNF8u)9|1O*0}*YRm#%7r3)`;~yDpp?p`L6q7hM;!Gp#_id`_QDA?~5j z$TJ^AmDEDcvWlpsT5c(nVsOb{vzzN=Wc(O7X=S56d3~i1n`JsA^&Mwp-}6y~0Z~tI z-16!YC${6=O_h23g0!ozwU)3_mbE@z6laviX2m<eC$E0Q{GQixW>(HLIv1B9&Cy^L z!6qK=02JAoa8IZdDMHjXrq;Y?y2*dTPhK+53CNmCm)4yCp3#Ov|BG!?i1=F{|M^QA z6|@Z1I)|xOGQ+?Yd<4WagN;9MgO*>CDdN@;-JDCF+W)_!u~!#F!^HobIeQM*{0X3n zJK!3?R-Z=y&Uq$Y@Np-jE=0C!ynS0wJ<o&-7DhYNm+0(PA8yD4G8bC4*>P(J63Iaz z$f}sn1;0tM$a0m!PHqX7u5G-uOtT#lOCji|Uv+YPAn3ODY;mOGBhY4bP8C526IOpl z_{T>A9~7-&DrIYmsW7RH6mAQ^+UyuQ7TM`{`T^0qyEt5uV{`h36T4eZG6+OXCanRD zgNS(z&|b@_<^O8(1#_ox(R7p-a=n255XQtcKl~X8mXQ;yz|~_Uzp)O<jQ{3g)GjcE zdHzF8K<Fd>mX8wbH6An0y#awY$fvgaSe^F9lb~SG4{*M~VjpPA?eyp}E$MprID|rU za$QfrxPWl+FzI+Jvy<m(>5v&B0gt7%Z|yFKsnq0Wq=@T;s)4F^#ka)t$GYMdZ7~B4 zy=PTH8dd*|3}F<nyWP<$t^r`L-Z_NCbHB~N3h2mpN#=P6hZ0?fY@-kQf`}uy#(|KY zBwaBhG&?QHsEOiXJ4}jvc1X6rZ?}%*p-sZFxnmN3=Zb(0(kTl1mtSC(P~@;w)J(%G z_+=kB+=ih|Ge&q10G#s~2U<iEvFD-B<T1dk2zk7&=tMliNN)s4z4h5=&I{KDoN10T z=uTNQL@?tvZA7;HU{g%%iV{$5J0I><xD31AaM^b`Ge6tbTDSSj`4Vr5`fj1e+KKpE zH>d~v1QH?ng5{0)SpMbSjl8r<O}X>Y?=(JmO-UutGrPQ?F1Q6?MbNkEGK${xtUen= za1CMY+DHmJfj2y*Tf=gkdF1^yrr}>-Y(8j~yZe-qQr^$fFbf^>M_!5VsmpsK=|uUF zG56bM?Qzm$&dCDj?|m$yHS7wf!<D3U{c^BsCBE-(S|1b;?VE2|iK7o>jL!f=N+=&Q z#am5UN8i_2uV*|2tdRZfHFH%hDKF2B7;as*0$cPMO2T@0|8;o|dj#%!v*wO;5j*Xc zCe{BAtet)mMJT=xEP6lTfXw~`q4JSOJf=G5=@Scj-AliyON>r7`hOplrhP(=#c$v1 z8g{6|y^`~OrH^^nZN(hmREw#E3UXM|JmxU(nD8AM!HrV-^M1hp{T&5qlb=w3t`BzY zmLMVeBFaRsx5RV^ege025y50uYFM#lenmzr-PPQek0^Eny?tVDxjYL@Dsb2jRxA=N zS9ZXRA9i1ENEsdUr+Xfd)US_abg8zSr^!}|-IDKBu(jzi=Kib*6aj2kc$zFau-*|0 z4%R;YqIxlSDpOa_tAJ;nI8oTfXhY3C+i?G$$0|rP3)kQB#esPQK}<)Kl4!iz^ZR#_ zhZpoYH0Tw+)E4GOzQa{##?=3Pfj1yRZnsr!*xkkVD)|?n78t&}_2koMF?hGc-70HG zfaaSEm12(@F}F`-#-4;?zq&SG+2QDWCPvJ}iM%PyIP3=76k%66IMZNHN^`~EBfC5F zxv<CHz*W>4*HXnM^S%2BR@}=vCkYxNM_#CmIr*e=#`8SZII~t(4m2ocT*ckDm9vC# z>sRayKC&o(`028kw~Vm-713ynZmnN)DFH!kwm)t=iW0D#Z~`yO^Z8E@A|f(Wfxu?< z?&y=x!wU!#<59TipU0$JlMF&bCQ-S(B6ok>B=*K<@w(dZ@EL3aXD6g+>FlZVsWZcf zT@Tlrx$R}U?y@J4SB9M&&Wh32Cm@nF!o+pqzCY9nR}s4GS(13ZXE6le=TTiGhw9hJ zjc-^S9XvkQM*1aL-n0a5wotuu>pkt;>st%yZyQ#154wrbEE`SI16NP1zGNE_eu1)y z#M!v4I#Mx_%k#zc!`<p-s8Hf4vu<rOoe~S6v^m7{=|^f09!6cluz}KxN}<jeh|QQ7 z5FA?1j?nLILA_X?#_rq-;yY9S%iYDFI#X&O{vB>F2c}EpAnYY%hFG;P?kaJRwav*n zID!-eXE90l>V*$=0%!dLBuAv0Mfu%=PWW7^@oiq#<2wW42P+lz<lOIpUEhWw^*C%& zA=OgfUh3TdUp@=xyWg*x8OLa3Pg`3R$lBqpQ`VRN09N-+J8gd4@(`)lI&>6ApKs7z zP?HssStysXj{6ZeK?&ux!XG=$<6Fg{H@*_hr-OK($c$}iO^J7x7Skz&L2OLpA6b`l zi!xh$WtInl-eIasw(BRQPin6vs><aGT(?!v53PJ8Z42OC?7HMzYx4Pb5N92=)3E0- z!HiR<M^~R>IMyW9eC5hJt>R2&nKueFm7v6V637~ZODj!MSsdJzpr=8=qW8So$%*Zu zo$;B}7;KXa*Ma?RlG>Ybt<%hOx2*&xsJEjOMV{YY;S)^E*ol@;ezTA$_L?I$<2f5D zTD-PqnEZPvtq<`l*l%>TDty+1aoa%@(+R}Cs;u2F;o1~0?@LlERls7;ZjjFx7GYLd zl<dq-il;1yIi$W@GOIE=sCefeNYmSb%`3pfxGxNLFP`=<8MA?tcRm*+;7kM(U<OX} zRhB!A{C;(<O)!wHXUP(0!gZ`eTU|s~sO+HcZ(}J0vW)j~H13IBCex>`Y{21oGl{Dt za=h%&q!k$x+&|Nhz+*LpWl}mckbR-gYDt~>5BJ~XROKgF4>~IX8sq{3Oz_?#$_(wY z%>vIOPA$Gb0Sk8)?stywg*acy{wl_mU9H}EY9O-_wG&}&mC;3}_#eFLL$sGJ7KuYO z0{<GOJhWX24D@U8F^&4(!_-mUc*!P43OzIIe($V}ow4J5x72vkG4J`Ke=w*lBNWey z+mFg>Ab|3e)4pA?jOk~lrwYzKD7T4*BYWJJg>s)7-@;q|2aNxafYC;@-!%JJXw*)P zR>bL<c$s}ICeF(>t|F;->CafHBK92&ZeiK~p9e)_pu$<l2jeb&Pc(JZ+JsOb>HK(I z$L!digP<k4*!miR#PY@@b5(e?mmLf<eW3k$_wiqjE+FPp4#gVzJ$H)0n!JD7ue}WZ zMWHm;InMpGw9pV7*nj;S(L4dJuH>QhmFhe@AyrNz@v9;{S+hgnF0!{)?<!!o#XgF= zuNTl`we(-f9-5W-nfPqX9fP&EL>g;&Bk3_Z-#UO*b=BMn<V~f>;;F!V44zPRFKKra zIA%l!Aj&zv__OROZgXs}*2$~yQrW?>RQWdik9Y3;M#TDrKxI2OX0pu0<y+;tTM8ya z7S%uMfS4D0Q0Dh>6t`!H9U@)WjmnTpms2|J+f{i|qKJ<-G)ywld#@w@<4FSYw_sta zS1Ri*zsI#0wYzbA=*BywxvJs)7PR>-c>pnF<gkAUz4ng(s?FvV$!e>nOg)ka6_P;K z;<(Yl@01ZhY4|ew3_NwoL?8_-zYUR#AsdO1EBNVL=g4uZEEsoL<VNH@FX|jH10OGq zRM^Iay03l35efq42IG0um%RP<65-!!bQNUDD%;!No)g`_C3=7Nn`X?m{_Z!K>SI-h z^?*W&UrfwJ)JAJ}u>SlWkNElnam#u@?Kai&>gzByMI!Zbr}Pp@G7sY@O1lX49O~H) z5cdp&s>%>ol-~uO5bfeEgf%x2bra))pjF%`Y%x2lo+m#cd5JX%{VI3EVM&V?JZbg< z_P{N}2w~^i&vkz7fS~c$>O0#GJd7fi?xQMLad3K`K<tMkT8LI}2%_>QzzY;IV?r3g zt$X%R-6UOOrPv^3Kl#p%uGjgYXkXx#Zm<eJrxpcF^(njL0Zso%l5>f-^MA<oQ5%0} z-JiJ$;@|*jyO?0v4kqa?wY^ITMt!Shq26wADKAR=?EPEPZnftjawhO0qeZPjYC$;K ziHNA@Vyc08`9kyX>f~c6hI~DTBrQJ?k0-CA6~`I^k3r+a#?{wX)Q~NcVB8rC_vje+ zz8MeXUIGpE{;mJ1HYIoCChI+5tPC(&x|Bl17ceHyQf%mM;><8!9*gL{4`*m-f(dJ2 z#b}bYV`dCwDEg*xj%0`na~}!Hi(%ir#~(xT;%S0?KVE-5s3~u_nfddqW*IB6j8|sd zdME116%BlCt+f}jBS0gG9Gho5`LkG%hv-{MNzcg6FN^^f#3u>L;k@&jIR8T6%6G9; zu~}m7tky~6GUMu9W2V;r3Ai~^m~qEPCKf$3Gnyn7w`ERY$!OH|V-uR+iOiqk>O$NU zKTyDv)4*Jz=V5x9=h(%`OR3gCXD1ND^gaL)eZA-?L;tNh$;I>H`|vBy;Jco^>+Gpj ze}m!ZbdqP7f%@We6_X;gvxSVz990Kzc&zDCNZL{yRW4DxPtrBxs{VdPz+yvLe-yKc zG8%{dTO#Xj6r1m{D^3xt{C-1sw9b%(fig`lPU`g)y!M=mn+l(VD?b!z0TE-x5c8gy zRT9uyE2J-Z{^xoHQTgr<elhJ05_<)RC%w9upygv4`HY8uw17Zvhd!L3+i3LR$~W$N z=e0Qe*Zu8G1p<Asxr^A2H<M02sVUxI#rQ?ruTTgMTrweiVRqMhrbk}e7AhEK%HQfU zoM?E36GOUTZKKVoc6Yw)pNnNBd1m9^ZzzFVY$(399zp$UkeaI1FZJ^qV}?!Hvg^n5 zrDnG4bL*6wiEmB4S&Tz$SW-cCOB8JI+!~+?r4GMpWYhj`$em{Ck{T+A&zUjF`xXi3 zLW`mm%9#{CAgaSB2=DV_nRZEnR1>g{wjaiuRLTBr0tIS`EOnGh+ok5mSIi7Ap@t6p z4BKOcQ>pqJnG6dhi}!ET{od2FDnm0H6WXxUmCM9zzyCap<0?HleKX1c%8eyo%+46< zHL$eBbgXaFcDLEx){B$7CBynvGW0&^hARx6nY9qP=ETn!J_?oeQHQ1dK%Yw|5&LU1 zNtNU$Sw;09YH>dn&C>8@9~KB`43AekZ|?BCeLfbspnqdtNNm|6-}QUV!9w`^?w>dt zn&v!7vkx-9G_$FgcOsBbCPg?)2jm3?w|UoPg?k+YZOVaJ^QcOZ?m08DkT(!}+iyCq zSS8%FFSZ`790Fd`g(l3X^LKD^oGM0u%WVbbDcGz(RJCEhwC2w(=vko0IZrp|KTH+x zwJ_#6fa}oy!Bz3jfgG!sR-1kO<%vacew(wCq{d7`&z5e?(()GU{kZP2ONEm&h-E?- zuR_PHOo*iwX3-EpGC`XLf)5kw@wRdbQM2&+ppeF@2i6F91i3fWYZ2qP3j-ssKf@A7 z>+J3SU>z@OB|dwFq9*Z*?*>V&PAlbd<c_t)^TwiZ+pYY?=i0)ojBT1qub)SgqE7|Q z?>VD&e<j7<HAcv8V<hstYtbxRuVG@BfEkFugUNfZe7B4KUv(bQSFI*aRUZ4-E*m`k z-6juQKRmL25ex(GVNiF3_#W;zP*?-DG@+Kn)$ybJA)Umfz3)_saSb!h6F+m@ERWy& z)AO@^UVrETG5!*es?JYPOWU+C`M<QB+Wm^daBecLRY?9(kz)<cMLT8OdIq-d>y4ND zpH8<aPm_ayqp!t#A#p)JRNZt``aISHg+Gam9_`gjJcb>)vawDWLg2)h$z+(A*K*hx zpZzkvl8NtY)&!VMSnL5%Kuc<{XD+MtiiTA0eTY)1K=zw3&hudvYh$n{(vse}da3QL zb!9eF5r??M@6ESgm44H%5rTE2f^apgaI~bOKU>!Ve|QM8G-#E_5GNA`uB`bX-aChi zxCMTayALFOM<q-+rdU=?z=}@P9GE}j*T7Qj*C0IPC#fkdVf0%kOW=V*K&c-hjo6!1 z`n{P#h}T8a&7u^DXE7mcc;$&Km)y^1kQE5A^qUbLw=OcA>@`1g15LrT5m1gy#EB>~ zjDBTYI21Z5!<!gf1Dcy(TcA=L+v@EFu~8erod=iPk9qe_!0w2s?nM3$osja%w8ID2 zC<&6RmFUlG{g3`ckBK(i=NKApDerD!PfXEb+<$Y9t-rzNicO90jq0TDTiXrwp9*ow z<*<Szy^7fHRUH-8Rux25f@+>R>8Qaly@95soFb;=_sPrj4<mdrk?GmbdOfSDe(V`G zT?3io(FWnZn$qp-TpaR3XN`HZJ+CKBaw@qozZQwg1dXvD-qSr((r-YqfA@fyna1P$ z^?`H!3Zi6k^q|7nNw3sm#cbZ4uVAlm!p&MSoyn?<1&u=hnh%#tJw!GzD*tBbol)>m zqO4wTdE`1JnH-5*c$O;X%wEb)qR@hC<%OXx+rYA0@>)AwhD_&12i@*_*{*0cGA_hj z6?eQLugx@f=xHJS`{x=GhjnwJcoR~Avo{FdF;k`;U3u+Tp9G%_zbvVbq`HIya-UdM z7tCDE0{v1KBNW|>z8V^e_5QgCxAd_y1moWtCD8V~0y2G7?N)YDSV7{9f&?s+S%o(X zllR5}rjmBPXV*q!DPXk!kc)~)iq5#9@XcC<#0V7P>sJp}KJ$k3R05J$e<s9IOP|`m z(Pybsg6O(gaOEXBf!cjh!O7}wZjlv_5+Hb!CU=0J%~5E|UAuLf7-=e}P#$TI2d8=t zAb;siwA~G;Q?Op>%{IK)Yctt2gjg9hF;^PA9EalMl$gMZwicyL>j~~js#UnyvD2Qx zcj`G$s=}}xfaHMCdV`kVB!H0ST2?mWgy*|J`sa;I$#CB}e^9}-xxuylW+M*v+WNZZ zMn;>{1RB~`?d(LoK$AP$6>$GmL4Rkc%)l1ti!Z)pB*T8@7DoKO1$_d^{pAP7>+21J zwT0^Vqh7GqN3Wx&$^6<Krs-lxxi}!qjACtyyZ)v<qCMceBqJLN!Z;&hJFT5(y*60% zZGn<`q4SXvA<Ga2O^|Ny2C^r%T)s&*Nl{Ng!A$J`*xviw33(fK7e$zH3r-Swqv3^w z>y{eAGe3Yi{MgR;voWa>51B5#(=YEdv19gqIn>Fb@WzDmy3^1mCdM&)4I*NGb64C= z63s)8`r!J(b-kCRks0-!omieqP(Ge<E5B+-$9U(mo?W|K<9h9scO-SoQ_nv=N#|+; z#G0NNb_uVPPuB5YZr^d+oACFE<}3M06U?S(-hQ)@Ig&b#Ax7Dd#75Mx#V4d>b#7+T zux-F5&iu^^f#7$U4C;jh42@^ig|Fi<$SN&K?rJrYyt;RzNtzy*mhTTP5HJX&I*ZHw z#fd}I8OyvL0s=JtQb{MQ)&0HI?yiVVERs^rOv9K@5(D72>90Y7rimvE{p!;Midw8k zw#oC|GY>#XUEg*g#{IZvpTYEhqUhNZzME&>{v{hJY~m+)>$Z7vnTiOr?{;66lSQNv z3Frv|rsc1Ngvzy_Crl!lGW4^5b;NMI=3m$#yM;Na4P;oKWk@y7$4DLal=%HJ=EsOS zM=BtGY792sr`T>mm~xHpqiuD*5PggtPDW*eRri{g(rtslnj&UCVSR%XbN%^-udf2x zy7&U`O$Xo^2k=$Pyvf;gtE9H%cu=_>L+^LfhuEGoJ!zJ{obo%B#@*`F;a)7p@cLaX z&YsYs2AaFWT5M_;dF{V!?eFTU6=WVHgx($~EMJhnR`W`2RBiMiPq24aCB2NuCR(vn zkU#(0Mj$&SK^oB;C9XV@m#L1+uSgisVo*isY@ChX#KUzHq76PrdC@FN8t34%LDT); zUv$H)t-0Rj2G6edxHmr{9p#f&P{azl_wZDmfhS3&o8NJw*}dN^7uV6%2^Dq^oigi$ z4$G)nAjqLi$!hJUXD`veZGS1!E`zpzD#|kPazWpP=O!o0hAhDJ9LuPAd5_{PZnv|c zD*}!Rxf7T#w|{}xE5V&t*0;`XOcICSHUn@uR_VB!Nd9u-_sMamee)TTV3sIMt!Miu z$EznVuKQv~*l6)+kCZ<huQnWs^W2&BRC)X#HW)K8nYR`e3#IJYZvtoX4U81j?Xrnt zt{Ap63rxjLZN%0bvbveqbB8{dmA@G1>qKa2a#Kdj%t~PBY*CQ1<TL)n;1!z&mdUTg z$qG}T5tM&Xu0R$0A9@h5S;Ns>#*DWK+P|1A-OpGtj@dMfaDT674plB2Ki?RVaFyn` z9P^%xp@l%a^VtI_#~kZ}%?;+~Og81%&xb_|Hl;aBe&Do&O{<5xWr5>|#kVKd2dXT7 zKgj)};c`Gc;QlBl(<c3ul1NdA_ZF7gBc%i9aTzMn9ozjSlEnB1_DTIi0{Z=iD>eUy z;RshXAf4b=4a>Cdzx+bU<Tr?J*LMEO>c9W0d=?6_re66h{~#F%(2o=v*A@;Q)Kl~r z<Qg*u$E!4QqtY2`8BGN%y2-K}S3bC=7uY5mRSn#pO?ICq{T1w%D{BiyMgM7hPNq!K zh-hW}ZxW5C67HbZcl@e7Sn9hLl}`4y%$;1Q$)-?(MYE5Osuty*{q?Ute+TnkxM@ta zvnJpw{O<6<*3!^N&foF|G-u*73hm_ny%G-ZTBOeBW?uk-8scv~>BuUK*CKZrds_V8 z|LP`A{^?S4v_qgdxcQm%9hM2}>lYiR9!P&({uQh*2QDC7#?{<=Cono>XB_+UE;{Bj z*6Zs3j^-KYRkdb25}tta6JIm-@1jukh$5mNPTu;@eIvw-S)GT9Nh;^zj9WzlmPv&? zdj3Be6mSPvv8;J;Wpt1<LZ5l~KY#HhmR+vivAQoORNC*oMcSp0MT!MJqK1Toghnc7 zQEr53iBvrrqnr}y2L_R+5QF}eN0-n-+mQVw^%Hz7+UNMr<WCp5<8nn&4juENxI2pm z6(EDxvO%s{<*5kCyvTN#`eM~ebodw54$0cj1<fHBqWTF&2SJW<?QkFK?I-$RCsn<{ z|5IGUXn=~ZEV!Mhk*DK3G&l|AZdA9t#6L(OWIY(Dc{77dvz(FOAbE5~On}FKE-D_^ zX}5%zKJf~zoiV&nlkaJ7MI{*}#(HtF>A~yt&pYT${P@Gca4LtRP$^bg>`SmR{rhjq zW~d4~16Rtnp-^tj`Sj!}Tyk`BVr;?{jMx_qvJiGi#|6n@alAz5j}9b`K6fydN4s1B ze9W2H32IPvyLWH>-~5({>%q<qVJSK{P!?#$xW|dQyNJJ1jOTBZ4yPYA83Z!q=T{6d zQ4ySkr#nG+@3nN*^Qa031J|*+rWG*K)2{w|C{wb({vT!O=RlUu{WIB&|LXrF>9$|q zHjN4Xv=aCUaW74h!e%hGRqA;NGuV?W9~rJsT{iElx=eUc^OiRtP)GW0+fS_UWO*@{ zr5I&UB8C5`b8sn{M5kY?<pOQBmD=NQUFOz&TGYA!xG&8)ARa<K+s^?H{s?a2w=ZOP zo*eIhfyW?Z?v^t2&L+YqpvfHO`MhLw@s`6inm`DLgy&Dd?C=v(p@Fg;4%kha2#W#F zbdBxi!&(eut8><4U!0r%-}o*~5K^k_^{OciK@NGb4lz-i;Kcbd>HwBkKmip;FpE$( zkm4Q~u6iJaU}8V9r&ZfAPhfVIHd5*ilE~1hXz(SptB2BMtz@tC$=>gOlExJAbhkuC zrPO+<VSs4rn*w9k_E3b=RUxF*N66r@XIKyRcwG^N%-2~e@9byj$J=V&Zf*X`M>PiO z21AKExMo<kh(}~Dm?RMvKoqkUH5d6<7>K2H>#)oGjF=l!^i$&M>5L#Yp3u4DCCE}) zPYZ7G32V2y;;yk&`q7$!kFy7RWejZx2uhy4o3pSUgg?_l1-i`-`V&+ztyknIKPrzS zenJR5cdNDLB&b<cFfr*!yqPjz%qu(Jj3;ki51vVbr^yV!2tr@QoDoZL>M&j~0P+L( zQf|5^oQ2d|)RGA&inz0WFP~XCf%2e!8o>MO&Z{aX^I=F{Kfmeu^`sdjPQ=Fsq`%9( zpYxWfjlQJ|LfaRNTrU#sDcIU!8c;<9FSMjaS2b5d4@tt-((MRXYukXzIwj7?H2CIl zYY5!$t>LEG1lYfQQd$JwPr`JcqxqSHLsnY;=b40!h~De$n^ZwkR5=k>#0}<7_l3<A zjPG!rt$9a%%ON+xWg#1pIQcJzR6GEUQoYRrL$&%^w>+=!U%3t9pJWAIU*`>5ex?NT zyrF6De_;E)^IkYb^#7AK2mcZhZNFX62MY*QeblGjbDS37DAxa|8K@?aw`KNc1|J!N zP2ku4v)qF<m4yV-nO@s+5C12?v9A94;~HnFRPgxmchaZ+F@?;2)(hZ^&xVWsM}QuG zReZMr5`{-;i{_xus|Ux_zBGes-%6x1;(36nH!tw0<I`A`tAGBp%6hW?CX=$~pq1|q zlBrvTdcXML_CjA9DP>1z)ylfra8yCBtCn@eG{5t}z6ih$re`xwv$WU#7(W8V4kw68 zAzT<<_1OK~=?6uB-gBIC-$_OXxbPKS$6vbwJEC4WD_bp-t%{UqK&p{X)vCCat+mjX zz6GUy`G#+fE(%_byiv$^3>8u&WbM|^7BzCsSgq6%@Sb~t2)^*gsEOiRyM!OubxAn@ zI^}m2YJZ7{0PX87P_X~jvCNCU;v^hyN@8;ZU~yfOS5h?lrdB3`{`Rk%!U#F%lf`|w zx~?a3%NDA~Z2rvE7SKFHb$^$iidp0NX~L7fg$3dlr_bPkYXwGU0xs#)JsliWUm6Ys zYHg!`ELk?iBf6JTsBj}J9trYKn<4kv6IHdDJOx7c^pHA5M073WD~}OBh{B}_k{rew z?Qd)rPZX$Hp)&di-Z0DZ2CHSHoN9hwVLOSs;4$vmQ)?#dVjyfcJr{?mYl(|k0V4%- z;h86nP_u8Ha~QE{mL}4W<b3-1-i?M22gVzOl!|O)zgqlfS!tAv+|pT_E)N6CfkaW@ zN`SQbe-ay2E7UnMqm)baQN(V6MRSIA%ujX!6`>h^?3c!fwO+q@X*jrHjg?J_{{d1v z$8RQMQ@ENNUL8X7<D%p|`1O(|Qh)(l7;Do{+J2`*1}?s4<#aHo{|P-71_qyMQ??Ag z;;7SMF9g{BC$Opw-7;UV=tz=2^*9s|nsy?%4Q&|i><WPBT$-ItDV@--6Wl^M3FW7h z#E!^cvJ0fz*l8BNBpxOH;%yXYQhF^cz7O~nc>UkNYePhf?*fB_u^$CL-#(ib>)T>< zDbP*9?#bGJXaEZEvRe58*S^TpEt=S!6`U00{k+6)Ji`95uvKVu_4zunGGqk7nQT{L zjL3dTy_vY18!4{48aBr0h;UElf->@CsF{i9?Ng4Vu|xrQp4fkZG39#<o>hcZXgmMS zk#%dE!|sFaAD+iO)TIsI7~Kzc2y+}dMFq%%qJ_0CUgG=O6ZLe*1Ji8j+AT^c2=laF zIgw3xhusfaQGSVvV$<rDl6p-$CM>)W9!s?PuP&%efz8cXRQnb`RkJWnZqPiPy<byn z-s=^_Qt6t37Hh1wS$wWf`E575aEi#4SL*)PBR{1+{l0>;IQ8y^ZCxCL*g&u7|0xh+ zQ=q#;E<-z)(S4=Kp0{V_km%9p6FX-OxC8Q<ybJ3OSWAhhFF=A^e$_jYb+r2i79;P1 zLRK2#`<%Da6T~mHxGrqG%$o9b2hpbZ12&EF!UhZO2|7z@BRa;5-M7H-c?oWV?c*qI zBf>LhY}hpV3mX;~4KI^XDmS6K9gNbg!lJN?Z)}m5uHc;-H3^`XrY<@02g;CUtlyn| ztepCrL@ZCYOmViP)fQAl-k@Wz+=yRe(iDLde17P|O8RWd$8^?TCrNgiG8cKLzC7+0 z^?>T&*N5UiLT@$6NMB@dtlh7y-#Tmhe9KxY32)1($gDugq`g@<@=EBObEtPncW2SR zVeGXiFW$+fLA#iBo91$drq{-jXkoVgPC{m)_ss|k@AE+6Q;P@gy&q|51AK~R&pm~T zSoo5X=O49RU8`o&h@$uEfA;`_;Oyc1w{a!5`!3Xz=jU~r-pKA=GvG0vBb@Aye^@{J z%>AMoTi-PZ7K?8-)tnry?td|!Xz05Co%piZi^<=m=nn+99`-T(E1(Go#~{NcaSa(4 zoeUAU(~z6p#;$J@qHDs%+<&JsLkQZZfPb}9dCW3Vj^5SkS9n4%@7lYyc(+EnJ&z4n zxT?4TJ~2f7-yihHD}?g)JiV9FDw*+ec9Po5pl(USO4a6ByCbtiV_jBVh^etbpwCol z!2R8nYadq2-z@5HcZG>H0~C05<&~+sR*6rbS9aK<!aF^nzihmj3a}@UXVbm8+sdBw za*JP2iHa@BwirDlA@A{@pq~h(AbEJS>Y2ocH6U<Lqn-M)&DUlTvyFP1h(<e_GujH3 zLI26YEFypiN=W&^`ae!tL3csg-<XzDo)d;)Y(6+8r<6Qak+TwA-QgSrvHm-soj!3d zUbmv6nbaRGJTe`o-ds5L>DonDdoS?iFFxkH?PE9IpFbF+`Z6RNIcopJxoV(_S^bez zyf=nHgb`s2*ka%G3C~a>q7~%IW!eX`lWWTr0iq_}T+9!o{u7C-puQAdn@u+bS0e%g zN?q{6N$rX`)S_&OyrlW!pRj!U&MySK?l&_Lx2ZO`Xzw=grsM)BaxEd2`~<ZEt_L#* zLvAI0KQ8`eQ+!A5F%DIHgxEI>no)Da)ptNk`3nTcrN|lyXR-iJCf@9Afct)ySW@-- zD3q-^b=xN5kVZJ8q8$HyQCfU!|MvP^zh@QGw~pP27fgX{6yn#6?oZ`h2MGUaWd>q_ z!ia@<>P57J%=+B>mPf?<B23J$8k=kWEO0LN=e?~0ub$FA4c#G#EUaKBE(1NipDhA( z7IjQ1-dZ*RnEPpfSghOZZy6LnmE8Y&6P@NI&ZLOdy-z1%Fj~(}kUF030rsRXT8u?l z4AQ?6y|4uaT+<`s3!JTw&fCCvpB3_FIOrO8HIO<(T!*tb1FtIs7He?8CZ2@k0u)b{ zATa-gcsRN7lMtBEDWdq#2L(y|o5rf*mSY1=$nl(}%l1O_79Ug^PNDFZclor=+kn=+ zy2QMv32~NvIqN!PXS#WzL0t%VZqGh|g_NP^FK?W)oGjyCcP#CE%Pji7?R{eI=pht) zvn~_$_zk9#_<vqyGE7l}fCIqHb75^4geR3YfKbxth%VmjJ$s%mPGr>}PW&nY&V9XE z0mLb7#F5hD(90&eT>GP$@9ohMEx`lmlth05>i4=wq(1%)3=QUVij*zFmpRV=`ygeR zYOyYifF#=t>P1M47Z&%cMSe=uVL-Y;Ja`z%i&#V<VT8L$G9g=Lx4SYL_2TLU@!t=j zKu>5%l?25G!<2g<I9o<QAgg%Om?9p%O00s^V^3E{6wiIV6Pv@fYNsJ_G+L$os&aj( z0$T7pO59Xs15@Q%@zTVV>)*HtcCm{_NYy4)#7+4axf3OeMz~31AE2aIF+(qI7oQv* zF5Nn*sMj-FNr=BS+kPPO<C$5<yXD<K7vqR(#<gKC<-I|0465IA^pQi<xDi9jCKquT zy)aPl10Ce0!^jR!?a(Ky1Psu03-qf<Z9hHv*$+w@iu~GsDISm)eFWVYn-0zPQLXox zCx9?aI~Z6>Rl4YETIJ;E8r~lr$A3piEBNVS$4$<ccN6@xF+LDDTLbHon1}3^ijR=J zXw9pIL>jIiDcZz?C6=+vgGKeo#{F!%H{;%0D=_TZL8{w6fgEx~7n--;r3l9+lBb-c zmst*U08DrBcp%?85$xn&dS13Kc7AexNO)&U67M*FK#_Z4@55ZRo3F=GUznERlk52Q zP>Nyjtr@4VXIOL)y{S|LeyV+S_o+&G-gQ-k<A=BUge_0E#rpp|O!J5pG00fGfy1xH zHzR|AiS?W@c}>=<9n*>?M;*fu%@~Wy)>O*0wnQqg39q{zVgCrK%RILI@GySan`g-? zxL6d67!Ah}qZwyVSS@jyR~scxe}x~#+-R@%(#wngd|<?b_6l*vRulQ>n4fUW|K}&! zU{vmMC)g}B7xaebMvWQigM3v$L@jvl8Xg_&mXRq6e?3b`V^VWC&08PEp^i0br5Dbf zlQ#hgZ5cvN(s}C%UJ>=FV;^+(AkVujAip8-vd!%)4i<4sHU=ht=9gSLIAu$s7rnm& z<V3?DpHc{CM~HlRP@)ht{r0->6%;rd1fPz*t0FWj&p^E0`t$YPPN*8R=gWKvrRGcd zX37BeLHwI7KA4zT8@zB6YHsLC!caf3CKuX4Qt97(!vfpo#Wyf_e$o=b6u1o(e{K<4 zP43q&VJpCdq^wqp-35CwG9BKU<L!c<KRk9mHt<7eTj&Xu_ld6T@%;|RI=kDtyR_qb ze%tds%>aiyfmVKU?VgZS3~N?zPyo5703o0l{sFfI69P)ELNLP}mky<&$e3Tx{d3w% z3>@;K24lOsRT1utRac6XAV3Fdm)#(8S%zo}w{2b}A2B%|&n`jYNW`7*QN~gKM~~|} z&f8xM7?1`Mw_xHgL-bJ!MWF(X`cJE5##p~O;5l1<SLK0+lTZuZCKv0po_{5024A;? zxGjVO4zSL>JZ~iHT1KqA#-SC1C(=1>7!q=Gh&6MoV7U%lF)N|b2P@uF^AMgjZr##B zp!OiF7^Xo&Sma=aU+CY23~LY}PI(?J8q`;kA8vU-NeRh8K7&(5-Sap5nl*o-fm`|= z@%#G>B`k@oo=F-Cvl1c#DxOcs7#yHF6jzs#IGZEBY4LVg(^s`5ccEfdXC~R_JihU2 z<<7&;u)->@j33Sj?d;Z^AiY=~u(9}4Y~rABP40O;GJF&oNx=k*Nd*OX=E*#^&$Z$N zE0BD|>)0@+z<t@0X>i`BOckgBJ-rnA1^TxUXN)Dd6X!M;9>{s>TZ0eC5(IWcJ@$%| zNbioBJ}m6kq{At8rjUh?9Tn>3oKNG#JgZOJn;qo3FLb{5;Wnrqfo+65MrF>bH>*oO zn1kiRTm8H&9kzu0Wyq%ZK0Qa)enWRit1}Y7^TajpEgmjo#6?V$i36QB0jzuxw%(N7 zI)ebo=B1^jwU_p$XqK&vU6gC>>D_PyROlz9eN>f2eKgtTqIUD$jpKerJpC$;&d~ls zA}7gUyXyJ09O7S1wh8k=WL<PWw6c33SKAo;s$GnVGv?{;VYloo|BR)jzrG0$cNP}d z7ooR_J#^~A(nz?ZJ(PST$1MRVJBRMeRbq7VSy&BdeidCtMyBKq1n&-d*QKIoiYZSW zVf}rdeovE66J#9qgiM9mZCXAZ{<)8xU^*=$Kp4PeEL<Or8u8Vr%Fkkpm2iBptSlDi z4#tmN$gmzPG>q5o)6*MD?(bSpa;#rW*XUk#Uv*{L(<lwm;pqF_3eRqzWbmLScYlaS zR~%VZT9nbV*A_&iN|wx(bCN|D-D;=$n>I9ZY^h-WPpw6FT<LWV9{Uh?^Q73cO~J75 zb1a39yMDskte@E6=)lS40Q?VsTZ(OQ?o<!@R8fEw3KX)`9^aegu<^YQ4fDpYJ?^Zv zn+QF-?7u1>w^k!&N1xTPcnDLej$DuYnt6BHl(thi21=Ve8Jj;iE*D(3iCfaWDs7)u zOjF(hMDdPe-kr#NRgHjLi_VHyWbBIPMt@jL^h9?-$i(T$hy5J@iSNCn*}-aC+M3dq zoxc2)zMX*F8G?T}5%;UgNFAU2T*MSv!ZMx5OocNezoq~FPYYiWz$fqInB3=%075_E z=pbTpS^h^y(`3;>il&z}Kc~L$X1p7AX~)mQ?E=pyH&@j(4J~Wz#fi?KaHph`J7#BV z4^Qr1tr$9MnRf?$5;f4e{zv9M_nC#rZn6HGHtxWuGwo3OV02&V=z7?Co`;@!u0{dq ze|&WZvn<u~^eUYszDjy$3Hn>nxpEk@ozTH<eDh@yEI#bZDF+@d)HxPkH#*9;Ot)5} zN2;Q`Gjq=U;c>3%<$x9|Z5+H98}@rzc@fhI#@YR{PjtDXvVC;e?T^zssO~vtwO4nB zSJ|~u&+ccX4rlA>Fj_Vz<T1m;zfL*_Gq<UY)6SH%RE@X)?pU%8UK{O}aUvc4btPC@ zzr8K_W<KpJ!>z83p`q!)Hc|8~;o(^<;>(&|wv272hRjGH@mDk<1+Q_CNnF_JZ^#ej zd<@Lu2b65c7yb2L>MUrlTv@;QzmLH{P2&^)e{-5zcSg=g!<)#Ak-;1lQ{nYHB>0u+ zX<JI|4%2*VF@hArn{!y-T&r!*1xb;>Hl2a8Gi?53bcOQo0Y`Acf99KL^Zxw-u^N1! zz!_tNtZ1hrtRQ7X&&b7W|8oI+6pZMm|6iVDMlTucybRxpb{w29{Q3niE37Kf{asmT z>_?_?9EMl{f+!>A<eNJ#J2nbI(tN}%vR)YRBvb-2;<YC#1LeSqnxODKGGpMRQr7#R zcyxb%q-2x3S%0~F)+I+pc<1?(+CL<+aE%#3Yd1Df^mOhI;3aH{4MfFd({IZi^YLDz z5}R>rFVcK`UA^iku&zk6Dzb<i)kl?Oa3rNo>Rm_HNmS-H#jy5gyGFSE=yTmq%N=l~ z>q{-W?5ek5`~F<D5}m8B>ZPHd;djJ#iZxaHU!woOYqOOXCxAlzSyw#591uH(O`#Y< z%0VPPgrfKk(2aG>&9jln5#|epcVwd{Rn-{HwZ{*EMqCUNr1{NtOEbjM4JttK896*v z6vYvBsTTgmyp_$5d&8^dzI~ikp=3l$SL_V#@}pYCe&JK$)6z@7xn^zz8R188N%J$^ zO1Kk*ngWpQ2`uxb{f+*^B+9}H`5z-ANiByzWnZ@*5$=tx-dvF^SREefDc0R~U#C<J zt11>%*(2{W=EW~vG8VzcjabheNa2b0Xg_L3dtbUC!f|<_xyrEKuM~Dt;>&muzBc7q zV<LN;Bd(ljI?US}<{!lR3TC!{X;8E7rBFl~7bsg?IywrdFN*ark0<k9!X;+>IN73u zFUh#?&sY(yqW7NW+Pyq&i@uE&OKe%cVXC#ObC?R=D)!Tus`eQt#A&5>`i~Pmi*S(p zOcuW?1DD?}-%g6#`@joB+qRyjK>WnXe9b0QQ>%e<jlss3xP+gBZehCTwusAOYKLdq zLFKdaaZ@}G`;zo6#CKeJT!|va0P1yJZKiJ4f8Q%>c0e+1%=<C2$<z8suUFnDe9~ay zFg5}s-g6VbY!0Wg={Q{5S75VIANAb!*3-s~ektb<+g(1XIt=!rY5p<{t0k&zQ}-Dw zj@1qDBk)7U-1CZXWRo-}hv`2NRg2NNmgv#;{q%T#BsD*nqi;T0_WH!X`-G>d;H9r7 zGs*<BFYx5djPVgMA2gS-$b2~0LoPy2b5wW17d&yC+S`Q(Y!5sW?G9b3)kd!<EclNa zyeWt{E7ozi3a>d+pQ6hFDLkvH?nYOhlU?Q;vQ3{GN(^qIOqK`42hSYsJ(fKt=_X27 zB6zxY2KF5!!rvk7Tund0sr6JMSQd+SUAAjrCx+feDErz>Kba%nU&p@jnh|A}*}}I) zw{2%E%>p;DW_~0+g}jDf*Me*HU_o)ShD>K{{9rKizT;?x4$nSykKkdseB#QgZ3$6s z*$gVXIo`8h%O~8jnzcV7->aPh_vm#@)+oE+=yPdvQMl&bn3Kt=6Iaz|TQw}LWyxLn z3%3$*W=0DSsiO_NSAH9RPv31#YBPw;j>nx7rh`ZW3=VEaHFhTscxG|ZWLBk!bj&r! zg_oFzRf%YzV+8Ma@y+&p{B%Jh%G)ccJ7pYwBq%*CT6BS&PxT`yBSBW>7E#m*wu+a+ z`S3rOs!qMm4?UOylIk_lQkPrw?jAD@oX_y!X-Np{R0J9~Q>N>p*q~^~d{gn4jb3B! zZQB^3=7nOeU(N5rKYnr1i1qebK!<XT1*8zqm+b|8b2k#WY|UcEil&sk&U!MvR>Np9 zI&tiatt!5B7Fl)Cd3bX|s=QB4RJ=mE-Hj{>dHiYF&@;qBQTJWFdJWE(@PDvZ;Z0iE z{kqvNvtkez$g??f2c2hrQ`)|rAK8j3C}l;z%hyD?WM_7GGHmNtIsOs4yScC%#pDPp z&B#zjmD$B9dh#Pr%|C|yzwYhO)Aez*9uf3pm^RVjKLB*a0Su{!ps|f@IfX_j>;!I1 z5r?<tGwt@bQ5LUy+s>r@$l;T)##(S23o2w6$}!7>3bJLG4&}D0vVw=rNu9#Ac%cE* zO+owV?HAYtxlsGB7^7Q6vdkA=Wp_RlHPSvHr-9f~IXhPLzzv3UQTP*jrbBS@`l8pa z$m)q}w*m2y?;6jO)yjT1(WgzcMwnO@mkS?vF(WQ~5YgxPSsK|OspoCXBc4C<HL>)} zM~>ZMi??1FyJTFC55~|YtK#Cx@zL{E_Qc#8J3&3pJ-O%X#UgA*l5qdN?k@niihx7S z%CqrdCrFDJ39!($K872sX&yq`y4kT~mYuGCBlw-Z3A*DU11ot!9_Q0Eeob^~#vCRn z8Hb#1j_48W$TMkUnbqnZb;cfHD3poEyPOgVqNwU;3y+dIs845)w-LGQ`PYqF$HQC# zn8kwILxTV8wc?nHqyZ1pi`sB|W6-d;BO=NXZ~)rzUOwGzd#fRK*je<tjb`LWA-sIB z;$wO+ND-f4CPRYE%VJ2X+izaslw_<%AsYtRwl|b{y*`J0F(Wr-hqpp-U_3GU7uZsN zLYhSmmsr-{b0s;AaWCs*>M#bEtz5Z*x_~!#*vu*)LrgC~(2>rEfkDM~S5jPE)z}O< zPa^6Qy6L0-6^g&d9U%Zm+Df+tosIz(2yZ6{U?#N-UL$epDI(Ak4+-_7Pr20Id$@Ga z&af0Rh&}Rv$kQ;X7dB+=OQMw0jK?VO{VtxzUqadp9s8!gJdHTa@rW6FjEvZ@f;7Ec z#VDVSsy&C(CNo21BE_#DgW=7HND~mspwH=S!9d|*T2DqL|04W*gkI>IFzAfb29bY* zEIc^;#S5W-KbVJYrANhx9xF)sAyf-XA9tlNbKQ`VhWkpKB?m){CLX_}oQ6Vr1tPtY zxVpR5tdQ&T{)SZ^kimbkS|V8%TTWg+5Ax(4$V0S1W*wyNZFC6<ogm61I2~?s05;O< z9ck)~8!qK`PT3B*7=9Ry=}k9(^eg<=uU`*BlXIQ4^vuE2(cQ=E^wmSY{O=G9_cci} zcJVnJhQDqua)&=aRHnh&u>0@jm}22Zm<sQCp=}7juCfcdvtaeyA3XQhKl~GOlE1G7 zx^W&ry8QsCGIQPj>w0B1Ax6q4-(*t8`ujy97r%SuG_XbA!z#!B%;v%sj1Iwq;KCFU z1p(^%V_~3xAvIEk{Pdn!5x^$R{q4`+L-dX#==8m~iJ#&0_Yl#g5E%?nn!5k<K|6fF zSMV^%A08K{X8tD%PK`7H&dt-8gz+Jk?0FQH5l`WxAM`m3*PYfL{wy?<XlK1lf4V}J zVwLyu>qh3{c%w*_A8r`}@Hmkd?p_%l%cDnwnt_(^=5L@g=FN%eae>oEie|hI*T_-# z2#c93f`*O)_xckkSqEy!5=GLJ+i$KxXRjgXZ<Pxc=7AXV<1%qRddPA`-0})uWtqZU zN^ds;Cnt4uul#$JNeGsPp~C+V0O=%d{V&2Jvo>Hi*Pn5Z7LlP}e=^()tp(+N0__nu z0{;~(SA@L2vQ>{x=LVWl+snYugmCN<u?nWIOqGZ*$F&bqHk&iwkq%UgJ(=ME34KSp z`9R!9FmCQvPbj1XA?VU;HN_%?oCZ4NI}yDb^pe-j{y8CSAiL!ny*DmCi@ywHz#<>6 zs~E0<vwj(HUJ+N)M_^r0P-tg4kYCao#r{@@Z58@-S#~CiJIx1Pv+&;1XvNp8r8<2w zQmkk%t`7?tg*Ife=fm;C@FVEyiNKiit*}kX(N0;-z0ZSS%$J3rDnKVa&w1qv9#b(y zcY!=lDnIsQm`KC>z}OGljFu*^Z}4X?9NE=kjk0YZ(wG4yE3gEhRqN{gnGn3DaE7OF zBTK;@zmw*=1-ZUOpgL!o{{LQCV#XV1i375{{AChSvwmgS(#gxq*AssAKX<_h_$V6b zqx}>Vx}!q|#~ZPTO(Q|xt58}Y!IC>J0cjM)%r`QS+0%HbR_a=#+Q92;eklA`3zZsP zz4DkFK-vF<u!nReR3vX|g4GXn07Gjfy~s||&0gmF>+M5(O;Mv6Q&9M}9(^VLvc6RS zYYaoV;S)`?T$>nJE4;t2_EmjxcbSCQQnIZMZXB8mCSXyPG`@-zivIVZ#;q~myiErC zA2Rmh117>#5fXJSy(!tj&p&w}W6W)>)TTULrjgKpZh(pPvMQ$UjjF>1OQKgU8TO`S zOLzU{+bnO>GgcA2b-k03+KjAa=tCsBE-;p(HujzZpTsLxL&fRycjDfh)6rjC-(;Xr zEa4`~yRI$NcDjK`8hBw`IJ%jJCB^Z}yF(&P2akgJmfak2er-Np8&dG=49d1=D-*TQ zr6Fgza5{Bi&Bf6EVz1O{%=nA@1-`@aLRYFkw52PPPJatcBFt|u(C-pF7P<DPT$=Ww z;px<ug{gl@&wWV*W$@{&OGGci?-YcphJ~YX&cPqR%-prY{TqAvR!(29MnHzSR{mse z@sVVyWrpqNz^=E`SK!fy^tZH#UIB;Zb8P^8^W=Wi;WT7A{RS=g24lS{a-J0wey9t7 zh`vjEaud+M3z0@6(4dbj(KjK`J2Bx1;WdGi23a_df__<P^Zyo5%t&Jl?*M$K;8YwD zY*}BK+s~gRx$hL=k+C67PM(0G?Y_gKoS%P?-Vsv4ltUn7%Z1n=u$jujeb~?c{v8uZ zB5DU(WHCsA#Q*_hyxs7flGUDVtz|vZ;5?k)@B98%s0?xK1Tf4BR)#{PcR{I1E2(ak zi+%YoX=C?(J9jYv%4lynSZU?MH13B^D{C9d3ryWUmZELnN>A@TzC2(k?9H}fVRawK zcFuZ#!m{ftS^1HryF2GMu3KhZ0yyYPTCW0w8fcJeJ@OdvGyL~90DhF3eW&TU<|~J- zFuJHxc68%+z@^h>CMi<ESM#6*fOM;0)9)d_Orb!*Q6<Hnmtey7*R93x4L8lcOpcOb zj2J;>D`&>s!4|=;ij0gT<~gbkwRo@2xJBy&BFj8M>yh%pkTM-X%YLqxa-n_LD|wI= zW!pP(nvkriN}irg4(34guQdvkFVC-8F&C$;W*QFRg(`mqYz1F=q6m&y9R~LszEZx@ z*h(b|9Fi_Msi=$@HLu=3)PL<8jOgd*7-3lyqvE?ExiBJwErTtakdV@u8G9$WvLfn? z31q4gj-SfV9O#AgwJgSY?ub8Qx(w#tA#-2rtdS|N4JoeKh1Y#d5lWa(4b^MaIN!fW ztt@n})S<u4$RV=ecK7xh<$563(Y|;e)5CwP8qn+Nt0Ff0YLk9bJI9Iu9`a>3*qkQ@ zNL&NZz9@R~zTvEhS)Ve+jI*+yr6n_J1Zic89FiPY|H!{rTfMHgxJD_P7mEqUL1b`p z()bmHiN(yBoNr1<zec|I<-V$6r!KvHU#WpsDtrIq8$|K=!EZEqJy#dk(KOnO4oJxX z&6op=K<@Kmekd9Idfz3HR+p49|IuI8UMgq1>qmI6{sJ@2_e^JU<|qRlf8K(kf?Fr) z#=)o4$@el$rv@FvBmgaI;lN~n8DA;){y~F<g&j&+y~~pm%56?wTjn|%XD0aSzddw- zuS>?oDu3lfqRuZB67Gf5c!z`J2lM5$;fDsuB^=^*qT(4ImA*i0VDaNwiWW4r@-7D? zQN`2A_H}3dXzeL3?#abE9kl}z8RpAfAx60pIK^!}C8w<7)a}6y<*7dneHkx8oOl{x zG4m+vqq&~yGz7P<oJKWMcYg)DdQO=eTb(_<ai^#IdnNp9Q-i&C18NEFoI<q!6p>P( zpc3M7Q5A*U?9*ck;KqG<{*mvW5B~q*B*{D2Q1760sB12%ky*k#jc0mc=BVWG?NE8s z;3GC1{qH4kT<6~VTa>d=p2i`UHN0=SiZTS1ti7g%oPrue#?WD?5$PJOTmH<Dk5n0n z)-m94Vn$2cmfyINcOODb!6Z@*74-fpSI5(8F)VK?9H@gJB!5xH0635e&00tR-a!wK z5BHH05L9fAtRODP`0>Ae*aUe9>LI{VFRTTUH^Rt$k43X60EjQLRmLMJQa1G_63nbt zYn0i;cRqpi>^*Cw^-_Sw<<Cg=*qegE9Z?eSBZH(Rvlht*f#k|0V)2=kl~wTBFLaOH z*}tA2KM73Ul*TW(l3M7p)eE;>?BYr1K4u8~wI@deV(1OVKjz~_kx(EUY@^Q5Wzvw- zB!nLVWPUR487bJZvquN?&s7%bz2G~&v25^$D13^ef(_vHfcvu4goRb?!_)jNA|K8- zFUQ9K=gZ1E7!Lku+C~XBQBiq1B^);1p`OkE%iuP!9(!{s`I_T4$R?+(Sn?V{u2t7J zIHEoxMSc1@t3$|?D;Kaz5>Spdg|EN%@7Ldidz^_RB9iLKAK+NZ(LtWC|M%&^p?rV0 zgeutjpOJ;ZHgl16MjS3@9$3{~b4?C-O{e$!pX7j8#oO+4L6sBehOmrJpZo_H=3k@8 zLRZ2lMC^@;sIUHCy<Ph|)M+1%H7%>GoJv~R-ff(vrP}g36?s{Qu|rdi(JF0@Z{##7 zW3^$EU0PvDI?Y5O#5-#dx_FgS7)5fbxR~S=!<u#%BM3y{`4+T;_W{*L<Jn^L#${ z=l<OH=_7}XB$xi-6C@9ck0vPMZAuMSh238_7BBxwK3FE>dTkh%sn(8VQkR#BQpH70 zyM4e&Vv|<#Q7kiMd6_g+d3Qv0P_+d3!$%kATTb}_IJ_|a1Uto!;mkPF{~dpnU9^hq zHaEP8!JC0LDvmMWQ+0<`3Eh!97By!Xxh5*<`oWKZfSlvbn?gOe9Jo^l0r0zBVH|ll z-unLrZ)!eDFk9xe7bO)udS?)(FGWn`PCq94B$8^f28h`YwNeM`=m#HNwI(D>7vgb? zNvvYhOo9rKSKs^DvN^3FYHt@5N4UfycNW8(R9<^U#PPAdDpSTGb&K#=^0Z{^d0WK+ z191wqkU9U~-%#zmLc`9GQc0#8Q7LXxfj8{$VAkICs$JQGwx1*`W0)naSBMVu7dF9Y zo4CR!*AFJ|L}BU79O|uYr6wL=>3CIw!`Q8~#lw%NPe|VITzHhmM;o)`f;OWYO$>7O zcpSPqbSVnSZ2i~ynM*b6eN6=V=ExfzYvgESIn5D#B=iuQ+EO%(R^}=(;un5>1^f00 zVK@@*_$O!KXK?5u<MRpPZ9p2pyH4<Zw^Ryp-}QfNT8M6N+;~va^WMRXIU<b(g69KL z%c5i=7rm^L6-<g@Oe-}O0eJv9;XM`69vhTbGgI=+q7R;x%Eu|;2m1`K*P7sT($==< zxN|#TG#Lm&yF>cV&(Lz;e(F7w9wr#=%zK4ovw(Q%da1_M5sK5+McCvXLtm^6<G?LM zISp|`TK88nx_a@*{RGAMhzQZEpfSbYBo;KJu8Z-NVt3MFxp^rcyFbrO^bIj@f*`~? z7tK%=)s0y4NMLO_<{rJCBGb_)dKZn%OK-gf>*9IfIM;naX#^9c9(-r{>&~Hy;oj!Y zL_wwQo6|}S`}b+bC8Sh?ajlv#4KLh`fT5vSy{nFiIowjk4N)^AYj$U|vOPGx4@1YU zFLt>zqK>uh>hR{=p8V8AP#ulFyzr&6C=e(VnJrXlSpI0ywuWsd)~jVTyz!>C5L1$+ znBHvc$Phpt<pI?p+YiwGs+K|?WjmQ}{HosZ-Zu;eV_P_ziQe$;v=gImqchcB#RhD~ z`vH()GpUT*PD4+OTbP(vsp)S)2}!zA^9-Cycs%P#UxVC-0Uu_b(yvK_@E8t&udY*9 z2#%sZ{QI1LxeN8b0h1(d|K0~zWvo66O(iCIC(u6aLH=9Y^ncHY7Z+N;Om99(rFYdI z5xwYe$q5~Pc*no4X~>CX&9QqHNDmnJQ5l2t=6Aj5oiH7%QS69nqTQ1y)w{WwUNE)N z_}$)~yb<BlFJ9|Kk(Wtom0PYhXULHvsrYjX^vjOdG}<f!M*;#Ixt1*<R-$S<9+6Ky zKVKonSJJPq(%8)%Xv4TKUq33IJcTBUAi`p=JRu(QkTPSa-22g#ux~N?rSxK8JfYn_ z-7^I!<>u@z5u#_7BakRR=P=p1b92&9r(I-@J&F`G1xB~e==d9(X8xJ7g;0EBY#9mj zvKlL5a66`tH?dU`OmPGI%#J|*Z%1!t5y)A@6)+0cAvJTR3vK6Z9d5M^$!ybcE7xa6 zgKz_(6^~+cq3gi%m8)!DeP0NbJu;Y%GP5Tev=jZ_G$Z&R)=n2$om=lbey(2LU|N*< z{8cEY5Ckxbm=mNw#`M0;Q<|HPllJr0%X{|tI_2eNyBK`iAWQF>LG`+U)jxPY@uPYW zBJ9i^9rD_Sq!i^srzcU8KLJymkI9Zw7~k+P6XD;tz$@c}Ss~SKZ~Vro{UnummI%pM z18<|cXCq4#?tn9Xc~bkOMb177Vq{fZP8djR-&-kBP16?Q)_O>O?l8P(lw+7-6$7SO z`oPw+D4Wmk?3f@Uc_oB1muE@W{fU0Ve)X+Pocl1zRBn8^suw#s65JseWcMB>RFd<y zPSR9S+F&*bh%d3ASu@yzQb8&5tct!YL9}mDi6-Rg*9gxGL5@GV$ZW%&HsS$AAv|8& z2V)UWMjLsDWa&R3Se~&aG9T;CD;rQtc8~6S{633YlZh5sWJ&JIz5qe>M$w+LBnW^d zy;H$(R6LS-`3%9WFryfN$Y!lT0M~(cV2XRMbqg~0j<mM64lk(wDtNH2b=QHa=#xYs zUVd7jlEvTv-&pOH9}rOLm!xXk&3s3M4#I7{FAhwbD%k&7IXfVf4CWoT+2APVu6AVr zQx>Jl28SP$!Eudvz5JukD*o4$Zcx83fBza*u8Uln&H=fXjt8BBoXTeU@5Rc;=ohhC z`iNEG!2A<1BmK);57&GzHJj-9w#EexY(#mn*#44<amjZ{Dm(Pt&R!AzM+EjuDqO-n zEExS&&dSM5H#voBcL(0;-Qd~WLO_iF`EQfih!uB_-Hu*`8Xs@<r5loFC>}b?G*PfS zs;MEqRaOA%g6%1P?NJlnD`rS`?)dBdS?2DKxj}n}O|<?^{gj)0cz)`|z;;tk-{zM3 zsHF&lqJGG|Dplq~1<=4nK6XIeCvGWP0PUzC5#+X~%?}?U$hYpm@It|R`0zoUD-e#? m3)e!Hzr(|K{*j0DFRr-3DJ~uw56)SEKWj^Si`%;ovi<;}o|3Qt diff --git a/docs/readme.md b/docs/readme.md deleted file mode 100644 index b584d71e..00000000 --- a/docs/readme.md +++ /dev/null @@ -1,91 +0,0 @@ -# ArduinoBLE library - -This library supports all the Arduino boards that have the hardware enabled for Bluetooth® Low Energy and Bluetooth® 4.0 and above; these include Nano 33 BLE, Arduino NANO 33 IoT, Uno WiFi Rev2, MKR WiFi 1010, Nicla Sense ME. - -To use this library -``#include <ArduinoBLE.h>`` - -## A quick introduction to BLE - -Bluetooth® 4.0 includes both traditional Bluetooth®, now labeled "Bluetooth® Classic", and the Bluetooth® Low Energy. Bluetooth® Low Energy is optimized for low power use at low data rates, and was designed to operate from simple lithium coin cell batteries. - -Unlike standard Bluetooth® communication basically based on an asynchronous serial connection (UART) a Bluetooth® LE radio acts like a community bulletin board. The computers that connect to it are like community members that read the bulletin board. Each radio acts as either the bulletin board or the reader. If your radio is a bulletin board (called a peripheral device in Bluetooth® LE parlance) it posts data for all radios in the community to read. If your radio is a reader (called a central device in Bluetooth LE terms) it reads from any of the bulletin boards (peripheral devices) that have information about which it cares. You can also think of peripheral devices as the servers in a client-server transaction, because they contain the information that reader radios ask for. Similarly, central devices are the clients of the Bluetooth® LE world because they read information available from the peripherals. - - - -Think of a Bluetooth® LE peripheral device as a bulletin board and central devices as viewers of the board. Central devices view the services, get the data, then move on. Each transaction is quick (a few milliseconds), so multiple central devices can get data from one peripheral. - -The information presented by a peripheral is structured as **services**, each of which is subdivided into **characteristics**. You can think of services as the notices on a bulletin board, and characteristics as the individual paragraphs of those notices. If you're a peripheral device, you just update each service characteristic when it needs updating and don't worry about whether the central devices read them or not. If you're a central device, you connect to the peripheral then read the boxes you want. If a given characteristic is readable and writable, then the peripheral and central can both change it. - -## Notify - -The Bluetooth® LE specification includes a mechanism known as **notify** that lets you know when data's changed. When notify on a characteristic is enabled and the sender writes to it, the new value is automatically sent to the receiver, without the receiver explicitly issuing a read command. This is commonly used for streaming data such as accelerometer or other sensor readings. There's a variation on this specification called **indicate** which works similarly, but in the indicate specification, the reader sends an acknowledgment of the pushed data. - -The client-server structure of Bluetooth® LE, combined with the notify characteristic, is generally called a **publish-and-subscribe model**. - -## Update a characteristic - -Your peripheral should update characteristics when there's a significant change to them. For example, when a switch changes from off to on, update its characteristic. When an analog sensor changes by a significant amount, update its characteristic. - -Just as with writing to a characteristic, you could update your characteristics on a regular interval, but this wastes processing power and energy if the characteristic has not changed. - -## Central and Peripheral Devices - -**Central** devices are **clients**. They read and write data from peripheral devices. **Peripheral** devices are **servers**. They provide data from sensors as readable characteristics, and provide read/writable characteristics to control actuators like motors, lights, and so forth. - -## Services, characteristics, and UUIDs - -A Bluetooth® Low Energy peripheral will provide **services**, which in turn provide **characteristics**. You can define your own services, or use standard services (see section 3.4 in the [Assigned Numbers document](https://www.bluetooth.com/specifications/assigned-numbers/)). - -Services are identified by unique numbers known as UUIDs. You know about UUIDs from other contexts. Standard services have a 16-bit UUID and custom services have a 128-bit UUID. The ability to define services and characteristics depends on the radio you're using and its firmware. - -## Service design patterns - -A characteristic value can be up to 512 bytes long. This is a key constraint in designing services. Given this limit, you should consider how best to store data about your sensors and actuators most effectively for your application. The simplest design pattern is to store one sensor or actuator value per characteristic, in ASCII encoded values. - -|**Characteristic**|**Value**| -|------------------|---------| -|Accelerometer X|200| -|Accelerometer Y|134| -|Accelerometer Z|150| - -This is also the most expensive in memory terms, and would take the longest to read. But it's the simplest for development and debugging. - -You could also combine readings into a single characteristic, when a given sensor or actuator has multiple values associated with it. - -|**Characteristic**|**Value**| -|------------------|---------| -|Motor Speed, Direction|150,1| -|Accelerometer X, Y, Z|200,133,150| - -This is more efficient, but you need to be careful not to exceed the 512-byte limit. The accelerometer characteristic above, for example, takes 11 bytes as an ASCII-encoded string. - -## Read/write/notify/indicate - -There are 4 things a central device can do with a characteristic: - -- **Read:** ask the peripheral to send back the current value of the characteristic. Often used for characteristics that don't change very often, for example characteristics used for configuration, version numbers, etc. -- **Write:** modify the value of the characteristic. Often used for things that are like commands, for example telling the peripheral to turn a motor on or off. -- **Indicate** and **Notify:** ask the peripheral to continuously send updated values of the characteristic, without the central having to constantly ask for it. - -## Advertising and GAP - -BLE devices let other devices know that they exist by advertising using the **General Advertising Profile (GAP)**. Advertising packets can contain a device name, some other information, and also a list of the services it provides. - -Advertising packets have a limited size. You will only be able to fit a single 128-bit service UUID in the packet. Make sure the device name is not too long, or you won't even be able to fit that. - -You can provide additional services that are not advertised. Central devices will learn about these through the connection/bonding process. Non-advertised services cannot be used to discover devices, though. Sometimes this is not an issue. For example, you may have a custom peripheral device with a custom service, but in your central device app you may know that it also provides the Battery Service and other services. - -## GATT - -The Bluetooth LE protocol operates on multiple layers. **General Attribute Profile (GATT)** is the layer that defines services and characteristics and enables read/write/notify/indicate operations on them. When reading more about GATT, you may encounter GATT concepts of a "server" and "client". These don't always correspond to central and peripherals. In most cases, though, the peripheral is the GATT server (since it provides the services and characteristics), while the central is the GATT client. - -## Library structure - -As the library enables multiple types of functionality, there are a number of different classes. - -- `BLE` used to enable the Bluetooth® Low Energy module. -- `BLEDevice` used to get information about the devices connected or discovered while scanning. -- `BLEService` used to enable the services board provides or interact with services a remote board provides. -- `BLECharacteristic` used to enable the characteristics board offers in a service or interact with characteristics a remote board provides. -- `BLEDescriptor` used to describe a characteristic the board offers. diff --git a/examples/Central/LedControl/LedControl.ino b/examples/Central/LedControl/LedControl.ino index 953de7d8..064bb29e 100644 --- a/examples/Central/LedControl/LedControl.ino +++ b/examples/Central/LedControl/LedControl.ino @@ -6,9 +6,7 @@ it will remotely control the Bluetooth® Low Energy peripheral's LED, when the button is pressed or released. The circuit: - - Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT, - Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board. - - Button with pull-up resistor connected to pin 2. + - Board with supported BLE modules. You can use it with another board that is compatible with this library and the Peripherals -> LED example. @@ -16,7 +14,7 @@ This example code is in the public domain. */ -#include <ArduinoBLE.h> +#include <STM32duinoBLE.h> // variables for button const int buttonPin = 2; diff --git a/examples/Central/PeripheralExplorer/PeripheralExplorer.ino b/examples/Central/PeripheralExplorer/PeripheralExplorer.ino index 919cdde0..4a72a697 100644 --- a/examples/Central/PeripheralExplorer/PeripheralExplorer.ino +++ b/examples/Central/PeripheralExplorer/PeripheralExplorer.ino @@ -5,8 +5,7 @@ is found. Then connects, and discovers + prints all the peripheral's attributes. The circuit: - - Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT, - Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board. + - Board with supported BLE modules. You can use it with another board that is compatible with this library and the Peripherals -> LED example. @@ -14,7 +13,7 @@ This example code is in the public domain. */ -#include <ArduinoBLE.h> +#include <STM32duinoBLE.h> void setup() { Serial.begin(9600); diff --git a/examples/Central/Scan/Scan.ino b/examples/Central/Scan/Scan.ino index 162e3c07..99e13696 100644 --- a/examples/Central/Scan/Scan.ino +++ b/examples/Central/Scan/Scan.ino @@ -5,13 +5,12 @@ address, local name, advertised service UUID's. The circuit: - - Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT, - Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board. + - Board with supported BLE modules. This example code is in the public domain. */ -#include <ArduinoBLE.h> +#include <STM32duinoBLE.h> void setup() { Serial.begin(9600); diff --git a/examples/Central/ScanCallback/ScanCallback.ino b/examples/Central/ScanCallback/ScanCallback.ino index 2687a3b9..63ab2753 100644 --- a/examples/Central/ScanCallback/ScanCallback.ino +++ b/examples/Central/ScanCallback/ScanCallback.ino @@ -7,13 +7,12 @@ reported for every single advertisement it makes. The circuit: - - Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT, - Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board. + - Board with supported BLE modules. This example code is in the public domain. */ -#include <ArduinoBLE.h> +#include <STM32duinoBLE.h> void setup() { Serial.begin(9600); diff --git a/examples/Central/SensorTagButton/SensorTagButton.ino b/examples/Central/SensorTagButton/SensorTagButton.ino index 27c421fe..26ee667d 100644 --- a/examples/Central/SensorTagButton/SensorTagButton.ino +++ b/examples/Central/SensorTagButton/SensorTagButton.ino @@ -8,14 +8,13 @@ outputted to the Serial Monitor when one is pressed. The circuit: - - Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT, - Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board. + - Board with supported BLE modules. - TI SensorTag This example code is in the public domain. */ -#include <ArduinoBLE.h> +#include <STM32duinoBLE.h> void setup() { Serial.begin(9600); diff --git a/examples/Peripheral/Advertising/EnhancedAdvertising/EnhancedAdvertising.ino b/examples/Peripheral/Advertising/EnhancedAdvertising/EnhancedAdvertising.ino index 979b69a8..806c41bd 100644 --- a/examples/Peripheral/Advertising/EnhancedAdvertising/EnhancedAdvertising.ino +++ b/examples/Peripheral/Advertising/EnhancedAdvertising/EnhancedAdvertising.ino @@ -1,4 +1,4 @@ -#include <ArduinoBLE.h> +#include <STM32duinoBLE.h> BLEService myService("fff0"); BLEIntCharacteristic myCharacteristic("fff1", BLERead | BLEBroadcast); diff --git a/examples/Peripheral/Advertising/RawDataAdvertising/RawDataAdvertising.ino b/examples/Peripheral/Advertising/RawDataAdvertising/RawDataAdvertising.ino index 5e7ba7f3..88b17e29 100644 --- a/examples/Peripheral/Advertising/RawDataAdvertising/RawDataAdvertising.ino +++ b/examples/Peripheral/Advertising/RawDataAdvertising/RawDataAdvertising.ino @@ -1,4 +1,4 @@ -#include <ArduinoBLE.h> +#include <STM32duinoBLE.h> BLEService myService("fff0"); BLEIntCharacteristic myCharacteristic("fff1", BLERead | BLEBroadcast); diff --git a/examples/Peripheral/BatteryMonitor/BatteryMonitor.ino b/examples/Peripheral/BatteryMonitor/BatteryMonitor.ino index 0d786627..3413127e 100644 --- a/examples/Peripheral/BatteryMonitor/BatteryMonitor.ino +++ b/examples/Peripheral/BatteryMonitor/BatteryMonitor.ino @@ -5,8 +5,7 @@ level characteristic. The A0 pin is used to calculate the battery level. The circuit: - - Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT, - Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board. + - Board with supported BLE modules. You can use a generic Bluetooth® Low Energy central app, like LightBlue (iOS and Android) or nRF Connect (Android), to interact with the services and characteristics @@ -15,7 +14,7 @@ This example code is in the public domain. */ -#include <ArduinoBLE.h> +#include <STM32duinoBLE.h> // Bluetooth® Low Energy Battery Service BLEService batteryService("180F"); diff --git a/examples/Peripheral/ButtonLED/ButtonLED.ino b/examples/Peripheral/ButtonLED/ButtonLED.ino index cbc14dd8..baa64b87 100644 --- a/examples/Peripheral/ButtonLED/ButtonLED.ino +++ b/examples/Peripheral/ButtonLED/ButtonLED.ino @@ -6,9 +6,7 @@ represents the state of the button. The circuit: - - Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT, - Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board. - - Button connected to pin 4 + - Board with supported BLE modules. You can use a generic Bluetooth® Low Energy central app, like LightBlue (iOS and Android) or nRF Connect (Android), to interact with the services and characteristics @@ -17,7 +15,7 @@ This example code is in the public domain. */ -#include <ArduinoBLE.h> +#include <STM32duinoBLE.h> const int ledPin = LED_BUILTIN; // set ledPin to on-board LED const int buttonPin = 4; // set buttonPin to digital pin 4 diff --git a/examples/Peripheral/CallbackLED/CallbackLED.ino b/examples/Peripheral/CallbackLED/CallbackLED.ino index 59bda5ed..8bb90106 100644 --- a/examples/Peripheral/CallbackLED/CallbackLED.ino +++ b/examples/Peripheral/CallbackLED/CallbackLED.ino @@ -6,8 +6,7 @@ library are used. The circuit: - - Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT, - Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board. + - Board with supported BLE modules. You can use a generic Bluetooth® Low Energy central app, like LightBlue (iOS and Android) or nRF Connect (Android), to interact with the services and characteristics @@ -16,7 +15,7 @@ This example code is in the public domain. */ -#include <ArduinoBLE.h> +#include <STM32duinoBLE.h> BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // create service diff --git a/examples/Peripheral/EncryptedBatteryMonitor/EncryptedBatteryMonitor.ino b/examples/Peripheral/EncryptedBatteryMonitor/EncryptedBatteryMonitor.ino deleted file mode 100644 index dfc9f4a0..00000000 --- a/examples/Peripheral/EncryptedBatteryMonitor/EncryptedBatteryMonitor.ino +++ /dev/null @@ -1,265 +0,0 @@ -/* - Battery Monitor - - This example creates a BLE peripheral with the standard battery service and - level characteristic. The A0 pin is used to calculate the battery level. - - The circuit: - - Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT, - Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board. - - You can use a generic BLE central app, like LightBlue (iOS and Android) or - nRF Connect (Android), to interact with the services and characteristics - created in this sketch. - - This example code is in the public domain. -*/ - -#include <ArduinoBLE.h> - - -#define PAIR_BUTTON 3 // button for pairing -#define PAIR_LED 24 // LED used to signal pairing -#define PAIR_LED_ON LOW // Blue LED on Nano BLE has inverted logic -#define PAIR_INTERVAL 30000 // interval for pairing after button press in ms - -#define CTRL_LED LED_BUILTIN - - - // BLE Battery Service -BLEService batteryService("180F"); - -// BLE Battery Level Characteristic -BLEUnsignedCharCharacteristic batteryLevelChar("2A19", // standard 16-bit characteristic UUID - BLERead | BLENotify); // remote clients will be able to get notifications if this characteristic changes -BLEStringCharacteristic stringcharacteristic("183E", BLERead | BLEWrite, 31); - - -// Add BLEEncryption tag to require pairing. This controls the LED. -BLEUnsignedCharCharacteristic secretValue("2a3F", BLERead | BLEWrite | BLEEncryption); - -int oldBatteryLevel = 0; // last battery level reading from analog input -unsigned long previousMillis = 0; // last time the battery level was checked, in ms -unsigned long pairingStarted = 0; // pairing start time when button is pressed -bool wasConnected = 0; -bool acceptOrReject = true; - -void setup() { - Serial.begin(9600); // initialize serial communication - while (!Serial); - - pinMode(CTRL_LED, OUTPUT); // initialize the built-in LED pin to indicate when a central is connected - pinMode(PAIR_LED, OUTPUT); - pinMode(PAIR_BUTTON, INPUT_PULLUP); - - - Serial.println("Serial connected"); - - // Callback function with confirmation code when new device is pairing. - BLE.setDisplayCode([](uint32_t confirmCode){ - Serial.println("New device pairing request."); - Serial.print("Confirm code matches pairing device: "); - char code[6]; - sprintf(code, "%06d", confirmCode); - Serial.println(code); - }); - - // Callback to allow accepting or rejecting pairing - BLE.setBinaryConfirmPairing([&acceptOrReject](){ - Serial.print("Should we confirm pairing? "); - delay(5000); - if(acceptOrReject){ - acceptOrReject = false; - Serial.println("yes"); - return true; - }else{ - acceptOrReject = true; - Serial.println("no"); - return false; - } - }); - - // IRKs are keys that identify the true owner of a random mac address. - // Add IRKs of devices you are bonded with. - BLE.setGetIRKs([](uint8_t* nIRKs, uint8_t** BDaddrTypes, uint8_t*** BDAddrs, uint8_t*** IRKs){ - // Set to number of devices - *nIRKs = 2; - - *BDAddrs = new uint8_t*[*nIRKs]; - *IRKs = new uint8_t*[*nIRKs]; - *BDaddrTypes = new uint8_t[*nIRKs]; - - // Set these to the mac and IRK for your bonded devices as printed in the serial console after bonding. - uint8_t device1Mac[6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - uint8_t device1IRK[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - - uint8_t device2Mac[6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - uint8_t device2IRK[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - - - (*BDaddrTypes)[0] = 0; // Type 0 is for pubc address, type 1 is for static random - (*BDAddrs)[0] = new uint8_t[6]; - (*IRKs)[0] = new uint8_t[16]; - memcpy((*IRKs)[0] , device1IRK,16); - memcpy((*BDAddrs)[0], device1Mac, 6); - - - (*BDaddrTypes)[1] = 0; - (*BDAddrs)[1] = new uint8_t[6]; - (*IRKs)[1] = new uint8_t[16]; - memcpy((*IRKs)[1] , device2IRK,16); - memcpy((*BDAddrs)[1], device2Mac, 6); - - - return 1; - }); - // The LTK is the secret key which is used to encrypt bluetooth traffic - BLE.setGetLTK([](uint8_t* address, uint8_t* LTK){ - // address is input - Serial.print("Received request for address: "); - btct.printBytes(address,6); - - // Set these to the MAC and LTK of your devices after bonding. - uint8_t device1Mac[6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - uint8_t device1LTK[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - uint8_t device2Mac[6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - uint8_t device2LTK[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - - - if(memcmp(device1Mac, address, 6) == 0) { - memcpy(LTK, device1LTK, 16); - return 1; - }else if(memcmp(device2Mac, address, 6) == 0) { - memcpy(LTK, device2LTK, 16); - return 1; - } - return 0; - }); - BLE.setStoreIRK([](uint8_t* address, uint8_t* IRK){ - Serial.print(F("New device with MAC : ")); - btct.printBytes(address,6); - Serial.print(F("Need to store IRK : ")); - btct.printBytes(IRK,16); - return 1; - }); - BLE.setStoreLTK([](uint8_t* address, uint8_t* LTK){ - Serial.print(F("New device with MAC : ")); - btct.printBytes(address,6); - Serial.print(F("Need to store LTK : ")); - btct.printBytes(LTK,16); - return 1; - }); - - while(1){ - // begin initialization - if (!BLE.begin()) { - Serial.println("starting BLE failed!"); - delay(200); - continue; - } - Serial.println("BT init"); - delay(200); - - /* Set a local name for the BLE device - This name will appear in advertising packets - and can be used by remote devices to identify this BLE device - The name can be changed but maybe be truncated based on space left in advertisement packet - */ - - BLE.setDeviceName("Arduino"); - BLE.setLocalName("BatteryMonitor"); - - BLE.setAdvertisedService(batteryService); // add the service UUID - batteryService.addCharacteristic(batteryLevelChar); // add the battery level characteristic - batteryService.addCharacteristic(stringcharacteristic); - batteryService.addCharacteristic(secretValue); - - BLE.addService(batteryService); // Add the battery service - batteryLevelChar.writeValue(oldBatteryLevel); // set initial value for this characteristic - char* stringCharValue = new char[32]; - stringCharValue = "string"; - stringcharacteristic.writeValue(stringCharValue); - secretValue.writeValue(0); - - delay(1000); - - // prevent pairing until button is pressed (will show a pairing rejected message) - BLE.setPairable(false); - - /* Start advertising BLE. It will start continuously transmitting BLE - advertising packets and will be visible to remote BLE central devices - until it receives a new connection */ - - // start advertising - if(!BLE.advertise()){ - Serial.println("failed to advertise bluetooth."); - BLE.stopAdvertise(); - delay(500); - }else{ - Serial.println("advertising..."); - break; - } - BLE.end(); - delay(100); - } -} - - -void loop() { - // wait for a BLE central - BLEDevice central = BLE.central(); - - - // If button is pressed, allow pairing for 30 sec - if (!BLE.pairable() && digitalRead(PAIR_BUTTON) == LOW){ - pairingStarted = millis(); - BLE.setPairable(Pairable::ONCE); - Serial.println("Accepting pairing for 30 s"); - } else if (BLE.pairable() && millis() > pairingStarted + PAIR_INTERVAL){ - BLE.setPairable(false); - Serial.println("No longer accepting pairing"); - } - // Make LED blink while pairing is allowed - digitalWrite(PAIR_LED, (BLE.pairable() ? (millis()%400)<200 : BLE.paired()) ? PAIR_LED_ON : !PAIR_LED_ON); - - - // if a central is connected to the peripheral: - if (central && central.connected()) { - if (!wasConnected){ - wasConnected = true; - Serial.print("Connected to central: "); - // print the central's BT address: - Serial.println(central.address()); - } - - // check the battery level every 200ms - // while the central is connected: - long currentMillis = millis(); - // if 200ms have passed, check the battery level: - if (currentMillis - previousMillis >= 1000) { - previousMillis = currentMillis; - updateBatteryLevel(); - digitalWrite(CTRL_LED, secretValue.value()>0 ? HIGH : LOW); - } - } else if (wasConnected){ - wasConnected = false; - Serial.print("Disconnected from central: "); - Serial.println(central.address()); - } - -} - -void updateBatteryLevel() { - /* Read the current voltage level on the A0 analog input pin. - This is used here to simulate the charge level of a battery. - */ - int battery = analogRead(A0); - int batteryLevel = map(battery, 0, 1023, 0, 100); - - if (batteryLevel != oldBatteryLevel) { // if the battery level has changed - // Serial.print("Battery Level % is now: "); // print it - // Serial.println(batteryLevel); - batteryLevelChar.writeValue(batteryLevel); // and update the battery level characteristic - oldBatteryLevel = batteryLevel; // save the level for next comparison - } -} \ No newline at end of file diff --git a/examples/Peripheral/LED/LED.ino b/examples/Peripheral/LED/LED.ino index 65b88605..7223365f 100644 --- a/examples/Peripheral/LED/LED.ino +++ b/examples/Peripheral/LED/LED.ino @@ -5,8 +5,7 @@ characteristic to control an LED. The circuit: - - Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT, - Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board. + - Board with supported BLE modules. You can use a generic Bluetooth® Low Energy central app, like LightBlue (iOS and Android) or nRF Connect (Android), to interact with the services and characteristics @@ -15,7 +14,7 @@ This example code is in the public domain. */ -#include <ArduinoBLE.h> +#include <STM32duinoBLE.h> BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // Bluetooth® Low Energy LED Service diff --git a/extras/arduino-ble-parser.py b/extras/arduino-ble-parser.py deleted file mode 100644 index 8f678711..00000000 --- a/extras/arduino-ble-parser.py +++ /dev/null @@ -1,85 +0,0 @@ -''' -Convert ArduinoBLE debug files into Btsnoop files ready to be analyzed using wireshark or hcidump -Btsnoop file format reference - https://www.fte.com/WebHelpII/Sodera/Content/Technical_Information/BT_Snoop_File_Format.htm -''' - -import os -import argparse - -DEBUG = False - -parser = argparse.ArgumentParser() -parser.add_argument('-i', dest='inputPath', type=str, required=True, help='input file containing debug log') -parser.add_argument('-o', dest='outputPath', type=str, required=True, help='result file that will contain the btsnoop encoded debug file') -args = parser.parse_args() - -# Extract only hci debug messages -def extractHCIDebugPrint(inputPath, outputPath): - inputFile = open(inputPath, 'r') - outputFile = open(outputPath, 'w') - for inputLine in inputFile: - lineItems = inputLine.split() - if (len(lineItems) < 7) or (lineItems[1] != "->") or (lineItems[2] != "HCI"): - if (len(lineItems) < 4) or (lineItems[0] != "HCI") or ((lineItems[3] != "<-") and (lineItems[3] != "->")): - continue - outputFile.write(inputLine) - outputFile.close() - -# Return packet in btsnoop format -def buildBinaryPacket(hciMessage, hciDirection, hciType): - commandFlag = 1 if (hciType == "COMMAND" or hciType == "EVENT") else 0 - directionFlag = 0 if (hciDirection == "TX") else 1 - flagHex = ("0" * 7) + str((commandFlag * 2) + directionFlag) - timestampHex = "0" * 16 - packetDropHex = "0" * 8 - dataLengthHex = format( (int(len(hciMessage) / 2)), 'x') - packetLengthHex = ("0" * (8 - len(dataLengthHex))) + dataLengthHex - binaryPacket = bytearray.fromhex(packetLengthHex + packetLengthHex + flagHex + packetDropHex + timestampHex + hciMessage) - if DEBUG: - print(len(hciMessage)) - print(dataLengthHex) - print(packetLengthHex) - print(flagHex) - print('\n') - return binaryPacket - -def buildBinaryHeader(): - defaultHeader = "6274736e6f6f700000000001000003ea" - binaryHeader = bytearray.fromhex(defaultHeader) - return binaryHeader - -def convertToBtsnoop(inputPath, outputPath): - # Open output file and write the Btsnoop header - outputFile = open(outputPath,'wb') - header = buildBinaryHeader() - outputFile.write(header) - - # Open input file containing HCI debug packets - inputFile = open(inputPath, 'r') - for inputLine in inputFile: - lineItems = inputLine.split() - # For a safer script, do not use indexes but look for symbols in the line - baseIndex = lineItems.index("HCI") - hciMessage = lineItems[baseIndex + 4] - hciDirection = lineItems[baseIndex + 2] - hciType = lineItems[baseIndex + 1] - # Build and write the encoded line - btsnoopPacket = buildBinaryPacket(hciMessage, hciDirection, hciType) - outputFile.write(btsnoopPacket) - if DEBUG: - print(hciDirection) - print(hciMessage) - print(hciType) - print('\n') - outputFile.close() - -inputPath = args.inputPath -outputPath = args.outputPath -tempFile = "temp-debug-print.txt" -# Run -extractHCIDebugPrint(inputPath,tempFile) -convertToBtsnoop(tempFile, outputPath) -# Delete temp file -os.remove(tempFile) - diff --git a/extras/test/.gitignore b/extras/test/.gitignore deleted file mode 100644 index 7e9215ee..00000000 --- a/extras/test/.gitignore +++ /dev/null @@ -1,17 +0,0 @@ -build -### CMake ### -CMakeLists.txt.user -CMakeCache.txt -CMakeFiles -CMakeScripts -Testing -Makefile -cmake_install.cmake -install_manifest.txt -compile_commands.json -CTestTestfile.cmake -_deps - -### CMake Patch ### -# External projects -*-prefix/ \ No newline at end of file diff --git a/extras/test/CMakeLists.txt b/extras/test/CMakeLists.txt deleted file mode 100644 index 5e66e18b..00000000 --- a/extras/test/CMakeLists.txt +++ /dev/null @@ -1,164 +0,0 @@ -########################################################################## - -set(CMAKE_VERBOSE_MAKEFILE ON) -cmake_minimum_required(VERSION 3.5) - -########################################################################## - -project(testArduinoBLE) - -Include(FetchContent) - -FetchContent_Declare( - Catch2 - GIT_REPOSITORY https://github.com/catchorg/Catch2.git - GIT_TAG v3.4.0 -) - -FetchContent_MakeAvailable(Catch2) - -########################################################################## - -set(CMAKE_CXX_STANDARD 11) -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) - -########################################################################## - -set(COMMON_TEST_SRCS - src/test_main.cpp - src/Arduino.cpp - src/util/itoa.c - src/util/TestUtil.cpp - src/util/String.cpp - src/util/Common.cpp -) - -set(DUT_SRCS - ../../src/utility/BLEUuid.cpp - ../../src/BLEDevice.cpp - ../../src/BLECharacteristic.cpp - ../../src/BLEDescriptor.cpp - ../../src/BLEService.cpp - ../../src/BLEAdvertisingData.cpp - ../../src/utility/ATT.cpp - ../../src/utility/GAP.cpp - ../../src/utility/HCI.cpp - ../../src/utility/GATT.cpp - ../../src/utility/L2CAPSignaling.cpp - ../../src/utility/keyDistribution.cpp - ../../src/utility/bitDescriptions.cpp - ../../src/utility/btct.cpp - ../../src/local/BLELocalAttribute.cpp - ../../src/local/BLELocalCharacteristic.cpp - ../../src/local/BLELocalDescriptor.cpp - ../../src/local/BLELocalDevice.cpp - ../../src/local/BLELocalService.cpp - ../../src/remote/BLERemoteAttribute.cpp - ../../src/remote/BLERemoteCharacteristic.cpp - ../../src/remote/BLERemoteDescriptor.cpp - ../../src/remote/BLERemoteDevice.cpp - ../../src/remote/BLERemoteService.cpp - ../../src/BLEStringCharacteristic.cpp - ../../src/BLETypedCharacteristics.cpp -) - -set(TEST_TARGET_UUID_SRCS - # Test files - ${COMMON_TEST_SRCS} - src/test_uuid/test_uuid.cpp - # DUT files - #${DUT_SRCS} - ../../src/utility/BLEUuid.cpp -) - -set(TEST_TARGET_DISC_DEVICE_SRCS - # Test files - ${COMMON_TEST_SRCS} - src/test_discovered_device/test_discovered_device.cpp - # DUT files - ${DUT_SRCS} - # Fake classes files - src/util/HCIFakeTransport.cpp - src/test_discovered_device/FakeGAP.cpp -) - -set(TEST_TARGET_ADVERTISING_DATA_SRCS - # Test files - ${COMMON_TEST_SRCS} - src/test_advertising_data/test_advertising_data.cpp - src/test_advertising_data/test_service.cpp - src/test_advertising_data/test_local_name.cpp - src/test_advertising_data/test_manufacturer.cpp - # DUT files - ${DUT_SRCS} - # Fake classes files - src/util/HCIFakeTransport.cpp - src/test_advertising_data/FakeBLELocalDevice.cpp -) - -set(TEST_TARGET_CHARACTERISTIC_SRCS - # Test files - ${COMMON_TEST_SRCS} - src/test_characteristic/test_permissions.cpp - src/test_characteristic/test_writeValue.cpp - # DUT files - ${DUT_SRCS} - # Fake classes files - src/util/HCIFakeTransport.cpp - src/test_advertising_data/FakeBLELocalDevice.cpp -) - -########################################################################## - -set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} "--coverage") -set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "--coverage") - -########################################################################## - -add_executable(TEST_TARGET_UUID ${TEST_TARGET_UUID_SRCS}) -add_executable(TEST_TARGET_DISC_DEVICE ${TEST_TARGET_DISC_DEVICE_SRCS}) -add_executable(TEST_TARGET_ADVERTISING_DATA ${TEST_TARGET_ADVERTISING_DATA_SRCS}) -add_executable(TEST_TARGET_CHARACTERISTIC_DATA ${TEST_TARGET_CHARACTERISTIC_SRCS}) - -########################################################################## - -include_directories(include) -include_directories(include/util) -include_directories(../../src) -include_directories(../../src/local) -include_directories(../../src/remote) -include_directories(../../src/utility) - -target_include_directories(TEST_TARGET_DISC_DEVICE PUBLIC include/test_discovered_device) -target_include_directories(TEST_TARGET_ADVERTISING_DATA PUBLIC include/test_advertising_data) -target_include_directories(TEST_TARGET_CHARACTERISTIC_DATA PUBLIC include/test_advertising_data) - -########################################################################## - -target_compile_definitions(TEST_TARGET_DISC_DEVICE PUBLIC FAKE_GAP) -target_compile_definitions(TEST_TARGET_ADVERTISING_DATA PUBLIC FAKE_BLELOCALDEVICE) -target_compile_definitions(TEST_TARGET_CHARACTERISTIC_DATA PUBLIC FAKE_BLELOCALDEVICE) - -########################################################################## - -# Build unit tests as a post build step -add_custom_command(TARGET TEST_TARGET_UUID POST_BUILD - COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/TEST_TARGET_UUID -) -add_custom_command(TARGET TEST_TARGET_DISC_DEVICE POST_BUILD - COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/TEST_TARGET_DISC_DEVICE -) -add_custom_command(TARGET TEST_TARGET_ADVERTISING_DATA POST_BUILD - COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/TEST_TARGET_ADVERTISING_DATA -) - -add_custom_command(TARGET TEST_TARGET_CHARACTERISTIC_DATA POST_BUILD - COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/TEST_TARGET_CHARACTERISTIC_DATA -) - -########################################################################## - -target_link_libraries( TEST_TARGET_UUID Catch2WithMain ) -target_link_libraries( TEST_TARGET_DISC_DEVICE Catch2WithMain ) -target_link_libraries( TEST_TARGET_ADVERTISING_DATA Catch2WithMain ) -target_link_libraries( TEST_TARGET_CHARACTERISTIC_DATA Catch2WithMain ) diff --git a/extras/test/include/Arduino.h b/extras/test/include/Arduino.h deleted file mode 100644 index 38f45554..00000000 --- a/extras/test/include/Arduino.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - This file is part of the ArduinoBLE library. - Copyright (c) 2018 Arduino SA. All rights reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#ifndef TEST_ARDUINO_H_ -#define TEST_ARDUINO_H_ - -/****************************************************************************** - INCLUDE - ******************************************************************************/ - -#include <stdio.h> -#include <stdlib.h> -#include "String.h" -#include "Stream.h" -#include "itoa.h" -#include "Common.h" - -/****************************************************************************** - TYPEDEF - ******************************************************************************/ - -typedef arduino::String String; -typedef bool boolean; - -#if defined(__cplusplus) - -#undef F -// C++11 F replacement declaration -template <typename T1> -auto F(T1&& A) - -> const arduino::__FlashStringHelper* -{ - return (const arduino::__FlashStringHelper*)A; -} - -#endif - -/****************************************************************************** - FUNCTION PROTOTYPES - ******************************************************************************/ - -#endif /* TEST_ARDUINO_H_ */ diff --git a/extras/test/include/test_advertising_data/FakeBLELocalDevice.h b/extras/test/include/test_advertising_data/FakeBLELocalDevice.h deleted file mode 100644 index 94e97730..00000000 --- a/extras/test/include/test_advertising_data/FakeBLELocalDevice.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - This file is part of the ArduinoBLE library. - Copyright (c) 2018 Arduino SA. All rights reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#ifndef _FAKE_BLELOCALDEVICE_H_ -#define _FAKE_BLELOCALDEVICE_H_ - -#define private public -#define protected public -#include "BLELocalDevice.h" - -class FakeBLELocalDevice : public BLELocalDevice { - public: - FakeBLELocalDevice(); - virtual ~FakeBLELocalDevice(); - - int advertise(); -}; - -#endif diff --git a/extras/test/include/test_discovered_device/FakeGAP.h b/extras/test/include/test_discovered_device/FakeGAP.h deleted file mode 100644 index 35b3233b..00000000 --- a/extras/test/include/test_discovered_device/FakeGAP.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - This file is part of the ArduinoBLE library. - Copyright (c) 2018 Arduino SA. All rights reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#ifndef _FAKE_GAP_H_ -#define _FAKE_GAP_H_ - -#define private public -#define protected public -#include "GAP.h" - -class FakeGAPClass : public GAPClass { - public: - FakeGAPClass(); - virtual ~FakeGAPClass(); -}; - -#endif diff --git a/extras/test/include/util/Common.h b/extras/test/include/util/Common.h deleted file mode 100644 index 8d288e18..00000000 --- a/extras/test/include/util/Common.h +++ /dev/null @@ -1,167 +0,0 @@ -#pragma once -#include <stdint.h> - -#ifdef __cplusplus -extern "C"{ -#endif - -void yield(void); - -typedef enum { - LOW = 0, - HIGH = 1, - CHANGE = 2, - FALLING = 3, - RISING = 4, -} PinStatus; - -typedef enum { - INPUT = 0x0, - OUTPUT = 0x1, - INPUT_PULLUP = 0x2, - INPUT_PULLDOWN = 0x3, -} PinMode; - -typedef enum { - LSBFIRST = 0, - MSBFIRST = 1, -} BitOrder; - -#define PI 3.1415926535897932384626433832795 -#define HALF_PI 1.5707963267948966192313216916398 -#define TWO_PI 6.283185307179586476925286766559 -#define DEG_TO_RAD 0.017453292519943295769236907684886 -#define RAD_TO_DEG 57.295779513082320876798154814105 -#define EULER 2.718281828459045235360287471352 - -#define SERIAL 0x0 -#define DISPLAY 0x1 - -#ifndef constrain -#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt))) -#endif - -#ifndef radians -#define radians(deg) ((deg)*DEG_TO_RAD) -#endif - -#ifndef degrees -#define degrees(rad) ((rad)*RAD_TO_DEG) -#endif - -#ifndef sq -#define sq(x) ((x)*(x)) -#endif - -typedef void (*voidFuncPtr)(void); -typedef void (*voidFuncPtrParam)(void*); - -// interrupts() / noInterrupts() must be defined by the core - -#define lowByte(w) ((uint8_t) ((w) & 0xff)) -#define highByte(w) ((uint8_t) ((w) >> 8)) - -#define bitRead(value, bit) (((value) >> (bit)) & 0x01) -#define bitSet(value, bit) ((value) |= (1UL << (bit))) -#define bitClear(value, bit) ((value) &= ~(1UL << (bit))) -#define bitToggle(value, bit) ((value) ^= (1UL << (bit))) -#define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit)) - -#ifndef bit -#define bit(b) (1UL << (b)) -#endif - -/* TODO: request for removal */ -typedef bool boolean; -typedef uint8_t byte; -typedef uint16_t word; - -void init(void); -void initVariant(void); - -int atexit(void (*func)()) __attribute__((weak)); -int main() __attribute__((weak)); - -#ifdef EXTENDED_PIN_MODE -// Platforms who wnat to declare more than 256 pins need to define EXTENDED_PIN_MODE globally -typedef uint32_t pin_size_t; -#else -typedef uint8_t pin_size_t; -#endif - -void pinMode(pin_size_t pinNumber, PinMode pinMode); -void digitalWrite(pin_size_t pinNumber, PinStatus status); -PinStatus digitalRead(pin_size_t pinNumber); -int analogRead(pin_size_t pinNumber); -void analogReference(uint8_t mode); -void analogWrite(pin_size_t pinNumber, int value); - -unsigned long millis(void); -unsigned long micros(void); -void delay(unsigned long); -void delayMicroseconds(unsigned int us); -unsigned long pulseIn(pin_size_t pin, uint8_t state, unsigned long timeout); -unsigned long pulseInLong(pin_size_t pin, uint8_t state, unsigned long timeout); - -void shiftOut(pin_size_t dataPin, pin_size_t clockPin, BitOrder bitOrder, uint8_t val); -pin_size_t shiftIn(pin_size_t dataPin, pin_size_t clockPin, BitOrder bitOrder); - -void attachInterrupt(pin_size_t interruptNumber, voidFuncPtr callback, PinStatus mode); -void attachInterruptParam(pin_size_t interruptNumber, voidFuncPtrParam callback, PinStatus mode, void* param); -void detachInterrupt(pin_size_t interruptNumber); - -void setup(void); -void loop(void); - -#ifdef __cplusplus -} // extern "C" -#endif - -#ifdef __cplusplus - template<class T, class L> - auto min(const T& a, const L& b) -> decltype((b < a) ? b : a) - { - return (b < a) ? b : a; - } - - template<class T, class L> - auto max(const T& a, const L& b) -> decltype((b < a) ? b : a) - { - return (a < b) ? b : a; - } -#else -#ifndef min -#define min(a,b) \ - ({ __typeof__ (a) _a = (a); \ - __typeof__ (b) _b = (b); \ - _a < _b ? _a : _b; }) -#endif -#ifndef max -#define max(a,b) \ - ({ __typeof__ (a) _a = (a); \ - __typeof__ (b) _b = (b); \ - _a > _b ? _a : _b; }) -#endif -#endif - -#ifdef __cplusplus - -/* C++ prototypes */ -uint16_t makeWord(uint16_t w); -uint16_t makeWord(byte h, byte l); - -#define word(...) makeWord(__VA_ARGS__) - -unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L); -unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L); - -void tone(uint8_t _pin, unsigned int frequency, unsigned long duration = 0); -void noTone(uint8_t _pin); - -// WMath prototypes -long random(long); -long random(long, long); -void randomSeed(unsigned long); -long map(long, long, long, long, long); - -#endif // __cplusplus diff --git a/extras/test/include/util/HCIFakeTransport.h b/extras/test/include/util/HCIFakeTransport.h deleted file mode 100644 index 6c8ac08c..00000000 --- a/extras/test/include/util/HCIFakeTransport.h +++ /dev/null @@ -1,19 +0,0 @@ -//#include "Common.h" -#pragma once - -#include "HCITransport.h" - -class HCIFakeTransportClass : public HCITransportInterface -{ -public: - HCIFakeTransportClass() {}; - ~HCIFakeTransportClass() {}; - - int begin() {return 0;} - void end() {return;} - void wait(unsigned long timeout) {return;} - int available() {return 0;} - int peek() {return 0;} - int read() {return 0;} - size_t write(const uint8_t* data, size_t length) {return 0;} -}; \ No newline at end of file diff --git a/extras/test/include/util/Stream.h b/extras/test/include/util/Stream.h deleted file mode 100644 index f367e34c..00000000 --- a/extras/test/include/util/Stream.h +++ /dev/null @@ -1,40 +0,0 @@ -//#include "Common.h" -#pragma once - -#define DEC 10 -#define HEX 16 -#define OCT 8 -#define BIN 2 - -class Stream -{ -public: - Stream(const char *name = NULL); - ~Stream(); - - void flush() {} - - size_t print(const char[]) { return 0; } - size_t print(char) { return 0; } - size_t print(unsigned char, int) { return 0; } - size_t print(int, int) { return 0; } - size_t print(unsigned int, int) { return 0; } - size_t print(long, int) { return 0; } - size_t print(unsigned long, int) { return 0; } - size_t print(long long, int) { return 0; } - size_t print(unsigned long long, int) { return 0; } - size_t print(double, int) { return 0; } - size_t print(void) { return 0; } - - size_t println(const char[]) { return 0; } - size_t println(char) { return 0; } - size_t println(unsigned char, int) { return 0; } - size_t println(int, int) { return 0; } - size_t println(unsigned int, int) { return 0; } - size_t println(long, int) { return 0; } - size_t println(unsigned long, int) { return 0; } - size_t println(long long, int) { return 0; } - size_t println(unsigned long long, int) { return 0; } - size_t println(double, int) { return 0; } - size_t println(void) { return 0; } -}; diff --git a/extras/test/include/util/String.h b/extras/test/include/util/String.h deleted file mode 100644 index 3021a31e..00000000 --- a/extras/test/include/util/String.h +++ /dev/null @@ -1,248 +0,0 @@ -/* - String library for Wiring & Arduino - ...mostly rewritten by Paul Stoffregen... - Copyright (c) 2009-10 Hernando Barragan. All right reserved. - Copyright 2011, Paul Stoffregen, paul@pjrc.com - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#ifdef __cplusplus - -#ifndef __ARDUINO_STRINGS__ -#define __ARDUINO_STRINGS__ - -#include <stdlib.h> -#include <string.h> -#include <ctype.h> - -namespace arduino { - -// When compiling programs with this class, the following gcc parameters -// dramatically increase performance and memory (RAM) efficiency, typically -// with little or no increase in code size. -// -felide-constructors -// -std=c++0x - -class __FlashStringHelper; -#define F(string_literal) (reinterpret_cast<const __FlashStringHelper *>(PSTR(string_literal))) - -// An inherited class for holding the result of a concatenation. These -// result objects are assumed to be writable by subsequent concatenations. -class StringSumHelper; - -// The string class -class String -{ - friend class StringSumHelper; - // use a function pointer to allow for "if (s)" without the - // complications of an operator bool(). for more information, see: - // http://www.artima.com/cppsource/safebool.html - typedef void (String::*StringIfHelperType)() const; - void StringIfHelper() const {} - -public: - // constructors - // creates a copy of the initial value. - // if the initial value is null or invalid, or if memory allocation - // fails, the string will be marked as invalid (i.e. "if (s)" will - // be false). - String(const char *cstr = ""); - String(const String &str); - String(const __FlashStringHelper *str); - #if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) - String(String &&rval); - String(StringSumHelper &&rval); - #endif - explicit String(char c); - explicit String(unsigned char, unsigned char base=10); - explicit String(int, unsigned char base=10); - explicit String(unsigned int, unsigned char base=10); - explicit String(long, unsigned char base=10); - explicit String(unsigned long, unsigned char base=10); - //explicit String(float, unsigned char decimalPlaces=2); - //explicit String(double, unsigned char decimalPlaces=2); - ~String(void); - - // memory management - // return true on success, false on failure (in which case, the string - // is left unchanged). reserve(0), if successful, will validate an - // invalid string (i.e., "if (s)" will be true afterwards) - unsigned char reserve(unsigned int size); - inline unsigned int length(void) const {return len;} - - // creates a copy of the assigned value. if the value is null or - // invalid, or if the memory allocation fails, the string will be - // marked as invalid ("if (s)" will be false). - String & operator = (const String &rhs); - String & operator = (const char *cstr); - //String & operator = (const __FlashStringHelper *str); - #if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) - String & operator = (String &&rval); - String & operator = (StringSumHelper &&rval); - #endif - - // concatenate (works w/ built-in types) - - // returns true on success, false on failure (in which case, the string - // is left unchanged). if the argument is null or invalid, the - // concatenation is considered unsucessful. - unsigned char concat(const String &str); - unsigned char concat(const char *cstr); - unsigned char concat(char c); - unsigned char concat(unsigned char c); - unsigned char concat(int num); - unsigned char concat(unsigned int num); - unsigned char concat(long num); - unsigned char concat(unsigned long num); - unsigned char concat(float num); - //unsigned char concat(double num); - unsigned char concat(const __FlashStringHelper * str); - - // if there's not enough memory for the concatenated value, the string - // will be left unchanged (but this isn't signalled in any way) - String & operator += (const String &rhs) {concat(rhs); return (*this);} - String & operator += (const char *cstr) {concat(cstr); return (*this);} - String & operator += (char c) {concat(c); return (*this);} - String & operator += (unsigned char num) {concat(num); return (*this);} - String & operator += (int num) {concat(num); return (*this);} - String & operator += (unsigned int num) {concat(num); return (*this);} - String & operator += (long num) {concat(num); return (*this);} - String & operator += (unsigned long num) {concat(num); return (*this);} - String & operator += (float num) {concat(num); return (*this);} - //String & operator += (double num) {concat(num); return (*this);} - String & operator += (const __FlashStringHelper *str){concat(str); return (*this);} - - friend StringSumHelper & operator + (const StringSumHelper &lhs, const String &rhs); - friend StringSumHelper & operator + (const StringSumHelper &lhs, const char *cstr); - friend StringSumHelper & operator + (const StringSumHelper &lhs, char c); - friend StringSumHelper & operator + (const StringSumHelper &lhs, unsigned char num); - friend StringSumHelper & operator + (const StringSumHelper &lhs, int num); - friend StringSumHelper & operator + (const StringSumHelper &lhs, unsigned int num); - friend StringSumHelper & operator + (const StringSumHelper &lhs, long num); - friend StringSumHelper & operator + (const StringSumHelper &lhs, unsigned long num); - friend StringSumHelper & operator + (const StringSumHelper &lhs, float num); - //friend StringSumHelper & operator + (const StringSumHelper &lhs, double num); - //friend StringSumHelper & operator + (const StringSumHelper &lhs, const __FlashStringHelper *rhs); - - // comparison (only works w/ Strings and "strings") - operator StringIfHelperType() const { return buffer ? &String::StringIfHelper : 0; } - int compareTo(const String &s) const; - int compareTo(const char *cstr) const; - unsigned char equals(const String &s) const; - unsigned char equals(const char *cstr) const; - - friend unsigned char operator == (const String &a, const String &b) { return a.equals(b); } - friend unsigned char operator == (const String &a, const char *b) { return a.equals(b); } - friend unsigned char operator == (const char *a, const String &b) { return b == a; } - friend unsigned char operator < (const String &a, const String &b) { return a.compareTo(b) < 0; } - friend unsigned char operator < (const String &a, const char *b) { return a.compareTo(b) < 0; } - friend unsigned char operator < (const char *a, const String &b) { return b.compareTo(a) > 0; } - - friend unsigned char operator != (const String &a, const String &b) { return !(a == b); } - friend unsigned char operator != (const String &a, const char *b) { return !(a == b); } - friend unsigned char operator != (const char *a, const String &b) { return !(a == b); } - friend unsigned char operator > (const String &a, const String &b) { return b < a; } - friend unsigned char operator > (const String &a, const char *b) { return b < a; } - friend unsigned char operator > (const char *a, const String &b) { return b < a; } - friend unsigned char operator <= (const String &a, const String &b) { return !(b < a); } - friend unsigned char operator <= (const String &a, const char *b) { return !(b < a); } - friend unsigned char operator <= (const char *a, const String &b) { return !(b < a); } - friend unsigned char operator >= (const String &a, const String &b) { return !(a < b); } - friend unsigned char operator >= (const String &a, const char *b) { return !(a < b); } - friend unsigned char operator >= (const char *a, const String &b) { return !(a < b); } - - unsigned char equalsIgnoreCase(const String &s) const; - unsigned char startsWith( const String &prefix) const; - unsigned char startsWith(const String &prefix, unsigned int offset) const; - unsigned char endsWith(const String &suffix) const; - - // character acccess - char charAt(unsigned int index) const; - void setCharAt(unsigned int index, char c); - char operator [] (unsigned int index) const; - char& operator [] (unsigned int index); - void getBytes(unsigned char *buf, unsigned int bufsize, unsigned int index=0) const; - void toCharArray(char *buf, unsigned int bufsize, unsigned int index=0) const - { getBytes((unsigned char *)buf, bufsize, index); } - const char* c_str() const { return buffer; } - char* begin() { return buffer; } - char* end() { return buffer + length(); } - const char* begin() const { return c_str(); } - const char* end() const { return c_str() + length(); } - - // search - int indexOf( char ch ) const; - int indexOf( char ch, unsigned int fromIndex ) const; - int indexOf( const String &str ) const; - int indexOf( const String &str, unsigned int fromIndex ) const; - int lastIndexOf( char ch ) const; - int lastIndexOf( char ch, unsigned int fromIndex ) const; - int lastIndexOf( const String &str ) const; - int lastIndexOf( const String &str, unsigned int fromIndex ) const; - String substring( unsigned int beginIndex ) const { return substring(beginIndex, len); }; - String substring( unsigned int beginIndex, unsigned int endIndex ) const; - - // modification - void replace(char find, char replace); - void replace(const String& find, const String& replace); - void remove(unsigned int index); - void remove(unsigned int index, unsigned int count); - void toLowerCase(void); - void toUpperCase(void); - void trim(void); - - // parsing/conversion - long toInt(void) const; - float toFloat(void) const; - double toDouble(void) const; - -protected: - char *buffer; // the actual char array - unsigned int capacity; // the array length minus one (for the '\0') - unsigned int len; // the String length (not counting the '\0') -protected: - void init(void); - void invalidate(void); - unsigned char changeBuffer(unsigned int maxStrLen); - unsigned char concat(const char *cstr, unsigned int length); - - // copy and move - String & copy(const char *cstr, unsigned int length); - String & copy(const __FlashStringHelper *pstr, unsigned int length); - #if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) - void move(String &rhs); - #endif -}; - -class StringSumHelper : public String -{ -public: - StringSumHelper(const String &s) : String(s) {} - StringSumHelper(const char *p) : String(p) {} - StringSumHelper(char c) : String(c) {} - StringSumHelper(unsigned char num) : String(num) {} - StringSumHelper(int num) : String(num) {} - StringSumHelper(unsigned int num) : String(num) {} - StringSumHelper(long num) : String(num) {} - StringSumHelper(unsigned long num) : String(num) {} - //StringSumHelper(float num) : String(num) {} - //StringSumHelper(double num) : String(num) {} -}; - -} // namespace arduino - -#endif // __cplusplus -#endif // __ARDUINO_STRINGS__ diff --git a/extras/test/include/util/TestUtil.h b/extras/test/include/util/TestUtil.h deleted file mode 100644 index 111607ec..00000000 --- a/extras/test/include/util/TestUtil.h +++ /dev/null @@ -1,3 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - */ diff --git a/extras/test/include/util/itoa.h b/extras/test/include/util/itoa.h deleted file mode 100644 index 55b28493..00000000 --- a/extras/test/include/util/itoa.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - Copyright (c) 2016 Arduino LLC. All right reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#pragma once - -// Standard C functions required in Arduino API -// If these functions are not provided by the standard library, the -// core should supply an implementation of them. - -#ifdef __cplusplus -extern "C" { -#endif - -extern char* itoa(int value, char *string, int radix); -extern char* ltoa(long value, char *string, int radix); -extern char* utoa(unsigned value, char *string, int radix); -extern char* ultoa(unsigned long value, char *string, int radix); - -#ifdef __cplusplus -} // extern "C" -#endif - diff --git a/extras/test/src/Arduino.cpp b/extras/test/src/Arduino.cpp deleted file mode 100644 index 6a6ab4e5..00000000 --- a/extras/test/src/Arduino.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/* - This file is part of the ArduinoBLE library. - Copyright (c) 2018 Arduino SA. All rights reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -/****************************************************************************** - INCLUDE - ******************************************************************************/ - -#include <Arduino.h> - -/****************************************************************************** - GLOBAL VARIABLES - ******************************************************************************/ - -static unsigned long current_millis = 0; - -/****************************************************************************** - PUBLIC FUNCTIONS - ******************************************************************************/ - -void set_millis(unsigned long const millis) -{ - current_millis = millis; -} - -unsigned long millis() -{ - return current_millis; -} diff --git a/extras/test/src/test_advertising_data/FakeBLELocalDevice.cpp b/extras/test/src/test_advertising_data/FakeBLELocalDevice.cpp deleted file mode 100644 index 7f5a71ad..00000000 --- a/extras/test/src/test_advertising_data/FakeBLELocalDevice.cpp +++ /dev/null @@ -1,40 +0,0 @@ -/* - This file is part of the ArduinoBLE library. - Copyright (c) 2018 Arduino SA. All rights reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#include "FakeBLELocalDevice.h" - -FakeBLELocalDevice::FakeBLELocalDevice() -{ - -} - -FakeBLELocalDevice::~FakeBLELocalDevice() -{ - -} - -int FakeBLELocalDevice::advertise() -{ - _advertisingData.updateData(); - _scanResponseData.updateData(); - return 1; -} - -FakeBLELocalDevice FakeBLEObj; -BLELocalDevice& BLE = FakeBLEObj; diff --git a/extras/test/src/test_advertising_data/test_advertising_data.cpp b/extras/test/src/test_advertising_data/test_advertising_data.cpp deleted file mode 100644 index 7f2e9cb8..00000000 --- a/extras/test/src/test_advertising_data/test_advertising_data.cpp +++ /dev/null @@ -1,204 +0,0 @@ -/* - This file is part of the ArduinoBLE library. - Copyright (c) 2018 Arduino SA. All rights reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#include <catch2/catch_test_macros.hpp> - -#define private public -#define protected public - -#include "FakeBLELocalDevice.h" -#include "BLEAdvertisingData.h" - -TEST_CASE("Test flags override", "[ArduinoBLE::BLEAdvertisingData]") -{ - // Mocking advertisement packet - BLEAdvertisingData advData; - // Expected results - const uint8_t defaultData[] = {0x02, BLEFieldFlags, 0x06}; - const uint8_t goldenFlags[] = {0x02, 0x01, BLEFlagsBREDRNotSupported}; - - WHEN("Default options for flags") - { - BLE.advertise(); - REQUIRE( 0 == (memcmp(defaultData, BLE.getAdvertisingData().data(), sizeof(defaultData))) ); - REQUIRE( BLE.getScanResponseData().dataLength() == 0 ); - } - - WHEN("Setting external advertising data which has flags") - { - advData.setFlags(BLEFlagsBREDRNotSupported); - advData.updateData(); - BLE.setAdvertisingData(advData); - BLE.advertise(); - REQUIRE( 3 == BLE.getAdvertisingData().dataLength()); - REQUIRE( 0 == (memcmp(goldenFlags, advData.data(), sizeof(goldenFlags))) ); - REQUIRE( 0 == (memcmp(goldenFlags, BLE.getAdvertisingData().data(), sizeof(goldenFlags))) ); - REQUIRE( 0 != (memcmp(defaultData, BLE.getAdvertisingData().data(), sizeof(defaultData))) ); - } - - WHEN("Setting external advertising data without flags") - { - advData.clear(); - BLE.setAdvertisingData(advData); - BLE.advertise(); - REQUIRE( 0 == (memcmp(defaultData, BLE.getAdvertisingData().data(), sizeof(defaultData))) ); - } - - // Clear BLE advertising data - advData.clear(); - BLE.setAdvertisingData(advData); -} - -TEST_CASE("Set default flags in an already full advertising data packet", "[ArduinoBLE::BLEAdvertisingData]") -{ - BLEAdvertisingData advData; - bool retVal; - - const char* name = "tes"; - const uint8_t manufacturerData[24] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, - 17, 18, 19, 20, 21, 22, 23}; - - const uint8_t defaultFlags[3] = {0x02, 0x01, 0x06}; - - const uint8_t goldenData[31] = { - (sizeof(manufacturerData) + 1), BLEFieldManufacturerData, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, - 17, 18, 19, 20, 21, 22, 23, - ((uint8_t)(strlen(name) + 1)), BLEFieldCompleteLocalName, 't', 'e', 's' - }; - - WHEN("Test flags when advertising data is full") - { - retVal = advData.setLocalName("tes"); - retVal = advData.setManufacturerData(manufacturerData, sizeof(manufacturerData)); - - BLE.setAdvertisingData(advData); - BLE.advertise(); - REQUIRE(0 != memcmp(defaultFlags, BLE.getAdvertisingData().data(), sizeof(defaultFlags))); - REQUIRE(0 == memcmp(goldenData, BLE.getAdvertisingData().data(), sizeof(goldenData))); - } - - // Clear BLE advertising data - advData.clear(); - BLE.setAdvertisingData(advData); -} - -TEST_CASE("BLE overwrite a full internal advertising data with an external built one", "[ArduinoBLE::BLEAdvertisingData]") -{ - bool verify; - BLEAdvertisingData advData; - BLEAdvertisingData internalData; - - WHEN("Copy empty external advertising data") - { - BLE.setLocalName("test"); - BLE.setAdvertisedServiceUuid("1818"); - BLE.advertise(); - - THEN("Check that BLE advertising data has been set") - { - verify = (BLE.getAdvertisingData().dataLength() == (3 + (2+2))); - REQUIRE(verify); - } - - THEN("Check that BLE scan response data has been set") - { - verify = (BLE.getScanResponseData().dataLength() == (4+2)); - REQUIRE(verify); - } - - // Copy external empty adv data into advertising data - BLE.setAdvertisingData(advData); - BLE.advertise(); - THEN("BLE advertising data should be erased") - { - verify = (BLE.getAdvertisingData().dataLength() == 3); - REQUIRE(verify); - } - - // Copy external empty adv data into scan response data - BLE.setScanResponseData(advData); - BLE.advertise(); - THEN("BLE scan response data should be erased") - { - verify = (BLE.getScanResponseData().dataLength() == 0); - REQUIRE(verify); - } - } - - // Clear BLE advertising data - advData.clear(); - BLE.setAdvertisingData(advData); -} - -TEST_CASE("BLE test raw data", "[ArduinoBLE::BLEAdvertisingData]") -{ - BLEAdvertisingData advData; - bool retVal; - - WHEN("Set too large raw data") - { - const uint8_t data[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, - 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, - 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32 }; - retVal = advData.setRawData(data, sizeof(data)); - THEN("Set raw data should return false. The parameter should not be set") - { - REQUIRE(!retVal); - } - advData.clear(); - } - - WHEN("Set correct raw data") - { - const uint8_t data[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, - 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, - 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31}; - retVal = advData.setRawData(data, sizeof(data)); - THEN("Set raw data should return true. The parameter should be correctly set") - { - REQUIRE(retVal); - } - advData.updateData(); - REQUIRE( 0 == memcmp(data, advData.data(), sizeof(data)) ); - advData.clear(); - } - - WHEN("Hide other parameters by setting raw data") - { - const uint8_t data[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; - advData.setLocalName("test"); - advData.setRawData(data, sizeof(data)); - - advData.updateData(); - REQUIRE( 0 == memcmp(data, advData.data(), sizeof(data)) ); - - advData.setLocalName("test"); - advData.updateData(); - REQUIRE( 0 == memcmp(data, advData.data(), sizeof(data)) ); - - advData.clear(); - advData.setLocalName("test"); - advData.updateData(); - REQUIRE( 0 != memcmp(data, advData.data(), sizeof(data)) ); - } - - // Clear BLE advertising data - advData.clear(); - BLE.setAdvertisingData(advData); -} diff --git a/extras/test/src/test_advertising_data/test_local_name.cpp b/extras/test/src/test_advertising_data/test_local_name.cpp deleted file mode 100644 index 5a6fde10..00000000 --- a/extras/test/src/test_advertising_data/test_local_name.cpp +++ /dev/null @@ -1,95 +0,0 @@ -/* - This file is part of the ArduinoBLE library. - Copyright (c) 2018 Arduino SA. All rights reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#include <catch2/catch_test_macros.hpp> - -#define private public -#define protected public - -#include "FakeBLELocalDevice.h" -#include "BLEAdvertisingData.h" - -TEST_CASE("Test local name setting", "[ArduinoBLE::BLEAdvertisingData]") -{ - BLEAdvertisingData advData; - int oldRemainingLength = advData.remainingLength(); - bool retVal; - - WHEN("Set correct local name") - { - const char* name = "test"; - retVal = advData.setLocalName(name); - THEN("Set local name should return true. The name parameter should be correctly set") - { - REQUIRE(retVal); - } - - THEN("Check the exact number of bytes occupied by the name just set") - { - REQUIRE( (strlen(name) + 2) == (oldRemainingLength - advData.remainingLength()) ); - } - oldRemainingLength = advData.remainingLength(); - - advData.updateData(); - REQUIRE(advData.dataLength() == (strlen(name) + 2)); - } - - WHEN("Set too long local name") - { - const char* name = "way too long local name (len 32)"; - retVal = advData.setLocalName(name); - THEN("Set local name should return false. The name parameter should not be set") - { - REQUIRE(!retVal); - REQUIRE( oldRemainingLength == advData.remainingLength() ); - advData.updateData(); - REQUIRE( advData.dataLength() == (MAX_AD_DATA_LENGTH - oldRemainingLength) ); - } - } - - WHEN("Overwrite local name with a name as long as max data length") - { - const char* name = "local name with full length "; - retVal = advData.setLocalName(name); - THEN("The name parameter should be correctly overwritten. The remaining length should be 0") - { - REQUIRE(retVal); - REQUIRE( (strlen(name) + 2) == (oldRemainingLength - advData.remainingLength()) ); - oldRemainingLength = advData.remainingLength(); - - advData.updateData(); - REQUIRE(advData.dataLength() == (strlen(name) + 2)); - // advData should be full now - REQUIRE( 0 == advData.remainingLength() ); - REQUIRE( 0 == advData.availableForWrite() ); - } - } - - WHEN("Check consistency when setting the external advertising data") - { - const auto goldenData = advData.data(); - BLE.setAdvertisingData(advData); - BLE.advertise(); - REQUIRE( 0 == memcmp(goldenData, BLE.getAdvertisingData().data(), advData.dataLength()) ); - } - - // Clear BLE advertising data - advData.clear(); - BLE.setAdvertisingData(advData); -} diff --git a/extras/test/src/test_advertising_data/test_manufacturer.cpp b/extras/test/src/test_advertising_data/test_manufacturer.cpp deleted file mode 100644 index c2fa8483..00000000 --- a/extras/test/src/test_advertising_data/test_manufacturer.cpp +++ /dev/null @@ -1,173 +0,0 @@ -/* - This file is part of the ArduinoBLE library. - Copyright (c) 2018 Arduino SA. All rights reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#include <catch2/catch_test_macros.hpp> - -#define private public -#define protected public - -#include "FakeBLELocalDevice.h" -#include "BLEAdvertisingData.h" - -TEST_CASE("Test manufacturer data setting", "[ArduinoBLE::BLEAdvertisingData]") -{ - BLEAdvertisingData advData; - int oldRemainingLength = advData.remainingLength(); - const uint16_t companyId = 0x1100; - bool retVal; - - WHEN("Set correct manufacturer data without id") - { - const uint8_t data[] = {0x00, 0x11, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; - const uint8_t goldenData[] = {(sizeof(data) + 1), BLEFieldManufacturerData, - 0x00, 0x11, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; - retVal = advData.setManufacturerData(data, sizeof(data)); - THEN("Check that the manufacturer data has been correctly set") - { - REQUIRE(retVal); - REQUIRE( (sizeof(data) + 2) == (oldRemainingLength - advData.remainingLength()) ); - } - oldRemainingLength = advData.remainingLength(); - - advData.updateData(); - REQUIRE(advData.dataLength() == sizeof(goldenData)); - REQUIRE( 0 == memcmp(goldenData, advData.data(), sizeof(goldenData)) ); - } - - WHEN("Set correct manufacturer data given a manufacturer id") - { - const uint8_t data[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; - const uint8_t goldenData[] = {(sizeof(data) + sizeof(companyId) + 1), BLEFieldManufacturerData, - 0x00, 0x11, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; - retVal = advData.setManufacturerData(companyId, data, sizeof(data)); - THEN("Check that the manufacturer data has been correctly set") - { - REQUIRE(retVal); - REQUIRE( (sizeof(data) + sizeof(companyId) + 2) == (oldRemainingLength - advData.remainingLength()) ); - } - oldRemainingLength = advData.remainingLength(); - - advData.updateData(); - REQUIRE(advData.dataLength() == sizeof(goldenData)); - REQUIRE( 0 == memcmp(goldenData, advData.data(), sizeof(goldenData)) ); - } - - WHEN("Set too long manufacturer data given id") - { - // extreme case, 1 byte more than the maximum - const uint8_t data[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27}; - retVal = advData.setManufacturerData(companyId, data, sizeof(data)); - THEN("Manufacturer data was too long, check that it has not been set") - { - REQUIRE(!retVal); - REQUIRE( oldRemainingLength == advData.remainingLength() ); - } - advData.updateData(); - REQUIRE( advData.dataLength() == (MAX_AD_DATA_LENGTH - oldRemainingLength) ); - } - - WHEN("Set too long manufacturer data without id") - { - // extreme case, 1 byte more than the maximum - const uint8_t data[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29}; - retVal = advData.setManufacturerData(data, sizeof(data)); - THEN("Manufacturer data was too long, check that it has not been set") - { - REQUIRE(!retVal); - REQUIRE( oldRemainingLength == advData.remainingLength() ); - } - advData.updateData(); - REQUIRE( advData.dataLength() == (MAX_AD_DATA_LENGTH - oldRemainingLength) ); - } - - WHEN("Set manufacturer data without id after setting manufacturer data given id") - { - advData.clear(); - const uint8_t dataGivenId[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26}; - const uint8_t data[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28}; - THEN("Check that first insertion of manufacturer data given id is correctly done") - { - retVal = advData.setManufacturerData(companyId, dataGivenId, sizeof(dataGivenId)); - REQUIRE(retVal); - } - THEN("Check that the insertion of manufacturer data without after one with id is correctly done") - { - retVal = advData.setManufacturerData(data, sizeof(data)); - REQUIRE(retVal); - REQUIRE( 0 == advData.remainingLength() ); - advData.updateData(); - REQUIRE( advData.dataLength() == (MAX_AD_DATA_LENGTH) ); - } - } - - WHEN("Set manufacturer data given id after setting manufacturer data without id") - { - advData.clear(); - // dataGivenId is too long!! it should not pass - const uint8_t dataGivenId[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27}; - const uint8_t data[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28}; - THEN("Check that first insertion of manufacturer data WITHOUT id is correctly done") - { - retVal = advData.setManufacturerData(data, sizeof(data)); - REQUIRE(retVal); - } - THEN("Check that the insertion of manufacturer data given id after one without id is correctly done") - { - retVal = advData.setManufacturerData(companyId, dataGivenId, sizeof(dataGivenId)); - REQUIRE(!retVal); - } - } - - WHEN("Overwrite manufacturer data with one as long as max data length") - { - const uint8_t data[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26}; - const uint8_t goldenData[] = {(sizeof(data) + sizeof(companyId) + 1), BLEFieldManufacturerData, - 0x00, 0x11, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, - 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26}; - retVal = advData.setManufacturerData(companyId, data, sizeof(data)); - THEN("Manufacturer data should be set correctly") - { - REQUIRE(retVal); - - advData.updateData(); - REQUIRE( 0 == advData.remainingLength() ); - REQUIRE( 0 == advData.availableForWrite() ); - REQUIRE( 0 == memcmp(goldenData, advData.data(), sizeof(goldenData)) ); - } - } - - WHEN("Check consistency when setting the external advertising data") - { - const auto goldenData = advData.data(); - BLE.setAdvertisingData(advData); - BLE.advertise(); - REQUIRE( 0 == memcmp(goldenData, BLE.getAdvertisingData().data(), advData.dataLength()) ); - } - - // Clear BLE advertising data - advData.clear(); - BLE.setAdvertisingData(advData); -} diff --git a/extras/test/src/test_advertising_data/test_service.cpp b/extras/test/src/test_advertising_data/test_service.cpp deleted file mode 100644 index 87c60497..00000000 --- a/extras/test/src/test_advertising_data/test_service.cpp +++ /dev/null @@ -1,164 +0,0 @@ -/* - This file is part of the ArduinoBLE library. - Copyright (c) 2018 Arduino SA. All rights reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#include <catch2/catch_test_macros.hpp> - -#define private public -#define protected public - -#include "FakeBLELocalDevice.h" -#include "BLEAdvertisingData.h" - -TEST_CASE("Test advertised service id setting", "[ArduinoBLE::BLEAdvertisingData]") -{ - BLEAdvertisingData advData; - int oldRemainingLength = advData.remainingLength(); - bool retVal; - - WHEN("Set correct advertised service") - { - const char* service = "00112233445566770011223344556677"; - retVal = advData.setAdvertisedServiceUuid(service); - REQUIRE(retVal); - REQUIRE( (16 + 2) == (oldRemainingLength - advData.remainingLength()) ); - oldRemainingLength = advData.remainingLength(); - - advData.updateData(); - REQUIRE(advData.dataLength() == (16 + 2)); - } - - WHEN("Set an advertised id too long with respect to the remaining length") - { - advData.clear(); - const char* name = "12 chars str"; - const char* service = "00112233445566770011223344556677"; - advData.setLocalName(name); - oldRemainingLength = advData.remainingLength(); - THEN("Check that the too long parameter has not been set") - { - REQUIRE(!advData.setAdvertisedServiceUuid(service)); - REQUIRE( oldRemainingLength == advData.remainingLength() ); - advData.updateData(); - REQUIRE( advData.dataLength() == (MAX_AD_DATA_LENGTH - oldRemainingLength) ); - } - } - - WHEN("Fill to maximum an advertising packet with a service id") - { - advData.clear(); - const char* name = "11 char str"; - const char* service = "00112233445566770011223344556677"; - advData.setLocalName(name); - REQUIRE(advData.setAdvertisedServiceUuid(service)); - - advData.updateData(); - REQUIRE(advData.dataLength() == (MAX_AD_DATA_LENGTH)); - // advData should be full now - REQUIRE( 0 == advData.remainingLength() ); - REQUIRE( 0 == advData.availableForWrite() ); - } - - WHEN("Check consistency when setting the external advertising data") - { - const auto goldenData = advData.data(); - BLE.setAdvertisingData(advData); - BLE.advertise(); - REQUIRE( 0 == memcmp(goldenData, BLE.getAdvertisingData().data(), advData.dataLength()) ); - } - - // Clear BLE advertising data - advData.clear(); - BLE.setAdvertisingData(advData); -} - -TEST_CASE("Test service data setting", "[ArduinoBLE::BLEAdvertisingData]") -{ - BLEAdvertisingData advData; - int oldRemainingLength = advData.remainingLength(); - const uint16_t uuid = 0x1100; - bool retVal; - - WHEN("Set correct service data") - { - const uint8_t data[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; - const uint8_t goldenData[] = {(sizeof(data) + sizeof(uuid) + 1), BLEFieldServiceData, - 0x00, 0x11, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; - retVal = advData.setAdvertisedServiceData(uuid, data, sizeof(data)); - THEN("Correctly set parameter") - { - REQUIRE(retVal); - REQUIRE( (sizeof(data) + 2 + sizeof(uuid)) == (oldRemainingLength - advData.remainingLength()) ); - } - oldRemainingLength = advData.remainingLength(); - - advData.updateData(); - THEN("Check parameter analyzing advertising raw data") - { - REQUIRE(advData.dataLength() == (sizeof(data) + 2 + sizeof(uuid))); - REQUIRE(advData.dataLength() == sizeof(goldenData)); - REQUIRE( 0 == memcmp(goldenData, advData.data(), sizeof(goldenData)) ); - } - } - - WHEN("Set too long service data") - { - // extreme case, 1 byte more than the maximum - const uint8_t data[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27}; - retVal = advData.setAdvertisedServiceData(uuid, data, sizeof(data)); - THEN("Check that the too long parameter has not been set") - { - REQUIRE(!retVal); - } - REQUIRE( oldRemainingLength == advData.remainingLength() ); - advData.updateData(); - REQUIRE( advData.dataLength() == (MAX_AD_DATA_LENGTH - oldRemainingLength) ); - } - - WHEN("Overwrite service data with one as long as max data length") - { - const uint8_t data[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26}; - retVal = advData.setAdvertisedServiceData(uuid, data, sizeof(data)); - THEN("Check correctly set parameter") - { - REQUIRE(retVal); - } - - advData.updateData(); - // advData should be full now - THEN("advData should be full now") - { - REQUIRE( 0 == advData.remainingLength() ); - REQUIRE( 0 == advData.availableForWrite() ); - } - } - - WHEN("Check consistency when setting the external advertising data") - { - const auto goldenData = advData.data(); - BLE.setAdvertisingData(advData); - BLE.advertise(); - REQUIRE( 0 == memcmp(goldenData, BLE.getAdvertisingData().data(), advData.dataLength()) ); - } - - // Clear BLE advertising data - advData.clear(); - BLE.setAdvertisingData(advData); -} diff --git a/extras/test/src/test_discovered_device/FakeGAP.cpp b/extras/test/src/test_discovered_device/FakeGAP.cpp deleted file mode 100644 index bbf78206..00000000 --- a/extras/test/src/test_discovered_device/FakeGAP.cpp +++ /dev/null @@ -1,31 +0,0 @@ -/* - This file is part of the ArduinoBLE library. - Copyright (c) 2018 Arduino SA. All rights reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#include "FakeGAP.h" - -FakeGAPClass::FakeGAPClass() -{ -} - -FakeGAPClass::~FakeGAPClass() -{ -} - -FakeGAPClass GAPFakeObj; -GAPClass& GAP = GAPFakeObj; diff --git a/extras/test/src/test_discovered_device/test_discovered_device.cpp b/extras/test/src/test_discovered_device/test_discovered_device.cpp deleted file mode 100644 index 14efcc0f..00000000 --- a/extras/test/src/test_discovered_device/test_discovered_device.cpp +++ /dev/null @@ -1,52 +0,0 @@ -/* - This file is part of the ArduinoBLE library. - Copyright (c) 2018 Arduino SA. All rights reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#include <catch2/catch_test_macros.hpp> - -#define private public -#define protected public -#include "BLEDevice.h" - -TEST_CASE("BLE discovered device test", "[ArduinoBLE::BLEDevice]") -{ - - WHEN("Retrieve local name from advertisement packet") - { - // Mocking advertisement packet - uint8_t advType = 0x03; - uint8_t eirLength = 6; - uint8_t eirData[] = {0x05, 0x09, 't', 'e', 's', 't'}; - uint8_t rssi = 0; - - // Expected results - String goldenName = "test"; - - // Simulate device discovery - BLEDevice device = BLEDevice(); - device.setAdvertisementData(0x03, eirLength, eirData, rssi); - - bool hasName = device.hasLocalName(); - REQUIRE(hasName); - - String name = device.localName(); - REQUIRE(goldenName == name); - - } - -} diff --git a/extras/test/src/test_main.cpp b/extras/test/src/test_main.cpp deleted file mode 100644 index 958f5367..00000000 --- a/extras/test/src/test_main.cpp +++ /dev/null @@ -1,21 +0,0 @@ -/* - This file is part of the ArduinoBLE library. - Copyright (c) 2018 Arduino SA. All rights reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#define CATCH_CONFIG_MAIN /* This tells Catch to provide a main() - only do this in one cpp file */ -#include <catch2/catch_test_macros.hpp> diff --git a/extras/test/src/test_uuid/test_uuid.cpp b/extras/test/src/test_uuid/test_uuid.cpp deleted file mode 100644 index 16c225eb..00000000 --- a/extras/test/src/test_uuid/test_uuid.cpp +++ /dev/null @@ -1,52 +0,0 @@ -/* - This file is part of the ArduinoBLE library. - Copyright (c) 2018 Arduino SA. All rights reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#include <catch2/catch_test_macros.hpp> - -#include "utility/BLEUuid.h" - -TEST_CASE("BLE uuid test", "[ArduinoBLE::BLEUuid]") -{ - WHEN("Set and retrieve uuid") - { - bool verify; - - const char* goldenUuid = "19b10010-e8f2-537e-4f6c-d104768a1214"; - // little-endian order - const uint8_t goldenData[] = {0x14,0x12,0x8A,0x76,0x04,0xD1,0x6C,0x4F,0x7E,0x53,0xF2,0xE8,0x10,0x00,0xB1,0x19}; - uint8_t goldenLength = 16; - - BLEUuid test(goldenUuid); - - uint8_t testLength = test.length(); - verify = (goldenLength == testLength); - REQUIRE(verify); - - const uint8_t *testData = test.data(); - verify = ( 0 == (memcmp(goldenData, testData, sizeof(goldenData))) ); - REQUIRE(verify); - - const char *testUuid = test.uuidToString(testData, testLength); - verify = ( 0 == strcmp(testUuid, goldenUuid) ); - REQUIRE(verify); - - // print the uuid - //WARN("test: " << testUuid << ", golden: " << goldenUuid); - } -} \ No newline at end of file diff --git a/extras/test/src/util/Common.cpp b/extras/test/src/util/Common.cpp deleted file mode 100644 index e2e1eeb5..00000000 --- a/extras/test/src/util/Common.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/* - This file is part of the ArduinoBLE library. - Copyright (c) 2018 Arduino SA. All rights reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#include "Common.h" - -void delay(unsigned long) -{ - -} - -/* C++ prototypes */ -long map(long x, long in_min, long in_max, long out_min, long out_max) -{ - return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; -} - -uint16_t makeWord(uint16_t w) { return w; } -uint16_t makeWord(uint8_t h, uint8_t l) { return (h << 8) | l; } \ No newline at end of file diff --git a/extras/test/src/util/HCIFakeTransport.cpp b/extras/test/src/util/HCIFakeTransport.cpp deleted file mode 100644 index 26645f5e..00000000 --- a/extras/test/src/util/HCIFakeTransport.cpp +++ /dev/null @@ -1,23 +0,0 @@ -/* - This file is part of the ArduinoBLE library. - Copyright (c) 2018 Arduino SA. All rights reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#include "HCIFakeTransport.h" - -HCIFakeTransportClass HCIFakeTransport; -HCITransportInterface& HCITransport = HCIFakeTransport; \ No newline at end of file diff --git a/extras/test/src/util/String.cpp b/extras/test/src/util/String.cpp deleted file mode 100644 index 618973b6..00000000 --- a/extras/test/src/util/String.cpp +++ /dev/null @@ -1,755 +0,0 @@ -/* - String library for Wiring & Arduino - ...mostly rewritten by Paul Stoffregen... - Copyright (c) 2009-10 Hernando Barragan. All rights reserved. - Copyright 2011, Paul Stoffregen, paul@pjrc.com - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#include "String.h" -#include "itoa.h" - -/*********************************************/ -/* Constructors */ -/*********************************************/ - -namespace arduino { - -String::String(const char *cstr) -{ - init(); - if (cstr) copy(cstr, strlen(cstr)); -} - -String::String(const String &value) -{ - init(); - *this = value; -} - -String::String(const __FlashStringHelper *pstr) -{ - init(); - *this = pstr; -} - -#if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) -String::String(String &&rval) -{ - init(); - move(rval); -} -String::String(StringSumHelper &&rval) -{ - init(); - move(rval); -} -#endif - -String::String(char c) -{ - init(); - char buf[2]; - buf[0] = c; - buf[1] = 0; - *this = buf; -} - -String::String(unsigned char value, unsigned char base) -{ - init(); - char buf[1 + 8 * sizeof(unsigned char)]; - utoa(value, buf, base); - *this = buf; -} - -String::String(int value, unsigned char base) -{ - init(); - char buf[2 + 8 * sizeof(int)]; - itoa(value, buf, base); - *this = buf; -} - -String::String(unsigned int value, unsigned char base) -{ - init(); - char buf[1 + 8 * sizeof(unsigned int)]; - utoa(value, buf, base); - *this = buf; -} - -String::String(long value, unsigned char base) -{ - init(); - char buf[2 + 8 * sizeof(long)]; - ltoa(value, buf, base); - *this = buf; -} - -String::String(unsigned long value, unsigned char base) -{ - init(); - char buf[1 + 8 * sizeof(unsigned long)]; - ultoa(value, buf, base); - *this = buf; -} - -/* -String::String(float value, unsigned char decimalPlaces) -{ - init(); - char buf[33]; - *this = dtostrf(value, (decimalPlaces + 2), decimalPlaces, buf); -} - -String::String(double value, unsigned char decimalPlaces) -{ - init(); - char buf[33]; - *this = dtostrf(value, (decimalPlaces + 2), decimalPlaces, buf); -} -*/ - -String::~String() -{ - if (buffer) free(buffer); -} - -/*********************************************/ -/* Memory Management */ -/*********************************************/ - -inline void String::init(void) -{ - buffer = NULL; - capacity = 0; - len = 0; -} - -void String::invalidate(void) -{ - if (buffer) free(buffer); - buffer = NULL; - capacity = len = 0; -} - -unsigned char String::reserve(unsigned int size) -{ - if (buffer && capacity >= size) return 1; - if (changeBuffer(size)) { - if (len == 0) buffer[0] = 0; - return 1; - } - return 0; -} - -unsigned char String::changeBuffer(unsigned int maxStrLen) -{ - char *newbuffer = (char *)realloc(buffer, maxStrLen + 1); - if (newbuffer) { - buffer = newbuffer; - capacity = maxStrLen; - return 1; - } - return 0; -} - -/*********************************************/ -/* Copy and Move */ -/*********************************************/ - -String & String::copy(const char *cstr, unsigned int length) -{ - if (!reserve(length)) { - invalidate(); - return *this; - } - len = length; - strcpy(buffer, cstr); - return *this; -} - -/* -String & String::copy(const __FlashStringHelper *pstr, unsigned int length) -{ - if (!reserve(length)) { - invalidate(); - return *this; - } - len = length; - strcpy_P(buffer, (PGM_P)pstr); - return *this; -} -*/ - -#if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) -void String::move(String &rhs) -{ - if (buffer) { - if (rhs && capacity >= rhs.len) { - strcpy(buffer, rhs.buffer); - len = rhs.len; - rhs.len = 0; - return; - } else { - free(buffer); - } - } - buffer = rhs.buffer; - capacity = rhs.capacity; - len = rhs.len; - rhs.buffer = NULL; - rhs.capacity = 0; - rhs.len = 0; -} -#endif - -String & String::operator = (const String &rhs) -{ - if (this == &rhs) return *this; - - if (rhs.buffer) copy(rhs.buffer, rhs.len); - else invalidate(); - - return *this; -} - -#if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) -String & String::operator = (String &&rval) -{ - if (this != &rval) move(rval); - return *this; -} - -String & String::operator = (StringSumHelper &&rval) -{ - if (this != &rval) move(rval); - return *this; -} -#endif - -String & String::operator = (const char *cstr) -{ - if (cstr) copy(cstr, strlen(cstr)); - else invalidate(); - - return *this; -} - -/* -String & String::operator = (const __FlashStringHelper *pstr) -{ - if (pstr) copy(pstr, strlen_P((PGM_P)pstr)); - else invalidate(); - - return *this; -} -*/ - -/*********************************************/ -/* concat */ -/*********************************************/ - -unsigned char String::concat(const String &s) -{ - return concat(s.buffer, s.len); -} - -unsigned char String::concat(const char *cstr, unsigned int length) -{ - unsigned int newlen = len + length; - if (!cstr) return 0; - if (length == 0) return 1; - if (!reserve(newlen)) return 0; - strcpy(buffer + len, cstr); - len = newlen; - return 1; -} - -unsigned char String::concat(const char *cstr) -{ - if (!cstr) return 0; - return concat(cstr, strlen(cstr)); -} - -unsigned char String::concat(char c) -{ - char buf[2]; - buf[0] = c; - buf[1] = 0; - return concat(buf, 1); -} - -unsigned char String::concat(unsigned char num) -{ - char buf[1 + 3 * sizeof(unsigned char)]; - itoa(num, buf, 10); - return concat(buf, strlen(buf)); -} - -unsigned char String::concat(int num) -{ - char buf[2 + 3 * sizeof(int)]; - itoa(num, buf, 10); - return concat(buf, strlen(buf)); -} - -unsigned char String::concat(unsigned int num) -{ - char buf[1 + 3 * sizeof(unsigned int)]; - utoa(num, buf, 10); - return concat(buf, strlen(buf)); -} - -unsigned char String::concat(long num) -{ - char buf[2 + 3 * sizeof(long)]; - ltoa(num, buf, 10); - return concat(buf, strlen(buf)); -} - -unsigned char String::concat(unsigned long num) -{ - char buf[1 + 3 * sizeof(unsigned long)]; - ultoa(num, buf, 10); - return concat(buf, strlen(buf)); -} - -/* -unsigned char String::concat(float num) -{ - char buf[20]; - char* string = dtostrf(num, 4, 2, buf); - return concat(string, strlen(string)); -} - -unsigned char String::concat(double num) -{ - char buf[20]; - char* string = dtostrf(num, 4, 2, buf); - return concat(string, strlen(string)); -} - -unsigned char String::concat(const __FlashStringHelper * str) -{ - if (!str) return 0; - int length = strlen_P((const char *) str); - if (length == 0) return 1; - unsigned int newlen = len + length; - if (!reserve(newlen)) return 0; - strcpy_P(buffer + len, (const char *) str); - len = newlen; - return 1; -} -*/ - -/*********************************************/ -/* Concatenate */ -/*********************************************/ - -StringSumHelper & operator + (const StringSumHelper &lhs, const String &rhs) -{ - StringSumHelper &a = const_cast<StringSumHelper&>(lhs); - if (!a.concat(rhs.buffer, rhs.len)) a.invalidate(); - return a; -} - -StringSumHelper & operator + (const StringSumHelper &lhs, const char *cstr) -{ - StringSumHelper &a = const_cast<StringSumHelper&>(lhs); - if (!cstr || !a.concat(cstr, strlen(cstr))) a.invalidate(); - return a; -} - -StringSumHelper & operator + (const StringSumHelper &lhs, char c) -{ - StringSumHelper &a = const_cast<StringSumHelper&>(lhs); - if (!a.concat(c)) a.invalidate(); - return a; -} - -StringSumHelper & operator + (const StringSumHelper &lhs, unsigned char num) -{ - StringSumHelper &a = const_cast<StringSumHelper&>(lhs); - if (!a.concat(num)) a.invalidate(); - return a; -} - -StringSumHelper & operator + (const StringSumHelper &lhs, int num) -{ - StringSumHelper &a = const_cast<StringSumHelper&>(lhs); - if (!a.concat(num)) a.invalidate(); - return a; -} - -StringSumHelper & operator + (const StringSumHelper &lhs, unsigned int num) -{ - StringSumHelper &a = const_cast<StringSumHelper&>(lhs); - if (!a.concat(num)) a.invalidate(); - return a; -} - -StringSumHelper & operator + (const StringSumHelper &lhs, long num) -{ - StringSumHelper &a = const_cast<StringSumHelper&>(lhs); - if (!a.concat(num)) a.invalidate(); - return a; -} - -StringSumHelper & operator + (const StringSumHelper &lhs, unsigned long num) -{ - StringSumHelper &a = const_cast<StringSumHelper&>(lhs); - if (!a.concat(num)) a.invalidate(); - return a; -} - -/* -StringSumHelper & operator + (const StringSumHelper &lhs, float num) -{ - StringSumHelper &a = const_cast<StringSumHelper&>(lhs); - if (!a.concat(num)) a.invalidate(); - return a; -} - -StringSumHelper & operator + (const StringSumHelper &lhs, double num) -{ - StringSumHelper &a = const_cast<StringSumHelper&>(lhs); - if (!a.concat(num)) a.invalidate(); - return a; -} - -StringSumHelper & operator + (const StringSumHelper &lhs, const __FlashStringHelper *rhs) -{ - StringSumHelper &a = const_cast<StringSumHelper&>(lhs); - if (!a.concat(rhs)) a.invalidate(); - return a; -} -*/ - -/*********************************************/ -/* Comparison */ -/*********************************************/ - -int String::compareTo(const String &s) const -{ - if (!buffer || !s.buffer) { - if (s.buffer && s.len > 0) return 0 - *(unsigned char *)s.buffer; - if (buffer && len > 0) return *(unsigned char *)buffer; - return 0; - } - return strcmp(buffer, s.buffer); -} - -int String::compareTo(const char *cstr) const -{ - if (!buffer || !cstr) { - if (cstr && !*cstr) return 0 - *(unsigned char *)cstr; - if (buffer && len > 0) return *(unsigned char *)buffer; - return 0; - } - return strcmp(buffer, cstr); -} - -unsigned char String::equals(const String &s2) const -{ - return (len == s2.len && compareTo(s2) == 0); -} - -unsigned char String::equals(const char *cstr) const -{ - if (len == 0) return (cstr == NULL || *cstr == 0); - if (cstr == NULL) return buffer[0] == 0; - return strcmp(buffer, cstr) == 0; -} - -unsigned char String::equalsIgnoreCase( const String &s2 ) const -{ - if (this == &s2) return 1; - if (len != s2.len) return 0; - if (len == 0) return 1; - const char *p1 = buffer; - const char *p2 = s2.buffer; - while (*p1) { - if (tolower(*p1++) != tolower(*p2++)) return 0; - } - return 1; -} - -unsigned char String::startsWith( const String &s2 ) const -{ - if (len < s2.len) return 0; - return startsWith(s2, 0); -} - -unsigned char String::startsWith( const String &s2, unsigned int offset ) const -{ - if (offset > len - s2.len || !buffer || !s2.buffer) return 0; - return strncmp( &buffer[offset], s2.buffer, s2.len ) == 0; -} - -unsigned char String::endsWith( const String &s2 ) const -{ - if ( len < s2.len || !buffer || !s2.buffer) return 0; - return strcmp(&buffer[len - s2.len], s2.buffer) == 0; -} - -/*********************************************/ -/* Character Access */ -/*********************************************/ - -char String::charAt(unsigned int loc) const -{ - return operator[](loc); -} - -void String::setCharAt(unsigned int loc, char c) -{ - if (loc < len) buffer[loc] = c; -} - -char & String::operator[](unsigned int index) -{ - static char dummy_writable_char; - if (index >= len || !buffer) { - dummy_writable_char = 0; - return dummy_writable_char; - } - return buffer[index]; -} - -char String::operator[]( unsigned int index ) const -{ - if (index >= len || !buffer) return 0; - return buffer[index]; -} - -void String::getBytes(unsigned char *buf, unsigned int bufsize, unsigned int index) const -{ - if (!bufsize || !buf) return; - if (index >= len) { - buf[0] = 0; - return; - } - unsigned int n = bufsize - 1; - if (n > len - index) n = len - index; - strncpy((char *)buf, buffer + index, n); - buf[n] = 0; -} - -/*********************************************/ -/* Search */ -/*********************************************/ - -int String::indexOf(char c) const -{ - return indexOf(c, 0); -} - -int String::indexOf( char ch, unsigned int fromIndex ) const -{ - if (fromIndex >= len) return -1; - const char* temp = strchr(buffer + fromIndex, ch); - if (temp == NULL) return -1; - return temp - buffer; -} - -int String::indexOf(const String &s2) const -{ - return indexOf(s2, 0); -} - -int String::indexOf(const String &s2, unsigned int fromIndex) const -{ - if (fromIndex >= len) return -1; - const char *found = strstr(buffer + fromIndex, s2.buffer); - if (found == NULL) return -1; - return found - buffer; -} - -int String::lastIndexOf( char theChar ) const -{ - return lastIndexOf(theChar, len - 1); -} - -int String::lastIndexOf(char ch, unsigned int fromIndex) const -{ - if (fromIndex >= len) return -1; - char tempchar = buffer[fromIndex + 1]; - buffer[fromIndex + 1] = '\0'; - char* temp = strrchr( buffer, ch ); - buffer[fromIndex + 1] = tempchar; - if (temp == NULL) return -1; - return temp - buffer; -} - -int String::lastIndexOf(const String &s2) const -{ - return lastIndexOf(s2, len - s2.len); -} - -int String::lastIndexOf(const String &s2, unsigned int fromIndex) const -{ - if (s2.len == 0 || len == 0 || s2.len > len) return -1; - if (fromIndex >= len) fromIndex = len - 1; - int found = -1; - for (char *p = buffer; p <= buffer + fromIndex; p++) { - p = strstr(p, s2.buffer); - if (!p) break; - if ((unsigned int)(p - buffer) <= fromIndex) found = p - buffer; - } - return found; -} - -String String::substring(unsigned int left, unsigned int right) const -{ - if (left > right) { - unsigned int temp = right; - right = left; - left = temp; - } - String out; - if (left >= len) return out; - if (right > len) right = len; - char temp = buffer[right]; // save the replaced character - buffer[right] = '\0'; - out = buffer + left; // pointer arithmetic - buffer[right] = temp; //restore character - return out; -} - -/*********************************************/ -/* Modification */ -/*********************************************/ - -void String::replace(char find, char replace) -{ - if (!buffer) return; - for (char *p = buffer; *p; p++) { - if (*p == find) *p = replace; - } -} - -void String::replace(const String& find, const String& replace) -{ - if (len == 0 || find.len == 0) return; - int diff = replace.len - find.len; - char *readFrom = buffer; - char *foundAt; - if (diff == 0) { - while ((foundAt = strstr(readFrom, find.buffer)) != NULL) { - memcpy(foundAt, replace.buffer, replace.len); - readFrom = foundAt + replace.len; - } - } else if (diff < 0) { - char *writeTo = buffer; - while ((foundAt = strstr(readFrom, find.buffer)) != NULL) { - unsigned int n = foundAt - readFrom; - memcpy(writeTo, readFrom, n); - writeTo += n; - memcpy(writeTo, replace.buffer, replace.len); - writeTo += replace.len; - readFrom = foundAt + find.len; - len += diff; - } - strcpy(writeTo, readFrom); - } else { - unsigned int size = len; // compute size needed for result - while ((foundAt = strstr(readFrom, find.buffer)) != NULL) { - readFrom = foundAt + find.len; - size += diff; - } - if (size == len) return; - if (size > capacity && !changeBuffer(size)) return; // XXX: tell user! - int index = len - 1; - while (index >= 0 && (index = lastIndexOf(find, index)) >= 0) { - readFrom = buffer + index + find.len; - memmove(readFrom + diff, readFrom, len - (readFrom - buffer)); - len += diff; - buffer[len] = 0; - memcpy(buffer + index, replace.buffer, replace.len); - index--; - } - } -} - -void String::remove(unsigned int index){ - // Pass the biggest integer as the count. The remove method - // below will take care of truncating it at the end of the - // string. - remove(index, (unsigned int)-1); -} - -void String::remove(unsigned int index, unsigned int count){ - if (index >= len) { return; } - if (count <= 0) { return; } - if (count > len - index) { count = len - index; } - char *writeTo = buffer + index; - len = len - count; - memmove(writeTo, buffer + index + count,len - index); - buffer[len] = 0; -} - -void String::toLowerCase(void) -{ - if (!buffer) return; - for (char *p = buffer; *p; p++) { - *p = tolower(*p); - } -} - -void String::toUpperCase(void) -{ - if (!buffer) return; - for (char *p = buffer; *p; p++) { - *p = toupper(*p); - } -} - -void String::trim(void) -{ - if (!buffer || len == 0) return; - char *begin = buffer; - while (isspace(*begin)) begin++; - char *end = buffer + len - 1; - while (isspace(*end) && end >= begin) end--; - len = end + 1 - begin; - if (begin > buffer) memmove(buffer, begin, len); - buffer[len] = 0; -} - -/*********************************************/ -/* Parsing / Conversion */ -/*********************************************/ - -long String::toInt(void) const -{ - if (buffer) return atol(buffer); - return 0; -} - -float String::toFloat(void) const -{ - return float(toDouble()); -} - -double String::toDouble(void) const -{ - if (buffer) return atof(buffer); - return 0; -} - -} // namespace arduino diff --git a/extras/test/src/util/TestUtil.cpp b/extras/test/src/util/TestUtil.cpp deleted file mode 100644 index 111607ec..00000000 --- a/extras/test/src/util/TestUtil.cpp +++ /dev/null @@ -1,3 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - */ diff --git a/extras/test/src/util/itoa.c b/extras/test/src/util/itoa.c deleted file mode 100644 index c9a275f6..00000000 --- a/extras/test/src/util/itoa.c +++ /dev/null @@ -1,126 +0,0 @@ -/* - Copyright (c) 2014 Arduino LLC. All right reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#include <itoa.h> -#include <string.h> - -#ifdef __cplusplus -extern "C" { -#endif - -extern char* itoa( int value, char *string, int radix ) -{ - return ltoa( value, string, radix ) ; -} - -extern char* ltoa( long value, char *string, int radix ) -{ - char tmp[33]; - char *tp = tmp; - long i; - unsigned long v; - int sign; - char *sp; - - if ( string == NULL ) - { - return 0 ; - } - - if (radix > 36 || radix <= 1) - { - return 0 ; - } - - sign = (radix == 10 && value < 0); - if (sign) - { - v = -value; - } - else - { - v = (unsigned long)value; - } - - while (v || tp == tmp) - { - i = v % radix; - v = v / radix; - if (i < 10) - *tp++ = i+'0'; - else - *tp++ = i + 'a' - 10; - } - - sp = string; - - if (sign) - *sp++ = '-'; - while (tp > tmp) - *sp++ = *--tp; - *sp = 0; - - return string; -} - -extern char* utoa( unsigned int value, char *string, int radix ) -{ - return ultoa( value, string, radix ) ; -} - -extern char* ultoa( unsigned long value, char *string, int radix ) -{ - char tmp[33]; - char *tp = tmp; - long i; - unsigned long v = value; - char *sp; - - if ( string == NULL ) - { - return 0; - } - - if (radix > 36 || radix <= 1) - { - return 0; - } - - while (v || tp == tmp) - { - i = v % radix; - v = v / radix; - if (i < 10) - *tp++ = i+'0'; - else - *tp++ = i + 'a' - 10; - } - - sp = string; - - - while (tp > tmp) - *sp++ = *--tp; - *sp = 0; - - return string; -} - -#ifdef __cplusplus -} // extern "C" -#endif diff --git a/keywords.txt b/keywords.txt index 481fd3eb..ee921a01 100644 --- a/keywords.txt +++ b/keywords.txt @@ -1,12 +1,12 @@ ####################################### -# Syntax Coloring Map For ArduinoBLE +# Syntax Coloring Map For STM32duinoBLE ####################################### ####################################### # Datatypes (KEYWORD1) ####################################### -ArduinoBLE KEYWORD1 +STM32duinoBLE KEYWORD1 BLE KEYWORD1 BLEDevice KEYWORD1 diff --git a/library.properties b/library.properties index 2a3aae10..7c5694cd 100644 --- a/library.properties +++ b/library.properties @@ -1,10 +1,10 @@ -name=ArduinoBLE +name=STM32duinoBLE version=1.4.0 -author=Arduino -maintainer=Arduino <info@arduino.cc> -sentence=Enables Bluetooth® Low Energy connectivity on the Arduino MKR WiFi 1010, Arduino UNO WiFi Rev2, Arduino Nano 33 IoT, Arduino Nano 33 BLE, Nicla Sense ME and UNO R4 WiFi. +author=Arduino, SRA +maintainer=stm32duino +sentence=Fork of ArduinoBLE library to add the support of SPBTLE-RF, SPBTLE-1S, BLUENRG-M2SP, BLUENRG-LP and BLUENRG-M0 BLE modules. paragraph=This library supports creating a Bluetooth® Low Energy peripheral & central mode. category=Communication -url=https://www.arduino.cc/en/Reference/ArduinoBLE -architectures=samd,megaavr,mbed,apollo3,mbed_nano,mbed_portenta,mbed_nicla,esp32,mbed_giga,renesas,renesas_portenta,mbed_opta,renesas_uno,silabs -includes=ArduinoBLE.h +url=https://github.com/stm32duino/STM32duinoBLE +architectures=stm32 +includes=STM32duinoBLE.h diff --git a/src/ArduinoBLE.h b/src/STM32duinoBLE.h similarity index 94% rename from src/ArduinoBLE.h rename to src/STM32duinoBLE.h index 588d5cb1..c603e3da 100644 --- a/src/ArduinoBLE.h +++ b/src/STM32duinoBLE.h @@ -17,8 +17,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef _ARDUINO_BLE_H_ -#define _ARDUINO_BLE_H_ +#ifndef _STM32DUINO_BLE_H_ +#define _STM32DUINO_BLE_H_ #include "local/BLELocalDevice.h" #include "BLEProperty.h" diff --git a/src/utility/CordioHCICustomDriver.h b/src/utility/CordioHCICustomDriver.h deleted file mode 100644 index fc062ee8..00000000 --- a/src/utility/CordioHCICustomDriver.h +++ /dev/null @@ -1,17 +0,0 @@ -#if defined(CORE_CM4) - -#include "CyH4TransportDriver.h" - -ble::vendor::cypress_ble::CyH4TransportDriver& ble_cordio_get_h4_transport_driver() -{ - static ble::vendor::cypress_ble::CyH4TransportDriver s_transport_driver( - /* TX */ CYBSP_BT_UART_TX, /* RX */ CYBSP_BT_UART_RX, - /* cts */ CYBSP_BT_UART_CTS, /* rts */ CYBSP_BT_UART_RTS, NC, DEF_BT_BAUD_RATE, - CYBSP_BT_HOST_WAKE, CYBSP_BT_DEVICE_WAKE - ); - return s_transport_driver; -} - -#define CUSTOM_HCI_DRIVER - -#endif \ No newline at end of file diff --git a/src/utility/HCICordioTransport.cpp b/src/utility/HCICordioTransport.cpp deleted file mode 100644 index b2a911d6..00000000 --- a/src/utility/HCICordioTransport.cpp +++ /dev/null @@ -1,322 +0,0 @@ -/* - This file is part of the ArduinoBLE library. - Copyright (c) 2019 Arduino SA. All rights reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#if defined(ARDUINO_ARCH_MBED) && !defined(TARGET_NANO_RP2040_CONNECT) // && !defined(CORE_CM4) -#include <Arduino.h> -#include <mbed.h> - -#include <driver/CordioHCITransportDriver.h> -#include <driver/CordioHCIDriver.h> - -#if defined(ARDUINO_PORTENTA_H7_M4) || defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_NICLA_VISION) || defined(ARDUINO_GIGA) || defined(ARDUINO_OPTA) -#include "ble/BLE.h" -#include <events/mbed_events.h> -#endif - -// Parts of this file are based on: https://github.com/ARMmbed/mbed-os-cordio-hci-passthrough/pull/2 -// With permission from the Arm Mbed team to re-license - -#if CORDIO_ZERO_COPY_HCI -#include <wsf_types.h> -#include <wsf_buf.h> -#include <wsf_msg.h> -#include <wsf_os.h> -#include <wsf_buf.h> -#include <wsf_timer.h> - -/* avoid many small allocs (and WSF doesn't have smaller buffers) */ -#define MIN_WSF_ALLOC (16) -#endif //CORDIO_ZERO_COPY_HCI - -#include "HCICordioTransport.h" - -#if (MBED_VERSION > MBED_ENCODE_VERSION(6, 2, 0)) -#define BLE_NAMESPACE ble -#else -#define BLE_NAMESPACE ble::vendor::cordio -#endif - -#include "CordioHCICustomDriver.h" - -extern BLE_NAMESPACE::CordioHCIDriver& ble_cordio_get_hci_driver(); -extern "C" void hciTrSerialRxIncoming(uint8_t *pBuf, uint8_t len); - -namespace BLE_NAMESPACE { - struct CordioHCIHook { - static CordioHCIDriver& getDriver() { - return ble_cordio_get_hci_driver(); - } - - static CordioHCITransportDriver& getTransportDriver() { - return getDriver()._transport_driver; - } - - static void setDataReceivedHandler(void (*handler)(uint8_t*, uint8_t)) { - getTransportDriver().set_data_received_handler(handler); - } - }; -} - -using BLE_NAMESPACE::CordioHCIHook; - -#if CORDIO_ZERO_COPY_HCI -extern uint8_t *SystemHeapStart; -extern uint32_t SystemHeapSize; - -void init_wsf(BLE_NAMESPACE::buf_pool_desc_t& buf_pool_desc) { - static bool init = false; - - if (init) { - return; - } - init = true; - - // use the buffer for the WSF heap - SystemHeapStart = buf_pool_desc.buffer_memory; - SystemHeapSize = buf_pool_desc.buffer_size; - - // Initialize buffers with the ones provided by the HCI driver - uint16_t bytes_used = WsfBufInit( - buf_pool_desc.pool_count, - (wsfBufPoolDesc_t*)buf_pool_desc.pool_description - ); - - // Raise assert if not enough memory was allocated - MBED_ASSERT(bytes_used != 0); - - SystemHeapStart += bytes_used; - SystemHeapSize -= bytes_used; - - WsfTimerInit(); -} - - -extern "C" void wsf_mbed_ble_signal_event(void) -{ - // do nothing -} -#endif //CORDIO_ZERO_COPY_HCI - -static void bleLoop() -{ -#if CORDIO_ZERO_COPY_HCI - uint64_t last_update_us = 0; - mbed::LowPowerTimer timer; - - timer.start(); - - while (true) { - last_update_us += (uint64_t) timer.read_high_resolution_us(); - timer.reset(); - - uint64_t last_update_ms = (last_update_us / 1000); - wsfTimerTicks_t wsf_ticks = (last_update_ms / WSF_MS_PER_TICK); - - if (wsf_ticks > 0) { - WsfTimerUpdate(wsf_ticks); - last_update_us -= (last_update_ms * 1000); - } - - wsfOsDispatcher(); - - bool sleep = false; - { - /* call needs interrupts disabled */ - mbed::CriticalSectionLock critical_section; - if (wsfOsReadyToSleep()) { - sleep = true; - } - } - - uint64_t time_spent = (uint64_t) timer.read_high_resolution_us(); - - /* don't bother sleeping if we're already past tick */ - if (sleep && (WSF_MS_PER_TICK * 1000 > time_spent)) { - /* sleep to maintain constant tick rate */ - uint64_t wait_time_us = WSF_MS_PER_TICK * 1000 - time_spent; - uint64_t wait_time_ms = wait_time_us / 1000; - - wait_time_us = wait_time_us % 1000; - - if (wait_time_ms) { - rtos::ThisThread::sleep_for(wait_time_ms); - } - - if (wait_time_us) { - wait_us(wait_time_us); - } - } - } -#else - while(true) { - rtos::ThisThread::sleep_for(osWaitForever); - } -#endif // CORDIO_ZERO_COPY_HCI -} - -static rtos::EventFlags bleEventFlags; -static rtos::Thread* bleLoopThread = NULL; - - -HCICordioTransportClass::HCICordioTransportClass() : - _begun(false) -{ -} - -HCICordioTransportClass::~HCICordioTransportClass() -{ -} - -#if (defined(ARDUINO_PORTENTA_H7_M4) || defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_NICLA_VISION) || defined(ARDUINO_GIGA) || defined(ARDUINO_OPTA)) && !defined(CUSTOM_HCI_DRIVER) -events::EventQueue eventQueue(10 * EVENTS_EVENT_SIZE); -void scheduleMbedBleEvents(BLE::OnEventsToProcessCallbackContext *context) { - eventQueue.call(mbed::Callback<void()>(&context->ble, &BLE::processEvents)); -} - -void completeCallback(BLE::InitializationCompleteCallbackContext *context) { - eventQueue.break_dispatch(); -} -#endif - -int HCICordioTransportClass::begin() -{ - _rxBuf.clear(); - -#if CORDIO_ZERO_COPY_HCI - BLE_NAMESPACE::buf_pool_desc_t bufPoolDesc = CordioHCIHook::getDriver().get_buffer_pool_description(); - init_wsf(bufPoolDesc); -#endif - -#if (defined(ARDUINO_PORTENTA_H7_M4) || defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_NICLA_VISION) || defined(ARDUINO_GIGA) || defined(ARDUINO_OPTA)) && !defined(CUSTOM_HCI_DRIVER) - - BLE &ble = BLE::Instance(); - ble.onEventsToProcess(scheduleMbedBleEvents); - - ble.init(completeCallback); - eventQueue.dispatch(10000); - - if (!ble.hasInitialized()){ - return 0; - } -#else - CordioHCIHook::getDriver().initialize(); -#endif - - if (bleLoopThread == NULL) { - bleLoopThread = new rtos::Thread(); - bleLoopThread->start(bleLoop); - } - - CordioHCIHook::setDataReceivedHandler(HCICordioTransportClass::onDataReceived); - - _begun = true; - - return 1; -} - -void HCICordioTransportClass::end() -{ - if (bleLoopThread != NULL) { - bleLoopThread->terminate(); - delete bleLoopThread; - bleLoopThread = NULL; - } - // Reset the callback with the mbed-os default handler to properly handle the following CYW43xxx chip initializations and begins - CordioHCIHook::setDataReceivedHandler(hciTrSerialRxIncoming); - -#if (defined(ARDUINO_PORTENTA_H7_M4) || defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_NICLA_VISION) || defined(ARDUINO_GIGA) || defined(ARDUINO_OPTA)) && !defined(CUSTOM_HCI_DRIVER) - BLE &ble = BLE::Instance(); - ble.shutdown(); -#endif - -#if !defined(TARGET_STM32H7) - CordioHCIHook::getDriver().terminate(); -#endif - - _begun = false; -} - -void HCICordioTransportClass::wait(unsigned long timeout) -{ - if (available()) { - return; - } - - // wait for handleRxData to signal - bleEventFlags.wait_all(0x01, timeout, true); -} - -int HCICordioTransportClass::available() -{ - return _rxBuf.available(); -} - -int HCICordioTransportClass::peek() -{ - return _rxBuf.peek(); -} - -int HCICordioTransportClass::read() -{ - return _rxBuf.read_char(); -} - -size_t HCICordioTransportClass::write(const uint8_t* data, size_t length) -{ - if (!_begun) { - return 0; - } - - uint8_t packetLength = length - 1; - uint8_t packetType = data[0]; - -#if CORDIO_ZERO_COPY_HCI - uint8_t* packet = (uint8_t*)WsfMsgAlloc(max(packetLength, MIN_WSF_ALLOC)); - - memcpy(packet, &data[1], packetLength); - - return CordioHCIHook::getTransportDriver().write(packetType, packetLength, packet); -#else - return CordioHCIHook::getTransportDriver().write(packetType, packetLength, (uint8_t*)&data[1]); -#endif -} - -void HCICordioTransportClass::handleRxData(uint8_t* data, uint8_t len) -{ - if (_rxBuf.availableForStore() < len) { - // drop! - return; - } - - for (int i = 0; i < len; i++) { - _rxBuf.store_char(data[i]); - } - - bleEventFlags.set(0x01); -} - -HCICordioTransportClass HCICordioTransport; -HCITransportInterface& HCITransport = HCICordioTransport; - -void HCICordioTransportClass::onDataReceived(uint8_t* data, uint8_t len) -{ - HCICordioTransport.handleRxData(data, len); -} - -#endif diff --git a/src/utility/HCICordioTransport.h b/src/utility/HCICordioTransport.h deleted file mode 100644 index b8d0596a..00000000 --- a/src/utility/HCICordioTransport.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - This file is part of the ArduinoBLE library. - Copyright (c) 2019 Arduino SA. All rights reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#ifndef _HCI_CORDIO_TRANSPORT_H_ -#define _HCI_CORDIO_TRANSPORT_H_ - -#include <string.h> - -#include "api/RingBuffer.h" - -#include "HCITransport.h" - -class HCICordioTransportClass : public HCITransportInterface { -public: - HCICordioTransportClass(); - virtual ~HCICordioTransportClass(); - - virtual int begin(); - virtual void end(); - - virtual void wait(unsigned long timeout); - - virtual int available(); - virtual int peek(); - virtual int read(); - - virtual size_t write(const uint8_t* data, size_t length); - -private: - static void onDataReceived(uint8_t* data, uint8_t len); - void handleRxData(uint8_t* data, uint8_t len); - -private: - bool _begun; - RingBufferN<256> _rxBuf; -}; - -#endif diff --git a/src/utility/HCISilabsTransport.cpp b/src/utility/HCISilabsTransport.cpp deleted file mode 100644 index 135fd020..00000000 --- a/src/utility/HCISilabsTransport.cpp +++ /dev/null @@ -1,130 +0,0 @@ -/* - This file is part of the ArduinoBLE library. - Copyright (c) 2024 Arduino SA. All rights reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#if defined(ARDUINO_SILABS) - -#include "HCISilabsTransport.h" -#include "sl_string.h" - -extern "C" { -#include "sl_btctrl_linklayer.h" -#include "sl_hci_common_transport.h" -} - -extern "C" int strcasecmp(char const *a, char const *b) { - return sl_strcasecmp(a, b); -} - -static RingBufferN<512> buf; - -HCISilabsTransportClass::HCISilabsTransportClass() -{ -} - -HCISilabsTransportClass::~HCISilabsTransportClass() -{ -} - -int HCISilabsTransportClass::begin() -{ - if(!sl_btctrl_is_initialized()) { - sl_bt_controller_init(); - } - - /* Initialize adv & scan components */ - sl_btctrl_init_adv(); - sl_btctrl_init_scan(); - sl_btctrl_init_conn(); - sl_btctrl_init_adv_ext(); - sl_btctrl_init_scan_ext(); - - /* Initialize HCI controller */ - sl_bthci_init_upper(); - sl_btctrl_hci_parser_init_default(); - sl_btctrl_hci_parser_init_conn(); - sl_btctrl_hci_parser_init_adv(); - sl_btctrl_hci_parser_init_phy(); - - return 1; -} - -void HCISilabsTransportClass::end() -{ - sl_bt_controller_deinit(); -} - -void HCISilabsTransportClass::wait(unsigned long timeout) -{ - for (unsigned long start = millis(); (millis() - start) < timeout;) { - if (available()) { - break; - } - } -} - -int HCISilabsTransportClass::available() -{ - return buf.available(); -} - -int HCISilabsTransportClass::peek() -{ - return buf.peek(); -} - -int HCISilabsTransportClass::read() -{ - return buf.read_char(); -} - -size_t HCISilabsTransportClass::write(const uint8_t* data, size_t len) -{ - int ret = 0; - ret = hci_common_transport_receive((uint8_t *)data, len, true); - - if (ret == 0) return len; - - return 0; -} - -extern "C" { - /** - * @brief Transmit HCI message using the currently used transport layer. - * The HCI calls this function to transmit a full HCI message. - * @param[in] data Packet type followed by HCI packet data. - * @param[in] len Length of the `data` parameter - * @return 0 - on success, or non-zero on failure. - */ - uint32_t hci_common_transport_transmit(uint8_t *data, int16_t len) - { - for (int i = 0; i < len; i++) { - buf.store_char(data[i]); - if (buf.isFull()) return SL_STATUS_FAIL; - } - - sl_btctrl_hci_transmit_complete(0); - return 0; - } -} - -HCISilabsTransportClass HCISilabsTransport; - -HCITransportInterface& HCITransport = HCISilabsTransport; - -#endif diff --git a/src/utility/HCISilabsTransport.h b/src/utility/HCISilabsTransport.h deleted file mode 100644 index 2061e782..00000000 --- a/src/utility/HCISilabsTransport.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - This file is part of the ArduinoBLE library. - Copyright (c) 2018 Arduino SA. All rights reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#ifndef _HCI_SILABS_TRANSPORT_H_ -#define _HCI_SILABS_TRANSPORT_H_ - -#include "HCITransport.h" - -class HCISilabsTransportClass : public HCITransportInterface { -public: - HCISilabsTransportClass(); - virtual ~HCISilabsTransportClass(); - - virtual int begin(); - virtual void end(); - - virtual void wait(unsigned long timeout); - - virtual int available(); - virtual int peek(); - virtual int read(); - - virtual size_t write(const uint8_t* data, size_t length); -}; - -#endif \ No newline at end of file diff --git a/src/utility/HCIUartTransport.cpp b/src/utility/HCIUartTransport.cpp deleted file mode 100644 index 191811a7..00000000 --- a/src/utility/HCIUartTransport.cpp +++ /dev/null @@ -1,109 +0,0 @@ -/* - This file is part of the ArduinoBLE library. - Copyright (c) 2018 Arduino SA. All rights reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#if !defined(ARDUINO_ARCH_MBED) && !defined(ESP32) && !defined(ARDUINO_SILABS) && !defined(ARDUINO_UNOR4_WIFI) || defined(TARGET_NANO_RP2040_CONNECT) //|| defined(CORE_CM4) - -#include "HCIUartTransport.h" - -#if defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_AVR_UNO_WIFI_REV2) -#define SerialHCI Serial2 -#elif defined(ARDUINO_SAMD_NANO_33_IOT) || defined(ARDUINO_NANO_RP2040_CONNECT) -// SerialHCI is already defined in the variant -#elif defined(ARDUINO_PORTENTA_H7_M4) -// SerialHCI is already defined in the variant -#elif defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_NICLA_VISION) -#define SerialHCI Serial2 -#elif defined(ARDUINO_OPTA) -#define SerialHCI Serial3 -#elif defined(ARDUINO_PORTENTA_C33) -#define SerialHCI Serial5 -#elif defined(ARDUINO_GIGA) -arduino::UART SerialHCI(CYBSP_BT_UART_TX, CYBSP_BT_UART_RX, CYBSP_BT_UART_RTS, CYBSP_BT_UART_CTS); -#else -#error "Unsupported board selected!" -#endif - -HCIUartTransportClass::HCIUartTransportClass(HardwareSerial& uart, unsigned long baudrate) : - _uart(&uart), - _baudrate(baudrate) -{ -} - -HCIUartTransportClass::~HCIUartTransportClass() -{ -} - -int HCIUartTransportClass::begin() -{ - _uart->begin(_baudrate); - - return 1; -} - -void HCIUartTransportClass::end() -{ - _uart->end(); -} - -void HCIUartTransportClass::wait(unsigned long timeout) -{ - for (unsigned long start = millis(); (millis() - start) < timeout;) { - if (available()) { - break; - } - } -} - -int HCIUartTransportClass::available() -{ - return _uart->available(); -} - -int HCIUartTransportClass::peek() -{ - return _uart->peek(); -} - -int HCIUartTransportClass::read() -{ - return _uart->read(); -} - -size_t HCIUartTransportClass::write(const uint8_t* data, size_t length) -{ -#ifdef ARDUINO_AVR_UNO_WIFI_REV2 - // wait while the CTS pin is low - while (digitalRead(NINA_CTS) == HIGH); -#endif - - size_t result = _uart->write(data, length); - - _uart->flush(); - - return result; -} - -#if defined(ARDUINO_AVR_UNO_WIFI_REV2) || defined(ARDUINO_NANO_RP2040_CONNECT) -HCIUartTransportClass HCIUartTransport(SerialHCI, 119600); -#else -HCIUartTransportClass HCIUartTransport(SerialHCI, 912600); -#endif -HCITransportInterface& HCITransport = HCIUartTransport; - -#endif diff --git a/src/utility/HCIUartTransport.h b/src/utility/HCIUartTransport.h deleted file mode 100644 index ba70dff4..00000000 --- a/src/utility/HCIUartTransport.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - This file is part of the ArduinoBLE library. - Copyright (c) 2018 Arduino SA. All rights reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#ifndef _HCI_UART_TRANSPORT_H_ -#define _HCI_UART_TRANSPORT_H_ - -#include "HCITransport.h" - -class HCIUartTransportClass : public HCITransportInterface { -public: - HCIUartTransportClass(HardwareSerial& uart, unsigned long baudrate); - virtual ~HCIUartTransportClass(); - - virtual int begin(); - virtual void end(); - - virtual void wait(unsigned long timeout); - - virtual int available(); - virtual int peek(); - virtual int read(); - - virtual size_t write(const uint8_t* data, size_t length); - -private: - HardwareSerial* _uart; - unsigned long _baudrate; -}; - -#endif diff --git a/src/utility/HCIVirtualTransport.cpp b/src/utility/HCIVirtualTransport.cpp deleted file mode 100644 index 509fafb5..00000000 --- a/src/utility/HCIVirtualTransport.cpp +++ /dev/null @@ -1,144 +0,0 @@ -/* - This file is part of the ArduinoBLE library. - Copyright (c) 2018 Arduino SA. All rights reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#if defined(ESP32) - -#include "HCIVirtualTransport.h" - -StreamBufferHandle_t rec_buffer; -StreamBufferHandle_t send_buffer; -TaskHandle_t bleHandle; - - -static void notify_host_send_available(void) -{ -} - -static int notify_host_recv(uint8_t *data, uint16_t length) -{ - xStreamBufferSend(rec_buffer,data,length,portMAX_DELAY); // !!!potentially waiting forever - return 0; -} - -static esp_vhci_host_callback_t vhci_host_cb = { - notify_host_send_available, - notify_host_recv -}; - -void bleTask(void *pvParameters) -{ - esp_vhci_host_register_callback(&vhci_host_cb); - size_t length; - uint8_t mybuf[258]; - - while(true){ - length = xStreamBufferReceive(send_buffer,mybuf,258,portMAX_DELAY); - while (!esp_vhci_host_check_send_available()) {} - esp_vhci_host_send_packet(mybuf, length); - } -} - - -HCIVirtualTransportClass::HCIVirtualTransportClass() -{ -} - -HCIVirtualTransportClass::~HCIVirtualTransportClass() -{ -} - -int HCIVirtualTransportClass::begin() -{ - btStarted(); // this somehow stops the arduino ide from initializing bluedroid - - rec_buffer = xStreamBufferCreate(258, 1); - send_buffer = xStreamBufferCreate(258, 1); - - esp_err_t ret = nvs_flash_init(); - if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) { - ESP_ERROR_CHECK(nvs_flash_erase()); - ret = nvs_flash_init(); - } - esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT(); - -#if CONFIG_IDF_TARGET_ESP32 - bt_cfg.mode = ESP_BT_MODE_BLE; //original esp32 chip -#else -#if !(CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2) - bt_cfg.bluetooth_mode = ESP_BT_MODE_BLE; //different api for newer models -#endif -#endif - - esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT); - esp_bt_controller_init(&bt_cfg); - esp_bt_controller_enable(ESP_BT_MODE_BLE); - xTaskCreatePinnedToCore(&bleTask, "bleTask", 2048, NULL, 5, &bleHandle, 0); - return 1; -} - -void HCIVirtualTransportClass::end() -{ - vStreamBufferDelete(rec_buffer); - vStreamBufferDelete(send_buffer); - esp_bt_controller_disable(); - esp_bt_controller_deinit(); - vTaskDelete(bleHandle); -} - -void HCIVirtualTransportClass::wait(unsigned long timeout) -{ - for (unsigned long start = (esp_timer_get_time() / 1000ULL); ((esp_timer_get_time() / 1000ULL) - start) < timeout;) { - if (available()) { - break; - } - } -} - -int HCIVirtualTransportClass::available() -{ - size_t bytes = xStreamBufferBytesAvailable(rec_buffer); - return bytes; -} - -// never called -int HCIVirtualTransportClass::peek() -{ - return -1; -} - -int HCIVirtualTransportClass::read() -{ - uint8_t c; - if(xStreamBufferReceive(rec_buffer, &c, 1, portMAX_DELAY)) { - return c; - } - return -1; -} - -size_t HCIVirtualTransportClass::write(const uint8_t* data, size_t length) -{ - size_t result = xStreamBufferSend(send_buffer,data,length,portMAX_DELAY); - return result; -} - -HCIVirtualTransportClass HCIVirtualTransport; - -HCITransportInterface& HCITransport = HCIVirtualTransport; - -#endif diff --git a/src/utility/HCIVirtualTransport.h b/src/utility/HCIVirtualTransport.h deleted file mode 100644 index 0da43cac..00000000 --- a/src/utility/HCIVirtualTransport.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - This file is part of the ArduinoBLE library. - Copyright (c) 2018 Arduino SA. All rights reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#include "HCITransport.h" -#include <stdint.h> -#include <stdio.h> -#include <string.h> - -#include "freertos/FreeRTOS.h" -#include "freertos/task.h" -#include "freertos/stream_buffer.h" - -#include "esp_bt.h" -#include "nvs_flash.h" - -#include "esp32-hal-bt.h" // this is needed to disable bluedroid - - -class HCIVirtualTransportClass : public HCITransportInterface { -public: - HCIVirtualTransportClass(); - virtual ~HCIVirtualTransportClass(); - - virtual int begin(); - virtual void end(); - - virtual void wait(unsigned long timeout); - - virtual int available(); - virtual int peek(); - virtual int read(); - - virtual size_t write(const uint8_t* data, size_t length); -}; \ No newline at end of file diff --git a/src/utility/HCIVirtualTransportAT.cpp b/src/utility/HCIVirtualTransportAT.cpp deleted file mode 100644 index 7b3a24a9..00000000 --- a/src/utility/HCIVirtualTransportAT.cpp +++ /dev/null @@ -1,112 +0,0 @@ -/* - This file is part of the ArduinoBLE library. - Copyright (c) 2018 Arduino SA. All rights reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#if defined(ARDUINO_UNOR4_WIFI) - -#include "HCIVirtualTransportAT.h" - -extern ModemClass modem; - -HCIVirtualTransportATClass::HCIVirtualTransportATClass() -{ -} - -HCIVirtualTransportATClass::~HCIVirtualTransportATClass() -{ -} - -static RingBufferN<258> buf; - -int HCIVirtualTransportATClass::begin() -{ - // TODO: add this helper - //modem.debug(Serial); - buf.clear(); - //modem.debug(true); - std::string res = ""; - modem.begin(); - if (modem.write(std::string(PROMPT(_HCI_BEGIN)), res, CMD(_HCI_BEGIN))) { - return 1; - } - return 0; -} - -void HCIVirtualTransportATClass::end() -{ -} - -void HCIVirtualTransportATClass::wait(unsigned long timeout) -{ - std::string res = ""; - modem.write(std::string(PROMPT(_HCI_WAIT)), res, "%d\n\r", CMD_WRITE(_HCI_WAIT), timeout); -} - -int HCIVirtualTransportATClass::available() -{ - std::string res = ""; - if (buf.available()) { - return buf.available(); - } - if (modem.write(std::string(PROMPT(_HCI_AVAILABLE)), res, CMD_READ(_HCI_AVAILABLE))) { - return atoi(res.c_str()); - } - - return 0; -} - -// never called -int HCIVirtualTransportATClass::peek() -{ - return -1; -} - -int HCIVirtualTransportATClass::read() -{ - uint8_t c; - std::string res = ""; - if (buf.available()) { - return buf.read_char(); - } - modem.avoid_trim_results(); - modem.read_using_size(); - if (modem.write(std::string(PROMPT(_HCI_READ)), res, CMD(_HCI_READ))) { - for(int i = 0; i < res.size(); i++) { - buf.store_char((uint8_t)res[i]); - } - return buf.read_char(); - } - - return -1; -} - -size_t HCIVirtualTransportATClass::write(const uint8_t* data, size_t length) -{ - std::string res = ""; - modem.write_nowait(std::string(PROMPT(_HCI_WRITE)), res, "%s%d\r\n" , CMD_WRITE(_HCI_WRITE), length); - if(modem.passthrough(data, length)) { - return length; - } - return 0; -} - -HCIVirtualTransportATClass HCIVirtualTransportAT; - -HCITransportInterface& HCITransport = HCIVirtualTransportAT; - -#endif diff --git a/src/utility/HCIVirtualTransportAT.h b/src/utility/HCIVirtualTransportAT.h deleted file mode 100644 index 8e29801d..00000000 --- a/src/utility/HCIVirtualTransportAT.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - This file is part of the ArduinoBLE library. - Copyright (c) 2018 Arduino SA. All rights reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#include "HCITransport.h" -#include <stdint.h> -#include <stdio.h> -#include <string.h> - -#include "WiFiS3.h" - -class HCIVirtualTransportATClass : public HCITransportInterface { -public: - HCIVirtualTransportATClass(); - virtual ~HCIVirtualTransportATClass(); - - virtual int begin(); - virtual void end(); - - virtual void wait(unsigned long timeout); - - virtual int available(); - virtual int peek(); - virtual int read(); - - virtual size_t write(const uint8_t* data, size_t length); -}; \ No newline at end of file diff --git a/src/utility/btct.cpp b/src/utility/btct.cpp index 77a5e818..dffbccf9 100644 --- a/src/utility/btct.cpp +++ b/src/utility/btct.cpp @@ -1,7 +1,7 @@ #include "btct.h" #include <Arduino.h> #include "HCI.h" -#include "ArduinoBLE.h" +#include "STM32duinoBLE.h" BluetoothCryptoToolbox::BluetoothCryptoToolbox(){} // In step 1, AES-128 with key K is applied to an all-zero input block. // In step 2, K1 is derived through the following operation: From a633b95b1b11c39483a6e6e0a1af72cb86c316b1 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Tue, 18 Mar 2025 16:38:00 +0100 Subject: [PATCH 207/226] feat: ability to define HCI SPI transport configuration Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- README.md | 55 +++++++++++++++++++++++++++++++++ src/utility/HCISpiTransport.cpp | 13 ++++++-- 2 files changed, 65 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e9f3a948..62186871 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,61 @@ https://github.com/stm32duino/Arduino_Core_STM32/wiki/STM32duinoBLE#stm32duinobl For more information about ArduinoBLE library please visit the official web page at: https://www.arduino.cc/en/Reference/ArduinoBLE +# Configuration + +### Shield + +The user can include the file `ble_spi_conf.h` to define which shield and configuration to use from the following list: + + * [X-NUCLEO-IDB05A2] + * `IDB05A2_SPI_CLOCK_D3`: SPI clock on D3 + * `IDB05A2_SPI_CLOCK_D13` SPI clock on D13 + * [X-NUCLEO-IDB05A1] + * `IDB05A1_SPI_CLOCK_D3`: SPI clock on D3 + * `IDB05A1_SPI_CLOCK_D13`: SPI clock on D13 + * [X-NUCLEO-BNRG2A1] + * `BNRG2A1_SPI_CLOCK_D3`: SPI clock on D3 + * `BNRG2A1_SPI_CLOCK_D13`: SPI clock on D13 + * `CUSTOM_BLE_SPI`: define a custom configuration, it requires below definition: + * `BLE_SPI_MISO`: SPI MISO pin + * `BLE_SPI_MOSI`: SPI MOSI pin + * `BLE_SPI_CLK`: SPI CLocK pin + * `BLE_SPI_CS`: SPI Chip Select pin + * `BLE_SPI_IRQ`: SPI IRQ pin + * `BLE_SPI_FREQ`: SPI bus frequency + * `BLE_SPI_MODE`: can be one of the below `SPIMode`: + * `SPI_MODE0` + * `SPI_MODE1` + * `SPI_MODE2` + * `SPI_MODE0` + * `BLE_CHIP_TYPE`: can be one of the below `BLEChip_t`: + * `SPBTLE_RF` + * `SPBTLE_1S` + * `BLUENRG_M2SP` + * `BLUENRG_M0` + * `BLUENRG_LP` + * `BLE_RESET`: BLE reset pin + +#### Examples + +To use the [X-NUCLEO-IDB05A2] with SPI clock on D3, define in `ble_spi_conf.h`: +```C +#define IDB05A2_SPI_CLOCK_D3 +``` +This is equivalent to the below configuration using the `CUSTOM_BLE_SPI`: +```C +#define CUSTOM_BLE_SPI +#define BLE_SPI_MISO D12 +#define BLE_SPI_MOSI D11 +#define BLE_SPI_CLK D3 +#define BLE_SPI_CS A1 +#define BLE_SPI_IRQ A0 +#define BLE_SPI_FREQ 8000000 +#define BLE_SPI_MODE SPI_MODE0 +#define BLE_CHIP_TYPE BLUENRG_M0 +#define BLE_RESET D7 +``` + ## License ``` diff --git a/src/utility/HCISpiTransport.cpp b/src/utility/HCISpiTransport.cpp index 91c2c5dc..9a3709da 100644 --- a/src/utility/HCISpiTransport.cpp +++ b/src/utility/HCISpiTransport.cpp @@ -19,7 +19,14 @@ #include "HCISpiTransport.h" -#if defined(ARDUINO_STEVAL_MKBOXPRO) +#if __has_include("ble_spi_conf.h") + #include "ble_spi_conf.h" +#endif + +#if defined(CUSTOM_BLE_SPI) +SPIClass SpiHCI(BLE_SPI_MOSI, BLE_SPI_MISO, BLE_SPI_CLK); +HCISpiTransportClass HCISpiTransport(SpiHCI, BLE_CHIP_TYPE, BLE_SPI_CS, BLE_SPI_IRQ, BLE_RESET, BLE_SPI_FREQ, BLE_SPI_MODE); +#elif defined(ARDUINO_STEVAL_MKBOXPRO) /* STEVAL-MKBOXPRO */ SPIClass SpiHCI(PA7, PA6, PA5); HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_LP, PA2, PB11, PD4, 1000000, SPI_MODE3); @@ -51,11 +58,11 @@ HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI /* Shield IDB05A1 with SPI clock on D13 */ #define SpiHCI SPI HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI_MODE0); -#elif defined(BNRG2A1_CLOCK_D3) +#elif defined(BNRG2A1_SPI_CLOCK_D3) /* Shield BNRG2A1 with SPI clock on D3 */ SPIClass SpiHCI(D11, D12, D3); HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1); -#elif defined(BNRG2A1_CLOCK_D13) +#elif defined(BNRG2A1_SPI_CLOCK_D13) /* Shield BNRG2A1 with SPI clock on D13 */ #define SpiHCI SPI HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1); From 44880e25518cd4ba971614d0bac2b139094fb277 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Mon, 17 Feb 2020 10:08:13 +0100 Subject: [PATCH 208/226] chore(ci): add build-for-stm32 step Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- .github/workflows/compile-examples.yml | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index b82efaec..5296427c 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -18,3 +18,28 @@ on: workflow_dispatch: jobs: + build-for-stm32: + runs-on: ubuntu-latest + + strategy: + matrix: + fqbn: + - STMicroelectronics:stm32:Eval:pnum=STEVAL_MKSBOX1V1,usb=CDCgen + - STMicroelectronics:stm32:Nucleo_64:pnum=NUCLEO_L476RG + - STMicroelectronics:stm32:Disco:pnum=B_L475E_IOT01A + + steps: + - uses: actions/checkout@v4 + - uses: arduino/compile-sketches@v1 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + fqbn: ${{ matrix.fqbn }} + platforms: | + - name: STMicroelectronics:stm32 + source-url: https://github.com/stm32duino/BoardManagerFiles/raw/main/package_stmicroelectronics_index.json + sketch-paths: | + - examples + cli-compile-flags: | + - --build-property + - build.extra_flags=-DIDB05A2_SPI_CLOCK_D3 + From bbbf535591535e474c2c00399d7e893bfbc6f8ab Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Tue, 18 Mar 2025 09:27:33 +0100 Subject: [PATCH 209/226] feat: add editor config Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- .editorconfig | 26 ++++++++++++++++++++++++++ .gitattributes | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 .editorconfig create mode 100644 .gitattributes diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..47433680 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,26 @@ +[*] +end_of_line = lf +insert_final_newline = true +indent_style = space +indent_size = 2 +trim_trailing_whitespace = true + +[*.patch] +insert_final_newline = unset +indent_style = unset +indent_size = unset +trim_trailing_whitespace = unset + +[*.md] +trim_trailing_whitespace = false + +[*.sh] +# like -i=2 +indent_style = space +indent_size = 2 + +#shell_variant = posix # like -ln=posix +#binary_next_line = true # like -bn +switch_case_indent = true # like -ci +space_redirects = true # like -sr +#keep_padding = true # like -kp diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..422ae6f5 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,42 @@ +# Set the default behavior, in case people don't have core.autocrlf set. +* text=auto + +# Explicitly declare text files you want to always be normalized and converted +# to native line endings on checkout. +.editorconfig text eol=lf +.flake8 text eol=lf +.gitattributes text eol=lf +.gitignore text eol=lf + +*.adoc text eol=lf +*.c text eol=lf +*.cmake text eol=lf +*.cpp text eol=lf +*.css text eol=lf +*.dtsi text eol=lf +*.gv text eol=lf +*.h text eol=lf +*.html text eol=lf +*.in text eol=lf +*.ino text eol=lf +*.json text eol=lf +*.ld text eol=lf +*.md text eol=lf +*.MD text eol=lf +*.old text eol=lf +*.patch text eol=lf +*.pde text eol=lf +*.properties text eol=lf +*.py text eol=lf +*.s text eol=lf +*.S text eol=lf +*.sh text eol=lf +*.spec text eol=lf +*.txt text eol=lf +*.yml text eol=lf + +# Denote all files that are truly binary and should not be modified. +*.jpg binary +*.pdf binary +*.png binary + From 141ebddab0e51603c8f2522d4b3563b6680904d0 Mon Sep 17 00:00:00 2001 From: Francois Ramu <francois.ramu@st.com> Date: Tue, 18 Mar 2025 09:33:50 +0100 Subject: [PATCH 210/226] feat: add HCISharedMemTransport to support the shared memory transport layer for the STM32WB built-in chip. It also Allows HCI SPI Transport with STM32WBxx Signed-off-by: Francois Ramu <francois.ramu@st.com> Co-Authored-by: Frederic Pillon <frederic.pillon@st.com> --- keywords.txt | 1 + src/utility/HCISharedMemTransport.cpp | 781 ++++++++++++++++++++++++++ src/utility/HCISharedMemTransport.h | 93 +++ 3 files changed, 875 insertions(+) create mode 100644 src/utility/HCISharedMemTransport.cpp create mode 100644 src/utility/HCISharedMemTransport.h diff --git a/keywords.txt b/keywords.txt index ee921a01..150e6262 100644 --- a/keywords.txt +++ b/keywords.txt @@ -31,6 +31,7 @@ BLEDoubleCharacteristic KEYWORD1 BLEStringCharacteristic KEYWORD1 HCISpiTransportClass KEYWORD1 +HCISharedMemTransportClass KEYWORD1 ####################################### # Methods and Functions (KEYWORD2) diff --git a/src/utility/HCISharedMemTransport.cpp b/src/utility/HCISharedMemTransport.cpp new file mode 100644 index 00000000..8a4cd21a --- /dev/null +++ b/src/utility/HCISharedMemTransport.cpp @@ -0,0 +1,781 @@ +/* + This file is part of the STM32duinoBLE library. + Copyright (c) 2019 STMicroelectronics. All rights reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ +#if defined(STM32WBxx) + +#include "HCISharedMemTransport.h" +#include "STM32_WPAN/hw.h" +#include "otp.h" + +HCISharedMemTransportClass HCISharedMemTransport; +#if !defined(ARDUINO_NUCLEO_WB15CC) && !defined(ARDUINO_P_NUCLEO_WB55RG) &&\ + !defined(ARDUINO_STM32WB5MM_DK) && !defined(ARDUINO_P_NUCLEO_WB55_USB_DONGLE) +#warning "Selected board has never been tested with this library, ensure to have a correct configuration!" +#endif + +/* Private variables ---------------------------------------------------------*/ +PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static TL_CmdPacket_t BleCmdBuffer; + +PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static uint8_t EvtPool[POOL_SIZE]; +PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static TL_CmdPacket_t SystemCmdBuffer; +PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static uint8_t +SystemSpareEvtBuffer[sizeof(TL_PacketHeader_t) + TL_EVT_HDR_SIZE + 255]; +PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static uint8_t +BleSpareEvtBuffer[sizeof(TL_PacketHeader_t) + TL_EVT_HDR_SIZE + 255]; +PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static uint8_t +HciAclDataBuffer[sizeof(TL_PacketHeader_t) + 5 + 251]; + + +/* global var used as semaphore to control incoming events */ +volatile bool sys_event; /* true : M0 core is already up and running */ +volatile bool acl_data_on; /* true : sending ACL data in progress, false : send is possible */ +volatile bool data_overflow; + +/* buffer to store the received packets */ +volatile uint8_t _rxbuff[BLE_MODULE_SHARED_MEM_BUFFER_SIZE]; +volatile uint16_t _read_index; /* fifo position when reading */ +volatile uint16_t _write_index; /* fifo position when receiving */ + +/* var of different device steps during init and receiving */ +volatile bool phase_bd_addr; +volatile bool phase_tx_power; +volatile bool phase_reset; +volatile bool phase_running; + + +/** Bluetooth Device Address */ +static uint8_t bd_addr_udn[CONFIG_DATA_PUBADDR_LEN]; + +/* Private functions ---------------------------------------------------------*/ +/** + * TL Mailbox synchronization means + */ + +/* returns true if sys_event was received, false otherwise */ +static bool sysevt_wait(void) +{ + /* sys_event remains false until event is received */ + for (unsigned long start = millis(); (millis() - start) < BLE_IPCC_TIMEOUT;) { + /* Wait for 10sec max - if not return an error */ + if (sys_event) { + break; + } + } + + if (!sys_event) { +#if defined(PRINT_IPCC_INFO) + printf("ERROR: sys_evt timeout\r\n"); +#endif /*(PRINT_IPCC_INFO)*/ + /* no event received, timeout occurs */ + return false; + } + /* release immediately, now that M0 runs */ + return true; +} + +/* WEAK callbacks from the BLE TL driver - will be called under Interrupt */ +static void sysevt_received(void *pdata) +{ + UNUSED(pdata); + /* For now only READY event is received, so we know this is it */ + __disable_irq(); + sys_event = true; + __enable_irq(); + /* But later on ... we'll have to parse the answer */ +} + +/* returns true if sysevt was already received, which means M0 core is + * already up and running */ +static bool sysevt_check(void) +{ + /* Check if system is UP and running already */ + for (unsigned long start = millis(); (millis() - start) < 10;) { + /* Wait for 10ms max - if not return an error */ + if (sys_event) { + break; + } + } + if (sys_event) { + /* release immediately as M0 already runs */ + return true; + } + return false; +} + +static void acl_data_ack(void) +{ + /** + * The current implementation assumes the taskGUI will not send a new HCI ACL DATA packet before this ack is received + * ( which means the CPU2 has handled the previous packet ) + * In order to implement a secure mechanism, it is required either + * - a flow control with the stack + * - a local pool of buffer to store packets received from the stack + */ + __disable_irq(); + acl_data_on = false; + __enable_irq(); +} + +static bool acl_data_wait(void) +{ + /* Wait 10 sec for previous ACL command to be ack'ed by Low Layers + * before sending the next one */ + for (unsigned long start = millis(); (millis() - start) < BLE_IPCC_TIMEOUT;) { + /* Wait for 10sec max - if not return an error */ + if (!acl_data_on) { + break; + } + } + if (acl_data_on) { + /* no event received, timeout occurs */ +#if defined(PRINT_IPCC_INFO) + printf("ERROR: acl data timeout\r\n"); +#endif /*(PRINT_IPCC_INFO)*/ + return false; + } + /* release immediately, now that M0 runs */ + __disable_irq(); + acl_data_on = false; + __enable_irq(); + return true; +} + +static void syscmd_status_not(SHCI_TL_CmdStatus_t status) +{ +#if defined(PRINT_IPCC_INFO) + printf("syscmd_status_not, status:%d\r\n", status); +#else + UNUSED(status); +#endif /*(PRINT_IPCC_INFO)*/ +} + +/* to received BLE packet from the SharedMem */ +void evt_received(TL_EvtPacket_t *hcievt) +{ + uint16_t len = 0; + + /* We need to memcpy the data before passing to higher layers. + * The received packet is copied in the _rxbuff + * but it must not exceed the BLE_MODULE_SHARED_MEM_BUFFER_SIZE + */ + switch (hcievt->evtserial.type) { + case TL_BLEEVT_PKT_TYPE: { + /* before starting the running_phase', a RESET command (0x0C03) is sent + * by the HCI. Then this evt packet is temporarily kept in the _rxbuff + * the set_bd_address (0xFC0C) and the set_tw_power (0xFC0F) commands are sent. + * Only when both evt are received (not store in the _rxbuffer), + * the Reset packet is handled at HCI layer : the running_phase begins + */ + if (phase_running == false) { + /* check the Rx event of complete the previous bd_addr or random address opcode 0xFC0C */ + if ((hcievt->evtserial.evt.evtcode == TL_BLEEVT_CC_OPCODE) && + (hcievt->evtserial.evt.payload[0] == 0x01) && + (hcievt->evtserial.evt.payload[1] == 0x0C) && + (hcievt->evtserial.evt.payload[2] == 0xFC)) { + /* First setting must be global address + */ + phase_bd_addr = true; + + if (hcievt->evtserial.evt.payload[3] != 0) { +#if defined(PRINT_IPCC_INFO) + printf("Error: wrong BD Addr\r\n"); +#endif /*(PRINT_IPCC_INFO)*/ + } + /* rx data is no more useful : not stored in the _rxbuff */ + break; + } + /* check the Rx event of complete the previous tx power opcode 0xFC0F */ + if ((hcievt->evtserial.evt.evtcode == TL_BLEEVT_CC_OPCODE) && + (hcievt->evtserial.evt.payload[0] == 0x01) && + (hcievt->evtserial.evt.payload[1] == 0x0F) && + (hcievt->evtserial.evt.payload[2] == 0xFC)) { + phase_tx_power = true; + if (hcievt->evtserial.evt.payload[3] != 0) { +#if defined(PRINT_IPCC_INFO) + printf("Error: wrong Tx power\r\n"); +#endif /*(PRINT_IPCC_INFO)*/ + } + /* rx data is no more useful : not stored in the _rxbuff */ + break; + } + + /* check if the reset phase is in progress (opcode is 0x0C03) */ + if ((hcievt->evtserial.evt.evtcode == TL_BLEEVT_CC_OPCODE) && + (hcievt->evtserial.evt.payload[0] == 0x01) && + (hcievt->evtserial.evt.payload[1] == 0x03) && + (hcievt->evtserial.evt.payload[2] == 0x0C)) { + phase_reset = true; +#if defined(PRINT_IPCC_INFO) + if (hcievt->evtserial.evt.payload[3] != 0) { + printf("Error: wrong reset\r\n"); + } +#endif /*(PRINT_IPCC_INFO)*/ + } + } + __disable_irq(); + /* store received data in the _rxbuff buffer */ + len = hcievt->evtserial.evt.plen + TL_EVT_HDR_SIZE; + if (len < BLE_MODULE_SHARED_MEM_BUFFER_SIZE - _write_index) { + /* at the position of the _write_index */ + memcpy((uint8_t *)&_rxbuff[_write_index], (uint8_t *)&hcievt->evtserial, len); + /* move index */ + _write_index += len; + } else { + data_overflow = true; + } + __enable_irq(); + } + break; + case TL_ACL_DATA_PKT_TYPE: { + TL_AclDataSerial_t *acl = &(((TL_AclDataPacket_t *)hcievt)->AclDataSerial); + __disable_irq(); + len = acl->length + 5; + if (len < BLE_MODULE_SHARED_MEM_BUFFER_SIZE - _write_index) { + memcpy((uint8_t *)&_rxbuff[_write_index], (uint8_t *)acl, len); + /* move index */ + _write_index += len; + } else { + data_overflow = true; + } + __enable_irq(); + } + break; + default: + /* should not happen */ +#if defined(PRINT_IPCC_INFO) + printf("BLE TL evt_received, wrong type:%d\r\n", hcievt->evtserial.type); + while (1); /* let's block to check */ +#endif /*(PRINT_IPCC_INFO)*/ + break; + } +#if defined(PRINT_IPCC_INFO) + if (data_overflow) { + printf("Error: data read overflow\r\n"); + } +#endif /*(PRINT_IPCC_INFO)*/ + + /* In case Event belongs to the Evt Pool we need to inform */ + if (((uint8_t *)hcievt >= EvtPool) && ((uint8_t *)hcievt < (EvtPool + POOL_SIZE))) { + /* Free the message from shared memory */ + TL_MM_EvtDone(hcievt); + } +} + +/* to send BLE packet to the SharedMem : return nb of bytes actually written */ +uint16_t mbox_write(uint8_t type, uint16_t len, const uint8_t *pData) +{ + TL_CmdPacket_t *bleCmdBuf = &BleCmdBuffer; + // Note: Until enum is available + // type 01 Command + // type 02 ACL DATA + // type 03 SCO Voice (not supported) + // type 04 event - uplink (not supported) + switch (type) { + case 1: { //BLE command + bleCmdBuf->cmdserial.type = type; // for now this param is overwritten in TL_BLE_SendCmd + bleCmdBuf->cmdserial.cmd.plen = len; + memcpy((void *) &bleCmdBuf->cmdserial.cmd, pData, len); + /* We're tracing here the command, after copy in shared mem but before M0 trigger. */ + TL_BLE_SendCmd(NULL, 0); // unused parameters for now + } + break; + case 2: { //ACL DATA + if (!acl_data_wait()) { +#if defined(PRINT_IPCC_INFO) + printf("ERROR: previous ACL message not ACK'd\r\n"); +#endif /*(PRINT_IPCC_INFO)*/ + /* return number of bytes sent, 0 in this error case */ + return 0; + } + TL_AclDataSerial_t *aclDataSerial = (TL_AclDataSerial_t *)(HciAclDataBuffer + sizeof(TL_PacketHeader_t)); + aclDataSerial->type = type; // for now this param is overwritten in TL_BLE_SendCmd + memcpy(HciAclDataBuffer + sizeof(TL_PacketHeader_t) + sizeof(type), pData, len); + TL_BLE_SendAclData(NULL, 0); // unused parameters for now + __disable_irq(); + acl_data_on = true; /* data being send */ + __enable_irq(); + } + break; + default: +#if defined(PRINT_IPCC_INFO) + printf("ERROR: not supported type\r\n"); +#endif /*(PRINT_IPCC_INFO)*/ + /* return number of bytes sent, 0 in this error case */ + len = 0; + break; + } + return len; +} + +/** + * Few utilities functions + */ +/* This function fills in a BD address table */ +static bool get_bd_address(uint8_t *bd_addr) +{ + uint32_t udn; + uint32_t company_id; + uint32_t device_id; + bool bd_found; + + udn = LL_FLASH_GetUDN(); + + if (udn != 0xFFFFFFFF) { + /* "Found Unique Device Number: %#06x", udn) */ + + company_id = LL_FLASH_GetSTCompanyID(); + device_id = LL_FLASH_GetDeviceID(); + + bd_addr[0] = (uint8_t)(udn & 0x000000FF); + bd_addr[1] = (uint8_t)((udn & 0x0000FF00) >> 8); + bd_addr[2] = (uint8_t)device_id; + bd_addr[3] = (uint8_t)(company_id & 0x000000FF); + bd_addr[4] = (uint8_t)((company_id & 0x0000FF00) >> 8); + bd_addr[5] = (uint8_t)((company_id & 0x00FF0000) >> 16); + + bd_found = true; + } else { + OTP_BT_t *p_otp = (OTP_BT_t *)OTP_Read(0); + if (p_otp) { + memcpy(bd_addr, p_otp->bd_address, CONFIG_DATA_PUBADDR_LEN); + bd_found = true; + } else { + bd_found = false; + } + } + + return bd_found; +} + +static void init_debug(void) +{ + /* In case of debug profile, configure debugger support */ + +#if defined(CONFIG_DEBUG) +#if defined(PRINT_IPCC_INFO) + printf("init_debug ENABLED\r\n"); +#endif /*(PRINT_IPCC_INFO)*/ + /** + * Keep debugger enabled while in any low power mode + */ + HAL_DBGMCU_EnableDBGSleepMode(); + HAL_DBGMCU_EnableDBGStopMode(); + HAL_DBGMCU_EnableDBGStandbyMode(); + + /* Enable debugger: Debug power up request wakeup EXTI line 48 */ + LL_EXTI_EnableIT_32_63(LL_EXTI_LINE_48); + LL_C2_EXTI_EnableIT_32_63(LL_EXTI_LINE_48); + +#endif /* CONFIG_DEBUG */ +} + +/* Class definition ----------------------------------------------------------*/ + +HCISharedMemTransportClass::HCISharedMemTransportClass() +{ + _read_index = 0; /* fifo position when reading */ + _write_index = 0; /* fifo position when receiving */ + + memset((void *)_rxbuff, 0, sizeof(_rxbuff)); + + sys_event = false; + acl_data_on = false; + + data_overflow = false; + + phase_bd_addr = false; + phase_tx_power = false; + phase_reset = false; + phase_running = false; +} + +HCISharedMemTransportClass::~HCISharedMemTransportClass() +{ +} + +int HCISharedMemTransportClass::begin() +{ + int status = 1; + /* clean data Rx variables */ + _read_index = 0; + _write_index = 0; + + memset((void *)_rxbuff, 0, sizeof(_rxbuff)); + + /* Check whether M0 sub-system was started already by + * checking if the system event was already received + * before. If it was not, then go through all init. */ + if (!sysevt_check()) { + start_ble_rf(); + init_debug(); + /* Take BLE out of reset */ + stm32wb_reset(); + /* "C2 unlocking" */ + transport_init(); + /* At this stage, we got the ready event, + * passed through TL_SYS_EvtReceived */ + + WirelessFwInfo_t wireless_info_instance; + WirelessFwInfo_t *p_wireless_info = &wireless_info_instance; + SHCI_GetWirelessFwInfo(p_wireless_info); +#if defined(PRINT_IPCC_INFO) + printf("WB copro FW version = %d.%d.%d\r\n", p_wireless_info->VersionMajor, p_wireless_info->VersionMinor, p_wireless_info->VersionSub); +#endif /*(PRINT_IPCC_INFO)*/ + + /* Now start BLE service on firmware side, using Vendor specific + * command on the System Channel + */ + status = stm32wb_start_ble(); + + /* Once reset complete event is received we will need + * to send a few more commands: + * set bd addr with bt_ipm_set_addr(); + * during the HCI rest command */ + } + /* IPM Channel is now open */ +#if defined(PRINT_IPCC_INFO) + printf("IPM Channel Open Completed\r\n"); +#endif /*(PRINT_IPCC_INFO)*/ + + return status; +} + +void HCISharedMemTransportClass::end() +{ + /* M0 sub-system is already on (sys_event) */ + acl_data_on = false; + data_overflow = false; + + /* the HCI RESET command ready to be processed again */ + phase_bd_addr = false; + phase_tx_power = false; + phase_reset = false; + phase_running = false; +} + +void HCISharedMemTransportClass::wait(unsigned long timeout) +{ + for (unsigned long start = millis(); (millis() - start) < timeout;) { + if (available()) { + break; + } + } +} + +int HCISharedMemTransportClass::available() +{ + /* assuming the reset is already achieved, + * the LL-only mode is already configured. */ + + if (_read_index != _write_index) { + return 1; + } else if (data_overflow) { + __disable_irq(); + data_overflow = false; + __enable_irq(); + if (_read_index != _write_index) { + return 1; + } + } + + return 0; +} + +int HCISharedMemTransportClass::peek() +{ + int peek_val = -1; + __disable_irq(); + if (_read_index != _write_index) { + peek_val = _rxbuff[_read_index]; + } + __enable_irq(); + return peek_val; +} + +int HCISharedMemTransportClass::read() +{ + int read_val = -1; + __disable_irq(); + if (_read_index != _write_index) { + read_val = _rxbuff[_read_index]; + _read_index++; + if (_read_index == _write_index) { + /* Reset buffer index */ + _read_index = 0; + _write_index = 0; + } + } + __enable_irq(); + return read_val; +} + +size_t HCISharedMemTransportClass::write(const uint8_t *data, size_t length) +{ + const uint8_t *msg_data; + msg_data = &data[1]; + + /* capture the HCI reset send command opcode = 0x0C03 + * After HCI reset event complete in the evt_received(), + * the bd_addr and tx_power must be sent + * before the phase_running begins. + */ + if (phase_running) { + return mbox_write(data[0], (length - 1), msg_data);; + } + if ((data[1] == 0x03) && (data[2] == 0x0C)) { + phase_reset = false; + + if (mbox_write(data[0], (length - 1), msg_data) != (length - 1)) { + /* Error: no data are written */ + return 0; + } + /* capture event after HCI_RESET */ + while (!phase_reset); + + /* set the bd add */ + if (!bt_ipm_set_addr()) { + /* in case of error, no data are written */ + return 0; + } + /* wait for the Rx complete */ + while (!phase_bd_addr); + /* this sequence is now complete */ + + /* set the Tx power */ + bt_ipm_set_power(); + /* wait for the Rx complete */ + while (!phase_tx_power); + + /* this sequence is now complete */ + phase_running = true; + + return (length - 1); /* mbox_size of the HCI reset command */ + } + return 0; /* Error: no data written */ +} + +//private: +void HCISharedMemTransportClass::start_ble_rf(void) +{ + /* Set the DBP bit in the Power control register 1 (PWR_CR1) */ + LL_PWR_EnableBkUpAccess(); + + /* LSE belongs to the back-up domain, enable access.*/ + while (!LL_PWR_IsEnabledBkUpAccess()) { + /* Wait for Backup domain access */ + } + LL_RCC_ForceBackupDomainReset(); + LL_RCC_ReleaseBackupDomainReset(); + + /* Enable LSE Oscillator (32.768 kHz) */ + LL_RCC_LSE_Enable(); + while (!LL_RCC_LSE_IsReady()) { + /* Wait for LSE ready */ + } + + LL_PWR_DisableBkUpAccess(); + + /* Switch OFF LSI as LSE is the source clock */ + LL_RCC_LSI2_Disable(); +} + +void HCISharedMemTransportClass::stm32wb_reset(void) +{ + // Reset IPCC + LL_AHB3_GRP1_EnableClock(LL_AHB3_GRP1_PERIPH_IPCC); + + LL_C1_IPCC_ClearFlag_CHx( + IPCC, + LL_IPCC_CHANNEL_1 | LL_IPCC_CHANNEL_2 | LL_IPCC_CHANNEL_3 | LL_IPCC_CHANNEL_4 + | LL_IPCC_CHANNEL_5 | LL_IPCC_CHANNEL_6); + + LL_C2_IPCC_ClearFlag_CHx( + IPCC, + LL_IPCC_CHANNEL_1 | LL_IPCC_CHANNEL_2 | LL_IPCC_CHANNEL_3 | LL_IPCC_CHANNEL_4 + | LL_IPCC_CHANNEL_5 | LL_IPCC_CHANNEL_6); + + LL_C1_IPCC_DisableTransmitChannel( + IPCC, + LL_IPCC_CHANNEL_1 | LL_IPCC_CHANNEL_2 | LL_IPCC_CHANNEL_3 | LL_IPCC_CHANNEL_4 + | LL_IPCC_CHANNEL_5 | LL_IPCC_CHANNEL_6); + + LL_C2_IPCC_DisableTransmitChannel( + IPCC, + LL_IPCC_CHANNEL_1 | LL_IPCC_CHANNEL_2 | LL_IPCC_CHANNEL_3 | LL_IPCC_CHANNEL_4 + | LL_IPCC_CHANNEL_5 | LL_IPCC_CHANNEL_6); + + LL_C1_IPCC_DisableReceiveChannel( + IPCC, + LL_IPCC_CHANNEL_1 | LL_IPCC_CHANNEL_2 | LL_IPCC_CHANNEL_3 | LL_IPCC_CHANNEL_4 + | LL_IPCC_CHANNEL_5 | LL_IPCC_CHANNEL_6); + + LL_C2_IPCC_DisableReceiveChannel( + IPCC, + LL_IPCC_CHANNEL_1 | LL_IPCC_CHANNEL_2 | LL_IPCC_CHANNEL_3 | LL_IPCC_CHANNEL_4 + | LL_IPCC_CHANNEL_5 | LL_IPCC_CHANNEL_6); + + /* IPCC default IRQ handlers: IPCC_C1_TX_IRQHandler & IPCC_C1_RX_IRQHandler + * are mapped in the flash mem area, so that NVIC does not need to SetVector + */ +} + +int HCISharedMemTransportClass::stm32wb_start_ble(void) +{ + SHCI_C2_Ble_Init_Cmd_Packet_t ble_init_cmd_packet = { + 0, 0, 0, /**< Header unused */ + 0, /** pBleBufferAddress not used */ + 0, /** BleBufferSize not used */ + CFG_BLE_NUM_GATT_ATTRIBUTES, + CFG_BLE_NUM_GATT_SERVICES, + CFG_BLE_ATT_VALUE_ARRAY_SIZE, + CFG_BLE_NUM_LINK, + CFG_BLE_DATA_LENGTH_EXTENSION, + CFG_BLE_PREPARE_WRITE_LIST_SIZE, + CFG_BLE_MBLOCK_COUNT, + CFG_BLE_MAX_ATT_MTU, + CFG_BLE_PERIPHERAL_SCA, + CFG_BLE_CENTRAL_SCA, + CFG_BLE_LS_SOURCE, + CFG_BLE_MAX_CONN_EVENT_LENGTH, + CFG_BLE_HSE_STARTUP_TIME, + CFG_BLE_VITERBI_MODE, + CFG_BLE_OPTIONS, + 0, /** TODO Should be read from HW */ + CFG_BLE_MAX_COC_INITIATOR_NBR, + CFG_BLE_MIN_TX_POWER, + CFG_BLE_MAX_TX_POWER, + CFG_BLE_RX_MODEL_CONFIG, + CFG_BLE_MAX_ADV_SET_NBR, + CFG_BLE_MAX_ADV_DATA_LEN, + CFG_BLE_TX_PATH_COMPENS, + CFG_BLE_RX_PATH_COMPENS, + CFG_BLE_CORE_VERSION, + CFG_BLE_OPTIONS_EXT + }; + /** + * Starts the BLE Stack on CPU2 + */ + if (SHCI_C2_BLE_Init(&ble_init_cmd_packet) == SHCI_Success) { + return 1; + } + return 0; +} + +void HCISharedMemTransportClass::transport_init(void) +{ + TL_MM_Config_t tl_mm_config; + TL_BLE_InitConf_t tl_ble_config; + /* STM32WB offers a System Channel HCI interface for + offering system services, with proprietary commands. + System Channel must be used as well for starting up + BLE service so we need to initialize it. */ + SHCI_TL_HciInitConf_t shci_init_config; + + /**< Reference table initialization */ + TL_Init(); + + /**< System channel initialization */ + shci_init_config.p_cmdbuffer = (uint8_t *)&SystemCmdBuffer; + shci_init_config.StatusNotCallBack = syscmd_status_not; + shci_init(sysevt_received, (void *) &shci_init_config); + + /**< Memory Manager channel initialization */ + tl_mm_config.p_BleSpareEvtBuffer = BleSpareEvtBuffer; + tl_mm_config.p_SystemSpareEvtBuffer = SystemSpareEvtBuffer; + tl_mm_config.p_AsynchEvtPool = EvtPool; + tl_mm_config.AsynchEvtPoolSize = POOL_SIZE; + TL_MM_Init(&tl_mm_config); + + TL_Enable(); + + /* At this stage, we'll need to wait for ready event, + * passed through TL_SYS_EvtReceived */ + if (!sysevt_wait()) { +#if defined(PRINT_IPCC_INFO) + printf("ERROR booting WB controller\r\n"); +#endif /*(PRINT_IPCC_INFO)*/ + } else { + /**< BLE channel initialization */ + tl_ble_config.p_cmdbuffer = (uint8_t *)&BleCmdBuffer; + tl_ble_config.p_AclDataBuffer = HciAclDataBuffer; + tl_ble_config.IoBusEvtCallBack = evt_received; + tl_ble_config.IoBusAclDataTxAck = acl_data_ack; + TL_BLE_Init((void *)&tl_ble_config); + } +} + +int HCISharedMemTransportClass::bt_ipm_set_addr(void) +{ + /* the specific table for set addr is 8 bytes: + * one byte for config_offset + * one byte for length + * 6 bytes for payload */ + uint8_t data[4 + 8]; + + phase_bd_addr = false; + + if (get_bd_address(bd_addr_udn)) { + /* create ACI_HAL_WRITE_CONFIG_DATA */ + + data[0] = BT_BUF_CMD; + data[1] = uint8_t(ACI_WRITE_CONFIG_DATA_OPCODE & 0x000000FF); /* OCF */ + data[2] = uint8_t((ACI_WRITE_CONFIG_DATA_OPCODE & 0x0000FF00) >> 8); /* OGF */ + data[3] = 8; /* length of parameters */ + /* fill the ACI_HAL_WRITE_CONFIG_DATA with the addr*/ + data[4] = CONFIG_DATA_PUBADDR_OFFSET; /* the offset */ + data[5] = 6; /* is the length of the bd_addr table */ + memcpy(data + 6, bd_addr_udn, 6); + /* send the ACI_HAL_WRITE_CONFIG_DATA */ + if (mbox_write(data[0], 11, &data[1]) != 11) { + /* Error: no data are written */ + return 0; + } + /* now wait for the corresponding Rx event */ + return 1; /* success */ + } + return 0; /* Error */ +} + + +int HCISharedMemTransportClass::bt_ipm_set_power(void) +{ + /* the specific table for power is 2 bytes: + * En_High_Power byte, PA_level byte */ + uint8_t data[4 + 2]; + + phase_tx_power = false; + + data[0] = BT_BUF_CMD; /* the type */ + data[1] = (uint8_t)(ACI_HAL_SET_TX_POWER_LEVEL & 0x000000FF); /* the OPCODE */ + data[2] = (uint8_t)((ACI_HAL_SET_TX_POWER_LEVEL & 0x0000FF00) >> 8); + data[3] = 2; /* the length */ + /* fill the SET_POWER */ + data[4] = 0x01; /* En_High_Power */ + data[5] = CFG_TX_POWER; /* PA_level */ + + /* send the SET_POWER */ + if (mbox_write(data[0], 5, &data[1]) != 5) { + /* Error: no data are written */ + return 0; + } + /* now wait for the corresponding Rx event */ + return 1; /* success */ +} + +HCITransportInterface& HCITransport = HCISharedMemTransport; +#endif /* STM32WBxx */ diff --git a/src/utility/HCISharedMemTransport.h b/src/utility/HCISharedMemTransport.h new file mode 100644 index 00000000..e739d63f --- /dev/null +++ b/src/utility/HCISharedMemTransport.h @@ -0,0 +1,93 @@ +/* + This file is part of the STM32duinoBLE library. + Copyright (c) 2019 STMicroelectronics. All rights reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef _HCI_SHARED_MEM_TRANSPORT_H_ +#define _HCI_SHARED_MEM_TRANSPORT_H_ + +#include "HCITransport.h" + +/* STM32WB include files */ +#include "stm32wbxx_ll_rcc.h" +#include "stm32wbxx_ll_ipcc.h" +#include "stm32wbxx_ll_system.h" +#include "STM32_WPAN/tl.h" +#include "STM32_WPAN/shci.h" +#include "STM32_WPAN/shci_tl.h" +#include "STM32_WPAN/app_conf.h" + +/* this one is for printing info content when HW serial enabled */ +//#define PRINT_IPCC_INFO + +/* this CONFIG_DEBUG must be defined for -Og option */ +//#define CONFIG_DEBUG + +/****************************************************************************** + * BLE config parameters + ******************************************************************************/ +/* Defined from WB Cube reference SW */ +#define CFG_TLBLE_EVT_QUEUE_LENGTH 5 +#define CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE 255 /**< Set to 255 with the memory manager and the mailbox */ +#define TL_BLE_EVENT_FRAME_SIZE ( TL_EVT_HDR_SIZE + CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE ) +#define POOL_SIZE (CFG_TLBLE_EVT_QUEUE_LENGTH*4*DIVC(( sizeof(TL_PacketHeader_t) + TL_BLE_EVENT_FRAME_SIZE ), 4)) + +#define CONFIG_DATA_PUBADDR_OFFSET (0x00) /**< Bluetooth public address */ +#define CONFIG_DATA_PUBADDR_LEN (6) + +#define BT_BUF_CMD 1 +#define BT_BUF_ACL_OUT 2 + +/* timeout (in ms) to wait for an incoming event */ +#define BLE_IPCC_TIMEOUT 10000 + +/* to received BLE packet from the SharedMem */ +void evt_received(TL_EvtPacket_t *hcievt); + +/* to send BLE packet to the SharedMem */ +uint16_t mbox_write(uint8_t type, uint16_t len, const uint8_t *pData); + +class HCISharedMemTransportClass : public HCITransportInterface { + public: + HCISharedMemTransportClass(); + virtual ~HCISharedMemTransportClass(); + + virtual int begin(); + virtual void end(); + + virtual void wait(unsigned long timeout); + + virtual int available(); + virtual int peek(); + virtual int read(); + + virtual size_t write(const uint8_t *data, size_t length); + + private: + + /* method to initialize the BLE device */ + void transport_init(void); + void start_ble_rf(void); + void stm32wb_reset(void); + int stm32wb_start_ble(void); + int bt_ipm_set_addr(void); + int bt_ipm_set_power(void); + + uint8_t _random_addr[6]; +}; + +#endif /* _HCI_SHARED_MEM_TRANSPORT_H_ */ From 4e0d7d6cf107f5d7f19dab38b506b2da7752895a Mon Sep 17 00:00:00 2001 From: Francois Ramu <francois.ramu@st.com> Date: Tue, 18 Mar 2025 09:40:37 +0100 Subject: [PATCH 211/226] feat: add the STM32Cube_FW to support stm32wb Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- src/utility/STM32_WPAN/LICENSE.md | 108 ++ src/utility/STM32_WPAN/README.md | 6 + src/utility/STM32_WPAN/app_conf.h | 20 + src/utility/STM32_WPAN/app_conf_default.h | 728 ++++++++++ src/utility/STM32_WPAN/ble_bufsize.h | 182 +++ src/utility/STM32_WPAN/hw.h | 114 ++ src/utility/STM32_WPAN/hw_ipcc.c | 749 +++++++++++ src/utility/STM32_WPAN/mbox_def.h | 280 ++++ src/utility/STM32_WPAN/shci.c | 763 +++++++++++ src/utility/STM32_WPAN/shci.h | 1402 ++++++++++++++++++++ src/utility/STM32_WPAN/shci_tl.c | 271 ++++ src/utility/STM32_WPAN/shci_tl.h | 173 +++ src/utility/STM32_WPAN/stm32_wpan_common.h | 171 +++ src/utility/STM32_WPAN/stm_list.c | 210 +++ src/utility/STM32_WPAN/stm_list.h | 55 + src/utility/STM32_WPAN/tl.h | 372 ++++++ src/utility/STM32_WPAN/tl_dbg_conf.h | 140 ++ src/utility/STM32_WPAN/tl_mbox.c | 855 ++++++++++++ src/utility/STM32_WPAN/utilities_conf.h | 66 + 19 files changed, 6665 insertions(+) create mode 100644 src/utility/STM32_WPAN/LICENSE.md create mode 100644 src/utility/STM32_WPAN/README.md create mode 100644 src/utility/STM32_WPAN/app_conf.h create mode 100644 src/utility/STM32_WPAN/app_conf_default.h create mode 100644 src/utility/STM32_WPAN/ble_bufsize.h create mode 100644 src/utility/STM32_WPAN/hw.h create mode 100644 src/utility/STM32_WPAN/hw_ipcc.c create mode 100644 src/utility/STM32_WPAN/mbox_def.h create mode 100644 src/utility/STM32_WPAN/shci.c create mode 100644 src/utility/STM32_WPAN/shci.h create mode 100644 src/utility/STM32_WPAN/shci_tl.c create mode 100644 src/utility/STM32_WPAN/shci_tl.h create mode 100644 src/utility/STM32_WPAN/stm32_wpan_common.h create mode 100644 src/utility/STM32_WPAN/stm_list.c create mode 100644 src/utility/STM32_WPAN/stm_list.h create mode 100644 src/utility/STM32_WPAN/tl.h create mode 100644 src/utility/STM32_WPAN/tl_dbg_conf.h create mode 100644 src/utility/STM32_WPAN/tl_mbox.c create mode 100644 src/utility/STM32_WPAN/utilities_conf.h diff --git a/src/utility/STM32_WPAN/LICENSE.md b/src/utility/STM32_WPAN/LICENSE.md new file mode 100644 index 00000000..4e70ee7c --- /dev/null +++ b/src/utility/STM32_WPAN/LICENSE.md @@ -0,0 +1,108 @@ +## Overview + + +This Software Bill Of Material (SBOM) lists the software components of this +software package, including the copyright owner and license terms for each +component. + +__SOFTWARE BILL OF MATERIALS__ + +Component | Copyright | License +--------- | ----------------------------------------------------------------- | ------- +Bluetooth Low Energy | STMicroelectronics | SLA +Bluetooth Low Energy LLD | STMicroelectronics | SLA +Interface | STMicroelectronics | SLA +MAC 802.15.4 | STMicroelectronics | SLA +PHY | STMicroelectronics | SLA +OpenThread | The OpenThread Authors | BSD-3-Clause +Utilities | STMicroelectronics, Amazon.com Inc. | SLA, MIT +Zigbee | Exegin Technologies Limited, STMicroelectronics, Dr Brian Gladman | SLA + + +__Notes:__ If the license is an open source license, then you can access the +terms at [www.opensource.org](https://opensource.org/). Otherwise, the full +license terms are below. If a component is not listed in the SBOM, then the SLA +shall apply unless other terms are clearly stated in the package. + + + +SLA0044 Rev5/February 2018 + +## Software license agreement + +### __ULTIMATE LIBERTY SOFTWARE LICENSE AGREEMENT__ + +BY INSTALLING, COPYING, DOWNLOADING, ACCESSING OR OTHERWISE USING THIS SOFTWARE +OR ANY PART THEREOF (AND THE RELATED DOCUMENTATION) FROM STMICROELECTRONICS +INTERNATIONAL N.V, SWISS BRANCH AND/OR ITS AFFILIATED COMPANIES +(STMICROELECTRONICS), THE RECIPIENT, ON BEHALF OF HIMSELF OR HERSELF, OR ON +BEHALF OF ANY ENTITY BY WHICH SUCH RECIPIENT IS EMPLOYED AND/OR ENGAGED AGREES +TO BE BOUND BY THIS SOFTWARE LICENSE AGREEMENT. + +Under STMicroelectronics’ intellectual property rights, the redistribution, +reproduction and use in source and binary forms of the software or any part +thereof, with or without modification, are permitted provided that the following +conditions are met: + +1. Redistribution of source code (modified or not) must retain any copyright +notice, this list of conditions and the disclaimer set forth below as items 10 +and 11. + +2. Redistributions in binary form, except as embedded into microcontroller or +microprocessor device manufactured by or for STMicroelectronics or a software +update for such device, must reproduce any copyright notice provided with the +binary code, this list of conditions, and the disclaimer set forth below as +items 10 and 11, in documentation and/or other materials provided with the +distribution. + +3. Neither the name of STMicroelectronics nor the names of other contributors to +this software may be used to endorse or promote products derived from this +software or part thereof without specific written permission. + +4. This software or any part thereof, including modifications and/or derivative +works of this software, must be used and execute solely and exclusively on or in +combination with a microcontroller or microprocessor device manufactured by or +for STMicroelectronics. + +5. No use, reproduction or redistribution of this software partially or totally +may be done in any manner that would subject this software to any Open Source +Terms. “Open Source Terms” shall mean any open source license which requires as +part of distribution of software that the source code of such software is +distributed therewith or otherwise made available, or open source license that +substantially complies with the Open Source definition specified at +www.opensource.org and any other comparable open source license such as for +example GNU General Public License (GPL), Eclipse Public License (EPL), Apache +Software License, BSD license or MIT license. + +6. STMicroelectronics has no obligation to provide any maintenance, support or +updates for the software. + +7. The software is and will remain the exclusive property of STMicroelectronics +and its licensors. The recipient will not take any action that jeopardizes +STMicroelectronics and its licensors' proprietary rights or acquire any rights +in the software, except the limited rights specified hereunder. + +8. The recipient shall comply with all applicable laws and regulations affecting +the use of the software or any part thereof including any applicable export +control law or regulation. + +9. Redistribution and use of this software or any part thereof other than as +permitted under this license is void and will automatically terminate your +rights under this license. + +10. THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY RIGHTS, WHICH ARE +DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT SHALL +STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +11. EXCEPT AS EXPRESSLY PERMITTED HEREUNDER, NO LICENSE OR OTHER RIGHTS, WHETHER +EXPRESS OR IMPLIED, ARE GRANTED UNDER ANY PATENT OR OTHER INTELLECTUAL PROPERTY +RIGHTS OF STMICROELECTRONICS OR ANY THIRD PARTY. diff --git a/src/utility/STM32_WPAN/README.md b/src/utility/STM32_WPAN/README.md new file mode 100644 index 00000000..90f96452 --- /dev/null +++ b/src/utility/STM32_WPAN/README.md @@ -0,0 +1,6 @@ + +## Source + +[STMicroelectronics/STM32CubeWB Release v1.22.0](https://github.com/STMicroelectronics/STM32CubeWB/releases/tag/v1.22.0) +- Application: [BLE_TransparentMode](https://github.com/STMicroelectronics/STM32CubeWB/tree/v1.22.0/Projects/P-NUCLEO-WB55.Nucleo/Applications/BLE/BLE_TransparentMode) + diff --git a/src/utility/STM32_WPAN/app_conf.h b/src/utility/STM32_WPAN/app_conf.h new file mode 100644 index 00000000..3246393f --- /dev/null +++ b/src/utility/STM32_WPAN/app_conf.h @@ -0,0 +1,20 @@ +//----------------------------- +// @file app_conf.h +// @author Kasper Meldgaard +// @brief Wrapper for BLE app configuration based on comment by fpistm +// (https://github.com/stm32duino/STM32duinoBLE/issues/34). +// @date 15-11-2021 +// @copyright Copyright (c) 2021 + +#ifndef APP_CONF_H +#define APP_CONF_H + +#include "hw.h" +#include "ble_bufsize.h" + +#if __has_include("app_conf_custom.h") + #include "app_conf_custom.h" +#endif +#include "app_conf_default.h" + +#endif /* APP_CONF_H */ diff --git a/src/utility/STM32_WPAN/app_conf_default.h b/src/utility/STM32_WPAN/app_conf_default.h new file mode 100644 index 00000000..ff2dc017 --- /dev/null +++ b/src/utility/STM32_WPAN/app_conf_default.h @@ -0,0 +1,728 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file app_conf_default.h + * @author MCD Application Team + * @brief Default application configuration file for STM32WPAN Middleware. + ****************************************************************************** + * @attention + * + * Copyright (c) 2020-2021 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef APP_CONF_DEFAULT_H +#define APP_CONF_DEFAULT_H + +#if 0 +#include "hw.h" +#include "hw_conf.h" +#include "hw_if.h" +#include "ble_bufsize.h" +#endif + +/****************************************************************************** + * Application Config + ******************************************************************************/ + +/**< generic parameters ******************************************************/ +/* HCI related defines */ + +#define ACI_HAL_SET_TX_POWER_LEVEL 0xFC0F +#define ACI_WRITE_CONFIG_DATA_OPCODE 0xFC0C +#define ACI_READ_CONFIG_DATA_OPCODE 0xFC0D +#define MAX_HCI_ACL_PACKET_SIZE (sizeof(TL_PacketHeader_t) + 5 + 251) +#define HCI_RESET 0x0C03 + +#ifndef BLE_SHARED_MEM_BYTE_ORDER + #define BLE_SHARED_MEM_BYTE_ORDER MSBFIRST +#endif +#define BLE_MODULE_SHARED_MEM_BUFFER_SIZE 128 + +/** + * Define Tx Power + */ +#ifndef CFG_TX_POWER + #define CFG_TX_POWER (0x18) /* -0.15dBm */ +#endif + +#if 0 +/** + * Define Secure Connections Support + */ +#define CFG_SECURE_NOT_SUPPORTED (0x00) +#define CFG_SECURE_OPTIONAL (0x01) +#define CFG_SECURE_MANDATORY (0x02) + +#define CFG_SC_SUPPORT CFG_SECURE_OPTIONAL + +/** + * Define Keypress Notification Support + */ +#define CFG_KEYPRESS_NOT_SUPPORTED (0x00) +#define CFG_KEYPRESS_SUPPORTED (0x01) + +#define CFG_KEYPRESS_NOTIFICATION_SUPPORT CFG_KEYPRESS_NOT_SUPPORTED + +/** + * Numeric Comparison Answers + */ +#define YES (0x01) +#define NO (0x00) + +/** + * Device name configuration for Generic Access Service + */ +#define CFG_GAP_DEVICE_NAME "TEMPLATE" +#define CFG_GAP_DEVICE_NAME_LENGTH (8) + +/** +* Identity root key used to derive IRK and DHK(Legacy) +*/ +#define CFG_BLE_IR {0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0} + +/** +* Encryption root key used to derive LTK(Legacy) and CSRK +*/ +#define CFG_BLE_ER {0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21, 0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21} + +/** + * SMPS supply + * SMPS not used when Set to 0 + * SMPS used when Set to 1 + */ +#define CFG_USE_SMPS 0 + +/* USER CODE BEGIN Generic_Parameters */ +/* USER CODE END Generic_Parameters */ + +/**< specific parameters */ +/*****************************************************/ + +/* USER CODE BEGIN Specific_Parameters */ +#define PUSH_BUTTON_SW1_EXTI_IRQHandler EXTI4_IRQHandler + +/* USER CODE END Specific_Parameters */ + +/****************************************************************************** + * Information Table + * + * Version + * [0:3] = Build - 0: Untracked - 15:Released - x: Tracked version + * [4:7] = branch - 0: Mass Market - x: ... + * [8:15] = Subversion + * [16:23] = Version minor + * [24:31] = Version major + * + ******************************************************************************/ +#define CFG_FW_MAJOR_VERSION (0) +#define CFG_FW_MINOR_VERSION (0) +#define CFG_FW_SUBVERSION (1) +#define CFG_FW_BRANCH (0) +#define CFG_FW_BUILD (0) +#endif + +/****************************************************************************** + * BLE Stack + ******************************************************************************/ +/** + * Maximum number of simultaneous connections that the device will support. + * Valid values are from 1 to 8 + */ +#ifndef CFG_BLE_NUM_LINK +#ifdef STM32WB15xx + #define CFG_BLE_NUM_LINK 3 +#else + #define CFG_BLE_NUM_LINK 8 +#endif +#endif + +/** + * Maximum number of Services that can be stored in the GATT database. + * Note that the GAP and GATT services are automatically added so this parameter should be 2 plus the number of user services + */ +#ifndef CFG_BLE_NUM_GATT_SERVICES +#ifdef STM32WB15xx + #define CFG_BLE_NUM_GATT_SERVICES 4 +#else + #define CFG_BLE_NUM_GATT_SERVICES 8 +#endif +#endif + +/** + * Maximum number of Attributes + * (i.e. the number of characteristic + the number of characteristic values + the number of descriptors, excluding the services) + * that can be stored in the GATT database. + * Note that certain characteristics and relative descriptors are added automatically during device initialization + * so this parameters should be 9 plus the number of user Attributes + */ +#ifndef CFG_BLE_NUM_GATT_ATTRIBUTES +#ifdef STM32WB15xx + #define CFG_BLE_NUM_GATT_ATTRIBUTES 30 +#else + #define CFG_BLE_NUM_GATT_ATTRIBUTES 68 +#endif +#endif + +/** + * Maximum supported ATT_MTU size + * This parameter is ignored by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set + */ +#define CFG_BLE_MAX_ATT_MTU (156) + +/** + * Size of the storage area for Attribute values + * This value depends on the number of attributes used by application. In particular the sum of the following quantities (in octets) should be made for each attribute: + * - attribute value length + * - 5, if UUID is 16 bit; 19, if UUID is 128 bit + * - 2, if server configuration descriptor is used + * - 2*DTM_NUM_LINK, if client configuration descriptor is used + * - 2, if extended properties is used + * The total amount of memory needed is the sum of the above quantities for each attribute. + * This parameter is ignored by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set + */ +#define CFG_BLE_ATT_VALUE_ARRAY_SIZE (1344) + +/** + * Prepare Write List size in terms of number of packet + * This parameter is ignored by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set + */ +#define CFG_BLE_PREPARE_WRITE_LIST_SIZE BLE_PREP_WRITE_X_ATT(CFG_BLE_MAX_ATT_MTU) + +/** + * Number of allocated memory blocks + * This parameter is overwritten by the CPU2 with an hardcoded optimal value when the parameter CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY flag set + */ +#define CFG_BLE_MBLOCK_COUNT (BLE_MBLOCKS_CALC(CFG_BLE_PREPARE_WRITE_LIST_SIZE, CFG_BLE_MAX_ATT_MTU, CFG_BLE_NUM_LINK)) + +/** + * Enable or disable the Extended Packet length feature. Valid values are 0 or 1. + */ +#ifndef CFG_BLE_DATA_LENGTH_EXTENSION + #define CFG_BLE_DATA_LENGTH_EXTENSION 1 +#endif + +/** + * Sleep clock accuracy in Peripheral mode (ppm value) + */ +#ifndef CFG_BLE_PERIPHERAL_SCA + #define CFG_BLE_PERIPHERAL_SCA 500 +#endif + +/** + * Sleep clock accuracy in Central mode + * 0 : 251 ppm to 500 ppm + * 1 : 151 ppm to 250 ppm + * 2 : 101 ppm to 150 ppm + * 3 : 76 ppm to 100 ppm + * 4 : 51 ppm to 75 ppm + * 5 : 31 ppm to 50 ppm + * 6 : 21 ppm to 30 ppm + * 7 : 0 ppm to 20 ppm + */ +#ifndef CFG_BLE_CENTRAL_SCA + #define CFG_BLE_CENTRAL_SCA 0 +#endif + +/** + * LsSource + * Some information for Low speed clock mapped in bits field + * - bit 0: 1: Calibration for the RF system wakeup clock source 0: No calibration for the RF system wakeup clock source + * - bit 1: 1: STM32WB5M Module device 0: Other devices as STM32WBxx SOC, STM32WB1M module + * - bit 2: 1: HSE/1024 Clock config 0: LSE Clock config + */ +#ifndef CFG_BLE_LS_SOURCE + #if defined(STM32WB5Mxx) + #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_MOD5MM_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) + #else + #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_OTHER_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) + #endif +#endif + +/** + * Start up time of the high speed (16 or 32 MHz) crystal oscillator in units of 625/256 us (~2.44 us) + */ +#ifndef CFG_BLE_HSE_STARTUP_TIME + #define CFG_BLE_HSE_STARTUP_TIME 0x148 +#endif + +/** + * Maximum duration of the connection event when the device is in Peripheral mode in units of 625/256 us (~2.44 us) + */ +#ifndef CFG_BLE_MAX_CONN_EVENT_LENGTH + #define CFG_BLE_MAX_CONN_EVENT_LENGTH (0xFFFFFFFF) +#endif + +/** + * Viterbi Mode + * 1 : enabled + * 0 : disabled + */ +#define CFG_BLE_VITERBI_MODE 1 + +/** + * BLE stack Options flags to be configured with: + * - SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY + * - SHCI_C2_BLE_INIT_OPTIONS_LL_HOST + * - SHCI_C2_BLE_INIT_OPTIONS_NO_SVC_CHANGE_DESC + * - SHCI_C2_BLE_INIT_OPTIONS_WITH_SVC_CHANGE_DESC + * - SHCI_C2_BLE_INIT_OPTIONS_DEVICE_NAME_RO + * - SHCI_C2_BLE_INIT_OPTIONS_DEVICE_NAME_RW + * - SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV + * - SHCI_C2_BLE_INIT_OPTIONS_NO_EXT_ADV + * - SHCI_C2_BLE_INIT_OPTIONS_CS_ALGO2 + * - SHCI_C2_BLE_INIT_OPTIONS_NO_CS_ALGO2 + * - SHCI_C2_BLE_INIT_OPTIONS_REDUC_GATTDB_NVM + * - SHCI_C2_BLE_INIT_OPTIONS_FULL_GATTDB_NVM + * - SHCI_C2_BLE_INIT_OPTIONS_GATT_CACHING_USED + * - SHCI_C2_BLE_INIT_OPTIONS_GATT_CACHING_NOTUSED + * - SHCI_C2_BLE_INIT_OPTIONS_POWER_CLASS_1 + * - SHCI_C2_BLE_INIT_OPTIONS_POWER_CLASS_2_3 + * which are used to set following configuration bits: + * (bit 0): 1: LL only + * 0: LL + host + * (bit 1): 1: no service change desc. + * 0: with service change desc. + * (bit 2): 1: device name Read-Only + * 0: device name R/W + * (bit 3): 1: extended advertizing supported + * 0: extended advertizing not supported + * (bit 4): 1: CS Algo #2 supported + * 0: CS Algo #2 not supported + * (bit 5): 1: Reduced GATT database in NVM + * 0: Full GATT database in NVM + * (bit 6): 1: GATT caching is used + * 0: GATT caching is not used + * (bit 7): 1: LE Power Class 1 + * 0: LE Power Class 2-3 + * other bits: complete with Options_extension flag + */ +#define CFG_BLE_OPTIONS (SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY | SHCI_C2_BLE_INIT_OPTIONS_WITH_SVC_CHANGE_DESC | SHCI_C2_BLE_INIT_OPTIONS_DEVICE_NAME_RW | SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV | SHCI_C2_BLE_INIT_OPTIONS_CS_ALGO2 | SHCI_C2_BLE_INIT_OPTIONS_FULL_GATTDB_NVM | SHCI_C2_BLE_INIT_OPTIONS_GATT_CACHING_NOTUSED | SHCI_C2_BLE_INIT_OPTIONS_POWER_CLASS_2_3) + +/** + * BLE stack Options_extension flags to be configured with: + * - SHCI_C2_BLE_INIT_OPTIONS_APPEARANCE_WRITABLE + * - SHCI_C2_BLE_INIT_OPTIONS_APPEARANCE_READONLY + * - SHCI_C2_BLE_INIT_OPTIONS_ENHANCED_ATT_SUPPORTED + * - SHCI_C2_BLE_INIT_OPTIONS_ENHANCED_ATT_NOTSUPPORTED + * which are used to set following configuration bits: + * (bit 0): 1: appearance Writable + * 0: appearance Read-Only + * (bit 1): 1: Enhanced ATT supported + * 0: Enhanced ATT not supported + * other bits: reserved (shall be set to 0) + */ +#define CFG_BLE_OPTIONS_EXT (SHCI_C2_BLE_INIT_OPTIONS_APPEARANCE_READONLY | SHCI_C2_BLE_INIT_OPTIONS_ENHANCED_ATT_NOTSUPPORTED) + +#define CFG_BLE_MAX_COC_INITIATOR_NBR (32) + +#define CFG_BLE_MIN_TX_POWER (-40) + +#define CFG_BLE_MAX_TX_POWER (6) + +/** + * BLE Rx model configuration flags to be configured with: + * - SHCI_C2_BLE_INIT_RX_MODEL_AGC_RSSI_LEGACY + * - SHCI_C2_BLE_INIT_RX_MODEL_AGC_RSSI_BLOCKER + * which are used to set following configuration bits: + * (bit 0): 1: agc_rssi model improved vs RF blockers + * 0: Legacy agc_rssi model + * other bits: reserved (shall be set to 0) + */ + +#define CFG_BLE_RX_MODEL_CONFIG (SHCI_C2_BLE_INIT_RX_MODEL_AGC_RSSI_LEGACY) + +/* Maximum number of advertising sets. + * Range: 1 .. 8 with limitation: + * This parameter is linked to CFG_BLE_MAX_ADV_DATA_LEN such as both compliant with allocated Total memory computed with BLE_EXT_ADV_BUFFER_SIZE based + * on Max Extended advertising configuration supported. + * This parameter is considered by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV flag set + */ + +#if defined(STM32WB15xx) + #define CFG_BLE_MAX_ADV_SET_NBR (3) +#else + #define CFG_BLE_MAX_ADV_SET_NBR (8) +#endif + + /* Maximum advertising data length (in bytes) + * Range: 31 .. 1650 with limitation: + * This parameter is linked to CFG_BLE_MAX_ADV_SET_NBR such as both compliant with allocated Total memory computed with BLE_EXT_ADV_BUFFER_SIZE based + * on Max Extended advertising configuration supported. + * This parameter is considered by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV flag set + */ + +#if defined(STM32WB15xx) + #define CFG_BLE_MAX_ADV_DATA_LEN (414) +#else + #define CFG_BLE_MAX_ADV_DATA_LEN (207) +#endif + + /* RF TX Path Compensation Value (16-bit signed integer). Units: 0.1 dB. + * Range: -1280 .. 1280 + */ + +#define CFG_BLE_TX_PATH_COMPENS (0) + + /* RF RX Path Compensation Value (16-bit signed integer). Units: 0.1 dB. + * Range: -1280 .. 1280 + */ + +#define CFG_BLE_RX_PATH_COMPENS (0) + + /* BLE core version (16-bit signed integer). + * - SHCI_C2_BLE_INIT_BLE_CORE_5_2 + * - SHCI_C2_BLE_INIT_BLE_CORE_5_3 + * - SHCI_C2_BLE_INIT_BLE_CORE_5_4 + * which are used to set: 11(5.2), 12(5.3), 13(5.4). + */ + +#define CFG_BLE_CORE_VERSION (SHCI_C2_BLE_INIT_BLE_CORE_5_4) + +#if 0 +/****************************************************************************** + * Transport Layer + ******************************************************************************/ +/** + * Queue length of BLE Event + * This parameter defines the number of asynchronous events that can be stored in the HCI layer before + * being reported to the application. When a command is sent to the BLE core coprocessor, the HCI layer + * is waiting for the event with the Num_HCI_Command_Packets set to 1. The receive queue shall be large + * enough to store all asynchronous events received in between. + * When CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE is set to 27, this allow to store three 255 bytes long asynchronous events + * between the HCI command and its event. + * This parameter depends on the value given to CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE. When the queue size is to small, + * the system may hang if the queue is full with asynchronous events and the HCI layer is still waiting + * for a CC/CS event, In that case, the notification TL_BLE_HCI_ToNot() is called to indicate + * to the application a HCI command did not receive its command event within 30s (Default HCI Timeout). + */ +#define CFG_TLBLE_EVT_QUEUE_LENGTH 5 +/** + * This parameter should be set to fit most events received by the HCI layer. It defines the buffer size of each element + * allocated in the queue of received events and can be used to optimize the amount of RAM allocated by the Memory Manager. + * It should not exceed 255 which is the maximum HCI packet payload size (a greater value is a lost of memory as it will + * never be used) + * It shall be at least 4 to receive the command status event in one frame. + * The default value is set to 27 to allow receiving an event of MTU size in a single buffer. This value maybe reduced + * further depending on the application. + */ +#define CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE 255 /**< Set to 255 with the memory manager and the mailbox */ + +#define TL_BLE_EVENT_FRAME_SIZE ( TL_EVT_HDR_SIZE + CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE ) +/****************************************************************************** + * UART interfaces + ******************************************************************************/ + +/** + * Select UART interfaces + */ +#define CFG_UART_GUI hw_uart1 +#define CFG_DEBUG_TRACE_UART 0 +/****************************************************************************** + * USB interface + ******************************************************************************/ + +/** + * Enable/Disable USB interface + */ +#define CFG_USB_INTERFACE_ENABLE 0 + +/****************************************************************************** + * IPCC interface + ******************************************************************************/ + +/** + * The IPCC is dedicated to the communication between the CPU2 and the CPU1 + * and shall not be modified by the application + * The two following definitions shall not be modified + */ +#define HAL_IPCC_TX_IRQHandler(...) HW_IPCC_Tx_Handler( ) +#define HAL_IPCC_RX_IRQHandler(...) HW_IPCC_Rx_Handler( ) + +/****************************************************************************** + * Low Power + ******************************************************************************/ +/** + * When set to 1, the low power mode is enable + * When set to 0, the device stays in RUN mode + */ +#define CFG_LPM_SUPPORTED 1 + +/****************************************************************************** + * RTC interface + ******************************************************************************/ +#define HAL_RTCEx_WakeUpTimerIRQHandler(...) HW_TS_RTC_Wakeup_Handler( ) + +/****************************************************************************** + * Timer Server + ******************************************************************************/ +/** + * CFG_RTC_WUCKSEL_DIVIDER: This sets the RTCCLK divider to the wakeup timer. + * The lower is the value, the better is the power consumption and the accuracy of the timerserver + * The higher is the value, the finest is the granularity + * + * CFG_RTC_ASYNCH_PRESCALER: This sets the asynchronous prescaler of the RTC. It should as high as possible ( to output + * clock as low as possible) but the output clock should be equal or higher frequency compare to the clock feeding + * the wakeup timer. A lower clock speed would impact the accuracy of the timer server. + * + * CFG_RTC_SYNCH_PRESCALER: This sets the synchronous prescaler of the RTC. + * When the 1Hz calendar clock is required, it shall be sets according to other settings + * When the 1Hz calendar clock is not needed, CFG_RTC_SYNCH_PRESCALER should be set to 0x7FFF (MAX VALUE) + * + * CFG_RTCCLK_DIVIDER_CONF: + * Shall be set to either 0,2,4,8,16 + * When set to either 2,4,8,16, the 1Hhz calendar is supported + * When set to 0, the user sets its own configuration + * + * The following settings are computed with LSI as input to the RTC + */ + +#define CFG_RTCCLK_DIVIDER_CONF 0 + +#if (CFG_RTCCLK_DIVIDER_CONF == 0) +/** + * Custom configuration + * It does not support 1Hz calendar + * It divides the RTC CLK by 16 + */ + +#define CFG_RTCCLK_DIV (16) +#define CFG_RTC_WUCKSEL_DIVIDER (0) +#define CFG_RTC_ASYNCH_PRESCALER (0x0F) +#define CFG_RTC_SYNCH_PRESCALER (0x7FFF) + +#else + +#if (CFG_RTCCLK_DIVIDER_CONF == 2) +/** + * It divides the RTC CLK by 2 + */ +#define CFG_RTC_WUCKSEL_DIVIDER (3) +#endif + +#if (CFG_RTCCLK_DIVIDER_CONF == 4) +/** + * It divides the RTC CLK by 4 + */ +#define CFG_RTC_WUCKSEL_DIVIDER (2) +#endif + +#if (CFG_RTCCLK_DIVIDER_CONF == 8) +/** + * It divides the RTC CLK by 8 + */ +#define CFG_RTC_WUCKSEL_DIVIDER (1) +#endif + +#if (CFG_RTCCLK_DIVIDER_CONF == 16) +/** + * It divides the RTC CLK by 16 + */ +#define CFG_RTC_WUCKSEL_DIVIDER (0) +#endif + +#define CFG_RTCCLK_DIV CFG_RTCCLK_DIVIDER_CONF +#define CFG_RTC_ASYNCH_PRESCALER (CFG_RTCCLK_DIV - 1) +#define CFG_RTC_SYNCH_PRESCALER (DIVR( LSE_VALUE, (CFG_RTC_ASYNCH_PRESCALER+1) ) - 1 ) + +#endif + +/** tick timer values */ +#define CFG_TS_TICK_VAL DIVR( (CFG_RTCCLK_DIV * 1000000), LSE_VALUE ) +#define CFG_TS_TICK_VAL_PS DIVR( ((uint64_t)CFG_RTCCLK_DIV * 1e12), (uint64_t)LSE_VALUE ) + +typedef enum +{ + CFG_TIM_PROC_ID_ISR, + /* USER CODE BEGIN CFG_TimProcID_t */ + + /* USER CODE END CFG_TimProcID_t */ +} CFG_TimProcID_t; + +/****************************************************************************** + * Debug + ******************************************************************************/ +/** + * When set, this resets some hw resources to put the device in the same state as at power up. + * It resets only register that may prevent the FW to run properly. + * + * This shall be set to 0 in a final product + * + */ +#define CFG_HW_RESET_BY_FW 0 + +/** + * keep debugger enabled while in any low power mode when set to 1 + * should be set to 0 in production + */ +#define CFG_DEBUGGER_SUPPORTED 0 + +/** + * When set to 1, the traces are enabled in the BLE services + */ +#define CFG_DEBUG_BLE_TRACE 0 + +/** + * Enable or Disable traces in application + */ +#define CFG_DEBUG_APP_TRACE 0 + +#if (CFG_DEBUG_APP_TRACE != 0) +#define APP_DBG_MSG PRINT_MESG_DBG +#else +#define APP_DBG_MSG PRINT_NO_MESG +#endif + +#if ( (CFG_DEBUG_BLE_TRACE != 0) || (CFG_DEBUG_APP_TRACE != 0) ) +#define CFG_DEBUG_TRACE 1 +#endif + +#if (CFG_DEBUG_TRACE != 0) +#undef CFG_LPM_SUPPORTED +#undef CFG_DEBUGGER_SUPPORTED +#define CFG_LPM_SUPPORTED 0 +#define CFG_DEBUGGER_SUPPORTED 1 +#endif + +/** + * When CFG_DEBUG_TRACE_FULL is set to 1, the trace are output with the API name, the file name and the line number + * When CFG_DEBUG_TRACE_LIGHT is set to 1, only the debug message is output + * + * When both are set to 0, no trace are output + * When both are set to 1, CFG_DEBUG_TRACE_FULL is selected + */ +#define CFG_DEBUG_TRACE_LIGHT 0 +#define CFG_DEBUG_TRACE_FULL 0 + +#if (( CFG_DEBUG_TRACE != 0 ) && ( CFG_DEBUG_TRACE_LIGHT == 0 ) && (CFG_DEBUG_TRACE_FULL == 0)) +#undef CFG_DEBUG_TRACE_FULL +#undef CFG_DEBUG_TRACE_LIGHT +#define CFG_DEBUG_TRACE_FULL 0 +#define CFG_DEBUG_TRACE_LIGHT 1 +#endif + +#if ( CFG_DEBUG_TRACE == 0 ) +#undef CFG_DEBUG_TRACE_FULL +#undef CFG_DEBUG_TRACE_LIGHT +#define CFG_DEBUG_TRACE_FULL 0 +#define CFG_DEBUG_TRACE_LIGHT 0 +#endif + +/** + * When not set, the traces is looping on sending the trace over UART + */ +#define DBG_TRACE_USE_CIRCULAR_QUEUE 1 + +/** + * max buffer Size to queue data traces and max data trace allowed. + * Only Used if DBG_TRACE_USE_CIRCULAR_QUEUE is defined + */ +#define DBG_TRACE_MSG_QUEUE_SIZE 4096 +#define MAX_DBG_TRACE_MSG_SIZE 1024 + +/* USER CODE BEGIN Defines */ +#define CFG_LED_SUPPORTED 1 +#define CFG_BUTTON_SUPPORTED 1 + +#define PUSH_BUTTON_SW1_EXTI_IRQHandler EXTI4_IRQHandler +#define PUSH_BUTTON_SW2_EXTI_IRQHandler EXTI0_IRQHandler +#define PUSH_BUTTON_SW3_EXTI_IRQHandler EXTI1_IRQHandler +/* USER CODE END Defines */ + +/****************************************************************************** + * Scheduler + ******************************************************************************/ + +/** + * These are the lists of task id registered to the scheduler + * Each task id shall be in the range [0:31] + * This mechanism allows to implement a generic code in the API TL_BLE_HCI_StatusNot() to comply with + * the requirement that a HCI/ACI command shall never be sent if there is already one pending + */ + +/**< Add in that list all tasks that may send a ACI/HCI command */ +typedef enum +{ + CFG_TASK_BLE_HCI_CMD_ID, + CFG_TASK_SYS_HCI_CMD_ID, + CFG_TASK_HCI_ACL_DATA_ID, + CFG_TASK_SYS_LOCAL_CMD_ID, + CFG_TASK_TX_TO_HOST_ID, + /* USER CODE BEGIN CFG_Task_Id_With_HCI_Cmd_t */ + CFG_TASK_SW1_BUTTON_PUSHED_ID, + CFG_TASK_SW2_BUTTON_PUSHED_ID, + CFG_TASK_SW3_BUTTON_PUSHED_ID, + /* USER CODE END CFG_Task_Id_With_HCI_Cmd_t */ + CFG_LAST_TASK_ID_WITH_HCICMD, /**< Shall be LAST in the list */ +} CFG_Task_Id_With_HCI_Cmd_t; + +/**< Add in that list all tasks that never send a ACI/HCI command */ +typedef enum +{ + CFG_FIRST_TASK_ID_WITH_NO_HCICMD = CFG_LAST_TASK_ID_WITH_HCICMD - 1, /**< Shall be FIRST in the list */ + CFG_TASK_SYSTEM_HCI_ASYNCH_EVT_ID, + /* USER CODE BEGIN CFG_Task_Id_With_NO_HCI_Cmd_t */ + + /* USER CODE END CFG_Task_Id_With_NO_HCI_Cmd_t */ + CFG_LAST_TASK_ID_WITH_NO_HCICMD /**< Shall be LAST in the list */ +} CFG_Task_Id_With_NO_HCI_Cmd_t; + +#define CFG_TASK_NBR CFG_LAST_TASK_ID_WITH_NO_HCICMD + +/** + * This is the list of priority required by the application + * Each Id shall be in the range 0..31 + */ +typedef enum +{ + CFG_SCH_PRIO_0, + /* USER CODE BEGIN CFG_SCH_Prio_Id_t */ + + /* USER CODE END CFG_SCH_Prio_Id_t */ + CFG_SCH_PRIO_NBR +} CFG_SCH_Prio_Id_t; + +/** + * This is a bit mapping over 32bits listing all events id supported in the application + */ +typedef enum +{ + CFG_IDLEEVT_SYSTEM_HCI_CMD_EVT_RSP_ID, + /* USER CODE BEGIN CFG_IdleEvt_Id_t */ + + /* USER CODE END CFG_IdleEvt_Id_t */ +} CFG_IdleEvt_Id_t; + +/****************************************************************************** + * LOW POWER + ******************************************************************************/ +/** + * Supported requester to the MCU Low Power Manager - can be increased up to 32 + * It list a bit mapping of all user of the Low Power Manager + */ +typedef enum +{ + CFG_LPM_APP, + CFG_LPM_APP_BLE, + /* USER CODE BEGIN CFG_LPM_Id_t */ + + /* USER CODE END CFG_LPM_Id_t */ +} CFG_LPM_Id_t; + +/****************************************************************************** + * OTP manager + ******************************************************************************/ +#define CFG_OTP_BASE_ADDRESS OTP_AREA_BASE + +#define CFG_OTP_END_ADRESS OTP_AREA_END_ADDR + +#endif +#endif /*APP_CONF_DEFAULT_H */ diff --git a/src/utility/STM32_WPAN/ble_bufsize.h b/src/utility/STM32_WPAN/ble_bufsize.h new file mode 100644 index 00000000..26551c09 --- /dev/null +++ b/src/utility/STM32_WPAN/ble_bufsize.h @@ -0,0 +1,182 @@ +/***************************************************************************** + * @file ble_bufsize.h + * + * @brief Definition of BLE stack buffers size + ***************************************************************************** + * @attention + * + * Copyright (c) 2018-2025 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ***************************************************************************** + */ + +#ifndef BLE_BUFSIZE_H__ +#define BLE_BUFSIZE_H__ + + +/* + * BLE_DEFAULT_ATT_MTU: minimum MTU value that GATT must support. + */ +#define BLE_DEFAULT_ATT_MTU 23 + +/* + * BLE_DEFAULT_MAX_ATT_SIZE: maximum attribute size. + */ +#define BLE_DEFAULT_MAX_ATT_SIZE 512 + +/* + * BLE_PREP_WRITE_X_ATT: compute how many Prepare Write Request are needed to + * write a characteristic with size 'max_att' when the used ATT_MTU value is + * equal to BLE_DEFAULT_ATT_MTU (23). + */ +#define BLE_PREP_WRITE_X_ATT(max_att) \ + (DIVC(max_att, BLE_DEFAULT_ATT_MTU - 5) * 2) + +/* + * BLE_DEFAULT_PREP_WRITE_LIST_SIZE: default minimum Prepare Write List size. + */ +#define BLE_DEFAULT_PREP_WRITE_LIST_SIZE \ + BLE_PREP_WRITE_X_ATT(BLE_DEFAULT_MAX_ATT_SIZE) + +/* + * BLE_MEM_BLOCK_X_MTU: compute how many memory blocks are needed to compose + * an ATT packet with ATT_MTU=mtu. + */ +#define BLE_MEM_BLOCK_SIZE 32 + +#if (SLAVE_ONLY != 0) || (BASIC_FEATURES != 0) +#define BLE_MEM_BLOCK_X_PTX(n_link) 0 +#else +#define BLE_MEM_BLOCK_X_PTX(n_link) (n_link) +#endif + +#define BLE_MEM_BLOCK_X_TX(mtu) \ + (DIVC((mtu) + 4U, BLE_MEM_BLOCK_SIZE) + 1) + +#define BLE_MEM_BLOCK_X_RX(mtu, n_link) \ + ((DIVC((mtu) + 4U, BLE_MEM_BLOCK_SIZE) + 2U) * (n_link) + 1) + +#define BLE_MEM_BLOCK_X_MTU(mtu, n_link) \ + (BLE_MEM_BLOCK_X_TX(mtu) + BLE_MEM_BLOCK_X_PTX(n_link) + \ + BLE_MEM_BLOCK_X_RX(mtu, n_link)) + +/* + * BLE_MBLOCKS_SECURE_CONNECTIONS: minimum number of blocks required for + * secure connections + */ +#define BLE_MBLOCKS_SECURE_CONNECTIONS 4 + +/* + * BLE_MBLOCKS_CALC: minimum number of buffers needed by the stack. + * This is the minimum racomanded value and depends on: + * - pw: size of Prepare Write List + * - mtu: ATT_MTU size + * - n_link: maximum number of simultaneous connections + */ +#define BLE_MBLOCKS_CALC(pw, mtu, n_link) \ + ((pw) + MAX(BLE_MEM_BLOCK_X_MTU(mtu, n_link), \ + BLE_MBLOCKS_SECURE_CONNECTIONS)) + +/* + * BLE_FIXED_BUFFER_SIZE_BYTES: + * A part of the RAM, is dynamically allocated by initializing all the pointers + * defined in a global context variable "mem_alloc_ctx_p". + * This initialization is made in the Dynamic_allocator functions, which + * assign a portion of RAM given by the external application to the above + * mentioned "global pointers". + * + * The size of this Dynamic RAM is made of 2 main components: + * - a part that is parameters-dependent (num of links, GATT buffers, ...), + * and which value is made explicit by the following macro; + * - a part, that may be considered "fixed", i.e. independent from the above + * mentioned parameters. +*/ +#if (BEACON_ONLY != 0) +#define BLE_FIXED_BUFFER_SIZE_BYTES 4200 /* Beacon only */ +#elif (LL_ONLY_BASIC != 0) +#define BLE_FIXED_BUFFER_SIZE_BYTES 6040 /* LL only Basic*/ +#elif (LL_ONLY != 0) +#define BLE_FIXED_BUFFER_SIZE_BYTES 6288 /* LL only Full */ +#elif (SLAVE_ONLY != 0) +#define BLE_FIXED_BUFFER_SIZE_BYTES 6408 /* Peripheral only */ +#elif (BASIC_FEATURES != 0) +#define BLE_FIXED_BUFFER_SIZE_BYTES 7184 /* Basic Features */ +#else +#define BLE_FIXED_BUFFER_SIZE_BYTES 7468 /* Full stack */ +#endif + +/* + * BLE_PER_LINK_SIZE_BYTES: additional memory size used per link + */ +#if (BEACON_ONLY != 0) +#define BLE_PER_LINK_SIZE_BYTES 76 /* Beacon only */ +#elif (LL_ONLY_BASIC != 0) +#define BLE_PER_LINK_SIZE_BYTES 244 /* LL only Basic */ +#elif (LL_ONLY != 0) +#define BLE_PER_LINK_SIZE_BYTES 244 /* LL only Full */ +#elif (SLAVE_ONLY != 0) +#define BLE_PER_LINK_SIZE_BYTES 392 /* Peripheral only */ +#elif (BASIC_FEATURES != 0) +#define BLE_PER_LINK_SIZE_BYTES 420 /* Basic Features */ +#else +#define BLE_PER_LINK_SIZE_BYTES 432 /* Full stack */ +#endif + +/* + * BLE_TOTAL_BUFFER_SIZE: this macro returns the amount of memory, in bytes, + * needed for the storage of data structures (except GATT database elements) + * whose size depends on the number of supported connections. + * + * @param n_link: Maximum number of simultaneous connections that the device + * will support. Valid values are from 1 to 8. + * + * @param mblocks_count: Number of memory blocks allocated for packets. + */ +#define BLE_TOTAL_BUFFER_SIZE(n_link, mblocks_count) \ + (16 + BLE_FIXED_BUFFER_SIZE_BYTES + \ + (BLE_PER_LINK_SIZE_BYTES * (n_link)) + \ + ((BLE_MEM_BLOCK_SIZE + 8) * (mblocks_count))) + +/* + * BLE_EXT_ADV_BUFFER_SIZE + * additional memory size used for Extended advertising; + * It has to be added to BLE_TOTAL_BUFFER_SIZE() if the Extended advertising + * feature is used. + * + * @param set_nbr: Maximum number of advertising sets. + * Valid values are from 1 to 8. + * + * @param data_len: Maximum size of advertising data. + * Valid values are from 31 to 1650. + */ +#define BLE_EXT_ADV_BUFFER_SIZE(set_nbr, data_len) \ + (2512 + ((892 + (DIVC(data_len, 207) * 244)) * (set_nbr))) + +/* + * BLE_TOTAL_BUFFER_SIZE_GATT: this macro returns the amount of memory, + * in bytes, needed for the storage of GATT database elements. + * + * @param num_gatt_attributes: Maximum number of Attributes (i.e. the number + * of characteristic + the number of characteristic values + the number of + * descriptors, excluding the services) that can be stored in the GATT + * database. Note that certain characteristics and relative descriptors are + * added automatically during device initialization so this parameters should + * be 9 plus the number of user Attributes + * + * @param num_gatt_services: Maximum number of Services that can be stored in + * the GATT database. Note that the GAP and GATT services are automatically + * added so this parameter should be 2 plus the number of user services + * + * @param att_value_array_size: Size of the storage area for Attribute values. + */ +#define BLE_TOTAL_BUFFER_SIZE_GATT(num_gatt_attributes, num_gatt_services, att_value_array_size) \ + (((((att_value_array_size) - 1) | 3) + 1) + \ + (40 * (num_gatt_attributes)) + (48 * (num_gatt_services))) + + +#endif /* BLE_BUFSIZE_H__ */ diff --git a/src/utility/STM32_WPAN/hw.h b/src/utility/STM32_WPAN/hw.h new file mode 100644 index 00000000..1472a5e8 --- /dev/null +++ b/src/utility/STM32_WPAN/hw.h @@ -0,0 +1,114 @@ +/** + ****************************************************************************** + * @file hw.h + * @author MCD Application Team + * @brief Hardware + ****************************************************************************** + * @attention + * + * Copyright (c) 2018-2021 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ + + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __HW_H +#define __HW_H + +#ifdef __cplusplus +extern "C" { +#endif + + /* Includes ------------------------------------------------------------------*/ +#include "stm32_def.h" +#include "stm32wbxx_ll_bus.h" +#include "stm32wbxx_ll_exti.h" +#include "stm32wbxx_ll_system.h" +#include "stm32wbxx_ll_rcc.h" +#include "stm32wbxx_ll_ipcc.h" +#include "stm32wbxx_ll_cortex.h" +#include "stm32wbxx_ll_utils.h" +#include "stm32wbxx_ll_pwr.h" + + /****************************************************************************** + * HW IPCC + ******************************************************************************/ + void HW_IPCC_Enable( void ); + void HW_IPCC_Init( void ); +#define HW_IPCC_Rx_Handler IPCC_C1_RX_IRQHandler +#define HW_IPCC_Tx_Handler IPCC_C1_TX_IRQHandler + + void HW_IPCC_BLE_Init( void ); + void HW_IPCC_BLE_SendCmd( void ); + void HW_IPCC_MM_SendFreeBuf( void (*cb)( void ) ); + void HW_IPCC_BLE_RxEvtNot( void ); + void HW_IPCC_BLE_SendAclData( void ); + void HW_IPCC_BLE_AclDataAckNot( void ); + + void HW_IPCC_SYS_Init( void ); + void HW_IPCC_SYS_SendCmd( void ); + void HW_IPCC_SYS_CmdEvtNot( void ); + void HW_IPCC_SYS_EvtNot( void ); + + void HW_IPCC_THREAD_Init( void ); + void HW_IPCC_OT_SendCmd( void ); + void HW_IPCC_CLI_SendCmd( void ); + void HW_IPCC_THREAD_SendAck( void ); + void HW_IPCC_OT_CmdEvtNot( void ); + void HW_IPCC_CLI_CmdEvtNot( void ); + void HW_IPCC_THREAD_EvtNot( void ); + void HW_IPCC_THREAD_CliSendAck( void ); + void HW_IPCC_THREAD_CliEvtNot( void ); + + + void HW_IPCC_LLDTESTS_Init( void ); + void HW_IPCC_LLDTESTS_SendCliCmd( void ); + void HW_IPCC_LLDTESTS_ReceiveCliRsp( void ); + void HW_IPCC_LLDTESTS_SendCliRspAck( void ); + void HW_IPCC_LLDTESTS_ReceiveM0Cmd( void ); + void HW_IPCC_LLDTESTS_SendM0CmdAck( void ); + + + void HW_IPCC_BLE_LLD_Init( void ); + void HW_IPCC_BLE_LLD_SendCliCmd( void ); + void HW_IPCC_BLE_LLD_ReceiveCliRsp( void ); + void HW_IPCC_BLE_LLD_SendCliRspAck( void ); + void HW_IPCC_BLE_LLD_ReceiveM0Cmd( void ); + void HW_IPCC_BLE_LLD_SendM0CmdAck( void ); + void HW_IPCC_BLE_LLD_SendCmd( void ); + void HW_IPCC_BLE_LLD_ReceiveRsp( void ); + void HW_IPCC_BLE_LLD_SendRspAck( void ); + + + void HW_IPCC_TRACES_Init( void ); + void HW_IPCC_TRACES_EvtNot( void ); + + void HW_IPCC_MAC_802_15_4_Init( void ); + void HW_IPCC_MAC_802_15_4_SendCmd( void ); + void HW_IPCC_MAC_802_15_4_SendAck( void ); + void HW_IPCC_MAC_802_15_4_CmdEvtNot( void ); + void HW_IPCC_MAC_802_15_4_EvtNot( void ); + + void HW_IPCC_ZIGBEE_Init( void ); + + void HW_IPCC_ZIGBEE_SendM4RequestToM0(void); /* M4 Request to M0 */ + void HW_IPCC_ZIGBEE_RecvAppliAckFromM0(void); /* Request ACK from M0 */ + + void HW_IPCC_ZIGBEE_RecvM0NotifyToM4(void); /* M0 Notify to M4 */ + void HW_IPCC_ZIGBEE_SendM4AckToM0Notify(void); /* Notify ACK from M4 */ + void HW_IPCC_ZIGBEE_RecvM0RequestToM4(void); /* M0 Request to M4 */ + void HW_IPCC_ZIGBEE_SendM4AckToM0Request(void); /* Request ACK from M4 */ + + +#ifdef __cplusplus +} +#endif + +#endif /*__HW_H */ + diff --git a/src/utility/STM32_WPAN/hw_ipcc.c b/src/utility/STM32_WPAN/hw_ipcc.c new file mode 100644 index 00000000..ad3c9d4c --- /dev/null +++ b/src/utility/STM32_WPAN/hw_ipcc.c @@ -0,0 +1,749 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file hw_ipcc.c + * @author MCD Application Team + * @brief Hardware IPCC source file for STM32WPAN Middleware. + ****************************************************************************** + * @attention + * + * Copyright (c) 2020-2021 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ + +#if defined(STM32WBxx) +/* Includes ------------------------------------------------------------------*/ +#include "hw.h" +#include "mbox_def.h" +#include "utilities_conf.h" + +/* Global variables ---------------------------------------------------------*/ +/* Private defines -----------------------------------------------------------*/ +#define HW_IPCC_TX_PENDING( channel ) ( !(LL_C1_IPCC_IsActiveFlag_CHx( IPCC, channel )) ) && (((~(IPCC->C1MR)) & (channel << 16U))) +#define HW_IPCC_RX_PENDING( channel ) (LL_C2_IPCC_IsActiveFlag_CHx( IPCC, channel )) && (((~(IPCC->C1MR)) & (channel << 0U))) + +/* Private macros ------------------------------------------------------------*/ +/* Private typedef -----------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +static void (*FreeBufCb)( void ); + +/* Private function prototypes -----------------------------------------------*/ +static void HW_IPCC_BLE_EvtHandler( void ); +static void HW_IPCC_BLE_AclDataEvtHandler( void ); +static void HW_IPCC_MM_FreeBufHandler( void ); +static void HW_IPCC_SYS_CmdEvtHandler( void ); +static void HW_IPCC_SYS_EvtHandler( void ); +static void HW_IPCC_TRACES_EvtHandler( void ); + +#ifdef THREAD_WB +static void HW_IPCC_OT_CmdEvtHandler( void ); +static void HW_IPCC_THREAD_NotEvtHandler( void ); +static void HW_IPCC_THREAD_CliNotEvtHandler( void ); +#endif + +#ifdef LLD_TESTS_WB +static void HW_IPCC_LLDTESTS_ReceiveCliRspHandler( void ); +static void HW_IPCC_LLDTESTS_ReceiveM0CmdHandler( void ); +#endif +#ifdef LLD_BLE_WB +/*static void HW_IPCC_LLD_BLE_ReceiveCliRspHandler( void );*/ +static void HW_IPCC_LLD_BLE_ReceiveRspHandler( void ); +static void HW_IPCC_LLD_BLE_ReceiveM0CmdHandler( void ); +#endif + +#ifdef MAC_802_15_4_WB +static void HW_IPCC_MAC_802_15_4_CmdEvtHandler( void ); +static void HW_IPCC_MAC_802_15_4_NotEvtHandler( void ); +#endif + +#ifdef ZIGBEE_WB +static void HW_IPCC_ZIGBEE_CmdEvtHandler( void ); +static void HW_IPCC_ZIGBEE_StackNotifEvtHandler( void ); +static void HW_IPCC_ZIGBEE_StackM0RequestHandler( void ); +#endif + +/* Public function definition -----------------------------------------------*/ + +/****************************************************************************** + * INTERRUPT HANDLER + ******************************************************************************/ +void HW_IPCC_Rx_Handler( void ) +{ + if (HW_IPCC_RX_PENDING( HW_IPCC_SYSTEM_EVENT_CHANNEL )) + { + HW_IPCC_SYS_EvtHandler(); + } +#ifdef MAC_802_15_4_WB + else if (HW_IPCC_RX_PENDING( HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL )) + { + HW_IPCC_MAC_802_15_4_NotEvtHandler(); + } +#endif /* MAC_802_15_4_WB */ +#ifdef THREAD_WB + else if (HW_IPCC_RX_PENDING( HW_IPCC_THREAD_NOTIFICATION_ACK_CHANNEL )) + { + HW_IPCC_THREAD_NotEvtHandler(); + } + else if (HW_IPCC_RX_PENDING( HW_IPCC_THREAD_CLI_NOTIFICATION_ACK_CHANNEL )) + { + HW_IPCC_THREAD_CliNotEvtHandler(); + } +#endif /* THREAD_WB */ +#ifdef LLD_TESTS_WB + else if (HW_IPCC_RX_PENDING( HW_IPCC_LLDTESTS_CLI_RSP_CHANNEL )) + { + HW_IPCC_LLDTESTS_ReceiveCliRspHandler(); + } + else if (HW_IPCC_RX_PENDING( HW_IPCC_LLDTESTS_M0_CMD_CHANNEL )) + { + HW_IPCC_LLDTESTS_ReceiveM0CmdHandler(); + } +#endif /* LLD_TESTS_WB */ +#ifdef LLD_BLE_WB + else if (HW_IPCC_RX_PENDING( HW_IPCC_LLD_BLE_RSP_CHANNEL )) + { + HW_IPCC_LLD_BLE_ReceiveRspHandler(); + } + else if (HW_IPCC_RX_PENDING( HW_IPCC_LLD_BLE_M0_CMD_CHANNEL )) + { + HW_IPCC_LLD_BLE_ReceiveM0CmdHandler(); + } +#endif /* LLD_TESTS_WB */ +#ifdef ZIGBEE_WB + else if (HW_IPCC_RX_PENDING( HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL )) + { + HW_IPCC_ZIGBEE_StackNotifEvtHandler(); + } + else if (HW_IPCC_RX_PENDING( HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL )) + { + HW_IPCC_ZIGBEE_StackM0RequestHandler(); + } +#endif /* ZIGBEE_WB */ + else if (HW_IPCC_RX_PENDING( HW_IPCC_BLE_EVENT_CHANNEL )) + { + HW_IPCC_BLE_EvtHandler(); + } + else if (HW_IPCC_RX_PENDING( HW_IPCC_TRACES_CHANNEL )) + { + HW_IPCC_TRACES_EvtHandler(); + } + + return; +} + +void HW_IPCC_Tx_Handler( void ) +{ + if (HW_IPCC_TX_PENDING( HW_IPCC_SYSTEM_CMD_RSP_CHANNEL )) + { + HW_IPCC_SYS_CmdEvtHandler(); + } +#ifdef MAC_802_15_4_WB + else if (HW_IPCC_TX_PENDING( HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL )) + { + HW_IPCC_MAC_802_15_4_CmdEvtHandler(); + } +#endif /* MAC_802_15_4_WB */ +#ifdef THREAD_WB + else if (HW_IPCC_TX_PENDING( HW_IPCC_THREAD_OT_CMD_RSP_CHANNEL )) + { + HW_IPCC_OT_CmdEvtHandler(); + } +#endif /* THREAD_WB */ +#ifdef LLD_TESTS_WB +// No TX handler for LLD tests +#endif /* LLD_TESTS_WB */ +#ifdef ZIGBEE_WB + if (HW_IPCC_TX_PENDING( HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL )) + { + HW_IPCC_ZIGBEE_CmdEvtHandler(); + } +#endif /* ZIGBEE_WB */ + else if (HW_IPCC_TX_PENDING( HW_IPCC_MM_RELEASE_BUFFER_CHANNEL )) + { + HW_IPCC_MM_FreeBufHandler(); + } + else if (HW_IPCC_TX_PENDING( HW_IPCC_HCI_ACL_DATA_CHANNEL )) + { + HW_IPCC_BLE_AclDataEvtHandler(); + } + + return; +} +/****************************************************************************** + * GENERAL + ******************************************************************************/ +void HW_IPCC_Enable( void ) +{ + /** + * Such as IPCC IP available to the CPU2, it is required to keep the IPCC clock running + * when FUS is running on CPU2 and CPU1 enters deep sleep mode + */ + LL_C2_AHB3_GRP1_EnableClock(LL_C2_AHB3_GRP1_PERIPH_IPCC); + + /** + * When the device is out of standby, it is required to use the EXTI mechanism to wakeup CPU2 + */ + LL_EXTI_EnableRisingTrig_32_63( LL_EXTI_LINE_41 ); + /* It is required to have at least a system clock cycle before a SEV after LL_EXTI_EnableRisingTrig_32_63() */ + LL_C2_EXTI_EnableEvent_32_63( LL_EXTI_LINE_41 ); + + /** + * In case the SBSFU is implemented, it may have already set the C2BOOT bit to startup the CPU2. + * In that case, to keep the mechanism transparent to the user application, it shall call the system command + * SHCI_C2_Reinit( ) before jumping to the application. + * When the CPU2 receives that command, it waits for its event input to be set to restart the CPU2 firmware. + * This is required because once C2BOOT has been set once, a clear/set on C2BOOT has no effect. + * When SHCI_C2_Reinit( ) is not called, generating an event to the CPU2 does not have any effect + * So, by default, the application shall both set the event flag and set the C2BOOT bit. + */ + __SEV( ); /* Set the internal event flag and send an event to the CPU2 */ + __WFE( ); /* Clear the internal event flag */ + LL_PWR_EnableBootC2( ); + + return; +} + +void HW_IPCC_Init( void ) +{ + LL_AHB3_GRP1_EnableClock( LL_AHB3_GRP1_PERIPH_IPCC ); + + LL_C1_IPCC_EnableIT_RXO( IPCC ); + LL_C1_IPCC_EnableIT_TXF( IPCC ); + + HAL_NVIC_EnableIRQ(IPCC_C1_RX_IRQn); + HAL_NVIC_EnableIRQ(IPCC_C1_TX_IRQn); + + return; +} + +/****************************************************************************** + * BLE + ******************************************************************************/ +void HW_IPCC_BLE_Init( void ) +{ + UTILS_ENTER_CRITICAL_SECTION(); + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_BLE_EVENT_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); + + return; +} + +void HW_IPCC_BLE_SendCmd( void ) +{ + LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_BLE_CMD_CHANNEL ); + + return; +} + +static void HW_IPCC_BLE_EvtHandler( void ) +{ + HW_IPCC_BLE_RxEvtNot(); + + LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_BLE_EVENT_CHANNEL ); + + return; +} + +void HW_IPCC_BLE_SendAclData( void ) +{ + LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_HCI_ACL_DATA_CHANNEL ); + UTILS_ENTER_CRITICAL_SECTION(); + LL_C1_IPCC_EnableTransmitChannel( IPCC, HW_IPCC_HCI_ACL_DATA_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); + + return; +} + +static void HW_IPCC_BLE_AclDataEvtHandler( void ) +{ + UTILS_ENTER_CRITICAL_SECTION(); + LL_C1_IPCC_DisableTransmitChannel( IPCC, HW_IPCC_HCI_ACL_DATA_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); + + HW_IPCC_BLE_AclDataAckNot(); + + return; +} + +__weak void HW_IPCC_BLE_AclDataAckNot( void ){}; +__weak void HW_IPCC_BLE_RxEvtNot( void ){}; + +/****************************************************************************** + * SYSTEM + ******************************************************************************/ +void HW_IPCC_SYS_Init( void ) +{ + UTILS_ENTER_CRITICAL_SECTION(); + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_SYSTEM_EVENT_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); + + return; +} + +void HW_IPCC_SYS_SendCmd( void ) +{ + LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_SYSTEM_CMD_RSP_CHANNEL ); + UTILS_ENTER_CRITICAL_SECTION(); + LL_C1_IPCC_EnableTransmitChannel( IPCC, HW_IPCC_SYSTEM_CMD_RSP_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); + + return; +} + +static void HW_IPCC_SYS_CmdEvtHandler( void ) +{ + UTILS_ENTER_CRITICAL_SECTION(); + LL_C1_IPCC_DisableTransmitChannel( IPCC, HW_IPCC_SYSTEM_CMD_RSP_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); + + HW_IPCC_SYS_CmdEvtNot(); + + return; +} + +static void HW_IPCC_SYS_EvtHandler( void ) +{ + HW_IPCC_SYS_EvtNot(); + + LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_SYSTEM_EVENT_CHANNEL ); + + return; +} + +__weak void HW_IPCC_SYS_CmdEvtNot( void ){}; +__weak void HW_IPCC_SYS_EvtNot( void ){}; + +/****************************************************************************** + * MAC 802.15.4 + ******************************************************************************/ +#ifdef MAC_802_15_4_WB +void HW_IPCC_MAC_802_15_4_Init( void ) +{ + UTILS_ENTER_CRITICAL_SECTION(); + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); + + return; +} + +void HW_IPCC_MAC_802_15_4_SendCmd( void ) +{ + LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL ); + UTILS_ENTER_CRITICAL_SECTION(); + LL_C1_IPCC_EnableTransmitChannel( IPCC, HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); + + return; +} + +void HW_IPCC_MAC_802_15_4_SendAck( void ) +{ + LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL ); + UTILS_ENTER_CRITICAL_SECTION(); + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); + + return; +} + +static void HW_IPCC_MAC_802_15_4_CmdEvtHandler( void ) +{ + UTILS_ENTER_CRITICAL_SECTION(); + LL_C1_IPCC_DisableTransmitChannel( IPCC, HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); + + HW_IPCC_MAC_802_15_4_CmdEvtNot(); + + return; +} + +static void HW_IPCC_MAC_802_15_4_NotEvtHandler( void ) +{ + UTILS_ENTER_CRITICAL_SECTION(); + LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); + + HW_IPCC_MAC_802_15_4_EvtNot(); + + return; +} +__weak void HW_IPCC_MAC_802_15_4_CmdEvtNot( void ){}; +__weak void HW_IPCC_MAC_802_15_4_EvtNot( void ){}; +#endif + +/****************************************************************************** + * THREAD + ******************************************************************************/ +#ifdef THREAD_WB +void HW_IPCC_THREAD_Init( void ) +{ + UTILS_ENTER_CRITICAL_SECTION(); + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_THREAD_NOTIFICATION_ACK_CHANNEL ); + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_THREAD_CLI_NOTIFICATION_ACK_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); + + return; +} + +void HW_IPCC_OT_SendCmd( void ) +{ + LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_THREAD_OT_CMD_RSP_CHANNEL ); + UTILS_ENTER_CRITICAL_SECTION(); + LL_C1_IPCC_EnableTransmitChannel( IPCC, HW_IPCC_THREAD_OT_CMD_RSP_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); + + return; +} + +void HW_IPCC_CLI_SendCmd( void ) +{ + LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_THREAD_CLI_CMD_CHANNEL ); + + return; +} + +void HW_IPCC_THREAD_SendAck( void ) +{ + LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_THREAD_NOTIFICATION_ACK_CHANNEL ); + UTILS_ENTER_CRITICAL_SECTION(); + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_THREAD_NOTIFICATION_ACK_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); + + return; +} + +void HW_IPCC_THREAD_CliSendAck( void ) +{ + LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_THREAD_CLI_NOTIFICATION_ACK_CHANNEL ); + UTILS_ENTER_CRITICAL_SECTION(); + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_THREAD_CLI_NOTIFICATION_ACK_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); + + return; +} + +static void HW_IPCC_OT_CmdEvtHandler( void ) +{ + UTILS_ENTER_CRITICAL_SECTION(); + LL_C1_IPCC_DisableTransmitChannel( IPCC, HW_IPCC_THREAD_OT_CMD_RSP_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); + + HW_IPCC_OT_CmdEvtNot(); + + return; +} + +static void HW_IPCC_THREAD_NotEvtHandler( void ) +{ + UTILS_ENTER_CRITICAL_SECTION(); + LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_THREAD_NOTIFICATION_ACK_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); + + HW_IPCC_THREAD_EvtNot(); + + return; +} + +static void HW_IPCC_THREAD_CliNotEvtHandler( void ) +{ + UTILS_ENTER_CRITICAL_SECTION(); + LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_THREAD_CLI_NOTIFICATION_ACK_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); + + HW_IPCC_THREAD_CliEvtNot(); + + return; +} + +__weak void HW_IPCC_OT_CmdEvtNot( void ){}; +__weak void HW_IPCC_CLI_CmdEvtNot( void ){}; +__weak void HW_IPCC_THREAD_EvtNot( void ){}; + +#endif /* THREAD_WB */ + +/****************************************************************************** + * LLD TESTS + ******************************************************************************/ +#ifdef LLD_TESTS_WB +void HW_IPCC_LLDTESTS_Init( void ) +{ + UTILS_ENTER_CRITICAL_SECTION(); + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_LLDTESTS_CLI_RSP_CHANNEL ); + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_LLDTESTS_M0_CMD_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); + return; +} + +void HW_IPCC_LLDTESTS_SendCliCmd( void ) +{ + LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_LLDTESTS_CLI_CMD_CHANNEL ); + return; +} + +static void HW_IPCC_LLDTESTS_ReceiveCliRspHandler( void ) +{ + UTILS_ENTER_CRITICAL_SECTION(); + LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_LLDTESTS_CLI_RSP_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); + + HW_IPCC_LLDTESTS_ReceiveCliRsp(); + return; +} + +void HW_IPCC_LLDTESTS_SendCliRspAck( void ) +{ + LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_LLDTESTS_CLI_RSP_CHANNEL ); + UTILS_ENTER_CRITICAL_SECTION(); + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_LLDTESTS_CLI_RSP_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); + return; +} + +static void HW_IPCC_LLDTESTS_ReceiveM0CmdHandler( void ) +{ + UTILS_ENTER_CRITICAL_SECTION(); + LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_LLDTESTS_M0_CMD_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); + HW_IPCC_LLDTESTS_ReceiveM0Cmd(); + return; +} + +void HW_IPCC_LLDTESTS_SendM0CmdAck( void ) +{ + LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_LLDTESTS_M0_CMD_CHANNEL ); + UTILS_ENTER_CRITICAL_SECTION(); + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_LLDTESTS_M0_CMD_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); + return; +} +__weak void HW_IPCC_LLDTESTS_ReceiveCliRsp( void ){}; +__weak void HW_IPCC_LLDTESTS_ReceiveM0Cmd( void ){}; +#endif /* LLD_TESTS_WB */ + +/****************************************************************************** + * LLD BLE + ******************************************************************************/ +#ifdef LLD_BLE_WB +void HW_IPCC_LLD_BLE_Init( void ) +{ + UTILS_ENTER_CRITICAL_SECTION(); + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_LLD_BLE_RSP_CHANNEL ); + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_LLD_BLE_M0_CMD_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); + return; +} + +void HW_IPCC_LLD_BLE_SendCliCmd( void ) +{ + LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_LLD_BLE_CLI_CMD_CHANNEL ); + return; +} + +/*static void HW_IPCC_LLD_BLE_ReceiveCliRspHandler( void ) +{ + UTILS_ENTER_CRITICAL_SECTION(); + LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_LLD_BLE_CLI_RSP_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); + HW_IPCC_LLD_BLE_ReceiveCliRsp(); + return; +}*/ + +void HW_IPCC_LLD_BLE_SendCliRspAck( void ) +{ + LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_LLD_BLE_CLI_RSP_CHANNEL ); + UTILS_ENTER_CRITICAL_SECTION(); + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_LLD_BLE_CLI_RSP_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); + return; +} + +static void HW_IPCC_LLD_BLE_ReceiveM0CmdHandler( void ) +{ + //LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_LLD_BLE_M0_CMD_CHANNEL ); + HW_IPCC_LLD_BLE_ReceiveM0Cmd(); + return; +} + +void HW_IPCC_LLD_BLE_SendM0CmdAck( void ) +{ + LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_LLD_BLE_M0_CMD_CHANNEL ); + //LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_LLD_BLE_M0_CMD_CHANNEL ); + return; +} +__weak void HW_IPCC_LLD_BLE_ReceiveCliRsp( void ){}; +__weak void HW_IPCC_LLD_BLE_ReceiveM0Cmd( void ){}; + +/* Transparent Mode */ +void HW_IPCC_LLD_BLE_SendCmd( void ) +{ + LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_LLD_BLE_CMD_CHANNEL ); + return; +} + +static void HW_IPCC_LLD_BLE_ReceiveRspHandler( void ) +{ + UTILS_ENTER_CRITICAL_SECTION(); + LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_LLD_BLE_RSP_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); + HW_IPCC_LLD_BLE_ReceiveRsp(); + return; +} + +void HW_IPCC_LLD_BLE_SendRspAck( void ) +{ + LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_LLD_BLE_RSP_CHANNEL ); + UTILS_ENTER_CRITICAL_SECTION(); + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_LLD_BLE_RSP_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); + return; +} + +#endif /* LLD_BLE_WB */ + +/****************************************************************************** + * ZIGBEE + ******************************************************************************/ +#ifdef ZIGBEE_WB +void HW_IPCC_ZIGBEE_Init( void ) +{ + UTILS_ENTER_CRITICAL_SECTION(); + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL ); + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); + + return; +} + +void HW_IPCC_ZIGBEE_SendM4RequestToM0( void ) +{ + LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL ); + UTILS_ENTER_CRITICAL_SECTION(); + LL_C1_IPCC_EnableTransmitChannel( IPCC, HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); + + return; +} + +void HW_IPCC_ZIGBEE_SendM4AckToM0Notify( void ) +{ + LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL ); + UTILS_ENTER_CRITICAL_SECTION(); + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); + + return; +} + +static void HW_IPCC_ZIGBEE_CmdEvtHandler( void ) +{ + UTILS_ENTER_CRITICAL_SECTION(); + LL_C1_IPCC_DisableTransmitChannel( IPCC, HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); + + HW_IPCC_ZIGBEE_RecvAppliAckFromM0(); + + return; +} + +static void HW_IPCC_ZIGBEE_StackNotifEvtHandler( void ) +{ + UTILS_ENTER_CRITICAL_SECTION(); + LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); + + HW_IPCC_ZIGBEE_RecvM0NotifyToM4(); + + return; +} + +static void HW_IPCC_ZIGBEE_StackM0RequestHandler( void ) +{ + UTILS_ENTER_CRITICAL_SECTION(); + LL_C1_IPCC_DisableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); + + HW_IPCC_ZIGBEE_RecvM0RequestToM4(); + + return; +} + +void HW_IPCC_ZIGBEE_SendM4AckToM0Request( void ) +{ + LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL ); + UTILS_ENTER_CRITICAL_SECTION(); + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); + + return; +} + +__weak void HW_IPCC_ZIGBEE_RecvAppliAckFromM0( void ){}; +__weak void HW_IPCC_ZIGBEE_RecvM0NotifyToM4( void ){}; +__weak void HW_IPCC_ZIGBEE_RecvM0RequestToM4( void ){}; +#endif /* ZIGBEE_WB */ + +/****************************************************************************** + * MEMORY MANAGER + ******************************************************************************/ +void HW_IPCC_MM_SendFreeBuf( void (*cb)( void ) ) +{ + if ( LL_C1_IPCC_IsActiveFlag_CHx( IPCC, HW_IPCC_MM_RELEASE_BUFFER_CHANNEL ) ) + { + FreeBufCb = cb; + UTILS_ENTER_CRITICAL_SECTION(); + LL_C1_IPCC_EnableTransmitChannel( IPCC, HW_IPCC_MM_RELEASE_BUFFER_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); + } + else + { + cb(); + + LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_MM_RELEASE_BUFFER_CHANNEL ); + } + + return; +} + +static void HW_IPCC_MM_FreeBufHandler( void ) +{ + UTILS_ENTER_CRITICAL_SECTION(); + LL_C1_IPCC_DisableTransmitChannel( IPCC, HW_IPCC_MM_RELEASE_BUFFER_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); + + FreeBufCb(); + + LL_C1_IPCC_SetFlag_CHx( IPCC, HW_IPCC_MM_RELEASE_BUFFER_CHANNEL ); + + return; +} + +/****************************************************************************** + * TRACES + ******************************************************************************/ +void HW_IPCC_TRACES_Init( void ) +{ + UTILS_ENTER_CRITICAL_SECTION(); + LL_C1_IPCC_EnableReceiveChannel( IPCC, HW_IPCC_TRACES_CHANNEL ); + UTILS_EXIT_CRITICAL_SECTION(); + + return; +} + +static void HW_IPCC_TRACES_EvtHandler( void ) +{ + HW_IPCC_TRACES_EvtNot(); + + LL_C1_IPCC_ClearFlag_CHx( IPCC, HW_IPCC_TRACES_CHANNEL ); + + return; +} + +__weak void HW_IPCC_TRACES_EvtNot( void ){}; +#endif /* STM32WBxx */ diff --git a/src/utility/STM32_WPAN/mbox_def.h b/src/utility/STM32_WPAN/mbox_def.h new file mode 100644 index 00000000..68b71f9c --- /dev/null +++ b/src/utility/STM32_WPAN/mbox_def.h @@ -0,0 +1,280 @@ +/** + ****************************************************************************** + * @file mbox_def.h + * @author MCD Application Team + * @brief Mailbox definition + ****************************************************************************** + * @attention + * + * Copyright (c) 2018-2021 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ + + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __MBOX_H +#define __MBOX_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "stm32_wpan_common.h" + + /** + * This file shall be identical between the CPU1 and the CPU2 + */ + + /** + ********************************************************************************* + * TABLES + ********************************************************************************* + */ + + /** + * Version + * [0:3] = Build - 0: Untracked - 15:Released - x: Tracked version + * [4:7] = branch - 0: Mass Market - x: ... + * [8:15] = Subversion + * [16:23] = Version minor + * [24:31] = Version major + * + * Memory Size + * [0:7] = Flash ( Number of 4k sector) + * [8:15] = Reserved ( Shall be set to 0 - may be used as flash extension ) + * [16:23] = SRAM2b ( Number of 1k sector) + * [24:31] = SRAM2a ( Number of 1k sector) + */ + typedef PACKED_STRUCT + { + uint32_t Version; + } MB_SafeBootInfoTable_t; + + typedef PACKED_STRUCT + { + uint32_t Version; + uint32_t MemorySize; + uint32_t FusInfo; + } MB_FusInfoTable_t; + + typedef PACKED_STRUCT + { + uint32_t Version; + uint32_t MemorySize; + uint32_t InfoStack; + uint32_t Reserved; + } MB_WirelessFwInfoTable_t; + + typedef struct + { + MB_SafeBootInfoTable_t SafeBootInfoTable; + MB_FusInfoTable_t FusInfoTable; + MB_WirelessFwInfoTable_t WirelessFwInfoTable; + } MB_DeviceInfoTable_t; + + typedef struct + { + uint8_t *pcmd_buffer; + uint8_t *pcs_buffer; + uint8_t *pevt_queue; + uint8_t *phci_acl_data_buffer; + } MB_BleTable_t; + + typedef struct + { + uint8_t *notack_buffer; + uint8_t *clicmdrsp_buffer; + uint8_t *otcmdrsp_buffer; + uint8_t *clinot_buffer; + } MB_ThreadTable_t; + + typedef struct + { + uint8_t *clicmdrsp_buffer; + uint8_t *m0cmd_buffer; + } MB_LldTestsTable_t; + + typedef struct + { + uint8_t *cmdrsp_buffer; + uint8_t *m0cmd_buffer; + } MB_BleLldTable_t; + + typedef struct + { + uint8_t *notifM0toM4_buffer; + uint8_t *appliCmdM4toM0_buffer; + uint8_t *requestM0toM4_buffer; + } MB_ZigbeeTable_t; + /** + * msg + * [0:7] = cmd/evt + * [8:31] = Reserved + */ + typedef struct + { + uint8_t *pcmd_buffer; + uint8_t *sys_queue; + } MB_SysTable_t; + + typedef struct + { + uint8_t *spare_ble_buffer; + uint8_t *spare_sys_buffer; + uint8_t *blepool; + uint32_t blepoolsize; + uint8_t *pevt_free_buffer_queue; + uint8_t *traces_evt_pool; + uint32_t tracespoolsize; + } MB_MemManagerTable_t; + + typedef struct + { + uint8_t *traces_queue; + } MB_TracesTable_t; + + typedef struct + { + uint8_t *p_cmdrsp_buffer; + uint8_t *p_notack_buffer; + uint8_t *evt_queue; + } MB_Mac_802_15_4_t; + + typedef struct + { + MB_DeviceInfoTable_t *p_device_info_table; + MB_BleTable_t *p_ble_table; + MB_ThreadTable_t *p_thread_table; + MB_SysTable_t *p_sys_table; + MB_MemManagerTable_t *p_mem_manager_table; + MB_TracesTable_t *p_traces_table; + MB_Mac_802_15_4_t *p_mac_802_15_4_table; + MB_ZigbeeTable_t *p_zigbee_table; + MB_LldTestsTable_t *p_lld_tests_table; + MB_BleLldTable_t *p_ble_lld_table; +} MB_RefTable_t; + +/** + * This table shall be used only in the case the CPU2 runs the FUS. + * It is used by the command SHCI_GetWirelessFwInfo() + */ +typedef struct +{ + uint32_t DeviceInfoTableState; + uint8_t Reserved1; + uint8_t LastFusActiveState; + uint8_t LastWirelessStackState; + uint8_t CurrentWirelessStackType; + uint32_t SafeBootVersion; + uint32_t FusVersion; + uint32_t FusMemorySize; + uint32_t WirelessStackVersion; + uint32_t WirelessStackMemorySize; + uint32_t WirelessFirmwareBleInfo; + uint32_t WirelessFirmwareThreadInfo; + uint32_t Reserved2; + uint64_t UID64; + uint16_t DeviceId; +} MB_FUS_DeviceInfoTable_t ; + +#ifdef __cplusplus +} +#endif + +/** + ********************************************************************************* + * IPCC CHANNELS + ********************************************************************************* + */ + +/* CPU1 CPU2 + * | (SYSTEM) | + * |----HW_IPCC_SYSTEM_CMD_RSP_CHANNEL-------------->| + * | | + * |<---HW_IPCC_SYSTEM_EVENT_CHANNEL-----------------| + * | | + * | (ZIGBEE) | + * |----HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL------------>| + * | | + * |----HW_IPCC_ZIGBEE_CMD_CLI_CHANNEL-------------->| + * | | + * |<---HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL-------| + * | | + * |<---HW_IPCC_ZIGBEE_CLI_NOTIF_ACK_CHANNEL---------| + * | | + * | (THREAD) | + * |----HW_IPCC_THREAD_OT_CMD_RSP_CHANNEL----------->| + * | | + * |----HW_IPCC_THREAD_CLI_CMD_CHANNEL-------------->| + * | | + * |<---HW_IPCC_THREAD_NOTIFICATION_ACK_CHANNEL------| + * | | + * |<---HW_IPCC_THREAD_CLI_NOTIFICATION_ACK_CHANNEL--| + * | | + * | (BLE) | + * |----HW_IPCC_BLE_CMD_CHANNEL--------------------->| + * | | + * |----HW_IPCC_HCI_ACL_DATA_CHANNEL---------------->| + * | | + * |<---HW_IPCC_BLE_EVENT_CHANNEL--------------------| + * | | + * | (BLE LLD) | + * |----HW_IPCC_BLE_LLD_CMD_CHANNEL----------------->| + * | | + * |<---HW_IPCC_BLE_LLD_RSP_CHANNEL------------------| + * | | + * |<---HW_IPCC_BLE_LLD_M0_CMD_CHANNEL---------------| + * | | + * | (MAC) | + * |----HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL-------->| + * | | + * |<---HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL| + * | | + * | (BUFFER) | + * |----HW_IPCC_MM_RELEASE_BUFFER_CHANNE------------>| + * | | + * | (TRACE) | + * |<----HW_IPCC_TRACES_CHANNEL----------------------| + * | | + * + * + * + */ + + + +/** CPU1 */ +#define HW_IPCC_BLE_CMD_CHANNEL LL_IPCC_CHANNEL_1 +#define HW_IPCC_SYSTEM_CMD_RSP_CHANNEL LL_IPCC_CHANNEL_2 +#define HW_IPCC_THREAD_OT_CMD_RSP_CHANNEL LL_IPCC_CHANNEL_3 +#define HW_IPCC_ZIGBEE_CMD_APPLI_CHANNEL LL_IPCC_CHANNEL_3 +#define HW_IPCC_MAC_802_15_4_CMD_RSP_CHANNEL LL_IPCC_CHANNEL_3 +#define HW_IPCC_MM_RELEASE_BUFFER_CHANNEL LL_IPCC_CHANNEL_4 +#define HW_IPCC_THREAD_CLI_CMD_CHANNEL LL_IPCC_CHANNEL_5 +#define HW_IPCC_LLDTESTS_CLI_CMD_CHANNEL LL_IPCC_CHANNEL_5 +#define HW_IPCC_BLE_LLD_CLI_CMD_CHANNEL LL_IPCC_CHANNEL_5 +#define HW_IPCC_BLE_LLD_CMD_CHANNEL LL_IPCC_CHANNEL_5 +#define HW_IPCC_HCI_ACL_DATA_CHANNEL LL_IPCC_CHANNEL_6 + +/** CPU2 */ +#define HW_IPCC_BLE_EVENT_CHANNEL LL_IPCC_CHANNEL_1 +#define HW_IPCC_SYSTEM_EVENT_CHANNEL LL_IPCC_CHANNEL_2 +#define HW_IPCC_THREAD_NOTIFICATION_ACK_CHANNEL LL_IPCC_CHANNEL_3 +#define HW_IPCC_ZIGBEE_APPLI_NOTIF_ACK_CHANNEL LL_IPCC_CHANNEL_3 +#define HW_IPCC_MAC_802_15_4_NOTIFICATION_ACK_CHANNEL LL_IPCC_CHANNEL_3 +#define HW_IPCC_LLDTESTS_M0_CMD_CHANNEL LL_IPCC_CHANNEL_3 +#define HW_IPCC_BLE_LLD_M0_CMD_CHANNEL LL_IPCC_CHANNEL_3 +#define HW_IPCC_TRACES_CHANNEL LL_IPCC_CHANNEL_4 +#define HW_IPCC_THREAD_CLI_NOTIFICATION_ACK_CHANNEL LL_IPCC_CHANNEL_5 +#define HW_IPCC_LLDTESTS_CLI_RSP_CHANNEL LL_IPCC_CHANNEL_5 +#define HW_IPCC_BLE_LLD_CLI_RSP_CHANNEL LL_IPCC_CHANNEL_5 +#define HW_IPCC_BLE_LLD_RSP_CHANNEL LL_IPCC_CHANNEL_5 +#define HW_IPCC_ZIGBEE_M0_REQUEST_CHANNEL LL_IPCC_CHANNEL_5 +#endif /*__MBOX_H */ + diff --git a/src/utility/STM32_WPAN/shci.c b/src/utility/STM32_WPAN/shci.c new file mode 100644 index 00000000..40110f42 --- /dev/null +++ b/src/utility/STM32_WPAN/shci.c @@ -0,0 +1,763 @@ +/** + ****************************************************************************** + * @file shci.c + * @author MCD Application Team + * @brief HCI command for the system channel + ****************************************************************************** + * @attention + * + * Copyright (c) 2018-2021 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ + + +#if defined(STM32WBxx) +/* Includes ------------------------------------------------------------------*/ +#include "stm32_wpan_common.h" + +#include "shci_tl.h" +#include "shci.h" +#include "stm32wbxx.h" + +/* Private typedef -----------------------------------------------------------*/ +/* Private defines -----------------------------------------------------------*/ +/* Private macros ------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +/* Global variables ----------------------------------------------------------*/ +/* Private function prototypes -----------------------------------------------*/ +/* Local Functions Definition ------------------------------------------------------*/ +/* Public Functions Definition ------------------------------------------------------*/ + +/** + * C2 COMMAND + * These commands are sent to the CPU2 + */ +uint8_t SHCI_C2_FUS_GetState( SHCI_FUS_GetState_ErrorCode_t *p_error_code ) +{ + /** + * Buffer is large enough to hold command complete with payload + */ + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE + 1]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send( SHCI_OPCODE_C2_FUS_GET_STATE, + 0, + 0, + p_rsp ); + + if(p_error_code != 0) + { + *p_error_code = (SHCI_FUS_GetState_ErrorCode_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[1]); + } + + return (((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_FUS_FwUpgrade( uint32_t fw_src_add, uint32_t fw_dest_add ) +{ + /** + * TL_BLEEVT_CC_BUFFER_SIZE is 16 bytes so it is large enough to hold the 8 bytes of command parameters + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + uint32_t *p_cmd; + uint8_t cmd_length; + + p_cmd = (uint32_t*)local_buffer; + cmd_length = 0; + + if(fw_src_add != 0) + { + *p_cmd = fw_src_add; + cmd_length += 4; + } + + if(fw_dest_add != 0) + { + *(p_cmd+1) = fw_dest_add; + cmd_length += 4; + } + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send( SHCI_OPCODE_C2_FUS_FW_UPGRADE, + cmd_length, + local_buffer, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_FUS_FwDelete( void ) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send( SHCI_OPCODE_C2_FUS_FW_DELETE, + 0, + 0, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_FUS_UpdateAuthKey( SHCI_C2_FUS_UpdateAuthKey_Cmd_Param_t *pParam ) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send( SHCI_OPCODE_C2_FUS_UPDATE_AUTH_KEY, + sizeof( SHCI_C2_FUS_UpdateAuthKey_Cmd_Param_t ), + (uint8_t*)pParam, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_FUS_LockAuthKey( void ) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send( SHCI_OPCODE_C2_FUS_LOCK_AUTH_KEY, + 0, + 0, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_FUS_StoreUsrKey( SHCI_C2_FUS_StoreUsrKey_Cmd_Param_t *pParam, uint8_t *p_key_index ) +{ + /** + * Buffer is large enough to hold command complete with payload + */ + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE + 1]; + TL_EvtPacket_t * p_rsp; + uint8_t local_payload_len; + + if(pParam->KeyType == KEYTYPE_ENCRYPTED) + { + /** + * When the key is encrypted, the 12 bytes IV Key is included in the payload as well + * The IV key is always 12 bytes + */ + local_payload_len = pParam->KeySize + 2 + 12; + } + else + { + local_payload_len = pParam->KeySize + 2; + } + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send( SHCI_OPCODE_C2_FUS_STORE_USR_KEY, + local_payload_len , + (uint8_t*)pParam, + p_rsp ); + + *p_key_index = (((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[1]); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_FUS_LoadUsrKey( uint8_t key_index ) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + local_buffer[0] = key_index; + + shci_send( SHCI_OPCODE_C2_FUS_LOAD_USR_KEY, + 1, + local_buffer, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_FUS_StartWs( void ) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send( SHCI_OPCODE_C2_FUS_START_WS, + 0, + 0, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_FUS_LockUsrKey( uint8_t key_index ) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + local_buffer[0] = key_index; + + shci_send( SHCI_OPCODE_C2_FUS_LOCK_USR_KEY, + 1, + local_buffer, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_FUS_UnloadUsrKey( uint8_t key_index ) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + local_buffer[0] = key_index; + + shci_send( SHCI_OPCODE_C2_FUS_UNLOAD_USR_KEY, + 1, + local_buffer, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_FUS_ActivateAntiRollback( void ) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send( SHCI_OPCODE_C2_FUS_ACTIVATE_ANTIROLLBACK, + 0, + 0, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_BLE_Init( SHCI_C2_Ble_Init_Cmd_Packet_t *pCmdPacket ) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send( SHCI_OPCODE_C2_BLE_INIT, + sizeof( SHCI_C2_Ble_Init_Cmd_Param_t ), + (uint8_t*)&pCmdPacket->Param, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_THREAD_Init( void ) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send( SHCI_OPCODE_C2_THREAD_INIT, + 0, + 0, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_LLDTESTS_Init( uint8_t param_size, uint8_t * p_param ) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send( SHCI_OPCODE_C2_LLD_TESTS_INIT, + param_size, + p_param, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_BLE_LLD_Init( uint8_t param_size, uint8_t * p_param ) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send( SHCI_OPCODE_C2_BLE_LLD_INIT, + param_size, + p_param, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_ZIGBEE_Init( void ) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send( SHCI_OPCODE_C2_ZIGBEE_INIT, + 0, + 0, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_DEBUG_Init( SHCI_C2_DEBUG_Init_Cmd_Packet_t *pCmdPacket ) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send( SHCI_OPCODE_C2_DEBUG_INIT, + sizeof( SHCI_C2_DEBUG_init_Cmd_Param_t ), + (uint8_t*)&pCmdPacket->Param, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_FLASH_EraseActivity( SHCI_EraseActivity_t erase_activity ) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + local_buffer[0] = erase_activity; + + shci_send( SHCI_OPCODE_C2_FLASH_ERASE_ACTIVITY, + 1, + local_buffer, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_CONCURRENT_SetMode( SHCI_C2_CONCURRENT_Mode_Param_t Mode ) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + local_buffer[0] = Mode; + + shci_send( SHCI_OPCODE_C2_CONCURRENT_SET_MODE, + 1, + local_buffer, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_CONCURRENT_GetNextBleEvtTime( SHCI_C2_CONCURRENT_GetNextBleEvtTime_Param_t *pParam ) +{ + /** + * Buffer is large enough to hold command complete with payload + */ + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE+4]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send( SHCI_OPCODE_C2_CONCURRENT_GET_NEXT_BLE_EVT_TIME, + 0, + 0, + p_rsp ); + + memcpy((void*)&(pParam->relative_time), (void*)&((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[1], sizeof(pParam->relative_time)); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_CONCURRENT_EnableNext_802154_EvtNotification( void ) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send( SHCI_OPCODE_C2_CONCURRENT_ENABLE_NEXT_802154_EVT_NOTIFICATION, + 0, + 0, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_FLASH_StoreData( SHCI_C2_FLASH_Ip_t Ip ) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + local_buffer[0] = Ip; + + shci_send( SHCI_OPCODE_C2_FLASH_STORE_DATA, + 1, + local_buffer, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_FLASH_EraseData( SHCI_C2_FLASH_Ip_t Ip ) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + local_buffer[0] = Ip; + + shci_send( SHCI_OPCODE_C2_FLASH_ERASE_DATA, + 1, + local_buffer, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_RADIO_AllowLowPower( SHCI_C2_FLASH_Ip_t Ip,uint8_t FlagRadioLowPowerOn) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + local_buffer[0] = Ip; + local_buffer[1] = FlagRadioLowPowerOn; + + shci_send( SHCI_OPCODE_C2_RADIO_ALLOW_LOW_POWER, + 2, + local_buffer, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_MAC_802_15_4_Init( void ) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send( SHCI_OPCODE_C2_MAC_802_15_4_INIT, + 0, + 0, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_Reinit( void ) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send( SHCI_OPCODE_C2_REINIT, + 0, + 0, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_ExtpaConfig(uint32_t gpio_port, uint16_t gpio_pin_number, uint8_t gpio_polarity, uint8_t gpio_status) +{ + /** + * TL_BLEEVT_CC_BUFFER_SIZE is 16 bytes so it is large enough to hold the 8 bytes of command parameters + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + ((SHCI_C2_EXTPA_CONFIG_Cmd_Param_t*)local_buffer)->gpio_port = gpio_port; + ((SHCI_C2_EXTPA_CONFIG_Cmd_Param_t*)local_buffer)->gpio_pin_number = gpio_pin_number; + ((SHCI_C2_EXTPA_CONFIG_Cmd_Param_t*)local_buffer)->gpio_polarity = gpio_polarity; + ((SHCI_C2_EXTPA_CONFIG_Cmd_Param_t*)local_buffer)->gpio_status = gpio_status; + + shci_send( SHCI_OPCODE_C2_EXTPA_CONFIG, + 8, + local_buffer, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_SetFlashActivityControl(SHCI_C2_SET_FLASH_ACTIVITY_CONTROL_Source_t Source) +{ + /** + * TL_BLEEVT_CC_BUFFER_SIZE is 16 bytes so it is large enough to hold the 1 byte of command parameter + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + local_buffer[0] = (uint8_t)Source; + + shci_send( SHCI_OPCODE_C2_SET_FLASH_ACTIVITY_CONTROL, + 1, + local_buffer, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_Config(SHCI_C2_CONFIG_Cmd_Param_t *pCmdPacket) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send( SHCI_OPCODE_C2_CONFIG, + sizeof(SHCI_C2_CONFIG_Cmd_Param_t), + (uint8_t*)pCmdPacket, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_802_15_4_DeInit( void ) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + shci_send( SHCI_OPCODE_C2_802_15_4_DEINIT, + 0, + 0, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +SHCI_CmdStatus_t SHCI_C2_SetSystemClock( SHCI_C2_SET_SYSTEM_CLOCK_Cmd_Param_t clockSel ) +{ + /** + * Buffer is large enough to hold command complete without payload + */ + uint8_t local_buffer[TL_BLEEVT_CC_BUFFER_SIZE]; + TL_EvtPacket_t * p_rsp; + + p_rsp = (TL_EvtPacket_t *)local_buffer; + + local_buffer[0] = (uint8_t)clockSel; + + shci_send( SHCI_OPCODE_C2_SET_SYSTEM_CLOCK, + 1, + local_buffer, + p_rsp ); + + return (SHCI_CmdStatus_t)(((TL_CcEvt_t*)(p_rsp->evtserial.evt.payload))->payload[0]); +} + +/** + * Local System COMMAND + * These commands are NOT sent to the CPU2 + */ + +SHCI_CmdStatus_t SHCI_GetWirelessFwInfo( WirelessFwInfo_t* pWirelessInfo ) +{ + uint32_t ipccdba = 0; + MB_RefTable_t * p_RefTable = NULL; + uint32_t wireless_firmware_version = 0; + uint32_t wireless_firmware_memorySize = 0; + uint32_t wireless_firmware_infoStack = 0; + MB_FUS_DeviceInfoTable_t * p_fus_device_info_table = NULL; + uint32_t fus_version = 0; + uint32_t fus_memorySize = 0; + + ipccdba = READ_BIT( FLASH->IPCCBR, FLASH_IPCCBR_IPCCDBA ); + + /** + * The Device Info Table mapping depends on which firmware is running on CPU2. + * If the FUS is running on CPU2, FUS_DEVICE_INFO_TABLE_VALIDITY_KEYWORD shall be written in the table. + * Otherwise, it means the Wireless Firmware is running on the CPU2 + */ + p_fus_device_info_table = (MB_FUS_DeviceInfoTable_t*)(*(uint32_t*)((ipccdba<<2) + SRAM2A_BASE)); + + if(p_fus_device_info_table->DeviceInfoTableState == FUS_DEVICE_INFO_TABLE_VALIDITY_KEYWORD) + { + /* The FUS is running on CPU2 */ + /** + * Retrieve the WirelessFwInfoTable + * This table is stored in RAM at startup during the TL (transport layer) initialization + */ + wireless_firmware_version = p_fus_device_info_table->WirelessStackVersion; + wireless_firmware_memorySize = p_fus_device_info_table->WirelessStackMemorySize; + wireless_firmware_infoStack = p_fus_device_info_table->WirelessFirmwareBleInfo; + + /** + * Retrieve the FusInfoTable + * This table is stored in RAM at startup during the TL (transport layer) initialization + */ + fus_version = p_fus_device_info_table->FusVersion; + fus_memorySize = p_fus_device_info_table->FusMemorySize; + } + else + { + /* The Wireless Firmware is running on CPU2 */ + p_RefTable = (MB_RefTable_t*)((ipccdba<<2) + SRAM2A_BASE); + + /** + * Retrieve the WirelessFwInfoTable + * This table is stored in RAM at startup during the TL (transport layer) initialization + */ + wireless_firmware_version = p_RefTable->p_device_info_table->WirelessFwInfoTable.Version; + wireless_firmware_memorySize = p_RefTable->p_device_info_table->WirelessFwInfoTable.MemorySize; + wireless_firmware_infoStack = p_RefTable->p_device_info_table->WirelessFwInfoTable.InfoStack; + + /** + * Retrieve the FusInfoTable + * This table is stored in RAM at startup during the TL (transport layer) initialization + */ + fus_version = p_RefTable->p_device_info_table->FusInfoTable.Version; + fus_memorySize = p_RefTable->p_device_info_table->FusInfoTable.MemorySize; + } + + /** + * Retrieve the WirelessFwInfoTable + * This table is stored in RAM at startup during the TL (transport layer) initialization + */ + pWirelessInfo->VersionMajor = ((wireless_firmware_version & INFO_VERSION_MAJOR_MASK) >> INFO_VERSION_MAJOR_OFFSET); + pWirelessInfo->VersionMinor = ((wireless_firmware_version & INFO_VERSION_MINOR_MASK) >> INFO_VERSION_MINOR_OFFSET); + pWirelessInfo->VersionSub = ((wireless_firmware_version & INFO_VERSION_SUB_MASK) >> INFO_VERSION_SUB_OFFSET); + pWirelessInfo->VersionBranch = ((wireless_firmware_version & INFO_VERSION_BRANCH_MASK) >> INFO_VERSION_BRANCH_OFFSET); + pWirelessInfo->VersionReleaseType = ((wireless_firmware_version & INFO_VERSION_TYPE_MASK) >> INFO_VERSION_TYPE_OFFSET); + + pWirelessInfo->MemorySizeSram2B = ((wireless_firmware_memorySize & INFO_SIZE_SRAM2B_MASK) >> INFO_SIZE_SRAM2B_OFFSET); + pWirelessInfo->MemorySizeSram2A = ((wireless_firmware_memorySize & INFO_SIZE_SRAM2A_MASK) >> INFO_SIZE_SRAM2A_OFFSET); + pWirelessInfo->MemorySizeSram1 = ((wireless_firmware_memorySize & INFO_SIZE_SRAM1_MASK) >> INFO_SIZE_SRAM1_OFFSET); + pWirelessInfo->MemorySizeFlash = ((wireless_firmware_memorySize & INFO_SIZE_FLASH_MASK) >> INFO_SIZE_FLASH_OFFSET); + + pWirelessInfo->StackType = ((wireless_firmware_infoStack & INFO_STACK_TYPE_MASK) >> INFO_STACK_TYPE_OFFSET); + + /** + * Retrieve the FusInfoTable + * This table is stored in RAM at startup during the TL (transport layer) initialization + */ + pWirelessInfo->FusVersionMajor = ((fus_version & INFO_VERSION_MAJOR_MASK) >> INFO_VERSION_MAJOR_OFFSET); + pWirelessInfo->FusVersionMinor = ((fus_version & INFO_VERSION_MINOR_MASK) >> INFO_VERSION_MINOR_OFFSET); + pWirelessInfo->FusVersionSub = ((fus_version & INFO_VERSION_SUB_MASK) >> INFO_VERSION_SUB_OFFSET); + + pWirelessInfo->FusMemorySizeSram2B = ((fus_memorySize & INFO_SIZE_SRAM2B_MASK) >> INFO_SIZE_SRAM2B_OFFSET); + pWirelessInfo->FusMemorySizeSram2A = ((fus_memorySize & INFO_SIZE_SRAM2A_MASK) >> INFO_SIZE_SRAM2A_OFFSET); + pWirelessInfo->FusMemorySizeFlash = ((fus_memorySize & INFO_SIZE_FLASH_MASK) >> INFO_SIZE_FLASH_OFFSET); + + return (SHCI_Success); +} +#endif /* STM32WBxx */ diff --git a/src/utility/STM32_WPAN/shci.h b/src/utility/STM32_WPAN/shci.h new file mode 100644 index 00000000..59c6fd46 --- /dev/null +++ b/src/utility/STM32_WPAN/shci.h @@ -0,0 +1,1402 @@ +/** + ****************************************************************************** + * @file shci.h + * @author MCD Application Team + * @brief HCI command for the system channel + ****************************************************************************** + * @attention + * + * Copyright (c) 2018-2021 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ + + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __SHCI_H +#define __SHCI_H + +#ifdef __cplusplus +extern "C" { +#endif + + /* Includes ------------------------------------------------------------------*/ +#include "mbox_def.h" /* Requested to expose the MB_WirelessFwInfoTable_t structure */ + + /* Exported types ------------------------------------------------------------*/ + + /* SYSTEM EVENT */ + typedef enum + { + WIRELESS_FW_RUNNING = 0x00, + FUS_FW_RUNNING = 0x01, + } SHCI_SysEvt_Ready_Rsp_t; + + /* ERROR CODES + * + * These error codes are detected on CPU2 side and are send back to the CPU1 via a system + * notification message. It is up to the application running on CPU1 to manage these errors + * + * These errors can be generated by all layers (low level driver, stack, framework infrastructure, etc..) + */ + typedef enum + { + ERR_BLE_INIT = 0, /* This event is currently not reported by the CPU2 */ + ERR_THREAD_LLD_FATAL_ERROR = 125, /* The LLD driver used on 802_15_4 detected a fatal error */ + ERR_THREAD_UNKNOWN_CMD = 126, /* The command send by the CPU1 to control the Thread stack is unknown */ + ERR_ZIGBEE_UNKNOWN_CMD = 200, /* The command send by the CPU1 to control the Zigbee stack is unknown */ + } SCHI_SystemErrCode_t; + +#define SHCI_EVTCODE ( 0xFF ) +#define SHCI_SUB_EVT_CODE_BASE ( 0x9200 ) + + /** + * THE ORDER SHALL NOT BE CHANGED TO GUARANTEE COMPATIBILITY WITH THE CPU1 DEFINITION + */ + typedef enum + { + SHCI_SUB_EVT_CODE_READY = SHCI_SUB_EVT_CODE_BASE, + SHCI_SUB_EVT_ERROR_NOTIF, + SHCI_SUB_EVT_BLE_NVM_RAM_UPDATE, + SHCI_SUB_EVT_THREAD_NVM_RAM_UPDATE, + SHCI_SUB_EVT_NVM_START_WRITE, + SHCI_SUB_EVT_NVM_END_WRITE, + SHCI_SUB_EVT_NVM_START_ERASE, + SHCI_SUB_EVT_NVM_END_ERASE, + SHCI_SUB_EVT_CODE_CONCURRENT_802154_EVT, + } SHCI_SUB_EVT_CODE_t; + + /** + * SHCI_SUB_EVT_CODE_READY + * This notifies the CPU1 that the CPU2 is now ready to receive commands + * It reports as well which firmware is running on CPU2 : The wireless stack of the FUS (previously named RSS) + */ + typedef PACKED_STRUCT{ + SHCI_SysEvt_Ready_Rsp_t sysevt_ready_rsp; + } SHCI_C2_Ready_Evt_t; + + /** + * SHCI_SUB_EVT_ERROR_NOTIF + * This reports to the CPU1 some error form the CPU2 + */ + typedef PACKED_STRUCT{ + SCHI_SystemErrCode_t errorCode; + } SHCI_C2_ErrorNotif_Evt_t; + + /** + * SHCI_SUB_EVT_BLE_NVM_RAM_UPDATE + * This notifies the CPU1 which part of the BLE NVM RAM has been updated so that only the modified + * section could be written in Flash/NVM + * StartAddress : Start address of the section that has been modified + * Size : Size (in bytes) of the section that has been modified + */ + typedef PACKED_STRUCT{ + uint32_t StartAddress; + uint32_t Size; + } SHCI_C2_BleNvmRamUpdate_Evt_t; + + /** + * SHCI_SUB_EVT_THREAD_NVM_RAM_UPDATE + * This notifies the CPU1 which part of the OT NVM RAM has been updated so that only the modified + * section could be written in Flash/NVM + * StartAddress : Start address of the section that has been modified + * Size : Size (in bytes) of the section that has been modified + */ + typedef PACKED_STRUCT{ + uint32_t StartAddress; + uint32_t Size; + } SHCI_C2_ThreadNvmRamUpdate_Evt_t; + + /** + * SHCI_SUB_EVT_NVM_START_WRITE + * This notifies the CPU1 that the CPU2 has started a write procedure in Flash + * NumberOfWords : The number of 64bits data the CPU2 needs to write in Flash. + * For each 64bits data, the algorithm as described in AN5289 is executed. + * When this number is reported to 0, it means the Number of 64bits to be written + * was unknown when the procedure has started. + * When all data are written, the SHCI_SUB_EVT_NVM_END_WRITE event is reported + */ + typedef PACKED_STRUCT{ + uint32_t NumberOfWords; + } SHCI_C2_NvmStartWrite_Evt_t; + + /** + * SHCI_SUB_EVT_NVM_END_WRITE + * This notifies the CPU1 that the CPU2 has written all expected data in Flash + */ + + /** + * SHCI_SUB_EVT_NVM_START_ERASE + * This notifies the CPU1 that the CPU2 has started a erase procedure in Flash + * NumberOfSectors : The number of sectors the CPU2 needs to erase in Flash. + * For each sector, the algorithm as described in AN5289 is executed. + * When this number is reported to 0, it means the Number of sectors to be erased + * was unknown when the procedure has started. + * When all sectors are erased, the SHCI_SUB_EVT_NVM_END_ERASE event is reported + */ + typedef PACKED_STRUCT{ + uint32_t NumberOfSectors; + } SHCI_C2_NvmStartErase_Evt_t; + + /** + * SHCI_SUB_EVT_NVM_END_ERASE + * This notifies the CPU1 that the CPU2 has erased all expected flash sectors + */ + + /* SYSTEM COMMAND */ + typedef PACKED_STRUCT + { + /** + * MetaData holds : + * 2*32bits for chaining list + * 1*32bits with BLE header (type + Opcode + Length) + */ + uint32_t MetaData[3]; + } SHCI_Header_t; + + typedef enum + { + SHCI_Success = 0x00, + SHCI_UNKNOWN_CMD = 0x01, + SHCI_MEMORY_CAPACITY_EXCEEDED_ERR_CODE= 0x07, + SHCI_ERR_UNSUPPORTED_FEATURE = 0x11, + SHCI_ERR_INVALID_HCI_CMD_PARAMS = 0x12, + SHCI_ERR_INVALID_PARAMS = 0x42, /* only used for release < v1.13.0 */ + SHCI_ERR_INVALID_PARAMS_V2 = 0x92, /* available for release >= v1.13.0 */ + SHCI_FUS_CMD_NOT_SUPPORTED = 0xFF, + } SHCI_CmdStatus_t; + + typedef enum + { + SHCI_8BITS = 0x01, + SHCI_16BITS = 0x02, + SHCI_32BITS = 0x04, + } SHCI_Busw_t; + +#define SHCI_OGF ( 0x3F ) +#define SHCI_OCF_BASE ( 0x50 ) + + /** + * THE ORDER SHALL NOT BE CHANGED TO GUARANTEE COMPATIBILITY WITH THE CPU2 DEFINITION + */ + typedef enum + { + SHCI_OCF_C2_RESERVED1 = SHCI_OCF_BASE, + SHCI_OCF_C2_RESERVED2, + SHCI_OCF_C2_FUS_GET_STATE, + SHCI_OCF_C2_FUS_RESERVED1, + SHCI_OCF_C2_FUS_FW_UPGRADE, + SHCI_OCF_C2_FUS_FW_DELETE, + SHCI_OCF_C2_FUS_UPDATE_AUTH_KEY, + SHCI_OCF_C2_FUS_LOCK_AUTH_KEY, + SHCI_OCF_C2_FUS_STORE_USR_KEY, + SHCI_OCF_C2_FUS_LOAD_USR_KEY, + SHCI_OCF_C2_FUS_START_WS, + SHCI_OCF_C2_FUS_RESERVED2, + SHCI_OCF_C2_FUS_RESERVED3, + SHCI_OCF_C2_FUS_LOCK_USR_KEY, + SHCI_OCF_C2_FUS_UNLOAD_USR_KEY, + SHCI_OCF_C2_FUS_ACTIVATE_ANTIROLLBACK, + SHCI_OCF_C2_FUS_RESERVED7, + SHCI_OCF_C2_FUS_RESERVED8, + SHCI_OCF_C2_FUS_RESERVED9, + SHCI_OCF_C2_FUS_RESERVED10, + SHCI_OCF_C2_FUS_RESERVED11, + SHCI_OCF_C2_FUS_RESERVED12, + SHCI_OCF_C2_BLE_INIT, + SHCI_OCF_C2_THREAD_INIT, + SHCI_OCF_C2_DEBUG_INIT, + SHCI_OCF_C2_FLASH_ERASE_ACTIVITY, + SHCI_OCF_C2_CONCURRENT_SET_MODE, + SHCI_OCF_C2_FLASH_STORE_DATA, + SHCI_OCF_C2_FLASH_ERASE_DATA, + SHCI_OCF_C2_RADIO_ALLOW_LOW_POWER, + SHCI_OCF_C2_MAC_802_15_4_INIT, + SHCI_OCF_C2_REINIT, + SHCI_OCF_C2_ZIGBEE_INIT, + SHCI_OCF_C2_LLD_TESTS_INIT, + SHCI_OCF_C2_EXTPA_CONFIG, + SHCI_OCF_C2_SET_FLASH_ACTIVITY_CONTROL, + SHCI_OCF_C2_BLE_LLD_INIT, + SHCI_OCF_C2_CONFIG, + SHCI_OCF_C2_CONCURRENT_GET_NEXT_BLE_EVT_TIME, + SHCI_OCF_C2_CONCURRENT_ENABLE_NEXT_802154_EVT_NOTIFICATION, + SHCI_OCF_C2_802_15_4_DEINIT, + SHCI_OCF_C2_SET_SYSTEM_CLOCK, + } SHCI_OCF_t; + +#define SHCI_OPCODE_C2_FUS_GET_STATE (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_GET_STATE) +/** No command parameters */ +/** Response parameters*/ +/** It responds a 1 byte value holding FUS State error code when the FUS State value is 0xFF (FUS_STATE_VALUE_ERROR) */ + typedef enum + { + FUS_STATE_ERROR_NO_ERROR = 0x00, + FUS_STATE_ERROR_IMG_NOT_FOUND = 0x01, + FUS_STATE_ERROR_IMG_CORRUPT = 0x02, + FUS_STATE_ERROR_IMG_NOT_AUTHENTIC = 0x03, + FUS_STATE_ERROR_IMG_NOT_ENOUGH_SPACE = 0x04, + FUS_STATE_ERROR_IMAGE_USRABORT = 0x05, + FUS_STATE_ERROR_IMAGE_ERSERROR = 0x06, + FUS_STATE_ERROR_IMAGE_WRTERROR = 0x07, + FUS_STATE_ERROR_AUTH_TAG_ST_NOTFOUND = 0x08, + FUS_STATE_ERROR_AUTH_TAG_CUST_NOTFOUND = 0x09, + FUS_STATE_ERROR_AUTH_KEY_LOCKED = 0x0A, + FUS_STATE_ERROR_FW_ROLLBACK_ERROR = 0x11, + FUS_STATE_ERROR_STATE_NOT_RUNNING = 0xFE, + FUS_STATE_ERROR_ERR_UNKNOWN = 0xFF, + } SHCI_FUS_GetState_ErrorCode_t; + + enum + { + FUS_STATE_VALUE_IDLE = 0x00, + FUS_STATE_VALUE_FW_UPGRD_ONGOING = 0x10, + FUS_STATE_VALUE_FW_UPGRD_ONGOING_END = 0x1F, /* All values between 0x10 and 0x1F has the same meaning */ + FUS_STATE_VALUE_FUS_UPGRD_ONGOING = 0x20, + FUS_STATE_VALUE_FUS_UPGRD_ONGOING_END = 0x2F, /* All values between 0x20 and 0x2F has the same meaning */ + FUS_STATE_VALUE_SERVICE_ONGOING = 0x30, + FUS_STATE_VALUE_SERVICE_ONGOING_END = 0x3F, /* All values between 0x30 and 0x3F has the same meaning */ + FUS_STATE_VALUE_ERROR = 0xFF, + }; + +#define SHCI_OPCODE_C2_FUS_RESERVED1 (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_RESERVED1) +/** No command parameters */ +/** No response parameters*/ + +#define SHCI_OPCODE_C2_FUS_FW_UPGRADE (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_FW_UPGRADE) + /** No structure for command parameters */ + /** No response parameters*/ + +#define SHCI_OPCODE_C2_FUS_FW_DELETE (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_FW_DELETE) +/** No command parameters */ +/** No response parameters*/ + +#define SHCI_OPCODE_C2_FUS_UPDATE_AUTH_KEY (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_UPDATE_AUTH_KEY) + typedef PACKED_STRUCT{ + uint8_t KeySize; + uint8_t KeyData[64]; + } SHCI_C2_FUS_UpdateAuthKey_Cmd_Param_t; + + /** No response parameters*/ + +#define SHCI_OPCODE_C2_FUS_LOCK_AUTH_KEY (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_LOCK_AUTH_KEY) +/** No command parameters */ +/** No response parameters*/ + +#define SHCI_OPCODE_C2_FUS_STORE_USR_KEY (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_STORE_USR_KEY) + /** Command parameters */ + /* List of supported key type */ + enum + { + KEYTYPE_NONE = 0x00, + KEYTYPE_SIMPLE = 0x01, + KEYTYPE_MASTER = 0x02, + KEYTYPE_ENCRYPTED = 0x03, + }; + + /* List of supported key size */ + enum + { + KEYSIZE_16 = 16, + KEYSIZE_32 = 32, + }; + + typedef PACKED_STRUCT{ + uint8_t KeyType; + uint8_t KeySize; + uint8_t KeyData[32 + 12]; + } SHCI_C2_FUS_StoreUsrKey_Cmd_Param_t; + + /** Response parameters*/ + /** It responds a 1 byte value holding the index given for the stored key */ + +#define SHCI_OPCODE_C2_FUS_LOAD_USR_KEY (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_LOAD_USR_KEY) + /** Command parameters */ + /** 1 byte holding the key index value */ + + /** No response parameters*/ + +#define SHCI_OPCODE_C2_FUS_START_WS (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_START_WS) +/** No command parameters */ +/** No response parameters*/ + +#define SHCI_OPCODE_C2_FUS_RESERVED2 (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_RESERVED2) +/** No command parameters */ +/** No response parameters*/ + +#define SHCI_OPCODE_C2_FUS_RESERVED3 (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_RESERVED3) +/** No command parameters */ +/** No response parameters*/ + +#define SHCI_OPCODE_C2_FUS_LOCK_USR_KEY (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_LOCK_USR_KEY) + /** Command parameters */ + /** 1 byte holding the key index value */ + + /** No response parameters*/ + +#define SHCI_OPCODE_C2_FUS_UNLOAD_USR_KEY (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_UNLOAD_USR_KEY) +/** No command parameters */ +/** 1 byte holding the key index value */ + +#define SHCI_OPCODE_C2_FUS_ACTIVATE_ANTIROLLBACK (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_ACTIVATE_ANTIROLLBACK) +/** No command parameters */ +/** No response parameters*/ + +#define SHCI_OPCODE_C2_FUS_RESERVED7 (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_RESERVED7) +/** No command parameters */ +/** No response parameters*/ + +#define SHCI_OPCODE_C2_FUS_RESERVED8 (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_RESERVED8) +/** No command parameters */ +/** No response parameters*/ + +#define SHCI_OPCODE_C2_FUS_RESERVED9 (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_RESERVED9) +/** No command parameters */ +/** No response parameters*/ + +#define SHCI_OPCODE_C2_FUS_RESERVED10 (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_RESERVED10) +/** No command parameters */ +/** No response parameters*/ + +#define SHCI_OPCODE_C2_FUS_RESERVED11 (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_RESERVED11) +/** No command parameters */ +/** No response parameters*/ + +#define SHCI_OPCODE_C2_FUS_RESERVED12 (( SHCI_OGF << 10) + SHCI_OCF_C2_FUS_RESERVED12) +/** No command parameters */ +/** No response parameters*/ + +#define SHCI_OPCODE_C2_BLE_INIT (( SHCI_OGF << 10) + SHCI_OCF_C2_BLE_INIT) + /** THE ORDER SHALL NOT BE CHANGED */ + typedef PACKED_STRUCT{ + uint8_t* pBleBufferAddress; /**< NOT USED - shall be set to 0 */ + uint32_t BleBufferSize; /**< NOT USED - shall be set to 0 */ + + /** + * NumAttrRecord + * Maximum number of attribute records related to all the required characteristics (excluding the services) + * that can be stored in the GATT database, for the specific BLE user application. + * For each characteristic, the number of attribute records goes from two to five depending on the characteristic properties: + * - minimum of two (one for declaration and one for the value) + * - add one more record for each additional property: notify or indicate, broadcast, extended property. + * The total calculated value must be increased by 9, due to the records related to the standard attribute profile and + * GAP service characteristics, and automatically added when initializing GATT and GAP layers + * - Min value: <number of user attributes> + 9 + * - Max value: depending on the GATT database defined by user application + */ + uint16_t NumAttrRecord; + + /** + * NumAttrServ + * Defines the maximum number of services that can be stored in the GATT database. Note that the GAP and GATT services + * are automatically added at initialization so this parameter must be the number of user services increased by two. + * - Min value: <number of user service> + 2 + * - Max value: depending GATT database defined by user application + */ + uint16_t NumAttrServ; + + /** + * AttrValueArrSize + * NOTE: This parameter is ignored by the CPU2 when the parameter "Options" is set to "LL_only" ( see Options description in that structure ) + * + * Size of the storage area for the attribute values. + * Each characteristic contributes to the attrValueArrSize value as follows: + * - Characteristic value length plus: + * + 5 bytes if characteristic UUID is 16 bits + * + 19 bytes if characteristic UUID is 128 bits + * + 2 bytes if characteristic has a server configuration descriptor + * + 2 bytes * NumOfLinks if the characteristic has a client configuration descriptor + * + 2 bytes if the characteristic has extended properties + * Each descriptor contributes to the attrValueArrSize value as follows: + * - Descriptor length + */ + uint16_t AttrValueArrSize; + + /** + * NumOfLinks + * Maximum number of BLE links supported + * - Min value: 1 + * - Max value: 8 + */ + uint8_t NumOfLinks; + + /** + * ExtendedPacketLengthEnable + * Disable/enable the extended packet length BLE 5.0 feature + * - Disable: 0 + * - Enable: 1 + */ + uint8_t ExtendedPacketLengthEnable; + + /** + * PrWriteListSize + * NOTE: This parameter is ignored by the CPU2 when the parameter "Options" is set to "LL_only" ( see Options description in that structure ) + * + * Maximum number of supported "prepare write request" + * - Min value: given by the macro DEFAULT_PREP_WRITE_LIST_SIZE + * - Max value: a value higher than the minimum required can be specified, but it is not recommended + */ + uint8_t PrWriteListSize; + + /** + * MblockCount + * NOTE: This parameter is overwritten by the CPU2 with an hardcoded optimal value when the parameter "Options" is set to "LL_only" + * ( see Options description in that structure ) + * + * Number of allocated memory blocks for the BLE stack + * - Min value: given by the macro MBLOCKS_CALC + * - Max value: a higher value can improve data throughput performance, but uses more memory + */ + uint8_t MblockCount; + + /** + * AttMtu + * NOTE: This parameter is ignored by the CPU2 when the parameter "Options" is set to "LL_only" ( see Options description in that structure ) + * + * Maximum ATT MTU size supported + * - Min value: 23 + * - Max value: 512 + */ + uint16_t AttMtu; + + /** + * PeripheralSca + * The sleep clock accuracy (ppm value) that used in BLE connected Peripheral mode to calculate the window widening + * (in combination with the sleep clock accuracy sent by master in CONNECT_REQ PDU), + * refer to BLE 5.0 specifications - Vol 6 - Part B - chap 4.5.7 and 4.2.2 + * - Min value: 0 + * - Max value: 500 (worst possible admitted by specification) + */ + uint16_t PeripheralSca; + + /** + * CentralSca + * The sleep clock accuracy handled in Central mode. It is used to determine the connection and advertising events timing. + * It is transmitted to the slave in CONNEC_REQ PDU used by the slave to calculate the window widening, + * see PeripheralSca and Bluetooth Core Specification v5.0 Vol 6 - Part B - chap 4.5.7 and 4.2.2 + * Possible values: + * - 251 ppm to 500 ppm: 0 + * - 151 ppm to 250 ppm: 1 + * - 101 ppm to 150 ppm: 2 + * - 76 ppm to 100 ppm: 3 + * - 51 ppm to 75 ppm: 4 + * - 31 ppm to 50 ppm: 5 + * - 21 ppm to 30 ppm: 6 + * - 0 ppm to 20 ppm: 7 + */ + uint8_t CentralSca; + + /** + * LsSource + * Some information for Low speed clock mapped in bits field + * - bit 0: 1: Calibration for the RF system wakeup clock source 0: No calibration for the RF system wakeup clock source + * - bit 1: 1: STM32W5M Module device 0: Other devices as STM32WBxx SOC, STM32WB1M module + * - bit 2: 1: HSE/1024 Clock config 0: LSE Clock config + */ + uint8_t LsSource; + + /** + * MaxConnEventLength + * This parameter determines the maximum duration of a slave connection event. When this duration is reached the slave closes + * the current connections event (whatever is the CE_length parameter specified by the master in HCI_CREATE_CONNECTION HCI command), + * expressed in units of 625/256 us (~2.44 us) + * - Min value: 0 (if 0 is specified, the master and slave perform only a single TX-RX exchange per connection event) + * - Max value: 1638400 (4000 ms). A higher value can be specified (max 0xFFFFFFFF) but results in a maximum connection time + * of 4000 ms as specified. In this case the parameter is not applied, and the predicted CE length calculated on slave is not shortened + */ + uint32_t MaxConnEventLength; + + /** + * HsStartupTime + * Startup time of the high speed (16 or 32 MHz) crystal oscillator in units of 625/256 us (~2.44 us). + * - Min value: 0 + * - Max value: 820 (~2 ms). A higher value can be specified, but the value that implemented in stack is forced to ~2 ms + */ + uint16_t HsStartupTime; + + /** + * ViterbiEnable + * Viterbi implementation in BLE LL reception. + * - 0: Enable + * - 1: Disable + */ + uint8_t ViterbiEnable; + + /** + * Options flags + * - bit 0: 1: LL only 0: LL + host + * - bit 1: 1: no service change desc. 0: with service change desc. + * - bit 2: 1: device name Read-Only 0: device name R/W + * - bit 3: 1: extended advertizing supported 0: extended advertizing not supported + * - bit 4: 1: CS Algo #2 supported 0: CS Algo #2 not supported + * - bit 5: 1: Reduced GATT database in NVM 0: Full GATT database in NVM + * - bit 6: 1: GATT caching is used 0: GATT caching is not used + * - bit 7: 1: LE Power Class 1 0: LE Power Class 2-3 + * - other bits: complete with Options_extension flag + */ + uint8_t Options; + + /** + * HwVersion + * Reserved for future use - shall be set to 0 + */ + uint8_t HwVersion; + + /** + * Maximum number of connection-oriented channels in initiator mode. + * Range: 0 .. 64 + */ + uint8_t max_coc_initiator_nbr; + + /** + * Minimum transmit power in dBm supported by the Controller. + * Range: -127 .. 20 + */ + int8_t min_tx_power; + + /** + * Maximum transmit power in dBm supported by the Controller. + * Range: -127 .. 20 + */ + int8_t max_tx_power; + + /** + * RX model configuration + * - bit 0: 1: agc_rssi model improved vs RF blockers 0: Legacy agc_rssi model + * - other bits: reserved ( shall be set to 0) + */ + uint8_t rx_model_config; + + /* Maximum number of advertising sets. + * Range: 1 .. 8 with limitation: + * This parameter is linked to max_adv_data_len such as both compliant with allocated Total memory computed with BLE_EXT_ADV_BUFFER_SIZE based + * on Max Extended advertising configuration supported. + * This parameter is considered by the CPU2 when Options has SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV flag set + */ + uint8_t max_adv_set_nbr; + + /* Maximum advertising data length (in bytes) + * Range: 31 .. 1650 with limitation: + * This parameter is linked to max_adv_set_nbr such as both compliant with allocated Total memory computed with BLE_EXT_ADV_BUFFER_SIZE based + * on Max Extended advertising configuration supported. + * This parameter is considered by the CPU2 when Options has SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV flag set + */ + uint16_t max_adv_data_len; + + /* RF TX Path Compensation Value (16-bit signed integer). Units: 0.1 dB. + * Range: -1280 .. 1280 + */ + int16_t tx_path_compens; + + /* RF RX Path Compensation Value (16-bit signed integer). Units: 0.1 dB. + * Range: -1280 .. 1280 + */ + int16_t rx_path_compens; + + /* BLE core specification version (8-bit unsigned integer). + * values as: 11(5.2), 12(5.3), 13(5.4) + */ + uint8_t ble_core_version; + + /** + * Options flags extension + * - bit 0: 1: appearance Writable 0: appearance Read-Only + * - bit 1: 1: Enhanced ATT supported 0: Enhanced ATT not supported + * - other bits: reserved ( shall be set to 0) + */ + uint8_t Options_extension; + + } SHCI_C2_Ble_Init_Cmd_Param_t; + + typedef PACKED_STRUCT{ + SHCI_Header_t Header; /** Does not need to be initialized by the user */ + SHCI_C2_Ble_Init_Cmd_Param_t Param; + } SHCI_C2_Ble_Init_Cmd_Packet_t; + + /** + * Options + * Each definition below may be added together to build the Options value + * WARNING : Only one definition per bit shall be added to build the Options value + */ +#define SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY (1<<0) +#define SHCI_C2_BLE_INIT_OPTIONS_LL_HOST (0<<0) + +#define SHCI_C2_BLE_INIT_OPTIONS_NO_SVC_CHANGE_DESC (1<<1) +#define SHCI_C2_BLE_INIT_OPTIONS_WITH_SVC_CHANGE_DESC (0<<1) + +#define SHCI_C2_BLE_INIT_OPTIONS_DEVICE_NAME_RO (1<<2) +#define SHCI_C2_BLE_INIT_OPTIONS_DEVICE_NAME_RW (0<<2) + +#define SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV (1<<3) +#define SHCI_C2_BLE_INIT_OPTIONS_NO_EXT_ADV (0<<3) + +#define SHCI_C2_BLE_INIT_OPTIONS_CS_ALGO2 (1<<4) +#define SHCI_C2_BLE_INIT_OPTIONS_NO_CS_ALGO2 (0<<4) + +#define SHCI_C2_BLE_INIT_OPTIONS_REDUC_GATTDB_NVM (1<<5) +#define SHCI_C2_BLE_INIT_OPTIONS_FULL_GATTDB_NVM (0<<5) + +#define SHCI_C2_BLE_INIT_OPTIONS_GATT_CACHING_USED (1<<6) +#define SHCI_C2_BLE_INIT_OPTIONS_GATT_CACHING_NOTUSED (0<<6) + +#define SHCI_C2_BLE_INIT_OPTIONS_POWER_CLASS_1 (1<<7) +#define SHCI_C2_BLE_INIT_OPTIONS_POWER_CLASS_2_3 (0<<7) + + /** + * Options extension + * Each definition below may be added together to build the Options value + * WARNING : Only one definition per bit shall be added to build the Options value + */ +#define SHCI_C2_BLE_INIT_OPTIONS_APPEARANCE_WRITABLE (1<<0) +#define SHCI_C2_BLE_INIT_OPTIONS_APPEARANCE_READONLY (0<<0) + +#define SHCI_C2_BLE_INIT_OPTIONS_ENHANCED_ATT_SUPPORTED (1<<1) +#define SHCI_C2_BLE_INIT_OPTIONS_ENHANCED_ATT_NOTSUPPORTED (0<<1) + + /** + * RX models configuration + */ +#define SHCI_C2_BLE_INIT_RX_MODEL_AGC_RSSI_LEGACY (0<<0) +#define SHCI_C2_BLE_INIT_RX_MODEL_AGC_RSSI_BLOCKER (1<<0) + + /** + * BLE core version + */ +#define SHCI_C2_BLE_INIT_BLE_CORE_5_2 11 +#define SHCI_C2_BLE_INIT_BLE_CORE_5_3 12 +#define SHCI_C2_BLE_INIT_BLE_CORE_5_4 13 + + /** + * LsSource information + */ +#define SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB (0<<0) +#define SHCI_C2_BLE_INIT_CFG_BLE_LS_CALIB (1<<0) +#define SHCI_C2_BLE_INIT_CFG_BLE_LS_OTHER_DEV (0<<1) +#define SHCI_C2_BLE_INIT_CFG_BLE_LS_MOD5MM_DEV (1<<1) +#define SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE (0<<2) +#define SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_HSE_1024 (1<<2) + +#define SHCI_OPCODE_C2_THREAD_INIT (( SHCI_OGF << 10) + SHCI_OCF_C2_THREAD_INIT) +/** No command parameters */ +/** No response parameters*/ + +#define SHCI_OPCODE_C2_DEBUG_INIT (( SHCI_OGF << 10) + SHCI_OCF_C2_DEBUG_INIT) + /** Command parameters */ + typedef PACKED_STRUCT + { + uint8_t thread_config; + uint8_t ble_config; + uint8_t mac_802_15_4_config; + uint8_t zigbee_config; + } SHCI_C2_DEBUG_TracesConfig_t; + + typedef PACKED_STRUCT + { + uint8_t ble_dtb_cfg; + /** + * sys_dbg_cfg1 options flag + * - bit 0: 0: IP BLE core in LP mode 1: IP BLE core in run mode (no LP supported) + * - bit 1: 0: CPU2 STOP mode Enable 1: CPU2 STOP mode Disable + * - bit [2-7]: bits reserved ( shall be set to 0) + */ + uint8_t sys_dbg_cfg1; + uint8_t reserved[2]; + uint16_t STBY_DebugGpioaPinList; + uint16_t STBY_DebugGpiobPinList; + uint16_t STBY_DebugGpiocPinList; + uint16_t STBY_DtbGpioaPinList; + uint16_t STBY_DtbGpiobPinList; + } SHCI_C2_DEBUG_GeneralConfig_t; + + typedef PACKED_STRUCT{ + uint8_t *pGpioConfig; + uint8_t *pTracesConfig; + uint8_t *pGeneralConfig; + uint8_t GpioConfigSize; + uint8_t TracesConfigSize; + uint8_t GeneralConfigSize; + } SHCI_C2_DEBUG_init_Cmd_Param_t; + + typedef PACKED_STRUCT{ + SHCI_Header_t Header; /** Does not need to be initialized by the user */ + SHCI_C2_DEBUG_init_Cmd_Param_t Param; + } SHCI_C2_DEBUG_Init_Cmd_Packet_t; + /** No response parameters*/ + + /** + * Options + * Each definition below may be added together to build the Options value + * WARNING : Only one definition per bit shall be added to build the Options value + */ +#define SHCI_C2_DEBUG_OPTIONS_IPCORE_LP (0<<0) +#define SHCI_C2_DEBUG_OPTIONS_IPCORE_NO_LP (1<<0) + +#define SHCI_C2_DEBUG_OPTIONS_CPU2_STOP_EN (0<<1) +#define SHCI_C2_DEBUG_OPTIONS_CPU2_STOP_DIS (1<<1) + + +#define SHCI_OPCODE_C2_FLASH_ERASE_ACTIVITY (( SHCI_OGF << 10) + SHCI_OCF_C2_FLASH_ERASE_ACTIVITY) + /** Command parameters */ + typedef enum + { + ERASE_ACTIVITY_OFF = 0x00, + ERASE_ACTIVITY_ON = 0x01, + } SHCI_EraseActivity_t; + + /** No response parameters*/ + +#define SHCI_OPCODE_C2_CONCURRENT_SET_MODE (( SHCI_OGF << 10) + SHCI_OCF_C2_CONCURRENT_SET_MODE) +/** command parameters */ + typedef enum + { + BLE_ENABLE, + THREAD_ENABLE, + ZIGBEE_ENABLE, + MAC_ENABLE, + } SHCI_C2_CONCURRENT_Mode_Param_t; + /** No response parameters*/ + +#define SHCI_OPCODE_C2_CONCURRENT_GET_NEXT_BLE_EVT_TIME (( SHCI_OGF << 10) + SHCI_OCF_C2_CONCURRENT_GET_NEXT_BLE_EVT_TIME) +/** command parameters */ + typedef PACKED_STRUCT + { + uint32_t relative_time; + } SHCI_C2_CONCURRENT_GetNextBleEvtTime_Param_t; + /** No response parameters*/ + +#define SHCI_OPCODE_C2_CONCURRENT_ENABLE_NEXT_802154_EVT_NOTIFICATION (( SHCI_OGF << 10) + SHCI_OCF_C2_CONCURRENT_ENABLE_NEXT_802154_EVT_NOTIFICATION) + /** No command parameters */ + /** No response parameters*/ + +#define SHCI_OPCODE_C2_FLASH_STORE_DATA (( SHCI_OGF << 10) + SHCI_OCF_C2_FLASH_STORE_DATA) +#define SHCI_OPCODE_C2_FLASH_ERASE_DATA (( SHCI_OGF << 10) + SHCI_OCF_C2_FLASH_ERASE_DATA) +/** command parameters */ + typedef enum + { + BLE_IP, + THREAD_IP, + ZIGBEE_IP, + } SHCI_C2_FLASH_Ip_t; + /** No response parameters*/ + +#define SHCI_OPCODE_C2_RADIO_ALLOW_LOW_POWER (( SHCI_OGF << 10) + SHCI_OCF_C2_RADIO_ALLOW_LOW_POWER) + +#define SHCI_OPCODE_C2_MAC_802_15_4_INIT (( SHCI_OGF << 10) + SHCI_OCF_C2_MAC_802_15_4_INIT) + +#define SHCI_OPCODE_C2_REINIT (( SHCI_OGF << 10) + SHCI_OCF_C2_REINIT) + +#define SHCI_OPCODE_C2_ZIGBEE_INIT (( SHCI_OGF << 10) + SHCI_OCF_C2_ZIGBEE_INIT) + +#define SHCI_OPCODE_C2_LLD_TESTS_INIT (( SHCI_OGF << 10) + SHCI_OCF_C2_LLD_TESTS_INIT) + +#define SHCI_OPCODE_C2_BLE_LLD_INIT (( SHCI_OGF << 10) + SHCI_OCF_C2_BLE_LLD_INIT) + +#define SHCI_OPCODE_C2_EXTPA_CONFIG (( SHCI_OGF << 10) + SHCI_OCF_C2_EXTPA_CONFIG) + /** Command parameters */ + enum + { + EXT_PA_ENABLED_LOW, + EXT_PA_ENABLED_HIGH, + }/* gpio_polarity */; + + enum + { + EXT_PA_DISABLED, + EXT_PA_ENABLED, + }/* gpio_status */; + + typedef PACKED_STRUCT{ + uint32_t gpio_port; + uint16_t gpio_pin_number; + uint8_t gpio_polarity; + uint8_t gpio_status; + } SHCI_C2_EXTPA_CONFIG_Cmd_Param_t; + + /** No response parameters*/ + +#define SHCI_OPCODE_C2_SET_FLASH_ACTIVITY_CONTROL (( SHCI_OGF << 10) + SHCI_OCF_C2_SET_FLASH_ACTIVITY_CONTROL) + /** Command parameters */ + typedef enum + { + FLASH_ACTIVITY_CONTROL_PES, + FLASH_ACTIVITY_CONTROL_SEM7, + }SHCI_C2_SET_FLASH_ACTIVITY_CONTROL_Source_t; + + /** No response parameters*/ + +#define SHCI_OPCODE_C2_CONFIG (( SHCI_OGF << 10) + SHCI_OCF_C2_CONFIG) + + /** Command parameters */ + typedef PACKED_STRUCT{ + uint8_t PayloadCmdSize; + uint8_t Config1; + uint8_t EvtMask1; + uint8_t Spare1; + uint32_t BleNvmRamAddress; + uint32_t ThreadNvmRamAddress; + uint16_t RevisionID; + uint16_t DeviceID; + } SHCI_C2_CONFIG_Cmd_Param_t; + +#define SHCI_OPCODE_C2_802_15_4_DEINIT (( SHCI_OGF << 10) + SHCI_OCF_C2_802_15_4_DEINIT) + +#define SHCI_OPCODE_C2_SET_SYSTEM_CLOCK (( SHCI_OGF << 10) + SHCI_OCF_C2_SET_SYSTEM_CLOCK) + /** Command parameters */ + typedef enum + { + SET_SYSTEM_CLOCK_HSE_TO_PLL, + SET_SYSTEM_CLOCK_PLL_ON_TO_HSE, + SET_SYSTEM_CLOCK_PLL_OFF_TO_HSE, + }SHCI_C2_SET_SYSTEM_CLOCK_Cmd_Param_t; + +/** + * PayloadCmdSize + * Value that shall be used + */ +#define SHCI_C2_CONFIG_PAYLOAD_CMD_SIZE (sizeof(SHCI_C2_CONFIG_Cmd_Param_t) - 1) + +/** + * Device revision ID + */ +#define SHCI_C2_CONFIG_CUT2_0 (0x2000) +#define SHCI_C2_CONFIG_CUT2_1 (0x2001) +#define SHCI_C2_CONFIG_CUT2_2 (0x2003) + +/** + * Device ID + */ +#define SHCI_C2_CONFIG_STM32WB55xx (0x495) +#define SHCI_C2_CONFIG_STM32WB15xx (0x494) + +/** + * Config1 + * Each definition below may be added together to build the Config1 value + * WARNING : Only one definition per bit shall be added to build the Config1 value + */ +#define SHCI_C2_CONFIG_CONFIG1_BIT0_BLE_NVM_DATA_TO_INTERNAL_FLASH (0<<0) +#define SHCI_C2_CONFIG_CONFIG1_BIT0_BLE_NVM_DATA_TO_SRAM (1<<0) +#define SHCI_C2_CONFIG_CONFIG1_BIT1_THREAD_NVM_DATA_TO_INTERNAL_FLASH (0<<1) +#define SHCI_C2_CONFIG_CONFIG1_BIT1_THREAD_NVM_DATA_TO_SRAM (1<<1) +#define SHCI_C2_CONFIG_CONFIG1_BIT2_SET_EUI64_FORMAT (1<<2) + +/** + * EvtMask1 + * Each definition below may be added together to build the EvtMask1 value + */ +#define SHCI_C2_CONFIG_EVTMASK1_BIT0_ERROR_NOTIF_ENABLE (1<<0) +#define SHCI_C2_CONFIG_EVTMASK1_BIT1_BLE_NVM_RAM_UPDATE_ENABLE (1<<1) +#define SHCI_C2_CONFIG_EVTMASK1_BIT2_THREAD_NVM_RAM_UPDATE_ENABLE (1<<2) +#define SHCI_C2_CONFIG_EVTMASK1_BIT3_NVM_START_WRITE_ENABLE (1<<3) +#define SHCI_C2_CONFIG_EVTMASK1_BIT4_NVM_END_WRITE_ENABLE (1<<4) +#define SHCI_C2_CONFIG_EVTMASK1_BIT5_NVM_START_ERASE_ENABLE (1<<5) +#define SHCI_C2_CONFIG_EVTMASK1_BIT6_NVM_END_ERASE_ENABLE (1<<6) + +/** + * BleNvmRamAddress + * The buffer shall have a size of BLE_NVM_SRAM_SIZE number of 32bits + * The buffer shall be allocated in SRAM2 + */ +#define BLE_NVM_SRAM_SIZE (507) + +/** + * ThreadNvmRamAddress + * The buffer shall have a size of THREAD_NVM_SRAM_SIZE number of 32bits + * The buffer shall be allocated in SRAM2 + */ +#define THREAD_NVM_SRAM_SIZE (1016) + + + /** No response parameters*/ + + /* Exported type --------------------------------------------------------*/ +#define FUS_DEVICE_INFO_TABLE_VALIDITY_KEYWORD (0xA94656B9) + +/* + * At startup, the information relative to the wireless binary are stored in RAM through a structure defined by + * MB_WirelessFwInfoTable_t.This structure contains 4 fields (Version,MemorySize, Stack_info and a reserved part) + * each of those coded on 32 bits as shown on the table below: + * + * + * |7 |6 |5 |4 |3 |2 |1 |0 |7 |6 |5 |4 |3 |2 |1 |0 |7 |6 |5 |4 |3 |2 |1 |0 |7 |6 |5 |4 |3 |2 |1 |0 | + * ------------------------------------------------------------------------------------------------- + * Version | Major version | Minor version | Sub version | Branch |ReleaseType| + * ------------------------------------------------------------------------------------------------- + * MemorySize | SRAM2B (kB) | SRAM2A (kB) | SRAM1 (kB) | FLASH (4kb) | + * ------------------------------------------------------------------------------------------------- + * Info stack | Reserved | Reserved | Reserved | Type (MAC,Thread,BLE) | + * ------------------------------------------------------------------------------------------------- + * Reserved | Reserved | Reserved | Reserved | Reserved | + * ------------------------------------------------------------------------------------------------- + * + */ + +/* Field Version */ +#define INFO_VERSION_MAJOR_OFFSET 24 +#define INFO_VERSION_MAJOR_MASK 0xff000000 +#define INFO_VERSION_MINOR_OFFSET 16 +#define INFO_VERSION_MINOR_MASK 0x00ff0000 +#define INFO_VERSION_SUB_OFFSET 8 +#define INFO_VERSION_SUB_MASK 0x0000ff00 +#define INFO_VERSION_BRANCH_OFFSET 4 +#define INFO_VERSION_BRANCH_MASK 0x0000000f0 +#define INFO_VERSION_TYPE_OFFSET 0 +#define INFO_VERSION_TYPE_MASK 0x00000000f + +#define INFO_VERSION_TYPE_RELEASE 1 + +/* Field Memory */ +#define INFO_SIZE_SRAM2B_OFFSET 24 +#define INFO_SIZE_SRAM2B_MASK 0xff000000 +#define INFO_SIZE_SRAM2A_OFFSET 16 +#define INFO_SIZE_SRAM2A_MASK 0x00ff0000 +#define INFO_SIZE_SRAM1_OFFSET 8 +#define INFO_SIZE_SRAM1_MASK 0x0000ff00 +#define INFO_SIZE_FLASH_OFFSET 0 +#define INFO_SIZE_FLASH_MASK 0x000000ff + +/* Field stack information */ +#define INFO_STACK_TYPE_OFFSET 0 +#define INFO_STACK_TYPE_MASK 0x000000ff +#define INFO_STACK_TYPE_NONE 0 + +#define INFO_STACK_TYPE_BLE_FULL 0x01 +#define INFO_STACK_TYPE_BLE_HCI 0x02 +#define INFO_STACK_TYPE_BLE_LIGHT 0x03 +#define INFO_STACK_TYPE_BLE_BEACON 0x04 +#define INFO_STACK_TYPE_BLE_BASIC 0x05 +#define INFO_STACK_TYPE_BLE_FULL_EXT_ADV 0x06 +#define INFO_STACK_TYPE_BLE_HCI_EXT_ADV 0x07 +#define INFO_STACK_TYPE_THREAD_FTD 0x10 +#define INFO_STACK_TYPE_THREAD_MTD 0x11 +#define INFO_STACK_TYPE_ZIGBEE_FFD 0x30 +#define INFO_STACK_TYPE_ZIGBEE_RFD 0x31 +#define INFO_STACK_TYPE_MAC 0x40 +#define INFO_STACK_TYPE_BLE_THREAD_FTD_STATIC 0x50 +#define INFO_STACK_TYPE_BLE_THREAD_FTD_DYNAMIC 0x51 +#define INFO_STACK_TYPE_BLE_THREAD_LIGHT_DYNAMIC 0x52 +#define INFO_STACK_TYPE_802154_LLD_TESTS 0x60 +#define INFO_STACK_TYPE_802154_PHY_VALID 0x61 +#define INFO_STACK_TYPE_BLE_PHY_VALID 0x62 +#define INFO_STACK_TYPE_BLE_LLD_TESTS 0x63 +#define INFO_STACK_TYPE_BLE_RLV 0x64 +#define INFO_STACK_TYPE_802154_RLV 0x65 +#define INFO_STACK_TYPE_BLE_ZIGBEE_FFD_STATIC 0x70 +#define INFO_STACK_TYPE_BLE_ZIGBEE_RFD_STATIC 0x71 +#define INFO_STACK_TYPE_BLE_ZIGBEE_FFD_DYNAMIC 0x78 +#define INFO_STACK_TYPE_BLE_ZIGBEE_RFD_DYNAMIC 0x79 +#define INFO_STACK_TYPE_RLV 0x80 +#define INFO_STACK_TYPE_BLE_MAC_STATIC 0x90 + +typedef struct { +/** + * Wireless Info + */ + uint8_t VersionMajor; + uint8_t VersionMinor; + uint8_t VersionSub; + uint8_t VersionBranch; + uint8_t VersionReleaseType; + uint8_t MemorySizeSram2B; /*< Multiple of 1K */ + uint8_t MemorySizeSram2A; /*< Multiple of 1K */ + uint8_t MemorySizeSram1; /*< Multiple of 1K */ + uint8_t MemorySizeFlash; /*< Multiple of 4K */ + uint8_t StackType; +/** + * Fus Info + */ + uint8_t FusVersionMajor; + uint8_t FusVersionMinor; + uint8_t FusVersionSub; + uint8_t FusMemorySizeSram2B; /*< Multiple of 1K */ + uint8_t FusMemorySizeSram2A; /*< Multiple of 1K */ + uint8_t FusMemorySizeFlash; /*< Multiple of 4K */ +}WirelessFwInfo_t; + + +/* Exported functions ------------------------------------------------------- */ + + /** + * SHCI_C2_FUS_GetState + * @brief Read the FUS State + * If the user is not interested by the Error code response, a null value may + * be passed as parameter + * + * Note: This command is fully supported only by the FUS. + * When the wireless firmware receives that command, it responds SHCI_FUS_CMD_NOT_SUPPORTED the first time. + * When the wireless firmware receives that command a second time, it reboots the full device with the FUS running on CPU2 + * + * @param p_rsp : return the error code when the FUS State Value = 0xFF + * @retval FUS State Values + */ + uint8_t SHCI_C2_FUS_GetState( SHCI_FUS_GetState_ErrorCode_t *p_rsp ); + + /** + * SHCI_C2_FUS_FwUpgrade + * @brief Request the FUS to install the CPU2 firmware update + * Note: This command is only supported by the FUS. + * + * @param fw_src_add: Address of the firmware image location + * @param fw_dest_add: Address of the firmware destination + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_FUS_FwUpgrade( uint32_t fw_src_add, uint32_t fw_dest_add ); + + /** + * SHCI_C2_FUS_FwDelete + * @brief Delete the wireless stack on CPU2 + * Note: This command is only supported by the FUS. + * + * @param None + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_FUS_FwDelete( void ); + + /** + * SHCI_C2_FUS_UpdateAuthKey + * @brief Request the FUS to update the authentication key + * Note: This command is only supported by the FUS. + * + * @param pCmdPacket + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_FUS_UpdateAuthKey( SHCI_C2_FUS_UpdateAuthKey_Cmd_Param_t *pParam ); + + /** + * SHCI_C2_FUS_LockAuthKey + * @brief Request the FUS to prevent any future update of the authentication key + * Note: This command is only supported by the FUS. + * + * @param None + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_FUS_LockAuthKey( void ); + + /** + * SHCI_C2_FUS_StoreUsrKey + * @brief Request the FUS to store the user key + * Note: This command is supported by both the FUS and the wireless stack. + * + * @param pParam : command parameter + * @param p_key_index : Index allocated by the FUS to the stored key + * + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_FUS_StoreUsrKey( SHCI_C2_FUS_StoreUsrKey_Cmd_Param_t *pParam, uint8_t *p_key_index ); + + /** + * SHCI_C2_FUS_LoadUsrKey + * @brief Request the FUS to load the user key into the AES + * Note: This command is supported by both the FUS and the wireless stack. + * + * @param key_index : index of the user key to load in AES1 + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_FUS_LoadUsrKey( uint8_t key_index ); + + /** + * SHCI_C2_FUS_StartWs + * @brief Request the FUS to reboot on the wireless stack + * Note: This command is only supported by the FUS. + * + * @param None + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_FUS_StartWs( void ); + + /** + * SHCI_C2_FUS_LockUsrKey + * @brief Request the FUS to lock the user key so that it cannot be updated later on + * Note: This command is supported by both the FUS and the wireless stack. + * + * @param key_index : index of the user key to lock + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_FUS_LockUsrKey( uint8_t key_index ); + + /** + * SHCI_C2_FUS_UnloadUsrKey + * @brief Request the FUS to Unload the user key so that the CPU1 may use the AES with another Key + * Note: This command is supported by both the FUS and the wireless stack. + * + * @param key_index : index of the user key to unload + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_FUS_UnloadUsrKey( uint8_t key_index ); + + /** + * SHCI_C2_FUS_ActivateAntiRollback + * @brief Request the FUS to enable the AntiRollback feature so that it is not possible to update the wireless firmware + * with an older version than the current one. + * Note: + * - This command is only supported by the FUS. + * - Once this feature is enabled, it is not possible anymore to disable it. + * + * @param None + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_FUS_ActivateAntiRollback( void ); + + /** + * SHCI_C2_BLE_Init + * @brief Provides parameters and starts the BLE Stack + * + * @param pCmdPacket : Parameters are described SHCI_C2_Ble_Init_Cmd_Packet_t declaration + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_BLE_Init( SHCI_C2_Ble_Init_Cmd_Packet_t *pCmdPacket ); + + /** + * SHCI_C2_THREAD_Init + * @brief Starts the THREAD Stack + * + * @param None + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_THREAD_Init( void ); + + /** + * SHCI_C2_LLDTESTS_Init + * @brief Starts the LLD tests CLI + * + * @param param_size : Nb of bytes + * @param p_param : pointer with data to give from M4 to M0 + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_LLDTESTS_Init( uint8_t param_size, uint8_t * p_param ); + + /** + * SHCI_C2_BLE_LLD_Init + * @brief Starts the LLD tests BLE + * + * @param param_size : Nb of bytes + * @param p_param : pointer with data to give from M4 to M0 + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_BLE_LLD_Init( uint8_t param_size, uint8_t * p_param ); + + /** + * SHCI_C2_ZIGBEE_Init + * @brief Starts the Zigbee Stack + * + * @param None + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_ZIGBEE_Init( void ); + + /** + * SHCI_C2_DEBUG_Init + * @brief Starts the Traces + * + * @param None + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_DEBUG_Init( SHCI_C2_DEBUG_Init_Cmd_Packet_t *pCmdPacket ); + + /** + * SHCI_C2_FLASH_EraseActivity + * @brief Provides the information of the start and the end of a flash erase window on the CPU1 + * The protection will be active until next end of radio event. + * + * @param erase_activity: Start/End of erase activity + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_FLASH_EraseActivity( SHCI_EraseActivity_t erase_activity ); + + /** + * SHCI_C2_CONCURRENT_SetMode + * @brief Enable/Disable Thread on CPU2 (M0+) + * + * @param Mode: BLE or Thread enable flag + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_CONCURRENT_SetMode( SHCI_C2_CONCURRENT_Mode_Param_t Mode ); + + /** + * SHCI_C2_CONCURRENT_GetNextBleEvtTime + * @brief Get the next BLE event date (relative time) + * + * @param Command Packet + * @retval None + */ + SHCI_CmdStatus_t SHCI_C2_CONCURRENT_GetNextBleEvtTime( SHCI_C2_CONCURRENT_GetNextBleEvtTime_Param_t *pParam ); + + /** + * SHCI_C2_CONCURRENT_EnableNext_802154_EvtNotification + * @brief Activate the next 802.15.4 event notification (one shot) + * + * @param None + * @retval None + */ + SHCI_CmdStatus_t SHCI_C2_CONCURRENT_EnableNext_802154_EvtNotification( void ); + + /** + * SHCI_C2_FLASH_StoreData + * @brief Store Data in Flash + * + * @param Ip: BLE or THREAD + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_FLASH_StoreData( SHCI_C2_FLASH_Ip_t Ip ); + + /** + * SHCI_C2_FLASH_EraseData + * @brief Erase Data in Flash + * + * @param Ip: BLE or THREAD + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_FLASH_EraseData( SHCI_C2_FLASH_Ip_t Ip ); + + /** + * SHCI_C2_RADIO_AllowLowPower + * @brief Allow or forbid IP_radio (802_15_4 or BLE) to enter in low power mode. + * + * @param Ip: BLE or 802_15_5 + * @param FlagRadioLowPowerOn: True or false + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_RADIO_AllowLowPower( SHCI_C2_FLASH_Ip_t Ip,uint8_t FlagRadioLowPowerOn); + + + /** + * SHCI_C2_MAC_802_15_4_Init + * @brief Starts the MAC 802.15.4 on M0 + * + * @param None + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_MAC_802_15_4_Init( void ); + + /** + * SHCI_GetWirelessFwInfo + * @brief This function read back the information relative to the wireless binary loaded. + * Refer yourself to MB_WirelessFwInfoTable_t structure to get the significance + * of the different parameters returned. + * @param pWirelessInfo : Pointer to WirelessFwInfo_t. + * + * @retval SHCI_Success + */ + SHCI_CmdStatus_t SHCI_GetWirelessFwInfo( WirelessFwInfo_t* pWirelessInfo ); + + /** + * SHCI_C2_Reinit + * @brief This is required to allow the CPU1 to fake a set C2BOOT when it has already been set. + * In order to fake a C2BOOT, the CPU1 shall : + * - Send SHCI_C2_Reinit() + * - call SEV instruction + * WARNING: + * This function is intended to be used by the SBSFU + * + * @param None + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_Reinit( void ); + + /** + * SHCI_C2_ExtpaConfig + * @brief Send the Ext PA configuration + * When the CPU2 receives the command, it controls the Ext PA as requested by the configuration + * This configures only which IO is used to enable/disable the ExtPA and the associated polarity + * This command has no effect on the other IO that is used to control the mode of the Ext PA (Rx/Tx) + * + * @param gpio_port: GPIOx where x can be (A..F) to select the GPIO peripheral for STM32WBxx family + * @param gpio_pin_number: This parameter can be one of GPIO_PIN_x (= LL_GPIO_PIN_x) where x can be (0..15). + * @param gpio_polarity: This parameter can be either + * - EXT_PA_ENABLED_LOW: ExtPA is enabled when GPIO is low + * - EXT_PA_ENABLED_HIGH: ExtPA is enabled when GPIO is high + * @param gpio_status: This parameter can be either + * - EXT_PA_DISABLED: Stop driving the ExtPA + * - EXT_PA_ENABLED: Drive the ExtPA according to radio activity + * (ON before the Event and OFF at the end of the event) + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_ExtpaConfig(uint32_t gpio_port, uint16_t gpio_pin_number, uint8_t gpio_polarity, uint8_t gpio_status); + + /** + * SHCI_C2_SetFlashActivityControl + * @brief Set the mechanism to be used on CPU2 to prevent the CPU1 to either write or erase in flash + * + * @param Source: It can be one of the following list + * - FLASH_ACTIVITY_CONTROL_PES : The CPU2 set the PES bit to prevent the CPU1 to either read or write in flash + * - FLASH_ACTIVITY_CONTROL_SEM7 : The CPU2 gets the semaphore 7 to prevent the CPU1 to either read or write in flash. + * This requires the CPU1 to first get semaphore 7 before erasing or writing the flash. + * + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_SetFlashActivityControl(SHCI_C2_SET_FLASH_ACTIVITY_CONTROL_Source_t Source); + + /** + * SHCI_C2_Config + * @brief Send the system configuration to the CPU2 + * + * @param pCmdPacket: address of the buffer holding following parameters + * uint8_t PayloadCmdSize : Size of the payload - shall be SHCI_C2_CONFIG_PAYLOAD_CMD_SIZE + * uint8_t Config1 : + * - bit0 : 0 - BLE NVM Data data are flushed in internal secure flash + * 1 - BLE NVM Data are written in SRAM cache pointed by BleNvmRamAddress + * - bit1 : 0 - THREAD NVM Data data are flushed in internal secure flash + * 1 - THREAD NVM Data are written in SRAM cache pointed by ThreadNvmRamAddress + * - bit2 : 0 - Thread EUI64 is set to new (and current) format + * 1 - Thread EUI64 is set to old format + * - bit3 to bit7 : Unused, shall be set to 0 + * uint8_t EvtMask1 : + * When a bit is set to 0, the event is not reported + * bit0 : Asynchronous Event with Sub Evt Code 0x9201 (= SHCI_SUB_EVT_ERROR_NOTIF) + * ... + * bit31 : Asynchronous Event with Sub Evt Code 0x9220 + * uint8_t Spare1 : Unused, shall be set to 0 + * uint32_t BleNvmRamAddress : + * Only considered when Config1.bit0 = 1 + * When set to 0, data are kept in internal SRAM on CPU2 + * Otherwise, data are copied in the cache pointed by BleNvmRamAddress + * The size of the buffer shall be BLE_NVM_SRAM_SIZE (number of 32bits) + * The buffer shall be allocated in SRAM2 + * uint32_t ThreadNvmRamAddress : + * Only considered when Config1.bit1 = 1 + * When set to 0, data are kept in internal SRAM on CPU2 + * Otherwise, data are copied in the cache pointed by ThreadNvmRamAddress + * The size of the buffer shall be THREAD_NVM_SRAM_SIZE (number of 32bits) + * The buffer shall be allocated in SRAM1 + * + * Please check macro definition to be used for this function + * They are defined in this file next to the definition of SHCI_OPCODE_C2_CONFIG + * + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_Config(SHCI_C2_CONFIG_Cmd_Param_t *pCmdPacket); + + /** + * SHCI_C2_802_15_4_DeInit + * @brief Deinit 802.15.4 layer (to be used before entering StandBy mode) + * + * @param None + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_802_15_4_DeInit( void ); + + /** + * SHCI_C2_SetSystemClock + * @brief Request CPU2 to change system clock + * + * @param clockSel: It can be one of the following list + * - SET_SYSTEM_CLOCK_HSE_TO_PLL : CPU2 set system clock to PLL, PLL must be configured and started before. + * - SET_SYSTEM_CLOCK_PLL_ON_TO_HSE : CPU2 set System clock to HSE, PLL is still ON after command execution. + * - SET_SYSTEM_CLOCK_PLL_OFF_TO_HSE : CPU2 set System clock to HSE, PLL is turned OFF after command execution. + * + * @retval Status + */ + SHCI_CmdStatus_t SHCI_C2_SetSystemClock( SHCI_C2_SET_SYSTEM_CLOCK_Cmd_Param_t clockSel ); + + +#ifdef __cplusplus +} +#endif + +#endif /*__SHCI_H */ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/src/utility/STM32_WPAN/shci_tl.c b/src/utility/STM32_WPAN/shci_tl.c new file mode 100644 index 00000000..25e1a214 --- /dev/null +++ b/src/utility/STM32_WPAN/shci_tl.c @@ -0,0 +1,271 @@ +/** + ****************************************************************************** + * @file shci.c + * @author MCD Application Team + * @brief System HCI command implementation + ****************************************************************************** + * @attention + * + * Copyright (c) 2018-2021 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ + + +#if defined(STM32WBxx) +/* Includes ------------------------------------------------------------------*/ +#include "stm32_wpan_common.h" + +#include "stm_list.h" +#include "shci_tl.h" +#include "stm32_def.h" +#include "wiring_time.h" + +/* Private typedef -----------------------------------------------------------*/ +typedef enum +{ + SHCI_TL_CMD_RESP_RELEASE, + SHCI_TL_CMD_RESP_WAIT, +} SHCI_TL_CmdRespStatus_t; + +/* Private defines -----------------------------------------------------------*/ +/** + * The default System HCI layer timeout is set to 33s + */ +#define SHCI_TL_DEFAULT_TIMEOUT (33000) + +/* Private macros ------------------------------------------------------------*/ +/* Public variables ---------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +/** + * START of Section SYSTEM_DRIVER_CONTEXT + */ +PLACE_IN_SECTION("SYSTEM_DRIVER_CONTEXT") static tListNode SHciAsynchEventQueue; +PLACE_IN_SECTION("SYSTEM_DRIVER_CONTEXT") static volatile SHCI_TL_CmdStatus_t SHCICmdStatus; +PLACE_IN_SECTION("SYSTEM_DRIVER_CONTEXT") static TL_CmdPacket_t *pCmdBuffer; +PLACE_IN_SECTION("SYSTEM_DRIVER_CONTEXT") SHCI_TL_UserEventFlowStatus_t SHCI_TL_UserEventFlow; +/** + * END of Section SYSTEM_DRIVER_CONTEXT + */ + +static tSHciContext shciContext; +static void (* StatusNotCallBackFunction) (SHCI_TL_CmdStatus_t status); + +static volatile SHCI_TL_CmdRespStatus_t CmdRspStatusFlag; + +/* Private function prototypes -----------------------------------------------*/ +static void Cmd_SetStatus(SHCI_TL_CmdStatus_t shcicmdstatus); +static void TlCmdEvtReceived(TL_EvtPacket_t *shcievt); +static void TlUserEvtReceived(TL_EvtPacket_t *shcievt); +static void TlInit( TL_CmdPacket_t * p_cmdbuffer ); + +/* Interface ------- ---------------------------------------------------------*/ +void shci_init(void(* UserEvtRx)(void* pData), void* pConf) +{ + StatusNotCallBackFunction = ((SHCI_TL_HciInitConf_t *)pConf)->StatusNotCallBack; + shciContext.UserEvtRx = UserEvtRx; + + shci_register_io_bus (&shciContext.io); + + TlInit((TL_CmdPacket_t *)(((SHCI_TL_HciInitConf_t *)pConf)->p_cmdbuffer)); + + return; +} + +void shci_user_evt_proc(void) +{ + TL_EvtPacket_t *phcievtbuffer; + tSHCI_UserEvtRxParam UserEvtRxParam; + + /** + * Up to release version v1.2.0, a while loop was implemented to read out events from the queue as long as + * it is not empty. However, in a bare metal implementation, this leads to calling in a "blocking" mode + * shci_user_evt_proc() as long as events are received without giving the opportunity to run other tasks + * in the background. + * From now, the events are reported one by one. When it is checked there is still an event pending in the queue, + * a request to the user is made to call again shci_user_evt_proc(). + * This gives the opportunity to the application to run other background tasks between each event. + */ + + /** + * It is more secure to use LST_remove_head()/LST_insert_head() compare to LST_get_next_node()/LST_remove_node() + * in case the user overwrite the header where the next/prev pointers are located + */ + if((LST_is_empty(&SHciAsynchEventQueue) == FALSE) && (SHCI_TL_UserEventFlow != SHCI_TL_UserEventFlow_Disable)) + { + LST_remove_head ( &SHciAsynchEventQueue, (tListNode **)&phcievtbuffer ); + + if (shciContext.UserEvtRx != NULL) + { + UserEvtRxParam.pckt = phcievtbuffer; + UserEvtRxParam.status = SHCI_TL_UserEventFlow_Enable; + shciContext.UserEvtRx((void *)&UserEvtRxParam); + SHCI_TL_UserEventFlow = UserEvtRxParam.status; + } + else + { + SHCI_TL_UserEventFlow = SHCI_TL_UserEventFlow_Enable; + } + + if(SHCI_TL_UserEventFlow != SHCI_TL_UserEventFlow_Disable) + { + TL_MM_EvtDone( phcievtbuffer ); + } + else + { + /** + * put back the event in the queue + */ + LST_insert_head ( &SHciAsynchEventQueue, (tListNode *)phcievtbuffer ); + } + } + + if((LST_is_empty(&SHciAsynchEventQueue) == FALSE) && (SHCI_TL_UserEventFlow != SHCI_TL_UserEventFlow_Disable)) + { + shci_notify_asynch_evt((void*) &SHciAsynchEventQueue); + } + + + return; +} + +void shci_resume_flow( void ) +{ + SHCI_TL_UserEventFlow = SHCI_TL_UserEventFlow_Enable; + + /** + * It is better to go through the background process as it is not sure from which context this API may + * be called + */ + shci_notify_asynch_evt((void*) &SHciAsynchEventQueue); + + return; +} + +void shci_send( uint16_t cmd_code, uint8_t len_cmd_payload, uint8_t * p_cmd_payload, TL_EvtPacket_t * p_rsp ) +{ + Cmd_SetStatus(SHCI_TL_CmdBusy); + + pCmdBuffer->cmdserial.cmd.cmdcode = cmd_code; + pCmdBuffer->cmdserial.cmd.plen = len_cmd_payload; + + memcpy(pCmdBuffer->cmdserial.cmd.payload, p_cmd_payload, len_cmd_payload ); + CmdRspStatusFlag = SHCI_TL_CMD_RESP_WAIT; + shciContext.io.Send(0,0); + + shci_cmd_resp_wait(SHCI_TL_DEFAULT_TIMEOUT); + + /** + * The command complete of a system command does not have the header + * It starts immediately with the evtserial field + */ + memcpy( &(p_rsp->evtserial), pCmdBuffer, ((TL_EvtSerial_t*)pCmdBuffer)->evt.plen + TL_EVT_HDR_SIZE ); + + Cmd_SetStatus(SHCI_TL_CmdAvailable); + + return; +} + +void shci_notify_asynch_evt(void *pdata) +{ + UNUSED(pdata); + /* Need to parse data in future version */ + shci_user_evt_proc(); +} + +void shci_register_io_bus(tSHciIO *fops) +{ + /* Register IO bus services */ + fops->Init = TL_SYS_Init; + fops->Send = TL_SYS_SendCmd; +} + +/* Private functions ---------------------------------------------------------*/ +static void TlInit( TL_CmdPacket_t * p_cmdbuffer ) +{ + TL_SYS_InitConf_t Conf; + + pCmdBuffer = p_cmdbuffer; + + LST_init_head (&SHciAsynchEventQueue); + + Cmd_SetStatus(SHCI_TL_CmdAvailable); + + SHCI_TL_UserEventFlow = SHCI_TL_UserEventFlow_Enable; + + /* Initialize low level driver */ + if (shciContext.io.Init) + { + + Conf.p_cmdbuffer = (uint8_t *)p_cmdbuffer; + Conf.IoBusCallBackCmdEvt = TlCmdEvtReceived; + Conf.IoBusCallBackUserEvt = TlUserEvtReceived; + shciContext.io.Init(&Conf); + } + + return; +} + +static void Cmd_SetStatus(SHCI_TL_CmdStatus_t shcicmdstatus) +{ + if(shcicmdstatus == SHCI_TL_CmdBusy) + { + if(StatusNotCallBackFunction != 0) + { + StatusNotCallBackFunction( SHCI_TL_CmdBusy ); + } + SHCICmdStatus = SHCI_TL_CmdBusy; + } + else + { + SHCICmdStatus = SHCI_TL_CmdAvailable; + if(StatusNotCallBackFunction != 0) + { + StatusNotCallBackFunction( SHCI_TL_CmdAvailable ); + } + } + + return; +} + +static void TlCmdEvtReceived(TL_EvtPacket_t *shcievt) +{ + (void)(shcievt); + shci_cmd_resp_release(0); /**< Notify the application the Cmd response has been received */ + + return; +} + +static void TlUserEvtReceived(TL_EvtPacket_t *shcievt) +{ + LST_insert_tail(&SHciAsynchEventQueue, (tListNode *)shcievt); + shci_notify_asynch_evt((void*) &SHciAsynchEventQueue); /**< Notify the application a full HCI event has been received */ + + return; +} + +/* Weak implementation ----------------------------------------------------------------*/ +__WEAK void shci_cmd_resp_wait(uint32_t timeout) +{ + for (unsigned long start = millis(); (millis() - start) < timeout;) { + if (CmdRspStatusFlag == SHCI_TL_CMD_RESP_RELEASE) { + break; + } + } + return; +} + +__WEAK void shci_cmd_resp_release(uint32_t flag) +{ + (void)flag; + + CmdRspStatusFlag = SHCI_TL_CMD_RESP_RELEASE; + + return; +} +#endif /* STM32WBxx */ diff --git a/src/utility/STM32_WPAN/shci_tl.h b/src/utility/STM32_WPAN/shci_tl.h new file mode 100644 index 00000000..74d0ff38 --- /dev/null +++ b/src/utility/STM32_WPAN/shci_tl.h @@ -0,0 +1,173 @@ +/** + ****************************************************************************** + * @file shci_tl.h + * @author MCD Application Team + * @brief System HCI command header for the system channel + ****************************************************************************** + * @attention + * + * Copyright (c) 2018-2021 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ + +#ifndef __SHCI_TL_H_ +#define __SHCI_TL_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "tl.h" + +/* Exported defines -----------------------------------------------------------*/ +typedef enum +{ + SHCI_TL_UserEventFlow_Disable, + SHCI_TL_UserEventFlow_Enable, +} SHCI_TL_UserEventFlowStatus_t; + +typedef enum +{ + SHCI_TL_CmdBusy, + SHCI_TL_CmdAvailable +} SHCI_TL_CmdStatus_t; + +/** + * @brief Structure used to manage the BUS IO operations. + * All the structure fields will point to functions defined at user level. + * @{ + */ +typedef struct +{ + int32_t (* Init) (void* pConf); /**< Pointer to SHCI TL function for the IO Bus initialization */ + int32_t (* DeInit) (void); /**< Pointer to SHCI TL function for the IO Bus de-initialization */ + int32_t (* Reset) (void); /**< Pointer to SHCI TL function for the IO Bus reset */ + int32_t (* Receive) (uint8_t*, uint16_t); /**< Pointer to SHCI TL function for the IO Bus data reception */ + int32_t (* Send) (uint8_t*, uint16_t); /**< Pointer to SHCI TL function for the IO Bus data transmission */ + int32_t (* DataAck) (uint8_t*, uint16_t* len); /**< Pointer to SHCI TL function for the IO Bus data ack reception */ + int32_t (* GetTick) (void); /**< Pointer to BSP function for getting the HAL time base timestamp */ +} tSHciIO; +/** + * @} + */ + +/** + * @brief Contain the SHCI context + * @{ + */ +typedef struct +{ + tSHciIO io; /**< Manage the BUS IO operations */ + void (* UserEvtRx) (void * pData); /**< User System events callback function pointer */ +} tSHciContext; + +typedef struct +{ + SHCI_TL_UserEventFlowStatus_t status; + TL_EvtPacket_t *pckt; +} tSHCI_UserEvtRxParam; + +typedef struct +{ + uint8_t *p_cmdbuffer; + void (* StatusNotCallBack) (SHCI_TL_CmdStatus_t status); +} SHCI_TL_HciInitConf_t; + +/** + * shci_send + * @brief Send an System HCI Command + * + * @param : cmd_code = Opcode of the command + * @param : len_cmd_payload = Length of the command payload + * @param : p_cmd_payload = Address of the command payload + * @param : p_rsp_status = Address of the full buffer holding the command complete event + * @retval : None + */ +void shci_send( uint16_t cmd_code, uint8_t len_cmd_payload, uint8_t * p_cmd_payload, TL_EvtPacket_t * p_rsp_status ); + +/** + * @brief Register IO bus services. + * @param fops The SHCI IO structure managing the IO BUS + * @retval None + */ +void shci_register_io_bus(tSHciIO* fops); + +/** + * @brief Interrupt service routine that must be called when the system channel + * reports a packet has been received + * + * @param pdata Packet or event pointer + * @retval None + */ +void shci_notify_asynch_evt(void* pdata); + +/** + * @brief This function resume the User Event Flow which has been stopped on return + * from UserEvtRx() when the User Event has not been processed. + * + * @param None + * @retval None + */ +void shci_resume_flow(void); + + +/** + * @brief This function is called when an System HCI Command is sent to the CPU2 and the response is waited. + * It is called from the same context the System HCI command has been sent. + * It shall not return until the command response notified by shci_cmd_resp_release() is received. + * A weak implementation is available in shci_tl.c based on polling mechanism + * The user may re-implement this function in the application to improve performance : + * - It may use UTIL_SEQ_WaitEvt() API when using the Sequencer + * - It may use a semaphore when using cmsis_os interface + * + * @param timeout: Waiting timeout + * @retval None + */ +void shci_cmd_resp_wait(uint32_t timeout); + +/** + * @brief This function is called when an System HCI command is received from the CPU2. + * A weak implementation is available in shci_tl.c based on polling mechanism + * The user may re-implement this function in the application to improve performance : + * - It may use UTIL_SEQ_SetEvt() API when using the Sequencer + * - It may use a semaphore when using cmsis_os interface + * + * + * @param flag: Release flag + * @retval None + */ +void shci_cmd_resp_release(uint32_t flag); + + +/** + * @brief This process shall be called each time the shci_notify_asynch_evt notification is received + * + * @param None + * @retval None + */ + +void shci_user_evt_proc(void); + +/** + * @brief Initialize the System Host Controller Interface. + * This function must be called before any communication on the System Channel + * + * @param UserEvtRx: System events callback function pointer + * This callback is triggered when an user event is received on + * the System Channel from CPU2. + * @param pConf: Configuration structure pointer + * @retval None + */ +void shci_init(void(* UserEvtRx)(void* pData), void* pConf); + +#ifdef __cplusplus +} +#endif + +#endif /* __SHCI_TL_H_ */ diff --git a/src/utility/STM32_WPAN/stm32_wpan_common.h b/src/utility/STM32_WPAN/stm32_wpan_common.h new file mode 100644 index 00000000..f407bb98 --- /dev/null +++ b/src/utility/STM32_WPAN/stm32_wpan_common.h @@ -0,0 +1,171 @@ +/** + ****************************************************************************** + * @file stm32_wpan_common.h + * @author MCD Application Team + * @brief Common file to utilities + ****************************************************************************** + * @attention + * + * Copyright (c) 2018-2021 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ + + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __STM32_WPAN_COMMON_H +#define __STM32_WPAN_COMMON_H + +#ifdef __cplusplus +extern "C" { +#endif + +#if defined ( __CC_ARM )||defined (__ARMCC_VERSION) + #define __ASM __asm /*!< asm keyword for ARM Compiler */ + #define __INLINE __inline /*!< inline keyword for ARM Compiler */ + #define __STATIC_INLINE static __inline +#elif defined ( __ICCARM__ ) + #define __ASM __asm /*!< asm keyword for IAR Compiler */ + #define __INLINE inline /*!< inline keyword for IAR Compiler. Only available in High optimization mode! */ + #define __STATIC_INLINE static inline +#elif defined ( __GNUC__ ) + #define __ASM __asm /*!< asm keyword for GNU Compiler */ + #define __INLINE inline /*!< inline keyword for GNU Compiler */ + #define __STATIC_INLINE static inline +#endif + +#include <stdint.h> +#include <string.h> +#include <stdio.h> +#include <stdlib.h> +#include <stdarg.h> +#include "cmsis_compiler.h" + + /* -------------------------------- * + * Basic definitions * + * -------------------------------- */ + +#undef NULL +#define NULL 0U + +#undef FALSE +#define FALSE 0U + +#undef TRUE +#define TRUE (!0U) + + /* -------------------------------- * + * Critical Section definition * + * -------------------------------- */ +#undef BACKUP_PRIMASK +#define BACKUP_PRIMASK() uint32_t primask_bit= __get_PRIMASK() + +#undef DISABLE_IRQ +#define DISABLE_IRQ() __disable_irq() + +#undef RESTORE_PRIMASK +#define RESTORE_PRIMASK() __set_PRIMASK(primask_bit) + + /* -------------------------------- * + * Macro delimiters * + * -------------------------------- */ +#undef M_BEGIN +#define M_BEGIN do { + +#undef M_END +#define M_END } while(0) + + /* -------------------------------- * + * Some useful macro definitions * + * -------------------------------- */ +#undef MAX +#define MAX(a, b) (((a) > (b)) ? (a) : (b)) + +#undef MIN +#define MIN(a, b) (((a) < (b)) ? (a) : (b)) + +#undef MODINC +#define MODINC( a, m ) M_BEGIN (a)++; if ((a)>=(m)) (a)=0; M_END + +#undef MODDEC +#define MODDEC( a, m ) M_BEGIN if ((a)==0) (a)=(m); (a)--; M_END + +#undef MODADD +#define MODADD( a, b, m ) M_BEGIN (a)+=(b); if ((a)>=(m)) (a)-=(m); M_END + +#undef MODSUB +#define MODSUB( a, b, m ) MODADD( a, (m)-(b), m ) + +#undef ALIGN +#ifdef WIN32 +#define ALIGN(n) +#else +#define ALIGN(n) __attribute__((aligned(n))) +#endif + +#undef PAUSE +#define PAUSE( t ) M_BEGIN \ + volatile int _i; \ + for ( _i = t; _i > 0; _i -- ); \ + M_END +#undef DIVF +#define DIVF( x, y ) ((x)/(y)) + +#undef DIVC +#define DIVC( x, y ) (((x)+(y)-1)/(y)) + +#undef DIVR +#define DIVR( x, y ) (((x)+((y)/2))/(y)) + +#undef SHRR +#define SHRR( x, n ) ((((x)>>((n)-1))+1)>>1) + +#undef BITN +#define BITN( w, n ) (((w)[(n)/32] >> ((n)%32)) & 1) + +#undef BITNSET +#define BITNSET( w, n, b ) M_BEGIN (w)[(n)/32] |= ((U32)(b))<<((n)%32); M_END + +/* -------------------------------- * + * Section attribute * + * -------------------------------- */ +#undef PLACE_IN_SECTION +#define PLACE_IN_SECTION( __x__ ) __attribute__((section (__x__))) + +/* ----------------------------------- * + * Packed usage (compiler dependent) * + * ----------------------------------- */ +#undef PACKED__ +#undef PACKED_STRUCT + +#if defined ( __CC_ARM ) + #if defined ( __GNUC__ ) + /* GNU extension */ + #define PACKED__ __attribute__((packed)) + #define PACKED_STRUCT struct PACKED__ + #elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050U) + #define PACKED__ __attribute__((packed)) + #define PACKED_STRUCT struct PACKED__ + #else + #define PACKED__(TYPE) __packed TYPE + #define PACKED_STRUCT PACKED__(struct) + #endif +#elif defined ( __GNUC__ ) + #define PACKED__ __attribute__((packed)) + #define PACKED_STRUCT struct PACKED__ +#elif defined (__ICCARM__) + #define PACKED_STRUCT __packed struct +#else + #define PACKED_STRUCT __packed struct +#endif + +#ifdef __cplusplus +} +#endif + +#endif /*__STM32_WPAN_COMMON_H */ diff --git a/src/utility/STM32_WPAN/stm_list.c b/src/utility/STM32_WPAN/stm_list.c new file mode 100644 index 00000000..df6c2155 --- /dev/null +++ b/src/utility/STM32_WPAN/stm_list.c @@ -0,0 +1,210 @@ +/** + ****************************************************************************** + * @file stm_list.c + * @author MCD Application Team + * @brief TCircular Linked List Implementation. + ****************************************************************************** + * @attention + * + * Copyright (c) 2018-2021 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ + + +#if defined(STM32WBxx) +/****************************************************************************** + * Include Files + ******************************************************************************/ +#include "stdint.h" +#include "cmsis_gcc.h" +#include "stm32_wpan_common.h" + +#include "stm_list.h" + +/****************************************************************************** + * Function Definitions + ******************************************************************************/ +void LST_init_head (tListNode * listHead) +{ + listHead->next = listHead; + listHead->prev = listHead; +} + +uint8_t LST_is_empty (tListNode * listHead) +{ + uint32_t primask_bit; + uint8_t return_value; + + primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ + __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ + if(listHead->next == listHead) + { + return_value = TRUE; + } + else + { + return_value = FALSE; + } + __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ + + return return_value; +} + +void LST_insert_head (tListNode * listHead, tListNode * node) +{ + uint32_t primask_bit; + + primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ + __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ + + node->next = listHead->next; + node->prev = listHead; + listHead->next = node; + (node->next)->prev = node; + + __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ +} + + +void LST_insert_tail (tListNode * listHead, tListNode * node) +{ + uint32_t primask_bit; + + primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ + __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ + + node->next = listHead; + node->prev = listHead->prev; + listHead->prev = node; + (node->prev)->next = node; + + __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ +} + + +void LST_remove_node (tListNode * node) +{ + uint32_t primask_bit; + + primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ + __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ + + (node->prev)->next = node->next; + (node->next)->prev = node->prev; + + __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ +} + + +void LST_remove_head (tListNode * listHead, tListNode ** node ) +{ + uint32_t primask_bit; + + primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ + __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ + + *node = listHead->next; + LST_remove_node (listHead->next); + + __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ +} + + +void LST_remove_tail (tListNode * listHead, tListNode ** node ) +{ + uint32_t primask_bit; + + primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ + __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ + + *node = listHead->prev; + LST_remove_node (listHead->prev); + + __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ +} + + +void LST_insert_node_after (tListNode * node, tListNode * ref_node) +{ + uint32_t primask_bit; + + primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ + __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ + + node->next = ref_node->next; + node->prev = ref_node; + ref_node->next = node; + (node->next)->prev = node; + + __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ +} + + +void LST_insert_node_before (tListNode * node, tListNode * ref_node) +{ + uint32_t primask_bit; + + primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ + __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ + + node->next = ref_node; + node->prev = ref_node->prev; + ref_node->prev = node; + (node->prev)->next = node; + + __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ +} + + +int LST_get_size (tListNode * listHead) +{ + int size = 0; + tListNode * temp; + uint32_t primask_bit; + + primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ + __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ + + temp = listHead->next; + while (temp != listHead) + { + size++; + temp = temp->next; + } + + __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ + + return (size); +} + +void LST_get_next_node (tListNode * ref_node, tListNode ** node) +{ + uint32_t primask_bit; + + primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ + __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ + + *node = ref_node->next; + + __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ +} + + +void LST_get_prev_node (tListNode * ref_node, tListNode ** node) +{ + uint32_t primask_bit; + + primask_bit = __get_PRIMASK(); /**< backup PRIMASK bit */ + __disable_irq(); /**< Disable all interrupts by setting PRIMASK bit on Cortex*/ + + *node = ref_node->prev; + + __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ +} +#endif /* STM32WBxx */ diff --git a/src/utility/STM32_WPAN/stm_list.h b/src/utility/STM32_WPAN/stm_list.h new file mode 100644 index 00000000..b7c3254c --- /dev/null +++ b/src/utility/STM32_WPAN/stm_list.h @@ -0,0 +1,55 @@ +/** + ****************************************************************************** + * @file stm_list.h + * @author MCD Application Team + * @brief Header file for linked list library. + ****************************************************************************** + * @attention + * + * Copyright (c) 2018-2021 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ + + +#ifndef _STM_LIST_H_ +#define _STM_LIST_H_ + +/* Includes ------------------------------------------------------------------*/ +#include "stm32_wpan_common.h" + +typedef PACKED_STRUCT _tListNode { + struct _tListNode * next; + struct _tListNode * prev; +} tListNode; + +void LST_init_head (tListNode * listHead); + +uint8_t LST_is_empty (tListNode * listHead); + +void LST_insert_head (tListNode * listHead, tListNode * node); + +void LST_insert_tail (tListNode * listHead, tListNode * node); + +void LST_remove_node (tListNode * node); + +void LST_remove_head (tListNode * listHead, tListNode ** node ); + +void LST_remove_tail (tListNode * listHead, tListNode ** node ); + +void LST_insert_node_after (tListNode * node, tListNode * ref_node); + +void LST_insert_node_before (tListNode * node, tListNode * ref_node); + +int LST_get_size (tListNode * listHead); + +void LST_get_next_node (tListNode * ref_node, tListNode ** node); + +void LST_get_prev_node (tListNode * ref_node, tListNode ** node); + +#endif /* _STM_LIST_H_ */ diff --git a/src/utility/STM32_WPAN/tl.h b/src/utility/STM32_WPAN/tl.h new file mode 100644 index 00000000..74520878 --- /dev/null +++ b/src/utility/STM32_WPAN/tl.h @@ -0,0 +1,372 @@ +/** + ****************************************************************************** + * @file tl.h + * @author MCD Application Team + * @brief Header for tl module + ****************************************************************************** + * @attention + * + * Copyright (c) 2018-2021 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ + + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __TL_H +#define __TL_H + +#ifdef __cplusplus +extern "C" { +#endif + + +/* Includes ------------------------------------------------------------------*/ +#include "stm32_wpan_common.h" + +/* Exported defines -----------------------------------------------------------*/ +#define TL_BLECMD_PKT_TYPE ( 0x01 ) +#define TL_ACL_DATA_PKT_TYPE ( 0x02 ) +#define TL_BLEEVT_PKT_TYPE ( 0x04 ) +#define TL_OTCMD_PKT_TYPE ( 0x08 ) +#define TL_OTRSP_PKT_TYPE ( 0x09 ) +#define TL_CLICMD_PKT_TYPE ( 0x0A ) +#define TL_OTNOT_PKT_TYPE ( 0x0C ) +#define TL_OTACK_PKT_TYPE ( 0x0D ) +#define TL_CLINOT_PKT_TYPE ( 0x0E ) +#define TL_CLIACK_PKT_TYPE ( 0x0F ) +#define TL_SYSCMD_PKT_TYPE ( 0x10 ) +#define TL_SYSRSP_PKT_TYPE ( 0x11 ) +#define TL_SYSEVT_PKT_TYPE ( 0x12 ) +#define TL_CLIRESP_PKT_TYPE ( 0x15 ) +#define TL_M0CMD_PKT_TYPE ( 0x16 ) +#define TL_LOCCMD_PKT_TYPE ( 0x20 ) +#define TL_LOCRSP_PKT_TYPE ( 0x21 ) +#define TL_TRACES_APP_PKT_TYPE ( 0x40 ) +#define TL_TRACES_WL_PKT_TYPE ( 0x41 ) + +#define TL_CMD_HDR_SIZE (4) +#define TL_EVT_HDR_SIZE (3) +#define TL_EVT_CS_PAYLOAD_SIZE (4) + +#define TL_BLEEVT_CC_OPCODE (0x0E) +#define TL_BLEEVT_CS_OPCODE (0x0F) +#define TL_BLEEVT_VS_OPCODE (0xFF) + +#define TL_BLEEVT_CC_PACKET_SIZE (TL_EVT_HDR_SIZE + sizeof(TL_CcEvt_t)) +#define TL_BLEEVT_CC_BUFFER_SIZE (sizeof(TL_PacketHeader_t) + TL_BLEEVT_CC_PACKET_SIZE) +/* Exported types ------------------------------------------------------------*/ +/**< Packet header */ +typedef PACKED_STRUCT +{ + uint32_t *next; + uint32_t *prev; +} TL_PacketHeader_t; + +/******************************************************************************* + * Event type + */ + +/** + * This the payload of TL_Evt_t for a command status event + */ +typedef PACKED_STRUCT +{ + uint8_t status; + uint8_t numcmd; + uint16_t cmdcode; +} TL_CsEvt_t; + +/** + * This the payload of TL_Evt_t for a command complete event, only used a pointer + */ +typedef PACKED_STRUCT +{ + uint8_t numcmd; + uint16_t cmdcode; + uint8_t payload[2]; +} TL_CcEvt_t; + +/** + * This the payload of TL_Evt_t for an asynchronous event, only used a pointer + */ +typedef PACKED_STRUCT +{ + uint16_t subevtcode; + uint8_t payload[2]; +} TL_AsynchEvt_t; + +/** + * This the payload of TL_Evt_t, only used a pointer + */ +typedef PACKED_STRUCT +{ + uint8_t evtcode; + uint8_t plen; + uint8_t payload[4]; +} TL_Evt_t; + +typedef PACKED_STRUCT +{ + uint8_t type; + TL_Evt_t evt; +} TL_EvtSerial_t; + +/** + * This format shall be used for all events (asynchronous and command response) reported + * by the CPU2 except for the command response of a system command where the header is not there + * and the format to be used shall be TL_EvtSerial_t. + * Note: Be careful that the asynchronous events reported by the CPU2 on the system channel do + * include the header and shall use TL_EvtPacket_t format. Only the command response format on the + * system channel is different. + */ +typedef PACKED_STRUCT +{ + TL_PacketHeader_t header; + TL_EvtSerial_t evtserial; +} TL_EvtPacket_t; + +/***************************************************************************************** + * Command type + */ + +typedef PACKED_STRUCT +{ + uint16_t cmdcode; + uint8_t plen; + uint8_t payload[255]; +} TL_Cmd_t; + +typedef PACKED_STRUCT +{ + uint8_t type; + TL_Cmd_t cmd; +} TL_CmdSerial_t; + +typedef PACKED_STRUCT +{ + TL_PacketHeader_t header; + TL_CmdSerial_t cmdserial; +} TL_CmdPacket_t; + +/***************************************************************************************** + * HCI ACL DATA type + */ +typedef PACKED_STRUCT +{ + uint8_t type; + uint16_t handle; + uint16_t length; + uint8_t acl_data[1]; +} TL_AclDataSerial_t; + +typedef PACKED_STRUCT +{ + TL_PacketHeader_t header; + TL_AclDataSerial_t AclDataSerial; +} TL_AclDataPacket_t; + +typedef struct +{ + uint8_t *p_BleSpareEvtBuffer; + uint8_t *p_SystemSpareEvtBuffer; + uint8_t *p_AsynchEvtPool; + uint32_t AsynchEvtPoolSize; + uint8_t *p_TracesEvtPool; + uint32_t TracesEvtPoolSize; +} TL_MM_Config_t; + +typedef struct +{ + uint8_t *p_ThreadOtCmdRspBuffer; + uint8_t *p_ThreadCliRspBuffer; + uint8_t *p_ThreadNotAckBuffer; + uint8_t *p_ThreadCliNotBuffer; +} TL_TH_Config_t; + +typedef struct +{ + uint8_t *p_LldTestsCliCmdRspBuffer; + uint8_t *p_LldTestsM0CmdBuffer; +} TL_LLD_tests_Config_t; + +typedef struct +{ + uint8_t *p_BleLldCmdRspBuffer; + uint8_t *p_BleLldM0CmdBuffer; +} TL_BLE_LLD_Config_t; + +typedef struct +{ + uint8_t *p_Mac_802_15_4_CmdRspBuffer; + uint8_t *p_Mac_802_15_4_NotAckBuffer; +} TL_MAC_802_15_4_Config_t; + +typedef struct +{ + uint8_t *p_ZigbeeOtCmdRspBuffer; + uint8_t *p_ZigbeeNotAckBuffer; + uint8_t *p_ZigbeeNotifRequestBuffer; +} TL_ZIGBEE_Config_t; + +/** + * @brief Contain the BLE HCI Init Configuration + * @{ + */ +typedef struct +{ + void (* IoBusEvtCallBack) ( TL_EvtPacket_t *phcievt ); + void (* IoBusAclDataTxAck) ( void ); + uint8_t *p_cmdbuffer; + uint8_t *p_AclDataBuffer; +} TL_BLE_InitConf_t; + +/** + * @brief Contain the SYSTEM HCI Init Configuration + * @{ + */ +typedef struct +{ + void (* IoBusCallBackCmdEvt) (TL_EvtPacket_t *phcievt); + void (* IoBusCallBackUserEvt) (TL_EvtPacket_t *phcievt); + uint8_t *p_cmdbuffer; +} TL_SYS_InitConf_t; + +/***************************************************************************************** + * Event type copied from ble_legacy.h + */ + +typedef PACKED_STRUCT +{ + uint8_t type; + uint8_t data[1]; +} hci_uart_pckt; + +typedef PACKED_STRUCT +{ + uint8_t evt; + uint8_t plen; + uint8_t data[1]; +} hci_event_pckt; + +typedef PACKED_STRUCT +{ + uint8_t subevent; + uint8_t data[1]; +} evt_le_meta_event; + +/** + * Vendor specific event for BLE core. + */ +typedef PACKED_STRUCT +{ + uint16_t ecode; /**< One of the BLE core event codes. */ + uint8_t data[1]; +} evt_blecore_aci; + +/* Bluetooth 48 bit address (in little-endian order). + */ +typedef uint8_t tBDAddr[6]; + + +/* Exported constants --------------------------------------------------------*/ +/* External variables --------------------------------------------------------*/ +/* Exported macros -----------------------------------------------------------*/ +/* Exported functions ------------------------------------------------------- */ + +/****************************************************************************** + * GENERAL + ******************************************************************************/ +void TL_Enable( void ); +void TL_Init( void ); + +/****************************************************************************** + * BLE + ******************************************************************************/ +int32_t TL_BLE_Init( void* pConf ); +int32_t TL_BLE_SendCmd( uint8_t* buffer, uint16_t size ); +int32_t TL_BLE_SendAclData( uint8_t* buffer, uint16_t size ); + +/****************************************************************************** + * SYSTEM + ******************************************************************************/ +int32_t TL_SYS_Init( void* pConf ); +int32_t TL_SYS_SendCmd( uint8_t* buffer, uint16_t size ); + +/****************************************************************************** + * THREAD + ******************************************************************************/ +void TL_THREAD_Init( TL_TH_Config_t *p_Config ); +void TL_OT_SendCmd( void ); +void TL_CLI_SendCmd( void ); +void TL_OT_CmdEvtReceived( TL_EvtPacket_t * Otbuffer ); +void TL_THREAD_NotReceived( TL_EvtPacket_t * Notbuffer ); +void TL_THREAD_SendAck ( void ); +void TL_THREAD_CliSendAck ( void ); +void TL_THREAD_CliNotReceived( TL_EvtPacket_t * Notbuffer ); + +/****************************************************************************** + * LLD TESTS + ******************************************************************************/ +void TL_LLDTESTS_Init( TL_LLD_tests_Config_t *p_Config ); +void TL_LLDTESTS_SendCliCmd( void ); +void TL_LLDTESTS_ReceiveCliRsp( TL_CmdPacket_t * Notbuffer ); +void TL_LLDTESTS_SendCliRspAck( void ); +void TL_LLDTESTS_ReceiveM0Cmd( TL_CmdPacket_t * Notbuffer ); +void TL_LLDTESTS_SendM0CmdAck( void ); + +/****************************************************************************** + * BLE LLD + ******************************************************************************/ +void TL_BLE_LLD_Init( TL_BLE_LLD_Config_t *p_Config ); +void TL_BLE_LLD_SendCliCmd( void ); +void TL_BLE_LLD_ReceiveCliRsp( TL_CmdPacket_t * Notbuffer ); +void TL_BLE_LLD_SendCliRspAck( void ); +void TL_BLE_LLD_ReceiveM0Cmd( TL_CmdPacket_t * Notbuffer ); +void TL_BLE_LLD_SendM0CmdAck( void ); +void TL_BLE_LLD_SendCmd( void ); +void TL_BLE_LLD_ReceiveRsp( TL_CmdPacket_t * Notbuffer ); +void TL_BLE_LLD_SendRspAck( void ); +/****************************************************************************** + * MEMORY MANAGER + ******************************************************************************/ +void TL_MM_Init( TL_MM_Config_t *p_Config ); +void TL_MM_EvtDone( TL_EvtPacket_t * hcievt ); + +/****************************************************************************** + * TRACES + ******************************************************************************/ +void TL_TRACES_Init( void ); +void TL_TRACES_EvtReceived( TL_EvtPacket_t * hcievt ); + +/****************************************************************************** + * MAC 802.15.4 + ******************************************************************************/ +void TL_MAC_802_15_4_Init( TL_MAC_802_15_4_Config_t *p_Config ); +void TL_MAC_802_15_4_SendCmd( void ); +void TL_MAC_802_15_4_CmdEvtReceived( TL_EvtPacket_t * Otbuffer ); +void TL_MAC_802_15_4_NotReceived( TL_EvtPacket_t * Notbuffer ); +void TL_MAC_802_15_4_SendAck ( void ); + +/****************************************************************************** + * ZIGBEE + ******************************************************************************/ +void TL_ZIGBEE_Init( TL_ZIGBEE_Config_t *p_Config ); +void TL_ZIGBEE_SendM4RequestToM0( void ); +void TL_ZIGBEE_SendM4AckToM0Notify ( void ); +void TL_ZIGBEE_NotReceived( TL_EvtPacket_t * Notbuffer ); +void TL_ZIGBEE_CmdEvtReceived( TL_EvtPacket_t * Otbuffer ); +void TL_ZIGBEE_M0RequestReceived(TL_EvtPacket_t * Otbuffer ); +void TL_ZIGBEE_SendM4AckToM0Request(void); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*__TL_H */ + diff --git a/src/utility/STM32_WPAN/tl_dbg_conf.h b/src/utility/STM32_WPAN/tl_dbg_conf.h new file mode 100644 index 00000000..841d1968 --- /dev/null +++ b/src/utility/STM32_WPAN/tl_dbg_conf.h @@ -0,0 +1,140 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * File Name : tl_dbg_conf.h + * Description : Debug configuration file for stm32wpan transport layer interface. + * + ****************************************************************************** + * @attention + * + * Copyright (c) 2019-2021 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef TL_DBG_CONF_H +#define TL_DBG_CONF_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* USER CODE BEGIN Tl_Conf */ + +/* Includes ------------------------------------------------------------------*/ +#include "core_debug.h" + +/** + * Enable or Disable traces + * The raw data output is the hci binary packet format as specified by the BT specification * + */ +#ifndef TL_SHCI_CMD_DBG_EN +#define TL_SHCI_CMD_DBG_EN 1 /* Reports System commands sent to CPU2 and the command response */ +#endif + +#ifndef TL_SHCI_EVT_DBG_EN +#define TL_SHCI_EVT_DBG_EN 1 /* Reports System Asynchronous Events received from CPU2 */ +#endif + +#ifndef TL_HCI_CMD_DBG_EN +#define TL_HCI_CMD_DBG_EN 1 /* Reports BLE command sent to CPU2 and the command response */ +#endif + +#ifndef TL_HCI_EVT_DBG_EN +#define TL_HCI_EVT_DBG_EN 1 /* Reports BLE Asynchronous Events received from CPU2 */ +#endif + +#ifndef TL_MM_DBG_EN +#define TL_MM_DBG_EN 1 /* Reports the information of the buffer released to CPU2 */ +#endif + +/** + * Macro definition + */ + +/** + * System Transport Layer + */ +#if (TL_SHCI_CMD_DBG_EN != 0) +#define TL_SHCI_CMD_DBG_MSG core_debug +#define TL_SHCI_CMD_DBG_BUF PRINT_LOG_BUFF_DBG +#else +#define TL_SHCI_CMD_DBG_MSG(...) +#define TL_SHCI_CMD_DBG_BUF(...) +#endif + +#define TL_SHCI_CMD_DBG_RAW(...) + +#if (TL_SHCI_EVT_DBG_EN != 0) +#define TL_SHCI_EVT_DBG_MSG core_debug +#define TL_SHCI_EVT_DBG_BUF PRINT_LOG_BUFF_DBG +#else +#define TL_SHCI_EVT_DBG_MSG(...) +#define TL_SHCI_EVT_DBG_BUF(...) +#endif + +#define TL_SHCI_EVT_DBG_RAW(...) + +/** + * BLE Transport Layer + */ +#if (TL_HCI_CMD_DBG_EN != 0) +#define TL_HCI_CMD_DBG_MSG core_debug +#define TL_HCI_CMD_DBG_BUF PRINT_LOG_BUFF_DBG +#else +#define TL_HCI_CMD_DBG_MSG(...) +#define TL_HCI_CMD_DBG_BUF(...) +#endif + +#define TL_HCI_CMD_DBG_RAW(...) + +#if (TL_HCI_EVT_DBG_EN != 0) +#define TL_HCI_EVT_DBG_MSG core_debug +#define TL_HCI_EVT_DBG_BUF PRINT_LOG_BUFF_DBG +#else +#define TL_HCI_EVT_DBG_MSG(...) +#define TL_HCI_EVT_DBG_BUF(...) +#endif + +#define TL_HCI_EVT_DBG_RAW(...) + +/** + * Memory Manager - Released buffer tracing + */ +#if (TL_MM_DBG_EN != 0) +#define TL_MM_DBG_MSG core_debug +#else +#define TL_MM_DBG_MSG(...) +#endif + + +#define PRINT_LOG_BUFF_DBG(...) DbgTraceBuffer(__VA_ARGS__) + +void DbgTraceBuffer(const void *pBuffer, uint32_t u32Length, const char *strFormat, ...) +{ + va_list vaArgs; + uint32_t u32Index; + va_start(vaArgs, strFormat); + vprintf(strFormat, vaArgs); + va_end(vaArgs); + for (u32Index = 0; u32Index < u32Length; u32Index ++) + { + core_debug(" %02X", ((const uint8_t *) pBuffer)[u32Index]); + } +} + +/* USER CODE END Tl_Conf */ + +#ifdef __cplusplus +} +#endif + +#endif /* TL_DBG_CONF_H */ + diff --git a/src/utility/STM32_WPAN/tl_mbox.c b/src/utility/STM32_WPAN/tl_mbox.c new file mode 100644 index 00000000..9a2a2973 --- /dev/null +++ b/src/utility/STM32_WPAN/tl_mbox.c @@ -0,0 +1,855 @@ +/** + ****************************************************************************** + * @file tl_mbox.c + * @author MCD Application Team + * @brief Transport layer for the mailbox interface + ****************************************************************************** + * @attention + * + * Copyright (c) 2018-2021 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ + +#if defined(STM32WBxx) +/* Includes ------------------------------------------------------------------*/ +#include "stm32_wpan_common.h" +#include "hw.h" + +#include "stm_list.h" +#include "tl.h" +#include "mbox_def.h" +#include "tl_dbg_conf.h" + +/* Private typedef -----------------------------------------------------------*/ +typedef enum +{ + TL_MB_MM_RELEASE_BUFFER, + TL_MB_BLE_CMD, + TL_MB_BLE_CMD_RSP, + TL_MB_BLE_ASYNCH_EVT, + TL_MB_SYS_CMD, + TL_MB_SYS_CMD_RSP, + TL_MB_SYS_ASYNCH_EVT, +} TL_MB_PacketType_t; + +/* Private defines -----------------------------------------------------------*/ +/* Private macros ------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ + +/**< reference table */ +PLACE_IN_SECTION("MAPPING_TABLE") static volatile MB_RefTable_t TL_RefTable; +PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_DeviceInfoTable_t TL_DeviceInfoTable; +PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_BleTable_t TL_BleTable; +PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_ThreadTable_t TL_ThreadTable; +PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_LldTestsTable_t TL_LldTestsTable; +PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_BleLldTable_t TL_BleLldTable; +PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_SysTable_t TL_SysTable; +PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_MemManagerTable_t TL_MemManagerTable; +PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_TracesTable_t TL_TracesTable; +#if 0 +PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_Mac_802_15_4_t TL_Mac_802_15_4_Table; +PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_ZigbeeTable_t TL_Zigbee_Table; +#endif + +/**< tables */ +PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode FreeBufQueue; +PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode TracesEvtQueue; +PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static uint8_t CsBuffer[sizeof(TL_PacketHeader_t) + TL_EVT_HDR_SIZE + sizeof(TL_CsEvt_t)]; +PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode EvtQueue; +PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode SystemEvtQueue; + + +static tListNode LocalFreeBufQueue; +static void (* BLE_IoBusEvtCallBackFunction) (TL_EvtPacket_t *phcievt); +static void (* BLE_IoBusAclDataTxAck) ( void ); +static void (* SYS_CMD_IoBusCallBackFunction) (TL_EvtPacket_t *phcievt); +static void (* SYS_EVT_IoBusCallBackFunction) (TL_EvtPacket_t *phcievt); + + +/* Global variables ----------------------------------------------------------*/ +/* Private function prototypes -----------------------------------------------*/ +static void SendFreeBuf( void ); +static void OutputDbgTrace(TL_MB_PacketType_t packet_type, uint8_t* buffer); + +/* Public Functions Definition ------------------------------------------------------*/ + +/****************************************************************************** + * GENERAL - refer to AN5289 for functions description. + ******************************************************************************/ +void TL_Enable( void ) +{ + HW_IPCC_Enable(); + + return; +} + + +void TL_Init( void ) +{ + TL_RefTable.p_device_info_table = &TL_DeviceInfoTable; + TL_RefTable.p_ble_table = &TL_BleTable; + TL_RefTable.p_thread_table = &TL_ThreadTable; + TL_RefTable.p_lld_tests_table = &TL_LldTestsTable; + TL_RefTable.p_ble_lld_table = &TL_BleLldTable; + TL_RefTable.p_sys_table = &TL_SysTable; + TL_RefTable.p_mem_manager_table = &TL_MemManagerTable; + TL_RefTable.p_traces_table = &TL_TracesTable; +#if 0 + TL_RefTable.p_mac_802_15_4_table = &TL_Mac_802_15_4_Table; + TL_RefTable.p_zigbee_table = &TL_Zigbee_Table; +#endif + HW_IPCC_Init(); + + return; +} + +/****************************************************************************** + * BLE + ******************************************************************************/ +int32_t TL_BLE_Init( void* pConf ) +{ + MB_BleTable_t * p_bletable; + + TL_BLE_InitConf_t *pInitHciConf = (TL_BLE_InitConf_t *) pConf; + + LST_init_head (&EvtQueue); + + p_bletable = TL_RefTable.p_ble_table; + + p_bletable->pcmd_buffer = pInitHciConf->p_cmdbuffer; + p_bletable->phci_acl_data_buffer = pInitHciConf->p_AclDataBuffer; + p_bletable->pcs_buffer = (uint8_t*)CsBuffer; + p_bletable->pevt_queue = (uint8_t*)&EvtQueue; + + HW_IPCC_BLE_Init(); + + BLE_IoBusEvtCallBackFunction = pInitHciConf->IoBusEvtCallBack; + BLE_IoBusAclDataTxAck = pInitHciConf->IoBusAclDataTxAck; + + return 0; +} + +int32_t TL_BLE_SendCmd( uint8_t* buffer, uint16_t size ) +{ + (void)(buffer); + (void)(size); + + ((TL_CmdPacket_t*)(TL_RefTable.p_ble_table->pcmd_buffer))->cmdserial.type = TL_BLECMD_PKT_TYPE; + + OutputDbgTrace(TL_MB_BLE_CMD, TL_RefTable.p_ble_table->pcmd_buffer); + + HW_IPCC_BLE_SendCmd(); + + return 0; +} + +void HW_IPCC_BLE_RxEvtNot(void) +{ + TL_EvtPacket_t *phcievt; + + while(LST_is_empty(&EvtQueue) == FALSE) + { + LST_remove_head (&EvtQueue, (tListNode **)&phcievt); + + if ( ((phcievt->evtserial.evt.evtcode) == TL_BLEEVT_CS_OPCODE) || ((phcievt->evtserial.evt.evtcode) == TL_BLEEVT_CC_OPCODE ) ) + { + OutputDbgTrace(TL_MB_BLE_CMD_RSP, (uint8_t*)phcievt); + } + else + { + OutputDbgTrace(TL_MB_BLE_ASYNCH_EVT, (uint8_t*)phcievt); + } + + BLE_IoBusEvtCallBackFunction(phcievt); + } + + return; +} + +int32_t TL_BLE_SendAclData( uint8_t* buffer, uint16_t size ) +{ + (void)(buffer); + (void)(size); + + ((TL_AclDataPacket_t *)(TL_RefTable.p_ble_table->phci_acl_data_buffer))->AclDataSerial.type = TL_ACL_DATA_PKT_TYPE; + + HW_IPCC_BLE_SendAclData(); + + return 0; +} + +void HW_IPCC_BLE_AclDataAckNot(void) +{ + BLE_IoBusAclDataTxAck( ); + + return; +} + +/****************************************************************************** + * SYSTEM + ******************************************************************************/ +int32_t TL_SYS_Init( void* pConf ) +{ + MB_SysTable_t * p_systable; + + TL_SYS_InitConf_t *pInitHciConf = (TL_SYS_InitConf_t *) pConf; + + LST_init_head (&SystemEvtQueue); + p_systable = TL_RefTable.p_sys_table; + p_systable->pcmd_buffer = pInitHciConf->p_cmdbuffer; + p_systable->sys_queue = (uint8_t*)&SystemEvtQueue; + + HW_IPCC_SYS_Init(); + + SYS_CMD_IoBusCallBackFunction = pInitHciConf->IoBusCallBackCmdEvt; + SYS_EVT_IoBusCallBackFunction = pInitHciConf->IoBusCallBackUserEvt; + + return 0; +} + +int32_t TL_SYS_SendCmd( uint8_t* buffer, uint16_t size ) +{ + (void)(buffer); + (void)(size); + + ((TL_CmdPacket_t *)(TL_RefTable.p_sys_table->pcmd_buffer))->cmdserial.type = TL_SYSCMD_PKT_TYPE; + + OutputDbgTrace(TL_MB_SYS_CMD, TL_RefTable.p_sys_table->pcmd_buffer); + + HW_IPCC_SYS_SendCmd(); + + return 0; +} + +void HW_IPCC_SYS_CmdEvtNot(void) +{ + OutputDbgTrace(TL_MB_SYS_CMD_RSP, (uint8_t*)(TL_RefTable.p_sys_table->pcmd_buffer) ); + + SYS_CMD_IoBusCallBackFunction( (TL_EvtPacket_t*)(TL_RefTable.p_sys_table->pcmd_buffer) ); + + return; +} + +void HW_IPCC_SYS_EvtNot( void ) +{ + TL_EvtPacket_t *p_evt; + + while(LST_is_empty(&SystemEvtQueue) == FALSE) + { + LST_remove_head (&SystemEvtQueue, (tListNode **)&p_evt); + + OutputDbgTrace(TL_MB_SYS_ASYNCH_EVT, (uint8_t*)p_evt ); + + SYS_EVT_IoBusCallBackFunction( p_evt ); + } + + return; +} + +/****************************************************************************** + * THREAD + ******************************************************************************/ +#ifdef THREAD_WB +void TL_THREAD_Init( TL_TH_Config_t *p_Config ) +{ + MB_ThreadTable_t * p_thread_table; + + p_thread_table = TL_RefTable.p_thread_table; + + p_thread_table->clicmdrsp_buffer = p_Config->p_ThreadCliRspBuffer; + p_thread_table->otcmdrsp_buffer = p_Config->p_ThreadOtCmdRspBuffer; + p_thread_table->notack_buffer = p_Config->p_ThreadNotAckBuffer; + p_thread_table->clinot_buffer = p_Config->p_ThreadCliNotBuffer; + + HW_IPCC_THREAD_Init(); + + return; +} + +void TL_OT_SendCmd( void ) +{ + ((TL_CmdPacket_t *)(TL_RefTable.p_thread_table->otcmdrsp_buffer))->cmdserial.type = TL_OTCMD_PKT_TYPE; + + HW_IPCC_OT_SendCmd(); + + return; +} + +void TL_CLI_SendCmd( void ) +{ + ((TL_CmdPacket_t *)(TL_RefTable.p_thread_table->clicmdrsp_buffer))->cmdserial.type = TL_CLICMD_PKT_TYPE; + + HW_IPCC_CLI_SendCmd(); + + return; +} + +void TL_THREAD_SendAck ( void ) +{ + ((TL_CmdPacket_t *)(TL_RefTable.p_thread_table->notack_buffer))->cmdserial.type = TL_OTACK_PKT_TYPE; + + HW_IPCC_THREAD_SendAck(); + + return; +} + +void TL_THREAD_CliSendAck ( void ) +{ + ((TL_CmdPacket_t *)(TL_RefTable.p_thread_table->notack_buffer))->cmdserial.type = TL_OTACK_PKT_TYPE; + + HW_IPCC_THREAD_CliSendAck(); + + return; +} + +void HW_IPCC_OT_CmdEvtNot(void) +{ + TL_OT_CmdEvtReceived( (TL_EvtPacket_t*)(TL_RefTable.p_thread_table->otcmdrsp_buffer) ); + + return; +} + +void HW_IPCC_THREAD_EvtNot( void ) +{ + TL_THREAD_NotReceived( (TL_EvtPacket_t*)(TL_RefTable.p_thread_table->notack_buffer) ); + + return; +} + +void HW_IPCC_THREAD_CliEvtNot( void ) +{ + TL_THREAD_CliNotReceived( (TL_EvtPacket_t*)(TL_RefTable.p_thread_table->clinot_buffer) ); + + return; +} + +__WEAK void TL_OT_CmdEvtReceived( TL_EvtPacket_t * Otbuffer ){}; +__WEAK void TL_THREAD_NotReceived( TL_EvtPacket_t * Notbuffer ){}; +__WEAK void TL_THREAD_CliNotReceived( TL_EvtPacket_t * Notbuffer ){}; + +#endif /* THREAD_WB */ + +/****************************************************************************** + * LLD TESTS + ******************************************************************************/ +#ifdef LLD_TESTS_WB +void TL_LLDTESTS_Init( TL_LLD_tests_Config_t *p_Config ) +{ + MB_LldTestsTable_t * p_lld_tests_table; + + p_lld_tests_table = TL_RefTable.p_lld_tests_table; + p_lld_tests_table->clicmdrsp_buffer = p_Config->p_LldTestsCliCmdRspBuffer; + p_lld_tests_table->m0cmd_buffer = p_Config->p_LldTestsM0CmdBuffer; + HW_IPCC_LLDTESTS_Init(); + return; +} + +void TL_LLDTESTS_SendCliCmd( void ) +{ + ((TL_CmdPacket_t *)(TL_RefTable.p_lld_tests_table->clicmdrsp_buffer))->cmdserial.type = TL_CLICMD_PKT_TYPE; + HW_IPCC_LLDTESTS_SendCliCmd(); + return; +} + +void HW_IPCC_LLDTESTS_ReceiveCliRsp( void ) +{ + TL_LLDTESTS_ReceiveCliRsp( (TL_CmdPacket_t*)(TL_RefTable.p_lld_tests_table->clicmdrsp_buffer) ); + return; +} + +void TL_LLDTESTS_SendCliRspAck( void ) +{ + HW_IPCC_LLDTESTS_SendCliRspAck(); + return; +} + +void HW_IPCC_LLDTESTS_ReceiveM0Cmd( void ) +{ + TL_LLDTESTS_ReceiveM0Cmd( (TL_CmdPacket_t*)(TL_RefTable.p_lld_tests_table->m0cmd_buffer) ); + return; +} + + +void TL_LLDTESTS_SendM0CmdAck( void ) +{ + HW_IPCC_LLDTESTS_SendM0CmdAck(); + return; +} + +__WEAK void TL_LLDTESTS_ReceiveCliRsp( TL_CmdPacket_t * Notbuffer ){}; +__WEAK void TL_LLDTESTS_ReceiveM0Cmd( TL_CmdPacket_t * Notbuffer ){}; +#endif /* LLD_TESTS_WB */ + +/****************************************************************************** + * BLE LLD + ******************************************************************************/ +#ifdef BLE_LLD_WB +void TL_BLE_LLD_Init( TL_BLE_LLD_Config_t *p_Config ) +{ + MB_BleLldTable_t * p_ble_lld_table; + + p_ble_lld_table = TL_RefTable.p_ble_lld_table; + p_ble_lld_table->cmdrsp_buffer = p_Config->p_BleLldCmdRspBuffer; + p_ble_lld_table->m0cmd_buffer = p_Config->p_BleLldM0CmdBuffer; + HW_IPCC_BLE_LLD_Init(); + return; +} + +void TL_BLE_LLD_SendCliCmd( void ) +{ + ((TL_CmdPacket_t *)(TL_RefTable.p_ble_lld_table->cmdrsp_buffer))->cmdserial.type = TL_CLICMD_PKT_TYPE; + HW_IPCC_BLE_LLD_SendCliCmd(); + return; +} + +void HW_IPCC_BLE_LLD_ReceiveCliRsp( void ) +{ + TL_BLE_LLD_ReceiveCliRsp( (TL_CmdPacket_t*)(TL_RefTable.p_ble_lld_table->cmdrsp_buffer) ); + return; +} + +void TL_BLE_LLD_SendCliRspAck( void ) +{ + HW_IPCC_BLE_LLD_SendCliRspAck(); + return; +} + +void HW_IPCC_BLE_LLD_ReceiveM0Cmd( void ) +{ + TL_BLE_LLD_ReceiveM0Cmd( (TL_CmdPacket_t*)(TL_RefTable.p_ble_lld_table->m0cmd_buffer) ); + return; +} + + +void TL_BLE_LLD_SendM0CmdAck( void ) +{ + HW_IPCC_BLE_LLD_SendM0CmdAck(); + return; +} + +__WEAK void TL_BLE_LLD_ReceiveCliRsp( TL_CmdPacket_t * Notbuffer ){}; +__WEAK void TL_BLE_LLD_ReceiveM0Cmd( TL_CmdPacket_t * Notbuffer ){}; + +/* Transparent Mode */ +void TL_BLE_LLD_SendCmd( void ) +{ + ((TL_CmdPacket_t *)(TL_RefTable.p_ble_lld_table->cmdrsp_buffer))->cmdserial.type = TL_CLICMD_PKT_TYPE; + HW_IPCC_BLE_LLD_SendCmd(); + return; +} + +void HW_IPCC_BLE_LLD_ReceiveRsp( void ) +{ + TL_BLE_LLD_ReceiveRsp( (TL_CmdPacket_t*)(TL_RefTable.p_ble_lld_table->cmdrsp_buffer) ); + return; +} + +void TL_BLE_LLD_SendRspAck( void ) +{ + HW_IPCC_BLE_LLD_SendRspAck(); + return; +} +#endif /* BLE_LLD_WB */ + +#ifdef MAC_802_15_4_WB +/****************************************************************************** + * MAC 802.15.4 + ******************************************************************************/ +void TL_MAC_802_15_4_Init( TL_MAC_802_15_4_Config_t *p_Config ) +{ + MB_Mac_802_15_4_t * p_mac_802_15_4_table; + + p_mac_802_15_4_table = TL_RefTable.p_mac_802_15_4_table; + + p_mac_802_15_4_table->p_cmdrsp_buffer = p_Config->p_Mac_802_15_4_CmdRspBuffer; + p_mac_802_15_4_table->p_notack_buffer = p_Config->p_Mac_802_15_4_NotAckBuffer; + + HW_IPCC_MAC_802_15_4_Init(); + + return; +} + +void TL_MAC_802_15_4_SendCmd( void ) +{ + ((TL_CmdPacket_t *)(TL_RefTable.p_mac_802_15_4_table->p_cmdrsp_buffer))->cmdserial.type = TL_OTCMD_PKT_TYPE; + + HW_IPCC_MAC_802_15_4_SendCmd(); + + return; +} + +void TL_MAC_802_15_4_SendAck ( void ) +{ + ((TL_CmdPacket_t *)(TL_RefTable.p_mac_802_15_4_table->p_notack_buffer))->cmdserial.type = TL_OTACK_PKT_TYPE; + + HW_IPCC_MAC_802_15_4_SendAck(); + + return; +} + +void HW_IPCC_MAC_802_15_4_CmdEvtNot(void) +{ + TL_MAC_802_15_4_CmdEvtReceived( (TL_EvtPacket_t*)(TL_RefTable.p_mac_802_15_4_table->p_cmdrsp_buffer) ); + + return; +} + +void HW_IPCC_MAC_802_15_4_EvtNot( void ) +{ + TL_MAC_802_15_4_NotReceived( (TL_EvtPacket_t*)(TL_RefTable.p_mac_802_15_4_table->p_notack_buffer) ); + + return; +} + +__WEAK void TL_MAC_802_15_4_CmdEvtReceived( TL_EvtPacket_t * Otbuffer ){}; +__WEAK void TL_MAC_802_15_4_NotReceived( TL_EvtPacket_t * Notbuffer ){}; +#endif + +#ifdef ZIGBEE_WB +/****************************************************************************** + * ZIGBEE + ******************************************************************************/ +void TL_ZIGBEE_Init( TL_ZIGBEE_Config_t *p_Config ) +{ + MB_ZigbeeTable_t * p_zigbee_table; + + p_zigbee_table = TL_RefTable.p_zigbee_table; + p_zigbee_table->appliCmdM4toM0_buffer = p_Config->p_ZigbeeOtCmdRspBuffer; + p_zigbee_table->notifM0toM4_buffer = p_Config->p_ZigbeeNotAckBuffer; + p_zigbee_table->requestM0toM4_buffer = p_Config->p_ZigbeeNotifRequestBuffer; + + HW_IPCC_ZIGBEE_Init(); + + return; +} + +/* Zigbee M4 to M0 Request */ +void TL_ZIGBEE_SendM4RequestToM0( void ) +{ + ((TL_CmdPacket_t *)(TL_RefTable.p_zigbee_table->appliCmdM4toM0_buffer))->cmdserial.type = TL_OTCMD_PKT_TYPE; + + HW_IPCC_ZIGBEE_SendM4RequestToM0(); + + return; +} + +/* Used to receive an ACK from the M0 */ +void HW_IPCC_ZIGBEE_RecvAppliAckFromM0(void) +{ + TL_ZIGBEE_CmdEvtReceived( (TL_EvtPacket_t*)(TL_RefTable.p_zigbee_table->appliCmdM4toM0_buffer) ); + + return; +} + +/* Zigbee notification from M0 to M4 */ +void HW_IPCC_ZIGBEE_RecvM0NotifyToM4( void ) +{ + TL_ZIGBEE_NotReceived( (TL_EvtPacket_t*)(TL_RefTable.p_zigbee_table->notifM0toM4_buffer) ); + + return; +} + +/* Send an ACK to the M0 for a Notification */ +void TL_ZIGBEE_SendM4AckToM0Notify ( void ) +{ + ((TL_CmdPacket_t *)(TL_RefTable.p_zigbee_table->notifM0toM4_buffer))->cmdserial.type = TL_OTACK_PKT_TYPE; + + HW_IPCC_ZIGBEE_SendM4AckToM0Notify(); + + return; +} + +/* Zigbee M0 to M4 Request */ +void HW_IPCC_ZIGBEE_RecvM0RequestToM4( void ) +{ + TL_ZIGBEE_M0RequestReceived( (TL_EvtPacket_t*)(TL_RefTable.p_zigbee_table->requestM0toM4_buffer) ); + + return; +} + +/* Send an ACK to the M0 for a Request */ +void TL_ZIGBEE_SendM4AckToM0Request(void) +{ + ((TL_CmdPacket_t *)(TL_RefTable.p_zigbee_table->requestM0toM4_buffer))->cmdserial.type = TL_OTACK_PKT_TYPE; + + HW_IPCC_ZIGBEE_SendM4AckToM0Request(); + + return; +} + + +__WEAK void TL_ZIGBEE_CmdEvtReceived( TL_EvtPacket_t * Otbuffer ){}; +__WEAK void TL_ZIGBEE_NotReceived( TL_EvtPacket_t * Notbuffer ){}; +#endif + + + +/****************************************************************************** + * MEMORY MANAGER + ******************************************************************************/ +void TL_MM_Init( TL_MM_Config_t *p_Config ) +{ + static MB_MemManagerTable_t * p_mem_manager_table; + + LST_init_head (&FreeBufQueue); + LST_init_head (&LocalFreeBufQueue); + + p_mem_manager_table = TL_RefTable.p_mem_manager_table; + + p_mem_manager_table->blepool = p_Config->p_AsynchEvtPool; + p_mem_manager_table->blepoolsize = p_Config->AsynchEvtPoolSize; + p_mem_manager_table->pevt_free_buffer_queue = (uint8_t*)&FreeBufQueue; + p_mem_manager_table->spare_ble_buffer = p_Config->p_BleSpareEvtBuffer; + p_mem_manager_table->spare_sys_buffer = p_Config->p_SystemSpareEvtBuffer; + p_mem_manager_table->traces_evt_pool = p_Config->p_TracesEvtPool; + p_mem_manager_table->tracespoolsize = p_Config->TracesEvtPoolSize; + + return; +} + +void TL_MM_EvtDone(TL_EvtPacket_t * phcievt) +{ + LST_insert_tail(&LocalFreeBufQueue, (tListNode *)phcievt); + + OutputDbgTrace(TL_MB_MM_RELEASE_BUFFER, (uint8_t*)phcievt); + + HW_IPCC_MM_SendFreeBuf( SendFreeBuf ); + + return; +} + +static void SendFreeBuf( void ) +{ + tListNode *p_node; + + while ( FALSE == LST_is_empty (&LocalFreeBufQueue) ) + { + LST_remove_head( &LocalFreeBufQueue, (tListNode **)&p_node ); + LST_insert_tail( (tListNode*)(TL_RefTable.p_mem_manager_table->pevt_free_buffer_queue), p_node ); + } + + return; +} + +/****************************************************************************** + * TRACES + ******************************************************************************/ +void TL_TRACES_Init( void ) +{ + LST_init_head (&TracesEvtQueue); + + TL_RefTable.p_traces_table->traces_queue = (uint8_t*)&TracesEvtQueue; + + HW_IPCC_TRACES_Init(); + + return; +} + +void HW_IPCC_TRACES_EvtNot(void) +{ + TL_EvtPacket_t *phcievt; + + while(LST_is_empty(&TracesEvtQueue) == FALSE) + { + LST_remove_head (&TracesEvtQueue, (tListNode **)&phcievt); + TL_TRACES_EvtReceived( phcievt ); + } + + return; +} + +__WEAK void TL_TRACES_EvtReceived( TL_EvtPacket_t * hcievt ) +{ + (void)(hcievt); +} + +/****************************************************************************** + * DEBUG INFORMATION + ******************************************************************************/ +static void OutputDbgTrace(TL_MB_PacketType_t packet_type, uint8_t* buffer) +{ + TL_EvtPacket_t *p_evt_packet; + TL_CmdPacket_t *p_cmd_packet; + TL_EvtSerial_t *p_cmd_rsp_packet; + + switch(packet_type) + { + case TL_MB_MM_RELEASE_BUFFER: + p_evt_packet = (TL_EvtPacket_t*)buffer; + switch(p_evt_packet->evtserial.evt.evtcode) + { + case TL_BLEEVT_CS_OPCODE: + TL_MM_DBG_MSG("mm evt released: 0x%02X", p_evt_packet->evtserial.evt.evtcode); + TL_MM_DBG_MSG(" cmd opcode: 0x%04X", ((TL_CsEvt_t*)(p_evt_packet->evtserial.evt.payload))->cmdcode); + TL_MM_DBG_MSG(" buffer addr: 0x%08X", p_evt_packet); + break; + + case TL_BLEEVT_CC_OPCODE: + TL_MM_DBG_MSG("mm evt released: 0x%02X", p_evt_packet->evtserial.evt.evtcode); + TL_MM_DBG_MSG(" cmd opcode: 0x%04X", ((TL_CcEvt_t*)(p_evt_packet->evtserial.evt.payload))->cmdcode); + TL_MM_DBG_MSG(" buffer addr: 0x%08X", p_evt_packet); + break; + + case TL_BLEEVT_VS_OPCODE: + TL_MM_DBG_MSG("mm evt released: 0x%02X", p_evt_packet->evtserial.evt.evtcode); + TL_MM_DBG_MSG(" subevtcode: 0x%04X", ((TL_AsynchEvt_t*)(p_evt_packet->evtserial.evt.payload))->subevtcode); + TL_MM_DBG_MSG(" buffer addr: 0x%08X", p_evt_packet); + break; + + default: + TL_MM_DBG_MSG("mm evt released: 0x%02X", p_evt_packet->evtserial.evt.evtcode); + TL_MM_DBG_MSG(" buffer addr: 0x%08X", p_evt_packet); + break; + } + + TL_MM_DBG_MSG("\r\n"); + break; + + case TL_MB_BLE_CMD: + p_cmd_packet = (TL_CmdPacket_t*)buffer; + TL_HCI_CMD_DBG_MSG("ble cmd: 0x%04X", p_cmd_packet->cmdserial.cmd.cmdcode); + if(p_cmd_packet->cmdserial.cmd.plen != 0) + { + TL_HCI_CMD_DBG_MSG(" payload:"); + TL_HCI_CMD_DBG_BUF(p_cmd_packet->cmdserial.cmd.payload, p_cmd_packet->cmdserial.cmd.plen, ""); + } + TL_HCI_CMD_DBG_MSG("\r\n"); + + TL_HCI_CMD_DBG_RAW(&p_cmd_packet->cmdserial, p_cmd_packet->cmdserial.cmd.plen+TL_CMD_HDR_SIZE); + break; + + case TL_MB_BLE_CMD_RSP: + p_evt_packet = (TL_EvtPacket_t*)buffer; + switch(p_evt_packet->evtserial.evt.evtcode) + { + case TL_BLEEVT_CS_OPCODE: + TL_HCI_CMD_DBG_MSG("ble rsp: 0x%02X", p_evt_packet->evtserial.evt.evtcode); + TL_HCI_CMD_DBG_MSG(" cmd opcode: 0x%04X", ((TL_CsEvt_t*)(p_evt_packet->evtserial.evt.payload))->cmdcode); + TL_HCI_CMD_DBG_MSG(" numhci: 0x%02X", ((TL_CsEvt_t*)(p_evt_packet->evtserial.evt.payload))->numcmd); + TL_HCI_CMD_DBG_MSG(" status: 0x%02X", ((TL_CsEvt_t*)(p_evt_packet->evtserial.evt.payload))->status); + break; + + case TL_BLEEVT_CC_OPCODE: + TL_HCI_CMD_DBG_MSG("ble rsp: 0x%02X", p_evt_packet->evtserial.evt.evtcode); + TL_HCI_CMD_DBG_MSG(" cmd opcode: 0x%04X", ((TL_CcEvt_t*)(p_evt_packet->evtserial.evt.payload))->cmdcode); + TL_HCI_CMD_DBG_MSG(" numhci: 0x%02X", ((TL_CcEvt_t*)(p_evt_packet->evtserial.evt.payload))->numcmd); + TL_HCI_CMD_DBG_MSG(" status: 0x%02X", ((TL_CcEvt_t*)(p_evt_packet->evtserial.evt.payload))->payload[0]); + if((p_evt_packet->evtserial.evt.plen-4) != 0) + { + TL_HCI_CMD_DBG_MSG(" payload:"); + TL_HCI_CMD_DBG_BUF(&((TL_CcEvt_t*)(p_evt_packet->evtserial.evt.payload))->payload[1], p_evt_packet->evtserial.evt.plen-4, ""); + } + break; + + default: + TL_HCI_CMD_DBG_MSG("unknown ble rsp received: %02X", p_evt_packet->evtserial.evt.evtcode); + break; + } + + TL_HCI_CMD_DBG_MSG("\r\n"); + + TL_HCI_CMD_DBG_RAW(&p_evt_packet->evtserial, p_evt_packet->evtserial.evt.plen+TL_EVT_HDR_SIZE); + break; + + case TL_MB_BLE_ASYNCH_EVT: + p_evt_packet = (TL_EvtPacket_t*)buffer; + if(p_evt_packet->evtserial.evt.evtcode != TL_BLEEVT_VS_OPCODE) + { + TL_HCI_EVT_DBG_MSG("ble evt: 0x%02X", p_evt_packet->evtserial.evt.evtcode); + if((p_evt_packet->evtserial.evt.plen) != 0) + { + TL_HCI_EVT_DBG_MSG(" payload:"); + TL_HCI_EVT_DBG_BUF(p_evt_packet->evtserial.evt.payload, p_evt_packet->evtserial.evt.plen, ""); + } + } + else + { + TL_HCI_EVT_DBG_MSG("ble evt: 0x%02X", p_evt_packet->evtserial.evt.evtcode); + TL_HCI_EVT_DBG_MSG(" subevtcode: 0x%04X", ((TL_AsynchEvt_t*)(p_evt_packet->evtserial.evt.payload))->subevtcode); + if((p_evt_packet->evtserial.evt.plen-2) != 0) + { + TL_HCI_EVT_DBG_MSG(" payload:"); + TL_HCI_EVT_DBG_BUF(((TL_AsynchEvt_t*)(p_evt_packet->evtserial.evt.payload))->payload, p_evt_packet->evtserial.evt.plen-2, ""); + } + } + + TL_HCI_EVT_DBG_MSG("\r\n"); + + TL_HCI_EVT_DBG_RAW(&p_evt_packet->evtserial, p_evt_packet->evtserial.evt.plen+TL_EVT_HDR_SIZE); + break; + + case TL_MB_SYS_CMD: + p_cmd_packet = (TL_CmdPacket_t*)buffer; + + TL_SHCI_CMD_DBG_MSG("sys cmd: 0x%04X", p_cmd_packet->cmdserial.cmd.cmdcode); + + if(p_cmd_packet->cmdserial.cmd.plen != 0) + { + TL_SHCI_CMD_DBG_MSG(" payload:"); + TL_SHCI_CMD_DBG_BUF(p_cmd_packet->cmdserial.cmd.payload, p_cmd_packet->cmdserial.cmd.plen, ""); + } + TL_SHCI_CMD_DBG_MSG("\r\n"); + + TL_SHCI_CMD_DBG_RAW(&p_cmd_packet->cmdserial, p_cmd_packet->cmdserial.cmd.plen+TL_CMD_HDR_SIZE); + break; + + case TL_MB_SYS_CMD_RSP: + p_cmd_rsp_packet = (TL_EvtSerial_t*)buffer; + switch(p_cmd_rsp_packet->evt.evtcode) + { + case TL_BLEEVT_CC_OPCODE: + TL_SHCI_CMD_DBG_MSG("sys rsp: 0x%02X", p_cmd_rsp_packet->evt.evtcode); + TL_SHCI_CMD_DBG_MSG(" cmd opcode: 0x%02X", ((TL_CcEvt_t*)(p_cmd_rsp_packet->evt.payload))->cmdcode); + TL_SHCI_CMD_DBG_MSG(" status: 0x%02X", ((TL_CcEvt_t*)(p_cmd_rsp_packet->evt.payload))->payload[0]); + if((p_cmd_rsp_packet->evt.plen-4) != 0) + { + TL_SHCI_CMD_DBG_MSG(" payload:"); + TL_SHCI_CMD_DBG_BUF(&((TL_CcEvt_t*)(p_cmd_rsp_packet->evt.payload))->payload[1], p_cmd_rsp_packet->evt.plen-4, ""); + } + break; + + default: + TL_SHCI_CMD_DBG_MSG("unknown sys rsp received: %02X", p_cmd_rsp_packet->evt.evtcode); + break; + } + + TL_SHCI_CMD_DBG_MSG("\r\n"); + + TL_SHCI_CMD_DBG_RAW(&p_cmd_rsp_packet->evt, p_cmd_rsp_packet->evt.plen+TL_EVT_HDR_SIZE); + break; + + case TL_MB_SYS_ASYNCH_EVT: + p_evt_packet = (TL_EvtPacket_t*)buffer; + if(p_evt_packet->evtserial.evt.evtcode != TL_BLEEVT_VS_OPCODE) + { + TL_SHCI_EVT_DBG_MSG("unknown sys evt received: %02X", p_evt_packet->evtserial.evt.evtcode); + } + else + { + TL_SHCI_EVT_DBG_MSG("sys evt: 0x%02X", p_evt_packet->evtserial.evt.evtcode); + TL_SHCI_EVT_DBG_MSG(" subevtcode: 0x%04X", ((TL_AsynchEvt_t*)(p_evt_packet->evtserial.evt.payload))->subevtcode); + if((p_evt_packet->evtserial.evt.plen-2) != 0) + { + TL_SHCI_EVT_DBG_MSG(" payload:"); + TL_SHCI_EVT_DBG_BUF(((TL_AsynchEvt_t*)(p_evt_packet->evtserial.evt.payload))->payload, p_evt_packet->evtserial.evt.plen-2, ""); + } + } + + TL_SHCI_EVT_DBG_MSG("\r\n"); + + TL_SHCI_EVT_DBG_RAW(&p_evt_packet->evtserial, p_evt_packet->evtserial.evt.plen+TL_EVT_HDR_SIZE); + break; + + default: + break; + } + + return; +} +#endif /* STM32WBxx */ diff --git a/src/utility/STM32_WPAN/utilities_conf.h b/src/utility/STM32_WPAN/utilities_conf.h new file mode 100644 index 00000000..d6221a73 --- /dev/null +++ b/src/utility/STM32_WPAN/utilities_conf.h @@ -0,0 +1,66 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file utilities_conf.h + * @author MCD Application Team + * @brief Configuration file for STM32 Utilities. + ****************************************************************************** + * @attention + * + * Copyright (c) 2019-2021 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef UTILITIES_CONF_H +#define UTILITIES_CONF_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "cmsis_compiler.h" +#include "string.h" +#include "app_conf.h" + +/****************************************************************************** + * common + ******************************************************************************/ +#define UTILS_ENTER_CRITICAL_SECTION( ) uint32_t primask_bit = __get_PRIMASK( );\ + __disable_irq( ) + +#define UTILS_EXIT_CRITICAL_SECTION( ) __set_PRIMASK( primask_bit ) + +#define UTILS_MEMSET8( dest, value, size ) memset( dest, value, size); + +/****************************************************************************** + * tiny low power manager + * (any macro that does not need to be modified can be removed) + ******************************************************************************/ +#define UTIL_LPM_INIT_CRITICAL_SECTION( ) +#define UTIL_LPM_ENTER_CRITICAL_SECTION( ) UTILS_ENTER_CRITICAL_SECTION( ) +#define UTIL_LPM_EXIT_CRITICAL_SECTION( ) UTILS_EXIT_CRITICAL_SECTION( ) + +/****************************************************************************** + * sequencer + * (any macro that does not need to be modified can be removed) + ******************************************************************************/ +#define UTIL_SEQ_INIT_CRITICAL_SECTION( ) +#define UTIL_SEQ_ENTER_CRITICAL_SECTION( ) UTILS_ENTER_CRITICAL_SECTION( ) +#define UTIL_SEQ_EXIT_CRITICAL_SECTION( ) UTILS_EXIT_CRITICAL_SECTION( ) +#define UTIL_SEQ_CONF_TASK_NBR (32) +#define UTIL_SEQ_CONF_PRIO_NBR CFG_SCH_PRIO_NBR +#define UTIL_SEQ_MEMSET8( dest, value, size ) UTILS_MEMSET8( dest, value, size ) + +#ifdef __cplusplus +} +#endif + +#endif /*UTILITIES_CONF_H */ From 71cd1d10ef484a6d01287ae9a7824a2adc128e7c Mon Sep 17 00:00:00 2001 From: Alexandre Bourdiol <alexandre.bourdiol@st.com> Date: Tue, 18 Mar 2025 09:42:32 +0100 Subject: [PATCH 212/226] feat: add patch files to be applied on stm32wb Cube update Signed-off-by: Alexandre Bourdiol <alexandre.bourdiol@st.com> --- .../0001-chore-adapt-STM32_WPAN-sources.patch | 310 ++++++++++++++++++ ...imeout-when-waiting-for-the-cmd_resp.patch | 41 +++ ...ort-for-customize-app_conf_default.h.patch | 135 ++++++++ ...-fix-TL_Evt_t-payload-size-for-reset.patch | 30 ++ 4 files changed, 516 insertions(+) create mode 100644 extras/STM32_WPAN/0001-chore-adapt-STM32_WPAN-sources.patch create mode 100644 extras/STM32_WPAN/0002-fix-include-a-timeout-when-waiting-for-the-cmd_resp.patch create mode 100644 extras/STM32_WPAN/0003-chore-add-support-for-customize-app_conf_default.h.patch create mode 100644 extras/STM32_WPAN/0004-fix-TL_Evt_t-payload-size-for-reset.patch diff --git a/extras/STM32_WPAN/0001-chore-adapt-STM32_WPAN-sources.patch b/extras/STM32_WPAN/0001-chore-adapt-STM32_WPAN-sources.patch new file mode 100644 index 00000000..a3f62011 --- /dev/null +++ b/extras/STM32_WPAN/0001-chore-adapt-STM32_WPAN-sources.patch @@ -0,0 +1,310 @@ +From 7f99c89e8a6f834daf4a76bf98307e9ebcd01c91 Mon Sep 17 00:00:00 2001 +From: Frederic Pillon <frederic.pillon@st.com> +Date: Wed, 10 Jan 2024 18:16:01 +0100 +Subject: [PATCH 1/4] chore: adapt STM32_WPAN sources + +Signed-off-by: Frederic Pillon <frederic.pillon@st.com> +--- + src/utility/STM32_WPAN/app_conf_default.h | 49 +++++++++++++++++++---- + src/utility/STM32_WPAN/hw.h | 13 +++++- + src/utility/STM32_WPAN/hw_ipcc.c | 4 +- + src/utility/STM32_WPAN/shci.c | 2 + + src/utility/STM32_WPAN/shci_tl.c | 17 ++++++++ + src/utility/STM32_WPAN/stm_list.c | 6 ++- + src/utility/STM32_WPAN/tl_mbox.c | 6 +++ + 7 files changed, 85 insertions(+), 12 deletions(-) + +diff --git a/src/utility/STM32_WPAN/app_conf_default.h b/src/utility/STM32_WPAN/app_conf_default.h +index 71fc107..bf2274a 100644 +--- a/src/utility/STM32_WPAN/app_conf_default.h ++++ b/src/utility/STM32_WPAN/app_conf_default.h +@@ -1,9 +1,9 @@ + /* USER CODE BEGIN Header */ + /** + ****************************************************************************** +- * @file app_conf.h ++ * @file app_conf_default.h + * @author MCD Application Team +- * @brief Application configuration file for STM32WPAN Middleware. ++ * @brief Default application configuration file for STM32WPAN Middleware. + ****************************************************************************** + * @attention + * +@@ -19,18 +19,40 @@ + /* USER CODE END Header */ + + /* Define to prevent recursive inclusion -------------------------------------*/ +-#ifndef APP_CONF_H +-#define APP_CONF_H ++#ifndef APP_CONF_DEFAULT_H ++#define APP_CONF_DEFAULT_H + ++#if 0 + #include "hw.h" + #include "hw_conf.h" + #include "hw_if.h" + #include "ble_bufsize.h" ++#endif + + /****************************************************************************** + * Application Config + ******************************************************************************/ + ++/**< generic parameters ******************************************************/ ++/* HCI related defines */ ++ ++#define ACI_HAL_SET_TX_POWER_LEVEL 0xFC0F ++#define ACI_WRITE_CONFIG_DATA_OPCODE 0xFC0C ++#define ACI_READ_CONFIG_DATA_OPCODE 0xFC0D ++#define MAX_HCI_ACL_PACKET_SIZE (sizeof(TL_PacketHeader_t) + 5 + 251) ++#define HCI_RESET 0x0C03 ++ ++#ifndef BLE_SHARED_MEM_BYTE_ORDER ++ #define BLE_SHARED_MEM_BYTE_ORDER MSBFIRST ++#endif ++#define BLE_MODULE_SHARED_MEM_BUFFER_SIZE 128 ++ ++/** ++ * Define Tx Power ++ */ ++#define CFG_TX_POWER (0x18) /* -0.15dBm */ ++ ++#if 0 + /** + * Define Secure Connections Support + */ +@@ -104,6 +126,7 @@ + #define CFG_FW_SUBVERSION (1) + #define CFG_FW_BRANCH (0) + #define CFG_FW_BUILD (0) ++#endif + + /****************************************************************************** + * BLE Stack +@@ -250,7 +273,7 @@ + * 0: LE Power Class 2-3 + * other bits: complete with Options_extension flag + */ +-#define CFG_BLE_OPTIONS (SHCI_C2_BLE_INIT_OPTIONS_LL_HOST | SHCI_C2_BLE_INIT_OPTIONS_WITH_SVC_CHANGE_DESC | SHCI_C2_BLE_INIT_OPTIONS_DEVICE_NAME_RW | SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV | SHCI_C2_BLE_INIT_OPTIONS_CS_ALGO2 | SHCI_C2_BLE_INIT_OPTIONS_FULL_GATTDB_NVM | SHCI_C2_BLE_INIT_OPTIONS_GATT_CACHING_NOTUSED | SHCI_C2_BLE_INIT_OPTIONS_POWER_CLASS_2_3) ++#define CFG_BLE_OPTIONS (SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY | SHCI_C2_BLE_INIT_OPTIONS_WITH_SVC_CHANGE_DESC | SHCI_C2_BLE_INIT_OPTIONS_DEVICE_NAME_RW | SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV | SHCI_C2_BLE_INIT_OPTIONS_CS_ALGO2 | SHCI_C2_BLE_INIT_OPTIONS_FULL_GATTDB_NVM | SHCI_C2_BLE_INIT_OPTIONS_GATT_CACHING_NOTUSED | SHCI_C2_BLE_INIT_OPTIONS_POWER_CLASS_2_3) + + /** + * BLE stack Options_extension flags to be configured with: +@@ -292,7 +315,11 @@ + * This parameter is considered by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV flag set + */ + +-#define CFG_BLE_MAX_ADV_SET_NBR (8) ++#if defined(STM32WB15xx) ++ #define CFG_BLE_MAX_ADV_SET_NBR (3) ++#else ++ #define CFG_BLE_MAX_ADV_SET_NBR (8) ++#endif + + /* Maximum advertising data length (in bytes) + * Range: 31 .. 1650 with limitation: +@@ -301,7 +328,11 @@ + * This parameter is considered by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV flag set + */ + +-#define CFG_BLE_MAX_ADV_DATA_LEN (207) ++#if defined(STM32WB15xx) ++ #define CFG_BLE_MAX_ADV_DATA_LEN (414) ++#else ++ #define CFG_BLE_MAX_ADV_DATA_LEN (207) ++#endif + + /* RF TX Path Compensation Value (16-bit signed integer). Units: 0.1 dB. + * Range: -1280 .. 1280 +@@ -324,6 +355,7 @@ + + #define CFG_BLE_CORE_VERSION (SHCI_C2_BLE_INIT_BLE_CORE_5_4) + ++#if 0 + /****************************************************************************** + * Transport Layer + ******************************************************************************/ +@@ -660,4 +692,5 @@ typedef enum + + #define CFG_OTP_END_ADRESS OTP_AREA_END_ADDR + +-#endif /*APP_CONF_H */ ++#endif ++#endif /*APP_CONF_DEFAULT_H */ +diff --git a/src/utility/STM32_WPAN/hw.h b/src/utility/STM32_WPAN/hw.h +index 651e1f1..1472a5e 100644 +--- a/src/utility/STM32_WPAN/hw.h ++++ b/src/utility/STM32_WPAN/hw.h +@@ -26,14 +26,23 @@ extern "C" { + #endif + + /* Includes ------------------------------------------------------------------*/ ++#include "stm32_def.h" ++#include "stm32wbxx_ll_bus.h" ++#include "stm32wbxx_ll_exti.h" ++#include "stm32wbxx_ll_system.h" ++#include "stm32wbxx_ll_rcc.h" ++#include "stm32wbxx_ll_ipcc.h" ++#include "stm32wbxx_ll_cortex.h" ++#include "stm32wbxx_ll_utils.h" ++#include "stm32wbxx_ll_pwr.h" + + /****************************************************************************** + * HW IPCC + ******************************************************************************/ + void HW_IPCC_Enable( void ); + void HW_IPCC_Init( void ); +- void HW_IPCC_Rx_Handler( void ); +- void HW_IPCC_Tx_Handler( void ); ++#define HW_IPCC_Rx_Handler IPCC_C1_RX_IRQHandler ++#define HW_IPCC_Tx_Handler IPCC_C1_TX_IRQHandler + + void HW_IPCC_BLE_Init( void ); + void HW_IPCC_BLE_SendCmd( void ); +diff --git a/src/utility/STM32_WPAN/hw_ipcc.c b/src/utility/STM32_WPAN/hw_ipcc.c +index 6a311b1..ad3c9d4 100644 +--- a/src/utility/STM32_WPAN/hw_ipcc.c ++++ b/src/utility/STM32_WPAN/hw_ipcc.c +@@ -18,8 +18,9 @@ + */ + /* USER CODE END Header */ + ++#if defined(STM32WBxx) + /* Includes ------------------------------------------------------------------*/ +-#include "app_common.h" ++#include "hw.h" + #include "mbox_def.h" + #include "utilities_conf.h" + +@@ -745,3 +746,4 @@ static void HW_IPCC_TRACES_EvtHandler( void ) + } + + __weak void HW_IPCC_TRACES_EvtNot( void ){}; ++#endif /* STM32WBxx */ +diff --git a/src/utility/STM32_WPAN/shci.c b/src/utility/STM32_WPAN/shci.c +index 5c32555..40110f4 100644 +--- a/src/utility/STM32_WPAN/shci.c ++++ b/src/utility/STM32_WPAN/shci.c +@@ -17,6 +17,7 @@ + */ + + ++#if defined(STM32WBxx) + /* Includes ------------------------------------------------------------------*/ + #include "stm32_wpan_common.h" + +@@ -759,3 +760,4 @@ SHCI_CmdStatus_t SHCI_GetWirelessFwInfo( WirelessFwInfo_t* pWirelessInfo ) + + return (SHCI_Success); + } ++#endif /* STM32WBxx */ +diff --git a/src/utility/STM32_WPAN/shci_tl.c b/src/utility/STM32_WPAN/shci_tl.c +index 0f60430..daa988c 100644 +--- a/src/utility/STM32_WPAN/shci_tl.c ++++ b/src/utility/STM32_WPAN/shci_tl.c +@@ -17,11 +17,13 @@ + */ + + ++#if defined(STM32WBxx) + /* Includes ------------------------------------------------------------------*/ + #include "stm32_wpan_common.h" + + #include "stm_list.h" + #include "shci_tl.h" ++#include "stm32_def.h" + + /* Private typedef -----------------------------------------------------------*/ + typedef enum +@@ -168,6 +170,20 @@ void shci_send( uint16_t cmd_code, uint8_t len_cmd_payload, uint8_t * p_cmd_payl + return; + } + ++void shci_notify_asynch_evt(void *pdata) ++{ ++ UNUSED(pdata); ++ /* Need to parse data in future version */ ++ shci_user_evt_proc(); ++} ++ ++void shci_register_io_bus(tSHciIO *fops) ++{ ++ /* Register IO bus services */ ++ fops->Init = TL_SYS_Init; ++ fops->Send = TL_SYS_SendCmd; ++} ++ + /* Private functions ---------------------------------------------------------*/ + static void TlInit( TL_CmdPacket_t * p_cmdbuffer ) + { +@@ -250,3 +266,4 @@ __WEAK void shci_cmd_resp_release(uint32_t flag) + + return; + } ++#endif /* STM32WBxx */ +diff --git a/src/utility/STM32_WPAN/stm_list.c b/src/utility/STM32_WPAN/stm_list.c +index 4c92864..df6c215 100644 +--- a/src/utility/STM32_WPAN/stm_list.c ++++ b/src/utility/STM32_WPAN/stm_list.c +@@ -17,10 +17,13 @@ + */ + + ++#if defined(STM32WBxx) + /****************************************************************************** + * Include Files + ******************************************************************************/ +-#include "utilities_common.h" ++#include "stdint.h" ++#include "cmsis_gcc.h" ++#include "stm32_wpan_common.h" + + #include "stm_list.h" + +@@ -204,3 +207,4 @@ void LST_get_prev_node (tListNode * ref_node, tListNode ** node) + + __set_PRIMASK(primask_bit); /**< Restore PRIMASK bit*/ + } ++#endif /* STM32WBxx */ +diff --git a/src/utility/STM32_WPAN/tl_mbox.c b/src/utility/STM32_WPAN/tl_mbox.c +index df07a19..9a2a297 100644 +--- a/src/utility/STM32_WPAN/tl_mbox.c ++++ b/src/utility/STM32_WPAN/tl_mbox.c +@@ -16,6 +16,7 @@ + ****************************************************************************** + */ + ++#if defined(STM32WBxx) + /* Includes ------------------------------------------------------------------*/ + #include "stm32_wpan_common.h" + #include "hw.h" +@@ -51,8 +52,10 @@ PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_BleLldTable_t TL_BleLldTable; + PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_SysTable_t TL_SysTable; + PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_MemManagerTable_t TL_MemManagerTable; + PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_TracesTable_t TL_TracesTable; ++#if 0 + PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_Mac_802_15_4_t TL_Mac_802_15_4_Table; + PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_ZigbeeTable_t TL_Zigbee_Table; ++#endif + + /**< tables */ + PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode FreeBufQueue; +@@ -97,8 +100,10 @@ void TL_Init( void ) + TL_RefTable.p_sys_table = &TL_SysTable; + TL_RefTable.p_mem_manager_table = &TL_MemManagerTable; + TL_RefTable.p_traces_table = &TL_TracesTable; ++#if 0 + TL_RefTable.p_mac_802_15_4_table = &TL_Mac_802_15_4_Table; + TL_RefTable.p_zigbee_table = &TL_Zigbee_Table; ++#endif + HW_IPCC_Init(); + + return; +@@ -847,3 +852,4 @@ static void OutputDbgTrace(TL_MB_PacketType_t packet_type, uint8_t* buffer) + + return; + } ++#endif /* STM32WBxx */ +-- +2.34.1 + diff --git a/extras/STM32_WPAN/0002-fix-include-a-timeout-when-waiting-for-the-cmd_resp.patch b/extras/STM32_WPAN/0002-fix-include-a-timeout-when-waiting-for-the-cmd_resp.patch new file mode 100644 index 00000000..bd6f66a2 --- /dev/null +++ b/extras/STM32_WPAN/0002-fix-include-a-timeout-when-waiting-for-the-cmd_resp.patch @@ -0,0 +1,41 @@ +From a33328182e334e1ddedd368a047d75cf1662e330 Mon Sep 17 00:00:00 2001 +From: Frederic Pillon <frederic.pillon@st.com> +Date: Thu, 13 Jul 2023 17:16:40 +0200 +Subject: [PATCH 2/4] fix: include a timeout when waiting for the cmd_resp + +Signed-off-by: Frederic Pillon <frederic.pillon@st.com> +--- + src/utility/STM32_WPAN/shci_tl.c | 10 ++++++---- + 1 file changed, 6 insertions(+), 4 deletions(-) + +diff --git a/src/utility/STM32_WPAN/shci_tl.c b/src/utility/STM32_WPAN/shci_tl.c +index daa988c..25e1a21 100644 +--- a/src/utility/STM32_WPAN/shci_tl.c ++++ b/src/utility/STM32_WPAN/shci_tl.c +@@ -24,6 +24,7 @@ + #include "stm_list.h" + #include "shci_tl.h" + #include "stm32_def.h" ++#include "wiring_time.h" + + /* Private typedef -----------------------------------------------------------*/ + typedef enum +@@ -251,10 +252,11 @@ static void TlUserEvtReceived(TL_EvtPacket_t *shcievt) + /* Weak implementation ----------------------------------------------------------------*/ + __WEAK void shci_cmd_resp_wait(uint32_t timeout) + { +- (void)timeout; +- +- while(CmdRspStatusFlag != SHCI_TL_CMD_RESP_RELEASE); +- ++ for (unsigned long start = millis(); (millis() - start) < timeout;) { ++ if (CmdRspStatusFlag == SHCI_TL_CMD_RESP_RELEASE) { ++ break; ++ } ++ } + return; + } + +-- +2.34.1 + diff --git a/extras/STM32_WPAN/0003-chore-add-support-for-customize-app_conf_default.h.patch b/extras/STM32_WPAN/0003-chore-add-support-for-customize-app_conf_default.h.patch new file mode 100644 index 00000000..3c5e66ae --- /dev/null +++ b/extras/STM32_WPAN/0003-chore-add-support-for-customize-app_conf_default.h.patch @@ -0,0 +1,135 @@ +From a973b405bf34a93b0c300c8bbc4aa5d59fa182e5 Mon Sep 17 00:00:00 2001 +From: Frederic Pillon <frederic.pillon@st.com> +Date: Wed, 10 Jan 2024 18:45:17 +0100 +Subject: [PATCH 3/4] chore: add support for customize app_conf_default.h + +Signed-off-by: Frederic Pillon <frederic.pillon@st.com> +--- + src/utility/STM32_WPAN/app_conf_default.h | 58 ++++++++++++++++++----- + 1 file changed, 45 insertions(+), 13 deletions(-) + +diff --git a/src/utility/STM32_WPAN/app_conf_default.h b/src/utility/STM32_WPAN/app_conf_default.h +index bf2274a..ff2dc01 100644 +--- a/src/utility/STM32_WPAN/app_conf_default.h ++++ b/src/utility/STM32_WPAN/app_conf_default.h +@@ -50,7 +50,9 @@ + /** + * Define Tx Power + */ +-#define CFG_TX_POWER (0x18) /* -0.15dBm */ ++#ifndef CFG_TX_POWER ++ #define CFG_TX_POWER (0x18) /* -0.15dBm */ ++#endif + + #if 0 + /** +@@ -135,13 +137,25 @@ + * Maximum number of simultaneous connections that the device will support. + * Valid values are from 1 to 8 + */ +-#define CFG_BLE_NUM_LINK 8 ++#ifndef CFG_BLE_NUM_LINK ++#ifdef STM32WB15xx ++ #define CFG_BLE_NUM_LINK 3 ++#else ++ #define CFG_BLE_NUM_LINK 8 ++#endif ++#endif + + /** + * Maximum number of Services that can be stored in the GATT database. + * Note that the GAP and GATT services are automatically added so this parameter should be 2 plus the number of user services + */ +-#define CFG_BLE_NUM_GATT_SERVICES 8 ++#ifndef CFG_BLE_NUM_GATT_SERVICES ++#ifdef STM32WB15xx ++ #define CFG_BLE_NUM_GATT_SERVICES 4 ++#else ++ #define CFG_BLE_NUM_GATT_SERVICES 8 ++#endif ++#endif + + /** + * Maximum number of Attributes +@@ -150,7 +164,13 @@ + * Note that certain characteristics and relative descriptors are added automatically during device initialization + * so this parameters should be 9 plus the number of user Attributes + */ +-#define CFG_BLE_NUM_GATT_ATTRIBUTES 68 ++#ifndef CFG_BLE_NUM_GATT_ATTRIBUTES ++#ifdef STM32WB15xx ++ #define CFG_BLE_NUM_GATT_ATTRIBUTES 30 ++#else ++ #define CFG_BLE_NUM_GATT_ATTRIBUTES 68 ++#endif ++#endif + + /** + * Maximum supported ATT_MTU size +@@ -186,12 +206,16 @@ + /** + * Enable or disable the Extended Packet length feature. Valid values are 0 or 1. + */ +-#define CFG_BLE_DATA_LENGTH_EXTENSION 1 ++#ifndef CFG_BLE_DATA_LENGTH_EXTENSION ++ #define CFG_BLE_DATA_LENGTH_EXTENSION 1 ++#endif + + /** + * Sleep clock accuracy in Peripheral mode (ppm value) + */ +-#define CFG_BLE_PERIPHERAL_SCA 500 ++#ifndef CFG_BLE_PERIPHERAL_SCA ++ #define CFG_BLE_PERIPHERAL_SCA 500 ++#endif + + /** + * Sleep clock accuracy in Central mode +@@ -204,7 +228,9 @@ + * 6 : 21 ppm to 30 ppm + * 7 : 0 ppm to 20 ppm + */ +-#define CFG_BLE_CENTRAL_SCA 0 ++#ifndef CFG_BLE_CENTRAL_SCA ++ #define CFG_BLE_CENTRAL_SCA 0 ++#endif + + /** + * LsSource +@@ -213,21 +239,27 @@ + * - bit 1: 1: STM32WB5M Module device 0: Other devices as STM32WBxx SOC, STM32WB1M module + * - bit 2: 1: HSE/1024 Clock config 0: LSE Clock config + */ +-#if defined(STM32WB5Mxx) +- #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_MOD5MM_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) +-#else +- #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_OTHER_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) ++#ifndef CFG_BLE_LS_SOURCE ++ #if defined(STM32WB5Mxx) ++ #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_MOD5MM_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) ++ #else ++ #define CFG_BLE_LS_SOURCE (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_OTHER_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE) ++ #endif + #endif + + /** + * Start up time of the high speed (16 or 32 MHz) crystal oscillator in units of 625/256 us (~2.44 us) + */ +-#define CFG_BLE_HSE_STARTUP_TIME 0x148 ++#ifndef CFG_BLE_HSE_STARTUP_TIME ++ #define CFG_BLE_HSE_STARTUP_TIME 0x148 ++#endif + + /** + * Maximum duration of the connection event when the device is in Peripheral mode in units of 625/256 us (~2.44 us) + */ +-#define CFG_BLE_MAX_CONN_EVENT_LENGTH (0xFFFFFFFF) ++#ifndef CFG_BLE_MAX_CONN_EVENT_LENGTH ++ #define CFG_BLE_MAX_CONN_EVENT_LENGTH (0xFFFFFFFF) ++#endif + + /** + * Viterbi Mode +-- +2.34.1 + diff --git a/extras/STM32_WPAN/0004-fix-TL_Evt_t-payload-size-for-reset.patch b/extras/STM32_WPAN/0004-fix-TL_Evt_t-payload-size-for-reset.patch new file mode 100644 index 00000000..110a8410 --- /dev/null +++ b/extras/STM32_WPAN/0004-fix-TL_Evt_t-payload-size-for-reset.patch @@ -0,0 +1,30 @@ +From 324eef795bfd0a754aae4d5f9b528d4c8ad706c8 Mon Sep 17 00:00:00 2001 +From: Frederic Pillon <frederic.pillon@st.com> +Date: Mon, 24 Jul 2023 10:55:20 +0200 +Subject: [PATCH 4/4] fix: TL_Evt_t payload size for reset + +Within STM32CubeWB v1.17.0 update TL_Evt_t payload size was reduced. +This produce a warning -Warray-bounds due to the reset management +which require 4 bytes. + +Signed-off-by: Frederic Pillon <frederic.pillon@st.com> +--- + src/utility/STM32_WPAN/tl.h | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/utility/STM32_WPAN/tl.h b/src/utility/STM32_WPAN/tl.h +index 8e8c6cb..7452087 100644 +--- a/src/utility/STM32_WPAN/tl.h ++++ b/src/utility/STM32_WPAN/tl.h +@@ -108,7 +108,7 @@ typedef PACKED_STRUCT + { + uint8_t evtcode; + uint8_t plen; +- uint8_t payload[2]; ++ uint8_t payload[4]; + } TL_Evt_t; + + typedef PACKED_STRUCT +-- +2.34.1 + From c6082cd14bd20dd4c8a5401cf5bf29bf39f30900 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Wed, 26 Mar 2025 10:14:02 +0100 Subject: [PATCH 213/226] chore: update with stm32wb Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- .github/workflows/compile-examples.yml | 2 ++ .github/workflows/spell-check.yml | 7 ++++++ README.md | 30 +++++++++++++++++++++++--- library.properties | 2 +- src/utility/HCISharedMemTransport.cpp | 4 ++-- src/utility/HCISpiTransport.cpp | 6 ++---- src/utility/HCITransport.h | 4 ++++ 7 files changed, 45 insertions(+), 10 deletions(-) diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index 5296427c..059e70f1 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -27,6 +27,8 @@ jobs: - STMicroelectronics:stm32:Eval:pnum=STEVAL_MKSBOX1V1,usb=CDCgen - STMicroelectronics:stm32:Nucleo_64:pnum=NUCLEO_L476RG - STMicroelectronics:stm32:Disco:pnum=B_L475E_IOT01A + - STMicroelectronics:stm32:Nucleo_64:pnum=P_NUCLEO_WB55RG + - STMicroelectronics:stm32:Nucleo_64:pnum=P_NUCLEO_WB55_USB_DONGLE steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/spell-check.yml b/.github/workflows/spell-check.yml index 6faf09c8..61af09cd 100644 --- a/.github/workflows/spell-check.yml +++ b/.github/workflows/spell-check.yml @@ -23,3 +23,10 @@ jobs: - name: Spell check uses: codespell-project/actions-codespell@v2 + with: + check_filenames: true + check_hidden: true + # In the event of a false positive, add the word in all lower case to this file: + # ignore_words_file: ./extras/codespell-ignore-words-list.txt + skip: src/utility/STM32_WPAN + path: src diff --git a/README.md b/README.md index 62186871..94d95daa 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,14 @@ # STM32duinoBLE -This library is a fork of ArduinoBLE library to add the support of SPBTLE-RF, SPBTLE-1S, BLUENRG-M2SP, BLUENRG-LP and BLUENRG-M0 BLE modules. +This library is a fork of ArduinoBLE library to add the support of STM32WB, SPBTLE-RF, SPBTLE-1S, BLUENRG-M2SP, BLUENRG-LP and BLUENRG-M0 BLE modules. -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], [B-L4S5I-IOT01A], [STEVAL-MKSBOX1V1], [STEVAL-MKBOXPRO] and with [STM32L562E-DK]. +It was successfully tested with the [NUCLEO-WB15CC], [P-NUCLEO-WB55RG], [STM32WB5MM-DK], [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], [B-L4S5I-IOT01A], [STEVAL-MKSBOX1V1], [STEVAL-MKBOXPRO] and with [STM32L562E-DK]. + + - In order to use this library with SM32WBxx series, you need to update the STM32WB Copro Wireless Binaries with stm32wbxx_BLE_HCILayer_fw.bin depending of your mcu: + +https://github.com/STMicroelectronics/STM32CubeWB/tree/master/Projects/STM32WB_Copro_Wireless_Binaries + + Each subdirectories contains binaries and Release_Notes.html which explain how to update it. - 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: @@ -17,6 +23,14 @@ https://www.arduino.cc/en/Reference/ArduinoBLE # Configuration +### STM32WB + +STM32Cube_WPAN has several configuration options, which are set in the `app_conf.h`. +This package has a default configuration named `app_conf_default.h`. +The user can include the file `app_conf_custom.h` to customize the BLE application. +Options wrapped in `#ifndef`, `#endif` in `app_conf_default.h` can be overwritten. +Additional options can be added. + ### Shield The user can include the file `ble_spi_conf.h` to define which shield and configuration to use from the following list: @@ -70,6 +84,12 @@ This is equivalent to the below configuration using the `CUSTOM_BLE_SPI`: #define BLE_RESET D7 ``` +#### Using a SPI BLE module on STM32WB + +If required, user can use a compatible BLE module over SPI. + +In the `ble_spi_conf.h`, define `USE_BLE_SPI`. + ## License ``` @@ -91,14 +111,18 @@ License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ``` + B-L475E-IOT01A: https://www.st.com/en/evaluation-tools/b-l475e-iot01a.html B-L4S5I-IOT01A: https://www.st.com/en/evaluation-tools/b-l4s5i-iot01a.html NUCLEO-F401RE: https://www.st.com/en/evaluation-tools/nucleo-f401re.html NUCLEO-L053R8: https://www.st.com/en/evaluation-tools/nucleo-l053r8.html NUCLEO-L476RG: https://www.st.com/en/evaluation-tools/nucleo-l476rg.html +NUCLEO-WB15CC: https://www.st.com/en/evaluation-tools/nucleo-wb15cc.html +P-NUCLEO-WB55RG: https://www.st.com/en/evaluation-tools/p-nucleo-wb55.html STEVAL-MKSBOX1V1: https://www.st.com/en/evaluation-tools/steval-mksbox1v1.html STEVAL-MKBOXPRO: https://www.st.com/en/evaluation-tools/steval-mkboxpro.html STM32L562E-DK: https://www.st.com/en/evaluation-tools/stm32l562e-dk.html +STM32WB5MM-DK: https://www.st.com/en/evaluation-tools/stm32wb5mm-dk.html X-NUCLEO-BNRG2A1: https://www.st.com/en/ecosystems/x-nucleo-bnrg2a1.html X-NUCLEO-IDB05A2: https://www.st.com/en/ecosystems/x-nucleo-idb05a2.html -X-NUCLEO-IDB05A1: https://www.st.com/en/ecosystems/x-nucleo-idb05a1.html \ No newline at end of file +X-NUCLEO-IDB05A1: https://www.st.com/en/ecosystems/x-nucleo-idb05a1.html diff --git a/library.properties b/library.properties index 7c5694cd..24c38d09 100644 --- a/library.properties +++ b/library.properties @@ -2,7 +2,7 @@ name=STM32duinoBLE version=1.4.0 author=Arduino, SRA maintainer=stm32duino -sentence=Fork of ArduinoBLE library to add the support of SPBTLE-RF, SPBTLE-1S, BLUENRG-M2SP, BLUENRG-LP and BLUENRG-M0 BLE modules. +sentence=Fork of ArduinoBLE library to add the support of STM32WB, SPBTLE-RF, SPBTLE-1S, BLUENRG-M2SP, BLUENRG-LP and BLUENRG-M0 BLE modules. paragraph=This library supports creating a Bluetooth® Low Energy peripheral & central mode. category=Communication url=https://github.com/stm32duino/STM32duinoBLE diff --git a/src/utility/HCISharedMemTransport.cpp b/src/utility/HCISharedMemTransport.cpp index 8a4cd21a..1544871a 100644 --- a/src/utility/HCISharedMemTransport.cpp +++ b/src/utility/HCISharedMemTransport.cpp @@ -16,7 +16,7 @@ License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#if defined(STM32WBxx) +#if defined(STM32WBxx) && !defined(USE_BLE_SPI) #include "HCISharedMemTransport.h" #include "STM32_WPAN/hw.h" @@ -778,4 +778,4 @@ int HCISharedMemTransportClass::bt_ipm_set_power(void) } HCITransportInterface& HCITransport = HCISharedMemTransport; -#endif /* STM32WBxx */ +#endif /* STM32WBxx && !USE_BLE_SPI */ diff --git a/src/utility/HCISpiTransport.cpp b/src/utility/HCISpiTransport.cpp index 9a3709da..16b81623 100644 --- a/src/utility/HCISpiTransport.cpp +++ b/src/utility/HCISpiTransport.cpp @@ -17,12 +17,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#if !defined(STM32WBxx) || defined(USE_BLE_SPI) #include "HCISpiTransport.h" -#if __has_include("ble_spi_conf.h") - #include "ble_spi_conf.h" -#endif - #if defined(CUSTOM_BLE_SPI) SPIClass SpiHCI(BLE_SPI_MOSI, BLE_SPI_MISO, BLE_SPI_CLK); HCISpiTransportClass HCISpiTransport(SpiHCI, BLE_CHIP_TYPE, BLE_SPI_CS, BLE_SPI_IRQ, BLE_RESET, BLE_SPI_FREQ, BLE_SPI_MODE); @@ -1404,3 +1401,4 @@ void HCISpiTransportClass::wait_for_set_address() } HCITransportInterface& HCITransport = HCISpiTransport; +#endif // !STM32WBxx || USE_BLE_SPI diff --git a/src/utility/HCITransport.h b/src/utility/HCITransport.h index d8aa6a95..02e7962f 100644 --- a/src/utility/HCITransport.h +++ b/src/utility/HCITransport.h @@ -22,6 +22,10 @@ #include <Arduino.h> +#if __has_include("ble_spi_conf.h") + #include "ble_spi_conf.h" +#endif + class HCITransportInterface { public: virtual int begin() = 0; From c6e7932e70cdb3c5add2e6c53dd4d70cf42a7ae6 Mon Sep 17 00:00:00 2001 From: Carlo Parata <carlo.parata@st.com> Date: Tue, 9 Feb 2021 15:35:13 +0100 Subject: [PATCH 214/226] feat: add possibility to choose the ownAddressType in the Arduino stack Signed-off-by: Carlo Parata <carlo.parata@st.com> --- src/local/BLELocalDevice.cpp | 6 +++++- src/local/BLELocalDevice.h | 11 ++++++++++- src/utility/ATT.cpp | 12 +++++++++++- src/utility/ATT.h | 6 ++++++ src/utility/GAP.cpp | 9 +++++++-- src/utility/GAP.h | 3 +++ 6 files changed, 42 insertions(+), 5 deletions(-) diff --git a/src/local/BLELocalDevice.cpp b/src/local/BLELocalDevice.cpp index 5792353f..3a620e32 100644 --- a/src/local/BLELocalDevice.cpp +++ b/src/local/BLELocalDevice.cpp @@ -39,7 +39,7 @@ #endif #endif -BLELocalDevice::BLELocalDevice() +BLELocalDevice::BLELocalDevice(uint8_t ownBdaddrType): _ownBdaddrType(ownBdaddrType) { _advertisingData.setFlags(BLEFlagsGeneralDiscoverable | BLEFlagsBREDRNotSupported); } @@ -207,6 +207,10 @@ int BLELocalDevice::begin() GATT.begin(); + GAP.setOwnBdaddrType(_ownBdaddrType); + + ATT.setOwnBdaddrType(_ownBdaddrType); + return 1; } diff --git a/src/local/BLELocalDevice.h b/src/local/BLELocalDevice.h index 6c45c063..4c39fb16 100644 --- a/src/local/BLELocalDevice.h +++ b/src/local/BLELocalDevice.h @@ -30,9 +30,16 @@ enum Pairable { ONCE = 2, }; +enum AddressType { + PUBLIC_ADDR = 0, + STATIC_RANDOM_ADDR = 1, + RESOLVABLE_PRIVATE_ADDR = 2, + NON_RESOLVABLE_PRIVATE_ADDR = 3, +}; + class BLELocalDevice { public: - BLELocalDevice(); + BLELocalDevice(uint8_t ownBdaddrType = STATIC_RANDOM_ADDR); virtual ~BLELocalDevice(); virtual int begin(); @@ -107,6 +114,7 @@ class BLELocalDevice { virtual void setDisplayCode(void (*displayCode)(uint32_t confirmationCode)); virtual void setBinaryConfirmPairing(bool (*binaryConfirmPairing)()); + uint8_t BDaddress[6]; protected: @@ -116,6 +124,7 @@ class BLELocalDevice { private: BLEAdvertisingData _advertisingData; BLEAdvertisingData _scanResponseData; + uint8_t _ownBdaddrType; }; extern BLELocalDevice& BLE; diff --git a/src/utility/ATT.cpp b/src/utility/ATT.cpp index ba717543..4a6d3ef8 100644 --- a/src/utility/ATT.cpp +++ b/src/utility/ATT.cpp @@ -114,7 +114,7 @@ ATTClass::~ATTClass() bool ATTClass::connect(uint8_t peerBdaddrType, uint8_t peerBdaddr[6]) { - if (HCI.leCreateConn(0x0060, 0x0030, 0x00, peerBdaddrType, peerBdaddr, 0x00, + if (HCI.leCreateConn(0x0060, 0x0030, 0x00, peerBdaddrType, peerBdaddr, _ownBdaddrType, 0x0006, 0x000c, 0x0000, 0x00c8, 0x0004, 0x0006) != 0) { return false; } @@ -1957,6 +1957,16 @@ int ATTClass::getPeerResolvedAddress(uint16_t connectionHandle, uint8_t resolved return 0; } +void ATTClass::setOwnBdaddrType(uint8_t ownBdaddrType) +{ + _ownBdaddrType = ownBdaddrType; +} + +uint8_t ATTClass::getOwnBdaddrType(void) +{ + return _ownBdaddrType; +} + #if !defined(FAKE_ATT) ATTClass ATTObj; ATTClass& ATT = ATTObj; diff --git a/src/utility/ATT.h b/src/utility/ATT.h index 9cf203a6..2d69d2b5 100644 --- a/src/utility/ATT.h +++ b/src/utility/ATT.h @@ -109,6 +109,10 @@ class ATTClass { uint8_t peerIRK[16]; /// This is just a random number... Not sure it has use unless privacy mode is active. uint8_t localIRK[16] = {0x54,0x83,0x63,0x7c,0xc5,0x1e,0xf7,0xec,0x32,0xdd,0xad,0x51,0x89,0x4b,0x9e,0x07}; + + void setOwnBdaddrType(uint8_t ownBdaddrType); + uint8_t getOwnBdaddrType(); // Used in L2CAPSignaling to encryption + private: virtual void error(uint16_t connectionHandle, uint8_t dlen, uint8_t data[]); virtual void mtuReq(uint16_t connectionHandle, uint8_t dlen, uint8_t data[]); @@ -170,6 +174,8 @@ class ATTClass { } _pendingResp; BLEDeviceEventHandler _eventHandlers[2]; + + uint8_t _ownBdaddrType; }; extern ATTClass& ATT; diff --git a/src/utility/GAP.cpp b/src/utility/GAP.cpp index f1bf02fe..fac04a67 100644 --- a/src/utility/GAP.cpp +++ b/src/utility/GAP.cpp @@ -54,7 +54,7 @@ int GAPClass::advertise(uint8_t* advData, uint8_t advDataLen, uint8_t* scanData, stopAdvertise(); - if (HCI.leSetAdvertisingParameters(_advertisingInterval, _advertisingInterval, type, 0x00, 0x00, directBdaddr, 0x07, 0) != 0) { + if (HCI.leSetAdvertisingParameters(_advertisingInterval, _advertisingInterval, type, _ownBdaddrType, 0x00, directBdaddr, 0x07, 0) != 0) { return 0; } @@ -93,7 +93,7 @@ int GAPClass::scan(bool withDuplicates) - scan window: mandatory range from 0x0011 to 0x1000 - The scan window can only be less than or equal to the scan interval */ - if (HCI.leSetScanParameters(0x01, 0x0020, 0x0020, 0x00, 0x00) != 0) { + if (HCI.leSetScanParameters(0x01, 0x0020, 0x0020, _ownBdaddrType, 0x00) != 0) { return false; } @@ -266,6 +266,11 @@ bool GAPClass::matchesScanFilter(const BLEDevice& device) return true; } +void GAPClass::setOwnBdaddrType(uint8_t ownBdaddrType) +{ + _ownBdaddrType = ownBdaddrType; +} + #if !defined(FAKE_GAP) GAPClass GAPObj; GAPClass& GAP = GAPObj; diff --git a/src/utility/GAP.h b/src/utility/GAP.h index 2ea22938..cadd0cba 100644 --- a/src/utility/GAP.h +++ b/src/utility/GAP.h @@ -45,6 +45,8 @@ class GAPClass { virtual void setEventHandler(BLEDeviceEvent event, BLEDeviceEventHandler eventHandler); + void setOwnBdaddrType(uint8_t ownBdaddrType); + protected: friend class HCIClass; @@ -67,6 +69,7 @@ class GAPClass { String _scanNameFilter; String _scanUuidFilter; String _scanAddressFilter; + uint8_t _ownBdaddrType; }; extern GAPClass& GAP; From a34566bede6e309a91ce0862c790180457548a6a Mon Sep 17 00:00:00 2001 From: Alexandre Bourdiol <alexandre.bourdiol@st.com> Date: Mon, 24 Oct 2022 11:35:21 +0200 Subject: [PATCH 215/226] fix: HCI only Firmware not supporting ACI_GAP_INIT ACI_GATT_INIT On STM32WB, Cube FW version 1.14.1, messages ACI_GATT_INIT and ACI_GAP_INIT are not available on HCI only BLE firmware (stm32wb5x_BLE_HCILayer_fw.bin) This imply to move Random Address to host instead of relying on controller Signed-off-by: Alexandre Bourdiol <alexandre.bourdiol@st.com> --- src/local/BLELocalDevice.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/local/BLELocalDevice.cpp b/src/local/BLELocalDevice.cpp index 3a620e32..e333b22f 100644 --- a/src/local/BLELocalDevice.cpp +++ b/src/local/BLELocalDevice.cpp @@ -124,6 +124,20 @@ int BLELocalDevice::begin() return 0; } + uint8_t randomNumber[8]; + if (HCI.leRand(randomNumber) != 0) { + end(); + return 0; + } + /* Random address only requires 6 bytes (48 bits) + * Force both MSB bits to b00 in order to define Static Random Address + */ + randomNumber[5] |= 0xC0; + if (HCI.leSetRandomAddress((uint8_t*)randomNumber) != 0) { + end(); + return 0; + } + uint8_t hciVer; uint16_t hciRev; uint8_t lmpVer; From 001aca906e773dea5e8fccb985cb4512e5421107 Mon Sep 17 00:00:00 2001 From: Lorenzo Bini <lorenzo.bini@studenti.unimi.it> Date: Tue, 14 Mar 2023 17:19:12 +0100 Subject: [PATCH 216/226] feat: add API to get random address Signed-off-by: Lorenzo Bini <lorenzo.bini@studenti.unimi.it> --- src/local/BLELocalDevice.cpp | 19 +++++++++++++++++++ src/local/BLELocalDevice.h | 3 +++ 2 files changed, 22 insertions(+) diff --git a/src/local/BLELocalDevice.cpp b/src/local/BLELocalDevice.cpp index e333b22f..a888963a 100644 --- a/src/local/BLELocalDevice.cpp +++ b/src/local/BLELocalDevice.cpp @@ -133,6 +133,15 @@ int BLELocalDevice::begin() * Force both MSB bits to b00 in order to define Static Random Address */ randomNumber[5] |= 0xC0; + + // Copy the random address in private variable as it will be sent to the BLE chip + randomAddress [0] = randomNumber[0]; + randomAddress [1] = randomNumber[1]; + randomAddress [2] = randomNumber[2]; + randomAddress [3] = randomNumber[3]; + randomAddress [4] = randomNumber[4]; + randomAddress [5] = randomNumber[5]; + if (HCI.leSetRandomAddress((uint8_t*)randomNumber) != 0) { end(); return 0; @@ -247,6 +256,16 @@ void BLELocalDevice::end() _scanResponseData.clear(); } +void BLELocalDevice::getRandomAddress(uint8_t buff[6]) +{ + buff [0] = randomAddress[0]; + buff [1] = randomAddress[1]; + buff [2] = randomAddress[2]; + buff [3] = randomAddress[3]; + buff [4] = randomAddress[4]; + buff [5] = randomAddress[5]; +} + void BLELocalDevice::poll() { HCI.poll(); diff --git a/src/local/BLELocalDevice.h b/src/local/BLELocalDevice.h index 4c39fb16..137ab69f 100644 --- a/src/local/BLELocalDevice.h +++ b/src/local/BLELocalDevice.h @@ -91,6 +91,8 @@ class BLELocalDevice { virtual void setTimeout(unsigned long timeout); + virtual void getRandomAddress(uint8_t buff[6]); + virtual void debug(Stream& stream); virtual void noDebug(); @@ -122,6 +124,7 @@ class BLELocalDevice { virtual BLEAdvertisingData& getScanResponseData(); private: + uint8_t randomAddress[6]; BLEAdvertisingData _advertisingData; BLEAdvertisingData _scanResponseData; uint8_t _ownBdaddrType; From 04de5dffd48a58341f88b062dd6b46eea884b8ce Mon Sep 17 00:00:00 2001 From: Carlo Parata <carlo.parata@st.com> Date: Fri, 7 Feb 2020 11:20:49 +0100 Subject: [PATCH 217/226] chore(GAP): improve scan Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- src/local/BLELocalDevice.cpp | 4 ++-- src/local/BLELocalDevice.h | 2 +- src/utility/GAP.cpp | 18 +++++++++++++++--- src/utility/GAP.h | 2 +- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/local/BLELocalDevice.cpp b/src/local/BLELocalDevice.cpp index a888963a..d1128788 100644 --- a/src/local/BLELocalDevice.cpp +++ b/src/local/BLELocalDevice.cpp @@ -421,9 +421,9 @@ int BLELocalDevice::scanForAddress(String address, bool withDuplicates) return GAP.scanForAddress(address, withDuplicates); } -void BLELocalDevice::stopScan() +int BLELocalDevice::stopScan() { - GAP.stopScan(); + return GAP.stopScan(); } BLEDevice BLELocalDevice::central() diff --git a/src/local/BLELocalDevice.h b/src/local/BLELocalDevice.h index 137ab69f..8217669f 100644 --- a/src/local/BLELocalDevice.h +++ b/src/local/BLELocalDevice.h @@ -77,7 +77,7 @@ class BLELocalDevice { virtual int scanForName(String name, bool withDuplicates = false); virtual int scanForUuid(String uuid, bool withDuplicates = false); virtual int scanForAddress(String address, bool withDuplicates = false); - virtual void stopScan(); + virtual int stopScan(); virtual BLEDevice central(); virtual BLEDevice available(); diff --git a/src/utility/GAP.cpp b/src/utility/GAP.cpp index fac04a67..ed001a96 100644 --- a/src/utility/GAP.cpp +++ b/src/utility/GAP.cpp @@ -84,7 +84,12 @@ void GAPClass::stopAdvertise() int GAPClass::scan(bool withDuplicates) { - HCI.leSetScanEnable(false, true); + if(_scanning) { + // Check if the HCI command fails + if (HCI.leSetScanEnable(false, true) != 0) { + return 0; + } + } // active scan, 20 ms scan interval (N * 0.625), 20 ms scan window (N * 0.625), public own address type, no filter /* @@ -133,9 +138,14 @@ int GAPClass::scanForAddress(String address, bool withDuplicates) return scan(withDuplicates); } -void GAPClass::stopScan() +int GAPClass::stopScan() { - HCI.leSetScanEnable(false, false); + if(_scanning) { + // Check if the HCI command fails + if (HCI.leSetScanEnable(false, false) != 0) { + return 0; + } + } _scanning = false; @@ -146,6 +156,8 @@ void GAPClass::stopScan() } _discoveredDevices.clear(); + + return 1; } BLEDevice GAPClass::available() diff --git a/src/utility/GAP.h b/src/utility/GAP.h index cadd0cba..c79a2aa7 100644 --- a/src/utility/GAP.h +++ b/src/utility/GAP.h @@ -37,7 +37,7 @@ class GAPClass { virtual int scanForName(String name, bool withDuplicates); virtual int scanForUuid(String uuid, bool withDuplicates); virtual int scanForAddress(String address, bool withDuplicates); - virtual void stopScan(); + virtual int stopScan(); virtual BLEDevice available(); virtual void setAdvertisingInterval(uint16_t advertisingInterval); From 3ee75de4c51483bbb292b9471ea6a54537d66da6 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Thu, 20 Mar 2025 11:29:22 +0100 Subject: [PATCH 218/226] chore(examples): enhance button support Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- examples/Central/LedControl/LedControl.ino | 15 ++++++++++++--- examples/Peripheral/ButtonLED/ButtonLED.ino | 8 ++++++-- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/examples/Central/LedControl/LedControl.ino b/examples/Central/LedControl/LedControl.ino index 064bb29e..fa4ebfc3 100644 --- a/examples/Central/LedControl/LedControl.ino +++ b/examples/Central/LedControl/LedControl.ino @@ -17,19 +17,28 @@ #include <STM32duinoBLE.h> // variables for button -const int buttonPin = 2; +#ifdef USER_BTN +const int buttonPin = USER_BTN; // set buttonPin to on-board button +#else +const int buttonPin = PC13; // set buttonPin to digital pin PC13 */ +#endif int oldButtonState = LOW; +int initialButtonState = LOW; void setup() { Serial.begin(9600); while (!Serial); // configure the button pin as input - pinMode(buttonPin, INPUT); + pinMode(buttonPin, INPUT_PULLUP); // initialize the Bluetooth® Low Energy hardware BLE.begin(); + // Get initial button state + initialButtonState = digitalRead(buttonPin); + oldButtonState = initialButtonState; + Serial.println("Bluetooth® Low Energy Central - LED control"); // start scanning for peripherals @@ -108,7 +117,7 @@ void controlLed(BLEDevice peripheral) { // button changed oldButtonState = buttonState; - if (buttonState) { + if (buttonState != initialButtonState) { Serial.println("button pressed"); // button is pressed, write 0x01 to turn the LED on diff --git a/examples/Peripheral/ButtonLED/ButtonLED.ino b/examples/Peripheral/ButtonLED/ButtonLED.ino index baa64b87..8ae7d665 100644 --- a/examples/Peripheral/ButtonLED/ButtonLED.ino +++ b/examples/Peripheral/ButtonLED/ButtonLED.ino @@ -18,7 +18,11 @@ #include <STM32duinoBLE.h> const int ledPin = LED_BUILTIN; // set ledPin to on-board LED -const int buttonPin = 4; // set buttonPin to digital pin 4 +#ifdef USER_BTN +const int buttonPin = USER_BTN; // set buttonPin to on-board button +#else +const int buttonPin = PC13; // set buttonPin to digital pin PC13 */ +#endif BLEService ledService("19B10010-E8F2-537E-4F6C-D104768A1214"); // create service @@ -32,7 +36,7 @@ void setup() { while (!Serial); pinMode(ledPin, OUTPUT); // use the LED as an output - pinMode(buttonPin, INPUT); // use button pin as an input + pinMode(buttonPin, INPUT_PULLUP); // use button pin as an input // begin initialization if (!BLE.begin()) { From 2c8c4a7c33b071f28c8e0524860060f83aca93f3 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Thu, 20 Mar 2025 11:32:00 +0100 Subject: [PATCH 219/226] chore(examples): enhance scan management Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- examples/Central/LedControl/LedControl.ino | 33 +++++++++++++++-- .../PeripheralExplorer/PeripheralExplorer.ino | 22 ++++++++++-- examples/Central/Scan/Scan.ino | 13 +++++-- .../Central/ScanCallback/ScanCallback.ino | 11 +++++- .../SensorTagButton/SensorTagButton.ino | 35 ++++++++++++++++--- 5 files changed, 102 insertions(+), 12 deletions(-) diff --git a/examples/Central/LedControl/LedControl.ino b/examples/Central/LedControl/LedControl.ino index fa4ebfc3..cbda07d1 100644 --- a/examples/Central/LedControl/LedControl.ino +++ b/examples/Central/LedControl/LedControl.ino @@ -42,7 +42,16 @@ void setup() { Serial.println("Bluetooth® Low Energy Central - LED control"); // start scanning for peripherals - BLE.scanForUuid("19b10000-e8f2-537e-4f6c-d104768a1214"); + int ret = 1; + do + { + ret = BLE.scanForUuid("19b10000-e8f2-537e-4f6c-d104768a1214"); + if (ret == 0) + { + BLE.end(); + BLE.begin(); + } + } while(ret == 0); } void loop() { @@ -64,12 +73,30 @@ void loop() { } // stop scanning - BLE.stopScan(); + int ret = 1; + do + { + ret = BLE.stopScan(); + if (ret == 0) + { + BLE.end(); + BLE.begin(); + } + } while(ret == 0); controlLed(peripheral); // peripheral disconnected, start scanning again - BLE.scanForUuid("19b10000-e8f2-537e-4f6c-d104768a1214"); + ret = 1; + do + { + ret = BLE.scanForUuid("19b10000-e8f2-537e-4f6c-d104768a1214"); + if (ret == 0) + { + BLE.end(); + BLE.begin(); + } + } while(ret == 0); } } diff --git a/examples/Central/PeripheralExplorer/PeripheralExplorer.ino b/examples/Central/PeripheralExplorer/PeripheralExplorer.ino index 4a72a697..7d4841ae 100644 --- a/examples/Central/PeripheralExplorer/PeripheralExplorer.ino +++ b/examples/Central/PeripheralExplorer/PeripheralExplorer.ino @@ -29,7 +29,16 @@ void setup() { Serial.println("Bluetooth® Low Energy Central - Peripheral Explorer"); // start scanning for peripherals - BLE.scan(); + int ret = 1; + do + { + ret = BLE.scan(); + if (ret == 0) + { + BLE.end(); + BLE.begin(); + } + } while(ret == 0); } void loop() { @@ -49,7 +58,16 @@ void loop() { // see if peripheral is a LED if (peripheral.localName() == "LED") { // stop scanning - BLE.stopScan(); + int ret = 1; + do + { + ret = BLE.stopScan(); + if (ret == 0) + { + BLE.end(); + BLE.begin(); + } + } while(ret == 0); explorerPeripheral(peripheral); diff --git a/examples/Central/Scan/Scan.ino b/examples/Central/Scan/Scan.ino index 99e13696..ca6b2b9a 100644 --- a/examples/Central/Scan/Scan.ino +++ b/examples/Central/Scan/Scan.ino @@ -25,8 +25,17 @@ void setup() { Serial.println("Bluetooth® Low Energy Central scan"); - // start scanning for peripheral - BLE.scan(); + // start scanning for peripherals + int ret = 1; + do + { + ret = BLE.scan(); + if (ret == 0) + { + BLE.end(); + BLE.begin(); + } + } while(ret == 0); } void loop() { diff --git a/examples/Central/ScanCallback/ScanCallback.ino b/examples/Central/ScanCallback/ScanCallback.ino index 63ab2753..cc33ee85 100644 --- a/examples/Central/ScanCallback/ScanCallback.ino +++ b/examples/Central/ScanCallback/ScanCallback.ino @@ -31,7 +31,16 @@ void setup() { BLE.setEventHandler(BLEDiscovered, bleCentralDiscoverHandler); // start scanning for peripherals with duplicates - BLE.scan(true); + int ret = 1; + do + { + ret = BLE.scan(true); + if (ret == 0) + { + BLE.end(); + BLE.begin(); + } + } while(ret == 0); } void loop() { diff --git a/examples/Central/SensorTagButton/SensorTagButton.ino b/examples/Central/SensorTagButton/SensorTagButton.ino index 26ee667d..f063ac68 100644 --- a/examples/Central/SensorTagButton/SensorTagButton.ino +++ b/examples/Central/SensorTagButton/SensorTagButton.ino @@ -30,8 +30,17 @@ void setup() { Serial.println("Bluetooth® Low Energy Central - SensorTag button"); Serial.println("Make sure to turn on the device."); - // start scanning for peripheral - BLE.scan(); + // start scanning for peripherals + int ret = 1; + do + { + ret = BLE.scan(); + if (ret == 0) + { + BLE.end(); + BLE.begin(); + } + } while(ret == 0); } void loop() { @@ -52,12 +61,30 @@ void loop() { // "CC2650 SensorTag" if (peripheral.localName() == "CC2650 SensorTag") { // stop scanning - BLE.stopScan(); + int ret = 1; + do + { + ret = BLE.stopScan(); + if (ret == 0) + { + BLE.end(); + BLE.begin(); + } + } while(ret == 0); monitorSensorTagButtons(peripheral); // peripheral disconnected, start scanning again - BLE.scan(); + ret = 1; + do + { + ret = BLE.scan(); + if (ret == 0) + { + BLE.end(); + BLE.begin(); + } + } while(ret == 0); } } } From 2f0cef7c8f82adc05bf4a0096489b1aa96725695 Mon Sep 17 00:00:00 2001 From: Arkadiusz Ambroziak <arekambroziak@op.pl> Date: Tue, 18 Mar 2025 15:36:06 +0100 Subject: [PATCH 220/226] fix: for pairing with Static Random Address Signed-off-by: Arkadiusz Ambroziak <arekambroziak@op.pl> Co-Auhthored-by: Frederic Pillon <frederic.pillon@st.com> --- src/local/BLELocalDevice.cpp | 23 +++++++++++++++++++++-- src/utility/L2CAPSignaling.cpp | 8 +++++--- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/local/BLELocalDevice.cpp b/src/local/BLELocalDevice.cpp index d1128788..6137e14b 100644 --- a/src/local/BLELocalDevice.cpp +++ b/src/local/BLELocalDevice.cpp @@ -142,10 +142,22 @@ int BLELocalDevice::begin() randomAddress [4] = randomNumber[4]; randomAddress [5] = randomNumber[5]; - if (HCI.leSetRandomAddress((uint8_t*)randomNumber) != 0) { + // Set Random address only when type is STATIC_RANDOM_ADDR + if ((_ownBdaddrType == STATIC_RANDOM_ADDR) && (HCI.leSetRandomAddress((uint8_t*)randomNumber) != 0)) { end(); return 0; } + // Save address to HCI.localAddr variable, which is used to encryption in pairing + if(_ownBdaddrType == PUBLIC_ADDR){ + if (HCI.readBdAddr() != 0) { + end(); + return 0; + } + } else { + for(int k=0; k<6; k++){ + HCI.localAddr[5-k] = randomAddress[k]; + } + } uint8_t hciVer; uint16_t hciRev; @@ -301,7 +313,14 @@ bool BLELocalDevice::disconnect() String BLELocalDevice::address() const { uint8_t addr[6] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - HCI.readBdAddr(addr); + // return correct device address when is set to STATIC RANDOM (set by HCI) + if(_ownBdaddrType == PUBLIC_ADDR) { + HCI.readBdAddr(addr); + } else { + for(int k=0; k<6; k++) { + addr[k]=HCI.localAddr[5-k]; + } + } char result[18]; sprintf(result, "%02x:%02x:%02x:%02x:%02x:%02x", addr[5], addr[4], addr[3], addr[2], addr[1], addr[0]); diff --git a/src/utility/L2CAPSignaling.cpp b/src/utility/L2CAPSignaling.cpp index a7582681..e88189cf 100644 --- a/src/utility/L2CAPSignaling.cpp +++ b/src/utility/L2CAPSignaling.cpp @@ -371,10 +371,12 @@ void L2CAPSignalingClass::smCalculateLTKandConfirm(uint16_t handle, uint8_t expe uint8_t localAddress[7]; uint8_t remoteAddress[7]; ATT.getPeerAddrWithType(handle, remoteAddress); - - HCI.readBdAddr(); + + // Address is taken directly from HCI.localaddress, + // which is set when object DeviceLocal is created + // HCI.readBdAddr(); memcpy(&localAddress[1],HCI.localAddr,6); - localAddress[0] = 0; // IOT 33 uses a static address // TODO: confirm for Nano BLE + localAddress[0] = ATT.getOwnBdaddrType(); // Adding bit with address type (e.g. Static random or public address) // Compute the LTK and MacKey uint8_t MacKey[16]; From 6c815fc50a405ed526c708d7136dec03ee7bab88 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Thu, 20 Mar 2025 10:36:52 +0100 Subject: [PATCH 221/226] fix: wrong Le Event Mask set See LE_META_EVENT supported. Note: Value should be 0x3B3 but set to 0x1B3 to explicitly ignore ENHANCED_CONN_COMPLETE event Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- src/local/BLELocalDevice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/local/BLELocalDevice.cpp b/src/local/BLELocalDevice.cpp index 6137e14b..0aa30313 100644 --- a/src/local/BLELocalDevice.cpp +++ b/src/local/BLELocalDevice.cpp @@ -174,7 +174,7 @@ int BLELocalDevice::begin() end(); return 0; } - if (HCI.setLeEventMask(0x00000000000003FF) != 0) { + if (HCI.setLeEventMask(0x00000000000001B3) != 0) { end(); return 0; } From dd9d26952334e9db2bebe3d39eaa05a66a67f5c3 Mon Sep 17 00:00:00 2001 From: Andrew Childs <tidy.desk9426@fastmail.com> Date: Sun, 4 Feb 2024 21:03:55 -0500 Subject: [PATCH 222/226] Reset scan filters when stopScan is called [Fixes #350] --- src/utility/GAP.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/utility/GAP.cpp b/src/utility/GAP.cpp index ed001a96..649b7e5d 100644 --- a/src/utility/GAP.cpp +++ b/src/utility/GAP.cpp @@ -147,6 +147,9 @@ int GAPClass::stopScan() } } + _scanNameFilter = ""; + _scanUuidFilter = ""; + _scanAddressFilter = ""; _scanning = false; for (unsigned int i = 0; i < _discoveredDevices.size(); i++) { From 612d7d1f55a2fc0d6159c263bba95a9507a1fb5b Mon Sep 17 00:00:00 2001 From: Derek Carter <carter_derek@live.com> Date: Sun, 25 Sep 2022 15:29:12 +0100 Subject: [PATCH 223/226] Fix for issue #245 - ATT_OP_FIND_INFO_RESP incorrect processing during ATTClass::discoverDescriptors causes crashing I've highlighted this issue on 9th July ... this is an issue of causing __CRASHES__ if using ArduinoBLE to connect as central and the response to ATT_OP_FIND_INFO_RESP includes 128-bit UUIDs. --- src/utility/ATT.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/utility/ATT.cpp b/src/utility/ATT.cpp index 4a6d3ef8..4fe4b71a 100644 --- a/src/utility/ATT.cpp +++ b/src/utility/ATT.cpp @@ -1745,8 +1745,19 @@ bool ATTClass::discoverDescriptors(uint16_t connectionHandle, BLERemoteDevice* d } if (responseBuffer[0] == ATT_OP_FIND_INFO_RESP) { - uint16_t lengthPerDescriptor = responseBuffer[1] * 4; - uint8_t uuidLen = 2; + // + // Format parameter (responseBuffer[1]) either 0x01 - 16-bit Bluetooth UUID(s), or 0x02 - 128 bit UUID(s) + // + // Therefore for: + // 0x01 - uuidLen = 2 (octets) + // lengthPerDescriptor = 4 (Handle 2 octets + UUID 2 octets) + // 0x02 - uuidLen = 16 (octets) + // lengthPerDescriptor = 18 (Handle 2 octets + UUID 16 octets) + // + // See section 3.4.3.2 ATT_FIND_INFORMATION_RSP of Bluetooth Core Specification 5.3. + // + uint16_t lengthPerDescriptor = responseBuffer[1] * 14 - 10; + uint8_t uuidLen = lengthPerDescriptor - 2; for (int i = 2; i < respLength; i += lengthPerDescriptor) { struct __attribute__ ((packed)) RawDescriptor { From def51aadbd6c142421785ca736f3f2e584f6f194 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Thu, 17 Apr 2025 11:30:02 +0200 Subject: [PATCH 224/226] fix: unused variable warnings Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- src/utility/HCI.cpp | 4 +--- src/utility/btct.cpp | 11 ++++++----- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/utility/HCI.cpp b/src/utility/HCI.cpp index af73ead2..ebe66a27 100644 --- a/src/utility/HCI.cpp +++ b/src/utility/HCI.cpp @@ -521,19 +521,17 @@ int HCIClass::leReadPeerResolvableAddress(uint8_t peerAddressType, uint8_t* peer #ifdef _BLE_TRACE_ Serial.print("res: 0x"); Serial.println(res, HEX); -#endif if(res==0){ struct __attribute__ ((packed)) Response { uint8_t status; uint8_t peerResolvableAddress[6]; } *response = (Response*)_cmdResponse; -#ifdef _BLE_TRACE_ Serial.print("Address resolution status: 0x"); Serial.println(response->status, HEX); Serial.print("peer resolvable address: "); btct.printBytes(response->peerResolvableAddress,6); -#endif } + #endif return res; } diff --git a/src/utility/btct.cpp b/src/utility/btct.cpp index dffbccf9..cb67fdf5 100644 --- a/src/utility/btct.cpp +++ b/src/utility/btct.cpp @@ -37,6 +37,9 @@ void BluetoothCryptoToolbox::printBytes(uint8_t bytes[], uint8_t length){ Serial.print(bytes[i],HEX); } Serial.print('\n'); +#else + (void)bytes; + (void)length; #endif } @@ -130,7 +133,7 @@ int BluetoothCryptoToolbox::ah(uint8_t k[16], uint8_t r[3], uint8_t* result) } void BluetoothCryptoToolbox::testAh() { - uint8_t irk[16] = {0xec,0x02,0x34,0xa3,0x57,0xc8,0xad,0x05,0x34,0x10,0x10,0xa6,0x0a,0x39,0x7d,0x9b}; + uint8_t irk[16] = {0xec,0x02,0x34,0xa3,0x57,0xc8,0xad,0x05,0x34,0x10,0x10,0xa6,0x0a,0x39,0x7d,0x9b}; uint8_t expected_final[3] = {0x0d,0xfb,0xaa}; uint8_t ourResult[3]; ah(irk, expected_final, ourResult); @@ -165,14 +168,12 @@ void BluetoothCryptoToolbox::testg2(){ uint8_t Y[16] = {0xa6,0xe8,0xe7,0xcc,0x25,0xa7,0x5f,0x6e,0x21,0x65,0x83,0xf7,0xff,0x3d,0xc4,0xcf}; uint8_t out[4]; - uint32_t expected = 0; g2(U,V,X,Y,out); uint32_t result = 0; for(int i=0; i<4; i++) result += out[i] << 8*i; #ifdef _BLE_TRACE_ - Serial.print("Expected : "); - Serial.println(expected); + Serial.println("Expected : 0"); Serial.print("Result : "); Serial.println(result); Serial.println(); @@ -383,4 +384,4 @@ void BluetoothCryptoToolbox::xor_128(unsigned char *a, unsigned char *b, unsigne out[i] = a[i] ^ b[i]; } } -BluetoothCryptoToolbox btct; \ No newline at end of file +BluetoothCryptoToolbox btct; From 3c253e4e4cfed80021f0ace2fd37ef2c74eff131 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Tue, 22 Apr 2025 09:22:46 +0200 Subject: [PATCH 225/226] doc: add configuration example Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index 94d95daa..f42464a1 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,17 @@ The user can include the file `app_conf_custom.h` to customize the BLE applicati Options wrapped in `#ifndef`, `#endif` in `app_conf_default.h` can be overwritten. Additional options can be added. +The user can refer to [AN5270](https://www.st.com/resource/en/application_note/an5270-introduction-to-stm32wb-bluetooth-low-energy-wireless-interface-stmicroelectronics.pdf) + +##### Examples + +The user can change the Tx Power by redefining `CFG_TX_POWER` using the [`build_opt.h`](https://github.com/stm32duino/Arduino_Core_STM32/wiki/Customize-build-options-using-build_opt.h) file. Possible values are listed in the chapter +**4.2 Tx power level**, default value is `0x18`(`-0.15dBm`). To set it at `+1dBm`, `CFG_TX_POWER` have to be defined at `0x1A`: + +``` +-DCFG_TX_POWER=0x1A +``` + ### Shield The user can include the file `ble_spi_conf.h` to define which shield and configuration to use from the following list: From 4a1bf81729c9219af3cc363c3619e6bf0b568487 Mon Sep 17 00:00:00 2001 From: Frederic Pillon <frederic.pillon@st.com> Date: Mon, 5 May 2025 09:27:53 +0200 Subject: [PATCH 226/226] fix(doc): links format Signed-off-by: Frederic Pillon <frederic.pillon@st.com> --- README.md | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index f42464a1..ca305c4a 100644 --- a/README.md +++ b/README.md @@ -123,17 +123,17 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ``` -B-L475E-IOT01A: https://www.st.com/en/evaluation-tools/b-l475e-iot01a.html -B-L4S5I-IOT01A: https://www.st.com/en/evaluation-tools/b-l4s5i-iot01a.html -NUCLEO-F401RE: https://www.st.com/en/evaluation-tools/nucleo-f401re.html -NUCLEO-L053R8: https://www.st.com/en/evaluation-tools/nucleo-l053r8.html -NUCLEO-L476RG: https://www.st.com/en/evaluation-tools/nucleo-l476rg.html -NUCLEO-WB15CC: https://www.st.com/en/evaluation-tools/nucleo-wb15cc.html -P-NUCLEO-WB55RG: https://www.st.com/en/evaluation-tools/p-nucleo-wb55.html -STEVAL-MKSBOX1V1: https://www.st.com/en/evaluation-tools/steval-mksbox1v1.html -STEVAL-MKBOXPRO: https://www.st.com/en/evaluation-tools/steval-mkboxpro.html -STM32L562E-DK: https://www.st.com/en/evaluation-tools/stm32l562e-dk.html -STM32WB5MM-DK: https://www.st.com/en/evaluation-tools/stm32wb5mm-dk.html -X-NUCLEO-BNRG2A1: https://www.st.com/en/ecosystems/x-nucleo-bnrg2a1.html -X-NUCLEO-IDB05A2: https://www.st.com/en/ecosystems/x-nucleo-idb05a2.html -X-NUCLEO-IDB05A1: https://www.st.com/en/ecosystems/x-nucleo-idb05a1.html +[B-L475E-IOT01A]: https://www.st.com/en/evaluation-tools/b-l475e-iot01a.html +[B-L4S5I-IOT01A]: https://www.st.com/en/evaluation-tools/b-l4s5i-iot01a.html +[NUCLEO-F401RE]: https://www.st.com/en/evaluation-tools/nucleo-f401re.html +[NUCLEO-L053R8]: https://www.st.com/en/evaluation-tools/nucleo-l053r8.html +[NUCLEO-L476RG]: https://www.st.com/en/evaluation-tools/nucleo-l476rg.html +[NUCLEO-WB15CC]: https://www.st.com/en/evaluation-tools/nucleo-wb15cc.html +[P-NUCLEO-WB55RG]: https://www.st.com/en/evaluation-tools/p-nucleo-wb55.html +[STEVAL-MKSBOX1V1]: https://www.st.com/en/evaluation-tools/steval-mksbox1v1.html +[STEVAL-MKBOXPRO]: https://www.st.com/en/evaluation-tools/steval-mkboxpro.html +[STM32L562E-DK]: https://www.st.com/en/evaluation-tools/stm32l562e-dk.html +[STM32WB5MM-DK]: https://www.st.com/en/evaluation-tools/stm32wb5mm-dk.html +[X-NUCLEO-BNRG2A1]: https://www.st.com/en/ecosystems/x-nucleo-bnrg2a1.html +[X-NUCLEO-IDB05A2]: https://www.st.com/en/ecosystems/x-nucleo-idb05a2.html +[X-NUCLEO-IDB05A1]: https://www.st.com/en/ecosystems/x-nucleo-idb05a1.html