A low-power operation mode based on GD32L23X

A low-power operation mode based on GD32L23X

  • 1.GD32 power management unit PMU
    • (1) Concepts of three power domains:
      • 1.VDD/VDDA domain
        • VDD/ VDDA domain basic peripherals:
        • VDD working status in different modes
      • 1.1V power domain
        • SRAM1 power domain
        • COREOFF1 power domain
        • COREOFF0 power domain
      • Battery backup domain
    • low power mode
      • The power management unit PMU provides 10 modes for low power consumption, as follows:
      • WFI and WFE instructions enter sleep
      • Note that you must be able to wake up when entering the sleep state and give it a delay. Otherwise, you will continue to sleep and will not be able to program. The specific solutions are as follows:
    • Is waking up from sleep a reset or continuing execution with this statement?
      • RTC sleep wake up note:
  • RTC alarm clock and automatic sleep wake-up
    • Clock source and frequency division
  • GPIO low power configuration
    • Basic configuration understanding
      • The effect of pulling up and down
      • The role of Schmitt trigger
      • Simulation mode
      • floating input
      • Drop down input
      • pull-up input
      • push-pull output
      • Open drain
    • Low power configuration mode
  • test

Using GD32L23X’s DEEP-SLEEP1, 1hz RTC wake-up, before sleeping, all GPIOs except specific GPIOs need to be configured into simulation mode, and all peripherals must be turned off to exit sleep. In the end, the power consumption can reach 15uA during sleep and 2mA during operation. .

1.GD32 power management unit PMU

(1) Concepts of three power domains:

GD32L23X provides 3 types of power domains: VDD / VDDA domain, 1.1V domain, and Backup domain,

1.VDD / VDDA domain

VDD/ VDDA domain basic peripherals:

HXTAL, LDO, POR / PDR (power on / down Reset),
FWDGT (free watchdog timer), all pads except PC13 / PC14 / PC15, etc.
VDDA domain includes ADC / DAC ,RC16M, IRC48M,
IRC32K ,PLLs (phase locking loop),
LVD (low voltage detector), etc.

VDD working status in different modes

run mode: 1.1V full power on
sleep mode (1.1V full power on, 0.9V full power on, low power),
Deep sleep/deep sleep 1/deep sleep 2 mode (on or low power)
Standby mode (power off)

1.1V power domain

SRAM1 power domain

SRAM1 can be turned off separately to reduce power consumption. GD32L233 includes two types of SRAM. SRAM1 (16KB) address: 0x20005000 – 0X20007FFFF 0x20004000 – 0x20004FFF
SRAM0 (16KB) address: 0x20002000 – 0x20003FFF 0x20001000 – 0x20001FFF
0x2000000 – 0x20000FFF

COOREOFF1 power domain

Can be turned off individually, including CAU unit (Crypto Acceleration Unit)

COOREOFF0 power domain

The COREOFF0 power domain is turned off when entering deep sleep 2 mode and turned on when exiting deep sleep 2 mode. The COREOFF0 power domain includes the following modules: CPU/BUS/ADC/CMP/CRC/CTC/CAC/I2C0/I2C1/SLCD/TRNG/TRNG/SPI0/SPI1/TIMER1/TIMER2/TIMER5/TIMER6/TIMER8/TIMER11/USART0/USART1 /USART3/USART4/USBD
When entering/exiting deep sleep 2 mode, the CPU registers can be retained or not retained by configuring the NRRD2 bit in the PMU_CTL1 register

Battery backup domain

Basic peripherals: LXTAL RTC BPOR BKP PAD (PC13, PC14, PC15) COREOFF0
It can save RTC time after power off and reset, and can switch to VBAT battery power supply. After using battery power supply, it can save

Low power mode

The power management unit PMU provides 10 modes for low power consumption, as follows:

