summaryrefslogtreecommitdiffstats
path: root/commandline
diff options
context:
space:
mode:
authorTim <cpldcpu@gmail.com>2014-01-14 23:40:25 -0800
committerTim <cpldcpu@gmail.com>2014-01-14 23:40:25 -0800
commit993bed77e563054f12ac61b5d8f93e2cb548525e (patch)
tree7fc9a7dc6860dbb9823f646b261d4238d7fd802e /commandline
parent18e258ace5c610e1e40f53adaca402b46820f72a (diff)
parent34b0f0f0b6ef651bb30878341cba2a28a107d82d (diff)
downloadmicronucleus-993bed77e563054f12ac61b5d8f93e2cb548525e.tar.gz
micronucleus-993bed77e563054f12ac61b5d8f93e2cb548525e.tar.bz2
micronucleus-993bed77e563054f12ac61b5d8f93e2cb548525e.zip
Merge pull request #34 from micronucleus/testing
v1.11 - pull request
Diffstat (limited to 'commandline')
-rw-r--r--commandline/Makefile24
-rwxr-xr-xcommandline/builds/Mac/micronucleusbin20328 -> 0 bytes
-rwxr-xr-xcommandline/builds/OSX/micronucleusbin0 -> 124292 bytes
-rwxr-xr-xcommandline/builds/Windows/micronucleus.exebin70631 -> 26126 bytes
-rw-r--r--commandline/cdc232.hex173
-rw-r--r--commandline/library/micronucleus_lib.c53
-rw-r--r--commandline/littleWire_v11.hex356
-rw-r--r--commandline/micronucleus.c (renamed from commandline/examples/micronucleus.c)189
8 files changed, 150 insertions, 645 deletions
diff --git a/commandline/Makefile b/commandline/Makefile
index af9a9ee..3c52cb4 100644
--- a/commandline/Makefile
+++ b/commandline/Makefile
@@ -1,19 +1,25 @@
# Makefile initially writen for Little-Wire by Omer Kilic <omerkilic@gmail.com>
-# Later on modified by ihsan Kehribar <ihsan@kehribar.me> for Micronucleus bootloader application.
+# Later on modified by ihsan Kehribar <ihsan@kehribar.me> for Micronucleus bootloader application.
CC=gcc
-# FIXME: Need to add OSX stuff
ifeq ($(shell uname), Linux)
- USBFLAGS = `libusb-config --cflags`
- USBLIBS = `libusb-config --libs`
+ USBFLAGS=$(shell libusb-config --cflags)
+ USBLIBS=$(shell libusb-config --libs)
EXE_SUFFIX =
OSFLAG = -D LINUX
else ifeq ($(shell uname), Darwin)
- USBFLAGS = `libusb-config --cflags`
- USBLIBS = `libusb-config --libs`
+ USBFLAGS=$(shell libusb-config --cflags || libusb-legacy-config --cflags)
+ USBLIBS=$(shell libusb-config --libs || libusb-legacy-config --libs)
EXE_SUFFIX =
OSFLAG = -D MAC_OS
+ # Uncomment these to create a static binary:
+ # USBLIBS = /opt/local/lib/libusb-legacy/libusb-legacy.a
+ # USBLIBS += -mmacosx-version-min=10.5
+ # USBLIBS += -framework CoreFoundation
+ # USBLIBS += -framework IOKit
+ # Uncomment these to create a dual architecture binary:
+ # OSFLAG += -arch x86_64 -arch i386
else
USBFLAGS = -I C:\MinGW\include
USBLIBS = -L C:\MinGW\lib -lusb
@@ -36,11 +42,11 @@ library: $(LWLIBS)
$(LWLIBS):
@echo Building library: $@...
- $(CC) $(CFLAGS) -c library/$@.c
+ $(CC) $(CFLAGS) -c library/$@.c
$(EXAMPLES): $(addsuffix .o, $(LWLIBS))
- @echo Building example: $@...
- $(CC) $(CFLAGS) -o $@$(EXE_SUFFIX) examples/$@.c $^ $(LIBS)
+ @echo Building command line tool: $@...
+ $(CC) $(CFLAGS) -o $@$(EXE_SUFFIX) $@.c $^ $(LIBS)
clean:
rm -f $(EXAMPLES)$(EXE_SUFFIX) *.o *.exe
diff --git a/commandline/builds/Mac/micronucleus b/commandline/builds/Mac/micronucleus
deleted file mode 100755
index 057528a..0000000
--- a/commandline/builds/Mac/micronucleus
+++ /dev/null
Binary files differ
diff --git a/commandline/builds/OSX/micronucleus b/commandline/builds/OSX/micronucleus
new file mode 100755
index 0000000..3ae62c4
--- /dev/null
+++ b/commandline/builds/OSX/micronucleus
Binary files differ
diff --git a/commandline/builds/Windows/micronucleus.exe b/commandline/builds/Windows/micronucleus.exe
index 25b5ba4..bfdb56b 100755
--- a/commandline/builds/Windows/micronucleus.exe
+++ b/commandline/builds/Windows/micronucleus.exe
Binary files differ
diff --git a/commandline/cdc232.hex b/commandline/cdc232.hex
deleted file mode 100644
index 81fc38f..0000000
--- a/commandline/cdc232.hex
+++ /dev/null
@@ -1,173 +0,0 @@
-:1000000054C019C4F9C124C46BC06AC069C068C0B7
-:1000100067C066C065C064C063C062C03BC40403FF
-:10002000090422037700770077002E007200650034
-:10003000630075007200730069006F006E002E008F
-:100040006A00700010035500530042002D0032007A
-:10005000330032001201100102000008C016E10551
-:10006000000101020001090243000201008032097F
-:100070000400000102020100052400100104240212
-:100080000205240600010524010301070583030876
-:1000900000FF09040100020A000000070501020236
-:1000A0000000070581020800000011241FBECFE5F3
-:1000B000D2E0DEBFCDBF10E0A0E6B0E0EEEAFAE0AD
-:1000C00002C005900D92AC36B107D9F711E0ACE64D
-:1000D000B0E001C01D92AF33B107E1F758D3E5C4DA
-:1000E0008FCFAC9A8BB780628BBF8BE480937C0000
-:1000F0008093A7008AE580937B008093A6000895F3
-:100100001F93CF93DF93DC01162FEA01888184FFD0
-:1001100005C0898198E88927898302C08AE5888398
-:10012000AE014E5F5F4F212FFA018D9181932150D7
-:100130001216DCF3CA01612F48D11C5F1883DF91CE
-:10014000CF911F91089546EA50E0DADF08954BE71A
-:1001500050E0D6DF08951F93CF93DF9360918C001A
-:10016000635067FDB3C080918900CCE0D0E0C81B2C
-:10017000D109C057DF4F80918800803118F4CE013B
-:10018000EAD29EC08D3209F08BC0683009F098C069
-:1001900083EC809370008AE58093600010926C007D
-:1001A0008881807621F0CE01A8D2282F66C09A815E
-:1001B000109279008981882321F410927A0022E03C
-:1001C00055C0853019F490938D004FC08630B9F535
-:1001D0008B81813041F484E590E090938B00809393
-:1001E0008A0022E128C0823021F4CE0171D2282F6A
-:1001F00022C08330F9F48A81882341F48EE190E0B3
-:1002000090938B0080938A0024E015C0813041F4E4
-:1002100082E290E090938B0080938A0022E20BC0F0
-:10022000823041F484E490E090938B0080938A00C4
-:1002300020E101C020E080E480936C001EC0883083
-:1002400021F421E08FE890E013C0893019F49093F5
-:100250008F000BC08A3011F421E008C08B3029F4E4
-:100260008BE480937C008093A70020E089E790E0F6
-:1002700090938B0080938A0009C02F3F39F48881C6
-:1002800087FD2E8180E880936C0006C08F818823D3
-:1002900019F48E81821708F0822F8093610010C0BC
-:1002A00080916C0087FF0CC0CE01B7D28F3F21F444
-:1002B0008EE18093600004C0882311F010926100E9
-:1002C00080918C00181614F410928C0080916000BC
-:1002D00084FF58C0809161008F3F09F453C0182FEC
-:1002E000893008F018E0811B8093610080917000D4
-:1002F00098E8892780937000112391F180916C0018
-:1003000087FF08C081E790E0612F16D2182F89304F
-:1003100098F526C020918A0030918B0086FF0DC091
-:10032000A1E7B0E080E090E0F901E80FF91FE49167
-:10033000ED9301961817C1F708C0912FD901E1E795
-:10034000F0E08D9181939150E1F71150812F90E071
-:100350001F5F0196820F931F90938B0080938A00FA
-:1003600081E790E0612F31D0612F6C5F6C3041F0FC
-:100370008FEF8093610004C08FEF809361006EE186
-:100380006093600094E186B3887131F49150D9F79D
-:1003900010928D0010928700DF91CF911F910895E8
-:1003A000A82FB92F80E090E041E050EA609530E05E
-:1003B00009C02D9182279795879510F0842795275E
-:1003C000305EC8F36F5FA8F30895EADF8D939D93C5
-:1003D0000895A6E088279927AA9569F00197E1F387
-:1003E000B399FCCFB39BFECF81E09927A6B30196CA
-:1003F00011F0A871D9F70895CF93CFB7CF93C395D4
-:10040000B39BE9F7B39B0BC0B39B09C0B39B07C079
-:10041000B39B05C0B39B03C0B39B01C0D8C00F9270
-:10042000DF93C0918900DD27C057DF4F012EB39BBA
-:1004300003C0DF910F90E6CF2F930F931F934F933D
-:100440002FEF4F6F06B303FB20F95F933F9350E00C
-:100450003BE065C016B30126502953FDC89556B33D
-:10046000012703FB25F92F7306B3B1F0502710279E
-:1004700013FB26F906B22230F0F000C016B30127B4
-:1004800003FB27F90126502906B22430E8F54F77FF
-:10049000206816B30000F6CF50274F7D206206B2C9
-:1004A000102F000000C006B300265029102713FBB0
-:1004B00026F906B2E2CF4F7B06B3206400C0DACF44
-:1004C00001265029187106B269F14E7F2160012F73
-:1004D00016B328C0002650294D7F06B22260102F87
-:1004E00029C0012650294B7F06B22460012F2DC060
-:1004F00016B301265029477F2860000006B22EC09F
-:100500004F7E06B3206130C0422706B349930026D0
-:100510005029102706B24FEF13FB20F9297F16B39D
-:1005200079F2187159F10126502906B2012703FB0F
-:1005300021F9237F06B371F2002650293150D0F003
-:1005400006B2102713FB22F9277E16B351F20126BB
-:100550005029012703FB06B223F92F7C49F2000042
-:1005600006B3102713FB24F90026502906B22F7971
-:1005700039F270CF10E21ABF00271CC03B503195F2
-:10058000C31BD04010E21ABF0881033C21F10B3499
-:1005900011F1209187001981110F1213EDCF4A81BB
-:1005A000441F093669F10D3211F0013E29F74F70F1
-:1005B00009F0042F00938E003F915F914F911F919E
-:1005C0000F912F91DF910F90CAB7C5FD18CFCF9132
-:1005D000CFBFCF91189520918E00222369F31091FF
-:1005E0008C001123D1F53430D2F130938C0020935C
-:1005F0008800109189003BE0311B309389002FC0A7
-:1006000000918C0001304CF50AE54F7049F43091AF
-:10061000600034FD25C000936000C0E7D0E024C036
-:10062000433049F030917B0034FD1AC000937B00C9
-:10063000CCE7D0E019C03091A60034FD11C0009382
-:10064000A600C7EAD0E010C0052710E000C021C016
-:10065000052710E0C89508BB14C03AE501C032ED8B
-:10066000032EC0E0D0E032E017B31861C39A08B39C
-:1006700017BB58E120E84FEF20FF052708BB27955F
-:1006800017951C3F28F700004552B0F720FF0527BB
-:10069000279508BB17951C3FB8F629913A9561F745
-:1006A000077E10918D00110F08BBC250D04011F091
-:1006B0001093870010E21ABF086017B3177E402F0F
-:1006C000477E54E05A95F1F708BB17BB48BB74CF7F
-:1006D000FC018381813049F484E590E090938B00A4
-:1006E00080938A0080915400089586E690E090936C
-:1006F0008B0080938A0083E40895FC012081822F7F
-:1007000080768032B9F49181892F8052823010F442
-:100710008FEF0895923239F480916D00882319F497
-:1007200082E080936D0027FD05C081E08093B200D8
-:1007300080E0089580E00895FC0180916E00808340
-:1007400080916F008183128213821482158288E067
-:10075000868387E00895DC010BC0E92FF0E0E454C4
-:10076000FF4F8D9180839F5F9F7790933D016150F4
-:1007700090913D01662389F780913E018150891B4C
-:100780008F77823018F48FEF80938C0008952EE0DD
-:1007900088E190E00FB6F894A89581BD0FBE21BD09
-:1007A00080E090E07AD18F3F09F081BF87EE88BB6F
-:1007B00088E187BBA89584EC99E02CE931E0F90148
-:1007C0003197F1F70197D9F717BA80EC92E190933E
-:1007D0006F0080936E0080D084DC10926D001092C8
-:1007E000B2007894A895B7DCC2D090916D0099239F
-:1007F000C9F38091A60084FFF5CF923021F482E600
-:1008000090E068E003C08AE690E062E09CDC8091C2
-:100810006D00815080936D00E5CFFC018081809355
-:100820006E00818180936F0080916E0090916F00C7
-:1008300053D081E00895B299189501BB05B50FBD5D
-:1008400009E00DBD07E000BF00E20BBF01B3189542
-:1008500001BB0FB702BB0DB50A950DBD79F00BB505
-:100860000695B29900680BBD13BB0FB51EB5011BF1
-:100870000FBD13B302B30FBF01B3189500BF04BD82
-:100880000BB50DBB00E40ABF00E60BBF02B30FBF00
-:1008900001B3189501BBF09907C00BE40EB90EBB6C
-:1008A00008B50FB901B3189500E40EB900E003BF15
-:1008B00001B31895881F9795881F9795881F97955E
-:1008C000881F9795881F9795881F9795881F9795DC
-:1008D000881F9795892F08959C0181E080BD80E84D
-:1008E00088B9B99ABA988BB78F7B8BBF1ABC13BEE5
-:1008F00010BE80EE8EB984E58DB98FEF8FB9B90146
-:100900007695679580E090E06C5E70418C4F9F4FCC
-:1009100040E050E085D021502EBD8EB589BD1DBC74
-:100920008EB590E0019695958795959587958195DB
-:1009300085BD95B58EB5891718F08EB58F5F85BDCD
-:1009400082E08ABD81E084BD90E499BF85B78C7F49
-:10095000826085BF9ABF8BB780648BBF10923E01C7
-:100960001092BB0010923C0110923D01089584B595
-:10097000882379F49091BB00983058F48DB3E92F17
-:10098000F0E0ED54FF4F80839F5F9093BB0081E0C8
-:1009900084BD80917B0084FF12C06091BB00662300
-:1009A00021F48091B200882351F083EB90E0CFDBFB
-:1009B0008091BB0088708093B2001092BB0083B717
-:1009C000882369F5E0913E0180913D018E1739F150
-:1009D000F0E0E454FF4F80816DDF20913E012F5FF6
-:1009E0002F7720933E0112BE9BE49EB91EBA982F2A
-:1009F0009295907F9F6098BD8695F8948FB983E01B
-:100A000083BF789480918C0087FF09C080913D015D
-:100A10008095820F8F77823010F010928C000895AD
-:100A200097FB092E05260ED057FD04D014D00AD00E
-:100A3000001C38F450954095309521953F4F4F4F0D
-:100A40005F4F0895F6F790958095709561957F4F6B
-:100A50008F4F9F4F0895A1E21A2EAA1BBB1BFD01C9
-:100A60000DC0AA1FBB1FEE1FFF1FA217B307E4078D
-:100A7000F50720F0A21BB30BE40BF50B661F771FE5
-:100A8000881F991F1A9469F76095709580959095C5
-:100A90009B01AC01BD01CF010895E199FECF9FBB41
-:0E0AA0008EBBE09A99278DB30895F894FFCF8E
-:0C0AAE005AFFA12000000000020003001D
-:00000001FF
diff --git a/commandline/library/micronucleus_lib.c b/commandline/library/micronucleus_lib.c
index 6bbf04c..6e574f5 100644
--- a/commandline/library/micronucleus_lib.c
+++ b/commandline/library/micronucleus_lib.c
@@ -50,17 +50,19 @@ micronucleus* micronucleus_connect() {
nucleus->version.minor = dev->descriptor.bcdDevice & 0xFF;
if (nucleus->version.major > MICRONUCLEUS_MAX_MAJOR_VERSION) {
- fprintf(stderr, "Warning: device with unknown new version of Micronucleus detected.\n");
- fprintf(stderr, "This tool doesn't know how to upload to this new device. Updates may be available.\n");
- fprintf(stderr, "Device reports version as: %d.%d\n", nucleus->version.major, nucleus->version.minor);
- return NULL;
+ fprintf(stderr,
+ "Warning: device with unknown new version of Micronucleus detected.\n"
+ "This tool doesn't know how to upload to this new device. Updates may be available.\n"
+ "Device reports version as: %d.%d\n",
+ nucleus->version.major, nucleus->version.minor);
+ return NULL;
}
nucleus->device = usb_open(dev);
// get nucleus info
unsigned char buffer[4];
- int res = usb_control_msg(nucleus->device, 0xC0, 0, 0, 0, buffer, 4, MICRONUCLEUS_USB_TIMEOUT);
+ int res = usb_control_msg(nucleus->device, 0xC0, 0, 0, 0, (char *)buffer, 4, MICRONUCLEUS_USB_TIMEOUT);
assert(res >= 4);
nucleus->flash_size = (buffer[0]<<8) + buffer[1];
@@ -102,7 +104,7 @@ int micronucleus_eraseFlash(micronucleus* deviceHandle, micronucleus_callback pr
Assertion failed: (res >= 4), function micronucleus_connect, file library/micronucleus_lib.c, line 63.
*/
if (res == -5 || res == -34 || res == -84) {
- if (res = -34) {
+ if (res == -34) {
usb_close(deviceHandle->device);
deviceHandle->device = NULL;
}
@@ -119,38 +121,49 @@ int micronucleus_writeFlash(micronucleus* deviceHandle, unsigned int program_siz
unsigned int address; // overall flash memory address
unsigned int page_address; // address within this page when copying buffer
unsigned int res;
-
+ unsigned int pagecontainsdata;
+
for (address = 0; address < deviceHandle->flash_size; address += deviceHandle->page_size) {
// work around a bug in older bootloader versions
if (deviceHandle->version.major == 1 && deviceHandle->version.minor <= 2
&& address / deviceHandle->page_size == deviceHandle->pages - 1) {
page_length = deviceHandle->flash_size % deviceHandle->page_size;
}
+
+ pagecontainsdata=0;
// copy in bytes from user program
for (page_address = 0; page_address < page_length; page_address += 1) {
if (address + page_address > program_size) {
page_buffer[page_address] = 0xFF; // pad out remainder with unprogrammed bytes
} else {
+ pagecontainsdata=1; // page contains data and needs to be written
page_buffer[page_address] = program[address + page_address]; // load from user program
}
}
+ // always write last page so bootloader can insert the tiny vector table
+ if ( address >= deviceHandle->flash_size - deviceHandle->page_size )
+ pagecontainsdata = 1;
+
// ask microcontroller to write this page's data
- res = usb_control_msg(deviceHandle->device,
- USB_ENDPOINT_OUT| USB_TYPE_VENDOR | USB_RECIP_DEVICE,
- 1,
- page_length, address,
- page_buffer, page_length,
- MICRONUCLEUS_USB_TIMEOUT);
-
- // call progress update callback if that's a thing
- if (prog) prog(((float) address) / ((float) deviceHandle->flash_size));
-
- // give microcontroller enough time to write this page and come back online
- delay(deviceHandle->write_sleep);
+ if (pagecontainsdata) {
+ res = usb_control_msg(deviceHandle->device,
+ USB_ENDPOINT_OUT| USB_TYPE_VENDOR | USB_RECIP_DEVICE,
+ 1,
+ page_length, address,
+ (char*)page_buffer, page_length,
+ MICRONUCLEUS_USB_TIMEOUT);
+
+ if (res != page_length) return -1;
+
+ // give microcontroller enough time to write this page and come back online
+ delay(deviceHandle->write_sleep);
+ }
- if (res != page_length) return -1;
+ // call progress update callback if that's a thing
+ if (prog) prog(((float) address) / ((float) deviceHandle->flash_size));
+
}
// call progress update callback with completion status
diff --git a/commandline/littleWire_v11.hex b/commandline/littleWire_v11.hex
deleted file mode 100644
index a5c07e5..0000000
--- a/commandline/littleWire_v11.hex
+++ /dev/null
@@ -1,356 +0,0 @@
-:1000000042C05CC0DDC15AC059C058C057C056C0BC
-:1000100055C054C053C052C051C050C04FC0B9CADF
-:1000200065C8B6C8D4C8FDC82DC944C961C9A1C92D
-:10003000A2C95AC8BFC9EDC9F0C954C851C886CAB7
-:1000400004030904160355005300420074006900BC
-:100050006E007900530050004900120110010000A9
-:10006000000881179F0C0401000200010902190019
-:1000700001010080640904000001FF000000070581
-:1000800081030800640011241FBECFE5D2E0DEBF6B
-:10009000CDBF10E0A0E6B0E0E0E2F6E102C00590DE
-:1000A0000D92A636B107D9F710E0A6E6B0E001C080
-:1000B0001D92AD3CB107E1F7C1D7B0CAA1CF1F93E4
-:1000C000162F2091910024FF07C02091920038E85C
-:1000D00023272093920003C02AE520939100212F2B
-:1000E000DC01E3E9F0E08D91819321501216DCF3FD
-:1000F00083E990E0612F4DD11C5F109391001F9117
-:1001000008951F93CF93DF936091A200635067FD22
-:10011000A7C080919F00CCE0D0E0C81BD109CA5590
-:10012000DF4F80919E008D3209F088C0683009F061
-:1001300095C083EC809386008AE5809360001092DE
-:1001400066008881807631F0CE01DAD38F3F09F4E2
-:1001500064C06AC09A8110928F008981882331F42B
-:10016000109290002FE830E082E052C0853019F400
-:100170009093A3004AC0863091F58B81813041F481
-:100180008AE590E09093A1008093A00082E123C0D3
-:10019000823041F48CE690E09093A1008093A0001F
-:1001A00089E119C08330B1F4992341F480E490E0EF
-:1001B0009093A1008093A00084E00DC0913051F095
-:1001C000923041F484E490E09093A1008093A000E9
-:1001D00086E101C080E090E49093660025C08830FD
-:1001E00069F0893019F49093A5000FC08A3049F066
-:1001F0008B3059F48BE48093920007C025EA30E0FD
-:1002000002C02FE830E081E003C02FE830E080E05A
-:100210003093A1002093A00007C0988197FD8E81A4
-:1002200090E89093660007C09F81992321F49E81F6
-:10023000981708F4892F8093610010C080916600A0
-:1002400087FF0CC0CE010FD38F3F21F48EE1809346
-:10025000600004C0882311F0109261001092A20087
-:100260008091600084FF5BC0809161008F3F09F442
-:1002700056C0182F893008F018E0811B8093610068
-:100280008091860098E88927809386001123B1F138
-:100290008091660087FF08C087E890E0612FC2D296
-:1002A000182F8930B0F52AC02091A0003091A1000C
-:1002B000412F415086FF0EC050E0EA01C857DF4F82
-:1002C000F901A7E8B0E084918D933196AC17BD0792
-:1002D000D1F70CC0D90150E0CA0188579F4FE7E819
-:1002E000F0E06D916193E817F907D9F74F5F5F4F21
-:1002F000420F531F5093A1004093A00087E890E065
-:10030000612F47D01C5F1C3041F08FEF809361005C
-:1003100004C08FEF809361001EE11093600084E1C0
-:1003200096B3987131F48150D9F71092A3001092CE
-:100330009D0011E0811110E080916700811729F084
-:10034000112309F4F6D410936700DF91CF911F9128
-:100350000895AC9A8BB780628BBF8BE48093920038
-:100360008AE5809391000895A82FB92F80E090E04E
-:1003700041E050EA609530E009C02D9182279795C1
-:10038000879510F084279527305EC8F36F5FA8F338
-:100390000895EADF8D939D930895A6E08827992715
-:1003A000AA9569F00197E1F3B399FCCFB39BFECF17
-:1003B00081E09927A6B3019611F0A871D9F70895A5
-:1003C000CF93CFB7CF93C395B39BE9F7B39B0BC044
-:1003D000B39B09C0B39B07C0B39B05C0B39B03C0CD
-:1003E000B39B01C0D5C00F92DF93C0919F00DD2762
-:1003F000CA55DF4F012EB39B03C0DF910F90E6CFAC
-:100400002F930F931F934F932FEF4F6F06B303FB61
-:1004100020F95F933F9350E03BE065C016B301269F
-:10042000502953FDC89556B3012703FB25F92F73B7
-:1004300006B3B1F05027102713FB26F906B222307D
-:10044000F0F000C016B3012703FB27F9012650295D
-:1004500006B22430E8F54F77206816B30000F6CFD7
-:1004600050274F7D206206B2102F000000C006B357
-:1004700000265029102713FB26F906B2E2CF4F7B46
-:1004800006B3206400C0DACF01265029187106B2E5
-:1004900069F14E7F2160012F16B328C00026502934
-:1004A0004D7F06B22260102F29C0012650294B7FB4
-:1004B00006B22460012F2DC016B301265029477FB4
-:1004C0002860000006B22EC04F7E06B3206130C007
-:1004D000422706B3499300265029102706B24FEF52
-:1004E00013FB20F9297F16B379F2187159F101260F
-:1004F000502906B2012703FB21F9237F06B371F2CD
-:10050000002650293150D0F006B2102713FB22F9F3
-:10051000277E16B351F201265029012703FB06B2AC
-:1005200023F92F7C49F2000006B3102713FB24F9AE
-:100530000026502906B22F7939F270CF10E21ABF87
-:10054000002719C03B503195C31BD04010E21ABFA1
-:100550000881033C09F10B34F9F020919D001981C9
-:10056000110F1213EDCF4A81441F093651F10D329C
-:1005700011F0013E29F70093A4003F915F914F9144
-:100580001F910F912F91DF910F90CAB7C5FD1BCF1F
-:10059000CF91CFBFCF9118952091A400222369F36A
-:1005A0001091A200112379F534307AF13093A20032
-:1005B00020939E0010919F003BE0311B30939F00E1
-:1005C00024C00091A2000130F4F40AE54F7049F410
-:1005D0003091600034FD1AC000936000C6E8D0E09E
-:1005E00019C03091910034FD11C000939100C2E90F
-:1005F000D0E010C0052710E000C021C0052710E0A2
-:10060000C89508BB14C03AE501C032ED032EC0E026
-:10061000D0E032E017B31861C39A08B317BB58E1B2
-:1006200020E84FEF20FF052708BB279517951C3FB3
-:1006300028F700004552B0F720FF0527279508BB93
-:1006400017951C3FB8F629913A9561F7077E1091EE
-:10065000A300110F08BBC250D04011F010939D00B1
-:1006600010E21ABF086017B3177E402F477E54E090
-:100670005A95F1F708BB17BB48BB7FCFFC015091DF
-:100680006500862F972FDC0194E0619128E030E02F
-:1006900040E880E0742F762309F0C09A052E00C050
-:1006A0000000000000000A94D1F7C29A052E00C095
-:1006B0000000000000000A94D1F7880FB1998F5F05
-:1006C000C098C29846952150304021F78D939150A3
-:1006D000E1F6089580917800909179009C012F5F58
-:1006E0003F4F309379002093780020917A0027FFC4
-:1006F00002C0880F991F20937E0080FF03C02860EE
-:1007000020937E00292F269520937F00969587952C
-:10071000809380008EE790E062E870E0AFDF08959C
-:10072000B99A24E030E0E1E09E2F982321F098B3BD
-:100730009C7F926002C098B39C7F98BBEE0F109292
-:10074000750007C045E04A95F1F700C09F5F9093A0
-:10075000750090917500692F70E040916300509191
-:1007600064006417750770F3C09A1092750007C093
-:1007700045E04A95F1F700C09F5F90937500909116
-:100780007500692F70E04091630050916400641718
-:10079000750770F32150304039F688B38C7F88BBE1
-:1007A0000895B99A28E030E0E1E09E2F982321F0E7
-:1007B00098B39C7F926002C098B39C7F98BBEE0F69
-:1007C0001092750007C045E04A95F1F700C09F5FA1
-:1007D0009093750090917500692F70E040916300CF
-:1007E000509164006417750770F3C09A10927500F9
-:1007F00007C045E04A95F1F700C09F5F90937500F0
-:1008000090917500692F70E04091630050916400F1
-:100810006417750770F32150304039F688B38C7F28
-:1008200088BB0895EF92FF921F93DF93CF930F92AF
-:10083000CDB7DEB7182F862F612F792F7B0108C027
-:10084000898348DF90918500F70191937F01898129
-:100850009E2D911B9817A0F30F90CF91DF911F91C0
-:10086000FF90EF900895DF92EF92FF920F931F9306
-:10087000CF93DF93F82EE62E0F2D192F50E6D52EAD
-:1008800032C0F80181918F018093810023DF809134
-:100890007E008D2580937E00C0E0D0E01DC08EE7F5
-:1008A00090E062E870E0EADE80918500909181003E
-:1008B000891741F490917600891721F09091770083
-:1008C000891789F42091650030E045E0220F331F3D
-:1008D0004A95E1F7C20FD31F20917B0030917C0035
-:1008E000C217D307E0F2802F8F198E1550F281E0E6
-:1008F000DF91CF911F910F91FF90EF90DF900895BE
-:10090000CF93DF93EC014981442341F481E2898351
-:10091000D093A100C093A00088E008C2413011F438
-:1009200086B307C15A81423011F458BBFEC102960A
-:10093000652F677021E030E0062E02C0220F331FC2
-:100940000A94E2F7433029F498B3822F80958923E3
-:1009500093C0443019F488B3822B8EC0453049F4DB
-:1009600050936500B99887B3856287BB88B3887D4B
-:1009700083C0463049F4B898C098B998C098BA98DE
-:10098000C09880E287BB78C0473041F4BE0176DE74
-:10099000D093A100C093A00084E0C8C1483031F4D6
-:1009A000509376008B8180937700BFC18C819D81AD
-:1009B0009093790080937800493011F480E211C05F
-:1009C0004B3011F480EA0DC08A819B8190937C00AA
-:1009D00080937B004A3011F480E403C04C3029F44A
-:1009E00080EC80937A008FEFA1C14D3029F487B35A
-:1009F0002095282327BB99C14E3021F487B3822B41
-:100A000087BB93C14F3009F5552329F480917D00B0
-:100A100087B9A59A0CC0513031F480917D00816076
-:100A200087B9A29A04C0523011F48FE887B9369A78
-:100A30003699FECF84B1888385B18983D093A10094
-:100A4000C093A00014BA82E071C1403159F4B89A41
-:100A5000B99A8AB5806A8ABD8AB583608ABD83B730
-:100A6000856038C0413121F459BD8C8188BD5DC19C
-:100A7000423121F488B3822B88BB57C1433129F41A
-:100A800088B32095282328BB50C1443151F486B344
-:100A900090E08223932302C0959587956A95E2F7AB
-:100AA00048C0463169F5552319F483B78B7F24C0BC
-:100AB000513031F483B78B7F83BF83B7826013C01B
-:100AC000523051F483B78B7F83BF83B7826083BF7B
-:100AD00083B7816083BF29C1533049F483B78460F1
-:100AE00083BF83B78D7F83BF83B78E7FF3CF5430AF
-:100AF00009F01BC183B7846083BF83B78D7FE7CFC5
-:100B00004F3149F49B8180E0850F911D90936400E3
-:100B1000809363000AC1403219F41ABC13BE05C1A8
-:100B2000413221F45093C50081E0B5C0423241F416
-:100B300081E18883D093A100C093A00081E0F6C03A
-:100B40004332D9F4379A86B19A81892B86B98B8141
-:100B5000813049F0813020F0823009F0E6C007C0D2
-:100B600010927D00E2C080917D00806803C080917A
-:100B70007D00806980937D00D8C0483249F48CEBB9
-:100B800090E09093A1008093A0008091C400CEC01B
-:100B9000493211F482E07FC04A3211F483E00BC085
-:100BA0004B3211F484E077C04C3211F488E073C00A
-:100BB0004D3239F489E0809368008A818093C500C2
-:100BC000B4C04E3259F48BE0809368008A818093E0
-:100BD000C5008B818093C6008C8134C04F3259F49C
-:100BE000513031F4B89AB99ABA9A509374009DC0B2
-:100BF000109274009AC0403349F450936E008B8178
-:100C000080936F008C81809370008FC0413329F4F2
-:100C10005093690010926A0088C0423311F485E055
-:100C20003AC0433321F45093C50086E034C04433C6
-:100C300061F4509368008B818093C5008C81809310
-:100C4000C6008D818093C70070C0453369F450930E
-:100C5000C5008B818093C6008C818093C7008D81F5
-:100C60008093C80080E117C0842F90E0807F90704F
-:100C7000803D910599F447704093C5008A81809327
-:100C8000C6008B818093C7008C818093C8008D81C2
-:100C90008093C9008EE08093680047C0803E910534
-:100CA00001F58AE080936800842F87708093C500E7
-:100CB00048704093C6001092750080E00BC090E031
-:100CC0000296FE01E80FF91F30818B539F4FFC0104
-:100CD0003083822F9091C500282F2F5F891778F3DA
-:100CE00022C0803F910509F587E080936800842F3A
-:100CF00088708093C50047704093C60010927500BD
-:100D000080E00BC090E00296FE01E80FF91F3081F1
-:100D10008B539F4FFC013083822F9091C600282F68
-:100D20002F5F891778F38093750080E0DF91CF9172
-:100D30000895DF92EF92FF920F931F93CF93DF936B
-:100D4000C8E0D0E0FF2460E8E62EDE2CDF0CD1BE48
-:100D500024DB082F192F89E0043318070CF4FD2C2D
-:100D6000E694219791F78F2D815081BFCF2DD0E050
-:100D7000219610C012DB8453994097FF03C09095D1
-:100D800081959F4F8017910714F4F1B68C0181B7BC
-:100D90008F5F81BF81B790E0C817D9075CF7F1BEBC
-:100DA00061B780E090E02CD4DF91CF911F910F913B
-:100DB000FF90EF90DF900895882311F0B99801C05B
-:100DC000B99ABA981092750007C025E02A95F1F7F4
-:100DD00000C09F5F9093750090917500492F50E07F
-:100DE0002091690030916A004217530770F3BA9A54
-:100DF0001092750007C025E02A95F1F700C09F5FAB
-:100E00009093750090917500492F50E020916900F2
-:100E100030916A004217530770F38111B99A08950F
-:100E2000B998BA981092750007C025E02A95F1F795
-:100E300000C04F5F4093750040917500242F30E053
-:100E40008091690090916A002817390770F386B382
-:100E5000BA9A1092750007C025E02A95F1F700C0F4
-:100E60009F5F9093750090917500492F50E02091FD
-:100E7000690030916A004217530770F386958170BC
-:100E8000089588B3897F88BBBA98B9981092750085
-:100E900007C085E08A95F1F700C04F5F4093750069
-:100EA00040917500242F30E08091690090916A0094
-:100EB0002817390770F3089587B3897F87BB10928D
-:100EC000750007C085E08A95F1F700C04F5F409339
-:100ED000750040917500242F30E080916900909159
-:100EE0006A002817390770F3B99A1092750007C085
-:100EF00085E08A95F1F700C04F5F409375004091FF
-:100F00007500242F30E08091690090916A002817C5
-:100F1000390770F3BA9A1092750007C085E08A9578
-:100F2000F1F700C04F5F4093750040917500242F8A
-:100F300030E08091690090916A002817390770F3BA
-:100F40000895B99ABA9A1092750007C085E08A95FB
-:100F5000F1F700C04F5F4093750040917500242F5A
-:100F600030E08091690090916A002817390770F38A
-:100F7000BA981092750007C085E08A95F1F700C015
-:100F80004F5F4093750040917500242F30E08091B1
-:100F9000690090916A002817390770F3B998109288
-:100FA000750007C085E08A95F1F700C04F5F409358
-:100FB000750040917500242F30E080916900909178
-:100FC0006A002817390770F308950F931F93082FAD
-:100FD00018E0802F8078F0DE000F1150D1F720DF6D
-:100FE0001F910F910895FF920F931F93F82E08E021
-:100FF00010E0110F15DF182B0150D9F7FF2011F069
-:1010000080E001C081E0D8DE1092750007C095E055
-:101010009A95F1F700C08F5F8093750080917500FD
-:10102000482F50E02091690030916A004217530721
-:1010300070F3812F1F910F91FF900895DF92EF922F
-:10104000FF920F931F93CF93DF9380E287BB88BB00
-:1010500080E090E0CDD28F3F09F081BFBB9A84E160
-:10106000E2EBF1EF3197F1F700C000008150C1F7DA
-:10107000BB9885E090E090936A008093690010929D
-:101080006400109263002EE088E190E00FB6F894BF
-:10109000A89581BD0FBE21BD10926B0010926C000F
-:1010A00010926D0010926E0010926F0010927000FE
-:1010B00010927100109268004CD97894BBE1EB2E2D
-:1010C000AAE1FA2E00E410E8A8951BD8E091680088
-:1010D000F0E0E131F10508F05AC2E15FFF4F0994F9
-:1010E00060E02AC2DD24D9C1DD2457C1B89AB9987D
-:1010F000BA9AC29A1092BC008091C5008093720087
-:10110000109373003FC0C09840E005C0F5E0FA9529
-:10111000F1F700C04F5F242F30E080916300909181
-:1011200064002817390790F3809173009091720042
-:10113000892309F0C09AC2988091BC00880F8093DF
-:10114000BC002091BC0086B390E0827090709595B1
-:101150008795280F2093BC0040E005C025E02A9524
-:10116000F1F700C04F5F242F30E080916300909131
-:1011700064002817390790F3C29A8091730086950E
-:101180008093730080917300882309F0BCCF1DC049
-:10119000BA9AC2988BEB97E00197F1F700C0000074
-:1011A0009FB7F894C29AE0E2F1E03197F1F700C0FE
-:1011B000BA9881E0B29980E08093BC009FBF8BE930
-:1011C00096E00197F1F7BA9AC29A81E0BCC180918A
-:1011D000C50080937300BA9A88E02FB7F894C2983C
-:1011E0009091730090FF0BC091E29A95F1F7C29A2B
-:1011F000E7E0F1E03197F1F700C0000009C0E7EF48
-:10120000F0E03197F1F70000C29AF7E3FA95F1F7B1
-:10121000909173009695909373002FBF8150E9F6DB
-:10122000B6C11092BC0028E08091BC0086958093E6
-:10123000BC00BA9A3FB7F894C29881E28A95F1F758
-:10124000C29A97E39A95F1F7BA9886B390E08470C2
-:1012500090709595879595958795809373003FBF7E
-:10126000E2EEF0E03197F1F700C0000080917300EA
-:10127000882329F08091BC0080688093BC002150B5
-:1012800099F6A3CFBA9A2FB7F894C298F1E2FA95DB
-:10129000F1F7C29A87E38A95F1F7BA9886B390E09E
-:1012A0008470907095958795959587958093BC00EF
-:1012B0002FBF8BCFBA9A8FB7F894C2989091C50080
-:1012C00090FF0BC091E29A95F1F7C29AE7E0F1E046
-:1012D0003197F1F700C0000009C0E7EFF0E0319767
-:1012E000F1F70000C29AF7E3FA95F1F78FBF4FC10B
-:1012F000B99AB898BA9AC298E0927200FDB88091F3
-:10130000C5008111C5981092730026C0F0E0E95322
-:10131000FF4F80818FB90EB9809172008DB940E086
-:1013200005C025E02A95F1F700C04F5F242F30E07B
-:1013300080916300909164002817390790F3769BA1
-:10134000EBCF80917300E82FF0E09FB1E454FF4FA2
-:1013500090838F5F80937300E09173008091C6004B
-:10136000E817A0F28091C5008111C59AE093C400EE
-:101370000EC187DD0CC180E090E09EDD8091C5004C
-:1013800024DE8093730013C0ED2DF0E0E953FF4F8E
-:1013900080811BDE80937300D3948091C500D816A2
-:1013A00098F38091C6008111CCDD80917300809309
-:1013B000BC000BCF8091C500882311F4DD241EC032
-:1013C000DD2404C081E00FDE8883D3942D2D30E02E
-:1013D0008091C60090E00197E901C454DF4F2817BF
-:1013E000390784F380E0FFDD88830CC0CD2DD0E089
-:1013F00081E0F9DDC454DF4F8883D3948091C60027
-:10140000D816A0F38091C700882309F49AC099DD0B
-:1014100098C08091C60084D9BAC04091C600B99ADC
-:101420002FC088B38C7F88BB41501092750007C0D5
-:1014300085E08A95F1F700C05F5F50937500509189
-:101440007500252F30E0809163009091640028178B
-:10145000390770F3C09A1092750007C095E09A950D
-:10146000F1F700C05F5F5093750050917500252F14
-:1014700030E080916300909164002817390770F381
-:10148000442379F688B38C7F88BB81C0ED2DF0E0D2
-:10149000EA53FF4F808185D9D3948091C500D81637
-:1014A000A8F375C0B998C19A88E090E071E01092F5
-:1014B000750007C0F5E0FA95F1F700C0EF5FE09323
-:1014C0007500E09175004E2F50E02091630030913F
-:1014D00064004217530770F3C09A1092750007C05A
-:1014E00025E02A95F1F700C0EF5FE0937500E091E9
-:1014F00075004E2F50E02091630030916400421738
-:10150000530770F330917300B19B04C0372B3093B5
-:10151000730005C0272F2095232320937300C098C4
-:10152000770F019721F6C198E62FF0E080917300C4
-:10153000E454FF4F80836F5F8091C600681708F402
-:10154000B1CF8091C6008093C40021C080E0E8D86C
-:101550008091C60026D98091C70023D98091C80008
-:1015600020D9109273000DC080E0DAD880E019D93C
-:1015700080E017D980E015D9809173008F5F809348
-:1015800073008091C50090917300981768F31092D2
-:10159000680080917400882309F496CD80917100D1
-:1015A000882369F490916E0090936B0090916F0086
-:1015B00090936C009091700090936D0015C0909185
-:1015C0006B00981710F4C09801C0C09A90916C00FD
-:1015D000981710F4C19801C0C19A90916D009817A6
-:1015E00010F4C29801C0C29A8F5F809371006CCDD5
-:1015F000E199FECF9FBB8EBBE09A99278DB30895EA
-:10160000262FE199FECF1CBA9FBB8EBB2DBB0FB618
-:10161000F894E29AE19A0FBE01960895F894FFCFEC
-:061620005AFF110A002828
-:00000001FF
diff --git a/commandline/examples/micronucleus.c b/commandline/micronucleus.c
index dc567da..b7d49ab 100644
--- a/commandline/examples/micronucleus.c
+++ b/commandline/micronucleus.c
@@ -1,7 +1,7 @@
/*
Created: September 2012
by ihsan Kehribar <ihsan@kehribar.me>
-
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
@@ -18,13 +18,14 @@
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- SOFTWARE.
+ SOFTWARE.
*/
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
+#include <time.h>
#include "micronucleus_lib.h"
#include "littleWire_util.h"
@@ -33,7 +34,7 @@
#define CONNECT_WAIT 250 /* milliseconds to wait after detecting device on usb bus - probably excessive */
/******************************************************************************
-* Global definitions
+* Global definitions
******************************************************************************/
unsigned char dataBuffer[65536 + 256]; /* buffer for file data */
/*****************************************************************************/
@@ -41,8 +42,8 @@ unsigned char dataBuffer[65536 + 256]; /* buffer for file data */
/******************************************************************************
* Function prototypes
******************************************************************************/
-static int parseRaw(char *hexfile, char* buffer, int *startAddr, int *endAddr);
-static int parseIntelHex(char *hexfile, char* buffer, int *startAddr, int *endAddr); /* taken from bootloadHID example from obdev */
+static int parseRaw(char *hexfile, unsigned char *buffer, int *startAddr, int *endAddr);
+static int parseIntelHex(char *hexfile, unsigned char *buffer, int *startAddr, int *endAddr); /* taken from bootloadHID example from obdev */
static int parseUntilColon(FILE *fp); /* taken from bootloadHID example from obdev */
static int parseHex(FILE *fp, int numDigits); /* taken from bootloadHID example from obdev */
static void printProgress(float progress);
@@ -52,7 +53,8 @@ static int progress_total_steps = 0; // total steps for upload
static char* progress_friendly_name; // name of progress section
static int dump_progress = 0; // output computer friendly progress info
static int use_ansi = 0; // output ansi control character stuff
-static int timeout = 0; //
+static int erase_only = 0; // only erase, dont't write file
+static int timeout = 0;
/*****************************************************************************/
/******************************************************************************
@@ -67,17 +69,18 @@ int main(int argc, char **argv) {
int run = 0;
int file_type = FILE_TYPE_INTEL_HEX;
int arg_pointer = 1;
- char* usage = "usage: micronucleus [--run] [--dump-progress] [--type intel-hex|raw] [--no-ansi] [--timeout integer] filename";
+ char* usage = "usage: micronucleus [--run] [--dump-progress] [--type intel-hex|raw] [--no-ansi] [--timeout integer] [--erase-only] filename";
progress_step = 0;
progress_total_steps = 5; // steps: waiting, connecting, parsing, erasing, writing, (running)?
dump_progress = 0;
+ erase_only = 0;
timeout = 0; // no timeout by default
//#if defined(WIN)
// use_ansi = 0;
//#else
use_ansi = 1;
//#endif
-
+
while (arg_pointer < argc) {
if (strcmp(argv[arg_pointer], "--run") == 0) {
run = 1;
@@ -99,6 +102,8 @@ int main(int argc, char **argv) {
puts(" bytes (intel hex is default)");
puts(" --dump-progress: Output progress data in computer-friendly form");
puts(" for driving GUIs");
+ puts(" --erase-only: Erase the device without programming. Fills the");
+ puts(" program memory with 0xFFFF. Any files are ignored.");
puts(" --run: Ask bootloader to run the program when finished");
puts(" uploading provided program");
//#ifndef WIN
@@ -112,6 +117,9 @@ int main(int argc, char **argv) {
dump_progress = 1;
} else if (strcmp(argv[arg_pointer], "--no-ansi") == 0) {
use_ansi = 0;
+ } else if (strcmp(argv[arg_pointer], "--erase-only") == 0) {
+ erase_only = 1;
+ progress_total_steps -= 1;
} else if (strcmp(argv[arg_pointer], "--timeout") == 0) {
arg_pointer += 1;
if (sscanf(argv[arg_pointer], "%d", &timeout) != 1) {
@@ -121,41 +129,41 @@ int main(int argc, char **argv) {
} else {
file = argv[arg_pointer];
}
-
+
arg_pointer += 1;
}
-
+
if (argc < 2) {
puts(usage);
return EXIT_FAILURE;
}
-
+
setProgressData("waiting", 1);
if (dump_progress) printProgress(0.5);
printf("> Please plug in the device ... \n");
printf("> Press CTRL+C to terminate the program.\n");
-
-
+
+
time_t start_time, current_time;
time(&start_time);
-
+
while (my_device == NULL) {
delay(100);
my_device = micronucleus_connect();
-
+
time(&current_time);
if (timeout && start_time + timeout < current_time) {
break;
}
}
-
+
if (my_device == NULL) {
printf("> Device search timed out\n");
return EXIT_FAILURE;
}
-
+
printf("> Device is found!\n");
-
+
// wait for CONNECT_WAIT milliseconds with progress output
float wait = 0.0f;
setProgressData("connecting", 2);
@@ -164,10 +172,10 @@ int main(int argc, char **argv) {
wait += 50.0f;
delay(50);
}
-
+
//my_device = micronucleus_connect();
printProgress(1.0);
-
+
// if (my_device->page_size == 64) {
// printf("> Device looks like ATtiny85!\n");
// } else if (my_device->page_size == 32) {
@@ -176,101 +184,108 @@ int main(int argc, char **argv) {
// printf("> Unsupported device!\n");
// return EXIT_FAILURE;
// }
-
- printf("> Available space for user application: %d bytes\n", my_device->flash_size);
+
+ printf("> Device has firmware version %d.%d\n",my_device->version.major,my_device->version.minor);
+ printf("> Available space for user applications: %d bytes\n", my_device->flash_size);
printf("> Suggested sleep time between sending pages: %ums\n", my_device->write_sleep);
- printf("> Whole page count: %d\n", my_device->pages);
+ printf("> Whole page count: %d page size: %d\n", my_device->pages,my_device->page_size);
printf("> Erase function sleep duration: %dms\n", my_device->erase_sleep);
-
- setProgressData("parsing", 3);
- printProgress(0.0);
- memset(dataBuffer, 0xFF, sizeof(dataBuffer));
-
+
int startAddress = 1, endAddress = 0;
- if (file_type == FILE_TYPE_INTEL_HEX) {
- if (parseIntelHex(file, dataBuffer, &startAddress, &endAddress)) {
- printf("> Error loading or parsing hex file.\n");
+
+ if (!erase_only) {
+ setProgressData("parsing", 3);
+ printProgress(0.0);
+ memset(dataBuffer, 0xFF, sizeof(dataBuffer));
+
+ if (file_type == FILE_TYPE_INTEL_HEX) {
+ if (parseIntelHex(file, dataBuffer, &startAddress, &endAddress)) {
+ printf("> Error loading or parsing hex file.\n");
+ return EXIT_FAILURE;
+ }
+ } else if (file_type == FILE_TYPE_RAW) {
+ if (parseRaw(file, dataBuffer, &startAddress, &endAddress)) {
+ printf("> Error loading raw file.\n");
+ return EXIT_FAILURE;
+ }
+ }
+
+ printProgress(1.0);
+
+ if (startAddress >= endAddress) {
+ printf("> No data in input file, exiting.\n");
return EXIT_FAILURE;
}
- } else if (file_type == FILE_TYPE_RAW) {
- if (parseRaw(file, dataBuffer, &startAddress, &endAddress)) {
- printf("> Error loading raw file.\n");
+
+ if (endAddress > my_device->flash_size) {
+ printf("> Program file is %d bytes too big for the bootloader!\n", endAddress - my_device->flash_size);
return EXIT_FAILURE;
}
}
-
+
printProgress(1.0);
- if (startAddress >= endAddress) {
- printf("> No data in input file, exiting.\n");
- return EXIT_FAILURE;
- }
-
- if (endAddress > my_device->flash_size) {
- printf("> Program file is %d bytes too big for the bootloader!\n", endAddress - my_device->flash_size);
- return EXIT_FAILURE;
- }
-
setProgressData("erasing", 4);
printf("> Erasing the memory ...\n");
res = micronucleus_eraseFlash(my_device, printProgress);
-
+
if (res == 1) { // erase disconnection bug workaround
printf(">> Eep! Connection to device lost during erase! Not to worry\n");
printf(">> This happens on some computers - reconnecting...\n");
my_device = NULL;
-
+
delay(CONNECT_WAIT);
-
+
int deciseconds_till_reconnect_notice = 50; // notice after 5 seconds
while (my_device == NULL) {
delay(100);
my_device = micronucleus_connect();
deciseconds_till_reconnect_notice -= 1;
-
+
if (deciseconds_till_reconnect_notice == 0) {
printf(">> (!) Automatic reconnection not working. Unplug and reconnect\n");
printf(" device usb connector, or reset it some other way to continue.\n");
}
}
-
+
printf(">> Reconnected! Continuing upload sequence...\n");
-
+
} else if (res != 0) {
printf(">> Flash erase error %d has occured ...\n", res);
printf(">> Please unplug the device and restart the program.\n");
return EXIT_FAILURE;
}
printProgress(1.0);
-
- printf("> Starting to upload ...\n");
- setProgressData("writing", 5);
- res = micronucleus_writeFlash(my_device, endAddress, dataBuffer, printProgress);
- if (res != 0) {
- printf(">> Flash write error %d has occured ...\n", res);
- printf(">> Please unplug the device and restart the program.\n");
- return EXIT_FAILURE;
+
+ if (!erase_only) {
+ printf("> Starting to upload ...\n");
+ setProgressData("writing", 5);
+ res = micronucleus_writeFlash(my_device, endAddress, dataBuffer, printProgress);
+ if (res != 0) {
+ printf(">> Flash write error %d has occured ...\n", res);
+ printf(">> Please unplug the device and restart the program.\n");
+ return EXIT_FAILURE;
+ }
}
-
+
if (run) {
-
printf("> Starting the user app ...\n");
setProgressData("running", 6);
printProgress(0.0);
-
+
res = micronucleus_startApp(my_device);
-
+
if (res != 0) {
printf(">> Run error %d has occured ...\n", res);
printf(">> Please unplug the device and restart the program. \n");
return EXIT_FAILURE;
}
-
+
printProgress(1.0);
}
-
+
printf(">> Micronucleus done. Thank you!\n");
-
+
return EXIT_SUCCESS;
}
/******************************************************************************/
@@ -279,7 +294,7 @@ int main(int argc, char **argv) {
static void printProgress(float progress) {
static int last_step;
static int last_integer_total_progress;
-
+
if (dump_progress) {
printf("{status:\"%s\",step:%d,steps:%d,progress:%f}\n", progress_friendly_name, progress_step, progress_total_steps, progress);
} else {
@@ -290,17 +305,17 @@ static void printProgress(float progress) {
printf("\r"); // return carriage to start of line so we can type over existing text
#endif
}
-
+
float total_progress = ((float) progress_step - 1.0f) / (float) progress_total_steps;
total_progress += progress / (float) progress_total_steps;
int integer_total_progress = total_progress * 100.0f;
-
+
if (use_ansi || integer_total_progress >= last_integer_total_progress + 5) {
printf("%s: %d%% complete\n", progress_friendly_name, integer_total_progress);
last_integer_total_progress = integer_total_progress;
}
}
-
+
last_step = progress_step;
}
@@ -313,11 +328,11 @@ static void setProgressData(char* friendly, int step) {
/******************************************************************************/
static int parseUntilColon(FILE *file_pointer) {
int character;
-
+
do {
character = getc(file_pointer);
} while(character != ':' && character != EOF);
-
+
return character;
}
/******************************************************************************/
@@ -331,22 +346,22 @@ static int parseHex(FILE *file_pointer, int num_digits) {
temp[iter] = getc(file_pointer);
}
temp[iter] = 0;
-
+
return strtol(temp, NULL, 16);
}
/******************************************************************************/
/******************************************************************************/
-static int parseIntelHex(char *hexfile, char* buffer, int *startAddr, int *endAddr) {
+static int parseIntelHex(char *hexfile, unsigned char *buffer, int *startAddr, int *endAddr) {
int address, base, d, segment, i, lineLen, sum;
FILE *input;
-
+
input = strcmp(hexfile, "-") == 0 ? stdin : fopen(hexfile, "r");
if (input == NULL) {
printf("> Error opening %s: %s\n", hexfile, strerror(errno));
return 1;
}
-
+
while (parseUntilColon(input) == ':') {
sum = 0;
sum += lineLen = parseHex(input, 2);
@@ -357,18 +372,18 @@ static int parseIntelHex(char *hexfile, char* buffer, int *startAddr, int *endAd
if (segment != 0) { /* ignore lines where this byte is not 0 */
continue;
}
-
+
for (i = 0; i < lineLen; i++) {
d = parseHex(input, 2);
buffer[address++] = d;
sum += d;
}
-
+
sum += parseHex(input, 2);
if ((sum & 0xff) != 0) {
printf("> Warning: Checksum error between address 0x%x and 0x%x\n", base, address);
}
-
+
if(*startAddr > base) {
*startAddr = base;
}
@@ -376,37 +391,37 @@ static int parseIntelHex(char *hexfile, char* buffer, int *startAddr, int *endAd
*endAddr = address;
}
}
-
+
fclose(input);
return 0;
}
/******************************************************************************/
/******************************************************************************/
-static int parseRaw(char *filename, char* data_buffer, int *start_address, int *end_address) {
+static int parseRaw(char *filename, unsigned char *data_buffer, int *start_address, int *end_address) {
FILE *input;
-
+
input = strcmp(filename, "-") == 0 ? stdin : fopen(filename, "r");
-
+
if (input == NULL) {
printf("> Error reading %s: %s\n", filename, strerror(errno));
return 1;
}
-
+
*start_address = 0;
*end_address = 0;
-
+
// read in bytes from file
int byte = 0;
while (1) {
byte = getc(input);
if (byte == EOF) break;
-
+
*data_buffer = byte;
data_buffer += 1;
*end_address += 1;
}
-
+
fclose(input);
return 0;
}