0

I use the openocd script below to dump the flash memory of a STM32 microcontroller.

mkdir -p dump

openocd -f board/stm3241g_eval_stlink.cfg \
\
-c "init" \
-c "reset halt" \
-c "dump_image dump/image.bin 0x08000000 0x100000" \
-c "shutdown" \

FILENAME=dump/image.bin
FILESIZE=$(stat -c%s "$FILENAME")
echo "Size of $FILENAME = $FILESIZE bytes."

The script is supposed to read the whole memory which is 1MB in my case but it does it very rarely. Generally it stops reading the memory before the end.

Why can't I obtain 1MB each time I execute this script? What is the problem here to cause openocd stop dumping the rest of the memory?

sanchop22
  • 2,729
  • 12
  • 43
  • 66

1 Answers1

1

You can use dfu-utils to reflash your STM32 micros.

In Ubuntu/Debian distros you can install dfu-utils with apt:

$ sudo apt-get install dfu-util                                              
$ sudo apt-get install fwupd 

Boot your board in DFU mode (check datasheet). Once in DFU mode, you should see something similar to this:

$  lsusb | grep DFU                                                          
Bus 003 Device 076: ID 0483:df11 STMicroelectronics STM Device in DFU Mode   

Once booted in DFU mode, reflash your binary:

$ sudo dfu-util -d 0483:df11 -a 0 -s 0x08000000:leave -D build/$(PROJECT).bin

With -d option you choose product:vendorid such as listed by lsusb in DFU mode.

With the -a 0 option you select alternate mode 0, check the options available as in the following example:

$ sudo dfu-util -l                                                           
Found DFU: [0483:df11] ver=2200, devnum=101, cfg=1, intf=0, alt=1, name="@Option Bytes /0x1FFFF800/01*016 e", serial="FFFFFFFEFFFF"
Found DFU: [0483:df11] ver=2200, devnum=101, cfg=1, intf=0, alt=0, name="@Internal Flash /0x08000000/064*0002Kg", serial="FFFFFFFEFFFF"

As you can see, alt=0 is for internal flash memory.

With the -s option you specify the flash memory address where you save your binary. Check your memory map in datasheet.

Hope this helps! :-)

aicastell
  • 2,182
  • 2
  • 21
  • 33