Loading files
This file is pinned to the selected release. Download the original to open it in your design tool.
316cc8ec7This file is pinned to the selected release. Download the original to open it in your design tool.
##########################################################################################################################
# File automatically-generated by tool: [projectgenerator] version: [3.18.0-B7] date: [Fri Jan 13 05:36:25 PST 2023]
##########################################################################################################################
# ------------------------------------------------
# Generic Makefile (based on gcc)
#
# ChangeLog :
# 2017-02-10 - Several enhancements + project update mode
# 2015-07-22 - first version
# ------------------------------------------------
######################################
# target
######################################
TARGET = md-flashcart
######################################
# building variables
######################################
# debug build?
DEBUG = 0
# optimization
OPT = -O3
#######################################
# paths
#######################################
# Build path
BUILD_DIR = build
######################################
# source
######################################
# C sources
C_SOURCES = \
Core/Src/app.c \
Core/Src/app_hw.c \
Core/Src/min.c \
Core/Src/queue.c \
Core/Src/main.c \
Core/Src/stm32g0xx_it.c \
Core/Src/stm32g0xx_hal_msp.c \
SEGGER_RTT_V792c/RTT/SEGGER_RTT.c \
SEGGER_RTT_V792c/RTT/SEGGER_RTT_printf.c \
Drivers/STM32G0xx_HAL_Driver/Src/stm32g0xx_hal_dac.c \
Drivers/STM32G0xx_HAL_Driver/Src/stm32g0xx_hal_dac_ex.c \
Drivers/STM32G0xx_HAL_Driver/Src/stm32g0xx_hal_rcc.c \
Drivers/STM32G0xx_HAL_Driver/Src/stm32g0xx_hal_rcc_ex.c \
Drivers/STM32G0xx_HAL_Driver/Src/stm32g0xx_ll_rcc.c \
Drivers/STM32G0xx_HAL_Driver/Src/stm32g0xx_hal_flash.c \
Drivers/STM32G0xx_HAL_Driver/Src/stm32g0xx_hal_flash_ex.c \
Drivers/STM32G0xx_HAL_Driver/Src/stm32g0xx_hal_gpio.c \
Drivers/STM32G0xx_HAL_Driver/Src/stm32g0xx_hal_dma.c \
Drivers/STM32G0xx_HAL_Driver/Src/stm32g0xx_hal_dma_ex.c \
Drivers/STM32G0xx_HAL_Driver/Src/stm32g0xx_ll_dma.c \
Drivers/STM32G0xx_HAL_Driver/Src/stm32g0xx_hal_pwr.c \
Drivers/STM32G0xx_HAL_Driver/Src/stm32g0xx_hal_pwr_ex.c \
Drivers/STM32G0xx_HAL_Driver/Src/stm32g0xx_hal_cortex.c \
Drivers/STM32G0xx_HAL_Driver/Src/stm32g0xx_hal.c \
Drivers/STM32G0xx_HAL_Driver/Src/stm32g0xx_hal_exti.c \
Drivers/STM32G0xx_HAL_Driver/Src/stm32g0xx_hal_tim.c \
Drivers/STM32G0xx_HAL_Driver/Src/stm32g0xx_hal_tim_ex.c \
Drivers/STM32G0xx_HAL_Driver/Src/stm32g0xx_hal_uart.c \
Drivers/STM32G0xx_HAL_Driver/Src/stm32g0xx_hal_uart_ex.c \
Core/Src/system_stm32g0xx.c \
Drivers/STM32G0xx_HAL_Driver/Src/stm32g0xx_hal_iwdg.c
# ASM sources
ASM_SOURCES = \
startup_stm32g081xx.s
#######################################
# binaries
#######################################
PREFIX = arm-none-eabi-
# The gcc compiler bin path can be either defined in make command via GCC_PATH variable (> make GCC_PATH=xxx)
# either it can be added to the PATH environment variable.
ifdef GCC_PATH
CC = $(GCC_PATH)/$(PREFIX)gcc
AS = $(GCC_PATH)/$(PREFIX)gcc -x assembler-with-cpp
CP = $(GCC_PATH)/$(PREFIX)objcopy
SZ = $(GCC_PATH)/$(PREFIX)size
else
CC = $(PREFIX)gcc
AS = $(PREFIX)gcc -x assembler-with-cpp
CP = $(PREFIX)objcopy
SZ = $(PREFIX)size
endif
HEX = $(CP) -O ihex
BIN = $(CP) -O binary -S
#######################################
# CFLAGS
#######################################
# cpu
CPU = -mcpu=cortex-m0plus
# fpu
# NONE for Cortex-M0/M0+/M3
# float-abi
# mcu
MCU = $(CPU) -mthumb $(FPU) $(FLOAT-ABI)
# macros for gcc
# AS defines
AS_DEFS =
# C defines
C_DEFS = \
-DUSE_HAL_DRIVER \
-DSTM32G081xx \
-DNO_TRANSPORT_PROTOCOL
# AS includes
AS_INCLUDES =
# C includes
C_INCLUDES = \
-ICore/Inc \
-ISEGGER_RTT_V792c/RTT \
-ISEGGER_RTT_V792c/Config \
-I$(STM32_TOOLCHAIN_HOME)/arm-none-eabi/include \
-IDrivers/STM32G0xx_HAL_Driver/Inc \
-IDrivers/STM32G0xx_HAL_Driver/Inc/Legacy \
-IDrivers/CMSIS/Device/ST/STM32G0xx/Include \
-IDrivers/CMSIS/Include
# compile gcc flags
ASFLAGS = $(MCU) $(AS_DEFS) $(AS_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections
CFLAGS += $(MCU) $(C_DEFS) $(C_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections
ifeq ($(DEBUG), 1)
CFLAGS += -g -gdwarf-2
endif
# Generate dependency information
CFLAGS += -MMD -MP -MF"$(@:%.o=%.d)"
#######################################
# LDFLAGS
#######################################
# link script
LDSCRIPT = STM32G081RBTx_FLASH.ld
# libraries
LIBS = -lc -lm -lnosys
LIBDIR =
LDFLAGS = $(MCU) -specs=nano.specs -T$(LDSCRIPT) $(LIBDIR) $(LIBS) -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref -Wl,--gc-sections,--no-warn-rwx-segments
# default action: build all
all: $(BUILD_DIR)/$(TARGET).elf $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).bin
#######################################
# build the application
#######################################
# list of objects
OBJECTS = $(addprefix $(BUILD_DIR)/,$(notdir $(C_SOURCES:.c=.o)))
vpath %.c $(sort $(dir $(C_SOURCES)))
# list of ASM program objects
OBJECTS += $(addprefix $(BUILD_DIR)/,$(notdir $(ASM_SOURCES:.s=.o)))
vpath %.s $(sort $(dir $(ASM_SOURCES)))
$(BUILD_DIR)/%.o: %.c Makefile | $(BUILD_DIR)
$(CC) -c $(CFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(notdir $(<:.c=.lst)) $< -o $@
$(BUILD_DIR)/%.o: %.s Makefile | $(BUILD_DIR)
$(AS) -c $(CFLAGS) $< -o $@
$(BUILD_DIR)/$(TARGET).elf: $(OBJECTS) Makefile
$(CC) $(OBJECTS) $(LDFLAGS) -o $@
$(SZ) $@
$(BUILD_DIR)/%.hex: $(BUILD_DIR)/%.elf | $(BUILD_DIR)
$(HEX) $< $@
$(BUILD_DIR)/%.bin: $(BUILD_DIR)/%.elf | $(BUILD_DIR)
$(BIN) $< $@
$(BUILD_DIR):
mkdir $@
#######################################
# clean up
#######################################
clean:
-rm -fR $(BUILD_DIR)
#######################################
# dependencies
#######################################
-include $(wildcard $(BUILD_DIR)/*.d)
# note: STM32G081xx have 36KB SRAM @ 0x20000000-0x200008fff
# start jlink gdb server and connect to target with jlink
jlink:
JLinkGDBServer -NoGui -device STM32G081RB -if SWD \
-select usb=$(JLINK_SERIAL) \
-port $(GDB_PORT) \
-RTTTelnetPort $(RTT_PORT)
jlink-edu:
JLinkGDBServer -NoGui -device STM32G081RB -if SWD \
-select usb=$(JLINK_EDU_SERIAL) \
-port $(GDB_PORT) \
-RTTTelnetPort $(RTT_PORT)
# start openocd gdb server and connect to target with jlink
openocd-jlink:
openocd -f interface/jlink.cfg \
-c "transport select swd" \
-c "adapter serial $(JLINK_SERIAL)" \
-f target/stm32g0x.cfg \
-c "bindto 0.0.0.0" \
-c "gdb_port $(GDB_PORT)" \
-c "telnet_port $(OPENOCD_REMOTE_PORT)" \
-c "tcl_port $(OPENOCD_TCL_PORT)" \
-c "gdb_flash_program enable" \
-c "init" \
-c "reset run" \
-c "sleep 500" \
-c "rtt setup 0x20000000 0x8fff \"SEGGER RTT\"" \
-c "rtt start" \
-c "rtt server start $(RTT_PORT) 0" \
-c "rtt server start $(RTT_PORT_CH1) 1"
# start openocd gdb server and connect to target with jlink edu
openocd-jlink-edu:
openocd -f interface/jlink.cfg \
-c "transport select swd" \
-c "adapter serial $(JLINK_EDU_SERIAL)" \
-f target/stm32g0x.cfg \
-c "bindto 0.0.0.0" \
-c "gdb_port $(GDB_PORT)" \
-c "telnet_port $(OPENOCD_REMOTE_PORT)" \
-c "tcl_port $(OPENOCD_TCL_PORT)" \
-c "gdb_flash_program enable" \
-c "init" \
-c "reset run" \
-c "sleep 500" \
-c "rtt setup 0x20000000 0x8fff \"SEGGER RTT\"" \
-c "rtt start" \
-c "rtt server start $(RTT_PORT) 0" \
-c "rtt server start $(RTT_PORT_CH1) 1"
# start openocd gdb server and connect to target with st-link
openocd-stlink:
openocd -f interface/stlink.cfg -f target/stm32g0x.cfg \
-c "bindto 0.0.0.0" \
-c "gdb_port $(GDB_PORT)" \
-c "telnet_port $(OPENOCD_REMOTE_PORT)" \
-c "tcl_port $(OPENOCD_TCL_PORT)" \
-c "gdb_flash_program enable" \
-c "init" \
-c "reset run" \
-c "rtt setup 0x20000000 0x8fff \"SEGGER RTT\"" \
-c "rtt start" \
-c "rtt server start $(RTT_PORT) 0" \
-c "rtt server start $(RTT_PORT_CH1) 1"
# flash target with running instance of openocd
flash-tcl: $(BUILD_DIR)/$(TARGET).elf
@echo -e \
"reset halt\x1a" \
"flash write_image erase unlock $(BUILD_DIR)/$(TARGET).elf\x1a" \
"reset run\x1a" \
"rtt stop\x1a" \
"rtt setup 0x20000000 0x8fff \"SEGGER RTT\"\x1a" \
"rtt start\x1a" \
"sleep 0\x1a" \
"exit\x1a" \
| socat -t 10 TCP:localhost:$(OPENOCD_TCL_PORT) -
# flash target with gdb using monitor commands for jlink
flash-gdb-jlink: $(BUILD_DIR)/$(TARGET).elf
arm-none-eabi-gdb -batch-silent \
-ex "target extended-remote $(GDB_HOST):$(GDB_PORT)" \
-ex "mon reset halt" \
-ex "load" \
-ex "mon reset run" \
-ex "mon sleep 500" \
-ex "mon rtt stop" \
-ex "mon rtt setup 0x20000000 0x8fff \"SEGGER RTT\"" \
-ex "mon rtt start" \
-ex "mon sleep 0" \
-ex "quit" \
$(BUILD_DIR)/$(TARGET).elf
# flash target with gdb using monitor commands for st-link
flash-gdb-stlink: $(BUILD_DIR)/$(TARGET).elf
arm-none-eabi-gdb \
-batch-silent \
-ex "target extended-remote $(GDB_HOST):$(GDB_PORT)" \
-ex "mon reset halt" \
-ex "mon flash write_image erase unlock $(BUILD_DIR)/$(TARGET).elf" \
-ex "mon reset run" \
-ex "mon sleep 500" \
-ex "mon rtt stop" \
-ex "mon rtt setup 0x20000000 0x8fff \"SEGGER RTT\"" \
-ex "mon rtt start" \
-ex "mon sleep 0" \
-ex "quit" \
$(BUILD_DIR)/$(TARGET).elf
# flash target with openocd with and st-link
flash-openocd-stlink: $(BUILD_DIR)/$(TARGET).elf
openocd -f interface/stlink.cfg -f target/stm32g0x.cfg \
-c "init" \
-c "reset halt" \
-c "flash write_image erase $(BUILD_DIR)/$(TARGET).elf" \
-c "reset" \
-c "shutdown"
flash-dfu: $(BUILD_DIR)/$(TARGET).bin
dfu-util -a 0 -s 0x08000000:leave -D $(BUILD_DIR)/$(TARGET).bin
# debug target with gdb and running instance of gdb server
gdb: $(BUILD_DIR)/$(TARGET).elf
arm-none-eabi-gdb \
-ex "target extended-remote $(GDB_HOST):$(GDB_PORT)" \
$(BUILD_DIR)/$(TARGET).elf
# open console session on target rtt channel 0
rtt:
socat tcp4:localhost:$(RTT_PORT) -
# open console session on target rtt channel 1
rtt-ch1:
socat tcp4:localhost:$(RTT_PORT_CH1) -
############
cp2102n-boot0:
cp210xsmt --device-count 1 --set-and-verify-config \
cp2102n_md-flashcart_boot0.configuration
cp2102n-swd:
cp210xsmt --device-count 1 --set-and-verify-config \
cp2102n_md-flashcart_swd.configuration
flash-usb: $(BUILD_DIR)/$(TARGET).hex
../cp2102n_reset_stm32/build/cp2102n_reset_stm32 gpiochip0 -b && \
stm32flash -w $(BUILD_DIR)/$(TARGET).hex -v /dev/ttyUSB0 && \
../cp2102n_reset_stm32/build/cp2102n_reset_stm32 gpiochip0
# *** EOF ***