Topics

nrf52 hw pwm 1 enabled and compile failed on sample code #builds #ninja


hotkernel@...
 

Hello guys,
I have got a compile error after enable the PWM channel 1 on nrf52_pca10040 board with sample code.
If I only use PWM0, there is no problem to pass the compile, but if I enable the PWM1, the issue happened.
I have searched all the source code, and did not find any difference between PWM0 and PWM1.
board: nrf52_pca10040
sample code: samples/bluetooth/peripheral_hr
ninja guiconfig:
 

the error info shows as below:
jeremy@jeremy:~/zephyr/source2/samples/bluetooth/peripheral_hr/build$ ninja
[0/1] Re-running CMake...
Zephyr version: 1.14.99
-- Selected BOARD nrf52_pca10040
-- Found west: /home/jeremy/.local/bin/west (found suitable version "0.5.7", minimum required is "0.5.6")
-- Loading /home/jeremy/zephyr/source2/boards/arm/nrf52_pca10040/nrf52_pca10040.dts as base
-- Overlaying /home/jeremy/zephyr/source2/dts/common/common.dts
Parsing Kconfig tree in /home/jeremy/zephyr/source2/Kconfig
Loaded configuration '/home/jeremy/zephyr/source2/samples/bluetooth/peripheral_hr/build/zephyr/.config'
No change to '/home/jeremy/zephyr/source2/samples/bluetooth/peripheral_hr/build/zephyr/.config'
-- Cache files will be written to: /home/jeremy/.cache/zephyr
-- Configuring done
-- Generating done
-- Build files have been written to: /home/jeremy/zephyr/source2/samples/bluetooth/peripheral_hr/build
[150/162] Building C object zephyr/drivers/pwm/CMakeFiles/drivers__pwm.dir/pwm_nrfx.c.obj
FAILED: zephyr/drivers/pwm/CMakeFiles/drivers__pwm.dir/pwm_nrfx.c.obj
ccache /home/jeremy/zephyr/sdk/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc -DBUILD_VERSION=zephyr-v1.14.0-1479-gd3977996088a -DKERNEL -DNRF52832_XXAA -D_FORTIFY_SOURCE=2 -D__ZEPHYR_SUPERVISOR__ -D__ZEPHYR__=1 -I../../../../kernel/include -I../../../../arch/arm/include -I../../../../include -I../../../../include/drivers -Izephyr/include/generated -I../../../../soc/arm/nordic_nrf/nrf52 -I../../../../soc/arm/nordic_nrf/include -I../../../../lib/libc/minimal/include -I../../../../ext/lib/crypto/tinycrypt/include -I../../../../ext/hal/cmsis/Include -I../../../../ext/hal/nordic/nrfx -I../../../../ext/hal/nordic/nrfx/drivers/include -I../../../../ext/hal/nordic/nrfx/hal -I../../../../ext/hal/nordic/nrfx/mdk -I../../../../ext/hal/nordic/. -I../../../../subsys/bluetooth -isystem /home/jeremy/zephyr/sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/8.3.0/include -isystem /home/jeremy/zephyr/sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/8.3.0/include-fixed -Os -nostdinc -imacros /home/jeremy/zephyr/source2/samples/bluetooth/peripheral_hr/build/zephyr/include/generated/autoconf.h -ffreestanding -fno-common -g -mthumb -mcpu=cortex-m4 -Wall -Wformat -Wformat-security -Wno-format-zero-length -Wno-main -Wno-pointer-sign -Wpointer-arith -Wno-unused-but-set-variable -Werror=implicit-int -fno-asynchronous-unwind-tables -fno-pie -fno-pic -fno-strict-overflow -fno-reorder-functions -fno-defer-pop -fmacro-prefix-map=/home/jeremy/zephyr/source2=. -ffunction-sections -fdata-sections -mabi=aapcs -march=armv7e-m -std=c99 -MD -MT zephyr/drivers/pwm/CMakeFiles/drivers__pwm.dir/pwm_nrfx.c.obj -MF zephyr/drivers/pwm/CMakeFiles/drivers__pwm.dir/pwm_nrfx.c.obj.d -o zephyr/drivers/pwm/CMakeFiles/drivers__pwm.dir/pwm_nrfx.c.obj   -c /home/jeremy/zephyr/source2/drivers/pwm/pwm_nrfx.c
In file included from ../../../../include/pwm.h:32,
                 from /home/jeremy/zephyr/source2/drivers/pwm/pwm_nrfx.c:7:
/home/jeremy/zephyr/source2/drivers/pwm/pwm_nrfx.c:384:9: error: 'DT_NORDIC_NRF_PWM_PWM_1_LABEL' undeclared here (not in a function); did you mean 'DT_NORDIC_NRF_PWM_PWM_0_LABEL'?
         DT_NORDIC_NRF_PWM_PWM_##idx##_LABEL,        \
         ^~~~~~~~~~~~~~~~~~~~~~
../../../../include/device.h:107:11: note: in definition of macro 'DEVICE_AND_API_INIT'
   .name = drv_name, .init = (init_fn),     \
           ^~~~~~~~
/home/jeremy/zephyr/source2/drivers/pwm/pwm_nrfx.c:383:2: note: in expansion of macro 'DEVICE_DEFINE'
  DEVICE_DEFINE(pwm_nrfx_##idx,           \
  ^~~~~~~~~~~~~
/home/jeremy/zephyr/source2/drivers/pwm/pwm_nrfx.c:444:1: note: in expansion of macro 'PWM_NRFX_DEVICE'
 PWM_NRFX_DEVICE(1);
 ^~~~~~~~~~~~~~~
[154/162] Building C object zephyr/kernel/CMakeFiles/kernel.dir/poll.c.obj
ninja: build stopped: subcommand failed.
 
Thanks in advance!
Jeremy


lairdjm
 

Hi Jeremy

The reason is that hardware is static and defined as part of the device tree, so for the nRF52840 this will be in the boards\arm\nrf52840_pca10056 directory and is nrf52840_pca10056.dts, if you open this file in a text editor and search for PWM you will find this code:

&pwm0 {

                status = "ok";

                ch0-pin = <13>;

                ch0-inverted;

};

There is no pwm1 section, so to utilise a second PWM channel you would need to create another section for it named &pwm1.

Thanks,
Jamie