Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wip #75

Merged
merged 60 commits into from
Jul 24, 2021
Merged

Wip #75

Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
6af1788
riscv-gd32vf103: add GD32VF103 target
lkundrak May 29, 2020
2077beb
added: esp_clk_cpu_freq esp_set_cpu_freq esp_deep_sleep
Jos-Ven Dec 4, 2020
7de0a33
arm-ariel: fix build with GCC 10.2
lkundrak Jan 8, 2021
5460c84
arm-xo-1.75: fix build with GCC 10.2
lkundrak Jan 8, 2021
1a91c30
Cooperative multitasking
MitchBradley Feb 7, 2021
f13c871
Changes for multitasking under esp8266-rtos
Feb 9, 2021
9de64a3
Added for multitasking
Feb 9, 2021
73ec8d2
Activating the 11N protocol too
Feb 9, 2021
1f7fded
Added functions for pre-emptive multitasking
Mar 9, 2021
8fb972d
Contains the experimental multitasking
Mar 9, 2021
b83f7ea
To load tasking_rtos.fth in ROM
Mar 9, 2021
a273c5f
3 counters to test tasking_rtos.fth
Mar 9, 2021
b9d25a2
More task words, added queues interrupts and an interface to write t…
May 9, 2021
73a67b6
Testing a queue and interrupt
May 9, 2021
3281ee0
Controlling a ledstrip apa201
May 9, 2021
1c42177
replaced ms@ by get-msecs
May 10, 2021
22d904e
Jos: Added ICACHE_FLASH_ATTR to avoid the error: .iram0.bss will not …
May 25, 2021
fa0bfd2
Jos: Added rtc_time_get pm_rtc_clock_cali_proc, pulse_isr_qhandler_ad…
May 25, 2021
f489987
Jos: Extensively testet on a AM2302.
May 25, 2021
24f115d
Jos: Sorry, minor correction
May 25, 2021
d57e16d
Checkpoint of esp8266-rtos and bottle-filler app
MitchBradley Oct 29, 2020
98dc4ff
Checkin interface.c and friends
MitchBradley Nov 2, 2020
4210329
Automated SDK and toolchain installation
MitchBradley Nov 3, 2020
b0f8589
Put new compiler at beginning of path, not end
MitchBradley Nov 3, 2020
21f1245
Fixed SDK PWM and automate toolchain installation
MitchBradley Nov 6, 2020
d2b609d
Fixed phase init in sdk.patch
MitchBradley Nov 6, 2020
5cb79f6
Clarified the operation of esp8266-rtos/sdk.mk
MitchBradley Nov 6, 2020
2121295
Fixed GPIO problems
MitchBradley Nov 6, 2020
8b34f87
Deleted spurious sdkconfig file
MitchBradley Nov 6, 2020
ea92246
Fixed bug in stream_connect
MitchBradley Nov 6, 2020
2a39051
HTTP Server is working
MitchBradley Nov 7, 2020
63e9fde
I2C for esp8266-rtos
MitchBradley Nov 7, 2020
00427e6
Fixed filename botch
MitchBradley Nov 8, 2020
d02fb4b
Weakened requirements for WiFi security mode.
MitchBradley Nov 8, 2020
c32167f
UDP support and build cleanup
MitchBradley Nov 10, 2020
faced5d
Revamped wifi to add access point support
MitchBradley Nov 11, 2020
076afc9
Fixed typos in wifi tests
MitchBradley Nov 11, 2020
864de26
Show filename on fl error
MitchBradley Nov 11, 2020
195a93e
Fixed bad filename in esp8266-rtos app.fth
MitchBradley Nov 11, 2020
c542af4
Added auxiliary make targets for esp8266-rtos
MitchBradley Nov 11, 2020
b4012ad
Added bootloader-flash target
MitchBradley Nov 12, 2020
40c4a49
Added app-flash target
MitchBradley Nov 12, 2020
c223525
Fix bug in vl53l0x.fth
MitchBradley Nov 13, 2020
7ed8d84
Update for latest SDK master
MitchBradley Nov 13, 2020
3c7c09b
Make sure a struct is initialized.
MitchBradley Nov 13, 2020
cdfca00
Don't parallelize make
MitchBradley Nov 13, 2020
472f4b5
Added menuconfig and sdkclean targets
MitchBradley Nov 21, 2020
d1c6a5f
added: esp_clk_cpu_freq esp_set_cpu_freq esp_deep_sleep
Jos-Ven Dec 4, 2020
c604809
Added for multitasking
Feb 9, 2021
9add8c3
Activating the 11N protocol too
Feb 9, 2021
48e7316
Added functions for pre-emptive multitasking
Mar 9, 2021
8d509ef
Contains the experimental multitasking
Mar 9, 2021
1acc435
To load tasking_rtos.fth in ROM
Mar 9, 2021
f459890
3 counters to test tasking_rtos.fth
Mar 9, 2021
b79b83a
More task words, added queues interrupts and an interface to write t…
May 9, 2021
f62abd5
Testing a queue and interrupt
May 9, 2021
d7c23d2
Controlling a ledstrip apa201
May 9, 2021
245852c
replaced ms@ by get-msecs
May 10, 2021
02de591
Merge branch 'master' into WIP
MitchBradley Jul 24, 2021
41be558
Merge branch 'WIP' into WIP
MitchBradley Jul 24, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
riscv-gd32vf103: add GD32VF103 target
This adds a very basic support for a MCU with STM32-compatible peripherals
and a 32-bit RISC-V core. Loosely based on based on arm-stm32f2013. The
peripheral driver library has a somewhat different interface though.

