Git Product home page Git Product logo

freertos-rust's People

Contributors

agerasev avatar apullin avatar iamthecarl avatar isaacdynamo avatar jalonwong avatar jean-santos avatar joe1994 avatar johnathancn avatar manishearth avatar niondir avatar reitermarkus avatar schteve avatar sheref-sidarous avatar stefanb7 avatar tothero avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

freertos-rust's Issues

Linux Example

Since the initial version was developed on Windows, we lack a Linux example.

Pull requests are very welcome.

Proper way to use queue from different threads

What is the proper way to share a queue object between 2 threads? Creating a local queue in main function and passing references to it to the threads does not compile:

 let queue = Queue::<u8>::new(4).unwrap();

 let ref_queue_1 = &queue;
 let ref_queue_2 = &queue;

 Task::new()
     .name("blinker")
     .stack_size(128)
     .priority(TaskPriority(2))
     .start(move || {
         ref_queue_1.send(1, Duration::infinite());
     })
     .unwrap();

 Task::new()
     .name("printer")
     .stack_size(128)
     .priority(TaskPriority(2))
     .start(move || {
         let _ = ref_queue_2.receive(Duration::infinite());
     })
     .unwrap();

 FreeRtosUtils::start_scheduler();

Is there a method to achieve this that I am not aware of? Or the only way is to have a global mutex-protected queue that is accessed by both threads?

Possible incorrect timing for `CurrentTask::delay;` on stm32f411

First of all, thanks for your hard work on this project.

I took the stm32f411 black pill example and promoted it to a free-standing repo. I was very happy to see it works nicely with defmt and newer versions of the stm32f4xx-hal. However, I did observe that the blinking frequency is way higher than 1Hz.

https://github.com/barafael/really-fast-buttons/blob/a2081814e0dbff1d8ebc5d2aaa62761cebbb0252/freertos-tasks/src/main.rs#L70

More like 6Hz estimated. This was also the case before I upgraded the hal dependencies and set

        let clocks = rcc.cfgr.use_hse(25.MHz()).sysclk(48.MHz()).freeze();

I'm not sure if this issue is even in the right place, perhaps I shouldn't touch the timer configuration when FreeRTOS already does it?

linux port: configCPU_CLOCK_HZ not defined

cargo:warning=/home/void/FreeRTOS-rust/freertos-rust/src/freertos/shim.c: In function 'freertos_rs_get_configCPU_CLOCK_HZ':
cargo:warning=/home/void/FreeRTOS-rust/freertos-rust/src/freertos/shim.c:117:10: error: 'configCPU_CLOCK_HZ' undeclared (first use in this function)
cargo:warning= 117 | return configCPU_CLOCK_HZ;
cargo:warning= | ^~~~~~~~~~~~~~~~~~

I realize this probably needs be defined in the examples / FreeRTOSConfig.h . Not sure what value to put there though...

Use `bool` for shim returns

The existing code in the shim layer returns 0 or 1 as a proxy for a boolean. I wonder if there's opportunity to change those to bool. It seems based on this PR that bool is effectively the FFI type for itself, which is why there's nothing in ffi for it. I'm not 100% sure, but I'm having a hard time imagining a situation where this could cause any problems. Although, on second glance the 0 and 1 values are (at least sometimes) reversed - where 0 means success and 1 means failure. So we'd have to be careful to get the logic correct.

bound `P: AsRef<Path>` for heap in freertos-cargo-build cannot infer type for string argument

I am trying to build this package with the latest nightly, and I am getting the following error:

error[E0282]: type annotations needed
 --> build.rs:8:7
  |
8 |     b.heap("heap_4.c".to_string());              // Set the heap_?.c allocator to use from
  |       ^^^^ cannot infer type for type parameter `P` declared on the associated function `heap`

error: aborting due to previous error

Notably, in my build.rs, I made the modification of explicit String conversion, otherwise I get a cargo error about mismatched types:
b.heap("heap_4.c".to_string() );

Relaxing the signature to: pub fn heap(&mut self, file_name: String)
appears to resolve the build issue, although that is just a guess, and other regressions may be introduced.

C files are not rebuit when modified

C files built through build.rs are not rebuilt when they are modified. The developer has to do something like cargo clean and then build again. There's also no warning or message that the C files are newer and may need to be rebuilt. This all results in the developer potentially building / running with out of date code and can easily cause confusing issues.

By default, Cargo doesn't know about files that are managed by build.rs so this makes sense. But it can be told about these files through cargo:rerun-if-changed. The files built through freertos-cargo-build should automatically have this applied if possible (at least shim.c but ideally also the FreeRTOS-Kernel source). There may be other files built by the user's build.rs through the inner cc, which should be left alone so the user can decide what to do.

Missing semaphore functions

It looks like these two functions are missing from the shim layer. We might want to add them someday. There are also FromISR variants for them.

  • xSemaphoreGetMutexHolder()
  • uxSemaphoreGetCount()

It's not much help just having the functions in the shim layer - we'd also want to add Rust code to make use of it. Both are probably straightforward as we already have Mutex types. Semaphore doesn't have a Counting-specific type (should it?), but GetCount is defined on both counting and binary semaphores anyway.

Failed to run custom build command ( Inline Assembly Constraints error)

I get the following warning when trying to compile my code. It worked previously... I had this issue before and back then what helped was to start the project from scratch again (adding the submodule). But now this does not seem to work. Does anyone have an idea of what is happening here?


