1 /* 2 * Copyright (c) 2024 STMicroelectronics 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 /** 8 * @file 9 * @brief System/hardware module for STM32H7RS CM7 processor 10 */ 11 12 #include <zephyr/kernel.h> 13 #include <zephyr/device.h> 14 #include <zephyr/init.h> 15 #include <zephyr/cache.h> 16 #include <soc.h> 17 #include <stm32_ll_bus.h> 18 #include <stm32_ll_pwr.h> 19 #include <stm32_ll_rcc.h> 20 21 #include <cmsis_core.h> 22 23 24 /** 25 * @brief Perform basic hardware initialization at boot. 26 * 27 * This needs to be run from the very beginning. 28 */ soc_early_init_hook(void)29void soc_early_init_hook(void) 30 { 31 sys_cache_instr_enable(); 32 sys_cache_data_enable(); 33 34 /* Update CMSIS SystemCoreClock variable (HCLK) */ 35 /* At reset, system core clock is set to 64 MHz from HSI */ 36 SystemCoreClock = 64000000; 37 38 /* Power Configuration */ 39 #if !defined(SMPS) && \ 40 (defined(CONFIG_POWER_SUPPLY_DIRECT_SMPS) || \ 41 defined(CONFIG_POWER_SUPPLY_SMPS_1V8_SUPPLIES_LDO) || \ 42 defined(CONFIG_POWER_SUPPLY_SMPS_2V5_SUPPLIES_LDO) || \ 43 defined(CONFIG_POWER_SUPPLY_SMPS_1V8_SUPPLIES_EXT_AND_LDO) || \ 44 defined(CONFIG_POWER_SUPPLY_SMPS_2V5_SUPPLIES_EXT_AND_LDO) || \ 45 defined(CONFIG_POWER_SUPPLY_SMPS_1V8_SUPPLIES_EXT) || \ 46 defined(CONFIG_POWER_SUPPLY_SMPS_2V5_SUPPLIES_EXT)) 47 #error Unsupported configuration: Selected SoC do not support SMPS 48 #endif 49 #if defined(CONFIG_POWER_SUPPLY_DIRECT_SMPS) 50 LL_PWR_ConfigSupply(LL_PWR_DIRECT_SMPS_SUPPLY); 51 #elif defined(CONFIG_POWER_SUPPLY_SMPS_1V8_SUPPLIES_LDO) 52 LL_PWR_ConfigSupply(LL_PWR_SMPS_1V8_SUPPLIES_LDO); 53 #elif defined(CONFIG_POWER_SUPPLY_SMPS_2V5_SUPPLIES_LDO) 54 LL_PWR_ConfigSupply(LL_PWR_SMPS_2V5_SUPPLIES_LDO); 55 #elif defined(CONFIG_POWER_SUPPLY_SMPS_1V8_SUPPLIES_EXT_AND_LDO) 56 LL_PWR_ConfigSupply(LL_PWR_SMPS_1V8_SUPPLIES_EXT_AND_LDO); 57 #elif defined(CONFIG_POWER_SUPPLY_SMPS_2V5_SUPPLIES_EXT_AND_LDO) 58 LL_PWR_ConfigSupply(LL_PWR_SMPS_2V5_SUPPLIES_EXT_AND_LDO); 59 #elif defined(CONFIG_POWER_SUPPLY_SMPS_1V8_SUPPLIES_EXT) 60 LL_PWR_ConfigSupply(LL_PWR_SMPS_1V8_SUPPLIES_EXT); 61 #elif defined(CONFIG_POWER_SUPPLY_SMPS_2V5_SUPPLIES_EXT) 62 LL_PWR_ConfigSupply(LL_PWR_SMPS_2V5_SUPPLIES_EXT); 63 #elif defined(CONFIG_POWER_SUPPLY_EXTERNAL_SOURCE) 64 LL_PWR_ConfigSupply(LL_PWR_EXTERNAL_SOURCE_SUPPLY); 65 #else 66 LL_PWR_ConfigSupply(LL_PWR_LDO_SUPPLY); 67 #endif 68 LL_PWR_SetRegulVoltageScaling(LL_PWR_REGU_VOLTAGE_SCALE1); 69 while (LL_PWR_IsActiveFlag_VOSRDY() == 0) { 70 } 71 72 #if DT_NODE_HAS_STATUS(DT_NODELABEL(gpioo), okay) || DT_NODE_HAS_STATUS(DT_NODELABEL(gpiop), okay) 73 LL_PWR_EnableXSPIM1(); /* Required for powering GPIO O and P */ 74 #endif /* gpioo || gpio p */ 75 #if DT_NODE_HAS_STATUS(DT_NODELABEL(gpion), okay) 76 LL_PWR_EnableXSPIM2(); /* Required for powering GPIO N */ 77 #endif /* gpio n */ 78 #if DT_NODE_HAS_STATUS(DT_NODELABEL(gpiom), okay) 79 LL_PWR_EnableUSBVoltageDetector(); /* Required for powering GPIO M */ 80 #endif /* gpiom */ 81 } 82