diff --git a/drivers/hwinfo/CMakeLists.txt b/drivers/hwinfo/CMakeLists.txt index 711aa4d8794..36fe7ed8b13 100644 --- a/drivers/hwinfo/CMakeLists.txt +++ b/drivers/hwinfo/CMakeLists.txt @@ -6,6 +6,7 @@ zephyr_sources_ifdef(CONFIG_HWINFO hwinfo_weak_impl.c) zephyr_sources_ifdef(CONFIG_HWINFO_STM32 hwinfo_stm32.c) zephyr_sources_ifdef(CONFIG_HWINFO_NRF hwinfo_nrf.c) zephyr_sources_ifdef(CONFIG_HWINFO_MCUX_SIM hwinfo_mcux_sim.c) +zephyr_sources_ifdef(CONFIG_HWINFO_ESP32 hwinfo_esp32.c) zephyr_sources_ifdef(CONFIG_HWINFO_IMXRT hwinfo_imxrt.c) zephyr_sources_ifdef(CONFIG_HWINFO_SAM hwinfo_sam.c) zephyr_sources_ifdef(CONFIG_HWINFO_SAM0 hwinfo_sam0.c) diff --git a/drivers/hwinfo/Kconfig b/drivers/hwinfo/Kconfig index cd38b009b6d..e660411d6b2 100644 --- a/drivers/hwinfo/Kconfig +++ b/drivers/hwinfo/Kconfig @@ -62,4 +62,11 @@ config HWINFO_SAM0 help Enable Atmel SAM0 hwinfo driver. +config HWINFO_ESP32 + bool "ESP32 device ID" + default y + depends on SOC_ESP32 + help + Enable ESP32 hwinfo driver. + endif diff --git a/drivers/hwinfo/hwinfo_esp32.c b/drivers/hwinfo/hwinfo_esp32.c new file mode 100644 index 00000000000..d8c76283715 --- /dev/null +++ b/drivers/hwinfo/hwinfo_esp32.c @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2019 Leandro A. F. Pereira + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +#include +#include + +ssize_t _impl_hwinfo_get_device_id(u8_t *buffer, size_t length) +{ + uint32_t fuse_rdata[] = { + sys_read32(EFUSE_BLK0_RDATA1_REG), + sys_read32(EFUSE_BLK0_RDATA2_REG), + }; + + if (length > sizeof(fuse_rdata)) { + length = sizeof(fuse_rdata); + } + + memcpy(buffer, fuse_rdata, length); + + return length; +}