Logo
Running grblHAL + CNCjs on UDOO Neo (i.MX 6SoloX) via Shared-Memory IPC

Running grblHAL + CNCjs on UDOO Neo (i.MX 6SoloX) via Shared-Memory IPC

Robby roboter @robby.roboter
Robby roboter @robby.roboter

The UDOO Neo is built around an unusual SoC: the NXP i.MX 6SoloX (MCIMX6X), which pairs an ARM Cortex-A9 application processor (running Ubuntu Linux) with an ARM Cortex-M4 microcontroller core on the exact same silicon die.

In a typical DIY CNC setup, you need two separate boards—a Raspberry Pi running CNCjs and an Arduino/STM32 running Grbl connected over USB-Serial. On the UDOO Neo, both halves live inside one chip and can talk directly through a shared physical DDR memory window—no USB-UART cable, no baud-rate bottleneck, and hard real-time step pulses isolated on the Cortex-M4.

This tutorial documents the exact software versions, installs, pitfalls, and code changes made across two projects (grblHAL and cncjs) to make the whole stack boot automatically and run natively on the UDOO Neo.


1. The NXP i.MX 6SoloX & Shared-Memory Window

Unlike dual-core symmetric CPUs (where Linux schedules threads across identical cores), the i.MX 6SoloX is an Asymmetric Multiprocessing (AMP) chip:

Core Architecture Role in This Project Memory Map
Cortex-A9 ARMv7-A Ubuntu 18.04 Linux, Node.js, CNCjs (:8080), grbl_bridge Main DDR (1 GB total)
Cortex-M4 ARMv7E-M (227 MHz, FPU) Bare-metal grblHAL 1.1f, stepper ISRs, CNC Shield GPIO 32 KB TCML (0x1FFF8000), 32 KB TCMU (0x20000000), 7 MB DDR (0x84000000)
Shared Window Uncached DDR Carveout Lock-free A9 ↔ M4 ring buffers (rx_buf + tx_buf) 0x84700000 (8 KB mapped)

Memory Layout (shm_stream.h)

The Linux kernel reserves 0x84000000–0x84FFFFFF (16 MB, no-map) for the Cortex-M4. Our firmware places code/vectors in the first 7 MB (0x84000000) and reserves 0x84700000 for a shared struct (grbl_shm_t) with separate single-producer / single-consumer ring-buffer indices:

#define GRBL_SHM_PHYS_ADDR 0x84700000u
#define GRBL_SHM_MAGIC     0x4752424Cu /* "GRBL" */
#define GRBL_SHM_RX_SIZE   2048u      /* Must be power of 2 */
#define GRBL_SHM_TX_SIZE   4096u      /* Must be power of 2 */

typedef struct {
    volatile uint32_t magic;
    volatile uint32_t a9_to_m4_wr;
    volatile uint32_t a9_to_m4_rd;
    volatile uint32_t m4_to_a9_wr;
    volatile uint32_t m4_to_a9_rd;
    uint8_t rx_buf[GRBL_SHM_RX_SIZE];
    uint8_t tx_buf[GRBL_SHM_TX_SIZE];
} grbl_shm_t;
  • A9 → M4 (rx_buf): grbl_bridge writes incoming G-code and realtime bytes (?, !, ~), calls __sync_synchronize(), and increments a9_to_m4_wr. M4 reads from rx_buf, issues __DMB(), and increments a9_to_m4_rd.
  • M4 → A9 (tx_buf): M4 writes <Idle|...>, ok, and [LED:ON] replies, issues __DMB(), and increments m4_to_a9_wr. grbl_bridge drains tx_buf to stdout.

2. Software Versions & Prerequisites

Tested directly on UDOO Neo Extended:

