Linux Format forums Forum Index Linux Format forums
Help, discussion, magazine feedback and more
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Serial connection 128000 Baud

 
Post new topic   Reply to topic    Linux Format forums Forum Index -> Help!
View previous topic :: View next topic  
Author Message
uli



Joined: Thu May 02, 2013 8:42 pm
Posts: 3

PostPosted: Fri May 03, 2013 11:43 am    Post subject: Serial connection 128000 Baud Reply with quote

Hi all,

I own a charger (iCharger 206B from Junsi) which has a USB interface (internally working with a CP210x chip form Silicon Laboratories). The baud rate is fixed to 128000 Baud and this seems to be a problem for Linux (non standard baudrate).

Windows on the other hand supports this with no problem at all.

Is there a way to get a 128000 baudrate in linux? When I try for example moserial and set the baud rate to 128000 baud it just crashes a few seconds later.

Using picocom from the terminal gives me a little more information about the problem:

FATAL: failed to add device /dev/ttyS0: Invalid baud rate

When searching for a explanation or solution, I found some pointers but no information on how to solve this problem ( it seems there was a bug filed at suse in 2010: http://lists.opensuse.org/opensuse-bugs/2010-04/msg03125.html ).

I use Ubuntu 12.10

Any ideas?

Thanks

Uli



[url][/url]
Back to top
View user's profile Send private message
Bazza
LXF regular


Joined: Sat Mar 21, 2009 11:16 am
Posts: 1474
Location: Loughborough

PostPosted: Mon May 06, 2013 7:00 pm    Post subject: Reply with quote

First things first...

Why are you attempting to hit /dev/ttyS0?

As you are on a USB slot the the device will probably be /dev/ttyUSBx OR /dev/ttyACMx whre x = 0 to 7.

How to find what it is:-
(Assumptions; you are in a Linux, root mode terminal, etc.)
1) Ensure the device is disconnected...
2) ls /dev/*tty*
3) Connect the device and allow a few seconds to settle.
4) ls /dev/*tty*
5) Scroll the terminal to see the diff's...

These will be the device name(s) added.

Let us assume that at least one is /dev/ttyUSB0

Try this from the terminal:-

*****$ stty -F /dev/ttyUSB0 128000<CR>
*****$ stty -F /dev/ttyUSB0 raw<CR>
*****$ stty<CR>

The last one should give the parameters only IF it works...

It is a long shot but worth a try...
_________________
73...

Bazza, G0LCU...

Team AMIGA...
Back to top
View user's profile Send private message
nelz
Site admin


Joined: Mon Apr 04, 2005 12:52 pm
Posts: 8453
Location: Warrington, UK

PostPosted: Mon May 06, 2013 7:29 pm    Post subject: Reply with quote

Bazza wrote:
How to find what it is:-
(Assumptions; you are in a Linux, root mode terminal, etc.)
1) Ensure the device is disconnected...
2) ls /dev/*tty*
3) Connect the device and allow a few seconds to settle.
4) ls /dev/*tty*
5) Scroll the terminal to see the diff's...


Or
1) Ensure the device is disconnected...
2) Run "tail -f /var/log/messages | grep /dev/"
3) connect the device

You can also use "dmesg --follow" instead of "tail -f /var/log/messages" but only with the most recent versions of dmesg.
_________________
"Insanity: doing the same thing over and over again and expecting different results." (Albert Einstein)
Back to top
View user's profile Send private message
uli



Joined: Thu May 02, 2013 8:42 pm
Posts: 3

PostPosted: Thu May 09, 2013 11:52 am    Post subject: Serial connection 128000 Baud Reply with quote

sorry I did a mistake in my initial post, I meant of course /dev/ttyUSB0 and yes when I plug the charger in I can see that it is available as ttyUSB0:

[ 44.411946] usbcore: registered new interface driver usbserial
[ 44.411966] USB Serial support registered for generic
[ 44.460610] usbcore: registered new interface driver usbserial_generic
[ 44.460616] usbserial: USB Serial Driver core
[ 44.462330] USB Serial support registered for cp210x
[ 44.462393] cp210x 4-2:1.0: cp210x converter detected
[ 44.636098] usb 4-2: reset full-speed USB device number 2 using ohci_hcd
[ 44.845288] usb 4-2: cp210x converter now attached to ttyUSB0
[ 44.845316] usbcore: registered new interface driver cp210x
[ 44.845319] cp210x: v0.09:Silicon Labs CP210x RS232 serial adaptor driver

But still it doesn't work as expected:

uli@uli-MacBookAir:~$ picocom -b 128000 /dev/ttyUSB0
picocom v1.4

port is : /dev/ttyUSB0
flowcontrol : none
baudrate is : 128000
parity is : none
databits are : 8
escape is : C-a
noinit is : no
noreset is : no
nolock is : no
send_cmd is : ascii_xfr -s -v -l10
receive_cmd is : rz -vv


FATAL: failed to add device /dev/ttyUSB0: Invalid baud rate
uli@uli-MacBookAir:~$ stty -F /dev/ttyUSB0 128000
stty: invalid argument `128000'
Try `stty --help' for more information.

or as suggested:


uli@uli-MacBookAir:~$ picocom -b 128000 /dev/ttyUSB0
picocom v1.4

port is : /dev/ttyUSB0
flowcontrol : none
baudrate is : 128000
parity is : none
databits are : 8
escape is : C-a
noinit is : no
noreset is : no
nolock is : no
send_cmd is : ascii_xfr -s -v -l10
receive_cmd is : rz -vv

uli@uli-MacBookAir:~$ stty -F /dev/ttyUSB0 128000
stty: invalid argument `128000'
Try `stty --help' for more information.


uli@uli-MacBookAir:~$ stty -F /dev/ttyUSB0 raw
uli@uli-MacBookAir:~$ stty
speed 38400 baud; line = 0;
eol = M-^?; eol2 = M-^?; swtch = M-^?;
ixany iutf8



Uli
Back to top
View user's profile Send private message
ferrari
LXF regular


Joined: Tue May 03, 2005 12:09 pm
Posts: 127

PostPosted: Fri May 10, 2013 10:02 am    Post subject: Reply with quote

You might want to consider purchasing an in-line baud rate converter instead. I've seen a few that support the baud rate you desire.
Back to top
View user's profile Send private message
uli



Joined: Thu May 02, 2013 8:42 pm
Posts: 3

PostPosted: Sat May 11, 2013 1:00 pm    Post subject: Reply with quote

Yes I could do that, or use a Microcontroller to do that, but I really dislike the fact that Linux isn't able to handle this serial speed even if it is technical possible and needed from the user standpoint.

And even worse M$ can handle these settings with no problem at all.

Uli
Back to top
View user's profile Send private message
ferrari
LXF regular


Joined: Tue May 03, 2005 12:09 pm
Posts: 127

PostPosted: Mon May 13, 2013 5:33 am    Post subject: Reply with quote

I guess the need for it is minimal... most equipment default to standard baud rates. (I've never encountered the situation you describe).
Back to top
View user's profile Send private message
ewykh



Joined: Mon Jun 24, 2013 8:26 am
Posts: 1
Location: Australia

PostPosted: Mon Jun 24, 2013 10:53 am    Post subject: Re: Serial connection 128000 Baud Reply with quote

uli wrote:
I own a charger (iCharger 206B from Junsi) which has a USB interface (internally working with a CP210x chip form Silicon Laboratories). The baud rate is fixed to 128000 Baud and this seems to be a problem for Linux (non standard baudrate).

You could of course petition Junsi to release a trivial firmware modification to change the 206B to use 115200 bps instead of 128000 bps...

As you know (since it works in Windows) your hardware is capable of handing 128000 bps; the problem is that getting a request for this speed through all the layers of library and kernel between an application program and the hardware would require changes to many different packages, and worse, changes to various standards. I can't see it happening unless there was a very popular product that needed it.

However, given Linux is open source, you can fairly easily do it yourself, and indeed I did it on my own system so that I could use that exact same model of battery charger!

I couldn't be bothered with all the changes that would have been needed to add proper support for B128000. Instead, what I did was to take over one of the existing speeds that I never used for anything else (I chose B230400), and then modified the cp210x.c kernel module source file so that when it was told to run at 230400 bps it actually used 128000 bps. The change to cp210x.c (from /usr/src/linux-source-3.5.0/drivers/usb/serial/cp210x.c) is quite trivial:

Code:
--- cp210x.c.old        2013-06-24 19:15:56.721784737 +1000
+++ cp210x.c.new        2013-06-24 19:25:18.573803882 +1000
@@ -27,7 +27,7 @@
 /*
  * Version Information
  */
