From 4b050f47a65b26f429c6cfcce53a0284e3a97afd Mon Sep 17 00:00:00 2001 From: Yingjing Xu Date: Wed, 20 Dec 2023 16:33:15 +0800 Subject: [PATCH] Disable ICACHE before access flash regions where caching is not practical --- Src/stm32h5xx_hal_dac.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Src/stm32h5xx_hal_dac.c b/Src/stm32h5xx_hal_dac.c index 79388cd..2f9e429 100644 --- a/Src/stm32h5xx_hal_dac.c +++ b/Src/stm32h5xx_hal_dac.c @@ -1226,6 +1226,7 @@ HAL_StatusTypeDef HAL_DAC_ConfigChannel(DAC_HandleTypeDef *hdac, uint32_t tickstart; uint32_t hclkfreq; uint32_t connectOnChip; + uint32_t isIcacheEn; /* Check the DAC peripheral handle and channel configuration struct */ if ((hdac == NULL) || (sConfig == NULL)) @@ -1347,6 +1348,13 @@ HAL_StatusTypeDef HAL_DAC_ConfigChannel(DAC_HandleTypeDef *hdac, /* Configure for the selected DAC channel: mode, buffer output & on chip peripheral connect */ #if !defined(TIM8) + /* For flash regions where caching is not practical, ICACHE has to be disable before access them */ + isIcacheEn = HAL_ICACHE_IsEnabled(); + if (isIcacheEn != 0UL) + { + HAL_ICACHE_Disable(); + } + /* Devices STM32H503xx */ /* On STM32H503EB (package WLCSP25) DAC channel 1 connection to GPIO is not available and should not be configured. Package information is stored at the address PACKAGE_BASE, WLCSP25 correspond to the value 0xF (For more @@ -1368,6 +1376,12 @@ HAL_StatusTypeDef HAL_DAC_ConfigChannel(DAC_HandleTypeDef *hdac, SET_BIT(hdac->ErrorCode, HAL_DAC_ERROR_INVALID_CONFIG); } } + + /* Re-enable ICACHE if need */ + if (isIcacheEn != 0UL) + { + HAL_ICACHE_Enable(); + } #endif /* Devices STM32H503xx */