This commit is contained in:
cfif 2026-06-15 18:59:29 +03:00
parent 469f59aa33
commit 93702b7ef1
2 changed files with 39 additions and 3 deletions

View File

@ -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); 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) #if defined(__cplusplus)
} }
#endif #endif

View File

@ -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) void FMCDRIVER_SwapBlock(const FMC_InstanceType eInstance, FMC_API_ACTIVE_BLOCK_TYPE bActive)
{ {
FMC_Type *const pFMC = s_apFmcBase[eInstance]; 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_SetOTAActive(pFMC, 0, bActive);
FMC_HWA_SetOTAEnable(pFMC, 0); 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;
}