Skip to content

Commit d519a31

Browse files
Merge pull request #48 from pennam/debug_optional
Make Arduino_DebugUtils optional
2 parents 619d5a9 + cde34da commit d519a31

5 files changed

+54
-11
lines changed

src/Arduino_Portenta_OTA.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
******************************************************************************/
2121

2222
#include "Arduino_Portenta_OTA.h"
23-
23+
#include "Arduino_Portenta_OTA_Debug.h"
2424
#include <stm32h7xx_hal_rtc_ex.h>
2525

2626
/******************************************************************************
@@ -143,15 +143,15 @@ bool Arduino_Portenta_OTA::caStorageInit()
143143
_bd_raw_qspi = mbed::BlockDevice::get_default_instance();
144144

145145
if (_bd_raw_qspi->init() != QSPIF_BD_ERROR_OK) {
146-
Debug.print(DBG_ERROR, F("Error: QSPI init failure."));
146+
DEBUG_ERROR(F("Error: QSPI init failure."));
147147
return false;
148148
}
149149

150150
mbed::MBRBlockDevice * cert_bd_qspi = new mbed::MBRBlockDevice(_bd_raw_qspi, 1);
151151
mbed::FATFileSystem * cert_fs_qspi = new mbed::FATFileSystem("wlan");
152152
int const err_mount = cert_fs_qspi->mount(cert_bd_qspi);
153153
if (err_mount) {
154-
Debug.print(DBG_ERROR, F("Error while mounting the certificate filesystem. Err = %d"), err_mount);
154+
DEBUG_ERROR(F("Error while mounting the certificate filesystem. Err = %d"), err_mount);
155155
return false;
156156
}
157157
return true;
@@ -161,7 +161,7 @@ bool Arduino_Portenta_OTA::caStorageOpen()
161161
{
162162
FILE* fp = fopen("/wlan/cacert.pem", "r");
163163
if (!fp) {
164-
Debug.print(DBG_ERROR, F("Error while opening the certificate file."));
164+
DEBUG_ERROR(F("Error while opening the certificate file."));
165165
return false;
166166
}
167167
fclose(fp);

src/Arduino_Portenta_OTA.h

-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
#include <MBRBlockDevice.h>
3636
#include <FATFileSystem.h>
3737
#include <LittleFileSystem.h>
38-
#include <Arduino_DebugUtils.h>
3938

4039
#include "WiFi.h" /* WiFi from ArduinoCore-mbed */
4140
#include <SocketHelpers.h>

src/Arduino_Portenta_OTA_Debug.h

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
This file is part of Arduino_Portenta_OTA.
3+
4+
Copyright 2024 ARDUINO SA (http://www.arduino.cc/)
5+
6+
This software is released under the GNU General Public License version 3,
7+
which covers the main part of arduino-cli.
8+
The terms of this license can be found at:
9+
https://www.gnu.org/licenses/gpl-3.0.en.html
10+
11+
You can be released from the requirements of the above licenses by purchasing
12+
a commercial license. Buying such a license is mandatory if you want to modify or
13+
otherwise use the software for commercial activities involving the Arduino
14+
software without disclosing the source code of your own applications. To purchase
15+
a commercial license, send an email to [email protected].
16+
*/
17+
18+
#ifndef ARDUINO_PORTENTA_OTA_DEBUG_H_
19+
#define ARDUINO_PORTENTA_OTA_DEBUG_H_
20+
21+
/******************************************************************************
22+
* INCLUDE
23+
******************************************************************************/
24+
25+
#if defined __has_include
26+
#if __has_include (<Arduino_DebugUtils.h>)
27+
#include <Arduino_DebugUtils.h>
28+
#else
29+
#define ARDUINO_PORTENTA_OTA_NO_DEBUG
30+
#endif
31+
#else
32+
#define ARDUINO_PORTENTA_OTA_NO_DEBUG
33+
#endif
34+
35+
#ifdef ARDUINO_PORTENTA_OTA_NO_DEBUG
36+
#define DEBUG_ERROR(fmt, ...) ((void)0)
37+
#define DEBUG_WARNING(fmt, ...) ((void)0)
38+
#define DEBUG_INFO(fmt, ...) ((void)0)
39+
#define DEBUG_DEBUG(fmt, ...) ((void)0)
40+
#define DEBUG_VERBOSE(fmt, ...) ((void)0)
41+
#endif
42+
#undef ARDUINO_PORTENTA_OTA_NO_DEBUG
43+
44+
#endif /* ARDUINO_PORTENTA_OTA_DEBUG_H_ */

src/Arduino_Portenta_OTA_QSPI.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#if defined(ARDUINO_PORTENTA_OTA_QSPI_SUPPORT)
2424

2525
#include "Arduino_Portenta_OTA_QSPI.h"
26-
26+
#include "Arduino_Portenta_OTA_Debug.h"
2727
#include <assert.h>
2828

2929
using namespace arduino;
@@ -52,7 +52,7 @@ bool Arduino_Portenta_OTA_QSPI::init()
5252
int const err_mount = _fs_qspi->mount(_bd_raw_qspi);
5353
if (err_mount)
5454
{
55-
Debug.print(DBG_ERROR, F("Error while mounting the filesystem. Err = %d"), err_mount);
55+
DEBUG_ERROR(F("Error while mounting the filesystem. Err = %d"), err_mount);
5656
return false;
5757
}
5858
return true;
@@ -64,7 +64,7 @@ bool Arduino_Portenta_OTA_QSPI::init()
6464
_fs_qspi = new mbed::FATFileSystem("fs");
6565
int const err_mount = _fs_qspi->mount(_bd_qspi);
6666
if (err_mount) {
67-
Debug.print(DBG_ERROR, F("Error while mounting the filesystem. Err = %d"), err_mount);
67+
DEBUG_ERROR(F("Error while mounting the filesystem. Err = %d"), err_mount);
6868
return false;
6969
}
7070
return true;

src/Arduino_Portenta_OTA_SD.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#if defined(ARDUINO_PORTENTA_OTA_SDMMC_SUPPORT)
2424

2525
#include "Arduino_Portenta_OTA_SD.h"
26-
26+
#include "Arduino_Portenta_OTA_Debug.h"
2727
#include "BSP.h"
2828
#include "stm32h7xx_hal_sd.h"
2929

@@ -61,7 +61,7 @@ bool Arduino_Portenta_OTA_SD::init()
6161
_fs_sd = new mbed::FATFileSystem("fs");
6262
int const err = _fs_sd->mount(&_block_device);
6363
if (err) {
64-
Debug.print(DBG_ERROR, F("Error while mounting the filesystem. Err = %d"), err);
64+
DEBUG_ERROR(F("Error while mounting the filesystem. Err = %d"), err);
6565
return false;
6666
}
6767
return true;
@@ -74,7 +74,7 @@ bool Arduino_Portenta_OTA_SD::init()
7474
int const err = _fs_sd->mount(_bd);
7575
if (err)
7676
{
77-
Debug.print(DBG_ERROR, F("Error while mounting the filesystem. Err = %d"), err);
77+
DEBUG_ERROR(F("Error while mounting the filesystem. Err = %d"), err);
7878
return false;
7979
}
8080
return true;

0 commit comments

Comments
 (0)