Skip to content

Commit

Permalink
#12 modular build
Browse files Browse the repository at this point in the history
  • Loading branch information
TG9541 committed Apr 13, 2020
1 parent 5b97cda commit 82dbd90
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 16 deletions.
32 changes: 32 additions & 0 deletions C0135/board.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#require MBSERVER

$4000 CONSTANT EE_NODE
$4002 CONSTANT EE_BAUD

#require :NVM
#require WIPE

NVM
#require OUT!

\ output handler
:NVM
coils @ OUT!
;NVM ( xt )

\ --- MODBUS server startup
: init ( -- )
( xt ) LITERAL mbact !
0 coils !

EE_BAUD @ ( #BR ) UARTISR
EE_NODE @ DUP 0 256 WITHIN NOT IF
DROP 1 \ out of range - use default
THEN
( n ) mbnode !

MBSERVER
;

' init 'BOOT !
WIPE RAM
44 changes: 28 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
STM8EF_BOARD=SWIMCOM
STM8EF_BOARD=C0135
STM8EF_VER=2.2.24.pre1
STM8EF_BIN=stm8ef-bin.zip
STM8EF_URL=https://github.com/TG9541/stm8ef/releases/download/${STM8EF_VER}/${STM8EF_BIN}
Expand All @@ -8,41 +8,40 @@ TERM_PORT=ttyUSB0
TERM_BAUD=9600
TERM_FLAGS=

ifeq ($(BOARD),)

# e4thcom style Forth code can't have a file suffix (but filenames are uppercase)
mmforth:=$(shell echo `ls|gawk '/^[A-Z0-9]*$$/ {print}'`)
forth=$(wildcard *fs) $(mmforth)

.PHONY: test clean

# Usage:make term BOARD=<board dir> [TERM_PORT=ttyXXXX] [TERM_BAUD=nnnn] [TERM_FLAGS="--half-duplex --idm"]
term:
$(E4THCOM) -t stm8ef -p .:lib $(TERM_FLAGS) -d $(TERM_PORT) -b B$(TERM_BAUD)
all: load

all: flash
load: flash
tools/codeload.py -b out/$(STM8EF_BOARD) -p /dev/$(TERM_PORT) serial main.fs

zip:
zip -r ${STM8EF_BOARD}-forth ${STM8EF_BOARD}-forth.ihx
flash: target defaults
stm8flash -c stlinkv2 -p stm8s103f3 -w out/$(STM8EF_BOARD)/$(STM8EF_BOARD).ihx

defaults:
stm8flash -c stlinkv2 -p stm8s103f3 -s opt -w tools/stm8s103FactoryDefaults.bin

flash: target
stm8flash -c stlinkv2 -p stm8s103f3 -w out/$(STM8EF_BOARD)/$(STM8EF_BOARD).ihx

load: target
tools/codeload.py -b out/$(STM8EF_BOARD) -p /dev/$(TERM_PORT) serial main.fs
test: simload
test/mbtest.sh $(STM8EF_BOARD)

simload: $(forth) target
tools/simload.sh $(STM8EF_BOARD)
touch simload

test: simload
test/mbtest.sh $(STM8EF_BOARD)

target: depend
target: binary
rm -f target
ln -s out/${STM8EF_BOARD}/target target

binary: depend
make BOARD=C0135

depend:
if [ ! -d "out" ]; then \
curl -# -L -O ${STM8EF_URL}; \
Expand All @@ -52,5 +51,18 @@ depend:
fi
touch depend

term:
$(E4THCOM) -t stm8ef -p .:lib $(TERM_FLAGS) -d $(TERM_PORT) -b B$(TERM_BAUD)

zip:
zip -r ${STM8EF_BOARD}-forth ${STM8EF_BOARD}-forth.ihx

clean:
rm -rf target STM8S103.efr STM8S105.efr simload depend docs lib mcu out inc tools
rm -rf target docs lib mcu out inc tools
rm -f forth.asm forth.h forth.mk main.c STM8S103.efr STM8S105.efr
rm -f simload depend

else
# the STM8 eForth make is a dependency
include forth.mk
endif

0 comments on commit 82dbd90

Please sign in to comment.