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)
74 f = ((float)(freq_hz)) / 1000000.0;
94 #define SAM3_CHIPID_CIDR (0x400E0740)
96 #define SAM3_CHIPID_CIDR2 (0x400E0940)
98 #define SAM3_CHIPID_EXID (0x400E0744)
100 #define SAM3_CHIPID_EXID2 (0x400E0944)
104 #define SAM3_PMC_BASE (0x400E0400)
105 #define SAM3_PMC_SCSR (SAM3_PMC_BASE + 0x0008)
107 #define SAM3_PMC_PCSR (SAM3_PMC_BASE + 0x0018)
109 #define SAM3_CKGR_UCKR (SAM3_PMC_BASE + 0x001c)
111 #define SAM3_CKGR_MOR (SAM3_PMC_BASE + 0x0020)
113 #define SAM3_CKGR_MCFR (SAM3_PMC_BASE + 0x0024)
115 #define SAM3_CKGR_PLLAR (SAM3_PMC_BASE + 0x0028)
117 #define SAM3_PMC_MCKR (SAM3_PMC_BASE + 0x0030)
119 #define SAM3_PMC_PCK0 (SAM3_PMC_BASE + 0x0040)
121 #define SAM3_PMC_PCK1 (SAM3_PMC_BASE + 0x0044)
123 #define SAM3_PMC_PCK2 (SAM3_PMC_BASE + 0x0048)
125 #define SAM3_PMC_SR (SAM3_PMC_BASE + 0x0068)
127 #define SAM3_PMC_IMR (SAM3_PMC_BASE + 0x006c)
129 #define SAM3_PMC_FSMR (SAM3_PMC_BASE + 0x0070)
131 #define SAM3_PMC_FSPR (SAM3_PMC_BASE + 0x0074)
180 #define SAM3_N_NVM_BITS 3
185 #define SAM3_MAX_FLASH_BANKS 2
241 .name =
"at91sam3u4e",
242 .total_flash_size = 256 * 1024,
243 .total_sram_size = 52 * 1024,
270 .controller_address = 0x400e0800,
271 .flash_wait_states = 6,
273 .size_bytes = 128 * 1024,
286 .controller_address = 0x400e0a00,
287 .flash_wait_states = 6,
289 .size_bytes = 128 * 1024,
298 .chipid_cidr = 0x281a0760,
299 .name =
"at91sam3u2e",
300 .total_flash_size = 128 * 1024,
301 .total_sram_size = 36 * 1024,
321 .controller_address = 0x400e0800,
322 .flash_wait_states = 6,
324 .size_bytes = 128 * 1024,
338 .chipid_cidr = 0x28190560,
339 .name =
"at91sam3u1e",
340 .total_flash_size = 64 * 1024,
341 .total_sram_size = 20 * 1024,
363 .controller_address = 0x400e0800,
364 .flash_wait_states = 6,
366 .size_bytes = 64 * 1024,
382 .chipid_cidr = 0x28000960,
383 .name =
"at91sam3u4c",
384 .total_flash_size = 256 * 1024,
385 .total_sram_size = 52 * 1024,
412 .controller_address = 0x400e0800,
413 .flash_wait_states = 6,
415 .size_bytes = 128 * 1024,
427 .controller_address = 0x400e0a00,
428 .flash_wait_states = 6,
430 .size_bytes = 128 * 1024,
439 .chipid_cidr = 0x280a0760,
440 .name =
"at91sam3u2c",
441 .total_flash_size = 128 * 1024,
442 .total_sram_size = 36 * 1024,
462 .controller_address = 0x400e0800,
463 .flash_wait_states = 6,
465 .size_bytes = 128 * 1024,
479 .chipid_cidr = 0x28090560,
480 .name =
"at91sam3u1c",
481 .total_flash_size = 64 * 1024,
482 .total_sram_size = 20 * 1024,
504 .controller_address = 0x400e0800,
505 .flash_wait_states = 6,
507 .size_bytes = 64 * 1024,
528 .chipid_cidr = 0x28A00960,
529 .name =
"at91sam3s4c",
530 .total_flash_size = 256 * 1024,
531 .total_sram_size = 48 * 1024,
542 .controller_address = 0x400e0a00,
543 .flash_wait_states = 6,
545 .size_bytes = 256 * 1024,
547 .sector_size = 16384,
561 .chipid_cidr = 0x28900960,
562 .name =
"at91sam3s4b",
563 .total_flash_size = 256 * 1024,
564 .total_sram_size = 48 * 1024,
575 .controller_address = 0x400e0a00,
576 .flash_wait_states = 6,
578 .size_bytes = 256 * 1024,
580 .sector_size = 16384,
593 .chipid_cidr = 0x28800960,
594 .name =
"at91sam3s4a",
595 .total_flash_size = 256 * 1024,
596 .total_sram_size = 48 * 1024,
607 .controller_address = 0x400e0a00,
608 .flash_wait_states = 6,
610 .size_bytes = 256 * 1024,
612 .sector_size = 16384,
625 .chipid_cidr = 0x28AA0760,
626 .name =
"at91sam3s2c",
627 .total_flash_size = 128 * 1024,
628 .total_sram_size = 32 * 1024,
639 .controller_address = 0x400e0a00,
640 .flash_wait_states = 6,
642 .size_bytes = 128 * 1024,
644 .sector_size = 16384,
657 .chipid_cidr = 0x289A0760,
658 .name =
"at91sam3s2b",
659 .total_flash_size = 128 * 1024,
660 .total_sram_size = 32 * 1024,
671 .controller_address = 0x400e0a00,
672 .flash_wait_states = 6,
674 .size_bytes = 128 * 1024,
676 .sector_size = 16384,
689 .chipid_cidr = 0x298B0A60,
690 .name =
"at91sam3sd8a",
691 .total_flash_size = 512 * 1024,
692 .total_sram_size = 64 * 1024,
703 .controller_address = 0x400e0a00,
704 .flash_wait_states = 6,
706 .size_bytes = 256 * 1024,
708 .sector_size = 32768,
718 .controller_address = 0x400e0a00,
719 .flash_wait_states = 6,
721 .size_bytes = 256 * 1024,
723 .sector_size = 32768,
729 .chipid_cidr = 0x299B0A60,
730 .name =
"at91sam3sd8b",
731 .total_flash_size = 512 * 1024,
732 .total_sram_size = 64 * 1024,
743 .controller_address = 0x400e0a00,
744 .flash_wait_states = 6,
746 .size_bytes = 256 * 1024,
748 .sector_size = 32768,
758 .controller_address = 0x400e0a00,
759 .flash_wait_states = 6,
761 .size_bytes = 256 * 1024,
763 .sector_size = 32768,
769 .chipid_cidr = 0x29ab0a60,
770 .name =
"at91sam3sd8c",
771 .total_flash_size = 512 * 1024,
772 .total_sram_size = 64 * 1024,
783 .controller_address = 0x400e0a00,
784 .flash_wait_states = 6,
786 .size_bytes = 256 * 1024,
788 .sector_size = 32768,
798 .controller_address = 0x400e0a00,
799 .flash_wait_states = 6,
801 .size_bytes = 256 * 1024,
803 .sector_size = 32768,
809 .chipid_cidr = 0x288A0760,
810 .name =
"at91sam3s2a",
811 .total_flash_size = 128 * 1024,
812 .total_sram_size = 32 * 1024,
823 .controller_address = 0x400e0a00,
824 .flash_wait_states = 6,
826 .size_bytes = 128 * 1024,
828 .sector_size = 16384,
841 .chipid_cidr = 0x28A90560,
842 .name =
"at91sam3s1c",
843 .total_flash_size = 64 * 1024,
844 .total_sram_size = 16 * 1024,
855 .controller_address = 0x400e0a00,
856 .flash_wait_states = 6,
858 .size_bytes = 64 * 1024,
860 .sector_size = 16384,
873 .chipid_cidr = 0x28990560,
874 .name =
"at91sam3s1b",
875 .total_flash_size = 64 * 1024,
876 .total_sram_size = 16 * 1024,
887 .controller_address = 0x400e0a00,
888 .flash_wait_states = 6,
890 .size_bytes = 64 * 1024,
892 .sector_size = 16384,
905 .chipid_cidr = 0x28890560,
906 .name =
"at91sam3s1a",
907 .total_flash_size = 64 * 1024,
908 .total_sram_size = 16 * 1024,
919 .controller_address = 0x400e0a00,
920 .flash_wait_states = 6,
922 .size_bytes = 64 * 1024,
924 .sector_size = 16384,
937 .chipid_cidr = 0x288B0A60,
938 .name =
"at91sam3s8a",
939 .total_flash_size = 256 * 2048,
940 .total_sram_size = 64 * 1024,
951 .controller_address = 0x400e0a00,
952 .flash_wait_states = 6,
954 .size_bytes = 256 * 2048,
956 .sector_size = 32768,
969 .chipid_cidr = 0x289B0A60,
970 .name =
"at91sam3s8b",
971 .total_flash_size = 256 * 2048,
972 .total_sram_size = 64 * 1024,
983 .controller_address = 0x400e0a00,
984 .flash_wait_states = 6,
986 .size_bytes = 256 * 2048,
988 .sector_size = 32768,
1001 .chipid_cidr = 0x28AB0A60,
1002 .name =
"at91sam3s8c",
1003 .total_flash_size = 256 * 2048,
1004 .total_sram_size = 64 * 1024,
1015 .controller_address = 0x400e0a00,
1016 .flash_wait_states = 6,
1018 .size_bytes = 256 * 2048,
1020 .sector_size = 32768,
1035 .chipid_cidr = 0x29540960,
1036 .name =
"at91sam3n4c",
1037 .total_flash_size = 256 * 1024,
1038 .total_sram_size = 24 * 1024,
1065 .controller_address = 0x400e0A00,
1066 .flash_wait_states = 6,
1068 .size_bytes = 256 * 1024,
1070 .sector_size = 16384,
1084 .chipid_cidr = 0x29440960,
1085 .name =
"at91sam3n4b",
1086 .total_flash_size = 256 * 1024,
1087 .total_sram_size = 24 * 1024,
1114 .controller_address = 0x400e0A00,
1115 .flash_wait_states = 6,
1117 .size_bytes = 256 * 1024,
1119 .sector_size = 16384,
1133 .chipid_cidr = 0x29340960,
1134 .name =
"at91sam3n4a",
1135 .total_flash_size = 256 * 1024,
1136 .total_sram_size = 24 * 1024,
1163 .controller_address = 0x400e0A00,
1164 .flash_wait_states = 6,
1166 .size_bytes = 256 * 1024,
1168 .sector_size = 16384,
1182 .chipid_cidr = 0x29590760,
1183 .name =
"at91sam3n2c",
1184 .total_flash_size = 128 * 1024,
1185 .total_sram_size = 16 * 1024,
1212 .controller_address = 0x400e0A00,
1213 .flash_wait_states = 6,
1215 .size_bytes = 128 * 1024,
1217 .sector_size = 16384,
1231 .chipid_cidr = 0x29490760,
1232 .name =
"at91sam3n2b",
1233 .total_flash_size = 128 * 1024,
1234 .total_sram_size = 16 * 1024,
1261 .controller_address = 0x400e0A00,
1262 .flash_wait_states = 6,
1264 .size_bytes = 128 * 1024,
1266 .sector_size = 16384,
1280 .chipid_cidr = 0x29390760,
1281 .name =
"at91sam3n2a",
1282 .total_flash_size = 128 * 1024,
1283 .total_sram_size = 16 * 1024,
1310 .controller_address = 0x400e0A00,
1311 .flash_wait_states = 6,
1313 .size_bytes = 128 * 1024,
1315 .sector_size = 16384,
1329 .chipid_cidr = 0x29580560,
1330 .name =
"at91sam3n1c",
1331 .total_flash_size = 64 * 1024,
1332 .total_sram_size = 8 * 1024,
1359 .controller_address = 0x400e0A00,
1360 .flash_wait_states = 6,
1362 .size_bytes = 64 * 1024,
1364 .sector_size = 16384,
1378 .chipid_cidr = 0x29480560,
1379 .name =
"at91sam3n1b",
1380 .total_flash_size = 64 * 1024,
1381 .total_sram_size = 8 * 1024,
1408 .controller_address = 0x400e0A00,
1409 .flash_wait_states = 6,
1411 .size_bytes = 64 * 1024,
1413 .sector_size = 16384,
1427 .chipid_cidr = 0x29380560,
1428 .name =
"at91sam3n1a",
1429 .total_flash_size = 64 * 1024,
1430 .total_sram_size = 8 * 1024,
1457 .controller_address = 0x400e0A00,
1458 .flash_wait_states = 6,
1460 .size_bytes = 64 * 1024,
1462 .sector_size = 16384,
1476 .chipid_cidr = 0x29480360,
1477 .name =
"at91sam3n0b",
1478 .total_flash_size = 32 * 1024,
1479 .total_sram_size = 8 * 1024,
1491 .controller_address = 0x400e0A00,
1492 .flash_wait_states = 6,
1494 .size_bytes = 32 * 1024,
1496 .sector_size = 16384,
1510 .chipid_cidr = 0x29380360,
1511 .name =
"at91sam3n0a",
1512 .total_flash_size = 32 * 1024,
1513 .total_sram_size = 8 * 1024,
1525 .controller_address = 0x400e0A00,
1526 .flash_wait_states = 6,
1528 .size_bytes = 32 * 1024,
1530 .sector_size = 16384,
1544 .chipid_cidr = 0x29450260,
1545 .name =
"at91sam3n00b",
1546 .total_flash_size = 16 * 1024,
1547 .total_sram_size = 4 * 1024,
1559 .controller_address = 0x400e0A00,
1560 .flash_wait_states = 6,
1562 .size_bytes = 16 * 1024,
1564 .sector_size = 16384,
1578 .chipid_cidr = 0x29350260,
1579 .name =
"at91sam3n00a",
1580 .total_flash_size = 16 * 1024,
1581 .total_sram_size = 4 * 1024,
1593 .controller_address = 0x400e0A00,
1594 .flash_wait_states = 6,
1596 .size_bytes = 16 * 1024,
1598 .sector_size = 16384,
1630 .chipid_cidr = 0x283E0A60,
1631 .name =
"at91sam3a8c",
1632 .total_flash_size = 512 * 1024,
1633 .total_sram_size = 96 * 1024,
1644 .controller_address = 0x400e0a00,
1645 .flash_wait_states = 6,
1647 .size_bytes = 256 * 1024,
1649 .sector_size = 16384,
1659 .controller_address = 0x400e0c00,
1660 .flash_wait_states = 6,
1662 .size_bytes = 256 * 1024,
1664 .sector_size = 16384,
1671 .chipid_cidr = 0x283B0960,
1672 .name =
"at91sam3a4c",
1673 .total_flash_size = 256 * 1024,
1674 .total_sram_size = 64 * 1024,
1685 .controller_address = 0x400e0a00,
1686 .flash_wait_states = 6,
1688 .size_bytes = 128 * 1024,
1690 .sector_size = 16384,
1700 .controller_address = 0x400e0c00,
1701 .flash_wait_states = 6,
1703 .size_bytes = 128 * 1024,
1705 .sector_size = 16384,
1730 .chipid_cidr = 0x286E0A20,
1731 .name =
"at91sam3x8h - ES",
1732 .total_flash_size = 512 * 1024,
1733 .total_sram_size = 96 * 1024,
1744 .controller_address = 0x400e0a00,
1745 .flash_wait_states = 6,
1747 .size_bytes = 256 * 1024,
1749 .sector_size = 16384,
1759 .controller_address = 0x400e0c00,
1760 .flash_wait_states = 6,
1762 .size_bytes = 256 * 1024,
1764 .sector_size = 16384,
1772 .chipid_cidr = 0x286E0A60,
1773 .name =
"at91sam3x8h",
1774 .total_flash_size = 512 * 1024,
1775 .total_sram_size = 96 * 1024,
1786 .controller_address = 0x400e0a00,
1787 .flash_wait_states = 6,
1789 .size_bytes = 256 * 1024,
1791 .sector_size = 16384,
1801 .controller_address = 0x400e0c00,
1802 .flash_wait_states = 6,
1804 .size_bytes = 256 * 1024,
1806 .sector_size = 16384,
1813 .chipid_cidr = 0x285E0A60,
1814 .name =
"at91sam3x8e",
1815 .total_flash_size = 512 * 1024,
1816 .total_sram_size = 96 * 1024,
1827 .controller_address = 0x400e0a00,
1828 .flash_wait_states = 6,
1830 .size_bytes = 256 * 1024,
1832 .sector_size = 16384,
1842 .controller_address = 0x400e0c00,
1843 .flash_wait_states = 6,
1845 .size_bytes = 256 * 1024,
1847 .sector_size = 16384,
1854 .chipid_cidr = 0x284E0A60,
1855 .name =
"at91sam3x8c",
1856 .total_flash_size = 512 * 1024,
1857 .total_sram_size = 96 * 1024,
1868 .controller_address = 0x400e0a00,
1869 .flash_wait_states = 6,
1871 .size_bytes = 256 * 1024,
1873 .sector_size = 16384,
1883 .controller_address = 0x400e0c00,
1884 .flash_wait_states = 6,
1886 .size_bytes = 256 * 1024,
1888 .sector_size = 16384,
1895 .chipid_cidr = 0x285B0960,
1896 .name =
"at91sam3x4e",
1897 .total_flash_size = 256 * 1024,
1898 .total_sram_size = 64 * 1024,
1909 .controller_address = 0x400e0a00,
1910 .flash_wait_states = 6,
1912 .size_bytes = 128 * 1024,
1914 .sector_size = 16384,
1924 .controller_address = 0x400e0c00,
1925 .flash_wait_states = 6,
1927 .size_bytes = 128 * 1024,
1929 .sector_size = 16384,
1936 .chipid_cidr = 0x284B0960,
1937 .name =
"at91sam3x4c",
1938 .total_flash_size = 256 * 1024,
1939 .total_sram_size = 64 * 1024,
1950 .controller_address = 0x400e0a00,
1951 .flash_wait_states = 6,
1953 .size_bytes = 128 * 1024,
1955 .sector_size = 16384,
1965 .controller_address = 0x400e0c00,
1966 .flash_wait_states = 6,
1968 .size_bytes = 128 * 1024,
1970 .sector_size = 16384,
2004 LOG_DEBUG(
"Status: 0x%08x (lockerror: %d, cmderror: %d, ready: %d)",
2006 ((
unsigned int)((*v >> 2) & 1)),
2007 ((
unsigned int)((*v >> 1) & 1)),
2008 ((
unsigned int)((*v >> 0) & 1)));
2027 LOG_DEBUG(
"Result: 0x%08x", ((
unsigned int)(rv)));
2032 unsigned int command,
unsigned int argument)
2052 n = (
private->size_bytes /
private->page_size);
2054 LOG_ERROR(
"*BUG*: Embedded flash has only %" PRIu32
" pages", n);
2059 if (argument >= private->chip->details.n_gpnvms) {
2060 LOG_ERROR(
"*BUG*: Embedded flash has only %d GPNVMs",
2061 private->chip->details.n_gpnvms);
2094 LOG_ERROR(
"flash controller(%d) is not ready! Error",
2095 private->bank_number);
2099 LOG_ERROR(
"Flash controller(%d) is not ready, attempting reset",
2100 private->bank_number);
2110 v = (0x5A << 24) | (argument << 8) |
command;
2111 LOG_DEBUG(
"Command: 0x%08x", ((
unsigned int)(v)));
2128 unsigned int argument,
2134 int64_t ms_now, ms_end;
2151 if (ms_now > ms_end) {
2156 }
while ((v & 1) == 0);
2176 private->chip->cfg.unique_id[0] = 0;
2177 private->chip->cfg.unique_id[1] = 0;
2178 private->chip->cfg.unique_id[2] = 0;
2179 private->chip->cfg.unique_id[3] = 0;
2186 for (x = 0; x < 4; x++) {
2188 private->bank->base + (x * 4),
2192 private->chip->cfg.unique_id[x] = v;
2196 LOG_DEBUG(
"End: R=%d, id = 0x%08x, 0x%08x, 0x%08x, 0x%08x",
2198 (
unsigned int)(private->chip->cfg.unique_id[0]),
2199 (
unsigned int)(private->chip->cfg.unique_id[1]),
2200 (
unsigned int)(private->chip->cfg.unique_id[2]),
2201 (
unsigned int)(private->chip->cfg.unique_id[3]));
2229 if (private->bank_number != 0) {
2230 LOG_ERROR(
"GPNVM only works with Bank0");
2234 if (
gpnvm >= private->chip->details.n_gpnvms) {
2235 LOG_ERROR(
"Invalid GPNVM %d, max: %d, ignored",
2236 gpnvm, private->chip->details.n_gpnvms);
2252 *puthere = (v >>
gpnvm) & 1;
2270 if (private->bank_number != 0) {
2271 LOG_ERROR(
"GPNVM only works with Bank0");
2275 if (
gpnvm >= private->chip->details.n_gpnvms) {
2276 LOG_ERROR(
"Invalid GPNVM %d, max: %d, ignored",
2277 gpnvm, private->chip->details.n_gpnvms);
2301 if (private->bank_number != 0) {
2302 LOG_ERROR(
"GPNVM only works with Bank0");
2306 if (
gpnvm >= private->chip->details.n_gpnvms) {
2307 LOG_ERROR(
"Invalid GPNVM %d, max: %d, ignored",
2308 gpnvm, private->chip->details.n_gpnvms);
2349 unsigned int start_sector,
2350 unsigned int end_sector)
2355 uint32_t pages_per_sector;
2357 pages_per_sector =
private->sector_size /
private->page_size;
2360 while (start_sector <= end_sector) {
2361 pg = start_sector * pages_per_sector;
2379 unsigned int start_sector,
2380 unsigned int end_sector)
2384 uint32_t pages_per_sector;
2387 pages_per_sector =
private->sector_size /
private->page_size;
2390 while (start_sector <= end_sector) {
2391 pg = start_sector * pages_per_sector;
2406 const char *regname,
2417 v = v & ((1 <<
width)-1);
2427 LOG_USER_N(
"\t%*s: %*" PRIu32
" [0x%0*" PRIx32
"] ",
2454 #define nvpsize2 nvpsize
2495 { 0x19,
"AT91SAM9xx Series" },
2496 { 0x29,
"AT91SAM9XExx Series" },
2497 { 0x34,
"AT91x34 Series" },
2498 { 0x37,
"CAP7 Series" },
2499 { 0x39,
"CAP9 Series" },
2500 { 0x3B,
"CAP11 Series" },
2501 { 0x40,
"AT91x40 Series" },
2502 { 0x42,
"AT91x42 Series" },
2503 { 0x55,
"AT91x55 Series" },
2504 { 0x60,
"AT91SAM7Axx Series" },
2505 { 0x61,
"AT91SAM7AQxx Series" },
2506 { 0x63,
"AT91x63 Series" },
2507 { 0x70,
"AT91SAM7Sxx Series" },
2508 { 0x71,
"AT91SAM7XCxx Series" },
2509 { 0x72,
"AT91SAM7SExx Series" },
2510 { 0x73,
"AT91SAM7Lxx Series" },
2511 { 0x75,
"AT91SAM7Xxx Series" },
2512 { 0x76,
"AT91SAM7SLxx Series" },
2513 { 0x80,
"ATSAM3UxC Series (100-pin version)" },
2514 { 0x81,
"ATSAM3UxE Series (144-pin version)" },
2515 { 0x83,
"ATSAM3AxC Series (100-pin version)" },
2516 { 0x84,
"ATSAM3XxC Series (100-pin version)" },
2517 { 0x85,
"ATSAM3XxE Series (144-pin version)" },
2518 { 0x86,
"ATSAM3XxG Series (208/217-pin version)" },
2519 { 0x88,
"ATSAM3SxA Series (48-pin version)" },
2520 { 0x89,
"ATSAM3SxB Series (64-pin version)" },
2521 { 0x8A,
"ATSAM3SxC Series (100-pin version)" },
2522 { 0x92,
"AT91x92 Series" },
2523 { 0x93,
"ATSAM3NxA Series (48-pin version)" },
2524 { 0x94,
"ATSAM3NxB Series (64-pin version)" },
2525 { 0x95,
"ATSAM3NxC Series (100-pin version)" },
2526 { 0x98,
"ATSAM3SDxA Series (48-pin version)" },
2527 { 0x99,
"ATSAM3SDxB Series (64-pin version)" },
2528 { 0x9A,
"ATSAM3SDxC Series (100-pin version)" },
2529 { 0xA5,
"ATSAM5A" },
2530 { 0xF0,
"AT75Cxx Series" },
2536 "romless or onchip flash",
2537 "embedded flash memory",
2538 "rom(nvpsiz) + embedded flash (nvpsiz2)",
2539 "sram emulating flash",
2554 "4 MHz",
"8 MHz",
"12 MHz",
"reserved"
2590 LOG_USER(
"(startup clks, time= %f uSecs)",
2591 ((
float)(v * 1000000)) / ((
float)(chip->
cfg.
slow_freq)));
2594 v ?
"external xtal" :
"internal RC");
2597 LOG_USER(
"(clock failure enabled: %s)",
2652 LOG_USER(
"(%3.03f Mhz (%" PRIu32
".%03" PRIu32
"khz slowclk)",
2660 uint32_t mula, diva;
2668 LOG_USER(
"\tPLLA Freq: (Disabled,mula = 0)");
2670 LOG_USER(
"\tPLLA Freq: (Disabled,diva = 0)");
2671 else if (diva >= 1) {
2673 LOG_USER(
"\tPLLA Freq: %3.03f MHz",
2680 uint32_t css, pres, fin = 0;
2682 const char *cp =
NULL;
2700 fin = 480 * 1000 * 1000;
2704 cp =
"upll (*ERROR* UPLL is disabled)";
2716 switch (pres & 0x07) {
2719 cp =
"selected clock";
2760 LOG_USER(
"\t\tResult CPU Freq: %3.03f",
2796 #define SAM3_ENTRY(NAME, FUNC) { .address = SAM3_ ## NAME, .struct_offset = offsetof( \
2798 NAME), # NAME, FUNC }
2825 return bank->driver_priv;
2843 possible = ((uint32_t *)(
void *)(((
char *)(&(chip->
cfg))) +
reg->struct_offset));
2846 if (possible == goes_here) {
2870 LOG_ERROR(
"Cannot read SAM3 register: %s @ 0x%08" PRIx32
", Err: %d",
2886 LOG_ERROR(
"Cannot read SAM3 register: %s @ 0x%08" PRIx32
", Error: %d",
2925 LOG_USER(
"%*s: [0x%08" PRIx32
"] -> 0x%08" PRIx32,
2930 if (
reg->explain_func)
2931 (*(
reg->explain_func))(chip);
2941 LOG_USER(
" UniqueId: 0x%08" PRIx32
" 0x%08" PRIx32
" 0x%08" PRIx32
" 0x%08" PRIx32,
2968 if (!(private->probed))
2977 for (x = 0; x <
private->nsectors; x++)
2978 bank->sectors[x].is_protected = (!!(v & (1 << x)));
2998 chip = calloc(1,
sizeof(
struct sam3_chip));
3013 switch (
bank->base) {
3015 LOG_ERROR(
"Address 0x%08x invalid bank address (try 0x%08x or 0x%08x "
3016 "[at91sam3u series] or 0x%08x [at91sam3s series] or "
3017 "0x%08x [at91sam3n series] or 0x%08x or 0x%08x or 0x%08x[at91sam3ax series] )",
3018 ((
unsigned int)(
bank->base)),
3033 bank->bank_number = 0;
3043 bank->bank_number = 1;
3078 while (details->
name) {
3080 if (((details->
chipid_cidr ^ private->chip->cfg.CHIPID_CIDR) & 0xFFFFFFE0) == 0)
3085 if (!details->
name) {
3086 LOG_ERROR(
"SAM3 ChipID 0x%08x not found in table (perhaps you can ID this chip?)",
3087 (
unsigned int)(private->chip->cfg.CHIPID_CIDR));
3089 LOG_INFO(
"SAM3 CHIPID_CIDR: 0x%08" PRIx32
" decodes as follows",
3090 private->chip->cfg.CHIPID_CIDR);
3099 chip =
private->chip;
3112 memcpy(&(private->chip->details),
3114 sizeof(private->chip->details));
3134 LOG_DEBUG(
"Begin: Bank: %u, Noise: %d",
bank->bank_number, noise);
3142 LOG_ERROR(
"Invalid/unknown bank number");
3151 if (private->chip->probed)
3160 if (
bank->base == private->chip->details.bank[x].base_address) {
3161 bank->size =
private->chip->details.bank[x].size_bytes;
3166 if (!
bank->sectors) {
3167 bank->sectors = calloc(private->nsectors, (
sizeof((
bank->sectors)[0])));
3168 if (!
bank->sectors) {
3172 bank->num_sectors =
private->nsectors;
3174 for (
unsigned int x = 0; x <
bank->num_sectors; x++) {
3175 bank->sectors[x].size =
private->sector_size;
3176 bank->sectors[x].offset = x * (
private->sector_size);
3178 bank->sectors[x].is_erased = -1;
3179 bank->sectors[x].is_protected = -1;
3183 private->probed =
true;
3190 private->bank_number, private->chip->details.n_banks);
3191 if ((private->bank_number + 1) == private->chip->details.n_banks) {
3229 if (!(private->probed))
3232 if ((first == 0) && ((last + 1) == private->nsectors)) {
3237 LOG_INFO(
"sam3 auto-erases while programming (request ignored)");
3254 if (!(private->probed))
3272 adr = pagenum *
private->page_size;
3273 adr +=
private->base_address;
3278 private->page_size / 4,
3281 LOG_ERROR(
"SAM3: Flash program failed to read page phys address: 0x%08x",
3282 (
unsigned int)(adr));
3293 adr = pagenum *
private->page_size;
3294 adr +=
private->base_address;
3297 r =
target_read_u32(private->chip->target, private->controller_address, &fmr);
3299 LOG_DEBUG(
"Error Read failed: read flash mode register");
3305 fmr |= (
private->flash_wait_states << 8);
3307 LOG_DEBUG(
"Flash Mode: 0x%08x", ((
unsigned int)(fmr)));
3308 r =
target_write_u32(private->bank->target, private->controller_address, fmr);
3310 LOG_DEBUG(
"Error Write failed: set flash mode register");
3312 LOG_DEBUG(
"Wr Page %u @ phys address: 0x%08x", pagenum, (
unsigned int)(adr));
3316 private->page_size / 4,
3319 LOG_ERROR(
"SAM3: Failed to write (buffer) page at phys address 0x%08x",
3320 (
unsigned int)(adr));
3331 LOG_ERROR(
"SAM3: Error performing Erase & Write page @ phys address 0x%08x",
3332 (
unsigned int)(adr));
3334 LOG_ERROR(
"SAM3: Page @ Phys address 0x%08x is locked", (
unsigned int)(adr));
3338 LOG_ERROR(
"SAM3: Flash Command error @phys address 0x%08x", (
unsigned int)(adr));
3350 unsigned int page_cur;
3351 unsigned int page_end;
3353 unsigned int page_offset;
3355 uint8_t *pagebuffer;
3373 if (!(private->probed)) {
3379 LOG_ERROR(
"Flash write error - past end of bank");
3380 LOG_ERROR(
" offset: 0x%08x, count 0x%08x, BankEnd: 0x%08x",
3382 (
unsigned int)(
count),
3383 (
unsigned int)(private->size_bytes));
3388 pagebuffer = malloc(private->page_size);
3390 LOG_ERROR(
"No memory for %d Byte page buffer", (
int)(private->page_size));
3396 page_cur =
offset /
private->page_size;
3397 page_end = (
offset +
count - 1) / private->page_size;
3400 LOG_DEBUG(
"Page start: %d, Page End: %d", (
int)(page_cur), (
int)(page_end));
3410 if (page_cur == page_end) {
3411 LOG_DEBUG(
"Special case, all in one page");
3416 page_offset = (
offset & (
private->page_size-1));
3417 memcpy(pagebuffer + page_offset,
3429 page_offset =
offset & (
private->page_size - 1);
3438 n = (
private->page_size - page_offset);
3439 memcpy(pagebuffer + page_offset,
3455 assert(
offset % private->page_size == 0);
3460 LOG_DEBUG(
"Full Page Loop: cur=%d, end=%d, count = 0x%08x",
3461 (
int)page_cur, (
int)page_end, (
unsigned int)(
count));
3463 while ((page_cur < page_end) &&
3464 (
count >= private->page_size)) {
3468 count -=
private->page_size;
3469 buffer +=
private->page_size;
3475 LOG_DEBUG(
"Terminal partial page, count = 0x%08x", (
unsigned int)(
count));
3508 "Please define bank %d via command: flash bank %s ... ",
3585 if ((strcmp(
CMD_ARGV[0],
"show") == 0) && (strcmp(
CMD_ARGV[1],
"all") == 0))
3595 if (strcmp(
"show",
CMD_ARGV[0]) == 0) {
3623 if (strcmp(
"set",
CMD_ARGV[0]) == 0)
3625 else if ((strcmp(
"clr",
CMD_ARGV[0]) == 0) ||
3626 (strcmp(
"clear",
CMD_ARGV[0]) == 0))
3674 .handler = sam3_handle_gpnvm_command,
3676 .usage =
"[('clr'|'set'|'show') bitnum]",
3677 .help =
"Without arguments, shows all bits in the gpnvm "
3678 "register. Otherwise, clears, sets, or shows one "
3679 "General Purpose Non-Volatile Memory (gpnvm) bit.",
3683 .handler = sam3_handle_info_command,
3685 .help =
"Print information about the current at91sam3 chip "
3686 "and its flash configuration.",
3691 .handler = sam3_handle_slowclk_command,
3693 .usage =
"[clock_hz]",
3694 .help =
"Display or set the slowclock frequency "
3695 "(default 32768 Hz).",
3703 .help =
"at91sam3 flash command group",
3713 .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.
#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