Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 | /* * Copyright (c) 2015-2016, Freescale Semiconductor, Inc. * Copyright 2016-2017 NXP * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * o Redistributions of source code must retain the above copyright notice, this list * of conditions and the following disclaimer. * * o Redistributions in binary form must reproduce the above copyright notice, this * list of conditions and the following disclaimer in the documentation and/or * other materials provided with the distribution. * * o Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived from this * software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "fsl_flash.h" /******************************************************************************* * Definitions ******************************************************************************/ /*! * @name Misc utility defines * @{ */ /*! @brief Alignment utility. */ #ifndef ALIGN_DOWN #define ALIGN_DOWN(x, a) ((x) & (uint32_t)(-((int32_t)(a)))) #endif #ifndef ALIGN_UP #define ALIGN_UP(x, a) (-((int32_t)((uint32_t)(-((int32_t)(x))) & (uint32_t)(-((int32_t)(a)))))) #endif /*! @brief Join bytes to word utility. */ #define B1P4(b) (((uint32_t)(b)&0xFFU) << 24) #define B1P3(b) (((uint32_t)(b)&0xFFU) << 16) #define B1P2(b) (((uint32_t)(b)&0xFFU) << 8) #define B1P1(b) ((uint32_t)(b)&0xFFU) #define B2P3(b) (((uint32_t)(b)&0xFFFFU) << 16) #define B2P2(b) (((uint32_t)(b)&0xFFFFU) << 8) #define B2P1(b) ((uint32_t)(b)&0xFFFFU) #define B3P2(b) (((uint32_t)(b)&0xFFFFFFU) << 8) #define B3P1(b) ((uint32_t)(b)&0xFFFFFFU) #define BYTES_JOIN_TO_WORD_1_3(x, y) (B1P4(x) | B3P1(y)) #define BYTES_JOIN_TO_WORD_2_2(x, y) (B2P3(x) | B2P1(y)) #define BYTES_JOIN_TO_WORD_3_1(x, y) (B3P2(x) | B1P1(y)) #define BYTES_JOIN_TO_WORD_1_1_2(x, y, z) (B1P4(x) | B1P3(y) | B2P1(z)) #define BYTES_JOIN_TO_WORD_1_2_1(x, y, z) (B1P4(x) | B2P2(y) | B1P1(z)) #define BYTES_JOIN_TO_WORD_2_1_1(x, y, z) (B2P3(x) | B1P2(y) | B1P1(z)) #define BYTES_JOIN_TO_WORD_1_1_1_1(x, y, z, w) (B1P4(x) | B1P3(y) | B1P2(z) | B1P1(w)) /*@}*/ /*! * @name Secondary flash configuration * @{ */ /*! @brief Indicates whether the secondary flash has its own protection register in flash module. */ #if defined(FSL_FEATURE_FLASH_HAS_MULTIPLE_FLASH) && defined(FTFE_FPROTS_PROTS_MASK) #define FLASH_SSD_SECONDARY_FLASH_HAS_ITS_OWN_PROTECTION_REGISTER (1) #else #define FLASH_SSD_SECONDARY_FLASH_HAS_ITS_OWN_PROTECTION_REGISTER (0) #endif /*! @brief Indicates whether the secondary flash has its own Execute-Only access register in flash module. */ #if defined(FSL_FEATURE_FLASH_HAS_MULTIPLE_FLASH) && defined(FTFE_FACSSS_SGSIZE_S_MASK) #define FLASH_SSD_SECONDARY_FLASH_HAS_ITS_OWN_ACCESS_REGISTER (1) #else #define FLASH_SSD_SECONDARY_FLASH_HAS_ITS_OWN_ACCESS_REGISTER (0) #endif /*@}*/ /*! * @name Flash cache ands speculation control defines * @{ */ #if defined(MCM_PLACR_CFCC_MASK) || defined(MCM_CPCR2_CCBC_MASK) #define FLASH_CACHE_IS_CONTROLLED_BY_MCM (1) #else #define FLASH_CACHE_IS_CONTROLLED_BY_MCM (0) #endif #if defined(FMC_PFB0CR_CINV_WAY_MASK) || defined(FMC_PFB01CR_CINV_WAY_MASK) #define FLASH_CACHE_IS_CONTROLLED_BY_FMC (1) #else #define FLASH_CACHE_IS_CONTROLLED_BY_FMC (0) #endif #if defined(MCM_PLACR_DFCS_MASK) #define FLASH_PREFETCH_SPECULATION_IS_CONTROLLED_BY_MCM (1) #else #define FLASH_PREFETCH_SPECULATION_IS_CONTROLLED_BY_MCM (0) #endif #if defined(MSCM_OCMDR_OCM1_MASK) || defined(MSCM_OCMDR_OCMC1_MASK) #define FLASH_PREFETCH_SPECULATION_IS_CONTROLLED_BY_MSCM (1) #else #define FLASH_PREFETCH_SPECULATION_IS_CONTROLLED_BY_MSCM (0) #endif #if defined(FMC_PFB0CR_S_INV_MASK) || defined(FMC_PFB0CR_S_B_INV_MASK) || defined(FMC_PFB01CR_S_INV_MASK) || \ defined(FMC_PFB01CR_S_B_INV_MASK) #define FLASH_PREFETCH_SPECULATION_IS_CONTROLLED_BY_FMC (1) #else #define FLASH_PREFETCH_SPECULATION_IS_CONTROLLED_BY_FMC (0) #endif /*@}*/ /*! @brief Data flash IFR map Field*/ #if defined(FSL_FEATURE_FLASH_IS_FTFE) && FSL_FEATURE_FLASH_IS_FTFE #define DFLASH_IFR_READRESOURCE_START_ADDRESS 0x8003F8U #else /* FSL_FEATURE_FLASH_IS_FTFL == 1 or FSL_FEATURE_FLASH_IS_FTFA = =1 */ #define DFLASH_IFR_READRESOURCE_START_ADDRESS 0x8000F8U #endif /*! * @name Reserved FlexNVM size (For a variety of purposes) defines * @{ */ #define FLEX_NVM_DFLASH_SIZE_FOR_DEPART_RESERVED 0xFFFFFFFFU #define FLEX_NVM_EEPROM_SIZE_FOR_EEESIZE_RESERVED 0xFFFFU /*@}*/ /*! * @name Flash Program Once Field defines * @{ */ #if defined(FSL_FEATURE_FLASH_IS_FTFA) && FSL_FEATURE_FLASH_IS_FTFA /* FTFA parts(eg. K80, KL80, L5K) support both 4-bytes and 8-bytes unit size */ #define FLASH_PROGRAM_ONCE_MIN_ID_8BYTES \ 0x10U /* Minimum Index indcating one of Progam Once Fields which is accessed in 8-byte records */ #define FLASH_PROGRAM_ONCE_MAX_ID_8BYTES \ 0x13U /* Maximum Index indcating one of Progam Once Fields which is accessed in 8-byte records */ #define FLASH_PROGRAM_ONCE_IS_4BYTES_UNIT_SUPPORT 1 #define FLASH_PROGRAM_ONCE_IS_8BYTES_UNIT_SUPPORT 1 #elif defined(FSL_FEATURE_FLASH_IS_FTFE) && FSL_FEATURE_FLASH_IS_FTFE /* FTFE parts(eg. K65, KE18) only support 8-bytes unit size */ #define FLASH_PROGRAM_ONCE_IS_4BYTES_UNIT_SUPPORT 0 #define FLASH_PROGRAM_ONCE_IS_8BYTES_UNIT_SUPPORT 1 #elif defined(FSL_FEATURE_FLASH_IS_FTFL) && FSL_FEATURE_FLASH_IS_FTFL /* FTFL parts(eg. K20) only support 4-bytes unit size */ #define FLASH_PROGRAM_ONCE_IS_4BYTES_UNIT_SUPPORT 1 #define FLASH_PROGRAM_ONCE_IS_8BYTES_UNIT_SUPPORT 0 #endif /*@}*/ /*! * @name Flash security status defines * @{ */ #define FLASH_SECURITY_STATE_KEYEN 0x80U #define FLASH_SECURITY_STATE_UNSECURED 0x02U #define FLASH_NOT_SECURE 0x01U #define FLASH_SECURE_BACKDOOR_ENABLED 0x02U #define FLASH_SECURE_BACKDOOR_DISABLED 0x04U /*@}*/ /*! * @name Flash controller command numbers * @{ */ #define FTFx_VERIFY_BLOCK 0x00U /*!< RD1BLK*/ #define FTFx_VERIFY_SECTION 0x01U /*!< RD1SEC*/ #define FTFx_PROGRAM_CHECK 0x02U /*!< PGMCHK*/ #define FTFx_READ_RESOURCE 0x03U /*!< RDRSRC*/ #define FTFx_PROGRAM_LONGWORD 0x06U /*!< PGM4*/ #define FTFx_PROGRAM_PHRASE 0x07U /*!< PGM8*/ #define FTFx_ERASE_BLOCK 0x08U /*!< ERSBLK*/ #define FTFx_ERASE_SECTOR 0x09U /*!< ERSSCR*/ #define FTFx_PROGRAM_SECTION 0x0BU /*!< PGMSEC*/ #define FTFx_GENERATE_CRC 0x0CU /*!< CRCGEN*/ #define FTFx_VERIFY_ALL_BLOCK 0x40U /*!< RD1ALL*/ #define FTFx_READ_ONCE 0x41U /*!< RDONCE or RDINDEX*/ #define FTFx_PROGRAM_ONCE 0x43U /*!< PGMONCE or PGMINDEX*/ #define FTFx_ERASE_ALL_BLOCK 0x44U /*!< ERSALL*/ #define FTFx_SECURITY_BY_PASS 0x45U /*!< VFYKEY*/ #define FTFx_SWAP_CONTROL 0x46U /*!< SWAP*/ #define FTFx_ERASE_ALL_BLOCK_UNSECURE 0x49U /*!< ERSALLU*/ #define FTFx_VERIFY_ALL_EXECUTE_ONLY_SEGMENT 0x4AU /*!< RD1XA*/ #define FTFx_ERASE_ALL_EXECUTE_ONLY_SEGMENT 0x4BU /*!< ERSXA*/ #define FTFx_PROGRAM_PARTITION 0x80U /*!< PGMPART)*/ #define FTFx_SET_FLEXRAM_FUNCTION 0x81U /*!< SETRAM*/ /*@}*/ /*! * @name Common flash register info defines * @{ */ #if defined(FTFA) #define FTFx FTFA #define FTFx_BASE FTFA_BASE #define FTFx_FSTAT_CCIF_MASK FTFA_FSTAT_CCIF_MASK #define FTFx_FSTAT_RDCOLERR_MASK FTFA_FSTAT_RDCOLERR_MASK #define FTFx_FSTAT_ACCERR_MASK FTFA_FSTAT_ACCERR_MASK #define FTFx_FSTAT_FPVIOL_MASK FTFA_FSTAT_FPVIOL_MASK #define FTFx_FSTAT_MGSTAT0_MASK FTFA_FSTAT_MGSTAT0_MASK #define FTFx_FSEC_SEC_MASK FTFA_FSEC_SEC_MASK #define FTFx_FSEC_KEYEN_MASK FTFA_FSEC_KEYEN_MASK #if defined(FSL_FEATURE_FLASH_HAS_FLEX_RAM) && FSL_FEATURE_FLASH_HAS_FLEX_RAM #define FTFx_FCNFG_RAMRDY_MASK FTFA_FCNFG_RAMRDY_MASK #endif /* FSL_FEATURE_FLASH_HAS_FLEX_RAM */ #if defined(FSL_FEATURE_FLASH_HAS_FLEX_NVM) && FSL_FEATURE_FLASH_HAS_FLEX_NVM #define FTFx_FCNFG_EEERDY_MASK FTFA_FCNFG_EEERDY_MASK #endif /* FSL_FEATURE_FLASH_HAS_FLEX_NVM */ #elif defined(FTFE) #define FTFx FTFE #define FTFx_BASE FTFE_BASE #define FTFx_FSTAT_CCIF_MASK FTFE_FSTAT_CCIF_MASK #define FTFx_FSTAT_RDCOLERR_MASK FTFE_FSTAT_RDCOLERR_MASK #define FTFx_FSTAT_ACCERR_MASK FTFE_FSTAT_ACCERR_MASK #define FTFx_FSTAT_FPVIOL_MASK FTFE_FSTAT_FPVIOL_MASK #define FTFx_FSTAT_MGSTAT0_MASK FTFE_FSTAT_MGSTAT0_MASK #define FTFx_FSEC_SEC_MASK FTFE_FSEC_SEC_MASK #define FTFx_FSEC_KEYEN_MASK FTFE_FSEC_KEYEN_MASK #if defined(FSL_FEATURE_FLASH_HAS_FLEX_RAM) && FSL_FEATURE_FLASH_HAS_FLEX_RAM #define FTFx_FCNFG_RAMRDY_MASK FTFE_FCNFG_RAMRDY_MASK #endif /* FSL_FEATURE_FLASH_HAS_FLEX_RAM */ #if defined(FSL_FEATURE_FLASH_HAS_FLEX_NVM) && FSL_FEATURE_FLASH_HAS_FLEX_NVM #define FTFx_FCNFG_EEERDY_MASK FTFE_FCNFG_EEERDY_MASK #endif /* FSL_FEATURE_FLASH_HAS_FLEX_NVM */ #elif defined(FTFL) #define FTFx FTFL #define FTFx_BASE FTFL_BASE #define FTFx_FSTAT_CCIF_MASK FTFL_FSTAT_CCIF_MASK #define FTFx_FSTAT_RDCOLERR_MASK FTFL_FSTAT_RDCOLERR_MASK #define FTFx_FSTAT_ACCERR_MASK FTFL_FSTAT_ACCERR_MASK #define FTFx_FSTAT_FPVIOL_MASK FTFL_FSTAT_FPVIOL_MASK #define FTFx_FSTAT_MGSTAT0_MASK FTFL_FSTAT_MGSTAT0_MASK #define FTFx_FSEC_SEC_MASK FTFL_FSEC_SEC_MASK #define FTFx_FSEC_KEYEN_MASK FTFL_FSEC_KEYEN_MASK #if defined(FSL_FEATURE_FLASH_HAS_FLEX_RAM) && FSL_FEATURE_FLASH_HAS_FLEX_RAM #define FTFx_FCNFG_RAMRDY_MASK FTFL_FCNFG_RAMRDY_MASK #endif /* FSL_FEATURE_FLASH_HAS_FLEX_RAM */ #if defined(FSL_FEATURE_FLASH_HAS_FLEX_NVM) && FSL_FEATURE_FLASH_HAS_FLEX_NVM #define FTFx_FCNFG_EEERDY_MASK FTFL_FCNFG_EEERDY_MASK #endif /* FSL_FEATURE_FLASH_HAS_FLEX_NVM */ #else #error "Unknown flash controller" #endif /*@}*/ /*! * @name Common flash register access info defines * @{ */ #define FTFx_FCCOB3_REG (FTFx->FCCOB3) #define FTFx_FCCOB5_REG (FTFx->FCCOB5) #define FTFx_FCCOB6_REG (FTFx->FCCOB6) #define FTFx_FCCOB7_REG (FTFx->FCCOB7) #if defined(FTFA_FPROTH0_PROT_MASK) || defined(FTFE_FPROTH0_PROT_MASK) || defined(FTFL_FPROTH0_PROT_MASK) #define FTFx_FPROT_HIGH_REG (FTFx->FPROTH3) #define FTFx_FPROTH3_REG (FTFx->FPROTH3) #define FTFx_FPROTH2_REG (FTFx->FPROTH2) #define FTFx_FPROTH1_REG (FTFx->FPROTH1) #define FTFx_FPROTH0_REG (FTFx->FPROTH0) #endif #if defined(FTFA_FPROTL0_PROT_MASK) || defined(FTFE_FPROTL0_PROT_MASK) || defined(FTFL_FPROTL0_PROT_MASK) #define FTFx_FPROT_LOW_REG (FTFx->FPROTL3) #define FTFx_FPROTL3_REG (FTFx->FPROTL3) #define FTFx_FPROTL2_REG (FTFx->FPROTL2) #define FTFx_FPROTL1_REG (FTFx->FPROTL1) #define FTFx_FPROTL0_REG (FTFx->FPROTL0) #elif defined(FTFA_FPROT0_PROT_MASK) || defined(FTFE_FPROT0_PROT_MASK) || defined(FTFL_FPROT0_PROT_MASK) #define FTFx_FPROT_LOW_REG (FTFx->FPROT3) #define FTFx_FPROTL3_REG (FTFx->FPROT3) #define FTFx_FPROTL2_REG (FTFx->FPROT2) #define FTFx_FPROTL1_REG (FTFx->FPROT1) #define FTFx_FPROTL0_REG (FTFx->FPROT0) #endif #if FLASH_SSD_IS_SECONDARY_FLASH_ENABLED && FLASH_SSD_SECONDARY_FLASH_HAS_ITS_OWN_PROTECTION_REGISTER #define FTFx_FPROTSH_REG (FTFx->FPROTSH) #define FTFx_FPROTSL_REG (FTFx->FPROTSL) #endif #define FTFx_XACCH3_REG (FTFx->XACCH3) #define FTFx_XACCL3_REG (FTFx->XACCL3) #if FLASH_SSD_IS_SECONDARY_FLASH_ENABLED && FLASH_SSD_SECONDARY_FLASH_HAS_ITS_OWN_ACCESS_REGISTER #define FTFx_XACCSH_REG (FTFx->XACCSH) #define FTFx_XACCSL_REG (FTFx->XACCSL) #endif /*@}*/ /*! * @brief Enumeration for access segment property. */ enum _flash_access_segment_property { kFLASH_AccessSegmentBase = 256UL, }; /*! * @brief Enumeration for flash config area. */ enum _flash_config_area_range { kFLASH_ConfigAreaStart = 0x400U, kFLASH_ConfigAreaEnd = 0x40FU }; /*! * @name Flash register access type defines * @{ */ #define FTFx_REG8_ACCESS_TYPE volatile uint8_t * #define FTFx_REG32_ACCESS_TYPE volatile uint32_t * /*@}*/ /*! * @brief MCM cache register access info defines. */ #if defined(MCM_PLACR_CFCC_MASK) #define MCM_CACHE_CLEAR_MASK MCM_PLACR_CFCC_MASK #define MCM_CACHE_CLEAR_SHIFT MCM_PLACR_CFCC_SHIFT #if defined(MCM) #define MCM0_CACHE_REG MCM->PLACR #elif defined(MCM0) #define MCM0_CACHE_REG MCM0->PLACR #endif #if defined(MCM1) #define MCM1_CACHE_REG MCM1->PLACR #endif #elif defined(MCM_CPCR2_CCBC_MASK) #define MCM_CACHE_CLEAR_MASK MCM_CPCR2_CCBC_MASK #define MCM_CACHE_CLEAR_SHIFT MCM_CPCR2_CCBC_SHIFT #if defined(MCM) #define MCM0_CACHE_REG MCM->CPCR2 #elif defined(MCM0) #define MCM0_CACHE_REG MCM0->CPCR2 #endif #if defined(MCM1) #define MCM1_CACHE_REG MCM1->CPCR2 #endif #endif /*! * @brief MSCM cache register access info defines. */ #if defined(MSCM_OCMDR_OCM1_MASK) #define MSCM_SPECULATION_DISABLE_MASK MSCM_OCMDR_OCM1_MASK #define MSCM_SPECULATION_DISABLE_SHIFT MSCM_OCMDR_OCM1_SHIFT #define MSCM_SPECULATION_DISABLE(x) MSCM_OCMDR_OCM1(x) #elif defined(MSCM_OCMDR_OCMC1_MASK) #define MSCM_SPECULATION_DISABLE_MASK MSCM_OCMDR_OCMC1_MASK #define MSCM_SPECULATION_DISABLE_SHIFT MSCM_OCMDR_OCMC1_SHIFT #define MSCM_SPECULATION_DISABLE(x) MSCM_OCMDR_OCMC1(x) #endif /*! * @brief MSCM prefetch speculation defines. */ #define MSCM_OCMDR_OCMC1_DFDS_MASK (0x10U) #define MSCM_OCMDR_OCMC1_DFCS_MASK (0x20U) #define MSCM_OCMDR_OCMC1_DFDS_SHIFT (4U) #define MSCM_OCMDR_OCMC1_DFCS_SHIFT (5U) /*! * @brief Flash size encoding rule. */ #define FLASH_MEMORY_SIZE_ENCODING_RULE_K1_2 (0x00U) #define FLASH_MEMORY_SIZE_ENCODING_RULE_K3 (0x01U) #if defined(K32W042S1M2_M0P_SERIES) || defined(K32W042S1M2_M4_SERIES) #define FLASH_MEMORY_SIZE_ENCODING_RULE (FLASH_MEMORY_SIZE_ENCODING_RULE_K3) #else #define FLASH_MEMORY_SIZE_ENCODING_RULE (FLASH_MEMORY_SIZE_ENCODING_RULE_K1_2) #endif /******************************************************************************* * Prototypes ******************************************************************************/ #if FLASH_DRIVER_IS_FLASH_RESIDENT /*! @brief Copy flash_run_command() to RAM*/ static void copy_flash_run_command(uint32_t *flashRunCommand); /*! @brief Copy flash_cache_clear_command() to RAM*/ static void copy_flash_common_bit_operation(uint32_t *flashCommonBitOperation); /*! @brief Check whether flash execute-in-ram functions are ready*/ static status_t flash_check_execute_in_ram_function_info(flash_config_t *config); #endif /* FLASH_DRIVER_IS_FLASH_RESIDENT */ /*! @brief Internal function Flash command sequence. Called by driver APIs only*/ static status_t flash_command_sequence(flash_config_t *config); /*! @brief Perform the cache clear to the flash*/ void flash_cache_clear(flash_config_t *config); /*! @brief Process the cache to the flash*/ static void flash_cache_clear_process(flash_config_t *config, flash_cache_clear_process_t process); /*! @brief Validates the range and alignment of the given address range.*/ static status_t flash_check_range(flash_config_t *config, uint32_t startAddress, uint32_t lengthInBytes, uint32_t alignmentBaseline); /*! @brief Gets the right address, sector and block size of current flash type which is indicated by address.*/ static status_t flash_get_matched_operation_info(flash_config_t *config, uint32_t address, flash_operation_config_t *info); /*! @brief Validates the given user key for flash erase APIs.*/ static status_t flash_check_user_key(uint32_t key); #if FLASH_SSD_IS_FLEXNVM_ENABLED /*! @brief Updates FlexNVM memory partition status according to data flash 0 IFR.*/ static status_t flash_update_flexnvm_memory_partition_status(flash_config_t *config); #endif /* FLASH_SSD_IS_FLEXNVM_ENABLED */ #if defined(FSL_FEATURE_FLASH_HAS_READ_RESOURCE_CMD) && FSL_FEATURE_FLASH_HAS_READ_RESOURCE_CMD /*! @brief Validates the range of the given resource address.*/ static status_t flash_check_resource_range(uint32_t start, uint32_t lengthInBytes, uint32_t alignmentBaseline, flash_read_resource_option_t option); #endif /* FSL_FEATURE_FLASH_HAS_READ_RESOURCE_CMD */ #if defined(FSL_FEATURE_FLASH_HAS_SWAP_CONTROL_CMD) && FSL_FEATURE_FLASH_HAS_SWAP_CONTROL_CMD /*! @brief Validates the gived swap control option.*/ static status_t flash_check_swap_control_option(flash_swap_control_option_t option); #endif /* FSL_FEATURE_FLASH_HAS_SWAP_CONTROL_CMD */ #if defined(FSL_FEATURE_FLASH_HAS_PFLASH_BLOCK_SWAP) && FSL_FEATURE_FLASH_HAS_PFLASH_BLOCK_SWAP /*! @brief Validates the gived address to see if it is equal to swap indicator address in pflash swap IFR.*/ static status_t flash_validate_swap_indicator_address(flash_config_t *config, uint32_t address); #endif /* FSL_FEATURE_FLASH_HAS_PFLASH_BLOCK_SWAP */ #if defined(FSL_FEATURE_FLASH_HAS_SET_FLEXRAM_FUNCTION_CMD) && FSL_FEATURE_FLASH_HAS_SET_FLEXRAM_FUNCTION_CMD /*! @brief Validates the gived flexram function option.*/ static inline status_t flasn_check_flexram_function_option_range(flash_flexram_function_option_t option); #endif /* FSL_FEATURE_FLASH_HAS_SET_FLEXRAM_FUNCTION_CMD */ /*! @brief Gets the flash protection information (region size, region count).*/ static status_t flash_get_protection_info(flash_config_t *config, flash_protection_config_t *info); #if defined(FSL_FEATURE_FLASH_HAS_ACCESS_CONTROL) && FSL_FEATURE_FLASH_HAS_ACCESS_CONTROL /*! @brief Gets the flash Execute-Only access information (Segment size, Segment count).*/ static status_t flash_get_access_info(flash_config_t *config, flash_access_config_t *info); #endif /* FSL_FEATURE_FLASH_HAS_ACCESS_CONTROL */ #if FLASH_CACHE_IS_CONTROLLED_BY_MCM /*! @brief Performs the cache clear to the flash by MCM.*/ void mcm_flash_cache_clear(flash_config_t *config); #endif /* FLASH_CACHE_IS_CONTROLLED_BY_MCM */ #if FLASH_CACHE_IS_CONTROLLED_BY_FMC /*! @brief Performs the cache clear to the flash by FMC.*/ void fmc_flash_cache_clear(void); #endif /* FLASH_CACHE_IS_CONTROLLED_BY_FMC */ #if FLASH_PREFETCH_SPECULATION_IS_CONTROLLED_BY_MSCM /*! @brief Sets the prefetch speculation buffer to the flash by MSCM.*/ void mscm_flash_prefetch_speculation_enable(bool enable); #endif /* FLASH_PREFETCH_SPECULATION_IS_CONTROLLED_BY_MSCM */ #if FLASH_PREFETCH_SPECULATION_IS_CONTROLLED_BY_FMC /*! @brief Performs the prefetch speculation buffer clear to the flash by FMC.*/ void fmc_flash_prefetch_speculation_clear(void); #endif /* FLASH_PREFETCH_SPECULATION_IS_CONTROLLED_BY_FMC */ /******************************************************************************* * Variables ******************************************************************************/ /*! @brief Access to FTFx->FCCOB */ volatile uint32_t *const kFCCOBx = (volatile uint32_t *)&FTFx_FCCOB3_REG; /*! @brief Access to FTFx->FPROT */ volatile uint32_t *const kFPROTL = (volatile uint32_t *)&FTFx_FPROT_LOW_REG; #if defined(FTFx_FPROT_HIGH_REG) volatile uint32_t *const kFPROTH = (volatile uint32_t *)&FTFx_FPROT_HIGH_REG; #endif #if FLASH_SSD_IS_SECONDARY_FLASH_ENABLED && FLASH_SSD_SECONDARY_FLASH_HAS_ITS_OWN_PROTECTION_REGISTER volatile uint8_t *const kFPROTSL = (volatile uint8_t *)&FTFx_FPROTSL_REG; volatile uint8_t *const kFPROTSH = (volatile uint8_t *)&FTFx_FPROTSH_REG; #endif #if FLASH_DRIVER_IS_FLASH_RESIDENT /*! @brief A function pointer used to point to relocated flash_run_command() */ static void (*callFlashRunCommand)(FTFx_REG8_ACCESS_TYPE ftfx_fstat); /*! @brief A function pointer used to point to relocated flash_common_bit_operation() */ static void (*callFlashCommonBitOperation)(FTFx_REG32_ACCESS_TYPE base, uint32_t bitMask, uint32_t bitShift, uint32_t bitValue); /*! * @brief Position independent code of flash_run_command() * * Note1: The prototype of C function is shown as below: * @code * void flash_run_command(FTFx_REG8_ACCESS_TYPE ftfx_fstat) * { * // clear CCIF bit * *ftfx_fstat = FTFx_FSTAT_CCIF_MASK; * * // Check CCIF bit of the flash status register, wait till it is set. * // IP team indicates that this loop will always complete. * while (!((*ftfx_fstat) & FTFx_FSTAT_CCIF_MASK)) * { * } * } * @endcode * Note2: The binary code is generated by IAR 7.70.1 */ const static uint16_t s_flashRunCommandFunctionCode[] = { 0x2180, /* MOVS R1, #128 ; 0x80 */ 0x7001, /* STRB R1, [R0] */ /* @4: */ 0x7802, /* LDRB R2, [R0] */ 0x420a, /* TST R2, R1 */ 0xd0fc, /* BEQ.N @4 */ 0x4770 /* BX LR */ }; /*! * @brief Position independent code of flash_common_bit_operation() * * Note1: The prototype of C function is shown as below: * @code * void flash_common_bit_operation(FTFx_REG32_ACCESS_TYPE base, uint32_t bitMask, uint32_t bitShift, uint32_t * bitValue) * { * if (bitMask) * { * uint32_t value = (((uint32_t)(((uint32_t)(bitValue)) << bitShift)) & bitMask); * *base = (*base & (~bitMask)) | value; * } * * __ISB(); * __DSB(); * } * @endcode * Note2: The binary code is generated by IAR 7.70.1 */ const static uint16_t s_flashCommonBitOperationFunctionCode[] = { 0xb510, /* PUSH {R4, LR} */ 0x2900, /* CMP R1, #0 */ 0xd005, /* BEQ.N @12 */ 0x6804, /* LDR R4, [R0] */ 0x438c, /* BICS R4, R4, R1 */ 0x4093, /* LSLS R3, R3, R2 */ 0x4019, /* ANDS R1, R1, R3 */ 0x4321, /* ORRS R1, R1, R4 */ 0x6001, /* STR R1, [R0] */ /* @12: */ 0xf3bf, 0x8f6f, /* ISB */ 0xf3bf, 0x8f4f, /* DSB */ 0xbd10 /* POP {R4, PC} */ }; #endif /* FLASH_DRIVER_IS_FLASH_RESIDENT */ #if (FLASH_DRIVER_IS_FLASH_RESIDENT && !FLASH_DRIVER_IS_EXPORTED) /*! @brief A static buffer used to hold flash_run_command() */ static uint32_t s_flashRunCommand[kFLASH_ExecuteInRamFunctionMaxSizeInWords]; /*! @brief A static buffer used to hold flash_common_bit_operation() */ static uint32_t s_flashCommonBitOperation[kFLASH_ExecuteInRamFunctionMaxSizeInWords]; /*! @brief Flash execute-in-ram function information */ static flash_execute_in_ram_function_config_t s_flashExecuteInRamFunctionInfo; #endif /*! * @brief Table of pflash sizes. * * The index into this table is the value of the SIM_FCFG1.PFSIZE bitfield. * * The values in this table have been right shifted 10 bits so that they will all fit within * an 16-bit integer. To get the actual flash density, you must left shift the looked up value * by 10 bits. * * Elements of this table have a value of 0 in cases where the PFSIZE bitfield value is * reserved. * * Code to use the table: * @code * uint8_t pfsize = (SIM->FCFG1 & SIM_FCFG1_PFSIZE_MASK) >> SIM_FCFG1_PFSIZE_SHIFT; * flashDensity = ((uint32_t)kPFlashDensities[pfsize]) << 10; * @endcode */ #if (FLASH_MEMORY_SIZE_ENCODING_RULE == FLASH_MEMORY_SIZE_ENCODING_RULE_K1_2) const uint16_t kPFlashDensities[] = { 8, /* 0x0 - 8192, 8KB */ 16, /* 0x1 - 16384, 16KB */ 24, /* 0x2 - 24576, 24KB */ 32, /* 0x3 - 32768, 32KB */ 48, /* 0x4 - 49152, 48KB */ 64, /* 0x5 - 65536, 64KB */ 96, /* 0x6 - 98304, 96KB */ 128, /* 0x7 - 131072, 128KB */ 192, /* 0x8 - 196608, 192KB */ 256, /* 0x9 - 262144, 256KB */ 384, /* 0xa - 393216, 384KB */ 512, /* 0xb - 524288, 512KB */ 768, /* 0xc - 786432, 768KB */ 1024, /* 0xd - 1048576, 1MB */ 1536, /* 0xe - 1572864, 1.5MB */ /* 2048, 0xf - 2097152, 2MB */ }; #elif(FLASH_MEMORY_SIZE_ENCODING_RULE == FLASH_MEMORY_SIZE_ENCODING_RULE_K3) const uint16_t kPFlashDensities[] = { 0, /* 0x0 - undefined */ 0, /* 0x1 - undefined */ 0, /* 0x2 - undefined */ 0, /* 0x3 - undefined */ 0, /* 0x4 - undefined */ 0, /* 0x5 - undefined */ 0, /* 0x6 - undefined */ 0, /* 0x7 - undefined */ 0, /* 0x8 - undefined */ 0, /* 0x9 - undefined */ 256, /* 0xa - 262144, 256KB */ 0, /* 0xb - undefined */ 1024, /* 0xc - 1048576, 1MB */ 0, /* 0xd - undefined */ 0, /* 0xe - undefined */ 0, /* 0xf - undefined */ }; #endif /******************************************************************************* * Code ******************************************************************************/ status_t FLASH_Init(flash_config_t *config) { if (config == NULL) { return kStatus_FLASH_InvalidArgument; } #if FLASH_SSD_IS_SECONDARY_FLASH_ENABLED if (config->FlashMemoryIndex == (uint8_t)kFLASH_MemoryIndexSecondaryFlash) { /* calculate the flash density from SIM_FCFG1.PFSIZE */ #if defined(SIM_FCFG1_CORE1_PFSIZE_MASK) uint32_t flashDensity; uint8_t pfsize = (SIM->FCFG1 & SIM_FCFG1_CORE1_PFSIZE_MASK) >> SIM_FCFG1_CORE1_PFSIZE_SHIFT; if (pfsize == 0xf) { flashDensity = FSL_FEATURE_FLASH_PFLASH_1_BLOCK_COUNT * FSL_FEATURE_FLASH_PFLASH_1_BLOCK_SIZE; } else { flashDensity = ((uint32_t)kPFlashDensities[pfsize]) << 10; } config->PFlashTotalSize = flashDensity; #else /* Unused code to solve MISRA-C issue*/ config->PFlashBlockBase = kPFlashDensities[0]; config->PFlashTotalSize = FSL_FEATURE_FLASH_PFLASH_1_BLOCK_COUNT * FSL_FEATURE_FLASH_PFLASH_1_BLOCK_SIZE; #endif config->PFlashBlockBase = FSL_FEATURE_FLASH_PFLASH_1_START_ADDRESS; config->PFlashBlockCount = FSL_FEATURE_FLASH_PFLASH_1_BLOCK_COUNT; config->PFlashSectorSize = FSL_FEATURE_FLASH_PFLASH_1_BLOCK_SECTOR_SIZE; } else #endif /* FLASH_SSD_IS_SECONDARY_FLASH_ENABLED */ { uint32_t flashDensity; /* calculate the flash density from SIM_FCFG1.PFSIZE */ #if defined(SIM_FCFG1_CORE0_PFSIZE_MASK) uint8_t pfsize = (SIM->FCFG1 & SIM_FCFG1_CORE0_PFSIZE_MASK) >> SIM_FCFG1_CORE0_PFSIZE_SHIFT; #elif defined(SIM_FCFG1_PFSIZE_MASK) uint8_t pfsize = (SIM->FCFG1 & SIM_FCFG1_PFSIZE_MASK) >> SIM_FCFG1_PFSIZE_SHIFT; #else #error "Unknown flash size" #endif /* PFSIZE=0xf means that on customer parts the IFR was not correctly programmed. * We just use the pre-defined flash size in feature file here to support pre-production parts */ if (pfsize == 0xf) { flashDensity = FSL_FEATURE_FLASH_PFLASH_BLOCK_COUNT * FSL_FEATURE_FLASH_PFLASH_BLOCK_SIZE; } else { flashDensity = ((uint32_t)kPFlashDensities[pfsize]) << 10; } /* fill out a few of the structure members */ config->PFlashBlockBase = FSL_FEATURE_FLASH_PFLASH_START_ADDRESS; config->PFlashTotalSize = flashDensity; config->PFlashBlockCount = FSL_FEATURE_FLASH_PFLASH_BLOCK_COUNT; config->PFlashSectorSize = FSL_FEATURE_FLASH_PFLASH_BLOCK_SECTOR_SIZE; } { #if defined(FSL_FEATURE_FLASH_HAS_ACCESS_CONTROL) && FSL_FEATURE_FLASH_HAS_ACCESS_CONTROL #if FLASH_SSD_IS_SECONDARY_FLASH_ENABLED && FLASH_SSD_SECONDARY_FLASH_HAS_ITS_OWN_ACCESS_REGISTER if (config->FlashMemoryIndex == (uint8_t)kFLASH_MemoryIndexSecondaryFlash) { config->PFlashAccessSegmentSize = kFLASH_AccessSegmentBase << FTFx->FACSSS; config->PFlashAccessSegmentCount = FTFx->FACSNS; } else #endif { config->PFlashAccessSegmentSize = kFLASH_AccessSegmentBase << FTFx->FACSS; config->PFlashAccessSegmentCount = FTFx->FACSN; } #else config->PFlashAccessSegmentSize = 0; config->PFlashAccessSegmentCount = 0; #endif /* FSL_FEATURE_FLASH_HAS_ACCESS_CONTROL */ } config->PFlashCallback = NULL; /* copy required flash commands to RAM */ #if (FLASH_DRIVER_IS_FLASH_RESIDENT && !FLASH_DRIVER_IS_EXPORTED) if (kStatus_FLASH_Success != flash_check_execute_in_ram_function_info(config)) { s_flashExecuteInRamFunctionInfo.activeFunctionCount = 0; s_flashExecuteInRamFunctionInfo.flashRunCommand = s_flashRunCommand; s_flashExecuteInRamFunctionInfo.flashCommonBitOperation = s_flashCommonBitOperation; config->flashExecuteInRamFunctionInfo = &s_flashExecuteInRamFunctionInfo.activeFunctionCount; FLASH_PrepareExecuteInRamFunctions(config); } #endif config->FlexRAMBlockBase = FSL_FEATURE_FLASH_FLEX_RAM_START_ADDRESS; config->FlexRAMTotalSize = FSL_FEATURE_FLASH_FLEX_RAM_SIZE; #if FLASH_SSD_IS_FLEXNVM_ENABLED { status_t returnCode; config->DFlashBlockBase = FSL_FEATURE_FLASH_FLEX_NVM_START_ADDRESS; returnCode = flash_update_flexnvm_memory_partition_status(config); if (returnCode != kStatus_FLASH_Success) { return returnCode; } } #endif return kStatus_FLASH_Success; } status_t FLASH_SetCallback(flash_config_t *config, flash_callback_t callback) { if (config == NULL) { return kStatus_FLASH_InvalidArgument; } config->PFlashCallback = callback; return kStatus_FLASH_Success; } #if FLASH_DRIVER_IS_FLASH_RESIDENT status_t FLASH_PrepareExecuteInRamFunctions(flash_config_t *config) { flash_execute_in_ram_function_config_t *flashExecuteInRamFunctionInfo; if (config == NULL) { return kStatus_FLASH_InvalidArgument; } flashExecuteInRamFunctionInfo = (flash_execute_in_ram_function_config_t *)config->flashExecuteInRamFunctionInfo; copy_flash_run_command(flashExecuteInRamFunctionInfo->flashRunCommand); copy_flash_common_bit_operation(flashExecuteInRamFunctionInfo->flashCommonBitOperation); flashExecuteInRamFunctionInfo->activeFunctionCount = kFLASH_ExecuteInRamFunctionTotalNum; return kStatus_FLASH_Success; } #endif /* FLASH_DRIVER_IS_FLASH_RESIDENT */ status_t FLASH_EraseAll(flash_config_t *config, uint32_t key) { status_t returnCode; if (config == NULL) { return kStatus_FLASH_InvalidArgument; } /* preparing passing parameter to erase all flash blocks */ kFCCOBx[0] = BYTES_JOIN_TO_WORD_1_3(FTFx_ERASE_ALL_BLOCK, 0xFFFFFFU); /* Validate the user key */ returnCode = flash_check_user_key(key); if (returnCode) { return returnCode; } flash_cache_clear_process(config, kFLASH_CacheClearProcessPre); /* calling flash command sequence function to execute the command */ returnCode = flash_command_sequence(config); flash_cache_clear(config); #if FLASH_SSD_IS_FLEXNVM_ENABLED /* Data flash IFR will be erased by erase all command, so we need to * update FlexNVM memory partition status synchronously */ if (returnCode == kStatus_FLASH_Success) { returnCode = flash_update_flexnvm_memory_partition_status(config); } #endif return returnCode; } status_t FLASH_Erase(flash_config_t *config, uint32_t start, uint32_t lengthInBytes, uint32_t key) { uint32_t sectorSize; flash_operation_config_t flashOperationInfo; uint32_t endAddress; /* storing end address */ uint32_t numberOfSectors; /* number of sectors calculated by endAddress */ status_t returnCode; flash_get_matched_operation_info(config, start, &flashOperationInfo); /* Check the supplied address range. */ returnCode = flash_check_range(config, start, lengthInBytes, flashOperationInfo.sectorCmdAddressAligment); if (returnCode) { return returnCode; } /* Validate the user key */ returnCode = flash_check_user_key(key); if (returnCode) { return returnCode; } start = flashOperationInfo.convertedAddress; sectorSize = flashOperationInfo.activeSectorSize; /* calculating Flash end address */ endAddress = start + lengthInBytes - 1; /* re-calculate the endAddress and align it to the start of the next sector * which will be used in the comparison below */ if (endAddress % sectorSize) { numberOfSectors = endAddress / sectorSize + 1; endAddress = numberOfSectors * sectorSize - 1; } flash_cache_clear_process(config, kFLASH_CacheClearProcessPre); /* the start address will increment to the next sector address * until it reaches the endAdddress */ while (start <= endAddress) { /* preparing passing parameter to erase a flash block */ kFCCOBx[0] = BYTES_JOIN_TO_WORD_1_3(FTFx_ERASE_SECTOR, start); /* calling flash command sequence function to execute the command */ returnCode = flash_command_sequence(config); /* calling flash callback function if it is available */ if (config->PFlashCallback) { config->PFlashCallback(); } /* checking the success of command execution */ if (kStatus_FLASH_Success != returnCode) { break; } else { /* Increment to the next sector */ start += sectorSize; } } flash_cache_clear(config); return (returnCode); } #if defined(FSL_FEATURE_FLASH_HAS_ERASE_ALL_BLOCKS_UNSECURE_CMD) && FSL_FEATURE_FLASH_HAS_ERASE_ALL_BLOCKS_UNSECURE_CMD status_t FLASH_EraseAllUnsecure(flash_config_t *config, uint32_t key) { status_t returnCode; if (config == NULL) { return kStatus_FLASH_InvalidArgument; } /* Prepare passing parameter to erase all flash blocks (unsecure). */ kFCCOBx[0] = BYTES_JOIN_TO_WORD_1_3(FTFx_ERASE_ALL_BLOCK_UNSECURE, 0xFFFFFFU); /* Validate the user key */ returnCode = flash_check_user_key(key); if (returnCode) { return returnCode; } flash_cache_clear_process(config, kFLASH_CacheClearProcessPre); /* calling flash command sequence function to execute the command */ returnCode = flash_command_sequence(config); flash_cache_clear(config); #if FLASH_SSD_IS_FLEXNVM_ENABLED /* Data flash IFR will be erased by erase all unsecure command, so we need to * update FlexNVM memory partition status synchronously */ if (returnCode == kStatus_FLASH_Success) { returnCode = flash_update_flexnvm_memory_partition_status(config); } #endif return returnCode; } #endif /* FSL_FEATURE_FLASH_HAS_ERASE_ALL_BLOCKS_UNSECURE_CMD */ status_t FLASH_EraseAllExecuteOnlySegments(flash_config_t *config, uint32_t key) { status_t returnCode; if (config == NULL) { return kStatus_FLASH_InvalidArgument; } /* preparing passing parameter to erase all execute-only segments * 1st element for the FCCOB register */ kFCCOBx[0] = BYTES_JOIN_TO_WORD_1_3(FTFx_ERASE_ALL_EXECUTE_ONLY_SEGMENT, 0xFFFFFFU); /* Validate the user key */ returnCode = flash_check_user_key(key); if (returnCode) { return returnCode; } flash_cache_clear_process(config, kFLASH_CacheClearProcessPre); /* calling flash command sequence function to execute the command */ returnCode = flash_command_sequence(config); flash_cache_clear(config); return returnCode; } status_t FLASH_Program(flash_config_t *config, uint32_t start, uint32_t *src, uint32_t lengthInBytes) { status_t returnCode; flash_operation_config_t flashOperationInfo; if (src == NULL) { return kStatus_FLASH_InvalidArgument; } flash_get_matched_operation_info(config, start, &flashOperationInfo); /* Check the supplied address range. */ returnCode = flash_check_range(config, start, lengthInBytes, flashOperationInfo.blockWriteUnitSize); if (returnCode) { return returnCode; } start = flashOperationInfo.convertedAddress; flash_cache_clear_process(config, kFLASH_CacheClearProcessPre); while (lengthInBytes > 0) { /* preparing passing parameter to program the flash block */ kFCCOBx[1] = *src++; if (4 == flashOperationInfo.blockWriteUnitSize) { kFCCOBx[0] = BYTES_JOIN_TO_WORD_1_3(FTFx_PROGRAM_LONGWORD, start); } else if (8 == flashOperationInfo.blockWriteUnitSize) { kFCCOBx[2] = *src++; kFCCOBx[0] = BYTES_JOIN_TO_WORD_1_3(FTFx_PROGRAM_PHRASE, start); } else { } /* calling flash command sequence function to execute the command */ returnCode = flash_command_sequence(config); /* calling flash callback function if it is available */ if (config->PFlashCallback) { config->PFlashCallback(); } /* checking for the success of command execution */ if (kStatus_FLASH_Success != returnCode) { break; } else { /* update start address for next iteration */ start += flashOperationInfo.blockWriteUnitSize; /* update lengthInBytes for next iteration */ lengthInBytes -= flashOperationInfo.blockWriteUnitSize; } } flash_cache_clear(config); return (returnCode); } status_t FLASH_ProgramOnce(flash_config_t *config, uint32_t index, uint32_t *src, uint32_t lengthInBytes) { status_t returnCode; if ((config == NULL) || (src == NULL)) { return kStatus_FLASH_InvalidArgument; } /* pass paramters to FTFx */ kFCCOBx[0] = BYTES_JOIN_TO_WORD_1_1_2(FTFx_PROGRAM_ONCE, index, 0xFFFFU); kFCCOBx[1] = *src; /* Note: Have to seperate the first index from the rest if it equals 0 * to avoid a pointless comparison of unsigned int to 0 compiler warning */ #if FLASH_PROGRAM_ONCE_IS_8BYTES_UNIT_SUPPORT #if FLASH_PROGRAM_ONCE_IS_4BYTES_UNIT_SUPPORT if (((index == FLASH_PROGRAM_ONCE_MIN_ID_8BYTES) || /* Range check */ ((index >= FLASH_PROGRAM_ONCE_MIN_ID_8BYTES + 1) && (index <= FLASH_PROGRAM_ONCE_MAX_ID_8BYTES))) && (lengthInBytes == 8)) #endif /* FLASH_PROGRAM_ONCE_IS_4BYTES_UNIT_SUPPORT */ { kFCCOBx[2] = *(src + 1); } #endif /* FLASH_PROGRAM_ONCE_IS_8BYTES_UNIT_SUPPORT */ flash_cache_clear_process(config, kFLASH_CacheClearProcessPre); /* calling flash command sequence function to execute the command */ returnCode = flash_command_sequence(config); flash_cache_clear(config); return returnCode; } #if defined(FSL_FEATURE_FLASH_HAS_PROGRAM_SECTION_CMD) && FSL_FEATURE_FLASH_HAS_PROGRAM_SECTION_CMD status_t FLASH_ProgramSection(flash_config_t *config, uint32_t start, uint32_t *src, uint32_t lengthInBytes) { status_t returnCode; uint32_t sectorSize; flash_operation_config_t flashOperationInfo; #if defined(FSL_FEATURE_FLASH_HAS_SET_FLEXRAM_FUNCTION_CMD) && FSL_FEATURE_FLASH_HAS_SET_FLEXRAM_FUNCTION_CMD bool needSwitchFlexRamMode = false; #endif /* FSL_FEATURE_FLASH_HAS_SET_FLEXRAM_FUNCTION_CMD */ if (src == NULL) { return kStatus_FLASH_InvalidArgument; } flash_get_matched_operation_info(config, start, &flashOperationInfo); /* Check the supplied address range. */ returnCode = flash_check_range(config, start, lengthInBytes, flashOperationInfo.sectionCmdAddressAligment); if (returnCode) { return returnCode; } start = flashOperationInfo.convertedAddress; sectorSize = flashOperationInfo.activeSectorSize; #if defined(FSL_FEATURE_FLASH_HAS_SET_FLEXRAM_FUNCTION_CMD) && FSL_FEATURE_FLASH_HAS_SET_FLEXRAM_FUNCTION_CMD /* Switch function of FlexRAM if needed */ if (!(FTFx->FCNFG & FTFx_FCNFG_RAMRDY_MASK)) { needSwitchFlexRamMode = true; returnCode = FLASH_SetFlexramFunction(config, kFLASH_FlexramFunctionOptionAvailableAsRam); if (returnCode != kStatus_FLASH_Success) { return kStatus_FLASH_SetFlexramAsRamError; } } #endif /* FSL_FEATURE_FLASH_HAS_SET_FLEXRAM_FUNCTION_CMD */ flash_cache_clear_process(config, kFLASH_CacheClearProcessPre); while (lengthInBytes > 0) { /* Make sure the write operation doesn't span two sectors */ uint32_t endAddressOfCurrentSector = ALIGN_UP(start, sectorSize); uint32_t lengthTobeProgrammedOfCurrentSector; uint32_t currentOffset = 0; if (endAddressOfCurrentSector == start) { endAddressOfCurrentSector += sectorSize; } if (lengthInBytes + start > endAddressOfCurrentSector) { lengthTobeProgrammedOfCurrentSector = endAddressOfCurrentSector - start; } else { lengthTobeProgrammedOfCurrentSector = lengthInBytes; } /* Program Current Sector */ while (lengthTobeProgrammedOfCurrentSector > 0) { /* Make sure the program size doesn't exceeds Acceleration RAM size */ uint32_t programSizeOfCurrentPass; uint32_t numberOfPhases; if (lengthTobeProgrammedOfCurrentSector > kFLASH_AccelerationRamSize) { programSizeOfCurrentPass = kFLASH_AccelerationRamSize; } else { programSizeOfCurrentPass = lengthTobeProgrammedOfCurrentSector; } /* Copy data to FlexRAM */ memcpy((void *)FSL_FEATURE_FLASH_FLEX_RAM_START_ADDRESS, src + currentOffset / 4, programSizeOfCurrentPass); /* Set start address of the data to be programmed */ kFCCOBx[0] = BYTES_JOIN_TO_WORD_1_3(FTFx_PROGRAM_SECTION, start + currentOffset); /* Set program size in terms of FEATURE_FLASH_SECTION_CMD_ADDRESS_ALIGMENT */ numberOfPhases = programSizeOfCurrentPass / flashOperationInfo.sectionCmdAddressAligment; kFCCOBx[1] = BYTES_JOIN_TO_WORD_2_2(numberOfPhases, 0xFFFFU); /* Peform command sequence */ returnCode = flash_command_sequence(config); /* calling flash callback function if it is available */ if (config->PFlashCallback) { config->PFlashCallback(); } if (returnCode != kStatus_FLASH_Success) { flash_cache_clear(config); return returnCode; } lengthTobeProgrammedOfCurrentSector -= programSizeOfCurrentPass; currentOffset += programSizeOfCurrentPass; } src += currentOffset / 4; start += currentOffset; lengthInBytes -= currentOffset; } flash_cache_clear(config); #if defined(FSL_FEATURE_FLASH_HAS_SET_FLEXRAM_FUNCTION_CMD) && FSL_FEATURE_FLASH_HAS_SET_FLEXRAM_FUNCTION_CMD /* Restore function of FlexRAM if needed. */ if (needSwitchFlexRamMode) { returnCode = FLASH_SetFlexramFunction(config, kFLASH_FlexramFunctionOptionAvailableForEeprom); if (returnCode != kStatus_FLASH_Success) { return kStatus_FLASH_RecoverFlexramAsEepromError; } } #endif /* FSL_FEATURE_FLASH_HAS_SET_FLEXRAM_FUNCTION_CMD */ return returnCode; } #endif /* FSL_FEATURE_FLASH_HAS_PROGRAM_SECTION_CMD */ #if FLASH_SSD_IS_FLEXNVM_ENABLED status_t FLASH_EepromWrite(flash_config_t *config, uint32_t start, uint8_t *src, uint32_t lengthInBytes) { status_t returnCode; bool needSwitchFlexRamMode = false; if (config == NULL) { return kStatus_FLASH_InvalidArgument; } /* Validates the range of the given address */ if ((start < config->FlexRAMBlockBase) || ((start + lengthInBytes) > (config->FlexRAMBlockBase + config->EEpromTotalSize))) { return kStatus_FLASH_AddressError; } returnCode = kStatus_FLASH_Success; /* Switch function of FlexRAM if needed */ if (!(FTFx->FCNFG & FTFx_FCNFG_EEERDY_MASK)) { needSwitchFlexRamMode = true; returnCode = FLASH_SetFlexramFunction(config, kFLASH_FlexramFunctionOptionAvailableForEeprom); if (returnCode != kStatus_FLASH_Success) { return kStatus_FLASH_SetFlexramAsEepromError; } } /* Write data to FlexRAM when it is used as EEPROM emulator */ while (lengthInBytes > 0) { if ((!(start & 0x3U)) && (lengthInBytes >= 4)) { *(uint32_t *)start = *(uint32_t *)src; start += 4; src += 4; lengthInBytes -= 4; } else if ((!(start & 0x1U)) && (lengthInBytes >= 2)) { *(uint16_t *)start = *(uint16_t *)src; start += 2; src += 2; lengthInBytes -= 2; } else { *(uint8_t *)start = *src; start += 1; src += 1; lengthInBytes -= 1; } /* Wait till EEERDY bit is set */ while (!(FTFx->FCNFG & FTFx_FCNFG_EEERDY_MASK)) { } /* Check for protection violation error */ if (FTFx->FSTAT & FTFx_FSTAT_FPVIOL_MASK) { return kStatus_FLASH_ProtectionViolation; } } /* Switch function of FlexRAM if needed */ if (needSwitchFlexRamMode) { returnCode = FLASH_SetFlexramFunction(config, kFLASH_FlexramFunctionOptionAvailableAsRam); if (returnCode != kStatus_FLASH_Success) { return kStatus_FLASH_RecoverFlexramAsRamError; } } return returnCode; } #endif /* FLASH_SSD_IS_FLEXNVM_ENABLED */ #if defined(FSL_FEATURE_FLASH_HAS_READ_RESOURCE_CMD) && FSL_FEATURE_FLASH_HAS_READ_RESOURCE_CMD status_t FLASH_ReadResource( flash_config_t *config, uint32_t start, uint32_t *dst, uint32_t lengthInBytes, flash_read_resource_option_t option) { status_t returnCode; flash_operation_config_t flashOperationInfo; if ((config == NULL) || (dst == NULL)) { return kStatus_FLASH_InvalidArgument; } flash_get_matched_operation_info(config, start, &flashOperationInfo); /* Check the supplied address range. */ returnCode = flash_check_resource_range(start, lengthInBytes, flashOperationInfo.resourceCmdAddressAligment, option); if (returnCode != kStatus_FLASH_Success) { return returnCode; } while (lengthInBytes > 0) { /* preparing passing parameter */ kFCCOBx[0] = BYTES_JOIN_TO_WORD_1_3(FTFx_READ_RESOURCE, start); if (flashOperationInfo.resourceCmdAddressAligment == 4) { kFCCOBx[2] = BYTES_JOIN_TO_WORD_1_3(option, 0xFFFFFFU); } else if (flashOperationInfo.resourceCmdAddressAligment == 8) { kFCCOBx[1] = BYTES_JOIN_TO_WORD_1_3(option, 0xFFFFFFU); } else { } /* calling flash command sequence function to execute the command */ returnCode = flash_command_sequence(config); if (kStatus_FLASH_Success != returnCode) { break; } /* fetch data */ *dst++ = kFCCOBx[1]; if (flashOperationInfo.resourceCmdAddressAligment == 8) { *dst++ = kFCCOBx[2]; } /* update start address for next iteration */ start += flashOperationInfo.resourceCmdAddressAligment; /* update lengthInBytes for next iteration */ lengthInBytes -= flashOperationInfo.resourceCmdAddressAligment; } return (returnCode); } #endif /* FSL_FEATURE_FLASH_HAS_READ_RESOURCE_CMD */ status_t FLASH_ReadOnce(flash_config_t *config, uint32_t index, uint32_t *dst, uint32_t lengthInBytes) { status_t returnCode; if ((config == NULL) || (dst == NULL)) { return kStatus_FLASH_InvalidArgument; } /* pass paramters to FTFx */ kFCCOBx[0] = BYTES_JOIN_TO_WORD_1_1_2(FTFx_READ_ONCE, index, 0xFFFFU); /* calling flash command sequence function to execute the command */ returnCode = flash_command_sequence(config); if (kStatus_FLASH_Success == returnCode) { *dst = kFCCOBx[1]; /* Note: Have to seperate the first index from the rest if it equals 0 * to avoid a pointless comparison of unsigned int to 0 compiler warning */ #if FLASH_PROGRAM_ONCE_IS_8BYTES_UNIT_SUPPORT #if FLASH_PROGRAM_ONCE_IS_4BYTES_UNIT_SUPPORT if (((index == FLASH_PROGRAM_ONCE_MIN_ID_8BYTES) || /* Range check */ ((index >= FLASH_PROGRAM_ONCE_MIN_ID_8BYTES + 1) && (index <= FLASH_PROGRAM_ONCE_MAX_ID_8BYTES))) && (lengthInBytes == 8)) #endif /* FLASH_PROGRAM_ONCE_IS_4BYTES_UNIT_SUPPORT */ { *(dst + 1) = kFCCOBx[2]; } #endif /* FLASH_PROGRAM_ONCE_IS_8BYTES_UNIT_SUPPORT */ } return returnCode; } status_t FLASH_GetSecurityState(flash_config_t *config, flash_security_state_t *state) { /* store data read from flash register */ uint8_t registerValue; if ((config == NULL) || (state == NULL)) { return kStatus_FLASH_InvalidArgument; } /* Get flash security register value */ registerValue = FTFx->FSEC; /* check the status of the flash security bits in the security register */ if (FLASH_SECURITY_STATE_UNSECURED == (registerValue & FTFx_FSEC_SEC_MASK)) { /* Flash in unsecured state */ *state = kFLASH_SecurityStateNotSecure; } else { /* Flash in secured state * check for backdoor key security enable bit */ if (FLASH_SECURITY_STATE_KEYEN == (registerValue & FTFx_FSEC_KEYEN_MASK)) { /* Backdoor key security enabled */ *state = kFLASH_SecurityStateBackdoorEnabled; } else { /* Backdoor key security disabled */ *state = kFLASH_SecurityStateBackdoorDisabled; } } return (kStatus_FLASH_Success); } status_t FLASH_SecurityBypass(flash_config_t *config, const uint8_t *backdoorKey) { uint8_t registerValue; /* registerValue */ status_t returnCode; /* return code variable */ if ((config == NULL) || (backdoorKey == NULL)) { return kStatus_FLASH_InvalidArgument; } /* set the default return code as kStatus_Success */ returnCode = kStatus_FLASH_Success; /* Get flash security register value */ registerValue = FTFx->FSEC; /* Check to see if flash is in secure state (any state other than 0x2) * If not, then skip this since flash is not secure */ if (0x02 != (registerValue & 0x03)) { /* preparing passing parameter to erase a flash block */ kFCCOBx[0] = BYTES_JOIN_TO_WORD_1_3(FTFx_SECURITY_BY_PASS, 0xFFFFFFU); kFCCOBx[1] = BYTES_JOIN_TO_WORD_1_1_1_1(backdoorKey[0], backdoorKey[1], backdoorKey[2], backdoorKey[3]); kFCCOBx[2] = BYTES_JOIN_TO_WORD_1_1_1_1(backdoorKey[4], backdoorKey[5], backdoorKey[6], backdoorKey[7]); /* calling flash command sequence function to execute the command */ returnCode = flash_command_sequence(config); } return (returnCode); } status_t FLASH_VerifyEraseAll(flash_config_t *config, flash_margin_value_t margin) { if (config == NULL) { return kStatus_FLASH_InvalidArgument; } /* preparing passing parameter to verify all block command */ kFCCOBx[0] = BYTES_JOIN_TO_WORD_1_1_2(FTFx_VERIFY_ALL_BLOCK, margin, 0xFFFFU); /* calling flash command sequence function to execute the command */ return flash_command_sequence(config); } status_t FLASH_VerifyErase(flash_config_t *config, uint32_t start, uint32_t lengthInBytes, flash_margin_value_t margin) { /* Check arguments. */ uint32_t blockSize; flash_operation_config_t flashOperationInfo; uint32_t nextBlockStartAddress; uint32_t remainingBytes; status_t returnCode; flash_get_matched_operation_info(config, start, &flashOperationInfo); returnCode = flash_check_range(config, start, lengthInBytes, flashOperationInfo.sectionCmdAddressAligment); if (returnCode) { return returnCode; } flash_get_matched_operation_info(config, start, &flashOperationInfo); start = flashOperationInfo.convertedAddress; blockSize = flashOperationInfo.activeBlockSize; nextBlockStartAddress = ALIGN_UP(start, blockSize); if (nextBlockStartAddress == start) { nextBlockStartAddress += blockSize; } remainingBytes = lengthInBytes; while (remainingBytes) { uint32_t numberOfPhrases; uint32_t verifyLength = nextBlockStartAddress - start; if (verifyLength > remainingBytes) { verifyLength = remainingBytes; } numberOfPhrases = verifyLength / flashOperationInfo.sectionCmdAddressAligment; /* Fill in verify section command parameters. */ kFCCOBx[0] = BYTES_JOIN_TO_WORD_1_3(FTFx_VERIFY_SECTION, start); kFCCOBx[1] = BYTES_JOIN_TO_WORD_2_1_1(numberOfPhrases, margin, 0xFFU); /* calling flash command sequence function to execute the command */ returnCode = flash_command_sequence(config); if (returnCode) { return returnCode; } remainingBytes -= verifyLength; start += verifyLength; nextBlockStartAddress += blockSize; } return kStatus_FLASH_Success; } status_t FLASH_VerifyProgram(flash_config_t *config, uint32_t start, uint32_t lengthInBytes, const uint32_t *expectedData, flash_margin_value_t margin, uint32_t *failedAddress, uint32_t *failedData) { status_t returnCode; flash_operation_config_t flashOperationInfo; if (expectedData == NULL) { return kStatus_FLASH_InvalidArgument; } flash_get_matched_operation_info(config, start, &flashOperationInfo); returnCode = flash_check_range(config, start, lengthInBytes, flashOperationInfo.checkCmdAddressAligment); if (returnCode) { return returnCode; } start = flashOperationInfo.convertedAddress; while (lengthInBytes) { /* preparing passing parameter to program check the flash block */ kFCCOBx[0] = BYTES_JOIN_TO_WORD_1_3(FTFx_PROGRAM_CHECK, start); kFCCOBx[1] = BYTES_JOIN_TO_WORD_1_3(margin, 0xFFFFFFU); kFCCOBx[2] = *expectedData; /* calling flash command sequence function to execute the command */ returnCode = flash_command_sequence(config); /* checking for the success of command execution */ if (kStatus_FLASH_Success != returnCode) { if (failedAddress) { *failedAddress = start; } if (failedData) { *failedData = 0; } break; } lengthInBytes -= flashOperationInfo.checkCmdAddressAligment; expectedData += flashOperationInfo.checkCmdAddressAligment / sizeof(*expectedData); start += flashOperationInfo.checkCmdAddressAligment; } return (returnCode); } status_t FLASH_VerifyEraseAllExecuteOnlySegments(flash_config_t *config, flash_margin_value_t margin) { if (config == NULL) { return kStatus_FLASH_InvalidArgument; } /* preparing passing parameter to verify erase all execute-only segments command */ kFCCOBx[0] = BYTES_JOIN_TO_WORD_1_1_2(FTFx_VERIFY_ALL_EXECUTE_ONLY_SEGMENT, margin, 0xFFFFU); /* calling flash command sequence function to execute the command */ return flash_command_sequence(config); } status_t FLASH_IsProtected(flash_config_t *config, uint32_t start, uint32_t lengthInBytes, flash_protection_state_t *protection_state) { uint32_t endAddress; /* end address for protection check */ uint32_t regionCheckedCounter; /* increments each time the flash address was checked for * protection status */ uint32_t regionCounter; /* incrementing variable used to increment through the flash * protection regions */ uint32_t protectStatusCounter; /* increments each time a flash region was detected as protected */ uint8_t flashRegionProtectStatus[FSL_FEATURE_FLASH_PFLASH_PROTECTION_REGION_COUNT]; /* array of the protection * status for each * protection region */ uint32_t flashRegionAddress[FSL_FEATURE_FLASH_PFLASH_PROTECTION_REGION_COUNT + 1]; /* array of the start addresses for each flash * protection region. Note this is REGION_COUNT+1 * due to requiring the next start address after * the end of flash for loop-check purposes below */ flash_protection_config_t flashProtectionInfo; /* flash protection information */ status_t returnCode; if (protection_state == NULL) { return kStatus_FLASH_InvalidArgument; } /* Check the supplied address range. */ returnCode = flash_check_range(config, start, lengthInBytes, FSL_FEATURE_FLASH_PFLASH_BLOCK_WRITE_UNIT_SIZE); if (returnCode) { return returnCode; } /* Get necessary flash protection information. */ returnCode = flash_get_protection_info(config, &flashProtectionInfo); if (returnCode) { return returnCode; } /* calculating Flash end address */ endAddress = start + lengthInBytes; /* populate the flashRegionAddress array with the start address of each flash region */ regionCounter = 0; /* make sure regionCounter is initialized to 0 first */ /* populate up to 33rd element of array, this is the next address after end of flash array */ while (regionCounter <= flashProtectionInfo.regionCount) { flashRegionAddress[regionCounter] = flashProtectionInfo.regionBase + flashProtectionInfo.regionSize * regionCounter; regionCounter++; } /* populate flashRegionProtectStatus array with status information * Protection status for each region is stored in the FPROT[3:0] registers * Each bit represents one region of flash * 4 registers * 8-bits-per-register = 32-bits (32-regions) * The convention is: * FPROT3[bit 0] is the first protection region (start of flash memory) * FPROT0[bit 7] is the last protection region (end of flash memory) * regionCounter is used to determine which FPROT[3:0] register to check for protection status * Note: FPROT=1 means NOT protected, FPROT=0 means protected */ regionCounter = 0; /* make sure regionCounter is initialized to 0 first */ while (regionCounter < flashProtectionInfo.regionCount) { #if FLASH_SSD_IS_SECONDARY_FLASH_ENABLED && FLASH_SSD_SECONDARY_FLASH_HAS_ITS_OWN_PROTECTION_REGISTER if (config->FlashMemoryIndex == (uint8_t)kFLASH_MemoryIndexSecondaryFlash) { if (regionCounter < 8) { flashRegionProtectStatus[regionCounter] = (FTFx_FPROTSL_REG >> regionCounter) & (0x01u); } else if ((regionCounter >= 8) && (regionCounter < 16)) { flashRegionProtectStatus[regionCounter] = (FTFx_FPROTSH_REG >> (regionCounter - 8)) & (0x01u); } else { break; } } else #endif { /* Note: So far protection region count may be 16/20/24/32/64 */ if (regionCounter < 8) { flashRegionProtectStatus[regionCounter] = (FTFx_FPROTL3_REG >> regionCounter) & (0x01u); } else if ((regionCounter >= 8) && (regionCounter < 16)) { flashRegionProtectStatus[regionCounter] = (FTFx_FPROTL2_REG >> (regionCounter - 8)) & (0x01u); } #if defined(FSL_FEATURE_FLASH_PFLASH_PROTECTION_REGION_COUNT) && (FSL_FEATURE_FLASH_PFLASH_PROTECTION_REGION_COUNT > 16) #if (FSL_FEATURE_FLASH_PFLASH_PROTECTION_REGION_COUNT == 20) else if ((regionCounter >= 16) && (regionCounter < 20)) { flashRegionProtectStatus[regionCounter] = (FTFx_FPROTL1_REG >> (regionCounter - 16)) & (0x01u); } #else else if ((regionCounter >= 16) && (regionCounter < 24)) { flashRegionProtectStatus[regionCounter] = (FTFx_FPROTL1_REG >> (regionCounter - 16)) & (0x01u); } #endif /* (FSL_FEATURE_FLASH_PFLASH_PROTECTION_REGION_COUNT == 20) */ #endif #if defined(FSL_FEATURE_FLASH_PFLASH_PROTECTION_REGION_COUNT) && (FSL_FEATURE_FLASH_PFLASH_PROTECTION_REGION_COUNT > 24) else if ((regionCounter >= 24) && (regionCounter < 32)) { flashRegionProtectStatus[regionCounter] = (FTFx_FPROTL0_REG >> (regionCounter - 24)) & (0x01u); } #endif #if defined(FSL_FEATURE_FLASH_PFLASH_PROTECTION_REGION_COUNT) && \ (FSL_FEATURE_FLASH_PFLASH_PROTECTION_REGION_COUNT == 64) else if (regionCounter < 40) { flashRegionProtectStatus[regionCounter] = (FTFx_FPROTH3_REG >> (regionCounter - 32)) & (0x01u); } else if (regionCounter < 48) { flashRegionProtectStatus[regionCounter] = (FTFx_FPROTH2_REG >> (regionCounter - 40)) & (0x01u); } else if (regionCounter < 56) { flashRegionProtectStatus[regionCounter] = (FTFx_FPROTH1_REG >> (regionCounter - 48)) & (0x01u); } else if (regionCounter < 64) { flashRegionProtectStatus[regionCounter] = (FTFx_FPROTH0_REG >> (regionCounter - 56)) & (0x01u); } #endif else { break; } } regionCounter++; } /* loop through the flash regions and check * desired flash address range for protection status * loop stops when it is detected that start has exceeded the endAddress */ regionCounter = 0; /* make sure regionCounter is initialized to 0 first */ regionCheckedCounter = 0; protectStatusCounter = 0; /* make sure protectStatusCounter is initialized to 0 first */ while (start < endAddress) { /* check to see if the address falls within this protection region * Note that if the entire flash is to be checked, the last protection * region checked would consist of the last protection start address and * the start address following the end of flash */ if ((start >= flashRegionAddress[regionCounter]) && (start < flashRegionAddress[regionCounter + 1])) { /* increment regionCheckedCounter to indicate this region was checked */ regionCheckedCounter++; /* check the protection status of this region * Note: FPROT=1 means NOT protected, FPROT=0 means protected */ if (!flashRegionProtectStatus[regionCounter]) { /* increment protectStatusCounter to indicate this region is protected */ protectStatusCounter++; } start += flashProtectionInfo.regionSize; /* increment to an address within the next region */ } regionCounter++; /* increment regionCounter to check for the next flash protection region */ } /* if protectStatusCounter == 0, then no region of the desired flash region is protected */ if (protectStatusCounter == 0) { *protection_state = kFLASH_ProtectionStateUnprotected; } /* if protectStatusCounter == regionCheckedCounter, then each region checked was protected */ else if (protectStatusCounter == regionCheckedCounter) { *protection_state = kFLASH_ProtectionStateProtected; } /* if protectStatusCounter != regionCheckedCounter, then protection status is mixed * In other words, some regions are protected while others are unprotected */ else { *protection_state = kFLASH_ProtectionStateMixed; } return (returnCode); } status_t FLASH_IsExecuteOnly(flash_config_t *config, uint32_t start, uint32_t lengthInBytes, flash_execute_only_access_state_t *access_state) { #if defined(FSL_FEATURE_FLASH_HAS_ACCESS_CONTROL) && FSL_FEATURE_FLASH_HAS_ACCESS_CONTROL flash_access_config_t flashAccessInfo; /* flash Execute-Only information */ #endif /* FSL_FEATURE_FLASH_HAS_ACCESS_CONTROL */ status_t returnCode; if (access_state == NULL) { return kStatus_FLASH_InvalidArgument; } /* Check the supplied address range. */ returnCode = flash_check_range(config, start, lengthInBytes, FSL_FEATURE_FLASH_PFLASH_BLOCK_WRITE_UNIT_SIZE); if (returnCode) { return returnCode; } #if defined(FSL_FEATURE_FLASH_HAS_ACCESS_CONTROL) && FSL_FEATURE_FLASH_HAS_ACCESS_CONTROL /* Get necessary flash Execute-Only information. */ returnCode = flash_get_access_info(config, &flashAccessInfo); if (returnCode) { return returnCode; } { uint32_t executeOnlySegmentCounter = 0; /* calculating end address */ uint32_t endAddress = start + lengthInBytes; /* Aligning start address and end address */ uint32_t alignedStartAddress = ALIGN_DOWN(start, flashAccessInfo.SegmentSize); uint32_t alignedEndAddress = ALIGN_UP(endAddress, flashAccessInfo.SegmentSize); uint32_t segmentIndex = 0; uint32_t maxSupportedExecuteOnlySegmentCount = (alignedEndAddress - alignedStartAddress) / flashAccessInfo.SegmentSize; while (start < endAddress) { uint32_t xacc; segmentIndex = (start - flashAccessInfo.SegmentBase) / flashAccessInfo.SegmentSize; #if FLASH_SSD_IS_SECONDARY_FLASH_ENABLED && FLASH_SSD_SECONDARY_FLASH_HAS_ITS_OWN_ACCESS_REGISTER if (config->FlashMemoryIndex == (uint8_t)kFLASH_MemoryIndexSecondaryFlash) { /* For secondary flash, The two XACCS registers allow up to 16 restricted segments of equal memory size. */ if (segmentIndex < 8) { xacc = *(const volatile uint8_t *)&FTFx_XACCSL_REG; } else if (segmentIndex < flashAccessInfo.SegmentCount) { xacc = *(const volatile uint8_t *)&FTFx_XACCSH_REG; segmentIndex -= 8; } else { break; } } else #endif { /* For primary flash, The eight XACC registers allow up to 64 restricted segments of equal memory size. */ if (segmentIndex < 32) { xacc = *(const volatile uint32_t *)&FTFx_XACCL3_REG; } else if (segmentIndex < flashAccessInfo.SegmentCount) { xacc = *(const volatile uint32_t *)&FTFx_XACCH3_REG; segmentIndex -= 32; } else { break; } } /* Determine if this address range is in a execute-only protection flash segment. */ if ((~xacc) & (1u << segmentIndex)) { executeOnlySegmentCounter++; } start += flashAccessInfo.SegmentSize; } if (executeOnlySegmentCounter < 1u) { *access_state = kFLASH_AccessStateUnLimited; } else if (executeOnlySegmentCounter < maxSupportedExecuteOnlySegmentCount) { *access_state = kFLASH_AccessStateMixed; } else { *access_state = kFLASH_AccessStateExecuteOnly; } } #else *access_state = kFLASH_AccessStateUnLimited; #endif /* FSL_FEATURE_FLASH_HAS_ACCESS_CONTROL */ return (returnCode); } status_t FLASH_GetProperty(flash_config_t *config, flash_property_tag_t whichProperty, uint32_t *value) { if ((config == NULL) || (value == NULL)) { return kStatus_FLASH_InvalidArgument; } switch (whichProperty) { case kFLASH_PropertyPflashSectorSize: *value = config->PFlashSectorSize; break; case kFLASH_PropertyPflashTotalSize: *value = config->PFlashTotalSize; break; case kFLASH_PropertyPflashBlockSize: *value = config->PFlashTotalSize / FSL_FEATURE_FLASH_PFLASH_BLOCK_COUNT; break; case kFLASH_PropertyPflashBlockCount: *value = (uint32_t)config->PFlashBlockCount; break; case kFLASH_PropertyPflashBlockBaseAddr: *value = config->PFlashBlockBase; break; case kFLASH_PropertyPflashFacSupport: #if defined(FSL_FEATURE_FLASH_HAS_ACCESS_CONTROL) *value = FSL_FEATURE_FLASH_HAS_ACCESS_CONTROL; #else *value = 0; #endif /* FSL_FEATURE_FLASH_HAS_ACCESS_CONTROL */ break; case kFLASH_PropertyPflashAccessSegmentSize: *value = config->PFlashAccessSegmentSize; break; case kFLASH_PropertyPflashAccessSegmentCount: *value = config->PFlashAccessSegmentCount; break; case kFLASH_PropertyFlexRamBlockBaseAddr: *value = config->FlexRAMBlockBase; break; case kFLASH_PropertyFlexRamTotalSize: *value = config->FlexRAMTotalSize; break; #if FLASH_SSD_IS_FLEXNVM_ENABLED case kFLASH_PropertyDflashSectorSize: *value = FSL_FEATURE_FLASH_FLEX_NVM_BLOCK_SECTOR_SIZE; break; case kFLASH_PropertyDflashTotalSize: *value = config->DFlashTotalSize; break; case kFLASH_PropertyDflashBlockSize: *value = FSL_FEATURE_FLASH_FLEX_NVM_BLOCK_SIZE; break; case kFLASH_PropertyDflashBlockCount: *value = FSL_FEATURE_FLASH_FLEX_NVM_BLOCK_COUNT; break; case kFLASH_PropertyDflashBlockBaseAddr: *value = config->DFlashBlockBase; break; case kFLASH_PropertyEepromTotalSize: *value = config->EEpromTotalSize; break; #endif /* FLASH_SSD_IS_FLEXNVM_ENABLED */ default: /* catch inputs that are not recognized */ return kStatus_FLASH_UnknownProperty; } return kStatus_FLASH_Success; } status_t FLASH_SetProperty(flash_config_t *config, flash_property_tag_t whichProperty, uint32_t value) { status_t status = kStatus_FLASH_Success; if (config == NULL) { return kStatus_FLASH_InvalidArgument; } switch (whichProperty) { #if FLASH_SSD_IS_SECONDARY_FLASH_ENABLED case kFLASH_PropertyFlashMemoryIndex: if ((value != (uint32_t)kFLASH_MemoryIndexPrimaryFlash) && (value != (uint32_t)kFLASH_MemoryIndexSecondaryFlash)) { return kStatus_FLASH_InvalidPropertyValue; } config->FlashMemoryIndex = (uint8_t)value; break; #endif /* FLASH_SSD_IS_SECONDARY_FLASH_ENABLED */ case kFLASH_PropertyFlashCacheControllerIndex: if ((value != (uint32_t)kFLASH_CacheControllerIndexForCore0) && (value != (uint32_t)kFLASH_CacheControllerIndexForCore1)) { return kStatus_FLASH_InvalidPropertyValue; } config->FlashCacheControllerIndex = (uint8_t)value; break; case kFLASH_PropertyPflashSectorSize: case kFLASH_PropertyPflashTotalSize: case kFLASH_PropertyPflashBlockSize: case kFLASH_PropertyPflashBlockCount: case kFLASH_PropertyPflashBlockBaseAddr: case kFLASH_PropertyPflashFacSupport: case kFLASH_PropertyPflashAccessSegmentSize: case kFLASH_PropertyPflashAccessSegmentCount: case kFLASH_PropertyFlexRamBlockBaseAddr: case kFLASH_PropertyFlexRamTotalSize: #if FLASH_SSD_IS_FLEXNVM_ENABLED case kFLASH_PropertyDflashSectorSize: case kFLASH_PropertyDflashTotalSize: case kFLASH_PropertyDflashBlockSize: case kFLASH_PropertyDflashBlockCount: case kFLASH_PropertyDflashBlockBaseAddr: case kFLASH_PropertyEepromTotalSize: #endif /* FLASH_SSD_IS_FLEXNVM_ENABLED */ status = kStatus_FLASH_ReadOnlyProperty; break; default: /* catch inputs that are not recognized */ status = kStatus_FLASH_UnknownProperty; break; } return status; } #if defined(FSL_FEATURE_FLASH_HAS_SET_FLEXRAM_FUNCTION_CMD) && FSL_FEATURE_FLASH_HAS_SET_FLEXRAM_FUNCTION_CMD status_t FLASH_SetFlexramFunction(flash_config_t *config, flash_flexram_function_option_t option) { status_t status; if (config == NULL) { return kStatus_FLASH_InvalidArgument; } status = flasn_check_flexram_function_option_range(option); if (status != kStatus_FLASH_Success) { return status; } /* preparing passing parameter to verify all block command */ kFCCOBx[0] = BYTES_JOIN_TO_WORD_1_1_2(FTFx_SET_FLEXRAM_FUNCTION, option, 0xFFFFU); /* calling flash command sequence function to execute the command */ return flash_command_sequence(config); } #endif /* FSL_FEATURE_FLASH_HAS_SET_FLEXRAM_FUNCTION_CMD */ #if defined(FSL_FEATURE_FLASH_HAS_SWAP_CONTROL_CMD) && FSL_FEATURE_FLASH_HAS_SWAP_CONTROL_CMD status_t FLASH_SwapControl(flash_config_t *config, uint32_t address, flash_swap_control_option_t option, flash_swap_state_config_t *returnInfo) { status_t returnCode; if ((config == NULL) || (returnInfo == NULL)) { return kStatus_FLASH_InvalidArgument; } if (address & (FSL_FEATURE_FLASH_PFLASH_SWAP_CONTROL_CMD_ADDRESS_ALIGMENT - 1)) { return kStatus_FLASH_AlignmentError; } /* Make sure address provided is in the lower half of Program flash but not in the Flash Configuration Field */ if ((address >= (config->PFlashTotalSize / 2)) || ((address >= kFLASH_ConfigAreaStart) && (address <= kFLASH_ConfigAreaEnd))) { return kStatus_FLASH_SwapIndicatorAddressError; } /* Check the option. */ returnCode = flash_check_swap_control_option(option); if (returnCode) { return returnCode; } kFCCOBx[0] = BYTES_JOIN_TO_WORD_1_3(FTFx_SWAP_CONTROL, address); kFCCOBx[1] = BYTES_JOIN_TO_WORD_1_3(option, 0xFFFFFFU); returnCode = flash_command_sequence(config); returnInfo->flashSwapState = (flash_swap_state_t)FTFx_FCCOB5_REG; returnInfo->currentSwapBlockStatus = (flash_swap_block_status_t)FTFx_FCCOB6_REG; returnInfo->nextSwapBlockStatus = (flash_swap_block_status_t)FTFx_FCCOB7_REG; return returnCode; } #endif /* FSL_FEATURE_FLASH_HAS_SWAP_CONTROL_CMD */ #if defined(FSL_FEATURE_FLASH_HAS_PFLASH_BLOCK_SWAP) && FSL_FEATURE_FLASH_HAS_PFLASH_BLOCK_SWAP status_t FLASH_Swap(flash_config_t *config, uint32_t address, flash_swap_function_option_t option) { flash_swap_state_config_t returnInfo; status_t returnCode; memset(&returnInfo, 0xFFU, sizeof(returnInfo)); do { returnCode = FLASH_SwapControl(config, address, kFLASH_SwapControlOptionReportStatus, &returnInfo); if (returnCode != kStatus_FLASH_Success) { return returnCode; } if (kFLASH_SwapFunctionOptionDisable == option) { if (returnInfo.flashSwapState == kFLASH_SwapStateDisabled) { return kStatus_FLASH_Success; } else if (returnInfo.flashSwapState == kFLASH_SwapStateUninitialized) { /* The swap system changed to the DISABLED state with Program flash block 0 * located at relative flash address 0x0_0000 */ returnCode = FLASH_SwapControl(config, address, kFLASH_SwapControlOptionDisableSystem, &returnInfo); } else { /* Swap disable should be requested only when swap system is in the uninitialized state */ return kStatus_FLASH_SwapSystemNotInUninitialized; } } else { /* When first swap: the initial swap state is Uninitialized, flash swap inidicator address is unset, * the swap procedure should be Uninitialized -> Update-Erased -> Complete. * After the first swap has been completed, the flash swap inidicator address cannot be modified * unless EraseAllBlocks command is issued, the swap procedure is changed to Update -> Update-Erased -> * Complete. */ switch (returnInfo.flashSwapState) { case kFLASH_SwapStateUninitialized: /* If current swap mode is Uninitialized, Initialize Swap to Initialized/READY state. */ returnCode = FLASH_SwapControl(config, address, kFLASH_SwapControlOptionIntializeSystem, &returnInfo); break; case kFLASH_SwapStateReady: /* Validate whether the address provided to the swap system is matched to * swap indicator address in the IFR */ returnCode = flash_validate_swap_indicator_address(config, address); if (returnCode == kStatus_FLASH_Success) { /* If current swap mode is Initialized/Ready, Initialize Swap to UPDATE state. */ returnCode = FLASH_SwapControl(config, address, kFLASH_SwapControlOptionSetInUpdateState, &returnInfo); } break; case kFLASH_SwapStateUpdate: /* If current swap mode is Update, Erase indicator sector in non active block * to proceed swap system to update-erased state */ returnCode = FLASH_Erase(config, address + (config->PFlashTotalSize >> 1), FSL_FEATURE_FLASH_PFLASH_SECTOR_CMD_ADDRESS_ALIGMENT, kFLASH_ApiEraseKey); break; case kFLASH_SwapStateUpdateErased: /* If current swap mode is Update or Update-Erased, progress Swap to COMPLETE State */ returnCode = FLASH_SwapControl(config, address, kFLASH_SwapControlOptionSetInCompleteState, &returnInfo); break; case kFLASH_SwapStateComplete: break; case kFLASH_SwapStateDisabled: /* When swap system is in disabled state, We need to clear swap system back to uninitialized * by issuing EraseAllBlocks command */ returnCode = kStatus_FLASH_SwapSystemNotInUninitialized; break; default: returnCode = kStatus_FLASH_InvalidArgument; break; } } if (returnCode != kStatus_FLASH_Success) { break; } } while (!((kFLASH_SwapStateComplete == returnInfo.flashSwapState) && (kFLASH_SwapFunctionOptionEnable == option))); return returnCode; } #endif /* FSL_FEATURE_FLASH_HAS_PFLASH_BLOCK_SWAP */ #if defined(FSL_FEATURE_FLASH_HAS_PROGRAM_PARTITION_CMD) && FSL_FEATURE_FLASH_HAS_PROGRAM_PARTITION_CMD status_t FLASH_ProgramPartition(flash_config_t *config, flash_partition_flexram_load_option_t option, uint32_t eepromDataSizeCode, uint32_t flexnvmPartitionCode) { status_t returnCode; if (config == NULL) { return kStatus_FLASH_InvalidArgument; } /* eepromDataSizeCode[7:6], flexnvmPartitionCode[7:4] should be all 1'b0 * or it will cause access error. */ /* eepromDataSizeCode &= 0x3FU; */ /* flexnvmPartitionCode &= 0x0FU; */ /* preparing passing parameter to program the flash block */ kFCCOBx[0] = BYTES_JOIN_TO_WORD_1_2_1(FTFx_PROGRAM_PARTITION, 0xFFFFU, option); kFCCOBx[1] = BYTES_JOIN_TO_WORD_1_1_2(eepromDataSizeCode, flexnvmPartitionCode, 0xFFFFU); flash_cache_clear_process(config, kFLASH_CacheClearProcessPre); /* calling flash command sequence function to execute the command */ returnCode = flash_command_sequence(config); flash_cache_clear(config); #if FLASH_SSD_IS_FLEXNVM_ENABLED /* Data flash IFR will be updated by program partition command during reset sequence, * so we just set reserved values for partitioned FlexNVM size here */ config->EEpromTotalSize = FLEX_NVM_EEPROM_SIZE_FOR_EEESIZE_RESERVED; config->DFlashTotalSize = FLEX_NVM_DFLASH_SIZE_FOR_DEPART_RESERVED; #endif return (returnCode); } #endif /* FSL_FEATURE_FLASH_HAS_PROGRAM_PARTITION_CMD */ status_t FLASH_PflashSetProtection(flash_config_t *config, pflash_protection_status_t *protectStatus) { if (config == NULL) { return kStatus_FLASH_InvalidArgument; } #if FLASH_SSD_IS_SECONDARY_FLASH_ENABLED && FLASH_SSD_SECONDARY_FLASH_HAS_ITS_OWN_PROTECTION_REGISTER if (config->FlashMemoryIndex == (uint8_t)kFLASH_MemoryIndexSecondaryFlash) { *kFPROTSL = protectStatus->valueLow32b.prots16b.protsl; if (protectStatus->valueLow32b.prots16b.protsl != *kFPROTSL) { return kStatus_FLASH_CommandFailure; } *kFPROTSH = protectStatus->valueLow32b.prots16b.protsh; if (protectStatus->valueLow32b.prots16b.protsh != *kFPROTSH) { return kStatus_FLASH_CommandFailure; } } else #endif { *kFPROTL = protectStatus->valueLow32b.protl32b; if (protectStatus->valueLow32b.protl32b != *kFPROTL) { return kStatus_FLASH_CommandFailure; } #if defined(FTFx_FPROT_HIGH_REG) *kFPROTH = protectStatus->valueHigh32b.proth32b; if (protectStatus->valueHigh32b.proth32b != *kFPROTH) { return kStatus_FLASH_CommandFailure; } #endif } return kStatus_FLASH_Success; } status_t FLASH_PflashGetProtection(flash_config_t *config, pflash_protection_status_t *protectStatus) { if ((config == NULL) || (protectStatus == NULL)) { return kStatus_FLASH_InvalidArgument; } #if FLASH_SSD_IS_SECONDARY_FLASH_ENABLED && FLASH_SSD_SECONDARY_FLASH_HAS_ITS_OWN_PROTECTION_REGISTER if (config->FlashMemoryIndex == (uint8_t)kFLASH_MemoryIndexSecondaryFlash) { protectStatus->valueLow32b.prots16b.protsl = *kFPROTSL; protectStatus->valueLow32b.prots16b.protsh = *kFPROTSH; } else #endif { protectStatus->valueLow32b.protl32b = *kFPROTL; #if defined(FTFx_FPROT_HIGH_REG) protectStatus->valueHigh32b.proth32b = *kFPROTH; #endif } return kStatus_FLASH_Success; } #if FLASH_SSD_IS_FLEXNVM_ENABLED status_t FLASH_DflashSetProtection(flash_config_t *config, uint8_t protectStatus) { if (config == NULL) { return kStatus_FLASH_InvalidArgument; } if ((config->DFlashTotalSize == 0) || (config->DFlashTotalSize == FLEX_NVM_DFLASH_SIZE_FOR_DEPART_RESERVED)) { return kStatus_FLASH_CommandNotSupported; } FTFx->FDPROT = protectStatus; if (FTFx->FDPROT != protectStatus) { return kStatus_FLASH_CommandFailure; } return kStatus_FLASH_Success; } #endif /* FLASH_SSD_IS_FLEXNVM_ENABLED */ #if FLASH_SSD_IS_FLEXNVM_ENABLED status_t FLASH_DflashGetProtection(flash_config_t *config, uint8_t *protectStatus) { if ((config == NULL) || (protectStatus == NULL)) { return kStatus_FLASH_InvalidArgument; } if ((config->DFlashTotalSize == 0) || (config->DFlashTotalSize == FLEX_NVM_DFLASH_SIZE_FOR_DEPART_RESERVED)) { return kStatus_FLASH_CommandNotSupported; } *protectStatus = FTFx->FDPROT; return kStatus_FLASH_Success; } #endif /* FLASH_SSD_IS_FLEXNVM_ENABLED */ #if FLASH_SSD_IS_FLEXNVM_ENABLED status_t FLASH_EepromSetProtection(flash_config_t *config, uint8_t protectStatus) { if (config == NULL) { return kStatus_FLASH_InvalidArgument; } if ((config->EEpromTotalSize == 0) || (config->EEpromTotalSize == FLEX_NVM_EEPROM_SIZE_FOR_EEESIZE_RESERVED)) { return kStatus_FLASH_CommandNotSupported; } FTFx->FEPROT = protectStatus; if (FTFx->FEPROT != protectStatus) { return kStatus_FLASH_CommandFailure; } return kStatus_FLASH_Success; } #endif /* FLASH_SSD_IS_FLEXNVM_ENABLED */ #if FLASH_SSD_IS_FLEXNVM_ENABLED status_t FLASH_EepromGetProtection(flash_config_t *config, uint8_t *protectStatus) { if ((config == NULL) || (protectStatus == NULL)) { return kStatus_FLASH_InvalidArgument; } if ((config->EEpromTotalSize == 0) || (config->EEpromTotalSize == FLEX_NVM_EEPROM_SIZE_FOR_EEESIZE_RESERVED)) { return kStatus_FLASH_CommandNotSupported; } *protectStatus = FTFx->FEPROT; return kStatus_FLASH_Success; } #endif /* FLASH_SSD_IS_FLEXNVM_ENABLED */ status_t FLASH_PflashSetPrefetchSpeculation(flash_prefetch_speculation_status_t *speculationStatus) { #if FLASH_PREFETCH_SPECULATION_IS_CONTROLLED_BY_MCM { FTFx_REG32_ACCESS_TYPE regBase; #if defined(MCM) regBase = (FTFx_REG32_ACCESS_TYPE)&MCM->PLACR; #elif defined(MCM0) regBase = (FTFx_REG32_ACCESS_TYPE)&MCM0->PLACR; #endif if (speculationStatus->instructionOption == kFLASH_prefetchSpeculationOptionDisable) { if (speculationStatus->dataOption == kFLASH_prefetchSpeculationOptionEnable) { return kStatus_FLASH_InvalidSpeculationOption; } else { *regBase |= MCM_PLACR_DFCS_MASK; } } else { *regBase &= ~MCM_PLACR_DFCS_MASK; if (speculationStatus->dataOption == kFLASH_prefetchSpeculationOptionEnable) { *regBase |= MCM_PLACR_EFDS_MASK; } else { *regBase &= ~MCM_PLACR_EFDS_MASK; } } } #elif FLASH_PREFETCH_SPECULATION_IS_CONTROLLED_BY_FMC { FTFx_REG32_ACCESS_TYPE regBase; uint32_t b0dpeMask, b0ipeMask; #if defined(FMC_PFB01CR_B0DPE_MASK) regBase = (FTFx_REG32_ACCESS_TYPE)&FMC->PFB01CR; b0dpeMask = FMC_PFB01CR_B0DPE_MASK; b0ipeMask = FMC_PFB01CR_B0IPE_MASK; #elif defined(FMC_PFB0CR_B0DPE_MASK) regBase = (FTFx_REG32_ACCESS_TYPE)&FMC->PFB0CR; b0dpeMask = FMC_PFB0CR_B0DPE_MASK; b0ipeMask = FMC_PFB0CR_B0IPE_MASK; #endif if (speculationStatus->instructionOption == kFLASH_prefetchSpeculationOptionEnable) { *regBase |= b0ipeMask; } else { *regBase &= ~b0ipeMask; } if (speculationStatus->dataOption == kFLASH_prefetchSpeculationOptionEnable) { *regBase |= b0dpeMask; } else { *regBase &= ~b0dpeMask; } /* Invalidate Prefetch Speculation Buffer */ #if defined(FMC_PFB01CR_S_INV_MASK) FMC->PFB01CR |= FMC_PFB01CR_S_INV_MASK; #elif defined(FMC_PFB01CR_S_B_INV_MASK) FMC->PFB01CR |= FMC_PFB01CR_S_B_INV_MASK; #elif defined(FMC_PFB0CR_S_INV_MASK) FMC->PFB0CR |= FMC_PFB0CR_S_INV_MASK; #elif defined(FMC_PFB0CR_S_B_INV_MASK) FMC->PFB0CR |= FMC_PFB0CR_S_B_INV_MASK; #endif } #elif FLASH_PREFETCH_SPECULATION_IS_CONTROLLED_BY_MSCM { FTFx_REG32_ACCESS_TYPE regBase; uint32_t flashSpeculationMask, dataPrefetchMask; regBase = (FTFx_REG32_ACCESS_TYPE)&MSCM->OCMDR[0]; flashSpeculationMask = MSCM_OCMDR_OCMC1_DFCS_MASK; dataPrefetchMask = MSCM_OCMDR_OCMC1_DFDS_MASK; if (speculationStatus->instructionOption == kFLASH_prefetchSpeculationOptionDisable) { if (speculationStatus->dataOption == kFLASH_prefetchSpeculationOptionEnable) { return kStatus_FLASH_InvalidSpeculationOption; } else { *regBase |= flashSpeculationMask; } } else { *regBase &= ~flashSpeculationMask; if (speculationStatus->dataOption == kFLASH_prefetchSpeculationOptionEnable) { *regBase &= ~dataPrefetchMask; } else { *regBase |= dataPrefetchMask; } } } #endif /* FSL_FEATURE_FTFx_MCM_FLASH_CACHE_CONTROLS */ return kStatus_FLASH_Success; } status_t FLASH_PflashGetPrefetchSpeculation(flash_prefetch_speculation_status_t *speculationStatus) { memset(speculationStatus, 0, sizeof(flash_prefetch_speculation_status_t)); /* Assuming that all speculation options are enabled. */ speculationStatus->instructionOption = kFLASH_prefetchSpeculationOptionEnable; speculationStatus->dataOption = kFLASH_prefetchSpeculationOptionEnable; #if FLASH_PREFETCH_SPECULATION_IS_CONTROLLED_BY_MCM { uint32_t value; #if defined(MCM) value = MCM->PLACR; #elif defined(MCM0) value = MCM0->PLACR; #endif if (value & MCM_PLACR_DFCS_MASK) { /* Speculation buffer is off. */ speculationStatus->instructionOption = kFLASH_prefetchSpeculationOptionDisable; speculationStatus->dataOption = kFLASH_prefetchSpeculationOptionDisable; } else { /* Speculation buffer is on for instruction. */ if (!(value & MCM_PLACR_EFDS_MASK)) { /* Speculation buffer is off for data. */ speculationStatus->dataOption = kFLASH_prefetchSpeculationOptionDisable; } } } #elif FLASH_PREFETCH_SPECULATION_IS_CONTROLLED_BY_FMC { uint32_t value; uint32_t b0dpeMask, b0ipeMask; #if defined(FMC_PFB01CR_B0DPE_MASK) value = FMC->PFB01CR; b0dpeMask = FMC_PFB01CR_B0DPE_MASK; b0ipeMask = FMC_PFB01CR_B0IPE_MASK; #elif defined(FMC_PFB0CR_B0DPE_MASK) value = FMC->PFB0CR; b0dpeMask = FMC_PFB0CR_B0DPE_MASK; b0ipeMask = FMC_PFB0CR_B0IPE_MASK; #endif if (!(value & b0dpeMask)) { /* Do not prefetch in response to data references. */ speculationStatus->dataOption = kFLASH_prefetchSpeculationOptionDisable; } if (!(value & b0ipeMask)) { /* Do not prefetch in response to instruction fetches. */ speculationStatus->instructionOption = kFLASH_prefetchSpeculationOptionDisable; } } #elif FLASH_PREFETCH_SPECULATION_IS_CONTROLLED_BY_MSCM { uint32_t value; uint32_t flashSpeculationMask, dataPrefetchMask; value = MSCM->OCMDR[0]; flashSpeculationMask = MSCM_OCMDR_OCMC1_DFCS_MASK; dataPrefetchMask = MSCM_OCMDR_OCMC1_DFDS_MASK; if (value & flashSpeculationMask) { /* Speculation buffer is off. */ speculationStatus->instructionOption = kFLASH_prefetchSpeculationOptionDisable; speculationStatus->dataOption = kFLASH_prefetchSpeculationOptionDisable; } else { /* Speculation buffer is on for instruction. */ if (value & dataPrefetchMask) { /* Speculation buffer is off for data. */ speculationStatus->dataOption = kFLASH_prefetchSpeculationOptionDisable; } } } #endif return kStatus_FLASH_Success; } #if FLASH_DRIVER_IS_FLASH_RESIDENT /*! * @brief Copy PIC of flash_run_command() to RAM */ static void copy_flash_run_command(uint32_t *flashRunCommand) { assert(sizeof(s_flashRunCommandFunctionCode) <= (kFLASH_ExecuteInRamFunctionMaxSizeInWords * 4)); /* Since the value of ARM function pointer is always odd, but the real start address * of function memory should be even, that's why +1 operation exist. */ memcpy((void *)flashRunCommand, (void *)s_flashRunCommandFunctionCode, sizeof(s_flashRunCommandFunctionCode)); callFlashRunCommand = (void (*)(FTFx_REG8_ACCESS_TYPE ftfx_fstat))((uint32_t)flashRunCommand + 1); } #endif /* FLASH_DRIVER_IS_FLASH_RESIDENT */ /*! * @brief Flash Command Sequence * * This function is used to perform the command write sequence to the flash. * * @param driver Pointer to storage for the driver runtime state. * @return An error code or kStatus_FLASH_Success */ static status_t flash_command_sequence(flash_config_t *config) { uint8_t registerValue; #if FLASH_DRIVER_IS_FLASH_RESIDENT /* clear RDCOLERR & ACCERR & FPVIOL flag in flash status register */ FTFx->FSTAT = FTFx_FSTAT_RDCOLERR_MASK | FTFx_FSTAT_ACCERR_MASK | FTFx_FSTAT_FPVIOL_MASK; status_t returnCode = flash_check_execute_in_ram_function_info(config); if (kStatus_FLASH_Success != returnCode) { return returnCode; } /* We pass the ftfx_fstat address as a parameter to flash_run_comamnd() instead of using * pre-processed MICRO sentences or operating global variable in flash_run_comamnd() * to make sure that flash_run_command() will be compiled into position-independent code (PIC). */ callFlashRunCommand((FTFx_REG8_ACCESS_TYPE)(&FTFx->FSTAT)); #else /* clear RDCOLERR & ACCERR & FPVIOL flag in flash status register */ FTFx->FSTAT = FTFx_FSTAT_RDCOLERR_MASK | FTFx_FSTAT_ACCERR_MASK | FTFx_FSTAT_FPVIOL_MASK; /* clear CCIF bit */ FTFx->FSTAT = FTFx_FSTAT_CCIF_MASK; /* Check CCIF bit of the flash status register, wait till it is set. * IP team indicates that this loop will always complete. */ while (!(FTFx->FSTAT & FTFx_FSTAT_CCIF_MASK)) { } #endif /* FLASH_DRIVER_IS_FLASH_RESIDENT */ /* Check error bits */ /* Get flash status register value */ registerValue = FTFx->FSTAT; /* checking access error */ if (registerValue & FTFx_FSTAT_ACCERR_MASK) { return kStatus_FLASH_AccessError; } /* checking protection error */ else if (registerValue & FTFx_FSTAT_FPVIOL_MASK) { return kStatus_FLASH_ProtectionViolation; } /* checking MGSTAT0 non-correctable error */ else if (registerValue & FTFx_FSTAT_MGSTAT0_MASK) { return kStatus_FLASH_CommandFailure; } else { return kStatus_FLASH_Success; } } #if FLASH_DRIVER_IS_FLASH_RESIDENT /*! * @brief Copy PIC of flash_common_bit_operation() to RAM * */ static void copy_flash_common_bit_operation(uint32_t *flashCommonBitOperation) { assert(sizeof(s_flashCommonBitOperationFunctionCode) <= (kFLASH_ExecuteInRamFunctionMaxSizeInWords * 4)); /* Since the value of ARM function pointer is always odd, but the real start address * of function memory should be even, that's why +1 operation exist. */ memcpy((void *)flashCommonBitOperation, (void *)s_flashCommonBitOperationFunctionCode, sizeof(s_flashCommonBitOperationFunctionCode)); callFlashCommonBitOperation = (void (*)(FTFx_REG32_ACCESS_TYPE base, uint32_t bitMask, uint32_t bitShift, uint32_t bitValue))((uint32_t)flashCommonBitOperation + 1); /* Workround for some devices which doesn't need this function */ callFlashCommonBitOperation((FTFx_REG32_ACCESS_TYPE)0, 0, 0, 0); } #endif /* FLASH_DRIVER_IS_FLASH_RESIDENT */ #if FLASH_CACHE_IS_CONTROLLED_BY_MCM /*! @brief Performs the cache clear to the flash by MCM.*/ void mcm_flash_cache_clear(flash_config_t *config) { FTFx_REG32_ACCESS_TYPE regBase = (FTFx_REG32_ACCESS_TYPE)&MCM0_CACHE_REG; #if defined(MCM0) && defined(MCM1) if (config->FlashCacheControllerIndex == (uint8_t)kFLASH_CacheControllerIndexForCore1) { regBase = (FTFx_REG32_ACCESS_TYPE)&MCM1_CACHE_REG; } #endif #if FLASH_DRIVER_IS_FLASH_RESIDENT callFlashCommonBitOperation(regBase, MCM_CACHE_CLEAR_MASK, MCM_CACHE_CLEAR_SHIFT, 1U); #else /* !FLASH_DRIVER_IS_FLASH_RESIDENT */ *regBase |= MCM_CACHE_CLEAR_MASK; /* Memory barriers for good measure. * All Cache, Branch predictor and TLB maintenance operations before this instruction complete */ __ISB(); __DSB(); #endif /* FLASH_DRIVER_IS_FLASH_RESIDENT */ } #endif /* FLASH_CACHE_IS_CONTROLLED_BY_MCM */ #if FLASH_CACHE_IS_CONTROLLED_BY_FMC /*! @brief Performs the cache clear to the flash by FMC.*/ void fmc_flash_cache_clear(void) { #if FLASH_DRIVER_IS_FLASH_RESIDENT FTFx_REG32_ACCESS_TYPE regBase = (FTFx_REG32_ACCESS_TYPE)0; #if defined(FMC_PFB01CR_CINV_WAY_MASK) regBase = (FTFx_REG32_ACCESS_TYPE)&FMC->PFB01CR; callFlashCommonBitOperation(regBase, FMC_PFB01CR_CINV_WAY_MASK, FMC_PFB01CR_CINV_WAY_SHIFT, 0xFU); #else regBase = (FTFx_REG32_ACCESS_TYPE)&FMC->PFB0CR; callFlashCommonBitOperation(regBase, FMC_PFB0CR_CINV_WAY_MASK, FMC_PFB0CR_CINV_WAY_SHIFT, 0xFU); #endif #else /* !FLASH_DRIVER_IS_FLASH_RESIDENT */ #if defined(FMC_PFB01CR_CINV_WAY_MASK) FMC->PFB01CR = (FMC->PFB01CR & ~FMC_PFB01CR_CINV_WAY_MASK) | FMC_PFB01CR_CINV_WAY(~0); #else FMC->PFB0CR = (FMC->PFB0CR & ~FMC_PFB0CR_CINV_WAY_MASK) | FMC_PFB0CR_CINV_WAY(~0); #endif /* Memory barriers for good measure. * All Cache, Branch predictor and TLB maintenance operations before this instruction complete */ __ISB(); __DSB(); #endif /* FLASH_DRIVER_IS_FLASH_RESIDENT */ } #endif /* FLASH_CACHE_IS_CONTROLLED_BY_FMC */ #if FLASH_PREFETCH_SPECULATION_IS_CONTROLLED_BY_MSCM /*! @brief Performs the prefetch speculation buffer clear to the flash by MSCM.*/ void mscm_flash_prefetch_speculation_enable(bool enable) { uint8_t setValue; if (enable) { setValue = 0x0U; } else { setValue = 0x3U; } /* The OCMDR[0] is always used to prefetch main Pflash*/ /* For device with FlexNVM support, the OCMDR[1] is used to prefetch Dflash. * For device with secondary flash support, the OCMDR[1] is used to prefetch secondary Pflash. */ #if FLASH_DRIVER_IS_FLASH_RESIDENT callFlashCommonBitOperation((FTFx_REG32_ACCESS_TYPE)&MSCM->OCMDR[0], MSCM_SPECULATION_DISABLE_MASK, MSCM_SPECULATION_DISABLE_SHIFT, setValue); #if FLASH_SSD_IS_FLEXNVM_ENABLED || BL_HAS_SECONDARY_INTERNAL_FLASH callFlashCommonBitOperation((FTFx_REG32_ACCESS_TYPE)&MSCM->OCMDR[1], MSCM_SPECULATION_DISABLE_MASK, MSCM_SPECULATION_DISABLE_SHIFT, setValue); #endif #else /* !FLASH_DRIVER_IS_FLASH_RESIDENT */ MSCM->OCMDR[0] |= MSCM_SPECULATION_DISABLE(setValue); /* Memory barriers for good measure. * All Cache, Branch predictor and TLB maintenance operations before this instruction complete */ __ISB(); __DSB(); #if FLASH_SSD_IS_FLEXNVM_ENABLED || BL_HAS_SECONDARY_INTERNAL_FLASH MSCM->OCMDR[1] |= MSCM_SPECULATION_DISABLE(setValue); /* Each cahce clear instaruction should be followed by below code*/ __ISB(); __DSB(); #endif #endif /* FLASH_DRIVER_IS_FLASH_RESIDENT */ } #endif /* FLASH_PREFETCH_SPECULATION_IS_CONTROLLED_BY_MSCM */ #if FLASH_PREFETCH_SPECULATION_IS_CONTROLLED_BY_FMC /*! @brief Performs the prefetch speculation buffer clear to the flash by FMC.*/ void fmc_flash_prefetch_speculation_clear(void) { #if FLASH_DRIVER_IS_FLASH_RESIDENT FTFx_REG32_ACCESS_TYPE regBase = (FTFx_REG32_ACCESS_TYPE)0; #if defined(FMC_PFB01CR_S_INV_MASK) regBase = (FTFx_REG32_ACCESS_TYPE)&FMC->PFB01CR; callFlashCommonBitOperation(regBase, FMC_PFB01CR_S_INV_MASK, FMC_PFB01CR_S_INV_SHIFT, 1U); #elif defined(FMC_PFB01CR_S_B_INV_MASK) regBase = (FTFx_REG32_ACCESS_TYPE)&FMC->PFB01CR; callFlashCommonBitOperation(regBase, FMC_PFB01CR_S_B_INV_MASK, FMC_PFB01CR_S_B_INV_SHIFT, 1U); #elif defined(FMC_PFB0CR_S_INV_MASK) regBase = (FTFx_REG32_ACCESS_TYPE)&FMC->PFB0CR; callFlashCommonBitOperation(regBase, FMC_PFB0CR_S_INV_MASK, FMC_PFB0CR_S_INV_SHIFT, 1U); #elif defined(FMC_PFB0CR_S_B_INV_MASK) regBase = (FTFx_REG32_ACCESS_TYPE)&FMC->PFB0CR; callFlashCommonBitOperation(regBase, FMC_PFB0CR_S_B_INV_MASK, FMC_PFB0CR_S_B_INV_SHIFT, 1U); #endif #else /* !FLASH_DRIVER_IS_FLASH_RESIDENT */ #if defined(FMC_PFB01CR_S_INV_MASK) FMC->PFB01CR |= FMC_PFB01CR_S_INV_MASK; #elif defined(FMC_PFB01CR_S_B_INV_MASK) FMC->PFB01CR |= FMC_PFB01CR_S_B_INV_MASK; #elif defined(FMC_PFB0CR_S_INV_MASK) FMC->PFB0CR |= FMC_PFB0CR_S_INV_MASK; #elif defined(FMC_PFB0CR_S_B_INV_MASK) FMC->PFB0CR |= FMC_PFB0CR_S_B_INV_MASK; #endif /* Memory barriers for good measure. * All Cache, Branch predictor and TLB maintenance operations before this instruction complete */ __ISB(); __DSB(); #endif /* FLASH_DRIVER_IS_FLASH_RESIDENT */ } #endif /* FLASH_PREFETCH_SPECULATION_IS_CONTROLLED_BY_FMC */ /*! * @brief Flash Cache Clear * * This function is used to perform the cache and prefetch speculation clear to the flash. */ void flash_cache_clear(flash_config_t *config) { flash_cache_clear_process(config, kFLASH_CacheClearProcessPost); } /*! * @brief Flash Cache Clear Process * * This function is used to perform the cache and prefetch speculation clear process to the flash. */ static void flash_cache_clear_process(flash_config_t *config, flash_cache_clear_process_t process) { #if FLASH_DRIVER_IS_FLASH_RESIDENT status_t returnCode = flash_check_execute_in_ram_function_info(config); if (kStatus_FLASH_Success != returnCode) { return; } #endif /* FLASH_DRIVER_IS_FLASH_RESIDENT */ /* We pass the ftfx register address as a parameter to flash_common_bit_operation() instead of using * pre-processed MACROs or a global variable in flash_common_bit_operation() * to make sure that flash_common_bit_operation() will be compiled into position-independent code (PIC). */ if (process == kFLASH_CacheClearProcessPost) { #if FLASH_CACHE_IS_CONTROLLED_BY_MCM mcm_flash_cache_clear(config); #endif #if FLASH_CACHE_IS_CONTROLLED_BY_FMC fmc_flash_cache_clear(); #endif #if FLASH_PREFETCH_SPECULATION_IS_CONTROLLED_BY_MSCM mscm_flash_prefetch_speculation_enable(true); #endif #if FLASH_PREFETCH_SPECULATION_IS_CONTROLLED_BY_FMC fmc_flash_prefetch_speculation_clear(); #endif } if (process == kFLASH_CacheClearProcessPre) { #if FLASH_PREFETCH_SPECULATION_IS_CONTROLLED_BY_MSCM mscm_flash_prefetch_speculation_enable(false); #endif } } #if FLASH_DRIVER_IS_FLASH_RESIDENT /*! @brief Check whether flash execute-in-ram functions are ready */ static status_t flash_check_execute_in_ram_function_info(flash_config_t *config) { flash_execute_in_ram_function_config_t *flashExecuteInRamFunctionInfo; if (config == NULL) { return kStatus_FLASH_InvalidArgument; } flashExecuteInRamFunctionInfo = (flash_execute_in_ram_function_config_t *)config->flashExecuteInRamFunctionInfo; if ((config->flashExecuteInRamFunctionInfo) && (kFLASH_ExecuteInRamFunctionTotalNum == flashExecuteInRamFunctionInfo->activeFunctionCount)) { return kStatus_FLASH_Success; } return kStatus_FLASH_ExecuteInRamFunctionNotReady; } #endif /* FLASH_DRIVER_IS_FLASH_RESIDENT */ /*! @brief Validates the range and alignment of the given address range.*/ static status_t flash_check_range(flash_config_t *config, uint32_t startAddress, uint32_t lengthInBytes, uint32_t alignmentBaseline) { if (config == NULL) { return kStatus_FLASH_InvalidArgument; } /* Verify the start and length are alignmentBaseline aligned. */ if ((startAddress & (alignmentBaseline - 1)) || (lengthInBytes & (alignmentBaseline - 1))) { return kStatus_FLASH_AlignmentError; } /* check for valid range of the target addresses */ if ( #if FLASH_SSD_IS_FLEXNVM_ENABLED ((startAddress >= config->DFlashBlockBase) && ((startAddress + lengthInBytes) <= (config->DFlashBlockBase + config->DFlashTotalSize))) || #endif ((startAddress >= config->PFlashBlockBase) && ((startAddress + lengthInBytes) <= (config->PFlashBlockBase + config->PFlashTotalSize)))) { return kStatus_FLASH_Success; } return kStatus_FLASH_AddressError; } /*! @brief Gets the right address, sector and block size of current flash type which is indicated by address.*/ static status_t flash_get_matched_operation_info(flash_config_t *config, uint32_t address, flash_operation_config_t *info) { if (config == NULL) { return kStatus_FLASH_InvalidArgument; } /* Clean up info Structure*/ memset(info, 0, sizeof(flash_operation_config_t)); #if FLASH_SSD_IS_FLEXNVM_ENABLED if ((address >= config->DFlashBlockBase) && (address <= (config->DFlashBlockBase + config->DFlashTotalSize))) { /* When required by the command, address bit 23 selects between program flash memory * (=0) and data flash memory (=1).*/ info->convertedAddress = address - config->DFlashBlockBase + 0x800000U; info->activeSectorSize = FSL_FEATURE_FLASH_FLEX_NVM_BLOCK_SECTOR_SIZE; info->activeBlockSize = config->DFlashTotalSize / FSL_FEATURE_FLASH_FLEX_NVM_BLOCK_COUNT; info->blockWriteUnitSize = FSL_FEATURE_FLASH_FLEX_NVM_BLOCK_WRITE_UNIT_SIZE; info->sectorCmdAddressAligment = FSL_FEATURE_FLASH_FLEX_NVM_SECTOR_CMD_ADDRESS_ALIGMENT; info->sectionCmdAddressAligment = FSL_FEATURE_FLASH_FLEX_NVM_SECTION_CMD_ADDRESS_ALIGMENT; info->resourceCmdAddressAligment = FSL_FEATURE_FLASH_FLEX_NVM_RESOURCE_CMD_ADDRESS_ALIGMENT; info->checkCmdAddressAligment = FSL_FEATURE_FLASH_FLEX_NVM_CHECK_CMD_ADDRESS_ALIGMENT; } else #endif /* FLASH_SSD_IS_FLEXNVM_ENABLED */ { info->convertedAddress = address - config->PFlashBlockBase; info->activeSectorSize = config->PFlashSectorSize; info->activeBlockSize = config->PFlashTotalSize / config->PFlashBlockCount; #if FLASH_SSD_IS_SECONDARY_FLASH_ENABLED if (config->FlashMemoryIndex == (uint8_t)kFLASH_MemoryIndexSecondaryFlash) { #if FLASH_SSD_SECONDARY_FLASH_HAS_ITS_OWN_PROTECTION_REGISTER || FLASH_SSD_SECONDARY_FLASH_HAS_ITS_OWN_ACCESS_REGISTER /* When required by the command, address bit 23 selects between main flash memory * (=0) and secondary flash memory (=1).*/ info->convertedAddress += 0x800000U; #endif info->blockWriteUnitSize = FSL_FEATURE_FLASH_PFLASH_1_BLOCK_WRITE_UNIT_SIZE; } else #endif /* FLASH_SSD_IS_SECONDARY_FLASH_ENABLED */ { info->blockWriteUnitSize = FSL_FEATURE_FLASH_PFLASH_BLOCK_WRITE_UNIT_SIZE; } info->sectorCmdAddressAligment = FSL_FEATURE_FLASH_PFLASH_SECTOR_CMD_ADDRESS_ALIGMENT; info->sectionCmdAddressAligment = FSL_FEATURE_FLASH_PFLASH_SECTION_CMD_ADDRESS_ALIGMENT; info->resourceCmdAddressAligment = FSL_FEATURE_FLASH_PFLASH_RESOURCE_CMD_ADDRESS_ALIGMENT; info->checkCmdAddressAligment = FSL_FEATURE_FLASH_PFLASH_CHECK_CMD_ADDRESS_ALIGMENT; } return kStatus_FLASH_Success; } /*! @brief Validates the given user key for flash erase APIs.*/ static status_t flash_check_user_key(uint32_t key) { /* Validate the user key */ if (key != kFLASH_ApiEraseKey) { return kStatus_FLASH_EraseKeyError; } return kStatus_FLASH_Success; } #if FLASH_SSD_IS_FLEXNVM_ENABLED /*! @brief Updates FlexNVM memory partition status according to data flash 0 IFR.*/ static status_t flash_update_flexnvm_memory_partition_status(flash_config_t *config) { struct { uint32_t reserved0; uint8_t FlexNVMPartitionCode; uint8_t EEPROMDataSetSize; uint16_t reserved1; } dataIFRReadOut; status_t returnCode; if (config == NULL) { return kStatus_FLASH_InvalidArgument; } #if defined(FSL_FEATURE_FLASH_HAS_READ_RESOURCE_CMD) && FSL_FEATURE_FLASH_HAS_READ_RESOURCE_CMD /* Get FlexNVM memory partition info from data flash IFR */ returnCode = FLASH_ReadResource(config, DFLASH_IFR_READRESOURCE_START_ADDRESS, (uint32_t *)&dataIFRReadOut, sizeof(dataIFRReadOut), kFLASH_ResourceOptionFlashIfr); if (returnCode != kStatus_FLASH_Success) { return kStatus_FLASH_PartitionStatusUpdateFailure; } #else #error "Cannot get FlexNVM memory partition info" #endif /* Fill out partitioned EEPROM size */ dataIFRReadOut.EEPROMDataSetSize &= 0x0FU; switch (dataIFRReadOut.EEPROMDataSetSize) { case 0x00U: config->EEpromTotalSize = FSL_FEATURE_FLASH_FLEX_NVM_EEPROM_SIZE_FOR_EEESIZE_0000; break; case 0x01U: config->EEpromTotalSize = FSL_FEATURE_FLASH_FLEX_NVM_EEPROM_SIZE_FOR_EEESIZE_0001; break; case 0x02U: config->EEpromTotalSize = FSL_FEATURE_FLASH_FLEX_NVM_EEPROM_SIZE_FOR_EEESIZE_0010; break; case 0x03U: config->EEpromTotalSize = FSL_FEATURE_FLASH_FLEX_NVM_EEPROM_SIZE_FOR_EEESIZE_0011; break; case 0x04U: config->EEpromTotalSize = FSL_FEATURE_FLASH_FLEX_NVM_EEPROM_SIZE_FOR_EEESIZE_0100; break; case 0x05U: config->EEpromTotalSize = FSL_FEATURE_FLASH_FLEX_NVM_EEPROM_SIZE_FOR_EEESIZE_0101; break; case 0x06U: config->EEpromTotalSize = FSL_FEATURE_FLASH_FLEX_NVM_EEPROM_SIZE_FOR_EEESIZE_0110; break; case 0x07U: config->EEpromTotalSize = FSL_FEATURE_FLASH_FLEX_NVM_EEPROM_SIZE_FOR_EEESIZE_0111; break; case 0x08U: config->EEpromTotalSize = FSL_FEATURE_FLASH_FLEX_NVM_EEPROM_SIZE_FOR_EEESIZE_1000; break; case 0x09U: config->EEpromTotalSize = FSL_FEATURE_FLASH_FLEX_NVM_EEPROM_SIZE_FOR_EEESIZE_1001; break; case 0x0AU: config->EEpromTotalSize = FSL_FEATURE_FLASH_FLEX_NVM_EEPROM_SIZE_FOR_EEESIZE_1010; break; case 0x0BU: config->EEpromTotalSize = FSL_FEATURE_FLASH_FLEX_NVM_EEPROM_SIZE_FOR_EEESIZE_1011; break; case 0x0CU: config->EEpromTotalSize = FSL_FEATURE_FLASH_FLEX_NVM_EEPROM_SIZE_FOR_EEESIZE_1100; break; case 0x0DU: config->EEpromTotalSize = FSL_FEATURE_FLASH_FLEX_NVM_EEPROM_SIZE_FOR_EEESIZE_1101; break; case 0x0EU: config->EEpromTotalSize = FSL_FEATURE_FLASH_FLEX_NVM_EEPROM_SIZE_FOR_EEESIZE_1110; break; case 0x0FU: config->EEpromTotalSize = FSL_FEATURE_FLASH_FLEX_NVM_EEPROM_SIZE_FOR_EEESIZE_1111; break; default: config->EEpromTotalSize = FLEX_NVM_EEPROM_SIZE_FOR_EEESIZE_RESERVED; break; } /* Fill out partitioned DFlash size */ dataIFRReadOut.FlexNVMPartitionCode &= 0x0FU; switch (dataIFRReadOut.FlexNVMPartitionCode) { case 0x00U: #if (FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_0000 != 0xFFFFFFFF) config->DFlashTotalSize = FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_0000; #else config->DFlashTotalSize = FLEX_NVM_DFLASH_SIZE_FOR_DEPART_RESERVED; #endif /* FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_0000 */ break; case 0x01U: #if (FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_0001 != 0xFFFFFFFF) config->DFlashTotalSize = FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_0001; #else config->DFlashTotalSize = FLEX_NVM_DFLASH_SIZE_FOR_DEPART_RESERVED; #endif /* FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_0001 */ break; case 0x02U: #if (FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_0010 != 0xFFFFFFFF) config->DFlashTotalSize = FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_0010; #else config->DFlashTotalSize = FLEX_NVM_DFLASH_SIZE_FOR_DEPART_RESERVED; #endif /* FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_0010 */ break; case 0x03U: #if (FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_0011 != 0xFFFFFFFF) config->DFlashTotalSize = FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_0011; #else config->DFlashTotalSize = FLEX_NVM_DFLASH_SIZE_FOR_DEPART_RESERVED; #endif /* FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_0011 */ break; case 0x04U: #if (FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_0100 != 0xFFFFFFFF) config->DFlashTotalSize = FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_0100; #else config->DFlashTotalSize = FLEX_NVM_DFLASH_SIZE_FOR_DEPART_RESERVED; #endif /* FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_0100 */ break; case 0x05U: #if (FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_0101 != 0xFFFFFFFF) config->DFlashTotalSize = FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_0101; #else config->DFlashTotalSize = FLEX_NVM_DFLASH_SIZE_FOR_DEPART_RESERVED; #endif /* FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_0101 */ break; case 0x06U: #if (FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_0110 != 0xFFFFFFFF) config->DFlashTotalSize = FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_0110; #else config->DFlashTotalSize = FLEX_NVM_DFLASH_SIZE_FOR_DEPART_RESERVED; #endif /* FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_0110 */ break; case 0x07U: #if (FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_0111 != 0xFFFFFFFF) config->DFlashTotalSize = FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_0111; #else config->DFlashTotalSize = FLEX_NVM_DFLASH_SIZE_FOR_DEPART_RESERVED; #endif /* FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_0111 */ break; case 0x08U: #if (FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_1000 != 0xFFFFFFFF) config->DFlashTotalSize = FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_1000; #else config->DFlashTotalSize = FLEX_NVM_DFLASH_SIZE_FOR_DEPART_RESERVED; #endif /* FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_1000 */ break; case 0x09U: #if (FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_1001 != 0xFFFFFFFF) config->DFlashTotalSize = FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_1001; #else config->DFlashTotalSize = FLEX_NVM_DFLASH_SIZE_FOR_DEPART_RESERVED; #endif /* FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_1001 */ break; case 0x0AU: #if (FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_1010 != 0xFFFFFFFF) config->DFlashTotalSize = FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_1010; #else config->DFlashTotalSize = FLEX_NVM_DFLASH_SIZE_FOR_DEPART_RESERVED; #endif /* FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_1010 */ break; case 0x0BU: #if (FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_1011 != 0xFFFFFFFF) config->DFlashTotalSize = FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_1011; #else config->DFlashTotalSize = FLEX_NVM_DFLASH_SIZE_FOR_DEPART_RESERVED; #endif /* FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_1011 */ break; case 0x0CU: #if (FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_1100 != 0xFFFFFFFF) config->DFlashTotalSize = FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_1100; #else config->DFlashTotalSize = FLEX_NVM_DFLASH_SIZE_FOR_DEPART_RESERVED; #endif /* FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_1100 */ break; case 0x0DU: #if (FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_1101 != 0xFFFFFFFF) config->DFlashTotalSize = FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_1101; #else config->DFlashTotalSize = FLEX_NVM_DFLASH_SIZE_FOR_DEPART_RESERVED; #endif /* FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_1101 */ break; case 0x0EU: #if (FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_1110 != 0xFFFFFFFF) config->DFlashTotalSize = FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_1110; #else config->DFlashTotalSize = FLEX_NVM_DFLASH_SIZE_FOR_DEPART_RESERVED; #endif /* FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_1110 */ break; case 0x0FU: #if (FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_1111 != 0xFFFFFFFF) config->DFlashTotalSize = FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_1111; #else config->DFlashTotalSize = FLEX_NVM_DFLASH_SIZE_FOR_DEPART_RESERVED; #endif /* FSL_FEATURE_FLASH_FLEX_NVM_DFLASH_SIZE_FOR_DEPART_1111 */ break; default: config->DFlashTotalSize = FLEX_NVM_DFLASH_SIZE_FOR_DEPART_RESERVED; break; } return kStatus_FLASH_Success; } #endif /* FLASH_SSD_IS_FLEXNVM_ENABLED */ #if defined(FSL_FEATURE_FLASH_HAS_READ_RESOURCE_CMD) && FSL_FEATURE_FLASH_HAS_READ_RESOURCE_CMD /*! @brief Validates the range of the given resource address.*/ static status_t flash_check_resource_range(uint32_t start, uint32_t lengthInBytes, uint32_t alignmentBaseline, flash_read_resource_option_t option) { status_t status; uint32_t maxReadbleAddress; if ((start & (alignmentBaseline - 1)) || (lengthInBytes & (alignme |