Low power mode Features Theoretical power consumption
Run mode NPLDO works in 1.1V mode 68 – 146uA/Mhz
Run1 mode NPLDO works in 0.9V mode and the maximum system clock can only be 16MHZ 48 – 119uA/Mhz
Run2 mode NPLDO works in 0.9V mode and the maximum system clock can only be 2MHZ 220uA
Sleep mode Provides the lowest wake-up time 36-120uA/Mhz
Sleep1 mode NPLDO should be selected as 0.9V. 32.5-109uA/Mhz
Sleep2 mode NPLDO should be selected as 0.9V. LDNP in PMU_CTL0 should be configured to select low-density mode, 210 -430uA
Deep-sleep mode 1.1V domain All clocks in the system are turned off, and all IRC16M, IRC48M, HXTAL and pll are disabled. LDO startup in low drive mode may cause additional delays. When exiting deep sleep mode, IRC16M will be selected as the system clock <40uA
Deep-sleep 1 mode All clocks in the 1.1V domain are turned off, all IRC16M, IRC48M, HXTAL and pll are disabled, LDO startup will cause additional delay. When exiting deep sleep mode, IRC16M will be selected as the system clock 3.14uA
Deep- sleep 2 mode All clocks are turned off, and all IRC16M, IRC48M, HXTAL and pll are disabled. Power is cut off to the COREOFF0/SRAM1/COREOFF1 domain. The contents of the COREOFF0 / SRAM1 / COREOFF1 fields are lost, and the data in the registers and SRAM are retained. When exiting deep sleep mode, IRC16M will be selected as the system clock <1.7uA
Standby mode Directly turning off the 1.1V domain can greatly reduce power consumption, but the contents of the registers in the domain are lost, including internal RAM. A power-on reset will occur when exiting standby mode. CotexM23 starts from 0x00000000 Execute 0.44uA

WFI and WFE instructions enter sleep

WFI (Wait for interrupt) and WFE (Wait for event) are two instructions that allow the ARM core to enter low-power standby mode. They are defined by ARM architecture and implemented by ARM core.
The biggest difference between WFI and WFE is that WFI can only be awakened by EXTI interrupts, while WFE can be awakened by any EXTI event.

Please note that you must be able to wake up when entering the sleep state, and give a delay, otherwise you will continue to sleep and will not be able to program. The specific solutions are as follows:

Boot source selection Boot1 Boot0
FLASH memory x 0
Boot loader 0 1
On-chip SRAM 1 1
Passed Set Boot0 to 1 and Boot1 to 0 by short-circuiting with tweezers or flying wires to enter the boot loader.

Is sleep wake-up a reset or will this statement continue to execute

LED_DISABLE
delay_1ms(2000);
pmu_to_deepsleepmode(PMU_LDNPDSP_LOWDRIVE, WFI_CMD, PMU_DEEPSLEEP2);
LED_ENABL
delay_1ms(1000);

By testing the above code in the while loop, the following conclusions are drawn:

Sleep mode selection LED light status Conclusion
deep-sleep mode The light flashes after waking up Continue execution
deep-sleep mode1 The light flashes after waking up Continue execution
deep-sleep mode2 The light does not flash The content is lost and the execution cannot continue
standby mode The light does not flash Reset

RTC sleep wake-up attention:

After entering deep sleep mode, there can only be EXTI interrupt
EXTI source:
All GPIO pins except PC13-PC15
LVD, RTC,USBD CMP0,CMP1 I2C0, I2C2, USART0,USART1,I2C1,LPUART,LPTIMER
To wake up, the RCT alarm clock needs to be mounted on EXTI to wake up regularly.
Remember to clear the interrupt flag bit in the RTC interrupt

void RTC_Init(void) {<!-- -->
\t
/* enable PMU and BKPI clocks */
rcu_periph_clock_enable(RCU_PMU);
rcu_periph_clock_enable(RCU_BKP);
\t
/* allow access to BKP domain */
pmu_backup_write_enable();
rcu_periph_clock_enable(RCU_RTC);
\t
/* enable LXTAL */
rcu_osci_on(RCU_IRC32K);
\t
/* wait for LXTAL stabilization flag */
rcu_osci_stab_wait(RCU_IRC32K);
rcu_lxtal_clock_monitor_enable();
\t
/* configure the RTC clock source selection */
rcu_rtc_clock_config(RCU_RTCSRC_IRC32K);
rtc_register_sync_wait();
\t
/* setup RTC time value */
rtc_initpara.factor_asyn = prescaler_a;
rtc_initpara.factor_syn = prescaler_s;
rtc_initpara.year = 0x16;
rtc_initpara.day_of_week = RTC_WEDNESDAY;rtc_initpara.month = RTC_SEP;
rtc_initpara.date = 0x07;
rtc_initpara.display_format = RTC_24HOUR;
rtc_initpara.am_pm = RTC_AM;
rtc_initpara.hour = 0x09;
rtc_initpara.minute = 0x28;
rtc_initpara.second = 0;
rtc_init( & amp;rtc_initpara);
\t
/* EXTI line 20 configuration */
nvic_irq_enable(RTC_WKUP_IRQn, 2);
exti_flag_clear(EXTI_20);
exti_init(EXTI_20, EXTI_INTERRUPT, EXTI_TRIG_RISING);
rtc_flag_clear(RTC_STAT_WTF);
\t
/* wakeup clock configuration */
rtc_wakeup_clock_set(WAKEUP_CKSPRE);
rtc_wakeup_timer_set(2);
rtc_interrupt_enable(RTC_INT_WAKEUP);
/*rtc enable*/
rtc_wakeup_enable();
}

