Report watchdog restarts and which loop step stalled

Open
#256 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
76/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Active
Tech stack
c
Domain
embedded-iot

Research direction

Read src/utils/watchdog.cpp and src/hello_robot.cpp, especially run() and crash_report(), then compare how teensy4/CrashReport.cpp reads SRC_SRSR and how teensy4/imxrt.h defines its watchdog bit. Trace the main loop steps and watchdog callback; test on a bare Teensy with a temporary forced hang, removing it before opening a PR. Done means a watchdog restart logs its cause and last loop step, while normal power-on logs no watchdog message.

Written by the indexing model from the issue text.

Description

good first issue not started

When the main loop stalls, the watchdog restarts the Teensy, but nothing tells us it was the watchdog or which part of the loop hung. See the TODO in src/utils/watchdog.cpp ("Read and print a flag to identify the cause of stall").

Good first task. Needs a bare Teensy, no robot.

Files

  • src/utils/watchdog.cpp, src/utils/watchdog.hpp
  • src/hello_robot.cpp (run() and crash_report())
  • teensy4/CrashReport.cpp (reference, reads SRC_SRSR around line 160)
  • teensy4/imxrt.h (SRC_SRSR_* bits)

Steps

  1. Our watchdog is WDT_T4<WDT1>, which sets the SRC_SRSR_WDOG_RST_B bit in SRC_SRSR on reset. CrashReport.breadcrumb(n, value) stores a value that survives a restart.
  2. In HelloRobot::run(), before each main step (sensors, controls, comms, ...), record a step number with CrashReport.breadcrumb(1, step). Use a small enum for the steps.
  3. At boot, before crash_report(), read SRC_SRSR. If the watchdog bit is set, log "Restarted by watchdog" and the last step via SystemLog.
  4. Don't clear SRC_SRSR yourself; CrashReport reads it too. Check CrashReport.cpp before writing to the register.
  5. Fill in the TODO in watchdog_callback() by printing the current step there as well.
  6. Test on a bare Teensy with a temporary forced hang (while (true) {} inside one step). Remove it before opening the PR.

Done when

  • After a forced hang, the next boot says the watchdog caused the restart and names the step.
  • A normal power-on prints no watchdog message.

Related: #211 (safety asserts currently end in a watchdog reset).

Dominant language
C
Stars
11
Forks
2
Avg merge
18d 3h
Merged PRs (30d)
3

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from CU-Robotics/firmware

All issues in CU-Robotics/firmware

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.