Hyperterminal -> GNU Screen

Posted on Jan 19, 2022

⬅️ Back to Intro

⬅️ Prev Post Next Post ➡️

Hyperterminal is used to communicate with the soft-core CPU via a UART connection.
A popular Linux alternative is GNU Screen. In this post I’ll use Screen to send and receive data.

Discovery

The first step is to find out which device file is associated with the USB to TTL Adapter. If you have no other serial devices connected, then it will probably be /dev/ttyUSB0.

The adapters that come with the CPEN 412 kit seem to use either an FTDI or Silicon Labs chip, so we’re looking for either of those names to pop up.

After plugging in your device, you can run the following command:

$ ls /dev/serial/by-id/

usb-Silicon_Labs_CP2102_USB_to_UART_Bridge_Controller_0001-if00-port0

In my case, I’ve got the Silicon Labs chip. You can then deference the link by running realpath on the output of the last command:

$ cd /dev/serial/by-id/
$ realpath usb-Silicon_Labs_CP2102_USB_to_UART_Bridge_Controller_0001-if00-port0

/dev/ttyUSB0

Turns out it’s ttyUSB0.

Connecting

At this point, we can connect to the adapter using Screen:

$ screen /dev/ttyUSB0 115200 -fn

DE1-68k Bug V1.77
Copyright (C) PJ Davies 2016
#

After pressing the reset button on the De1, we receive the soft CPU’s welcome message. We can now send commands.

  • 115200 is the baud rate
  • -fn tells Screen to turn off flow control

The above settings were determined using the Hyperterminal Pre-Lab handout.
Note: To exit Screen hit Ctrl+A then colon and type “quit”.

Sending Programs

Hyperterminal’s other main function is to send .hex program files to the CPU’s memory. This is possible with Screen, but it is a little clunky.

First, while inside Screen, hit Ctrl+A then colon and type the following:

# Screen session is already active
# Hit Ctrl+A then colon and type:
readreg p /home/ano/c412/hello_world.hex

This reads the contents of the hello_world.hex into Screen’s p software register (Nothing to do with the hardware). You can think of it as a staging area.
Note that the path to the .hex file must be an absolute path.

Next, while in the CPU prompt, type “l”. This is the load command

DE1-68k Bug V1.77
Copyright (C) PJ Davies 2016
$ l

Download Program to Memory....<ESC> to Cancel
Waiting for Laptop to send '.HEX' file:

Then hit Ctrl+A again and type the following

# Screen session is already active
# Hit Ctrl+A then colon and type:
paste p

This will paste the contents of the hello_world.hex into the prompt. Because the soft CPU is in load mode, it will interpret the data as a program code and store it.

If it immediately fails, it probably because the soft CPU cannot keep up with how fast the host computer is sending the data.

To slow the sending down, hit Ctrl+A and type the following

# Screen session is already active
# Hit Ctrl+A then colon and type:
slowpaste 10

This forces Screen to wait 10ms after sending every byte. This turns out to be quite slow, so reduce it until it stops working again.

Once you have a working value, you can append it to ~/.screenrc to make it permanent.

# ~/.screenrc
slowpaste 5

⬅️ Prev Post Next Post ➡️