Screen and Linux tips

I normally use the Linux utility screen to connect to my BusPirate. I have two tips

  1. While connecting to the BP, if you want to scroll back the terminal history (i.e. to see the help menu), press "Control-A ESCAPE - and then you can use the up-arrow and down-arrow to scroll the display.
  2. Here is a trivial script I use with screen. It reminds me if the BusPirate is unplugged or in bootloader mode.
#!/bin/sh
# Launch BusPirate using screen
#Usage:
#       BusPirate
#       BusPirate /dev/ttyACM2 - if it's on a different port
TT=${1:-"/dev/ttyACM0"} # default port
# You have to change this to match your ID
ID=5021-0000
#Is it in bookloader mode?
if [ -d /media/$USER/RPI-RP2 ]
then
    echo "Unplug and replug the BusPirate"
elif [ -d /media/$USER/$ID/ ]
then
    # Looks good
    screen "$TT" 115200
else
    # What? No Bus Pirate?!?!
    echo "Please plug in your Bus Pirate"
fi
1 Like

Typo! Bootloader not bookloaderšŸ˜‹

2 Likes

I love a good script!

Iā€™d like to make a script that watches the bus pirate firmware file for changes (python watchman?), then sends bootloader code to Bus Pirate binary interface. Watch for the USB drive to attach, copy the firmware.

I think it will be faster than the debugger when I donā€™t need to step code.

Iā€™m using screen to connect to BP v5, did you manage to get colors on the terminal? Iā€™m using MacOS with iTerm2.

Iā€™m not sure about screen, but iTerm2 seems to support VT100-like escape commands. They recommend using them in their faq page to test boldness.

Yep, iTerm2 works great, but connecting to serial using screen doesnā€™t work.

I made it work using pyserial miniterm:

Command line:

python -m serial.tools.miniterm --raw /dev/tty.usbmodem1234567890121 115200

2 Likes

While screen is an excellent tool, Iā€™d highly recommend checking out tio, which is a serial terminal emulator specifically designed for hardware hacking/development:

It has a lot of nice features, such as defaulting to 115200 8n1 and gracefully reconnecting when a serial device goes down and comes back up (like when updating the firmware on the BP5). It also offers a remapping function which can fix some of the unusual behaviors the BP exhibits under different platforms (such as backspace not working).

In the config file, you can even setup profiles for different devices. Mine looks like this:

# Config file for tio serial terminal emulator

[bp5]
device = /dev/ttyACM0
map = INLCRNL,ODELBS

[bp3]
device = /dev/ttyUSB0
map = INLCRNL,ODELBS

This lets me connect to either the v5 or v3 Bus Pirate by simply running:

tio bp5

or

tio bp3
5 Likes

Thanks for the tip. Iā€™ll check it out.

Hmm. I Installed tio and used your config file. When I connect to the BP I get no response to anything I type. Is that your entire config file?
[edit]
tio /dev/ttyACM0
works fineā€¦

Aha. The standard tio installed via apt was an old rev. I had to uninstall tio, install meson, and install tio from the github source, and make sure /usr/local/bin was in my searchpath.

BTW, the toolbar display is much nicer looking than screen. I might just be a convert!

I should have been suspicious when I typed ā€œman tioā€ and there was no mention of the config file.

Which version of tio do you have now? I was/am still using screen but considering converting my faith when its good replacement

Also I would suggest some udev rules that make /dev/buspirate3 and /dev/buspirate5 for example. In case you have more ttys in your system. Mentioned here:

https://wiki.archlinux.org/title/Bus_Pirate

The version of tio that Ubuntu installed was 1.2
The Github version is 2.8

tio also allows you to use the device ID, i.e.
/dev/serial/by-id/usb-Bus_Pirate_Bus_Pirate_5_123456789012-if00

I thought that I could use this to automatically distinguish between my rev8 and rev10, but they have the same ID. They have the same serial # as well. I wonder if Ian is going to assign unique serial numbers to them in the future. [edited]

tio can also remap the DEL/BACKSPACE/CONTROL-H keys. I think screen can do this, but i didnā€™t see an obvious way to do it. The man page for tio is 480 lines, which for screen itā€™s 3278 lines long.

So I switched to tio. Thank you for this suggestion. Now the colors are correct and its easier to scroll up.

Now I have bash aliases for buspirate3 and buspirate5 :slight_smile:

3 Likes

I second the tio recommendation! :slight_smile:

I was looking through the main documentation for more information on BusPirate attached to a pi running Debian. I am using a pi and the GPIO header while developing code for SPI devices and BusPirate in SPI sniff mode is the goto for watching the more complex exchanges. I have normally attached the BP5 to a Mac but I wanted to run the whole thing off the Pi as the code is developed in CLion remotely to the pi and it all seemed a bit crazy to need so many computers in the Dev environment.

Whilst lsusb will show you if the BP5 is attached to the pi, I came across a useful script here: [usb - command to determine ports of a device (like /dev/ttyUSB0) - Unix & Linux Stack Exchange](https://scan usb dev entries)
for determining the device dev entries.

#!/bin/bash

for sysdevpath in $(find /sys/bus/usb/devices/usb*/ -name dev); do
    (
        syspath="${sysdevpath%/dev}"
        devname="$(udevadm info -q name -p $syspath)"
        [[ "$devname" == "bus/"* ]] && exit
        eval "$(udevadm info -q property --export -p $syspath)"
        [[ -z "$ID_SERIAL" ]] && exit
        echo "/dev/$devname - $ID_SERIAL"
    )
done

At the risk of responding to a very old postā€¦

The current firmware uses a unique per-CPU serial number in the USB Device Descriptor. IIRC, this means the above request is now resolved. :slight_smile:

If you want to view the commits, they are from last June / early July:

  • 56a07f621bf3faeed3e3ca8d1e6852ae26a1b9b4 - 2024-05-24 - USB serial number from MCU serial number
  • 7ac39b72e82e70b448e21b0e6524438e1e5f7092 - 2024-06-04 - reverse byte order to match MCU serial number displayed by info commandā€¦