diff --git a/.gitignore b/.gitignore index ff73199c..d7441e60 100644 --- a/.gitignore +++ b/.gitignore @@ -72,10 +72,12 @@ eagle.epf *.eps obj_* inc/commandslist.h -inc/hal_tbl.h +inc/comps/* +inc/shared_comps/* src/hal_tbl.c src/conf_templates.c stm32f303/inc/commandslist.h -stm32f303/inc/hal_tbl.h +stm32f303/inc/comps/* +stm32f303/inc/shared_comps/* stm32f303/src/hal_tbl.c toolchain-user.mak diff --git a/Makefile b/Makefile index 7687fec3..e5726179 100644 --- a/Makefile +++ b/Makefile @@ -14,6 +14,9 @@ TARGET = $(OBJDIR)/stmbl # Define all C source files (dependencies are generated automatically) INCDIRS += inc +INCDIRS += inc/comps +INCDIRS += inc/comps/hw +INCDIRS += inc/shared_comps INCDIRS += shared SOURCES += src/main.c @@ -28,96 +31,97 @@ SOURCES += src/hal_tbl.c HWVERSION = v4 ifeq ($(HWVERSION),v3) - COMPS += src/comps/hw/io3.c - COMPS += src/comps/hvf1.c - COMPS += shared/comps/pmsm.c - COMPS += shared/comps/curpid.c - COMPS += shared/comps/dq.c - COMPS += shared/comps/idq.c - SOURCES += shared/common_f1.c + SRC_COMPS += src/comps/hw/io3.c + SRC_COMPS += src/comps/hvf1.c + SHARED_COMPS += shared/comps/pmsm.c + SHARED_COMPS += shared/comps/curpid.c + SHARED_COMPS += shared/comps/dq.c + SHARED_COMPS += shared/comps/idq.c + SHARED_COMPS += shared/common_f1.c CFLAGS += -DV3 else - COMPS += src/comps/hw/io4.c - COMPS += src/comps/hv.c + SRC_COMPS += src/comps/hw/io4.c + SRC_COMPS += src/comps/hv.c #TODO: need backport to v3 - COMPS += src/comps/enc_cmd.c - COMPS += src/comps/o_fb.c - COMPS += src/comps/sserial.c - COMPS += src/comps/yaskawa.c - COMPS += src/comps/encs.c - COMPS += src/comps/encf.c - COMPS += src/comps/endat.c + SRC_COMPS += src/comps/enc_cmd.c + SRC_COMPS += src/comps/o_fb.c + SRC_COMPS += src/comps/sserial.c + SRC_COMPS += src/comps/yaskawa.c + SRC_COMPS += src/comps/encs.c + SRC_COMPS += src/comps/encf.c + SRC_COMPS += src/comps/endat.c CFLAGS += -DV4 endif -COMPS += src/comps/usart.c -COMPS += src/comps/encm.c -COMPS += src/comps/dmm.c -COMPS += src/comps/smartabs.c -COMPS += src/comps/adc.c -COMPS += src/comps/enc_fb.c -COMPS += src/comps/conf.c -COMPS += src/comps/res.c -COMPS += src/comps/hx711.c +SRC_COMPS += src/comps/usart.c +SRC_COMPS += src/comps/encm.c +SRC_COMPS += src/comps/dmm.c +SRC_COMPS += src/comps/smartabs.c +SRC_COMPS += src/comps/adc.c +SRC_COMPS += src/comps/enc_fb.c +SRC_COMPS += src/comps/conf.c +SRC_COMPS += src/comps/res.c +SRC_COMPS += src/comps/hx711.c -COMPS += shared/comps/sim.c -COMPS += shared/comps/term.c -COMPS += shared/comps/svm.c +SHARED_COMPS += shared/comps/sim.c +SHARED_COMPS += shared/comps/term.c +SHARED_COMPS += shared/comps/svm.c -COMPS += shared/comps/vel.c -COMPS += shared/comps/rev.c -COMPS += shared/comps/hal_test.c -# COMPS += shared/comps/dc.c -COMPS += shared/comps/ypid.c -COMPS += shared/comps/fault.c -COMPS += shared/comps/pid.c -COMPS += shared/comps/spid.c -COMPS += shared/comps/pe.c -COMPS += shared/comps/pmsm_limits.c -COMPS += shared/comps/pmsm_ttc.c -COMPS += shared/comps/dc_limits.c -COMPS += shared/comps/dc_ttc.c -COMPS += shared/comps/acim_ttc.c -COMPS += shared/comps/uvw.c -COMPS += shared/comps/fanuc.c -COMPS += shared/comps/fb_switch.c -COMPS += shared/comps/reslimit.c -COMPS += shared/comps/iit.c -COMPS += shared/comps/vel_int.c -COMPS += shared/comps/linrev.c -COMPS += shared/comps/psi.c -COMPS += shared/comps/stp.c -#COMPS += shared/comps/uf.c -COMPS += shared/comps/uf2.c -COMPS += shared/comps/ramp.c -COMPS += shared/comps/scale.c -COMPS += shared/comps/idx_home.c -COMPS += shared/comps/move.c -# COMPS += shared/comps/ac.c -COMPS += shared/comps/not.c -COMPS += shared/comps/and.c -COMPS += shared/comps/or.c -COMPS += shared/comps/jog.c -COMPS += shared/comps/velbuf.c -COMPS += shared/comps/avg.c -COMPS += shared/comps/mux.c -COMPS += shared/comps/veltopos.c -# COMPS += shared/comps/wobl.c -COMPS += shared/comps/debounce.c -COMPS += shared/comps/pos_filter.c -COMPS += shared/comps/rl.c -COMPS += shared/comps/mad.c -COMPS += shared/comps/sensorless.c -COMPS += shared/comps/field.c -COMPS += shared/comps/gain.c -COMPS += shared/comps/rlpsij.c -COMPS += shared/comps/veltime.c -COMPS += shared/comps/mpid.c -COMPS += shared/comps/fmove.c -COMPS += shared/comps/home.c -COMPS += shared/comps/en.c -COMPS += shared/comps/th.c +SHARED_COMPS += shared/comps/vel.c +SHARED_COMPS += shared/comps/rev.c +SHARED_COMPS += shared/comps/hal_test.c +# SHARED_COMPS += shared/comps/dc.c +SHARED_COMPS += shared/comps/ypid.c +SHARED_COMPS += shared/comps/fault.c +SHARED_COMPS += shared/comps/pid.c +SHARED_COMPS += shared/comps/spid.c +SHARED_COMPS += shared/comps/pe.c +SHARED_COMPS += shared/comps/pmsm_limits.c +SHARED_COMPS += shared/comps/pmsm_ttc.c +SHARED_COMPS += shared/comps/dc_limits.c +SHARED_COMPS += shared/comps/dc_ttc.c +SHARED_COMPS += shared/comps/acim_ttc.c +SHARED_COMPS += shared/comps/uvw.c +SHARED_COMPS += shared/comps/fanuc.c +SHARED_COMPS += shared/comps/fb_switch.c +SHARED_COMPS += shared/comps/reslimit.c +SHARED_COMPS += shared/comps/iit.c +SHARED_COMPS += shared/comps/vel_int.c +SHARED_COMPS += shared/comps/linrev.c +SHARED_COMPS += shared/comps/psi.c +SHARED_COMPS += shared/comps/stp.c +#SHARED_COMPS += shared/comps/uf.c +SHARED_COMPS += shared/comps/uf2.c +SHARED_COMPS += shared/comps/ramp.c +SHARED_COMPS += shared/comps/scale.c +SHARED_COMPS += shared/comps/idx_home.c +SHARED_COMPS += shared/comps/move.c +# SHARED_COMPS += shared/comps/ac.c +SHARED_COMPS += shared/comps/not.c +SHARED_COMPS += shared/comps/and.c +SHARED_COMPS += shared/comps/or.c +SHARED_COMPS += shared/comps/jog.c +SHARED_COMPS += shared/comps/velbuf.c +SHARED_COMPS += shared/comps/avg.c +SHARED_COMPS += shared/comps/mux.c +SHARED_COMPS += shared/comps/veltopos.c +# SHARED_COMPS += shared/comps/wobl.c +SHARED_COMPS += shared/comps/debounce.c +SHARED_COMPS += shared/comps/pos_filter.c +SHARED_COMPS += shared/comps/rl.c +SHARED_COMPS += shared/comps/mad.c +SHARED_COMPS += shared/comps/sensorless.c +SHARED_COMPS += shared/comps/field.c +SHARED_COMPS += shared/comps/gain.c +SHARED_COMPS += shared/comps/rlpsij.c +SHARED_COMPS += shared/comps/veltime.c +SHARED_COMPS += shared/comps/mpid.c +SHARED_COMPS += shared/comps/fmove.c +SHARED_COMPS += shared/comps/home.c +SHARED_COMPS += shared/comps/en.c +SHARED_COMPS += shared/comps/th.c +COMPS = $(SRC_COMPS) $(SHARED_COMPS) SOURCES += $(COMPS) # SOURCES += src/eeprom.c @@ -136,6 +140,8 @@ SOURCES += src/conf_templates.c SOURCES += shared/ringbuf.c +CONFIG_TEMPLATES = $(wildcard conf/template/*.txt) + USB_VCP_DIR = lib/STM32_USB_Device_VCP-1.2.0 CPPFLAGS += -DUSBD_PRODUCT_STRING='"STMBL Virtual ComPort"' @@ -191,6 +197,8 @@ CPPFLAGS += -DHSE_VALUE=8000000 LDSCRIPT = stm32_flash.ld #============================================================================ +SRC_COMP_OBJECTS = $(addprefix $(OBJDIR)/,$(addsuffix .o,$(basename $(SRC_COMPS)))) +SHARED_COMP_OBJECTS = $(addprefix $(OBJDIR)/,$(addsuffix .o,$(basename $(SHARED_COMPS)))) OBJECTS += $(addprefix $(OBJDIR)/,$(addsuffix .o,$(basename $(SOURCES)))) OBJECTS += hv_firmware.o CPPFLAGS += $(addprefix -I,$(INCDIRS)) @@ -286,33 +294,56 @@ bin: tbl $(TARGET).bin lss: $(TARGET).lss sym: $(TARGET).sym -inc/commandslist.h: tbl -inc/hal_tbl.h: tbl -src/hal_tbl.c: tbl -src/conf_templates.c: tbl +$(OBJDIR)/shared/commands.o: inc/commandslist.h -#generate hal and command tables -tbl: - @echo Generating tables - @$(PYTHON) tools/create_hal_tbl.py . $(COMPS) - @$(PYTHON) tools/create_config.py conf/template/* > src/conf_templates.c - @$(PYTHON) tools/create_cmd.py $(SOURCES) > inc/commandslist.h +inc/commandslist.h: tools/create_cmd.py $(SOURCES) + @echo Generating commands list + @$(MKDIR) -p $(dir $@) + @$(PYTHON) tools/create_cmd.py $@ $(SOURCES) -#build f4 bootloader -boot: +src/hal_tbl.c: tools/create_hal_tbl.py $(COMPS) + @echo Generating HAL table + @$(MKDIR) -p $(dir $@) + @$(PYTHON) tools/create_hal_tbl.py $@ $(COMPS) + +$(SRC_COMP_OBJECTS): $(OBJDIR)/src/comps/%.o: inc/comps/%_comp.h + +$(SHARED_COMP_OBJECTS): $(OBJDIR)/shared/comps/%.o: inc/shared_comps/%_comp.h + +inc/comps/%_comp.h: src/comps/%.c + @echo Generating H: $< + @$(MKDIR) -p $(dir $@) + @$(PYTHON) tools/create_comp_h.py $@ $< + +inc/shared_comps/%_comp.h: shared/comps/%.c + @echo Generating H: $< + @$(MKDIR) -p $(dir $@) + @$(PYTHON) tools/create_comp_h.py $@ $< + +src/conf_templates.c: tools/create_config.py $(CONFIG_TEMPLATES) + @echo Generating config + @$(MKDIR) -p $(dir $@) + @$(PYTHON) tools/create_config.py src/conf_templates.c $(CONFIG_TEMPLATES) + +tbl: inc/commandslist.h src/hal_tbl.c src/conf_templates.c + +obj_boot/blboot.bin: force_look $(MAKE) -f bootloader/Makefile +#build f4 bootloader +boot: obj_boot/blboot.bin + #flash f4 bootloader using stlink -boot_flash: boot +boot_flash: $(MAKE) -f bootloader/Makefile flash #flash f4 bootloader using df-util -boot_btburn: boot +boot_btburn: $(MAKE) -f bootloader/Makefile btburn #build f3 bootloader -f3_boot: +f3_boot: force_look $(MAKE) -f f3_boot/Makefile #flash f3 bootloader using stlink @@ -325,7 +356,7 @@ f3_boot_btburn: #build f3 firmware -f3: +f3: force_look $(MAKE) -f stm32f303/Makefile #flash f3 firmware using stlink @@ -338,39 +369,50 @@ f3_btburn: #generate f3 firmware object from f3 bin -hv_firmware.o: +hv_firmware.o: force_look $(MAKE) -f stm32f303/Makefile all #build f103 firmware for V3 hardware -f1: +f1: force_look $(MAKE) -f stm32f103/Makefile #flash f103 firmware for V3 hardware using stlink f1_flash: boot $(MAKE) -f stm32f103/Makefile flash -f3_all_btburn: +f3_all_btburn: f3.bin @$(DFU-UTIL) -d 0483:df11 -a 0 -s 0x08000000:leave -D f3.bin -all_btburn: +all_btburn: tools/bootloader.py f4.bin @$(PYTHON) tools/bootloader.py @sleep 1 @$(DFU-UTIL) -d 0483:df11 -a 0 -s 0x08000000:leave -D f4.bin -all_flash: +all_flash: f4.bin @$(ST-FLASH) --reset write f4.bin 0x08000000 -f3_all_flash: +f3_all_flash: f3.bin @$(ST-FLASH) --reset write f3.bin 0x08000000 deploy: f3_boot f3 boot build binall -binall: +f4.bin: obj_boot/blboot.bin conf/festo.txt $(TARGET).bin cat obj_boot/blboot.bin /dev/zero | head -c 32768 > f4.bin cat conf/festo.txt /dev/zero | head -c 32768 >> f4.bin - cat obj_app/stmbl.bin >> f4.bin + cat $(TARGET).bin >> f4.bin + +f3.bin: obj_f3_boot/f3_boot.bin obj_hvf3/hvf3.bin cat obj_f3_boot/f3_boot.bin /dev/zero | head -c 16384 > f3.bin cat obj_hvf3/hvf3.bin >> f3.bin + +# TODO: consolidate these two rules into a wildcard version? +f4.dfu: tools/dfu-convert.py f4.bin $(PYTHON) tools/dfu-convert.py -b 0x08000000:f4.bin f4.dfu + +f3.dfu: tools/dfu-convert.py f3.bin $(PYTHON) tools/dfu-convert.py -b 0x08000000:f3.bin f3.dfu - $(PYTHON) tools/dfu-convert.py -b 0x08010000:obj_app/stmbl.bin stmbl.dfu + +stmbl.dfu: tools/dfu-convert.py $(TARGET).bin + $(PYTHON) tools/dfu-convert.py -b 0x08010000:$(TARGET).bin stmbl.dfu + +binall: f4.dfu f3.dfu stmbl.dfu format: find src/ f3_boot/ bootloader/ stm32f103/ stm32f303/ shared/ inc/ tools/ -iname '*.h' -o -iname '*.c' | xargs clang-format -i @@ -380,10 +422,13 @@ format: clean: @echo Cleaning project: rm -rf hv_firmware.o - rm -rf f3.bin f4.bin f3.dfu f4.dfu stmbl.dfu + rm -rf f3.bin f4.bin f3.dfu f4.dfu stmbl.dfu rm -rf $(OBJDIR) rm -rf inc/commandslist.h + rm -rf inc/comps/* + rm -rf inc/shared_comps/* rm -rf src/conf_templates.c + rm -rf src/hal_tbl.c @$(MAKE) -f bootloader/Makefile clean @$(MAKE) -f f3_boot/Makefile clean @$(MAKE) -f stm32f103/Makefile clean @@ -397,9 +442,18 @@ include base.mak # -include $(OBJECTS:.o=.d) +force_look: + @true + # Listing of phony targets # -.PHONY: all build flash clean \ - boot boot_clean boot_flash btburn boot_btflash boot_flash\ - elf lss sym \ - showsize gccversion tbl f3_boot binall deploy format f3_all_btburn all_btburn f3_all_flash all_flash +.PHONY: all build clean \ + elf hex bin lss sym tbl \ + boot boot_flash boot_brburn \ + f3_boot f3_boot_flash f3_boot_btburn \ + f3 f3_flash f3_btburn \ + f1 f1_flash \ + f3_all_btburn all_btburn all_flash f3_all_flash \ + deploy \ + format \ + force_look diff --git a/base.mak b/base.mak index eac25290..8a6b694f 100644 --- a/base.mak +++ b/base.mak @@ -74,7 +74,7 @@ showsize: build # Flash the device # -btburn: build showsize $(TARGET).dfu +btburn: tools/bootloader.py build showsize $(TARGET).dfu @$(PYTHON) tools/bootloader.py @sleep 1 @$(DFU-UTIL) -d 0483:df11 -a 0 -s $(ADDRESS):leave -D $(TARGET).dfu @@ -89,3 +89,5 @@ flash: $(TARGET).bin include toolchain.mak -include toolchain-user.mak + +.PHONY: gccversion showsize btburn flash diff --git a/bootloader/Makefile b/bootloader/Makefile index e22c3959..69385fe5 100644 --- a/bootloader/Makefile +++ b/bootloader/Makefile @@ -155,7 +155,5 @@ include base.mak # Listing of phony targets # -.PHONY: all build flash btfash clean \ - boot boot_clean boot_flash \ - elf lss sym \ - showsize gccversion +.PHONY: all build clean \ + elf hex bin lss sym diff --git a/f3_boot/Makefile b/f3_boot/Makefile index 7244bf17..f7905e4d 100644 --- a/f3_boot/Makefile +++ b/f3_boot/Makefile @@ -175,7 +175,5 @@ include base.mak # Listing of phony targets # -.PHONY: all build flash clean \ - boot boot_clean boot_flash btburn boot_btflash boot_flash\ - elf lss sym \ - showsize gccversion +.PHONY: all build clean \ + elf hex bin lss sym diff --git a/shared/comps/ac.c b/shared/comps/ac.c index c0907036..17e17ceb 100644 --- a/shared/comps/ac.c +++ b/shared/comps/ac.c @@ -1,3 +1,4 @@ +#include "comps/ac_comp.h" #include "hal.h" HAL_COMP(ac); diff --git a/shared/comps/acim_ttc.c b/shared/comps/acim_ttc.c index 13fef23e..ba7d9501 100644 --- a/shared/comps/acim_ttc.c +++ b/shared/comps/acim_ttc.c @@ -1,3 +1,4 @@ +#include "acim_ttc_comp.h" #include "commands.h" #include "hal.h" #include "math.h" diff --git a/shared/comps/and.c b/shared/comps/and.c index 39553570..5da0a7fa 100644 --- a/shared/comps/and.c +++ b/shared/comps/and.c @@ -1,3 +1,4 @@ +#include "and_comp.h" #include "hal.h" HAL_COMP(and); diff --git a/shared/comps/auto_ac.c b/shared/comps/auto_ac.c index 19816c53..7025cbf7 100644 --- a/shared/comps/auto_ac.c +++ b/shared/comps/auto_ac.c @@ -1,3 +1,4 @@ +#include "comps/auto_ac_comp.h" #include "hal.h" #include "defines.h" diff --git a/shared/comps/avg.c b/shared/comps/avg.c index 1470ea28..d28245c5 100644 --- a/shared/comps/avg.c +++ b/shared/comps/avg.c @@ -1,3 +1,4 @@ +#include "avg_comp.h" #include "hal.h" #include "defines.h" diff --git a/shared/comps/curpid.c b/shared/comps/curpid.c index c0f1bbce..9b117764 100644 --- a/shared/comps/curpid.c +++ b/shared/comps/curpid.c @@ -1,3 +1,4 @@ +#include "curpid_comp.h" #include "commands.h" #include "common.h" #include "hal.h" diff --git a/shared/comps/dc.c b/shared/comps/dc.c index 4d23ab5a..0b0c7c65 100644 --- a/shared/comps/dc.c +++ b/shared/comps/dc.c @@ -1,3 +1,4 @@ +#include "comps/dc_comp.h" #include "commands.h" #include "hal.h" #include "math.h" diff --git a/shared/comps/dc_limits.c b/shared/comps/dc_limits.c index 6f3ab01a..77c7cad6 100644 --- a/shared/comps/dc_limits.c +++ b/shared/comps/dc_limits.c @@ -1,3 +1,4 @@ +#include "dc_limits_comp.h" #include "commands.h" #include "hal.h" #include "math.h" diff --git a/shared/comps/dc_ttc.c b/shared/comps/dc_ttc.c index 64872f93..7d0e26db 100644 --- a/shared/comps/dc_ttc.c +++ b/shared/comps/dc_ttc.c @@ -1,3 +1,4 @@ +#include "dc_ttc_comp.h" #include "commands.h" #include "hal.h" #include "math.h" diff --git a/shared/comps/debounce.c b/shared/comps/debounce.c index 6aeef727..e3d2c609 100644 --- a/shared/comps/debounce.c +++ b/shared/comps/debounce.c @@ -1,3 +1,4 @@ +#include "debounce_comp.h" #include "commands.h" #include "hal.h" #include "math.h" diff --git a/shared/comps/dq.c b/shared/comps/dq.c index 48acdcc3..43f80a72 100644 --- a/shared/comps/dq.c +++ b/shared/comps/dq.c @@ -1,3 +1,4 @@ +#include "dq_comp.h" #include "commands.h" #include "common.h" #include "hal.h" diff --git a/shared/comps/en.c b/shared/comps/en.c index a04fa921..c1a4afe0 100644 --- a/shared/comps/en.c +++ b/shared/comps/en.c @@ -1,3 +1,4 @@ +#include "en_comp.h" #include "commands.h" #include "hal.h" #include "math.h" diff --git a/shared/comps/fanuc.c b/shared/comps/fanuc.c index 0cd9663f..a9d782d8 100644 --- a/shared/comps/fanuc.c +++ b/shared/comps/fanuc.c @@ -1,3 +1,4 @@ +#include "fanuc_comp.h" #include "commands.h" #include "hal.h" #include "math.h" diff --git a/shared/comps/fault.c b/shared/comps/fault.c index 61ff5895..999a88cd 100644 --- a/shared/comps/fault.c +++ b/shared/comps/fault.c @@ -1,3 +1,4 @@ +#include "fault_comp.h" #include "commands.h" #include "hal.h" #include "math.h" diff --git a/shared/comps/fb_switch.c b/shared/comps/fb_switch.c index 17ff817b..6c71879d 100644 --- a/shared/comps/fb_switch.c +++ b/shared/comps/fb_switch.c @@ -1,3 +1,4 @@ +#include "fb_switch_comp.h" #include "commands.h" #include "hal.h" #include "math.h" diff --git a/shared/comps/field.c b/shared/comps/field.c index 028ba726..07eb0f79 100644 --- a/shared/comps/field.c +++ b/shared/comps/field.c @@ -1,3 +1,4 @@ +#include "field_comp.h" /* * This file is part of the stmbl project. * diff --git a/shared/comps/fmove.c b/shared/comps/fmove.c index 6dc38622..87d10c1d 100644 --- a/shared/comps/fmove.c +++ b/shared/comps/fmove.c @@ -1,3 +1,4 @@ +#include "fmove_comp.h" #include "commands.h" #include "hal.h" #include "math.h" diff --git a/shared/comps/gain.c b/shared/comps/gain.c index 7acb8bbb..57b3ba99 100644 --- a/shared/comps/gain.c +++ b/shared/comps/gain.c @@ -1,3 +1,4 @@ +#include "gain_comp.h" #include "commands.h" #include "hal.h" #include "math.h" diff --git a/shared/comps/hal_test.c b/shared/comps/hal_test.c index 41b29a89..20f93135 100644 --- a/shared/comps/hal_test.c +++ b/shared/comps/hal_test.c @@ -1,3 +1,4 @@ +#include "hal_test_comp.h" #include "hal.h" HAL_COMP(hal_test); diff --git a/shared/comps/home.c b/shared/comps/home.c index 9b86d8d2..85d8c778 100644 --- a/shared/comps/home.c +++ b/shared/comps/home.c @@ -1,3 +1,4 @@ +#include "home_comp.h" #include "commands.h" #include "hal.h" #include "math.h" diff --git a/shared/comps/idq.c b/shared/comps/idq.c index e68f3c9c..29e29807 100644 --- a/shared/comps/idq.c +++ b/shared/comps/idq.c @@ -1,3 +1,4 @@ +#include "idq_comp.h" #include "commands.h" #include "common.h" #include "hal.h" diff --git a/shared/comps/idx_home.c b/shared/comps/idx_home.c index b8aaddb2..4be9e00d 100644 --- a/shared/comps/idx_home.c +++ b/shared/comps/idx_home.c @@ -1,3 +1,4 @@ +#include "idx_home_comp.h" #include "commands.h" #include "hal.h" #include "math.h" diff --git a/shared/comps/iit.c b/shared/comps/iit.c index 1a870b77..bb4a56eb 100644 --- a/shared/comps/iit.c +++ b/shared/comps/iit.c @@ -1,3 +1,4 @@ +#include "iit_comp.h" #include "commands.h" #include "hal.h" #include "math.h" diff --git a/shared/comps/iit_old.c b/shared/comps/iit_old.c index 7f013c6f..4af6f0a4 100644 --- a/shared/comps/iit_old.c +++ b/shared/comps/iit_old.c @@ -1,3 +1,4 @@ +#include "comps/iit_old_comp.h" #include "commands.h" #include "hal.h" #include "math.h" diff --git a/shared/comps/jog.c b/shared/comps/jog.c index 9ffa7359..01207ca1 100644 --- a/shared/comps/jog.c +++ b/shared/comps/jog.c @@ -1,3 +1,4 @@ +#include "jog_comp.h" #include "commands.h" #include "hal.h" #include "defines.h" diff --git a/shared/comps/linrev.c b/shared/comps/linrev.c index cb2b1490..07c36d68 100644 --- a/shared/comps/linrev.c +++ b/shared/comps/linrev.c @@ -1,3 +1,4 @@ +#include "linrev_comp.h" //Calculate motor angle from position in machine units /* diff --git a/shared/comps/mad.c b/shared/comps/mad.c index 0f772ab1..803e294b 100644 --- a/shared/comps/mad.c +++ b/shared/comps/mad.c @@ -1,3 +1,4 @@ +#include "mad_comp.h" #include "hal.h" HAL_COMP(mad); diff --git a/shared/comps/move.c b/shared/comps/move.c index ee445c29..1aea73c0 100644 --- a/shared/comps/move.c +++ b/shared/comps/move.c @@ -1,3 +1,4 @@ +#include "move_comp.h" #include "commands.h" #include "hal.h" #include "math.h" diff --git a/shared/comps/mpid.c b/shared/comps/mpid.c index d59e4e9b..435d5cd9 100644 --- a/shared/comps/mpid.c +++ b/shared/comps/mpid.c @@ -1,3 +1,4 @@ +#include "mpid_comp.h" #include "commands.h" #include "hal.h" #include "math.h" diff --git a/shared/comps/mux.c b/shared/comps/mux.c index 51f9069d..68e2dfae 100644 --- a/shared/comps/mux.c +++ b/shared/comps/mux.c @@ -1,3 +1,4 @@ +#include "mux_comp.h" #include "hal.h" #include "defines.h" diff --git a/shared/comps/not.c b/shared/comps/not.c index d5bd5375..e566eb93 100644 --- a/shared/comps/not.c +++ b/shared/comps/not.c @@ -1,3 +1,4 @@ +#include "not_comp.h" #include "hal.h" HAL_COMP(not); diff --git a/shared/comps/or.c b/shared/comps/or.c index 56f55c74..e3a2a3d5 100644 --- a/shared/comps/or.c +++ b/shared/comps/or.c @@ -1,3 +1,4 @@ +#include "or_comp.h" #include "hal.h" HAL_COMP(or); diff --git a/shared/comps/pe.c b/shared/comps/pe.c index 11ebe976..b90610c5 100644 --- a/shared/comps/pe.c +++ b/shared/comps/pe.c @@ -1,3 +1,4 @@ +#include "pe_comp.h" #include "commands.h" #include "hal.h" #include "math.h" diff --git a/shared/comps/pid.c b/shared/comps/pid.c index f3c45c4b..ba9e53bc 100644 --- a/shared/comps/pid.c +++ b/shared/comps/pid.c @@ -1,3 +1,4 @@ +#include "pid_comp.h" /* * This file is part of the stmbl project. * diff --git a/shared/comps/pmsm.c b/shared/comps/pmsm.c index 8cd89cf8..59079c17 100644 --- a/shared/comps/pmsm.c +++ b/shared/comps/pmsm.c @@ -1,3 +1,4 @@ +#include "comps/pmsm_comp.h" /* * This file is part of the stmbl project. * diff --git a/shared/comps/pmsm_limits.c b/shared/comps/pmsm_limits.c index 1c2c3dd5..81c3191b 100644 --- a/shared/comps/pmsm_limits.c +++ b/shared/comps/pmsm_limits.c @@ -1,3 +1,4 @@ +#include "pmsm_limits_comp.h" #include "commands.h" #include "hal.h" #include "math.h" diff --git a/shared/comps/pmsm_ttc.c b/shared/comps/pmsm_ttc.c index 80ac7f98..56765f53 100644 --- a/shared/comps/pmsm_ttc.c +++ b/shared/comps/pmsm_ttc.c @@ -1,3 +1,4 @@ +#include "pmsm_ttc_comp.h" #include "commands.h" #include "hal.h" #include "math.h" diff --git a/shared/comps/pos_filter.c b/shared/comps/pos_filter.c index 98c4aaea..978a55d0 100644 --- a/shared/comps/pos_filter.c +++ b/shared/comps/pos_filter.c @@ -1,3 +1,4 @@ +#include "pos_filter_comp.h" #include "hal.h" #include "angle.h" #include "defines.h" diff --git a/shared/comps/psi.c b/shared/comps/psi.c index 970cf927..af980da3 100644 --- a/shared/comps/psi.c +++ b/shared/comps/psi.c @@ -1,3 +1,4 @@ +#include "psi_comp.h" #include "hal.h" #include "math.h" #include "defines.h" diff --git a/shared/comps/ramp.c b/shared/comps/ramp.c index cc058a51..57d4fcd1 100644 --- a/shared/comps/ramp.c +++ b/shared/comps/ramp.c @@ -1,3 +1,4 @@ +#include "ramp_comp.h" #include "commands.h" #include "hal.h" #include "defines.h" diff --git a/shared/comps/reslimit.c b/shared/comps/reslimit.c index 3daf4822..750d1714 100644 --- a/shared/comps/reslimit.c +++ b/shared/comps/reslimit.c @@ -1,3 +1,4 @@ +#include "reslimit_comp.h" #include "commands.h" #include "hal.h" #include "math.h" diff --git a/shared/comps/rev.c b/shared/comps/rev.c index 8ffd18fe..bec0ba62 100644 --- a/shared/comps/rev.c +++ b/shared/comps/rev.c @@ -1,3 +1,4 @@ +#include "rev_comp.h" #include "commands.h" #include "hal.h" #include "math.h" diff --git a/shared/comps/rl.c b/shared/comps/rl.c index 4280c28b..c9fbf958 100644 --- a/shared/comps/rl.c +++ b/shared/comps/rl.c @@ -1,3 +1,4 @@ +#include "rl_comp.h" #include "hal.h" #include "angle.h" #include "defines.h" diff --git a/shared/comps/rlpsij.c b/shared/comps/rlpsij.c index 1e1928fc..8514f1d7 100644 --- a/shared/comps/rlpsij.c +++ b/shared/comps/rlpsij.c @@ -1,3 +1,4 @@ +#include "rlpsij_comp.h" #include "commands.h" #include "hal.h" #include "math.h" diff --git a/shared/comps/scale.c b/shared/comps/scale.c index 72d63c2e..7894ef9a 100644 --- a/shared/comps/scale.c +++ b/shared/comps/scale.c @@ -1,3 +1,4 @@ +#include "scale_comp.h" #include "commands.h" #include "hal.h" #include "math.h" diff --git a/shared/comps/sensorless.c b/shared/comps/sensorless.c index 31e26199..e4596e34 100644 --- a/shared/comps/sensorless.c +++ b/shared/comps/sensorless.c @@ -1,3 +1,4 @@ +#include "sensorless_comp.h" /* * This file is part of the stmbl project. * diff --git a/shared/comps/sim.c b/shared/comps/sim.c index 11a5d4f7..fb77ac46 100644 --- a/shared/comps/sim.c +++ b/shared/comps/sim.c @@ -1,3 +1,4 @@ +#include "sim_comp.h" #include "commands.h" #include "hal.h" #include "math.h" diff --git a/shared/comps/spid.c b/shared/comps/spid.c index 6fe5ebef..b71d077e 100644 --- a/shared/comps/spid.c +++ b/shared/comps/spid.c @@ -1,3 +1,4 @@ +#include "spid_comp.h" #include "commands.h" #include "hal.h" #include "math.h" diff --git a/shared/comps/stp.c b/shared/comps/stp.c index 0b7e03be..758f9b7c 100644 --- a/shared/comps/stp.c +++ b/shared/comps/stp.c @@ -1,3 +1,4 @@ +#include "stp_comp.h" #include "hal.h" #include "math.h" #include "defines.h" diff --git a/shared/comps/svm.c b/shared/comps/svm.c index bb880f05..090a3730 100644 --- a/shared/comps/svm.c +++ b/shared/comps/svm.c @@ -1,3 +1,4 @@ +#include "svm_comp.h" #include "commands.h" #include "hal.h" #include "math.h" diff --git a/shared/comps/term.c b/shared/comps/term.c index 2794cff7..d8ed91aa 100644 --- a/shared/comps/term.c +++ b/shared/comps/term.c @@ -1,3 +1,4 @@ +#include "term_comp.h" #include "commands.h" #include "hal.h" #include "defines.h" diff --git a/shared/comps/th.c b/shared/comps/th.c index 22027c10..9e77fe5c 100644 --- a/shared/comps/th.c +++ b/shared/comps/th.c @@ -1,3 +1,4 @@ +#include "th_comp.h" #include "hal.h" HAL_COMP(th); diff --git a/shared/comps/uf.c b/shared/comps/uf.c index fb92eb0e..36cf36b1 100644 --- a/shared/comps/uf.c +++ b/shared/comps/uf.c @@ -1,3 +1,4 @@ +#include "comps/uf_comp.h" #include "commands.h" #include "hal.h" #include "math.h" diff --git a/shared/comps/uf2.c b/shared/comps/uf2.c index 12805b9c..d3a9e0b1 100644 --- a/shared/comps/uf2.c +++ b/shared/comps/uf2.c @@ -1,3 +1,4 @@ +#include "uf2_comp.h" #include "hal.h" #include "defines.h" #include "angle.h" diff --git a/shared/comps/uvw.c b/shared/comps/uvw.c index 1fd7175f..194a827b 100644 --- a/shared/comps/uvw.c +++ b/shared/comps/uvw.c @@ -1,3 +1,4 @@ +#include "uvw_comp.h" #include "commands.h" #include "hal.h" #include "math.h" diff --git a/shared/comps/vel.c b/shared/comps/vel.c index 63adaf57..293ad7ff 100644 --- a/shared/comps/vel.c +++ b/shared/comps/vel.c @@ -1,3 +1,4 @@ +#include "vel_comp.h" #include "commands.h" #include "hal.h" #include "math.h" diff --git a/shared/comps/vel_int.c b/shared/comps/vel_int.c index b895b49b..6f9d995b 100644 --- a/shared/comps/vel_int.c +++ b/shared/comps/vel_int.c @@ -1,3 +1,4 @@ +#include "vel_int_comp.h" #include "commands.h" #include "hal.h" #include "math.h" diff --git a/shared/comps/velbuf.c b/shared/comps/velbuf.c index a8896fe4..d0770797 100644 --- a/shared/comps/velbuf.c +++ b/shared/comps/velbuf.c @@ -1,3 +1,4 @@ +#include "velbuf_comp.h" #include "commands.h" #include "hal.h" #include "math.h" diff --git a/shared/comps/veltime.c b/shared/comps/veltime.c index e4701867..45ad464f 100644 --- a/shared/comps/veltime.c +++ b/shared/comps/veltime.c @@ -1,3 +1,4 @@ +#include "veltime_comp.h" #include "commands.h" #include "hal.h" #include "math.h" diff --git a/shared/comps/veltopos.c b/shared/comps/veltopos.c index 9b9af853..fc6acb6e 100644 --- a/shared/comps/veltopos.c +++ b/shared/comps/veltopos.c @@ -1,3 +1,4 @@ +#include "veltopos_comp.h" #include "commands.h" #include "hal.h" #include "math.h" diff --git a/shared/comps/wobl.c b/shared/comps/wobl.c index 1a8b7e1c..a37fb38f 100644 --- a/shared/comps/wobl.c +++ b/shared/comps/wobl.c @@ -1,3 +1,4 @@ +#include "comps/wobl_comp.h" #include "commands.h" #include "hal.h" #include "math.h" diff --git a/shared/comps/ypid.c b/shared/comps/ypid.c index 50e048f5..c4a1fc29 100644 --- a/shared/comps/ypid.c +++ b/shared/comps/ypid.c @@ -1,3 +1,4 @@ +#include "ypid_comp.h" /* * This file is part of the stmbl project. * diff --git a/shared/hal.h b/shared/hal.h index 88e684f1..6d40c607 100644 --- a/shared/hal.h +++ b/shared/hal.h @@ -191,4 +191,13 @@ uint32_t hal_parse(char *cmd); void hal_error(uint32_t error_handler); void hal_set_debug_level(uint32_t debug_level); -#include "hal_tbl.h" +//#include "hal_tbl.h" +struct pin_ctx_t{ + hal_pin_inst_t rt_prio; + hal_pin_inst_t frt_prio; +}; + +extern const hal_comp_t * comps[]; +extern const pin_t pins[]; +extern const uint32_t comp_count; +extern const uint32_t pin_count; \ No newline at end of file diff --git a/src/comps/adc.c b/src/comps/adc.c index 6684f46e..9ea36c7a 100644 --- a/src/comps/adc.c +++ b/src/comps/adc.c @@ -1,3 +1,4 @@ +#include "adc_comp.h" #include "commands.h" #include "hal.h" #include "math.h" diff --git a/src/comps/conf.c b/src/comps/conf.c index 0d691a77..548258ca 100644 --- a/src/comps/conf.c +++ b/src/comps/conf.c @@ -1,3 +1,4 @@ +#include "conf_comp.h" #include #include "main.h" // for Wait #include "commands.h" diff --git a/src/comps/dmm.c b/src/comps/dmm.c index bb582dee..3dfea75a 100644 --- a/src/comps/dmm.c +++ b/src/comps/dmm.c @@ -1,3 +1,4 @@ +#include "comps/dmm_comp.h" #include "commands.h" #include "hal.h" #include "math.h" diff --git a/src/comps/enc_cmd.c b/src/comps/enc_cmd.c index 20c81266..97603357 100644 --- a/src/comps/enc_cmd.c +++ b/src/comps/enc_cmd.c @@ -1,3 +1,4 @@ +#include "enc_cmd_comp.h" #include "commands.h" #include "hal.h" #include "math.h" diff --git a/src/comps/enc_fb.c b/src/comps/enc_fb.c index efcd2630..305d0d89 100644 --- a/src/comps/enc_fb.c +++ b/src/comps/enc_fb.c @@ -1,3 +1,4 @@ +#include "enc_fb_comp.h" #include "commands.h" #include "hal.h" #include "math.h" diff --git a/src/comps/encf.c b/src/comps/encf.c index 1adb5a78..e161dab1 100644 --- a/src/comps/encf.c +++ b/src/comps/encf.c @@ -1,3 +1,4 @@ +#include "encf_comp.h" #include "commands.h" #include "hal.h" #include "math.h" diff --git a/src/comps/encm.c b/src/comps/encm.c index a8402150..b6abb3c9 100644 --- a/src/comps/encm.c +++ b/src/comps/encm.c @@ -1,3 +1,4 @@ +#include "encm_comp.h" #include "commands.h" #include "hal.h" #include "math.h" diff --git a/src/comps/encs.c b/src/comps/encs.c index 22e11b2f..c610e752 100644 --- a/src/comps/encs.c +++ b/src/comps/encs.c @@ -1,3 +1,4 @@ +#include "encs_comp.h" #include "commands.h" #include "hal.h" #include "math.h" diff --git a/src/comps/endat.c b/src/comps/endat.c index 2b268d47..a7a0aa55 100644 --- a/src/comps/endat.c +++ b/src/comps/endat.c @@ -1,3 +1,4 @@ +#include "endat_comp.h" #include "commands.h" #include "hal.h" #include "math.h" diff --git a/src/comps/hv.c b/src/comps/hv.c index 76929240..ef19150d 100644 --- a/src/comps/hv.c +++ b/src/comps/hv.c @@ -1,3 +1,4 @@ +#include "hv_comp.h" #include "commands.h" #include "hal.h" #include "math.h" diff --git a/src/comps/hvf1.c b/src/comps/hvf1.c index 8143c687..e1a751f0 100644 --- a/src/comps/hvf1.c +++ b/src/comps/hvf1.c @@ -1,3 +1,4 @@ +#include "comps/hvf1_comp.h" #include "commands.h" #include "hal.h" #include "math.h" diff --git a/src/comps/hw/io3.c b/src/comps/hw/io3.c index 9cc55c7c..7d916bcc 100644 --- a/src/comps/hw/io3.c +++ b/src/comps/hw/io3.c @@ -1,3 +1,4 @@ +#include "comps/io3_comp.h" #include "commands.h" #include "hal.h" #include "defines.h" diff --git a/src/comps/hw/io4.c b/src/comps/hw/io4.c index 2398882a..5f12bd12 100644 --- a/src/comps/hw/io4.c +++ b/src/comps/hw/io4.c @@ -1,3 +1,4 @@ +#include "io4_comp.h" #include "commands.h" #include "hal.h" #include "defines.h" diff --git a/src/comps/hx711.c b/src/comps/hx711.c index 5e61dec9..10f53923 100644 --- a/src/comps/hx711.c +++ b/src/comps/hx711.c @@ -1,3 +1,4 @@ +#include "hx711_comp.h" /* * This file is part of the stmbl project. * diff --git a/src/comps/o_fb.c b/src/comps/o_fb.c index 1744dad9..f52e1a3a 100644 --- a/src/comps/o_fb.c +++ b/src/comps/o_fb.c @@ -1,3 +1,4 @@ +#include "o_fb_comp.h" #include "commands.h" #include "hal.h" #include "math.h" diff --git a/src/comps/res.c b/src/comps/res.c index 94690ce3..fc43f1a4 100644 --- a/src/comps/res.c +++ b/src/comps/res.c @@ -1,3 +1,4 @@ +#include "res_comp.h" #include "commands.h" #include "hal.h" #include "math.h" diff --git a/src/comps/smartabs.c b/src/comps/smartabs.c index 67791bb2..7d263509 100644 --- a/src/comps/smartabs.c +++ b/src/comps/smartabs.c @@ -1,3 +1,4 @@ +#include "smartabs_comp.h" #include "commands.h" #include "hal.h" #include "math.h" diff --git a/src/comps/sserial.c b/src/comps/sserial.c index 803b1c71..2135780b 100644 --- a/src/comps/sserial.c +++ b/src/comps/sserial.c @@ -1,3 +1,4 @@ +#include "sserial_comp.h" /* * This file is part of the stmbl project. * diff --git a/src/comps/usart.c b/src/comps/usart.c index d39d9a7c..4915303b 100644 --- a/src/comps/usart.c +++ b/src/comps/usart.c @@ -1,3 +1,4 @@ +#include "usart_comp.h" #include "commands.h" #include "hal.h" #include "math.h" diff --git a/src/comps/yaskawa.c b/src/comps/yaskawa.c index aa092791..fdd29dd0 100644 --- a/src/comps/yaskawa.c +++ b/src/comps/yaskawa.c @@ -1,3 +1,4 @@ +#include "yaskawa_comp.h" #include "commands.h" #include "hal.h" #include "math.h" diff --git a/stm32f103/Makefile b/stm32f103/Makefile index 71c0690f..7fd49945 100644 --- a/stm32f103/Makefile +++ b/stm32f103/Makefile @@ -155,5 +155,4 @@ include toolchain.mak # Listing of phony targets # .PHONY: all build flash clean \ - elf lss sym \ - showsize gccversion + elf hex bin lss sym diff --git a/stm32f303/Makefile b/stm32f303/Makefile index 9c884abe..9aceb369 100644 --- a/stm32f303/Makefile +++ b/stm32f303/Makefile @@ -14,6 +14,8 @@ TARGET = $(OBJDIR)/hvf3 # Define all C source files (dependencies are generated automatically) INCDIRS += stm32f303/inc +INCDIRS += stm32f303/inc/comps +INCDIRS += stm32f303/inc/shared_comps SOURCES += stm32f303/src/main.c SOURCES += stm32f303/src/adc.c SOURCES += stm32f303/src/dac.c @@ -27,23 +29,24 @@ SOURCES += stm32f303/src/version.c SOURCES += stm32f303/src/hal_tbl.c CFLAGS += -DHAL_MAX_CTX=1024 -COMPS += stm32f303/src/comps/hv.c -COMPS += stm32f303/src/comps/io.c -COMPS += stm32f303/src/comps/ls.c -#COMPS += stm32f303/src/comps/enc.c +SRC_COMPS += stm32f303/src/comps/hv.c +SRC_COMPS += stm32f303/src/comps/io.c +SRC_COMPS += stm32f303/src/comps/ls.c +#SRC_COMPS += stm32f303/src/comps/enc.c -COMPS += shared/comps/sim.c -COMPS += shared/comps/term.c -COMPS += shared/comps/curpid.c -COMPS += shared/comps/svm.c -COMPS += shared/comps/dq.c -COMPS += shared/comps/idq.c -COMPS += shared/comps/sensorless.c -# COMPS += shared/comps/vel.c -# COMPS += shared/comps/hal_test.c -# COMPS += shared/comps/dc.c -# COMPS += shared/comps/ypid.c +SHARED_COMPS += shared/comps/sim.c +SHARED_COMPS += shared/comps/term.c +SHARED_COMPS += shared/comps/curpid.c +SHARED_COMPS += shared/comps/svm.c +SHARED_COMPS += shared/comps/dq.c +SHARED_COMPS += shared/comps/idq.c +SHARED_COMPS += shared/comps/sensorless.c +# SHARED_COMPS += shared/comps/vel.c +# SHARED_COMPS += shared/comps/hal_test.c +# SHARED_COMPS += shared/comps/dc.c +# SHARED_COMPS += shared/comps/ypid.c +COMPS = $(SRC_COMPS) $(SHARED_COMPS) SOURCES += $(COMPS) INCDIRS += shared @@ -85,6 +88,8 @@ SOURCES += $(HAL_DRV_DIR)/Src/stm32f3xx_hal_uart_ex.c LDSCRIPT = stm32f303/STM32F303CBTx_FLASH.ld #============================================================================ +SRC_COMP_OBJECTS = $(addprefix $(OBJDIR)/,$(addsuffix .o,$(basename $(SRC_COMPS)))) +SHARED_COMP_OBJECTS = $(addprefix $(OBJDIR)/,$(addsuffix .o,$(basename $(SHARED_COMPS)))) OBJECTS += $(addprefix $(OBJDIR)/,$(addsuffix .o,$(basename $(SOURCES)))) CPPFLAGS += $(addprefix -I,$(INCDIRS)) @@ -93,7 +98,7 @@ CPPFLAGS += $(addprefix -I,$(INCDIRS)) # -g generate debugging information # -save-temps preserve .s and .i-files # -#CPPFLAGS += +#CPPFLAGS += # CPPFLAGS += -g # CPPFLAGS += -save-temps=obj @@ -181,9 +186,12 @@ ADDRESS = 0x8004000 # all: gccversion build showsize -build: tbl elf hex bin lss sym +hv_firmware.o: obj_hvf3/hvf3.bin $(OBJCOPY) --rename-section .data=.hv_firmware -I binary obj_hvf3/hvf3.bin -B arm -O elf32-littlearm hv_firmware.o +build: tbl elf hex bin lss sym hv_firmware.o + + elf: $(TARGET).elf hex: $(TARGET).hex bin: tbl $(TARGET).bin @@ -193,15 +201,33 @@ sym: $(TARGET).sym # Display compiler version information # -stm32f303/inc/commandslist.h: tbl -stm32f303/inc/hal_tbl.h: tbl -stm32f303/src/hal_tbl.c: tbl +$(OBJDIR)/shared/commands.o: stm32f303/inc/commandslist.h -tbl: - @echo Generating tables - @$(PYTHON) tools/create_hal_tbl.py stm32f303/ $(COMPS) - #shared/comps/*.c src/comps/hw/*.c src/comps/*.c - @$(PYTHON) tools/create_cmd.py $(SOURCES) > stm32f303/inc/commandslist.h +stm32f303/inc/commandslist.h: tools/create_cmd.py $(SOURCES) + @echo Generating commands list + @$(MKDIR) -p $(dir $@) + @$(PYTHON) tools/create_cmd.py $@ $(SOURCES) + +stm32f303/src/hal_tbl.c: tools/create_hal_tbl.py $(COMPS) + @echo Generating HAL table + @$(MKDIR) -p $(dir $@) + @$(PYTHON) tools/create_hal_tbl.py $@ $(COMPS) + +$(SRC_COMP_OBJECTS): $(OBJDIR)/stm32f303/src/comps/%.o: stm32f303/inc/comps/%_comp.h + +$(SHARED_COMP_OBJECTS): $(OBJDIR)/shared/comps/%.o: stm32f303/inc/shared_comps/%_comp.h + +stm32f303/inc/comps/%_comp.h: stm32f303/src/comps/%.c + @echo Generating H: $< + @$(MKDIR) -p $(dir $@) + @$(PYTHON) tools/create_comp_h.py $@ $< + +stm32f303/inc/shared_comps/%_comp.h: shared/comps/%.c + @echo Generating H: $< + @$(MKDIR) -p $(dir $@) + @$(PYTHON) tools/create_comp_h.py $@ $< + +tbl: stm32f303/src/hal_tbl.c stm32f303/inc/commandslist.h # Target: clean project # @@ -209,7 +235,8 @@ clean: @echo Cleaning project: rm -rf $(OBJDIR) rm -rf stm32f303/inc/commandslist.h - rm -rf stm32f303/inc/hal_tbl.h + rm -rf stm32f303/inc/comps/* + rm -rf stm32f303/inc/shared_comps/* rm -rf stm32f303/src/hal_tbl.c rm -rf hv_firmware.o @@ -223,7 +250,5 @@ include base.mak # Listing of phony targets # -.PHONY: all build flash clean \ - boot boot_clean boot_flash btburn boot_btflash boot_flash\ - elf lss sym \ - showsize gccversion tbl +.PHONY: all build clean \ + elf hex bin lss sym tbl diff --git a/stm32f303/src/comps/enc.c b/stm32f303/src/comps/enc.c index 1dbd2b7d..5b9cf534 100644 --- a/stm32f303/src/comps/enc.c +++ b/stm32f303/src/comps/enc.c @@ -1,3 +1,4 @@ +#include "comps/enc_comp.h" #include "commands.h" #include "hal.h" #include "math.h" diff --git a/stm32f303/src/comps/hv.c b/stm32f303/src/comps/hv.c index ca1319c0..b8780c04 100644 --- a/stm32f303/src/comps/hv.c +++ b/stm32f303/src/comps/hv.c @@ -1,3 +1,4 @@ +#include "hv_comp.h" #include "commands.h" #include "hal.h" #include "math.h" diff --git a/stm32f303/src/comps/io.c b/stm32f303/src/comps/io.c index 430d0fb4..3a18e4d7 100644 --- a/stm32f303/src/comps/io.c +++ b/stm32f303/src/comps/io.c @@ -1,3 +1,4 @@ +#include "io_comp.h" #include "commands.h" #include "hal.h" #include "math.h" diff --git a/stm32f303/src/comps/ls.c b/stm32f303/src/comps/ls.c index 2690a501..2720df46 100644 --- a/stm32f303/src/comps/ls.c +++ b/stm32f303/src/comps/ls.c @@ -1,3 +1,4 @@ +#include "ls_comp.h" #include "commands.h" #include "hal.h" #include "math.h" diff --git a/toolchain.mak b/toolchain.mak index a09d6f5c..9a3b1ee3 100644 --- a/toolchain.mak +++ b/toolchain.mak @@ -1,6 +1,6 @@ # Define programs and commands for the toolchain # Do not modiy this file. Instead create a file toolchain-user.mak which can overwrite anything in here. -PYTHON = python +PYTHON = python3 DFU-UTIL = dfu-util DFU-SUFFIX = dfu-suffix ST-FLASH = st-flash diff --git a/tools/create_cmd.py b/tools/create_cmd.py index 561b77f0..b1aa4c1d 100755 --- a/tools/create_cmd.py +++ b/tools/create_cmd.py @@ -4,21 +4,25 @@ import sys cmd = [] -for infile in sys.argv[1:]: +for infile in sys.argv[2:]: with open(infile) as f: for line_number, line in enumerate(f): match = re.search('COMMAND\("(\w*)", *(\w*), *"([^"]*)"\);', line) if match: cmd.append((match.groups(), infile, line_number)) -print ("//generated by " + sys.argv[0] + " DO NOT EDIT") +header = open(sys.argv[1], 'w') + +header.write("//generated by " + sys.argv[0] + " DO NOT EDIT\n") for (name, ptr, doc), file_name, line_number in cmd: - print ("extern void " + ptr + "(char *); // found in " + file_name + " line: " + str(line_number + 1)) + header.write("extern void " + ptr + "(char *); // found in " + file_name + " line: " + str(line_number + 1) + "\n") -print ("\n") +header.write("\n\n") -print ("cmd_t cmd[] = {") +header.write("cmd_t cmd[] = {\n") for (name, ptr, doc), file_name, line_number in cmd: - print (" {\"" + name + "\", \"" + doc + "\", " + ptr + "}, // found in " + file_name + " line: " + str(line_number + 1)) -print ("};") + header.write(" {\"" + name + "\", \"" + doc + "\", " + ptr + "}, // found in " + file_name + " line: " + str(line_number + 1) + "\n") +header.write("};\n") + +header.close() diff --git a/tools/create_comp_h.py b/tools/create_comp_h.py new file mode 100644 index 00000000..920263d5 --- /dev/null +++ b/tools/create_comp_h.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python +import re +import sys + +infile = sys.argv[2] +with open(sys.argv[2]) as f: # TODO raise error if file cannot be opened instead of silently succeeding + pins = [] + comp_name = '' + comp_file = infile.split("/")[-1].split(".")[0] + for line in f: + comp = re.search('COMP\((\w*)\);', line) + if comp: + comp_name = comp.groups()[0] + pin = re.search('HAL_PIN\((\w*)\)', line) + if pin: + pins.append((pin.groups()[0], int(1))) + pin = re.search('HAL_PINA\((\w*),\s*(\d*)\)', line) + if pin: + pins.append((pin.groups()[0], int(pin.groups()[1]))) + + header = open(sys.argv[1], 'w') + header.write("#pragma once\n") + header.write("//generated by " + sys.argv[0] + " DO NOT EDIT\n\n") + header.write("#include \"hal.h\"\n") + header.write("struct " + comp_name + "_pin_ctx_t{ // found in " + infile + "\n") + header.write(" hal_pin_inst_t rt_prio;\n") + header.write(" hal_pin_inst_t frt_prio;\n") + # header.write(" hal_pin_inst_t rt_calc_time;\n") + # header.write(" hal_pin_inst_t rt_start_time;\n") + # header.write(" hal_pin_inst_t frt_calc_time;\n") + # header.write(" hal_pin_inst_t frt_start_time;\n") + # header.write(" hal_pin_inst_t nrt_calc_time;\n") + # header.write(" hal_pin_inst_t nrt_start_time;\n") + + for (p, i) in pins: + if i > 1: + header.write(" hal_pin_inst_t " + p + "[" + str(i) + "]" + ";\n") + else: + header.write(" hal_pin_inst_t " + p + ";\n") + header.write("};\n") + header.close() diff --git a/tools/create_config.py b/tools/create_config.py index 03506fef..108e5349 100755 --- a/tools/create_config.py +++ b/tools/create_config.py @@ -5,21 +5,25 @@ import os config = [] -for infile in sys.argv[1:]: +for infile in sys.argv[2:]: with open(infile) as f: config.append((os.path.splitext(os.path.basename(infile))[0], f.read())) -print ("//generated by " + sys.argv[0] + " DO NOT EDIT\n") -print ("#include \"config.h\"\n") -print ("const uint32_t num_of_config_templates = " + str(len(config)) + ";\n") +code = open(sys.argv[1], 'w') -print ("config_template_t config_templates[] = {") +code.write("//generated by " + sys.argv[0] + " DO NOT EDIT\n\n") +code.write("#include \"config.h\"\n\n") +code.write("const uint32_t num_of_config_templates = " + str(len(config)) + ";\n\n") + +code.write("config_template_t config_templates[] = {\n") for index, (file_name, content) in enumerate(config): - print ("{") - print (".name = \"" + file_name + "\",") - print (".config = \"\\") + code.write("{\n") + code.write(".name = \"" + file_name + "\",\n") + code.write(".config = \"\\\n") for line in content.splitlines(): - print (line + "\\n\\") - print ("\"\n},\n") -print ("};") + code.write(line + "\\n\\\n") + code.write("\"\n},\n\n") +code.write("};\n") + +code.close() diff --git a/tools/create_hal_tbl.py b/tools/create_hal_tbl.py index 2e79aab6..3ee4d53e 100755 --- a/tools/create_hal_tbl.py +++ b/tools/create_hal_tbl.py @@ -4,13 +4,13 @@ import sys comps = [] -header = open(sys.argv[1] + '/inc/hal_tbl.h', 'w') -code = open(sys.argv[1] + '/src/hal_tbl.c', 'w') +code = open(sys.argv[1], 'w') for infile in sys.argv[2:]: with open(infile) as f: pins = [] compname = '' + comp_file = infile.split("/")[-1].split(".")[0] for line in f: comp = re.search('COMP\((\w*)\);', line) if comp: @@ -21,60 +21,21 @@ for infile in sys.argv[2:]: pin = re.search('HAL_PINA\((\w*),\s*(\d*)\)', line) if pin: pins.append((pin.groups()[0], int(pin.groups()[1]))) - comps.append((compname, pins, infile)) + comps.append((compname, pins, infile, comp_file)) -header.write("#pragma once\n") -header.write("//generated by " + sys.argv[0] + " DO NOT EDIT\n\n") - -header.write("struct pin_ctx_t{\n") -header.write(" hal_pin_inst_t rt_prio;\n") -header.write(" hal_pin_inst_t frt_prio;\n") -# header.write(" hal_pin_inst_t rt_calc_time;\n") -# header.write(" hal_pin_inst_t rt_start_time;\n") -# header.write(" hal_pin_inst_t frt_calc_time;\n") -# header.write(" hal_pin_inst_t frt_start_time;\n") -# header.write(" hal_pin_inst_t nrt_calc_time;\n") -# header.write(" hal_pin_inst_t nrt_start_time;\n") - -header.write("};\n\n") - -for comp_name, pins, file_name in comps: - header.write("struct " + comp_name + "_pin_ctx_t{ // found in " + file_name + "\n") - header.write(" hal_pin_inst_t rt_prio;\n") - header.write(" hal_pin_inst_t frt_prio;\n") - # header.write(" hal_pin_inst_t rt_calc_time;\n") - # header.write(" hal_pin_inst_t rt_start_time;\n") - # header.write(" hal_pin_inst_t frt_calc_time;\n") - # header.write(" hal_pin_inst_t frt_start_time;\n") - # header.write(" hal_pin_inst_t nrt_calc_time;\n") - # header.write(" hal_pin_inst_t nrt_start_time;\n") - - for (p, i) in pins: - if i > 1: - header.write(" hal_pin_inst_t " + p + "[" + str(i) + "]" + ";\n") - else: - header.write(" hal_pin_inst_t " + p + ";\n") - header.write("};\n\n") - -header.write("extern const hal_comp_t * comps[];\n") -header.write("extern const pin_t pins[];\n") -header.write("extern const uint32_t comp_count;\n") -header.write("extern const uint32_t pin_count;\n\n") - -for comp_name, pins, file_name in comps: - header.write("extern const hal_comp_t " + comp_name + "_comp_struct; // found in " + file_name + "\n") - - -code.write("#include \"hal.h\"\n") +code.write("#include \"hal.h\"\n\n") code.write("//generated by " + sys.argv[0] + " DO NOT EDIT\n\n") +for comp_name, pins, file_name, comp_file in comps: + code.write("extern const hal_comp_t " + comp_name + "_comp_struct; // found in " + file_name + "\n") +code.write("\n\n") code.write("const hal_comp_t * comps[] = {\n") -for comp_name, pins, file_name in comps: +for comp_name, pins, file_name, comp_file in comps: code.write(" &" + comp_name + "_comp_struct, // found in " + file_name + "\n") code.write("};\n\n") code.write("const uint32_t comp_count = sizeof(comps) / sizeof(comps[0]);\n\n") code.write("const pin_t pins[] = {\n") -for comp_name, pins, file_name in comps: +for comp_name, pins, file_name, comp_file in comps: code.write(" // pins for comp " + comp_name + " found in " + file_name + "\n") code.write(" \"rt_prio\",\n") code.write(" \"frt_prio\",\n") @@ -95,5 +56,5 @@ for comp_name, pins, file_name in comps: code.write("};\n\n") code.write("const uint32_t pin_count = sizeof(pins) / sizeof(pins[0]);\n\n") -header.close() +# header.close() code.close()