A fork of mAVRISP by Aaron Berk. This version does not use a local file system to hold the AVR program. Instead it uses a serial connection to a PC and a python script to send the AVR program to the mbed.
Fork of mAVRISP by
Diff: main.cpp
- Revision:
- 0:3066745764a5
- Child:
- 1:276f6df4be7a
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Aug 31 14:09:53 2010 +0000 @@ -0,0 +1,75 @@ +/** + * Program an AVR with an mbed. + */ + +#include "AVR910.h" + +LocalFileSystem local("local"); +Serial pc(USBTX, USBRX); +AVR910 mAVRISP(p5, p6, p7, p8); //mosi, miso, sclk, nreset. + +int main() { + + int success = -1; + int response = 0; + + //Read the vendor code [0x1E == Atmel]. + response = mAVRISP.readVendorCode(); + + if (response == ATMEL_VENDOR_CODE) { + pc.printf("Microcontroller is an Atmel [0x%02x]\n", response); + } else if (response == DEVICE_LOCKED) { + pc.printf("Device is locked\n"); + return -1; + } else { + pc.printf("Microcontroller is not an Atmel\n"); + return -1; + } + + //Read part family and flash size - see datasheet for code meaning. + response = mAVRISP.readPartFamilyAndFlashSize(); + + if (response == 0xFF) { + pc.printf("Device code erased or target missing\n"); + } else if (response == 0x01) { + pc.printf("Device locked\n"); + return -1; + } else { + pc.printf("Part family and flash size code is: 0x%02x\n", response); + } + + //Read part number. + response = mAVRISP.readPartNumber(); + + if (response == 0xFF) { + pc.printf("Device code erased or target missing\n"); + return -1; + } else if (response == 0x02) { + pc.printf("Device locked\n"); + return -1; + } else { + pc.printf("Part number code is: 0x%02x\n", response); + } + + //Open binary file to write to AVR. + FILE *fp = fopen(PATH_TO_BINARY, "rb"); + + if(fp == NULL){ + pc.printf("Failed to open binary. Please check the file path\n"); + return -1; + } + else{ + //Program it! + pc.printf("Binary file opened successfully\n"); + success = mAVRISP.program(fp); + fclose(fp); + } + + if(success < 0){ + printf("Programming failed.\n"); + } + else{ + printf("Programming was successful!\n"); + } + +}