Question about spi usage of the nrfx library

The chip I'm using is the nRF52840, the sdk and toolchain versions are both 2.5.0, my code is here   :



When I call spim3 peripheral with nrfx library, I add
CONFIG_NRFX_SPIM3=y
Code in prj.conf file

Then do the initialisation of spi3 with the following
code
static nrfx_spim_t spi_instance = NRFX_SPIM_INSTANCE(3);
int SPI_init(void)
{
    nrfx_spim_config_t spi_config = NRFX_SPIM_DEFAULT_CONFIG(LCD_SCLK_PIN, LCD_MOSI_PIN, NRF_SPIM_PIN_NOT_CONNECTED, LCD_CS_PIN);
    spi_config.frequency = NRF_SPIM_FREQ_4M;

    nrfx_spim_init(&spi_instance, &spi_config, NULL, NULL);
}

Up to this point I was able to complete the initialisation of spi3 normally and use him without any problems;

But when I want to change spi3 to spi2, I modify the configuration in prj.conf file to
CONFIG_NRFX_SPIM2=y
And change my initialisation code to
static nrfx_spim_t spi_instance = NRFX_SPIM_INSTANCE(2);
int SPI_init(void)
{
    nrfx_spim_config_t spi_config = NRFX_SPIM_DEFAULT_CONFIG(LCD_SCLK_PIN, LCD_MOSI_PIN, NRF_SPIM_PIN_NOT_CONNECTED, LCD_CS_PIN);
    spi_config.frequency = NRF_SPIM_FREQ_4M;

    nrfx_spim_init(&spi_instance, &spi_config, NULL, NULL);
}

When I compile the code after completing the changes, I get an error, and the compilation log reads as follows

* 正在执行任务: nRF Connect: Build [pristine]: lcd_nrfx_spi/build (active)

Building lcd_nrfx_spi
C:\windows\system32\cmd.exe /d /s /c "west build --build-dir d:/Downloads/nRF-Connect-SDK-Demo-master/nRF-Connect-SDK-Demo-master/Peripherals/6_spi/lcd_nrfx_spi/build d:/Downloads/nRF-Connect-SDK-Demo-master/nRF-Connect-SDK-Demo-master/Peripherals/6_spi/lcd_nrfx_spi --pristine --board nrf52840dk_nrf52840 -- -DNCS_TOOLCHAIN_VERSION=NONE"

-- west build: generating a build system
-- Application: D:/Downloads/nRF-Connect-SDK-Demo-master/nRF-Connect-SDK-Demo-master/Peripherals/6_spi/lcd_nrfx_spi
-- CMake version: 3.20.5
Loading Zephyr default modules (Zephyr base).
-- Found Python3: E:/ncs/toolchains/c57af46cb7/opt/bin/python.exe (found suitable version "3.8.2", minimum required is "3.8") found components: Interpreter
-- Cache files will be written to: E:/ncs/v2.5.0/zephyr/.cache
-- Zephyr version: 3.4.99 (E:/ncs/v2.5.0/zephyr)
-- Found west (found suitable version "1.1.0", minimum required is "0.14.0")
-- Board: nrf52840dk_nrf52840
-- Found host-tools: zephyr 0.16.1 (E:/ncs/toolchains/c57af46cb7/opt/zephyr-sdk)
-- Found toolchain: zephyr 0.16.1 (E:/ncs/toolchains/c57af46cb7/opt/zephyr-sdk)
-- Found Dtc: E:/ncs/toolchains/c57af46cb7/opt/bin/dtc.exe (found suitable version "1.4.7", minimum required is "1.4.6")
-- Found BOARD.dts: E:/ncs/v2.5.0/zephyr/boards/arm/nrf52840dk_nrf52840/nrf52840dk_nrf52840.dts
-- Found devicetree overlay: D:/Downloads/nRF-Connect-SDK-Demo-master/nRF-Connect-SDK-Demo-master/Peripherals/6_spi/lcd_nrfx_spi/nrf52840dk_nrf52840.overlay
-- Generated zephyr.dts: D:/Downloads/nRF-Connect-SDK-Demo-master/nRF-Connect-SDK-Demo-master/Peripherals/6_spi/lcd_nrfx_spi/build/zephyr/zephyr.dts
-- Generated devicetree_generated.h: D:/Downloads/nRF-Connect-SDK-Demo-master/nRF-Connect-SDK-Demo-master/Peripherals/6_spi/lcd_nrfx_spi/build/zephyr/include/generated/devicetree_generated.h
-- Including generated dts.cmake file: D:/Downloads/nRF-Connect-SDK-Demo-master/nRF-Connect-SDK-Demo-master/Peripherals/6_spi/lcd_nrfx_spi/build/zephyr/dts.cmake

