Skip to content

UART Replacement

Robin Verhagen-Guest edited this page Mar 22, 2024 · 24 revisions

UARTReplacement is a configurable plugin for the CSpect emulator, which replaces the internal CSpect emulated ESP and Raspberry Pi Accelerator UARTs.

The replacement UARTs write binary bytes to the serial port, whereas the internal CSpect UARTs constrain bytes to ASCII characters 0x00..0x3f. This doesn't matter so much for sending AT commands to the ESP-01, but programming the ESP with low-level SLIP commands requires a binary UART. Also the NextPi SUPervisor uses non-ASCII control bytes.

The UARTs dynamically respond to baud rate changes written to the Next's UART I/O ports, using prescaler calculations taking into account the current video timing.

The UARTs also drive the serial DTR and RTS lines in response to ESP RST and GPIO enable and control nextregs; and Pi GPIO enable and control nextregs. This is required for ESP boot mode selection, and for a proposed NextPi GPIO protocol to control the SUPervisor and applications when the UART is otherwise engaged.

Installation

You must be running CSpect version 2.19.4.4, or newer. The latest version of CSpect is always available to download here.

The latest tested version of the plugin is always available at the releases page.

Download the CSpectPlugins.zip file, then extract the UARTReplacement.dll and UARTReplacement.dll.config files. Exit CSpect, then copy these into your CSpect directory (the one which contains CSpect.exe).

CSpect is supplied with some plugins preinstalled. If your CSpect installation already has these two files, skip to the Configuration section unless you wish to update to the latest plugin version.

Restart CSpect to enable the plugin.

If you're using this plugin, do not start CSpect with the -com or -com2 arguments.

Uninstallation

To uninstall, exit CSpect and delete the UARTReplacement.dll file from the CSpect directory.

Configuration

The plugin can be configured by editing the UARTReplacement.dll.config file in your favourite text editor. Always restart CSpect after changing the configuration. You may configure these settings:

EspPortName

Set this to the name of the serial port you are using on your host operating system to talk to the ESP, for example COM3 or /dev/ttyS0.

The default value is COM1.

PiPortName

Set this to the name of the serial port you are using on your host operating system to talk to the Pi, for example COM52 or /dev/ttyS1.

The default value is COM2.

PiMapGpio4And5ToDtrAndRtsEnable

Set this to True if you want writes to Pi GPIO pin 4 to drive the serial port DTR line, and writes to Pi GPIO pin 5 to drive the serial port RTS line.

The default value is False.

Serial Port Exclusive Use

CSpect can operate in two modes. The default mode internally emulates a cut-down ESP-01 directly, without using a serial port. The passthrough mode uses the -com argument on the CSpect command line to specify a PC serial port to pass the UART traffic to, for example -com="COM1:115200".

CSpect passthrough mode and this plugin both require exclusive use of the serial port in order to operate, and CSpect passthrough mode locks the port for exclusive use before the plugin initiates. Therefore you should also use this plugin in default mode, without specifying a -com argument on the CSpect command line. Always specify the PortName in the UARTReplacement.dll.config file instead.

Baud Rate

The routine for the prescaler baud calculations does an integer division: clock rate / prescaler value, using truncation instead of rounding. For example, using HDMI timings the plugin calculation for 115200 baud is 27000000 / 234 = 115384 baud.

In practice, this is what is most likely to work, as the ESP-01 effectively uses a similar calculation in its divider chain circuit. Issuing these commands:

AT+UART_CUR=115200,8,1,0,0
AT+UART_CUR?

also reports 115384 baud. (Note that AT+UART_CUR? is only available on more recent ESP firmwares, but older firmwares also operate the divider chain in the same way.)

Clone this wiki locally