Monday, March 31, 2014

Intel Hex with Python

Needed to create an intelHex file in Python.  Luckily there is a nice existing package at https://launchpad.net/intelhex/+download.  After downloading to get it to work with Python 3 just type the following:

python3 setup.py build install

Then just import

from intelhex import IntelHex

and then you can setup a blank intelHex file

ihData = IntelHex()

and then add as follows:

ihData[indexHex] = first




Tuesday, March 11, 2014

Setting Xboot with xmega256a3

Been playing with Xboot for use with the xmega256a3.  You can find the Xboot code here.  In the conf folder there are some example configurations.  I copied x64a3.conf.mk and created xmega256a3.conf.mk and modified the parameters as follows (only listing those that I changed):

MCU = atxmega256a3
F_CPU = 32000000
AVRDUDE_PROGRAMMER = avrispmkii
USE_AVR1008_EEPROM = yes
USE_INTERRUPTS = yes
USE_WATCHDOG = yes
ENTER_BLINK_COUNT     = 5
ENTER_BLINK_WAIT      = 600000
WATCHDOG_TIMEOUT      = WDT_PER_8KCLK_gc
LED_PORT_NAME         = C
LED_PIN               = 0
LED_INV               = 1
UART_BAUD_RATE        = 230400
UART_PORT_NAME        = C
UART_NUMBER           = 0
UART_RX_PUEN          = yes

Wanted a longer delay while in boot mode so I increased the blink count to 5 and increased the wait.  I also modified the XBOOT code to support a baud rate of 230400.  This I did by adding the following code to xboot.h:

#elif (F_CPU == 32000000L) && (UART_BAUD_RATE == 230400)
#define UART_BSEL_VALUE         123
#define UART_BSCALE_VALUE       -4

#define UART_CLK2X              0

When the code modifications are done, now just need to compile.  To do this move or copy xmega256a3.conf.mk up a directory and then do:

make clean
make xmega256a3.conf.mk

then to program:

make program

in protocol.h there are a bunch of single character commands that you can enter while the LED is blinking and get response.  Such as 'S' which will respond with "XBoot++".

If you want to use avrdude to program the application section of flash just do the following:

avrdude -p atxmega256a3 -P /dev/tty.usbserial-FTFXXXX -c avr109 -b 230400 -U flash:w:twig_xmega256a3.bin -e

with -P being the serial port, -b the baud rate and -e indicating to erase the chip (this is very important cause I have not been able to get it to work without this option).