Convert code to use u{8,16,32,64}_t and s{8,16,32,64}_t instead of C99
integer types.
Jira: ZEP-2051
Change-Id: I08c682bfc0b80dfa88de859e90a011bcd2db2762
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
73 lines
1.8 KiB
C
73 lines
1.8 KiB
C
/*
|
|
* Copyright (c) 2016 Intel Corporation.
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
#include <zephyr.h>
|
|
#include <flash.h>
|
|
#include <device.h>
|
|
#include <stdio.h>
|
|
|
|
#define FLASH_TEST_REGION_OFFSET 0xff000
|
|
#define FLASH_SECTOR_SIZE 4096
|
|
#define TEST_DATA_BYTE_0 0x55
|
|
#define TEST_DATA_BYTE_1 0xaa
|
|
#define TEST_DATA_LEN 2
|
|
|
|
void main(void)
|
|
{
|
|
struct device *flash_dev;
|
|
u8_t buf[TEST_DATA_LEN];
|
|
|
|
printf("\nW25QXXDV SPI flash testing\n");
|
|
printf("==========================\n");
|
|
|
|
flash_dev = device_get_binding(CONFIG_SPI_FLASH_W25QXXDV_DRV_NAME);
|
|
|
|
if (!flash_dev) {
|
|
printf("SPI flash driver was not found!\n");
|
|
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.
|
|
*/
|
|
printf("\nTest 1: Flash erase\n");
|
|
flash_write_protection_set(flash_dev, false);
|
|
if (flash_erase(flash_dev,
|
|
FLASH_TEST_REGION_OFFSET,
|
|
FLASH_SECTOR_SIZE) != 0) {
|
|
printf(" Flash erase failed!\n");
|
|
} else {
|
|
printf(" Flash erase succeeded!\n");
|
|
}
|
|
|
|
printf("\nTest 2: Flash write\n");
|
|
flash_write_protection_set(flash_dev, false);
|
|
|
|
buf[0] = TEST_DATA_BYTE_0;
|
|
buf[1] = TEST_DATA_BYTE_1;
|
|
printf(" Attempted to write %x %x\n", buf[0], buf[1]);
|
|
if (flash_write(flash_dev, FLASH_TEST_REGION_OFFSET, buf,
|
|
TEST_DATA_LEN) != 0) {
|
|
printf(" Flash write failed!\n");
|
|
return;
|
|
}
|
|
|
|
if (flash_read(flash_dev, FLASH_TEST_REGION_OFFSET, buf,
|
|
TEST_DATA_LEN) != 0) {
|
|
printf(" Flash read failed!\n");
|
|
return;
|
|
}
|
|
printf(" Data read %x %x\n", buf[0], buf[1]);
|
|
|
|
if ((buf[0] == TEST_DATA_BYTE_0) && (buf[1] == TEST_DATA_BYTE_1)) {
|
|
printf(" Data read matches with data written. Good!!\n");
|
|
} else {
|
|
printf(" Data read does not match with data written!!\n");
|
|
}
|
|
}
|