1.. _soc-flash-nrf-sample: 2 3nRF SoC flash sample 4#################### 5 6Overview 7******** 8 9This sample demonstrates using the flash API on a SoC internal flash. 10The sample uses :ref:`flash_map_api` to obtain device for flash, using 11DTS node label, and then directly uses :ref:`flash_api` to perform 12flash operations. 13 14Within the sample user may observe how read/write/erase operations 15are performed on a device and how to first check whether device is 16ready for operation. 17 18Building and Running 19******************** 20 21The application will build for any SoC with internal flash memory 22access enabled, as it is default for SoC devices, and fixed-partition 23defined over that internal flash labeled `slot1_partition`, when 24:kconfig:option:`CONFIG_TRUSTED_EXECUTION_NONSECURE` is not selected, 25or `slot1_ns_partition`, when the Kconfig option is selected. 26 27.. zephyr-app-commands:: 28 :zephyr-app: samples/drivers/soc_flash_nrf 29 :board: nrf52840dk_nrf52840 30 :goals: build flash 31 :compact: 32 33Sample Output 34============= 35 36.. code-block:: console 37 38 *** Booting Zephyr OS build v2.7.99-17621-g54832687bcbb *** 39 40 Nordic nRF5 Flash Testing 41 ========================= 42 43 Test 1: Flash erase page at 0x82000 44 Flash erase succeeded! 45 46 Test 2: Flash write (word array 1) 47 Attempted to write 1122 at 0x82000 48 Attempted to read 0x82000 49 Data read: 1122 50 Data read matches data written. Good! 51 Attempted to write aabb at 0x82004 52 Attempted to read 0x82004 53 Data read: aabb 54 Data read matches data written. Good! 55 Attempted to write abcd at 0x82008 56 Attempted to read 0x82008 57 Data read: abcd 58 Data read matches data written. Good! 59 Attempted to write 1234 at 0x8200c 60 Attempted to read 0x8200c 61 Data read: 1234 62 Data read matches data written. Good! 63 64 Test 3: Flash erase (4 pages at 0x80000) 65 Flash erase succeeded! 66 67 Test 4: Flash write (word array 2) 68 Attempted to write 1234 at 0x82000 69 Attempted to read 0x82000 70 Data read: 1234 71 Data read matches data written. Good! 72 Attempted to write aabb at 0x82004 73 Attempted to read 0x82004 74 Data read: aabb 75 Data read matches data written. Good! 76 Attempted to write abcd at 0x82008 77 Attempted to read 0x82008 78 Data read: abcd 79 Data read matches data written. Good! 80 Attempted to write 1122 at 0x8200c 81 Attempted to read 0x8200c 82 Data read: 1122 83 Data read matches data written. Good! 84 85 Test 5: Flash erase page at 0x82000 86 Flash erase succeeded! 87 88 Test 6: Non-word aligned write (word array 3) 89 Attempted to write 1122 at 0x82001 90 Attempted to read 0x82001 91 Data read: 1122 92 Data read matches data written. Good! 93 Attempted to write aabb at 0x82005 94 Attempted to read 0x82005 95 Data read: aabb 96 Data read matches data written. Good! 97 Attempted to write abcd at 0x82009 98 Attempted to read 0x82009 99 Data read: abcd 100 Data read matches data written. Good! 101 Attempted to write 1234 at 0x8200d 102 Attempted to read 0x8200d 103 Data read: 1234 104 Data read matches data written. Good! 105 Attempted to write 1122 at 0x82011 106 Attempted to read 0x82011 107 Data read: 1122 108 Data read matches data written. Good! 109 Attempted to write aabb at 0x82015 110 Attempted to read 0x82015 111 Data read: aabb 112 Data read matches data written. Good! 113 Attempted to write abcd at 0x82019 114 Attempted to read 0x82019 115 Data read: abcd 116 Data read matches data written. Good! 117 Attempted to write 1234 at 0x8201d 118 Attempted to read 0x8201d 119 Data read: 1234 120 Data read matches data written. Good! 121 122 Test 7: Page layout API 123 Offset 0x00041234: 124 belongs to the page 65 of start offset 0x00041000 125 and the size of 0x00001000 B. 126 Page of number 37 has start offset 0x00025000 127 and size of 0x00001000 B. 128 Page index resolved properly 129 SoC flash consists of 256 pages. 130 131 Test 8: Write block size API 132 write-block-size = 1 133