; Orange programmer module v4.2 beta ; (c) 2010-2015 CnCLab ; Atmel AVR ; ;CHIP=ATmega169A,16K,atm649.hpl ;AREA=FLASH,16K(128),0 ;AREA=EEPROM,512 ;CHIP=ATmega169PA,16K,atm649.hpl ;AREA=FLASH,16K(128),0 ;AREA=EEPROM,512 ;CHIP=ATmega329,32K,atm649.hpl ;AREA=FLASH,32K(128),0 ;AREA=EEPROM,1K ;CHIP=ATmega329A,32K,atm649.hpl ;AREA=FLASH,32K(128),0 ;AREA=EEPROM,1K ;CHIP=ATmega329PA,32K,atm649.hpl ;AREA=FLASH,32K(128),0 ;AREA=EEPROM,1K ;CHIP=ATmega3290,32K,atm649.hpl ;AREA=FLASH,32K(128),0 ;AREA=EEPROM,1K ;CHIP=ATmega3290A,32K,atm649.hpl ;AREA=FLASH,32K(128),0 ;AREA=EEPROM,1K ;CHIP=ATmega3290PA,32K,atm649.hpl ;AREA=FLASH,32K(128),0 ;AREA=EEPROM,1K ;CHIP=ATmega649,64K,atm649.hpl ;AREA=FLASH,64K(128),0 ;AREA=EEPROM,2K ;CHIP=ATmega649A,64K,atm649.hpl ;AREA=FLASH,64K(128),0 ;AREA=EEPROM,2K ;CHIP=ATmega649PA,64K,atm649.hpl ;AREA=FLASH,64K(128),0 ;AREA=EEPROM,2K ;CHIP=ATmega6490,64K,atm649.hpl ;AREA=FLASH,64K(128),0 ;AREA=EEPROM,2K ;CHIP=ATmega6490A,64K,atm649.hpl ;AREA=FLASH,64K(128),0 ;AREA=EEPROM,2K ;CHIP=ATmega6490PA,64K,atm649.hpl ;AREA=FLASH,64K(128),0 ;AREA=EEPROM,2K ; based on Atm328.hpl, but different fuses ; Primary tested ATmega329 ; atmega xxxA and xxxPA have unused BODLEVEL2 fuse. ALLPINS=0 INFO="AVR Adapter" OPTIONS=mf, PINO=SCK, 0 PINO=MOSI, 2 PINO=MISO, 1 PINO=RESET,3 PINI=MISO, 1 PING=GND,255 PINO=VCC,254 BUSO=CFREQ,128 R8=Fuses,B8 R9=Lock,C6,BLB12,BLB11,BLB02,BLB01,LB2,LB1 R10=CKSEL,L,"0000: Ext Clk,0001: Reserved,0010: IntRC,0011: Reserved,0100: Reserved,0101: Reserved,0110: Low Crystal,0111: Low Crystal,1000: Crystal 0.4-0.9MHz,1001: Crystal 0.4-0.9MHz,1010: Crystal 0.9-3.0MHz,1011: Crystal 0.9-3.0MHz,1100: Crystal 3-8MHz,1101: Crystal 3-8MHz,1110: Crystal >8MHz,1111: Crystal >8MHz" R11=SUT,C2,SUT1,SUT0 R12=CKOUT,L,"0 - On,1 - Off" R13=CKDIV8,L,"0 - On,1 - Off" R14=BOOTRST,L,"0 - Boot Loader","1 - Application" R15=BOOTSZ,L,"32 pages,16 pages,8 pages,4 pages" R16=EESAVE,L,"0 - Save,1 - Clear" R17=WDTON,L,"0 - On,1 - Off" R18=JTAGEN,L,"0 - On,1 - Off" R19=OCDEN,L,"0 - On,1 - Off" R1A=RSTDISBL,L,"0 - PG5:IO,1 - PG5:RESET" R1B=BODLEVEL,L,"00: 4.3V,01: 2.7V,10: 1.8V,11: Disabled" ;2 bits ;R14=SPIEN,L,"0 - On,1 - Off" SPIEN Fuse is not accessible in serial programming mode. CDELAY=10 ; minimum periods for the serial clock (SCK) > 4 XTAL1 clock cycle! [_DOUT] R1=0; LOOP=(7,0){MOSI=R0[I],SCK=1,R1[I]=MISO,SCK=0} [_DIN] R0=0 LOOP=(7,0){SCK=1,R0[I]=MISO,SCK=0} ;return R0 [_RDLOCK] _DOUT(0x58) ;rd lock bits _DOUT(0x00) _DOUT(0x00) _DIN [INIT] SCK=0 MISO=Z CFREQ=2000000 RESET=0,P=1000 LOOP=(32){ ; 32 attempts RESET=1,P=250 RESET=0,P=20000 _DOUT(0xAC) ;Programming Enable _DOUT(0x53) _DOUT(0x00) R3=R1 _DOUT(0) R3?0x53{BREAK} ;PRINT=("ANSWER: %02lX",R1) } R3?!0x53{PRINT=("ANSWER ERROR: %02lX",R3),EXIT} P=10 RE?<4{ _RDLOCK R0=&3,R0?0{PRINT=S("#MCU memory locked!")} } [READ] $AREA?0{ R0=0x20 ;program memory area R1=ADR,R0[3]=R1[0] ;Hi/Lo _DOUT LOOP=(16,9){MOSI=ADR[I],SCK=P} LOOP=(8,1){MOSI=ADR[I],SCK=P} } $AREA?1{ R0=0xA0 ;eeprom area _DOUT LOOP=(15,8){MOSI=ADR[I],SCK=P} LOOP=(7,0){MOSI=ADR[I],SCK=P} } _DIN ;common DATA=R0 [WRITE] $AREA?0{ PRINT=("Only Page Write Supported!") EXIT } $AREA?1{ _DOUT(0xC0) ;eeprom memory area LOOP=(15,8){MOSI=ADR[I],SCK=P} LOOP=(7,0){MOSI=ADR[I],SCK=P} R0=DATA,_DOUT P=9000 ; 4ms } [WRITEBLOCK] R7=ADR ;check empty (0xFF) block LOOP=($BLOCKSIZE){ R1=DATA R1?!0xFF{BREAK} ADR=+1 } R1?0xFF{RETURN} ADR=R7 LOOP=($BLOCKSIZE){ R0=0x40 ;program memory R1=ADR,R0[3]=R1[0],_DOUT ;Hi/Lo R0=0,_DOUT LOOP=(8,1){MOSI=ADR[I],SCK=P} R0=DATA,_DOUT P=5 ADR=+1 } ;Write Program memory Page: ADR=R7 _DOUT(0x4C) LOOP=(16,9){MOSI=ADR[I],SCK=P} LOOP=(8,6){MOSI=ADR[I],SCK=P} LOOP=(5,1){MOSI=0,SCK=P} _DOUT(0) ;dummy data P=5000 [WRITEEND] P=10000 RESET=1,P=50 RESET=0,P=20000 ;Ext Fuse: bit ;BODLEVEL1 2 Brown-out Detector level 1 ;BODLEVEL0 1 Brown-out Detector level 1 ;RSTDISBL 0 External Reset Disable 1 (unprog) ;Fuse High Byte ;OCDEN 7 Enable OCD 1 (unprogrammed, OCD disabled) ;JTAGEN 6 Enable JTAG 0 (programmed, JTAG enabled) ;SPIEN 5 Enable Serial Program and Data Downloading 0 (programmed, SPI prog. enabled) ;WDTON 4 Watchdog Timer always on 1 (unprogrammed) ;EESAVE 3 EEPROM memory is preserved through the Chip Erase 1 (unprogrammed, EEPROM not preserved) ;BOOTSZ1 2 Select Boot Size 0 (programmed) ;BOOTSZ0 1 Select Boot Size 0 (programmed) ;BOOTRST 0 Select Reset Vector 1 (unprogrammed) ;Fuse Low Byte ;CKDIV8 7 Divide clock by 8 0 (programmed) ;CKOUT 6 Clock output 1 (unprogrammed) ;SUT1 5 Select start-up time 1 (unprogrammed) ;SUT0 4 Select start-up time 0 (programmed) ;CKSEL3 3 Select Clock source 0 (programmed) ;CKSEL2 2 Select Clock source 0 (programmed) ;CKSEL1 1 Select Clock source 1 (unprogrammed) ;CKSEL0 0 Select Clock source 0 (programmed) ["Read Fuses"] _DOUT(0x50) ;Read Low Fuse bits _DOUT(0x00) _DOUT(0x00) _DIN R8=R0 R10=0,R11=0,R12=0,R13=0 R10=R8,R10=&0xF ;R10=CKSEL R11[0]=R8[4] ;R11=SUT,C2 R11[1]=R8[5] R12[0]=R8[6] ;R12=CKOUT,L R13[0]=R8[7] ;R13=CKDIV8,L _DOUT(0x58) ;Read Fuse High Bits _DOUT(0x08) _DOUT(0x00) _DIN R8=R0 R14=0,R15=0,R16=0,R17=0,R18=0,R19=0 R14[0]=R8[0] ;BOOTRST R15[0]=R8[1] ;BOOTSZ0 R15[1]=R8[2] ;BOOTSZ1 R16[0]=R8[3] ;EESAVE R17[0]=R8[4] ;WDTON R18[0]=R8[6] ;JTAGEN R19[0]=R8[7] ;OCDEN _DOUT(0x50) ;Read Fuse ext Bits _DOUT(0x08) _DOUT(0x00) _DIN ;R1B=BODLEVEL,L,"00: 4.3V,01: 2.7V,10: 1.8V,11: Disabled" ;2 bits R1A=0,R1B=0 R1A[0]=R8[0] ;RSTDISBL R1B[0]=R8[1] ;BODLEVEL R1B[1]=R8[2] ;BODLEVEL RESET=1,P=10 VCC=0 GET=("Read Fuses",R10,R11,R12,R13,R14,R15,R16,R17,R18,R19,R1A,R1B) ;GET=("Read Fuses",R10,R11,R12,R13,R14) ["Write Fuses"] GET=("Write Fuses",R10,R11,R12,R13,R14,R15,R16,R17,R18,R19,R1A,R1B) RA?0{EXIT} ;PRINT=("%lX",R11) R10?0{ ;R10=CKSEL PRINT=A("This fuses value require Ext. Clock, continue?") RA?0{EXIT} } R1A?0{ ;R1A=RSTDISBL PRINT=A("This fuses value disable serial prog., continue?") RA?0{EXIT} } R8=0xFF ;Low Fuse bits R8=R10,R8=&0xF ;R10=CKSEL,L R8[4]=R11[0] ;R11=SUT,C2 R8[5]=R11[1] R8[6]=R12[0] ;R12=CKOUT,L R8[7]=R13[0] ;R13=CKDIV8,L _DOUT(0xAC) _DOUT(0xA0) _DOUT(0x00) R0=R8,_DOUT P=15000 R8=0xFF ;High Fuse bits R8[0]=R14[0] ;BOOTRST R8[1]=R15[0] ;BOOTSZ0 R8[2]=R15[1] ;BOOTSZ1 R8[3]=R16[0] ;EESAVE R8[4]=R17[0] ;WDTON R8[6]=R18[0] ;JTAGEN ;bugfix R8[7]=R19[0] ;OCDEN _DOUT(0xAC) ;Write High Fuse _DOUT(0xA8) _DOUT(0x00) R0=R8,_DOUT P=15000 R8=0xFF ;Ext Fuse R8[0]=R1A[0] ;RSTDISBL R8[1]=R1B[0] ;BODLEVEL R8[2]=R1B[1] ;BODLEVEL _DOUT(0xAC) ;Write Ext Fuse _DOUT(0xA4) _DOUT(0x00) R0=R8,_DOUT P=15000 RESET=1,P=20 RESET=0,P=20000 [ReadLock] _DOUT(0x58) ;Write lock bits _DOUT(0x00) _DOUT(0x00) _DIN R9=R0 ;PRINT=("R9: %04lX",R9) GET=("Lock",R9) [WriteLock] GET=("Write Lock",R9) RA?0{EXIT} _DOUT(0xAC) ;Write lock bits _DOUT(0xE0) _DOUT(0x00) R0=R9,R0=|0xC0 ;PRINT=("R9: %04lX",R9) _DOUT P=50000 RESET=1,P=20 RESET=0,P=10000 [ReadID] _DOUT(0x30) _DOUT(0x00) _DOUT(0x00) _DIN R2=R0,R2=<<8 _DOUT(0x30) _DOUT(0x00) _DOUT(0x01) _DIN R2=|R0,R2=<<8 _DOUT(0x30) _DOUT(0x00) _DOUT(0x02) _DIN R2=|R0 R2?0x1E9503{PRINT=("ID: %06X - ATmega329",R2),EXIT} R2?0x1E9504{PRINT=("ID: %06X - ATmega3290",R2),EXIT} R2?0x1E9603{PRINT=("ID: %06X - ATmega649",R2),EXIT} R2?0x1E9604{PRINT=("ID: %06X - ATmega6490",R2),EXIT} PRINT=("ID: %06lX",R2) [Erase] _DOUT(0xAC) ;Chip Erase _DOUT(0x80) _DOUT(0x00) _DOUT(0x00) P=100000 ; Check _DOUT(0x20) ;program memory area _DOUT(0x00) ;ADR 0 _DOUT(0x00) _DIN ;common R0?!0xFF{PRINT=E("Erase error")} R0?0xFF{PRINT=S("Erase finished")} RESET=1,P=2000, RESET=0,P=500000 [END] RESET=1 ;EO=1,P=10 ;BB off