Component Verified Version Notes
OS Ubuntu 18.04.3 LTS (Bionic Beaver, armv7l) glibc 2.27 (ldd 2.27-3ubuntu1)
Kernel 4.1.15-g23c6c7b4d23a (linux-udooneo) Reserves M4 DDR carveout
M4 Cross-Compiler arm-none-eabi-gcc 6.3.1 20170620 (15:6.3.1+svn253039-1build1) Installed on-board
Host C Compiler gcc 7.4.0 (Ubuntu/Linaro 7.4.0-1ubuntu1~18.04.1) Compiles grbl_bridge & node-gyp addons
M4 Uploader udooneo-m4uploader v2.2.0 Loads firmware to 0x84000000
Node.js / npm v16.20.2 (linux-armv7l) / npm 8.19.4 Important: Node 18+ requires glibc >= 2.28
grblHAL 1.1f (branch udoo-neo-m4) Custom drivers/udoo_neo/ HAL driver
CNCjs 1.13.0 (branch udoo-neo-m4) Custom UdooNeoBridge (/dev/udoo-neo-m4)

Step 1: Install Build Tools & Node.js v16.20.2 on UDOO Neo

Apt Tip for UDOO Neo: If apt update fails on dead repository-test.udoo.org entries, move /etc/apt/sources.list.d/udoo.list aside first (sudo mkdir -p /root/apt-disabled && sudo mv /etc/apt/sources.list.d/udoo.list /root/apt-disabled/). Also hold xserver-xorg-core (sudo apt-mark hold xserver-xorg-core) before running apt upgrade so Ubuntu does not break the Vivante Xorg ABI.

Install the C/M4 toolchain and Node.js v16.20.2 (linux-armv7l):

sudo apt update
sudo apt install -y gcc g++ make python3 git gcc-arm-none-eabi binutils-arm-none-eabi

curl -fL -o /tmp/node.tar.xz https://nodejs.org/dist/v16.20.2/node-v16.20.2-linux-armv7l.tar.xz
sudo tar -C /usr/local --strip-components=1 -xf /tmp/node.tar.xz
rm -f /tmp/node.tar.xz

node -v   # v16.20.2
npm -v    # 8.19.4

3. Part 1 — grblHAL Driver & Shared-Memory Bridge (udoo-neo-m4)

All M4 firmware and bridge code lives in projects/grblHAL/drivers/udoo_neo/ on branch udoo-neo-m4:

Key Changes Implemented

  1. Linker & Startup (linker.ld, startup.c):

    • Places .vectors and .text at 0x84000000, time-critical stepper ISRs (.tcm_code) in zero-wait-state TCML (0x1FFF8000), and .data/.bss in TCMU (0x20000000).
    • Writes 0x000001FF to 0xBFF0FFF4 in Reset_Handler so udooneo-m4uploader detects M4 boot immediately.
    • Sets SCB->VTOR = (uint32_t)vector_table; (critical: without this, SysTick jumps to 0x00000000 instead of 0x84000000).
    • Enables the Cortex-M4 FPU (SCB->CPACR |= (0xFu << 20)).
  2. Hardware Driver (driver.h, driver.c, my_machine.h):

    • Maps a Protoneer Arduino CNC Shield v3 directly to UDOO Neo M4 GPIO4 / GPIO5 pins (X/Y/Z STEP, X/Y/Z DIR, EN, X/Y/Z LIMIT, SPINDLE_EN, and Pin 13 GPIO4_IO06 LED).
    • Avoids GPT completely: On i.MX 6SoloX, Linux uses GPT as its system timer during boot. Touching GPT->CR from M4 hangs Linux right after the Tux splash! Instead, our driver uses:
      • SysTick (227000 cycles = 1 ms) for get_elapsed_ticks(), get_micros(), and M4_STOP_FLAG (0xBFF0FFFF) so udooneo-m4uploader can stop/reflash M4 live.
      • EPIT1 (24 MHz OSC) for step rate timing.
      • EPIT2 (EPIT2_IRQn = 57, 24 MHz OSC) for step pulse off-time.
    • Realtime Command Handling: Since hal.stream is assigned directly (not via stream_connect()), driver_init() sets enqueue_realtime_command = protocol_enqueue_realtime_command; and shm_read() passes each incoming byte through it so ?, !, ~, and 0x18 work.
    • HAL Self-Test Capability: Sets hal.driver_cap.step_pulse_delay = On; so grblHAL boots cleanly into Idle instead of ALARM:16.
    • Custom $LED Command: Registers $LED=1|ON, $LED=0|OFF, and $LED (toggle) via system_register_commands() to drive the built-in orange LED (GPIO4_IO06).
  3. Non-Sudo Userspace Bridge (grbl_bridge.c):

    • Maps /dev/mem at 0x84700000 with O_RDWR | O_SYNC and bridges stdin/stdout (or --listen <port>) to the shared ring buffers.
    • Installed as setuid-root (root:dialout, mode 4750) at /usr/local/bin/grbl_bridge so user udooer (in group dialout) can run cncjs without sudo.

