PIC, AVR, and Arduino programming in Haiku

That seems very very strange… perhaps the wrong oscillator setting is being used?

Dunno. I used the same makefile and fuse settings as I did from Debian 10. Except the avr build tools in Haiku did not recognize
avr-size --format=avr

That’s the setting I used in Linux. The haiku version gave me a choice of SysV or BSD style. I chose BSD and stopped after I had the success of seeing Haiku blinkenlight auf das protoboard. It was late and I didn’t feel like further pursuits at the time.

# Makefile for programming the ATtiny85
# modified the one generated by CrossPack

DEVICE      = attiny85
CLOCK      = 8000000
PROGRAMMER = -c usbtiny 
OBJECTS    = main.o
# for ATTiny85
# see http://www.engbedded.com/fusecalc/
FUSES       = -U lfuse:w:0x62:m -U hfuse:w:0xdf:m -U efuse:w:0xff:m 

# Tune the lines below only if you know what you are doing:
AVRDUDE = avrdude $(PROGRAMMER) -p $(DEVICE)
COMPILE = avr-gcc -Wall -Os -DF_CPU=$(CLOCK) -mmcu=$(DEVICE)

# symbolic targets:
all:	main.hex

.c.o:
	$(COMPILE) -c $< -o $@

.S.o:
	$(COMPILE) -x assembler-with-cpp -c $< -o $@

.c.s:
	$(COMPILE) -S $< -o $@

flash:	all
	$(AVRDUDE) -U flash:w:main.hex:i

fuse:
	$(AVRDUDE) $(FUSES)

# Xcode uses the Makefile targets "", "clean" and "install"
install: flash fuse

# if you use a bootloader, change the command below appropriately:
load: all
	bootloadHID main.hex

clean:
	rm -f main.hex main.elf $(OBJECTS)

# file targets:
main.elf: $(OBJECTS)
	$(COMPILE) -o main.elf $(OBJECTS)

main.hex: main.elf
	rm -f main.hex
	avr-objcopy -j .text -j .data -O ihex main.elf main.hex
	avr-size --format=avr --mcu=$(DEVICE) main.elf
# If you have an EEPROM section, you must also create a hex file for the
# EEPROM and add it to the "flash" target.

# Targets for code debugging and analysis:
disasm:	main.elf
	avr-objdump -d main.elf

cpp:
	$(COMPILE) -E main.c
// main.c
// 
// A simple blinky program for ATtiny85
// Connect red LED at pin 2 (PB3)
//
// electronut.in

#include <avr/io.h>
#include <util/delay.h>
 
 
int main (void)
{
  // set PB3 to be output
	DDRB = 0b00001000;
  while (1) {
    
    // flash# 1:
    // set PB3 high
    PORTB = 0b00001000; 
    _delay_ms(20);
    // set PB3 low
    PORTB = 0b00000000;
    _delay_ms(20);

    // flash# 2:
    // set PB3 high
    PORTB = 0b00001000; 
    _delay_ms(200);
    // set PB3 low
    PORTB = 0b00000000;
    _delay_ms(200);
  }
 
  return 1;
}

Here is what I changed from the makefile that worked in Linux to the one that barely worked in Haiku.

I’ll try some other settings to see what it does. IIRC, I did not have to make this change to the Makefile in my previous attempts. But previous attempts were totally fruitless.

Apparently avr-size in Haiku doesn’t recognize sysv formatting either.

avr-size is used to print some information about the size of your code. You could remove this line entirely and the makefile would still work.

The problem you had was with writing the fuses, anyway, not with flashing the program itself. So the .hex file isn’t even used for that step.

Probably there is still something wrong with our libusb port and it will somehow not manage to write the fuse data. I had that happen a few times as well here, but usually I got it to work after several retries, or I just flashed the fuses once on another system and then did not need to rewrite them.

2 Likes