1818#include <zephyr.h>
1919#include <flash.h>
2020#include <device.h>
21-
22- #define SYS_LOG_LEVEL SYS_LOG_LEVEL_INFO
23- #include <misc/sys_log.h>
21+ #if defined(CONFIG_STDOUT_CONSOLE )
22+ #include <stdio.h>
23+ #define PRINT printf
24+ #else
25+ #include <misc/printk.h>
26+ #define PRINT printk
27+ #endif
2428
2529/* Offset between pages */
2630#define FLASH_TEST_OFFSET 0x40000
@@ -41,83 +45,79 @@ void main(void)
4145 uint32_t buf_word = 0 ;
4246 uint32_t i , offset ;
4347
44- SYS_LOG_INF ("\nNordic nRF5 Flash Testing" );
45- SYS_LOG_INF ("=========================" );
48+ PRINT ("\nNordic nRF5 Flash Testing\n " );
49+ PRINT ("=========================\n " );
4650
4751 flash_dev = device_get_binding ("NRF5_FLASH" );
4852
4953 if (!flash_dev ) {
50- SYS_LOG_ERR ("Nordic nRF5 flash driver was not found!" );
54+ PRINT ("Nordic nRF5 flash driver was not found!\n " );
5155 return ;
5256 }
5357
54- SYS_LOG_INF ("\nTest 1: Flash erase page at 0x%x" , FLASH_TEST_OFFSET );
58+ PRINT ("\nTest 1: Flash erase page at 0x%x\n " , FLASH_TEST_OFFSET );
5559 if (flash_erase (flash_dev , FLASH_TEST_OFFSET , FLASH_PAGE_SIZE ) != 0 ) {
56- SYS_LOG_INF (" Flash erase failed!" );
60+ PRINT (" Flash erase failed!\n " );
5761 } else {
58- SYS_LOG_INF (" Flash erase succeeded!" );
62+ PRINT (" Flash erase succeeded!\n " );
5963 }
6064
61- SYS_LOG_INF ("\nTest 2: Flash write (word array 1)" );
65+ PRINT ("\nTest 2: Flash write (word array 1)\n " );
6266 flash_write_protection_set (flash_dev , false);
6367 for (i = 0 ; i < TEST_DATA_LEN ; i ++ ) {
6468 offset = FLASH_TEST_OFFSET + (i << 2 );
65- SYS_LOG_INF (" Attempted to write %x at 0x%x" ,
66- buf_array_1 [ i ], offset );
69+ PRINT (" Attempted to write %x at 0x%x\n" , buf_array_1 [ i ] ,
70+ offset );
6771 if (flash_write (flash_dev , offset , & buf_array_1 [i ],
6872 TEST_DATA_LEN ) != 0 ) {
69- SYS_LOG_INF (" Flash write failed!" );
73+ PRINT (" Flash write failed!\n " );
7074 return ;
7175 }
72- SYS_LOG_INF (" Attempted to read 0x%x" , offset );
76+ PRINT (" Attempted to read 0x%x\n " , offset );
7377 if (flash_read (flash_dev , offset , & buf_word ,
7478 TEST_DATA_LEN ) != 0 ) {
75- SYS_LOG_INF (" Flash read failed!" );
79+ PRINT (" Flash read failed!\n " );
7680 return ;
7781 }
78- SYS_LOG_INF (" Data read: %x" , buf_word );
82+ PRINT (" Data read: %x\n " , buf_word );
7983 if (buf_array_1 [i ] == buf_word ) {
80- SYS_LOG_INF (" Data read matches data written. "
81- "Good!" );
84+ PRINT (" Data read matches data written. Good!\n" );
8285 } else {
83- SYS_LOG_INF (" Data read does not match data "
84- "written!" );
86+ PRINT (" Data read does not match data written!\n" );
8587 }
8688 }
8789 flash_write_protection_set (flash_dev , true);
8890
8991 offset = FLASH_TEST_OFFSET - FLASH_PAGE_SIZE * 2 ;
90- SYS_LOG_INF ("\nTest 3: Flash erase (4 pages at 0x%x)" , offset );
92+ PRINT ("\nTest 3: Flash erase (4 pages at 0x%x)\n " , offset );
9193 if (flash_erase (flash_dev , offset , FLASH_PAGE_SIZE * 4 ) != 0 ) {
92- SYS_LOG_INF (" Flash erase failed!" );
94+ PRINT (" Flash erase failed!\n " );
9395 } else {
94- SYS_LOG_INF (" Flash erase succeeded!" );
96+ PRINT (" Flash erase succeeded!\n " );
9597 }
9698
97- SYS_LOG_INF ("\nTest 4: Flash write (word array 2)" );
99+ PRINT ("\nTest 4: Flash write (word array 2)\n " );
98100 flash_write_protection_set (flash_dev , false);
99101 for (i = 0 ; i < TEST_DATA_LEN ; i ++ ) {
100102 offset = FLASH_TEST_OFFSET + (i << 2 );
101- SYS_LOG_INF (" Attempted to write %x at 0x%x" ,
102- buf_array_2 [ i ], offset );
103+ PRINT (" Attempted to write %x at 0x%x\n" , buf_array_2 [ i ] ,
104+ offset );
103105 if (flash_write (flash_dev , offset , & buf_array_2 [i ],
104106 TEST_DATA_LEN ) != 0 ) {
105- SYS_LOG_INF (" Flash write failed!" );
107+ PRINT (" Flash write failed!\n " );
106108 return ;
107109 }
108- SYS_LOG_INF (" Attempted to read 0x%x" , offset );
110+ PRINT (" Attempted to read 0x%x\n " , offset );
109111 if (flash_read (flash_dev , offset , & buf_word ,
110112 TEST_DATA_LEN ) != 0 ) {
111- SYS_LOG_INF (" Flash read failed!" );
113+ PRINT (" Flash read failed!\n " );
112114 return ;
113115 }
114- SYS_LOG_INF (" Data read: %x" , buf_word );
116+ PRINT (" Data read: %x\n " , buf_word );
115117 if (buf_array_2 [i ] == buf_word ) {
116- SYS_LOG_INF (" Data read matches data written. "
117- "Good!" );
118+ PRINT (" Data read matches data written. Good!\n" );
118119 } else {
119- SYS_LOG_INF (" Data read does not match data "
120- "written!" );
120+ PRINT (" Data read does not match data written!\n" );
121121 }
122122 }
123123 flash_write_protection_set (flash_dev , true);
0 commit comments