|
| 1 | +## Create file `/usr/bin/enable-i2c-pins.sh` |
| 2 | + **sudo vi /usr/bin/enable-i2c-pins.sh** |
| 3 | +``` |
| 4 | +#!/bin/bash |
| 5 | +
|
| 6 | +config-pin p9.17 i2c |
| 7 | +config-pin p9.18 i2c |
| 8 | +``` |
| 9 | +**sudo chmod 755 /usr/bin/enable-i2c-pins.sh** |
| 10 | + |
| 11 | +## Create file `/lib/systemd/system/enable-i2c-pins.service` |
| 12 | +**sudo vi /lib/systemd/system/enable-i2c-pins.service** |
| 13 | +``` |
| 14 | +[Unit] |
| 15 | +Description=Enable I2C pins |
| 16 | +After=generic-board-startup.service |
| 17 | +
|
| 18 | +[Service] |
| 19 | +Type=simple |
| 20 | +ExecStart=/usr/bin/enable-i2c-pins.sh |
| 21 | +
|
| 22 | +[Install] |
| 23 | +WantedBy=multi-user.target |
| 24 | +``` |
| 25 | +## Enable the new systemd service |
| 26 | +**sudo systemctl daemon-reload** |
| 27 | +**sudo systemctl enable enable-i2c-pins.service** |
| 28 | +``` |
| 29 | +Created symlink /etc/systemd/system/multi-user.target.wants/enable-i2c-pins.service → /lib/systemd/system/enable-i2c-pins.service. |
| 30 | +``` |
| 31 | + |
| 32 | +## Reboot and test |
| 33 | +**sudo systemctl status enable-i2c-pins.service** |
| 34 | +``` |
| 35 | +debian@beaglebone:~$ sudo systemctl status enable-i2c-pins.service |
| 36 | +● enable-i2c-pins.service - Enable I2C pins |
| 37 | + Loaded: loaded (/lib/systemd/system/enable-i2c-pins.service; enabled) |
| 38 | + Active: inactive (dead) since Wed 2017-04-19 06:35:06 UTC; 48s ago |
| 39 | + Process: 649 ExecStart=/usr/bin/enable-i2c-pins.sh (code=exited, status=0/SUCCESS) |
| 40 | + Main PID: 649 (code=exited, status=0/SUCCESS) |
| 41 | +
|
| 42 | +Apr 19 06:35:05 beaglebone sudo[664]: root : TTY=unknown ; PWD=/ ; USER=root ; COMMAND=/bin/bash -c echo i2c > /sys/devices/platform/ocp/ocp:P9_17_pinmux/state |
| 43 | +Apr 19 06:35:05 beaglebone sudo[664]: pam_unix(sudo:session): session opened for user root by (uid=0) |
| 44 | +Apr 19 06:35:05 beaglebone sudo[664]: pam_unix(sudo:session): session closed for user root |
| 45 | +Apr 19 06:35:06 beaglebone sudo[677]: root : TTY=unknown ; PWD=/ ; USER=root ; COMMAND=/bin/bash -c echo i2c > /sys/devices/platform/ocp/ocp:P9_18_pinmux/state |
| 46 | +Apr 19 06:35:06 beaglebone sudo[677]: pam_unix(sudo:session): session opened for user root by (uid=0) |
| 47 | +Apr 19 06:35:06 beaglebone sudo[677]: pam_unix(sudo:session): session closed for user root |
| 48 | +``` |
| 49 | + |
| 50 | +**config-pin -q p9.17 && config-pin -q p9.18** |
| 51 | +``` |
| 52 | +debian@beaglebone:~$ config-pin -q p9.17 && config-pin -q p9.18 |
| 53 | +P9_17 Mode: i2c |
| 54 | +P9_18 Mode: i2c |
| 55 | +``` |
0 commit comments