Programming registers and function recalling

Hi! Recently I need to use the Wiring language of Arduino (but usually I use C on AVRs) and I don't undertand one thing: when I need a particular HW configuration, I know that I can directly write on mcu register, for example modifying timer2 register or whatever. But what is not so clear is a guarantee that the C++ functions (alredy included and loaded from the Arduino software core) like the Timer2 init (that is called by default if I understand, for using Millis() function) are not (re)overwrite my configurations, maybe recalling Millis(). Should I modify cpp files inside the Arduino core?

Another question is this: Did exist something like a graph that indicates all the files and configurations (headers and code before the .hex final file) loaded on an Arduino board (the Uno at least) with a barely simple program, like blinking? I'd like to know exactly what are those 800byte in the blinking code.

thanks! :)

thexeno: Did exist something like a graph that indicates all the files and configurations (headers and code before the .hex final file) loaded on an Arduino board (the Uno at least) with a barely simple program, like blinking? I'd like to know exactly what are those 800byte in the blinking code.

"Blink" requires: - main.cpp for main() function (doh) - wiring.c for init() to setup timer, delay() etc. - wiring_digital.c for pinMode() and digitalWrite()

You can use avr-size to check out the compiled sizes in your temp directory. And avr-objdump -x to disassemble your elf file and find out what gets linked into your final binary.

int2str: You can use avr-size to check out the compiled sizes in your temp directory. And avr-objdump -x to disassemble your elf file and find out what gets linked into your final binary.

It tell that a.out is not a file. How can I use this avr-objdump? Here, I've never used before those commands and seems not too easy understand directories organisation.

Coming to my post: wiring.c has a fully configuration. But when those functions are called? If I don't want to call them anymore during execution and/or neither at reset, should I coming back again and write in pure C in an IDE like AtmelStudio? Or there is some kind of control w/out rewriting functions inside wiring.c?

thexeno: It tell that a.out is not a file. How can I use this avr-objdump? Here, I've never used before those commands and seems not too easy understand directories organisation.

avr-objdump --help :)

Here's an example output for "avr-size":

