diff --git a/cores/nRF5/common_func.h b/cores/nRF5/common_func.h index 71e1fd65c..be9a868e6 100644 --- a/cores/nRF5/common_func.h +++ b/cores/nRF5/common_func.h @@ -116,6 +116,13 @@ //--------------------------------------------------------------------+ const char* dbg_err_str(int32_t err_id); // TODO move to other place +#if __cplusplus +#define PRINTF ::printf +#else +#define PRINTF printf +#endif + + #if CFG_DEBUG #define LOG_LV1(...) ADALOG(__VA_ARGS__) #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 #if CFG_DEBUG -#if __cplusplus -#define PRINTF ::printf -#else -#define PRINTF printf -#endif - #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 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_FLOAT(x) PRINTF("%s: %d: " #x " = %f\n" , __FUNCTION__, __LINE__, (float) (x) ) diff --git a/cores/nRF5/utility/debug.cpp b/cores/nRF5/utility/debug.cpp index 4bbe866ae..33118c30c 100644 --- a/cores/nRF5/utility/debug.cpp +++ b/cores/nRF5/utility/debug.cpp @@ -39,6 +39,7 @@ #include #include #include +#include // defined in linker script extern uint32_t __data_start__[]; @@ -106,14 +107,14 @@ static void printMemRegion(const char* name, uint32_t top, uint32_t bottom, uint sprintf(buffer, "%lu", top-bottom); } - printf("| %-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) { - printf(" ______________________________________________\n"); - printf("| Name | Addr 0x2000xxxx | Usage |\n"); - printf("| ---------------------------------------------|\n"); + PRINTF(" ______________________________________________\n"); + PRINTF("| Name | Addr 0x2000xxxx | Usage |\n"); + PRINTF("| ---------------------------------------------|\n"); // Pritn SRAM used for Stack executed by Softdevice and ISR printMemRegion("Stack", ((uint32_t) __StackTop), ((uint32_t) __StackLimit), dbgStackUsed() ); @@ -127,8 +128,8 @@ void dbgMemInfo(void) // Print SRAM Used by SoftDevice printMemRegion("SD", (uint32_t) __data_start__, 0x20000000, 0); - printf("|______________________________________________|\n"); - printf("\n"); + PRINTF("|______________________________________________|\n"); + PRINTF("\n"); // Print Task list uint32_t tasknum = uxTaskGetNumberOfTasks(); @@ -136,20 +137,20 @@ void dbgMemInfo(void) vTaskList(buf); - printf("Task State Prio StackLeft Num\n"); - printf("-----------------------------------\n"); - printf(buf); - printf("\n"); + PRINTF("Task State Prio StackLeft Num\n"); + PRINTF("-----------------------------------\n"); + PRINTF(buf); + PRINTF("\n"); rtos_free(buf); } void dbgPrintVersion(void) { - printf("\n"); - printf("BSP Library : " ARDUINO_BSP_VERSION "\n"); - printf("Bootloader : %s\n", getBootloaderVersion()); - printf("Serial No : %s\n", getMcuUniqueID()); - printf("\n"); + PRINTF("\n"); + PRINTF("BSP Library : " ARDUINO_BSP_VERSION "\n"); + PRINTF("Bootloader : %s\n", getBootloaderVersion()); + PRINTF("Serial No : %s\n", getMcuUniqueID()); + PRINTF("\n"); } /******************************************************************************/ @@ -163,7 +164,7 @@ static void dump_str_line(uint8_t const* buf, uint16_t count) for(int i=0; igetAddr(); // MAC is in little endian --> print reverse - Serial.printBufferReverse(gap_addr.addr, 6, ':'); - Serial.printf(" (%s)", type_str[gap_addr.addr_type]); + logger.printBufferReverse(gap_addr.addr, 6, ':'); + logger.printf(" (%s)", type_str[gap_addr.addr_type]); } - Serial.println(); + logger.println(); // Tx Power - Serial.printf(title_fmt, "TX Power"); - Serial.printf("%d dBm", _tx_power); - Serial.println(); + logger.printf(title_fmt, "TX Power"); + logger.printf("%d dBm", _tx_power); + logger.println(); Periph.printInfo(); /*------------- List the paried device -------------*/ if ( _prph_count ) { - Serial.printf(title_fmt, "Peripheral Paired Devices"); - Serial.println(); + logger.printf(title_fmt, "Peripheral Paired Devices"); + logger.println(); bond_print_list(BLE_GAP_ROLE_PERIPH); } if ( _central_count ) { - Serial.printf(title_fmt, "Central Paired Devices"); - Serial.println(); + logger.printf(title_fmt, "Central Paired Devices"); + logger.println(); bond_print_list(BLE_GAP_ROLE_CENTRAL); } - Serial.println(); + logger.println(); } diff --git a/libraries/Bluefruit52Lib/src/utility/bonding.cpp b/libraries/Bluefruit52Lib/src/utility/bonding.cpp index 9783ac5d2..5c5f666aa 100644 --- a/libraries/Bluefruit52Lib/src/utility/bonding.cpp +++ b/libraries/Bluefruit52Lib/src/utility/bonding.cpp @@ -250,14 +250,14 @@ void bond_print_list(uint8_t role) char devname[len]; file.read(devname, len); - printf(" %s : %s (%lu bytes)\n", file.name(), devname, file.size()); + PRINTF(" %s : %s (%lu bytes)\n", file.name(), devname, file.size()); } } file.close(); } - printf("\n"); + PRINTF("\n"); file.close(); dir.close(); diff --git a/platform.txt b/platform.txt index 5d16d6ef9..a0897725d 100644 --- a/platform.txt +++ b/platform.txt @@ -51,13 +51,16 @@ compiler.size.cmd=arm-none-eabi-size # this can be overriden in boards.txt build.float_flags=-mfloat-abi=hard -mfpu=fpv4-sp-d16 -u _printf_float build.debug_flags=-DCFG_DEBUG=0 +build.logger_flags=-DCFG_LOGGER=1 +build.sysview_flags=-DCFG_SYSVIEW=0 # common compiler for nrf rtos.path={build.core.path}/freertos nordic.path={build.core.path}/nordic - -build.flags.nrf= -DSOFTDEVICE_PRESENT -DARDUINO_NRF52_ADAFRUIT -DNRF52_SERIES -DLFS_NAME_MAX=64 -Ofast {build.debug_flags} "-I{build.core.path}/cmsis/include" "-I{nordic.path}" "-I{nordic.path}/nrfx" "-I{nordic.path}/nrfx/hal" "-I{nordic.path}/nrfx/mdk" "-I{nordic.path}/nrfx/soc" "-I{nordic.path}/nrfx/drivers/include" "-I{nordic.path}/nrfx/drivers/src" "-I{nordic.path}/softdevice/{build.sd_name}_nrf52_{build.sd_version}_API/include" "-I{rtos.path}/Source/include" "-I{rtos.path}/config" "-I{rtos.path}/portable/GCC/nrf52" "-I{rtos.path}/portable/CMSIS/nrf52" "-I{build.core.path}/sysview/SEGGER" "-I{build.core.path}/sysview/Config" "-I{build.core.path}/TinyUSB" "-I{build.core.path}/TinyUSB/Adafruit_TinyUSB_ArduinoCore" "-I{build.core.path}/TinyUSB/Adafruit_TinyUSB_ArduinoCore/tinyusb/src" +# build.logger_flags and build.sysview_flags and intentionally empty, +# to allow modification via a user's own boards.local.txt or platform.local.txt files. +build.flags.nrf= -DSOFTDEVICE_PRESENT -DARDUINO_NRF52_ADAFRUIT -DNRF52_SERIES -DLFS_NAME_MAX=64 -Ofast {build.debug_flags} {build.logger_flags} {build.sysview_flags} "-I{build.core.path}/cmsis/include" "-I{nordic.path}" "-I{nordic.path}/nrfx" "-I{nordic.path}/nrfx/hal" "-I{nordic.path}/nrfx/mdk" "-I{nordic.path}/nrfx/soc" "-I{nordic.path}/nrfx/drivers/include" "-I{nordic.path}/nrfx/drivers/src" "-I{nordic.path}/softdevice/{build.sd_name}_nrf52_{build.sd_version}_API/include" "-I{rtos.path}/Source/include" "-I{rtos.path}/config" "-I{rtos.path}/portable/GCC/nrf52" "-I{rtos.path}/portable/CMSIS/nrf52" "-I{build.core.path}/sysview/SEGGER" "-I{build.core.path}/sysview/Config" "-I{build.core.path}/TinyUSB" "-I{build.core.path}/TinyUSB/Adafruit_TinyUSB_ArduinoCore" "-I{build.core.path}/TinyUSB/Adafruit_TinyUSB_ArduinoCore/tinyusb/src" # usb flags build.flags.usb= -DUSBCON -DUSE_TINYUSB -DUSB_VID={build.vid} -DUSB_PID={build.pid} '-DUSB_MANUFACTURER={build.usb_manufacturer}' '-DUSB_PRODUCT={build.usb_product}' @@ -147,3 +150,4 @@ tools.bootburn.bootloader.pattern={program.burn_pattern} tools.bootburn.erase.params.verbose= tools.bootburn.erase.params.quiet= tools.bootburn.erase.pattern= +