Go Down

Topic: Coding arduino with arduino as isp in assembly (Read 1 time) previous topic - next topic

microheru

I want to program one arduino board through another. There's a straightforward way in the arduino tutorial page here:
https://www.arduino.cc/en/tutorial/arduinoISP
As I understood, the procedure is:
1. Uploading the sketch ArduinoISP to the first board and turning it to a programmer.
2. Choosing the "Arduino as ISP" option from tools menu, so that arduino IDE knows that I want my program to pass through the first board and sit on the programmed board.
3. Choosing the name of the programmed board instead of programmer board, so that the IDE recognizes the bootloader it's going to communicate with.
But what if I want to program one arduino through another with assembly code instead of arduino code?
Is arduino IDE capable of uploading assembly code to the programmed board? If it isn't, which software should I use?
Is the existing bootloader on the programmed board a barrier to upload assembly code on the board? If so, how can I get rid of it?
I would appreciate it, if you explain the whole procedure of uploading assembly code to the second board.
If it's possible to program the board directly, without using another arduino as a programmer, it also would be great.


Juraj

#1
Mar 03, 2019, 08:51 pm Last Edit: Mar 03, 2019, 08:52 pm by Juraj
I want to program one arduino board through another. There's a straightforward way in the arduino tutorial page here:
https://www.arduino.cc/en/tutorial/arduinoISP
As I understood, the procedure is:
1. Uploading the sketch ArduinoISP to the first board and turning it to a programmer.
2. Choosing the "Arduino as ISP" option from tools menu, so that arduino IDE knows that I want my program to pass through the first board and sit on the programmed board.
3. Choosing the name of the programmed board instead of programmer board, so that the IDE recognizes the bootloader it's going to communicate with.
But what if I want to program one arduino through another with assembly code instead of arduino code?
Is arduino IDE capable of uploading assembly code to the programmed board? If it isn't, which software should I use?
Is the existing bootloader on the programmed board a barrier to upload assembly code on the board? If so, how can I get rid of it?
I would appreciate it, if you explain the whole procedure of uploading assembly code to the second board.
If it's possible to program the board directly, without using another arduino as a programmer, it also would be great.


compiled binary in form of hex file is send to the MCU. here no one cares how the hex was build.
it applies to ISP and over bootloader upload.

pert

Is arduino IDE capable of uploading assembly code to the programmed board? If it isn't, which software should I use?
After a little bit of preprocessing, the .ino files of the Arduino IDE's sketches are C++. You can add inline assembly to your sketch code by wrapping the assembly in asm(). However, I don't think that's what you're interested in. What might be more interesting to you is that the Arduino IDE does allow you to add assembly files (.S) to your sketch. You still need to have at least one .ino file in the sketch, but you can have as much assembly as you like in additional .S files added to the sketch. Here is a simple demonstration of doing that:
https://forum.arduino.cc/index.php?topic=413151

If you don't want to deal with the .ino file, you will not be able to use the Arduino IDE. However, you can use the avr-gcc compiler that comes with the Arduino IDE to compile your assembly into a .hex file you can upload to the Arduino board. You can see the compilation commands the Arduino IDE generates by enabling File > Preferences > Show verbose output during: compilation, compiling a sketch (preferrably with a .S file) and then examining the contents of the black console window at the bottom of the Arduino IDE window (scroll up to see it all). You can copy those commands, modify them as you like, and run them from the command line.

Is the existing bootloader on the programmed board a barrier to upload assembly code on the board?
No.

how can I get rid of it?
The Arduino IDE has a feature: Sketch > Upload Using Programmer. The upload command for Upload Using Programmer will erase the bootloader. You can see this command by enabling File > Preferences > Show verbose output during: Upload, doing an Upload Using Programmer, and then examining the contents of the console window.

If it's possible to program the board directly, without using another arduino as a programmer, it also would be great.
For that, you do need the bootloader. The Arduino IDE will upload via the bootloader when you do a standard upload (Sketch > Upload) You can see this command by enabling File > Preferences > Show verbose output during: Upload, doing an Upload, and then examining the contents of the console window.

GoForSmoke

I want to program one arduino board through another. There's a straightforward way in the arduino tutorial page here:
https://www.arduino.cc/en/tutorial/arduinoISP
I made that work for a short while, it was the hard way. I had to hack my core files to replace the 328P-PA chip ID with the 328P-PU ID. The -PA cost almost 50% more in 2012.

Then Nick Gammon made his software and tutorial, it identifies many different AVR's and does them right.
He covers options, custom cabling, and uses "The Mighty" 1284P (intermediate step towards a Mega) as a second example.

 http://www.gammon.com.au/breadboard

I'd use his software to program AVR's on boards, if they don't have ICSP they should have SPI pins. I can find out for sure what I've got and have options on what to do with it.

In another tutorial he builds a hex file from SD loader and Cross Roads Electronics sells finished versions of their cooperation.
1) http://gammon.com.au/blink  <-- tasking Arduino 1-2-3
2) http://gammon.com.au/serial <-- techniques howto
3) http://gammon.com.au/interrupts
Your sketch can sense ongoing process events in time.
Your sketch can make events to control it over time.

alesam

#4
Mar 04, 2019, 05:35 am Last Edit: Mar 04, 2019, 05:36 am by alesam
But what if I want to program one arduino through another with assembly code instead of arduino code?
Is arduino IDE capable of uploading assembly code to the programmed board? If it isn't, which software should I use?
Is the existing bootloader on the programmed board a barrier to upload assembly code on the board? If so, how can I get rid of it?


You can't "program" arduino with assembler code as well as by "arduino code". When you do "programming  arduino by another arduino" you are flashing a binary file. You need a second arduino to avoid using of bootloader. With bootloader involved you don't need a second arduiono to do the same task-  flash a binary code to  arduino. Binary code can be produced by compiling C++ code as Arduion IDE does, or you can produce it from assembler code using gcc. To flash a binary code Arduino IDE invokes a avrdude programmer.
Don't say "Thank you", just click on 'karma [add]' instead.

pert

I had to hack my core files to replace the 328P-PA chip ID with the 328P-PU ID. The -PA cost almost 50% more in 2012.
Are you sure about those model numbers? I've never heard of the ATmega328P-PA and I can't imagine that it would have a different chip signature from the ATmega328P-PU.

Anyway, MiniCore now provides support for all variations and common configurations of the ATmega328. No "hacking" necessary:
https://github.com/MCUdude/MiniCore
But for the ATmega328P, the standard Arduino AVR Boards that comes with the Arduino IDE does provide a reasonable level of support via the Uno, Pro Mini, and other board definitions.

Then Nick Gammon made his software and tutorial, it identifies many different AVR's and does them right.
I like the breadboard part of the Nick Gammon tutorial but I don't see any point in using that software Nick Gammon wrote. It's much more flexible to learn the real way to use an ISP programmer via the Arduino IDE, as shown in https://www.arduino.cc/en/tutorial/arduinoISP.

GoForSmoke

Are you sure about those model numbers? I've never heard of the ATmega328P-PA and I can't imagine that it would have a different chip signature from the ATmega328P-PU.
Oh, well if YOU can't imagine it then it must not be true. OTOH you could check and find out that it is and that every variant has its own ID and that bootloader software that is around now wasn't around too very long ago.

Quote
It's much more flexible to learn the real way to use an ISP programmer via the Arduino IDE, as shown in https://www.arduino.cc/en/tutorial/arduinoISP.
I found Nick's explanations of the process to be more complete but then I didn't limit myself to a quick skim of one tutorial. The Arduino material is the first I went through btw but that's changed a little too.

Showing how to program AVR chips with the dev board you have and not need to buy a special thing is good, not bad.

1) http://gammon.com.au/blink  <-- tasking Arduino 1-2-3
2) http://gammon.com.au/serial <-- techniques howto
3) http://gammon.com.au/interrupts
Your sketch can sense ongoing process events in time.
Your sketch can make events to control it over time.

pert

OTOH you could check and find out that it is
I did check via a Google search and didn't find anything about this mysterious ATmega328P-PA other than a previous post of yours on the forum. If I have to make the choice between believing that nobody else in the history of the Internet has ever mentioned this microcontroller, or that you got it wrong, guess which I'll go with.

every variant has its own ID
Most variants have their own signature. For example, the ATmega328 has a different signature (0x1E 0x95 0x14) from the ATmega328P (0x1E 0x95 0x0F). However, the part of the model number after the - typically only denotes the package type or operational range, and I have never seen an AVR which has different signature bytes at that level of specificity.

Showing how to program AVR chips with the dev board you have and not need to buy a special thing is good, not bad.
I agree. Both tutorials do that. However, the knowledge you gain learning to use the Arduino as ISP programmer will also apply if you end up eventually spending a couple bucks to buy a dedicated programmer.

GoForSmoke

I did check via a Google search and didn't find anything about this mysterious ATmega328P-PA other than a previous post of yours on the forum. If I have to make the choice between believing that nobody else in the history of the Internet has ever mentioned this microcontroller, or that you got it wrong, guess which I'll go with.]/quote]

Yes, it is the ATmega328PA or the ATmega328P-AU vs the ATmega328P-PU that cost less.

