This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Getting Started with NCS (NRF Connect SDK) with simple PWMs.

Hi,

I trouble the support team for quite a few months now with NRF5 and I am now trying to get started with the up to date SDK and hopefully being able to get along with matter functionnalities.

I am using the SDK on VS Code and I find it a bit troubling how things works with Zephyr. I started on a standard blinky but I can't find any examples using Zephyr for a PWM or interrupt based events. So far my attempts at getting along the new SDK was applying changes in the zephyr.dts file : 

		pwm0: pwm@4001c000 {
			compatible = "nordic,nrf-pwm";
			reg = < 0x4001c000 0x1000 >;
			interrupts = < 0x1c 0x1 >;
			status = "okay";
			label = "PWM_0";
			#pwm-cells = < 0x1 >;
			ch0-pin = < 14 >;
			ch0-inverted;
			ch1-pin = < 15 >;
			ch1-inverted;
			ch2-pin = < 16 >;
			ch3-inverted;
			phandle = < 0x5 >;
		};
		
........................

	pwmleds {
		compatible = "pwm-leds";
		pwm_led0: pwm_led_0 {
			pwms = < &pwm0 14 >;
			label = "Voyant Rouge";
		};
		pwm_led1: pwm_led_1 {
			pwms = < &pwm0 15 >;
			label = "Voyant Vert";
		};
		pwm_led2: pwm_led_2 {
			pwms = < &pwm0 16 >;
			label = "Voyant Bleu";
		};
	};
