[app][mdebug] support v1.0 rswd protocol
- report protocol version, board id, build id, maxdata - report swd clk frequency when it changes
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
/* rswd.c
|
||||
*
|
||||
* Copyright 2011-2015 Brian Swetland <swetland@frotz.net>
|
||||
*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
@@ -29,6 +29,11 @@ unsigned usb_recv(void *data, unsigned len);
|
||||
|
||||
unsigned swdp_trace = 0;
|
||||
|
||||
// indicates host knows about v1.0 protocol features
|
||||
unsigned host_version = 0;
|
||||
|
||||
#define VERSION_1_0 0x0100
|
||||
|
||||
static u8 optable[16] = {
|
||||
[OP_RD | OP_DP | OP_X0] = RD_IDCODE,
|
||||
[OP_RD | OP_DP | OP_X4] = RD_DPCTRL,
|
||||
@@ -48,6 +53,9 @@ static u8 optable[16] = {
|
||||
[OP_WR | OP_AP | OP_XC] = WR_AP3,
|
||||
};
|
||||
|
||||
static const char *board_str = TARGET;
|
||||
static const char *build_str = "fw v0.9 (" __DATE__ ", " __TIME__ ")";
|
||||
|
||||
/* TODO bounds checking -- we trust the host far too much */
|
||||
void process_txn(u32 txnid, u32 *rx, int rxc, u32 *tx) {
|
||||
unsigned msg, op, n;
|
||||
@@ -79,7 +87,7 @@ void process_txn(u32 txnid, u32 *rx, int rxc, u32 *tx) {
|
||||
}
|
||||
continue;
|
||||
case CMD_SWD_READ:
|
||||
tx[txc++] = RSWD_MSG(CMD_SWD_DATA, 0, n);
|
||||
tx[txc++] = RSWD_MSG(CMD_SWD_DATA, 0, n);
|
||||
while (n-- > 0) {
|
||||
if (swd_read(optable[op], tx + txc)) {
|
||||
txc++;
|
||||
@@ -129,6 +137,28 @@ void process_txn(u32 txnid, u32 *rx, int rxc, u32 *tx) {
|
||||
case CMD_SET_CLOCK:
|
||||
n = swd_set_clock(n);
|
||||
printf("swdp clock is now %d KHz\n", n);
|
||||
if (host_version >= VERSION_1_0) {
|
||||
tx[txc++] = RSWD_MSG(CMD_CLOCK_KHZ, 0, n);
|
||||
}
|
||||
continue;
|
||||
case CMD_VERSION:
|
||||
host_version = n;
|
||||
tx[txc++] = RSWD_MSG(CMD_VERSION, 0, VERSION_1_0);
|
||||
|
||||
n = strlen(board_str);
|
||||
memcpy(tx + txc + 1, board_str, n + 1);
|
||||
n = (n + 4) / 4;
|
||||
tx[txc++] = RSWD_MSG(CMD_BOARD_STR, 0, n);
|
||||
txc += n;
|
||||
|
||||
n = strlen(build_str);
|
||||
memcpy(tx + txc + 1, build_str, n + 1);
|
||||
n = (n + 4) / 4;
|
||||
tx[txc++] = RSWD_MSG(CMD_BUILD_STR, 0, n);
|
||||
txc += n;
|
||||
|
||||
tx[txc++] = RSWD_MSG(CMD_RX_MAXDATA, 0, 8192);
|
||||
txc += n;
|
||||
continue;
|
||||
default:
|
||||
printf("unknown command %02x\n", RSWD_MSG_CMD(msg));
|
||||
@@ -160,7 +190,7 @@ done:
|
||||
for (n = 0; n < 1000000; n++) asm("nop");
|
||||
func();
|
||||
for (;;) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// io buffers in AHB SRAM
|
||||
@@ -179,7 +209,7 @@ void handle_rswd(void) {
|
||||
#endif
|
||||
|
||||
for (;;) {
|
||||
rxc = usb_recv(rxbuffer, 4096);
|
||||
rxc = usb_recv(rxbuffer, 8192);
|
||||
|
||||
#if CONFIG_MDEBUG_TRACE
|
||||
int n;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* rswdp.h - remote serial wire debug protocol
|
||||
*
|
||||
* Copyright 2011 Brian Swetland <swetland@frotz.net>
|
||||
*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
@@ -23,14 +23,14 @@
|
||||
/* Basic framing:
|
||||
* - host and device exchange "transactions" consisting of
|
||||
* some number of "messages".
|
||||
* - each "message" has a 32bit header and may have 0 or more
|
||||
* 32bit words of payload
|
||||
* - each "message" has a 32bit header and may have 0 or more
|
||||
* 32bit words of payload
|
||||
* - a transaction may not exceed 4K (1024 words)
|
||||
* - a transaction is sent in a series of USB BULK packets
|
||||
* - the final packet must be a short packet unless the
|
||||
* - the final packet must be a short packet unless the
|
||||
* transaction is exactly 4K in length
|
||||
* - packets must be a multiple of 4 bytes
|
||||
* - the first message in a transaction must be
|
||||
* - the first message in a transaction must be
|
||||
* CMD_TXN_START or CMD_TXN_ASYNC
|
||||
*/
|
||||
|
||||
@@ -50,7 +50,7 @@
|
||||
#define CMD_SWD_READ 0x02 /* op=addr arg=count payload: data x count */
|
||||
#define CMD_SWD_DISCARD 0x03 /* op=addr arg=count payload: none (discards) */
|
||||
#define CMD_ATTACH 0x04 /* do swdp reset/connect handshake */
|
||||
#define CMD_RESET 0x05 /* arg=1 -> assert RESETn, otherwise deassert */
|
||||
#define CMD_RESET 0x05 /* arg=1 -> assert RESETn, otherwise deassert */
|
||||
#define CMD_DOWNLOAD 0x06 /* arg=wordcount, payload: addr x 1, data x n */
|
||||
#define CMD_EXECUTE 0x07 /* payload: addr x 1 */
|
||||
#define CMD_TRACE 0x08 /* op=tracebits n=0 */
|
||||
@@ -64,6 +64,15 @@
|
||||
/* valid: target to host async */
|
||||
#define CMD_DEBUG_PRINT 0x20 /* arg*4 bytes of ascii debug output */
|
||||
|
||||
/* valid: bidirectional query/config messages */
|
||||
#define CMD_VERSION 0x30 /* arg=bcdversion (0x0100 etc) */
|
||||
#define CMD_BUILD_STR 0x31 /* arg=wordcount, payload = asciiz */
|
||||
#define CMD_BOARD_STR 0x32 /* arg=wordcount, payload = asciiz */
|
||||
#define CMD_RX_MAXDATA 0x33 /* arg=bytes, declares senders rx buffer size */
|
||||
#define CMD_CLOCK_KHZ 0x34 /* arg=khz, reports active clock rate */
|
||||
|
||||
#define RSWD_VERSION 0x0100
|
||||
|
||||
/* CMD_SWD_OP operations - combine for direct AP/DP io */
|
||||
#define OP_RD 0x00
|
||||
#define OP_WR 0x01
|
||||
|
||||
Reference in New Issue
Block a user