In contrast to more modern boards, there is no internal serial connection between the target chip and the on-board debugger. A common solution is to use a USB serial interface converter, but is that the only way?

Hardware solution

The user manual recognises this issue and helpfully provides a diagram of the points you need to connect to use the built-in virtual com port.

image could not be loaded

After disassembling something from my electronics bin, I salvaged a bit of magnet wire and connected the points.

image could not be loaded

Testing using a simple hello world program went without witout a hitch.

Minicom output on reset:

�
Hello from the Discovery!

Note that the junk output also occurs on reset when using an external converter.

This solution makes the board act like newer STM dev boards, thus it might be the best solution when working with multiple different boards. It does however require that you are comfortable with soldering and own the board.

The same type of board is used in one of my favorite classes, soldering wasn’t an option but I wanted to help some classmates that used laptops with just a single usable USB port.

Software solution

We don’t actually need the serial output, we just want to see what the firmware is trying to communicate. And while the serial lines are not connected SWD is, and with that we have a high level of control over the target chip.

Using SWD debugging (trough the pyocd library) we can write a script to break on send_USART_str or any other function you are using.

...
addr = provider.get_symbol_value("send_USART_str")
target.set_breakpoint(addr, Target.BreakpointType.HW)
continue_until_halt(target)
target.remove_breakpoint(addr)

And read out the string that is passed to it.

char_pointer = target.read_core_register('r0')
char = target.read8(char_pointer)
string = ""
while char != 0:
    string += chr(char)
    char_pointer += 1
    char = target.read8(char_pointer)
print(string)

Python script output on reset:

Hello from the Discovery!

A full example script can be found here

It seems to be completely stable and doesn’t suffer from the floating line output after reset.