Skip to content

Commit

Permalink
init parafocus
Browse files Browse the repository at this point in the history
  • Loading branch information
trentgill committed Jun 27, 2024
1 parent 7027d29 commit 03d9a80
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 123 deletions.
126 changes: 6 additions & 120 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
TARGET=crow
TARGET=parafocus
EXECUTABLE=$(TARGET).elf

GIT_VERSION := $(shell git describe --tags)
Expand All @@ -8,11 +8,8 @@ HALS=$(CUBE)/STM32F7xx_HAL_Driver/Src
USBD=submodules/STM32CubeF7_USB/STM32_USB_Device_Library
WRLIB=submodules/wrLib
WRDSP=submodules/wrDsp
LUAS=submodules/lua/src
BOOTLOADER=submodules/dfu-stm32f7
BUILD_DIR := build
PRJ_DIR=crow
LUAC_CROSS=util/luacc
PRJ_DIR=parafocus

CC=arm-none-eabi-gcc
LD=arm-none-eabi-gcc
Expand All @@ -21,8 +18,6 @@ AS=arm-none-eabi-as
CP=arm-none-eabi-objcopy
OBJDUMP=arm-none-eabi-objdump

FENNEL=fennel

# BIN=$(CP) -O ihex
BIN = $(TARGET).bin

Expand Down Expand Up @@ -52,11 +47,9 @@ CFLAGS += $(MCFLAGS)
CFLAGS += $(OPTIMIZE)
CFLAGS += $(DEFS) -I. -I./ $(STM32_INCLUDES)
CFLAGS += -fsingle-precision-constant -Wdouble-promotion
CFLAGS += -DLUA_32BITS
CFLAGS += -fno-common
CFLAGS += -DVERSION=\"$(GIT_VERSION)\"
CFLAGS += -ffunction-sections -fdata-sections # provides majority of LTO binary size reduction
CFLAGS += -DLUA_COMPAT_MATHLIB

# debugger: choose between uart (=0) & swtrace(=1). latter requires hardware mod
TRACE ?= 0
Expand Down Expand Up @@ -115,82 +108,15 @@ SRC = main.c \
$(WRDSP)/wrFilter.c \