I am then very concerned about the way to proceed, the blink exemple seems to use deprecated GPIO definitions (device_get_binding()) and I am not able to set up anything easily.
I hope you can make my way into this easier.
Best Regards,
Charles
Parents
  • Hi Charles,

    As a beginner to the nRF Connect SDK, I can understand your confusion as it is quite different from your previous environment. But once you get the hang of it, it gets very convenient. I would recommend you to take a look at all the parts of our Getting Started Guide. Even though 2 specific boards are mentioned here, the working is quite similar to all the DKs. 

    In order to begin with the VS Code extension, we have a tutorial series on Youtube.

    There is blinky and blinky_pwm sample in Zephyr as shown below:

    You can try implementing all this. But Kindly go through the guides and before you begin everything just make sure you have the nRF Connect SDK installed properly. First you should install the nRF Command Line Tools, and then you could try installing the nRF Connect for Desktop

    Also, in the Guide, there is a detailed explanation of creating overlay files and working with the various pins etc so as to not make any direct modifications to the devicetree.

    Regards,

    Priyanka

  • Hi again,

    I am getting the hang a how to deal with many things in the SDK but I still can't add functionnalities as I wish.

    I tried to add node using an overlay the same way I did previously but it seems it does not work.

    EDIT : 

    To be precise, I started from the PWM_blinky exemple.

    Then I added the files device_overlay.overlay and device_conf.conf (this one is empty for now).

    Overlay: 

    / {
        aliases {
            pwm_led0 = &pwm_led0;
            pwm_led1 = &pwm_led1;
            pwm_led2 = &pwm_led2;
        };
    
        &pwm0 {
            status = "okay";
            ch0-pin = <13>;
            ch0-inverted;
            ch1-pin = <14>;
            ch1-inverted;
            ch2-pin = <15>;
            ch2-inverted;
        };
    
        pwmleds {
            compatible = "pwm-leds";
            pwm_led0: pwm_led_0 {
                pwms = <&pwm0 13>;
                status = "okay";
            };
            pwm_led1: pwm_led_1 {
                pwms = <&pwm0 14>;
                status = "okay";
            };
            pwm_led2: pwm_led_2 {
                pwms = <&pwm0 15>;
                status = "okay";
            };
        };
    };

    I added the following lines in the CMaleLists.txt : 

    set(DTC_OVERLAY_FILE
      ${CMAKE_CURRENT_SOURCE_DIR}/device_overlay.overlay
    )
    set(CONF_FILE
      prj.conf
      ${CMAKE_CURRENT_LIST_DIR}/device_conf.conf
    )

    Then I modified the main.c by adding these lines: 

    #if DT_NODE_HAS_STATUS(PWM_LED1_NODE, okay)
    #define PWM1_CTLR	    DT_PWMS_CTLR(PWM_LED1_NODE)
    #define PWM1_CHANNEL	DT_PWMS_CHANNEL(PWM_LED1_NODE)
    #define PWM1_FLAGS   	DT_PWMS_FLAGS(PWM_LED1_NODE)
    #else
    #error "Unsupported board: pwm-led1 devicetree alias is not defined"
    #define PWM1_CTLR	    DT_INVALID_NODE
    #define PWM1_CHANNEL   	0
    #define PWM1_FLAGS    	0
    #endif
    
    #if DT_NODE_HAS_STATUS(PWM_LED2_NODE, okay)
    #define PWM2_CTLR	        DT_PWMS_CTLR(PWM_LED2_NODE)
    #define PWM2_CHANNEL	    DT_PWMS_CHANNEL(PWM_LED2_NODE)
    #define PWM2_FLAGS	        DT_PWMS_FLAGS(PWM_LED2_NODE)
    #else
    #error "Unsupported board: pwm-led2 devicetree alias is not defined"
    #define PWM2_CTLR	    DT_INVALID_NODE
    #define PWM2_CHANNEL  	0
    #define PWM2_FLAGS	    0
    #endif

    and modifying the first PWM accordingly.

    When I try to bulid the application I get the error message : 

    synthax error*

    FATAL ERROR: Unable to parse input tree

    Best Regards,

    Charles

  • Hi Charles,

    So first, you need to check whether you have named the overlay file's right. Which DK are you working with? In case you are using a nRF52840DK, you should name your overlay file "nrf52840dk_nrf52840.overlay". Exception is in the case of nrf5340, for which you name it as "nrf5340dk_nrf5340_cpuapp.overlay". Basically, you name it after the board. 

    Next, you don't have to modify the CMakeLists or prj.conf. The overlay files will be detected and used to modify the devicetree if you put the overlay file in the the project file. It should look something like this:

    You could also place your overlay files inside the "boards" folder (that would be more clean Slight smile)

    Now you can see in your main.c, the line #if DT_NODE_HAS_STATUS(PWM_LED1_NODE, okay). But the compiler has not seen PWM_LED1_NODE defined before, and the same applies for PWM_LED2_NODE . So, you could try defining those too in the main.c as follows:

    Also, try modifying the 'aliases' in your overlay as follows:

    {
        aliases {
            pwm-led0 = &pwm_led0;
            pwm-led1 = &pwm_led1;
            pwm-led2 = &pwm_led2;
        };

    Regards,

    Priyanka

  • Hi,

    I tried renaming the overlay. It seems the problem lies within the synthax of my overlay because I have the same issue.

    I did add the DT_ALIAS but I did not mention it ....

  • Could you attach the detailed error message that you get?

    -Priyanka

Reply Children
  • Error: c:\Users\user\Desktop\project\project_app\build\nrf52840dk_nrf52840.dts.pre.tmp:680.1-8 syntax error
    FATAL ERROR: Unable to parse input tree
    CMake Error at C:\Users\user\ncs\v1.8.0\zephyr\cmake\dts.cmake:225 (message):
    command failed with return code: 1
    Call Stack (most recent call first):
    C:\Users\user\ncs\v1.8.0\zephyr\cmake\app\boilerplate.cmake:545 (include)
    C:\Users\user\ncs\v1.8.0\zephyr\share\zephyr-package\cmake\ZephyrConfig.cmake:24 (include)
    C:\Users\user\ncs\v1.8.0\zephyr\share\zephyr-package\cmake\ZephyrConfig.cmake:35 (include_boilerplate)
    c:\Users\user\Desktop\project\project_app\build\CMakeLists.txt:4 (find_package)


    -- Configuring incomplete, errors occurred!
    FATAL ERROR: command exited with status 1: 'c:\Users\user\ncs\v1.8.0\toolchain\opt\bin\cmake.EXE' '-DWEST_PYTHON=c:\Users\user\ncs\v1.8.0\toolchain\opt\bin\python.exe' '-Bc:\Users\user\Desktop\project\project_app\build' '-Sc:\Users\user\Desktop\project\project_app' -GNinja -DBOARD=nrf52840dk_nrf52840 -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=On -DNCS_TOOLCHAIN_VERSION:STRING=NONE -DBOARD_ROOT:STRING=c:/Users\user/Desktop/project/project_app -DCONFIG_DEBUG_OPTIMIZATIONS:STRING=y -DCONFIG_DEBUG_THREAD_INFO:STRING=y -DDTC_OVERLAY_FILE:STRING=c:/Users/user/Desktop/project/project_app/nrf52840dk_nrf52840.overlay -DCONF_FILE:STRING=c:/Users/user/Desktop/project/project_app\/prj.conf

  • We can take a look around now:

    1. Have you made sure that you have taken CMakeLists and prj.conf back to how it was before you modified it?

    CMakeLists:

    prj.conf:

    2. When you generate the build configuration, do you enable the debug option?

    Also, could you tell me the path where you create the project folder?

    -Priyanka

  • Yes my files are the default files.

    I created a directory in my desktop named project c:\Users\user\Desktop\project. Then I opened the empty directory with vs code and created the application with the name project_app.

    I enabled the debug options.

  • Could you create the folder "projects" inside the c:\Users\user\ncs ?

    Then, when you open the VS Code via Toolchain manager, click on "Create a new application from sample" and enter the details similar to as follows (your Application location will be c:\Users\user\ncs\projects)

    And, later when generating the build configurations, do not enable the debug options.

    Regards,

    Priyanka

  • I managed to make things work. I finally found a synthax that work with the overlay : 

    / {
        pwmleds { 
    
            pwm_led1: pwm_led1 {
                pwms = <&pwm0 14>;
                status = "okay";
            };
            pwm_led2: pwm_led2 {
                pwms = <&pwm0 15>;
                status = "okay";
            };
        };
    
        aliases {
            pwm-led0 = &pwm_led0;
            pwm-led1 = &pwm_led1;
            pwm-led2 = &pwm_led2;
        };
    };
    
    &pwm0 {
        status = "okay";
        ch0-pin = <13>;
        ch0-inverted;
        ch1-pin = <14>;
        ch1-inverted;
        ch2-pin = <15>;
        ch2-inverted;
    };
    

Related