From d7313388c9e19116b02124a7b27d1e2752b959cc Mon Sep 17 00:00:00 2001 From: "J.P. Hutchins" Date: Mon, 7 Aug 2023 11:40:48 -0700 Subject: [PATCH] drivers: flash: fix hw write protect before sw This change sets write-protect pin disabled BEFORE SW write-protect disable and write-protect pin enabled AFTER SW write-protect enable. Signed-off-by: J.P. Hutchins --- drivers/flash/spi_nor.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/flash/spi_nor.c b/drivers/flash/spi_nor.c index 042bc19a60de04..88d9725168e05f 100644 --- a/drivers/flash/spi_nor.c +++ b/drivers/flash/spi_nor.c @@ -848,8 +848,8 @@ static int spi_nor_write_protection_set(const struct device *dev, int ret; #if ANY_INST_HAS_WP_GPIOS - if (DEV_CFG(dev)->wp) { - gpio_pin_set_dt(DEV_CFG(dev)->wp, write_protect); + if (DEV_CFG(dev)->wp && write_protect == false) { + gpio_pin_set_dt(DEV_CFG(dev)->wp, 0); } #endif @@ -862,6 +862,12 @@ static int spi_nor_write_protection_set(const struct device *dev, ret = spi_nor_cmd_write(dev, SPI_NOR_CMD_ULBPR); } +#if ANY_INST_HAS_WP_GPIOS + if (DEV_CFG(dev)->wp && write_protect == true) { + gpio_pin_set_dt(DEV_CFG(dev)->wp, 1); + } +#endif + return ret; }