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; }