From 48e8c8d361f886ba8e630557428089d2ead852e8 Mon Sep 17 00:00:00 2001 From: pennam Date: Mon, 22 Jan 2024 09:47:33 +0100 Subject: [PATCH 1/2] Make Arduino_DebugUtils optional --- src/Arduino_Portenta_OTA.cpp | 8 +++--- src/Arduino_Portenta_OTA.h | 1 - src/Arduino_Portenta_OTA_Debug.h | 43 +++++++++++++++++++++++++++++++ src/Arduino_Portenta_OTA_QSPI.cpp | 6 ++--- src/Arduino_Portenta_OTA_SD.cpp | 6 ++--- 5 files changed, 53 insertions(+), 11 deletions(-) create mode 100644 src/Arduino_Portenta_OTA_Debug.h diff --git a/src/Arduino_Portenta_OTA.cpp b/src/Arduino_Portenta_OTA.cpp index 0284261..639001c 100644 --- a/src/Arduino_Portenta_OTA.cpp +++ b/src/Arduino_Portenta_OTA.cpp @@ -20,7 +20,7 @@ ******************************************************************************/ #include "Arduino_Portenta_OTA.h" - +#include "Arduino_Portenta_OTA_Debug.h" #include /****************************************************************************** @@ -143,7 +143,7 @@ bool Arduino_Portenta_OTA::caStorageInit() _bd_raw_qspi = mbed::BlockDevice::get_default_instance(); if (_bd_raw_qspi->init() != QSPIF_BD_ERROR_OK) { - Debug.print(DBG_ERROR, F("Error: QSPI init failure.")); + DEBUG_ERROR(F("Error: QSPI init failure.")); return false; } @@ -151,7 +151,7 @@ bool Arduino_Portenta_OTA::caStorageInit() mbed::FATFileSystem * cert_fs_qspi = new mbed::FATFileSystem("wlan"); int const err_mount = cert_fs_qspi->mount(cert_bd_qspi); if (err_mount) { - Debug.print(DBG_ERROR, F("Error while mounting the certificate filesystem. Err = %d"), err_mount); + DEBUG_ERROR(F("Error while mounting the certificate filesystem. Err = %d"), err_mount); return false; } return true; @@ -161,7 +161,7 @@ bool Arduino_Portenta_OTA::caStorageOpen() { FILE* fp = fopen("/wlan/cacert.pem", "r"); if (!fp) { - Debug.print(DBG_ERROR, F("Error while opening the certificate file.")); + DEBUG_ERROR(F("Error while opening the certificate file.")); return false; } fclose(fp); diff --git a/src/Arduino_Portenta_OTA.h b/src/Arduino_Portenta_OTA.h index 8a1a524..824cd64 100644 --- a/src/Arduino_Portenta_OTA.h +++ b/src/Arduino_Portenta_OTA.h @@ -35,7 +35,6 @@ #include #include #include -#include #include "WiFi.h" /* WiFi from ArduinoCore-mbed */ #include diff --git a/src/Arduino_Portenta_OTA_Debug.h b/src/Arduino_Portenta_OTA_Debug.h new file mode 100644 index 0000000..870754b --- /dev/null +++ b/src/Arduino_Portenta_OTA_Debug.h @@ -0,0 +1,43 @@ +/* + This file is part of Arduino_Portenta_OTA. + + Copyright 2024 ARDUINO SA (http://www.arduino.cc/) + + This software is released under the GNU General Public License version 3, + which covers the main part of arduino-cli. + The terms of this license can be found at: + https://www.gnu.org/licenses/gpl-3.0.en.html + + You can be released from the requirements of the above licenses by purchasing + a commercial license. Buying such a license is mandatory if you want to modify or + otherwise use the software for commercial activities involving the Arduino + software without disclosing the source code of your own applications. To purchase + a commercial license, send an email to license@arduino.cc. +*/ + +#ifndef ARDUINO_PORTENTA_OTA_DEBUG_H_ +#define ARDUINO_PORTENTA_OTA_DEBUG_H_ + +/****************************************************************************** + * INCLUDE + ******************************************************************************/ + +#if defined __has_include + #if __has_include () + #include + #else + #define DEBUG_ERROR(fmt, ...) + #define DEBUG_WARNING(fmt, ...) + #define DEBUG_INFO(fmt, ...) + #define DEBUG_DEBUG(fmt, ...) + #define DEBUG_VERBOSE(fmt, ...) + #endif +#else + #define DEBUG_ERROR(fmt, ...) + #define DEBUG_WARNING(fmt, ...) + #define DEBUG_INFO(fmt, ...) + #define DEBUG_DEBUG(fmt, ...) + #define DEBUG_VERBOSE(fmt, ...) +#endif + +#endif /* ARDUINO_PORTENTA_OTA_DEBUG_H_ */ diff --git a/src/Arduino_Portenta_OTA_QSPI.cpp b/src/Arduino_Portenta_OTA_QSPI.cpp index 16f309c..17cd36b 100644 --- a/src/Arduino_Portenta_OTA_QSPI.cpp +++ b/src/Arduino_Portenta_OTA_QSPI.cpp @@ -23,7 +23,7 @@ #if defined(ARDUINO_PORTENTA_OTA_QSPI_SUPPORT) #include "Arduino_Portenta_OTA_QSPI.h" - +#include "Arduino_Portenta_OTA_Debug.h" #include using namespace arduino; @@ -52,7 +52,7 @@ bool Arduino_Portenta_OTA_QSPI::init() int const err_mount = _fs_qspi->mount(_bd_raw_qspi); if (err_mount) { - Debug.print(DBG_ERROR, F("Error while mounting the filesystem. Err = %d"), err_mount); + DEBUG_ERROR(F("Error while mounting the filesystem. Err = %d"), err_mount); return false; } return true; @@ -64,7 +64,7 @@ bool Arduino_Portenta_OTA_QSPI::init() _fs_qspi = new mbed::FATFileSystem("fs"); int const err_mount = _fs_qspi->mount(_bd_qspi); if (err_mount) { - Debug.print(DBG_ERROR, F("Error while mounting the filesystem. Err = %d"), err_mount); + DEBUG_ERROR(F("Error while mounting the filesystem. Err = %d"), err_mount); return false; } return true; diff --git a/src/Arduino_Portenta_OTA_SD.cpp b/src/Arduino_Portenta_OTA_SD.cpp index 0232078..ba7ee6a 100644 --- a/src/Arduino_Portenta_OTA_SD.cpp +++ b/src/Arduino_Portenta_OTA_SD.cpp @@ -23,7 +23,7 @@ #if defined(ARDUINO_PORTENTA_OTA_SDMMC_SUPPORT) #include "Arduino_Portenta_OTA_SD.h" - +#include "Arduino_Portenta_OTA_Debug.h" #include "BSP.h" #include "stm32h7xx_hal_sd.h" @@ -61,7 +61,7 @@ bool Arduino_Portenta_OTA_SD::init() _fs_sd = new mbed::FATFileSystem("fs"); int const err = _fs_sd->mount(&_block_device); if (err) { - Debug.print(DBG_ERROR, F("Error while mounting the filesystem. Err = %d"), err); + DEBUG_ERROR(F("Error while mounting the filesystem. Err = %d"), err); return false; } return true; @@ -74,7 +74,7 @@ bool Arduino_Portenta_OTA_SD::init() int const err = _fs_sd->mount(_bd); if (err) { - Debug.print(DBG_ERROR, F("Error while mounting the filesystem. Err = %d"), err); + DEBUG_ERROR(F("Error while mounting the filesystem. Err = %d"), err); return false; } return true; From cde34da076129dc46b8a9764a31529617a530716 Mon Sep 17 00:00:00 2001 From: Andrea Gilardoni <4046444+andreagilardoni@users.noreply.github.com> Date: Tue, 13 Feb 2024 11:23:33 +0100 Subject: [PATCH 2/2] Imrpove DEBUG macro definitions - avoid redundant definition - incorporate a noop to avoid issues --- src/Arduino_Portenta_OTA_Debug.h | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/Arduino_Portenta_OTA_Debug.h b/src/Arduino_Portenta_OTA_Debug.h index 870754b..c37e6ef 100644 --- a/src/Arduino_Portenta_OTA_Debug.h +++ b/src/Arduino_Portenta_OTA_Debug.h @@ -26,18 +26,19 @@ #if __has_include () #include #else - #define DEBUG_ERROR(fmt, ...) - #define DEBUG_WARNING(fmt, ...) - #define DEBUG_INFO(fmt, ...) - #define DEBUG_DEBUG(fmt, ...) - #define DEBUG_VERBOSE(fmt, ...) + #define ARDUINO_PORTENTA_OTA_NO_DEBUG #endif #else - #define DEBUG_ERROR(fmt, ...) - #define DEBUG_WARNING(fmt, ...) - #define DEBUG_INFO(fmt, ...) - #define DEBUG_DEBUG(fmt, ...) - #define DEBUG_VERBOSE(fmt, ...) + #define ARDUINO_PORTENTA_OTA_NO_DEBUG +#endif + +#ifdef ARDUINO_PORTENTA_OTA_NO_DEBUG + #define DEBUG_ERROR(fmt, ...) ((void)0) + #define DEBUG_WARNING(fmt, ...) ((void)0) + #define DEBUG_INFO(fmt, ...) ((void)0) + #define DEBUG_DEBUG(fmt, ...) ((void)0) + #define DEBUG_VERBOSE(fmt, ...) ((void)0) #endif +#undef ARDUINO_PORTENTA_OTA_NO_DEBUG #endif /* ARDUINO_PORTENTA_OTA_DEBUG_H_ */