diff --git a/.github/workflows/Continuous-Integration.yml b/.github/workflows/Continuous-Integration.yml index b324ceb..259d70f 100644 --- a/.github/workflows/Continuous-Integration.yml +++ b/.github/workflows/Continuous-Integration.yml @@ -31,14 +31,21 @@ jobs: run: | cat ${{ steps.Astyle.outputs.astyle-result }} exit 1 - spell-check: + codespell: + name: Check for spelling errors runs-on: ubuntu-latest - name: Spell check steps: - - uses: actions/checkout@main - - uses: arduino/actions/libraries/spell-check@master - # with: - # ignore-words-list: "./extras/codespell-ignore-words-list.txt" + - name: Checkout + uses: actions/checkout@main + + # See: https://github.com/codespell-project/actions-codespell/blob/master/README.md + - name: Spell check + uses: codespell-project/actions-codespell@master + with: + check_filenames: true + check_hidden: true + # In the event of a false positive, add the word in all lower case to this file: + # ignore_words_file: ./extras/codespell-ignore-words-list.txt lib_build: runs-on: ubuntu-latest name: Library compilation diff --git a/README.md b/README.md index 6e2262d..b87f2b2 100644 --- a/README.md +++ b/README.md @@ -66,4 +66,4 @@ Call `Ethernet::schedule()` performs an update of the LwIP stack.
## Wiki -You can find information at https://github.com/stm32duino/wiki/wiki/STM32Ethernet +You can find information at https://github.com/stm32duino/Arduino_Core_STM32/wiki/STM32Ethernet diff --git a/keywords.txt b/keywords.txt index 367603a..09e494c 100644 --- a/keywords.txt +++ b/keywords.txt @@ -24,7 +24,9 @@ peek KEYWORD2 flush KEYWORD2 stop KEYWORD2 connected KEYWORD2 +accept KEYWORD2 begin KEYWORD2 +beginMulticast KEYWORD2 beginPacket KEYWORD2 endPacket KEYWORD2 parsePacket KEYWORD2 @@ -32,10 +34,17 @@ remoteIP KEYWORD2 remotePort KEYWORD2 getSocketNumber KEYWORD2 localIP KEYWORD2 -MACAddress KEYWORD2 +localPort KEYWORD2 maintain KEYWORD2 +linkStatus KEYWORD2 +MACAddress KEYWORD2 +subnetMask KEYWORD2 +gatewayIP KEYWORD2 +dnsServerIP KEYWORD2 +setConnectionTimeout KEYWORD2 ####################################### # Constants (LITERAL1) ####################################### - +LinkON LITERAL1 +LinkOFF LITERAL1 diff --git a/library.json b/library.json index f4f202c..f8fe867 100755 --- a/library.json +++ b/library.json @@ -7,7 +7,7 @@ "type": "git", "url": "https://github.com/stm32duino/STM32Ethernet" }, - "version": "1.3.0", + "version": "1.4.0", "frameworks": "arduino", "platforms": "ststm32", "build": { diff --git a/library.properties b/library.properties index 3a4aaee..a7e954a 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=STM32duino STM32Ethernet -version=1.3.0 +version=1.4.0 author=Various maintainer=STMicroelectronics sentence=Enables network connection (local and Internet) using the STM32 Board. diff --git a/src/EthernetClient.cpp b/src/EthernetClient.cpp index 4fd0a7f..aa2606b 100644 --- a/src/EthernetClient.cpp +++ b/src/EthernetClient.cpp @@ -76,7 +76,7 @@ int EthernetClient::connect(IPAddress ip, uint16_t port) startTime = millis(); while (_tcp_client->state == TCP_NONE) { stm32_eth_scheduler(); - if ((_tcp_client->state == TCP_CLOSING) || ((millis() - startTime) >= _timeout)) { + if ((_tcp_client->state == TCP_CLOSING) || ((millis() - startTime) >= _connectionTimeout)) { stop(); return 0; } @@ -194,6 +194,7 @@ void EthernetClient::stop() if (status() != TCP_CLOSING) { tcp_connection_close(_tcp_client->pcb, _tcp_client); } + mem_free(_tcp_client); } uint8_t EthernetClient::connected() diff --git a/src/EthernetClient.h b/src/EthernetClient.h index c937a05..5afb160 100644 --- a/src/EthernetClient.h +++ b/src/EthernetClient.h @@ -52,9 +52,9 @@ class EthernetClient : public Client { { return (_tcp_client->pcb->remote_port); }; - void setTimeout(uint16_t timeout) + void setConnectionTimeout(uint16_t timeout) { - _timeout = timeout; + _connectionTimeout = timeout; } friend class EthernetServer; @@ -63,7 +63,7 @@ class EthernetClient : public Client { private: struct tcp_struct *_tcp_client; - uint16_t _timeout = 10000; + uint16_t _connectionTimeout = 10000; }; #endif diff --git a/src/EthernetServer.cpp b/src/EthernetServer.cpp index 386ae9d..2082498 100644 --- a/src/EthernetServer.cpp +++ b/src/EthernetServer.cpp @@ -46,6 +46,22 @@ void EthernetServer::begin(uint16_t port) begin(); } +void EthernetServer::end(void) +{ + /* Free client */ + for (int n = 0; n < MAX_CLIENT; n++) { + if (_tcp_client[n] != NULL) { + EthernetClient client(_tcp_client[n]); + client.stop(); + _tcp_client[n] = NULL; + } + } + if (_tcp_server.pcb != NULL) { + tcp_close(_tcp_server.pcb); + _tcp_server.pcb = NULL; + } +} + void EthernetServer::accept() { /* Free client if disconnected */ @@ -93,10 +109,10 @@ size_t EthernetServer::write(const uint8_t *buffer, size_t size) accept(); - for (int n = 0; n < MAX_CLIENT; n++) { - if (_tcp_client[n] != NULL) { - if (_tcp_client[n]->pcb != NULL) { - EthernetClient client(_tcp_client[n]); + for (int i = 0; i < MAX_CLIENT; i++) { + if (_tcp_client[i] != NULL) { + if (_tcp_client[i]->pcb != NULL) { + EthernetClient client(_tcp_client[i]); uint8_t s = client.status(); if (s == TCP_ACCEPTED) { n += client.write(buffer, size); @@ -107,3 +123,9 @@ size_t EthernetServer::write(const uint8_t *buffer, size_t size) return n; } + +EthernetServer::operator bool() +{ + // server is listening for incoming clients + return ((_tcp_server.pcb != NULL) && (_tcp_server.pcb->state == LISTEN)); +} diff --git a/src/EthernetServer.h b/src/EthernetServer.h index 3a218d4..10c306c 100644 --- a/src/EthernetServer.h +++ b/src/EthernetServer.h @@ -18,8 +18,10 @@ class EthernetServer : EthernetClient available(); virtual void begin(); virtual void begin(uint16_t port); + void end(void); virtual size_t write(uint8_t); virtual size_t write(const uint8_t *buf, size_t size); + virtual operator bool(); using Print::write; }; diff --git a/src/lwipopts_default.h b/src/lwipopts_default.h index d7fae2d..f605098 100644 --- a/src/lwipopts_default.h +++ b/src/lwipopts_default.h @@ -51,7 +51,7 @@ a lot of data that needs to be copied, this should be set high. */ /* MEMP_NUM_UDP_PCB: the number of UDP protocol control blocks. One per active UDP "connection". */ #define MEMP_NUM_UDP_PCB 6 -/* MEMP_NUM_TCP_PCB: the number of simulatenously active TCP +/* MEMP_NUM_TCP_PCB: the number of simultaneously active TCP connections. */ #define MEMP_NUM_TCP_PCB 10 /* MEMP_NUM_TCP_PCB_LISTEN: the number of listening TCP @@ -60,7 +60,7 @@ a lot of data that needs to be copied, this should be set high. */ /* MEMP_NUM_TCP_SEG: the number of simultaneously queued TCP segments. */ #define MEMP_NUM_TCP_SEG 8 -/* MEMP_NUM_SYS_TIMEOUT: the number of simulateously active +/* MEMP_NUM_SYS_TIMEOUT: the number of simultaneously active timeouts. */ #define MEMP_NUM_SYS_TIMEOUT 10 diff --git a/src/utility/stm32_eth.cpp b/src/utility/stm32_eth.cpp index 937a297..7b06955 100644 --- a/src/utility/stm32_eth.cpp +++ b/src/utility/stm32_eth.cpp @@ -67,6 +67,13 @@ #warning "Default timer used to call ethernet scheduler at regular interval: TIM14" #endif +/* Interrupt priority */ +#ifndef ETH_TIM_IRQ_PRIO + #define ETH_TIM_IRQ_PRIO 15 // Warning: it should be lower prio (higher value) than Systick +#endif +#ifndef ETH_TIM_IRQ_SUBPRIO + #define ETH_TIM_IRQ_SUBPRIO 0 +#endif /* Ethernet configuration: user parameters */ struct stm32_eth_config { ip_addr_t ipaddr; @@ -182,6 +189,7 @@ static void TIM_scheduler_Config(void) { /* Configure HardwareTimer */ EthTim = new HardwareTimer(DEFAULT_ETHERNET_TIMER); + EthTim->setInterruptPriority(ETH_TIM_IRQ_PRIO, ETH_TIM_IRQ_SUBPRIO); EthTim->setMode(1, TIMER_OUTPUT_COMPARE); /* Timer set to 1ms */