Skip to content

Commit 1ce51b4

Browse files
author
fpr
committed
Use callback method to update LwIP stack and add update function to Ethernet
Signed-off-by: fpr <[email protected]>
1 parent 2cbafb0 commit 1ce51b4

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ It is done automatically by the LwIP stack in a background task.
2121
An Idle task is required by the LwIP stack to handle timer and data reception.
2222
This idle task is called inside the main loop in background by the function
2323
stm32_eth_scheduler(). Be careful to not lock the system inside the function
24-
loop() where LwIP could never be updated. Call EthernetUDP::parsePacket() or
25-
EthernetClient::available() performs an update of the LwIP stack.
24+
loop() where LwIP could never be updated. Call Ethernet::schedule() performs an
25+
update of the LwIP stack.
2626

2727
## Wiki
2828

src/STM32Ethernet.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,15 @@ int EthernetClass::maintain(){
7373
return rc;
7474
}
7575

76+
/*
77+
* This function updates the LwIP stack and can be called to be sure to update
78+
* the stack (e.g. in case of a long loop).
79+
*/
80+
void EthernetClass::schedule(void)
81+
{
82+
stm32_eth_scheduler();
83+
}
84+
7685
IPAddress EthernetClass::localIP()
7786
{
7887
return IPAddress(stm32_eth_get_ipaddr());

src/STM32Ethernet.h

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class EthernetClass {
2121
void begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server, IPAddress gateway);
2222
void begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet);
2323
int maintain();
24+
void schedule(void);
2425

2526
IPAddress localIP();
2627
IPAddress subnetMask();

src/utility/stm32_eth.c

+12
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,15 @@
4646
#include "lwip/prot/dhcp.h"
4747
#include "lwip/dns.h"
4848

49+
//Keeps compatibilty with older version of the STM32 core
50+
#if __has_include("core_callback.h")
51+
#include "core_callback.h"
52+
#else
53+
void registerCoreCallback(void (*func)(void)) {
54+
UNUSED(func);
55+
}
56+
#endif
57+
4958

5059
#ifdef __cplusplus
5160
extern "C" {
@@ -168,6 +177,9 @@ void stm32_eth_init(const uint8_t *mac, const uint8_t *ip, const uint8_t *gw, co
168177
User_notification(&gnetif);
169178

170179
stm32_eth_scheduler();
180+
181+
// stm32_eth_scheduler() will be called directly inside the loop of the main() function.
182+
registerCoreCallback(stm32_eth_scheduler);
171183
}
172184

173185
/**

0 commit comments

Comments
 (0)