Skip to content

Commit edea529

Browse files
committed
update debug functions
1 parent bc19796 commit edea529

File tree

6 files changed

+55
-47
lines changed

6 files changed

+55
-47
lines changed

cores/nRF5/debug.cpp

+42-39
Original file line numberDiff line numberDiff line change
@@ -54,30 +54,30 @@ extern uint32_t __StackLimit[];
5454

5555
extern "C"
5656
{
57-
int cprintf(const char * format, ...)
58-
{
59-
char buf[256];
60-
int len;
6157

62-
va_list ap;
63-
va_start(ap, format);
58+
int cprintf(const char * format, ...)
59+
{
60+
char buf[256];
61+
int len;
6462

65-
len = vsnprintf(buf, 256, format, ap);
66-
Serial.write(buf, len);
63+
va_list ap;
64+
va_start(ap, format);
6765

68-
va_end(ap);
69-
return len;
70-
}
66+
len = vsnprintf(buf, 256, format, ap);
67+
Serial.write(buf, len);
7168

72-
void vApplicationMallocFailedHook(void)
73-
{
74-
Serial.println("Failed to Malloc");
75-
}
69+
va_end(ap);
70+
return len;
71+
}
7672

77-
void vApplicationStackOverflowHook( TaskHandle_t xTask, char *pcTaskName )
78-
{
79-
Serial.printf("%s Stack Overflow !!!", pcTaskName);
80-
}
73+
void vApplicationMallocFailedHook(void)
74+
{
75+
cprintf("Failed to Malloc");
76+
}
77+
78+
void vApplicationStackOverflowHook( TaskHandle_t xTask, char *pcTaskName )
79+
{
80+
cprintf("%s Stack Overflow !!!", pcTaskName);
8181
}
8282

8383
int dbgHeapTotal(void)
@@ -124,14 +124,14 @@ static void printMemRegion(const char* name, uint32_t top, uint32_t bottom, uint
124124
sprintf(buffer, "%lu", top-bottom);
125125
}
126126

127-
Serial.printf("| %-5s| 0x%04X - 0x%04X | %-19s |\n", name, (uint16_t) bottom, (uint16_t) (top-1), buffer);
127+
cprintf("| %-5s| 0x%04X - 0x%04X | %-19s |\n", name, (uint16_t) bottom, (uint16_t) (top-1), buffer);
128128
}
129129

130130
void dbgMemInfo(void)
131131
{
132-
Serial.println(" ______________________________________________");
133-
Serial.println("| Name | Addr 0x2000xxxx | Usage |");
134-
Serial.println("| ---------------------------------------------|");
132+
cprintf(" ______________________________________________\n");
133+
cprintf("| Name | Addr 0x2000xxxx | Usage |\n");
134+
cprintf("| ---------------------------------------------|\n");
135135

136136
// Pritn SRAM used for Stack executed by S132 and ISR
137137
printMemRegion("Stack", ((uint32_t) __StackTop), ((uint32_t) __StackLimit), dbgStackUsed() );
@@ -145,28 +145,29 @@ void dbgMemInfo(void)
145145
// Print SRAM Used by SoftDevice
146146
printMemRegion("S132", (uint32_t) __data_start__, 0x20000000, 0);
147147

148-
Serial.printf("|______________________________________________|\n");
149-
Serial.println();
148+
cprintf("|______________________________________________|\n");
149+
cprintf("\n");
150150

151151
// Print Task list
152152
uint32_t tasknum = uxTaskGetNumberOfTasks();
153153
char* buf = (char*) rtos_malloc(tasknum*40); // 40 bytes per task
154154

155155
vTaskList(buf);
156156

157-
Serial.println("Task State Prio StackLeft Num");
158-
Serial.println("-----------------------------------");
159-
Serial.println(buf);
157+
cprintf("Task State Prio StackLeft Num\n");
158+
cprintf("-----------------------------------\n");
159+
cprintf(buf);
160+
cprintf("\n");
160161
rtos_free(buf);
161162
}
162163

163164
void dbgPrintVersion(void)
164165
{
165-
Serial.println();
166-
Serial.println("BSP Library : " ARDUINO_BSP_VERSION);
167-
Serial.printf ("Firmware : %s\n", getFirmwareVersion());
168-
Serial.printf ("Serial No : %s\n", getMcuUniqueID());
169-
Serial.println();
166+
cprintf("\n");
167+
cprintf("BSP Library : " ARDUINO_BSP_VERSION "\n");
168+
cprintf("Firmware : %s\n", getFirmwareVersion());
169+
cprintf("Serial No : %s\n", getMcuUniqueID());
170+
cprintf("\n");
170171
}
171172

