Using Arduino code on a DIY board?

I have been programming Atmel processors for over 10 years with other development packages and I have all the chip programming tools.

Now is there a way to take an Arduino Uno project and program the hex code into a raw MEGA328 that does not contain the Arduino boot loader? Again I have an official SPI programmer.

I assume just putting a raw MEGA 328 in a Uno board won't work as the boot loader is missing on the raw chip.

And I would rather not have the Arduino boot loader in the final product release.

Yes.

Consider this:

Yes you can. It is however important that you set the fuses correctly. A raw board 328 runs on an 8 MHz internal crystal, an Uno on a 16MHz external crystal. The easy way is to first burn the Uno bootloader via ICSP; it's a once-off exercise for the board.

Once the fuses are set you can upload the program via ISCP using "upload using programmer" in the IDE; this will wipe the bootloader but will not have an effect on the fuses.

It also should be possible to set the fuses directly while uploading a sketch via ICSP; this can't be done from the IDE but with a correct AVRdude command on the command line. I've never done that.

2 Likes

Yes, you can upload Arduino code to a raw ATMEGA328 using the Arduino IDE using various ICSP programmers. Whether it will work with your particular programmer I don't know but I believe it works with standard ATMEL ICSP programmers. This method does not install a bootloader. The bootloader is only useful if you want to use serial (UART) programming.

What you will need to use is an Arduino "core". A core is a set of libraries/functions which provide the standard Arduino functions like digitalWrite() and millis(). Cores for the common Arduino models like Uno and Nano are pre-installed in the IDE. You will need to install a core for your bare ATMEGA328. I recommend this one:

Yes, just take the .hex file and program into a raw Mega328.

The BOOTRST and IVSEL fuses default to "no bootloader". Application code always starts at 0x0000, so the .hex file generated by the Arduino IDE is compatible. I think the only caveat is that the Arduino will subtract the bootloader size from the Flash size when calculating the size available for the application.

Of course, you need to set other fuses appropriate for your DIY board.

These two statements seem to contradict each other.
If you don't want the bootloader then why do you want to plug it into an Uno board?

I have AVR Studio4 which has all the fuse programming functions as well as options to program EEPROM and Flash memory separately if desired.

But where is the .hex file? All I have is the windows executable .ino file.

I also noted the IDE supports the AVR ISP programmer which is what I have. The question is do I need a boot loader installed to use that?

Ah, it's in the temporary sketch folder. If you look at the verbose compiler output :

Compiling sketch...
"C:\\Users\\bobco\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-g++" -c -g -Os -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\\Users\\bobco\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.6\\cores\\arduino" "-IC:\\Users\\bobco\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.6\\variants\\standard" "-Ic:\\Users\\bobco\\OneDrive\\Documents\\Arduino\\libraries\\AccelStepper\\src" "C:\\Users\\bobco\\AppData\\Local\\Temp\\arduino\\sketches\\22B81D59569AD80942065F917515010E\\sketch\\test_cnc_shield_accelstepper.ino.cpp" -o "C:\\Users\\bobco\\AppData\\Local\\Temp\\arduino\\sketches\\22B81D59569AD80942065F917515010E\\sketch\\test_cnc_shield_accelstepper.ino.cpp.o"
Compiling libraries...
Compiling library "AccelStepper"
Using previously compiled file: C:\Users\bobco\AppData\Local\Temp\arduino\sketches\22B81D59569AD80942065F917515010E\libraries\AccelStepper\AccelStepper.cpp.o
Using previously compiled file: C:\Users\bobco\AppData\Local\Temp\arduino\sketches\22B81D59569AD80942065F917515010E\libraries\AccelStepper\MultiStepper.cpp.o
Compiling core...
Using precompiled core: C:\Users\bobco\AppData\Local\Temp\arduino\cores\arduino_avr_uno_6ebe88981b21de8662fca0b4e514ff97\core.a
Linking everything together...
"C:\\Users\\bobco\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-gcc" -Os -g -flto -fuse-linker-plugin -Wl,--gc-sections -mmcu=atmega328p -o "C:\\Users\\bobco\\AppData\\Local\\Temp\\arduino\\sketches\\22B81D59569AD80942065F917515010E/test_cnc_shield_accelstepper.ino.elf" "C:\\Users\\bobco\\AppData\\Local\\Temp\\arduino\\sketches\\22B81D59569AD80942065F917515010E\\sketch\\test_cnc_shield_accelstepper.ino.cpp.o" "C:\\Users\\bobco\\AppData\\Local\\Temp\\arduino\\sketches\\22B81D59569AD80942065F917515010E\\libraries\\AccelStepper\\AccelStepper.cpp.o" "C:\\Users\\bobco\\AppData\\Local\\Temp\\arduino\\sketches\\22B81D59569AD80942065F917515010E\\libraries\\AccelStepper\\MultiStepper.cpp.o" "C:\\Users\\bobco\\AppData\\Local\\Temp\\arduino\\sketches\\22B81D59569AD80942065F917515010E/..\\..\\cores\\arduino_avr_uno_6ebe88981b21de8662fca0b4e514ff97\\core.a" "-LC:\\Users\\bobco\\AppData\\Local\\Temp\\arduino\\sketches\\22B81D59569AD80942065F917515010E" -lm
"C:\\Users\\bobco\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-objcopy" -O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 "C:\\Users\\bobco\\AppData\\Local\\Temp\\arduino\\sketches\\22B81D59569AD80942065F917515010E/test_cnc_shield_accelstepper.ino.elf" "C:\\Users\\bobco\\AppData\\Local\\Temp\\arduino\\sketches\\22B81D59569AD80942065F917515010E/test_cnc_shield_accelstepper.ino.eep"
"C:\\Users\\bobco\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-objcopy" -O ihex -R .eeprom "C:\\Users\\bobco\\AppData\\Local\\Temp\\arduino\\sketches\\22B81D59569AD80942065F917515010E/test_cnc_shield_accelstepper.ino.elf" "C:\\Users\\bobco\\AppData\\Local\\Temp\\arduino\\sketches\\22B81D59569AD80942065F917515010E/test_cnc_shield_accelstepper.ino.hex"

