STM32L1xx-Discovery - USB CDC

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

Post Reply
yushanh
Posts: 31
Joined: Mon Jul 29, 2013 6:23 pm

STM32L1xx-Discovery - USB CDC

Post by yushanh »

Hi all,

Currently I'm trying to modify the USB_CDC code for STM32F37x to fit into STM32L-Discovery board.


I did some research online and make changes as the following:

Hardware:
1. Attach 8 MHz oscillator and capacitor on X3 pad on the board to enable HSE
2. External pull-up 1.5K resistor connecting D+ to C12 according to the errata
3. Power supplied by the mini-usb cable, D+/D- connecting to PA12/PA11, and GND to GND pin.

|-------1.5K--------PC12
D+ ------------------------------ PA12
D- ------------------------------ PA11
GND --------------------------- GND

Software
1. I made some changes in board.h, and set the PIN_OSPEED_40M(GPIOA_USB_DM), assuming USB should be fastest speed.
#define STM32_LSECLK 32768
#define STM32_HSECLK 8000000
#define usb_lld_connect_bus(usbp) palClearPad(GPIOC, GPIOC_USB_DISC) /* GPIOC_USB_DISC is PC12, for external pull-up */
#define usb_lld_disconnect_bus(usbp) palSetPad(GPIOC, GPIOC_USB_DISC)

2. mcuconf.h
#define STM32L1xx_MCUCONF
#define STM32_HSE_ENABLED TRUE
#define STM32_PLLSRC STM32_PLLSRC_HSE

3. halconf.h
#define HAL_USE_USB TRUE

4. Lastly, I changed the Makefile according to the STM32L.


I'm not sure if I miss anything here. The code can be compiled successfully, but after I loaded the binary to the board, I could not see anything on linux by typing "lsusb" and nothing happened in the kernal.log either.

I wonder what happened here and how would linux react when it detects the properly-programmed USB device? I'm pretty new to this. If anyone could suggest me a way to test whether the USB device is working, that would be great.

I can post my code if needed.

Thanks a lot,
V.
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: STM32L1xx-Discovery - USB CDC

Post by Giovanni »

Hi,

There are some notes here: viewtopic.php?f=3&t=20&hilit=stm32l&start=70

Please make sure to configure the USB pins correctly and MAKE SURE to take the mcuconf.h file from an STM32L1 demo, they are all different.

Giovanni
yushanh
Posts: 31
Joined: Mon Jul 29, 2013 6:23 pm

Re: STM32L1xx-Discovery - USB CDC

Post by yushanh »

Thanks Giovanni!

That's a really fast response. :)

All my configuration header file are taken from STM32L, and I modified them according to STM32F37.
In my previous post, I've already set them according to the post you gave, but it is still not working.

1) The port mode must be PIN_MODE_INPUT ----------------------------------- board.h: USB_DM, USB_DP are input, and USB_DISC (external pull-up) is output
2) The port speed must be configured as 40MHz (highest) ------------------- board.h: all the USB-related ports are configured as 40 MHz
3) The port pull-ups must be disabled ------------------------------------------------- board.h: all are set to PIN_PUPDR_FLOATING.
4) The PLL output frequency must be 96MHz ------------------------------------- mcuconf.h: STM32_PLLMUL_VALUE = 12, so (12 * 8M) = 96 MHz

Did I miss anything else?

Thanks,
V.
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: STM32L1xx-Discovery - USB CDC

Post by Giovanni »

Hard to tell without having my hands on the problem, I don't have an L1 board with USB connector to make a test, may be somebody else already did it, let's wait for posts.

Is the board enumerated at least? or no reaction at all?

Giovanni
yushanh
Posts: 31
Joined: Mon Jul 29, 2013 6:23 pm

Re: STM32L1xx-Discovery - USB CDC

Post by yushanh »

No, there's no enumeration process. From the kernel log, there's nothing going on. I wonder what would be the possible reasons of it. :(

V.
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: STM32L1xx-Discovery - USB CDC

Post by Giovanni »

Verify if the pull up resistor is activated, without that the host does not enumerate the device.

Giovanni
yushanh
Posts: 31
Joined: Mon Jul 29, 2013 6:23 pm

Re: STM32L1xx-Discovery - USB CDC

Post by yushanh »

I found out the reason. There was a pretty stupid mistake.

I didn't solder the R30 resistor on the X30 pad so the external oscillator didn't work at all. I thought the resistor was there by default. :cry:

Now I learn what these tiny resistors look like.

Thanks Giovanni!
beaming
Posts: 11
Joined: Sun Nov 10, 2013 9:27 pm

Re: STM32L1xx-Discovery - USB CDC

Post by beaming »

Hi, I am also trying to use USB CDC with STM32L1xx-Discovery, without much success.

Am I right that there is a need of external oscillator for 8 MHz in order it to work
with discovery?

If so, can someone point me to a document which describes what resistors and capacitors needed for it to work?

Also, an example of working code would be greatly appreciated.

For now I am trying to work on top of testhal/STM32F1xx/USB_CDC/ code
with the following additional definitions in the main file

Code: Select all

#define usb_lld_disconnect_bus(usbp) palSetPad(GPIOC, GPIOC_PIN12);
#define usb_lld_connect_bus(usbp) palClearPad(GPIOC, GPIOC_PIN12);


My USB connection is identical to original poster, so I also have an additional
pull up resistor of 1k between D+ (PA12) and PC12.

I see that Linux kernel continuously tries to enumerate once I connect pull up resistor,
but looks like it does not succeed.
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: STM32L1xx-Discovery - USB CDC

Post by Giovanni »

Hi,

If I remember well on the Discovery schematic there are the values for the missing components, you have to make sure the USB gets exactly 48mhz. If you search the forum you will find tips about USB on the L1.

Giovanni
Post Reply