Skip to content

Commit 0ec82e3

Browse files
committed
New debug management independent of monitoring
1 parent 829de7f commit 0ec82e3

File tree

10 files changed

+168
-128
lines changed

10 files changed

+168
-128
lines changed

src/BLDCMotor.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "BLDCMotor.h"
2+
#include "./communication/SimpleFOCDebug.h"
23

34
// BLDCMotor( int pp , float R)
45
// - pp - pole pair number

src/SimpleFOC.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,5 +114,6 @@ void loop() {
114114
#include "current_sense/GenericCurrentSense.h"
115115
#include "communication/Commander.h"
116116
#include "communication/StepDirListener.h"
117+
#include "communication/SimpleFOCDebug.h"
117118

118119
#endif

src/StepperMotor.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#include "StepperMotor.h"
2+
#include "./communication/SimpleFOCDebug.h"
3+
24

35
// StepperMotor(int pp)
46
// - pp - pole pair number

src/communication/SimpleFOCDebug.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,39 @@ void SimpleFOCDebug::println(const __FlashStringHelper* str, int val) {
5353
}
5454
}
5555

56+
57+
void SimpleFOCDebug::print(const char* str) {
58+
if (_debugPrint != NULL) {
59+
_debugPrint->print(str);
60+
}
61+
}
62+
63+
64+
void SimpleFOCDebug::print(const __FlashStringHelper* str) {
65+
if (_debugPrint != NULL) {
66+
_debugPrint->print(str);
67+
}
68+
}
69+
70+
71+
void SimpleFOCDebug::print(int val) {
72+
if (_debugPrint != NULL) {
73+
_debugPrint->print(val);
74+
}
75+
}
76+
77+
78+
void SimpleFOCDebug::print(float val) {
79+
if (_debugPrint != NULL) {
80+
_debugPrint->print(val);
81+
}
82+
}
83+
84+
85+
void SimpleFOCDebug::println() {
86+
if (_debugPrint != NULL) {
87+
_debugPrint->println();
88+
}
89+
}
90+
5691
#endif

src/communication/SimpleFOCDebug.h

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*
1717
* To produce debug output, use the macro SIMPLEFOC_DEBUG:
1818
* SIMPLEFOC_DEBUG("Debug message!");
19-
* SIMPLEFOC_DEBUG("a float value:", 123.456);
19+
* SIMPLEFOC_DEBUG("a float value:", 123.456f);
2020
* SIMPLEFOC_DEBUG("an integer value: ", 123);
2121
*
2222
* Keep debugging output short and simple. Some of our MCUs have limited
@@ -37,22 +37,28 @@
3737

3838
class SimpleFOCDebug {
3939
public:
40-
void enable(Print* debugPrint = Serial);
40+
static void enable(Print* debugPrint = &Serial);
4141

42-
void println(const __FlashStringHelper* msg);
43-
void println(const char* msg);
44-
void println(const __FlashStringHelper* msg, float val);
45-
void println(const char* msg, float val);
46-
void println(const __FlashStringHelper* msg, int val);
47-
void println(const char* msg, int val);
42+
static void println(const __FlashStringHelper* msg);
43+
static void println(const char* msg);
44+
static void println(const __FlashStringHelper* msg, float val);
45+
static void println(const char* msg, float val);
46+
static void println(const __FlashStringHelper* msg, int val);
47+
static void println(const char* msg, int val);
48+
static void println();
49+
50+
static void print(const char* msg);
51+
static void print(const __FlashStringHelper* msg);
52+
static void print(int val);
53+
static void print(float val);
4854

4955
protected:
5056
static Print* _debugPrint;
5157
};
5258

5359