running: "cc" "-Os" "-ffunction-sections" "-fdata-sections" "-fPIC" "-gdwarf-2" "-fno-omit-frame-pointer" "-arch" "arm64" "-I" "FreeRTOS-Kernel/include" "-I" "FreeRTOS-Kernel/portable/GCC/ARM_CM4F" "-I" "include" "-Wall" "-Wextra" "-o" "/Users/linus/coconut-elu-embedded/target/release/build/coconut-elu-embedded-582a3cfb0564ffbf/out/FreeRTOS-Kernel/list.o" "-c" "FreeRTOS-Kernel/list.c"
  cargo:warning=In file included from FreeRTOS-Kernel/list.c:37:

  cargo:warning=In file included from FreeRTOS-Kernel/include/FreeRTOS.h:103:

  cargo:warning=In file included from FreeRTOS-Kernel/include/portable.h:53:

  cargo:warning=FreeRTOS-Kernel/portable/GCC/ARM_CM4F/portmacro.h:155:48: warning: value size does not match register size specified by the constraint and modifier [-Wasm-operand-widths]

  cargo:warning=        __asm volatile ( "clz %0, %1" : "=r" ( ucReturn ) : "r" ( ulBitmap ) : "memory" );

  cargo:warning=                                               ^

  cargo:warning=FreeRTOS-Kernel/portable/GCC/ARM_CM4F/portmacro.h:155:31: note: use constraint modifier "w"

  cargo:warning=        __asm volatile ( "clz %0, %1" : "=r" ( ucReturn ) : "r" ( ulBitmap ) : "memory" );

  cargo:warning=                              ^~

  cargo:warning=                              %w0

  cargo:warning=FreeRTOS-Kernel/portable/GCC/ARM_CM4F/portmacro.h:155:67: warning: value size does not match register size specified by the constraint and modifier [-Wasm-operand-widths]

  cargo:warning=        __asm volatile ( "clz %0, %1" : "=r" ( ucReturn ) : "r" ( ulBitmap ) : "memory" );

  cargo:warning=                                                                  ^

  cargo:warning=FreeRTOS-Kernel/portable/GCC/ARM_CM4F/portmacro.h:155:35: note: use constraint modifier "w"

  cargo:warning=        __asm volatile ( "clz %0, %1" : "=r" ( ucReturn ) : "r" ( ulBitmap ) : "memory" );

  cargo:warning=                                  ^~

  cargo:warning=                                  %w1

  cargo:warning=FreeRTOS-Kernel/portable/GCC/ARM_CM4F/portmacro.h:197:46: warning: value size does not match register size specified by the constraint and modifier [-Wasm-operand-widths]

  cargo:warning=    __asm volatile ( "mrs %0, ipsr" : "=r" ( ulCurrentInterrupt )::"memory" );

  cargo:warning=                                             ^

  cargo:warning=FreeRTOS-Kernel/portable/GCC/ARM_CM4F/portmacro.h:197:27: note: use constraint modifier "w"

  cargo:warning=    __asm volatile ( "mrs %0, ipsr" : "=r" ( ulCurrentInterrupt )::"memory" );

  cargo:warning=                          ^~

  cargo:warning=                          %w0

  cargo:warning=FreeRTOS-Kernel/portable/GCC/ARM_CM4F/portmacro.h:223:18: warning: value size does not match register size specified by the constraint and modifier [-Wasm-operand-widths]

  cargo:warning=        : "=r" ( ulNewBASEPRI ) : "i" ( configMAX_SYSCALL_INTERRUPT_PRIORITY ) : "memory"

  cargo:warning=                 ^

  cargo:warning=FreeRTOS-Kernel/portable/GCC/ARM_CM4F/portmacro.h:219:17: note: use constraint modifier "w"

  cargo:warning=        "   mov %0, %1                                              \n" \

  cargo:warning=                ^~

  cargo:warning=                %w0

  cargo:warning=FreeRTOS-Kernel/portable/GCC/ARM_CM4F/portmacro.h:223:18: warning: value size does not match register size specified by the constraint and modifier [-Wasm-operand-widths]

  cargo:warning=        : "=r" ( ulNewBASEPRI ) : "i" ( configMAX_SYSCALL_INTERRUPT_PRIORITY ) : "memory"

  cargo:warning=                 ^

  cargo:warning=FreeRTOS-Kernel/portable/GCC/ARM_CM4F/portmacro.h:220:26: note: use constraint modifier "w"

  cargo:warning=        "   msr basepri, %0                                         \n" \

  cargo:warning=                         ^~

  cargo:warning=                         %w0

  cargo:warning=FreeRTOS-Kernel/portable/GCC/ARM_CM4F/portmacro.h:240:18: warning: value size does not match register size specified by the constraint and modifier [-Wasm-operand-widths]

  cargo:warning=        : "=r" ( ulOriginalBASEPRI ), "=r" ( ulNewBASEPRI ) : "i" ( configMAX_SYSCALL_INTERRUPT_PRIORITY ) : "memory"

  cargo:warning=                 ^

  cargo:warning=FreeRTOS-Kernel/portable/GCC/ARM_CM4F/portmacro.h:235:17: note: use constraint modifier "w"

  cargo:warning=        "   mrs %0, basepri                                         \n" \

  cargo:warning=                ^~

  cargo:warning=                %w0

  cargo:warning=FreeRTOS-Kernel/portable/GCC/ARM_CM4F/portmacro.h:240:46: warning: value size does not match register size specified by the constraint and modifier [-Wasm-operand-widths]

  cargo:warning=        : "=r" ( ulOriginalBASEPRI ), "=r" ( ulNewBASEPRI ) : "i" ( configMAX_SYSCALL_INTERRUPT_PRIORITY ) : "memory"

  cargo:warning=                                             ^

  cargo:warning=FreeRTOS-Kernel/portable/GCC/ARM_CM4F/portmacro.h:236:17: note: use constraint modifier "w"

  cargo:warning=        "   mov %1, %2                                              \n" \

  cargo:warning=                ^~

  cargo:warning=                %w1

  cargo:warning=FreeRTOS-Kernel/portable/GCC/ARM_CM4F/portmacro.h:240:46: warning: value size does not match register size specified by the constraint and modifier [-Wasm-operand-widths]

  cargo:warning=        : "=r" ( ulOriginalBASEPRI ), "=r" ( ulNewBASEPRI ) : "i" ( configMAX_SYSCALL_INTERRUPT_PRIORITY ) : "memory"

  cargo:warning=                                             ^

  cargo:warning=FreeRTOS-Kernel/portable/GCC/ARM_CM4F/portmacro.h:237:26: note: use constraint modifier "w"

  cargo:warning=        "   msr basepri, %1                                         \n" \

  cargo:warning=                         ^~

  cargo:warning=                         %w1

  cargo:warning=FreeRTOS-Kernel/portable/GCC/ARM_CM4F/portmacro.h:253:39: warning: value size does not match register size specified by the constraint and modifier [-Wasm-operand-widths]

  cargo:warning=        "   msr basepri, %0 " ::"r" ( ulNewMaskValue ) : "memory"

  cargo:warning=                                      ^

  cargo:warning=FreeRTOS-Kernel/portable/GCC/ARM_CM4F/portmacro.h:253:26: note: use constraint modifier "w"

  cargo:warning=        "   msr basepri, %0 " ::"r" ( ulNewMaskValue ) : "memory"

  cargo:warning=                         ^~

  cargo:warning=                         %w0

  cargo:warning=9 warnings generated.

  exit status: 0
  running: "cc" "-Os" "-ffunction-sections" "-fdata-sections" "-fPIC" "-gdwarf-2" "-fno-omit-frame-pointer" "-arch" "arm64" "-I" "FreeRTOS-Kernel/include" "-I" "FreeRTOS-Kernel/portable/GCC/ARM_CM4F" "-I" "include" "-Wall" "-Wextra" "-o" "/Users/linus/coconut-elu-embedded/target/release/build/coconut-elu-embedded-582a3cfb0564ffbf/out/FreeRTOS-Kernel/stream_buffer.o" "-c" "FreeRTOS-Kernel/stream_buffer.c"
  cargo:warning=In file included from FreeRTOS-Kernel/stream_buffer.c:38:

  cargo:warning=In file included from FreeRTOS-Kernel/include/FreeRTOS.h:103:

  cargo:warning=In file included from FreeRTOS-Kernel/include/portable.h:53:

  cargo:warning=FreeRTOS-Kernel/portable/GCC/ARM_CM4F/portmacro.h:155:48: warning: value size does not match register size specified by the constraint and modifier [-Wasm-operand-widths]

  cargo:warning=        __asm volatile ( "clz %0, %1" : "=r" ( ucReturn ) : "r" ( ulBitmap ) : "memory" );

  cargo:warning=                                               ^

  cargo:warning=FreeRTOS-Kernel/portable/GCC/ARM_CM4F/portmacro.h:155:31: note: use constraint modifier "w"

  cargo:warning=        __asm volatile ( "clz %0, %1" : "=r" ( ucReturn ) : "r" ( ulBitmap ) : "memory" );

  cargo:warning=                              ^~

  cargo:warning=                              %w0

  cargo:warning=FreeRTOS-Kernel/portable/GCC/ARM_CM4F/portmacro.h:155:67: warning: value size does not match register size specified by the constraint and modifier [-Wasm-operand-widths]

  cargo:warning=        __asm volatile ( "clz %0, %1" : "=r" ( ucReturn ) : "r" ( ulBitmap ) : "memory" );

  cargo:warning=                                                                  ^

  cargo:warning=FreeRTOS-Kernel/portable/GCC/ARM_CM4F/portmacro.h:155:35: note: use constraint modifier "w"

  cargo:warning=        __asm volatile ( "clz %0, %1" : "=r" ( ucReturn ) : "r" ( ulBitmap ) : "memory" );

  cargo:warning=                                  ^~

  cargo:warning=                                  %w1

  cargo:warning=FreeRTOS-Kernel/portable/GCC/ARM_CM4F/portmacro.h:197:46: warning: value size does not match register size specified by the constraint and modifier [-Wasm-operand-widths]

  cargo:warning=    __asm volatile ( "mrs %0, ipsr" : "=r" ( ulCurrentInterrupt )::"memory" );

  cargo:warning=                                             ^

  cargo:warning=FreeRTOS-Kernel/portable/GCC/ARM_CM4F/portmacro.h:197:27: note: use constraint modifier "w"

  cargo:warning=    __asm volatile ( "mrs %0, ipsr" : "=r" ( ulCurrentInterrupt )::"memory" );

  cargo:warning=                          ^~

  cargo:warning=                          %w0

  cargo:warning=FreeRTOS-Kernel/portable/GCC/ARM_CM4F/portmacro.h:223:18: warning: value size does not match register size specified by the constraint and modifier [-Wasm-operand-widths]

  cargo:warning=        : "=r" ( ulNewBASEPRI ) : "i" ( configMAX_SYSCALL_INTERRUPT_PRIORITY ) : "memory"

  cargo:warning=                 ^

  cargo:warning=FreeRTOS-Kernel/portable/GCC/ARM_CM4F/portmacro.h:219:17: note: use constraint modifier "w"

  cargo:warning=        "   mov %0, %1                                              \n" \

  cargo:warning=                ^~

  cargo:warning=                %w0

  cargo:warning=FreeRTOS-Kernel/portable/GCC/ARM_CM4F/portmacro.h:223:18: warning: value size does not match register size specified by the constraint and modifier [-Wasm-operand-widths]

  cargo:warning=        : "=r" ( ulNewBASEPRI ) : "i" ( configMAX_SYSCALL_INTERRUPT_PRIORITY ) : "memory"

  cargo:warning=                 ^

  cargo:warning=FreeRTOS-Kernel/portable/GCC/ARM_CM4F/portmacro.h:220:26: note: use constraint modifier "w"

  cargo:warning=        "   msr basepri, %0                                         \n" \

  cargo:warning=                         ^~

  cargo:warning=                         %w0

  cargo:warning=FreeRTOS-Kernel/portable/GCC/ARM_CM4F/portmacro.h:240:18: warning: value size does not match register size specified by the constraint and modifier [-Wasm-operand-widths]

  cargo:warning=        : "=r" ( ulOriginalBASEPRI ), "=r" ( ulNewBASEPRI ) : "i" ( configMAX_SYSCALL_INTERRUPT_PRIORITY ) : "memory"

  cargo:warning=                 ^

  cargo:warning=FreeRTOS-Kernel/portable/GCC/ARM_CM4F/portmacro.h:235:17: note: use constraint modifier "w"

  cargo:warning=        "   mrs %0, basepri                                         \n" \

  cargo:warning=                ^~

  cargo:warning=                %w0

  cargo:warning=FreeRTOS-Kernel/portable/GCC/ARM_CM4F/portmacro.h:240:46: warning: value size does not match register size specified by the constraint and modifier [-Wasm-operand-widths]

  cargo:warning=        : "=r" ( ulOriginalBASEPRI ), "=r" ( ulNewBASEPRI ) : "i" ( configMAX_SYSCALL_INTERRUPT_PRIORITY ) : "memory"

  cargo:warning=                                             ^

  cargo:warning=FreeRTOS-Kernel/portable/GCC/ARM_CM4F/portmacro.h:236:17: note: use constraint modifier "w"

  cargo:warning=        "   mov %1, %2                                              \n" \

  cargo:warning=                ^~

  cargo:warning=                %w1

  cargo:warning=FreeRTOS-Kernel/portable/GCC/ARM_CM4F/portmacro.h:240:46: warning: value size does not match register size specified by the constraint and modifier [-Wasm-operand-widths]

  cargo:warning=        : "=r" ( ulOriginalBASEPRI ), "=r" ( ulNewBASEPRI ) : "i" ( configMAX_SYSCALL_INTERRUPT_PRIORITY ) : "memory"

  cargo:warning=                                             ^

  cargo:warning=FreeRTOS-Kernel/portable/GCC/ARM_CM4F/portmacro.h:237:26: note: use constraint modifier "w"

  cargo:warning=        "   msr basepri, %1                                         \n" \

  cargo:warning=                         ^~

  cargo:warning=                         %w1

  cargo:warning=FreeRTOS-Kernel/portable/GCC/ARM_CM4F/portmacro.h:253:39: warning: value size does not match register size specified by the constraint and modifier [-Wasm-operand-widths]

  cargo:warning=        "   msr basepri, %0 " ::"r" ( ulNewMaskValue ) : "memory"

  cargo:warning=                                      ^

  cargo:warning=FreeRTOS-Kernel/portable/GCC/ARM_CM4F/portmacro.h:253:26: note: use constraint modifier "w"

  cargo:warning=        "   msr basepri, %0 " ::"r" ( ulNewMaskValue ) : "memory"

  cargo:warning=                         ^~

  cargo:warning=                         %w0

  cargo:warning=FreeRTOS-Kernel/portable/GCC/ARM_CM4F/portmacro.h:235:9: error: expected readable system register

  cargo:warning=        "   mrs %0, basepri                                         \n" \

  cargo:warning=        ^

  cargo:warning=<inline asm>:1:14: note: instantiated into assembly here

  cargo:warning=           mrs x22, basepri                                         

  cargo:warning=                    ^

  cargo:warning=In file included from FreeRTOS-Kernel/stream_buffer.c:38:

  cargo:warning=In file included from FreeRTOS-Kernel/include/FreeRTOS.h:103:

  cargo:warning=In file included from FreeRTOS-Kernel/include/portable.h:53:

  cargo:warning=FreeRTOS-Kernel/portable/GCC/ARM_CM4F/portmacro.h:237:10: error: expected writable system register or pstate

  cargo:warning=        "   msr basepri, %1                                         \n" \

  cargo:warning=         ^

  cargo:warning=<inline asm>:3:8: note: instantiated into assembly here

  cargo:warning=   msr basepri, x8                                         

  cargo:warning=       ^

  cargo:warning=In file included from FreeRTOS-Kernel/stream_buffer.c:38:

  cargo:warning=In file included from FreeRTOS-Kernel/include/FreeRTOS.h:103:

  cargo:warning=In file included from FreeRTOS-Kernel/include/portable.h:53:

  cargo:warning=FreeRTOS-Kernel/portable/GCC/ARM_CM4F/portmacro.h:239:10: error: too few operands for instruction

  cargo:warning=        "   dsb                                                     \n" \

  cargo:warning=         ^

  cargo:warning=<inline asm>:5:4: note: instantiated into assembly here

  cargo:warning=   dsb                                                     

  cargo:warning=   ^~~

  cargo:warning=In file included from FreeRTOS-Kernel/stream_buffer.c:38:

  cargo:warning=In file included from FreeRTOS-Kernel/include/FreeRTOS.h:103:

  cargo:warning=In file included from FreeRTOS-Kernel/include/portable.h:53:

  cargo:warning=FreeRTOS-Kernel/portable/GCC/ARM_CM4F/portmacro.h:253:9: error: expected writable system register or pstate

  cargo:warning=        "   msr basepri, %0 " ::"r" ( ulNewMaskValue ) : "memory"

  cargo:warning=        ^

  cargo:warning=<inline asm>:1:9: note: instantiated into assembly here

  cargo:warning=           msr basepri, x22 

  cargo:warning=               ^

  cargo:warning=In file included from FreeRTOS-Kernel/stream_buffer.c:38:

  cargo:warning=In file included from FreeRTOS-Kernel/include/FreeRTOS.h:103:

  cargo:warning=In file included from FreeRTOS-Kernel/include/portable.h:53:

  cargo:warning=FreeRTOS-Kernel/portable/GCC/ARM_CM4F/portmacro.h:235:9: error: expected readable system register

  cargo:warning=        "   mrs %0, basepri                                         \n" \

  cargo:warning=        ^

  cargo:warning=<inline asm>:1:14: note: instantiated into assembly here

  cargo:warning=           mrs x21, basepri                                         

  cargo:warning=                    ^

  cargo:warning=In file included from FreeRTOS-Kernel/stream_buffer.c:38:

  cargo:warning=In file included from FreeRTOS-Kernel/include/FreeRTOS.h:103:

  cargo:warning=In file included from FreeRTOS-Kernel/include/portable.h:53:

  cargo:warning=FreeRTOS-Kernel/portable/GCC/ARM_CM4F/portmacro.h:237:10: error: expected writable system register or pstate

  cargo:warning=        "   msr basepri, %1                                         \n" \

  cargo:warning=         ^

  cargo:warning=<inline asm>:3:8: note: instantiated into assembly here

  cargo:warning=   msr basepri, x8                                         

  cargo:warning=       ^

  cargo:warning=In file included from FreeRTOS-Kernel/stream_buffer.c:38:

  cargo:warning=In file included from FreeRTOS-Kernel/include/FreeRTOS.h:103:

  cargo:warning=In file included from FreeRTOS-Kernel/include/portable.h:53:

  cargo:warning=FreeRTOS-Kernel/portable/GCC/ARM_CM4F/portmacro.h:239:10: error: too few operands for instruction

  cargo:warning=        "   dsb                                                     \n" \

  cargo:warning=         ^

  cargo:warning=<inline asm>:5:4: note: instantiated into assembly here

  cargo:warning=   dsb                                                     

  cargo:warning=   ^~~

  cargo:warning=In file included from FreeRTOS-Kernel/stream_buffer.c:38:

  cargo:warning=In file included from FreeRTOS-Kernel/include/FreeRTOS.h:103:

  cargo:warning=In file included from FreeRTOS-Kernel/include/portable.h:53:

  cargo:warning=FreeRTOS-Kernel/portable/GCC/ARM_CM4F/portmacro.h:253:9: error: expected writable system register or pstate

  cargo:warning=        "   msr basepri, %0 " ::"r" ( ulNewMaskValue ) : "memory"

  cargo:warning=        ^

  cargo:warning=<inline asm>:1:9: note: instantiated into assembly here

  cargo:warning=           msr basepri, x21 

  cargo:warning=               ^

  cargo:warning=In file included from FreeRTOS-Kernel/stream_buffer.c:38:

  cargo:warning=In file included from FreeRTOS-Kernel/include/FreeRTOS.h:103:

  cargo:warning=In file included from FreeRTOS-Kernel/include/portable.h:53:

  cargo:warning=FreeRTOS-Kernel/portable/GCC/ARM_CM4F/portmacro.h:235:9: error: expected readable system register

  cargo:warning=        "   mrs %0, basepri                                         \n" \

  cargo:warning=        ^

  cargo:warning=<inline asm>:1:14: note: instantiated into assembly here

  cargo:warning=           mrs x21, basepri                                         

  cargo:warning=                    ^

  cargo:warning=In file included from FreeRTOS-Kernel/stream_buffer.c:38:

  cargo:warning=In file included from FreeRTOS-Kernel/include/FreeRTOS.h:103:

  cargo:warning=In file included from FreeRTOS-Kernel/include/portable.h:53:

  cargo:warning=FreeRTOS-Kernel/portable/GCC/ARM_CM4F/portmacro.h:237:10: error: expected writable system register or pstate

  cargo:warning=        "   msr basepri, %1                                         \n" \

  cargo:warning=         ^

  cargo:warning=<inline asm>:3:8: note: instantiated into assembly here

  cargo:warning=   msr basepri, x8                                         

  cargo:warning=       ^

  cargo:warning=In file included from FreeRTOS-Kernel/stream_buffer.c:38:

  cargo:warning=In file included from FreeRTOS-Kernel/include/FreeRTOS.h:103:

  cargo:warning=In file included from FreeRTOS-Kernel/include/portable.h:53:

  cargo:warning=FreeRTOS-Kernel/portable/GCC/ARM_CM4F/portmacro.h:239:10: error: too few operands for instruction

  cargo:warning=        "   dsb                                                     \n" \

  cargo:warning=         ^

  cargo:warning=<inline asm>:5:4: note: instantiated into assembly here

  cargo:warning=   dsb                                                     

  cargo:warning=   ^~~

  cargo:warning=In file included from FreeRTOS-Kernel/stream_buffer.c:38:

  cargo:warning=In file included from FreeRTOS-Kernel/include/FreeRTOS.h:103:

  cargo:warning=In file included from FreeRTOS-Kernel/include/portable.h:53:

  cargo:warning=FreeRTOS-Kernel/portable/GCC/ARM_CM4F/portmacro.h:253:9: error: expected writable system register or pstate

  cargo:warning=        "   msr basepri, %0 " ::"r" ( ulNewMaskValue ) : "memory"

  cargo:warning=        ^

  cargo:warning=<inline asm>:1:9: note: instantiated into assembly here

  cargo:warning=           msr basepri, x21 

  cargo:warning=               ^

  cargo:warning=In file included from FreeRTOS-Kernel/stream_buffer.c:38:

  cargo:warning=In file included from FreeRTOS-Kernel/include/FreeRTOS.h:103:

  cargo:warning=In file included from FreeRTOS-Kernel/include/portable.h:53:

  cargo:warning=FreeRTOS-Kernel/portable/GCC/ARM_CM4F/portmacro.h:235:9: error: expected readable system register

  cargo:warning=        "   mrs %0, basepri                                         \n" \

  cargo:warning=        ^

  cargo:warning=<inline asm>:1:14: note: instantiated into assembly here

  cargo:warning=           mrs x21, basepri                                         

  cargo:warning=                    ^

  cargo:warning=In file included from FreeRTOS-Kernel/stream_buffer.c:38:

  cargo:warning=In file included from FreeRTOS-Kernel/include/FreeRTOS.h:103:

  cargo:warning=In file included from FreeRTOS-Kernel/include/portable.h:53:

  cargo:warning=FreeRTOS-Kernel/portable/GCC/ARM_CM4F/portmacro.h:237:10: error: expected writable system register or pstate

  cargo:warning=        "   msr basepri, %1                                         \n" \

  cargo:warning=         ^

  cargo:warning=<inline asm>:3:8: note: instantiated into assembly here

  cargo:warning=   msr basepri, x8                                         

  cargo:warning=       ^

  cargo:warning=In file included from FreeRTOS-Kernel/stream_buffer.c:38:

  cargo:warning=In file included from FreeRTOS-Kernel/include/FreeRTOS.h:103:

  cargo:warning=In file included from FreeRTOS-Kernel/include/portable.h:53:

  cargo:warning=FreeRTOS-Kernel/portable/GCC/ARM_CM4F/portmacro.h:239:10: error: too few operands for instruction

  cargo:warning=        "   dsb                                                     \n" \

  cargo:warning=         ^

  cargo:warning=<inline asm>:5:4: note: instantiated into assembly here

  cargo:warning=   dsb                                                     

  cargo:warning=   ^~~

  cargo:warning=In file included from FreeRTOS-Kernel/stream_buffer.c:38:

  cargo:warning=In file included from FreeRTOS-Kernel/include/FreeRTOS.h:103:

  cargo:warning=In file included from FreeRTOS-Kernel/include/portable.h:53:

  cargo:warning=FreeRTOS-Kernel/portable/GCC/ARM_CM4F/portmacro.h:253:9: error: expected writable system register or pstate

  cargo:warning=        "   msr basepri, %0 " ::"r" ( ulNewMaskValue ) : "memory"

  cargo:warning=        ^

  cargo:warning=<inline asm>:1:9: note: instantiated into assembly here

  cargo:warning=           msr basepri, x21 

  cargo:warning=               ^

  cargo:warning=9 warnings and 16 errors generated.

  exit status: 1

