1 # Assume newlib gcc toolchain
2 ARMCC=arm-none-eabi-gcc
3 OBJCOPY=arm-none-eabi-objcopy
5 CPPFLAGS=-DSTM32F205xx -DUSE_HAL_DRIVER -Wall
6 CFLAGS=-mcpu=cortex-m3 -mthumb -mslow-flash-data \
12 "-Tsrc/firmware/link.ld" \
17 STM32CubeMX_INCUDE = \
18 -ISTM32CubeMX/SCSI2SD-V6/Inc \
19 -ISTM32CubeMX/SCSI2SD-V6/Middlewares/ST/STM32_USB_Host_Library/Class/MSC/Inc \
20 -ISTM32CubeMX/SCSI2SD-V6/Middlewares/ST/STM32_USB_Host_Library/Core/Inc \
21 -ISTM32CubeMX/SCSI2SD-V6/Drivers/CMSIS/Include \
22 -ISTM32CubeMX/SCSI2SD-V6/Drivers/CMSIS/Device/ST/STM32F2xx/Include \
23 -ISTM32CubeMX/SCSI2SD-V6/Drivers/STM32F2xx_HAL_Driver/Inc \
24 -ISTM32CubeMX/SCSI2SD-V6/Middlewares/Third_Party/FatFs/src/ \
25 -ISTM32CubeMX/SCSI2SD-V6/Middlewares/Third_Party/FatFs/src/drivers \
26 -ISTM32CubeMX/SCSI2SD-V6/Middlewares/ST/STM32_USB_Device_Library/Core/Inc \
27 -Isrc/firmware/usb_device \
29 all: build/firmware.dfu
31 build/stm32cubemx/fsmc.o: STM32CubeMX/SCSI2SD-V6/Src/fsmc.c
32 build/stm32cubemx/gpio.o: STM32CubeMX/SCSI2SD-V6/Src/gpio.c
33 build/stm32cubemx/main.o: STM32CubeMX/SCSI2SD-V6/Src/main.c
34 build/stm32cubemx/sdio.o: STM32CubeMX/SCSI2SD-V6/Src/sdio.c
35 build/stm32cubemx/spi.o: STM32CubeMX/SCSI2SD-V6/Src/spi.c
36 build/stm32cubemx/stm32f2xx_hal_msp.o: STM32CubeMX/SCSI2SD-V6/Src/stm32f2xx_hal_msp.c
37 build/stm32cubemx/stm32f2xx_it.o: STM32CubeMX/SCSI2SD-V6/Src/stm32f2xx_it.c
38 build/stm32cubemx/usart.o: STM32CubeMX/SCSI2SD-V6/Src/usart.c
39 build/stm32cubemx/usbd_conf.o: STM32CubeMX/SCSI2SD-V6/Src/usbd_conf.c
40 build/stm32cubemx/stm32f2xx_hal.o: STM32CubeMX/SCSI2SD-V6/Drivers/STM32F2xx_HAL_Driver/Src/stm32f2xx_hal.c
41 build/stm32cubemx/stm32f2xx_hal_cortex.o: STM32CubeMX/SCSI2SD-V6/Drivers/STM32F2xx_HAL_Driver/Src/stm32f2xx_hal_cortex.c
42 build/stm32cubemx/stm32f2xx_hal_dma.o: STM32CubeMX/SCSI2SD-V6/Drivers/STM32F2xx_HAL_Driver/Src/stm32f2xx_hal_dma.c
43 build/stm32cubemx/stm32f2xx_hal_flash.o: STM32CubeMX/SCSI2SD-V6/Drivers/STM32F2xx_HAL_Driver/Src/stm32f2xx_hal_flash.c
44 build/stm32cubemx/stm32f2xx_hal_flash_ex.o: STM32CubeMX/SCSI2SD-V6/Drivers/STM32F2xx_HAL_Driver/Src/stm32f2xx_hal_flash_ex.c
45 build/stm32cubemx/stm32f2xx_hal_gpio.o: STM32CubeMX/SCSI2SD-V6/Drivers/STM32F2xx_HAL_Driver/Src/stm32f2xx_hal_gpio.c
46 build/stm32cubemx/stm32f2xx_hal_hcd.o: STM32CubeMX/SCSI2SD-V6/Drivers/STM32F2xx_HAL_Driver/Src/stm32f2xx_hal_hcd.c
47 build/stm32cubemx/stm32f2xx_hal_pcd.o: STM32CubeMX/SCSI2SD-V6/Drivers/STM32F2xx_HAL_Driver/Src/stm32f2xx_hal_pcd.c
48 build/stm32cubemx/stm32f2xx_hal_pcd_ex.o: STM32CubeMX/SCSI2SD-V6/Drivers/STM32F2xx_HAL_Driver/Src/stm32f2xx_hal_pcd_ex.c
49 build/stm32cubemx/stm32f2xx_hal_rcc.o: STM32CubeMX/SCSI2SD-V6/Drivers/STM32F2xx_HAL_Driver/Src/stm32f2xx_hal_rcc.c
50 build/stm32cubemx/stm32f2xx_hal_sd.o: STM32CubeMX/SCSI2SD-V6/Drivers/STM32F2xx_HAL_Driver/Src/stm32f2xx_hal_sd.c
51 build/stm32cubemx/stm32f2xx_hal_spi.o: STM32CubeMX/SCSI2SD-V6/Drivers/STM32F2xx_HAL_Driver/Src/stm32f2xx_hal_spi.c
52 build/stm32cubemx/stm32f2xx_hal_sram.o: STM32CubeMX/SCSI2SD-V6/Drivers/STM32F2xx_HAL_Driver/Src/stm32f2xx_hal_sram.c
53 build/stm32cubemx/stm32f2xx_hal_tim.o: STM32CubeMX/SCSI2SD-V6/Drivers/STM32F2xx_HAL_Driver/Src/stm32f2xx_hal_tim.c
54 build/stm32cubemx/stm32f2xx_hal_tim_ex.o: STM32CubeMX/SCSI2SD-V6/Drivers/STM32F2xx_HAL_Driver/Src/stm32f2xx_hal_tim_ex.c
55 build/stm32cubemx/stm32f2xx_hal_uart.o: STM32CubeMX/SCSI2SD-V6/Drivers/STM32F2xx_HAL_Driver/Src/stm32f2xx_hal_uart.c
56 build/stm32cubemx/stm32f2xx_ll_fsmc.o: STM32CubeMX/SCSI2SD-V6/Drivers/STM32F2xx_HAL_Driver/Src/stm32f2xx_ll_fsmc.c
57 build/stm32cubemx/stm32f2xx_ll_sdmmc.o: STM32CubeMX/SCSI2SD-V6/Drivers/STM32F2xx_HAL_Driver/Src/stm32f2xx_ll_sdmmc.c
58 build/stm32cubemx/stm32f2xx_ll_usb.o: STM32CubeMX/SCSI2SD-V6/Drivers/STM32F2xx_HAL_Driver/Src/stm32f2xx_ll_usb.c
59 build/stm32cubemx/usbd_core.o: STM32CubeMX/SCSI2SD-V6/Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_core.c
60 build/stm32cubemx/usbd_ctlreq.o: STM32CubeMX/SCSI2SD-V6/Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ctlreq.c
61 build/stm32cubemx/usbd_ioreq.o: STM32CubeMX/SCSI2SD-V6/Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ioreq.c
62 build/stm32cubemx/system_stm32f2xx.o: STM32CubeMX/SCSI2SD-V6/Drivers/CMSIS/Device/ST/STM32F2xx/Source/Templates/system_stm32f2xx.c
63 build/stm32cubemx/startup_stm32f205xx.o: STM32CubeMX/SCSI2SD-V6/Drivers/CMSIS/Device/ST/STM32F2xx/Source/Templates/gcc/startup_stm32f205xx.s
66 build/stm32cubemx/fsmc.o \
67 build/stm32cubemx/gpio.o \
68 build/stm32cubemx/main.o \
69 build/stm32cubemx/sdio.o \
70 build/stm32cubemx/spi.o \
71 build/stm32cubemx/stm32f2xx_hal_msp.o \
72 build/stm32cubemx/stm32f2xx_it.o \
73 build/stm32cubemx/usart.o \
74 build/stm32cubemx/usbd_conf.o \
75 build/stm32cubemx/stm32f2xx_hal.o \
76 build/stm32cubemx/stm32f2xx_hal_cortex.o \
77 build/stm32cubemx/stm32f2xx_hal_dma.o \
78 build/stm32cubemx/stm32f2xx_hal_flash.o \
79 build/stm32cubemx/stm32f2xx_hal_flash_ex.o \
80 build/stm32cubemx/stm32f2xx_hal_gpio.o \
81 build/stm32cubemx/stm32f2xx_hal_hcd.o \
82 build/stm32cubemx/stm32f2xx_hal_pcd.o \
83 build/stm32cubemx/stm32f2xx_hal_pcd_ex.o \
84 build/stm32cubemx/stm32f2xx_hal_rcc.o \
85 build/stm32cubemx/stm32f2xx_hal_sd.o \
86 build/stm32cubemx/stm32f2xx_hal_spi.o \
87 build/stm32cubemx/stm32f2xx_hal_sram.o \
88 build/stm32cubemx/stm32f2xx_hal_tim.o \
89 build/stm32cubemx/stm32f2xx_hal_tim_ex.o \
90 build/stm32cubemx/stm32f2xx_hal_uart.o \
91 build/stm32cubemx/stm32f2xx_ll_fsmc.o \
92 build/stm32cubemx/stm32f2xx_ll_sdmmc.o \
93 build/stm32cubemx/stm32f2xx_ll_usb.o \
94 build/stm32cubemx/usbd_core.o \
95 build/stm32cubemx/usbd_ctlreq.o \
96 build/stm32cubemx/usbd_ioreq.o \
97 build/stm32cubemx/system_stm32f2xx.o \
98 build/stm32cubemx/startup_stm32f205xx.o \
100 # Modified versin from stm32cubemx for a composite class with both
101 # mass-storage and HID interfaces
103 src/firmware/usb_device/usb_device.c \
104 src/firmware/usb_device/usbd_composite.c \
105 src/firmware/usb_device/usbd_desc.c \
106 src/firmware/usb_device/usbd_hid.c \
107 src/firmware/usb_device/usbd_msc_bot.c \
108 src/firmware/usb_device/usbd_msc.c \
109 src/firmware/usb_device/usbd_msc_data.c \
110 src/firmware/usb_device/usbd_msc_scsi.c \
111 src/firmware/usb_device/usbd_msc_storage_sd.c \
114 src/firmware/bootloader.c \
116 src/firmware/cdrom.c \
117 src/firmware/config.c \
118 src/firmware/disk.c \
119 src/firmware/diagnostic.c \
120 src/firmware/fpga.c \
121 src/firmware/geometry.c \
122 src/firmware/hidpacket.c \
123 src/firmware/hwversion.c \
124 src/firmware/inquiry.c \
126 src/firmware/main.c \
128 src/firmware/mode.c \
129 src/firmware/scsiPhy.c \
130 src/firmware/scsi.c \
132 src/firmware/spinlock.c \
133 src/firmware/tape.c \
134 src/firmware/time.c \
135 src/firmware/vendor.c \
136 src/firmware/bsp_driver_sd.c \
139 build/firmware.elf: $(SRC) rtl/fpga_bitmap.o $(STM32OBJS)
140 $(ARMCC) $(CPPFLAGS) $(CFLAGS) -o $@ $(STM32CubeMX_INCUDE) $(INCLUDE) $^ $(LDFLAGS)
141 @EBSS=`arm-none-eabi-nm build/firmware.elf | grep _ebss | cut -f1 "-d "`; \
142 echo HEAPSIZE = $$((0x2001C000 - 0x$${EBSS})) bytes
143 @echo STACKSIZE = 16384 bytes
146 build/firmware.bin: build/firmware.elf
147 $(OBJCOPY) -O binary $< $@
149 # Example to hard-code config within firmware
150 #sudo arm-none-eabi-objcopy --update-section .fixed_config=config.dat firmware.elf -O binary firmware.bin
152 build/stm32cubemx/%.o:
153 mkdir -p build/stm32cubemx
154 $(ARMCC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $(STM32CubeMX_INCUDE) $(INCLUDE) $^
157 build/stm32cubemx/stm32f2xx_it.o:
158 mkdir -p build/stm32cubemx
159 $(ARMCC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $(STM32CubeMX_INCUDE) $(INCLUDE) $^
160 $(OBJCOPY) -N EXTI4_IRQHandler $@
162 build/stm32cubemx/system_stm32f2xx.o:
163 mkdir -p build/stm32cubemx
164 $(ARMCC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $(STM32CubeMX_INCUDE) $(INCLUDE) $^
165 $(OBJCOPY) --redefine-sym SystemInit=OrigSystemInit $@
167 build/scsiPhy.s: src/firmware/scsiPhy.c
168 $(ARMCC) $(CPPFLAGS) $(CFLAGS) -S -o $@ $(STM32CubeMX_INCUDE) $(INCLUDE) $^
171 build/firmware.dfu: build/firmware.bin
172 python tools/dfu-convert.py -b 0x08000000:$< $@
175 rm -f build/firmware.elf build/firmware.bin
178 dfu-util --download build/firmware.dfu --alt 0