mirror of https://github.com/ARMmbed/mbed-os.git
[NUCLEO_L152RE] Change system clock to 32MHz + restart PLL after deepsleep
parent
a5cb2f420f
commit
ad9f894f10
|
@ -3,7 +3,7 @@
|
|||
* @file system_stm32l1xx.c
|
||||
* @author MCD Application Team
|
||||
* @version V1.2.0
|
||||
* @date 11-January-2014
|
||||
* @date 14-March-2014
|
||||
* @brief CMSIS Cortex-M3 Device Peripheral Access Layer System Source File.
|
||||
* This file contains the system clock configuration for STM32L1xx Ultra
|
||||
* Low power devices, and is generated by the clock configuration
|
||||
|
@ -43,11 +43,11 @@
|
|||
*=============================================================================
|
||||
* System Clock Configuration
|
||||
*=============================================================================
|
||||
* System clock source | HSI
|
||||
* System Clock source | PLL(HSI)
|
||||
*-----------------------------------------------------------------------------
|
||||
* SYSCLK | 16000000 Hz
|
||||
* SYSCLK | 32000000 Hz
|
||||
*-----------------------------------------------------------------------------
|
||||
* HCLK | 16000000 Hz
|
||||
* HCLK | 32000000 Hz
|
||||
*-----------------------------------------------------------------------------
|
||||
* AHB Prescaler | 1
|
||||
*-----------------------------------------------------------------------------
|
||||
|
@ -55,17 +55,17 @@
|
|||
*-----------------------------------------------------------------------------
|
||||
* APB2 Prescaler | 1
|
||||
*-----------------------------------------------------------------------------
|
||||
* HSE Frequency | 8000000 Hz
|
||||
* HSE Frequency | Not used
|
||||
*-----------------------------------------------------------------------------
|
||||
* PLL DIV | Not Used
|
||||
* PLL DIV | 2
|
||||
*-----------------------------------------------------------------------------
|
||||
* PLL MUL | Not Used
|
||||
* PLL MUL | 4
|
||||
*-----------------------------------------------------------------------------
|
||||
* VDD | 3.3 V
|
||||
*-----------------------------------------------------------------------------
|
||||
* Vcore | 1.8 V (Range 1)
|
||||
*-----------------------------------------------------------------------------
|
||||
* Flash Latency | 0 WS
|
||||
* Flash Latency | 1 WS
|
||||
*-----------------------------------------------------------------------------
|
||||
* Require 48MHz for USB clock | Disabled
|
||||
*-----------------------------------------------------------------------------
|
||||
|
@ -149,7 +149,7 @@
|
|||
/** @addtogroup STM32L1xx_System_Private_Variables
|
||||
* @{
|
||||
*/
|
||||
uint32_t SystemCoreClock = 16000000;
|
||||
uint32_t SystemCoreClock = 32000000;
|
||||
__I uint8_t PLLMulTable[9] = {3, 4, 6, 8, 12, 16, 24, 32, 48};
|
||||
__I uint8_t AHBPrescTable[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9};
|
||||
|
||||
|
@ -161,7 +161,7 @@ __I uint8_t AHBPrescTable[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9}
|
|||
* @{
|
||||
*/
|
||||
|
||||
static void SetSysClock(void);
|
||||
void SetSysClock(void);
|
||||
|
||||
/**
|
||||
* @}
|
||||
|
@ -206,6 +206,23 @@ void SystemInit (void)
|
|||
#else
|
||||
SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH. */
|
||||
#endif
|
||||
|
||||
/* ADDED FOR MBED DEBUG PURPOSE */
|
||||
/*
|
||||
// Enable the GPIOA peripheral
|
||||
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
|
||||
// Output the system clock on MCO pin (PA.08)
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
|
||||
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
|
||||
GPIO_Init(GPIOA, &GPIO_InitStructure);
|
||||
// Select the clock to output on MCO pin (PA.08)
|
||||
RCC_MCOConfig(RCC_MCOSource_SYSCLK, RCC_MCODiv_1);
|
||||
//RCC_MCOConfig(RCC_MCOSource_HSI, RCC_MCODiv_1);
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -305,7 +322,7 @@ void SystemCoreClockUpdate (void)
|
|||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void SetSysClock(void)
|
||||
void SetSysClock(void)
|
||||
{
|
||||
__IO uint32_t StartUpCounter = 0, HSIStatus = 0;
|
||||
|
||||
|
@ -330,42 +347,54 @@ static void SetSysClock(void)
|
|||
|
||||
if (HSIStatus == (uint32_t)0x01)
|
||||
{
|
||||
/* Flash 0 wait state */
|
||||
FLASH->ACR &= ~FLASH_ACR_LATENCY;
|
||||
/* Enable 64-bit access */
|
||||
FLASH->ACR |= FLASH_ACR_ACC64;
|
||||
|
||||
/* Disable Prefetch Buffer */
|
||||
FLASH->ACR &= ~FLASH_ACR_PRFTEN;
|
||||
/* Enable Prefetch Buffer */
|
||||
FLASH->ACR |= FLASH_ACR_PRFTEN;
|
||||
|
||||
/* Disable 64-bit access */
|
||||
FLASH->ACR &= ~FLASH_ACR_ACC64;
|
||||
/* Flash 1 wait state (latency) */
|
||||
FLASH->ACR |= FLASH_ACR_LATENCY;
|
||||
|
||||
|
||||
/* Power enable */
|
||||
RCC->APB1ENR |= RCC_APB1ENR_PWREN;
|
||||
|
||||
/* Select the Voltage Range 1 (1.8 V) */
|
||||
PWR->CR = PWR_CR_VOS_0;
|
||||
|
||||
|
||||
|
||||
/* Wait Until the Voltage Regulator is ready */
|
||||
while((PWR->CSR & PWR_CSR_VOSF) != RESET)
|
||||
{
|
||||
}
|
||||
|
||||
/* HCLK = SYSCLK /1*/
|
||||
|
||||
/* PLL configuration */
|
||||
/* SYSCLK = (HSI 16 MHz * 4) / 2 = 32 MHz */
|
||||
RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_PLLSRC | RCC_CFGR_PLLMUL | RCC_CFGR_PLLDIV));
|
||||
RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLSRC_HSI | RCC_CFGR_PLLMUL4 | RCC_CFGR_PLLDIV2);
|
||||
|
||||
/* HCLK = 32 MHz */
|
||||
RCC->CFGR |= (uint32_t)RCC_CFGR_HPRE_DIV1;
|
||||
/* PCLK2 = HCLK /1*/
|
||||
|
||||
/* PCLK2 = 32 MHz */
|
||||
RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE2_DIV1;
|
||||
|
||||
/* PCLK1 = HCLK /1*/
|
||||
/* PCLK1 = 32 MHz */
|
||||
RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE1_DIV1;
|
||||
|
||||
/* Select HSI as system clock source */
|
||||
RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_SW));
|
||||
RCC->CFGR |= (uint32_t)RCC_CFGR_SW_HSI;
|
||||
|
||||
/* Wait till HSI is used as system clock source */
|
||||
while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS) != (uint32_t)RCC_CFGR_SWS_HSI)
|
||||
/* Enable PLL */
|
||||
RCC->CR |= RCC_CR_PLLON;
|
||||
|
||||
/* Wait till PLL is ready */
|
||||
while((RCC->CR & RCC_CR_PLLRDY) == 0)
|
||||
{
|
||||
}
|
||||
|
||||
/* Select PLL as system clock source */
|
||||
RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_SW));
|
||||
RCC->CFGR |= (uint32_t)RCC_CFGR_SW_PLL;
|
||||
|
||||
/* Wait till PLL is used as system clock source */
|
||||
while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS) != (uint32_t)RCC_CFGR_SWS_PLL)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,74 +30,8 @@
|
|||
#include "sleep_api.h"
|
||||
#include "cmsis.h"
|
||||
|
||||
static void SetSysClock_HSI(void)
|
||||
{
|
||||
__IO uint32_t StartUpCounter = 0, HSIStatus = 0;
|
||||
|
||||
/* SYSCLK, HCLK, PCLK2 and PCLK1 configuration ---------------------------*/
|
||||
/* Enable HSI */
|
||||
RCC->CR |= ((uint32_t)RCC_CR_HSION);
|
||||
|
||||
/* Wait till HSI is ready and if Time out is reached exit */
|
||||
do
|
||||
{
|
||||
HSIStatus = RCC->CR & RCC_CR_HSIRDY;
|
||||
} while((HSIStatus == 0) && (StartUpCounter != HSI_STARTUP_TIMEOUT));
|
||||
|
||||
if ((RCC->CR & RCC_CR_HSIRDY) != RESET)
|
||||
{
|
||||
HSIStatus = (uint32_t)0x01;
|
||||
}
|
||||
else
|
||||
{
|
||||
HSIStatus = (uint32_t)0x00;
|
||||
}
|
||||
|
||||
if (HSIStatus == (uint32_t)0x01)
|
||||
{
|
||||
/* Flash 0 wait state */
|
||||
FLASH->ACR &= ~FLASH_ACR_LATENCY;
|
||||
|
||||
/* Disable Prefetch Buffer */
|
||||
FLASH->ACR &= ~FLASH_ACR_PRFTEN;
|
||||
|
||||
/* Disable 64-bit access */
|
||||
FLASH->ACR &= ~FLASH_ACR_ACC64;
|
||||
|
||||
/* Power enable */
|
||||
RCC->APB1ENR |= RCC_APB1ENR_PWREN;
|
||||
|
||||
/* Select the Voltage Range 1 (1.8 V) */
|
||||
PWR->CR = PWR_CR_VOS_0;
|
||||
|
||||
/* Wait Until the Voltage Regulator is ready */
|
||||
while((PWR->CSR & PWR_CSR_VOSF) != RESET)
|
||||
{
|
||||
}
|
||||
|
||||
/* HCLK = SYSCLK /1*/
|
||||
RCC->CFGR |= (uint32_t)RCC_CFGR_HPRE_DIV1;
|
||||
/* PCLK2 = HCLK /1*/
|
||||
RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE2_DIV1;
|
||||
|
||||
/* PCLK1 = HCLK /1*/
|
||||
RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE1_DIV1;
|
||||
|
||||
/* Select HSI as system clock source */
|
||||
RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_SW));
|
||||
RCC->CFGR |= (uint32_t)RCC_CFGR_SW_HSI;
|
||||
|
||||
/* Wait till HSI is used as system clock source */
|
||||
while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS) != (uint32_t)RCC_CFGR_SWS_HSI)
|
||||
{
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* If HSI fails to start-up, the application will have wrong clock
|
||||
configuration. User can add here some code to deal with this error */
|
||||
}
|
||||
}
|
||||
// This function is in the system_stm32l1xx.c file
|
||||
extern void SetSysClock(void);
|
||||
|
||||
// MCU SLEEP mode
|
||||
void sleep(void)
|
||||
|
@ -121,7 +55,6 @@ void deepsleep(void)
|
|||
// Enter Stop Mode
|
||||
PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI);
|
||||
|
||||
// After wake-up from STOP reconfigure the system clock (HSI)
|
||||
SetSysClock_HSI();
|
||||
|
||||
// After wake-up from STOP reconfigure the PLL
|
||||
SetSysClock();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue