2016-08-16 11:45 PM
Hi,
Assume there is a button for emergency on the hardware, so the program which is currently running on ST will erase its own code when someone pressed the emergency button more than 10seconds.How could you implement it? Could anybody lead me how to do it?Regards2016-08-17 01:31 AM
Hi,
I assume that you just want to remove the code and thereby making the device unusable.This is very possible and should not be hard. The hard part is when you need to get things working, not the other way around :)I would put some erase procedure either in ram when device is started or in flash somewhere and just simply call this code to erase the flash section containing the program code.If you do not need to erase everything you could render the device useless by simply writing a couple of zeros to the startup address (for stm32 usually 0x80000000). For this option you do not need dedicated code to erase flash. Just write the zeros and do soft reset (NVIC).2016-08-17 01:46 AM
Hi,
You are right, I want to make the device unsable, however, this is not the only purpose also want to prevent downloading the code by anybody, so need to write 0xFF or zeros to entire flash memory of device.The thing that I do not get is erasing from the beggining of flash while running the code. How could it affect the running code? Does not it break if I start to write zeros from the beggining?Thanks2016-08-17 02:01 AM
If you want to erase everything, including the code that does the erase, I would suggest jumping to an erase function in RAM (I have never done this so cannot give any guarantee that it will work or how difficult it is). Perhaps it is also possible to jump to the STM32 default bootloader and call some procedure there. This I do not know.
2016-08-17 06:16 AM
Flash is erased by blocks, the block is set to 0xFF. You do not need to overwrite it byte by byte. Use spare flash block to store ''erase routine'' (functions are part of STM libs), jump there, disable all interrupts and erase all blocks with code except this one, then stay in infinite loop. You can place code at certain address using some pragma or SCT (scatter) file.
If you do not have a spare flash block, than use RAM, but this needs some more fiddling - otherwise you end up erasing your routine and the CPU will jump to hard fault or something leaving the rest not erased.2016-08-19 07:19 AM
Hi,
You can find the flash erase example code in ST documentation. Search for IAP (in application programming) and you will find code for programming by Serial, I2C, USB, and Ethernet. All of them erase first the flash then programm the flash. You can use the Erase part for your job.After erasing dont forget to go in infinte loop or enable watch dog for generating a rest to be back in an defined state.Regards,Osto2016-08-19 11:30 PM
2016-08-20 08:53 AM
Lighting off a mass-erase should be sufficient to nuke the part, and wouldn't require code in RAM or other non-sense.