Tested by blinking a led on a Polos Alef R1 board, though my friends and
family didn't appreciate it nearly as much as I did.
  • Loading branch information
lkundrak authored and MitchBradley committed May 30, 2020
commit 6af178823db1f227b02e174d6f51dfb545bb63c0
65 changes: 65 additions & 0 deletions build/riscv-gd32vf103/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Builds CForth for GD32VF103, for example "Polos Alef" boards

# You need the GD32VF103 Firmware Library; see below for the URL

# You also need the riscv-nuclei-elf- version of the gcc toolchain.
# I got it from https://github.com/riscv-mcu/riscv-gnu-toolchain/releases
# Its bin/ subdirectory must be in the search path

TOPDIR = ../..

MYNAME = riscv-gd32vf103

CONFIG += -DBITS32 -DT16

default: app.elf app.bin app.nm app.dump

CROSS ?= $(GD32V_TOOLCHAIN)/bin/riscv-nuclei-elf-
CPU_VARIANT ?= -march=rv32imac -mabi=ilp32 -mcmodel=medlow

GD32V_TOOLCHAIN_PARENT_PATH = $(TOPDIR)/..
GD32V_TOOLCHAIN ?= $(GD32V_TOOLCHAIN_PARENT_PATH)/rv_linux_bare_$(GD32V_TOOLCHAIN_VERSION)

GD32V_TOOLCHAIN_VERSION ?= 1908312208
GD32V_TOOLCHAIN_ARCHIVE = rv_linux_bare_$(GD32V_TOOLCHAIN_VERSION).tar.bz2
GD32V_TOOLCHAIN_URL = https://github.com/riscv-mcu/riscv-gnu-toolchain/releases/download/v9.2RC/$(GD32V_TOOLCHAIN_ARCHIVE)

GD32V_LIB_PARENT_PATH = $(TOPDIR)/..
GD32V_LIB ?= $(GD32V_LIB_PARENT_PATH)/GD32VF103_Firmware_Library-$(GD32V_LIB_VERSION)

GD32V_LIB_VERSION ?= 12b61d1bf29afbee8ec4eee81cdbf1bd9f89470a
GD32V_LIB_ARCHIVE = GD32VF103_Firmware_Library-$(GD32V_LIB_VERSION).zip
GD32V_LIB_URL = https://github.com/riscv-mcu/GD32VF103_Firmware_Library/archive/$(GD32V_LIB_VERSION)/$(GD32V_LIB_ARCHIVE)

$(GD32V_LIB):
@echo Getting GD32VF103_Firmware_Library
(cd $(GD32V_LIB_PARENT_PATH) \
&& wget $(GD32V_LIB_URL) \
&& echo Unpacking GD32VF103_Firmware_Library \
&& unzip -q $(GD32V_LIB_ARCHIVE) \
&& rm $(GD32V_LIB_ARCHIVE) \
)

