I'm trying to add addtional pins as PWM signals in my application. I've followed the process shown here, but I'm getting a bunch of build errors.
This is my overlay file:
&pinctrl {
pwm0_custom: pwm0_custom {
group1 {
psels = <NRF_PSEL(PWM_OUT0, 0, 22)>,
<NRF_PSEL(PWM_OUT1, 0, 23)>;
nordic,invert;
};
};
pwm0_csleep: pwm0_csleep {
group1 {
psels = <NRF_PSEL(PWM_OUT0, 0, 22)>,
<NRF_PSEL(PWM_OUT1, 0, 23)>;
low-power-enable;
};
};
};
&pwm0 {
status = "okay";
pinctrl-0 = <&pwm0_custom>;
pinctrl-1 = <&pwm0_csleep>;
pinctrl-names = "default", "sleep";
};
/{
pwmleds {
compatible = "pwm-leds";
pwm_led0: pwm_led_0 {
pwms = <&pwm0 0 PWM_MSEC(1) PWM_POLARITY_NORMAL>;
};
pwm_led1: pwm_led_1 {
pwms = <&pwm0 1 PWM_USEC(100) PWM_POLARITY_NORMAL>;
};
};
};
With just that, I can get my code to build without errors.
But the moment I try and get the device for the second PWM pin (pwm_led1) via:
static const struct pwm_dt_spec pwm_out_0 = PWM_DT_SPEC_GET(DT_ALIAS(pwm_led0)); static const struct pwm_dt_spec pwm_out_1 = PWM_DT_SPEC_GET(DT_ALIAS(pwm_led1));
I get all these errors:
FAILED: CMakeFiles/app.dir/src/main.c.obj
C:\Nordic\toolchains\v2.2.0\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:/Nordic/v2.2.0/zephyr/include -Izephyr/include/generated -IC:/Nordic/v2.2.0/zephyr/soc/arm/nordic_nrf/nrf52 -IC:/Nordic/v2.2.0/zephyr/soc/arm/nordic_nrf/common/. -IC:/Nordic/v2.2.0/nrf/include -IC:/Nordic/v2.2.0/nrf/tests/include -IC:/Nordic/v2.2.0/pcf85063a/include -IC:/Nordic/v2.2.0/modules/hal/cmsis/CMSIS/Core/Include -IC:/Nordic/v2.2.0/modules/hal/nordic/nrfx -IC:/Nordic/v2.2.0/modules/hal/nordic/nrfx/drivers/include -IC:/Nordic/v2.2.0/modules/hal/nordic/nrfx/mdk -IC:/Nordic/v2.2.0/zephyr/modules/hal_nordic/nrfx/. -IC:/Nordic/v2.2.0/modules/debug/segger/SEGGER -IC:/Nordic/v2.2.0/modules/debug/segger/Config -IC:/Nordic/v2.2.0/zephyr/modules/segger/. -isystem C:/Nordic/v2.2.0/zephyr/lib/libc/minimal/include -isystem c:/nordic/toolchains/v2.2.0/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.1.0/include -isystem c:/nordic/toolchains/v2.2.0/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.1.0/include-fixed -fno-strict-aliasing -Os -imacros C:/Nordic/Development/blinky_pwm/build/zephyr/include/generated/autoconf.h -ffreestanding -fno-common -g -gdwarf-4 -fdiagnostics-color=always -mcpu=cortex-m4 -mthumb -mabi=aapcs -mfp16-format=ieee --sysroot=C:/Nordic/toolchains/v2.2.0/opt/zephyr-sdk/arm-zephyr-eabi/arm-zephyr-eabi -imacros C:/Nordic/v2.2.0/zephyr/include/zephyr/toolchain/zephyr_stdint.h -Wall -Wformat -Wformat-security -Wno-format-zero-length -Wno-main -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=C:/Nordic/Development/blinky_pwm=CMAKE_SOURCE_DIR -fmacro-prefix-map=C:/Nordic/v2.2.0/zephyr=ZEPHYR_BASE -fmacro-prefix-map=C:/Nordic/v2.2.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:\Nordic\v2.2.0\zephyr\include\zephyr\toolchain\gcc.h:88,
from C:\Nordic\v2.2.0\zephyr\include\zephyr\toolchain.h:50,
from C:\Nordic\v2.2.0\zephyr\include\zephyr\kernel_includes.h:19,
from C:\Nordic\v2.2.0\zephyr\include\zephyr\kernel.h:17,
from c:\Nordic\Development\blinky_pwm\src\main.c:12:
C:\Nordic\v2.2.0\zephyr\include\zephyr\device.h:83:41: error: '__device_dts_ord_DT_N_ALIAS_pwm_led1_P_pwms_IDX_0_PH_ORD' undeclared here (not in a function)
83 | #define DEVICE_NAME_GET(dev_id) _CONCAT(__device_, dev_id)
| ^~~~~~~~~
C:\Nordic\v2.2.0\zephyr\include\zephyr\toolchain\common.h:132:26: note: in definition of macro '_DO_CONCAT'
132 | #define _DO_CONCAT(x, y) x ## y
| ^
C:\Nordic\v2.2.0\zephyr\include\zephyr\device.h:83:33: note: in expansion of macro '_CONCAT'
83 | #define DEVICE_NAME_GET(dev_id) _CONCAT(__device_, dev_id)
| ^~~~~~~
C:\Nordic\v2.2.0\zephyr\include\zephyr\device.h:209:37: note: in expansion of macro 'DEVICE_NAME_GET'
209 | #define DEVICE_DT_NAME_GET(node_id) DEVICE_NAME_GET(Z_DEVICE_DT_DEV_ID(node_id))
| ^~~~~~~~~~~~~~~
C:\Nordic\v2.2.0\zephyr\include\zephyr\device.h:226:34: note: in expansion of macro 'DEVICE_DT_NAME_GET'
226 | #define DEVICE_DT_GET(node_id) (&DEVICE_DT_NAME_GET(node_id))
| ^~~~~~~~~~~~~~~~~~
C:\Nordic\v2.2.0\zephyr\include\zephyr\drivers\pwm.h:258:24: note: in expansion of macro 'DEVICE_DT_GET'
258 | .dev = DEVICE_DT_GET(DT_PWMS_CTLR_BY_IDX(node_id, idx)), \
| ^~~~~~~~~~~~~
C:\Nordic\v2.2.0\zephyr\include\zephyr\drivers\pwm.h:326:34: note: in expansion of macro 'PWM_DT_SPEC_GET_BY_IDX'
326 | #define PWM_DT_SPEC_GET(node_id) PWM_DT_SPEC_GET_BY_IDX(node_id, 0)
| ^~~~~~~~~~~~~~~~~~~~~~
c:\Nordic\Development\blinky_pwm\src\main.c:50:45: note: in expansion of macro 'PWM_DT_SPEC_GET'
50 | static const struct pwm_dt_spec pwm_out_1 = PWM_DT_SPEC_GET(DT_ALIAS(pwm_led1));
| ^~~~~~~~~~~~~~~
In file included from C:\Nordic\v2.2.0\zephyr\include\zephyr\arch\arm\aarch32\arch.h:20,
from C:\Nordic\v2.2.0\zephyr\include\zephyr\arch\cpu.h:19,
from C:\Nordic\v2.2.0\zephyr\include\zephyr\kernel_includes.h:33:
C:\Nordic\v2.2.0\zephyr\include\zephyr\devicetree.h:230:32: error: 'DT_N_ALIAS_pwm_led1_P_pwms_IDX_0_VAL_channel' undeclared here (not in a function); did you mean 'DT_N_S_pwmleds_S_pwm_led_1_P_pwms_IDX_0_VAL_channel'?
230 | #define DT_ALIAS(alias) DT_CAT(DT_N_ALIAS_, alias)
| ^~~~~~~~~~~
C:\Nordic\v2.2.0\zephyr\include\zephyr\devicetree.h:3901:9: note: in definition of macro 'DT_CAT7'
3901 | a1 ## a2 ## a3 ## a4 ## a5 ## a6 ## a7
| ^~
C:\Nordic\v2.2.0\zephyr\include\zephyr\devicetree\pwms.h:136:9: note: in expansion of macro 'DT_PHA_BY_IDX'
136 | DT_PHA_BY_IDX(node_id, pwms, idx, cell)
| ^~~~~~~~~~~~~
C:\Nordic\v2.2.0\zephyr\include\zephyr\devicetree\pwms.h:208:9: note: in expansion of macro 'DT_PWMS_CELL_BY_IDX'
208 | DT_PWMS_CELL_BY_IDX(node_id, idx, channel)
| ^~~~~~~~~~~~~~~~~~~
C:\Nordic\v2.2.0\zephyr\include\zephyr\drivers\pwm.h:259:28: note: in expansion of macro 'DT_PWMS_CHANNEL_BY_IDX'
259 | .channel = DT_PWMS_CHANNEL_BY_IDX(node_id, idx), \
| ^~~~~~~~~~~~~~~~~~~~~~
C:\Nordic\v2.2.0\zephyr\include\zephyr\drivers\pwm.h:326:34: note: in expansion of macro 'PWM_DT_SPEC_GET_BY_IDX'
326 | #define PWM_DT_SPEC_GET(node_id) PWM_DT_SPEC_GET_BY_IDX(node_id, 0)
| ^~~~~~~~~~~~~~~~~~~~~~
c:\Nordic\Development\blinky_pwm\src\main.c:50:45: note: in expansion of macro 'PWM_DT_SPEC_GET'
50 | static const struct pwm_dt_spec pwm_out_1 = PWM_DT_SPEC_GET(DT_ALIAS(pwm_led1));
| ^~~~~~~~~~~~~~~
C:\Nordic\v2.2.0\zephyr\include\zephyr\devicetree.h:230:25: note: in expansion of macro 'DT_CAT'
230 | #define DT_ALIAS(alias) DT_CAT(DT_N_ALIAS_, alias)
| ^~~~~~
c:\Nordic\Development\blinky_pwm\src\main.c:50:61: note: in expansion of macro 'DT_ALIAS'
50 | static const struct pwm_dt_spec pwm_out_1 = PWM_DT_SPEC_GET(DT_ALIAS(pwm_led1));
| ^~~~~~~~
C:\Nordic\v2.2.0\zephyr\include\zephyr\devicetree.h:230:32: error: 'DT_N_ALIAS_pwm_led1_P_pwms_IDX_0_VAL_period' undeclared here (not in a function); did you mean 'DT_N_S_pwmleds_S_pwm_led_1_P_pwms_IDX_0_VAL_period'?
230 | #define DT_ALIAS(alias) DT_CAT(DT_N_ALIAS_, alias)
| ^~~~~~~~~~~
C:\Nordic\v2.2.0\zephyr\include\zephyr\devicetree.h:3901:9: note: in definition of macro 'DT_CAT7'
3901 | a1 ## a2 ## a3 ## a4 ## a5 ## a6 ## a7
| ^~
C:\Nordic\v2.2.0\zephyr\include\zephyr\devicetree\pwms.h:136:9: note: in expansion of macro 'DT_PHA_BY_IDX'
136 | DT_PHA_BY_IDX(node_id, pwms, idx, cell)
| ^~~~~~~~~~~~~
C:\Nordic\v2.2.0\zephyr\include\zephyr\devicetree\pwms.h:249:9: note: in expansion of macro 'DT_PWMS_CELL_BY_IDX'
249 | DT_PWMS_CELL_BY_IDX(node_id, idx, period)
| ^~~~~~~~~~~~~~~~~~~
C:\Nordic\v2.2.0\zephyr\include\zephyr\drivers\pwm.h:260:27: note: in expansion of macro 'DT_PWMS_PERIOD_BY_IDX'
260 | .period = DT_PWMS_PERIOD_BY_IDX(node_id, idx), \
| ^~~~~~~~~~~~~~~~~~~~~
C:\Nordic\v2.2.0\zephyr\include\zephyr\drivers\pwm.h:326:34: note: in expansion of macro 'PWM_DT_SPEC_GET_BY_IDX'
326 | #define PWM_DT_SPEC_GET(node_id) PWM_DT_SPEC_GET_BY_IDX(node_id, 0)
| ^~~~~~~~~~~~~~~~~~~~~~
c:\Nordic\Development\blinky_pwm\src\main.c:50:45: note: in expansion of macro 'PWM_DT_SPEC_GET'
50 | static const struct pwm_dt_spec pwm_out_1 = PWM_DT_SPEC_GET(DT_ALIAS(pwm_led1));
| ^~~~~~~~~~~~~~~
C:\Nordic\v2.2.0\zephyr\include\zephyr\devicetree.h:230:25: note: in expansion of macro 'DT_CAT'
230 | #define DT_ALIAS(alias) DT_CAT(DT_N_ALIAS_, alias)
| ^~~~~~
c:\Nordic\Development\blinky_pwm\src\main.c:50:61: note: in expansion of macro 'DT_ALIAS'
50 | static const struct pwm_dt_spec pwm_out_1 = PWM_DT_SPEC_GET(DT_ALIAS(pwm_led1));
| ^~~~~~~~
Note that with just the pwm_out_0 struct, everything works. Just adding the struct for pwm_out_1 seems to give the above errors
Can anyone spot what I'm doing wrong??
Cheers,
Mike