Hi, I created an nrfx spim instance referring to the nrfx_spim example on GitHub, but I'm having a problem.
I added it to the prj.conf file as follows.
Is there anything I didn't know and left out??
thank you
Hi, I created an nrfx spim instance referring to the nrfx_spim example on GitHub, but I'm having a problem.
I added it to the prj.conf file as follows.
Is there anything I didn't know and left out??
thank you
Hi,
Do you have a .overlay for your board in place?
It should look something like this, located in my_project/boards/nrf52dk_nrf52832.overlay:
&spi1 { status = "okay"; compatible = "nordic,nrf-spim"; pinctrl-0 = <&spi1_default>; ...rest of configuration };
Do you get any complication/cmake errors? If yes, please post these.
Kind regards,
Håkon
Thank you for your answer.
.overlay file has added settings for spi1 as shown in the picture below, but the error still occurs.
Can you share the full compiler/cmake error?
Kind regards,
Håkon
An error occurs when executing the build as shown below.
FAILED: CMakeFiles/app.dir/src/main.c.obj
C:\ncs\toolchains\31f4403e35\opt\zephyr-sdk\arm-zephyr-eabi\bin\arm-zephyr-eabi-gcc.exe -DKERNEL -DNRF52832_XXAA -DUSE_PARTITION_MANAGER=0 -D__PROGRAM_START -D__ZEPHYR__=1 -IC:/ncs/v2.4.0/zephyr/include -Izephyr/include/generated -IC:/ncs/v2.4.0/zephyr/soc/arm/nordic_nrf/nrf52 -IC:/ncs/v2.4.0/zephyr/soc/arm/nordic_nrf/common/. -IC:/ncs/v2.4.0/nrf/include -IC:/ncs/v2.4.0/nrf/tests/include -IC:/ncs/v2.4.0/modules/hal/cmsis/CMSIS/Core/Include -IC:/ncs/v2.4.0/modules/hal/nordic/nrfx -IC:/ncs/v2.4.0/modules/hal/nordic/nrfx/drivers/include -IC:/ncs/v2.4.0/modules/hal/nordic/nrfx/mdk -IC:/ncs/v2.4.0/zephyr/modules/hal_nordic/nrfx/. -IC:/ncs/v2.4.0/modules/debug/segger/SEGGER -IC:/ncs/v2.4.0/modules/debug/segger/Config -IC:/ncs/v2.4.0/zephyr/modules/segger/. -isystem C:/ncs/v2.4.0/zephyr/lib/libc/minimal/include -isystem c:/ncs/toolchains/31f4403e35/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/include -isystem c:/ncs/toolchains/31f4403e35/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/include-fixed -fno-strict-aliasing -Og -imacros E:/testhere/spitest/build/zephyr/include/generated/autoconf.h -ffreestanding -fno-common -g -gdwarf-4 -fdiagnostics-color=always -mcpu=cortex-m4 -mthumb -mabi=aapcs --sysroot=C:/ncs/toolchains/31f4403e35/opt/zephyr-sdk/arm-zephyr-eabi/arm-zephyr-eabi -imacros C:/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=E:/testhere/spitest=CMAKE_SOURCE_DIR -fmacro-prefix-map=C:/ncs/v2.4.0/zephyr=ZEPHYR_BASE -fmacro-prefix-map=C:/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 C:\ncs\v2.4.0\modules\hal\nordic\nrfx\nrfx.h:38,
from c:\ncs\v2.4.0\zephyr\soc\arm\nordic_nrf\common\soc_nrf_common.h:14,
from C:\ncs\v2.4.0\zephyr\soc\arm\nordic_nrf\nrf52\soc.h:14,
from C:\ncs\v2.4.0\zephyr\include\zephyr\arch\arm\aarch32\cortex_m\cmsis.h:19,
from C:\ncs\v2.4.0\zephyr\include\zephyr\arch\arm\aarch32\mpu\arm_mpu_v7m.h:11,
from C:\ncs\v2.4.0\zephyr\include\zephyr\arch\arm\aarch32\mpu\arm_mpu.h:14,
from C:\ncs\v2.4.0\zephyr\include\zephyr\arch\arm\aarch32\arch.h:266,
from C:\ncs\v2.4.0\zephyr\include\zephyr\arch\cpu.h:19,
from C:\ncs\v2.4.0\zephyr\include\zephyr\kernel_includes.h:33,
from C:\ncs\v2.4.0\zephyr\include\zephyr\kernel.h:17,
from e:\testhere\spitest\src\main.c:7:
C:\ncs\v2.4.0\modules\hal\nordic\nrfx\drivers\include\nrfx_spim.h:84:35: error: 'NRFX_SPIM1_INST_IDX' undeclared here (not in a function); did you mean 'NRF_SPIM_INST_GET'?
84 | .drv_inst_idx = NRFX_CONCAT_3(NRFX_SPIM, id, _INST_IDX), \
| ^~~~~~~~~
C:\ncs\v2.4.0\modules\hal\nordic\nrfx\drivers\nrfx_common.h:140:37: note: in definition of macro 'NRFX_CONCAT_3_'
140 | #define NRFX_CONCAT_3_(p1, p2, p3) p1 ## p2 ## p3
| ^~
C:\ncs\v2.4.0\modules\hal\nordic\nrfx\drivers\include\nrfx_spim.h:84:21: note: in expansion of macro 'NRFX_CONCAT_3'
84 | .drv_inst_idx = NRFX_CONCAT_3(NRFX_SPIM, id, _INST_IDX), \
| ^~~~~~~~~~~~~
e:\testhere\spitest\src\main.c:68:24: note: in expansion of macro 'NRFX_SPIM_INSTANCE'
68 | nrfx_spim_t spi_inst = NRFX_SPIM_INSTANCE(SPIM_INST_IDX);
| ^~~~~~~~~~~~~~~~~~
In file included from e:\testhere\spitest\src\main.c:11:
../src/main.c: In function 'spi_init':
C:\ncs\v2.4.0\modules\hal\nordic\nrfx\hal\nrf_spim.h:71:37: warning: conversion from 'unsigned int' to 'unsigned char' changes value from '4294967295' to '255' [-Woverflow]
71 | #define NRF_SPIM_PIN_NOT_CONNECTED 0xFFFFFFFF
| ^~~~~~~~~~
C:\ncs\v2.4.0\modules\hal\nordic\nrfx\drivers\include\nrfx_spim.h:194:23: note: in definition of macro 'NRFX_SPIM_DEFAULT_CONFIG'
194 | .ss_pin = _pin_ss, \
| ^~~~~~~
e:\testhere\spitest\src\main.c:73:21: note: in expansion of macro 'NRF_SPIM_PIN_NOT_CONNECTED'
73 | 13, 14, 12, NRF_SPIM_PIN_NOT_CONNECTED);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
../src/main.c: In function 'ads1291_command':
e:\testhere\spitest\src\main.c:104:5: warning: implicit declaration of function 'nrfx_spi_xfer'; did you mean 'nrfx_spim_xfer'? [-Wimplicit-function-declaration]
104 | nrfx_spi_xfer(spi, &spi_xfer_desc, 0);
| ^~~~~~~~~~~~~
| nrfx_spim_xfer
../src/main.c: In function 'main':
e:\testhere\spitest\src\main.c:191:13: warning: unused variable 'reg' [-Wunused-variable]
191 | uint8_t reg = 0;
| ^~~
e:\testhere\spitest\src\main.c:190:13: warning: unused variable 'whoami' [-Wunused-variable]
190 | uint8_t whoami = 0;
| ^~~~~~
../src/main.c: At top level:
e:\testhere\spitest\src\main.c:122:16: warning: 'ads1291_read_reg' defined but not used [-Wunused-function]
122 | static int32_t ads1291_read_reg(uint8_t reg, uint8_t *data, uint8_t len)
| ^~~~~~~~~~~~~~~~
e:\testhere\spitest\src\main.c:78:16: warning: 'ads1291_command' defined but not used [-Wunused-function]
78 | static int32_t ads1291_command(uint8_t cmd, uint8_t *data, uint8_t len)
| ^~~~~~~~~~~~~~~
e:\testhere\spitest\src\main.c:70:13: warning: 'spi_init' defined but not used [-Wunused-function]
70 | static void spi_init(void)
| ^~~~~~~~
e:\testhere\spitest\src\main.c:61:29: warning: 'spi0_dev' defined but not used [-Wunused-variable]
61 | static const struct device *spi0_dev = DEVICE_DT_GET(SPI0_NODE);
| ^~~~~~~~
[61/156] Building C object zephyr/CMakeFiles/zephyr.dir/lib/os/multi_heap.c.obj
[62/156] Linking C static library zephyr\soc\arm\common\cortex_m\libsoc__arm__common__cortex_m.a
[63/156] Linking C static library zephyr\lib\libc\minimal\liblib__libc__minimal.a
[64/156] Building C object zephyr/CMakeFiles/zephyr.dir/lib/os/bitarray.c.obj
[65/156] Linking C static library zephyr\soc\arm\nordic_nrf\nrf52\libsoc__arm__nordic_nrf__nrf52.a
[66/156] Building C object zephyr/CMakeFiles/zephyr.dir/lib/os/heap.c.obj
[67/156] Building C object zephyr/CMakeFiles/zephyr.dir/lib/os/notify.c.obj
[68/156] Building C object zephyr/CMakeFiles/zephyr.dir/lib/os/cbprintf_complete.c.obj
[69/156] Building C object zephyr/CMakeFiles/zephyr.dir/lib/os/onoff.c.obj
ninja: build stopped: subcommand failed.
FATAL ERROR: command exited with status 1: 'C:\ncs\toolchains\31f4403e35\opt\bin\cmake.EXE' --build 'e:\testhere\spitest\build'
Hi,
There is something strange with your build/project that does not pick up the overlay properly. Try deleting all your build folders and regenerate the project.
Here's a minimal sample that enables NRFX_SPIM1 on nrf52dk_nrf52832:
3731.hello_world_nrfx_spim1.zip
Kind regards,
Håkon