Blackpill example blink rate is wrong

It seems the blackpill example blinks at the incorrect rate. It should blink with one toggle per second (0.5 Hz blink rate) with the given task timings but is going too fast. This is likely due to configCPU_CLOCK_HZ being set incorrectly.

See #44

Use FreeRtosSemaphoreHandle for semaphore functions

shim.rs has a bunch of semaphore functions that use FreeRtosQueueHandle instead of FreeRtosSemaphoreHandle. It's the same underlying type so it should be a non-functional change to switch over.

Also review other types to see if there are others that could be improved.

Looking for Maintainer

The project was created in the urge of using Rust for our embedded development and was a first proof of concept. Unfortunately the real world makes it much harder to migrate to rust than I would like. That's the reason why we do not use the library in production yet.

On the other side I see a lot of interest in moving the code forward and welcome this a lot. I just feel too inactive on GitHub to maintain the project alone with the Quality it deserves.

If there is someone who like to help maintaining the library I'm open for suggestions.

@schteve I just merged a lot of PR from you. If you have long term interest to use and develop the library, just let me know.
@reitermarkus same holds for you.

FreeRTOS submodule doesn't have Linux port

thread 'main' panicked at 'Directory freertos_port_dir does not exist: FreeRTOS-Kernel/portable/GCC/Linux', freertos-rust-examples/build.rs:61:38

Looks like this is recent regression following change from in-tree copy of Kernel to submodule.
I checked upstream and can't find trace of that Linux folder ever being there, maybe it was added to the local copy in this repo

Potential Bug Fix. Tested on Cortex M4

Hi;
I wanted to link FreeRTOS in a project to use is as its kernel. I am using Cortex M4F. But it wasn't passing shim_sanity_check function. Turns out the problem was where task.h was defined as;

typedef struct xTASK_STATUS
{
	TaskHandle_t xHandle;			/* The handle of the task to which the rest of the information in the structure relates. */
	const char *pcTaskName;			/* A pointer to the task's name.  This value will be invalid if the task was deleted since the structure was populated! */ /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
	UBaseType_t xTaskNumber;		/* A number unique to the task. */
	eTaskState eCurrentState;		/* The state in which the task existed when the structure was populated. */
	UBaseType_t uxCurrentPriority;	/* The priority at which the task was running (may be inherited) when the structure was populated. */
	UBaseType_t uxBasePriority;		/* The priority to which the task will return if the task's current priority has been inherited to avoid unbounded priority inversion when obtaining a mutex.  Only valid if configUSE_MUTEXES is defined as 1 in FreeRTOSConfig.h. */
	uint32_t ulRunTimeCounter;		/* The total run time allocated to the task so far, as defined by the run time stats clock.  See http://www.freertos.org/rtos-run-time-stats.html.  Only valid when configGENERATE_RUN_TIME_STATS is defined as 1 in FreeRTOSConfig.h. */
	StackType_t *pxStackBase;		/* Points to the lowest address of the task's stack area. */
	configSTACK_DEPTH_TYPE usStackHighWaterMark;	/* The minimum amount of stack space that has remained for the task since the task was created.  The closer this value is to zero the closer the task has come to overflowing its stack. */
} TaskStatus_t;

