David Lattimore | bedd66a | 2021-09-10 13:36:05 +1000 | [diff] [blame] | 1 | #!/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 | |
| 11 | from pyftdi.gpio import GpioAsyncController |
| 12 | import time |
David Lattimore | 567b128 | 2021-10-21 10:01:33 +1100 | [diff] [blame^] | 13 | import argparse |
| 14 | |
| 15 | parser = argparse.ArgumentParser(description='HPS dev board controller') |
| 16 | parser.add_argument( |
| 17 | '--write-protect', action='store_true', |
| 18 | help='Enable write protect.') |
| 19 | args = parser.parse_args() |
David Lattimore | bedd66a | 2021-09-10 13:36:05 +1000 | [diff] [blame] | 20 | |
| 21 | gpio = GpioAsyncController() |
David Lattimore | 567b128 | 2021-10-21 10:01:33 +1100 | [diff] [blame^] | 22 | power_pin = 1 << 6 |
| 23 | write_protect_pin = 1 << 4 |
| 24 | direction = 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. |
| 28 | if not args.write_protect: |
| 29 | direction |= write_protect_pin |
| 30 | gpio.configure('ftdi://ftdi:ft4232/1', direction=direction, initial=0) |
David Lattimore | bedd66a | 2021-09-10 13:36:05 +1000 | [diff] [blame] | 31 | time.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 Lattimore | 567b128 | 2021-10-21 10:01:33 +1100 | [diff] [blame^] | 34 | gpio.set_direction(power_pin, 0) |