[gnoduino: 208/237] restored original non-interrupt-driven DiskLoader
- From: Lucian Langa <lucilanga src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnoduino: 208/237] restored original non-interrupt-driven DiskLoader
- Date: Sat, 31 Mar 2012 20:32:19 +0000 (UTC)
commit 07c41a0801def9e51257e58c483761477f7352a5
Author: Zach Eveland <zeveland blacklabel-development com>
Date: Wed Nov 9 14:04:59 2011 -0500
restored original non-interrupt-driven DiskLoader
Interrupt-driven version was a dead-end - too many bugs with that approach.
.../bootloaders/diskloader/DiskLoader-Leonardo.hex | 290 ++++------
.../bootloaders/diskloader/DiskLoader-Micro.hex | 113 ++++
arduino/bootloaders/diskloader/Makefile | 200 ++++----
arduino/bootloaders/diskloader/src/CDC.cpp | 93 ---
arduino/bootloaders/diskloader/src/DiskLoader.cpp | 304 +++++------
arduino/bootloaders/diskloader/src/Platform.h | 63 +--
arduino/bootloaders/diskloader/src/USBAPI.h | 64 ---
arduino/bootloaders/diskloader/src/USBCore.cpp | 589 ++++++++------------
arduino/bootloaders/diskloader/src/USBCore.h | 88 ++--
arduino/bootloaders/diskloader/src/USBDesc.cpp | 82 +++
arduino/bootloaders/diskloader/src/USBDesc.h | 45 ++-
arduino/cores/arduino/CDC.cpp | 2 +-
12 files changed, 883 insertions(+), 1050 deletions(-)
---
diff --git a/arduino/bootloaders/diskloader/DiskLoader-Leonardo.hex b/arduino/bootloaders/diskloader/DiskLoader-Leonardo.hex
index 434b8bf..4528a8b 100644
--- a/arduino/bootloaders/diskloader/DiskLoader-Leonardo.hex
+++ b/arduino/bootloaders/diskloader/DiskLoader-Leonardo.hex
@@ -1,179 +1,113 @@
-:10700000BDC00000E0C00000DEC00000DCC0000029
-:10701000DAC00000D8C00000D6C00000D4C0000014
-:10702000D2C00000D0C00000C4C3000036C40000BD
-:10703000CAC00000C8C00000C6C00000C4C0000034
-:10704000C2C00000C0C00000BEC00000BCC0000044
-:10705000BAC00000B8C00000B6C00000B4C0000054
-:10706000B2C00000B0C00000AEC00000ACC0000064
-:10707000AAC00000A8C00000A6C00000A4C0000074
-:10708000A2C00000A0C000009EC000009CC0000084
-:107090009AC0000098C0000096C0000094C0000094
-:1070A00092C0000090C000008EC0000011241FBEDE
-:1070B000CFEFDAE0DEBFCDBF2AC1080B000202022B
-:1070C0000100090400000102020000052400100173
-:1070D0000524010101042402060524060001070518
-:1070E000810310004009040100020A0000000705A6
-:1070F00002024000000705830240000041014214E3
-:107100004505560455026403740300001E9587026A
-:10711000011003000403090422034100720064000B
-:10712000750069006E006F0020004C0065006F0064
-:107130006E006100720064006F001803410072006D
-:107140006400750069006E006F0020004C004C0068
-:107150004300120100020000004041233200000100
-:10716000010200011201000202000040412332002E
-:1071700000010102000100C180813D3C11241FBEBD
-:10718000CFEFDAE0DEBFCDBF11E0A0E0B1E0E6EF87
-:10719000FAE702C005900D92A830B107D9F711E0C7
-:1071A000A8E0B1E001C01D92A739B107E1F711E7EE
-:1071B000CCE7D1E703C02297FE0197D4CA37D107A5
-:1071C000D1F7A5D096C41CCFFC0180818E5F80834F
-:1071D00080E86AEB70E742E450E09DC2FC018181E7
-:1071E0009081913A49F48132C1F480E060E071E02D
-:1071F00047E050E090D20FC0913279F4803231F400
-:1072000080E091E067E070E0C2D205C0823229F4EC
-:1072100082818093070181E0089580E008952091A4
-:107220008C0130918D012F5F3F4F30938D01209362
-:107230008C01C901892F99278695982F803418F0E1
-:107240008FE7891B982F990F921710F4479808958C
-:10725000479A0895E0E0F0E0859194918F5F9F4F09
-:1072600081F04798289A769AF89401E005BF00E0EB
-:1072700005BF81E08093E0001092E200EE27FF2737
-:1072800009940895FF920F931F93CF93DF93982F44
-:107290008B01FF2480E76030780738F4FF24F394F3
-:1072A00083E0FB0180935700E895C42FD0E0892F3D
-:1072B00068E071E0AE0121D1FF2019F107B600FCB2
-:1072C000FDCFD595C7954C2FF801A8E0B1E020E09F
-:1072D00031E009C08D919D910C0130935700E895E4
-:1072E000112432962F5F2417A8F385E0F8018093CC
-:1072F0005700E89507B600FCFDCF81E18093570069
-:10730000E895DF91CF911F910F91FF90089588E14B
-:107310000FB6F89480936000109260000FBE3F9A01
-:10732000209A6E9A90E8909361001092610081E833
-:1073300085BF95BF01E005BF02E005BF769A289A98
-:10734000479886E991E083D2789484E1809388011C
-:1073500080E180938901CC24DD2470E9A72E71E0BF
-:10736000B72E02C0CC24DD2482E0BED0882309F4ED
-:1073700093C082E017D1E82E8CEF90E7FC012491B6
-:107380003196029644912E1511F02223B9F71092EE
-:107390008B0110928A0150E082E068E071E0ADD08C
-:1073A000F1E4EF1679F4609108016058633028F039
-:1073B000683111F064E001C063E0C62FD0E0C15F26
-:1073C000DE4810C026E5E21681F480910801803382
-:1073D00019F0FF24F39428C080910A01C82FD0E04F
-:1073E000C45FDE48FF24F39427C085E7E81629F43C
-:1073F00063E0F62ECCE0D1E71FC0E5E5EE1639F4E8
-:10740000C0900801D0900901CC0CDD1C0CC0F4E642
-:10741000EF1631F482E0B6014091090133DF03C079
-:1074200024E7E21621F0FF24C3E1D1E705C0F09084
-:107430000901E601CF0CD11C08E813E1015010400E
-:107440000930110509F43BC082E04ED0882309F0D1
-:1074500036C0F4CF809709F085CF83E068E871E00B
-:1074600041E050E0C7D0FF2029F04F2D50E083E8E5
-:10747000BE01C0D083E469E871E041E050E0BAD0D9
-:1074800081E5E81609F070CF88EE93E0F5013197B9
-:10749000F1F70197D9F711C0C2DEC5010197F1F7E5
-:1074A00080918A0190918B01019790938B01809339
-:1074B0008A010196019709F057CFCCDE55CF82E0C3
-:1074C00071D0EFEF8F3F9E0709F0C4CFC6CFFC010C
-:1074D00004C08091F100819361506623D1F7289810
-:1074E00084E680938F0108959FB7F8948770809306
-:1074F000E9008091F2009FBF0895FB019FB7F894C7
-:1075000087708093E90034E62BE610C08091E80094
-:1075100085FFFCCF289830938F018091F1008193F3
-:107520008091E80085FD02C02093E8004150504062
-:107530008FEF4F3F580751F79FBF0895282F809135
-:1075400090018823C1F057FF1AC015C02898909366
-:107550008F018091F1008193E217F307B9F741158C
-:10756000510539F08091F200882319F48BE680935D
-:10757000E800AFBF02C04FEF5FEFCA010895AFB799
-:10758000F89427702093E9008091F200282F30E0D2
-:10759000241735070CF4A901FB019B01240F311DB1
-:1075A00094E6DACFDF93CF930F92CDB7DEB7BE016B
-:1075B0006F5F7F4F41E050E0C1DF019719F08FEF1F
-:1075C0009FEF02C0898190E00F90CF91DF910895E5
-:1075D0002FB7F89487708093E9008091E80085FDCB
-:1075E00002C090E004C08091F20090E4981B2FBF8D
-:1075F000892F08955F926F927F928F929F92AF92A0
-:10760000BF92CF92DF92EF92FF920F931F93CF938F
-:10761000DF93F82E6A0180919001882319F44FEFCF
-:107620005FEF68C08B01EA0157E0E52EEF208F2D58
-:1076300090E040E2842E912C882299223AE3532E46
-:1076400020E4A22EB12CA822B92280EA682E8FE075
-:10765000782E43C08F2DBCDF282F882321F4C3014F
-:107660000197F1F73AC090E0C817D9070CF42C2F16
-:10767000C21BD1094FB7F894E092E900811491043C
-:1076800021F406C01092F10021502223D9F719C02D
-:10769000F7FC03C0F801922F10C0C801322F06C0BA
-:1076A000FC010196E491E093F10031503323C1F7DE
-:1076B00006C081918093F10091509923D1F7020F78
-:1076C000111D8091E80085FF05C0209729F4A114C1
-:1076D000B10411F05092E8004FBF209709F0BACFE3
-:1076E000F6FE03C08AE38093E800769884E68093F0
-:1076F0008E01A601CA01DF91CF911F910F91FF90DA
-:10770000EF90DF90CF90BF90AF909F908F907F9041
-:107710006F905F9008950F931F93182FFB01A09116
-:107720009301B0919401BA010EEF2AC017FF02C075
-:10773000949101C0908120919101309192012A177A
-:107740003B07ACF48091E8008570E1F38091E8009C
-:1077500082FF03C04FEF5FEF16C09093F100C901A5
-:1077600001968F739070892B11F40093E8002F5FBE
-:107770003F4F3093920120939101615070403196B8
-:107780006115710599F6CA011F910F910895CF9364
-:10779000DF939C01EB018091E80082FFFCCFC901DF
-:1077A0006C2F95DE8BEF8093E800CE01DF91CF91B7
-:1077B00008951F920F920FB60F9211242F933F93AB
-:1077C0008F938091E1001092E100282F83FF0FC07A
-:1077D0001092E90081E08093EB001092EC0082E3CC
-:1077E0008093ED001092900188E08093F00022FFDA
-:1077F00026C083E08093E9008091F200882319F08D
-:107800008AE38093E80080918E01882351F0809173
-:107810008E01815080938E0180918E01882309F41E
-:10782000769A80918F01882351F080918F01815049
-:1078300080938F0180918F01882309F4289A8F917A
-:107840003F912F910F900FBE0F901F90189510929F
-:10785000900181E08093D70080EA8093D80082E194
-:1078600089BD09B400FEFDCF80E98093D8008CE08B
-:107870008093E2001092E00008950895DF93CF9383
-:107880000F92CDB7DEB71982CE0101969DDC8981BA
-:1078900090E00F90CF91DF9108951F920F920FB655
-:1078A0000F921124EF92FF921F932F933F934F93C8
-:1078B0005F936F937F938F939F93AF93BF93EF9358
-:1078C000FF93DF93CF93CDB7DEB76197DEBFCDBF18
-:1078D0001092E9008091E80083FFECC0CE01019690
-:1078E00068E0F5DD82EF8093E800998197FF05C09D
-:1078F0008091E80080FFFCCF03C08EEF8093E8000A
-:10790000292F30E0C90180769070892B09F0B3C02F
-:107910008A81882329F41092F1001092F100BFC0EF
-:10792000813009F4BCC0833009F4B9C0853049F412
-:107930008091E80080FFFCCF8B8180688093E3001A
-:10794000AEC0863009F06DC01C81EF80F884123023
-:10795000A9F51092E90010929201109291011092F3
-:107960009401109293018ADF99E0FE013996DF01BC
-:10797000292F1D922A95E9F799871A8791E09E870A
-:1079800090E8988B9AEF998B209191013091920118
-:10799000275F3F4F3C872B878D871092E90010921D
-:1079A000920110929101F0929401E092930180E093
-:1079B000BF0149E050E0AFDE61DF71C01092E90025
-:1079C0001092920110929101F0929401E092930131
-:1079D000113071F488E0E816F10411F41093950168
-:1079E00080919501882309F062C0E2E5F1E713C0B8
-:1079F000133009F058C08B81882319F4E4E1F1E7D2
-:107A00000AC0823019F4E8E1F1E705C0813009F0DD
-:107A10004AC0EAE3F1E7449150E080E8BF017BDE31
-:107A20003EC0873009F43FC0883021F481E0809364
-:107A3000F10035C0893099F523703070232B99F50A
-:107A4000E7E7F1E791E031E026E39093E900309336
-:107A5000EB0084918093EC002093ED009F5F3196C2
-:107A6000943099F78EE78093EA001092EA008B81B8
-:107A70008093900114C08F8198851092E900109234
-:107A800092011092910190939401809393018D81C2
-:107A9000882349F4CE010196A1DB882321F08EEFE3
-:107AA0008093E80007C081E28093EB0003C0E4E626
-:107AB000F1E7B1CF6196DEBFCDBFCF91DF91FF91EE
-:107AC000EF91BF91AF919F918F917F916F915F9156
-:107AD0004F913F912F911F91FF90EF900F900FBE0C
-:107AE0000F901F901895EE0FFF1F0590F491E02D59
-:067AF0000994F894FFCF99
-:087AF60000E1000000000000A7
-:040000030000700089
+:1078000011241FBECFEFDAE0DEBFCDBFF2C04101D1
+:1078100042144505560455026403740300001E9586
+:1078200087020110030000C18081C106C0FF0A0069
+:107830000CA10185037508150026FF00954009017C
+:107840008102954009029102C004030904380341F2
+:107850000072006400750069006E006F0020004C2B
+:107860000065006F006E006100720064006F002010
+:107870000062006F006F0074006C006F00610064B4
+:107880000065007200180341007200640075006911
+:10789000006E006F0020004C004C004300120100FD
+:1078A00002020000404123340000010102000112E5
+:1078B00001000200000040412334000001010200E9
+:1078C00001090264000301008032080B0002020279
+:1078D000010009040000010202000005240010015B
+:1078E0000524010101042402020524060001070504
+:1078F000810310004009040100020A00000007058E
+:107900000202400000070583024000000904020053
+:107910000103000000092101010001221E000705EA
+:1079200084034000400020918A0130918B012C5F3C
+:107930003F4F30938B0120938A01C901892F9927EA
+:107940008695982F803418F08FE7891B982F990F10
+:10795000921710F447980895479A08955D9A289AC7
+:1079600081E08093E0001092E200EE27FF27099467
+:1079700008950F931F93CF93DF93982FEB01042F5C
+:1079800010E088E76030780730F411E083E0FB0115
+:1079900080935700E895892F68E071E0402FF8D078
+:1079A000112311F107B600FCFDCF402F4695FE01D3
+:1079B000A8E0B1E020E031E009C08D919D910C017B
+:1079C00030935700E895112432962F5F2417A8F3BF
+:1079D00085E0FE0180935700E89507B600FCFDCFD7
+:1079E00081E180935700E895DF91CF911F910F912E
+:1079F000089588E10FB6F8948093600010926000BB
+:107A00000FBE5D9A289A47983F9A209A559A90E817
+:107A1000909361001092610081E885BF95BF9FD06F
+:107A200084E18093880180E180938901E0E0F0E0C7
+:107A3000859194918F5F9F4F19F081E080938F0122
+:107A4000EE24FF24BB24B39454EFC52E51E0D52E71
+:107A50000ED2082F8EE098E7FC0124913196029611
+:107A60004491201711F02223B9F71092910110923E
+:107A7000900182E068E071E08BD0013479F460918C
+:107A800008016058633028F0683111F064E001C0EB
+:107A900063E0C62FD0E0CF5DD7480EC0063571F445
+:107AA00080910801803311F011E022C080910A0119
+:107AB000C82FD0E0C25ED74811E022C0053721F4BC
+:107AC00013E0CEE1D8E71CC0053539F4E090080199
+:107AD000F0900901EE0CFF1C0AC0043631F482E07C
+:107AE000B7014091090145DF02C0043721F010E0E1
+:107AF000C5E2D8E705C010910901E701E10EF11CCC
+:107B0000B6D18097B1F483E068E871E041E050E0DD
+:107B100059D0112329F0412F50E083E8BE0152D003
+:107B200083E469E871E041E050E04CD0013509F0B0
+:107B30008FCFD0929101C0929001B0928F01EE242C
+:107B4000FF2486CFFC01289884E680938D0104C031
+:107B50008091F100819361506623D1F708951092CE
+:107B600091011092900110928E0110928F0181E08C
+:107B70008093D70080EA8093D80082E189BD09B460
+:107B800000FEFDCF80E98093D8001092E0000895B8
+:107B9000FB018093E90024E69BE611C08091E80098
+:107BA00085FFFCCF289820938D018091F10081936F
+:107BB0008091E80085FD02C09093E8004150442385
+:107BC00069F70895982FFB01282F20728770809302
+:107BD000E90064E63AE317C08091E80085FFFCCF36
+:107BE00097FF02C0849101C080813196211180E00D
+:107BF0005D9860938C018093F1008091E80085FD91
+:107C000002C03093E800415050408FEF4F3F58077B
+:107C100019F796FF03C08AE38093E80008958091E6
+:107C20009301813299F45D9884E680938C0120E081
+:107C300030E003C080818093F100F901E050FF4FF4
+:107C40002F5F3F4F28303105A9F714C0803261F40F
+:107C50008091E80082FFFCCF80E091E067E072DF76
+:107C60008BEF8093E80006C0823221F4809194016A
+:107C70008093070181E0089520919501223261F1FE
+:107C8000213081F48091980190919901089711F425
+:107C900020939A0180919A01882309F04AC0EFEA63
+:107CA000F8E749C0223021F484E6E1ECF8E717C098
+:107CB000233009F03CC080919401882319F4E9E451
+:107CC000F8E739C0823019F4EDE4F8E734C08130C8
+:107CD00071F5E5E8F8E72FC081E0EBE2F8E7909175
+:107CE0009801382F981708F4392F90918C0120E0D3
+:107CF0004EEF8091E8008570E1F38091E80082FD0D
+:107D000012C02F5F84915D988093F100822F8F7352
+:107D100011F44093E800319694E6231750F39093C2
+:107D20008C0181E0089590938C0180E0089580E0BB
+:107D30000895EDE9F8E78491D2CF1092E90080919F
+:107D4000E80083FF61C082E991E068E0FBDE82EF3A
+:107D50008093E8008091920187FF05C08091E80040
+:107D600080FFFCCF03C08EEF8093E80080919301E9
+:107D7000853051F48091E80080FFFCCF8091940120
+:107D800080688093E30039C08930E1F480919401E8
+:107D900080938E01E7E2F8E791E031E026E39093EB
+:107DA000E9003093EB0084918093EC002093ED0088
+:107DB0009F5F3196953099F78EE78093EA00109295
+:107DC000EA001BC0883049F490918E015D9884E6EA
+:107DD00080938C019093F10010C0882339F45D9852
+:107DE00084E680938C011092F10007C0863011F474
+:107DF00043DF01C014DF882321F08EEF8093E80079
+:107E0000089581E28093EB0008958091E100109243
+:107E1000E100282F83FF0CC01092E90081E08093DD
+:107E2000EB001092EC0082E38093ED0010928E0143
+:107E300022FF1CC080918C01882331F081508093F7
+:107E40008C01882309F45D9A80918D01882331F09B
+:107E5000815080938D01882309F4289A80918F01A5
+:107E6000882321F4109291011092900108951F939C
+:107E7000CF93DF9312E0C0E9D1E05FDFC6DF10935C
+:107E8000E9008091E80085FF13C0289884E680937C
+:107E90008D019091F1008091E80085FD03C08BE693
+:107EA0008093E800892F90E0DF91CF911F91089592
+:107EB000809190019091910101979093910180930D
+:107EC00090018091900190919101892B09F446DDF8
+:0A7ED000CE010197F1F727DDD0CFB6
+:087EDA0000E1000000000000BF
+:040000030000780081
:00000001FF
diff --git a/arduino/bootloaders/diskloader/DiskLoader-Micro.hex b/arduino/bootloaders/diskloader/DiskLoader-Micro.hex
new file mode 100644
index 0000000..fbbcc52
--- /dev/null
+++ b/arduino/bootloaders/diskloader/DiskLoader-Micro.hex
@@ -0,0 +1,113 @@
+:1078000011241FBECFEFDAE0DEBFCDBFF2C04101D1
+:1078100042144505560455026403740300001E9586
+:1078200087020110030000C18081C106C0FF0A0069
+:107830000CA10185037508150026FF00954009017C
+:107840008102954009029102C004030904380341F2
+:107850000072006400750069006E006F0020004D2A
+:10786000006900630072006F00200062006F006F0B
+:107870000074006C006F00610064006500720020FD
+:1078800000200020001803410072006400750069A8
+:10789000006E006F0020004C004C004300120100FD
+:1078A00002020000404123350000010102000112E4
+:1078B00001000200000040412335000001010200E8
+:1078C00001090264000301008032080B0002020279
+:1078D000010009040000010202000005240010015B
+:1078E0000524010101042402020524060001070504
+:1078F000810310004009040100020A00000007058E
+:107900000202400000070583024000000904020053
+:107910000103000000092101010001221E000705EA
+:1079200084034000400020918A0130918B012C5F3C
+:107930003F4F30938B0120938A01C901892F9927EA
+:107940008695982F803418F08FE7891B982F990F10
+:10795000921710F447980895479A08955D9A289AC7
+:1079600081E08093E0001092E200EE27FF27099467
+:1079700008950F931F93CF93DF93982FEB01042F5C
+:1079800010E088E76030780730F411E083E0FB0115
+:1079900080935700E895892F68E071E0402FF8D078
+:1079A000112311F107B600FCFDCF402F4695FE01D3
+:1079B000A8E0B1E020E031E009C08D919D910C017B
+:1079C00030935700E895112432962F5F2417A8F3BF
+:1079D00085E0FE0180935700E89507B600FCFDCFD7
+:1079E00081E180935700E895DF91CF911F910F912E
+:1079F000089588E10FB6F8948093600010926000BB
+:107A00000FBE5D9A289A47983F9A209A559A90E817
+:107A1000909361001092610081E885BF95BF9FD06F
+:107A200084E18093880180E180938901E0E0F0E0C7
+:107A3000859194918F5F9F4F19F081E080938F0122
+:107A4000EE24FF24BB24B39454EFC52E51E0D52E71
+:107A50000ED2082F8EE098E7FC0124913196029611
+:107A60004491201711F02223B9F71092910110923E
+:107A7000900182E068E071E08BD0013479F460918C
+:107A800008016058633028F0683111F064E001C0EB
+:107A900063E0C62FD0E0CF5DD7480EC0063571F445
+:107AA00080910801803311F011E022C080910A0119
+:107AB000C82FD0E0C25ED74811E022C0053721F4BC
+:107AC00013E0CEE1D8E71CC0053539F4E090080199
+:107AD000F0900901EE0CFF1C0AC0043631F482E07C
+:107AE000B7014091090145DF02C0043721F010E0E1
+:107AF000C5E2D8E705C010910901E701E10EF11CCC
+:107B0000B6D18097B1F483E068E871E041E050E0DD
+:107B100059D0112329F0412F50E083E8BE0152D003
+:107B200083E469E871E041E050E04CD0013509F0B0
+:107B30008FCFD0929101C0929001B0928F01EE242C
+:107B4000FF2486CFFC01289884E680938D0104C031
+:107B50008091F100819361506623D1F708951092CE
+:107B600091011092900110928E0110928F0181E08C
+:107B70008093D70080EA8093D80082E189BD09B460
+:107B800000FEFDCF80E98093D8001092E0000895B8
+:107B9000FB018093E90024E69BE611C08091E80098
+:107BA00085FFFCCF289820938D018091F10081936F
+:107BB0008091E80085FD02C09093E8004150442385
+:107BC00069F70895982FFB01282F20728770809302
+:107BD000E90064E63AE317C08091E80085FFFCCF36
+:107BE00097FF02C0849101C080813196211180E00D
+:107BF0005D9860938C018093F1008091E80085FD91
+:107C000002C03093E800415050408FEF4F3F58077B
+:107C100019F796FF03C08AE38093E80008958091E6
+:107C20009301813299F45D9884E680938C0120E081
+:107C300030E003C080818093F100F901E050FF4FF4
+:107C40002F5F3F4F28303105A9F714C0803261F40F
+:107C50008091E80082FFFCCF80E091E067E072DF76
+:107C60008BEF8093E80006C0823221F4809194016A
+:107C70008093070181E0089520919501223261F1FE
+:107C8000213081F48091980190919901089711F425
+:107C900020939A0180919A01882309F04AC0EFEA63
+:107CA000F8E749C0223021F484E6E1ECF8E717C098
+:107CB000233009F03CC080919401882319F4E9E451
+:107CC000F8E739C0823019F4EDE4F8E734C08130C8
+:107CD00071F5E5E8F8E72FC081E0EBE2F8E7909175
+:107CE0009801382F981708F4392F90918C0120E0D3
+:107CF0004EEF8091E8008570E1F38091E80082FD0D
+:107D000012C02F5F84915D988093F100822F8F7352
+:107D100011F44093E800319694E6231750F39093C2
+:107D20008C0181E0089590938C0180E0089580E0BB
+:107D30000895EDE9F8E78491D2CF1092E90080919F
+:107D4000E80083FF61C082E991E068E0FBDE82EF3A
+:107D50008093E8008091920187FF05C08091E80040
+:107D600080FFFCCF03C08EEF8093E80080919301E9
+:107D7000853051F48091E80080FFFCCF8091940120
+:107D800080688093E30039C08930E1F480919401E8
+:107D900080938E01E7E2F8E791E031E026E39093EB
+:107DA000E9003093EB0084918093EC002093ED0088
+:107DB0009F5F3196953099F78EE78093EA00109295
+:107DC000EA001BC0883049F490918E015D9884E6EA
+:107DD00080938C019093F10010C0882339F45D9852
+:107DE00084E680938C011092F10007C0863011F474
+:107DF00043DF01C014DF882321F08EEF8093E80079
+:107E0000089581E28093EB0008958091E100109243
+:107E1000E100282F83FF0CC01092E90081E08093DD
+:107E2000EB001092EC0082E38093ED0010928E0143
+:107E300022FF1CC080918C01882331F081508093F7
+:107E40008C01882309F45D9A80918D01882331F09B
+:107E5000815080938D01882309F4289A80918F01A5
+:107E6000882321F4109291011092900108951F939C
+:107E7000CF93DF9312E0C0E9D1E05FDFC6DF10935C
+:107E8000E9008091E80085FF13C0289884E680937C
+:107E90008D019091F1008091E80085FD03C08BE693
+:107EA0008093E800892F90E0DF91CF911F91089592
+:107EB000809190019091910101979093910180930D
+:107EC00090018091900190919101892B09F446DDF8
+:0A7ED000CE010197F1F727DDD0CFB6
+:087EDA0000E1000000000000BF
+:040000030000780081
+:00000001FF
diff --git a/arduino/bootloaders/diskloader/Makefile b/arduino/bootloaders/diskloader/Makefile
index 8eec350..6ac3db3 100644
--- a/arduino/bootloaders/diskloader/Makefile
+++ b/arduino/bootloaders/diskloader/Makefile
@@ -1,103 +1,105 @@
-###############################################################################
-# Makefile for DiskLoader
-###############################################################################
-
-## General Flags
-PROJECT = DiskLoader
-TARGET = DiskLoader.elf
-CC = avr-gcc
-
-# BOARD2
-MCU = atmega32u4
-AVR_FREQ = 16000000L
-
+###############################################################################
+# Makefile for DiskLoader
+###############################################################################
+
+## General Flags
+PROJECT = DiskLoader
+TARGET = DiskLoader.elf
+CC = avr-gcc
+
+# BOARD2
+MCU = atmega32u4
+AVR_FREQ = 16000000L
+
# Specify the Arduino model using the assigned PID. This is used by Descriptors.c
# to set PID and product descriptor string
# Arduino Leonardo PID
-ARDUINO_MODEL_PID = 0x0032
+ARDUINO_MODEL_PID = 0x0034
# Arduino Micro PID
-#ARDUINO_MODEL_PID = 0x0033
-
-# Change if your programmer is different
-AVRDUDE_PROGRAMMER = avrispmkII
-AVRDUDE_PORT = usb
-
-# program name should not be changed...
-PROGRAM = DiskLoader
-
-AVRDUDE = avrdude
-AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) -p $(MCU)
-
-## Options common to compile, link and assembly rules
-COMMON = -mmcu=$(MCU)
-
-override CFLAGS = -g -Wall -Os -mmcu=$(MCU) -DF_CPU=$(AVR_FREQ) -DARDUINO_MODEL_PID=$(ARDUINO_MODEL_PID) $(DEFS) -ffunction-sections -gdwarf-2 -fdata-sections -fno-split-wide-types
-
-## Assembly specific flags
-ASMFLAGS = $(COMMON)
-ASMFLAGS += $(CFLAGS)
-ASMFLAGS += -x assembler-with-cpp -Wa,-gdwarf2
-
-## Linker flags
-LDFLAGS = $(COMMON)
-LDFLAGS += -Wl,-gc-sections,-Map=DiskLoader.map,--section-start=.text=0x7000,--relax
-
-## Intel Hex file production flags
-HEX_EEPROM_FLAGS = -j .eeprom
-HEX_EEPROM_FLAGS += --set-section-flags=.eeprom="alloc,load"
-HEX_EEPROM_FLAGS += --change-section-lma .eeprom=0 --no-change-warnings
-
-## Objects explicitly added by the user
-LINKONLYOBJECTS =
-
-MODULES := .
-SRC_DIR := $(addprefix src/,$(MODULES))
-BUILD_DIR := $(addprefix build/,$(MODULES))
-
-SRC := $(foreach sdir,$(SRC_DIR),$(wildcard $(sdir)/*.cpp))
-OBJ := $(patsubst src/%.cpp,build/%.o,$(SRC))
-DEP := $(OBJ:%.o=%.d)
-INCLUDES := $(addprefix -I,$(SRC_DIR))
-
-vpath %.cpp $(SRC_DIR)
-
-.PHONY: all checkdirs clean
-
-all: checkdirs $(TARGET) DiskLoader.hex DiskLoader.lss size
-
--include $(DEP)
-
-checkdirs: $(BUILD_DIR)
-
-$(BUILD_DIR):
- @mkdir -p $@
-
-clean:
- @rm -rf build/
- @rm -f *.hex
- @rm -f *.elf
- @rm -f *.lss
- @rm -f *.map
-
-define make-goal
-$1/%.o: %.cpp
- $(CC) $(INCLUDES) $(CFLAGS) -c $$< -MD -o $$@
-endef
-
-$(foreach bdir,$(BUILD_DIR),$(eval $(call make-goal,$(bdir))))
-
-$(TARGET): $(OBJ)
- $(CC) $(LDFLAGS) $(LINKONLYOBJECTS) $(LIBDIRS) $(LIBS) $^ -o $@
-
-%.hex: $(TARGET)
- avr-objcopy -O ihex $(HEX_FLASH_FLAGS) $< $@
-
-%.lss: $(TARGET)
- avr-objdump -h -S $< > $@
-
-size: $(TARGET)
- @echo
-# @avr-size -C --mcu=${MCU} ${TARGET}.elf
-
-program: $(TARGET).hex
- $(AVRDUDE) $(AVRDUDE_FLAGS) -B 1 -u -U flash:w:$(TARGET).hex
+#ARDUINO_MODEL_PID = 0x0035
+
+# Change if your programmer is different
+AVRDUDE_PROGRAMMER = avrispmkII
+AVRDUDE_PORT = usb
+
+# program name should not be changed...
+PROGRAM = DiskLoader
+
+AVRDUDE = avrdude
+AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) -p $(MCU)
+
+## Options common to compile, link and assembly rules
+COMMON = -mmcu=$(MCU)
+
+override CFLAGS = -g -Wall -Os -mmcu=$(MCU) -DF_CPU=$(AVR_FREQ) -DARDUINO_MODEL_PID=$(ARDUINO_MODEL_PID) $(DEFS) -ffunction-sections -gdwarf-2 -fdata-sections -fno-split-wide-types
+
+## Assembly specific flags
+ASMFLAGS = $(COMMON)
+ASMFLAGS += $(CFLAGS)
+ASMFLAGS += -x assembler-with-cpp -Wa,-gdwarf2
+
+## Linker flags
+LDFLAGS = $(COMMON)
+LDFLAGS += -Wl,-gc-sections,-Map=DiskLoader.map,--section-start=.text=0x7800,--relax
+LDFLAGS += -nodefaultlibs -nostartfiles
+
+
+## Intel Hex file production flags
+HEX_EEPROM_FLAGS = -j .eeprom
+HEX_EEPROM_FLAGS += --set-section-flags=.eeprom="alloc,load"
+HEX_EEPROM_FLAGS += --change-section-lma .eeprom=0 --no-change-warnings
+
+## Objects explicitly added by the user
+LINKONLYOBJECTS =
+
+MODULES := .
+SRC_DIR := $(addprefix src/,$(MODULES))
+BUILD_DIR := $(addprefix build/,$(MODULES))
+
+SRC := $(foreach sdir,$(SRC_DIR),$(wildcard $(sdir)/*.cpp))
+OBJ := $(patsubst src/%.cpp,build/%.o,$(SRC))
+DEP := $(OBJ:%.o=%.d)
+INCLUDES := $(addprefix -I,$(SRC_DIR))
+
+vpath %.cpp $(SRC_DIR)
+
+.PHONY: all checkdirs clean
+
+all: checkdirs $(TARGET) DiskLoader.hex DiskLoader.lss size
+
+-include $(DEP)
+
+checkdirs: $(BUILD_DIR)
+
+$(BUILD_DIR):
+ @mkdir -p $@
+
+clean:
+ @rm -rf build/
+ @rm -f *.hex
+ @rm -f *.elf
+ @rm -f *.lss
+ @rm -f *.map
+
+define make-goal
+$1/%.o: %.cpp
+ $(CC) $(INCLUDES) $(CFLAGS) -c $$< -MD -o $$@
+endef
+
+$(foreach bdir,$(BUILD_DIR),$(eval $(call make-goal,$(bdir))))
+
+$(TARGET): $(OBJ)
+ $(CC) $(LDFLAGS) $(LINKONLYOBJECTS) $(LIBDIRS) $(LIBS) $^ -o $@
+
+%.hex: $(TARGET)
+ avr-objcopy -O ihex $(HEX_FLASH_FLAGS) $< $@
+
+%.lss: $(TARGET)
+ avr-objdump -h -S $< > $@
+
+size: $(TARGET)
+ @echo
+# @avr-size -C --mcu=${MCU} ${TARGET}.elf
+
+program: $(TARGET).hex
+ $(AVRDUDE) $(AVRDUDE_FLAGS) -B 5 -u -U flash:w:$(TARGET).hex
\ No newline at end of file
diff --git a/arduino/bootloaders/diskloader/src/DiskLoader.cpp b/arduino/bootloaders/diskloader/src/DiskLoader.cpp
index 2792bc6..6580618 100644
--- a/arduino/bootloaders/diskloader/src/DiskLoader.cpp
+++ b/arduino/bootloaders/diskloader/src/DiskLoader.cpp
@@ -1,67 +1,64 @@
-/*
- * DiskLoader.cpp
- */
+
#include "Platform.h"
+// This bootloader creates a composite Serial device
+//
+// The serial interface supports a STK500v1 protocol that is very similar to optiboot
+//
+// The bootloader will timeout and start the firmware after a few hundred milliseconds
+// if a usb connection is not detected.
+//
+// The tweakier code is to keep the bootloader below 2k (no interrupt table, for example)
+
extern "C"
void entrypoint(void) __attribute__ ((naked)) __attribute__ ((section (".vectors")));
void entrypoint(void)
{
asm volatile (
- "eor r1, r1\n" // Zero register
- "out 0x3F, r1\n" // SREG
- "ldi r28, 0xFF\n" // Y-register
- "ldi r29, 0x0A\n" // Y-register
- "out 0x3E, r29\n" // SPH
- "out 0x3D, r28\n" // SPL
- "rjmp main" // Stack is all set up, start the main code
- ::);
+ "eor r1, r1\n" // Zero register
+ "out 0x3F, r1\n" // SREG
+ "ldi r28, 0xFF\n"
+ "ldi r29, 0x0A\n"
+ "out 0x3E, r29\n" // SPH
+ "out 0x3D, r28\n" // SPL
+ "rjmp main" // Stack is all set up, start the main code
+ ::);
}
u8 _flashbuf[128];
u8 _inSync;
u8 _ok;
-u16 do_reset = 0;
-volatile u16 _timeout = 0;
+extern volatile u8 _ejected;
+extern volatile u16 _timeout;
void Program(u8 ep, u16 page, u8 count)
{
- u8 write = page < 28*1024; // Don't write over bootloader please
+ u8 write = page < 30*1024; // Don't write over firmware please
if (write)
boot_page_erase(page);
-
- USB_Recv_block(ep,_flashbuf,count); // Read while page is erasing
-
+
+ Recv(ep,_flashbuf,count); // Read while page is erasing
+
if (!write)
return;
-
+
boot_spm_busy_wait(); // Wait until the memory is erased.
-
+
count >>= 1;
u16* p = (u16*)page;
u16* b = (u16*)_flashbuf;
for (u8 i = 0; i < count; i++)
boot_page_fill(p++, b[i]);
-
+
boot_page_write(page);
boot_spm_busy_wait();
boot_rww_enable ();
}
-u16 _pulse;
-void LEDPulse()
-{
- _pulse += 1;
- u8 p = _pulse >> 9;
- if (p > 63)
- p = 127-p;
- p += p;
- if (((u8)_pulse) > p)
- L_LED_OFF();
- else
- L_LED_ON();
-}
+
+int USBGetChar();
+#define getch USBGetChar
#define HW_VER 0x02
#define SW_MAJOR 0x01
@@ -107,147 +104,136 @@ const u8 _consts[] =
0x00, //
};
-void start_sketch()
-{
- if (pgm_read_word(0) == -1) // no sketch has been uploaded yet - stay in bootloader
- return;
-
- L_LED_OFF();
- RX_LED_OFF();
- TX_LED_OFF();
- /* move interrupts to application section:
- * uses inline assembly because the procedure must be completed in four cycles.
- */
- cli(); // disable interrupts first
- asm volatile (
- "ldi r16, 0x01\n" // (1<<IVCE) /* Enable change of interrupt vectors */
- "out 0x35, r16\n" // MCUCR
- "ldi r16, 0x00\n" // (1<<IVSEL) /* Move interrupts to application flash section */
- "out 0x35, r16\n" // MCUCR
- );
- UDCON = 1; // Detatch USB
- UDIEN = 0;
- asm volatile ( // Reset vector to run firmware
- "clr r30\n"
- "clr r31\n"
- "ijmp\n"
- ::);
-}
+void USBInit(void);
int main(void) __attribute__ ((naked));
-int main()
-{
+
+// STK500v1 main loop, very similar to optiboot in protocol and implementation
+int main()
+{
wdt_disable();
+ TXLED0;
+ RXLED0;
+ LED0;
BOARD_INIT();
- /* move interrupts to boot section:
- * uses inline assembly because the procedure must be completed in four cycles.
- * seems to fail if called before disabling WDT and calling BOARD_INIT()
- */
- asm volatile (
- "ldi r16, 0x01\n" // (1<<IVCE) /* Enable change of interrupt vectors */
- "out 0x35, r16\n" // MCUCR
- "ldi r16, 0x02\n" // (1<<IVSEL) /* Move interrupts to boot flash section */
- "out 0x35, r16\n" // MCUCR
- );
- TX_LED_OFF();
- RX_LED_OFF();
- L_LED_OFF();
- USB.attach();
- sei();
-
+ USBInit();
+
_inSync = STK_INSYNC;
_ok = STK_OK;
-
- for (;;)
+
+ if (pgm_read_word(0) != -1)
+ _ejected = 1;
+
+ for(;;)
{
u8* packet = _flashbuf;
u16 address = 0;
for (;;)
- {
- if (USB_Available(CDC_RX))
+ {
+ u8 cmd = getch();
+
+ // Read packet contents
+ u8 len;
+ const u8* rs = _readSize;
+ for(;;)
{
- u8 cmd = USB_Recv(CDC_RX);
-
- // Read packet contents
- u8 len;
- const u8* rs = _readSize;
- for (;;)
- {
- u8 c = pgm_read_byte(rs++);
- len = pgm_read_byte(rs++);
- if (c == cmd || c == 0)
- break;
- }
- _timeout = 0;
- // Read params
- USB_Recv_block(CDC_RX, packet, len);
-
- // Send a response
- u8 send = 0;
- const u8* pgm = _consts+7;
- if (STK_GET_PARAMETER == cmd)
- {
- u8 i = packet[0] - 0x80;
- if (i > 2)
- i = (i==0x18) ? 3 : 4;
- pgm = _consts + i + 3;
- send = 1;
- }
- else if (STK_UNIVERSAL == cmd)
- {
- if (packet[0] == 0x30)
- pgm = _consts + packet[2];
- send = 1;
- }
- else if (STK_READ_SIGN == cmd)
- {
- pgm = _consts;
- send = 3;
- }
- else if (STK_LOAD_ADDRESS == cmd)
- {
- address = *((u16*)packet); // word address
- address += address;
- }
- else if (STK_PROG_PAGE == cmd)
- {
- Program(CDC_RX, address, packet[1]);
- }
- else if (STK_READ_PAGE == cmd)
- {
- send = packet[1];
- pgm = (const u8*)address;
- address += send;
- }
-
- u16 countdown = 5000;
- while (countdown-- > 10 && !USB_Available(CDC_RX))
- ;
- int x = USB_Recv(CDC_RX);
- if (x != -1 && x != ' ')
+ u8 c = pgm_read_byte(rs++);
+ len = pgm_read_byte(rs++);
+ if (c == cmd || c == 0)
break;
-
- USB_Send(CDC_TX, &_inSync, 1);
-
- if (send)
- USB_Send(CDC_TX|TRANSFER_PGM, pgm, send);
-
- // Send ok
- USB_Send(CDC_TX|TRANSFER_RELEASE, &_ok, 1);
-
- if ('Q' == cmd)
- {
- _delay_ms(100);
- start_sketch();
- }
}
- else
+ _timeout = 0;
+ // Read params
+ Recv(CDC_RX,packet,len);
+
+ // Send a response
+ u8 send = 0;
+ const u8* pgm = _consts+7; // 0
+ if (STK_GET_PARAMETER == cmd)
+ {
+ u8 i = packet[0] - 0x80;
+ if (i > 2)
+ i = (i == 0x18) ? 3 : 4; // 0x80:HW_VER,0x81:SW_MAJOR,0x82:SW_MINOR,0x18:3 or 0
+ pgm = _consts + i + 3;
+ send = 1;
+ }
+
+ else if (STK_UNIVERSAL == cmd)
{
- LEDPulse();
- _delay_us(100);
- if (_timeout-- == 1)
- start_sketch();
+ if (packet[0] == 0x30)
+ pgm = _consts + packet[2]; // read signature
+ send = 1;
}
+
+ // Read signature bytes
+ else if (STK_READ_SIGN == cmd)
+ {
+ pgm = _consts;
+ send = 3;
+ }
+
+ else if (STK_LOAD_ADDRESS == cmd)
+ {
+ address = *((u16*)packet); // word addresses
+ address += address;
+ }
+
+ else if (STK_PROG_PAGE == cmd)
+ {
+ Program(CDC_RX,address,packet[1]);
+ }
+
+ else if (STK_READ_PAGE == cmd)
+ {
+ send = packet[1];
+ pgm = (const u8*)address;
+ address += send; // not sure of this is required
+ }
+
+ // Check sync
+ if (getch() != ' ')
+ break;
+ Transfer(CDC_TX,&_inSync,1);
+
+ // Send result
+ if (send)
+ Transfer(CDC_TX|TRANSFER_PGM,pgm,send); // All from pgm memory
+
+ // Send ok
+ Transfer(CDC_TX|TRANSFER_RELEASE,&_ok,1);
+
+ if (cmd == 'Q')
+ break;
}
+ _timeout = 500; // wait a moment before exiting the bootloader - may need to finish responding to 'Q' for example
+ _ejected = 1;
}
}
+
+// Nice breathing LED indicates we are in the firmware
+u16 _pulse;
+void LEDPulse()
+{
+ _pulse += 4;
+ u8 p = _pulse >> 9;
+ if (p > 63)
+ p = 127-p;
+ p += p;
+ if (((u8)_pulse) > p)
+ LED0;
+ else
+ LED1;
+}
+
+void Reboot()
+{
+ TXLED0; // switch off the RX and TX LEDs before starting the user sketch
+ RXLED0;
+ UDCON = 1; // Detatch USB
+ UDIEN = 0;
+ asm volatile ( // Reset vector to run firmware
+ "clr r30\n"
+ "clr r31\n"
+ "ijmp\n"
+ ::);
+}
diff --git a/arduino/bootloaders/diskloader/src/Platform.h b/arduino/bootloaders/diskloader/src/Platform.h
index d1f884c..6acbf39 100644
--- a/arduino/bootloaders/diskloader/src/Platform.h
+++ b/arduino/bootloaders/diskloader/src/Platform.h
@@ -1,9 +1,3 @@
-/*
- * Platform.h
- */
-
-#ifndef __PLATFORM_H__
-#define __PLATFORM_H__
#include <inttypes.h>
#include <avr/io.h>
@@ -17,50 +11,39 @@
#include <stdlib.h>
#include <string.h>
-#ifdef __cplusplus
-extern "C"{
-#endif
-
typedef unsigned char u8;
typedef unsigned short u16;
typedef unsigned long u32;
-#define USB_PID_LEONARDO 0x0032
-#define USB_PID_MICRO 0x0033
-#define USB_VID 0x2341 // arduino LLC vid
-#define USB_PID ARDUINO_MODEL_PID // passed in by Makefile - 0x0032 for Leonardo, 0x0033 for Micro
-
-#define min(a,b) ((a)<(b)?(a):(b))
#define CPU_PRESCALE(n) (CLKPR = 0x80, CLKPR = (n))
-#define DISABLE_JTAG() MCUCR = (1 << JTD) | (1 << IVCE) | (0 << PUD); MCUCR = (1 << JTD) | (0 << IVSEL) | (0 << IVCE) | (0 << PUD)
+#define DISABLE_JTAG() MCUCR = (1 << JTD) | (1 << IVCE) | (0 << PUD); MCUCR = (1 << JTD) | (0 << IVSEL) | (0 << IVCE) | (0 << PUD);
-#define BOARD_INIT() DDRC |= (1<<7); DDRB |= (1<<0); DDRE |= (1<<6); CPU_PRESCALE(0); DISABLE_JTAG(); // for XXX-series boards
-//#define BOARD_INIT() DDRC |= (1<<7); DDRB |= (1<<0); DDRD |= (1<<5); CPU_PRESCALE(0); DISABLE_JTAG(); // for non-XXX boards
+#define USB_PID_LEONARDO 0x0034
+#define USB_PID_MICRO 0x0035
+#define USB_VID 0x2341 // arduino LLC vid
+#define USB_PID ARDUINO_MODEL_PID // passed in by Makefile - 0x0034 for Leonardo, 0x0035 for MIcro
+
+#define OEM_NAME 'l','e','o','n','a','r','d','o' // 8 chars
+#define BOARD_INIT() DDRC |= (1<<7); DDRB |= (1<<0); DDRD |= (1<<5); CPU_PRESCALE(0); DISABLE_JTAG();
+#define LED0 PORTC &= ~(1<<7)
+#define LED1 PORTC |= (1<<7)
+#define TXLED0 PORTD |= (1<<5)
+#define TXLED1 PORTD &= ~(1<<5)
+#define RXLED0 PORTB |= (1<<0)
+#define RXLED1 PORTB &= ~(1<<0)
-// for XXX-series boards
-#define TX_LED_OFF() PORTE |= (1<<6)
-#define TX_LED_ON() PORTE &= ~(1<<6)
-#define RX_LED_OFF() PORTB |= (1<<0)
-#define RX_LED_ON() PORTB &= ~(1<<0)
-#define L_LED_OFF() PORTC &= ~(1<<7)
-#define L_LED_ON() PORTC |= (1<<7)
-#define L_LED_TOGGLE() PORTC ^= (1<<7)
+#define TRANSFER_PGM 0x80
+#define TRANSFER_RELEASE 0x40
+#define TRANSFER_ZERO 0x20
-// these for non-XXX boards
-//#define LED0 PORTC &= ~(1<<7)
-//#define LED1 PORTC |= (1<<7)
-//#define TXLED0 PORTD |= (1<<5)
-//#define TXLED1 PORTD &= ~(1<<5)
-//#define RXLED0 PORTB |= (1<<0)
-//#define RXLED1 PORTB &= ~(1<<0)
+void Transfer(u8 ep, const u8* data, int len);
+void Recv(u8 ep, u8* dst, u8 len);
+void Program(u8 ep, u16 page, u8 count);
-#ifdef __cplusplus
-} /* extern "C"{ */
-#endif
+#define CDC_ENABLED
+#include "USBCore.h"
#include "USBDesc.h"
-#include "USBCore.h"
-#include "USBAPI.h"
-#endif /* __PLATFORM_H__ */
+
diff --git a/arduino/bootloaders/diskloader/src/USBCore.cpp b/arduino/bootloaders/diskloader/src/USBCore.cpp
index 6518ae9..ca74721 100644
--- a/arduino/bootloaders/diskloader/src/USBCore.cpp
+++ b/arduino/bootloaders/diskloader/src/USBCore.cpp
@@ -1,4 +1,5 @@
+
/* Copyright (c) 2010, Peter Barrett
**
** Permission to use, copy, modify, and/or distribute this software for
@@ -16,10 +17,9 @@
*/
#include "Platform.h"
-#include "USBAPI.h"
-#include "USBDesc.h"
-#if defined(USBCON)
+#define CDC_TX CDC_ENDPOINT_IN
+#define CDC_RX CDC_ENDPOINT_OUT
#define EP_TYPE_CONTROL 0x00
#define EP_TYPE_BULK_IN 0x81
@@ -31,50 +31,32 @@
/** Pulse generation counters to keep track of the number of milliseconds remaining for each pulse type */
#define TX_RX_LED_PULSE_MS 100
-volatile u8 TxLEDPulse; /**< Milliseconds remaining for data Tx LED pulse */
-volatile u8 RxLEDPulse; /**< Milliseconds remaining for data Rx LED pulse */
+u8 TxLEDPulse; /**< Milliseconds remaining for data Tx LED pulse */
+u8 RxLEDPulse; /**< Milliseconds remaining for data Rx LED pulse */
+
+void Reboot();
//==================================================================
//==================================================================
-extern const u16 STRING_LANGUAGE[] PROGMEM;
-extern const u16 STRING_IPRODUCT[] PROGMEM;
-extern const u16 STRING_IMANUFACTURER[] PROGMEM;
-extern const DeviceDescriptor USB_DeviceDescriptor PROGMEM;
-extern const DeviceDescriptor USB_DeviceDescriptorA PROGMEM;
-
-const u16 STRING_LANGUAGE[2] = {
- (3<<8) | (2+2),
- 0x0409 // English
-};
-
-const u16 STRING_IPRODUCT[17] = {
- (3<<8) | (2+2*16),
-#if USB_PID == USB_PID_LEONARDO
- 'A','r','d','u','i','n','o',' ','L','e','o','n','a','r','d','o'
-#elif USB_PID == USB_PID_MICRO
- 'A','r','d','u','i','n','o',' ','M','i','c','r','o',' ',' ',' '
-#endif
-};
-
-const u16 STRING_IMANUFACTURER[12] = {
- (3<<8) | (2+2*11),
- 'A','r','d','u','i','n','o',' ','L','L','C'
-};
-
-#define DEVICE_CLASS 0x02
-
-// DEVICE DESCRIPTOR
-const DeviceDescriptor USB_DeviceDescriptor =
- D_DEVICE(0x00,0x00,0x00,64,USB_VID,USB_PID,0x100,IMANUFACTURER,IPRODUCT,0,1);
+typedef struct
+{
+ u32 dwDTERate;
+ u8 bCharFormat;
+ u8 bParityType;
+ u8 bDataBits;
+ u8 lineState;
+} LineInfo;
-const DeviceDescriptor USB_DeviceDescriptorA =
- D_DEVICE(DEVICE_CLASS,0x00,0x00,64,USB_VID,USB_PID,0x100,IMANUFACTURER,IPRODUCT,0,1);
+static volatile LineInfo _usbLineInfo = { 57600, 0x00, 0x00, 0x00, 0x00 };
//==================================================================
//==================================================================
-volatile u8 _usbConfiguration = 0;
+// 4 bytes of RAM
+volatile u8 _usbConfiguration;
+volatile u8 _ejected;
+volatile u16 _timeout;
static inline void WaitIN(void)
{
@@ -104,25 +86,34 @@ static inline void ClearOUT(void)
UEINTX = ~(1<<RXOUTI);
}
+static
+void Send(volatile const u8* data, u8 count)
+{
+ TXLED1; // light the TX LED
+ TxLEDPulse = TX_RX_LED_PULSE_MS;
+ while (count--)
+ UEDATX = *data++;
+}
+
void Recv(volatile u8* data, u8 count)
{
+ RXLED1; // light the RX LED
+ RxLEDPulse = TX_RX_LED_PULSE_MS;
while (count--)
*data++ = UEDATX;
-
- RX_LED_ON();
- RxLEDPulse = TX_RX_LED_PULSE_MS;
}
static inline u8 Recv8()
{
- RX_LED_ON();
+ RXLED1; // light the RX LED
RxLEDPulse = TX_RX_LED_PULSE_MS;
-
- return UEDATX;
+ return UEDATX;
}
static inline void Send8(u8 d)
{
+ TXLED1; // light the TX LED
+ TxLEDPulse = TX_RX_LED_PULSE_MS;
UEDATX = d;
}
@@ -184,37 +175,48 @@ static inline u8 FrameNumber()
//==================================================================
//==================================================================
-u8 USBGetConfiguration(void)
+#define EP_SINGLE_64 0x32 // EP0
+#define EP_DOUBLE_64 0x36 // Other endpoints
+
+static void InitEP(u8 index, u8 type, u8 size)
{
- return _usbConfiguration;
+ UENUM = index;
+ UECONX = 1;
+ UECFG0X = type;
+ UECFG1X = size;
}
-#define USB_RECV_TIMEOUT
-class LockEP
+// API
+void USBInit(void)
{
- u8 _sreg;
-public:
- LockEP(u8 ep) : _sreg(SREG)
- {
- cli();
- SetEP(ep & 7);
- }
- ~LockEP()
- {
- SREG = _sreg;
- }
-};
+ _timeout = 0;
+ _usbConfiguration = 0;
+ _ejected = 0;
+
+ UHWCON = 0x01; // power internal reg (don't need this?)
+ USBCON = (1<<USBE)|(1<<FRZCLK); // clock frozen, usb enabled
+ PLLCSR = 0x12; // Need 16 MHz xtal
+ while (!(PLLCSR & (1<<PLOCK))) // wait for lock pll
+ ;
+ USBCON = ((1<<USBE)|(1<<OTGPADE)); // start USB clock
+ UDCON = 0; // enable attach resistor
+}
-// Number of bytes, assumes a rx endpoint
-u8 USB_Available(u8 ep)
+u8 USBGetConfiguration(void)
{
- LockEP lock(ep);
- return FifoByteCount();
+ return _usbConfiguration;
+}
+
+u8 HasData(u8 ep)
+{
+ SetEP(ep);
+ return ReadWriteAllowed(); // count in fifo
}
-void USB_Recv_block(u8 ep, u8* dst, int len)
+int USBGetChar();
+void Recv(u8 ep, u8* dst, u8 len)
{
- LockEP lock(ep);
+ SetEP(ep);
while (len--)
{
while (!ReadWriteAllowed())
@@ -222,119 +224,47 @@ void USB_Recv_block(u8 ep, u8* dst, int len)
*dst++ = Recv8();
if (!ReadWriteAllowed()) // release empty buffer
ReleaseRX();
- }
-}
-
-// Non Blocking receive
-// Return number of bytes read
-int USB_Recv(u8 ep, void* d, int len)
-{
- if (!_usbConfiguration || len < 0)
- return -1;
-
- LockEP lock(ep);
- u8 n = FifoByteCount();
- len = min(n,len);
- n = len;
- u8* dst = (u8*)d;
- while (n--)
- *dst++ = Recv8();
- if (len && !FifoByteCount()) // release empty buffer
- ReleaseRX();
-
- return len;
-}
-
-// Recv 1 byte if ready
-int USB_Recv(u8 ep)
-{
- u8 c;
- if (USB_Recv(ep,&c,1) != 1)
- return -1;
- return c;
-}
-
-// Space in send EP
-u8 USB_SendSpace(u8 ep)
-{
- LockEP lock(ep);
- if (!ReadWriteAllowed())
- return 0;
- return 64 - FifoByteCount();
+ }
}
-// Blocking Send of data to an endpoint
-int USB_Send(u8 ep, const void* d, int len)
+// Transmit a packet to endpoint
+void Transfer(u8 ep, const u8* data, int len)
{
- if (!_usbConfiguration)
- return -1;
-
- int r = len;
- const u8* data = (const u8*)d;
- while (len)
+ u8 zero = ep & TRANSFER_ZERO;
+ SetEP(ep & 7);
+ while (len--)
{
- u8 n = USB_SendSpace(ep);
- if (n == 0)
- {
- _delay_ms(1);
- continue;
- }
+ while (!ReadWriteAllowed())
+ ; // TODO Check for STALL etc
- if (n > len)
- n = len;
- len -= n;
- {
- LockEP lock(ep);
- if (ep & TRANSFER_ZERO)
- {
- while (n--)
- Send8(0);
- }
- else if (ep & TRANSFER_PGM)
- {
- while (n--)
- Send8(pgm_read_byte(data++));
- }
- else
- {
- while (n--)
- Send8(*data++);
- }
- if (!ReadWriteAllowed() || ((len == 0) && (ep & TRANSFER_RELEASE))) // Release full buffer
- ReleaseTX();
- }
+ u8 d = (ep & TRANSFER_PGM) ? pgm_read_byte(data) : data[0];
+ data++;
+ if (zero)
+ d = 0;
+ Send8(d);
+
+ if (!ReadWriteAllowed())
+ ReleaseTX();
}
if (ep & TRANSFER_RELEASE)
ReleaseTX();
-
- TX_LED_ON();
- TxLEDPulse = TX_RX_LED_PULSE_MS;
- return r;
}
extern const u8 _initEndpoints[] PROGMEM;
const u8 _initEndpoints[] =
{
0,
+
+#ifdef CDC_ENABLED
EP_TYPE_INTERRUPT_IN, // CDC_ENDPOINT_ACM
EP_TYPE_BULK_OUT, // CDC_ENDPOINT_OUT
EP_TYPE_BULK_IN, // CDC_ENDPOINT_IN
-};
-
-#define EP_SINGLE_64 0x32 // EP0
-#define EP_DOUBLE_64 0x36 // Other endpoints
+#endif
-static
-void InitEP(u8 index, u8 type, u8 size)
-{
- UENUM = index;
- UECONX = 1;
- UECFG0X = type;
- UECFG1X = size;
-}
+ EP_TYPE_INTERRUPT_IN, // HID_ENDPOINT_INT
+};
-static
-void InitEndpoints()
+static void InitEndpoints()
{
for (u8 i = 1; i < sizeof(_initEndpoints); i++)
{
@@ -347,113 +277,99 @@ void InitEndpoints()
UERST = 0;
}
-// Handle CLASS_INTERFACE requests
-static
-bool ClassInterfaceRequest(Setup& setup)
+typedef struct
{
- u8 i = setup.wIndex;
-
- if (CDC_ACM_INTERFACE == i)
- return CDC_Setup(setup);
-
- return false;
-}
+ u8 bmRequestType;
+ u8 bRequest;
+ u8 wValueL;
+ u8 wValueH;
+ u16 wIndex;
+ u16 wLength;
+} Setup;
+Setup _setup;
-int _cmark;
-int _cend;
-void InitControl(int end)
+//bool USBHook(Setup& setup)
+bool USBHook()
{
- SetEP(0);
- _cmark = 0;
- _cend = end;
-}
+ Setup& setup = _setup;
+ u8 r = setup.bRequest;
-static
-bool SendControl(u8 d)
-{
- if (_cmark < _cend)
+ // CDC Requests
+ if (CDC_GET_LINE_CODING == r)
{
- if (!WaitForINOrOUT())
- return false;
- Send8(d);
- if (!((_cmark + 1) & 0x3F))
- ClearIN(); // Fifo is full, release this packet
+ Send((const volatile u8*)&_usbLineInfo,7);
}
- _cmark++;
- return true;
-};
-// Clipped by _cmark/_cend
-int USB_SendControl(u8 flags, const void* d, int len)
-{
- int sent = len;
- const u8* data = (const u8*)d;
- bool pgm = flags & TRANSFER_PGM;
- while (len--)
+ else if (CDC_SET_LINE_CODING == r)
{
- u8 c = pgm ? pgm_read_byte(data++) : *data++;
- if (!SendControl(c))
- return -1;
+ WaitOUT();
+ Recv((volatile u8*)&_usbLineInfo,7);
+ ClearOUT();
}
- return sent;
-}
-// Does not timeout or cross fifo boundaries
-// Will only work for transfers <= 64 bytes
-// TODO
-int USB_RecvControl(void* d, int len)
-{
- WaitOUT();
- Recv((u8*)d,len);
- ClearOUT();
- return len;
-}
+ else if (CDC_SET_CONTROL_LINE_STATE == r)
+ {
+ _usbLineInfo.lineState = setup.wValueL;
+ }
-int SendInterfaces()
-{
- int total = 0;
- u8 interfaces = 0;
- total = CDC_GetInterface(&interfaces);
- return interfaces;
+ return true;
}
-// Construct a dynamic configuration descriptor
-// This really needs dynamic endpoint allocation etc
-// TODO
-static
-bool SendConfiguration(int maxlen)
+extern const u8 _rawHID[] PROGMEM;
+#define LSB(_x) ((_x) & 0xFF)
+#define MSB(_x) ((_x) >> 8)
+
+#define RAWHID_USAGE_PAGE 0xFFC0
+#define RAWHID_USAGE 0x0C00
+#define RAWHID_TX_SIZE 64
+#define RAWHID_RX_SIZE 64
+
+const u8 _rawHID[] =
{
- // Count and measure interfaces
- InitControl(0);
- int interfaces = SendInterfaces();
- ConfigDescriptor config = D_CONFIG(_cmark + sizeof(ConfigDescriptor),interfaces);
+ // RAW HID
+ 0x06, LSB(RAWHID_USAGE_PAGE), MSB(RAWHID_USAGE_PAGE), // 30
+ 0x0A, LSB(RAWHID_USAGE), MSB(RAWHID_USAGE),
- // Now send them
- InitControl(maxlen);
- USB_SendControl(0,&config,sizeof(ConfigDescriptor));
- SendInterfaces();
- return true;
-}
+ 0xA1, 0x01, // Collection 0x01
+ 0x85, 0x03, // REPORT_ID (3)
+ 0x75, 0x08, // report size = 8 bits
+ 0x15, 0x00, // logical minimum = 0
+ 0x26, 0xFF, 0x00, // logical maximum = 255
-u8 _cdcComposite = 0;
+ 0x95, 64, // report count TX
+ 0x09, 0x01, // usage
+ 0x81, 0x02, // Input (array)
-static
-bool SendDescriptor(Setup& setup)
-{
- u8 t = setup.wValueH;
- if (USB_CONFIGURATION_DESCRIPTOR_TYPE == t)
- return SendConfiguration(setup.wLength);
+ 0x95, 64, // report count RX
+ 0x09, 0x02, // usage
+ 0x91, 0x02, // Output (array)
+ 0xC0 // end collection
+};
- InitControl(setup.wLength);
+u8 _cdcComposite = 0;
+bool SendDescriptor()
+{
+ Setup& setup = _setup;
u8 desc_length = 0;
const u8* desc_addr = 0;
- if (USB_DEVICE_DESCRIPTOR_TYPE == t)
+
+ u8 t = setup.wValueH;
+ if (0x22 == t)
+ {
+ desc_addr = _rawHID;
+ desc_length = sizeof(desc_length);
+ } else if (USB_DEVICE_DESCRIPTOR_TYPE == t)
{
if (setup.wLength == 8)
_cdcComposite = 1;
desc_addr = _cdcComposite ? (const u8*)&USB_DeviceDescriptorA : (const u8*)&USB_DeviceDescriptor;
}
+ else if (USB_CONFIGURATION_DESCRIPTOR_TYPE == t)
+ {
+ desc_addr = (const u8*)&USB_ConfigDescriptor;
+ desc_length = sizeof(USB_ConfigDescriptor);
+ }
else if (USB_STRING_DESCRIPTOR_TYPE == t)
{
if (setup.wValueL == 0)
@@ -464,106 +380,81 @@ bool SendDescriptor(Setup& setup)
desc_addr = (const u8*)&STRING_IMANUFACTURER;
else
return false;
- }
-
- if (desc_addr == 0)
+ } else
return false;
+
if (desc_length == 0)
desc_length = pgm_read_byte(desc_addr);
-
- USB_SendControl(TRANSFER_PGM,desc_addr,desc_length);
+ if ((u8)setup.wLength < desc_length) // bit of a cheat limiting to 255 bytes TODO (saved 8 bytes)
+ desc_length = (u8)setup.wLength;
+
+ // Send descriptor
+ // EP0 is 64 bytes long
+ // RWAL and FIFOCON don't work on EP0
+ u8 n = 0;
+ do
+ {
+ if (!WaitForINOrOUT())
+ return false;
+ Send8(pgm_read_byte(&desc_addr[n++]));
+ u8 clr = n & 0x3F;
+ if (!clr)
+ ClearIN(); // Fifo is full, release this packet
+ } while (n < desc_length);
return true;
}
-// Endpoint 0 interrupt
-ISR(USB_COM_vect)
+void USBSetupInterrupt()
{
SetEP(0);
if (!ReceivedSetupInt())
return;
- Setup setup;
+ Setup& setup = _setup; // global saves ~30 bytes
Recv((u8*)&setup,8);
ClearSetupInt();
- u8 requestType = setup.bmRequestType;
- if (requestType & REQUEST_DEVICETOHOST)
+ if (setup.bmRequestType & DEVICETOHOST)
WaitIN();
else
ClearIN();
bool ok = true;
- if (REQUEST_STANDARD == (requestType & REQUEST_TYPE))
+ u8 r = setup.bRequest;
+ if (SET_ADDRESS == r)
{
- // Standard Requests
- u8 r = setup.bRequest;
- if (GET_STATUS == r)
- {
- Send8(0); // TODO
- Send8(0);
- }
- else if (CLEAR_FEATURE == r)
- {
- }
- else if (SET_FEATURE == r)
- {
- }
- else if (SET_ADDRESS == r)
- {
- WaitIN();
- UDADDR = setup.wValueL | (1<<ADDEN);
- }
- else if (GET_DESCRIPTOR == r)
- {
- ok = SendDescriptor(setup);
- }
- else if (SET_DESCRIPTOR == r)
- {
- ok = false;
- }
- else if (GET_CONFIGURATION == r)
- {
- Send8(1);
- }
- else if (SET_CONFIGURATION == r)
- {
- if (REQUEST_DEVICE == (requestType & REQUEST_RECIPIENT))
- {
- InitEndpoints();
- _usbConfiguration = setup.wValueL;
- } else
- ok = false;
- }
- else if (GET_INTERFACE == r)
- {
- }
- else if (SET_INTERFACE == r)
- {
- }
+ WaitIN();
+ UDADDR = setup.wValueL | (1<<ADDEN);
+ }
+ else if (SET_CONFIGURATION == r)
+ {
+ _usbConfiguration = setup.wValueL;
+ InitEndpoints();
+ }
+ else if (GET_CONFIGURATION == r)
+ {
+ Send8(_usbConfiguration);
+ }
+ else if (GET_STATUS == r)
+ {
+ Send8(0); // All good as far as I know
+ }
+ else if (GET_DESCRIPTOR == r)
+ {
+ ok = SendDescriptor();
}
else
{
- InitControl(setup.wLength); // Max length of transfer
- ok = ClassInterfaceRequest(setup);
+ ok = USBHook();
}
if (ok)
ClearIN();
else
- {
Stall();
- }
}
-void USB_Flush(u8 ep)
-{
- SetEP(ep);
- if (FifoByteCount())
- ReleaseTX();
-}
-
-// General interrupt
-ISR(USB_GEN_vect)
+void USBGeneralInterrupt()
{
u8 udint = UDINT;
UDINT = 0;
@@ -573,67 +464,45 @@ ISR(USB_GEN_vect)
{
InitEP(0,EP_TYPE_CONTROL,EP_SINGLE_64); // init ep0
_usbConfiguration = 0; // not configured yet
- UEIENX = 1 << RXSTPE; // Enable interrupts for ep0
}
// Start of Frame - happens every millisecond so we use it for TX and RX LED one-shot timing, too
if (udint & (1<<SOFI))
{
- USB_Flush(CDC_TX); // Send a tx frame if found
-
// check whether the one-shot period has elapsed. if so, turn off the LED
if (TxLEDPulse && !(--TxLEDPulse))
- TX_LED_OFF();
+ TXLED0;
if (RxLEDPulse && !(--RxLEDPulse))
- RX_LED_OFF();
+ RXLED0;
+
+ if (!_ejected)
+ _timeout = 0;
}
}
-// VBUS or counting frames
-// Any frame counting?
-u8 USBConnected()
-{
- u8 f = UDFNUML;
-// delay(3);
- _delay_ms(3);
- return f != UDFNUML;
-}
-
-//=======================================================================
-//=======================================================================
-
-USB_ USB;
-
-USB_::USB_()
+void LEDPulse();
+int USBGetChar()
{
-}
-
-void USB_::attach()
-{
- _usbConfiguration = 0;
- UHWCON = 0x01; // power internal reg
- USBCON = (1<<USBE)|(1<<FRZCLK); // clock frozen, usb enabled
- PLLCSR = 0x12; // Need 16 MHz xtal
- while (!(PLLCSR & (1<<PLOCK))) // wait for lock pll
- ;
- USBCON = ((1<<USBE)|(1<<OTGPADE)); // start USB clock
- UDIEN = (1<<EORSTE)|(1<<SOFE); // Enable interrupts for EOR (End of Reset) and SOF (start of frame)
- UDCON = 0; // enable attach resistor
-}
-
-void USB_::detach()
-{
-}
-
-// Check for interrupts
-// TODO: VBUS detection
-bool USB_::configured()
-{
- return _usbConfiguration;
-}
+ for(;;)
+ {
+ USBSetupInterrupt();
+ USBGeneralInterrupt();
-void USB_::poll()
-{
+ // Read a char
+ if (HasData(CDC_RX))
+ {
+ u8 c = Recv8();
+ if (!ReadWriteAllowed())
+ ReleaseRX();
+ return c;
+ }
+
+ if (!--_timeout) {
+ Reboot(); // USB not connected, run firmware
+ }
+
+ _delay_us(100); // stretch out the bootloader period to about 5 seconds after enumeration
+ LEDPulse();
+ }
+ return -1;
}
-
-#endif /* if defined(USBCON) */
diff --git a/arduino/bootloaders/diskloader/src/USBCore.h b/arduino/bootloaders/diskloader/src/USBCore.h
index 511b57c..537c0ec 100644
--- a/arduino/bootloaders/diskloader/src/USBCore.h
+++ b/arduino/bootloaders/diskloader/src/USBCore.h
@@ -18,42 +18,29 @@
#ifndef __USBCORE_H__
#define __USBCORE_H__
-// Standard requests
#define GET_STATUS 0
#define CLEAR_FEATURE 1
#define SET_FEATURE 3
#define SET_ADDRESS 5
#define GET_DESCRIPTOR 6
-#define SET_DESCRIPTOR 7
#define GET_CONFIGURATION 8
#define SET_CONFIGURATION 9
#define GET_INTERFACE 10
#define SET_INTERFACE 11
-
// bmRequestType
-#define REQUEST_HOSTTODEVICE 0x00
-#define REQUEST_DEVICETOHOST 0x80
-#define REQUEST_DIRECTION 0x80
-
-#define REQUEST_STANDARD 0x00
-#define REQUEST_CLASS 0x20
-#define REQUEST_VENDOR 0x40
-#define REQUEST_TYPE 0x60
-
-#define REQUEST_DEVICE 0x00
-#define REQUEST_INTERFACE 0x01
-#define REQUEST_ENDPOINT 0x02
-#define REQUEST_OTHER 0x03
-#define REQUEST_RECIPIENT 0x03
-
-#define REQUEST_DEVICETOHOST_CLASS_INTERFACE (REQUEST_DEVICETOHOST + REQUEST_CLASS + REQUEST_INTERFACE)
-#define REQUEST_HOSTTODEVICE_CLASS_INTERFACE (REQUEST_HOSTTODEVICE + REQUEST_CLASS + REQUEST_INTERFACE)
-
-// Class requests
-
-#define CDC_SET_LINE_CODING 0x20
-#define CDC_GET_LINE_CODING 0x21
+#define HOSTTODEVICE 0x00
+#define DEVICETOHOST 0x80
+#define STANDARD 0x00
+#define CLASS 0x20
+#define VENDOR 0x40
+#define DEVICE 0x00
+#define INTERFACE 0x01
+#define ENDPOINT 0x02
+#define OTHER 0x03
+
+#define CDC_SET_LINE_CODING 0x20
+#define CDC_GET_LINE_CODING 0x21
#define CDC_SET_CONTROL_LINE_STATE 0x22
// Descriptors
@@ -107,6 +94,7 @@
#define CDC_CS_ENDPOINT 0x25
#define CDC_DATA_INTERFACE_CLASS 0x0A
+
// Device
typedef struct {
u8 len; // 18
@@ -198,32 +186,14 @@ typedef struct
typedef struct
{
- u8 len;
- u8 dtype; // 0x24
- u8 subtype; // 1
- u8 bmCapabilities;
- u8 bDataInterface;
-} CMFunctionalDescriptor;
-
-typedef struct
-{
- u8 len;
- u8 dtype; // 0x24
- u8 subtype; // 1
- u8 bmCapabilities;
-} ACMFunctionalDescriptor;
-
-typedef struct
-{
- // IAD
IADDescriptor iad; // Only needed on compound device
// Control
InterfaceDescriptor cif; //
CDCCSInterfaceDescriptor header;
- CMFunctionalDescriptor callManagement; // Call Management
- ACMFunctionalDescriptor controlManagement; // ACM
- CDCCSInterfaceDescriptor functionalDescriptor; // CDC_UNION
+ CDCCSInterfaceDescriptor callManagement;
+ CDCCSInterfaceDescriptor4 controlManagement;
+ CDCCSInterfaceDescriptor functionalDescriptor;
EndpointDescriptor cifin;
// Data
@@ -232,11 +202,31 @@ typedef struct
EndpointDescriptor out;
} CDCDescriptor;
+typedef struct
+{
+ u8 len; // 9
+ u8 dtype; // 0x21
+ u8 addr;
+ u8 versionL; // 0x101
+ u8 versionH; // 0x101
+ u8 country;
+ u8 desctype; // 0x22 report
+ u8 descLenL;
+ u8 descLenH;
+} HIDDescDescriptor;
+
+typedef struct
+{
+ InterfaceDescriptor hid;
+ HIDDescDescriptor desc;
+ EndpointDescriptor in;
+} HIDDescriptor;
+
#define D_DEVICE(_class,_subClass,_proto,_packetSize0,_vid,_pid,_version,_im,_ip,_is,_configs) \
{ 18, 1, 0x200, _class,_subClass,_proto,_packetSize0,_vid,_pid,_version,_im,_ip,_is,_configs }
#define D_CONFIG(_totalLength,_interfaces) \
- { 9, 2, _totalLength,_interfaces, 1, 0, USB_CONFIG_BUS_POWERED, USB_CONFIG_POWER_MA(500) }
+ { 9, 2, _totalLength,_interfaces, 1, 0, USB_CONFIG_BUS_POWERED, USB_CONFIG_POWER_MA(100) }
#define D_INTERFACE(_n,_numEndpoints,_class,_subClass,_protocol) \
{ 9, 4, _n, 0, _numEndpoints, _class,_subClass, _protocol, 0 }
@@ -247,8 +237,10 @@ typedef struct
#define D_IAD(_firstInterface, _count, _class, _subClass, _protocol) \
{ 8, 11, _firstInterface, _count, _class, _subClass, _protocol, 0 }
+#define D_HIDREPORT(_descriptorLength) \
+ { 9, 0x21, 0x1, 0x1, 0, 1, 0x22, _descriptorLength, 0 }
+
#define D_CDCCS(_subtype,_d0,_d1) { 5, 0x24, _subtype, _d0, _d1 }
#define D_CDCCS4(_subtype,_d0) { 4, 0x24, _subtype, _d0 }
-
#endif
\ No newline at end of file
diff --git a/arduino/bootloaders/diskloader/src/USBDesc.cpp b/arduino/bootloaders/diskloader/src/USBDesc.cpp
new file mode 100644
index 0000000..c8ea9c6
--- /dev/null
+++ b/arduino/bootloaders/diskloader/src/USBDesc.cpp
@@ -0,0 +1,82 @@
+
+
+/* Copyright (c) 2011, Peter Barrett
+**
+** Permission to use, copy, modify, and/or distribute this software for
+** any purpose with or without fee is hereby granted, provided that the
+** above copyright notice and this permission notice appear in all copies.
+**
+** THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
+** WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
+** WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR
+** BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES
+** OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+** WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+** ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+** SOFTWARE.
+*/
+
+#include "Platform.h"
+
+//====================================================================================================
+//====================================================================================================
+// Actual device descriptors
+
+const u16 STRING_LANGUAGE[2] = {
+ (3<<8) | (2+2),
+ 0x0409 // English
+};
+
+
+const u16 STRING_IPRODUCT[28] = {
+ (3<<8) | (2+2*27),
+#if USB_PID == USB_PID_LEONARDO
+ 'A','r','d','u','i','n','o',' ','L','e','o','n','a','r','d','o',' ','b','o','o','t','l','o','a','d','e','r'
+#elif USB_PID == USB_PID_MICRO
+ 'A','r','d','u','i','n','o',' ','M','i','c','r','o',' ','b','o','o','t','l','o','a','d','e','r',' ',' ',' '
+#endif
+};
+
+const u16 STRING_IMANUFACTURER[12] = {
+ (3<<8) | (2+2*11),
+ 'A','r','d','u','i','n','o',' ','L','L','C'
+};
+
+
+//#ifdef CDC_ENABLED
+DeviceDescriptor USB_DeviceDescriptorA = D_DEVICE(0X02,0X00,0X00,64,USB_VID,USB_PID,0x100,IMANUFACTURER,IPRODUCT,0,1);
+//#else
+DeviceDescriptor USB_DeviceDescriptor = D_DEVICE(0x00,0x00,0x00,64,USB_VID,USB_PID,0x100,IMANUFACTURER,IPRODUCT,0,1);
+//#endif
+
+Config USB_ConfigDescriptor =
+{
+ D_CONFIG(sizeof(Config),INTERFACE_COUNT),
+
+#ifdef CDC_ENABLED
+ // CDC
+ {
+ D_IAD(0,2,CDC_COMMUNICATION_INTERFACE_CLASS,CDC_ABSTRACT_CONTROL_MODEL,1),
+
+ // CDC communication interface
+ D_INTERFACE(CDC_ACM_INTERFACE,1,CDC_COMMUNICATION_INTERFACE_CLASS,CDC_ABSTRACT_CONTROL_MODEL,0),
+ D_CDCCS(CDC_HEADER,0x10,0x01), // Header (1.10 bcd)
+ D_CDCCS(CDC_CALL_MANAGEMENT,1,1), // Device handles call management
+ D_CDCCS4(CDC_ABSTRACT_CONTROL_MANAGEMENT,2), // SET_LINE_CODING, GET_LINE_CODING, SET_CONTROL_LINE_STATE supported
+ D_CDCCS(CDC_UNION,CDC_ACM_INTERFACE,CDC_DATA_INTERFACE), // Communication interface is master, data interface is slave 0
+ D_ENDPOINT(USB_ENDPOINT_IN (CDC_ENDPOINT_ACM),USB_ENDPOINT_TYPE_INTERRUPT,0x10,0x40),
+
+ // CDC data interface
+ D_INTERFACE(CDC_DATA_INTERFACE,2,CDC_DATA_INTERFACE_CLASS,0,0),
+ D_ENDPOINT(USB_ENDPOINT_OUT(CDC_ENDPOINT_OUT),USB_ENDPOINT_TYPE_BULK,0x40,0),
+ D_ENDPOINT(USB_ENDPOINT_IN (CDC_ENDPOINT_IN ),USB_ENDPOINT_TYPE_BULK,0x40,0)
+ },
+#endif
+ // HID
+ {
+ D_INTERFACE(HID_INTERFACE,1,3,0,0),
+ D_HIDREPORT(30),
+ D_ENDPOINT(USB_ENDPOINT_IN (HID_ENDPOINT_INT),USB_ENDPOINT_TYPE_INTERRUPT,0x40,0x40)
+ }
+};
+
diff --git a/arduino/bootloaders/diskloader/src/USBDesc.h b/arduino/bootloaders/diskloader/src/USBDesc.h
index 588a40c..094dba5 100644
--- a/arduino/bootloaders/diskloader/src/USBDesc.h
+++ b/arduino/bootloaders/diskloader/src/USBDesc.h
@@ -16,19 +16,48 @@
** SOFTWARE.
*/
-#define CDC_INTERFACE_COUNT 2
-#define CDC_ENPOINT_COUNT 3
+
+#ifdef CDC_ENABLED
#define CDC_ACM_INTERFACE 0 // CDC ACM
#define CDC_DATA_INTERFACE 1 // CDC Data
-#define CDC_FIRST_ENDPOINT 1
-#define CDC_ENDPOINT_ACM (CDC_FIRST_ENDPOINT) // CDC First
-#define CDC_ENDPOINT_OUT (CDC_FIRST_ENDPOINT+1)
-#define CDC_ENDPOINT_IN (CDC_FIRST_ENDPOINT+2)
+#define CDC_ENDPOINT_ACM 1
+#define CDC_ENDPOINT_OUT 2
+#define CDC_ENDPOINT_IN 3
-#define CDC_RX CDC_ENDPOINT_OUT
-#define CDC_TX CDC_ENDPOINT_IN
+#define HID_INTERFACE 2 // HID Interface
+#define HID_ENDPOINT_INT 4
+
+#define INTERFACE_COUNT 3 // 2 for cdc + 1 for hid
+
+#else
+
+#define HID_INTERFACE 2 // HID Interface
+#define HID_ENDPOINT_INT 4
+
+#define INTERFACE_COUNT 1 // 1 for hid
+
+#endif
+
+typedef struct
+{
+ ConfigDescriptor config;
+#ifdef CDC_ENABLED
+ CDCDescriptor cdc;
+#endif
+ HIDDescriptor hid;
+} Config;
+
+extern Config USB_ConfigDescriptor PROGMEM;
+extern DeviceDescriptor USB_DeviceDescriptor PROGMEM;
+extern DeviceDescriptor USB_DeviceDescriptorA PROGMEM;
+
+extern const u16 STRING_LANGUAGE[2] PROGMEM;
+extern const u16 STRING_IPRODUCT[28] PROGMEM;
+extern const u16 STRING_IMANUFACTURER[12] PROGMEM;
#define IMANUFACTURER 1
#define IPRODUCT 2
+#define CDC_TX CDC_ENDPOINT_IN
+#define CDC_RX CDC_ENDPOINT_OUT
\ No newline at end of file
diff --git a/arduino/cores/arduino/CDC.cpp b/arduino/cores/arduino/CDC.cpp
index b8df09f..14a0eae 100644
--- a/arduino/cores/arduino/CDC.cpp
+++ b/arduino/cores/arduino/CDC.cpp
@@ -27,7 +27,7 @@ void Reboot()
{
USB.detach();
cli();
- asm volatile("jmp 0x7000"); // jump to bootloader - DiskLoader lives in the last 4kB of Flash
+ asm volatile("jmp 0x7800"); // jump to bootloader - DiskLoader takes up last 2 kB
}
typedef struct
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]