EEPROM MAC Address
When you program the node, a chip erase is required to clear the FLASH. This chip erase also clears the EEPROM. Therefore, it is required to write the MAC address to EEPROM for a particular image after the node is programmed. Though this is an extra step, it still saves the developer from having to recompile all of the code for each image. A single FLASH image can be written to all nodes and the EEPROM-mac-set tool can be used to set MAC addresses stored on EEPROM.
EEPROM-mac-set
EEPROM-mac-set allows you to set the MAC address of the node including a checksum to prevent accidental use of an incorrect MAC address. Inside Nano-RK the MAC address can be read using the read_eeprom_mac_address() function as shown in the example below (from: basic_eeprom project):
uint32_t mac_address; ... val=read_eeprom_mac_address(&mac_address); if(val==NRK_OK) { nrk_kprintf( PSTR("MAC = 0x")); printf( "%x",(uint8_t)((mac_address>>24)&0xff)); printf( "%x",(uint8_t)((mac_address>>16)&0xff)); printf( "%x",(uint8_t)((mac_address>>8)&0xff)); printf( "%x\n",(uint8_t)((mac_address & 0xff))); } else { while(1) { nrk_kprintf( PSTR( "* ERROR reading MAC address\r\n" )); nrk_wait_until_next_period(); } }
The MAC address is then set using the eeprom-mac-set tool located in /nano-RK/tools/EEPROM_mac_set. The below example shows how to set the MAC address to 0x11223344:
agr@shiraz:~/nano-RK/tools> cd EEPROM_mac_set/
agr@shiraz:~/nano-RK/tools/EEPROM_mac_set> ls
main.c makefile
agr@shiraz:~/nano-RK/tools/EEPROM_mac_set> make
gcc -c -o main.o main.c -I.
gcc -o eeprom-mac-set main.o -I.
agr@shiraz:~/nano-RK/tools/EEPROM_mac_set> ls
eeprom-mac-set main.c main.o makefile
agr@shiraz:~/nano-RK/tools/EEPROM_mac_set> ./eeprom-mac-set
EEPROM MAC address write utility
1) Set serial port
2) Set and Write MAC addresses
3) Exit
>2
Enter MAC address to be written in the following format:
e.g. 0x11223344 "11 22 33 44"
or Ctrl-C to exit
Enter MAC [xx xx xx xx] (hex values)
>11 22 33 44
Writing MAC 0x11223344 with checksum 0xaa
Connecting to programmer: .
Found programmer: Id = "AVR ISP"; type = S
Software Version = 3.8; Hardware Version = 1.2
Programmer supports auto addr increment.
Programmer supports buffered memory access with buffersize=64 bytes.
Programmer supports the following devices:
Device code: 0x13
Device code: 0x20
Device code: 0x28
Device code: 0x30
Device code: 0x34
Device code: 0x38
Device code: 0x48
Device code: 0x4c
Device code: 0x51
Device code: 0x55
Device code: 0x56
Device code: 0x68
Device code: 0x6c
Device code: 0x86
Device code: 0x87
Device code: 0x01
Device code: 0x04
Device code: 0x05
Device code: 0x06
Device code: 0x07
Device code: 0x08
Device code: 0x09
Device code: 0x0e
Device code: 0x1a
Device code: 0x0f
Device code: 0x1b
Device code: 0x14
Device code: 0x1c
Device code: 0x1d
Device code: 0x23
Device code: 0x31
Device code: 0x33
Device code: 0x35
Device code: 0x37
Device code: 0x39
Device code: 0x3d
Device code: 0x3e
Device code: 0x57
Device code: 0x3a
Device code: 0x3b
Device code: 0x41
Device code: 0x43
Device code: 0x44
Device code: 0x45
Device code: 0x46
Device code: 0x5e
Device code: 0x60
Device code: 0x61
Device code: 0x62
Device code: 0x63
Device code: 0x64
Device code: 0x66
Device code: 0x69
Device code: 0x6a
Device code: 0x72
Device code: 0x73
Device code: 0x74
Device code: 0x75
Device code: 0x76
Device code: 0x77
Device code: 0x78
Device code: 0x79
avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.02s
avrdude: Device signature = 0x1e9704
avrdude: reading input file "0x11 0x22 0x33 0x44 0xaa"
avrdude: writing eeprom (5 bytes):
Writing | ################################################## | 100% 0.10s
avrdude: 5 bytes of eeprom written
avrdude: safemode: Fuses OK
avrdude done. Thank you.
MAC written
Enter MAC [xx xx xx xx] (hex values)
>
