Skip to content

15 files changed

+2573
-0
lines changed
 

‎.gitignore

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
AvrBuild.bat
2+
*.a
3+
*.acy
4+
*.atsuo
5+
*.avrsuo
6+
*.aws
7+
*.cfg
8+
*.d
9+
*.dep
10+
*.depend
11+
*.i
12+
*.layout
13+
*.log
14+
*.lss
15+
*.lst
16+
*.map
17+
*.mk
18+
*.o
19+
*.obj
20+
*.srec
21+
*.suo
22+
*.sym
23+
*.tmp
24+
*.xml
25+
*.xslt
26+
27+
# AVR programming files
28+
29+
# *.eep
30+
# *.elf
31+
# *.hex

‎1-Wire.png

18.3 KB
Loading

‎AVRootIntf.pas

+175
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
unit AVRootIntf;
2+
3+
interface
4+
5+
uses Windows, Classes;
6+
7+
const
8+
// IApplication.Output() Code
9+
ocInfo = $10000000;
10+
ocError = $11000000;
11+
ocOthers = $12000000;
12+
// RetCode Flags
13+
msCrypt = $01;
14+
msCryptFlash = $02;
15+
msCryptEeprom = $04;
16+
msVersioning = $08;
17+
// Return Codes of AVR Bootloader Software
18+
SUCCESS = $30;
19+
ERRORVERIFY = $C0;
20+
ERRORCOMMAND = $C1;
21+
ERRORCRC = $C2;
22+
ERRORBOUNDS = $C3;
23+
ERRORCRYPT = $C4;
24+
ERRORPROG = $C5;
25+
ERRORVERSION = $C6;
26+
ERRORUNKNOWN = $CF;
27+
28+
RETMASK = $F0;
29+
30+
// IDevice.Support Flags
31+
sfCrypt = $0001; // Cryptography supported
32+
sfCryptFlash = $0002; // FLASH Write must be encrypted, unencrypted FLASH write not supported
33+
sfCryptEeprom = $0004; // EEPROM Write must be encrypted, unencrypted EEPROM write not supported
34+
sfVersioning = $0008; // Versioning supported
35+
sfReadEeprom = $0100; // command EEPROM Read supported, examined at runtime
36+
sfWriteEeprom = $0200; // command EEPROM Write supported, examined at runtime
37+
sfReadRam = $0400; // command RAM Read supported, examined at runtime
38+
sfVerifyFlash = $0800; // command Verify FLASH supported, examined at runtime
39+
40+
type
41+
// RS232 encapsulation of windows COM port
42+
TCRCFlag = (crcReset, crcSend);
43+
TCRCFlags = set of TCRCFlag;
44+
45+
ICOM = interface
46+
procedure Flush; stdcall;
47+
procedure Purge; stdcall;
48+
49+
procedure SetTimeout(Value: Cardinal; const ProcName: WideString = ''); stdcall;
50+
procedure SetParams(Baudrate: Cardinal; Parity: Byte = NOPARITY; Databits: Byte = 8; Stopbits: Byte = ONESTOPBIT; const ProcName: WideString = ''); stdcall;
51+
procedure SetEchoMode(Value: Bool); stdcall;
52+
function EchoMode: Bool; stdcall;
53+
54+
procedure SetDTR(Value: Bool); stdcall;
55+
procedure SetRTS(Value: Bool); stdcall;
56+
procedure WriteData(Buffer: Pointer; Size: Integer; Flags: TCRCFlags = []; const ProcName: WideString = ''); stdcall;
57+
procedure WriteByte(Value: Byte; Flags: TCRCFlags = []; const ProcName: WideString = ''); stdcall;
58+
procedure WriteChar(Value: Char; Flags: TCRCFlags = []; const ProcName: WideString = ''); stdcall;
59+
procedure WriteWord(Value: Word; Flags: TCRCFlags = []; const ProcName: WideString = ''); stdcall;
60+
procedure WriteLong(Value: Cardinal; Flags: TCRCFlags = []; const ProcName: WideString = ''); stdcall;
61+
procedure WriteCRC(const ProcName: WideString = ''); stdcall;
62+
procedure ResetCRC; stdcall;
63+
64+
procedure ReadData(Buffer: Pointer; Size: Integer; Flags: TCRCFlags = []; const ProcName: WideString = ''); stdcall;
65+
function ReadByte(Flags: TCRCFlags = []; const ProcName: WideString = ''): Byte; stdcall;
66+
function ReadChar(Flags: TCRCFlags = []; const ProcName: WideString = ''): Char; stdcall;
67+
function ReadWord(Flags: TCRCFlags = []; const ProcName: WideString = ''): Word; stdcall;
68+
function ReadLong(Flags: TCRCFlags = []; const ProcName: WideString = ''): Cardinal; stdcall;
69+
function ReadCRC(const ProcName: WideString = ''): Bool; stdcall;
70+
end;
71+
72+
// Timeout Record for IApplication
73+
TTimeouts = packed record
74+
Baudrate: Integer;
75+
Connect: Integer;
76+
Base: Integer;
77+
Erase: Integer;
78+
Flash: Integer;
79+
Eeprom: Integer;
80+
Buffer: Integer;
81+
AppCmd: Integer;
82+
KeepAlive: Integer;
83+
RTSPulse: Integer;
84+
RTSInterval: Integer;
85+
ConnectTrials: Integer;
86+
MaxPacketSize: Integer;
87+
Options: Integer;
88+
end;
89+
90+
// Application Callback Interface, must be provided to OpenAVRootloader()
91+
IApplication = interface
92+
['{62DEB67D-8AB2-476E-9CB6-F582A508B1F7}']
93+
function ProcessMessages: Bool; stdcall;
94+
procedure Changed; stdcall;
95+
procedure Output(const Msg: WideString; Code: Integer); stdcall;
96+
97+
function GetFLASHFileName: WideString; stdcall;
98+
function GetEEPROMFileName: WideString; stdcall;
99+
function GetACYFileName: WideString; stdcall;
100+
function GetPassword: WideString; stdcall;
101+
function GetBootSign: WideString; stdcall;
102+
function GetTimeouts: TTimeouts; stdcall;
103+
function GetAppCmd: WideString; stdcall;
104+
function GetAppCmdResponse: WideString; stdcall;
105+
function GetAppVersion(Masked: Bool = False): Integer; stdcall;
106+
function GetACYInfo: WideString; stdcall;
107+
108+
function OpenCommunication(Index: Integer): ICOM; stdcall;
109+
end;
110+
111+
// individual Commands to send to AVR Bootloader software, part of IAVRootloader
112+
ICommandSet = interface
113+
['{E9C64A3F-306C-4694-B250-FC57D2CB2DEB}']
114+
function SetAddr(Address: Integer): Bool; stdcall;
115+
function SetBuffer(Buffer: Pointer; Size: Integer; Code: Byte = 0): Bool; stdcall;
116+
function Run(Code: Byte = 1): Bool; stdcall;
117+
function EraseFlash(Pages: Byte = 1): Bool; stdcall;
118+
function VerifyFlash(Pages: Byte = 1): Bool; stdcall;
119+
function WriteFlash(Pages: Byte = 1): Bool; stdcall;
120+
function WriteEeprom(Size: Integer; Pages: Byte = 1): Bool; stdcall;
121+
function ReadEeprom(Buffer: Pointer; Size: Integer; Address: Integer = 0): Bool; stdcall;
122+
function ReadRam(Buffer: Pointer; Size: Integer; Address: Integer = 0): Bool; stdcall;
123+
end;
124+
125+
// connected Device Information, part of IAVRootloader
126+
IDevice = interface
127+
['{9EC8A92B-F6BB-47F3-A9C9-DF8F4F481F49}']
128+
function Signature: Integer; stdcall;
129+
function Name: WideString; stdcall;
130+
function Info: WideString; stdcall;
131+
function FlashSize: Integer; stdcall;
132+
function AppFlashSize: Integer; stdcall;
133+
function AppVersion: Integer; stdcall;
134+
function AppVersionString: WideString; stdcall;
135+
function EepromSize: Integer; stdcall;
136+
function RamSize: Integer; stdcall;
137+
function RamStartAddress: Integer; stdcall;
138+
function PageSize: Integer; stdcall;
139+
function BufferSize: Integer; stdcall;
140+
function Version: Integer; stdcall;
141+
function UseBootSection: Bool; stdcall;
142+
function RetCode: Byte; stdcall;
143+
function Support: Integer; stdcall;
144+
function XMLFileName: WideString; stdcall;
145+
end;
146+
147+
TMode = (moDisconnected, moConnecting, moConnected, moWorking, moTimer, moAbort);
148+
149+
// Bootloader Interface
150+
IAVRootloader = interface
151+
['{3A2E99C2-CE9E-407B-8943-A6D5EB1F6B7A}']
152+
function Mode: TMode; stdcall;
153+
154+
function DoConnect(Working: Bool = False): Bool; stdcall;
155+
procedure DoDisconnect; stdcall;
156+
procedure DoAbort; stdcall;
157+
158+
function DoProgram(EraseFlash: Bool; VerifyFlash: Bool): Bool; stdcall;
159+
function DoCompile(EraseFlash: Bool; VerifyFlash: Bool): Bool; stdcall;
160+
function DoVerifyFlash: Bool; stdcall;
161+
function DoEraseFlash: Bool; stdcall;
162+
function DoEraseEeprom: Bool; stdcall;
163+
164+
function COM: ICOM; stdcall;
165+
function Device: IDevice; stdcall;
166+
function Command: ICommandSet; stdcall;
167+
end;
168+
169+
170+
function OpenCOM(const Port: WideString; const Application: IApplication): ICOM; stdcall; external 'AVRootloader.dll';
171+
function OpenAVRootloader(const Application: IApplication): IAVRootloader; stdcall; external 'AVRootloader.dll';
172+
173+
implementation
174+
175+
end.

‎AVRootloader.aps

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<AVRStudio><MANAGEMENT><Created>06-Mar-2008 17:30:47</Created><LastEdit>22-Apr-2009 19:16:07</LastEdit><ProjectType>0</ProjectType><Created>06-Mar-2008 17:30:47</Created><Version>4</Version><Build>4, 13, 0, 528</Build><ProjectTypeName>Atmel AVR Assembler</ProjectTypeName><ICON>208</ICON><ProjectName>AVRootloader</ProjectName><Created>14-Mar-2008 23:47:09</Created><LastEdit>14-Mar-2008 23:47:09</LastEdit><ICON>208</ICON><ProjectType>0</ProjectType><Created>14-Mar-2008 23:47:09</Created><Version>4</Version><Build>4, 13, 0, 528</Build><ProjectTypeName>Atmel AVR Assembler</ProjectTypeName></MANAGEMENT><CODE_CREATION><ObjectFile>AVRootloader.obj</ObjectFile><EntryFile>C:\Programme\Atmel\AVRootloader\AVR\AVRootloader.asm</EntryFile><ObjectFile></ObjectFile><EntryFile></EntryFile><SaveFolder>C:\Programme\Atmel\AVRootloader\AVR\</SaveFolder></CODE_CREATION><DEBUG_TARGET><CURRENT_PART>ATmega162</CURRENT_PART><BREAKPOINTS></BREAKPOINTS><IO_EXPAND><HIDE>false</HIDE></IO_EXPAND><REGISTERNAMES><Register>R00</Register><Register>R01</Register><Register>R02</Register><Register>R03</Register><Register>R04</Register><Register>R05</Register><Register>R06</Register><Register>R07</Register><Register>R08</Register><Register>R09</Register><Register>R10</Register><Register>R11</Register><Register>R12</Register><Register>R13</Register><Register>R14</Register><Register>R15</Register><Register>R16</Register><Register>R17</Register><Register>R18</Register><Register>R19</Register><Register>R20</Register><Register>R21</Register><Register>R22</Register><Register>R23</Register><Register>R24</Register><Register>R25</Register><Register>R26</Register><Register>R27</Register><Register>R28</Register><Register>R29</Register><Register>R30</Register><Register>R31</Register></REGISTERNAMES><CURRENT_TARGET>JTAGICE mkII</CURRENT_TARGET><CURRENT_TARGET>AVR Simulator</CURRENT_TARGET><CURRENT_PART>ATmega162.xml</CURRENT_PART><BREAKPOINTS></BREAKPOINTS><IO_EXPAND></IO_EXPAND><REGISTERNAMES></REGISTERNAMES><COM>COM8</COM><COMType>1</COMType><WATCHNUM>0</WATCHNUM><WATCHNAMES><Pane0><Variables>zx</Variables></Pane0><Pane1></Pane1><Pane2></Pane2><Pane3></Pane3></WATCHNAMES><BreakOnTrcaeFull>0</BreakOnTrcaeFull></DEBUG_TARGET><Debugger><modules><module></module></modules><Triggers></Triggers></Debugger><AvrAssembler><Folder>C:\Programme\Atmel\AVRootloader\AVR\</Folder><RelPath>AVRootloader.asm</RelPath><EntryFile>C:\Programme\Atmel\AVRootloader\AVR\AVRootloader.asm</EntryFile><IncludePath>C:\Programme\Atmel\AVR Tools\AvrAssembler\AppNotes</IncludePath><V2IncludePath></V2IncludePath><V2Parameters></V2Parameters><FileType>I</FileType><ObjectName>AVRootloader</ObjectName><Wrap>1</Wrap><ErrorAsWarning>0</ErrorAsWarning><MapFile>1</MapFile><ListFile>1</ListFile><Version1>0</Version1><PreCompile></PreCompile><PostCompile></PostCompile><SourceFiles>,</SourceFiles></AvrAssembler><JTAG_ICE><BAUDRATE>19200</BAUDRATE><OCD_FREQUENCY>250000</OCD_FREQUENCY><PRESERVE_EEPROM>0</PRESERVE_EEPROM><RUN_TIMERS>0</RUN_TIMERS><REPROGRAM>0</REPROGRAM><EXT_RESET>0</EXT_RESET><RESTORE>1</RESTORE><DAISY_CHAIN>0</DAISY_CHAIN><DEVS_BEFORE>0</DEVS_BEFORE><DEVS_AFTER>0</DEVS_AFTER><INSTRBITS_BEFORE>0</INSTRBITS_BEFORE><INSTRBITS_AFTER>0</INSTRBITS_AFTER><NOJTAGIN_RUNMODE>0</NOJTAGIN_RUNMODE><BREAKON_CHANGEOFFLOW>0</BREAKON_CHANGEOFFLOW><ALLOW_BREAKINSTR>0</ALLOW_BREAKINSTR><PRINT_BREAKCAUSE>1</PRINT_BREAKCAUSE><ENTRY_FUNCTION>main</ENTRY_FUNCTION><STOPIF_ENTRYFUNC_NOTFOUND>1</STOPIF_ENTRYFUNC_NOTFOUND><PRINT_BREAKWARNING>1</PRINT_BREAKWARNING><CURRENT_BUILDTIME>39531.6</CURRENT_BUILDTIME></JTAG_ICE><JTAGICEmkII><DAISY_CHAIN>0</DAISY_CHAIN><DEVS_BEFORE>0</DEVS_BEFORE><DEVS_AFTER>0</DEVS_AFTER><INSTRBITS_BEFORE>0</INSTRBITS_BEFORE><INSTRBITS_AFTER>0</INSTRBITS_AFTER><BAUDRATE>115200</BAUDRATE><JTAG_FREQ>1000000</JTAG_FREQ><TIMERS_RUNNING>0</TIMERS_RUNNING><PRESERVE_EEPROM>0</PRESERVE_EEPROM><ALWAYS_EXT_RESET>0</ALWAYS_EXT_RESET><PRINT_BRK_CAUSE>0</PRINT_BRK_CAUSE><ENABLE_IDR_IN_RUN_MODE>0</ENABLE_IDR_IN_RUN_MODE><STOPIF_ENTRYFUNC_NOTFOUND>1</STOPIF_ENTRYFUNC_NOTFOUND><ENTRY_FUNCTION>main</ENTRY_FUNCTION><REPROGRAM>1</REPROGRAM></JTAGICEmkII><ProjectIncludeDirs><Dirs><Dir>C:\Programme\Atmel\AVR Tools\AvrAssembler2\Appnotes</Dir></Dirs></ProjectIncludeDirs><ProjectFiles><Files><Name>\AVRootloader.asm</Name><Name>C:\Programme\Atmel\AVR Tools\AvrAssembler2\Appnotes\m162def.inc</Name><Name>\AVRootloader.inc</Name><Name>\Special.inc</Name></Files></ProjectFiles><IOView><usergroups/><sort sorted="0" column="0" ordername="1" orderaddress="1" ordergroup="1"/></IOView><Files><File00000><FileId>00000</FileId><FileName>AVRootloader.asm</FileName><Status>257</Status></File00000><File00001><FileId>00001</FileId><FileName>AVRootloader.lst</FileName><Status>1</Status></File00001></Files><Events><Bookmarks></Bookmarks></Events><Trace><Filters></Filters></Trace></AVRStudio>

‎AVRootloader.asm

+804
Large diffs are not rendered by default.

‎AVRootloader.dev

