Flatten samd_probe.
This commit is contained in:
parent
5c337c9aa7
commit
1de685198c
124
src/samd.c
124
src/samd.c
|
@ -374,82 +374,80 @@ bool samd_probe(struct target_s *target)
|
||||||
uint32_t pid = samd_read_pid(target);
|
uint32_t pid = samd_read_pid(target);
|
||||||
|
|
||||||
/* Check the ARM Coresight Component and Perhiperal IDs */
|
/* Check the ARM Coresight Component and Perhiperal IDs */
|
||||||
if (cid == SAMD_CID_VALUE &&
|
if ((cid != SAMD_CID_VALUE) ||
|
||||||
(pid & SAMD_PID_MASK) == SAMD_PID_CONST_VALUE) {
|
((pid & SAMD_PID_MASK) != SAMD_PID_CONST_VALUE))
|
||||||
|
return false;
|
||||||
|
|
||||||
/* Read the Device ID */
|
/* Read the Device ID */
|
||||||
uint32_t did = target_mem_read32(target, SAMD_DSU_DID);
|
uint32_t did = target_mem_read32(target, SAMD_DSU_DID);
|
||||||
|
|
||||||
/* If the Device ID matches */
|
/* If the Device ID matches */
|
||||||
if ((did & SAMD_DID_MASK) == SAMD_DID_CONST_VALUE) {
|
if ((did & SAMD_DID_MASK) != SAMD_DID_CONST_VALUE)
|
||||||
|
return false;
|
||||||
|
|
||||||
uint32_t ctrlstat = target_mem_read32(target,
|
uint32_t ctrlstat = target_mem_read32(target,
|
||||||
SAMD_DSU_CTRLSTAT);
|
SAMD_DSU_CTRLSTAT);
|
||||||
struct samd_descr samd = samd_parse_device_id(did);
|
struct samd_descr samd = samd_parse_device_id(did);
|
||||||
|
|
||||||
/* Protected? */
|
/* Protected? */
|
||||||
int protected = (ctrlstat & SAMD_STATUSB_PROT);
|
bool protected = (ctrlstat & SAMD_STATUSB_PROT);
|
||||||
|
|
||||||
/* Part String */
|
/* Part String */
|
||||||
if (protected) {
|
if (protected) {
|
||||||
sprintf(variant_string,
|
sprintf(variant_string,
|
||||||
"Atmel SAMD%d%c%dA%s (rev %c) (PROT=1)",
|
"Atmel SAMD%d%c%dA%s (rev %c) (PROT=1)",
|
||||||
samd.series, samd.pin, samd.mem,
|
samd.series, samd.pin, samd.mem,
|
||||||
samd.package, samd.revision);
|
samd.package, samd.revision);
|
||||||
} else {
|
} else {
|
||||||
sprintf(variant_string,
|
sprintf(variant_string,
|
||||||
"Atmel SAMD%d%c%dA%s (rev %c)",
|
"Atmel SAMD%d%c%dA%s (rev %c)",
|
||||||
samd.series, samd.pin, samd.mem,
|
samd.series, samd.pin, samd.mem,
|
||||||
samd.package, samd.revision);
|
samd.package, samd.revision);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Setup Target */
|
/* Setup Target */
|
||||||
target->driver = variant_string;
|
target->driver = variant_string;
|
||||||
target->reset = samd_reset;
|
target->reset = samd_reset;
|
||||||
|
|
||||||
if (samd.series == 20 && samd.revision == 'B') {
|
if (samd.series == 20 && samd.revision == 'B') {
|
||||||
/**
|
/**
|
||||||
* These functions check for and
|
* These functions check for and
|
||||||
* extended reset. Appears to be
|
* extended reset. Appears to be
|
||||||
* related to Errata 35.4.1 ref 12015
|
* related to Errata 35.4.1 ref 12015
|
||||||
*/
|
*/
|
||||||
target->detach = samd20_revB_detach;
|
target->detach = samd20_revB_detach;
|
||||||
target->halt_resume = samd20_revB_halt_resume;
|
target->halt_resume = samd20_revB_halt_resume;
|
||||||
}
|
}
|
||||||
if (protected) {
|
if (protected) {
|
||||||
/**
|
/**
|
||||||
* Overload the default cortexm attach
|
* Overload the default cortexm attach
|
||||||
* for when the samd is protected.
|
* for when the samd is protected.
|
||||||
* This function allows users to
|
* This function allows users to
|
||||||
* attach on a temporary basis so they
|
* attach on a temporary basis so they
|
||||||
* can rescue the device.
|
* can rescue the device.
|
||||||
*/
|
*/
|
||||||
target->attach = samd_protected_attach;
|
target->attach = samd_protected_attach;
|
||||||
}
|
}
|
||||||
|
|
||||||
target->xml_mem_map = samd_xml_memory_map;
|
target->xml_mem_map = samd_xml_memory_map;
|
||||||
target->flash_erase = samd_flash_erase;
|
target->flash_erase = samd_flash_erase;
|
||||||
target->flash_write = samd_flash_write;
|
target->flash_write = samd_flash_write;
|
||||||
target_add_commands(target, samd_cmd_list, "SAMD");
|
target_add_commands(target, samd_cmd_list, "SAMD");
|
||||||
|
|
||||||
/* If we're not in reset here */
|
/* If we're not in reset here */
|
||||||
if (!connect_assert_srst) {
|
if (!connect_assert_srst) {
|
||||||
/* We'll have to release the target from
|
/* We'll have to release the target from
|
||||||
* extended reset to make attach possible */
|
* extended reset to make attach possible */
|
||||||
if (target_mem_read32(target, SAMD_DSU_CTRLSTAT) &
|
if (target_mem_read32(target, SAMD_DSU_CTRLSTAT) &
|
||||||
SAMD_STATUSA_CRSTEXT) {
|
SAMD_STATUSA_CRSTEXT) {
|
||||||
|
|
||||||
/* Write bit to clear from extended reset */
|
/* Write bit to clear from extended reset */
|
||||||
target_mem_write32(target, SAMD_DSU_CTRLSTAT,
|
target_mem_write32(target, SAMD_DSU_CTRLSTAT,
|
||||||
SAMD_STATUSA_CRSTEXT);
|
SAMD_STATUSA_CRSTEXT);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue