Skip to content

Commit 123c308

Browse files
committed
clean up, replace cprintf by std printf (with _write hook)
1 parent ebbed82 commit 123c308

File tree

7 files changed

+63
-76
lines changed

7 files changed

+63
-76
lines changed

cores/nRF5/common_func.h

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,11 @@
115115
// DEBUG HELPER
116116
//--------------------------------------------------------------------+
117117
#if CFG_DEBUG == 2
118-
#define malloc_named( name, size ) ({ cprintf("[malloc] %s : %d\r\n", name, size); malloc(size); })
118+
#define malloc_named( name, size ) ({ printf("[malloc] %s : %d\r\n", name, size); malloc(size); })
119119
#else
120120
#define malloc_named( name, size ) malloc ( size )
121121
#endif
122122

123-
int cprintf(const char * format, ...);
124123
const char* dbg_err_str(int32_t err_id); // TODO move to other place
125124

126125
#if CFG_DEBUG
@@ -141,38 +140,38 @@ const char* dbg_err_str(int32_t err_id); // TODO move to other place
141140

142141
#if CFG_DEBUG
143142

144-
#define PRINT_LOCATION() cprintf("%s: %d:\n", __PRETTY_FUNCTION__, __LINE__)
145-
#define PRINT_MESS(x) cprintf("%s: %d: %s \n" , __FUNCTION__, __LINE__, (char*)(x))
146-
#define PRTNT_HEAP() if (CFG_DEBUG == 3) cprintf("\n%s: %d: Heap free: %d\n", __FUNCTION__, __LINE__, util_heap_get_free_size())
147-
#define PRINT_STR(x) cprintf("%s: %d: " #x " = %s\n" , __FUNCTION__, __LINE__, (char*)(x) )
148-
#define PRINT_INT(x) cprintf("%s: %d: " #x " = %ld\n" , __FUNCTION__, __LINE__, (uint32_t) (x) )
143+
#define PRINT_LOCATION() printf("%s: %d:\n", __PRETTY_FUNCTION__, __LINE__)
144+
#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 PRINT_STR(x) printf("%s: %d: " #x " = %s\n" , __FUNCTION__, __LINE__, (char*)(x) )
147+
#define PRINT_INT(x) printf("%s: %d: " #x " = %ld\n" , __FUNCTION__, __LINE__, (uint32_t) (x) )
149148

