ardnew / STUSB4500

Arduino library for USB PD sink controller (STUSB4500)
MIT License
29 stars 3 forks source link

DEVICE_ID different from default one #2

Closed zuev93 closed 3 years ago

zuev93 commented 3 years ago

Hi, Thanks for the library but unfortunately I was not able to make it work for my case (STUSB4500 + atmega328p).

The first issue what I've encountered is that defined DEVICE_ID in STUSB4500.cpp (0x21) different from what I got: 0x25, https://www.st.com/resource/en/user_manual/dm00664189-the-stusb4500-software-programing-guide-stmicroelectronics.pdf says that default 0x25 as well (section 3.27).

Thanks!

ardnew commented 3 years ago

Interesting, that document didn't exist when this library was originally written (for the STM32Cube HAL), as their first revision was from Dec 19, 2019!

The DEVICE_ID of 0x21 came from ST's own STM32CubeIDE SDK library they originally provided for development with this chip, which, at the time, was the only documentation available. The current version of this library (STSW-STUSB003) indicates the source of this discrepancy:

  do /* wait for NVM to be reloaded */
  {
    Status = I2C_Read_USB_PD(STUSB45DeviceConf[Usb_Port].I2cBus,STUSB45DeviceConf[Usb_Port].I2cDeviceID_7bit,DEVICE_ID ,&Cut[Usb_Port], 1 );

    if (Cut[Usb_Port] == (uint8_t)0x21)  ID_OK = 1;  // ST eval board
    if (Cut[Usb_Port] == (uint8_t)0x25)  ID_OK = 1;  // Product 
   } while( ID_OK == 0); 
  I2C_Read_USB_PD(STUSB45DeviceConf[Usb_Port].I2cBus,STUSB45DeviceConf[Usb_Port].I2cDeviceID_7bit,DEVICE_ID ,&Cut[Usb_Port], 1 );

#ifdef PRINTF
  if ((Cut[Usb_Port] == 0x21 )|| (Cut[Usb_Port] == 0x25) )
  { 
    printf("\r\n------------------------------------------------");
    printf("\r\n---- INIT: STUSB4500 detected               ----");
    printf("\r\n- Port #%i                                   ----",Usb_Port);
    printf("\r\n- Device ID: 0x%02x                           ----",Cut[Usb_Port]);
    printf("\r\n------------------------------------------------\r\n");
  }
  else printf(" STUSB45 Not detected\r\n");
#endif

So it looks like the eval board uses 0x21 and the standalone chip uses 0x25 which you're expecting.

However, using my breakout board (which it doesn't look like is still sold anymore), I'm indeed reading a 0x21 from the device ID (register 0x2F). This chip is not on an ST eval board, and I would be surprised if the creator pulled it from one, so I'm not sure why.

Considering the comments in the ST source code, what their own documentation says, and what you are personally observing, I think the correct device ID should be 0x25 like you suggest, and that the 0x21 I'm seeing is the exception.

So I'll go ahead and make the change. Thanks for reporting this.

ardnew commented 3 years ago

I've published a new release (v1.0.5) that should appear in the Arduino library manager shortly.

Please let me know if this resolves your issue and I will close this item.

ardnew commented 3 years ago

20201101_165110 The STUSB4500 is shown with orange arrow, and the red arrow shows an I2C bus monitor reading 0x21 from device 0x28 register 0x2F

zuev93 commented 3 years ago

Thank you for the exhaustive explanation. It is a nice story behind the scene :)

It resolves my first issue and the bug can be closed.

P.S. I still have other issues (like I have to call endTransmission(true) while doing a read) or failing updateRDOSnk because of rdo.b.Object_Pos is 0. But since I'm developing and testing this is on a custom circuit and PCB this might be not connected to the lib itself.

usb-c commented 3 years ago

There are 2 versions of STUSB4500. STUSB4500QTR$YAC: DEVICE_ID = 0x21 STUSB4500QTR$YBC: DEVICE_ID = 0x25

The latest version has the DEVICE_ID = 0x25.