23 #define REG_NAME_WIDTH (12)
26 #define FLASH_BANK0_BASE_U 0x00080000
27 #define FLASH_BANK1_BASE_U 0x00100000
30 #define FLASH_BANK_BASE_S 0x00400000
33 #define FLASH_BANK0_BASE_SD FLASH_BANK_BASE_S
34 #define FLASH_BANK1_BASE_512K_SD (FLASH_BANK0_BASE_SD+(512*1024/2))
38 #define FLASH_BANK_BASE_N 0x00400000
41 #define FLASH_BANK0_BASE_AX 0x00080000
43 #define FLASH_BANK1_BASE_256K_AX 0x000A0000
44 #define FLASH_BANK1_BASE_512K_AX 0x000C0000
46 #define AT91C_EFC_FCMD_GETD (0x0)
47 #define AT91C_EFC_FCMD_WP (0x1)
48 #define AT91C_EFC_FCMD_WPL (0x2)
49 #define AT91C_EFC_FCMD_EWP (0x3)
50 #define AT91C_EFC_FCMD_EWPL (0x4)
51 #define AT91C_EFC_FCMD_EA (0x5)
56 #define AT91C_EFC_FCMD_SLB (0x8)
57 #define AT91C_EFC_FCMD_CLB (0x9)
58 #define AT91C_EFC_FCMD_GLB (0xA)
59 #define AT91C_EFC_FCMD_SFB (0xB)
60 #define AT91C_EFC_FCMD_CFB (0xC)
61 #define AT91C_EFC_FCMD_GFB (0xD)
62 #define AT91C_EFC_FCMD_STUI (0xE)
63 #define AT91C_EFC_FCMD_SPUI (0xF)
65 #define OFFSET_EFC_FMR 0
66 #define OFFSET_EFC_FCR 4
67 #define OFFSET_EFC_FSR 8
68 #define OFFSET_EFC_FRR 12
72 static float _tomhz(uint32_t freq_hz)
76 f = ((float)(freq_hz)) / 1000000.0;
96 #define SAM3_CHIPID_CIDR (0x400E0740)
98 #define SAM3_CHIPID_CIDR2 (0x400E0940)
100 #define SAM3_CHIPID_EXID (0x400E0744)
102 #define SAM3_CHIPID_EXID2 (0x400E0944)
106 #define SAM3_PMC_BASE (0x400E0400)
107 #define SAM3_PMC_SCSR (SAM3_PMC_BASE + 0x0008)
109 #define SAM3_PMC_PCSR (SAM3_PMC_BASE + 0x0018)
111 #define SAM3_CKGR_UCKR (SAM3_PMC_BASE + 0x001c)
113 #define SAM3_CKGR_MOR (SAM3_PMC_BASE + 0x0020)
115 #define SAM3_CKGR_MCFR (SAM3_PMC_BASE + 0x0024)
117 #define SAM3_CKGR_PLLAR (SAM3_PMC_BASE + 0x0028)
119 #define SAM3_PMC_MCKR (SAM3_PMC_BASE + 0x0030)
121 #define SAM3_PMC_PCK0 (SAM3_PMC_BASE + 0x0040)
123 #define SAM3_PMC_PCK1 (SAM3_PMC_BASE + 0x0044)
125 #define SAM3_PMC_PCK2 (SAM3_PMC_BASE + 0x0048)
127 #define SAM3_PMC_SR (SAM3_PMC_BASE + 0x0068)
129 #define SAM3_PMC_IMR (SAM3_PMC_BASE + 0x006c)
131 #define SAM3_PMC_FSMR (SAM3_PMC_BASE + 0x0070)
133 #define SAM3_PMC_FSPR (SAM3_PMC_BASE + 0x0074)
182 #define SAM3_N_NVM_BITS 3
187 #define SAM3_MAX_FLASH_BANKS 2
243 .name =
"at91sam3u4e",
244 .total_flash_size = 256 * 1024,
245 .total_sram_size = 52 * 1024,
272 .controller_address = 0x400e0800,
273 .flash_wait_states = 6,
275 .size_bytes = 128 * 1024,
288 .controller_address = 0x400e0a00,
289 .flash_wait_states = 6,
291 .size_bytes = 128 * 1024,
300 .chipid_cidr = 0x281a0760,
301 .name =
"at91sam3u2e",
302 .total_flash_size = 128 * 1024,
303 .total_sram_size = 36 * 1024,
323 .controller_address = 0x400e0800,
324 .flash_wait_states = 6,
326 .size_bytes = 128 * 1024,
340 .chipid_cidr = 0x28190560,
341 .name =
"at91sam3u1e",
342 .total_flash_size = 64 * 1024,
343 .total_sram_size = 20 * 1024,
365 .controller_address = 0x400e0800,
366 .flash_wait_states = 6,
368 .size_bytes = 64 * 1024,
384 .chipid_cidr = 0x28000960,
385 .name =
"at91sam3u4c",
386 .total_flash_size = 256 * 1024,
387 .total_sram_size = 52 * 1024,
414 .controller_address = 0x400e0800,
415 .flash_wait_states = 6,
417 .size_bytes = 128 * 1024,
429 .controller_address = 0x400e0a00,
430 .flash_wait_states = 6,
432 .size_bytes = 128 * 1024,
441 .chipid_cidr = 0x280a0760,
442 .name =
"at91sam3u2c",
443 .total_flash_size = 128 * 1024,
444 .total_sram_size = 36 * 1024,
464 .controller_address = 0x400e0800,
465 .flash_wait_states = 6,
467 .size_bytes = 128 * 1024,
481 .chipid_cidr = 0x28090560,
482 .name =
"at91sam3u1c",
483 .total_flash_size = 64 * 1024,
484 .total_sram_size = 20 * 1024,
506 .controller_address = 0x400e0800,
507 .flash_wait_states = 6,
509 .size_bytes = 64 * 1024,
530 .chipid_cidr = 0x28A00960,
531 .name =
"at91sam3s4c",
532 .total_flash_size = 256 * 1024,
533 .total_sram_size = 48 * 1024,
544 .controller_address = 0x400e0a00,
545 .flash_wait_states = 6,
547 .size_bytes = 256 * 1024,
549 .sector_size = 16384,
563 .chipid_cidr = 0x28900960,
564 .name =
"at91sam3s4b",
565 .total_flash_size = 256 * 1024,
566 .total_sram_size = 48 * 1024,
577 .controller_address = 0x400e0a00,
578 .flash_wait_states = 6,
580 .size_bytes = 256 * 1024,
582 .sector_size = 16384,
595 .chipid_cidr = 0x28800960,
596 .name =
"at91sam3s4a",
597 .total_flash_size = 256 * 1024,
598 .total_sram_size = 48 * 1024,
609 .controller_address = 0x400e0a00,
610 .flash_wait_states = 6,
612 .size_bytes = 256 * 1024,
614 .sector_size = 16384,
627 .chipid_cidr = 0x28AA0760,
628 .name =
"at91sam3s2c",
629 .total_flash_size = 128 * 1024,
630 .total_sram_size = 32 * 1024,
641 .controller_address = 0x400e0a00,
642 .flash_wait_states = 6,
644 .size_bytes = 128 * 1024,
646 .sector_size = 16384,
659 .chipid_cidr = 0x289A0760,
660 .name =
"at91sam3s2b",
661 .total_flash_size = 128 * 1024,
662 .total_sram_size = 32 * 1024,
673 .controller_address = 0x400e0a00,
674 .flash_wait_states = 6,
676 .size_bytes = 128 * 1024,
678 .sector_size = 16384,
691 .chipid_cidr = 0x298B0A60,
692 .name =
"at91sam3sd8a",
693 .total_flash_size = 512 * 1024,
694 .total_sram_size = 64 * 1024,
705 .controller_address = 0x400e0a00,
706 .flash_wait_states = 6,
708 .size_bytes = 256 * 1024,
710 .sector_size = 32768,
720 .controller_address = 0x400e0a00,
721 .flash_wait_states = 6,
723 .size_bytes = 256 * 1024,
725 .sector_size = 32768,
731 .chipid_cidr = 0x299B0A60,
732 .name =
"at91sam3sd8b",
733 .total_flash_size = 512 * 1024,
734 .total_sram_size = 64 * 1024,
745 .controller_address = 0x400e0a00,
746 .flash_wait_states = 6,
748 .size_bytes = 256 * 1024,
750 .sector_size = 32768,
760 .controller_address = 0x400e0a00,
761 .flash_wait_states = 6,
763 .size_bytes = 256 * 1024,
765 .sector_size = 32768,
771 .chipid_cidr = 0x29ab0a60,
772 .name =
"at91sam3sd8c",
773 .total_flash_size = 512 * 1024,
774 .total_sram_size = 64 * 1024,
785 .controller_address = 0x400e0a00,
786 .flash_wait_states = 6,
788 .size_bytes = 256 * 1024,
790 .sector_size = 32768,
800 .controller_address = 0x400e0a00,
801 .flash_wait_states = 6,
803 .size_bytes = 256 * 1024,
805 .sector_size = 32768,
811 .chipid_cidr = 0x288A0760,
812 .name =
"at91sam3s2a",
813 .total_flash_size = 128 * 1024,
814 .total_sram_size = 32 * 1024,
825 .controller_address = 0x400e0a00,
826 .flash_wait_states = 6,
828 .size_bytes = 128 * 1024,
830 .sector_size = 16384,
843 .chipid_cidr = 0x28A90560,
844 .name =
"at91sam3s1c",
845 .total_flash_size = 64 * 1024,
846 .total_sram_size = 16 * 1024,
857 .controller_address = 0x400e0a00,
858 .flash_wait_states = 6,
860 .size_bytes = 64 * 1024,
862 .sector_size = 16384,
875 .chipid_cidr = 0x28990560,
876 .name =
"at91sam3s1b",
877 .total_flash_size = 64 * 1024,
878 .total_sram_size = 16 * 1024,
889 .controller_address = 0x400e0a00,
890 .flash_wait_states = 6,
892 .size_bytes = 64 * 1024,
894 .sector_size = 16384,
907 .chipid_cidr = 0x28890560,
908 .name =
"at91sam3s1a",
909 .total_flash_size = 64 * 1024,
910 .total_sram_size = 16 * 1024,
921 .controller_address = 0x400e0a00,
922 .flash_wait_states = 6,
924 .size_bytes = 64 * 1024,
926 .sector_size = 16384,
939 .chipid_cidr = 0x288B0A60,
940 .name =
"at91sam3s8a",
941 .total_flash_size = 256 * 2048,
942 .total_sram_size = 64 * 1024,
953 .controller_address = 0x400e0a00,
954 .flash_wait_states = 6,
956 .size_bytes = 256 * 2048,
958 .sector_size = 32768,
971 .chipid_cidr = 0x289B0A60,
972 .name =
"at91sam3s8b",
973 .total_flash_size = 256 * 2048,
974 .total_sram_size = 64 * 1024,
985 .controller_address = 0x400e0a00,
986 .flash_wait_states = 6,
988 .size_bytes = 256 * 2048,
990 .sector_size = 32768,
1003 .chipid_cidr = 0x28AB0A60,
1004 .name =
"at91sam3s8c",
1005 .total_flash_size = 256 * 2048,
1006 .total_sram_size = 64 * 1024,
1017 .controller_address = 0x400e0a00,
1018 .flash_wait_states = 6,
1020 .size_bytes = 256 * 2048,
1022 .sector_size = 32768,
1037 .chipid_cidr = 0x29540960,
1038 .name =
"at91sam3n4c",
1039 .total_flash_size = 256 * 1024,
1040 .total_sram_size = 24 * 1024,
1067 .controller_address = 0x400e0A00,
1068 .flash_wait_states = 6,
1070 .size_bytes = 256 * 1024,
1072 .sector_size = 16384,
1086 .chipid_cidr = 0x29440960,
1087 .name =
"at91sam3n4b",
1088 .total_flash_size = 256 * 1024,
1089 .total_sram_size = 24 * 1024,
1116 .controller_address = 0x400e0A00,
1117 .flash_wait_states = 6,
1119 .size_bytes = 256 * 1024,
1121 .sector_size = 16384,
1135 .chipid_cidr = 0x29340960,
1136 .name =
"at91sam3n4a",
1137 .total_flash_size = 256 * 1024,
1138 .total_sram_size = 24 * 1024,
1165 .controller_address = 0x400e0A00,
1166 .flash_wait_states = 6,
1168 .size_bytes = 256 * 1024,
1170 .sector_size = 16384,
1184 .chipid_cidr = 0x29590760,
1185 .name =
"at91sam3n2c",
1186 .total_flash_size = 128 * 1024,
1187 .total_sram_size = 16 * 1024,
1214 .controller_address = 0x400e0A00,
1215 .flash_wait_states = 6,
1217 .size_bytes = 128 * 1024,
1219 .sector_size = 16384,
1233 .chipid_cidr = 0x29490760,
1234 .name =
"at91sam3n2b",
1235 .total_flash_size = 128 * 1024,
1236 .total_sram_size = 16 * 1024,
1263 .controller_address = 0x400e0A00,
1264 .flash_wait_states = 6,
1266 .size_bytes = 128 * 1024,
1268 .sector_size = 16384,
1282 .chipid_cidr = 0x29390760,
1283 .name =
"at91sam3n2a",
1284 .total_flash_size = 128 * 1024,
1285 .total_sram_size = 16 * 1024,
1312 .controller_address = 0x400e0A00,
1313 .flash_wait_states = 6,
1315 .size_bytes = 128 * 1024,
1317 .sector_size = 16384,
1331 .chipid_cidr = 0x29580560,
1332 .name =
"at91sam3n1c",
1333 .total_flash_size = 64 * 1024,
1334 .total_sram_size = 8 * 1024,
1361 .controller_address = 0x400e0A00,
1362 .flash_wait_states = 6,
1364 .size_bytes = 64 * 1024,
1366 .sector_size = 16384,
1380 .chipid_cidr = 0x29480560,
1381 .name =
"at91sam3n1b",
1382 .total_flash_size = 64 * 1024,
1383 .total_sram_size = 8 * 1024,
1410 .controller_address = 0x400e0A00,
1411 .flash_wait_states = 6,
1413 .size_bytes = 64 * 1024,
1415 .sector_size = 16384,
1429 .chipid_cidr = 0x29380560,
1430 .name =
"at91sam3n1a",
1431 .total_flash_size = 64 * 1024,
1432 .total_sram_size = 8 * 1024,
1459 .controller_address = 0x400e0A00,
1460 .flash_wait_states = 6,
1462 .size_bytes = 64 * 1024,
1464 .sector_size = 16384,
1478 .chipid_cidr = 0x29480360,
1479 .name =
"at91sam3n0b",
1480 .total_flash_size = 32 * 1024,
1481 .total_sram_size = 8 * 1024,
1493 .controller_address = 0x400e0A00,
1494 .flash_wait_states = 6,
1496 .size_bytes = 32 * 1024,
1498 .sector_size = 16384,
1512 .chipid_cidr = 0x29380360,
1513 .name =
"at91sam3n0a",
1514 .total_flash_size = 32 * 1024,
1515 .total_sram_size = 8 * 1024,
1527 .controller_address = 0x400e0A00,
1528 .flash_wait_states = 6,
1530 .size_bytes = 32 * 1024,
1532 .sector_size = 16384,
1546 .chipid_cidr = 0x29450260,
1547 .name =
"at91sam3n00b",
1548 .total_flash_size = 16 * 1024,
1549 .total_sram_size = 4 * 1024,
1561 .controller_address = 0x400e0A00,
1562 .flash_wait_states = 6,
1564 .size_bytes = 16 * 1024,
1566 .sector_size = 16384,
1580 .chipid_cidr = 0x29350260,
1581 .name =
"at91sam3n00a",
1582 .total_flash_size = 16 * 1024,
1583 .total_sram_size = 4 * 1024,
1595 .controller_address = 0x400e0A00,
1596 .flash_wait_states = 6,
1598 .size_bytes = 16 * 1024,
1600 .sector_size = 16384,
1632 .chipid_cidr = 0x283E0A60,
1633 .name =
"at91sam3a8c",
1634 .total_flash_size = 512 * 1024,
1635 .total_sram_size = 96 * 1024,
1646 .controller_address = 0x400e0a00,
1647 .flash_wait_states = 6,
1649 .size_bytes = 256 * 1024,
1651 .sector_size = 16384,
1661 .controller_address = 0x400e0c00,
1662 .flash_wait_states = 6,
1664 .size_bytes = 256 * 1024,
1666 .sector_size = 16384,
1673 .chipid_cidr = 0x283B0960,
1674 .name =
"at91sam3a4c",
1675 .total_flash_size = 256 * 1024,
1676 .total_sram_size = 64 * 1024,
1687 .controller_address = 0x400e0a00,
1688 .flash_wait_states = 6,
1690 .size_bytes = 128 * 1024,
1692 .sector_size = 16384,
1702 .controller_address = 0x400e0c00,
1703 .flash_wait_states = 6,
1705 .size_bytes = 128 * 1024,
1707 .sector_size = 16384,
1732 .chipid_cidr = 0x286E0A20,
1733 .name =
"at91sam3x8h - ES",
1734 .total_flash_size = 512 * 1024,
1735 .total_sram_size = 96 * 1024,
1746 .controller_address = 0x400e0a00,
1747 .flash_wait_states = 6,
1749 .size_bytes = 256 * 1024,
1751 .sector_size = 16384,
1761 .controller_address = 0x400e0c00,
1762 .flash_wait_states = 6,
1764 .size_bytes = 256 * 1024,
1766 .sector_size = 16384,
1774 .chipid_cidr = 0x286E0A60,
1775 .name =
"at91sam3x8h",
1776 .total_flash_size = 512 * 1024,
1777 .total_sram_size = 96 * 1024,
1788 .controller_address = 0x400e0a00,
1789 .flash_wait_states = 6,
1791 .size_bytes = 256 * 1024,
1793 .sector_size = 16384,
1803 .controller_address = 0x400e0c00,
1804 .flash_wait_states = 6,
1806 .size_bytes = 256 * 1024,
1808 .sector_size = 16384,
1815 .chipid_cidr = 0x285E0A60,
1816 .name =
"at91sam3x8e",
1817 .total_flash_size = 512 * 1024,
1818 .total_sram_size = 96 * 1024,
1829 .controller_address = 0x400e0a00,
1830 .flash_wait_states = 6,
1832 .size_bytes = 256 * 1024,
1834 .sector_size = 16384,
1844 .controller_address = 0x400e0c00,
1845 .flash_wait_states = 6,
1847 .size_bytes = 256 * 1024,
1849 .sector_size = 16384,
1856 .chipid_cidr = 0x284E0A60,
1857 .name =
"at91sam3x8c",
1858 .total_flash_size = 512 * 1024,
1859 .total_sram_size = 96 * 1024,
1870 .controller_address = 0x400e0a00,
1871 .flash_wait_states = 6,
1873 .size_bytes = 256 * 1024,
1875 .sector_size = 16384,
1885 .controller_address = 0x400e0c00,
1886 .flash_wait_states = 6,
1888 .size_bytes = 256 * 1024,
1890 .sector_size = 16384,
1897 .chipid_cidr = 0x285B0960,
1898 .name =
"at91sam3x4e",
1899 .total_flash_size = 256 * 1024,
1900 .total_sram_size = 64 * 1024,
1911 .controller_address = 0x400e0a00,
1912 .flash_wait_states = 6,
1914 .size_bytes = 128 * 1024,
1916 .sector_size = 16384,
1926 .controller_address = 0x400e0c00,
1927 .flash_wait_states = 6,
1929 .size_bytes = 128 * 1024,
1931 .sector_size = 16384,
1938 .chipid_cidr = 0x284B0960,
1939 .name =
"at91sam3x4c",
1940 .total_flash_size = 256 * 1024,
1941 .total_sram_size = 64 * 1024,
1952 .controller_address = 0x400e0a00,
1953 .flash_wait_states = 6,
1955 .size_bytes = 128 * 1024,
1957 .sector_size = 16384,
1967 .controller_address = 0x400e0c00,
1968 .flash_wait_states = 6,
1970 .size_bytes = 128 * 1024,
1972 .sector_size = 16384,
2006 LOG_DEBUG(
"Status: 0x%08x (lockerror: %d, cmderror: %d, ready: %d)",
2008 ((
unsigned int)((*v >> 2) & 1)),
2009 ((
unsigned int)((*v >> 1) & 1)),
2010 ((
unsigned int)((*v >> 0) & 1)));
2029 LOG_DEBUG(
"Result: 0x%08x", ((
unsigned int)(rv)));
2034 unsigned command,
unsigned argument)
2054 n = (
private->size_bytes /
private->page_size);
2056 LOG_ERROR(
"*BUG*: Embedded flash has only %u pages", (
unsigned)(n));
2061 if (argument >= private->chip->details.n_gpnvms) {
2062 LOG_ERROR(
"*BUG*: Embedded flash has only %d GPNVMs",
2063 private->chip->details.n_gpnvms);
2096 LOG_ERROR(
"flash controller(%d) is not ready! Error",
2097 private->bank_number);
2101 LOG_ERROR(
"Flash controller(%d) is not ready, attempting reset",
2102 private->bank_number);
2112 v = (0x5A << 24) | (argument << 8) |
command;
2113 LOG_DEBUG(
"Command: 0x%08x", ((
unsigned int)(v)));
2136 int64_t ms_now, ms_end;
2153 if (ms_now > ms_end) {
2158 }
while ((v & 1) == 0);
2178 private->chip->cfg.unique_id[0] = 0;
2179 private->chip->cfg.unique_id[1] = 0;
2180 private->chip->cfg.unique_id[2] = 0;
2181 private->chip->cfg.unique_id[3] = 0;
2188 for (x = 0; x < 4; x++) {
2190 private->bank->base + (x * 4),
2194 private->chip->cfg.unique_id[x] = v;
2198 LOG_DEBUG(
"End: R=%d, id = 0x%08x, 0x%08x, 0x%08x, 0x%08x",
2200 (
unsigned int)(private->chip->cfg.unique_id[0]),
2201 (
unsigned int)(private->chip->cfg.unique_id[1]),
2202 (
unsigned int)(private->chip->cfg.unique_id[2]),
2203 (
unsigned int)(private->chip->cfg.unique_id[3]));
2231 if (private->bank_number != 0) {
2232 LOG_ERROR(
"GPNVM only works with Bank0");
2236 if (
gpnvm >= private->chip->details.n_gpnvms) {
2237 LOG_ERROR(
"Invalid GPNVM %d, max: %d, ignored",
2238 gpnvm, private->chip->details.n_gpnvms);
2254 *puthere = (v >>
gpnvm) & 1;
2272 if (private->bank_number != 0) {
2273 LOG_ERROR(
"GPNVM only works with Bank0");
2277 if (
gpnvm >= private->chip->details.n_gpnvms) {
2278 LOG_ERROR(
"Invalid GPNVM %d, max: %d, ignored",
2279 gpnvm, private->chip->details.n_gpnvms);
2303 if (private->bank_number != 0) {
2304 LOG_ERROR(
"GPNVM only works with Bank0");
2308 if (
gpnvm >= private->chip->details.n_gpnvms) {
2309 LOG_ERROR(
"Invalid GPNVM %d, max: %d, ignored",
2310 gpnvm, private->chip->details.n_gpnvms);
2351 unsigned start_sector,
2352 unsigned end_sector)
2357 uint32_t pages_per_sector;
2359 pages_per_sector =
private->sector_size /
private->page_size;
2362 while (start_sector <= end_sector) {
2363 pg = start_sector * pages_per_sector;
2381 unsigned start_sector,
2382 unsigned end_sector)
2386 uint32_t pages_per_sector;
2389 pages_per_sector =
private->sector_size /
private->page_size;
2392 while (start_sector <= end_sector) {
2393 pg = start_sector * pages_per_sector;
2408 const char *regname,
2419 v = v & ((1 <<
width)-1);
2429 LOG_USER_N(
"\t%*s: %*" PRIu32
" [0x%0*" PRIx32
"] ",
2456 #define nvpsize2 nvpsize
2497 { 0x19,
"AT91SAM9xx Series" },
2498 { 0x29,
"AT91SAM9XExx Series" },
2499 { 0x34,
"AT91x34 Series" },
2500 { 0x37,
"CAP7 Series" },
2501 { 0x39,
"CAP9 Series" },
2502 { 0x3B,
"CAP11 Series" },
2503 { 0x40,
"AT91x40 Series" },
2504 { 0x42,
"AT91x42 Series" },
2505 { 0x55,
"AT91x55 Series" },
2506 { 0x60,
"AT91SAM7Axx Series" },
2507 { 0x61,
"AT91SAM7AQxx Series" },
2508 { 0x63,
"AT91x63 Series" },
2509 { 0x70,
"AT91SAM7Sxx Series" },
2510 { 0x71,
"AT91SAM7XCxx Series" },
2511 { 0x72,
"AT91SAM7SExx Series" },
2512 { 0x73,
"AT91SAM7Lxx Series" },
2513 { 0x75,
"AT91SAM7Xxx Series" },
2514 { 0x76,
"AT91SAM7SLxx Series" },
2515 { 0x80,
"ATSAM3UxC Series (100-pin version)" },
2516 { 0x81,
"ATSAM3UxE Series (144-pin version)" },
2517 { 0x83,
"ATSAM3AxC Series (100-pin version)" },
2518 { 0x84,
"ATSAM3XxC Series (100-pin version)" },
2519 { 0x85,
"ATSAM3XxE Series (144-pin version)" },
2520 { 0x86,
"ATSAM3XxG Series (208/217-pin version)" },
2521 { 0x88,
"ATSAM3SxA Series (48-pin version)" },
2522 { 0x89,
"ATSAM3SxB Series (64-pin version)" },
2523 { 0x8A,
"ATSAM3SxC Series (100-pin version)" },
2524 { 0x92,
"AT91x92 Series" },
2525 { 0x93,
"ATSAM3NxA Series (48-pin version)" },
2526 { 0x94,
"ATSAM3NxB Series (64-pin version)" },
2527 { 0x95,
"ATSAM3NxC Series (100-pin version)" },
2528 { 0x98,
"ATSAM3SDxA Series (48-pin version)" },
2529 { 0x99,
"ATSAM3SDxB Series (64-pin version)" },
2530 { 0x9A,
"ATSAM3SDxC Series (100-pin version)" },
2531 { 0xA5,
"ATSAM5A" },
2532 { 0xF0,
"AT75Cxx Series" },
2538 "romless or onchip flash",
2539 "embedded flash memory",
2540 "rom(nvpsiz) + embedded flash (nvpsiz2)",
2541 "sram emulating flash",
2556 "4 MHz",
"8 MHz",
"12 MHz",
"reserved"
2592 LOG_USER(
"(startup clks, time= %f uSecs)",
2593 ((
float)(v * 1000000)) / ((
float)(chip->
cfg.
slow_freq)));
2596 v ?
"external xtal" :
"internal RC");
2599 LOG_USER(
"(clock failure enabled: %s)",
2654 LOG_USER(
"(%3.03f Mhz (%" PRIu32
".%03" PRIu32
"khz slowclk)",
2662 uint32_t mula, diva;
2670 LOG_USER(
"\tPLLA Freq: (Disabled,mula = 0)");
2672 LOG_USER(
"\tPLLA Freq: (Disabled,diva = 0)");
2673 else if (diva >= 1) {
2675 LOG_USER(
"\tPLLA Freq: %3.03f MHz",
2682 uint32_t css, pres, fin = 0;
2684 const char *cp =
NULL;
2702 fin = 480 * 1000 * 1000;
2706 cp =
"upll (*ERROR* UPLL is disabled)";
2718 switch (pres & 0x07) {
2721 cp =
"selected clock";
2762 LOG_USER(
"\t\tResult CPU Freq: %3.03f",
2798 #define SAM3_ENTRY(NAME, FUNC) { .address = SAM3_ ## NAME, .struct_offset = offsetof( \
2800 NAME), # NAME, FUNC }
2827 return bank->driver_priv;
2845 possible = ((uint32_t *)(
void *)(((
char *)(&(chip->
cfg))) +
reg->struct_offset));
2848 if (possible == goes_here) {
2872 LOG_ERROR(
"Cannot read SAM3 register: %s @ 0x%08x, Err: %d",
2888 LOG_ERROR(
"Cannot read SAM3 register: %s @ 0x%08x, Error: %d",
2927 LOG_USER(
"%*s: [0x%08" PRIx32
"] -> 0x%08" PRIx32,
2932 if (
reg->explain_func)
2933 (*(
reg->explain_func))(chip);
2943 LOG_USER(
" UniqueId: 0x%08" PRIx32
" 0x%08" PRIx32
" 0x%08" PRIx32
" 0x%08" PRIx32,
2970 if (!(private->probed))
2979 for (x = 0; x <
private->nsectors; x++)
2980 bank->sectors[x].is_protected = (!!(v & (1 << x)));
3000 chip = calloc(1,
sizeof(
struct sam3_chip));
3015 switch (
bank->base) {
3017 LOG_ERROR(
"Address 0x%08x invalid bank address (try 0x%08x or 0x%08x "
3018 "[at91sam3u series] or 0x%08x [at91sam3s series] or "
3019 "0x%08x [at91sam3n series] or 0x%08x or 0x%08x or 0x%08x[at91sam3ax series] )",
3020 ((
unsigned int)(
bank->base)),
3035 bank->bank_number = 0;
3045 bank->bank_number = 1;
3080 while (details->
name) {
3082 if (((details->
chipid_cidr ^ private->chip->cfg.CHIPID_CIDR) & 0xFFFFFFE0) == 0)
3087 if (!details->
name) {
3088 LOG_ERROR(
"SAM3 ChipID 0x%08x not found in table (perhaps you can ID this chip?)",
3089 (
unsigned int)(private->chip->cfg.CHIPID_CIDR));
3091 LOG_INFO(
"SAM3 CHIPID_CIDR: 0x%08" PRIx32
" decodes as follows",
3092 private->chip->cfg.CHIPID_CIDR);
3101 chip =
private->chip;
3114 memcpy(&(private->chip->details),
3116 sizeof(private->chip->details));
3136 LOG_DEBUG(
"Begin: Bank: %u, Noise: %d",
bank->bank_number, noise);
3144 LOG_ERROR(
"Invalid/unknown bank number");
3153 if (private->chip->probed)
3162 if (
bank->base == private->chip->details.bank[x].base_address) {
3163 bank->size =
private->chip->details.bank[x].size_bytes;
3168 if (!
bank->sectors) {
3169 bank->sectors = calloc(private->nsectors, (
sizeof((
bank->sectors)[0])));
3170 if (!
bank->sectors) {
3174 bank->num_sectors =
private->nsectors;
3176 for (
unsigned int x = 0; x <
bank->num_sectors; x++) {
3177 bank->sectors[x].size =
private->sector_size;
3178 bank->sectors[x].offset = x * (
private->sector_size);
3180 bank->sectors[x].is_erased = -1;
3181 bank->sectors[x].is_protected = -1;
3185 private->probed =
true;
3192 private->bank_number, private->chip->details.n_banks);
3193 if ((private->bank_number + 1) == private->chip->details.n_banks) {
3231 if (!(private->probed))
3234 if ((first == 0) && ((last + 1) == private->nsectors)) {
3239 LOG_INFO(
"sam3 auto-erases while programming (request ignored)");
3256 if (!(private->probed))
3274 adr = pagenum *
private->page_size;
3275 adr +=
private->base_address;
3280 private->page_size / 4,
3283 LOG_ERROR(
"SAM3: Flash program failed to read page phys address: 0x%08x",
3284 (
unsigned int)(adr));
3295 adr = pagenum *
private->page_size;
3296 adr +=
private->base_address;
3299 r =
target_read_u32(private->chip->target, private->controller_address, &fmr);
3301 LOG_DEBUG(
"Error Read failed: read flash mode register");
3307 fmr |= (
private->flash_wait_states << 8);
3309 LOG_DEBUG(
"Flash Mode: 0x%08x", ((
unsigned int)(fmr)));
3310 r =
target_write_u32(private->bank->target, private->controller_address, fmr);
3312 LOG_DEBUG(
"Error Write failed: set flash mode register");
3314 LOG_DEBUG(
"Wr Page %u @ phys address: 0x%08x", pagenum, (
unsigned int)(adr));
3318 private->page_size / 4,
3321 LOG_ERROR(
"SAM3: Failed to write (buffer) page at phys address 0x%08x",
3322 (
unsigned int)(adr));
3333 LOG_ERROR(
"SAM3: Error performing Erase & Write page @ phys address 0x%08x",
3334 (
unsigned int)(adr));
3336 LOG_ERROR(
"SAM3: Page @ Phys address 0x%08x is locked", (
unsigned int)(adr));
3340 LOG_ERROR(
"SAM3: Flash Command error @phys address 0x%08x", (
unsigned int)(adr));
3355 unsigned page_offset;
3357 uint8_t *pagebuffer;
3375 if (!(private->probed)) {
3381 LOG_ERROR(
"Flash write error - past end of bank");
3382 LOG_ERROR(
" offset: 0x%08x, count 0x%08x, BankEnd: 0x%08x",
3384 (
unsigned int)(
count),
3385 (
unsigned int)(private->size_bytes));
3390 pagebuffer = malloc(private->page_size);
3392 LOG_ERROR(
"No memory for %d Byte page buffer", (
int)(private->page_size));
3398 page_cur =
offset /
private->page_size;
3399 page_end = (
offset +
count - 1) / private->page_size;
3402 LOG_DEBUG(
"Page start: %d, Page End: %d", (
int)(page_cur), (
int)(page_end));
3412 if (page_cur == page_end) {
3413 LOG_DEBUG(
"Special case, all in one page");
3418 page_offset = (
offset & (
private->page_size-1));
3419 memcpy(pagebuffer + page_offset,
3431 page_offset =
offset & (
private->page_size - 1);
3440 n = (
private->page_size - page_offset);
3441 memcpy(pagebuffer + page_offset,
3457 assert(
offset % private->page_size == 0);
3462 LOG_DEBUG(
"Full Page Loop: cur=%d, end=%d, count = 0x%08x",
3463 (
int)page_cur, (
int)page_end, (
unsigned int)(
count));
3465 while ((page_cur < page_end) &&
3466 (
count >= private->page_size)) {
3470 count -=
private->page_size;
3471 buffer +=
private->page_size;
3477 LOG_DEBUG(
"Terminal partial page, count = 0x%08x", (
unsigned int)(
count));
3510 "Please define bank %d via command: flash bank %s ... ",
3587 if ((strcmp(
CMD_ARGV[0],
"show") == 0) && (strcmp(
CMD_ARGV[1],
"all") == 0))
3597 if (strcmp(
"show",
CMD_ARGV[0]) == 0) {
3625 if (strcmp(
"set",
CMD_ARGV[0]) == 0)
3627 else if ((strcmp(
"clr",
CMD_ARGV[0]) == 0) ||
3628 (strcmp(
"clear",
CMD_ARGV[0]) == 0))
3676 .handler = sam3_handle_gpnvm_command,
3678 .usage =
"[('clr'|'set'|'show') bitnum]",
3679 .help =
"Without arguments, shows all bits in the gpnvm "
3680 "register. Otherwise, clears, sets, or shows one "
3681 "General Purpose Non-Volatile Memory (gpnvm) bit.",
3685 .handler = sam3_handle_info_command,
3687 .help =
"Print information about the current at91sam3 chip "
3688 "and its flash configuration.",
3693 .handler = sam3_handle_slowclk_command,
3695 .usage =
"[clock_hz]",
3696 .help =
"Display or set the slowclock frequency "
3697 "(default 32768 Hz).",
3705 .help =
"at91sam3 flash command group",
3715 .flash_bank_command = sam3_flash_bank_command,
#define FLASH_BANK1_BASE_512K_AX
#define FLASH_BANK0_BASE_U
#define FLASH_BANK1_BASE_256K_AX
static int sam3_get_info(struct sam3_chip *chip)
static int flashd_clr_gpnvm(struct sam3_bank_private *private, unsigned gpnvm)
Clears the selected GPNVM bit.
static struct sam3_chip * get_current_sam3(struct command_invocation *cmd)
static void sam3_explain_ckgr_mcfr(struct sam3_chip *chip)
static void sam3_explain_mckr(struct sam3_chip *chip)
#define AT91C_EFC_FCMD_WPL
#define AT91C_EFC_FCMD_GLB
#define FLASH_BANK_BASE_S
static int sam3_read_this_reg(struct sam3_chip *chip, uint32_t *goes_here)
static void sam3_explain_ckgr_plla(struct sam3_chip *chip)
static const char *const eproc_names[]
#define AT91C_EFC_FCMD_EWPL
static int efc_start_command(struct sam3_bank_private *private, unsigned command, unsigned argument)
static const char _unknown[]
#define FLASH_BANK1_BASE_512K_SD
static const char * _yes_or_no(uint32_t v)
#define AT91C_EFC_FCMD_SFB
static int sam3_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
static int sam3_probe(struct flash_bank *bank)
static int flashd_get_lock_bits(struct sam3_bank_private *private, uint32_t *v)
Returns a bit field (at most 64) of locked regions within a page.
#define AT91C_EFC_FCMD_EA
static const struct sam3_chip_details all_sam3_details[]
static const struct sam3_reg_list * sam3_get_reg(struct sam3_chip *chip, uint32_t *goes_here)
Given a pointer to where it goes in the structure, determine the register name, address from the all ...
static int flashd_read_uid(struct sam3_bank_private *private)
Read the unique ID.
static struct sam3_bank_private * get_sam3_bank_private(struct flash_bank *bank)
static const struct command_registration at91sam3_exec_command_handlers[]
#define AT91C_EFC_FCMD_GFB
static int sam3_protect(struct flash_bank *bank, int set, unsigned int first, unsigned int last)
static int flashd_unlock(struct sam3_bank_private *private, unsigned start_sector, unsigned end_sector)
Unlocks all the regions in the given address range.
static int flashd_lock(struct sam3_bank_private *private, unsigned start_sector, unsigned end_sector)
Locks regions.
static const char *const nvpsize[]
#define AT91C_EFC_FCMD_EWP
const struct flash_driver at91sam3_flash
#define FLASH_BANK_BASE_N
static float _tomhz(uint32_t freq_hz)
static int flashd_set_gpnvm(struct sam3_bank_private *private, unsigned gpnvm)
Sets the selected GPNVM bit.
static int sam3_page_write(struct sam3_bank_private *private, unsigned pagenum, const uint8_t *buf)
#define AT91C_EFC_FCMD_WP
static struct sam3_chip * all_sam3_chips
static int _sam3_probe(struct flash_bank *bank, int noise)
static const struct command_registration at91sam3_command_handlers[]
static void sam3_free_driver_priv(struct flash_bank *bank)
Remove all chips from the internal list without distinguishing which one is owned by this bank.
static int sam3_get_details(struct sam3_bank_private *private)
static const char *const nvptype[]
static int efc_get_result(struct sam3_bank_private *private, uint32_t *v)
Get the result of the last executed command.
static void sam3_explain_chipid_cidr(struct sam3_chip *chip)
#define FLASH_BANK0_BASE_SD
static uint32_t * sam3_get_reg_ptr(struct sam3_cfg *cfg, const struct sam3_reg_list *list)
static const struct sam3_reg_list sam3_all_regs[]
#define FLASH_BANK0_BASE_AX
static void sam3_explain_ckgr_mor(struct sam3_chip *chip)
static uint32_t sam3_reg_fieldname(struct sam3_chip *chip, const char *regname, uint32_t value, unsigned shift, unsigned width)
#define SAM3_ENTRY(NAME, FUNC)
#define AT91C_EFC_FCMD_STUI
#define AT91C_EFC_FCMD_GETD
static int sam3_auto_probe(struct flash_bank *bank)
static int efc_get_status(struct sam3_bank_private *private, uint32_t *v)
Get the current status of the EEFC and the value of some status bits (LOCKE, PROGE).
static int sam3_erase(struct flash_bank *bank, unsigned int first, unsigned int last)
static int sam3_read_all_regs(struct sam3_chip *chip)
FLASH_BANK_COMMAND_HANDLER(sam3_flash_bank_command)
static const char *const sramsize[]
#define AT91C_EFC_FCMD_SPUI
#define FLASH_BANK1_BASE_U
#define AT91C_EFC_FCMD_CLB
static int flashd_erase_entire_bank(struct sam3_bank_private *private)
Erases the entire flash.
static int sam3_protect_check(struct flash_bank *bank)
#define AT91C_EFC_FCMD_SLB
static int sam3_page_read(struct sam3_bank_private *private, unsigned pagenum, uint8_t *buf)
static const char *const _rc_freq[]
#define AT91C_EFC_FCMD_CFB
static int efc_perform_command(struct sam3_bank_private *private, unsigned command, unsigned argument, uint32_t *status)
Performs the given command and wait until its completion (or an error).
static int flashd_get_gpnvm(struct sam3_bank_private *private, unsigned gpnvm, unsigned *puthere)
Gets current GPNVM state.
#define SAM3_MAX_FLASH_BANKS
COMMAND_HANDLER(sam3_handle_info_command)
void command_print_sameline(struct command_invocation *cmd, const char *format,...)
void command_print(struct command_invocation *cmd, const char *format,...)
#define CMD
Use this macro to access the command being handled, rather than accessing the variable directly.
#define CMD_ARGV
Use this macro to access the arguments for the command being handled, rather than accessing the varia...
#define ERROR_COMMAND_SYNTAX_ERROR
#define CMD_ARGC
Use this macro to access the number of arguments for the command being handled, rather than accessing...
#define COMMAND_PARSE_NUMBER(type, in, out)
parses the string in into out as a type, or prints a command error and passes the error code to the c...
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
#define ERROR_FLASH_BANK_NOT_PROBED
int default_flash_blank_check(struct flash_bank *bank)
Provides default erased-bank check handling.
int default_flash_read(struct flash_bank *bank, uint8_t *buffer, uint32_t offset, uint32_t count)
Provides default read implementation for flash memory.
#define LOG_USER(expr ...)
#define LOG_USER_N(expr ...)
#define LOG_ERROR(expr ...)
#define LOG_INFO(expr ...)
#define LOG_DEBUG(expr ...)
When run_command is called, a new instance will be created on the stack, filled with the proper value...
Provides details of a flash bank, available either on-chip or through a major interface.
Provides the implementation-independent structure that defines all of the callbacks required by OpenO...
const char * name
Gives a human-readable name of this flash driver, This field is used to select and initialize the dri...
uint32_t controller_address
uint32_t flash_wait_states
unsigned gpnvm[SAM3_N_NVM_BITS]
unsigned total_flash_size
struct sam3_bank_private bank[SAM3_MAX_FLASH_BANKS]
struct sam3_chip_details details
void(* explain_func)(struct sam3_chip *chip)
int target_write_memory(struct target *target, target_addr_t address, uint32_t size, uint32_t count, const uint8_t *buffer)
Write count items of size bytes to the memory of target at the address given.
int target_write_u32(struct target *target, target_addr_t address, uint32_t value)
int target_read_u32(struct target *target, target_addr_t address, uint32_t *value)
int target_read_memory(struct target *target, target_addr_t address, uint32_t size, uint32_t count, uint8_t *buffer)
Read count items of size bytes from the memory of target at the address given.
struct target * get_current_target(struct command_context *cmd_ctx)
#define ERROR_TARGET_NOT_HALTED