Skip to content

soc: esp32h2: Add initial support #472

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/driver/gpio/include/driver/rtc_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ bool rtc_gpio_is_valid_gpio(gpio_num_t gpio_num);

#define RTC_GPIO_IS_VALID_GPIO(gpio_num) rtc_gpio_is_valid_gpio(gpio_num)

#if SOC_RTCIO_INPUT_OUTPUT_SUPPORTED
#if SOC_RTCIO_PIN_COUNT > 0
/**
* @brief Get RTC IO index number by gpio number.
*
Expand Down
3 changes: 0 additions & 3 deletions components/esp_hw_support/port/esp32h2/cpu_region_protect.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,6 @@ void esp_cpu_configure_region_protection(void)
_Static_assert(SOC_IROM_MASK_LOW < SOC_IROM_MASK_HIGH, "Invalid I/D-ROM region");

if (esp_cpu_dbgr_is_attached()) {
// Anti-FI check that cpu is really in ocd mode
ESP_FAULT_ASSERT(esp_cpu_dbgr_is_attached());

// 5. IRAM and DRAM
PMP_ENTRY_SET(5, SOC_IRAM_LOW, NONE);
PMP_ENTRY_SET(6, SOC_IRAM_HIGH, PMP_TOR | RWX);
Expand Down
3 changes: 2 additions & 1 deletion components/esp_hw_support/port/esp32h2/esp_cpu_intr.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@
void esp_cpu_intr_get_desc(int core_id, int intr_num, esp_cpu_intr_desc_t *intr_desc_ret)
{
/* On the ESP32-H2, interrupt:
* - 0 is unavailable according to TRM
* - 1 is for Wi-Fi
* - 6 for "permanently disabled interrupt"
*
* Interrupts 3, 4 and 7 are unavailable for PULP CPU as they are bound to Core-Local Interrupts (CLINT)
*/
// [TODO: IDF-2465]
const uint32_t rsvd_mask = BIT(1) | BIT(3) | BIT(4) | BIT(6) | BIT(7);
const uint32_t rsvd_mask = BIT(0) | BIT(1) | BIT(3) | BIT(4) | BIT(6) | BIT(7);

intr_desc_ret->priority = 1;
intr_desc_ret->type = ESP_CPU_INTR_TYPE_NA;
Expand Down
6 changes: 6 additions & 0 deletions components/esp_hw_support/port/esp32h2/rtc_clk.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,14 @@ soc_rtc_fast_clk_src_t rtc_clk_fast_src_get(void)

static void rtc_clk_bbpll_disable(void)
{
#if defined(CLK_BBPLL_DISABLE)
/* Disabling BBPLL is commented due to issues when transitioning
* from PLL to XTAL clock sources. Comprehensive clock management
* must be implemented for peripherals as well (ZEP-827).
*/
clk_ll_bbpll_disable();
s_cur_pll_freq = 0;
#endif
}

static void rtc_clk_bbpll_enable(void)
Expand Down
28 changes: 14 additions & 14 deletions components/esp_rom/esp32h2/ld/esp32h2.rom.newlib.ld
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ memrchr = 0x40000518;
strcasecmp = 0x4000051c;
strcasestr = 0x40000520;
strcat = 0x40000524;
strdup = 0x40000528;
PROVIDE ( strdup = 0x40000528 );
strchr = 0x4000052c;
strcspn = 0x40000530;
strcoll = 0x40000534;
Expand All @@ -62,7 +62,7 @@ strlcpy = 0x4000053c;
strlwr = 0x40000540;
strncasecmp = 0x40000544;
strncat = 0x40000548;
strndup = 0x4000054c;
PROVIDE ( strndup = 0x4000054c );
strnlen = 0x40000550;
strrchr = 0x40000554;
strsep = 0x40000558;
Expand All @@ -76,22 +76,22 @@ div = 0x40000574;
labs = 0x40000578;
ldiv = 0x4000057c;
qsort = 0x40000580;
rand_r = 0x40000584;
rand = 0x40000588;
srand = 0x4000058c;
PROVIDE ( rand_r = 0x40000584 );
PROVIDE ( rand = 0x40000588 );
PROVIDE ( srand = 0x4000058c );
utoa = 0x40000590;
itoa = 0x40000594;
atoi = 0x40000598;
atol = 0x4000059c;
strtol = 0x400005a0;
strtoul = 0x400005a4;
fflush = 0x400005a8;
_fflush_r = 0x400005ac;
_fwalk = 0x400005b0;
_fwalk_reent = 0x400005b4;
PROVIDE ( atoi = 0x40000598 );
PROVIDE ( atol = 0x4000059c );
PROVIDE ( strtol = 0x400005a0 );
PROVIDE ( strtoul = 0x400005a4 );
PROVIDE ( fflush = 0x400005a8 );
PROVIDE ( _fflush_r = 0x400005ac );
PROVIDE ( _fwalk = 0x400005b0 );
PROVIDE ( _fwalk_reent = 0x400005b4 );
__smakebuf_r = 0x400005b8;
__swhatbuf_r = 0x400005bc;
__swbuf_r = 0x400005c0;
PROVIDE ( __swbuf_r = 0x400005c0 );
__swbuf = 0x400005c4;
__swsetup_r = 0x400005c8;
/* Data (.data, .bss, .rodata) */
Expand Down
1 change: 1 addition & 0 deletions components/esp_rom/include/esp32h2/rom/rtc.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <stdbool.h>
#include <stdint.h>
#include <stddef.h>

