From 7755ec9fb8a4e9d317369ee9e05a727f72dfe2f8 Mon Sep 17 00:00:00 2001 From: Josh Chester Date: Sun, 6 Sep 2026 18:03:36 -0500 Subject: [PATCH] Fix BCORNE firmware build for vial-qmk on modern Python. Include m57.c for RGB matrix linking, add Python 3.14 math patch and platform fallback, and keep brightness step in info.json only. --- corne/firmware/config.h | 1 - corne/firmware/patches/vial-qmk-math-py.patch | 15 ++++++++ corne/firmware/post_rules.mk | 3 ++ corne/firmware/readme.md | 36 +++++++++++++++---- corne/firmware/rules.mk | 1 + 5 files changed, 48 insertions(+), 8 deletions(-) create mode 100644 corne/firmware/patches/vial-qmk-math-py.patch create mode 100644 corne/firmware/post_rules.mk diff --git a/corne/firmware/config.h b/corne/firmware/config.h index 62ac9b5..a708ae9 100644 --- a/corne/firmware/config.h +++ b/corne/firmware/config.h @@ -89,7 +89,6 @@ # define WS2812_DMA_CHANNEL 5 // DMA Channel for TIMx_UP, see the respective reference manual for the appropriate values for your MCU. //# define WS2812_DMAMUX_ID STM32_DMAMUX1_TIM2_UP // DMAMUX configuration for TIMx_UP -- only required if your MCU has a DMAMUX peripheral, see the respective reference manual for the appropriate values for your MCU. #define RGB_MATRIX_SLEEP -#define RGB_MATRIX_VAL_STEP 1 #define WEAR_LEVELING_LOGICAL_SIZE 2048 #define WEAR_LEVELING_BACKING_SIZE (WEAR_LEVELING_LOGICAL_SIZE * 2) diff --git a/corne/firmware/patches/vial-qmk-math-py.patch b/corne/firmware/patches/vial-qmk-math-py.patch new file mode 100644 index 0000000..607ddff --- /dev/null +++ b/corne/firmware/patches/vial-qmk-math-py.patch @@ -0,0 +1,15 @@ +--- a/lib/python/qmk/math.py ++++ b/lib/python/qmk/math.py +@@ -23,8 +23,10 @@ def compute(expr): + + + def _eval(node): +- if isinstance(node, ast.Num): # +- return node.n ++ if isinstance(node, ast.Constant) and isinstance(node.value, (int, float, complex)): ++ return node.value ++ elif isinstance(node, ast.Num): # (Python <3.14) ++ return node.n + elif isinstance(node, ast.BinOp): # + return operators[type(node.op)](_eval(node.left), _eval(node.right)) + elif isinstance(node, ast.UnaryOp): # e.g., -1 diff --git a/corne/firmware/post_rules.mk b/corne/firmware/post_rules.mk new file mode 100644 index 0000000..23fd11a --- /dev/null +++ b/corne/firmware/post_rules.mk @@ -0,0 +1,3 @@ +# Fallback when qmk info parsing fails (e.g. Python 3.14+ ast.Num removal). +MCU ?= STM32F401 +PLATFORM_KEY ?= chibios diff --git a/corne/firmware/readme.md b/corne/firmware/readme.md index 875057e..c0d062f 100644 --- a/corne/firmware/readme.md +++ b/corne/firmware/readme.md @@ -5,7 +5,8 @@ Keyboard target: `sh01/m36:via` ## Prerequisites 1. Install [QMK CLI 1.2.0](https://docs.qmk.fm/#/cli) (or QMK MSYS on Windows). -2. Clone vial-qmk at the IFKB-pinned commit: +2. Use **Python 3.11 or 3.12** for the build. Python 3.14 breaks the pinned vial-qmk commit unless patched (see Troubleshooting). +3. Clone vial-qmk at the IFKB-pinned commit: ```bash git clone https://github.com/vial-kb/vial-qmk.git @@ -25,6 +26,13 @@ cp -r /path/to/kb-layouts/corne/firmware/* keyboards/sh01/m36/ The make target comes from that path: `keyboards/sh01/m36` → `sh01/m36:via`. +If you are on Python 3.14+, apply the QMK math patch from inside your vial-qmk checkout: + +```bash +cd /path/to/vial-qmk +patch -p1 < /path/to/kb-layouts/corne/firmware/patches/vial-qmk-math-py.patch +``` + ## Build ```bash @@ -47,11 +55,25 @@ After flashing, load `../corne.vil` in Vial to restore your keymap. ## RGB brightness dial -Brightness step size is controlled in `config.h`: +Brightness step size is set in `info.json` under `rgb_matrix.val_steps` (currently `1`). -```c -#define RGB_MATRIX_VAL_STEP 1 -``` +With `max_brightness: 50`, step `1` gives 51 brightness levels. Increase to `2` or `4` if the dial feels too slow. -With `max_brightness: 50` in `info.json`, step `1` gives 51 brightness levels. -Increase to `2` or `4` if the dial feels too slow. +Do not also define `RGB_MATRIX_VAL_STEP` in `config.h` — QMK warns when both are set. + +## Troubleshooting + +### `AttributeError: module 'ast' has no attribute 'Num'` + +The pinned vial-qmk commit uses `ast.Num`, which was removed in Python 3.14. Fix options: + +1. **Recommended:** build with Python 3.11 or 3.12 (`python3.12 -m venv .venv && source .venv/bin/activate && pip install qmk`). +2. **Alternative:** apply `patches/vial-qmk-math-py.patch` inside your vial-qmk checkout (see Install step above). + +### `Platform not defined` + +Usually a follow-on error from the `ast.Num` failure — QMK never parses `processor: STM32F401` from `info.json`. Fixing the Python issue should resolve this. `post_rules.mk` also provides a fallback (`PLATFORM_KEY = chibios`, `MCU = STM32F401`). + +### `RGB_MATRIX_VAL_STEP in config.h is overwriting rgb_matrix.val_steps in info.json` + +Keep the step size in **one place only** — use `val_steps` in `info.json`, not `#define RGB_MATRIX_VAL_STEP` in `config.h`. diff --git a/corne/firmware/rules.mk b/corne/firmware/rules.mk index b252b5f..706e755 100644 --- a/corne/firmware/rules.mk +++ b/corne/firmware/rules.mk @@ -24,5 +24,6 @@ SRC += rtt_viewer/SEGGER_RTT.c CUSTOM_MATRIX = lite SRC += matrix.c +SRC += m57.c # SRC += split_util_qf.c ALLOW_WARNINGS = yes