# Copyright (c) 2024 STMicroelectronics
# SPDX-License-Identifier: Apache-2.0

config SOC_FAMILY_STM32
	select HAS_SEGGER_RTT if ZEPHYR_SEGGER_MODULE
	select STM32_ENABLE_DEBUG_SLEEP_STOP if DEBUG || ZTEST
	select BUILD_OUTPUT_HEX

if SOC_FAMILY_STM32

rsource "*/Kconfig"

# STM32 wide symbols definitions

# Workaround for not being able to have commas in macro arguments
DT_CHOSEN_Z_CCM := zephyr,ccm

config STM32_CCM
	def_bool $(dt_chosen_enabled,$(DT_CHOSEN_Z_CCM))

config USE_STM32_ASSERT
	depends on ASSERT
	bool "STM32Cube HAL and LL drivers asserts"
	help
	  Enable asserts in STM32Cube HAL and LL drivers.

config STM32_BACKUP_SRAM
	bool "STM32 Backup SRAM"
	default y
	depends on DT_HAS_ST_STM32_BACKUP_SRAM_ENABLED
	help
	  Enable support for STM32 backup SRAM.

config STM32_BACKUP_SRAM_INIT_PRIORITY
	int "STM32 Backup SRAM init priority"
	default APPLICATION_INIT_PRIORITY
	depends on STM32_BACKUP_SRAM
	help
	  STM32 Backup SRAM device initialization priority.

config STM32_ENABLE_DEBUG_SLEEP_STOP
	bool "Allow debugger attach in stop/sleep Mode"
	help
	  Some STM32 parts disable the DBGMCU in sleep/stop modes because
	  of power consumption. As a side-effects this prevents
	  debuggers from attaching w/o resetting the target. This
	  effectively destroys the use-case of `west attach`. Also
	  SEGGER RTT and similar technologies need this.

config SWJ_ANALOG_PRIORITY
	int "SWJ DP port to analog routine initialization priority"
	default 49
	help
	  Initialization priority of the routine within the PRE_KERNEL1 level.
	  This priority must be greater than GPIO_INIT_PRIORITY and lower than
	  UART_INIT_PRIORITY.

config HAS_STM32_FLASH_PREFETCH
	bool
	help
	  Hidden symbol selected by SoCs which support flash prefetch.

config STM32_FLASH_PREFETCH
	bool "Flash prefetch buffer"
	default y
	depends on HAS_STM32_FLASH_PREFETCH
	help
	  Enable flash prefetch. For power efficiency, it is recommended to
	  be enabled when flash is accessed through a cache memory. Flash
	  prefetch also improves performances a bit.

config STM32_WKUP_PINS
	bool "STM32 PWR Wake-up Pins"
	depends on DT_HAS_ST_STM32_PWR_ENABLED
	help
	  Enable support for STM32 PWR wake-up pins.

choice POWER_SUPPLY_CHOICE
	prompt "STM32 power supply configuration"
	default POWER_SUPPLY_LDO
	depends on SOC_SERIES_STM32H7X || SOC_SERIES_STM32H7RSX || \
		SOC_SERIES_STM32U5X || SOC_STM32WBA55XX || SOC_STM32WBA65XX

config POWER_SUPPLY_LDO
	bool "LDO supply"

config POWER_SUPPLY_DIRECT_SMPS
	bool "Direct SMPS supply"

config POWER_SUPPLY_SMPS_1V8_SUPPLIES_LDO
	bool "SMPS 1.8V supplies LDO (no external supply)"
	depends on SOC_SERIES_STM32H7X || SOC_SERIES_STM32H7RSX

config POWER_SUPPLY_SMPS_2V5_SUPPLIES_LDO
	bool "SMPS 2.5V supplies LDO (no external supply)"
	depends on SOC_SERIES_STM32H7X || SOC_SERIES_STM32H7RSX

config POWER_SUPPLY_SMPS_1V8_SUPPLIES_EXT_AND_LDO
	bool "External SMPS 1.8V supply, supplies LDO"
	depends on SOC_SERIES_STM32H7X || SOC_SERIES_STM32H7RSX

config POWER_SUPPLY_SMPS_2V5_SUPPLIES_EXT_AND_LDO
	bool "External SMPS 2.5V supply, supplies LDO"
	depends on SOC_SERIES_STM32H7X || SOC_SERIES_STM32H7RSX

config POWER_SUPPLY_SMPS_1V8_SUPPLIES_EXT
	bool "External SMPS 1.8V supply and bypass"
	depends on SOC_SERIES_STM32H7X || SOC_SERIES_STM32H7RSX

config POWER_SUPPLY_SMPS_2V5_SUPPLIES_EXT
	bool "External SMPS 2.5V supply and bypass"
	depends on SOC_SERIES_STM32H7X || SOC_SERIES_STM32H7RSX

config POWER_SUPPLY_EXTERNAL_SOURCE
	bool "Bypass"
	depends on SOC_SERIES_STM32H7X || SOC_SERIES_STM32H7RSX

endchoice

config STM32_BACKUP_PROTECTION
	bool "SoC has backup domain protection access"
	help
	  Enabled for SoCs for which access protection to backup domain
	  resources needs to be explicitly handled.

config STM32_APP_IN_EXT_FLASH
	bool
	help
	  Allows the SoC clock driver to correctly initialize the
	  Q/O/XSPI controller clocks when the application is residing
	  in external Flash and is chainloaded with MCUboot.
	  Whether the app is eXecuted in Place (XiP) depends on the MCUboot mode used.

endif # SOC_FAMILY_STM32
