Skip to content

Commit

Permalink
drivers: flash: fix hw write protect before sw
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
JPHutchins authored and carlescufi committed Sep 13, 2023
1 parent b403fde commit d731338
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions drivers/flash/spi_nor.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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;
}

Expand Down

0 comments on commit d731338

Please sign in to comment.