STEP-4 : Setting up the Start-up Script and make active at boot-up
Copy and Pase following lines in "init_boot.sh" file - Download
#!/bin/bash
echo 5 > /sys/class/gpio/export
echo 33 > /sys/class/gpio/export
echo 65 > /sys/class/gpio/export
echo 115 > /sys/class/gpio/export
export SLOTS=/sys/devices/bone_capemgr.8/slots
echo GPIO-Test > $SLOTS
root@beaglebone:# vi /lib/systemd/init_boot.service- In order to work with device tree overlay what we have created in previous step, we need to write a start-up script.
- The C code we are going to use is have some issues with GPIO ports like "Bus Error" when the compiled file is executed.
- Based on this website the issue got resolved when we export one pin on each GPIO port. So this we need to add it on start-up script.
- This start-up script will be executed every time the Beaglebone Black is started.
- Make a start-up script with the following steps:
Copy and Pase following lines in "init_boot.sh" file - Download
#!/bin/bash
echo 5 > /sys/class/gpio/export
echo 33 > /sys/class/gpio/export
echo 65 > /sys/class/gpio/export
echo 115 > /sys/class/gpio/export
export SLOTS=/sys/devices/bone_capemgr.8/slots
echo GPIO-Test > $SLOTS
- To save and exit the file press "Esc" type ":wq" and Enter.
- Now start-up script is ready to make active at booting process.
- To make start-up script active at booting process, make a service with the following lines:
[Unit]
Description=Enable GPIO Pins
After=syslog.target network.target
[Service]
Type=simple
ExecStart=/usr/bin/init_boot.sh
[Install]
WantedBy=multi-user.target
- To save and exit the file press "Esc" type ":wq" and Enter.
- Make a symbolic link
root@beaglebone:# cd /etc/systemd/system/
root@beaglebone:# ln /lib/systemd/init_boot.service init_boot.service
root@beaglebone:# ln /lib/systemd/init_boot.service init_boot.service
- Make systemd take notice of it, activate the service immediately and enable the service to be started on boot-up
root@beaglebone:# systemctl daemon-reload
root@beaglebone:# systemctl start init_boot.service
root@beaglebone:# systemctl enable init_boot.service
root@beaglebone:# systemctl start init_boot.service
root@beaglebone:# systemctl enable init_boot.service
- Now the start-up script is active.
- To check whether start-up script is active restart the beaglebone black.
- Run following commands:
root@beaglebone:# ls -al /sys/class/gpio
root@beaglebone:# ls -al /sys/class/gpio/total 0
drwxr-xr-x 2 root root 0 Jan 1 05:00 .
drwxr-xr-x 48 root root 0 Jan 1 05:00 ..
--w------- 1 root root 4096 Jan 1 05:00 export
lrwxrwxrwx 1 root root 0 Jan 1 11:30 gpio115 -> ../../devices/virtual/gpio/gpio115
lrwxrwxrwx 1 root root 0 Jan 1 11:30 gpio33 -> ../../devices/virtual/gpio/gpio33
lrwxrwxrwx 1 root root 0 Jan 1 11:30 gpio5 -> ../../devices/virtual/gpio/gpio5
lrwxrwxrwx 1 root root 0 Jan 1 11:30 gpio65 -> ../../devices/virtual/gpio/gpio65lrwxrwxrwx 1 root root 0 Jan 1 05:00 gpiochip0 -> ../../devices/virtual/gpio/gpiochip0
lrwxrwxrwx 1 root root 0 Jan 1 05:00 gpiochip32 -> ../../devices/virtual/gpio/gpiochip32
lrwxrwxrwx 1 root root 0 Jan 1 05:00 gpiochip64 -> ../../devices/virtual/gpio/gpiochip64
lrwxrwxrwx 1 root root 0 Jan 1 05:00 gpiochip96 -> ../../devices/virtual/gpio/gpiochip96
--w------- 1 root root 4096 Jan 1 05:00 unexport
drwxr-xr-x 2 root root 0 Jan 1 05:00 .
drwxr-xr-x 48 root root 0 Jan 1 05:00 ..
--w------- 1 root root 4096 Jan 1 05:00 export
lrwxrwxrwx 1 root root 0 Jan 1 11:30 gpio115 -> ../../devices/virtual/gpio/gpio115
lrwxrwxrwx 1 root root 0 Jan 1 11:30 gpio33 -> ../../devices/virtual/gpio/gpio33
lrwxrwxrwx 1 root root 0 Jan 1 11:30 gpio5 -> ../../devices/virtual/gpio/gpio5
lrwxrwxrwx 1 root root 0 Jan 1 11:30 gpio65 -> ../../devices/virtual/gpio/gpio65lrwxrwxrwx 1 root root 0 Jan 1 05:00 gpiochip0 -> ../../devices/virtual/gpio/gpiochip0
lrwxrwxrwx 1 root root 0 Jan 1 05:00 gpiochip32 -> ../../devices/virtual/gpio/gpiochip32
lrwxrwxrwx 1 root root 0 Jan 1 05:00 gpiochip64 -> ../../devices/virtual/gpio/gpiochip64
lrwxrwxrwx 1 root root 0 Jan 1 05:00 gpiochip96 -> ../../devices/virtual/gpio/gpiochip96
--w------- 1 root root 4096 Jan 1 05:00 unexport
To check the device tree overlay is loaded:
root@beaglebone:# cat /sys/devices/bone_capemgr.8/slots
root@beaglebone:# cat /sys/devices/bone_capemgr.8/slots
root@beaglebone:/lib/firmware# cat $SLOTS
0: 54:PF---
1: 55:PF---
2: 56:PF---
3: 57:PF---
4: ff:P-O-- Bone-LT-eMMC-2G,00A0,Texas Instrument,BB-BONE-EMMC-2G
5: ff:P-O-- Bone-Black-HDMI,00A0,Texas Instrument,BB-BONELT-HDMI
6: ff:P-O-- Bone-Black-HDMIN,00A0,Texas Instrument,BB-BONELT-HDMIN
7: ff:P-O-L Override Board Name,00A0,Override Manuf,GPIO-Test
- It is loaded on 7th slot.