assignment of member 'port' in read-only object

Dear, I defined Port1 pins as in attached overlay file. The binding of pins is done as in lcd.h attached file. When, build is started, the error written in title is displayed and build failed. Please guide, how to fix this issue.

Gulzar Singh

 6888.nrf5340dk_nrf5340_cpuapp.overlay5383.lcd.h   

Parents
  • Hi Gulzar,

    Could you kindly change the "tasks" option in the output to "output" and share the messages that appear there?

    Regards,

    Priyanka

  • Hello Priyanka, here is the attached image of OUTPUT. A well, I uploading the main.c, lcd,h, lcd.c and overlay file  6114.nrf5340dk_nrf5340_cpuapp.overlay

    //************** LCD Interface *****
    loc_curser curser_pos;
    //***************
    void lcd_init()
    {
      //DelayMs(15);
      k_msleep(15); 
      if (lcd_pin0.port && !device_is_ready(lcd_pin0.port)) {
    		printk("Error %d: LED device %s is not ready; ignoring it\n",ret, lcd_pin0.port->name);
    		lcd_pin0.port = NULL;
    	}
      if (lcd_pin0.port) {
    		ret = gpio_pin_configure_dt(&lcd_pin0, (GPIO_OUTPUT_LOW|GPIO_VOLTAGE_5P0) );
    		if (ret != 0) {
    			printk("Error %d: failed to configure LED device %s pin %d\n",ret, lcd_pin0.port->name, lcd_pin0.pin);
    			lcd_pin0.port = NULL;
    		} else {
    			printk("Set up LED at %s pin %d\n", lcd_pin0.port->name, lcd_pin0.pin);
    		}
    	}
      if (lcd_pin1.port && !device_is_ready(lcd_pin1.port)) {
    		printk("Error %d: LED device %s is not ready; ignoring it\n",ret, lcd_pin1.port->name);
    		lcd_pin1.port = NULL;
    	}
      if (lcd_pin1.port) {
    		ret = gpio_pin_configure_dt(&lcd_pin1, GPIO_OUTPUT_LOW);
    		if (ret != 0) {
    			printk("Error %d: failed to configure LED device %s pin %d\n",ret, lcd_pin1.port->name, lcd_pin1.pin);
    			lcd_pin1.port = NULL;
    		} else {
    			printk("Set up LED at %s pin %d\n", lcd_pin1.port->name, lcd_pin1.pin);
    		}
    	}
       if (lcd_pin2.port && !device_is_ready(lcd_pin2.port)) {
    		printk("Error %d: LED device %s is not ready; ignoring it\n",ret, lcd_pin2.port->name);
    		lcd_pin2.port = NULL;
    	}
       if (lcd_pin2.port) {
    		ret = gpio_pin_configure_dt(&lcd_pin2, GPIO_OUTPUT_LOW);
    		if (ret != 0) {
    			printk("Error %d: failed to configure LED device %s pin %d\n",ret, lcd_pin2.port->name, lcd_pin2.pin);
    			lcd_pin2.port = NULL;
    		} else {
    			printk("Set up LED at %s pin %d\n", lcd_pin2.port->name, lcd_pin2.pin);
    		}
    	}
        if (lcd_pin3.port && !device_is_ready(lcd_pin3.port)) {
    		printk("Error %d: LED device %s is not ready; ignoring it\n",ret, lcd_pin3.port->name);
    		lcd_pin3.port = NULL;
    	}
        if (lcd_pin3.port) {
    		ret = gpio_pin_configure_dt(&lcd_pin3, GPIO_OUTPUT_LOW);
    		if (ret != 0) {
    			printk("Error %d: failed to configure LED device %s pin %d\n",ret, lcd_pin3.port->name, lcd_pin3.pin);
    			lcd_pin3.port = NULL;
    		} else {
    			printk("Set up LED at %s pin %d\n", lcd_pin3.port->name, lcd_pin3.pin);
    		}
    	}
        if (rs_pin.port && !device_is_ready(rs_pin.port)) {
    		printk("Error %d: LED device %s is not ready; ignoring it\n",ret, rs_pin.port->name);
    		rs_pin.port = NULL;
    	}
        if (rs_pin.port) {
    		ret = gpio_pin_configure_dt(&rs_pin, GPIO_OUTPUT_LOW);
    		if (ret != 0) {
    			printk("Error %d: failed to configure LED device %s pin %d\n",ret, rs_pin.port->name, rs_pin.pin);
    			rs_pin.port = NULL;
    		} else {
    			printk("Set up LED at %s pin %d\n", rs_pin.port->name, rs_pin.pin);
    		}
    	}
       if (en_pin.port && !device_is_ready(en_pin.port)) {
    		printk("Error %d: LED device %s is not ready; ignoring it\n",ret, en_pin.port->name);
    		en_pin.port = NULL;
    	}
       if (en_pin.port) {
    		ret = gpio_pin_configure_dt(&en_pin, GPIO_OUTPUT_LOW);
    		if (ret != 0) {
    			printk("Error %d: failed to configure LED device %s pin %d\n",ret, en_pin.port->name, en_pin.pin);
    			en_pin.port = NULL;
    		} else {
    			printk("Set up LED at %s pin %d\n", en_pin.port->name, en_pin.pin);
    		}
    	}
    
      gpio_pin_set_dt(&en_pin,1);
      gpio_pin_set_dt(&rs_pin,0);
      lcd_cmd_4bit(0x03);k_msleep(5);
      lcd_cmd_4bit(0x03);k_msleep(5);
      lcd_cmd_4bit(0x03);k_msleep(5);
      lcd_cmd_4bit(0x02);k_msleep(5);
      lcd_cmd_byte(0x28);k_msleep(5);
      lcd_cmd_byte(0x08);k_msleep(5);
      lcd_cmd_byte(0x01);k_msleep(5);
      lcd_cmd_byte(0x06);k_msleep(5);
      lcd_cmd_byte(0x0c);k_msleep(5);
    }
    void lcd_cmd_4bit(unsigned char ch)
    {
     gpio_pin_set_dt(&rs_pin,0);
     if(ch&1)gpio_pin_set_dt(&lcd_pin0,1); else gpio_pin_set_dt(&lcd_pin0,0);
     if(ch&1)gpio_pin_set_dt(&lcd_pin1,1); else gpio_pin_set_dt(&lcd_pin1,0);
     if(ch&1)gpio_pin_set_dt(&lcd_pin2,1); else gpio_pin_set_dt(&lcd_pin2,0);
     if(ch&1)gpio_pin_set_dt(&lcd_pin3,1); else gpio_pin_set_dt(&lcd_pin3,0);
     
     gpio_pin_set_dt(&en_pin,1);
     
     gpio_pin_set_dt(&en_pin,0);
    }
    /***************/
    void lcd_cmd_byte(unsigned char a)
    { unsigned char z = a;
     
     lcd_command((a>>4)&(0x0f));
      a = z;
     lcd_command(a&(0x0f));
    }
    /***************/
    void lcd_command(unsigned char ch)
    {   k_msleep(1);
    
        gpio_pin_set_dt(&rs_pin,0);
    
     if(ch&1)gpio_pin_set_dt(&lcd_pin0,1); else gpio_pin_set_dt(&lcd_pin0,0);
     if(ch&1)gpio_pin_set_dt(&lcd_pin1,1); else gpio_pin_set_dt(&lcd_pin1,0);
     if(ch&1)gpio_pin_set_dt(&lcd_pin2,1); else gpio_pin_set_dt(&lcd_pin2,0);
     if(ch&1)gpio_pin_set_dt(&lcd_pin3,1); else gpio_pin_set_dt(&lcd_pin3,0);
        
     gpio_pin_set_dt(&en_pin,1);
     k_usleep(100);
     gpio_pin_set_dt(&en_pin,0);
    }
    /*************/
    void lcd_data_byte(unsigned char  a)
    {char z = a; 
     lcd_data((z>>4)&0x0f);
      z = a;
     lcd_data(z&0x0f); 
    }
    /******************/
    void lcd_data(unsigned char ch)
    {   k_msleep(1);
      gpio_pin_set_dt(&rs_pin,1);
    
     if(ch&1)gpio_pin_set_dt(&lcd_pin0,1); else gpio_pin_set_dt(&lcd_pin0,0);
     if(ch&1)gpio_pin_set_dt(&lcd_pin1,1); else gpio_pin_set_dt(&lcd_pin1,0);
     if(ch&1)gpio_pin_set_dt(&lcd_pin2,1); else gpio_pin_set_dt(&lcd_pin2,0);
     if(ch&1)gpio_pin_set_dt(&lcd_pin3,1); else gpio_pin_set_dt(&lcd_pin3,0);
        
     gpio_pin_set_dt(&en_pin,1);
     k_usleep(100);
     gpio_pin_set_dt(&en_pin,0);
    }
    /*********/
    void lcd_1Home(void)
    {
     lcd_cmd_byte(0x80);
    }
    /*******/
    void lcd_clear(void)
    {
    lcd_cmd_byte(0x01);
    }
    /*********/
    void lcd_2Home(void)
    {
     lcd_cmd_byte(0xc0);
    }
    //*****************
    void lcd_3Home(void)
    {
     lcd_cmd_byte(0x94);
    }
    /***************/
    void lcd_4Home(void)
    {
     lcd_cmd_byte(0xD4);
    }
    void lcd_blank(unsigned char a)
    {while(a)
      {lcd_data_byte(' '); DelayMs(5);a--;}
    }
    /////////////////////////
    void lcd_goto1(unsigned char a)
    {
     lcd_cmd_byte(0x80+ a);
    }
    void lcd_goto2(unsigned char a)
    {
     lcd_cmd_byte(0xC0+ a);
    }
    void lcd_goto3(unsigned char a)
    {
     lcd_cmd_byte(0x94+ a);
    }
    void lcd_goto4(unsigned char a)
    {
     lcd_cmd_byte(0xD4+ a);
    }
    void lcd_spaces(unsigned char z)
    {
      while(z)
     {
      lcd_data_byte(' ');z--;
     }
    }
    //**************************
    void jump_cursor(void)
    {
      switch(curser_pos.line_no)
      {
      case(1):{lcd_goto1(curser_pos.loc_add);break;}
      case(2):{lcd_goto2(curser_pos.loc_add);break;}
      case(3):{lcd_goto3(curser_pos.loc_add);break;}
      case(4):{lcd_goto4(curser_pos.loc_add);break;}
      }
    }
    //********************
    void update_curser_pos(unsigned char L,unsigned char a)
    {
      curser_pos.line_no = L;
      curser_pos.loc_add = a;
    }
    //**********************
    /*
     * Copyright (c) 2016 Open-RnD Sp. z o.o.
     * Copyright (c) 2020 Nordic Semiconductor ASA
     *
     * SPDX-License-Identifier: Apache-2.0
     */
    //****************************************************
    #include <zephyr.h>
    #include <device.h>
    #include<devicetree.h>
    #include <drivers/gpio.h>
    #include <sys/util.h>
    #include <sys/printk.h>
    #include <drivers/uart.h>
    #include <sys/ring_buffer.h>
    #include <string.h>
    #include <sys/__assert.h>
    //*********************************
    #include "lcd.h"
    #include "Delay.h"
    #include "msg.h"
    //**********************
    #define SLEEP_TIME_MS	1
    
    /*
     * Get button configuration from the devicetree sw0 alias. This is mandatory.
     */
     //***********
     int ret;
    #define SW0_NODE	DT_ALIAS(sw0)
    #define SW1_NODE	DT_ALIAS(sw1)
    #define SW2_NODE	DT_ALIAS(sw2)
    #define SW3_NODE	DT_ALIAS(sw3)
    //***************
    #if !DT_NODE_HAS_STATUS(SW0_NODE, okay)
    #error "Unsupported board: sw0 devicetree alias is not defined"
    #endif
    #if !DT_NODE_HAS_STATUS(SW1_NODE, okay)
    #error "Unsupported board: sw1 devicetree alias is not defined"
    #endif
    #if !DT_NODE_HAS_STATUS(SW2_NODE, okay)
    #error "Unsupported board: sw2 devicetree alias is not defined"
    #endif
    #if !DT_NODE_HAS_STATUS(SW3_NODE, okay)
    #error "Unsupported board: sw3 devicetree alias is not defined"
    #endif
    //*************
    static const struct gpio_dt_spec button_one = GPIO_DT_SPEC_GET_OR(SW0_NODE, gpios,{0});
    static const struct gpio_dt_spec button_two = GPIO_DT_SPEC_GET_OR(SW1_NODE, gpios,{0});
    static const struct gpio_dt_spec button_three = GPIO_DT_SPEC_GET_OR(SW2_NODE, gpios,{0});
    static const struct gpio_dt_spec button_four = GPIO_DT_SPEC_GET_OR(SW3_NODE, gpios,{0});
    //static struct gpio_callback button_cb_data;
    /*
     * The led0 devicetree alias is optional. If present, we'll use it
     * to turn on the LED whenever the button is pressed.
     */
    static struct gpio_dt_spec led_one = GPIO_DT_SPEC_GET_OR(DT_ALIAS(led0), gpios,{0});
    static struct gpio_dt_spec led_two = GPIO_DT_SPEC_GET_OR(DT_ALIAS(led1), gpios,{0});
    static struct gpio_dt_spec led_three = GPIO_DT_SPEC_GET_OR(DT_ALIAS(led2), gpios,{0});
    static struct gpio_dt_spec led_four = GPIO_DT_SPEC_GET_OR(DT_ALIAS(led3), gpios,{0});
    
    
    //*****************************************
    void main(void)
    {
    	
    	if (!device_is_ready(button_one.port)) {
    		printk("Error: button device %s is not ready\n",
    		       button_one.port->name);
    		return;
    	}
    
    	ret = gpio_pin_configure_dt(&button_one, GPIO_INPUT);
    	if (ret != 0) {
    		printk("Error %d: failed to configure %s pin %d\n",
    		       ret, button_one.port->name, button_one.pin);
    		return;
    	}
    /*
    	ret = gpio_pin_interrupt_configure_dt(&button_one,GPIO_INT_EDGE_TO_ACTIVE);
    	if (ret != 0) {
    		printk("Error %d: failed to configure interrupt on %s pin %d\n",
    			ret, button_one.port->name, button_one.pin);
    		return;
    	}
    
    	gpio_init_callback(&button_cb_data, button_pressed, BIT(button_one.pin));
    	gpio_add_callback(button_one.port, &button_cb_data);
    	printk("Set up button at %s pin %d\n", button_one.port->name, button_one.pin);
    */
    
    	ret = gpio_pin_configure_dt(&button_two, GPIO_INPUT);
    	if (ret != 0) {
    		printk("Error %d: failed to configure %s pin %d\n",
    		       ret, button_two.port->name, button_two.pin);
    		return;
    	}
    /*
    	ret = gpio_pin_interrupt_configure_dt(&button_two,
    					      GPIO_INT_EDGE_TO_ACTIVE);
    	if (ret != 0) {
    		printk("Error %d: failed to configure interrupt on %s pin %d\n",
    			ret, button_two.port->name, button_two.pin);
    		return;
    	}
    
    	gpio_init_callback(&button_cb_data, button_pressed, BIT(button_two.pin));
    	gpio_add_callback(button_two.port, &button_cb_data);
    	printk("Set up button at %s pin %d\n", button_two.port->name, button_two.pin);
    */
            
    	ret = gpio_pin_configure_dt(&button_three, GPIO_INPUT);
    	if (ret != 0) {
    		printk("Error %d: failed to configure %s pin %d\n",
    		       ret, button_three.port->name, button_three.pin);
    		return;
    	}
    /*
    	ret = gpio_pin_interrupt_configure_dt(&button_three,
    					      GPIO_INT_EDGE_TO_ACTIVE);
    	if (ret != 0) {
    		printk("Error %d: failed to configure interrupt on %s pin %d\n",
    			ret, button_three.port->name, button_three.pin);
    		return;
    	}
    
    	gpio_init_callback(&button_cb_data, button_pressed, BIT(button_three.pin));
    	gpio_add_callback(button_three.port, &button_cb_data);
    	printk("Set up button at %s pin %d\n", button_three.port->name, button_three.pin);
    */
            
    	ret = gpio_pin_configure_dt(&button_four, GPIO_INPUT);
    	if (ret != 0) {
    		printk("Error %d: failed to configure %s pin %d\n",
    		       ret, button_four.port->name, button_four.pin);
    		return;
    	}
    /*
    	ret = gpio_pin_interrupt_configure_dt(&button_four,
    					      GPIO_INT_EDGE_TO_ACTIVE);
    	if (ret != 0) {
    		printk("Error %d: failed to configure interrupt on %s pin %d\n",
    			ret, button_four.port->name, button_four.pin);
    		return;
    	}
    
    	gpio_init_callback(&button_cb_data, button_pressed, BIT(button_four.pin));
    	gpio_add_callback(button_four.port, &button_cb_data);
    	printk("Set up button at %s pin %d\n", button_four.port->name, button_four.pin);
    
    */
    	if (led_one.port && !device_is_ready(led_one.port)) {
    		printk("Error %d: LED device %s is not ready; ignoring it\n",
    		       ret, led_one.port->name);
    		led_one.port = NULL;
    	}
    	if (led_one.port) {
    		ret = gpio_pin_configure_dt(&led_one, GPIO_OUTPUT_LOW);
    		if (ret != 0) {
    			printk("Error %d: failed to configure LED device %s pin %d\n",
    			       ret, led_one.port->name, led_one.pin);
    			led_one.port = NULL;
    		} else {
    			printk("Set up LED at %s pin %d\n", led_one.port->name, led_one.pin);
    		}
    	}
            if (led_two.port && !device_is_ready(led_two.port)) {
    		printk("Error %d: LED device %s is not ready; ignoring it\n",
    		       ret, led_two.port->name);
    		led_two.port = NULL;
    	}
            if (led_two.port) {
    		ret = gpio_pin_configure_dt(&led_two, GPIO_OUTPUT_LOW);
    		if (ret != 0) {
    			printk("Error %d: failed to configure LED device %s pin %d\n",
    			       ret, led_two.port->name, led_two.pin);
    			led_two.port = NULL;
    		} else {
    			printk("Set up LED at %s pin %d\n", led_two.port->name, led_two.pin);
    		}
    	}
            if (led_three.port && !device_is_ready(led_three.port)) {
    		printk("Error %d: LED device %s is not ready; ignoring it\n",
    		       ret, led_three.port->name);
    		led_three.port = NULL;
    	}
            if (led_three.port) {
    		ret = gpio_pin_configure_dt(&led_three, GPIO_OUTPUT_LOW);
    		if (ret != 0) {
    			printk("Error %d: failed to configure LED device %s pin %d\n",
    			       ret, led_three.port->name, led_three.pin);
    			led_three.port = NULL;
    		} else {
    			printk("Set up LED at %s pin %d\n", led_three.port->name, led_three.pin);
    		}
    	}
            if (led_four.port && !device_is_ready(led_four.port)) {
    		printk("Error %d: LED device %s is not ready; ignoring it\n",
    		       ret, led_four.port->name);
    		led_four.port = NULL;
    	}
            if (led_four.port) {
    		ret = gpio_pin_configure_dt(&led_four, GPIO_OUTPUT_LOW);
    		if (ret != 0) {
    			printk("Error %d: failed to configure LED device %s pin %d\n",
    			       ret, led_four.port->name, led_four.pin);
    			led_four.port = NULL;
    		} else {
    			printk("Set up LED at %s pin %d\n", led_four.port->name, led_four.pin);
    		}
    	}	
     	
              lcd_init();
              boot_msg();
    
     		while (1) {
    			/* If we have an LED, match its state to the button's. */
    			/*
                            int val = gpio_pin_get_dt(&button_one);
    
    			if (val >= 0) {
    				gpio_pin_set_dt(&led_one, val);
    			}
    			k_msleep(SLEEP_TIME_MS);
                            */
                            if(gpio_pin_get_dt(&button_one)!= 0)
                            {
                              k_msleep(200);
                              if(gpio_pin_get_dt(&button_one)!= 0)
                              {
                                gpio_pin_toggle_dt(&led_one);
                              }
                            }
                           if(gpio_pin_get_dt(&button_two)!= 0)
                            {
                              k_msleep(200);
                              if(gpio_pin_get_dt(&button_two)!= 0)
                              {
                                gpio_pin_toggle_dt(&led_two);
                              }
                            }
                            if(gpio_pin_get_dt(&button_three)!= 0)
                            {
                              k_msleep(200);
                              if(gpio_pin_get_dt(&button_three)!= 0)
                              {
                                gpio_pin_toggle_dt(&led_three);
                              }
                            }
                            if(gpio_pin_get_dt(&button_four)!= 0)
                            {
                              k_msleep(200);
                              if(gpio_pin_get_dt(&button_four)!= 0)
                              {
                                gpio_pin_toggle_dt(&led_four);
                              }
                            }
                            
    		
    		}	        
    }
    //****************
    #include "lcd.c"
    #include "Delay.c"
    #include "msg.c"
    //*****************
    3487.lcd.h  

  • Hi Gulzar,

    As you can observe on line 263, 264 and 265 in main.c, you have added the statements to include the .c files. Since the lcd, delay and msg are custom files that you create for your project, the Icd.h, delay.h and msg.h should be included inside the .c versions of these files.

    Also, lcd.c , delay.c and msg.c should be called inside CMakeLists.txt inside your project folder.

    A detailed way of creating a custom application is mentioned in the GitHub page of one of my colleagues.. Kindly take a look.

    Regards,

    Priyanka

Reply
  • Hi Gulzar,

    As you can observe on line 263, 264 and 265 in main.c, you have added the statements to include the .c files. Since the lcd, delay and msg are custom files that you create for your project, the Icd.h, delay.h and msg.h should be included inside the .c versions of these files.

    Also, lcd.c , delay.c and msg.c should be called inside CMakeLists.txt inside your project folder.

    A detailed way of creating a custom application is mentioned in the GitHub page of one of my colleagues.. Kindly take a look.

    Regards,

    Priyanka

Children
Related