zephyr: RTT is not working on STM32

Describe the bug I would like to use logging RTT backend with Segger RTTViwer but it does not work. My Segger J-Link is not able to find the RTT control block. Using the same setup with another board (nRF52840dk) does work without any problem.

To Reproduce Steps to reproduce the behavior:

  1. Use Blinky sample as the base
  2. use the following prj.conf
CONFIG_DEBUG=y

# RTT
CONFIG_USE_SEGGER_RTT=y

# console
CONFIG_RTT_CONSOLE=y
CONFIG_UART_CONSOLE=n

# shell
CONFIG_SHELL=y
CONFIG_SHELL_BACKENDS=y
CONFIG_SHELL_BACKEND_SERIAL=y
CONFIG_SHELL_PROMPT_UART="uart:~$ "

# logging
CONFIG_LOG=y
CONFIG_LOG_BACKEND_RTT=y
CONFIG_LOG_BACKEND_UART=n
CONFIG_SHELL_LOG_BACKEND=n

CONFIG_LOG_PROCESS_TRIGGER_THRESHOLD=10
CONFIG_LOG_PROCESS_THREAD=y
CONFIG_LOG_PROCESS_THREAD_SLEEP_MS=500
CONFIG_LOG_PROCESS_THREAD_STACK_SIZE=2048
CONFIG_LOG_BUFFER_SIZE=1024
CONFIG_LOG_DETECT_MISSED_STRDUP=y
#LOG Maximum string define
CONFIG_LOG_STRDUP_MAX_STRING=100
CONFIG_LOG_STRDUP_BUF_COUNT=4
  1. add LOG_xxx in main loop
void main(void)
{
	struct device *dev;
	bool led_is_on = true;
	int ret;

        printk("Blinky sample on board: %s\n", CONFIG_BOARD);

	dev = device_get_binding(LED0);
	if (dev == NULL) {
		return;
	}

	ret = gpio_pin_configure(dev, PIN, GPIO_OUTPUT_ACTIVE | FLAGS);
	if (ret < 0) {
		return;
	}

	while (1) {
                // printk("led: %d\n", led_is_on);
                // LOG_DBG("led: %d\n", led_is_on);
                LOG_INF("led: %d\n", led_is_on);
                // LOG_WRN("led: %d\n", led_is_on);
                // LOG_ERR("led: %d\n", led_is_on);
		gpio_pin_set(dev, PIN, (int)led_is_on);
		led_is_on = !led_is_on;
		k_msleep(SLEEP_TIME_MS);
	}
}
  1. Build and flash the application to board nucleo_l476rg successfully (the ST-Link on board was already replaced with JLink firmware)
  2. Open JLinkRTTViewer and connect successfully with SWD, RTT Control Block select “Auto” or “Address” 0x20000920
.bss._SEGGER_RTT
                0x0000000020000920       0xa8 zephyr/libzephyr.a(SEGGER_RTT.c.obj)
                0x0000000020000920                _SEGGER_RTT
  1. No log output in Terminal at all.
  2. I also use J-Mem, it connected ok, but all memory shows “00”.
  3. I tried on another board STM32F3 Discovery, the same problem.
  4. I also tried to use a real J-Link Plus probe, it has the same problem.

Expected behavior RTT logging should work to display in JLinkRTTViewer. Seems the memory is protected from being readout from SWD. The same program and settings works fine on nRF52840dk.

Environment (please complete the following information):

  • OS: MacOS
  • Toolchain: gnuarmemb gcc-arm-none-eabi-9-2019-q4-major
  • Commit SHA or Version used: 2.5-branch 6c2ae13e9a85f41dc421c206f28baf6eb71ba48e
  • JLink: SEGGER J-Link V6.98e

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 2
  • Comments: 33 (15 by maintainers)

Commits related to this issue

Most upvoted comments

@ghlualven, @mHendelja, @wthidden, @manoj153 would you mind testing #38561 ?

@jaybuckeye06 , @mass-anis , Thanks for your help, that is a good catch, enabling clock of DMA (either DMA1 or DMA2) works !!! As far as DBGMCU bits, it is not mandatory for STM32L476, but it is mandatory for STM32F103.

So I made a PR #38561 to activate DMA clock and setting one of DBGMCU bit. I hope it will be sufficient for all STM32 boards.