There are several Microchip/Atmel boards that come with an Atmel MAC in
AT24MAC402 EEPROM. You should be able to clone that logic (including
setting the MAC address). See:
samv7/samv71-xult/src/sam_ethernet.c
samv7/same70-xplained/src/sam_ethernet.c
These keep the MAC address in the AT24MAC402 which requires some special
operations.
152 /* Initialize the AT24 driver */
153
154 at24 = at24c_initialize(i2c);
155 if (!at24)
156 {
157 nerr("ERROR: Failed to initialize the AT24 driver\n");
158 sam_i2cbus_uninitialize(i2c);
159 return -ENODEV;
160 }
161
162 /* Configure the AT24 to access the extended memory region */
163
164 ret = at24->ioctl(at24, MTDIOC_EXTENDED, 1);
165 if (ret < 0)
166 {
167 nerr("ERROR: AT24 ioctl(MTDIOC_EXTENDED) failed: %d\n", ret);
168 sam_i2cbus_uninitialize(i2c);
169 return ret;
170 }
171
172 /* Read the MAC address */
173
174 nread = at24->read(at24, AT24XX_MACADDR_OFFSET, 6, mac);
175 if (nread < 6)
176 {
177 nerr("ERROR: AT24 read(AT24XX_MACADDR_OFFSET) failed: %zd\n",
178 nread);
179 sam_i2cbus_uninitialize(i2c);
180 return (int)nread;
181 }
182
183 /* Put the AT24 back in normal memory access mode */
184
185 ret = at24->ioctl(at24, MTDIOC_EXTENDED, 0);
186 if (ret < 0)
187 {
188 nerr("ERROR: AT24 ioctl(MTDIOC_EXTENDED) failed: %d\n", ret);
189 }
...
206 ret = sam_emac_setmacaddr(EMAC0_INTF, mac);
207 if (ret < 0)
208 {
209 nerr("ERROR: Failed to set MAC address: %d\n", ret);
210 }
On 4/29/2021 5:05 AM, Frank-Christian Kruegel wrote:
Hi.
I'm currently porting NuttX to some proprietary compute modules with
STM32F7 and STM32H7. Each and every board has got a small AT24MAC402
256 Byte EEPROM with additional UID and MAC address accessible under a
second I2C address, and many boards have an additional AT24C256 32kB
EEPROM.
I've had a look at the At24 driver and example board drivers. For the
32k EEPROM using a file system seems a good idea. The small ID EEPROM
however is another story. 256 bytes seem to me way to small to use a
file system on it. And how do I extract the 6 bytes of MAC address
residing in the midde of the second bank?
How is this designed to work? I have no problem using the at24 driver
as a base for something own, but I'd rather like to use what is there
or feed my own solution back into the main repository so others can
reuse it.
Best Regards
Frank-Christian
Datasheet for AT24MAC402/602:
https://ww1.microchip.com/downloads/en/DeviceDoc/I%C2%B2C-Compatible-(Two-Wire)-Serial-EEPROM-with-a-Factory%E2%80%91Programmed-EUI-48%E2%84%A2-or-EUI-64%E2%84%A2-Address-Plus-a-Unique-Factory-Programmed-128%E2%80%91Bit-Serial-Number-2%E2%80%91Kbit-(256x8)-20006430A.pdf