A Rust wrapper for FreeRTOS.

Overview

freertos.rs

A Rust wrapper for FreeRTOS. Beta Rust is required - soon to be stable.

The main entry point for your embedded executable should be provided by your platform's preffered compiler toolchain. For example, for STM microcontrollers, a project generated using STM32CubeMX and compiled using GCC could be used as a starting point. Additional shims between C and Rust provide access to drivers, hardware and FreeRTOS.

This library uses a C shim to communicate with FreeRTOS's API. Dynamic memory allocation is required at the moment.

RustNightly

Documentation

Introduction article

Usage

First, add this to your Cargo.toml:

[dependencies]
freertos_rs = "0.3"

Next, add this to your project:

extern crate freertos_rs;

use freertos_rs::*;

Unit tests

This project includes unit tests that are run on the The GNU ARM Eclipse QEMU emulator. The basic firmware for STM32 is written in C, compiled with GCC and finally linked with the particular unit test's entry point. Since the QEMU emulator doesn't support FPU registers, slight changes were made to the FreeRTOS kernel. Lacking timer hardware emulation is simulated with a Systick-dependent IRQ trigger. Rust code invokes the cross compilation of this crate, compilation of the base firmware, final linkage and then runs the unit tests using the emulator.

Comments
  • error[E0432]: unresolved import `alloc::arc`   [stm32l475]

    error[E0432]: unresolved import `alloc::arc` [stm32l475]

    tasosxak@tasosxak:~/Documents/RustProjects/frtos$ cargo +nightly build
       Compiling freertos_rs v0.2.0
    error[E0432]: unresolved import `alloc::arc`
      --> /home/tasosxak/.cargo/registry/src/github.com-1ecc6299db9ec823/freertos_rs-0.2.0/src/prelude/no_std.rs:17:16
       |
    17 | pub use alloc::arc::{Arc, Weak};
       |                ^^^ could not find `arc` in `alloc`
    
    error[E0207]: the type parameter `O` is not constrained by the impl trait, self type, or predicates
       --> /home/tasosxak/.cargo/registry/src/github.com-1ecc6299db9ec823/freertos_rs-0.2.0/src/patterns/processor.rs:164:9
        |
    164 | impl<I, O> ProcessorClient<I, SharedClientWithReplyQueue<O>> where I: ReplyableMessage + Copy, O: Copy {
        |         ^ unconstrained type parameter
    
    error[E0207]: the type parameter `O` is not constrained by the impl trait, self type, or predicates
       --> /home/tasosxak/.cargo/registry/src/github.com-1ecc6299db9ec823/freertos_rs-0.2.0/src/patterns/processor.rs:175:9
        |
    175 | impl<I, O> ProcessorClient<InputMessage<I>, SharedClientWithReplyQueue<O>> where I: Copy, O: Copy {
        |         ^ unconstrained type parameter
    
    error: aborting due to 3 previous errors
    
    Some errors occurred: E0207, E0432.
    For more information about an error, try `rustc --explain E0207`.
    error: Could not compile `freertos_rs`.
    
    To learn more, run the command again with --verbose.
    

    main.rs

    extern crate freertos_rs;
    
    use freertos_rs::*;
    use prelude::v1::*;
    
    #[no_mangle]
    pub extern fn main_entry() {
        let mut s = Serial::new();
        s.tx_string("Hello from Rust!\n");
        loop {
            let data = s.rx_i32();
            s.tx_string("Received: ");
            s.tx_i32(data);
            s.tx_string("\n");
        }
    }
    

    Rust version:

    tasosxak@tasosxak:~/Documents/RustProjects/frtos$ rustup default nightly
    info: using existing install for 'nightly-x86_64-unknown-linux-gnu'
    info: default toolchain set to 'nightly-x86_64-unknown-linux-gnu'
    
      nightly-x86_64-unknown-linux-gnu unchanged - rustc 1.35.0-nightly (26b4cb484 2019-03-09)
    

    .cargo/config

    [target.thumbv7em-none-eabi]
    
    [target.'cfg(all(target_arch = "arm", target_os = "none"))']
    runner = "gdb-multiarch -q -x openocd.gdb"
    
    
    rustflags = [
      "-C", "link-arg=-Tlink.x",
    ]
    
    [build]
    target = "thumbv7em-none-eabi"   # Cortex-M4 and Cortex-M7 (no FPU)
    
    opened by tasosxak 9
  • How about to release new version?

    How about to release new version?

    Hello,

    Thank you for such good crate. I tried version 0.1.0 from crates.io, basically all fine, but there is issue with Duration::ms(). As I see you made some fixes/modification since 0.1.0, would you like to publish new version to crates.io ?

    Thanks in advance.

    opened by lexxvir 4
  • Question about passing huge struct through queue

    Question about passing huge struct through queue

    Is it possible to pass huge struct through queue without copying whole struct?

    It seems that freertos.rs makes copying of item in Queue::send() (though it possibly be removed by optimizations), then FreeRTOS' xQueueSend also does copy.

    Box<T> could be used for this purpose but as I see, Box doesn't implement Copy trait that required by Queue.

    opened by lexxvir 3
  • Build broken

    Build broken

    I assume this is due to changes in the latest Rust version. Also happens to me using rustc 1.28.0and rustc 1.30.0-nightly

    error[E0207]: the type parameter `O` is not constrained by the impl trait, self type, or predicates
       --> src/patterns/processor.rs:164:9
        |
    164 | impl<I, O> ProcessorClient<I, SharedClientWithReplyQueue<O>> where I: ReplyableMessage + Copy, O: Copy {
        |         ^ unconstrained type parameter
    error[E0207]: the type parameter `O` is not constrained by the impl trait, self type, or predicates
       --> src/patterns/processor.rs:175:9
        |
    175 | impl<I, O> ProcessorClient<InputMessage<I>, SharedClientWithReplyQueue<O>> where I: Copy, O: Copy {
        |         ^ unconstrained type parameter
    
    opened by marcelbuesing 2
  • [BUG] Task memory leak/unsafety - do not merge

    [BUG] Task memory leak/unsafety - do not merge

    Possible sources of this bug:

    • FreeRTOS.rs's implementation of the Task spawning and boxing
    • Memory allocation glue used by Rust/FreeRTOS (specifically, the alignment is ignored!)
    opened by rudib 1
  • Release 0.3.0

    Release 0.3.0

    The changes made in #20 allow this to successfully compile. Can you push it to crates.io? Additionally, #![feature(alloc)] can be removed, as alloc is now stable.

    opened by lights0123 1
  • Latest Rust nightly build broken

    Latest Rust nightly build broken

    Once again, after the latest updates for nightly Rust, the current master is broken. I can't replicate the Travis build failure on my local machine.

    https://travis-ci.org/hashmismatch/freertos.rs/builds/485077268

    cc @ilya-epifanov

    opened by rudib 1
  • freertos_rs_delete_semaphore takes UBaseType_t in C wrapper

    freertos_rs_delete_semaphore takes UBaseType_t in C wrapper

    A small type detected by compiling with warnings

    // from shim.rs
    extern {
    	// ...
    	pub fn freertos_rs_queue_delete(queue: FreeRtosQueueHandle);
    	// ...
    

    And in C code:

    // queue.c
    void vQueueDelete( QueueHandle_t xQueue )
    // shim.c
    void freertos_rs_queue_delete(UBaseType_t queue)
    

    There are also a few minor problems:

    • uint8_t is used and passed as char * when transforming string (strict aliasing violation) (freertos_rs_spawn_task and freertos_rs_timer_create)
    • freertos_rs_queue_send_isr have unused variable ret.

    I can send a pull request for them later today but they should be easy enough to fix

    opened by uzytkownik 1
  • Linking errors when some features are disabled in FreeRTOS (at least stack high water mark)

    Linking errors when some features are disabled in FreeRTOS (at least stack high water mark)

    /tmp//libkvm.a(freertos_rs-4d6cd4cda3cfed3d.freertos_rs0.rcgu.o): In function `freertos_rs::task::Task::get_stack_high_water_mark::h2ebc848c0d006b62':
    /home/mpiechotka/.cargo/registry/src/github.com-1ecc6299db9ec823/freertos_rs-0.2.0/src/task.rs:257: undefined reference to `freertos_rs_get_stack_high_water_mark'
    /tmp//libkvm.a(freertos_rs-4d6cd4cda3cfed3d.freertos_rs0.rcgu.o): In function `freertos_rs::task::CurrentTask::get_stack_high_water_mark::ha19f8026cb3c6f12':
    /home/mpiechotka/.cargo/registry/src/github.com-1ecc6299db9ec823/freertos_rs-0.2.0/src/task.rs:275: undefined reference to `freertos_rs_get_stack_high_water_mark'
    

    freertos_rs_get_stack_high_water_mark is not compiled as INCLUDE_uxTaskGetStackHighWaterMark is not equal to 1.

    opened by uzytkownik 1
  • Add feature 'core_collections'

    Add feature 'core_collections'

    Hi,

    Unfortunately currently I tied to certain version of rustc. In this version collections crate is not deprecated yet. I added feature that allows to use such old rustc versions.

    opened by lexxvir 1
  • Collections has been merged into alloc

    Collections has been merged into alloc

    Pulled this for some work on an RTL8710, looks like it doesn't compile anymore on nightly because collections has been merged into alloc. I've got it compiling on my own fork making some small changes here and there but not sure about any implications of what i've been doing.

    opened by Moggers 1
  • Added delete method for Tasks

    Added delete method for Tasks

    Added delete method in Task so that users could delete a task after it was created.

    Double delete can not happen, because once a task was terminated its main function will never return.

    opened by Neo-Zhixing 0
  • Change the trait bound for Queue elements from Copy to Unpin

    Change the trait bound for Queue elements from Copy to Unpin

    Right now Queue requires that all elements needs to be Copy. This seems correct, because xQueueSend will copy a predetermined bytes from *pvItemToQueue to the queue.

    However, let's consider a type that is not Copy. Vec can be cheaply moved because it only contains ptr, capacity and length, but it is not Copy.

    I believe that here we only need to require the item to be Unpin to guarantee that they can be freely moved.

    opened by Neo-Zhixing 0
  • Added uninitialized for Queue

    Added uninitialized for Queue

    Certain functions in ESP-IDR (for example uart_driver_install ) asks for an uninitialized Queue pointer. This creates an additional method in Queue to creates an uninitialized queue so that they could be initialized by something else.

    opened by Neo-Zhixing 1
  • Doesn't compile on Cortex-M0

    Doesn't compile on Cortex-M0

    It seems the Cortex-M0 doesn't have LDREX and STREX opcodes, so atomics are not implemented, so std::sync is not compiled into the alloc crate.

    Either we should use our own implementation of Arc (using disabling interrupts or using the FreeRTOS critical sections), or figure out some way to avoid using them (at least) on platforms without atomic support

    opened by axos88 0
  • libfreertos-sys implementation created

    libfreertos-sys implementation created

    This is an FYI, that I just created a crate that compiles the FreeRTOS C code and creates the rust bindings for it: https://github.com/axos88/libfreertos-sys.

    It's uncomplete, but it might help people get started.

    opened by axos88 1
Owner
HashMismatch
HashMismatch
A comparison of operating systems written in Rust

Rust OS comparison A comparison of operating systems written in Rust. There are several open source operating systems written in Rust. Most of them ar

Markus Kohlhase 492 Jan 8, 2023
An OS kernel written in rust. Non POSIX

"Tifflin" Experimental Kernel (and eventually Operating System) This is an experiment in writing an OS Kernel in rust (http://rust-lang.org). Mostly t

John Hodge (Mutabah) 618 Jan 8, 2023
A hobby operating system, in Rust

intermezzOS: kernel intermezzOS is a hobby operating system. This repository is for its kernel. See the website for more. License This project is dual

intermezzOS 1.3k Jan 1, 2023
A Rust version of the Weenix OS

Reenix This is the start of a unix like operating system written in Rust. It is based on the Weenix Operating system written for Brown's CS167/9. At t

Alex Light 311 Dec 22, 2022
A tiny 32 bit kernel written in Rust

rustboot A tiny 32 bit kernel written in Rust. I was inspired to download Rust and try to do this after seeing zero.rs - a stub that lets Rust program

Charlie Somerville 1.5k Dec 30, 2022
A language-based OS to run Rust on bare metal

RustOS A simple, language-based OS. Current features: Simple VGA for seeing output Some Rust libraries (core, alloc, collections) already in Working (

null 402 Dec 8, 2022
A language-based OS to run Rust on bare metal

RustOS A simple, language-based OS. Current features: Simple VGA for seeing output Some Rust libraries (core, alloc, collections) already in Working (

null 79 Dec 3, 2022
Experimental kernel for embedded devices written in Rust

bkernel is an experimental kernel for embedded devices written in Rust. I'm mostly trying out Rust now to see how it applies to kernel development. Pr

Alexey Shmalko 84 Dec 13, 2022
Open Source Rust kernel; Runs WASM and WASI as lightweight containers.

?? etheryal Kernel etheryal kernel is an Open Source capability-based Kernel written in the Rust programming language. The kernel allows implementing

null 32 Dec 4, 2022
Basic Rust kernel using Limine

Rust Limine Barebones This is a small kernel that boots using Limine. Build First of all, download Rust ! (I guess you already did it if you are here

Quentincestino 16 Dec 23, 2022
A new operating system kernel with Linux binary compatibility written in Rust.

Kerla Kerla is a monolithic operating system kernel from scratch in Rust which aims to be compatible with the Linux ABI, that is, runs Linux binaries

Seiya Nuta 3.1k Jan 1, 2023
Fast dense evaluation of Green's function kernels in Rust

Fast evaluation of Greens functions in Rust This library allows the fast evaluation of Greens functions and potential sums for Laplace, Helmholtz, and

null 8 Nov 10, 2022
Minimal x86_64 OS kernel written in Rust

rkernel A minimal x86_64 Rust OS kernel. Multiboot2 VGA driver PIC PIT PS/2 Keyboard driver PS/2 Mouse driver TSC RTC Allocator ATA PIO (In progress..

Divy Srivastava 36 Apr 26, 2022
Operating system written in Rust for NumWorks calculator (model n0110)

RustWorks An OS (eventually) for the Numworks calculator (model n0110). Setup First install Rust by following these instuctions then: rustup target ad

null 30 Nov 10, 2022
SteinsOS is an operating system written in Rust

SteinsOS is an operating system featuring non-preemptive kernel targeting on single-core armv8 architecture.

Sheng 84 Dec 15, 2022
🍒 Small, simple, and fast kernel written in Rust. 🌸

?? Small, simple, and fast kernel written in Rust. ??

Cherry Developers 5 May 20, 2022
Learn to write an embedded OS in Rust

Operating System development tutorials in Rust on the Raspberry Pi

Rust Embedded 9.9k Jan 6, 2023
Revons Os is a new OS written from scratch in Rust to experiment with novel OS structure

Revons Os is a new OS written from scratch in Rust to experiment with novel OS structure, better state management, and how to leverage intralingual design principles to shift OS responsibilities like resource management into the compiler.

Fayssal Chokri 1 Jul 2, 2022
Examples on how to write Windows kernel drivers in Rust

windows-kernel-rs Note: this is still work in progress! This is a Windows kernel framework in Rust that consists of windows-kernel-sys, a crate that p

S.J.R. van Schaik 77 Dec 28, 2022