/*****************************************************************************
* *
-* mem_ap_write_buf(struct adiv5_dap *dap, uint8_t *buffer, int count, uint32_t address) *
+* mem_ap_write_buf(struct adiv5_dap *dap, uint8_t *buffer, int count, uint32_t address, bool addr_incr) *
* *
* Write a buffer in target order (little endian) *
* *
*****************************************************************************/
-int mem_ap_write_buf_u32(struct adiv5_dap *dap, const uint8_t *buffer, int count, uint32_t address)
+int mem_ap_write_buf_u32(struct adiv5_dap *dap, const uint8_t *buffer, int count, uint32_t address, bool addr_incr)
{
int wcount, blocksize, writecount, errorcount = 0, retval = ERROR_OK;
uint32_t adr = address;
const uint8_t *pBuffer = buffer;
+ uint32_t incr_flag = CSW_ADDRINC_OFF;
count >>= 2;
wcount = count;
if (blocksize == 0)
blocksize = 1;
- retval = dap_setup_accessport(dap, CSW_32BIT | CSW_ADDRINC_SINGLE, address);
+ if (addr_incr)
+ incr_flag = CSW_ADDRINC_SINGLE;
+
+ retval = dap_setup_accessport(dap, CSW_32BIT | incr_flag, address);
if (retval != ERROR_OK)
return retval;
for (writecount = 0; writecount < blocksize; writecount++) {
- retval = dap_queue_ap_write(dap, AP_REG_DRW,
- *(uint32_t *) ((void *) (buffer + 4 * writecount)));
+ uint32_t tmp;
+ tmp = buf_get_u32(buffer + 4 * writecount, 0, 32);
+ retval = dap_queue_ap_write(dap, AP_REG_DRW, tmp);
if (retval != ERROR_OK)
break;
}
retval = dap_run(dap);
if (retval == ERROR_OK) {
wcount = wcount - blocksize;
- address = address + 4 * blocksize;
+ if (addr_incr)
+ address = address + 4 * blocksize;
buffer = buffer + 4 * blocksize;
} else
errorcount++;
* @param buffer where the words will be stored (in host byte order).
* @param count How many words to read.
* @param address Memory address from which to read words; all the
+ * @param addr_incr if true, increment the source address for each u32
* words must be readable by the currently selected MEM-AP.
*/
int mem_ap_read_buf_u32(struct adiv5_dap *dap, uint8_t *buffer,
- int count, uint32_t address)
+ int count, uint32_t address, bool addr_incr)
{
int wcount, blocksize, readcount, errorcount = 0, retval = ERROR_OK;
uint32_t adr = address;
uint8_t *pBuffer = buffer;
+ uint32_t incr_flag = CSW_ADDRINC_OFF;
count >>= 2;
wcount = count;
if (blocksize == 0)
blocksize = 1;
- retval = dap_setup_accessport(dap, CSW_32BIT | CSW_ADDRINC_SINGLE,
+ if (addr_incr)
+ incr_flag = CSW_ADDRINC_SINGLE;
+
+ retval = dap_setup_accessport(dap, CSW_32BIT | incr_flag,
address);
if (retval != ERROR_OK)
return retval;
return retval;
}
wcount = wcount - blocksize;
- address += 4 * blocksize;
+ if (addr_incr)
+ address += 4 * blocksize;
buffer += 4 * blocksize;
}
return mem_ap_read_buf_u16(swjdp, buffer, count, address);
}
+int mem_ap_sel_read_buf_u32_noincr(struct adiv5_dap *swjdp, uint8_t ap,
+ uint8_t *buffer, int count, uint32_t address)
+{
+ dap_ap_select(swjdp, ap);
+ return mem_ap_read_buf_u32(swjdp, buffer, count, address, false);
+}
+
int mem_ap_sel_read_buf_u32(struct adiv5_dap *swjdp, uint8_t ap,
uint8_t *buffer, int count, uint32_t address)
{
dap_ap_select(swjdp, ap);
- return mem_ap_read_buf_u32(swjdp, buffer, count, address);
+ return mem_ap_read_buf_u32(swjdp, buffer, count, address, true);
}
int mem_ap_sel_write_buf_u8(struct adiv5_dap *swjdp, uint8_t ap,
const uint8_t *buffer, int count, uint32_t address)
{
dap_ap_select(swjdp, ap);
- return mem_ap_write_buf_u32(swjdp, buffer, count, address);
+ return mem_ap_write_buf_u32(swjdp, buffer, count, address, true);
+}
+
+int mem_ap_sel_write_buf_u32_noincr(struct adiv5_dap *swjdp, uint8_t ap,
+ const uint8_t *buffer, int count, uint32_t address)
+{
+ dap_ap_select(swjdp, ap);
+ return mem_ap_write_buf_u32(swjdp, buffer, count, address, false);
}
#define MDM_REG_STAT 0x00
&& ((cid1 & 0x0f) == 0) && cid0 == 0x0d;
}
+/*
+ * This function checks the ID for each access port to find the requested Access Port type
+ */
+int dap_find_ap(struct adiv5_dap *dap, enum ap_type type_to_find, uint8_t *ap_num_out)
+{
+ int ap;
+
+ /* Maximum AP number is 255 since the SELECT register is 8 bits */
+ for (ap = 0; ap <= 255; ap++) {
+
+ /* read the IDR register of the Access Port */
+ uint32_t id_val = 0;
+ dap_ap_select(dap, ap);
+
+ int retval = dap_queue_ap_read(dap, AP_REG_IDR, &id_val);
+ if (retval != ERROR_OK)
+ return retval;
+
+ retval = dap_run(dap);
+
+ /* IDR bits:
+ * 31-28 : Revision
+ * 27-24 : JEDEC bank (0x4 for ARM)
+ * 23-17 : JEDEC code (0x3B for ARM)
+ * 16 : Mem-AP
+ * 15-8 : Reserved
+ * 7-0 : AP Identity (1=AHB-AP 2=APB-AP 0x10=JTAG-AP)
+ */
+
+ /* Reading register for a non-existant AP should not cause an error,
+ * but just to be sure, try to continue searching if an error does happen.
+ */
+ if ((retval == ERROR_OK) && /* Register read success */
+ ((id_val & 0x0FFF0000) == 0x04770000) && /* Jedec codes match */
+ ((id_val & 0xFF) == type_to_find)) { /* type matches*/
+
+ LOG_DEBUG("Found %s at AP index: %d (IDR=0x%08X)",
+ (type_to_find == AP_TYPE_AHB_AP) ? "AHB-AP" :
+ (type_to_find == AP_TYPE_APB_AP) ? "APB-AP" :
+ (type_to_find == AP_TYPE_JTAG_AP) ? "JTAG-AP" : "Unknown",
+ ap, id_val);
+
+ *ap_num_out = ap;
+ return ERROR_OK;
+ }
+ }
+
+ LOG_DEBUG("No %s found",
+ (type_to_find == AP_TYPE_AHB_AP) ? "AHB-AP" :
+ (type_to_find == AP_TYPE_APB_AP) ? "APB-AP" :
+ (type_to_find == AP_TYPE_JTAG_AP) ? "JTAG-AP" : "Unknown");
+ return ERROR_FAIL;
+}
+
int dap_get_debugbase(struct adiv5_dap *dap, int ap,
uint32_t *out_dbgbase, uint32_t *out_apid)
{
type = "Cortex-M3 FBP";
full = "(Flash Patch and Breakpoint)";
break;
+ case 0x00c:
+ type = "Cortex-M4 SCS";
+ full = "(System Control Space)";
+ break;
case 0x00d:
type = "CoreSight ETM11";
full = "(Embedded Trace)";
type = "Cortex-M3 ETM";
full = "(Embedded Trace)";
break;
+ case 0x925:
+ type = "Cortex-M4 ETM";
+ full = "(Embedded Trace)";
+ break;
case 0x930:
type = "Cortex-R4 ETM";
full = "(Embedded Trace)";
break;
+ case 0x9a1:
+ type = "Cortex-M4 TPUI";
+ full = "(Trace Port Interface Unit)";
+ break;
case 0xc08:
type = "Cortex-A8 Debug";
full = "(Debug Unit)";