PWM in nrf5340 - blinky example fails to compile with SDK 2.7.0

Greetings,

trying to get PWM working with nrf5340. Unfortunately I am not able to even get the blinky PWM example compiled with the setup using SDK 2.7.0. The compile is ok nrf51822, so the environment should be in order.

The compilation log claims (for bl5340_dvk tried some other boards as well with no success):

In file included from C:/Apps/NordicSemiconductor/SDKs/v2.7.0/zephyr/include/zephyr/toolchain/gcc.h:98,
                 from C:/Apps/NordicSemiconductor/SDKs/v2.7.0/zephyr/include/zephyr/toolchain.h:50,
                 from C:/Apps/NordicSemiconductor/SDKs/v2.7.0/zephyr/include/zephyr/kernel_includes.h:23,
                 from C:/Apps/NordicSemiconductor/SDKs/v2.7.0/zephyr/include/zephyr/kernel.h:17,
                 from C:/Users/mattip-local/Projects/Nordic/Sandbox/blinky_pwm_ref/src/main.c:12:
C:/Apps/NordicSemiconductor/SDKs/v2.7.0/zephyr/include/zephyr/device.h:91:41: error: '__device_dts_ord_DT_N_ALIAS_pwm_led0_P_pwms_IDX_0_PH_ORD' undeclared here (not in a function)
   91 | #define DEVICE_NAME_GET(dev_id) _CONCAT(__device_, dev_id)
      |                                         ^~~~~~~~~
C:/Apps/NordicSemiconductor/SDKs/v2.7.0/zephyr/include/zephyr/toolchain/common.h:137:26: note: in definition of macro '_DO_CONCAT'
  137 | #define _DO_CONCAT(x, y) x ## y
      |                          ^
C:/Apps/NordicSemiconductor/SDKs/v2.7.0/zephyr/include/zephyr/device.h:91:33: note: in expansion of macro '_CONCAT'
   91 | #define DEVICE_NAME_GET(dev_id) _CONCAT(__device_, dev_id)
      |                                 ^~~~~~~
C:/Apps/NordicSemiconductor/SDKs/v2.7.0/zephyr/include/zephyr/device.h:228:37: note: in expansion of macro 'DEVICE_NAME_GET'
  228 | #define DEVICE_DT_NAME_GET(node_id) DEVICE_NAME_GET(Z_DEVICE_DT_DEV_ID(node_id))
      |                                     ^~~~~~~~~~~~~~~
C:/Apps/NordicSemiconductor/SDKs/v2.7.0/zephyr/include/zephyr/device.h:245:34: note: in expansion of macro 'DEVICE_DT_NAME_GET'
  245 | #define DEVICE_DT_GET(node_id) (&DEVICE_DT_NAME_GET(node_id))
      |                                  ^~~~~~~~~~~~~~~~~~
C:/Apps/NordicSemiconductor/SDKs/v2.7.0/zephyr/include/zephyr/drivers/pwm.h:260:24: note: in expansion of macro 'DEVICE_DT_GET'
  260 |                 .dev = DEVICE_DT_GET(DT_PWMS_CTLR_BY_IDX(node_id, idx)),       \
      |                        ^~~~~~~~~~~~~
C:/Apps/NordicSemiconductor/SDKs/v2.7.0/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)
      |                                  ^~~~~~~~~~~~~~~~~~~~~~
C:/Users/mattip-local/Projects/Nordic/Sandbox/blinky_pwm_ref/src/main.c:17:44: note: in expansion of macro 'PWM_DT_SPEC_GET'
   17 | static const struct pwm_dt_spec pwm_led0 = PWM_DT_SPEC_GET(DT_ALIAS(pwm_led0));
      |                                            ^~~~~~~~~~~~~~~
In file included from C:/Apps/NordicSemiconductor/SDKs/v2.7.0/zephyr/include/zephyr/arch/arm/arch.h:20,
                 from C:/Apps/NordicSemiconductor/SDKs/v2.7.0/zephyr/include/zephyr/arch/cpu.h:19,
                 from C:/Apps/NordicSemiconductor/SDKs/v2.7.0/zephyr/include/zephyr/kernel_includes.h:36:
