<commit_before>export

DEVICE_FAMILY = STM32F4xx
STARTUP_FILE = stm32f4xx
DEVICE_TYPE = STM32F411xE
SYSTEM_FILE = stm32f4xx

CMSIS = Drivers/CMSIS
CMSIS_DEVSUP = $(CMSIS)/Device/ST/$(DEVICE_FAMILY)/
CMSIS_OPT = -D$(DEVICE_TYPE) -DUSE_HAL_DRIVER
OTHER_OPT = "-D__weak=__attribute__((weak))" "-D__packed=__attribute__((__packed__))" 
CPU = -mthumb -mcpu=cortex-m4 -mfloat-abi=softfp -mfpu=fpv4-sp-d16
SYSTEM = arm-none-eabi

LDSCRIPT = Src/STM32f411CE_FLASH.ld

SRCDIR := Src/
INCDIR := Inc/

LIBDIR := Drivers/
MDLDIR := Middlewares/

#LIBINC := $(shell find $(INCDIR) -name *.h -printf "-I%h/\n"|sort|uniq)
#LIBINC += $(shell find $(LIBDIR) -name *.h -printf "-I%h/\n"|sort|uniq)
#LIBINC += $(shell find $(MDLDIR) -name *.h -printf "-I%h/\n"|sort|uniq|sed -e 's/lwip\///'|sed -e 's/arch\///')

LIBINC := -IInc
LIBINC += -IMiddlewares/Third_Party/LwIP/system
LIBINC += -IMiddlewares/Third_Party/LwIP/src/include
LIBINC += -IMiddlewares/Third_Party/LwIP/src/include/ipv4
LIBINC += -IDrivers/STM32F4xx_HAL_Driver/Inc
LIBINC += -IMiddlewares/Third_Party/FatFs/src/drivers
LIBINC += -IMiddlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F
LIBINC += -IMiddlewares/ST/STM32_USB_Device_Library/Core/Inc
LIBINC += -IMiddlewares/ST/STM32_USB_Device_Library/Class/CDC/Inc
LIBINC += -IMiddlewares/ST/STM32_USB_Device_Library/Class/video/Inc
LIBINC += -IMiddlewares/ST/STM32_USB_Host_Library/Core/Inc
LIBINC += -IMiddlewares/ST/STM32_USB_Host_Library/Class/MSC/Inc
LIBINC += -IMiddlewares/Third_Party/FatFs/src
LIBINC += -IMiddlewares/Third_Party/FreeRTOS/Source/include
LIBINC += -IMiddlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS
LIBINC += -IMiddlewares/Third_Party/LwIP/system/arch
LIBINC += -IMiddlewares/Third_Party/LwIP/system/OS
LIBINC += -IMiddlewares/Third_Party/LwIP/src/include/ipv4/lwip
LIBINC += -IMiddlewares/Third_Party/LwIP/src/include/lwip
LIBINC += -IMiddlewares/Third_Party/LwIP/src/include/netif
LIBINC += -IMiddlewares/Third_Party/LwIP/src/include/posix
LIBINC += -IMiddlewares/Third_Party/LwIP/src/include/posix/sys
LIBINC += -IMiddlewares/Third_Party/LwIP/src/netif/ppp
LIBINC += -IDrivers/CMSIS/Include
LIBINC += -IDrivers/CMSIS/Device/ST/STM32F4xx/Include


LIBS := ./$(LIBDIR)/STM32F4xx_HAL_Driver/libstm32fw.a
LIBS += ./$(MDLDIR)/Third_Party/FatFs/fatfs.a
LIBS += ./$(MDLDIR)/Third_Party/FreeRTOS/freertos.a
LIBS += ./$(MDLDIR)/Third_Party/LwIP/lwip.a
LIBS += ./$(MDLDIR)/ST/STM32_USB_Device_Library/libstm32usbdev.a
LIBS += ./$(MDLDIR)/ST/STM32_USB_Host_Library/libstm32usbhost.a
	   
	   
LIBS += -lm
CC      = $(SYSTEM)-gcc
CCDEP   = $(SYSTEM)-gcc
LD      = $(SYSTEM)-gcc
AR      = $(SYSTEM)-ar
AS      = $(SYSTEM)-gcc
OBJCOPY = $(SYSTEM)-objcopy
OBJDUMP	= $(SYSTEM)-objdump
GDB		= $(SYSTEM)-gdb
SIZE	= $(SYSTEM)-size
OCD	= sudo openocd \
		-s /usr/local/share/openocd/scripts \
		-f interface/stlink-v2.cfg \
		-f target/stm32f4x_stlink.cfg


  
