OpenEtherCATsociety / SOES

Simple Open Source EtherCAT Slave
Other
587 stars 251 forks source link

Segmentation Fault when running the Rasberry demo #153

Closed JlassiSeif closed 1 year ago

JlassiSeif commented 1 year ago

I built the RPI demo using these instruction https://github.com/OpenEtherCATsociety/SOES/issues/121#issuecomment-1175789968. When I run the demo this is what I get: Hello Main Hello Main Segmentation fault

nakarlsson commented 1 year ago

Can you build and pin-point what row that fails?

Get a callstack?

Amir7RN commented 1 year ago

I have exactly the same issue: Segmentation fault after running the code!!

nakarlsson commented 1 year ago

Can you build and pin-point what row that fails?

Get a callstack?

Amir7RN commented 1 year ago

thanks for your reply, nakarlsson!

here are the steps I have followed to get a call stack:

1- I added the debugging flags -g to the CMakeLists.txt file: ""add_executable(soes-demo main.c slave_objectlist.c) -->Adding debugging flags target_compile_options(soes-demo PRIVATE -g) target_link_libraries(soes-demo LINK_PUBLIC soes bcm2835) install(TARGETS soes-demo DESTINATION sbin) install(PROGRAMS S60soes DESTINATION /etc/init.d)"" 2- I build the executable using this modified CMakeList.txt

3- In order to analyze the segmentation fault, I used a debugger "gdb" by commanding "gdb soes-demo" and "run" here is the result: "(gdb) run Starting program: /home/IMU/SOES/build/applications/raspberry_lan9252demo/soes-demo Hello Main Hello Main

Program received signal SIGSEGV, Segmentation fault. bcm2835_peri_read (paddr=0xffffffff) at bcm2835.c:212 212 ret = *paddr;"

4- Then I obtained the call stack by commanding "backtrace" and here is the result: "(gdb) backtrace

0 bcm2835_peri_read (paddr=0xffffffff) at bcm2835.c:212

1 bcm2835_peri_set_bits (paddr=0xffffffff, value=48, mask=48)

at bcm2835.c:273

2 0x0001d438 in bcm2835_spi_transfernb (tbuf=0x0,

rbuf=0x1 <error: Cannot access memory at address 0x1>, len=7) at bcm2835.c:814

3 0x0001374c in bcm2835_spi_write_32 ()

4 0x00013824 in ESC_read_csr ()

5 0x0001413c in ESC_read ()

6 0x00013660 in ecat_slv_init ()

7 0x00012ef4 in main_run (arg=0x0)

at /home/IMU/SOES/applications/raspberry_lan9252demo/main.c:98

8 0x00012f1c in main ()

at /home/IMU/SOES/applications/raspberry_lan9252demo/main.c:110"

jehutting commented 1 year ago

Shouldn't the demo be run as sudo? sudo ./build/applications/raspberry_lan9252demo/soes-demo

nakarlsson commented 1 year ago

Does that make a difference for you? DEBUG prints in esc_hw.c certainly hint of that

DPRINT("bcm2835_spi_begin failed. Are you running as root?\n");

NOTE, I'm not the author of this port, nor have I tired it. Juts trying to help out anyway

Amir7RN commented 1 year ago

@jehutting and @nakarlsson I appreciate your comments,

I tried to run as sudo as recommended but still has the Segmentation fault.

ArthurKetels commented 1 year ago

Please define ESC_DEBUG. This will print out some more info at ESC_init(). I think there is something wrong with the bcm2835 initialization.

This is where it goes wrong:

void bcm2835_spi_transfernb(char* tbuf, char* rbuf, uint32_t len)
{
    volatile uint32_t* paddr = bcm2835_spi0 + BCM2835_SPI0_CS/4;

paddr is assigned 0xffffffff. And this is obviously not correct. This means bcm2835_spi0 is not set correctly by the spi init function that is ultimately called from ESC_init(). It could be as simple as that your device tree is not setup correctly for the bmc2835 driver.

Amir7RN commented 1 year ago

@ArthurKetels @nakarlsson

I did #define ESC_DEBUG, but did not get any additional info. BTW, the problem was resolved since there was an issue w/ the hardware connection of the RPI and SPI device. After reconnecting the devices properly, no segmentation fault occurred!