void RTC_WKUP_IRQHandler(void){<!-- -->
if(RESET != rtc_flag_get(RTC_FLAG_WT)) {<!-- -->
/* clear EXTI line 20 pending and rtc wakeup flag */rtc_flag_clear(RTC_FLAG_WT);
exti_flag_clear(EXTI_20);
/* disable rtc auto wakeup function */
\t
}
}

RTC alarm clock and automatic sleep wake-up

Clock source and frequency division

Using internal clock IRC32K
Average frequency: 31.7-32.3khz
Operating current: 160nA
Wake-up time: 40us
RTC provides a certain time, which includes hours/minutes/seconds/subseconds, and a calendar, which includes day of the year/month/day/week. Except for sub-seconds, time and calendar are expressed in BCD code. Subseconds are expressed in binary code. Adjust time for daylight saving time. Working in power saving mode and smart wake-up are software configurable. Supports the use of an external precision low-frequency clock to improve calendar accuracy.
GD32 divides the RTC into two parts. The core part (prescaler, divider, counter, alarm clock) is placed in backup to achieve the purpose of reset and restart without losing time. The other part (APB1 interface) is placed in the VDD power domain.
Add a battery. When VDD is powered off, it will automatically switch to battery power supply (VBAT) to achieve the purpose of not losing time when the MCU is powered off.
The RTC unit has three independent clock sources: LXTAL, IRC32K and HXTAL
There are 2 frequency dividers, a 7-bit asynchronous frequency divider and the other is a 15-bit synchronous frequency divider. The asynchronous frequency divider is mainly used to reduce energy consumption.

F

=

F

C

/

(

F

A

C

T

O

R

A

+

F

A

C

T

O

R

B

)

+

1

F = F_C/(FACTOR_A + FACTOR_B) + 1

F=FC?/(FACTORA? + FACTORB?) + 1
1HZ automatic wake-up calculation 32K/128/250 = 1HZ
7-bit asynchronous divider = 128
15-bit sync divider = 250
Automatic wake-up is mounted to EXTI_20, priority 2, alarm clock Alarm is mounted to EXTI_17, priority 0

GPIO low power configuration

Pull up and down 40kΩ
Working frequency 10MHZ 50MHZ 2MHZ optional

Basic configuration understanding

The role of pull-up and drop-down

First of all, pull-down is to give IO a default state. For example, if EN is controlled, then we will pull it down if it is high and valid, and we will pull it up if it is low and valid.
Pull-up is to clamp the uncertain signal to a high level through a resistor, and the resistor also acts as a current limiter. The same goes for drop-down. It also clamps the uncertain signal at a low level through a resistor.
Pull-up resistors are sometimes used to provide current when the bus drive capability is insufficient. Generally speaking, they are pulling current; pull-down resistors are used to absorb current, that is, sinking current. For example, the I2C bus uses a pull-up resistor of 10k.

The role of Schmitt trigger

The main function of the Schmitt trigger in GPIO is waveform transformation and wave shaping. When there is electromagnetic interference or noise in the circuit, the voltage passing through the GPIO pin may become unstable, that is, fluctuate up and down; after applying After the Mitter trigger, the fluctuating signal will be regularized into a rectangular wave, which facilitates the microcontroller to identify high and low level signals.