+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
ID =Sign. , Devicename , Flash, E2P, SRAM, Ofs,Page,BZ1,BZ2,BZ3,BZ4
2+
9007=1E9007, ATtiny13 , 1024, 64, 64, 96, 32, 0, 0, 0, 0
3+
9007=1E9007, ATtiny13A , 1024, 64, 64, 96, 32, 0, 0, 0, 0
4+
9108=1E9108, ATtiny25 , 2048, 128, 128, 96, 32, 0, 0, 0, 0
5+
910A=1E910A, ATtiny2313 , 2048, 128, 128, 96, 32, 0, 0, 0, 0
6+
910B=1E910B, ATtiny24 , 2048, 128, 128, 96, 32, 0, 0, 0, 0
7+
910B=1E910B, ATtiny24A , 2048, 128, 128, 96, 32, 0, 0, 0, 0
8+
910C=1E910C, ATtiny261 , 2048, 128, 128, 96, 32, 0, 0, 0, 0
9+
9205=1E9205, ATmega48 , 4096, 256, 512, 256, 64, 0, 0, 0, 0
10+
9206=1E9206, ATtiny45 , 4096, 256, 256, 96, 64, 0, 0, 0, 0
11+
9207=1E9207, ATtiny44 , 4096, 256, 256, 96, 64, 0, 0, 0, 0
12+
9207=1E9207, ATtiny44A , 4096, 256, 256, 96, 64, 0, 0, 0, 0
13+
9208=1E9208, ATtiny461 , 4096, 256, 256, 96, 64, 0, 0, 0, 0
14+
9209=1E9209, ATtiny48 , 4096, 64, 256, 256, 64, 0, 0, 0, 0
15+
920A=1E920A, ATmega48P , 4096, 256, 512, 256, 64, 0, 0, 0, 0
16+
920A=1E920A, ATmega48P , 4096, 256, 512, 256, 64, 0, 0, 0, 0
17+
920A=1E920A, ATmega48PA , 4096, 256, 512, 256, 64, 0, 0, 0, 0
18+
920C=1E920C, ATtiny43U , 4096, 64, 256, 96, 32, 0, 0, 0, 0
19+
9301=1E9301, AT90S8515comp, 8192, 512, 512, 96, 64, 4, 8, 16, 32
20+
9303=1E9303, AT90S8535comp, 8192, 512, 512, 96, 64, 2, 4, 8, 16
21+
9306=1E9306, ATmega8515 , 8192, 512, 512, 96, 64, 4, 8, 16, 32
22+
9307=1E9307, ATmega8 , 8192, 512, 1024, 96, 64, 4, 8, 16, 32
23+
9307=1E9307, ATmega8A , 8192, 512, 1024, 96, 64, 4, 8, 16, 32
24+
9308=1E9308, ATmega8535 , 8192, 512, 512, 96, 64, 2, 4, 8, 16
25+
930A=1E930A, ATmega88 , 8192, 512, 1024, 256, 64, 4, 8, 16, 32
26+
930B=1E930B, ATtiny85 , 8192, 512, 512, 96, 64, 0, 0, 0, 0
27+
930C=1E930C, ATtiny84 , 8192, 512, 512, 96, 64, 0, 0, 0, 0
28+
930D=1E930D, ATtiny861 , 8192, 512, 512, 96, 64, 0, 0, 0, 0
29+
930F=1E930F, ATmega88P , 8192, 512, 1024, 256, 64, 4, 8, 16, 32
30+
930F=1E930F, ATmega88PA , 8192, 512, 1024, 256, 64, 4, 8, 16, 32
31+
9310=1E9310, ATmega8HVA , 8192, 256, 512, 256, 128, 0, 0, 0, 0
32+
9311=1E9311, ATtiny88 , 8192, 64, 512, 256, 64, 0, 0, 0, 0
33+
9381=1E9381, AT90PWM2 , 8192, 512, 512, 256, 64, 4, 8, 16, 32
34+
9381=1E9381, AT90PWM3 , 8192, 512, 512, 256, 64, 4, 8, 16, 32
35+
9382=1E9382, AT90USB82 , 8192, 512, 512, 256, 128, 4, 8, 16, 32
36+
9383=1E9383, AT90PWM2B , 8192, 512, 512, 256, 64, 4, 8, 16, 32
37+
9383=1E9383, AT90PWM3B , 8192, 512, 512, 256, 64, 4, 8, 16, 32
38+
9387=1E9387, ATtiny87 , 8192, 512, 512, 256, 128, 0, 0, 0, 0
39+
9401=1E9401, ATmega161 , 16384, 512, 1024, 96, 128, 2, 4, 8, 16
40+
9401=1E9401, ATmega161comp, 16384, 512, 1024, 96, 128, 2, 4, 8, 16
41+
9402=1E9402, ATmega163 , 16384, 512, 1024, 96, 128, 2, 4, 8, 16
42+
9403=1E9403, ATmega16 , 16384, 512, 1024, 96, 128, 2, 4, 8, 16
43+
9403=1E9403, ATmega16A , 16384, 512, 1024, 96, 128, 2, 4, 8, 16
44+
9404=1E9404, ATmega162 , 16384, 512, 1024, 256, 128, 2, 4, 8, 16
45+
9405=1E9405, ATmega169 , 16384, 512, 1024, 256, 128, 2, 4, 8, 16
46+
9405=1E9405, ATmega169P , 16384, 512, 1024, 256, 128, 2, 4, 8, 16
47+
9406=1E9406, ATmega168 , 16384, 512, 1024, 256, 128, 2, 4, 8, 16
48+
9407=1E9407, ATmega165 , 16384, 512, 1024, 256, 128, 2, 4, 8, 16
49+
9407=1E9407, ATmega165P , 16384, 512, 1024, 256, 128, 2, 4, 8, 16
50+
940A=1E940A, ATmega164P , 16384, 512, 1024, 256, 128, 2, 4, 8, 16
51+
940B=1E940B, ATmega168P , 16384, 512, 1024, 256, 128, 2, 4, 8, 16
52+
940B=1E940B, ATmega168PA , 16384, 512, 1024, 256, 128, 2, 4, 8, 16
53+
940C=1E940C, ATmega16HVA , 16384, 256, 512, 256, 128, 0, 0, 0, 0
54+
9482=1E9482, AT90USB162 , 16384, 512, 512, 256, 128, 4, 8, 16, 32
55+
9483=1E9483, AT90PWM216 , 16384, 512, 1024, 256, 128, 4, 8, 16, 32
56+
9483=1E9483, AT90PWM316 , 16384, 512, 1024, 256, 128, 4, 8, 16, 32
57+
9484=1E9484, ATmega16M1 , 16384, 512, 1024, 256, 128, 4, 8, 16, 32
58+
9487=1E9487, ATtiny167 , 16384, 512, 512, 256, 128, 0, 0, 0, 0
59+
9488=1E9488, ATmega16U4 , 16384, 512, 1280, 256, 128, 4, 8, 16, 32
60+
9489=1E9489, ATmega16U2 , 16384, 512, 512, 256, 128, 4, 8, 16, 32
61+
9501=1E9501, ATmega323 , 32768, 1024, 2048, 96, 128, 4, 8, 16, 32
62+
9502=1E9502, ATmega32 , 32768, 1024, 2048, 96, 128, 4, 8, 16, 32
63+
9502=1E9502, ATmega32A , 32768, 1024, 2048, 96, 128, 4, 8, 16, 32
64+
9503=1E9503, ATmega329 , 32768, 1024, 2048, 256, 128, 4, 8, 16, 32
65+
9503=1E9503, ATmega329P , 32768, 1024, 2048, 256, 128, 4, 8, 16, 32
66+
9504=1E9504, ATmega3290 , 32768, 1024, 2048, 256, 128, 4, 8, 16, 32
67+
9505=1E9505, ATmega325 , 32768, 1024, 2048, 256, 128, 4, 8, 16, 32
68+
9506=1E9506, ATmega3250 , 32768, 1024, 2048, 256, 128, 4, 8, 16, 32
69+
9507=1E9507, ATmega406 , 40960, 512, 2048, 256, 128, 4, 8, 16, 32
70+
9508=1E9508, ATmega324P , 32768, 1024, 2048, 256, 128, 4, 8, 16, 32
71+
950C=1E950C, ATmega3290P , 32768, 1024, 2048, 256, 128, 4, 8, 16, 32
72+
950D=1E950D, ATmega325P , 32768, 1024, 2048, 256, 128, 4, 8, 16, 32
73+
950E=1E950E, ATmega3250P , 32768, 1024, 2048, 256, 128, 4, 8, 16, 32
74+
950F=1E950F, ATmega328P , 32768, 1024, 2048, 256, 128, 4, 8, 16, 32
75+
9510=1E9510, ATmega32HVB , 32768, 1024, 2048, 256, 128, 4, 8, 16, 32
76+
9511=1E9511, ATmega324PA , 32768, 1024, 2048, 256, 128, 4, 8, 16, 32
77+
956E=1E956E, ATmega3250P , 32768, 1024, 2048, 256, 128, 4, 8, 16, 32
78+
9581=1E9581, AT90CAN32 , 32768, 1024, 2048, 256, 256, 4, 8, 16, 32
79+
9584=1E9584, AT90PWM324 , 32768, 1024, 2048, 256, 128, 4, 8, 16, 32
80+
9584=1E9584, ATmega32M1 , 32768, 1024, 2048, 256, 128, 4, 8, 16, 32
81+
9586=1E9586, ATmega32C1 , 32768, 1024, 2048, 256, 128, 4, 8, 16, 32
82+
9587=1E9587, ATmega32U4 , 32768, 1024, 2560, 256, 128, 4, 8, 16, 32
83+
9588=1E9588, ATmega32U6 , 32768, 1024, 2560, 256, 128, 4, 8, 16, 32
84+
958A=1E958A, ATmega32U2 , 32768, 1024, 1024, 256, 128, 4, 8, 16, 32
85+
9602=1E9602, ATmega64 , 65536, 2048, 4096, 256, 256, 4, 8, 16, 32
86+
9602=1E9602, ATmega64A , 65536, 2048, 4096, 256, 256, 4, 8, 16, 32
87+
9603=1E9603, ATmega649 , 65536, 2048, 4096, 256, 256, 4, 8, 16, 32
88+
9604=1E9604, ATmega6490 , 65536, 2048, 4096, 256, 256, 4, 8, 16, 32
89+
9605=1E9605, ATmega645 , 65536, 2048, 4096, 256, 256, 4, 8, 16, 32
90+
9606=1E9606, ATmega6450 , 65536, 2048, 4096, 256, 256, 4, 8, 16, 32
91+
9608=1E9608, ATmega640 , 65536, 4096, 8192, 512, 256, 4, 8, 16, 32
92+
9609=1E9609, ATmega644 , 65536, 2048, 4096, 256, 256, 4, 8, 16, 32
93+
960A=1E960A, ATmega644P , 65536, 2048, 4096, 256, 256, 4, 8, 16, 32
94+
9681=1E9681, AT90CAN64 , 65536, 2048, 4096, 256, 256, 4, 8, 16, 32
95+
9682=1E9682, AT90USB646 , 65536, 2048, 4096, 256, 256, 4, 8, 16, 32
96+
9682=1E9682, AT90USB647 , 65536, 2048, 4096, 256, 256, 4, 8, 16, 32
97+
9684=1E9684, ATmega64M1 , 65536, 2048, 4096, 256, 256, 4, 8, 16, 32
98+
9686=1E9686, ATmega64C1 , 65536, 2048, 4096, 256, 256, 4, 8, 16, 32
99+
9702=1E9702, ATmega128 , 131072, 4096, 4096, 256, 256, 4, 8, 16, 32
100+
9702=1E9702, ATmega128A , 131072, 4096, 4096, 256, 256, 4, 8, 16, 32
101+
9703=1E9703, ATmega1280 , 131072, 4096, 8192, 512, 256, 4, 8, 16, 32
102+
9704=1E9704, ATmega1281 , 131072, 4096, 8192, 512, 256, 4, 8, 16, 32
103+
9705=1E9705, ATmega1284P , 131072, 4096,16384, 256, 256, 4, 8, 16, 32
104+
9781=1E9781, AT90CAN128 , 131072, 4096, 4096, 256, 256, 4, 8, 16, 32
105+
9782=1E9782, AT90USB1286 , 131072, 4096, 8192, 256, 256, 4, 8, 16, 32
106+
9782=1E9782, AT90USB1287 , 131072, 4096, 8192, 256, 256, 4, 8, 16, 32
107+
9801=1E9801, ATmega2560 , 262144, 4096, 8192, 512, 256, 4, 8, 16, 32
108+
9802=1E9802, ATmega2561 , 262144, 4096, 8192, 512, 256, 4, 8, 16, 32

