PlatformIO Community

Unit test custom STM32 board with ST-Link

Hi all,

I am using an ST-Link connected over SWD to a custom SMT32 board and am trying to implement unit testing. The only relevant example I can find - STM32Cube HAL and Nucleo-F401RE - relies on the UART interface of the MCU being connected to the Nucleo board’s integrated debugging interface.

How can I go about running my target-run unit tests through a regular, external, ST-Link? Note that I do have access to this MCU’s USB interface.

Thanks, Shane

The main goal is to transfer output from the board to your host machine. In order to do that you will need to implement custom transport as in the example. As the transport you can use the following options:

  • UART with UART-USB converter
  • Virtual COM port implemented via on-board USB
  • Virtual COM port implemented on STLink probe (only if hardware supports this feature)

Thanks for your reply!

Is there any additional configuration required for this as the returning data will be on a seperate COM port from the ST-Link? Or will PlatformIO auto-detect the second port?

You can always specify the test port manually.

I’ve set this up both with and without specifying the test port:

When I do specify it, PlatformIO says that it can’t open the port - I believe that PlatformIO is checking too early, before the board has begun it’s unit testing sequence. This may be because the COM port is first opened in unittest_uart_begin() ?

When I do no specify the port, PlatformIO displays the message If you don't see any output for the first 10 secs, please reset board (press reset button) then waits indefinitely, regardless of whether or not the board is reset.

Is there a way to continue trying for the specified test port every second or so instead of just throwing an error after an unsuccessful first attempt?

In addition to this, I can’t create a functioning USB-based unittest_transport.h

Is there any documentation or examples of this that I can reference?


1 Like

Did you find any way? I am facing same problem

1 Like

Have the same problem as well