environment:
Host: WIN7
Development environment: MDK4.23
MCU:STM32F103CBT6
illustrate:
In the previous article http://blog.csdn.net/jdh99/article/details/7369844 , some tests on the STM32 standby mode were conducted. Among them, how to determine whether it is the standby mode when restarting was not tested. In addition, there is a problem in the previous article that the alarm interrupt cannot be entered in the standby mode.
This article conducts independent watchdog IWDG testing, as well as more detailed testing of standby mode.
In STM32, there are 3 types of reset:
1. System reset: external reset, WWDG, IWDG, SW reset, low power management reset. All are reset except the reset flag register RCC_CSR.
2. Power reset: power on/off reset, reset from standby mode. Power on/off reset resets all registers except the backup domain. Standby reset does not reset the backup domain registers and PWR_CSR register.
3. Reset the backup domain.
Register Description:
As can be seen from the figure, the WUF bit can be used to determine whether it is awakened from standby mode.
RCC_CSR register:
As can be seen from the figure, the IWDGRSTF bit of the RCC_CSR register can indicate whether an independent watchdog reset occurs.
Because the PWR_CSR register will also be reset if the system is not in standby mode when the watchdog is reset, the WUF bit can also indicate whether an independent watchdog reset has occurred.
source code:
Independent watchdog reset test:
// Check if the wakeup flag is set
if (PWR_GetFlagStatus(PWR_FLAG_WU) == RESET)
{
//First start, or independent watchdog reset
// Initialize the backup registers
//BKP_DeInit();
//RTC function is turned on
// Enable external crystal oscillator
RCC_LSEConfig(RCC_LSE_ON);
//Wait for the external crystal to be ready
while(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET);
//Set the RTC clock to an external crystal
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
// Enable the RTC clock
RCC_RTCCLKCmd(ENABLE);
//Wait for the RSF bit (register synchronization flag) in the RTC_CTL register to be set to 1 by hardware
RTC_WaitForSynchro();
RTC_WaitForLastTask();
// Enable alarm interrupt
RTC_ITConfig(RTC_IT_ALR, ENABLE);
RTC_WaitForLastTask();
//The frequency division coefficient is 1, that is, the minimum time unit is 1/2^15 = 30.5us
RTC_SetPrescaler(RTC_PRESCALE);
RTC_WaitForLastTask();
//Start independent watchdog
IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable); //Enable register write before access
IWDG_SetPrescaler(IWDG_Prescaler_64); //64 division, one cycle 1.6ms
IWDG_SetReload(1250); //Longest 12 bits [0,4096] 1250*1.6 = 2s
IWDG_ReloadCounter(); //Feed the dog
// Enable the door dog
IWDG_Enable();
if (BKP_ReadBackupRegister(BKP_DR6) == 0xabcd)
{
GPIO_ResetBits(GPIOA, GPIO_Pin_11);
BKP_WriteBackupRegister(BKP_DR6,0);
}
else
{
GPIO_SetBits(GPIOA,GPIO_Pin_11);
BKP_WriteBackupRegister(BKP_DR6,0xabcd);
}
}
else
{
// Exit from standby mode
// Clear the wake-up flag
RCC_ClearFlag();
if (BKP_ReadBackupRegister(BKP_DR7) == 0xabcd)
{
GPIO_ResetBits(GPIOA, GPIO_Pin_8);
BKP_WriteBackupRegister(BKP_DR7,0);
}
else
{
GPIO_SetBits(GPIOA,GPIO_Pin_8);
BKP_WriteBackupRegister(BKP_DR7,0xabcd);
}
}
while (1);
The test results show that the LED connected to the PA11 pin keeps flashing, and the LED connected to PA8 is always on, which means that the watchdog reset is constantly entered.
Standby mode RTC alarm wake-up test:
// Check if the wakeup flag is set
if (PWR_GetFlagStatus(PWR_FLAG_WU) == RESET)
{
//First start, or independent watchdog reset
// Initialize the backup registers
//BKP_DeInit();
//RTC function is turned on
// Enable external crystal oscillator
RCC_LSEConfig(RCC_LSE_ON);
//Wait for the external crystal to be ready
while(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET);
//Set the RTC clock to an external crystal
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
// Enable the RTC clock
RCC_RTCCLKCmd(ENABLE);
//Wait for the RSF bit (register synchronization flag) in the RTC_CTL register to be set to 1 by hardware
RTC_WaitForSynchro();
RTC_WaitForLastTask();
// Enable alarm interrupt
RTC_ITConfig(RTC_IT_ALR, ENABLE);
RTC_WaitForLastTask();
//The frequency division coefficient is 1, that is, the minimum time unit is 1/2^15 = 30.5us
RTC_SetPrescaler(RTC_PRESCALE);
RTC_WaitForLastTask();
//Start independent watchdog
IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable); //Enable register write before access
IWDG_SetPrescaler(IWDG_Prescaler_64); //64 division, one cycle 1.6ms
IWDG_SetReload(1250); //Longest 12 bits [0,4096] 1250*1.6 = 2s
IWDG_ReloadCounter(); //Feed the dog
// Enable the door dog
//IWDG_Enable();
if (BKP_ReadBackupRegister(BKP_DR6) == 0xabcd)
{
GPIO_ResetBits(GPIOA, GPIO_Pin_11);
BKP_WriteBackupRegister(BKP_DR6,0);
}
else
{
GPIO_SetBits(GPIOA,GPIO_Pin_11);
BKP_WriteBackupRegister(BKP_DR6,0xabcd);
}
}
else
{
// Exit from standby mode
// Clear the wake-up flag
RCC_ClearFlag();
if (BKP_ReadBackupRegister(BKP_DR7) == 0xabcd)
{
GPIO_ResetBits(GPIOA, GPIO_Pin_8);
BKP_WriteBackupRegister(BKP_DR7,0);
}
else
{
GPIO_SetBits(GPIOA,GPIO_Pin_8);
BKP_WriteBackupRegister(BKP_DR7,0xabcd);
}
}
//Delay 1s
for (i = 0;i < 100;i++)
{
_delay_ms(10);
}
// Turn on standby mode and wake up after 1s
open_standy_mode(30000);
All LEDs will light up every time the power is turned on, and all will go out when entering standby mode. The test results show that the LED connected to the PA8 pin will light up for 1s and then go out to enter standby mode, and will go out for the next time to enter standby mode. The LED connected to PA11 will light up and go out normally as the power consumption decreases, which means that the alarm wake-up occurs continuously (the watchdog is turned off).
IWDG wake-up test in standby mode:
// Check if the wakeup flag is set
if (PWR_GetFlagStatus(PWR_FLAG_WU) == RESET)
{
//First start, or independent watchdog reset
// Initialize the backup registers
//BKP_DeInit();
//RTC function is turned on
// Enable external crystal oscillator
RCC_LSEConfig(RCC_LSE_ON);
//Wait for the external crystal to be ready
while(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET);
//Set the RTC clock to an external crystal
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
// Enable the RTC clock
RCC_RTCCLKCmd(ENABLE);
//Wait for the RSF bit (register synchronization flag) in the RTC_CTL register to be set to 1 by hardware
RTC_WaitForSynchro();
RTC_WaitForLastTask();
// Enable alarm interrupt
RTC_ITConfig(RTC_IT_ALR, ENABLE);
RTC_WaitForLastTask();
//The frequency division coefficient is 1, that is, the minimum time unit is 1/2^15 = 30.5us
RTC_SetPrescaler(RTC_PRESCALE);
RTC_WaitForLastTask();
//Start independent watchdog
IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable); //Enable register write before access
IWDG_SetPrescaler(IWDG_Prescaler_64); //64 division, one cycle 1.6ms
IWDG_SetReload(1250); //Longest 12 bits [0,4096] 1250*1.6 = 2s
IWDG_ReloadCounter(); //Feed the dog
// Enable the door dog
IWDG_Enable();
if (BKP_ReadBackupRegister(BKP_DR6) == 0xabcd)
{
GPIO_ResetBits(GPIOA, GPIO_Pin_11);
BKP_WriteBackupRegister(BKP_DR6,0);
}
else
{
GPIO_SetBits(GPIOA,GPIO_Pin_11);
BKP_WriteBackupRegister(BKP_DR6,0xabcd);
}
}
else
{
// Exit from standby mode
// Clear the wake-up flag
RCC_ClearFlag();
if (BKP_ReadBackupRegister(BKP_DR7) == 0xabcd)
{
GPIO_ResetBits(GPIOA, GPIO_Pin_8);
BKP_WriteBackupRegister(BKP_DR7,0);
}
else
{
GPIO_SetBits(GPIOA,GPIO_Pin_8);
BKP_WriteBackupRegister(BKP_DR7,0xabcd);
}
}
//Delay 1s
for (i = 0;i < 100;i++)
{
_delay_ms(10);
}
// Turn on standby mode and wake up after 2s
open_standy_mode(60000);
All LEDs will light up every time the power is turned on, and all will go out when entering standby mode. The test results show that the LED connected to the PA11 pin will light up for 1s and then go out to enter standby mode, and will go out normally the next time to enter standby mode. The LED connected to PA8 will light up and go out normally with low power consumption, and the standby mode is 2s standby plus 1s delay, which should be 3s wake-up. The LED flashing frequency of about 2s indicates that it is awakened in advance. This shows that the watchdog wake-up occurs continuously.
Complete test program: determine the first startup program, the watchdog reset when the MCU is in normal state, and the MCU is awakened by the alarm clock/watchdog in standby mode.
Note: Each watchdog reset must be reconfigured and started
// Check if watchdog reset occurs in normal state
if (RCC_GetFlagStatus(RCC_FLAG_IWDGRST) != RESET)
{
// Clear flag
RCC_ClearFlag();
//RTC function is turned on
// Enable external crystal oscillator
RCC_LSEConfig(RCC_LSE_ON);
//Wait for the external crystal to be ready
while(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET);
//Set the RTC clock to an external crystal
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
// Enable the RTC clock
RCC_RTCCLKCmd(ENABLE);
//Wait for the RSF bit (register synchronization flag) in the RTC_CTL register to be set to 1 by hardware
RTC_WaitForSynchro();
RTC_WaitForLastTask();
// Enable alarm interrupt
RTC_ITConfig(RTC_IT_ALR, ENABLE);
RTC_WaitForLastTask();
//The frequency division coefficient is 1, that is, the minimum time unit is 1/2^15 = 30.5us
RTC_SetPrescaler(RTC_PRESCALE);
RTC_WaitForLastTask();
//Start independent watchdog
IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable); //Enable register write before access
IWDG_SetPrescaler(IWDG_Prescaler_64); //64 division, one cycle 1.6ms
IWDG_SetReload(1250); //Longest 12 bits [0,4096] 1250*1.6 = 2s
IWDG_ReloadCounter(); //Feed the dog
// Enable the door dog
IWDG_Enable();
if (BKP_ReadBackupRegister(BKP_DR5) == 0xabcd)
{
GPIO_SetBits(GPIOA,GPIO_Pin_12);
BKP_WriteBackupRegister(BKP_DR5,0);
}
else
{
GPIO_ResetBits(GPIOA, GPIO_Pin_12);
BKP_WriteBackupRegister(BKP_DR5,0xabcd);
}
}
else
{
// Check whether the wake-up flag is set to determine whether it is the first startup
if (PWR_GetFlagStatus(PWR_FLAG_WU) == RESET)
{
//First start
// Initialize the backup registers
//BKP_DeInit();
//RTC function is turned on
// Enable external crystal oscillator
RCC_LSEConfig(RCC_LSE_ON);
//Wait for the external crystal to be ready
while(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET);
//Set the RTC clock to an external crystal
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
// Enable the RTC clock
RCC_RTCCLKCmd(ENABLE);
//Wait for the RSF bit (register synchronization flag) in the RTC_CTL register to be set to 1 by hardware
RTC_WaitForSynchro();
RTC_WaitForLastTask();
// Enable alarm interrupt
RTC_ITConfig(RTC_IT_ALR, ENABLE);
RTC_WaitForLastTask();
//The frequency division coefficient is 1, that is, the minimum time unit is 1/2^15 = 30.5us
RTC_SetPrescaler(RTC_PRESCALE);
RTC_WaitForLastTask();
//Start independent watchdog
IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable); //Enable register write before access
IWDG_SetPrescaler(IWDG_Prescaler_64); //64 division, one cycle 1.6ms
IWDG_SetReload(1250); //Longest 12 bits [0,4096] 1250*1.6 = 2s
IWDG_ReloadCounter(); //Feed the dog
// Enable the door dog
IWDG_Enable();
if (BKP_ReadBackupRegister(BKP_DR6) == 0xabcd)
{
GPIO_ResetBits(GPIOA, GPIO_Pin_11);
BKP_WriteBackupRegister(BKP_DR6,0);
}
else
{
GPIO_SetBits(GPIOA,GPIO_Pin_11);
BKP_WriteBackupRegister(BKP_DR6,0xabcd);
}
}
else
{
//Exit from standby mode, wake up by alarm or watchdog
// Clear the wake-up flag
RCC_ClearFlag();
if (BKP_ReadBackupRegister(BKP_DR7) == 0xabcd)
{
GPIO_ResetBits(GPIOA, GPIO_Pin_8);
BKP_WriteBackupRegister(BKP_DR7,0);
}
else
{
GPIO_SetBits(GPIOA,GPIO_Pin_8);
BKP_WriteBackupRegister(BKP_DR7,0xabcd);
}
}
}
//Delay 1s
for (i = 0;i < 100;i++)
{
_delay_ms(10);
}
// Turn on standby mode and wake up after 2s
open_standy_mode(60000);
Previous article:STM32 MCU PWM output test
Next article:STM32 external interrupt test
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Ranking of installed capacity of smart driving suppliers from January to September 2024: Rise of independent manufacturers and strong growth of LiDAR market
- Industry first! Xiaopeng announces P7 car chip crowdfunding is completed: upgraded to Snapdragon 8295, fluency doubled
- P22-009_Butterfly E3106 Cord Board Solution
- Keysight Technologies Helps Samsung Electronics Successfully Validate FiRa® 2.0 Safe Distance Measurement Test Case
- Innovation is not limited to Meizhi, Welling will appear at the 2024 China Home Appliance Technology Conference
- Innovation is not limited to Meizhi, Welling will appear at the 2024 China Home Appliance Technology Conference
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- EEWORLD University Hall ---- Pattern Recognition National University of Defense Technology Cai Xuanping
- ST32F103x Read the sensor value on X-NUCLEO-IKS01A3 via I2C
- Need help designing a CAN communication solution between two MCUs!
- 【NUCLEO-WL55JC2 Review 1】 Overview of STM32WL Chip
- Friends who are familiar with MP2307DN, please take a look!
- General welding specifications for MINI manufacturers
- Why constant current source simulation does not produce constant current
- [National Technology N32G457 Review] 1. Unboxing + Lighting
- The second article is a simple comparison between GD32VF103C START and ST official routines
- [GD32L233C-START Review] Part 3 PWM driving breathing light