From 93702b7ef188bd8c2c0083453cf510a62c1f752a Mon Sep 17 00:00:00 2001 From: cfif Date: Mon, 15 Jun 2026 18:59:29 +0300 Subject: [PATCH] Commit --- Inc/fc7xxx_driver_fmc.h | 2 ++ Src/fc7xxx_driver_fmc.c | 40 +++++++++++++++++++++++++++++++++++++--- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/Inc/fc7xxx_driver_fmc.h b/Inc/fc7xxx_driver_fmc.h index c5f6c89..bff2c09 100644 --- a/Inc/fc7xxx_driver_fmc.h +++ b/Inc/fc7xxx_driver_fmc.h @@ -178,6 +178,8 @@ FMC_Lock_StatusType FMCDRIVER_FlashLock(FMC_DRIVER_Lock_ParamType *pFmcParam); */ void FMCDRIVER_SwapBlock(const FMC_InstanceType eInstance, FMC_API_ACTIVE_BLOCK_TYPE bActive); +FMC_API_ACTIVE_BLOCK_TYPE FMCDRIVER_GetActiveBlock(const FMC_InstanceType eInstance); + #if defined(__cplusplus) } #endif diff --git a/Src/fc7xxx_driver_fmc.c b/Src/fc7xxx_driver_fmc.c index abb4d1f..4971014 100644 --- a/Src/fc7xxx_driver_fmc.c +++ b/Src/fc7xxx_driver_fmc.c @@ -188,10 +188,44 @@ FMC_Lock_StatusType FMCDRIVER_FlashLock(FMC_DRIVER_Lock_ParamType *pFmcParam) void FMCDRIVER_SwapBlock(const FMC_InstanceType eInstance, FMC_API_ACTIVE_BLOCK_TYPE bActive) { FMC_Type *const pFMC = s_apFmcBase[eInstance]; - if (0U == FMC_HWA_GetOTACtrlValue(pFMC, 0)) - { +// if (0U == FMC_HWA_GetOTACtrlValue(pFMC, 0)) +// { FMC_HWA_SetOTAActive(pFMC, 0, bActive); FMC_HWA_SetOTAEnable(pFMC, 0); - } +// } } +/** + * \brief Get current active OTA block + * + * \param eInstance FMC instance + * \return Current active block (FMC_Active0 or FMC_Active1) + * Returns FMC_Active0 by default if OTA is not enabled or error + */ +FMC_API_ACTIVE_BLOCK_TYPE FMCDRIVER_GetActiveBlock(const FMC_InstanceType eInstance) +{ + FMC_Type *const pFMC = s_apFmcBase[eInstance]; + + // Validate instance + if ((eInstance >= FMC_INSTANCE_COUNT) || (pFMC == NULL)) + { + return FMC_Active0; + } + + // Read OTA_CTRL register + uint32_t u32OTACtrl = FMC_HWA_GetOTACtrlValue(pFMC, 0U); + + // Check if OTA is enabled (0xA = enabled) + uint32_t u32OTAEn = (u32OTACtrl & FMC_OTA_CTRL_OTA_EN_MASK) >> FMC_OTA_CTRL_OTA_EN_SHIFT; + + if (u32OTAEn != 0xA) + { + // OTA not enabled - no swapping configured, return default Bank 0 + return FMC_Active0; + } + + // OTA is enabled - read which bank is active + uint32_t u32Active = (u32OTACtrl & FMC_OTA_CTRL_OTA_ACTIVE_MASK) >> FMC_OTA_CTRL_OTA_ACTIVE_SHIFT; + + return (FMC_API_ACTIVE_BLOCK_TYPE)u32Active; +} \ No newline at end of file