misc: Remove generic PRINT macros from flash samples

Remove generic PRINT macros from flash samples and replace
with SYS_LOG  module.

Jira: ZEP-240

Change-Id: I2a9b69e9eb82bbdb03af563bdc49c7ed51681580
Signed-off-by: Juan Manuel Cruz Alcaraz <juan.m.cruz.alcaraz@intel.com>
This commit is contained in:
Juan Manuel Cruz Alcaraz 2016-08-02 22:07:19 -05:00 committed by Inaky Perez-Gonzalez
commit a6412042fb
4 changed files with 52 additions and 54 deletions

View file

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

View file

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

View file

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