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:
- 3:df6782d01720
- Parent:
- 1:276f6df4be7a
- Child:
- 4:ceee1eb7062e
--- a/main.cpp Thu Sep 09 11:11:37 2010 +0000 +++ b/main.cpp Sat Jan 31 21:54:05 2015 +0000 @@ -4,18 +4,26 @@ #include "AVR910.h" -LocalFileSystem local("local"); +//LocalFileSystem local("local"); Serial pc(USBTX, USBRX); -AVR910 mAVRISP(p5, p6, p7, p8); //mosi, miso, sclk, nreset. +//AVR910 mAVRISP(PA_7, PA_6, PA_5, PB_6); //mosi, miso, sclk, nreset. +//AVR910 mAVRISP(PB_5, PB_4, PB_3, PA_10); //mosi, miso, sclk, nreset. +AVR910 mAVRISP(PB_15, PB_14, PB_13, PB_2); //mosi, miso, sclk, nreset. -int main() { +DigitalOut working(LED1); + +int main() +{ + working = 1; int success = -1; int response = 0; + pc.printf("Starting\n"); + //Read the vendor code [0x1E == Atmel]. response = mAVRISP.readVendorCode(); - + printf("vendorcode=%d\n",response); if (response == ATMEL_VENDOR_CODE) { pc.printf("Microcontroller is an Atmel [0x%02x]\n", response); } else if (response == DEVICE_LOCKED) { @@ -51,19 +59,47 @@ } //Open binary file to write to AVR. - FILE *fp = fopen(PATH_TO_BINARY, "rb"); + //FILE *fp = fopen(PATH_TO_BINARY, "rb"); + printf("@"); + + int hs, ls; + while (!pc.readable()); + hs = pc.getc(); + printf("hs=%d\n",hs); + while (!pc.readable()); + ls = pc.getc(); + printf("ls=%d\n",ls); + int fileSize = (hs<<8) + ls; + printf ("file size = %d\n", fileSize); - 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, - ATMEGA328P_PAGESIZE, - ATMEGA328P_NUM_PAGES); - fclose(fp); + printf("#"); + + char *myFile; + myFile = new char [fileSize]; + int readChar=0; + while (readChar < fileSize) { + if (pc.readable()) { + myFile[readChar]=pc.getc(); + readChar++; + } + } + for (int i=0; i<fileSize; i++) { + printf("r %d: 0x%02x\n",i, myFile[i]); } + wait_ms(1000); + success = mAVRISP.programData(myFile, fileSize, ATMEGA328P_PAGESIZE, ATMEGA328P_NUM_PAGES); + +// 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, +// ATMEGA328P_PAGESIZE, +// ATMEGA328P_NUM_PAGES); +// fclose(fp); +// } if (success < 0) { printf("Programming failed.\n"); @@ -72,3 +108,58 @@ } } + +/* Python file for on the pc: +import serial +import sys +import os + +fileName=sys.argv[1] +fileSize=os.path.getsize(fileName) + +serdev='/dev/ttyACM0' +s = serial.Serial(serdev) + +while True: + if s.readable(): + c = s.read() + if '@' in c: + print "Start sending file size\n" + hs = (fileSize>>8) & 0xff + s.write(chr(hs)) + ls = fileSize & 0xff + s.write(chr(ls)) + if '#' in c: + print "Start sending file\n" + with open(fileName, "rb") as f: + byte = f.read(1) + while byte != "": +# while not s.writable(): +# pass +# print "send: 0x",format(ord(byte),'02x') + s.write(byte) + byte = f.read(1) + else: + sys.stdout.write(c) +*/ + +/* avr test file: +#define F_CPU 1000000UL // 1 MHz +#include <avr/io.h> +#include <util/delay.h> + +int main(void) +{ +// Set Port D pins as all outputs +DDRD = 0xff; + +// Set all Port D pins as HIGH +while (1) { +PORTD = 0xFF; +_delay_ms(500.); +PORTD = 0x00; +_delay_ms(500.); +} +return 1; +} +*/ \ No newline at end of file