Skip to content

Commit e2e0a42

Browse files
ABOSTMfpistm
authored andcommitted
fix: call effective ETH scheduler only from Timer callback
Restrict effective ETH scheduler to Timer callback only. This is to avoid any race condition on ETH scheduler, which could previously be called from timer ISR, as well as DHCP or UDP driver parts. Any direct request for ETH scheduler (direct call to stm32_eth_scheduler()) will generate a Timer Update Event to force a call to timer callback Fixes #45 Signed-off-by: Alexandre Bourdiol <[email protected]>
1 parent d5993db commit e2e0a42

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

src/utility/stm32_eth.cpp

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ static uint32_t gEhtLinkTickStart = 0;
9595
#if !defined(STM32_CORE_VERSION) || (STM32_CORE_VERSION <= 0x01060100)
9696
/* Handler for stimer */
9797
static stimer_t TimHandle;
98+
#else
99+
HardwareTimer *EthTim = NULL;
98100
#endif
99101

100102
/*************************** Function prototype *******************************/
@@ -103,6 +105,9 @@ static err_t tcp_recv_callback(void *arg, struct tcp_pcb *tpcb, struct pbuf *p,
103105
static err_t tcp_sent_callback(void *arg, struct tcp_pcb *tpcb, u16_t len);
104106
static void tcp_err_callback(void *arg, err_t err);
105107
static void TIM_scheduler_Config(void);
108+
#if defined(STM32_CORE_VERSION) && (STM32_CORE_VERSION > 0x01060100)
109+
void _stm32_eth_scheduler(void);
110+
#endif
106111

107112
/**
108113
* @brief Configurates the network interface
@@ -148,7 +153,7 @@ static void Netif_Config(void)
148153
#if (STM32_CORE_VERSION <= 0x01080000)
149154
UNUSED(htim);
150155
#endif
151-
stm32_eth_scheduler();
156+
_stm32_eth_scheduler();
152157
}
153158

154159
#if !defined(STM32_CORE_VERSION) || (STM32_CORE_VERSION <= 0x01060100)
@@ -176,7 +181,7 @@ static void TIM_scheduler_Config(void)
176181
static void TIM_scheduler_Config(void)
177182
{
178183
/* Configure HardwareTimer */
179-
HardwareTimer *EthTim = new HardwareTimer(DEFAULT_ETHERNET_TIMER);
184+
EthTim = new HardwareTimer(DEFAULT_ETHERNET_TIMER);
180185
EthTim->setMode(1, TIMER_OUTPUT_COMPARE);
181186

182187
/* Timer set to 1ms */
@@ -265,12 +270,33 @@ uint8_t stm32_eth_link_up(void)
265270
return netif_is_link_up(&gnetif);
266271
}
267272

273+
#if defined(STM32_CORE_VERSION) && (STM32_CORE_VERSION > 0x01060100)
274+
/**
275+
* @brief This function generates Timer Update event to force call to _stm32_eth_scheduler().
276+
* @param None
277+
* @retval None
278+
*/
279+
void stm32_eth_scheduler(void)
280+
{
281+
if (EthTim != NULL) {
282+
EthTim->refresh();
283+
}
284+
}
285+
268286
/**
269-
* @brief This function must be called in main loop in standalone mode.
287+
* @brief This function is called solely by Timer callback to avoid race condition.
288+
* @param None
289+
* @retval None
290+
*/
291+
void _stm32_eth_scheduler(void)
292+
#else
293+
/**
294+
* @brief This function is called solely by Timer callback to avoid race condition.
270295
* @param None
271296
* @retval None
272297
*/
273298
void stm32_eth_scheduler(void)
299+
#endif
274300
{
275301
/* Read a received packet from the Ethernet buffers and send it
276302
to the lwIP for handling */

0 commit comments

Comments
 (0)