#include "soc/soc.h"
#include "soc/lp_aon_reg.h"
Expand Down
2 changes: 1 addition & 1 deletion components/esp_rom/include/esp32h2/rom/uart.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ typedef enum {
} UartFlowCtrl;

typedef enum {
EMPTY,
EMPTY_,
UNDER_WRITE,
WRITE_OVER
} RcvMsgBuffState;
Expand Down
3 changes: 0 additions & 3 deletions components/esp_system/port/soc/esp32h2/clk.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

#include <stdint.h>
#include <sys/cdefs.h>
#include <sys/time.h>
#include <sys/param.h>
#include "sdkconfig.h"
#include "esp_attr.h"
Expand Down Expand Up @@ -35,8 +34,6 @@
*/
#define SLOW_CLK_CAL_CYCLES CONFIG_RTC_CLK_CAL_CYCLES

#define MHZ (1000000)

static void select_rtc_slow_clk(soc_rtc_slow_clk_src_t rtc_slow_clk_src);
static __attribute__((unused)) void recalib_bbpll(void);

Expand Down
2 changes: 1 addition & 1 deletion components/esp_system/port/soc/esp32h2/reset_reason.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ static esp_reset_reason_t get_reset_reason(soc_reset_reason_t rtc_reset_reason,
}
}

static void esp_reset_reason_init(void)
void esp_reset_reason_init(void)
{
esp_reset_reason_t hint = esp_reset_reason_get_hint();
s_reset_reason = get_reset_reason(esp_rom_get_reset_reason(PRO_CPU_NUM), hint);
Expand Down
54 changes: 42 additions & 12 deletions components/hal/esp32h2/include/hal/clk_gate_ll.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand All @@ -11,6 +11,7 @@
#include "soc/periph_defs.h"
#include "soc/pcr_reg.h"
#include "soc/soc.h"
#include "soc/lpperi_reg.h"

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -77,8 +78,6 @@ static inline uint32_t periph_ll_get_clk_en_mask(periph_module_t periph)
return PCR_TSENS_CLK_EN;
case PERIPH_REGDMA_MODULE:
return PCR_REGDMA_CLK_EN;
// case PERIPH_RNG_MODULE:
// return PCR_WIFI_CLK_RNG_EN;
// case PERIPH_WIFI_MODULE:
// return PCR_WIFI_CLK_WIFI_EN_M;
// case PERIPH_BT_MODULE:
Expand All @@ -89,6 +88,8 @@ static inline uint32_t periph_ll_get_clk_en_mask(periph_module_t periph)
// return PCR_BT_BASEBAND_EN;
// case PERIPH_BT_LC_MODULE:
// return PCR_BT_LC_EN;
case PERIPH_RNG_MODULE:
return LPPERI_RNG_CK_EN;
default:
return 0;
}
Expand Down Expand Up @@ -197,7 +198,6 @@ static inline uint32_t periph_ll_get_rst_en_mask(periph_module_t periph, bool en
static uint32_t periph_ll_get_clk_en_reg(periph_module_t periph)
{// ESP32H2-TODO: IDF-6400
switch (periph) {
// case PERIPH_RNG_MODULE:
// case PERIPH_WIFI_MODULE:
// case PERIPH_BT_MODULE:
// case PERIPH_WIFI_BT_COMMON_MODULE:
Expand Down Expand Up @@ -263,6 +263,8 @@ static uint32_t periph_ll_get_clk_en_reg(periph_module_t periph)
return PCR_TSENS_CLK_CONF_REG;
case PERIPH_REGDMA_MODULE:
return PCR_REGDMA_CONF_REG;
case PERIPH_RNG_MODULE:
return LPPERI_CLK_EN_REG;
default:
return 0;
}
Expand Down Expand Up @@ -337,14 +339,30 @@ static uint32_t periph_ll_get_rst_en_reg(periph_module_t periph)

static inline void periph_ll_enable_clk_clear_rst(periph_module_t periph)
{
SET_PERI_REG_MASK(periph_ll_get_clk_en_reg(periph), periph_ll_get_clk_en_mask(periph));
CLEAR_PERI_REG_MASK(periph_ll_get_rst_en_reg(periph), periph_ll_get_rst_en_mask(periph, true));
uint32_t clk_en_reg = periph_ll_get_clk_en_reg(periph);
uint32_t rst_en_reg = periph_ll_get_rst_en_reg(periph);

if (clk_en_reg != 0) {
SET_PERI_REG_MASK(clk_en_reg, periph_ll_get_clk_en_mask(periph));
}

if (rst_en_reg != 0) {
CLEAR_PERI_REG_MASK(rst_en_reg, periph_ll_get_rst_en_mask(periph, true));
}
}

static inline void periph_ll_disable_clk_set_rst(periph_module_t periph)
{
CLEAR_PERI_REG_MASK(periph_ll_get_clk_en_reg(periph), periph_ll_get_clk_en_mask(periph));
SET_PERI_REG_MASK(periph_ll_get_rst_en_reg(periph), periph_ll_get_rst_en_mask(periph, false));
uint32_t clk_en_reg = periph_ll_get_clk_en_reg(periph);
uint32_t rst_en_reg = periph_ll_get_rst_en_reg(periph);

if (clk_en_reg != 0) {
CLEAR_PERI_REG_MASK(clk_en_reg, periph_ll_get_clk_en_mask(periph));
}

if (rst_en_reg != 0) {
SET_PERI_REG_MASK(rst_en_reg, periph_ll_get_rst_en_mask(periph, false));
}
}

static inline void periph_ll_wifi_bt_module_enable_clk(void)
Expand All @@ -359,14 +377,26 @@ static inline void periph_ll_wifi_bt_module_disable_clk(void)

static inline void periph_ll_reset(periph_module_t periph)
{
SET_PERI_REG_MASK(periph_ll_get_rst_en_reg(periph), periph_ll_get_rst_en_mask(periph, false));
CLEAR_PERI_REG_MASK(periph_ll_get_rst_en_reg(periph), periph_ll_get_rst_en_mask(periph, false));
uint32_t rst_en_reg = periph_ll_get_rst_en_reg(periph);

if (rst_en_reg != 0) {
SET_PERI_REG_MASK(rst_en_reg, periph_ll_get_rst_en_mask(periph, false));
CLEAR_PERI_REG_MASK(rst_en_reg, periph_ll_get_rst_en_mask(periph, false));
}
}

static inline bool periph_ll_periph_enabled(periph_module_t periph)
{
return REG_GET_BIT(periph_ll_get_rst_en_reg(periph), periph_ll_get_rst_en_mask(periph, false)) == 0 &&
REG_GET_BIT(periph_ll_get_clk_en_reg(periph), periph_ll_get_clk_en_mask(periph)) != 0;
uint32_t clk_en_reg = periph_ll_get_clk_en_reg(periph);
uint32_t rst_en_reg = periph_ll_get_rst_en_reg(periph);

bool clk_enabled = (clk_en_reg != 0) &&
(REG_GET_BIT(clk_en_reg, periph_ll_get_clk_en_mask(periph)) != 0);

bool rst_disabled = (rst_en_reg == 0) ||
(REG_GET_BIT(rst_en_reg, periph_ll_get_rst_en_mask(periph, false)) == 0);

return clk_enabled && rst_disabled;
}

static inline void periph_ll_wifi_module_enable_clk_clear_rst(void)
Expand Down
3 changes: 3 additions & 0 deletions components/hal/esp32h2/include/hal/clk_tree_ll.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@
extern "C" {
#endif

#if !defined(DT_DRV_COMPAT)
#undef MHZ
#define MHZ (1000000)
#endif

#define CLK_LL_PLL_8M_FREQ_MHZ (8)
#define CLK_LL_PLL_48M_FREQ_MHZ (48)
Expand Down
12 changes: 12 additions & 0 deletions components/hal/esp32h2/include/hal/uart_ll.h
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,18 @@ FORCE_INLINE_ATTR void uart_ll_set_mode_rs485_half_duplex(uart_dev_t *hw)
uart_ll_update(hw);
}

/**
* @brief Get the rs485_half_duplex mode.
*
* @param hw Beginning address of the peripheral registers.
*
* @return True if RS485 half duplex mode enabled.
*/
FORCE_INLINE_ATTR bool uart_ll_is_mode_rs485_half_duplex(uart_dev_t *hw)
{
return (!hw->rs485_conf_sync.rs485rxby_tx_en && hw->rs485_conf_sync.rs485_en);
}

/**
* @brief Configure the UART work in collision_detect mode.
*
Expand Down
3 changes: 2 additions & 1 deletion components/soc/esp32h2/include/soc/ext_mem_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,9 @@ extern "C" {
/**
* I/D share the MMU linear address range
*/
#ifndef __ASSEMBLER__
_Static_assert(SOC_MMU_IRAM0_LINEAR_ADDRESS_LOW == SOC_MMU_DRAM0_LINEAR_ADDRESS_LOW, "IRAM0 and DRAM0 linear address should be same");

#endif

#ifdef __cplusplus
}
Expand Down
1 change: 1 addition & 0 deletions components/soc/esp32h2/include/soc/pmu_struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#pragma once

#include <stdint.h>
#include <stddef.h>
#include "soc/pmu_reg.h"
#ifdef __cplusplus
extern "C" {
Expand Down
3 changes: 1 addition & 2 deletions components/soc/esp32h2/include/soc/rtc.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include "stubs.h"
#include "soc/soc.h"
#include "soc/clk_tree_defs.h"

Expand Down Expand Up @@ -43,8 +44,6 @@ extern "C" {
* - rtc_sleep: entry into sleep modes
*/

#define MHZ (1000000)

#define RTC_SLOW_CLK_150K_CAL_TIMEOUT_THRES(cycles) (cycles << 10)
#define RTC_SLOW_CLK_32K_CAL_TIMEOUT_THRES(cycles) (cycles << 12)
#define RTC_FAST_CLK_8M_CAL_TIMEOUT_THRES(cycles) (TIMG_RTC_CALI_TIMEOUT_THRES_V) // Just use the max timeout thres value
Expand Down
5 changes: 3 additions & 2 deletions components/soc/esp32h2/include/soc/soc.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2020-2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2020-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand All @@ -11,6 +11,7 @@
#include "esp_assert.h"
#endif

#include "soc/ext_mem_defs.h"
#include "esp_bit_defs.h"
#include "reg_base.h"

Expand Down Expand Up @@ -164,7 +165,7 @@
#define SOC_IRAM_HIGH 0x40850000
#define SOC_DRAM_LOW 0x40800000
#define SOC_DRAM_HIGH 0x40850000
#define SOC_RTC_IRAM_LOW 0x50000000 // ESP32-H2 only has 16k LP memory
#define SOC_RTC_IRAM_LOW 0x50000000 // ESP32-H2 only has 4k LP memory
#define SOC_RTC_IRAM_HIGH 0x50001000
#define SOC_RTC_DRAM_LOW 0x50000000
#define SOC_RTC_DRAM_HIGH 0x50001000
Expand Down
1 change: 1 addition & 0 deletions zephyr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ add_subdirectory_ifdef(CONFIG_SOC_SERIES_ESP32 esp32)
add_subdirectory_ifdef(CONFIG_SOC_SERIES_ESP32C2 esp32c2)
add_subdirectory_ifdef(CONFIG_SOC_SERIES_ESP32C3 esp32c3)
add_subdirectory_ifdef(CONFIG_SOC_SERIES_ESP32C6 esp32c6)
add_subdirectory_ifdef(CONFIG_SOC_SERIES_ESP32H2 esp32h2)
add_subdirectory_ifdef(CONFIG_SOC_SERIES_ESP32S2 esp32s2)
add_subdirectory_ifdef(CONFIG_SOC_SERIES_ESP32S3 esp32s3)
5 changes: 5 additions & 0 deletions zephyr/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ config IDF_FIRMWARE_CHIP_ID
default 0x000C if SOC_SERIES_ESP32C2
default 0x0005 if SOC_SERIES_ESP32C3
default 0x000D if SOC_SERIES_ESP32C6
default 0x0010 if IDF_TARGET_ESP32H2

config SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY
bool
Expand Down Expand Up @@ -68,6 +69,10 @@ config IDF_TARGET_ESP32C6
bool
default y if SOC_SERIES_ESP32C6

config IDF_TARGET_ESP32H2
bool
default y if SOC_SERIES_ESP32H2

config ESP_TIMER_IMPL_TG0_LAC
bool
default y
Expand Down
Loading