mbed library sources. Supersedes mbed-src.
Dependents: Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more
targets/TARGET_NUVOTON/TARGET_M451/device/system_M451Series.c@189:f392fc9709a3, 2019-02-20 (annotated)
- Committer:
- AnnaBridge
- Date:
- Wed Feb 20 22:31:08 2019 +0000
- Revision:
- 189:f392fc9709a3
- Parent:
- 149:156823d33999
mbed library release version 165
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
<> | 149:156823d33999 | 1 | /****************************************************************************** |
<> | 149:156823d33999 | 2 | * @file system_M451Series.c |
<> | 149:156823d33999 | 3 | * @version V0.10 |
<> | 149:156823d33999 | 4 | * $Revision: 11 $ |
<> | 149:156823d33999 | 5 | * $Date: 15/09/02 10:02a $ |
<> | 149:156823d33999 | 6 | * @brief CMSIS Cortex-M4 Core Peripheral Access Layer Source File for M451 Series MCU |
<> | 149:156823d33999 | 7 | * |
<> | 149:156823d33999 | 8 | * @note |
<> | 149:156823d33999 | 9 | * Copyright (C) 2013~2015 Nuvoton Technology Corp. All rights reserved. |
<> | 149:156823d33999 | 10 | *****************************************************************************/ |
<> | 149:156823d33999 | 11 | |
<> | 149:156823d33999 | 12 | #include "M451Series.h" |
<> | 149:156823d33999 | 13 | |
<> | 149:156823d33999 | 14 | |
<> | 149:156823d33999 | 15 | /*---------------------------------------------------------------------------- |
<> | 149:156823d33999 | 16 | DEFINES |
<> | 149:156823d33999 | 17 | *----------------------------------------------------------------------------*/ |
<> | 149:156823d33999 | 18 | |
<> | 149:156823d33999 | 19 | |
<> | 149:156823d33999 | 20 | /*---------------------------------------------------------------------------- |
<> | 149:156823d33999 | 21 | Clock Variable definitions |
<> | 149:156823d33999 | 22 | *----------------------------------------------------------------------------*/ |
<> | 149:156823d33999 | 23 | uint32_t SystemCoreClock = __SYSTEM_CLOCK; /*!< System Clock Frequency (Core Clock)*/ |
<> | 149:156823d33999 | 24 | uint32_t CyclesPerUs = (__HSI / 1000000); /* Cycles per micro second */ |
<> | 149:156823d33999 | 25 | uint32_t PllClock = __HSI; /*!< PLL Output Clock Frequency */ |
<> | 149:156823d33999 | 26 | uint32_t gau32ClkSrcTbl[] = {__HXT, __LXT, 0, __LIRC, 0, 0, 0, __HIRC}; |
<> | 149:156823d33999 | 27 | |
<> | 149:156823d33999 | 28 | /*---------------------------------------------------------------------------- |
<> | 149:156823d33999 | 29 | Clock functions |
<> | 149:156823d33999 | 30 | *----------------------------------------------------------------------------*/ |
<> | 149:156823d33999 | 31 | void SystemCoreClockUpdate(void) /* Get Core Clock Frequency */ |
<> | 149:156823d33999 | 32 | { |
<> | 149:156823d33999 | 33 | #if 1 |
<> | 149:156823d33999 | 34 | uint32_t u32Freq, u32ClkSrc; |
<> | 149:156823d33999 | 35 | uint32_t u32HclkDiv; |
<> | 149:156823d33999 | 36 | |
<> | 149:156823d33999 | 37 | /* Update PLL Clock */ |
<> | 149:156823d33999 | 38 | PllClock = CLK_GetPLLClockFreq(); |
<> | 149:156823d33999 | 39 | |
<> | 149:156823d33999 | 40 | u32ClkSrc = CLK->CLKSEL0 & CLK_CLKSEL0_HCLKSEL_Msk; |
<> | 149:156823d33999 | 41 | |
<> | 149:156823d33999 | 42 | if(u32ClkSrc == CLK_CLKSEL0_HCLKSEL_PLL) |
<> | 149:156823d33999 | 43 | { |
<> | 149:156823d33999 | 44 | /* Use PLL clock */ |
<> | 149:156823d33999 | 45 | u32Freq = PllClock; |
<> | 149:156823d33999 | 46 | } |
<> | 149:156823d33999 | 47 | else |
<> | 149:156823d33999 | 48 | { |
<> | 149:156823d33999 | 49 | /* Use the clock sources directly */ |
<> | 149:156823d33999 | 50 | u32Freq = gau32ClkSrcTbl[u32ClkSrc]; |
<> | 149:156823d33999 | 51 | } |
<> | 149:156823d33999 | 52 | |
<> | 149:156823d33999 | 53 | u32HclkDiv = (CLK->CLKDIV0 & CLK_CLKDIV0_HCLKDIV_Msk) + 1; |
<> | 149:156823d33999 | 54 | |
<> | 149:156823d33999 | 55 | /* Update System Core Clock */ |
<> | 149:156823d33999 | 56 | SystemCoreClock = u32Freq / u32HclkDiv; |
<> | 149:156823d33999 | 57 | |
<> | 149:156823d33999 | 58 | |
<> | 149:156823d33999 | 59 | //if(SystemCoreClock == 0) |
<> | 149:156823d33999 | 60 | // __BKPT(0); |
<> | 149:156823d33999 | 61 | |
<> | 149:156823d33999 | 62 | CyclesPerUs = (SystemCoreClock + 500000) / 1000000; |
<> | 149:156823d33999 | 63 | #endif |
<> | 149:156823d33999 | 64 | } |
<> | 149:156823d33999 | 65 | |
<> | 149:156823d33999 | 66 | /** |
<> | 149:156823d33999 | 67 | * Initialize the system |
<> | 149:156823d33999 | 68 | * |
<> | 149:156823d33999 | 69 | * @param None |
<> | 149:156823d33999 | 70 | * @return None |
<> | 149:156823d33999 | 71 | * |
<> | 149:156823d33999 | 72 | * @brief Setup the microcontroller system. |
<> | 149:156823d33999 | 73 | * Initialize the System. |
<> | 149:156823d33999 | 74 | */ |
<> | 149:156823d33999 | 75 | void SystemInit(void) |
<> | 149:156823d33999 | 76 | { |
<> | 149:156823d33999 | 77 | /* ToDo: add code to initialize the system |
<> | 149:156823d33999 | 78 | do not use global variables because this function is called before |
<> | 149:156823d33999 | 79 | reaching pre-main. RW section maybe overwritten afterwards. */ |
<> | 149:156823d33999 | 80 | |
<> | 149:156823d33999 | 81 | SYS_UnlockReg(); |
<> | 149:156823d33999 | 82 | /* One-time POR18 */ |
<> | 149:156823d33999 | 83 | if((SYS->PDID >> 12) == 0x945) |
<> | 149:156823d33999 | 84 | { |
<> | 149:156823d33999 | 85 | M32(GCR_BASE+0x14) |= BIT7; |
<> | 149:156823d33999 | 86 | } |
<> | 149:156823d33999 | 87 | /* Force to use INV type with HXT */ |
<> | 149:156823d33999 | 88 | CLK->PWRCTL &= ~CLK_PWRCTL_HXTSELTYP_Msk; |
<> | 149:156823d33999 | 89 | SYS_LockReg(); |
<> | 149:156823d33999 | 90 | |
<> | 149:156823d33999 | 91 | |
<> | 149:156823d33999 | 92 | #if 0 |
<> | 149:156823d33999 | 93 | // NOTE: C-runtime not initialized yet. Ensure no static memory (global variable) are accessed in this function. |
<> | 149:156823d33999 | 94 | nu_ebi_init(); |
<> | 149:156823d33999 | 95 | #endif |
<> | 149:156823d33999 | 96 | |
<> | 149:156823d33999 | 97 | /* FPU settings ------------------------------------------------------------*/ |
<> | 149:156823d33999 | 98 | #if (__FPU_PRESENT == 1) && (__FPU_USED == 1) |
<> | 149:156823d33999 | 99 | SCB->CPACR |= ((3UL << 10 * 2) | /* set CP10 Full Access */ |
<> | 149:156823d33999 | 100 | (3UL << 11 * 2)); /* set CP11 Full Access */ |
<> | 149:156823d33999 | 101 | #endif |
<> | 149:156823d33999 | 102 | |
<> | 149:156823d33999 | 103 | } |
<> | 149:156823d33999 | 104 | |
<> | 149:156823d33999 | 105 | #if 0 |
<> | 149:156823d33999 | 106 | void nu_ebi_init(void) |
<> | 149:156823d33999 | 107 | { |
<> | 149:156823d33999 | 108 | // TO BE CONTINUED |
<> | 149:156823d33999 | 109 | } |
<> | 149:156823d33999 | 110 | #endif |
<> | 149:156823d33999 | 111 | /*** (C) COPYRIGHT 2013~2015 Nuvoton Technology Corp. ***/ |