Skip to content

Commit e616558

Browse files
committed
Ignore non-printable characters, re-organize for multiple boards/mcus, add GitHub action. Fixes #11 and fixes #9
1 parent c1c6118 commit e616558

File tree

11 files changed

+112
-29
lines changed

11 files changed

+112
-29
lines changed

.github/workflows/main.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: CI
2+
3+
on: [push]
4+
5+
jobs:
6+
build:
7+
8+
runs-on: ubuntu-latest
9+
10+
timeout-minutes: 5
11+
12+
strategy:
13+
matrix:
14+
device: ['longan-nano', 'longan-nano-lite']
15+
16+
steps:
17+
- uses: actions/checkout@v3
18+
19+
- name: Install RISC-V build dependencies
20+
run: sudo apt-get install build-essential binutils-riscv64-unknown-elf gcc-riscv64-unknown-elf
21+
22+
- name: Build the FiveForths firmware binary for ${{matrix.device}}
23+
run: make ${{matrix.device}}
24+
25+
- name: Obtain SHA256 hash of the firmware ${{matrix.device}}.bin
26+
run: sha256sum fiveforths.bin > fiveforths.bin.sha256
27+
28+
- uses: actions/upload-artifact@v3
29+
with:
30+
name: fiveforths-firmware-${{matrix.device}}
31+
path: fiveforths.bin*

Makefile

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,28 @@
44

55
PROGNAME = fiveforths
66
CFLAGS := -g
7-
ARCH ?= rv32imac # rv32imac for Longan Nano
8-
EMU ?= elf32lriscv
97
CROSS ?= /usr/bin/riscv64-unknown-elf-
108
AS := $(CROSS)as
119
LD := $(CROSS)ld
1210
OBJCOPY := $(CROSS)objcopy
1311
OBJDUMP := $(CROSS)objdump
1412
READELF := $(CROSS)readelf
1513

14+
# MCU and board specific variables
15+
ARCH ?= rv32imac
16+
EMU ?= elf32lriscv
17+
MCU ?= gd32vf103
18+
BOARD ?= longan-nano-lite
19+
1620
.PHONY: clean
1721

1822
build: $(PROGNAME).o $(PROGNAME).elf $(PROGNAME).bin $(PROGNAME).hex $(PROGNAME).dump
1923

2024
%.o: %.s
21-
$(AS) $(CFLAGS) -march=$(ARCH) -I src -o $@ $<
25+
$(AS) $(CFLAGS) -march=$(ARCH) -I src/boards/$(BOARD) -I src/mcus/$(MCU) -I src -o $@ $<
2226

2327
%.elf: %.o
24-
$(LD) -m $(EMU) -T $(PROGNAME).ld -o $@ $<
28+
$(LD) -m $(EMU) -T src/boards/$(BOARD)/linker.ld -o $@ $<
2529

2630
%.bin: %.elf
2731
$(OBJCOPY) -O binary $< $@
@@ -44,5 +48,11 @@ openocd:
4448
debug:
4549
/opt/riscv/bin/riscv64-unknown-elf-gdb -command=debug.gdb -q fiveforths.elf
4650

51+
longan-nano:
52+
$(MAKE) build BOARD=longan-nano
53+
54+
longan-nano-lite:
55+
$(MAKE) build BOARD=longan-nano-lite
56+
4757
clean:
4858
rm -v *.bin *.elf *.o *.hex *.dump