Build, Flash & Test M4

cd ~/projects/grblHAL/drivers/udoo_neo
make build
sudo make install-bridge   # installs /usr/local/bin/grbl_bridge (4750 root:dialout)
sudo make upload           # flashes out/grblhal.bin with 45s timeout guard

Verify M4 directly from the shell:

(printf '?'; sleep 0.3; printf '$LED=1\n'; sleep 0.3) | timeout -k 2 3 /usr/local/bin/grbl_bridge

Expected output:

Connected to grblHAL M4 shared-memory stream @ 0x84700000
<Idle|MPos:0.000,0.000,0.000|Bf:100,2047|F:0|Pn:XYZ|Ov:100,100,100|A:|Sc:>
[LED:ON]
ok

4. Part 2 — cncjs Integration (udoo-neo-m4)

On the udoo-neo-m4 branch of [email protected]:

  • src/server/lib/UdooNeoBridge.js: Implements a SerialPort-compatible stream wrapper (EventEmitter with open(), write(), close()) for virtual port /dev/udoo-neo-m4. It spawns /usr/local/bin/grbl_bridge directly (checking isSetuidRoot) and also supports remote TCP testing via UDOO_NEO_HOST.
  • src/server/lib/SerialConnection.js: Instantiates UdooNeoBridge when this.settings.path === '/dev/udoo-neo-m4'.
  • src/server/services/cncengine/CNCEngine.js: Prepends /dev/udoo-neo-m4 to the port list returned to the UI whenever grbl_bridge is present.

Building & Installing on the Board

Because @serialport/[email protected]’s prebuilt armv7 binary targets GLIBC_2.28 while Ubuntu 18.04 uses GLIBC_2.27, rebuild the native addon once on the UDOO Neo:

cd ~/projects/cncjs/node_modules/@serialport/bindings-cpp
node /usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js rebuild

5. Auto-Start at Boot & LED Macros

  1. Auto-load M4 firmware on boot:
sudo cp ~/projects/grblHAL/drivers/udoo_neo/out/grblhal.bin /var/opt/m4/m4last.fw
# Ensure /boot/uEnv.txt has: m4_enabled=true
  1. Install & enable cncjs.service on port 8080:
sudo cp ~/projects/grblHAL/drivers/udoo_neo/cncjs.service /etc/systemd/system/cncjs.service
sudo systemctl daemon-reload
sudo systemctl enable --now cncjs.service
  1. Add LED On / LED Off Macros in ~/.cncrc (or via the CNCjs Macro widget):
    • LED On → $LED=1
    • LED Off → $LED=0

Open http://<udoo-neo-ip>:8080, select Grbl and port /dev/udoo-neo-m4, and you have a self-contained single-board CNC controller running both Linux + CNCjs and real-time bare-metal grblHAL on one chip.

Comments

Join the conversation powered by GitHub Discussions.

Discussions on GitHub
Loading discussion...