Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
c5b463d
bricks: Add simhub for testing embedded ports on CI.
laurensvalk Oct 14, 2025
a66cbf7
bricks/_common: Rename common makefile.
laurensvalk Oct 14, 2025
f35cf4a
bricks/simhub: Compile option for CI clock.
laurensvalk Oct 14, 2025
7361ef7
bricks/simhub: Debug locally with wall clock.
laurensvalk Oct 14, 2025
ea884c0
pbio/platform/sim_hub: Enable program stop.
laurensvalk Oct 14, 2025
28f4549
pbio/drv/bluetooth_simulation: Clean up terminal on exit.
laurensvalk Oct 14, 2025
05b6765
pbio/sys/hmi_mpy_env: Compile script with Pybricksdev.
laurensvalk Oct 15, 2025
41965e7
bricks/simhub: Fix debug build paths and mpy-cross.
laurensvalk Oct 15, 2025
129fbf6
pbio/platform/sim_hub: Don't use Linux signal for clock tick.
laurensvalk Oct 27, 2025
63f16a4
bricks/simhub: Clean up VM_HOOK.
laurensvalk Oct 27, 2025
7314162
pbio/platform: Rename main to _main on embedded.
laurensvalk Oct 28, 2025
aa5a57d
bricks/simhub: Poll Contiki.
laurensvalk Oct 28, 2025
0e2ebde
pbio/platform/virtual_hub: Use UDP to send data.
laurensvalk Oct 29, 2025
c398a65
pbio/platform/sim_hub: Use CLI args for file instead of ENV.
laurensvalk Oct 31, 2025
ed963db
bricks/simhub: Enable sys module.
laurensvalk Oct 31, 2025
f002dcc
bricks/simhub: Enable floating point.
laurensvalk Oct 31, 2025
faafa41
pbio/platform/sim_hub: Use wall clock by default.
laurensvalk Oct 31, 2025
8e9848f
bricks/simhub: Replace mpy wrapper script with Pybricksdev call.
laurensvalk Oct 31, 2025
fd165dd
tests: Use embedded virtual hub.
laurensvalk Oct 31, 2025
8a2ac99
tests/virtualhub/motor: Make drivebase tests actually run.
laurensvalk Nov 1, 2025
7360359
pbio/drv/clock_test: Fix counting clock.
laurensvalk Nov 2, 2025
92a6bb0
pbio/platform/sim_hub: Set and reset terminal settings from main.
laurensvalk Nov 2, 2025
44eea10
pbio/platform/sim_hub: Don't modify stdin on CI.
laurensvalk Nov 2, 2025
1800141
bricks/simhub: Run tests with coverage.
laurensvalk Nov 2, 2025
489769a
.github: Run new simulated hub on CI.
laurensvalk Nov 2, 2025
3f9b0a3
bricks/virtualhub: Replace with embedded simulation.
laurensvalk Nov 2, 2025
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
8 changes: 5 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,10 @@ jobs:
needs: [mpy_cross]
runs-on: ubuntu-24.04
steps:
- name: Install depedencies
run: sudo apt-get update && sudo apt-get install lcov python3-numpy --yes
- name: Install dependencies
run: sudo apt-get update && sudo apt-get install lcov pipx
- name: Install Pybricksdev
run: pipx install pybricksdev
- name: Checkout repo
uses: actions/checkout@v4
with:
Expand All @@ -166,7 +168,7 @@ jobs:
- name: Fix file permission
run: chmod +x micropython/mpy-cross/build/mpy-cross
- name: Build and test
run: COVERAGE=1 ./test-virtualhub.sh
run: ./test-virtualhub.sh
- name: Coveralls
uses: coverallsapp/github-action@v2
with:
Expand Down
44 changes: 21 additions & 23 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,27 @@
"cStandard": "c11",
"intelliSenseMode": "gcc-arm"
},
{
"name": "pbio/test",
"includePath": [
"${workspaceFolder}/lib/btstack/chipset/cc256x",
"${workspaceFolder}/lib/btstack/platform/posix",
"${workspaceFolder}/lib/btstack/src",
"${workspaceFolder}/lib/contiki-core",
"${workspaceFolder}/lib/lego",
"${workspaceFolder}/lib/lwrb/src/include",
"${workspaceFolder}/lib/pbio",
"${workspaceFolder}/lib/pbio/include",
"${workspaceFolder}/lib/pbio/platform/test",
"${workspaceFolder}/lib/pbio/test",
"${workspaceFolder}/lib/pbio/test/build",
"${workspaceFolder}/lib/tinytest"
],
"defines": [
"UNIX"
],
"cStandard": "c11"
},
{
"name": "virtualhub",
"includePath": [
Expand All @@ -352,41 +373,18 @@
"${workspaceFolder}/lib/pbio",
"${workspaceFolder}/lib/pbio/include",
"${workspaceFolder}/lib/pbio/platform/virtual_hub",
"${workspaceFolder}/micropython/ports/unix",
"${workspaceFolder}/micropython",
"${workspaceFolder}",
"/usr/include/python3.10"
],
"defines": [
"UNIX",
"MICROPY_MODULE_FROZEN_MPY",
"MICROPY_USE_READLINE=1"
],
"compilerPath": "/usr/bin/gcc",
"cStandard": "c11",
"intelliSenseMode": "gcc-x64"
},
{
"name": "pbio/test",
"includePath": [
"${workspaceFolder}/lib/btstack/chipset/cc256x",
"${workspaceFolder}/lib/btstack/platform/posix",
"${workspaceFolder}/lib/btstack/src",
"${workspaceFolder}/lib/contiki-core",
"${workspaceFolder}/lib/lego",
"${workspaceFolder}/lib/lwrb/src/include",
"${workspaceFolder}/lib/pbio",
"${workspaceFolder}/lib/pbio/include",
"${workspaceFolder}/lib/pbio/platform/test",
"${workspaceFolder}/lib/pbio/test",
"${workspaceFolder}/lib/pbio/test/build",
"${workspaceFolder}/lib/tinytest"
],
"defines": [
"UNIX"
],
"cStandard": "c11"
}
],
"version": 4
}
20 changes: 10 additions & 10 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,20 @@
"args": [],
"console": "integratedTerminal"
},
{
"name":"Virtual Hub Animation",
"type":"debugpy",
"request":"launch",
"program":"${workspaceFolder}/lib/pbio/platform/virtual_hub/animation.py",
"console":"integratedTerminal"
},
{
"name": "virtualhub",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/bricks/virtualhub/build-debug/virtualhub-micropython",
"program": "${workspaceFolder}/bricks/virtualhub/build-debug/firmware.elf",
"args": [
"${workspaceFolder}/tests/virtualhub/motor/car.py"
"${workspaceFolder}/tests/virtualhub/motor/car.py",
],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
Expand All @@ -83,14 +90,7 @@
"ignoreFailures": false
}
],
"preLaunchTask": "build virtualhub"
},
{
"name":"Virtual Hub Animation",
"type":"debugpy",
"request":"launch",
"program":"${workspaceFolder}/lib/pbio/platform/virtual_hub/animation.py",
"console":"integratedTerminal"
"preLaunchTask": "build virtualhub (debug)"
},
{
"name": "test-pbio",
Expand Down
7 changes: 5 additions & 2 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,12 @@
"detail": "Build the PrimeHub project"
},
{
"label": "build virtualhub",
"options": {
"cwd": "${workspaceFolder}/bricks/virtualhub"
},
"label": "build virtualhub (debug)",
"type": "shell",
"command": "poetry run make -C bricks/virtualhub DEBUG=1 COPT=-O0 CROSS_COMPILE= -j"
"command": "make -C ../../micropython/mpy-cross -j && poetry run make DEBUG=1 BUILD=build-debug -j",
},
{
"label": "build test-pbio",
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ virtualhub: mpy-cross
@$(MAKE) -C bricks/virtualhub CROSS_COMPILE=

clean-virtualhub: clean-mpy-cross
@$(MAKE) -C bricks/virtualhub clean CROSS_COMPILE=
@$(MAKE) -C bricks/virtualhub clean DEBUG=1
@$(MAKE) -C bricks/virtualhub clean
@$(MAKE) -C bricks/virtualhub clean BUILD=build-debug

mpy-cross:
@$(MAKE) -C micropython/mpy-cross CROSS_COMPILE=$(HOST_CROSS_COMPILE)
Expand Down
56 changes: 47 additions & 9 deletions bricks/_common/arm_none_eabi.mk → bricks/_common/common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# This file is shared by all bare-metal Arm Pybricks ports.

THIS_MAKEFILE := $(lastword $(MAKEFILE_LIST))
PBTOP := ../$(patsubst %/_common/arm_none_eabi.mk,%,$(THIS_MAKEFILE))
PBTOP := ../$(patsubst %/_common/common.mk,%,$(THIS_MAKEFILE))

# Bricks must specify the following variables in their Makefile

Expand Down Expand Up @@ -101,8 +101,6 @@ MICROPY_ROM_TEXT_COMPRESSION ?= 1
include $(TOP)/py/py.mk
include $(TOP)/extmod/extmod.mk

CROSS_COMPILE ?= arm-none-eabi-

INC += -I.
INC += -I$(TOP)
ifeq ($(PB_MCU_FAMILY),STM32)
Expand Down Expand Up @@ -155,6 +153,18 @@ OPENOCD ?= openocd
OPENOCD_CONFIG ?= openocd_stm32$(PB_MCU_SERIES_LCASE).cfg
TEXT0_ADDR ?= 0x08000000

ifeq ($(PB_MCU_FAMILY),native)
UNAME_S := $(shell uname -s)
LD = $(CC)
CFLAGS += $(INC) -Wall -Werror -Wdouble-promotion -Wfloat-conversion -std=gnu99 $(COPT) -D_GNU_SOURCE
ifeq ($(UNAME_S),Linux)
LDFLAGS += -Wl,[email protected],--cref -Wl,--gc-sections
else ifeq ($(UNAME_S),Darwin)
LDFLAGS += -Wl,-map,[email protected] -Wl,-dead_strip
endif
LIBS = -lm
else # end native, begin embedded
CROSS_COMPILE ?= arm-none-eabi-
ifeq ($(PB_MCU_FAMILY),STM32)
CFLAGS_MCU_F0 = -mthumb -mtune=cortex-m0 -mcpu=cortex-m0 -msoft-float
CFLAGS_MCU_F4 = -mthumb -mtune=cortex-m4 -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard
Expand Down Expand Up @@ -200,9 +210,14 @@ endif
# avoid doubles
CFLAGS += -fsingle-precision-constant -Wdouble-promotion

endif # end embedded, begin common

# Tune for Debugging or Optimization
ifeq ($(DEBUG), 1)
CFLAGS += -Og -ggdb
ifeq ($(COVERAGE), 1)
CFLAGS += --coverage -fprofile-arcs -ftest-coverage
LDFLAGS += --coverage
else ifeq ($(DEBUG), 1)
CFLAGS += -O0 -ggdb
else ifeq ($(DEBUG), 2)
CFLAGS += -Os -DNDEBUG -flto=auto
else
Expand All @@ -218,7 +233,7 @@ CFLAGS += -DSTM32_H='<stm32$(PB_MCU_SERIES_LCASE)xx.h>'
CFLAGS += -DSTM32_HAL_H='<stm32$(PB_MCU_SERIES_LCASE)xx_hal.h>'
endif

LIBS = "$(shell $(CC) $(CFLAGS) -print-libgcc-file-name)"
LIBS += "$(shell $(CC) $(CFLAGS) -print-libgcc-file-name)"

# Sources and libraries common to all pybricks bricks

Expand All @@ -233,13 +248,26 @@ include $(PBTOP)/bricks/_common/sources.mk
# between the top level directory and the micropython/ subdirectory.

PY_EXTRA_SRC_C = $(addprefix shared/,\
libc/string0.c \
runtime/gchelper_native.c \
runtime/interrupt_char.c \
runtime/pyexec.c \
runtime/stdout_helpers.c \
)

ifeq ($(PB_MCU_FAMILY),native)
PY_EXTRA_SRC_C += $(addprefix shared/,\
runtime/gchelper_generic.c \
runtime/sys_stdio_mphal.c \
)
PY_EXTRA_SRC_C += $(addprefix bricks/virtualhub/,\
pbio_os_hook.c \
)
else
PY_EXTRA_SRC_C += $(addprefix shared/,\
libc/string0.c \
runtime/gchelper_native.c \
runtime/sys_stdio_mphal.c \
)
endif

ifneq ($(PBIO_PLATFORM),move_hub)
# to avoid adding unused root pointers
Expand All @@ -262,7 +290,9 @@ PY_EXTRA_SRC_C += $(addprefix bricks/_common/,\
endif

# Not all MCUs support thumb2 instructions.
ifeq ($(PB_MCU_SERIES),$(filter $(PB_MCU_SERIES),AT91SAM7 F0 TIAM1808))
ifeq ($(PB_MCU_FAMILY),native)
SRC_S +=
else ifeq ($(PB_MCU_SERIES),$(filter $(PB_MCU_SERIES),AT91SAM7 F0 TIAM1808))
SRC_S += shared/runtime/gchelper_thumb1.s
else
SRC_S += shared/runtime/gchelper_thumb2.s
Expand Down Expand Up @@ -561,8 +591,12 @@ CFLAGS += -DMICROPY_MODULE_FROZEN_MPY
MPY_TOOL_FLAGS += -mlongint-impl none
endif

ifneq ($(PB_MCU_FAMILY),native)
# Main firmware build targets
TARGETS := $(BUILD)/firmware.zip
else
TARGETS := $(BUILD)/firmware.elf
endif
Comment on lines +594 to +599
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
ifneq ($(PB_MCU_FAMILY),native)
# Main firmware build targets
TARGETS := $(BUILD)/firmware.zip
else
TARGETS := $(BUILD)/firmware.elf
endif
ifeq ($(PB_MCU_FAMILY),native)
TARGETS := $(BUILD)/firmware.elf
else
TARGETS := $(BUILD)/firmware.zip
endif

avoiding negation is easier on the brain


all: $(TARGETS)

Expand Down Expand Up @@ -673,4 +707,8 @@ deploy-openocd: $(BUILD)/firmware-base.bin
$(ECHO) "Writing $< to the board via ST-LINK using OpenOCD"
$(Q)$(OPENOCD) -f $(OPENOCD_CONFIG) -c "stm_flash $< $(TEXT0_ADDR)"

# Run emulation build on a POSIX system using normal stdio
run: $(BUILD)/firmware.elf
@$(BUILD)/firmware.elf
Copy link
Member

Choose a reason for hiding this comment

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

Would also be nice to have one more recipe to give this a proper executable name, like pybricks-micropython-virtual-hub.


include $(TOP)/py/mkrules.mk
6 changes: 6 additions & 0 deletions bricks/_common/mpconfigport.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,14 @@ typedef long mp_off_t;
#define MICROPY_END_ATOMIC_SECTION(state) (void)(state)
#endif

// Optional extra code to run before MicroPython drives the event loop.
#ifndef PYBRICKS_VM_HOOK_LOOP_EXTRA
#define PYBRICKS_VM_HOOK_LOOP_EXTRA
#endif

#define MICROPY_VM_HOOK_LOOP \
do { \
PYBRICKS_VM_HOOK_LOOP_EXTRA \
extern bool pbio_os_run_processes_once(void); \
pbio_os_run_processes_once(); \
} while (0);
Expand Down
1 change: 1 addition & 0 deletions bricks/_common/sources.mk
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ PBIO_SRC_C = $(addprefix lib/pbio/,\
sys/battery.c \
sys/command.c \
sys/core.c \
sys/hmi_env_mpy.c \
sys/hmi_lcd.c \
sys/hmi_pup.c \
sys/hmi_none.c \
Expand Down
2 changes: 1 addition & 1 deletion bricks/cityhub/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ PB_LIB_STM32_HAL = 1
PB_LIB_BLE5STACK = 1
PB_FROZEN_MODULES = 1

include ../_common/arm_none_eabi.mk
include ../_common/common.mk
2 changes: 1 addition & 1 deletion bricks/essentialhub/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ DFU_VID = 0x0694
DFU_PID = 0x000C
PB_FROZEN_MODULES = 1

include ../_common/arm_none_eabi.mk
include ../_common/common.mk
2 changes: 1 addition & 1 deletion bricks/ev3/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ PB_MCU_FAMILY = TIAM1808

PB_LIB_UMM_MALLOC = 1

include ../_common/arm_none_eabi.mk
include ../_common/common.mk
2 changes: 1 addition & 1 deletion bricks/movehub/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ PB_LIB_BLUENRG = 1
PB_FROZEN_MODULES = 0
MICROPY_ROM_TEXT_COMPRESSION = 0 # Needed for PYBRICKS_OPT_TERSE_ERR

include ../_common/arm_none_eabi.mk
include ../_common/common.mk
2 changes: 1 addition & 1 deletion bricks/nxt/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
PBIO_PLATFORM = nxt
PB_MCU_FAMILY = AT91SAM7

include ../_common/arm_none_eabi.mk
include ../_common/common.mk
2 changes: 1 addition & 1 deletion bricks/primehub/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ DFU_VID = 0x0694
DFU_PID = 0x0008
PB_FROZEN_MODULES = 1

include ../_common/arm_none_eabi.mk
include ../_common/common.mk
2 changes: 1 addition & 1 deletion bricks/technichub/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ PB_LIB_BLE5STACK = 1
PB_LIB_LSM6DS3TR_C = 1
PB_FROZEN_MODULES = 1

include ../_common/arm_none_eabi.mk
include ../_common/common.mk
1 change: 1 addition & 0 deletions bricks/virtualhub/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
debug/
Loading
Loading