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

add bmi088 driver. #15483

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
0f9df8d
arch/arm/stm32:add stm32g4 spi driver.
JerrySlhao Jan 9, 2025
4b9afd7
Documentation: Add Rust integration guide for NuttX
no1wudi Jan 9, 2025
204c296
Remove duplicate includes across multiple files
no1wudi Jan 8, 2025
6065c4d
segger: rm spin_lock_irqsave(NULL) in drivers/segger/config/SEGGER_RT…
hujun260 Jan 9, 2025
c17b679
rv-virt:citest64: bump CONFIG_INIT_STACKSIZE
yamt Jan 9, 2025
ee0db2b
net/tcp_timer: remove tcp_callback(TIMEOUT) when accept conn timeout
zhhyu7 Jan 7, 2025
a148ae3
arch/risc-v: Refactor LLVM CPU type handling in Toolchain.cmake
no1wudi Jan 8, 2025
79ca93b
esp32[c3|c6|h2]: Fix misconfigured gpio issue
eren-terzioglu Jan 9, 2025
7e4bb0b
goldfish_sensor_uorb.c: add set_interval for goldfish sensor
chenzihan0416 Nov 22, 2024
9dfeeeb
drivers/sensors/bmi088: add driver for Bosch BMI088 IMU
JerrySlhao Jan 9, 2025
0f34230
arm64/sctlr: Allows thread to independent control the switch of sctlr
W-M-R Jan 6, 2025
2c975cf
arm64/vector: Reduce two useless instructions
W-M-R Jan 10, 2025
a732784
Initial STM32H5 Timers Commit
kywwilson11 Jan 3, 2025
a745937
armv7-a.cmake: Improve FPU options table formatting and readability
no1wudi Jan 10, 2025
2c1404f
arch/arm: Add LLVM configuration to CMake
no1wudi Jan 10, 2025
df89c6e
rv-virt:citest64: Bump CONFIG_SYSTEM_POPEN_STACKSIZE
yamt Jan 10, 2025
77e8a83
esp32[c6]: Fix misconfigured pin functions for esp32c6-devkitm
eren-terzioglu Jan 10, 2025
be8281f
drivers/usbdev/cdcacm.c: Fix a crash in cdcacm if usbdev gets unregis…
jlaitine Jan 9, 2025
081f53a
use small lock to protect register about l2cc, involving the followi…
wangzhi-art Jan 7, 2025
f51d938
armv7-a/Toolchain.defs: Update LLVM arch type to thumbv7a
no1wudi Jan 10, 2025
0694de1
use small lock in following files:
wangzhi-art Jan 7, 2025
37cd0a1
use small lock to protect g_ram_vectors, involving armv6-m, armv7-m, …
wangzhi-art Jan 7, 2025
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
1 change: 1 addition & 0 deletions Documentation/guides/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,5 @@ Guides
ram_rom_disks.rst
reading_can_msgs.rst
remove_device_drivers_nsh.rst
rust.rst

90 changes: 90 additions & 0 deletions Documentation/guides/rust.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
===============
Rust in NuttX
===============

.. warning::
This guide is under development. Rust support in NuttX is experimental.

Introduction
============
NuttX is exploring Rust integration to provide memory safety guarantees and modern
language features while maintaining its small footprint and real-time capabilities.

This guide covers:

- Setting up Rust toolchain for NuttX development
- Building Rust components with NuttX
- Interoperability between Rust and C
- Testing Rust components

Prerequisites
=============
- Rust toolchain installed (rustup recommended)
- NuttX build environment configured
- Basic knowledge of Rust and NuttX development

Supported Platforms
===================
- AArch64 (WIP)
- ARMv7-A (WIP)
- ARMv6-M
- ARMv7-M
- ARMv8-M
- RISCV32
- RISCV64

Getting Started
===============
1. Install Rust toolchain and switch to nightly

Please refer to the official Rust installation guide for more details: https://www.rust-lang.org/tools/install

.. code-block:: bash

rustup toolchain install nightly
rustup default nightly

2. Prepare NuttX build environment

Please ensure that you have a working NuttX build environment, and with the following PR merged or cherry-picked:
- https://github.com/apache/nuttx-apps/pull/2487
- https://github.com/apache/nuttx/pull/15469