Simulation mode

In analog mode, the microcontroller needs to receive or send analog signals, so there is no need for any denoising circuit in the circuit, so it can be simply understood as connecting a straight line to the corresponding pin of the microcontroller.
At this time, the weak pull-up and pull-down resistors are disabled; the output buffer is disabled; the Schmitt trigger input is disabled; and the corresponding bit in the port input status register is “0”.

Floating input

When the microcontroller pin is at a floating input, the pull-up and pull-down resistors in the input circuit are disabled, and the Schmitt trigger is enabled. This can be understood as a high or low level on the pin, and the microcontroller receives a high or low voltage. flat.

Drop-down input

When the microcontroller is at the pull-down input, the pull-down resistor in the input circuit is enabled and the Schmitt trigger is enabled. When the pin is connected to the line, its function is the same as a floating input; but when the pin is floating, the pin level will be pulled down to a low level, and the microcontroller can only receive a low level at this time.

Pull-up input

When the microcontroller is at the pull-up input, the pull-up resistor in the input circuit is enabled and the Schmitt trigger is enabled. The phenomenon is opposite to the pull-down input, that is, when the pin is left floating, the pin level will be pulled up to a high level. At this time, the microcontroller can only receive a high level.

Push-pull output

Unifiedly disable the pull-up and pull-down resistors, enable the Schmitt trigger, and enable the output buffer.
When in push-pull mode, when the output control register is set to “0”, the corresponding pin outputs a low level; when the output control register is set to “1”, the corresponding pin outputs a high level.

Open drain

When in open-drain mode, when the output control register is set to “0”, the corresponding pin outputs a low level; when the output control register is set to “1”, the corresponding pin is in a high-impedance state.

Low power configuration mode

All unused pins should be configured as analog inputs, in which case the Schmitt triggers are disabled and each I/O consumes zero to avoid drawing additional current. For output, it is recommended to use the lowest I/O speed, and users should avoid activating pull-up and pull-down configurations if not necessary. The user also needs to disable the clock output pin when not needed.
In low power consumption mode, if the GPIO has external component input/output, it is recommended to configure the input as pull-up/pull-down and output push-pull to ensure that the GPIO is at a fixed level when idle, and configure the GPIO to be disable before sleep through pull-up and pull-down. Level.
All GPIOs enter simulation mode and can reach close to the official low power consumption current.
However, due to the need for burning, BOOT and swd cannot be configured into simulation mode. At the same time, external interrupt key_on and shutdown wake-up cannot enter simulation mode.

Test

Sleep energy consumption test (RTC wake-up is enabled by default at 1HZ) GD32 working mode GPIO configuration The average current of the microcontroller plus peripheral circuits (voltage/20 ohm resistance = current)
Normal power on run mode Use all peripherals and clocks 76.844mv/20=3.84mA
Normal power on run mode Disable all peripherals and clocks 64.2mV/20=3.21mA
Deep sleep test Deep Sleep mode Use all peripherals and clocks 69mV/20 = 3.45mA
Deep sleep test Deep Sleep mode Disabled All peripherals and clocks 34mV/20=1.7mA
Deep sleep test Deep Sleep mode Set all GPIOs to analog mode 1.105mV/20=55.20uA
Deep Sleep1 Deep Sleep1 mode Use all peripherals and clocks 43mV/20= 2.15mA
Deep Sleep1 Deep Sleep1 mode Disable all peripherals and clocks 34mV/20= 1.7mA
Deep sleep 1 Deep Sleep1 mode Set all GPIOs to analog mode 0.086mV/20 = 4.3uA
Deep Sleep1 Deep Sleep1 mode Set GPIO except SWD and BOOT to analog mode, and disable UART, ADC, DMA and other peripherals (note that disabling requires turning on the corresponding clock) 0.286mV/20= 14.3uA
Deep Sleep2 Deep Sleep2 mode Use all peripherals and clocks 35mV/20= 1.75mA
Deep Sleep2 Deep Sleep2 mode Disable all peripherals and clock 25mv/20= 1.25mA
Deep sleep 2 Deep Sleep2 mode Set all gpio to simulation mode 2.9uA
Standby mode Standby mode Disable all peripherals and clocks, and set GPIO to analog mode 2uA