Segmentation fault with inbuilt .c files in api

Applications, development tools, FPGA, C, WEB
Post Reply
njoshi
Posts: 5
Joined: Thu Jun 07, 2018 10:12 am

Segmentation fault with inbuilt .c files in api

Post by njoshi » Tue Dec 03, 2019 1:51 pm

<r>Hi,<br/>
I am not proficient in C and fpga, so please excuse if I have made any obvious mistake.<br/>
I am trying to use redpitaya generator functionality using inbuilt api C functions.<br/>
<br/>
I wasn't able to compile from multiple directories, so just copied my test script NJ_Gen_01.c to
<CODE><s>

Code: Select all

</s>/root/RedPitaya/api/src 
<e>
</e></CODE>

NJ_Gen_01.c
<CODE><s>

Code: Select all

</s><i>
</i>#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <getopt.h>
#include <string.h>
#include <stddef.h>
#include <sys/param.h>
#include <unistd.h>
#include <time.h>
#include <sys/time.h>
#include <sys/stat.h>
#include <sys/types.h>
#include "/root/RedPitaya/api/src/gen_handler.h"
#include "/root/RedPitaya/api/src/generate.h"
#include "/root/RedPitaya/api/src/common.h"

int main(int argc, char *argv[])
{
  int func_ret=-1; /*to check return value from functions*/
  printf("\nHello world.\n");
  func_ret = gen_SetDefaultValues(RP_CH_1);
  // func_ret = gen_setAmplitude(0, 0.7);
  // func_ret = gen_setFrequency(0, 100e3);
  // func_ret = gen_setWaveform(0, RP_WAVEFORM_SQUARE);
  // func_ret = gen_setGenMode(0, RP_GEN_MODE_CONTINUOUS);
  // func_ret = gen_Enable(RP_CH_1);
  // func_ret = gen_Trigger(RP_CH_1);
  return func_ret;
}

<e>
</e></CODE>

Compiling all C files together
<CODE><s>

Code: Select all

</s><i>
</i># gcc   -Wall NJ_Gen_01.c gen_handler.c generate.c common.c common.h calib.c rp.c spec_dsp.c spec_fpga.c acq_handler.c oscilloscope.c kiss_fft.c kiss_fftr.c -lm -g -o NJ_Gen_01
n file included from NJ_Gen_01.c:16:0:
/root/RedPitaya/api/src/common.h:56:0: warning: "MIN" redefined
 #define MIN(X, Y) (((X) < (Y)) ? (X) : (Y))
 ^
In file included from NJ_Gen_01.c:8:0:
/usr/include/arm-linux-gnueabihf/sys/param.h:102:0: note: this is the location of the previous definition
 #define MIN(a,b) (((a)<(b))?(a):(b))
 ^
In file included from NJ_Gen_01.c:16:0:
/root/RedPitaya/api/src/common.h:57:0: warning: "MAX" redefined
 #define MAX(X, Y) (((X) > (Y)) ? (X) : (Y))
 ^
In file included from NJ_Gen_01.c:8:0:
/usr/include/arm-linux-gnueabihf/sys/param.h:103:0: note: this is the location of the previous definition
 #define MAX(a,b) (((a)>(b))?(a):(b))

<e>
</e></CODE>
Which works fine, I think. As the generator has been set to default values, it should generate sine wave of 1V and 1kHz. Instead I get segmentation fault as follows. I have not added any code, but used in built function only,
<CODE><s>

Code: Select all

</s><i>
</i># gdb NJ_Gen_01
Reading symbols from NJ_Gen_01...done.
(gdb) run
Starting program: /root/RedPitaya/api/src/NJ_Gen_01 

Program received signal SIGSEGV, Segmentation fault.
0xb6fd9dde in ?? () from /lib/ld-linux-armhf.so.3
(gdb) backtrace
#0  0xb6fd9dde in ?? () from /lib/ld-linux-armhf.so.3
#1  0xb6fd9df6 in ?? () from /lib/ld-linux-armhf.so.3
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
(gdb)

<e>
</e></CODE>
Thank you in advance and appreciate your efforts.</r>

User avatar
redpitaya
Site Admin
Posts: 898
Joined: Wed Mar 26, 2014 7:04 pm

Re: Segmentation fault with inbuilt .c files in api

Post by redpitaya » Tue Mar 03, 2020 3:45 pm

Hi, thank you for posting!

It looks like you are trying to use functions without initialization.
Here is some sample how it can be solved -
https://redpitaya.readthedocs.io/en/lat ... exm1.html.

Post Reply
jadalnie klasyczne ekskluzywne meble wypoczynkowe do salonu ekskluzywne meble tapicerowane ekskluzywne meble do sypialni ekskluzywne meble włoskie

Who is online

Users browsing this forum: No registered users and 19 guests