3. Enable essential kernel configurations

Pleae enable the following configurations in your NuttX configuration:
- CONFIG_SYSTEM_TIME64
- CONFIG_FS_LARGEFILE
- CONFIG_TLS_NELEM = 16
- CONFIG_DEV_URANDOM

The `rv-virt:nsh` board using make as the build system is recommended for testing Rust applications as it has been verified to work with this configuration.

For `rv-virt:nsh` board, you should disable `CONFIG_ARCH_FPU` configuration since RISCV32 with FPU is not supported yet.

4. Enable sample application

Please enable the sample application in your NuttX configuration:
- CONFIG_EXAMPLES_HELLO_RUST_CARGO

5. Build and run the sample application

Build the NuttX image and run it on your target platform:

.. code-block:: bash

qemu-system-riscv32 -semihosting -M virt,aclint=on -cpu rv32 -smp 8 -bios nuttx/nuttx -nographic

NuttShell (NSH) NuttX-12.8.0
nsh> hello_rust_cargo
{"name":"John","age":30}
{"name":"Jane","age":25}
Deserialized: Alice is 28 years old
Pretty JSON:
{
"name": "Alice",
"age": 28
}
Hello world from tokio!

Congratulations! You have successfully built and run a Rust application on NuttX.
19 changes: 14 additions & 5 deletions arch/arm/src/am335x/am335x_can.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@
#include <nuttx/config.h>

#include <assert.h>
#include <sched.h>

#include <arch/board/board.h>
#include <nuttx/irq.h>
#include <nuttx/spinlock.h>
#include <nuttx/arch.h>
#include <nuttx/can/can.h>

Expand Down Expand Up @@ -205,6 +207,8 @@ static struct can_dev_s g_can1dev =
};
#endif

static spinlock_t g_can_lock = SP_UNLOCKED;

/****************************************************************************
* Private Functions
****************************************************************************/
Expand Down Expand Up @@ -1079,7 +1083,8 @@ struct can_dev_s *am335x_can_initialize(int port)

syslog(LOG_DEBUG, "CAN%d\n", port);

flags = enter_critical_section();
flags = spin_lock_irqsave(&g_can_lock);
sched_lock();

#ifdef CONFIG_AM335X_CAN0
if (port == 0)
Expand Down Expand Up @@ -1109,11 +1114,13 @@ struct can_dev_s *am335x_can_initialize(int port)
{
canerr("Unsupported port: %d\n", port);

leave_critical_section(flags);
spin_unlock_irqrestore(&g_can_lock, flags);
sched_unlock();
return NULL;
}

leave_critical_section(flags);
spin_unlock_irqrestore(&g_can_lock, flags);
sched_unlock();

return candev;
}
Expand All @@ -1124,7 +1131,8 @@ void am335x_can_uninitialize(struct can_dev_s *dev)

DEBUGASSERT(dev);

flags = enter_critical_section();
flags = spin_lock_irqsave(&g_can_lock);
sched_lock();

#ifdef CONFIG_AM335X_CAN0
if (dev == &g_can0dev)
Expand All @@ -1151,7 +1159,8 @@ void am335x_can_uninitialize(struct can_dev_s *dev)
canerr("Not a CAN device: %p\n", dev);
}

leave_critical_section(flags);
spin_unlock_irqrestore(&g_can_lock, flags);
sched_unlock();
}

#endif
15 changes: 9 additions & 6 deletions arch/arm/src/am335x/am335x_gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <errno.h>

#include <nuttx/irq.h>
#include <nuttx/spinlock.h>

#include "chip.h"
#include "arm_internal.h"
Expand Down Expand Up @@ -219,6 +220,8 @@ static const uint8_t *g_gpio_padctl[AM335X_GPIO_NPORTS] =
g_gpio3_padctl, /* GPIO3 */
};

static spinlock_t g_gpio_lock = SP_UNLOCKED;

/****************************************************************************
* Private Functions
****************************************************************************/
Expand Down Expand Up @@ -364,7 +367,7 @@ int am335x_gpio_config(gpio_pinset_t pinset)

/* Configure the pin as an input initially to avoid any spurious outputs */

