This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Erasing the entire flash

Hello.

In one project I need to erase the whole flash from my main program.Is it possible to do it?

We have tried to do it via FlashErase function inside a for, but if you delete a zone of a function that is called, then the program gets stuck.

Regards

  • Hello PAk,

    The only way is to copy the erase function to the SRAM, program then branches to SRAM and runs the FlashErase while executing from SRAM. However after a reset with the Flash empty the device will execute from ROM.

    Regards

    Amit

  • Thank you Amit for your answer.

    Amit Ashara said:
    However after a reset with the Flash empty the device will execute from ROM.

    That is what we want!!

    Amit Ashara said:
    The only way is to copy the erase function to the SRAM, program then branches to SRAM and runs the FlashErase while executing from SRAM.

    Could you give us a hand on this with some little code?

    Regards

  • Hi Pak,

    I don't know if there's a way to do this without using assembly but here it goes a small explanation of the basic:

    You first need to ofcourse setup the fuction in the RAM. The Assembly commands are just binary 32bits each so if you jump the PC to that address it will read it as commands. If you set it up like array you should have them all next to each other.

    Then you need to do a jump into this fuction address right? That would be the array address, just do a jump to that. Jump and link would not realy matter since you would be erasing the flash.

    Look at this image, maybe it will help understand why it's possible to jump to the ram. This is from the TM4c123 launchpad chip

    Of course if you jump into the rong address you can cause alot of problems

    Then of course you need to not let the PC go through the entire ram, you need to either make a while(1); or jump it back to a newly written code in the flash or rom

  • Thank you Luis Alfonso.

    All those concepts were pretty clear for us, however it is a great help for those new into Tiva devices.

    Luis Afonso said:
    I don't know if there's a way to do this without using assembly but here it goes a small explanation of the basic:

    That was my point.

    Anyway, which could be the assembler code?

    Regards

  • Hi Pak,

    I only learn assembly with MIPS based processors so i can't realy help you with that :/

    I can analyse assembly code from ARM but i can't actualy create one easily so i can«t realy help you with that unless you want a MIPS example 

  • I found an easy way to launch a function in SRAM, thanks to the linker.

    In your cmd file just add a new section:

    .new_sec_ram  : load = FLASH, run = SRAM

    After that, just above the function you want to launch from RAM add:

    #pragma CODE_SECTION(function_name, ".new_sec_ram");
    void function_name(){}

    Works like a charm, I can now erase entire flash.

  • Hi Pak,

    Glad to hear it! 

  • Hello PAk,

    I'm using TM4C123GH6PMI. I want to erase the entire flash. Either from my application OR from another MCU over UART0. I see that you have done the similar work.

    I'm using Keil and noticed that ".sct" is what linker handles. I do not understand where shall I put ".new_sec_ram" section. What shall I write inside the "function_name()" which can erase the flash.

    Could you please help me with little explanation and code that will do the task.

    Thanks in advance.