Skip to content

Commit

Permalink
Merge pull request #359 from TG9541/rel2.2.26.pre3
Browse files Browse the repository at this point in the history
#358 experiment with STM8L Medium+ and High Density devices
  • Loading branch information
TG9541 authored Sep 26, 2020
2 parents 7e16235 + 2b345af commit 75d17c8
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 26 deletions.
41 changes: 24 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,29 @@ STM8 eForth is an interactive Forth system for very low-cost STM8 µCs. The Fort

STM8 eForth is based on [Dr. C.H. Ting's eForth](http://www.forth.org/svfig/kk/07-2010.html) for the STM8S Discovery. With the kind permission of the original author this code is under an [MIT-like license](https://github.com/TG9541/stm8ef/blob/master/LICENSE.md). Most of the code was re-written and new features include compiling Forth code to Flash memory, autostart operation, interrupt handling and many more.

The [binary release](https://github.com/TG9541/stm8ef/releases) provides a full working environment, including the library, target folders, STM8 register definitions and [modular board support](https://github.com/TG9541/stm8ef-modular-build). Travis-CI takes care of [automated testing in the uCsim STM8 simulator](https://travis-ci.org/TG9541/stm8ef) and it's possible to create ready-to-run binaries in "downstream projects".
The [binary release](https://github.com/TG9541/stm8ef/releases) provides a full working environment, including the library, target folders, STM8 register definitions and [modular board support](https://github.com/TG9541/stm8ef-modular-build). Travis-CI takes care of automated testing in the [uCsim STM8 simulator](https://travis-ci.org/TG9541/stm8ef) which also makes building ready-to-run binaries in "downstream projects" possible.

[![STM8EF Wiki](https://user-images.githubusercontent.com/5466977/28994765-3267d78c-79d6-11e7-927f-91751cd402db.jpg)](https://github.com/TG9541/stm8ef/wiki)

The programming language Forth works by defining new words out of existing words where data simply flows through the stack. "Hello World" in Forth is as simple as this:
The programming language Forth is very well suited for embedded control. Forth works by defining new words out of existing words where data simply flows through the stack.

"Hello World" in Forth is as simple as this:

```Forth
: hello ." Hello World!" ;
```

Forth is very well suited for embedded programming. Find out more in the [STM8 eForth Walk-Through](https://github.com/TG9541/stm8ef/wiki/STM8-eForth-Programming).
Find out more in the [STM8 eForth Walk-Through](https://github.com/TG9541/stm8ef/wiki/STM8-eForth-Programming).

STM8 eForth is configurable: a minimal system fits in 3.5K, small enough for an STM8S103F2 with 4K ROM. A full featured core binary requires 4 to 5.5K Flash memory, leaving sufficent space for applications in 8K devices. For large applications devices with up to 32K Flash memory can be used (e.g. the $0.50 STM8S005C6T6).
STM8 eForth is configurable: a minimal system fits in 3.5K which is small enough for µCs with 4K ROM. A full featured core binary requires 4 to 5.5K Flash memory which leaves sufficent space for applications in the cheap 8K device [STM8S003F3P6](https://www.st.com/resource/en/datasheet/stm8s003f3.pdf). For larger applications 32K devices like the [STM8S005C6T6](https://www.st.com/resource/en/datasheet/stm8s005c6.pdf) can be used (a chip with 38 GPIOs for less than $1).

The Forth console uses the STM8 U(S)ART or a simulated serial interface and 3-wire or 2-wire (half-duplex). For interacting and programming [e4thcom](https://wiki.forth-ev.de/doku.php/en:projects:e4thcom) is recommended but any common serial terminal will work. The console can be configured, even at runtime, to use other types of [character I/O](https://github.com/TG9541/stm8ef/wiki/STM8-eForth-Board-Character-IO), e.g. keyboard and display.

The [Wiki on GitHub](https://github.com/TG9541/stm8ef/wiki) covers various topics, e.g. using [Breakout Boards](https://github.com/TG9541/stm8ef/wiki/Breakout-Boards) or the conversion of low-cost Chinese thermostats, voltmeters, or DC/DC-converters into Forth powered embedded control boards.
The [Wiki on GitHub](https://github.com/TG9541/stm8ef/wiki) covers various topics, e.g. converting low-cost Chinese thermostats, voltmeters, or DC/DC-converters into Forth powered embedded control boards.

## Generic targets

Generic target binaries are provided as for use or for evaluation:
The Releases section provides several generic binaries:

Support for STM8S devices [RM0016](https://www.st.com/resource/en/reference_manual/cd00190271-stm8s-series-and-stm8af-series-8-bit-microcontrollers-stmicroelectronics.pdf) is stable. Various STM8 Discovery boards and [breakout boards](https://github.com/TG9541/stm8ef/wiki/Breakout-Boards) for Low-, Medium-, and High-Density devices can be used.

Expand All @@ -38,17 +40,17 @@ Support for STM8S devices [RM0016](https://www.st.com/resource/en/reference_manu
* [STM8S105K4](https://github.com/TG9541/stm8ef/tree/master/STM8S105K4) for STM8S Medium Density devices (Value or Access Line) with 2K RAM and up to 32K Flash
* [STM8S207RB](https://github.com/TG9541/stm8ef/tree/master/STM8S207RB) for STM8S High Density devices (Value or Performance Line) with 6K RAM and up to 32K + 96K Flash

Support for STM8L devices is work-in-progress: especially the latest additions STM8L101F3 and STM8L001J3 are experimental, and there have been no documented tests with STM8L Medium+ or High Density devices (although the code can be expected to work.
Support for STM8L devices is work-in-progress: especially the latest additions STM8L101F3 and STM8L001J3 are experimental, and there have been no documented tests with STM8L Medium+ or High Density devices like STM8L152R8 (although the code can be expected to work, see note in [STM8L151K4](https://github.com/TG9541/stm8ef/tree/master/STM8L151K4)).

* STM8L Low Density devices ([RM0013](https://www.st.com/resource/en/reference_manual/CD00184503-.pdf), RM0031, [RM0312](https://www.st.com/resource/en/reference_manual/dm00040094-stm8tl5xxx-microcontroller-family-stmicroelectronics.pdf))
* [STM8L101F3](https://github.com/TG9541/stm8ef/tree/master/STM8L101F3) for STM8L101 Low Density devices (experimental, see [issue](https://github.com/TG9541/stm8ef/issues/349))
* [STM8L051F3](https://github.com/TG9541/stm8ef/tree/master/STM8L051F3) for STM8L Low Density devices (see [issue](https://github.com/TG9541/stm8ef/issues/137#issuecomment-354542670))
* STM8L Medium Density devices ([RM0031](https://www.st.com/resource/en/reference_manual/cd00218714-stm8l050j3-stm8l051f3-stm8l052c6-stm8l052r8-mcus-and-stm8l151l152-stm8l162-stm8al31-stm8al3l-lines-stmicroelectronics.pdf))
* [STM8L151K4](https://github.com/TG9541/stm8ef/tree/master/STM8L-DISCOVERY) for STM8L Medium Density devices
* [STM8L151K4](https://github.com/TG9541/stm8ef/tree/master/STM8L151K4) for STM8L Medium Density devices

## Board support:

TG9541/STM8EF provides board support, e.g. LED display code, for several common "Chinese gadgets" like the following:
STM8 eForth provides board support like LED display code for several common boards and "Chinese gadgets":

* [MINDEV](https://github.com/TG9541/stm8ef/wiki/Breakout-Boards) for the STM8S103F3P6 $0.80 "minimum development board"
* [STM8L-DISCOVERY](https://github.com/TG9541/stm8ef/tree/master/STM8L-DISCOVERY) for the STM8L-Discovery Board (STM8L152C6 Medium Density with LCD)
Expand All @@ -63,24 +65,29 @@ TG9541/STM8EF provides board support, e.g. LED display code, for several common

The Wiki lists other supported "[Value Line Gadgets][WG1]", e.g. [voltmeters & power supplies](https://github.com/TG9541/stm8ef/wiki/STM8S-Value-Line-Gadgets#voltmeters-and-power-supplies), [breakout boards](https://github.com/TG9541/stm8ef/wiki/Breakout-Boards), and [thermostats](https://github.com/TG9541/stm8ef/wiki/STM8S-Value-Line-Gadgets#thermostats).

## Other target boards
## Targeting other boards

The binary release contains all files required for building a configured STM8 eForth, e.g. for a custom target board. The [modular build](https://github.com/TG9541/stm8ef-modular-build) repository provides instructions, a `Makefile` and an example "board folder". Other examples are in the GitHub repositories [W1209](https://github.com/TG9541/W1209), [STM8 eForth MODBUS](https://github.com/TG9541/stm8ef-modbus), [STM8L051LED](https://github.com/TG9541/stm8l051led) or [XY-LPWM](https://github.com/TG9541/XY-LPWM).

From STM8 eForth 2.2.24 on, the binary release contains all files necessary for building STM8 eForth, e.g. for a custom target board. The [modular build](https://github.com/TG9541/stm8ef-modular-build) repository provides instructions and all required files. Examples are [W1209](https://github.com/TG9541/W1209), [STM8 eForth MODBUS](https://github.com/TG9541/stm8ef-modbus), [STM8L051LED](https://github.com/TG9541/stm8l051led) or [XY-LPWM](https://github.com/TG9541/XY-LPWM).

# STM8 eForth Feature Overview

In addition to the original "stm8ef" this STM8 eForth offers many features:
Compared to the original "stm8ef" STM8 eForth offers many features:

* Subroutine Threaded Code (STC) with improved code density that rivals DTC
* native `BRANCH` (JP), and `EXIT` (RET)
* relative CALL when possible (2 instead of 3 bytes)
* TRAP as a pseudo-opcode for literals (3 instead of 5 bytes)
* a versatile framework for development based on Manfred Mahlow's e4thcom
* board folder and include file structure for simple configuration
* `#include` and `#require` for loading code into the STM8 eForth dictionary
* `mcu`, `target` and `lib` folders provide a high degree of abstraction
* [ALIAS words](https://github.com/TG9541/stm8ef/wiki/STM8-eForth-Alias-Words) for indirect dictionary entries ([even in EEPROM!](https://github.com/TG9541/stm8ef/wiki/STM8-eForth-Alias-Words#dictionary-with-alias-words-in-the-eeprom))
* Forth - machine-code interface using STM8 registers
* compile Forth to Flash ROM with IAP (In Application Programming)
* Words `NVM` and `RAM` switch between volatile (RAM) and non volatile (NVM) modes (*execute `RAM` after `NVM` if you want your new words to be available after power-cycle or `COLD`*)
* autostart feature for embedded applications
* RAM allocation for `VARIABLE` and `ALLOT` in NVM mode (basic RAM management)
* Subroutine Threaded Code (STC) with improved code density that rivals DTC
* native `BRANCH` (JP), and `EXIT` (RET)
* relative CALL when possible (2 instead of 3 bytes)
* TRAP as a pseudo-opcode for literals (3 instead of 5 bytes)
* Forth - machine-code interface using STM8 registers
* preemptive background tasks `BG`
* `INPUT-PROCESS-OUTPUT` task indepent of the Forth console
* fixed cycle time (configurable, default: 5ms)
Expand Down
24 changes: 22 additions & 2 deletions STM8L151K4/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,29 @@

This folder contains support for STM8L Medium Density devices like [STM8L151K4](https://www.st.com/resource/en/datasheet/stm8l151r6.pdf).

STM8L151K4 stands for "Medium density" devices with 2K RAM, 1K EEPROM and up to 32K Flash ROM as described in [RM0031](https://www.st.com/resource/en/reference_manual/cd00218714-stm8l050j3-stm8l051f3-stm8l052c6-stm8l052r8-mcus-and-stm8l151l152-stm8l162-stm8al31-stm8al3l-lines-stmicroelectronics.pdf) (or "32 Kbyte die" as described in [UM0470](https://www.st.com/content/ccc/resource/technical/document/user_manual/ca/89/41/4e/72/31/49/f4/CD00173911.pdf/files/CD00173911.pdf/jcr:content/translations/en.CD00173911.pdf)), all of which should work with the STM8L151K4 binary in the Releases section (it's likely that it is also usable for Automotive Grade STM8L devices that meet these criteria).
STM8L151K4 stands for "Medium density" devices with 2K RAM, 1K EEPROM and up to 32K Flash ROM as described in [RM0031](https://www.st.com/resource/en/reference_manual/cd00218714-stm8l050j3-stm8l051f3-stm8l052c6-stm8l052r8-mcus-and-stm8l151l152-stm8l162-stm8al31-stm8al3l-lines-stmicroelectronics.pdf) (or "32 Kbyte die" as described in [UM0470](https://www.st.com/content/ccc/resource/technical/document/user_manual/ca/89/41/4e/72/31/49/f4/CD00173911.pdf/files/CD00173911.pdf/jcr:content/translations/en.CD00173911.pdf)), all of which should work with the STM8L151K4 binary in the Releases section (likely it's also usable for Automotive Grade STM8L Medium Density devices).

"Medium+" or "High Density" devices as described in RM0031 have 4K RAM (e.g. STM8L052R8) and require different RAM settings in `target.inc`. Peripheral register addresses are likely the same and constants imported from `\res MCU: STM8L151` should work.

"Medium+" or "High Density" devices described in RM0031 (e.g. STM8L052R8) have, besides more peripherals, 4K RAM and require different RAM settings in `target.inc`. If you have e.g. a NUCLEO-8L152R8 you may want to try the following settings:

```
; STM8L152R8 device and memory layout configuration
TARGET = STM8L152R8
RAMEND = 0x0FFF ; "RAMEND" system (return) stack, growing down
EEPROMBASE = 0x1000 ; "EESTART" EEPROM start address
EEPROMEND = 0x17FF ; "EEEND" 2K EEPROM
FLASHEND = 0xFFFF ; 32K Forth + 32K far memory
FORTHRAM = 0x0030 ; Start of RAM controlled by Forth
UPPLOC = 0x0060 ; UPP (user/system area) location for 4K RAM
CTOPLOC = 0x0080 ; CTOP (user dictionary) location for 4K RAM
SPPLOC = 0x0f50 ; SPP (data stack top), TIB start
RPPLOC = RAMEND ; RPP (return stack top)
```

The default USART for the Forth console is USART1. That can be changed by setting `USE_USART2 = 1` or `USE_USART3 = 1` in `globconf.inc`. Peripheral register addresses are likely the same and constants imported from `\res MCU: STM8L151` should work. Of course, we'd be happy to hear from you if it works (or help fixing it if it doesn't).

Low Density devices described in RM0031 (e.g. STM8L051), RM0013 (e.g. STM8L101) or RM0312 (STM8TL5xxx) use different peripheral register addresses and have a different memory layout. These require a different binary.

Expand Down
1 change: 1 addition & 0 deletions forth.asm
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
STM8L101F3 = STM8L_101 ; L core, 8K flash incl EEPROM, 1.5K RAM, UART1
STM8L051F3 = STM8L_LOD ; L core, 8K flash, 1K RAM, 256 EEPROM, UART1
STM8L152C6 = STM8L_MHD ; L core, 32K flash, 2K RAM, 1K EEPROM, UART1
STM8L152R8 = STM8L_MHD ; L core, 64K flash, 4K RAM, 2K EEPROM, UART1
STM8S003F3 = STM8S_LOD ; 8K flash, 1K RAM, 128 EEPROM, UART1
STM8S103F3 = STM8S_LOD ; like STM8S003F3, 640 EEPROM
STM8S105K4 = STM8S_MED ; 16K/32K flash, 2K RAM, 1K EEPROM, UART2
Expand Down
3 changes: 2 additions & 1 deletion inc/defconf.inc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
TERM_LINUX = 1 ; LF terminates line

HALF_DUPLEX = 0 ; Use the STM8S Low Density UART in half duplex mode (1: PD5, 2: PA3)
USE_UART2 = 0 ; Use the 2nd UART for the console (STM8S207: optional, STM8S105: default)
USE_UART2 = 0 ; Use the 2nd UART for the console (STM8S207: optional, STM8S105: default, STM8L152: optional)
USE_UART3 = 0 ; Use the 3rd UART for the console (STM8L152: optional)
CUARTBRR = 0x6803 ; default value for UARTBRR 9600 baud (refer to mcu/UART_DIV)
HAS_RXUART = 1 ; Enable UART RXD, word ?RX
HAS_TXUART = 1 ; Enable UART TXD, word TX!
Expand Down
38 changes: 32 additions & 6 deletions inc/stm8ldevice.inc
Original file line number Diff line number Diff line change
Expand Up @@ -273,11 +273,6 @@
USART1_GTR = 0x5239 ; USART1 guard time register 0x00
USART1_PSCR = 0x523A ; USART1 prescaler register 0x00

UART_SR = USART1_SR
UART_DR = USART1_DR
UART_BRR1 = USART1_BRR1
UART_CR2 = USART1_CR2

; 0x00 523B to 0x00 524F Reserved area (21 bytes)
; TIM2
TIM2_CR1 = 0x5250 ; TIM2 control register 1 0x00
Expand Down Expand Up @@ -446,7 +441,38 @@
ADC1_TRIGR3 = 0x5350 ; ADC1 trigger disable 3 0x00
ADC1_TRIGR4 = 0x5351 ; ADC1 trigger disable 4 0x00
; 0x00 53C8 to 0x00 53FF Reserved area
; LCD

; USART2
USART2_SR = 0x53E0 ; USART2 status register0xC0
USART2_DR = 0x53E1 ; USART2 data register0xXX
USART2_BRR1 = 0x53E2 ; USART2 baud rate register 1
USART2_CR2 = 0x53E5 ; USART2 control register 2

; USART3
USART3_SR = 0x53F0 ; USART3 status register0xC0
USART3_DR = 0x53F1 ; USART3 data register0xXX
USART3_BRR1 = 0x53F2 ; USART3 baud rate register 1
USART3_CR2 = 0x53F5 ; USART3 control register 2

.ifeq (TARGET - STM8L_MHD) * (USE_UART3 - 1)
UART_DR = USART3_DR
UART_SR = USART3_SR
UART_BRR1 = USART3_BRR1
UART_CR2 = USART3_CR2
.else
.ifeq (TARGET - STM8L_MHD) * (USE_UART2 - 1)
UART_DR = USART2_DR
UART_SR = USART2_SR
UART_BRR1 = USART2_BRR1
UART_CR2 = USART2_CR2
.else
UART_SR = USART1_SR
UART_DR = USART1_DR
UART_BRR1 = USART1_BRR1
UART_CR2 = USART1_CR2
.endif
.endif
;; LCD
LCD_CR1 = 0x5400 ; LCD control register 1 0x00
LCD_CR2 = 0x5401 ; LCD control register 2 0x00
LCD_CR3 = 0x5402 ; LCD control register 3 0x00
Expand Down

0 comments on commit 75d17c8

Please sign in to comment.