1 /*
2  * Copyright (c) 2018 qianfan Zhao <qianfanguijin@163.com>
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 /**
8  * @file
9  * @brief System/hardware module for stm32f2 processor
10  */
11 
12 #include <kernel.h>
13 #include <device.h>
14 #include <init.h>
15 #include <soc.h>
16 #include <arch/cpu.h>
17 #include <arch/arm/aarch32/cortex_m/cmsis.h>
18 #include <stm32_ll_system.h>
19 #include <linker/linker-defs.h>
20 #include <string.h>
21 
22 /**
23  * @brief Perform basic hardware initialization at boot.
24  *
25  * This needs to be run from the very beginning.
26  * So the init priority has to be 0 (zero).
27  *
28  * @return 0
29  */
stm32f2_init(const struct device * arg)30 static int stm32f2_init(const struct device *arg)
31 {
32 	uint32_t key;
33 
34 	ARG_UNUSED(arg);
35 
36 	/* Enable ART Flash cache accelerator for both Instruction and Data */
37 	LL_FLASH_EnableInstCache();
38 	LL_FLASH_EnableDataCache();
39 
40 	key = irq_lock();
41 
42 	/* Install default handler that simply resets the CPU
43 	 * if configured in the kernel, NOP otherwise
44 	 */
45 	NMI_INIT();
46 
47 	irq_unlock(key);
48 
49 	/* Update CMSIS SystemCoreClock variable (HCLK) */
50 	/* At reset, system core clock is set to 16 MHz from HSI */
51 	SystemCoreClock = 16000000;
52 
53 	return 0;
54 }
55 
56 SYS_INIT(stm32f2_init, PRE_KERNEL_1, 0);
57