cancel
Showing results for 
Search instead for 
Did you mean: 

STLink emulator with Stop mode condition

davide_mp
Associate II

Hi everyone,
I have a problem, let's see if someone can help me...
I have a board that works with an STM32L053xxxx, my application, at a certain point, enters stop mode. Here comes the problem, the emulator disconnects.
Is there any technique or emulator that allows me to continue the emulation even in stop mode?

 

1 ACCEPTED SOLUTION

Accepted Solutions

OK !
Then, with Keil, STM32L053C8T6 and ST-Link V1, it is possible!!

The important thing is to enable the clock for the debugger...
Then, you enable the debugger for the desired condition, in my case for the stop condition:

RCC->APB2ENR |= RCC_APB2ENR_DBGEN;
DBGMCU->CR |= DBGMCU_CR_DBG_STOP; // Way 1)
DBGMCU->CR = 0x00000002; // Way 2)

In the same way you can enable/disable the other conditions:

RCC->APB2ENR |= RCC_APB2ENR_DBGEN;
// DBGMCU->CR |= DBGMCU_CR_DBG_SLEEP;
DBGMCU->CR |= DBGMCU_CR_DBG_STOP;
// DBGMCU->CR |= DBGMCU_CR_DBG_STANDBY;
// DBGMCU->CR = 0x00000000;
// DBGMCU->CR = 0x00000001;
// DBGMCU->CR = 0x00000002;
// DBGMCU->CR = 0x00000004;
// DBGMCU->CR = 0x00000007;

Warning: these bits, once set, remain active until the next power on.
To use this method, I implemented a directive that activates these functions when needed.

View solution in original post

5 REPLIES 5

See section 33.9.1 in the Reference Manual:

AndrewNeil_0-1715082813974.png

Also, if you're using STM32CubeIDE, enable debug in low-power:

AndrewNeil_1-1715083025935.png

 

And make sure that your application doesn't disable the SWD pins during sleep ...

On higher Cortex-Ms, there's a bit you can directly test to see if a debugger is active.

That's not available on Cortex-M0/M0+, but you can still infer it from the DBGMCU Clock Enable:

	  // Look at the DBGMCU Clock Enable:
	  // This is 1 if a debug session is active, 0 if not.
	  // (It *is* still 0 when a debugger is physically connected,
	  //  but not in a debug session)
	  if( RCC->APB2ENR & RCC_APB2ENR_DBGMCUEN )
	  {
		  fprintf( stderr, "Debugger Connected\n" );

		  // Allow debug in STOP
		  DBGMCU->CR |= DBGMCU_CR_DBG_STOP;
	  }
	  else
	  {
		  // No debugger connected.
		  :
		  :
	  }

 

HI,
Thanks for your reply, now I know it's somehow possible.
I could still use your help, please.
I use Keil uVision 5 and an STM32L053C8T6.
It's not like you know how to set up the debugger, at the moment I use a simple ST-Link Debugger V.1.
I don't understand if it is possible to program this to work or I have to use other debuggers.

Greetings,

David

I can't even visualise what an ST-Link V1 looked like!

How old is it?

The features mentioned in section 33.9.1 of the Reference Manual are internal to the chip - so shouldn't be restricted by what debug probe you use ...

You'd have to ask Keil what is their equivalent of the  STM32CubeIDE's "enable debug in low-power" feature:

https://community.arm.com/support-forums/f/keil-forum

 

OK !
Then, with Keil, STM32L053C8T6 and ST-Link V1, it is possible!!

The important thing is to enable the clock for the debugger...
Then, you enable the debugger for the desired condition, in my case for the stop condition:

RCC->APB2ENR |= RCC_APB2ENR_DBGEN;
DBGMCU->CR |= DBGMCU_CR_DBG_STOP; // Way 1)
DBGMCU->CR = 0x00000002; // Way 2)

In the same way you can enable/disable the other conditions:

RCC->APB2ENR |= RCC_APB2ENR_DBGEN;
// DBGMCU->CR |= DBGMCU_CR_DBG_SLEEP;
DBGMCU->CR |= DBGMCU_CR_DBG_STOP;
// DBGMCU->CR |= DBGMCU_CR_DBG_STANDBY;
// DBGMCU->CR = 0x00000000;
// DBGMCU->CR = 0x00000001;
// DBGMCU->CR = 0x00000002;
// DBGMCU->CR = 0x00000004;
// DBGMCU->CR = 0x00000007;

Warning: these bits, once set, remain active until the next power on.
To use this method, I implemented a directive that activates these functions when needed.