STMicroelectronics / stm32-lsm6dso

Provides the LSM6DSO driver, part of the STM32Cube BSP Component for all STM32xx series
BSD 3-Clause "New" or "Revised" License
7 stars 0 forks source link

Device ID readout fails after soft-reset #1

Closed emha69 closed 1 month ago

emha69 commented 2 months ago

When the hosting CPU is soft reset (e.g. thru HAL_NVIC_SystemReset()) the LSM6DSO_0_Probe() function in lsm6dso.c will fail in the standard 4-wire SPI configuration, since the LSM6DSO_ReadID() in most cases returns 0 (zero) for the device ID.

Working code fix, that has been successfully tested:

In the function int32_t LSM6DSO_RegisterBusIO() the following code should be added, after checking, if the bus is in the 3-wire SPI configuration.

      if (pObj->IO.BusType == LSM6DSO_SPI_3WIRES_BUS)
      {

        if (pObj->is_initialized == 0U)
        {
          uint8_t data = 0x0C;

          if (LSM6DSO_Write_Reg(pObj, LSM6DSO_CTRL3_C, data) != LSM6DSO_OK)
          {
            ret = LSM6DSO_ERROR;
          }
        }
      }
      else { 
         // FIX for failing device ID readout after soft-reset

          if (LSM6DSO_DISABLE_I3C(pObj) != LSM6DSO_OK) {
              ret = LSM6DSO_ERROR;
          }

          if (LSM6DSO_RESET_CHIP(pObj) != LSM6DSO_OK) {
              ret = LSM6DSO_ERROR;
          }
      }

The functions DISABLE_I3C and CHIP RESET used above have been added to the lsm6dso.c

int32_t LSM6DSO_DISABLE_I3C(LSM6DSO_Object_t *pObj)
{
    if (lsm6dso_i3c_disable_set(&(pObj->Ctx), 0x80) != LSM6DSO_OK) {
        return LSM6DSO_ERROR;
    }

    return LSM6DSO_OK;
}

int32_t LSM6DSO_RESET_CHIP(LSM6DSO_Object_t *pObj)
{
    if (lsm6dso_reset_set(&(pObj->Ctx), 0x01) != LSM6DSO_OK) {
        return LSM6DSO_ERROR;
    }

    return LSM6DSO_OK;
}

Maybe the same is the case in 3-wire configuration, but I was not able to test it.

KRASTM commented 2 months ago

Hello @emha69,

Thank you for the report. Can you please share more details, such as:

With regards.

emha69 commented 2 months ago

No, I am using custom board in two different MCU type variants : STM32L562 and STM32L4P5. Both MCUs run (more or less) the same code, and the reset effect is (mostly) same.

Besides that, it is the original STM code, except few functions added (e.g. abstractions for register functions as shown in my example).

MCU config files attached.

VIBS_L5C.zip STM-L4B-V2.zip

KRASTM commented 2 months ago

Hello,

In fact, there is an example BSP MotionSensor_demo with STML562E-DK board. I have tested and work fine even with the soft reset, I didn't get an error with the function LSM6DSO_Probe() or LSM6DSO_ReadID(). For information, the example based on I2C not SPI.

I will try to analyze and test with your config.

With regards.

emha69 commented 2 months ago

Reading similar reports around the internet, the problem with reading out the ID initially seems to be related to the SPI. Using the chip in high-performance streaming mode requires use of SPI. So, I am looking forward, to see what you find out with SPI.

KRASTM commented 1 month ago

Hello @emha69,

Unfortunately, the component LSM6DSO on the STM32L562-DK board is driven by I²C, even the connections. Sorry from my side, I cannot test your project or reproduce the issue with SPI.

I found some links related to this topic in our community, maybe it can help you to solve your problem: Link1 Link2

Otherwise, your issue it's related to the product rather than Embedded software. So, you can submit a post to the ST Community.

Since this issue is not directly related to the STM32Cube firmware but rather to our ecosystem, please allow me then to close this thread. Thank you for your comprehension.

With regards.

emha69 commented 1 month ago

Hello @KRASTM,

I understand, that you are not willing to change the code, although I think there are ST boards out there that are using SPI with LSM6DSO, since this problem is IMHO not directly related to the STML5 series. However, it is also fine with me, if we have this issue and workaround noted here, if somebody encounters the same problem.

KRASTM commented 1 month ago

Hello @emha69,

As I said before, I didn't manage to reproduce the issue with the means on board, but you can submit a post to the ST Community.

Please, allow me to close this issue.

With regards.