You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by "rushabhvg (via GitHub)" <gi...@apache.org> on 2024/07/08 08:16:22 UTC
[PR] examples/hello_rust: Add feature to blink the LED [nuttx-apps]
rushabhvg opened a new pull request, #2437:
URL: https://github.com/apache/nuttx-apps/pull/2437
## Summary
- The existing Rust Demo App `hello_rust` only prints a message, it might be simplistic for a NuttX App. This PR extends `hello_rust` to call NuttX POSIX APIs like `open()` and `ioctl()`, so that it blinks an LED.
- If the LED Driver is not available, the app terminates gracefully.
- The updated `hello_rust` app is also used for testing the GPIO and LED Drivers for Ox64 BL808 SBC in Google Summer of Code.
- The code is based on `examples/leds` in C.
## Modified file examples/hello_rust:
- `hello_rust_main.rs`: Call LED and GPIO drivers to turn the LED on and off
## Impact
- With this PR, NuttX for Ox64 will be able to test and verify the operation of LED through GPIO pins.
- No impact on existing code, since we are extending the functionality of a Rust Demo App.
- [Build Instructions for QEMU RISC-V 32-bit](https://lupyuen.github.io/articles/rust4#build-the-rust-core-library)
- [Build Instructions for QEMU RISC-V 64-bit](https://lupyuen.github.io/articles/rust5#appendix-build-nuttx-for-qemu)
- [Build Instructions for Ox64](https://lupyuen.github.io/articles/rust5#appendix-build-nuttx-for-ox64-sbc)
## Testing
We tested the updated `hello_rust` app on Ox64 Emulator. The app blinks the Simulated LED correctly:
- [Build Instructions for Ox64](https://lupyuen.github.io/articles/rust5#appendix-build-nuttx-for-ox64-sbc)
- [Ox64 Demo Video](https://drive.google.com/file/d/1GEJfIoIvFmWuE_TQJImONJBsgV9onVpw/view?usp=drive_link)
- [Ox64 Test Log](https://gist.github.com/lupyuen/84d9bf8071980a52b558072505430435)
- [Test Log for Ox64 Emulator](https://github.com/rushabhvg/rushabhvg.github.io/blob/master/nuttx/LED%20Blinky%20App/build_log%20b8c1ce45e6%20Jul%20%208%202024%2013_30_17.txt)
```
rushabhvg@rushabhvg-laptop:~/Desktop/nuttx$ ./temu nuttx.cfg
TinyEMU Emulator for Ox64 BL808 RISC-V SBC
NuttShell (NSH)
nsh> nx_start: CPU0: Beginning Idle Loop
nsh> uname -a
nxposix_spawn_exec: ERROR: exec failed: 2
NuttX 0.0.0 b8c1ce45e6 Jul 8 2024 13:30:17 risc-v ox64
nsh> hello_rust
nxtask_activate: hello_rust pid=4,TCB=0x5040b290
nxsig_tcbdispatch: TCB=0x5040b290 pid=4 signo=0 code=0 value=0 masked=NO
Hello, Rust!!
Opening /dev/userleds
Set LED 1 to 1
{"nuttxemu":{"gpio29":1}}
Sleeping...
Set LED 1 to 0
{"nuttxemu":{"gpio29":0}}
nxsig_tcbdispatch: TCB=0x5040af80 pid=3 signo=17 code=5 value=0 masked=NO
nxtask_exit: hello_rust pid=4,TCB=0x5040b290
nxsig_tcbdispatch: TCB=0x5040af80 pid=3 signo=17 code=5 value=0 masked=NO
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] examples/hello_rust: Add feature to blink the LED [nuttx-apps]
Posted by "lupyuen (via GitHub)" <gi...@apache.org>.
lupyuen closed pull request #2437: examples/hello_rust: Add feature to blink the LED
URL: https://github.com/apache/nuttx-apps/pull/2437
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] examples/hello_rust: Add feature to blink the LED [nuttx-apps]
Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 commented on PR #2437:
URL: https://github.com/apache/nuttx-apps/pull/2437#issuecomment-2214043461
should we keep rust_hello independent from the hardware? but create a new example(e.g. blink_rust)?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] examples/hello_rust: Add feature to blink the LED [nuttx-apps]
Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 commented on PR #2437:
URL: https://github.com/apache/nuttx-apps/pull/2437#issuecomment-2214472410
> > should we keep rust_hello independent from the hardware? but create a new example(e.g. blink_rust)?
>
> @xiaoxiang781216 Good point! Rushabh suggested a separate app, but I thought we should extend hello_rust because: (1) By convention, there seems to be only 1 sample app per language? hello_nim, hello_zig, hello_d, ... (2) If we look at [hello_nim](https://github.com/apache/nuttx-apps/blob/master/examples/hello_nim/hello_nim_async.nim): It's actually doing quite a lot. Maybe hello_rust should also do something substantial? (3) Our Rust Blinky App will terminate gracefully if the LED Driver is missing anyway
>
> If we have no concerns about breaking convention (1), then sure we can split into a blink_rust app. Lemme know what you think. Thanks!
It' fine to put into hello_rust If the demo doesn't depend on any hardware feature and can run with a basic porting. But, the change in this patch depends on userleds which mayn't exist on many board.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] examples/hello_rust: Add feature to blink the LED [nuttx-apps]
Posted by "lupyuen (via GitHub)" <gi...@apache.org>.
lupyuen commented on PR #2437:
URL: https://github.com/apache/nuttx-apps/pull/2437#issuecomment-2213787932
> should we enable rust on some board's defconfig?
@xiaoxiang781216 Thanks for the suggestion! We might add to QEMU RISC-V later, first we need to add the LED Driver to QEMU. Also we have a few manual build steps needed for Rust on QEMU, we will fix them in the coming weeks.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] examples/hello_rust: Add feature to blink the LED [nuttx-apps]
Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 commented on PR #2437:
URL: https://github.com/apache/nuttx-apps/pull/2437#issuecomment-2213781595
@rushabhvg should we enable rust on some board's defconfig?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] examples/hello_rust: Add feature to blink the LED [nuttx-apps]
Posted by "lupyuen (via GitHub)" <gi...@apache.org>.
lupyuen commented on PR #2437:
URL: https://github.com/apache/nuttx-apps/pull/2437#issuecomment-2213342910
Hmmm the NuttX Build doesn't seem happy with Rust Files. Lemme find out why...
https://github.com/apache/nuttx-apps/actions/runs/9835985035/job/27150755232?pr=2437
```text
Run echo "::add-matcher::nuttx/.github/nxstyle.json"
Defaulting to user installation because normal site-packages is not writeable
b167569c0 Merge 17de01ddbb37445b2d4b3f0394bc2a91b7a57b88 into 6b9d51793f7373e3c48d4590a368ab8b8f42e61e
17de01ddb examples/hello_rust: Add feature to blink the LED
../nuttx/tools/checkpatch.sh -m -g 6b9d51793f7373e3c48d4590a368ab8b8f42e61e..HEAD
Diff in /home/runner/work/nuttx-apps/nuttx-apps/apps/examples/hello_rust/hello_rust_main.rs at line 22:
* Attributes
****************************************************************************/
- #![no_main]
- #![no_std]
+#![no_main]
+#![no_std]
/****************************************************************************
* Uses
Diff in /home/runner/work/nuttx-apps/nuttx-apps/apps/examples/hello_rust/hello_rust_main.rs at line 73:
#[no_mangle]
pub extern "C" fn hello_rust_main(_argc: i32, _argv: *const *const u8) -> i32 {
-
unsafe {
-
/* "Hello, Rust!!" using printf() from libc */
printf(b"Hello, Rust!!\n\0" as *const u8);
Diff in /home/runner/work/nuttx-apps/nuttx-apps/apps/examples/hello_rust/hello_rust_main.rs at line [11](https://github.com/apache/nuttx-apps/actions/runs/9835985035/job/27150755232?pr=2437#step:4:12)5:
0
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] examples/hello_rust: Add feature to blink the LED [nuttx-apps]
Posted by "lupyuen (via GitHub)" <gi...@apache.org>.
lupyuen commented on PR #2437:
URL: https://github.com/apache/nuttx-apps/pull/2437#issuecomment-2216069576
Yep sure no worries, we'll repackage the app as `blink_rust`. Thanks!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] examples/hello_rust: Add feature to blink the LED [nuttx-apps]
Posted by "lupyuen (via GitHub)" <gi...@apache.org>.
lupyuen commented on PR #2437:
URL: https://github.com/apache/nuttx-apps/pull/2437#issuecomment-2213430064
@rushabhvg Sorry `rustfmt` is super particular with our whitespace and blank lines. Could you do the following:
1. Overwrite Rust Blinky with this version that agrees with `rustfmt`: https://github.com/lupyuen2/wip-nuttx-apps/blob/gpio7/examples/hello_rust/hello_rust_main.rs
2. Run `rustfmt`. It should not show anything:
```bash
$ rustfmt --edition 2021 --check hello_rust_main.rs
[should not show anything]
$
```
3. There should be a blank line at the end of the file. Otherwise `rustfmt` will fail:
```bash
$ rustfmt --edition 2021 --check hello_rust_main.rs
0
}
+
[rustfmt needs a blank line]
```
4. Commit the changes. Squash the commits into one single commit. Thank you so much! :-)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] examples/hello_rust: Add feature to blink the LED [nuttx-apps]
Posted by "lupyuen (via GitHub)" <gi...@apache.org>.
lupyuen commented on PR #2437:
URL: https://github.com/apache/nuttx-apps/pull/2437#issuecomment-2214111138
> should we keep rust_hello independent from the hardware? but create a new example(e.g. blink_rust)?
@xiaoxiang781216 Good point! Rushabh suggested a separate app, but I thought we should extend hello_rust because:
(1) By convention, there seems to be only 1 sample app per language? hello_nim, hello_zig, hello_d, ...
(2) If we look at [hello_nim](https://github.com/apache/nuttx-apps/blob/master/examples/hello_nim/hello_nim_async.nim): It's actually doing quite a lot. Maybe hello_rust should also do something substantial?
(3) Our Rust Blinky App will terminate gracefully if the LED Driver is missing anyway
If we have no concerns about breaking convention (1), then sure we can split into a blink_rust app. Lemme know what you think. Thanks!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org