---
title: Serial Logging With STLINK
description: Learn how to perform serial logging with an STLINK debugger.
source_url: https://dev.blues.io/feather-mcus/serial-logging-with-stlink/
canonical_url: https://dev.blues.io/feather-mcus/serial-logging-with-stlink/
markdown_url: https://dev.blues.io/feather-mcus/serial-logging-with-stlink.md
---

# Serial Logging With STLINK

Programmers like the [STLINK-V3MINI](https://shop.blues.com/products/stlink-v3mini?utm_source=dev-blues\&utm_medium=web\&utm_campaign=store-link) include a virtual COM port (VCP) that allows them to function as a serial-to-USB adapter. When used with STM32-based microcontrollers like Blues Cygnet or Blues Swan, you can use the STLINK's `VCP_RX` and `VCP_TX` pins for serial logging.

Using the programmer for logging offers several advantages:

- **Single USB connection**: You don’t need a separate USB cable for serial logging. As long as the host is powered by other means, the same USB connection used to power the programmer also handles logs.
- **Persistent serial connection**: The serial link stays active even when the host is power-cycled, which is especially helpful for applications that frequently enter sleep mode.

> **Note:**
>
> - The STLINK's `VCP_RX` and `VCP_TX` pins map to:
>
>   - `PB10` and `PB11` on Blues Cygnet.
>   - `PG8` and `PG7` on Blues Swan.

The STLINK's `VCP_RX` and `VCP_TX` pins provide a UART interface. In general, to do your debug logging through these pins you can treat them as a standard UART interface.

The sections below show specific instructions you can follow when working with an STLINK for logging in Arduino and Zephyr.

## Arduino

When using the STLINK on Arduino you can use the `HardwareSerial` class to establish a serial connection through the STLINK’s `VCP_RX` and `VCP_TX` pins.

```c
HardwareSerial serialDebug(PIN_VCP_RX, PIN_VCP_TX);
```

Next, in `setup()`, initialize the serial interface by calling its `begin()` function with a baud rate:

```c
serialDebug.begin(115200);
```

After calling `begin()` to initialize the serial interface, it's often helpful to wait for the connection to become available—especially when relying on tools like a serial monitor that may need time to enumerate the device. The following code waits up to 5 seconds for the serial interface to become ready:

```c
serialDebug.begin(115200);
const size_t timeout_ms = 5000;
for (const size_t start_ms = millis(); !serialDebug && (millis() - start_ms) < timeout_ms;);
```

With the setup complete, you can use `print()` and `println()` as normal to log to your serial monitor.

```c
serialDebug.println("Testing...");
```

You can also use the STLINK’s serial connection as a way of [viewing Notecard debug logs](https://dev.blues.io/tools-and-sdks/firmware-libraries/arduino-library.md#debug-mode) with the `setDebugOutputStream()` method.

```c
Notecard notecard;
notecard.setDebugOutputStream(serialDebug);
```

When put together, here's a good starting point for an Arduino sketch that uses an STLINK for viewing debug logs.

```c
Notecard notecard;
HardwareSerial serialDebug(PIN_VCP_RX, PIN_VCP_TX);

void setup() {
  serialDebug.begin(115200);
  const size_t timeout_ms = 5000;
  for (const size_t start_ms = millis(); !serialDebug && (millis() - start_ms) < timeout_ms;);

  notecard.setDebugOutputStream(serialDebug);
  notecard.begin();
}
```

## Zephyr

The Zephyr board configuration for both Blues Swan and Blues Cygnet specifies `lpuart1` as the system console, which is connected to the STLINK’s virtual COM port. This means any `printk()` output or logging automatically appears over the STLINK USB connection.
