Please don’t forget to read this post before coming here.
For the newly developed Phoenix-MDK, I suggested few hardware modifications. Among them was the hardware modification for resetting the Phoenix-MDK through software i.e the user doesn’t have to press the reset button on the board to load a new program. I copied the design of software resetting from Arduino project.
The plan was to reset the controller using two pins i.e there was a pin (RTS) coming from the FTDI chip connected via a 100Kohm resistor to the reset pin of the ATMega32 and also a pin (DTR) from FTDI chip connected via a 100Kohm resistor to the PD2 pin of ATMega32. The two 100Kohm resistor was for current limit. So when the user wants to flash a software, he has to hold the PD2 down (because bootloader will wait for code from serial port only if this pin is low), send LOW pulse on RESET. Then Avrdude loads the code, take PD2 high and then send a Reset pulse again.
When I checked the Arduino design, they were only using the RESET pin to load the software using Avrdude. Arduino bootloader loaded the code in the following manner – Send a reset pulse. The bootloader will wait for the software from serial port . If the data is coming, then they will write the flash memory using that data or else they will jump to the main code. The greatest advantage over here was of using only one pin (DTR) of the FTDI chip to load the software.
I adapted the same design to the Phoenix-MDK. Now The other pin (RTS) need not be used i.e the DTR pin of FTDI chip was connected to the RESET pin of ATMega32 via 100nF capacitor. So we saved one pin (PD2) of ATMega32 which is not used in the new design.
The below python code can flash code to Phoenix-MDK (written by Pramode).
import serial, time
import os, sys
fd = serial.Serial(port='/dev/ttyUSB0', baudrate=19200)
cmd = 'avrdude -b 19200 -P /dev/ttyUSB0 -pm32 -c stk500v1 -U ' + sys.argv
1) Save the above code as load.py
2) Write the code which you want to run on ATMega32 and Compile the code using avr-gcc.
avr-gcc -mmcu=atmega32 -Os filename.c
3) Convert a.out to hex file
avr-objcopy -j .text -j .data -O ihex a.out a.hex
4) Load the hex to Phoenix-MDK
python load.py a.hex
Update: I will soon upload the pics of newly developed Phoenix-MDK .
Today I got a chance to do some hacks on Phoenix-MDK. There was a need of a bootloader for this board. Along with that, we should be able to program the board without hitting any reset switch. The first thing which came into my mind was the arduino boards. They had all the above mentioned features. So I started understanding how the arduino board works, which boot loader is used inside, how reset can be triggered through software etc.
The bootloader used in arduino’s are the optiboot which has a very small footprint (around 512kb) and it was using the serial protocol STK500 for its communication. So I took the optiboot and made some modifications. But it failed. I don’t know where I went wrong and also I bricked one ATMega32 chip.
I had one more ATMega32 chip with me. But this time I was really careful not to brick again a chip. It was really hard to find a bootloader. After a long search I found this page which really helped me a lot – http://wiki.edwindertien.nl/doku.php?id=software:bootloaders
The bootloader can be obtained from http://wiki.edwindertien.nl/lib/exe/fetch.php?media=software:atmegaboot-32.zip. Phoenix-MDK uses 8MHz crystal. So I had to modify a line in the makefile which contains the clock frequency to AVR_FREQ = 8000000L . Thats all. I gave a make and got the hex file.
Below are the steps for flashing the bootloader and using it.
1) Flashing the bootloader using parallel programmer
flashing the hex:
avrdude -c dapa -patmega32 -U flash:w:ATmegaBOOT_168_atmega32.hex
flashing the fuse:
avrdude -c dapa -patmega32 -U lfuse:w:0xff:m -U hfuse:w:0xda:m
2) Testing the bootloader
avrdude -b 19200 -P /dev/ttyUSB0 -pm32 -c stk500v1 -n
This should give a proper response.
3)Uploading a hex file using the serial bootloader
avrdude -b 19200 -P /dev/ttyUSB0 -pm32 -c stk500v1 -U flash:w:a.hex
For the above code to work on Phoenix-MDK, I also had to do some hardware hack. Now the DTR pin is connected to the reset pin so that reset can be done by software. I have to find a software way to reset the chip.
Today I fabricated the PCB for GNUduino (Arduino made with gEDA). I used screen printing to transfer the PCB layout. Screen printing is another way to transfer the PCB layout to the copper clad instead of the conventional toner transfer method. Download GNUduino design files
The PCB was successfully fabricated and also tested the LED blink sketch. Everything is working fine.
NOTE: The below shown are only prototype’s to verify the design. High quality PCB’s cab be made with the design files.
Here are some snapshots
The screen printed copper clad’s
Etching the PCB
After drilling holes
GNUduino is ready