Skip to content
Permalink
Browse files

samples/drivers/spi_flash: fix device naming

There are multiple flash implementations.  This sample was originally
written for the W25QXXDV driver, but has since been used for
jedec,spi-nor.  The sample should work with multiple drivers.

Add device name sources for several drivers, falling back to spi-nor
which was recently used as a test filter.

Signed-off-by: Peter A. Bigot <pab@pabigot.com>
  • Loading branch information...
pabigot authored and galak committed Jul 18, 2019
1 parent 64eca42 commit 0e338efb3cd2842aede31ed6beccd5b73d59b2a8
Showing with 19 additions and 8 deletions.
  1. +1 −1 samples/drivers/spi_flash/sample.yaml
  2. +18 −7 samples/drivers/spi_flash/src/main.c
@@ -3,7 +3,7 @@ sample:
tests:
sample.driver.spi_flash:
tags: spi flash
filter: DT_INST_0_JEDEC_SPI_NOR_BUS_NAME
filter: DT_INST_0_JEDEC_SPI_NOR_LABEL
harness: console
harness_config:
type: multi_line
@@ -9,6 +9,17 @@
#include <device.h>
#include <stdio.h>

#if (CONFIG_SPI_FLASH_W25QXXDV - 0)
/* NB: W25Q16DV is a JEDEC spi-nor device, but has a separate driver. */
#define FLASH_DEVICE CONFIG_SPI_FLASH_W25QXXDV_DRV_NAME
#define FLASH_NAME "W25QXXDV"
#elif (CONFIG_SPI_NOR - 0) || defined(DT_INST_0_JEDEC_SPI_NOR_LABEL)
#define FLASH_DEVICE DT_INST_0_JEDEC_SPI_NOR_LABEL
#define FLASH_NAME "JEDEC SPI-NOR"
#else
#error Unsupported flash driver
#endif

#define FLASH_TEST_REGION_OFFSET 0xff000
#define FLASH_SECTOR_SIZE 4096
#define TEST_DATA_BYTE_0 0x55
@@ -20,20 +31,20 @@ void main(void)
struct device *flash_dev;
u8_t buf[TEST_DATA_LEN];

printf("\nW25QXXDV SPI flash testing\n");
printf("\n" FLASH_NAME " SPI flash testing\n");
printf("==========================\n");

flash_dev = device_get_binding(DT_INST_0_JEDEC_SPI_NOR_BUS_NAME);
flash_dev = device_get_binding(FLASH_DEVICE);

if (!flash_dev) {
printf("SPI flash driver was not found!\n");
printf("SPI flash driver %s was not found!\n", FLASH_DEVICE);
return;
}

/* Write protection needs to be disabled in w25qxxdv flash before
* each write or erase. This is because the flash component turns
* on write protection automatically after completion of write and
* erase operations.
/* Write protection needs to be disabled before each write or
* erase, since the flash component turns on write protection
* automatically after completion of write and erase
* operations.
*/
printf("\nTest 1: Flash erase\n");
flash_write_protection_set(flash_dev, false);

0 comments on commit 0e338ef

Please sign in to comment.
You can’t perform that action at this time.