43 #undef SPIFLASH_PAGE_PROGRAM
46 #define QSPI_MODE (stmqspi_info->saved_ccr & \
47 (0xF0000000U | QSPI_DCYC_MASK | QSPI_4LINE_MODE | QSPI_ALTB_MODE | QSPI_ADDR4))
51 #define QSPI_CCR_READ (QSPI_READ_MODE | (stmqspi_info->saved_ccr & \
52 (0xF0000000U | QSPI_DCYC_MASK | QSPI_4LINE_MODE | QSPI_ALTB_MODE | QSPI_ADDR4 | 0xFF)))
55 #define QSPI_CCR_READ_STATUS \
56 ((QSPI_MODE & ~QSPI_DCYC_MASK & QSPI_NO_ADDR & QSPI_NO_ALTB) | \
57 (QSPI_READ_MODE | SPIFLASH_READ_STATUS))
59 #define QSPI_CCR_READ_ID \
60 ((QSPI_MODE & ~QSPI_DCYC_MASK & QSPI_NO_ADDR & QSPI_NO_ALTB) | \
61 (QSPI_READ_MODE | SPIFLASH_READ_ID))
63 #define QSPI_CCR_READ_MID \
64 ((QSPI_MODE & ~QSPI_DCYC_MASK & QSPI_NO_ADDR & QSPI_NO_ALTB) | \
65 (QSPI_READ_MODE | SPIFLASH_READ_MID))
68 #define QSPI_CCR_READ_SFDP \
69 ((QSPI_MODE & ~QSPI_DCYC_MASK & ~QSPI_ADDR4 & QSPI_NO_ALTB) | \
70 (QSPI_READ_MODE | QSPI_ADDR3 | SPIFLASH_READ_SFDP))
72 #define QSPI_CCR_WRITE_ENABLE \
73 ((QSPI_MODE & ~QSPI_DCYC_MASK & QSPI_NO_ADDR & QSPI_NO_ALTB & QSPI_NO_DATA) | \
74 (QSPI_WRITE_MODE | SPIFLASH_WRITE_ENABLE))
76 #define QSPI_CCR_SECTOR_ERASE \
77 ((QSPI_MODE & ~QSPI_DCYC_MASK & QSPI_NO_ALTB & QSPI_NO_DATA) | \
78 (QSPI_WRITE_MODE | stmqspi_info->dev.erase_cmd))
80 #define QSPI_CCR_MASS_ERASE \
81 ((QSPI_MODE & ~QSPI_DCYC_MASK & QSPI_NO_ADDR & QSPI_NO_ALTB & QSPI_NO_DATA) | \
82 (QSPI_WRITE_MODE | stmqspi_info->dev.chip_erase_cmd))
84 #define QSPI_CCR_PAGE_PROG \
85 ((QSPI_MODE & ~QSPI_DCYC_MASK & QSPI_NO_ALTB) | \
86 (QSPI_WRITE_MODE | stmqspi_info->dev.pprog_cmd))
89 #define OCTOSPI_MODE (stmqspi_info->saved_cr & 0xCFFFFFFF)
91 #define OPI_MODE ((stmqspi_info->saved_ccr & OCTOSPI_ISIZE_MASK) != 0)
93 #define OCTOSPI_MODE_CCR (stmqspi_info->saved_ccr & \
94 (0xF0000000U | OCTOSPI_8LINE_MODE | OCTOSPI_ALTB_MODE | OCTOSPI_ADDR4))
97 #define OCTOSPI_CCR_READ OCTOSPI_MODE_CCR
108 ((stmqspi_info->saved_ccr & OCTOSPI_DQSEN) ? 6U : 4U)
110 #define OCTOSPI_CCR_READ_STATUS \
111 ((OCTOSPI_MODE_CCR & OCTOSPI_NO_DDTR & \
112 (OPI_MODE ? ~0U : OCTOSPI_NO_ADDR) & OCTOSPI_NO_ALTB))
114 #define OCTOSPI_CCR_READ_ID \
115 ((OCTOSPI_MODE_CCR & OCTOSPI_NO_DDTR & \
116 (OPI_MODE ? ~0U : OCTOSPI_NO_ADDR) & OCTOSPI_NO_ALTB))
118 #define OCTOSPI_CCR_READ_MID OCTOSPI_CCR_READ_ID
121 #define OCTOSPI_CCR_READ_SFDP(len) \
122 ((OCTOSPI_MODE_CCR & OCTOSPI_NO_DDTR & ~OCTOSPI_ADDR4 & OCTOSPI_NO_ALTB) | \
123 (((len) < 4) ? OCTOSPI_ADDR3 : OCTOSPI_ADDR4))
125 #define OCTOSPI_CCR_WRITE_ENABLE \
126 ((OCTOSPI_MODE_CCR & OCTOSPI_NO_ADDR & OCTOSPI_NO_ALTB & OCTOSPI_NO_DATA))
128 #define OCTOSPI_CCR_SECTOR_ERASE \
129 ((OCTOSPI_MODE_CCR & OCTOSPI_NO_ALTB & OCTOSPI_NO_DATA))
131 #define OCTOSPI_CCR_MASS_ERASE \
132 ((OCTOSPI_MODE_CCR & OCTOSPI_NO_ADDR & OCTOSPI_NO_ALTB & OCTOSPI_NO_DATA))
134 #define OCTOSPI_CCR_PAGE_PROG \
135 ((OCTOSPI_MODE_CCR & QSPI_NO_ALTB))
137 #define SPI_ADSIZE (((stmqspi_info->saved_ccr >> SPI_ADSIZE_POS) & 0x3) + 1)
139 #define OPI_CMD(cmd) ((OPI_MODE ? ((((uint16_t)(cmd)) << 8) | (~(cmd) & 0xFFU)) : (cmd)))
151 #define SPI_CMD_TIMEOUT (100)
152 #define SPI_PROBE_TIMEOUT (100)
153 #define SPI_MAX_TIMEOUT (2000)
154 #define SPI_MASS_ERASE_TIMEOUT (400000)
177 uint32_t ccr, uint32_t ir)
223 bank->driver_priv = stmqspi_info;
226 stmqspi_info->
probed =
false;
384 *
status |= ((uint16_t)data) << 8;
467 LOG_ERROR(
"Cannot write enable flash1. Status=0x%02x",
476 LOG_ERROR(
"Cannot write enable flash2. Status=0x%02x",
505 stmqspi_info =
bank->driver_priv;
513 if (!(stmqspi_info->
probed)) {
519 LOG_ERROR(
"Mass erase not available for this device");
523 for (sector = 0; sector <
bank->num_sectors; sector++) {
524 if (
bank->sectors[sector].is_protected) {
525 LOG_ERROR(
"Flash sector %u protected", sector);
530 io_base = stmqspi_info->
io_base;
560 LOG_ERROR(
"Mass erase command not accepted by flash1. Status=0x%02x",
571 LOG_ERROR(
"Mass erase command not accepted by flash2. Status=0x%02x",
600 for (result = 0; (
unsigned int) result <
sizeof(uint32_t) * CHAR_BIT; result++)
601 if (word ==
BIT(result))
614 unsigned int index = 0, dual, fsize;
628 stmqspi_info =
bank->driver_priv;
635 bank->num_sectors = 0;
639 stmqspi_info->
probed =
false;
640 memset(&stmqspi_info->
dev, 0,
sizeof(stmqspi_info->
dev));
641 stmqspi_info->
dev.
name =
"unknown";
680 "0x6B/0x6C/0xBB/0xBC/0xEB/0xEC/0xEE QREAD allowed");
719 io_base = stmqspi_info->
io_base;
728 if (
bank->size ==
BIT(fsize + 1))
729 LOG_DEBUG(
"FSIZE in DCR(1) matches actual capacity. Beware of silicon bug in H7, L4+, MP1.");
730 else if (
bank->size ==
BIT(fsize + 0))
731 LOG_DEBUG(
"FSIZE in DCR(1) is off by one regarding actual capacity. Fix for silicon bug?");
733 LOG_ERROR(
"FSIZE in DCR(1) doesn't match actual capacity.");
744 for (
unsigned int sector = 0; sector <
bank->num_sectors; sector++) {
751 bank->sectors = sectors;
754 LOG_INFO(
"flash \'%s\' id = unknown\nchip size = %" PRIu32
" KiB,"
755 " bank size = %" PRIu32
" KiB", stmqspi_info->
dev.
name,
759 LOG_INFO(
"flash \'%s\' id = unknown\nchip size = %" PRIu32
" B,"
760 " bank size = %" PRIu32
" B", stmqspi_info->
dev.
name,
764 stmqspi_info->
probed =
true;
775 uint8_t num_write, num_read, cmd_byte, data;
778 char temp[4],
output[(2 + max + 256) * 3 + 8];
787 if (num_write > max) {
788 LOG_ERROR(
"at most %d bytes may be sent", max);
797 stmqspi_info =
bank->driver_priv;
812 if ((num_write & 1) == 0) {
813 LOG_ERROR(
"number of data bytes to write must be even in dual mode");
820 if ((num_read & 1) != 0) {
821 LOG_ERROR(
"number of bytes to read must be even in dual mode");
825 if ((num_write < 1) || (num_write > 5)) {
826 LOG_ERROR(
"one cmd and up to four addr bytes must be send when reading");
842 snprintf(
output,
sizeof(
output),
"spi: %02x ", cmd_byte);
864 snprintf(temp,
sizeof(temp),
"%02" PRIx8
" ", data);
876 snprintf(temp,
sizeof(temp),
"%02" PRIx8
" ", data);
907 for ( ; num_read > 0; num_read--) {
911 snprintf(temp,
sizeof(temp),
"%02" PRIx8
" ", data);
967 LOG_ERROR(
"Sector erase command not accepted by flash1. Status=0x%02x",
979 LOG_ERROR(
"Sector erase command not accepted by flash2. Status=0x%02x",
1002 LOG_DEBUG(
"%s: from sector %u to sector %u", __func__, first, last);
1009 if (!(stmqspi_info->
probed)) {
1015 LOG_ERROR(
"Sector erase not available for this device");
1019 if ((last < first) || (last >=
bank->num_sectors)) {
1024 for (sector = first; sector <= last; sector++) {
1025 if (
bank->sectors[sector].is_protected) {
1026 LOG_ERROR(
"Flash sector %u protected", sector);
1031 for (sector = first; sector <= last; sector++) {
1040 LOG_ERROR(
"Flash sector_erase failed on sector %u", sector);
1049 unsigned int first,
unsigned int last)
1051 unsigned int sector;
1053 for (sector = first; sector <= last; sector++)
1054 bank->sectors[sector].is_protected = set;
1057 LOG_WARNING(
"setting soft protection only, not related to flash's hardware write protection");
1071 const uint8_t *code;
1073 uint32_t codesize, maxsize,
result, exit_point;
1074 unsigned int count, index, num_sectors, sector;
1076 const uint32_t erased = 0x00FF;
1083 if (!(stmqspi_info->
probed)) {
1099 static const uint8_t stmqspi_erase_check_code[] = {
1100 #include "../../../contrib/loaders/flash/stmqspi/stmqspi_erase_check.inc"
1104 static const uint8_t stmoctospi_erase_check_code[] = {
1105 #include "../../../contrib/loaders/flash/stmqspi/stmoctospi_erase_check.inc"
1109 code = stmoctospi_erase_check_code;
1110 codesize =
sizeof(stmoctospi_erase_check_code);
1112 code = stmqspi_erase_check_code;
1113 codesize =
sizeof(stmqspi_erase_check_code);
1118 uint32_t ccr_buffer[][4] = {
1132 if (maxsize < codesize +
sizeof(erase_check_info)) {
1133 LOG_ERROR(
"Not enough working area, can't do QSPI blank check");
1137 num_sectors = (maxsize - codesize) /
sizeof(erase_check_info);
1138 num_sectors = (
bank->num_sectors < num_sectors) ?
bank->num_sectors : num_sectors;
1141 codesize + num_sectors *
sizeof(erase_check_info), &algorithm) !=
ERROR_OK) {
1142 LOG_ERROR(
"allocating working area failed");
1148 codesize -
sizeof(ccr_buffer), code);
1154 + codesize -
sizeof(ccr_buffer),
1155 sizeof(ccr_buffer), (uint8_t *)ccr_buffer);
1163 exit_point = algorithm->
address + codesize -
sizeof(uint32_t) -
sizeof(ccr_buffer);
1169 while (sector < bank->num_sectors) {
1172 if (
count > num_sectors)
1173 count = num_sectors;
1175 for (index = 0; index <
count; index++) {
1181 + codesize + index *
sizeof(erase_check_info),
1182 sizeof(erase_check_info), (uint8_t *)&erase_check_info);
1193 LOG_DEBUG(
"checking sectors %u to %u", sector, sector +
count - 1);
1198 algorithm->
address, exit_point,
1199 count * ((
bank->sectors[sector].size >> 6) + 1) + 1000,
1204 for (index = 0; index <
count; index++) {
1206 + codesize + index *
sizeof(erase_check_info),
1207 sizeof(erase_check_info), (uint8_t *)&erase_check_info);
1211 if ((erase_check_info.offset !=
h_to_le_32(
bank->sectors[sector + index].offset)) ||
1212 (erase_check_info.size != 0)) {
1213 LOG_ERROR(
"corrupted blank check info");
1219 bank->sectors[sector + index].is_erased = ((
result & 0xFF) == 0xFF);
1220 LOG_DEBUG(
"Flash sector %u checked: 0x%04x", sector + index,
result & 0xFFFFU);
1251 const uint8_t *code;
1252 uint32_t pagesize, codesize, crc32, result, exit_point;
1256 static const uint8_t stmqspi_crc32_code[] = {
1257 #include "../../../contrib/loaders/flash/stmqspi/stmqspi_crc32.inc"
1261 static const uint8_t stmoctospi_crc32_code[] = {
1262 #include "../../../contrib/loaders/flash/stmqspi/stmoctospi_crc32.inc"
1266 code = stmoctospi_crc32_code;
1267 codesize =
sizeof(stmoctospi_crc32_code);
1269 code = stmqspi_crc32_code;
1270 codesize =
sizeof(stmqspi_crc32_code);
1285 uint32_t ccr_buffer[][4] = {
1299 LOG_ERROR(
"Not enough working area, can't do QSPI verify");
1305 codesize -
sizeof(ccr_buffer), code);
1311 + codesize -
sizeof(ccr_buffer),
1312 sizeof(ccr_buffer), (uint8_t *)ccr_buffer);
1318 exit_point = algorithm->
address + codesize -
sizeof(uint32_t) -
sizeof(ccr_buffer);
1326 buf_set_u32(reg_params[1].value, 0, 32, pagesize);
1337 algorithm->
address, exit_point,
1338 (
count >> 5) + 1000,
1348 if (~crc32 != result)
1375 uint32_t pagesize, fifo_start, fifosize, remaining;
1376 uint32_t maxsize, codesize, exit_point;
1377 const uint8_t *code =
NULL;
1381 LOG_DEBUG(
"%s: offset=0x%08" PRIx32
" len=0x%08" PRIx32,
1387 static const uint8_t stmqspi_read_code[] = {
1388 #include "../../../contrib/loaders/flash/stmqspi/stmqspi_read.inc"
1392 static const uint8_t stmoctospi_read_code[] = {
1393 #include "../../../contrib/loaders/flash/stmqspi/stmoctospi_read.inc"
1397 static const uint8_t stmqspi_write_code[] = {
1398 #include "../../../contrib/loaders/flash/stmqspi/stmqspi_write.inc"
1402 static const uint8_t stmoctospi_write_code[] = {
1403 #include "../../../contrib/loaders/flash/stmqspi/stmoctospi_write.inc"
1408 uint32_t ccr_buffer[][4] = {
1442 code = stmoctospi_write_code;
1443 codesize =
sizeof(stmoctospi_write_code);
1445 code = stmqspi_write_code;
1446 codesize =
sizeof(stmqspi_write_code);
1450 code = stmoctospi_read_code;
1451 codesize =
sizeof(stmoctospi_read_code);
1453 code = stmqspi_read_code;
1454 codesize =
sizeof(stmqspi_read_code);
1471 if (maxsize < codesize + 2 *
sizeof(uint32_t) + pagesize) {
1472 LOG_ERROR(
"not enough working area, can't do QSPI page reads/writes");
1477 maxsize -= (codesize + 2 *
sizeof(uint32_t));
1478 fifosize = ((maxsize < fifosize) ? maxsize : fifosize) & ~(pagesize - 1);
1481 codesize + 2 *
sizeof(uint32_t) + fifosize, &algorithm) !=
ERROR_OK) {
1482 LOG_ERROR(
"allocating working area failed");
1488 codesize -
sizeof(ccr_buffer), code);
1494 + codesize -
sizeof(ccr_buffer),
1495 sizeof(ccr_buffer), (uint8_t *)ccr_buffer);
1501 fifo_start = algorithm->
address + codesize + 2 *
sizeof(uint32_t);
1511 buf_set_u32(reg_params[1].value, 0, 32, pagesize);
1514 buf_set_u32(reg_params[4].value, 0, 32, fifo_start);
1515 buf_set_u32(reg_params[5].value, 0, 32, fifo_start + fifosize);
1522 exit_point = algorithm->
address + codesize
1523 - (
sizeof(ccr_buffer) +
sizeof(uint32_t));
1529 algorithm->
address + codesize,
1530 fifosize + 2 *
sizeof(uint32_t),
1531 algorithm->
address, exit_point,
1537 algorithm->
address + codesize,
1538 fifosize + 2 *
sizeof(uint32_t),
1539 algorithm->
address, exit_point,
1543 remaining =
buf_get_u32(reg_params[0].value, 0, 32);
1544 if ((retval ==
ERROR_OK) && remaining)
1549 LOG_ERROR(
"flash %s failed at address 0x%" PRIx32
", remaining 0x%" PRIx32,
1550 write ?
"write" :
"read",
offset, remaining);
1576 LOG_DEBUG(
"%s: offset=0x%08" PRIx32
" count=0x%08" PRIx32,
1584 if (!(stmqspi_info->
probed)) {
1590 LOG_WARNING(
"Read beyond end of flash. Extra data to be ignored.");
1612 unsigned int dual, sector;
1616 LOG_DEBUG(
"%s: offset=0x%08" PRIx32
" count=0x%08" PRIx32,
1627 if (!(stmqspi_info->
probed)) {
1633 LOG_WARNING(
"Write beyond end of flash. Extra data discarded.");
1638 for (sector = 0; sector <
bank->num_sectors; sector++) {
1641 if ((
offset < (
bank->sectors[sector].offset +
bank->sectors[sector].size)) &&
1643 bank->sectors[sector].is_protected) {
1644 LOG_ERROR(
"Flash sector %u protected", sector);
1649 if ((dual || octal_dtr) && ((
offset & 1) != 0 || (
count & 1) != 0)) {
1650 LOG_ERROR(
"In dual-QSPI and octal-DTR modes writes must be two byte aligned: "
1651 "%s: address=0x%08" PRIx32
" len=0x%08" PRIx32, __func__,
offset,
count);
1677 LOG_DEBUG(
"%s: offset=0x%08" PRIx32
" count=0x%08" PRIx32,
1688 if (!(stmqspi_info->
probed)) {
1694 LOG_WARNING(
"Verify beyond end of flash. Extra data ignored.");
1698 if ((dual || octal_dtr) && ((
offset & 1) != 0 || (
count & 1) != 0)) {
1699 LOG_ERROR(
"In dual-QSPI and octal-DTR modes reads must be two byte aligned: "
1700 "%s: address=0x%08" PRIx32
" len=0x%08" PRIx32, __func__,
offset,
count);
1724 unsigned int dual,
count;
1727 const unsigned int max_bytes = 64;
1731 LOG_DEBUG(
"%s: len=%d, dual=%u, flash1=%d",
1732 __func__, len, dual, flash1);
1770 if ((dual != 0) && !flash1) {
1782 LOG_DEBUG(
"start of SFDP header for flash%c after %u dummy bytes",
1783 flash1 ?
'1' :
'2',
count);
1791 if ((dual != 0) && flash1) {
1799 LOG_DEBUG(
"no start of SFDP header even after %u dummy bytes",
count);
1810 uint32_t words, uint32_t *
buffer)
1851 LOG_DEBUG(
"%s: addr=0x%08" PRIx32
" words=0x%08" PRIx32
" dummy=%u",
1872 ((*
dummy + words *
sizeof(uint32_t)) << dual) - 1);
1896 for ( ; words > 0; words--) {
1898 uint32_t word1, word2;
1914 *
buffer = (word1 & 0xFFU) | ((word1 & 0xFF0000U) >> 8) |
1915 ((word2 & 0xFFU) << 16) | ((word2 & 0xFF0000U) << 8);
2016 for (len1 = 0, len2 = 0;
count > 0; --
count) {
2023 if ((
byte != 0x7F) && (len1 < 3)) {
2024 *id1 = (*id1 >> 8) | ((uint32_t)byte) << 16;
2034 if ((
byte != 0x7F) && (len2 < 3)) {
2035 *id2 = (*id2 >> 8) | ((uint32_t)byte) << 16;
2041 if (((*id1 != 0x000000) && (*id1 != 0xFFFFFF)) ||
2042 ((*id2 != 0x000000) && (*id2 != 0xFFFFFF)))
2048 if ((*id1 == 0x000000) || (*id1 == 0xFFFFFF)) {
2056 if ((*id2 == 0x000000) || (*id2 == 0xFFFFFF)) {
2072 uint32_t io_base = stmqspi_info->
io_base;
2073 uint32_t id1 = 0, id2 = 0, data = 0;
2075 const uint32_t magic = 0xAEF1510E;
2076 unsigned int dual, fsize;
2081 if (stmqspi_info->
probed)
2082 free(
bank->sectors);
2084 bank->num_sectors = 0;
2088 stmqspi_info->
probed =
false;
2089 memset(&stmqspi_info->
dev, 0,
sizeof(stmqspi_info->
dev));
2090 stmqspi_info->
dev.
name =
"unknown";
2109 if (data == magic) {
2111 stmqspi_info->
octo =
false;
2119 stmqspi_info->
octo =
true;
2121 LOG_ERROR(
"No QSPI, no OCTOSPI at 0x%08" PRIx32, io_base);
2122 stmqspi_info->
probed =
false;
2123 stmqspi_info->
dev.
name =
"none";
2147 LOG_ERROR(
"No OCTOSPI at io_base 0x%08" PRIx32, io_base);
2148 stmqspi_info->
probed =
false;
2149 stmqspi_info->
dev.
name =
"none";
2155 if ((mtyp != 0x0) && (mtyp != 0x1)) {
2156 LOG_ERROR(
"Only regular SPI protocol supported in OCTOSPI");
2157 stmqspi_info->
probed =
false;
2158 stmqspi_info->
dev.
name =
"none";
2162 LOG_DEBUG(
"OCTOSPI at 0x%08" PRIx64
", io_base at 0x%08" PRIx32
", OCTOSPI_CR 0x%08"
2163 PRIx32
", OCTOSPI_CCR 0x%08" PRIx32
", %d-byte addr",
bank->base, io_base,
2167 LOG_DEBUG(
"QSPI at 0x%08" PRIx64
", io_base at 0x%08" PRIx32
", QSPI_CR 0x%08"
2168 PRIx32
", QSPI_CCR 0x%08" PRIx32
", %d-byte addr",
bank->base, io_base,
2171 LOG_WARNING(
"DDR mode is untested and suffers from some silicon bugs");
2173 LOG_ERROR(
"No QSPI at io_base 0x%08" PRIx32, io_base);
2174 stmqspi_info->
probed =
false;
2175 stmqspi_info->
dev.
name =
"none";
2182 if (dual || octal_dtr)
2183 bank->write_start_alignment =
bank->write_end_alignment = 2;
2185 bank->write_start_alignment =
bank->write_end_alignment = 1;
2189 LOG_DEBUG(
"id1 0x%06" PRIx32
", id2 0x%06" PRIx32, id1, id2);
2192 LOG_INFO(
"No id - set flash parameters manually");
2203 memcpy(&stmqspi_info->
dev, p,
sizeof(stmqspi_info->
dev));
2205 LOG_INFO(
"flash1 \'%s\' id = 0x%06" PRIx32
" size = %" PRIu32
2208 LOG_INFO(
"flash1 \'%s\' id = 0x%06" PRIx32
" size = %" PRIu32
2214 if (id1 && !p->
name) {
2217 uint32_t saved_cr = stmqspi_info->
saved_cr;
2227 LOG_INFO(
"flash1 \'%s\' id = 0x%06" PRIx32
" size = %" PRIu32
2230 memcpy(&stmqspi_info->
dev, &temp,
sizeof(stmqspi_info->
dev));
2234 LOG_WARNING(
"Unknown flash1 device id = 0x%06" PRIx32
2235 " - set flash parameters manually", id1);
2245 LOG_INFO(
"flash2 \'%s\' id = 0x%06" PRIx32
" size = %" PRIu32
2248 LOG_INFO(
"flash2 \'%s\' id = 0x%06" PRIx32
" size = %" PRIu32
2252 memcpy(&stmqspi_info->
dev, p,
sizeof(stmqspi_info->
dev));
2261 LOG_ERROR(
"Incompatible flash1/flash2 devices");
2272 if (id2 && !p->
name) {
2275 uint32_t saved_cr = stmqspi_info->
saved_cr;
2285 LOG_INFO(
"flash2 \'%s\' id = 0x%06" PRIx32
" size = %" PRIu32
2289 LOG_WARNING(
"Unknown flash2 device id = 0x%06" PRIx32
2290 " - set flash parameters manually", id2);
2296 memcpy(&stmqspi_info->
dev, &temp,
sizeof(stmqspi_info->
dev));
2305 LOG_ERROR(
"Incompatible flash1/flash2 devices");
2326 if (
bank->size ==
BIT((fsize + 1)))
2327 LOG_DEBUG(
"FSIZE in DCR(1) matches actual capacity. Beware of silicon bug in H7, L4+, MP1.");
2328 else if (
bank->size ==
BIT((fsize + 0)))
2329 LOG_DEBUG(
"FSIZE in DCR(1) is off by one regarding actual capacity. Fix for silicon bug?");
2331 LOG_ERROR(
"FSIZE in DCR(1) doesn't match actual capacity.");
2349 for (
unsigned int sector = 0; sector <
bank->num_sectors; sector++) {
2356 bank->sectors = sectors;
2357 stmqspi_info->
probed =
true;
2370 if (stmqspi_info->
probed)
2386 if (!(stmqspi_info->
probed)) {
2392 ", flash size = %" PRIu32
"%s B\n(page size = %" PRIu32
2393 ", read = 0x%02" PRIx8
", qread = 0x%02" PRIx8
2394 ", pprog = 0x%02" PRIx8
", mass_erase = 0x%02" PRIx8
2395 ", sector size = %" PRIu32
" %sB, sector_erase = 0x%02" PRIx8
")",
2415 .
name =
"mass_erase",
2416 .handler = stmqspi_handle_mass_erase_command,
2419 .help =
"Mass erase entire flash device.",
2423 .handler = stmqspi_handle_set,
2425 .usage =
"bank_id name chip_size page_size read_cmd qread_cmd pprg_cmd "
2426 "[ mass_erase_cmd ] [ sector_size sector_erase_cmd ]",
2427 .help =
"Set params of single flash chip",
2431 .handler = stmqspi_handle_cmd,
2433 .usage =
"bank_id num_resp cmd_byte ...",
2434 .help =
"Send low-level command cmd_byte and following bytes or read num_resp.",
2443 .help =
"stmqspi flash command group",
2453 .flash_bank_command = stmqspi_flash_bank_command,
void init_reg_param(struct reg_param *param, char *reg_name, uint32_t size, enum param_direction direction)
void destroy_reg_param(struct reg_param *param)
#define ARMV7M_COMMON_MAGIC
Support functions to access arbitrary bits in a byte array.
static uint32_t buf_get_u32(const uint8_t *_buffer, unsigned first, unsigned num)
Retrieves num bits from _buffer, starting at the first bit, returning the bits in a 32-bit word.
static void buf_set_u32(uint8_t *_buffer, unsigned first, unsigned num, uint32_t value)
Sets num bits in _buffer, starting at the first bit, using the bits in value.
void command_print_sameline(struct command_invocation *cmd, const char *format,...)
void command_print(struct command_invocation *cmd, const char *format,...)
#define CMD
Use this macro to access the command being handled, rather than accessing the variable directly.
#define CALL_COMMAND_HANDLER(name, extra ...)
Use this to macro to call a command helper (or a nested handler).
#define CMD_ARGV
Use this macro to access the arguments for the command being handled, rather than accessing the varia...
#define ERROR_COMMAND_SYNTAX_ERROR
#define CMD_ARGC
Use this macro to access the number of arguments for the command being handled, rather than accessing...
#define COMMAND_PARSE_NUMBER(type, in, out)
parses the string in into out as a type, or prints a command error and passes the error code to the c...
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
#define ERROR_FLASH_OPER_UNSUPPORTED
#define ERROR_FLASH_PROTECTED
#define ERROR_FLASH_SECTOR_INVALID
#define ERROR_FLASH_BANK_NOT_PROBED
#define ERROR_FLASH_OPERATION_FAILED
#define ERROR_FLASH_DST_BREAKS_ALIGNMENT
void default_flash_free_driver_priv(struct flash_bank *bank)
Deallocates bank->driver_priv.
int image_calculate_checksum(const uint8_t *buffer, uint32_t nbytes, uint32_t *checksum)
void alive_sleep(uint64_t ms)
#define LOG_WARNING(expr ...)
#define LOG_ERROR(expr ...)
#define LOG_INFO(expr ...)
#define LOG_DEBUG(expr ...)
int spi_sfdp(struct flash_bank *bank, struct flash_device *dev, read_sfdp_block_t read_sfdp_block)
const struct flash_device flash_devices[]
#define SPIFLASH_READ_MID
#define SPIFLASH_READ_SFDP
#define SPIFLASH_READ_STATUS
#define SPIFLASH_WRITE_ENABLE
#define SPIFLASH_DEF_PAGESIZE
#define OCTOSPI_CCR_SECTOR_ERASE
#define OCTOSPI_CCR_READ_STATUS
static int qspi_write_enable(struct flash_bank *bank)
#define OCTOSPI_CCR_WRITE_ENABLE
static int stmqspi_protect_check(struct flash_bank *bank)
static int stmqspi_verify(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
static int octospi_cmd(struct flash_bank *bank, uint32_t mode, uint32_t ccr, uint32_t ir)
static int stmqspi_protect(struct flash_bank *bank, int set, unsigned int first, unsigned int last)
#define QSPI_CCR_READ_STATUS
static int read_sfdp_block(struct flash_bank *bank, uint32_t addr, uint32_t words, uint32_t *buffer)
static int stmqspi_probe(struct flash_bank *bank)
static int qspi_read_write_block(struct flash_bank *bank, uint8_t *buffer, uint32_t offset, uint32_t count, bool write)
COMMAND_HANDLER(stmqspi_handle_mass_erase_command)
#define OCTOSPI_CCR_READ_ID
static int poll_busy(struct flash_bank *bank, int timeout)
#define QSPI_CCR_READ_SFDP
static int log2u(uint32_t word)
#define SPI_PROBE_TIMEOUT
#define QSPI_CCR_READ_MID
#define SPI_MASS_ERASE_TIMEOUT
#define OCTOSPI_CCR_MASS_ERASE
static int qspi_verify(struct flash_bank *bank, uint8_t *buffer, uint32_t offset, uint32_t count)
static int stmqspi_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
static int qspi_erase_sector(struct flash_bank *bank, unsigned int sector)
static int read_flash_id(struct flash_bank *bank, uint32_t *id1, uint32_t *id2)
static int read_status_reg(struct flash_bank *bank, uint16_t *status)
#define QSPI_CCR_MASS_ERASE
static const struct command_registration stmqspi_exec_command_handlers[]
static int set_mm_mode(struct flash_bank *bank)
static int stmqspi_blank_check(struct flash_bank *bank)
static uint32_t h_to_le_32(uint32_t val)
static int wait_till_ready(struct flash_bank *bank, int timeout)
#define OCTOSPI_CCR_READ_MID
#define OCTOSPI_CCR_READ_SFDP(len)
FLASH_BANK_COMMAND_HANDLER(stmqspi_flash_bank_command)
#define OCTOSPI_CCR_PAGE_PROG
static int stmqspi_read(struct flash_bank *bank, uint8_t *buffer, uint32_t offset, uint32_t count)
static const struct command_registration stmqspi_command_handlers[]
static int stmqspi_erase(struct flash_bank *bank, unsigned int first, unsigned int last)
static int stmqspi_auto_probe(struct flash_bank *bank)
static int get_stmqspi_info(struct flash_bank *bank, struct command_invocation *cmd)
#define QSPI_CCR_WRITE_ENABLE
struct flash_driver stmqspi_flash
#define QSPI_CCR_PAGE_PROG
#define QSPI_CCR_SECTOR_ERASE
static int stmqspi_abort(struct flash_bank *bank)
static int find_sfdp_dummy(struct flash_bank *bank, int len)
#define OCTOSPI_READ_MODE
#define OCTOSPI_DCYC_MASK
#define OCTOSPI_WRITE_MODE
#define OCTOSPI_MTYP_MASK
unsigned int common_magic
When run_command is called, a new instance will be created on the stack, filled with the proper value...
Provides details of a flash bank, available either on-chip or through a major interface.
Provides the implementation-independent structure that defines all of the callbacks required by OpenO...
const char * name
Gives a human-readable name of this flash driver, This field is used to select and initialize the dri...
Describes the geometry and status of a single flash sector within a flash bank.
int is_erased
Indication of erasure status: 0 = not erased, 1 = erased, other = unknown.
uint32_t offset
Bus offset from start of the flash chip (in bytes).
int is_protected
Indication of protection status: 0 = unprotected/unlocked, 1 = protected/locked, other = unknown.
uint32_t size
Number of bytes in this flash sector.
int target_run_read_async_algorithm(struct target *target, uint8_t *buffer, uint32_t count, int block_size, int num_mem_params, struct mem_param *mem_params, int num_reg_params, struct reg_param *reg_params, uint32_t buffer_start, uint32_t buffer_size, uint32_t entry_point, uint32_t exit_point, void *arch_info)
This routine is a wrapper for asynchronous algorithms.
int target_write_buffer(struct target *target, target_addr_t address, uint32_t size, const uint8_t *buffer)
int target_write_u8(struct target *target, target_addr_t address, uint8_t value)
int target_read_buffer(struct target *target, target_addr_t address, uint32_t size, uint8_t *buffer)
int target_read_u8(struct target *target, target_addr_t address, uint8_t *value)
uint32_t target_get_working_area_avail(struct target *target)
int target_write_u32(struct target *target, target_addr_t address, uint32_t value)
int target_free_working_area(struct target *target, struct working_area *area)
Free a working area.
int target_run_algorithm(struct target *target, int num_mem_params, struct mem_param *mem_params, int num_reg_params, struct reg_param *reg_param, target_addr_t entry_point, target_addr_t exit_point, int timeout_ms, void *arch_info)
Downloads a target-specific native code algorithm to the target, and executes it.
int target_alloc_working_area_try(struct target *target, uint32_t size, struct working_area **area)
int target_run_flash_async_algorithm(struct target *target, const uint8_t *buffer, uint32_t count, int block_size, int num_mem_params, struct mem_param *mem_params, int num_reg_params, struct reg_param *reg_params, uint32_t buffer_start, uint32_t buffer_size, uint32_t entry_point, uint32_t exit_point, void *arch_info)
Streams data to a circular buffer on target intended for consumption by code running asynchronously o...
int target_read_u32(struct target *target, target_addr_t address, uint32_t *value)
#define ERROR_TARGET_NOT_HALTED
#define ERROR_TARGET_RESOURCE_NOT_AVAILABLE
float duration_elapsed(const struct duration *duration)
int duration_measure(struct duration *duration)
Update the duration->elapsed field to finish the duration measurement.
int duration_start(struct duration *duration)
Update the duration->start field to start the duration measurement.
float duration_kbps(const struct duration *duration, size_t count)
static void h_u32_to_le(uint8_t *buf, uint32_t val)
#define ARRAY_SIZE(x)
Compute the number of elements of a variable length array.
static uint32_t le_to_h_u32(const uint8_t *buf)