Zephyr sample code for accessing NOR flash through SPI APIs

I would like to access NOR flash through SPI APIs on nRF5340 device. Does Nordic provide Zephyr sample code for accessing NOR flash through SPI APIs?

Parents
  • Hi,

    There is already a sample in Zephyr for SPI-NOR flash,

    regards

    Jared 

  • Thanks for your reply! The sample that you provided is using nordic,qspi-nor. Could you provide another sample for jedec,spi-nor. 

    &spi3 {
    	cs-gpios = <&arduino_header 16 GPIO_ACTIVE_LOW>, /* D10 */
    		   <&gpio0 25 GPIO_ACTIVE_LOW>;
    	mx25r64: mx25r6435f@1 {
    		compatible = "jedec,spi-nor";
    		status = "disabled";
    		reg = <1>;
    		spi-max-frequency = <8000000>;
    		label = "MX25R64";
    		jedec-id = [c2 28 17];
    		sfdp-bfp = [
    			e5 20 f1 ff  ff ff ff 03  44 eb 08 6b  08 3b 04 bb
    			ee ff ff ff  ff ff 00 ff  ff ff 00 ff  0c 20 0f 52
    			10 d8 00 ff  23 72 f5 00  82 ed 04 cc  44 83 68 44
    			30 b0 30 b0  f7 c4 d5 5c  00 be 29 ff  f0 d0 ff ff
    		];
    		size = <67108864>;
    		has-dpd;
    		t-enter-dpd = <10000>;
    		t-exit-dpd = <35000>;
    	};
    };
    

  • Procedure to reproduce this issue are as follows.

    1. cd ~/ncs/v2.4.0/zephyr/samples/drivers/spi_flash

    2. west build -b nrf9161dk_nrf9161

  • ~/ncs/v2.4.0/zephyr/samples/drivers/spi_flash$ west build -b nrf9161dk_nrf9161
    -- west build: generating a build system
    Loading Zephyr default modules (Zephyr base).
    -- Application: /home/henry/ncs/v2.4.0/zephyr/samples/drivers/spi_flash
    -- CMake version: 3.20.5
    -- Using NCS Toolchain 2.4.0 for building. (/home/henry/ncs/toolchains/1f9b40e71a/cmake)
    -- Found Python3: /home/henry/ncs/toolchains/1f9b40e71a/usr/local/bin/python3 (found suitable exact version "3.8.2") found components: Interpreter 
    -- Cache files will be written to: /home/henry/.cache/zephyr
    -- Zephyr version: 3.3.99 (/home/henry/ncs/v2.4.0/zephyr)
    -- Found west (found suitable version "1.0.0", minimum required is "0.7.1")
    -- Board: nrf9161dk_nrf9161
    -- Found host-tools: zephyr 0.16.0 (/home/henry/ncs/toolchains/1f9b40e71a/opt/zephyr-sdk)
    -- Found toolchain: zephyr 0.16.0 (/home/henry/ncs/toolchains/1f9b40e71a/opt/zephyr-sdk)
    -- Found Dtc: /home/henry/ncs/toolchains/1f9b40e71a/usr/local/bin/dtc (found suitable version "1.4.7", minimum required is "1.4.6") 
    -- Found BOARD.dts: /home/henry/ncs/v2.4.0/zephyr/boards/arm/nrf9161dk_nrf9161/nrf9161dk_nrf9161.dts
    -- Generated zephyr.dts: /home/henry/ncs/v2.4.0/zephyr/samples/drivers/spi_flash/build/zephyr/zephyr.dts
    -- Generated devicetree_generated.h: /home/henry/ncs/v2.4.0/zephyr/samples/drivers/spi_flash/build/zephyr/include/generated/devicetree_generated.h
    -- Including generated dts.cmake file: /home/henry/ncs/v2.4.0/zephyr/samples/drivers/spi_flash/build/zephyr/dts.cmake
    Parsing /home/henry/ncs/v2.4.0/zephyr/Kconfig
    Loaded configuration '/home/henry/ncs/v2.4.0/zephyr/boards/arm/nrf9161dk_nrf9161/nrf9161dk_nrf9161_defconfig'
    Merged configuration '/home/henry/ncs/v2.4.0/zephyr/samples/drivers/spi_flash/prj.conf'
    Configuration saved to '/home/henry/ncs/v2.4.0/zephyr/samples/drivers/spi_flash/build/zephyr/.config'
    Kconfig header saved to '/home/henry/ncs/v2.4.0/zephyr/samples/drivers/spi_flash/build/zephyr/include/generated/autoconf.h'
    -- Found GnuLd: /home/henry/ncs/toolchains/1f9b40e71a/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd (found version "2.38") 
    -- The C compiler identification is GNU 12.2.0
    -- The CXX compiler identification is GNU 12.2.0
    -- The ASM compiler identification is GNU
    -- Found assembler: /home/henry/ncs/toolchains/1f9b40e71a/opt/zephyr-sdk/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc
    CMake Warning at ../../../CMakeLists.txt:838 (message):
      No SOURCES given to Zephyr library: lib__libc__common
    
      Excluding target from build.
    
    
    -- Configuring done
    -- Generating done
    -- Build files have been written to: /home/henry/ncs/v2.4.0/zephyr/samples/drivers/spi_flash/build
    -- west build: building application
    [1/175] Preparing syscall dependency handling
    
    [2/175] Generating include/generated/version.h
    -- Zephyr version: 3.3.99 (/home/henry/ncs/v2.4.0/zephyr), build: v3.3.99-ncs1
    [67/175] Building C object CMakeFiles/app.dir/src/main.c.obj
    FAILED: CMakeFiles/app.dir/src/main.c.obj 
    ccache /home/henry/ncs/toolchains/1f9b40e71a/opt/zephyr-sdk/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc -DKERNEL -DNRF9120_XXAA -DNRF_SKIP_FICR_NS_COPY_TO_RAM -DUSE_PARTITION_MANAGER=0 -D__PROGRAM_START -D__ZEPHYR__=1 -I/home/henry/ncs/v2.4.0/zephyr/include -Izephyr/include/generated -I/home/henry/ncs/v2.4.0/zephyr/soc/arm/nordic_nrf/nrf91 -I/home/henry/ncs/v2.4.0/zephyr/soc/arm/nordic_nrf/common/. -I/home/henry/ncs/v2.4.0/nrf/include -I/home/henry/ncs/v2.4.0/nrf/tests/include -I/home/henry/ncs/v2.4.0/modules/hal/cmsis/CMSIS/Core/Include -I/home/henry/ncs/v2.4.0/modules/hal/nordic/nrfx -I/home/henry/ncs/v2.4.0/modules/hal/nordic/nrfx/drivers/include -I/home/henry/ncs/v2.4.0/modules/hal/nordic/nrfx/mdk -I/home/henry/ncs/v2.4.0/zephyr/modules/hal_nordic/nrfx/. -isystem /home/henry/ncs/v2.4.0/zephyr/lib/libc/minimal/include -isystem /home/henry/ncs/toolchains/1f9b40e71a/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/include -isystem /home/henry/ncs/toolchains/1f9b40e71a/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/include-fixed -isystem /home/henry/ncs/v2.4.0/nrfxlib/crypto/nrf_cc310_platform/include -fno-strict-aliasing -Os -imacros /home/henry/ncs/v2.4.0/zephyr/samples/drivers/spi_flash/build/zephyr/include/generated/autoconf.h -ffreestanding -fno-common -g -gdwarf-4 -fdiagnostics-color=always -mcpu=cortex-m33 -mthumb -mabi=aapcs --sysroot=/home/henry/ncs/toolchains/1f9b40e71a/opt/zephyr-sdk/arm-zephyr-eabi/arm-zephyr-eabi -imacros /home/henry/ncs/v2.4.0/zephyr/include/zephyr/toolchain/zephyr_stdint.h -Wall -Wformat -Wformat-security -Wno-format-zero-length -Wno-pointer-sign -Wpointer-arith -Wexpansion-to-defined -Wno-unused-but-set-variable -Werror=implicit-int -fno-pic -fno-pie -fno-asynchronous-unwind-tables -fno-reorder-functions --param=min-pagesize=0 -fno-defer-pop -fmacro-prefix-map=/home/henry/ncs/v2.4.0/zephyr/samples/drivers/spi_flash=CMAKE_SOURCE_DIR -fmacro-prefix-map=/home/henry/ncs/v2.4.0/zephyr=ZEPHYR_BASE -fmacro-prefix-map=/home/henry/ncs/v2.4.0=WEST_TOPDIR -ffunction-sections -fdata-sections -std=c99 -nostdinc -MD -MT CMakeFiles/app.dir/src/main.c.obj -MF CMakeFiles/app.dir/src/main.c.obj.d -o CMakeFiles/app.dir/src/main.c.obj -c ../src/main.c
    In file included from /home/henry/ncs/v2.4.0/zephyr/include/zephyr/toolchain/gcc.h:92,
                     from /home/henry/ncs/v2.4.0/zephyr/include/zephyr/toolchain.h:50,
                     from /home/henry/ncs/v2.4.0/zephyr/include/zephyr/kernel_includes.h:19,
                     from /home/henry/ncs/v2.4.0/zephyr/include/zephyr/kernel.h:17,
                     from ../src/main.c:7:
    ../src/main.c: In function 'main':
    /home/henry/ncs/v2.4.0/zephyr/include/zephyr/device.h:84:41: error: '__device_dts_ord_113' undeclared (first use in this function); did you mean '__device_dts_ord_13'?
       84 | #define DEVICE_NAME_GET(dev_id) _CONCAT(__device_, dev_id)
          |                                         ^~~~~~~~~
    /home/henry/ncs/v2.4.0/zephyr/include/zephyr/toolchain/common.h:132:26: note: in definition of macro '_DO_CONCAT'
      132 | #define _DO_CONCAT(x, y) x ## y
          |                          ^
    /home/henry/ncs/v2.4.0/zephyr/include/zephyr/device.h:84:33: note: in expansion of macro '_CONCAT'
       84 | #define DEVICE_NAME_GET(dev_id) _CONCAT(__device_, dev_id)
          |                                 ^~~~~~~
    /home/henry/ncs/v2.4.0/zephyr/include/zephyr/device.h:210:37: note: in expansion of macro 'DEVICE_NAME_GET'
      210 | #define DEVICE_DT_NAME_GET(node_id) DEVICE_NAME_GET(Z_DEVICE_DT_DEV_ID(node_id))
          |                                     ^~~~~~~~~~~~~~~
    /home/henry/ncs/v2.4.0/zephyr/include/zephyr/device.h:227:34: note: in expansion of macro 'DEVICE_DT_NAME_GET'
      227 | #define DEVICE_DT_GET(node_id) (&DEVICE_DT_NAME_GET(node_id))
          |                                  ^~~~~~~~~~~~~~~~~~
    ../src/main.c:180:42: note: in expansion of macro 'DEVICE_DT_GET'
      180 |         const struct device *flash_dev = DEVICE_DT_GET(DT_ALIAS(spi_flash0));
          |                                          ^~~~~~~~~~~~~
    /home/henry/ncs/v2.4.0/zephyr/include/zephyr/device.h:84:41: note: each undeclared identifier is reported only once for each function it appears in
       84 | #define DEVICE_NAME_GET(dev_id) _CONCAT(__device_, dev_id)
          |                                         ^~~~~~~~~
    /home/henry/ncs/v2.4.0/zephyr/include/zephyr/toolchain/common.h:132:26: note: in definition of macro '_DO_CONCAT'
      132 | #define _DO_CONCAT(x, y) x ## y
          |                          ^
    /home/henry/ncs/v2.4.0/zephyr/include/zephyr/device.h:84:33: note: in expansion of macro '_CONCAT'
       84 | #define DEVICE_NAME_GET(dev_id) _CONCAT(__device_, dev_id)
          |                                 ^~~~~~~
    /home/henry/ncs/v2.4.0/zephyr/include/zephyr/device.h:210:37: note: in expansion of macro 'DEVICE_NAME_GET'
      210 | #define DEVICE_DT_NAME_GET(node_id) DEVICE_NAME_GET(Z_DEVICE_DT_DEV_ID(node_id))
          |                                     ^~~~~~~~~~~~~~~
    /home/henry/ncs/v2.4.0/zephyr/include/zephyr/device.h:227:34: note: in expansion of macro 'DEVICE_DT_NAME_GET'
      227 | #define DEVICE_DT_GET(node_id) (&DEVICE_DT_NAME_GET(node_id))
          |                                  ^~~~~~~~~~~~~~~~~~
    ../src/main.c:180:42: note: in expansion of macro 'DEVICE_DT_GET'
      180 |         const struct device *flash_dev = DEVICE_DT_GET(DT_ALIAS(spi_flash0));
          |                                          ^~~~~~~~~~~~~
    [80/175] Building C object zephyr/arch/arch/arm/core/aarch3...akeFiles/arch__arm__core__aarch32__cortex_m.dir/fault.c.obj
    ninja: build stopped: subcommand failed.
    

  • Hi,

    Ah yes, you are correct in that it uses QSPI. It's because the onboard flash supports QSPI and not SPI. Are you going to use the onboard external flash? Or do you have a stand alone onboard flash device?

    regards

    Jared

Reply Children
Related