Transcription of AN3156 Application note - STMicroelectronics
1 June 2021AN3156 Rev 121/23AN3156 Application noteUSB DFU protocol used in the STM32 bootloader IntroductionThis Application note describes the USB DFU protocol used in STM32 microcontroller bootloader , detailing each supported document applies to the STM32 products embedding bootloader versions , , , , and as specified in AN2606 STM32 microcontroller system memory boot mode (available on ), which also contains more information about the USB hardware resources and requirements for the device bootloader .
2 These products are listed in Table 1, and are referred to as STM32 throughout the document. Table 1. Applicable productsTypeSeriesMicrocontrollersSTM32F 0 SeriesSTM32F1 SeriesSTM32F2 SeriesSTM32F3 SeriesSTM32F4 SeriesSTM32F7 SeriesSTM32G0 SeriesSTM32G4 SeriesSTM32H7 SeriesSTM32L0 SeriesSTM32L1 SeriesSTM32L4 SeriesSTM32L5 SeriesSTM32WB Rev 12 Contents1 bootloader code sequence .. 52 USB DFU bootloader requests .. 83 DFU bootloader commands .. 94 DFU_UPLOAD request commands .. memory.
3 Command .. 105 DFU_DNLOAD request commands .. memory .. Address Pointer command .. command .. Unprotect command .. DFU mode .. 186 bootloader protocol version evolution .. 217 Revision history .. 22AN3156 Rev 123/23AN3156 List of tables3 List of tablesTable products .. 1 Table class requests .. 8 Table of DFU class-specific requests .. 8 Table bootloader commands .. 9 Table protocol versions .. 21 Table revision history .. 22 List of figuresAN31564/23AN3156 Rev 12 List of figuresFigure for STM32 connectivity line devices.
4 6 Figure for other STM32 devices .. 7 Figure request: device side.. 11 Figure request: host side .. 11 Figure request: device side .. 12 Figure request: host side .. 13 Figure memory: device side .. 15 Figure Address Pointer command: device side .. 16 Figure command: device side .. 17 Figure Unprotect command: device side .. 18 Figure DFU operation: device side .. 20AN3156 Rev 125/23AN3156 bootloader code sequence221 bootloader code sequenceThere is no difference in terms of protocol (requests and commands) between different bootloader DFU versions.
5 For the detailed difference list refer to Section the system memory boot mode is entered and the STM32 microcontroller (based on on Arm (a) cores) has been configured (for more details refer to AN2606), the bootloader code configures the USB and its interrupts, and waits for the enumeration done USB enumeration is performed as soon as the USB cable is plugged (or immediately if the cable is already plugged). If the user does not want the STM32 to enter the USB DFU bootloader Application , the USB cable has to be unplugged before reset.
6 The bootloader version is returned in the device descriptor in the MSB of the bcd Device field (example: 0x2000 = Version ).For connectivity line USB DFU bootloader , the device first tries the 25 MHz configuration, then, if it fails, the MHz configuration, and finally, if it fails, the 8 MHz configuration. In case of fail, this operation is repeated with an higher timeout value (the three configurations are tested again). If the second trial fails, a system reset is Arm is a registered trademark of Arm Limited (or its subsidiaries) in the US and/or code sequenceAN31566/23AN3156 Rev 12 Figure 1.
7 bootloader for STM32 connectivity line devices1. After system reset, the device return to the BL_DFU loop or execute code from Flash memory/RAM, depending upon the connection states and the boot pin Leave DFU is achieved by a 0 data download request followed by GetStatus request and device After six trials (the three clock configurations are tested twice), a system reset is generated. If the product uses HSE for the USB operation (except connectivity line): At startup the HSE is measured (if present) and if it is supported the USB is configured.
8 If the HSE is not detected the bootloader performs a system reset. If the measured value of the HSE clock is an unsupported value, the USB protocol does not work correctly. If the product uses the HSI for the USB operation: At startup the USB is configured using HSI to AN2606 for more details about product packet?No (Timeout)Ye sConfigure external oscillator mode and re-initialize USBE numeration phaseEnter DFU modeWait forHost commandsDFU requestroutinesDFU requestsJump to Leave DFUroutineLeave DFUG enerate Systemand exit DFU modeNeed reset?
9 Reset (1) Application AddressYe sNo Mode (2)Configure internal oscillator mode and re-initialize USBUSB deviceconnectedNoYe sDevice USB resetClock detectionphase(3) Increment TrialNumTrialNum > 6 Generate SystemResetai17755AN3156 Rev 127/23AN3156 bootloader code sequence22 Figure 2. bootloader for other STM32 devices1. After system reset, the device returns to the BL_DFU loop or execute code from Flash memory/RAM, depending upon the connection states and the boot pin Leave DFU is achieved by a 0 data download request followed by GetStatus request and device For some products the external oscillator HSE is not used for USB bootloader operations, only the internal oscillator HSI is used.
10 Check AN2606 to know which oscillator is required for each :At bootloader startup, the internal oscillator (HSI) is used as clock source for the USB interface. When the USB event is detected, the external oscillator is configured as USB clock for enumerationNoYe sConfigure Oscillator mode(HSE/HSI)(3)Enumeration phaseEnter DFU ModeGenerate System Reset (1)Wait for Host CommandsDFU request routinesYe sNeed Reset ?Leave DFU routineJump to Application Address and exit DFU modeDFU requestsLeave DFU Mode (2)NoNoUSB DFU bootloader requestsAN31568/23AN3156 Rev 122 USB DFU bootloader requestsUSB DFU bootloader supports the DFU protocol and requests compliant with the Universal Serial Bus Device Upgrade Specification for Device Firmware Upgrade Version , Aug 5, 2004.