Ethernet for Nucleo and Disco board STM32F746 works with gcc and arm. IAC is untested
Fork of F7_Ethernet by
EthernetInterface.h@0:d26c1b55cfca, 2016-06-19 (annotated)
- Committer:
- DieterGraef
- Date:
- Sun Jun 19 16:23:40 2016 +0000
- Revision:
- 0:d26c1b55cfca
- Child:
- 2:11660e6c9d7a
Ethernet Library for Nucleo stm32f746ZG and Disco stm32f746NG works under arm and gcc environment
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
DieterGraef | 0:d26c1b55cfca | 1 | /* EthernetInterface.h */ |
DieterGraef | 0:d26c1b55cfca | 2 | /* Copyright (C) 2012 mbed.org, MIT License |
DieterGraef | 0:d26c1b55cfca | 3 | * |
DieterGraef | 0:d26c1b55cfca | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
DieterGraef | 0:d26c1b55cfca | 5 | * and associated documentation files (the "Software"), to deal in the Software without restriction, |
DieterGraef | 0:d26c1b55cfca | 6 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
DieterGraef | 0:d26c1b55cfca | 7 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
DieterGraef | 0:d26c1b55cfca | 8 | * furnished to do so, subject to the following conditions: |
DieterGraef | 0:d26c1b55cfca | 9 | * |
DieterGraef | 0:d26c1b55cfca | 10 | * The above copyright notice and this permission notice shall be included in all copies or |
DieterGraef | 0:d26c1b55cfca | 11 | * substantial portions of the Software. |
DieterGraef | 0:d26c1b55cfca | 12 | * |
DieterGraef | 0:d26c1b55cfca | 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
DieterGraef | 0:d26c1b55cfca | 14 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
DieterGraef | 0:d26c1b55cfca | 15 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
DieterGraef | 0:d26c1b55cfca | 16 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
DieterGraef | 0:d26c1b55cfca | 17 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
DieterGraef | 0:d26c1b55cfca | 18 | */ |
DieterGraef | 0:d26c1b55cfca | 19 | |
DieterGraef | 0:d26c1b55cfca | 20 | #ifndef ETHERNETINTERFACE_H_ |
DieterGraef | 0:d26c1b55cfca | 21 | #define ETHERNETINTERFACE_H_ |
DieterGraef | 0:d26c1b55cfca | 22 | |
DieterGraef | 0:d26c1b55cfca | 23 | #if !defined(TARGET_STM32F746ZG) && !defined(TARGET_STM32F746NG) |
DieterGraef | 0:d26c1b55cfca | 24 | #error The Ethernet Interface library is not supported on this target |
DieterGraef | 0:d26c1b55cfca | 25 | #endif |
DieterGraef | 0:d26c1b55cfca | 26 | |
DieterGraef | 0:d26c1b55cfca | 27 | #include "rtos.h" |
DieterGraef | 0:d26c1b55cfca | 28 | #include "lwip/netif.h" |
DieterGraef | 0:d26c1b55cfca | 29 | |
DieterGraef | 0:d26c1b55cfca | 30 | /** Interface using Ethernet to connect to an IP-based network |
DieterGraef | 0:d26c1b55cfca | 31 | * |
DieterGraef | 0:d26c1b55cfca | 32 | */ |
DieterGraef | 0:d26c1b55cfca | 33 | class EthernetInterface { |
DieterGraef | 0:d26c1b55cfca | 34 | public: |
DieterGraef | 0:d26c1b55cfca | 35 | /** Initialize the interface with DHCP. |
DieterGraef | 0:d26c1b55cfca | 36 | * Initialize the interface and configure it to use DHCP (no connection at this point). |
DieterGraef | 0:d26c1b55cfca | 37 | * \return 0 on success, a negative number on failure |
DieterGraef | 0:d26c1b55cfca | 38 | */ |
DieterGraef | 0:d26c1b55cfca | 39 | static int init(); //With DHCP |
DieterGraef | 0:d26c1b55cfca | 40 | |
DieterGraef | 0:d26c1b55cfca | 41 | /** Initialize the interface with a static IP address. |
DieterGraef | 0:d26c1b55cfca | 42 | * Initialize the interface and configure it with the following static configuration (no connection at this point). |
DieterGraef | 0:d26c1b55cfca | 43 | * \param ip the IP address to use |
DieterGraef | 0:d26c1b55cfca | 44 | * \param mask the IP address mask |
DieterGraef | 0:d26c1b55cfca | 45 | * \param gateway the gateway to use |
DieterGraef | 0:d26c1b55cfca | 46 | * \return 0 on success, a negative number on failure |
DieterGraef | 0:d26c1b55cfca | 47 | */ |
DieterGraef | 0:d26c1b55cfca | 48 | static int init(const char* ip, const char* mask, const char* gateway); |
DieterGraef | 0:d26c1b55cfca | 49 | |
DieterGraef | 0:d26c1b55cfca | 50 | /** Connect |
DieterGraef | 0:d26c1b55cfca | 51 | * Bring the interface up, start DHCP if needed. |
DieterGraef | 0:d26c1b55cfca | 52 | * \param timeout_ms timeout in ms (default: (15)s). |
DieterGraef | 0:d26c1b55cfca | 53 | * \return 0 on success, a negative number on failure |
DieterGraef | 0:d26c1b55cfca | 54 | */ |
DieterGraef | 0:d26c1b55cfca | 55 | static int connect(unsigned int timeout_ms=15000); |
DieterGraef | 0:d26c1b55cfca | 56 | |
DieterGraef | 0:d26c1b55cfca | 57 | /** Disconnect |
DieterGraef | 0:d26c1b55cfca | 58 | * Bring the interface down |
DieterGraef | 0:d26c1b55cfca | 59 | * \return 0 on success, a negative number on failure |
DieterGraef | 0:d26c1b55cfca | 60 | */ |
DieterGraef | 0:d26c1b55cfca | 61 | static int disconnect(); |
DieterGraef | 0:d26c1b55cfca | 62 | |
DieterGraef | 0:d26c1b55cfca | 63 | /** Get the MAC address of your Ethernet interface |
DieterGraef | 0:d26c1b55cfca | 64 | * \return a pointer to a string containing the MAC address |
DieterGraef | 0:d26c1b55cfca | 65 | */ |
DieterGraef | 0:d26c1b55cfca | 66 | static char* getMACAddress(); |
DieterGraef | 0:d26c1b55cfca | 67 | |
DieterGraef | 0:d26c1b55cfca | 68 | /** Get the IP address of your Ethernet interface |
DieterGraef | 0:d26c1b55cfca | 69 | * \return a pointer to a string containing the IP address |
DieterGraef | 0:d26c1b55cfca | 70 | */ |
DieterGraef | 0:d26c1b55cfca | 71 | static char* getIPAddress(); |
DieterGraef | 0:d26c1b55cfca | 72 | |
DieterGraef | 0:d26c1b55cfca | 73 | /** Get the Gateway address of your Ethernet interface |
DieterGraef | 0:d26c1b55cfca | 74 | * \return a pointer to a string containing the Gateway address |
DieterGraef | 0:d26c1b55cfca | 75 | */ |
DieterGraef | 0:d26c1b55cfca | 76 | static char* getGateway(); |
DieterGraef | 0:d26c1b55cfca | 77 | |
DieterGraef | 0:d26c1b55cfca | 78 | /** Get the Network mask of your Ethernet interface |
DieterGraef | 0:d26c1b55cfca | 79 | * \return a pointer to a string containing the Network mask |
DieterGraef | 0:d26c1b55cfca | 80 | */ |
DieterGraef | 0:d26c1b55cfca | 81 | static char* getNetworkMask(); |
DieterGraef | 0:d26c1b55cfca | 82 | }; |
DieterGraef | 0:d26c1b55cfca | 83 | |
DieterGraef | 0:d26c1b55cfca | 84 | #include "TCPSocketConnection.h" |
DieterGraef | 0:d26c1b55cfca | 85 | #include "TCPSocketServer.h" |
DieterGraef | 0:d26c1b55cfca | 86 | |
DieterGraef | 0:d26c1b55cfca | 87 | #include "Endpoint.h" |
DieterGraef | 0:d26c1b55cfca | 88 | #include "UDPSocket.h" |
DieterGraef | 0:d26c1b55cfca | 89 | |
DieterGraef | 0:d26c1b55cfca | 90 | #endif /* ETHERNETINTERFACE_H_ */ |