Example: confidence

AN3155 Application note - STMicroelectronics

February 2022AN3155 Rev 151/481AN3155 Application noteUSART protocol used in the STM32 bootloader IntroductionThis Application note describes the USART protocol used in the STM32 microcontroller bootloader, providing details on each supported document applies to STM32 products embedding any bootloader version, as specified in Application note AN2606 STM32 system memory boot mode, available on These products are listed in Ta b l e 1, and are referred to as STM32 throughout the more information about the USART hardware resources and requirements for your device bootloader, refer to the already mentioned AN2606.

The Get command allows the user 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 shown in . Figure 2. Figure 2. Get command: host side. Send 0x00 + 0xFF Start Get Wait for ACK or NACK Receive the ...

Tags:

  Supported, Command, Supported commands

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

Transcription of AN3155 Application note - STMicroelectronics

1 February 2022AN3155 Rev 151/481AN3155 Application noteUSART protocol used in the STM32 bootloader IntroductionThis Application note describes the USART protocol used in the STM32 microcontroller bootloader, providing details on each supported document applies to STM32 products embedding any bootloader version, as specified in Application note AN2606 STM32 system memory boot mode, available on These products are listed in Ta b l e 1, and are referred to as STM32 throughout the more information about the USART hardware resources and requirements for your device bootloader, refer to the already mentioned AN2606.

2 Table 1. Applicable productsTypeProduct seriesMicrocontrollersSTM32F0 SeriesSTM32F1 SeriesSTM32F2 SeriesSTM32F3 SeriesSTM32F4 SeriesSTM32F7 SeriesSTM32G0 SeriesSTM32G4 SeriesSTM32H7 SeriesSTM32L0 SeriesSTM32L1 SeriesSTM32L4 SeriesSTM32L5 SeriesSTM32U5 SeriesSTM32WB SeriesSTM32WL Rev 15 Contents1 USART bootloader code sequence .. 52 Choosing the USARTx baud rate .. baud rate .. baud rate .. 63 Bootloader command set .. command .. Version & Read Protection Status command .. ID command .. Memory command .

3 command .. Memory command .. Memory command .. Erase Memory command .. Protect command .. Unprotect command .. Protect command .. Unprotect command .. Checksum command .. command .. Special command .. 414 Bootloader protocol version evolution .. 455 Revision history .. 46AN3155 Rev 153/48AN3155 List of tables3 List of tablesTable products .. 1 Table bootloader commands .. 7 Table protocol versions .. 45 Table revision history .. 46 List of figuresAN31554/48AN3155 Rev 15 List of figuresFigure for STM32 with USART.

4 5 Figure command : host side .. 8 Figure command : device side .. 9 Figure Version & Read Protection Status command : host side .. 10 Figure Version & Read Protection Status command : device side.. 11 Figure ID command : host side .. 12 Figure ID command : device side.. 13 Figure Memory command : host side .. 14 Figure Memory command : device side .. 15 Figure command : host side .. 16 Figure command : device side .. 17 Figure Memory command : host side .. 19 Figure Memory command : device side.. 20 Figure Memory command : host side.

5 22 Figure Memory command : device side .. 23 Figure Erase Memory command : host side .. 25 Figure Erase Memory command : device side .. 26 Figure Protect command : host side .. 28 Figure Protect command : device side .. 29 Figure Unprotect command : host side .. 30 Figure Unprotect command : device side .. 31 Figure Protect command : host side.. 32 Figure Protect command : device side .. 32 Figure Unprotect command : host side .. 33 Figure Unprotect command : device side .. 34 Figure Checksum command : host side .. 37 Figure Checksum command : device side.

6 38 Figure command : host side .. 39 Figure command : device side .. 40 Figure Special command : host side.. 42 Figure Special command : device side .. 43AN3155 Rev 155/48AN3155 USART bootloader code sequence471 USART bootloader code sequenceFigure 1. Bootloader for STM32 with USARTOnce the system memory boot mode is entered and the STM32 microcontroller (based on Arm (a) cores) has been configured (for more details refer to AN2606) the bootloader code begins to scan the USARTx_RX line pin, waiting to receive the 0x7F data frame: a start bit, 0x7F data bits, even parity bit and a stop on the USART IP, the baudrate detection is based on the HW (IP supporting auto baudrate) or on the SW.

7 The following paragraphs explain the SW detection duration of this data frame is measured using the Systick timer. The count value of the timer is then used to calculate the corresponding baud rate factor with respect to the current system , 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 STM32 is ready to receive Arm is a registered trademark of Arm Limited (or its subsidiaries) in the US and/or received onUSARTx Rx pinWait for acommandGET cmdroutineai15702 USARTx selectedAuto-baud rate sequencesend ACK byte & disableunused peripheralsRD cmdroutine(optional)

8 Routines forloading into RAMGO cmdroutineJP to_AddressGO cmdCommandreceivedGET cmdChoosing the USARTx baud rateAN31556/48AN3155 Rev 152 Choosing the USARTx baud rateThe calculation of the serial baud rate for USARTx, from the length of the first received byte, is used to operate the bootloader within a wide range of baud rates. However, the upper and lower limits have to be kept, to ensure proper data a correct data transfer from the host to the microcontroller, the maximum deviation between the internal initialized baud rate for USARTx and the real baud rate of the host must be below The deviation (fB, in percent) between the host baud rate and the microcontroller baud rate can be calculated using the formula below.

9 FBSTM32 baud rate Host baud rate STM32 baud rate------------------------------------ ---------------------------------------- ---------------100% =, where fB This baud rate deviation is a nonlinear function, depending upon the CPU clock and the baud rate of the host. The maximum of the function (fB) increases with the host baud rate. This is due to the smaller baud rate prescale factors, and the implied higher quantization Minimum baud rateThe lowest tested baud rate (BLow) is 1200. Baud rates below BLow cause SysTick timer overflow.

10 In this event, USARTx is not correctly Maximum baud rateBHigh is the highest baud rate for which the deviation does not exceed the limit. All baud rates between BLow and BHigh are below the deviation highest tested baud rate (BHigh) is Rev 157/48AN3155 Bootloader command set473 Bootloader command setThe supported commands are listed in Ta b l e 2. Each command is described in this section. Communication safetyAll communication from the programming tool (PC) to the device is verified : received blocks of data bytes are XOR-ed.


Related search queries