Yes, it is standard way to use Hse_Ip driver for this. But the driver is not prepared to relocate necessary code to RAM or to another flash block, so it must be done manually. And it’s not only HSE_IP_ServiceRequest function. Be aware that this function calls some other functions.
This is the critical part of code inside the function when using synchronous mode:
if (HSE_IP_REQTYPE_SYNC == pRequest->eReqType)
{
/* Convert from microseconds to ticks */
u32TimeoutTicks = OsIf_MicrosToTicks(pRequest->u32Timeout, (OsIf_CounterType)HSE_IP_TIMEOUT_OSIF_COUNTER_TYPE);
/* Send the service request to HSE */
Mu_Ip_SetTxRegister(Hse_Ip_apMuBase[u8MuInstance], u8MuChannel, (uint32)pHseSrvDesc);
/* Read the current value of the counter */
u32CurrentTicks = OsIf_GetCounter((OsIf_CounterType)HSE_IP_TIMEOUT_OSIF_COUNTER_TYPE);
/* Wait for the HSE response */
while ((FALSE == Mu_Ip_IsResponseReady(Hse_Ip_apMuBase[u8MuInstance], u8MuChannel)) && (u32ElapsedTicks < u32TimeoutTicks))
{
/* Update the elapsed ticks, current ticks will be updated too by the OsIf function */
u32ElapsedTicks += OsIf_GetElapsed(&u32CurrentTicks, (OsIf_CounterType)HSE_IP_TIMEOUT_OSIF_COUNTER_TYPE);
}
The Mu_Ip… functions are inlined, so there’s no problem. But OsIf functions from BaseNXP module are not inlined, so you need to move them to RAM too. I recommend to step the function to see that all the code executed in this area is running from RAM. Or you can check the map file as well.
I will create a feature request to implement some support for code relocation to future versions of the driver because I can see this is causing troubles.
When the UTEST is being programmed, nothing can access flash block 0. So, it’s necessary to keep the interrupts disabled. Otherwise you would have to move all used resources (vector table, handlers, functions and data used by handlers) to RAM or to another flash block. But because OTP attributes are usually programmed in factory in controlled environment, it should be more convenient to disable interrupts.
Synchronization: in configuration phase, it is good idea to launch one command at a time when programming OTP attributes. In this case, it’s sufficient to wait for completion of current service only. In more complex system, yes, it could be necessary to use also HSE GPR3 register.
In case of single flash block device, run the code from RAM.
Regards,
Lukas