Skip to content

[BUG] I2C & SPI Tool crash system with SMP enabled #16501

@MainframeReboot

Description

@MainframeReboot

Description / Steps to reproduce the issue

Using the MPFS Icicle-kit with NuttX in Kernel mode, the I2C and SPI tools cause a full system crash when these tools are run and SMP is enabled.

Below is an image of the I2C bus scan performed on NuttX 12.9 (tagged release) with SMP disabled:

Image

When SMP is enabled, the same command results in:

Image

This issue has been present since release 12.8 but I managed to hack around the problem in the I2C tool by replacing the following function:

static int mpfs_i2c_sem_waitdone(struct mpfs_i2c_priv_s *priv)
{
  uint32_t timeout = mpfs_i2c_timeout(priv->msgc, priv->msgv);
  return nxsem_tickwait_uninterruptible(&priv->sem_isr, USEC2TICK(timeout));
}

With one that avoids the nxsem_tickwait_uninterruptible call and uses an atomic variable to lock out the driver:

static int mpfs_i2c_sem_waitdone(struct mpfs_i2c_priv_s *priv)
{
  int32_t timeout = mpfs_i2c_timeout(priv->msgc, priv->msgv);
  clock_t end = clock_systime_ticks() + timeout + 1;
  int ret;

  for (; ; )
  {
      if (atomic_load(&priv->transfer_lock))
      {
        ret = OK;
        break;
      }

      timeout = end - clock_systime_ticks();
      if (timeout < 0)
      {
          ret = -EINTR;
          break;
      }
    }

  atomic_store(&priv->transfer_lock, false);
  return ret;
}

I get that this is a dirty hack but I just needed a quick way to poke around in registers of an I2C device from the nsh terminal and as such it did the job. However, since moving to NuttX 12.9, the issue is not only still present, but it has now also manifested itself in the SPI tool, The dirty hack above also no longer works.

Can anyone shed light on what is going on here? Am I possibly missing a config value? I'm concerned that everything is set up correctly but something isn't working quite right deeper in NuttX, I just haven't had much time to dive into all of the changes between the versions.

On which OS does this issue occur?

[OS: Linux]

What is the version of your OS?

Ubuntu 22.04.4

NuttX Version

12.9, 12.8

Issue Architecture

[Arch: risc-v]

Issue Area

[Area: OS Components]

Host information

No response

Verification

  • I have verified before submitting the report.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Arch: risc-vIssues related to the RISC-V (32-bit or 64-bit) architectureArea: OS ComponentsOS Components issuesOS: LinuxIssues related to Linux (building system, etc)Type: BugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions