Need help with to compile a atmega168 code from around 2010 or maybe earlier - Page 1
Forum section: electronics / general

author: arslan43711
author_rank: Contributor
timestamp: April 06, 2023, 07:23:59 am
content: I am using using Atmel studio 6.1Can any guide me in the right direction. How can I fix the code or How figure out and setup the right build environment. ThanksQuestion number oneI code some variables are declared with flash keyword. (Note: I know that compiler support __flash. Is there any difference between these two ?). Code snippet isCode:flash char deviceName[] = DEVICE_NAME;flash uint8_t demoSwipes = Demo_Limit;flash uint16_t demoSeconds = Demo_Limit * 60;Question number 2:some variables are declared with eeprom keywaord like above is with flash. code snippet isCode:eeprom uint32_t eGuard @ 0x01;eeprom uint8_t bootLoader @ BOOTLOADER_FLAG_ADDR; /* this has to be at this address in order for the bootloader to work! */eeprom bool eIsDemo @ 0x06;eeprom bool readerMode @ 0x07;eeprom uint32_t eLifeSwipes @ 0x08;eeprom uint32_t eTotalSwipes @ 0x0c;eeprom uint8_t failedLogins @ 0x10;eeprom uint8_t failedDemoTries @ 0x11;eeprom char serialNumber[sizeof(BUILD)] @ 0x12;eeprom char demoPass @ 0x19;Question Number 3:This code also has some assembly code. With the #asm and #asmendCode:void aes_decrypt( uint8_t *aes_crypted, uint8_t *aes_raw ){#asmsave_registers ; save registers into stackldd r27,y+1 ; msb raw bufferldd r26,y+0 ; lsb raw bufferldd r25,y+3 ; msb crypted bufferldd r24,y+2 ; lsb crypted bufferldi R22,LOW(_expanded_key_buffer)ldi R23,HIGH(_expanded_key_buffer)mov ZH,r25mov ZL,r24ld ST11, Z+ld ST21, Z+ld ST31, Z+ld ST41, Z+ld ST12, Z+ld ST22, Z+ld ST32, Z+ld ST42, Z+ld ST13, Z+ld ST23, Z+ld ST33, Z+ld ST43, Z+ld ST14, Z+ld ST24, Z+ld ST34, Z+ld ST44, Z+; -------------------- decode -----------------------ldi YL, $b0 ; initialize YH:YL to point BEHIND $b0 = 176ldi YH, $00add YL, r22 ; decryption key material andadc YH, r23rcall decrypt ; call decryption routine; now the registers ST11-ST44 contain the plaintext again; ------------ store - just for checking. delete after proven ok -----------mov ZH,r27 ; store the text into raw text buffermov ZL,r26st Z+, ST11st Z+, ST21st Z+, ST31st Z+, ST41st Z+, ST12st Z+, ST22st Z+, ST32st Z+, ST42st Z+, ST13st Z+, ST23st Z+, ST33st Z+, ST43st Z+, ST14st Z+, ST24st Z+, ST34st Z+, ST44; --------------- end decode -------------------------restore_registers ; restore registers from stackADIW R28,4 ; in CVAVR we have to add the number of bytes received as paramettersret;;; ***************************************************************************;;;;;; DECRYPT;;; This routine decrypts a 128 bit ciphertext block (given in ST11-ST44),;;; using an expanded key supplied in the 16*11 memory locations BEFORE YH:YL;;; (YH:YL points behind the last byte of the key material!). The resulting 128;;; bit plaintext block is stored in ST11-ST44.;;;;;; Parameters:;;; YH:YL: pointer behind key;;; ST11-ST44: 128 bit ciphertext block;;; Touched registers:;;; ST11-ST41,H1,I,ZH,ZL,YH,YL;;; Clock cycles: 3579decrypt:ldi I, 10sbiw YL,16rcall addroundkey ; AddRoundKeysbiw YL,32decryp1:ldi ZH, high(isbox<<1) ; SubBytes + ShiftRowsmov ZL, ST11lpm ST11, Zmov ZL, ST12lpm ST12, Zmov ZL, ST13lpm ST13, Zmov ZL, ST14lpm ST14, Zmov H1, ST21mov ZL, ST24lpm ST21, Zmov ZL, ST23lpm ST24, Zmov ZL, ST22lpm ST23, Zmov ZL, H1lpm ST22, Zmov H1, ST33mov ZL, ST31lpm ST33, Zmov ZL, H1lpm ST31, Zmov H1, ST34mov ZL, ST32lpm ST34, Zmov ZL, H1lpm ST32, Zmov H1, ST41mov ZL, ST42lpm ST41, Zmov ZL, ST43lpm ST42, Zmov ZL, ST44lpm ST43, Zmov ZL, H1lpm ST44, Zrcall addroundkey ; AddRoundKeysbiw YL,32dec Ibrne PC+2retldi ZH, high(xtime<<1) ; preprocessing to use MixColumnsmov ZL, ST11eor ZL, ST31lpm H2, Zmov ZL, H2lpm H1, Zmov ZL, ST21eor ZL, ST41lpm H2, Zmov ZL, H2lpm H2, Zeor ST11, H1eor ST21, H2eor ST31, H1eor ST41, H2mov ZL, ST12eor ZL, ST32lpm H2, Zmov ZL, H2lpm H1, Zmov ZL, ST22eor ZL, ST42lpm H2, Zmov ZL, H2lpm H2, Zeor ST12, H1eor ST22, H2eor ST32, H1eor ST42, H2mov ZL, ST13eor ZL, ST33lpm H2, Zmov ZL, H2lpm H1, Zmov ZL, ST23eor ZL, ST43lpm H2, Zmov ZL, H2lpm H2, Zeor ST13, H1eor ST23, H2eor ST33, H1eor ST43, H2mov ZL, ST14eor ZL, ST34lpm H2, Zmov ZL, H2lpm H1, Zmov ZL, ST24eor ZL, ST44lpm H2, Zmov ZL, H2lpm H2, Zeor ST14, H1eor ST24, H2eor ST34, H1eor ST44, H2rcall mixcolumns ; MixColumnsrjmp decryp1#endasm}

author: wek
author_rank: Frequent Contributor
timestamp: April 06, 2023, 07:41:40 am
content: This is not written for avr-gcc, which is the compiler AVRStudio6 uses.This appears to be CodeVisionhttp://www.hpinfotech.ro/cvavr-features.htmlJW

author: darkspr1te
author_rank: Frequent Contributor
timestamp: April 06, 2023, 07:50:50 am
content: you dont say what the actual problems your are having (eg actual compiler/build error or crash in code)Also your questions are more statements of your belief and not actual questions but am going to assume a few things and maybe have a answerin code snippet 1 and 2 your refer to __flash labels and __eeprom labels, these tell the build environment where that data is stored, in flash along with code or on emulated eeprom (or physical) requiring it be read into ram and additional processes (like talking to the i2c/spi bus) , both having different needs ,in flash it's faster but read only, in eeprom it's read/write and in ram it's read/write but lost at power off.in snippet 3 you point out that the assembly is between #asm and #asmend, this is correct as it tells the build environment to not treat it as c/C++ but assembly inline. while faster you have to manually push/pop your registers and handle your own stackAlso there are different build environments and compilers out there, avr-gcc is just one but is used by arduino and avrstudio and often each has it's own format for how it handles inline commands and build instructions.hope this helpsdarkspr1te

author: arslan43711
author_rank: Contributor
timestamp: April 06, 2023, 08:07:54 am
content: Its an open source codehere is the link of the github repositoryhttps://github.com/cardreaderfactory/v007Its has .cproj and .prj files due to which it looks like a Atmel sutdio project. But it does not recognize the #asm preprocessor directives

author: arslan43711
author_rank: Contributor
timestamp: April 06, 2023, 08:15:27 am
content: Quote from: darkspr1te on April 06, 2023, 07:50:50 amI am having build errors. Not able to compile the code.here are the acutal eerors thrown by the compilerCode:Error1unknown type name 'flash'Error4unknown type name 'eeprom'Error13invalid preprocessing directive #asm

author: darkspr1te
author_rank: Frequent Contributor
timestamp: April 06, 2023, 10:41:37 am
content: When ever i has issues like this i setup a vm and install the next version of the software, in one of the files it shows v6.2 as the version that created it, so maybe try v6.2sp1 or v7 as the later version may support that inline build command (i did not find it mentioned in the v6.1 pdfs that i have)darkspr1te

author: voltsandjolts
author_rank: Unknown
timestamp: April 06, 2023, 10:51:10 am
content: Quote from: arslan43711 on April 06, 2023, 08:15:27 amThose errors mean you are using the wrong compiler.Like wek said above, you need to use thecodevision compileror port the code to the compiler you are using (avr-gcc).

author: arslan43711
author_rank: Contributor
timestamp: April 06, 2023, 10:58:45 am
content: Yes Wek is right, the code is written with CodeVision. I am not getting those errors now but getting some new one. Will share those shortly.

author: T3sl4co1l
author_rank: Super Contributor
timestamp: April 06, 2023, 11:30:38 am
content: If it's from a public git, why not contact the author who surely knows how they built it?Offhand, changing the type identifiers should work. See:https://onlinedocs.microchip.com/pr/GUID-78362176-487F-41B9-95C7-B478A9A186EB-en-US-2/index.html?GUID-E8E50411-4A61-4C7B-A8FD-7E07E93F6DDEWhether there are any other differences, who knows.Tim

author: arslan43711
author_rank: Contributor
timestamp: April 06, 2023, 11:42:24 am
content: Author's GitHub account is inactive. Last commit on this repository is from 2018, maybe five years ago. That's why I did posted the question here.