Subversion Repositories EngineBay2

Rev

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

Rev 2 Rev 28
Line 1... Line 1...
1
/**
1
/**
2
  ******************************************************************************
2
  ******************************************************************************
3
  * @file    stm32l1xx_hal_rcc_ex.c
3
  * @file    stm32l1xx_hal_rcc_ex.c
4
  * @author  MCD Application Team
4
  * @author  MCD Application Team
5
  * @version V1.2.0
-
 
6
  * @date    01-July-2016
-
 
7
  * @brief   Extended RCC HAL module driver.
5
  * @brief   Extended RCC HAL module driver.
8
  *          This file provides firmware functions to manage the following
6
  *          This file provides firmware functions to manage the following
9
  *          functionalities RCC extension peripheral:
7
  *          functionalities RCC extension peripheral:
10
  *           + Extended Peripheral Control functions
8
  *           + Extended Peripheral Control functions
11
  *
9
  *
12
  ******************************************************************************
10
  ******************************************************************************
13
  * @attention
11
  * @attention
14
  *
12
  *
15
  * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
13
  * <h2><center>&copy; Copyright(c) 2017 STMicroelectronics.
-
 
14
  * All rights reserved.</center></h2>
16
  *
15
  *
17
  * Redistribution and use in source and binary forms, with or without modification,
16
  * This software component is licensed by ST under BSD 3-Clause license,
18
  * are permitted provided that the following conditions are met:
17
  * the "License"; You may not use this file except in compliance with the
19
  *   1. Redistributions of source code must retain the above copyright notice,
-
 
20
  *      this list of conditions and the following disclaimer.
-
 
21
  *   2. Redistributions in binary form must reproduce the above copyright notice,
-
 
22
  *      this list of conditions and the following disclaimer in the documentation
-
 
23
  *      and/or other materials provided with the distribution.
18
  * License. You may obtain a copy of the License at:
24
  *   3. Neither the name of STMicroelectronics nor the names of its contributors
-
 
25
  *      may be used to endorse or promote products derived from this software
19
  *                        opensource.org/licenses/BSD-3-Clause
26
  *      without specific prior written permission.
-
 
27
  *
20
  *
28
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-
 
29
  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-
 
30
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-
 
31
  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-
 
32
  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-
 
33
  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-
 
34
  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-
 
35
  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-
 
36
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-
 
37
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
 
38
  *
-
 
39
  ******************************************************************************  
21
  ******************************************************************************
40
  */
22
  */
41
 
23
 
42
/* Includes ------------------------------------------------------------------*/
24
/* Includes ------------------------------------------------------------------*/
43
#include "stm32l1xx_hal.h"
25
#include "stm32l1xx_hal.h"
44
 
26
 
45
/** @addtogroup STM32L1xx_HAL_Driver
27
/** @addtogroup STM32L1xx_HAL_Driver
Line 59... Line 41...
59
  * @{
41
  * @{
60
  */
42
  */
61
/**
43
/**
62
  * @}
44
  * @}
63
  */
45
  */
64
 
46
 
65
/* Private macro -------------------------------------------------------------*/
47
/* Private macro -------------------------------------------------------------*/
66
/** @defgroup RCCEx_Private_Macros RCCEx Private Macros
48
/** @defgroup RCCEx_Private_Macros RCCEx Private Macros
67
  * @{
49
  * @{
68
  */
50
  */
69
/**
51
/**
Line 76... Line 58...
76
 
58
 
77
/** @defgroup RCCEx_Exported_Functions RCCEx Exported Functions
59
/** @defgroup RCCEx_Exported_Functions RCCEx Exported Functions
78
  * @{
60
  * @{
79
  */
61
  */
80
 
62
 
81
/** @defgroup RCCEx_Exported_Functions_Group1 Extended Peripheral Control functions
63
/** @defgroup RCCEx_Exported_Functions_Group1 Extended Peripheral Control functions
82
 *  @brief  Extended Peripheral Control functions  
64
 *  @brief  Extended Peripheral Control functions
83
 *
65
 *
84
@verbatim  
66
@verbatim
85
 ===============================================================================
67
 ===============================================================================
86
                ##### Extended Peripheral Control functions  #####
68
                ##### Extended Peripheral Control functions  #####
87
 ===============================================================================  
69
 ===============================================================================
88
    [..]
70
    [..]
89
    This subsection provides a set of functions allowing to control the RCC Clocks
71
    This subsection provides a set of functions allowing to control the RCC Clocks
90
    frequencies.
72
    frequencies.
91
    [..]
73
    [..]
92
    (@) Important note: Care must be taken when HAL_RCCEx_PeriphCLKConfig() is used to
74
    (@) Important note: Care must be taken when HAL_RCCEx_PeriphCLKConfig() is used to
93
        select the RTC clock source; in this case the Backup domain will be reset in  
75
        select the RTC clock source; in this case the Backup domain will be reset in
94
        order to modify the RTC Clock source, as consequence RTC registers (including
76
        order to modify the RTC Clock source, as consequence RTC registers (including
95
        the backup registers) are set to their reset values.
77
        the backup registers) are set to their reset values.
96
     
78
 
97
@endverbatim
79
@endverbatim
98
  * @{
80
  * @{
99
  */
81
  */
100
 
82
 
101
/**
83
/**
Line 107... Line 89...
107
  * @note   If HAL_ERROR returned, first switch-OFF HSE clock oscillator with @ref HAL_RCC_OscConfig()
89
  * @note   If HAL_ERROR returned, first switch-OFF HSE clock oscillator with @ref HAL_RCC_OscConfig()
108
  *         to possibly update HSE divider.
90
  *         to possibly update HSE divider.
109
  */
91
  */
110
HAL_StatusTypeDef HAL_RCCEx_PeriphCLKConfig(RCC_PeriphCLKInitTypeDef  *PeriphClkInit)
92
HAL_StatusTypeDef HAL_RCCEx_PeriphCLKConfig(RCC_PeriphCLKInitTypeDef  *PeriphClkInit)
111
{
93
{
112
  uint32_t tickstart = 0U;
94
  uint32_t tickstart;
113
  uint32_t temp_reg = 0U;
95
  uint32_t temp_reg;
114
 
96
 
115
  /* Check the parameters */
97
  /* Check the parameters */
116
  assert_param(IS_RCC_PERIPHCLOCK(PeriphClkInit->PeriphClockSelection));
98
  assert_param(IS_RCC_PERIPHCLOCK(PeriphClkInit->PeriphClockSelection));
117
 
99
 
118
  /*------------------------------- RTC/LCD Configuration ------------------------*/
100
  /*------------------------------- RTC/LCD Configuration ------------------------*/
119
  if ((((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_RTC) == RCC_PERIPHCLK_RTC)
101
  if ((((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_RTC) == RCC_PERIPHCLK_RTC)
120
#if defined(LCD)
102
#if defined(LCD)
121
   || (((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_LCD) == RCC_PERIPHCLK_LCD)
103
   || (((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_LCD) == RCC_PERIPHCLK_LCD)
122
#endif /* LCD */
104
#endif /* LCD */
123
     )
105
     )
124
  {
106
  {
Line 135... Line 117...
135
    }
117
    }
136
#endif /* LCD */
118
#endif /* LCD */
137
 
119
 
138
    FlagStatus       pwrclkchanged = RESET;
120
    FlagStatus       pwrclkchanged = RESET;
139
 
121
 
140
    /* As soon as function is called to change RTC clock source, activation of the
122
    /* As soon as function is called to change RTC clock source, activation of the
141
       power domain is done. */
123
       power domain is done. */
142
    /* Requires to enable write access to Backup Domain of necessary */
124
    /* Requires to enable write access to Backup Domain of necessary */
143
    if(__HAL_RCC_PWR_IS_CLK_DISABLED())
125
    if(__HAL_RCC_PWR_IS_CLK_DISABLED())
144
    {
126
    {
145
      __HAL_RCC_PWR_CLK_ENABLE();
127
      __HAL_RCC_PWR_CLK_ENABLE();
146
      pwrclkchanged = SET;
128
      pwrclkchanged = SET;
147
    }
129
    }
148
   
130
 
149
    if(HAL_IS_BIT_CLR(PWR->CR, PWR_CR_DBP))
131
    if(HAL_IS_BIT_CLR(PWR->CR, PWR_CR_DBP))
150
    {
132
    {
151
      /* Enable write access to Backup domain */
133
      /* Enable write access to Backup domain */
152
      SET_BIT(PWR->CR, PWR_CR_DBP);
134
      SET_BIT(PWR->CR, PWR_CR_DBP);
153
     
135
 
154
      /* Wait for Backup domain Write protection disable */
136
      /* Wait for Backup domain Write protection disable */
155
      tickstart = HAL_GetTick();
137
      tickstart = HAL_GetTick();
156
 
138
 
157
      while(HAL_IS_BIT_CLR(PWR->CR, PWR_CR_DBP))
139
      while(HAL_IS_BIT_CLR(PWR->CR, PWR_CR_DBP))
158
      {
140
      {
Line 161... Line 143...
161
          return HAL_TIMEOUT;
143
          return HAL_TIMEOUT;
162
        }
144
        }
163
      }
145
      }
164
    }
146
    }
165
 
147
 
166
    /* Check if user wants to change HSE RTC prescaler whereas HSE is enabled */
148
    /* Check if user wants to change HSE RTC prescaler whereas HSE is enabled */
167
    temp_reg = (RCC->CR & RCC_CR_RTCPRE);
149
    temp_reg = (RCC->CR & RCC_CR_RTCPRE);
168
    if ((temp_reg != (PeriphClkInit->RTCClockSelection & RCC_CR_RTCPRE))
150
    if ((temp_reg != (PeriphClkInit->RTCClockSelection & RCC_CR_RTCPRE))
169
#if defined (LCD)
151
#if defined (LCD)
170
     || (temp_reg != (PeriphClkInit->LCDClockSelection & RCC_CR_RTCPRE))
152
     || (temp_reg != (PeriphClkInit->LCDClockSelection & RCC_CR_RTCPRE))
171
#endif /* LCD */
153
#endif /* LCD */
172
       )
154
       )
173
    { /* Check HSE State */
155
    { /* Check HSE State */
174
      if (((PeriphClkInit->RTCClockSelection & RCC_CSR_RTCSEL) == RCC_CSR_RTCSEL_HSE) && HAL_IS_BIT_SET(RCC->CR, RCC_CR_HSERDY))
156
      if ((PeriphClkInit->RTCClockSelection & RCC_CSR_RTCSEL) == RCC_CSR_RTCSEL_HSE)
175
      {
157
      {
-
 
158
        if (HAL_IS_BIT_SET(RCC->CR, RCC_CR_HSERDY))
-
 
159
        {
176
        /* To update HSE divider, first switch-OFF HSE clock oscillator*/
160
          /* To update HSE divider, first switch-OFF HSE clock oscillator*/
177
        return HAL_ERROR;
161
          return HAL_ERROR;
-
 
162
        }
178
      }
163
      }
179
    }
164
    }
180
   
165
 
181
    /* Reset the Backup domain only if the RTC Clock source selection is modified from reset value */
166
    /* Reset the Backup domain only if the RTC Clock source selection is modified from reset value */
182
    temp_reg = (RCC->CSR & RCC_CSR_RTCSEL);
167
    temp_reg = (RCC->CSR & RCC_CSR_RTCSEL);
183
   
168
 
184
    if((temp_reg != 0x00000000U) && (((temp_reg != (PeriphClkInit->RTCClockSelection & RCC_CSR_RTCSEL)) \
169
    if((temp_reg != 0x00000000U) && (((temp_reg != (PeriphClkInit->RTCClockSelection & RCC_CSR_RTCSEL)) \
185
      && (((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_RTC) == RCC_PERIPHCLK_RTC))
170
      && (((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_RTC) == RCC_PERIPHCLK_RTC))
186
#if defined(LCD)
171
#if defined(LCD)
187
      || ((temp_reg != (PeriphClkInit->LCDClockSelection & RCC_CSR_RTCSEL)) \
172
      || ((temp_reg != (PeriphClkInit->LCDClockSelection & RCC_CSR_RTCSEL)) \
188
       && (((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_LCD) == RCC_PERIPHCLK_LCD))
173
       && (((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_LCD) == RCC_PERIPHCLK_LCD))
189
#endif /* LCD */
174
#endif /* LCD */
190
     ))
175
     ))
191
    {
176
    {
192
      /* Store the content of CSR register before the reset of Backup Domain */
177
      /* Store the content of CSR register before the reset of Backup Domain */
193
      temp_reg = (RCC->CSR & ~(RCC_CSR_RTCSEL));
178
      temp_reg = (RCC->CSR & ~(RCC_CSR_RTCSEL));
194
     
179
 
195
      /* RTC Clock selection can be changed only if the Backup Domain is reset */
180
      /* RTC Clock selection can be changed only if the Backup Domain is reset */
196
      __HAL_RCC_BACKUPRESET_FORCE();
181
      __HAL_RCC_BACKUPRESET_FORCE();
197
      __HAL_RCC_BACKUPRESET_RELEASE();
182
      __HAL_RCC_BACKUPRESET_RELEASE();
198
     
183
 
199
      /* Restore the Content of CSR register */
184
      /* Restore the Content of CSR register */
200
      RCC->CSR = temp_reg;
185
      RCC->CSR = temp_reg;
201
     
186
 
202
       /* Wait for LSERDY if LSE was enabled */
187
       /* Wait for LSERDY if LSE was enabled */
203
      if (HAL_IS_BIT_SET(temp_reg, RCC_CSR_LSEON))
188
      if (HAL_IS_BIT_SET(temp_reg, RCC_CSR_LSEON))
204
      {
189
      {
205
        /* Get Start Tick */
190
        /* Get Start Tick */
206
        tickstart = HAL_GetTick();
191
        tickstart = HAL_GetTick();
207
       
192
 
208
        /* Wait till LSE is ready */  
193
        /* Wait till LSE is ready */
209
        while(__HAL_RCC_GET_FLAG(RCC_FLAG_LSERDY) == RESET)
194
        while(__HAL_RCC_GET_FLAG(RCC_FLAG_LSERDY) == 0U)
210
        {
195
        {
211
          if((HAL_GetTick() - tickstart ) > RCC_LSE_TIMEOUT_VALUE)
196
          if((HAL_GetTick() - tickstart ) > RCC_LSE_TIMEOUT_VALUE)
212
          {
197
          {
213
            return HAL_TIMEOUT;
198
            return HAL_TIMEOUT;
214
          }
199
          }
Line 221... Line 206...
221
    if(pwrclkchanged == SET)
206
    if(pwrclkchanged == SET)
222
    {
207
    {
223
      __HAL_RCC_PWR_CLK_DISABLE();
208
      __HAL_RCC_PWR_CLK_DISABLE();
224
    }
209
    }
225
  }
210
  }
226
 
211
 
227
  return HAL_OK;
212
  return HAL_OK;
228
}
213
}
229
 
214
 
230
/**
215
/**
231
  * @brief  Get the PeriphClkInit according to the internal RCC configuration registers.
216
  * @brief  Get the PeriphClkInit according to the internal RCC configuration registers.
232
  * @param  PeriphClkInit pointer to an RCC_PeriphCLKInitTypeDef structure that
217
  * @param  PeriphClkInit pointer to an RCC_PeriphCLKInitTypeDef structure that
233
  *         returns the configuration information for the Extended Peripherals clocks(RTC/LCD clocks).
218
  *         returns the configuration information for the Extended Peripherals clocks(RTC/LCD clocks).
234
  * @retval None
219
  * @retval None
235
  */
220
  */
236
void HAL_RCCEx_GetPeriphCLKConfig(RCC_PeriphCLKInitTypeDef  *PeriphClkInit)
221
void HAL_RCCEx_GetPeriphCLKConfig(RCC_PeriphCLKInitTypeDef  *PeriphClkInit)
237
{
222
{
238
  uint32_t srcclk = 0;
223
  uint32_t srcclk;
239
 
224
 
240
  /* Set all possible values for the extended clock type parameter------------*/
225
  /* Set all possible values for the extended clock type parameter------------*/
241
  PeriphClkInit->PeriphClockSelection = RCC_PERIPHCLK_RTC;
226
  PeriphClkInit->PeriphClockSelection = RCC_PERIPHCLK_RTC;
242
#if defined(LCD)   
227
#if defined(LCD)
243
  PeriphClkInit->PeriphClockSelection |= RCC_PERIPHCLK_LCD;
228
  PeriphClkInit->PeriphClockSelection |= RCC_PERIPHCLK_LCD;
244
#endif /* LCD */
229
#endif /* LCD */
245
 
230
 
246
  /* Get the RTC/LCD configuration -----------------------------------------------*/
231
  /* Get the RTC/LCD configuration -----------------------------------------------*/
247
  srcclk = __HAL_RCC_GET_RTC_SOURCE();
232
  srcclk = __HAL_RCC_GET_RTC_SOURCE();
Line 270... Line 255...
270
  * @note   (*) means that this peripheral is not present on all the devices
255
  * @note   (*) means that this peripheral is not present on all the devices
271
  * @retval Frequency in Hz (0: means that no available frequency for the peripheral)
256
  * @retval Frequency in Hz (0: means that no available frequency for the peripheral)
272
  */
257
  */
273
uint32_t HAL_RCCEx_GetPeriphCLKFreq(uint32_t PeriphClk)
258
uint32_t HAL_RCCEx_GetPeriphCLKFreq(uint32_t PeriphClk)
274
{
259
{
275
  uint32_t temp_reg = 0U, clkprediv = 0U, frequency = 0U;
260
  uint32_t frequency = 0;
276
  uint32_t srcclk = 0U;
261
  uint32_t srcclk;
277
 
262
 
278
  /* Check the parameters */
263
  /* Check the parameters */
279
  assert_param(IS_RCC_PERIPHCLOCK(PeriphClk));
264
  assert_param(IS_RCC_PERIPHCLOCK(PeriphClk));
280
 
265
 
281
  switch (PeriphClk)
266
  switch (PeriphClk)
282
  {
267
  {
283
  case RCC_PERIPHCLK_RTC:
268
  case RCC_PERIPHCLK_RTC:
284
#if defined(LCD)
269
#if defined(LCD)
285
  case RCC_PERIPHCLK_LCD:
270
  case RCC_PERIPHCLK_LCD:
286
#endif /* LCD */
271
#endif /* LCD */
287
    {
272
    {
288
      /* Get RCC CSR configuration ------------------------------------------------------*/
-
 
289
      temp_reg = RCC->CSR;
-
 
290
 
-
 
291
      /* Get the current RTC source */
273
      /* Get the current RTC source */
292
      srcclk = __HAL_RCC_GET_RTC_SOURCE();
274
      srcclk = __HAL_RCC_GET_RTC_SOURCE();
293
 
275
 
294
      /* Check if LSE is ready if RTC clock selection is LSE */
276
      /* Check if LSE is ready if RTC clock selection is LSE */
295
      if ((srcclk == RCC_RTCCLKSOURCE_LSE) && (HAL_IS_BIT_SET(temp_reg, RCC_CSR_LSERDY)))
277
      if (srcclk == RCC_RTCCLKSOURCE_LSE)
296
      {
278
      {
-
 
279
        if (HAL_IS_BIT_SET(RCC->CSR, RCC_CSR_LSERDY))
-
 
280
        {
297
        frequency = LSE_VALUE;
281
          frequency = LSE_VALUE;
-
 
282
        }
298
      }
283
      }
299
      /* Check if LSI is ready if RTC clock selection is LSI */
284
      /* Check if LSI is ready if RTC clock selection is LSI */
300
      else if ((srcclk == RCC_RTCCLKSOURCE_LSI) && (HAL_IS_BIT_SET(temp_reg, RCC_CSR_LSIRDY)))
285
      else if (srcclk == RCC_RTCCLKSOURCE_LSI)
301
      {
286
      {
-
 
287
        if (HAL_IS_BIT_SET(RCC->CSR, RCC_CSR_LSIRDY))
-
 
288
        {
302
        frequency = LSI_VALUE;
289
          frequency = LSI_VALUE;
-
 
290
        }
303
      }
291
      }
304
      /* Check if HSE is ready and if RTC clock selection is HSE */
292
      /* Check if HSE is ready and if RTC clock selection is HSE */
305
      else if ((srcclk == RCC_RTCCLKSOURCE_HSE_DIVX) && (HAL_IS_BIT_SET(RCC->CR, RCC_CR_HSERDY)))
293
      else if (srcclk == RCC_RTCCLKSOURCE_HSE_DIVX)
306
      {
294
      {
307
        /* Get the current HSE clock divider */
-
 
308
        clkprediv = __HAL_RCC_GET_RTC_HSE_PRESCALER();
295
        if (HAL_IS_BIT_SET(RCC->CR, RCC_CR_HSERDY))
309
 
-
 
310
        switch (clkprediv)
-
 
311
        {
296
        {
312
          case RCC_RTC_HSE_DIV_16:  /* HSE DIV16 has been selected */
-
 
313
          {
-
 
314
            frequency = HSE_VALUE / 16U;
297
          /* Get the current HSE clock divider */
315
            break;
-
 
316
          }
-
 
317
          case RCC_RTC_HSE_DIV_8:   /* HSE DIV8 has been selected  */
-
 
318
          {
-
 
319
            frequency = HSE_VALUE / 8U;
-
 
320
            break;
-
 
321
          }
-
 
322
          case RCC_RTC_HSE_DIV_4:   /* HSE DIV4 has been selected  */
-
 
323
          {
-
 
324
            frequency = HSE_VALUE / 4U;
298
          switch (__HAL_RCC_GET_RTC_HSE_PRESCALER())
325
            break;
-
 
326
          }
-
 
327
          default:                  /* HSE DIV2 has been selected  */
-
 
328
          {
299
          {
-
 
300
            case RCC_RTC_HSE_DIV_16:  /* HSE DIV16 has been selected */
-
 
301
            {
-
 
302
              frequency = HSE_VALUE / 16U;
-
 
303
              break;
-
 
304
            }
-
 
305
            case RCC_RTC_HSE_DIV_8:   /* HSE DIV8 has been selected  */
-
 
306
            {
-
 
307
              frequency = HSE_VALUE / 8U;
-
 
308
              break;
-
 
309
            }
-
 
310
            case RCC_RTC_HSE_DIV_4:   /* HSE DIV4 has been selected  */
-
 
311
            {
-
 
312
              frequency = HSE_VALUE / 4U;
-
 
313
              break;
-
 
314
            }
-
 
315
            default:                  /* HSE DIV2 has been selected  */
-
 
316
            {
329
            frequency = HSE_VALUE / 2U;
317
              frequency = HSE_VALUE / 2U;
330
            break;
318
              break;
-
 
319
            }
331
          }
320
          }
332
        }
321
        }
333
      }
322
      }
334
      /* Clock not enabled for RTC */
-
 
335
      else
323
      else
336
      {
324
      {
337
        frequency = 0U;
325
        /* No clock source, frequency default init at 0 */
338
      }
326
      }
339
      break;
327
      break;
340
    }
328
    }
-
 
329
 
341
  default:
330
  default:
342
    {
-
 
343
      break;
331
    break;
344
    }
-
 
345
  }
332
  }
-
 
333
 
346
  return(frequency);
334
  return(frequency);
347
}
335
}
348
 
336
 
349
#if defined(RCC_LSECSS_SUPPORT)
337
#if defined(RCC_LSECSS_SUPPORT)
350
/**
338
/**
Line 353... Line 341...
353
  *         to the RTC but no hardware action is made to the registers.
341
  *         to the RTC but no hardware action is made to the registers.
354
  *         In Standby mode a wakeup is generated. In other modes an interrupt can be sent to wakeup
342
  *         In Standby mode a wakeup is generated. In other modes an interrupt can be sent to wakeup
355
  *         the software (see Section 5.3.4: Clock interrupt register (RCC_CIR) on page 104).
343
  *         the software (see Section 5.3.4: Clock interrupt register (RCC_CIR) on page 104).
356
  *         The software MUST then disable the LSECSSON bit, stop the defective 32 kHz oscillator
344
  *         The software MUST then disable the LSECSSON bit, stop the defective 32 kHz oscillator
357
  *         (disabling LSEON), and can change the RTC clock source (no clock or LSI or HSE, with
345
  *         (disabling LSEON), and can change the RTC clock source (no clock or LSI or HSE, with
358
  *         RTCSEL), or take any required action to secure the application.  
346
  *         RTCSEL), or take any required action to secure the application.
359
  * @note   LSE CSS available only for high density and medium+ devices
347
  * @note   LSE CSS available only for high density and medium+ devices
360
  * @retval None
348
  * @retval None
361
  */
349
  */
362
void HAL_RCCEx_EnableLSECSS(void)
350
void HAL_RCCEx_EnableLSECSS(void)
363
{
351
{
364
  *(__IO uint32_t *) CSR_LSECSSON_BB = (uint32_t)ENABLE;
352
  *(__IO uint32_t *) CSR_LSECSSON_BB = (uint32_t)ENABLE;
365
}
353
}
366
 
354
 
367
/**
355
/**
368
  * @brief  Disables the LSE Clock Security System.
356
  * @brief  Disables the LSE Clock Security System.
369
  * @note   Once enabled this bit cannot be disabled, except after an LSE failure detection
357
  * @note   Once enabled this bit cannot be disabled, except after an LSE failure detection
370
  *         (LSECSSD=1). In that case the software MUST disable the LSECSSON bit.
358
  *         (LSECSSD=1). In that case the software MUST disable the LSECSSON bit.
371
  *         Reset by power on reset and RTC software reset (RTCRST bit).
359
  *         Reset by power on reset and RTC software reset (RTCRST bit).
372
  * @note   LSE CSS available only for high density and medium+ devices
360
  * @note   LSE CSS available only for high density and medium+ devices
373
  * @retval None
361
  * @retval None
374
  */
362
  */
Line 391... Line 379...
391
  /* Enable LSE CSS */
379
  /* Enable LSE CSS */
392
  *(__IO uint32_t *) CSR_LSECSSON_BB = (uint32_t)ENABLE;
380
  *(__IO uint32_t *) CSR_LSECSSON_BB = (uint32_t)ENABLE;
393
 
381
 
394
  /* Enable LSE CSS IT */
382
  /* Enable LSE CSS IT */
395
  __HAL_RCC_ENABLE_IT(RCC_IT_LSECSS);
383
  __HAL_RCC_ENABLE_IT(RCC_IT_LSECSS);
396
 
384
 
397
  /* Enable IT on EXTI Line 19 */
385
  /* Enable IT on EXTI Line 19 */
398
  __HAL_RCC_LSECSS_EXTI_ENABLE_IT();
386
  __HAL_RCC_LSECSS_EXTI_ENABLE_IT();
399
  __HAL_RCC_LSECSS_EXTI_ENABLE_RISING_EDGE();
387
  __HAL_RCC_LSECSS_EXTI_ENABLE_RISING_EDGE();
400
}
388
}
401
 
389
 
Line 412... Line 400...
412
    HAL_RCCEx_LSECSS_Callback();
400
    HAL_RCCEx_LSECSS_Callback();
413
 
401
 
414
    /* Clear RCC LSE CSS pending bit */
402
    /* Clear RCC LSE CSS pending bit */
415
    __HAL_RCC_CLEAR_IT(RCC_IT_LSECSS);
403
    __HAL_RCC_CLEAR_IT(RCC_IT_LSECSS);
416
  }
404
  }
417
}                                                                            
-
 
-
 
405
}
418
 
406
 
419
/**
407
/**
420
  * @brief  RCCEx LSE Clock Security System interrupt callback.
408
  * @brief  RCCEx LSE Clock Security System interrupt callback.
421
  * @retval none
409
  * @retval none
422
  */
410
  */
Line 425... Line 413...
425
  /* NOTE : This function should not be modified, when the callback is needed,
413
  /* NOTE : This function should not be modified, when the callback is needed,
426
            the @ref HAL_RCCEx_LSECSS_Callback should be implemented in the user file
414
            the @ref HAL_RCCEx_LSECSS_Callback should be implemented in the user file
427
   */
415
   */
428
}
416
}
429
#endif /* RCC_LSECSS_SUPPORT */
417
#endif /* RCC_LSECSS_SUPPORT */
430
 
418
 
431
/**
419
/**
432
  * @}
420
  * @}
433
  */
421
  */
434
 
422
 
435
/**
423
/**