stm32h743: make debugger attach more reliable

Add an optional sequence in the startup code to disable clock
gating when the CPU goes to sleep. Normally the D1 and D3 domain
clocks can be automatically gated when the CPU is asleep, and
because the debug infrastructure is clocked from these domains,
the debugger cannot attach when those clocks are stopped.

Setting some bits in DBGMCU_CR prevents this problem, but will
increase power consumption, hence it isn't enabled by default.

Change-Id: Iba87750371a493adf72655aab86a908ef2702cef
This commit is contained in:
Aidan MacDonald 2025-09-05 08:19:06 +01:00 committed by Solomon Peachy
parent 4b9b2c510e
commit 025f3def04
2 changed files with 26 additions and 0 deletions

View file

@ -27,6 +27,7 @@
#include "regs/stm32h743/pwr.h"
#include "regs/stm32h743/syscfg.h"
#include "regs/stm32h743/flash.h"
#include "regs/stm32h743/dbgmcu.h"
/* EXT timer is 1/8th of CPU clock */
#define SYSTICK_FREQ (CPU_FREQ / 8)
@ -168,6 +169,10 @@ static void stm_init_lse(void)
void system_init(void)
{
#if defined(DEBUG)
system_debug_enable(true);
#endif
/* Ensure IRQs are disabled and set vector table address */
disable_irq();
reg_var(CM_SCB_VTOR) = (uint32_t)__vectors_arm;
@ -192,6 +197,23 @@ void system_init(void)
fmc_init();
}
void system_debug_enable(bool enable)
{
/*
* Debug infrastructure is split across D3 and D1 power domains and
* normally these domains can be automatically clock gated when the
* CPU enters sleep mode. Because of this, the debugger might not be
* able to properly attach if the CPU is in sleep mode.
*
* Overriding clock gating using DBGMCU_CR makes debugger attaches
* more reliable, although it will increase power consumption.
*/
reg_writef(DBGMCU_CR,
D1DBGCKEN(enable),
D3DBGCKEN(enable),
DBGSLEEP_D1(enable));
}
void tick_start(unsigned int interval_in_ms)
{
(void)interval_in_ms;

View file

@ -23,6 +23,10 @@
#include "system-arm.h"
#include "cpucache-armv7m.h"
#include <stdbool.h>
/* Enable/disable debug clock domain during sleep mode. */
void system_debug_enable(bool enable);
/* Implemented by the target -- can be a no-op if not needed */
void gpio_init(void) INIT_ATTR;