Table of Contents
Introduction
It can get really irritating having to press reset or boot buttons on development boards!
Often, most or all of it can be automated by using a debugger such as J-Link, however, not everyone has access to a debugger, or there may still be a need to reset other parts of a system, set jumpers, or apply or remove power.
I decided to try using USB from my PC in order to automate things. This is a simple project, but it might come in handy for others too, so I decided to document it. In brief, the method relies on setting spare pins on a USB UART board as outputs, under control of the PC. These outputs can be used to control things like relays. For my application, I didn’t need relays. I needed open collector outputs instead.
The screenshot below shows how it improved my workflow; now, I don’t have to physically touch my dev-board at all. I just hit the up key in the lower-right window and press Enter in order to build the code, and then click in the upper-left window and again press the up key and press Enter to transfer and run the code. The same USB UART board also provides any debug print statements as shown at the upper-right. In my case, all my code and the compiler reside on a Linux box (this is not essential of course), and I do all my work on a Windows PC, but the information in this blog post is compatible with Linux and Mac too. The screenshot below shows code for a Pi Pico, but similar procedures could be used for any other board too.
Reusing a USB UART Board
This project uses a USB UART board that is described here. No changes were made to the board.
Alternatively, a ready-made Sparkfun board can be used.
Open Collector Outputs
The Cypress chip on the USB UART board has normal 3.3V logic outputs. I soldered up a couple of transistors to provide open collector outputs instead:
That’s it in terms of the hardware! The two open collector outputs labeled OUT6 and OUT7 can be wired to any reset or bootloader buttons on the development board.
Driver, Configuration Utility and SDK
The USB UART board can be used as normal with (say) PuTTY or whatever, however to get the GPIO working, a specific driver needs to be installed. Navigate to the CY7C65213 web page, scroll down to Development Tools and download CypressDriverInstaller, and then run it.
Next, download the SDK from the same link. There are SDKs for Windows, Linux, Mac and Android. I used the Windows SDK. The SDK is required because it contains a USB Serial Configuration Utility.
Note that after downloading and installing the driver, it is very important to reboot the PC (I initially didn’t, and the GPIO cannot be controlled although no error is generated. It appears a reboot is essential for things to work).
Plug in the USB UART board into a USB port on the PC, and then run the USB Serial Configuration Utility. Click Select Target then Connect and then click to a tab called BCD/GPIO. Select Unused GPIO drive mode Configure and then set GPIO 06 and GPIO 07 to Drive 0 (this will set the GPIO as outputs defaulted to low level). Click OK, then Program, then Disconnect. It’s all shown in the screenshot below. After that, the Configuration Utility is no longer required. The USB Serial board should be disconnected from the PC and then reconnected.
GPIO Control Software
I used the SDK, and Visual Studio, to edit an existing sample program, to create a general-purpose GPIO output controller. The final Windows executable called gpio.exe, and the source code for the single file that I modified, is at the cy7c65213_gpio GitHub page. The executable can be used directly (i.e. there is no need to download Visual Studio or to compile/build anything) if the functionality meets your needs. If you want to do custom stuff, then the gpio.cpp code can be inspected; it’s fairly straightforward to understand it. If you’re using Linux or Mac, then you’ll need to create and build your own executable, but hopefully the gpio.cpp file can be used as a reference since the API for the CY7C65213 chip will look identical.
The executable is called gpio.exe, and the syntax is:
gpio.exe <output|input> <gpionumber> <0|1> <msec>
The first parameter needs to be set to the text output because input is not currently supported by the code. The second parameter is set to either 6 or 7, to control the IO6 or IO7 pins on the CY7C65213 chip respectively.
Here’s an example where the open collector attached to IO6 is temporarily pulled low for 100 msec:
gpio.exe output 6 1 100
gpio exe output 6 0 100
Note that the value 1 refers to logic level high (3.3V) from the CY7C65213 chip, which corresponds to the open collector being pulled low.
An Example Application: Pi Pico
The Pi Pico has a Run (reset) pin, and it has a bootloader button. In order to put code onto the Pico, the usual procedure is to hold down the bootloader button, then briefly pull the reset pin low, and then after the reset pin has been pulled up or disconnected, then the bootloader button can be released after a second or so. To automate this, I connected OUT6 to the bootloader button and OUT7 to the reset pin (and the ground connection was made too of course).
Next, I wrote a file called pico_deploy_auto.bat containing the following:
@echo off
echo Setting Pico into Boot Mode..
CD "C:\development\gpio"
gpio.exe output 6 1 100
gpio.exe output 7 1 100
gpio.exe output 7 0 1000
gpio.exe output 6 0 3000
The code performs the bootloader/reset combination, and then waits three seconds for the Pico drive letter to appear, ready for uploading code.
Note that you could extend the file to automatically transfer your code to the Pico too. In my case, I build Pico software on a Linux box, so I would need to SFTP it to my Windows laptop first. All of that can be automated as shown here.
Firstly, append the following to the batch file, to occur after the GPIO commands:
CD "C:\Program Files (x86)\WinSCP"
WinSCP.com /script=c:\development\winscp_script_proj1.txt
Next, create a file called winscp_script_proj1.txt containing:
option echo off
option batch on
option confirm off
open sftp://myusername:mypassword@192.168.x.x
lcd "D:"
cd "development/proj1/build"
get proj1.uf2
exit
You’ll need to edit the file, for it to make sense for your project and environment. Install WinSCP onto your PC.
Now you can automatically set up the Pico into boot mode and transfer the code from the Linux server onto the Pico, all with one command, as shown in the screenshot at the start of this blog.
Summary
This very simple project makes life a bit easier when working with hardware that needs signals for reset or boot modes and so on. It reuses the USB UART board so that the same hardware that provides serial UART debug can also be used for control of the signals.
Thanks for reading!