Hi,
I'm trying to write a byte in UTEST sector in this block:

NB: API is called at init with interrupts disabled.
This is my code:
HostFlash_Program((uint32_t )0x1B000780U, (uint8_t* )hseFwFeatureFlagEnabledValue, (uint32_t)8U);
eel_status_t HostFlash_Program( uint32_t Address, uint8_t* SourceAddress, uint32_t Length)
{
uint32_t ErrorFlags;
C40_Ip_StatusType C40_Ip_Status = STATUS_C40_IP_ERROR ;
const uint8_t *DataPtr8 = SourceAddress;
volatile uint32_t DataTemp32; /* Prevent compiler optimization when working with unaligned addresses */
/* Disable HV to finalize/abort the operation */
Fsld_FlashInstance->MCR &= ~FLASH_MCR_EHV_MASK;
/*Clear ERS and PGM bits */
Fsld_FlashInstance->MCR &= ~(FLASH_MCR_PGM_MASK|FLASH_MCR_ESS_MASK|FLASH_MCR_ERS_MASK);
/* Disable watchdog interrupt */
Fsld_FlashInstance->MCR &= ~FLASH_MCR_WDIE_MASK;
/* No interrupt request will be generated when the DONE flag is set */
Fsld_FlashInstance->MCR &= ~FLASH_MCR_PECIE_MASK;
/* Clear all error flags for main interface */
Fsld_FlashInstance->MCRS &= FLASH_MCRS_EER_MASK | \
FLASH_MCRS_SBC_MASK | \
FLASH_MCRS_AEE_MASK | \
FLASH_MCRS_EEE_MASK | \
FLASH_MCRS_RVE_MASK | \
FLASH_MCRS_RRE_MASK | \
FLASH_MCRS_RWE_MASK | \
FLASH_MCRS_PES_MASK | \
FLASH_MCRS_PEP_MASK;
/* Sector is in Utest */
Fsld_PFlashInstance->PFCBLKU_SPELOCK[0u] &= FSLD_MASK_UNLOCK_UTEST_SECTOR;
/* Write the address to be programmed */
Fsld_PFlashInstance->PFCPGM_PEADR_L = Address;
DataTemp32 = (uint32_t)DataPtr8[0U] << 0U;
DataTemp32 |= (uint32_t)DataPtr8[1U] << 8U;
DataTemp32 |= (uint32_t)DataPtr8[2U] << 16U;
DataTemp32 |= (uint32_t)DataPtr8[3U] << 24U;
Fsld_FlashInstance->DATA[0U] = DataTemp32;
DataTemp32 = (uint32_t)DataPtr8[4U] << 0U;
DataTemp32 |= (uint32_t)DataPtr8[5U] << 8U;
DataTemp32 |= (uint32_t)DataPtr8[6U] << 16U;
DataTemp32 |= (uint32_t)DataPtr8[7U] << 24U;
Fsld_FlashInstance->DATA[1U] = DataTemp32;
/* Setup program operation */
Fsld_FlashInstance->MCR |= FLASH_MCR_PGM_MASK;
/* Start internal erase/program sequence */
Fsld_FlashInstance->MCR |= FLASH_MCR_EHV_MASK;
while (0U == ((Fsld_FlashInstance->MCRS & FLASH_MCRS_DONE_MASK) >> FLASH_MCRS_DONE_SHIFT))
{
}
ErrorFlags = Fsld_FlashInstance->MCRS & (FLASH_MCRS_PEG_MASK | FLASH_MCRS_PEP_MASK | FLASH_MCRS_PES_MASK);
/* Program/Erase Good: only PEG = 1; both PEP and PES should be 0 */
if (FLASH_MCRS_PEG_MASK == ErrorFlags)
{
C40_Ip_Status = STATUS_C40_IP_SUCCESS;
}
else
{
C40_Ip_Status = STATUS_C40_IP_ERROR;
}
/* terminate program operation */
Fsld_FlashInstance->MCR &= ~FLASH_MCR_EHV_MASK;
/* Terminate program operation */
Fsld_FlashInstance->MCR &= ~FLASH_MCR_PGM_MASK;
/* The write job has finished or the end of the sector was reached. Time to lock the sector */
Fsld_PFlashInstance->PFCBLKU_SPELOCK[0u] |= FSLD_MASK_LOCK_UTEST_SECTOR;
if( STATUS_C40_IP_SUCCESS == C40_Ip_Status )
{
return EEL_OK ;
}
else
{
return EEL_ERR_PARAMETER ;
}
}
If I don't place the function in RAM, it writes the byte but, just after the write uC generates a hard fault

#case 2
If I place the function in RAM, no hard fault occurs, but write operation fails. Byte is not written in UTEST sector.

Can you help me?
Thanks a lot.