Select one of the symbols to view example projects that use it.
 
Outline
#include "config.h"
#include <jtag/interface.h>
#include <jtag/swd.h>
#include <jtag/commands.h>
#include "libusb_helper.h"
#define VID
#define PID
#define BULK_EP_OUT
#define BULK_EP_IN
#define PICOPROBE_INTERFACE
#define PICOPROBE_MAX_PACKET_LENGTH
#define LIBUSB_TIMEOUT
picoprobe
swd_cmd_queue
swd_cmd_queue_length
swd_cmd_queue_alloced
queued_retval
picoprobe_handle
PROBE_CMDS
probe_cmd_hdr
probe_pkt_hdr
#define PICOPROBE_QUEUE_SIZE
picoprobe_queue
picoprobe_queue_length
picoprobe_queue_alloced
packet_length(uint8_t *)
picoprobe_bulk_write(struct probe_pkt_hdr *, uint8_t *)
picoprobe_flush()
picoprobe_read_write_bits(const uint8_t *, unsigned int, unsigned int, uint8_t)
picoprobe_write_bits(const uint8_t *, unsigned int, unsigned int)
picoprobe_read_bits(const uint8_t *, unsigned int, unsigned int)
picoprobe_swd_run_queue()
picoprobe_swd_queue_cmd(uint8_t, uint32_t *, uint32_t, uint32_t)
picoprobe_swd_read_reg(uint8_t, uint32_t *, uint32_t)
picoprobe_swd_write_reg(uint8_t, uint32_t, uint32_t)
picoprobe_set_frequency(int_least32_t)
picoprobe_speed(int_least32_t)
picoprobe_khz(int, int *)
picoprobe_speed_div(int, int *)
picoprobe_swd_init()
picoprobe_swd_switch_seq(enum swd_special_seq)
picoprobe_reset(int, int)
picoprobe_swd
picoprobe_transports
picoprobe_adapter_driver
picoprobe_usb_open()
picoprobe_usb_close()
picoprobe_init()
picoprobe_quit()
Files
loading...
SourceVuDevelopment ToolsOpenOCDsrc/jtag/drivers/picoprobe.c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/*************************************************************************** * Copyright (C) 2020 by Liam Fraser * * liam@raspberrypi.com * * * * Based on: kitprog.c, ftdi.c, mpsse.c * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see <http://www.gnu.org/licenses/>. * ***************************************************************************//* ... */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include <jtag/interface.h> #include <jtag/swd.h> #include <jtag/commands.h> #include "libusb_helper.h" #define VID 0x2E8A /* Raspberry Pi */ #define PID 0x0004 /* Picoprobe */ #define BULK_EP_OUT 4 #define BULK_EP_IN 5 #define PICOPROBE_INTERFACE 2 #define PICOPROBE_MAX_PACKET_LENGTH 512 #define LIBUSB_TIMEOUT 10000 7 defines struct picoprobe { struct libusb_device_handle *usb_handle; uint8_t *packet_buffer; int freq; ...}; static struct swd_cmd_queue_entry { uint8_t cmd; uint32_t *dst; uint8_t trn_ack_data_parity_trn[DIV_ROUND_UP(4 + 3 + 32 + 1 + 4, 8)]; ...} *swd_cmd_queue; static size_t swd_cmd_queue_length; static size_t swd_cmd_queue_alloced; static int queued_retval; static struct picoprobe *picoprobe_handle; static int picoprobe_init(void); static int picoprobe_quit(void); enum PROBE_CMDS { PROBE_INVALID = 0, /* Invalid */ PROBE_WRITE_BITS = 1, /* Host wants us to write bits */ PROBE_READ_BITS = 2, /* Host wants us to read bits */ PROBE_SET_FREQ = 3, /* Set TCK freq */ PROBE_RESET = 4 ...}; struct __attribute__((__packed__)) probe_cmd_hdr { uint8_t id; uint8_t cmd; uint32_t bits; ...}; struct __attribute__((__packed__)) probe_pkt_hdr { uint32_t total_packet_length; ...}; /* Separate queue to swd_cmd_queue because we sometimes insert idle cycles not described * there *//* ... */ #define PICOPROBE_QUEUE_SIZE 64 static struct picoprobe_queue_entry { uint8_t id; uint8_t cmd; /* PROBE_CMDS */ unsigned bits; unsigned offset; const uint8_t *buf; ...} *picoprobe_queue; static size_t picoprobe_queue_length; static size_t picoprobe_queue_alloced; static inline unsigned packet_length(uint8_t *pkt) { return pkt - picoprobe_handle->packet_buffer; }{ ... } static int picoprobe_bulk_write(struct probe_pkt_hdr *pkt_hdr, uint8_t *pkt) { pkt_hdr->total_packet_length = packet_length(pkt); assert(pkt_hdr->total_packet_length <= PICOPROBE_MAX_PACKET_LENGTH); int ret = 0; jtag_libusb_bulk_write(picoprobe_handle->usb_handle, BULK_EP_OUT, (char *)picoprobe_handle->packet_buffer, packet_length(pkt), LIBUSB_TIMEOUT, &ret); if (ret < 0) return ERROR_JTAG_DEVICE_ERROR; return ERROR_OK; }{ ... } static int picoprobe_flush(void) { LOG_DEBUG_IO("Flush %d transactions", (int)picoprobe_queue_length); int ret = ERROR_OK; struct probe_pkt_hdr *pkt_hdr = (struct probe_pkt_hdr *)picoprobe_handle->packet_buffer; /* Chain pending write and read commands together */ uint8_t *pkt = picoprobe_handle->packet_buffer + sizeof(struct probe_pkt_hdr); unsigned total_reads = 0; unsigned total_read_bytes = 0; for (unsigned i = 0; i < picoprobe_queue_length; i++) { /* Copy header regardless of read or write */ struct picoprobe_queue_entry *q = &picoprobe_queue[i]; struct probe_cmd_hdr *hdr = (struct probe_cmd_hdr *)pkt; if (q->id != i) { LOG_ERROR("Wrong queue id. q->id %d != %d", q->id, i); return ERROR_JTAG_DEVICE_ERROR; }if (q->id != i) { ... } hdr->id = q->id; hdr->cmd = q->cmd; hdr->bits = q->bits; pkt += sizeof(struct probe_cmd_hdr); unsigned length_bytes = DIV_ROUND_UP(q->bits, 8); if (q->cmd == PROBE_WRITE_BITS) { /* Copy the data to write into the packet buffer */ if (q->buf) { bit_copy(pkt, 0, q->buf, q->offset, q->bits); }if (q->buf) { ... } else { /* Make sure the packet buffer is zerod to clock zeros */ assert(q->offset == 0); memset(pkt, 0, length_bytes); }else { ... } pkt += length_bytes; }if (q->cmd == PROBE_WRITE_BITS) { ... } else if (q->cmd == PROBE_READ_BITS) { /* Nothing to do for a read as we have already copied the header * Will process the data later in one go *//* ... */ total_reads++; total_read_bytes += length_bytes; }else if (q->cmd == PROBE_READ_BITS) { ... } else { /* Unexpected cmd to flush */ return ERROR_FAIL; }else { ... } }for (unsigned i = 0; i < picoprobe_queue_length; i++) { ... } /* Send all read/write commands + write data */ ret = picoprobe_bulk_write(pkt_hdr, pkt); if (ret < 0) return ERROR_JTAG_DEVICE_ERROR; /* If no reads we can bail */ if (total_reads == 0) { picoprobe_queue_length = 0; return ret; }if (total_reads == 0) { ... } /* Now get any read responses */ unsigned rx_pkt_len = sizeof(struct probe_pkt_hdr) + (sizeof(struct probe_cmd_hdr) * total_reads) + total_read_bytes; jtag_libusb_bulk_read(picoprobe_handle->usb_handle, BULK_EP_IN | LIBUSB_ENDPOINT_IN, (char *)picoprobe_handle->packet_buffer, rx_pkt_len, LIBUSB_TIMEOUT, &ret); if (ret < 0) return ERROR_JTAG_DEVICE_ERROR; /* Now time to process the rx data */ LOG_DEBUG_IO("Read %d bytes from probe", ret); /* If we didn't get length we expected */ if ((int)rx_pkt_len != ret) return ERROR_JTAG_DEVICE_ERROR; struct probe_pkt_hdr *response_hdr = (struct probe_pkt_hdr *)picoprobe_handle->packet_buffer; if (rx_pkt_len != response_hdr->total_packet_length) return ERROR_JTAG_DEVICE_ERROR; pkt = picoprobe_handle->packet_buffer + sizeof(struct probe_pkt_hdr); /* Now go through read responses */ for (unsigned i = 0; i < total_reads; i++) { struct probe_cmd_hdr *read_hdr = (struct probe_cmd_hdr *)pkt; pkt += sizeof(struct probe_cmd_hdr); unsigned read_bytes = DIV_ROUND_UP(read_hdr->bits, 8); if (read_hdr->cmd != PROBE_READ_BITS) return ERROR_JTAG_DEVICE_ERROR; uint8_t id = read_hdr->id; struct picoprobe_queue_entry *q = &picoprobe_queue[id]; assert(read_hdr->cmd == q->cmd); assert(read_hdr->id == q->id); assert(read_hdr->bits == q->bits); LOG_DEBUG_IO("Processing read of %d bits", read_hdr->bits); /* Copy data back to swd cmd queue */ memcpy((void *)q->buf, pkt, read_bytes); pkt += read_bytes; }for (unsigned i = 0; i < total_reads; i++) { ... } unsigned processed_len = (pkt - picoprobe_handle->packet_buffer); if (processed_len != rx_pkt_len) return ERROR_JTAG_DEVICE_ERROR; picoprobe_queue_length = 0; /* Keep gdb alive */ keep_alive(); return ERROR_OK; }{ ... } static int picoprobe_read_write_bits(const uint8_t *buf, unsigned offset, unsigned length, uint8_t cmd) { if (picoprobe_queue_length == picoprobe_queue_alloced) { LOG_ERROR("Picoprobe queue full"); return ERROR_BUF_TOO_SMALL; }if (picoprobe_queue_length == picoprobe_queue_alloced) { ... } else { LOG_DEBUG_IO("Picoprobe queue len %d -> %d", (int)picoprobe_queue_length, (int)picoprobe_queue_length + 1); }else { ... } struct picoprobe_queue_entry *q = &picoprobe_queue[picoprobe_queue_length]; q->id = picoprobe_queue_length++; q->cmd = cmd; q->bits = length; q->offset = offset; q->buf = buf; return ERROR_OK; }{ ... } static int picoprobe_write_bits(const uint8_t *buf, unsigned offset, unsigned length) { LOG_DEBUG_IO("Write %d bits @ offset %d", length, offset); return picoprobe_read_write_bits(buf, offset, length, PROBE_WRITE_BITS); }{ ... } static int picoprobe_read_bits(const uint8_t *buf, unsigned offset, unsigned length) { LOG_DEBUG_IO("Read %d bits @ offset %d", length, offset); if (picoprobe_queue_length == picoprobe_queue_alloced) return ERROR_BUF_TOO_SMALL; return picoprobe_read_write_bits(buf, offset, length, PROBE_READ_BITS); }{ ... } static int picoprobe_swd_run_queue(void) { LOG_DEBUG_IO("Executing %zu queued transactions", swd_cmd_queue_length); int retval; queued_retval = picoprobe_flush(); if (queued_retval != ERROR_OK) { LOG_DEBUG_IO("Skipping due to previous errors: %d", queued_retval); goto skip; }if (queued_retval != ERROR_OK) { ... } for (size_t i = 0; i < swd_cmd_queue_length; i++) { if (0 == ((swd_cmd_queue[i].cmd ^ swd_cmd(false, false, DP_TARGETSEL)) & (SWD_CMD_APNDP|SWD_CMD_RNW|SWD_CMD_A32))) { /* Targetsel has no ack so force it */ buf_set_u32(swd_cmd_queue[i].trn_ack_data_parity_trn, 1, 3, SWD_ACK_OK); }if (0 == ((swd_cmd_queue[i].cmd ^ swd_cmd(false, false, DP_TARGETSEL)) & (SWD_CMD_APNDP|SWD_CMD_RNW|SWD_CMD_A32))) { ... } LOG_DEBUG_IO("trn_ack_data_parity_trn:"); for (size_t y = 0; y < sizeof(swd_cmd_queue[i].trn_ack_data_parity_trn); y++) LOG_DEBUG_IO("BYTE %d 0x%x", (int)y, swd_cmd_queue[i].trn_ack_data_parity_trn[y]); int ack = buf_get_u32(swd_cmd_queue[i].trn_ack_data_parity_trn, 1, 3); LOG_DEBUG_IO("%s %s %s reg %X = %08"PRIx32, ack == SWD_ACK_OK ? "OK" : ack == SWD_ACK_WAIT ? "WAIT" : ack == SWD_ACK_FAULT ? "FAULT" : "JUNK", swd_cmd_queue[i].cmd & SWD_CMD_APNDP ? "AP" : "DP", swd_cmd_queue[i].cmd & SWD_CMD_RNW ? "read" : "write", (swd_cmd_queue[i].cmd & SWD_CMD_A32) >> 1, buf_get_u32(swd_cmd_queue[i].trn_ack_data_parity_trn, 1 + 3 + (swd_cmd_queue[i].cmd & SWD_CMD_RNW ? 0 : 1), 32)); if (ack != SWD_ACK_OK) { queued_retval = ack == SWD_ACK_WAIT ? ERROR_WAIT : ERROR_FAIL; goto skip; }if (ack != SWD_ACK_OK) { ... } else if (swd_cmd_queue[i].cmd & SWD_CMD_RNW) { uint32_t data = buf_get_u32(swd_cmd_queue[i].trn_ack_data_parity_trn, 1 + 3, 32); int parity = buf_get_u32(swd_cmd_queue[i].trn_ack_data_parity_trn, 1 + 3 + 32, 1); if (parity != parity_u32(data)) { LOG_ERROR("SWD Read data parity mismatch"); queued_retval = ERROR_FAIL; goto skip; }if (parity != parity_u32(data)) { ... } if (swd_cmd_queue[i].dst != NULL) *swd_cmd_queue[i].dst = data; }else if (swd_cmd_queue[i].cmd & SWD_CMD_RNW) { ... } }for (size_t i = 0; i < swd_cmd_queue_length; i++) { ... } skip: /* Defensive cleanup - seems like a bad idea to have potentially stale pointers sticking around */ for (size_t i = 0; i < swd_cmd_queue_length; i++) swd_cmd_queue[i].dst = NULL; swd_cmd_queue_length = 0; retval = queued_retval; queued_retval = ERROR_OK; return retval; }{ ... } static void picoprobe_swd_queue_cmd(uint8_t cmd, uint32_t *dst, uint32_t data, uint32_t ap_delay_clk) { if (swd_cmd_queue_length == swd_cmd_queue_alloced) queued_retval = picoprobe_swd_run_queue(); if (queued_retval != ERROR_OK) return; size_t i = swd_cmd_queue_length++; swd_cmd_queue[i].cmd = cmd | SWD_CMD_START | SWD_CMD_PARK; picoprobe_write_bits(&swd_cmd_queue[i].cmd, 0, 8); if (swd_cmd_queue[i].cmd & SWD_CMD_RNW) { /* Queue a read transaction */ swd_cmd_queue[i].dst = dst; picoprobe_read_bits(swd_cmd_queue[i].trn_ack_data_parity_trn, 0, 1 + 3 + 32 + 1 + 1); }if (swd_cmd_queue[i].cmd & SWD_CMD_RNW) { ... } else { /* Queue a write transaction */ picoprobe_read_bits(swd_cmd_queue[i].trn_ack_data_parity_trn, 0, 1 + 3 + 1); buf_set_u32(swd_cmd_queue[i].trn_ack_data_parity_trn, 1 + 3 + 1, 32, data); buf_set_u32(swd_cmd_queue[i].trn_ack_data_parity_trn, 1 + 3 + 1 + 32, 1, parity_u32(data)); picoprobe_write_bits(swd_cmd_queue[i].trn_ack_data_parity_trn, 1 + 3 + 1, 32 + 1); }else { ... } /* Insert idle cycles after AP accesses to avoid WAIT */ if (cmd & SWD_CMD_APNDP) { if (ap_delay_clk == 0) return; LOG_DEBUG("Add %d idle cycles", ap_delay_clk); picoprobe_write_bits(NULL, 0, ap_delay_clk); }if (cmd & SWD_CMD_APNDP) { ... } }{ ... } static void picoprobe_swd_read_reg(uint8_t cmd, uint32_t *value, uint32_t ap_delay_clk) { assert(cmd & SWD_CMD_RNW); picoprobe_swd_queue_cmd(cmd, value, 0, ap_delay_clk); }{ ... } static void picoprobe_swd_write_reg(uint8_t cmd, uint32_t value, uint32_t ap_delay_clk) { assert(!(cmd & SWD_CMD_RNW)); picoprobe_swd_queue_cmd(cmd, NULL, value, ap_delay_clk); }{ ... } static int_least32_t picoprobe_set_frequency(int_least32_t hz) { int ret; struct probe_pkt_hdr *pkt_hdr = (struct probe_pkt_hdr *)picoprobe_handle->packet_buffer; /* Assert this is a standalone command with nothing else queued */ assert(picoprobe_queue_length == 0); /* Chain writes and read commands together */ uint8_t *pkt = picoprobe_handle->packet_buffer + sizeof(struct probe_pkt_hdr); struct probe_cmd_hdr *hdr = (struct probe_cmd_hdr *)pkt; hdr->id = 0; hdr->cmd = PROBE_SET_FREQ; hdr->bits = hz / 1000; pkt += sizeof(struct probe_cmd_hdr); /* Send all read/write commands + write data */ ret = picoprobe_bulk_write(pkt_hdr, pkt); if (ret < 0) return ERROR_JTAG_DEVICE_ERROR; return hz; }{ ... } static int_least32_t picoprobe_speed(int_least32_t hz) { int ret = picoprobe_set_frequency(hz); if (ret < 0) LOG_ERROR("Couldn't set picoprobe speed"); else picoprobe_handle->freq = ret; return ERROR_OK; }{ ... } static int picoprobe_khz(int khz, int *jtag_speed) { *jtag_speed = khz * 1000; return ERROR_OK; }{ ... } static int picoprobe_speed_div(int speed, int *khz) { *khz = speed / 1000; return ERROR_OK; }{ ... } static int picoprobe_swd_init(void) { return ERROR_OK; }{ ... } static int picoprobe_swd_switch_seq(enum swd_special_seq seq) { int ret = ERROR_OK; switch (seq) { case LINE_RESET: LOG_DEBUG_IO("SWD line reset"); ret = picoprobe_write_bits(swd_seq_line_reset, 0, swd_seq_line_reset_len); break;case LINE_RESET: case JTAG_TO_SWD: LOG_DEBUG("JTAG-to-SWD"); ret = picoprobe_write_bits(swd_seq_jtag_to_swd, 0, swd_seq_jtag_to_swd_len); break;case JTAG_TO_SWD: case SWD_TO_JTAG: LOG_DEBUG("SWD-to-JTAG"); ret = picoprobe_write_bits(swd_seq_swd_to_jtag, 0, swd_seq_swd_to_jtag_len); break;case SWD_TO_JTAG: case DORMANT_TO_SWD: LOG_DEBUG("DORMANT-to-SWD"); ret = picoprobe_write_bits(swd_seq_dormant_to_swd, 0, swd_seq_dormant_to_swd_len); break;case DORMANT_TO_SWD: case SWD_TO_DORMANT: LOG_DEBUG("SWD-to-DORMANT"); ret = picoprobe_write_bits(swd_seq_swd_to_dormant, 0, swd_seq_swd_to_dormant_len); break;case SWD_TO_DORMANT: default: LOG_ERROR("Sequence %d not supported", seq); return ERROR_FAIL;default }switch (seq) { ... } return ret; }{ ... } static int picoprobe_reset(int trst, int srst) { return ERROR_OK; }{ ... } static const struct swd_driver picoprobe_swd = { .init = picoprobe_swd_init, .switch_seq = picoprobe_swd_switch_seq, .read_reg = picoprobe_swd_read_reg, .write_reg = picoprobe_swd_write_reg, .run = picoprobe_swd_run_queue, ...}; static const char * const picoprobe_transports[] = { "swd", NULL }; struct adapter_driver picoprobe_adapter_driver = { .name = "picoprobe", .commands = NULL, .transports = picoprobe_transports, .swd_ops = &picoprobe_swd, .init = picoprobe_init, .quit = picoprobe_quit, .reset = picoprobe_reset, .speed = picoprobe_speed, .speed_div = picoprobe_speed_div, .khz = picoprobe_khz, ...}; static int picoprobe_usb_open(void) { const uint16_t vids[] = { VID, 0 }; const uint16_t pids[] = { PID, 0 }; if (jtag_libusb_open(vids, pids, NULL, &picoprobe_handle->usb_handle, NULL) != ERROR_OK) { LOG_ERROR("Failed to open or find the device"); return ERROR_FAIL; }if (jtag_libusb_open(vids, pids, NULL, &picoprobe_handle->usb_handle, NULL) != ERROR_OK) { ... } if (libusb_claim_interface(picoprobe_handle->usb_handle, PICOPROBE_INTERFACE) != ERROR_OK) { LOG_ERROR("Failed to claim picoprobe interface"); return ERROR_FAIL; }if (libusb_claim_interface(picoprobe_handle->usb_handle, PICOPROBE_INTERFACE) != ERROR_OK) { ... } return ERROR_OK; }{ ... } static void picoprobe_usb_close(void) { jtag_libusb_close(picoprobe_handle->usb_handle); }{ ... } static int picoprobe_init(void) { picoprobe_handle = malloc(sizeof(struct picoprobe)); if (picoprobe_handle == NULL) { LOG_ERROR("Failed to allocate memory"); return ERROR_FAIL; }if (picoprobe_handle == NULL) { ... } if (picoprobe_usb_open() != ERROR_OK) { LOG_ERROR("Can't find a picoprobe device! Please check device connections and permissions."); return ERROR_JTAG_INIT_FAILED; }if (picoprobe_usb_open() != ERROR_OK) { ... } /* Allocate packet buffers and queues */ picoprobe_handle->packet_buffer = malloc(PICOPROBE_MAX_PACKET_LENGTH); if (picoprobe_handle->packet_buffer == NULL) { LOG_ERROR("Failed to allocate memory for the packet buffer"); return ERROR_FAIL; }if (picoprobe_handle->packet_buffer == NULL) { ... } picoprobe_queue_alloced = PICOPROBE_QUEUE_SIZE; picoprobe_queue_length = 0; picoprobe_queue = malloc(picoprobe_queue_alloced * sizeof(*picoprobe_queue)); if (picoprobe_queue == NULL) return ERROR_FAIL; swd_cmd_queue_alloced = 10; swd_cmd_queue = malloc(swd_cmd_queue_alloced * sizeof(*swd_cmd_queue)); return swd_cmd_queue != NULL ? ERROR_OK : ERROR_FAIL; }{ ... } static int picoprobe_quit(void) { picoprobe_usb_close(); return ERROR_OK; }{ ... }
Details
Show:
from
Types: Columns:
Click anywhere in the source to view detailed information here...