PDF
Documento
LwIP TCP/IP stack demonstration for STM32F2x7 microcontrollers Application Note | Manualzz

Anuncio

Anuncio

October 2011 Doc ID 018698 Rev 2 1/47
AN3384
Application note
LwIP TCP/IP stack demonstration
for STM32F2x7xx microcontrollers
1 Introduction
STM32F2x7xx microcontrollers features a high-quality 10/100 Mbit/s Ethernet peripheral
that supports both the Media Independent Interface (MII) and Reduced Media Independent
Interface (RMII) to interface with the Physical Layer (PHY).
When working with an Ethernet communication interface, a TCP/IP stack is usually used for
communicating over a local or a wide area network.
This application note presents a demonstration package built on top of the lwIP (Lightweight
IP) TCP/IP stack which is an open source stack intended for embedded devices.
This demonstration package contains nine applications running on top of the lwIP stack:
● Applications running in standalone mode (without an RTOS):
– A Web server
– A TFTP server
– A TCP echo client application
– A TCP echo server application
– A UDP echo client application
– A UDP echo server application
● Applications running with the FreeRTOS operating system:
– A Web server based on netconn API
– A Web server based on socket API
– A TCP/UDP echo server application based on netconn API
www.st.com
Contents AN3384
2/47 Doc ID 018698 Rev 2
Contents
1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
2 LwIP stack overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.1 Stack features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.2 Folder organization of the lwIP stack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.3 LwIP API overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.3.1 Raw API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.3.2 Netconn API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.3.3 Socket API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.4 lwIP buffer management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2.4.1 Packet buffer structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2.4.2 API for managing pbufs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.5 Interfacing lwIP to STM32F2x7 Ethernet network interface . . . . . . . . . . . 11
3 STM32F2x7 low level driver overview . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.1 Global Ethernet MAC/DMA functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.1.1 Ethernet MAC/DMA configuration parameters . . . . . . . . . . . . . . . . . . . . 14
3.2 DMA descriptor handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.2.1 DMA descriptors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.2.2 DMA descriptor handling functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
3.3 PHY control functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
3.4 Hardware checksum . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
4 Developing applications with lwIP stack . . . . . . . . . . . . . . . . . . . . . . . . 22
4.1 Developing in standalone mode using the Raw API . . . . . . . . . . . . . . . . . 22
4.1.1 Model of operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
4.1.2 Example of the TCP echo server demo . . . . . . . . . . . . . . . . . . . . . . . . . 23
4.2 Developing with an RTOS using Netconn or Socket API . . . . . . . . . . . . . 26
4.2.1 Model of operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
4.2.2 Example of a TCP echoserver demo using the Netconn API . . . . . . . . 27
4.3 lwIP memory configuration options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
5 Description of the demonstration package . . . . . . . . . . . . . . . . . . . . . 31
AN3384 Contents
Doc ID 018698 Rev 2 3/47
5.1 Package directories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
5.2 Demonstration settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
5.2.1 PHY interface configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
5.2.2 MAC and IP address settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
5.2.3 STM322xG-EVAL settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
6 Using the demos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
6.1 Standalone demos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
6.1.1 Httpserver demo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
6.1.2 TCP echo client demo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
6.1.3 TCP echo server demo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
6.1.4 UDP echo client demo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
6.1.5 UDP echo server demo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
6.1.6 TFTP server demo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
6.2 FreeRTOS demos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
6.2.1 HTTP server netconn demo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
6.2.2 HTTP server socket demo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
6.2.3 UDP TCP echo server netconn demo . . . . . . . . . . . . . . . . . . . . . . . . . . 42
7 Footprint information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
7.1 HTTP server demo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
7.2 HTTP server netconn demo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
8 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
9 Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
List of tables AN3384
4/47 Doc ID 018698 Rev 2
List of tables
Table 1. TCP Raw API functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Table 2. UDP Raw API functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Table 3. Netconn API functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Table 4. Socket API functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Table 5. Pbuf API functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Table 6. ethernet_if.c functions description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Table 7. Global Ethernet MAC/DMA functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Table 8. ETH_InitTypeDef structure MAC configuration parameters . . . . . . . . . . . . . . . . . . . . . . . . 14
Table 9. ETH_InitTypeDef Structure DMA configuration parameters . . . . . . . . . . . . . . . . . . . . . . . . 16
Table 10. DMA descriptor functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Table 11. PHY control functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Table 12. lwIP memory configuration options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Table 13. STM322xG-EVAL jumper configurations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
Table 14. HTTP server demo footprint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Table 15. Httpserver netconn demo footprint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
Table 16. Document revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/

Anuncio

Preparando el documento para imprimir…
0%