Skip to content

Commit 67924f1

Browse files
Michal Sidoraalexanderr
authored andcommitted
Add means to control STM power-on from userland
This patch adds a shell script `muxpi-power` which can power the STM on or off. The patch also contains a systemd service that runs `muxpi-power on` during system boot. It is a fairly universal (while there's systemd, there's a way) and convenient (compared to formerly used u-boot script modification) way of powering STM on. Change-Id: Ia96e5ef75bc70a5b25ef34633157939e7f11554a Signed-off-by: Michal Sidor <m.sidor@samsung.com>
1 parent a61026c commit 67924f1

File tree

3 files changed

+83
-0
lines changed

3 files changed

+83
-0
lines changed

sw/nanopi/power/muxpi-power

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
MODE_PIN=203
6+
MODE_NORMAL=0
7+
MODE_FLASHING=1
8+
9+
POWER_PIN=3
10+
POWER_OFF=0
11+
POWER_ON=1
12+
13+
check_gpio_sysfs() {
14+
test -e /sys/class/gpio
15+
}
16+
17+
export_gpio_out() {
18+
GPIO_NUM=$1
19+
test -d "/sys/class/gpio/gpio$GPIO_NUM" \
20+
|| echo "$GPIO_NUM" > /sys/class/gpio/export
21+
echo out > "/sys/class/gpio/gpio$GPIO_NUM/direction"
22+
}
23+
24+
prepare_gpios() {
25+
export_gpio_out $MODE_PIN
26+
export_gpio_out $POWER_PIN
27+
}
28+
29+
gpio_set() {
30+
GPIO_NUM=$1
31+
GPIO_VALUE=$2
32+
echo "$GPIO_VALUE" > "/sys/class/gpio/gpio$GPIO_NUM/value"
33+
}
34+
35+
stm_power_off() {
36+
prepare_gpios
37+
gpio_set $POWER_PIN $POWER_OFF
38+
gpio_set $MODE_PIN $MODE_NORMAL
39+
}
40+
41+
stm_power_on() {
42+
prepare_gpios
43+
gpio_set $POWER_PIN $POWER_OFF
44+
gpio_set $MODE_PIN $MODE_NORMAL
45+
gpio_set $POWER_PIN $POWER_ON
46+
}
47+
48+
stm_flash_mode() {
49+
prepare_gpios
50+
gpio_set $POWER_PIN $POWER_OFF
51+
gpio_set $MODE_PIN $MODE_FLASHING
52+
gpio_set $POWER_PIN $POWER_ON
53+
}
54+
55+
SUBCOMMAND="$1"
56+
case "$SUBCOMMAND" in
57+
"off")
58+
stm_power_off
59+
;;
60+
"on")
61+
stm_power_on
62+
;;
63+
"flashing")
64+
stm_flash_mode
65+
;;
66+
*)
67+
echo "unknown command"
68+
printf "usage: %s {off,on,flashing}\n" "$0"
69+
exit 1
70+
;;
71+
esac
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[Unit]
2+
Description=MuxPi microcontroller power
3+
4+
[Service]
5+
Type=oneshot
6+
ExecStart=/usr/bin/muxpi-power on
7+
ExecStop=/usr/bin/muxpi-power off
8+
RemainAfterExit=yes
9+
10+
[Install]
11+
WantedBy=basic.target

sw/nanopi/stm/systemd/stm.service

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Description=STM RPC
33
Requires=stm-user.socket
44
Requires=stm.socket
5+
Requires=muxpi-power.service
56

67
[Service]
78
ExecStart=/usr/bin/stm -serve

0 commit comments

Comments
 (0)