|
| 1 | +.. _spi_mngr_sample: |
| 2 | + |
| 3 | +SPI manager: external NOR flash |
| 4 | +############################### |
| 5 | + |
| 6 | +.. contents:: |
| 7 | + :local: |
| 8 | + :depth: 2 |
| 9 | + |
| 10 | +The SPI manager sample demonstrates how to use the :ref:`lib_bm_spi_mngr` library with |BMlong| to perform non-blocking read, page program, and sector erase operations on the external flash memory of the development kit. |
| 11 | + |
| 12 | +Requirements |
| 13 | +************ |
| 14 | + |
| 15 | +Use a development kit with **on-board SPI external flash** and ``BOARD_EXTERNAL_MEMORY_*`` in :file:`board-config.h` (**nRF54L15 DK** and **nRF54LM20 DK** only). The nRF54LV10 and nRF54LS05 DKs have no on-board external flash for this sample and are not listed. |
| 16 | + |
| 17 | +The following board targets match :file:`sample.yaml`: |
| 18 | + |
| 19 | +.. tabs:: |
| 20 | + |
| 21 | + .. group-tab:: Simple board variants |
| 22 | + |
| 23 | + The following board variants do **not** have DFU capabilities: |
| 24 | + |
| 25 | + .. include:: /includes/supported_boards_with_external_flash_memory_non-mcuboot_variants_s115.txt |
| 26 | + |
| 27 | + .. include:: /includes/supported_boards_with_external_flash_memory_non-mcuboot_variants_s145.txt |
| 28 | + |
| 29 | + .. group-tab:: MCUboot board variants |
| 30 | + |
| 31 | + The following board variants have DFU capabilities: |
| 32 | + |
| 33 | + .. include:: /includes/supported_boards_with_external_flash_memory_mcuboot_variants_s115.txt |
| 34 | + |
| 35 | + .. include:: /includes/supported_boards_with_external_flash_memory_mcuboot_variants_s145.txt |
| 36 | + |
| 37 | +.. important:: |
| 38 | + Enable **external storage** in **nRF Connect for Desktop** → **Board Configurator**, then write the configuration to the board. Without that, the on-board flash may not be powered or routed to the SoC, and the sample does not work. |
| 39 | + |
| 40 | +Overview |
| 41 | +******** |
| 42 | + |
| 43 | +The sample uses the SPI manager library to schedule read, program, and erase operations on the external flash without blocking the CPU. All operations target the same flash address (``FLASH_ADDR`` in :file:`main.c`) and share a single SPI manager instance. |
| 44 | + |
| 45 | +The flash is the on-board MX25-class NOR device on the development kit. Its SPI and strap pins are defined by the ``BOARD_EXTERNAL_MEMORY_*`` macros in :file:`board-config.h`. |
| 46 | + |
| 47 | +User interface |
| 48 | +************** |
| 49 | + |
| 50 | +LED 0: |
| 51 | + Lit when the device is initialized. |
| 52 | + |
| 53 | +Button 1: |
| 54 | + Erase the flash sector. |
| 55 | + |
| 56 | +Button 2: |
| 57 | + Read from the flash and log the data as a hex dump. |
| 58 | + |
| 59 | +Button 3: |
| 60 | + Program the message defined by :kconfig:option:`CONFIG_SAMPLE_SPI_MNGR_MSG` to the flash. |
| 61 | + |
| 62 | +Configuration |
| 63 | +************* |
| 64 | + |
| 65 | +Set the message written to flash through the following Kconfig option: |
| 66 | + |
| 67 | +* :kconfig:option:`CONFIG_SAMPLE_SPI_MNGR_MSG`. String written to the external flash during a program operation. The string is truncated to 64 bytes if longer. The default value is ``"Hello World!"``. |
| 68 | + |
| 69 | +Building and running |
| 70 | +******************** |
| 71 | + |
| 72 | +This sample can be found under :file:`samples/peripherals/spi_mngr/` in the |BMshort| folder structure. |
| 73 | + |
| 74 | +For details on how to create, configure, and program a sample, see :ref:`getting_started_with_the_samples`. |
| 75 | + |
| 76 | +Testing |
| 77 | +======= |
| 78 | + |
| 79 | +Make sure that you have enabled **external storage** in the Board Configurator (see the note in the Requirements section) before flashing the sample. |
| 80 | + |
| 81 | +You can then test the sample by performing the following steps: |
| 82 | + |
| 83 | +1. Compile and program the application. |
| 84 | +#. Open a serial terminal and observe the startup log, which lists the buttons and their operations. |
| 85 | +#. Press **Button 2** to read the on-board flash. The hex dump shows either all ``0xFF`` (erased) or whatever was last written to the address in a previous session. |
| 86 | +#. Press **Button 3** to program the configured message. The log prints ``Programming "Hello World!" @ 0x00100000``. |
| 87 | +#. Press **Button 2** again. The hex dump now starts with the message bytes, confirming that the write succeeded. For the default configuration, this is ``48 65 6c 6c 6f 20 57 6f 72 6c 64 21`` followed by ``0xFF`` padding. |
| 88 | +#. Power-cycle the board and press **Button 2** without programming again. The same message reappears, which confirms that the data is non-volatile and persists in the external flash across resets. |
| 89 | +#. Press **Button 1** to erase the sector. Wait a moment for the chip to finish the self-timed erase. |
| 90 | +#. Power-cycle the board and press **Button 2**. The hex dump shows all ``0xFF`` again, which confirms that the erase removed the data. |
| 91 | +#. Optionally, change :kconfig:option:`CONFIG_SAMPLE_SPI_MNGR_MSG` to a different string, rebuild, and repeat steps 4 to 6 to verify that your custom message is written and persists across reboots. |
0 commit comments