diff --git a/samples/drivers/soc_flash_nrf5/prj.conf b/samples/drivers/soc_flash_nrf5/prj.conf index 2b15c897a54..ddba4985063 100644 --- a/samples/drivers/soc_flash_nrf5/prj.conf +++ b/samples/drivers/soc_flash_nrf5/prj.conf @@ -1,3 +1,4 @@ CONFIG_STDOUT_CONSOLE=y CONFIG_FLASH=y CONFIG_SOC_FLASH_NRF5=y +CONFIG_SYS_LOG=y diff --git a/samples/drivers/soc_flash_nrf5/src/main.c b/samples/drivers/soc_flash_nrf5/src/main.c index 377d3665795..5ea51148f21 100644 --- a/samples/drivers/soc_flash_nrf5/src/main.c +++ b/samples/drivers/soc_flash_nrf5/src/main.c @@ -18,13 +18,9 @@ #include #include #include -#if defined(CONFIG_STDOUT_CONSOLE) -#include -#define PRINT printf -#else -#include -#define PRINT printk -#endif + +#define SYS_LOG_LEVEL SYS_LOG_LEVEL_INFO +#include /* 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); diff --git a/samples/drivers/spi_flash/prj.conf b/samples/drivers/spi_flash/prj.conf index 9f1a32ff484..5a5597b05bb 100644 --- a/samples/drivers/spi_flash/prj.conf +++ b/samples/drivers/spi_flash/prj.conf @@ -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 diff --git a/samples/drivers/spi_flash/src/main.c b/samples/drivers/spi_flash/src/main.c index 87124831005..737daee21bc 100644 --- a/samples/drivers/spi_flash/src/main.c +++ b/samples/drivers/spi_flash/src/main.c @@ -17,13 +17,8 @@ #include #include #include -#if defined(CONFIG_STDOUT_CONSOLE) -#include -#define PRINT printf -#else -#include -#define PRINT printk -#endif +#define SYS_LOG_LEVEL SYS_LOG_LEVEL_INFO +#include #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!!"); } }