Auduino questions

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

I have a number of AVR boards around here - none are official Audino. I began with a mega128 stamp (ETT) plugged in to ETT's baseboard. The stamp itself has no standard ISP connector, but the baseboard has a JTAG connector that works with my NKC JTAG under AVR Studio. Works OK.

Rather than use a serial bootloader, I'd like to use the JTAG to flash .hex files produced by Arduino. I found one obtuse comment on where Audino's C++ stores the .hex for a project. It's in a very odd tmp directory in windows 7.

Questions
1. Is there a way to tell Audino to put the .hex and linker map files in the project directory? Or some reasonable place?

2. Do the Audino libraries handle > 64KB flash where the RAMPZ bits must be managed?

3. I found one mega128 bootloader for "wiring", but not sure it's compatible with Audino's IDE?

Maybe these Q's should go in an Arduino forum, but I suspect these are too complex.

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

I'd like to be able to help, but I can't really because the Arduino has quite a gulf between what is easy and the rest of the stuff. All the source code is available so you can do everything you want, but like you already noticed finding things can be a bit obtuse. Personally, if my goal was to use a mega128 I'd just put the Arduino bootloader on it and then use the regular Arduino code and if I wanted to do something different, I'd consider the more common ways of doing things before trying to bend the Arduino underlying tools to my will. I'm not all that interested in learning Processing\Java or C++ at the moment so I haven't dug to deeply into what they are doing.

But you are an experienced guy, why do you want to hack up Arduino?

smiley

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

Thanks...
First/short-term: Ardino's IDE has a list of "boards". Among these is no mega128. There is a mega1280. I need to see if the I/O such as UART is the same for the m128 and the m1280. Maybe this is why the first Arduino example I tried doesn't work; it sends data out the UART. (my other AVR Studio m128 programs work OK on the same hardware).

I want to use Arduino as a springboard to learning C++ on the AVR. I was going to learn (for microprocessors) using an ARM Cortex M3 mbed (I have one), but that C++ is mind-boggling to me, with the virtual destructors and so on. I'm stuck in the C rut from doing it for 20 years.

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

Hi Steve,

I am using a Seeeduino Mega at the moment. It uses a mega1280. Would it help you if I post its schematic in pdf?

Cheers,

Ross

Ross McKenzie ValuSoft Melbourne Australia

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

Steve,

For some insight to some of your question see this thread I contributed to just before I went on holiday:

https://www.avrfreaks.net/index.p...

Cliff

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

Quote:
I want to use Arduino as a springboard to learning C++ on the AVR.

From what I've seen of the Arduino code, I'm far from sure that it is the most fitting springboard for learning C++ in embedded systems.

Instead I would suggest starting simple, deciding on a "medium-sized" app, designing it with an OO approach and implementing it in C++ where applicable. "Things" that lend themselves to OO are e.g. hardware peripherals (though you will struggle with ISRs in C++), and of-course many other things on levels above the hardware.

From what I've seen, the Arduino code is written to extremely generic resulting in large generated code. IIRC clawson demonstrated what a simple pin I/O generated a few months back.

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

valusoft wrote:
Hi Steve,

I am using a Seeeduino Mega at the moment. It uses a mega1280. Would it help you if I post its schematic in pdf?

Cheers,

Ross

Yes, thanks. The Arduino's menu of "boards" does not include that; it does include the mega1280 board. A quick read of the Atmel data sheets says that perhaps the m1280 and m128 I/O registers are similar. But the two Arduino samples I tried don't run on my ETT m128, when flashed using the NKC JTAG. I was going to skip using the bootloader since I use the JTAG for flashing/debugging.

So with teh Seeeduino m128, what "board" do you choose from the Arduino menu? The m1280 board?

Is it valid for me to assume that the Ardino startup code doesn't depend on (or call) code in the bootstrap section?

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

JohanEkdahl wrote:
Quote:
I want to use Arduino as a springboard to learning C++ on the AVR.

From what I've seen of the Arduino code, I'm far from sure that it is the most fitting springboard for learning C++ in embedded systems.

