UM1709 User Manual: STM32Cube Ethernet IAP Example
UM1709 User Manual: STM32Cube Ethernet IAP Example
UM1709 User Manual: STM32Cube Ethernet IAP Example
User manual
STM32Cube Ethernet IAP example
Introduction
The In-Application Programming (IAP) is a way to program the flash memory while code
execution from the same flash. It provides the possibility to load an application code using
high speed communication protocols.
This user manual is intended for developers who use STM32Cube firmware on STM32
microcontrollers. It provides a full description of how to implement In-Application
Programming (IAP) using Ethernet communication.
This document is applicable to all STM32 devices featuring an Ethernet peripheral; however
for simplicity reason, the STM32F2x7xx and STM32F4x7/9xx microcontrollers and
STM32CubeF2 and STM32CubeF4 are used as reference platform.
Two possible solutions are provided on top of the LwIP TCP/IP stack:
Note:
February 2015
DocID025701 Rev 2
1/22
www.st.com
Contents
UM1709
Contents
1
STM32Cube overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
IAP overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.1
Theory of operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.2
2.3
2.3.2
TFTP overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.2
3.3
4.2
4.3
Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
5.1
5.2
2.3.1
Application settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
5.1.1
5.1.2
STM324x9I-EVAL settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
5.2.2
STM324xG-EVAL settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
5.2.3
STM322xG-EVAL settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
5.3
5.4
Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Appendix A FAQ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
2/22
DocID025701 Rev 2
UM1709
Contents
A.1
A.2
A.3
Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
DocID025701 Rev 2
3/22
3
List of tables
UM1709
List of tables
Table 1.
Table 2.
Table 3.
Table 4.
Table 5.
Table 6.
4/22
TFTP opcode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
STM324x9I-EVALjumper configurations. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
STM324xG-EVAL jumper configurations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
STM322xG-EVAL jumper configurations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Files organization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Document revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
DocID025701 Rev 2
UM1709
List of figures
List of figures
Figure 1.
Figure 2.
Figure 3.
Figure 4.
Figure 5.
Figure 6.
Figure 7.
Figure 8.
Figure 9.
DocID025701 Rev 2
5/22
5
STM32Cube overview
UM1709
STM32Cube overview
The STMCube initiative was originated by STMicroelectronics to ease developers life by
reducing development efforts, time and cost. STM32Cube covers the STM32 portfolio.
STM32Cube Version 1.x includes:
The STM32CubeMX, a graphical software configuration tool that allows the generation
of C initialization code using graphical wizards.
6/22
DocID025701 Rev 2
UM1709
IAP overview
IAP overview
2.1
Theory 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:
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 2 illustrates the IAP operation flow:
Figure 2. IAP operation flow
0&85HVHW
0&85HVHW
(QWHU,$3
(QWHU,$3
PRGH"
PRGH"
1R
([HFXWHDSSOLFDWLRQ
([HFXWHDSSOLFDWLRQ
FRGH
FRGH
,$3LQLWLDOL]DWLRQ
,$3LQLWLDOL]DWLRQ
1R
,$3UHTXHVW"
,$3UHTXHVW"
5HFHLYHELQDU\LPDJH
5HFHLYHELQDU\LPDJH
DQGSURJUDPLWLQWR
DQGSURJUDPLWLQWR
XVHU)ODVKDUHD
XVHU)ODVKDUHD
069
DocID025701 Rev 2
7/22
21
IAP overview
2.2
UM1709
2.3
Standardized application protocols such as FTP, TFTP, HTTP on top of the TCP/IP
stack that can be used for implementing the IAP
Both solutions run on top of the LwIP stack, which is a light-weight implementation of the
TCP/IP protocol suite.
2.3.1
2.3.2
8/22
DocID025701 Rev 2
UM1709
3.1
TFTP overview
TFTP is a simple file transfer protocol that works on top of UDP. A file transfer is initiated
from a TFTP client, that sends a Read or Write request to a TFTP server. When the server
acknowledges the request, the file data transfer starts. The data is sent in fixed size blocks
(for example in blocks of 512 bytes).
Each transferred data block must be acknowledged by the recipient 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 3 describes the format of the various TFTP packets:
Figure 3. TFTP packets
Operation
0x1
0x2
0x3
Data
0x4
Acknowledgment (ACK)
0x5
Error
DocID025701 Rev 2
9/22
21
3.2
UM1709
7)73VHUYHU
7)73VHUYHU
,QLWLDOL]DWLRQ
,QLWLDOL]DWLRQ
7)73ZULWH
7)73 ZULWH
7)73ZULWH
UHTXHVW"
UHTXHVW"
1R
(UDVHWKHWRWDO
(UDVHWKHWRWDO
XVHU)ODVKDUHD
XVHU)ODVKDUHD
6HQG$FN
6HQG$FN
'DWDSDFNHW
'DWD SDFNHW
'DWDSDFNHW
UHFHLYHG"
U
UHFHLYHG
"
1R
:ULWHGDWDEORFNWR
:ULWHGDWDEORFNWR
)ODVK
)ODVK
6HQG$FN
6HQG$FN
/DVWGDWD
/ W G W
/DVWGDWD
SDFNHW"
S
SDFNHW
"
1R
(QGRIILOH
(QGRIILOH
WUDQVIHU
WUDQVIHU
10/22
DocID025701 Rev 2
069
UM1709
3.3
Make sure the jumper settings in the evaluation board are set correctly (see
Section 5.2)
2.
In the main.h file, uncomment the option #define USE_IAP_TFTP. Also, depending
on your needs, you can uncomment/comment other options such as #define
USE_DHCP or #define USE_LCD.
3.
Recompile the firmware. Using the generated map file, be sure that there is no overlap
between the IAP code area (starting from address 0x0) and the user Flash area starting
from address: USER_FLASH_FIRST_PAGE_ADDRESS defined in main.h.
4.
5.
To enter IAP mode, press and then release the Reset button while keeping the Key
button pressed.
6.
If USE_LCD is defined in main.h file then the LCD screen displays a message indicating
that IAP mode has been entered. Also if DHCP is used (USE_DHCP defined in main.h),
a message is displayed on the LCD screen indicating the success or failure of DHCP IP
address allocation.
7.
After IP address assignment (either static or dynamic address), the user can start the
IAP process.
8.
On the PC side, open the TFTP client (for example TFTPD32), and configure the TFTP
server address (host address in TFTPD32).
9.
Browse for a binary image to load in the STM32F4xx Flash (a binary image is provided
as examples in the /project/binary folder).
10. Start a file write request by clicking the Put button in the TFTPD32 utility.
11. When LCD is enabled, the progress of the IAP operation is shown on the LCD.
12. At the end of IAP operation, you can reset the evaluation board and run the application
that you have just programmed in the STM32F4xx Flash.
Figure 5. TFTPD32 dialog box
DocID025701 Rev 2
11/22
21
UM1709
4.1
Press Browse button to select a binary file to upload, and then the Upload button to send it.
Depending on the file size, the data is sent in consecutive TCP segments to the web server.
Note:
Before sending the file data, the web client sends HTTP header data that contains
information such as the file name and the content length, some of which must be parsed by
the web server.
Web clients do not always have the same HTTP header format. The http web server must
handle these differences.
4.2
12/22
DocID025701 Rev 2
UM1709
Enter a correct User ID and Password (pre-defined in main.h file) and click the Login
button. A file upload web page is then loaded (see Figure 6).
Note:
1.
2.
If the User ID or Password is incorrect, the login web page is reloaded. After a
successful login, browse to select the binary file to be loaded into the STM32 Flash.
3.
Make sure the binary file size does not exceed the total size of the STM32 user Flash
area.
4.
When clicking the Upload button (see Figure 6), a POST request is sent to the server.
At this moment the server starts erasing all the user Flash area and waits for the binary
file raw data. The received data is then written into the user Flash area.
5.
Note that the total length of the data to be received is extracted from the HTTP header
data sent at the beginning of the transfer.
6.
At the end of IAP operation, a web page indicates the success of IAP operation,
displaying a button which allows you to reset the MCU.
Figure 8. File upload done
DocID025701 Rev 2
13/22
21
UM1709
+773VHUYHU,QLWLDOL]DWLRQ
+773VHUYHU,QLWLDOL]DWLRQ
1R
,QGH[SDJH
,QGH[SDJH
UHTXHVW"
UHTXHVW"
,QGH[SDJHVHQWWRZHE
,QGH[SDJHVHQWWRZHE
FOLHQW
FOLHQW
1R
&RUUHFW8VHU,'
&
&RUUHFW8VHU,'
W 8
,'
3:VXEPLWWHG"
3:VXEPLWWHG"
)LOHXSORDGSDJHVHQWWR
)LOHXSORDGSDJHVHQWWR
ZHEFOLHQW
ZHEFOLHQW
+70/3267
+70/3267
UHTXHVWUHFHLYHG
UHTXHVWUHFHLYHG
IRUILOHXSORDG
IRUILOHXSORDG
1R
(UDVHWKHWRWDO)ODVKDUHD
(UDVHWKHWRWDO)ODVKDUHD
5DZGDWD
5DZGDWD
UHFHLYHG"
UHFHLYHG"
1R
:ULWHGDWDLQWRIODVK
:ULWHGDWDLQWRIODVK
PHPRU\
PHPRU\
$OOGDWD
$OOGDWD
UHFHLYHG"
UHFHLYHG"
1R
(QGRIILOHWUDQVIHU
(QGRIILOHWUDQVIHU
069
14/22
DocID025701 Rev 2
UM1709
4.3
Make sure the jumpers on the evaluation board are set correctly (see Section 5.2).
2.
In the main.h file, uncomment the option USE_IAP_HTTP, also depending on your
needs you can uncomment/comment other options like USE_DHCP or USE_LCD.
3.
Recompile the firmware. Using the generated map file, make sure there is no overlap
between the IAP code area (starting from address 0x0) and the user Flash area starting
from address: USER_FLASH_FIRST_PAGE_ADDRESS (defined in main.h).
4.
5.
To enter IAP mode, press then release the Reset button while keeping the Key button
pressed.
6.
If USE_LCD is defined in main.h file then the LCD screen displays a message
indicating that IAP mode has been entered. Also in the case of using DHCP
(USE_DHCP defined in main.h), a message is displayed on the LCD screen indicating
the success or failure of DHCP IP address allocation.
7.
After IP address assignment (either static or dynamic address), the user can start the
IAP process.
8.
Open a web client (Mozilla Firefox or Microsoft Internet Explorer) and enter the STM32
IP address.
9.
A login web page will be shown. In the User ID field enter user and in the Password
field enter stm32 then press the Login button.
10. The fileupload.html web page is then loaded. Browse for a binary image to be loaded
into STM32 Flash then press the Upload button in order to start the IAP process.
11. If LCD is enabled, the progress of the IAP operation is shown on LCD.
12. At the end of the IAP operation, a new web page is loaded indicating the success of the
file upload operation.
13. Press the RESET MCU button to reset the MCU and run the application just
programmed in the STM32F4xx Flash.
Note:
1.
If there is a connection issue when LCD is enabled, an error message displays on the
LCD screen indicating the connection failure.
2.
The software was tested with the following Web clients: Microsoft Internet Explorer 8
and Mozilla Firefox 24.
DocID025701 Rev 2
15/22
21
Environment
UM1709
Environment
5.1
Application settings
5.1.1
Note:
The RMII mode is not supported when using the STM324x9I-EVAL board.
In the RMII mode with STM324xG-EVAL, you have to provide the 50 MHz clock by soldering
a 50 MHz oscillator (ref SM7745HEV-50.0M or equivalent) on the U3 footprint located under
CN3 and also by removing the jumper from JP5. This oscillator is not provided with the
board.
5.1.2
5.2
5.2.1
STM324x9I-EVAL settings
In order to run the software on the STM324x9I-EVAL board, please configure it as shown in
Table 2.
Table 2. STM324x9I-EVALjumper configurations
Jumper
JP6
5.2.2
STM324xG-EVAL settings
In order to run the software on the STM324xG-EVAL board, please configure it as shown in
Table 3.
16/22
DocID025701 Rev 2
UM1709
Environment
Table 3. STM324xG-EVAL jumper configurations
Jumper
5.2.3
JP5
JP6
JP8
STM322xG-EVAL settings
To run the software on the STM322xG-EVAL board, configure it as shown in Table 4.
Table 4. STM322xG-EVAL jumper configurations
Jumper
5.3
JP5
Not fitted
JP6
JP8
Note:
Description
main.c
main.h
httpserver.c /.h
tftpserver.c /.h
flash_if.c /.h
stm32f4xx_it.c /.h
Interrupt handler
fsdata.c
lwipopts.h
ethernetif.c/.h
stm32f4xx_hal_conf
The table does not show files used from the STM32Cube HAL and BSP libraries and the
LwIP stack.
DocID025701 Rev 2
17/22
21
Environment
5.4
UM1709
18/22
1.
The firmware is compiled and linked to run starting from the start address of the user
Flash area (this address should be the same address as the one defined by
USER_FLASH_FIRST_PAGE_ADDRESS in main.h).
2.
The vector table start address is configured as the start address of the user Flash area.
The vector table base offset is configured by modifying the value of the constant
VECT_TAB_OFFSET defined in system_stm32f4xx.c file. For example, to set the
vector table base location at 0x08020000: #define VECT_TAB_OFFSET 0x20000
3.
The compiled software size does not exceed the total user Flash area.
DocID025701 Rev 2
UM1709
Conclusion
Conclusion
The aim of this user manual is to explain the Ethernet In-Application Programming (IAP)
using the STM32Cube HAL drivers for the STM32F4xx microcontrollers.
Two solutions are provided to support HTTP and TFTP protocols; both of them are based on
the LwIP stack as a middleware component for TCP/IP communication.
DocID025701 Rev 2
19/22
21
FAQ
UM1709
Appendix A
A.1
FAQ
A.2
A.3
20/22
DocID025701 Rev 2
UM1709
Revision history
Revision history
Table 6. Document revision history
Date
Revision
Changes
28-Mar-2014
Initial release
05-Feb-2015
DocID025701 Rev 2
21/22
21
UM1709
22/22
DocID025701 Rev 2