cancel
Showing results for 
Search instead for 
Did you mean: 

Open port error on host while using HAL_Delay

kozlovdmn
Associate II
Posted on December 19, 2016 at 12:03

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. The following code runs OK again.

while (1) {
Hal_Delay(5e3);
//CDC_Transmit_FS(b, 4);}
I have tried to increase Heap size, it doesn't help.

#open-port-error #cdc #vcp
5 REPLIES 5
akravchenko9
Associate II
Posted on December 27, 2016 at 12:29

Same problem, still no any solutions

Amel NASRI
ST Employee
Posted on December 27, 2016 at 14:44

Hello,

This should be related to interrupts priorities: check USB and SysTick priorities.

As you may have already noted it in any readme file of the Cube examples, we have following recommendation:

'Care must be taken when using HAL_Delay(), this function provides accurate delay (in milliseconds) based on variable incremented in HAL time base ISR. This implies that if HAL_Delay() is called from a peripheral ISR process, then the HAL time base interrupt must have higher priority (numerically lower) than the peripheral interrupt. Otherwise the caller ISR process will be blocked.To change the HAL time base interrupt priority you have to use HAL_NVIC_SetPriority() function.'

-Amel-

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

akravchenko9
Associate II
Posted on December 27, 2016 at 14:59

On the other hand...

If I use CUBE MX generated project for the GCC, without any source code modification -- project works fine time-to-time. But if I will place simple source code part on the main function -- project does not working always (Open port error on host)

for (unsigned char i = 0; i < 32; i++)

{

    transmitBuffer[i] = i + 1;

}

P.S.

I was trying to play with 'heap_size', 'V_bus'... Results is same

STM32f4-Discovery

Posted on January 10, 2017 at 18:06

Actually the problem is not in using delay function. If I add some other code, then the problem is the same 'open error port'.

Posted on January 10, 2017 at 18:12

Somethere in configuration there is an error. I have made the following thing.

1. Create project as described here 

http://visualgdb.com/tutorials/arm/stm32/usb/

 

2. Copy all files relating to usb (drivers, config...)  in my environment. 

3. It works with the last hal drivers, and clock settings generated by cube.