In the previous guide, you learned how to create and run basic applications written in C on the Flipper Zero.
Now, let's explore real-time debugging. It allows launching an application, pausing execution at any point, stepping through code line by line, and monitoring variable states and execution flow. This approach helps identify and fix significantly more bugs than testing without real-time debugging.
The Flipper Zero microcontroller’s SWD (Serial Wire Debug) interface is accessible through the device’s expansion port. You can connect a supported SWD probe to this interface to control program execution.
Therefore, you will need the following:
To use real-time debugging, you need a device that functions as a debug probe. This can be:
Your computer must have the necessary tools and libraries installed to compile and run applications on Flipper Zero. We recommend using a preconfigured package that automates this setup — uFBT (micro Flipper Build Tool). Install it by following the instructions in the uFBT repo.
Debugging must also be enabled on your Flipper Zero. To do this, set Settings > System > Debug to ON.
1. Connect the SWD probe to the Flipper Zero expansion port. If you are using a probe not specially designed for Flipper Zero, you need to connect 3 pins: SWCLK (pin 10), SWDIO (pin 12), and GND (pin 8/11/18). If your SWD probe provides a UART interface, it is helpful to connect it to the Flipper Zero USART (pins 13, 14). This serial port outputs logs and information about critical program crashes when they occur, aiding in debugging.
2. Connect the SWD probe to your computer. Most debuggers connect via USB cable, but the WiFi Devboard supports connection via USB or WiFi (see official documentation for details).
3. In Visual Studio Code, switch to debugging mode by clicking the debug icon in the left menu or use the keyboard shortcut Ctrl+Shift+D on Windows/Linux or Cmd+Shift+D on macOS. Select the debugger model and press the Play button.
4. Use the debug control buttons (reset, pause, run, step in, step out, and disconnect).
5. Set breakpoints by clicking to the left of the code line. Code execution will automatically pause when it reaches a line with a breakpoint.
6. View the call stack tree. When code execution is paused, you can view the call stack tree in the Call Stack window, showing the functions the processor has entered at the moment of the pause.
7. View variable values using the Variables, Watch, or Live Watch panels.
Watch the demo below to see how to debug Flipper Zero FAPs in VS Code: