0
\$\begingroup\$

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.

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

This is probably because your Hal_Delay function is not working properly. Hal_Delay function will enter a busy loop that will compare an interrupt incremented value with the value you specify as argument. The interrupt functions will get initiated when calling HAL_init(), otherwise you need to make this configuration yourself.

To summarize, make sure that the HAL_Tick function is getting called before using HAL_Delay.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.