README.md

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,14 @@ Development progress has been logged regularly in the [devlogs](https://aw.githu
3030

3131
# Getting started
3232

33+
It is possible to download a firmware binary or build the firmware manually.
34+
3335
## Download it
3436

3537
Download one of the firmware binaries from the [releases page](https://github.com/aw/fiveforths/releases).
3638

37-
* [fiveforths-longan-nano-lite.bin](https://github.com/aw/fiveforths/releases/download/v0.1/fiveforths-longan-nano-lite.bin) (64K Flash, 20K RAM)
38-
* [fiveforths-longan-nano.bin](https://github.com/aw/fiveforths/releases/download/v0.1/fiveforths-longan-nano.bin) (128K Flash, 32K RAM)
39+
* [fiveforths-longan-nano-lite.bin](https://github.com/aw/fiveforths/releases/download/v0.2/fiveforths-longan-nano-lite.bin) (64K Flash, 20K RAM)
40+
* [fiveforths-longan-nano.bin](https://github.com/aw/fiveforths/releases/download/v0.2/fiveforths-longan-nano.bin) (128K Flash, 32K RAM)
3941

4042
## Build it
4143

@@ -65,7 +67,7 @@ $ make
6567
/usr/bin/riscv64-unknown-elf-objdump -D -S fiveforths.elf > fiveforths.dump
6668
```
6769

68-
The firmware file is called `fiveforths.bin` and is **under 2 KBytes** as of _January 08, 2023_.
70+
The firmware file is called `fiveforths.bin` and is **under 2 KBytes** as of _release v0.1_ since _January 08, 2023_.
6971

7072
# Flashing the firmware
7173

@@ -121,7 +123,7 @@ The source files are:
121123
# TODO
122124

123125
- [ ] Finish writing this README
124-
- [ ] Fix remaining bugs (carriage return issue)
126+
- [x] Fix remaining bugs (carriage return issue)
125127
- [ ] Implement bounds checks for stacks and dictionary
126128
- [ ] Code cleanup and optimizations
127129
- [ ] Add example Forth code to turn it into a "real" Forth (ex: `[`, `]`, `branch`, etc)
@@ -132,7 +134,14 @@ Please create a pull-request or [open an issue](https://github.com/aw/picolisp-k
132134

133135
# Changelog
134136

135-
* 2023-01-09 - First release
137+
## 0.2 (2023-01-10)
138+
139+
* Fix issue #9 - Handling of carriage return
140+
* Fix issue #11 - Ignore non-printable characters
141+
* Re-organize code to support different boards and MCUs
142+
* Add GitHub action to automatically build and publish the firmware binaries
143+
144+
## 0.1 2023-01-09 - First release
136145

137146
# Other Forths
138147

fiveforths.s

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,16 @@ Copyright (c) 2021 Alexander Williams, On-Prem <license@on-premises.com>
1919
# s1 = IP = instruction pointer
2020
# s2 = RSP = return stack pointer
2121

22+
# include board-specific functions and constants from src/boards/<board>/
23+
.include "board.s"
24+
25+
# include MCU-specific functions and constants from src/mcus/<MCU>/
26+
.include "mcu.s"
27+
28+
# include source files from src/
2229
.include "01-variables-constants.s"
2330
.include "02-macros.s"
2431
.include "03-interrupts.s"
25-
26-
# include board-specific functions
27-
.include "gd32vf103.s"
28-
2932
.include "04-io-helpers.s"
3033
.include "05-internal-functions.s"
3134
.include "06-initialization.s"

src/01-variables-constants.s

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,6 @@
88
# Memory map
99
##
1010

11-
# adjust these values for specific targets
12-
.equ CELL, 4 # 32-bits cell size
13-
.equ RAM_BASE, 0x20000000 # base address of RAM
14-
.equ RAM_SIZE, 1024 * 20 # 20 KiB
15-
.equ STACK_SIZE, 256 # 256 Bytes
16-
1711
# DSP, RSP, TIB stacks grow downward from the top of memory
1812
.equ DSP_TOP, RAM_BASE + RAM_SIZE # address of top of data stack
1913
.equ RSP_TOP, DSP_TOP - STACK_SIZE # address of top of return stack
@@ -36,7 +30,7 @@
3630
##
3731

3832
.equ CHAR_NEWLINE, '\n' # newline character 0x0A
39-
.equ CHAR_CARRIAGE, '\r' # carriage return character 0x13
33+
.equ CHAR_CARRIAGE, '\r' # carriage return character 0x0D
4034
.equ CHAR_SPACE, ' ' # space character 0x20
4135
.equ CHAR_BACKSPACE, '\b' # backspace character 0x08
4236
.equ CHAR_COMMENT, '\\' # backslash character 0x5C

src/09-interpreter.s

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ interpreter:
1414
call uart_get # read a character from UART
1515
li t4, CHAR_NEWLINE # load newline into temporary
1616
beq a0, t4, skip_send # don't send the character if it's a newline
17+
18+
# ignore specific characters
19+
mv t4, zero # load 0x00 zero into temporary
20+
beq a0, t4, interpreter # ignore the character if it matches
21+
li t4, CHAR_CARRIAGE # load 0x0D carriage return into temporary
22+
beq a0, t4, interpreter # ignore the character if it matches
23+
1724
call uart_put # send the character to UART
1825

1926
skip_send:
@@ -27,11 +34,6 @@ skip_send:
2734
li t0, CHAR_BACKSPACE # load backspace into temporary
2835
beq a0, t0, process_backspace # process the backspace if it matches
2936

30-
li t0, CHAR_CARRIAGE # load carriage return into temporary
31-
beq a0, t0, process_carriage # process the carriage return if it matches
32-
33-
# TODO: check if character is printable
34-
3537
interpreter_tib:
3638
# add the character to the TIB
3739
li t4, TIB_TOP # load TIB_TOP memory address
@@ -64,10 +66,6 @@ process_backspace:
6466

6567
j interpreter # return to the interpreter after erasing the character
6668

67-
process_carriage:
68-
li a0, CHAR_NEWLINE # convert a carriage return to a newline
69-
j interpreter_tib # jump to add the character to the TIB
70-
7169
.balign CELL
7270
replace_newline:
7371
li a0, CHAR_SPACE # convert newline to a space
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
##
2+
# Longan Nano Lite
3+
##
4+
5+
.equ RAM_SIZE, 1024 * 20 # 20 KiB
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* GD32VF103C8 */
12
MEMORY
23
{
34
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 64k

src/boards/longan-nano/board.s

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
##
2+
# Longan Nano
3+
##
4+
5+
.equ RAM_SIZE, 1024 * 32 # 32 KiB

src/boards/longan-nano/linker.ld

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/* GD32VF103CB */
2+
MEMORY
3+
{
4+
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 128k
5+
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 32k
6+
}
7+
8+
/* The entry point is the reset handler */
9+
ENTRY(_start);
10+
11+
SECTIONS {
12+
__stacktop = ORIGIN(RAM) + LENGTH(RAM);
13+
14+
/* The program code and other data goes into FLASH */
15+
.text :
16+
{
17+
. = ALIGN(4);
18+
*(.text) /* .text sections (code) */
19+
*(.rodata) /* .rodata sections (constants, strings, etc.) */
20+
} >FLASH
21+
22+
}

0 commit comments

Comments
 (0)