0

I am playing with STM32F4DISCOVERY kit. I am loading a simple "blink led" program from jeremyherbert. I managed to compile the code and load it with OpenOCD. I loaded the code with the following command:

flash write_image main.bin 0x08000000

The program loads and runs after resetting the board. However, write_image command works only after I erase flash with:

flash erase_sector 0 0 11

If I do not erase flash, even if I do write_image with success, the program won't run (the leds won't blink).

Question: Why do I need to erase_sector before writing image? Why write_image alone is not enough?

glts
  • 21,808
  • 12
  • 73
  • 94
Jakub M.
  • 32,471
  • 48
  • 110
  • 179
  • look at the help for write_image I think there is an erase option. write writes, erase erases, if you want to write you need to erase first. – old_timer Jun 04 '18 at 02:06
  • Thanks. But why overwriting flash with write_image is not enough? If "erase" is necessary, why it is even an option (and not a default behavior)? It is not that "write" writes ones, and "erase" writes zeros :) – Jakub M. Jun 04 '18 at 04:57
  • depends on the part more often an erase clears it to ones, and a write writes the zeros if you want to think about that. But if a byte had the value 0xA from the last write and now you want that byte to be a 0x4 and write a 0x4 that by stays an 0xA. Making your program not work. – old_timer Jun 04 '18 at 12:13
  • it is an option because these are two separate steps, you can for example erase the whole part, but then write pages separately. – old_timer Jun 04 '18 at 12:13
  • why not just use the software as designed? – old_timer Jun 04 '18 at 12:14
  • unlike a hard drive where the only sectors you want to affect are the ones you are writing to, with a microcontroller you may want to erase more sectors than the ones you are writing and/or in some rare/special cases you want to write on top of a section that you have already written on, making more zeros or ones depending on the erase state (erase to 0xFF is common but sometimes you will find erase to 0x00). – old_timer Jun 04 '18 at 13:16
  • as a bare metal developer you own the whole chip/system generally, as an application programmer on some OS you own only the portion of the memory or disk space the OS allows you to have. – old_timer Jun 04 '18 at 13:18
  • That explains everything, thanks! – Jakub M. Jun 05 '18 at 20:58

0 Answers0