Skip to content

Commit

Permalink
Detect RISC-V build and switch to RISCV-compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
maxgerhardt committed Sep 27, 2024
1 parent 934fe15 commit bd17d78
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
21 changes: 13 additions & 8 deletions builder/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,18 +165,23 @@ def generate_uf2(target, source, env):
env = DefaultEnvironment()
platform = env.PioPlatform()
board = env.BoardConfig()
chip = board.get("build.mcu")

toolchain_tripple = "arm-none-eabi"
if chip == "rp2350-riscv":
toolchain_tripple = "riscv32-unknown-elf"

env.Replace(
__fetch_fs_size=fetch_fs_size,

AR="arm-none-eabi-ar",
AS="arm-none-eabi-as",
CC="arm-none-eabi-gcc",
CXX="arm-none-eabi-g++",
GDB="arm-none-eabi-gdb",
OBJCOPY="arm-none-eabi-objcopy",
RANLIB="arm-none-eabi-ranlib",
SIZETOOL="arm-none-eabi-size",
AR="%s-ar" % toolchain_tripple,
AS="%s-as" % toolchain_tripple,
CC="%s-gcc" % toolchain_tripple,
CXX="%s-g++" % toolchain_tripple,
GDB="%s-gdb" % toolchain_tripple,
OBJCOPY="%s-objcopy" % toolchain_tripple,
RANLIB="%s-ranlib" % toolchain_tripple,
SIZETOOL="%s-size" % toolchain_tripple,

ARFLAGS=["rc"],

Expand Down
8 changes: 7 additions & 1 deletion platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ def configure_default_packages(self, variables, targets):
# select the right one based on the build.core, disable other one.
board = variables.get("board")
board_config = self.board_config(board)
chip = variables.get("board_build.mcu", board_config.get("build.mcu"))
build_core = variables.get(
"board_build.core", board_config.get("build.core", "arduino"))
# Use the same string identifier as seen in "pio system info" and registry
Expand All @@ -117,7 +118,12 @@ def configure_default_packages(self, variables, targets):
self.packages.pop("toolchain-gccarmnoneeabi", None)
self.packages["toolchain-rp2040-earlephilhower"]["optional"] = False
# Configure toolchain download link dynamically
self.packages["toolchain-rp2040-earlephilhower"]["version"] = RaspberrypiPlatform.earle_toolchain_arm[sys_type]
# RP2350 (RISC-V)
if chip == "rp2350-riscv":
self.packages["toolchain-rp2040-earlephilhower"]["version"] = RaspberrypiPlatform.earle_toolchain_riscv[sys_type]
# RP2040, RP2350 (ARM)
else:
self.packages["toolchain-rp2040-earlephilhower"]["version"] = RaspberrypiPlatform.earle_toolchain_arm[sys_type]
else:
sys.stderr.write(
"Error! Unknown build.core value '%s'. Don't know which Arduino core package to use." % build_core)
Expand Down

0 comments on commit bd17d78

Please sign in to comment.