Skip to content

Remove dependency with the core #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from Sep 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ It is done automatically by the LwIP stack in a background task.
An Idle task is required by the LwIP stack to handle timer and data reception.
This idle task is called inside the main loop in background by the function
stm32_eth_scheduler(). Be careful to not lock the system inside the function
loop() where LwIP could never be updated. Call EthernetUDP::parsePacket() or
EthernetClient::available() performs an update of the LwIP stack.
loop() where LwIP could never be updated. Call Ethernet::schedule() performs an
update of the LwIP stack.

## Wiki

Expand Down
9 changes: 9 additions & 0 deletions src/STM32Ethernet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ int EthernetClass::maintain(){
return rc;
}

/*
* This function updates the LwIP stack and can be called to be sure to update
* the stack (e.g. in case of a long loop).
*/
void EthernetClass::schedule(void)
{
stm32_eth_scheduler();
}

IPAddress EthernetClass::localIP()
{
return IPAddress(stm32_eth_get_ipaddr());
Expand Down
1 change: 1 addition & 0 deletions src/STM32Ethernet.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class EthernetClass {
void begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server, IPAddress gateway);
void begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet);
int maintain();
void schedule(void);

IPAddress localIP();
IPAddress subnetMask();
Expand Down
12 changes: 12 additions & 0 deletions src/utility/stm32_eth.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@
#include "lwip/prot/dhcp.h"
#include "lwip/dns.h"

//Keeps compatibilty with older version of the STM32 core
#if __has_include("core_callback.h")
#include "core_callback.h"
#else
void registerCoreCallback(void (*func)(void)) {
UNUSED(func);
}
#endif


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

stm32_eth_scheduler();

// stm32_eth_scheduler() will be called directly inside the loop of the main() function.
registerCoreCallback(stm32_eth_scheduler);
}

/**
Expand Down