Skip to content

Commit

Permalink
Merge pull request #38 from TG9541/update
Browse files Browse the repository at this point in the history
Update
  • Loading branch information
TG9541 authored Jan 31, 2021
2 parents 9ef0e5d + 7674d15 commit 7b5882c
Show file tree
Hide file tree
Showing 9 changed files with 160 additions and 87 deletions.
7 changes: 3 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ language: c
services:
- docker
before_install:
- docker pull tg9541/docker-sdcc:V3.8.6
- docker pull tg9541/docker-sdcc:V3.9.0
install:
- docker run -v `pwd`:/home tg9541/docker-sdcc:V3.8.4 /bin/sh -c "sdcc --version ;
- docker run -v `pwd`:/home tg9541/docker-sdcc:V3.9.0 /bin/sh -c "sdcc --version ;
sstm8 -version"
script: docker run -v `pwd`:/home tg9541/docker-sdcc:V3.8.4 /bin/sh -c "cd /home &&
make release"
script: docker run -v `pwd`:/home tg9541/docker-sdcc:V3.9.0 /bin/sh -c "cd /home && make release"
deploy:
provider: releases
api_key:
Expand Down
2 changes: 1 addition & 1 deletion C0135/IN@
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
\ C0135 4-Relay board: read low side inputs - License MIT refer to STM8 eForth

\ This is close to the iron
\res MCU: STM8S105
\res MCU: STM8S103
\res export PC_IDR PC_CR1 PD_IDR PD_CR1

\ copy bit to C flag, set/res bit
Expand Down
4 changes: 2 additions & 2 deletions C0135/board.fs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#require LOCK
#require ULOCK
#require 'IDLE
#require .OK

