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