C:/Apps/NordicSemiconductor/SDKs/v2.7.0/zephyr/include/zephyr/devicetree.h:240:32: error: 'DT_N_ALIAS_pwm_led0_P_pwms_IDX_0_VAL_channel' undeclared here (not in a function)

What is wrong here?

Parents Reply Children
  • Greetings,

    thank you for the quick response!

    Ok - now the sample compiles Thumbsup

    However when trying to build with custom configuration I get:

    In file included from C:/Apps/NordicSemiconductor/SDKs/v2.7.0/zephyr/include/zephyr/toolchain/gcc.h:98,
                     from C:/Apps/NordicSemiconductor/SDKs/v2.7.0/zephyr/include/zephyr/toolchain.h:50,
                     from C:/Apps/NordicSemiconductor/SDKs/v2.7.0/zephyr/include/zephyr/kernel_includes.h:23,
                     from C:/Apps/NordicSemiconductor/SDKs/v2.7.0/zephyr/include/zephyr/kernel.h:17,
                     from C:/Users/mattip-local/Projects/Nordic/Sandbox/hello_world_sample/src/main.c:7:
    C:/Users/mattip-local/Projects/Nordic/Sandbox/hello_world_sample/src/main.c: In function 'main':
    C:/Apps/NordicSemiconductor/SDKs/v2.7.0/zephyr/include/zephyr/device.h:91:41: error: '__device_dts_ord_DT_N_ALIAS_pwm_led0_P_pwms_IDX_0_PH_ORD' undeclared (first use in this function)
       91 | #define DEVICE_NAME_GET(dev_id) _CONCAT(__device_, dev_id)

    The custom board .dts file has:

    /dts-v1/;
    #include <nordic/nrf5340_cpuapp_qkaa.dtsi>
    #include "GGHHx_Dev0_0-pinctrl.dtsi"

    / {
        model = "Custom Board auto generated by nRF Connect for VS Code (CPUAPP)";
        compatible = "None,custom-board-name-cpuapp";

        chosen {
            zephyr,console = &uart0;
            zephyr,shell-uart = &uart0;
            zephyr,uart-mcumgr = &uart0;
            zephyr,bt-mon-uart = &uart0;
            zephyr,bt-c2h-uart = &uart0;
            zephyr,sram = &sram0_image;
            zephyr,flash = &flash0;
            zephyr,code-partition = &slot0_partition;
            zephyr,sram-secure-partition = &sram0_s;
            zephyr,sram-non-secure-partition = &sram0_ns;
        };


        leds {
            compatible = "gpio-leds";
            led0: led_0 {
                gpios = <&gpio0 6 GPIO_ACTIVE_LOW>;
                label = "Green LED 0";
            };
        };

        pwmleds {
            compatible = "pwm-leds";
            pwm_led0: pwm_led_0 {
                pwms = <&sw_pwm 0 PWM_MSEC(20) PWM_POLARITY_INVERTED>;
            };
        };

    };



    &gpiote {
        status = "okay";
    };

    &gpio0 {
        status = "okay";
    };

    &gpio1 {
        status = "okay";
    };


    &pwm0 {
        status = "disabled";
    };

    &sw_pwm {
        status = "okay";
        channel-gpios = <&gpio0 6 PWM_POLARITY_INVERTED>;
    };

    What am I missing here?


  • When comparing with the sample there seems to be an alias definition missing in the devicetree_generated.h header:

    Sample has:

    /* Existence and alternate IDs: */
    #define DT_N_S_pwmleds_S_pwm_led_0_EXISTS 1
    #define DT_N_ALIAS_pwm_led0     DT_N_S_pwmleds_S_pwm_led_0
    #define DT_N_NODELABEL_pwm_led0 DT_N_S_pwmleds_S_pwm_led_0

    Whereas my the header generated from my code has:

    /* Existence and alternate IDs: */
    #define DT_N_S_pwmleds_S_pwm_led_0_EXISTS 1
    #define DT_N_NODELABEL_pwm_led0 DT_N_S_pwmleds_S_pwm_led_0

    Now just need to figure out how this alias is supposed to be generated...

  • And of course that is in the alias definition:

    pwm-led0 = &pwm_led0;

    There must be a good reason why the build system converts the dash "-" to an underscore "_" during the build process. I really do hope there is a good reason for this.

Related