From 1fc7f54a8a05792d6e56d0ed14ded1c4a7b389bd Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 22 Apr 2020 19:18:03 +0700 Subject: [PATCH 1/2] added swo as logger tested with feather nrf52840 + jlink --- .../cdc_msc_freertos/src/FreeRTOSConfig.h | 71 +--------- .../src/FreeRTOSConfig.h | 71 +--------- examples/make.mk | 6 +- examples/readme.md | 14 +- hw/bsp/board.c | 27 +++- hw/bsp/board_mcu.h | 121 ++++++++++++++++++ src/tusb_option.h | 6 +- 7 files changed, 172 insertions(+), 144 deletions(-) create mode 100644 hw/bsp/board_mcu.h diff --git a/examples/device/cdc_msc_freertos/src/FreeRTOSConfig.h b/examples/device/cdc_msc_freertos/src/FreeRTOSConfig.h index 0945baf1..494452d4 100644 --- a/examples/device/cdc_msc_freertos/src/FreeRTOSConfig.h +++ b/examples/device/cdc_msc_freertos/src/FreeRTOSConfig.h @@ -42,78 +42,11 @@ * See http://www.freertos.org/a00110.html. *----------------------------------------------------------*/ -// for OPT_MCU_ -#include "tusb_option.h" - -#if CFG_TUSB_MCU == OPT_MCU_LPC11UXX || CFG_TUSB_MCU == OPT_MCU_LPC13XX || \ - CFG_TUSB_MCU == OPT_MCU_LPC15XX || CFG_TUSB_MCU == OPT_MCU_LPC175X_6X || \ - CFG_TUSB_MCU == OPT_MCU_LPC177X_8X || CFG_TUSB_MCU == OPT_MCU_LPC18XX || \ - CFG_TUSB_MCU == OPT_MCU_LPC40XX || CFG_TUSB_MCU == OPT_MCU_LPC43XX - #include "chip.h" - -#elif CFG_TUSB_MCU == OPT_MCU_LPC51UXX || CFG_TUSB_MCU == OPT_MCU_LPC54XXX || \ - CFG_TUSB_MCU == OPT_MCU_LPC55XX - #include "fsl_device_registers.h" - -#elif CFG_TUSB_MCU == OPT_MCU_NRF5X - #include "nrf.h" - -#elif CFG_TUSB_MCU == OPT_MCU_SAMD21 || CFG_TUSB_MCU == OPT_MCU_SAMD51 - #include "sam.h" - -#elif CFG_TUSB_MCU == OPT_MCU_SAMG - #undef LITTLE_ENDIAN // hack to suppress "LITTLE_ENDIAN" redefined - #include "sam.h" - -#elif CFG_TUSB_MCU == OPT_MCU_STM32F0 - #include "stm32f0xx.h" - -#elif CFG_TUSB_MCU == OPT_MCU_STM32F1 - #include "stm32f1xx.h" - -#elif CFG_TUSB_MCU == OPT_MCU_STM32F2 - #include "stm32f2xx.h" - -#elif CFG_TUSB_MCU == OPT_MCU_STM32F3 - #include "stm32f3xx.h" - -#elif CFG_TUSB_MCU == OPT_MCU_STM32F4 - #include "stm32f4xx.h" - -#elif CFG_TUSB_MCU == OPT_MCU_STM32F7 - #include "stm32f7xx.h" - -#elif CFG_TUSB_MCU == OPT_MCU_STM32H7 - #include "stm32h7xx.h" - -#elif CFG_TUSB_MCU == OPT_MCU_STM32L0 - #include "stm32l0xx.h" - -#elif CFG_TUSB_MCU == OPT_MCU_STM32L1 - #include "stm32l1xx.h" - -#elif CFG_TUSB_MCU == OPT_MCU_STM32L4 - #include "stm32l4xx.h" - -#elif CFG_TUSB_MCU == OPT_MCU_MIMXRT10XX - #include "fsl_device_registers.h" - -#elif CFG_TUSB_MCU == OPT_MCU_NUC120 - #include "NUC100Series.h" - -#elif CFG_TUSB_MCU == OPT_MCU_NUC121 || CFG_TUSB_MCU == OPT_MCU_NUC126 - #include "NuMicro.h" - -#elif CFG_TUSB_MCU == OPT_MCU_NUC505 - #include "NUC505Series.h" - -#else - #error "FreeRTOSConfig.h need to include low level mcu header for configuration" -#endif +// Include MCU header +#include "bsp/board_mcu.h" extern uint32_t SystemCoreClock; - /* Cortex M23/M33 port configuration. */ #define configENABLE_MPU 0 #define configENABLE_FPU 1 diff --git a/examples/device/hid_composite_freertos/src/FreeRTOSConfig.h b/examples/device/hid_composite_freertos/src/FreeRTOSConfig.h index 0945baf1..494452d4 100644 --- a/examples/device/hid_composite_freertos/src/FreeRTOSConfig.h +++ b/examples/device/hid_composite_freertos/src/FreeRTOSConfig.h @@ -42,78 +42,11 @@ * See http://www.freertos.org/a00110.html. *----------------------------------------------------------*/ -// for OPT_MCU_ -#include "tusb_option.h" - -#if CFG_TUSB_MCU == OPT_MCU_LPC11UXX || CFG_TUSB_MCU == OPT_MCU_LPC13XX || \ - CFG_TUSB_MCU == OPT_MCU_LPC15XX || CFG_TUSB_MCU == OPT_MCU_LPC175X_6X || \ - CFG_TUSB_MCU == OPT_MCU_LPC177X_8X || CFG_TUSB_MCU == OPT_MCU_LPC18XX || \ - CFG_TUSB_MCU == OPT_MCU_LPC40XX || CFG_TUSB_MCU == OPT_MCU_LPC43XX - #include "chip.h" - -#elif CFG_TUSB_MCU == OPT_MCU_LPC51UXX || CFG_TUSB_MCU == OPT_MCU_LPC54XXX || \ - CFG_TUSB_MCU == OPT_MCU_LPC55XX - #include "fsl_device_registers.h" - -#elif CFG_TUSB_MCU == OPT_MCU_NRF5X - #include "nrf.h" - -#elif CFG_TUSB_MCU == OPT_MCU_SAMD21 || CFG_TUSB_MCU == OPT_MCU_SAMD51 - #include "sam.h" - -#elif CFG_TUSB_MCU == OPT_MCU_SAMG - #undef LITTLE_ENDIAN // hack to suppress "LITTLE_ENDIAN" redefined - #include "sam.h" - -#elif CFG_TUSB_MCU == OPT_MCU_STM32F0 - #include "stm32f0xx.h" - -#elif CFG_TUSB_MCU == OPT_MCU_STM32F1 - #include "stm32f1xx.h" - -#elif CFG_TUSB_MCU == OPT_MCU_STM32F2 - #include "stm32f2xx.h" - -#elif CFG_TUSB_MCU == OPT_MCU_STM32F3 - #include "stm32f3xx.h" - -#elif CFG_TUSB_MCU == OPT_MCU_STM32F4 - #include "stm32f4xx.h" - -#elif CFG_TUSB_MCU == OPT_MCU_STM32F7 - #include "stm32f7xx.h" - -#elif CFG_TUSB_MCU == OPT_MCU_STM32H7 - #include "stm32h7xx.h" - -#elif CFG_TUSB_MCU == OPT_MCU_STM32L0 - #include "stm32l0xx.h" - -#elif CFG_TUSB_MCU == OPT_MCU_STM32L1 - #include "stm32l1xx.h" - -#elif CFG_TUSB_MCU == OPT_MCU_STM32L4 - #include "stm32l4xx.h" - -#elif CFG_TUSB_MCU == OPT_MCU_MIMXRT10XX - #include "fsl_device_registers.h" - -#elif CFG_TUSB_MCU == OPT_MCU_NUC120 - #include "NUC100Series.h" - -#elif CFG_TUSB_MCU == OPT_MCU_NUC121 || CFG_TUSB_MCU == OPT_MCU_NUC126 - #include "NuMicro.h" - -#elif CFG_TUSB_MCU == OPT_MCU_NUC505 - #include "NUC505Series.h" - -#else - #error "FreeRTOSConfig.h need to include low level mcu header for configuration" -#endif +// Include MCU header +#include "bsp/board_mcu.h" extern uint32_t SystemCoreClock; - /* Cortex M23/M33 port configuration. */ #define configENABLE_MPU 0 #define configENABLE_FPU 1 diff --git a/examples/make.mk b/examples/make.mk index 78581f81..319ceece 100644 --- a/examples/make.mk +++ b/examples/make.mk @@ -80,7 +80,7 @@ ifneq ($(LOG),) CFLAGS += -DCFG_TUSB_DEBUG=$(LOG) endif -# Logger: default is UART, can be set to RTT +# Logger: default is uart, can be set to rtt or swo ifeq ($(LOGGER),rtt) RTT_SRC = lib/SEGGER_RTT @@ -88,4 +88,8 @@ ifeq ($(LOGGER),rtt) INC += $(TOP)/$(RTT_SRC)/RTT SRC_C += $(RTT_SRC)/RTT/SEGGER_RTT_printf.c SRC_C += $(RTT_SRC)/RTT/SEGGER_RTT.c + +else ifeq ($(LOGGER),swo) + CFLAGS += -DLOGGER_SWO + endif diff --git a/examples/readme.md b/examples/readme.md index 09278722..ae7b0a11 100644 --- a/examples/readme.md +++ b/examples/readme.md @@ -44,13 +44,23 @@ $ make LOG=2 BOARD=feather_nrf52840_express all ### Logger -By default log message is printed via on-board UART which is slow and take lots of CPU time comparing to USB speed. If your board support on-board/external JLink debugger, it would be more efficient to use it with [RTT protocol](https://www.segger.com/products/debug-probes/j-link/technology/about-real-time-transfer/) for logging. To do that add option `LOGGER=rtt` to build command e.g +By default log message is printed via on-board UART which is slow and take lots of CPU time comparing to USB speed. If your board support on-board/external debugger, it would be more efficient to use it for logging. There are 2 protocols: + +- `LOGGER=rtt`: use [Segger RTT protocol](https://www.segger.com/products/debug-probes/j-link/technology/about-real-time-transfer/) + - Cons: requires jlink as the debugger. + - Pros: work with most if not all MCUs + - Software viewer is JLink RTT Viewer/Client/Logger which is bundled with JLink driver package. +- `LOGGER=swo`: Use dedicated SWO pin of ARM Cortex SWD debug header. + - Cons: only work with ARM Cortex MCUs minus M0 + - Pros: even faster than RTT, and should be compatible with hardware and software debugger that support SWO. + - Software viewer is JLink SWO Viewer which is also bundled with JLink driver package. ``` $ make LOG=2 LOGGER=rtt BOARD=feather_nrf52840_express all +$ make LOG=2 LOGGER=swo BOARD=feather_nrf52840_express all ``` -The log can be retrieved by JLink RTT Viewer/Client/Logger software which is bundled with their JLink driver. +The log can be retrieved by ## Flash diff --git a/hw/bsp/board.c b/hw/bsp/board.c index 55236668..56f40732 100644 --- a/hw/bsp/board.c +++ b/hw/bsp/board.c @@ -37,7 +37,8 @@ // newlib read()/write() retarget //--------------------------------------------------------------------+ -#ifdef LOGGER_RTT +#if defined(LOGGER_RTT) +// Logging with RTT #include "SEGGER_RTT.h" @@ -54,9 +55,31 @@ TU_ATTR_USED int sys_read (int fhdl, char *buf, size_t count) return SEGGER_RTT_Read(0, buf, count); } +#elif defined(LOGGER_SWO) +// Logging with SWO for ARM Cortex + +#include "board_mcu.h" + +TU_ATTR_USED int sys_write (int fhdl, const void *buf, size_t count) +{ + (void) fhdl; + uint8_t const* buf8 = (uint8_t const*) buf; + for(size_t i=0; i Date: Wed, 22 Apr 2020 19:19:17 +0700 Subject: [PATCH 2/2] clean up --- examples/readme.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/examples/readme.md b/examples/readme.md index ae7b0a11..8d3d2e41 100644 --- a/examples/readme.md +++ b/examples/readme.md @@ -60,8 +60,6 @@ $ make LOG=2 LOGGER=rtt BOARD=feather_nrf52840_express all $ make LOG=2 LOGGER=swo BOARD=feather_nrf52840_express all ``` -The log can be retrieved by - ## Flash `flash` target will use the default on-board debugger (jlink/cmsisdap/stlink/dfu) to flash the binary, please install those support software in advance. Some board use bootloader/DFU via serial which is required to pass to make command