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
70 static float _tomhz(uint32_t freq_hz)
72 return ((
float)freq_hz) / 1000000.0;
91 #define SAM3_CHIPID_CIDR (0x400E0740)
93 #define SAM3_CHIPID_CIDR2 (0x400E0940)
95 #define SAM3_CHIPID_EXID (0x400E0744)
97 #define SAM3_CHIPID_EXID2 (0x400E0944)
101 #define SAM3_PMC_BASE (0x400E0400)
102 #define SAM3_PMC_SCSR (SAM3_PMC_BASE + 0x0008)
104 #define SAM3_PMC_PCSR (SAM3_PMC_BASE + 0x0018)
106 #define SAM3_CKGR_UCKR (SAM3_PMC_BASE + 0x001c)
108 #define SAM3_CKGR_MOR (SAM3_PMC_BASE + 0x0020)
110 #define SAM3_CKGR_MCFR (SAM3_PMC_BASE + 0x0024)
112 #define SAM3_CKGR_PLLAR (SAM3_PMC_BASE + 0x0028)
114 #define SAM3_PMC_MCKR (SAM3_PMC_BASE + 0x0030)
116 #define SAM3_PMC_PCK0 (SAM3_PMC_BASE + 0x0040)
118 #define SAM3_PMC_PCK1 (SAM3_PMC_BASE + 0x0044)
120 #define SAM3_PMC_PCK2 (SAM3_PMC_BASE + 0x0048)
122 #define SAM3_PMC_SR (SAM3_PMC_BASE + 0x0068)
124 #define SAM3_PMC_IMR (SAM3_PMC_BASE + 0x006c)
126 #define SAM3_PMC_FSMR (SAM3_PMC_BASE + 0x0070)
128 #define SAM3_PMC_FSPR (SAM3_PMC_BASE + 0x0074)
177 #define SAM3_N_NVM_BITS 3
182 #define SAM3_MAX_FLASH_BANKS 2
238 .name =
"at91sam3u4e",
239 .total_flash_size = 256 * 1024,
240 .total_sram_size = 52 * 1024,
267 .controller_address = 0x400e0800,
268 .flash_wait_states = 6,
270 .size_bytes = 128 * 1024,
283 .controller_address = 0x400e0a00,
284 .flash_wait_states = 6,
286 .size_bytes = 128 * 1024,
295 .chipid_cidr = 0x281a0760,
296 .name =
"at91sam3u2e",
297 .total_flash_size = 128 * 1024,
298 .total_sram_size = 36 * 1024,
318 .controller_address = 0x400e0800,
319 .flash_wait_states = 6,
321 .size_bytes = 128 * 1024,
335 .chipid_cidr = 0x28190560,
336 .name =
"at91sam3u1e",
337 .total_flash_size = 64 * 1024,
338 .total_sram_size = 20 * 1024,
360 .controller_address = 0x400e0800,
361 .flash_wait_states = 6,
363 .size_bytes = 64 * 1024,
379 .chipid_cidr = 0x28000960,
380 .name =
"at91sam3u4c",
381 .total_flash_size = 256 * 1024,
382 .total_sram_size = 52 * 1024,
409 .controller_address = 0x400e0800,
410 .flash_wait_states = 6,
412 .size_bytes = 128 * 1024,
424 .controller_address = 0x400e0a00,
425 .flash_wait_states = 6,
427 .size_bytes = 128 * 1024,
436 .chipid_cidr = 0x280a0760,
437 .name =
"at91sam3u2c",
438 .total_flash_size = 128 * 1024,
439 .total_sram_size = 36 * 1024,
459 .controller_address = 0x400e0800,
460 .flash_wait_states = 6,
462 .size_bytes = 128 * 1024,
476 .chipid_cidr = 0x28090560,
477 .name =
"at91sam3u1c",
478 .total_flash_size = 64 * 1024,
479 .total_sram_size = 20 * 1024,
501 .controller_address = 0x400e0800,
502 .flash_wait_states = 6,
504 .size_bytes = 64 * 1024,
525 .chipid_cidr = 0x28A00960,
526 .name =
"at91sam3s4c",
527 .total_flash_size = 256 * 1024,
528 .total_sram_size = 48 * 1024,
539 .controller_address = 0x400e0a00,
540 .flash_wait_states = 6,
542 .size_bytes = 256 * 1024,
544 .sector_size = 16384,
558 .chipid_cidr = 0x28900960,
559 .name =
"at91sam3s4b",
560 .total_flash_size = 256 * 1024,
561 .total_sram_size = 48 * 1024,
572 .controller_address = 0x400e0a00,
573 .flash_wait_states = 6,
575 .size_bytes = 256 * 1024,
577 .sector_size = 16384,
590 .chipid_cidr = 0x28800960,
591 .name =
"at91sam3s4a",
592 .total_flash_size = 256 * 1024,
593 .total_sram_size = 48 * 1024,
604 .controller_address = 0x400e0a00,
605 .flash_wait_states = 6,
607 .size_bytes = 256 * 1024,
609 .sector_size = 16384,
622 .chipid_cidr = 0x28AA0760,
623 .name =
"at91sam3s2c",
624 .total_flash_size = 128 * 1024,
625 .total_sram_size = 32 * 1024,
636 .controller_address = 0x400e0a00,
637 .flash_wait_states = 6,
639 .size_bytes = 128 * 1024,
641 .sector_size = 16384,
654 .chipid_cidr = 0x289A0760,
655 .name =
"at91sam3s2b",
656 .total_flash_size = 128 * 1024,
657 .total_sram_size = 32 * 1024,
668 .controller_address = 0x400e0a00,
669 .flash_wait_states = 6,
671 .size_bytes = 128 * 1024,
673 .sector_size = 16384,
686 .chipid_cidr = 0x298B0A60,
687 .name =
"at91sam3sd8a",
688 .total_flash_size = 512 * 1024,
689 .total_sram_size = 64 * 1024,
700 .controller_address = 0x400e0a00,
701 .flash_wait_states = 6,
703 .size_bytes = 256 * 1024,
705 .sector_size = 32768,
715 .controller_address = 0x400e0a00,
716 .flash_wait_states = 6,
718 .size_bytes = 256 * 1024,
720 .sector_size = 32768,
726 .chipid_cidr = 0x299B0A60,
727 .name =
"at91sam3sd8b",
728 .total_flash_size = 512 * 1024,
729 .total_sram_size = 64 * 1024,
740 .controller_address = 0x400e0a00,
741 .flash_wait_states = 6,
743 .size_bytes = 256 * 1024,
745 .sector_size = 32768,
755 .controller_address = 0x400e0a00,
756 .flash_wait_states = 6,
758 .size_bytes = 256 * 1024,
760 .sector_size = 32768,
766 .chipid_cidr = 0x29ab0a60,
767 .name =
"at91sam3sd8c",
768 .total_flash_size = 512 * 1024,
769 .total_sram_size = 64 * 1024,
780 .controller_address = 0x400e0a00,
781 .flash_wait_states = 6,
783 .size_bytes = 256 * 1024,
785 .sector_size = 32768,
795 .controller_address = 0x400e0a00,
796 .flash_wait_states = 6,
798 .size_bytes = 256 * 1024,
800 .sector_size = 32768,
806 .chipid_cidr = 0x288A0760,
807 .name =
"at91sam3s2a",
808 .total_flash_size = 128 * 1024,
809 .total_sram_size = 32 * 1024,
820 .controller_address = 0x400e0a00,
821 .flash_wait_states = 6,
823 .size_bytes = 128 * 1024,
825 .sector_size = 16384,
838 .chipid_cidr = 0x28A90560,
839 .name =
"at91sam3s1c",
840 .total_flash_size = 64 * 1024,
841 .total_sram_size = 16 * 1024,
852 .controller_address = 0x400e0a00,
853 .flash_wait_states = 6,
855 .size_bytes = 64 * 1024,
857 .sector_size = 16384,
870 .chipid_cidr = 0x28990560,
871 .name =
"at91sam3s1b",
872 .total_flash_size = 64 * 1024,
873 .total_sram_size = 16 * 1024,
884 .controller_address = 0x400e0a00,
885 .flash_wait_states = 6,
887 .size_bytes = 64 * 1024,
889 .sector_size = 16384,
902 .chipid_cidr = 0x28890560,
903 .name =
"at91sam3s1a",
904 .total_flash_size = 64 * 1024,
905 .total_sram_size = 16 * 1024,
916 .controller_address = 0x400e0a00,
917 .flash_wait_states = 6,
919 .size_bytes = 64 * 1024,
921 .sector_size = 16384,
934 .chipid_cidr = 0x288B0A60,
935 .name =
"at91sam3s8a",
936 .total_flash_size = 256 * 2048,
937 .total_sram_size = 64 * 1024,
948 .controller_address = 0x400e0a00,
949 .flash_wait_states = 6,
951 .size_bytes = 256 * 2048,
953 .sector_size = 32768,
966 .chipid_cidr = 0x289B0A60,
967 .name =
"at91sam3s8b",
968 .total_flash_size = 256 * 2048,
969 .total_sram_size = 64 * 1024,
980 .controller_address = 0x400e0a00,
981 .flash_wait_states = 6,
983 .size_bytes = 256 * 2048,
985 .sector_size = 32768,
998 .chipid_cidr = 0x28AB0A60,
999 .name =
"at91sam3s8c",
1000 .total_flash_size = 256 * 2048,
1001 .total_sram_size = 64 * 1024,
1012 .controller_address = 0x400e0a00,
1013 .flash_wait_states = 6,
1015 .size_bytes = 256 * 2048,
1017 .sector_size = 32768,
1032 .chipid_cidr = 0x29540960,
1033 .name =
"at91sam3n4c",
1034 .total_flash_size = 256 * 1024,
1035 .total_sram_size = 24 * 1024,
1062 .controller_address = 0x400e0A00,
1063 .flash_wait_states = 6,
1065 .size_bytes = 256 * 1024,
1067 .sector_size = 16384,
1081 .chipid_cidr = 0x29440960,
1082 .name =
"at91sam3n4b",
1083 .total_flash_size = 256 * 1024,
1084 .total_sram_size = 24 * 1024,
1111 .controller_address = 0x400e0A00,
1112 .flash_wait_states = 6,
1114 .size_bytes = 256 * 1024,
1116 .sector_size = 16384,
1130 .chipid_cidr = 0x29340960,
1131 .name =
"at91sam3n4a",
1132 .total_flash_size = 256 * 1024,
1133 .total_sram_size = 24 * 1024,
1160 .controller_address = 0x400e0A00,
1161 .flash_wait_states = 6,
1163 .size_bytes = 256 * 1024,
1165 .sector_size = 16384,
1179 .chipid_cidr = 0x29590760,
1180 .name =
"at91sam3n2c",
1181 .total_flash_size = 128 * 1024,
1182 .total_sram_size = 16 * 1024,
1209 .controller_address = 0x400e0A00,
1210 .flash_wait_states = 6,
1212 .size_bytes = 128 * 1024,
1214 .sector_size = 16384,
1228 .chipid_cidr = 0x29490760,
1229 .name =
"at91sam3n2b",
1230 .total_flash_size = 128 * 1024,
1231 .total_sram_size = 16 * 1024,
1258 .controller_address = 0x400e0A00,
1259 .flash_wait_states = 6,
1261 .size_bytes = 128 * 1024,
1263 .sector_size = 16384,
1277 .chipid_cidr = 0x29390760,
1278 .name =
"at91sam3n2a",
1279 .total_flash_size = 128 * 1024,
1280 .total_sram_size = 16 * 1024,
1307 .controller_address = 0x400e0A00,
1308 .flash_wait_states = 6,
1310 .size_bytes = 128 * 1024,
1312 .sector_size = 16384,
1326 .chipid_cidr = 0x29580560,
1327 .name =
"at91sam3n1c",
1328 .total_flash_size = 64 * 1024,
1329 .total_sram_size = 8 * 1024,
1356 .controller_address = 0x400e0A00,
1357 .flash_wait_states = 6,
1359 .size_bytes = 64 * 1024,
1361 .sector_size = 16384,
1375 .chipid_cidr = 0x29480560,
1376 .name =
"at91sam3n1b",
1377 .total_flash_size = 64 * 1024,
1378 .total_sram_size = 8 * 1024,
1405 .controller_address = 0x400e0A00,
1406 .flash_wait_states = 6,
1408 .size_bytes = 64 * 1024,
1410 .sector_size = 16384,
1424 .chipid_cidr = 0x29380560,
1425 .name =
"at91sam3n1a",
1426 .total_flash_size = 64 * 1024,
1427 .total_sram_size = 8 * 1024,
1454 .controller_address = 0x400e0A00,
1455 .flash_wait_states = 6,
1457 .size_bytes = 64 * 1024,
1459 .sector_size = 16384,
1473 .chipid_cidr = 0x29480360,
1474 .name =
"at91sam3n0b",
1475 .total_flash_size = 32 * 1024,
1476 .total_sram_size = 8 * 1024,
1488 .controller_address = 0x400e0A00,
1489 .flash_wait_states = 6,
1491 .size_bytes = 32 * 1024,
1493 .sector_size = 16384,
1507 .chipid_cidr = 0x29380360,
1508 .name =
"at91sam3n0a",
1509 .total_flash_size = 32 * 1024,
1510 .total_sram_size = 8 * 1024,
1522 .controller_address = 0x400e0A00,
1523 .flash_wait_states = 6,
1525 .size_bytes = 32 * 1024,
1527 .sector_size = 16384,
1541 .chipid_cidr = 0x29450260,
1542 .name =
"at91sam3n00b",
1543 .total_flash_size = 16 * 1024,
1544 .total_sram_size = 4 * 1024,
1556 .controller_address = 0x400e0A00,
1557 .flash_wait_states = 6,
1559 .size_bytes = 16 * 1024,
1561 .sector_size = 16384,
1575 .chipid_cidr = 0x29350260,
1576 .name =
"at91sam3n00a",
1577 .total_flash_size = 16 * 1024,
1578 .total_sram_size = 4 * 1024,
1590 .controller_address = 0x400e0A00,
1591 .flash_wait_states = 6,
1593 .size_bytes = 16 * 1024,
1595 .sector_size = 16384,
1627 .chipid_cidr = 0x283E0A60,
1628 .name =
"at91sam3a8c",
1629 .total_flash_size = 512 * 1024,
1630 .total_sram_size = 96 * 1024,
1641 .controller_address = 0x400e0a00,
1642 .flash_wait_states = 6,
1644 .size_bytes = 256 * 1024,
1646 .sector_size = 16384,
1656 .controller_address = 0x400e0c00,
1657 .flash_wait_states = 6,
1659 .size_bytes = 256 * 1024,
1661 .sector_size = 16384,
1668 .chipid_cidr = 0x283B0960,
1669 .name =
"at91sam3a4c",
1670 .total_flash_size = 256 * 1024,
1671 .total_sram_size = 64 * 1024,
1682 .controller_address = 0x400e0a00,
1683 .flash_wait_states = 6,
1685 .size_bytes = 128 * 1024,
1687 .sector_size = 16384,
1697 .controller_address = 0x400e0c00,
1698 .flash_wait_states = 6,
1700 .size_bytes = 128 * 1024,
1702 .sector_size = 16384,
1727 .chipid_cidr = 0x286E0A20,
1728 .name =
"at91sam3x8h - ES",
1729 .total_flash_size = 512 * 1024,
1730 .total_sram_size = 96 * 1024,
1741 .controller_address = 0x400e0a00,
1742 .flash_wait_states = 6,
1744 .size_bytes = 256 * 1024,
1746 .sector_size = 16384,
1756 .controller_address = 0x400e0c00,
1757 .flash_wait_states = 6,
1759 .size_bytes = 256 * 1024,
1761 .sector_size = 16384,
1769 .chipid_cidr = 0x286E0A60,
1770 .name =
"at91sam3x8h",
1771 .total_flash_size = 512 * 1024,
1772 .total_sram_size = 96 * 1024,
1783 .controller_address = 0x400e0a00,
1784 .flash_wait_states = 6,
1786 .size_bytes = 256 * 1024,
1788 .sector_size = 16384,
1798 .controller_address = 0x400e0c00,
1799 .flash_wait_states = 6,
1801 .size_bytes = 256 * 1024,
1803 .sector_size = 16384,
1810 .chipid_cidr = 0x285E0A60,
1811 .name =
"at91sam3x8e",
1812 .total_flash_size = 512 * 1024,
1813 .total_sram_size = 96 * 1024,
1824 .controller_address = 0x400e0a00,
1825 .flash_wait_states = 6,
1827 .size_bytes = 256 * 1024,
1829 .sector_size = 16384,
1839 .controller_address = 0x400e0c00,
1840 .flash_wait_states = 6,
1842 .size_bytes = 256 * 1024,
1844 .sector_size = 16384,
1851 .chipid_cidr = 0x284E0A60,
1852 .name =
"at91sam3x8c",
1853 .total_flash_size = 512 * 1024,
1854 .total_sram_size = 96 * 1024,
1865 .controller_address = 0x400e0a00,
1866 .flash_wait_states = 6,
1868 .size_bytes = 256 * 1024,
1870 .sector_size = 16384,
1880 .controller_address = 0x400e0c00,
1881 .flash_wait_states = 6,
1883 .size_bytes = 256 * 1024,
1885 .sector_size = 16384,
1892 .chipid_cidr = 0x285B0960,
1893 .name =
"at91sam3x4e",
1894 .total_flash_size = 256 * 1024,
1895 .total_sram_size = 64 * 1024,
1906 .controller_address = 0x400e0a00,
1907 .flash_wait_states = 6,
1909 .size_bytes = 128 * 1024,
1911 .sector_size = 16384,
1921 .controller_address = 0x400e0c00,
1922 .flash_wait_states = 6,
1924 .size_bytes = 128 * 1024,
1926 .sector_size = 16384,
1933 .chipid_cidr = 0x284B0960,
1934 .name =
"at91sam3x4c",
1935 .total_flash_size = 256 * 1024,
1936 .total_sram_size = 64 * 1024,
1947 .controller_address = 0x400e0a00,
1948 .flash_wait_states = 6,
1950 .size_bytes = 128 * 1024,
1952 .sector_size = 16384,
1962 .controller_address = 0x400e0c00,
1963 .flash_wait_states = 6,
1965 .size_bytes = 128 * 1024,
1967 .sector_size = 16384,
2001 LOG_DEBUG(
"Status: 0x%08x (lockerror: %d, cmderror: %d, ready: %d)",
2003 ((
unsigned int)((*v >> 2) & 1)),
2004 ((
unsigned int)((*v >> 1) & 1)),
2005 ((
unsigned int)((*v >> 0) & 1)));
2024 LOG_DEBUG(
"Result: 0x%08x", ((
unsigned int)(rv)));
2029 unsigned int command,
unsigned int argument)
2048 n = (
private->size_bytes /
private->page_size);
2050 LOG_ERROR(
"*BUG*: Embedded flash has only %" PRIu32
" pages", n);
2055 if (argument >= private->chip->details.n_gpnvms) {
2056 LOG_ERROR(
"*BUG*: Embedded flash has only %d GPNVMs",
2057 private->chip->details.n_gpnvms);
2090 LOG_ERROR(
"flash controller(%d) is not ready! Error",
2091 private->bank_number);
2095 LOG_ERROR(
"Flash controller(%d) is not ready, attempting reset",
2096 private->bank_number);
2106 v = (0x5A << 24) | (argument << 8) |
command;
2107 LOG_DEBUG(
"Command: 0x%08x", ((
unsigned int)(v)));
2124 unsigned int argument,
2130 int64_t ms_now, ms_end;
2147 if (ms_now > ms_end) {
2152 }
while ((v & 1) == 0);
2172 private->chip->cfg.unique_id[0] = 0;
2173 private->chip->cfg.unique_id[1] = 0;
2174 private->chip->cfg.unique_id[2] = 0;
2175 private->chip->cfg.unique_id[3] = 0;
2182 for (x = 0; x < 4; x++) {
2184 private->bank->base + (x * 4),
2188 private->chip->cfg.unique_id[x] = v;
2192 LOG_DEBUG(
"End: R=%d, id = 0x%08x, 0x%08x, 0x%08x, 0x%08x",
2194 (
unsigned int)(private->chip->cfg.unique_id[0]),
2195 (
unsigned int)(private->chip->cfg.unique_id[1]),
2196 (
unsigned int)(private->chip->cfg.unique_id[2]),
2197 (
unsigned int)(private->chip->cfg.unique_id[3]));
2225 if (private->bank_number != 0) {
2226 LOG_ERROR(
"GPNVM only works with Bank0");
2230 if (
gpnvm >= private->chip->details.n_gpnvms) {
2231 LOG_ERROR(
"Invalid GPNVM %d, max: %d, ignored",
2232 gpnvm, private->chip->details.n_gpnvms);
2248 *puthere = (v >>
gpnvm) & 1;
2266 if (private->bank_number != 0) {
2267 LOG_ERROR(
"GPNVM only works with Bank0");
2271 if (
gpnvm >= private->chip->details.n_gpnvms) {
2272 LOG_ERROR(
"Invalid GPNVM %d, max: %d, ignored",
2273 gpnvm, private->chip->details.n_gpnvms);
2297 if (private->bank_number != 0) {
2298 LOG_ERROR(
"GPNVM only works with Bank0");
2302 if (
gpnvm >= private->chip->details.n_gpnvms) {
2303 LOG_ERROR(
"Invalid GPNVM %d, max: %d, ignored",
2304 gpnvm, private->chip->details.n_gpnvms);
2345 unsigned int start_sector,
2346 unsigned int end_sector)
2351 uint32_t pages_per_sector;
2353 pages_per_sector =
private->sector_size /
private->page_size;
2356 while (start_sector <= end_sector) {
2357 pg = start_sector * pages_per_sector;
2375 unsigned int start_sector,
2376 unsigned int end_sector)
2380 uint32_t pages_per_sector;
2383 pages_per_sector =
private->sector_size /
private->page_size;
2386 while (start_sector <= end_sector) {
2387 pg = start_sector * pages_per_sector;
2402 const char *regname,
2413 v = v & ((1 <<
width)-1);
2423 LOG_USER_N(
"\t%*s: %*" PRIu32
" [0x%0*" PRIx32
"] ",
2450 #define nvpsize2 nvpsize
2491 { 0x19,
"AT91SAM9xx Series" },
2492 { 0x29,
"AT91SAM9XExx Series" },
2493 { 0x34,
"AT91x34 Series" },
2494 { 0x37,
"CAP7 Series" },
2495 { 0x39,
"CAP9 Series" },
2496 { 0x3B,
"CAP11 Series" },
2497 { 0x40,
"AT91x40 Series" },
2498 { 0x42,
"AT91x42 Series" },
2499 { 0x55,
"AT91x55 Series" },
2500 { 0x60,
"AT91SAM7Axx Series" },
2501 { 0x61,
"AT91SAM7AQxx Series" },
2502 { 0x63,
"AT91x63 Series" },
2503 { 0x70,
"AT91SAM7Sxx Series" },
2504 { 0x71,
"AT91SAM7XCxx Series" },
2505 { 0x72,
"AT91SAM7SExx Series" },
2506 { 0x73,
"AT91SAM7Lxx Series" },
2507 { 0x75,
"AT91SAM7Xxx Series" },
2508 { 0x76,
"AT91SAM7SLxx Series" },
2509 { 0x80,
"ATSAM3UxC Series (100-pin version)" },
2510 { 0x81,
"ATSAM3UxE Series (144-pin version)" },
2511 { 0x83,
"ATSAM3AxC Series (100-pin version)" },
2512 { 0x84,
"ATSAM3XxC Series (100-pin version)" },
2513 { 0x85,
"ATSAM3XxE Series (144-pin version)" },
2514 { 0x86,
"ATSAM3XxG Series (208/217-pin version)" },
2515 { 0x88,
"ATSAM3SxA Series (48-pin version)" },
2516 { 0x89,
"ATSAM3SxB Series (64-pin version)" },
2517 { 0x8A,
"ATSAM3SxC Series (100-pin version)" },
2518 { 0x92,
"AT91x92 Series" },
2519 { 0x93,
"ATSAM3NxA Series (48-pin version)" },
2520 { 0x94,
"ATSAM3NxB Series (64-pin version)" },
2521 { 0x95,
"ATSAM3NxC Series (100-pin version)" },
2522 { 0x98,
"ATSAM3SDxA Series (48-pin version)" },
2523 { 0x99,
"ATSAM3SDxB Series (64-pin version)" },
2524 { 0x9A,
"ATSAM3SDxC Series (100-pin version)" },
2525 { 0xA5,
"ATSAM5A" },
2526 { 0xF0,
"AT75Cxx Series" },
2532 "romless or onchip flash",
2533 "embedded flash memory",
2534 "rom(nvpsiz) + embedded flash (nvpsiz2)",
2535 "sram emulating flash",
2550 "4 MHz",
"8 MHz",
"12 MHz",
"reserved"
2586 LOG_USER(
"(startup clks, time= %f uSecs)",
2587 ((
float)(v * 1000000)) / ((
float)(chip->
cfg.
slow_freq)));
2590 v ?
"external xtal" :
"internal RC");
2593 LOG_USER(
"(clock failure enabled: %s)",
2648 LOG_USER(
"(%3.03f Mhz (%" PRIu32
".%03" PRIu32
"khz slowclk)",
2656 uint32_t mula, diva;
2664 LOG_USER(
"\tPLLA Freq: (Disabled,mula = 0)");
2666 LOG_USER(
"\tPLLA Freq: (Disabled,diva = 0)");
2667 else if (diva >= 1) {
2669 LOG_USER(
"\tPLLA Freq: %3.03f MHz",
2676 uint32_t css, pres, fin = 0;
2678 const char *cp =
NULL;
2696 fin = 480 * 1000 * 1000;
2700 cp =
"upll (*ERROR* UPLL is disabled)";
2712 switch (pres & 0x07) {
2715 cp =
"selected clock";
2756 LOG_USER(
"\t\tResult CPU Freq: %3.03f",
2792 #define SAM3_ENTRY(NAME, FUNC) { .address = SAM3_ ## NAME, .struct_offset = offsetof( \
2794 NAME), # NAME, FUNC }
2821 return bank->driver_priv;
2839 possible = ((uint32_t *)(
void *)(((
char *)(&(chip->
cfg))) +
reg->struct_offset));
2842 if (possible == goes_here) {
2866 LOG_ERROR(
"Cannot read SAM3 register: %s @ 0x%08" PRIx32
", Err: %d",
2882 LOG_ERROR(
"Cannot read SAM3 register: %s @ 0x%08" PRIx32
", Error: %d",
2921 LOG_USER(
"%*s: [0x%08" PRIx32
"] -> 0x%08" PRIx32,
2926 if (
reg->explain_func)
2927 (*(
reg->explain_func))(chip);
2937 LOG_USER(
" UniqueId: 0x%08" PRIx32
" 0x%08" PRIx32
" 0x%08" PRIx32
" 0x%08" PRIx32,
2964 if (!(private->probed))
2973 for (x = 0; x <
private->nsectors; x++)
2974 bank->sectors[x].is_protected = (!!(v & (1 << x)));
2994 chip = calloc(1,
sizeof(
struct sam3_chip));
3009 switch (
bank->base) {
3015 bank->bank_number = 0;
3025 bank->bank_number = 1;
3032 "[at91sam3u series] or 0x%08x [at91sam3s series] or "
3033 "0x%08x [at91sam3n series] or 0x%08x or 0x%08x or 0x%08x[at91sam3ax series] )",
3074 while (details->
name) {
3076 if (((details->
chipid_cidr ^ private->chip->cfg.CHIPID_CIDR) & 0xFFFFFFE0) == 0)
3081 if (!details->
name) {
3082 LOG_ERROR(
"SAM3 ChipID 0x%08x not found in table (perhaps you can ID this chip?)",
3083 (
unsigned int)(private->chip->cfg.CHIPID_CIDR));
3085 LOG_INFO(
"SAM3 CHIPID_CIDR: 0x%08" PRIx32
" decodes as follows",
3086 private->chip->cfg.CHIPID_CIDR);
3095 chip =
private->chip;
3108 memcpy(&(private->chip->details),
3110 sizeof(private->chip->details));
3130 LOG_DEBUG(
"Begin: Bank: %u, Noise: %d",
bank->bank_number, noise);
3138 LOG_ERROR(
"Invalid/unknown bank number");
3147 if (private->chip->probed)
3156 if (
bank->base == private->chip->details.bank[x].base_address) {
3157 bank->size =
private->chip->details.bank[x].size_bytes;
3162 if (!
bank->sectors) {
3163 bank->sectors = calloc(private->nsectors, (
sizeof((
bank->sectors)[0])));
3164 if (!
bank->sectors) {
3168 bank->num_sectors =
private->nsectors;
3170 for (
unsigned int x = 0; x <
bank->num_sectors; x++) {
3171 bank->sectors[x].size =
private->sector_size;
3172 bank->sectors[x].offset = x * (
private->sector_size);
3174 bank->sectors[x].is_erased = -1;
3175 bank->sectors[x].is_protected = -1;
3179 private->probed =
true;
3186 private->bank_number, private->chip->details.n_banks);
3187 if ((private->bank_number + 1) == private->chip->details.n_banks) {
3225 if (!(private->probed))
3228 if ((first == 0) && ((last + 1) == private->nsectors)) {
3233 LOG_INFO(
"sam3 auto-erases while programming (request ignored)");
3250 if (!(private->probed))
3268 adr = pagenum *
private->page_size;
3269 adr +=
private->base_address;
3274 private->page_size / 4,
3277 LOG_ERROR(
"SAM3: Flash program failed to read page phys address: 0x%08x",
3278 (
unsigned int)(adr));
3289 adr = pagenum *
private->page_size;
3290 adr +=
private->base_address;
3293 r =
target_read_u32(private->chip->target, private->controller_address, &fmr);
3295 LOG_DEBUG(
"Error Read failed: read flash mode register");
3301 fmr |= (
private->flash_wait_states << 8);
3303 LOG_DEBUG(
"Flash Mode: 0x%08x", ((
unsigned int)(fmr)));
3304 r =
target_write_u32(private->bank->target, private->controller_address, fmr);
3306 LOG_DEBUG(
"Error Write failed: set flash mode register");
3308 LOG_DEBUG(
"Wr Page %u @ phys address: 0x%08x", pagenum, (
unsigned int)(adr));
3312 private->page_size / 4,
3315 LOG_ERROR(
"SAM3: Failed to write (buffer) page at phys address 0x%08x",
3316 (
unsigned int)(adr));
3327 LOG_ERROR(
"SAM3: Error performing Erase & Write page @ phys address 0x%08x",
3328 (
unsigned int)(adr));
3330 LOG_ERROR(
"SAM3: Page @ Phys address 0x%08x is locked", (
unsigned int)(adr));
3334 LOG_ERROR(
"SAM3: Flash Command error @phys address 0x%08x", (
unsigned int)(adr));
3346 unsigned int page_cur;
3347 unsigned int page_end;
3349 unsigned int page_offset;
3351 uint8_t *pagebuffer;
3369 if (!(private->probed)) {
3375 LOG_ERROR(
"Flash write error - past end of bank");
3376 LOG_ERROR(
" offset: 0x%08x, count 0x%08x, BankEnd: 0x%08x",
3378 (
unsigned int)(
count),
3379 (
unsigned int)(private->size_bytes));
3384 pagebuffer = malloc(private->page_size);
3386 LOG_ERROR(
"No memory for %d Byte page buffer", (
int)(private->page_size));
3392 page_cur =
offset /
private->page_size;
3393 page_end = (
offset +
count - 1) / private->page_size;
3396 LOG_DEBUG(
"Page start: %d, Page End: %d", (
int)(page_cur), (
int)(page_end));
3406 if (page_cur == page_end) {
3407 LOG_DEBUG(
"Special case, all in one page");
3412 page_offset = (
offset & (
private->page_size-1));
3413 memcpy(pagebuffer + page_offset,
3425 page_offset =
offset & (
private->page_size - 1);
3434 n = (
private->page_size - page_offset);
3435 memcpy(pagebuffer + page_offset,
3451 assert(
offset % private->page_size == 0);
3456 LOG_DEBUG(
"Full Page Loop: cur=%d, end=%d, count = 0x%08x",
3457 (
int)page_cur, (
int)page_end, (
unsigned int)(
count));
3459 while ((page_cur < page_end) &&
3460 (
count >= private->page_size)) {
3464 count -=
private->page_size;
3465 buffer +=
private->page_size;
3471 LOG_DEBUG(
"Terminal partial page, count = 0x%08x", (
unsigned int)(
count));
3504 "Please define bank %d via command: flash bank %s ... ",
3579 if ((strcmp(
CMD_ARGV[0],
"show") == 0) && (strcmp(
CMD_ARGV[1],
"all") == 0)) {
3591 if (strcmp(
"show",
CMD_ARGV[0]) == 0) {
3619 if (strcmp(
"set",
CMD_ARGV[0]) == 0)
3621 else if ((strcmp(
"clr",
CMD_ARGV[0]) == 0) ||
3622 (strcmp(
"clear",
CMD_ARGV[0]) == 0))
3670 .handler = sam3_handle_gpnvm_command,
3672 .usage =
"[('clr'|'set'|'show') bitnum]",
3673 .help =
"Without arguments, shows all bits in the gpnvm "
3674 "register. Otherwise, clears, sets, or shows one "
3675 "General Purpose Non-Volatile Memory (gpnvm) bit.",
3679 .handler = sam3_handle_info_command,
3681 .help =
"Print information about the current at91sam3 chip "
3682 "and its flash configuration.",
3687 .handler = sam3_handle_slowclk_command,
3689 .usage =
"[clock_hz]",
3690 .help =
"Display or set the slowclock frequency "
3691 "(default 32768 Hz).",
3699 .help =
"at91sam3 flash command group",
3709 .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 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 const char _unknown[]
#define FLASH_BANK1_BASE_512K_SD
static int efc_perform_command(struct sam3_bank_private *private, unsigned int command, unsigned int argument, uint32_t *status)
Performs the given command and wait until its completion (or an error).
static const char * _yes_or_no(uint32_t v)
static int flashd_get_gpnvm(struct sam3_bank_private *private, unsigned int gpnvm, unsigned int *puthere)
Gets current GPNVM state.
#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 uint32_t sam3_reg_fieldname(struct sam3_chip *chip, const char *regname, uint32_t value, unsigned int shift, unsigned int width)
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[]
static int flashd_unlock(struct sam3_bank_private *private, unsigned int start_sector, unsigned int end_sector)
Unlocks all the regions in the given address range.
#define AT91C_EFC_FCMD_GFB
static int sam3_protect(struct flash_bank *bank, int set, unsigned int first, unsigned int last)
static int sam3_page_write(struct sam3_bank_private *private, unsigned int pagenum, const uint8_t *buf)
static int flashd_clr_gpnvm(struct sam3_bank_private *private, unsigned int gpnvm)
Clears the selected GPNVM bit.
static int flashd_set_gpnvm(struct sam3_bank_private *private, unsigned int gpnvm)
Sets the selected GPNVM bit.
static int efc_start_command(struct sam3_bank_private *private, unsigned int command, unsigned int argument)
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)
#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)
static int sam3_page_read(struct sam3_bank_private *private, unsigned int pagenum, uint8_t *buf)
#define FLASH_BANK0_BASE_SD
static int flashd_lock(struct sam3_bank_private *private, unsigned int start_sector, unsigned int end_sector)
Locks regions.
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)
#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 const char *const _rc_freq[]
#define AT91C_EFC_FCMD_CFB
#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.
uint64_t buffer
Pointer to data buffer to send over SPI.
#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 int total_flash_size
unsigned int gpnvm[SAM3_N_NVM_BITS]
struct sam3_bank_private bank[SAM3_MAX_FLASH_BANKS]
unsigned int total_sram_size
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