From d21ad833341d38d2d0f823fabeaed26d0c5001f3 Mon Sep 17 00:00:00 2001 From: Zhu Qi Date: Tue, 1 Aug 2023 11:44:00 +0800 Subject: [PATCH] Fix BLE stack overflow when compiling with standard printf enabled --- .../BLEBatteryService/BLEBatteryService.ino | 15 +++++++-- .../BLEUartService/BLEUartService.ino | 21 +++++++++--- .../DHT_over_BLEUart/DHT_over_BLEUart.ino | 17 +++++++--- .../PWM_over_BLEUart/PWM_over_BLEUart.ino | 32 +++++++++++++++---- 4 files changed, 66 insertions(+), 19 deletions(-) diff --git a/Arduino_package/hardware/libraries/BLE/examples/BLEBatteryService/BLEBatteryService.ino b/Arduino_package/hardware/libraries/BLE/examples/BLEBatteryService/BLEBatteryService.ino index 78d32bb5..2150ac05 100644 --- a/Arduino_package/hardware/libraries/BLE/examples/BLEBatteryService/BLEBatteryService.ino +++ b/Arduino_package/hardware/libraries/BLE/examples/BLEBatteryService/BLEBatteryService.ino @@ -17,18 +17,27 @@ uint8_t battlevel = 0; bool notify = false; void readCB (BLECharacteristic* chr, uint8_t connID) { - printf("Characteristic %s read by connection %d \n", chr->getUUID().str(), connID); + //printf("Characteristic %s read by connection %d \n", chr->getUUID().str(), connID); + Serial.print("Characteristic "); + Serial.print(chr->getUUID().str()); + Serial.print(" read by connection "); + Serial.println(connID); chr->writeData8(90); } void notifCB (BLECharacteristic* chr, uint8_t connID, uint16_t cccd) { if (cccd & GATT_CLIENT_CHAR_CONFIG_NOTIFY) { - printf("Notifications enabled on Characteristic %s for connection %d \n", chr->getUUID().str(), connID); + //printf("Notifications enabled on Characteristic %s for connection %d \n", chr->getUUID().str(), connID); + Serial.print("Notifications enabled on Characteristic"); notify = true; } else { - printf("Notifications disabled on Characteristic %s for connection %d \n", chr->getUUID().str(), connID); + //printf("Notifications disabled on Characteristic %s for connection %d \n", chr->getUUID().str(), connID); + Serial.print("Notifications disabled on Characteristic"); notify = false; } + Serial.print(chr->getUUID().str()); + Serial.print(" for connection"); + Serial.println(connID); } void setup() { diff --git a/Arduino_package/hardware/libraries/BLE/examples/BLEUartService/BLEUartService.ino b/Arduino_package/hardware/libraries/BLE/examples/BLEUartService/BLEUartService.ino index 5e02ee23..1ca2b87a 100644 --- a/Arduino_package/hardware/libraries/BLE/examples/BLEUartService/BLEUartService.ino +++ b/Arduino_package/hardware/libraries/BLE/examples/BLEUartService/BLEUartService.ino @@ -20,11 +20,17 @@ BLEAdvertData scndata; bool notify = false; void readCB (BLECharacteristic* chr, uint8_t connID) { - printf("Characteristic %s read by connection %d \n", chr->getUUID().str(), connID); + Serial.print("Characteristic "); + Serial.print(chr->getUUID().str()); + Serial.print(" read by connection "); + Serial.println(connID); } void writeCB (BLECharacteristic* chr, uint8_t connID) { - printf("Characteristic %s write by connection %d :\n", chr->getUUID().str(), connID); + Serial.print("Characteristic "); + Serial.print(chr->getUUID().str()); + Serial.print(" write by connection "); + Serial.println(connID); if (chr->getDataLen() > 0) { Serial.print("Received string: "); Serial.print(chr->readString()); @@ -32,14 +38,19 @@ void writeCB (BLECharacteristic* chr, uint8_t connID) { } } -void notifCB (BLECharacteristic* chr, uint8_t connID, uint16_t cccd) { +void notifCB(BLECharacteristic* chr, uint8_t connID, uint16_t cccd) { if (cccd & GATT_CLIENT_CHAR_CONFIG_NOTIFY) { - printf("Notifications enabled on Characteristic %s for connection %d \n", chr->getUUID().str(), connID); + //printf("Notifications enabled on Characteristic %s for connection %d \n", chr->getUUID().str(), connID); + Serial.print("Notifications enabled on Characteristic"); notify = true; } else { - printf("Notifications disabled on Characteristic %s for connection %d \n", chr->getUUID().str(), connID); + //printf("Notifications disabled on Characteristic %s for connection %d \n", chr->getUUID().str(), connID); + Serial.print("Notifications disabled on Characteristic"); notify = false; } + Serial.print(chr->getUUID().str()); + Serial.print(" for connection"); + Serial.println(connID); } void setup() { diff --git a/Arduino_package/hardware/libraries/BLE/examples/DHT_over_BLEUart/DHT_over_BLEUart.ino b/Arduino_package/hardware/libraries/BLE/examples/DHT_over_BLEUart/DHT_over_BLEUart.ino index afe261a5..dd24d129 100644 --- a/Arduino_package/hardware/libraries/BLE/examples/DHT_over_BLEUart/DHT_over_BLEUart.ino +++ b/Arduino_package/hardware/libraries/BLE/examples/DHT_over_BLEUart/DHT_over_BLEUart.ino @@ -31,7 +31,11 @@ BLEAdvertData scndata; bool notify = false; void writeCB (BLECharacteristic* chr, uint8_t connID) { - printf("Characteristic %s write by connection %d :\n", chr->getUUID().str(), connID); + //printf("Characteristic %s write by connection %d :\n", chr->getUUID().str(), connID); + Serial.print("Characteristic "); + Serial.print(chr->getUUID().str()); + Serial.print(" write by connection "); + Serial.println(connID); if (chr->getDataLen() > 0) { Serial.print("Received string: "); Serial.print(chr->readString()); @@ -39,14 +43,19 @@ void writeCB (BLECharacteristic* chr, uint8_t connID) { } } -void notifCB (BLECharacteristic* chr, uint8_t connID, uint16_t cccd) { +void notifCB(BLECharacteristic* chr, uint8_t connID, uint16_t cccd) { if (cccd & GATT_CLIENT_CHAR_CONFIG_NOTIFY) { - printf("Notifications enabled on Characteristic %s for connection %d \n", chr->getUUID().str(), connID); + //printf("Notifications enabled on Characteristic %s for connection %d \n", chr->getUUID().str(), connID); + Serial.print("Notifications enabled on Characteristic"); notify = true; } else { - printf("Notifications disabled on Characteristic %s for connection %d \n", chr->getUUID().str(), connID); + //printf("Notifications disabled on Characteristic %s for connection %d \n", chr->getUUID().str(), connID); + Serial.print("Notifications disabled on Characteristic"); notify = false; } + Serial.print(chr->getUUID().str()); + Serial.print(" for connection"); + Serial.println(connID); } void setup() { diff --git a/Arduino_package/hardware/libraries/BLE/examples/PWM_over_BLEUart/PWM_over_BLEUart.ino b/Arduino_package/hardware/libraries/BLE/examples/PWM_over_BLEUart/PWM_over_BLEUart.ino index 3a761a18..cc828aae 100644 --- a/Arduino_package/hardware/libraries/BLE/examples/PWM_over_BLEUart/PWM_over_BLEUart.ino +++ b/Arduino_package/hardware/libraries/BLE/examples/PWM_over_BLEUart/PWM_over_BLEUart.ino @@ -29,19 +29,31 @@ BLEAdvertData scndata; bool notify = false; void readCB (BLECharacteristic* chr, uint8_t connID) { - printf("Characteristic %s read by connection %d \n", chr->getUUID().str(), connID); + Serial.print("Characteristic "); + Serial.print(chr->getUUID().str()); + Serial.print(" read by connection "); + Serial.println(connID); } void writeCB (BLECharacteristic* chr, uint8_t connID) { - printf("Characteristic %s write by connection %d :\n", chr->getUUID().str(), connID); + Serial.print("Characteristic "); + Serial.print(chr->getUUID().str()); + Serial.print(" write by connection "); + Serial.println(connID); uint16_t datalen = chr->getDataLen(); if (datalen > 0) { if (chr->readData8() == '!') { uint8_t command[datalen]; chr->getData(command, datalen); if (command[1] == 'C') { + Serial.print("Color command R = "); + Serial.print(command[2]); + Serial.print(" G = "); + Serial.print(command[3]); + Serial.print(" B = "); + Serial.println(command[4]); // print hex - printf("Color command R = %x G = %x B = %x \n", command[2], command[3], command[4]); + //printf("Color command R = %x G = %x B = %x \n", command[2], command[3], command[4]); // print decimal //printf("Color command R = %d G = %d B = %d \n", command[2], command[3], command[4]); #if defined(CathodeRGB) @@ -53,7 +65,8 @@ void writeCB (BLECharacteristic* chr, uint8_t connID) { analogWrite(LED_GRN, (255 - command[3])); analogWrite(LED_BLU, (255 - command[4])); #else - printf("Error, please choose the RGB LED type \n"); + //printf("Error, please choose the RGB LED type \n"); + Serial.println("Error, please choose the RGB LED type"); #endif } } else { @@ -64,14 +77,19 @@ void writeCB (BLECharacteristic* chr, uint8_t connID) { } } -void notifCB (BLECharacteristic* chr, uint8_t connID, uint16_t cccd) { +void notifCB(BLECharacteristic* chr, uint8_t connID, uint16_t cccd) { if (cccd & GATT_CLIENT_CHAR_CONFIG_NOTIFY) { - printf("Notifications enabled on Characteristic %s for connection %d \n", chr->getUUID().str(), connID); + //printf("Notifications enabled on Characteristic %s for connection %d \n", chr->getUUID().str(), connID); + Serial.print("Notifications enabled on Characteristic"); notify = true; } else { - printf("Notifications disabled on Characteristic %s for connection %d \n", chr->getUUID().str(), connID); + //printf("Notifications disabled on Characteristic %s for connection %d \n", chr->getUUID().str(), connID); + Serial.print("Notifications disabled on Characteristic"); notify = false; } + Serial.print(chr->getUUID().str()); + Serial.print(" for connection"); + Serial.println(connID); } void setup() {