PiGpio exception SIGSEGV lazarus / 32-Linux ---------------------------------------------------------------------- babbel · 2020-03-09 14:16 Hi theren, new to Raspberry (and linux...), trying to get GPIO running. Most works with the encapsulated shell calls, but there I cannot find how to setup Pull_up for an input. I am trying to use the RPi to build an alarm system with some passive IR sensors and switches for on doors and windows. I've got a draft version running in Python 2.7, but I am using Lazarus quite some time in windows and would like to get this running on a raspberry with a nice GUI, which I cannot find in Python So I wanted to try the unit PiGpio, but this results in exception SIGSEGV in the line gpiof := Pointer(LongWord(Self.FGpio) + fSel); I has probably something to do with rights, but I can't figure out what. Any help is appreciated. Robbert ---------------------------------------------------------------------- eljo · 2020-03-09 14:19 search this forums for ultibo. a bare metal framework to work with raspberry pi. ---------------------------------------------------------------------- Thaddy · 2020-03-09 14:46 I need to know the version of the Raspberry Pi and in case of the RPi2 the revision number too. The GPIO base address differs between the models and there is code that needs to be corrected for pagesize ($1000 or 4096, so it needs a division) ---------------------------------------------------------------------- babbel · 2020-03-10 06:26 It is on a RPi 4. I found that if I start Lazarus with pi@raspberrypi:~$ sudo /usr/lib/lazarus/2.0.0/startlazarus it seems to work, but on startup this gives me a lot of messages and warnings. There must be a better way that I would like to learn ---------------------------------------------------------------------- Thaddy · 2020-03-10 06:31 if you start from a terminal this is normal on all platforms.  Code: Bash  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i ./startlazarus --quietYou will still get some output, but much less. And you can ignore them all. If you install lazarus from the Raspbian package manager you can start Lazarus through a menu item and that won't show any messages at all. You can also create such a link yourself. ---------------------------------------------------------------------- babbel · 2020-03-10 07:37 Ok, starting Lazarus will give me less warnings. But running lazarus as root, does this give me also an executable that allows acces to the GPIO? The executable still gives me an access violation and if I ignore this the PiGpio reports "Error mapping gpio registry" So I still need to understand more about how to set privileges to access the GPIO About Ultibo, i seems what I need, but also it seems there is not a lot activity anymore as the latest news is from 2018 and I thing it will not support the RPi 4 I use ---------------------------------------------------------------------- hansotten · 2020-03-10 08:53 I have the same problem with GPIO,rpi_hal and Lazarus, no access to /dev/mem is the cause of the troubles. These libs should use /dev/gpiomem instead of /dev/mem as access in current versions of Raspbian is is enabled for user. But alas, access to /dev/mem requires root Console apps work fine when run as root, Lazarus X apps not. ---------------------------------------------------------------------- Thaddy · 2020-03-10 09:29 Quote from: hansotten on March 10, 2020, 09:53:41 amI have the same problem with GPIO,rpi_hal and Lazarus, no access to /dev/mem is the cause of the troubles. These libs should use /dev/gpiomem instead of /dev/mem as access in current versions of Raspbian is is enabled for user. But alas, access to /dev/mem requires root Console apps work fine when run as root, Lazarus X apps not. The GPIO address in the wiki is only correct for RPi 1 so will sigsev on all others. I will edit it and add the GPIO base addresses for all other Pi versions. Can take some time, because I am busy. Possibly this weekend. You can look up the GPIO base address from the Raspberry Pi chipset documentation for your revision. You need to divide the full address through $1000 to obtain the correct entry for PiGPIO. ---------------------------------------------------------------------- hansotten · 2020-03-10 12:23 I guess that the problem of the OP and me are not related to the GPIO address. Like the OP  I started Lazarus as root with sudo and the resulting test program ran fine from run in Lazarus. Our underlying problem seems to be the same, PIGPIO also tries to open /dev/mem as I read in the source. So its rights on /dev/mem and/or being able to run a desktop with root privs. And we are not Linux experts enough and cant find a way. ---------------------------------------------------------------------- Thaddy · 2020-03-10 12:31 Hans can you add a simple example that fails (just a led)? Then I can investigate further. I still think you are both using the GPIO address from the wiki, which is wrong for RPi3 and 4. Wriiten from a RPi 4.... ---------------------------------------------------------------------- hansotten · 2020-03-10 12:36 Seems I found a solution here: https://wiki.archlinux.org/index.php/Running_GUI_applications_as_root Hope this helps the OP also! I applied method 2: sudo nano /etc/profile and added this line as last line export XAUTHORITY=/home/pi/.Xauthority Now i can do $ sudo ./testinit (my simple test program with only the init line of rpi_hal) and this worked without error, init succeeded. Not a secure solution, but user pi already had the right to run apps as root and now also X apps. Original text from https://wiki.archlinux.org/index.php/Running_GUI_applications_as_root Method 2: Globally in /etc/profile Add the following line to /etc/profile: export XAUTHORITY=/home/username/.Xauthority This will permanently allow root to connect to a non-root user's X server. Or, merely specify a particular app: XAUTHORITY=/home/username/.Xauthority appname where appname is the name of the particular app. (e.g. kwrite ---------------------------------------------------------------------- avra · 2020-03-10 12:52 Have you seen "sudo adduser pi gpio" solution at below wiki page? https://wiki.freepascal.org/Lazarus_on_Raspberry_Pi#Accessing_external _hardware It looks much more proper. ---------------------------------------------------------------------- hansotten · 2020-03-10 12:57 Quote from: avra on March 10, 2020, 01:52:34 pmHave you seen "sudo adduser pi gpio" solution at below wiki page? https://wiki.freepascal.org/Lazarus_on_Raspberry_Pi#Accessing_external _hardware It looks much more proper. That allows access to /dev/gpiomem which is now default in Raspbian. The libraries require access to /dev/mem