2023-07-27 12:57 PM
Hi ST USB PD community. I'm using https://github.com/STMicroelectronics/x-cube-tcpp but can't seem to find the right callbacks to respond to our port-partner when they send a Get_Battery_Status command.
I need the ST MCU to respond with the Battery_Status data message. Does the USBPD library support this?
I have similar question for Battery_Capabilities and Manufacturer_Info.
thank you for the support!
2023-07-27 09:10 PM
Those messages are all Extended messages.
They are supposed to be handled in USBPD_DPM_ExtendedMessageReceived callback, but it looks not yet implemented.
Refer to usbpd_dpm_user.c in the Src folders of the projects.
2023-07-27 09:43 PM
Hi Winfred, thank you for the prompt response.
Yes, I noticed USBPD_DPM_ExtendedMessageReceived() and also noticed that it wasn't being called when the library received Get_Battery_Status.
Is there anything I can do to help integrate the support in the next release?
2023-07-27 10:34 PM
I am not sure if @Nicolas P. would like to comment about this?
2023-07-31 09:53 AM
Hello @DDesr.1
You will need some updates on application side in order to enable handling of GET_BATTERY_STATUS reception. First you need to enable the support of the Get Battery Status message type into the application configuration : Update the Is_GetBattery_Supported field in your DPM_Settings structure to USBPD_TRUE
Then you need to allow storing on application side for the type of information requested by the GET_BATTERY_STATUS.
This is done by adding this specific data type (USBPD_CORE_GET_BATTERY_STATUS) in the USBPD_DPM_SetDataInfo() of your usbpd_dpm_user.c
case USBPD_CORE_GET_BATTERY_STATUS:
{
DPM_Ports[PortNum].DPM_GetBatteryStatus.BatteryStatusRef = *(uint8_t*)Ptr;
}
break;
Then the USBPD stack will build a BATTERY STATUS message whose content has to be provided by application side.
This is done through the call of USBPD_DPM_GetDataInfo() of your usbpd_dpm_user.c with the USBPD_CORE_BATTERY_STATUS data type.
Here is an example of what could be the code on application side for this :
case USBPD_CORE_BATTERY_STATUS:
{
USBPD_BSDO_TypeDef battery_status;
battery_status.d32 = 0;
battery_status.b.BatteryPC = ...;
battery_status.b.BatteryInfo = ...;
*Size = 4;
memcpy((uint8_t *)Ptr, (uint8_t *)&battery_status.d32, *Size);
}
break;
Of course, this is just an example, but this mechanism allows the application to fully define the content of the answer to the Get_Battery_Status command.
Hope this helps.
Guenael
PS : GET_BATTERY_STATUS is not handled through USBPD_DPM_ExtendedMessageReceived() fonction, which is only handling FirmwareUpdate request/response and Security request/response message types.