Bootloader Flash Erase Issue on FRDM-K64F (Flash Protection and Related Functions Not Working)

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Bootloader Flash Erase Issue on FRDM-K64F (Flash Protection and Related Functions Not Working)

671件の閲覧回数
Mert_Demirel
Contributor I

Hello,

I'm working on developing a bootloader for the FRDM-K64F board and encountered an issue. When trying to erase a specific area of flash memory starting from the APP_START_ADDRESS, we run into Flash Protection issues. The functions we have tried to disable this protection are failing.

When attempting to erase the flash memory, we receive a Flash Protection Violation error. Below, I've outlined the steps we're following. However, even though we are using functions like FLASH_PflashSetProtection and FLASH_SecurityBypass, we're unable to bypass the protection and erase the specified APP_START_ADDRESS.

void EraseFlashMemory(uint32_t startAddress, uint32_t eraseSize)

{

flash_status = FLASH_Init(&s_flashDriver);

if (flash_status != kStatus_FLASH_Success)

{

UART_Send("Flash initialization failed.\r\n");

return;

}

uint32_t protectStatus = 0x00000000;

flash_status = FLASH_PflashSetProtection(&s_flashDriver, protectStatus);

if (flash_status != kStatus_FLASH_Success)

{

UART_Send("Failed to remove flash protection.\r\n");

return;

}

flash_status = FLASH_Erase(&s_flashDriver, startAddress, eraseSize, kFTFx_ApiEraseKey);

if (flash_status == kStatus_FLASH_Success)

{

UART_Send("Flash erase successful.\r\n");

}

else

{

UART_Send("Flash erase failed.\r\n");

char error_msg[64];

sprintf(error_msg, "Error code: 0x%x\r\n", flash_status);

UART_Send(error_msg);

return;

}

I don't know what causes the flash protection I mentioned.

 

0 件の賞賛
返信
2 返答(返信)

606件の閲覧回数
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,

I suppose that you can use two methods to set the protection.

1)set the word3 as 0xFFFFFFFF, all the program flash will be unprotected.

 

xiangjun_rong_0-1727061232113.png

2)call the

status_t FLASH_PflashSetProtection(flash_config_t *config, pflash_prot_status_t *protectStatus)

 

The FRDM-K64 use MK64FN1M0VLL12, it has 1MB flash, ranging from 0x00000000 to 0x10_0000

so you can write the code as

uint32_t protectStatus;

FLASH_PflashGetProtection(&s_flashDriver, &protectStatus);

protectStatus|=1<<5; //unprotect 0x2_0000 address

FLASH_PflashSetProtection&s_flashDriver, &protectStatus);

 

I hope you use the first method.

Hope it can help you

BR

XiangJun Rong

 

0 件の賞賛
返信

667件の閲覧回数
Mert_Demirel
Contributor I
APP_START_ADDRESS=0x00020000
0 件の賞賛
返信