MainframeReboot opened a new issue, #16501:
URL: https://github.com/apache/nuttx/issues/16501

   ### 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](https://github.com/user-attachments/assets/a0423ab4-4ae3-47a9-9b0b-5b415978efd7)
   
   When SMP is enabled, the same command results in:
   
   
![Image](https://github.com/user-attachments/assets/15e7b09c-7f05-4481-ac75-99cad025de78)
   
   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:
   ``` C
   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:
   ``` C
   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
   
   - [x] I have verified before submitting the report.


-- 
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-unsubscr...@nuttx.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to