cancel
Showing results for 
Search instead for 
Did you mean: 

problem with usb device cdc in hal library

ctc.ctc
Associate II
Posted on September 26, 2017 at 17:56

Hello, all

I recently learn to use stm32 usb device

I think it's easy to build a CDC example with HAL library in CubeMX,

And I put the code into stm32f429-discvoery, it's the HS pin, but actually use FS speed

I'm successfully to connect stm32 in Linux, like I use command 'cat /dev/ttyACM0'

and I can easy to observe stm32 usb transmit data

But there is something strange and I don't know why.

When I plug the usb line and I can find /dev/ttyACM0,

I cannot direct connect it, like 

'cat /dev/ttyACM0'

it will show a error info 'cat: /dev/ttyACM0: Device or resource busy'

But after about 10 seconds, it will success connect it.

Everytime I try same way, it all need 10 seconds wait,

All I setting in CubeMX for USB is default, only VBUS sensing with Enable

I'm not sure why, but it's there any possible to connect usb cdc more quickly?

#usb #cdc
4 REPLIES 4
Posted on September 26, 2017 at 21:09

hello!

Increase the Heap size inside startup_stm32f429xx.s file

eg make it 0x1200

Regards

vf

Posted on September 27, 2017 at 04:16

Actually, I didn't find heap info in 

startup_stm32f429xx.s,

So I modify this viarable in STM32F429ZITx_FLASH.ld

_Min_Heap_Size = 0x200; [TO]   _Min_Heap_Size = 0x1200; 

to make heap size bigger

and clean build again

But after I observe, it still need 10seconds to wait, so there is no improvement,

actually I have no idea why it relative with heap size,

but still thanks you 

Posted on September 27, 2017 at 08:48

Inside USBD_CDC_Init(..) function there is a malloc function which allocates about 540 Bytes memory on the Heap.

This was not taken into account from CubeMX when code generated .

So , at least you must define the Heap size taking into account theese extra Bytes,  to have the USB CDC port working.

the malloc function def.

0690X00000608OUQAY.png

the allocation

0690X00000608GgQAI.png

the typedef of handle

0690X00000608OKQAY.png

and the size of max packet size.

0690X00000608GqQAI.png

It will help the comunity to solve your problem if you post your IOC file  and other relative code here.

Regards

vf

Posted on September 27, 2017 at 11:51

Finally, I found it because I use Ubuntu, and there is modem manager will suspend it for a while

here is a page to tell how to prevent modem manager to keep using /dev/ttyACM0

https://linux-tips.com/t/prevent-modem-manager-to-capture-usb-serial-devices/284

now I can direct use it without wait 10 seconds =)

And really thanks you for give much info