Skip to content

Commit c9e6d74

Browse files
authored
Merge pull request stm32duino#1 from Solairseir/fix_staticIP_after_DHCP_fails
when DHCP fails the static IP can be appllied without problem
2 parents 8155ff2 + c0b1040 commit c9e6d74

File tree

1 file changed

+34
-31
lines changed

1 file changed

+34
-31
lines changed

src/utility/stm32_eth.cpp

+34-31
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@
6363
* They could be used for this library when available
6464
*/
6565
#ifndef DEFAULT_ETHERNET_TIMER
66-
#define DEFAULT_ETHERNET_TIMER TIM14
67-
#warning "Default timer used to call ethernet scheduler at regular interval: TIM14"
66+
#define DEFAULT_ETHERNET_TIMER TIM14
67+
#warning "Default timer used to call ethernet scheduler at regular interval: TIM14"
6868
#endif
6969

7070
/* Ethernet configuration: user parameters */
@@ -93,8 +93,8 @@ static uint8_t DHCP_Started_by_user = 0;
9393
static uint32_t gEhtLinkTickStart = 0;
9494

9595
#if !defined(STM32_CORE_VERSION) || (STM32_CORE_VERSION <= 0x01060100)
96-
/* Handler for stimer */
97-
static stimer_t TimHandle;
96+
/* Handler for stimer */
97+
static stimer_t TimHandle;
9898
#endif
9999

100100
/*************************** Function prototype *******************************/
@@ -111,6 +111,7 @@ static void TIM_scheduler_Config(void);
111111
*/
112112
static 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, &ethernetif_init, &ethernet_input);
116117

@@ -137,11 +138,11 @@ static void Netif_Config(void)
137138
* @retval None
138139
*/
139140
#if !defined(STM32_CORE_VERSION) || (STM32_CORE_VERSION <= 0x01060100)
140-
static void scheduler_callback(stimer_t *htim)
141+
static void scheduler_callback(stimer_t *htim)
141142
#elif (STM32_CORE_VERSION <= 0x01080000)
142-
static void scheduler_callback(HardwareTimer *htim)
143+
static void scheduler_callback(HardwareTimer *htim)
143144
#else
144-
static void scheduler_callback(void)
145+
static void scheduler_callback(void)
145146
#endif
146147
{
147148
#if (STM32_CORE_VERSION <= 0x01080000)
@@ -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

Comments
 (0)