3

I'm using PlatformIO as an IDE for programming AVR MCUs. I'm beginning AVR programming (I have a background in C/C++ and programming on OS's, not embedded, although I have done some Arduino stuff in the past) and using PlatformIO gives me code completion for the registers/pins, which is why I use it.

It seems I can't switch framework from Arduino to avr-gcc in PlatformIO without losing code-completing.

I am wondering if there's any drawbacks in keeping Arduino as the framework?

I know Arduino uses avr-gcc in the back, but I read that it still does a bit of setup without the users knowing it (such as Timer0 setting for delays, which I need since I'm using it as a clock source for USI on my ATTiny85).

Otherwise, is there anyway in PlatformIO to keep code completion and use avr-gcc instead of Arduino?

Thanks!

EDIT: I'm on either OSX or linux (ubuntu).

Community
  • 1
  • 1
Cedric
  • 889
  • 1
  • 8
  • 18
  • 2
    *I am wondering if there's any drawbacks in keeping Arduino as the framework?* - Arduino framework is a one big drawback. – Eugene Sh. Jul 20 '16 at 13:56
  • To reformulate: _I am wondering if, by not using or including any of the Arduino framework stuff, the frameworks skips the drawbacks of Arduino._ On a personal note: I've used Arduino and found it bulky and not really adaptable. Reading on embedded programming made me stop using it. – Cedric Jul 20 '16 at 14:04
  • If you are asking if the AVR MCUs are any good without using Arduino stuff, I would say they are pretty capable by themselves. The problem, as I can recall, is with limited debugging capabilities. – Eugene Sh. Jul 20 '16 at 14:19
  • Thanks for your reply! But it is not what I'm asking. I programmed in ANSI-C without using any of the Arduino stuff (which means I'm programming without a setup() and loop() block and using registers to set the pins, the ADC and the timers). PlatformIO only gives me the Arduino framework, but it builds my code nonetheless. I was wondering it there is any performance decrease in doing so (not directly compiling using avr-gcc). Thanks! – Cedric Jul 20 '16 at 14:28

3 Answers3

6

As pointed out by ivankravets on the PlatformIO community platform (see: https://community.platformio.org/t/avr-programming-without-arduino-framework/525/4), it is as simple as removing the line framework = arduino from the platformio.ini file to get rid of the Arduino framework and work in bare C for avr-gcc.

JrBenito
  • 973
  • 8
  • 30
Cedric
  • 889
  • 1
  • 8
  • 18
2

I have never used PlatformIO, and my answer is only based on my (extended) knowledge of AVR development and the Arduino mess…err…framework.

The Arduino framework is using AVR-libc (the standard low level framework that gives you all the tools you need to program on AVR), and adds a layer of abstraction so you're not directly handling registers, but use a more easily understandable interface.

So when you write on a pin, instead of looking at the AVR's IC leg number, looking for the matching PORT address to configure it and mutate it, you're using digitalWrite() on the board's pin number. So, whatever the IC is, the pin will stay the same with consistent capabilities.

The pin definition is done using a header file that's given to the compiler depending on your target setting in your IDE (so whether you use an Arduino Mega or a Leonardo the matching between AVR port/pin and board pinout will change radically).

Given your description of PlatformIO, it's using that information to give you appropriate pinout completion based on the board configuration. It's also certainly taking advantage of the object oriented approach of the Arduino framework, so that you can easily have method completion when using singletons (like when you use Serial).

Using raw AVR-libc, on the other hand, it's harder to get any meaningful completion, because most of the operations are being done on registers which are being declared through preprocessors aliases, and the whole code is pure C, so code completion is not really helpful (you cannot list all the methods that applies to a given object… like with the Serial example).

Then, Arduino offers a nice high level approach to prototyping embedded code, that you can then curate when you need to optimise in time and/or space. And some projects (like the Marlin firmware for repraps) use some sort of hybrid approach, reimplementing many parts of the Arduino interface in a more optimised way (like digitalWrite or the Serial object).

In the end, my advice to you would be to drop platform.io or the arduino IDE, and switch to eclipse if you're really into IDE GUIs, or better, use your preferred powerful editor (like vim/nvim, emacs, atom, sublime…) to have it handle AVR code like any other C code.

JrBenito
  • 973
  • 8
  • 30
zmo
  • 24,463
  • 4
  • 54
  • 90
  • 1
    AVRStudio is a good choice for working with AVRs on low level. Setting up the Eclipse to work with it is not trivial. – Eugene Sh. Jul 20 '16 at 14:22
  • I should have emphasize on the fact that I am not using any Arduino framework tools. There's no such thing as SPI for the ATTiny on Arduino, as it uses a common bus for both SPI, I2C and USART. Thus, I've really only used what is basically defined in avr-gcc. I felt like Platform.oi could be my got-to editor for any embedded projects (since it is built upon atom.io, with git integration and project management), without having to write a makefile to build and upload my code. Seems like I'll just get back to Sublime for now. – Cedric Jul 20 '16 at 14:36
  • @EugeneSh. I'm not a windows user, and the few times I tried AVRStudio never convinced me to switch to it, far from that actually. TBH, I find it very bloated and inconvenient to use. – zmo Jul 20 '16 at 15:31
  • 1
    @Cedric for embedded dev, you'd rather use your "standard" code completion/syntax checking tools along with your editor. What I've done, is to use llvm-avr just for that (even though I'm still compiling with avr-gcc). – zmo Jul 20 '16 at 15:32
  • @zmo That's a good idea thanks, I'll look into that! Basically you used llvm-avr for it's clang integration into an editor? – Cedric Jul 20 '16 at 17:14
  • 1
    I do! But as llvm-avr is still pretty immature, I wouldn't recommend it for anything else, like actually compiling the code. But most of the important stuff is there, like the registers and the important macros, so it's pretty decent for code completion and static code analysis… Given that I've already been bitten hard by avr-gcc bugs, which maturity is worth years of development and bug hunting, I'm not much curious to discover the novel ways llvm-avr will fail in real world usage. – zmo Jul 20 '16 at 17:19
1

If you work on an Arduino project including avr-gcc internals using VisualMicro plugin and VisualStudio (Community Edititon) all the code completion / syntax highlighting / goto declaration etc. works for anything in your project and all libraries.

Is this what you're looking for?

Of course, VisualMicro is annoying if you use them "for free"

datafiddler
  • 1,755
  • 3
  • 17
  • 30