Tuesday, June 12, 2012

Arduino success

I have managed to upload an example sketch to the leostick, it took a bit of sleuthing to get all the bits right.

step 1: I used the boot configuration editor (boot -c) to disable the uhidev driver so that it would not claim the leostick, this meant that the ugen driver claimed it instead which is what I wanted.  I already had a program that used the ugen ioctl USB_GET_CONFIG_DESC to get the configuration description of the device.  It turned out the leostick had three interfaces, the first is a CDC ACM (usb serial) the second looks to be CDC Data but didn't make much sense and the third is the HID that uhidev was latching on to.  Given that the NetBSD umodem driver supports the CDC ACM interface type it was a matter of working out why umodem was not attaching.  It turns out that the umodem match was checking that the interface protocol attribute was set to a particular number, on the leostick the protocol was 0.

step 2: fix the umodem driver.  I just modified the attach so that it would attach if the protocol was the AT protocol or if protocol is 0.  Rebuilt the kernel, installed, rebooted and now when I plug the leostick in the umodem driver claims the serial port.  I could connect to the serial port and see output from the leostick.

step 3: I built the blink sketch from the examples in the arduino IDE.  I had built a native version of avrdude and put it in the right place in the arduino tree.  I tried using the upload using programmer menu item but this errored out.  I replaced avrdude with a script that logged the command line parameters and tried to manually run avrdude with the logged parameters but had the same errors.  After a bit of fumbling around I found that some of the avrdude parameters weren't right for my environment plus I could only upload a sketch when the bootloader was active (the first 7 seconds after reset).  So, I finally managed to upload a sketch by firstly pressing reset and then running the command:

/usr/pkg/bin/avrdude -C/home/user/blymn/arduino-1.0.1/hardware/tools/avrdude.conf -patmega32u4 -carduino -P/dev/ttyU1 -Uflash:w:/tmp/build1833870341762611968.tmp/Blink.cpp.hex:i -v

I was still stumped for a while because it seemed like I couldn't upload a sketch without doing a reset but adding the option to force the baud rate to 1200 would let me upload again without resetting:

/usr/pkg/bin/avrdude -C/home/user/blymn/arduino-1.0.1/hardware/tools/avrdude.conf -patmega32u4 -carduino -P/dev/ttyU1 -Uflash:w:/tmp/build1833870341762611968.tmp/Blink.cpp.hex:i -v -b 1200

The only problem now is that the NetBSD usb drivers detach from the leostick and don't reattach when a sketch is uploaded when a sketch is already running so I still need to reset the leostick to get the devices back... inconvenient.


No comments: