Skip to content

Commit 8acdb60

Browse files
authored
Merge branch 'master' into develop
2 parents e33fa24 + 0a7d94e commit 8acdb60

File tree

10 files changed

+129
-113
lines changed

10 files changed

+129
-113
lines changed

cores/nRF5/common_func.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,13 @@
116116
//--------------------------------------------------------------------+
117117
const char* dbg_err_str(int32_t err_id); // TODO move to other place
118118

119+
#if __cplusplus
120+
#define PRINTF ::printf
121+
#else
122+
#define PRINTF printf
123+
#endif
124+
125+
119126
#if CFG_DEBUG
120127
#define LOG_LV1(...) ADALOG(__VA_ARGS__)
121128
#define LOG_LV1_BUFFER(...) ADALOG_BUFFER(__VA_ARGS__)
@@ -134,15 +141,9 @@ const char* dbg_err_str(int32_t err_id); // TODO move to other place
134141

135142
#if CFG_DEBUG
136143

137-
#if __cplusplus
138-
#define PRINTF ::printf
139-
#else
140-
#define PRINTF printf
141-
#endif
142-
143144
#define PRINT_LOCATION() PRINTF("%s: %d:\n", __PRETTY_FUNCTION__, __LINE__)
144145
#define PRINT_MESS(x) PRINTF("%s: %d: %s \n" , __FUNCTION__, __LINE__, (char*)(x))
145-
#define PRTNT_HEAP() if (CFG_DEBUG == 3) PRINTF("\n%s: %d: Heap free: %d\n", __FUNCTION__, __LINE__, util_heap_get_free_size())
146+
#define PRTNT_HEAP() if (CFG_DEBUG >= 3) PRINTF("\n%s: %d: Heap free: %d\n", __FUNCTION__, __LINE__, util_heap_get_free_size())
146147
#define PRINT_STR(x) PRINTF("%s: %d: " #x " = %s\n" , __FUNCTION__, __LINE__, (char*)(x) )
147148
#define PRINT_INT(x) PRINTF("%s: %d: " #x " = %ld\n" , __FUNCTION__, __LINE__, (uint32_t) (x) )
148149
#define PRINT_FLOAT(x) PRINTF("%s: %d: " #x " = %f\n" , __FUNCTION__, __LINE__, (float) (x) )

cores/nRF5/utility/debug.cpp

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include <malloc.h>
4040
#include <Arduino.h>
4141
#include <ctype.h>
42+
#include <common_func.h>
4243

4344
// defined in linker script
4445
extern uint32_t __data_start__[];
@@ -106,14 +107,14 @@ static void printMemRegion(const char* name, uint32_t top, uint32_t bottom, uint
106107
sprintf(buffer, "%lu", top-bottom);
107108
}
108109

109-
printf("| %-5s| 0x%04X - 0x%04X | %-19s |\n", name, (uint16_t) bottom, (uint16_t) (top-1), buffer);
110+
PRINTF("| %-5s| 0x%04X - 0x%04X | %-19s |\n", name, (uint16_t) bottom, (uint16_t) (top-1), buffer);
110111
}
111112

112113
void dbgMemInfo(void)
113114
{
114-
printf(" ______________________________________________\n");
115-
printf("| Name | Addr 0x2000xxxx | Usage |\n");
116-
printf("| ---------------------------------------------|\n");
115+
PRINTF(" ______________________________________________\n");
116+
PRINTF("| Name | Addr 0x2000xxxx | Usage |\n");
117+
PRINTF("| ---------------------------------------------|\n");
117118

118119
// Pritn SRAM used for Stack executed by Softdevice and ISR
119120
printMemRegion("Stack", ((uint32_t) __StackTop), ((uint32_t) __StackLimit), dbgStackUsed() );
@@ -127,29 +128,29 @@ void dbgMemInfo(void)
127128
// Print SRAM Used by SoftDevice
128129
printMemRegion("SD", (uint32_t) __data_start__, 0x20000000, 0);
129130

130-
printf("|______________________________________________|\n");
131-
printf("\n");
131+
PRINTF("|______________________________________________|\n");
132+
PRINTF("\n");
132133

133134
// Print Task list
134135
uint32_t tasknum = uxTaskGetNumberOfTasks();
135136
char* buf = (char*) rtos_malloc(tasknum*40); // 40 bytes per task
136137

137138
vTaskList(buf);
138139

139-
printf("Task State Prio StackLeft Num\n");
140-
printf("-----------------------------------\n");
141-
printf(buf);
142-
printf("\n");
140+
PRINTF("Task State Prio StackLeft Num\n");
141+
PRINTF("-----------------------------------\n");
142+
PRINTF(buf);
143+
PRINTF("\n");
143144
rtos_free(buf);
144145
}
145146

146147
void dbgPrintVersion(void)
147148
{
148-
printf("\n");
149-
printf("BSP Library : " ARDUINO_BSP_VERSION "\n");
150-
printf("Bootloader : %s\n", getBootloaderVersion());
151-
printf("Serial No : %s\n", getMcuUniqueID());
152-
printf("\n");
149+
PRINTF("\n");
150+
PRINTF("BSP Library : " ARDUINO_BSP_VERSION "\n");
151+
PRINTF("Bootloader : %s\n", getBootloaderVersion());
152+
PRINTF("Serial No : %s\n", getMcuUniqueID());
153+
PRINTF("\n");
153154
}
154155

155156
/******************************************************************************/
@@ -163,15 +164,15 @@ static void dump_str_line(uint8_t const* buf, uint16_t count)
163164
for(int i=0; i<count; i++)
164165
{
165166
const char ch = buf[i];
166-
printf("%c", isprint(ch) ? ch : '.');
167+
PRINTF("%c", isprint(ch) ? ch : '.');
167168
}
168169
}
169170

170171
void dbgDumpMemory(void const *buf, uint8_t size, uint16_t count, bool printOffset)
171172
{
172173
if ( !buf || !count )
173174
{
174-
printf("NULL\n");
175+
PRINTF("NULL\n");
175176
return;
176177
}
177178

@@ -191,26 +192,26 @@ void dbgDumpMemory(void const *buf, uint8_t size, uint16_t count, bool printOffs
191192
// Print Ascii
192193
if ( i != 0 )
193194
{
194-
printf(" | ");
195+
PRINTF(" | ");
195196
dump_str_line(buf8-16, 16);
196-
printf("\n");
197+
PRINTF("\n");
197198
}
198199

199200
// print offset or absolute address
200201
if (printOffset)
201202
{
202-
printf("%03lX: ", 16*i/item_per_line);
203+
PRINTF("%03lX: ", 16*i/item_per_line);
203204
}else
204205
{
205-
printf("%08lX:", (uint32_t) buf8);
206+
PRINTF("%08lX:", (uint32_t) buf8);
206207
}
207208
}
208209

209210
memcpy(&value, buf8, size);
210211
buf8 += size;
211212

212-
printf(" ");
213-
printf(format, value);
213+
PRINTF(" ");
214+
PRINTF(format, value);
214215
}
215216

216217
// fill up last row to 16 for printing ascii
@@ -221,46 +222,46 @@ void dbgDumpMemory(void const *buf, uint8_t size, uint16_t count, bool printOffs
221222
{
222223
for(int i=0; i< 16-remain; i++)
223224
{
224-
printf(" ");
225-
for(int j=0; j<2*size; j++) printf(" ");
225+
PRINTF(" ");
226+
for(int j=0; j<2*size; j++) PRINTF(" ");
226227
}
227228
}
228229

229-
printf(" | ");
230+
PRINTF(" | ");
230231
dump_str_line(buf8-nback, nback);
231-
printf("\n");
232+
PRINTF("\n");
232233

233-
printf("\n");
234+
PRINTF("\n");
234235
}
235236

236237

237238
void dbgDumpMemoryCFormat(const char* str, void const *buf, uint16_t count)
238239
{
239240
if ( !buf )
240241
{
241-
printf("NULL\n");
242+
PRINTF("NULL\n");
242243
return;
243244
}
244245

245-
printf("%s = \n{\n ", str);
246+
PRINTF("%s = \n{\n ", str);
246247

247248
uint8_t const *buf8 = (uint8_t const *) buf;
248249

249250
for(uint32_t i=0; i<count; i++)
250251
{
251252
if ( i%16 == 0 )
252253
{
253-
if ( i != 0 ) printf(",\n ");
254+
if ( i != 0 ) PRINTF(",\n ");
254255
}else
255256
{
256-
if ( i != 0 ) printf(", ");
257+
if ( i != 0 ) PRINTF(", ");
257258
}
258259

259-
printf("0x%02X", *buf8);
260+
PRINTF("0x%02X", *buf8);
260261
buf8++;
261262
}
262263

263-
printf("\n};\n");
264+
PRINTF("\n};\n");
264265
}
265266

