Skip to content

Commit 59d0a61

Browse files
authored
Merge pull request #52 from fprwi6labs/Ethernet_F4
Ethernet f4 All provided example tested and ok.
2 parents 03fe9fd + cc913eb commit 59d0a61

File tree

10 files changed

+383
-17
lines changed

10 files changed

+383
-17
lines changed

Diff for: cores/arduino/chip.h

+2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
#include "usb_interface.h"
3939
#endif //USBCON
4040

41+
#include "ethernet.h"
42+
4143
/* Define attribute */
4244
#if defined ( __GNUC__ ) /* GCC CS3 */
4345
#define WEAK __attribute__ ((weak))

Diff for: cores/arduino/main.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ int main( void )
4747

4848
for (;;)
4949
{
50+
// Define by Ethernet library. It is defined as __weak.
51+
stm32_eth_scheduler();
52+
5053
loop();
5154
if (serialEventRun) serialEventRun();
5255
}

Diff for: cores/arduino/stm32/PeripheralPins.h

+3
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,8 @@ extern const PinMap PinMap_SPI_SSEL[];
6262
extern const PinMap PinMap_CAN_RD[];
6363
extern const PinMap PinMap_CAN_TD[];
6464

65+
//*** ETHERNET ***
66+
extern const PinMap PinMap_Ethernet[];
67+
6568
#endif
6669

Diff for: cores/arduino/stm32/ethernet.h

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/**
2+
******************************************************************************
3+
* @file ethernet.h
4+
* @author WI6LABS
5+
* @version V1.0.0
6+
* @date 14-June-2017
7+
* @brief Header for ethernet background task for LwIP stack.
8+
******************************************************************************
9+
* @attention
10+
*
11+
* <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
12+
*
13+
* Redistribution and use in source and binary forms, with or without modification,
14+
* are permitted provided that the following conditions are met:
15+
* 1. Redistributions of source code must retain the above copyright notice,
16+
* this list of conditions and the following disclaimer.
17+
* 2. Redistributions in binary form must reproduce the above copyright notice,
18+
* this list of conditions and the following disclaimer in the documentation
19+
* and/or other materials provided with the distribution.
20+
* 3. Neither the name of STMicroelectronics nor the names of its contributors
21+
* may be used to endorse or promote products derived from this software
22+
* without specific prior written permission.
23+
*
24+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
28+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34+
*
35+
******************************************************************************
36+
*/
37+
38+
/* Define to prevent recursive inclusion -------------------------------------*/
39+
#ifndef __ETHERNET_H
40+
#define __ETHERNET_H
41+
42+
/* Includes ------------------------------------------------------------------*/
43+
#ifdef __cplusplus
44+
extern "C" {
45+
#endif
46+
47+
/* Exported types ------------------------------------------------------------*/
48+
/* Exported constants --------------------------------------------------------*/
49+
/* Exported macro ------------------------------------------------------------*/
50+
/* Exported functions ------------------------------------------------------- */
51+
52+
/* This function is defined by the NativeEthernet library and it is used as
53+
background task inside the main loop. */
54+
__weak void stm32_eth_scheduler(void)
55+
{
56+
/* NOTE : This function should not be modified. It is defined in the Ethernet
57+
library.
58+
*/
59+
}
60+
61+
void stm32_eth_scheduler(void);
62+
63+
#ifdef __cplusplus
64+
}
65+
#endif
66+
67+
#endif /* __ETHERNET_H */
68+
69+
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

Diff for: cores/arduino/stm32/pinmap.c

+8
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,11 @@ void* pinmap_merge_peripheral(void* a, void* b) {
8282
// error("pinmap mis-match");
8383
return NP;
8484
}
85+
86+
PinName pin_pinName(const PinMap* map) {
87+
if(map->pin != (PinName)NC) {
88+
return map->pin;
89+
} else {
90+
return (PinName)NC;
91+
}
92+
}

Diff for: cores/arduino/stm32/pinmap.h

+2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ typedef struct {
3939
bool pin_in_pinmap(PinName pin, const PinMap* map);
4040
void pin_function(PinName pin, int function);
4141

42+
PinName pin_pinName(const PinMap* map);
43+
4244
void* pinmap_peripheral(PinName pin, const PinMap* map);
4345
uint32_t pinmap_function(PinName pin, const PinMap* map);
4446
void* pinmap_find_peripheral(PinName pin, const PinMap* map);

Diff for: platform.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ version=1.0.0
1010

1111
# STM compile variables
1212
# ----------------------
13-
compiler.stm.extra_include="-I{build.core.path}/avr" "-I{build.core.path}/stm32" "-I{build.system.path}/Drivers/{build.series}_HAL_Driver/Inc/" "-I{build.system.path}/Drivers/{build.series}_HAL_Driver/Src/" "-I{build.system.path}/{build.series}/" "-I{build.variant.path}/usb" "-I{build.system.path}/Middlewares/ST/STM32_USB_Device_Library/Core/Inc" "-I{build.system.path}/Middlewares/ST/STM32_USB_Device_Library/Core/Src"
13+
compiler.stm.extra_include="-I{build.core.path}/avr" "-I{build.core.path}/stm32" "-I{build.system.path}/Drivers/{build.series}_HAL_Driver/Inc/" "-I{build.system.path}/Drivers/{build.series}_HAL_Driver/Src/" "-I{build.system.path}/{build.series}/" "-I{build.variant.path}/usb" "-I{build.variant.path}/Ethernet" "-I{build.system.path}/Middlewares/ST/STM32_USB_Device_Library/Core/Inc" "-I{build.system.path}/Middlewares/ST/STM32_USB_Device_Library/Core/Src"
1414

1515
# "-I{build.system.path}/Drivers/BSP/Components" "-I{build.system.path}/Middlewares/Third_Party/FatFs/src" "-I{build.system.path}/Middlewares/ST/STM32_USB_Device_Library/Core/Src" "-I{build.system.path}/Middlewares/ST/STM32_USB_Device_Library/Class/HID/Inc"
1616

Diff for: variants/NUCLEO_F429ZI/Ethernet/lwipopts.h

+251
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,251 @@
1+
/**
2+
******************************************************************************
3+
* @file LwIP/LwIP_HTTP_Server_Raw/Inc/lwipopts.h
4+
* @author MCD Application Team
5+
* @version V1.5.0
6+
* @date 17-February-2017
7+
* @brief lwIP Options Configuration.
8+
******************************************************************************
9+
* @attention
10+
*
11+
* <h2><center>&copy; Copyright (c) 2017 STMicroelectronics International N.V.
12+
* All rights reserved.</center></h2>
13+
*
14+
* Redistribution and use in source and binary forms, with or without
15+
* modification, are permitted, provided that the following conditions are met:
16+
*
17+
* 1. Redistribution of source code must retain the above copyright notice,
18+
* this list of conditions and the following disclaimer.
19+
* 2. Redistributions in binary form must reproduce the above copyright notice,
20+
* this list of conditions and the following disclaimer in the documentation
21+
* and/or other materials provided with the distribution.
22+
* 3. Neither the name of STMicroelectronics nor the names of other
23+
* contributors to this software may be used to endorse or promote products
24+
* derived from this software without specific written permission.
25+
* 4. This software, including modifications and/or derivative works of this
26+
* software, must execute solely and exclusively on microcontroller or
27+
* microprocessor devices manufactured by or for STMicroelectronics.
28+
* 5. Redistribution and use of this software other than as permitted under
29+
* this license is void and will automatically terminate your rights under
30+
* this license.
31+
*
32+
* THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
33+
* AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
34+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
35+
* PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
36+
* RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
37+
* SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
38+
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
39+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
40+
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
41+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
42+
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
43+
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44+
*
45+
******************************************************************************
46+
*/
47+
#ifndef __LWIPOPTS_H__
48+
#define __LWIPOPTS_H__
49+
50+
/**
51+
* NO_SYS==1: Provides VERY minimal functionality. Otherwise,
52+
* use lwIP facilities.
53+
*/
54+
#define NO_SYS 1
55+
56+
/**
57+
* SYS_LIGHTWEIGHT_PROT==1: if you want inter-task protection for certain
58+
* critical regions during buffer allocation, deallocation and memory
59+
* allocation and deallocation.
60+
*/
61+
#define SYS_LIGHTWEIGHT_PROT 0
62+
63+
/* ---------- Memory options ---------- */
64+
/* MEM_ALIGNMENT: should be set to the alignment of the CPU for which
65+
lwIP is compiled. 4 byte alignment -> define MEM_ALIGNMENT to 4, 2
66+
byte alignment -> define MEM_ALIGNMENT to 2. */
67+
#define MEM_ALIGNMENT 4
68+
69+
/* MEM_SIZE: the size of the heap memory. If the application will send
70+
a lot of data that needs to be copied, this should be set high. */
71+
#define MEM_SIZE (10*1024)
72+
73+
/* MEMP_NUM_PBUF: the number of memp struct pbufs. If the application
74+
sends a lot of data out of ROM (or other static memory), this
75+
should be set high. */
76+
#define MEMP_NUM_PBUF 10
77+
/* MEMP_NUM_UDP_PCB: the number of UDP protocol control blocks. One
78+
per active UDP "connection". */
79+
#define MEMP_NUM_UDP_PCB 6
80+
/* MEMP_NUM_TCP_PCB: the number of simulatenously active TCP
81+
connections. */
82+
#define MEMP_NUM_TCP_PCB 10
83+
/* MEMP_NUM_TCP_PCB_LISTEN: the number of listening TCP
84+
connections. */
85+
#define MEMP_NUM_TCP_PCB_LISTEN 6
86+
/* MEMP_NUM_TCP_SEG: the number of simultaneously queued TCP
87+
segments. */
88+
#define MEMP_NUM_TCP_SEG 8
89+
/* MEMP_NUM_SYS_TIMEOUT: the number of simulateously active
90+
timeouts. */
91+
#define MEMP_NUM_SYS_TIMEOUT 10
92+
93+
94+
/* ---------- Pbuf options ---------- */
95+
/* PBUF_POOL_SIZE: the number of buffers in the pbuf pool. */
96+
#define PBUF_POOL_SIZE 8
97+
98+
/* PBUF_POOL_BUFSIZE: the size of each pbuf in the pbuf pool. */
99+
#define PBUF_POOL_BUFSIZE 1524
100+
101+
102+
/* ---------- TCP options ---------- */
103+
#define LWIP_TCP 1
104+
#define TCP_TTL 255
105+
106+
/* Controls if TCP should queue segments that arrive out of
107+
order. Define to 0 if your device is low on memory. */
108+
#define TCP_QUEUE_OOSEQ 0
109+
110+
/* TCP Maximum segment size. */
111+
#define TCP_MSS (1500 - 40) /* TCP_MSS = (Ethernet MTU - IP header size - TCP header size) */
112+
113+
/* TCP sender buffer space (bytes). */
114+
#define TCP_SND_BUF (4*TCP_MSS)
115+
116+
/* TCP_SND_QUEUELEN: TCP sender buffer space (pbufs). This must be at least
117+
as much as (2 * TCP_SND_BUF/TCP_MSS) for things to work. */
118+
119+
#define TCP_SND_QUEUELEN (2* TCP_SND_BUF/TCP_MSS)
120+
121+
/* TCP receive window. */
122+
#define TCP_WND (2*TCP_MSS)
123+
124+
125+
/* ---------- ICMP options ---------- */
126+
#define LWIP_ICMP 1
127+
128+
129+
/* ---------- DHCP options ---------- */
130+
#define LWIP_DHCP 1
131+
132+
/* ---------- DNS options ---------- */
133+
#define LWIP_DNS 1
134+
135+
136+
/* ---------- UDP options ---------- */
137+
#define LWIP_UDP 1
138+
#define UDP_TTL 255
139+
140+
141+
/* ---------- Statistics options ---------- */
142+
#define LWIP_STATS 0
143+
144+
/* ---------- link callback options ---------- */
145+
/* LWIP_NETIF_LINK_CALLBACK==1: Support a callback function from an interface
146+
* whenever the link changes (i.e., link down)
147+
*/
148+
#define LWIP_NETIF_LINK_CALLBACK 1
149+
150+
/*
151+
--------------------------------------
152+
---------- Checksum options ----------
153+
--------------------------------------
154+
*/
155+
156+
/*
157+
The STM32F4x7 allows computing and verifying the IP, UDP, TCP and ICMP checksums by hardware:
158+
- To use this feature let the following define uncommented.
159+
- To disable it and process by CPU comment the the checksum.
160+
*/
161+
#define CHECKSUM_BY_HARDWARE
162+
163+
164+
#ifdef CHECKSUM_BY_HARDWARE
165+
/* CHECKSUM_GEN_IP==0: Generate checksums by hardware for outgoing IP packets.*/
166+
#define CHECKSUM_GEN_IP 0
167+
/* CHECKSUM_GEN_UDP==0: Generate checksums by hardware for outgoing UDP packets.*/
168+
#define CHECKSUM_GEN_UDP 0
169+
/* CHECKSUM_GEN_TCP==0: Generate checksums by hardware for outgoing TCP packets.*/
170+
#define CHECKSUM_GEN_TCP 0
171+
/* CHECKSUM_CHECK_IP==0: Check checksums by hardware for incoming IP packets.*/
172+
#define CHECKSUM_CHECK_IP 0
173+
/* CHECKSUM_CHECK_UDP==0: Check checksums by hardware for incoming UDP packets.*/
174+
#define CHECKSUM_CHECK_UDP 0
175+
/* CHECKSUM_CHECK_TCP==0: Check checksums by hardware for incoming TCP packets.*/
176+
#define CHECKSUM_CHECK_TCP 0
177+
/* CHECKSUM_CHECK_ICMP==0: Check checksums by hardware for incoming ICMP packets.*/
178+
#define CHECKSUM_GEN_ICMP 0
179+
#else
180+
/* CHECKSUM_GEN_IP==1: Generate checksums in software for outgoing IP packets.*/
181+
#define CHECKSUM_GEN_IP 1
182+
/* CHECKSUM_GEN_UDP==1: Generate checksums in software for outgoing UDP packets.*/
183+
#define CHECKSUM_GEN_UDP 1
184+
/* CHECKSUM_GEN_TCP==1: Generate checksums in software for outgoing TCP packets.*/
185+
#define CHECKSUM_GEN_TCP 1
186+
/* CHECKSUM_CHECK_IP==1: Check checksums in software for incoming IP packets.*/
187+
#define CHECKSUM_CHECK_IP 1
188+
/* CHECKSUM_CHECK_UDP==1: Check checksums in software for incoming UDP packets.*/
189+
#define CHECKSUM_CHECK_UDP 1
190+
/* CHECKSUM_CHECK_TCP==1: Check checksums in software for incoming TCP packets.*/
191+
#define CHECKSUM_CHECK_TCP 1
192+
/* CHECKSUM_CHECK_ICMP==1: Check checksums by hardware for incoming ICMP packets.*/
193+
#define CHECKSUM_GEN_ICMP 1
194+
#endif
195+
196+
197+
/*
198+
----------------------------------------------
199+
---------- Sequential layer options ----------
200+
----------------------------------------------
201+
*/
202+
/**
203+
* LWIP_NETCONN==1: Enable Netconn API (require to use api_lib.c)
204+
*/
205+
#define LWIP_NETCONN 0
206+
207+
/*
208+
------------------------------------
209+
---------- Socket options ----------
210+
------------------------------------
211+
*/
212+
/**
213+
* LWIP_SOCKET==1: Enable Socket API (require to use sockets.c)
214+
*/
215+
#define LWIP_SOCKET 0
216+
217+
/*
218+
------------------------------------
219+
---------- httpd options ----------
220+
------------------------------------
221+
*/
222+
223+
/** Set this to 1 to support CGI */
224+
#define LWIP_HTTPD_CGI 1
225+
226+
/** Set this to 1 to support SSI (Server-Side-Includes) */
227+
#define LWIP_HTTPD_SSI 1
228+
229+
/** Set this to 1 to include "fsdata_custom.c" instead of "fsdata.c" for the
230+
* file system (to prevent changing the file included in CVS) */
231+
#define HTTPD_USE_CUSTOM_FSDATA 1
232+
233+
/*
234+
------------------------------------
235+
---------- Custom options ----------
236+
------------------------------------
237+
*/
238+
239+
/** Enables the Ethernet peripheral in RMII mode. If not defined, MII mode will
240+
be enabled. Pin mapping must be configured for the selected mode
241+
(see PinMap_Ethernet in PeripheralPins.c). */
242+
#define ETHERNET_RMII_MODE_CONFIGURATION 1
243+
244+
/** Uncomment this line to use the ethernet input in interrupt mode.
245+
* NOTE: LwIP stack documentation recommends to use the polling mode without
246+
* an operating system. */
247+
//#define ETH_INPUT_USE_IT 1
248+
249+
#endif /* __LWIPOPTS_H__ */
250+
251+
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

0 commit comments

Comments
 (0)