Notizbl0g.

h4cking, ham radio, fire fighting and m0re

Firmware Upgrade on DVmega Without Programmer

A while ago I stumbled accross a thread in the MMDVM Yahoo group about the firmware upgrade on DVmega PCBs [1]. The interesting note was that Tom ON4TOP managed to upgrade the firmware without the need for a programming adapter. This is especially of interest for all those who have a dualband DVmega because the ATmega CPU in this case is a SMD one. For the single band radio there is an easier solution: Just pull out the ATmega 328P DIL processor and reprogram it with an Arduino Uno. So I tried the direct programming of the controller for my dualband radio DVmega.

The only problem to manage is to pull the reset pin of the ATmega 328P to ground at the right time. Otherwise the bootloader will go straight on and start the firmware. Luckily there is an easy solution:

Let one GPIO pin of the Raspberry Pi control the reset pin of the ATmega CPU. There is some hack on the internet for avrdude [2] to manage this. With this autoreset script there is no need to manually ground the reset pin anymore. You just have to hook up some wire from the reset pin to one of the Raspberry Pi GPIOs.

I used the GPIO4 / Pin7 of the Raspberry Pi and connected it to the capacitor sitting right in the corner of the PCB. After hooking up the wire it is just a matter of installing the modified startup script for avrdude:

$ git clone https://github.com/openenergymonitor/avrdude-rpi.git
$ cd avrdude-rpi
$ sudo ./install

It is advisable that you run an apt-get update before. In my case the install script failed because it tried to download some old files ending with a 404 error.

After everything is installed you can download the new firmware and programm it to the ATmega CPU:

$ avrdude -p m328p -c arduino -P /dev/ttyAMA0 -b 115200 -F -U flash:w:DVMEGA_HB_V223_UNO.cpp.hex -v

avrdude-original: Version 6.1, compiled on Jul  7 2015 at 13:18:47
                  Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
                  Copyright (c) 2007-2014 Joerg Wunsch

                  System wide configuration file is "/etc/avrdude.conf"                                                               [40/195]
                  User configuration file is "/root/.avrduderc"
                  User configuration file does not exist or is not a regular file, skipping

                  Using Port                    : /dev/ttyAMA0
                  Using Programmer              : arduino
                  Overriding Baud Rate          : 115200
avrdude-original: Using autoreset DTR on GPIO Pin 7
                  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 : Arduino
                  Description     : Arduino
                  Hardware Version: 3
                  Firmware Version: 4.4
                  Vtarget         : 0.3 V
                  Varef           : 0.3 V
                  Oscillator      : 28.800 kHz
                  SCK period      : 3.3 us

avrdude-original: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.01s

avrdude-original: Device signature = 0x1e950f
avrdude-original: safemode: lfuse reads as 0
avrdude-original: safemode: hfuse reads as 0
avrdude-original: safemode: efuse reads as 0
avrdude-original: NOTE: "flash" memory has been specified, an erase cycle will be performed
                  To disable this feature, specify the -D option.
avrdude-original: erasing chip
avrdude-original: reading input file "DVMEGA_HB_V223_UNO.cpp.hex"
avrdude-original: input file DVMEGA_HB_V223_UNO.cpp.hex auto detected as Intel Hex
avrdude-original: writing flash (25062 bytes):

Writing | ################################################## | 100% 3.86s

avrdude-original: 25062 bytes of flash written
avrdude-original: verifying flash memory against DVMEGA_HB_V223_UNO.cpp.hex:
avrdude-original: load data flash data from input file DVMEGA_HB_V223_UNO.cpp.hex:
avrdude-original: input file DVMEGA_HB_V223_UNO.cpp.hex auto detected as Intel Hex
avrdude-original: input file DVMEGA_HB_V223_UNO.cpp.hex contains 25062 bytes
avrdude-original: reading on-chip flash data:

Reading | ################################################## | 100% 3.17s

avrdude-original: verifying ...
avrdude-original: 25062 bytes of flash verified

avrdude-original: safemode: lfuse reads as 0
avrdude-original: safemode: hfuse reads as 0
avrdude-original: safemode: efuse reads as 0
avrdude-original: safemode: Fuses OK (E:00, H:00, L:00)

From here on you can use the DVmega in combination with recent releases of MMDVMHost [3] for D-Star or DMR.

Please be aware that any modification to your rig may lead to a loss of warranty. Use this information at your own risk. I am not responsible for any damage to your equipment.

References

[1] https://groups.yahoo.com/neo/groups/mmdvm/conversations/topics/1558
[2] https://github.com/openenergymonitor/avrdude-rpi
[3] https://github.com/g4klx/MMDVMHost