H-tronic Port Devices Driver



  1. H-tronic Port Devices Drivers
  2. H-tronic Port Devices Driver License Test
  3. H-tronic Port Devices Driver Updater
Port

The CH340 chip is used by a number of Arduino compatible boards to provide USB connectivity, you may need to install a driver, don’t panic, it’s easier than falling off a log, and much less painful.

  • In order to establish communications between your LG devices and computer, you need to install the latest LG Drivers properly onto your computer. The LG USB Driver installer package LGMobileDriverWHQLVer4.5.0.exe will install LG MTP drivers for file transfer between phone & PC, LG ADB drivers for Fastboot Mode & LG Serial Port Driver for.
  • G o to Device Manager by going to start / search box and type device manager and enter and then double-click on the program icon that appears. Check each device for a red x, yellow! These identify devices with problems (probably drivers, but also conflicts or something else). Click on each for further details and troubleshooting tips.
  • These are the newest CH Drivers for CH Game Port devices. These new drivers will work with the CH F-16 Combatstick, CH F-16 Flightstick, CH Fighterstick, CH Flight Sim Yoke PC, CH Flightstick Pro.

Most programs access devices by using general commands; the device driver translates the language into specialized commands for the device. Many device drivers are provided by the manufacturer or are available as built-in components of the OS. When hardware and software components are updated or replaced, this renders the device drivers obsolete. This is a driver library for communication with Arduinos and other USB serial hardware on Android, using the Android USB Host Mode (OTG) available since Android 3.1 and working reliably since Android 4.2. No root access, ADK, or special kernel drivers are required; all drivers are implemented in Java.


Windows

(Manufacturer’s Chinese Info Link)

  1. Download the Windows CH340 Driver
  2. Unzip the file
  3. Run the installer which you unzipped
  4. In the Arduino IDE when the CH340 is connected you will see a COM Port in the Tools > Serial Port menu, the COM number for your device may vary depending on your system.

Older Windows Driver Version and Instructions

  1. Download the Windows CH340 Driver
  2. Unzip the folder.
  3. If you are running a 64Bit Windows: – run the SETUP_64.EXE installer.
  4. If you are running a 32Bit Windows: – run the SETUP_32.EXE installer.
  5. If you don’t know, try the 64 bit and if it doesn’t work, the 32 bit.
  6. In the Arduino IDE when the CH340 is connected you will see a COM Port in the Tools > Serial Port menu, the COM number for your device may vary depending on your system.

Macintosh

(Manufacturer’s Chinese Info Link)

The following github has up to day pkg files for 1.3, 1.4 and 1.5 at time of writing, thanks to Joshua Wallis for bringing this to my attention…

Direct Download Links (from the github repo above):

See the github link above for installation instructions if you need them.

Previous macinstosh downloads if the above doesn’t work for you…

(V1.3) Download the CH340 Macintosh Signed Driver for Mavericks (10.9), Yosemite (10.10) and El Capitan (10.11) and Sierra (10.12)

Inside the zip file you will find a PDF and a “pkg” file, short version, double click the pkg file, the PDF has some extra information.

OSX Sierra (10.12) Note

A kindly user, Maarten Segers reports

FYI, the driver documented here WILL crash on OSX Sierra.

Make sure to use this one instead: https://github.com/MPParsley/ch340g-ch34g-ch34x-mac-os-x-driver

I can personally not test on MacOS and can not vouch for the above drivers at github, but there you go.

See uninstalling information at the bottom of the page if the driver causes problems for you.

Here is an older version of the Mac driver, NOT FOR 10.12 Sierra

(V1.0) Download the CH340 Macintosh Signed Driver for Mavericks (10.9), Yosemite (10.10) and El Capitan (10.11)

Linux

(Manufacturer’s Chinese Info Link)

Drivers are almost certainly built into your Linux kernel already and it will probably just work as soon as you plug it in. If not you can download the Linux CH340 Driver (but I’d recommend just upgrading your Linux install so that you get the “built in” one).

Uninstalling From Macinstosh

A couple of Mac users have said “the driver crashes my mac Sierra how do I uninstall”.

Firstly regards the crash make sure you installed the 1.3 version of the driver, not the old one. You could download it directly from the Manufacturers Website in case they have issued an update since I wrote this page.

