Sleep Mode

Post here all questions related to LibMaple core if you can't find a relevant section!
Post Reply
hyur
Posts: 36
Joined: Fri May 27, 2022 7:42 am
Answers: 2

Sleep Mode

Post by hyur »

Board : Stm32f103c8t6 (Roger's Core)

I want to use sleep mode on the board.
So I tried to use the STM32duino LOW POWER library,
Because it is Roger's Core, stm32_def.h compilation error occurs.

How does Roger's Core use sleep mode?

Can you provide a relevant register datasheet or example code?
Ouroboros
Posts: 1
Joined: Sun Mar 05, 2023 9:28 pm

Re: Sleep Mode

Post by Ouroboros »

I'm trying to implement standby and stop modes on this core for STM32F103 mcu. I had no isues with standby mode, it works properly with power consumption about of 48 uA. Same power is consumed when using STM32LowPower with official core. Here it's my source:

Code: Select all

void lp_init()
{
	//enable power clock
	RCC_BASE->APB1ENR |= RCC_APB1ENR_PWREN;
	delay(10);

	/* Enable access to RTC and backup registers */
	PWR_BASE->CR |= PWR_CR_DBP;

	/* Check if the system was resumed from StandBy mode */
	if (PWR_BASE->CSR & SCB_SCR_SLEEPONEXIT) {
		/* Clear Standby flag */
		PWR_BASE->CR |= PWR_CR_CSBF;
	}

	//Clear wakeup flag
	PWR_BASE->CR |= PWR_CR_CWUF;
}

Code: Select all

void standby()
{
	lp_init();
	nvic_globalirq_disable();

	SCB_BASE->SCR |= SCB_SCR_SLEEPDEEP;
	//Power down deepsleep
	PWR_BASE->CR |= PWR_CR_PDDS;
	//Enable wakeup pin 
	PWR_BASE->CSR |= PWR_CSR_EWUP;
	__asm volatile("WFI":::"memory");
}
There are some difficuelties with stop mode. It consumes about 79uA instead of 54uA using original core. Something keeps consuming 25uA. Here the sources of my implementation:

Code: Select all

void stop()
{
	for (int i = 0; i < BOARD_NR_GPIO_PINS; i++)
	{
		pinMode(i, INPUT);
		digitalWrite(i, 0);
	}

	Serial.end();
	adc_disable_all();
	lp_init();
	
	nvic_globalirq_disable();

	PWR_BASE->CR &= ~PWR_CR_PDDS;
	//Low-power deepsleep
	PWR_BASE->CR |= PWR_CR_LPDS;

	SCB_BASE->SCR |= SCB_SCR_SLEEPDEEP;

	__asm volatile("WFI":::"memory");
	
	SCB_BASE->SCR &= ~SCB_SCR_SLEEPDEEP;

	//post wakeup setup
	////////////////////////////////////////////////////////////
	setup_clocks();
	nvic_init((uint32)VECT_TAB_ADDR, 0);  //setup_nvic();
	systick_init(SYSTICK_RELOAD_VAL);
	adc_set_prescaler(wirish::priv::w_adc_pre); adc_foreach(adc_default_config); //setup_adcs();
	timer_foreach(timer_default_config);  //setup_timers();
	////////////////////////////////////////////////////////////

	nvic_globalirq_enable();
}
Post Reply

Return to “General discussion”