Skip to content

Commit 735fd68

Browse files
committed
[examples] Add Ethernet (FreeRTOS+TCP) example on Nucleo-F429ZI
1 parent 97d2161 commit 735fd68

File tree

3 files changed

+538
-0
lines changed

3 files changed

+538
-0
lines changed
Lines changed: 271 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,271 @@
1+
/*
2+
* FreeRTOS+TCP V2.2.1
3+
* Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4+
*
5+
* Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
* this software and associated documentation files (the "Software"), to deal in
7+
* the Software without restriction, including without limitation the rights to
8+
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9+
* the Software, and to permit persons to whom the Software is furnished to do so,
10+
* subject to the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be included in all
13+
* copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17+
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18+
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19+
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21+
*
22+
* http://www.FreeRTOS.org
23+
* http://aws.amazon.com/freertos
24+
*
25+
* 1 tab == 4 spaces!
26+
*/
27+
28+
#ifndef FREERTOS_IP_CONFIG_H
29+
# error "Don't include this file, use 'FreeRTOSIPConfig.h' instead!"
30+
#endif
31+
32+
/* Set to 1 to print out debug messages. If ipconfigHAS_DEBUG_PRINTF is set to
33+
1 then FreeRTOS_debug_printf should be defined to the function used to print
34+
out the debugging messages. */
35+
#define ipconfigHAS_DEBUG_PRINTF 0
36+
37+
/* Set to 1 to print out non debugging messages, for example the output of the
38+
FreeRTOS_netstat() command, and ping replies. If ipconfigHAS_PRINTF is set to 1
39+
then FreeRTOS_printf should be set to the function used to print out the
40+
messages. */
41+
#define ipconfigHAS_PRINTF 0
42+
43+
/* If the network card/driver includes checksum offloading (IP/TCP/UDP checksums)
44+
then set ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM to 1 to prevent the software
45+
stack repeating the checksum calculations. */
46+
#define ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM 1
47+
#define ipconfigDRIVER_INCLUDED_TX_IP_CHECKSUM 1
48+
49+
/* Several API's will block until the result is known, or the action has been
50+
performed, for example FreeRTOS_send() and FreeRTOS_recv(). The timeouts can be
51+
set per socket, using setsockopt(). If not set, the times below will be
52+
used as defaults. */
53+
#define ipconfigSOCK_DEFAULT_RECEIVE_BLOCK_TIME ( 5000 )
54+
#define ipconfigSOCK_DEFAULT_SEND_BLOCK_TIME ( 5000 )
55+
56+
/* Include support for LLMNR: Link-local Multicast Name Resolution
57+
(non-Microsoft) */
58+
#define ipconfigUSE_LLMNR ( 0 )
59+
60+
/* Include support for NBNS: NetBIOS Name Service (Microsoft) */
61+
#define ipconfigUSE_NBNS ( 0 )
62+
63+
/* Include support for DNS caching. For TCP, having a small DNS cache is very
64+
useful. When a cache is present, ipconfigDNS_REQUEST_ATTEMPTS can be kept low
65+
and also DNS may use small timeouts. If a DNS reply comes in after the DNS
66+
socket has been destroyed, the result will be stored into the cache. The next
67+
call to FreeRTOS_gethostbyname() will return immediately, without even creating
68+
a socket. */
69+
#define ipconfigUSE_DNS_CACHE ( 1 )
70+
#define ipconfigDNS_CACHE_NAME_LENGTH ( 16 )
71+
#define ipconfigDNS_CACHE_ENTRIES ( 4 )
72+
#define ipconfigDNS_REQUEST_ATTEMPTS ( 2 )
73+
74+
/* ipconfigRAND32() is called by the IP stack to generate random numbers for
75+
things such as a DHCP transaction number or initial sequence number. Random
76+
number generation is performed via this macro to allow applications to use their
77+
own random number generation method. For example, it might be possible to
78+
generate a random number by sampling noise on an analogue input. */
79+
extern UBaseType_t uxRand(void);
80+
#define ipconfigRAND32() uxRand()
81+
82+
/* If ipconfigUSE_NETWORK_EVENT_HOOK is set to 1 then FreeRTOS+TCP will call the
83+
network event hook at the appropriate times. If ipconfigUSE_NETWORK_EVENT_HOOK
84+
is not set to 1 then the network event hook will never be called. See
85+
http://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_UDP/API/vApplicationIPNetworkEventHook.shtml
86+
*/
87+
#define ipconfigUSE_NETWORK_EVENT_HOOK 1
88+
89+
/* Sockets have a send block time attribute. If FreeRTOS_sendto() is called but
90+
a network buffer cannot be obtained then the calling task is held in the Blocked
91+
state (so other tasks can continue to executed) until either a network buffer
92+
becomes available or the send block time expires. If the send block time expires
93+
then the send operation is aborted. The maximum allowable send block time is
94+
capped to the value set by ipconfigMAX_SEND_BLOCK_TIME_TICKS. Capping the
95+
maximum allowable send block time prevents prevents a deadlock occurring when
96+
all the network buffers are in use and the tasks that process (and subsequently
97+
free) the network buffers are themselves blocked waiting for a network buffer.
98+
ipconfigMAX_SEND_BLOCK_TIME_TICKS is specified in RTOS ticks. A time in
99+
milliseconds can be converted to a time in ticks by dividing the time in
100+
milliseconds by portTICK_PERIOD_MS. */
101+
#define ipconfigUDP_MAX_SEND_BLOCK_TIME_TICKS ( 5000 / portTICK_PERIOD_MS )
102+
103+
/* If ipconfigUSE_DHCP is 1 then FreeRTOS+TCP will attempt to retrieve an IP
104+
address, netmask, DNS server address and gateway address from a DHCP server. If
105+
ipconfigUSE_DHCP is 0 then FreeRTOS+TCP will use a static IP address. The
106+
stack will revert to using the static IP address even when ipconfigUSE_DHCP is
107+
set to 1 if a valid configuration cannot be obtained from a DHCP server for any
108+
reason. The static configuration used is that passed into the stack by the
109+
FreeRTOS_IPInit() function call. */
110+
#define ipconfigUSE_DHCP 0
111+
112+
/* When ipconfigUSE_DHCP is set to 1, DHCP requests will be sent out at
113+
increasing time intervals until either a reply is received from a DHCP server
114+
and accepted, or the interval between transmissions reaches
115+
ipconfigMAXIMUM_DISCOVER_TX_PERIOD. The IP stack will revert to using the
116+
static IP address passed as a parameter to FreeRTOS_IPInit() if the
117+
re-transmission time interval reaches ipconfigMAXIMUM_DISCOVER_TX_PERIOD without
118+
a DHCP reply being received. */
119+
#define ipconfigMAXIMUM_DISCOVER_TX_PERIOD ( 120000 / portTICK_PERIOD_MS )
120+
121+
/* The ARP cache is a table that maps IP addresses to MAC addresses. The IP
122+
stack can only send a UDP message to a remove IP address if it knowns the MAC
123+
address associated with the IP address, or the MAC address of the router used to
124+
contact the remote IP address. When a UDP message is received from a remote IP
125+
address the MAC address and IP address are added to the ARP cache. When a UDP
126+
message is sent to a remote IP address that does not already appear in the ARP
127+
cache then the UDP message is replaced by a ARP message that solicits the
128+
required MAC address information. ipconfigARP_CACHE_ENTRIES defines the maximum
129+
number of entries that can exist in the ARP table at any one time. */
130+
#define ipconfigARP_CACHE_ENTRIES 6
131+
132+
/* ARP requests that do not result in an ARP response will be re-transmitted a
133+
maximum of ipconfigMAX_ARP_RETRANSMISSIONS times before the ARP request is
134+
aborted. */
135+
#define ipconfigMAX_ARP_RETRANSMISSIONS ( 5 )
136+
137+
/* ipconfigMAX_ARP_AGE defines the maximum time between an entry in the ARP
138+
table being created or refreshed and the entry being removed because it is stale.
139+
New ARP requests are sent for ARP cache entries that are nearing their maximum
140+
age. ipconfigMAX_ARP_AGE is specified in tens of seconds, so a value of 150 is
141+
equal to 1500 seconds (or 25 minutes). */
142+
#define ipconfigMAX_ARP_AGE 150
143+
144+
/* Implementing FreeRTOS_inet_addr() necessitates the use of string handling
145+
routines, which are relatively large. To save code space the full
146+
FreeRTOS_inet_addr() implementation is made optional, and a smaller and faster
147+
alternative called FreeRTOS_inet_addr_quick() is provided. FreeRTOS_inet_addr()
148+
takes an IP in decimal dot format (for example, "192.168.0.1") as its parameter.
149+
FreeRTOS_inet_addr_quick() takes an IP address as four separate numerical octets
150+
(for example, 192, 168, 0, 1) as its parameters. If
151+
ipconfigINCLUDE_FULL_INET_ADDR is set to 1 then both FreeRTOS_inet_addr() and
152+
FreeRTOS_indet_addr_quick() are available. If ipconfigINCLUDE_FULL_INET_ADDR is
153+
not set to 1 then only FreeRTOS_indet_addr_quick() is available. */
154+
#define ipconfigINCLUDE_FULL_INET_ADDR 1
155+
156+
/* ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS defines the total number of network buffer that
157+
are available to the IP stack. The total number of network buffers is limited
158+
to ensure the total amount of RAM that can be consumed by the IP stack is capped
159+
to a pre-determinable value. */
160+
#define ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS 60
161+
162+
/* A FreeRTOS queue is used to send events from application tasks to the IP
163+
stack. ipconfigEVENT_QUEUE_LENGTH sets the maximum number of events that can
164+
be queued for processing at any one time. The event queue must be a minimum of
165+
5 greater than the total number of network buffers. */
166+
#define ipconfigEVENT_QUEUE_LENGTH ( ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS + 5 )
167+
168+
/* The address of a socket is the combination of its IP address and its port
169+
number. FreeRTOS_bind() is used to manually allocate a port number to a socket
170+
(to 'bind' the socket to a port), but manual binding is not normally necessary
171+
for client sockets (those sockets that initiate outgoing connections rather than
172+
wait for incoming connections on a known port number). If
173+
ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND is set to 1 then calling
174+
FreeRTOS_sendto() on a socket that has not yet been bound will result in the IP
175+
stack automatically binding the socket to a port number from the range
176+
socketAUTO_PORT_ALLOCATION_START_NUMBER to 0xffff. If
177+
ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND is set to 0 then calling FreeRTOS_sendto()
178+
on a socket that has not yet been bound will result in the send operation being
179+
aborted. */
180+
#define ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND 1
181+
182+
/* Defines the Time To Live (TTL) values used in outgoing UDP packets. */
183+
#define ipconfigUDP_TIME_TO_LIVE 128
184+
#define ipconfigTCP_TIME_TO_LIVE 128 /* also defined in FreeRTOSIPConfigDefaults.h */
185+
186+
/* USE_TCP: Use TCP and all its features */
187+
#define ipconfigUSE_TCP ( 1 )
188+
189+
/* USE_WIN: Let TCP use windowing mechanism. */
190+
#define ipconfigUSE_TCP_WIN ( 1 )
191+
192+
/* The MTU is the maximum number of bytes the payload of a network frame can
193+
contain. For normal Ethernet V2 frames the maximum MTU is 1500. Setting a
194+
lower value can save RAM, depending on the buffer management scheme used. If
195+
ipconfigCAN_FRAGMENT_OUTGOING_PACKETS is 1 then (ipconfigNETWORK_MTU - 28) must
196+
be divisible by 8. */
197+
#define ipconfigNETWORK_MTU 1500
198+
199+
/* Set ipconfigUSE_DNS to 1 to include a basic DNS client/resolver. DNS is used
200+
through the FreeRTOS_gethostbyname() API function. */
201+
#define ipconfigUSE_DNS 0
202+
203+
/* If ipconfigREPLY_TO_INCOMING_PINGS is set to 1 then the IP stack will
204+
generate replies to incoming ICMP echo (ping) requests. */
205+
#define ipconfigREPLY_TO_INCOMING_PINGS 1
206+
207+
/* If ipconfigSUPPORT_OUTGOING_PINGS is set to 1 then the
208+
FreeRTOS_SendPingRequest() API function is available. */
209+
#define ipconfigSUPPORT_OUTGOING_PINGS 0
210+
211+
/* If ipconfigSUPPORT_SELECT_FUNCTION is set to 1 then the FreeRTOS_select()
212+
(and associated) API function is available. */
213+
#define ipconfigSUPPORT_SELECT_FUNCTION 1
214+
215+
/* If ipconfigFILTER_OUT_NON_ETHERNET_II_FRAMES is set to 1 then Ethernet frames
216+
that are not in Ethernet II format will be dropped. This option is included for
217+
potential future IP stack developments. */
218+
#define ipconfigFILTER_OUT_NON_ETHERNET_II_FRAMES 1
219+
220+
/* If ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES is set to 1 then it is the
221+
responsibility of the Ethernet interface to filter out packets that are of no
222+
interest. If the Ethernet interface does not implement this functionality, then
223+
set ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES to 0 to have the IP stack
224+
perform the filtering instead (it is much less efficient for the stack to do it
225+
because the packet will already have been passed into the stack). If the
226+
Ethernet driver does all the necessary filtering in hardware then software
227+
filtering can be removed by using a value other than 1 or 0. */
228+
#define ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES 1
229+
230+
/* The windows simulator cannot really simulate MAC interrupts, and needs to
231+
block occasionally to allow other tasks to run. */
232+
#define configWINDOWS_MAC_INTERRUPT_SIMULATOR_DELAY ( 20 / portTICK_PERIOD_MS )
233+
234+
/* Advanced only: in order to access 32-bit fields in the IP packets with
235+
32-bit memory instructions, all packets will be stored 32-bit-aligned, plus 16-bits.
236+
This has to do with the contents of the IP-packets: all 32-bit fields are
237+
32-bit-aligned, plus 16-bit(!) */
238+
#define ipconfigPACKET_FILLER_SIZE 2
239+
240+
/* Define the size of the pool of TCP window descriptors. On the average, each
241+
TCP socket will use up to 2 x 6 descriptors, meaning that it can have 2 x 6
242+
outstanding packets (for Rx and Tx). When using up to 10 TP sockets
243+
simultaneously, one could define TCP_WIN_SEG_COUNT as 120. */
244+
#define ipconfigTCP_WIN_SEG_COUNT 240
245+
246+
/* Each TCP socket has a circular buffers for Rx and Tx, which have a fixed
247+
maximum size. Define the size of Rx buffer for TCP sockets. */
248+
#define ipconfigTCP_RX_BUFFER_LENGTH ( 2000 )
249+
250+
/* Define the size of Tx buffer for TCP sockets. */
251+
#define ipconfigTCP_TX_BUFFER_LENGTH ( 2000 )
252+
253+
/* When using call-back handlers, the driver may check if the handler points to
254+
real program memory (RAM or flash) or just has a random non-zero value. */
255+
#define ipconfigIS_VALID_PROG_ADDRESS(x) ( (x) != NULL )
256+
257+
/* Include support for TCP hang protection. All sockets in a connecting or
258+
disconnecting stage will timeout after a period of non-activity. */
259+
#define ipconfigTCP_HANG_PROTECTION ( 1 )
260+
#define ipconfigTCP_HANG_PROTECTION_TIME ( 30 )
261+
262+
/* Include support for TCP keep-alive messages. */
263+
#define ipconfigTCP_KEEP_ALIVE ( 1 )
264+
#define ipconfigTCP_KEEP_ALIVE_INTERVAL ( 20 ) /* in seconds */
265+
266+
#define ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES 1
267+
#define ipconfigDRIVER_INCLUDED_TX_IP_CHECKSUM 1
268+
#define ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM 1
269+
#define ipconfigZERO_COPY_RX_DRIVER 1
270+
#define ipconfigZERO_COPY_TX_DRIVER 1
271+
#define ipconfigUSE_LINKED_RX_MESSAGES 1

0 commit comments

Comments
 (0)