Commit c1880895 authored by Francois Ramu's avatar Francois Ramu Committed by Carles Cufi
Browse files

drivers: flash: stm32 ospi flash driver erase large size



Erase operation with block of 64KByte
larger size than the default 4K sector size
if the flash supports.

Signed-off-by: default avatarFrancois Ramu <francois.ramu@st.com>
parent 70ae4758
Loading
Loading
Loading
Loading
+18 −15
Original line number Diff line number Diff line
@@ -1048,10 +1048,20 @@ static int flash_stm32_ospi_erase(const struct device *dev, off_t addr,
				break;
			}
		} else {
			/* Sector erase */
			LOG_DBG("Sector Erase");
			/* Sector or Block erase depending on the size */
			LOG_INF("Sector/Block Erase");

			cmd_erase.AddressMode =
				(dev_cfg->data_mode == OSPI_OPI_MODE)
				? HAL_OSPI_ADDRESS_8_LINES
				: HAL_OSPI_ADDRESS_1_LINE;
			cmd_erase.AddressDtrMode =
				(dev_cfg->data_rate == OSPI_DTR_TRANSFER)
				? HAL_OSPI_ADDRESS_DTR_ENABLE
				: HAL_OSPI_ADDRESS_DTR_DISABLE;
			cmd_erase.AddressSize = stm32_ospi_hal_address_size(dev);
			cmd_erase.Address = addr;

			const struct jesd216_erase_type *erase_types =
							dev_data->erase_types;
			const struct jesd216_erase_type *bet = NULL;
@@ -1063,12 +1073,12 @@ static int flash_stm32_ospi_erase(const struct device *dev, off_t addr,

				if ((etp->exp != 0)
				    && SPI_NOR_IS_ALIGNED(addr, etp->exp)
				    && SPI_NOR_IS_ALIGNED(size, etp->exp)
				    && (size >= BIT(etp->exp))
				    && ((bet == NULL)
					|| (etp->exp > bet->exp))) {
					bet = etp;
					cmd_erase.Instruction = bet->cmd;
				} else {
				} else if (bet == NULL) {
					/* Use the default sector erase cmd */
					if (dev_cfg->data_mode == OSPI_OPI_MODE) {
						cmd_erase.Instruction = SPI_NOR_OCMD_SE;
@@ -1079,22 +1089,15 @@ static int flash_stm32_ospi_erase(const struct device *dev, off_t addr,
							? SPI_NOR_CMD_SE_4B
							: SPI_NOR_CMD_SE;
					}
					cmd_erase.AddressMode =
						(dev_cfg->data_mode == OSPI_OPI_MODE)
						? HAL_OSPI_ADDRESS_8_LINES
						: HAL_OSPI_ADDRESS_1_LINE;
					cmd_erase.AddressDtrMode =
						(dev_cfg->data_rate == OSPI_DTR_TRANSFER)
						? HAL_OSPI_ADDRESS_DTR_ENABLE
						: HAL_OSPI_ADDRESS_DTR_DISABLE;
					cmd_erase.AddressSize = stm32_ospi_hal_address_size(dev);
					cmd_erase.Address = addr;
					/* Avoid using wrong erase type,
					 * if zero entries are found in erase_types
					 */
					bet = NULL;
				}
			}
			LOG_INF("Sector/Block Erase addr 0x%x, asize 0x%x amode 0x%x  instr 0x%x",
				cmd_erase.Address, cmd_erase.AddressSize,
				cmd_erase.AddressMode, cmd_erase.Instruction);

			ospi_send_cmd(dev, &cmd_erase);