warning: NRFX_SPIM2 (defined at E:/ncs/v2.5.0/zephyr/modules/hal_nordic\nrfx/Kconfig:218,
modules\hal_nordic\nrfx/Kconfig:218) was assigned the value 'y' but got the value 'n'. Check these
unsatisfied dependencies: n (=n). See
docs.zephyrproject.org/.../kconfig.html and/or look up NRFX_SPIM2 in the
menuconfig/guiconfig interface. The Application Development Primer, Setting Configuration Values,
and Kconfig - Tips and Best Practices sections of the manual might be helpful too.

Parsing E:/ncs/v2.5.0/zephyr/Kconfig
Loaded configuration 'E:/ncs/v2.5.0/zephyr/boards/arm/nrf52840dk_nrf52840/nrf52840dk_nrf52840_defconfig'
Merged configuration 'D:/Downloads/nRF-Connect-SDK-Demo-master/nRF-Connect-SDK-Demo-master/Peripherals/6_spi/lcd_nrfx_spi/prj.conf'
Configuration saved to 'D:/Downloads/nRF-Connect-SDK-Demo-master/nRF-Connect-SDK-Demo-master/Peripherals/6_spi/lcd_nrfx_spi/build/zephyr/.config'
Kconfig header saved to 'D:/Downloads/nRF-Connect-SDK-Demo-master/nRF-Connect-SDK-Demo-master/Peripherals/6_spi/lcd_nrfx_spi/build/zephyr/include/generated/autoconf.h'
-- Found GnuLd: e:/ncs/toolchains/c57af46cb7/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd.exe (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: E:/ncs/toolchains/c57af46cb7/opt/zephyr-sdk/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc.exe
-- Configuring done
-- Generating done
-- Build files have been written to: D:/Downloads/nRF-Connect-SDK-Demo-master/nRF-Connect-SDK-Demo-master/Peripherals/6_spi/lcd_nrfx_spi/build
-- west build: building application
[2/142] Generating include/generated/version.h
-- Zephyr version: 3.4.99 (E:/ncs/v2.5.0/zephyr), build: v3.4.99-ncs1
[61/142] Building C object CMakeFiles/app.dir/src/lcd_init.c.obj
FAILED: CMakeFiles/app.dir/src/lcd_init.c.obj
E:\ncs\toolchains\c57af46cb7\opt\zephyr-sdk\arm-zephyr-eabi\bin\arm-zephyr-eabi-gcc.exe -DKERNEL -DNRF52840_XXAA -DPICOLIBC_INTEGER_PRINTF_SCANF -D_FORTIFY_SOURCE=1 -D_POSIX_C_SOURCE=200809 -D__LINUX_ERRNO_EXTENSIONS__ -D__PROGRAM_START -D__ZEPHYR__=1 -IE:/ncs/v2.5.0/zephyr/include -Izephyr/include/generated -IE:/ncs/v2.5.0/zephyr/soc/arm/nordic_nrf/nrf52 -IE:/ncs/v2.5.0/zephyr/soc/arm/nordic_nrf/common/. -IE:/ncs/v2.5.0/nrf/include -IE:/ncs/v2.5.0/nrf/tests/include -IE:/ncs/v2.5.0/modules/hal/cmsis/CMSIS/Core/Include -IE:/ncs/v2.5.0/zephyr/modules/cmsis/. -IE:/ncs/v2.5.0/modules/hal/nordic/nrfx -IE:/ncs/v2.5.0/modules/hal/nordic/nrfx/drivers/include -IE:/ncs/v2.5.0/modules/hal/nordic/nrfx/mdk -IE:/ncs/v2.5.0/zephyr/modules/hal_nordic/nrfx/. -IE:/ncs/v2.5.0/modules/debug/segger/SEGGER -IE:/ncs/v2.5.0/modules/debug/segger/Config -isystem E:/ncs/v2.5.0/nrfxlib/crypto/nrf_cc310_platform/include -fno-strict-aliasing -Os -imacros D:/Downloads/nRF-Connect-SDK-Demo-master/nRF-Connect-SDK-Demo-master/Peripherals/6_spi/lcd_nrfx_spi/build/zephyr/include/generated/autoconf.h -fno-printf-return-value -fno-common -g -gdwarf-4 -fdiagnostics-color=always -mcpu=cortex-m4 -mthumb -mabi=aapcs -mfp16-format=ieee --sysroot=E:/ncs/toolchains/c57af46cb7/opt/zephyr-sdk/arm-zephyr-eabi/arm-zephyr-eabi -imacros E:/ncs/v2.5.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 -ftls-model=local-exec -fno-reorder-functions --param=min-pagesize=0 -fno-defer-pop -fmacro-prefix-map=D:/Downloads/nRF-Connect-SDK-Demo-master/nRF-Connect-SDK-Demo-master/Peripherals/6_spi/lcd_nrfx_spi=CMAKE_SOURCE_DIR -fmacro-prefix-map=E:/ncs/v2.5.0/zephyr=ZEPHYR_BASE -fmacro-prefix-map=E:/ncs/v2.5.0=WEST_TOPDIR -ffunction-sections -fdata-sections --specs=picolibc.specs -std=c99 -MD -MT CMakeFiles/app.dir/src/lcd_init.c.obj -MF CMakeFiles\app.dir\src\lcd_init.c.obj.d -o CMakeFiles/app.dir/src/lcd_init.c.obj -c ../src/lcd_init.c
In file included from E:/ncs/v2.5.0/modules/hal/nordic/nrfx/nrfx.h:38,
from E:/ncs/v2.5.0/modules/hal/nordic/nrfx/hal/nrf_gpio.h:37,
from ../src/lcd_init.h:4,
from ../src/lcd_init.c:1:
E:/ncs/v2.5.0/modules/hal/nordic/nrfx/drivers/include/nrfx_spim.h:71:35: error: 'NRFX_SPIM2_INST_IDX' undeclared here (not in a function); did you mean 'NRF_SPIM_INST_GET'?
71 | .drv_inst_idx = NRFX_CONCAT_3(NRFX_SPIM, id, _INST_IDX), \
| ^~~~~~~~~
E:/ncs/v2.5.0/modules/hal/nordic/nrfx/drivers/nrfx_common.h:188:36: note: in definition of macro 'NRFX_CONCAT_3_'
188 | #define NRFX_CONCAT_3_(p1, p2, p3) p1 ## p2 ## p3
| ^~
E:/ncs/v2.5.0/modules/hal/nordic/nrfx/drivers/include/nrfx_spim.h:71:21: note: in expansion of macro 'NRFX_CONCAT_3'
71 | .drv_inst_idx = NRFX_CONCAT_3(NRFX_SPIM, id, _INST_IDX), \
| ^~~~~~~~~~~~~
../src/lcd_init.c:7:35: note: in expansion of macro 'NRFX_SPIM_INSTANCE'
7 | static nrfx_spim_t spi_instance = NRFX_SPIM_INSTANCE(2);
| ^~~~~~~~~~~~~~~~~~
../src/lcd_init.c: In function 'SPI_init':
../src/lcd_init.c:15:1: warning: control reaches end of non-void function [-Wreturn-type]
15 | }
| ^
[78/142] Building C object zephyr/drivers/serial/CMakeFiles/drivers__serial.dir/uart_nrfx_uarte.c.obj
ninja: build stopped: subcommand failed.
FATAL ERROR: command exited with status 1: 'E:\ncs\toolchains\c57af46cb7\opt\bin\cmake.EXE' --build 'd:\Downloads\nRF-Connect-SDK-Demo-master\nRF-Connect-SDK-Demo-master\Peripherals\6_spi\lcd_nrfx_spi\build'
Related