‎AVRootloader.dll

367 KB
Binary file not shown.

‎AVRootloader.exe

780 KB
Binary file not shown.

‎AVRootloader.h

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#ifndef AVRootloader_H
2+
#define AVRootloader_H
3+
4+
#include <avr/io.h>
5+
#include <avr/wdt.h>
6+
#include <avr/pgmspace.h>
7+
#include "intcast.h"
8+
9+
// start bootloader with direct jump
10+
static inline void bootloader_start_jump(void) __attribute__((always_inline, noreturn));
11+
// start bootloader trough watchdog reset
12+
static inline void bootloader_start_wdt(void) __attribute__((always_inline, noreturn));
13+
// retrieve size in bytes of bootmsg
14+
static inline uint16_t bootmsg_size(void) __attribute__((always_inline));
15+
// retrieve flash address of bootmsg
16+
static inline uint32_t bootmsg_addr(void) __attribute__((always_inline));
17+
// retrieve application version number, if not supported return 0xFFFFFFFF
18+
static inline uint32_t get_appversion(void) __attribute__((always_inline));
19+
// read FLASH from address, size bytes into SRAM buffer
20+
static inline void read_flash(uint32_t address, uint16_t size, const uint8_t* buffer) __attribute__((always_inline));
21+
// write FLASH to address, size bytes from SRAM buffer, there is no limitation for alignment address and size
22+
static inline void write_flash(uint32_t address, uint16_t size, const uint8_t* buffer) __attribute__((always_inline));
23+
// write FLASH, but we can write into bootloader section if SPM is not locked by lockbi fuses
24+
static inline void write_flash_boot(uint32_t address, uint16_t size, const uint8_t* buffer) __attribute__((always_inline));
25+
// execute SPM opcode
26+
static inline void dospm(uint8_t command) __attribute__((always_inline));
27+
28+
#define GETBOOTMSG_VEC FLASHEND -9
29+
#define READFLASH_VEC FLASHEND -7
30+
#define WRITEFLASH_VEC FLASHEND -5
31+
#define DOSPM_VEC FLASHEND -3
32+
#define BOOTSTART_VEC FLASHEND -1
33+
34+
35+
void bootloader_start_jump(void) {
36+
37+
asm volatile("jmp -2");
38+
for (;;);
39+
}
40+
41+
void bootloader_start_wdt(void) {
42+
43+
wdt_reset();
44+
_WD_CONTROL_REG = (1 << WDE) | (1 << _WD_CHANGE_BIT);
45+
_WD_CONTROL_REG = (1 << WDE);
46+
for (;;);
47+
}
48+
49+
uint16_t bootmsg_size(void) {
50+
51+
uint16_t (*proc)(void) = (void*)GETBOOTMSG_VEC;
52+
return H8(proc());
53+
}
54+
55+
uint32_t bootmsg_addr(void) {
56+
57+
uint32_t (*proc)(void) = (void*)GETBOOTMSG_VEC;
58+
uint32_t res = proc();
59+
asm volatile("clr %D0" : "+&r" (res) : "r" (res));
60+
return res;
61+
}
62+
63+
uint32_t get_appversion(void) {
64+
65+
uint8_t pagecount;
66+
read_flash(bootmsg_addr() + bootmsg_size() + 3, 1, &pagecount);
67+
return pgm_read_dword((FLASHEND - 3) - SPM_PAGESIZE * pagecount);
68+
}
69+
70+
void read_flash(uint32_t address, uint16_t size, const uint8_t* buffer) {
71+
72+
void (*proc)(uint32_t address, uint16_t size, const uint8_t* buffer) = (void*)READFLASH_VEC;
73+
proc(address, size, buffer);
74+
}
75+
76+
void write_flash(uint32_t address, uint16_t size, const uint8_t* buffer) {
77+
78+
void (*proc)(uint32_t address, uint16_t size, const uint8_t* buffer) = (void*)WRITEFLASH_VEC;
79+
proc(address, size, buffer);
80+
}
81+
82+
void write_flash_boot(uint32_t address, uint16_t size, const uint8_t* buffer) {
83+
84+
void (*proc)(uint32_t address, uint16_t size, const uint8_t* buffer) = (void*)WRITEFLASH_VEC;
85+
asm volatile("ldi %D0, 0xAC" : "+&r" (address) : "r" (address)); // magic code, address |= 0xAC000000
86+
proc(address, size, buffer);
87+
}
88+
89+
void dospm(uint8_t command) {
90+
91+
void (*proc)(uint8_t command) = (void*)DOSPM_VEC;
92+
proc(command);
93+
}
94+
#endif

‎AVRootloader.inc

