J-Link Low-power mode debugging

From SEGGER Wiki
Revision as of 14:18, 21 May 2024 by Leon (talk | contribs) (Created page with "Many devices support low-power modes, also known as "sleep modes" or similar. When put into such a mode, the target saves power while waiting for an event, an interrupt or sim...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Many devices support low-power modes, also known as "sleep modes" or similar. When put into such a mode, the target saves power while waiting for an event, an interrupt or similar.
The implementation of such low power modes is up to the chip designer and can vary from one device to another.
On Cortex-M, for example, this is achieved by executing the WFI ("wait for interrupt") and WFE ("wait for event") instructions.

Problems

Unfortunately, low power modes are known to cause problems when used during debugging.
This is due to the fact that many implementations for low power modes limit (or even completely disable) the debug logic of the device:

  1. Some devices disable the whole debug unit during low power modes, causing J-Link to lose the connection to the device.
  2. Some keep the debug unit enabled but disable the internal flash and RAM, making it effectively impossible for J-Link to perform background memory accesses while the target is in a low-power mode.
    This makes is virtually impossible to use RTT reliably, as the target memory cannot be accessed the majority of time while the core is running.
    Halting the core causes the device to wake up and exit the low-power mode and the memory becomes available again.
  3. ...

Production programming

To connect to a target device via the debug interface, J-Link / Flasher needs to setup certain bits in the debug logic of the device. These bits as a side effect may prevent the target from entering a low-power mode.

It is a common use case to have the target enter a low-power mode following production programming, especially for battery powered devices.
Therefore, after closing a debug or programming session, J-Link clears the debug bits that have been set previously. Unfortunately, this does not mean that the target enters the low-power mode immediately. An additional toggle of the reset pin may be required to achieve this. It is not guaranteed that clearing the debug bits will put a device back into low-power modes it probably was taken out of, by setting the bits.

Recommended sequence:

  1. Program target via J-Flash
  2. Make sure that under OptionsProject settings → Production → Start application is checked and set to "via reset pin"
    JFlash StartApp.png

Alternatively:

  1. Program target via J-Flash etc.
  2. Exit J-Flash etc. (will clear the debug bits)
  3. Start J-Link Commander
  4. Issue "r0" followed by "r1" command (do NOT call "connect" or anything else!)
  5. Exit J-Link Commander
Note:
All the steps above assume that the reset pin of the target device is connected to J-Link and can be controlled by J-Link.

Solution

In general, the effects of low-power modes on debugging depend very much on the implementation of the low-power mode for the target in use.
Because of that, proper function of J-Link cannot be guaranteed when debugging a target device that makes use of a low-power mode.

The solution to any problems that arise when using J-Link in conjunction with a low-power mode is to not make use of any low-power modes.