nRF Connect SDK Modifying basic examples

Hello All,

We are intending to start a new project using nRF52840 SOC, for the same i decided to work with nRF connect SDK as it is recommended by nordic,

I am new to Nordic as well as nRF Connect SDK, so i decided to study the nRF Connect SDK fundamentals course on Dev academy in order to have proper understanding, 

I am able to work as per excersizes given and was able run the demonstarted codes,

However For excersize 2 in order to have better understanding i tried importing blinky sample using option "Add new application from sample" and then modified the code for button interrupt,

But i am not able to understand why i am getting the following error, whereas there is nothing much in this excersize and the code is replicated as same,

[{
	"resource": "/c:/VSCode_nRF/myapps/ButtonPolling/build/zephyr/include/generated/devicetree_unfixed.h",
	"owner": "cpptools",
	"severity": 8,
	"message": "'DT_N_S_buttons_S_button_0' undeclared (first use in this function); did you mean 'DT_N_S_buttons_S_button_0_ORD'?",
	"source": "gcc",
	"startLineNumber": 1138,
	"startColumn": 32,
	"endLineNumber": 1138,
	"endColumn": 32
}]

Also when i try using the excersize code i am able to work properly.

I understand this looks very simple error but as the error is from Build directory which is generated using VS code so i am afraid that changes made here would afftect my whole configuration would change the configs for all project.

Please suggest where i have gone wrong

Parents
  • Hi Utkarsh,

    However For excersize 2 in order to have better understanding i tried importing blinky sample using option "Add new application from sample" and then modified the code for button interrupt,

    Could you share the changes that you have made?

    Are you using a custom board?

    Regards,

    Priyanka

  • Hello,

    thank you for quick response

    I really understand this is very basic code but i am not sure why i get this error, 

    I have just added the button polling code to blinky which i have attached below,

    In the below code i have just changed the button 0 to button 2.

    #define SW2_NODE    DT_ALIAS(sw2)
    
    #if DT_NODE_HAS_STATUS(SW2_NODE, okay)
    #define SW2_GPIO_LABEL  DT_GPIO_LABEL(SW2_NODE, gpios)
    #define SW2_GPIO_PIN    DT_GPIO_PIN(SW2_NODE, gpios)
    #define SW2_GPIO_FLAGS  DT_GPIO_FLAGS(SW2_NODE, gpios)
    #else
    #error "Unsupported board: sw0 devicetree alias is not defined"
    #define SW0_GPIO_LABEL  ""
    #define SW0_GPIO_PIN    0
    #define SW0_GPIO_FLAGS  0
    #endif
    
    void main(void)
    {
    	const struct device *dev, *button_dev;
    	bool led_is_on = true, val; 
    	int ret;
    
    
    	dev = device_get_binding(LED0);
    	if (dev == NULL) {
    		return;
    	}
    		button_dev = device_get_binding(LED0);
    	if (dev == NULL) {
    		return;
    	}
    
    	ret = gpio_pin_configure(dev, PIN, GPIO_OUTPUT_ACTIVE | FLAGS);
    	if (ret < 0) {
    		return;
    	}
    
    	ret = gpio_pin_configure(button_dev, SW2_GPIO_PIN, GPIO_INPUT | SW2_GPIO_FLAGS);
        if (ret < 0) {
            return;
        }
    
    	while (1) {
    		        
            val = gpio_pin_get(button_dev, SW2_GPIO_PIN); //Read the status of the button
            gpio_pin_set(dev, PIN, val); //Update the LED to the status of the button
            // k_msleep(SLEEP_TIME_MS); // Put the CPU to sleep for 100ms so it does not consume power
    
    		// gpio_pin_set(dev, PIN, (int)led_is_on);
    		// led_is_on = !led_is_on;
    		// k_msleep(SLEEP_TIME_MS);
    	}

    Maybe there is something wrong adding project so now i am planing to restart with new workspace.

    Thanks and Regards 

    Utkarash

Reply
  • Hello,

    thank you for quick response

    I really understand this is very basic code but i am not sure why i get this error, 

    I have just added the button polling code to blinky which i have attached below,

    In the below code i have just changed the button 0 to button 2.

    #define SW2_NODE    DT_ALIAS(sw2)
    
    #if DT_NODE_HAS_STATUS(SW2_NODE, okay)
    #define SW2_GPIO_LABEL  DT_GPIO_LABEL(SW2_NODE, gpios)
    #define SW2_GPIO_PIN    DT_GPIO_PIN(SW2_NODE, gpios)
    #define SW2_GPIO_FLAGS  DT_GPIO_FLAGS(SW2_NODE, gpios)
    #else
    #error "Unsupported board: sw0 devicetree alias is not defined"
    #define SW0_GPIO_LABEL  ""
    #define SW0_GPIO_PIN    0
    #define SW0_GPIO_FLAGS  0
    #endif
    
    void main(void)
    {
    	const struct device *dev, *button_dev;
    	bool led_is_on = true, val; 
    	int ret;
    
    
    	dev = device_get_binding(LED0);
    	if (dev == NULL) {
    		return;
    	}
    		button_dev = device_get_binding(LED0);
    	if (dev == NULL) {
    		return;
    	}
    
    	ret = gpio_pin_configure(dev, PIN, GPIO_OUTPUT_ACTIVE | FLAGS);
    	if (ret < 0) {
    		return;
    	}
    
    	ret = gpio_pin_configure(button_dev, SW2_GPIO_PIN, GPIO_INPUT | SW2_GPIO_FLAGS);
        if (ret < 0) {
            return;
        }
    
    	while (1) {
    		        
            val = gpio_pin_get(button_dev, SW2_GPIO_PIN); //Read the status of the button
            gpio_pin_set(dev, PIN, val); //Update the LED to the status of the button
            // k_msleep(SLEEP_TIME_MS); // Put the CPU to sleep for 100ms so it does not consume power
    
    		// gpio_pin_set(dev, PIN, (int)led_is_on);
    		// led_is_on = !led_is_on;
    		// k_msleep(SLEEP_TIME_MS);
    	}

    Maybe there is something wrong adding project so now i am planing to restart with new workspace.

    Thanks and Regards 

    Utkarash

Children
Related