PostHeaderIcon MSP430G2312: Debugging a Device That Sleeps for a Living

The defining feature of a product built on this family is not its peripherals. It is that the core is asleep for almost the entire life of the product. A sensor node wakes for a few microseconds to sample, computes for a few hundred more, transmits, and returns to a mode where the main clock is stopped.

That design is correct engineering and it is hostile to a debug session. The interface is not disabled and the protection is not involved. The problem is that there is almost no time during which the core is in a state where a debugger can take control of it.

Why a sleeping device resists a connection

A debug connection is not a passive attachment. To halt the core, take a breakpoint, read memory through the core’s own address path, or start a flash operation, the tool needs the device in a state where those operations are meaningful.

In the deepest low-power modes the main clock is stopped and the core is held. Some operations still work, because the interface has its own clock and can reach memory directly. Others do not, and the ones that do not are usually the ones the extraction needs: anything that requires the core to execute, and anything that requires the flash controller to be timed.

The result is a connection that half succeeds. The tool identifies the device, reads a register or two, and then fails when it tries to do something that needs a running core.

The window problem

The more common failure is not the deep sleep itself but the duty cycle of wakefulness.

Phase Duration Debugger opportunity
Reset to first sleep Milliseconds Full control if caught here
Awake, sampling Microseconds to milliseconds One halt attempt, maybe
Asleep Seconds Interface only, core unavailable
Wake on interrupt Microseconds Race with the program’s own code

A tool that attempts to connect by polling will almost always poll during the long sleep, conclude that the device does not respond, and report a failure. The device is responding; it is simply not in a state where the request means anything.

The techniques that work

Four approaches, in the order they should be tried.

Catch the reset. Set a hardware breakpoint at the reset vector before releasing the device from reset. The program stops before it has a chance to enter its first low-power mode, and from that point the debugger is in control and the program can be single-stepped into the sleep and back out.

Hold the device in reset and configure first. Many tools allow the debug interface to be established while the core is held, so that breakpoints and configuration are in place before the first instruction executes.

Wake it externally. If the product has a wake source that can be triggered on demand — a button, a bus message, a sensor edge — generating that event on a controlled schedule turns an unpredictable window into a predictable one.

Change the wake period. On a unit that is not the only copy, or on a device whose program can be replaced, modifying the timer period to something short makes the device nearly continuously awake and removes the problem entirely.

The first is the correct default. It costs nothing, it works regardless of what the program does afterwards, and it fails only when the reset vector itself is not accessible.

Why the supply current matters

There is an electrical dimension to the same problem. A device in its deepest low-power mode draws so little current that some debug tools, which detect a target by measuring the supply, do not see one.

The symptom is a tool that reports no target while a multimeter shows the device is powered. The fix is to tell the tool to skip detection, or to power the board from a supply the tool controls.

This is worth knowing because it produces a failure that looks exactly like a hardware fault and is a configuration option.

What to read once you are in

With the core halted at the reset vector, the order of work is the one used on any other device, with one addition.

Read the vector table first, then the startup code. The startup code of a low-power design is unusually informative: it configures the clock system, sets up the wake sources, and initialises the peripherals that will be used after each wake. That sequence is a specification of the product’s power strategy, and on a device whose application logic is small, the power strategy is most of the design.

Next, identify the low-power mode transitions themselves. The instruction that enters a mode is distinctive, and the code around it shows what had to be done before sleeping and what is restored on wake. On a device that spends its life there, that code is the main loop.

When the device is genuinely closed

If the connection succeeds and the array is refused, the sleep behaviour is irrelevant and the protection question takes over. It is worth being clear that the two are separate: a device that will not connect is not evidence of protection, and a device that is protected may connect perfectly.

The behavioural observations that the low-power design makes available are, however, unusually rich. A device that sleeps and wakes on a schedule is producing a timing signature, and a device that transmits after each wake is producing a data signature. On a product that reports anything at all, that is a channel.

Related reading

FAQ

Does the debug interface stop working in low-power mode? It does not stop, but operations that need the core or a running clock do.

Why does the tool report no target on a powered board? Because the current is too low for the tool’s detection.

Can a breakpoint be set before the first instruction? Yes, and that is the standard technique for sleeping targets.

Is a sleeping device harder to extract than a busy one? Harder to connect to. The array itself is no different.

Conclusion

A device that sleeps is not a device that resists debugging; it is a device with a very small window. Catch the reset, hold the core before releasing it, and the window stops mattering. Everything after that is the ordinary work of reading an array that either opens or does not.

Comments are closed.