Skip to content

Commit 994e17d

Browse files
committed
target/espressif: add esp32c61 initial support
1 parent f9bbc96 commit 994e17d

File tree

12 files changed

+385
-0
lines changed

12 files changed

+385
-0
lines changed

src/rtos/FreeRTOS.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,23 @@ static const struct freertos_params freertos_params_list[] = {
208208
NULL,
209209
rtos_freertos_riscv_pick_stacking_info, /* fn to pick stacking_info */
210210
},
211+
{
212+
"esp32c61", /* target_name */
213+
4, /* thread_count_width; */
214+
4, /* pointer_width; */
215+
16, /* list_next_offset; */
216+
8, /* list_end_offset; */
217+
20, /* list_width; */
218+
8, /* list_elem_next_offset; */
219+
12, /* list_elem_content_offset */
220+
0, /* thread_stack_offset; */
221+
52, /* thread_name_offset; */
222+
4, /* thread_counter_width */
223+
NULL, /* stacking_info */
224+
NULL,
225+
NULL,
226+
rtos_freertos_riscv_pick_stacking_info, /* fn to pick stacking_info */
227+
},
211228
{
212229
"esp32p4", /* target_name */
213230
4, /* thread_count_width; */

src/target/espressif/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ target_sources(espressif PRIVATE
1818
esp32h2.c
1919
esp32p4.c
2020
esp32c5.c
21+
esp32c61.c
2122
esp.c
2223
esp.h
2324
esp_riscv.c

src/target/espressif/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ noinst_LTLIBRARIES += %D%/libespressif.la
1717
%D%/esp32c6.c \
1818
%D%/esp32p4.c \
1919
%D%/esp32c5.c \
20+
%D%/esp32c61.c \
2021
%D%/esp.c \
2122
%D%/esp.h \
2223
%D%/esp_riscv.c \

src/target/espressif/esp32c61.c

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
// SPDX-License-Identifier: GPL-2.0-or-later
2+
3+
/***************************************************************************
4+
* ESP32-C61 target for OpenOCD *
5+
* Copyright (C) 2024 Espressif Systems Ltd. *
6+
***************************************************************************/
7+
8+
#ifdef HAVE_CONFIG_H
9+
#include "config.h"
10+
#endif
11+
12+
#include <helper/command.h>
13+
#include <helper/bits.h>
14+
#include <target/target.h>
15+
#include <target/target_type.h>
16+
#include <target/register.h>
17+
#include <target/semihosting_common.h>
18+
#include <target/riscv/debug_defines.h>
19+
20+
#include "esp_semihosting.h"
21+
#include "esp_riscv_apptrace.h"
22+
#include "esp_riscv.h"
23+
24+
/* max supported hw breakpoint and watchpoint count */
25+
#define ESP32C61_BP_NUM 3
26+
#define ESP32C61_WP_NUM 3
27+
28+
/* ASSIST_DEBUG registers */
29+
#define ESP32C61_ASSIST_DEBUG_CPU0_MON_REG 0xFFFFFFFF//0x600C2000
30+
31+
#define ESP32C61_DRAM_LOW 0x40800000
32+
#define ESP32C61_DRAM_HIGH 0x40860000
33+
34+
static bool esp32c61_is_idram_address(target_addr_t addr)
35+
{
36+
return addr >= ESP32C61_DRAM_LOW && addr < ESP32C61_DRAM_HIGH;
37+
}
38+
39+
static const struct esp_semihost_ops esp32c61_semihost_ops = {
40+
.prepare = NULL,
41+
.post_reset = esp_semihosting_post_reset
42+
};
43+
44+
static const struct esp_flash_breakpoint_ops esp32c61_flash_brp_ops = {
45+
.breakpoint_prepare = esp_algo_flash_breakpoint_prepare,
46+
.breakpoint_add = esp_algo_flash_breakpoint_add,
47+
.breakpoint_remove = esp_algo_flash_breakpoint_remove,
48+
.breakpoint_lazy_process = true,
49+
};
50+
51+
static const char *esp32c61_csrs[] = {
52+
"mideleg", "medeleg", "mie", "mip",
53+
};
54+
55+
static int esp32c61_target_create(struct target *target, Jim_Interp *interp)
56+
{
57+
struct esp_riscv_common *esp_riscv = calloc(1, sizeof(*esp_riscv));
58+
if (!esp_riscv)
59+
return ERROR_FAIL;
60+
61+
target->arch_info = esp_riscv;
62+
63+
esp_riscv->assist_debug_cpu0_mon_reg = ESP32C61_ASSIST_DEBUG_CPU0_MON_REG;
64+
esp_riscv->assist_debug_cpu_offset = 0;
65+
66+
esp_riscv->max_bp_num = ESP32C61_BP_NUM;
67+
esp_riscv->max_wp_num = ESP32C61_WP_NUM;
68+
69+
esp_riscv->rtccntl_reset_state_reg = 0;//ESP32C61_RTCCNTL_RESET_STATE_REG;
70+
esp_riscv->print_reset_reason = NULL;//&esp32c61_print_reset_reason;
71+
esp_riscv->existent_csrs = esp32c61_csrs;
72+
esp_riscv->existent_csr_size = ARRAY_SIZE(esp32c61_csrs);
73+
esp_riscv->is_dram_address = esp32c61_is_idram_address;
74+
esp_riscv->is_iram_address = esp32c61_is_idram_address;
75+
76+
if (esp_riscv_alloc_trigger_addr(target) != ERROR_OK)
77+
return ERROR_FAIL;
78+
79+
riscv_info_init(target, &esp_riscv->riscv);
80+
81+
return ERROR_OK;
82+
}
83+
84+
static int esp32c61_init_target(struct command_context *cmd_ctx,
85+
struct target *target)
86+
{
87+
int ret = riscv_target.init_target(cmd_ctx, target);
88+
if (ret != ERROR_OK)
89+
return ret;
90+
91+
target->semihosting->user_command_extension = esp_semihosting_common;
92+
93+
struct esp_riscv_common *esp_riscv = target_to_esp_riscv(target);
94+
95+
ret = esp_riscv_init_arch_info(target,
96+
esp_riscv,
97+
&esp32c61_flash_brp_ops,
98+
&esp32c61_semihost_ops);
99+
if (ret != ERROR_OK)
100+
return ret;
101+
102+
return ERROR_OK;
103+
}
104+
105+
static const struct command_registration esp32c61_command_handlers[] = {
106+
{
107+
.usage = "",
108+
.chain = riscv_command_handlers,
109+
},
110+
{
111+
.name = "esp",
112+
.usage = "",
113+
.chain = esp_riscv_command_handlers,
114+
},
115+
{
116+
.name = "esp",
117+
.usage = "",
118+
.chain = esp32_apptrace_command_handlers,
119+
},
120+
COMMAND_REGISTRATION_DONE
121+
};
122+
123+
struct target_type esp32c61_target = {
124+
.name = "esp32c61",
125+
126+
.target_create = esp32c61_target_create,
127+
.init_target = esp32c61_init_target,
128+
.deinit_target = esp_riscv_deinit_target,
129+
.examine = esp_riscv_examine,
130+
131+
/* poll current target status */
132+
.poll = esp_riscv_poll,
133+
134+
.halt = riscv_halt,
135+
.resume = esp_riscv_resume,
136+
.step = riscv_openocd_step,
137+
138+
.assert_reset = riscv_assert_reset,
139+
.deassert_reset = riscv_deassert_reset,
140+
141+
.read_memory = esp_riscv_read_memory,
142+
.write_memory = esp_riscv_write_memory,
143+
144+
.checksum_memory = riscv_checksum_memory,
145+
146+
.get_gdb_arch = riscv_get_gdb_arch,
147+
.get_gdb_reg_list = riscv_get_gdb_reg_list,
148+
.get_gdb_reg_list_noread = riscv_get_gdb_reg_list_noread,
149+
150+
.add_breakpoint = esp_riscv_breakpoint_add,
151+
.remove_breakpoint = esp_riscv_breakpoint_remove,
152+
153+
.add_watchpoint = riscv_add_watchpoint,
154+
.remove_watchpoint = riscv_remove_watchpoint,
155+
.hit_watchpoint = esp_riscv_hit_watchpoint,
156+
157+
.arch_state = riscv_arch_state,
158+
159+
.run_algorithm = esp_riscv_run_algorithm,
160+
.start_algorithm = esp_riscv_start_algorithm,
161+
.wait_algorithm = esp_riscv_wait_algorithm,
162+
163+
.commands = esp32c61_command_handlers,
164+
165+
.address_bits = riscv_xlen_nonconst,
166+
};

src/target/target.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ static struct target_type *target_types[] = {
9595
&esp32c3_target,
9696
&esp32c6_target,
9797
&esp32c5_target,
98+
&esp32c61_target,
9899
&esp32p4_target,
99100
&or1k_target,
100101
&quark_x10xx_target,

src/target/target_type.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@ extern struct target_type esp32c3_target;
340340
extern struct target_type esp32c6_target;
341341
extern struct target_type esp32p4_target;
342342
extern struct target_type esp32c5_target;
343+
extern struct target_type esp32c61_target;
343344
extern struct target_type fa526_target;
344345
extern struct target_type feroceon_target;
345346
extern struct target_type hla_target;

tcl/board/esp32c61-bridge.cfg

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# SPDX-License-Identifier: GPL-2.0-or-later
2+
#
3+
# Example OpenOCD configuration file for ESP32-C61 connected via ESP USB Bridge board
4+
#
5+
# For example, OpenOCD can be started for ESP32-C61 debugging on
6+
#
7+
# openocd -f board/esp32c61-bridge.cfg
8+
#
9+
10+
# Source the JTAG interface configuration file
11+
source [find interface/esp_usb_bridge.cfg]
12+
# ESP32C61 chip id defined in the idf esp_chip_model_t
13+
espusbjtag chip_id 20
14+
# Source the ESP32-C61 configuration file
15+
source [find target/esp32c61.cfg]

tcl/board/esp32c61-builtin.cfg

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# SPDX-License-Identifier: GPL-2.0-or-later
2+
#
3+
# Example OpenOCD configuration file for ESP32-C61 connected via builtin USB-JTAG adapter.
4+
#
5+
# For example, OpenOCD can be started for ESP32-C61 debugging on
6+
#
7+
# openocd -f board/esp32c61-builtin.cfg
8+
#
9+
10+
# Source the JTAG interface configuration file
11+
source [find interface/esp_usb_jtag.cfg]
12+
# Source the ESP32-C61 configuration file
13+
source [find target/esp32c61.cfg]

tcl/board/esp32c61-ftdi.cfg

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# SPDX-License-Identifier: GPL-2.0-or-later
2+
#
3+
# Example OpenOCD configuration file for ESP32-C61 connected via ESP-Prog.
4+
#
5+
# For example, OpenOCD can be started for ESP32-C61 debugging on
6+
#
7+
# openocd -f board/esp32c61-ftdi.cfg
8+
#
9+
10+
# Source the JTAG interface configuration file
11+
source [find interface/ftdi/esp32_devkitj_v1.cfg]
12+
# Source the ESP32-C61 configuration file
13+
source [find target/esp32c61.cfg]

tcl/esp-config-schema.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@
136136
"esp32c3",
137137
"esp32c5",
138138
"esp32c6",
139+
"esp32c61",
139140
"esp32h2",
140141
"esp32p4"
141142
]

0 commit comments

Comments
 (0)