Lib to change the clock speed of the ST Nucleo L152RE board to 32 MHz.

The ST Nucleo L152 board is running on 16 MHz out of the box. To speed up the cpu to the maximum 32MHz speed we have to change the clock setting. Simply add the lib and :

         #include "ST_L152_32MHZ.h"
        L152_init32 myinit(0);   // use the internal oscillator 

in front of your program. This should be the first line in main to ensure the frequency is changed before other objects are initialised.

This frequency is generated out of the internal RC oscillator. The frequency is not so stable like a crystal. The PLL is switched to 96MHz to enable the use of the USB interface.

If you need a more precise timing source, you have to add a external crystal.

/media/uploads/dreschpe/oszillator.jpg

You need : X3 8MHz crystal , C33 and C34 18pF 0603 , R35 and R37 have to be short with a small piece of wire.

         #include "ST_L152_32MHZ.h"
        L152_init32 myinit(1);   // use external crystal oscillator 
Committer:
dreschpe
Date:
Tue Mar 11 20:34:57 2014 +0000
Revision:
0:84e23a19e37d
Child:
1:bdeac50afe1a
Lib for the ST Nucleo L152RE board to switch the clock to 32MHz.; Out of the box the board is running on 16MHz.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dreschpe 0:84e23a19e37d 1 /* mbed library for the ST NUCLEO board L152RE
dreschpe 0:84e23a19e37d 2 * to change the CPU clock to 32 MHz
dreschpe 0:84e23a19e37d 3 * A pll clock of 96 MHz is used to enable USB
dreschpe 0:84e23a19e37d 4 *
dreschpe 0:84e23a19e37d 5 * Copyright (c) 2014 Peter Drescher - DC2PD
dreschpe 0:84e23a19e37d 6 * Released under the MIT License: http://mbed.org/license/mit
dreschpe 0:84e23a19e37d 7 *
dreschpe 0:84e23a19e37d 8 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
dreschpe 0:84e23a19e37d 9 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
dreschpe 0:84e23a19e37d 10 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
dreschpe 0:84e23a19e37d 11 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
dreschpe 0:84e23a19e37d 12 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
dreschpe 0:84e23a19e37d 13 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
dreschpe 0:84e23a19e37d 14 * THE SOFTWARE.
dreschpe 0:84e23a19e37d 15 */
dreschpe 0:84e23a19e37d 16
dreschpe 0:84e23a19e37d 17
dreschpe 0:84e23a19e37d 18 #ifndef MBED_ST_L152_32MHZ_H
dreschpe 0:84e23a19e37d 19 #define MBED_ST_L152_32MHZ_H
dreschpe 0:84e23a19e37d 20
dreschpe 0:84e23a19e37d 21 /** Setup cpu speed to 32 MHz
dreschpe 0:84e23a19e37d 22 *
dreschpe 0:84e23a19e37d 23 * @code
dreschpe 0:84e23a19e37d 24 * #include "mbed.h"
dreschpe 0:84e23a19e37d 25 * #include "ST_L152_32MHZ.h"
dreschpe 0:84e23a19e37d 26 *
dreschpe 0:84e23a19e37d 27 * // place the init before other code to ensure right timing of other objects !
dreschpe 0:84e23a19e37d 28 * L152_init32 myinit(0); // use the internal oscillator
dreschpe 0:84e23a19e37d 29 *
dreschpe 0:84e23a19e37d 30 */
dreschpe 0:84e23a19e37d 31
dreschpe 0:84e23a19e37d 32 class L152_init32
dreschpe 0:84e23a19e37d 33 {
dreschpe 0:84e23a19e37d 34 public:
dreschpe 0:84e23a19e37d 35 /** Create a L152_init32 object to change the clock
dreschpe 0:84e23a19e37d 36 * @param external = 0 use internal oscillator
dreschpe 0:84e23a19e37d 37 * @param external = 1 use external 8 MHz crystal - you have to add some comonents to the pcb !
dreschpe 0:84e23a19e37d 38 */
dreschpe 0:84e23a19e37d 39 L152_init32(unsigned int external);
dreschpe 0:84e23a19e37d 40 int clk_err;
dreschpe 0:84e23a19e37d 41
dreschpe 0:84e23a19e37d 42 protected:
dreschpe 0:84e23a19e37d 43 // do the magic ;-)
dreschpe 0:84e23a19e37d 44 int setup_clock_32MHZ(int external);
dreschpe 0:84e23a19e37d 45 };
dreschpe 0:84e23a19e37d 46
dreschpe 0:84e23a19e37d 47 #endif
dreschpe 0:84e23a19e37d 48
dreschpe 0:84e23a19e37d 49