266267

cores/nRF5/verify.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,16 @@ extern "C"
6060
#define VERIFY_MESS(_status, _functstr) VERIFY_MESS_impl(_status, _functstr, __PRETTY_FUNCTION__, __LINE__)
6161
static inline void VERIFY_MESS_impl(int32_t _status, const char* (*_fstr)(int32_t), const char* func_name, int line_number)
6262
{
63-
printf("%s: %d: verify failed, error = ", func_name, line_number);
63+
PRINTF("%s: %d: verify failed, error = ", func_name, line_number);
6464
if (_fstr && _fstr(_status))
6565
{
66-
printf(_fstr(_status));
66+
PRINTF(_fstr(_status));
6767
}
6868
else
6969
{
70-
printf("0x%lX (%ld)", _status, _status);
70+
PRINTF("0x%lX (%ld)", _status, _status);
7171
}
72-
printf("\n");
72+
PRINTF("\n");
7373
}
7474
#else
7575
#define VERIFY_MESS(_status, _funcstr)

libraries/Adafruit_LittleFS/src/littlefs/lfs_util.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,21 @@ extern "C"
5656
// Logging functions
5757
#ifndef LFS_NO_DEBUG
5858
#define LFS_DEBUG(fmt, ...) \
59-
printf("lfs debug:%d: " fmt "\n", __LINE__, __VA_ARGS__)
59+
PRINTF("lfs debug:%d: " fmt "\n", __LINE__, __VA_ARGS__)
6060
#else
6161
#define LFS_DEBUG(fmt, ...)
6262
#endif
6363

6464
#ifndef LFS_NO_WARN
6565
#define LFS_WARN(fmt, ...) \
66-
printf("lfs warn:%d: " fmt "\n", __LINE__, __VA_ARGS__)
66+
PRINTF("lfs warn:%d: " fmt "\n", __LINE__, __VA_ARGS__)
6767
#else
6868
#define LFS_WARN(fmt, ...)
6969
#endif
7070

7171
#ifndef LFS_NO_ERROR
7272
#define LFS_ERROR(fmt, ...) \
73-
printf("lfs error:%d: " fmt "\n", __LINE__, __VA_ARGS__)
73+
PRINTF("lfs error:%d: " fmt "\n", __LINE__, __VA_ARGS__)
7474
#else
7575
#define LFS_ERROR(fmt, ...)
7676
#endif

libraries/BLEAdafruitService/src/services/BLEAdafruitQuaternion.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,9 @@ void BLEAdafruitQuaternion::_update_timer(int32_t ms)
134134
#if CFG_DEBUG
135135
static void print_quaternion(float quater[4])
136136
{
137-
Serial.printf("Quaternion: %.04f, %.04f, %.04f, %.04f\n", quater[0], quater[1], quater[2], quater[3]);
137+
// prepare for ability to change output, based on compile-time flags
138+
Print& logger = Serial;
139+
logger.printf("Quaternion: %.04f, %.04f, %.04f, %.04f\n", quater[0], quater[1], quater[2], quater[3]);
138140
}
139141
#endif
140142

libraries/Bluefruit52Lib/src/BLEPeriph.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -154,14 +154,16 @@ void BLEPeriph::_eventHandler(ble_evt_t* evt)
154154
void BLEPeriph::printInfo(void)
155155
{
156156
char const * title_fmt = "%-16s: ";
157+
// prepare for ability to change output, based on compile-time flags
158+
Print& logger = Serial;
157159

158-
Serial.printf(title_fmt, "Conn Intervals");
159-
Serial.printf("min = %.2f ms, ", _ppcp.min_conn_interval*1.25f);
160-
Serial.printf("max = %.2f ms", _ppcp.max_conn_interval*1.25f);
161-
Serial.println();
160+
logger.printf(title_fmt, "Conn Intervals");
161+
logger.printf("min = %.2f ms, ", _ppcp.min_conn_interval*1.25f);
162+
logger.printf("max = %.2f ms", _ppcp.max_conn_interval*1.25f);
163+
logger.println();
162164

163-
Serial.printf(title_fmt, "Conn Timeout");
164-
Serial.printf("%d ms", _ppcp.conn_sup_timeout*10);
165-
Serial.println();
165+
logger.printf(title_fmt, "Conn Timeout");
166+
logger.printf("%d ms", _ppcp.conn_sup_timeout*10);
167+
logger.println();
166168
}
167169

0 commit comments

Comments
 (0)