42 #define CHIP_NAME "Winbond W25QXX"
43 #define MANUFACTURER_NAME "Winbond"
44 #define SUPPLY_VOLTAGE_MIN 2.7f
45 #define SUPPLY_VOLTAGE_MAX 3.6f
46 #define MAX_CURRENT 25.0f
47 #define TEMPERATURE_MIN -40.0f
48 #define TEMPERATURE_MAX 85.0f
49 #define DRIVER_VERSION 1000
54 #define W25QXX_COMMAND_WRITE_ENABLE 0x06
55 #define W25QXX_COMMAND_VOLATILE_SR_WRITE_ENABLE 0x50
56 #define W25QXX_COMMAND_WRITE_DISABLE 0x04
57 #define W25QXX_COMMAND_READ_STATUS_REG1 0x05
58 #define W25QXX_COMMAND_READ_STATUS_REG2 0x35
59 #define W25QXX_COMMAND_READ_STATUS_REG3 0x15
60 #define W25QXX_COMMAND_WRITE_STATUS_REG1 0x01
61 #define W25QXX_COMMAND_WRITE_STATUS_REG2 0x31
62 #define W25QXX_COMMAND_WRITE_STATUS_REG3 0x11
63 #define W25QXX_COMMAND_CHIP_ERASE 0xC7
64 #define W25QXX_COMMAND_ERASE_PROGRAM_SUSPEND 0x75
65 #define W25QXX_COMMAND_ERASE_PROGRAM_RESUME 0x7A
66 #define W25QXX_COMMAND_POWER_DOWN 0xB9
67 #define W25QXX_COMMAND_RELEASE_POWER_DOWN 0xAB
68 #define W25QXX_COMMAND_READ_MANUFACTURER 0x90
69 #define W25QXX_COMMAND_JEDEC_ID 0x9F
70 #define W25QXX_COMMAND_GLOBAL_BLOCK_SECTOR_LOCK 0x7E
71 #define W25QXX_COMMAND_GLOBAL_BLOCK_SECTOR_UNLOCK 0x98
72 #define W25QXX_COMMAND_ENTER_QSPI_MODE 0x38
73 #define W25QXX_COMMAND_ENABLE_RESET 0x66
74 #define W25QXX_COMMAND_RESET_DEVICE 0x99
75 #define W25QXX_COMMAND_READ_UNIQUE_ID 0x4B
76 #define W25QXX_COMMAND_PAGE_PROGRAM 0x02
77 #define W25QXX_COMMAND_QUAD_PAGE_PROGRAM 0x32
78 #define W25QXX_COMMAND_SECTOR_ERASE_4K 0x20
79 #define W25QXX_COMMAND_BLOCK_ERASE_32K 0x52
80 #define W25QXX_COMMAND_BLOCK_ERASE_64K 0xD8
81 #define W25QXX_COMMAND_READ_DATA 0x03
82 #define W25QXX_COMMAND_FAST_READ 0x0B
83 #define W25QXX_COMMAND_FAST_READ_DUAL_OUTPUT 0x3B
84 #define W25QXX_COMMAND_FAST_READ_QUAD_OUTPUT 0x6B
85 #define W25QXX_COMMAND_READ_SFDP_REGISTER 0x5A
86 #define W25QXX_COMMAND_ERASE_SECURITY_REGISTER 0x44
87 #define W25QXX_COMMAND_PROGRAM_SECURITY_REGISTER 0x42
88 #define W25QXX_COMMAND_READ_SECURITY_REGISTER 0x48
89 #define W25QXX_COMMAND_INDIVIDUAL_BLOCK_LOCK 0x36
90 #define W25QXX_COMMAND_INDIVIDUAL_BLOCK_UNLOCK 0x39
91 #define W25QXX_COMMAND_READ_BLOCK_LOCK 0x3D
92 #define W25QXX_COMMAND_FAST_READ_DUAL_IO 0xBB
93 #define W25QXX_COMMAND_DEVICE_ID_DUAL_IO 0x92
94 #define W25QXX_COMMAND_SET_BURST_WITH_WRAP 0x77
95 #define W25QXX_COMMAND_FAST_READ_QUAD_IO 0xEB
96 #define W25QXX_COMMAND_WORD_READ_QUAD_IO 0xE7
97 #define W25QXX_COMMAND_OCTAL_WORD_READ_QUAD_IO 0xE3
98 #define W25QXX_COMMAND_DEVICE_ID_QUAD_IO 0x94
112 static uint8_t a_w25qxx_spi_write_read(
w25qxx_handle_t *handle, uint8_t *in_buf, uint32_t in_len, uint8_t *out_buf, uint32_t out_len)
115 0x00000000, 0x00, 0x00,
116 0x00, in_buf, in_len, out_buf, out_len, 1) != 0)
148 static uint8_t a_w25qxx_qspi_write_read(
w25qxx_handle_t *handle, uint8_t instruction, uint8_t instruction_line,
149 uint32_t address, uint8_t address_line, uint8_t address_len,
150 uint32_t alternate, uint8_t alternate_line, uint8_t alternate_len,
151 uint8_t dummy, uint8_t *in_buf, uint32_t in_len,
152 uint8_t *out_buf, uint32_t out_len, uint8_t data_line)
154 if (handle->
spi_qspi_write_read(instruction, instruction_line, address, address_line, address_len,
155 alternate, alternate_line, alternate_len,
156 dummy, in_buf, in_len, out_buf, out_len, data_line) != 0)
224 handle->
type = (uint16_t)type;
266 handle->
spi_qspi = (uint8_t)interface;
319 handle->
debug_print(
"w25qxx: current type can't use this function.\n");
336 res = a_w25qxx_qspi_write_read(handle, buf[0], 1,
337 0x00000000, 0x00, 0x00,
338 0x00000000, 0x00, 0x00,
343 handle->
debug_print(
"w25qxx: set address mode failed.\n");
358 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 1, NULL, 0);
361 handle->
debug_print(
"w25qxx: set address mode failed.\n");
377 res = a_w25qxx_qspi_write_read(handle, buf[0], 4,
378 0x00000000, 0x00, 0x00,
379 0x00000000, 0x00, 0x00,
384 handle->
debug_print(
"w25qxx: set address mode failed.\n");
450 0x00000000, 0x00, 0x00,
451 0x00000000, 0x00, 0x00,
456 handle->
debug_print(
"w25qxx: write enable failed.\n");
464 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 1, NULL, 0);
467 handle->
debug_print(
"w25qxx: write enable failed.\n");
476 0x00000000, 0x00, 0x00,
477 0x00000000, 0x00, 0x00,
482 handle->
debug_print(
"w25qxx: write enable failed.\n");
519 res = a_w25qxx_qspi_write_read(handle,
521 0x00000000, 0x00, 0x00,
522 0x00000000, 0x00, 0x00,
527 handle->
debug_print(
"w25qxx: sr write enable failed.\n");
535 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 1, NULL, 0);
538 handle->
debug_print(
"w25qxx: sr write enable failed.\n");
547 0x00000000, 0x00, 0x00,
548 0x00000000, 0x00, 0x00,
553 handle->
debug_print(
"w25qxx: sr write enable failed.\n");
591 0x00000000, 0x00, 0x00,
592 0x00000000, 0x00, 0x00,
597 handle->
debug_print(
"w25qxx: write disable failed.\n");
605 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 1, NULL, 0);
608 handle->
debug_print(
"w25qxx: write disable failed.\n");
617 0x00000000, 0x00, 0x00,
618 0x00000000, 0x00, 0x00,
623 handle->
debug_print(
"w25qxx: write disable failed.\n");
661 res = a_w25qxx_qspi_write_read(handle,
663 0x00000000, 0x00, 0x00,
664 0x00000000, 0x00, 0x00,
669 handle->
debug_print(
"w25qxx: get status1 failed.\n");
677 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf,
681 handle->
debug_print(
"w25qxx: get status1 failed.\n");
690 0x00000000, 0x00, 0x00,
691 0x00000000, 0x00, 0x00,
696 handle->
debug_print(
"w25qxx: get status1 failed.\n");
734 res = a_w25qxx_qspi_write_read(handle,
736 0x00000000, 0x00, 0x00,
737 0x00000000, 0x00, 0x00,
742 handle->
debug_print(
"w25qxx: get status2 failed.\n");
750 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf,
754 handle->
debug_print(
"w25qxx: get status2 failed.\n");
763 0x00000000, 0x00, 0x00,
764 0x00000000, 0x00, 0x00,
769 handle->
debug_print(
"w25qxx: get status2 failed.\n");
807 res = a_w25qxx_qspi_write_read(handle,
809 0x00000000, 0x00, 0x00,
810 0x00000000, 0x00, 0x00,
815 handle->
debug_print(
"w25qxx: get status3 failed.\n");
823 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 1,
827 handle->
debug_print(
"w25qxx: get status3 failed.\n");
836 0x00000000, 0x00, 0x00,
837 0x00000000, 0x00, 0x00,
842 handle->
debug_print(
"w25qxx: get status3 failed.\n");
868 uint8_t status_check;
884 0x00000000, 0x00, 0x00,
885 0x00000000, 0x00, 0x00,
890 handle->
debug_print(
"w25qxx: write enable failed.\n");
896 0x00000000, 0x00, 0x00,
897 0x00000000, 0x00, 0x00,
898 0x00, (uint8_t *)buf, 1,
902 handle->
debug_print(
"w25qxx: set status1 failed.\n");
911 0x00000000, 0x00, 0x00,
912 0x00000000, 0x00, 0x00,
914 (uint8_t *)&status_check, 1, 1);
917 handle->
debug_print(
"w25qxx: get status1 failed.\n");
921 if ((status_check & 0x01) == 0x00)
930 handle->
debug_print(
"w25qxx: write status 1 timeout.\n");
942 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 1, NULL, 0);
945 handle->
debug_print(
"w25qxx: write enable failed.\n");
951 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 2, NULL, 0);
954 handle->
debug_print(
"w25qxx: set status1 failed.\n");
963 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 1,
964 (uint8_t *)&status_check, 1);
967 handle->
debug_print(
"w25qxx: get status1 failed.\n");
971 if ((status_check & 0x01) == 0x00)
980 handle->
debug_print(
"w25qxx: write status 1 timeout.\n");
993 0x00000000, 0x00, 0x00,
994 0x00000000, 0x00, 0x00,
999 handle->
debug_print(
"w25qxx: write enable failed.\n");
1005 0x00000000, 0x00, 0x00,
1006 0x00000000, 0x00, 0x00,
1007 0x00, (uint8_t *)buf, 1,
1011 handle->
debug_print(
"w25qxx: set status1 failed.\n");
1017 while (timeout != 0)
1020 0x00000000, 0x00, 0x00,
1021 0x00000000, 0x00, 0x00,
1023 (uint8_t *)&status_check, 1, 4);
1026 handle->
debug_print(
"w25qxx: get status1 failed.\n");
1030 if ((status_check & 0x01) == 0x00)
1039 handle->
debug_print(
"w25qxx: write status 1 timeout.\n");
1067 uint8_t status_check;
1083 0x00000000, 0x00, 0x00,
1084 0x00000000, 0x00, 0x00,
1089 handle->
debug_print(
"w25qxx: write enable failed.\n");
1095 0x00000000, 0x00, 0x00,
1096 0x00000000, 0x00, 0x00,
1097 0x00, (uint8_t *)buf, 1,
1101 handle->
debug_print(
"w25qxx: set status2 failed.\n");
1107 while (timeout != 0)
1110 0x00000000, 0x00, 0x00,
1111 0x00000000, 0x00, 0x00,
1113 (uint8_t *)&status_check, 1, 1);
1116 handle->
debug_print(
"w25qxx: get status1 failed.\n");
1120 if ((status_check & 0x01) == 0x00)
1129 handle->
debug_print(
"w25qxx: write status 2 timeout.\n");
1141 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 1, NULL, 0);
1144 handle->
debug_print(
"w25qxx: write enable failed.\n");
1150 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 2, NULL, 0);
1153 handle->
debug_print(
"w25qxx: set status2 failed.\n");
1159 while (timeout != 0)
1162 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 1,
1163 (uint8_t *)&status_check, 1);
1166 handle->
debug_print(
"w25qxx: get status1 failed.\n");
1170 if ((status_check & 0x01) == 0x00)
1179 handle->
debug_print(
"w25qxx: write status 2 timeout.\n");
1192 0x00000000, 0x00, 0x00,
1193 0x00000000, 0x00, 0x00,
1198 handle->
debug_print(
"w25qxx: write enable failed.\n");
1204 0x00000000, 0x00, 0x00,
1205 0x00000000, 0x00, 0x00,
1206 0x00, (uint8_t *)buf, 1,
1210 handle->
debug_print(
"w25qxx: set status2 failed.\n");
1216 while (timeout != 0)
1219 0x00000000, 0x00, 0x00,
1220 0x00000000, 0x00, 0x00,
1222 (uint8_t *)&status_check, 1, 4);
1225 handle->
debug_print(
"w25qxx: get status1 failed.\n");
1229 if ((status_check & 0x01) == 0x00)
1238 handle->
debug_print(
"w25qxx: write status 2 timeout.\n");
1266 uint8_t status_check;
1282 0x00000000, 0x00, 0x00,
1283 0x00000000, 0x00, 0x00,
1288 handle->
debug_print(
"w25qxx: write enable failed.\n");
1294 0x00000000, 0x00, 0x00,
1295 0x00000000, 0x00, 0x00,
1296 0x00, (uint8_t *)buf, 1,
1300 handle->
debug_print(
"w25qxx: set status3 failed.\n");
1306 while (timeout != 0)
1309 0x00000000, 0x00, 0x00,
1310 0x00000000, 0x00, 0x00,
1312 (uint8_t *)&status_check, 1, 1);
1315 handle->
debug_print(
"w25qxx: get status1 failed.\n");
1319 if ((status_check & 0x01) == 0x00)
1328 handle->
debug_print(
"w25qxx: write status 3 timeout.\n");
1340 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 1, NULL, 0);
1343 handle->
debug_print(
"w25qxx: write enable failed.\n");
1349 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 2, NULL, 0);
1352 handle->
debug_print(
"w25qxx: set status3 failed.\n");
1358 while (timeout != 0)
1361 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 1,
1362 (uint8_t *)&status_check, 1);
1365 handle->
debug_print(
"w25qxx: get status1 failed.\n");
1369 if ((status_check & 0x01) == 0x00)
1378 handle->
debug_print(
"w25qxx: write status 3 timeout.\n");
1391 0x00000000, 0x00, 0x00,
1392 0x00000000, 0x00, 0x00,
1397 handle->
debug_print(
"w25qxx: write enable failed.\n");
1403 0x00000000, 0x00, 0x00,
1404 0x00000000, 0x00, 0x00,
1405 0x00, (uint8_t *)buf, 1,
1409 handle->
debug_print(
"w25qxx: set status3 failed.\n");
1415 while (timeout != 0)
1418 0x00000000, 0x00, 0x00,
1419 0x00000000, 0x00, 0x00,
1421 (uint8_t *)&status_check, 1, 4);
1424 handle->
debug_print(
"w25qxx: get status1 failed.\n");
1428 if ((status_check & 0x01) == 0x00)
1437 handle->
debug_print(
"w25qxx: write status 3 timeout.\n");
1480 0x00000000, 0x00, 0x00,
1481 0x00000000, 0x00, 0x00,
1486 handle->
debug_print(
"w25qxx: write enable failed.\n");
1491 0x00000000, 0x00, 0x00,
1492 0x00000000, 0x00, 0x00,
1497 handle->
debug_print(
"w25qxx: chip erase failed.\n");
1501 timeout = 1000 * 1000;
1502 while (timeout != 0)
1505 0x00000000, 0x00, 0x00,
1506 0x00000000, 0x00, 0x00,
1508 (uint8_t *)&status, 1, 1);
1511 handle->
debug_print(
"w25qxx: get status1 failed.\n");
1515 if ((status & 0x01) == 0x00)
1536 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 1, NULL, 0);
1539 handle->
debug_print(
"w25qxx: write enable failed.\n");
1544 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 1, NULL, 0);
1547 handle->
debug_print(
"w25qxx: chip erase failed.\n");
1551 timeout = 1000 * 1000;
1552 while (timeout != 0)
1555 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 1,
1556 (uint8_t *)&status, 1);
1559 handle->
debug_print(
"w25qxx: get status1 failed.\n");
1563 if ((status & 0x01) == 0x00)
1585 0x00000000, 0x00, 0x00,
1586 0x00000000, 0x00, 0x00,
1591 handle->
debug_print(
"w25qxx: write enable failed.\n");
1596 0x00000000, 0x00, 0x00,
1597 0x00000000, 0x00, 0x00,
1602 handle->
debug_print(
"w25qxx: chip erase failed.\n");
1606 timeout = 1000 * 1000;
1607 while (timeout != 0)
1610 0x00000000, 0x00, 0x00,
1611 0x00000000, 0x00, 0x00,
1613 (uint8_t *)&status, 1, 4);
1616 handle->
debug_print(
"w25qxx: get status1 failed.\n");
1620 if ((status & 0x01) == 0x00)
1669 0x00000000, 0x00, 0x00,
1670 0x00000000, 0x00, 0x00,
1675 handle->
debug_print(
"w25qxx: erase program suspend failed.\n");
1683 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 1, NULL, 0);
1686 handle->
debug_print(
"w25qxx: erase program suspend failed.\n");
1697 0x00000000, 0x00, 0x00,
1698 0x00000000, 0x00, 0x00,
1703 handle->
debug_print(
"w25qxx: erase program suspend failed.\n");
1741 0x00000000, 0x00, 0x00,
1742 0x00000000, 0x00, 0x00,
1747 handle->
debug_print(
"w25qxx: erase program resume failed.\n");
1755 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 1, NULL, 0);
1758 handle->
debug_print(
"w25qxx: erase program resume failed.\n");
1767 0x00000000, 0x00, 0x00,
1768 0x00000000, 0x00, 0x00,
1773 handle->
debug_print(
"w25qxx: erase program resume failed.\n");
1811 0x00000000, 0x00, 0x00,
1812 0x00000000, 0x00, 0x00,
1817 handle->
debug_print(
"w25qxx: power down failed.\n");
1825 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf,
1829 handle->
debug_print(
"w25qxx: power down failed.\n");
1837 res = a_w25qxx_qspi_write_read(handle, 0xFF, 4,
1838 0x00000000, 0x00, 0x00,
1839 0x00000000, 0x00, 0x00,
1844 handle->
debug_print(
"w25qxx: exit qspi mode failed.\n");
1850 0x00000000, 0x00, 0x00,
1851 0x00000000, 0x00, 0x00,
1856 handle->
debug_print(
"w25qxx: power down failed.\n");
1894 res = a_w25qxx_qspi_write_read(handle,
1896 0x00000000, 0x00, 0x00,
1897 0x00000000, 0x00, 0x00,
1899 (uint8_t *)&
id, 1, 1);
1902 handle->
debug_print(
"w25qxx: release power down failed.\n");
1913 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 4, (uint8_t *)&
id, 1);
1916 handle->
debug_print(
"w25qxx: release power down failed.\n");
1925 0x00000000, 0x00, 0x00,
1926 0x00000000, 0x00, 0x00,
1928 (uint8_t *)&
id, 1, 4);
1931 handle->
debug_print(
"w25qxx: release power down failed.\n");
1973 0x00000000, 0x00, 0x00,
1975 (uint8_t *)out, 2, 1);
1978 handle->
debug_print(
"w25qxx: get manufacturer device id failed.\n");
1982 *manufacturer = out[0];
1983 *device_id = out[1];
1991 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 4,
1995 handle->
debug_print(
"w25qxx: get manufacturer device id failed.\n");
1999 *manufacturer = out[0];
2000 *device_id = out[1];
2007 0x00000000, 0x00, 0x00,
2009 (uint8_t *)out, 2, 4);
2012 handle->
debug_print(
"w25qxx: get manufacturer device id failed.\n");
2016 *manufacturer = out[0];
2017 *device_id = out[1];
2056 handle->
debug_print(
"w25qxx: standard spi can't use this function failed.\n");
2066 (uint8_t *)out, 2, 2);
2069 handle->
debug_print(
"w25qxx: get manufacturer device id dual io failed.\n");
2080 (uint8_t *)out, 2, 2);
2083 handle->
debug_print(
"w25qxx: get manufacturer device id dual io failed.\n");
2090 handle->
debug_print(
"w25qxx: address mode is invalid.\n");
2094 *manufacturer = out[0];
2095 *device_id = out[1];
2099 handle->
debug_print(
"w25qxx: qspi can't use this function.\n");
2140 handle->
debug_print(
"w25qxx: standard spi can't use this function failed.\n");
2150 (uint8_t *)out, 2, 4);
2153 handle->
debug_print(
"w25qxx: get manufacturer device id quad io failed.\n");
2164 (uint8_t *)out, 2, 4);
2167 handle->
debug_print(
"w25qxx: get manufacturer device id quad io failed.\n");
2174 handle->
debug_print(
"w25qxx: address mode is invalid.\n");
2178 *manufacturer = out[0];
2179 *device_id = out[1];
2183 handle->
debug_print(
"w25qxx: qspi can't use this function.\n");
2223 0x00000000, 0x00, 0x00,
2224 0x00000000, 0x00, 0x00,
2226 (uint8_t *)out, 3, 1);
2229 handle->
debug_print(
"w25qxx: get jedec id failed.\n");
2233 *manufacturer = out[0];
2234 device_id[0] = out[1];
2235 device_id[1] = out[2];
2240 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 1,
2244 handle->
debug_print(
"w25qxx: get jedec id failed.\n");
2248 *manufacturer = out[0];
2249 device_id[0] = out[1];
2250 device_id[1] = out[2];
2256 0x00000000, 0x00, 0x00,
2257 0x00000000, 0x00, 0x00,
2259 (uint8_t *)out, 3, 4);
2262 handle->
debug_print(
"w25qxx: get jedec id failed.\n");
2266 *manufacturer = out[0];
2267 device_id[0] = out[1];
2268 device_id[1] = out[2];
2303 0x00000000, 0x00, 0x00,
2304 0x00000000, 0x00, 0x00,
2309 handle->
debug_print(
"w25qxx: global block lock failed.\n");
2317 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 1, NULL, 0);
2320 handle->
debug_print(
"w25qxx: global block lock failed.\n");
2329 0x00000000, 0x00, 0x00,
2330 0x00000000, 0x00, 0x00,
2335 handle->
debug_print(
"w25qxx: global block lock failed.\n");
2373 0x00000000, 0x00, 0x00,
2374 0x00000000, 0x00, 0x00,
2379 handle->
debug_print(
"w25qxx: global block unlock failed.\n");
2387 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 1, NULL, 0);
2390 handle->
debug_print(
"w25qxx: global block unlock failed.\n");
2399 0x00000000, 0x00, 0x00,
2400 0x00000000, 0x00, 0x00,
2405 handle->
debug_print(
"w25qxx: global block unlock failed.\n");
2443 handle->
debug_print(
"w25qxx: spi interface can't use this function.\n");
2449 handle->
param = (uint8_t)((dummy << 4) | (length << 0));
2450 buf[0] = handle->
param;
2451 res = a_w25qxx_qspi_write_read(handle, 0xC0, 4,
2452 0x00000000, 0x00, 0x00,
2453 0x00000000, 0x00, 0x00,
2454 0, (uint8_t *)buf, 1,
2458 handle->
debug_print(
"w25qxx: set read parameters failed.\n");
2462 if (((buf[0] >> 4) & 0x03) == 0x00)
2466 else if (((buf[0] >> 4) & 0x03) == 0x01)
2470 else if (((buf[0] >> 4) & 0x03) == 0x02)
2510 handle->
debug_print(
"w25qxx: qspi interface can't use this function.\n");
2517 0x00000000, 0x00, 0x00,
2518 0x00000000, 0x00, 0x00,
2523 handle->
debug_print(
"w25qxx: enter qspi mode failed.\n");
2528 buf[0] = handle->
param;
2529 res = a_w25qxx_qspi_write_read(handle, 0xC0, 4,
2530 0x00000000, 0x00, 0x00,
2531 0x00000000, 0x00, 0x00,
2532 0, (uint8_t *)buf, 1,
2536 handle->
debug_print(
"w25qxx: set read parameters failed.\n");
2540 if (((buf[0] >> 4) & 0x03) == 0x00)
2544 else if (((buf[0] >> 4) & 0x03) == 0x01)
2548 else if (((buf[0] >> 4) & 0x03) == 0x02)
2587 handle->
debug_print(
"w25qxx: spi interface can't use this function.\n");
2593 res = a_w25qxx_qspi_write_read(handle, 0xFF, 4,
2594 0x00000000, 0x00, 0x00,
2595 0x00000000, 0x00, 0x00,
2600 handle->
debug_print(
"w25qxx: exit qspi mode failed.\n");
2638 0x00000000, 0x00, 0x00,
2639 0x00000000, 0x00, 0x00,
2644 handle->
debug_print(
"w25qxx: enable reset failed.\n");
2652 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf,
2656 handle->
debug_print(
"w25qxx: enable reset failed.\n");
2665 0x00000000, 0x00, 0x00,
2666 0x00000000, 0x00, 0x00,
2671 handle->
debug_print(
"w25qxx: enable reset failed.\n");
2709 0x00000000, 0x00, 0x00,
2710 0x00000000, 0x00, 0x00,
2715 handle->
debug_print(
"w25qxx: reset device failed.\n");
2723 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf,
2727 handle->
debug_print(
"w25qxx: reset device failed.\n");
2736 0x00000000, 0x00, 0x00,
2737 0x00000000, 0x00, 0x00,
2742 handle->
debug_print(
"w25qxx: reset device failed.\n");
2785 0x00000000, 0x00, 0x00,
2786 0x00000000, 0x00, 0x00,
2788 (uint8_t *)
id, 8, 1);
2791 handle->
debug_print(
"w25qxx: read unique id failed.\n");
2799 0x00000000, 0x00, 0x00,
2800 0x00000000, 0x00, 0x00,
2802 (uint8_t *)
id, 8, 1);
2805 handle->
debug_print(
"w25qxx: read unique id failed.\n");
2812 handle->
debug_print(
"w25qxx: address mode is invalid.\n");
2826 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 5, (uint8_t *)
id, 8);
2829 handle->
debug_print(
"w25qxx: read unique id failed.\n");
2842 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 6, (uint8_t *)
id, 8);
2845 handle->
debug_print(
"w25qxx: read unique id failed.\n");
2852 handle->
debug_print(
"w25qxx: address mode is invalid.\n");
2860 handle->
debug_print(
"w25qxx: qspi can't use this function.\n");
2898 res = a_w25qxx_qspi_write_read(handle,
2901 0x00000000, 0x00, 0x00,
2903 (uint8_t *)sfdp, 256, 1);
2906 handle->
debug_print(
"w25qxx: read unique id failed.\n");
2918 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 5,
2919 (uint8_t *)sfdp, 256);
2922 handle->
debug_print(
"w25qxx: get sfdp failed.\n");
2930 handle->
debug_print(
"w25qxx: qspi can't use this function.\n");
2972 res = a_w25qxx_qspi_write_read(handle,
2974 0x00000000, 0x00, 0x00,
2975 0x00000000, 0x00, 0x00,
2980 handle->
debug_print(
"w25qxx: write enable failed.\n");
2986 res = a_w25qxx_qspi_write_read(handle,
2989 0x00000000, 0x00, 0x00,
2994 handle->
debug_print(
"w25qxx: erase security register failed.\n");
3001 res = a_w25qxx_qspi_write_read(handle,
3004 0x00000000, 0x00, 0x00,
3009 handle->
debug_print(
"w25qxx: erase security register failed.\n");
3016 handle->
debug_print(
"w25qxx: address mode is invalid.\n");
3021 timeout = 100 * 100;
3022 while (timeout != 0)
3024 res = a_w25qxx_qspi_write_read(handle,
3026 0x00000000, 0x00, 0x00,
3027 0x00000000, 0x00, 0x00,
3029 (uint8_t *)&status, 1, 1);
3032 handle->
debug_print(
"w25qxx: get status1 failed.\n");
3036 if ((status & 0x01) == 0x00)
3045 handle->
debug_print(
"w25qxx: erase security register timeout.\n");
3053 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 1, NULL, 0);
3056 handle->
debug_print(
"w25qxx: write enable failed.\n");
3066 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 4, NULL, 0);
3069 handle->
debug_print(
"w25qxx: erase security register failed.\n");
3081 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 5, NULL, 0);
3084 handle->
debug_print(
"w25qxx: erase security register failed.\n");
3091 handle->
debug_print(
"w25qxx: address mode is invalid.\n");
3096 timeout = 100 * 100;
3097 while (timeout != 0)
3100 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 1, (uint8_t *)&status, 1);
3103 handle->
debug_print(
"w25qxx: get status1 failed.\n");
3107 if ((status & 0x01) == 0x00)
3116 handle->
debug_print(
"w25qxx: erase security register timeout.\n");
3124 handle->
debug_print(
"w25qxx: qspi can't use this function.\n");
3167 res = a_w25qxx_qspi_write_read(handle,
3169 0x00000000, 0x00, 0x00,
3170 0x00000000, 0x00, 0x00,
3175 handle->
debug_print(
"w25qxx: write enable failed.\n");
3181 res = a_w25qxx_qspi_write_read(handle,
3184 0x00000000, 0x00, 0x00,
3189 handle->
debug_print(
"w25qxx: program security register failed.\n");
3196 res = a_w25qxx_qspi_write_read(handle,
3199 0x00000000, 0x00, 0x00,
3204 handle->
debug_print(
"w25qxx: program security register failed.\n");
3211 handle->
debug_print(
"w25qxx: address mode is invalid.\n");
3217 while (timeout != 0)
3219 res = a_w25qxx_qspi_write_read(handle,
3221 0x00000000, 0x00, 0x00,
3222 0x00000000, 0x00, 0x00,
3224 (uint8_t *)&status, 1, 1);
3227 handle->
debug_print(
"w25qxx: get status1 failed.\n");
3231 if ((status & 0x01) == 0x00)
3240 handle->
debug_print(
"w25qxx: program security register timeout.\n");
3248 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 1, NULL, 0);
3251 handle->
debug_print(
"w25qxx: write enable failed.\n");
3258 handle->
buf[1] = 0x00;
3259 handle->
buf[2] = num;
3260 handle->
buf[3] = 0x00;
3261 memcpy(&handle->
buf[4], data, 256);
3262 res = a_w25qxx_spi_write_read(handle, (uint8_t *)handle->
buf, 260, NULL, 0);
3265 handle->
debug_print(
"w25qxx: program security register failed.\n");
3273 handle->
buf[1] = 0x00;
3274 handle->
buf[2] = 0x00;
3275 handle->
buf[3] = num;
3276 handle->
buf[4] = 0x00;
3277 memcpy(&handle->
buf[5], data, 256);
3278 res = a_w25qxx_spi_write_read(handle, (uint8_t *)handle->
buf, 261, NULL, 0);
3281 handle->
debug_print(
"w25qxx: program security register failed.\n");
3288 handle->
debug_print(
"w25qxx: address mode is invalid.\n");
3294 while (timeout != 0)
3297 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 1, (uint8_t *)&status, 1);
3300 handle->
debug_print(
"w25qxx: get status1 failed.\n");
3304 if ((status & 0x01) == 0x00)
3313 handle->
debug_print(
"w25qxx: program security register timeout.\n");
3321 handle->
debug_print(
"w25qxx: qspi can't use this function.\n");
3364 res = a_w25qxx_qspi_write_read(handle,
3367 0x00000000, 0x00, 0x00,
3372 handle->
debug_print(
"w25qxx: read security register failed.\n");
3379 res = a_w25qxx_qspi_write_read(handle,
3382 0x00000000, 0x00, 0x00,
3387 handle->
debug_print(
"w25qxx: read security register failed.\n");
3394 handle->
debug_print(
"w25qxx: address mode is invalid.\n");
3408 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 5, data, 256);
3411 handle->
debug_print(
"w25qxx: read security register failed.\n");
3424 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 6, data, 256);
3427 handle->
debug_print(
"w25qxx: read security register failed.\n");
3434 handle->
debug_print(
"w25qxx: address mode is invalid.\n");
3442 handle->
debug_print(
"w25qxx: qspi can't use this function.\n");
3487 res = a_w25qxx_qspi_write_read(handle,
3489 0x00000000, 0x00, 0x00,
3490 0x00000000, 0x00, 0x00,
3495 handle->
debug_print(
"w25qxx: write enable failed.\n");
3499 buf[0] = (addr >> 24) & 0xFF;
3500 res = a_w25qxx_qspi_write_read(handle,
3502 0x00000000, 0x00, 0x00,
3503 0x00000000, 0x00, 0x00,
3504 0x00, (uint8_t *)buf, 1,
3508 handle->
debug_print(
"w25qxx: write extended addr register failed.\n");
3514 res = a_w25qxx_qspi_write_read(handle,
3517 0x00000000, 0x00, 0x00,
3522 handle->
debug_print(
"w25qxx: only spi read failed.\n");
3530 res = a_w25qxx_qspi_write_read(handle,
3533 0x00000000, 0x00, 0x00,
3538 handle->
debug_print(
"w25qxx: only spi read failed.\n");
3545 handle->
debug_print(
"w25qxx: address mode is invalid.\n");
3557 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 1, NULL, 0);
3560 handle->
debug_print(
"w25qxx: write enable failed.\n");
3565 buf[1] = (addr >> 24) & 0xFF;
3566 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 2, NULL, 0);
3569 handle->
debug_print(
"w25qxx: write extended addr register failed.\n");
3575 buf[1] = (addr >> 16) & 0xFF;
3576 buf[2] = (addr >> 8) & 0xFF;
3577 buf[3] = (addr >> 0) & 0xFF;
3578 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 4, (uint8_t *)data, (uint32_t)len);
3581 handle->
debug_print(
"w25qxx: only spi read failed.\n");
3590 buf[1] = (addr >> 24) & 0xFF;
3591 buf[2] = (addr >> 16) & 0xFF;
3592 buf[3] = (addr >> 8) & 0xFF;
3593 buf[4] = (addr >> 0) & 0xFF;
3594 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 5, (uint8_t *)data, (uint32_t)len);
3597 handle->
debug_print(
"w25qxx: only spi read failed.\n");
3604 handle->
debug_print(
"w25qxx: address mode is invalid.\n");
3612 handle->
debug_print(
"w25qxx: only spi interface can use this function.\n");
3657 0x00000000, 0x00, 0x00,
3658 0x00000000, 0x00, 0x00,
3663 handle->
debug_print(
"w25qxx: write enable failed.\n");
3667 buf[0] = (addr >> 24) & 0xFF;
3668 res = a_w25qxx_qspi_write_read(handle, 0xC5, 1,
3669 0x00000000, 0x00, 0x00,
3670 0x00000000, 0x00, 0x00,
3671 0, (uint8_t *)buf, 0x01,
3675 handle->
debug_print(
"w25qxx: write extended addr register failed.\n");
3682 0x00000000, 0x00, 0x00,
3687 handle->
debug_print(
"w25qxx: fast read failed.\n");
3696 0x00000000, 0x00, 0x00,
3701 handle->
debug_print(
"w25qxx: fast read failed.\n");
3708 handle->
debug_print(
"w25qxx: address mode is invalid.\n");
3720 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 1, NULL, 0);
3723 handle->
debug_print(
"w25qxx: write enable failed.\n");
3728 buf[1] = (addr >> 24) & 0xFF;
3729 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 2, NULL, 0);
3732 handle->
debug_print(
"w25qxx: write extended addr register failed.\n");
3738 buf[1] = (addr >> 16) & 0xFF;
3739 buf[2] = (addr >> 8) & 0xFF;
3740 buf[3] = (addr >> 0) & 0xFF;
3742 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 5, (uint8_t *)data, (uint32_t)len);
3745 handle->
debug_print(
"w25qxx: fast read failed.\n");
3754 buf[1] = (addr >> 24) & 0xFF;
3755 buf[2] = (addr >> 16) & 0xFF;
3756 buf[3] = (addr >> 8) & 0xFF;
3757 buf[4] = (addr >> 0) & 0xFF;
3759 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 6, (uint8_t *)data, (uint32_t)len);
3762 handle->
debug_print(
"w25qxx: fast read failed.\n");
3769 handle->
debug_print(
"w25qxx: address mode is invalid.\n");
3782 0x00000000, 0x00, 0x00,
3783 0x00000000, 0x00, 0x00,
3788 handle->
debug_print(
"w25qxx: write enable failed.\n");
3792 buf[0] = (addr >> 24) & 0xFF;
3793 res = a_w25qxx_qspi_write_read(handle, 0xC5, 4,
3794 0x00000000, 0x00, 0x00,
3795 0x00000000, 0x00, 0x00,
3796 0, (uint8_t *)buf, 0x01,
3800 handle->
debug_print(
"w25qxx: write extended addr register failed.\n");
3807 0x00000000, 0x00, 0x00,
3808 handle->
dummy, NULL, 0x00,
3812 handle->
debug_print(
"w25qxx: fast read failed.\n");
3821 0x00000000, 0x00, 0x00,
3822 handle->
dummy, NULL, 0x00,
3826 handle->
debug_print(
"w25qxx: fast read failed.\n");
3833 handle->
debug_print(
"w25qxx: address mode is invalid.\n");
3876 handle->
debug_print(
"w25qxx: standard spi can't use this function failed.\n");
3885 0x00000000, 0x00, 0x00,
3886 0x00000000, 0x00, 0x00,
3891 handle->
debug_print(
"w25qxx: write enable failed.\n");
3895 buf[0] = (addr >> 24) & 0xFF;
3896 res = a_w25qxx_qspi_write_read(handle, 0xC5, 1,
3897 0x00000000, 0x00, 0x00,
3898 0x00000000, 0x00, 0x00,
3899 0, (uint8_t *)buf, 0x01,
3903 handle->
debug_print(
"w25qxx: write extended addr register failed.\n");
3910 0x00000000, 0x00, 0x00,
3915 handle->
debug_print(
"w25qxx: fast read dual output failed.\n");
3924 0x00000000, 0x00, 0x00,
3929 handle->
debug_print(
"w25qxx: fast read dual output failed.\n");
3936 handle->
debug_print(
"w25qxx: address mode is invalid.\n");
3943 handle->
debug_print(
"w25qxx: qspi can't use this function.\n");
3985 handle->
debug_print(
"w25qxx: standard spi can't use this function failed.\n");
3994 0x00000000, 0x00, 0x00,
3995 0x00000000, 0x00, 0x00,
4000 handle->
debug_print(
"w25qxx: write enable failed.\n");
4004 buf[0] = (addr >> 24) & 0xFF;
4005 res = a_w25qxx_qspi_write_read(handle, 0xC5, 1,
4006 0x00000000, 0x00, 0x00,
4007 0x00000000, 0x00, 0x00,
4008 0, (uint8_t *)buf, 0x01,
4012 handle->
debug_print(
"w25qxx: write extended addr register failed.\n");
4019 0x00000000, 0x00, 0x00,
4024 handle->
debug_print(
"w25qxx: fast read quad output failed.\n");
4033 0x00000000, 0x00, 0x00,
4038 handle->
debug_print(
"w25qxx: fast read quad output failed.\n");
4045 handle->
debug_print(
"w25qxx: address mode is invalid.\n");
4052 handle->
debug_print(
"w25qxx: qspi can't use this function.\n");
4094 handle->
debug_print(
"w25qxx: standard spi can't use this function failed.\n");
4103 0x00000000, 0x00, 0x00,
4104 0x00000000, 0x00, 0x00,
4109 handle->
debug_print(
"w25qxx: write enable failed.\n");
4113 buf[0] = (addr >> 24) & 0xFF;
4114 res = a_w25qxx_qspi_write_read(handle, 0xC5, 1,
4115 0x00000000, 0x00, 0x00,
4116 0x00000000, 0x00, 0x00,
4117 0, (uint8_t *)buf, 0x01,
4121 handle->
debug_print(
"w25qxx: write extended addr register failed.\n");
4133 handle->
debug_print(
"w25qxx: fast read dual io failed.\n");
4147 handle->
debug_print(
"w25qxx: fast read dual io failed.\n");
4154 handle->
debug_print(
"w25qxx: address mode is invalid.\n");
4161 handle->
debug_print(
"w25qxx: qspi can't use this function.\n");
4202 handle->
debug_print(
"w25qxx: standard spi can't use this function failed.\n");
4211 0x00000000, 0x00, 0x00,
4212 0x00000000, 0x00, 0x00,
4217 handle->
debug_print(
"w25qxx: write enable failed.\n");
4221 buf[0] = (addr >> 24) & 0xFF;
4222 res = a_w25qxx_qspi_write_read(handle, 0xC5, 1,
4223 0x00000000, 0x00, 0x00,
4224 0x00000000, 0x00, 0x00,
4225 0, (uint8_t *)buf, 0x01,
4229 handle->
debug_print(
"w25qxx: write extended addr register failed.\n");
4241 handle->
debug_print(
"w25qxx: fast read quad io failed.\n");
4255 handle->
debug_print(
"w25qxx: fast read quad io failed.\n");
4262 handle->
debug_print(
"w25qxx: address mode is invalid.\n");
4274 0x00000000, 0x00, 0x00,
4275 0x00000000, 0x00, 0x00,
4280 handle->
debug_print(
"w25qxx: write enable failed.\n");
4284 buf[0] = (addr >> 24) & 0xFF;
4285 res = a_w25qxx_qspi_write_read(handle, 0xC5, 4,
4286 0x00000000, 0x00, 0x00,
4287 0x00000000, 0x00, 0x00,
4288 0, (uint8_t *)buf, 0x01,
4292 handle->
debug_print(
"w25qxx: write extended addr register failed.\n");
4300 handle->
dummy, NULL, 0x00,
4304 handle->
debug_print(
"w25qxx: fast read quad io failed.\n");
4314 handle->
dummy, NULL, 0x00,
4318 handle->
debug_print(
"w25qxx: fast read quad io failed.\n");
4325 handle->
debug_print(
"w25qxx: address mode is invalid.\n");
4368 handle->
debug_print(
"w25qxx: standard spi can't use this function failed.\n");
4377 0x00000000, 0x00, 0x00,
4378 0x00000000, 0x00, 0x00,
4383 handle->
debug_print(
"w25qxx: write enable failed.\n");
4387 buf[0] = (addr >> 24) & 0xFF;
4388 res = a_w25qxx_qspi_write_read(handle, 0xC5, 1,
4389 0x00000000, 0x00, 0x00,
4390 0x00000000, 0x00, 0x00,
4391 0, (uint8_t *)buf, 0x01,
4395 handle->
debug_print(
"w25qxx: write extended addr register failed.\n");
4407 handle->
debug_print(
"w25qxx: word read quad io failed.\n");
4421 handle->
debug_print(
"w25qxx: word read quad io failed.\n");
4428 handle->
debug_print(
"w25qxx: address mode is invalid.\n");
4435 handle->
debug_print(
"w25qxx: qspi can't use this function.\n");
4477 handle->
debug_print(
"w25qxx: standard spi can't use this function failed.\n");
4486 0x00000000, 0x00, 0x00,
4487 0x00000000, 0x00, 0x00,
4492 handle->
debug_print(
"w25qxx: write enable failed.\n");
4496 buf[0] = (addr >> 24) & 0xFF;
4497 res = a_w25qxx_qspi_write_read(handle, 0xC5, 1,
4498 0x00000000, 0x00, 0x00,
4499 0x00000000, 0x00, 0x00,
4500 0, (uint8_t *)buf, 0x01,
4504 handle->
debug_print(
"w25qxx: write extended addr register failed.\n");
4516 handle->
debug_print(
"w25qxx: octal word read quad io failed.\n");
4530 handle->
debug_print(
"w25qxx: octal word read quad io failed.\n");
4537 handle->
debug_print(
"w25qxx: address mode is invalid.\n");
4544 handle->
debug_print(
"w25qxx: qspi can't use this function.\n");
4584 if ((addr % 256) != 0)
4586 handle->
debug_print(
"w25qxx: addr is invalid.\n");
4592 handle->
debug_print(
"w25qxx: length is over 256.\n");
4602 0x00000000, 0x00, 0x00,
4603 0x00000000, 0x00, 0x00,
4608 handle->
debug_print(
"w25qxx: write enable failed.\n");
4616 buf[0] = (addr >> 24) & 0xFF;
4617 res = a_w25qxx_qspi_write_read(handle, 0xC5, 1,
4618 0x00000000, 0x00, 0x00,
4619 0x00000000, 0x00, 0x00,
4620 0, (uint8_t *)buf, 0x01,
4624 handle->
debug_print(
"w25qxx: write extended addr register failed.\n");
4629 0x00000000, 0x00, 0x00,
4630 0x00000000, 0x00, 0x00,
4635 handle->
debug_print(
"w25qxx: write enable failed.\n");
4642 0x00000000, 0x00, 0x00,
4647 handle->
debug_print(
"w25qxx: page program failed.\n");
4656 0x00000000, 0x00, 0x00,
4661 handle->
debug_print(
"w25qxx: page program failed.\n");
4668 handle->
debug_print(
"w25qxx: address mode is invalid.\n");
4674 while (timeout != 0)
4677 0x00000000, 0x00, 0x00,
4678 0x00000000, 0x00, 0x00,
4680 (uint8_t *)&status, 1, 1);
4683 handle->
debug_print(
"w25qxx: page program failed.\n");
4687 if ((status & 0x01) == 0x00)
4696 handle->
debug_print(
"w25qxx: page program timeout.\n");
4704 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 1, NULL, 0);
4707 handle->
debug_print(
"w25qxx: write enable failed.\n");
4716 buf[1] = (addr >> 24) & 0xFF;
4717 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 2, NULL, 0);
4720 handle->
debug_print(
"w25qxx: write extended addr register failed.\n");
4725 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 1, NULL, 0);
4728 handle->
debug_print(
"w25qxx: write enable failed.\n");
4734 handle->
buf[1] = (addr >> 16) & 0xFF;
4735 handle->
buf[2] = (addr >> 8) & 0xFF;
4736 handle->
buf[3] = (addr >> 0) & 0xFF;
4737 memcpy(&handle->
buf[4], data, len);
4738 res = a_w25qxx_spi_write_read(handle, (uint8_t *)handle->
buf, 4 + len, NULL, 0);
4741 handle->
debug_print(
"w25qxx: page program failed.\n");
4750 handle->
buf[1] = (addr >> 24) & 0xFF;
4751 handle->
buf[2] = (addr >> 16) & 0xFF;
4752 handle->
buf[3] = (addr >> 8) & 0xFF;
4753 handle->
buf[4] = (addr >> 0) & 0xFF;
4754 memcpy(&handle->
buf[5], data, len);
4755 res = a_w25qxx_spi_write_read(handle, (uint8_t *)handle->
buf, 5 + len, NULL, 0);
4758 handle->
debug_print(
"w25qxx: page program failed.\n");
4765 handle->
debug_print(
"w25qxx: address mode is invalid.\n");
4771 while (timeout != 0)
4774 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 1, (uint8_t *)&status, 1);
4777 handle->
debug_print(
"w25qxx: get status1 failed.\n");
4781 if ((status & 0x01) == 0x00)
4790 handle->
debug_print(
"w25qxx: page program timeout.\n");
4799 0x00000000, 0x00, 0x00,
4800 0x00000000, 0x00, 0x00,
4805 handle->
debug_print(
"w25qxx: write enable failed.\n");
4813 buf[0] = (addr >> 24) & 0xFF;
4814 res = a_w25qxx_qspi_write_read(handle, 0xC5, 4,
4815 0x00000000, 0x00, 0x00,
4816 0x00000000, 0x00, 0x00,
4817 0, (uint8_t *)buf, 0x01,
4821 handle->
debug_print(
"w25qxx: write extended addr register failed.\n");
4826 0x00000000, 0x00, 0x00,
4827 0x00000000, 0x00, 0x00,
4832 handle->
debug_print(
"w25qxx: write enable failed.\n");
4839 0x00000000, 0x00, 0x00,
4844 handle->
debug_print(
"w25qxx: page program failed.\n");
4853 0x00000000, 0x00, 0x00,
4858 handle->
debug_print(
"w25qxx: page program failed.\n");
4865 handle->
debug_print(
"w25qxx: address mode is invalid.\n");
4871 while (timeout != 0)
4874 0x00000000, 0x00, 0x00,
4875 0x00000000, 0x00, 0x00,
4877 (uint8_t *)&status, 1, 4);
4880 handle->
debug_print(
"w25qxx: page program failed.\n");
4884 if ((status & 0x01) == 0x00)
4893 handle->
debug_print(
"w25qxx: page program timeout.\n");
4935 if ((addr % 256) != 0)
4937 handle->
debug_print(
"w25qxx: addr is invalid.\n");
4943 handle->
debug_print(
"w25qxx: length is over 256.\n");
4950 handle->
debug_print(
"w25qxx: qspi can't use this function.\n");
4958 handle->
debug_print(
"w25qxx: standard spi can't use this function failed.\n");
4963 0x00000000, 0x00, 0x00,
4964 0x00000000, 0x00, 0x00,
4969 handle->
debug_print(
"w25qxx: write enable failed.\n");
4977 buf[0] = (addr >> 24) & 0xFF;
4978 res = a_w25qxx_qspi_write_read(handle, 0xC5, 1,
4979 0x00000000, 0x00, 0x00,
4980 0x00000000, 0x00, 0x00,
4981 0, (uint8_t *)buf, 0x01,
4985 handle->
debug_print(
"w25qxx: write extended addr register failed.\n");
4990 0x00000000, 0x00, 0x00,
4991 0x00000000, 0x00, 0x00,
4996 handle->
debug_print(
"w25qxx: write enable failed.\n");
5003 0x00000000, 0x00, 0x00,
5008 handle->
debug_print(
"w25qxx: quad page program failed.\n");
5017 0x00000000, 0x00, 0x00,
5022 handle->
debug_print(
"w25qxx: quad page program failed.\n");
5029 handle->
debug_print(
"w25qxx: address mode is invalid.\n");
5035 while (timeout != 0)
5038 0x00000000, 0x00, 0x00,
5039 0x00000000, 0x00, 0x00,
5041 (uint8_t *)&status, 1, 1);
5044 handle->
debug_print(
"w25qxx: get status1 failed.\n");
5048 if ((status & 0x01) == 0x00)
5057 handle->
debug_print(
"w25qxx: quad page program timeout.\n");
5095 if ((addr % 4096) != 0)
5097 handle->
debug_print(
"w25qxx: addr is invalid.\n");
5107 0x00000000, 0x00, 0x00,
5108 0x00000000, 0x00, 0x00,
5113 handle->
debug_print(
"w25qxx: write enable failed.\n");
5121 buf[0] = (addr >> 24) & 0xFF;
5122 res = a_w25qxx_qspi_write_read(handle, 0xC5, 1,
5123 0x00000000, 0x00, 0x00,
5124 0x00000000, 0x00, 0x00,
5125 0, (uint8_t *)buf, 0x01,
5129 handle->
debug_print(
"w25qxx: write extended addr register failed.\n");
5134 0x00000000, 0x00, 0x00,
5135 0x00000000, 0x00, 0x00,
5140 handle->
debug_print(
"w25qxx: write enable failed.\n");
5147 0x00000000, 0x00, 0x00,
5152 handle->
debug_print(
"w25qxx: sector erase 4k failed.\n");
5161 0x00000000, 0x00, 0x00,
5166 handle->
debug_print(
"w25qxx: sector erase 4k failed.\n");
5173 handle->
debug_print(
"w25qxx: address mode is invalid.\n");
5179 while (timeout != 0)
5182 0x00000000, 0x00, 0x00,
5183 0x00000000, 0x00, 0x00,
5185 (uint8_t *)&status, 1, 1);
5188 handle->
debug_print(
"w25qxx: get status1 failed.\n");
5192 if ((status & 0x01) == 0x00)
5201 handle->
debug_print(
"w25qxx: sector erase 4k timeout.\n");
5209 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 1, NULL, 0);
5212 handle->
debug_print(
"w25qxx: write enable failed.\n");
5221 buf[1] = (addr >> 24) & 0xFF;
5222 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 2, NULL, 0);
5225 handle->
debug_print(
"w25qxx: write extended addr register failed.\n");
5230 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 1, NULL, 0);
5233 handle->
debug_print(
"w25qxx: write enable failed.\n");
5239 buf[1] = (addr >> 16) & 0xFF;
5240 buf[2] = (addr >> 8) & 0xFF;
5241 buf[3] = (addr >> 0) & 0xFF;
5242 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 4, NULL, 0);
5245 handle->
debug_print(
"w25qxx: sector erase 4k failed.\n");
5254 buf[1] = (addr >> 24) & 0xFF;
5255 buf[2] = (addr >> 16) & 0xFF;
5256 buf[3] = (addr >> 8) & 0xFF;
5257 buf[4] = (addr >> 0) & 0xFF;
5258 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 5, NULL, 0);
5261 handle->
debug_print(
"w25qxx: sector erase 4k failed.\n");
5268 handle->
debug_print(
"w25qxx: address mode is invalid.\n");
5274 while (timeout != 0)
5277 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 1, (uint8_t *)&status, 1);
5280 handle->
debug_print(
"w25qxx: get status1 failed.\n");
5284 if ((status & 0x01) == 0x00)
5293 handle->
debug_print(
"w25qxx: sector erase 4k timeout.\n");
5302 0x00000000, 0x00, 0x00,
5303 0x00000000, 0x00, 0x00,
5308 handle->
debug_print(
"w25qxx: write enable failed.\n");
5316 buf[0] = (addr >> 24) & 0xFF;
5317 res = a_w25qxx_qspi_write_read(handle, 0xC5, 4,
5318 0x00000000, 0x00, 0x00,
5319 0x00000000, 0x00, 0x00,
5320 0, (uint8_t *)buf, 0x01,
5324 handle->
debug_print(
"w25qxx: write extended addr register failed.\n");
5329 0x00000000, 0x00, 0x00,
5330 0x00000000, 0x00, 0x00,
5335 handle->
debug_print(
"w25qxx: write enable failed.\n");
5342 0x00000000, 0x00, 0x00,
5347 handle->
debug_print(
"w25qxx: sector erase 4k failed.\n");
5356 0x00000000, 0x00, 0x00,
5361 handle->
debug_print(
"w25qxx: sector erase 4k failed.\n");
5368 handle->
debug_print(
"w25qxx: address mode is invalid.\n");
5374 while (timeout != 0)
5377 0x00000000, 0x00, 0x00,
5378 0x00000000, 0x00, 0x00,
5380 (uint8_t *)&status, 1, 4);
5383 handle->
debug_print(
"w25qxx: get status1 failed.\n");
5387 if ((status & 0x01) == 0x00)
5396 handle->
debug_print(
"w25qxx: sector erase 4k timeout.\n");
5434 if ((addr % (32 * 1024)) != 0)
5436 handle->
debug_print(
"w25qxx: addr is invalid.\n");
5446 0x00000000, 0x00, 0x00,
5447 0x00000000, 0x00, 0x00,
5452 handle->
debug_print(
"w25qxx: write enable failed.\n");
5460 buf[0] = (addr >> 24) & 0xFF;
5461 res = a_w25qxx_qspi_write_read(handle, 0xC5, 1,
5462 0x00000000, 0x00, 0x00,
5463 0x00000000, 0x00, 0x00,
5464 0, (uint8_t *)buf, 0x01,
5468 handle->
debug_print(
"w25qxx: write extended addr register failed.\n");
5473 0x00000000, 0x00, 0x00,
5474 0x00000000, 0x00, 0x00,
5479 handle->
debug_print(
"w25qxx: write enable failed.\n");
5486 0x00000000, 0x00, 0x00,
5491 handle->
debug_print(
"w25qxx: block erase 32k failed.\n");
5500 0x00000000, 0x00, 0x00,
5505 handle->
debug_print(
"w25qxx: block erase 32k failed.\n");
5512 handle->
debug_print(
"w25qxx: address mode is invalid.\n");
5518 while (timeout != 0)
5521 0x00000000, 0x00, 0x00,
5522 0x00000000, 0x00, 0x00,
5524 (uint8_t *)&status, 1, 1);
5527 handle->
debug_print(
"w25qxx: get status1 failed.\n");
5531 if ((status & 0x01) == 0x00)
5540 handle->
debug_print(
"w25qxx: block erase 32k timeout.\n");
5548 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 1, NULL, 0);
5551 handle->
debug_print(
"w25qxx: write enable failed.\n");
5560 buf[1] = (addr >> 24) & 0xFF;
5561 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 2, NULL, 0);
5564 handle->
debug_print(
"w25qxx: write extended addr register failed.\n");
5569 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 1, NULL, 0);
5572 handle->
debug_print(
"w25qxx: write enable failed.\n");
5578 buf[1] = (addr >> 16) & 0xFF;
5579 buf[2] = (addr >> 8) & 0xFF;
5580 buf[3] = (addr >> 0) & 0xFF;
5581 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 4, NULL, 0);
5584 handle->
debug_print(
"w25qxx: block erase 32k failed.\n");
5593 buf[1] = (addr >> 24) & 0xFF;
5594 buf[2] = (addr >> 16) & 0xFF;
5595 buf[3] = (addr >> 8) & 0xFF;
5596 buf[4] = (addr >> 0) & 0xFF;
5597 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 5, NULL, 0);
5600 handle->
debug_print(
"w25qxx: block erase 32k failed.\n");
5607 handle->
debug_print(
"w25qxx: address mode is invalid.\n");
5613 while (timeout != 0)
5616 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 1, (uint8_t *)&status, 1);
5619 handle->
debug_print(
"w25qxx: get status1 failed.\n");
5623 if ((status & 0x01) == 0x00)
5632 handle->
debug_print(
"w25qxx: block erase 32k timeout.\n");
5641 0x00000000, 0x00, 0x00,
5642 0x00000000, 0x00, 0x00,
5647 handle->
debug_print(
"w25qxx: write enable failed.\n");
5655 buf[0] = (addr >> 24) & 0xFF;
5656 res = a_w25qxx_qspi_write_read(handle, 0xC5, 4,
5657 0x00000000, 0x00, 0x00,
5658 0x00000000, 0x00, 0x00,
5659 0, (uint8_t *)buf, 0x01,
5663 handle->
debug_print(
"w25qxx: write extended addr register failed.\n");
5668 0x00000000, 0x00, 0x00,
5669 0x00000000, 0x00, 0x00,
5674 handle->
debug_print(
"w25qxx: write enable failed.\n");
5681 0x00000000, 0x00, 0x00,
5686 handle->
debug_print(
"w25qxx: block erase 32k failed.\n");
5695 0x00000000, 0x00, 0x00,
5700 handle->
debug_print(
"w25qxx: block erase 32k failed.\n");
5707 handle->
debug_print(
"w25qxx: address mode is invalid.\n");
5713 while (timeout != 0)
5716 0x00000000, 0x00, 0x00,
5717 0x00000000, 0x00, 0x00,
5719 (uint8_t *)&status, 1, 4);
5722 handle->
debug_print(
"w25qxx: get status1 failed.\n");
5726 if ((status & 0x01) == 0x00)
5735 handle->
debug_print(
"w25qxx: block erase 32k timeout.\n");
5773 if ((addr % (64 * 1024)) != 0)
5775 handle->
debug_print(
"w25qxx: addr is invalid.\n");
5785 0x00000000, 0x00, 0x00,
5786 0x00000000, 0x00, 0x00,
5791 handle->
debug_print(
"w25qxx: write enable failed.\n");
5799 buf[0] = (addr >> 24) & 0xFF;
5800 res = a_w25qxx_qspi_write_read(handle, 0xC5, 1,
5801 0x00000000, 0x00, 0x00,
5802 0x00000000, 0x00, 0x00,
5803 0, (uint8_t *)buf, 0x01,
5807 handle->
debug_print(
"w25qxx: write extended addr register failed.\n");
5812 0x00000000, 0x00, 0x00,
5813 0x00000000, 0x00, 0x00,
5818 handle->
debug_print(
"w25qxx: write enable failed.\n");
5825 0x00000000, 0x00, 0x00,
5830 handle->
debug_print(
"w25qxx: block erase 64k failed.\n");
5839 0x00000000, 0x00, 0x00,
5844 handle->
debug_print(
"w25qxx: block erase 64k failed.\n");
5851 handle->
debug_print(
"w25qxx: address mode is invalid.\n");
5857 while (timeout != 0)
5860 0x00000000, 0x00, 0x00,
5861 0x00000000, 0x00, 0x00,
5863 (uint8_t *)&status, 1, 1);
5866 handle->
debug_print(
"w25qxx: get status1 failed.\n");
5870 if ((status & 0x01) == 0x00)
5879 handle->
debug_print(
"w25qxx: block erase 64k timeout.\n");
5887 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 1, NULL, 0);
5890 handle->
debug_print(
"w25qxx: write enable failed.\n");
5899 buf[1] = (addr >> 24) & 0xFF;
5900 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 2, NULL, 0);
5903 handle->
debug_print(
"w25qxx: write extended addr register failed.\n");
5908 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 1, NULL, 0);
5911 handle->
debug_print(
"w25qxx: write enable failed.\n");
5917 buf[1] = (addr >> 16) & 0xFF;
5918 buf[2] = (addr >> 8) & 0xFF;
5919 buf[3] = (addr >> 0) & 0xFF;
5920 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 4, NULL, 0);
5923 handle->
debug_print(
"w25qxx: block erase 64k failed.\n");
5931 buf[1] = (addr >> 24) & 0xFF;
5932 buf[2] = (addr >> 16) & 0xFF;
5933 buf[3] = (addr >> 8) & 0xFF;
5934 buf[4] = (addr >> 0) & 0xFF;
5935 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 5, NULL, 0);
5938 handle->
debug_print(
"w25qxx: block erase 64k failed.\n");
5945 handle->
debug_print(
"w25qxx: address mode is invalid.\n");
5951 while (timeout != 0)
5954 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 1, (uint8_t *)&status, 1);
5957 handle->
debug_print(
"w25qxx: get status1 failed.\n");
5961 if ((status & 0x01) == 0x00)
5970 handle->
debug_print(
"w25qxx: block erase 64k timeout.\n");
5979 0x00000000, 0x00, 0x00,
5980 0x00000000, 0x00, 0x00,
5985 handle->
debug_print(
"w25qxx: write enable failed.\n");
5993 buf[0] = (addr >> 24) & 0xFF;
5994 res = a_w25qxx_qspi_write_read(handle, 0xC5, 4,
5995 0x00000000, 0x00, 0x00,
5996 0x00000000, 0x00, 0x00,
5997 0, (uint8_t *)buf, 0x01,
6001 handle->
debug_print(
"w25qxx: write extended addr register failed.\n");
6006 0x00000000, 0x00, 0x00,
6007 0x00000000, 0x00, 0x00,
6012 handle->
debug_print(
"w25qxx: write enable failed.\n");
6019 0x00000000, 0x00, 0x00,
6024 handle->
debug_print(
"w25qxx: block erase 64k failed.\n");
6033 0x00000000, 0x00, 0x00,
6038 handle->
debug_print(
"w25qxx: block erase 64k failed.\n");
6045 handle->
debug_print(
"w25qxx: address mode is invalid.\n");
6051 while (timeout != 0)
6054 0x00000000, 0x00, 0x00,
6055 0x00000000, 0x00, 0x00,
6057 (uint8_t *)&status, 1, 4);
6060 handle->
debug_print(
"w25qxx: get status1 failed.\n");
6064 if ((status & 0x01) == 0x00)
6073 handle->
debug_print(
"w25qxx: block erase 64k timeout.\n");
6117 0x00000000, 0x00, 0x00,
6118 0x00000000, 0x00, 0x00,
6123 handle->
debug_print(
"w25qxx: write enable failed.\n");
6127 buf[0] = (addr >> 24) & 0xFF;
6128 res = a_w25qxx_qspi_write_read(handle, 0xC5, 1,
6129 0x00000000, 0x00, 0x00,
6130 0x00000000, 0x00, 0x00,
6131 0, (uint8_t *)buf, 0x01,
6135 handle->
debug_print(
"w25qxx: write extended addr register failed.\n");
6142 0x00000000, 0x00, 0x00,
6147 handle->
debug_print(
"w25qxx: individual block lock failed.\n");
6156 0x00000000, 0x00, 0x00,
6161 handle->
debug_print(
"w25qxx: individual block lock failed.\n");
6168 handle->
debug_print(
"w25qxx: address mode is invalid.\n");
6180 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 1, NULL, 0);
6183 handle->
debug_print(
"w25qxx: write enable failed.\n");
6188 buf[1] = (addr >> 24) & 0xFF;
6189 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 2, NULL, 0);
6192 handle->
debug_print(
"w25qxx: write extended addr register failed.\n");
6198 buf[1] = (addr >> 16) & 0xFF;
6199 buf[2] = (addr >> 8) & 0xFF;
6200 buf[3] = (addr >> 0) & 0xFF;
6201 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 4, NULL, 0);
6204 handle->
debug_print(
"w25qxx: individual block lock failed.\n");
6212 buf[1] = (addr >> 24) & 0xFF;
6213 buf[2] = (addr >> 16) & 0xFF;
6214 buf[3] = (addr >> 8) & 0xFF;
6215 buf[4] = (addr >> 0) & 0xFF;
6216 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 5, NULL, 0);
6219 handle->
debug_print(
"w25qxx: individual block lock failed.\n");
6226 handle->
debug_print(
"w25qxx: address mode is invalid.\n");
6239 0x00000000, 0x00, 0x00,
6240 0x00000000, 0x00, 0x00,
6245 handle->
debug_print(
"w25qxx: write enable failed.\n");
6249 buf[0] = (addr >> 24) & 0xFF;
6250 res = a_w25qxx_qspi_write_read(handle, 0xC5, 4,
6251 0x00000000, 0x00, 0x00,
6252 0x00000000, 0x00, 0x00,
6253 0, (uint8_t *)buf, 0x01,
6257 handle->
debug_print(
"w25qxx: write extended addr register failed.\n");
6264 0x00000000, 0x00, 0x00,
6269 handle->
debug_print(
"w25qxx: individual block lock failed.\n");
6278 0x00000000, 0x00, 0x00,
6283 handle->
debug_print(
"w25qxx: individual block lock failed.\n");
6290 handle->
debug_print(
"w25qxx: address mode is invalid.\n");
6334 0x00000000, 0x00, 0x00,
6335 0x00000000, 0x00, 0x00,
6340 handle->
debug_print(
"w25qxx: write enable failed.\n");
6344 buf[0] = (addr >> 24) & 0xFF;
6345 res = a_w25qxx_qspi_write_read(handle, 0xC5, 1,
6346 0x00000000, 0x00, 0x00,
6347 0x00000000, 0x00, 0x00,
6348 0, (uint8_t *)buf, 0x01,
6352 handle->
debug_print(
"w25qxx: write extended addr register failed.\n");
6359 0x00000000, 0x00, 0x00,
6364 handle->
debug_print(
"w25qxx: individual block unlock failed.\n");
6373 0x00000000, 0x00, 0x00,
6378 handle->
debug_print(
"w25qxx: individual block unlock failed.\n");
6385 handle->
debug_print(
"w25qxx: address mode is invalid.\n");
6397 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 1, NULL, 0);
6400 handle->
debug_print(
"w25qxx: write enable failed.\n");
6405 buf[1] = (addr >> 24) & 0xFF;
6406 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 2, NULL, 0);
6409 handle->
debug_print(
"w25qxx: write extended addr register failed.\n");
6415 buf[1] = (addr >> 16) & 0xFF;
6416 buf[2] = (addr >> 8) & 0xFF;
6417 buf[3] = (addr >> 0) & 0xFF;
6418 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 4, NULL, 0);
6421 handle->
debug_print(
"w25qxx: individual block unlock failed.\n");
6429 buf[1] = (addr >> 24) & 0xFF;
6430 buf[2] = (addr >> 16) & 0xFF;
6431 buf[3] = (addr >> 8) & 0xFF;
6432 buf[4] = (addr >> 0) & 0xFF;
6433 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 5, NULL, 0);
6436 handle->
debug_print(
"w25qxx: individual block unlock failed.\n");
6443 handle->
debug_print(
"w25qxx: address mode is invalid.\n");
6456 0x00000000, 0x00, 0x00,
6457 0x00000000, 0x00, 0x00,
6462 handle->
debug_print(
"w25qxx: write enable failed.\n");
6466 buf[0] = (addr >> 24) & 0xFF;
6467 res = a_w25qxx_qspi_write_read(handle, 0xC5, 4,
6468 0x00000000, 0x00, 0x00,
6469 0x00000000, 0x00, 0x00,
6470 0, (uint8_t *)buf, 0x01,
6474 handle->
debug_print(
"w25qxx: write extended addr register failed.\n");
6481 0x00000000, 0x00, 0x00,
6486 handle->
debug_print(
"w25qxx: individual block unlock failed.\n");
6495 0x00000000, 0x00, 0x00,
6500 handle->
debug_print(
"w25qxx: individual block unlock failed.\n");
6507 handle->
debug_print(
"w25qxx: address mode is invalid.\n");
6552 0x00000000, 0x00, 0x00,
6553 0x00000000, 0x00, 0x00,
6558 handle->
debug_print(
"w25qxx: write enable failed.\n");
6562 buf[0] = (addr >> 24) & 0xFF;
6563 res = a_w25qxx_qspi_write_read(handle, 0xC5, 1,
6564 0x00000000, 0x00, 0x00,
6565 0x00000000, 0x00, 0x00,
6566 0, (uint8_t *)buf, 0x01,
6570 handle->
debug_print(
"w25qxx: write extended addr register failed.\n");
6577 0x00000000, 0x00, 0x00,
6582 handle->
debug_print(
"w25qxx: read block lock failed.\n");
6591 0x00000000, 0x00, 0x00,
6596 handle->
debug_print(
"w25qxx: read block lock failed.\n");
6603 handle->
debug_print(
"w25qxx: address mode is invalid.\n");
6615 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 1, NULL, 0);
6618 handle->
debug_print(
"w25qxx: write enable failed.\n");
6623 buf[1] = (addr >> 24) & 0xFF;
6624 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 2, NULL, 0);
6627 handle->
debug_print(
"w25qxx: write extended addr register failed.\n");
6633 buf[1] = (addr >> 16) & 0xFF;
6634 buf[2] = (addr >> 8) & 0xFF;
6635 buf[3] = (addr >> 0) & 0xFF;
6636 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 4, value, 1);
6639 handle->
debug_print(
"w25qxx: read block lock failed.\n");
6647 buf[1] = (addr >> 24) & 0xFF;
6648 buf[2] = (addr >> 16) & 0xFF;
6649 buf[3] = (addr >> 8) & 0xFF;
6650 buf[4] = (addr >> 0) & 0xFF;
6651 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 5, value, 1);
6654 handle->
debug_print(
"w25qxx: read block lock failed.\n");
6661 handle->
debug_print(
"w25qxx: address mode is invalid.\n");
6674 0x00000000, 0x00, 0x00,
6675 0x00000000, 0x00, 0x00,
6680 handle->
debug_print(
"w25qxx: write enable failed.\n");
6684 buf[0] = (addr >> 24) & 0xFF;
6685 res = a_w25qxx_qspi_write_read(handle, 0xC5, 4,
6686 0x00000000, 0x00, 0x00,
6687 0x00000000, 0x00, 0x00,
6688 0, (uint8_t *)buf, 0x01,
6692 handle->
debug_print(
"w25qxx: write extended addr register failed.\n");
6699 0x00000000, 0x00, 0x00,
6704 handle->
debug_print(
"w25qxx: read block lock failed.\n");
6713 0x00000000, 0x00, 0x00,
6718 handle->
debug_print(
"w25qxx: read block lock failed.\n");
6725 handle->
debug_print(
"w25qxx: address mode is invalid.\n");
6765 res = a_w25qxx_qspi_write_read(handle,
6767 0x00000000, 0x00, 0x00,
6768 0x00000000, 0x00, 0x00,
6769 3 * 8, (uint8_t *)buf, 1,
6773 handle->
debug_print(
"w25qxx: set burst with wrap failed.\n");
6785 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 5, NULL, 0);
6788 handle->
debug_print(
"w25qxx: set burst with wrap failed.\n");
6796 handle->
debug_print(
"w25qxx: qspi can't use this function.\n");
6837 handle->
debug_print(
"w25qxx: spi_qspi_init is null.\n");
6843 handle->
debug_print(
"w25qxx: spi_qspi_deinit is null.\n");
6849 handle->
debug_print(
"w25qxx: spi_qspi_write_read is null.\n");
6855 handle->
debug_print(
"w25qxx: delay_us is null.\n");
6861 handle->
debug_print(
"w25qxx: delay_ms is null.\n");
6871 handle->
debug_print(
"w25qxx: spi init failed.\n");
6877 res = a_w25qxx_qspi_write_read(handle,
6879 0x00000000, 0x00, 0x00,
6880 0x00000000, 0x00, 0x00,
6882 (uint8_t *)&
id, 1, 1);
6885 handle->
debug_print(
"w25qxx: release power down failed.\n");
6890 res = a_w25qxx_qspi_write_read(handle,
6892 0x00000000, 0x00, 0x00,
6893 0x00000000, 0x00, 0x00,
6898 handle->
debug_print(
"w25qxx: enable reset failed.\n");
6903 res = a_w25qxx_qspi_write_read(handle,
6905 0x00000000, 0x00, 0x00,
6906 0x00000000, 0x00, 0x00,
6911 handle->
debug_print(
"w25qxx: reset device failed.\n");
6919 0x00000000, 0x00, 0x00,
6921 (uint8_t *)out, 2, 1);
6924 handle->
debug_print(
"w25qxx: get manufacturer device id failed.\n");
6929 id = (uint16_t)out[0] << 8 | out[1];
6930 if (
id != handle->
type)
6939 res = a_w25qxx_qspi_write_read(handle, 0xE9, 1,
6941 0x00000000, 0x00, 0x00,
6946 handle->
debug_print(
"w25qxx: enter 3 byte mode failed.\n");
6959 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 4,
6963 handle->
debug_print(
"w25qxx: release power down failed.\n");
6969 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 1, NULL, 0);
6972 handle->
debug_print(
"w25qxx: enable reset failed.\n");
6978 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 1, NULL, 0);
6981 handle->
debug_print(
"w25qxx: reset device failed.\n");
6991 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 4,
6995 handle->
debug_print(
"w25qxx: get manufacturer device id failed.\n");
7000 id = (uint16_t)out[0] << 8 | out[1];
7001 if (
id != handle->
type)
7011 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 1, NULL, 0);
7014 handle->
debug_print(
"w25qxx: set address mode failed.\n");
7027 handle->
debug_print(
"w25qxx: qspi init failed.\n");
7031 res = a_w25qxx_qspi_write_read(handle,
7033 0x00000000, 0x00, 0x00,
7034 0x00000000, 0x00, 0x00,
7036 (uint8_t *)&
id, 1, 1);
7039 handle->
debug_print(
"w25qxx: release power down failed.\n");
7044 res = a_w25qxx_qspi_write_read(handle,
7046 0x00000000, 0x00, 0x00,
7047 0x00000000, 0x00, 0x00,
7052 handle->
debug_print(
"w25qxx: enable reset failed.\n");
7057 res = a_w25qxx_qspi_write_read(handle,
7059 0x00000000, 0x00, 0x00,
7060 0x00000000, 0x00, 0x00,
7065 handle->
debug_print(
"w25qxx: reset device failed.\n");
7071 res = a_w25qxx_qspi_write_read(handle,
7073 0x00000000, 0x00, 0x00,
7074 0x00000000, 0x00, 0x00,
7076 (uint8_t *)&status, 1, 1);
7079 handle->
debug_print(
"w25qxx: read status 2 failed.\n");
7084 if ((status & 0x02) == 0)
7086 res = a_w25qxx_qspi_write_read(handle,
7088 0x00000000, 0x00, 0x00,
7089 0x00000000, 0x00, 0x00,
7094 handle->
debug_print(
"w25qxx: set sr write enable failed.\n");
7099 res = a_w25qxx_qspi_write_read(handle,
7101 0x00000000, 0x00, 0x00,
7102 0x00000000, 0x00, 0x00,
7107 handle->
debug_print(
"w25qxx: write status 2 failed.\n");
7113 res = a_w25qxx_qspi_write_read(handle,
7115 0x00000000, 0x00, 0x00,
7116 0x00000000, 0x00, 0x00,
7121 handle->
debug_print(
"w25qxx: enter qspi failed.\n");
7128 handle->
param = buf[0];
7130 res = a_w25qxx_qspi_write_read(handle, 0xC0, 4,
7131 0x00000000, 0x00, 0x00,
7132 0x00000000, 0x00, 0x00,
7133 0, (uint8_t *)buf, 1,
7137 handle->
debug_print(
"w25qxx: set read parameters failed.\n");
7144 0x00000000, 0x00, 0x00,
7146 (uint8_t *)out, 2, 4);
7149 handle->
debug_print(
"w25qxx: get manufacturer device id failed.\n");
7154 id = (uint16_t)out[0] << 8 | out[1];
7155 if (
id != handle->
type)
7164 res = a_w25qxx_qspi_write_read(handle, 0xE9, 4,
7166 0x00000000, 0x00, 0x00,
7171 handle->
debug_print(
"w25qxx: enter 3 byte mode failed.\n");
7214 0x00000000, 0x00, 0x00,
7215 0x00000000, 0x00, 0x00,
7220 handle->
debug_print(
"w25qxx: power down failed.\n");
7228 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf,
7232 handle->
debug_print(
"w25qxx: power down failed.\n");
7240 res = a_w25qxx_qspi_write_read(handle, 0xFF, 4,
7241 0x00000000, 0x00, 0x00,
7242 0x00000000, 0x00, 0x00,
7247 handle->
debug_print(
"w25qxx: exit qspi mode failed.\n");
7253 0x00000000, 0x00, 0x00,
7254 0x00000000, 0x00, 0x00,
7259 handle->
debug_print(
"w25qxx: power down failed.\n");
7267 handle->
debug_print(
"w25qxx: spi or qspi deinit failed.\n");
7312 0x00000000, 0x00, 0x00,
7313 0x00000000, 0x00, 0x00,
7318 handle->
debug_print(
"w25qxx: write enable failed.\n");
7322 buf[0] = (addr >> 24) & 0xFF;
7323 res = a_w25qxx_qspi_write_read(handle, 0xC5, 1,
7324 0x00000000, 0x00, 0x00,
7325 0x00000000, 0x00, 0x00,
7326 0, (uint8_t *)buf, 0x01,
7330 handle->
debug_print(
"w25qxx: write extended addr register failed.\n");
7337 0x00000000, 0x00, 0x00,
7342 handle->
debug_print(
"w25qxx: fast read failed.\n");
7351 0x00000000, 0x00, 0x00,
7356 handle->
debug_print(
"w25qxx: fast read failed.\n");
7363 handle->
debug_print(
"w25qxx: address mode is invalid.\n");
7375 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 1, NULL, 0);
7378 handle->
debug_print(
"w25qxx: write enable failed.\n");
7383 buf[1] = (addr >> 24) & 0xFF;
7384 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 2, NULL, 0);
7387 handle->
debug_print(
"w25qxx: write extended addr register failed.\n");
7393 buf[1] = (addr >> 16) & 0xFF;
7394 buf[2] = (addr >> 8) & 0xFF;
7395 buf[3] = (addr >> 0) & 0xFF;
7397 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 5, (uint8_t *)data, (uint32_t)len);
7400 handle->
debug_print(
"w25qxx: fast read failed.\n");
7409 buf[1] = (addr >> 24) & 0xFF;
7410 buf[2] = (addr >> 16) & 0xFF;
7411 buf[3] = (addr >> 8) & 0xFF;
7412 buf[4] = (addr >> 0) & 0xFF;
7414 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 6, (uint8_t *)data, (uint32_t)len);
7417 handle->
debug_print(
"w25qxx: fast read failed.\n");
7424 handle->
debug_print(
"w25qxx: address mode is invalid.\n");
7437 0x00000000, 0x00, 0x00,
7438 0x00000000, 0x00, 0x00,
7443 handle->
debug_print(
"w25qxx: write enable failed.\n");
7447 buf[0] = (addr >> 24) & 0xFF;
7448 res = a_w25qxx_qspi_write_read(handle, 0xC5, 4,
7449 0x00000000, 0x00, 0x00,
7450 0x00000000, 0x00, 0x00,
7451 0, (uint8_t *)buf, 0x01,
7455 handle->
debug_print(
"w25qxx: write extended addr register failed.\n");
7462 0x00000000, 0x00, 0x00,
7463 handle->
dummy, NULL, 0x00,
7467 handle->
debug_print(
"w25qxx: fast read failed.\n");
7476 0x00000000, 0x00, 0x00,
7477 handle->
dummy, NULL, 0x00,
7481 handle->
debug_print(
"w25qxx: fast read failed.\n");
7488 handle->
debug_print(
"w25qxx: address mode is invalid.\n");
7508 static uint8_t a_w25qxx_read(
w25qxx_handle_t *handle, uint32_t addr, uint8_t *data, uint32_t len)
7522 0x00000000, 0x00, 0x00,
7523 0x00000000, 0x00, 0x00,
7528 handle->
debug_print(
"w25qxx: write enable failed.\n");
7532 buf[0] = (addr >> 24) & 0xFF;
7533 res = a_w25qxx_qspi_write_read(handle, 0xC5, 1,
7534 0x00000000, 0x00, 0x00,
7535 0x00000000, 0x00, 0x00,
7536 0, (uint8_t *)buf, 0x01,
7540 handle->
debug_print(
"w25qxx: write extended addr register failed.\n");
7547 0x00000000, 0x00, 0x00,
7552 handle->
debug_print(
"w25qxx: fast read failed.\n");
7561 0x00000000, 0x00, 0x00,
7566 handle->
debug_print(
"w25qxx: fast read failed.\n");
7573 handle->
debug_print(
"w25qxx: address mode is invalid.\n");
7585 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 1, NULL, 0);
7588 handle->
debug_print(
"w25qxx: write enable failed.\n");
7593 buf[1] = (addr >> 24) & 0xFF;
7594 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 2, NULL, 0);
7597 handle->
debug_print(
"w25qxx: write extended addr register failed.\n");
7603 buf[1] = (addr >> 16) & 0xFF;
7604 buf[2] = (addr >> 8) & 0xFF;
7605 buf[3] = (addr >> 0) & 0xFF;
7607 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 5, (uint8_t *)data, (uint32_t)len);
7610 handle->
debug_print(
"w25qxx: fast read failed.\n");
7618 buf[1] = (addr >> 24) & 0xFF;
7619 buf[2] = (addr >> 16) & 0xFF;
7620 buf[3] = (addr >> 8) & 0xFF;
7621 buf[4] = (addr >> 0) & 0xFF;
7623 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 6, (uint8_t *)data, (uint32_t)len);
7626 handle->
debug_print(
"w25qxx: fast read failed.\n");
7633 handle->
debug_print(
"w25qxx: address mode is invalid.\n");
7646 0x00000000, 0x00, 0x00,
7647 0x00000000, 0x00, 0x00,
7652 handle->
debug_print(
"w25qxx: write enable failed.\n");
7656 buf[0] = (addr >> 24) & 0xFF;
7657 res = a_w25qxx_qspi_write_read(handle, 0xC5, 4,
7658 0x00000000, 0x00, 0x00,
7659 0x00000000, 0x00, 0x00,
7660 0, (uint8_t *)buf, 0x01,
7664 handle->
debug_print(
"w25qxx: write extended addr register failed.\n");
7671 0x00000000, 0x00, 0x00,
7672 handle->
dummy, NULL, 0x00,
7676 handle->
debug_print(
"w25qxx: fast read failed.\n");
7685 0x00000000, 0x00, 0x00,
7686 handle->
dummy, NULL, 0x00,
7690 handle->
debug_print(
"w25qxx: fast read failed.\n");
7697 handle->
debug_print(
"w25qxx: address mode is invalid.\n");
7715 static uint8_t a_w25qxx_erase_sector(
w25qxx_handle_t *handle, uint32_t addr)
7727 0x00000000, 0x00, 0x00,
7728 0x00000000, 0x00, 0x00,
7733 handle->
debug_print(
"w25qxx: write enable failed.\n");
7741 buf[0] = (addr >> 24) & 0xFF;
7742 res = a_w25qxx_qspi_write_read(handle, 0xC5, 1,
7743 0x00000000, 0x00, 0x00,
7744 0x00000000, 0x00, 0x00,
7745 0, (uint8_t *)buf, 0x01,
7749 handle->
debug_print(
"w25qxx: write extended addr register failed.\n");
7754 0x00000000, 0x00, 0x00,
7755 0x00000000, 0x00, 0x00,
7760 handle->
debug_print(
"w25qxx: write enable failed.\n");
7767 0x00000000, 0x00, 0x00,
7772 handle->
debug_print(
"w25qxx: sector erase 4k failed.\n");
7781 0x00000000, 0x00, 0x00,
7786 handle->
debug_print(
"w25qxx: sector erase 4k failed.\n");
7793 handle->
debug_print(
"w25qxx: address mode is invalid.\n");
7799 while (timeout != 0)
7802 0x00000000, 0x00, 0x00,
7803 0x00000000, 0x00, 0x00,
7805 (uint8_t *)&status, 1, 1);
7808 handle->
debug_print(
"w25qxx: get status1 failed.\n");
7812 if ((status & 0x01) == 0x00)
7821 handle->
debug_print(
"w25qxx: sector erase 4k timeout.\n");
7829 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 1, NULL, 0);
7832 handle->
debug_print(
"w25qxx: write enable failed.\n");
7841 buf[1] = (addr >> 24) & 0xFF;
7842 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 2, NULL, 0);
7845 handle->
debug_print(
"w25qxx: write extended addr register failed.\n");
7850 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 1, NULL, 0);
7853 handle->
debug_print(
"w25qxx: write enable failed.\n");
7859 buf[1] = (addr >> 16) & 0xFF;
7860 buf[2] = (addr >> 8) & 0xFF;
7861 buf[3] = (addr >> 0) & 0xFF;
7862 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 4, NULL, 0);
7865 handle->
debug_print(
"w25qxx: sector erase 4k failed.\n");
7873 buf[1] = (addr >> 24) & 0xFF;
7874 buf[2] = (addr >> 16) & 0xFF;
7875 buf[3] = (addr >> 8) & 0xFF;
7876 buf[4] = (addr >> 0) & 0xFF;
7877 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 5, NULL, 0);
7880 handle->
debug_print(
"w25qxx: sector erase 4k failed.\n");
7887 handle->
debug_print(
"w25qxx: address mode is invalid.\n");
7893 while (timeout != 0)
7896 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 1, (uint8_t *)&status, 1);
7899 handle->
debug_print(
"w25qxx: get status1 failed.\n");
7903 if ((status & 0x01) == 0x00)
7912 handle->
debug_print(
"w25qxx: sector erase 4k timeout.\n");
7921 0x00000000, 0x00, 0x00,
7922 0x00000000, 0x00, 0x00,
7927 handle->
debug_print(
"w25qxx: write enable failed.\n");
7935 buf[0] = (addr >> 24) & 0xFF;
7936 res = a_w25qxx_qspi_write_read(handle, 0xC5, 4,
7937 0x00000000, 0x00, 0x00,
7938 0x00000000, 0x00, 0x00,
7939 0, (uint8_t *)buf, 0x01,
7943 handle->
debug_print(
"w25qxx: write extended addr register failed.\n");
7948 0x00000000, 0x00, 0x00,
7949 0x00000000, 0x00, 0x00,
7954 handle->
debug_print(
"w25qxx: write enable failed.\n");
7961 0x00000000, 0x00, 0x00,
7966 handle->
debug_print(
"w25qxx: sector erase 4k failed.\n");
7975 0x00000000, 0x00, 0x00,
7980 handle->
debug_print(
"w25qxx: sector erase 4k failed.\n");
7987 handle->
debug_print(
"w25qxx: address mode is invalid.\n");
7993 while (timeout != 0)
7996 0x00000000, 0x00, 0x00,
7997 0x00000000, 0x00, 0x00,
7999 (uint8_t *)&status, 1, 4);
8002 handle->
debug_print(
"w25qxx: get status1 failed.\n");
8006 if ((status & 0x01) == 0x00)
8015 handle->
debug_print(
"w25qxx: sector erase 4k timeout.\n");
8035 static uint8_t a_w25qxx_page_program(
w25qxx_handle_t *handle, uint32_t addr, uint8_t *data, uint16_t len)
8047 0x00000000, 0x00, 0x00,
8048 0x00000000, 0x00, 0x00,
8053 handle->
debug_print(
"w25qxx: write enable failed.\n");
8061 buf[0] = (addr >> 24) & 0xFF;
8062 res = a_w25qxx_qspi_write_read(handle, 0xC5, 1,
8063 0x00000000, 0x00, 0x00,
8064 0x00000000, 0x00, 0x00,
8065 0, (uint8_t *)buf, 0x01,
8069 handle->
debug_print(
"w25qxx: write extended addr register failed.\n");
8074 0x00000000, 0x00, 0x00,
8075 0x00000000, 0x00, 0x00,
8080 handle->
debug_print(
"w25qxx: write enable failed.\n");
8087 0x00000000, 0x00, 0x00,
8092 handle->
debug_print(
"w25qxx: page program failed.\n");
8101 0x00000000, 0x00, 0x00,
8106 handle->
debug_print(
"w25qxx: page program failed.\n");
8113 handle->
debug_print(
"w25qxx: address mode is invalid.\n");
8119 while (timeout != 0)
8122 0x00000000, 0x00, 0x00,
8123 0x00000000, 0x00, 0x00,
8125 (uint8_t *)&status, 1, 1);
8128 handle->
debug_print(
"w25qxx: page program failed.\n");
8132 if ((status & 0x01) == 0x00)
8141 handle->
debug_print(
"w25qxx: page program timeout.\n");
8149 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 1, NULL, 0);
8152 handle->
debug_print(
"w25qxx: write enable failed.\n");
8161 buf[1] = (addr >> 24) & 0xFF;
8162 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 2, NULL, 0);
8165 handle->
debug_print(
"w25qxx: write extended addr register failed.\n");
8170 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 1, NULL, 0);
8173 handle->
debug_print(
"w25qxx: write enable failed.\n");
8179 handle->
buf[1] = (addr >> 16) & 0xFF;
8180 handle->
buf[2] = (addr >> 8) & 0xFF;
8181 handle->
buf[3] = (addr >> 0) & 0xFF;
8182 memcpy(&handle->
buf[4], data, len);
8183 res = a_w25qxx_spi_write_read(handle, (uint8_t *)handle->
buf, 4 + len, NULL, 0);
8186 handle->
debug_print(
"w25qxx: page program failed.\n");
8195 handle->
buf[1] = (addr >> 24) & 0xFF;
8196 handle->
buf[2] = (addr >> 16) & 0xFF;
8197 handle->
buf[3] = (addr >> 8) & 0xFF;
8198 handle->
buf[4] = (addr >> 0) & 0xFF;
8199 memcpy(&handle->
buf[5], data, len);
8200 res = a_w25qxx_spi_write_read(handle, (uint8_t *)handle->
buf, 5 + len, NULL, 0);
8203 handle->
debug_print(
"w25qxx: page program failed.\n");
8210 handle->
debug_print(
"w25qxx: address mode is invalid.\n");
8216 while (timeout != 0)
8219 res = a_w25qxx_spi_write_read(handle, (uint8_t *)buf, 1, (uint8_t *)&status, 1);
8222 handle->
debug_print(
"w25qxx: get status1 failed.\n");
8226 if ((status & 0x01) == 0x00)
8235 handle->
debug_print(
"w25qxx: page program timeout.\n");
8244 0x00000000, 0x00, 0x00,
8245 0x00000000, 0x00, 0x00,
8250 handle->
debug_print(
"w25qxx: write enable failed.\n");
8258 buf[0] = (addr >> 24) & 0xFF;
8259 res = a_w25qxx_qspi_write_read(handle, 0xC5, 4,
8260 0x00000000, 0x00, 0x00,
8261 0x00000000, 0x00, 0x00,
8262 0, (uint8_t *)buf, 0x01,
8266 handle->
debug_print(
"w25qxx: write extended addr register failed.\n");
8271 0x00000000, 0x00, 0x00,
8272 0x00000000, 0x00, 0x00,
8277 handle->
debug_print(
"w25qxx: write enable failed.\n");
8284 0x00000000, 0x00, 0x00,
8289 handle->
debug_print(
"w25qxx: page program failed.\n");
8298 0x00000000, 0x00, 0x00,
8303 handle->
debug_print(
"w25qxx: page program failed.\n");
8310 handle->
debug_print(
"w25qxx: address mode is invalid.\n");
8316 while (timeout != 0)
8319 0x00000000, 0x00, 0x00,
8320 0x00000000, 0x00, 0x00,
8322 (uint8_t *)&status, 1, 4);
8325 handle->
debug_print(
"w25qxx: page program failed.\n");
8329 if ((status & 0x01) == 0x00)
8338 handle->
debug_print(
"w25qxx: page program timeout.\n");
8358 static uint8_t a_w25qxx_write_no_check(
w25qxx_handle_t *handle, uint32_t addr, uint8_t *data, uint32_t len)
8361 uint16_t page_remain;
8363 page_remain = 256 - addr % 256;
8364 if (len <= page_remain)
8366 page_remain = (uint16_t)len;
8370 res = a_w25qxx_page_program(handle, addr, data, page_remain);
8373 handle->
debug_print(
"w25qxx: page program failed.\n");
8377 if (len == page_remain)
8383 data += page_remain;
8384 addr += page_remain;
8392 page_remain = (uint16_t)len;
8420 uint32_t sec_remain;
8432 sec_pos = addr / 4096;
8433 sec_off = addr % 4096;
8434 sec_remain = 4096 - sec_off;
8435 if (len <= sec_remain)
8441 res = a_w25qxx_read(handle, sec_pos * 4096, handle->
buf_4k, 4096);
8448 for (i = 0; i< sec_remain; i++)
8450 if (handle->
buf_4k[sec_off + i] != 0xFF)
8457 res = a_w25qxx_erase_sector(handle, sec_pos * 4096);
8460 handle->
debug_print(
"w25qxx: erase sector failed.\n");
8464 for (i = 0; i<sec_remain; i++)
8466 handle->
buf_4k[i + sec_off] = data[i];
8468 res = a_w25qxx_write_no_check(handle, sec_pos * 4096, handle->
buf_4k, 4096);
8478 res = a_w25qxx_write_no_check(handle, addr, data, sec_remain);
8486 if (len == sec_remain)
8536 uint32_t address, uint8_t address_line, uint8_t address_len,
8537 uint32_t alternate, uint8_t alternate_line, uint8_t alternate_len,
8538 uint8_t dummy, uint8_t *in_buf, uint32_t in_len,
8539 uint8_t *out_buf, uint32_t out_len, uint8_t data_line)
8551 return a_w25qxx_qspi_write_read(handle, instruction, instruction_line,
8552 address, address_line, address_len,
8553 alternate, alternate_line, alternate_len,
8554 dummy, in_buf, in_len,
8555 out_buf, out_len, data_line);
8576 strncpy(info->
interface,
"SPI QSPI", 16);
#define W25QXX_COMMAND_ENTER_QSPI_MODE
#define W25QXX_COMMAND_READ_STATUS_REG3
#define W25QXX_COMMAND_ERASE_PROGRAM_RESUME
#define W25QXX_COMMAND_READ_BLOCK_LOCK
#define W25QXX_COMMAND_FAST_READ_DUAL_IO
#define W25QXX_COMMAND_READ_DATA
#define W25QXX_COMMAND_INDIVIDUAL_BLOCK_LOCK
#define W25QXX_COMMAND_WRITE_DISABLE
#define W25QXX_COMMAND_DEVICE_ID_DUAL_IO
#define W25QXX_COMMAND_INDIVIDUAL_BLOCK_UNLOCK
#define W25QXX_COMMAND_ERASE_PROGRAM_SUSPEND
#define W25QXX_COMMAND_READ_STATUS_REG2
#define W25QXX_COMMAND_WRITE_STATUS_REG2
#define W25QXX_COMMAND_BLOCK_ERASE_64K
#define W25QXX_COMMAND_READ_SECURITY_REGISTER
#define W25QXX_COMMAND_FAST_READ_QUAD_OUTPUT
#define W25QXX_COMMAND_JEDEC_ID
#define W25QXX_COMMAND_READ_SFDP_REGISTER
#define W25QXX_COMMAND_CHIP_ERASE
#define SUPPLY_VOLTAGE_MAX
#define W25QXX_COMMAND_READ_UNIQUE_ID
#define W25QXX_COMMAND_WRITE_STATUS_REG3
#define W25QXX_COMMAND_ENABLE_RESET
#define W25QXX_COMMAND_SECTOR_ERASE_4K
#define W25QXX_COMMAND_POWER_DOWN
#define W25QXX_COMMAND_DEVICE_ID_QUAD_IO
#define W25QXX_COMMAND_VOLATILE_SR_WRITE_ENABLE
#define W25QXX_COMMAND_FAST_READ_QUAD_IO
#define W25QXX_COMMAND_QUAD_PAGE_PROGRAM
#define W25QXX_COMMAND_ERASE_SECURITY_REGISTER
#define W25QXX_COMMAND_BLOCK_ERASE_32K
#define W25QXX_COMMAND_FAST_READ_DUAL_OUTPUT
#define W25QXX_COMMAND_PROGRAM_SECURITY_REGISTER
#define W25QXX_COMMAND_WRITE_STATUS_REG1
#define W25QXX_COMMAND_WORD_READ_QUAD_IO
#define MANUFACTURER_NAME
#define SUPPLY_VOLTAGE_MIN
#define W25QXX_COMMAND_RESET_DEVICE
#define W25QXX_COMMAND_GLOBAL_BLOCK_SECTOR_UNLOCK
#define W25QXX_COMMAND_FAST_READ
#define W25QXX_COMMAND_OCTAL_WORD_READ_QUAD_IO
#define W25QXX_COMMAND_SET_BURST_WITH_WRAP
#define W25QXX_COMMAND_RELEASE_POWER_DOWN
#define CHIP_NAME
chip information definition
#define W25QXX_COMMAND_READ_STATUS_REG1
#define W25QXX_COMMAND_PAGE_PROGRAM
#define W25QXX_COMMAND_WRITE_ENABLE
chip command definition
#define W25QXX_COMMAND_READ_MANUFACTURER
#define W25QXX_COMMAND_GLOBAL_BLOCK_SECTOR_LOCK
driver w25qxx header file
uint8_t w25qxx_erase_program_resume(w25qxx_handle_t *handle)
resume erase or program
uint8_t w25qxx_enable_volatile_sr_write(w25qxx_handle_t *handle)
enable volatile sr writing
uint8_t w25qxx_get_unique_id(w25qxx_handle_t *handle, uint8_t id[8])
get the unique id
uint8_t w25qxx_get_manufacturer_device_id_dual_io(w25qxx_handle_t *handle, uint8_t *manufacturer, uint8_t *device_id)
get the manufacturer && device id information with dual io
uint8_t w25qxx_page_program_quad_input(w25qxx_handle_t *handle, uint32_t addr, uint8_t *data, uint16_t len)
quad page program with quad input
uint8_t w25qxx_get_sfdp(w25qxx_handle_t *handle, uint8_t sfdp[256])
get the sfdp
uint8_t w25qxx_set_status1(w25qxx_handle_t *handle, uint8_t status)
set the status 1
uint8_t w25qxx_reset_device(w25qxx_handle_t *handle)
reset the device
w25qxx_qspi_read_wrap_length_t
w25qxx qspi read wrap length enumeration definition
uint8_t w25qxx_read_security_register(w25qxx_handle_t *handle, w25qxx_security_register_t num, uint8_t data[256])
read the security register
uint8_t w25qxx_program_security_register(w25qxx_handle_t *handle, w25qxx_security_register_t num, uint8_t data[256])
program the security register
uint8_t w25qxx_individual_block_lock(w25qxx_handle_t *handle, uint32_t addr)
lock the individual block
uint8_t w25qxx_read_block_lock(w25qxx_handle_t *handle, uint32_t addr, uint8_t *value)
read the block lock
uint8_t w25qxx_get_manufacturer_device_id_quad_io(w25qxx_handle_t *handle, uint8_t *manufacturer, uint8_t *device_id)
get the manufacturer && device id information with quad io
uint8_t w25qxx_exit_qspi_mode(w25qxx_handle_t *handle)
exit the qspi mode
uint8_t w25qxx_global_block_unlock(w25qxx_handle_t *handle)
unlock the whole block
w25qxx_qspi_read_dummy_t
w25qxx qspi read dummy enumeration definition
uint8_t w25qxx_fast_read_dual_output(w25qxx_handle_t *handle, uint32_t addr, uint8_t *data, uint32_t len)
read with dual output in the fast mode
uint8_t w25qxx_individual_block_unlock(w25qxx_handle_t *handle, uint32_t addr)
unlock the individual block
w25qxx_security_register_t
w25qxx security register enumeration definition
uint8_t w25qxx_octal_word_read_quad_io(w25qxx_handle_t *handle, uint32_t addr, uint8_t *data, uint32_t len)
octal word read with quad io
uint8_t w25qxx_get_jedec_id(w25qxx_handle_t *handle, uint8_t *manufacturer, uint8_t device_id[2])
get the jedec id information
w25qxx_burst_wrap_t
w25qxx burst wrap enumeration definition
uint8_t w25qxx_get_status3(w25qxx_handle_t *handle, uint8_t *status)
get the status 3
uint8_t w25qxx_set_read_parameters(w25qxx_handle_t *handle, w25qxx_qspi_read_dummy_t dummy, w25qxx_qspi_read_wrap_length_t length)
set the read parameters
uint8_t w25qxx_get_status2(w25qxx_handle_t *handle, uint8_t *status)
get the status 2
uint8_t w25qxx_enter_qspi_mode(w25qxx_handle_t *handle)
enter the qspi mode
uint8_t w25qxx_get_status1(w25qxx_handle_t *handle, uint8_t *status)
get the status 1
uint8_t w25qxx_set_status2(w25qxx_handle_t *handle, uint8_t status)
set the status 2
uint8_t w25qxx_global_block_lock(w25qxx_handle_t *handle)
lock the whole block
uint8_t w25qxx_enable_reset(w25qxx_handle_t *handle)
enable the reset
uint8_t w25qxx_fast_read_quad_io(w25qxx_handle_t *handle, uint32_t addr, uint8_t *data, uint32_t len)
read with quad io in the fast mode
uint8_t w25qxx_disable_write(w25qxx_handle_t *handle)
disable writing
uint8_t w25qxx_set_burst_with_wrap(w25qxx_handle_t *handle, w25qxx_burst_wrap_t wrap)
set the burst with wrap
uint8_t w25qxx_erase_program_suspend(w25qxx_handle_t *handle)
suspend erase or program
uint8_t w25qxx_fast_read_dual_io(w25qxx_handle_t *handle, uint32_t addr, uint8_t *data, uint32_t len)
read with dual io in the fast mode
uint8_t w25qxx_word_read_quad_io(w25qxx_handle_t *handle, uint32_t addr, uint8_t *data, uint32_t len)
word read with quad io
uint8_t w25qxx_set_status3(w25qxx_handle_t *handle, uint8_t status)
set the status 3
uint8_t w25qxx_enable_write(w25qxx_handle_t *handle)
enable writing
uint8_t w25qxx_erase_security_register(w25qxx_handle_t *handle, w25qxx_security_register_t num)
erase the security register
uint8_t w25qxx_fast_read_quad_output(w25qxx_handle_t *handle, uint32_t addr, uint8_t *data, uint32_t len)
read with quad output in the fast mode
uint8_t w25qxx_chip_erase(w25qxx_handle_t *handle)
erase the chip
uint8_t w25qxx_release_power_down(w25qxx_handle_t *handle)
release power down
uint8_t w25qxx_only_spi_read(w25qxx_handle_t *handle, uint32_t addr, uint8_t *data, uint32_t len)
read only in the spi interface
uint8_t w25qxx_block_erase_32k(w25qxx_handle_t *handle, uint32_t addr)
erase the 32k block
uint8_t w25qxx_get_address_mode(w25qxx_handle_t *handle, w25qxx_address_mode_t *mode)
get the chip address mode
uint8_t w25qxx_set_interface(w25qxx_handle_t *handle, w25qxx_interface_t interface)
set the chip interface
uint8_t w25qxx_page_program(w25qxx_handle_t *handle, uint32_t addr, uint8_t *data, uint16_t len)
page program
uint8_t w25qxx_set_dual_quad_spi(w25qxx_handle_t *handle, w25qxx_bool_t enable)
enable or disable the dual quad spi
uint8_t w25qxx_get_type(w25qxx_handle_t *handle, w25qxx_type_t *type)
get the chip type
w25qxx_type_t
w25qxx type enumeration definition
uint8_t w25qxx_get_interface(w25qxx_handle_t *handle, w25qxx_interface_t *interface)
get the chip interface
uint8_t w25qxx_init(w25qxx_handle_t *handle)
initialize the chip
uint8_t w25qxx_get_manufacturer_device_id(w25qxx_handle_t *handle, uint8_t *manufacturer, uint8_t *device_id)
get the manufacturer && device id information
uint8_t w25qxx_info(w25qxx_info_t *info)
get chip's information
uint8_t w25qxx_sector_erase_4k(w25qxx_handle_t *handle, uint32_t addr)
erase the 4k sector
uint8_t w25qxx_deinit(w25qxx_handle_t *handle)
close the chip
w25qxx_address_mode_t
w25qxx address mode enumeration definition
uint8_t w25qxx_set_type(w25qxx_handle_t *handle, w25qxx_type_t type)
set the chip type
uint8_t w25qxx_write(w25qxx_handle_t *handle, uint32_t addr, uint8_t *data, uint32_t len)
write data
uint8_t w25qxx_fast_read(w25qxx_handle_t *handle, uint32_t addr, uint8_t *data, uint32_t len)
read in the fast mode
w25qxx_interface_t
w25qxx interface enumeration definition
uint8_t w25qxx_set_address_mode(w25qxx_handle_t *handle, w25qxx_address_mode_t mode)
set the chip address mode
uint8_t w25qxx_get_dual_quad_spi(w25qxx_handle_t *handle, w25qxx_bool_t *enable)
get the dual quad spi status
uint8_t w25qxx_power_down(w25qxx_handle_t *handle)
power down
uint8_t w25qxx_read(w25qxx_handle_t *handle, uint32_t addr, uint8_t *data, uint32_t len)
read data
uint8_t w25qxx_block_erase_64k(w25qxx_handle_t *handle, uint32_t addr)
erase the 64k block
w25qxx_bool_t
w25qxx bool enumeration definition
@ W25QXX_ADDRESS_MODE_3_BYTE
@ W25QXX_ADDRESS_MODE_4_BYTE
uint8_t w25qxx_write_read_reg(w25qxx_handle_t *handle, uint8_t instruction, uint8_t instruction_line, uint32_t address, uint8_t address_line, uint8_t address_len, uint32_t alternate, uint8_t alternate_line, uint8_t alternate_len, uint8_t dummy, uint8_t *in_buf, uint32_t in_len, uint8_t *out_buf, uint32_t out_len, uint8_t data_line)
write and read register
w25qxx handle structure definition
uint8_t(* spi_qspi_write_read)(uint8_t instruction, uint8_t instruction_line, uint32_t address, uint8_t address_line, uint8_t address_len, uint32_t alternate, uint8_t alternate_line, uint8_t alternate_len, uint8_t dummy, uint8_t *in_buf, uint32_t in_len, uint8_t *out_buf, uint32_t out_len, uint8_t data_line)
void(* delay_ms)(uint32_t ms)
uint8_t(* spi_qspi_deinit)(void)
void(* debug_print)(const char *const fmt,...)
void(* delay_us)(uint32_t us)
uint8_t dual_quad_spi_enable
uint8_t(* spi_qspi_init)(void)
w25qxx information structure definition
float supply_voltage_max_v
char manufacturer_name[32]
float supply_voltage_min_v