Ditching the Arduino IDE and going Atmel IDE

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

I have been using the Arduino IDE (on a MS Windows laptop)  with a Uno (clone) and the cable to start learning Atmel AVR ASM.  I wish now to ditch working in the Arduino world and go "pure" Atmel.

 

1) Do I need a different boot loader burnt on to my chip or can the "arduino boot loader" stay and work?

 

2) Can I keep using my Uno and its cable or do i need to buy a different cable?

 

3) What is the cheapest / simplest route to go (hardware and software)? I am doing this just to learn, i do not need all the bells and whistles, just a basic "get started" set up.

 

4) If I went out and bought Atmel Studio 7 will that have the full IDE I need or will I have to go get a editor, terminal emulator and other stuff?

 

Thank you all for any advice.

I am a new AVR programmer. I am learning alone out of books, the Internet, etc. Please excuse me if I ask simple questions. Thanks.

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

AVR_Beginner wrote:
1) Do I need a different boot loader burnt on to my chip or can the "arduino boot loader" stay and work?

Atmel Studio has no functionality to communicate with an Arduino bootloader, but AVRDUDE can and you can get a half-*rsed integration of AVRDUDE into Atmel Studio.

 

AVR_Beginner wrote:
2) Can I keep using my Uno and its cable or do i need to buy a different cable?

You can continue using your current cable,

 

AVR_Beginner wrote:
3) What is the cheapest / simplest route to go (hardware and software)?

Hardware: What you already have. Software: Atmel Studio and AVRDUDE. Cost, monetary-wise: $0.

 

AVR_Beginner wrote:
4) If I went out and bought Atmel Studio 7 will that have the full IDE I need or will I have to go get a editor, terminal emulator and other stuff?

The complete Atmel Studio is free (again, monetary-wise). Just download and install.

 

You might be disappointed by the terminal emulator in Studio, and when you air that disappointment here you will likely get the advice to download and install (Brays) Terminal. Again $0.

 

If you get to terms with Studio, you might soon ask how to do on-chip debugging. For that you need new hardware. The advice will likely be "Atmel-ICE" which will cost you anything between $50 to $175 or so. Study the alternatives thoroughly before you buy. Ask here at 'freaks if anything is unclear re Atmel -ICE! (And with the Atmel-ICE the bootloader is not needed anymore, and you can program your AVRs flash using only Studio (no AVRDUDE needed).

 

EDIT: Poetry time!

 

El Tangas types so very slow,

the proof is in the post below.

It's usually me that comes in second,

if only by a fraction of a minute.

For once I typed sufficiently fast,

and so my post came first. At last!

 

Note: "minute" does not rhyme with second, I know - but I liked the wordplay...

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

Last Edited: Fri. Nov 17, 2017 - 10:56 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Atmel Studio is free, you don't need to buy it. Just get it from the Microchip site.

 

You can use your Arduino without any modification, but you will need to learn how to configure Atmel Studio to work with avrdude, that is the tool the Arduino IDE uses to talk to the bootloader.

 

You can search this forum on how to do it, for example: https://www.avrfreaks.net/search/...

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

It seems from the last two posts my Arduino bootloader is a bit of a bottle neck.  I am ditching the Arduino IDE all together so can i burn my chip with the "correct" Atmel/AVR Assembler bootloader from with in studio 7 and thus have a nice clean simple IDE?

I am a new AVR programmer. I am learning alone out of books, the Internet, etc. Please excuse me if I ask simple questions. Thanks.

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

The obvious thing to get is an XPlained-Pro or Mini board.

 

This comes with a built-in programmer and debugger on the board.

 

Having the debugger is the big advantage of using Studio.

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I don't know if Atmel has a special bootloader that you can burn and talk directly to Studio. But even if they did, to burn it would require an external programmer, the bootloader can't replace itself AFAIK.

 

If you have an extra Arduino, you can use it as a programmer. In fact, you can use it as an STK500v2 programmer that can talk directly to Studio, this is simpler than using avrdude IMO.

 

If you want, I can explain how to do it, it takes a few steps.

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

No, Studio does not have intrinsic functionality to communicate with a bootloader. It uses (talks to) programming dongles.

 

 

Studio does not talk to the dirt-cheap programming dongles you find at e.g. EBay for a few bucks. To use those, again you will rely on AVRDUDE.

 

Stick with your Arduino bootaloder. It is not a bottleneck.

 

