Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: align MAC address api with Arduino reference #89

Merged
merged 3 commits into from
Sep 11, 2024

Conversation

fpistm
Copy link
Member

@fpistm fpistm commented Sep 10, 2024

References:
https://www.arduino.cc/reference/en/libraries/ethernet/ethernet.macaddress/ https://www.arduino.cc/reference/en/libraries/ethernet/ethernet.setmacaddress/

Important

Pay attention that setMACAddress() have to be called before Begin().
Else new MAC will be ignored.

This PR also fixes with the default MAC address usage. It is used only if one or more MAC_ADDRx defined.
The MAC address is also correct at all level.

Fixes #81

Test sketch

#include <LwIP.h>
#include <STM32Ethernet.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 1, 69);

void printMacAddress(byte* macBuffer) {
  Serial.print("The MAC address is: ");
  for (byte octet = 0; octet < 6; octet++) {
    Serial.printf("%02X", macBuffer[octet]);
    if (octet < 5) {
      Serial.print('-');
    } else {
      Serial.println();
    }
  }
}

void setup() {
  Serial.begin(9600);
  while (!Serial) {};
  byte macBuffer[6];  // create a buffer to hold the MAC address
  byte newMac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };

  Ethernet.MACAddress(macBuffer);  // fill the buffer
  printMacAddress(macBuffer);      // print default MAC address
  // Selectdesired config for the test
  // Ethernet.setMACAddress(newMac);  // change the MAC address
  // Ethernet.begin(mac, ip);
  // Ethernet.begin(ip);
  Ethernet.MACAddress(macBuffer);  // fill the buffer
  printMacAddress(macBuffer);
  Ethernet.setMACAddress(newMac);  // change the MAC address
  Ethernet.MACAddress(macBuffer);  // fill the buffer
  printMacAddress(macBuffer);
}

void loop() {
}

@fpistm fpistm added this to the 1.4.1/1.5.0 milestone Sep 10, 2024
@fpistm fpistm marked this pull request as draft September 10, 2024 15:07
Signed-off-by: Frederic Pillon <[email protected]>
Anyway the MAC address get by the application is always 0 while
the real address is correct.
Will be fixed by latter commit.

Signed-off-by: Frederic Pillon <[email protected]>
@fpistm fpistm force-pushed the MACAddress branch 2 times, most recently from 5a50a4e to ac94829 Compare September 11, 2024 09:01
@fpistm fpistm marked this pull request as ready for review September 11, 2024 12:36
@fpistm fpistm merged commit 055af9a into stm32duino:main Sep 11, 2024
3 checks passed
@fpistm fpistm deleted the MACAddress branch September 11, 2024 12:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

Ethernet.MACAddress should be a getter, not setter
1 participant