Using library AccelStepper at version 1.64 in folder: C:\Users\bobco\OneDrive\Documents\Arduino\libraries\AccelStepper 
"C:\\Users\\bobco\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-size" -A "C:\\Users\\bobco\\AppData\\Local\\Temp\\arduino\\sketches\\22B81D59569AD80942065F917515010E/test_cnc_shield_accelstepper.ino.elf"
Sketch uses 7722 bytes (23%) of program storage space. Maximum is 32256 bytes.
Global variables use 528 bytes (25%) of dynamic memory, leaving 1520 bytes for local variables. Maximum is 2048 bytes.

Here the temp folder is

C:\Users\bobco\AppData\Local\Temp\arduino\sketches\22B81D59569AD80942065F917515010E

(There may be a shortcut to get to this folder, but I don't know what it is)

If you open that folder there is a file ending ".ino.hex".

No, it programs the chip directly bypassing the bootloader.

If you don't want to use the IDE for the upload using programmer, you can use Sketch → Export Compiled Binary. In IDE 1.x this will dump the hex file in the sketch directory, in IDE 2.x this will dump it in the build directory in the sketch directory.

Note:
An ino file is not an executable.

1 Like

I answered that question for you already. Why ask if you are not going to read or not going to believe the answers?

Just verifying if the Uno board always needs a bootloader as it has the extra processor for the USB port.

I do read all the answers. But different responses here seem to contradict each other. Post# 5, that says just load the .HEX file in the chip and of course set the fuses correctly.

You are suggesting the core package from GIT. So do I need that core package or can I just dump the raw .HEX as suggested in post 5?

Note that I don't need IDE access to the final embedded Mega328. If I need to modify the code I will still use the Uno board and then just reprogram the target 328 with the new hex file.

Hi @andy_ee.

The "core package" (the correct term is actually "platform") adds support to Arduino IDE for a specific board model or microcontroller. You need an appropriate platform if you want to use Arduino IDE to compile sketches for, or upload to, a given board.

However, if you aren't using Arduino IDE, then the platform is not required.

If you want to use the Uno as an Uno and be able to program it via the USB port,then yes, you need the bootloader

I am developing the code on an Uno board, using Arduino libraries, and will code and test updates on the Uno as well.

But the final product will not have Arduino support. Just the raw Hex file programmed into a Mega328. But of course that HEX file will need any Arduino libraries included in the binary code, which I assume has to be the case in a HEX file.

I have the Atmel/Intel hardware tools to program Atmel chips in the standard SPI mode. I have developed many projects with another compiler package (ICC AVR) which is just a C compiler that generates HEX files. No interactive IDE per se. So I fully understand the physical HEX file programming procedures.

If you are using Arduino IDE for that purpose, you need to have an appropriate platform installed.

You can use Arduino IDE's "Upload Using Programmer" feature to flash the hex file to the board using the programmer if you like. In this case, you need to have an appropriate platform installed.

Or you can use some other tool (e.g., AVRDUDE) to program the chip directly instead of using Arduino IDE. In this case, an Arduino boards platform is not relevant.

Thanks,

I have AVRstudio4 and the latest Microchip Studio with the serial and USB 10/6pin SPI programming pods.

(I have to use the serial pod for the old AT90S8515 40pin DIP processor as the USB pod does not support that legacy device)

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.