When I program my AT90USBKEY2 with dfu-programmer, the delays are wrong until I restart the board by unplugging it.
#include <avr/io.h>
#include <util/delay.h>
int main(void) {
DDRD = 0xF0;
while(1) {
PORTD |= 0xF0;
_delay_ms(100);
PORTD &= 0x0F;
_delay_ms(100);
}
}
A simple program. F_CPU
is defined in the makefile.
Makefile I am not proud of does these steps:
avr-gcc -Wall -Os -DF_CPU=1000000 -mmcu=at90usb1287 -c blink.c -o blink.o
avr-gcc -Wall -Os -DF_CPU=1000000 -mmcu=at90usb1287 -o blink.elf blink.o
avr-objcopy -j .text -j .data -O ihex blink.elf blink.hex
dfu-programmer at90usb1287 erase
dfu-programmer at90usb1287 flash blink.hex
dfu-programmer at90usb1287 reset
Reading pin 6 of port D shows this:
15.6 ms high, 63.2 low.
After bouncing power, and any time it's started after that
100ms high and low, the correct timing.
I also tried a pin on port A that isn't tied to an onboard LED, same results.
avrdude: safemode: Fuses OK (E:F3, H:99, L:5E)
Am I doing something clearly wrong, or is it just accepted that I have to unplug the board after programming?
It seems like this might just be an issue where the reset button/dfu-programmer reset
doesn't reset it properly.
I don't know how that works yet, will update when I learn more.
Though bouncing the thing after programming isn't the worst.