How to set a MAC address

取消
显示结果 
搜索替代 
您的意思是: 
已解决

How to set a MAC address

跳至解决方案
4,385 次查看
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

标签 (1)
1 解答
2,920 次查看
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

在原帖中查看解决方案

6 回复数
2,920 次查看
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 


2,920 次查看
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

2,921 次查看
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

2,920 次查看
gustavocosta
Contributor III

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

BR

Gustavo Costa

R&D Engineer

2,920 次查看
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

1,377 次查看
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 项奖励