cancel
Showing results for 
Search instead for 
Did you mean: 

USB CDC dont work in debug

o gaste
Associate III
Posted on April 11, 2017 at 12:39

Hi all

I'm working on a STM32F303CC very simple board(just µC IMU and USB).

I need to use a USB Virtual COM (CDC) for a MtoM data transfer with a Windows PC

I set up BSP with STMCubeMx and compiling/debuging with Keil V5 with an STlink V2 in SWD mode

board and microcontrolers are powered by USB

all look's working great when I make a hard reset (just fresh power up) but if I try to make a soft reset like when entering in debug despite Virtual Com Port is well enumerated on windows side it could not open com port and no Usb transmit can be done on target side becase of Usb Device descriptor not defined in Usb Midle ware

does anyone faced the same issue or somthing similare ? I tried to use USBLyser to see what's wrong but I must admit I've not seen something particular when doing soft reset

thank's for any help
1 ACCEPTED SOLUTION

Accepted Solutions
Posted on April 20, 2017 at 17:18

YES !!!!!

I finaly found a way to force the USB master to forget the device and do the enumeration procedure completly

i'm calling this :

/*pull down the USB RP pin to let think of master that device have been disconnect and force new device identification when calling MX_USB_DEVICE_Init() */

void USB_DEVICE_MasterHardReset(void)

{

    GPIO_InitTypeDef GPIO_InitStruct;

    GPIO_InitStruct.Pin = GPIO_PIN_12;

    GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;

    GPIO_InitStruct.Pull = GPIO_PULLDOWN;

    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;

    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

    HAL_GPIO_WritePin(GPIOA,GPIO_PIN_12,0);

    HAL_Delay(1000);

}

just before   MX_USB_DEVICE_Init(); call I think delai could be reduced a lot (I'm not sure it is mandatory even) but I was so happy to to say it that I did not take time to ajust that yet

I hope it will help. I'm so surprised nobody encounter this before.

View solution in original post

3 REPLIES 3
Imen.D
ST Employee
Posted on April 11, 2017 at 16:57

Hi,

Try

i

ncrease the heap and stack size and r

efer to the CDC example from STM32CubeF3 firmware package this will help you on your porject.

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen
Posted on April 20, 2017 at 13:27

hi Imen thank's for your fast reply (and sory for my slow one )

unfortunatly I already tried to increase Heap and Stack

Stack_Size        EQU     0x4000

Heap_Size      EQU     0x2000

I based my CDC framework calls on the Cube Example I realy think there is something different between debug reset and power on

when I start a debug session the hUsbDeviceFS.pClassData struct stay null and CDC_Transmit_FS return immediatly

I've folowed calls to determine where pClassData would be initialised and I didnt realy figured what causes this but one again after a power on all works perfectly

after few more test I think problem comes because when soft reseting the Device on USB window master side is not unmount/reset ... I tried to call USBD_Stop() and USBD_DeInit() before main MX_USB_DEVICE_Init() call but as the hUsbDeviceFS has not been properly initialised it dead lock by calling null function pointers ( pdev->pClass->DeInit() for the first one)

I tried also to set CNTR register to force reset before init

  /* disable all interrupts and force USB reset */

  USB->CNTR = USB_CNTR_FRES;

  /* clear interrupt status register */

  USB->ISTR = 0U;

  /* switch-off device */

  USB->CNTR = (USB_CNTR_FRES | USB_CNTR_PDWN);

but it did nothing too

the objective is to force the master to forget reseted device and be aware to a new device connect procedure

I continue to play in device register trying to force it to reset but if there is a good way to do it I will be gratefull !!

thank's for any help

Posted on April 20, 2017 at 17:18

YES !!!!!

I finaly found a way to force the USB master to forget the device and do the enumeration procedure completly

i'm calling this :

/*pull down the USB RP pin to let think of master that device have been disconnect and force new device identification when calling MX_USB_DEVICE_Init() */

void USB_DEVICE_MasterHardReset(void)

{

    GPIO_InitTypeDef GPIO_InitStruct;

    GPIO_InitStruct.Pin = GPIO_PIN_12;

    GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;

    GPIO_InitStruct.Pull = GPIO_PULLDOWN;

    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;

    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

    HAL_GPIO_WritePin(GPIOA,GPIO_PIN_12,0);

    HAL_Delay(1000);

}

just before   MX_USB_DEVICE_Init(); call I think delai could be reduced a lot (I'm not sure it is mandatory even) but I was so happy to to say it that I did not take time to ajust that yet

I hope it will help. I'm so surprised nobody encounter this before.