RP 2040: Special handling for rescue DP

As the rescue DP provided no AP, trigger the reset with attach().
However attach will indicate failure also reset/halt has succeeded.
This commit is contained in:
Uwe Bonnes 2021-02-15 12:05:48 +01:00
parent ea92c8b8c8
commit fa5e69e3be
1 changed files with 23 additions and 20 deletions

View File

@ -42,21 +42,35 @@
#include "target_internal.h"
#include "cortexm.h"
#define BOOTROM_MAGIC ('M' | ('u' << 8) | (0x01 << 16))
#define BOOTROM_MAGIC_ADDR 0x00000010
bool rp_probe(target *t)
{
/* Check bootrom magic*/
uint32_t boot_magic = target_mem_read32(t, BOOTROM_MAGIC_ADDR);
if ((boot_magic & 0x00ffffff) != BOOTROM_MAGIC) {
DEBUG_WARN("Wrong Bootmagic %08" PRIx32 " found\n!", boot_magic);
return false;
}
t->driver = "Raspberry RP2040";
target_add_ram(t, 0x20000000, 0x40000);
return true;
}
static bool rp_rescue_do_reset(target *t)
{
ADIv5_AP_t *ap = (ADIv5_AP_t *)t->priv;
ap->dp->low_access(ap->dp, ADIV5_LOW_WRITE, ADIV5_DP_CTRLSTAT,
ADIV5_DP_CTRLSTAT_CDBGPWRUPREQ);
ap->dp->low_access(ap->dp, ADIV5_LOW_WRITE, ADIV5_DP_CTRLSTAT, 0);
return false;
}
static bool rp_rescue_reset(target *t, int argc, const char **argv);
const struct command_s rp_rescue_cmd_list[] = {
{"rescue_reset", (cmd_handler)rp_rescue_reset, "Hard reset to bootrom and halt"},
{NULL, NULL, NULL}
};
/* The RP Pico rescue DP provides no AP, so we need special handling
*
* Attach to this DP will do the reset, but will fail to attach!
*/
void rp_rescue_probe(ADIv5_AP_t *ap)
{
target *t = target_new();
@ -65,20 +79,9 @@ void rp_rescue_probe(ADIv5_AP_t *ap)
}
adiv5_ap_ref(ap);
t->attach = (void*)rp_rescue_do_reset;
t->priv = ap;
t->priv_free = (void*)adiv5_ap_unref;
t->driver = "Raspberry RP2040 Rescue";
t->driver = "Raspberry RP2040 Rescue(Attach to reset!)";
target_add_commands(t, rp_rescue_cmd_list, t->driver);
}
static bool rp_rescue_reset(target *t, int argc, const char **argv)
{
(void)argc;
(void)argv;
ADIv5_AP_t *ap = (ADIv5_AP_t *)t->priv;
ap->dp->low_access(ap->dp, ADIV5_LOW_WRITE, ADIV5_DP_CTRLSTAT,
ADIV5_DP_CTRLSTAT_CDBGPWRUPREQ);
ap->dp->low_access(ap->dp, ADIV5_LOW_WRITE, ADIV5_DP_CTRLSTAT, 0);
return true;
}