1 /*
2  * Copyright (c) 2019 Linaro Ltd.
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 /**
8  * @file
9  * @brief System/hardware module for STM32L1 processor
10  */
11 
12 #include <zephyr/device.h>
13 #include <zephyr/init.h>
14 #include <zephyr/linker/linker-defs.h>
15 #include <string.h>
16 #include <stm32_ll_bus.h>
17 #include <stm32_ll_pwr.h>
18 
19 #include <cmsis_core.h>
20 
21 /**
22  * @brief Perform basic hardware initialization at boot.
23  *
24  * This needs to be run from the very beginning.
25  * So the init priority has to be 0 (zero).
26  *
27  * @return 0
28  */
stm32l1_init(void)29 static int stm32l1_init(void)
30 {
31 	/* Update CMSIS SystemCoreClock variable (HCLK) */
32 	/* At reset, system core clock is set to 2.1 MHz from MSI */
33 	SystemCoreClock = 2097000;
34 
35 	/* Default Voltage scaling range selection (range2)
36 	 * doesn't allow to configure Max frequency
37 	 * switch to range1 to match any frequency
38 	 */
39 	LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_PWR);
40 	LL_PWR_SetRegulVoltageScaling(LL_PWR_REGU_VOLTAGE_SCALE1);
41 
42 	return 0;
43 }
44 
45 SYS_INIT(stm32l1_init, PRE_KERNEL_1, 0);
46