cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F030 Erase internal flash page

HamidRezaMaddah
Associate III

Dear,

I made a project for STM32F030RC with STM32CubeIDE. when I use "HAL_FLASHEx_Erase" function to erase some flash pages (at end of flash that there is no code on it) , the CPU crash.

I guessed it is depended on interrupts. so I disabled interrupts with  __disable_irq before erase and enable with __enable_irq after erase. Then the erase done but after I enable interrupts, the CPU crash.

I tested the __disable_irq and __enable_irq in other place of code in main loop. I saw that some times CPU crash after enable interrupts.

Do you have any idea?

Best regards

Hamid

7 REPLIES 7
Ozone
Lead

Specifying "the CPU crash" in more detail would be helpful. Does it end up in the hardfault handler ?

Without looking it up, I believe the F030 has just one bank, the code execution stalls while the erase is ongoing.

Are there peripherals that might resent such long breaks (watchdog, timer, ext. communication lines) ?

What do the SCB registers say ?

HamidRezaMaddah
Associate III

It does not end up in hardfault handler. I can not find why crashed the CPU. I have no debug pin in my board.

That is right, the code execution stalls while the erase is ongoing.

I don't have long break in peripheral interrupts.

How can I read SCB registers?

thanks for your response

mattias norlander
ST Employee

So you do not have any SWD or JTAG interface available to the MCU?

How do you interact with the system? UART? Can you print information to the terminal?

Maybe the most simple thing would be to define individual handler functions for the NMI_Handler() and HardFault_Handler() and toggle a LED in these, if possible?!

> How can I read SCB registers?

With a debugger.

Helpful in case of hardfaults, which seem not to apply in your case.

> I tested the __disable_irq and __enable_irq in other place of code in main loop. I saw that some times CPU crash after enable interrupts.

Have you tried to single-step through this sequence, on assembler instruction level ?

It would be helpful to post the core register contents immediately before the problem/crash happens.

I don't have any connector on board to use SWD and JTAG.

I Have UART to Print

I turn on a LED in NMI_Handler() and HardFault_Handler() . but the LED never turned on

Thanks

> I don't have any connector on board to use SWD and JTAG.

> I Have UART to Print

You make your life unnecessary difficult.

UART/printf requires much more to work properly, JTAG relies on separate, additional hardware on the MCU chip, and is thus mainly independant of the core.

> I turn on a LED in NMI_Handler() and HardFault_Handler() . but the LED never turned on

If the core is hardfaulting in the hardfault handler, it is going into lockup (requiring a power cycle).

You options are quite limited currently.

> If the core is hardfaulting in the hardfault handler, it is going into lockup (requiring a power cycle).

> You options are quite limited currently.

Sorry, I don't understand " it is going into lockup (requiring a power cycle)"

What should I to do?

thanks