From 36c04e7b000035086b2e2b8020a2337c5c2fa390 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Fri, 24 Feb 2023 15:05:52 +0100 Subject: desktop compilation options in makefile --- src/.gitignore | 1 + src/ds.mk | 2 + src/main.c | 19 +++++---- src/makefile | 120 +++++++++++++++++++++++---------------------------------- src/stm32.mk | 61 +++++++++++++++++++++++++++++ 5 files changed, 121 insertions(+), 82 deletions(-) create mode 100644 src/ds.mk create mode 100644 src/stm32.mk (limited to 'src') diff --git a/src/.gitignore b/src/.gitignore index 312c0ff..8b91843 100644 --- a/src/.gitignore +++ b/src/.gitignore @@ -1,3 +1,4 @@ *.o main.elf main.bin +main diff --git a/src/ds.mk b/src/ds.mk new file mode 100644 index 0000000..57b305f --- /dev/null +++ b/src/ds.mk @@ -0,0 +1,2 @@ +CC := gcc +LD := gcc diff --git a/src/main.c b/src/main.c index 910d2dd..1b8cdba 100644 --- a/src/main.c +++ b/src/main.c @@ -1,6 +1,5 @@ -#include +#include #include -#include #include "ppu/ppu.h" #include "ppu/consts.h" @@ -16,17 +15,17 @@ hh_s_ppu_loc_sprite* hh_debug_circle_sprite() { } int main() { - hh_ppu_init(); + // hh_ppu_init(); - hh_ppu_update_aux((hh_s_ppu_loc_aux) { - .bg_shift_x = 0, - .bg_shift_y = 0, - .fg_fetch = 0, - .sysreset = 0, - }); + // hh_ppu_update_aux((hh_s_ppu_loc_aux) { + // .bg_shift_x = 0, + // .bg_shift_y = 0, + // .fg_fetch = 0, + // .sysreset = 0, + // }); hh_s_ppu_loc_sprite* sprite = hh_debug_circle_sprite(); - hh_ppu_update_sprite(0, *sprite); + // hh_ppu_update_sprite(0, *sprite); free(sprite); while (1); diff --git a/src/makefile b/src/makefile index 22e956e..6077824 100644 --- a/src/makefile +++ b/src/makefile @@ -1,109 +1,85 @@ -CC = arm-none-eabi-gcc -LD = arm-none-eabi-gcc -OC = arm-none-eabi-objcopy -OS = arm-none-eabi-size RM = rm -f TARGET = main +# platform is ds (desktop) or stm (stm32) +PLATFORM = ds + +ifeq ($(PLATFORM),stm) +STM = true +include stm32.mk +endif +ifeq ($(PLATFORM),ds) +DESKTOP = true +include ds.mk +endif + HOST=$(strip $(shell uname -o)) SHARED_FLAGS += -g -SHARED_FLAGS += -DSTM32F091xC SHARED_FLAGS += -Wall SHARED_FLAGS += -Wextra -# SHARED_FLAGS += -Wno-register -SHARED_FLAGS += -Wa,--defsym,CALL_ARM_SYSTEM_INIT=1 -SHARED_FLAGS += -I./lib/STM32-base-STM32Cube/HAL/STM32F0xx/inc -SHARED_FLAGS += -I./lib/STM32-base-STM32Cube/HAL/STM32F0xx/inc/Legacy -SHARED_FLAGS += -I./lib/STM32-base-STM32Cube/CMSIS/ARM/inc -SHARED_FLAGS += -I./lib/STM32-base-STM32Cube/CMSIS/STM32F0xx/inc -SHARED_FLAGS += -I./lib/STM32-base/startup -SHARED_FLAGS += -I./lib/FreeRTOS-Kernel/include -SHARED_FLAGS += -I./lib/FreeRTOS-Kernel/portable/GCC/ARM_CM0/ -SHARED_FLAGS += -I. -ifeq ($(HOST),GNU/Linux) -SHARED_FLAGS += -I/usr/arm-none-eabi/include/ -endif # SHARED_FLAGS += -O1 -SHARED_FLAGS += -ffunction-sections -SHARED_FLAGS += -fdata-sections -SHARED_FLAGS += -Wl,--gc-sections -SHARED_FLAGS += -mlittle-endian -SHARED_FLAGS += -mthumb -SHARED_FLAGS += -specs=nosys.specs -SHARED_FLAGS += -fno-exceptions -SHARED_FLAGS += -fno-unwind-tables -SHARED_FLAGS += -Wl,-L./lib/STM32-base/linker,-T./lib/STM32-base/linker/STM32F0xx/STM32F091xC.ld -SHARED_FLAGS += -mcpu=cortex-m0 -SHARED_FLAGS += -march=armv6-m +LFLAGS += -lm +# LFLAGS += -lc +CFLAGS += $(if $(STM), -DHH_TARGET_STM32, ) +CFLAGS += $(if $(DESKTOP), -DHH_TARGET_DESKTOP, ) + +LOCAL_SRCS += main.c CFLAGS += $(SHARED_FLAGS) LFLAGS += $(SHARED_FLAGS) AFLAGS += $(SHARED_FLAGS) -OBJS += lib/STM32-base/startup/STM32F0xx/STM32F091xC.o -OBJS += lib/STM32-base-STM32Cube/CMSIS/STM32F0xx/src/system_stm32f0xx.o -OBJS += lib/FreeRTOS-Kernel/croutine.o \ - lib/FreeRTOS-Kernel/event_groups.o \ - lib/FreeRTOS-Kernel/list.o \ - lib/FreeRTOS-Kernel/queue.o \ - lib/FreeRTOS-Kernel/stream_buffer.o \ - lib/FreeRTOS-Kernel/tasks.o \ - lib/FreeRTOS-Kernel/timers.o \ - lib/FreeRTOS-Kernel/portable/GCC/ARM_CM0/port.o \ - lib/FreeRTOS-Kernel/portable/MemMang/heap_4.o -OBJS += lib/STM32-base-STM32Cube/HAL/STM32F0xx/src/stm32f0xx_hal_rcc.o \ - lib/STM32-base-STM32Cube/HAL/STM32F0xx/src/stm32f0xx_hal_rcc_ex.o \ - lib/STM32-base-STM32Cube/HAL/STM32F0xx/src/stm32f0xx_hal.o \ - lib/STM32-base-STM32Cube/HAL/STM32F0xx/src/stm32f0xx_hal_i2c.o \ - lib/STM32-base-STM32Cube/HAL/STM32F0xx/src/stm32f0xx_hal_i2c_ex.o \ - lib/STM32-base-STM32Cube/HAL/STM32F0xx/src/stm32f0xx_hal_gpio.o \ - lib/STM32-base-STM32Cube/HAL/STM32F0xx/src/stm32f0xx_hal_dma.o \ - lib/STM32-base-STM32Cube/HAL/STM32F0xx/src/stm32f0xx_hal_cortex.o \ - lib/STM32-base-STM32Cube/HAL/STM32F0xx/src/stm32f0xx_hal_pwr.o \ - lib/STM32-base-STM32Cube/HAL/STM32F0xx/src/stm32f0xx_hal_pwr_ex.o \ - lib/STM32-base-STM32Cube/HAL/STM32F0xx/src/stm32f0xx_hal_flash.o \ - lib/STM32-base-STM32Cube/HAL/STM32F0xx/src/stm32f0xx_hal_flash_ex.o \ - lib/STM32-base-STM32Cube/HAL/STM32F0xx/src/stm32f0xx_hal_tim.o \ - lib/STM32-base-STM32Cube/HAL/STM32F0xx/src/stm32f0xx_hal_tim_ex.o \ - lib/STM32-base-STM32Cube/HAL/STM32F0xx/src/stm32f0xx_hal_uart.o \ - lib/STM32-base-STM32Cube/HAL/STM32F0xx/src/stm32f0xx_hal_uart_ex.o -OBJS += idle_task_static_memory.o -OBJS += main.o - -.PHONY: flash clean format +SRCS += $(LOCAL_SRCS) +SRCS += $(if $(STM), $(STM_SRCS), ) -$(TARGET).bin: $(TARGET).elf - $(OC) -O binary $< $@ - $(OS) $< +ifeq ($(PLATFORM),stm) +OBJS := $(patsubst %.c,%-stm.o, $(patsubst %.s,%-stm.o, $(SRCS))) +all: $(TARGET).bin +endif +ifeq ($(PLATFORM),ds) +OBJS := $(patsubst %.c,%-ds.o, $(SRCS)) +all: $(TARGET) +endif -%.o: %.s +%-stm.o: %.s $(CC) -c $(AFLAGS) $< -o $@ -lib/%.o: lib/%.c +lib/%-stm.o: lib/%.c $(CC) -c $(CFLAGS) -w $< -o $@ -%.o: %.c - $(CC) -c $(CFLAGS) $< -o $@ - %-stm.o: %.c $(CC) -c $(CFLAGS) $< -o $@ $(TARGET).elf: $(OBJS) - $(LD) $(LFLAGS) $^ -o $@ + $(LD) $^ $(LFLAGS) -o $@ +$(TARGET).bin: $(TARGET).elf + $(OC) -O binary $< $@ + $(OS) $< + +PHONY += flash flash: $(TARGET).bin st-flash --reset write $(TARGET).bin 0x08000000 -compile_commands.json: clean +%-ds.o: %.c + $(CC) -c $(CFLAGS) $< -o $@ + +$(TARGET): $(OBJS) + $(LD) $(LFLAGS) $^ -o $@ + +compile_commands.json: compiledb make -Bn ../scripts/compiledb-full-path-mingw.sh compile_commands.json +PHONY += format format: - clang-format -i $(SRCS) - clang-tidy --fix-errors $(SRCS) + clang-format -i $(LOCAL_SRCS) + clang-tidy --fix-errors $(LOCAL_SRCS) +PHONY += clean clean: $(RM) $(TARGET).bin $(TARGET).elf $(OBJS) +.PHONY: $(PHONY) diff --git a/src/stm32.mk b/src/stm32.mk new file mode 100644 index 0000000..a3b8338 --- /dev/null +++ b/src/stm32.mk @@ -0,0 +1,61 @@ +CC := arm-none-eabi-gcc +LD := arm-none-eabi-gcc +OC := arm-none-eabi-objcopy +OS := arm-none-eabi-size + +SHARED_FLAGS += -DSTM32F091xC +# SHARED_FLAGS += -Wno-register +SHARED_FLAGS += -Wa,--defsym,CALL_ARM_SYSTEM_INIT=1 +SHARED_FLAGS += -I./lib/STM32-base-STM32Cube/HAL/STM32F0xx/inc +SHARED_FLAGS += -I./lib/STM32-base-STM32Cube/HAL/STM32F0xx/inc/Legacy +SHARED_FLAGS += -I./lib/STM32-base-STM32Cube/CMSIS/ARM/inc +SHARED_FLAGS += -I./lib/STM32-base-STM32Cube/CMSIS/STM32F0xx/inc +SHARED_FLAGS += -I./lib/STM32-base/startup +SHARED_FLAGS += -I./lib/FreeRTOS-Kernel/include +SHARED_FLAGS += -I./lib/FreeRTOS-Kernel/portable/GCC/ARM_CM0/ +SHARED_FLAGS += -I. +SHARED_FLAGS += -I./stm32 +ifeq ($(HOST),GNU/Linux) +SHARED_FLAGS += -I/usr/arm-none-eabi/include/ +endif +SHARED_FLAGS += -ffunction-sections +SHARED_FLAGS += -fdata-sections +SHARED_FLAGS += -Wl,--gc-sections +SHARED_FLAGS += -mlittle-endian +SHARED_FLAGS += -mthumb +SHARED_FLAGS += -specs=nosys.specs +SHARED_FLAGS += -fno-exceptions +SHARED_FLAGS += -fno-unwind-tables +SHARED_FLAGS += -Wl,-L./lib/STM32-base/linker,-T./lib/STM32-base/linker/STM32F0xx/STM32F091xC.ld +SHARED_FLAGS += -mcpu=cortex-m0 +SHARED_FLAGS += -march=armv6-m + +STM_SRCS += lib/STM32-base/startup/STM32F0xx/STM32F091xC.s +STM_SRCS += lib/STM32-base-STM32Cube/CMSIS/STM32F0xx/src/system_stm32f0xx.c +STM_SRCS += lib/FreeRTOS-Kernel/croutine.c \ + lib/FreeRTOS-Kernel/event_groups.c \ + lib/FreeRTOS-Kernel/list.c \ + lib/FreeRTOS-Kernel/queue.c \ + lib/FreeRTOS-Kernel/stream_buffer.c \ + lib/FreeRTOS-Kernel/tasks.c \ + lib/FreeRTOS-Kernel/timers.c \ + lib/FreeRTOS-Kernel/portable/GCC/ARM_CM0/port.c \ + lib/FreeRTOS-Kernel/portable/MemMang/heap_4.c +STM_SRCS += lib/STM32-base-STM32Cube/HAL/STM32F0xx/src/stm32f0xx_hal_rcc.c \ + lib/STM32-base-STM32Cube/HAL/STM32F0xx/src/stm32f0xx_hal_rcc_ex.c \ + lib/STM32-base-STM32Cube/HAL/STM32F0xx/src/stm32f0xx_hal.c \ + lib/STM32-base-STM32Cube/HAL/STM32F0xx/src/stm32f0xx_hal_i2c.c \ + lib/STM32-base-STM32Cube/HAL/STM32F0xx/src/stm32f0xx_hal_i2c_ex.c \ + lib/STM32-base-STM32Cube/HAL/STM32F0xx/src/stm32f0xx_hal_gpio.c \ + lib/STM32-base-STM32Cube/HAL/STM32F0xx/src/stm32f0xx_hal_dma.c \ + lib/STM32-base-STM32Cube/HAL/STM32F0xx/src/stm32f0xx_hal_cortex.c \ + lib/STM32-base-STM32Cube/HAL/STM32F0xx/src/stm32f0xx_hal_pwr.c \ + lib/STM32-base-STM32Cube/HAL/STM32F0xx/src/stm32f0xx_hal_pwr_ex.c \ + lib/STM32-base-STM32Cube/HAL/STM32F0xx/src/stm32f0xx_hal_flash.c \ + lib/STM32-base-STM32Cube/HAL/STM32F0xx/src/stm32f0xx_hal_flash_ex.c \ + lib/STM32-base-STM32Cube/HAL/STM32F0xx/src/stm32f0xx_hal_tim.c \ + lib/STM32-base-STM32Cube/HAL/STM32F0xx/src/stm32f0xx_hal_tim_ex.c \ + lib/STM32-base-STM32Cube/HAL/STM32F0xx/src/stm32f0xx_hal_uart.c \ + lib/STM32-base-STM32Cube/HAL/STM32F0xx/src/stm32f0xx_hal_uart_ex.c +STM_SRCS += stm32/idle_task_static_memory.c + -- cgit v1.2.3