├── MQTTPublish_LAN8720 ├── hal_conf_extra.h └── MQTTPublish_LAN8720.ino ├── UDPBroadcast_LAN8720 ├── hal_conf_extra.h ├── README.md ├── receive.py └── UDPBroadcast_LAN8720.ino ├── UdpNtpClient_LAN8720 ├── hal_conf_extra.h └── UdpNtpClient_LAN8720.ino ├── DhcpAddressPrinter_LAN8720 ├── hal_conf_extra.h └── DhcpAddressPrinter_LAN8720.ino ├── LICENSE └── README.md /MQTTPublish_LAN8720/hal_conf_extra.h: -------------------------------------------------------------------------------- 1 | //#define HAL_ETH_MODULE_ENABLED // For core version 2.2 or earlier 2 | #define HAL_ETH_LEGACY_MODULE_ENABLED // For core version 2.3 or later 3 | #define LAN8742A_PHY_ADDRESS 0x01U 4 | -------------------------------------------------------------------------------- /UDPBroadcast_LAN8720/hal_conf_extra.h: -------------------------------------------------------------------------------- 1 | //#define HAL_ETH_MODULE_ENABLED // For core version 2.2 or earlier 2 | #define HAL_ETH_LEGACY_MODULE_ENABLED // For core version 2.3 or later 3 | #define LAN8742A_PHY_ADDRESS 0x01U 4 | -------------------------------------------------------------------------------- /UdpNtpClient_LAN8720/hal_conf_extra.h: -------------------------------------------------------------------------------- 1 | //#define HAL_ETH_MODULE_ENABLED // For core version 2.2 or earlier 2 | #define HAL_ETH_LEGACY_MODULE_ENABLED // For core version 2.3 or later 3 | #define LAN8742A_PHY_ADDRESS 0x01U 4 | -------------------------------------------------------------------------------- /DhcpAddressPrinter_LAN8720/hal_conf_extra.h: -------------------------------------------------------------------------------- 1 | //#define HAL_ETH_MODULE_ENABLED // For core version 2.2 or earlier 2 | #define HAL_ETH_LEGACY_MODULE_ENABLED // For core version 2.3 or later 3 | #define LAN8742A_PHY_ADDRESS 0x01U 4 | -------------------------------------------------------------------------------- /UDPBroadcast_LAN8720/README.md: -------------------------------------------------------------------------------- 1 | UDP Broadcast Client using LAN8720 PHY 2 | 3 | You can use receive.py as UDP receiver. 4 | ![UDP_Broadcast](https://github.com/user-attachments/assets/0c298f4a-a8d8-4c1b-ba64-af00ac7f1e32) 5 | -------------------------------------------------------------------------------- /UDPBroadcast_LAN8720/receive.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | import select, socket 4 | 5 | s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) 6 | s.bind(('', 9876)) 7 | s.setblocking(0) 8 | 9 | while True: 10 | result = select.select([s],[],[]) 11 | msg = result[0][0].recv(1024) 12 | if (type(msg) is bytes): 13 | msg = msg.decode('utf-8') 14 | print(msg) 15 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 nopnop2002 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /UDPBroadcast_LAN8720/UDPBroadcast_LAN8720.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | unsigned int localPort = 9800; // local port to listen for UDP packets 6 | unsigned int remotePort = 9876; // remote port to listen for UDP packets 7 | unsigned long lastMillis; 8 | IPAddress broadcastIp(255, 255, 255, 255); 9 | 10 | // A UDP instance to let us send and receive packets over UDP 11 | EthernetUDP Udp; 12 | 13 | void setup() { 14 | // Open serial communications and wait for port to open: 15 | Serial.begin(115200); 16 | while (!Serial) { 17 | ; // wait for serial port to connect. Needed for native USB port only 18 | } 19 | 20 | // start Ethernet and UDP 21 | Serial.println("Begin Ethernet"); 22 | if (Ethernet.begin() == 0) { 23 | Serial.println("Failed to configure Ethernet using DHCP"); 24 | // no point in carrying on, so do nothing forevermore: 25 | for (;;) 26 | ; 27 | } 28 | Serial.println("Success to configure Ethernet using DHCP"); 29 | 30 | Serial.print("localIP: "); 31 | Serial.println(Ethernet.localIP()); 32 | Serial.print("subnetMask: "); 33 | Serial.println(Ethernet.subnetMask()); 34 | Serial.print("gatewayIP: "); 35 | Serial.println(Ethernet.gatewayIP()); 36 | Serial.print("dnsServerIP: "); 37 | Serial.println(Ethernet.dnsServerIP()); 38 | 39 | Serial.print("broadcastIP: "); 40 | for (byte thisByte = 0; thisByte < 4; thisByte++) { 41 | // print the value of each byte of the IP address: 42 | Serial.print(broadcastIp[thisByte], DEC); 43 | if (thisByte < 3) Serial.print("."); 44 | } 45 | Serial.println(); 46 | 47 | Udp.begin(localPort); 48 | lastMillis = millis(); 49 | } 50 | 51 | void loop() { 52 | unsigned long now = millis(); 53 | if (now < lastMillis) lastMillis = now; 54 | if (now - lastMillis > 10000) { 55 | Serial.print("Broadcast to "); 56 | Serial.println(remotePort); 57 | lastMillis = now; 58 | Udp.beginPacket(broadcastIp, remotePort); 59 | char sbuf[128]; 60 | sprintf(sbuf, "Hello STM32 %lu", now); 61 | Udp.write(sbuf); 62 | //Udp.write("\r\n"); 63 | Udp.endPacket(); 64 | } 65 | Ethernet.maintain(); 66 | } 67 | -------------------------------------------------------------------------------- /MQTTPublish_LAN8720/MQTTPublish_LAN8720.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define MQTT_SERVER "broker.emqx.io" 6 | #define MQTT_PORT 1883 7 | #define MQTT_TOPIC "/test/stm32" // You can change 8 | #define MQTT_WILL_TOPIC MQTT_TOPIC 9 | #define MQTT_WILL_MSG "I am leaving..." // You can change 10 | #define MQTT_INTERVAL 2000 11 | 12 | EthernetClient EthClient; 13 | PubSubClient client(EthClient); 14 | unsigned long lastMillis; 15 | 16 | void errorDisplay(char* buff) { 17 | Serial.print("Error:"); 18 | Serial.println(buff); 19 | while(1); 20 | } 21 | 22 | void setup() { 23 | // Open serial communications and wait for port to open: 24 | Serial.begin(115200); 25 | while (!Serial) { 26 | ; // wait for serial port to connect. Needed for native USB port only 27 | } 28 | 29 | 30 | // start Ethernet and UDP 31 | Serial.println("Begin Ethernet"); 32 | if (Ethernet.begin() == 0) { 33 | Serial.println("Failed to configure Ethernet using DHCP"); 34 | // no point in carrying on, so do nothing forevermore: 35 | for (;;) 36 | ; 37 | } 38 | Serial.println("Success to configure Ethernet using DHCP"); 39 | 40 | Serial.print("localIP: "); 41 | Serial.println(Ethernet.localIP()); 42 | IPAddress ip = Ethernet.localIP(); 43 | 44 | client.setServer(MQTT_SERVER, MQTT_PORT); 45 | char clientid[20]; 46 | sprintf(clientid,"STM32-%03d",ip[3]); 47 | Serial.print("clientid="); 48 | Serial.println(clientid); 49 | Serial.print("Attempting MQTT connection..."); 50 | // Attempt to connect 51 | if (!client.connect(clientid, MQTT_WILL_TOPIC, 0, 0, MQTT_WILL_MSG)) { 52 | errorDisplay("connect Fail"); 53 | } 54 | Serial.println("connected"); 55 | lastMillis = millis(); 56 | } 57 | 58 | void loop() { 59 | char msg[50]; 60 | 61 | if (!client.connected()) { 62 | errorDisplay("not connect Broker"); 63 | } 64 | client.loop(); 65 | 66 | long now = millis(); 67 | if (now < lastMillis) lastMillis = now; 68 | if (now - lastMillis > MQTT_INTERVAL) { 69 | lastMillis = now; 70 | snprintf (msg, 75, "hello world #%lu", now); 71 | Serial.print("Publish message: "); 72 | Serial.println(msg); 73 | if (!client.publish(MQTT_TOPIC, msg)) { 74 | errorDisplay("publish fail"); 75 | } 76 | } 77 | Ethernet.maintain(); 78 | } 79 | -------------------------------------------------------------------------------- /DhcpAddressPrinter_LAN8720/DhcpAddressPrinter_LAN8720.ino: -------------------------------------------------------------------------------- 1 | /* 2 | DHCP-based IP printer 3 | 4 | This sketch uses the DHCP extensions to the Ethernet library 5 | to get an IP address via DHCP and print the address obtained. 6 | 7 | Circuit: 8 | STM32 board with Ethernet support 9 | 10 | created 12 April 2011 11 | modified 9 Apr 2012 12 | by Tom Igoe 13 | modified 02 Sept 2015 14 | by Arturo Guadalupi 15 | modified 23 Jun 2017 16 | by Wi6Labs 17 | modified 1 Jun 2018 18 | by sstaub 19 | */ 20 | 21 | #include 22 | #include 23 | 24 | // Initialize the Ethernet client library 25 | // with the IP address and port of the server 26 | // that you want to connect to (port 80 is default for HTTP): 27 | EthernetClient client; 28 | 29 | // Last Logging Time (MilliSecond) 30 | unsigned long lastLoggingTime = 0; 31 | 32 | void printCoreVersion() 33 | { 34 | Serial.print("My Core version: "); 35 | Serial.print(STM32_CORE_VERSION_MAJOR); 36 | Serial.print("."); 37 | Serial.print(STM32_CORE_VERSION_MINOR); 38 | Serial.print("."); 39 | Serial.print(STM32_CORE_VERSION_PATCH); 40 | Serial.println(); 41 | } 42 | 43 | void printIPAddress() 44 | { 45 | Serial.print("My IP address: "); 46 | for (byte thisByte = 0; thisByte < 4; thisByte++) { 47 | // print the value of each byte of the IP address: 48 | Serial.print(Ethernet.localIP()[thisByte], DEC); 49 | if (thisByte < 3) Serial.print("."); 50 | } 51 | 52 | Serial.println(); 53 | } 54 | 55 | 56 | void setup() { 57 | // Open serial communications and wait for port to open: 58 | Serial.begin(115200); 59 | // this check is only needed on the Leonardo: 60 | while (!Serial) { 61 | ; // wait for serial port to connect. Needed for native USB port only 62 | } 63 | 64 | // start the Ethernet connection: 65 | Serial.println("start the Ethernet connection"); 66 | if (Ethernet.begin() == 0) { 67 | Serial.println("Failed to configure Ethernet using DHCP"); 68 | // no point in carrying on, so do nothing forevermore: 69 | for (;;) 70 | ; 71 | } 72 | 73 | // print my core version 74 | printCoreVersion(); 75 | // print my local IP address 76 | printIPAddress(); 77 | lastLoggingTime = millis(); 78 | } 79 | 80 | void loop() { 81 | 82 | switch (Ethernet.maintain()) 83 | { 84 | case 1: 85 | //renewed fail 86 | Serial.println("Error: renewed fail"); 87 | break; 88 | 89 | case 2: 90 | //renewed success 91 | Serial.println("Renewed success"); 92 | 93 | case 3: 94 | //rebind fail 95 | Serial.println("Error: rebind fail"); 96 | break; 97 | 98 | case 4: 99 | //rebind success 100 | Serial.println("Rebind success"); 101 | 102 | default: 103 | //nothing happened 104 | break; 105 | 106 | } // end swich 107 | 108 | unsigned long now = millis(); 109 | if ( (now - lastLoggingTime) < 0) { 110 | lastLoggingTime = now; 111 | } 112 | if ( (now - lastLoggingTime) > 1000) { 113 | lastLoggingTime = now; 114 | printIPAddress(); 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /UdpNtpClient_LAN8720/UdpNtpClient_LAN8720.ino: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Udp NTP Client 4 | 5 | Get the time from a Network Time Protocol (NTP) time server 6 | Demonstrates use of UDP sendPacket and ReceivePacket 7 | For more on NTP time servers and the messages needed to communicate with them, 8 | see http://en.wikipedia.org/wiki/Network_Time_Protocol 9 | 10 | created 4 Sep 2010 11 | by Michael Margolis 12 | modified 9 Apr 2012 13 | by Tom Igoe 14 | modified 02 Sept 2015 15 | by Arturo Guadalupi 16 | modified 23 Jun 2017 17 | by Wi6Labs 18 | modified 1 Jun 2018 19 | by sstaub 20 | This code is in the public domain. 21 | 22 | */ 23 | 24 | #include 25 | #include 26 | #include 27 | #include // https://github.com/PaulStoffregen/Time 28 | 29 | // Your NTP Server 30 | #define NTP_SERVER "pool.ntp.org" 31 | // Your local time zone 32 | #define TIME_ZONE 9 33 | // local port to listen for UDP packets 34 | #define LOCAL_PORT 8888 35 | 36 | // NTP time stamp is in the first 48 bytes of the message 37 | #define NTP_PACKET_SIZE 48 38 | byte packetBuffer[ NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing packets 39 | 40 | // A UDP instance to let us send and receive packets over UDP 41 | EthernetUDP Udp; 42 | 43 | // Get Day of the week string [Sun,Mon....] 44 | char * dow2char(byte days) { 45 | char *dayOfWeek[] = {"Sun","Mon","Tue","Wed","Thu","Fri","Sat"}; 46 | return dayOfWeek[days]; 47 | } 48 | 49 | // Get Day of the week [0-Sunday, 1-Monday etc.] 50 | uint8_t get_dow(unsigned long t) { 51 | return ((t / 86400) + 4) % 7; 52 | } 53 | 54 | void showTime(char * title, time_t timet, char * dow) { 55 | Serial.print(title); 56 | Serial.print(year(timet)); 57 | Serial.print("/"); 58 | Serial.print(month(timet)); 59 | Serial.print("/"); 60 | Serial.print(day(timet)); 61 | Serial.print(" "); 62 | Serial.print(hour(timet)); 63 | Serial.print(":"); 64 | Serial.print(minute(timet)); 65 | Serial.print(":"); 66 | Serial.print(second(timet)); 67 | Serial.print(" ["); 68 | Serial.print(dow); 69 | Serial.println("]"); 70 | } 71 | 72 | void setup() { 73 | // Open serial communications and wait for port to open: 74 | Serial.begin(115200); 75 | while (!Serial) { 76 | ; // wait for serial port to connect. Needed for native USB port only 77 | } 78 | 79 | // start Ethernet and UDP 80 | Serial.println("Begin Ethernet"); 81 | if (Ethernet.begin() == 0) { 82 | Serial.println("Failed to configure Ethernet using DHCP"); 83 | // no point in carrying on, so do nothing forevermore: 84 | for (;;) 85 | ; 86 | } 87 | Serial.println("Success to configure Ethernet using DHCP"); 88 | 89 | Serial.print("localIP: "); 90 | Serial.println(Ethernet.localIP()); 91 | Serial.print("subnetMask: "); 92 | Serial.println(Ethernet.subnetMask()); 93 | Serial.print("gatewayIP: "); 94 | Serial.println(Ethernet.gatewayIP()); 95 | Serial.print("dnsServerIP: "); 96 | Serial.println(Ethernet.dnsServerIP()); 97 | 98 | Udp.begin(LOCAL_PORT); 99 | } 100 | 101 | void loop() { 102 | sendNTPpacket(NTP_SERVER); // send an NTP packet to a time server 103 | 104 | // wait to see if a reply is available 105 | delay(1000); 106 | if (Udp.parsePacket()) { 107 | // We've received a packet, read the data from it 108 | Udp.read(packetBuffer, NTP_PACKET_SIZE); // read the packet into the buffer 109 | 110 | // the timestamp starts at byte 40 of the received packet and is four bytes, 111 | // or two words, long. First, extract the two words: 112 | 113 | unsigned long highWord = word(packetBuffer[40], packetBuffer[41]); 114 | unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]); 115 | // combine the four bytes (two words) into a long integer 116 | // this is NTP time (seconds since Jan 1 1900): 117 | unsigned long secsSince1900 = highWord << 16 | lowWord; 118 | //Serial.print("Seconds since Jan 1 1900 = "); 119 | //Serial.println(secsSince1900); 120 | 121 | // now convert NTP time into UNIX time: 122 | // UNIX time starts on Jan 1 1970. In seconds, that's 2208988800: 123 | const unsigned long seventyYears = 2208988800UL; 124 | // subtract seventy years: 125 | unsigned long epoch = secsSince1900 - seventyYears; 126 | Serial.print("Unix time = "); 127 | Serial.println(epoch); 128 | 129 | // Greenwich Mean Time 130 | uint8_t DayOfWeek = get_dow(epoch); 131 | showTime("The UTC time is ", (time_t)epoch, dow2char(DayOfWeek)); 132 | 133 | // Local Time 134 | if (TIME_ZONE != 0) { 135 | unsigned long epochLocal = epoch + (TIME_ZONE * 60 * 60); 136 | DayOfWeek = get_dow(epochLocal); 137 | showTime("The LOCAL time is ", (time_t)epochLocal, dow2char(DayOfWeek)); 138 | } 139 | 140 | } 141 | // wait ten seconds before asking for the time again 142 | delay(10000); 143 | Ethernet.maintain(); 144 | } 145 | 146 | // send an NTP request to the time server at the given address 147 | void sendNTPpacket(char* address) { 148 | // set all bytes in the buffer to 0 149 | memset(packetBuffer, 0, NTP_PACKET_SIZE); 150 | // Initialize values needed to form NTP request 151 | // (see URL above for details on the packets) 152 | packetBuffer[0] = 0b11100011; // LI, Version, Mode 153 | packetBuffer[1] = 0; // Stratum, or type of clock 154 | packetBuffer[2] = 6; // Polling Interval 155 | packetBuffer[3] = 0xEC; // Peer Clock Precision 156 | // 8 bytes of zero for Root Delay & Root Dispersion 157 | packetBuffer[12] = 49; 158 | packetBuffer[13] = 0x4E; 159 | packetBuffer[14] = 49; 160 | packetBuffer[15] = 52; 161 | 162 | // all NTP fields have been given values, now 163 | // you can send a packet requesting a timestamp: 164 | Udp.beginPacket(address, 123); //NTP requests are to port 123 165 | Udp.write(packetBuffer, NTP_PACKET_SIZE); 166 | Udp.endPacket(); 167 | } 168 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # STM32Ethernet_LAN8720 2 | 3 | STM provides an Ethernet library for Arduino_Core_STM32, but it supports only LAN8742A. 4 | However, it is difficult to get LAN8742 PHY. 5 | We can get the LAN8720 PHY cheaply instead of the LAN8742 PHY. 6 | With a little change, You can use LAN8720 PHY with STM32F407. 7 | 8 | __Note__ 9 | STM is currently rebuilding external PHY Ethernet support for Arduino_Core_STM32. 10 | In the future, Ethernet support using external PHYs will change significantly and support may change. 11 | This is an interim action until officially supported. 12 | When STM become officially supports external PHY Ethernet, I will delete this repository. 13 | 14 | # Hardware requirements 15 | 16 | - STM32F407VET6/VGT6 Development Board. About $10 for AliExpress/eBay. 17 | - LAN8720 PHY module. About $2 for AliExpress/eBay. 18 | - STM32 NUCLEO Board. Because we need STLink V2.1 for farmware writting. 19 | 20 | - Board parts number is DIYMORE STM32F407VGT. 21 | ![LAN8720-2](https://user-images.githubusercontent.com/6020549/62419501-80a64d00-b6bc-11e9-9cc1-9293446bec45.JPG) 22 | 23 | - Board parts number is Black F407VE. 24 | ![LAN8720-11](https://user-images.githubusercontent.com/6020549/62419879-2362c980-b6c5-11e9-8bd9-0fc0ef1444b0.JPG) 25 | 26 | - Board parts number is Black F407VE. 27 | ![LAN8720-21](https://user-images.githubusercontent.com/6020549/62815224-ca29e880-bb51-11e9-9197-a6f8a1870501.JPG) 28 | 29 | # Software requirements 30 | - Arduino IDE 31 | I used V1.8.19 32 | ![ArduinoIDE_V1 8 19](https://github.com/nopnop2002/Arduino-STM32-Ethernet-LAN8720/assets/6020549/d0211c18-b77e-436f-b931-8a9759f833eb) 33 | 34 | - Arduino core support for STM32 based boards. 35 | https://github.com/stm32duino/Arduino_Core_STM32 36 | ___Note for Core version___ 37 | Requires core version 2.3 or higher. 38 | Core version 2.8 or later requires Arduino IDE 2.x. 39 | I used version 2.7.1. 40 | This is the final version available for Arduino IDE 1.x. 41 | ![STM32_Core_2 7 1](https://github.com/user-attachments/assets/e135c6b2-61f5-4ac8-a4e5-8878a29a2be4) 42 | 43 | - Arduino library to support Ethernet for STM32 based board. 44 | https://github.com/stm32duino/STM32Ethernet 45 | ___Note for library name___ 46 | When installed using the ZIP file, it will be ```STM32Ethernet```. 47 | When installed using the Library Manager, it will be ```STM32duino_STM32Ethernet```. 48 | Installing using the ZIP file and then updating using the Library Manager will result in duplicate libraries. 49 | 50 | - Lightweight TCP/IP stack (LwIP) is a small independent implementation of the TCP/IP protocol suite. 51 | https://github.com/stm32duino/LwIP 52 | ![Arduino-STM32-Ethernet-LAN8720](https://user-images.githubusercontent.com/6020549/231913627-4294b712-bde5-4735-8569-46199f85e8d9.jpg) 53 | 54 | # Library modify 55 | You have to modify your local file. 56 | The file location is ```C:\Users\user\AppData\Local\Arduino15\packages\STMicroelectronics\hardware\stm32\2.7.1\system\STM32F4xx```. 57 | ___The file location may vary depending on core library version.___ 58 | Please look for ```stm32f4xx_hal_conf_default.h```. 59 | 60 | [stm32f4xx_hal_conf_default.h](https://github.com/stm32duino/Arduino_Core_STM32/blob/85fd492c15a87048086e7e82318c555fb6410a41/system/STM32F4xx/stm32f4xx_hal_conf_default.h#L233-L273) 61 | 62 | - Before change 63 | ``` 64 | /* Section 2: PHY configuration section */ 65 | /* LAN8742A PHY Address*/ 66 | #define LAN8742A_PHY_ADDRESS 0x00U 67 | ``` 68 | 69 | - After change 70 | ``` 71 | /* Section 2: PHY configuration section */ 72 | #if !defined (LAN8742A_PHY_ADDRESS) 73 | /* LAN8742A PHY Address*/ 74 | #define LAN8742A_PHY_ADDRESS 0x00U 75 | #endif 76 | ``` 77 | 78 | # Wireing 79 | 80 | |LAN8720 PHY|---|STM32F407| 81 | |:-:|:-:|:-:| 82 | |TX1|---|PB_13| 83 | |TX_EN|---|PB_11| 84 | |TX0|---|PB_12| 85 | |RX0|---|PC_4| 86 | |RX1|---|PC_5| 87 | |nINT/RETCLK|---|PA_1| 88 | |CRS|---|PA_7| 89 | |MDIO|---|PA_2| 90 | |MDC|---|PC_1| 91 | |GND|---|GND| 92 | |VCC|---|+3.3V| 93 | 94 | # How to flash 95 | 96 | STM32 NUCLEO provides a on-board STLINK-V2.1 USB interface. 97 | Actually the board has two STM32 chips. One is the target of the demo board, and the other is the STLINK. 98 | This STLINK-V2.1 can be used as programmer and debugger for external targets. 99 | Remove the two jumpers from CN2, and place them at the two outermost empty jumper pins marked CN11 and CN12. 100 | SWD port pinmap for using the Nucleo as a programming device can be found [here](https://os.mbed.com/questions/7974/F401RE-Cut-off-ST-LINK/). 101 | 102 | Connect the NUCLEO SWD port to the STM32F407. 103 | 104 | |NUCLEO SWD|---|STM32F407| 105 | |:-:|:-:|:-:| 106 | |SWDIO|---|PA_13| 107 | |SWCLK|---|PA_14| 108 | |nRST|---|RESET(*1)| 109 | |GND|---|GND| 110 | |+3.3V|---|+3.3V| 111 | 112 | __(*1)If a non-standard BootLoader has already been written to STM32, connection of nRTS pin and RESET pin is required.__ 113 | 114 | Choose Tool->Upload method "STM32CubeProgrammer(SWD)" 115 | 116 | __Please note the board part number.__ 117 | Some boards do not support Ethernet. 118 | 119 | ![LAN8720-Arduino](https://user-images.githubusercontent.com/6020549/113068815-07952b00-91fa-11eb-8e88-1f7aa6a9b79a.JPG) 120 | 121 | # Serial monitor 122 | 123 | You need to use a USB-TTL converter to display the serial output. 124 | 125 | |USB-TTL|---|STM32F407| 126 | |:-:|:-:|:-:| 127 | |TX|---|PA_9| 128 | |GND|---|GND| 129 | 130 | ___Note for Virtual COM port___ 131 | STM32F407 can use a Virtual COM port. 132 | If you enable Virtual COM port, you can use the USB port as a serial port. 133 | But Ethernet and Virtual COM port cannot be used at the same time. 134 | Something is probably in conflict. 135 | Don't use USB Support. 136 | 137 | # Other examples 138 | There is other examples provided by STM. 139 | To use these you need to add hal_conf_extra.h. 140 | https://github.com/stm32duino/STM32Ethernet/tree/main/examples 141 | --------------------------------------------------------------------------------