$(GD32V_TOOLCHAIN):
@echo Getting riscv-gnu-toolchain
(cd $(GD32V_TOOLCHAIN_PARENT_PATH) \
&& wget $(GD32V_TOOLCHAIN_URL) \
&& echo Unpacking riscv-gnu-toolchain \
&& tar xjf $(GD32V_TOOLCHAIN_ARCHIVE) \
&& rm $(GD32V_TOOLCHAIN_ARCHIVE) \
)

$(GD32V_TOOLCHAIN)/install-tools/macro_list: $(GD32V_TOOLCHAIN) $(GD32V_LIB)
include $(GD32V_TOOLCHAIN)/install-tools/macro_list

# The recipe for DFU flashing follows

# The device needs to enter the DFU mode first, by starting with BOOT0=1
# (typically a button on a board).

DFU_UTIL = dfu-util

flash: app.bin
$(DFU_UTIL) -d 28e9:0189 -a 0 -s 0x8000000:mass-erase:force:leave -D $<

include $(TOPDIR)/src/app/$(MYNAME)/targets.mk
36 changes: 36 additions & 0 deletions src/app/riscv-gd32vf103/app.fth
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
\ Load file for application-specific Forth extensions

: bitset ( mask adr -- ) tuck l@ or swap l! ;
: bitclr ( mask adr -- ) tuck l@ swap invert and swap l! ;

0 constant gpioa
1 constant gpiob
2 constant gpioc
3 constant gpiod
4 constant gpioe

\ GPIO modes. This encoding matches the GD32VF103 Firmware Library
$00 constant ain

$10 constant out_pp
$14 constant out_od

$18 constant af_pp
$1c constant af_od

$04 constant in_floating
$28 constant in_pulldown
$48 constant in_pullup

0 value led-gpio
: init-led ( -- )
out_pp #13 gpioc gpio-open to led-gpio
;
: led-on ( -- ) led-gpio gpio-set ;
: led-off ( -- ) led-gpio gpio-clr ;

\ Replace 'quit' to make CForth auto-run some application code
\ instead of just going interactive.
: app ." CForth (GD32VF103)" cr hex quit ;

" app.dic" save
11 changes: 11 additions & 0 deletions src/app/riscv-gd32vf103/targets.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# APPPATH is the path to the application code, i.e. this directory
APPPATH=$(TOPDIR)/src/app/$(MYNAME)

# APPLOADFILE is the top-level "Forth load file" for the application code.
APPLOADFILE = app.fth

