Hi everybody,
I am using Arduino0018 IDE .
I want to execute my code for different optimizations(all -O0,-O1,O2,O3 and Os)
Can anybody pls tell me the way to do so.
Thanks in advance
Hi everybody,
I am using Arduino0018 IDE .
I want to execute my code for different optimizations(all -O0,-O1,O2,O3 and Os)
Can anybody pls tell me the way to do so.
Thanks in advance
Hi all,
I have an idea.
I should first create .hex file using avr-gcc from command line , there i can specify -O options
Then i upload it using avrdude also from command line.
Then i open my serial monitor.
Here i am having 2 doubts:
First my code is using Serial.print and micros() . So when i compile from command line , i need to include the files in which these functions are defined. But i don't have any idea which files i should include. By the way I have arduino0018
Second thing, i am not sure that after uploading from command prompt, if i run arduino IDE and open Serial Monitor , i will see the print statements
Please help me out if there is some other way!!
--Arpan
Basically following is my code and i want to run it with different optomisations
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <avr/pgmspace.h>
#include "cubehash.h"
long startTime ; // start time for stop watch
long elapsedTime ; // elapsed time for stop watch
int fractional; // variable used to store fractional part of time
void setup(){
Serial.begin(9600);
int ret_val;
Serial.println("start");
ret_val=genShortMsg(224);
}
void loop()
{
}
STATUS_CODES
genShortMsg(int hashbitlen)
{
int msglen, msgbytelen;
BitSequence Msg[1011], MD[64];
msglen=8083;
msgbytelen = (msglen+7)/8;
int ch, started;
BitSequence ich;
int i;
if ( msgbytelen == 0 ) {
Msg[0] = 0x00;
}
Serial.println(msgbytelen);
Serial.println("reached 1");
memset(Msg, 0x00, msgbytelen);
Serial.println("reached 2");
started = 0;
static char str[] PROGMEM= "14B06DD54EB364";
for(j=0;j<strlen(str);j++){
ch=pgm_read_byte(&(str[j]));
if ( (ch >= '0') && (ch <= '9') )
ich = ch - '0';
else if ( (ch >= 'A') && (ch <= 'F') )
ich = ch - 'A' + 10;
else if ( (ch >= 'a') && (ch <= 'f') )
ich = ch - 'a' + 10;
for ( i=0; i<msgbytelen-1; i++ )Msg[i] = (Msg[i] << 4) | (Msg[i+1] >> 4);
Msg[msgbytelen-1] = (Msg[msgbytelen-1] << 4) | ich;
}
Serial.println("");
startTime = micros();
Hash(hashbitlen, Msg, msglen, MD);
elapsedTime = micros() - startTime;
// store buttonState in lastButtonState, to compare next time
Serial.print( (long )(elapsedTime / 1000000L)); // divide by 1000000 to convert to seconds - then cast to an int to print
Serial.print("."); // print decimal point
// use modulo operator to get fractional part of time
fractional = (long)(elapsedTime % 1000000L);
if (fractional == 0)
Serial.print("000000"); // add six zero's
else if (fractional < 10) // if fractional < 10 the 0 is ignored giving a wrong time, so add the zeros
Serial.print("00000"); // add 5 zeros
else if (fractional < 100)
Serial.print("0000"); // add 4 zero
else if (fractional < 1000)
Serial.print("000");
else if (fractional < 10000)
Serial.print("00");
else if (fractional < 100000)
Serial.print("0");
Serial.println(fractional); // print fractional part of time
Serial.println("");
for(i=0;i<hashbitlen/8;++i){
if(MD[i] < 16){
Serial.print(0,HEX);
Serial.print(MD[i],HEX);
}
else{
Serial.print(MD[i],HEX);
}
}
Serial.println("");
return KAT_SUCCESS;
}
////////////////////////
Ok so nobdy wants to help me!!
What i did:
1.I rename the my .pde file to .c file.
2.Create a new folder and add my C code and all the files in the folder
\arduino-0018\hardware\arduino\cores\arduino
3.Then i include "WProgram.h" on the top my C file that contains void setup()
4.I tried the foolowing command
avr-gcc -mmcu=atmega328p -Wall -Os -DF_CPU=20000000 -I./ -o cubehash.out genKAT.c cubehash.h WProgram.h
genKAT.c and cubehash.h are my files
But now i am getting error
'Serial' undeclared(first use in this function)
PLEASE atleast tell me if there is a way or its not possible to
"compile the C code containing HardwareSerial functions like Serial.print() from commandprompt , then uploading from commandprompt and then got the result (of print statements)back on serial monitor or console"
hi GodMembers,
any suggestions?
There is no way to do this from the IDE.
Hold down the shift-key and click verify inside IDE to show the calls made to avr-gcc.
Eberhard
@Wayoda
Thanks a lot!
I am looking at the compile log(actually there are many commands, not just 2 or 3) and trying to figure out the solution.
Meanwhile, if i execute those commands(that i see in the log) , then where can i see the serial output on the monitor.(because i will be executing the commands from prompt, then there is no monitor associated).
Also , please tell me if there is a cleaner way to execite my code with different optimizations and measure the time.
Warm Regards,
--Arpan
I looked at the command log and try to execute all those commands from command line.
But, i got stuck in the 3rd last command.
4th last command
C:/Users/arpan/Desktop/arduino-0018/arduino-0018/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=18 -IC:/Users/arpan/Desktop/arduino-0018/arduino-0018/hardware/arduino/cores/arduino C:/Users/arpan/AppData/Local/Temp/build742897174907760180.tmp/sketch_jun02a.cpp -oC:/Users/arpan/AppData/Local/Temp/build742897174907760180.tmp/sketch_jun02a.cpp.oand
3rd last commad
C:/Users/arpan/Desktop/arduino-0018/arduino-0018/hardware/tools/avr/bin/avr-gcc -Os -W1,--gc-sections -mmcu=atmega328p -o C:/Users/arpan/AppData/Local/Temp/build742897174907760180.tmp/sketch_jun02a.cpp.elf C:/Users/arpan/AppData/Local/Temp/build742897174907760180.tmp/sketch_jun02a.cpp.o C:/Users/arpan/AppData/Local/Temp/build742897174907760180.tmp/core.a -LC:/Users/arpan/AppData/Local/Temp/build742897174907760180.tmp -lm
i got an error like
C:/Users/arpan/AppData/Local/Temp/build742897174907760180.tmp/core.a(Print.cpp.o
):(.rodata._ZTV5Print+0x4): undefined reference to `__cxa_pure_virtual'
why these command are executed correctly by arduino IDE, and not by command line
Hi,
I compiled using arduino and then took .elf file and convert it into hex file successfully. then i uploaded it using avrdude and got the result of print statements on monitor successfully.
The only place i am stuck at is 3rd last step. Please help me to get it correct so that i can test my program with different optimizations
Hi guys,
Finally, i got succeded.
I took Wayoda's advice and looked at the compile log of arduino IDE and executed the commands with the desired optimization mode.
Also at one point , i got error "undefined reference to "'__cxa_pure_virtual" . To get rid of this , i included
extern "C" void __cxa_pure_virtual()
{
while (1);
}
in my code .
and then uploaded it using avrdude from command prompt and got the result back on Serial monitor of avrdude.
--Arpan