# INCLUDES = -I$(SRCDIR) $(LIBINC)
INCLUDES = $(LIBINC)
CFLAGS  = $(CPU) $(CMSIS_OPT) $(OTHER_OPT) -Wall -fno-common -fno-strict-aliasing -O2 $(INCLUDES) -g -Wfatal-errors -g 
ifdef USART_DEBUG
	USART_DEBUG_SPEED = 115200
	CFLAGS += -DUSART_DEBUG -DUSART_DEBUG_SPEED=$(USART_DEBUG_SPEED)
endif
ASFLAGS = $(CFLAGS) -x assembler-with-cpp
LDFLAGS = -Wl,--gc-sections,-Map=$*.map,-cref -T $(LDSCRIPT) $(CPU)
ARFLAGS = cr
OBJCOPYFLAGS = -Obinary
OBJDUMPFLAGS = -S

STARTUP_OBJ = $(CMSIS_DEVSUP)/Source/Templates/gcc/startup_$(STARTUP_FILE).o
SYSTEM_OBJ = $(CMSIS_DEVSUP)/Source/Templates/system_$(SYSTEM_FILE).o

.PHONY: print_vars

BIN = main.bin

OBJS = $(sort \
 $(patsubst %.c,%.o,$(wildcard Src/*.c)) \
 $(patsubst %.s,%.o,$(wildcard Src/*.s)) \
 $(STARTUP_OBJ) \
 $(SYSTEM_OBJ))

all: $(BIN) print_vars

reset:
	$(OCD) -c init -c "reset run" -c shutdown
	#$(GDB) main.out <reset.gdb

flash: $(BIN)<commit_msg>Allow definition of USART_DEBUG_SPEED when USART_DEBUG is set<commit_after>export

DEVICE_FAMILY = STM32F4xx
STARTUP_FILE = stm32f4xx
DEVICE_TYPE = STM32F411xE
SYSTEM_FILE = stm32f4xx

CMSIS = Drivers/CMSIS
CMSIS_DEVSUP = $(CMSIS)/Device/ST/$(DEVICE_FAMILY)/
CMSIS_OPT = -D$(DEVICE_TYPE) -DUSE_HAL_DRIVER
OTHER_OPT = "-D__weak=__attribute__((weak))" "-D__packed=__attribute__((__packed__))" 
CPU = -mthumb -mcpu=cortex-m4 -mfloat-abi=softfp -mfpu=fpv4-sp-d16
SYSTEM = arm-none-eabi

LDSCRIPT = Src/STM32f411CE_FLASH.ld

SRCDIR := Src/
INCDIR := Inc/

LIBDIR := Drivers/
MDLDIR := Middlewares/

#LIBINC := $(shell find $(INCDIR) -name *.h -printf "-I%h/\n"|sort|uniq)
#LIBINC += $(shell find $(LIBDIR) -name *.h -printf "-I%h/\n"|sort|uniq)
#LIBINC += $(shell find $(MDLDIR) -name *.h -printf "-I%h/\n"|sort|uniq|sed -e 's/lwip\///'|sed -e 's/arch\///')

LIBINC := -IInc
LIBINC += -IMiddlewares/Third_Party/LwIP/system
LIBINC += -IMiddlewares/Third_Party/LwIP/src/include
LIBINC += -IMiddlewares/Third_Party/LwIP/src/include/ipv4
LIBINC += -IDrivers/STM32F4xx_HAL_Driver/Inc
LIBINC += -IMiddlewares/Third_Party/FatFs/src/drivers
LIBINC += -IMiddlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F
LIBINC += -IMiddlewares/ST/STM32_USB_Device_Library/Core/Inc
LIBINC += -IMiddlewares/ST/STM32_USB_Device_Library/Class/CDC/Inc
LIBINC += -IMiddlewares/ST/STM32_USB_Device_Library/Class/video/Inc
LIBINC += -IMiddlewares/ST/STM32_USB_Host_Library/Core/Inc
LIBINC += -IMiddlewares/ST/STM32_USB_Host_Library/Class/MSC/Inc
LIBINC += -IMiddlewares/Third_Party/FatFs/src
LIBINC += -IMiddlewares/Third_Party/FreeRTOS/Source/include
LIBINC += -IMiddlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS
LIBINC += -IMiddlewares/Third_Party/LwIP/system/arch
LIBINC += -IMiddlewares/Third_Party/LwIP/system/OS
LIBINC += -IMiddlewares/Third_Party/LwIP/src/include/ipv4/lwip
LIBINC += -IMiddlewares/Third_Party/LwIP/src/include/lwip
LIBINC += -IMiddlewares/Third_Party/LwIP/src/include/netif
LIBINC += -IMiddlewares/Third_Party/LwIP/src/include/posix
LIBINC += -IMiddlewares/Third_Party/LwIP/src/include/posix/sys
LIBINC += -IMiddlewares/Third_Party/LwIP/src/netif/ppp
LIBINC += -IDrivers/CMSIS/Include
LIBINC += -IDrivers/CMSIS/Device/ST/STM32F4xx/Include


LIBS := ./$(LIBDIR)/STM32F4xx_HAL_Driver/libstm32fw.a
LIBS += ./$(MDLDIR)/Third_Party/FatFs/fatfs.a
LIBS += ./$(MDLDIR)/Third_Party/FreeRTOS/freertos.a
LIBS += ./$(MDLDIR)/Third_Party/LwIP/lwip.a
LIBS += ./$(MDLDIR)/ST/STM32_USB_Device_Library/libstm32usbdev.a
LIBS += ./$(MDLDIR)/ST/STM32_USB_Host_Library/libstm32usbhost.a
	   
	   
LIBS += -lm
CC      = $(SYSTEM)-gcc
CCDEP   = $(SYSTEM)-gcc
LD      = $(SYSTEM)-gcc
AR      = $(SYSTEM)-ar
AS      = $(SYSTEM)-gcc
OBJCOPY = $(SYSTEM)-objcopy
OBJDUMP	= $(SYSTEM)-objdump
GDB		= $(SYSTEM)-gdb
SIZE	= $(SYSTEM)-size
OCD	= sudo openocd \
		-s /usr/local/share/openocd/scripts \
		-f interface/stlink-v2.cfg \
		-f target/stm32f4x_stlink.cfg


  
# INCLUDES = -I$(SRCDIR) $(LIBINC)
INCLUDES = $(LIBINC)
CFLAGS  = $(CPU) $(CMSIS_OPT) $(OTHER_OPT) -Wall -fno-common -fno-strict-aliasing -O2 $(INCLUDES) -g -Wfatal-errors -g 
ifdef USART_DEBUG
	USART_DEBUG_SPEED ?= 115200
	CFLAGS += -DUSART_DEBUG -DUSART_DEBUG_SPEED=$(USART_DEBUG_SPEED)
endif
ASFLAGS = $(CFLAGS) -x assembler-with-cpp
LDFLAGS = -Wl,--gc-sections,-Map=$*.map,-cref -T $(LDSCRIPT) $(CPU)
ARFLAGS = cr
OBJCOPYFLAGS = -Obinary
OBJDUMPFLAGS = -S

STARTUP_OBJ = $(CMSIS_DEVSUP)/Source/Templates/gcc/startup_$(STARTUP_FILE).o
SYSTEM_OBJ = $(CMSIS_DEVSUP)/Source/Templates/system_$(SYSTEM_FILE).o

.PHONY: print_vars

BIN = main.bin

OBJS = $(sort \
 $(patsubst %.c,%.o,$(wildcard Src/*.c)) \
 $(patsubst %.s,%.o,$(wildcard Src/*.s)) \
 $(STARTUP_OBJ) \
 $(SYSTEM_OBJ))

all: $(BIN) print_vars

reset:
	$(OCD) -c init -c "reset run" -c shutdown
	#$(GDB) main.out <reset.gdb

flash: $(BIN)
{'fraction_non_alphanumeric': 0.16765130628856506, 'fraction_numerical': 0.01732965734541158, 'mean_word_length': 4.544395924308588, 'pattern_counts': {'":': 0, '<': 5, '<?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': '268537', 'n_tokens_mistral': 3566, 'n_tokens_neox': 3226, 'n_words': 466}