@@ -111,6 +111,7 @@ static void TIM_scheduler_Config(void);
111111*/
112112static void Netif_Config (void )
113113{
114+ netif_remove (&gnetif);
114115 /* Add the network interface */
115116 netif_add (&gnetif, &(gconfig.ipaddr ), &(gconfig.netmask ), &(gconfig.gw ), NULL , ðernetif_init, ðernet_input);
116117
@@ -176,6 +177,7 @@ static void TIM_scheduler_Config(void)
176177{
177178 /* Configure HardwareTimer */
178179 HardwareTimer *EthTim = new HardwareTimer (DEFAULT_ETHERNET_TIMER);
180+ EthTim->setMode (1 , TIMER_OUTPUT_COMPARE);
179181
180182 /* Timer set to 1ms */
181183 EthTim->setOverflow (1000 , MICROSEC_FORMAT);
@@ -191,47 +193,48 @@ void stm32_eth_init(const uint8_t *mac, const uint8_t *ip, const uint8_t *gw, co
191193 if (!initDone) {
192194 /* Initialize the LwIP stack */
193195 lwip_init ();
196+ }
194197
195- if (mac != NULL ) {
196- ethernetif_set_mac_addr (mac);
197- } // else default value is used: MAC_ADDR0 ... MAC_ADDR5
198+ if (mac != NULL ) {
199+ ethernetif_set_mac_addr (mac);
200+ } // else default value is used: MAC_ADDR0 ... MAC_ADDR5
198201
199- if (ip != NULL ) {
200- IP_ADDR4 (&(gconfig.ipaddr ), ip[0 ], ip[1 ], ip[2 ], ip[3 ]);
201- } else {
202+ if (ip != NULL ) {
203+ IP_ADDR4 (&(gconfig.ipaddr ), ip[0 ], ip[1 ], ip[2 ], ip[3 ]);
204+ } else {
202205#if LWIP_DHCP
203- ip_addr_set_zero_ip4 (&(gconfig.ipaddr ));
206+ ip_addr_set_zero_ip4 (&(gconfig.ipaddr ));
204207#else
205- IP_ADDR4 (&(gconfig.ipaddr ), IP_ADDR0, IP_ADDR1, IP_ADDR2, IP_ADDR3);
208+ IP_ADDR4 (&(gconfig.ipaddr ), IP_ADDR0, IP_ADDR1, IP_ADDR2, IP_ADDR3);
206209#endif /* LWIP_DHCP */
207- }
210+ }
208211
209- if (gw != NULL ) {
210- IP_ADDR4 (&(gconfig.gw ), gw[0 ], gw[1 ], gw[2 ], gw[3 ]);
211- } else {
212+ if (gw != NULL ) {
213+ IP_ADDR4 (&(gconfig.gw ), gw[0 ], gw[1 ], gw[2 ], gw[3 ]);
214+ } else {
212215#if LWIP_DHCP
213- ip_addr_set_zero_ip4 (&(gconfig.gw ));
216+ ip_addr_set_zero_ip4 (&(gconfig.gw ));
214217#else
215- IP_ADDR4 (&(gconfig.gw ), GW_ADDR0, GW_ADDR1, GW_ADDR2, GW_ADDR3);
218+ IP_ADDR4 (&(gconfig.gw ), GW_ADDR0, GW_ADDR1, GW_ADDR2, GW_ADDR3);
216219#endif /* LWIP_DHCP */
217- }
220+ }
218221
219- if (netmask != NULL ) {
220- IP_ADDR4 (&(gconfig.netmask ), netmask[0 ], netmask[1 ], netmask[2 ], netmask[3 ]);
221- } else {
222+ if (netmask != NULL ) {
223+ IP_ADDR4 (&(gconfig.netmask ), netmask[0 ], netmask[1 ], netmask[2 ], netmask[3 ]);
224+ } else {
222225#if LWIP_DHCP
223- ip_addr_set_zero_ip4 (&(gconfig.netmask ));
226+ ip_addr_set_zero_ip4 (&(gconfig.netmask ));
224227#else
225- IP_ADDR4 (&(gconfig.netmask ), NETMASK_ADDR0, NETMASK_ADDR1, NETMASK_ADDR2, NETMASK_ADDR3);
228+ IP_ADDR4 (&(gconfig.netmask ), NETMASK_ADDR0, NETMASK_ADDR1, NETMASK_ADDR2, NETMASK_ADDR3);
226229#endif /* LWIP_DHCP */
227- }
230+ }
228231
229- /* Configure the Network interface */
230- Netif_Config ();
232+ /* Configure the Network interface */
233+ Netif_Config ();
231234
235+ if (!initDone) {
232236 // stm32_eth_scheduler() will be called every 1ms.
233237 TIM_scheduler_Config ();
234-
235238 initDone = 1 ;
236239 }
237240
0 commit comments