diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b69ccdea..2fa277d9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -42,8 +42,8 @@ jobs: freertos-rust-stable: name: Build freertos-rust using stable runs-on: ubuntu-latest - env: - RUSTFLAGS: -D warnings # Warnings disabled only in CI + # env: + # RUSTFLAGS: -D warnings # Warnings disabled only in CI steps: - name: Clone uses: actions/checkout@v3 @@ -70,8 +70,8 @@ jobs: # target: x86_64-pc-windows-gnu #- example: linux # target: x86_64-unknown-linux-gnu - #- example: stm32-cortex-m3 - # target: thumbv7m-none-eabi + - example: stm32-cortex-m3 + target: thumbv7m-none-eabi - example: stm32-cortex-m4-blackpill target: thumbv7em-none-eabihf #- example: nrf9160 @@ -93,7 +93,7 @@ jobs: target key: ${{ runner.os }}-${{ runner.arch }} - name: Install Rust - uses: dtolnay/rust-toolchain@nightly + uses: dtolnay/rust-toolchain@stable with: targets: ${{ matrix.target }} - name: Install cross deps diff --git a/README.md b/README.md index f407024e..3bd01418 100644 --- a/README.md +++ b/README.md @@ -13,61 +13,68 @@ In contrast to freertos.rs this crate differs in these points: ## How it works -The `freertos-cargo-build` build-dependency compiles the FreeRTOS code from its original "C" sources files into an -archive to be linked against your Rust app. Internally it uses the [cc crate](https://docs.rs/crate/cc) and some meta +The `freertos-cargo-build` build-dependency compiles the FreeRTOS code from its original "C" sources files into an +archive to be linked against your Rust app. Internally it uses the [cc crate](https://docs.rs/crate/cc) and some meta info provided by your apps `build.rs`: - + 1. A path to the [FreeRTOS](https://github.com/FreeRTOS/FreeRTOS-Kernel) `Sources` 1. A path to the app specific `FreeRTOSConfig.h` 1. A relative path to the `FreeRTOS port` to be used, e.g. for ARM Cortex-M3 cores. 1. Optional: Additional C code to be compiled - - The `freertos-rust` dependency provides an interface to access all FreeRTOS functionality from your (embedded) + + The `freertos-rust` dependency provides an interface to access all FreeRTOS functionality from your (embedded) Rust app. - + ## Usage -1. Checkout FreeRTOS: https://github.com/FreeRTOS/FreeRTOS-Kernel +1. Checkout FreeRTOS: https://github.com/FreeRTOS/FreeRTOS-Kernel 1. Add dependencies to your Rust apps `Cargo.toml` - - ``` + ```toml [dependencies] freertos-rust = "*" - + [build-dependencies] freertos-cargo-build = "*" ``` - + 1. Add this snippet to your apps `build.rs`: - ``` + ```rust fn main() { let mut b = freertos_cargo_build::Builder::new(); - + // Path to FreeRTOS kernel or set ENV "FREERTOS_SRC" instead b.freertos("path/to/FreeRTOS-Kernel"); - b.freertos_config("src"); // Location of `FreeRTOSConfig.h` - b.freertos_port("GCC/ARM_CM3"); // Port dir relativ to 'FreeRTOS-Kernel/portable' - b.heap("heap_4.c"); // Set the heap_?.c allocator to use from - // 'FreeRTOS-Kernel/portable/MemMang' (Default: heap_4.c) - + b.freertos_config("src"); // Location of `FreeRTOSConfig.h` + b.freertos_port("GCC/ARM_CM3"); // Port dir relativ to 'FreeRTOS-Kernel/portable' + b.heap("heap_4.c"); // Set the heap_?.c allocator to use from + // 'FreeRTOS-Kernel/portable/MemMang' (Default: heap_4.c) + // b.get_cc().file("More.c"); // Optional additional C-Code to be compiled - + b.compile().unwrap_or_else(|e| { panic!("{}", e.to_string()) }); } - ``` + ``` ### Used C compiler `freertos-cargo-build` depends on the [cc crate](https://docs.rs/crate/cc). So the C compiler -used can be set by using the `CC` enviroment variable or otherwise defined by internal +used can be set by using the `CC` enviroment variable or otherwise defined by internal defaults. For the ARM architecture this is the `arm-none-eabi-gcc` which can be found [here](https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads). +Install: +```shell +# on Ubuntu +sudo apt-get install -y gcc-arm-none-eabi +# on Windows +scoop install gcc-arm-none-eabi +``` + ## Examples To get started there are examples in [freertos-rust-examples](freertos-rust-examples) for: * Cortex M33 (nRF9160) -* Cortex M3 (STM32L151CBU6A) -* Cortex M4 (STM32F411CEU6) +* Cortex M3 (STM32F103C8) +* Cortex M4 (STM32F411CE) * Windows * ...more to come... @@ -80,7 +87,3 @@ To get started there are examples in [freertos-rust-examples](freertos-rust-exam This repository is using the MIT License. Some parts might state different licenses that need to be respected when used. * The [Linux port](https://github.com/michaelbecker/freertos-addons) is licensed under GPLv2 - - - - diff --git a/freertos-rust-examples/Cargo.toml b/freertos-rust-examples/Cargo.toml index da6599ee..ab9cb2fa 100644 --- a/freertos-rust-examples/Cargo.toml +++ b/freertos-rust-examples/Cargo.toml @@ -13,20 +13,17 @@ repository = "https://github.com/lobaro/FreeRTOS-rust" freertos-rust = {path = "../freertos-rust"} [target.'cfg(target_arch = "arm")'.dependencies] -cortex-m = "0.6.0" -cortex-m-rt = {version = "0.6.12"} -nrf9160-pac = "0.2.1" +cortex-m = "0.7" +cortex-m-rt = "0.7" # Example: stm32-cortex-m3 [target.thumbv7m-none-eabi.dependencies] -panic-halt = "0.2.0" -stm32l1xx-hal = {version = "0.1.0", features = ["stm32l151"], default-features = false} +stm32f1xx-hal = {version = "0.10", features = ["rt", "stm32f103", "medium"]} # Example: stm32-cortex-m4-blackpill [target.thumbv7em-none-eabihf.dependencies] -panic-halt = "0.2.0" -embedded-hal = "0.2.3" -stm32f4xx-hal = {version = "0.8.3", features = ["rt", "stm32f411"]} +embedded-hal = "1.0" +stm32f4xx-hal = {version = "0.22", features = ["stm32f411"]} # Example: nrf9160 [target."thumbv8m.main-none-eabihf".dependencies] @@ -39,4 +36,4 @@ nrf9160-pac = "0.2.1" [target.x86_64-unknown-linux-gnu.dependencies] [build-dependencies] -freertos-cargo-build = {path = "../freertos-cargo-build"} \ No newline at end of file +freertos-cargo-build = {path = "../freertos-cargo-build"} diff --git a/freertos-rust-examples/README.md b/freertos-rust-examples/README.md index b447f5c0..28817c48 100644 --- a/freertos-rust-examples/README.md +++ b/freertos-rust-examples/README.md @@ -80,29 +80,28 @@ Run the example ### Run STM32 Cortex-M3 Demo -we need the nightly build for some features like allocator_api: +We use stable toolchain and the target is thumbv7m-none-eabi: - rustup default nightly-x86_64-pc-windows-gnu // TODO: Build does not finish with GNU Toolchain - rustup default nightly-x86_64-pc-windows-msvc rustup target add thumbv7m-none-eabi - + Build the binary: cargo build --package freertos-rust-examples --example stm32-cortex-m3 --target thumbv7m-none-eabi - + Create hex file to be flashed: cargo objcopy --example stm32-cortex-m3 --target thumbv7m-none-eabi -- -O ihex stm32-cortex-m3.hex ### Run STM32 Cortex-M4 Demo -As the previous example, we need nightly toolchain and the target is thumbv7em-none-eabihf: +We use stable toolchain and the target is thumbv7em-none-eabihf: + rustup target add thumbv7em-none-eabihf Build the binary: cargo build --package freertos-rust-examples --example stm32-cortex-m4-blackpill --target thumbv7em-none-eabihf - + Create hex file to be flashed: cargo objcopy --example stm32-cortex-m4-blackpill --target thumbv7em-none-eabihf -- -O ihex stm32-cortex-m4-blackpill.hex diff --git a/freertos-rust-examples/examples/stm32-cortex-m3/FreeRTOSConfig.h b/freertos-rust-examples/examples/stm32-cortex-m3/FreeRTOSConfig.h index 5d57496f..6893cbcd 100644 --- a/freertos-rust-examples/examples/stm32-cortex-m3/FreeRTOSConfig.h +++ b/freertos-rust-examples/examples/stm32-cortex-m3/FreeRTOSConfig.h @@ -93,7 +93,7 @@ extern void vAssertCalled( const char * const pcFileName, unsigned long ulLine ) #define configUSE_PREEMPTION 1 #define configUSE_IDLE_HOOK 0 #define configUSE_TICK_HOOK 0 -#define configCPU_CLOCK_HZ ( 4200000UL ) //also systick runs at this frequency +#define configCPU_CLOCK_HZ ( 72000000UL ) //also systick runs at this frequency #define configTICK_RATE_HZ ( ( TickType_t ) 1000 ) //1000=1ms per tick, 100=10ms per tick #define configMAX_PRIORITIES ( 5 ) #define configMINIMAL_STACK_SIZE ( ( unsigned short ) 80 ) @@ -104,7 +104,7 @@ extern void vAssertCalled( const char * const pcFileName, unsigned long ulLine ) #define configIDLE_SHOULD_YIELD 1 #define configUSE_MUTEXES 1 #define configQUEUE_REGISTRY_SIZE 5 -#define configCHECK_FOR_STACK_OVERFLOW 2 +#define configCHECK_FOR_STACK_OVERFLOW 0 #define configUSE_RECURSIVE_MUTEXES 0 #define configUSE_MALLOC_FAILED_HOOK 0 //TR #define configUSE_APPLICATION_TASK_TAG 0 diff --git a/freertos-rust-examples/examples/stm32-cortex-m3/layout.ld b/freertos-rust-examples/examples/stm32-cortex-m3/layout.ld deleted file mode 100644 index a0b91f31..00000000 --- a/freertos-rust-examples/examples/stm32-cortex-m3/layout.ld +++ /dev/null @@ -1,5 +0,0 @@ -MEMORY -{ - FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 128K - RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 32K -} \ No newline at end of file diff --git a/freertos-rust-examples/examples/stm32-cortex-m3/main.rs b/freertos-rust-examples/examples/stm32-cortex-m3/main.rs index 9476fdb0..5d455dc7 100644 --- a/freertos-rust-examples/examples/stm32-cortex-m3/main.rs +++ b/freertos-rust-examples/examples/stm32-cortex-m3/main.rs @@ -1,121 +1,74 @@ #![no_std] #![no_main] -// For allocator -#![feature(lang_items)] -#![feature(alloc_error_handler)] - -extern crate panic_halt; // you can put a breakpoint on `rust_begin_unwind` to catch panics +use core::panic::PanicInfo; use cortex_m::asm; use cortex_m_rt::exception; use cortex_m_rt::{entry, ExceptionFrame}; use freertos_rust::*; -use core::alloc::Layout; -use stm32l1xx_hal as hal; -use stm32l1xx_hal::hal::digital::v2::*; -use stm32l1xx_hal::gpio::*; -use stm32l1xx_hal::gpio::gpioa::PA1; - +use stm32f1xx_hal::{gpio::PinState, pac, prelude::*}; #[global_allocator] static GLOBAL: FreeRtosAllocator = FreeRtosAllocator; -fn delay() { - let mut _i = 0; - for _ in 0..2_00 { - _i += 1; - } -} - -fn delay_n(n: i32) { - for _ in 0..n { - delay(); - } +#[entry] +fn main() -> ! { + Task::new() + .name("default") + .stack_size(1000) + .start(move |_| { + app_main(); + }) + .unwrap(); + FreeRtosUtils::start_scheduler(); } -static mut LED: Option>> = None; - -fn set_led(on: bool) { - unsafe { - let mut led = LED.take().unwrap(); - if on { - led.set_low(); - } else { - led.set_high(); - } - } -} +fn app_main() -> ! { + let dp = pac::Peripherals::take().unwrap(); + let mut flash = dp.FLASH.constrain(); + let rcc = dp.RCC.constrain(); + let _clocks = rcc + .cfgr + .use_hse(8.MHz()) + .sysclk(72.MHz()) + .freeze(&mut flash.acr); + + let mut gpio = dp.GPIOB.split(); + let mut led = gpio + .pb0 + .into_open_drain_output_with_state(&mut gpio.crl, PinState::High); -// Setup IO for the LED and blink, does not return. -fn do_blink_forever() -> ! { loop { - delay(); - set_led(true); - delay(); - set_led(false); + CurrentTask::delay(Duration::ms(500)); + led.set_low(); + CurrentTask::delay(Duration::ms(500)); + led.set_high(); } } -#[entry] -fn main() -> ! { - let dp = hal::stm32::Peripherals::take().unwrap(); - - // Set up the LED, it's connected to pin PA1. - let gpioa: stm32l1xx_hal::gpio::gpioa::Parts = dp.GPIOA.split(); - unsafe { LED = Some(gpioa.pa1.into_push_pull_output()); } - - // Initial blink - set_led(true); - delay_n(10); - set_led(false); - delay_n(10); - - // Just blink (does NOT work!) - do_blink_forever(); - - // TODO: What comes now does not work yet! - // Initialize Tasks and start FreeRTOS - Task::new().name("hello").stack_size(128).priority(TaskPriority(1)).start(|_this_task| { - // Just blink - freertos_rust::CurrentTask::delay(Duration::ms(1000)); - set_led(true); - freertos_rust::CurrentTask::delay(Duration::ms(1000)); - set_led(false); - }).unwrap(); - - - // TODO: Starting the scheduler fails, we need debugging to find the issue - // Seems like we don't even get an assert - FreeRtosUtils::start_scheduler(); -} - +#[allow(non_snake_case)] #[exception] -fn DefaultHandler(_irqn: i16) { -// custom default handler -// irqn is negative for Cortex-M exceptions -// irqn is positive for device specific (line IRQ) -// set_led(true);(true); -// panic!("Exception: {}", irqn); +unsafe fn DefaultHandler(_irqn: i16) { + // custom default handler + // irqn is negative for Cortex-M exceptions + // irqn is positive for device specific (line IRQ) + // set_led(true);(true); + // panic!("Exception: {}", irqn); + asm::bkpt(); + loop {} } - +#[allow(non_snake_case)] #[exception] -fn HardFault(_ef: &ExceptionFrame) -> ! { -// Blink 3 times long when exception occures - delay_n(10); - for _ in 0..3 { - set_led(true); - delay_n(10); - set_led(false); - delay_n(5); - } +unsafe fn HardFault(_ef: &ExceptionFrame) -> ! { + asm::bkpt(); loop {} } -// define what happens in an Out Of Memory (OOM) condition -#[alloc_error_handler] -fn alloc_error(_layout: Layout) -> ! { - set_led(true); +// We no longer need to use #[alloc_error_handler] since v1.68. +// It will automatically call the panic handler. +#[panic_handler] +fn panic(_info: &PanicInfo) -> ! { asm::bkpt(); loop {} -} \ No newline at end of file +} diff --git a/freertos-rust-examples/examples/stm32-cortex-m3/memory.x b/freertos-rust-examples/examples/stm32-cortex-m3/memory.x index a0b91f31..f18a0968 100644 --- a/freertos-rust-examples/examples/stm32-cortex-m3/memory.x +++ b/freertos-rust-examples/examples/stm32-cortex-m3/memory.x @@ -1,5 +1,5 @@ MEMORY { - FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 128K - RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 32K -} \ No newline at end of file + FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 64K + RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 20K +} diff --git a/freertos-rust-examples/examples/stm32-cortex-m4-blackpill/FreeRTOSConfig.h b/freertos-rust-examples/examples/stm32-cortex-m4-blackpill/FreeRTOSConfig.h index 4f964109..deb6af39 100644 --- a/freertos-rust-examples/examples/stm32-cortex-m4-blackpill/FreeRTOSConfig.h +++ b/freertos-rust-examples/examples/stm32-cortex-m4-blackpill/FreeRTOSConfig.h @@ -71,8 +71,8 @@ #define FREERTOS_CONFIG_H #include -extern void vAssertCalled( unsigned long ulLine, const char * const pcFileName ); -#define configASSERT( x ) if( ( x ) == 0 ) vAssertCalled( __LINE__, __FILE__ ) +extern void vAssertCalled( const char * const pcFileName, unsigned long ulLine ); +#define configASSERT( x ) if( ( x ) == 0 ) vAssertCalled( __FILE__, __LINE__ ) #define vPortSVCHandler SVCall #define xPortPendSVHandler PendSV @@ -93,7 +93,7 @@ extern void vAssertCalled( unsigned long ulLine, const char * const pcFileName ) #define configUSE_PREEMPTION 1 #define configUSE_IDLE_HOOK 0 #define configUSE_TICK_HOOK 0 -#define configCPU_CLOCK_HZ ( 4200000UL ) //also systick runs at this frequency +#define configCPU_CLOCK_HZ ( 100000000UL ) //also systick runs at this frequency #define configTICK_RATE_HZ ( ( TickType_t ) 1000 ) //1000=1ms per tick, 100=10ms per tick #define configMAX_PRIORITIES ( 5 ) #define configMINIMAL_STACK_SIZE ( ( unsigned short ) 80 ) @@ -186,4 +186,3 @@ See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */ // } #endif /* FREERTOS_CONFIG_H */ - diff --git a/freertos-rust-examples/examples/stm32-cortex-m4-blackpill/main.rs b/freertos-rust-examples/examples/stm32-cortex-m4-blackpill/main.rs index 15983bb3..64289538 100644 --- a/freertos-rust-examples/examples/stm32-cortex-m4-blackpill/main.rs +++ b/freertos-rust-examples/examples/stm32-cortex-m4-blackpill/main.rs @@ -1,39 +1,55 @@ #![no_std] #![no_main] -// For allocator -#![feature(lang_items)] -#![feature(alloc_error_handler)] +use core::panic::PanicInfo; use cortex_m::asm; use cortex_m_rt::exception; use cortex_m_rt::{entry, ExceptionFrame}; -use embedded_hal::digital::v2::OutputPin; +use embedded_hal::digital::OutputPin; use freertos_rust::*; -use core::alloc::Layout; use stm32f4xx_hal::gpio::*; -use cortex_m; use stm32f4xx_hal as hal; -use crate::hal::{ - stm32::{Peripherals}, -}; - -extern crate panic_halt; // panic handler +use crate::hal::{pac, prelude::*}; #[global_allocator] static GLOBAL: FreeRtosAllocator = FreeRtosAllocator; -fn delay() { - let mut _i = 0; - for _ in 0..2_00 { - _i += 1; - } +#[entry] +fn main() -> ! { + Task::new() + .name("default") + .stack_size(1000) + .start(move |_| { + app_main(); + }) + .unwrap(); + FreeRtosUtils::start_scheduler(); } -fn delay_n(n: i32) { - for _ in 0..n { - delay(); +fn app_main() -> ! { + let dp = pac::Peripherals::take().unwrap(); + let rcc = dp.RCC.constrain(); + let _clocks = rcc.cfgr.use_hse(25.MHz()).sysclk(100.MHz()).freeze(); + + let gpioc = dp.GPIOC.split(); + let mut device = MyDevice::from_pins(gpioc.pc13.into_open_drain_output()); + device.set_led(false); + Task::new() + .name("hello") + .stack_size(128) + .priority(TaskPriority(2)) + .start(move |_| loop { + CurrentTask::delay(Duration::ms(1000)); + device.set_led(true); + CurrentTask::delay(Duration::ms(1000)); + device.set_led(false); + }) + .unwrap(); + + loop { + CurrentTask::delay(Duration::ms(1000)); } } @@ -41,70 +57,49 @@ pub struct MyDevice { d1: D1, } -impl MyDevice -{ +impl MyDevice { pub fn from_pins(d1: D1) -> MyDevice { - MyDevice { - d1 - } + MyDevice { d1 } } - pub fn set_led(&mut self,on:bool){ + + pub fn set_led(&mut self, on: bool) { if on { - self.d1.set_high(); + self.d1.set_low().ok(); } else { - self.d1.set_low(); + self.d1.set_high().ok(); } } } -#[entry] -fn main() -> ! { - let dp = Peripherals::take().unwrap(); - let gpioc = dp.GPIOC.split(); - let mut device = MyDevice::from_pins(gpioc.pc13.into_push_pull_output()); - device.set_led(false); - Task::new().name("hello").stack_size(128).priority(TaskPriority(2)).start(move |_| { - loop{ - freertos_rust::CurrentTask::delay(Duration::ms(1000)); - device.set_led(true); - freertos_rust::CurrentTask::delay(Duration::ms(1000)); - device.set_led(false); - } - }).unwrap(); - FreeRtosUtils::start_scheduler(); -} - +#[allow(non_snake_case)] #[exception] -fn DefaultHandler(_irqn: i16) { -// custom default handler -// irqn is negative for Cortex-M exceptions -// irqn is positive for device specific (line IRQ) -// set_led(true);(true); -// panic!("Exception: {}", irqn); +unsafe fn DefaultHandler(_irqn: i16) { + // custom default handler + // irqn is negative for Cortex-M exceptions + // irqn is positive for device specific (line IRQ) + // set_led(true);(true); + // panic!("Exception: {}", irqn); + asm::bkpt(); + loop {} } +#[allow(non_snake_case)] #[exception] -fn HardFault(_ef: &ExceptionFrame) -> ! { -// Blink 3 times long when exception occures - delay_n(10); - for _ in 0..3 { - // set_led(true); - // delay_n(1000); - // set_led(false); - // delay_n(555); - } +unsafe fn HardFault(_ef: &ExceptionFrame) -> ! { + asm::bkpt(); loop {} } -// define what happens in an Out Of Memory (OOM) condition -#[alloc_error_handler] -fn alloc_error(_layout: Layout) -> ! { - //set_led(true); +// We no longer need to use #[alloc_error_handler] since v1.68. +// It will automatically call the panic handler. +#[panic_handler] +fn panic(_info: &PanicInfo) -> ! { asm::bkpt(); loop {} } +#[allow(non_snake_case)] #[no_mangle] -fn vApplicationStackOverflowHook(pxTask: FreeRtosTaskHandle, pcTaskName: FreeRtosCharPtr) { +fn vApplicationStackOverflowHook(_pxTask: FreeRtosTaskHandle, _pcTaskName: FreeRtosCharPtr) { asm::bkpt(); } diff --git a/freertos-rust/src/critical.rs b/freertos-rust/src/critical.rs index 79f8dea9..405d711e 100644 --- a/freertos-rust/src/critical.rs +++ b/freertos-rust/src/critical.rs @@ -37,7 +37,7 @@ impl ExclusiveData { } } - pub fn lock(&self) -> Result, FreeRtosError> { + pub fn lock(&self) -> Result, FreeRtosError> { Ok(ExclusiveDataGuard { __data: &self.data, __lock: CriticalRegion::enter(), @@ -47,7 +47,7 @@ impl ExclusiveData { pub fn lock_from_isr( &self, _context: &mut crate::isr::InterruptContext, - ) -> Result, FreeRtosError> { + ) -> Result, FreeRtosError> { Ok(ExclusiveDataGuardIsr { __data: &self.data }) } } @@ -106,7 +106,7 @@ impl SuspendScheduler { } } - pub fn lock(&self) -> SuspendSchedulerGuard { + pub fn lock(&self) -> SuspendSchedulerGuard<'_,T> { unsafe { freertos_rs_vTaskSuspendAll(); } diff --git a/freertos-rust/src/mutex.rs b/freertos-rust/src/mutex.rs index fb43eff0..6d71542b 100644 --- a/freertos-rust/src/mutex.rs +++ b/freertos-rust/src/mutex.rs @@ -36,7 +36,7 @@ where } /// Try to obtain a lock and mutable access to our inner value - pub fn lock(&self, max_wait: D) -> Result, FreeRtosError> { + pub fn lock(&self, max_wait: D) -> Result, FreeRtosError> { self.mutex.take(max_wait)?; Ok(MutexGuard { diff --git a/freertos-rust/src/semaphore.rs b/freertos-rust/src/semaphore.rs index 75ccef6d..cb5d4768 100644 --- a/freertos-rust/src/semaphore.rs +++ b/freertos-rust/src/semaphore.rs @@ -50,7 +50,7 @@ impl Semaphore { } /// Lock this semaphore in a RAII fashion - pub fn lock(&self, max_wait: D) -> Result { + pub fn lock(&self, max_wait: D) -> Result, FreeRtosError> { self.take(max_wait).map(|()| SemaphoreGuard { owner: self }) }