cancel
Showing results for 
Search instead for 
Did you mean: 

CubeMX - STM32L1 USB CDC

George.P
Associate III
Posted on May 12, 2015 at 09:45

Hello,

I have set up a CubeMX project with USB FS and CDC enabled. The device is STM32L151CCT6.

Also, I have installed the VCP 1.4.0 drivers for Win7 (x64).

When I start the debug session (IAR 7.40), Windows complain that the device is unknown and of course is not shown on the COM port list.

Moreover I use the following code in my USB gatekeeper thread, to avoid illegal usage of the device:

while (hUsbDeviceFS.dev_state != USBD_STATE_CONFIGURED)

{

    osThreadYield ();

}

but it never goes through that check. The

dev_state

always evaluates to 

USBD_STATE_DEFAULT

.

Any thoughts? Thanks!

Best regards,

George

#cubemx #stm32l1
5 REPLIES 5
alexanderpolleti9
Associate II
Posted on May 13, 2015 at 00:50

Hello George,

I have some Issues with the CDC Class, too. Actually I just stuck on a simple project without anything but USB-CDC.

I found out, that everything works fine if I just lower the optimization level to O0 (I am using Keil). Further inspection shows that if I only use O0 on the function USBD_static_malloc in usbd_conf.c everything works fine. I made it with pramgas in the source file. It looks like any optimization throws out that unused static variable...

hope that helps

Alex
George.P
Associate III
Posted on May 13, 2015 at 07:41

Hello Alex,

Thank you for your reply and sharing your thoughts.

I am using IAR with optimizations disabled.

Unfortunately the last couple of days I've been looking around the forum and found out that many people are having problems with the USB middleware.

I'll try to work on an F4 eval board for now and perhaps I'll find something.

Best regards,

George

George.P
Associate III
Posted on May 14, 2015 at 08:26

Hello,

I've found something that was creating problems.

in

usb_conf.c

line 477 (STM32L1 v1.2.0), there is a ''static malloc'' function.

void *USBD_static_malloc(uint32_t size)

{

  //static uint32_t mem[sizeof(USBD_CDC_HandleTypeDef)];

  static uint8_t mem[512];

  return mem;

}

The input obviously does nothing and this is just a complex way to declare a static variable and its pointer.

The real problem is that sizeof(USBD_CDC_HandleTypeDef) is 540.

So what the developer tried to do is fit a 540 byte long structure in a 512 byte array, for no obvious reason.

Commenting the 512 byte declaration and un-commenting the original allowed me to send messages via CDC.

I still can't receive, but I will update as soon as I manage.

Mikk Leini
Senior
Posted on May 15, 2015 at 13:20

Hi,

It might be a long shot but when you started talking about memory then i remember i had a problem with USB also and in this forum i found that somebody suggested increasing stack and heap size (in startup_xxx.s file).

stm32cube-t
Senior III
Posted on December 01, 2015 at 12:36

Dear user,

The issue has been solved by updating the  static_malloc function used by the USB device class.