STM32 standby mode wake-up test and independent watchdog test

Publisher:不懂之人Latest update time:2016-12-19 Source: eefocusKeywords:STM32 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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:

 

  1. // Check if the wakeup flag is set  

  2. if (PWR_GetFlagStatus(PWR_FLAG_WU) == RESET)  

  3. {  

  4.     //First start, or independent watchdog reset   

  5.     // Initialize the backup registers  

  6.     //BKP_DeInit();  

  7.   

  8.     //RTC function is turned on  

  9.     // Enable external crystal oscillator  

  10.     RCC_LSEConfig(RCC_LSE_ON);  

  11.     //Wait for the external crystal to be ready  

  12.     while(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET);  

  13.   

  14.     //Set the RTC clock to an external crystal  

  15.     RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);  

  16.   

  17.     // Enable the RTC clock  

  18.     RCC_RTCCLKCmd(ENABLE);  

  19.     //Wait for the RSF bit (register synchronization flag) in the RTC_CTL register to be set to 1 by hardware  

  20.     RTC_WaitForSynchro();  

  21.     RTC_WaitForLastTask();    

  22.   

  23.     // Enable alarm interrupt     

  24.     RTC_ITConfig(RTC_IT_ALR, ENABLE);    

  25.     RTC_WaitForLastTask();    

  26.   

  27.     //The frequency division coefficient is 1, that is, the minimum time unit is 1/2^15 = 30.5us  

  28.     RTC_SetPrescaler(RTC_PRESCALE);    

  29.     RTC_WaitForLastTask();  

  30.   

  31.     //Start independent watchdog  

  32.     IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable); //Enable register write before access  

  33.     IWDG_SetPrescaler(IWDG_Prescaler_64); //64 division, one cycle 1.6ms  

  34.     IWDG_SetReload(1250); //Longest 12 bits [0,4096] 1250*1.6 = 2s  

  35.     IWDG_ReloadCounter(); //Feed the dog  

  36.     // Enable the door dog  

  37.     IWDG_Enable();    

  38.       

  39.     if (BKP_ReadBackupRegister(BKP_DR6) == 0xabcd)  

  40.     {  

  41.         GPIO_ResetBits(GPIOA, GPIO_Pin_11);  

  42.         BKP_WriteBackupRegister(BKP_DR6,0);  

  43.     }  

  44.     else  

  45.     {  

  46.         GPIO_SetBits(GPIOA,GPIO_Pin_11);  

  47.         BKP_WriteBackupRegister(BKP_DR6,0xabcd);  

  48.     }                                             

  49. }  

  50. else  

  51. {     

  52.     // Exit from standby mode    

  53.     // Clear the wake-up flag  

  54.     RCC_ClearFlag();   

  55.   

  56.     if (BKP_ReadBackupRegister(BKP_DR7) == 0xabcd)  

  57.     {  

  58.         GPIO_ResetBits(GPIOA, GPIO_Pin_8);  

  59.         BKP_WriteBackupRegister(BKP_DR7,0);  

  60.     }  

  61.     else  

  62.     {  

  63.         GPIO_SetBits(GPIOA,GPIO_Pin_8);  

  64.         BKP_WriteBackupRegister(BKP_DR7,0xabcd);  

  65.     }  

  66. }  

  67. 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:

 

  1. // Check if the wakeup flag is set  

  2. if (PWR_GetFlagStatus(PWR_FLAG_WU) == RESET)  

  3. {  

  4.     //First start, or independent watchdog reset   

  5.     // Initialize the backup registers  

  6.     //BKP_DeInit();  

  7.   

  8.     //RTC function is turned on  

  9.     // Enable external crystal oscillator  

  10.     RCC_LSEConfig(RCC_LSE_ON);  

  11.     //Wait for the external crystal to be ready  

  12.     while(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET);  

  13.   

  14.     //Set the RTC clock to an external crystal  

  15.     RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);  

  16.   

  17.     // Enable the RTC clock  

  18.     RCC_RTCCLKCmd(ENABLE);  

  19.     //Wait for the RSF bit (register synchronization flag) in the RTC_CTL register to be set to 1 by hardware  

  20.     RTC_WaitForSynchro();  

  21.     RTC_WaitForLastTask();    

  22.   

  23.     // Enable alarm interrupt     

  24.     RTC_ITConfig(RTC_IT_ALR, ENABLE);    

  25.     RTC_WaitForLastTask();    

  26.   

  27.     //The frequency division coefficient is 1, that is, the minimum time unit is 1/2^15 = 30.5us  

  28.     RTC_SetPrescaler(RTC_PRESCALE);    

  29.     RTC_WaitForLastTask();  

  30.   

  31.     //Start independent watchdog  

  32.     IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable); //Enable register write before access  

  33.     IWDG_SetPrescaler(IWDG_Prescaler_64); //64 division, one cycle 1.6ms  

  34.     IWDG_SetReload(1250); //Longest 12 bits [0,4096] 1250*1.6 = 2s  

  35.     IWDG_ReloadCounter(); //Feed the dog  

  36.     // Enable the door dog  

  37.     //IWDG_Enable();      

  38.       

  39.     if (BKP_ReadBackupRegister(BKP_DR6) == 0xabcd)  

  40.     {  

  41.         GPIO_ResetBits(GPIOA, GPIO_Pin_11);  

  42.         BKP_WriteBackupRegister(BKP_DR6,0);  

  43.     }  

  44.     else  

  45.     {  

  46.         GPIO_SetBits(GPIOA,GPIO_Pin_11);  

  47.         BKP_WriteBackupRegister(BKP_DR6,0xabcd);  

  48.     }                                             

  49. }  

  50. else  

  51. {     

  52.     // Exit from standby mode    

  53.     // Clear the wake-up flag  

  54.     RCC_ClearFlag();   

  55.   

  56.     if (BKP_ReadBackupRegister(BKP_DR7) == 0xabcd)  

  57.     {  

  58.         GPIO_ResetBits(GPIOA, GPIO_Pin_8);  

  59.         BKP_WriteBackupRegister(BKP_DR7,0);  

  60.     }  

  61.     else  

  62.     {  

  63.         GPIO_SetBits(GPIOA,GPIO_Pin_8);  

  64.         BKP_WriteBackupRegister(BKP_DR7,0xabcd);  

  65.     }  

  66. }  

 

  1. //Delay 1s  

  2. for (i = 0;i < 100;i++)  

  3. {  

  4.       _delay_ms(10);  

  5. }  

 

  1. // Turn on standby mode and wake up after 1s  

 

  1. 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:

 

  1. // Check if the wakeup flag is set  

  2. if (PWR_GetFlagStatus(PWR_FLAG_WU) == RESET)  

  3. {  

  4.     //First start, or independent watchdog reset   

  5.     // Initialize the backup registers  

  6.     //BKP_DeInit();  

  7.   

  8.     //RTC function is turned on  

  9.     // Enable external crystal oscillator  

  10.     RCC_LSEConfig(RCC_LSE_ON);  

  11.     //Wait for the external crystal to be ready  

  12.     while(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET);  

  13.   

  14.     //Set the RTC clock to an external crystal  

  15.     RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);  

  16.   

  17.     // Enable the RTC clock  

  18.     RCC_RTCCLKCmd(ENABLE);  

  19.     //Wait for the RSF bit (register synchronization flag) in the RTC_CTL register to be set to 1 by hardware  

  20.     RTC_WaitForSynchro();  

  21.     RTC_WaitForLastTask();    

  22.   

  23.     // Enable alarm interrupt     

  24.     RTC_ITConfig(RTC_IT_ALR, ENABLE);    

  25.     RTC_WaitForLastTask();    

  26.   

  27.     //The frequency division coefficient is 1, that is, the minimum time unit is 1/2^15 = 30.5us  

  28.     RTC_SetPrescaler(RTC_PRESCALE);    

  29.     RTC_WaitForLastTask();  

  30.   

  31.     //Start independent watchdog  

  32.     IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable); //Enable register write before access  

  33.     IWDG_SetPrescaler(IWDG_Prescaler_64); //64 division, one cycle 1.6ms  

  34.     IWDG_SetReload(1250); //Longest 12 bits [0,4096] 1250*1.6 = 2s  

  35.     IWDG_ReloadCounter(); //Feed the dog  

  36.     // Enable the door dog  

  37.     IWDG_Enable();    

  38.       

  39.     if (BKP_ReadBackupRegister(BKP_DR6) == 0xabcd)  

  40.     {  

  41.         GPIO_ResetBits(GPIOA, GPIO_Pin_11);  

  42.         BKP_WriteBackupRegister(BKP_DR6,0);  

  43.     }  

  44.     else  

  45.     {  

  46.         GPIO_SetBits(GPIOA,GPIO_Pin_11);  

  47.         BKP_WriteBackupRegister(BKP_DR6,0xabcd);  

  48.     }                                             

  49. }  

  50. else  

  51. {     

  52.     // Exit from standby mode    

  53.     // Clear the wake-up flag  

  54.     RCC_ClearFlag();   

  55.   

  56.     if (BKP_ReadBackupRegister(BKP_DR7) == 0xabcd)  

  57.     {  

  58.         GPIO_ResetBits(GPIOA, GPIO_Pin_8);  

  59.         BKP_WriteBackupRegister(BKP_DR7,0);  

  60.     }  

  61.     else  

  62.     {  

  63.         GPIO_SetBits(GPIOA,GPIO_Pin_8);  

  64.         BKP_WriteBackupRegister(BKP_DR7,0xabcd);  

  65.     }  

  66. }  

  67.   

  68. //Delay 1s  

  69. for (i = 0;i < 100;i++)  

  70. {  

  71.     _delay_ms(10);  

  72. }  

  73.       

  74. // Turn on standby mode and wake up after 2s  

  75. 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

 

  1. // Check if watchdog reset occurs in normal state  

  2. if (RCC_GetFlagStatus(RCC_FLAG_IWDGRST) != RESET)  

  3. {  

  4.     // Clear flag  

  5.     RCC_ClearFlag();  

  6.   

  7.     //RTC function is turned on  

  8.     // Enable external crystal oscillator  

  9.     RCC_LSEConfig(RCC_LSE_ON);  

  10.     //Wait for the external crystal to be ready  

  11.     while(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET);  

  12.   

  13.     //Set the RTC clock to an external crystal  

  14.     RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);  

  15.   

  16.     // Enable the RTC clock  

  17.     RCC_RTCCLKCmd(ENABLE);  

  18.     //Wait for the RSF bit (register synchronization flag) in the RTC_CTL register to be set to 1 by hardware  

  19.     RTC_WaitForSynchro();  

  20.     RTC_WaitForLastTask();    

  21.   

  22.     // Enable alarm interrupt     

  23.     RTC_ITConfig(RTC_IT_ALR, ENABLE);    

  24.     RTC_WaitForLastTask();    

  25.   

  26.     //The frequency division coefficient is 1, that is, the minimum time unit is 1/2^15 = 30.5us  

  27.     RTC_SetPrescaler(RTC_PRESCALE);    

  28.     RTC_WaitForLastTask();  

  29.   

  30.     //Start independent watchdog  

  31.     IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable); //Enable register write before access  

  32.     IWDG_SetPrescaler(IWDG_Prescaler_64); //64 division, one cycle 1.6ms  

  33.     IWDG_SetReload(1250); //Longest 12 bits [0,4096] 1250*1.6 = 2s  

  34.     IWDG_ReloadCounter(); //Feed the dog  

  35.     // Enable the door dog  

  36.     IWDG_Enable();  

  37.   

  38.     if (BKP_ReadBackupRegister(BKP_DR5) == 0xabcd)  

  39.     {  

  40.         GPIO_SetBits(GPIOA,GPIO_Pin_12);  

  41.         BKP_WriteBackupRegister(BKP_DR5,0);  

  42.     }  

  43.     else  

  44.     {  

  45.         GPIO_ResetBits(GPIOA, GPIO_Pin_12);  

  46.         BKP_WriteBackupRegister(BKP_DR5,0xabcd);  

  47.     }     

  48. }  

  49. else  

  50. {  

  51.     // Check whether the wake-up flag is set to determine whether it is the first startup  

  52.     if (PWR_GetFlagStatus(PWR_FLAG_WU) == RESET)  

  53.     {  

  54.         //First start  

  55.         // Initialize the backup registers  

  56.         //BKP_DeInit();  

  57.   

  58.         //RTC function is turned on  

  59.         // Enable external crystal oscillator  

  60.         RCC_LSEConfig(RCC_LSE_ON);  

  61.         //Wait for the external crystal to be ready  

  62.         while(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET);  

  63.       

  64.         //Set the RTC clock to an external crystal  

  65.         RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);  

  66.       

  67.         // Enable the RTC clock  

  68.         RCC_RTCCLKCmd(ENABLE);  

  69.         //Wait for the RSF bit (register synchronization flag) in the RTC_CTL register to be set to 1 by hardware  

  70.         RTC_WaitForSynchro();  

  71.         RTC_WaitForLastTask();    

  72.   

  73.         // Enable alarm interrupt     

  74.         RTC_ITConfig(RTC_IT_ALR, ENABLE);    

  75.         RTC_WaitForLastTask();    

  76.   

  77.         //The frequency division coefficient is 1, that is, the minimum time unit is 1/2^15 = 30.5us  

  78.         RTC_SetPrescaler(RTC_PRESCALE);    

  79.         RTC_WaitForLastTask();  

  80.   

  81.         //Start independent watchdog  

  82.         IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable); //Enable register write before access  

  83.         IWDG_SetPrescaler(IWDG_Prescaler_64); //64 division, one cycle 1.6ms  

  84.         IWDG_SetReload(1250); //Longest 12 bits [0,4096] 1250*1.6 = 2s  

  85.         IWDG_ReloadCounter(); //Feed the dog  

  86.         // Enable the door dog  

  87.         IWDG_Enable();    

  88.           

  89.         if (BKP_ReadBackupRegister(BKP_DR6) == 0xabcd)  

  90.         {  

  91.             GPIO_ResetBits(GPIOA, GPIO_Pin_11);  

  92.             BKP_WriteBackupRegister(BKP_DR6,0);  

  93.         }  

  94.         else  

  95.         {  

  96.             GPIO_SetBits(GPIOA,GPIO_Pin_11);  

  97.             BKP_WriteBackupRegister(BKP_DR6,0xabcd);  

  98.         }                                             

  99.     }  

  100.     else  

  101.     {     

  102.         //Exit from standby mode, wake up by alarm or watchdog   

  103.         // Clear the wake-up flag  

  104.         RCC_ClearFlag();   

  105.   

  106.         if (BKP_ReadBackupRegister(BKP_DR7) == 0xabcd)  

  107.         {  

  108.             GPIO_ResetBits(GPIOA, GPIO_Pin_8);  

  109.             BKP_WriteBackupRegister(BKP_DR7,0);  

  110.         }  

  111.         else  

  112.         {  

  113.             GPIO_SetBits(GPIOA,GPIO_Pin_8);  

  114.             BKP_WriteBackupRegister(BKP_DR7,0xabcd);  

  115.         }  

  116.     }  

  117. }  

  118.   

  119. //Delay 1s  

  120. for (i = 0;i < 100;i++)  

  121. {  

  122.     _delay_ms(10);  

  123. }  

  124.   

  125. // Turn on standby mode and wake up after 2s  

  126. open_standy_mode(60000);  


Keywords:STM32 Reference address:STM32 standby mode wake-up test and independent watchdog test

Previous article:STM32 MCU PWM output test
Next article:STM32 external interrupt test

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号