Error: jtag status contains invalid mode value – communication failure = SOLVED!

This issue bugged me a long time, finally I solved it this evening. Debugging code on my PIP-Watch using my ST-LINK-v2 JTAG debugger was very painful because the debugger software — OpenOCD and GDB — kept failing randomly during debug sessions with a rather cryptic message:

Error: jtag status contains invalid mode value - communication failure
Polling target stm32f1x.cpu failed, GDB will be halted. Polling again in 100ms

I scratched my head, updated firmware in ST-Link, looked at JTAG/SWDIO signals using a scope… But nothing helped.

Finally I found this message in a discussion forum. The problem is in the low-power mode! When CPU core clock is halted the debugger connection fails and debug session is halted.

I am using low-power mode to halt CPU clock when OS is idle – in vApplicationIdleHook() function I have the __WFI() – wait for interrupt – intrinsic function.

The solution is either to entirely disable low-power modes, or allow low-power debugging in the DBGMCU_CR register:

1
DBGMCU_Config(DBGMCU_SLEEP | DBGMCU_STOP | DBGMCU_STANDBY, ENABLE);
DBGMCU_Config(DBGMCU_SLEEP | DBGMCU_STOP | DBGMCU_STANDBY, ENABLE);

This code must be executed during CPU initialization before any low-power mode is first activated. After this, debugger connections will be kept even in sleep, standby and stop modes. The problem is gone!

8 thoughts on “Error: jtag status contains invalid mode value – communication failure = SOLVED!”

    1. My quick measurement shows that power consumption is normally the same, but it goes up once debugger connects for the first time.

  1. Thank you for your wonderful post!
    I know that this is a silly question, but into which file should I put your code?
    Thank you.

  2. thanks for all
    i use stm32f103c8t6, ,linux mint, openstm32 and HAL lib.
    this is my code
    HAL_DBGMCU_EnableDBGSleepMode();
    HAL_DBGMCU_EnableDBGStopMode();
    HAL_DBGMCU_EnableDBGStandbyMode();

    now, i have headache because, this error

    Info : Previous state query failed, trying to reconnect
    Error: jtag status contains invalid mode value – communication failure
    Polling target STM32F103C8Tx.cpu failed, trying to reexamine
    Examination failed, GDB will be halted. Polling again in 3100ms

  3. Hi, thank you for raising this issue. It seems that the post you found and you mention here, it doesn’t open. You propose to add this:
    DBGMCU_Config(DBGMCU_SLEEP | DBGMCU_STOP | DBGMCU_STANDBY, ENABLE);
    But as a beginner, I don’t see where I have to add it. Could you please indicate where this should be added? thank you very much.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.