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 #2063

Closed
wants to merge 5 commits into from
Closed
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
1 change: 1 addition & 0 deletions src/platforms/hosted/serial_unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <netinet/in.h>

#define READ_BUFFER_LENGTH 4096U

Expand Down
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;
Copy link
Member

Choose a reason for hiding this comment

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

Do please note that this will only work for a single scan - the next run through will break. This is because previous_idx is static and so only initialised once on program start and is unable to be reset to 0.

It might be better to make the previous index used a return parameter to this function stored as a local in the calling context, this way it can be properly reinitialised on each new scan.

Copy link
Author

Choose a reason for hiding this comment

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

It works for multiple scans - first scan:
jtag_device_get_quirks() returning idx: 40
jtag_device_get_quirks() returning idx: 41

Second scan:
jtag_device_get_quirks() returning idx: 40
jtag_device_get_quirks() returning idx: 41

If it isn't static it will fail on the 1st scan:
jtag_device_get_quirks() returning idx: 40
jtag_device_get_quirks() returning idx: 40
jtag_scan: IR does not match the expected value, bailing out

Copy link
Member

Choose a reason for hiding this comment

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

We are not convinced, in part because consider: what happens if a scan fails having found the first TAP but before it can find the second, and then a user tries re-scanning? Please lift the previous index value out into the calling function as a local, and pass a pointer to it to this function. This hidden global is way too brittle.

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;

/* 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;
uint8_t counter = 0;
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