Skip to content

Commit aafbbec

Browse files
committed
[L0] Update CMSIS Cortex M0+ System Source File
Signed-off-by: Frederic.Pillon <[email protected]>
1 parent bffa6dd commit aafbbec

File tree

1 file changed

+28
-34
lines changed

1 file changed

+28
-34
lines changed

system/STM32L0xx/system_stm32l0xx.c

+28-34
Original file line numberDiff line numberDiff line change
@@ -22,29 +22,13 @@
2222
******************************************************************************
2323
* @attention
2424
*
25-
* <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
25+
* <h2><center>&copy; Copyright(c) 2016 STMicroelectronics.
26+
* All rights reserved.</center></h2>
2627
*
27-
* Redistribution and use in source and binary forms, with or without modification,
28-
* are permitted provided that the following conditions are met:
29-
* 1. Redistributions of source code must retain the above copyright notice,
30-
* this list of conditions and the following disclaimer.
31-
* 2. Redistributions in binary form must reproduce the above copyright notice,
32-
* this list of conditions and the following disclaimer in the documentation
33-
* and/or other materials provided with the distribution.
34-
* 3. Neither the name of STMicroelectronics nor the names of its contributors
35-
* may be used to endorse or promote products derived from this software
36-
* without specific prior written permission.
37-
*
38-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
39-
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40-
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
41-
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
42-
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
43-
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
44-
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
45-
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
46-
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
47-
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28+
* This software component is licensed by ST under BSD 3-Clause license,
29+
* the "License"; You may not use this file except in compliance with the
30+
* License. You may obtain a copy of the License at:
31+
* opensource.org/licenses/BSD-3-Clause
4832
*
4933
******************************************************************************
5034
*/
@@ -68,7 +52,7 @@
6852
#endif /* HSE_VALUE */
6953

7054
#if !defined (MSI_VALUE)
71-
#define MSI_VALUE ((uint32_t)2000000U) /*!< Value of the Internal oscillator in Hz*/
55+
#define MSI_VALUE ((uint32_t)2097152U) /*!< Value of the Internal oscillator in Hz*/
7256
#endif /* MSI_VALUE */
7357

7458
#if !defined (HSI_VALUE)
@@ -98,7 +82,7 @@
9882
/* #define VECT_TAB_SRAM */
9983
#ifndef VECT_TAB_OFFSET
10084
#define VECT_TAB_OFFSET 0x00U /*!< Vector Table base offset field.
101-
This value must be a multiple of 0x200. */
85+
This value must be a multiple of 0x100. */
10286
#endif
10387
/******************************************************************************/
10488
/**
@@ -124,7 +108,7 @@
124108
is no need to call the 2 first functions listed above, since SystemCoreClock
125109
variable is updated automatically.
126110
*/
127-
uint32_t SystemCoreClock = 2000000U;
111+
uint32_t SystemCoreClock = 2097152U; /* 32.768 kHz * 2^6 */
128112
const uint8_t AHBPrescTable[16] = {0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 1U, 2U, 3U, 4U, 6U, 7U, 8U, 9U};
129113
const uint8_t APBPrescTable[8] = {0U, 0U, 0U, 0U, 1U, 2U, 3U, 4U};
130114
const uint8_t PLLMulTable[9] = {3U, 4U, 6U, 8U, 12U, 16U, 24U, 32U, 48U};
@@ -229,43 +213,53 @@ void SystemCoreClockUpdate (void)
229213
switch (tmp)
230214
{
231215
case 0x00U: /* MSI used as system clock */
232-
msirange = (RCC->ICSCR & RCC_ICSCR_MSIRANGE) >> 13U;
216+
msirange = (RCC->ICSCR & RCC_ICSCR_MSIRANGE) >> RCC_ICSCR_MSIRANGE_Pos;
233217
SystemCoreClock = (32768U * (1U << (msirange + 1U)));
234218
break;
235219
case 0x04U: /* HSI used as system clock */
220+
if ((RCC->CR & RCC_CR_HSIDIVF) != 0U)
221+
{
222+
SystemCoreClock = HSI_VALUE / 4U;
223+
}
224+
else
225+
{
236226
SystemCoreClock = HSI_VALUE;
227+
}
237228
break;
238229
case 0x08U: /* HSE used as system clock */
239230
SystemCoreClock = HSE_VALUE;
240231
break;
241-
case 0x0CU: /* PLL used as system clock */
232+
default: /* PLL used as system clock */
242233
/* Get PLL clock source and multiplication factor ----------------------*/
243234
pllmul = RCC->CFGR & RCC_CFGR_PLLMUL;
244235
plldiv = RCC->CFGR & RCC_CFGR_PLLDIV;
245-
pllmul = PLLMulTable[(pllmul >> 18U)];
246-
plldiv = (plldiv >> 22U) + 1U;
236+
pllmul = PLLMulTable[(pllmul >> RCC_CFGR_PLLMUL_Pos)];
237+
plldiv = (plldiv >> RCC_CFGR_PLLDIV_Pos) + 1U;
247238

248239
pllsource = RCC->CFGR & RCC_CFGR_PLLSRC;
249240

250241
if (pllsource == 0x00U)
251242
{
252243
/* HSI oscillator clock selected as PLL clock entry */
244+
if ((RCC->CR & RCC_CR_HSIDIVF) != 0U)
245+
{
246+
SystemCoreClock = (((HSI_VALUE / 4U) * pllmul) / plldiv);
247+
}
248+
else
249+
{
253250
SystemCoreClock = (((HSI_VALUE) * pllmul) / plldiv);
254251
}
252+
}
255253
else
256254
{
257255
/* HSE selected as PLL clock entry */
258256
SystemCoreClock = (((HSE_VALUE) * pllmul) / plldiv);
259257
}
260258
break;
261-
default: /* MSI used as system clock */
262-
msirange = (RCC->ICSCR & RCC_ICSCR_MSIRANGE) >> 13U;
263-
SystemCoreClock = (32768U * (1U << (msirange + 1U)));
264-
break;
265259
}
266260
/* Compute HCLK clock frequency --------------------------------------------*/
267261
/* Get HCLK prescaler */
268-
tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4U)];
262+
tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> RCC_CFGR_HPRE_Pos)];
269263
/* HCLK clock frequency */
270264
SystemCoreClock >>= tmp;
271265
}

0 commit comments

Comments
 (0)