|
@@ -7,15 +7,15 @@
|
|
****************************************************************************************/
|
|
****************************************************************************************/
|
|
#include "ch32f10x.h"
|
|
#include "ch32f10x.h"
|
|
|
|
|
|
-/*
|
|
|
|
- * Uncomment the line corresponding to the desired System clock (SYSCLK) frequency (after
|
|
|
|
|
|
+/*
|
|
|
|
+ * Uncomment the line corresponding to the desired System clock (SYSCLK) frequency (after
|
|
* reset the HSI is used as SYSCLK source).
|
|
* reset the HSI is used as SYSCLK source).
|
|
- * If none of the define below is enabled, the HSI is used as System clock source.
|
|
|
|
|
|
+ * If none of the define below is enabled, the HSI is used as System clock source.
|
|
*/
|
|
*/
|
|
-// #define SYSCLK_FREQ_HSE HSE_VALUE
|
|
|
|
-/* #define SYSCLK_FREQ_24MHz 24000000 */
|
|
|
|
-// #define SYSCLK_FREQ_48MHz 48000000
|
|
|
|
-/* #define SYSCLK_FREQ_56MHz 56000000 */
|
|
|
|
|
|
+// #define SYSCLK_FREQ_HSE HSE_VALUE
|
|
|
|
+/* #define SYSCLK_FREQ_24MHz 24000000 */
|
|
|
|
+// #define SYSCLK_FREQ_48MHz 48000000
|
|
|
|
+/* #define SYSCLK_FREQ_56MHz 56000000 */
|
|
#define SYSCLK_FREQ_72MHz 72000000
|
|
#define SYSCLK_FREQ_72MHz 72000000
|
|
|
|
|
|
|
|
|
|
@@ -23,10 +23,10 @@
|
|
/* #define VECT_TAB_SRAM */
|
|
/* #define VECT_TAB_SRAM */
|
|
|
|
|
|
/* Vector Table base offset field This value must be a multiple of 0x200 */
|
|
/* Vector Table base offset field This value must be a multiple of 0x200 */
|
|
-#define VECT_TAB_OFFSET 0x0
|
|
|
|
|
|
+#define VECT_TAB_OFFSET 0x0
|
|
|
|
|
|
|
|
|
|
-/* Clock Definitions */
|
|
|
|
|
|
+/* Clock Definitions */
|
|
#ifdef SYSCLK_FREQ_HSE
|
|
#ifdef SYSCLK_FREQ_HSE
|
|
uint32_t SystemCoreClock = SYSCLK_FREQ_HSE; /*!< System Clock Frequency (Core Clock) */
|
|
uint32_t SystemCoreClock = SYSCLK_FREQ_HSE; /*!< System Clock Frequency (Core Clock) */
|
|
#elif defined SYSCLK_FREQ_24MHz
|
|
#elif defined SYSCLK_FREQ_24MHz
|
|
@@ -54,19 +54,19 @@ static void SetSysClock(void);
|
|
#elif defined SYSCLK_FREQ_48MHz
|
|
#elif defined SYSCLK_FREQ_48MHz
|
|
static void SetSysClockTo48(void);
|
|
static void SetSysClockTo48(void);
|
|
#elif defined SYSCLK_FREQ_56MHz
|
|
#elif defined SYSCLK_FREQ_56MHz
|
|
- static void SetSysClockTo56(void);
|
|
|
|
|
|
+ static void SetSysClockTo56(void);
|
|
#elif defined SYSCLK_FREQ_72MHz
|
|
#elif defined SYSCLK_FREQ_72MHz
|
|
static void SetSysClockTo72(void);
|
|
static void SetSysClockTo72(void);
|
|
#endif
|
|
#endif
|
|
|
|
|
|
#ifdef DATA_IN_ExtSRAM
|
|
#ifdef DATA_IN_ExtSRAM
|
|
- static void SystemInit_ExtMemCtl(void);
|
|
|
|
|
|
+ static void SystemInit_ExtMemCtl(void);
|
|
#endif /* DATA_IN_ExtSRAM */
|
|
#endif /* DATA_IN_ExtSRAM */
|
|
|
|
|
|
|
|
|
|
/******************************************************************************************
|
|
/******************************************************************************************
|
|
* Function Name : SystemInit
|
|
* Function Name : SystemInit
|
|
-* Description : Setup the microcontroller system Initialize the Embedded Flash Interface,
|
|
|
|
|
|
+* Description : Setup the microcontroller system Initialize the Embedded Flash Interface,
|
|
* the PLL and update the SystemCoreClock variable.
|
|
* the PLL and update the SystemCoreClock variable.
|
|
* Input : None
|
|
* Input : None
|
|
* Return : None
|
|
* Return : None
|
|
@@ -78,14 +78,14 @@ void SystemInit (void)
|
|
RCC->CTLR &= (uint32_t)0xFEF6FFFF;
|
|
RCC->CTLR &= (uint32_t)0xFEF6FFFF;
|
|
RCC->CTLR &= (uint32_t)0xFFFBFFFF;
|
|
RCC->CTLR &= (uint32_t)0xFFFBFFFF;
|
|
RCC->CFGR0 &= (uint32_t)0xFF80FFFF;
|
|
RCC->CFGR0 &= (uint32_t)0xFF80FFFF;
|
|
- RCC->INTR = 0x009F0000;
|
|
|
|
|
|
+ RCC->INTR = 0x009F0000;
|
|
SetSysClock();
|
|
SetSysClock();
|
|
-
|
|
|
|
|
|
+
|
|
#ifdef VECT_TAB_SRAM
|
|
#ifdef VECT_TAB_SRAM
|
|
SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM. */
|
|
SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM. */
|
|
#else
|
|
#else
|
|
SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH. */
|
|
SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH. */
|
|
-#endif
|
|
|
|
|
|
+#endif
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -98,27 +98,27 @@ void SystemInit (void)
|
|
void SystemCoreClockUpdate (void)
|
|
void SystemCoreClockUpdate (void)
|
|
{
|
|
{
|
|
uint32_t tmp = 0, pllmull = 0, pllsource = 0;
|
|
uint32_t tmp = 0, pllmull = 0, pllsource = 0;
|
|
-
|
|
|
|
|
|
+
|
|
tmp = RCC->CFGR0 & RCC_SWS;
|
|
tmp = RCC->CFGR0 & RCC_SWS;
|
|
-
|
|
|
|
|
|
+
|
|
switch (tmp)
|
|
switch (tmp)
|
|
{
|
|
{
|
|
case 0x00:
|
|
case 0x00:
|
|
SystemCoreClock = HSI_VALUE;
|
|
SystemCoreClock = HSI_VALUE;
|
|
break;
|
|
break;
|
|
- case 0x04:
|
|
|
|
|
|
+ case 0x04:
|
|
SystemCoreClock = HSE_VALUE;
|
|
SystemCoreClock = HSE_VALUE;
|
|
break;
|
|
break;
|
|
- case 0x08:
|
|
|
|
|
|
+ case 0x08:
|
|
pllmull = RCC->CFGR0 & RCC_PLLMULL;
|
|
pllmull = RCC->CFGR0 & RCC_PLLMULL;
|
|
- pllsource = RCC->CFGR0 & RCC_PLLSRC;
|
|
|
|
|
|
+ pllsource = RCC->CFGR0 & RCC_PLLSRC;
|
|
pllmull = ( pllmull >> 18) + 2;
|
|
pllmull = ( pllmull >> 18) + 2;
|
|
if (pllsource == 0x00)
|
|
if (pllsource == 0x00)
|
|
{
|
|
{
|
|
SystemCoreClock = (HSI_VALUE >> 1) * pllmull;
|
|
SystemCoreClock = (HSI_VALUE >> 1) * pllmull;
|
|
}
|
|
}
|
|
else
|
|
else
|
|
- {
|
|
|
|
|
|
+ {
|
|
if ((RCC->CFGR0 & RCC_PLLXTPRE) != (uint32_t)RESET)
|
|
if ((RCC->CFGR0 & RCC_PLLXTPRE) != (uint32_t)RESET)
|
|
{
|
|
{
|
|
SystemCoreClock = (HSE_VALUE >> 1) * pllmull;
|
|
SystemCoreClock = (HSE_VALUE >> 1) * pllmull;
|
|
@@ -133,15 +133,15 @@ void SystemCoreClockUpdate (void)
|
|
SystemCoreClock = HSI_VALUE;
|
|
SystemCoreClock = HSI_VALUE;
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
tmp = AHBPrescTable[((RCC->CFGR0 & RCC_HPRE) >> 4)];
|
|
tmp = AHBPrescTable[((RCC->CFGR0 & RCC_HPRE) >> 4)];
|
|
- SystemCoreClock >>= tmp;
|
|
|
|
|
|
+ SystemCoreClock >>= tmp;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
/******************************************************************************************
|
|
/******************************************************************************************
|
|
* Function Name : SetSysClock
|
|
* Function Name : SetSysClock
|
|
-* Description : Configures the System clock frequency, HCLK, PCLK2 and PCLK1 prescalers.
|
|
|
|
|
|
+* Description : Configures the System clock frequency, HCLK, PCLK2 and PCLK1 prescalers.
|
|
* Input : None
|
|
* Input : None
|
|
* Return : None
|
|
* Return : None
|
|
*******************************************************************************************/
|
|
*******************************************************************************************/
|
|
@@ -154,14 +154,14 @@ static void SetSysClock(void)
|
|
#elif defined SYSCLK_FREQ_48MHz
|
|
#elif defined SYSCLK_FREQ_48MHz
|
|
SetSysClockTo48();
|
|
SetSysClockTo48();
|
|
#elif defined SYSCLK_FREQ_56MHz
|
|
#elif defined SYSCLK_FREQ_56MHz
|
|
- SetSysClockTo56();
|
|
|
|
|
|
+ SetSysClockTo56();
|
|
#elif defined SYSCLK_FREQ_72MHz
|
|
#elif defined SYSCLK_FREQ_72MHz
|
|
SetSysClockTo72();
|
|
SetSysClockTo72();
|
|
#endif
|
|
#endif
|
|
-
|
|
|
|
|
|
+
|
|
/* If none of the define above is enabled, the HSI is used as System clock
|
|
/* If none of the define above is enabled, the HSI is used as System clock
|
|
- * source (default after reset)
|
|
|
|
- */
|
|
|
|
|
|
+ * source (default after reset)
|
|
|
|
+ */
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -169,27 +169,27 @@ static void SetSysClock(void)
|
|
|
|
|
|
/******************************************************************************************
|
|
/******************************************************************************************
|
|
* Function Name : SystemInit_ExtMemCtl
|
|
* Function Name : SystemInit_ExtMemCtl
|
|
-* Description : Setup the external memory controller.
|
|
|
|
|
|
+* Description : Setup the external memory controller.
|
|
* Input : None
|
|
* Input : None
|
|
* Return : None
|
|
* Return : None
|
|
*******************************************************************************************/
|
|
*******************************************************************************************/
|
|
-void SystemInit_ExtMemCtl(void)
|
|
|
|
|
|
+void SystemInit_ExtMemCtl(void)
|
|
{
|
|
{
|
|
RCC->AHBENR = 0x00000114;
|
|
RCC->AHBENR = 0x00000114;
|
|
RCC->APB2ENR = 0x000001E0;
|
|
RCC->APB2ENR = 0x000001E0;
|
|
-
|
|
|
|
- GPIOD->CRL = 0x44BB44BB;
|
|
|
|
|
|
+
|
|
|
|
+ GPIOD->CRL = 0x44BB44BB;
|
|
GPIOD->CRH = 0xBBBBBBBB;
|
|
GPIOD->CRH = 0xBBBBBBBB;
|
|
|
|
|
|
- GPIOE->CRL = 0xB44444BB;
|
|
|
|
|
|
+ GPIOE->CRL = 0xB44444BB;
|
|
GPIOE->CRH = 0xBBBBBBBB;
|
|
GPIOE->CRH = 0xBBBBBBBB;
|
|
|
|
|
|
- GPIOF->CRL = 0x44BBBBBB;
|
|
|
|
|
|
+ GPIOF->CRL = 0x44BBBBBB;
|
|
GPIOF->CRH = 0xBBBB4444;
|
|
GPIOF->CRH = 0xBBBB4444;
|
|
|
|
|
|
- GPIOG->CRL = 0x44BBBBBB;
|
|
|
|
|
|
+ GPIOG->CRL = 0x44BBBBBB;
|
|
GPIOG->CRH = 0x44444B44;
|
|
GPIOG->CRH = 0x44444B44;
|
|
-
|
|
|
|
|
|
+
|
|
FSMC_Bank1->BTCR[4] = 0x00001011;
|
|
FSMC_Bank1->BTCR[4] = 0x00001011;
|
|
FSMC_Bank1->BTCR[5] = 0x00000200;
|
|
FSMC_Bank1->BTCR[5] = 0x00000200;
|
|
}
|
|
}
|
|
@@ -207,15 +207,15 @@ void SystemInit_ExtMemCtl(void)
|
|
static void SetSysClockToHSE(void)
|
|
static void SetSysClockToHSE(void)
|
|
{
|
|
{
|
|
__IO uint32_t StartUpCounter = 0, HSEStatus = 0;
|
|
__IO uint32_t StartUpCounter = 0, HSEStatus = 0;
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+
|
|
RCC->CTLR |= ((uint32_t)RCC_HSEON);
|
|
RCC->CTLR |= ((uint32_t)RCC_HSEON);
|
|
-
|
|
|
|
|
|
+
|
|
/* Wait till HSE is ready and if Time out is reached exit */
|
|
/* Wait till HSE is ready and if Time out is reached exit */
|
|
do
|
|
do
|
|
{
|
|
{
|
|
HSEStatus = RCC->CTLR & RCC_HSERDY;
|
|
HSEStatus = RCC->CTLR & RCC_HSERDY;
|
|
- StartUpCounter++;
|
|
|
|
|
|
+ StartUpCounter++;
|
|
} while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));
|
|
} while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));
|
|
|
|
|
|
if ((RCC->CTLR & RCC_HSERDY) != RESET)
|
|
if ((RCC->CTLR & RCC_HSERDY) != RESET)
|
|
@@ -225,7 +225,7 @@ static void SetSysClockToHSE(void)
|
|
else
|
|
else
|
|
{
|
|
{
|
|
HSEStatus = (uint32_t)0x00;
|
|
HSEStatus = (uint32_t)0x00;
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
|
|
|
if (HSEStatus == (uint32_t)0x01)
|
|
if (HSEStatus == (uint32_t)0x01)
|
|
{
|
|
{
|
|
@@ -233,17 +233,17 @@ static void SetSysClockToHSE(void)
|
|
/* Flash 0 wait state */
|
|
/* Flash 0 wait state */
|
|
FLASH->ACTLR &= (uint32_t)((uint32_t)~FLASH_ACTLR_LATENCY);
|
|
FLASH->ACTLR &= (uint32_t)((uint32_t)~FLASH_ACTLR_LATENCY);
|
|
FLASH->ACTLR |= (uint32_t)FLASH_ACTLR_LATENCY_0;
|
|
FLASH->ACTLR |= (uint32_t)FLASH_ACTLR_LATENCY_0;
|
|
-
|
|
|
|
- /* HCLK = SYSCLK */
|
|
|
|
- RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1;
|
|
|
|
|
|
+
|
|
|
|
+ /* HCLK = SYSCLK */
|
|
|
|
+ RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1;
|
|
/* PCLK2 = HCLK */
|
|
/* PCLK2 = HCLK */
|
|
RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1;
|
|
RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1;
|
|
/* PCLK1 = HCLK */
|
|
/* PCLK1 = HCLK */
|
|
RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV1;
|
|
RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV1;
|
|
-
|
|
|
|
|
|
+
|
|
/* Select HSE as system clock source */
|
|
/* Select HSE as system clock source */
|
|
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_SW));
|
|
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_SW));
|
|
- RCC->CFGR0 |= (uint32_t)RCC_SW_HSE;
|
|
|
|
|
|
+ RCC->CFGR0 |= (uint32_t)RCC_SW_HSE;
|
|
|
|
|
|
/* Wait till HSE is used as system clock source */
|
|
/* Wait till HSE is used as system clock source */
|
|
while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x04)
|
|
while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x04)
|
|
@@ -251,11 +251,11 @@ static void SetSysClockToHSE(void)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
else
|
|
- {
|
|
|
|
- /* If HSE fails to start-up, the application will have wrong clock
|
|
|
|
- * configuration. User can add here some code to deal with this error
|
|
|
|
- */
|
|
|
|
- }
|
|
|
|
|
|
+ {
|
|
|
|
+ /* If HSE fails to start-up, the application will have wrong clock
|
|
|
|
+ * configuration. User can add here some code to deal with this error
|
|
|
|
+ */
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
#elif defined SYSCLK_FREQ_24MHz
|
|
#elif defined SYSCLK_FREQ_24MHz
|
|
@@ -269,14 +269,14 @@ static void SetSysClockToHSE(void)
|
|
static void SetSysClockTo24(void)
|
|
static void SetSysClockTo24(void)
|
|
{
|
|
{
|
|
__IO uint32_t StartUpCounter = 0, HSEStatus = 0;
|
|
__IO uint32_t StartUpCounter = 0, HSEStatus = 0;
|
|
-
|
|
|
|
|
|
+
|
|
RCC->CTLR |= ((uint32_t)RCC_HSEON);
|
|
RCC->CTLR |= ((uint32_t)RCC_HSEON);
|
|
-
|
|
|
|
|
|
+
|
|
/* Wait till HSE is ready and if Time out is reached exit */
|
|
/* Wait till HSE is ready and if Time out is reached exit */
|
|
do
|
|
do
|
|
{
|
|
{
|
|
HSEStatus = RCC->CTLR & RCC_HSERDY;
|
|
HSEStatus = RCC->CTLR & RCC_HSERDY;
|
|
- StartUpCounter++;
|
|
|
|
|
|
+ StartUpCounter++;
|
|
} while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));
|
|
} while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));
|
|
|
|
|
|
if ((RCC->CTLR & RCC_HSERDY) != RESET)
|
|
if ((RCC->CTLR & RCC_HSERDY) != RESET)
|
|
@@ -286,7 +286,7 @@ static void SetSysClockTo24(void)
|
|
else
|
|
else
|
|
{
|
|
{
|
|
HSEStatus = (uint32_t)0x00;
|
|
HSEStatus = (uint32_t)0x00;
|
|
- }
|
|
|
|
|
|
+ }
|
|
if (HSEStatus == (uint32_t)0x01)
|
|
if (HSEStatus == (uint32_t)0x01)
|
|
{
|
|
{
|
|
/* Enable Prefetch Buffer */
|
|
/* Enable Prefetch Buffer */
|
|
@@ -294,12 +294,12 @@ static void SetSysClockTo24(void)
|
|
|
|
|
|
/* Flash 0 wait state */
|
|
/* Flash 0 wait state */
|
|
FLASH->ACTLR &= (uint32_t)((uint32_t)~FLASH_ACTLR_LATENCY);
|
|
FLASH->ACTLR &= (uint32_t)((uint32_t)~FLASH_ACTLR_LATENCY);
|
|
- FLASH->ACTLR |= (uint32_t)FLASH_ACTLR_LATENCY_0;
|
|
|
|
|
|
+ FLASH->ACTLR |= (uint32_t)FLASH_ACTLR_LATENCY_0;
|
|
|
|
|
|
/* HCLK = SYSCLK */
|
|
/* HCLK = SYSCLK */
|
|
- RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1;
|
|
|
|
|
|
+ RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1;
|
|
/* PCLK2 = HCLK */
|
|
/* PCLK2 = HCLK */
|
|
- RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1;
|
|
|
|
|
|
+ RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1;
|
|
/* PCLK1 = HCLK */
|
|
/* PCLK1 = HCLK */
|
|
RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV1;
|
|
RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV1;
|
|
|
|
|
|
@@ -307,25 +307,25 @@ static void SetSysClockTo24(void)
|
|
RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSE | RCC_PLLXTPRE_HSE | RCC_PLLMULL3);
|
|
RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSE | RCC_PLLXTPRE_HSE | RCC_PLLMULL3);
|
|
/* Enable PLL */
|
|
/* Enable PLL */
|
|
RCC->CTLR |= RCC_PLLON;
|
|
RCC->CTLR |= RCC_PLLON;
|
|
-
|
|
|
|
|
|
+
|
|
/* Wait till PLL is ready */
|
|
/* Wait till PLL is ready */
|
|
while((RCC->CTLR & RCC_PLLRDY) == 0)
|
|
while((RCC->CTLR & RCC_PLLRDY) == 0)
|
|
{
|
|
{
|
|
}
|
|
}
|
|
/* Select PLL as system clock source */
|
|
/* Select PLL as system clock source */
|
|
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_SW));
|
|
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_SW));
|
|
- RCC->CFGR0 |= (uint32_t)RCC_SW_PLL;
|
|
|
|
|
|
+ RCC->CFGR0 |= (uint32_t)RCC_SW_PLL;
|
|
/* Wait till PLL is used as system clock source */
|
|
/* Wait till PLL is used as system clock source */
|
|
while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08)
|
|
while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08)
|
|
{
|
|
{
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
else
|
|
- {
|
|
|
|
- /* If HSE fails to start-up, the application will have wrong clock
|
|
|
|
- * configuration. User can add here some code to deal with this error
|
|
|
|
- */
|
|
|
|
- }
|
|
|
|
|
|
+ {
|
|
|
|
+ /* If HSE fails to start-up, the application will have wrong clock
|
|
|
|
+ * configuration. User can add here some code to deal with this error
|
|
|
|
+ */
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -340,14 +340,14 @@ static void SetSysClockTo24(void)
|
|
static void SetSysClockTo48(void)
|
|
static void SetSysClockTo48(void)
|
|
{
|
|
{
|
|
__IO uint32_t StartUpCounter = 0, HSEStatus = 0;
|
|
__IO uint32_t StartUpCounter = 0, HSEStatus = 0;
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+
|
|
RCC->CTLR |= ((uint32_t)RCC_HSEON);
|
|
RCC->CTLR |= ((uint32_t)RCC_HSEON);
|
|
/* Wait till HSE is ready and if Time out is reached exit */
|
|
/* Wait till HSE is ready and if Time out is reached exit */
|
|
do
|
|
do
|
|
{
|
|
{
|
|
HSEStatus = RCC->CTLR & RCC_HSERDY;
|
|
HSEStatus = RCC->CTLR & RCC_HSERDY;
|
|
- StartUpCounter++;
|
|
|
|
|
|
+ StartUpCounter++;
|
|
} while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));
|
|
} while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));
|
|
|
|
|
|
if ((RCC->CTLR & RCC_HSERDY) != RESET)
|
|
if ((RCC->CTLR & RCC_HSERDY) != RESET)
|
|
@@ -357,7 +357,7 @@ static void SetSysClockTo48(void)
|
|
else
|
|
else
|
|
{
|
|
{
|
|
HSEStatus = (uint32_t)0x00;
|
|
HSEStatus = (uint32_t)0x00;
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
|
|
|
if (HSEStatus == (uint32_t)0x01)
|
|
if (HSEStatus == (uint32_t)0x01)
|
|
{
|
|
{
|
|
@@ -366,12 +366,12 @@ static void SetSysClockTo48(void)
|
|
|
|
|
|
/* Flash 1 wait state */
|
|
/* Flash 1 wait state */
|
|
FLASH->ACTLR &= (uint32_t)((uint32_t)~FLASH_ACTLR_LATENCY);
|
|
FLASH->ACTLR &= (uint32_t)((uint32_t)~FLASH_ACTLR_LATENCY);
|
|
- FLASH->ACTLR |= (uint32_t)FLASH_ACTLR_LATENCY_1;
|
|
|
|
-
|
|
|
|
|
|
+ FLASH->ACTLR |= (uint32_t)FLASH_ACTLR_LATENCY_1;
|
|
|
|
+
|
|
/* HCLK = SYSCLK */
|
|
/* HCLK = SYSCLK */
|
|
- RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1;
|
|
|
|
|
|
+ RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1;
|
|
/* PCLK2 = HCLK */
|
|
/* PCLK2 = HCLK */
|
|
- RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1;
|
|
|
|
|
|
+ RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1;
|
|
/* PCLK1 = HCLK */
|
|
/* PCLK1 = HCLK */
|
|
RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV2;
|
|
RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV2;
|
|
|
|
|
|
@@ -387,19 +387,19 @@ static void SetSysClockTo48(void)
|
|
}
|
|
}
|
|
/* Select PLL as system clock source */
|
|
/* Select PLL as system clock source */
|
|
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_SW));
|
|
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_SW));
|
|
- RCC->CFGR0 |= (uint32_t)RCC_SW_PLL;
|
|
|
|
|
|
+ RCC->CFGR0 |= (uint32_t)RCC_SW_PLL;
|
|
/* Wait till PLL is used as system clock source */
|
|
/* Wait till PLL is used as system clock source */
|
|
while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08)
|
|
while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08)
|
|
{
|
|
{
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
else
|
|
- {
|
|
|
|
- /*
|
|
|
|
- * If HSE fails to start-up, the application will have wrong clock
|
|
|
|
- * configuration. User can add here some code to deal with this error
|
|
|
|
- */
|
|
|
|
- }
|
|
|
|
|
|
+ {
|
|
|
|
+ /*
|
|
|
|
+ * If HSE fails to start-up, the application will have wrong clock
|
|
|
|
+ * configuration. User can add here some code to deal with this error
|
|
|
|
+ */
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
#elif defined SYSCLK_FREQ_56MHz
|
|
#elif defined SYSCLK_FREQ_56MHz
|
|
@@ -413,14 +413,14 @@ static void SetSysClockTo48(void)
|
|
static void SetSysClockTo56(void)
|
|
static void SetSysClockTo56(void)
|
|
{
|
|
{
|
|
__IO uint32_t StartUpCounter = 0, HSEStatus = 0;
|
|
__IO uint32_t StartUpCounter = 0, HSEStatus = 0;
|
|
-
|
|
|
|
|
|
+
|
|
RCC->CTLR |= ((uint32_t)RCC_HSEON);
|
|
RCC->CTLR |= ((uint32_t)RCC_HSEON);
|
|
|
|
|
|
/* Wait till HSE is ready and if Time out is reached exit */
|
|
/* Wait till HSE is ready and if Time out is reached exit */
|
|
do
|
|
do
|
|
{
|
|
{
|
|
HSEStatus = RCC->CTLR & RCC_HSERDY;
|
|
HSEStatus = RCC->CTLR & RCC_HSERDY;
|
|
- StartUpCounter++;
|
|
|
|
|
|
+ StartUpCounter++;
|
|
} while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));
|
|
} while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));
|
|
|
|
|
|
if ((RCC->CTLR & RCC_HSERDY) != RESET)
|
|
if ((RCC->CTLR & RCC_HSERDY) != RESET)
|
|
@@ -430,7 +430,7 @@ static void SetSysClockTo56(void)
|
|
else
|
|
else
|
|
{
|
|
{
|
|
HSEStatus = (uint32_t)0x00;
|
|
HSEStatus = (uint32_t)0x00;
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
|
|
|
if (HSEStatus == (uint32_t)0x01)
|
|
if (HSEStatus == (uint32_t)0x01)
|
|
{
|
|
{
|
|
@@ -439,15 +439,15 @@ static void SetSysClockTo56(void)
|
|
|
|
|
|
/* Flash 2 wait state */
|
|
/* Flash 2 wait state */
|
|
FLASH->ACTLR &= (uint32_t)((uint32_t)~FLASH_ACTLR_LATENCY);
|
|
FLASH->ACTLR &= (uint32_t)((uint32_t)~FLASH_ACTLR_LATENCY);
|
|
- FLASH->ACTLR |= (uint32_t)FLASH_ACTLR_LATENCY_2;
|
|
|
|
-
|
|
|
|
|
|
+ FLASH->ACTLR |= (uint32_t)FLASH_ACTLR_LATENCY_2;
|
|
|
|
+
|
|
/* HCLK = SYSCLK */
|
|
/* HCLK = SYSCLK */
|
|
- RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1;
|
|
|
|
|
|
+ RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1;
|
|
/* PCLK2 = HCLK */
|
|
/* PCLK2 = HCLK */
|
|
RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1;
|
|
RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1;
|
|
/* PCLK1 = HCLK */
|
|
/* PCLK1 = HCLK */
|
|
RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV2;
|
|
RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV2;
|
|
-
|
|
|
|
|
|
+
|
|
/* PLL configuration: PLLCLK = HSE * 7 = 56 MHz */
|
|
/* PLL configuration: PLLCLK = HSE * 7 = 56 MHz */
|
|
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_PLLSRC | RCC_PLLXTPRE | RCC_PLLMULL));
|
|
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_PLLSRC | RCC_PLLXTPRE | RCC_PLLMULL));
|
|
RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSE | RCC_PLLMULL7);
|
|
RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSE | RCC_PLLMULL7);
|
|
@@ -460,19 +460,19 @@ static void SetSysClockTo56(void)
|
|
|
|
|
|
/* Select PLL as system clock source */
|
|
/* Select PLL as system clock source */
|
|
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_SW));
|
|
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_SW));
|
|
- RCC->CFGR0 |= (uint32_t)RCC_SW_PLL;
|
|
|
|
|
|
+ RCC->CFGR0 |= (uint32_t)RCC_SW_PLL;
|
|
/* Wait till PLL is used as system clock source */
|
|
/* Wait till PLL is used as system clock source */
|
|
while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08)
|
|
while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08)
|
|
{
|
|
{
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
else
|
|
- {
|
|
|
|
- /*
|
|
|
|
- * If HSE fails to start-up, the application will have wrong clock
|
|
|
|
- * configuration. User can add here some code to deal with this error
|
|
|
|
- */
|
|
|
|
- }
|
|
|
|
|
|
+ {
|
|
|
|
+ /*
|
|
|
|
+ * If HSE fails to start-up, the application will have wrong clock
|
|
|
|
+ * configuration. User can add here some code to deal with this error
|
|
|
|
+ */
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
#elif defined SYSCLK_FREQ_72MHz
|
|
#elif defined SYSCLK_FREQ_72MHz
|
|
@@ -486,14 +486,14 @@ static void SetSysClockTo56(void)
|
|
static void SetSysClockTo72(void)
|
|
static void SetSysClockTo72(void)
|
|
{
|
|
{
|
|
__IO uint32_t StartUpCounter = 0, HSEStatus = 0;
|
|
__IO uint32_t StartUpCounter = 0, HSEStatus = 0;
|
|
-
|
|
|
|
|
|
+
|
|
RCC->CTLR |= ((uint32_t)RCC_HSEON);
|
|
RCC->CTLR |= ((uint32_t)RCC_HSEON);
|
|
-
|
|
|
|
|
|
+
|
|
/* Wait till HSE is ready and if Time out is reached exit */
|
|
/* Wait till HSE is ready and if Time out is reached exit */
|
|
do
|
|
do
|
|
{
|
|
{
|
|
HSEStatus = RCC->CTLR & RCC_HSERDY;
|
|
HSEStatus = RCC->CTLR & RCC_HSERDY;
|
|
- StartUpCounter++;
|
|
|
|
|
|
+ StartUpCounter++;
|
|
} while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));
|
|
} while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));
|
|
|
|
|
|
if ((RCC->CTLR & RCC_HSERDY) != RESET)
|
|
if ((RCC->CTLR & RCC_HSERDY) != RESET)
|
|
@@ -503,7 +503,7 @@ static void SetSysClockTo72(void)
|
|
else
|
|
else
|
|
{
|
|
{
|
|
HSEStatus = (uint32_t)0x00;
|
|
HSEStatus = (uint32_t)0x00;
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
|
|
|
if (HSEStatus == (uint32_t)0x01)
|
|
if (HSEStatus == (uint32_t)0x01)
|
|
{
|
|
{
|
|
@@ -512,15 +512,15 @@ static void SetSysClockTo72(void)
|
|
|
|
|
|
/* Flash 2 wait state */
|
|
/* Flash 2 wait state */
|
|
FLASH->ACTLR &= (uint32_t)((uint32_t)~FLASH_ACTLR_LATENCY);
|
|
FLASH->ACTLR &= (uint32_t)((uint32_t)~FLASH_ACTLR_LATENCY);
|
|
- FLASH->ACTLR |= (uint32_t)FLASH_ACTLR_LATENCY_2;
|
|
|
|
|
|
+ FLASH->ACTLR |= (uint32_t)FLASH_ACTLR_LATENCY_2;
|
|
|
|
|
|
/* HCLK = SYSCLK */
|
|
/* HCLK = SYSCLK */
|
|
- RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1;
|
|
|
|
|
|
+ RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1;
|
|
/* PCLK2 = HCLK */
|
|
/* PCLK2 = HCLK */
|
|
- RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1;
|
|
|
|
|
|
+ RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1;
|
|
/* PCLK1 = HCLK */
|
|
/* PCLK1 = HCLK */
|
|
RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV2;
|
|
RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV2;
|
|
-
|
|
|
|
|
|
+
|
|
/* PLL configuration: PLLCLK = HSE * 9 = 72 MHz */
|
|
/* PLL configuration: PLLCLK = HSE * 9 = 72 MHz */
|
|
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_PLLSRC | RCC_PLLXTPRE |
|
|
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_PLLSRC | RCC_PLLXTPRE |
|
|
RCC_PLLMULL));
|
|
RCC_PLLMULL));
|
|
@@ -530,25 +530,25 @@ static void SetSysClockTo72(void)
|
|
/* Wait till PLL is ready */
|
|
/* Wait till PLL is ready */
|
|
while((RCC->CTLR & RCC_PLLRDY) == 0)
|
|
while((RCC->CTLR & RCC_PLLRDY) == 0)
|
|
{
|
|
{
|
|
- }
|
|
|
|
|
|
+ }
|
|
/* Select PLL as system clock source */
|
|
/* Select PLL as system clock source */
|
|
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_SW));
|
|
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_SW));
|
|
- RCC->CFGR0 |= (uint32_t)RCC_SW_PLL;
|
|
|
|
|
|
+ RCC->CFGR0 |= (uint32_t)RCC_SW_PLL;
|
|
/* Wait till PLL is used as system clock source */
|
|
/* Wait till PLL is used as system clock source */
|
|
while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08)
|
|
while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08)
|
|
{
|
|
{
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
else
|
|
- {
|
|
|
|
- /*
|
|
|
|
- * If HSE fails to start-up, the application will have wrong clock
|
|
|
|
- * configuration. User can add here some code to deal with this error
|
|
|
|
- */
|
|
|
|
|
|
+ {
|
|
|
|
+ /*
|
|
|
|
+ * If HSE fails to start-up, the application will have wrong clock
|
|
|
|
+ * configuration. User can add here some code to deal with this error
|
|
|
|
+ */
|
|
}
|
|
}
|
|
}
|
|
}
|
|
#endif
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
+
|