Expand description
§ra-hal
ra-hal is a Hardware Abstraction Layer (HAL) for the Renesas Renesas RA family of microcontrollers written in Rust.
This HAL implements a variety of traits to provide both asynchronous and blocking interfaces that enable compatibility with software frameworks like Embassy and RTIC
as well as more general libraries like embedded-hal.
The end goal is to provide a safe, idiomatic Rust interface that surfaces most of the flexibility provided by the RA microcontrollers.
§Documentation
For more information check out the docs and take a peek at the examples. To build documentation for a specific group run:
just doc-<chip>Replace <chip> with the model of your MCU.
To automatically open the generated documentation in a web browser append the --open argument.
§Application Template
A template suitable for cargo-generate is available at: https://git.sr.ht/~az1/ra-template.
This template can be used to generate an Embassy project that uses the HAL or a PAC based project.
§Prerequisites
- Ensure
cargo-generateis installed. - Get familiar with Embassy.
§Usage
$ cargo generate --git https://git.sr.ht/~az1/ra-template --branch metapac
<follow the prompts>
$ cd <name of your new project>
$ cargo build --release
$ cargo run --releaseCheck out the examples and the Embassy docs if you’re not already familiar.
§Limitations
- Currently only one core per MCU is supported (relevant for multi-core RA8 MCUs).
- On MCUs with TrustZone™ support the HAL is designed to only work in secure mode.
RA2: Use of theRA2family is subject to significant caveats. No compile- or run-time checking of interrupt groups is done. Atomic ops may hang or report failure (TN-RA*-A0098A/E).EK-RA2A1: Despite a reported 500 kHz maximum SWO speed, the onboard J-Link seems to work most reliably withprobe-rswhen the SWO frequency is limited to 125 kHz via the--speed 125argument.- TODO: Add knobs to generate a HAL+RTICv2 project.
For the canonical list of known issues check the issue tracker.
https://todo.sr.ht/~az1/ra-rs/
§Development
§Prerequisites
- MSRV is 1.95,
rust-toolchain.tomlhas been set to 1.95. Older versions of Rust will not work as we depend oncfg_select!. just.justcan be installed by viacargo install just.probe-rsfor debugging and flashing.
To use a local version of ra-metapac for development you can patch cargo with a configuration file named cargo-config.toml in the root directory of ra-hal.
For example:
[patch."https://git.sr.ht/~az1/ra-metapac"]
ra-metapac = { path = "/path/to/ra-metapac/ra-metapac" }§Feature flags
rt(enabled by default) — Enable thertfeature of the PAC. Withrtenabled the PAC provides interrupt vectors instead of lettingcortex-m-rtdo that. See https://docs.rs/cortex-m-rt/latest/cortex_m_rt/#device for more info.cache— Enable the flash cache. The cache is invalidated after eachDMAC/DTCoperation. See: §44.3.chrono(enabled by default) — Enable dependency onchronoand expose methods that work with chrono structures.defmt— Usedefmtfor logging.diag(enabled by default) — Log the reset reason during initialization. Only useful in conjunction withdefmtfeature.swd-as-gpio— Allow access to pins normally used for JTAG/SWD debuggingunstable-pac— Re-export the PAC atra_hal::pac. This is unstable because minor HAL updates may depend on major PAC updates.strict-assert(enabled by default) — Extra runtime assertions.skip-osm— Don’t setOSMregisters in the HAL, instead define them in your application.
§Time features
time-driver-gpt0— Enables support forembassy-timeand provides a time driver using a 32-bit GPT instance (GPT32_0).time-driver-gpt1— Enables support forembassy-timeand provides a time driver using a 32-bit GPT instance (GPT32_1).time-driver-agt— Enables support forembassy-timeand provides a time driver using a 32-bit AGTW instance.time-driver-ulpt— Enables support forembassy-timeand provides a time driver using a 32-bit ULPT instance.
§USB features
§On-Chip Oscillator Configuration
Consult your reference manual for valid frequencies. TODO: Decouple this from the embassy tick rate.
hoco_16mhz— Sets the high speed on-chip oscillator (HOCO) to 16 MHz.hoco_18mhz— Sets the high speed on-chip oscillator (HOCO) to 18 MHz.hoco_20mhz— Sets the high speed on-chip oscillator (HOCO) to 20 MHz.hoco_32mhz— Sets the high speed on-chip oscillator (HOCO) to 32 MHz.hoco_40mhz— Sets the high speed on-chip oscillator (HOCO) to 40 MHz.hoco_48mhz— Sets the high speed on-chip oscillator (HOCO) to 48 MHz.hoco_64mhz— Sets the high speed on-chip oscillator (HOCO) to 64 MHz.hoco_80mhz— Sets the high speed on-chip oscillator (HOCO) to 80 MHz.
§Chip Features
ra2a1— RA2A1ra4l1— RA4L1ra4m1— RA4M1ra6m5— RA6M5ra8m1— RA8M1
§Memory Configuration
Consult the reference manual for valid configurations for your chip.
mem_ram64k_flash256k— 64K RAM, 256K flashmem_ram64k_flash512k— 64K RAM, 512K flashmem_ram512k_flash1024k— 512K RAM, 1024K flashmem_ram512k_flash1536k— 512K RAM, 1536K flashmem_ram512k_flash2048k— 512K RAM, 2048K flashmem_ram896k_flash2016k— 896K RAM, 2016K flash
§Chip Package
Consult the reference manual for valid packages for your chip.
32lqfp— 32-pin LQFP36bga— 36-pin BGA40qfn— 40-pin QFN48lqfp— 48-pin LQFP48qfn— 48-pin QFN64bga— 64-pin BGA64lqfp— 64-pin LQFP64qfn— 64-pin QFN100bga— 100-pin BGA100lga— 100-pin LGA100lqfp— 100-pin LQFP144bga— 144-pin BGA144lqfp— 144-pin LQFP176bga— 176-pin BGA176lqfp— 176-pin LQFP224bga— 224-pin BGA
Re-exports§
pub use chrono;
Modules§
- adc
- Analog-to-Digital Converter (
ADC12,ADC14,ADC16). - clock
- Clock information and configuration.
- constants
- crc
- Cyclic Redundancy Check Calculator (
CRC). - dac
- 12-bit Digital-to-Analog Converter (
DAC12). - dmac
- Direct Memory Access Controller (
DMAC). - dtc
- Data Transfer Controller (
DTC). - event_
link - Event Link Controller (
ELC) and Interrupt Controller Unit (ICU) related shenanigans. - gpio
- General Purpose Input/Output (
PORT). - i2c
- I2C Bus Interface (
IIC). - interrupt
- Interrupt definitions.
- mcu_
info - Factory MCU Information
- module_
stop - Module stop (
MSTP). - osm
- Option-Setting Memory (
OFS0,OFS1,SECMPU). - peripherals
- Types for the peripheral singletons.
- pwm
- Pulse Width Modulation driver utilizing the General PWM Timer (
GPT). - qdec
- Quadrature decoder driver (
GPT) utilizing the General PWM Timer (GPT). - spi
- Serial Peripheral Interface (
SPI). - time_
driver - Driver for
embassy-time. - timer_
agt - Timer that generates interrupts utilizing the Low Power Asynchronous General Purpose Timer (
AGT/AGTW). - timer_
gpt - Timer that generates interrupts utilizing the General PWM Timer (
GPT). - uart
- Universal Asynchronous Receiver-Transmitter
- usb
- USB Full-Speed 2.0 peripheral.
- watchdog
- Watchdog drivers.
- write_
protect - Conveniences for registers that are gated by a write protect flag.
Macros§
- assert_
eq - Expands to
defmt::assert_eq!if thedefmtfeature is enabled, core impl otherwise. - bind_
interrupts - Macro to bind interrupts to interrupt handlers.
- debug
- Log at the
debuglevel if thedefmtfeature is enabled. No-op otherwise. - error
- Log at the
errorlevel if thedefmtfeature is enabled. No-op otherwise. - exit
- Calls the semihosting exit hook. Will cause an exception without a semihosting implementation on the host side.
- info
- Log at the
infolevel if thedefmtfeature is enabled. No-op otherwise. - trace
- Log at the
tracelevel if thedefmtfeature is enabled. No-op otherwise. - warn
- Log at the
warnlevel if thedefmtfeature is enabled. No-op otherwise.
Structs§
- Peri
- An exclusive reference to a peripheral.
- Peripherals
- Struct containing all the peripheral singletons.
Enums§
- Reset
Cause - Coarse indication of why the processor reset.
Constants§
- CONFIGURED_
FAMILY - MCU family e.g. RA4 that this firmware was configured/built for.
- CONFIGURED_
MCU - MCU group e.g. RA4M1 that this firmware was configured/built for.
- NUM_
INTERRUPTS - Number of interrupts exposed to the
NVIC.
Functions§
- init
- Initializes the MCU.
Attribute Macros§
- interrupt
- Attribute to declare an interrupt (AKA device-specific exception) handler