I wrote some codes to try to read back CMPA, then change its bootcfg, then write it back. However, it bricks chip. Now chip does not responds to DAP and USB ISP is not working.
Program codes:
#include "flash.h"
#include "fsl_iap.h"
#include "fsl_iap_ffr.h"
#define FLASH_BL3_START_ADDR 0x10008000
#define FLASH_BL3_SIZE 0x18000
static flash_config_t flashInstance;
static flash_config_t ffr_instance;
static cfpa_cfg_info_t cfpa_data;
static cmpa_cfg_info_t cmpa_data;
void flash_init(void)
{
status_t status;
if ((status=FLASH_Init(&flashInstance) )!= kStatus_Success)
{
printf("Flash init failed,Error Code:%lu\r\n", status);
}
if ((status=FFR_Init(&ffr_instance)) != kStatus_Success)
{
printf("FFR init failed,Error Code:%lu\r\n",status);
}
//read cfpa to sram
if ((status=flash_read_cfpa()) != kStatus_Success)
{
printf("CFPA cannot read,Error Code:%lu\r\n", status);
}
if ((status=flash_read_cmpa()) != kStatus_Success)
{
printf("CMPA cannot read,Error Code:%lu\r\n", status);
}
if (cmpa_data.bootCfg != 0x88000300)
{
printf("CMPA Bootcfg not match,program it\r\n");
cmpa_data.bootCfg = 0x88000300;
if ((status = flash_program_CMPA()) != kStatus_Success)
{
printf("CMPA cannot write,Error Code:%lu\r\n", status);
}
}
printf("Secure FW Min Version:%lu, Non-Secure FW Min Version:%lu\r\n",
cfpa_data.secureFwVersion,
cfpa_data.nsFwVersion);
}
status_t flash_erase_BL3(void)
{
return FLASH_Erase(&flashInstance, FLASH_BL3_START_ADDR, FLASH_BL3_SIZE, kFLASH_ApiEraseKey);
}
status_t flash_verify_erase(void)
{
return FLASH_VerifyErase(&flashInstance, FLASH_BL3_START_ADDR, FLASH_BL3_SIZE);
}
status_t flash_program(uint32_t flash_addr, void *pData, uint32_t len)
{
return FLASH_Program(&flashInstance, flash_addr, pData, len);
}
status_t flash_read_cfpa(void)
{
return FFR_GetCustomerInfieldData(&ffr_instance, (uint8_t*)&cfpa_data, 0, sizeof(cfpa_data));
}
status_t flash_read_cmpa(void)
{
return FFR_GetCustomerData(&ffr_instance, (uint8_t*)&cmpa_data, 0, sizeof(cmpa_data));
}
status_t flash_program_CMPA(void)
{
return FFR_CustFactoryPageWrite(&ffr_instance, (uint8_t *)&cmpa_data, false);
}
I could read back both CMPA and CFPA, all zeros inside these structures, then I added codes to program CMPA, the chip bricks. I want the chip be able to boot to ISP with USBFS.
I checked the settings with MCUXpresso secure provisioning, I don't think I setup the wrong boot cfg
