makefile: Add ability to flash binary to microcontroller

This commit is contained in:
Alexander Heldt
2024-07-28 11:52:54 +02:00
parent 5b5da238d5
commit 278d3cfb9d
3 changed files with 9 additions and 0 deletions

1
.gitignore vendored
View File

@@ -1,2 +1,3 @@
.direnv/ .direnv/
.ccls-cache/ .ccls-cache/
build/*.bin

View File

@@ -33,6 +33,9 @@ OBJ_FILES := $(patsubst $(BUILD_DIR)/%.S,$(BUILD_DIR)/%.o,$(ASM_FILES))
.PHONY: build .PHONY: build
build: builddir preprocess compile assemble $(BUILD_DIR)/$(TARGET).elf build: builddir preprocess compile assemble $(BUILD_DIR)/$(TARGET).elf
$(BUILD_DIR)/$(TARGET).bin: $(BUILD_DIR)/$(TARGET).elf
arm-none-eabi-objcopy -O binary $< $@
$(BUILD_DIR)/$(TARGET).elf: $(OBJ_FILES) $(BUILD_DIR)/$(TARGET).elf: $(OBJ_FILES)
$(CC) $(LDFLAGS) $^ -o $@ $(CC) $(LDFLAGS) $^ -o $@
@@ -58,6 +61,10 @@ compile: preprocess $(ASM_FILES)
.PHONY: assemble .PHONY: assemble
assemble: compile $(OBJ_FILES) assemble: compile $(OBJ_FILES)
.PHONY: flash
flash: $(BUILD_DIR)/$(TARGET).bin
st-flash --reset write $< 0x8000000
.PHONY: clean .PHONY: clean
clean: clean:
rm -rf $(BUILD_DIR) rm -rf $(BUILD_DIR)

View File

@@ -23,6 +23,7 @@
packages = [ packages = [
pkgs.gnumake pkgs.gnumake
pkgs.gcc-arm-embedded pkgs.gcc-arm-embedded
pkgs.stlink
]; ];
}; };
} }