# lua tests
LTESTS = $(wildcard tests/*.lua) \


# recipes!
all: $(TARGET).hex $(BIN)


### pre-process only files

# fennel script conversion to lua
FNL_SRC = $(wildcard lua/*.fnl) \

FNL_PP = $(FNL_SRC:%.fnl=%.lua)

# i2c descriptors
II_SRCD = lua/ii
II_SRC = $(wildcard $(II_SRCD)/*.lua)

$(BUILD_DIR)/ii_c_layer.h: $(II_SRC) util/ii_c_layer.lua | $(BUILD_DIR)
@lua util/ii_c_layer.lua $(II_SRCD) $@
@echo "ii-c-layer $@"

$(BUILD_DIR)/ii_mod_gen.h: $(II_SRC) util/ii_mod_gen.lua | $(BUILD_DIR)
@lua util/ii_mod_gen.lua $(II_SRCD) $@
@echo "ii-mod-gen $@"


### destination sources

# lua srcs: these get converted to bytecode strings wrapped in c-headers
LUA_SRC += lua/asl.lua
LUA_SRC += lua/asllib.lua
LUA_SRC += lua/calibrate.lua
LUA_SRC += lua/clock.lua
LUA_SRC += lua/crowlib.lua
LUA_SRC += lua/First.lua
LUA_SRC += lua/ii.lua
LUA_SRC += lua/input.lua
LUA_SRC += lua/metro.lua
LUA_SRC += lua/output.lua
LUA_SRC += lua/public.lua
LUA_SRC += lua/quote.lua
LUA_SRC += lua/sequins.lua
LUA_SRC += lua/timeline.lua
LUA_SRC += lua/hotswap.lua

LUA_PP = $(LUA_SRC:%.lua=%.lua.h)
LUA_PP: $(LUA_SRC)
@echo "pre-compiling lua sources to bytecode wrapped in c headers"

LUACORE_OBJS= lapi.o lcode.o lctype.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o \
lmem.o lobject.o lopcodes.o lparser.o lstate.o lstring.o ltable.o \
ltm.o lundump.o lvm.o lzio.o
LUALIB_OBJS= lauxlib.o lbaselib.o lbitlib.o lcorolib.o ldblib.o liolib.o \
lmathlib.o loslib.o lstrlib.o ltablib.o lutf8lib.o loadlib.o linit.o


# build the objects from c source
OBJDIR = .
OBJS = $(SRC:%.c=$(OBJDIR)/%.o)
OBJS += $(addprefix $(LUAS)/,$(LUACORE_OBJS) $(LUALIB_OBJS) )
OBJS += Startup.o

$(OBJS): $(LUA_PP)

# specific objects that require built dependencies (ii)
$(OBJDIR)/lib/l_bootstrap.o: $(LUA_PP) #$(BUILD_DIR)/ii_lualink.h
$(OBJDIR)/lib/ii.o: $(BUILD_DIR)/ii_c_layer.h
$(OBJDIR)/lib/l_ii_mod.o: $(BUILD_DIR)/ii_mod_gen.h

# generate the build directory
$(BUILD_DIR):
@echo build_dir $(BUILD_DIR)/
@mkdir -p $(BUILD_DIR)


# C dependencies echoed into Makefile
DEP = $(OBJS:.o=.d) # one dependency file for each source
Expand All @@ -206,12 +132,6 @@ ifeq ($(UNAME), Darwin)
endif


.PHONY: tests
tests:
@for t in $(LTESTS); do \
lua $$t; \
done

# include all DEP files in the makefile
# will rebuild elements if dependent C headers are changed
-include $(DEP)
Expand All @@ -232,18 +152,18 @@ $(BIN): $(EXECUTABLE)
@echo "symbol table: $@.dmp"
@echo "Release: "$(R)
@$(GETSIZE) $(BIN) | grep 'Size'
@echo " ^ must be less than 384kB (384,000)"
@echo " ^ must be less than 512kB"
# 512kb -64kb(bootloader) -128kb(scripts)

flash: $(BIN)
st-flash write $(BIN) 0x08020000
st-flash write $(BIN) 0x08000000

debug:
make flash TRACE=1
stlink-trace -c 216

dfu: $(BIN)
sudo dfu-util -a 0 -s 0x08020000 -R -D $(BIN) -d ,0483:df11
sudo dfu-util -a 0 -s 0x08000000 -R -D $(BIN) -d ,0483:df11

dfureset:
@stty -F /dev/ttyACM0 raw speed 115200
Expand All @@ -254,7 +174,7 @@ pydfu: $(TARGET).dfu $(BIN)
@python3 util/pydfu.py -u $<

$(TARGET).dfu: $(BIN)
python3 util/dfu.py -D 0x0483:0xDF11 -b 0x08020000:$^ $@
python3 util/dfu.py -D 0x0483:0xDF11 -b 0x08000000:$^ $@

boot:
cd $(BOOTLOADER) && \
Expand All @@ -281,50 +201,16 @@ zip: $(BIN) $(TARGET).dfu
%.s: %.c
@$(CC) -ggdb $(CFLAGS) -S $< -o $@

%.lua: %.fnl
@echo f2l $< "->" $@
@$(FENNEL) --compile $< > $@

# a bunch of gnarly make-functions to massage the intermediate stage filenames
# everything goes into /build now, and we have to save output of LUAC_CROSS into
# named files for (xxd -i) to build include files with valid names
# could be avoided by a more complicated pass in (sed), but this was easier
# 1. cross-compile all .lua files into .lc bytecode for stm32-arm-cortex-m7 format
# 2. wrap the .lc binary files into .h headers with auto-generated names
# 3. add const qualifiers to headers to satisfy C99 struct initializer requirement

%.lua.h: %.lua $(BUILD_DIR)
@echo l2h $< "->" $(addprefix $(BUILD_DIR)/, $(notdir $(subst .lua.h,.h,$@)))
@$(LUAC_CROSS) -s -o $(addprefix $(BUILD_DIR)/, $(notdir $(subst .lua,.lc,$<))) $<
@xxd -i $(addprefix $(BUILD_DIR)/, $(notdir $(subst .lua,.lc,$<))) $(addprefix $(BUILD_DIR)/, $(notdir $(subst .lua.h,.h,$@)))
@sed -i 's/unsigned int/const unsigned int/g' $(addprefix $(BUILD_DIR)/, $(notdir $(subst .lua.h,.h,$@)))

Startup.o: $(STARTUP)
@$(CC) $(CFLAGS) -c $< -o $@
@echo $@

wav: fsk-wav

fsk-wav: $(BIN)
export PYTHONPATH=$$PYTHONPATH:'.' && \
cd .. && python stm-audio-bootloader/fsk/encoder.py \
-s 48000 -b 16 -n 8 -z 4 -p 256 -g 16384 -k 1800 \
$(PRJ_DIR)/$(BIN)

erase:
st-flash erase

norns:
lua util/ii_norns_actions.lua lua/ii/ $(NORNS_DIR)/lua/core/crow/ii_actions.lua
lua util/ii_norns_events.lua lua/ii/ $(NORNS_DIR)/lua/core/crow/ii_events.lua

.PHONY: clean
clean:
@rm -rf Startup.lst $(TARGET).elf.lst $(OBJS) $(AUTOGEN) \
$(TARGET).bin $(TARGET).out $(TARGET).hex $(TARGET).dfu \
$(TARGET).map $(TARGET).dmp $(EXECUTABLE) $(DEP) \
$(BUILD_DIR) lua/*.lua.h \
$(TARGET)-$(GIT_VERSION)/ *.zip \

splint:
splint -I. -I./ $(STM32_INCLUDES) *.c
3 changes: 1 addition & 2 deletions stm32_flash.ld
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ _Min_Stack_Size = 0x10000; /* required amount of stack */
/* Specify the memory areas */
MEMORY
{
/* FLASH (rx) : ORIGIN = 0x00200000, LENGTH = 512K */ /* ITCM interface */
FLASH (rx) : ORIGIN = 0x08020000, LENGTH = 384K /* AXIM interface */
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 512K /* AXIM interface */
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 256K
/* MEMORY_B1 (rx) : ORIGIN = 0x60000000, LENGTH = 0K */
/* CCMRAM (rw) : ORIGIN = 0x10000000, LENGTH = 64K */
Expand Down
2 changes: 1 addition & 1 deletion system_stm32f7xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
/*!< Uncomment the following line if you need to relocate your vector Table in
Internal SRAM. */
/* #define VECT_TAB_SRAM */
#define VECT_TAB_OFFSET 0x20000 /*!< Vector Table base offset field.
#define VECT_TAB_OFFSET 0x0000 /*!< Vector Table base offset field.
This value must be a multiple of 0x200. */
/******************************************************************************/

Expand Down

0 comments on commit 03d9a80

Please sign in to comment.