Skip to content

Commit

Permalink
nrf51: Rename MDM to CTRL-AP
Browse files Browse the repository at this point in the history
MDM is a NXP-specific term, Nordic calls it a CTRL-AP.
  • Loading branch information
zyp committed Dec 3, 2024
1 parent a782475 commit e94242c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/target/adiv5.c
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ void adiv5_dp_init(adiv5_debug_port_s *const dp)
}

kinetis_mdm_probe(ap);
nrf51_mdm_probe(ap);
nrf51_ctrl_ap_probe(ap);
nrf54l_ctrl_ap_probe(ap);
efm32_aap_probe(ap);
lpc55_dmap_probe(ap);
Expand Down
40 changes: 20 additions & 20 deletions src/target/nrf51.c
Original file line number Diff line number Diff line change
Expand Up @@ -400,20 +400,20 @@ static bool nrf51_cmd_read(target_s *t, int argc, const char **argv)
return nrf51_cmd_read_help(t, 0, NULL);
}

#define NRF52_MDM_IDR 0x02880000U
#define NRF52_CTRL_AP_IDR 0x02880000U

static bool nrf51_mdm_mass_erase(target_s *t, platform_timeout_s *print_progess);
static bool nrf51_ctrl_ap_mass_erase(target_s *t, platform_timeout_s *print_progess);

#define MDM_POWER_EN ADIV5_DP_REG(0x01U)
#define MDM_SELECT_AP ADIV5_DP_REG(0x02U)
#define MDM_STATUS ADIV5_AP_REG(0x08U)
#define MDM_CONTROL ADIV5_AP_REG(0x04U)
#define MDM_PROT_EN ADIV5_AP_REG(0x0cU)
#define CTRL_AP_POWER_EN ADIV5_DP_REG(0x01U)
#define CTRL_AP_SELECT_AP ADIV5_DP_REG(0x02U)
#define CTRL_AP_STATUS ADIV5_AP_REG(0x08U)
#define CTRL_AP_CONTROL ADIV5_AP_REG(0x04U)
#define CTRL_AP_PROT_EN ADIV5_AP_REG(0x0cU)

bool nrf51_mdm_probe(adiv5_access_port_s *ap)
bool nrf51_ctrl_ap_probe(adiv5_access_port_s *ap)
{
switch (ap->idr) {
case NRF52_MDM_IDR:
case NRF52_CTRL_AP_IDR:
break;
default:
return false;
Expand All @@ -424,13 +424,13 @@ bool nrf51_mdm_probe(adiv5_access_port_s *ap)
return false;

t->enter_flash_mode = target_enter_flash_mode_stub;
t->mass_erase = nrf51_mdm_mass_erase;
t->mass_erase = nrf51_ctrl_ap_mass_erase;
adiv5_ap_ref(ap);
t->priv = ap;
t->priv_free = (void *)adiv5_ap_unref;

uint32_t status = adiv5_ap_read(ap, MDM_PROT_EN);
status = adiv5_ap_read(ap, MDM_PROT_EN);
uint32_t status = adiv5_ap_read(ap, CTRL_AP_PROT_EN);
status = adiv5_ap_read(ap, CTRL_AP_PROT_EN);
if (status)
t->driver = "Nordic nRF52 Access Port";
else
Expand All @@ -440,24 +440,24 @@ bool nrf51_mdm_probe(adiv5_access_port_s *ap)
return true;
}

static bool nrf51_mdm_mass_erase(target_s *const t, platform_timeout_s *const print_progess)
static bool nrf51_ctrl_ap_mass_erase(target_s *const t, platform_timeout_s *const print_progess)
{
adiv5_access_port_s *const ap = t->priv;

uint32_t status = adiv5_ap_read(ap, MDM_STATUS);
adiv5_dp_write(ap->dp, MDM_POWER_EN, 0x50000000U);
adiv5_dp_write(ap->dp, MDM_SELECT_AP, 0x01000000U);
adiv5_ap_write(ap, MDM_CONTROL, 0x00000001U);
uint32_t status = adiv5_ap_read(ap, CTRL_AP_STATUS);
adiv5_dp_write(ap->dp, CTRL_AP_POWER_EN, 0x50000000U);
adiv5_dp_write(ap->dp, CTRL_AP_SELECT_AP, 0x01000000U);
adiv5_ap_write(ap, CTRL_AP_CONTROL, 0x00000001U);

// Read until 0, probably should have a timeout here...
do {
status = adiv5_ap_read(ap, MDM_STATUS);
status = adiv5_ap_read(ap, CTRL_AP_STATUS);
target_print_progress(print_progess);
} while (status);

// The second read will provide true prot status
status = adiv5_ap_read(ap, MDM_PROT_EN);
status = adiv5_ap_read(ap, MDM_PROT_EN);
status = adiv5_ap_read(ap, CTRL_AP_PROT_EN);
status = adiv5_ap_read(ap, CTRL_AP_PROT_EN);

// Should we return the prot status here?
return true;
Expand Down
2 changes: 1 addition & 1 deletion src/target/target_probe.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ TARGET_PROBE_WEAK_NOP(riscv64_probe)
CORTEXM_PROBE_WEAK_NOP(efm32_aap_probe)
CORTEXM_PROBE_WEAK_NOP(kinetis_mdm_probe)
CORTEXM_PROBE_WEAK_NOP(lpc55_dmap_probe)
CORTEXM_PROBE_WEAK_NOP(nrf51_mdm_probe)
CORTEXM_PROBE_WEAK_NOP(nrf51_ctrl_ap_probe)
CORTEXM_PROBE_WEAK_NOP(nrf54l_ctrl_ap_probe)
CORTEXM_PROBE_WEAK_NOP(rp2040_rescue_probe)

Expand Down
2 changes: 1 addition & 1 deletion src/target/target_probe.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ bool riscv64_probe(target_s *target);
bool efm32_aap_probe(adiv5_access_port_s *ap);
bool kinetis_mdm_probe(adiv5_access_port_s *ap);
bool lpc55_dmap_probe(adiv5_access_port_s *ap);
bool nrf51_mdm_probe(adiv5_access_port_s *ap);
bool nrf51_ctrl_ap_probe(adiv5_access_port_s *ap);
bool nrf54l_ctrl_ap_probe(adiv5_access_port_s *ap);
bool rp2040_rescue_probe(adiv5_access_port_s *ap);

Expand Down

0 comments on commit e94242c

Please sign in to comment.