+390
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,390 @@
1+
; copyright HR
2+
3+
.equ RX_DDR = RX_PORT -1
4+
.equ RX_PIN = RX_PORT -2
5+
.equ TX_DDR = TX_PORT -1
6+
.equ TX_PIN = TX_PORT -2
7+
8+
.if UseRS485
9+
.equ DE_DDR = DE_PORT -1
10+
.endif
11+
12+
.if RX_PORT == TX_PORT && RX == TX
13+
.set Use1Wire = 1
14+
.else
15+
.set Use1Wire = 0
16+
.endif ; .if RX_PORT == TX_PORT && RX == TX
17+
18+
.equ UartLoop = 29 ; don't change, except timing of putc, getc are changed
19+
.equ BaudTolerance = 3
20+
21+
.if !UseAutobaud
22+
.set Baudrate = XTAL / BootBaudrate - UartLoop
23+
.endif ; .if !UseAutobaud
24+
25+
.set SUCCESS = 0x30
26+
.set ERRORVERIFY = 0xC0
27+
.set ERRORCOMMAND = 0xC1
28+
.set ERRORCRC = 0xC2
29+
.set ERRORBOUNDS = 0xC3
30+
.set ERRORCRYPT = 0xC4
31+
.set ERRORPROG = 0xC5
32+
.set ERRORVERSION = 0xC6
33+
34+
.if UseCrypt
35+
.set SUCCESS = SUCCESS | 0x01
36+
.if UseCryptFLASH
37+
.set SUCCESS = SUCCESS | 0x02
38+
.endif ; .if UseCryptFLASH
39+
.if UseCryptE2
40+
.set SUCCESS = SUCCESS | 0x04
41+
.endif ; .if UseCryptE2
42+
.endif ; .if UseCrypt
43+
.if UseVersioning
44+
.set SUCCESS = SUCCESS | 0x08
45+
.endif ; .if UseVersioning
46+
47+
.equ POLYNOM = 0xA001 ; CRC Polynom
48+
49+
.def feedl = r4 ; feedback pointer
50+
.def feedh = r5
51+
.def zx = r7 ; RAMPZ
52+
.def crcl = r8 ; CRC 16Bit
53+
.def crch = r9
54+
.def zerol = r10 ; zero
55+
.def zeroh = r11
56+
.def baudl = r12 ; baudrate
57+
.def baudh = r13
58+
.def sraml = r14 ; SRAM buffer start
59+
.def sramh = r15
60+
.def paral = r16 ; params for UART
61+
.def parah = r17
62+
.def polyl = r18 ; Polynom CRC
63+
.def polyh = r19
64+
.def cnt = r20 ; counter in UART loops
65+
.def flag = r21 ; flag for crypto
66+
.def cmdl = r22 ; commands
67+
.def cmdh = r23
68+
.def cntl = r24 ; temp/baudrate
69+
.def cnth = r25
70+
71+
.if FlashEnd > 0x7FFF
72+
.set BigMega = 1 ; ATMega with big FLASH
73+
.else
74+
.set BigMega = 0
75+
.endif ; .if FlashEnd > 0x7FFF
76+
77+
.ifdef FirstBootStart
78+
.set BLS = 1 ; Bootloader Section supported
79+
.else
80+
.set BLS = 0
81+
.endif ; .ifdef FirstBootStart
82+
83+
; calculate Bootloader start address
84+
.ifdef FirstBootStart
85+
.set FirstBoot = FirstBootStart
86+
.else
87+
.set FirstBoot = FlashEnd +1
88+
.endif ; .ifdef FirstBootStart
89+
90+
.ifdef SecondBootStart
91+
.set SecondBoot = SecondBootStart
92+
.else
93+
.set SecondBoot = FlashEnd +1
94+
.endif ; .ifdef SecondBootStart
95+
96+
.ifdef ThirdBootStart
97+
.set ThirdBoot = ThirdBootStart
98+
.else
99+
.set ThirdBoot = FlashEnd +1
100+
.endif ; .ifdef ThirdBootStart
101+
102+
.ifdef FourthBootStart
103+
.set FourthBoot = FourthBootStart
104+
.else
105+
.set FourthBoot = FlashEnd +1
106+
.endif ; .ifdef FourthBootStart
107+
108+
.if BootCodeSize
109+
.if BLS
110+
.set FlashSize = FlashEnd +1
111+
.if FlashSize - FirstBoot >= BootCodeSize >> 1
112+
.equ BootStart = FirstBoot
113+
.message "Please program Boot Fuse to First Boot Start !"
114+
.elif FlashSize - SecondBoot >= BootCodeSize >> 1
115+
.equ BootStart = SecondBoot
116+
.message "Please program Boot Fuse to Second Boot Start !"
117+
.elif FlashSize - ThirdBoot >= BootCodeSize >> 1
118+
.equ BootStart = ThirdBoot
119+
.message "Please program Boot Fuse to Third Boot Start !"
120+
.elif FlashSize - FourthBoot >= BootCodeSize >> 1
121+
.equ BootStart = FourthBoot
122+
.message "Please program Boot Fuse to Fourth Boot Start !"
123+
.else
124+
.equ BootStart = 0
125+
.error "BootStart is undefinied !"
126+
.endif ; .if FlashSize ...
127+
.else
128+
.set FlashSize = ((FlashEnd +1) * 2 - BootCodeSize) >> 1
129+
.equ BootStart = FlashSize - FlashSize % PageSize
130+
.message "Compile Bootloader without Boot Section !"
131+
.endif ; .if BLS
132+
.else
133+
.if (FLASHEND > 1023)
134+
.equ BootStart = ((FlashEnd +1) * 2 - 2048) / 2
135+
.else
136+
.equ BootStart = 0
137+
.endif
138+
.message "Please set used CSEG to BootSize !"
139+
.endif ; .if BootCodeSize
140+
141+
; fix bug with parsing HEX files in AVRStudio 4.16
142+
.if BootCodeSize
143+
.org 0
144+
.db 0xFF, 0xFF
145+
.endif
146+
147+
.set BootPages = (FlashEnd +1 - BootStart) / PageSize
148+
149+
.if UseVersioning
150+
.if BLS
151+
.set AppVerAddr = BootStart * 2 - 4
152+
.else
153+
.set AppVerAddr = BootStart * 2 - 6
154+
.endif ; .if BLS
155+
.endif ; .if UseVersioning
156+
157+
; examine special handling for SPM
158+
.if BLS && (SIGNATURE_000 == 0x1e)
159+
.if (SIGNATURE_001 == 0x94) && (SIGNATURE_002 == 0x01) ; ATmega161
160+
.set SPMspecial = 1
161+
.endif
162+
.if (SIGNATURE_001 == 0x94) && (SIGNATURE_002 == 0x02) ; ATmega163
163+
.set SPMspecial = 2
164+
.endif
165+
.if (SIGNATURE_001 == 0x95) && (SIGNATURE_002 == 0x01) ; ATmega323
166+
.set SPMspecial = 3
167+
.endif
168+
.endif
169+
170+
; BootMode flags
171+
.if UseBootMode == 1
172+
.set BootModeFlag = PORF
173+
.elif UseBootMode == 2
174+
.set BootModeFlag = EXTRF
175+
.elif UseBootMode == 3
176+
.set BootModeFlag = WDRF
177+
.elif UseBootMode == 4
178+
.ifndef USBRF
179+
.error "Device provable do not support USB reset, take a look into datasheet and include file if USBRF is defined"
180+
.else
181+
.set BootModeFlag = USBRF
182+
.endif
183+
.endif
184+
185+
.set ResetFlags = (1 << PORF) | (1 << EXTRF) | (1 << WDRF)
186+
.ifdef BORF
187+
.set ResetFlags = ResetFlags | (1 << BORF)
188+
.endif
189+
.ifdef JTRF
190+
.set ResetFlags = ResetFlags | (1 << JTRF)
191+
.endif
192+
.ifdef BODRF
193+
.set ResetFlags = ResetFlags | (1 << BODRF)
194+
.endif
195+
.ifdef OCDRF
196+
.set ResetFlags = ResetFlags | (1 << OCDRF)
197+
.endif
198+
.ifdef USBRF
199+
.set ResetFlags = ResetFlags | (1 << USBRF)
200+
.endif
201+
202+
203+
; some redefinition of register names or bits
204+
.ifndef MCUSR
205+
.ifndef MCUCSR
206+
.error "no definition for MCU Control Status Register found, look into AVRootloader.inc"
207+
.else
208+
.equ MCUSR = MCUCSR
209+
.endif
210+
.endif ; .ifndef MCUCSR
211+
212+
.ifndef WDCE
213+
.ifndef WDDE
214+
.equ WDCE = WDTOE
215+
.else
216+
.equ WDCE = WDDE
217+
.endif ; .ifndef WDDE
218+
.endif ; .ifndef WDCE
219+
220+
.ifndef WDTCR
221+
.equ WDTCR = WDTCSR
222+
.endif ; .ifndef WDTCR
223+
224+
.ifndef SPMCSR
225+
.equ SPMCSR = SPMCR
226+
.endif ; .ifndef SPMCSR
227+
228+
.ifndef RWWSRE
229+
.ifdef ASRE
230+
.equ RWWSRE = ASRE
231+
.endif ; .ifdef ASRE
232+
.endif ; .ifndef RWWSRE
233+
234+
.ifndef SPMEN
235+
.equ SPMEN = SELFPRGEN
236+
.endif ; .ifndef SPMEN
237+
238+
239+
.ifndef EEMWE
240+
.equ EEMWE = EEMPE
241+
.endif ; .ifndef EEMWE
242+
243+
.ifndef EEWE
244+
.equ EEWE = EEPE
245+
.endif ; .ifndef EEWE
246+
247+
.ifndef EEARL
248+
.equ EEARL = EEAR
249+
.endif ; .ifndef EEARL
250+
251+
; macros
252+
.macro xout
253+
.ifdef @0
254+
.if @0 > 0x3F
255+
sts @0, @1
256+
.else
257+
out @0, @1
258+
.endif
259+
.endif
260+
.endmacro
261+
262+
.macro xin
263+
.ifdef @1
264+
.if @1 > 0x3F
265+
lds @0, @1
266+
.else
267+
in @0, @1
268+
.endif
269+
.endif
270+
.endmacro
271+
272+
.macro xwdr
273+
.if UseWDR
274+
wdr
275+
.endif ; .if UseWDR
276+
.endmacro
277+
278+
.macro xlpm
279+
.if BigMega
280+
elpm @0, @1
281+
.else
282+
lpm @0, @1
283+
.endif
284+
.endmacro
285+
286+
.macro jmpapp
287+
.if BLS
288+
rjmp FLASHEND +1 ; run application
289+
.elif BootStart
290+
rjmp BootStart -1 ; run application
291+
.else
292+
rjmp BootStart ; dummy
293+
.endif ; .if BLS
294+
.endmacro
295+
296+
.macro bjmp
297+
.if @1
298+
rjmp @0
299+
.else
300+
ret
301+
.endif
302+
.endmacro
303+
304+
.macro rx_0
305+
.if UseUartInvert
306+
sbic RX_PIN, RX
307+
.else
308+
sbis RX_PIN, RX
309+
.endif ; .if UseUartInvert
310+
.endmacro
311+
312+
.macro rx_1
313+
.if UseUartInvert
314+
sbis RX_PIN, RX
315+
.else
316+
sbic RX_PIN, RX
317+
.endif ; .if UseUartInvert
318+
.endmacro
319+
320+
321+
.macro tx_1
322+
323+
.if (RX != TX) && (RX_PORT == TX_PORT)
324+
.if UseUartInvert
325+
.set tx1 = (1 << RX)
326+
.else
327+
.set tx1 = (1 << TX) | (1 << RX)
328+
.endif ; .if UseUartInvert
329+
.elif UseUartInvert && !Use1Wire
330+
.set tx1 = 0
331+
.else
332+
.set tx1 = (1 << TX)
333+
.endif ; .if (RX != TX) && (RX_PORT == TX_PORT)
334+
.ifdef DE_PORT
335+
.if !UseRS485Invert && (DE_PORT == TX_PORT)
336+
.set tx1 = tx1 | (1 << DE)
337+
.endif
338+
.endif
339+
ldi cnth, tx1
340+
.endmacro
341+
342+
.macro tx_0
343+
.if (RX != TX) && (RX_PORT == TX_PORT)
344+
.if UseUartInvert
345+
.set tx0 = (1 << TX) | (1 << RX)
346+
.else
347+
.set tx0 = (1 << RX)
348+
.endif ; .if UseUartInvert
349+
.elif UseUartInvert && !Use1Wire
350+
.set tx0 = (1 << TX)
351+
.else
352+
.set tx0 = 0
353+
.endif ; .if (RX != TX) && (RX_PORT == TX_PORT)
354+
.ifdef DE_PORT
355+
.if !UseRS485Invert && (DE_PORT == TX_PORT)
356+
.set tx0 = tx0 | (1 << DE)
357+
.endif
358+
.endif
359+
ldi cnth, tx0
360+
.endmacro
361+
362+
363+
.macro tx_out
364+
.if Use1Wire
365+
xout TX_DDR, cnth
366+
.else
367+
xout TX_PORT, cnth
368+
.endif ; .if Use1Wire
369+
.endmacro
370+
371+
.macro de_0
372+
.if UseRS485
373+
.if UseRS485Invert
374+
sbi DE_PORT, DE
375+
.else
376+
cbi DE_PORT, DE
377+
.endif
378+
.endif
379+
.endmacro
380+
381+
.macro de_1
382+
.if UseRS485
383+
.if UseRS485Invert
384+
cbi DE_PORT, DE
385+
.else
386+
sbi DE_PORT, DE
387+
.endif
388+
.endif
389+
.endmacro
390+