but in base.rs we needed this;

pub struct FreeRtosTaskStatusFfi {
    pub handle: FreeRtosTaskHandle,
    pub task_name: FreeRtosCharPtr,
    pub task_number: FreeRtosUBaseType,
    pub task_state: FreeRtosTaskState,
    pub current_priority: FreeRtosUBaseType,
    pub base_priority: FreeRtosUBaseType,
    pub run_time_counter: FreeRtosUnsignedLong,
    pub stack_base: FreeRtosCharPtr, // <- added this line
    pub stack_high_water_mark: FreeRtosUnsignedShort,
}

You can take a look at my fork there and the place I tried to use it was the Prust repo.
Right now I am able to use multiple simple tasks (printing infinite loop). I wanted you to know was this intentional or why did shim_sanity_check on other projects?

Add Cargo features for functionality

Woudl it be possible to add Cargo features for the various bits of functionality? For example, I only want the allocator; otherwise I'm working with a no_std + alloc crate.

Proposal: re-organize examples to contain their own target and dependencies

Currently, the dependencies are tied to the target-triple in freertos-rust-examples/Cargo.toml, and the build.rs ties example paths directly to targets.

After some tinkering with cargo, it seems there might not be a way to improve on this.

However, if each "example" is reorganized into its own cargo binary project, then:

  • the target triple can be put into .cargo/config.toml for each
  • dependencies for each can be made unique
  • build.rs does not need to link targets to example paths

