Skip to content
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

docs: enhance Rust guide #15754

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions Documentation/guides/rust.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ Supported Platforms
- ARMv8-M
- RISCV32
- RISCV64
- X86
- X86_64

Getting Started
===============
Expand Down Expand Up @@ -90,3 +92,43 @@ Build the NuttX image and run it on your target platform:
Hello world from tokio!

Congratulations! You have successfully built and run a Rust application on NuttX.

Specifying Target CPU for Optimization
======================================
To optimize your Rust application for a specific CPU, you can use the `RUSTFLAGS` environment variable to specify the target CPU. This can significantly improve performance by enabling CPU-specific optimizations.

The `RUSTFLAGS` environment variable is particularly useful when you are working with CPUs that share the same Instruction Set Architecture (ISA) but have different microarchitectures. For example, both the Cortex-M33 and Cortex-M55 share the `thumbv8m.main` target name, but they have different performance characteristics and features. By specifying the actual CPU core, you can take advantage of the specific optimizations and features of the target CPU, leading to better performance and efficiency.

For instance, if you are targeting a Cortex-M33, you would set the `RUSTFLAGS` environment variable as follows:

.. code-block:: bash

export RUSTFLAGS="-C target-cpu=cortex-m33"

And for a Cortex-M55, you would use:

.. code-block:: bash

export RUSTFLAGS="-C target-cpu=cortex-m55"

This ensures that the Rust compiler generates optimized code tailored to the specific CPU core, rather than a generic ISA.

1. Set the `RUSTFLAGS` environment variable to include the `--target-cpu` flag:

.. code-block:: bash

export RUSTFLAGS="-C target-cpu=your_cpu_model"

Replace `your_cpu_model` with the specific CPU model you are targeting. For example, for an ARM Cortex-M4, you would use:

.. code-block:: bash

export RUSTFLAGS="-C target-cpu=cortex-m4"

2. Build your NuttX image with the specified target CPU:

.. code-block:: bash

make

This will ensure that the Rust compiler generates optimized code for the specified CPU.