Skip to content
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

Add ESP32-P4 support #2064

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
26 changes: 26 additions & 0 deletions src/target/jtag_devs.c
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,32 @@ const jtag_dev_descr_s dev_descr[] = {
#endif
.handler = riscv_jtag_dtm_handler,
},
{
.idcode = 0x00012c25U,
.idmask = 0x0fffffffU,
#if ENABLE_DEBUG == 1
.descr = "ESP32-P4",
#endif
.handler = riscv_jtag_dtm_handler,
.ir_quirks =
{
.ir_length = 5U,
.ir_value = 5U,
},
},
{
.idcode = 0x00012c25U,
.idmask = 0x0fffffffU,
#if ENABLE_DEBUG == 1
.descr = "ESP32-P4",
#endif
.handler = riscv_jtag_dtm_handler,
.ir_quirks =
{
.ir_length = 5U,
.ir_value = 1U,
},
},
#endif
#if defined(CONFIG_CORTEXAR) // && defined(ENABLE_SITARA)
{
Expand Down
8 changes: 8 additions & 0 deletions src/target/jtag_scan.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,17 @@ static void jtag_display_idcodes(void)

static jtag_ir_quirks_s jtag_device_get_quirks(const uint32_t idcode)
{
static size_t previous_idx = 0;

for (size_t idx = 0; dev_descr[idx].idcode; ++idx) {
if ((idcode & dev_descr[idx].idmask) == dev_descr[idx].idcode)
{
/* workaround for ESP32-P4 which has 2 different ir_value */
if (idcode == 0x12c25U && previous_idx == idx)
idx++;
previous_idx = idx;
return dev_descr[idx].ir_quirks;
}
}
return (jtag_ir_quirks_s){0};
}
Expand Down
24 changes: 24 additions & 0 deletions src/target/riscv_debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,30 @@ void riscv_dmi_init(riscv_dmi_s *const dmi)
do {
/* Read out the DM's status register */
uint32_t dm_status = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one still needs moving down to line 330 please 🙂


/* Turn on DM before trying to read version */
if (!riscv_dmi_write(dmi, base_addr + RV_DM_CONTROL, RV_DM_CTRL_ACTIVE)) {
DEBUG_ERROR("error turning on DM!\n");
return;
}

/* After changing the value of dm_active, the debugger must poll dmcontrol
* until dm_active has taken the requested value */
bool dm_active = false;
uint32_t dm_control = 0;
while (!dm_active) {
if (!riscv_dmi_read(dmi, base_addr + RV_DM_CONTROL, &dm_control)) {
DEBUG_ERROR("error turning on DM!\n");
return;
}
dm_active = dm_control & 1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please suffix this constant with U - this does a signed-unsigned conversion that can trigger UB otherwise during application of the mask operation (changing the sign bit on a signed number is not permitted for bitwise operations).

uint8_t counter = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We would expect to see this defined just outside the while loop on line 317 - otherwise it won't have the intended effect.

Please suffix the initialiser and the comparison value with U to make them both unsigned.

if (++counter >= 100) {
DEBUG_ERROR("Timeout while trying to turn on DM\n");
return;
}
}

if (!riscv_dmi_read(dmi, base_addr + RV_DM_STATUS, &dm_status)) {
/* If we fail to read the status register, abort */
break;
Expand Down
Loading