first commit

This commit is contained in:
kr rt 2023-10-26 23:38:08 +03:00
commit c119ec0f82
4 changed files with 77 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*.bin

17
Makefile Normal file
View File

@ -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

13
README.md Normal file
View File

@ -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

46
flash_uploader.mk Normal file
View File

@ -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