flash/stm32l4x: fix scan-build warnings
[openocd.git] / src / flash / nor / at91sam4l.c
1 /***************************************************************************
2 * Copyright (C) 2013 by Andrey Yurovsky *
3 * Andrey Yurovsky <yurovsky@gmail.com> *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
17 ***************************************************************************/
18
19 #ifdef HAVE_CONFIG_H
20 #include "config.h"
21 #endif
22
23 #include "imp.h"
24
25 #include <jtag/jtag.h>
26 #include <target/cortex_m.h>
27
28 /* At this time, the SAM4L Flash is available in these capacities:
29 * ATSAM4Lx4xx: 256KB (512 pages)
30 * ATSAM4Lx2xx: 128KB (256 pages)
31 * ATSAM4Lx8xx: 512KB (1024 pages)
32 */
33
34 /* There are 16 lockable regions regardless of overall capacity. The number
35 * of pages per sector is therefore dependant on capacity. */
36 #define SAM4L_NUM_SECTORS 16
37
38 /* Locations in memory map */
39 #define SAM4L_FLASH ((uint32_t)0x00000000) /* Flash region */
40 #define SAM4L_FLASH_USER 0x00800000 /* Flash user page region */
41 #define SAM4L_FLASHCALW 0x400A0000 /* Flash controller */
42 #define SAM4L_CHIPID 0x400E0740 /* Chip Identification */
43
44 /* Offsets from SAM4L_FLASHCALW */
45 #define SAM4L_FCR 0x00 /* Flash Control Register (RW) */
46 #define SAM4L_FCMD 0x04 /* Flash Command Register (RW) */
47 #define SAM4L_FSR 0x08 /* Flash Status Register (RO) */
48 #define SAM4L_FPR 0x0C /* Flash Parameter Register (RO) */
49 #define SAM4L_FVR 0x10 /* Flash Version Register (RO) */
50 #define SAM4L_FGPFRHI 0x14 /* Flash General Purpose Register High (RO) */
51 #define SAM4L_FGPFRLO 0x18 /* Flash General Purpose Register Low (RO) */
52
53 /* Offsets from SAM4L_CHIPID */
54 #define SAM4L_CIDR 0x00 /* Chip ID Register (RO) */
55 #define SAM4L_EXID 0x04 /* Chip ID Extension Register (RO) */
56
57 /* Flash commands (for SAM4L_FCMD), see Table 14-5 */
58 #define SAM4L_FCMD_NOP 0 /* No Operation */
59 #define SAM4L_FCMD_WP 1 /* Write Page */
60 #define SAM4L_FCMD_EP 2 /* Erase Page */
61 #define SAM4L_FCMD_CPB 3 /* Clear Page Buffer */
62 #define SAM4L_FCMD_LP 4 /* Lock region containing given page */
63 #define SAM4L_FCMD_UP 5 /* Unlock region containing given page */
64 #define SAM4L_FCMD_EA 6 /* Erase All */
65 #define SAM4L_FCMD_WGPB 7 /* Write general-purpose fuse bit */
66 #define SAM4L_FCMD_EGPB 8 /* Erase general-purpose fuse bit */
67 #define SAM4L_FCMD_SSB 9 /* Set security fuses */
68 #define SAM4L_FCMD_PGPFB 10 /* Program general-purpose fuse byte */
69 #define SAM4L_FCMD_EAGPF 11 /* Erase all general-purpose fuse bits */
70 #define SAM4L_FCMD_QPR 12 /* Quick page read */
71 #define SAM4L_FCMD_WUP 13 /* Write user page */
72 #define SAM4L_FCMD_EUP 14 /* Erase user page */
73 #define SAM4L_FCMD_QPRUP 15 /* Quick page read (user page) */
74 #define SAM4L_FCMD_HSEN 16 /* High speed mode enable */
75 #define SAM4L_FCMD_HSDIS 17 /* High speed mode disable */
76
77 #define SAM4L_FMCD_CMDKEY 0xA5UL /* 'key' to issue commands, see 14.10.2 */
78
79
80 /* SMAP registers and bits */
81 #define SMAP_BASE 0x400A3000
82
83 #define SMAP_SCR (SMAP_BASE + 8)
84 #define SMAP_SCR_HCR (1 << 1)
85
86
87 struct sam4l_chip_info {
88 uint32_t id;
89 uint32_t exid;
90 const char *name;
91 };
92
93 /* These are taken from Table 9-1 in 42023E-SAM-07/2013 */
94 static const struct sam4l_chip_info sam4l_known_chips[] = {
95 { 0xAB0B0AE0, 0x1400000F, "ATSAM4LC8C" },
96 { 0xAB0A09E0, 0x0400000F, "ATSAM4LC4C" },
97 { 0xAB0A07E0, 0x0400000F, "ATSAM4LC2C" },
98 { 0xAB0B0AE0, 0x1300000F, "ATSAM4LC8B" },
99 { 0xAB0A09E0, 0x0300000F, "ATSAM4LC4B" },
100 { 0xAB0A07E0, 0x0300000F, "ATSAM4LC2B" },
101 { 0xAB0B0AE0, 0x1200000F, "ATSAM4LC8A" },
102 { 0xAB0A09E0, 0x0200000F, "ATSAM4LC4A" },
103 { 0xAB0A07E0, 0x0200000F, "ATSAM4LC2A" },
104 { 0xAB0B0AE0, 0x14000002, "ATSAM4LS8C" },
105 { 0xAB0A09E0, 0x04000002, "ATSAM4LS4C" },
106 { 0xAB0A07E0, 0x04000002, "ATSAM4LS2C" },
107 { 0xAB0B0AE0, 0x13000002, "ATSAM4LS8B" },
108 { 0xAB0A09E0, 0x03000002, "ATSAM4LS4B" },
109 { 0xAB0A07E0, 0x03000002, "ATSAM4LS2B" },
110 { 0xAB0B0AE0, 0x12000002, "ATSAM4LS8A" },
111 { 0xAB0A09E0, 0x02000002, "ATSAM4LS4A" },
112 { 0xAB0A07E0, 0x02000002, "ATSAM4LS2A" },
113 };
114
115 /* Meaning of SRAMSIZ field in CHIPID, see 9.3.1 in 42023E-SAM-07/2013 */
116 static const uint16_t sam4l_ram_sizes[16] = { 48, 1, 2, 6, 24, 4, 80, 160, 8, 16, 32, 64, 128, 256, 96, 512 };
117
118 /* Meaning of PSZ field in FPR, see 14.10.4 in 42023E-SAM-07/2013 */
119 static const uint16_t sam4l_page_sizes[8] = { 32, 64, 128, 256, 512, 1024, 2048, 4096 };
120
121 struct sam4l_info {
122 const struct sam4l_chip_info *details;
123
124 uint32_t flash_kb;
125 uint32_t ram_kb;
126 uint32_t page_size;
127 int num_pages;
128 int sector_size;
129 unsigned int pages_per_sector;
130
131 bool probed;
132 struct target *target;
133 };
134
135
136 static int sam4l_flash_wait_until_ready(struct target *target)
137 {
138 volatile unsigned int t = 0;
139 uint32_t st;
140 int res;
141
142 /* Poll the status register until the FRDY bit is set */
143 do {
144 res = target_read_u32(target, SAM4L_FLASHCALW + SAM4L_FSR, &st);
145 } while (res == ERROR_OK && !(st & (1<<0)) && ++t < 10);
146
147 return res;
148 }
149
150 static int sam4l_flash_check_error(struct target *target, uint32_t *err)
151 {
152 uint32_t st;
153 int res;
154
155 res = target_read_u32(target, SAM4L_FLASHCALW + SAM4L_FSR, &st);
156
157 if (res == ERROR_OK)
158 *err = st & ((1<<3) | (1<<2)); /* grab PROGE and LOCKE bits */
159
160 return res;
161 }
162
163 static int sam4l_flash_command(struct target *target, uint8_t cmd, int page)
164 {
165 int res;
166 uint32_t fcmd;
167 uint32_t err;
168
169 res = sam4l_flash_wait_until_ready(target);
170 if (res != ERROR_OK)
171 return res;
172
173 if (page >= 0) {
174 /* Set the page number. For some commands, the page number is just an
175 * argument (ex: fuse bit number). */
176 fcmd = (SAM4L_FMCD_CMDKEY << 24) | ((page & 0xFFFF) << 8) | (cmd & 0x3F);
177 } else {
178 /* Reuse the page number that was read from the flash command register. */
179 res = target_read_u32(target, SAM4L_FLASHCALW + SAM4L_FCMD, &fcmd);
180 if (res != ERROR_OK)
181 return res;
182
183 fcmd &= ~0x3F; /* clear out the command code */
184 fcmd |= (SAM4L_FMCD_CMDKEY << 24) | (cmd & 0x3F);
185 }
186
187 /* Send the command */
188 res = target_write_u32(target, SAM4L_FLASHCALW + SAM4L_FCMD, fcmd);
189 if (res != ERROR_OK)
190 return res;
191
192 res = sam4l_flash_check_error(target, &err);
193 if (res != ERROR_OK)
194 return res;
195
196 if (err != 0)
197 LOG_ERROR("%s got error status 0x%08" PRIx32, __func__, err);
198
199 res = sam4l_flash_wait_until_ready(target);
200
201 return res;
202 }
203
204 FLASH_BANK_COMMAND_HANDLER(sam4l_flash_bank_command)
205 {
206 if (bank->base != SAM4L_FLASH) {
207 LOG_ERROR("Address " TARGET_ADDR_FMT
208 " invalid bank address (try 0x%08" PRIx32
209 "[at91sam4l series] )",
210 bank->base, SAM4L_FLASH);
211 return ERROR_FAIL;
212 }
213
214 struct sam4l_info *chip;
215 chip = calloc(1, sizeof(*chip));
216 if (!chip) {
217 LOG_ERROR("No memory for flash bank chip info");
218 return ERROR_FAIL;
219 }
220
221 chip->target = bank->target;
222 chip->probed = false;
223
224 bank->driver_priv = chip;
225
226 return ERROR_OK;
227 }
228
229 static const struct sam4l_chip_info *sam4l_find_chip_name(uint32_t id, uint32_t exid)
230 {
231 unsigned int i;
232
233 id &= ~0xF;
234
235 for (i = 0; i < ARRAY_SIZE(sam4l_known_chips); i++) {
236 if (sam4l_known_chips[i].id == id && sam4l_known_chips[i].exid == exid)
237 return &sam4l_known_chips[i];
238 }
239
240 return NULL;
241 }
242
243 static int sam4l_check_page_erased(struct flash_bank *bank, uint32_t pn,
244 bool *is_erased_p)
245 {
246 int res;
247 uint32_t st;
248
249 /* Issue a quick page read to verify that we've erased this page */
250 res = sam4l_flash_command(bank->target, SAM4L_FCMD_QPR, pn);
251 if (res != ERROR_OK) {
252 LOG_ERROR("Quick page read %" PRIu32 " failed", pn);
253 return res;
254 }
255
256 /* Retrieve the flash status */
257 res = target_read_u32(bank->target, SAM4L_FLASHCALW + SAM4L_FSR, &st);
258 if (res != ERROR_OK) {
259 LOG_ERROR("Couldn't read erase status");
260 return res;
261 }
262
263 /* Is the page in question really erased? */
264 *is_erased_p = !!(st & (1<<5));
265
266 return ERROR_OK;
267 }
268
269 static int sam4l_probe(struct flash_bank *bank)
270 {
271 uint32_t id, exid, param;
272 int res;
273 struct sam4l_info *chip = (struct sam4l_info *)bank->driver_priv;
274
275 if (chip->probed)
276 return ERROR_OK;
277
278 res = target_read_u32(bank->target, SAM4L_CHIPID + SAM4L_CIDR, &id);
279 if (res != ERROR_OK) {
280 LOG_ERROR("Couldn't read chip ID");
281 return res;
282 }
283
284 res = target_read_u32(bank->target, SAM4L_CHIPID + SAM4L_EXID, &exid);
285 if (res != ERROR_OK) {
286 LOG_ERROR("Couldn't read extended chip ID");
287 return res;
288 }
289
290 chip->details = sam4l_find_chip_name(id, exid);
291
292 /* The RAM capacity is in a lookup table. */
293 chip->ram_kb = sam4l_ram_sizes[0xF & (id >> 16)];
294
295 switch (0xF & (id >> 8)) {
296 case 0x07:
297 chip->flash_kb = 128;
298 break;
299 case 0x09:
300 chip->flash_kb = 256;
301 break;
302 case 0x0A:
303 chip->flash_kb = 512;
304 break;
305 default:
306 LOG_ERROR("Unknown flash size (chip ID is %08" PRIx32 "), assuming 128K", id);
307 chip->flash_kb = 128;
308 break;
309 }
310
311 /* Retrieve the Flash parameters */
312 res = target_read_u32(bank->target, SAM4L_FLASHCALW + SAM4L_FPR, &param);
313 if (res != ERROR_OK) {
314 LOG_ERROR("Couldn't read Flash parameters");
315 return res;
316 }
317
318 /* Fetch the page size from the parameter register. Technically the flash
319 * capacity is there too though the manual mentions that not all parts will
320 * have it set so we use the Chip ID capacity information instead. */
321 chip->page_size = sam4l_page_sizes[0x7 & (param >> 8)];
322 assert(chip->page_size);
323 chip->num_pages = chip->flash_kb * 1024 / chip->page_size;
324
325 chip->sector_size = (chip->flash_kb * 1024) / SAM4L_NUM_SECTORS;
326 chip->pages_per_sector = chip->sector_size / chip->page_size;
327
328 /* Make sure the bank size is correct */
329 bank->size = chip->flash_kb * 1024;
330
331 /* Allocate the sector table. */
332 bank->num_sectors = SAM4L_NUM_SECTORS;
333 bank->sectors = calloc(bank->num_sectors, (sizeof((bank->sectors)[0])));
334 if (!bank->sectors)
335 return ERROR_FAIL;
336
337 /* Fill out the sector information: all SAM4L sectors are the same size and
338 * there is always a fixed number of them. */
339 for (unsigned int i = 0; i < bank->num_sectors; i++) {
340 bank->sectors[i].size = chip->sector_size;
341 bank->sectors[i].offset = i * chip->sector_size;
342 /* mark as unknown */
343 bank->sectors[i].is_erased = -1;
344 bank->sectors[i].is_protected = -1;
345 }
346
347 /* Done */
348 chip->probed = true;
349
350 LOG_INFO("SAM4L MCU: %s (Rev %c) (%" PRIu32 "KB Flash with %d %" PRIu32 "B pages, %" PRIu32 "KB RAM)",
351 chip->details ? chip->details->name : "unknown", (char)('A' + (id & 0xF)),
352 chip->flash_kb, chip->num_pages, chip->page_size, chip->ram_kb);
353
354 return ERROR_OK;
355 }
356
357 static int sam4l_protect_check(struct flash_bank *bank)
358 {
359 int res;
360 uint32_t st;
361 struct sam4l_info *chip = (struct sam4l_info *)bank->driver_priv;
362
363 if (bank->target->state != TARGET_HALTED) {
364 LOG_ERROR("Target not halted");
365
366 return ERROR_TARGET_NOT_HALTED;
367 }
368
369 if (!chip->probed) {
370 if (sam4l_probe(bank) != ERROR_OK)
371 return ERROR_FLASH_BANK_NOT_PROBED;
372 }
373
374 res = target_read_u32(bank->target, SAM4L_FLASHCALW + SAM4L_FSR, &st);
375 if (res != ERROR_OK)
376 return res;
377
378 st >>= 16; /* There are 16 lock region bits in the upper half word */
379 for (unsigned int i = 0; i < bank->num_sectors; i++)
380 bank->sectors[i].is_protected = !!(st & (1<<i));
381
382 return ERROR_OK;
383 }
384
385 static int sam4l_protect(struct flash_bank *bank, int set, unsigned int first,
386 unsigned int last)
387 {
388 struct sam4l_info *chip = (struct sam4l_info *)bank->driver_priv;
389
390 if (bank->target->state != TARGET_HALTED) {
391 LOG_ERROR("Target not halted");
392
393 return ERROR_TARGET_NOT_HALTED;
394 }
395
396 if (!chip->probed) {
397 if (sam4l_probe(bank) != ERROR_OK)
398 return ERROR_FLASH_BANK_NOT_PROBED;
399 }
400
401 /* Make sure the pages make sense. */
402 if (first >= bank->num_sectors || last >= bank->num_sectors) {
403 LOG_ERROR("Protect range %u - %u not valid (%u sectors total)", first, last,
404 bank->num_sectors);
405 return ERROR_FAIL;
406 }
407
408 /* Try to lock or unlock each sector in the range. This is done by locking
409 * a region containing one page in that sector, we arbitrarily choose the 0th
410 * page in the sector. */
411 for (unsigned int i = first; i <= last; i++) {
412 int res;
413
414 res = sam4l_flash_command(bank->target,
415 set ? SAM4L_FCMD_LP : SAM4L_FCMD_UP, i * chip->pages_per_sector);
416 if (res != ERROR_OK) {
417 LOG_ERROR("Can't %slock region containing page %d", set ? "" : "un", i);
418 return res;
419 }
420 }
421
422 return ERROR_OK;
423 }
424
425 static int sam4l_erase(struct flash_bank *bank, unsigned int first,
426 unsigned int last)
427 {
428 int ret;
429 struct sam4l_info *chip = (struct sam4l_info *)bank->driver_priv;
430
431 if (bank->target->state != TARGET_HALTED) {
432 LOG_ERROR("Target not halted");
433
434 return ERROR_TARGET_NOT_HALTED;
435 }
436
437 if (!chip->probed) {
438 if (sam4l_probe(bank) != ERROR_OK)
439 return ERROR_FLASH_BANK_NOT_PROBED;
440 }
441
442 /* Make sure the pages make sense. */
443 if (first >= bank->num_sectors || last >= bank->num_sectors) {
444 LOG_ERROR("Erase range %u - %u not valid (%u sectors total)", first, last,
445 bank->num_sectors);
446 return ERROR_FAIL;
447 }
448
449 /* Erase */
450 if ((first == 0) && ((last + 1) == bank->num_sectors)) {
451 LOG_DEBUG("Erasing the whole chip");
452
453 ret = sam4l_flash_command(bank->target, SAM4L_FCMD_EA, -1);
454 if (ret != ERROR_OK) {
455 LOG_ERROR("Erase All failed");
456 return ret;
457 }
458 } else {
459 LOG_DEBUG("Erasing sectors %u through %u...\n", first, last);
460
461 /* For each sector... */
462 for (unsigned int i = first; i <= last; i++) {
463 /* For each page in that sector... */
464 for (unsigned int j = 0; j < chip->pages_per_sector; j++) {
465 unsigned int pn = i * chip->pages_per_sector + j;
466 bool is_erased = false;
467
468 /* Issue the page erase */
469 ret = sam4l_flash_command(bank->target, SAM4L_FCMD_EP, pn);
470 if (ret != ERROR_OK) {
471 LOG_ERROR("Erasing page %u failed", pn);
472 return ret;
473 }
474
475 ret = sam4l_check_page_erased(bank, pn, &is_erased);
476 if (ret != ERROR_OK)
477 return ret;
478
479 if (!is_erased) {
480 LOG_DEBUG("Page %u was not erased.", pn);
481 return ERROR_FAIL;
482 }
483 }
484 }
485 }
486
487 return ERROR_OK;
488 }
489
490 /* Write an entire page from host buffer 'buf' to page-aligned 'address' in the
491 * Flash. */
492 static int sam4l_write_page(struct sam4l_info *chip, struct target *target,
493 uint32_t address, const uint8_t *buf)
494 {
495 int res;
496
497 LOG_DEBUG("sam4l_write_page address=%08" PRIx32, address);
498
499 /* Clear the page buffer before we write to it */
500 res = sam4l_flash_command(target, SAM4L_FCMD_CPB, -1);
501 if (res != ERROR_OK) {
502 LOG_ERROR("%s: can't clear page buffer", __func__);
503 return res;
504 }
505
506 /* Write the modified page back to the target's page buffer */
507 res = target_write_memory(target, address, 4, chip->page_size / 4, buf);
508
509 if (res != ERROR_OK) {
510 LOG_ERROR("%s: %d", __func__, __LINE__);
511 return res;
512 }
513
514 /* Commit the page contents to Flash: erase the current page and then
515 * write it out. */
516 res = sam4l_flash_command(target, SAM4L_FCMD_EP, -1);
517 if (res != ERROR_OK)
518 return res;
519 res = sam4l_flash_command(target, SAM4L_FCMD_WP, -1);
520
521 return res;
522 }
523
524 /* Write partial contents into page-aligned 'address' on the Flash from host
525 * buffer 'buf' by writing 'nb' of 'buf' at 'offset' into the Flash page. */
526 static int sam4l_write_page_partial(struct sam4l_info *chip,
527 struct flash_bank *bank, uint32_t address, const uint8_t *buf,
528 uint32_t page_offset, uint32_t nb)
529 {
530 int res;
531 uint8_t *pg = malloc(chip->page_size);
532 if (!pg)
533 return ERROR_FAIL;
534
535 LOG_DEBUG("sam4l_write_page_partial address=%08" PRIx32 " nb=%08" PRIx32, address, nb);
536
537 assert(page_offset + nb < chip->page_size);
538 assert((address % chip->page_size) == 0);
539
540 /* Retrieve the full page contents from Flash */
541 res = target_read_memory(bank->target, address, 4,
542 chip->page_size / 4, pg);
543 if (res != ERROR_OK) {
544 free(pg);
545 return res;
546 }
547
548 /* Insert our partial page over the data from Flash */
549 memcpy(pg + (page_offset % chip->page_size), buf, nb);
550
551 /* Write the page back out */
552 res = sam4l_write_page(chip, bank->target, address, pg);
553 free(pg);
554
555 return res;
556 }
557
558 static int sam4l_write(struct flash_bank *bank, const uint8_t *buffer,
559 uint32_t offset, uint32_t count)
560 {
561 int res;
562 uint32_t nb = 0;
563 struct sam4l_info *chip = (struct sam4l_info *)bank->driver_priv;
564
565 LOG_DEBUG("sam4l_write offset=%08" PRIx32 " count=%08" PRIx32, offset, count);
566
567 if (bank->target->state != TARGET_HALTED) {
568 LOG_ERROR("Target not halted");
569
570 return ERROR_TARGET_NOT_HALTED;
571 }
572
573 if (!chip->probed) {
574 if (sam4l_probe(bank) != ERROR_OK)
575 return ERROR_FLASH_BANK_NOT_PROBED;
576 }
577
578 if (offset % chip->page_size) {
579 /* We're starting at an unaligned offset so we'll write a partial page
580 * comprising that offset and up to the end of that page. */
581 nb = chip->page_size - (offset % chip->page_size);
582 if (nb > count)
583 nb = count;
584 } else if (count < chip->page_size) {
585 /* We're writing an aligned but partial page. */
586 nb = count;
587 }
588
589 if (nb > 0) {
590 res = sam4l_write_page_partial(chip, bank,
591 (offset / chip->page_size) * chip->page_size + bank->base,
592 buffer,
593 offset % chip->page_size, nb);
594 if (res != ERROR_OK)
595 return res;
596
597 /* We're done with the page contents */
598 count -= nb;
599 offset += nb;
600 }
601
602 /* There's at least one aligned page to write out. */
603 if (count >= chip->page_size) {
604 assert(chip->page_size > 0);
605 int np = count / chip->page_size + ((count % chip->page_size) ? 1 : 0);
606
607 for (int i = 0; i < np; i++) {
608 if (count >= chip->page_size) {
609 res = sam4l_write_page(chip, bank->target,
610 bank->base + offset,
611 buffer + (i * chip->page_size));
612 /* Advance one page */
613 offset += chip->page_size;
614 count -= chip->page_size;
615 } else {
616 res = sam4l_write_page_partial(chip, bank,
617 bank->base + offset,
618 buffer + (i * chip->page_size), 0, count);
619 /* We're done after this. */
620 offset += count;
621 count = 0;
622 }
623
624 if (res != ERROR_OK)
625 return res;
626 }
627 }
628
629 return ERROR_OK;
630 }
631
632
633 COMMAND_HANDLER(sam4l_handle_reset_deassert)
634 {
635 struct target *target = get_current_target(CMD_CTX);
636 int retval = ERROR_OK;
637 enum reset_types jtag_reset_config = jtag_get_reset_config();
638
639 /* If the target has been unresponsive before, try to re-establish
640 * communication now - CPU is held in reset by DSU, DAP is working */
641 if (!target_was_examined(target))
642 target_examine_one(target);
643 target_poll(target);
644
645 /* In case of sysresetreq, debug retains state set in cortex_m_assert_reset()
646 * so we just release reset held by SMAP
647 *
648 * n_RESET (srst) clears the DP, so reenable debug and set vector catch here
649 *
650 * After vectreset SMAP release is not needed however makes no harm
651 */
652 if (target->reset_halt && (jtag_reset_config & RESET_HAS_SRST)) {
653 retval = target_write_u32(target, DCB_DHCSR, DBGKEY | C_HALT | C_DEBUGEN);
654 if (retval == ERROR_OK)
655 retval = target_write_u32(target, DCB_DEMCR,
656 TRCENA | VC_HARDERR | VC_BUSERR | VC_CORERESET);
657 /* do not return on error here, releasing SMAP reset is more important */
658 }
659
660 int retval2 = target_write_u32(target, SMAP_SCR, SMAP_SCR_HCR);
661 if (retval2 != ERROR_OK)
662 return retval2;
663
664 return retval;
665 }
666
667 static const struct command_registration at91sam4l_exec_command_handlers[] = {
668 {
669 .name = "smap_reset_deassert",
670 .handler = sam4l_handle_reset_deassert,
671 .mode = COMMAND_EXEC,
672 .help = "deassert internal reset held by SMAP",
673 .usage = "",
674 },
675 COMMAND_REGISTRATION_DONE
676 };
677
678 static const struct command_registration at91sam4l_command_handlers[] = {
679 {
680 .name = "at91sam4l",
681 .mode = COMMAND_ANY,
682 .help = "at91sam4l flash command group",
683 .usage = "",
684 .chain = at91sam4l_exec_command_handlers,
685 },
686 COMMAND_REGISTRATION_DONE
687 };
688
689 const struct flash_driver at91sam4l_flash = {
690 .name = "at91sam4l",
691 .commands = at91sam4l_command_handlers,
692 .flash_bank_command = sam4l_flash_bank_command,
693 .erase = sam4l_erase,
694 .protect = sam4l_protect,
695 .write = sam4l_write,
696 .read = default_flash_read,
697 .probe = sam4l_probe,
698 .auto_probe = sam4l_probe,
699 .erase_check = default_flash_blank_check,
700 .protect_check = sam4l_protect_check,
701 .free_driver_priv = default_flash_free_driver_priv,
702 };

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)