blob: 53ab64523542f57da07270093788b96842c1b78f [file] [log] [blame]
David Lattimorebedd66a2021-09-10 13:36:05 +10001#!/usr/bin/env python3
2
3# Copyright 2021 The Chromium OS Authors. All rights reserved.
4# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6
7# Turns the HPS off then back on again. This is useful after flashing the HPS
8# MCU for the first time, or after running a factory test in order to get back
9# to the system bootloader (provided the MCU flash is empty).
10
11from pyftdi.gpio import GpioAsyncController
12import time
David Lattimore567b1282021-10-21 10:01:33 +110013import argparse
14
15parser = argparse.ArgumentParser(description='HPS dev board controller')
16parser.add_argument(
17 '--write-protect', action='store_true',
18 help='Enable write protect.')
19args = parser.parse_args()
David Lattimorebedd66a2021-09-10 13:36:05 +100020
21gpio = GpioAsyncController()
David Lattimore567b1282021-10-21 10:01:33 +110022power_pin = 1 << 6
23write_protect_pin = 1 << 4
24direction = power_pin
25# Both power enable and firmware write-protect have pull-up resistors, so we set
26# them low by making the pins outputs and pulling them low, but we set them high
27# by making them inputs and letting the pull-ups do their work.
28if not args.write_protect:
29 direction |= write_protect_pin
30gpio.configure('ftdi://ftdi:ft4232/1', direction=direction, initial=0)
David Lattimorebedd66a2021-09-10 13:36:05 +100031time.sleep(0.1)
32# Set GPIO pin 6 back to being an input. It'll get pulled high by the pull-up
33# resistor (power on).
David Lattimore567b1282021-10-21 10:01:33 +110034gpio.set_direction(power_pin, 0)