A ravedude-like tool for flashing Rust firmware to the Arduino Uno R4 (WiFi & Minima), with an easy-to-use BSP library.
The Arduino Uno R4 uses an ARM Cortex-M4 (Renesas RA4M1) instead of the AVR architecture, which means the standard ravedude + avrdude toolchain doesn't work. This project provides:
- cargo-r4: Automated flashing tool (like ravedude for AVR)
- r4-bsp: Board Support Package library for easy hardware access
- xtask: Build automation for streamlined development
Note: This tool is currently optimized for Linux. Windows and macOS support is planned but not yet fully verified.
# Clone and build
git clone <repo-url>
cd cargo-r4
cargo build --release
# Flash an example (builds + flashes automatically)
cargo xtask flash blinky
# Or use the convenience script
./flash.sh heartbeat- One-command flashing -
cargo xtask flash <example>handles everything - Automatic cargo run - Just
cargo run --releaseto flash - Auto-detect Arduino R4 boards (WiFi & Minima variants)
- Automatic bootloader trigger using
bossac - ELF to BIN conversion using
objcopy - Serial monitor for viewing output
- r4-bsp library - Professional BSP with
embedded-halsupport - Optimized GPIO - High-performance pin operations
- Modular architecture - Clean, maintainable codebase
- Flexible tool detection - Supports environment variable overrides
You need two external tools for flashing:
- bossac - BOSSA flash programmer for SAM-BA bootloaders
- objcopy - Binary utilities (usually
arm-none-eabi-objcopy)
On Linux (Debian/Ubuntu):
sudo apt install bossac gcc-arm-none-eabiOn macOS:
brew install bossa-cli arm-none-eabi-gccOn Arch Linux:
sudo pacman -S arm-none-eabi-binutils
# Install bossac from AUR or use arduino-cliVia Arduino CLI (all platforms):
# Install Arduino CLI
curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | sh
# Install Arduino tools (includes bossac)
arduino-cli core install arduino:renesas_unoThe tools will be at:
- Linux/macOS:
~/.arduino15/packages/arduino/tools/bossac/*/
You can also place bossac and objcopy binaries in a bin/ directory next to the cargo-r4 executable, and they will be found automatically.
A helper script is provided to assist with tool setup:
./setup-tools.shYou can override tool paths using environment variables:
export R4_BOSSAC_PATH=/path/to/custom/bossac
export R4_OBJCOPY_PATH=/path/to/custom/objcopyThe tool search order is:
- Environment variables (
R4_BOSSAC_PATH,R4_OBJCOPY_PATH) - System PATH
- Local
bin/directory - Workspace
bin/directory
cargo build --releaseThe binary will be at target/release/cargo-r4.
# Build and flash an example in one command
cargo xtask flash blinky
# Or use the convenience script
./flash.sh heartbeatFrom the examples directory:
cd examples
cargo run --release --example blinkyThe .cargo/config.toml runner automatically flashes to your Arduino R4.
# Build your firmware
cargo build --release
# Flash it
./target/release/cargo-r4 path/to/your/firmware.elf--baud <RATE>: Set serial monitor baud rate (default: 115200)
The r4-bsp library provides a professional, embedded-hal compatible interface:
#![no_std]
#![no_main]
use cortex_m_rt::entry;
use panic_halt as _;
use r4_bsp::{Board, Led, delay_ms};
#[entry]
fn main() -> ! {
// Initialize hardware (must be called first!)
Board::init();
let mut led = Led::new();
loop {
led.on();
delay_ms(500);
led.off();
delay_ms(500);
}
}The r4-bsp library implements the standard embedded-hal traits, allowing you to use any compatible driver:
use embedded_hal::digital::OutputPin;
use r4_bsp::{Board, Pin};
// Pin and Led implement OutputPin trait
let mut pin = Pin::new(1, 2);
pin.set_high().ok();
pin.set_low().ok();See the examples/ directory for complete working examples, including setup files (Cargo.toml, memory.x, build.rs).
One-Command Flash (Recommended):
cargo xtask flash blinky
cargo xtask flash heartbeatConvenience Script:
./flash.sh blinkyCargo Run (from examples directory):
cd examples
cargo run --release --example blinkyWhen you run cargo xtask flash blinky:
- Build - Compiles
blinky.rsforthumbv7em-none-eabihf - Detect - Finds your Arduino R4 (WiFi or Minima)
- Bootloader - Triggers bootloader mode via bossac
- Convert - Transforms ELF to BIN format
- Flash - Writes firmware via BOSSA protocol
- Monitor - Opens serial connection at 115200 baud
All automatic! Press Ctrl+C to exit the serial monitor.
Quick testing:
cargo xtask flash <example_name>Development iteration:
cd examples
# Edit your example file...
cargo run --release --example <name>Custom projects:
Add this to your .cargo/config.toml:
[target.thumbv7em-none-eabihf]
runner = "/path/to/cargo-r4"Then just cargo run --release in your project.
- VID:
0x2341 - PID:
0x1002(ESP32-S3 USB bridge) - MCU: Renesas RA4M1 (ARM Cortex-M4F @ 48MHz)
- Flash: 256KB (240KB usable, 16KB bootloader)
- RAM: 32KB
- Built-in LED: P102 (Port 1, Pin 2)
- VID:
0x2341 - PID:
0x0069 - MCU: Renesas RA4M1 (ARM Cortex-M4F @ 48MHz)
- Flash: 256KB (240KB usable)
- RAM: 32KB
- Ensure the board is connected via USB
- Check that you have permissions for serial ports (add user to
dialoutgroup on Linux) - Try unplugging and replugging the board
- Make sure no other program (Arduino IDE, serial monitor) is using the port
- Try pressing the reset button twice quickly to manually enter bootloader mode
- Check that the binary size doesn't exceed available flash (240KB)
- Verify the memory.x file has the correct flash origin (
0x00004000) - Check that the firmware was compiled for
thumbv7em-none-eabihftarget - Ensure the binary includes all necessary sections (
.text,.data)
MIT License - see LICENSE file for details.
- Arduino team for the R4 board and bootloader
- Renesas for the RA4M1 MCU and FSP
- BOSSA project for the flash programming tool
- es_r4 reference implementation https://github.com/eyyyyyyy3/es_r4
"Arduino® is a trademark of Arduino SA. This project is not affiliated with or endorsed by Arduino SA."