Debug Output from Patch.Init() via STLINKv3

How can I print debug output and see it in the terminal or in VSCode?

When I do

int main(void)
{
patch.Init();
System::Delay(500);
patch.StartLog(true);

it hangs on the StartLog() line. I can debug in VSCode and see my variables.

The simple answer:

StartLog starts the Logger Serial connection over USB. The true argument means the seed will hang on that line until it detects the computer is connected.

You should get logging output if you connect the seed via USB. There are some VSCode extensions that will allow you to start the serial connection and watch the output there.

The more complicated answer:

The logger uses the USB by default, you can however set a logger up to use semihosting, which will make the serial connection through the debugger.

That would look something like this:

using Log = Logger<LOGGER_SEMIHOSTING>;

// to write and so on
Log::StartLog(true);
Log::PrintLine("print this string");

TBH I’ve never actually tried this so I’m not 100% what it looks like on the PC side and so on, you could probably use one of the previously mentioned Serial extensions.

1 Like

I tried this

using Log = Logger<LOGGER_SEMIHOST>;
Log::StartLog(true);
Log::PrintLine("print this string\n", 18);
Log::PrintLine("print this string\n", 18);
Log::PrintLine("print this string\n", 18);
Log::PrintLine("print this string\n", 18);

but no love. I tried a serial monitor in VSCode and Serial Tools.

Also tried flashing via the dfu but the serial port doesn’t appear if I connect directly without the STLINK

Did you try reading the log over USB without the semihosting stuff?
i.e. plugging USB straight into the daisy without the stlink and using your original code.

1 Like

Nah, I tried but for some reason I can’t program the dfu without the STLINK anymore.

➜ PickupMachine git:(main) ✗ make program
openocd -s /usr/local/share/openocd/scripts -f interface/stlink.cfg -f target/stm32h7x.cfg
-c “program ./build/PickupMachine.elf verify reset exit”
Open On-Chip Debugger 0.11.0
Licensed under GNU GPL v2
For bug reports, read
OpenOCD: Bug Reporting
Info : auto-selecting first available session transport “hla_swd”. To override use ‘transport select ’.
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
Info : clock speed 1800 kHz
Error: open failed
in procedure ‘program’
** OpenOCD init failed **
shutdown command invoked

Looks like you’re running the program task, which tries to use the debug probe. If it’s not connected it’ll throw those errors.

Instead, you can flash over USB without the debug probe with the program-dfu task.

  • First, “Put the Daisy into bootloader mode by holding the BOOT button down, and then pressing the RESET button. Once you release the RESET button, you can also let go of the BOOT button.”
  • Next run the command with Ctrl-P on Windows or Command-P on mac, then task build_and_program_dfu.

This is laid out nicely here with gifs and stuff.

Hope that helps!

1 Like

Thanks, I was able to program the module via usb that way and was able to see some debug output!

2 Likes