fdcavalcanti opened a new pull request, #16965:
URL: https://github.com/apache/nuttx/pull/16965

   ## Summary
   
   This merge request fixes E-Fuse driver to handle proper block and bit offset.
   Also adds support for using virtual E-Fuses that can be saved in flash. This 
is useful for MCUBoot, which is why some options have been added to it.
   
   The documentation changes now describe how the partitioning works when 
MCUBoot is enabled.
   
   ## Impact
   
   - Impact on user: No.
   - Impact on build: No.
   - Impact on hardware: No.
   - Impact on documentation: No.
   - Impact on security: No.
   - Impact on compatibility: Changes how E-Fuse block is selected. Previously 
it would not work on the proper block, now it does.
   
   ## Testing
   
   The following example tests reading the MAC Address from E-Fuse.
   E-Fuse table can be found 
[here](https://docs.espressif.com/projects/esp-idf/en/v5.5/esp32c3/api-reference/system/efuse.html)
 and also on the Technincal Reference Manual for the SoC.
   
   ### Building
   
   - ./tools/configure.sh esp32c3-generic:efuse
   - Enable DEBUG_ASSERTIONS
   
   Include the following example to the build system (I can provide full code 
if needed, just added a simple snippet):
   
   ```
   #define ESP_EFUSE_MAC_BLK     ESP_EFUSE_MAC_FACTORY[0][0].efuse_block
   #define ESP_EFUSE_MAC_START   ESP_EFUSE_MAC_FACTORY[5][0].bit_start
   #define ESP_EFUSE_MAC_BITLEN  48
   #define ESP_EFUSE_MAC_OFFSET  (ESP_EFUSE_MAC_BLK * ESP_EFUSE_BLK_SIZE) + 
ESP_EFUSE_MAC_START
   
   int main(int argc, FAR char *argv[])
   {
     uint8_t mac[6] =
     {
       0x0
     };
     int fd;
     int ret;
   
     struct efuse_param_s param;
     struct efuse_desc_s mac_addr =
     {
       .bit_offset = ESP_EFUSE_MAC_OFFSET,
       .bit_count = ESP_EFUSE_MAC_BITLEN
     };
   
     const efuse_desc_t* desc[] = {
         &mac_addr,
         NULL
     };
   
     fd = open("/dev/efuse", O_RDONLY);
     if (fd < 0)
       {
         printf("Failed to open /dev/efuse, error = %d!\n", errno);
         return -ENODEV;
       }
   
     param.field = desc;
     param.size = ESP_EFUSE_MAC_BITLEN;
     param.data = mac;
   
     ret = ioctl(fd, EFUSEIOC_READ_FIELD, &param);
     if (ret < 0)
       {
         printf("Failed to run ioctl EFUSEIOC_READ_FIELD_BIT, error = %d!\n",
                errno);
         close(fd);
         return -EINVAL;
       }
   
     printf("MAC address: %02x:%02x:%02x:%02x:%02x:%02x\n",
            param.data[5],
            param.data[4],
            param.data[3],
            param.data[2],
            param.data[1],
            param.data[0]);
   
     return OK;
   }
   ```
   
   ### Running
   Run the program showed above, and it should read from the MAC E-Fuse block.
   
   ### Results
   MAC Address reads succesfully.
   ```
   nsh> efuse
   esp_efuse_lowerhalf_read: read from blk_num: 1, bit_start: 0, bit_count: 48
   D (421) efuse: BLK1 REG0 [0-31], len=32 bits
   D (424) efuse: BLK1 REG1 [0-15], len=16 bits
   MAC address: 58:cf:79:07:51:e8
   nsh> 
   ```
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to