STM32F107 In-Application Programming (IAP) over Ethernet
Introduction
This application note is intended for developers using the STM32F107 microcontroller. It
provides implementation solutions for In-Application Programming (IAP) using the
STM32F107 Ethernet communications interface.
Two possible solutions are provided on top of the LwIP TCP/IP stack:
In-Application Programming (IAP) is a means of upgrading firmware in the field using the
MCU communication interfaces like UART, USB, CAN, Ethernet,etc...
When you boot the microcontroller, you can choose to put it in IAP mode in order to execute
the IAP code or else, in normal mode, start to execute the application code. Both the IAP
code and the application code are reside in the embedded Flash memory of the
microcontroller. Usually the IAP code is stored in the first pages of the MCU Flash, and the
user application code occupies the remaining Flash area.
The IAP operation flow is described in the following figure:
Figure 1.IAP operation flow
1.2 IAP using the MCU’s 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/100Mbit/s)
●Remote programming through the network (LAN or WAN)
●Standardized application protocols on top of the TCP/IP stack that can be used for
implementing the IAP like: FTP, TFTP, HTTP,...
Doc ID 17570 Rev 13/18
IAP overviewAN3226
1.3 Implementing IAP over Ethernet on the STM32F107
This application note describes two solutions that implement IAP for the STM32F107 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.1) which is a light-weight implementation of
the TCP/IP protocol suite.
1.3.1 IAP 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 working on top of the UDP transport layer and it is
mainly intended to be used on a LAN environment. It is based on a client/server
architecture, where a client will request a file transfer (read or write operation) from a file
server.
In our case, a simple TFTP server is implemented on top of the LwIP stack, this server only
processes write requests coming from a PC TFTP client.
1.3.2 IAP method using HTTP
Firmware upgrade through HTTP protocol is less common than with TFTP, but it can be an
useful solution, when remote programming over the Internet is needed. In this case TCP
transport protocol is needed to ensure optimum operation.
HTTP which works on top of TCP, offers a way of sending a binary file from a web client
(example: Mozilla Firefox or Microsoft Internet Explorer) using HTML Forms, it is called
HTTP File-upload (RFC 1867).
The next sections of this document, give more details about the implementation of both IAP
methods and an explanation of how to use the software.
4/18Doc ID 17570 Rev 1
AN3226IAP using TFTP
2 bytesString1 byteString1 byte
OpcodeFile name0Mode0
Opcode Block#Data
2 bytes 2 bytesn bytes
2 bytes 2 bytes
Opcode Block#
2 bytes 2 bytesString1 byte
Opcode
Error
code
Error
message
0
RRQ/WRQ packet
Data packet
ACK packet
Error packet
2 IAP using TFTP
2.1 TFTP overview
Trivial File Transfer Protocol (TFTP) is a simple file transfer protocol, working on top of UDP.
A file transfer is initiated from a TFTP client which sends a Read or Write request to a TFTP
server.
When the server acknowledges the request, file data transfers start. The data is sent in fixed
size blocks (for example in blocks of 512 bytes).
Each transferred data block must be acknowledged by the recepient, before the next block
can be sent. The acknowledge mechanism is based on the block number sent with each
data block.
A data block with less than the fixed block size indicates the termination of the file transfer.
Figure 2 describes the format of the various TFTP packets:
Figure 2.TFTP packets
The TFTP opcodes are listed in Tab le 1 .
Table 1.TFTP opcodes
OpcodeOperation
0x1Read request (RRQ)
0x2Write request (WRQ)
0x3Data
0x4Acknowledgment (ACK)
0x5Error
Doc ID 17570 Rev 15/18
IAP using TFTPAN3226
2.2 Implementing IAP for the STM32F107 using TFTP
This IAP implementation consists of a basic TFTP server on top of the LwIP TCP/IP stack.
This server responds to file WRITE requests received from a remote TFTP client (PC).
TFTP READ requests are ignored.
Instead of writing received files to a filesystem which is normally what TFTP is used for, the
server writes the received data blocks into the MCU Flash (in the user Flash area).
Note:In this implementation, the data block size is fixed to 512 bytes.
The following flowchart gives an overview of the IAP operation using TFTP.
6/18Doc ID 17570 Rev 1
Loading...
+ 12 hidden pages
You need points to download manuals.
1 point = 1 manual.
You can buy points or you can get point for every manual you upload.