Am 29.04.2021 um 15:23 schrieb Gregory Nutt:
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.
Thank you for your suggestions.
I can't use the method shown in in the samv7 boards. The main reason is
that the AT24XX MTD driver only can handle one type of devices on a
single bus. My hardware however has got an AT24MAC402 on #50 and an
AT24C256 on #51 on a single bus. My plan is to use the AT24XX MTD driver
for the 24C256 and put a NuttFS on it, and use the i2c_xx24xx char
driver for the 24MAC402, which is too small for a fs anyway. The char
driver already has support for the UUID area on the 24MAC402, and I
patched the driver with minimal effort also to export another device for
the MAC of an AT24MAC402 (48 bit) or AT24MAC602 (64 bit).
The (yet untested) patch is appended to this posting. I can make a pull
request if you like it.
The stm32_ethernet drivers for STM32F7 and STM32H7 don't accept an
external MAC but hash one out internally from the STM32 uid. I guess I
need to add a stm32_emac_setmacaddr(uint8_t mac[6]) function to these
drivers. Do you like me to upload these patches as well?
Best Regards
Frank-Christian
diff -r -u ../../nuttx1/nuttx/drivers/eeprom/i2c_xx24xx.c
./drivers/eeprom/i2c_xx24xx.c
--- ../../nuttx1/nuttx/drivers/eeprom/i2c_xx24xx.c 2021-04-15
13:38:39.000000000 +0200
+++ ./drivers/eeprom/i2c_xx24xx.c 2021-04-29 15:09:01.926357073 +0200
@@ -94,7 +94,22 @@
# define CONFIG_EE24XX_FREQUENCY 100000
#endif
+#ifdef CONFIG_AT24CS_UUID
+#define UUID_START 128
#define UUID_SIZE 16
+#endif
+
+#ifdef CONFIG_AT24CS_MAC
+#if defined(CONFIG_AT24CS_E48)
+#define MAC_START 154
+#define MAC_SIZE 6
+#elif defined(CONFIG_AT24CS_E64)
+#define MAC_START 152
+#define MAC_SIZE 8
+#else
+#error "if CONFIG_AT24CS_MAC then define CONFIG_AT24CS_E48 or
CONFIG_AT24CS_E64"
+#endif
+#endif
/****************************************************************************
* Types
@@ -253,6 +268,19 @@
};
#endif
+#ifdef CONFIG_AT24CS_MAC
+static const struct file_operations at24cs_mac_fops =
+{
+ ee24xx_open, /* piggyback on the ee24xx_open */
+ ee24xx_close, /* piggyback on the ee24xx_close */
+ at24cs_read_mac, /* read */
+ NULL, /* write */
+ NULL, /* seek */
+ NULL, /* ioctl */
+ NULL /* poll */
+};
+#endif
+
/****************************************************************************
* Private Functions
****************************************************************************/
@@ -633,7 +661,7 @@
finfo("READ %d bytes at pos %d\n", len, filep->f_pos);
- regindx = 0x80; /* reg index of UUID[0] */
+ regindx = UUID_START; /* reg index of UUID[0] */
msgs[0].frequency = eedev->freq;
msgs[0].addr = eedev->addr + 8; /* slave addr of UUID */
@@ -668,6 +696,82 @@
#endif
/****************************************************************************
+ * Name: at24cs_read_mac
+ ****************************************************************************/
+
+#ifdef CONFIG_AT24CS_MAC
+static ssize_t at24cs_read_mac(FAR struct file *filep, FAR char *buffer,
+ size_t len)
+{
+ FAR struct ee24xx_dev_s *eedev;
+ FAR struct inode *inode = filep->f_inode;
+ struct i2c_msg_s msgs[2];
+ uint8_t regindx;
+ int ret;
+
+ DEBUGASSERT(inode && inode->i_private);
+ eedev = (FAR struct ee24xx_dev_s *)inode->i_private;
+
+ ret = ee24xx_semtake(eedev);
+ if (ret < 0)
+ {
+ return ret;
+ }
+
+ /* trim len if read would go beyond end of device */
+
+ if ((filep->f_pos + len) > MAC_SIZE)
+ {
+ len = MAC_SIZE - filep->f_pos;
+ }
+
+ if (len == 0)
+ {
+ /* We are at end of file */
+
+ ret = 0;
+ goto done;
+ }
+
+ /* Write data address */
+
+ finfo("READ %d bytes at pos %d\n", len, filep->f_pos);
+
+ regindx = MAC_START; /* reg index of MAC[0] */
+
+ msgs[0].frequency = eedev->freq;
+ msgs[0].addr = eedev->addr + 8; /* slave addr of MAC */
+ msgs[0].flags = 0;
+ msgs[0].buffer = ®indx;
+ msgs[0].length = 1;
+
+ /* Read data */
+
+ msgs[1].frequency = msgs[0].frequency;
+ msgs[1].addr = msgs[0].addr;
+ msgs[1].flags = I2C_M_READ;
+ msgs[1].buffer = (uint8_t *)buffer;
+ msgs[1].length = len;
+
+ ret = I2C_TRANSFER(eedev->i2c, msgs, 2);
+ if (ret < 0)
+ {
+ goto done;
+ }
+
+ ret = len;
+
+ /* Update the file position */
+
+ filep->f_pos += len;
+
+done:
+ ee24xx_semgive(eedev);
+ return ret;
+}
+#endif
+
+/****************************************************************************
* Name: ee24xx_write
****************************************************************************/
@@ -926,6 +1030,30 @@
return ret;
}
#endif
+
+#ifdef CONFIG_AT24CS_MAC
+ uuidname = kmm_zalloc(strlen(devname) + 8);
+ if (!uuidname)
+ {
+ return -ENOMEM;
+ }
+
+ /* register the MAC I2C slave with the same name as the parent
+ * EEPROM chip, but with the ".uuid" suffix
+ */
+
+ strcpy(uuidname, devname);
+ strcat(uuidname, ".mac");
+ ret = register_driver(uuidname, &at24cs_mac_fops, 0444, eedev);
+
+ kmm_free(uuidname);
+
+ if (OK != ret)
+ {
+ ferr("register mac failed, ret = %d\n", ret);
+ return ret;
+ }
+#endif
return register_driver(devname, &ee24xx_fops, 0666, eedev);
}
diff -r -u ../../nuttx1/nuttx/drivers/eeprom/Kconfig ./drivers/eeprom/Kconfig
--- ../../nuttx1/nuttx/drivers/eeprom/Kconfig 2021-04-15 13:38:39.000000000
+0200
+++ ./drivers/eeprom/Kconfig 2021-04-29 15:19:38.096601745 +0200
@@ -48,14 +48,51 @@
default 100000
depends on I2C_EE_24XX
-config AT24CS_UUID
- bool "Device driver support for Atmel AT24CSxx UUID"
- default n
+choice
+ prompt "Support for Atmel UUID or MAC"
depends on I2C_EE_24XX
+
+config AT24CSXX
+ bool "Device driver support for Atmel AT24CSxx UUID"
+ select AT24CS_UUID
---help---
The Atmel AT24CSxx family have a 128-bit UUID which appears as
another I2C slave whose address is offset from the EEPROM by +8.
- This option registers a char device driver with the ".uuid"
suffix.
+ This option registers a char device driver with the ".uuid"
suffix
+ for the UUID.
+
+config AT24MAC402
+ bool "Device driver support for Atmel AT24MAC402 E48 MAC Address"
+ select AT24CS_UUID
+ select AT24CS_MAC
+ select AT24CS_E48
+ ---help---
+ The Atmel AT24MAC402 has a 48-bit E48 MAC and a 128 bit UUID
which
+ appears as another I2C slave whose address is offset from the
+ EEPROM by +8.
+ This option registers a char device driver with the ".uuid"
suffix
+ for the UUID.
+ This option registers a char device driver with the ".mac"
suffix.
+ for the MAC.
+
+config AT24MAC602
+ bool "Device driver support for Atmel AT24MAC602 E64 MAC Address"
+ select AT24CS_UUID
+ select AT24CS_MAC
+ select AT24CS_E64
+ ---help---
+ The Atmel AT24MAC602 has a 64-bit E64 MAC and a 128 bit UUID
which
+ appears as another I2C slave whose address is offset from the
+ EEPROM by +8.
+ This option registers a char device driver with the ".uuid"
suffix
+ for the UUID.
+ This option registers a char device driver with the ".mac"
suffix.
+ for the MAC.
+
+config AT24STD
+ bool "No UUID/MAC support"
+
+endchoice
endif # I2C_EE_24XX
diff -r -u ../../nuttx1/nuttx/include/nuttx/eeprom/i2c_xx24xx.h
./include/nuttx/eeprom/i2c_xx24xx.h
--- ../../nuttx1/nuttx/include/nuttx/eeprom/i2c_xx24xx.h 2021-04-15
13:38:39.000000000 +0200
+++ ./include/nuttx/eeprom/i2c_xx24xx.h 2021-04-29 14:24:22.334086133 +0200
@@ -78,6 +78,9 @@
EEPROM_M24256 = EEPROM_24XX256,
EEPROM_M24512 = EEPROM_24XX512,
EEPROM_M24M01 = EEPROM_24XX1026,
+
+ EEPROM_AT24MAC402 = EEPROM_24XX02,
+ EEPROM_AT24MAC602 = EEPROM_24XX02,
};
/****************************************************************************