flags = enter_critical_section();
flags = spin_lock_irqsave(&g_gpio_lock);

/* Configure based upon the pin mode */

Expand Down Expand Up @@ -407,7 +410,7 @@ int am335x_gpio_config(gpio_pinset_t pinset)
break;
}

leave_critical_section(flags);
spin_unlock_irqrestore(&g_gpio_lock, flags);
return ret;
}

Expand All @@ -425,9 +428,9 @@ void am335x_gpio_write(gpio_pinset_t pinset, bool value)
int port = (pinset & GPIO_PORT_MASK) >> GPIO_PORT_SHIFT;
int pin = (pinset & GPIO_PIN_MASK) >> GPIO_PIN_SHIFT;

flags = enter_critical_section();
flags = spin_lock_irqsave(&g_gpio_lock);
am335x_gpio_setoutput(port, pin, value);
leave_critical_section(flags);
spin_unlock_irqrestore(&g_gpio_lock, flags);
}

/****************************************************************************
Expand All @@ -445,9 +448,9 @@ bool am335x_gpio_read(gpio_pinset_t pinset)
int pin = (pinset & GPIO_PIN_MASK) >> GPIO_PIN_SHIFT;
bool value;

flags = enter_critical_section();
flags = spin_lock_irqsave(&g_gpio_lock);
value = am335x_gpio_getinput(port, pin);
leave_critical_section(flags);
spin_unlock_irqrestore(&g_gpio_lock, flags);
return value;
}

Expand Down
25 changes: 17 additions & 8 deletions arch/arm/src/am335x/am335x_i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

#include <nuttx/arch.h>
#include <nuttx/irq.h>
#include <nuttx/spinlock.h>
#include <nuttx/clock.h>
#include <nuttx/mutex.h>
#include <nuttx/semaphore.h>
Expand Down Expand Up @@ -185,6 +186,7 @@ struct am335x_i2c_priv_s

int refs; /* Reference count */
mutex_t lock; /* Mutual exclusion mutex */
spinlock_t spinlock; /* Spinlock */
#ifndef CONFIG_I2C_POLLED
sem_t sem_isr; /* Interrupt wait semaphore */
#endif
Expand Down Expand Up @@ -317,6 +319,7 @@ static struct am335x_i2c_priv_s am335x_i2c0_priv =
.config = &am335x_i2c0_config,
.refs = 0,
.lock = NXMUTEX_INITIALIZER,
.spinlock = SP_UNLOCKED,
#ifndef CONFIG_I2C_POLLED
.sem_isr = SEM_INITIALIZER(0),
#endif
Expand Down Expand Up @@ -352,6 +355,7 @@ static struct am335x_i2c_priv_s am335x_i2c1_priv =
.config = &am335x_i2c1_config,
.refs = 0,
.lock = NXMUTEX_INITIALIZER,
.spinlock = SP_UNLOCKED,
#ifndef CONFIG_I2C_POLLED
.sem_isr = SEM_INITIALIZER(0),
#endif
Expand Down Expand Up @@ -387,6 +391,7 @@ static struct am335x_i2c_priv_s am335x_i2c2_priv =
.config = &am335x_i2c2_config,
.refs = 0,
.lock = NXMUTEX_INITIALIZER,
.spinlock = SP_UNLOCKED,
#ifndef CONFIG_I2C_POLLED
.sem_isr = SEM_INITIALIZER(0),
#endif
Expand Down Expand Up @@ -492,7 +497,7 @@ static inline int am335x_i2c_sem_waitdone(struct am335x_i2c_priv_s *priv)
uint32_t regval;
int ret;

flags = enter_critical_section();
flags = spin_lock_irqsave(&priv->spinlock);

/* Enable Interrupts when master mode */

Expand Down Expand Up @@ -529,6 +534,8 @@ static inline int am335x_i2c_sem_waitdone(struct am335x_i2c_priv_s *priv)
*/

priv->intstate = INTSTATE_WAITING;
spin_unlock_irqrestore(&priv->spinlock, flags);

do
{
/* Wait until either the transfer is complete or the timeout expires */
Expand All @@ -551,6 +558,8 @@ static inline int am335x_i2c_sem_waitdone(struct am335x_i2c_priv_s *priv)
}
}