# APPSRCS is a list of Forth source files that the application uses,
# i.e. the list of files that APPLOADFILE floads. It's for dependency checking.
APPSRCS = $(wildcard $(APPPATH)/*.fth)

include $(TOPDIR)/src/platform/$(MYNAME)/targets.mk
9 changes: 9 additions & 0 deletions src/cpu/riscv/compiler.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# allow override of default cross location
CROSS ?= riscv64-linux-gnu-
TCC=$(CROSS)gcc
TLD=$(CROSS)ld
TOBJDUMP=$(CROSS)objdump
TOBJCOPY=$(CROSS)objcopy

TCFLAGS += $(CPU_VARIANT)
TSFLAGS += $(CPU_VARIANT)
49 changes: 49 additions & 0 deletions src/platform/riscv-gd32vf103/consoleio.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Character I/O stubs

#include "gd32vf103_libopt.h"

uint32_t consoleUart;

void raw_putchar(char ch)
{
usart_data_transmit(consoleUart, ch);
while (usart_flag_get(consoleUart, USART_FLAG_TBE) == RESET);
}

int kbhit() {
return usart_flag_get(consoleUart, USART_FLAG_RBNE);
}

int getkey()
{
while (!kbhit());
return usart_data_receive(consoleUart);
}

void init_io()
{
consoleUart = USART0;

rcu_periph_clock_enable(RCU_GPIOA);
rcu_periph_clock_enable(RCU_USART0);

gpio_init(GPIOA, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_9);
gpio_init(GPIOA, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, GPIO_PIN_10);

usart_deinit(consoleUart);
usart_baudrate_set(consoleUart, 115200U);
usart_word_length_set(consoleUart, USART_WL_8BIT);
usart_stop_bit_set(consoleUart, USART_STB_1BIT);
usart_parity_config(consoleUart, USART_PM_NONE);
usart_hardware_flow_rts_config(consoleUart, USART_RTS_DISABLE);
usart_hardware_flow_cts_config(consoleUart, USART_CTS_DISABLE);
usart_receive_config(consoleUart, USART_RECEIVE_ENABLE);
usart_transmit_config(consoleUart, USART_TRANSMIT_ENABLE);
usart_enable(consoleUart);
}

// These would drag in obsecenely large "impure_data" symbol from the libc
void exit(int status) { while(1); }
void atexit() {}
void handle_nmi() {}
void handle_trap() {}
22 changes: 22 additions & 0 deletions src/platform/riscv-gd32vf103/extend.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Edit this file to include C routines that can be called as Forth words.
// See "ccalls" below.

#include "forth.h"
#include "systick.h"

// Prototypes

void gpio_open();
void gpio_set();
void gpio_clr();
void gpio_write();
void gpio_read();

cell ((* const ccalls[])()) = {
C(delay_1ms) //c ms { i.nmsecs -- }
C(gpio_open) //c gpio-open { i.mode i.pin i.port -- i.portpin }
C(gpio_set) //c gpio-set { i.portpin -- }
C(gpio_clr) //c gpio-clr { i.portpin -- }
C(gpio_write) //c gpio-pin! { i.value i.portpin -- }
C(gpio_read) //c gpio-pin@ { i.portpin -- i.value }
};
62 changes: 62 additions & 0 deletions src/platform/riscv-gd32vf103/gpio.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#include "gd32vf103_libopt.h"
#include "systick.h"

rcu_periph_enum gpio_clocks[] = {
RCU_GPIOA,
RCU_GPIOB,
RCU_GPIOC,
RCU_GPIOD,
RCU_GPIOE,
};

uint32_t gpio_ports[] = {
GPIOA,
GPIOB,
GPIOC,
GPIOD,
GPIOE,
};

int gpio_open(unsigned int portno, unsigned int pin, int mode)
{
if (portno >= sizeof(gpio_ports) / sizeof(gpio_ports[0]))
return 0;

uint32_t portp = gpio_ports[portno];

if (pin > 15)
return 0;

rcu_periph_clock_enable(gpio_clocks[portno]);
gpio_init(gpio_ports[portno], mode, GPIO_OSPEED_50MHZ, 1 << pin);

return (int)portp + pin;
}

void gpio_set(int portpin)
{
uint32_t port = (uint32_t)(portpin & ~0x0f);
int pin = portpin & 0x0f;
gpio_bit_set(port, 1 << pin);
}

void gpio_clr(int portpin)
{
uint32_t port = (uint32_t)(portpin & ~0x0f);
int pin = portpin & 0x0f;
gpio_bit_reset(port, 1 << pin);
}

void gpio_write(int portpin, int value)
{
uint32_t port = (uint32_t)(portpin & ~0x0f);
int pin = portpin & 0x0f;
gpio_bit_write(port, 1 << pin, !!value);
}

int gpio_read(int portpin)
{
uint32_t port = (uint32_t)(portpin & ~0x0f);
int pin = portpin & 0x0f;
return gpio_input_bit_get(port, 1 << pin) == RESET ? 0 : -1;
}
120 changes: 120 additions & 0 deletions src/platform/riscv-gd32vf103/targets.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
# Makefile fragment for the final target application

SRC=$(TOPDIR)/src

# Target compiler definitions
include $(SRC)/cpu/riscv/compiler.mk

DEFS += -DUSE_STDPERIPH_DRIVER
DEFS += -DHXTAL_VALUE=8000000U

DICTIONARY = ROM

ifneq ($(findstring FLOATING,$(CONFIG)),)
DICTSIZE ?= 0x3000
else
DICTSIZE ?= 0x4000
TLFLAGS += -lm
endif

CFLAGS += -m32 -march=i386

TCFLAGS += -Os

# Omit unreachable functions from output

TCFLAGS += -ffunction-sections -fdata-sections
TLFLAGS += -Wl,--gc-sections
TLFLAGS += -Wl,--defsym -Wl,__stack_size=0x80

VPATH += $(SRC)/platform/$(MYNAME)
VPATH += $(SRC)/lib
VPATH += $(SRC)/cforth
VPATH += $(GD32V_LIB)/Firmware/GD32VF103_standard_peripheral/Source
VPATH += $(GD32V_LIB)/Firmware/GD32VF103_standard_peripheral
VPATH += $(GD32V_LIB)/Firmware/RISCV/stubs
VPATH += $(GD32V_LIB)/Firmware/RISCV/drivers
VPATH += $(GD32V_LIB)/Firmware/RISCV/env_Eclipse
VPATH += $(GD32V_LIB)/Template

# This directory, including board information
INCS += -I$(SRC)/platform/$(MYNAME)

INCS += -I$(GD32V_LIB)/Firmware/GD32VF103_standard_peripheral/Include
INCS += -I$(GD32V_LIB)/Firmware/GD32VF103_standard_peripheral
INCS += -I$(GD32V_LIB)/Firmware/RISCV/drivers
INCS += -I$(GD32V_LIB)/Template

include $(SRC)/common.mk
include $(SRC)/cforth/targets.mk

# Platform-specific object files for low-level startup and platform I/O

PLAT_OBJS += tsystem_gd32vf103.o
PLAT_OBJS += tgd32vf103_usart.o
PLAT_OBJS += tgd32vf103_rcu.o
PLAT_OBJS += tgd32vf103_gpio.o
PLAT_OBJS += tsystick.o
PLAT_OBJS += twrite.o

PLAT_OBJS += tn200_func.o
PLAT_OBJS += tstart.o
PLAT_OBJS += tentry.o
PLAT_OBJS += thandlers.o
PLAT_OBJS += tinit.o

PLAT_OBJS += ttmain.o
PLAT_OBJS += mallocembed.o
PLAT_OBJS += tconsoleio.o
PLAT_OBJS += tgpio.o

ttmain.o: vars.h

# EXTEND_OBJS ?= ti2c.o

PLAT_OBJS += $(EXTEND_OBJS)

# Object files for the Forth system and application-specific extensions

FORTH_OBJS = tembed.o textend.o

# Recipe for linking the final image

# 16k Flash, 6k RAM -- too small
#LDSCRIPT = $(GD32V_LIB)/Firmware/RISCV/env_Eclipse/GD32VF103x4.lds
# 32k Flash, 10k RAM -- too small
#LDSCRIPT = $(GD32V_LIB)/Firmware/RISCV/env_Eclipse/GD32VF103x6.lds
# 64k Flash, 20k RAM -- Sipeed Longan Nano Lite
#LDSCRIPT = $(GD32V_LIB)/Firmware/RISCV/env_Eclipse/GD32VF103x8.lds
# 128k Flash, 32k RAM -- GD32VF103V-EVAL, Sipeed Longan Nano,
# Wio Lite RISC-V, Polos Alef
LDSCRIPT = $(GD32V_LIB)/Firmware/RISCV/env_Eclipse/GD32VF103xB.lds

LDCMD := $(TCC) $(CPU_VARIANT) $(TLFLAGS) \
-T$(LDSCRIPT) $(PLAT_OBJS) $(FORTH_OBJS) \
-nostartfiles -specs=nosys.specs

app.elf: $(PLAT_OBJS) $(FORTH_OBJS)
@echo Linking $@ ...
$(LDCMD) -o $@


# This rule extracts the executable bits from an ELF file, yielding raw binary.

%.img: %.elf
@$(TOBJCOPY) -O binary $< $@
date "+%F %H:%M" >>$@
@ls -l $@

# Override the default .dump rule to include the interrupt vector table

%.dump: %.elf
@$(TOBJDUMP) -s -j .init $< >$@
@$(TOBJDUMP) --disassemble $< >>$@

# This rule builds a date stamp object that you can include in the image
# if you wish.

EXTRA_CLEAN += *.bin *.elf *.dump *.nm *.img date.c $(FORTH_OBJS) $(PLAT_OBJS)

include $(SRC)/cforth/embed/targets.mk
13 changes: 13 additions & 0 deletions src/platform/riscv-gd32vf103/tmain.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Top-level routine for starting Forth

#include "forth.h"
#include "compiler.h"

int main()
{
cell *up;
init_io(0, (char **)0, (cell *)up); // Perform platform-specific initialization
up = (void *)init_forth();
execute_word("app", up); // Call the top-level application word
while(1);
}