Skip to content

Commit 7517710

Browse files
committed
samples: boards: stm32 octo-spi_flash in MemoryMapped mode
Sample to configure the octo/quad external Flash in memory Mapped mode so that read is accessible in memecopy Write too even if not recommended. Signed-off-by: Francois Ramu <[email protected]>
1 parent b65c2e3 commit 7517710

File tree

11 files changed

+322
-0
lines changed

11 files changed

+322
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
cmake_minimum_required(VERSION 3.20.0)
4+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
5+
project(spi_flash)
6+
7+
FILE(GLOB app_sources src/*.c)
8+
target_sources(app PRIVATE ${app_sources})
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
.. zephyr:code-sample:: spi-nor
2+
:name: JEDEC SPI-NOR flash
3+
:relevant-api: flash_interface
4+
5+
Use the flash API to interact with an SPI NOR serial flash memory device.
6+
7+
Overview
8+
********
9+
10+
This sample demonstrates using the :ref:`flash API <flash_api>` on a SPI NOR serial flash
11+
memory device. While trivial it is an example of direct access and
12+
allows confirmation that the flash is working and that automatic power
13+
savings is correctly implemented.
14+
15+
Building and Running
16+
********************
17+
18+
The application will build only for a target that has a :ref:`devicetree
19+
<dt-guide>` entry with ``jedec,spi-nor`` as a compatible.
20+
21+
.. zephyr-app-commands::
22+
:zephyr-app: samples/drivers/spi_flash
23+
:board: nrf52840dk_nrf52840
24+
:goals: build flash
25+
:compact:
26+
27+
Sample Output
28+
=============
29+
30+
.. code-block:: console
31+
32+
*** Booting Zephyr OS build zephyr-v2.3.0-2142-gca01d2e1d748 ***
33+
34+
JEDEC QSPI-NOR SPI flash testing
35+
==========================
36+
37+
Test 1: Flash erase
38+
Flash erase succeeded!
39+
40+
Test 2: Flash write
41+
Attempting to write 4 bytes
42+
Data read matches data written. Good!
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#CONFIG_LOG=y
2+
#CONFIG_FLASH_LOG_LEVEL_DBG=y
3+
CONFIG_STM32_MEMMAP=y
4+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*
2+
* Copyright (c) 2022 STMicroelectronics
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
&octospi2 {
8+
/* channel 12-15 are for transfers to/from external memories */
9+
/* dmas = <&gpdma1 12 41 0x10480>; /* request 41 for OCTOSPI2 */
10+
/* dma-names = "tx_rx";*/
11+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CONFIG_SPI=n
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* Copyright (c) 2022 STMicroelectronics
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
&octospi1 {
8+
dmas = <&dma1 1 0x16 0x480>; /* request for OCTOSPI1 fifo THreshold */
9+
dma-names = "tx_rx";
10+
};
11+
12+
&mdma {
13+
status = "okay";
14+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CONFIG_SPI=n
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright (c) 2022 STMicroelectronics
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
&octospi1 {
8+
dmas = <&dma1 0 41 0x480>; /* request 41 for OCTOSPI1 */
9+
dma-names = "tx_rx";
10+
};
11+
12+
&dma1 {
13+
status = "okay";
14+
};
15+
16+
&dma2 {
17+
status = "okay";
18+
};
19+
20+
&dmamux1 {
21+
status = "okay";
22+
};
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CONFIG_STDOUT_CONSOLE=y
2+
CONFIG_FLASH=y
3+
CONFIG_SPI=y
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
sample:
2+
name: SPI Flash Sample
3+
tests:
4+
sample.drivers.spi.flash:
5+
tags:
6+
- spi
7+
- flash
8+
filter: dt_compat_enabled("jedec,spi-nor") or dt_compat_enabled("st,stm32-qspi-nor")
9+
or dt_compat_enabled("st,stm32-ospi-nor")
10+
platform_exclude: hifive_unmatched
11+
harness: console
12+
harness_config:
13+
type: multi_line
14+
ordered: true
15+
regex:
16+
- "Test 1: Flash erase"
17+
- "Flash erase succeeded!"
18+
- "Test 2: Flash write"
19+
- "Attempting to write 4 bytes"
20+
- "Data read matches data written. Good!!"
21+
depends_on: spi
22+
sample.drivers.spi.flash_dpd:
23+
tags:
24+
- spi
25+
- flash
26+
filter: dt_compat_enabled("jedec,spi-nor")
27+
platform_exclude: hifive_unmatched
28+
build_only: true
29+
extra_configs:
30+
- CONFIG_SPI_NOR_IDLE_IN_DPD=y
31+
depends_on: spi

0 commit comments

Comments
 (0)