ST STM32F105 Series Application Note

ST STM32F105 Series Application Note

System memory boot mode
Hide thumbs Also See for STM32F105 Series:
Table of Contents

Advertisement

AN2662
Application note
STM32F105xx and STM32F107xx system memory boot mode
Introduction
This application note describes the bootloader stored in the system memory of the
STM32F105xx and STM32F107xx Connectivity Line Microcontrollers. All STM32F105xx
and STM32F107xx in production (rev. Z) include the bootloader detailed in this application
note.
The bootloader is used to program the application into the internal Flash memory. For more
information about the Flash module organization, refer to the STM32F10xxx Flash
programming manual (PM0042).
The specifications cover the architectural model of the bootloader for the STM32F105xx and
STM32F107xx family, but the low-level communication software supports all the
microcontroller families that implement the bootloader.
July 2009
Doc ID 14156 Rev 1
1/83
www.st.com

Advertisement

Table of Contents
loading

Summary of Contents for ST STM32F105 Series

  • Page 1 (PM0042). The specifications cover the architectural model of the bootloader for the STM32F105xx and STM32F107xx family, but the low-level communication software supports all the microcontroller families that implement the bootloader. July 2009 Doc ID 14156 Rev 1 1/83 www.st.com...
  • Page 2: Table Of Contents

    Contents AN2662 Contents Bootloader description ........7 Bootloader introduction .
  • Page 3 AN2662 Contents Get ID command ......... . . 47 Speed command .
  • Page 4 List of tables AN2662 List of tables Table 1. Boot pin configuration ............7 Table 2.
  • Page 5 AN2662 List of figures List of figures Figure 1. Bootloader selection ............11 Figure 2.
  • Page 6 List of figures AN2662 Figure 49. Readout Protect command via CAN: device side ....... . 64 Figure 50.
  • Page 7: Bootloader Description

    AN2662 Bootloader description Bootloader description Bootloader introduction The bootloader is stored in the internal boot ROM memory (system memory), and its main task is to download the application program to the internal Flash memory through one of the following communication interfaces: USART1, USART2 (remapped), CAN2 (remapped) or USB OTG FS in Device mode (DFU: device firmware upgrade).
  • Page 8: Table 2. Stm32F105Xx And Stm32F107Xx Configuration In System Memory Boot Mode

    Bootloader description AN2662 Table 2. STM32F105xx and STM32F107xx configuration in System memory boot mode Bootloader Feature/Peripheral State Comment The system clock frequency is 24 MHz using the PLL. This is used only for USART1 and USART2 bootloaders and during HSI enabled CAN2, USB detection for CAN and DFU bootloaders (Once CAN or DFU bootloader is selected, the clock source will be derived from external crystal).
  • Page 9: Hardware Requirements

    The user must use a full null modem cable. The necessary hardware to implement for this control exists in the STM3210C-EVAL board. For more details about this, refer to document: “STM3210C-EVAL board user manual”, available from the STMicroelectronics website: www.st.com. Bootloader selection The STM32F105xx and STM32F107xx embedded bootloader supports four peripherals interfaces: USART1, USART2, CAN2 and DFU (USB).
  • Page 10 Bootloader description AN2662 interfaces can be used to communicate with the bootloader and download the application code to the internal Flash. The embedded bootloader firmware is able to auto-detect the peripheral interface to be used. In an infinite loop, it detects any communication on the supported bootloader interfaces.
  • Page 11: Figure 1. Bootloader Selection

    AN2662 Bootloader description Figure 1. Bootloader selection BL reset Configure internal RC mode Configure USART1 and USART2 pins Configure CAN2 Configure USB 0x7F received on USART2 Configure USART2 Execute BL_USART_Loop for 0x7F received on USART2 USART1 Configure USART1 Execute BL_USART_Loop for USART1 CAN2_RX pin is low level...
  • Page 12: Exiting System Memory Boot Mode

    Bootloader description AN2662 Exiting System Memory boot mode System Memory boot mode must be exited in order to start execution of the application program. This can be done by applying a hardware reset. During reset, the BOOT pins (BOOT0 and BOOT1) must be set at the proper levels to select the desired boot mode (see Table 1).
  • Page 13: Usart Bootloader

    AN2662 USART bootloader USART bootloader Bootloader code sequence Figure 2. Bootloader for STM32F105xx and STM32F107xx with USART1/USART2 Once System memory boot mode is entered and the microcontroller has been configured as described above, the bootloader code begins to scan the USARTx_RX line pin, waiting to receive the 0x7F data frame: one start bit, 0x7F data bits, even parity bit and one stop bit.
  • Page 14: Minimum Baud Rate

    USART bootloader AN2662 microcontroller baud rate can be calculated using the formula below: STM32Fxxx baud rate Host baud rate – × ≤ 2.5%. 100% , where f ------------------------------------------------------------------------------------------------------- - STM32Fxxx baud rate This baud rate deviation is a nonlinear function depending on the CPU clock and the baud rate of the host.
  • Page 15: Get Command

    AN2662 USART bootloader Table 3. Bootloader commands (continued) Command Command Command description code Readout Protect 0x82 Enables the read protection Readout Unprotect 0x92 Disables the read protection 1. If a denied command is received or an error occurs during the command execution, the bootloader sends NACK byte and goes back to command checking.
  • Page 16: Figure 3. Get Command: Host Side

    USART bootloader AN2662 Figure 3. Get command: host side Start Get Send 0x00 + 0xFF NACK Wait for ACK or NACK Receive the number of bytes (version+commands) Receive the bootloader version Receive the supported commands Wait for ACK NACK or NACK End of Get ai14631 Figure 4.
  • Page 17: Get Version & Read Protection Status Command

    AN2662 USART bootloader The STM32F105xx and STM32F107xx sends the bytes as follows: Byte 1: Byte 2: N = 11 = the number of bytes to follow – 1 except current and ACKs. Byte 3: Bootloader version (0 < Version < 255): 0x10 = Version 1.0 Byte 4: 0x00 –...
  • Page 18: Figure 5. Get Version & Read Protection Status Command: Host Side

    USART bootloader AN2662 Figure 5. Get Version & Read Protection Status command: host side Start GV Send 0x01+0xFE NACK Wait for ACK or NACK Receive the bootloader version Receive the number of times the read protection was disabled Receive the number of times the read protection was enabled NACK Wait for ACK...
  • Page 19: Get Id Command

    AN2662 USART bootloader Figure 6. Get Version & Read Protection Status command: device side Start GV Received byte = 0x01+0xFE? Send NACK byte Send ACK byte Send the bootloader version Option byte 1 Option byte 2 Send ACK byte End of GV ai14634 1.
  • Page 20: Figure 7. Get Id Command: Host Side

    USART bootloader AN2662 Figure 7. Get ID command: host side Start GID Send 0x02+0xFD NACK Wait for ACK or NACK Receive N = number of bytes – 1 Receive PID NACK Wait for ACK or NACK End of GID ai14633 1.
  • Page 21: Read Memory Command

    AN2662 USART bootloader Read Memory command The Read Memory command is used to read data from any memory address in RAM (starting from address 0x20001000), Flash memory and information block (System memory or option byte areas). When the bootloader receives the Read Memory command, it transmits the ACK byte to the user.
  • Page 22: Figure 9. Read Memory Command: Host Side

    USART bootloader AN2662 Figure 9. Read Memory command: host side Start RM Send 0x11+0xEE NACK Wait for ACK or NACK Send the start address (4 bytes) with checksum NACK Wait for ACK or NACK Send the number of bytes to be read (1 byte) and a checksum (1 byte) Wait for ACK or NACK...
  • Page 23: Go Command

    AN2662 USART bootloader Figure 10. Read Memory command: device side Start RM Received byte = 0x11+0xEE ROP active Send ACK byte Receive the start address (4 bytes) with checksum Address valid & checksum OK? Send ACK byte Receive the number of bytes to be read (1 byte) and a checksum (1 byte) Checksum OK? Send ACK byte...
  • Page 24: Figure 11. Go Command: Host Side

    USART bootloader AN2662 When the address is valid and the checksum is correct, the program counter of the CPU automatically jumps to the address. Figure 11. Go command: host side Start Go Send 0x21+0xDE NACK Wait for ACK or NACK Send the start address (4 bytes) &...
  • Page 25: Write Memory Command

    AN2662 USART bootloader Figure 12. Go command: device side Start Go Received bytes = 0x21+0xDE? ROP active Send ACK byte Receive the start address (4 bytes) & checksum Send ACK byte Address valid & Send NACK byte checksum OK? Send ACK byte End of Go Jump to address ai14640b...
  • Page 26 USART bootloader AN2662 start address must be 0x1FFFF800 to avoid writing inopportunely in this area. If the received address is valid and the checksum is correct, the bootloader transmits an ACK byte, otherwise it transmits a NACK byte and aborts the command. When the address is valid and the checksum is correct, the bootloader: ●...
  • Page 27: Figure 13. Write Memory Command: Host Side

    AN2662 USART bootloader Figure 13. Write Memory command: host side Start WM Send 0x31+0xCE NACK Wait for ACK or NACK Send the start address (4 bytes) & checksum NACK Wait for ACK or NACK Send the number of bytes to be written (1 byte), the data (N + 1) bytes) &...
  • Page 28: Figure 14. Write Memory Command: Device Side

    USART bootloader AN2662 Figure 14. Write Memory command: device side Start WM Received byte = 0x31+0xCE? ROP inactive? Send ACK byte Receive the start address (4 bytes) & checksum Checksum OK? Send ACK byte Receive the number of bytes to be written (1 byte), the data (N + 1 bytes) &...
  • Page 29: Erase Memory Command

    AN2662 USART bootloader The host sends the bytes to the STM32F105xx and STM32F107xx as follows: Byte 1: 0x31 Byte 2: 0xCE Wait for ACK Byte 3 to byte 6: start address byte 3: MSB byte 6: LSB Byte 7: Checksum: XOR (Byte3, Byte4, Byte5, Byte6) Wait for ACK Number of bytes to be received (0 <...
  • Page 30: Figure 15. Erase Memory Command: Host Side

    USART bootloader AN2662 Figure 15. Erase Memory command: host side Start ER Send 0x43+0xBC NACK Wait for ACK or NACK Global Erase? Send 0xFF Send the number of pages to be erased (1 byte) Send 0x00 Send the page numbers Send checksum NACK Wait for ACK...
  • Page 31: Figure 16. Erase Memory Command: Device Side

    AN2662 USART bootloader Figure 16. Erase Memory command: device side Start ER Received bytes = 0x43+0xBC? ROP active Send ACK byte Receive the number of pages to be erased (1 byte) 0xFF received? Receive the page codes Start Global Erase Receive the checksum (Mass Erase) Checksum...
  • Page 32: Write Protect Command

    USART bootloader AN2662 2.13 Write Protect command The Write Protect command is used to enable the write protection for some or all Flash memory sectors. When the bootloader receives the Write Protect command, it transmits the ACK byte to the host. After the transmission of the ACK byte, the bootloader waits for the number of bytes to be received (sectors to be protected) and then receives the Flash memory sector codes from the user.
  • Page 33: Write Unprotect Command

    AN2662 USART bootloader Figure 18. Write Protect command: device side Start WP Received bytes = 0x63+0x9C? ROP active Send ACK byte Receive the number of sectors to be protected (1 byte) Receive the sector codes Receive the checksum Checksum Write-protect the requested sectors Send ACK byte Send NACK byte Generate system reset...
  • Page 34: Figure 19. Write Unprotect Command: Host Side

    USART bootloader AN2662 Figure 19. Write Unprotect command: host side Start WPUN Send 0x73+0x8C NACK Wait for ACK or NACK NACK Wait for ACK or NACK End of WPUN ai14647 1. WPUN = Write Unprotect. Figure 20. Write Unprotect command: device side Start WPUN Received bytes = 0x73+0x8C?
  • Page 35: Readout Protect Command

    AN2662 USART bootloader 2.15 Readout Protect command The Readout Protect command is used to enable the Flash memory read protection. When the bootloader receives the Readout Protect command, it transmits the ACK byte to the host. After the transmission of the ACK byte, the bootloader enables the read protection for the Flash memory.
  • Page 36: Readout Unprotect Command

    USART bootloader AN2662 Figure 22. Readout Protect command: device side Start RDP_PRM Received bytes = 0x82+0x7D? ROP active Send ACK byte Activate Read protection for Flash memory Send NACK byte Send ACK byte Generate system reset End of RDP_PRM ai14650b 1.
  • Page 37: Figure 23. Readout Unprotect Command: Host Side

    AN2662 USART bootloader Figure 23. Readout Unprotect command: host side Start RDU_PRM Send 0x92+0x6D NACK Wait for ACK or NACK NACK Wait for ACK or NACK End of RDU_PRM ai14651 1. RDU_PRM = Readout Unprotect. Figure 24. Readout Unprotect command: device side 1.
  • Page 38: Can Bootloader

    CAN bootloader AN2662 CAN bootloader Bootloader code sequence Figure 25. Bootloader for STM32F105xx and STM32F107xx withCAN2 Once System memory boot mode is entered and the microcontroller has been configured as described above, the bootloader code waits for a falling edge on the CAN2_Rx pin. When a detection occurs the CAN Bootloader firmware starts to check the external clock frequency, Figure 26 shows the flowchart of the frequency check.
  • Page 39: Figure 26. Check Hse Frequency Value

    AN2662 CAN bootloader Figure 26. Check HSE frequency value Doc ID 14156 Rev 1 39/83...
  • Page 40: Can Settings

    CAN bootloader AN2662 Next, the code initializes the serial interface accordingly. Using this calculated baud rate, an acknowledge byte (0x79) is returned to the host, which signals that the STM32F105xx and STM32F107xx is ready to receive user commands. CAN settings The STM32F105xx and STM32F107xx CAN2 is compliant with the 2.0A and B (active) specifications with a bitrate up to 1Mbit/s.
  • Page 41: Bootloader Command Set

    AN2662 CAN bootloader Note: The CAN Bootloader firmware supports only one node at the same time. This means that CAN Network Management is not supported by the firmware. Bootloader command set The supported commands are listed in Table 3 below. Each command is further described in this section.
  • Page 42: Get Command

    CAN bootloader AN2662 Get command The get command allows the host to get the version of the bootloader and the supported commands. When the bootloader receives the get command, it transmits the bootloader version and the supported command codes to the host. 42/83 Doc ID 14156 Rev 1...
  • Page 43: Figure 28. Get Command Via Can: Host Side

    AN2662 CAN bootloader Figure 28. Get command via CAN: Host side Doc ID 14156 Rev 1 43/83...
  • Page 44: Figure 29. Get Command Via Can: Device Side

    CAN bootloader AN2662 The host sends the messages as follows Command message: Std ID = 0x00, data length code (DLC) = ‘not important’. Figure 29. Get command via CAN: Device side The STM32F105xx and STM32F107xx sends the messages as follows Message 1: Std ID = 0x00, DLC = 1, data = 0x79 - ACK Message 2: Std ID = 0x00, DLC = 1 data = N = 12 = the number of bytes to be sent -1...
  • Page 45: Get Version & Read Protection Status Command

    AN2662 CAN bootloader Message 12: Std ID = 0x00, DLC = 1, data = 0x63 - Write Protect command Message 13: Std ID = 0x00, DLC = 1, data = 0x73 - Write Unprotect command Message 14: Std ID = 0x00, DLC = 1, data = 82h - Readout Protect command Message 15: Std ID = 0x00, DLC = 1, data = 92h - Readout Unprotect command...
  • Page 46: Figure 31. Get Version & Read Protection Status Command: Device Side

    CAN bootloader AN2662 Figure 31. Get Version & Read Protection Status command: device side 1. GV = Get Version & Read Protection Status. The STM32F105xx and STM32F107xx sends the messages as follows: Message 1: Std ID = 0x01, DLC = 1, data = ACK Message 2: Std ID = 0x01, DLC = 1, data[0] = bootloader version (0 <...
  • Page 47: Get Id Command

    AN2662 CAN bootloader Get ID command The Get ID command is used to get the version of the chip ID (identification). When the bootloader receives the command, it transmits the product ID to the host. Figure 32. Get ID command: host side 1.
  • Page 48: Speed Command

    CAN bootloader AN2662 Figure 33. Get ID command: device side 1. GID = Get ID. 2. PID: is the product ID, which may be 0x0410, 0x0412, 0x0414 or 0x0418 according to the STM32F105xx and STM32F107xx product. byte 1 is the MSB and byte 2 is LSB of the address. The STM32F105xx and STM32F107xx sends the bytes as follows: Message 1: Std ID = 0x02, DLC = 1, data = ACK with DLC except for current message...
  • Page 49: Figure 34. Speed Command Via Can: Host Side

    AN2662 CAN bootloader Figure 34. Speed command via CAN: Host side 1. After setting the new baud rate, the bootloader sends the ACK message. Therefore, the host sets its baud rate while waiting for the ACK. The host sends the message as follows Command message: Std ID = 0x03, DLC = 0x01, data[0] = XXh where XXh takes the following values depending on the baud rate to be set: ●...
  • Page 50: Read Memory Command

    CAN bootloader AN2662 Figure 35. Speed command via CAN: Device side The STM32F105xx and STM32F107xx sends the bytes as follows: Message 1: Std ID = 0x03, DLC = 1, data[0] = ACK= 0x79: with old baudrate if the receive message is correct else data[0] = NACK= 0x1F Message 2: Std ID = 0x02, DLC = 1, data[0] = ACK = 0x79 with new baudrate Read Memory command...
  • Page 51: Figure 36. Read Memory Command Via Can: Host Side

    AN2662 CAN bootloader After sending an ACK message, then it transmits the required data to the user ((N + 1) bytes) via (N+1) messages /8 (since each message contains 8 bytes), starting from the received address. Figure 36. Read memory command via CAN: Host side The host sends the messages as follows Command message: Std ID = 0x11, DLC = 0x05, data[0] = 0xXX: MSB of the address ...
  • Page 52: Go Command Via Can

    CAN bootloader AN2662 The STM32F105xx and STM32F107xx sends the messages as follows: ACK message: Std ID = 0x11, DLC = 1, data[0] = ACK if content of the command is correct else data[0] = NACK Data message (N+1) / 8: Std ID = 0x11, DLC = Number of Byte, data[0] = 0xXX ... data[Number of Byte - 1] = 0xYY ACK message: Std ID = 0x11, DLC = 1, data[0] = ACK Go command via CAN...
  • Page 53: Write Memory Command Via Can

    AN2662 CAN bootloader Figure 39. Go command via CAN: Device side The STM32F105xx and STM32F107xx sends the messages as follows: ACK message: Std ID = 0x21, DLC = 1, data[0] = ACK if content of the command is correct else data[0] = NACK 3.10 Write Memory command via CAN The Write Memory command is used to write data to any memory address of RAM starting...
  • Page 54: Figure 40. Write Memory Command Via Can: Host Side

    CAN bootloader AN2662 Note: When writing to the RAM, care must be taken to avoid overlapping the first 4Kbytes (0x1000) in RAM because they are used by the bootloader firmware. Note: No error is returned when performing write operations on write protected sectors. Write operations to FLASH/SRAM must be word aligned, if less data are written the remaining bytes must be filled with 0xFF.
  • Page 55 AN2662 CAN bootloader The host sends the messages as follows Command message: Std ID = 0x31, DLC = 0x05, data[0] = 0xXX: MSB address,... , data[3] = 0xYY: LSB address, data[4] = N(number of bytes to be written), 0 < N <= 255). then the host send N/8 message Data message: Std ID = 0x31, DLC_1 = to 8, data = byte_11, …...
  • Page 56: Figure 41. Write Memory Command Via Can: Device Side

    CAN bootloader AN2662 Figure 41. Write memory command via CAN: Device side The STM32F105xx and STM32F107xx sends the messages as follows: ACK message: Std ID = 0x31, DLC = 1, data[0] = ACK if the content of the command is correct else data[0] = NACK 56/83 Doc ID 14156 Rev 1...
  • Page 57: Erase Memory Command Via Can

    AN2662 CAN bootloader 3.11 Erase Memory command via CAN The Erase Memory command allows the host to erase Flash memory pages. When the bootloader receives the Erase Memory command and ROP is disabled, it transmits the ACK message to the host. After the transmission of the ACK message, the bootloader checks if the message that contain data[0].
  • Page 58: Write Protect Command

    CAN bootloader AN2662 Figure 43. Erase Memory command via CAN: Device side The STM32F105xx and STM32F107xx sends the messages as follows: ACK message: Std ID = 0x43, DLC = 1, data[0] = ACK if content of the command is correct and ROP is not active else data[0] = NACK 3.12 Write Protect command...
  • Page 59: Figure 44. Write Protect Command Via Can: Host Side

    AN2662 CAN bootloader Note: The total number of sectors and the sector number to be protected are not checked, this means that no error is returned when a command is passed with a wrong number of sectors to be protected or a wrong sector number. If a second Write Protect command is executed, the Flash memory sectors that were protected by the first command become unprotected and only the sectors passed within the second Write Protect command become protected.
  • Page 60: Write Unprotect Command

    CAN bootloader AN2662 Figure 45. Write Protect command via CAN: device side 1. WP = Write Protect The STM32F105xx and STM32F107xx sends the messages as follows: ACK message: Std ID = 0x43, DLC = 1, data[0] = ACK if the content of the command is correct and ROP is not active else data[0] = NACK.
  • Page 61: Figure 46. Write Unprotect Command: Host Side

    AN2662 CAN bootloader Figure 46. Write Unprotect command: Host side 1. WPUN = Write Unprotect. The host sends the messages as follows Command message: Std ID = 0x73, DLC = 0x01, data = 00. Doc ID 14156 Rev 1 61/83...
  • Page 62: Readout Protect Command

    CAN bootloader AN2662 Figure 47. Write Unprotect command: device side 1. WPUN = Write Unprotect. The STM32F105xx and STM32F107xx sends the messages as follows: ACK message: Std ID = 0x73, DLC = 1, data[0] = ACK if the content of the command is correct and ROP is not active else data[0] = NACK.
  • Page 63: Figure 48. Readout Protect Command Via Can: Host Side

    AN2662 CAN bootloader Figure 48. Readout Protect command via CAN: Host side 1. RDP_PRM = Readout Protect. The host sends the messages as follows Command message: Std ID = 0x82, DLC = 0x01, data[0] = 00. Doc ID 14156 Rev 1 63/83...
  • Page 64: Readout Unprotect Command

    CAN bootloader AN2662 Figure 49. Readout Protect command via CAN: device side 1. RDP_PRM = Readout Protect The STM32F105xx and STM32F107xx sends the messages as follows: ACK message: Std ID = 0x82, DLC = 1, data[0] = ACK if the content of the command is correct and ROP is not active else data[0] = NACK.
  • Page 65: Figure 50. Readout Unprotect Command Via Can: Host Side

    AN2662 CAN bootloader Figure 50. Readout Unprotect command via CAN: Host side 1. RDU_PRM = Readout Unprotect. The host sends the messages as follows Command message: Std ID = 0x92, DLC = 0x01, data = 00. Doc ID 14156 Rev 1 65/83...
  • Page 66: Figure 51. Readout Unprotect Command Via Can: Device Side

    CAN bootloader AN2662 Figure 51. Readout Unprotect command via CAN: device side 1. RDU_PRM = Readout Unprotect. The STM32F105xx and STM32F107xx sends the messages as follows: ACK message: Std ID = 0x92, DLC = 1, data[0] = ACK if the content of the command is correct and ROP is not active else data[0] = NACK.
  • Page 67: Dfu Bootloader

    AN2662 DFU bootloader DFU bootloader Bootloader code sequence Figure 52. Bootloader for STM32F105xx and STM32F107xx with USB DFU BL_DFU Configure internal oscillator mode and re-initialize USB Device USB reset Increment TrialNum USB Device connected Clock Detection Phase Configure external oscillator TrialNum >...
  • Page 68: Usb Dfu Bootloader Requests

    DFU bootloader AN2662 Once System Memory boot mode is entered and the STM32F105xx and STM32F107xx has been configured as described above, the bootloader code configures the USB and its interrupts and waits for the “enumeration done” interrupt. Once this interrupt is detected (A Host is present, has connected the device and enumerated it), the system is configured in External Oscillator mode and the USB device is re-initialized.
  • Page 69: Dfu Bootloader Commands

    AN2662 DFU bootloader Note: The Detach request is not meaningful in the case of the bootloader. The bootloader is started by a system reset depending on the boot mode configuration settings, which means that no other application is running at this time. Table 6.
  • Page 70: Get Commands

    DFU bootloader AN2662 The host requests the device to send a specified number of data bytes ( ) from wLength Internal Flash, Embedded RAM (starting from 0x2000 1000 address), System Memory or from Option Bytes. The allowed number of bytes to be read depends on the memory target: ●...
  • Page 71: Figure 53. Dfu_Upload Request: Device Side

    AN2662 DFU bootloader Figure 53. DFU_UPLOAD request: Device side DFU_UPLOAD request Current status is dfuIDLE or dfuUPLOAD-IDLE Stall Acknowledge the request wBlockNum == 0 ? wBlockNum > 1? Stall ROP Active? Send the supported Send the requested State = dfuERROR number of data bytes command codes Status = errVENDOR...
  • Page 72: Dfu_Dnload Request Commands

    DFU bootloader AN2662 Note: Before issuing an Upload request, the host has to check that the device is in a correct state (dfuIDLE or dfuUPLOAD-IDLE state) and that there is no error reported in the status. If the Device is not in the required state/status, the Host has to clear any error (DFU_CLRSTATUS request) and get the new status till the Device returns to dfuIDLE state.
  • Page 73: Figure 55. Download Request: Device Side

    AN2662 DFU bootloader Figure 55. Download request: Device side Download request Current status is dfuIDLE or dfuDNLOAD-IDLE Stall Acknowledge the request wLength > 0 Leave DFU routine Wait for data stage Receive data buffer Wait for Get Status Return Status: dfuDNBUSY wBlockNum == 0 ? wBlockNum >...
  • Page 74: Figure 56. Download Request: Host Side

    DFU bootloader AN2662 Figure 56. Download request: Host side Download request Packet Acked? Write/Set Address Pointer/ Leave DFU routine Error Erase/Read Unprotect routines Send Data Buffer State == dfuManifest? Packet Acked? Error Expect Device Error disconnect Get Status State == dfuDNBUSY? Error Operation needs System Reset?
  • Page 75: Write Memory

    AN2662 DFU bootloader Device is not in the required state/status, the Host has to clear any error (DFU_CLRSTATUS request) and get again the status till the Device returns to dfuIDLE state. 4.5.1 Write memory > 1. The Write Memory operation is selected when wValue The host requests the device to receive a specified number of data bytes ( ) to load...
  • Page 76: Set Address Pointer Command

    DFU bootloader AN2662 Figure 57. Write Memory: Device side Write Memory Compute address Address allowed? State = dfuERROR Status = errTARGET ROP active? State = dfuERROR Write the received buffer Status = errVENDOR to the destination address Destination == Option Bytes? State = dfuDNLOAD-IDLE System Reset...
  • Page 77: Erase Command

    AN2662 DFU bootloader A second DFU_GETSTATUS request is needed to check if the command has been correctly executed. If the received address is wrong or unsupported, the device status will then be (Status = dfuERROR, State = errTARGET). The allowed locations for Address Pointer values are: ●...
  • Page 78: Read Unprotect Command

    DFU bootloader AN2662 The STM32F105xx and STM32F107xx receives the bytes as follows (Mass Erase): Byte 1: 0x41 - Erase command After sending an Erase command, the host has to send a DFU_GETSTATUS request. The Erase command is effectively executed only when a DFU_GETSTATUS request is issued by the Host.
  • Page 79: Leave Dfu Mode

    AN2662 DFU bootloader The Host sends a DFU_DNLOAD request with the above parameters to remove the read protection of the internal Flash memory. The STM32F105xx and STM32F107xx receives the byte as follows: Byte 1: 0x92 - Read Unprotect command After sending a Read Unprotect command, the Host has to send a DFU_GETSTATUS request.
  • Page 80 DFU bootloader AN2662 The DFU Leave operation is effectively executed only when a DFU_GETSTATUS request is issued by the Host. If the status returned by the device is other than dfuMANIFEST, then an error has occurred. After this operation, the device frees all used resources, disconnects itself and jumps to the destination given by the Address Pointer in order to execute the code loaded in this address.
  • Page 81: Figure 61. Leave Dfu Operation: Device Side

    AN2662 DFU bootloader Figure 61. Leave DFU operation: Device side DFU Leave routine Wait for Get Status Return state: dfuMANIFEST Manifestation initiated? Free resources Return error status and disconnect device Jump to application address This status depends on the error origin and the current status. Doc ID 14156 Rev 1 81/83...
  • Page 82: Revision History

    Revision history AN2662 Revision history Table 7. Document revision history Date Revision Changes 08-Jul-2009 Initial release. 82/83 Doc ID 14156 Rev 1...
  • Page 83 No license, express or implied, by estoppel or otherwise, to any intellectual property rights is granted under this document. If any part of this document refers to any third party products or services it shall not be deemed a license grant by ST for the use of such third party products or services, or any intellectual property contained therein or considered as a warranty covering the use in any manner whatsoever of such third party products or services or any intellectual property contained therein.

This manual is also suitable for:

Stm32f107 series

Table of Contents