0

[SOLVED] very slow USB serial programming on Mac OS X
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

[SOLVED] very slow USB serial programming on Mac OS X

by xor on Mon Nov 23, 2009 9:53 am

There are several reports of very slow programming using a USB serial adapter on Mac OS X. All of them are answered by helpful people that this is the way it is with USB/serial adapters. However people are reporting programming speeds of 2 seconds for a single byte. Now even given all the overhead involved in having several (exactly 4 with avrdude) USB operations per bit, this cannot possibly be OK. So when I ran into this problem when I tried to program an Attiny13 in a 'dasa' configuration with a PL2303 based adapter on my Mac OS X 10.5 system I took a closer look.

It turned out that one operation in avrdude's serbb_posix.c is taking very long. It is the setting of the TXD line via:

Code: Select all | TOGGLE FULL SIZE
  switch ( pin )
  {
    case 3:  /* txd */
             r = ioctl(pgm->fd.ifd, value ? TIOCSBRK : TIOCCBRK, 0);
             ...
             return 0;

but only in case of value == 1, thus involving the TIOCSBRK operation. My measurements gave 250 milliseconds for that operation. All the other bitbanging operations take less than a millisecond. In the 'dasa' setup the TXD line is connected to the MOSI (data input) pin of the device, meaning that this happens every time a 1 bit has to be written.

I decided not to investigate the issue further (maybe somebody else will) but to try a workaround instead. I reconnected the AVR so that TXD would be used for the RESET pin of the device (it is not flipped often, so the 250ms do not hurt) and to connect RTS to the MOSI pin instead (thus switching RXD and RTS). Of course the lines have to be switched in the corresponding programmer section in avrdude.conf as well (or better make a new programmer entry for the modified setup). There is one kludge I ran into because I was experimenting with different avrdude versions - the numbering of the lines in avrdude.conf changed from version 5.1 to 5.2. From 5.2 on the numbers correspond to the numbers on the 9pin Sub-D PC connector, previously this was not the case.

Before this modification I had

avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 2.29s
avrdude: Device signature = 0x1e9007
...
avrdude: writing flash (108 bytes):
Writing | ################################################## | 100% 205.29s
avrdude: 108 bytes of flash written

and afterwards:

avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.20s
avrdude: Device signature = 0x1e9007
...
avrdude: writing flash (108 bytes):
Writing | ################################################## | 100% 8.12s
avrdude: 108 bytes of flash written

so I am now a perfectly happy perfectly normal slow USB serial AVR programmer user.

As a final note, I am using the ladyada recommended Mac OS X driver for the PL2303 chip (http://sourceforge.net/projects/osx-pl2303) and (now) an unmodified avrdude 5.6 (the newest 5.8 worked as well, as the modified 5.1 from http://ladyada.net/make/minipov3/software.html#macosx). And I do not know whether this problem is specific to the PL2303, the driver, Mac OS X, 10.5 or whatever - it probably is.
xor
 
Posts: 6
Joined: Mon Nov 23, 2009 8:29 am

Re: [SOLVED] very slow USB serial programming on Mac OS X

by adafruit on Mon Nov 23, 2009 1:26 pm

the reason we suggested a different pl2303 driver is that the 'original' one does not allow twiddling the TX line (iirc) and just doesnt work at all :(

either way, this is really fantastic. I'll stick it! thanks :)

adafruit
 
Posts: 12131
Joined: Thu Apr 06, 2006 4:21 pm
Location: nyc

Re: [SOLVED] very slow USB serial programming on Mac OS X

by westfw on Mon Nov 23, 2009 7:12 pm

It all makes sense! The sending of BREAK is relatively poorly defined (a "space" condition on data exceeding one character time is about all people will agree on.) It is handled differently on different uarts (sometimes not at all) and in different operating systems. It seems that MacOS wants to send at least 250ms SPACE condition, and the ioctl blocks for that whole time (which is not an unusual way to handle things for some uarts. The uart world is NOT uniformly composed of enhanced intel8250 clones!

The workaround of using txd for RESET instead of data is very clever, and I like it a lot! It's a shame it's such an invasive fix, though.
User avatar
westfw
 
Posts: 1382
Joined: Fri Apr 27, 2007 1:01 pm
Location: SF Bay area

Re: [SOLVED] very slow USB serial programming on Mac OS X

by brianmay27 on Fri Dec 18, 2009 12:38 am

So for this problem what are the steps to fix this? Is it just to switch the RXD and RTS pins on the serial and edit the config file? Could you post what the config file should look like? Im realy tired of waiting 900 sec for it to write my 500 bit app.
brianmay27
 
Posts: 11
Joined: Thu Dec 03, 2009 9:53 pm

Re: [SOLVED] very slow USB serial programming on Mac OS X

by xor on Sun Dec 20, 2009 3:55 pm

There is a typo in the original posting - it should read "switching TXD and RTS". Sorry for that.

So TXD and RTS have to be swapped physically and in the avrdude config. For a "dasa" compatible programmer this means swapping the numbers for the "reset" and the "mosi" line.

The following example is for an avrdude version 5.2 or later - earlier versions use a different pin numbering - however swapping the numbers still works of course.

So if the original configuration is

programmer
id = "dasa";
desc = "serial port banging, reset=rts sck=dtr mosi=txd miso=cts";
type = serbb;
reset = 7;
sck = 4;
mosi = 3;
miso = 8;

then the modified one would be

programmer
id = "dasa";
desc = "serial port banging, reset=txd sck=dtr mosi=rts miso=cts";
type = serbb;
reset = 3;
sck = 4;
mosi = 7;
miso = 8;

Instead of changing the "dasa" entry it is probably more clean to copy the "dasa" entry and give it a different name e.g. "myprog" and using this name instead of dasa when running avrdude:

programmer
id = "myprog";
desc = "serial port banging, reset=txd sck=dtr mosi=rts miso=cts";
type = serbb;
reset = 3;
sck = 4;
mosi = 7;
miso = 8;

That's it.
xor
 
Posts: 6
Joined: Mon Nov 23, 2009 8:29 am

Re: [SOLVED] very slow USB serial programming on Mac OS X

by TomS on Sun Jul 18, 2010 11:09 pm

How about a little more detail on the physical changes required? Is this as simple as crossing R10 and R11 as silkscreened on the PCB (which look like they're labeled R11 and R12 on the schematic)? So instead of R10 and R11 paralleling D2 they would make an X over it? Any hints on insulating the leads on the resistors?
TomS
 
Posts: 2
Joined: Sun Jul 18, 2010 11:03 pm

Re: [SOLVED] very slow USB serial programming on Mac OS X

by mightyohm on Mon Apr 25, 2011 4:28 pm

Programming on OS X 10.6.7 with the USB-serial adapter sold in the Adafruit store takes over 10 minutes on my Macbook Core Duo (~2006) laptop. This is using the original pinout and avrdude 5.10, and just editing the Makefile to set the serial port and running "make program-minipov".
mightyohm
 
Posts: 19
Joined: Mon Sep 22, 2008 8:30 pm

Please be positive and constructive with your questions and comments.


cron