Instead I would suggest starting simple, deciding on a "medium-sized" app, designing it with an OO approach and implementing it in C++ where applicable. "Things" that lend themselves to OO are e.g. hardware peripherals (though you will struggle with ISRs in C++), and of-course many other things on levels above the hardware.

From what I've seen, the Arduino code is written to extremely generic resulting in large generated code. IIRC clawson demonstrated what a simple pin I/O generated a few months back.


I am beginning to agree, having looked at the source for the Arduino libraries for m1280 vs. m128 dependencies.
I did get some AVR C++ code to run on the ETT m128 stamp using the JTAG. Not using Ardino. Don't know who wrote it. It includes files like IOpin.hpp and IOpin.cpp.
EDIT: Here's the AVR Studio compiler choice override I'm using
C:\WinAVR-20100110\bin\avr-g++.exe

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

stevech wrote:
valusoft wrote:
Hi Steve,

I am using a Seeeduino Mega at the moment. It uses a mega1280. Would it help you if I post its schematic in pdf?

Cheers,

Ross

Yes, thanks.
Attached. I like the board, BUT this has to be the worst circuit diagram I have EVER examined. I have used the Eagle files to "print" to the pdf file for you.

stevech wrote:
The Arduino's menu of "boards" does not include that; it does include the mega1280 board.

That is what I use.

stevech wrote:
Is it valid for me to assume that the Ardino startup code doesn't depend on (or call) code in the bootstrap section?
Don't know ... I am simply "driving it, haven't looked under the hood". :lol:

Attachment(s): 

Ross McKenzie ValuSoft Melbourne Australia

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

No Arduino, but...

Well, here's an experienced C programmer but bumbling c++ newbie's attempt. I found this I/O code on the 'net, for the classes In, Out, IOPin and LED. I also found the c++ code from a different author, for a timer interrupt handler for c++. I changed that a little to get a 1mSec interrupt with the mega128 at 16MHz, on the ETT mega128 stamp board (cheap).

I modified the code so all files are in the same directory (for now). I changed the .h file names to .hpp.
Using generic AVR Studio with GCC (WinAVR) I got this program to run. Using NKC's cheap JTAG ICE to download rather than a serial port bootloader.

I see that class Out is derived from class IOPin and class LED is derived from class Out.

As noted above, the c++ mode is enabled in the project settings (aps file), to change the compiler invocation.

So main.c toggles an LED twice a second.
1441 bytes. Wow, my ole C would be 1/10th that, but the classes have more generality in function calls.

Now I'm trying to fully understand what code goes in an hpp file versus a cpp file. In old C, it was a no-no to put functions in a .h.

I think I can add c++ UART code I found on the 'net.
There's no way I could have authored this myself, as a newbie, esp. the interrupt code.

since the instances of Out and LED are within the main() function, I wonder if the RAM used by these classes is obtained by malloc() and this may be why there's more code? If I made those instances static (outside of main() or whatever, perhaps the RAM would be allocated at compile time?

The timer class is hard-coded for timer 2. Maybe I'll get competent enough so that it could be instantiated for any extant timer and mode/rate. But it's really intended to support ticks and waits.

zip file enclosed.

Onward.
Help from embedded c++ gurus appreciated.

Here's main.c that's within the attached zip file.

#include 
//#include "Out.hpp"
#include "LED.hpp"
#include "Timer.hpp"

int main(void)  {


	TIMER mytimer;

	OUT myLED('G', 2, false);
	//LED myLED('G', 2);


	while (1)  {
		//myLED.On();
		myLED.Toggle();
		mytimer.WaitMs(500);
		//myLED.Off();
		//mytimer.WaitMs(500);
	}

}

I used both the Out class and the LED class, hence some are commented out for test purposes.

The author of the Out class used this rather odd scheme of initializing a port by passing the ASCII character of the port name, i.e., the 'G' means PORTG.

Attachment(s): 

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

Quote:
1. Is there a way to tell Audino to put the .hex and linker map files in the project directory? Or some reasonable place?

Using a text editor, edit your Arduino "preferences.txt" (after figuring out where it is) so that you have:

   build.path=c:\tmp\ardbld

