Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8586a25547 | |||
| aa83f5c957 | |||
| 9f51718235 | |||
| 01b3a189ed | |||
| 3ef2ca02a6 |
+22
-7
@@ -3,20 +3,31 @@
|
||||
# "Using OTG mode on Raspberry Pi SBCs"
|
||||
# https://pip-assets.raspberrypi.com/categories/685-app-notes-guides-whitepapers/documents/RP-009276-WP/Using-OTG-mode-on-Raspberry-Pi-SBCs
|
||||
|
||||
# Is the dwc2 overlay installed? Nothing will work if it isn't.
|
||||
LOGGER="systemd-cat -t gadget.sh"
|
||||
if lsmod | grep -q "dwc2"; then
|
||||
$LOGGER -p info "DWC2 module loaded, setting up OTG gadget serial and ethernet"
|
||||
else
|
||||
$LOGGER -p warning "DWC2 module missing. Aborting OTG setup"
|
||||
# This script only works if you are running it as root
|
||||
if [ $(id -u) -ne 0 ]; then
|
||||
echo "Please run as root or use sudo"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
# Is the dwc2 overlay installed? Nothing will work if it isn't.
|
||||
if lsmod | grep -q "dwc2"; then
|
||||
systemd-cat -t gadget.sh -p info echo "DWC2 module loaded, setting up OTG gadget serial and ethernet"
|
||||
else
|
||||
systemd-cat -t gadget.sh -p warning echo "DWC2 module missing. Aborting OTG setup."
|
||||
systemctl disable serial-getty@ttyGS0.service
|
||||
exit 1
|
||||
fi
|
||||
|
||||
sudo modprobe libcomposite
|
||||
cd /sys/kernel/config/usb_gadget
|
||||
if [ -d "MyGadget" ]; then
|
||||
systemd-cat -t gadget.sh -p warning echo "MyGadget already exists. Aborting OTG setup."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Create our new gadget
|
||||
sudo mkdir MyGadget
|
||||
mkdir MyGadget
|
||||
cd MyGadget
|
||||
# Add some boilerplate data that the gadget needs
|
||||
echo 0x1d6b > idVendor # Linux Foundation’s USB VID. Replace with your own VID if required
|
||||
@@ -41,6 +52,7 @@ echo "Config 1" > configs/c.1/strings/0x409/configuration
|
||||
### Remember to create the storage block device first
|
||||
## cd /root
|
||||
### Example: Make a 256 MB file to act as "USB stick"
|
||||
## Only create it once or it will delete the previous content
|
||||
## sudo dd if=/dev/zero of=drive.bin bs=1M count=256
|
||||
### Create a VFAT file system on the backing store
|
||||
## sudo mkfs.vfat drive.bin
|
||||
@@ -64,3 +76,6 @@ ln -s functions/ecm.usb0 configs/c.1/
|
||||
## USB Device Controller update
|
||||
UDC=`ls /sys/class/udc`
|
||||
echo $UDC > UDC
|
||||
|
||||
# Enable the gettys
|
||||
systemctl enable serial-getty@ttyGS0.service
|
||||
|
||||
Executable
+19
@@ -0,0 +1,19 @@
|
||||
#!/usr/bin/python
|
||||
# From https://raspberry.tips/en/raspberrypi-tutorials/raspberry-pi-gpio-python
|
||||
import lgpio
|
||||
import time
|
||||
|
||||
# Open GPIO chip (0 = /dev/gpiochip0, on Pi 5 gpiochip4 also possible)
|
||||
h = lgpio.gpiochip_open(0)
|
||||
|
||||
try:
|
||||
lgpio.gpio_claim_output(h, 18) # GPIO18 (pin 12) as output (MOTA1)
|
||||
|
||||
for _ in range(5):
|
||||
lgpio.gpio_write(h, 18, 1) # HIGH
|
||||
time.sleep(0.5)
|
||||
lgpio.gpio_write(h, 18, 0) # LOW
|
||||
time.sleep(0.5)
|
||||
|
||||
finally:
|
||||
lgpio.gpiochip_close(h) # Always close!
|
||||
Executable
+25
@@ -0,0 +1,25 @@
|
||||
#!/usr/bin/python
|
||||
# From https://raspberry.tips/en/raspberrypi-tutorials/raspberry-pi-gpio-python
|
||||
import lgpio
|
||||
import time
|
||||
|
||||
# Open GPIO chip (0 = /dev/gpiochip0, on Pi 5 gpiochip4 also possible)
|
||||
h = lgpio.gpiochip_open(0)
|
||||
|
||||
try:
|
||||
lgpio.gpio_claim_output(h, 16) # GPIO16 as output (MOTA2)
|
||||
lgpio.gpio_write(h, 16, 0) # LOW
|
||||
|
||||
# Hardware PWM on GPIO18 (pin 12) must be PWM-capable
|
||||
# Frequency: 1000 Hz, duty cycle: 50%
|
||||
lgpio.tx_pwm(h, 18, 1000, 50)
|
||||
time.sleep(2)
|
||||
|
||||
# Reduce duty cycle to 20%
|
||||
lgpio.tx_pwm(h, 18, 1000, 20)
|
||||
time.sleep(2)
|
||||
|
||||
lgpio.tx_pwm(h, 18, 0, 0) # Stop PWM
|
||||
|
||||
finally:
|
||||
lgpio.gpiochip_close(h) # Always close!
|
||||
Reference in New Issue
Block a user