Topics

Update QCX Firmware to v1.05 notes (Linux command line, breadboard programmer) #qcx #firmware

Jonathan Dog
 

I'm in the process of building my QCX-40 and wanted to upgrade the firmware.

I thought perhaps my notes on how to do this from Linux command line might help.

I did it with:

  • QCX'sATMega328P on a breadboard, no QCX used at all
  • Ubuntu 18.04 command line
  • Avrdude 6.3 (installed with sudo apt-get install avrdude)
  • Arduino Nano as the programmer (it's an ATMega 328p with FTDI serial-to-USB interface, running at 5V)
    • An Arduino Uno should be the same, other Arduinos would work except wiring is a little different
  • ArduinoISP firmware on the Nano (programmed with Arduino developer's IDE)
  • Additionally: a crystal (anything above 8MHz should be fine, I used 12 MHz), a 10μF capacitor (biggish, non critical), optionally some LEDs and resistors

This task is perfectly possible with other kinds of Arduino, I used a Nano because I had one handy; they are very similar to the Uno. I use cheapest possible ones from Ebay, which are about EUR 4.

Task 1: Firmware on the Nano

  • Step 1: Get the Nano, solder its connectors if necessary
  • Step 2: Get a computer which runs Arduino developer IDE (mine is v1.8.12)
  • Step 3: Program the Nano with "blink" to verify it works from File > Examples > 01 Basics > Blink (if you don't know how to do this, read any "first steps Arduino" tutorial)
  • Step 3a: Don't continue if you can't get step 3 to work
  • Step 4: Program the Nano with File > Examples > 11. ArduinoISP > ArduinoISP

Usually the only problem with programming the Nano is getting the right details into the Arduino software so it can be programmed.

My values in the Tools menu were

  • Board: Arduino Nano
  • Processor: ATMega 328P (old bootloader)
  • Port: /dev/ttyUSB0

Once you've done this, you now have an Arduino Nano which is an Atmega ISP programmer. That's the end of all the Arduino business: now we're strictly dealing with ATMegas as CPUs.

Task 2: Programmer Wiring

"Programmer" is the Nano; "Target" is the 328P chip from your QCX.

  • If it's not a Nano or Uno All the programmer pins are different, but the target pins are the same
  • Programmer RST to 10μF to GND
  • Programmer D7 to Green LED to 1K R to GND (programming), optional but sensible
  • Programmer D8 to Red LED to 1K R to GND (error), optional but sensible
  • Programmer D9 to Yellow LED to 1K R to GND (heartbeat), optional but sensible
  • Programmer D10 to target pin 1 Reset and also 10K resistor to VCC
  • Programmer D11 to target pin 17 MOSI
  • Programmer D12 to target pin 18 MISO
  • Programmer D13 to target pin 19 SCK
  • Target pin 7 VCC to 5V
  • Target pin 8 GND
  • Target pin 9 OSC1 to crystal
  • Target pin 10 OSC2 to crystal
  • Target pin 20 AVCC to 5V
  • Target pin 22 GND to GND

If you want to know what this circuit is, see Section 28.8 "Serial Downloading" of the ATMega 328P datasheet. In brief, during startup, the CPU can be programmed or read by sending it special values on its clocked serial interface (MOSI, MISO, SCK -- Master-In-Slave-Out, Master-Out-Slave-In, Serial-Clock). This is the mechanism used on the In-System-Programming interface (ISP) of the QCX and many other microcontroller systems. http://ww1.microchip.com/downloads/en/DeviceDoc/ATmega48A-PA-88A-PA-168A-PA-328-P-DS-DS40002061A.pdf

The reason for the 10μF capacitor is this: the avrdude software signals DTR on the serial interface; this is connected to the /RESET line of the Nano BUT we don't want it to reset. So we put a big capacitor there to defeat this. Different models of 328-based Arduino might or might not need this. Arduinos with ATmega 32u4 do not need this.

Note that the crystal is required. It doesn't have to be a 20 MHz crystal like in the QCX, just something similar. I used a 12 MHz one because that's what I had. Although most ATMega designs will show small capacitors on each leg of the crystal (to ground), they are not on the QCX and my programming worked without them. If you use this circuit to program other 328P devices (not from QRP Labs), be aware that you may need some other kind of clock on these pins (external oscillator, nothing, resonator), depending on the fuse bits (specifically CKSEL and SUT of the Low Fuse).

Task 3: Read your existing firmware

Do not leap without looking.

You need to know the device name you used to contact your Nano. Mine was /dev/ttyUSB0. Change it in all following commands if yours is different.

When you connect the USB to the Nano you should see the LEDs flash briefly, then the yellow "heartbeat" LED beat at about 1 Hz.

Check everything works by reading the current firmware:

$ avrdude -c stk500v1 -P /dev/ttyUSB0 -b 19200 -p m328p -v -U flash:r:BEFORE.hex:i
           |           |               |        |        |   |     
           |           |               |        |        |   + read flash, write to `BEFORE.hex` in Intel format
           |           |               |        |        + verbose
           |           |               |        + part (must be this)
           |           |               + baud rate (don't change this)
           |           + serial port (which you found out before
           + protocol (don't change this)

Task 4: Write your new firmware

Uncompress your T1.05.zip $ unzip T1.05.zip

Now give the program command:

$ avrdude -c stk500v1 -P /dev/ttyUSB0 -b 19200 -p m328p -v -U flash:w:T1.05.hex:i

Note the part at the end is now w for write (to the target) reading from your file T1.05.hex which you got from QRP Labs.

avrdude: Version 6.3
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "/etc/avrdude.conf"
         User configuration file is "/home/jdog/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : /dev/ttyUSB0
         Using Programmer              : stk500v1
         Overriding Baud Rate          : 19200
         AVR Part                      : ATmega328P
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PC2
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65    20     4    0 no       1024    4      0  3600  3600 0xff 0xff
           flash         65     6   128    0 yes     32768  128    256  4500  4500 0xff 0xff
           lfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           lock           0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

         Programmer Type : STK500
         Description     : Atmel STK500 Version 1.x firmware
         Hardware Version: 2
         Firmware Version: 1.18
         Topcard         : Unknown
         Vtarget         : 0.0 V
         Varef           : 0.0 V
         Oscillator      : Off
         SCK period      : 0.1 us

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.02s

avrdude: Device signature = 0x1e950f (probably m328p)
avrdude: safemode: hfuse reads as D1
avrdude: safemode: efuse reads as FC
avrdude: NOTE: "flash" memory has been specified, an erase cycle will be performed
         To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file "T1.05.hex"
avrdude: writing flash (32678 bytes):

Writing | ################################################## | 100% 36.14s

avrdude: 32678 bytes of flash written
avrdude: verifying flash memory against T1.05.hex:
avrdude: load data flash data from input file T1.05.hex:
avrdude: input file T1.05.hex contains 32678 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 20.00s

avrdude: verifying ...
avrdude: 32678 bytes of flash verified

avrdude: safemode: hfuse reads as D1
avrdude: safemode: efuse reads as FC
avrdude: safemode: Fuses OK (E:FC, H:D1, L:D7)

avrdude done.  Thank you.

Wes AE6ZM
 

Well done Jonathan! Would you pdf this and post to Files? I know many could use the guidance.
--
> I finally got it all together...now I can't remember where I put it<

VY 73,
Wes

AE6ZM

Sierra Vista, AZ

 

Kirk KD0J
 

Thanks very much. Worked perfectly without a hitch.

73,
Kirk
KD0J
Salt Lake City, UT

Jacques - ZS1PL
 

Thanks Jonathan, this really helped me to get my QCX running again with the latest FW. It is worth noting to others that you need to use this method to reprogram an existing QRPLabs chip to make it work. Using a new blank 328 chip will not work unless you also set the fuses to their correct value, and also burn the EEPROM default values. For these values you will need to email Hans.

73 de Jacques ZS1PL