As I said above, the definitive time to abandon the bootloader is when you want real on-chip <em>debugging</em>. For programming, the bootaloder will be just fine. The integration of AVRDUDE into Studio is not complicated. Ask us when you get there. You will need to do that setup once (as long as you don't switch to another AVR model) regardless of how many projects you work on.

 

 

Just keep the bootloader and go with Studio and AVRDUDE until you know you need something else.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

Last Edited: Fri. Nov 17, 2017 - 10:54 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

El Tangas:  Yes, I made a boot loader burner that uses a seperate Uno board. I use it (with in the Arduino IDE) to burn the 328P chips i bought that did NOT have the boot loader installed already...  If i can make that work with studio with out arvdude and all that comes with that i would be happy.

I am a new AVR programmer. I am learning alone out of books, the Internet, etc. Please excuse me if I ask simple questions. Thanks.

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

Johan: OK... I am going to read up on how to use avrdude with studio... I am going to install Studio now (I down loaded it already).

I am a new AVR programmer. I am learning alone out of books, the Internet, etc. Please excuse me if I ask simple questions. Thanks.

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

AVR_Beginner wrote:

El Tangas:  Yes, I made a boot loader burner that uses a seperate Uno board. I use it (with in the Arduino IDE) to burn the 328P chips i bought that did NOT have the boot loader installed already...  If i can make that work with studio with out arvdude and all that comes with that i would be happy.

 

Good. Probably you are using the ArduinoISP sketch. Replace it with the ScratchMonkey sketch instead, you can get it here: https://github.com/microtherion/...

 

Once you download ScratchMonkey, you need to do some simple modifications before uploading to the Arduino:

 

1) In the file SMoGeneral.cpp find variable kSoftwareMinor and replace it's value by 0x0A.

2) In the same file, find the SMoGeneral::SignOn() function. There is a line that says "#if 0", replace by "#if 1".

 

Now upload the modified sketch to the programmer Arduino, it will become STK500v2 compatible and can talk to Atmel Studio.

But you also need to disable the auto-reset feature of the Arduino. Put a 220 or 470 nF capacitor between Reset and +5V. Now it's ready to connect to AS.

 

 

 

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

Ugh!  Trying to install studio 7 and need MS Windows driver and updates... more MS crap...

 

Let me ask the following question:  If I stay with the Arduino IDE for doing assembler (not C!)... is it true that the compiled software is just as "efficent" and just as "good" and "fast" as if I did it in Studio 7?  What I am getting at is asside from not having debugging tools, etc, will my ASSEMBLER code done in the Arduino IDE and uploaded to the Uno via avrdude be just as "good" as if I did it in Studio (assume no bugs, etc)?

I am a new AVR programmer. I am learning alone out of books, the Internet, etc. Please excuse me if I ask simple questions. Thanks.

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

Of course the code will be just as good, nearly identical actually. It's assembly, it can't really vary.

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

El Tangas: well then maybe I should leave sleeping dogs lie... I have enough to learn the ASM language... if its basically the same then... leave it for now.

 

One final question: I made a simple "Blink" program in pure Arduino and a different one in pure ASM... The ASM is about 400 bytes (give or take).  The Arduino one is about 900 bytes (give or take).

 

Does ASM and Arduino have some minimal executable size? The ASM is about 1/2 the size of the Arduino code. I would have thought the ASM would be much smaller?

 

Thanks... any help is apreciated.

I am a new AVR programmer. I am learning alone out of books, the Internet, etc. Please excuse me if I ask simple questions. Thanks.

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

Arduino IDE and AS7 use the same C compiler/Assembler (may be different versions, but whatever) so produce the same code.

 

The Arduino environment sets up some background stuff, like a timer (for millis) and the basic program loop (main()) for you, so there is some small overhead that would not be there in pure AS7, although you may need to provide your own setup and loop anyway.

 

There is very little you have to use in the Arduino way, you can write your own functions(), or assembler code, nothing says you have to use the built in functions.

 

Jim

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
get $5 free gold/silver https://www.onegold.com/join/713...

 

 

 

 

Last Edited: Sat. Nov 18, 2017 - 01:16 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

An asm program built with the Arduino IDE will be linked to the assembly file gcrt1.S (well, to the object code resulting from this file). This file does some initialization that C programs need, then calls the "main" function.

 

For this reason it has minimum size of about 130 bytes, even without any code. I'll attach a small blink example.

 

 

Attachment(s): 

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

AVR_Beginner wrote:
I would have thought the ASM would be much smaller?

Why? What are your assumptions underlying this thought?

 

