1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

drivers/mtd_spi_nor: define WP and HOLD pin

Hold and WP are not used by the driver, but if they are connected
to the flash they must be driven HIGH to enable writes and not stop
any flash operation.
This commit is contained in:
Benjamin Valentin 2020-11-02 02:41:37 +01:00 committed by Benjamin Valentin
parent dee3ae4ab7
commit 53ca0dd1d0
2 changed files with 24 additions and 3 deletions

View File

@ -111,6 +111,8 @@ typedef struct {
spi_t spi; /**< SPI bus the device is connected to */
spi_mode_t mode; /**< SPI mode */
gpio_t cs; /**< CS pin GPIO handle */
gpio_t wp; /**< Write Protect pin GPIO handle */
gpio_t hold; /**< HOLD pin GPIO handle */
uint8_t addr_width; /**< Number of bytes in addresses, usually 3 for small devices */
} mtd_spi_nor_params_t;

View File

@ -359,6 +359,26 @@ static inline void wait_for_write_complete(const mtd_spi_nor_t *dev, uint32_t us
DEBUG("\n");
}
static void _init_pins(mtd_spi_nor_t *dev)
{
DEBUG("mtd_spi_nor_init: init pins\n");
/* CS */
spi_init_cs(_get_spi(dev), dev->params->cs);
/* Write Protect - not used by the driver */
if (gpio_is_valid(dev->params->wp)) {
gpio_init(dev->params->wp, GPIO_OUT);
gpio_set(dev->params->wp);
}
/* Hold - not used by the driver */
if (gpio_is_valid(dev->params->hold)) {
gpio_init(dev->params->hold, GPIO_OUT);
gpio_set(dev->params->hold);
}
}
static int mtd_spi_nor_power(mtd_dev_t *mtd, enum mtd_power_state power)
{
mtd_spi_nor_t *dev = (mtd_spi_nor_t *)mtd;
@ -408,9 +428,8 @@ static int mtd_spi_nor_init(mtd_dev_t *mtd)
return -EINVAL;
}
/* CS */
DEBUG("mtd_spi_nor_init: CS init\n");
spi_init_cs(_get_spi(dev), dev->params->cs);
/* CS, WP, Hold */
_init_pins(dev);
/* power up the MTD device*/
DEBUG("mtd_spi_nor_init: power up MTD device");