or whatever. (The annoying default is apparently what you get if your app asks java to give you a "temporary directory." Bleh!)

Quote:
2. Do the Audino libraries handle > 64KB flash where the RAMPZ bits must be managed?

The Arduino libraries contain no special handling of RAMPZ. OTOH, they are all written in C/C++, so you get whatever (that particular version of) avr-gcc gives you automatically. IIRC, that wasn't quite 100%, but was somewhat useful.

Quote:
3. I found one mega128 bootloader for "wiring", but not sure it's compatible with Audino's IDE?

The Arduino IDE uses avrdude for interacting with the bootloader, as configured via a "boards.txt" somewhere in the arduino paths. In theory, any bootloader that supports an avrdude-compatible protocol should usable. Arduino uses STK500v1, so any bootloader that uses that should be easier.

The bootloader is only the start of compatibility issues, though. The mega128 is not among the chips officially supported by the core libraries, so you'll have to make some allowances there. As of version 0022, the core libraries are now MUCH more device-independent, and I believe that they will support m128. With only a small amount of effort.

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

westfw wrote:
As of version 0022, the core libraries are now MUCH more device-independent, and I believe that they will support m128. With only a small amount of effort.

Thanks!
At the moment, as discussed above, I've moved on to C++ without Arduino. My jump-start is using code from users on the website
http://www.societyofrobots.com/m...
and
http://www.societyofrobots.com/m...
Using a mega128 without any libraries - on the m128. His buffer class and uart class are working too on my m128, but he has a bug in the uart driver when it runs at full speed. I can fix that - it's an interrupt handling issue.

The website's user contributed the fundamentals I need.
I may find a better source of examples.

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

Quote:

Now I'm trying to fully understand what code goes in an hpp file versus a cpp file. In old C, it was a no-no to put functions in a .h.

In C++ you can define a member function either in the class declaration, e.g.:

class foo
{
public:
   void bar()
   {
      // Code here
   }
};

or separate from the class declaration

class foo
{
public:
   void bar();
   {
      // Code here
   }
};

void foo::bar()
{
   // Code here
}

In the latter case the rule of thumb (no code in header files) still holds, so the class declaration
should go into eg foo.hpp and the function definition eg into foo.c.

In the former case the member function is inlined, so the problems stemming from C function definitions in header files does not apply.

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

Quote:
3. I found one mega128 bootloader for "wiring", but not sure it's compatible with Audino's IDE?

It's compatible with arduino IDE.

Jeckson

.

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

Quote:

EDIT: Here's the AVR Studio compiler choice override I'm using
C:\WinAVR-20100110\bin\avr-g++.exe

Why do that? In Studio if you give a source file a .C or .cpp extension rather than .c then it automatically gets passed to avr-g++ rather than the C compiler. avr-gcc is a "meta compiler" and will invoke the right compilation mechanism based on the extension anyway (.s or .S just get passed straight to avr-as for example). So leave Studio set to avr-gcc.exe and use the file extensions to determine how the file is compiled/assembled.
Quote:
So main.c toggles an LED twice a second.
1441 bytes. Wow, my ole C would be 1/10th that, but the classes have more generality in function calls.

The majority of the "overhead" in Arudino's pinMode and digitalWrite() is not the fact they are implemented as C++ but the code to do the chip pin number to PORT/pin number mapping in fact. Maybe that's the same in the code you are using? One things for sure, once you start indirectly addressing IO registers the compiler no longer has the opportunity to use the efficient SBI/CBI or even IN/OUT any more - but that's as true of C as C++ in fact.

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

Steve!

The ISR in Timer.cpp is a more or less "plain old C ISR", i.e. it is not a member of the Timer class which would be desirable from an encapsulation point of view. (With the "C solution", the s_msTimer variable is placed outside of the class.)

You write:

Quote:
I also found the c++ code from a different author, for a timer interrupt handler for c++. I changed that a little to get a 1mSec interrupt with the mega128 at 16MHz, on the ETT mega128 stamp board (cheap).

Is it the ISR in the Timer class you are talking about?