WOW! Now everybody else in all of history is SAFE AGAIN now that fantastic YOU has saved them! Yaaaaay!

Quote
Most variants have their own signature. For example, the ATmega328 has a different signature (0x1E 0x95 0x14) from the ATmega328P (0x1E 0x95 0x0F). However, the part of the model number after the - typically only denotes the package type or operational range, and I have never seen an AVR which has different signature bytes at that level of specificity.
Well I did the first times I tried. I am so VERY GLAD THAT YOU DID NOT HELP ME THEN. You would have failed me whereas the members here pointed out what to do and did not count their I-don't-know ignorance for it-can't-be knowledge.

The ATmega328P that came on my first Uno has a different chip ID than the ATmega328P-PU I bought. Perhaps ATMEL made a mistake not consulting with you on their decision.

Quote
I agree. Both tutorials do that. However, the knowledge you gain learning to use the Arduino as ISP programmer will also apply if you end up eventually spending a couple bucks to buy a dedicated programmer.
If you think so it must be. But then you think funny things about chip ID's and your own expertise that aren't real too.
1) http://gammon.com.au/blink  <-- tasking Arduino 1-2-3
2) http://gammon.com.au/serial <-- techniques howto
3) http://gammon.com.au/interrupts
Your sketch can sense ongoing process events in time.
Your sketch can make events to control it over time.

pert

Yes, it is the ATmega328PA or the ATmega328P-AU vs the ATmega328P-PU that cost less.
I had to hack my core files to replace the 328P-PA chip ID with the 328P-PU ID. The -PA cost almost 50% more in 2012.
It's hilarious how you try to slip in the correction that you actually meant ATmega328PA instead of ATmega328P-PA (as I suspected from the start), without actually admitting you were wrong. Very classy.

GoForSmoke

#10
Mar 05, 2019, 01:08 pm Last Edit: Mar 05, 2019, 01:13 pm by GoForSmoke
Quote
I did check via a Google search and didn't find anything about this mysterious ATmega328P-PA other than a previous post of yours on the forum. If I have to make the choice between believing that nobody else in the history of the Internet has ever mentioned this microcontroller, or that you got it wrong, guess which I'll go with.
Quote
Yes, it is the ATmega328PA or the ATmega328P-AU vs the ATmega328P-PU that cost less.
It's hilarious how you try to slip in the correction that you actually meant ATmega328PA instead of ATmega328P-PA (as I suspected from the start), without actually admitting you were wrong. Very classy.

And there you go misrepresenting again. What I did not do was kiss your sorry trivial ass.

The fact that you'll go so far over so little tells so much about you. But facts do come through and now you've read that different AVR's have different chip ID's, and they never checked with you first.

1) http://gammon.com.au/blink  <-- tasking Arduino 1-2-3
2) http://gammon.com.au/serial <-- techniques howto
3) http://gammon.com.au/interrupts
Your sketch can sense ongoing process events in time.
Your sketch can make events to control it over time.

westfw

Geez; aren't you guys old and experienced enough not to let this sort of thing get this far out of hand?

The parts of the part-number after the dash usually refer to the package type, which AFAIK never affects the device signature.

AFACT, There has never been at ATmega328PA.   The ATmega328 (no P) had s different signature from the ATmega328P, despite relatively trivial differences.  (Compare to ATmega644 vs 644A, where the A-version kept the SAME signature but added a whole SECOND UART!)

The ATmega168 and ATmega168A had the same signature, different than the ATmega168PA.  There has never been an ATmega168P.

There is now an ATmega328PB with MANY NEW FEATURES, and it has a different signature than the 328P.
There is also a 168PB (88PB and 48PB too!) with different signatures from their "parents", but WITHOUT most of the new features that are in the 328PB.

In short, Atmel part numbering vs internal device signatures vs features is a bit of a mess, and has always been a mess.  (and now we can add that Microchip is changing the actual physical labeling of chips themselves to the confusion.)   Sigh.

(None of which has much to do with the original question, which I thought was answered adequately back in reply #1...)

GoForSmoke

Then which chip went in 2011 Uno's? It has a different ID from the -PU that I had to look up and hack into a core file.

I'm sure of the -PU because that's what I bought, the price was discount compared to the Arduino chip.

And when I search on it, the -PU appears to be an exception, the pink house on a white house street?

Please, is that the only chip signature exception?

1) http://gammon.com.au/blink  <-- tasking Arduino 1-2-3
2) http://gammon.com.au/serial <-- techniques howto
3) http://gammon.com.au/interrupts
Your sketch can sense ongoing process events in time.
Your sketch can make events to control it over time.

Go Up