# Open Error on host while using VCP on STM32

I use STM32F407G-DISC1 board. I have run some examples with VCP based on STD library. Everything is OK. Then I have tried to generate code by CubeMX. And something interesting happens.

If not to add any code, then VCP is defined by host and Terminal can connect that.

If I add CDC_Transmit_FS in endless loop of main(), it works

volatile uint32_t time_var = 3e7;
while (1)
{
while(time_var) {
time_var--;
}
CDC_Transmit_FS(b, 4);
time_var = 3e8;
}


If instead of internal while loop I use HAL_Delay function, then terminal can't open the port.

while (1) {
Hal_Delay(5e3);
CDC_Transmit_FS(b, 4);
}


So, COM port is defined in DeviceManager, but terminal can't connect that. It happens even before the first call of CDC_Transmit_FS, though hUsbDeviceFS is already initialized.

• CDC_Transmit_FS() never gets called in your second example. Look at the following part while(1) Hal_Delay(5e3); more closely. Dec 16 '16 at 19:38
• Sorry, of course there is "{" after while. Dec 16 '16 at 20:42