English
Language : 

UM0290 Datasheet, PDF (36/76 Pages) STMicroelectronics – This document presents a description
Device firmware upgrade
UM0290
4.5.4
4.5.5
Downloading and uploading
The host slices the firmware image file into N pieces and sends them to the device by
means of control-write operations in the default endpoint (Endpoint 0).
The maximum number of bytes that the device can accept per control-write transaction is
specified in the wTransferSize field of the DFU Functional Descriptor.
There are several possible download mechanisms depending on the MCU device memory
mapping and the Type of the memory (that is Readable, Erasable, Writeable or a
combination).
The most generic mechanism is described below, where we have a readable, erasable and
writeable sector of memory:
● In addition to the data collected after the enumeration phase about the whole memory
mapping, the device capabilities etc., the Host starts to send a GetCommands
command in order to know additional device capabilities and which commands are
supported by the DFU implementation.
● The host sends an Erase Sector Containing Address command using a DFU_DNLOAD
request with wBlockNum = 0 and wLength = 5. At this stage, the device erases the
memory block where the address sent by the host is located. After the erase operation,
the DFU firmware is able to write application data into the erased block.
● The host begins by sending the Set Address Pointer command using a DFU_DNLOAD
request with wBlockNum = 0 and wLength = 5. This address pointer is saved in the
device RAM as an Absolute Offset.
● The host continues to send the N pieces to the device by means of DFU_DNLOAD
requests with wBlockNum starting from 2 and with the maximum number of bytes that
the device can accept per control-write transaction specified in the wTransferSize
field of the DFU Functional Descriptor.
So the last data written into the memory will be located at device address:
Absolute Offset + (wBlockNum – 2) × wTransferSize + wLength, where
wBlockNum and wLength are the parameters of the last DFU_DNLOAD request.
If the Host wants to upload the memory data for verification, or to retrieve and archive a
device firmware, by definition the reverse of a Download is performed:
● The host begins by sending a Set Address Pointer command using a DFU_DNLOAD
request with wBlockNum = 0 and wLength = 5. This address pointer is saved in the
device RAM as an Absolute Offset.
● The host continues to send N DFU_UPLOAD requests with wBlockNum starting from 2
and with the maximum number of bytes that the device can accept per control-write
transaction specified in the wTransferSize field of the DFU Functional Descriptor if
bitCanAccelerate = 0. If bitCanAccelerate = 1 in the DFU Functional Descriptor, the
value in the wTransferSize field is fixed to 0x4096 bytes.
So the last data retrieved from the memory will be located at device address:
Absolute Offset + (wBlockNum – 2) × wTransferSize + wLength, where
wBlockNum and wLength are the parameters of the last DFU_UPLOAD request.
Manifestation phase
After the transfer phase completes, the device is ready to execute the new firmware. This is
achieved by performing a USB reset to re-enumerate the device in normal run-time
operation.
36/76