proposed reorg here:
https://github.com/apullin/FreeRTOS-rust/tree/examples_reorg/freertos-rust-examples/examples/stm32f407-segger-trace

This might be moot, since the "examples" should just be templates, and any new project would have a project-specific build.rs and config.toml anyway.

However, this way, each refactored example would be a template to copy & adapt directly (just paths, I think?) for new projects.

`Semaphore::create_binary` can't be used

Quoting the docs:

[...] binary semaphores created using xSemaphoreCreateBinary() are created in a state such that the the semaphore must first be 'given' before it can be 'taken'

The Semaphore API only allows locking, and then dropping the guard, which means there is no way to "give" a binary semaphore. This API also makes using Semaphores as synchronization tools unwieldy.

Unable to disable `vAssertCalled`

I already have an implementation of vAssertCalled in C, and because would like to disable the implementation in this create, but have not found a way.

I tried removing the hooks feature, but it turns out that vAssertCalled is defined anyway. Is this intentional?

struct FreeRtosTaskStatusFfi missing field

I'm new in rust, but i used FreeRTOS before.

I wanted to get Tasks statistics using freertos_rust::task::FreeRtosUtils::get_all_tasks() but i got memory corrupt exception into FreeRTOS heap_4.c module.
Than I found, that struct freertos_rust::task::FreeRtosTaskStatus not an equivalent of struct xTASK_STATUS

Missing field StackType_t * pxStackBase;

So, memory allocation by Vec has incorrect size -> heap corruption.

Sending message from ISR does not work

Sending a message from an ISR through send_from_isr method does not work, but instead it causes panic:

(gdb) bt
#0 panic_halt::panic (info=0x2001f8ac) at src/lib.rs:32
#1 0x0800bf94 in core::panicking::panic_fmt () at library/core/src/panicking.rs:64
#2 0x0800c0be in core::result::unwrap_failed () at library/core/src/result.rs:1750
#3 0x0800bb7e in core::result::Result<alloc::string::String, freertos_rust::base::FreeRtosError>::unwrap<alloc::string::String, freertos_rust::base::FreeRtosError> (self=...)
at /rustc/44f5180584404d18058cbbf224c55255db4fdcbb/library/core/src/result.rs:1090
#4 0x0800abf0 in freertos_rust::hooks::vAssertCalled (file_name_ptr=0x1cd, line=134272464)
at src/hooks.rs:31
#5 0x08003f24 in vPortEnterCritical () at FreeRTOS-Kernel/portable/GCC/ARM_CM4F/port.c:461
#6 0x08002d0c in xTaskResumeAll () at FreeRTOS-Kernel/tasks.c:2193
#7 0x08003a52 in pvPortMalloc (xWantedSize=16) at FreeRTOS-Kernel/portable/MemMang/heap_4.c:287
#8 0x080026c6 in freertos_rs_pvPortMalloc (xWantedSize=8)
at /home/chkolli/.cargo/registry/src/index.crates.io-6f17d22bba15001f/freertos-rust-0.1.2/src/freertos/shim.c:24
#9 0x0800ac78 in freertos_rust::allocator::{impl#0}::alloc (self=0x800ce70, layout=...)
at src/allocator.rs:16
#10 0x08000228 in ::
::__rg_alloc (arg0=8, arg1=1) at src/main.rs:25
#11 0x0800ad7a in alloc::alloc::alloc ()
at /rustc/44f5180584404d18058cbbf224c55255db4fdcbb/library/alloc/src/alloc.rs:95
#12 alloc::alloc::Global::alloc_impl (self=0x2001fe1c, layout=..., zeroed=false)
at /rustc/44f5180584404d18058cbbf224c55255db4fdcbb/library/alloc/src/alloc.rs:177
#13 0x0800b156 in alloc::alloc::{impl#1}::allocate (self=0x2001fe1c, layout=...)
at /rustc/44f5180584404d18058cbbf224c55255db4fdcbb/library/alloc/src/alloc.rs:237
#14 0x0800b318 in alloc::raw_vec::finish_growalloc::alloc::Global (new_layout=...,
current_memory=..., alloc=0x2001fe1c)
at /rustc/44f5180584404d18058cbbf224c55255db4fdcbb/library/alloc/src/raw_vec.rs:476
#15 0x0800b69a in alloc::raw_vec::RawVec<u8, alloc::alloc::Global>::grow_amortized<u8, alloc::alloc::Global> (self=0x2001fe1c, len=0, additional=1)
at /rustc/44f5180584404d18058cbbf224c55255db4fdcbb/library/alloc/src/raw_vec.rs:405
#16 0x0800b752 in alloc::raw_vec::RawVec<u8, alloc::alloc::Global>::reserve_for_push<u8, alloc::alloc::Global> (self=0x2001fe1c, len=0)
at /rustc/44f5180584404d18058cbbf224c55255db4fdcbb/library/alloc/src/raw_vec.rs:303
#17 0x0800b83e in alloc::vec::Vec<u8, alloc::alloc::Global>::push<u8, alloc::alloc::Global> (
self=0x2001fe1c, value=35)
at /rustc/44f5180584404d18058cbbf224c55255db4fdcbb/library/alloc/src/vec/mod.rs:1840
#18 0x0800a7d6 in freertos_rust::utils::str_from_c_string (str=0x358) at src/utils.rs:59
#19 0x0800abe0 in freertos_rust::hooks::vAssertCalled (file_name_ptr=0x358, line=134272464)
at src/hooks.rs:31
#20 0x080040ac in vPortValidateInterruptPriority ()
at FreeRTOS-Kernel/portable/GCC/ARM_CM4F/port.c:856
#21 0x08004996 in xQueueGenericSendFromISR (xQueue=0x20000140 <ucHeap+8>, pvItemToQueue=0x2001ff5e,
pxHigherPriorityTaskWoken=0x0, xCopyPosition=0) at FreeRTOS-Kernel/queue.c:1119
#22 0x080027da in freertos_rs_queue_send_isr (queue=0x20000140 <ucHeap+8>, item=0x2001ff5e,
xHigherPriorityTaskWoken=0x0)
at /home/chkolli/.cargo/registry/src/index.crates.io-6f17d22bba15001f/freertos-rust-0.1.2/src/freertos/shim.c:244
#23 0x08001af6 in freertos_rust::queue::Queue::send_from_isr (self=0x200001a8 <ucHeap+112>,
context=0x2001ff98, item=1)
at /home/chkolli/.cargo/registry/src/index.crates.io-6f17d22bba15001f/freertos-rust-0.1.2/src/queue.rs:54

The reason for this is vAssertCalled function that attempts to allocate memory to create a String.

If I remove the corresponding lines from vAssertCalled, my program does not panic but the waiting thread is never woken up. The reason for this is that listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) call in xQueueGenericSendFromISR always returns pdTRUE.

My code (STM32F411RE):

#![no_std]
#![no_main]

////////////////////////////////////////////////////////////////////////////////
use core::cell::RefCell;
use core::ops::DerefMut;
use core::ops::Deref;
use cortex_m::interrupt::Mutex;
use cortex_m_rt::entry;
use freertos_rust::*;
use panic_halt as _;
use stm32f4xx_hal;
use stm32f4xx_hal::gpio::{GpioExt};
use stm32f4xx_hal::interrupt;
use stm32f4xx_hal::pac::USART1;
use stm32f4xx_hal::prelude::*;
use stm32f4xx_hal::serial::{Config, Event, Serial};
extern crate alloc;
use alloc::sync::Arc;

////////////////////////////////////////////////////////////////////////////////

// Global allocator for memory allocations.
#[global_allocator]
static GLOBAL: FreeRtosAllocator = FreeRtosAllocator;

// Required by USART1 interrupt handler
static UART_SERVICE_CHANNEL: Mutex<RefCell<Option<Serial<USART1>>>> =
    Mutex::new(RefCell::new(None));
static UART_MESSAGE_QUEUE: Mutex<RefCell<Option<Arc<Queue<u8>>>>> = Mutex::new(RefCell::new(None));

////////////////////////////////////////////////////////////////////////////////
#[entry]
fn main() -> ! {
    let dp = stm32f4xx_hal::pac::Peripherals::take().unwrap();

    let rcc = dp.RCC.constrain();
    let clocks = rcc
        .cfgr
        .sysclk(100.MHz())
        .hclk(100.MHz())
        .pclk1(50.MHz())
        .pclk2(100.MHz())
        .freeze();

    let gpioa = dp.GPIOA.split();

    let pin_service_channel_tx = gpioa.pa9.into_alternate();
    let pin_service_channel_rx = gpioa.pa10.into_alternate();

    let service_channel_uart = dp
        .USART1
        .serial(
            (pin_service_channel_tx, pin_service_channel_rx),
            Config::default()
                .baudrate(115200.bps())
                .wordlength_8()
                .parity_none(),
            &clocks,
        )
        .unwrap()
        .with_u8_data();

    cortex_m::interrupt::free(|cs| {
        UART_SERVICE_CHANNEL
            .borrow(cs)
            .replace(Some(service_channel_uart))
    });

    let uart_message_queue = Arc::new(Queue::<u8>::new(4).unwrap());

    // To be used from the uart interrupt handler.
    cortex_m::interrupt::free(|cs| {
        UART_MESSAGE_QUEUE
            .borrow(cs)
            .replace(Some(uart_message_queue.clone()))
    });

    Task::new()
        .name("uart_rx")
        .stack_size(1024)
        .priority(TaskPriority(5))
        .start(move || {
            // Enable service channel uart and then proceed to wait for data.
            cortex_m::interrupt::free(|cs| {
                if let Some(ref mut uart) = UART_SERVICE_CHANNEL.borrow(cs).borrow_mut().deref_mut()
                {
                    uart.listen(Event::Rxne);
                    
                    unsafe {
                        // Enable USART1 interrupt in NVIC
                        cortex_m::peripheral::NVIC::unmask(stm32f4xx_hal::interrupt::USART1);
                    }
                    
                }
            });

            loop {
                let _ = uart_message_queue.receive(Duration::infinite());

                cortex_m::interrupt::free(|cs| {
                    if let Some(ref mut uart) =
                        UART_SERVICE_CHANNEL.borrow(cs).borrow_mut().deref_mut()
                    {
                        if let Ok(byte) = uart.read() {
                            // Do something with the received byte.
                        }
                    }
                });
            }
        })
        .unwrap();

    FreeRtosUtils::start_scheduler();
}

#[interrupt]
fn USART1() {
    cortex_m::interrupt::free(|cs| {
        if let Some(ref mut uart) = UART_SERVICE_CHANNEL.borrow(cs).borrow_mut().deref_mut() {
            if uart.is_rx_not_empty() {
                let _ = UART_MESSAGE_QUEUE
                    .borrow(cs)
                    .borrow()
                    .deref()
                    .as_ref()
                    .unwrap()
                    .send_from_isr(&mut InterruptContext::new(), 1);
            }
        }
    });
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.