Closed JlassiSeif closed 1 year ago
Can you build and pin-point what row that fails?
Get a callstack?
I have exactly the same issue: Segmentation fault after running the code!!
Can you build and pin-point what row that fails?
Get a callstack?
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
at bcm2835.c:273
rbuf=0x1 <error: Cannot access memory at address 0x1>, len=7) at bcm2835.c:814
at /home/IMU/SOES/applications/raspberry_lan9252demo/main.c:98
at /home/IMU/SOES/applications/raspberry_lan9252demo/main.c:110"
Shouldn't the demo be run as sudo?
sudo ./build/applications/raspberry_lan9252demo/soes-demo
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
@jehutting and @nakarlsson I appreciate your comments,
I tried to run as sudo as recommended but still has the Segmentation fault.
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.
@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!
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