ST AN3155 Application Note
ST AN3155 Application Note

ST AN3155 Application Note

Usart protocol used in the stm32 bootloader
Table of Contents

Advertisement

AN3155
Application note
USART protocol used
in the STM32™ bootloader
Introduction
This application note describes the USART protocol used in the STM32 microcontroller
bootloader. It details each supported command. For more information about the USART
hardware resources and requirements for your device bootloader, please refer to the
"STM32 system memory boot mode" application note (AN2606).
Related documents
Available from www.st.com:
AN2606 "STM32 system memory boot mode"
April 2010
Doc ID 17066 Rev 2
1/37
www.st.com

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the AN3155 and is the answer not in the manual?

Questions and answers

Summary of Contents for ST AN3155

  • Page 1 It details each supported command. For more information about the USART hardware resources and requirements for your device bootloader, please refer to the “STM32 system memory boot mode” application note (AN2606). Related documents Available from www.st.com: AN2606 “STM32 system memory boot mode” April 2010 Doc ID 17066 Rev 2 1/37 www.st.com...
  • Page 2: Table Of Contents

    Contents AN3155 Contents USART bootloader code sequence ......5 Choosing the USARTx baud rate ....... 6 Minimum baud rate .
  • Page 3 AN3155 List of tables List of tables Table 1. USART bootloader commands ..........7 Table 2.
  • Page 4 List of figures AN3155 List of figures Figure 1. Bootloader for STM32 with USART ......... . . 5 Figure 2.
  • Page 5: Usart Bootloader Code Sequence

    AN3155 USART bootloader code sequence USART bootloader code sequence Figure 1. Bootloader for STM32 with USART Once the system memory boot mode is entered and the STM32 microcontroller has been configured (for more details refer to application note AN2606 “STM32 system memory boot mode”) the bootloader code begins to scan the USARTx_RX line pin, waiting to receive the...
  • Page 6: Choosing The Usartx Baud Rate

    Choosing the USARTx baud rate AN3155 Choosing the USARTx baud rate The calculation of the serial baud rate for USARTx, from the length of the first byte that is received, is used to operate the bootloader within a wide range of baud rates. However, the upper and lower limits have to be kept, in order to ensure proper data transfer.
  • Page 7: Bootloader Command Set

    AN3155 Bootloader command set Bootloader command set The supported commands are listed in Table 1 below. Each command is further described in this section. Table 1. USART bootloader commands Command Command code Command description Gets the version and the allowed commands supported...
  • Page 8: Device-Dependent Bootloader Parameters

    Bootloader command set AN3155 Each packet is either accepted (ACK answer) or discarded (NACK answer): ● ACK = 0x79 ● NACK = 0x1F Device-dependent bootloader parameters While the USART bootloader protocol’s command set and sequences are the same for all the STM32 devices, some parameters are device-dependent.
  • Page 9: Get Command

    AN3155 Bootloader command set Get command The Get command allows you 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, as described in Figure Figure 2.
  • Page 10: Get Version & Read Protection Status Command

    Bootloader command set AN3155 The STM32 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), example: 0x10 = Version 1.0...
  • Page 11: Figure 4. Get Version & Read Protection Status Command: Host Side

    AN3155 Bootloader command set Figure 4. 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...
  • Page 12: Get Id Command

    Bootloader command set AN3155 The STM32 sends the bytes as follows: Byte 1: Bootloader version (0 < Version ≤ 255), example: 0x10 = Version 1.0 Byte 2: Byte 3: Option byte 1: 0x00 to keep the compatibility with generic bootloader protocol...
  • Page 13: Read Memory Command

    AN3155 Bootloader command set Figure 7. Get ID command: device side Start GID Received byte = 0x02+0xFD? Send NACK byte Send ACK byte Send N = number of bytes – 1 Send product ID Send ACK byte End of GID ai14636 1.
  • Page 14: Figure 8. Read Memory Command: Host Side

    Bootloader command set AN3155 The host sends bytes to the STM32 as follows: Bytes 1-2: 0x11+0xEE Wait for ACK Bytes 3 to 6: start address ● byte 3: MSB ● byte 6: LSB Byte 7: Checksum: XOR (byte 3, byte 4, byte 5, byte 6) Wait for ACK The number of bytes to be read –...
  • Page 15: Figure 9. Read Memory Command: Device Side

    AN3155 Bootloader command set Figure 9. 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)
  • Page 16: Go Command

    Bootloader command set AN3155 Go command The Go command is used to execute the downloaded code or any other code by branching to an address specified by the application. When the bootloader receives the Go command, it transmits the ACK byte to the application. After the transmission of the ACK byte, the bootloader waits for an address (4 bytes, byte 1 is the address MSB and byte 4 is LSB) and a checksum byte, then it checks the received address.
  • Page 17: Figure 11. Go Command: Device Side

    AN3155 Bootloader command set Note: Valid addresses for the Go command are in RAM or Flash memory (refer to Section 3.1: Device-dependent bootloader parameters for more details about the valid memory addresses for the device you are using). All other addresses are considered not valid and are NACKed by the device.
  • Page 18: Write Memory Command

    Bootloader command set AN3155 The host sends bytes as follow to the STM32: Byte 1: 0x21 Byte 2: 0xDE Wait for ACK Byte 3 to byte 6: start address byte 3: MSB byte 6: LSB Byte 7: checksum: XOR (byte 3, byte 4, byte 5, byte 6)
  • Page 19: Figure 12. Write Memory Command: Host Side

    AN3155 Bootloader command set Figure 12. Write Memory command: host side 1. WM = Write Memory. 2. N+1 should always be a multiple of 4. Doc ID 17066 Rev 2 19/37...
  • Page 20: Figure 13. Write Memory Command: Device Side

    Bootloader command set AN3155 Figure 13. 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...
  • Page 21: Erase Memory Command

    AN3155 Bootloader command set The host sends the bytes to the STM32 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 22: Figure 14. Erase Memory Command: Host Side

    Bootloader command set AN3155 Figure 14. 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...
  • Page 23: Figure 15. Erase Memory Command: Device Side

    AN3155 Bootloader command set Figure 15. 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...
  • Page 24: Extended Erase Memory Command

    Bootloader command set AN3155 Extended Erase Memory command The Extended Erase Memory command allows the host to erase Flash memory pages using two bytes addressing mode. When the bootloader receives the Extended Erase Memory command, it transmits the ACK byte to the host. After the transmission of the ACK byte, the...
  • Page 25: Figure 16. Extended Erase Memory Command: Host Side

    AN3155 Bootloader command set Figure 16. Extended Erase Memory command: host side Start EER Send 0x44 + 0xBB NACK Wait for ACK or NACK Special Erase ? Send the number of pages to be erased N (on two Send Special Erase cmd:...
  • Page 26: Figure 17. Extended Erase Memory Command: Device Side

    Bootloader command set AN3155 Figure 17. Extended Erase Memory command: device side Start EER Received bytes = 0x44 + 0xBB ? ROP Active ? Send ACK Byte Receive Number of Pages to be erased N (2 bytes) MSB first 0xFFFY received ? Where Y can be [0..F]...
  • Page 27: Write Protect Command

    AN3155 Bootloader command set The host sends the bytes to the STM32F1xxx as follows: Byte 1: 0x44 Byte 2: 0xBB Wait for ACK Bytes 3-4: - Special erase (0xFFFF, 0xFFFE or 0xFFFD) - Number of pages to be erased (N+1 where: 0 ≤ N < Maximum number of pages).
  • Page 28: Figure 18. Write Protect Command: Host Side

    Bootloader command set AN3155 Figure 18. Write Protect command: host side Start WP Send 0x63+0x9C NACK Wait for ACK or NACK Send the number of sectors to be protected (1 byte) Send the sector codes Send checksum NACK Wait for ACK...
  • Page 29: Figure 19. Write Protect Command: Device Side

    AN3155 Bootloader command set Figure 19. 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...
  • Page 30: Write Unprotect Command

    Bootloader command set AN3155 3.11 Write Unprotect command The Write Unprotect command is used to disable the write protection of all the Flash memory sectors. When the bootloader receives the Write Unprotect command, it transmits the ACK byte to the host. After the transmission of the ACK byte, the bootloader disables the write protection of all the Flash memory sectors.
  • Page 31: Readout Protect Command

    AN3155 Bootloader command set Figure 21. Write Unprotect command: device side Start WPUN Received bytes = 0x73+0x8C? ROP active Send ACK byte Remove the protection for the entire Flash memory Send ACK byte Send NACK byte Generate system reset End of WPUN ai14648b 1.
  • Page 32: Figure 22. Readout Protect Command: Host Side

    Bootloader command set AN3155 Figure 22. Readout Protect command: host side Start RDP_PRM Send 0x82+0x7D NACK Wait for ACK or NACK NACK Wait for ACK or NACK End of RDP_PRM ai14649 1. RDP_PRM = Readout Protect. Figure 23. Readout Protect command: device side...
  • Page 33: Readout Unprotect Command

    AN3155 Bootloader command set 3.13 Readout Unprotect command The Readout Unprotect command is used to disable the Flash memory read protection. When the bootloader receives the Readout Unprotect command, it transmits the ACK byte to the host. After the transmission of the ACK byte, the bootloader erases all the Flash memory sectors and it disables the read protection for the entire Flash memory.
  • Page 34: Figure 25. Readout Unprotect Command: Device Side

    Bootloader command set AN3155 Figure 25. Readout Unprotect command: device side 2. RDU_PRM = Readout Unprotect. 34/37 Doc ID 17066 Rev 2...
  • Page 35: Bootloader Protocol Version Evolution

    AN3155 Bootloader protocol version evolution Bootloader protocol version evolution Table 2 lists the bootloader versions. Table 2. Bootloader protocol versions Version Description V2.0 Initial bootloader version. – Update Go command to initialize the main stack pointer – Update Go command to return NACK when jump address is in the Option byte area or System memory area V2.1...
  • Page 36: Revision History

    Revision history AN3155 Revision history Table 3. Document revision history Date Revision Changes 09-Mar-2010 Initial release. Table 1: USART bootloader commands: added Extended Erase command; removed footnote 2 concerning read protection from the Readout Protect command. Communication safety: amended Note Section 3.2: Get...
  • Page 37 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.

Table of Contents