Skip to content

Conversation

@mkobetic
Copy link
Owner

@mkobetic mkobetic commented Jan 25, 2026

The build setup for CH32 controls the target configuration to build with config.inc parameters. This makes it difficult to change whatever is configured dynamically in CI. This PR allows overriding this with environment variables.

Summary of changes:

  • A new environment variable TARGET controls which configuration will be built (307, 305, 302 or QEM)
  • personal bits are pulled out into an .env file
  • pulled up/reconciled some of the targets and variable definitions with core Makefile (buildinfo, clean, shell, ...)
  • Added new RISC-V build step to build the 307 configuration (as well as the QEM coniguration)

See more detailed explanations inline.



YES=TRUE
NO=FALSE
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are defined in core/dev/Makefile

#.include "words/dicthelp.s"

.if WANT_QEM_BUILD
.ifdef BUILD_QEM
Copy link
Owner Author

@mkobetic mkobetic Jan 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dropped the WANT_ prefix to distinguish these from the set of config.inc parameters. They are not that anymore. I also had to swap BUILD and target ID, because 307_BUILD is not a valid symbol.

TMPPATH?=$(HOME)/ng/dev/uc/minasm
MINICOM=/opt/homebrew/bin/minicom
MINICOM=/usr/local/bin/minicom
AMSHELL=$(TMPPATH)/tools/amforth-shell.py --port $(MODEM) --speed 115200 $1
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pulled AMSHELL up to core Makefile.

ifeq ($(wildcard $(TC_DIR)),)
ifeq ($(strip $(ARDUINO)),TRUE)
BIN_STUB=$(ARDU15)/packages/WCH/tools/riscv-none-embed-gcc/8.2.0/bin/riscv-none-embed-
TC_DIR = $(ARDU15)/packages/WCH/tools/riscv-none-embed-gcc/8.2.0
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replacing BIN_STUB with TC_DIR and CROSS to match the rest.

OBJCOPY := $(BIN_STUB)objcopy
OBJDUMP := $(BIN_STUB)objdump
OBJSIZE := $(BIN_STUB)size
RANLIB := $(BIN_STUB)ranlib
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pulled up to core Makefile

ifeq ($(strip $(ASMONLY)),YES)
SRC_DIRS := .
SRCS = $(shell find $(SRC_DIRS) -name "*.S")
SRCS = $(shell find $(SRC_DIRS) -name "*.S" | sed 's|^./||')
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

find returns the filename with the directory being searched prepended. That results in USER_OBJS to look like build/./amforth.S. This later causes troubles when you're trying to match targets that do not have the intervening dot directory. I needed this when I was trying to hit core Makefile targets, which I later gave up on (for now), but this seems like a good fix to keep regardless.

$(BUILD_DIR)/$(LIB_USER)/%,$(OBJS))

INC_FLAGS := -I . -I ../.. -I $(AMFORTH)/core -I $(AMFORTH)
INC_FLAGS := -I . $(INCLUDES)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

INCLUDES is inherited from core Makefile

## Connect via AmShell
shell:
export EDITOR=emacs
$(AMSHELL) --no-error-on-output -i
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pulled up into core Makefile

$(MINICOM) -D $(MODEM) --color=on -C minicom.cap

## Update build info - run before build
info:
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duplicates buildinfo from core Makefile

$(HOME)/.cargo/bin/wlink flash $(BUILD_DIR)/$(TARGET_HEX)

## Clean - run before build
clean:
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicates clean from core Makefile.

run: cd rv/mcu/hifive1 && WANT_IGNORECASE=1 make all

- name: Build CH32
run: cd rv/mcu/ch32v307 && WANT_IGNORECASE=1 make all
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Building both 307 and QEM configurations now.

mkdir -p build

AOPTS ?= -g --warn --fatal-warnings -alms=build/amforth.lst-as
ASFLAGS := -g --warn --fatal-warnings -alms=build/amforth.lst-as
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adopting the naming convention from the CH32 Makefile.

CPPFLAGS := $(FLAGS) $(INCLUDES) -MMD -MP $(DEFINES)

LDFLAGS := $(FLAGS) -T $(LD_FILE) -nostartfiles -Xlinker -t -Xlinker --gc-sections -Xlinker --verbose --specs=nano.specs --specs=nosys.specs \
#LDFLAGS += -nostartfiles -Xlinker -t -Xlinker --gc-sections -Xlinker --verbose --specs=nano.specs --specs=nosys.specs \
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused


OBJS = $(SRCS:%=$(BUILD_DIR)/%.o)
DEPS = $(OBJS:.o=.d)
#DEPS = $(OBJS:.o=.d)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused


ifeq ($(strip $(WANT_203)),YES)
# Default target to build
TARGET ?= 307
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Picked 307 as the default target config.

# however dependencies of both targets are collected and executed, so this will run some unnecessary steps from core
# resulting in unnecessary files in build/
$(BUILD_DIR)/$(TARGET_ELF): buildinfo $(USER_OBJS) $(BUILD_DIR)/libcode.a
$(BUILD_DIR)/$(TARGET_ELF): $(USER_OBJS) $(BUILD_DIR)/libcode.a
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

buildinfo really should be prerequisite of the earlier file targets not the elf file.

SOCKSHELL=$(TMPPATH)/tools/socket-shell.py --port $(MODEM) --speed 115200 $1
QEMU_RV32 ?= qemu-system-riscv32
WLINK ?= $(HOME)/.cargo/bin/wlink
MINICOM ?= minicom
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Defaults for some of the .env parameters.

TARGET_HEX := $(TARGET_NAME).hex
TARGET_BIN := $(TARGET_NAME).bin
TARGET_MAP := $(TARGET_NAME).map
TARGET_LIST := $(TARGET_NAME).list
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved this further down, closer to where it's used.

CROSS = riscv-none-embed-
TOOLCHAIN = WCH-via-Arduino
OPENOCD = $(ARDU15)/packages/WCH/tools/openocd/1.0.0/bin/openocd
OPENCFG = $(ARDU15)/packages/WCH/tools/openocd/1.0.0/bin/wch-riscv.cfg
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving the OpenOCD stuff here since it depends on ArduinoIDE being installed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants