Skip to content

Commit

Permalink
detect if running on RPi4 or RPi5 in flashing script
Browse files Browse the repository at this point in the history
  • Loading branch information
DominikN committed Aug 5, 2024
1 parent cb555cc commit 727d96f
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions rosbot_utils/rosbot_utils/flash-firmware.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python3
#!/usr/bin/env python3

# Copyright 2024 Husarion sp. z o.o.
#
Expand All @@ -25,6 +25,20 @@
import gpiod
import sh

def get_raspberry_pi_model():
try:
with open("/proc/cpuinfo", "r") as f:
for line in f:
if "Model" in line:
model_info = line.split(":")[1].strip()
if "Raspberry Pi 4" in model_info:
return "Raspberry Pi 4"
elif "Raspberry Pi 5" in model_info:
return "Raspberry Pi 5"
else:
return "Unknown Raspberry Pi Model"
except FileNotFoundError:
return "Not a Raspberry Pi"

class FirmwareFlasher:
def __init__(self, sys_arch, binary_file):
Expand Down Expand Up @@ -53,12 +67,19 @@ def __init__(self, sys_arch, binary_file):

elif self.sys_arch == "aarch64":
# Setups RPi pins
print("Device: RPi\n")
model = get_raspberry_pi_model()
print(f"Device: {model}\n")
self.serial_port = "/dev/ttyAMA0"
gpio_chip = "/dev/gpiochip0"

if model == "Raspberry Pi 4":
gpio_chip = "/dev/gpiochip0"
elif model == "Raspberry Pi 5":
gpio_chip = "/dev/gpiochip4"
else:
gpio_chip = "/dev/gpiochip0" # Default or error handling

boot0_pin_no = 17
reset_pin_no = 18

else:
print("Unknown device...")

Expand Down

0 comments on commit 727d96f

Please sign in to comment.