Subversion Repositories LedShow

Rev

Rev 2 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2 Rev 9
Line 14... Line 14...
14
  ==============================================================================
14
  ==============================================================================
15
  [..]
15
  [..]
16
    (+) The IWDG can be started by either software or hardware (configurable
16
    (+) The IWDG can be started by either software or hardware (configurable
17
        through option byte).
17
        through option byte).
18
 
18
 
19
    (+) The IWDG is clocked by Low-Speed clock (LSI) and thus stays active even
19
    (+) The IWDG is clocked by the Low-Speed Internal clock (LSI) and thus stays
20
        if the main clock fails.
20
        active even if the main clock fails.
21
 
21
 
22
    (+) Once the IWDG is started, the LSI is forced ON and both can not be
22
    (+) Once the IWDG is started, the LSI is forced ON and both cannot be
23
        disabled. The counter starts counting down from the reset value (0xFFF).
23
        disabled. The counter starts counting down from the reset value (0xFFF).
24
        When it reaches the end of count value (0x000) a reset signal is
24
        When it reaches the end of count value (0x000) a reset signal is
25
        generated (IWDG reset).
25
        generated (IWDG reset).
26
 
26
 
27
    (+) Whenever the key value 0x0000 AAAA is written in the IWDG_KR register,
27
    (+) Whenever the key value 0x0000 AAAA is written in the IWDG_KR register,
28
        the IWDG_RLR value is reloaded in the counter and the watchdog reset is
28
        the IWDG_RLR value is reloaded into the counter and the watchdog reset
29
        prevented.
29
        is prevented.
30
 
30
 
31
    (+) The IWDG is implemented in the VDD voltage domain that is still functional
31
    (+) The IWDG is implemented in the VDD voltage domain that is still functional
32
        in STOP and STANDBY mode (IWDG reset can wake-up from STANDBY).
32
        in STOP and STANDBY mode (IWDG reset can wake up the CPU from STANDBY).
33
        IWDGRST flag in RCC_CSR register can be used to inform when an IWDG
33
        IWDGRST flag in RCC_CSR register can be used to inform when an IWDG
34
        reset occurs.
34
        reset occurs.
35
 
35
 
36
    (+) Debug mode : When the microcontroller enters debug mode (core halted),
36
    (+) Debug mode: When the microcontroller enters debug mode (core halted),
37
        the IWDG counter either continues to work normally or stops, depending
37
        the IWDG counter either continues to work normally or stops, depending
38
        on DBG_IWDG_STOP configuration bit in DBG module, accessible through
38
        on DBG_IWDG_STOP configuration bit in DBG module, accessible through
39
        __HAL_DBGMCU_FREEZE_IWDG() and __HAL_DBGMCU_UNFREEZE_IWDG() macros
39
        __HAL_DBGMCU_FREEZE_IWDG() and __HAL_DBGMCU_UNFREEZE_IWDG() macros.
40
 
40
 
41
    [..] Min-max timeout value @32KHz (LSI): ~125us / ~32.7s
41
    [..] Min-max timeout value @32KHz (LSI): ~125us / ~32.7s
42
         The IWDG timeout may vary due to LSI frequency dispersion. STM32F1xx
42
         The IWDG timeout may vary due to LSI clock frequency dispersion.
43
         devices provide the capability to measure the LSI frequency (LSI clock
43
         STM32F1xx devices provide the capability to measure the LSI clock
44
         connected internally to TIM5 CH4 input capture). The measured value
44
         frequency (LSI clock is internally connected to TIM5 CH4 input capture).
45
         can be used to have an IWDG timeout with an acceptable accuracy.
45
         The measured value can be used to have an IWDG timeout with an
-
 
46
         acceptable accuracy.
-
 
47
 
-
 
48
    [..] Default timeout value (necessary for IWDG_SR status register update):
-
 
49
         Constant LSI_VALUE is defined based on the nominal LSI clock frequency.
-
 
50
         This frequency being subject to variations as mentioned above, the
-
 
51
         default timeout value (defined through constant HAL_IWDG_DEFAULT_TIMEOUT
-
 
52
         below) may become too short or too long.
-
 
53
         In such cases, this default timeout value can be tuned by redefining
-
 
54
         the constant LSI_VALUE at user-application level (based, for instance,
-
 
55
         on the measured LSI clock frequency as explained above).
46
 
56
 
47
                     ##### How to use this driver #####
57
                     ##### How to use this driver #####
48
  ==============================================================================
58
  ==============================================================================
49
  [..]
59
  [..]
50
    (#) Use IWDG using HAL_IWDG_Init() function to :
60
    (#) Use IWDG using HAL_IWDG_Init() function to :
51
      (++) Enable instance by writing Start keyword in IWDG_KEY register. LSI
61
      (++) Enable instance by writing Start keyword in IWDG_KEY register. LSI
52
           clock is forced ON and IWDG counter starts downcounting.
62
           clock is forced ON and IWDG counter starts counting down.
53
      (++) Enable write access to configuration register: IWDG_PR & IWDG_RLR.
63
      (++) Enable write access to configuration registers:
-
 
64
          IWDG_PR and IWDG_RLR.
54
      (++) Configure the IWDG prescaler and counter reload value. This reload
65
      (++) Configure the IWDG prescaler and counter reload value. This reload
55
           value will be loaded in the IWDG counter each time the watchdog is
66
           value will be loaded in the IWDG counter each time the watchdog is
56
           reloaded, then the IWDG will start counting down from this value.
67
           reloaded, then the IWDG will start counting down from this value.
57
      (++) wait for status flags to be reset"
68
      (++) Wait for status flags to be reset.
58
 
69
 
59
    (#) Then the application program must refresh the IWDG counter at regular
70
    (#) Then the application program must refresh the IWDG counter at regular
60
        intervals during normal operation to prevent an MCU reset, using
71
        intervals during normal operation to prevent an MCU reset, using
61
        HAL_IWDG_Refresh() function.
72
        HAL_IWDG_Refresh() function.
62
 
73
 
Line 70... Line 81...
70
 
81
 
71
  @endverbatim
82
  @endverbatim
72
  ******************************************************************************
83
  ******************************************************************************
73
  * @attention
84
  * @attention
74
  *
85
  *
75
  * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
86
  * <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
-
 
87
  * All rights reserved.</center></h2>
76
  *
88
  *
77
  * Redistribution and use in source and binary forms, with or without modification,
89
  * This software component is licensed by ST under BSD 3-Clause license,
78
  * are permitted provided that the following conditions are met:
90
  * the "License"; You may not use this file except in compliance with the
79
  *   1. Redistributions of source code must retain the above copyright notice,
-
 
80
  *      this list of conditions and the following disclaimer.
-
 
81
  *   2. Redistributions in binary form must reproduce the above copyright notice,
-
 
82
  *      this list of conditions and the following disclaimer in the documentation
-
 
83
  *      and/or other materials provided with the distribution
91
  * License. You may obtain a copy of the License at:
84
  *   3. Neither the name of STMicroelectronics nor the names of its contributors
-
 
85
  *      may be used to endorse or promote products derived from this software
92
  *                        opensource.org/licenses/BSD-3-Clause
86
  *      without specific prior written permission.
-
 
87
  *
-
 
88
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-
 
89
  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-
 
90
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-
 
91
  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-
 
92
  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-
 
93
  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-
 
94
  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-
 
95
  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-
 
96
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-
 
97
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
 
98
  *
93
  *
99
  ******************************************************************************
94
  ******************************************************************************
100
  */
95
  */
101
 
96
 
102
/* Includes ------------------------------------------------------------------*/
97
/* Includes ------------------------------------------------------------------*/
Line 105... Line 100...
105
/** @addtogroup STM32F1xx_HAL_Driver
100
/** @addtogroup STM32F1xx_HAL_Driver
106
  * @{
101
  * @{
107
  */
102
  */
108
 
103
 
109
#ifdef HAL_IWDG_MODULE_ENABLED
104
#ifdef HAL_IWDG_MODULE_ENABLED
110
/** @defgroup IWDG IWDG
105
/** @addtogroup IWDG
111
  * @brief IWDG HAL module driver.
106
  * @brief IWDG HAL module driver.
112
  * @{
107
  * @{
113
  */
108
  */
114
 
109
 
115
/* Private typedef -----------------------------------------------------------*/
110
/* Private typedef -----------------------------------------------------------*/
116
/* Private define ------------------------------------------------------------*/
111
/* Private define ------------------------------------------------------------*/
117
/** @defgroup IWDG_Private_Defines IWDG Private Defines
112
/** @defgroup IWDG_Private_Defines IWDG Private Defines
118
  * @{
113
  * @{
119
  */
114
  */
120
/* Status register need 5 RC LSI divided by prescaler clock to be updated. With
115
/* Status register needs up to 5 LSI clock periods divided by the clock
121
   higher prescaler (256), and according to HSI variation, we need to wait at
116
   prescaler to be updated. The number of LSI clock periods is upper-rounded to
122
   least 6 cycles so 48 ms. */
117
   6 for the timeout value calculation.
-
 
118
   The timeout value is also calculated using the highest prescaler (256) and
-
 
119
   the LSI_VALUE constant. The value of this constant can be changed by the user
-
 
120
   to take into account possible LSI clock period variations.
-
 
121
   The timeout value is multiplied by 1000 to be converted in milliseconds. */
123
#define HAL_IWDG_DEFAULT_TIMEOUT            48U
122
#define HAL_IWDG_DEFAULT_TIMEOUT ((6UL * 256UL * 1000UL) / LSI_VALUE)
124
/**
123
/**
125
  * @}
124
  * @}
126
  */
125
  */
127
 
126
 
128
/* Private macro -------------------------------------------------------------*/
127
/* Private macro -------------------------------------------------------------*/
Line 172... Line 171...
172
  /* Check the parameters */
171
  /* Check the parameters */
173
  assert_param(IS_IWDG_ALL_INSTANCE(hiwdg->Instance));
172
  assert_param(IS_IWDG_ALL_INSTANCE(hiwdg->Instance));
174
  assert_param(IS_IWDG_PRESCALER(hiwdg->Init.Prescaler));
173
  assert_param(IS_IWDG_PRESCALER(hiwdg->Init.Prescaler));
175
  assert_param(IS_IWDG_RELOAD(hiwdg->Init.Reload));
174
  assert_param(IS_IWDG_RELOAD(hiwdg->Init.Reload));
176
 
175
 
177
  /* Enable IWDG. LSI is turned on automaticaly */
176
  /* Enable IWDG. LSI is turned on automatically */
178
  __HAL_IWDG_START(hiwdg);
177
  __HAL_IWDG_START(hiwdg);
179
 
178
 
180
  /* Enable write access to IWDG_PR and IWDG_RLR registers by writing 0x5555 in KR */
179
  /* Enable write access to IWDG_PR and IWDG_RLR registers by writing
-
 
180
  0x5555 in KR */
181
  IWDG_ENABLE_WRITE_ACCESS(hiwdg);
181
  IWDG_ENABLE_WRITE_ACCESS(hiwdg);
182
 
182
 
183
  /* Write to IWDG registers the Prescaler & Reload values to work with */
183
  /* Write to IWDG registers the Prescaler & Reload values to work with */
184
  hiwdg->Instance->PR = hiwdg->Init.Prescaler;
184
  hiwdg->Instance->PR = hiwdg->Init.Prescaler;
185
  hiwdg->Instance->RLR = hiwdg->Init.Reload;
185
  hiwdg->Instance->RLR = hiwdg->Init.Reload;
186
 
186
 
187
  /* Check pending flag, if previous update not done, return timeout */
187
  /* Check pending flag, if previous update not done, return timeout */
188
  tickstart = HAL_GetTick();
188
  tickstart = HAL_GetTick();
189
 
189
 
190
  /* Wait for register to be updated */
190
  /* Wait for register to be updated */
191
  while (hiwdg->Instance->SR != RESET)
191
  while (hiwdg->Instance->SR != 0x00u)
192
  {
192
  {
193
    if ((HAL_GetTick() - tickstart) > HAL_IWDG_DEFAULT_TIMEOUT)
193
    if ((HAL_GetTick() - tickstart) > HAL_IWDG_DEFAULT_TIMEOUT)
194
    {
194
    {
195
      return HAL_TIMEOUT;
195
      return HAL_TIMEOUT;
196
    }
196
    }
Line 205... Line 205...
205
 
205
 
206
/**
206
/**
207
  * @}
207
  * @}
208
  */
208
  */
209
 
209
 
-
 
210
 
210
/** @addtogroup IWDG_Exported_Functions_Group2
211
/** @addtogroup IWDG_Exported_Functions_Group2
211
  *  @brief   IO operation functions
212
  *  @brief   IO operation functions
212
  *
213
  *
213
@verbatim
214
@verbatim
214
 ===============================================================================
215
 ===============================================================================
Line 219... Line 220...
219
 
220
 
220
@endverbatim
221
@endverbatim
221
  * @{
222
  * @{
222
  */
223
  */
223
 
224
 
-
 
225
 
224
/**
226
/**
225
  * @brief  Refresh the IWDG.
227
  * @brief  Refresh the IWDG.
226
  * @param  hiwdg  pointer to a IWDG_HandleTypeDef structure that contains
228
  * @param  hiwdg  pointer to a IWDG_HandleTypeDef structure that contains
227
  *                the configuration information for the specified IWDG module.
229
  *                the configuration information for the specified IWDG module.
228
  * @retval HAL status
230
  * @retval HAL status