ST AN3968 Application note

AN3968

Application note

STM32F407/STM32F417 in-application programming (IAP) over Ethernet

1 Introduction

This application note is intended for developers using the STM32F407/STM32F417 microcontroller. It provides implementation solutions for In-Application Programming (IAP) using the STM32F407/STM32F417 Ethernet communications interface.

Two possible solutions are provided on top of the LwIP TCP/IP stack:

IAP using TFTP (Trivial File Transfer Protocol)

IAP using HTTP (Hypertext Transfer Protocol)

October 2011

Doc ID 022107 Rev 1

1/19

www.st.com

Contents

AN3968

 

 

Contents

1

Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

1

2

IAP overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

5

 

2.1

Theory of operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

5

 

2.2

IAP using the MCU Ethernet interface . . . . . . . . . . . . . . . . . . . . . . . . . . . .

5

2.3Implementing IAP over the Ethernet on the STM32F407/STM32F417 . . . 6

 

2.3.1

IAP method using TFTP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

6

 

2.3.2

IAP method using HTTP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

6

3

IAP using TFTP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

7

3.1 TFTP overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 3.2 Implementing IAP for the STM32F407/STM32F417 using TFTP . . . . . . . . 8 3.3 Using the software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

4

IAP using HTTP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

10

 

4.1

HTTP file upload overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

10

 

4.2

Implementing IAP using HTTP on the STM32F407/STM32F417 . . . . . .

12

 

4.3

Using the software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

14

 

4.4

Known limitations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

14

4.4.1 Extra bytes added to binary file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14

5

Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

15

 

5.1

MAC and IP address settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

15

 

5.2

Jumper settings on the STM324xG-EVAL board . . . . . . . . . . . . . . . . . . .

15

 

5.3

Software file organization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

16

 

5.4

Code size measurements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

16

 

5.5

Building an image for IAP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

17

6

Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

18

2/19

Doc ID 022107 Rev 1

AN3968

List of tables

 

 

List of tables

Table 1. TFTP opcodes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 Table 2. Jumper configurations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 Table 3. File organization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 Table 4. Code size vs. configuration options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 Table 5. Document revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

Doc ID 022107 Rev 1

3/19

List of figures

AN3968

 

 

List of figures

Figure 1. IAP operation flow. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 Figure 2. TFTP packets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 Figure 3. Flowchart of IAP using TFTP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 Figure 4. TFTPD32 dialog box. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 Figure 5. Browser view of the file upload HTML form . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 Figure 6. IE8 HTTP header format. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 Figure 7. Mozilla Firefox HTTP header format. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 Figure 8. Login web page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 Figure 9. File upload done web page. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 Figure 10. Flowchart of IAP using HTTP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

4/19

Doc ID 022107 Rev 1

ST AN3968 Application note

AN3968

IAP overview

 

 

2 IAP overview

2.1Theory of operation

In-Application Programming (IAP) is a means of upgrading firmware in the field using the MCU communication interfaces such as UART, USB, CAN and Ethernet.

When you boot the microcontroller, you can choose to put it in either:

IAP mode in order to execute the IAP code,

normal mode in order to execute the application code.

Both the IAP code and the application code are in the embedded Flash memory of the microcontroller. The IAP code is usually stored in the first pages of the MCU Flash, and the user application code occupies the remaining Flash area.

Figure 1 illustrates the IAP operation flow:

Figure 1. IAP operation flow

-#5#RESET

 

 

.O

%NTERT)!0RMODE

%XECUTEUAPPLICATIONPCODE

)!0!INITIALIZATION

 

)!0!REQUEST

.O

 

9ES

 

2ECEIVEEBINARYYIMAGEMANDG

 

PROGRAM IT INTO USERN&LASH AREA

 

 

-3 6

2.2IAP using the MCU Ethernet interface

When it is available, Ethernet is often the preferred interface for implementing IAP capability in an embedded application. The advantages are:

High speed communication interface (10/100 Mbit/s)

Remote programming through the network (LAN or WAN)

Standardized application protocols such as FTP, TFTP, HTTP on top of the TCP/IP stack that can be used for implementing the IAP

Doc ID 022107 Rev 1

5/19

IAP overview

AN3968

 

 

2.3Implementing IAP over the Ethernet on the STM32F407/STM32F417

This application note describes two solutions that implement IAP for the

STM32F407/STM32F417 using the Ethernet communication peripheral:

IAP using TFTP (Trivial File Transfer Protocol)

IAP using HTTP (Hypertext Transfer Protocol)

Both solutions run on top of the LwIP stack (v1.3.2), which is a light-weight implementation of the TCP/IP protocol suite.

2.3.1IAP method using TFTP

The IAP method using TFTP is widely used in embedded applications that require a firmware upgrade capability (for example, in embedded Linux bootloaders).

TFTP is a simple file transfer protocol that works on top of the UDP transport layer. It is intended to be used in a LAN environment. It is based on a client/server architecture, where a client requests a file transfer (read or write operation) from a file server.

In this case the server only processes write requests from a PC TFTP client, so a simple TFTP server is implemented on top of the LwIP stack.

2.3.2IAP method using HTTP

A firmware upgrade using the HTTP protocol is less common than with TFTP, but it can be a useful solution when remote programming over the Internet is needed. In this case, the TCP transport protocol is needed to ensure optimum operation.

HTTP works on top of TCP, and offers a way of sending a binary file from a Web client (Mozilla Firefox or Microsoft Internet Explorer) using HTML Forms. This is called HTTP Fileupload (RFC 1867).

The following sections of this document provide details about the implementation of both IAP methods, and an explanation of how to use the software.

6/19

Doc ID 022107 Rev 1

Loading...
+ 13 hidden pages