Skip to content

Commit d731338

Browse files
JPHutchinscarlescufi
authored andcommitted
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 <[email protected]>
1 parent b403fde commit d731338

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

drivers/flash/spi_nor.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -848,8 +848,8 @@ static int spi_nor_write_protection_set(const struct device *dev,
848848
int ret;
849849

850850
#if ANY_INST_HAS_WP_GPIOS
851-
if (DEV_CFG(dev)->wp) {
852-
gpio_pin_set_dt(DEV_CFG(dev)->wp, write_protect);
851+
if (DEV_CFG(dev)->wp && write_protect == false) {
852+
gpio_pin_set_dt(DEV_CFG(dev)->wp, 0);
853853
}
854854
#endif
855855

@@ -862,6 +862,12 @@ static int spi_nor_write_protection_set(const struct device *dev,
862862
ret = spi_nor_cmd_write(dev, SPI_NOR_CMD_ULBPR);
863863
}
864864

865+
#if ANY_INST_HAS_WP_GPIOS
866+
if (DEV_CFG(dev)->wp && write_protect == true) {
867+
gpio_pin_set_dt(DEV_CFG(dev)->wp, 1);
868+
}
869+
#endif
870+
865871
return ret;
866872
}
867873

0 commit comments

Comments
 (0)