\ define temporary constants
$4000 CONSTANT EE_NODE
Expand Down Expand Up @@ -69,7 +68,8 @@ NVM
EE_BAUD @ ( #BR ) UARTISR

[ ' MBPROTO ( xt ) ] LITERAL 'IDLE !
.OK

." STM8EF-MODBUS C0135" hi
;

\ register initialization
Expand Down
28 changes: 0 additions & 28 deletions C0135/boardcore.inc
Original file line number Diff line number Diff line change
Expand Up @@ -53,34 +53,6 @@ AOUTSTOR:
RET
.endif

;===============================================================

; Dummy labels for PSIM interrupts declared in main.c

.ifne PSIM-PORTA
; Dummy label for _EXTIA_IRQHandler
_EXTI0_IRQHandler:
.endif

.ifne PSIM-PORTB
; Dummy label for _EXTIB_IRQHandler
_EXTI1_IRQHandler:
.endif

.ifne PSIM-PORTC
; Dummy label for _EXTIC_IRQHandler
_EXTI2_IRQHandler:
.endif

.ifne PSIM-PORTD
; Dummy label for _EXTID_IRQHandler
_EXTI3_IRQHandler:
.endif

.ifne PSIM-PORTE
; Dummy label for _EXTIE_IRQHandler
_EXTI4_IRQHandler:
.endif

;===============================================================

Expand Down
9 changes: 5 additions & 4 deletions C0135/target.inc
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

TARGET = STM8S103F3

RAMEND = 0x03FF ; system (return) stack, growing down
EEPROMEND = 0x427F ; STM8S103F3: 640 bytes EEPROM
FLASHEND = 0x9FFF ; 8K devices
RAMEND = 0x03FF ; "RAMEND" system (return) stack, growing down
EEPROMBASE = 0x4000 ; "EESTART" EEPROM start address
EEPROMEND = 0x427F ; "EEEND" 640 bytes EEPROM
FLASHEND = 0x9FFF ; "FLASHEND" 8K devices

FORTHRAM = 0x0040 ; Start of RAM controlled by Forth
FORTHRAM = 0x0030 ; Start of RAM controlled by Forth
UPPLOC = 0x0060 ; UPP (user/system area) location for 1K RAM
CTOPLOC = 0x0080 ; CTOP (user dictionary) location for 1K RAM
SPPLOC = 0x0350 ; SPP (data stack top), TIB start
Expand Down
49 changes: 28 additions & 21 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
STM8EF_BOARD=C0135
STM8EF_VER=2.2.24.pre3
STM8EF_VER=2.2.27.pre2
STM8EF_BIN=stm8ef-bin.zip
STM8EF_URL=https://github.com/TG9541/stm8ef/releases/download/${STM8EF_VER}/${STM8EF_BIN}

E4THCOM=e4thcom-0.6.3
E4THCOM=e4thcom
TERM_PORT=ttyUSB0
TERM_BAUD=9600
TERM_FLAGS=
TERM_FLAGS="-p mcu:target:lib"

# MODBOARD=C0135

ifeq ($(BOARD),)

Expand All @@ -16,55 +17,61 @@ forth=$(wildcard *fs) $(mmforth)

.PHONY: test clean

# Usage:make term BOARD=<board dir> [TERM_PORT=ttyXXXX] [TERM_BAUD=nnnn] [TERM_FLAGS="--half-duplex --idm"]
all: load
all: build

release: zip tgz
release: buildload zip tgz

zip: simload
zip:
find out/ -name "*.ihx" -print | zip -r out/stm8ef-bin LICENSE.md docs/words.md inc/* mcu/* lib/* -@
find out/ -name "simbreak.txt" -print | zip -r out/stm8ef-bin tools/* -@
find out/ -name "target" -print | zip -r out/stm8ef-bin -@

tgz: simload
tgz:
( find out/ -path "*target/*" -print0 ; find out/ -name "*.ihx" -type f -print0 ; find out/ -name "simbreak.txt" -type f -print0 ) | tar -czvf out/stm8ef-bin.tgz LICENSE.md docs/words.md mcu lib tools --null -T -
( find out/ -name "forth.rst" -type f -print0 ) | tar -czvf out/stm8ef-rst.tgz --null -T -

build: words
make BOARD=CORE
build: depend
make BOARD=C0135
make BOARD=STM8S001J3RS485

buildload: depend
make MODBOARD=C0135 simload
make MODBOARD=STM8S001J3RS485 simload

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

flash: target defaults
stm8flash -c stlinkv2 -p stm8s103f3 -w out/$(STM8EF_BOARD)/$(STM8EF_BOARD).ihx
flash: target
make BOARD=$(MODBOARD) flash

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

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

simload: $(forth) target
tools/simload.sh $(STM8EF_BOARD)
make BOARD=$(MODBOARD)
tools/simload.sh $(MODBOARD)
touch simload

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

binary: depend
make BOARD=C0135
make BOARD=$(MODBOARD)

depend:
if [ ! -d "out" ]; then \
if [ ! -d "lib" ]; then \
curl -# -L -O ${STM8EF_URL}; \
unzip -q -o ${STM8EF_BIN} -x out/*; \
unzip -q -o ${STM8EF_BIN} out/${STM8EF_BOARD}/*; \
# tar -xz --exclude='out/*' -f ${STM8EF_BIN}; \
unzip -q -n ${STM8EF_BIN} -x out/*; \
rm ${STM8EF_BIN}; \
fi
touch depend

# 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)

Expand Down
35 changes: 35 additions & 0 deletions STM8S001J3RS485/BUSCTRL
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
\ STM8EF-MODBUS bus control for the STM8S001J3RS485 board

\res MCU: STM8S103
\res export PD_ODR PD_DDR PD_CR1
\res export UART1_CR2 UART1_CR5 UART1_DR

5 CONSTANT #RIEN

#require ]B!
#require WIPE

NVM
\ Set RS485 Driver to "RX"
: BUSrx ( -- )
[ 0 PD_ODR 6 ]B!
UART1_DR C@ DROP \ remove any received char
[ 0 UART1_CR2 #RIEN ]B! \ re-enable interrupt
;

\ Set RS485 Driver to "TX"
: BUStx ( -- )
[ 0 UART1_CR2 #RIEN ]B! \ RX/TX is a shared pin - play it safe
[ 1 PD_ODR 6 ]B!
;

\ Initialize GPIO and RS485 Driver
: BUSCTRL ( -- )
[ 1 UART1_CR5 3 ]B! \ UART1 Half-Duplex
[ 0 PD_DDR 5 ]B! \ PD5 input mode
[ 1 PD_CR1 5 ]B! \ PD5 UART_TXRX pull-up
[ 1 PD_DDR 6 ]B! \ PD6 !RE/DE output mode
[ 1 PD_CR1 6 ]B! \ PD6 push-pull
BUSrx
;
WIPE RAM
86 changes: 86 additions & 0 deletions STM8S001J3RS485/board.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
\ STM8 eForth MODBUS board code for the STM8S001J3RS485 board

( Hint for non-Forthers )
\ - this and the above are comments
\ - @ means "read" and ! means "write"
\ - : means "compile", [ switches to "interpret", ] back and ; "end compile"
\ - #require, \res, etc are e4thcom or codeload.py keywords

\ pre-load BUSCTRL so that a later #require won't load the C0135 default code
#include STM8S001J3RS485/BUSCTRL

\ compile MODBUS server and protocol words
#require MBSERVER

\ no inputs here but this would be a good place to start (or use I2C)
\ #include C0135/IN@

\ we're in RAM mode: load "scaffolding words"
#require :NVM
#require WIPE
#require LOCK
#require ULOCK
#require 'IDLE
#require .OK

\ define temporary constants
$4000 CONSTANT EE_NODE
$4002 CONSTANT EE_BAUD

\ now compile to Flash ROM
NVM

\ set MODBUS RTU default node ID (1) and 9600 baud RTU
: default ( -- )
ULOCK
1 EE_NODE ! \ 1 as Node-ID (holding register 0)
0 EE_BAUD ! \ default rate (holding register 1)
LOCK
;

\ headerless code Preparation Handler
:NVM
\ no inputs here but this is a good place to read a sensor value from I2C
\ IN@ inputs !
;NVM ( xt-pre ) \ compile time: keep this eXecution Token on the stack

\ headerless code Action Handler
:NVM
\ no outputs here but this is the right place to write to I2C
\ coils @ OUT!
;NVM ( xt-act ) \ and also this execution token

\ --- MODBUS server startup
: init ( -- )
\ register the xt (see above) as the MODBUS Action Handler
( xt-act ) LITERAL mbact !
( xt-pre ) LITERAL mbpre !

\ Holding C0135 key "S2" while start-up resets Node-ID and baud rate
\ BKEY IF
default
\ THEN

\ no inputs here but this is the right place to init the I2C peripheral
\ IN@INIT

\ initialize MODBUS "coils" and outputs
0 coils ! ( no outputs here \ 0 OUT! )

\ set MODBUS node ID
EE_NODE @ DUP 0 256 WITHIN NOT IF
DROP 1 \ out of range - use 1 as default node ID
THEN ( n ) mbnode !

\ start interrupt handler
EE_BAUD @ ( #BR ) UARTISR

\ register protocol handler
[ ' MBPROTO ( xt ) ] LITERAL 'IDLE !

CR ." STM8EF-MODBUS STM8S001J3RS485" .OK
;

\ register initialization
' init 'BOOT !
WIPE RAM
27 changes: 0 additions & 27 deletions STM8S001J3RS485/boardcore.inc
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,6 @@



; Dummy labels for PSIM interrupts declared in main.c

.ifne PSIM-PORTA
; Dummy label for _EXTIA_IRQHandler
_EXTI0_IRQHandler:
.endif

.ifne PSIM-PORTB
; Dummy label for _EXTIB_IRQHandler
_EXTI1_IRQHandler:
.endif

.ifne PSIM-PORTC
; Dummy label for _EXTIC_IRQHandler
_EXTI2_IRQHandler:
.endif

.ifne PSIM-PORTD
; Dummy label for _EXTID_IRQHandler
_EXTI3_IRQHandler:
.endif

.ifne PSIM-PORTE
; Dummy label for _EXTIE_IRQHandler
_EXTI4_IRQHandler:
.endif

;===============================================================

.ifne HAS_LED7SEG
Expand Down

0 comments on commit 7b5882c

Please sign in to comment.