Skip to content

Commit 6ad3c90

Browse files
committed
feat: Add initial chip structure
1 parent 2b2dbe2 commit 6ad3c90

File tree

18 files changed

+807
-1
lines changed

18 files changed

+807
-1
lines changed

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ add_subdirectory(${CMAKE_SOURCE_DIR}/src)
6262

6363
set(ESP_TARGET ${TARGET_CHIP} CACHE INTERNAL "Pass TARGET_CHIP as ESP_TARGET")
6464
add_subdirectory(${CMAKE_SOURCE_DIR}/esp-stub-lib)
65-
target_link_libraries(${TARGET_NAME} PRIVATE esp-stub-lib)
65+
add_subdirectory(${CMAKE_SOURCE_DIR}/soc)
66+
target_link_libraries(${TARGET_NAME} PRIVATE esp-stub-lib soc)
6667

6768
add_custom_command(TARGET ${TARGET_NAME} POST_BUILD
6869
COMMAND ${CMAKE_SOURCE_DIR}/tools/elf2json.py ${CMAKE_BINARY_DIR}/${TARGET_NAME}${CMAKE_EXECUTABLE_SUFFIX_C} ${CMAKE_BINARY_DIR}/${TARGET_CHIP}.json

soc/CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
cmake_minimum_required(VERSION 3.28)
2+
3+
add_library(soc STATIC)
4+
5+
target_sources(soc PRIVATE
6+
common/soc.c
7+
common/watchdog_common.c
8+
)
9+
10+
target_sources(soc PRIVATE targets/${TARGET_CHIP}.c)
11+
12+
# Include directories
13+
target_include_directories(soc PUBLIC
14+
${CMAKE_CURRENT_SOURCE_DIR}/include
15+
)

soc/common/soc.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0 OR MIT
5+
*/
6+
7+
#include <stddef.h>
8+
#include "soc.h"
9+
10+
/*
11+
* Single SoC info structure - chip-specific file provides this
12+
* Chip selected at compile time
13+
*/
14+
extern const struct soc_info g_soc_info;
15+
16+
const struct soc_info* soc_get_info(void)
17+
{
18+
return &g_soc_info;
19+
}

soc/common/watchdog_common.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0 OR MIT
5+
*/
6+
7+
#include "soc.h"
8+
9+
void disable_watchdogs(void)
10+
{
11+
const struct watchdog *watchdog = soc_get_peripherals()->watchdog;
12+
if (watchdog->wdt_disable) {
13+
watchdog->wdt_disable();
14+
}
15+
}
16+
17+
void enable_watchdogs(void)
18+
{
19+
const struct watchdog *watchdog = soc_get_peripherals()->watchdog;
20+
if (watchdog->wdt_enable) {
21+
watchdog->wdt_enable();
22+
}
23+
}

soc/include/peripherals/usb_otg.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0 OR MIT
5+
*/
6+
7+
#pragma once
8+
9+
#include <stdint.h>
10+
11+
#ifdef __cplusplus
12+
extern "C" {
13+
#endif
14+
15+
/* USB OTG peripheral structure */
16+
struct usb_otg {
17+
uint32_t usb_otg_intr_map_reg; /* USB OTG interrupt mapping */
18+
uint32_t hp_sys_usbotg20_ctrl_reg; /* USB OTG control register */
19+
uint32_t usb_inum; /* USB interrupt number */
20+
uint32_t clic_ext_intr_num_offset; /* RISC-V CLIC interrupt offset */
21+
};
22+
23+
#ifdef __cplusplus
24+
}
25+
#endif

soc/include/peripherals/watchdog.h

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0 OR MIT
5+
*/
6+
7+
#pragma once
8+
9+
#include <stdint.h>
10+
11+
#ifdef __cplusplus
12+
extern "C" {
13+
#endif
14+
15+
/* Watchdog peripheral structure */
16+
struct watchdog {
17+
/* Register offsets */
18+
uint32_t option1_reg;
19+
uint32_t wdtconfig0_reg;
20+
uint32_t wdtwprotect_reg;
21+
uint32_t swd_conf_reg;
22+
uint32_t swd_wprotect_reg;
23+
uint32_t cpu_per_conf_reg;
24+
uint32_t sysclk_conf_reg;
25+
26+
/* Chip-specific values */
27+
uint32_t swd_wkey;
28+
uint32_t wdt_wkey;
29+
uint32_t swd_auto_feed_en_bit;
30+
uint32_t force_download_boot_bit;
31+
uint32_t cpuperiod_sel_mask;
32+
uint32_t cpuperiod_sel_shift;
33+
uint32_t cpuperiod_max;
34+
uint32_t soc_clk_sel_mask;
35+
uint32_t soc_clk_sel_shift;
36+
uint32_t soc_clk_max;
37+
38+
/* Function pointers for RTC-specific operations */
39+
void (*wdt_disable)(void);
40+
void (*wdt_enable)(void);
41+
};
42+
43+
#ifdef __cplusplus
44+
}
45+
#endif

soc/include/soc.h

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0 OR MIT
5+
*/
6+
7+
#pragma once
8+
9+
#include <stdbool.h>
10+
#include <stdint.h>
11+
#include "peripherals/usb_otg.h"
12+
#include "peripherals/watchdog.h"
13+
14+
#ifdef __cplusplus
15+
extern "C" {
16+
#endif
17+
18+
/* Essential SoC Capabilities for flasher stub */
19+
struct soc_capabilities {
20+
bool is_riscv; /* RISC-V architecture (affects interrupt handling) */
21+
};
22+
23+
/* Essential peripherals for flasher stub */
24+
struct soc_peripherals {
25+
const struct usb_otg *usb_otg; /* USB-OTG communication */
26+
const struct watchdog *watchdog; /* Watchdog and power management */
27+
};
28+
29+
/* Main SoC structure */
30+
struct soc_info {
31+
const struct soc_capabilities *capabilities;
32+
const struct soc_peripherals *peripherals;
33+
uint8_t security_info_bytes;
34+
};
35+
36+
const struct soc_info* soc_get_info(void);
37+
38+
/* Convenience accessors */
39+
static inline const struct soc_capabilities* soc_get_capabilities(void)
40+
{
41+
return soc_get_info()->capabilities;
42+
}
43+
44+
static inline const struct soc_peripherals* soc_get_peripherals(void)
45+
{
46+
return soc_get_info()->peripherals;
47+
}
48+
49+
#ifdef __cplusplus
50+
}
51+
#endif

soc/targets/esp32.c

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0 OR MIT
5+
*/
6+
7+
#include <stddef.h>
8+
#include "soc.h"
9+
10+
/* ESP32 capabilities */
11+
static const struct soc_capabilities esp32_capabilities = {
12+
.is_riscv = false,
13+
};
14+
15+
/* ESP32 USB-OTG peripheral */
16+
static const struct usb_otg esp32_usb_otg = {
17+
.usb_otg_intr_map_reg = 0,
18+
.hp_sys_usbotg20_ctrl_reg = 0,
19+
.usb_inum = 0,
20+
.clic_ext_intr_num_offset = 0,
21+
};
22+
23+
/* ESP32 Watchdog peripheral */
24+
static const struct watchdog esp32_watchdog = {
25+
.option1_reg = 0,
26+
.wdtconfig0_reg = 0,
27+
.wdtwprotect_reg = 0,
28+
.swd_conf_reg = 0,
29+
.swd_wprotect_reg = 0,
30+
.cpu_per_conf_reg = 0,
31+
.sysclk_conf_reg = 0,
32+
.swd_wkey = 0,
33+
.wdt_wkey = 0,
34+
.swd_auto_feed_en_bit = 0,
35+
.force_download_boot_bit = 0,
36+
.cpuperiod_sel_mask = 0,
37+
.cpuperiod_sel_shift = 0,
38+
.cpuperiod_max = 0,
39+
.soc_clk_sel_mask = 0,
40+
.soc_clk_sel_shift = 0,
41+
.soc_clk_max = 0,
42+
.wdt_disable = NULL,
43+
.wdt_enable = NULL,
44+
};
45+
46+
/* ESP32 peripherals structure */
47+
static const struct soc_peripherals esp32_peripherals = {
48+
.usb_otg = &esp32_usb_otg,
49+
.watchdog = &esp32_watchdog,
50+
};
51+
52+
/* ESP32 SoC info */
53+
const struct soc_info g_soc_info = {
54+
.capabilities = &esp32_capabilities,
55+
.peripherals = &esp32_peripherals,
56+
.security_info_bytes = 0,
57+
};

soc/targets/esp32c2.c

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0 OR MIT
5+
*/
6+
7+
#include <stddef.h>
8+
#include "soc.h"
9+
10+
/* ESP32C2 capabilities */
11+
static const struct soc_capabilities esp32c2_capabilities = {
12+
.is_riscv = true,
13+
};
14+
15+
/* ESP32C2 USB-OTG peripheral */
16+
static const struct usb_otg esp32c2_usb_otg = {
17+
.usb_otg_intr_map_reg = 0,
18+
.hp_sys_usbotg20_ctrl_reg = 0,
19+
.usb_inum = 0,
20+
.clic_ext_intr_num_offset = 0,
21+
};
22+
23+
/* ESP32C2 Watchdog peripheral */
24+
static const struct watchdog esp32c2_watchdog = {
25+
.option1_reg = 0,
26+
.wdtconfig0_reg = 0,
27+
.wdtwprotect_reg = 0,
28+
.swd_conf_reg = 0,
29+
.swd_wprotect_reg = 0,
30+
.cpu_per_conf_reg = 0,
31+
.sysclk_conf_reg = 0,
32+
.swd_wkey = 0,
33+
.wdt_wkey = 0,
34+
.swd_auto_feed_en_bit = 0,
35+
.force_download_boot_bit = 0,
36+
.cpuperiod_sel_mask = 0,
37+
.cpuperiod_sel_shift = 0,
38+
.cpuperiod_max = 0,
39+
.soc_clk_sel_mask = 0,
40+
.soc_clk_sel_shift = 0,
41+
.soc_clk_max = 0,
42+
.wdt_disable = NULL,
43+
.wdt_enable = NULL,
44+
};
45+
46+
/* ESP32C2 peripherals structure */
47+
static const struct soc_peripherals esp32c2_peripherals = {
48+
.usb_otg = &esp32c2_usb_otg,
49+
.watchdog = &esp32c2_watchdog,
50+
};
51+
52+
/* ESP32C2 SoC info */
53+
const struct soc_info g_soc_info = {
54+
.capabilities = &esp32c2_capabilities,
55+
.peripherals = &esp32c2_peripherals,
56+
.security_info_bytes = 0,
57+
};

soc/targets/esp32c3.c

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0 OR MIT
5+
*/
6+
7+
#include <stddef.h>
8+
#include "soc.h"
9+
10+
/* ESP32C3 capabilities */
11+
static const struct soc_capabilities esp32c3_capabilities = {
12+
.is_riscv = true,
13+
};
14+
15+
/* ESP32C3 USB-OTG peripheral */
16+
static const struct usb_otg esp32c3_usb_otg = {
17+
.usb_otg_intr_map_reg = 0,
18+
.hp_sys_usbotg20_ctrl_reg = 0,
19+
.usb_inum = 0,
20+
.clic_ext_intr_num_offset = 0,
21+
};
22+
23+
/* ESP32C3 Watchdog peripheral */
24+
static const struct watchdog esp32c3_watchdog = {
25+
.option1_reg = 0,
26+
.wdtconfig0_reg = 0,
27+
.wdtwprotect_reg = 0,
28+
.swd_conf_reg = 0,
29+
.swd_wprotect_reg = 0,
30+
.cpu_per_conf_reg = 0,
31+
.sysclk_conf_reg = 0,
32+
.swd_wkey = 0,
33+
.wdt_wkey = 0,
34+
.swd_auto_feed_en_bit = 0,
35+
.force_download_boot_bit = 0,
36+
.cpuperiod_sel_mask = 0,
37+
.cpuperiod_sel_shift = 0,
38+
.cpuperiod_max = 0,
39+
.soc_clk_sel_mask = 0,
40+
.soc_clk_sel_shift = 0,
41+
.soc_clk_max = 0,
42+
.wdt_disable = NULL,
43+
.wdt_enable = NULL,
44+
};
45+
46+
/* ESP32C3 peripherals structure */
47+
static const struct soc_peripherals esp32c3_peripherals = {
48+
.usb_otg = &esp32c3_usb_otg,
49+
.watchdog = &esp32c3_watchdog,
50+
};
51+
52+
/* ESP32C3 SoC info */
53+
const struct soc_info g_soc_info = {
54+
.capabilities = &esp32c3_capabilities,
55+
.peripherals = &esp32c3_peripherals,
56+
.security_info_bytes = 0,
57+
};

0 commit comments

Comments
 (0)