cancel
Showing results for 
Search instead for 
Did you mean: 

NUCLEO-G071RB flash unlock hardfault

dmrsim
Associate III

Hello,

I'm new in ARM programming, I'm trying to study how CHIP work using the documentation.
I wanna unlock the flash memory and according with documentation:

1. Write KEY1 = 0x4567 0123 in the FLASH key register (FLASH_KEYR)
2. Write KEY2 = 0xCDEF 89AB in the FLASH key register (FLASH_KEYR).
Any wrong sequence locks the FLASH_CR registers until the next system reset. In the case
of a wrong key sequence, a bus error is detected and a Hard Fault interrupt is generated.

 

I write this simple code:

void unlock_flash()
{
   FLASH_TypeDef *flash;
   flash->KEYR = 0x45670123;
   flash->KEYR = 0xCDEF89AB;
}
But after registre write I have an HARDFAULT...
Please could you help me?

Thanks a lot!

4 REPLIES 4
FBL
ST Employee

Hello @dmrsim 

In case of an unsuccessful unlock operation, this Lock bit in FLASH_CR remains set until the next system reset. You may need to read this bit before authorizing the access and after that you can wait to check if flash unlock is complete.

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.


I'm out of offce with limited access to my emails.
Happy New Year!
dmrsim
Associate III

Hello, 

thanks for your reply.

Before unlock I have tried also in debug mode, to read flash->CR bit, but also this read cause HardFault(I cannot read Flash registers using my code)....

Could you help me?

dmrsim
Associate III

Really sorry, my big mistake...I forgot to init: FLASH_TypeDef *flash = FLASH;

FBL
ST Employee

Hi @dmrsim 

You may check the faults view to see why it is triggered. We don't have all the inputs needed to help further. You can check clocks in RCC register view, or you can simply see the implementation of our HAL driver.

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.


I'm out of offce with limited access to my emails.
Happy New Year!