How to set a MAC address

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to set a MAC address

Jump to solution
8,757 Views
biafra
Senior Contributor I

Hi everyone,

 

I'm new in unsing lwIP.

I'm developing a board using NXP Kinetis K65 device, with FreeRTOS and lwIP, and IAR EWARM compiler/debugger.
I'm testing my application and everything seems woking fine.


Now my problem is how to set a different MAC address for every physical device: I've browsed the source code and it seems that the MAC address is hardcoded in the source file (ethernetif.h).
My idea is to read the MAC address from an otp memory and set it during the initialization phase.

 

Has anyone some suggestion to solve my problem?

 

Many thanks
Biafra

Labels (1)
1 Solution
7,292 Views
biafra
Senior Contributor I

Hi Gustavo,

I think I've found the solution.

extern unsigned char MACAddress[ 6 ];

...

#define configMAC_ADDR0 MACAddress[ 0 ]
#define configMAC_ADDR1 MACAddress[ 1 ]
#define configMAC_ADDR2 MACAddress[ 2 ]
#define configMAC_ADDR3 MACAddress[ 3 ]
#define configMAC_ADDR4 MACAddress[ 4 ]
#define configMAC_ADDR5 MACAddress[ 5 ]

...

memcpy( MACAddress, Mac, sizeof( MACAddress));

Many thanks

Biafra

View solution in original post

6 Replies
7,292 Views
bobpaddock
Senior Contributor III

Software Safety: Automatic Serial Number for Test Driven Development. Makefile Tip #0 
There I show how to create an incrementing define in C.

Look at your programming equipment as many have ways to do this as each chip is programmed.

Some vendors will do it as well.

An other option is to buy a EEPROM chip that has the MAC in it 

MAC Address Chips Products - Microchip Technology Inc 

this has the advantage of not having to screw around with IEEE MAC licensing etc.


IEEE-SA - Registration Authority Standard Group MAC Address 

IEEE-SA - FAQs: Registration Authority 


7,292 Views
gustavocosta
Contributor III

Hello bobpaddock,

I believe that what francescobianchini meant was: how to configure the driver with the MAC address I've obtained from a EEPROM (for example) during run-time? Since in lwIP it is hard-coded in the file ethernetif.c and ethernetif.h:

pastedImage_3.png

pastedImage_4.png

Thank you very much.

BR

Gustavo Costa

R&D Engineer

7,293 Views
biafra
Senior Contributor I

Hi Gustavo,

I think I've found the solution.

extern unsigned char MACAddress[ 6 ];

...

#define configMAC_ADDR0 MACAddress[ 0 ]
#define configMAC_ADDR1 MACAddress[ 1 ]
#define configMAC_ADDR2 MACAddress[ 2 ]
#define configMAC_ADDR3 MACAddress[ 3 ]
#define configMAC_ADDR4 MACAddress[ 4 ]
#define configMAC_ADDR5 MACAddress[ 5 ]

...

memcpy( MACAddress, Mac, sizeof( MACAddress));

Many thanks

Biafra

7,292 Views
gustavocosta
Contributor III

Thank you for sharing francescobianchini‌. I'll do that.

BR

Gustavo Costa

R&D Engineer

7,292 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Francesco,

In a local ethernet, the mac address is gotten  from a server generally so that the mac address is guaranteed to not conflict with the other user who use the same local network. This is called DHCP, but it seems that we have not the code for the DHCP, the LWIP stack supports DHCP.

If you want to save mac into OTP memory, as you know that the K66 has IFR in flash module, you can save the mac address in IFR.

Hope it can help you

BR

Xiangjun Rong

5,749 Views
jensseifr
Contributor II

A MAC-Adress is never given by a Server to a Device.... It´s the IP-Adress, which must be uniqu in an Network, equal its local or global WWW.

A MAC Adress is also a unique Adress given to an Hardware, in best case hardcoded in the Hardware itself, and can´t normally be changed. And those MAC-Adresses had to be bought and given to the Hardware by the Manufacturer. Every network able device in the world has its unique MAC, so a device can be identified with it.

This makes the DHCP possible to block devices from an Network by MAC-Filter. Without Filter every device connected to the network is given an IP (by Server or provider, etc..)  to enable communication between them. And those IPs had to be also unique in the Network.

 

 

0 Kudos
Reply