Fixes for 2021 board
[SCSI2SD-V6.git] / Makefile.2021
1 # Assume newlib gcc toolchain
2 ARMCC=arm-none-eabi-gcc
3 OBJCOPY=arm-none-eabi-objcopy
4
5 #CPPFLAGS=-DSTM32F446xx -DSTM32F4xx -DUSE_HAL_DRIVER -Wall -DS2S_USB_HS
6 CPPFLAGS=-DSTM32F446xx -DSTM32F4xx -DUSE_HAL_DRIVER -Wall -DS2S_USB_FS
7 CFLAGS=-mcpu=cortex-m4 -mthumb -mslow-flash-data \
8         -std=gnu11 \
9         -specs=nosys.specs \
10         -Os -g \
11
12 LDFLAGS= \
13         "-Tsrc/firmware/link.ld" \
14
15 INCLUDE = -Iinclude
16
17
18 STM32CubeMX_INCUDE = \
19         -ISTM32CubeMX/2021/Inc \
20         -ISTM32CubeMX/2021/Middlewares/ST/STM32_USB_Host_Library/Class/MSC/Inc \
21         -ISTM32CubeMX/2021/Middlewares/ST/STM32_USB_Host_Library/Core/Inc \
22         -ISTM32CubeMX/2021/Drivers/CMSIS/Include \
23         -ISTM32CubeMX/2021/Drivers/CMSIS/Device/ST/STM32F4xx/Include \
24         -ISTM32CubeMX/2021/Drivers/STM32F4xx_HAL_Driver/Inc \
25         -ISTM32CubeMX/2021/Middlewares/Third_Party/FatFs/src/ \
26         -ISTM32CubeMX/2021/Middlewares/Third_Party/FatFs/src/drivers \
27         -ISTM32CubeMX/2021/Middlewares/ST/STM32_USB_Device_Library/Core/Inc \
28         -Isrc/firmware/usb_device \
29
30 all: build/firmware.V6.2021.dfu
31
32 build/2021/stm32cubemx/dma.o: STM32CubeMX/2021/Src/dma.c
33 build/2021/stm32cubemx/fmc.o: STM32CubeMX/2021/Src/fmc.c
34 build/2021/stm32cubemx/gpio.o: STM32CubeMX/2021/Src/gpio.c
35 build/2021/stm32cubemx/main.o: STM32CubeMX/2021/Src/main.c
36 build/2021/stm32cubemx/sdio.o: STM32CubeMX/2021/Src/sdio.c
37 build/2021/stm32cubemx/spi.o: STM32CubeMX/2021/Src/spi.c
38 build/2021/stm32cubemx/stm32f4xx_hal_msp.o: STM32CubeMX/2021/Src/stm32f4xx_hal_msp.c
39 build/2021/stm32cubemx/stm32f4xx_it.o: STM32CubeMX/2021/Src/stm32f4xx_it.c
40 build/2021/stm32cubemx/usart.o: STM32CubeMX/2021/Src/usart.c
41 build/2021/stm32cubemx/usbd_conf.o: STM32CubeMX/2021/Src/usbd_conf.c
42 build/2021/stm32cubemx/stm32f4xx_hal.o: STM32CubeMX/2021/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.c
43 build/2021/stm32cubemx/stm32f4xx_hal_cortex.o: STM32CubeMX/2021/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cortex.c
44 build/2021/stm32cubemx/stm32f4xx_hal_dma.o: STM32CubeMX/2021/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma.c
45 build/2021/stm32cubemx/stm32f4xx_hal_flash.o: STM32CubeMX/2021/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash.c
46 build/2021/stm32cubemx/stm32f4xx_hal_flash_ex.o: STM32CubeMX/2021/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.c
47 build/2021/stm32cubemx/stm32f4xx_hal_gpio.o: STM32CubeMX/2021/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_gpio.c
48 build/2021/stm32cubemx/stm32f4xx_hal_hcd.o: STM32CubeMX/2021/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_hcd.c
49 build/2021/stm32cubemx/stm32f4xx_hal_pcd.o: STM32CubeMX/2021/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pcd.c
50 build/2021/stm32cubemx/stm32f4xx_hal_pcd_ex.o: STM32CubeMX/2021/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pcd_ex.c
51 build/2021/stm32cubemx/stm32f4xx_hal_pwr_ex.o: STM32CubeMX/2021/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr_ex.c
52 build/2021/stm32cubemx/stm32f4xx_hal_rcc.o: STM32CubeMX/2021/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc.c
53 build/2021/stm32cubemx/stm32f4xx_hal_rcc_ex.o: STM32CubeMX/2021/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc_ex.c
54 build/2021/stm32cubemx/stm32f4xx_hal_sd.o: STM32CubeMX/2021/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_sd.c
55 build/2021/stm32cubemx/stm32f4xx_hal_spi.o: STM32CubeMX/2021/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_spi.c
56 build/2021/stm32cubemx/stm32f4xx_hal_sram.o: STM32CubeMX/2021/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_sram.c
57 build/2021/stm32cubemx/stm32f4xx_hal_tim.o: STM32CubeMX/2021/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim.c
58 build/2021/stm32cubemx/stm32f4xx_hal_tim_ex.o: STM32CubeMX/2021/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim_ex.c
59 build/2021/stm32cubemx/stm32f4xx_hal_uart.o: STM32CubeMX/2021/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_uart.c
60 build/2021/stm32cubemx/stm32f4xx_ll_fmc.o: STM32CubeMX/2021/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_fmc.c
61 build/2021/stm32cubemx/stm32f4xx_ll_fsmc.o: STM32CubeMX/2021/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_fsmc.c
62 build/2021/stm32cubemx/stm32f4xx_ll_sdmmc.o: STM32CubeMX/2021/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_sdmmc.c
63 build/2021/stm32cubemx/stm32f4xx_ll_usb.o: STM32CubeMX/2021/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_usb.c
64 build/2021/stm32cubemx/usbd_core.o: STM32CubeMX/2021/Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_core.c
65 build/2021/stm32cubemx/usbd_ctlreq.o: STM32CubeMX/2021/Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ctlreq.c
66 build/2021/stm32cubemx/usbd_ioreq.o: STM32CubeMX/2021/Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ioreq.c
67 build/2021/stm32cubemx/system_stm32f4xx.o: STM32CubeMX/2021/Drivers/CMSIS/Device/ST/STM32F4xx/Source/Templates/system_stm32f4xx.c
68 build/2021/stm32cubemx/startup_stm32f446xx.o: STM32CubeMX/2021/Drivers/CMSIS/Device/ST/STM32F4xx/Source/Templates/gcc/startup_stm32f446xx.s
69
70 STM32OBJS = \
71         build/2021/stm32cubemx/dma.o \
72         build/2021/stm32cubemx/fmc.o \
73         build/2021/stm32cubemx/gpio.o \
74         build/2021/stm32cubemx/main.o \
75         build/2021/stm32cubemx/sdio.o \
76         build/2021/stm32cubemx/spi.o \
77         build/2021/stm32cubemx/stm32f4xx_hal_msp.o \
78         build/2021/stm32cubemx/stm32f4xx_it.o \
79         build/2021/stm32cubemx/usart.o \
80         build/2021/stm32cubemx/usbd_conf.o \
81         build/2021/stm32cubemx/stm32f4xx_hal.o \
82         build/2021/stm32cubemx/stm32f4xx_hal_cortex.o \
83         build/2021/stm32cubemx/stm32f4xx_hal_dma.o \
84         build/2021/stm32cubemx/stm32f4xx_hal_flash.o \
85         build/2021/stm32cubemx/stm32f4xx_hal_flash_ex.o \
86         build/2021/stm32cubemx/stm32f4xx_hal_gpio.o \
87         build/2021/stm32cubemx/stm32f4xx_hal_hcd.o \
88         build/2021/stm32cubemx/stm32f4xx_hal_pcd.o \
89         build/2021/stm32cubemx/stm32f4xx_hal_pcd_ex.o \
90         build/2021/stm32cubemx/stm32f4xx_hal_pwr_ex.o \
91         build/2021/stm32cubemx/stm32f4xx_hal_rcc.o \
92         build/2021/stm32cubemx/stm32f4xx_hal_rcc_ex.o \
93         build/2021/stm32cubemx/stm32f4xx_hal_sd.o \
94         build/2021/stm32cubemx/stm32f4xx_hal_spi.o \
95         build/2021/stm32cubemx/stm32f4xx_hal_sram.o \
96         build/2021/stm32cubemx/stm32f4xx_hal_tim.o \
97         build/2021/stm32cubemx/stm32f4xx_hal_tim_ex.o \
98         build/2021/stm32cubemx/stm32f4xx_hal_uart.o \
99         build/2021/stm32cubemx/stm32f4xx_ll_fmc.o \
100         build/2021/stm32cubemx/stm32f4xx_ll_fsmc.o \
101         build/2021/stm32cubemx/stm32f4xx_ll_sdmmc.o \
102         build/2021/stm32cubemx/stm32f4xx_ll_usb.o \
103         build/2021/stm32cubemx/usbd_core.o \
104         build/2021/stm32cubemx/usbd_ctlreq.o \
105         build/2021/stm32cubemx/usbd_ioreq.o \
106         build/2021/stm32cubemx/system_stm32f4xx.o \
107         build/2021/stm32cubemx/startup_stm32f446xx.o \
108
109 # Modified versin from stm32cubemx for a composite class with both
110 # mass-storage and HID interfaces
111 USBCOMPOSITE_SRC= \
112         src/firmware/usb_device/usb_device.c \
113         src/firmware/usb_device/usbd_composite.c \
114         src/firmware/usb_device/usbd_desc.c \
115         src/firmware/usb_device/usbd_hid.c \
116         src/firmware/usb_device/usbd_msc_bot.c \
117         src/firmware/usb_device/usbd_msc.c \
118         src/firmware/usb_device/usbd_msc_data.c \
119         src/firmware/usb_device/usbd_msc_scsi.c \
120         src/firmware/usb_device/usbd_msc_storage_sd.c \
121
122 SRC = \
123         src/firmware/bootloader.c \
124         src/firmware/bsp.c \
125         src/firmware/cdrom.c \
126         src/firmware/config.c \
127         src/firmware/disk.c \
128         src/firmware/diagnostic.c \
129         src/firmware/fpga.c \
130         src/firmware/geometry.c \
131         src/firmware/hidpacket.c \
132         src/firmware/hwversion.c \
133         src/firmware/inquiry.c \
134         src/firmware/led.c \
135         src/firmware/main.c \
136         src/firmware/mo.c \
137         src/firmware/mode.c \
138         src/firmware/scsiPhy.c \
139         src/firmware/scsi.c \
140         src/firmware/sd.c \
141         src/firmware/spinlock.c \
142         src/firmware/tape.c \
143         src/firmware/time.c \
144         src/firmware/vendor.c \
145         src/firmware/bsp_driver_sd.c \
146         ${USBCOMPOSITE_SRC}
147
148 build/2021/firmware.elf: $(SRC) rtl/fpga_bitmap.o $(STM32OBJS)
149         $(ARMCC) $(CPPFLAGS) $(CFLAGS) -o $@ $(STM32CubeMX_INCUDE) $(INCLUDE) $^ $(LDFLAGS)
150         @EBSS=`arm-none-eabi-nm build/2021/firmware.elf | grep _ebss | cut -f1 "-d "`; \
151         echo HEAPSIZE = $$((0x2001C000 - 0x$${EBSS})) bytes
152         @echo STACKSIZE = 16384 bytes
153
154
155 build/2021/firmware.bin: build/2021/firmware.elf
156         $(OBJCOPY) -O binary $< $@
157
158 # Example to hard-code config within firmware
159 #sudo arm-none-eabi-objcopy --update-section .fixed_config=config.dat firmware.elf -O binary firmware.bin
160
161 build/2021/stm32cubemx/%.o:
162         mkdir -p build/2021/stm32cubemx
163         $(ARMCC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $(STM32CubeMX_INCUDE) $(INCLUDE) $^
164
165
166 build/2021/stm32cubemx/stm32f4xx_it.o:
167         mkdir -p build/2021/stm32cubemx
168         $(ARMCC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $(STM32CubeMX_INCUDE) $(INCLUDE) $^
169         $(OBJCOPY) -N EXTI4_IRQHandler $@
170
171 build/2021/stm32cubemx/system_stm32f4xx.o:
172         mkdir -p build/2021/stm32cubemx
173         $(ARMCC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $(STM32CubeMX_INCUDE) $(INCLUDE) $^
174         $(OBJCOPY) --redefine-sym SystemInit=OrigSystemInit $@
175
176 build/2021/scsiPhy.s: src/firmware/scsiPhy.c
177         $(ARMCC) $(CPPFLAGS) $(CFLAGS) -S -o $@ $(STM32CubeMX_INCUDE) $(INCLUDE) $^
178
179
180 build/firmware.V6.2021.dfu: build/2021/firmware.bin
181         python tools/dfu-convert.py -b 0x08000000:$< $@
182
183 clean:
184         rm -f build/firmware.V6.2021.dfu
185         rm -rf build/2021/
186
187 program:
188         dfu-util --download build/firmware.V6.2021.dfu --alt 0
189