From 313d938968dbc883a0ca53443195e6ea5e01e18f Mon Sep 17 00:00:00 2001 From: fvanroie Date: Wed, 6 May 2020 22:44:59 +0200 Subject: [PATCH] Add W5500 support --- include/hasp_conf.h | 17 +++++++++++++++-- include/stm32f4/hal_conf_custom.h | 3 +++ src/hasp_ethernet.cpp | 10 +--------- src/hasp_hal.cpp | 7 ++----- src/hasp_mqtt.cpp | 7 +++++++ src/hasp_telnet.cpp | 3 ++- src/main.cpp | 4 ---- .../stm32f4xx/stm32f407-black_ili9341.ini | 13 ++++++++++--- .../stm32f4xx/stm32f407-devebox_ili9341.ini | 1 + 9 files changed, 41 insertions(+), 24 deletions(-) diff --git a/include/hasp_conf.h b/include/hasp_conf.h index 8e883a1f..075102aa 100644 --- a/include/hasp_conf.h +++ b/include/hasp_conf.h @@ -35,7 +35,7 @@ #endif #ifndef HASP_USE_SYSLOG -#define HASP_USE_SYSLOG (HASP_HAS_NETWORK) +#define HASP_USE_SYSLOG 0 #endif #ifndef HASP_USE_TELNET @@ -94,7 +94,7 @@ #include "hasp_spiffs.h" #if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266) -#include "lv_zifont.h" +//#include "lv_zifont.h" #endif #endif // SPIFFS @@ -107,6 +107,19 @@ #endif #if HASP_USE_ETHERNET>0 +#if USE_BUILTIN_ETHERNET>0 +#include +#include +#warning Use built-in STM32 Ethernet +#elif USE_UIP_ETHERNET +#include +#include +#warning Use ENC28J60 Ethernet shield +#else +#include "Ethernet.h" +#include "EthernetClient.h" +#warning Use W5x00 Ethernet shield +#endif #include "hasp_ethernet.h" #endif diff --git a/include/stm32f4/hal_conf_custom.h b/include/stm32f4/hal_conf_custom.h index 0febc31b..b0bc4acf 100644 --- a/include/stm32f4/hal_conf_custom.h +++ b/include/stm32f4/hal_conf_custom.h @@ -1,6 +1,7 @@ /* Include the normal default core configuration */ #include "stm32f4xx_hal_conf_default.h" +#if USE_BUILTIN_ETHERNET /* Remove the default PHY address */ #ifdef LAN8742A_PHY_ADDRESS #undef LAN8742A_PHY_ADDRESS @@ -10,4 +11,6 @@ /* Redefine LAN8742A PHY Address*/ #ifndef LAN8742A_PHY_ADDRESS #define LAN8742A_PHY_ADDRESS 0x01U //HASP_PHY_ADDRESS +#endif + #endif \ No newline at end of file diff --git a/src/hasp_ethernet.cpp b/src/hasp_ethernet.cpp index 0738c4e1..2d2c93ec 100644 --- a/src/hasp_ethernet.cpp +++ b/src/hasp_ethernet.cpp @@ -5,15 +5,7 @@ #if HASP_USE_ETHERNET > 0 -#if defined(W5500_MOSI) && defined(W5500_MISO) && defined(W5500_SCLK) -#define W5500_LAN -#include -#include -#else -#include -#include -#include -#endif + EthernetClient EthClient; IPAddress ip; diff --git a/src/hasp_hal.cpp b/src/hasp_hal.cpp index 5a9536a6..b8b6a0e3 100644 --- a/src/hasp_hal.cpp +++ b/src/hasp_hal.cpp @@ -1,8 +1,5 @@ -#if defined(STM32F4xx) -#include -#endif - #include "hasp_hal.h" +#include "hasp_conf.h" #if defined(ESP8266) #include @@ -250,7 +247,7 @@ String halGetMacAddress(int start, const char * seperator) #if defined(STM32F4xx) uint8_t * mac_p; - mac_p = Ethernet.MACAddress(); + //mac_p = Ethernet.MACAddress(); for(uint8_t i = 0; i < 6; i++) mac[i] = *(mac_p + i); #else WiFi.macAddress(mac); diff --git a/src/hasp_mqtt.cpp b/src/hasp_mqtt.cpp index a9390dba..dcb0e6f6 100644 --- a/src/hasp_mqtt.cpp +++ b/src/hasp_mqtt.cpp @@ -18,7 +18,14 @@ WiFiClient mqttNetworkClient; #include WiFiClient mqttNetworkClient; #else + +#if defined(W5500_MOSI) && defined(W5500_MISO) && defined(W5500_SCLK) +#define W5500_LAN +#include +#else #include +#endif + EthernetClient mqttNetworkClient; #endif diff --git a/src/hasp_telnet.cpp b/src/hasp_telnet.cpp index 3c5eab43..e6595dba 100644 --- a/src/hasp_telnet.cpp +++ b/src/hasp_telnet.cpp @@ -9,6 +9,7 @@ #include "hasp_config.h" #include "hasp_dispatch.h" #include "hasp_telnet.h" +#include "hasp_conf.h" #if defined(ARDUINO_ARCH_ESP32) #include @@ -19,7 +20,7 @@ static WiFiServer * telnetServer; WiFiClient telnetClient; static WiFiServer * telnetServer; #else -#include +//#include EthernetClient telnetClient; static EthernetServer telnetServer(23); #endif diff --git a/src/main.cpp b/src/main.cpp index 75a3e146..18cd738d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -9,10 +9,6 @@ #include "hasp_oobe.h" #include "hasp_gpio.h" -#if HASP_USE_ETHERNET > 0 -#include -#endif - bool isConnected; uint8_t mainLoopCounter = 0; unsigned long mainLastLoopTime = 0; diff --git a/user_setups/stm32f4xx/stm32f407-black_ili9341.ini b/user_setups/stm32f4xx/stm32f407-black_ili9341.ini index d7fab307..ccb986a9 100644 --- a/user_setups/stm32f4xx/stm32f407-black_ili9341.ini +++ b/user_setups/stm32f4xx/stm32f407-black_ili9341.ini @@ -28,17 +28,24 @@ build_flags = -D HASP_OUTPUT_PIN=PE0 ; User LED D2 on DevEBox board -D HASP_INPUT_PIN=PD15 ; User Button K1 on DevEBox board -D STM32_SERIAL1 ; Set this option to use Serial1 as default sersial port, leave out if using Serial2 - -D HAL_ETH_MODULE_ENABLED=1 ; enable ethernet support - -D LAN8742A_PHY_ADDRESS=0x01U ; set LAN8720 PHY address + ;-D HAL_ETH_MODULE_ENABLED=1 ; enable ethernet support + ;-D LAN8742A_PHY_ADDRESS=0x01U ; set LAN8720 PHY address -D HASP_USE_TASMOTA_SLAVE=1 + -D W5500_MOSI=PB15 ;SPI2 MOSI + -D W5500_MISO=PB14 ;SPI2 MISO + -D W5500_SCLK=PB13 ;SPI2 SCLK + -D W5500_CS=PB6 ;SPI2 CS + -D W5500_RST=PD1 ;SPI2 CS lib_deps = ${env.lib_deps} Ticker@^3.1.5 + Ethernet ; STM32duino LwIP@^2.1.2 ; STM32duino STM32Ethernet@^1.0.5 https://github.com/stm32duino/LwIP.git - https://github.com/stm32duino/STM32Ethernet.git + ;https://github.com/netwizeBE/Ethernet3.git + https://github.com/khoih-prog/EthernetWebServer_STM32 src_filter = +<*> -<.git/> -<.svn/> - - - - - + diff --git a/user_setups/stm32f4xx/stm32f407-devebox_ili9341.ini b/user_setups/stm32f4xx/stm32f407-devebox_ili9341.ini index 406b5976..43b5d65c 100644 --- a/user_setups/stm32f4xx/stm32f407-devebox_ili9341.ini +++ b/user_setups/stm32f4xx/stm32f407-devebox_ili9341.ini @@ -47,5 +47,6 @@ lib_deps = ; STM32duino STM32Ethernet@^1.0.5 https://github.com/stm32duino/LwIP.git https://github.com/stm32duino/STM32Ethernet.git + https://github.com/khoih-prog/EthernetWebServer_STM32 src_filter = +<*> -<.git/> -<.svn/> - - - - - +