commit c119ec0f82b0da4df7dbf91458333d748c1fae60 Author: kr rt Date: Thu Oct 26 23:38:08 2023 +0300 first commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a8a0dce --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.bin diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..ffaa8fc --- /dev/null +++ b/Makefile @@ -0,0 +1,17 @@ +SHELL=/bin/bash + +BIN = $(wildcard ./*.bin) +OFFSET = 0x08000000 +OPEN_OCD_PROGRAMMER_CFG = /usr/local/share/openocd/scripts/interface/stlink.cfg +OPEN_OCD_MK_CFG = /usr/local/share/openocd/scripts/target/stm32g0x.cfg + +.PHONY: help + +help: + @echo "Flash uploader to stm32. " + @echo " " + @echo "Before using, perform: install OpenOCD or stlink-tools" + @echo " " + @echo -e $(HELP_FLASH_UPLOADER) + +include ./flash_uploader.mk \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..c5539b4 --- /dev/null +++ b/README.md @@ -0,0 +1,13 @@ +This repository contains a makefile describing the functions of openocd & st-utils. +Using these files you can upload and erase the microcontroller firmware, and use GDB. + +st-utils is used only for stm32. openocd can be used for various microcontrollers, for example: WCH, Novoton, Geehy, GigaDevice. +You can include flash_uploader.mk in you Makefile and use. + +Target: + + make flash : upload flash use OpenOCD + make erase : erase flash use OpenOCD + make flash-st : upload flash use st-flash + make erase-st : erase flash use st-flash + make gdb : open GNU debugger diff --git a/flash_uploader.mk b/flash_uploader.mk new file mode 100644 index 0000000..8f31474 --- /dev/null +++ b/flash_uploader.mk @@ -0,0 +1,46 @@ +SHELL=/bin/bash + +# Before using, perform: init BIN, OFFSET, OPEN_OCD_PROGRAMMER_CFG, OPEN_OCD_MK_CFG. +# example: +# BIN = ./Project.bin +# OFFSET = 0x08000000 +# OPEN_OCD_PROGRAMMER_CFG = /usr/local/share/openocd/scripts/interface/stlink.cfg +# OPEN_OCD_MK_CFG = /usr/local/share/openocd/scripts/target/stm32g0x.cfg + +HELP_FLASH_UPLOADER = \ + " make flash : upload flash use OpenOCD\n"\ + "make erase : erase flash use OpenOCD\n"\ + "make flash-st : upload flash use st-flash\n"\ + "make erase-st : erase flash use st-flash\n"\ + "make gdb : open GNU debugger\n"\ + + +.PHONY: flash erase flash-st erase-st gdb-server gdb + +flash: + openocd -f $(OPEN_OCD_PROGRAMMER_CFG) \ + -f $(OPEN_OCD_MK_CFG) \ + -c init \ + -c "reset halt; flash write_image erase $(BIN) $(OFFSET) ; reset" \ + -c shutdown + +erase: + openocd -f $(OPEN_OCD_PROGRAMMER_CFG) \ + -f $(OPEN_OCD_MK_CFG) \ + -c "flash init; init; reset halt; flash erase_sector 0 1 last " \ + -c shutdown \ + +flash-st: + st-flash write $(BIN) $(OFFSET) + +erase-st: + st-flash erase + +OPENOCD_PORT=3333 +gdb: $(PROJECT) + openocd -f $(OPEN_OCD_PROGRAMMER_CFG) \ + -f $(OPEN_OCD_MK_CFG) \ + -c 'transport select hla_swd; reset_config none' & + arm-none-eabi-gdb $(PROJECT) \ + -ex 'target remote localhost:$(OPENOCD_PORT); monitor reset halt' \ + && killall openocd