Revert "misc: Remove generic PRINT macros from flash samples"

This reverts commit a6412042fb.

Change-Id: I190d418103bfdd3d6714d1ac063cc1e533ce60ad
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
This commit is contained in:
Andrew Boie 2016-08-23 13:15:18 -07:00
commit 83298d8020
4 changed files with 54 additions and 52 deletions

View file

@ -1,4 +1,3 @@
CONFIG_STDOUT_CONSOLE=y
CONFIG_FLASH=y
CONFIG_SOC_FLASH_NRF5=y
CONFIG_SYS_LOG=y

View file

@ -18,9 +18,13 @@
#include <zephyr.h>
#include <flash.h>
#include <device.h>
#define SYS_LOG_LEVEL SYS_LOG_LEVEL_INFO
#include <misc/sys_log.h>
#if defined(CONFIG_STDOUT_CONSOLE)
#include <stdio.h>
#define PRINT printf
#else
#include <misc/printk.h>
#define PRINT printk
#endif
/* Offset between pages */
#define FLASH_TEST_OFFSET 0x40000
@ -41,83 +45,79 @@ void main(void)
uint32_t buf_word = 0;
uint32_t i, offset;
SYS_LOG_INF("\nNordic nRF5 Flash Testing");
SYS_LOG_INF("=========================");
PRINT("\nNordic nRF5 Flash Testing\n");
PRINT("=========================\n");
flash_dev = device_get_binding("NRF5_FLASH");
if (!flash_dev) {
SYS_LOG_ERR("Nordic nRF5 flash driver was not found!");
PRINT("Nordic nRF5 flash driver was not found!\n");
return;
}
SYS_LOG_INF("\nTest 1: Flash erase page at 0x%x", FLASH_TEST_OFFSET);
PRINT("\nTest 1: Flash erase page at 0x%x\n", FLASH_TEST_OFFSET);
if (flash_erase(flash_dev, FLASH_TEST_OFFSET, FLASH_PAGE_SIZE) != 0) {
SYS_LOG_INF(" Flash erase failed!");
PRINT(" Flash erase failed!\n");
} else {
SYS_LOG_INF(" Flash erase succeeded!");
PRINT(" Flash erase succeeded!\n");
}
SYS_LOG_INF("\nTest 2: Flash write (word array 1)");
PRINT("\nTest 2: Flash write (word array 1)\n");
flash_write_protection_set(flash_dev, false);
for (i = 0; i < TEST_DATA_LEN; i++) {
offset = FLASH_TEST_OFFSET + (i << 2);
SYS_LOG_INF(" Attempted to write %x at 0x%x",
buf_array_1[i], offset);
PRINT(" Attempted to write %x at 0x%x\n", buf_array_1[i],
offset);
if (flash_write(flash_dev, offset, &buf_array_1[i],
TEST_DATA_LEN) != 0) {
SYS_LOG_INF(" Flash write failed!");
PRINT(" Flash write failed!\n");
return;
}
SYS_LOG_INF(" Attempted to read 0x%x", offset);
PRINT(" Attempted to read 0x%x\n", offset);
if (flash_read(flash_dev, offset, &buf_word,
TEST_DATA_LEN) != 0) {
SYS_LOG_INF(" Flash read failed!");
PRINT(" Flash read failed!\n");
return;
}
SYS_LOG_INF(" Data read: %x", buf_word);
PRINT(" Data read: %x\n", buf_word);
if (buf_array_1[i] == buf_word) {
SYS_LOG_INF(" Data read matches data written. "
"Good!");
PRINT(" Data read matches data written. Good!\n");
} else {
SYS_LOG_INF(" Data read does not match data "
"written!");
PRINT(" Data read does not match data written!\n");
}
}
flash_write_protection_set(flash_dev, true);
offset = FLASH_TEST_OFFSET - FLASH_PAGE_SIZE * 2;
SYS_LOG_INF("\nTest 3: Flash erase (4 pages at 0x%x)", offset);
PRINT("\nTest 3: Flash erase (4 pages at 0x%x)\n", offset);
if (flash_erase(flash_dev, offset, FLASH_PAGE_SIZE * 4) != 0) {
SYS_LOG_INF(" Flash erase failed!");
PRINT(" Flash erase failed!\n");
} else {
SYS_LOG_INF(" Flash erase succeeded!");
PRINT(" Flash erase succeeded!\n");
}
SYS_LOG_INF("\nTest 4: Flash write (word array 2)");
PRINT("\nTest 4: Flash write (word array 2)\n");
flash_write_protection_set(flash_dev, false);
for (i = 0; i < TEST_DATA_LEN; i++) {
offset = FLASH_TEST_OFFSET + (i << 2);
SYS_LOG_INF(" Attempted to write %x at 0x%x",
buf_array_2[i], offset);
PRINT(" Attempted to write %x at 0x%x\n", buf_array_2[i],
offset);
if (flash_write(flash_dev, offset, &buf_array_2[i],
TEST_DATA_LEN) != 0) {
SYS_LOG_INF(" Flash write failed!");
PRINT(" Flash write failed!\n");
return;
}
SYS_LOG_INF(" Attempted to read 0x%x", offset);
PRINT(" Attempted to read 0x%x\n", offset);
if (flash_read(flash_dev, offset, &buf_word,
TEST_DATA_LEN) != 0) {
SYS_LOG_INF(" Flash read failed!");
PRINT(" Flash read failed!\n");
return;
}
SYS_LOG_INF(" Data read: %x", buf_word);
PRINT(" Data read: %x\n", buf_word);
if (buf_array_2[i] == buf_word) {
SYS_LOG_INF(" Data read matches data written. "
"Good!");
PRINT(" Data read matches data written. Good!\n");
} else {
SYS_LOG_INF(" Data read does not match data "
"written!");
PRINT(" Data read does not match data written!\n");
}
}
flash_write_protection_set(flash_dev, true);