Secondly a quick google search reveals that this is how you uninstall:

  1. Open a terminal and type: cd /Library/Extensions/
  2. Verify that the .kext file is present: ls | grep usbserial.kext
  3. Output should be: usbserial.kext
  4. Then type: sudo rm -R usbserial.kext
  5. Verify that the .kext file has been removed: ls | grep usbserial.kext
  6. Output should be empty.
  7. After you should remove the files stored in receipts folder: cd /private/var/db/receipts/
  8. Find the enties: ls | grep usbserial*
  9. Output should be: codebender.cc.ch34xinstaller.usbserial.pkg.bom codebender.cc.ch34xinstaller.usbserial.pkg.plist
  10. Remove each one of the files of the above list: sudo rm -r filename`

“Do you pine for the nice days of Minix-1.1, when men were men and wrote their own device drivers?” Linus Torvalds

In order to develop Linux device drivers, it is necessary to have an understanding of the following:

  • C programming. Some in-depth knowledge of C programming is needed, like pointer usage, bit manipulating functions, etc.
  • Microprocessor programming. It is necessary to know how microcomputers work internally: memory addressing, interrupts, etc. All of these concepts should be familiar to an assembler programmer.

There are several different devices in Linux. For simplicity, this brief tutorial will only cover type char devices loaded as modules. Kernel 2.6.x will be used (in particular, kernel 2.6.8 under Debian Sarge, which is now Debian Stable).

When you write device drivers, it’s important to make the distinction between “user space” and “kernel space”.

  • Kernel space. Linux (which is a kernel) manages the machine's hardware in a simple and efficient manner, offering the user a simple and uniform programming interface. In the same way, the kernel, and in particular its device drivers, form a bridge or interface between the end-user/programmer and the hardware. Any subroutines or functions forming part of the kernel (modules and device drivers, for example) are considered to be part of kernel space.
  • User space. End-user programs, like the UNIX shell or other GUI based applications (kpresenter for example), are part of the user space. Obviously, these applications need to interact with the system's hardware . However, they don’t do so directly, but through the kernel supported functions.

All of this is shown in figure 1.

The kernel offers several subroutines or functions in user space, which allow the end-user application programmer to interact with the hardware. Usually, in UNIX or Linux systems, this dialogue is performed through functions or subroutines in order to read and write files. The reason for this is that in Unix devices are seen, from the point of view of the user, as files.

On the other hand, in kernel space Linux also offers several functions or subroutines to perform the low level interactions directly with the hardware, and allow the transfer of information from kernel to user space.

Usually, for each function in user space (allowing the use of devices or files), there exists an equivalent in kernel space (allowing the transfer of information from the kernel to the user and vice-versa). This is shown in Table 1, which is, at this point, empty. It will be filled when the different device drivers concepts are introduced.

EventsUser functionsKernel functions
Load module
Open device
Read device
Write device
Close device
Remove module

Table 1. Device driver events and their associated interfacing functions in kernel space and user space.

There are also functions in kernel space which control the device or exchange information between the kernel and the hardware. Table 2 illustrates these concepts. This table will also be filled as the concepts are introduced.

EventsKernel functions
Read data
Write data

Table 2. Device driver events and their associated functions between kernel space and the hardware device.

I’ll now show you how to develop your first Linux device driver, which will be introduced in the kernel as a module.

For this purpose I’ll write the following program in a file named nothing.c

<nothing.c> =

Since the release of kernel version 2.6.x, compiling modules has become slightly more complicated. First, you need to have a complete, compiled kernel source-code-tree. If you have a Debian Sarge system, you can follow the steps in Appendix B (towards the end of this article). In the following, I’ll assume that a kernel version 2.6.8 is being used.

Next, you need to generate a makefile. The makefile for this example, which should be named Makefile, will be:

=

Unlike with previous versions of the kernel, it’s now also necessary to compile the module using the same kernel that you’re going to load and use the module with. To compile it, you can type:

This extremely simple module belongs to kernel space and will form part of it once it’s loaded.

In user space, you can load the module as root by typing the following into the command line:

# insmod nothing.ko

The insmod command allows the installation of the module in the kernel. However, this particular module isn’t of much use.

It is possible to check that the module has been installed correctly by looking at all installed modules:

# lsmod

Finally, the module can be removed from the kernel using the command:

# rmmod nothing

By issuing the lsmod command again, you can verify that the module is no longer in the kernel.

The summary of all this is shown in Table 3.

EventsUser functionsKernel functions
Load moduleinsmod
Open device
Read device
Write device
Close device
Remove modulermmod

Table 3. Device driver events and their associated interfacing functions between kernel space and user space.

When a module device driver is loaded into the kernel, some preliminary tasks are usually performed like resetting the device, reserving RAM, reserving interrupts, and reserving input/output ports, etc.

These tasks are performed, in kernel space, by two functions which need to be present (and explicitly declared): module_init and module_exit; they correspond to the user space commands insmod and rmmod , which are used when installing or removing a module. To sum up, the user commands insmod and rmmod use the kernel space functions module_init and module_exit.

Let’s see a practical example with the classic program Hello world:

<hello.c> =

The actual functions hello_init and hello_exit can be given any name desired. However, in order for them to be identified as the corresponding loading and removing functions, they have to be passed as parameters to the functions module_init and module_exit.

The printk function has also been introduced. It is very similar to the well known printf apart from the fact that it only works inside the kernel. The <1> symbol shows the high priority of the message (low number). In this way, besides getting the message in the kernel system log files, you should also receive this message in the system console.

H-tronic Port Devices Driver

This module can be compiled using the same command as before, after adding its name into the Makefile.

=

In the rest of the article, I have left the Makefiles as an exercise for the reader. A complete Makefile that will compile all of the modules of this tutorial is shown in Appendix A.

When the module is loaded or removed, the messages that were written in the printk statement will be displayed in the system console. If these messages do not appear in the console, you can view them by issuing the dmesg command or by looking at the system log file with cat /var/log/syslog.

Table 4 shows these two new functions.

EventsUser functionsKernel functions
Load moduleinsmodmodule_init()
Open device
Read device
Write device
Close device
Remove modulermmodmodule_exit()

Table 4. Device driver events and their associated interfacing functions between kernel space and user space.

I’ll now show how to build a complete device driver: memory.c. This device will allow a character to be read from or written into it. This device, while normally not very useful, provides a very illustrative example since it is a complete driver; it's also easy to implement, since it doesn’t interface to a real hardware device (besides the computer itself).

To develop this driver, several new #include statements which appear frequently in device drivers need to be added:

H-tronic Port Devices Drivers

To achieve this, a file (which will be used to access the device driver) must be created, by typing the following command as root:

# mknod /dev/memory c 60 0

In the above, c means that a char device is to be created, 60 is the major number and 0 is the minor number.

Within the driver, in order to link it with its corresponding /dev file in kernel space, the register_chrdev function is used. It is called with three arguments: major number, a string of characters showing the module name, and a file_operations structure which links the call with the file functions it defines. It is invoked, when installing the module, in this way:

=

Also, note the use of the kmalloc function. This function is used for memory allocation of the buffer in the device driver which resides in kernel space. Its use is very similar to the well known malloc function. Finally, if registering the major number or allocating the memory fails, the module acts accordingly.

In order to remove the module inside the memory_exit function, the function unregsiter_chrdev needs to be present. This will free the major number for the kernel.

=

The buffer memory is also freed in this function, in order to leave a clean kernel when removing the device driver.

The kernel space function, which corresponds to opening a file in user space (fopen), is the member open: of the file_operations structure in the call to register_chrdev. In this case, it is the memory_open function. It takes as arguments: an inode structure, which sends information to the kernel regarding the major number and minor number; and a file structure with information relative to the different operations that can be performed on a file. Neither of these functions will be covered in depth within this article.

When a file is opened, it’s normally necessary to initialize driver variables or reset the device. In this simple example, though, these operations are not performed.

The memory_open function can be seen below:

=

This new function is shown in Table 6.

EventsUser functionsKernel functions
Load moduleinsmodmodule_init()
Open devicefopenfile_operations: open
Read device
Write device
Close devicefclosefile_operations: release
Remove modulermmodmodule_exit()

Table 6. Device driver events and their associated interfacing functions between kernel space and user space.

To read a device with the user function fread or similar, the member read: of the file_operations structure is used in the call to register_chrdev. This time, it is the function memory_read. Its arguments are: a type file structure; a buffer (buf), from which the user space function (fread) will read; a counter with the number of bytes to transfer (count), which has the same value as the usual counter in the user space function (fread); and finally, the position of where to start reading the file (f_pos).

In this simple case, the memory_read function transfers a single byte from the driver buffer (memory_buffer) to user space with the function copy_to_user:

=

In this case, the function copy_from_user transfers the data from user space to kernel space.

In Table 8 this new function is shown.

EventsUser functionsKernel functions
Load moduleinsmodmodule_init()
Open devicefopenfile_operations: open
Close devicefreadfile_operations: read
Write devicefwritefile_operations: write
Close devicefclosefile_operations: release
Remove modulermmodmodule_exit()

Device driver events and their associated interfacing functions between kernel space and user space.

By joining all of the previously shown code, the complete driver is achieved:

<memory.c> =

Before this module can be used, you will need to compile it in the same way as with previous modules. The module can then be loaded with:

# insmod memory.ko

It’s also convenient to unprotect the device:

# chmod 666 /dev/memory

If everything went well, you will have a device /dev/memory to which you can write a string of characters and it will store the last one of them. You can perform the operation like this:

$ echo -n abcdef >/dev/memory

To check the content of the device you can use a simple cat:

$ cat /dev/memory

The stored character will not change until it is overwritten or the module is removed.

I’ll now proceed by modifying the driver that I just created to develop one that does a real task on a real device. I’ll use the simple and ubiquitous computer parallel port and the driver will be called parlelport.

The parallel port is effectively a device that allows the input and output of digital information. More specifically it has a female D-25 connector with twenty-five pins. Internally, from the point of view of the CPU, it uses three bytes of memory. In a PC, the base address (the one from the first byte of the device) is usually 0x378. In this basic example, I’ll use just the first byte, which consists entirely of digital outputs.

The connection of the above-mentioned byte with the external connector pins is shown in figure 2.

The previous memory_init function needs modification—changing the RAM memory allocation for the reservation of the memory address of the parallel port (0x378). To achieve this, use the function for checking the availability of a memory region (check_region), and the function to reserve the memory region for this device (request_region). Both have as arguments the base address of the memory region and its length. The request_region function also accepts a string which defines the module.

=

In this case, a real device reading action needs to be added to allow the transfer of this information to user space. The inb function achieves this; its arguments are the address of the parallel port and it returns the content of the port.

=

Table 10 summarizes this new function.

EventsKernel functions
Read datainb
Write dataoutb

Device driver events and their associated functions between kernel space and the hardware device.

I’ll proceed by looking at the whole code of the parlelport module. You have to replace the word memory for the word parlelport throughout the code for the memory module. The final result is shown below:

<parlelport.c> =

Initial section

In the initial section of the driver a different major number is used (61). Also, the global variable memory_buffer is changed to port and two more #include lines are added: ioport.h and io.h.

=

Closing the device as a file

Again, the match is perfect.

H-tronic Port Devices Driver License Test

Reading the device

The reading function is similar to the memory one with the corresponding modifications to read from the port of a device.

=

In this section I’ll detail the construction of a piece of hardware that can be used to visualize the state of the parallel port with some simple LEDs.

WARNING: Connecting devices to the parallel port can harm your computer. Make sure that you are properly earthed and your computer is turned off when connecting the device. Any problems that arise due to undertaking these experiments is your sole responsibility.

The circuit to build is shown in figure 3 You can also read “PC & Electronics: Connecting Your PC to the Outside World” by Zoller as reference.

In order to use it, you must first ensure that all hardware is correctly connected. Next, switch off the PC and connect the device to the parallel port. The PC can then be turned on and all device drivers related to the parallel port should be removed (for example, lp, parport, parport_pc, etc.). The hotplug module of the Debian Sarge distribution is particularly annoying and should be removed. If the file /dev/parlelport does not exist, it must be created as root with the command:

# mknod /dev/parlelport c 61 0

Then it needs to be made readable and writable by anybody with:

# chmod 666 /dev/parlelport

The module can now be installed, parlelport. You can check that it is effectively reserving the input/output port addresses 0x378 with the command:

$ cat /proc/ioports

To turn on the LEDs and check that the system is working, execute the command:

$ echo -n A >/dev/parlelport

This should turn on LED zero and six, leaving all of the others off.

You can check the state of the parallel port issuing the command:

$ cat /dev/parlelport Digidesign mbox 2 usb driver download.

Finally, I’ll develop a pretty application which will make the LEDs flash in succession. To achieve this, a program in user space needs to be written with which only one bit at a time will be written to the /dev/parlelport device.

<lights.c> =

It can be compiled in the usual way:

$ gcc -o lights lights.c

and can be executed with the command:

$ lights

The lights will flash successively one after the other! The flashing LEDs and the Linux computer running this program are shown in figure 4.

Having followed this brief tutorial you should now be capable of writing your own complete device driver for simple hardware like a relay board (see Appendix C), or a minimal device driver for complex hardware. Learning to understand some of these simple concepts behind the Linux kernel allows you, in a quick and easy way, to get up to speed with respect to writing device drivers. And, this will bring you another step closer to becoming a true Linux kernel developer.

A. Rubini, J. Corbert. 2001. Linux device drivers (second edition). Ed. O’Reilly. This book is available for free on the internet.

Jonathan Corbet. 2003/2004. Porting device drivers to the 2.6 kernel. This is a very valuable resource for porting drivers to the new 2.6 Linux kernel and also for learning about Linux device drivers.

B. Zoller. 1998. PC & Electronics: Connecting Your PC to the Outside World (Productivity Series). Nowadays it is probably easier to surf the web for hardware projects like this one.

M. Waite, S. Prata. 1990. C Programming. Any other good book on C programming would suffice.

=

H-tronic Port Devices Driver

To compile a 2.6.x kernel on a Debian Sarge system you need to perform the following steps, which should be run as root:

  1. Install the “kernel-image-2.6.x” package.
  2. Reboot the machine to make this the running kernel image. This is done semi-automatically by Debian. You may need to tweak the lilo configuration file /etc/lilo.conf and then run lilo to achieve this.
  3. Install the “kernel-source-2.6.x” package.
  4. Change to the source code directory, cd /usr/src and unzip and untar the source code with bunzip2 kernel-source-2.6.x.tar.bz2 and tar xvf kernel-source-2.6.x.tar. Change to the kernel source directory with cd /usr/src/kernel-source-2.6.x
  5. Copy the default Debian kernel configuration file to your local kernel source directory cp /boot/config-2.6.x .config.
  6. Make the kernel and the modules with make and then make modules.

If you would like to take on some bigger challenges, here are a couple of exercises you can do:

  1. I once wrote two device drivers for two ISA Meilhaus boards, an analog to digital converter (ME26) and a relay control board (ME53). The software is available from the ADQ project. Get the newer PCI versions of these Meilhaus boards and update the software.
  2. Take any device that doesn’t work on Linux, but has a very similar chipset to another device which does have a proven device driver for Linux. Try to modify the working device driver to make it work for the new device. If you achieve this, submit your code to the kernel and become a kernel developer yourself!

Three years have elapsed since the first version of this document was written. It was originally written in Spanish and intended for version 2.2 of the kernel, but kernel 2.4 was already making its first steps at that time. The reason for this choice is that good documentation for writing device drivers, the Linux device drivers book (see bibliography), lagged the release of the kernel in some months. This new version is also coming out soon after the release of the new 2.6 kernel, but up to date documentation is now readily available in Linux Weekly News making it possible to have this document synchronized with the newest kernel.

Fortunately enough, PCs still come with a built-in parallel port, despite the actual trend of changing everything inside a PC to render it obsolete in no time. Let us hope that PCs still continue to have built-in parallel ports for some time in the future, or that at least, parallel port PCI cards are still being sold.

This tutorial has been originally typed using a text editor (i.e. emacs) in noweb format. This text is then processed with the noweb tool to create a LaTeX file ( .tex ) and the source code files ( .c ). All this can be done using the supplied makefile.document with the command make -f makefile.document.

H-tronic Port Devices Driver Updater

I would like to thank the “Instituto Politécnico de Bragança”, the “Núcleo Estudantil de Linux del Instituto Politécnico de Bragança (NUX)”, the “Asociación de Software Libre de León (SLeón)” and the “Núcleo de Estudantes de Engenharia Informática da Universidade de Évora” for making this update possible.

Fremantle counselling -- does it interest you?

If software development is stressing you out, or if you need help, you can have Perth Counselling at your fingertips!