STM32 independent watchdog principle

Publisher:DelightWish123Latest update time:2018-05-14 Source: eefocusKeywords:STM32 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

The independent watchdog of STM32 is driven by a dedicated internal 40Khz low-speed clock, that is, it is still effective even if the main clock fails. Here we need to note that the clock of the independent watchdog is not an accurate 40Khz, but a clock that varies between 30 and 60Khz. It is just that we estimate it to be 40Khz. The watchdog is not very demanding on time, and a little deviation in the clock is acceptable.

Several registers related to independent watchdog

Working principle of independent watchdog: Write 0XCCCC in the key value register (IWDG_KR) to enable the independent watchdog. At this time, the counter starts to count down from its reset value OXFFF. When the counter counts to the end 0X000, a reset signal (IWDG_RESET) is generated. Whenever 0XAAAA is written to the register IWDG_KR, the value in IWDG_RLR will be reloaded into the counter to avoid a watchdog reset.

Write protection of prescaler register (IWDG_PR) and reload register (IWDG_RLR): IWDG_PR and IWDG_RLR registers have write protection function. To modify the value of these two registers, first write 0X5555 to IWDG_KR. Writing to this register with a different value or reloading (writing 0XAAAA) will restart the write protection.

2. Independent watchdog startup process

In this way, as long as we set the above three registers accordingly, we can start the STM32 independent watchdog. The startup process is as follows:

2.1. 1. Inhale 0X5555 into IWDG_KR

Through this step we have cancelled the write protection of IWDG_PR and IWDG_RLR. The next step is to set their initial values.

Set the initial values ​​of IWDG_PR and IWDG_RLR.

Let's calculate the watchdog feeding time (watchdog overflow time) calculation formula

All=((4*2^prer)*rlr)/40

 Tout is the watchdog overflow time (in ms), prer is the watchdog clock pre-division value (IWDG_PR value), ranging from 0 to 7, and rlr is the watchdog reload value (IWDG_RLR). For example, if we set prer to 4 and rlr to 625, we can calculate Tout = 64 * 625 / 40 = 1000ms, so the watchdog overflow time is 1S. As long as 0XAAAA is sucked into IWDG_KR once within this second, the watchdog will not be reset (it is also possible to write multiple times) (since the watchdog clock is not accurate to 40Khz, do not feed the dog too late to avoid a watchdog reset).

2.2. 2. Write 0XAAAA to IWDG_KR

This sentence can load the initial count value in the reload register (IWDG_RLR) into the watchdog counter (you can also use this command to feed the watchdog).

2.3. 3. Write 0XCCCC to IWDG_KR

Through this sentence, we have started the watchdog of STM32. After enabling the watchdog, we must feed the dog at a certain interval in the program, otherwise it will cause the program to reset. Taking advantage of this, we use an LED to indicate whether it is reset and verify the independent watchdog.

The watchdog core in STM32 is inside the chip and does not require an external circuit. Here we use two IO ports in the external circuit, one for inputting the dog feeding signal and the other for indicating whether the program is reset. The WK_UP button is used to feed the dog and DS0 is used to indicate program restart.


Keywords:STM32 Reference address:STM32 independent watchdog principle

Previous article:The difference between stm32 independent watchdog and window watchdog
Next article:STM32 self-study notes - watchdog

Recommended ReadingLatest update time:2024-11-23 03:06

STM32 GPIO register introduction and settings
Each GPIO port has two 32-bit configuration registers (GPIOx_CRL, GPIOx_CRH) to control the high and low eight bits of each port respectively. If the IO port is 0-7, write the CRL register, if the IO port is 8-15, write the CRH register, two 32-bit data registers (GPIOx_IDR, GPIOx_ODR), one is read-only as input data
[Microcontroller]
STM32 heap and stack, storage of variables
The topic of heap and stack has become a monthly topic for programmers, and most of the discussions are based on the OS layer.   So, what is the distribution of the heap and stack in a bare-bones MCU? Here is an excerpt from the Internet:     When you first take over STM32, you only write one int main() { while(1); }
[Microcontroller]
STM32 heap and stack, storage of variables
STM32 I2C_EEPROM read and write
EEPROM data organization:  EEPROM devices divide their storage matrix into pages:  The AT24C02 EEPROM is divided into 32 pages, and each page can store 8 bytes of data. If more than 8 bytes are written to the same page, the excess will be written at the starting address of the page (that is, the part written at the b
[Microcontroller]
Significance of assert_param function
In the STM32 firmware library and the provided routines, assert_param() can be seen everywhere. If you open the stm32f10x_conf.h file in any routine, you can see that assert_param is actually a macro definition; in the firmware library, its function is to detect whether the parameters passed to the function are valid
[Microcontroller]
Introduction to STM32 input capture
     Input capture mode can be used to measure pulse width or frequency. Except for TIM6 and TIM7, all other STM32 timers have input capture function. Simply put, STM32 input capture detects the edge signal on TIMx_CHx. When the edge signal changes (such as rising edge/falling edge), the current timer value (TIMx_CNT)
[Microcontroller]
stm32 nested vector interrupt controller NVIC
The Nested Vectored Interrupt Controller (NVIC) is closely connected to the processor core interface, which enables low-latency interrupt processing and efficient processing of late interrupts. The Nested Vectored Interrupt Controller manages interrupts including kernel exceptions. NVIC related functions are included
[Microcontroller]
stm32 nested vector interrupt controller NVIC
STM32 remapping and address mapping
Remap In stm32, some ports' peripherals have been used by other pins. In this case, port remapping is needed to solve the problem, which is very convenient. Take USART1 as an example  The steps for remapping are: Turn on the remapped clock and the USART remapped I/O port pin clock,  RCC_APB2PeriphClockCmd(RCC_APB2
[Microcontroller]
STM32 remapping and address mapping
STM32SPI read and write functions
//SPIx read and write a byte //TxData: Bytes to be written //Return value: the bytes read u8 SPIx_ReadWriteByte(u8 TxData) {                                                                        while((SPI1- SR&(1 1))==0);                     SPI1- DR=TxData; //Send a byte                    while((SPI1
[Microcontroller]
Latest Microcontroller Articles
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号