Skip to main content
Uwe Bonnes
Chief
March 9, 2020
Question

StlinkV3 fails to connect to STM32G474 using WFI

  • March 9, 2020
  • 6 replies
  • 1113 views

Hello,

I have a Nucleo-G474RE with a simple blinker program mostly in WFI, awaking every Millisecond. I can can warm connect with STlinkV2 e.g. by pyOCD, but with on-board StlinkV2 pyOCD reports

Exception reading AP#0 IDR: STLink error (5): No device connected

I can connect when the program does not use WFI.

This topic has been closed for replies.

6 replies

Piranha
Principal III
March 9, 2020

Enable the DBG_SLEEP bit in DBGMCU_CR register.

Uwe Bonnes
Chief
March 10, 2020

To enable DBG_SLEEP you need AP access. But as the error above tells, V3 fails to create the AP. So no chance to for any access! B.t.w. you first need to halt the CPU with DHCSR before you can write DBGMCU. But again, writing DHCSR needs AP access.

Piranha
Principal III
March 21, 2020

Enable it in code for debug builds before any WFI is executed! :) For example, system initialization is a good place.

Uwe Bonnes
Chief
March 21, 2020

Other debuggers can attach to the device in that situation. So it is some shortcoming of the StlinkV3.

Piranha
Principal III
March 22, 2020

For example SEGGER J-Link sets DBG_STANDBY | DBG_STOP|DBG_SLEEP bits before your code can execute WFI. ST-LINK (at least the on-board V2-1) doesn't do that. Apart form waiting on ST for a decades on simple things, another option is to add a debugger script.

# Enable Debug connection in low power modes (DBGMCU->CR)
set 0xE0042004 = (0xE0042004) | 0x7

http://blog.atollic.com/automate-your-gdb-debug-sessions-cortex-m-development

Uwe Bonnes
Chief
March 22, 2020

I knowe about those bits. But that changes nothing with the situation that e.g. pyOcd with StlinkV2 _can_ attach, while STLINKV3 does _not_ attach. This is a shortcoming of the StlinkV3 i.m.h.o.