Mac address on FRDM-K64F

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

Mac address on FRDM-K64F

跳至解决方案
2,771 次查看
ironsean
Contributor V

Hello, is there a Mac address assigned to the FRDM-K64F Freedom platform boards? I believe some skimming at mbed led me to believe there was. If so, is there any documentation on where and how to programmatically read and use it using MQX 4.1.1?

Thanks,

Sean

1 解答
1,244 次查看
dave408
Senior Contributor II

Sean, for deployment of a "real" product that really needs to have a unique MAC address, you can integrate a Microchip 24AA02E64 (or E48) -- it's very simple, but will cost you a little extra money and space on your PCB.

Here's how mbed does it -- they query a memory region in the K64 that is marked "System integration module (SIM)".  I don't know what this module does, but I'm going to look it up shortly.  Anyhow, here's their code for getting a "semi-unique" MAC address.  I think this is the approach I will be using in my device since it's not IoT or anything like that.

void mbed_mac_address(char *mac)

{

  // Fetch word 0

  uint32_t word0 = *(uint32_t *)0x40048060;

  // Fetch word 1

  // we only want bottom 16 bits of word1 (MAC bits 32-47)

  // and bit 1 forced to 1, bit 0 forced to 0

  // Locally administered MAC, reduced conflicts

  // http://en.wikipedia.org/wiki/MAC_address

  uint32_t word1 = *(uint32_t *)0x4004805C;

  word1 |= 0x00000002;

  word1 &= 0x0000FFFE;

  mac[0] = (word1 & 0x000000ff);

  mac[1] = (word1 & 0x0000ff00) >> 8;

  mac[2] = (word0 & 0xff000000) >> 24;

  mac[3] = (word0 & 0x00ff0000) >> 16;

  mac[4] = (word0 & 0x0000ff00) >> 8;

  mac[5] = (word0 & 0x000000ff);

}

pastedImage_0.png

pastedImage_1.png

Hope this helps.

在原帖中查看解决方案

0 项奖励
回复
9 回复数
1,244 次查看
dave408
Senior Contributor II

I don't know, Sean, I was under the same impression.  I was using a MAC/EEPROM chip from Microchip to get a MAC address for our boards before, but then got rid of my definition for mbed_mac_address and just used mbed's, which seemed to work fine.  :smileyhappy:  I don't know how they did it, but I'll dig into it a little.  It would be nice not to have to add another IC just to get a MAC if we can generate something unique with the parts already available on the board.  At least in our case, the device won't be hooked up to the internet and is limited to a single PC connection only.  I'll post up whatever I happen to find.

0 项奖励
回复
1,244 次查看
Rick_Li
NXP Employee
NXP Employee

Hi,

the MAC address is defined in frdmk64f.h which is located in {MQX}\mqx\source\bsp\frdmk64f\.

the MAC address is defined as {0x00,0x00,0x5E, 0, 0, 0} as the base address and then you can change the MAC address in file init_enet.c by re-define value of parameter "value".

I hope it helps!

0 项奖励
回复
1,244 次查看
ironsean
Contributor V

So there is no included/assigned official MAC address currently on the boards? And therefore adding a small EEPROM chip or something similar is the best way to get a valid MAC address for deployment?

0 项奖励
回复
1,245 次查看
dave408
Senior Contributor II

Sean, for deployment of a "real" product that really needs to have a unique MAC address, you can integrate a Microchip 24AA02E64 (or E48) -- it's very simple, but will cost you a little extra money and space on your PCB.

Here's how mbed does it -- they query a memory region in the K64 that is marked "System integration module (SIM)".  I don't know what this module does, but I'm going to look it up shortly.  Anyhow, here's their code for getting a "semi-unique" MAC address.  I think this is the approach I will be using in my device since it's not IoT or anything like that.

void mbed_mac_address(char *mac)

{

  // Fetch word 0

  uint32_t word0 = *(uint32_t *)0x40048060;

  // Fetch word 1

  // we only want bottom 16 bits of word1 (MAC bits 32-47)

  // and bit 1 forced to 1, bit 0 forced to 0

  // Locally administered MAC, reduced conflicts

  // http://en.wikipedia.org/wiki/MAC_address

  uint32_t word1 = *(uint32_t *)0x4004805C;

  word1 |= 0x00000002;

  word1 &= 0x0000FFFE;

  mac[0] = (word1 & 0x000000ff);

  mac[1] = (word1 & 0x0000ff00) >> 8;

  mac[2] = (word0 & 0xff000000) >> 24;

  mac[3] = (word0 & 0x00ff0000) >> 16;

  mac[4] = (word0 & 0x0000ff00) >> 8;

  mac[5] = (word0 & 0x000000ff);

}

pastedImage_0.png

pastedImage_1.png

Hope this helps.

0 项奖励
回复
1,244 次查看
ironsean
Contributor V

Dave, thank you very much!

Based on this manual: http://cache.freescale.com/files/microcontrollers/doc/ref_manual/SIMRM.pdf
"The SIM supplies a clock signal to the rest of the microcontroller, provides system protection features, and manages the external bus. In addition, the SIM provides on-chip chip-select signals and (if the pins are not being used for their alternate functions) I/O ports."

And based on the information there it looks like the SIM contains some unique identification registers which mbed is using as a basis for generating a MAC Address, which they set to Locally Administered to prevent it conflicting with proper assigned MAC addresses in the field.

That's very interesting to know that's there, and how mbed determines it's MAC address. This also answers my question about whether it is valid or not. For development this would be fine, but we actually are developing IoT devices for the field so an external chip with a MAC will be necessary.

Sean

1,244 次查看
dave408
Senior Contributor II

Hey Sean, thanks for that additional information.  Just out of curiosity, what chip are you going to use for the MAC assignment?

0 项奖励
回复
1,244 次查看
ironsean
Contributor V

We're just using a Microship EPROM with an embedded MAC, it's in the 24AAxxx family I believe.

Sean

0 项奖励
回复
1,244 次查看
dave408
Senior Contributor II

Ok, thanks.  We're using the same family.  I was just curious to know what else might be out there.

0 项奖励
回复
1,244 次查看
Rick_Li
NXP Employee
NXP Employee

Hi Sean Mackay,

there is NO included/assigned offical MAC address on the boards, you have to buy MAC address from OUI for your product.

The MAC address {0x00, 0x00, 0x5E, 0, 0, 0} can be used for development!