From 2596b14c90e168ce4c727e8642ae20bf5a88f2b4 Mon Sep 17 00:00:00 2001 From: Jussi Kivilinna Date: Tue, 13 Jun 2017 07:33:34 -0600 Subject: [PATCH] mtd/w25: add missing locking and fix SPI_SELECT usage for w25_unprotect --- drivers/mtd/w25.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/drivers/mtd/w25.c b/drivers/mtd/w25.c index 9fc0d754a5..0648306ec8 100644 --- a/drivers/mtd/w25.c +++ b/drivers/mtd/w25.c @@ -440,19 +440,16 @@ static inline int w25_readid(struct w25_dev_s *priv) #ifndef CONFIG_W25_READONLY static void w25_unprotect(FAR struct w25_dev_s *priv) { - /* Select this FLASH part */ + /* Lock and configure the SPI bus */ - SPI_SELECT(priv->spi, SPIDEV_FLASH(0), true); + w25_lock(priv->spi); /* Send "Write enable (WREN)" */ w25_wren(priv); - /* Re-select this FLASH part (This might not be necessary... but is it shown in - * the SST25 timing diagrams from which this code was leveraged.) - */ + /* Select this FLASH part */ - SPI_SELECT(priv->spi, SPIDEV_FLASH(0), false); SPI_SELECT(priv->spi, SPIDEV_FLASH(0), true); /* Send "Write enable status (EWSR)" */ @@ -463,6 +460,11 @@ static void w25_unprotect(FAR struct w25_dev_s *priv) SPI_SEND(priv->spi, 0); SPI_SEND(priv->spi, 0); + + /* Deselect the FLASH and unlock the bus */ + + SPI_SELECT(priv->spi, SPIDEV_FLASH(0), false); + w25_unlock(priv->spi); } #endif