STM32L Discovery adding HSE crystal

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

Moderator: RoccoMarco

Post Reply
dflogeras
Posts: 232
Joined: Tue Sep 03, 2013 8:16 pm
Has thanked: 8 times
Been thanked: 22 times

STM32L Discovery adding HSE crystal

Post by dflogeras »

Hi,

I'm interested in playing with USB on the STM32L152 discovery board. From my reading I see you require a more accurate clock than the internal HSI oscillator. I've added a 20pf 20ppm 8Mhz crystal X3, and the R30 C21 and C22 parts (values taken from ST's BOM).

I've changed in mcuconf.h

Code: Select all

#define STM32_HSI_ENABLED TRUE


but when I boot it, it gets stuck waiting for the clock to ready:

Code: Select all

while ((RCC->CR & RCC_CR_HSERDY) == 0);


I can also see on my scope that X3 is not producing any output. Is there something else in software that I may have missed, or should I suspect the hardware? I've checked all my soldering, as well as swapped the xtal for another (I got a bag on ebay, so could have had a bad one).

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

Re: STM32L Discovery adding HSE crystal

Post by Giovanni »

Hi,

You should enable HSE not just HSI.

Giovanni
dflogeras
Posts: 232
Joined: Tue Sep 03, 2013 8:16 pm
Has thanked: 8 times
Been thanked: 22 times

Re: STM32L Discovery adding HSE crystal

Post by dflogeras »

Sorry about that, that was a typo. HSE is enabled.
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: STM32L Discovery adding HSE crystal

Post by Giovanni »

If it is stuck in that loop then I would assume an HW problem, are there any solder jumpers to connect or disconnect?

Giovanni
dflogeras
Posts: 232
Joined: Tue Sep 03, 2013 8:16 pm
Has thanked: 8 times
Been thanked: 22 times

Re: STM32L Discovery adding HSE crystal

Post by dflogeras »

There are three:

SB17 - Not fitted (factory) - Ties OSC-IN to MCO
SB18 - Not fitted (factory) - Ties OSC-IN to PH0 pin on user connector
SB20 - Fitted (factory) - Ties OSC-OUT to PH1 pin on user connector

I've tried removing the SB20, in case it was somehow introducing capacitance preventing the XTAL from starting, but the results are the same.

I'm not sure what MCO is, but it seems to be connected to the STLINK sides clock. Perhaps you can "borrow" the 8Mhz clock from it?
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: STM32L Discovery adding HSE crystal

Post by Giovanni »

Yes, that way you can use the ST-Link as clock source.

Ah, maybe you need to remove the "bypass" from the board.h file, if it is there.

Giovanni
dflogeras
Posts: 232
Joined: Tue Sep 03, 2013 8:16 pm
Has thanked: 8 times
Been thanked: 22 times

Re: STM32L Discovery adding HSE crystal

Post by dflogeras »

That did the trick! I guess it's time to roll my own custom board.h for this project.

Now, should I set STM32_PLLSRC to HSE as well (does this determine how the peripherals get their clock)? I assume this would mean I must also double the PLLMUL value since the internal oscillator is 16Mhz.
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: STM32L Discovery adding HSE crystal

Post by Giovanni »

Yes, consult the RCC/clocks section of the STM32 RM, there are constraints to respect.

Giovanni
Post Reply