OTP write operation fails when using flash_programmer, jtag_programmer and secondary bootloader generated from SDK 6.0.24
ID: LPCBARESDK-1152
Status: Open
First reported: 6.0.24.1464
Fixed in: TBD
Affected devices
All DA1453x devices.
Note: This issue also affects the Secondary Bootloader, as it uses the same OTP write utility.
Description
The failure is caused by the initialization of the result variable inside otp_utils_write_data().
bool otp_utils_write_data(uint32_t otp_address, uint8_t *data, uint32_t len)
{
uint32_t otp_addr_offset = otp_address - MEMORY_OTP_BASE;
uint32_t word2write[HW_OTP_CELL_SIZE / 4];
volatile size_t i;
bool result = false;
for (i = 0; i < len; i += HW_OTP_CELL_SIZE)
{
memcpy(word2write, data + i, sizeof(word2write));
/*
* OTP cell must be powered on, so we turn on the related clock.
* However, the OTP LDO will not be able to sustain an infinite
* amount of writes. So we keep our writes limited. Turning off the
* LDO at the end of the operation ensures that we restart the
* operation appropriately for the next write.
*/
hw_otpc_init();
#if defined (__DA14531__)
if (word2write[0] != 0xffffffff)
{
result = hw_otpc_prog_and_verify((word2write), otp_addr_offset >> 2, 1);
}
#else
/*
* From the manual: The destination address is a word aligned address, that represents the OTP memory
* address. It is not an AHB bus address. The lower allowed value is 0x0000 and the maximum allowed
* value is 0x1FFF (8K words space).
*/
result = hw_otpc_fifo_prog((const uint32_t *) (&word2write),
otp_addr_offset >> 3,
HW_OTPC_WORD_LOW, 2, false);
#endif
hw_otpc_disable();
otp_addr_offset += HW_OTP_CELL_SIZE;
if (!result)
break;
}
return result;
}
On DA1453x, programming is skipped when the target cell contains 0xFFFFFFFF (interpreted as empty). In this case, the if block is not executed and result is never updated. Since it is initialized to false, the function treats the operation as a failure and exits.
Workaround
Initialize result to true:
bool result = true;