Simulate Serial Communication Application
This page describes how to setup serial port in RTEMS and VMWare in order to simulate RTEMS serial communication application in VMWare running on Windows.
As mentioned in QEMU and USB, simulator is useful in developing USB support in RTEMS. So hopefully this page might also be helpful for someone to use VMWare as an aid to develop new RTEMS device drivers (USB, new gigabit ethernet, etc).
Serial Port Hardware Setup
Sometimes there is no built-in serial port in modern PCs especially notebooks. Here a notebook with a serial PCMCIA card and USB Serial Converter is used. A null modem cable connects these 2 ports together.
The serial PCMCIA card is the one we're going to access in RTEMS application. Any type of serial port can be used on the other end of the wire.
The base I/O addresses of COM1 and COM2 are defined in libbsp/i386/shared/comm/uart.h as the following:
#define COM1_BASE_IO 0x3F8 #define COM2_BASE_IO 0x2F8
Unlike traditional serial ports, the base address of serial PCMCIA card is not 0x3F8 or 0x2F8. This mismatched base address presents a challenge, and casts doubt about whether the whole thing would work or not.
As shown above, it shows up as a PCI serial port at 0xFEE8 with IRQ 16.
BTW, you can use advanced port setting page to re-assign port number, e.g., from COM15 to COM3. (Refer to http://www.windmill.co.uk/usb-serial.html for details) This is useful since when adding serial port, sometimes VMWare provides you with only one choice: COM3.
Enable COM1 in RTEMS
One of our basic goals is to make the following 3 API work:
int fd = open("/dev/ttyS1", ...); write(fd, ...); read(fd, ...);
The 1st error I encountered was that /dev/ttyS1 was not found. The following shows one way to enable COM1 through configuration:
#define CONFIGURE_APPLICATION_EXTRA_DRIVERS TTY1_DRIVER_TABLE_ENTRY
Configure Serial Port in VMWare
After searching over internet and trying out many configurations, here are the steps which worked.
Let's assume we continue from the last step of MinGW:Grub2:VMWare Development Environment Setup.
Add Serial Port
Click on Add Hardware in Commands panel, and choose Serial Port:
Enable Serial Port
The newly added serial port might not be enabled, especially when your serial PCMCIA card is installed after serial port is added in VMWare.
Click on Configure VM in Commands panel, go to Power tab, and check the box under BIOS setup:
Power up the VM, go to Advanced | I/O Device Configuration, and enable COM1 and COM2. Make sure base I/O addresses match what're in the above uart.h.
Later on we check if the serial port is enabled by clicking on the serial port icon in the bottom right corner of VMWare Remote Console.
For a quick test, we can replace init.c in sample hello test program directory with a Simple Serial and Shell Test Program, build ISO image, and test it in VMWare.
As shown above, the RTEMS application in VMWare successfully communicated with a HyperTerminal in Windows. The existence of /dev/ttyS1 is also shown in RTEMS Shell.
It seems that VMWare put a bridge between virtual COM1 @ 0x3F8 IRQ 4 and physical COM3 @ 0xFEE8 IRQ 16.