b90b51a305db3e01a79618080f58af8bc5a9cb21
[SCSI2SD-V6.git] / Makefile
1 # Assume newlib gcc toolchain
2 ARMCC=arm-none-eabi-gcc
3 OBJCOPY=arm-none-eabi-objcopy
4
5 CPPFLAGS=-DSTM32F205xx -DUSE_HAL_DRIVER -Wall -Werror
6 CFLAGS=-mcpu=cortex-m3 -mthumb -mslow-flash-data \
7         -std=gnu11 \
8         -specs=nosys.specs \
9         -Os -g \
10
11 LDFLAGS= \
12         "-Tsrc/firmware/link.ld" \
13
14 INCLUDE = -Iinclude
15
16
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 \
28
29 all: build/firmware.dfu
30
31 build/stm32cubemx/bsp_driver_sd.o: STM32CubeMX/SCSI2SD-V6/Src/bsp_driver_sd.c
32 build/stm32cubemx/fsmc.o: STM32CubeMX/SCSI2SD-V6/Src/fsmc.c
33 build/stm32cubemx/gpio.o: STM32CubeMX/SCSI2SD-V6/Src/gpio.c
34 build/stm32cubemx/main.o: STM32CubeMX/SCSI2SD-V6/Src/main.c
35 build/stm32cubemx/sdio.o: STM32CubeMX/SCSI2SD-V6/Src/sdio.c
36 build/stm32cubemx/spi.o: STM32CubeMX/SCSI2SD-V6/Src/spi.c
37 build/stm32cubemx/stm32f2xx_hal_msp.o: STM32CubeMX/SCSI2SD-V6/Src/stm32f2xx_hal_msp.c
38 build/stm32cubemx/stm32f2xx_it.o: STM32CubeMX/SCSI2SD-V6/Src/stm32f2xx_it.c
39 build/stm32cubemx/usart.o: STM32CubeMX/SCSI2SD-V6/Src/usart.c
40 build/stm32cubemx/usbd_conf.o: STM32CubeMX/SCSI2SD-V6/Src/usbd_conf.c
41 build/stm32cubemx/usbh_conf.o: STM32CubeMX/SCSI2SD-V6/Src/usbh_conf.c
42 build/stm32cubemx/usb_host.o: STM32CubeMX/SCSI2SD-V6/Src/usb_host.c
43 build/stm32cubemx/stm32f2xx_hal.o: STM32CubeMX/SCSI2SD-V6/Drivers/STM32F2xx_HAL_Driver/Src/stm32f2xx_hal.c
44 build/stm32cubemx/stm32f2xx_hal_cortex.o: STM32CubeMX/SCSI2SD-V6/Drivers/STM32F2xx_HAL_Driver/Src/stm32f2xx_hal_cortex.c
45 build/stm32cubemx/stm32f2xx_hal_dma.o: STM32CubeMX/SCSI2SD-V6/Drivers/STM32F2xx_HAL_Driver/Src/stm32f2xx_hal_dma.c
46 build/stm32cubemx/stm32f2xx_hal_gpio.o: STM32CubeMX/SCSI2SD-V6/Drivers/STM32F2xx_HAL_Driver/Src/stm32f2xx_hal_gpio.c
47 build/stm32cubemx/stm32f2xx_hal_hcd.o: STM32CubeMX/SCSI2SD-V6/Drivers/STM32F2xx_HAL_Driver/Src/stm32f2xx_hal_hcd.c
48 build/stm32cubemx/stm32f2xx_hal_pcd.o: STM32CubeMX/SCSI2SD-V6/Drivers/STM32F2xx_HAL_Driver/Src/stm32f2xx_hal_pcd.c
49 build/stm32cubemx/stm32f2xx_hal_pcd_ex.o: STM32CubeMX/SCSI2SD-V6/Drivers/STM32F2xx_HAL_Driver/Src/stm32f2xx_hal_pcd_ex.c
50 build/stm32cubemx/stm32f2xx_hal_rcc.o: STM32CubeMX/SCSI2SD-V6/Drivers/STM32F2xx_HAL_Driver/Src/stm32f2xx_hal_rcc.c
51 build/stm32cubemx/stm32f2xx_hal_sd.o: STM32CubeMX/SCSI2SD-V6/Drivers/STM32F2xx_HAL_Driver/Src/stm32f2xx_hal_sd.c
52 build/stm32cubemx/stm32f2xx_hal_spi.o: STM32CubeMX/SCSI2SD-V6/Drivers/STM32F2xx_HAL_Driver/Src/stm32f2xx_hal_spi.c
53 build/stm32cubemx/stm32f2xx_hal_sram.o: STM32CubeMX/SCSI2SD-V6/Drivers/STM32F2xx_HAL_Driver/Src/stm32f2xx_hal_sram.c
54 build/stm32cubemx/stm32f2xx_hal_tim.o: STM32CubeMX/SCSI2SD-V6/Drivers/STM32F2xx_HAL_Driver/Src/stm32f2xx_hal_tim.c
55 build/stm32cubemx/stm32f2xx_hal_tim_ex.o: STM32CubeMX/SCSI2SD-V6/Drivers/STM32F2xx_HAL_Driver/Src/stm32f2xx_hal_tim_ex.c
56 build/stm32cubemx/stm32f2xx_hal_uart.o: STM32CubeMX/SCSI2SD-V6/Drivers/STM32F2xx_HAL_Driver/Src/stm32f2xx_hal_uart.c
57 build/stm32cubemx/stm32f2xx_ll_fsmc.o: STM32CubeMX/SCSI2SD-V6/Drivers/STM32F2xx_HAL_Driver/Src/stm32f2xx_ll_fsmc.c
58 build/stm32cubemx/stm32f2xx_ll_sdmmc.o: STM32CubeMX/SCSI2SD-V6/Drivers/STM32F2xx_HAL_Driver/Src/stm32f2xx_ll_sdmmc.c
59 build/stm32cubemx/stm32f2xx_ll_usb.o: STM32CubeMX/SCSI2SD-V6/Drivers/STM32F2xx_HAL_Driver/Src/stm32f2xx_ll_usb.c
60 build/stm32cubemx/usbd_core.o: STM32CubeMX/SCSI2SD-V6/Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_core.c
61 build/stm32cubemx/usbd_ctlreq.o: STM32CubeMX/SCSI2SD-V6/Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ctlreq.c
62 build/stm32cubemx/usbd_ioreq.o: STM32CubeMX/SCSI2SD-V6/Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ioreq.c
63 build/stm32cubemx/usbh_core.o: STM32CubeMX/SCSI2SD-V6/Middlewares/ST/STM32_USB_Host_Library/Core/Src/usbh_core.c
64 build/stm32cubemx/usbh_ctlreq.o: STM32CubeMX/SCSI2SD-V6/Middlewares/ST/STM32_USB_Host_Library/Core/Src/usbh_ctlreq.c
65 build/stm32cubemx/usbh_ioreq.o: STM32CubeMX/SCSI2SD-V6/Middlewares/ST/STM32_USB_Host_Library/Core/Src/usbh_ioreq.c
66 build/stm32cubemx/usbh_pipes.o: STM32CubeMX/SCSI2SD-V6/Middlewares/ST/STM32_USB_Host_Library/Core/Src/usbh_pipes.c
67 build/stm32cubemx/usbh_msc.o: STM32CubeMX/SCSI2SD-V6/Middlewares/ST/STM32_USB_Host_Library/Class/MSC/Src/usbh_msc.c
68 build/stm32cubemx/usbh_msc_bot.o: STM32CubeMX/SCSI2SD-V6/Middlewares/ST/STM32_USB_Host_Library/Class/MSC/Src/usbh_msc_bot.c
69 build/stm32cubemx/usbh_msc_scsi.o: STM32CubeMX/SCSI2SD-V6/Middlewares/ST/STM32_USB_Host_Library/Class/MSC/Src/usbh_msc_scsi.c
70 build/stm32cubemx/system_stm32f2xx.o: STM32CubeMX/SCSI2SD-V6/Drivers/CMSIS/Device/ST/STM32F2xx/Source/Templates/system_stm32f2xx.c
71 build/stm32cubemx/startup_stm32f205xx.o: STM32CubeMX/SCSI2SD-V6/Drivers/CMSIS/Device/ST/STM32F2xx/Source/Templates/gcc/startup_stm32f205xx.s
72
73 STM32OBJS = \
74         build/stm32cubemx/bsp_driver_sd.o \
75         build/stm32cubemx/fsmc.o \
76         build/stm32cubemx/gpio.o \
77         build/stm32cubemx/main.o \
78         build/stm32cubemx/sdio.o \
79         build/stm32cubemx/spi.o \
80         build/stm32cubemx/stm32f2xx_hal_msp.o \
81         build/stm32cubemx/stm32f2xx_it.o \
82         build/stm32cubemx/usart.o \
83         build/stm32cubemx/usbd_conf.o \
84         build/stm32cubemx/usbh_conf.o \
85         build/stm32cubemx/usb_host.o \
86         build/stm32cubemx/stm32f2xx_hal.o \
87         build/stm32cubemx/stm32f2xx_hal_cortex.o \
88         build/stm32cubemx/stm32f2xx_hal_dma.o \
89         build/stm32cubemx/stm32f2xx_hal_gpio.o \
90         build/stm32cubemx/stm32f2xx_hal_hcd.o \
91         build/stm32cubemx/stm32f2xx_hal_pcd.o \
92         build/stm32cubemx/stm32f2xx_hal_pcd_ex.o \
93         build/stm32cubemx/stm32f2xx_hal_rcc.o \
94         build/stm32cubemx/stm32f2xx_hal_sd.o \
95         build/stm32cubemx/stm32f2xx_hal_spi.o \
96         build/stm32cubemx/stm32f2xx_hal_sram.o \
97         build/stm32cubemx/stm32f2xx_hal_tim.o \
98         build/stm32cubemx/stm32f2xx_hal_tim_ex.o \
99         build/stm32cubemx/stm32f2xx_hal_uart.o \
100         build/stm32cubemx/stm32f2xx_ll_fsmc.o \
101         build/stm32cubemx/stm32f2xx_ll_sdmmc.o \
102         build/stm32cubemx/stm32f2xx_ll_usb.o \
103         build/stm32cubemx/usbd_core.o \
104         build/stm32cubemx/usbd_ctlreq.o \
105         build/stm32cubemx/usbd_ioreq.o \
106         build/stm32cubemx/usbh_core.o \
107         build/stm32cubemx/usbh_ctlreq.o \
108         build/stm32cubemx/usbh_ioreq.o \
109         build/stm32cubemx/usbh_pipes.o \
110         build/stm32cubemx/usbh_msc.o \
111         build/stm32cubemx/usbh_msc_bot.o \
112         build/stm32cubemx/usbh_msc_scsi.o \
113         build/stm32cubemx/system_stm32f2xx.o \
114         build/stm32cubemx/startup_stm32f205xx.o \
115
116 # Modified versin from stm32cubemx for a composite class with both
117 # mass-storage and HID interfaces
118 USBCOMPOSITE_SRC= \
119         src/firmware/usb_device/usb_device.c \
120         src/firmware/usb_device/usbd_composite.c \
121         src/firmware/usb_device/usbd_desc.c \
122         src/firmware/usb_device/usbd_hid.c \
123         src/firmware/usb_device/usbd_msc_bot.c \
124         src/firmware/usb_device/usbd_msc.c \
125         src/firmware/usb_device/usbd_msc_data.c \
126         src/firmware/usb_device/usbd_msc_scsi.c \
127         src/firmware/usb_device/usbd_msc_storage_sd.c \
128
129 SRC = \
130         src/firmware/bootloader.c \
131         src/firmware/bsp.c \
132         src/firmware/cdrom.c \
133         src/firmware/config.c \
134         src/firmware/disk.c \
135         src/firmware/diagnostic.c \
136         src/firmware/fpga.c \
137         src/firmware/geometry.c \
138         src/firmware/hidpacket.c \
139         src/firmware/inquiry.c \
140         src/firmware/led.c \
141         src/firmware/main.c \
142         src/firmware/mo.c \
143         src/firmware/mode.c \
144         src/firmware/scsiPhy.c \
145         src/firmware/scsi.c \
146         src/firmware/sd.c \
147         src/firmware/spinlock.c \
148         src/firmware/tape.c \
149         src/firmware/time.c \
150         src/firmware/trace.c \
151         ${USBCOMPOSITE_SRC}
152
153 build/firmware.elf: $(SRC) rtl/fpga_bitmap.o $(STM32OBJS)
154         $(ARMCC) $(CPPFLAGS) $(CFLAGS) -o $@ $(STM32CubeMX_INCUDE) $(INCLUDE) $^ $(LDFLAGS)
155         @EBSS=`arm-none-eabi-nm build/firmware.elf | grep _ebss | cut -f1 "-d "`; \
156         echo HEAPSIZE = $$((0x2001C000 - 0x$${EBSS})) bytes
157         @echo STACKSIZE = 16384 bytes
158
159
160 build/firmware.bin: build/firmware.elf
161         $(OBJCOPY) -O binary $< $@
162
163 build/stm32cubemx/%.o:
164         mkdir -p build/stm32cubemx
165         $(ARMCC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $(STM32CubeMX_INCUDE) $(INCLUDE) $^
166
167
168 build/stm32cubemx/stm32f2xx_it.o:
169         mkdir -p build/stm32cubemx
170         $(ARMCC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $(STM32CubeMX_INCUDE) $(INCLUDE) $^
171         $(OBJCOPY) -N EXTI4_IRQHandler $@
172
173 build/stm32cubemx/system_stm32f2xx.o:
174         mkdir -p build/stm32cubemx
175         $(ARMCC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $(STM32CubeMX_INCUDE) $(INCLUDE) $^
176         $(OBJCOPY) --redefine-sym SystemInit=OrigSystemInit $@
177
178 build/scsiPhy.s: src/firmware/scsiPhy.c
179         $(ARMCC) $(CPPFLAGS) $(CFLAGS) -S -o $@ $(STM32CubeMX_INCUDE) $(INCLUDE) $^
180
181
182 build/firmware.dfu: build/firmware.bin
183         python tools/dfu-convert.py -b 0x08000000:$< $@
184
185 clean:
186         rm -f build/firmware.elf build/firmware.bin
187
188 program:
189         dfu-util --download build/firmware.dfu --alt 0