‎AVRootloader.ini

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
[System]
2+
Sign=BOOTLOADER
3+
Port=AUTO
4+
Baudrate=115200
5+
ConnectTrials=3
6+
FLASH=
7+
EEPROM=
8+
ASMFile=AVRootloader.asm
9+
Erase=1
10+
Verify=1
11+
Protocol=0
12+
Password=
13+
AppCmd=
14+
AppCmdResponse=
15+
AppVersion=$01020000
16+
AppVersionFlag=$0C
17+
ACYInfo=
18+
19+
[Timeouts]
20+
Connect=0
21+
Base=50
22+
Erase=10
23+
Flash=15
24+
Eeprom=10
25+
Buffer=1
26+
AppCmd=0
27+
KeepAlive=250
28+
MaxPacketSize=0
29+
RTSPulse=0
30+
RTSInterval=0
31+
Options=0
32+
33+
; Timeouts in Millisekunden
34+
; Base = Minimum Timeout für 1 Zeichen über UART, bei hohen Baudraten stellt dieser Wert das Minimum an Timeout dar
35+
; Erase = Timeout zum Löschen einer FLASH Page, normalerweise 5 ms laut Datenblätter
36+
; Flash = Timeout zum Löschen und Programmieren eienr FLASH Page, normalerweise 2*5ms
37+
; Eeprom = Timeout zum Programmieren eines Bytes im EEPROM, normalerweise 5 ms
38+
; Buffer = Timeout beim Warten auf ein Fehlercodebyte beim Schreiben von Bufferdaten, sollte mit 1ms immer gehen
39+
; RTSPulse = PC-Sofwtare pulst für RTSPulse Millisekunden die RTS Leitung, bei RTSPulse=0 ist das deaktiviert
40+
; bei RTSPulse > 0 wird von HIGH->LOW->HIGH und bei RTSPulse < 0 von LOW->HIGH->LOW gepulst.
41+
; Bsp: RTSPulse=20 bedeutet HIGH->20ms LOW ->HIGH
42+
; RTSInterval, wenn RTSPulse <> 0 ist bestimmt dieser Wert in welchem Interval das Pulsen von RTS erfolgen soll.
43+
; Beim Wert 0 wird nur einmalig beim Verbindungsaufbau RTS gepulst. Beim Wert 1 vor jedem einzlenen Connect Versuch zum AVR.
44+
; Bei Wert 2 jedes zweitemal usw. Ein Wert von 4 bedeutet also das nach einem RTS Puls exakt 4 Connect Versuche folgen
45+
; bis es wieder von vorne losgeht.
46+
47+
[GUI]
48+
Left=601
49+
Top=241
50+
Width=563
51+
Height=513
52+
53+
[Baudrates]
54+
0=2400
55+
1=4800
56+
2=9600
57+
3=14400
58+
4=19200
59+
5=28800
60+
6=38400
61+
7=56000
62+
8=57600
63+
9=115200
64+
10=128000
65+
11=230400
66+
12=256000
67+
13=921600
68+
69+
[Signs]
70+
0=BOOTLOADER
71+
1=BOOT
72+
73+
[FLASH]
74+
0=
75+
76+
[EEPROM]
77+
0=

‎Crypt.inc

