Skip to content

drivers/memory/spiflash.c: Write 2nd byte of SR as separate command. #11932

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions drivers/memory/spiflash.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#define CMD_RDSR (0x05)
#define CMD_WREN (0x06)
#define CMD_SEC_ERASE (0x20)
#define CMD_WRCR (0x31) // sometimes referred to as SR byte 2
#define CMD_RDCR (0x35)
#define CMD_RD_DEVID (0x9f)
#define CMD_CHIP_ERASE (0xc7)
Expand Down Expand Up @@ -199,10 +200,17 @@ void mp_spiflash_init(mp_spiflash_t *self) {
}
uint32_t data = (sr & 0xff) | (cr & 0xff) << 8;
if (ret == 0 && !(data & (QSPI_QE_MASK << 8))) {
// Write both bytes of SR
data |= QSPI_QE_MASK << 8;
mp_spiflash_write_cmd(self, CMD_WREN);
mp_spiflash_write_cmd_data(self, CMD_WRSR, 2, data);
mp_spiflash_wait_wip0(self);

// Write just byte 2 of SR for flash that only supports that mode of setting SR
data = (cr & 0xff) | QSPI_QE_MASK;
mp_spiflash_write_cmd(self, CMD_WREN);
mp_spiflash_write_cmd_data(self, CMD_WRCR, 1, data);
mp_spiflash_wait_wip0(self);
}
}

Expand Down
8 changes: 6 additions & 2 deletions ports/stm32/qspi.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,12 @@ STATIC int qspi_write_cmd_data(void *self_in, uint8_t cmd, size_t len, uint32_t
while (!(QUADSPI->SR & QUADSPI_SR_FTF)) {
}

// This assumes len==2
*(uint16_t *)&QUADSPI->DR = data;
if (len == 1) {
*(uint8_t *)&QUADSPI->DR = data;
} else {
// This assumes len==2
*(uint16_t *)&QUADSPI->DR = data;
}
}

// Wait for write to finish
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy