Hi,
I'm trying to get the PWM to work to operate a vibrator connected to the nRF54L15 PDK. I'm basing my activity on lesson4 - pwm as I'm also new to Zephyr (but experienced with nrf52).
The configuration part succeeds, but then the compilation fails with the following error:
main.c:26:64: error: 'vibrator_P_pwms_IDX_0_VAL_channel' undeclared here (not in a function) 26 | static const struct pwm_dt_spec pwm_vibrator = PWM_DT_SPEC_GET(vibrator); /home/me/ncs/zephyr/include/zephyr/devicetree.h:4888:9: note: in definition of macro 'DT_CAT7' 4888 | a1 ## a2 ## a3 ## a4 ## a5 ## a6 ## a7 | ^~ /home/me/ncs/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) | ^~~~~~~~~~~~~ /home/me/ncs/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) | ^~~~~~~~~~~~~~~~~~~ /home/me/ncs/zephyr/include/zephyr/drivers/pwm.h:261:28: note: in expansion of macro 'DT_PWMS_CHANNEL_BY_IDX' 261 | .channel = DT_PWMS_CHANNEL_BY_IDX(node_id, idx), \ | ^~~~~~~~~~~~~~~~~~~~~~ /home/me/ncs/zephyr/include/zephyr/drivers/pwm.h:328:34: note: in expansion of macro 'PWM_DT_SPEC_GET_BY_IDX' 328 | #define PWM_DT_SPEC_GET(node_id) PWM_DT_SPEC_GET_BY_IDX(node_id, 0) | ^~~~~~~~~~~~~~~~~~~~~~ /home/me/srcs/main.c:26:48: note: in expansion of macro 'PWM_DT_SPEC_GET' 26 | static const struct pwm_dt_spec pwm_vibrator = PWM_DT_SPEC_GET(vibrator); | ^~~~~~~~~~~~~~~ /home/me/srcs/main.c:26:64: error: 'vibrator_P_pwms_IDX_0_VAL_period' undeclared here (not in a function) 26 | static const struct pwm_dt_spec pwm_vibrator = PWM_DT_SPEC_GET(vibrator); | ^~~~~~~~ /home/me/ncs/zephyr/include/zephyr/devicetree.h:4888:9: note: in definition of macro 'DT_CAT7' 4888 | a1 ## a2 ## a3 ## a4 ## a5 ## a6 ## a7 | ^~ /home/me/ncs/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) | ^~~~~~~~~~~~~ /home/me/ncs/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) | ^~~~~~~~~~~~~~~~~~~ /home/me/ncs/zephyr/include/zephyr/drivers/pwm.h:262:27: note: in expansion of macro 'DT_PWMS_PERIOD_BY_IDX' 262 | .period = DT_PWMS_PERIOD_BY_IDX(node_id, idx), \ | ^~~~~~~~~~~~~~~~~~~~~ /home/me/ncs/zephyr/include/zephyr/drivers/pwm.h:328:34: note: in expansion of macro 'PWM_DT_SPEC_GET_BY_IDX' 328 | #define PWM_DT_SPEC_GET(node_id) PWM_DT_SPEC_GET_BY_IDX(node_id, 0) | ^~~~~~~~~~~~~~~~~~~~~~ /home/me/srcs/main.c:26:48: note: in expansion of macro 'PWM_DT_SPEC_GET' 26 | static const struct pwm_dt_spec pwm_vibrator = PWM_DT_SPEC_GET(vibrator);
This is my overlay:
/ { vibrator: vibrator { compatible = "pwm-servo"; pwms = <&pwm20 0 PWM_USEC(5) PWM_POLARITY_NORMAL>; min-pulse = <PWM_USEC(1)>; max-pulse = <PWM_USEC(5)>; status = "okay"; }; }; &pinctrl { pwm20_default_custom: pwm20_default_custom { group1 { psels = <NRF_PSEL(PWM_OUT0, 0, 13)>; nordic,invert; }; }; }; &pwm20 { status = "okay"; pinctrl-0 = <&pwm20_default_custom>; pinctrl-names = "default"; /delete-property/ pinctrl-1; };
This is my basic prj.conf:
CONFIG_PWM=y CONFIG_LED=y CONFIG_LED_PWM=y
And this is my basic main.c (I removed some unrelated parts so don't mind line numbers in the error messages):
#include <stdint.h> #include <zephyr/kernel.h> #include <zephyr/device.h> #include <zephyr/drivers/pwm.h> #define PWM_VIB DT_ALIAS(vibrator) #define PWM_PERIOD_NS 100000000 #define PWM_DUTY_CYCLE 1400000 static const struct pwm_dt_spec pwm_vibrator = PWM_DT_SPEC_GET(PWM_VIB); void main(void) { }
If I remove the line where I declare `pwm_vibrator` there's no more compilation error.
How can I make this work ?
All is built with `west build -b [email protected]/nrf54l15/cpuapp`
I'm using the toolchain 2.8.0 and nRF Connect SDK 2.8.0 on a Debian system.
Edit: I'd like to add that I tried to run the example's solution itself and ended up with the same issue.
I've cloned ncs-inter on commit 0b2e2e2, built in ncs-inter/v2.8.x-v2.7.0/l4/l4_e2_sol with 'west build -b [email protected]/nrf54l15/cpuapp' on SDK+toolchain 2.8.0 and obtained the same kind of error, i.e.:
/workdir/zephyr/include/zephyr/device.h:92:41: error: '__device_dts_ord_DT_N_NODELABEL_servo_P_pwms_IDX_0_PH_ORD' undeclared here (not in a function)
This was on my own variation of nrf-docker where I built the image for toolchain/SDK 2.8.0, so it's quite reproducible.