Pages: [1] 2   Go Down
Author Topic: AVR MacPack or CrossPack for Macintosh  (Read 3189 times)
0 Members and 1 Guest are viewing this topic.
France
Offline Offline
Sr. Member
****
Karma: 0
Posts: 262
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

When I lauch file:///Applications/arduino-0015/hardware/tools/avr/manual/installation.html it says I can install AVR MacPack by double-click AVR MacPack.pkg but where is MacPack.pkg ?

I've downloaded arduino15 then compiling, running,... everything works but when I search MacPack on my disk, i found  :'(
« Last Edit: June 16, 2009, 12:05:48 pm by selfonlypath » Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 118
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That file doesn't exist in Arduino-16... I'm betting it was a mistake, it's likely that the Arduino IDE uses parts of CrossPack and accidently included that file.

"CrossPack" is just the AVR gcc toolchain compiled for OSX. "AVR MacPack" is the old name for CrossPack (trademark problem). You can download CrossPack from http://www.obdev.at/products/crosspack/index.html , but you don't need it unless you want to develop outside of the Arduino IDE.
Logged

France
Offline Offline
Sr. Member
****
Karma: 0
Posts: 262
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

OK I see so it looks like this file does not exist either on arduino15.

On another thread, two members suggested I use [size=14]avr-objdump[/size] to dissambly and optimize my arduino code.

I can see & go to /Applications/arduino-0015/hardware/tools/avr/bin/avr-objdump but how do I launch avr-objdump - S on my sketch.elf which is stored on another directory ?


Can someone help on this & tell me if I need to dowload CrossPack to run easiy avr-objdump ?

Thank you in advance
Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 118
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You will need to know a fare bit about assembly to make any sense of the output, but to run it you would open Terminal and type something like "/Applications/arduino-0016/hardware/tools/avr/bin/avr-objdump -d AVR_EXEC.elf" where AVR_EXEC.elf is the elf executable.

Where the elf executable is placed changed in the Arduino-16 IDE. The easiest way to find it is to intentionally create a linking error.
Code:
SIGNAL(USART_RX_vect){}
void setup() {
    Serial.begin(1000000);
    ...
}

Redefining the USART_RX_vect interrupt will throw an error like:
Code:
/var/folders/IL/IL-Z8iI2FtCrO5IKr63SCE+++TI/-Tmp-/build1409329740626090124.tmp/core.a(HardwareSerial.cpp.o): In function `__vector_18':
This would mean I can find the elf in "/var/folders/IL/IL-Z8iI2FtCrO5IKr63SCE+++TI/-Tmp-/build1409329740626090124.tmp/". Arduino-15 and lower use an "applet" folder, so it's not as crazy a location.

So the command I would put into Terminal is:
Code:
/Applications/arduino-0016/hardware/tools/avr/bin/avr-objdump -d /var/folders/IL/IL-Z8iI2FtCrO5IKr63SCE+++TI/-Tmp-/build1409329740626090124.tmp/sketch_090608a.elf

Remember, the elf doesn't exist unless your code compiles successfully.

What are you trying to optimize? I doubt this is really what you want.
« Last Edit: June 16, 2009, 06:45:16 pm by gabebear » Logged

France
Offline Offline
Sr. Member
****
Karma: 0
Posts: 262
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Many thanks for explanation.

How about if i copy-paste my file.elf locally into where avr-objdump resides ?

Otherwise, there is no easy SDK on Mac ?

Regarding what i'm trying to optimize, please look at this thread where 2 members suggested I use avr-objump, in particular reply #21 and #24:
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1230286016/15

Also this thread:
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1244864818
Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 118
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you are only interested in little snippets of assembly then you want to look at the ".o" object files for each source file. The code in the ".o" files is the intermediate code used to generate the final executable. This intermediate code won't necessarily make it into the final executable, but it is easier to understand.

Example:
---------

If I compile
Code:
void setup() {
        // UCSR0A is defined as (*(volatile uint8_t *)(0x00C0))
        UCSR0A=0x09;
}
void loop() {}
and then run
Code:
avr-objdump -d Temporary_6746_1374.cpp.o
I get
Code:
Temporary_6746_1374.cpp.o:     file format elf32-avr


Disassembly of section .text.setup:

00000000 <setup>:
   0:      89 e0             ldi      r24, 0x09      ; 9
   2:      80 93 c0 00       sts      0x00C0, r24
   6:      08 95             ret

Disassembly of section .text.loop:

00000000 <loop>:
   0:      08 95             ret

Disassembly of section .text.main:

00000000 <main>:
   0:      0e 94 00 00       call      0      ; 0x0 <main>
   4:      89 e0             ldi      r24, 0x09      ; 9
   6:      80 93 c0 00       sts      0x00C0, r24
   a:      00 c0             rjmp      .+0            ; 0xc <__zero_reg__+0xb>
from which I can see exactly what's going on.
  • The ".text.setup:" has the interesting bits
  • 9 is loaded into register 24
  • the contents of register 24 is assigned to the memory address at UCSR0A(which is 0x00C0).
  • the loop() was empty, so the ".text.loop:" section is empty
  • The Arduino IDE adds a main() to your program, which is the ".text.main:" section. main() calls setup() and then calls loop() in an infinite loop.The compiler chose to smash the setup() and loop() functions together here. This is an example of a simple optimization the compiler may or may not make.
If you look at the output from
Code:
avr-objdump -d sketch_090608a.elf
the "<main>:" section is very similar to the assembly from the ".text.main:" section of the other object file except that it first calls to a large initialization function and uses a slightly different infinite loop. The code in the elf file is what is actually being executed on the Arduino.

More complicated programs will be much harder to step through. The compiler can/will make optimizations that make the assembly VERY hard to follow. If you are needing to optimize down to this level you are probably better off using inline assembly so that the compiler doesn't optimize the code differently.
Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 118
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you install CrossPack, you don't have to worry about where avr-objdump resides, it will be added to your PATH so you can run it from anywhere. CrossPack's AVR toolchain is kept more current than what is included with the Arduino IDE.

I don't use the Arduino IDE much. There are at least two other good IDEs you can use for the Arduino with OSX.
  • CrossPack comes with an XCode template, so you can use XCode to write programs. I created a better XCode template for CrossPack than the one included with CrossPack, I'll post it if you want. When you click on compile errors using my template XCode will jump to the correct location in the source files.
  • Eclipse has an AVR plugin which is pretty bad-ass. There are instructions on the Arduino site for setting up Eclipse with the AVR plugin. Installing the Eclipse AVR stuff is harder than it should be, but I think it's the best option. I'm going to write an up-to-date tutorial on how to set this up soon.
The nice thing about the default Arduino IDE is that it is stupidly simple to get going and the same everywhere.

The Eclipse IDE with the AVR plugin will create a .lss file everytime you compile, which has the assembly of your program. The CrossPack makefile for XCode will dump the assembly if you run "make disasm". You could easily adjust it to always generate the assembly.
« Last Edit: June 16, 2009, 06:43:37 pm by gabebear » Logged

SF Bay Area (USA)
Offline Offline
Tesla Member
***
Karma: 137
Posts: 6805
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It depends on how comfortable you are using the command line interface in MacOS ("Terminal.app")
I just explicitly run the binaries from the arduino directories:
Code:
BillW-MacOSX-2<1041> cd ~/Documents/Arduino/tones/applet/
BillW-MacOSX-2<1042> /Applications/arduino/arduino-0014/hardware/tools/avr/bin/avr-objdump  -S *.elf > foo.S
BillW-MacOSX-2<1043>
I have the shell set up to save command history, so there's pretty much always an "objdump" in there somewhere, and I can get the command back using the "reverse search for objdump" sort of CLI feature.  But then I've been using unix CLIs since before there was any alternative :-)
« Last Edit: June 16, 2009, 07:03:47 pm by westfw » Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 118
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

http://www.ghearing.com/AVR.zip

Here is my XCode template.
  • It doesn't create .o files, it goes straight to .elf then to .hex
  • It's C only, no C++, should be easy to change if you want C++
  • compile-errors are clickable
  • "Jump to definition" only works for stuff in the project (not avr-libc/standard headers)
  • "Find Selected Text in Project" will search avr-libc and the standard headers from CrossPack. The links in the project are relative to "/usr/local/CrossPack-AVR/" so they won't break between revisions of CrossPack
  • looks for source files in all directories in the project one level deep.
  • Change build-settings in XCode by modifying the "Run Makefile" target. Set your CPU, Mhz, baud-rate, and Serial-Port in here. Project->"Edit Active Target".
  • Command-B will build the project
  • Command-R will upload the project to the Arduino
http://www.ghearing.com/AVR.zip
You need to install CrossPack and XCode...

UPDATE: Thinking about the build-settings...  putting them in XCode was a bad idea. The settings aren't shared between uploading and compiling...
« Last Edit: June 16, 2009, 07:25:32 pm by gabebear » Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 118
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I just downloaded the latest CrossOver beta version, and AVR Studio 4 seems to work now!



This is the CrossOver 8.0 beta, the final version should be out soon.
Logged

France
Offline Offline
Sr. Member
****
Karma: 0
Posts: 262
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

hello gabebear,

yeah, my plan is to use Xcode which seems te be freely avalaible on new Mac sold now but not sure if i'm gonna buy one for the moment. My plan is still develop dedicated Hyperterminal controlling my arduino board because arduino Serial Terminal is not very practical but it helps me discover arduino.

what is best strategy to dowload & install Xcode on my actual Mac ?

I'm gonna 1st download CrossPack to see how it goes.

If you have any info about Xcode, arduino, dsissambly, whatever, please do share if you're ok..

hello westfw,

I'm ok with using basic commands on Mac Terminal because I used to develop back 20 years ago on Unix Sun Station. It just just that I bumped into many contradictions while looking on arduino applications files as discussed previously.
« Last Edit: June 16, 2009, 10:01:36 pm by selfonlypath » Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 118
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Everything is free.

  • XCode - Apple's IDE, Primarily focused on Objective-C, but also supports C, C++, Java, and more.
  • It's included on the CDs/DVDs that come with every Mac since 2003, although it's not installed by default.
  • You can download it from http://developer.apple.com/mac/ , but you have to sign up for a free Apple developer account
  • Get "Eclipse IDE for C/C++ Developers" from http://www.eclipse.org/downloads/
  • This isn't the easiest thing to install, especially if you aren't familiar with Eclipse or the gcc toolchain.
  • AVR Studio - Amtel has a free IDE for their AVR chips (the Arduino is AVR based). It's available from http://www.atmel.com/dyn/products/tools_card.asp?tool_id=2725 but it's Windows only. It does run fine in Parallels and VMWare. Soon it will hopefully run in Wine on OSX. It might be worth packaging this up as a ready-made OSX app.

Crossover is a commercial version of Wine ( http://wiki.winehq.org/MacOSX ), but Wine is available for free via MacPorts ( http://www.macports.org/ ). Crossover does make Wine more user-friendly on OSX. One big thing Crossover does is guarantee compatibility with certain software.
« Last Edit: June 16, 2009, 10:51:42 pm by gabebear » Logged

France
Offline Offline
Sr. Member
****
Karma: 0
Posts: 262
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I've been able to dissamble as suggested by westfw in reply #7 so I might for the moment just use avr-objdump to quick understand how critical time cycling is implemented.

It is not that my project is really big but is there a way to tell avr-objdump to only dissamble part of my sketch.elf (i.e.  a specific subroutine) because I get a huge file so takes me a while to find in the file my loop() with critical fast PWM call out ?

Many thx to all of you
Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 118
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

No, disassembling a specific subroutine in a optimized executable is not possible. Disassembling the .o files will give you assembly for each subroutine that is somewhat optimized, but that assembly is not necessarily what will end up in the final executable. If you want to account for every CPU cycle/instruction, you have to go sifting through the assembly of the final optimized executable.



Simplified Example:

Assuming we are interested in the hello() function:

If this was the orignal code:
Code:
int i = 0;
void printg(char *msg) {
      for(int j=0;j<5;j++) UDR0=msg[j];
}
void hello() {
      printg("Hello");
      i++;
}
void world() {
      printg("World");
      i++;
}
void setup() {
      hello();
      world();
}
void loop() {}

The code in the .o file would resemble:
Code:
int i = 0;
void printg(char *msg) {
      for(int j=0;j<5;j++) UDR0=msg[j];
}
void hello() {
      const char msg[] = "Hello";
      for(int j=0;j<5;j++) UDR0=msg[j];
      i++;
}
void world() {
      const char msg[] = "World";
      for(int j=0;j<5;j++) UDR0=msg[j];
      i++;
}
void setup() {
      const char msg[] = "HelloWorld";
      for(int j=0;j<10;j++) UDR0=msg[j];
      i+=2;
}
void loop() {}
void main() {
      const char msg[] = "HelloWorld";
      for(int j=0;j<10;j++) UDR0=msg[j];
      while(TRUE);
}

The code in the .elf would resemble:
Code:
void main() {
      const char msg[] = "HelloWorld";
      for(int j=0;j<10;j++) UDR0=msg[j];
      while(TRUE);
}

 So in the end the assembly for the hello() function doesn't bear much resemblance to the code that is going into the final executable.
« Last Edit: June 17, 2009, 02:29:16 pm by gabebear » Logged

France
Offline Offline
Sr. Member
****
Karma: 0
Posts: 262
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Many thx for teaching me efficient design & methodology (C with assembly) in Macintosh context for my project.

From what I read in the forum, i'll stick for the moment with arduino15 & continue my project.

Amicalement, Albert
Logged

Pages: [1] 2   Go Up
Jump to: