tjboldt / Apple2-IO-RPi

Apple II expansion card using a Raspberry Pi for I/O
MIT License
123 stars 14 forks source link

GPIO errors on startup #175

Closed tjboldt closed 4 months ago

tjboldt commented 4 months ago

What happened?

CygnusTM reported:

The apple2driver.service fails on autostart every time the Pi reboots. Then it will work fine if I restart the service

todd@raspberrypi:~ $ sudo systemctl status apple2driver.service
× apple2driver.service - Apple2-IO-RPi Driver (Classic edition)
     Loaded: loaded (/etc/systemd/system/apple2driver.service; enabled; preset: enabled)
     Active: failed (Result: exit-code) since Mon 2024-04-29 10:49:28 EDT; 56s ago
   Duration: 777ms
    Process: 392 ExecStart=/home/todd/Apple2-IO-RPi/RaspberryPi/apple2driver/apple2driver (code=exited, status=2)
   Main PID: 392 (code=exited, status=2)
        CPU: 226ms

Apr 29 10:49:28 raspberrypi apple2driver[392]: Starting Apple II RPi v002D...
Apr 29 10:49:28 raspberrypi apple2driver[392]: Starting communications via GPIO ports...
Apr 29 10:49:28 raspberrypi apple2driver[392]: panic: failed to open gpio
Apr 29 10:49:28 raspberrypi apple2driver[392]: goroutine 1 [running]:
Apr 29 10:49:28 raspberrypi apple2driver[392]: github.com/tjboldt/Apple2-IO-RPi/RaspberryPi/apple2driver/a2io.A2Gpio.Init({})
Apr 29 10:49:28 raspberrypi apple2driver[392]:         /home/todd/Apple2-IO-RPi/RaspberryPi/apple2driver/a2io/gpio.go:54 +0x3d0
Apr 29 10:49:28 raspberrypi apple2driver[392]: main.main()
Apr 29 10:49:28 raspberrypi apple2driver[392]:         /home/todd/Apple2-IO-RPi/RaspberryPi/apple2driver/driver.go:60 +0x148
Apr 29 10:49:28 raspberrypi systemd[1]: apple2driver.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
Apr 29 10:49:28 raspberrypi systemd[1]: apple2driver.service: Failed with result 'exit-code'.

dkgeorge also had this issue:

Was having the same issue and included the line below the [Service] section of /etc/systemd/system/apple2driver.service

[Service]
ExecStartPre=/bin/sleep 30

This fixed the problem. Apparently apple2driver.service was attempting to start too early during boot.

Hardware Version

Sixth Prototype (lastest classic hardware)

Firmware Version

0010 (classic hardware)

Driver Version

002D (add support for RPi Pico hardware)

Shell Version

000F (classic hardware support)

Where are you seeing this problem?

Boot

What computer is this running on?

Apple //e (enhanced / platinum)

dkgeorge commented 4 months ago

According to How do you make a systemd service as the last service on boot?, adding instead

[Service]
Type=idle

is a more accurate, efficent and faster working solution. I've tested it a few times, and the issue hasn't happened.

tjboldt commented 4 months ago

@dkgeorge I did some digging and it seems there are quite a few dependencies to put into the file if I wanted to add After= so I think your suggestion of Type=idle is best. If you want to show up as a contributor, you could fork, add that line to RaspberryPi/setup.sh in two places and make a pull request. If not, I'll make the change and just add you to the thanks in the readme.

diff --git a/RaspberryPi/setup.sh b/RaspberryPi/setup.sh
index 51de4f8..18e4195 100644
--- a/RaspberryPi/setup.sh
+++ b/RaspberryPi/setup.sh
@@ -58,6 +58,7 @@ sudo --preserve-env=HOME --preserve-env=USER bash -c 'cat > apple2driver.service
 Description=Apple2-IO-RPi Driver (Pico edition)

 [Service]
+Type=idle
 ExecStart=$HOME/Apple2-IO-RPi/RaspberryPi/apple2driver/apple2driver -cdc=true
 StandardOutput=syslog
 StandardError=syslog
@@ -75,6 +76,7 @@ sudo --preserve-env=HOME --preserve-env=USER bash -c 'cat > apple2driver.service
 Description=Apple2-IO-RPi Driver (Classic edition)

 [Service]
+Type=idle
 ExecStart=$HOME/Apple2-IO-RPi/RaspberryPi/apple2driver/apple2driver
 StandardOutput=syslog
 StandardError=syslog
dkgeorge commented 4 months ago

Thanks. Pull request created.

tjboldt commented 4 months ago

Fixed with #177