-#define DRIVER_VERSION "v0.09"
+#define DRIVER_VERSION "v0.09k128"
 #define DRIVER_DESC "Silicon Labs CP210x RS232 serial adaptor driver"
 
 /*
@@ -431,9 +431,7 @@
        else if (baud <= 64111)    baud = 64000;
        else if (baud <= 77608)    baud = 76800;
        else if (baud <= 117028)   baud = 115200;
-       else if (baud <= 129347)   baud = 128000;
-       else if (baud <= 156868)   baud = 153600;
-       else if (baud <= 237832)   baud = 230400;
+       else if (baud <= 237832)   baud = 128000;
        else if (baud <= 254234)   baud = 250000;
        else if (baud <= 273066)   baud = 256000;
        else if (baud <= 491520)   baud = 460800;

So now I just ask for 230400 bps and get 128000 bps, which works perfectly with the 206B charger.

By the way, if you don't want to rebuild an entire kernel, you can use DKMS. It is probably getting a bit off-topic, but (once you install all the necessary kernel source and development tool packages) you just create a directory (say /usr/src/cp210x-0.09k128) and put in it thee files: the patched cp210x.c, dkms.conf which looks like:
Code:
PACKAGE_VERSION="0.09k128"

# Items below here should not have to change with each driver version
PACKAGE_NAME="cp210x"
MAKE[0]="make -C ${kernel_source_dir} SUBDIRS=${dkms_tree}/${PACKAGE_NAME}/${PACKAGE_VERSION}/build modules"
CLEAN="make -C ${kernel_source_dir} SUBDIRS=${dkms_tree}/${PACKAGE_NAME}/${PACKAGE_VERSION}/build clean"

BUILT_MODULE_NAME[0]="cp210x"
DEST_MODULE_LOCATION[0]="/kernel/drivers/usb/serial/"

and Makefile that looks like:
Code:
#
# Makefile for the USB serial device drivers.
#

# Object file lists.

obj-m                   += cp210x.o

You can then build and install the module use the commands:
Code:
dkms add -m cp210x -v 0.09k128
dkms build -m cp210x -v 0.09k128
dkms install -m cp210x -v 0.09k128

Finally, either reboot or else force a reload of the cp210x module so that you are using the new one:
Code:
depmod -a
rmmod cp210x
modprobe cp210x

Note that you need to be logged in as root to do most of this.

By the way, I also added a udev rule (/etc/udev/rules.d/95-cp210x.rules) that looks like:
Code:
BUS!="usb", ACTION!="add", SUBSYSTEM!=="usb_device", GOTO="kcontrol_rules_end"

ATTRS{idProduct}=="ea60", ATTRS{idVendor}=="10c4", ATTRS{product}=="Junsi iCharger 206B", MODE="664", GROUP="plugdev", SYMLINK+="ic206b"

LABEL="kcontrol_rules_end"
so that I can now refer to /dev/ic206b whenever I want to access this device.

Hope this helps!
Back to top
View user's profile Send private message
View previous topic :: View next topic  
Display posts from previous:   
Post new topic   Reply to topic    Linux Format forums Forum Index -> Help! All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Linux Format forums topic RSS feed 


Powered by phpBB © 2001, 2005 phpBB Group


Copyright 2011 Future Publishing, all rights reserved.


Web hosting by UKFast