+259
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,259 @@
1+
; copyright HR
2+
; decryption code, XTEA with special double CBC ciphermode to get a CMAC, cipher message authentication code
3+
.nolist
4+
5+
.undef feedl
6+
.undef feedh
7+
.undef crcl
8+
.undef crch
9+
.undef paral
10+
.undef parah
11+
.undef polyl
12+
.undef polyh
13+
.undef zx
14+
.undef cmdl
15+
.undef cmdh
16+
.undef cntl
17+
.undef cnth
18+
19+
.def a0 = r0
20+
.def a1 = r1
21+
.def a2 = r2
22+
.def a3 = r3
23+
.def b0 = r4 ; feedl
24+
.def b1 = r5 ; feedh
25+
.def b2 = r6
26+
.def b3 = r7 ; zx
27+
.def t0 = r8 ; crcl
28+
.def t1 = r9 ; crch
29+
;.def zerol = r10 ; zerol
30+
;.def zeroh = r11 ; zeroh
31+
;.def baudl = r12 ; baudl
32+
;.def baudh = r13 ; baudl
33+
;.def sraml = r14 ; SRAM buffer start
34+
;.def sramh = r15
35+
.def s0 = r16 ; paral
36+
.def s1 = r17 ; parah
37+
.def s2 = r18 ; polyl, restored
38+
.def s3 = r19 ; polyh, restored
39+
;.def cnt = r20 ; cnt
40+
;.def flag = r21 ; flag
41+
.def round = r22 ; cmdl
42+
.def t4 = r23 ; cmdh
43+
.def t2 = r24 ; cntl
44+
.def t3 = r25 ; cnth
45+
;.def XL = r26 ; buffer_endl
46+
;.def XH = r27 ; buffer_endh
47+
;.def YL = r28 ; unused
48+
;.def YH = r29 ; unused
49+
;.def ZL = r30 ; overwritten Address
50+
;.def ZH = r31 ;
51+
.list
52+
53+
54+
; XTEA decryption with spezial CBC feedback modus, final checksum/signature block with 24 Bit FLASH Address setup
55+
; SRAML points to start of buffer, SRAML-16 points to feedback, SRAML-8 points to buffer of next used feedback
56+
; X points after buffer
57+
; T flag = 0 = CMDL = 0xFE = decryption init, = 1 = CMDL = 0xFF = normal data decryption
58+
; cycles:
59+
; 698 * 8 Bytes -1 = 5583 one data block
60+
; + 98 for CMDL=0xFE=init
61+
; + 76 for CMDL=0xFF=data
62+
; thus average throughput by 8Mhz is 11kByte/sec
63+
64+
decrypt:
65+
movw yl, sraml
66+
sbiw yl, 16
67+
movw sraml, yl
68+
sbiw xl, 16
69+
.if BigMega
70+
ldi cnt, byte3(BootKey * 2)
71+
xout RAMPZ, cnt
72+
.endif ; .if BigMega
73+
74+
tea1: ldi cnt, 8
75+
movw zl, zerol ; zerol, z points to register file r0-r7 = a,b
76+
tea2: ldd t0, y +0 ; buffer = feedback xor cipherblock
77+
ldd t1, y +16 ; in next round buffer is feedback
78+
eor t0, t1
79+
std y +8, t0
80+
st z+, t1 ; setup a,b = cipherblock
81+
adiw yl, 1
82+
dec cnt
83+
brne tea2
84+
85+
ldi s0, 0x20 ; sum = 32 * delta
86+
ldi s1, 0x37
87+
ldi s2, 0xef
88+
ldi s3, 0xc6
89+
90+
rcall teadec ; first 16 rounds
91+
92+
tea3: ld t0, z ; ciphertext = ciphertext xor feedback
93+
ld t1, y+
94+
eor t0, t1
95+
st z+, t0
96+
dec cnt
97+
brne tea3
98+
99+
rcall teadec ; second 16 rounds
100+
101+
tea4: ld t0, z+ ; plaintext = ciphertext xor feedback
102+
ld t1, y
103+
eor t0, t1
104+
st y+, t0
105+
dec cnt
106+
brne tea4
107+
108+
cp yl, xl ; sram buffer end reached ?
109+
cpc yh, xh
110+
brlo tea1
111+
ldi s0, ERRORCRYPT
112+
brcs tea7 ; overflow, datasize not a multiple of 8
113+
114+
sbiw yl, 8 ; points to signature + dummy + address
115+
116+
.if UseVersioning
117+
brts tea80
118+
119+
ldi zl, byte1(AppVerAddr) ; check version number
120+
ldi zh, byte2(AppVerAddr)
121+
ldi cnt, 4
122+
sbiw yl, 4
123+
ldi s2, 0xFF
124+
ldi s3, 0xFF
125+
126+
tea8: ld r0, y+
127+
xlpm r1, z+
128+
and s3, r1
129+
cpse r0, s2
130+
cpc r0, r1
131+
dec cnt
132+
brne tea8
133+
134+
ldi s0, ERRORVERSION
135+
cpse s3, s2
136+
brcs tea7
137+
ldi s0, ERRORCRYPT
138+
tea80:
139+
.endif ;.if UseVersioning
140+
141+
ori flag, 0x02 ; success crypt
142+
143+
ldi zl, byte1(BootKey * 2)
144+
ldi zh, byte2(BootKey * 2)
145+
movw xl, yl
146+
ldi cnt, 4 ; check signature
147+
brts tea5
148+
sbiw zl, 4
149+
ldi cnt, 8 ; check BootInfo and signature
150+
tea5: ld r0, y+
151+
xlpm r1, z+
152+
cpse r0, r1
153+
clr flag ; signature don't match
154+
dec cnt
155+
brne tea5
156+
157+
movw b0, xl ; feedback
158+
159+
brtc tea6
160+
ldd s1, y +0 ; correct XH:XL = bufferend pointer for non-multiple-of-8 data
161+
sub xl, s1
162+
sbc xh, zerol
163+
ldd b3, y +1 ; ZX:ZH:ZL, new FLASH/EEPROM Address, only valid if cmdl = 0xFF
164+
ldd zh, y +2
165+
ldd zl, y +3
166+
167+
tea6: sbrc flag, 1
168+
ldi s0, SUCCESS
169+
tea7: ldi s2, byte1(POLYNOM) ; restore CRC polynom
170+
ldi s3, byte2(POLYNOM)
171+
rjmp mai1
172+
173+
174+
; plain XTEA decryption
175+
teadec: ldi round, 32 ; 16 round XTEA, r0-r7=a,b ciphertext
176+
movw t0, a0
177+
movw t2, a2
178+
179+
dec1: clr t4 ; t = (a shr 4) xor (a shl 5)
180+
ldi cnt, 3
181+
dec2: lsl t0
182+
rol t1
183+
rol t2
184+
rol t3
185+
rol t4
186+
dec cnt
187+
brne dec2
188+
189+
lsl t0
190+
eor t0, t1
191+
rol t1
192+
eor t1, t2
193+
rol t2
194+
eor t2, t3
195+
rol t3
196+
eor t3, t4
197+
198+
add t0, a0 ; t = ((a shr 4) xor (a shl 5)) + a
199+
adc t1, a1
200+
adc t2, a2
201+
adc t3, a3
202+
203+
ldi zl, low(BootKey *2)
204+
ldi zh, high(BootKey *2)
205+
206+
sbrc round, 0
207+
rjmp dec3
208+
209+
sbrc s1, 3 ; k = key[(sum shr 11) and 3]
210+
adiw zl, 4
211+
sbrc s1, 4
212+
adiw zl, 8
213+
214+
rjmp dec4
215+
216+
dec3: subi s0, 0xB9 ; sum = sum - delta
217+
sbci s1, 0x79
218+
sbci s2, 0x37
219+
sbci s3, 0x9E
220+
221+
sbrc s0, 0 ; k = key[sum and 3]
222+
adiw zl, 4
223+
sbrc s0, 1
224+
adiw zl, 8
225+
226+
dec4: xlpm t4, z+ ; t = t xor (sum + k)
227+
add t4, s0
228+
eor t0, t4
229+
xlpm t4, z+
230+
adc t4, s1
231+
eor t1, t4
232+
xlpm t4, z+
233+
adc t4, s2
234+
eor t2, t4
235+
xlpm t4, z+
236+
adc t4, s3
237+
eor t3, t4
238+
239+
sub b0, t0 ; b = b - t
240+
sbc b1, t1
241+
sbc b2, t2
242+
sbc b3, t3
243+
244+
movw t0, b0 ; b = a, a = b
245+
movw t2, b2
246+
movw b0, a0
247+
movw b2, a2
248+
movw a0, t0
249+
movw a2, t2
250+
251+
dec round
252+
brne dec1
253+
254+
ldi cnt, 8
255+
movw zl, zerol
256+
sbiw yl, 8
257+
258+
ret
259+

‎Readme.md

+338
Large diffs are not rendered by default.

‎Special.inc

+259
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,259 @@
1+
.nolist
2+
; copyright HR
3+
; special functions to provide for application code access to FLASH
4+
; can be expanded with own functions and place a rjmp vector at end of this file
5+
6+
; First calculate size of code to align code at end of FLASH, better solution possible ?
7+
8+
; Align all follow function at end of FLASH get us to posibility to reprogram a new bootloader.
9+
; For minimal solutions use UseSpecialBootVect=1 to include a rjmp bootstart, rjmp dospm
10+
; vector and the dospm function at end of bootloader section. This cost 16 bytes of FLASH and
11+
; thus the last FLASH page should be always unchanged. With a own application and help of
12+
; dospm function can the remaining bootloader section repogrammed. Please remember that
13+
; all stuff like ISR blocking, waiting for EEPROM write finish and so on must be done in own
14+
; application that wants to update the bootloader (including sanity checks not to overwrite last FLASH page)
15+
; For more comfortable solution set UseSpecialWrite=1 and UseSpecialWriteBoot=1. Now with function
16+
; write_flash() a ways exists to write from SRAM buffer to any address on FLASH without to consider
17+
; page aligment or data size. If the application read access to bootloader section is prohibited by lockbits
18+
; then set UseSpecialRead=1. Now with read_flash() it's possible to read the entire full flash.
19+
; These feature are only usefull on AVRs with bootloader sections. On Tiny AVRs there is always the possibility to
20+
; use SPM in application code.
21+
22+
23+
.set SpecialSize = 0
24+
25+
.if UseSpecialWrite
26+
.set SpecialSize = SpecialSize +48
27+
.if UseSpecialWriteBoot
28+
.set SpecialSize = SpecialSize +5
29+
.endif
30+
.if BigMega
31+
.set SpecialSize = SpecialSize +4
32+
.endif
33+
.if BLS
34+
.set SpecialSize = SpecialSize +5
35+
.ifdef SPMSpecial
36+
.set SpecialSize = SpecialSize +3
37+
.endif
38+
.ifdef RWWSRE
39+
.set SpecialSize = SpecialSize +2
40+
.endif
41+
.else
42+
.set SpecialSize = SpecialSize +8
43+
.endif
44+
.if UseWDR
45+
.set SpecialSize = SpecialSize +1
46+
.endif
47+
.endif
48+
49+
.if UseSpecialRead
50+
.set SpecialSize = SpecialSize +9
51+
.if BigMega
52+
.set SpecialSize = SpecialSize +1
53+
.endif
54+
.endif
55+
56+
.if UseSpecialMsg
57+
.set SpecialSize = SpecialSize +5
58+
.endif
59+
60+
; rjmp vector table
61+
.if UseSpecialWrite || UseSpecialRead || UseSpecialMsg
62+
.set SpecialSize = SpecialSize +5
63+
.elif UseSpecialBootVect
64+
.set SpecialSize = SpecialSize +1
65+
.if BLS
66+
.set SpecialSize = SpecialSize +1
67+
.endif
68+
.endif
69+
70+
; dospm
71+
.if SpecialSize > 0
72+
.if BLS
73+
.set SpecialSize = SpecialSize +6
74+
.ifdef SPMSpecial
75+
.set SpecialSize = SpecialSize +3
76+
.endif
77+
.endif
78+
79+
; align follow code at flash end
80+
.if BootCodeSize
81+
.org (FLASHEND +1) - SpecialSize
82+
.endif
83+
.endif ; .if SpecialSize > 0
84+
85+
; end of size calculation
86+
.list
87+
88+
89+
.if UseSpecialMsg
90+
getbootmsg:
91+
; return address and size of BootMsg, can be used in application to read out BootMsg and follow datas
92+
ldi r22, byte1(BootMsg * 2)
93+
ldi r23, byte2(BootMsg * 2)
94+
ldi r24, byte3(BootMsg * 2)
95+
ldi r25, (BootInfo - BootMsg) * 2
96+
ret
97+
.endif ;.if UseSpecialMsg
98+
99+
100+
.if UseSpecialRead
101+
readflash:
102+
; void readflash(uint32_t address, uint16_t size, const uint8_t* buffer);
103+
; r25:r24:r23:r22, r21:r20, r19:r18
104+
.if BigMega
105+
xout RAMPZ, r24
106+
.endif
107+
movw zl, r22
108+
movw xl, r18
109+
movw r24, r20
110+
rf1: sbiw r24, 1
111+
brcs rf2
112+
xlpm r23, z+
113+
st x+, r23
114+
rjmp rf1
115+
rf2: ret
116+
.endif ;.if UseSpecialRead
117+
118+
119+
.if UseSpecialWrite
120+
writeflash:
121+
; void write_flash(uint32_t address, uint16_t size, const uint8_t* buffer);
122+
; r25:r24:r23:r22, r21:r20, r19:r18
123+
124+
.if PageSize * 2 > 256
125+
.error "PageSize is greater as 256 bytes, check programing loops"
126+
.endif
127+
128+
movw zl, r22 ; address to r24:Z
129+
movw xl, r18 ; SRAM buffer to X
130+
movw r18, yl ; save Y to r18
131+
movw yl, r20 ; size to Y
132+
movw r20, r16 ; save r17:r16 to r21:r20
133+
movw r16, r24 ;
134+
xin r23, SREG ; save SREG to r23
135+
cli ; disable IRQs
136+
.if UseSpecialWriteBoot
137+
clt ; set T flag if MSB of address is a magic to deactivate
138+
cpi r17, 0xAC ; write cheks to bootloader section
139+
brne wf1
140+
set
141+
.endif ; .if UseSpecialWriteBoot
142+
143+
wf1: sbic EECR, EEWE ; wait for EEPROM
144+
rjmp wf1
145+
146+
andi r22, PageSize *2 -1 ; align address
147+
sub zl, r22
148+
149+
wf2: ldi r17, PageSize
150+
.if UseSpecialWriteBoot
151+
brts wf3 ; if T flag is set ignore sanity check
152+
.endif
153+
cpi zl, byte1(BootStart *2) ; sanity check to ensure not to overwrite bootloader
154+
ldi r24, byte2(BootStart *2)
155+
cpc zh, r24
156+
.if BigMega
157+
ldi r24, byte3(BootStart * 2)
158+
cpc r16, r24
159+
.endif
160+
brsh wf8
161+
162+
wf3: ldi r24, (1 << SPMEN)
163+
.if BigMega
164+
xout RAMPZ, r16
165+
.endif
166+
wf4: xlpm r0, z+ ; first load word from FLASH
167+
xlpm r1, z
168+
sbiw z, 1
169+
sbiw yl, 0 ; size = 0 ?
170+
breq wf7
171+
cpi r22, 1
172+
brlo wf5
173+
breq wf6
174+
subi r22, 2
175+
rjmp wf7
176+
wf5: ld r0, x+
177+
sbiw yl, 1
178+
breq wf7
179+
wf6: ld r1, x+
180+
sbiw yl, 1
181+
clr r22
182+
wf7: xwdr
183+
.if BLS
184+
rcall dospm ; fill FLASH buffer
185+
.else
186+
xout SPMCSR, r24
187+
spm
188+
.endif
189+
adiw z, 2
190+
dec r17 ; PageSize
191+
brne wf4
192+
193+
subi zl, byte1(PageSize *2)
194+
sbci zh, byte2(PageSize *2)
195+
.if BLS
196+
ldi r24, (1 << PGERS) | (1 << SPMEN) ; erase FLASH page
197+
rcall dospm
198+
ldi r24, (1 << PGWRT) | (1 << SPMEN) ; program FLASH page
199+
rcall dospm
200+
.ifdef RWWSRE
201+
ldi r24, (1 << RWWSRE) | (1 << SPMEN) ; unlock FLASH page
202+
rcall dospm
203+
.endif
204+
.else
205+
ldi r24, (1 << PGERS) | (1 << SPMEN) ; erase FLASH page
206+
xout SPMCSR, r24
207+
spm
208+
ldi r24, (1 << PGWRT) | (1 << SPMEN) ; program FLASH page
209+
xout SPMCSR, r24
210+
spm
211+
.endif
212+
subi zl, byte1(-PageSize *2)
213+
sbci zh, byte2(-PageSize *2)
214+
.if BigMega
215+
sbci r16, byte3(-PageSize *2)
216+
.endif
217+
sbiw yl, 0 ; size = 0 ?
218+
brne wf2
219+
220+
wf8: clr r1 ; restore r1=zero
221+
movw yl, r18 ; restore Y
222+
movw r16, r20 ; restore r17:r16
223+
xout SREG, r23 ; restore SREG
224+
ret
225+
.endif ;.if UseSpecialWrite
226+
227+
228+
; SPM helper function, put in here to support updates of bootloader code, programmed into last FLASH page
229+
; r25=cnth destroyed, r24=cntl unchanged
230+
.if BLS
231+
dospm: xout SPMCSR, r24
232+
spm
233+
.ifdef SPMspecial
234+
.dw $FFFF
235+
nop
236+
.endif
237+
dspm1: xin r25, SPMCSR
238+
sbrc r25, SPMEN
239+
rjmp dspm1
240+
ret
241+
.endif ; .if BLS
242+
243+
244+
.if UseSpecialWrite || UseSpecialRead || UseSpecialMsg
245+
; rjmp vectors for support from application code
246+
; can be expanded with own vectors to own code, look into AVRootloader.h how to call
247+
; please don't reorder this jump table, but you can expand it to own code
248+
; if you expand it remember to update above SpecialSize calculation
249+
bjmp getbootmsg, UseSpecialMsg ; rjmp getbootmsg if UseSpecial else ret
250+
bjmp readflash, UseSpecialRead
251+
bjmp writeflash, UseSpecialWrite
252+
bjmp dospm, BLS
253+
rjmp bootstart
254+
.elif UseSpecialBootVect
255+
.if BLS
256+
rjmp dospm
257+
.endif
258+
rjmp bootstart
259+
.endif

‎intcast.h

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#ifndef INTCAST_H
2+
#define INTCAST_H
3+
4+
typedef union {
5+
uint16_t word;
6+
struct {
7+
uint8_t a,b;
8+
};
9+
} uint16_t_u;
10+
11+
typedef union {
12+
uint32_t dword;
13+
struct {
14+
uint8_t a,b,c,d;
15+
};
16+
} uint32_t_u;
17+
18+
typedef union {
19+
uint32_t dword;
20+
struct {
21+
uint16_t a,b;
22+
};
23+
} uint32_t_s;
24+
25+
#define L8(v) (((uint16_t_u)v).a)
26+
#define H8(v) (((uint16_t_u)v).b)
27+
28+
#define L16(v) (((uint32_t_s)v).a)
29+
#define H16(v) (((uint32_t_s)v).b)
30+
31+
#define LL8(v) (((uint32_t_u)v).a)
32+
#define LH8(v) (((uint32_t_u)v).b)
33+
#define HL8(v) (((uint32_t_u)v).c)
34+
#define HH8(v) (((uint32_t_u)v).d)
35+
36+
37+
#endif

0 commit comments

Comments
 (0)
Please sign in to comment.