2025-02-02 05:43 PM
Hello,
I am looking up on how to capture printf output using ITM on my stm32H723ZG board. Most tutorials I see online are using some sort of IDE. I tried using CubeMX and it works there but I would like to use gdb/openocd since that is my preferred way of debugging.
I am wondering how is it possible to enable printf output using gdb/openocd combo? What setup needs to be done on the gdb side and on the openocd side?
Code wise, I know I have to implement the _write function which I have done below for GCC.
int _write(int fd, char *ptr, int len){
size_t i;
for(i=0; i<len;i++){
ITM_SendChar(ptr[i]);
}
return len;
}
Also i added in the --specs=nosys.specs flag in my makefile
Do i need to setup some ITM hardware as well? Part of the confusion for me is that when i used CubeMx it doesn't seem to generate any additional ITM setup code so I not sure if I need to do.
Here is what I have for my gdbscript:
target extended-remote localhost:3333
file build/bare_metal.elf
load
display /x $r0
display /x $r1
display /x $r2
display /x $r3
display /x $r4
display /x $msp
display /x $psp
display /x $control
display /x $lr
display /x $xPSR
monitor tpiu config internal itm.txt uart off 64000000 106667
monitor itm port 0 on
Here is my openocd:
# This is an NUCLEO-H723ZG board with a single STM32H723ZGTx chip
#
# Take care that such file, as generated, may be overridden without any early notice. Please have a look to debug launch configuration setup(s)
# https://github.com/zephyrproject-rtos/zephyr/issues/51508
# https://github.com/zephyrproject-rtos/zephyr/issues/50590
source [find interface/stlink-dap.cfg]
transport select dapdirect_swd
set WORKAREASIZE 0x8000
set CHIPNAME STM32H723ZGTx
set BOARDNAME NUCLEO-H723ZG
source [find target/stm32h7x.cfg]
# Enable debug when in low power modes
set ENABLE_LOW_POWER 1
# Stop Watchdog counters when halt
set STOP_WATCHDOG 1
# STlink Debug clock frequency
set CLOCK_FREQ 8000
# Reset configuration
# use hardware reset, connect under reset
# connect_assert_srst needed if low power mode application running (WFI...)
reset_config srst_only srst_nogate connect_assert_srst
set CONNECT_UNDER_RESET 1
set CORE_RESET 0
# ACCESS PORT NUMBER
set AP_NUM 0
# GDB PORT
set GDB_PORT 3333
# Due to the use of connect_assert_srst, running gdb requires
# to reset halt just after openocd init.
rename init old_init
proc init {} {
old_init
reset halt
}
~