Skip to content

Commit 4278e98

Browse files
FRASTMkartben
authored andcommitted
drivers: flash: stm32 octospi supports the 4Bytes address mode
Add the 4Bytes program mode to the stm32_ospi driver to enter 4-Byte Address Mode (SPI_NOR_CMD_4BA) when flash is supporting it. This is given by the JESD216 SFDP table. Based on the stm32 qspi driver. Signed-off-by: Francois Ramu <francois.ramu@st.com>
1 parent 63f2fe9 commit 4278e98

File tree

1 file changed

+66
-1
lines changed

1 file changed

+66
-1
lines changed

drivers/flash/flash_stm32_ospi.c

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1845,6 +1845,49 @@ static int stm32_ospi_write_status_register(const struct device *dev, uint8_t re
18451845
return ospi_write_access(dev, &s_command, regs_p, size);
18461846
}
18471847

1848+
static int stm32_ospi_program_addr_4b(const struct device *dev, bool write_enable)
1849+
{
1850+
uint8_t statReg;
1851+
struct flash_stm32_ospi_data *data = dev->data;
1852+
OSPI_HandleTypeDef *hospi = &data->hospi;
1853+
uint8_t nor_mode = OSPI_SPI_MODE;
1854+
uint8_t nor_rate = OSPI_STR_TRANSFER;
1855+
OSPI_RegularCmdTypeDef s_command = ospi_prepare_cmd(nor_mode, nor_rate);
1856+
1857+
if (write_enable) {
1858+
if (stm32_ospi_write_enable(data, nor_mode, nor_rate) < 0) {
1859+
LOG_DBG("program_addr_4b failed to write_enable");
1860+
return -EIO;
1861+
}
1862+
}
1863+
1864+
/* Initialize the write enable command */
1865+
s_command.Instruction = SPI_NOR_CMD_4BA;
1866+
if (nor_mode != OSPI_OPI_MODE) {
1867+
/* force 1-line InstructionMode for any non-OSPI transfer */
1868+
s_command.InstructionMode = HAL_OSPI_INSTRUCTION_1_LINE;
1869+
}
1870+
s_command.AddressMode = HAL_OSPI_ADDRESS_NONE;
1871+
s_command.DataMode = HAL_OSPI_DATA_NONE;
1872+
s_command.DummyCycles = 0U;
1873+
1874+
if (HAL_OSPI_Command(hospi, &s_command, HAL_OSPI_TIMEOUT_DEFAULT_VALUE) != HAL_OK) {
1875+
LOG_DBG("OSPI Address Mode Change cmd failed");
1876+
return -EIO;
1877+
}
1878+
1879+
/* Check that ADS Bit in Status Reg 3 is now set indicating 4 Byte Address mode */
1880+
if (stm32_ospi_read_status_register(dev, 3, &statReg)) {
1881+
LOG_DBG("Status reg read failed");
1882+
return -EIO;
1883+
}
1884+
1885+
if (statReg & 0x01) {
1886+
return 0;
1887+
}
1888+
return -EIO;
1889+
}
1890+
18481891
static int stm32_ospi_enable_qe(const struct device *dev)
18491892
{
18501893
struct flash_stm32_ospi_data *data = dev->data;
@@ -1983,6 +2026,7 @@ static int spi_nor_process_bfp(const struct device *dev,
19832026
const size_t flash_size = jesd216_bfp_density(bfp) / 8U;
19842027
struct jesd216_instr read_instr = { 0 };
19852028
struct jesd216_bfp_dw15 dw15;
2029+
uint8_t addr_mode;
19862030

19872031
if (flash_size != dev_cfg->flash_size) {
19882032
LOG_DBG("Unexpected flash size: %u", flash_size);
@@ -2002,8 +2046,29 @@ static int spi_nor_process_bfp(const struct device *dev,
20022046
++etp;
20032047
}
20042048

2005-
spi_nor_process_bfp_addrbytes(dev, jesd216_bfp_addrbytes(bfp));
2049+
addr_mode = jesd216_bfp_addrbytes(bfp);
2050+
spi_nor_process_bfp_addrbytes(dev, addr_mode);
20062051
LOG_DBG("Address width: %u Bytes", data->address_width);
2052+
/* 4 Byte Address Mode has to be explicitly enabled for Winbond Flash */
2053+
if (addr_mode == JESD216_SFDP_BFP_DW1_ADDRBYTES_VAL_3B4B) {
2054+
struct jesd216_bfp_dw16 dw16;
2055+
2056+
if (jesd216_bfp_decode_dw16(php, bfp, &dw16) == 0) {
2057+
/*
2058+
* According to JESD216, the bit0 of dw16.enter_4ba
2059+
* portion of flash description register 16 indicates
2060+
* if it is enough to use 0xB7 instruction without
2061+
* write enable to switch to 4 bytes addressing mode.
2062+
* If bit 1 is set, a write enable is needed.
2063+
*/
2064+
if (dw16.enter_4ba & 0x3) {
2065+
if (stm32_ospi_program_addr_4b(dev, dw16.enter_4ba & 2)) {
2066+
LOG_ERR("Unable to enter 4B mode.");
2067+
return -EIO;
2068+
}
2069+
}
2070+
}
2071+
}
20072072

20082073
/* use PP opcode based on configured data mode if nothing is set in DTS */
20092074
if (data->write_opcode == SPI_NOR_WRITEOC_NONE) {

0 commit comments

Comments
 (0)