5460
#define SIMPLEFOC_DEBUG(msg, ...) \
55-
SimpleFOCDebug::println(F(msg) __VA_OPT__(,) __VA_ARGS__)
61+
SimpleFOCDebug::println(F(msg), ##__VA_ARGS__)
5662

5763

5864

src/drivers/hardware_api.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
#include "../common/foc_utils.h"
55
#include "../common/time_utils.h"
6+
#include "../communication/SimpleFOCDebug.h"
7+
68

79
// flag returned if driver init fails
810
#define SIMPLEFOC_DRIVER_INIT_FAILED ((void*)-1)

src/drivers/hardware_specific/samd21_mcu.cpp

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ void configureSAMDClock() {
164164
while (GCLK->STATUS.bit.SYNCBUSY); // Wait for synchronization
165165

166166
#ifdef SIMPLEFOC_SAMD_DEBUG
167-
SIMPLEFOC_SAMD_DEBUG_SERIAL.println("Configured clock...");
167+
SIMPLEFOC_DEBUG("SAMD: Configured clock...");
168168
#endif
169169
}
170170
}
@@ -227,8 +227,7 @@ void configureTCC(tccConfiguration& tccConfig, long pwm_frequency, bool negate,
227227
tc->COUNT8.CTRLA.bit.ENABLE = 1;
228228
while ( tc->COUNT8.STATUS.bit.SYNCBUSY == 1 );
229229
#ifdef SIMPLEFOC_SAMD_DEBUG
230-
SIMPLEFOC_SAMD_DEBUG_SERIAL.print("Initialized TC ");
231-
SIMPLEFOC_SAMD_DEBUG_SERIAL.println(tccConfig.tcc.tccn);
230+
SIMPLEFOC_DEBUG("SAMD: Initialized TC ", tccConfig.tcc.tccn);
232231
#endif
233232
}
234233
else {
@@ -264,15 +263,16 @@ void configureTCC(tccConfiguration& tccConfig, long pwm_frequency, bool negate,
264263
tcc->CTRLA.reg |= TCC_CTRLA_ENABLE | TCC_CTRLA_PRESCALER_DIV1; //48Mhz/1=48Mhz/2(up/down)=24MHz/1024=24KHz
265264
while ( tcc->SYNCBUSY.bit.ENABLE == 1 ); // wait for sync
266265

267-
#ifdef SIMPLEFOC_SAMD_DEBUG
268-
SIMPLEFOC_SAMD_DEBUG_SERIAL.print(" Initialized TCC ");
269-
SIMPLEFOC_SAMD_DEBUG_SERIAL.print(tccConfig.tcc.tccn);
270-
SIMPLEFOC_SAMD_DEBUG_SERIAL.print("-");
271-
SIMPLEFOC_SAMD_DEBUG_SERIAL.print(tccConfig.tcc.chan);
272-
SIMPLEFOC_SAMD_DEBUG_SERIAL.print("[");
273-
SIMPLEFOC_SAMD_DEBUG_SERIAL.print(tccConfig.wo);
274-
SIMPLEFOC_SAMD_DEBUG_SERIAL.print("] pwm res ");
275-
SIMPLEFOC_SAMD_DEBUG_SERIAL.println(pwm_resolution);
266+
#if defined(SIMPLEFOC_SAMD_DEBUG) && !defined(SIMPLEFOC_DISABLE_DEBUG)
267+
SimpleFOCDebug::print("SAMD: Initialized TCC ");
268+
SimpleFOCDebug::print(tccConfig.tcc.tccn);
269+
SimpleFOCDebug::print("-");
270+
SimpleFOCDebug::print(tccConfig.tcc.chan);
271+
SimpleFOCDebug::print("[");
272+
SimpleFOCDebug::print(tccConfig.wo);
273+
SimpleFOCDebug::print("] pwm res ");
274+
SimpleFOCDebug::print((int)pwm_resolution);
275+
SimpleFOCDebug::println();
276276
#endif
277277
}
278278
}
@@ -298,15 +298,16 @@ void configureTCC(tccConfiguration& tccConfig, long pwm_frequency, bool negate,
298298
tcc->CTRLA.bit.ENABLE = 1;
299299
while ( tcc->SYNCBUSY.bit.ENABLE == 1 );
300300

301-
#ifdef SIMPLEFOC_SAMD_DEBUG
302-
SIMPLEFOC_SAMD_DEBUG_SERIAL.print("(Re-)Initialized TCC ");
303-
SIMPLEFOC_SAMD_DEBUG_SERIAL.print(tccConfig.tcc.tccn);
304-
SIMPLEFOC_SAMD_DEBUG_SERIAL.print("-");
305-
SIMPLEFOC_SAMD_DEBUG_SERIAL.print(tccConfig.tcc.chan);
306-
SIMPLEFOC_SAMD_DEBUG_SERIAL.print("[");
307-
SIMPLEFOC_SAMD_DEBUG_SERIAL.print(tccConfig.wo);
308-
SIMPLEFOC_SAMD_DEBUG_SERIAL.print("] pwm res ");
309-
SIMPLEFOC_SAMD_DEBUG_SERIAL.println(pwm_resolution);
301+
#if defined(SIMPLEFOC_SAMD_DEBUG) && !defined(SIMPLEFOC_DISABLE_DEBUG)
302+
SimpleFOCDebug::print("SAMD: (Re-)Initialized TCC ");
303+
SimpleFOCDebug::print(tccConfig.tcc.tccn);
304+
SimpleFOCDebug::print("-");
305+
SimpleFOCDebug::print(tccConfig.tcc.chan);
306+
SimpleFOCDebug::print("[");
307+
SimpleFOCDebug::print(tccConfig.wo);
308+
SimpleFOCDebug::print("] pwm res ");
309+
SimpleFOCDebug::print((int)pwm_resolution);
310+
SimpleFOCDebug::println();
310311
#endif
311312
}
312313

src/drivers/hardware_specific/samd51_mcu.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ void configureSAMDClock() {
190190
while (GCLK->SYNCBUSY.vec.GENCTRL&(0x1<<PWM_CLOCK_NUM));
191191

192192
#ifdef SIMPLEFOC_SAMD_DEBUG
193-
SIMPLEFOC_SAMD_DEBUG_SERIAL.println("Configured clock...");
193+
SIMPLEFOC_DEBUG("SAMD: Configured clock...");
194194
#endif
195195
}
196196
}
@@ -258,15 +258,16 @@ void configureTCC(tccConfiguration& tccConfig, long pwm_frequency, bool negate,
258258
tcc->CTRLA.reg |= TCC_CTRLA_ENABLE | TCC_CTRLA_PRESCALER_DIV1; //48Mhz/1=48Mhz/2(up/down)=24MHz/1024=24KHz
259259
while ( tcc->SYNCBUSY.bit.ENABLE == 1 ); // wait for sync
260260

261-
#ifdef SIMPLEFOC_SAMD_DEBUG
262-
SIMPLEFOC_SAMD_DEBUG_SERIAL.print("(Re-)Initialized TCC ");
263-
SIMPLEFOC_SAMD_DEBUG_SERIAL.print(tccConfig.tcc.tccn);
264-
SIMPLEFOC_SAMD_DEBUG_SERIAL.print("-");
265-
SIMPLEFOC_SAMD_DEBUG_SERIAL.print(tccConfig.tcc.chan);
266-
SIMPLEFOC_SAMD_DEBUG_SERIAL.print("[");
267-
SIMPLEFOC_SAMD_DEBUG_SERIAL.print(tccConfig.wo);
268-
SIMPLEFOC_SAMD_DEBUG_SERIAL.print("] pwm res ");
269-
SIMPLEFOC_SAMD_DEBUG_SERIAL.println(pwm_resolution);
261+
#if defined(SIMPLEFOC_SAMD_DEBUG) && !defined(SIMPLEFOC_DISABLE_DEBUG)
262+
SimpleFOCDebug::print("SAMD: (Re-)Initialized TCC ");
263+
SimpleFOCDebug::print(tccConfig.tcc.tccn);
264+
SimpleFOCDebug::print("-");
265+
SimpleFOCDebug::print(tccConfig.tcc.chan);
266+
SimpleFOCDebug::print("[");
267+
SimpleFOCDebug::print(tccConfig.wo);
268+
SimpleFOCDebug::print("] pwm res ");
269+
SimpleFOCDebug::print((int)pwm_resolution);
270+
SimpleFOCDebug::println();
270271
#endif
271272
}
272273
else if (tccConfig.tcc.tccn>=TCC_INST_NUM) {
@@ -292,9 +293,8 @@ void configureTCC(tccConfiguration& tccConfig, long pwm_frequency, bool negate,
292293
// while ( tc->COUNT8.STATUS.bit.SYNCBUSY == 1 );
293294

294295
#ifdef SIMPLEFOC_SAMD_DEBUG
295-
SIMPLEFOC_SAMD_DEBUG_SERIAL.print("Not initialized: TC ");
296-
SIMPLEFOC_SAMD_DEBUG_SERIAL.println(tccConfig.tcc.tccn);
297-
SIMPLEFOC_SAMD_DEBUG_SERIAL.print("TC units not supported on SAMD51");
296+
SIMPLEFOC_DEBUG("SAMD: Not initialized: TC ", tccConfig.tcc.tccn);
297+
SIMPLEFOC_DEBUG("SAMD: TC units not supported on SAMD51");
298298
#endif
299299
}
300300

0 commit comments

Comments
 (0)