我写了一些代码试图读回 CMPA,然后更改它的 bootcfg,然后再写回。但是,它变砖了。现在芯片不响应 DAP,USB ISP 不工作。
程序代码:
#include "flash.h"
#include "fsl_iap.h"
#include "fsl_iap_ffr.h"
#define FLASH_BL3_START_ADDR 0x10008000
#define FLASH_BL3_SIZE 0x18000
sta
tic 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
", status);
}
if ((status=FFR_Init(&ffr_instance)) != kStatus_Success)
{
printf("FFR init failed,Error Code:%lu
",status);
}
//read cfpa to sram
if ((status=flash_read_cfpa()) != kStatus_Success)
{
printf("CFPA cannot read,Error Code:%lu
", status);
}
if ((status=flash_read_cmpa()) != kStatus_Success)
{
printf("CMPA cannot read,Error Code:%lu
", status);
}
if (cmpa_data.bootCfg != 0x88000300)
{
printf("CMPA Bootcfg not match,program it
");
cmpa_data.bootCfg = 0x88000300;
if ((status = flash_program_CMPA()) != kStatus_Success)
{
printf("CMPA cannot write,Error Code:%lu
", status);
}
}
printf("Secure FW Min Version:%lu, Non-Secure FW Min Version:%lu
",
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);
}
我可以读回 CMPA 和 CFPA,这些结构中的所有零,然后我添加代码来编程 CMPA,芯片砖。我希望芯片能够使用 USBFS 启动到 ISP。
我用 MCUXpresso 安全配置检查了设置,我不认为我设置了错误的启动 cfg