Command-line build with Atmel Studio 7

Go To Last Post
8 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

 

I'm trying to make command-line build working properly with AS7 (running Win7, 64-bit). I've tried two solutions, but none of them work quite right.

 

1. atmelstudio.exe

I did as instructed on this page: https://avrstudio5.wordpress.com/2012/05/08/build-atmelstudio-projects-from-command-line/

c:\EXAMPLE1> atmelstudio.exe EXAMPLE1.cproj /build debug /out foo.txt

I could even replace EXAMPLE1.cproj with *.cproj, and it would automatically build whatever it found in the working directory. Brilliant!

However, the output can apparently only be sent to a text file, which means that my text editor can't capture it. I have found no way to direct the output to console. If this can be done, I guess that the problem is solved.

 

2. make.exe

I found this advice from Cliff, which apparently works in AS6: https://www.avrfreaks.net/forum/build-atmel-studio-project-command-line

In short, I must make paths to make.exe and avr-gcc.exe, and then run make -f in the working directory. Well, it doesn't work directly in AS7 (at least not in my installation), but I can make it work if I replace -f with the target name.

 

[Source path]\Debug make.exe [Target name]

 

This works, and my text editor can capture the output. But I obviously can't create a generic, permanent user tool that just runs make.exe on any project that I have decided to open. I need to change the target name when I switch between projects. OK, I can probably live with that, but it would be nice to have it working properly.

 

If I don't specify a target name, the compiler just tries to compile the first .c file it stumbles upon in the makefile, and leaves it at that. So I guess that AS7 has left something out in the makefile (the target name?), but I can't figure out how to put it there. Anyone?

 

I can't believe that I'm the only one trying to do this, but I haven't been able to find anything about it. Probably using the wrong search parameters...

 

3. Just to mention it (before anyone else does): The third solution is to keep Atmel Studio 7 open in parallel with the text editor, and then just use AS7 for building. But then solution 2 is better by far.

 

Does anyone have THE optimal solution, to end all other solutions?

 

Best regards

ErikT

 

You're absolutely right. This member is stupid. Please help.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Why would you want to build at the command line? is this for night-time or per-commit costant integration or similar?

 

The solution in the Visual Studio world is actually "msbuild". I don't knw if the equivalent of that is supplied with Studio 7 but it would be the way to do it if you just want to be able to say "build this .atsln"

 

If this is for unattended building then clearly solutions that involve invoking the "Command Prompt" option from the Tools menu in AS7 aren't really a runner anyway.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Why would you want to build at the command line? is this for night-time or per-commit costant integration or similar?

I'm not sure I understand the second part of the question. But in short, I really don't like the AS7 interface. At all. Including the editor. Besides, I've never seen the point in using a fancy graphical IDE for simple 8-bit products. It was a relief when my former company moved from PIC17 and the IAR compiler to AVR and gcc.

 

But clearly, AS7 can build a project at command line. It just throws the output in a text file, rather than to the console. In my limited understanding of the world, this should've been an easy fix.

 

Btw Cliff - your own picture on this forum builds at command line... wink

You're absolutely right. This member is stupid. Please help.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

EDIT: Forget what I wrote about *.cproj working with atmelstudio.exe. I thought I saw it working, but it seems that I was mistaken. Back to square 1.
 

You're absolutely right. This member is stupid. Please help.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ErikT wrote:
Besides, I've never seen the point in using a fancy graphical IDE for simple 8-bit products.
Emacs for me after I fumbled my learning of vi.

IDE do have features like GUI interfaces to lint, make, GDB, etc.

PlatformIO wraps the AVR GCC toolchain in Python but it's not the Atmel AVR toolchain.


https://github.com/platformio/platformio-examples/blob/develop/atmelavr-and-arduino/atmelavr-native-blink/README.rst

http://docs.platformio.org/en/stable/ide.html (Note: Emacs, VIM)

http://docs.platformio.org/en/stable/ci/index.html (Continuous Integration)

 

"Dare to be naïve." - Buckminster Fuller

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

But if this is just about building at the command line then why not start a command prompt from within AS7. Type "PATH" and note the directories that AS7 has added to the normal PATH (that are the location of "make" and "avr-gcc" etc). Take those directory names and just add them to your system wide environment variables. Now, whenever you start ANY Command Prompt it will have a path to the avr-gcc and other tools in AS7.

 

Now forget you ever installed AS7 as all and just use Makefile's (perhaps created by Mfile) and work that way. Use your own choice of editor to edit the .c/.cpp/.h (Notepad++ is often a good choice) and then "make" to build the code.

 

Yet another way is to forget AS7 all together. There is a much newer version of the compiler for download here:

 

http://gnutoolchains.com/download/

 

That gives you a 5.3 but note that this is not from the Atmel development tree so it won't have support for quite so many model of AVR just yet (Atmel are pushing their stuff back so one day this will be the same!). Set a path to c:\SysGCC\avr\bin and then you can do things like this:

C:\foo>avr-gcc -v 2>&1 | grep version
gcc version 5.3.0 (GCC)

C:\foo>nano avr.c

C:\foo>type avr.c
#define F_CPU 8000000UL
#include <avr/io.h>
#include <util/delay.h>

int main(void) {
        DDRB = 0xFF;
        while(1) {
                PORTB ^= 0xFF;
                _delay_ms(100);
        }
}

C:\foo>avr-gcc -mmcu=atmega16 -Os -g avr.c -o avr.elf

C:\foo>avr-objdump -S avr.elf

avr.elf:     file format elf32-avr

Disassembly of section .text:

00000000 <__vectors>:
   0:   0c 94 2a 00     jmp     0x54    ; 0x54 <__ctors_end>
   4:   0c 94 34 00     jmp     0x68    ; 0x68 <__bad_interrupt>
   8:   0c 94 34 00     jmp     0x68    ; 0x68 <__bad_interrupt>
   c:   0c 94 34 00     jmp     0x68    ; 0x68 <__bad_interrupt>
  10:   0c 94 34 00     jmp     0x68    ; 0x68 <__bad_interrupt>
  14:   0c 94 34 00     jmp     0x68    ; 0x68 <__bad_interrupt>
  18:   0c 94 34 00     jmp     0x68    ; 0x68 <__bad_interrupt>
  1c:   0c 94 34 00     jmp     0x68    ; 0x68 <__bad_interrupt>
  20:   0c 94 34 00     jmp     0x68    ; 0x68 <__bad_interrupt>
  24:   0c 94 34 00     jmp     0x68    ; 0x68 <__bad_interrupt>
  28:   0c 94 34 00     jmp     0x68    ; 0x68 <__bad_interrupt>
  2c:   0c 94 34 00     jmp     0x68    ; 0x68 <__bad_interrupt>
  30:   0c 94 34 00     jmp     0x68    ; 0x68 <__bad_interrupt>
  34:   0c 94 34 00     jmp     0x68    ; 0x68 <__bad_interrupt>
  38:   0c 94 34 00     jmp     0x68    ; 0x68 <__bad_interrupt>
  3c:   0c 94 34 00     jmp     0x68    ; 0x68 <__bad_interrupt>
  40:   0c 94 34 00     jmp     0x68    ; 0x68 <__bad_interrupt>
  44:   0c 94 34 00     jmp     0x68    ; 0x68 <__bad_interrupt>
  48:   0c 94 34 00     jmp     0x68    ; 0x68 <__bad_interrupt>
  4c:   0c 94 34 00     jmp     0x68    ; 0x68 <__bad_interrupt>
  50:   0c 94 34 00     jmp     0x68    ; 0x68 <__bad_interrupt>

00000054 <__ctors_end>:
  54:   11 24           eor     r1, r1
  56:   1f be           out     0x3f, r1        ; 63
  58:   cf e5           ldi     r28, 0x5F       ; 95
  5a:   d4 e0           ldi     r29, 0x04       ; 4
  5c:   de bf           out     0x3e, r29       ; 62
  5e:   cd bf           out     0x3d, r28       ; 61
  60:   0e 94 36 00     call    0x6c    ; 0x6c <main>
  64:   0c 94 45 00     jmp     0x8a    ; 0x8a <_exit>

00000068 <__bad_interrupt>:
  68:   0c 94 00 00     jmp     0       ; 0x0 <__vectors>

0000006c <main>:
#define F_CPU 8000000UL
#include <avr/io.h>
#include <util/delay.h>

int main(void) {
        DDRB = 0xFF;
  6c:   8f ef           ldi     r24, 0xFF       ; 255
  6e:   87 bb           out     0x17, r24       ; 23
        while(1) {
                PORTB ^= 0xFF;
  70:   88 b3           in      r24, 0x18       ; 24
  72:   80 95           com     r24
  74:   88 bb           out     0x18, r24       ; 24
        #else
                //round up by default
                __ticks_dc = (uint32_t)(ceil(fabs(__tmp)));
        #endif

        __builtin_avr_delay_cycles(__ticks_dc);
  76:   2f ef           ldi     r18, 0xFF       ; 255
  78:   80 e7           ldi     r24, 0x70       ; 112
  7a:   92 e0           ldi     r25, 0x02       ; 2
  7c:   21 50           subi    r18, 0x01       ; 1
  7e:   80 40           sbci    r24, 0x00       ; 0
  80:   90 40           sbci    r25, 0x00       ; 0
  82:   e1 f7           brne    .-8             ; 0x7c <main+0x10>
  84:   00 c0           rjmp    .+0             ; 0x86 <main+0x1a>
  86:   00 00           nop
  88:   f3 cf           rjmp    .-26            ; 0x70 <main+0x4>

0000008a <_exit>:
  8a:   f8 94           cli

0000008c <__stop_program>:
  8c:   ff cf           rjmp    .-2             ; 0x8c <__stop_program>

C:\foo>

That seems to successfully have built code that is something like my avatar for the mega16. Of course this is doing it in the most raw form. I just typed a direct avr-gcc command there to both compile and link the code. Usually I would do something like:

C:\foo>type Makefile
avr.elf: avr.c
        avr-gcc -mmcu=atmega16 -Os -g2 $< -o $@
C:\foo>\SysGCC\avr\bin\make
avr-gcc -mmcu=atmega16 -Os -g2 avr.c -o avr.elf

C:\foo>

But even that is a stupidly short Makefile (two lines) and does not encompass all the build rules I would really like to use. I'd like to really to separately compile each and every .c file to .o and then a final step where it invokes the linker to join the .o files. Followed by steps to use avr-objcopy to extract .hex from .elf and so on. For all that I would probably take a short-cut and use Mfile to create it for me.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Oh and yet another way. Forget Windows. Install VMware or VirtualBox and within that Ubuntu then get and install the avr-gcc compiler in that. This is my preferred solution because if you want to work at a command line you want the strongest set of powerful command line tools available. Linux gives you this. Windows doesn't even get close!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ErikT wrote:

 

1. atmelstudio.exe

I did as instructed on this page: https://avrstudio5.wordpress.com/2012/05/08/build-atmelstudio-projects-from-command-line/

c:\EXAMPLE1> atmelstudio.exe EXAMPLE1.cproj /build debug /out foo.txt

I could even replace EXAMPLE1.cproj with *.cproj, and it would automatically build whatever it found in the working directory. Brilliant!

However, the output can apparently only be sent to a text file, which means that my text editor can't capture it. I have found no way to direct the output to console. If this can be done, I guess that the problem is solved.

 

I don't know your situation.  I wrote my own editor decades ago.  It spawns a shell that runs a command similar to the above one, except for the foo.txt.  The details are a bit fuzzy.  It creates a named pipe that studio writes too.  My editor sucks the data out of the pipe and displays it. 

 

My editor is not usually in the folder where the .atsln file is.   I can put a simple file I call avrSolutionLocation.txt that contains the path to the .atsln file in any folder I might be in.  My editor reads this file to access the .atsln file.