Dual-Core Example (MAX78000 ARM + RISC-V)
Overview
This example demonstrates the no-OS coprocessor API and inter-core communication (IPC) framework for the MAX78000's dual-core architecture:
CPU0: ARM Cortex-M4F (primary core) -- boots, manages lifecycle, publishes callbacks
CPU1: RISC-V RV32 IMC (coprocessor) -- performs work, signals completion via doorbell
Architecture
┌───────────────────────────────────────────────────────────────────┐
│ MAX78000 SoC (Unified 0x10000000–0x1007FFFF Flash) │
├───────────────────────────────────────────────────────────────────┤
│ CPU0 (ARM) │ Shared Resources │ CPU1 (RISC-V) │
│ ┌─────────────┐ │ ┌─────────────────────────┐ │ ┌──────────┐ │
│ │ Cortex-M4F │ │ │ SEMA (0x4003E000) │ │ │ RV32 │ │
│ │ │ │ │ ├─ Semaphores │ │ │ │ │
│ │ - Boots │ │ │ ├─ Doorbells (irq0/1) │ │ │ - Waits │ │
│ │ - Publishes │ │ │ └─ Mailboxes │ │ │ - Reads │ │
│ │ callback │──┼──┤ ┌──────────────────────┐│ ├──┤ - Echoes │ │
│ │ - Sleeps │ │ │ │ IPC Shared Memory ││ │ │ - Notif. │ │
│ │ on WFI │ │ │ │ (SRAM2 0x20011000) ││ │ │ │ │
│ └─────────────┘ │ │ └──────────────────────┘│ │ └──────────┘ │
│ │ └─────────────────────────┘ │ │
└───────────────────────────────────────────────────────────────────┘
Key Files
dual_core_example.c-- ARM side: initialization, boot, callback publishing, wait loopdual_core_example_riscv.c-- RISC-V side: boot, IPC table read, doorbell notifydual_core_example.h-- ARM example header
Usage
Configuration
Enable the dual-core example (run from the no-OS repository root):
cmake --preset max78000fthr \
-DPROJECT_DEFCONFIG=max78000/dual_core.conf
cmake --build out/build/max78000fthr
Or manually enable the options in any defconfig:
CONFIG_CAPI=y
CONFIG_CAPI_ALLOC=y
CONFIG_CAPI_MAILBOX=y
CONFIG_CAPI_COPROCESSOR=y
CONFIG_MAX78000_DUAL_CORE_EXAMPLE=y
Expected Output (ARM Console)
See the Smoke Test section below for the full, verified console output.
Flow
Initialization Phase
ARM boots (main.c -> common_data.c -> dual_core_example.c), selects the 100 MHz IPO system clock
ARM initializes SEMA -> enables hardware semaphores and doorbells
ARM initializes coprocessor -> allocates CPU1 descriptor
ARM boots RISC-V -> clears
FCR->urvctrl, setsFCR->urvbootaddr = &_riscv_boot(a flash address), pulses CPU1 reset. The RISC-V image is already resident in flash (embedded in the ARM ELF); it runs in place -- no copy to SRAM.RISC-V starts executing -> the RISC-V startup sets mtvec/gp/sp, copies .data / zeroes .bss (into SRAM2);
main()enables the RISC-V instruction cache, then reads the IPC table and spins until ready
IPC Handshake
/* ARM side publishes callback (fixed-address pointer to SRAM2 0x20011000) */
g_ipc_table->magic = 0; // invalidate
g_ipc_table->fn[0] = (uint32_t)callback_fn; // write address
maxim_ipc_table_publish(g_ipc_table);
/* CPU1 acquires the slots before reading. */
while (!maxim_ipc_table_ready(g_ipc_table))
no_os_mdelay(10);
uint32_t addr = g_ipc_table->fn[0];
Event Loop (10-round 1:1 handshake)
RISC-V -> echoes callback address to
MXC_SEMA->mail1, rings doorbell (setsCM4_IRQinMXC_SEMA->irq0)ARM -> polls
CM4_IRQ, readsmail1, acknowledges (clearsCM4_IRQ), dispatches the echoed callback, and counts the eventRISC-V -> waits for the ARM to clear
CM4_IRQbefore ringing again (guarantees every notification is seen exactly once), then repeatsBoth finish after 10 acknowledged events
Implementation Notes
No Data Cache
Both cores have no data cache. Publication and acquisition still require ordering against the SEMA doorbell: the platform provides ARM DMB and RISC-V FENCE barriers through the shared IPC helpers. Volatile fields alone do not provide this ordering.
Function Pointer Communication
The IPC table stores function addresses as uint32_t (not typed C
pointers):
Why: Avoids cross-arch ABI issues (Thumb bit on ARM, different calling conventions)
Pattern: ARM publishes address -> RISC-V reads it -> RISC-V echoes back via doorbell -> ARM dispatches from its own ISR (stays on ARM core, avoids remote function calls)
Memory Layout & IPC Table Placement
RISC-V code runs in place from flash (at
_riscv_boot); its data/bss/stack live in SRAM2 (per the stockmax78000_riscv.ld). SRAM3 is unused by this build.The IPC table lives at the fixed SRAM2 address ``0x20011000``, reached by both cores through an identical fixed-address pointer (
(maxim_ipc_table_t *)0x20011000) rather than a linker-placed object -- this is what makes the two cores agree on the table location.It must be in SRAM2, not SRAM3: when the RISC-V runs from flash, SRAM3 (the "RV Code" region) is not accessible to the RV core as data. The first 8 KiB of SRAM2 are reserved, so CPU1 private data starts at
0x20012000and cannot overlap the table.
Build Integration
The RISC-V firmware is cross-compiled and embedded into the ARM ELF by the
no-OS platform helper maxim_add_riscv_coprocessor() (in
cmake/maxim/maxim_coprocessor.cmake). This project just names the RISC-V
source:
include(maxim_coprocessor)
maxim_add_riscv_coprocessor(max78000
DEFCONFIG .../riscv/dual_core.conf
SRAM2_RESERVE 0x2000
SOURCES .../dual_core_example_riscv.c
INCLUDES ...)
The helper runs a two-pass build (the RISC-V must be linked at its flash load address, which is only known after the ARM is linked):
Premap: link a twin of the ARM target (same sources, no RISC-V blob) and read the
_riscv_bootflash address from its map.Derive CPU1 flash origin and length in
coprocessor/flash.cmake.Configure and build CPU1 with its own toolchain and Kconfig header, using the platform RISC-V startup/services; link at
_riscv_bootand generatecoprocessor/build/riscv.bin.Wrap
riscv.bin(.incbin) intoriscv.o.Final: link the ARM ELF with
riscv.o. The platform's dual-core ARM linker script (drivers/platform/maxim/max78000/max78000_dualcore_arm.ld)KEEP``s ``riscv.oat.riscv_flash/_riscv_boot, excludes it from ARM.text, and confines the ARM stack to SRAM0/1 so it cannot trample the RISC-V's SRAM2.
The image rides inside the single ARM ELF that gets flashed -- no separate flash invocation.
Future Enhancements
Real Work Examples
In production, the RISC-V side would do useful work:
CNN inference: run inference on the neural network accelerator while ARM sleeps
DSP processing: audio/signal processing in the background
Autonomous tasks: RTC alarms, periodic sensors, power-down sequencing
Replace the delay_ms() + doorbell loop with your actual workload.
Testing
Smoke Test
Build and flash to MAX78000FTHR:
python tools/scripts/no_os_build.py build \
--project max78000 --variant dual_core --board max78000fthr \
--probe openocd --flash --clean
Then open the USB-UART console (e.g. /dev/ttyACM0, 115200 8N1). Expected
output:
========================================
MAX78000 Dual-Core Example (ARM Side)
========================================
[ARM] RISC-V firmware embedded in flash at 0x1000d200
[ARM] Initializing IPC (doorbells + mailboxes)...
[ARM] IPC initialized
[ARM] Initializing coprocessor (CPU1)...
[ARM] Booting coprocessor (CPU1)...
[ARM] Coprocessor booted successfully
[ARM] Callback address published to RISC-V (0x...)
[ARM] Waiting for RISC-V events...
[ARM] RISC-V event callback invoked
[ARM] Wakeup 1/10 (callback 0x...)
...
[ARM] Wakeup 10/10 (callback 0x...)
[ARM] Example complete (10 wakeups received)
[ARM] Halting coprocessor...
[ARM] Dual-core example finished
This is a verified, working dual-core flow: the RISC-V image is embedded in flash inside the ARM ELF, the ARM boots CPU1 to run in place from flash, and the two cores complete a 10-round doorbell handshake through the shared IPC table.
How the RISC-V image is embedded and booted
The RISC-V source + the RISC-V startup/system are cross-compiled with
riscv-none-elf-gccand linked withmax78000_riscv.ldto run in place from flash at_riscv_boot(see the two-pass Build Integration).The built
.binis.incbin-wrapped intoriscv.o, which the ARM linkerKEEP``s in the ``.riscv_flashsection at_riscv_boot.At boot the coprocessor driver clears
FCR->urvctrl(select flash), setsFCR.urvbootaddr = &_riscv_boot, and pulsesGCR.rst1.CPU1to release CPU1.The RISC-V startup sets mtvec/gp/sp, copies
.data/ zeroes.bssinto SRAM2;main()then enables the RISC-V instruction cache and runs.
Debug Hints
RISC-V not waking ARM: Check the IPC table at
0x20011000-- offset 0 (magic) must read0xCAFEFEEDand offset 68 (ready) must be 1. Both cores must use the fixed0x20011000(SRAM2), not a linker-placed section, and not SRAM3 (inaccessible to the RV when it runs from flash).SEMA registers: Check
MXC_SEMA->irq0-- theCM4_IRQbit is the doorbell from RISC-V;mail1carries the echoed callback address.RISC-V code not running: Verify
FCR->urvctrl == 0andFCR->urvbootaddr == &_riscv_boot, and that the bytes at_riscv_bootin flash matchriscv.bin. A RISC-V trap with nomtvec(not an issue with the stock startup) wedges the AHB bus -- recover by racingreset halt+flash erase_sector 0 0 lastbefore the bad image runs.RISC-V reads garbage from the table: verify the shared address is reserved in both linker layouts and use the publication/acquisition helpers.
References
capi/inc/capi_coprocessor.h-- CAPI coprocessor APIcapi/inc/capi_mailbox.h-- CAPI mailbox (doorbell + mailbox) APIdual_core_example.c-- local Arm memory-barrier functioncapi/platform/maxim/max78000/maxim_capi_coprocessor.c-- CPU1 lifecyclecapi/platform/maxim/max78000/maxim_ipc.{c,h}-- SEMA doorbell/mailbox IPCcapi/platform/maxim/max78000/maxim_ipc_shared.h-- Shared table layout