From 123c3080c3c5f516d3cf2cd95a6b4d4fb2c987fb Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 2 Nov 2018 20:17:33 +0700 Subject: [PATCH] clean up, replace cprintf by std printf (with _write hook) --- cores/nRF5/common_func.h | 31 ++++--- cores/nRF5/flash/flash_nrf5x.c | 2 - cores/nRF5/rtos.h | 4 +- cores/nRF5/utility/debug.cpp | 85 +++++++++---------- cores/nRF5/verify.h | 6 +- .../Bluefruit52Lib/src/utility/bonding.cpp | 4 +- libraries/FileSystem/src/littlefs/lfs_util.h | 7 +- 7 files changed, 63 insertions(+), 76 deletions(-) diff --git a/cores/nRF5/common_func.h b/cores/nRF5/common_func.h index 48de5a82..b9f3b5a4 100644 --- a/cores/nRF5/common_func.h +++ b/cores/nRF5/common_func.h @@ -115,12 +115,11 @@ // DEBUG HELPER //--------------------------------------------------------------------+ #if CFG_DEBUG == 2 - #define malloc_named( name, size ) ({ cprintf("[malloc] %s : %d\r\n", name, size); malloc(size); }) + #define malloc_named( name, size ) ({ printf("[malloc] %s : %d\r\n", name, size); malloc(size); }) #else #define malloc_named( name, size ) malloc ( size ) #endif -int cprintf(const char * format, ...); const char* dbg_err_str(int32_t err_id); // TODO move to other place #if CFG_DEBUG @@ -141,38 +140,38 @@ const char* dbg_err_str(int32_t err_id); // TODO move to other place #if CFG_DEBUG -#define PRINT_LOCATION() cprintf("%s: %d:\n", __PRETTY_FUNCTION__, __LINE__) -#define PRINT_MESS(x) cprintf("%s: %d: %s \n" , __FUNCTION__, __LINE__, (char*)(x)) -#define PRTNT_HEAP() if (CFG_DEBUG == 3) cprintf("\n%s: %d: Heap free: %d\n", __FUNCTION__, __LINE__, util_heap_get_free_size()) -#define PRINT_STR(x) cprintf("%s: %d: " #x " = %s\n" , __FUNCTION__, __LINE__, (char*)(x) ) -#define PRINT_INT(x) cprintf("%s: %d: " #x " = %ld\n" , __FUNCTION__, __LINE__, (uint32_t) (x) ) +#define PRINT_LOCATION() printf("%s: %d:\n", __PRETTY_FUNCTION__, __LINE__) +#define PRINT_MESS(x) printf("%s: %d: %s \n" , __FUNCTION__, __LINE__, (char*)(x)) +#define PRTNT_HEAP() if (CFG_DEBUG == 3) printf("\n%s: %d: Heap free: %d\n", __FUNCTION__, __LINE__, util_heap_get_free_size()) +#define PRINT_STR(x) printf("%s: %d: " #x " = %s\n" , __FUNCTION__, __LINE__, (char*)(x) ) +#define PRINT_INT(x) printf("%s: %d: " #x " = %ld\n" , __FUNCTION__, __LINE__, (uint32_t) (x) ) #define PRINT_HEX(x) \ do {\ - cprintf("%s: %d: " #x " = 0x", __PRETTY_FUNCTION__, __LINE__);\ + printf("%s: %d: " #x " = 0x", __PRETTY_FUNCTION__, __LINE__);\ char fmt[] = "%00X\n";\ fmt[2] += 2*sizeof(x); /* Hex with correct size */\ - cprintf(fmt, (x) );\ + printf(fmt, (x) );\ }while(0) #define PRINT_BUFFER(buf, n) \ do {\ uint8_t const* p8 = (uint8_t const*) (buf);\ - cprintf(#buf ": ");\ - for(uint32_t i=0; i<(n); i++) cprintf("%02x ", p8[i]);\ - cprintf("\n");\ + printf(#buf ": ");\ + for(uint32_t i=0; i<(n); i++) printf("%02x ", p8[i]);\ + printf("\n");\ }while(0) #define ADALOG(tag, ...) \ do { \ - if ( tag ) cprintf("[%-6s] ", tag);\ - cprintf(__VA_ARGS__);\ - cprintf("\n");\ + if ( tag ) printf("[%-6s] ", tag);\ + printf(__VA_ARGS__);\ + printf("\n");\ }while(0) #define ADALOG_BUFFER(_tag, _buf, _n) \ do {\ - if ( _tag ) cprintf("%-6s: len = %d\n", _tag, _n);\ + if ( _tag ) printf("%-6s: len = %d\n", _tag, _n);\ dbgDumpMemory(_buf, 1, _n, true);\ }while(0) diff --git a/cores/nRF5/flash/flash_nrf5x.c b/cores/nRF5/flash/flash_nrf5x.c index 71086cb9..5ccbfe6d 100644 --- a/cores/nRF5/flash/flash_nrf5x.c +++ b/cores/nRF5/flash/flash_nrf5x.c @@ -125,8 +125,6 @@ bool fal_erase (uint32_t addr) static uint32_t fal_program (uint32_t dst, void const * src, uint32_t len) { - cprintf("Programming 0x%08X\n", dst); - // wait for async event if SD is enabled uint8_t sd_en = 0; (void) sd_softdevice_is_enabled(&sd_en); diff --git a/cores/nRF5/rtos.h b/cores/nRF5/rtos.h index 7eacfc87..ae0e23d9 100644 --- a/cores/nRF5/rtos.h +++ b/cores/nRF5/rtos.h @@ -68,8 +68,8 @@ enum #define malloc_type(type) rtos_malloc( sizeof(type) ) #if 0 -#define rtos_malloc(_size) ({ cprintf("[malloc] %s:%d : %d bytes\r\n", __PRETTY_FUNCTION__, __LINE__, _size); pvPortMalloc(_size); }) -#define rtos_free(ptr) ({ cprintf("[free] %s:%d\r\n" ,__PRETTY_FUNCTION__, __LINE__/*malloc_usable_size(ptr)*/); vPortFree(ptr); }) +#define rtos_malloc(_size) ({ printf("[malloc] %s:%d : %d bytes\r\n", __PRETTY_FUNCTION__, __LINE__, _size); pvPortMalloc(_size); }) +#define rtos_free(ptr) ({ printf("[free] %s:%d\r\n" ,__PRETTY_FUNCTION__, __LINE__/*malloc_usable_size(ptr)*/); vPortFree(ptr); }) #else #define rtos_malloc_type(_type) (_type*) rtos_malloc(sizeof(_type)) diff --git a/cores/nRF5/utility/debug.cpp b/cores/nRF5/utility/debug.cpp index c91d26e6..bc0032a7 100644 --- a/cores/nRF5/utility/debug.cpp +++ b/cores/nRF5/utility/debug.cpp @@ -62,21 +62,12 @@ void HardFault_Handler(void) NVIC_SystemReset(); } -int cprintf(const char * format, ...) +// nanolib printf() retarget +int _write (int fd, const void *buf, size_t count) { - char buf[256]; - int len; + (void) fd; - va_list ap; - va_start(ap, format); - - len = vsnprintf(buf, 256, format, ap); - -// SEGGER_SYSVIEW_Print(buf); - Serial.write(buf, len); - - va_end(ap); - return len; + Serial.write( (const uint8_t *) buf, count); } int dbgHeapTotal(void) @@ -123,14 +114,14 @@ static void printMemRegion(const char* name, uint32_t top, uint32_t bottom, uint sprintf(buffer, "%lu", top-bottom); } - cprintf("| %-5s| 0x%04X - 0x%04X | %-19s |\n", name, (uint16_t) bottom, (uint16_t) (top-1), buffer); + printf("| %-5s| 0x%04X - 0x%04X | %-19s |\n", name, (uint16_t) bottom, (uint16_t) (top-1), buffer); } void dbgMemInfo(void) { - cprintf(" ______________________________________________\n"); - cprintf("| Name | Addr 0x2000xxxx | Usage |\n"); - cprintf("| ---------------------------------------------|\n"); + printf(" ______________________________________________\n"); + printf("| Name | Addr 0x2000xxxx | Usage |\n"); + printf("| ---------------------------------------------|\n"); // Pritn SRAM used for Stack executed by S132 and ISR printMemRegion("Stack", ((uint32_t) __StackTop), ((uint32_t) __StackLimit), dbgStackUsed() ); @@ -144,8 +135,8 @@ void dbgMemInfo(void) // Print SRAM Used by SoftDevice printMemRegion("S132", (uint32_t) __data_start__, 0x20000000, 0); - cprintf("|______________________________________________|\n"); - cprintf("\n"); + printf("|______________________________________________|\n"); + printf("\n"); // Print Task list uint32_t tasknum = uxTaskGetNumberOfTasks(); @@ -153,20 +144,20 @@ void dbgMemInfo(void) vTaskList(buf); - cprintf("Task State Prio StackLeft Num\n"); - cprintf("-----------------------------------\n"); - cprintf(buf); - cprintf("\n"); + printf("Task State Prio StackLeft Num\n"); + printf("-----------------------------------\n"); + printf(buf); + printf("\n"); rtos_free(buf); } void dbgPrintVersion(void) { - cprintf("\n"); - cprintf("BSP Library : " ARDUINO_BSP_VERSION "\n"); - cprintf("Bootloader : %s\n", getBootloaderVersion()); - cprintf("Serial No : %s\n", getMcuUniqueID()); - cprintf("\n"); + printf("\n"); + printf("BSP Library : " ARDUINO_BSP_VERSION "\n"); + printf("Bootloader : %s\n", getBootloaderVersion()); + printf("Serial No : %s\n", getMcuUniqueID()); + printf("\n"); } /******************************************************************************/ @@ -180,7 +171,7 @@ static void dump_str_line(uint8_t const* buf, uint16_t count) for(int i=0; i -int cprintf (const char * format, ...); #endif #ifdef __cplusplus @@ -57,21 +56,21 @@ extern "C" // Logging functions #ifndef LFS_NO_DEBUG #define LFS_DEBUG(fmt, ...) \ - cprintf("lfs debug:%d: " fmt "\n", __LINE__, __VA_ARGS__) + printf("lfs debug:%d: " fmt "\n", __LINE__, __VA_ARGS__) #else #define LFS_DEBUG(fmt, ...) #endif #ifndef LFS_NO_WARN #define LFS_WARN(fmt, ...) \ - cprintf("lfs warn:%d: " fmt "\n", __LINE__, __VA_ARGS__) + printf("lfs warn:%d: " fmt "\n", __LINE__, __VA_ARGS__) #else #define LFS_WARN(fmt, ...) #endif #ifndef LFS_NO_ERROR #define LFS_ERROR(fmt, ...) \ - cprintf("lfs error:%d: " fmt "\n", __LINE__, __VA_ARGS__) + printf("lfs error:%d: " fmt "\n", __LINE__, __VA_ARGS__) #else #define LFS_ERROR(fmt, ...) #endif