How to set a MAC address

cancel
Showing results for 
Search instead for 
Did you mean: 

How to set a MAC address

Jump to solution
2,534 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
1,069 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

5 Replies
1,069 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 


1,069 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

1,070 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

1,069 Views
gustavocosta
Contributor III

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

BR

Gustavo Costa

R&D Engineer

1,069 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