Skip to content

Commit

Permalink
feat: makefile for openocd op
Browse files Browse the repository at this point in the history
  • Loading branch information
lunarifish committed Sep 13, 2024
1 parent 3d2364f commit ccaddf0
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 61 deletions.
11 changes: 1 addition & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,7 @@ target_link_libraries(${CMAKE_PROJECT_NAME}

# Convert ELF to BIN for flashing
add_custom_command(TARGET ${CMAKE_PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_OBJCOPY} -O binary ${CMAKE_PROJECT_NAME}.elf ${CMAKE_PROJECT_NAME}.bin
COMMAND ${CMAKE_OBJCOPY} -O binary ${CMAKE_PROJECT_NAME}.elf program.bin
DEPENDS ${CMAKE_PROJECT_NAME}
COMMENT "Converting ELF to BIN"
)

# Add openocd functions
include(${CMAKE_SOURCE_DIR}/openocd/flash-target.cmake)

# 调用 add_erase_and_reset 函数
add_erase_and_reset()

# 调用 flash_target 函数
flash_target()
18 changes: 18 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Makefile for STM32 operations using OpenOCD

# OpenOCD configuration file
OPENOCD_CFG = ./openocd/openocd.cfg

# Target to flash the STM32
flash:
openocd -f $(OPENOCD_CFG) -c "program program.bin 0x08000000 verify reset exit"

# Target to reset the STM32
reset:
openocd -f $(OPENOCD_CFG) -c "init" -c "reset" -c "exit"

# Target to erase the STM32
erase:
openocd -f $(OPENOCD_CFG) -c "init" -c "halt" -c "stm32f4x mass_erase 0" -c "exit"

.PHONY: flash reset erase
14 changes: 0 additions & 14 deletions README.markdown

This file was deleted.

21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# STM32F4项目模板

## Prerequisites

- cmake `>=3.22`

- openocd

- vscode + cortex-debug extension

- arm-none-eabi-gcc

## Usage

把项目clone到本地,然后在VSCode里打开进行开发即可。

### makefile shortcuts

- `make download`
- `make reset`
- `make erase`
37 changes: 0 additions & 37 deletions openocd/flash-target.cmake

This file was deleted.

0 comments on commit ccaddf0

Please sign in to comment.