Fixed with HAL.
Fork of ST_L152_32MHZ by
Not finish yet. External crystal doesn't work.
Revision 1:bdeac50afe1a, committed 2014-03-11
- Comitter:
- dreschpe
- Date:
- Tue Mar 11 21:03:03 2014 +0000
- Parent:
- 0:84e23a19e37d
- Child:
- 2:9e2ba1d93567
- Commit message:
- change result type to enum
Changed in this revision
ST_L152_32MHZ.cpp | Show annotated file Show diff for this revision Revisions of this file |
ST_L152_32MHZ.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/ST_L152_32MHZ.cpp Tue Mar 11 20:34:57 2014 +0000 +++ b/ST_L152_32MHZ.cpp Tue Mar 11 21:03:03 2014 +0000 @@ -1,21 +1,32 @@ - - +/* mbed library for the ST NUCLEO board L152RE + * to change the CPU clock to 32 MHz + * A pll clock of 96 MHz is used to enable USB + * + * Copyright (c) 2014 Peter Drescher - DC2PD + * Released under the MIT License: http://mbed.org/license/mit + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + #include "stm32l1xx.h" #include "stm32l1xx_flash.h" #include "stm32l1xx_rcc.h" #include "ST_L152_32MHZ.h" -// set cpu clock to 32MHz - - - +// only the constructor L152_init32::L152_init32(unsigned int external){ - clk_err = setup_clock_32MHZ(external); + Status = setup_clock_32MHZ(external); } #define PLL_STARTUP_TIMEOUT 0x5000 -int L152_init32::setup_clock_32MHZ(int external) +ClockStatus L152_init32::setup_clock_32MHZ(int external) { uint32_t PLLStartUpCounter = 0,PLLStatus = 0,error; @@ -25,7 +36,7 @@ RCC_HSEConfig(RCC_HSE_ON); // start external crystal osc. error = RCC_WaitForHSEStartUp(); if(error == ERROR ) { // no external crystal - return(0); + return(EXT_ERR); } RCC_PLLConfig(RCC_PLLSource_HSE,RCC_PLLMul_12,RCC_PLLDiv_3); // setup pll to 96MHz to use USB } @@ -34,7 +45,7 @@ PLLStatus = RCC->CR & RCC_CR_PLLRDY; } while((PLLStatus == 0) && (PLLStartUpCounter < PLL_STARTUP_TIMEOUT)); // wait for pll if(PLLStatus == 0) { - return(0); + return(PLL_ERR); } FLASH_SetLatency(FLASH_Latency_1); FLASH_PrefetchBufferCmd(ENABLE); @@ -42,5 +53,5 @@ RCC_HCLKConfig(RCC_SYSCLK_Div2); RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); // switch to 32 MHz clock SystemCoreClockUpdate(); // update SystemCoreClock var - return(1); + return(OK); } \ No newline at end of file
--- 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