1.. _spi_flash_at45_sample:
2
3AT45 DataFlash driver sample
4#############################
5
6Overview
7********
8
9This sample shows how to use the AT45 family DataFlash driver and how to
10specify devicetree nodes that enable flash chip instances to be handled
11by the driver (an overlay with two sample nodes is provided).
12The sample writes a defined test region in the flash memory with bytes of
13increasing (and overflowing at the 8-bit range) values and then reads it back
14to check if the write was successful. The starting value is also increased
15in consecutive runs of the sample.
16
17The sample have two config overlays.
18The :zephyr_file:`samples/drivers/spi_flash_at45/overlay-pm.conf` enables the
19device power management API which allows set device into a low power state.
20The :zephyr_file:`samples/drivers/spi_flash_at45/overlay-page_layout.conf`
21enables the flash page layout API which allow show the flash information.
22
23In the default configuration, the AT45 flash driver is configured to use
24the Read-Modify-Write functionality of DataFlash chips and does not perform
25page erasing, as it is not needed in this case. This can be modified by
26simply disabling the SPI_FLASH_AT45_USE_READ_MODIFY_WRITE option.
27
28Requirements
29************
30
31This sample has been tested on the Nordic Semiconductor nRF9160 DK
32(nrf9160dk_nrf9160) board with the AT45DB321E chip connected.
33It can be easily adjusted to be usable on other boards and with other
34AT45 family chips by just providing a corresponding overlay file.
35
36Building and Running
37********************
38
39The code can be found in :zephyr_file:`samples/drivers/spi_flash_at45`.
40
41To build and flash the application:
42
43.. zephyr-app-commands::
44   :zephyr-app: samples/drivers/spi_flash_at45
45   :board: nrf9160dk_nrf9160
46   :goals: build flash
47   :compact:
48
49To build and flash with device power management enabled:
50
51.. zephyr-app-commands::
52   :zephyr-app: samples/drivers/spi_flash_at45
53   :board: nrf9160dk_nrf9160
54   :gen-args: -DOVERLAY_CONFIG=overlay-pm.conf
55   :goals: build flash
56   :compact:
57
58To build and flash with flash page layout enabled:
59
60.. zephyr-app-commands::
61   :zephyr-app: samples/drivers/spi_flash_at45
62   :board: nrf9160dk_nrf9160
63   :gen-args: -DOVERLAY_CONFIG=overlay-page_layout.conf
64   :goals: build flash
65   :compact:
66
67Finally, to build and flash with both device power management and flash page
68layout enabled:
69
70.. zephyr-app-commands::
71   :zephyr-app: samples/drivers/spi_flash_at45
72   :board: nrf9160dk_nrf9160
73   :gen-args: -DOVERLAY_CONFIG="overlay-pm.conf overlay-page_layout.conf"
74   :goals: build flash
75   :compact:
76
77Sample Output
78=============
79
80This is a typical output when both device power management and flash page
81layout are enabled:
82
83.. code-block:: console
84
85   DataFlash sample app on nrf9160dk_nrf9160
86   Using DATAFLASH_1, chip size: 4194304 bytes (page: 512)
87   Reading the first byte of the test region ... OK
88   Preparing test content starting with 0x01.
89   Writing the first half of the test region... OK
90   Writing the second half of the test region... OK
91   Reading the whole test region... OK
92   Checking the read content... OK
93   Putting the flash device into low power state... OK
94
95The sample is supplied with the overlay file that specifies two instances
96of AT45 family chips but only the one labeled "DATAFLASH_1" is required
97for the sample to work. If the other chip is not connected, the following
98log message appears, but apart from that the behavior of the sample stays
99unaffected.
100
101.. code-block:: console
102
103   [00:00:00.000,000] <err> spi_flash_at45: Wrong JEDEC ID: ff ff ff, expected: 1f 24 00
104