cancel
Showing results for 
Search instead for 
Did you mean: 

USB PTP API documentation

alsierraromero
Associate II

Hello,

I'm trying to do a proof of concept using the STM32429I-EVAL1, which basically sends a PTP command to a camera. All the USB host library documentation only covers MTP, but there is nothing about PTP. I understand that this board offers out of the box support for MTP, but in the "MTP_Standalone" project example, the files "usbh_mtp_ptp.h" and "usbh_mtp_ptp.c" are part of the projects and the function USBH_PTP_SendRequest, seems to be what I need to send a specific PTP command, but there is no documentation about those functions. I'd appreciate a bit of guidance on this.
Thank you!

9 REPLIES 9
Pavel A.
Evangelist III

MTP is extension of PTP, so you can start from MTP host examples.

 

Hi Pavel,

The reason why I'm asking for guidance here is because I already went through that documentation and there is nothing there about the APIs I referenced in my previous message. 

Pavel A.
Evangelist III

Let me google copilot this for you.

Q: where is documentation on picture transfer protocol (PTP)?

A: 

You can find detailed documentation on the Picture Transfer Protocol (PTP) from several sources:

  1. Imaging.org: This site provides a comprehensive overview of PTP, including its history, transport implementations, and vendor extensions1.
  2. Wikipedia: The Wikipedia page on PTP offers a summary of the protocol’s development, its standardization, and its applications2.
  3. ISO Standards: The official ISO 15740:2013 standard for PTP can be accessed through the ISO website2.
  4. CIPA: The Camera & Imaging Products Association provides documentation on PTP over IP networks3.

 

Q: Isn't PTP described in some USB.org standard?

A:Yes, the Picture Transfer Protocol (PTP) is described in the USB Still Image Capture Device Definition, which is part of the USB.org standards. Specifically, it is detailed in the USB Still Image Capture Device Definition, Revision 1.0, which outlines how PTP is used for transferring images over USB connections.

 

Source: Conversation with Copilot, 10/09/2024
 
 

I'm glad you know how Google and Copilot works, but that is not what I'm asking. I'm reaching out to the STMicro forum with the hope that the people that work for STMicro can shed some light on how their HW/FW works. Can you please pretend to care and read my first message and at least try to help me?

 

Pavel A.
Evangelist III

Yes I've read your first message. Can you build the host MTP host example and connect a PTP device to it? It is expected at least to start enumeration, parse descriptors and so on.

Azure/Eclipse USBX supports PTP and PictBridge, it's worth to check there too.

 

alsierraromero
Associate II

I've built the MTP Standalone example and connected the dev kit to the camera. The camera is recognized by the DK and everything works as is intended in the example.
I've also modified the example code, because I need to send a PTP command. The MTP APIs that appear in the document UM1720 page 34, don't work for what I'm trying to do, because they are specific to the transfer of media. The only function that seems to be useful for that purpose is USBH_PTP_SendRequest, which I found going through the "usbh_mtp_ptp.h" and "usbh_mtp_ptp.c" files in the example folder. There is no documentation about those PAIs as I mentioned before. Unfortunately, the modified example does not work and I'm not sure if it's because I'm incorrectly using the argument of type PTP_ContainerTypedef or because I need to use the function USBH_PTP_GetResponseas well. 

Pavel A.
Evangelist III

Hmm indeed UM1720 does not document USBH_PTP_SendRequest, USBH_PTP_GetResponse. Not great (( But as you've already found, usbh_mtp_ptp.c gives clues about sending and receiving requests. See for example flow of USBH_PTP_GetStorageInfo().

 

Hi Pavel,

Thanks for the tip. I implemented a function that starts a capture based on your advice and still it isn't working. I've been doing some digging to understand why, but unfortunately I haven't been able to figure it out. The function code is below. Can you please let me know if you spot something I'm overlooking? Thanks!

USBH_StatusTypeDef USBH_PTP_InitOpenCapture(USBH_HandleTypeDef *phost)
{
  USBH_StatusTypeDef status = USBH_BUSY;
  MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData;
  PTP_ContainerTypedef ptp_container;

  switch (MTP_Handle->ptp.req_state)
  {
    case PTP_REQ_SEND:
      /* Set operation request type */
      MTP_Handle->ptp.flags = PTP_DP_NODATA;

      /* Fill operation request params */
      ptp_container.Code = PTP_OC_InitiateOpenCapture;
      ptp_container.SessionID = MTP_Handle->ptp.session_id;
      ptp_container.Transaction_ID = MTP_Handle->ptp.transaction_id++;
      ptp_container.Nparam = 0U;

      /* convert request packet inti USB raw packet*/
      (void)USBH_PTP_SendRequest(phost, &ptp_container);

      /* Setup State machine and start transfer */
      MTP_Handle->ptp.state = PTP_OP_REQUEST_STATE;
      MTP_Handle->ptp.req_state = PTP_REQ_WAIT;
      status = USBH_BUSY;

#if (USBH_USE_OS == 1U)
      phost->os_msg = (uint32_t)USBH_STATE_CHANGED_EVENT;
#if (osCMSIS < 0x20000U)
      (void)osMessagePut(phost->os_event, phost->os_msg, 0U);
#else
      (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, 0U);
#endif
#endif
      break;

    case PTP_REQ_WAIT:
      status = USBH_PTP_Process(phost);
      break;

    default:
      break;
  }
  return status;
}
Pavel A.
Evangelist III

Sorry I don't have a suitable board anymore.