<commit_before>CMSIS       ?=../../CMSIS
CMSISDEV    ?= $(CMSIS)/Device
CMSISCORE   ?= $(CMSIS)/CMSIS/Include $(CMSIS)/CMSIS/Core/Include
FLASH       ?= st-flash
TOOLSET     ?= arm-none-eabi-
CC           = $(TOOLSET)gcc
LD           = $(TOOLSET)gcc
AR           = $(TOOLSET)gcc-ar
OBJCOPY      = $(TOOLSET)objcopy

ifeq ($(OS),Windows_NT)
	RM = del /Q
	fixpath = $(strip $(subst /,\, $1))
else
	RM = rm -f
	fixpath = $(strip $1)
endif

MODULE      ?= libusb.a
CFLAGS      ?= -mcpu=cortex-m3
DEFINES     ?= STM32F1 STM32F103x6

ARFLAGS      = -cvq
LDFLAGS      = --specs=nano.specs -nostartfiles -Wl,--gc-sections
INCLUDES     = $(CMSISDEV)/ST $(CMSISCORE) inc
CFLAGS2      = -mthumb -Os -std=gnu99 -fshort-wchar

OBJDIR       = obj
SOURCES      = $(wildcard src/*.c) $(wildcard src/*.S)
OBJECTS      = $(addprefix $(OBJDIR)/, $(addsuffix .o, $(notdir $(basename $(SOURCES)))))
DSRC         = $(wildcard demo/*.c) $(wildcard demo/*.S) $(STARTUP)
DOBJ         = $(addprefix $(OBJDIR)/, $(addsuffix .o, $(notdir $(basename $(DSRC)))))
DOUT         = cdc_loop

SRCPATH      = $(sort $(dir $(SOURCES) $(DSRC)))
vpath %.c $(SRCPATH)
vpath %.S $(SRCPATH)
vpath %.s $(SRCPATH)


help all:
	@echo 'Usage: make target [program]'
	@echo 'Available targets are:'
	@echo '  bluepill'
	@echo '  stm32f103x6   CDC loopback demo for STM32F103 based boards'
	@echo '  32l100c-disco'
	@echo '  stm32l100xc   CDC loopback demo for STM32L100xC based boards'
	@echo '  32l476rg-nucleo'
	@echo '  stm32l476rg   CDC loopback demo for STM32L476xG based boards'
	@echo '  stm32l052x8   CDC loopback demo for STM32L052x8 based boards'
	@echo '  32f429zi-nucleo'
	@echo '  stm32f429xi   CDC loopback demo for STM32F429xI based boards'
	@echo '  doc           DOXYGEN documentation'
	@echo '  module        static library module using following envars (defaults)'
	@echo '                MODULE  module name (libusb.a)'
	@echo '                CFLAGS  mcu specified compiler flags (-mcpu=cortex-m3)'
	@echo '                DEFINES mcu and module specified defines (STM32F1 STM32F103x6)'
	@echo '                        see USB Device HW driver and core API section for the'
	@echo '                        compile-time control macros'
	@echo ' '
	@echo 'Environmental variables (defaults):'
	@echo '  CMSIS         Path to the CMSIS V4 or CMSIS V5 root folder ($(CMSIS))'
	@echo '  CMSISCORE     Path to the CMSIS Core include folder(s) ($(CMSISCORE))'
	@echo '  CMSISDEV      Path to the CMSIS Device folder ($(CMSISDEV))'
	@echo '  FLASH         st-link flash utility ($(FLASH))'
	@echo ' '
	@echo 'Examples:'
	@echo '  make bluepill program'
	@echo '  make module MODULE="usbd.a" CFLAGS="-mcpu=cotrex-m4" DEFINES="STM32L4 STM32L476xx USBD_VBUS_DETECT"'

$(OBJDIR):
	@mkdir $@

program: $(DOUT).hex
	$(FLASH) --reset --format ihex write $(DOUT).hex

demo: $(DOUT).hex

$(DOUT).hex : $(DOUT).elf
	@echo building $@
	@$(OBJCOPY) -O ihex $< $@

$(DOUT).elf : $(OBJDIR) $(DOBJ) $(OBJECTS)
	@echo building $@
	@$(LD) $(CFLAGS) $(CFLAGS2) $(LDFLAGS) -Wl,--script='$(LDSCRIPT)' -Wl,-Map=$(DOUT).map $(DOBJ) $(OBJECTS) -o $@

clean:
	@$(RM) $(DOUT).*
	@$(RM) $(call fixpath, $(OBJDIR)/*.*)

doc:
	doxygen

module: clean $(MODULE)<commit_msg>Add target to flash using dfu-util and the system bootloader.<commit_after>CMSIS       ?=../../CMSIS
CMSISDEV    ?= $(CMSIS)/Device
CMSISCORE   ?= $(CMSIS)/CMSIS/Include $(CMSIS)/CMSIS/Core/Include
FLASH       ?= st-flash
TOOLSET     ?= arm-none-eabi-
CC           = $(TOOLSET)gcc
LD           = $(TOOLSET)gcc
AR           = $(TOOLSET)gcc-ar
OBJCOPY      = $(TOOLSET)objcopy
DFU_UTIL	?= dfu-util

ifeq ($(OS),Windows_NT)
	RM = del /Q
	fixpath = $(strip $(subst /,\, $1))
else
	RM = rm -f
	fixpath = $(strip $1)
endif

MODULE      ?= libusb.a
CFLAGS      ?= -mcpu=cortex-m3
DEFINES     ?= STM32F1 STM32F103x6

ARFLAGS      = -cvq
LDFLAGS      = --specs=nano.specs -nostartfiles -Wl,--gc-sections
INCLUDES     = $(CMSISDEV)/ST $(CMSISCORE) inc
CFLAGS2      = -mthumb -Os -std=gnu99 -fshort-wchar

OBJDIR       = obj
SOURCES      = $(wildcard src/*.c) $(wildcard src/*.S)
OBJECTS      = $(addprefix $(OBJDIR)/, $(addsuffix .o, $(notdir $(basename $(SOURCES)))))
DSRC         = $(wildcard demo/*.c) $(wildcard demo/*.S) $(STARTUP)
DOBJ         = $(addprefix $(OBJDIR)/, $(addsuffix .o, $(notdir $(basename $(DSRC)))))
DOUT         = cdc_loop

SRCPATH      = $(sort $(dir $(SOURCES) $(DSRC)))
vpath %.c $(SRCPATH)
vpath %.S $(SRCPATH)
vpath %.s $(SRCPATH)


help all:
	@echo 'Usage: make target [program]'
	@echo 'Available targets are:'
	@echo '  bluepill'
	@echo '  stm32f103x6   CDC loopback demo for STM32F103 based boards'
	@echo '  32l100c-disco'
	@echo '  stm32l100xc   CDC loopback demo for STM32L100xC based boards'
	@echo '  32l476rg-nucleo'
	@echo '  stm32l476rg   CDC loopback demo for STM32L476xG based boards'
	@echo '  stm32l052x8   CDC loopback demo for STM32L052x8 based boards'
	@echo '  32f429zi-nucleo'
	@echo '  stm32f429xi   CDC loopback demo for STM32F429xI based boards'
	@echo '  doc           DOXYGEN documentation'
	@echo '  module        static library module using following envars (defaults)'
	@echo '                MODULE  module name (libusb.a)'
	@echo '                CFLAGS  mcu specified compiler flags (-mcpu=cortex-m3)'
	@echo '                DEFINES mcu and module specified defines (STM32F1 STM32F103x6)'
	@echo '                        see USB Device HW driver and core API section for the'
	@echo '                        compile-time control macros'
	@echo ' '
	@echo 'Environmental variables (defaults):'
	@echo '  CMSIS         Path to the CMSIS V4 or CMSIS V5 root folder ($(CMSIS))'
	@echo '  CMSISCORE     Path to the CMSIS Core include folder(s) ($(CMSISCORE))'
	@echo '  CMSISDEV      Path to the CMSIS Device folder ($(CMSISDEV))'
	@echo '  FLASH         st-link flash utility ($(FLASH))'
	@echo ' '
	@echo 'Examples:'
	@echo '  make bluepill program'
	@echo '  make module MODULE="usbd.a" CFLAGS="-mcpu=cotrex-m4" DEFINES="STM32L4 STM32L476xx USBD_VBUS_DETECT"'

$(OBJDIR):
	@mkdir $@

program: $(DOUT).hex
	$(FLASH) --reset --format ihex write $(DOUT).hex

program_dfu: $(DOUT).bin
	$(DFU_UTIL) -d 0483:DF11 -a 0 -D $(DOUT).bin -s 0x08000000

demo: $(DOUT).hex $(DOUT).bin

$(DOUT).bin : $(DOUT).elf
	@echo building $@
	@$(OBJCOPY) -O binary $< $@

$(DOUT).hex : $(DOUT).elf
	@echo building $@
	@$(OBJCOPY) -O ihex $< $@

$(DOUT).elf : $(OBJDIR) $(DOBJ) $(OBJECTS)
	@echo building $@
	@$(LD) $(CFLAGS) $(CFLAGS2) $(LDFLAGS) -Wl,--script='$(LDSCRIPT)' -Wl,-Map=$(DOUT).map $(DOBJ) $(OBJECTS) -o $@

clean:
	@$(RM) $(DOUT).*
	@$(RM) $(call fixpath, $(OBJDIR)/*.*)

doc:
	doxygen

module: clean $(MODULE)
{'fraction_non_alphanumeric': 0.15900900900900902, 'fraction_numerical': 0.03393393393393394, 'mean_word_length': 2.936761229314421, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '542974', 'n_tokens_mistral': 2818, 'n_tokens_neox': 2485, 'n_words': 671}