Simulating Hardware Interrupts for Clion Step-Debugging for the Raspberry-Pi Pico

In this quick short tutorial we go over artificially clocking your chip to continue to enable step-debugging.

Simulating Hardware Interrupts for Clion Step-Debugging for the Raspberry-Pi Pico

Music of the Day: Chill Flow Programming Music!

Probably all of about 5 people on the planet that can benefit from this, but maybe one day it will help you.  Maybe it helps all kinds of embedded engineers..

  • Step-Debugging stops execution at a break-point and allows you to inspect the internal variables and run-state at that point.
  • Typically experienced developers will realistically see about a 5-800% fold increase in debugging by having this feature.
  • The problem arises on interrupts because human time is not the same as interrupt time as the interrupt may run in 10 microseconds while the stepping-debugging is a different time differential. It just doesn't work right and you get random breaks - because the interrupt runs outside the confine control and in the background from the debugger!

Artificial Clocking.

  • To remedy this we use artificial clocking, consider the following small code snippet that uses modulus ticks.
unsigned int gbl_counter = 0;

while (1)
  {
    gbl_counter++;
    if (gbl_counter % 5 == 0)
    {
      gbl_clk_triggered = true;  // Set Trigger
    }
    if (gbl_active && gbl_clk_triggered)
    {
      Cout.onClock();
      gbl_clk_triggered = false;  // Clear Trigger
    }
    if (gbl_counter % 50000 == 0)
    {
      printf("Big counter: %u \n", big_counter);
      printf("Sending fresh packet... \n");
      Cout.add_Packet(3, buffer, M4_PKT_PRIORITY_HIGH);
    }
  • Now step-debugging can fully arrest the clock.
  • On modulus 5 is a TICK
  • On modulus 50000 is a SIMULATED EVENT

This allows one to continue to simulate clock interrupts and still allow for clock debugging.

Linux Rocks Every Day