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 <device.h> 13 #include <init.h> 14 #include <arch/cpu.h> 15 #include <arch/arm/aarch32/cortex_m/cmsis.h> 16 #include <linker/linker-defs.h> 17 #include <string.h> 18 #include <stm32_ll_bus.h> 19 #include <stm32_ll_pwr.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(const struct device * arg)29static int stm32l1_init(const struct device *arg) 30 { 31 uint32_t key; 32 33 ARG_UNUSED(arg); 34 35 key = irq_lock(); 36 37 /* Install default handler that simply resets the CPU 38 * if configured in the kernel, NOP otherwise 39 */ 40 NMI_INIT(); 41 42 irq_unlock(key); 43 44 /* Update CMSIS SystemCoreClock variable (HCLK) */ 45 /* At reset, system core clock is set to 2.1 MHz from MSI */ 46 SystemCoreClock = 2097000; 47 48 /* Default Voltage scaling range selection (range2) 49 * doesn't allow to configure Max frequency 50 * switch to range1 to match any frequency 51 */ 52 LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_PWR); 53 LL_PWR_SetRegulVoltageScaling(LL_PWR_REGU_VOLTAGE_SCALE1); 54 55 return 0; 56 } 57 58 SYS_INIT(stm32l1_init, PRE_KERNEL_1, 0); 59