ST AN3078 Application note

July 2010 Doc ID 16393 Rev 1 1/10
AN3078
Application note
STM32™ in-application programming
over the I²C bus
Introduction
A key requirement for most Flash-memory-based systems is the ability to update firmware
once the system is installed in the end product. This is referred to as in-application
creating an IAP application.
STM32F10x microcontrollers can run user-specific firmware to perform the IAP of their
embedded Flash memory. This feature allows the use of any type of communication protocol
for the reprogramming process (such as CAN, USART, USB, SPI, I2C, etc.).
This application note describes how to perform in-application programming using the
STM32F10x’s I2C peripheral. As a first step, the Aardvark tool is used as the host sending
the IAP commands to the STM32F10x. As a second step, the host is another STM32F10x
microcontroller that behaves as a bridge between the PC and the target (USB/I2C bridge).
The STM32F10x behaves as an I2C memory that can be programmed, erased and read via
the I2C/ interface.
For further information on the STM32F10x family features, pinout, electrical characteristics,
mechanical data and ordering information, please refer to the STM32F10x datasheets
available from the STMicroelectronics website: www.st.com.
The STM32 firmware libraries are available from www.st.com.
The versions of the Aardvark host adapter used during the development are listed below:
Firmware: Aardvark I2C/SPI Control Center v3.52 -2009.0130
Hardware: Aardvark I2C/SPI v3.0
For further information on the Aardvark host adapter and its software, please refer to its
documentation on www.st.com.
www.st.com
Contents AN3078
2/21 Doc ID 16393 Rev 1
Contents
1 IAP overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.1 Principle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.2 User program conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.3 Global flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.4 IAP commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.4.1 Read command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.4.2 Write command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.4.3 Erase page command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.4.4 Erase User Space memory command . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.4.5 Go To User Code command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2 STM32 IAP over the I
2
C peripheral . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.1 Hardware description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.2 Software description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.2.1 I
2
C packet description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.2.2 IAP I
2
C Read command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.2.3 IAP I
2
C Write command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
2.2.4 IAP I
2
C Erase Page command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
2.2.5 IAP I
2
C Erase User Space Memory command . . . . . . . . . . . . . . . . . . . 12
2.2.6 IAP I
2
C Go To User Code command . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
2.2.7 IAP I
2
C flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3 Sending IAP commands to a target . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
3.1 Sending IAP I
2
C commands using the Aardvark I
2
C host
adapter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
3.1.1 Aardvark I
2
C interface mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
3.1.2 Aardvark I
2
C batch mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3.2 Sending IAP commands using another STM32 device as a
bridge . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.2.1 Principle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.2.2 Hardware description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
3.2.3 Firmware description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
4 IAP timings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
AN3078 Contents
Doc ID 16393 Rev 1 3/21
5 Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
List of tables AN3078
4/21 Doc ID 16393 Rev 1
List of tables
Table 1. IAP timings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Table 2. Document revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
AN3078 List of figures
Doc ID 16393 Rev 1 5/21
List of figures
Figure 1. Flash memory usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Figure 2. Global flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Figure 3. Read command flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Figure 4. Write command flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Figure 5. Erase Page command flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Figure 6. User Space Memory Erase command flowchart. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Figure 7. Go To User Code command flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Figure 8. Hardware connection between the host master and the STM32 I
2
C target . . . . . . . . . . . . 11
Figure 9. Read packet sequence using the I
2
C protocol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Figure 10. Write packet sequence using the I
2
C protocol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Figure 11. Erase Page packet sequence using the I
2
C protocol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Figure 12. Erase User Space Memory packet sequence using the I
2
C protocol . . . . . . . . . . . . . . . . . 12
Figure 13. Go To User Code sequence using the I
2
C protocol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Figure 14. IAP I
2
C flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Figure 15. Configuration of Aardvark I
2
C host adapter in interface modet . . . . . . . . . . . . . . . . . . . . . 14
Figure 16. Read command using the Aardvark I
2
C interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Figure 17. Read command I
2
C transaction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Figure 18. Write command using the Aardvark I
2
C interface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Figure 19. Write command I
2
C transaction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Figure 20. Aardvark I
2
C configuration using the Batch mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Figure 21. IAP I
2
C Read command in batch script . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Figure 22. IAP I
2
C Write command in batch script . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Figure 23. Hardware connection between the PC, the STM32 bridge and the I
2
C
target. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Figure 24. Modified DFU firmware architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
IAP overview AN3078
6/10 Doc ID 16393 Rev 1

1 IAP overview

1.1 Principle

The IAP driver must be programmed from the Flash memory base address via the JTAG or
SWD interface using a development toolchain. This driver uses the I2C to load a file from
the host to the STM32F10x’s internal Flash memory, and then executes it.

1.2 User program conditions

The IAP application is loaded from the Flash memory base address (0x0800 0000) to the
0x0800 0FFF address. The user application therefore has to be loaded from the
0x0800 1000 address to the top Flash memory address.

Figure 1. Flash memory usage

Flash memory
0x0800 0FFF
0x0800 1000
IAP code
Vector table
User code
Vector table
0x0800 0000
To p F l ash memory
address
User space
memory
IAP space
memory
ai17364
AN3078 IAP overview
Doc ID 16393 Rev 1 7/10

1.3 Global flowchart

Figure 2. Global flowchart

A pin connected to a push-button is used to select between jumping to the user application
and executing IAP for reprogramming purposes:
at reset, when the push-button is pressed IAP is executed
otherwise, a jump to the user program is performed

1.4 IAP commands

1.4.1 Read command

The read command is used to read data from the STM32’s Flash memory, starting from any
Flash address in the user space memory.
Start
User button
pressed
Switch to IAP
IAP program
Yes
No
Reset
pressed
Yes
No
Switch to User program
User program
Reset
pressed
Yes
No
ai17365
Loading...
+ 14 hidden pages