Search code examples
stm32dfu

How to determin size of internal flash for target?


I want to upload the device firmware to a file using dfu-util. How can I determine the correct size of flash memory?

After booting the device into DFU it can be found using:

dfu-util -l

For which I receive the following information:

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

To upload the flash configuration to a file I need to determine the size of flash memory. Based on this article the size would be 64 x 1kB of flash memory.

What is the meaning of 'Kg' in 0002Kg?
The instructions I am following (elsewhere, for a different device, see above) is using 128 x 1kB, instead which I believe is incorrect.
How can I calculate the size of flash memory and what will happen if I set the memory size too large to download an image?

The command is:

dfu-util -a 0 -s 0x08000000:131072 -U ./original.bin

I think it should be

dfu-util -a 0 -s 0x08000000:65536 -U ./original.bin

Solution

  • Please see UM0290 in which we find:

    Each Alternate setting string descriptor must follow this memory mapping else the PC Host Software would be able to decode the right mapping for the selected device:

    • @: To detect that this is a special mapping descriptor (to avoid decoding standard descriptor)
    • /: for separator between zones
    • Maximum 8 digits per address starting by “0x”
    • /: for separator between zones
    • Maximum of 2 digits for the number of sectors
    • * : For separator between number of sectors and sector size
    • Maximum 3 digits for sector size between 0 and 999
    • 1 digit for the sector size multiplier. Valid entries are: B (byte), K (Kilo), M (Mega)
    • 1 digit for the sector type as follows:
      • a (0x41): Readable
      • b (0x42): Erasable
      • c (0x43): Readable and Erasable
      • d (0x44): Writeable
      • e (0x45): Readable and Writeable
      • f (0x46): Erasable and Writeable
      • g (0x47): Readable, Erasable and Writeable

    So your string really does mean that the internal flash is 64 sectors of 2 KB, and that they are "readable, erasable and writable" (i.e. flash). Are you sure about your expectations of the device's flash layout?