
AN2662
USART bootloader
Doc ID 14156 Rev 1
2 USART
bootloader
2.1
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.
The 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 clock.
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.
2.2
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.
For 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
should be below 2.5%. The deviation (f
B
, in percent) between the host baud rate and the
X&RECEIVEDON
53!24X2XPIN
7AITFORA
COMMAND
'%4CMD
ROUTINE
AI
53!24XSELECTED
!UTOBAUDRATESEQUENCE
SEND!#+BYTEDISABLE
UNUSEDPERIPHERALS
2$CMD
ROUTINE
OPTIONAL
2OUTINESFOR
LOADING
INTO2!-
'/CMD
ROUTINE
*0TO?!DDRESS
'/CMD
#OMMAND
RECEIVED
'%4CMD