2018-06-06 09:46 PM
Hi All,
I am working on a charger based on STM32F04.
It can detect the SDP or DCP when PC or charger connected, but it only works one time. That means when I unplug and plug the USB, it always detects as SDP.
I believe it might be the USB is not uninitialized correctly, but really don't know which parts cause this problem.
When I do a software reset, then the correct port type can be detected. So I am not sure what USB uninitialized should be done.
thanks
if(vbus_detect)
{ if(usb_init) { USBD_Stop(&hUsbDeviceFS); USBD_DeInit(&hUsbDeviceFS); HAL_Delay(10); *(uint16_t *)(USB_BCDR) &= (uint16_t)(~(USB_BCDR_DPPU)); __IO uint16_t * cntr=(uint16_t *)(USB_CNTR); (*cntr)= USB_CNTR_FRES } USBD_Init(&hUsbDeviceFS, &FS_Desc, DEVICE_FS); USBD_RegisterClass(&hUsbDeviceFS, &USBD_CDC); USBD_CDC_RegisterInterface(&hUsbDeviceFS, &USBD_Interface_fops_FS); charge_port_detect(); USBD_Start(&hUsbDeviceFS); usb_init=true;}
void charge_port_detect()
{ __IO uint16_t * bcdr=(uint16_t *)(USB_BCDR); (*bcdr) |= (USB_BCDR_BCDEN); HAL_Delay( 300 ); (*bcdr) |= (USB_BCDR_PDEN); HAL_Delay( 300 ); lastport=port; /* If Charger detect ? */ if( (*bcdr) & USB_BCDR_PDET ) { /* Start secondary detection to check connection to Charging Downstream Port or Dedicated Charging Port */ (*bcdr) &= ~(USB_BCDR_PDEN); (*bcdr) |= (USB_BCDR_SDEN); HAL_Delay( 300 ); /* If CDP ? */ if( (*bcdr) & USB_BCDR_SDET ) { /* Dedicated Downstream Port DCP */ port = PORT_DCP; } else { /* Charging Downstream Port CDP */ port = PORT_CDP; } } else /* NO */ { /* Standard Downstream Port */ port = PORT_SDP; } (*bcdr) &= ~(USB_BCDR_BCDEN);}#usb-stm32f04-battery-charging-detector(usb_bcdr)2018-06-07 02:58 AM
It appears that you leave secondary detection enabled (SDEN bit set). Try to switch it off after the detection.
JW