Thursday, January 26, 2012

NetMos 9845 Multiserial on Ubuntu 10.04

I have installed a NetMos 9845 Multiserial (8 port) card on my pc as i need several serial ports for a project.
Problem is Ubuntu does not recognize more than 4 ports by default.
To solve this you need to add a kernel boot parameter to instruct the kernel during boot to look for more serial devices.

With Grub2 on the machine, you can no longer edit the grub kernel parameters directly as Grub2 uses a templeting system.
So use your favorite editor and open (as root)


there you will see a line


change it to

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash 8250.nr_uarts=8"

save the file and then issue the command

sudo update-grub

for the changes to take effect

Reboot your machine and check dmesg for the number of serial ports you now have
In my case it looks like this

:/etc/grub.d$ dmesg | grep ttyS
[ 0.709951] serial8250: ttyS0 at I/O 0x3f8 (irq = 4) is a 16550A
[ 0.710235] 00:07: ttyS0 at I/O 0x3f8 (irq = 4) is a 16550A
[ 0.710400] 0000:05:01.0: ttyS4 at I/O 0xc000 (irq = 19) is a 16550A
[ 0.710477] 0000:05:01.0: ttyS5 at I/O 0xc100 (irq = 19) is a 16550A
[ 0.710551] 0000:05:01.0: ttyS6 at I/O 0xc200 (irq = 19) is a 16550A
[ 0.710626] 0000:05:01.0: ttyS7 at I/O 0xc300 (irq = 19) is a 16550A
[ 0.710700] 0000:05:01.0: ttyS1 at I/O 0xc400 (irq = 19) is a 16550A
[ 0.710775] 0000:05:01.0: ttyS2 at I/O 0xc500 (irq = 19) is a 16550A

You can also check the number and setting of the serial ports using the setserial command for every port

sudo setserial /dev/ttyS7 -a
/dev/ttyS7, Line 7, UART: 16550A, Port: 0xc300, IRQ: 19
Baud_base: 115200, close_delay: 50, divisor: 0
closing_wait: 3000
Flags: spd_normal skip_test

Sunday, January 22, 2012

Getting your Android phone recognized by adb for debugging

In an older post i have shown hot to get a Samsung phone "recognized" by adb for debugging.
These were the "early days" of Android development...
Since then Android got more mature (so did adb) and now there are many companies producing Android compatible phones that developers want to use for testing/debugging their apps.
One of the main issues people have in Ubuntu is how to get the correct udev rules for their phone, as there are many sites ans post with old info or targeting specific phones.
The other problem developers face is how to use the phone in debug mode without having to run adb as root.

First thing to do is have a go at the official Android dev page
It has (most of) the instruction you need to get your phone connected and recognized.

It all boils down to creating a new udev rule file and adding something like this

SUBSYSTEM=="usb", ATTR{idVendor}=="0bb4", MODE="0666", GROUP="plugdev"

Basically you have to tell udev that devices with idVendor=="0bb4" should get read/write privileges (the MODE="0666" part) for the group "plugdev"
In this example, the vendor ID 0bb4 is for HTC. The MODE assignment specifies read/write permissions, and GROUP defines which Unix group owns the device node.

It also has an extensive list of vendor id's you can use to match your device.

In case your device manufacturer is not in that list, there is an easy way to find the vendor id of your device.
Connect your device and issue


and you will get a list of connected usb devices and their associated vendor and device id's

in my case it looks like this

Bus 008 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 007 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 015: ID 12d1:1038 Huawei Technologies Co., Ltd.
Bus 001 Device 005: ID 0d8c:000c C-Media Electronics, Inc. Audio Adapter
Bus 001 Device 004: ID 05e3:0702 Genesys Logic, Inc. USB 2.0 IDE Adapter
Bus 001 Device 003: ID 0409:0050 NEC Corp.
Bus 001 Device 002: ID 03f0:4105 Hewlett-Packard ScanJet 4370
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Locate your device (in this case it's the Huawei Technologies Co., Ltd) and the first part of the ID 12d1:1038 (i.e the 12d1) is the idVendor you need you need to put in the udev rules

Another common problem developers face is that although the udev rules are correct the phone does not connect to adb and shows up as a number of ???????????? when issuing an "adb devices" command.

The only way to get the phone connected is to start the adb with root privileges using sudo ,which in my book is a big "NoNo"
To solve this you need to set the correct user and group in the udev rules
Here is how my udev entry looks like

SUBSYSTEM=="usb", SYSFS{idVendor}=="22b8", OWNER="your-user-name" GROUP="your-group"
SUBSYSTEM=="usb", ATTR{idVendor}=="22b8", MODE="0666"

To get your username and group issue the command


and look for the uid and gid entries
in my case they look like this

uid=1000(stelios) gid=1000(stelios)

Use the uid name in parenthesis in the OWNER and gid name in the GROUP, restart udev and now you will be able to access the phone from adb as a normal user without having to issue sudo