diff --git a/Cargo.toml b/Cargo.toml index 46eaddc..f0f132e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,3 +7,9 @@ edition = "2018" [dependencies] # this is broken #ruduino = "0.2" + +[profile.release] +codegen-units = 1 +lto = true +debug = false +opt-level = "s" diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..152e079 --- /dev/null +++ b/Makefile @@ -0,0 +1,30 @@ +.PHONY: upload + +BIN=rust-test +DEVICE=/dev/ttyUSB0 +RELEASE_DIR=target/avr-unknown-gnu-atmega2560/release +ELF=$(RELEASE_DIR)/$(BIN).elf +HEX=$(RELEASE_DIR)/$(BIN).hex +EEP=$(RELEASE_DIR)/$(BIN).eep +SRC=$(wildcard **/*.rs) + +build: $(HEX) + +upload: $(HEX) + avrdude -patmega2560 -cwiring -P$(DEVICE) -b115200 -D -Uflash:w:$(HEX):i + +# rust builds a .elf file +$(ELF): $(SRC) + cargo build --release + +# convert elf to hex for the programmer, pull .eeprom out because that is +# programmed separately +# ihex is short for "intel hex", which is recognized by avrdude +$(HEX): $(ELF) + avr-objcopy -O ihex -R .eeprom $(ELF) $(HEX) + +# pull .eeprom from the elf and create a separate file representing what should +# be written to the eeprom (this file is currently unused in the build process) +# eeprom can also be programmed by avrdude's -U +$(EEP): $(ELF) + avr-objcopy -O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 $(ELF) $(EEP) diff --git a/README.md b/README.md deleted file mode 100644 index fee29b1..0000000 --- a/README.md +++ /dev/null @@ -1,2 +0,0 @@ -basically atmega2560.json is required to be the name because of a bug with -relative paths in dylanmckay/target-cpu-utils diff --git a/avr-unknown-gnu-atmega2560.json b/avr-unknown-gnu-atmega2560.json index 98a18c1..4041977 100644 --- a/avr-unknown-gnu-atmega2560.json +++ b/avr-unknown-gnu-atmega2560.json @@ -11,7 +11,8 @@ "late-link-args": { "gcc": [ "-lgcc", - "-lc" + "-lc", + "-flto" ] }, "linker": "avr-gcc", @@ -24,7 +25,8 @@ "pre-link-args": { "gcc": [ "-mmcu=atmega2560", - "-Wl,--as-needed" + "-Wl,--as-needed", + "-Wl,--gc-sections" ] }, "target-c-int-width": "16",