Page 1 of 1

STM32L Discovery adding HSE crystal

Posted: Wed Jan 07, 2015 2:42 pm
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

Re: STM32L Discovery adding HSE crystal

Posted: Wed Jan 07, 2015 2:50 pm
by Giovanni
Hi,

You should enable HSE not just HSI.

Giovanni

Re: STM32L Discovery adding HSE crystal

Posted: Wed Jan 07, 2015 3:14 pm
by dflogeras
Sorry about that, that was a typo. HSE is enabled.

Re: STM32L Discovery adding HSE crystal

Posted: Wed Jan 07, 2015 4:00 pm
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

Re: STM32L Discovery adding HSE crystal

Posted: Wed Jan 07, 2015 4:29 pm
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?

Re: STM32L Discovery adding HSE crystal

Posted: Wed Jan 07, 2015 4:34 pm
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

Re: STM32L Discovery adding HSE crystal

Posted: Wed Jan 07, 2015 4:58 pm
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.

Re: STM32L Discovery adding HSE crystal

Posted: Wed Jan 07, 2015 5:00 pm
by Giovanni
Yes, consult the RCC/clocks section of the STM32 RM, there are constraints to respect.

Giovanni