Skip to content

Commit 83599b5

Browse files
committed
1 parent 52aba52 commit 83599b5

File tree

4 files changed

+37
-30
lines changed

4 files changed

+37
-30
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ extend the default one by adding some extra configuration in a file named `lwipo
2929

3030
## New alternative init procedure **!!!**
3131

32-
There are alternative inits of the Ethernetinterface with following orders:
32+
There are alternative inits of the Ethernet interface with following orders:
3333

3434
Ethernet.begin();
3535
Ethernet.begin(ip);
@@ -39,16 +39,16 @@ There are alternative inits of the Ethernetinterface with following orders:
3939

4040
This is more logical. A MAC address is no more needed and will retrieved internally by the mbed MAC address!
4141

42-
You can get the MAC address with following function, this must done after Ethernet.Begin()
42+
You can get the MAC address with following function, this must be done after Ethernet.Begin()
4343

4444
uint8_t *mac;
4545
Ethernet.begin();
46-
mac = Ethernet.MACAddress();
46+
Ethernet.MACAddress(mac);
4747

48-
You can also set a new user based MAC address, this must done before Ethernet.begin()
48+
You can also set a new user based MAC address, this must be done before Ethernet.begin()
4949

5050
uint8_t newMAC[] = {0x00, 0x80, 0xE1, 0x01, 0x01, 0x01};
51-
Ethernet.MACAddress(newMAC);
51+
Ethernet.setMACAddress(newMAC);
5252
Ethernet.begin();
5353

5454
## Note

keywords.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,11 @@ localPort KEYWORD2
3838
maintain KEYWORD2
3939
linkStatus KEYWORD2
4040
MACAddress KEYWORD2
41+
setMACAddress KEYWORD2
4142
subnetMask KEYWORD2
4243
gatewayIP KEYWORD2
4344
dnsServerIP KEYWORD2
45+
setDnsServerIP KEYWORD2
4446
setConnectionTimeout KEYWORD2
4547

4648
#######################################

src/STM32Ethernet.cpp

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ int EthernetClass::begin(unsigned long timeout, unsigned long responseTimeout)
88
stm32_eth_init(MACAddressDefault(), NULL, NULL, NULL);
99

1010
// Now try to get our config info from a DHCP server
11-
int ret = _dhcp->beginWithDHCP(mac_address, timeout, responseTimeout);
11+
int ret = _dhcp->beginWithDHCP(_mac_address, timeout, responseTimeout);
1212
if (ret == 1) {
1313
_dnsServerAddress = _dhcp->getDnsServerIp();
1414
}
@@ -58,7 +58,7 @@ int EthernetClass::begin(uint8_t *mac_address, unsigned long timeout, unsigned l
5858
if (ret == 1) {
5959
_dnsServerAddress = _dhcp->getDnsServerIp();
6060
}
61-
MACAddress(mac_address);
61+
setMACAddress(mac_address);
6262
return ret;
6363
}
6464

@@ -86,14 +86,14 @@ void EthernetClass::begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dn
8686
begin(mac_address, local_ip, dns_server, gateway, subnet);
8787
}
8888

89-
void EthernetClass::begin(uint8_t *mac, IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet)
89+
void EthernetClass::begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet)
9090
{
91-
stm32_eth_init(mac, local_ip.raw_address(), gateway.raw_address(), subnet.raw_address());
91+
stm32_eth_init(mac_address, local_ip.raw_address(), gateway.raw_address(), subnet.raw_address());
9292
/* If there is a local DHCP informs it of our manual IP configuration to
9393
prevent IP conflict */
9494
stm32_DHCP_manual_config();
9595
_dnsServerAddress = dns_server;
96-
MACAddress(mac);
96+
setMACAddress(mac_address);
9797
}
9898

9999
EthernetLinkStatus EthernetClass::linkStatus()
@@ -135,31 +135,36 @@ void EthernetClass::schedule(void)
135135

136136
uint8_t *EthernetClass::MACAddressDefault(void)
137137
{
138-
if ((mac_address[0] + mac_address[1] + mac_address[2] + mac_address[3] + mac_address[4] + mac_address[5]) == 0) {
138+
if ((_mac_address[0] + _mac_address[1] + _mac_address[2] + _mac_address[3] + _mac_address[4] + _mac_address[5]) == 0) {
139139
uint32_t baseUID = *(uint32_t *)UID_BASE;
140-
mac_address[0] = 0x00;
141-
mac_address[1] = 0x80;
142-
mac_address[2] = 0xE1;
143-
mac_address[3] = (baseUID & 0x00FF0000) >> 16;
144-
mac_address[4] = (baseUID & 0x0000FF00) >> 8;
145-
mac_address[5] = (baseUID & 0x000000FF);
140+
_mac_address[0] = 0x00;
141+
_mac_address[1] = 0x80;
142+
_mac_address[2] = 0xE1;
143+
_mac_address[3] = (baseUID & 0x00FF0000) >> 16;
144+
_mac_address[4] = (baseUID & 0x0000FF00) >> 8;
145+
_mac_address[5] = (baseUID & 0x000000FF);
146146
}
147-
return mac_address;
147+
return _mac_address;
148148
}
149149

150-
void EthernetClass::MACAddress(uint8_t *mac)
150+
void EthernetClass::setMACAddress(const uint8_t *mac_address)
151151
{
152-
mac_address[0] = mac[0];
153-
mac_address[1] = mac[1];
154-
mac_address[2] = mac[2];
155-
mac_address[3] = mac[3];
156-
mac_address[4] = mac[4];
157-
mac_address[5] = mac[5];
152+
_mac_address[0] = mac_address[0];
153+
_mac_address[1] = mac_address[1];
154+
_mac_address[2] = mac_address[2];
155+
_mac_address[3] = mac_address[3];
156+
_mac_address[4] = mac_address[4];
157+
_mac_address[5] = mac_address[5];
158158
}
159159

160-
uint8_t *EthernetClass::MACAddress(void)
160+
void EthernetClass::MACAddress(uint8_t *mac_address)
161161
{
162-
return mac_address;
162+
mac_address[0] = _mac_address[0];
163+
mac_address[1] = _mac_address[1];
164+
mac_address[2] = _mac_address[2];
165+
mac_address[3] = _mac_address[3];
166+
mac_address[4] = _mac_address[4];
167+
mac_address[5] = _mac_address[5];
163168
}
164169

165170
IPAddress EthernetClass::localIP()

src/STM32Ethernet.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class EthernetClass {
1717
private:
1818
IPAddress _dnsServerAddress;
1919
DhcpClass *_dhcp;
20-
uint8_t mac_address[6];
20+
uint8_t _mac_address[6];
2121
uint8_t *MACAddressDefault(void);
2222

2323
public:
@@ -43,13 +43,13 @@ class EthernetClass {
4343
int maintain();
4444
void schedule(void);
4545

46-
void MACAddress(uint8_t *mac);
47-
uint8_t *MACAddress(void);
46+
void MACAddress(uint8_t *mac_address);
4847
IPAddress localIP();
4948
IPAddress subnetMask();
5049
IPAddress gatewayIP();
5150
IPAddress dnsServerIP();
5251

52+
void setMACAddress(const uint8_t *mac_address);
5353
void setDnsServerIP(const IPAddress dns_server);
5454

5555
friend class EthernetClient;

0 commit comments

Comments
 (0)