SparkFun Forums 

Where electronics enthusiasts find answers.

Discussions on the software and hardware for Atmel's STK standard.
By arix
#120582
Hi,
They say better to ask a stupid question than to do a stupid mistake :mrgreen:

First time I programed for Atmega32L in AVRStudio 4 IDE (and this forum greatly helped to succeed!). Now my question is if it is possible to write C++?

I googled and in some places it seems AVRStudio using WinAVR can compile C++, in other places no mention on C++. Also, I could not define a class in my working C program in AVRStudio (but if C/C++ both supported, then it should be possible right? With some include directives?).

Please let me know :-)
By stevech
#120720
C++ on AVR for beginners: see arduino.
Advanced: see discussions on C++ on avrfreaks.net forum

keep classes simple. compile-time class instantiation to minimize use of new and malloc.
By arix
#120742
stevech wrote:C++ on AVR for beginners: see arduino.
Advanced: see discussions on C++ on avrfreaks.net forum

keep classes simple. compile-time class instantiation to minimize use of new and malloc.
Thank you for pointing me to C++ resources. My problem at hand is to write a small kernel containing a scheduler, with the purpose of learning:
1. OS-kernel on MCU
2. Design Patterns.

I know of kernels like FreeRTOS and some versions on PIC18, and I also have beginner knowledge on design patterns. By beginner I mean that I know coding design patterns, but I never created a whole system that consists of them. I thought that if I try to make a real kernel based on MCU and forcing me to use d.p. I may get some skills in real usage of them.

I think Arduino is not a choice as I would like to use ANSI C++ or Java and not the language that Arduino uses. If you see that there are points I must know to improve my new research, please kindly let me know.

As long as I understand by the reply, the answer is 'yes' and I can write C++ free of Arduino IDE.
By stevech
#120886
start with a cooperative task scheduler, single-stack. Some for AVR micros can be found on avrfreaks.net's projects section.
There are many examples of these, with public domain source code. These are also called run-to-completion tasks, typically as a state machine, called repeatedly by a scheduler. They can be event driven.

C++ rather than C, is thought by many to be a poor choice for small memory microprocessors. Arduino's environment uses C++ with GCC. If done carefully, it can be done. Be sure that you are totally C competent and with interrupt handlers before worrying with C++.

Next step up is an ARM7 or ARM Cortex M3 such as the LPC1768. The mbed is such a chip. You can roll your own or use their C++ libraries. You can use GCC for the ARMs with C++ as an option, or the 32KB limited size version of the excellent compilers from Keil and IAR (I prefer the latter).

In either case, the use of new() needs to be minimized or avoided, and try/catch is out of the question in small RAM micros.

And note too that developers for small RAM micros tend to use no scheduler, or a cooperative task non-preemptive scheduler, single-stack, and multiple state machines, rather than a classic RTOS.
By arix
#120891
Stevech! Thank you, very informative! Wonderful response!