172173
/******************************************************************************/
@@ -195,26 +196,26 @@ void dbgDumpMemory(void const *buf, uint8_t size, uint16_t count, bool printOffs
195196
// Print address
196197
if ( i%item_per_line == 0 )
197198
{
198-
if ( i != 0 ) Serial.println();
199+
if ( i != 0 ) cprintf("\n");
199200

200201
// print offset or absolute address
201202
if (printOffset)
202203
{
203-
Serial.printf(offset_fmt, 16*i/item_per_line);
204+
cprintf(offset_fmt, 16*i/item_per_line);
204205
}else
205206
{
206-
Serial.printf("%08lX:", (uint32_t) buf8);
207+
cprintf("%08lX:", (uint32_t) buf8);
207208
}
208209
}
209210

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

213-
Serial.print(' ');
214-
Serial.printf(format, value);
214+
cprintf(" ");
215+
cprintf(format, value);
215216
}
216217

217-
Serial.println();
218+
cprintf("\n");
218219
}
219220

220221
#if CFG_DEBUG
@@ -395,5 +396,7 @@ const char* dbg_err_str(uint32_t err_id)
395396
return str;
396397
}
397398

399+
}
400+
398401
#endif
399402

cores/nRF5/debug.h

+8
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@
3939

4040
#include "common_inc.h"
4141

42+
#ifdef __cplusplus
43+
extern "C" {
44+
#endif
45+
4246
#if CFG_DEBUG
4347
const char* dbg_ble_event_str(uint16_t evt_id);
4448
const char* dbg_err_str(uint32_t err_id);
@@ -59,4 +63,8 @@ void dbgMemInfo(void);
5963
void dbgPrintVersion(void);
6064
void dbgDumpMemory(void const *buf, uint8_t size, uint16_t count, bool printOffset);
6165

66+
#ifdef __cplusplus
67+
}
68+
#endif
69+
6270
#endif

libraries/Bluefruit52Lib/src/bluefruit.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ void adafruit_soc_task(void* arg);
6666
void _adafruit_save_bond_key_dfr(uint32_t conn_handle);
6767

6868
#if CFG_DEBUG >= 2
69-
#define printBondDir() dbgPrintDir(CFG_BOND_NFFS_DIR)
69+
#define printBondDir() Nffs.listDir(CFG_BOND_NFFS_DIR)
7070
#else
7171
#define printBondDir()
7272
#endif

libraries/nffs/src/Nffs.cpp

+1-4
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,7 @@ bool ApacheNffs::testFolder(const char* path)
200200
return result;
201201
}
202202

203-
/*------------------------------------------------------------------*/
204-
/* Debug
205-
*------------------------------------------------------------------*/
206-
void dbgPrintDir(const char* cwd)
203+
void ApacheNffs::listDir(const char* cwd)
207204
{
208205
// Open the input folder
209206
NffsDir dir(cwd);

libraries/nffs/src/Nffs.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ class ApacheNffs
8484
{
8585
return writeFile(filename, str, strlen(str), offset);
8686
}
87+
88+
void listDir(const char* cwd);
8789
};
8890

8991

9092
extern ApacheNffs Nffs;
9193

92-
void dbgPrintDir(const char* cwd);
93-
9494
#endif /* NFFS_H_ */

platform.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ compiler.elf2hex.extra_flags=
7979
# ----------------
8080

8181
## Compile c files
82-
recipe.c.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.c.flags} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.c.extra_flags} {build.extra_flags} {compiler.nrf.flags} {includes} "{source_file}" -o "{object_file}"
82+
recipe.c.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.c.flags} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} -DARDUINO_BSP_VERSION="{version}" {compiler.c.extra_flags} {build.extra_flags} {compiler.nrf.flags} {includes} "{source_file}" -o "{object_file}"
8383

8484
## Compile c++ files
8585
recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpp.flags} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} -DARDUINO_BSP_VERSION="{version}" {compiler.cpp.extra_flags} {build.extra_flags} {compiler.nrf.flags} {includes} "{source_file}" -o "{object_file}"

0 commit comments

Comments
 (0)