View file

@ -4,4 +4,3 @@ CONFIG_SPI=y
CONFIG_GPIO=y
CONFIG_SPI_CS_GPIO=y
CONFIG_SPI_0_CS_GPIO_PIN=24
CONFIG_SYS_LOG=y

View file

@ -17,8 +17,13 @@
#include <zephyr.h>
#include <flash.h>
#include <device.h>
#define SYS_LOG_LEVEL SYS_LOG_LEVEL_INFO
#include <misc/sys_log.h>
#if defined(CONFIG_STDOUT_CONSOLE)
#include <stdio.h>
#define PRINT printf
#else
#include <misc/printk.h>
#define PRINT printk
#endif
#define FLASH_TEST_REGION_OFFSET 0xff000
#define FLASH_SECTOR_SIZE 4096
@ -31,13 +36,13 @@ void main(void)
struct device *flash_dev;
uint8_t buf[TEST_DATA_LEN];
SYS_LOG_INF("\nW25QXXDV SPI flash testing");
SYS_LOG_INF("==========================");
PRINT("\nW25QXXDV SPI flash testing\n");
PRINT("==========================\n");
flash_dev = device_get_binding("W25QXXDV");
if (!flash_dev) {
SYS_LOG_ERR("SPI flash driver was not found!");
PRINT("SPI flash driver was not found!\n");
return;
}
@ -46,39 +51,38 @@ void main(void)
* on write protection automatically after completion of write and
* erase operations.
*/
SYS_LOG_INF("\nTest 1: Flash erase");
PRINT("\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) {
SYS_LOG_INF(" Flash erase failed!");
PRINT(" Flash erase failed!\n");
} else {
SYS_LOG_INF(" Flash erase succeeded!");
PRINT(" Flash erase succeeded!\n");
}
SYS_LOG_INF("\nTest 2: Flash write");
PRINT("\nTest 2: Flash write\n");
flash_write_protection_set(flash_dev, false);
buf[0] = TEST_DATA_BYTE_0;
buf[1] = TEST_DATA_BYTE_1;
SYS_LOG_INF(" Attempted to write %x %x", buf[0], buf[1]);
PRINT(" Attempted to write %x %x\n", buf[0], buf[1]);
if (flash_write(flash_dev, FLASH_TEST_REGION_OFFSET, buf,
TEST_DATA_LEN) != 0) {
SYS_LOG_INF(" Flash write failed!");
PRINT(" Flash write failed!\n");
return;
}
if (flash_read(flash_dev, FLASH_TEST_REGION_OFFSET, buf,
TEST_DATA_LEN) != 0) {
SYS_LOG_INF(" Flash read failed!");
PRINT(" Flash read failed!\n");
return;
}
SYS_LOG_INF(" Data read %x %x", buf[0], buf[1]);
PRINT(" Data read %x %x\n", buf[0], buf[1]);
if ((buf[0] == TEST_DATA_BYTE_0) && (buf[1] == TEST_DATA_BYTE_1)) {
SYS_LOG_INF(" Data read matches with data written. Good!!");
PRINT(" Data read matches with data written. Good!!\n");
} else {
SYS_LOG_INF(" Data read does not match with data "
"written!!");
PRINT(" Data read does not match with data written!!\n");
}
}