Skip to content

Debugging, datasheets and reliability

The debugger, the 2 datasheet tables that matter most, and the capacitor that prevents random resets.

Explanation

Printing has limits: the crash can happen before the print, or the print itself can change the timing. The next tool is the hardware debugger. On Cortex-M chips, the SWD interface needs only 2 signals, SWDIO for data and SWCLK for the clock, plus ground. Nucleo boards include an ST-Link adapter, so you already have one. The Pico exposes its SWD pins but needs a Raspberry Pi Debug Probe (about USD 12) or a second Pico running the debugprobe firmware. The Arduino Uno has no SWD and no debugger; on that board, continue to use prints or borrow a Nucleo for this lesson. With a debugger you can stop the program anywhere, step through it one line at a time, and inspect every variable and register.

Datasheets are long, but they consist mostly of tables. Start with 2 of them. The Absolute Maximum Ratings table lists the limits beyond which the part may be permanently damaged; it is not a working range. The Recommended Operating Conditions table, always lower, gives the range in which the part is designed to work. If the maximum is 4.0 V, do not run the part at 3.9 V.

Beginners often skip one rule of board design: place a 100 nF capacitor right next to every supply pin of the MCU. Digital logic draws current in very short spikes when it switches, and the supply wiring cannot deliver them fast enough. The capacitor acts as a small local reservoir. Without it, you get random resets and unpredictable behaviour that no code change can fix. Ready-made boards already have these capacitors. Your first PCB design will not, unless you add them.

Real products also must not rely on the code never hanging. A watchdog timer resets the MCU unless the firmware confirms, at regular intervals, that it is running correctly. This is called feeding the watchdog. If the program stops responding, the reset restarts it. Once your project runs unattended, enable the watchdog.

Key points

  • SWD debugging needs SWDIO, SWCLK and ground. Nucleo boards include the adapter, the Pico needs a Debug Probe, and the Uno has none.
  • Absolute maximum is a damage limit, not an operating range.
  • Place a 100 nF capacitor next to every supply pin.
  • A watchdog resets the chip if the firmware stops feeding it.

Check your understanding

4 questions on this lesson. An explanation follows each answer.

Sign in to answer the questions. Your answers count towards your level.

Sign in

You can read the lesson and the project without an account.

Project

First complete device: a small weather station

What you need

  • Everything from the earlier lessons: the board, the I2C sensor, the button, the LED and serial output.
  • Optional: the OLED display.

Steps

  1. 1Combine the parts: read the sensor once a second, show the reading on serial and on the display if you have one, and use the button to switch between readings.
  2. 2On a board with a debugger (a Nucleo, or a Pico with a Debug Probe), set a breakpoint in the sensor reading code and step through one measurement. Inspect the raw register values before they are converted into a temperature.
  3. 3Look up your MCU's absolute maximum supply voltage and its recommended range, and record both in a comment at the top of main.
  4. 4Enable the watchdog with a timeout of about 1 second and feed it in the main loop. Then add a deliberate endless loop, triggered by the button, and confirm that the board resets itself. From now on, pausing at a breakpoint for longer than the timeout also resets the board, unless you configure the debugger to freeze the watchdog while halted (on STM32, this is the IWDG option under DBGMCU). Freeze the watchdog or disable it before you return to stepping through code.

Done when

The device runs on its own, you have stepped through it in the debugger, and the watchdog recovers from a hang without the reset button.