Segmentation Fault- is the error while running the executable.Kindly suggest the possible cause

93 views
asked Jan 31 in System Integration by rpi3usr

The only changes done by me are to the device driver .c file while using the generated code from the Device Integration example of Raspberry Pi.

1 Answer

+1 vote
answered Jan 31 by Manfred Schweyer
 
Best answer
Hello,

difficult to say....

What happens if you take the original DeviceDriver.c file - does it work without segmentation fault?

Best regards,

Manfred.
commented Feb 1 by rpi3usr

Hello Manfred

I followed your suggestion. And pin-pointed the location where the error is occuring. 

The fault occurs before the DeviceDriver_Initialize() function is even called. Since devicedriver.c was the file which was modified , I am not able to draw any conclusions from this.

 

commented Feb 1 by Manfred Schweyer
Can you send your modified DeviceDriver.c file? I will have a look on that.
commented Feb 1 by rpi3usr

https://ask.embedded-wizard.de/?qa=blob&qa_blobid=614896531816490184 //devicedriver,c

Here, I have attached the device driver.c file. 

Just FYI, I am using an ADC chip ADS1256 . An example file(namely ADS1256test.c- which is also attached below) was available online which uses bcm2835.h as the base functionality file. I had tested the file independently , also I tested the Deviceintegeration project independently. This is my attempt to basically include the ADC functions into the Devicedriver.

https://ask.embedded-wizard.de/?qa=blob&qa_blobid=6536290395998010090    //ads1256test.c

https://ask.embedded-wizard.de/?qa=blob&qa_blobid=5383896756556811157    //bcm2835.c

https://ask.embedded-wizard.de/?qa=blob&qa_blobid=12596710160883662912 //bcm2835.h

commented Feb 2 by Manfred Schweyer

I still believe the segmentation fault happens somewhere within the DeviceDriver_Intialize() function - your EwPrint() messages are maybe not transferred because of the missing "\n".

Try to find the erroneous location e.g. by putting a lot of simple but unique messages within your code, e.g.:

void DeviceDriver_Initialize( void )
{
  EwPrint("A\n");
    if (!bcm2835_init())
        return 1;
  EwPrint("B\n");
    bcm2835_spi_begin();
  EwPrint("C\n");
    bcm2835_spi_setBitOrder(BCM2835_SPI_BIT_ORDER_MSBFIRST);   //default
  EwPrint("D\n");
    bcm2835_spi_setDataMode(BCM2835_SPI_MODE1);                //default
  EwPrint("E\n");
    bcm2835_spi_setClockDivider(BCM2835_SPI_CLOCK_DIVIDER_256);//default
  EwPrint("F\n");
    bcm2835_gpio_fsel(SPICS, BCM2835_GPIO_FSEL_OUTP);//
  EwPrint("G\n");
    bcm2835_gpio_write(SPICS, HIGH);
  EwPrint("H\n");
    bcm2835_gpio_fsel(DRDY, BCM2835_GPIO_FSEL_INPT);
  EwPrint("I\n");
    bcm2835_gpio_set_pud(DRDY, BCM2835_GPIO_PUD_UP);    	
...

 

commented Feb 2 by rpi3usr

Thanks a lot Manfred

You were right. The error was due the bcm2835.h library. It required root access to run

Embedded Wizard Website | Privacy Policy | Imprint

...