Standalone Atmega32u4 pro micro 5 times slower without bootloader.

I have few fresh atmega32u4 blank micros without any bootloader. I observed that when i upload sketch to blank chip without burning bootloader and use delay(1000); it gives 5 second delay instead 1 second. If i upload bootloader from arduino IDE and then upload same sketch using ICSP header then it works fine. I always though when you upload something using ICSP header it will flush everything. Then why it matters to upload bootloader first? And is there anyway to make t work correctly without ever uploading bootloader? Thank you

CKDIV8 fuse.

To program an atmega328p I use two steps, first set the fuse and then load the firmware application. So with avrdude installed on Ubuntu or Pi.

avrdude -v -p atmega328p -c stk500v1 -P /dev/ttyACM0 -b 19200 -e -U lock:w:0x3f:m -U lfuse:w:0xFF:m -U hfuse:w:0xDE:m -U efuse:w:0xFD:m
avrdude -v -p atmega328p -c stk500v1 -P /dev/ttyACM0 -b 19200 -e -U flash:w:optiboot_atmega328.hex -U lock:w:0x2f:m

The application firmware, in this case, is a bootloader, but it can be anything. Also I put these in a Makefile to keep track of the commands and not have to type them.

# Makefile 
# Use this to flash a serial bootloader
# hexfile is from https://github.com/Optiboot/optiboot
TARGET = Bootloader
LIBDIR = ../lib
OBJECTS = 

## programing ports. the FTDI on my board shows as ttyUSBx, while an Uno shows as ttyACMx
## /dev/ttyUSB0
##/dev/ttyACM0

all:

$(TARGET):

## http://eleccelerator.com/fusecalc/fusecalc.php?chip=atmega328p&LOW=FF&HIGH=DE&EXTENDED=05&LOCKBIT=2F
## stk500v1 is for Arduino as ISP (e.g. it is an example in the Arduino.cc IDE 1.6.7+)
## lock is from optiboot's Makefile.isp, 
fuse: 
 avrdude -v -p atmega328p -c stk500v1 -P /dev/ttyACM0 -b 19200 -e -U lock:w:0x3f:m -U lfuse:w:0xFF:m -U hfuse:w:0xDE:m -U efuse:w:0xFD:m

## 328p can lock the bootloader section
isp:
 avrdude -v -p atmega328p -c stk500v1 -P /dev/ttyACM0 -b 19200 -e -U flash:w:optiboot_atmega328.hex -U lock:w:0x2f:m

The main oddness (trick) to using a make file is remembering the leading tab.

You can also fish around in the IDE files and hack it to do your bidding, but frankly, someone would have to pay me to do that.

Thanks for suggestions. It was helpful. I just found that arduino generated 2 hex files. One regular XYZABC.ino.hex and One XYZABC.ino.with_bootloader.hex. I opened both files to compare them. I found XYZABC.ino.with_bootloader.hex has bootloader part attached after application part. I always thought first you need bootloader and then you upload application. Does it matter?

In Arduino Land, the usual thing to do is the Burn Bootloader option in the IDE. That installs the bootloader and sets the fuses to the normal value for the board. Then if you upload a sketch using ISP (the Upload Using Programmer option on the IDE menu) the chip is erased and the sketch loaded (without the bootloader). The fuses are not altered during the chip erase.

So, you may see people mention that you need to burn the bootloader on new chips, and then upload sketches to them, they are just saying that because burning the bootloader is the convenient way to set the fuses. If you don't use the IDE or don't want to burn the bootloader that is fine, go ahead and set the fuses separately.

Thanks dmjlambert. I am using it for mass production. So I was trying to upload everything in a single step.

parthk:
Thanks dmjlambert. I am using it for mass production. So I was trying to upload everything in a single step.

In that case the sketch+bootloader file won't help you. You need to set the fuses, in particular you need to unprogram CLKDIV8. The Arduino IDE does this as part of its process when you click "Burn Bootloader", but its a separate step that happens before the bootloader file is actually uploaded. The bootloader code is irrelevant.

To do everything I would just add another rule to the Makefile.

# Makefile 
# Use this to flash a serial bootloader
# hexfile is from https://github.com/Optiboot/optiboot
TARGET = Bootloader
LIBDIR = ../lib
OBJECTS = 

## programing ports. the FTDI on my board shows as ttyUSBx, while an Uno shows as ttyACMx
## /dev/ttyUSB0
##/dev/ttyACM0

all:

$(TARGET):

## http://eleccelerator.com/fusecalc/fusecalc.php?chip=atmega328p&LOW=FF&HIGH=DE&EXTENDED=05&LOCKBIT=2F
## stk500v1 is for Arduino as ISP (e.g. it is an example in the Arduino.cc IDE 1.6.7+)
## lock is from optiboot's Makefile.isp, 
fuse: 
	avrdude -v -p atmega328p -c stk500v1 -P /dev/ttyACM0 -b 19200 -e -U lock:w:0x3f:m -U lfuse:w:0xFF:m -U hfuse:w:0xDE:m -U efuse:w:0xFD:m

## 328p can lock the bootloader section
isp:
	avrdude -v -p atmega328p -c stk500v1 -P /dev/ttyACM0 -b 19200 -e -U flash:w:blink_atmega328.hex -U lock:w:0x2f:m

fullauto:
	fuse
	isp

"make fullauto" should then run the fuse rule followed by the isp rule. That can be further automated by a shell script or a program (e.g. Python, Perl, or whatever flips your switch) perhaps as part of a production final test.

And why not send the assembly house a Pi to run it from, (that is funny, I never even considered it till just now).