--- remote_bitbang.c 2016-10-31 11:06:57.812267924 +0600 +++ remote_bitbang.c 2016-10-31 12:33:57.921692808 +0600 @@ -120,11 +120,25 @@ remote_bitbang_putc(c); } +static int remote_bitbang_swdio_read (void) +{ + remote_swd_putc ('R'); + return remote_bitbang_rread (); +} + +static void remote_bitbang_swdio_drive (bool is_output) +{ + char c = is_output ? 'o' : 'i'; + remote_bitbang_putc (c); +} + static struct bitbang_interface remote_bitbang_bitbang = { .read = &remote_bitbang_read, .write = &remote_bitbang_write, .reset = &remote_bitbang_reset, .blink = &remote_bitbang_blink, + .swdio_read = &remote_bitbang_swdio_read, + .swdio_drive = &remote_bitbang_swdio_drive, }; static int remote_bitbang_init_tcp(void) @@ -271,10 +285,14 @@ COMMAND_REGISTRATION_DONE, }; +static const char * const remote_bitbang_transport[] = { "jtag", "swd", NULL }; + struct jtag_interface remote_bitbang_interface = { .name = "remote_bitbang", + .transports = remote_bitbang_transport, .execute_queue = &bitbang_execute_queue, .commands = remote_bitbang_command_handlers, + .swd = &bitbang_swd, .init = &remote_bitbang_init, .quit = &remote_bitbang_quit, };
#define SWCLK 0 #define SWDIO 2 IRAM void openocd_handler (void *pvParameters) { struct netconn *nc = (struct netconn *) pvParameters; struct netbuf *rbuf = NULL; char *rx_buf; char d, r; err_t err; uint16_t len; uint16_t i; gpio_set_pullup (SWCLK, false, false); gpio_set_pullup (SWDIO, false, false); gpio_enable (SWCLK, GPIO_OUTPUT); gpio_enable (SWDIO, GPIO_OUTPUT); while (1) { if ((err = netconn_recv (nc, &rbuf)) != ERR_OK) { printf ("R ERROR %d\n", err); return; } netbuf_data (rbuf, (void **) &rx_buf, &len); for (i = 0; i < len; i++) { switch (rx_buf [i]) { case 'Q': // Quit netconn_disconnect (nc); return; case '0'...'7': d = rx_buf [i] - '0'; gpio_write (SWDIO, (d & 0x1)); gpio_write (SWCLK, !!(d & 0x4)); break; case 'i': gpio_enable (SWDIO, GPIO_INPUT); break; case 'o': gpio_enable (SWDIO, GPIO_OUTPUT); break; case 'R': // Writeback r = ((char) gpio_read (SWDIO)) + '0'; netconn_write (nc, &r, 1, NETCONN_COPY); break; } } netbuf_delete (rbuf); } }
Source: https://habr.com/ru/post/398781/
All Articles