I would have thought the opposite - the size of the executable from the Arduino seems a bit big. It's either about the Arduino framework doing things very inefficiently, or the Arduino sketch written to be very inefficient. OTOH, if we're talking about a "plain blinky", i.e. one LED (or eight on the same port, just on-off-on-off... with delays then 400 bytes for that executable seems awfully high. I would think more like well below 100 bytes (i.e. well below 50 assembler instructions.

 

Anyway, my ballpark estimate is that a reasonably written C or C++ program should come in at not more than 125% of the hand-written assembler in most cases.

 

Nota bene: What we're talking about here is the amount of flash that the final executable occupies. Sizes of e.g. the hex file (and of course the source sketch or assembler files) are not representative in any manner whatsoever. If you're looking at the size of the hex file, then stop that immediately - it is a meaningless activity.

 

EDIT: Saw El Tangas post above. Sorry, I forgot that you're using GNU Assembler (not Atmels assembler) and that it adds startup code and the like. Yes, that will add a "fixed base cost". But if I'm not mistaken, you can get rid of that with some options passed to the assembler.

 

I still believe that a plain blinky in assembler should come in at (much?) less than 50 instructions: A loop for turning LED on, call a delay subroutine, turn LED off, call a delay function... That's less than 10 instructions. The delay subroutine should be less than 20 instructions. No interrupts, so no flash occupied by vectors. Surely well under 50 instructions..

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

Last Edited: Sat. Nov 18, 2017 - 01:28 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Jim: thanks! I am thinking it may pay for me to just stay with the devil I know already especially since I am just starting out.  Thanks for the advice. As long as I can write pure Assembler within the IDE I will stay with it. This is just for learning right now.  When the time comes I am ready to "step up" I will revisit the whole avrdude - studio 7 concept.

I am a new AVR programmer. I am learning alone out of books, the Internet, etc. Please excuse me if I ask simple questions. Thanks.

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

3) What is the cheapest / simplest route to go (hardware and software)?

Aside from using the Arduinos you already have, an "Atmel ATmega328p Xplained Mini"  runs about $10, and works "natively" with Atmel Studio (including debugging.)  It's also more-or-less an Arduino clone ("Shields" fit, though you might have to add connectors.)

 

 

It seems from the last two posts my Arduino bootloader is a bit of a bottle neck.

It's not really a "bottleneck" (which usually means "slows things down"), but it doesn't have native support from Atmel Studio.  And an Uno-class Arduino needs hardware modifications to support debugging, even if you had an external debug tool.

 

 

 so can i burn my chip with the "correct" Atmel/AVR Assembler bootloader from with in studio 7 and thus have a nice clean simple IDE?

 I would hesitate to ever describe Atmel Studio as either "clean" or "simple."  At best, it's professional, powerful, and The Standard environment for programming AVRs.

(I see you're discovering this, from your install attempts.)

If nothing else, using AS7 may give you a new appreciation for why the Arduino IDE exists, and what it does "right"...

 

 

The ASM [blink] is about 400 bytes (give or take). ... I would have thought the ASM would be much smaller?

 400 bytes sounds a bit on the large size, but with the "normal" compile environment, you'll probably be still including over 100 bytes of interrupt vectors and some startup code.

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

westfw:

 

Thank you. given time contraints and such its better to deal with what I have than try to bite off more than I can chew.   My #1 goal is to learn the AVR ASM langauge effectively. Then I can re-do all my Arduino stuff into ASM. After that i can "graduate" to better tools etc.

 

Thank you everyone for a reality check and all the great advice and help!

I am a new AVR programmer. I am learning alone out of books, the Internet, etc. Please excuse me if I ask simple questions. Thanks.

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

I would stongly advise that you stick with Arduino.
Write/replace selected Arduino functions.
.
What makes you think ASM is important?
Yes, having optimised a particular Arduino function in C++ or C, you can see if you can make any significant improvement in ASM.
.
In practice, knowledge and experience in C++ is far more attractive to employers.
Knowing how to find bottlenecks and optimise with a few lines of ASM is sometimes useful.
.
Oh, and unless I want to examine a short sequence with debugWIRE, I generally upload with the bootloader.
.
David.

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

AVR_Beginner wrote:
Then I can re-do all my Arduino stuff into ASM.

As others, I have to question this approach.

 

It's OK if you do it just for the fun, the puzzle and as a pastime.

 

If you want to write (reasonably) efficient code then go for C (or eventually C++) and learn how to use that language to create efficient code. Please understand that the extreme in-efficiency you might have experienced in the Arduino framework is not something intrinsic to the C/C++ language(s) but an idiosyncrasy of that specific framework. As an example, Arduinos DigitalWrite() can take about 50 CPU clocks, but if you know at compile-time what pin you want to wiggle then you write good C/C++ code to do it in two CPU clocks. A factor of 25 faster, using the same language and the same compiler!

 

Please note: I'm not after a C v/s assembler war here! I just want to make sure you opt for assember for a good reason rather than some misconception.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

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

Johan:

 

Your hitting the heart of what I am trying to do!  I want to make the smallest and most efficent and fastest code I can for my 328P... From what I have read on the internet C (and C++) are a big improvement over the stock Arduino environment but for absolute best performance, ASM is the choice... and I also enjoy ASM more than what little C I have already learned.

 

So, personal enjoyment aside, am I barking up the correct tree when I am learning ASM (as opposed to C) to make the smallest / most efficent / fastest code ?

I am a new AVR programmer. I am learning alone out of books, the Internet, etc. Please excuse me if I ask simple questions. Thanks.

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

AVR_Beginner wrote:
So, personal enjoyment aside, am I barking up the correct tree when I am learning ASM (as opposed to C) to make the smallest / most efficent / fastest code ?

That's a complicated discussion and analysis, and likely a war-starter. I'll try to be very diplomatic:

 

A skilled assembler programmer will always be able to produce code that is at least as efficient as that generated by a compiler from source written by a skilled C/C++ programmer.

 

The problem is that if you're not a skilled assembler programmer you're likely to produce code that is less efficient than that generated by a compiler from C/C++ sources. For anything but the quite special cases my guess is that you'd gain on the order of perhaps 10 (20?) percent more efficient code. And I wager it takes a longer time becoming a skilled assembler programmer than a decent C/C++ programmer.

 

The root question now becomes why this need for "smallest and most efficient code" is so important for you that you (in my opinion) is trading that for taking a longer (much longer?) time to get there? Do you just want it in general, or do you have a specific application in mind that requires this performance.

 

From that follows this: If you don't have a specific application in mind then it is (again, in my opinion) rather meaningless to strive for the most efficient code. The art of engineering is to do things efficient enough, but not spend efforts on more than that since it will just be "heat going up the chimney".

 

So, could you put numbers on what efficiency you need? ("E.g. I need to do s<some complex calculation> on n sampes per second (n being a large number) because...")

 

IMO the best approach is to code in C/C++, and if you have some piece of algorithm that needs ultimate efficiency you write just that in assembler, leaving the rest of the code as C/C++ which makes for e.g. much easier maintained code. C/C++ and assembler can inter-operate just fine.

 

That was the diplomatic version. I still think the war is close... ;-) Helmets on! Duck and cover! Assember missiles incoming!

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

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

So, personal enjoyment aside, am I barking up the correct tree when I am learning ASM (as opposed to C) to make the smallest / most efficent / fastest code ?

There's a difference between writing efficient code, and writing code efficiently.

 

You can get very close to optimally fast/small code with C/C++.  Say, 90% there.  To get better, yes, arguably ASM is the way to go, but engineering isn't all about the final product.  It's also about the process.  If getting those last 10% takes you 700% greater investment in time and human resources, that's a waste of your time, and worse, you'll be late to market, or miss the market altogether.

 

Maybe not relevant for a pure hobbyist, but that's your call.  Were it me, I'd learn C/C++ and ASM at the same time.  Learn from the compiler.  It does a pretty good job of generating ASM.  Not always, mind you, but it's a good place to start.

 

You need to realise that it's not always necessary, or even good, to optimise every part of your code.  Many apps will have speed-critical section.  Focus on getting those fast.  If you need to resort to ASM to do so, so be it.  Use your time wisely.

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

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

JohanEkdahl wrote:
I still think the war is close... ;-) Helmets on! Duck and cover! Assember missiles incoming!

 