150149
#define PRINT_HEX(x) \
151150
do {\
152-
cprintf("%s: %d: " #x " = 0x", __PRETTY_FUNCTION__, __LINE__);\
151+
printf("%s: %d: " #x " = 0x", __PRETTY_FUNCTION__, __LINE__);\
153152
char fmt[] = "%00X\n";\
154153
fmt[2] += 2*sizeof(x); /* Hex with correct size */\
155-
cprintf(fmt, (x) );\
154+
printf(fmt, (x) );\
156155
}while(0)
157156

158157
#define PRINT_BUFFER(buf, n) \
159158
do {\
160159
uint8_t const* p8 = (uint8_t const*) (buf);\
161-
cprintf(#buf ": ");\
162-
for(uint32_t i=0; i<(n); i++) cprintf("%02x ", p8[i]);\
163-
cprintf("\n");\
160+
printf(#buf ": ");\
161+
for(uint32_t i=0; i<(n); i++) printf("%02x ", p8[i]);\
162+
printf("\n");\
164163
}while(0)
165164

166165
#define ADALOG(tag, ...) \
167166
do { \
168-
if ( tag ) cprintf("[%-6s] ", tag);\
169-
cprintf(__VA_ARGS__);\
170-
cprintf("\n");\
167+
if ( tag ) printf("[%-6s] ", tag);\
168+
printf(__VA_ARGS__);\
169+
printf("\n");\
171170
}while(0)
172171

173172
#define ADALOG_BUFFER(_tag, _buf, _n) \
174173
do {\
175-
if ( _tag ) cprintf("%-6s: len = %d\n", _tag, _n);\
174+
if ( _tag ) printf("%-6s: len = %d\n", _tag, _n);\
176175
dbgDumpMemory(_buf, 1, _n, true);\
177176
}while(0)
178177

cores/nRF5/flash/flash_nrf5x.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,6 @@ bool fal_erase (uint32_t addr)
125125

126126
static uint32_t fal_program (uint32_t dst, void const * src, uint32_t len)
127127
{
128-
cprintf("Programming 0x%08X\n", dst);
129-
130128
// wait for async event if SD is enabled
131129
uint8_t sd_en = 0;
132130
(void) sd_softdevice_is_enabled(&sd_en);

cores/nRF5/rtos.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ enum
6868
#define malloc_type(type) rtos_malloc( sizeof(type) )
6969

7070
#if 0
71-
#define rtos_malloc(_size) ({ cprintf("[malloc] %s:%d : %d bytes\r\n", __PRETTY_FUNCTION__, __LINE__, _size); pvPortMalloc(_size); })
72-
#define rtos_free(ptr) ({ cprintf("[free] %s:%d\r\n" ,__PRETTY_FUNCTION__, __LINE__/*malloc_usable_size(ptr)*/); vPortFree(ptr); })
71+
#define rtos_malloc(_size) ({ printf("[malloc] %s:%d : %d bytes\r\n", __PRETTY_FUNCTION__, __LINE__, _size); pvPortMalloc(_size); })
72+
#define rtos_free(ptr) ({ printf("[free] %s:%d\r\n" ,__PRETTY_FUNCTION__, __LINE__/*malloc_usable_size(ptr)*/); vPortFree(ptr); })
7373
#else
7474

7575
#define rtos_malloc_type(_type) (_type*) rtos_malloc(sizeof(_type))

cores/nRF5/utility/debug.cpp

Lines changed: 38 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -62,21 +62,12 @@ void HardFault_Handler(void)
6262
NVIC_SystemReset();
6363
}
6464

65-
int cprintf(const char * format, ...)
65+
// nanolib printf() retarget
66+
int _write (int fd, const void *buf, size_t count)
6667
{
67-
char buf[256];
68-
int len;
68+
(void) fd;
6969

70-
va_list ap;
71-
va_start(ap, format);
72-
73-
len = vsnprintf(buf, 256, format, ap);
74-
75-
// SEGGER_SYSVIEW_Print(buf);
76-
Serial.write(buf, len);
77-
78-
va_end(ap);
79-
return len;
70+
Serial.write( (const uint8_t *) buf, count);
8071
}
8172

8273
int dbgHeapTotal(void)
@@ -123,14 +114,14 @@ static void printMemRegion(const char* name, uint32_t top, uint32_t bottom, uint
123114
sprintf(buffer, "%lu", top-bottom);
124115
}
125116

126-
cprintf("| %-5s| 0x%04X - 0x%04X | %-19s |\n", name, (uint16_t) bottom, (uint16_t) (top-1), buffer);
117+
printf("| %-5s| 0x%04X - 0x%04X | %-19s |\n", name, (uint16_t) bottom, (uint16_t) (top-1), buffer);
127118
}
128119

129120
void dbgMemInfo(void)
130121
{
131-
cprintf(" ______________________________________________\n");
132-
cprintf("| Name | Addr 0x2000xxxx | Usage |\n");
133-
cprintf("| ---------------------------------------------|\n");
122+
printf(" ______________________________________________\n");
123+
printf("| Name | Addr 0x2000xxxx | Usage |\n");
124+
printf("| ---------------------------------------------|\n");
134125

135126
// Pritn SRAM used for Stack executed by S132 and ISR
136127
printMemRegion("Stack", ((uint32_t) __StackTop), ((uint32_t) __StackLimit), dbgStackUsed() );
@@ -144,29 +135,29 @@ void dbgMemInfo(void)
144135
// Print SRAM Used by SoftDevice
145136
printMemRegion("S132", (uint32_t) __data_start__, 0x20000000, 0);
146137

147-
cprintf("|______________________________________________|\n");
148-
cprintf("\n");
138+
printf("|______________________________________________|\n");
139+
printf("\n");
149140

150141
// Print Task list
151142
uint32_t tasknum = uxTaskGetNumberOfTasks();
152143
char* buf = (char*) rtos_malloc(tasknum*40); // 40 bytes per task
153144

154145
vTaskList(buf);
155146

156-
cprintf("Task State Prio StackLeft Num\n");
157-
cprintf("-----------------------------------\n");
158-
cprintf(buf);
159-
cprintf("\n");
147+
printf("Task State Prio StackLeft Num\n");
148+
printf("-----------------------------------\n");
149+
printf(buf);
150+
printf("\n");
160151
rtos_free(buf);
161152
}
162153

163154
void dbgPrintVersion(void)
164155
{
165-
cprintf("\n");
166-
cprintf("BSP Library : " ARDUINO_BSP_VERSION "\n");
167-
cprintf("Bootloader : %s\n", getBootloaderVersion());
168-
cprintf("Serial No : %s\n", getMcuUniqueID());
169-
cprintf("\n");
156+
printf("\n");
157+
printf("BSP Library : " ARDUINO_BSP_VERSION "\n");
158+
printf("Bootloader : %s\n", getBootloaderVersion());
159+
printf("Serial No : %s\n", getMcuUniqueID());
160+
printf("\n");
170161
}
171162

172163
/******************************************************************************/
@@ -180,15 +171,15 @@ static void dump_str_line(uint8_t const* buf, uint16_t count)
180171
for(int i=0; i<count; i++)
181172
{
182173
const char ch = buf[i];
183-
cprintf("%c", isprint(ch) ? ch : '.');
174+
printf("%c", isprint(ch) ? ch : '.');
184175
}
185176
}
186177

187178
void dbgDumpMemory(void const *buf, uint8_t size, uint16_t count, bool printOffset)
188179
{
189180
if ( !buf )
190181
{
191-
cprintf("NULL\n");
182+
printf("NULL\n");
192183
return;
193184
}
194185

@@ -208,26 +199,26 @@ void dbgDumpMemory(void const *buf, uint8_t size, uint16_t count, bool printOffs
208199
// Print Ascii
209200
if ( i != 0 )
210201
{
211-
cprintf(" | ");
202+
printf(" | ");
212203
dump_str_line(buf8-16, 16);
213-
cprintf("\n");
204+
printf("\n");
214205
}
215206

216207
// print offset or absolute address
217208
if (printOffset)
218209
{
219-
cprintf("%03lX: ", 16*i/item_per_line);
210+
printf("%03lX: ", 16*i/item_per_line);
220211
}else
221212
{
222-
cprintf("%08lX:", (uint32_t) buf8);
213+
printf("%08lX:", (uint32_t) buf8);
223214
}
224215
}
225216

226217
memcpy(&value, buf8, size);
227218
buf8 += size;
228219

229-
cprintf(" ");
230-
cprintf(format, value);
220+
printf(" ");
221+
printf(format, value);
231222
}
232223

233224
// fill up last row to 16 for printing ascii
@@ -238,28 +229,28 @@ void dbgDumpMemory(void const *buf, uint8_t size, uint16_t count, bool printOffs
238229
{
239230
for(int i=0; i< 16-remain; i++)
240231
{
241-
cprintf(" ");
242-
for(int j=0; j<2*size; j++) cprintf(" ");
232+
printf(" ");
233+
for(int j=0; j<2*size; j++) printf(" ");
243234
}
244235
}
245236

246-
cprintf(" | ");
237+
printf(" | ");
247238
dump_str_line(buf8-nback, nback);
248-
cprintf("\n");
239+
printf("\n");
249240

250-
cprintf("\n");
241+
printf("\n");
251242
}
252243

253244

254245
void dbgDumpMemoryCFormat(const char* str, void const *buf, uint16_t count)
255246
{
256247
if ( !buf )
257248
{
258-
cprintf("NULL\n");
249+
printf("NULL\n");
259250
return;
260251
}
261252

262-
cprintf("%s = \n{\n ", str);
253+
printf("%s = \n{\n ", str);
263254

264255
uint8_t const *buf8 = (uint8_t const *) buf;
265256

@@ -269,17 +260,17 @@ void dbgDumpMemoryCFormat(const char* str, void const *buf, uint16_t count)
269260

270261
if ( i%16 == 0 )
271262
{
272-
if ( i != 0 ) cprintf(",\n ");
263+
if ( i != 0 ) printf(",\n ");
273264
}else
274265
{
275-
if ( i != 0 ) cprintf(", ");
266+
if ( i != 0 ) printf(", ");
276267
}
277268

278-
cprintf("0x%02lX", *buf8);
269+
printf("0x%02lX", *buf8);
279270
buf8++;
280271
}
281272

282-
cprintf("\n\};\n");
273+
printf("\n\};\n");
283274
}
284275

285276

cores/nRF5/verify.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ extern "C"
6565
#define VERIFY_MESS(_status, _funcstr) \
6666
do { \
6767
const char* (*_fstr)(int32_t) = _funcstr;\
68-
cprintf("%s: %d: verify failed, error = ", __PRETTY_FUNCTION__, __LINE__);\
69-
if (_fstr) cprintf(_fstr(_status)); else cprintf("%d", _status);\
70-
cprintf("\n");\
68+
printf("%s: %d: verify failed, error = ", __PRETTY_FUNCTION__, __LINE__);\
69+
if (_fstr) printf(_fstr(_status)); else printf("%d", _status);\
70+
printf("\n");\
7171
}while(0)
7272
#else
7373
#define VERIFY_MESS(_status, _funcstr)

libraries/Bluefruit52Lib/src/utility/bonding.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,14 +255,14 @@ void bond_print_list(uint8_t role)
255255
char devname[len];
256256
file.read(devname, len);
257257

258-
cprintf(" %s : %s (%d bytes)\n", file.name(), devname, file.size());
258+
printf(" %s : %s (%d bytes)\n", file.name(), devname, file.size());
259259
}
260260
}
261261

262262
file.close();
263263
}
264264

265-
cprintf("\n");
265+
printf("\n");
266266

267267
file.close();
268268
dir.close();

libraries/FileSystem/src/littlefs/lfs_util.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141

4242
#if !defined(LFS_NO_DEBUG) || !defined(LFS_NO_WARN) || !defined(LFS_NO_ERROR)
4343
#include <stdio.h>
44-
int cprintf (const char * format, ...);
4544
#endif
4645

4746
#ifdef __cplusplus
@@ -57,21 +56,21 @@ extern "C"
5756
// Logging functions
5857
#ifndef LFS_NO_DEBUG
5958
#define LFS_DEBUG(fmt, ...) \
60-
cprintf("lfs debug:%d: " fmt "\n", __LINE__, __VA_ARGS__)
59+
printf("lfs debug:%d: " fmt "\n", __LINE__, __VA_ARGS__)
6160
#else
6261
#define LFS_DEBUG(fmt, ...)
6362
#endif
6463

6564
#ifndef LFS_NO_WARN
6665
#define LFS_WARN(fmt, ...) \
67-
cprintf("lfs warn:%d: " fmt "\n", __LINE__, __VA_ARGS__)
66+
printf("lfs warn:%d: " fmt "\n", __LINE__, __VA_ARGS__)
6867
#else
6968
#define LFS_WARN(fmt, ...)
7069
#endif
7170

7271
#ifndef LFS_NO_ERROR
7372
#define LFS_ERROR(fmt, ...) \
74-
cprintf("lfs error:%d: " fmt "\n", __LINE__, __VA_ARGS__)
73+
printf("lfs error:%d: " fmt "\n", __LINE__, __VA_ARGS__)
7574
#else
7675
#define LFS_ERROR(fmt, ...)
7776
#endif

0 commit comments

Comments
 (0)