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 
Revision:
1:bdeac50afe1a
Parent:
0:84e23a19e37d
--- a/ST_L152_32MHZ.h	Tue Mar 11 20:34:57 2014 +0000
+++ b/ST_L152_32MHZ.h	Tue Mar 11 21:03:03 2014 +0000
@@ -29,6 +29,8 @@
  * 
  */
 
+typedef enum { OK = 0 , PLL_ERR, EXT_ERR }ClockStatus;
+
 class L152_init32
 {
 public:
@@ -37,11 +39,11 @@
    * @param external = 1 use external 8 MHz crystal - you have to add some comonents to the pcb !
 */
 L152_init32(unsigned int external);
-int clk_err;
+ClockStatus Status;
 
 protected:
 // do the magic ;-)
-int setup_clock_32MHZ(int external);
+ClockStatus setup_clock_32MHZ(int external);
 };
 
 #endif