flags = spin_lock_irqsave(&priv->spinlock);

/* Loop until the interrupt level transfer is complete. */

while (priv->intstate != INTSTATE_DONE);
Expand All @@ -563,7 +572,7 @@ static inline int am335x_i2c_sem_waitdone(struct am335x_i2c_priv_s *priv)

am335x_i2c_putreg(priv, AM335X_I2C_IRQ_EN_CLR_OFFSET, I2C_ICR_CLEARMASK);

leave_critical_section(flags);
spin_unlock_irqrestore(&priv->spinlock, flags);
return ret;
}
#else
Expand Down Expand Up @@ -992,7 +1001,7 @@ static int am335x_i2c_isr_process(struct am335x_i2c_priv_s *priv)
*/

#ifdef CONFIG_I2C_POLLED
irqstate_t flags = enter_critical_section();
irqstate_t flags = spin_lock_irqsave(&priv->spinlock);
#endif

/* Transmit a byte */
Expand All @@ -1001,7 +1010,7 @@ static int am335x_i2c_isr_process(struct am335x_i2c_priv_s *priv)
priv->dcnt--;

#ifdef CONFIG_I2C_POLLED
leave_critical_section(flags);
spin_unlock_irqrestore(&priv->spinlock, flags);
#endif
if ((priv->dcnt == 0) && ((priv->flags & I2C_M_NOSTOP) == 0))
{
Expand All @@ -1026,7 +1035,7 @@ static int am335x_i2c_isr_process(struct am335x_i2c_priv_s *priv)
*/

#ifdef CONFIG_I2C_POLLED
irqstate_t flags = enter_critical_section();
irqstate_t flags = spin_lock_irqsave(&priv->spinlock);
#endif

/* Receive a byte */
Expand All @@ -1036,7 +1045,7 @@ static int am335x_i2c_isr_process(struct am335x_i2c_priv_s *priv)
priv->dcnt--;

#ifdef CONFIG_I2C_POLLED
leave_critical_section(flags);
spin_unlock_irqrestore(&priv->spinlock, flags);
#endif
if ((priv->msgc <= 0) && (priv->dcnt == 0))
{
Expand Down Expand Up @@ -1100,7 +1109,7 @@ static int am335x_i2c_isr_process(struct am335x_i2c_priv_s *priv)
*/

#ifdef CONFIG_I2C_POLLED
irqstate_t flags = enter_critical_section();
irqstate_t flags = spin_lock_irqsave(&priv->spinlock);
#endif

/* Transmit a byte */
Expand All @@ -1109,7 +1118,7 @@ static int am335x_i2c_isr_process(struct am335x_i2c_priv_s *priv)
priv->dcnt--;

#ifdef CONFIG_I2C_POLLED
leave_critical_section(flags);
spin_unlock_irqrestore(&priv->spinlock, flags);
#endif
if ((priv->dcnt == 0) && ((priv->flags & I2C_M_NOSTOP) == 0))
{
Expand Down
12 changes: 10 additions & 2 deletions arch/arm/src/am335x/am335x_irq.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,21 @@
#include <assert.h>

#include <nuttx/arch.h>
#include <nuttx/spinlock.h>

#include "arm_internal.h"
#include "sctlr.h"

#include "am335x_gpio.h"
#include "am335x_irq.h"

/****************************************************************************
* Private Data
****************************************************************************/
#ifdef CONFIG_ARCH_IRQPRIO
static spinlock_t g_irq_lock = SP_UNLOCKED;
#endif

/****************************************************************************
* Public Data
****************************************************************************/
Expand Down Expand Up @@ -328,7 +336,7 @@ int up_prioritize_irq(int irq, int priority)
{
/* These operations must be atomic */

flags = enter_critical_section();
flags = spin_lock_irqsave(&g_irq_lock);

#if 0 // TODO
/* Set the new priority */
Expand All @@ -340,7 +348,7 @@ int up_prioritize_irq(int irq, int priority)
putreg32(regval, regaddr);
#endif

leave_critical_section(flags);
spin_unlock_irqrestore(&g_irq_lock, flags);
return OK;
}

Expand Down
Loading
Loading