# HG changeset patch # User Tero Marttila # Date 1396455005 -10800 # Node ID 7f930a94ee1ed2b3cac458d021a23f80bff520e3 # Parent ffb0c3ec9bc034980f319bf599cce298db29eeb9 bravely step into the modern world of C-programming, using avr-gcc for a hello world... diff -r ffb0c3ec9bc0 -r 7f930a94ee1e .hgignore --- a/.hgignore Tue Aug 02 09:27:19 2011 +0300 +++ b/.hgignore Wed Apr 02 19:10:05 2014 +0300 @@ -1,7 +1,11 @@ -syntax: regexp - +syntax: glob -\.(swo|swp)$ -\.(hex|s.cof|s.eep.hex|s.obj)$ +.*.swo +.*.swp -^docs/ +*.hex +*.elf + +*.s.* + +docs/ diff -r ffb0c3ec9bc0 -r 7f930a94ee1e Makefile --- a/Makefile Tue Aug 02 09:27:19 2011 +0300 +++ b/Makefile Wed Apr 02 19:10:05 2014 +0300 @@ -1,6 +1,47 @@ +PROG = hello +# console +# dmx + +all: $(PROG).hex + +## Compiler +MCU = atmega328p + +# CPU clock frequency +CPU = 16000000 + +CC = avr-gcc +CFLAGS = -g -mmcu=$(MCU) -DF_CPU=$(CPU)UL -Os + +%.elf: %.c + $(CC) $(CFLAGS) -o $@ $+ + +%.hex: %.elf + avr-objcopy -O ihex -R .eeprom $< $@ + +.PRECIOUS: %.elf + +## Assembler AS = avra ASFLAGS = +matrix.hex: spi.inc matrix.inc timer.inc delay.inc macros.inc font.inc font.def +led7seg.hex: spi.inc led7seg.inc adc.inc timer.inc delay.inc macros.inc +timer.hex: timer.inc macros.inc + +%.hex: %.s + $(AS) $(ASFLAGS) $< + mv $<.hex $@ + +# fonts +font.inc: font.def + +font.def: font.txt font-compile.py + python font-compile.py $< $@ > /dev/null + + +## Flashing +# Arduino Duemilanove AD_PART = m328p AD_PROG = arduino AD_BAUD = 57600 @@ -9,26 +50,10 @@ AD = avrdude ADFLAGS = -p $(AD_PART) -c $(AD_PROG) -b $(AD_BAUD) -P $(AD_PORT) -PROG = dmx - -all: $(PROG).hex - -matrix.hex: spi.inc matrix.inc timer.inc delay.inc macros.inc font.inc font.def -led7seg.hex: spi.inc led7seg.inc adc.inc timer.inc delay.inc macros.inc -timer.hex: timer.inc macros.inc - -font.inc: font.def - -%.hex: %.s - $(AS) $(ASFLAGS) $< - mv $<.hex $@ - -font.def: font.txt font-compile.py - python font-compile.py $< $@ > /dev/null - upload: $(PROG).hex $(AD) $(ADFLAGS) -U flash:w:$< +## Console SERIAL_BAUD = 9600 SERIAL_FLOW = n SERIAL_PARITY = n @@ -38,6 +63,6 @@ SERIAL_TERM = picocom SERIAL_FLAGS = -b $(SERIAL_BAUD) -f $(SERIAL_FLOW) -p $(SERIAL_PARITY) -d $(SERIAL_BITS) -chat: +console: $(SERIAL_TERM) $(SERIAL_FLAGS) $(SERIAL_PORT) diff -r ffb0c3ec9bc0 -r 7f930a94ee1e README.md --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/README.md Wed Apr 02 19:10:05 2014 +0300 @@ -0,0 +1,14 @@ +## Dependencies +* avrdude +* avra +* picocom +* gcc-avr +* avr-libc + +## USB +Configure udev for the `/dev/arduino` symlink. + +### /etc/udev/rules.d/09-arduino.rules + # /dev/arduino + SUBSYSTEMS=="usb", ATTRS{product}=="FT232R USB UART", ATTRS{idProduct}=="6001", ATTRS{idVendor}=="0403", SYMLINK+="arduino arduino_$attr{serial}" + diff -r ffb0c3ec9bc0 -r 7f930a94ee1e hello.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/hello.c Wed Apr 02 19:10:05 2014 +0300 @@ -0,0 +1,22 @@ +#include +#include + +#define false 0 +#define true 1 + +#define SBI(port, bit) do { port |= (1 << (bit)); } while (0) +#define CBI(port, bit) do { port &= ~(1 << (bit)); } while (0) + +int main (void) +{ + // LED + SBI(DDRB, DDB5); + + while (true) { + // flip + PORTB ^= (1 << PORTB5); + + // busyloop + _delay_ms(1000); + } +}