Nah... just blame Trump LOL

 

joeymorin wrote:
Use your time wisely.

 

I get the feeling from the statements that given limited time (family, job, etc)  I will be an old man before my ASM code is as good as say my C or even Arduino code. 

 

OK... if that's the case I will keep learning ASM time permitting  and go back to learning C. I just like ASM and the idea of being able to be unhindered by "libraries" and "drivers" and other shit that is never documented right anyway... i hate "black boxes" when making something... just how I am. Ergo ASM (and learning how the entire processor works, timers, interupts, etc) appeals to me.

 

But... if C brings me to 90% of that in 1/4 of the time and effort compared to ASM then I guess that's how the ball bounces.   Its like I want a Mercedes but in reality I can only afford a Ford... OK, reality check.

 

Thank you all again!  The Arduino environment seems to support standard C and I have a good book on it to start off with (yet again LOL).

 

Everyone: thank you for untold years of good solid advice compressed into this one HTML page :-)

I am a new AVR programmer. I am learning alone out of books, the Internet, etc. Please excuse me if I ask simple questions. Thanks.

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

You don't need "libraries" to code in C for your AVR - except for the avrlibc runtime library (as long as we're talking about the avr-gcc toolchain), which is well documented. (A substantial part of it is an implementation of parts of the Standard C Library, which is very well standardized and documented.)

 

With only avrlibc and the part-specific header files (for convenience) you can write "everything" yourself.

 

Having said that, we often recommend to use well tested and proven "libraries" for commonly recurring stuff - e.g. driving I2C communication or driving a LCD display.

 

I admit that I do a lot of tinkering myself - not relying on libraries - for the sake of learning and understanding. But when it comes to doing something that should end up as a usable "thing" I prefer the libraries of others a lot of the time. Just saves such a lot of time developing, testing etc.

 

 

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

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

joeymorin wrote:
There's a difference between writing efficient code, and writing code efficiently.

+99 - Excellently put!!

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The Arduino development model combines all the aspects of microcontroller [MCU] design and implementation into a single reasonably-well integrated system.  It extends beyond the standardized C++ definition by adding keywords to handle common MCU operations and tested libraries for more complex operations like interfacing to complex peripherals like intelligent sensors and TFT displays.  But it does have the reputation of being stupid and ugly.  

 

The colors of the Arduino IDE are adjustable, but these adjustments are hidden in the default.xml file in c:\Arduino-x.x.x\lib\theme\syntax\ folder and the theme.txt file in c:\Arduino-x.x.x\lib\theme\ folder.

 

Atmel Studio shines when compiling code for AVR devices that aren't covered by Arduino, which is all of them expect the mega328P, the mega2560, and mega32u4 (the Leonardo).  There is a reduced version of Arduino for the 8 and 14 pin AVRs Tiny85 and Tiny84, but it is more "proof of concept" than useful for complex applications.

 

Assembler will start to drive you crazy when the code gets more than about twenty pages long and it is not very well structured and documented, which it won't be when you're learning it.  As for the extended instructions like digitalWrite() that are sometimes shown to take lots more instruction cycles than necessary, they can often be replaced by macros that compile into code that is as small and concise as that written in assembler. 

 

Study the library code that is available for commonly used peripherals.  Limor Fried's (Lady Ada of Adafruit) library code is pretty good, and David Prentice's MCUfriend code for TFT devices is worth a good study.  The Mat Hertel library for the various 50-cent FM radio ICs is a good place to see how structured classes and callback functions can all fit together.  The Adafruit library for NeoPixels shows how to use Arduino C++ with inline assembly for applications that need microsecond precision but also need to call background functions to handle LED patterns and setup complex peripherals.

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

The beauty of Arduino is that there are no ‘black boxes’. Whilst it does try to shield you from the evil, you can go looking and find the source code - it comes with the Arduino installation. You can see exactly how it implements millis() etc.
there’s also untold numbers of discussions on how inefficient the port i/o is but little on the many other functions that are provided. That tends to suggest that most of the functions are perfectly adequate.

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

Normally, what I do is write most of the code in C or C++. But if some function needs to be extra fast or needs to have exact timing, I may write it in assembly.

 

Another problem is if your code is getting too large for your goals. Arduino libraries are somewhat bloated, but avr-libc is ok. But libraries always need to consider every possible situation. So if you have some special case and need smaller code, it may be necessary to write your own functions.

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

Does anyone know if Arduino IDE can be cajoled into using -nostartfiles?
.
PS not that I particularly agree with all this stuff about ultimate efficiency but if you are going to implement code in Asm perhaps you want an "empty machine" so you can can take control of the IVT and ditch the CRT.

Last Edited: Sun. Nov 19, 2017 - 02:32 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Deep within the bowels of the Arduino install, there is the file "platform.txt", that has the compiler and link options. In fact there are several of these files, in my Windows 7 system, the user level one is at:

(home)\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.20\platform.txt

 

I suppose you could add -nostartfiles somewhere in this file.

 

It's also possible to create new hardware profiles with their own "platform.txt", but all this doesn't seem to be very well documented.

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

Does anyone know if Arduino IDE can be cajoled into using -nostartfiles?

Not easily.  One of the ways that the Arduino IDE has "simplified" the world is by getting rid of most of the ability to customize compile-time options.

 

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

JohanEkdahl wrote:
You might be disappointed by the terminal emulator in Studio

 

Is it worse than Arduino terminal emulator?

clawson wrote:
Does anyone know if Arduino IDE can be cajoled into using -nostartfiles?

 

Well, if Arduino could make setup as weak, or main as weak, that would be useful (and save a little space). It can be done manually, but what would happen if Arduino upgrades (there is an option to upgrade automagically).