~/Projects/Arduino/blink $ avr-size obj/*
   text    data     bss     dec     hex filename
   1062       0       9    1071     42f obj/blink.elf
     66       0       0      66      42 obj/main.o
    488       0       9     497     1f1 obj/wiring.o
   476       0       0     476     1dc obj/wiring_digital.o

And here's example output for avr-objdump, note how it lists the functions used in the file:

~/Projects/Arduino/blink $ avr-objdump -x obj/main.o 

obj/main.o:     file format elf32-avr
obj/main.o
architecture: avr:5, flags 0x00000011:
HAS_RELOC, HAS_SYMS
start address 0x00000000

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .text         00000000  00000000  00000000  00000034  2**0
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  1 .data         00000000  00000000  00000000  00000034  2**0
                  CONTENTS, ALLOC, LOAD, DATA
  2 .bss          00000000  00000000  00000000  00000034  2**0
                  ALLOC                                                                                                                                                              
  3 .text.setup   0000000a  00000000  00000000  00000034  2**0                                                                                                                       
                  CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE                                                                                                                       
  4 .text.loop    0000002a  00000000  00000000  0000003e  2**0                                                                                                                       
                  CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE                                                                                                                       
  5 .text.startup.main 0000000e  00000000  00000000  00000068  2**0                                                                                                                  
                  CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE                                                                                                                       
SYMBOL TABLE:                                                                                                                                                                        
00000000 l    df *ABS*  00000000 main.cpp                                                                                                                                            
00000000 l    d  .text  00000000 .text                                                                                                                                               
00000000 l    d  .data  00000000 .data                                                                                                                                               
00000000 l    d  .bss   00000000 .bss
0000003f l       *ABS*  00000000 __SREG__
0000003e l       *ABS*  00000000 __SP_H__
0000003d l       *ABS*  00000000 __SP_L__
00000000 l       *ABS*  00000000 __tmp_reg__
00000001 l       *ABS*  00000000 __zero_reg__
00000000 l    d  .text.setup    00000000 .text.setup
00000000 l    d  .text.loop     00000000 .text.loop
00000000 l    d  .text.startup.main     00000000 .text.startup.main
00000000         *UND*  00000000 __do_copy_data
00000000         *UND*  00000000 __do_clear_bss
00000000 g     F .text.setup    0000000a setup
00000000         *UND*  00000000 pinMode
00000000 g     F .text.loop     0000002a loop
00000000         *UND*  00000000 digitalWrite
00000000         *UND*  00000000 delay
00000000 g     F .text.startup.main     0000000e main
00000000         *UND*  00000000 init


RELOCATION RECORDS FOR [.text.setup]:
OFFSET   TYPE              VALUE 
00000004 R_AVR_CALL        pinMode


RELOCATION RECORDS FOR [.text.loop]:
OFFSET   TYPE              VALUE 
00000004 R_AVR_CALL        digitalWrite
00000010 R_AVR_CALL        delay
00000018 R_AVR_CALL        digitalWrite
00000024 R_AVR_CALL        delay


RELOCATION RECORDS FOR [.text.startup.main]:
OFFSET   TYPE              VALUE 
00000000 R_AVR_CALL        init
00000004 R_AVR_CALL        .text.setup
00000008 R_AVR_CALL        .text.loop
0000000c R_AVR_13_PCREL    .text.startup.main+0x00000008

Coming to my post: wiring.c has a fully configuration. But when those functions are called? If I don't want to call them anymore during execution and/or neither at reset, should I coming back again and write in pure C in an IDE like AtmelStudio? Or there is some kind of control w/out rewriting functions inside wiring.c?

init() is called from main.cpp. The code is all there for you to study and it's really not much at all.

Whether you need to go back to pure C is completely up to you. What's your specific issue that you're trying to solve?

int2str:
Whether you need to go back to pure C is completely up to you.
What’s your specific issue that you’re trying to solve?

First of all, thanks for the help.
For NOW, I just need to explore possibilities and compatibilities of programming rule, if they can be compatible with a pure C approach w/out rewriting Arduino libraries, otherwise the simplification of Wiring goes away and became simpler to use a classical C. For example, is too simple the PWM approach to justifying a newbie to use Wiring language, but what about changing frequency and still using Wiring? I can do that (not now, to be honest, I don’t have any Arduino here right now) because I can simply write in registers (all of them are well declared) and regardless the changing freq will work or not, I trying to understand when the PWM freq default setting is loaded after reset state, so I can know where to put in my code my new setting and make sure that this setting will remain forever until I will choose to change it -explicitly- again.

I hope to be explained :slight_smile:

No any clues at this moment? :)

No any clues at this moment?

I don't even have a clue what your problem is. I think the ball is on your court.

PaulS:

No any clues at this moment?

I don't even have a clue what your problem is. I think the ball is on your court.

Maybe you've lost my latest post :)

This is the central part of problem, that I can't know in advance:

What about changing frequency and still using Wiring? I can do that because I can simply write in registers (all of them are well declared and r/w able) and regardless the change of pwm freqency will work or not, I trying to understand when the PWM freq default setting is loaded after reset state, so I can know where to put in my code my new freq setting and make sure that this setting will remain forever until I will choose to change it -explicitly- again.

It seems to be pretty clear what I'm trying to understand. The ball is yours too now :P

It seems to be pretty clear what I’m trying to understand.

Not to me it isn’t.

What about changing frequency and still using Wiring?

This is an Arduino forum, not a Wiring forum. Which board do you have? What does this question mean?

I trying to understand when the PWM freq default setting is loaded after reset state

When init() gets called (before setup()).

so I can know where to put in my code my new freq setting and make sure that this setting will remain forever until I will choose to change it -explicitly- again.

Anywhere you like. Your code will not be executed until after init() gets called (except for constructors).

Are you telling me that Arduino is NOT using Wiring, based on an open source Java language named Processing.

The IDE is written in Java. The Arduino is not programmed in Java. It is programmed in C++.

PaulS:

Are you telling me that Arduino is NOT using Wiring, based on an open source Java language named Processing.

The IDE is written in Java. The Arduino is not programmed in Java. It is programmed in C++.

Again, tell me how is called that language. I knew that "the Wiring IDE is a cross-platform application written in Java which is derived from the IDE made for the Processing programming language". It's neither C++, libs are witten in C++, you simply use the Wiring interface. You should know that.

Read. http://en.wikipedia.org/wiki/Wiring_(development_platform)

Btw, when you wrote "except for constructors".. WHO are they? Who are constructors? What does it mean constructor?

thexeno: Again, tell me how is called that language.

Read http://en.wikipedia.org/wiki/Arduino

thexeno: Read. http://en.wikipedia.org/wiki/Wiring_(development_platform)

When I read that it says:

Wiring and Processing have spawned another project, Arduino, which uses the Processing IDE, with a simplified version of the C++ language, as a way to teach artists and designers how to program microcontrollers. There are now two separate hardware projects, Wiring and Arduino, using the Wiring environment and language

thexeno: Btw, when you wrote "except for constructors".. WHO are they? Who are constructors? What does it mean constructor?

Read http://en.wikipedia.org/wiki/C%2B%2B or google "C++ constructor"

RbSCR: Read http://en.wikipedia.org/wiki/C%2B%2B or google "C++ constructor"

Oh ok, I see... I'm only an analog electronic engineer, not good enough in programming terms used in C++ (I used it only few times)

There are now two separate hardware projects, Wiring and Arduino, using the Wiring environment and language

Finally one that support my thesis and read my links, Arduino is programmed in WIRING ENVIRONMENT AND LANGUAGE (Arduino is a kind of a comm€rcial spin-off of Wiring). Since it's born from Wiring, use the same tools. Of course, it's another project with other libraries, and of course IS BASED on Wiring, but substantially is Wiring. Writing a dummy row like "digitalWrite(ledPin, HIGH);" is NOT C++ like Paul says. I can't read this blasphemy jajaj This "dummy row" follow the Wiring language with different libraries. And it said even in the Arduino IDE itself, I can't see why should be different. Try to be not manupulated by the market, like someone that the other day said that the Arduino boards are made to barely cover the cost production only because they are "good people" or some excuse like that.

Finally one that support my thesis and read my links, Arduino is programmed in WIRING ENVIRONMENT AND LANGUAGE (Arduino is a kind of a comm€rcial spin-off of Wiring). Since it's born from Wiring, use the same tools. Of course, it's another project with other libraries, and of course IS BASED on Wiring, but substantially is Wiring. Writing a dummy row like "digitalWrite(ledPin, HIGH);" is NOT C++ like Paul says. I can't read this blasphemy jajaj This "dummy row" follow the Wiring language with different libraries. And it said even in the Arduino IDE itself, I can't see why should be different. Try to be not manupulated by the market, like someone that the other day said that the Arduino boards are made to barely cover the cost production only because they are "good people" or some excuse like that.

Is there some point, or relevance even, to your rant?

It simple, I don't like to read fake things on Arduino on the Arduino site. There are too many people that can be manipulated by those (unintentionally) fake informations on this site. And unfortunately I've some reasons to think this. :(

thexeno: Writing a dummy row like "digitalWrite(ledPin, HIGH);" is NOT C++ like Paul says. I can't read this blasphemy jajaj

Huh? That is C++. Haven't we been over this in another thread?

What's a dummy row anyway?

Look:

int main ()
  {
  return 0;
  }

That compiles under the IDE. It generates 176 bytes of code:

Binary sketch size: 176 bytes (of a 32,256 byte maximum)

The libraries are there to help you. Don't use them if you don't want to. The code will be smaller. If you write your own, which do the same things, your code will be larger again.

It simple, I don't like to read fake things on Arduino on the Arduino site.

What fake things? Give an example.

thexeno: But what is not so clear is a guarantee that the C++ functions (alredy included and loaded from the Arduino software core) like the Timer2 init (that is called by default if I understand, for using Millis() function) are not (re)overwrite my configurations, maybe recalling Millis().

Timer 0, not Timer 2.

What configurations?

Should I modify cpp files inside the Arduino core?

You can do whatever you want. It's open source after all.

thexeno: Coming to my post: wiring.c has a fully configuration. But when those functions are called? If I don't want to call them anymore during execution and/or neither at reset, should I coming back again and write in pure C in an IDE like AtmelStudio? Or there is some kind of control w/out rewriting functions inside wiring.c?

You don't want any extra functions called?

int main ()
  {
  return 0;
  }

Done.

In a real C I’ve to include all header files, which your

int main ()
  {
  return 0;
  }

don’t have: everything is still quite hidden, giving a different approach to a pure C. I’ve to digg if I want to see everything even in this case.
You know what was the misunderstanting? PaulS and you might have right, but not because Arduino Language is C/C++, but if you mean that is BASED on it. It is written on this site too (Arduino.cc :slight_smile: ), and is different to me.
That means for me which you don’t have to learn C (applied on MCUs) to use it thanks to the libraries developed ready to help you, learning only -how- to use libraries and not how to create them. You can do it, since all language is no more than high level functions -written- in C, so it’s quite natural that I can write in C too.
“Based on” means that you have some differences, like Setup() and loop(), pre-written in C, which is the goal of the IDE. Of course, you can write in almost-pure C like you said before. In real pure-C environment no one write those things, except for stdio stuff et similia. So, it’s C, but not with a pure approach (if you don’t want to). It’s a slight difference. Under this point PaulS have right, you can use the same language if you want.

But this leads to the next answer:
For fake things I mean someone that says which is able to program a microcontroller and knows C because have used Arduino. Most of them don’t know how to use printf() functions (those famous already made, but are STANDARD functions, not like Arduino ones), are not capable to manage registers in a microcontroller and embarrassing stuff like that, all of this from people saying that are capable to program an MCU, or are not capable to use a Timer because “they never used” it before (never used explicitly, of course), while it is a mandatory knowledge about that. And thise because they was think that this was “pure” C, expecting to have some (and simple) stuff already made, where in some environment is NORMAL (and sometimes mandatory if you need particular configurations) doing it by your self and does not require too much time.

But this leads to the next answer:
configurations are intended like the procedure to follow for setting and activating of USART module, to say one example.

Maybe understanding the difference between BASED ON and IT IS could be the key to understand each other. :slight_smile: In a way I said what you say, but a bit more precise. This little difference is the success of Arduino, one can’t deny that. I’m happy for this, I’ve an Arduino Duemilanove too, but I find ethically right to explain well things. It’s important for newbies or “people who don’t care right know” (i.e. artists w/out a kind of knowledge, of course).

This is the reason why companies don’t use Arduino, and in almost all universities is recommended to be used only for proto-proto-prototyping, translating to see only if the idea work. An MCU pure-C language allows you to predict a single clock cycle, which you can’t in Arduino IDE (this is said by Arduino “staff” makers that work in Turin, during a presentation). Which is fundamental saying that is BASED on C and for learn a good C programming manner is not the best using the IDE. And this is not (only) my idea.

Adding libraries and initialization code doesn't turn the language from "is C" to "is based on C." Nor does automatically providing the base #include files. Microsoft's C#, and EAGLE's ULP language are "based on" C, but Arduino is C (well, C++) It uses a very standard C compiler, and has access to the same avr-libc implementation that you'd be using if you were using Atmel Studio 6 to program the same chips. And the additional Arduino libraries don't make in "not C" any more than using ASF would make it "not C."

"Wiring" isn't "a language based on C", either.

Does that mean you can call yourself a "C Programmer" just because you've compiled the Arduino Examples? No. Nor can you call yourself a "C Programmer" after the typical 1-semester university class that happens to use C.

(I guess you could have an interesting argument about whether avr-g++ is really C++, given that it doesn't have a C++ runtime library...)