As an Embedded Software Engineer serial port access is very critical requirement for me irrespective off which OS I am using and how I am using it (I mean with or without virtualization).
I have Windows XP as primary Operating System, however, I need to work on Linux for lot of hobby projects. I hate to manage two computers for two reasons first is it makes workplace really messy with extra wires and Second is I always need some space to keep items like Power Supplies, Oscilloscopes, Programmers, Debuggers etc. which are unavoidable.
So I installed Kubuntu as Guest OS on my Windows Host and I wanted to access the host serial port for debugging purposes. Virtual Box does provide this feature and its quite easy to configure as well. The problem is, it can be done in more then one way and that’s where user might get confused that’s why I am writing this post. Before jumping into action we will just find little more information about serial ports
How Serial Ports are Named:
In windows like operating systems serial ports are named like COM1, COM2 and so on while in Linux they are named like /dev/ttyS0, /dev/ttyS1 and so on. As my example involves both operating systems it might create some confusion, as a rule of thumb what will call COM1 in windows will be /dev/ttyS0, COM2 will be /dev/ttyS1 and so on. Even though the names are different they refer to the same Interrupt and IO ports and that’s how we map these names.
|Name Under Windows||Name Under Linux||IO Address||Interrupt Request (IRQ)|
Setup & Requirement:
My computer has four serial port COM1, COM2, COM3 & COM4 . My requirement is very simple I want to access COM3 in my Kubuntu guest installed under Virtual Box Virtual Machine. (We could have taken COM1 itself but that will be little bit confusing so we will stick to COM3 first, once we know how to do it we can access any port in similar manner).
The next step is to configure virtual box to connect virtual serial port in guest OS to physical serial port on host. This is pretty easy if you know what to IGNORE on the serial port configuration dialog of Virtual Box. Lets get started with the configuration now, Open the serial port configuration dialog box for the virtual machine of interest, by default Port0 Tab will be visible. For our purpose IGNORE IRQ, IO PORT and Create Pipe fields.
- On Port0 Tab select Enable Serial Port check box (you will not be able to change any other setting till you check this one).
- Port Number : This field refers to port number under guest OS, we want to map it to COM1 (/dev/ttyS0) so select COM1 (remember it has nothing to do with physical ports)
- Port Mode: We want to connect virtual device to physical device on host so set it to “Host Device”
- Port Path: For “Host Device” port mode this field refers to physical device port number on host, we want to connect to COM3 on host so enter COM3 here.
Check out the screen shot below for Virtual Box Configuration.
That’s it just set these 3 fields to correct values and you are done.
Now lets check if it really works or not, as I said my virtual machine runs Kubuntu so the serial port COM1 (Technically the port with IRQ= 4 and I/O Port = 0x3f8) will be mapped to /dev/ttyS0.
Verification Under Guest OS:
To verify the serial port operation under guest OS we need some Kind of Serial Port terminal for gust OS. As our guest OS is Kubuntu I have used Cutecom. Now the actual verification can be done in two ways.
- Short Pin 2 and 3 of the physical serial port, this will short the Rx and Tx pins of the serial port and whatever you send through terminal will echoed back to the terminal.
- Connect any RS-232 device to serial port and verify it with the device specific commands or application.
I will choose the first method because it will work for everyone, so short RX and Tx pins for your physical serial port and configure Cutecom to set the device to /dev/ttyS0, make other settings as per screen shot below.
See it in action below:
- In order to map COM1 to /dev/ttyS0 we need to set both Port Number and Port Path fields to COM1 in Virtual Box serial port settings.
- Even though I have tested it on Kubuntu it should work on any Linux destro.
- If your guest OS is Windows you can use the Hyper Terminal program and port name given in Port Number field of Virtual Box serial port settings.
- Please note that the selected physical port can not be accessed by the Host when the Virtual Machine using that port is running.
Links Related to This Post: