Skip to content

examples/leds_rust: Add Rust App for blinking the LED #2462

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 5, 2024

Conversation

rushabhvg
Copy link
Contributor

Summary

  • This PR adds examples/leds_rust to call NuttX POSIX APIs like open() and ioctl(), so that it blinks an LED
  • The leds_rust app is also used for testing the GPIO and LED Drivers for Ox64 BL808 SBC and QEMU RISC-V Emulator in Google Summer of Code
  • leds_rust be executed locally on Linux / macOS / Windows, by commenting out the first 2 lines of code
  • The code is based on examples/leds in C, and examples/hello_rust in Rust

New Files in examples/leds_rust

  • Kconfig: Configuration file for leds_rust that defines EXAMPLES_LEDS_RUST
  • Make.defs: Build the app if EXAMPLES_LEDS_RUST is enabled
  • Makefile: Makefile for leds_rust
  • leds_rust_main.rs: Call NuttX POSIX APIs and LED driver to blink the LED
  • nuttx.rs: NuttX Module for Rust to access the NuttX POSIX APIs in a safer way

Impact

  • With this PR, NuttX for Ox64 and QEMU will be able to test and verify the operation of LED in Rust.
  • No impact on existing code, since we are adding a Rust App in examples directory.

Testing

We tested on QEMU RISC-V Emulator with rv-virt:leds (32-bit) and rv-virt:leds64 (64-bit):

$ tools/configure.sh rv-virt:leds / leds64
$ kconfig-tweak --enable CONFIG_EXAMPLES_LEDS_RUST
$ make olddefconfig
...
NuttShell (NSH) NuttX-12.4.0
nsh> uname -a
NuttX 12.4.0 fe45d8aace2 Aug  1 2024 14:03:19 risc-v rv-virt

nsh> leds_rust
Hello, Rust!!
Opening /dev/userleds
Set LED 1 to 1
board_userled: LED 1 set to 1
board_userled: LED 2 set to 0
board_userled: LED 3 set to 0
Sleeping...
Set LED 1 to 0
board_userled: LED 1 set to 0
board_userled: LED 2 set to 0
board_userled: LED 3 set to 0
nsh> 

- This PR adds `examples/leds_rust` to call NuttX POSIX APIs like `open()` and `ioctl()`, so that it blinks an LED
- The `leds_rust` app is also used for testing the GPIO and LED Drivers for Ox64 BL808 SBC and QEMU RISC-V Emulator in Google Summer of Code
- `leds_rust` be executed locally on Linux / macOS / Windows, by commenting out the first 2 lines of code
- The code is based on `examples/leds` in C, and `examples/hello_rust` in Rust

Co-Authored-By: Lup Yuen Lee <[email protected]>
@lupyuen lupyuen marked this pull request as ready for review August 5, 2024 12:21
Copy link
Member

@lupyuen lupyuen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Rushabh for your valuable contribution to Rust Apps on NuttX! This PR completes your coding requirements for Google Summer of Code. We hope you will continue contributing to NuttX after GSoC :-)

@rushabhvg
Copy link
Contributor Author

Yes, I would love to contribute to the NuttX community even after the GSoC 2024 period! Thank you!

@xiaoxiang781216
Copy link
Contributor

let's enable it in one of defconfig to ensure it can pass ci without break in the future.

@xiaoxiang781216 xiaoxiang781216 merged commit 437c903 into apache:master Aug 5, 2024
27 checks passed
@lupyuen
Copy link
Member

lupyuen commented Aug 5, 2024

@xiaoxiang781216 Thanks! I'll create a new defconfig for rv-virt:leds64_rust. Right now it's failing with the incorrect Rust Target riscv64i-unknown-none-elf (should be riscv64gc-unknown-none-elf). I'll fix the Makefile to select the correct Rust Target.

Update: PR for rv-virt:leds64_rust is here: apache/nuttx#12852

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants