Win a free ISP/TPI/PDI Programmer!

Where?

That’s right folks! Only here do you get the chance to win one of three AVRISP-MKII clone programmers, ready made and shipped to you entirely for free! These three programmers are all the new V1.1a board revision of Tom’s excellent design and manufacture, worth US$33 each. Tom sent me one a few weeks ago to test out, and I’m so happy with it I thought I’d buy three from him and give them away here to LUFA users. This is the programmer I’m talking about:

What?

The USBTINY-MKII programmer features high speed ISP, TPI and PDI programming (for all 8-bit AVRs, including the new 6-pin TINY and the gigantic XMEGA chips) as well as native AVRStudio 4 compatibility, logic level translation, target powering from the USB bus, and easy firmware upgrades via the USB interface. At the core of the programmer is an AT90USB162, running my LUFA AVRISP-MKII firmware. That means the programmer itself is open source, and you’ll receive future updates for it through the regular LUFA releases.

For more information of the USBTINY-MKII programmer, see Tom’s website page about it.

How?

How do you win one? Simple. Just submit a full bug report for a reproducible bug in the current SVN repository, LUFA 100807 BETA package or (eventually) the 100807 official release via email, and you’ll go into the draw. At the end of August, I’ll randomly select three bug reporters as the winners of one of these most excellent pieces of hardware. That’s it – you don’t even need to post a fix for the bug, just report it. The more new bug reports you submit, the more chances you have to win.

All eligible bug reports must be submitted to me before the 30th of August, 2010, and must contain full details of how to reproduce the bug, including the exact version/revision of LUFA, the hardware and software used.

You can download the current 100807 BETA and – when it is ready – official release from the LUFA project page. Happy hunting!

 

LUFA 100807 BETA is out!

I finally feel the time is right to release the next public beta version of LUFA, scheduled for a full release on the 7th of next month – giving two whole weeks for me to complete the USB Test and Measurement Class code I’ve started (special thanks to Peter Lawrence for his amazing research into it) and for everyone else to download, test, and report back any problems.

This new beta contains a large number of internal changes, as well as the usual user visible improvements to the APIs, demos, projects and bootloaders. Bugs have been fixed, but I’ve also gone to a lot of effort to clean up sections of the internal library core code, so that (in theory, at least) ports to different architectures will be less difficult to achieve. There’s still some work to be done there, but the groundwork I’ve laid so far will mean that if the library does become targeted to multiple platforms, it shouldn’t become an (even bigger) gigantic pile of preprocessor macros.

Notably, I’ve converted over all the pseudo-functions used heavily in the library to real static inline functions. That gives several benefits – the documentation and code is now always in-sync, the static inline functions are properly type-checked and syntax checked at compile time, and the functions can be extended with more complicated implementations as needed when and if the library is ported to different architectures. Overall I’m quite happy with this, as it has already uncovered a fault in an obscure pipe interrupt macro, which has apparently been there since the dawn of time.

I implore everyone to please, please download, test and report back on the new beta version. The more issues that are uncovered now, the less issues that will be in the official release in two weeks. I hate seeing bugs in the release packages, as it means the fixed version won’t enter wide circulation until the following release, since most sane people don’t pull straight from the repository mirrors in production project code. I’ve uploaded the beta downloads and documentation to the regular LUFA project page, so that it will get maximum exposure throughout the beta testing window.

If you uncover any issue with the beta release, please let me know as soon as possible so that I have as long as possible to correct it.

Direct download of the 100807 BETA package

Direct download of the 100807 prebuilt documentation package


New:

  • Added new ADC_DisableChannel() function (thanks to Mich Davis)
  • Added new VTARGET_REF_VOLTS and VTARGET_SCALE_FACTOR compile time defines to the AVRISP-MKII programmer project to set the VTARGET reference voltage and scale factor
  • Added new pgm_read_ptr() macro to Common.h for reading of pointers out of flash memory space
  • Added new SWAPENDIAN_16() and SWAPENDIAN_32() macros to Common.h for statically initialized variables at compile time
  • Added new Drivers/USB/LowLevel/Device.c file to house Device mode specific functions that are more complicated than simple macros
  • Added new AVRStudio 4 project files for all library demos, projects and bootloaders
  • Added ability to set the serial baud rate via the user’s terminal in the XPLAINBridge project
  • Added new LUFA module variables for the different source modules in the core library makefile to simplify project makefiles
  • Added start of a new Test and Measurement class demo (thanks to Peter Lawrence)

Changed:

  • The RingBuff library code has been replaced in the XPLAINBridge, Benito and USBtoSerial projects with an ultra lightweight ring buffer to help improve the reliability of the projects
  • The EEPROM stream read/write functions now use eeprom_update_byte() instead of eeprom_write_byte(), so that only changed bytes are written to EEPROM to preserve its lifespan
  • Changed over the AVRISP-MKII and TemperatureDataLogger projects to use eeprom_update_byte() when writing non-volatile parameters to EEPROM to preserve its lifespan
  • Removed unused line encoding data and control requests from the CDC Bootloader code, to save space
  • Renamed SERIAL_STREAM_ASSERT() macro to STDOUT_ASSERT()
  • The USB_Device_IsRemoteWakeupSent() and USB_Device_IsUSBSuspended() macros have been deleted, as they are now obsolete
  • Rewrote the implementation of the SwapEndian_16() and SwapEndian_32() functions so that they compile down in most instances to minimal loads and stores rather than complicated shifts
  • The software UART in the XPLAINBridge has been largely altered to try to improve upon its performance and reliability
  • The USBtoSerial project now flushes received data via a flush timer, so that several bytes can be transmitted at once
  • Removed the automated checking of event names in the demo, project and bootloader makefiles due to inconsistancies between the behaviour of the command line tools used to perform the check on each platform
  • Internal USB driver source files renamed and moved to ease future possible architecture ports
  • All internal pseudo-function macros have been converted to true inline functions for type-safety and readability

Fixed:

  • Fixed AVRISP project sending a LOAD EXTENDED ADDRESS command to 128KB AVRs after programming or reading from the last page of FLASH (thanks to Gerard Sexton)
  • Fixed AVRISP project not sending a full erase-and-write EEPROM command to XMEGA targets when writing to the EEPROM instead of the split write-only command (thanks to Tim Margush)
  • Fixed RNDISEthernet demos crashing when calculating checksums for Ethernet/TCP packets of more than ~500 bytes due to an overflow in the checksum calculation loop (thanks to Kevin Malec)
  • Fixed XPLAINBridge project not correctly reading the XMEGA’s supply voltage when reporting back to the host
  • Fixed incorrect signature for the ATMEGA32U2 in the DFU bootloader (thanks to Axel Rohde)
  • Fixed internal device serial not being accessible on the ATMEGAXXU2 AVRs (thanks to Axel Rohde)
  • Fixed void pointer arithmetic in ConfigDescriptor.h breaking C++ compatibility (thanks to Michael Hennebry)
  • Fixed broken PDI EEPROM Section Erase functionality in the AVRISP-MKII project
  • Fixed USB_Device_SendRemoteWakeup() not working when the USB clock was frozen during USB bus suspend (thanks to Brian Dickman)
  • Fixed occasional lockup of the AVRISP project due to the timeout extension code incorrectly extending the timeout in PDI and TPI programming modes infinitely
  • Fixed HID device class driver still using PrevReportINBuffer for GetReport control requests even when it has been set to NULL by the user application (thanks to Axel Rohde)
  • Fixed MIDI_Device_SendEventPacket() not correctly waiting for the endpoint to become ready (thanks to Robin Green)
 

LUFA Feature Focus: Source Modules

Last week I decided to download the latest Atmel Toolchain beta package from their rather well hidden beta site. This new toolchain is the spiritual successor to the WinAVR project — actually, it’s the same thing, except now it’s officially endorsed by Atmel, and it’s still being produced by the same guy. The new toolchain package contains updated avr-libc, binutils and avr-gcc versions, which means lots of bugs fixed, and new features to discover. One of the big changes to the new Atmel branded toochain package over the older WinAVR package is the presence of AVR32 versions of the tools; the one package now serves both the 8-bit and more powerful AVR-32 models. This means a single download serves the entire AVR lineup, reducing developer confusion.

So far, I’ve had a few teething troubles; the new Atmel AVR Toolchain package is missing a lot of the neat *nix tools that WinAVR included, such as grep. The existing makefiles of LUFA made use of these tools to process the source code to automate some tasks, but that’s now got to change. Biting the bullet, I’ve remade all of the LUFA project makefiles, so that with one exception (the main library core makefile’s doxygen target) these special tools aren’t needed anymore.

While I was at it, I decided to finally get around to doing something I’ve been wanting to do to the makefiles for a long time; make the core library makefile includable in the project makefiles. This has the distinct advantage of being able to inject extra common targets into the project makefiles as needed (say, to check for invalid events if I find a way to re-add it without the grep dependencies) but also the advantage of being able to list the module source files in the one place.

Why is this neat? It means that no longer do you need to care about what I call the source files inside the library core. I can now move and rename them as I see fit, and the user projects will still compile, providing they use the new “module source” names I’ve added to the makefile. Here’s an example of what the makefile source list use to look like for a typical class driver demo:

# List C source files here. (C dependencies are automatically generated.)
SRC = $(TARGET).c                                                 \
      Descriptors.c                                               \
      $(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/DevChapter9.c        \
      $(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Device.c             \
      $(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Endpoint.c           \
      $(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Host.c               \
      $(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/HostChapter9.c       \
      $(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/LowLevel.c           \
      $(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/Pipe.c               \
      $(LUFA_PATH)/LUFA/Drivers/USB/LowLevel/USBInterrupt.c       \
      $(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/ConfigDescriptor.c  \
      $(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/Events.c            \
      $(LUFA_PATH)/LUFA/Drivers/USB/HighLevel/USBTask.c           \
      $(LUFA_PATH)/LUFA/Drivers/USB/Class/Device/CDC.c            \
      $(LUFA_PATH)/LUFA/Drivers/USB/Class/Host/CDC.c              \
      $(LUFA_PATH)/LUFA/Drivers/USB/Class/Device/HID.c            \
      $(LUFA_PATH)/LUFA/Drivers/USB/Class/Host/HID.c

Which is, let’s face it, damned ugly and hard to maintain. Instead, here’s how the new system works:

# Create the LUFA source path variables by including the LUFA root makefile
include $(LUFA_PATH)/LUFA/makefile
 
# List C source files here. (C dependencies are automatically generated.)
SRC = $(TARGET).c                                                 \
      Descriptors.c                                               \
      $(LUFA_SRC_USB)                                             \
      $(LUFA_SRC_USBCLASS)

Which is much neater – once the library core makefile is included (with the LUFA_PATH value set beforehand) the new module source names become available. In the documentation, just look for the module names rather than the source names, and add those as needed to your project makefile. Of course, you can still use your existing makefiles, but this new system means less restrictions on how I internally structure the library code.

Finished Bluetooth code or not, it’s about time I thought about releasing all the changes I’ve made to the project over the last two months, so I’ll be releasing a public beta version in a few days.

 

XPLAIN Bridge Firmware Update

Today I wasted a good portion of my day running around my University trying to get the forms I need for my Norwegian Visa application for my internship at Atmel in November. Ever seen the Hitchhiker’s Guide to the Galaxy movie, the scene where they try to free Trillian by filling out all the bureaucratic forms, and are forced to line up several times, each time with a different form? Today was like that, but worse, since half the staff are away on leave during the mid-year break, and the remaining staff are on lunch break. After all my trouble, I’ve now got to go back next week and pick up my $25 form letter stating that yes, I am indeed a student at Latrobe. Bah.

Now, back to the good stuff. I believe that every programmer has an Achilles Heel, that one algorithm that everyone else seems to have no trouble with, but for that person it causes endless frustration and misery. For me, that algorithm is the implementation of a software U(S)ART. I’ve now written and re-written different implementations several times, and although they eventually work, my bidirectional software UARTs always seem to miss the occasional character.

A software UART is supposed to be a simple affair – after all, with the most common 8-bit, no parity, one stop bit setting that many devices use, each frame is just the raw bytes framed by a low start and a high stop bit. This translates to some fairly simple code, which is usually run in a timer ISR to ensure that the timing of each bit is constant, to prevent reception errors at either end.

A unidirectional UART is possibly the easiest algorithm to get working, with the exception perhaps of a software SPI port. It’s when the requirements are for a bidirectional software UART that things get hairy, since now you’ve got to work out how to prevent the bit transmission and reception ISRs from tripping each other up and delaying the other long enough to corrupt the transfer. This is needed in my XPLAIN Bridge firmware for Atmel’s XPLAIN board, when the bridge operates as a USB to Serial converter. Since the AVR’s hardware UART is instead used as the PDI programmer transport to the XMEGA chip on the board, the serial channel is instead implemented in software on the USB AVR side.

It’s not just me that’s had trouble with this algorithm however; recognizing that it’s not as simple as it appears I originally outsources the software UART code on AVRFreaks, and ended up with an ASM and a C implementation from two kind members there. Both of these worked, but things got wonky when both ends of the link tried to send at the same time, as the transmission and reception code blocked each other.
After some complaints about my less-than-perfect UART code, I took yet another crack at it last night, trying to fix up the implementation so that lost characters would be the exception, rather than the rule. This has led to my new implementation of the software UART, which uses two timers and an external interrupt pin. This new implementation uses one timer for bit transmissions – each bit period, either the next bit to send is transmitted, or the next byte to send is loaded into a temporary buffer so that it can be shifted out. The reception code relies on an external interrupt pin to sense the start bit, which then starts the bit reception timer to shift in the incoming bits.

Additionally, I found that the Windows CDC driver does not like mostly-empty incoming packets, even though it is quite happy to issue them to attached devices – I found my Windows 7 machine locking up when I barraged it with a constant stream of single-byte packets (one for each incoming character). This also lead to the reception buffer being overflown due to the host not processing the packets fast enough, which corrupted the incoming data stream occasionally. To combat this, the bridge code has a third timer which flushes the current reception buffer contents to the host in a single packet rapidly (30 flushes a second) to aggregate multiple bytes into a single USB IN packet.

Tests on the latest code show this new code to be far, far more reliable that the old, although large streams in both directions can still cause some issues. I’d like some more testers on this before the next official release to get a wider opinion on the new code’s performance – I’ve started uploading pre-built versions of the project to the XPLAIN Bridge project page for convenience.

 

Something, Something, Title, Something

Something something AVR, something something Bluetooth, something.

Sorry, I’m a little distracted today – it’s a special day! My girlfriend decided to show her baking prowess (and knowledge of the T1 line to my heart) through this creation:

Has it been four years already? I think I need to go lie down. Regular programming will return next week. For now, there’s cake.