-----

Interestingly, the class itself allows multiple instantiation, so now you could end up with two object manipulating the same static variable. The ideal would be to make everything in the class static, and have the variable in the class. The only thing lacking then would be to get the ISR inside the class to, and we would be totally encapsulated.

I know I ran across a case where someone managed (with attributes and stuff), to write an ISR inside an C++ class (using the AR-GPP ompiler). I failed to save a link and now I am stumped trying to locate it again.

Anyone have any recollection of this? (Author was not a regular here, IIRC.)

EDIT: It's not this, although that thread also is interesting.

Edit 2: Ah! Here it is.

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

@Clawson: thanks. I did not know that using .C or .cpp automagically caused GCC to use the other compiler mode. Not well documented! Nit pick: the "open" dialog boxes in GCC for AVR studio don't have C or cpp types in the wildcard lists. So each time, I must change to "all files". end nit pick.

The whole issue of ISRs in C++ is at the moment mind-boggling to me. I wonder if the ISRs in Ardino c++ are good examples. The freeware ISR for the UART that I am using is incorrectly designed. Wrong logic for the I/O for buffered I/O. It has race conditions and crumps easily.

Ardino: I do not think that the current libraries run on the m128. Examples I tried don't startup at all on the m128. The library code has no constants or ifdefs for m128. There are such for the m1280 which differs.

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

Quote:

The whole issue of ISRs in C++ is at the moment mind-boggling to me.

Here's my $.05 of facts and thoughts:

Fact: C++ supports function overloading - you can have several functions with the same name as long as their parameter lists differs (in number and/or types of parameters differ - parameter name difference is not enough). To handle this the compiler "decorates" (or "mangles") the function names in the symbol table.

AFAICT all C++ functions that are members of a class are decorated, and it seems that an ISR must be a C function - with a non-decorated name.

If so this prevents an ISR to be a member of a class, and (as in your code above) this would mean that we are forced to
i) make the ISR an ordinary C function, and for it to be able to access the members of a class
ii) these members must be declared public
This will break the OO principle of encapsulation.

Example: Imagine a class to handle a UART with ring buffers for reception and transmission. Since the ISRs need to be C functions and need to access the ring buffers per se, and the in- and out-indices the class is not encapsulated.

If the ISRs could be class members, then the buffers and indices could be private and we would have "perfect" encapsulation.

Now, if someone has more technical insight re ISRs (in avr-gcc) and could share how a C++ class member function could be set up I would be very interested to hear about the details.

I strongly suspect that it is in principle impossible because the ISRs would need to be passed the (implicit) this-pointer.

Perhaps it could be solved by making all class members static, but that then implies that only one UART can be handled. Making all members static implies that the class is a "sort of" singleton.

Perhaps a template class could solve this, but then the compiler would most likely generate code for each template instantiation.

Seems we-re between a rock and a hard place..

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

Thanks a zillion for the explanation - which I actually "get". Does this mean that C++ for Linux or Windows (or is that C# for system software?) uses some proprietary/custom kludge for ISRs? How would this work in an RTOS system where, in interrupts, variables must be accessed in different contexts?

I've continued this discussion in this thread of a different name, since we're talking general C++ with AVR Studio/GCC rather than the Arduino variant.

https://www.avrfreaks.net/index.p...

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

JohanEkdahl wrote:
...

I know I ran across a case where someone managed (with attributes and stuff), to write an ISR inside an C++ class (using the AR-GPP ompiler). I failed to save a link and now I am stumped trying to locate it again.

Anyone have any recollection of this? (Author was not a regular here, IIRC.)

EDIT: It's not this, although that thread also is interesting.

Edit 2: Ah! Here it is.

Johan,
Those links go to the same place. Can you correct the link please?
Thanks.

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

Quote:

Johan,
Those links go to the same place. Can you correct the link please?

Darn! I thought I had it. I'll have to sift through all those search results again. No time right now.

Irritating. I've been meaning to straighten out ISRs and C++ thoroughly for a long time now. Other matters, think "work", means that such activities gets pushed onto the "not-now stack".

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]