This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

RTT Logging not working when building with ARM GCC

Hi,

I'm trying to use RTT Logging in my application. If I build and flash my application through Segger Embedded Studio RTT logging works. However If I use ARM GCC to build the application and nrfjprog to flash RTT logging does not work. 

NRF_LOG and BACKEND_RTT is enabled in my sdk_config.h and I'm doing the following calls in main:

APP_ERROR_CHECK(NRF_LOG_INIT(NULL));
NRF_LOG_DEFAULT_BACKENDS_INIT();


For ARM GCC I'm using the generic linker file inside the SDK folder config/nrf52840/generic_gcc_nrf52.ld, with a slight modification to the RAM_START and RAM_SIZE to allow for multiple connections. 

Are there any more modifications that needs to be done in order to enable RTT Logging when using ARM GCC? 

As a side note: UART Backend logging works without any issues when I build with ARM GCC

board: nRF52840 Preview DK

SDK: v15

Softdevice: 6.0.0

Br,
Anton

Parents
  • Hi,

    Which version of ARM GCC do you use? We have seen issues with ARM GCC 7.x.x and link time optimization (LTO). (Therefor, the SDK is still tested using version 6.3.1).

  • One more thing I forgot to mention in the original post is that before I changed the RAM_START and RAM_SIZE the RTT output worked. However then the application doesn't work since there is not enough memory for the softdevice. 

  • Hi,

    The application is verified to run on the device, I can see that the device's advertisement appears in the nRF Connect app and as stated previously UART Logging works (I have modified the print statements to make sure its the correct application running).

    To flash the device using nrfjprog I use the following commands:

    ./nrfjprog --eraseall --family NRF52
    ./nrfjprog --reset --program PATH_TO_SOFTDEVICE --family NRF52 --verify
    ./nrfjprog --reset --program PATH_TO_APPLICATION_HEX --family NRF52 --verify

  • I see, then that is not it. Could it be related to LTO somehow (similar to what is described in this post)? Do you enable LTO in your Makefile (-flto)? If so, can you see what happens if you disable it?

  • PROJECT_NAME     := checkout_pod_pca10056
    TARGETS          := nrf52840_xxaa
    OUTPUT_DIRECTORY := _build
    
    SDK_ROOT := ../../../../sdk/nRF5_SDK_15.0.0_a53641a
    PROJ_DIR := ../../../src
    
    $(OUTPUT_DIRECTORY)/nrf52840_xxaa.out: \
      LINKER_SCRIPT  := checkout_pod_nrf52.ld
    
    # Source files common to all targets
    SRC_FILES += \
      $(PROJ_DIR)/ble_checkout_pod.c \
      $(PROJ_DIR)/connect_zone_service.c \
      $(PROJ_DIR)/detect_zone_advertiser.c \
      $(PROJ_DIR)/coupon_io.c \
      $(PROJ_DIR)/main.c \
      $(PROJ_DIR)/usb.c \
      $(PROJ_DIR)/application/application.c \
      $(PROJ_DIR)/application/coupon.c \
      $(PROJ_DIR)/application/coupon_entry.c \
      $(PROJ_DIR)/application/csv.c \
      $(PROJ_DIR)/application/fifo_buffer.c \
      $(PROJ_DIR)/../../common_src/adv_timer.c \
      $(PROJ_DIR)/../../common_src/ble_pod.c \
      $(PROJ_DIR)/../../common_src/gpio.c \
      $(PROJ_DIR)/../../common_src/led.c \
      $(PROJ_DIR)/../../common_src/led_blinker.c \
      $(PROJ_DIR)/../../common_src/led_service.c \
      $(SDK_ROOT)/modules/nrfx/mdk/gcc_startup_nrf52840.S \
      $(SDK_ROOT)/components/libraries/experimental_log/src/nrf_log_backend_rtt.c \
      $(SDK_ROOT)/components/libraries/experimental_log/src/nrf_log_backend_serial.c \
      $(SDK_ROOT)/components/libraries/experimental_log/src/nrf_log_backend_uart.c \
      $(SDK_ROOT)/components/libraries/experimental_log/src/nrf_log_default_backends.c \
      $(SDK_ROOT)/components/libraries/experimental_log/src/nrf_log_frontend.c \
      $(SDK_ROOT)/components/libraries/experimental_log/src/nrf_log_str_formatter.c \
      $(SDK_ROOT)/components/libraries/button/app_button.c \
      $(SDK_ROOT)/components/libraries/util/app_error.c \
      $(SDK_ROOT)/components/libraries/util/app_error_handler_gcc.c \
      $(SDK_ROOT)/components/libraries/util/app_error_weak.c \
      $(SDK_ROOT)/components/libraries/fifo/app_fifo.c \
      $(SDK_ROOT)/components/libraries/scheduler/app_scheduler.c \
      $(SDK_ROOT)/components/libraries/timer/app_timer.c \
      $(SDK_ROOT)/components/libraries/usbd/app_usbd.c \
      $(SDK_ROOT)/components/libraries/usbd/app_usbd_core.c \
      $(SDK_ROOT)/components/libraries/usbd/class/dummy/app_usbd_dummy.c \
      $(SDK_ROOT)/components/libraries/usbd/class/hid/app_usbd_hid.c \
      $(SDK_ROOT)/components/libraries/usbd/class/hid/kbd/app_usbd_hid_kbd.c \
      $(SDK_ROOT)/components/libraries/usbd/class/hid/mouse/app_usbd_hid_mouse.c \
      $(SDK_ROOT)/components/libraries/usbd/app_usbd_string_desc.c \
      $(SDK_ROOT)/components/libraries/uart/app_uart_fifo.c \
      $(SDK_ROOT)/components/libraries/util/app_util_platform.c \
      $(SDK_ROOT)/components/libraries/cli/nrf_cli.c \
      $(SDK_ROOT)/components/libraries/hardfault/hardfault_implementation.c \
      $(SDK_ROOT)/components/libraries/util/nrf_assert.c \
      $(SDK_ROOT)/components/libraries/atomic_fifo/nrf_atfifo.c \
      $(SDK_ROOT)/components/libraries/atomic_flags/nrf_atflags.c \
      $(SDK_ROOT)/components/libraries/atomic/nrf_atomic.c \
      $(SDK_ROOT)/components/libraries/balloc/nrf_balloc.c \
      $(SDK_ROOT)/components/libraries/queue/nrf_queue.c \
      $(SDK_ROOT)/external/fprintf/nrf_fprintf.c \
      $(SDK_ROOT)/external/fprintf/nrf_fprintf_format.c \
      $(SDK_ROOT)/components/libraries/fstorage/nrf_fstorage.c \
      $(SDK_ROOT)/components/libraries/fstorage/nrf_fstorage_sd.c \
      $(SDK_ROOT)/components/libraries/experimental_memobj/nrf_memobj.c \
      $(SDK_ROOT)/components/libraries/pwr_mgmt/nrf_pwr_mgmt.c \
      $(SDK_ROOT)/components/libraries/experimental_section_vars/nrf_section_iter.c \
      $(SDK_ROOT)/components/libraries/strerror/nrf_strerror.c \
      $(SDK_ROOT)/components/libraries/uart/retarget.c \
      $(SDK_ROOT)/modules/nrfx/mdk/system_nrf52840.c \
      $(SDK_ROOT)/components/boards/boards.c \
      $(SDK_ROOT)/integration/nrfx/legacy/nrf_drv_clock.c \
      $(SDK_ROOT)/integration/nrfx/legacy/nrf_drv_uart.c \
      $(SDK_ROOT)/integration/nrfx/legacy/nrf_drv_rng.c \
      $(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_clock.c \
      $(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_gpiote.c \
      $(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_power_clock.c \
      $(SDK_ROOT)/modules/nrfx/drivers/src/prs/nrfx_prs.c \
      $(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_uart.c \
      $(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_uarte.c \
      $(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_rng.c \
      $(SDK_ROOT)/components/drivers_nrf/usbd/nrf_drv_usbd.c \
      $(SDK_ROOT)/components/libraries/bsp/bsp.c \
      $(SDK_ROOT)/components/libraries/bsp/bsp_btn_ble.c \
      $(PROJ_DIR)/main.c \
      $(SDK_ROOT)/components/ble/common/ble_advdata.c \
      $(SDK_ROOT)/components/ble/ble_advertising/ble_advertising.c \
      $(SDK_ROOT)/components/ble/common/ble_conn_params.c \
      $(SDK_ROOT)/components/ble/common/ble_conn_state.c \
      $(SDK_ROOT)/components/ble/ble_link_ctx_manager/ble_link_ctx_manager.c \
      $(SDK_ROOT)/components/ble/common/ble_srv_common.c \
      $(SDK_ROOT)/components/ble/nrf_ble_gatt/nrf_ble_gatt.c \
      $(SDK_ROOT)/components/ble/nrf_ble_qwr/nrf_ble_qwr.c \
      $(SDK_ROOT)/components/ble/ble_services/ble_nus/ble_nus.c \
      $(SDK_ROOT)/components/softdevice/common/nrf_sdh.c \
      $(SDK_ROOT)/components/softdevice/common/nrf_sdh_ble.c \
      $(SDK_ROOT)/components/softdevice/common/nrf_sdh_soc.c \
      $(SDK_ROOT)/external/segger_rtt/SEGGER_RTT.c \
      $(SDK_ROOT)/external/segger_rtt/SEGGER_RTT_Syscalls_GCC.c \
      $(SDK_ROOT)/external/segger_rtt/SEGGER_RTT_printf.c \
    
    # Include folders common to all targets
    INC_FOLDERS += \
      $(PROJ_DIR)/ \
      $(PROJ_DIR)/application \
      $(PROJ_DIR)/../../common_src \
      $(SDK_ROOT)/components/ble/ble_services/ble_ancs_c \
      $(SDK_ROOT)/components/ble/ble_services/ble_ias_c \
      $(SDK_ROOT)/components/libraries/pwm \
      $(SDK_ROOT)/components/libraries/usbd/class/cdc/acm \
      $(SDK_ROOT)/components/libraries/usbd/class/hid/generic \
      $(SDK_ROOT)/components/libraries/usbd/class/msc \
      $(SDK_ROOT)/components/libraries/usbd/class/hid \
      $(SDK_ROOT)/modules/nrfx/hal \
      $(SDK_ROOT)/components/libraries/experimental_log \
      $(SDK_ROOT)/components/libraries/fstorage \
      $(SDK_ROOT)/components/libraries/mutex \
      $(SDK_ROOT)/components/libraries/gfx \
      $(SDK_ROOT)/components/libraries/experimental_log/src \
      $(SDK_ROOT)/components/libraries/bootloader/ble_dfu \
      $(SDK_ROOT)/components/libraries/fifo \
      $(SDK_ROOT)/components/boards \
      $(SDK_ROOT)/components/libraries/experimental_memobj \
      $(SDK_ROOT)/components/ble/ble_advertising \
      $(SDK_ROOT)/modules/nrfx/drivers/include \
      $(SDK_ROOT)/components/libraries/experimental_task_manager \
      $(SDK_ROOT)/components/softdevice/s140/headers/nrf52 \
      $(SDK_ROOT)/components/libraries/queue \
      $(SDK_ROOT)/components/libraries/pwr_mgmt \
      $(SDK_ROOT)/components/ble/ble_dtm \
      $(SDK_ROOT)/components/toolchain \
      $(SDK_ROOT)/components/toolchain/cmsis/include \
    	$(SDK_ROOT)/components/toolchain/gcc \
      $(SDK_ROOT)/components/ble/common \
      $(SDK_ROOT)/components/libraries/bsp \
      $(SDK_ROOT)/components/libraries/experimental_section_vars \
      $(SDK_ROOT)/components/libraries/delay \
      $(SDK_ROOT)/components/libraries/experimental_mpu \
      $(SDK_ROOT)/components/libraries/mem_manager \
      $(SDK_ROOT)/components/libraries/usbd/config \
      $(SDK_ROOT)/components/softdevice/common \
      $(SDK_ROOT)/components/libraries/usbd/class/hid/mouse \
      $(SDK_ROOT)/components/libraries/low_power_pwm \
      $(SDK_ROOT)/external/fprintf \
      $(SDK_ROOT)/components/libraries/atomic \
      $(SDK_ROOT)/components \
      $(SDK_ROOT)/components/libraries/scheduler \
      $(SDK_ROOT)/components/libraries/cli \
      $(SDK_ROOT)/components/ble/ble_services/ble_lbs \
      $(SDK_ROOT)/components/ble/ble_services/ble_hts \
      $(SDK_ROOT)/components/ble/ble_services/ble_cts_c \
      $(SDK_ROOT)/components/libraries/util \
      ../config \
      $(SDK_ROOT)/components/libraries/usbd/class/cdc \
      $(SDK_ROOT)/components/libraries/csense \
      $(SDK_ROOT)/components/libraries/balloc \
      $(SDK_ROOT)/components/libraries/ecc \
      $(SDK_ROOT)/components/libraries/hardfault \
      $(SDK_ROOT)/components/libraries/uart \
      $(SDK_ROOT)/components/libraries/hci \
      $(SDK_ROOT)/components/libraries/usbd/class/hid/kbd \
      $(SDK_ROOT)/components/libraries/timer \
      $(SDK_ROOT)/components/softdevice/s140/headers \
      $(SDK_ROOT)/integration/nrfx \
      $(SDK_ROOT)/components/libraries/sortlist \
      $(SDK_ROOT)/components/libraries/spi_mngr \
      $(SDK_ROOT)/components/libraries/experimental_stack_guard \
      $(SDK_ROOT)/components/libraries/led_softblink \
      $(SDK_ROOT)/components/libraries/sdcard \
      $(SDK_ROOT)/modules/nrfx/mdk \
      $(SDK_ROOT)/components/ble/ble_link_ctx_manager \
      $(SDK_ROOT)/components/libraries/strerror \
      $(SDK_ROOT)/components/libraries/crc32 \
      $(SDK_ROOT)/components/libraries/usbd/class/audio \
      $(SDK_ROOT)/components/ble/peer_manager \
      $(SDK_ROOT)/components/drivers_nrf/usbd \
      $(SDK_ROOT)/components/ble/nrf_ble_gatt \
      $(SDK_ROOT)/components/ble/nrf_ble_qwr \
      $(SDK_ROOT)/components/libraries/gpiote \
      $(SDK_ROOT)/components/libraries/button \
      $(SDK_ROOT)/modules/nrfx \
      $(SDK_ROOT)/integration/nrfx/legacy \
      $(SDK_ROOT)/components/libraries/usbd \
      $(SDK_ROOT)/components/libraries/block_dev \
      $(SDK_ROOT)/external/segger_rtt \
      $(SDK_ROOT)/components/libraries/atomic_fifo \
      $(SDK_ROOT)/components/libraries/experimental_ringbuf \
      $(SDK_ROOT)/components/libraries/fds \
      $(SDK_ROOT)/components/libraries/atomic_flags \
    
    # Libraries common to all targets
    LIB_FILES += \
    
    # Optimization flags
    OPT = -O3 -g3
    # Uncomment the line below to enable link time optimization
    #OPT += -flto
    
    # C flags common to all targets
    CFLAGS += $(OPT)
    CFLAGS += -DBOARD_PCA10056
    CFLAGS += -DCONFIG_GPIO_AS_PINRESET
    CFLAGS += -DFLOAT_ABI_HARD
    CFLAGS += -DNRF52840_XXAA
    CFLAGS += -DNRF_SD_BLE_API_VERSION=6
    CFLAGS += -DS140
    CFLAGS += -DSOFTDEVICE_PRESENT
    CFLAGS += -DSWI_DISABLE0
    CFLAGS += -DHW_NINA_B3
    CFLAGS += -mcpu=cortex-m4
    CFLAGS += -mthumb -mabi=aapcs
    CFLAGS += -Wall -Werror -Wno-unused-result -Wunused-value -Wunused-local-typedefs
    CFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16
    # keep every function in a separate section, this allows linker to discard unused ones
    CFLAGS += -ffunction-sections -fdata-sections -fno-strict-aliasing
    CFLAGS += -fno-builtin -fshort-enums
    
    # C++ flags common to all targets
    CXXFLAGS += $(OPT)
    
    # Assembler flags common to all targets
    ASMFLAGS += -g3
    ASMFLAGS += -mcpu=cortex-m4
    ASMFLAGS += -mthumb -mabi=aapcs
    ASMFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16
    ASMFLAGS += -DBOARD_PCA10056
    ASMFLAGS += -DCONFIG_GPIO_AS_PINRESET
    ASMFLAGS += -DFLOAT_ABI_HARD
    ASMFLAGS += -DNRF52840_XXAA
    ASMFLAGS += -DNRF_SD_BLE_API_VERSION=6
    ASMFLAGS += -DS140
    ASMFLAGS += -DSOFTDEVICE_PRESENT
    ASMFLAGS += -DSWI_DISABLE0
    
    # Linker flags
    LDFLAGS += $(OPT)
    LDFLAGS += -mthumb -mabi=aapcs -L$(SDK_ROOT)/modules/nrfx/mdk -T$(LINKER_SCRIPT)
    LDFLAGS += -mcpu=cortex-m4
    LDFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16
    # let linker dump unused sections
    LDFLAGS += -Wl,--gc-sections
    # use newlib in nano version
    LDFLAGS += --specs=nano.specs
    
    nrf52840_xxaa: CFLAGS += -D__HEAP_SIZE=8192
    nrf52840_xxaa: CFLAGS += -D__STACK_SIZE=8192
    nrf52840_xxaa: ASMFLAGS += -D__HEAP_SIZE=8192
    nrf52840_xxaa: ASMFLAGS += -D__STACK_SIZE=8192
    
    # Add standard libraries at the very end of the linker input, after all objects
    # that may need symbols provided by these libraries.
    LIB_FILES += -lc -lnosys -lm
    
    
    .PHONY: default help
    
    # Default target - first one defined
    default: nrf52840_xxaa
    
    # Print all targets that can be built
    help:
    	@echo following targets are available:
    	@echo		nrf52840_xxaa
    	@echo		flash_softdevice
    	@echo		sdk_config - starting external tool for editing sdk_config.h
    	@echo		flash      - flashing binary
    
    TEMPLATE_PATH := $(SDK_ROOT)/components/toolchain/gcc
    
    
    include $(TEMPLATE_PATH)/Makefile.common
    
    $(foreach target, $(TARGETS), $(call define_target, $(target)))
    
    .PHONY: flash flash_softdevice erase
    
    # Flash the program
    flash: $(OUTPUT_DIRECTORY)/nrf52840_xxaa.hex
    	@echo Flashing: $<
    	nrfjprog -f nrf52 --program $< --sectorerase
    	nrfjprog -f nrf52 --reset
    
    # Flash softdevice
    flash_softdevice:
    	@echo Flashing: s140_nrf52_6.0.0_softdevice.hex
    	nrfjprog -f nrf52 --program $(SDK_ROOT)/components/softdevice/s140/hex/s140_nrf52_6.0.0_softdevice.hex --sectorerase
    	nrfjprog -f nrf52 --reset
    
    erase:
    	nrfjprog -f nrf52 --eraseall
    
    SDK_CONFIG_FILE := ../config/sdk_config.h
    CMSIS_CONFIG_TOOL := $(SDK_ROOT)/external_tools/cmsisconfig/CMSIS_Configuration_Wizard.jar
    sdk_config:
    	java -jar $(CMSIS_CONFIG_TOOL) $(SDK_CONFIG_FILE)
    

    LTO was/is disabled. I have uploaded my Makefile as a txt file if you want to look at it. 

  • Yes, it would be very useful if you could reproduce this from an example project and upload the project here. Then I would hopefully be able to reproduce it on my side as well.

  • Hi,

    I can reproduce the issue. I used the example project ble_app_hrs. These are the following steps I took:

    1. Increase Peripheral Link Count and Total Link count to 20 in sdk_config.h
    2. Decrease the GATT and GAP data length to make enough memory for the Softdevice according to this thread: Nordic semi devzone
    3. Change the RAM ORIGIN to 0x20015290 and LENGTH to 0x2AD70

    Br,

    Anton

Reply Children
  • Hi Anton,

    Unfortunately, I have not been able to test this again on my side yet due to a busy morning, but I noticed something which I should have spotted earlier. In the printout from JLinkExe I see that you use the configuration for NRF52832_XXAA. So I suspect that what may be happening is that the RTT client is only looking for the RTT buffer within the nRF52832 RAM region, and this only have 64 kB RAM compared to 256 kB in the nRf52840. If the RTT buffer is placed in the upper half this is not found. If this is correct, then it sould be fixed by specifying that you have a nRF52840 device so that the RTT client will look for the RTT buffer in all of the RAM.

  • Hi Einar,

    Your suspicion were correct. After I changed the configuration to NRF52840_XXAA It started to print the RTT logs. Thank you very much for your assistance!

    Br,
    Anton

Related