mirror of
https://github.com/FreeRTOS/FreeRTOS-Kernel.git
synced 2025-04-20 05:21:59 -04:00
Update XMC4000 tasking project to use latest system files.
This commit is contained in:
parent
7d92a29d2d
commit
77d817ffaa
|
@ -1,7 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<?fileVersion 4.0.0?>
|
||||
|
||||
<cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
|
||||
<?fileVersion 4.0.0?><cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
|
||||
<storageModule moduleId="org.eclipse.cdt.core.settings">
|
||||
<cconfiguration id="com.tasking.config.arm.abs.debug.1826238485">
|
||||
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="com.tasking.config.arm.abs.debug.1826238485" moduleId="org.eclipse.cdt.core.settings" name="Debug">
|
||||
|
@ -15,11 +13,11 @@
|
|||
<configuration artifactExtension="abs" artifactName="RTOSDemo" buildArtefactType="com.tasking.arm.buildArtefactType.elf" buildProperties="org.eclipse.cdt.build.core.buildArtefactType=com.tasking.arm.buildArtefactType.elf" cleanCommand=""${PRODDIR}/bin/rm" -rf" description="" id="com.tasking.config.arm.abs.debug.1826238485" name="Debug" parent="com.tasking.config.arm.abs.debug">
|
||||
<folderInfo id="com.tasking.config.arm.abs.debug.1826238485." name="/" resourcePath="">
|
||||
<toolChain id="com.tasking.arm.abs.debug.30340712" name="TASKING VX-toolset for ARM" superClass="com.tasking.arm.abs.debug">
|
||||
<option id="com.tasking.arm.pluginVersion.2141845622" name="Plugin version" superClass="com.tasking.arm.pluginVersion" value="1.77.0.0" valueType="string"/>
|
||||
<option id="com.tasking.arm.pluginVersion.2141845622" name="Plugin version" superClass="com.tasking.arm.pluginVersion" value="1.109.0.0" valueType="string"/>
|
||||
<option id="com.tasking.arm.prodDir.157728853" name="Product directory:" superClass="com.tasking.arm.prodDir" value="${eclipse_home}/.." valueType="string"/>
|
||||
<option id="com.tasking.arm.cpu.1839436230" name="Processor:" superClass="com.tasking.arm.cpu" value="xmc4500x1024" valueType="string"/>
|
||||
<targetPlatform archList="all" binaryParser="com.tasking.managedbuilder.TASKING_ELF" id="com.tasking.arm.platform.abs.debug.1822567351" name="Debug" osList="" superClass="com.tasking.arm.platform.abs.debug"/>
|
||||
<builder buildPath="${workspace_loc:/RTOSDemo/Debug}" id="com.tasking.arm.builder.abs.debug.1973824774" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="TASKING ARM Makefile generator" parallelBuildOn="true" parallelizationNumber="-1" superClass="com.tasking.arm.builder.abs.debug"/>
|
||||
<builder buildPath="${workspace_loc:/RTOSDemo/Debug}" id="com.tasking.arm.builder.abs.debug.1973824774" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="TASKING ARM Makefile generator" parallelBuildOn="true" parallelizationNumber="unlimited" superClass="com.tasking.arm.builder.abs.debug"/>
|
||||
<tool id="com.tasking.arm.cc.abs.debug.950672563" name="C/C++ Compiler" superClass="com.tasking.arm.cc.abs.debug">
|
||||
<option id="com.tasking.arm.cc.pr36858.1857781873" name="workaround for PR36858" superClass="com.tasking.arm.cc.pr36858" value="true" valueType="string"/>
|
||||
<option id="com.tasking.arm.cc.includePaths.181073230" name="Include paths" superClass="com.tasking.arm.cc.includePaths" valueType="includePath">
|
||||
|
@ -30,6 +28,9 @@
|
|||
</option>
|
||||
<option id="com.tasking.arm.cc.optimize.1219621169" name="Optimization level:" superClass="com.tasking.arm.cc.optimize" value="com.tasking.arm.cc.optimize.0" valueType="enumerated"/>
|
||||
<option id="com.tasking.arm.cc.globalTypeChecking.1886266211" name="Perform global type checking on C code" superClass="com.tasking.arm.cc.globalTypeChecking" value="false" valueType="boolean"/>
|
||||
<option id="com.tasking.arm.cc.definedSymbols.1190877408" superClass="com.tasking.arm.cc.definedSymbols" valueType="definedSymbols">
|
||||
<listOptionValue builtIn="false" value="PART_XMC4500"/>
|
||||
</option>
|
||||
<inputType id="com.tasking.arm.cppInputType.1974521058" name="C++" superClass="com.tasking.arm.cppInputType"/>
|
||||
<inputType id="com.tasking.arm.cpp.cInputType.1635312661" name="C" superClass="com.tasking.arm.cpp.cInputType"/>
|
||||
<inputType id="com.tasking.arm.cc.msInputType.1200945921" name="MS" superClass="com.tasking.arm.cc.msInputType"/>
|
||||
|
@ -55,7 +56,8 @@
|
|||
</storageModule>
|
||||
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
|
||||
<storageModule moduleId="com.tasking.toolInfo">
|
||||
<toolInfo>TASKING program builder v4.2r1 Build 063</toolInfo>
|
||||
<toolInfo>TASKING program builder v4.4r1 Build 077</toolInfo>
|
||||
<toolInfo>TASKING rm v0.0r0 Build 022</toolInfo>
|
||||
</storageModule>
|
||||
</cconfiguration>
|
||||
<cconfiguration id="com.tasking.config.arm.abs.debug.1826238485.654381753">
|
||||
|
@ -70,11 +72,11 @@
|
|||
<configuration artifactExtension="abs" artifactName="RTOSDemo" buildArtefactType="com.tasking.arm.buildArtefactType.elf" buildProperties="org.eclipse.cdt.build.core.buildArtefactType=com.tasking.arm.buildArtefactType.elf" cleanCommand=""${PRODDIR}/bin/rm" -rf" description="" id="com.tasking.config.arm.abs.debug.1826238485.654381753" name="Optimised" parent="com.tasking.config.arm.abs.debug">
|
||||
<folderInfo id="com.tasking.config.arm.abs.debug.1826238485.654381753." name="/" resourcePath="">
|
||||
<toolChain id="com.tasking.arm.abs.debug.88571467" name="TASKING VX-toolset for ARM" superClass="com.tasking.arm.abs.debug">
|
||||
<option id="com.tasking.arm.pluginVersion.2020974908" name="Plugin version" superClass="com.tasking.arm.pluginVersion" value="1.77.0.0" valueType="string"/>
|
||||
<option id="com.tasking.arm.pluginVersion.2020974908" name="Plugin version" superClass="com.tasking.arm.pluginVersion" value="1.109.0.0" valueType="string"/>
|
||||
<option id="com.tasking.arm.prodDir.543770190" name="Product directory:" superClass="com.tasking.arm.prodDir" value="${eclipse_home}/.." valueType="string"/>
|
||||
<option id="com.tasking.arm.cpu.407790444" name="Processor:" superClass="com.tasking.arm.cpu" value="xmc4500x1024" valueType="string"/>
|
||||
<targetPlatform archList="all" binaryParser="com.tasking.managedbuilder.TASKING_ELF" id="com.tasking.arm.platform.abs.debug.1538796444" name="Debug" osList="" superClass="com.tasking.arm.platform.abs.debug"/>
|
||||
<builder buildPath="${workspace_loc:/RTOSDemo/Debug}" id="com.tasking.arm.builder.abs.debug.362325101" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="TASKING ARM Makefile generator" parallelBuildOn="true" parallelizationNumber="-1" superClass="com.tasking.arm.builder.abs.debug"/>
|
||||
<builder buildPath="${workspace_loc:/RTOSDemo/Debug}" id="com.tasking.arm.builder.abs.debug.362325101" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="TASKING ARM Makefile generator" parallelBuildOn="true" parallelizationNumber="unlimited" superClass="com.tasking.arm.builder.abs.debug"/>
|
||||
<tool id="com.tasking.arm.cc.abs.debug.2020315503" name="C/C++ Compiler" superClass="com.tasking.arm.cc.abs.debug">
|
||||
<option id="com.tasking.arm.cc.pr36858.710990228" name="workaround for PR36858" superClass="com.tasking.arm.cc.pr36858" value="true" valueType="string"/>
|
||||
<option id="com.tasking.arm.cc.includePaths.179492897" name="Include paths" superClass="com.tasking.arm.cc.includePaths" valueType="includePath">
|
||||
|
@ -135,4 +137,5 @@
|
|||
<content-type-mapping configuration="" content-type="org.eclipse.cdt.core.cxxSource" language="com.tasking.arm.cpplanguage"/>
|
||||
</project-mappings>
|
||||
</storageModule>
|
||||
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
|
||||
</cproject>
|
||||
|
|
|
@ -42,16 +42,12 @@ IF EXIST FreeRTOS_Source Goto END
|
|||
|
||||
REM Copy the files that define the common demo tasks.
|
||||
copy %COMMON_SOURCE%\dynamic.c Common_Demo_Source
|
||||
copy %COMMON_SOURCE%\BlockQ.c Common_Demo_Source
|
||||
copy %COMMON_SOURCE%\death.c Common_Demo_Source
|
||||
copy %COMMON_SOURCE%\blocktim.c Common_Demo_Source
|
||||
copy %COMMON_SOURCE%\semtest.c Common_Demo_Source
|
||||
copy %COMMON_SOURCE%\PollQ.c Common_Demo_Source
|
||||
copy %COMMON_SOURCE%\GenQTest.c Common_Demo_Source
|
||||
copy %COMMON_SOURCE%\recmutex.c Common_Demo_Source
|
||||
copy %COMMON_SOURCE%\sp_flop.c Common_Demo_Source
|
||||
copy %COMMON_SOURCE%\countsem.c Common_Demo_Source
|
||||
copy %COMMON_SOURCE%\integer.c Common_Demo_Source
|
||||
copy %COMMON_SOURCE%\QueueSet.c Common_Demo_Source
|
||||
copy %COMMON_SOURCE%\QueueOverwrite.c Common_Demo_Source
|
||||
copy %COMMON_SOURCE%\GenQTest.c Common_Demo_Source
|
||||
|
||||
REM Copy the common demo file headers.
|
||||
copy %COMMON_INCLUDE%\*.h Common_Demo_Source\include
|
||||
|
|
|
@ -85,19 +85,19 @@
|
|||
* executed from within the IDE! Once it has been executed, re-open or refresh
|
||||
* the Eclipse project and remove the #error line below.
|
||||
*/
|
||||
#error Ensure CreateProjectDirectoryStructure.bat has been executed before building. See comment immediately above.
|
||||
//#error Ensure CreateProjectDirectoryStructure.bat has been executed before building. See comment immediately above.
|
||||
|
||||
#include <stdint.h>
|
||||
extern uint32_t SystemCoreClock;
|
||||
|
||||
#define configUSE_PREEMPTION 1
|
||||
#define configUSE_IDLE_HOOK 0
|
||||
#define configUSE_TICK_HOOK 0
|
||||
#define configUSE_TICK_HOOK 1
|
||||
#define configCPU_CLOCK_HZ ( SystemCoreClock )
|
||||
#define configTICK_RATE_HZ ( ( portTickType ) 1000 )
|
||||
#define configMAX_PRIORITIES ( ( unsigned portBASE_TYPE ) 5 )
|
||||
#define configMINIMAL_STACK_SIZE ( ( unsigned short ) 130 )
|
||||
#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 40960 ) )
|
||||
#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 22800 ) )
|
||||
#define configMAX_TASK_NAME_LEN ( 10 )
|
||||
#define configUSE_TRACE_FACILITY 1
|
||||
#define configUSE_16_BIT_TICKS 0
|
||||
|
@ -110,6 +110,7 @@ extern uint32_t SystemCoreClock;
|
|||
#define configUSE_APPLICATION_TASK_TAG 0
|
||||
#define configUSE_COUNTING_SEMAPHORES 1
|
||||
#define configGENERATE_RUN_TIME_STATS 0
|
||||
#define configUSE_QUEUE_SETS 1
|
||||
|
||||
/* Co-routine definitions. */
|
||||
#define configUSE_CO_ROUTINES 0
|
||||
|
@ -160,5 +161,37 @@ See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */
|
|||
header file. */
|
||||
#define configASSERT( x ) if( ( x ) == 0 ) { taskDISABLE_INTERRUPTS(); for( ;; ) __asm volatile( "NOP" ); }
|
||||
|
||||
/* Demo application specific settings. */
|
||||
#if defined( PART_XMC4500 )
|
||||
/* Hardware includes. */
|
||||
#include "XMC4500.h"
|
||||
#include "System_XMC4500.h"
|
||||
|
||||
/* Configure pin P3.9 for the LED. */
|
||||
#define configCONFIGURE_LED() ( PORT3->IOCR8 = 0x00008000 )
|
||||
/* To toggle the single LED */
|
||||
#define configTOGGLE_LED() ( PORT3->OMR = 0x02000200 )
|
||||
#elif defined( PART_XMC4400 )
|
||||
/* Hardware includes. */
|
||||
#include "XMC4400.h"
|
||||
#include "System_XMC4200.h"
|
||||
|
||||
/* Configure pin P5.2 for the LED. */
|
||||
#define configCONFIGURE_LED() ( PORT5->IOCR0 = 0x00800000 )
|
||||
/* To toggle the single LED */
|
||||
#define configTOGGLE_LED() ( PORT5->OMR = 0x00040004 )
|
||||
#elif defined( PART_XMC4200 )
|
||||
/* Hardware includes. */
|
||||
#include "XMC4200.h"
|
||||
#include "System_XMC4200.h"
|
||||
|
||||
/* Configure pin P2.1 for the LED. */
|
||||
#define configCONFIGURE_LED() PORT2->IOCR0 = 0x00008000; PORT2->HWSEL &= ~0x0000000cUL
|
||||
/* To toggle the single LED */
|
||||
#define configTOGGLE_LED() ( PORT2->OMR = 0x00020002 )
|
||||
#else
|
||||
#error Part number not specified in project options
|
||||
#endif
|
||||
|
||||
#endif /* FREERTOS_CONFIG_H */
|
||||
|
||||
|
|
|
@ -0,0 +1,118 @@
|
|||
/*
|
||||
** @(#)cstart.c 1.9 $E%
|
||||
**
|
||||
** Copyright 1997-2013 Altium BV *
|
||||
**
|
||||
** DESCRIPTION:
|
||||
**
|
||||
** The system startup code initializes the processor's registers
|
||||
** and the application C variables.
|
||||
**
|
||||
*/
|
||||
|
||||
#pragma nomisrac
|
||||
#pragma profiling off /* prevent profiling information on cstart */
|
||||
#pragma optimize abcefgIJKlopRsUy /* preset optimization level */
|
||||
#pragma tradeoff 4 /* preset tradeoff level */
|
||||
#pragma runtime BCMSZ /* disable runtime error checking for cstart */
|
||||
#pragma warning 750 /* do not warn about unsaved registers */
|
||||
#pragma section .text=cstart /* use: .text.cstart as the section name */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <dbg.h>
|
||||
|
||||
#define VTOR (*(volatile unsigned int *)0xE000ED08)
|
||||
#define PREF_FCON (*(volatile unsigned int *)0x58002014)
|
||||
#define SCU_GCU_PEEN (*(volatile unsigned int *)0x5000413C)
|
||||
#define SCU_GCU_PEFLAG (*(volatile unsigned int *)0x50004150)
|
||||
|
||||
/* In the absence of DAVE code engine, CMSIS SystemInit() must perform clock
|
||||
tree setup.
|
||||
|
||||
This decision routine defined here will always return TRUE.
|
||||
|
||||
When overridden by a definition defined in DAVE code engine, this routine
|
||||
returns FALSE indicating that the code engine has performed the clock setup
|
||||
*/
|
||||
#pragma weak AllowPLLInitByStartup
|
||||
uint32_t AllowPLLInitByStartup( void )
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
extern unsigned char _lc_ub_stack[];
|
||||
extern unsigned char _lc_vtor_value[];
|
||||
|
||||
#pragma weak exit
|
||||
#pragma extern _Exit
|
||||
#pragma extern main
|
||||
extern int main( int argc, char *argv[] );
|
||||
extern void SystemInit( void );
|
||||
extern void __init( void );
|
||||
#if __PROF_ENABLE__
|
||||
extern void __prof_init( void );
|
||||
#endif
|
||||
|
||||
#ifdef __POSIX__
|
||||
extern void * _posix_boot_stack_top;
|
||||
extern int posix_main( void );
|
||||
#endif
|
||||
|
||||
#ifdef __USE_ARGC_ARGV
|
||||
#ifndef __ARGCV_BUFSIZE
|
||||
#define __ARGCV_BUFSIZE 256
|
||||
#endif
|
||||
static char argcv[__ARGCV_BUFSIZE];
|
||||
#endif
|
||||
|
||||
void __interrupt() __frame() Reset_Handler( void )
|
||||
{
|
||||
/* Set flash wait states to 3 */
|
||||
PREF_FCON = (PREF_FCON & 0xFFFFFFF0) | 0x00000003;
|
||||
SCU_GCU_PEFLAG =0xFFFFFFFF; /* Clear existing parity errors if any */
|
||||
SCU_GCU_PEEN = 0; /* Disable parity */
|
||||
|
||||
/*
|
||||
* Anticipate possible ROM/RAM remapping
|
||||
* by loading the 'real' program address.
|
||||
*/
|
||||
__remap_pc();
|
||||
/*
|
||||
* Initialize stack pointer.
|
||||
*/
|
||||
__setsp( _lc_ub_stack );
|
||||
/*
|
||||
* Call a user function which initializes hardware,
|
||||
* such as ROM/RAM re-mapping or MMU configuration.
|
||||
*/
|
||||
SystemInit();
|
||||
/*
|
||||
* Copy initialized sections from ROM to RAM
|
||||
* and clear uninitialized data sections in RAM.
|
||||
*/
|
||||
__init();
|
||||
__asm( "_cptable_handled:" ); /* symbol may be used by debugger */
|
||||
|
||||
/*
|
||||
* Load VTOR register with the actual vector table
|
||||
* start address
|
||||
*/
|
||||
VTOR = (unsigned int)_lc_vtor_value;
|
||||
|
||||
#ifdef __POSIX__
|
||||
__setsp( _posix_boot_stack_top );
|
||||
#endif
|
||||
#if __PROF_ENABLE__
|
||||
__prof_init();
|
||||
#endif
|
||||
#ifdef __POSIX__
|
||||
exit( posix_main() );
|
||||
#elif defined __USE_ARGC_ARGV
|
||||
exit( main( _argcv( argcv, __ARGCV_BUFSIZE ), (char **)argcv ) );
|
||||
#else
|
||||
exit( main( 0, NULL ) );
|
||||
#endif
|
||||
return;
|
||||
}
|
|
@ -0,0 +1,708 @@
|
|||
/**************************************************************************//**
|
||||
* @file system_XMC4200.c
|
||||
* @brief CMSIS Cortex-M4 Device Peripheral Access Layer Header File
|
||||
* for the Infineon XMC4000 Device Series
|
||||
* @version V3.0.1 Alpha
|
||||
* @date 26. September 2012
|
||||
*
|
||||
* @note
|
||||
* Copyright (C) 2011 ARM Limited. All rights reserved.
|
||||
*
|
||||
* @par
|
||||
* ARM Limited (ARM) is supplying this software for use with Cortex-M
|
||||
* processor based microcontrollers. This file can be freely distributed
|
||||
* within development tools that are supporting such ARM based processors.
|
||||
*
|
||||
* @par
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
|
||||
* OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
|
||||
* ARM SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR
|
||||
* CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#include <system_XMC4200.h>
|
||||
#include <XMC4200.h>
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
Clock Variable definitions
|
||||
*----------------------------------------------------------------------------*/
|
||||
/*!< System Clock Frequency (Core Clock)*/
|
||||
uint32_t SystemCoreClock;
|
||||
|
||||
/* clock definitions, do not modify! */
|
||||
#define SCU_CLOCK_CRYSTAL 1
|
||||
#define SCU_CLOCK_BACK_UP_FACTORY 2
|
||||
#define SCU_CLOCK_BACK_UP_AUTOMATIC 3
|
||||
|
||||
|
||||
#define HIB_CLOCK_FOSI 1
|
||||
#define HIB_CLOCK_OSCULP 2
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
//-------- <<< Use Configuration Wizard in Context Menu >>> ------------------
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/*--------------------- Watchdog Configuration -------------------------------
|
||||
//
|
||||
// <e> Watchdog Configuration
|
||||
// <o1.0> Disable Watchdog
|
||||
//
|
||||
// </e>
|
||||
*/
|
||||
#define WDT_SETUP 1
|
||||
#define WDTENB_nVal 0x00000001
|
||||
|
||||
/*--------------------- CLOCK Configuration -------------------------------
|
||||
//
|
||||
// <e> Main Clock Configuration
|
||||
// <o1.0..1> CPU clock divider
|
||||
// <0=> fCPU = fSYS
|
||||
// <1=> fCPU = fSYS / 2
|
||||
// <o2.0..1> Peripheral Bus clock divider
|
||||
// <0=> fPB = fCPU
|
||||
// <1=> fPB = fCPU / 2
|
||||
// <o3.0..1> CCU Bus clock divider
|
||||
// <0=> fCCU = fCPU
|
||||
// <1=> fCCU = fCPU / 2
|
||||
//
|
||||
// </e>
|
||||
//
|
||||
*/
|
||||
|
||||
#define SCU_CLOCK_SETUP 1
|
||||
#define SCU_CPUCLKCR_DIV 0x00000000
|
||||
#define SCU_PBCLKCR_DIV 0x00000000
|
||||
#define SCU_CCUCLKCR_DIV 0x00000000
|
||||
/* not avalible in config wizzard*/
|
||||
/*
|
||||
* mandatory clock parameters **************************************************
|
||||
*
|
||||
* source for clock generation
|
||||
* range: SCU_CLOCK_CRYSTAL (crystal or external clock at crystal input)
|
||||
*
|
||||
**************************************************************************************/
|
||||
// Selection of imput lock for PLL
|
||||
/*************************************************************************************/
|
||||
#define SCU_PLL_CLOCK_INPUT SCU_CLOCK_CRYSTAL
|
||||
//#define SCU_PLL_CLOCK_INPUT SCU_CLOCK_BACK_UP_FACTORY
|
||||
//#define SCU_PLL_CLOCK_INPUT SCU_CLOCK_BACK_UP_AUTOMATIC
|
||||
|
||||
/*************************************************************************************/
|
||||
// Standby clock selection for Backup clock source trimming
|
||||
/*************************************************************************************/
|
||||
#define SCU_STANDBY_CLOCK HIB_CLOCK_OSCULP
|
||||
//#define SCU_STANDBY_CLOCK HIB_CLOCK_FOSI
|
||||
|
||||
/*************************************************************************************/
|
||||
// Global clock parameters
|
||||
/*************************************************************************************/
|
||||
#define CLOCK_FSYS 80000000
|
||||
#define CLOCK_CRYSTAL_FREQUENCY 12000000
|
||||
#define CLOCK_BACK_UP 24000000
|
||||
|
||||
/*************************************************************************************/
|
||||
/* OSC_HP setup parameters */
|
||||
/*************************************************************************************/
|
||||
#define SCU_OSC_HP_MODE 0xF0
|
||||
#define SCU_OSCHPWDGDIV 2
|
||||
|
||||
/*************************************************************************************/
|
||||
/* MAIN PLL setup parameters */
|
||||
/*************************************************************************************/
|
||||
//Divider settings for external crystal @ 12 MHz
|
||||
/*************************************************************************************/
|
||||
#define SCU_PLL_K1DIV 1
|
||||
#define SCU_PLL_K1DIV 1
|
||||
#define SCU_PLL_K2DIV 5
|
||||
#define SCU_PLL_PDIV 1
|
||||
#define SCU_PLL_NDIV 79
|
||||
|
||||
/*************************************************************************************/
|
||||
//Divider settings for use of backup clock source trimmed
|
||||
/*************************************************************************************/
|
||||
//#define SCU_PLL_K1DIV 1
|
||||
//#define SCU_PLL_K2DIV 5
|
||||
//#define SCU_PLL_PDIV 3
|
||||
//#define SCU_PLL_NDIV 79
|
||||
/*************************************************************************************/
|
||||
|
||||
|
||||
/*--------------------- USB CLOCK Configuration ---------------------------
|
||||
//
|
||||
// <e> USB Clock Configuration
|
||||
//
|
||||
// </e>
|
||||
//
|
||||
*/
|
||||
|
||||
#define SCU_USB_CLOCK_SETUP 0
|
||||
/* not avalible in config wizzard*/
|
||||
#define SCU_USBPLL_PDIV 0
|
||||
#define SCU_USBPLL_NDIV 31
|
||||
#define SCU_USBDIV 3
|
||||
|
||||
/*--------------------- Flash Wait State Configuration -------------------------------
|
||||
//
|
||||
// <e> Flash Wait State Configuration
|
||||
// <o1.0..3> Flash Wait State
|
||||
// <0=> 3 WS
|
||||
// <1=> 4 WS
|
||||
// <2=> 5 WS
|
||||
// <3=> 6 WS
|
||||
// </e>
|
||||
//
|
||||
*/
|
||||
|
||||
#define PMU_FLASH 1
|
||||
#define PMU_FLASH_WS 0x00000000
|
||||
|
||||
|
||||
/*--------------------- CLOCKOUT Configuration -------------------------------
|
||||
//
|
||||
// <e> Clock OUT Configuration
|
||||
// <o1.0..1> Clockout Source Selection
|
||||
// <0=> System Clock
|
||||
// <2=> Divided value of USB PLL output
|
||||
// <3=> Divided value of PLL Clock
|
||||
// <o2.0..4> Clockout divider <1-10><#-1>
|
||||
// <o3.0..1> Clockout Pin Selection
|
||||
// <0=> P1.15
|
||||
// <1=> P0.8
|
||||
//
|
||||
//
|
||||
// </e>
|
||||
//
|
||||
*/
|
||||
|
||||
#define SCU_CLOCKOUT_SETUP 0
|
||||
#define SCU_CLOCKOUT_SOURCE 0x00000000
|
||||
#define SCU_CLOCKOUT_DIV 0x00000009
|
||||
#define SCU_CLOCKOUT_PIN 0x00000001
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
Clock Variable definitions
|
||||
*----------------------------------------------------------------------------*/
|
||||
/*!< System Clock Frequency (Core Clock)*/
|
||||
#if SCU_CLOCK_SETUP
|
||||
uint32_t SystemCoreClock = CLOCK_FSYS;
|
||||
#else
|
||||
uint32_t SystemCoreClock = CLOCK_BACK_UP;
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
static functions declarations
|
||||
*----------------------------------------------------------------------------*/
|
||||
#if (SCU_CLOCK_SETUP == 1)
|
||||
static int SystemClockSetup(void);
|
||||
#endif
|
||||
|
||||
#if (SCU_USB_CLOCK_SETUP == 1)
|
||||
static int USBClockSetup(void);
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* @brief Setup the microcontroller system.
|
||||
* Initialize the PLL and update the
|
||||
* SystemCoreClock variable.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void SystemInit(void)
|
||||
{
|
||||
int temp;
|
||||
|
||||
#if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
|
||||
SCB->CPACR |= ((3UL << 10*2) | /* set CP10 Full Access */
|
||||
(3UL << 11*2) ); /* set CP11 Full Access */
|
||||
#endif
|
||||
|
||||
/* Enable unaligned memory access - SCB_CCR.UNALIGN_TRP = 0 */
|
||||
SCB->CCR &= ~(SCB_CCR_UNALIGN_TRP_Msk);
|
||||
|
||||
/* Setup the WDT */
|
||||
#if WDT_SETUP
|
||||
|
||||
WDT->CTR &= ~WDTENB_nVal;
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/* Setup the Flash Wait State */
|
||||
#if PMU_FLASH
|
||||
temp = FLASH0->FCON;
|
||||
temp &= ~FLASH_FCON_WSPFLASH_Msk;
|
||||
temp |= PMU_FLASH_WS+3;
|
||||
FLASH0->FCON = temp;
|
||||
#endif
|
||||
|
||||
|
||||
/* Setup the clockout */
|
||||
#if SCU_CLOCKOUT_SETUP
|
||||
|
||||
SCU_CLK->EXTCLKCR |= SCU_CLOCKOUT_SOURCE;
|
||||
/*set PLL div for clkout */
|
||||
SCU_CLK->EXTCLKCR |= SCU_CLOCKOUT_DIV<<16;
|
||||
|
||||
if (SCU_CLOCKOUT_PIN) {
|
||||
PORT0->IOCR8 = 0x00000088; /*P0.8 --> ALT1 select + HWSEL */
|
||||
PORT0->HWSEL &= (~PORT0_HWSEL_HW8_Msk);
|
||||
PORT0->PDR1 &= (~PORT0_PDR1_PD8_Msk); /*set to strong driver */
|
||||
}
|
||||
else {
|
||||
PORT1->IOCR12 = 0x88000000; /*P1.15--> ALT1 select */
|
||||
PORT1->PDR1 &= (~PORT1_PDR1_PD15_Msk); /*set to strong driver */
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/* Setup the System clock */
|
||||
#if SCU_CLOCK_SETUP
|
||||
SystemClockSetup();
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
Clock Variable definitions
|
||||
*----------------------------------------------------------------------------*/
|
||||
SystemCoreClockUpdate();/*!< System Clock Frequency (Core Clock)*/
|
||||
|
||||
|
||||
/* Setup the USB PL */
|
||||
#if SCU_USB_CLOCK_SETUP
|
||||
USBClockSetup();
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Update SystemCoreClock according to Clock Register Values
|
||||
* @note -
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void SystemCoreClockUpdate(void)
|
||||
{
|
||||
unsigned int PDIV;
|
||||
unsigned int NDIV;
|
||||
unsigned int K2DIV;
|
||||
unsigned int long VCO;
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
Clock Variable definitions
|
||||
*----------------------------------------------------------------------------*/
|
||||
if (SCU_CLK->SYSCLKCR == 0x00010000)
|
||||
{
|
||||
if (SCU_PLL->PLLSTAT & SCU_PLL_PLLSTAT_VCOLOCK_Msk){
|
||||
/* check if PLL is locked */
|
||||
/* read back divider settings */
|
||||
PDIV = ((SCU_PLL->PLLCON1 & SCU_PLL_PLLCON1_PDIV_Msk)>>24)+1;
|
||||
NDIV = ((SCU_PLL->PLLCON1 & SCU_PLL_PLLCON1_NDIV_Msk)>>8)+1;
|
||||
K2DIV = ((SCU_PLL->PLLCON1 & SCU_PLL_PLLCON1_K2DIV_Msk)>>16)+1;
|
||||
|
||||
if(SCU_PLL->PLLCON2 & SCU_PLL_PLLCON2_PINSEL_Msk){
|
||||
/* the selected clock is the Backup clock fofi */
|
||||
VCO = (CLOCK_BACK_UP/PDIV)*NDIV;
|
||||
SystemCoreClock = VCO/K2DIV;
|
||||
/* in case the sysclock div is used */
|
||||
SystemCoreClock = SystemCoreClock/((SCU_CLK->SYSCLKCR & SCU_CLK_SYSCLKCR_SYSDIV_Msk)+1);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
/* the selected clock is the PLL external oscillator */
|
||||
VCO = (CLOCK_CRYSTAL_FREQUENCY/PDIV)*NDIV;
|
||||
SystemCoreClock = VCO/K2DIV;
|
||||
/* in case the sysclock div is used */
|
||||
SystemCoreClock = SystemCoreClock/((SCU_CLK->SYSCLKCR & SCU_CLK_SYSCLKCR_SYSDIV_Msk)+1);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SystemCoreClock = CLOCK_BACK_UP;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief -
|
||||
* @note -
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
#if (SCU_CLOCK_SETUP == 1)
|
||||
static int SystemClockSetup(void)
|
||||
{
|
||||
int temp;
|
||||
unsigned int long VCO;
|
||||
int stepping_K2DIV;
|
||||
|
||||
/* this weak function enables DAVE3 clock App usage */
|
||||
if(AllowPLLInitByStartup()){
|
||||
|
||||
/* check if PLL is switched on */
|
||||
if ((SCU_PLL->PLLCON0 &(SCU_PLL_PLLCON0_VCOPWD_Msk | SCU_PLL_PLLCON0_PLLPWD_Msk)) != 0){
|
||||
/* enable PLL first */
|
||||
SCU_PLL->PLLCON0 &= ~(SCU_PLL_PLLCON0_VCOPWD_Msk | SCU_PLL_PLLCON0_PLLPWD_Msk);
|
||||
|
||||
}
|
||||
|
||||
/* Enable OSC_HP if not already on*/
|
||||
if (SCU_PLL_CLOCK_INPUT == SCU_CLOCK_CRYSTAL)
|
||||
{
|
||||
/********************************************************************************************************************/
|
||||
/* Use external crystal for PLL clock input */
|
||||
/********************************************************************************************************************/
|
||||
|
||||
if (SCU_OSC->OSCHPCTRL & SCU_OSC_OSCHPCTRL_MODE_Msk){
|
||||
SCU_OSC->OSCHPCTRL &= ~(SCU_OSC_HP_MODE); /*enable the OSC_HP*/
|
||||
/* setup OSC WDG devider */
|
||||
SCU_OSC->OSCHPCTRL |= (SCU_OSCHPWDGDIV<<16);
|
||||
/* select external OSC as PLL input */
|
||||
SCU_PLL->PLLCON2 &= ~SCU_PLL_PLLCON2_PINSEL_Msk;
|
||||
/* restart OSC Watchdog */
|
||||
SCU_PLL->PLLCON0 &= ~SCU_PLL_PLLCON0_OSCRES_Msk;
|
||||
|
||||
/* Timeout for wait loop ~150ms */
|
||||
/********************************/
|
||||
SysTick->LOAD = ((5000000+100) & SysTick_LOAD_RELOAD_Msk) - 1;/* set reload register */
|
||||
SysTick->VAL = 0; /* Load the SysTick Counter Value */
|
||||
SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk |
|
||||
SysTick_CTRL_ENABLE_Msk; /* Enable SysTick IRQ and SysTick Timer */
|
||||
do
|
||||
{
|
||||
;/* wait for ~150ms */
|
||||
}while((((SCU_PLL->PLLSTAT) & (SCU_PLL_PLLSTAT_PLLHV_Msk | SCU_PLL_PLLSTAT_PLLLV_Msk |SCU_PLL_PLLSTAT_PLLSP_Msk)) != 0x380)&&(SysTick->VAL >= 500));
|
||||
|
||||
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk; /* Stop SysTick Timer */
|
||||
if (((SCU_PLL->PLLSTAT) & (SCU_PLL_PLLSTAT_PLLHV_Msk | SCU_PLL_PLLSTAT_PLLLV_Msk |SCU_PLL_PLLSTAT_PLLSP_Msk)) != 0x380)
|
||||
return(0);/* Return Error */
|
||||
|
||||
}
|
||||
}
|
||||
else if (SCU_PLL_CLOCK_INPUT == SCU_CLOCK_BACK_UP_FACTORY)
|
||||
{
|
||||
/********************************************************************************************************************/
|
||||
/* Use factory trimming Back-up clock for PLL clock input */
|
||||
/********************************************************************************************************************/
|
||||
/* PLL Back up clock selected */
|
||||
SCU_PLL->PLLCON2 |= SCU_PLL_PLLCON2_PINSEL_Msk;
|
||||
|
||||
}
|
||||
else if (SCU_PLL_CLOCK_INPUT == SCU_CLOCK_BACK_UP_AUTOMATIC)
|
||||
{
|
||||
/********************************************************************************************************************/
|
||||
/* Use automatic trimming Back-up clock for PLL clock input */
|
||||
/********************************************************************************************************************/
|
||||
/* check for HIB Domain enabled */
|
||||
if((SCU_POWER->PWRSTAT & SCU_POWER_PWRSTAT_HIBEN_Msk) == 0)
|
||||
SCU_POWER->PWRSET |= SCU_POWER_PWRSET_HIB_Msk; /*enable Hibernate domain*/
|
||||
|
||||
/* check for HIB Domain is not in reset state */
|
||||
if ((SCU_RESET->RSTSTAT & SCU_RESET_RSTSTAT_HIBRS_Msk)== 1)
|
||||
SCU_RESET->RSTCLR |= SCU_RESET_RSTCLR_HIBRS_Msk; /*de-assert hibernate reset*/
|
||||
|
||||
/* PLL Back up clock selected */
|
||||
SCU_PLL->PLLCON2 |= SCU_PLL_PLLCON2_PINSEL_Msk;
|
||||
|
||||
if (SCU_STANDBY_CLOCK == HIB_CLOCK_FOSI)
|
||||
{
|
||||
/****************************************************************************************************************/
|
||||
/* Use fOSI as source of the standby clock */
|
||||
/****************************************************************************************************************/
|
||||
SCU_HIBERNATE->HDCR &= ~SCU_HIBERNATE_HDCR_STDBYSEL_Msk;
|
||||
|
||||
SCU_PLL->PLLCON0 &= ~SCU_PLL_PLLCON0_FOTR_Msk;
|
||||
for(temp=0;temp<=0xFFFF;temp++);
|
||||
|
||||
SCU_PLL->PLLCON0 |= SCU_PLL_PLLCON0_AOTREN_Msk;
|
||||
}
|
||||
else if (SCU_STANDBY_CLOCK == HIB_CLOCK_OSCULP)
|
||||
{
|
||||
/****************************************************************************************************************/
|
||||
/* Use fULP as source of the standby clock */
|
||||
/****************************************************************************************************************/
|
||||
/*check OSCUL if running correct*/
|
||||
if ((SCU_HIBERNATE->OSCULCTRL & SCU_HIBERNATE_OSCULCTRL_MODE_Msk)!= 0)
|
||||
{
|
||||
while (SCU_GENERAL->MIRRSTS & SCU_GENERAL_MIRRSTS_OSCULCTRL_Msk);
|
||||
|
||||
SCU_HIBERNATE->OSCULCTRL &= ~SCU_HIBERNATE_OSCULCTRL_MODE_Msk; /*enable OSCUL*/
|
||||
/*now ceck if the clock is OK using OSCULP Oscillator Watchdog (ULPWDG)*/
|
||||
/* select OSCUL clock for RTC*/
|
||||
SCU_HIBERNATE->HDCR |= SCU_HIBERNATE_HDCR_RCS_Msk;
|
||||
while (SCU_GENERAL->MIRRSTS & SCU_GENERAL_MIRRSTS_HDCR_Msk);
|
||||
/*enable OSCULP WDG Alarm Enable*/
|
||||
SCU_HIBERNATE->HDCR |= SCU_HIBERNATE_HDCR_ULPWDGEN_Msk;
|
||||
while (SCU_GENERAL->MIRRSTS & SCU_GENERAL_MIRRSTS_HDCR_Msk);
|
||||
/*wait now for clock is stable */
|
||||
do
|
||||
{
|
||||
SCU_HIBERNATE->HDCLR |= SCU_HIBERNATE_HDCLR_ULPWDG_Msk;
|
||||
while (SCU_GENERAL->MIRRSTS & SCU_GENERAL_MIRRSTS_HDCLR_Msk);
|
||||
for(temp=0;temp<=0xFFFF;temp++);
|
||||
}
|
||||
while ((SCU_HIBERNATE->HDSTAT & SCU_HIBERNATE_HDSTAT_ULPWDG_Msk)==SCU_HIBERNATE_HDSTAT_ULPWDG_Msk);
|
||||
|
||||
SCU_HIBERNATE->HDCLR |= SCU_HIBERNATE_HDCLR_ULPWDG_Msk;
|
||||
while (SCU_GENERAL->MIRRSTS & SCU_GENERAL_MIRRSTS_HDCLR_Msk);
|
||||
}
|
||||
// now OSCULP is running and can be used
|
||||
SCU_HIBERNATE->HDCR |= SCU_HIBERNATE_HDCR_STDBYSEL_Msk;
|
||||
while (SCU_GENERAL->MIRRSTS & SCU_GENERAL_MIRRSTS_HDCR_Msk);
|
||||
|
||||
SCU_PLL->PLLCON0 &= ~SCU_PLL_PLLCON0_FOTR_Msk;
|
||||
/*TRIAL for delay loop*/
|
||||
for(temp=0;temp<=0xFFFF;temp++);
|
||||
|
||||
SCU_PLL->PLLCON0 |= SCU_PLL_PLLCON0_AOTREN_Msk;
|
||||
/*TRIAL for delay loop*/
|
||||
for(temp=0;temp<=0xFFFF;temp++);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/********************************************************************************************************************/
|
||||
/* Setup and look the main PLL */
|
||||
/********************************************************************************************************************/
|
||||
|
||||
if (!(SCU_PLL->PLLSTAT & SCU_PLL_PLLSTAT_VCOLOCK_Msk)){
|
||||
/* Systen is still running from internal clock */
|
||||
/* select FOFI as system clock */
|
||||
if((SCU_CLK->SYSCLKCR & SCU_CLK_SYSCLKCR_SYSSEL_Msk) != 0x0)SCU_CLK->SYSCLKCR &= ~SCU_CLK_SYSCLKCR_SYSSEL_Msk; /*Select FOFI*/
|
||||
|
||||
|
||||
/*calulation for stepping*/
|
||||
if (SCU_PLL_CLOCK_INPUT == SCU_CLOCK_CRYSTAL)VCO = (CLOCK_CRYSTAL_FREQUENCY/(SCU_PLL_PDIV+1))*(SCU_PLL_NDIV+1);
|
||||
if ((SCU_PLL_CLOCK_INPUT == SCU_CLOCK_BACK_UP_AUTOMATIC) ||(SCU_PLL_CLOCK_INPUT == SCU_CLOCK_BACK_UP_FACTORY))
|
||||
VCO = (CLOCK_BACK_UP/(SCU_PLL_PDIV+1))*(SCU_PLL_NDIV+1);
|
||||
|
||||
stepping_K2DIV = (VCO/24000000)-1;
|
||||
/* Go to bypass the Main PLL */
|
||||
SCU_PLL->PLLCON0 |= SCU_PLL_PLLCON0_VCOBYP_Msk;
|
||||
/* disconnect OSC_HP to PLL */
|
||||
SCU_PLL->PLLCON0 |= SCU_PLL_PLLCON0_FINDIS_Msk;
|
||||
/* Setup devider settings for main PLL */
|
||||
SCU_PLL->PLLCON1 = ((SCU_PLL_K1DIV) | (SCU_PLL_NDIV<<8) | (stepping_K2DIV<<16) | (SCU_PLL_PDIV<<24));
|
||||
/* we may have to set OSCDISCDIS */
|
||||
SCU_PLL->PLLCON0 |= SCU_PLL_PLLCON0_OSCDISCDIS_Msk;
|
||||
/* connect OSC_HP to PLL */
|
||||
SCU_PLL->PLLCON0 &= ~SCU_PLL_PLLCON0_FINDIS_Msk;
|
||||
/* restart PLL Lock detection */
|
||||
SCU_PLL->PLLCON0 |= SCU_PLL_PLLCON0_RESLD_Msk;
|
||||
/* wait for PLL Lock */
|
||||
/* setup time out loop */
|
||||
/* Timeout for wait loo ~150ms */
|
||||
/********************************/
|
||||
SysTick->LOAD = ((5000000+100) & SysTick_LOAD_RELOAD_Msk) - 1;/* set reload register */
|
||||
SysTick->VAL = 0; /* Load the SysTick Counter Value */
|
||||
SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk |
|
||||
SysTick_CTRL_ENABLE_Msk; /* Enable SysTick IRQ and SysTick Timer */
|
||||
|
||||
while ((!(SCU_PLL->PLLSTAT & SCU_PLL_PLLSTAT_VCOLOCK_Msk))&&(SysTick->VAL >= 500));
|
||||
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk; /* Stop SysTick Timer */
|
||||
|
||||
if ((SCU_PLL->PLLSTAT & SCU_PLL_PLLSTAT_VCOLOCK_Msk)==SCU_PLL_PLLSTAT_VCOLOCK_Msk)
|
||||
{
|
||||
/* Go back to the Main PLL */
|
||||
SCU_PLL->PLLCON0 &= ~SCU_PLL_PLLCON0_VCOBYP_Msk;
|
||||
}
|
||||
else return(0);
|
||||
|
||||
|
||||
/*********************************************************
|
||||
here we need to setup the system clock divider
|
||||
*********************************************************/
|
||||
|
||||
SCU_CLK->CPUCLKCR = SCU_CPUCLKCR_DIV;
|
||||
SCU_CLK->PBCLKCR = SCU_PBCLKCR_DIV;
|
||||
SCU_CLK->CCUCLKCR = SCU_CCUCLKCR_DIV;
|
||||
|
||||
|
||||
/* Switch system clock to PLL */
|
||||
SCU_CLK->SYSCLKCR |= 0x00010000;
|
||||
|
||||
/* we may have to reset OSCDISCDIS */
|
||||
SCU_PLL->PLLCON0 &= ~SCU_PLL_PLLCON0_OSCDISCDIS_Msk;
|
||||
|
||||
|
||||
/*********************************************************/
|
||||
/* Delay for next K2 step ~50µs */
|
||||
/*********************************************************/
|
||||
SysTick->LOAD = ((1250+100) & SysTick_LOAD_RELOAD_Msk) - 1;/* set reload register */
|
||||
SysTick->VAL = 0; /* Load the SysTick Counter Value */
|
||||
SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk |
|
||||
SysTick_CTRL_ENABLE_Msk; /* Enable SysTick IRQ and SysTick Timer */
|
||||
|
||||
while (SysTick->VAL >= 100); /* wait for ~50µs */
|
||||
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk; /* Stop SysTick Timer */
|
||||
/*********************************************************/
|
||||
|
||||
/*********************************************************
|
||||
here the ramp up of the system clock starts FSys < 60MHz
|
||||
*********************************************************/
|
||||
if (CLOCK_FSYS > 60000000){
|
||||
/*calulation for stepping*/
|
||||
if (SCU_PLL_CLOCK_INPUT == SCU_CLOCK_CRYSTAL)VCO = (CLOCK_CRYSTAL_FREQUENCY/(SCU_PLL_PDIV+1))*(SCU_PLL_NDIV+1);
|
||||
if ((SCU_PLL_CLOCK_INPUT == SCU_CLOCK_BACK_UP_AUTOMATIC) ||(SCU_PLL_CLOCK_INPUT == SCU_CLOCK_BACK_UP_FACTORY))
|
||||
VCO = (CLOCK_BACK_UP/(SCU_PLL_PDIV+1))*(SCU_PLL_NDIV+1);
|
||||
|
||||
stepping_K2DIV = (VCO/60000000)-1;
|
||||
|
||||
/* Setup devider settings for main PLL */
|
||||
SCU_PLL->PLLCON1 = ((SCU_PLL_K1DIV) | (SCU_PLL_NDIV<<8) | (stepping_K2DIV<<16) | (SCU_PLL_PDIV<<24));
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Setup devider settings for main PLL */
|
||||
SCU_PLL->PLLCON1 = ((SCU_PLL_K1DIV) | (SCU_PLL_NDIV<<8) | (SCU_PLL_K2DIV<<16) | (SCU_PLL_PDIV<<24));
|
||||
SCU_TRAP->TRAPCLR = SCU_TRAP_TRAPCLR_SOSCWDGT_Msk | SCU_TRAP_TRAPCLR_SVCOLCKT_Msk; /* clear request for System OCS Watchdog Trap and System VCO Lock Trap */
|
||||
return(1);
|
||||
}
|
||||
|
||||
/*********************************************************/
|
||||
/* Delay for next K2 step ~50µs */
|
||||
/*********************************************************/
|
||||
SysTick->LOAD = ((3000+100) & SysTick_LOAD_RELOAD_Msk) - 1;
|
||||
SysTick->VAL = 0; /* Load the SysTick Counter Value */
|
||||
SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk |
|
||||
SysTick_CTRL_ENABLE_Msk; /* Enable SysTick IRQ and SysTick Timer */
|
||||
|
||||
while (SysTick->VAL >= 100); /* wait for ~50µs */
|
||||
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk; /* Stop SysTick Timer */
|
||||
/********************************/
|
||||
|
||||
/*********************************************************
|
||||
here the ramp up of the system clock starts FSys < 90MHz
|
||||
*********************************************************/
|
||||
if (CLOCK_FSYS > 90000000){
|
||||
/*calulation for stepping*/
|
||||
if (SCU_PLL_CLOCK_INPUT == SCU_CLOCK_CRYSTAL)VCO = (CLOCK_CRYSTAL_FREQUENCY/(SCU_PLL_PDIV+1))*(SCU_PLL_NDIV+1);
|
||||
if ((SCU_PLL_CLOCK_INPUT == SCU_CLOCK_BACK_UP_AUTOMATIC) ||(SCU_PLL_CLOCK_INPUT == SCU_CLOCK_BACK_UP_FACTORY))
|
||||
VCO = (CLOCK_BACK_UP/(SCU_PLL_PDIV+1))*(SCU_PLL_NDIV+1);
|
||||
|
||||
stepping_K2DIV = (VCO/90000000)-1;
|
||||
|
||||
/* Setup devider settings for main PLL */
|
||||
SCU_PLL->PLLCON1 = ((SCU_PLL_K1DIV) | (SCU_PLL_NDIV<<8) | (stepping_K2DIV<<16) | (SCU_PLL_PDIV<<24));
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Setup devider settings for main PLL */
|
||||
SCU_PLL->PLLCON1 = ((SCU_PLL_K1DIV) | (SCU_PLL_NDIV<<8) | (SCU_PLL_K2DIV<<16) | (SCU_PLL_PDIV<<24));
|
||||
SCU_TRAP->TRAPCLR = SCU_TRAP_TRAPCLR_SOSCWDGT_Msk | SCU_TRAP_TRAPCLR_SVCOLCKT_Msk; /* clear request for System OCS Watchdog Trap and System VCO Lock Trap */
|
||||
return(1);
|
||||
}
|
||||
|
||||
/*********************************************************/
|
||||
/* Delay for next K2 step ~50µs */
|
||||
/*********************************************************/
|
||||
SysTick->LOAD = ((4800+100) & SysTick_LOAD_RELOAD_Msk) - 1;
|
||||
SysTick->VAL = 0; /* Load the SysTick Counter Value */
|
||||
SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk |
|
||||
SysTick_CTRL_ENABLE_Msk; /* Enable SysTick IRQ and SysTick Timer */
|
||||
|
||||
while (SysTick->VAL >= 100); /* wait for ~50µs */
|
||||
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk; /* Stop SysTick Timer */
|
||||
/********************************/
|
||||
|
||||
/* Setup devider settings for main PLL */
|
||||
SCU_PLL->PLLCON1 = ((SCU_PLL_K1DIV) | (SCU_PLL_NDIV<<8) | (SCU_PLL_K2DIV<<16) | (SCU_PLL_PDIV<<24));
|
||||
|
||||
SCU_TRAP->TRAPCLR = SCU_TRAP_TRAPCLR_SOSCWDGT_Msk | SCU_TRAP_TRAPCLR_SVCOLCKT_Msk; /* clear request for System OCS Watchdog Trap and System VCO Lock Trap */
|
||||
}
|
||||
}/* end this weak function enables DAVE3 clock App usage */
|
||||
return(1);
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief -
|
||||
* @note -
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
#if (SCU_USB_CLOCK_SETUP == 1)
|
||||
static int USBClockSetup(void)
|
||||
{
|
||||
/* this weak function enables DAVE3 clock App usage */
|
||||
if(AllowPLLInitByStartup()){
|
||||
|
||||
/* check if PLL is switched on */
|
||||
if ((SCU_PLL->USBPLLCON &(SCU_PLL_USBPLLCON_VCOPWD_Msk | SCU_PLL_USBPLLCON_PLLPWD_Msk)) != 0){
|
||||
/* enable PLL first */
|
||||
SCU_PLL->USBPLLCON &= ~(SCU_PLL_USBPLLCON_VCOPWD_Msk | SCU_PLL_USBPLLCON_PLLPWD_Msk);
|
||||
}
|
||||
|
||||
/* check and if not already running enable OSC_HP */
|
||||
if (SCU_OSC->OSCHPCTRL & SCU_OSC_OSCHPCTRL_MODE_Msk){
|
||||
/* check if Main PLL is switched on for OSC WD*/
|
||||
if ((SCU_PLL->PLLCON0 &(SCU_PLL_PLLCON0_VCOPWD_Msk | SCU_PLL_PLLCON0_PLLPWD_Msk)) != 0){
|
||||
/* enable PLL first */
|
||||
SCU_PLL->PLLCON0 &= ~(SCU_PLL_PLLCON0_VCOPWD_Msk | SCU_PLL_PLLCON0_PLLPWD_Msk);
|
||||
}
|
||||
SCU_OSC->OSCHPCTRL &= ~(SCU_OSC_HP_MODE); /*enable the OSC_HP*/
|
||||
/* setup OSC WDG devider */
|
||||
SCU_OSC->OSCHPCTRL |= (SCU_OSCHPWDGDIV<<16);
|
||||
/* restart OSC Watchdog */
|
||||
SCU_PLL->PLLCON0 &= ~SCU_PLL_PLLCON0_OSCRES_Msk;
|
||||
|
||||
/* Timeout for wait loop ~150ms */
|
||||
/********************************/
|
||||
SysTick->LOAD = ((5000000+100) & SysTick_LOAD_RELOAD_Msk) - 1;/* set reload register */
|
||||
SysTick->VAL = 0; /* Load the SysTick Counter Value */
|
||||
SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk |
|
||||
SysTick_CTRL_ENABLE_Msk; /* Enable SysTick IRQ and SysTick Timer */
|
||||
do
|
||||
{
|
||||
;/* wait for ~150ms */
|
||||
}while((((SCU_PLL->PLLSTAT) & (SCU_PLL_PLLSTAT_PLLHV_Msk | SCU_PLL_PLLSTAT_PLLLV_Msk |SCU_PLL_PLLSTAT_PLLSP_Msk)) != 0x380)&&(SysTick->VAL >= 500));
|
||||
|
||||
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk; /* Stop SysTick Timer */
|
||||
if (((SCU_PLL->PLLSTAT) & (SCU_PLL_PLLSTAT_PLLHV_Msk | SCU_PLL_PLLSTAT_PLLLV_Msk |SCU_PLL_PLLSTAT_PLLSP_Msk)) != 0x380)
|
||||
return(0);/* Return Error */
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* Setup USB PLL */
|
||||
/* Go to bypass the Main PLL */
|
||||
SCU_PLL->USBPLLCON |= SCU_PLL_USBPLLCON_VCOBYP_Msk;
|
||||
/* disconnect OSC_FI to PLL */
|
||||
SCU_PLL->USBPLLCON |= SCU_PLL_USBPLLCON_FINDIS_Msk;
|
||||
/* Setup devider settings for main PLL */
|
||||
SCU_PLL->USBPLLCON = ((SCU_USBPLL_NDIV<<8) | (SCU_USBPLL_PDIV<<24));
|
||||
/* Setup USBDIV settings USB clock */
|
||||
SCU_CLK->USBCLKCR = SCU_USBDIV;
|
||||
/* we may have to set OSCDISCDIS */
|
||||
SCU_PLL->USBPLLCON |= SCU_PLL_USBPLLCON_OSCDISCDIS_Msk;
|
||||
/* connect OSC_FI to PLL */
|
||||
SCU_PLL->USBPLLCON &= ~SCU_PLL_USBPLLCON_FINDIS_Msk;
|
||||
/* restart PLL Lock detection */
|
||||
SCU_PLL->USBPLLCON |= SCU_PLL_USBPLLCON_RESLD_Msk;
|
||||
/* wait for PLL Lock */
|
||||
while (!(SCU_PLL->USBPLLSTAT & SCU_PLL_USBPLLSTAT_VCOLOCK_Msk));
|
||||
|
||||
}/* end this weak function enables DAVE3 clock App usage */
|
||||
return(1);
|
||||
|
||||
}
|
||||
#endif
|
||||
|
|
@ -0,0 +1,118 @@
|
|||
/*
|
||||
** @(#)cstart.c 1.9 $E%
|
||||
**
|
||||
** Copyright 1997-2013 Altium BV *
|
||||
**
|
||||
** DESCRIPTION:
|
||||
**
|
||||
** The system startup code initializes the processor's registers
|
||||
** and the application C variables.
|
||||
**
|
||||
*/
|
||||
|
||||
#pragma nomisrac
|
||||
#pragma profiling off /* prevent profiling information on cstart */
|
||||
#pragma optimize abcefgIJKlopRsUy /* preset optimization level */
|
||||
#pragma tradeoff 4 /* preset tradeoff level */
|
||||
#pragma runtime BCMSZ /* disable runtime error checking for cstart */
|
||||
#pragma warning 750 /* do not warn about unsaved registers */
|
||||
#pragma section .text=cstart /* use: .text.cstart as the section name */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <dbg.h>
|
||||
|
||||
#define VTOR (*(volatile unsigned int *)0xE000ED08)
|
||||
#define PREF_FCON (*(volatile unsigned int *)0x58002014)
|
||||
#define SCU_GCU_PEEN (*(volatile unsigned int *)0x5000413C)
|
||||
#define SCU_GCU_PEFLAG (*(volatile unsigned int *)0x50004150)
|
||||
|
||||
/* In the absence of DAVE code engine, CMSIS SystemInit() must perform clock
|
||||
tree setup.
|
||||
|
||||
This decision routine defined here will always return TRUE.
|
||||
|
||||
When overridden by a definition defined in DAVE code engine, this routine
|
||||
returns FALSE indicating that the code engine has performed the clock setup
|
||||
*/
|
||||
#pragma weak AllowPLLInitByStartup
|
||||
uint32_t AllowPLLInitByStartup( void )
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
extern unsigned char _lc_ub_stack[];
|
||||
extern unsigned char _lc_vtor_value[];
|
||||
|
||||
#pragma weak exit
|
||||
#pragma extern _Exit
|
||||
#pragma extern main
|
||||
extern int main( int argc, char *argv[] );
|
||||
extern void SystemInit( void );
|
||||
extern void __init( void );
|
||||
#if __PROF_ENABLE__
|
||||
extern void __prof_init( void );
|
||||
#endif
|
||||
|
||||
#ifdef __POSIX__
|
||||
extern void * _posix_boot_stack_top;
|
||||
extern int posix_main( void );
|
||||
#endif
|
||||
|
||||
#ifdef __USE_ARGC_ARGV
|
||||
#ifndef __ARGCV_BUFSIZE
|
||||
#define __ARGCV_BUFSIZE 256
|
||||
#endif
|
||||
static char argcv[__ARGCV_BUFSIZE];
|
||||
#endif
|
||||
|
||||
void __interrupt() __frame() Reset_Handler( void )
|
||||
{
|
||||
/* Set flash wait states to 3 */
|
||||
PREF_FCON = (PREF_FCON & 0xFFFFFFF0) | 0x00000003;
|
||||
SCU_GCU_PEFLAG =0xFFFFFFFF; /* Clear existing parity errors if any */
|
||||
SCU_GCU_PEEN = 0; /* Disable parity */
|
||||
|
||||
/*
|
||||
* Anticipate possible ROM/RAM remapping
|
||||
* by loading the 'real' program address.
|
||||
*/
|
||||
__remap_pc();
|
||||
/*
|
||||
* Initialize stack pointer.
|
||||
*/
|
||||
__setsp( _lc_ub_stack );
|
||||
/*
|
||||
* Call a user function which initializes hardware,
|
||||
* such as ROM/RAM re-mapping or MMU configuration.
|
||||
*/
|
||||
SystemInit();
|
||||
/*
|
||||
* Copy initialized sections from ROM to RAM
|
||||
* and clear uninitialized data sections in RAM.
|
||||
*/
|
||||
__init();
|
||||
__asm( "_cptable_handled:" ); /* symbol may be used by debugger */
|
||||
|
||||
/*
|
||||
* Load VTOR register with the actual vector table
|
||||
* start address
|
||||
*/
|
||||
VTOR = (unsigned int)_lc_vtor_value;
|
||||
|
||||
#ifdef __POSIX__
|
||||
__setsp( _posix_boot_stack_top );
|
||||
#endif
|
||||
#if __PROF_ENABLE__
|
||||
__prof_init();
|
||||
#endif
|
||||
#ifdef __POSIX__
|
||||
exit( posix_main() );
|
||||
#elif defined __USE_ARGC_ARGV
|
||||
exit( main( _argcv( argcv, __ARGCV_BUFSIZE ), (char **)argcv ) );
|
||||
#else
|
||||
exit( main( 0, NULL ) );
|
||||
#endif
|
||||
return;
|
||||
}
|
|
@ -0,0 +1,707 @@
|
|||
/**************************************************************************//**
|
||||
* @file system_XMC4400.c
|
||||
* @brief CMSIS Cortex-M4 Device Peripheral Access Layer Header File
|
||||
* for the Infineon XMC4500 Device Series
|
||||
* @version V3.0.1 Alpha
|
||||
* @date 17. September 2012
|
||||
*
|
||||
* @note
|
||||
* Copyright (C) 2011 ARM Limited. All rights reserved.
|
||||
*
|
||||
* @par
|
||||
* ARM Limited (ARM) is supplying this software for use with Cortex-M
|
||||
* processor based microcontrollers. This file can be freely distributed
|
||||
* within development tools that are supporting such ARM based processors.
|
||||
*
|
||||
* @par
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
|
||||
* OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
|
||||
* ARM SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR
|
||||
* CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#include <system_XMC4400.h>
|
||||
#include <XMC4400.h>
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
Clock Variable definitions
|
||||
*----------------------------------------------------------------------------*/
|
||||
/*!< System Clock Frequency (Core Clock)*/
|
||||
uint32_t SystemCoreClock;
|
||||
|
||||
/* clock definitions, do not modify! */
|
||||
#define SCU_CLOCK_CRYSTAL 1
|
||||
#define SCU_CLOCK_BACK_UP_FACTORY 2
|
||||
#define SCU_CLOCK_BACK_UP_AUTOMATIC 3
|
||||
|
||||
|
||||
#define HIB_CLOCK_FOSI 1
|
||||
#define HIB_CLOCK_OSCULP 2
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
//-------- <<< Use Configuration Wizard in Context Menu >>> ------------------
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/*--------------------- Watchdog Configuration -------------------------------
|
||||
//
|
||||
// <e> Watchdog Configuration
|
||||
// <o1.0> Disable Watchdog
|
||||
//
|
||||
// </e>
|
||||
*/
|
||||
#define WDT_SETUP 1
|
||||
#define WDTENB_nVal 0x00000001
|
||||
|
||||
/*--------------------- CLOCK Configuration -------------------------------
|
||||
//
|
||||
// <e> Main Clock Configuration
|
||||
// <o1.0..1> CPU clock divider
|
||||
// <0=> fCPU = fSYS
|
||||
// <1=> fCPU = fSYS / 2
|
||||
// <o2.0..1> Peripheral Bus clock divider
|
||||
// <0=> fPB = fCPU
|
||||
// <1=> fPB = fCPU / 2
|
||||
// <o3.0..1> CCU Bus clock divider
|
||||
// <0=> fCCU = fCPU
|
||||
// <1=> fCCU = fCPU / 2
|
||||
//
|
||||
// </e>
|
||||
//
|
||||
*/
|
||||
|
||||
#define SCU_CLOCK_SETUP 1
|
||||
#define SCU_CPUCLKCR_DIV 0x00000000
|
||||
#define SCU_PBCLKCR_DIV 0x00000000
|
||||
#define SCU_CCUCLKCR_DIV 0x00000000
|
||||
/* not avalible in config wizzard*/
|
||||
/*
|
||||
* mandatory clock parameters **************************************************
|
||||
*
|
||||
* source for clock generation
|
||||
* range: SCU_CLOCK_CRYSTAL (crystal or external clock at crystal input)
|
||||
*
|
||||
**************************************************************************************/
|
||||
// Selection of imput lock for PLL
|
||||
/*************************************************************************************/
|
||||
#define SCU_PLL_CLOCK_INPUT SCU_CLOCK_CRYSTAL
|
||||
//#define SCU_PLL_CLOCK_INPUT SCU_CLOCK_BACK_UP_FACTORY
|
||||
//#define SCU_PLL_CLOCK_INPUT SCU_CLOCK_BACK_UP_AUTOMATIC
|
||||
|
||||
/*************************************************************************************/
|
||||
// Standby clock selection for Backup clock source trimming
|
||||
/*************************************************************************************/
|
||||
#define SCU_STANDBY_CLOCK HIB_CLOCK_OSCULP
|
||||
//#define SCU_STANDBY_CLOCK HIB_CLOCK_FOSI
|
||||
|
||||
/*************************************************************************************/
|
||||
// Global clock parameters
|
||||
/*************************************************************************************/
|
||||
#define CLOCK_FSYS 120000000
|
||||
#define CLOCK_CRYSTAL_FREQUENCY 12000000
|
||||
#define CLOCK_BACK_UP 24000000
|
||||
|
||||
/*************************************************************************************/
|
||||
/* OSC_HP setup parameters */
|
||||
/*************************************************************************************/
|
||||
#define SCU_OSC_HP_MODE 0xF0
|
||||
#define SCU_OSCHPWDGDIV 2
|
||||
|
||||
/*************************************************************************************/
|
||||
/* MAIN PLL setup parameters */
|
||||
/*************************************************************************************/
|
||||
//Divider settings for external crystal @ 12 MHz
|
||||
/*************************************************************************************/
|
||||
#define SCU_PLL_K1DIV 1
|
||||
#define SCU_PLL_K2DIV 3
|
||||
#define SCU_PLL_PDIV 1
|
||||
#define SCU_PLL_NDIV 79
|
||||
|
||||
/*************************************************************************************/
|
||||
//Divider settings for use of backup clock source trimmed
|
||||
/*************************************************************************************/
|
||||
//#define SCU_PLL_K1DIV 1
|
||||
//#define SCU_PLL_K2DIV 3
|
||||
//#define SCU_PLL_PDIV 3
|
||||
//#define SCU_PLL_NDIV 79
|
||||
/*************************************************************************************/
|
||||
|
||||
|
||||
/*--------------------- USB CLOCK Configuration ---------------------------
|
||||
//
|
||||
// <e> USB Clock Configuration
|
||||
//
|
||||
// </e>
|
||||
//
|
||||
*/
|
||||
|
||||
#define SCU_USB_CLOCK_SETUP 0
|
||||
/* not avalible in config wizzard*/
|
||||
#define SCU_USBPLL_PDIV 0
|
||||
#define SCU_USBPLL_NDIV 31
|
||||
#define SCU_USBDIV 3
|
||||
|
||||
/*--------------------- Flash Wait State Configuration -------------------------------
|
||||
//
|
||||
// <e> Flash Wait State Configuration
|
||||
// <o1.0..3> Flash Wait State
|
||||
// <0=> 3 WS
|
||||
// <1=> 4 WS
|
||||
// <2=> 5 WS
|
||||
// <3=> 6 WS
|
||||
// </e>
|
||||
//
|
||||
*/
|
||||
|
||||
#define PMU_FLASH 1
|
||||
#define PMU_FLASH_WS 0x00000000
|
||||
|
||||
|
||||
/*--------------------- CLOCKOUT Configuration -------------------------------
|
||||
//
|
||||
// <e> Clock OUT Configuration
|
||||
// <o1.0..1> Clockout Source Selection
|
||||
// <0=> System Clock
|
||||
// <2=> Divided value of USB PLL output
|
||||
// <3=> Divided value of PLL Clock
|
||||
// <o2.0..4> Clockout divider <1-10><#-1>
|
||||
// <o3.0..1> Clockout Pin Selection
|
||||
// <0=> P1.15
|
||||
// <1=> P0.8
|
||||
//
|
||||
//
|
||||
// </e>
|
||||
//
|
||||
*/
|
||||
|
||||
#define SCU_CLOCKOUT_SETUP 0
|
||||
#define SCU_CLOCKOUT_SOURCE 0x00000000
|
||||
#define SCU_CLOCKOUT_DIV 0x00000009
|
||||
#define SCU_CLOCKOUT_PIN 0x00000001
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
Clock Variable definitions
|
||||
*----------------------------------------------------------------------------*/
|
||||
/*!< System Clock Frequency (Core Clock)*/
|
||||
#if SCU_CLOCK_SETUP
|
||||
uint32_t SystemCoreClock = CLOCK_FSYS;
|
||||
#else
|
||||
uint32_t SystemCoreClock = CLOCK_BACK_UP;
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
static functions declarations
|
||||
*----------------------------------------------------------------------------*/
|
||||
#if (SCU_CLOCK_SETUP == 1)
|
||||
static int SystemClockSetup(void);
|
||||
#endif
|
||||
|
||||
#if (SCU_USB_CLOCK_SETUP == 1)
|
||||
static int USBClockSetup(void);
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* @brief Setup the microcontroller system.
|
||||
* Initialize the PLL and update the
|
||||
* SystemCoreClock variable.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void SystemInit(void)
|
||||
{
|
||||
int temp;
|
||||
|
||||
#if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
|
||||
SCB->CPACR |= ((3UL << 10*2) | /* set CP10 Full Access */
|
||||
(3UL << 11*2) ); /* set CP11 Full Access */
|
||||
#endif
|
||||
|
||||
/* Enable unaligned memory access - SCB_CCR.UNALIGN_TRP = 0 */
|
||||
SCB->CCR &= ~(SCB_CCR_UNALIGN_TRP_Msk);
|
||||
|
||||
/* Setup the WDT */
|
||||
#if WDT_SETUP
|
||||
|
||||
WDT->CTR &= ~WDTENB_nVal;
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/* Setup the Flash Wait State */
|
||||
#if PMU_FLASH
|
||||
temp = FLASH0->FCON;
|
||||
temp &= ~FLASH_FCON_WSPFLASH_Msk;
|
||||
temp |= PMU_FLASH_WS+3;
|
||||
FLASH0->FCON = temp;
|
||||
#endif
|
||||
|
||||
|
||||
/* Setup the clockout */
|
||||
#if SCU_CLOCKOUT_SETUP
|
||||
|
||||
SCU_CLK->EXTCLKCR |= SCU_CLOCKOUT_SOURCE;
|
||||
/*set PLL div for clkout */
|
||||
SCU_CLK->EXTCLKCR |= SCU_CLOCKOUT_DIV<<16;
|
||||
|
||||
if (SCU_CLOCKOUT_PIN) {
|
||||
PORT0->IOCR8 = 0x00000088; /*P0.8 --> ALT1 select + HWSEL */
|
||||
PORT0->HWSEL &= (~PORT0_HWSEL_HW8_Msk);
|
||||
PORT0->PDR1 &= (~PORT0_PDR1_PD8_Msk); /*set to strong driver */
|
||||
}
|
||||
else {
|
||||
PORT1->IOCR12 = 0x88000000; /*P1.15--> ALT1 select */
|
||||
PORT1->PDR1 &= (~PORT1_PDR1_PD15_Msk); /*set to strong driver */
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/* Setup the System clock */
|
||||
#if SCU_CLOCK_SETUP
|
||||
SystemClockSetup();
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
Clock Variable definitions
|
||||
*----------------------------------------------------------------------------*/
|
||||
SystemCoreClockUpdate();/*!< System Clock Frequency (Core Clock)*/
|
||||
|
||||
|
||||
/* Setup the USB PL */
|
||||
#if SCU_USB_CLOCK_SETUP
|
||||
USBClockSetup();
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Update SystemCoreClock according to Clock Register Values
|
||||
* @note -
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void SystemCoreClockUpdate(void)
|
||||
{
|
||||
unsigned int PDIV;
|
||||
unsigned int NDIV;
|
||||
unsigned int K2DIV;
|
||||
unsigned int long VCO;
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
Clock Variable definitions
|
||||
*----------------------------------------------------------------------------*/
|
||||
if (SCU_CLK->SYSCLKCR == 0x00010000)
|
||||
{
|
||||
if (SCU_PLL->PLLSTAT & SCU_PLL_PLLSTAT_VCOLOCK_Msk){
|
||||
/* check if PLL is locked */
|
||||
/* read back divider settings */
|
||||
PDIV = ((SCU_PLL->PLLCON1 & SCU_PLL_PLLCON1_PDIV_Msk)>>24)+1;
|
||||
NDIV = ((SCU_PLL->PLLCON1 & SCU_PLL_PLLCON1_NDIV_Msk)>>8)+1;
|
||||
K2DIV = ((SCU_PLL->PLLCON1 & SCU_PLL_PLLCON1_K2DIV_Msk)>>16)+1;
|
||||
|
||||
if(SCU_PLL->PLLCON2 & SCU_PLL_PLLCON2_PINSEL_Msk){
|
||||
/* the selected clock is the Backup clock fofi */
|
||||
VCO = (CLOCK_BACK_UP/PDIV)*NDIV;
|
||||
SystemCoreClock = VCO/K2DIV;
|
||||
/* in case the sysclock div is used */
|
||||
SystemCoreClock = SystemCoreClock/((SCU_CLK->SYSCLKCR & SCU_CLK_SYSCLKCR_SYSDIV_Msk)+1);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
/* the selected clock is the PLL external oscillator */
|
||||
VCO = (CLOCK_CRYSTAL_FREQUENCY/PDIV)*NDIV;
|
||||
SystemCoreClock = VCO/K2DIV;
|
||||
/* in case the sysclock div is used */
|
||||
SystemCoreClock = SystemCoreClock/((SCU_CLK->SYSCLKCR & SCU_CLK_SYSCLKCR_SYSDIV_Msk)+1);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SystemCoreClock = CLOCK_BACK_UP;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief -
|
||||
* @note -
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
#if (SCU_CLOCK_SETUP == 1)
|
||||
static int SystemClockSetup(void)
|
||||
{
|
||||
int temp;
|
||||
unsigned int long VCO;
|
||||
int stepping_K2DIV;
|
||||
|
||||
/* this weak function enables DAVE3 clock App usage */
|
||||
if(AllowPLLInitByStartup()){
|
||||
|
||||
/* check if PLL is switched on */
|
||||
if ((SCU_PLL->PLLCON0 &(SCU_PLL_PLLCON0_VCOPWD_Msk | SCU_PLL_PLLCON0_PLLPWD_Msk)) != 0){
|
||||
/* enable PLL first */
|
||||
SCU_PLL->PLLCON0 &= ~(SCU_PLL_PLLCON0_VCOPWD_Msk | SCU_PLL_PLLCON0_PLLPWD_Msk);
|
||||
|
||||
}
|
||||
|
||||
/* Enable OSC_HP if not already on*/
|
||||
if (SCU_PLL_CLOCK_INPUT == SCU_CLOCK_CRYSTAL)
|
||||
{
|
||||
/********************************************************************************************************************/
|
||||
/* Use external crystal for PLL clock input */
|
||||
/********************************************************************************************************************/
|
||||
|
||||
if (SCU_OSC->OSCHPCTRL & SCU_OSC_OSCHPCTRL_MODE_Msk){
|
||||
SCU_OSC->OSCHPCTRL &= ~(SCU_OSC_HP_MODE); /*enable the OSC_HP*/
|
||||
/* setup OSC WDG devider */
|
||||
SCU_OSC->OSCHPCTRL |= (SCU_OSCHPWDGDIV<<16);
|
||||
/* select external OSC as PLL input */
|
||||
SCU_PLL->PLLCON2 &= ~SCU_PLL_PLLCON2_PINSEL_Msk;
|
||||
/* restart OSC Watchdog */
|
||||
SCU_PLL->PLLCON0 &= ~SCU_PLL_PLLCON0_OSCRES_Msk;
|
||||
|
||||
/* Timeout for wait loop ~150ms */
|
||||
/********************************/
|
||||
SysTick->LOAD = ((5000000+100) & SysTick_LOAD_RELOAD_Msk) - 1;/* set reload register */
|
||||
SysTick->VAL = 0; /* Load the SysTick Counter Value */
|
||||
SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk |
|
||||
SysTick_CTRL_ENABLE_Msk; /* Enable SysTick IRQ and SysTick Timer */
|
||||
do
|
||||
{
|
||||
;/* wait for ~150ms */
|
||||
}while((((SCU_PLL->PLLSTAT) & (SCU_PLL_PLLSTAT_PLLHV_Msk | SCU_PLL_PLLSTAT_PLLLV_Msk |SCU_PLL_PLLSTAT_PLLSP_Msk)) != 0x380)&&(SysTick->VAL >= 500));
|
||||
|
||||
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk; /* Stop SysTick Timer */
|
||||
if (((SCU_PLL->PLLSTAT) & (SCU_PLL_PLLSTAT_PLLHV_Msk | SCU_PLL_PLLSTAT_PLLLV_Msk |SCU_PLL_PLLSTAT_PLLSP_Msk)) != 0x380)
|
||||
return(0);/* Return Error */
|
||||
|
||||
}
|
||||
}
|
||||
else if (SCU_PLL_CLOCK_INPUT == SCU_CLOCK_BACK_UP_FACTORY)
|
||||
{
|
||||
/********************************************************************************************************************/
|
||||
/* Use factory trimming Back-up clock for PLL clock input */
|
||||
/********************************************************************************************************************/
|
||||
/* PLL Back up clock selected */
|
||||
SCU_PLL->PLLCON2 |= SCU_PLL_PLLCON2_PINSEL_Msk;
|
||||
|
||||
}
|
||||
else if (SCU_PLL_CLOCK_INPUT == SCU_CLOCK_BACK_UP_AUTOMATIC)
|
||||
{
|
||||
/********************************************************************************************************************/
|
||||
/* Use automatic trimming Back-up clock for PLL clock input */
|
||||
/********************************************************************************************************************/
|
||||
/* check for HIB Domain enabled */
|
||||
if((SCU_POWER->PWRSTAT & SCU_POWER_PWRSTAT_HIBEN_Msk) == 0)
|
||||
SCU_POWER->PWRSET |= SCU_POWER_PWRSET_HIB_Msk; /*enable Hibernate domain*/
|
||||
|
||||
/* check for HIB Domain is not in reset state */
|
||||
if ((SCU_RESET->RSTSTAT & SCU_RESET_RSTSTAT_HIBRS_Msk)== 1)
|
||||
SCU_RESET->RSTCLR |= SCU_RESET_RSTCLR_HIBRS_Msk; /*de-assert hibernate reset*/
|
||||
|
||||
/* PLL Back up clock selected */
|
||||
SCU_PLL->PLLCON2 |= SCU_PLL_PLLCON2_PINSEL_Msk;
|
||||
|
||||
if (SCU_STANDBY_CLOCK == HIB_CLOCK_FOSI)
|
||||
{
|
||||
/****************************************************************************************************************/
|
||||
/* Use fOSI as source of the standby clock */
|
||||
/****************************************************************************************************************/
|
||||
SCU_HIBERNATE->HDCR &= ~SCU_HIBERNATE_HDCR_STDBYSEL_Msk;
|
||||
|
||||
SCU_PLL->PLLCON0 &= ~SCU_PLL_PLLCON0_FOTR_Msk;
|
||||
for(temp=0;temp<=0xFFFF;temp++);
|
||||
|
||||
SCU_PLL->PLLCON0 |= SCU_PLL_PLLCON0_AOTREN_Msk;
|
||||
}
|
||||
else if (SCU_STANDBY_CLOCK == HIB_CLOCK_OSCULP)
|
||||
{
|
||||
/****************************************************************************************************************/
|
||||
/* Use fULP as source of the standby clock */
|
||||
/****************************************************************************************************************/
|
||||
/*check OSCUL if running correct*/
|
||||
if ((SCU_HIBERNATE->OSCULCTRL & SCU_HIBERNATE_OSCULCTRL_MODE_Msk)!= 0)
|
||||
{
|
||||
while (SCU_GENERAL->MIRRSTS & SCU_GENERAL_MIRRSTS_OSCULCTRL_Msk);
|
||||
|
||||
SCU_HIBERNATE->OSCULCTRL &= ~SCU_HIBERNATE_OSCULCTRL_MODE_Msk; /*enable OSCUL*/
|
||||
/*now ceck if the clock is OK using OSCULP Oscillator Watchdog (ULPWDG)*/
|
||||
/* select OSCUL clock for RTC*/
|
||||
SCU_HIBERNATE->HDCR |= SCU_HIBERNATE_HDCR_RCS_Msk;
|
||||
while (SCU_GENERAL->MIRRSTS & SCU_GENERAL_MIRRSTS_HDCR_Msk);
|
||||
/*enable OSCULP WDG Alarm Enable*/
|
||||
SCU_HIBERNATE->HDCR |= SCU_HIBERNATE_HDCR_ULPWDGEN_Msk;
|
||||
while (SCU_GENERAL->MIRRSTS & SCU_GENERAL_MIRRSTS_HDCR_Msk);
|
||||
/*wait now for clock is stable */
|
||||
do
|
||||
{
|
||||
SCU_HIBERNATE->HDCLR |= SCU_HIBERNATE_HDCLR_ULPWDG_Msk;
|
||||
while (SCU_GENERAL->MIRRSTS & SCU_GENERAL_MIRRSTS_HDCLR_Msk);
|
||||
for(temp=0;temp<=0xFFFF;temp++);
|
||||
}
|
||||
while ((SCU_HIBERNATE->HDSTAT & SCU_HIBERNATE_HDSTAT_ULPWDG_Msk)==SCU_HIBERNATE_HDSTAT_ULPWDG_Msk);
|
||||
|
||||
SCU_HIBERNATE->HDCLR |= SCU_HIBERNATE_HDCLR_ULPWDG_Msk;
|
||||
while (SCU_GENERAL->MIRRSTS & SCU_GENERAL_MIRRSTS_HDCLR_Msk);
|
||||
}
|
||||
// now OSCULP is running and can be used
|
||||
SCU_HIBERNATE->HDCR |= SCU_HIBERNATE_HDCR_STDBYSEL_Msk;
|
||||
while (SCU_GENERAL->MIRRSTS & SCU_GENERAL_MIRRSTS_HDCR_Msk);
|
||||
|
||||
SCU_PLL->PLLCON0 &= ~SCU_PLL_PLLCON0_FOTR_Msk;
|
||||
/*TRIAL for delay loop*/
|
||||
for(temp=0;temp<=0xFFFF;temp++);
|
||||
|
||||
SCU_PLL->PLLCON0 |= SCU_PLL_PLLCON0_AOTREN_Msk;
|
||||
/*TRIAL for delay loop*/
|
||||
for(temp=0;temp<=0xFFFF;temp++);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/********************************************************************************************************************/
|
||||
/* Setup and look the main PLL */
|
||||
/********************************************************************************************************************/
|
||||
|
||||
if (!(SCU_PLL->PLLSTAT & SCU_PLL_PLLSTAT_VCOLOCK_Msk)){
|
||||
/* Systen is still running from internal clock */
|
||||
/* select FOFI as system clock */
|
||||
if((SCU_CLK->SYSCLKCR & SCU_CLK_SYSCLKCR_SYSSEL_Msk) != 0x0)SCU_CLK->SYSCLKCR &= ~SCU_CLK_SYSCLKCR_SYSSEL_Msk; /*Select FOFI*/
|
||||
|
||||
|
||||
/*calulation for stepping*/
|
||||
if (SCU_PLL_CLOCK_INPUT == SCU_CLOCK_CRYSTAL)VCO = (CLOCK_CRYSTAL_FREQUENCY/(SCU_PLL_PDIV+1))*(SCU_PLL_NDIV+1);
|
||||
if ((SCU_PLL_CLOCK_INPUT == SCU_CLOCK_BACK_UP_AUTOMATIC) ||(SCU_PLL_CLOCK_INPUT == SCU_CLOCK_BACK_UP_FACTORY))
|
||||
VCO = (CLOCK_BACK_UP/(SCU_PLL_PDIV+1))*(SCU_PLL_NDIV+1);
|
||||
|
||||
stepping_K2DIV = (VCO/24000000)-1;
|
||||
/* Go to bypass the Main PLL */
|
||||
SCU_PLL->PLLCON0 |= SCU_PLL_PLLCON0_VCOBYP_Msk;
|
||||
/* disconnect OSC_HP to PLL */
|
||||
SCU_PLL->PLLCON0 |= SCU_PLL_PLLCON0_FINDIS_Msk;
|
||||
/* Setup devider settings for main PLL */
|
||||
SCU_PLL->PLLCON1 = ((SCU_PLL_K1DIV) | (SCU_PLL_NDIV<<8) | (stepping_K2DIV<<16) | (SCU_PLL_PDIV<<24));
|
||||
/* we may have to set OSCDISCDIS */
|
||||
SCU_PLL->PLLCON0 |= SCU_PLL_PLLCON0_OSCDISCDIS_Msk;
|
||||
/* connect OSC_HP to PLL */
|
||||
SCU_PLL->PLLCON0 &= ~SCU_PLL_PLLCON0_FINDIS_Msk;
|
||||
/* restart PLL Lock detection */
|
||||
SCU_PLL->PLLCON0 |= SCU_PLL_PLLCON0_RESLD_Msk;
|
||||
/* wait for PLL Lock */
|
||||
/* setup time out loop */
|
||||
/* Timeout for wait loo ~150ms */
|
||||
/********************************/
|
||||
SysTick->LOAD = ((5000000+100) & SysTick_LOAD_RELOAD_Msk) - 1;/* set reload register */
|
||||
SysTick->VAL = 0; /* Load the SysTick Counter Value */
|
||||
SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk |
|
||||
SysTick_CTRL_ENABLE_Msk; /* Enable SysTick IRQ and SysTick Timer */
|
||||
|
||||
while ((!(SCU_PLL->PLLSTAT & SCU_PLL_PLLSTAT_VCOLOCK_Msk))&&(SysTick->VAL >= 500));
|
||||
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk; /* Stop SysTick Timer */
|
||||
|
||||
if ((SCU_PLL->PLLSTAT & SCU_PLL_PLLSTAT_VCOLOCK_Msk)==SCU_PLL_PLLSTAT_VCOLOCK_Msk)
|
||||
{
|
||||
/* Go back to the Main PLL */
|
||||
SCU_PLL->PLLCON0 &= ~SCU_PLL_PLLCON0_VCOBYP_Msk;
|
||||
}
|
||||
else return(0);
|
||||
|
||||
|
||||
/*********************************************************
|
||||
here we need to setup the system clock divider
|
||||
*********************************************************/
|
||||
|
||||
SCU_CLK->CPUCLKCR = SCU_CPUCLKCR_DIV;
|
||||
SCU_CLK->PBCLKCR = SCU_PBCLKCR_DIV;
|
||||
SCU_CLK->CCUCLKCR = SCU_CCUCLKCR_DIV;
|
||||
|
||||
|
||||
/* Switch system clock to PLL */
|
||||
SCU_CLK->SYSCLKCR |= 0x00010000;
|
||||
|
||||
/* we may have to reset OSCDISCDIS */
|
||||
SCU_PLL->PLLCON0 &= ~SCU_PLL_PLLCON0_OSCDISCDIS_Msk;
|
||||
|
||||
|
||||
/*********************************************************/
|
||||
/* Delay for next K2 step ~50µs */
|
||||
/*********************************************************/
|
||||
SysTick->LOAD = ((1250+100) & SysTick_LOAD_RELOAD_Msk) - 1;/* set reload register */
|
||||
SysTick->VAL = 0; /* Load the SysTick Counter Value */
|
||||
SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk |
|
||||
SysTick_CTRL_ENABLE_Msk; /* Enable SysTick IRQ and SysTick Timer */
|
||||
|
||||
while (SysTick->VAL >= 100); /* wait for ~50µs */
|
||||
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk; /* Stop SysTick Timer */
|
||||
/*********************************************************/
|
||||
|
||||
/*********************************************************
|
||||
here the ramp up of the system clock starts FSys < 60MHz
|
||||
*********************************************************/
|
||||
if (CLOCK_FSYS > 60000000){
|
||||
/*calulation for stepping*/
|
||||
if (SCU_PLL_CLOCK_INPUT == SCU_CLOCK_CRYSTAL)VCO = (CLOCK_CRYSTAL_FREQUENCY/(SCU_PLL_PDIV+1))*(SCU_PLL_NDIV+1);
|
||||
if ((SCU_PLL_CLOCK_INPUT == SCU_CLOCK_BACK_UP_AUTOMATIC) ||(SCU_PLL_CLOCK_INPUT == SCU_CLOCK_BACK_UP_FACTORY))
|
||||
VCO = (CLOCK_BACK_UP/(SCU_PLL_PDIV+1))*(SCU_PLL_NDIV+1);
|
||||
|
||||
stepping_K2DIV = (VCO/60000000)-1;
|
||||
|
||||
/* Setup devider settings for main PLL */
|
||||
SCU_PLL->PLLCON1 = ((SCU_PLL_K1DIV) | (SCU_PLL_NDIV<<8) | (stepping_K2DIV<<16) | (SCU_PLL_PDIV<<24));
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Setup devider settings for main PLL */
|
||||
SCU_PLL->PLLCON1 = ((SCU_PLL_K1DIV) | (SCU_PLL_NDIV<<8) | (SCU_PLL_K2DIV<<16) | (SCU_PLL_PDIV<<24));
|
||||
SCU_TRAP->TRAPCLR = SCU_TRAP_TRAPCLR_SOSCWDGT_Msk | SCU_TRAP_TRAPCLR_SVCOLCKT_Msk; /* clear request for System OCS Watchdog Trap and System VCO Lock Trap */
|
||||
return(1);
|
||||
}
|
||||
|
||||
/*********************************************************/
|
||||
/* Delay for next K2 step ~50µs */
|
||||
/*********************************************************/
|
||||
SysTick->LOAD = ((3000+100) & SysTick_LOAD_RELOAD_Msk) - 1;
|
||||
SysTick->VAL = 0; /* Load the SysTick Counter Value */
|
||||
SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk |
|
||||
SysTick_CTRL_ENABLE_Msk; /* Enable SysTick IRQ and SysTick Timer */
|
||||
|
||||
while (SysTick->VAL >= 100); /* wait for ~50µs */
|
||||
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk; /* Stop SysTick Timer */
|
||||
/********************************/
|
||||
|
||||
/*********************************************************
|
||||
here the ramp up of the system clock starts FSys < 90MHz
|
||||
*********************************************************/
|
||||
if (CLOCK_FSYS > 90000000){
|
||||
/*calulation for stepping*/
|
||||
if (SCU_PLL_CLOCK_INPUT == SCU_CLOCK_CRYSTAL)VCO = (CLOCK_CRYSTAL_FREQUENCY/(SCU_PLL_PDIV+1))*(SCU_PLL_NDIV+1);
|
||||
if ((SCU_PLL_CLOCK_INPUT == SCU_CLOCK_BACK_UP_AUTOMATIC) ||(SCU_PLL_CLOCK_INPUT == SCU_CLOCK_BACK_UP_FACTORY))
|
||||
VCO = (CLOCK_BACK_UP/(SCU_PLL_PDIV+1))*(SCU_PLL_NDIV+1);
|
||||
|
||||
stepping_K2DIV = (VCO/90000000)-1;
|
||||
|
||||
/* Setup devider settings for main PLL */
|
||||
SCU_PLL->PLLCON1 = ((SCU_PLL_K1DIV) | (SCU_PLL_NDIV<<8) | (stepping_K2DIV<<16) | (SCU_PLL_PDIV<<24));
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Setup devider settings for main PLL */
|
||||
SCU_PLL->PLLCON1 = ((SCU_PLL_K1DIV) | (SCU_PLL_NDIV<<8) | (SCU_PLL_K2DIV<<16) | (SCU_PLL_PDIV<<24));
|
||||
SCU_TRAP->TRAPCLR = SCU_TRAP_TRAPCLR_SOSCWDGT_Msk | SCU_TRAP_TRAPCLR_SVCOLCKT_Msk; /* clear request for System OCS Watchdog Trap and System VCO Lock Trap */
|
||||
return(1);
|
||||
}
|
||||
|
||||
/*********************************************************/
|
||||
/* Delay for next K2 step ~50µs */
|
||||
/*********************************************************/
|
||||
SysTick->LOAD = ((4800+100) & SysTick_LOAD_RELOAD_Msk) - 1;
|
||||
SysTick->VAL = 0; /* Load the SysTick Counter Value */
|
||||
SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk |
|
||||
SysTick_CTRL_ENABLE_Msk; /* Enable SysTick IRQ and SysTick Timer */
|
||||
|
||||
while (SysTick->VAL >= 100); /* wait for ~50µs */
|
||||
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk; /* Stop SysTick Timer */
|
||||
/********************************/
|
||||
|
||||
/* Setup devider settings for main PLL */
|
||||
SCU_PLL->PLLCON1 = ((SCU_PLL_K1DIV) | (SCU_PLL_NDIV<<8) | (SCU_PLL_K2DIV<<16) | (SCU_PLL_PDIV<<24));
|
||||
|
||||
SCU_TRAP->TRAPCLR = SCU_TRAP_TRAPCLR_SOSCWDGT_Msk | SCU_TRAP_TRAPCLR_SVCOLCKT_Msk; /* clear request for System OCS Watchdog Trap and System VCO Lock Trap */
|
||||
}
|
||||
}/* end this weak function enables DAVE3 clock App usage */
|
||||
return(1);
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief -
|
||||
* @note -
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
#if (SCU_USB_CLOCK_SETUP == 1)
|
||||
static int USBClockSetup(void)
|
||||
{
|
||||
/* this weak function enables DAVE3 clock App usage */
|
||||
if(AllowPLLInitByStartup()){
|
||||
|
||||
/* check if PLL is switched on */
|
||||
if ((SCU_PLL->USBPLLCON &(SCU_PLL_USBPLLCON_VCOPWD_Msk | SCU_PLL_USBPLLCON_PLLPWD_Msk)) != 0){
|
||||
/* enable PLL first */
|
||||
SCU_PLL->USBPLLCON &= ~(SCU_PLL_USBPLLCON_VCOPWD_Msk | SCU_PLL_USBPLLCON_PLLPWD_Msk);
|
||||
}
|
||||
|
||||
/* check and if not already running enable OSC_HP */
|
||||
if (SCU_OSC->OSCHPCTRL & SCU_OSC_OSCHPCTRL_MODE_Msk){
|
||||
/* check if Main PLL is switched on for OSC WD*/
|
||||
if ((SCU_PLL->PLLCON0 &(SCU_PLL_PLLCON0_VCOPWD_Msk | SCU_PLL_PLLCON0_PLLPWD_Msk)) != 0){
|
||||
/* enable PLL first */
|
||||
SCU_PLL->PLLCON0 &= ~(SCU_PLL_PLLCON0_VCOPWD_Msk | SCU_PLL_PLLCON0_PLLPWD_Msk);
|
||||
}
|
||||
SCU_OSC->OSCHPCTRL &= ~(SCU_OSC_HP_MODE); /*enable the OSC_HP*/
|
||||
/* setup OSC WDG devider */
|
||||
SCU_OSC->OSCHPCTRL |= (SCU_OSCHPWDGDIV<<16);
|
||||
/* restart OSC Watchdog */
|
||||
SCU_PLL->PLLCON0 &= ~SCU_PLL_PLLCON0_OSCRES_Msk;
|
||||
|
||||
/* Timeout for wait loop ~150ms */
|
||||
/********************************/
|
||||
SysTick->LOAD = ((5000000+100) & SysTick_LOAD_RELOAD_Msk) - 1;/* set reload register */
|
||||
SysTick->VAL = 0; /* Load the SysTick Counter Value */
|
||||
SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk |
|
||||
SysTick_CTRL_ENABLE_Msk; /* Enable SysTick IRQ and SysTick Timer */
|
||||
do
|
||||
{
|
||||
;/* wait for ~150ms */
|
||||
}while((((SCU_PLL->PLLSTAT) & (SCU_PLL_PLLSTAT_PLLHV_Msk | SCU_PLL_PLLSTAT_PLLLV_Msk |SCU_PLL_PLLSTAT_PLLSP_Msk)) != 0x380)&&(SysTick->VAL >= 500));
|
||||
|
||||
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk; /* Stop SysTick Timer */
|
||||
if (((SCU_PLL->PLLSTAT) & (SCU_PLL_PLLSTAT_PLLHV_Msk | SCU_PLL_PLLSTAT_PLLLV_Msk |SCU_PLL_PLLSTAT_PLLSP_Msk)) != 0x380)
|
||||
return(0);/* Return Error */
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* Setup USB PLL */
|
||||
/* Go to bypass the Main PLL */
|
||||
SCU_PLL->USBPLLCON |= SCU_PLL_USBPLLCON_VCOBYP_Msk;
|
||||
/* disconnect OSC_FI to PLL */
|
||||
SCU_PLL->USBPLLCON |= SCU_PLL_USBPLLCON_FINDIS_Msk;
|
||||
/* Setup devider settings for main PLL */
|
||||
SCU_PLL->USBPLLCON = ((SCU_USBPLL_NDIV<<8) | (SCU_USBPLL_PDIV<<24));
|
||||
/* Setup USBDIV settings USB clock */
|
||||
SCU_CLK->USBCLKCR = SCU_USBDIV;
|
||||
/* we may have to set OSCDISCDIS */
|
||||
SCU_PLL->USBPLLCON |= SCU_PLL_USBPLLCON_OSCDISCDIS_Msk;
|
||||
/* connect OSC_FI to PLL */
|
||||
SCU_PLL->USBPLLCON &= ~SCU_PLL_USBPLLCON_FINDIS_Msk;
|
||||
/* restart PLL Lock detection */
|
||||
SCU_PLL->USBPLLCON |= SCU_PLL_USBPLLCON_RESLD_Msk;
|
||||
/* wait for PLL Lock */
|
||||
while (!(SCU_PLL->USBPLLSTAT & SCU_PLL_USBPLLSTAT_VCOLOCK_Msk));
|
||||
|
||||
}/* end this weak function enables DAVE3 clock App usage */
|
||||
return(1);
|
||||
|
||||
}
|
||||
#endif
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
** @(#)cstart.c 1.8 $E%
|
||||
** @(#)cstart.c 1.9 $E%
|
||||
**
|
||||
** Copyright 1997-2012 Altium BV *
|
||||
** Copyright 1997-2013 Altium BV *
|
||||
**
|
||||
** DESCRIPTION:
|
||||
**
|
||||
|
@ -17,16 +17,25 @@
|
|||
#pragma runtime BCMSZ /* disable runtime error checking for cstart */
|
||||
#pragma warning 750 /* do not warn about unsaved registers */
|
||||
#pragma section .text=cstart /* use: .text.cstart as the section name */
|
||||
#pragma alias Reset_Handler = _START /* requirement for CMSIS */
|
||||
#pragma extern Reset_Handler /* required for mil-linking with CMSIS */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <dbg.h>
|
||||
|
||||
#define VTOR (*(volatile unsigned int *)0xE000ED08)
|
||||
#define PREF_PCON (*(volatile unsigned int *)0x58004000)
|
||||
#define SCU_GCU_PEEN (*(volatile unsigned int *)0x5000413C)
|
||||
#define SCU_GCU_PEFLAG (*(volatile unsigned int *)0x50004150)
|
||||
/* In the absence of DAVE code engine, CMSIS SystemInit() must perform clock
|
||||
tree setup.
|
||||
|
||||
This decision routine defined here will always return TRUE.
|
||||
|
||||
When overridden by a definition defined in DAVE code engine, this routine
|
||||
returns FALSE indicating that the code engine has performed the clock setup
|
||||
*/
|
||||
#pragma weak AllowPLLInitByStartup
|
||||
uint32_t AllowPLLInitByStartup( void )
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
extern unsigned char _lc_ub_stack[];
|
||||
|
@ -54,11 +63,8 @@ extern int posix_main( void );
|
|||
static char argcv[__ARGCV_BUFSIZE];
|
||||
#endif
|
||||
|
||||
void __interrupt() __frame() _START( void )
|
||||
void __interrupt() __frame() Reset_Handler( void )
|
||||
{
|
||||
PREF_PCON |= 0x00010000; /* Disable Branch prediction */
|
||||
SCU_GCU_PEFLAG =0xFFFFFFFF; /* Clear existing parity errors if any */
|
||||
SCU_GCU_PEEN = 0; /* Disable parity */
|
||||
|
||||
/*
|
||||
* Anticipate possible ROM/RAM remapping
|
||||
|
|
|
@ -1,47 +1,47 @@
|
|||
/******************************************************************************
|
||||
/**************************************************************************//**
|
||||
* @file system_XMC4500.c
|
||||
* @brief Device specific initialization for the XMC4500-Series according to CMSIS
|
||||
* @version V2.2
|
||||
* @date 20. January 2012
|
||||
* @brief CMSIS Cortex-M4 Device Peripheral Access Layer Header File
|
||||
* for the Infineon XMC4500 Device Series
|
||||
* @version V3.0.1 Alpha
|
||||
* @date 17. September 2012
|
||||
*
|
||||
* @note
|
||||
* Copyright (C) 2011 Infineon Technologies AG. All rights reserved.
|
||||
|
||||
* Copyright (C) 2011 ARM Limited. All rights reserved.
|
||||
*
|
||||
* @par
|
||||
* Infineon Technologies AG (Infineon) is supplying this software for use with Infineon’s microcontrollers.
|
||||
* This file can be freely distributed within development tools that are supporting such microcontrollers.
|
||||
|
||||
* ARM Limited (ARM) is supplying this software for use with Cortex-M
|
||||
* processor based microcontrollers. This file can be freely distributed
|
||||
* within development tools that are supporting such ARM based processors.
|
||||
*
|
||||
* @par
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
|
||||
* OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
|
||||
* INFINEON SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR
|
||||
* ARM SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR
|
||||
* CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
|
||||
*
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#include "system_XMC4500.h"
|
||||
#include <XMC4500.h>
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
Define clocks is located in System_XMC4500.h
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
Clock Variable definitions
|
||||
*----------------------------------------------------------------------------*/
|
||||
/*!< System Clock Frequency (Core Clock)*/
|
||||
uint32_t SystemCoreClock = CLOCK_OSC_HP;
|
||||
uint32_t SystemCoreClock;
|
||||
|
||||
/* clock definitions, do not modify! */
|
||||
#define SCU_CLOCK_CRYSTAL 1
|
||||
#define SCU_CLOCK_BACK_UP_FACTORY 2
|
||||
#define SCU_CLOCK_BACK_UP_AUTOMATIC 3
|
||||
|
||||
|
||||
#define HIB_CLOCK_FOSI 1
|
||||
#define HIB_CLOCK_OSCULP 2
|
||||
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
Keil pragma to prevent warnings
|
||||
*----------------------------------------------------------------------------*/
|
||||
#if defined(__ARMCC_VERSION)
|
||||
#pragma diag_suppress 177
|
||||
#endif
|
||||
|
||||
/*
|
||||
//-------- <<< Use Configuration Wizard in Context Menu >>> ------------------
|
||||
|
@ -80,8 +80,57 @@ uint32_t SystemCoreClock = CLOCK_OSC_HP;
|
|||
#define SCU_CPUCLKCR_DIV 0x00000000
|
||||
#define SCU_PBCLKCR_DIV 0x00000000
|
||||
#define SCU_CCUCLKCR_DIV 0x00000000
|
||||
/* not avalible in config wizzard*/
|
||||
/*
|
||||
* mandatory clock parameters **************************************************
|
||||
*
|
||||
* source for clock generation
|
||||
* range: SCU_CLOCK_CRYSTAL (crystal or external clock at crystal input)
|
||||
*
|
||||
**************************************************************************************/
|
||||
// Selection of imput lock for PLL
|
||||
/*************************************************************************************/
|
||||
#define SCU_PLL_CLOCK_INPUT SCU_CLOCK_CRYSTAL
|
||||
//#define SCU_PLL_CLOCK_INPUT SCU_CLOCK_BACK_UP_FACTORY
|
||||
//#define SCU_PLL_CLOCK_INPUT SCU_CLOCK_BACK_UP_AUTOMATIC
|
||||
|
||||
/*************************************************************************************/
|
||||
// Standby clock selection for Backup clock source trimming
|
||||
/*************************************************************************************/
|
||||
#define SCU_STANDBY_CLOCK HIB_CLOCK_OSCULP
|
||||
//#define SCU_STANDBY_CLOCK HIB_CLOCK_FOSI
|
||||
|
||||
/*************************************************************************************/
|
||||
// Global clock parameters
|
||||
/*************************************************************************************/
|
||||
#define CLOCK_FSYS 120000000
|
||||
#define CLOCK_CRYSTAL_FREQUENCY 12000000
|
||||
#define CLOCK_BACK_UP 24000000
|
||||
|
||||
/*************************************************************************************/
|
||||
/* OSC_HP setup parameters */
|
||||
/*************************************************************************************/
|
||||
#define SCU_OSC_HP_MODE 0xF0
|
||||
#define SCU_OSCHPWDGDIV 2
|
||||
|
||||
/*************************************************************************************/
|
||||
/* MAIN PLL setup parameters */
|
||||
/*************************************************************************************/
|
||||
//Divider settings for external crystal @ 12 MHz
|
||||
/*************************************************************************************/
|
||||
#define SCU_PLL_K1DIV 1
|
||||
#define SCU_PLL_K2DIV 3
|
||||
#define SCU_PLL_PDIV 1
|
||||
#define SCU_PLL_NDIV 79
|
||||
|
||||
/*************************************************************************************/
|
||||
//Divider settings for use of backup clock source trimmed
|
||||
/*************************************************************************************/
|
||||
//#define SCU_PLL_K1DIV 1
|
||||
//#define SCU_PLL_K2DIV 3
|
||||
//#define SCU_PLL_PDIV 3
|
||||
//#define SCU_PLL_NDIV 79
|
||||
/*************************************************************************************/
|
||||
|
||||
/*--------------------- USB CLOCK Configuration ---------------------------
|
||||
//
|
||||
|
@ -92,6 +141,25 @@ uint32_t SystemCoreClock = CLOCK_OSC_HP;
|
|||
*/
|
||||
|
||||
#define SCU_USB_CLOCK_SETUP 0
|
||||
/* not avalible in config wizzard*/
|
||||
#define SCU_USBPLL_PDIV 0
|
||||
#define SCU_USBPLL_NDIV 31
|
||||
#define SCU_USBDIV 3
|
||||
|
||||
/*--------------------- Flash Wait State Configuration -------------------------------
|
||||
//
|
||||
// <e> Flash Wait State Configuration
|
||||
// <o1.0..3> Flash Wait State
|
||||
// <0=> 3 WS
|
||||
// <1=> 4 WS
|
||||
// <2=> 5 WS
|
||||
// <3=> 6 WS
|
||||
// </e>
|
||||
//
|
||||
*/
|
||||
|
||||
#define PMU_FLASH 1
|
||||
#define PMU_FLASH_WS 0x00000000
|
||||
|
||||
|
||||
/*--------------------- CLOCKOUT Configuration -------------------------------
|
||||
|
@ -99,9 +167,10 @@ uint32_t SystemCoreClock = CLOCK_OSC_HP;
|
|||
// <e> Clock OUT Configuration
|
||||
// <o1.0..1> Clockout Source Selection
|
||||
// <0=> System Clock
|
||||
// <2=> USB Clock
|
||||
// <2=> Divided value of USB PLL output
|
||||
// <3=> Divided value of PLL Clock
|
||||
// <o2.0..1> Clockout Pin Selection
|
||||
// <o2.0..4> Clockout divider <1-10><#-1>
|
||||
// <o3.0..1> Clockout Pin Selection
|
||||
// <0=> P1.15
|
||||
// <1=> P0.8
|
||||
//
|
||||
|
@ -110,9 +179,20 @@ uint32_t SystemCoreClock = CLOCK_OSC_HP;
|
|||
//
|
||||
*/
|
||||
|
||||
#define SCU_CLOCKOUT_SETUP 0 // recommended to keep disabled
|
||||
#define SCU_CLOCKOUT_SOURCE 0x00000000
|
||||
#define SCU_CLOCKOUT_PIN 0x00000000
|
||||
#define SCU_CLOCKOUT_SETUP 0
|
||||
#define SCU_CLOCKOUT_SOURCE 0x00000003
|
||||
#define SCU_CLOCKOUT_DIV 0x00000009
|
||||
#define SCU_CLOCKOUT_PIN 0x00000001
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
Clock Variable definitions
|
||||
*----------------------------------------------------------------------------*/
|
||||
/*!< System Clock Frequency (Core Clock)*/
|
||||
#if SCU_CLOCK_SETUP
|
||||
uint32_t SystemCoreClock = CLOCK_FSYS;
|
||||
#else
|
||||
uint32_t SystemCoreClock = CLOCK_BACK_UP;
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
static functions declarations
|
||||
|
@ -122,9 +202,10 @@ static int SystemClockSetup(void);
|
|||
#endif
|
||||
|
||||
#if (SCU_USB_CLOCK_SETUP == 1)
|
||||
static void USBClockSetup(void);
|
||||
static int USBClockSetup(void);
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* @brief Setup the microcontroller system.
|
||||
* Initialize the PLL and update the
|
||||
|
@ -134,59 +215,70 @@ static void USBClockSetup(void);
|
|||
*/
|
||||
void SystemInit(void)
|
||||
{
|
||||
/* Setup the WDT */
|
||||
#if (WDT_SETUP == 1)
|
||||
WDT->CTR &= ~WDTENB_nVal;
|
||||
#endif
|
||||
int temp;
|
||||
|
||||
#if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
|
||||
SCB->CPACR |= ((3UL << 10*2) | /* set CP10 Full Access */
|
||||
(3UL << 11*2) ); /* set CP11 Full Access */
|
||||
#endif
|
||||
|
||||
/* Disable branch prediction - PCON.PBS = 1 */
|
||||
PREF->PCON |= (PREF_PCON_PBS_Msk);
|
||||
|
||||
/* Enable unaligned memory access - SCB_CCR.UNALIGN_TRP = 0 */
|
||||
SCB->CCR &= ~(SCB_CCR_UNALIGN_TRP_Msk);
|
||||
|
||||
/* Setup the WDT */
|
||||
#if WDT_SETUP
|
||||
|
||||
WDT->CTR &= ~WDTENB_nVal;
|
||||
|
||||
#endif
|
||||
|
||||
/* Setup the Flash Wait State */
|
||||
#if PMU_FLASH
|
||||
temp = FLASH0->FCON;
|
||||
temp &= ~FLASH_FCON_WSPFLASH_Msk;
|
||||
temp |= PMU_FLASH_WS+3;
|
||||
FLASH0->FCON = temp;
|
||||
#endif
|
||||
|
||||
|
||||
/* Setup the clockout */
|
||||
/* README README README README README README README README README README */
|
||||
/*
|
||||
* Please use the CLOCKOUT feature with diligence. Use this only if you know
|
||||
* what you are doing.
|
||||
*
|
||||
* You must be aware that the settings below can potentially be in conflict
|
||||
* with DAVE code generation engine preferences.
|
||||
*
|
||||
* Even worse, the setting below configures the ports as output ports while in
|
||||
* reality, the board on which this chip is mounted may have a source driving
|
||||
* the ports.
|
||||
*
|
||||
* So use this feature only when you are absolutely sure that the port must
|
||||
* indeed be configured as an output AND you are NOT linking this startup code
|
||||
* with code that was generated by DAVE code engine.
|
||||
*/
|
||||
#if (SCU_CLOCKOUT_SETUP == 1)
|
||||
#if SCU_CLOCKOUT_SETUP
|
||||
|
||||
SCU_CLK->EXTCLKCR |= SCU_CLOCKOUT_SOURCE;
|
||||
/*set PLL div for clkout */
|
||||
SCU_CLK->EXTCLKCR |= SCU_CLOCKOUT_DIV<<16;
|
||||
|
||||
if (SCU_CLOCKOUT_PIN) {
|
||||
PORT0->IOCR8 = 0x00000088; /*P0.8 --> ALT1 select + HWSEL */
|
||||
PORT0->HWSEL &= (~PORT0_HWSEL_HW8_Msk);
|
||||
//PORT0->PDR1 &= (~PORT0_PDR1_PD8_Msk); /*set to strong driver */
|
||||
}
|
||||
else PORT1->IOCR12 = 0x88000000; /*P1.15--> ALT1 select */
|
||||
else {
|
||||
PORT1->IOCR12 = 0x88000000; /*P1.15--> ALT1 select */
|
||||
//PORT1->PDR1 &= (~PORT1_PDR1_PD15_Msk); /*set to strong driver */
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/* Setup the System clock */
|
||||
#if (SCU_CLOCK_SETUP == 1)
|
||||
#if SCU_CLOCK_SETUP
|
||||
SystemClockSetup();
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
Clock Variable definitions
|
||||
*----------------------------------------------------------------------------*/
|
||||
SystemCoreClockUpdate();/*!< System Clock Frequency (Core Clock)*/
|
||||
|
||||
|
||||
/* Setup the USB PL */
|
||||
#if (SCU_USB_CLOCK_SETUP == 1)
|
||||
#if SCU_USB_CLOCK_SETUP
|
||||
USBClockSetup();
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -198,11 +290,49 @@ USBClockSetup();
|
|||
*/
|
||||
void SystemCoreClockUpdate(void)
|
||||
{
|
||||
unsigned int PDIV;
|
||||
unsigned int NDIV;
|
||||
unsigned int K2DIV;
|
||||
unsigned int long VCO;
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
Clock Variable definitions
|
||||
*----------------------------------------------------------------------------*/
|
||||
SystemCoreClock = SYSTEM_FREQUENCY;/*!< System Clock Frequency (Core Clock)*/
|
||||
if (SCU_CLK->SYSCLKCR == 0x00010000)
|
||||
{
|
||||
if (SCU_PLL->PLLSTAT & SCU_PLL_PLLSTAT_VCOLOCK_Msk){
|
||||
/* check if PLL is locked */
|
||||
/* read back divider settings */
|
||||
PDIV = ((SCU_PLL->PLLCON1 & SCU_PLL_PLLCON1_PDIV_Msk)>>24)+1;
|
||||
NDIV = ((SCU_PLL->PLLCON1 & SCU_PLL_PLLCON1_NDIV_Msk)>>8)+1;
|
||||
K2DIV = ((SCU_PLL->PLLCON1 & SCU_PLL_PLLCON1_K2DIV_Msk)>>16)+1;
|
||||
|
||||
if(SCU_PLL->PLLCON2 & SCU_PLL_PLLCON2_PINSEL_Msk){
|
||||
/* the selected clock is the Backup clock fofi */
|
||||
VCO = (CLOCK_BACK_UP/PDIV)*NDIV;
|
||||
SystemCoreClock = VCO/K2DIV;
|
||||
/* in case the sysclock div is used */
|
||||
SystemCoreClock = SystemCoreClock/((SCU_CLK->SYSCLKCR & SCU_CLK_SYSCLKCR_SYSDIV_Msk)+1);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
/* the selected clock is the PLL external oscillator */
|
||||
VCO = (CLOCK_CRYSTAL_FREQUENCY/PDIV)*NDIV;
|
||||
SystemCoreClock = VCO/K2DIV;
|
||||
/* in case the sysclock div is used */
|
||||
SystemCoreClock = SystemCoreClock/((SCU_CLK->SYSCLKCR & SCU_CLK_SYSCLKCR_SYSDIV_Msk)+1);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SystemCoreClock = CLOCK_BACK_UP;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@ -216,62 +346,182 @@ SystemCoreClock = SYSTEM_FREQUENCY;/*!< System Clock Frequency (Core Clock)*/
|
|||
#if (SCU_CLOCK_SETUP == 1)
|
||||
static int SystemClockSetup(void)
|
||||
{
|
||||
int temp;
|
||||
unsigned int long VCO;
|
||||
int stepping_K2DIV;
|
||||
|
||||
/* this weak function enables DAVE3 clock App usage */
|
||||
if(AllowPLLInitByStartup()){
|
||||
|
||||
/* check if PLL is switched on */
|
||||
if ((SCU_PLL->PLLCON0 &(SCU_PLL_PLLCON0_VCOPWD_Msk | SCU_PLL_PLLCON0_PLLPWD_Msk)) != 0){
|
||||
/* enable PLL first */
|
||||
SCU_PLL->PLLCON0 &= ~(SCU_PLL_PLLCON0_VCOPWD_Msk |
|
||||
SCU_PLL_PLLCON0_PLLPWD_Msk);
|
||||
|
||||
/* Enable OSC_HP */
|
||||
if (SCU_PLL_CLOCK_INPUT == SCU_CLOCK_CRYSTAL)
|
||||
{
|
||||
/* Enable the OSC_HP*/
|
||||
SCU_OSC->OSCHPCTRL = (OSC_HP_MODE<<4);
|
||||
/* Setup OSC WDG devider */
|
||||
SCU_OSC->OSCHPCTRL |= (OSCHPWDGDIV<<16);
|
||||
/* Select external OSC as PLL input */
|
||||
SCU_PLL->PLLCON2 &= ~SCU_PLL_PLLCON2_PINSEL_Msk;
|
||||
/* Restart OSC Watchdog */
|
||||
SCU_PLL->PLLCON0 &= ~SCU_PLL_PLLCON0_OSCRES_Msk;
|
||||
|
||||
do
|
||||
{
|
||||
; /* here a timeout need to be added */
|
||||
}while(!( (SCU_PLL->PLLSTAT) &
|
||||
(SCU_PLL_PLLSTAT_PLLHV_Msk | SCU_PLL_PLLSTAT_PLLLV_Msk |
|
||||
SCU_PLL_PLLSTAT_PLLSP_Msk)
|
||||
)
|
||||
);
|
||||
SCU_PLL->PLLCON0 &= ~(SCU_PLL_PLLCON0_VCOPWD_Msk | SCU_PLL_PLLCON0_PLLPWD_Msk);
|
||||
|
||||
}
|
||||
|
||||
/* Setup Main PLL */
|
||||
/* Select FOFI as system clock */
|
||||
if(SCU_CLK->SYSCLKCR != 0X000000)
|
||||
SCU_CLK->SYSCLKCR = 0x00000000; /*Select FOFI*/
|
||||
/* Enable OSC_HP if not already on*/
|
||||
if (SCU_PLL_CLOCK_INPUT == SCU_CLOCK_CRYSTAL)
|
||||
{
|
||||
/********************************************************************************************************************/
|
||||
/* Use external crystal for PLL clock input */
|
||||
/********************************************************************************************************************/
|
||||
|
||||
if (SCU_OSC->OSCHPCTRL & SCU_OSC_OSCHPCTRL_MODE_Msk){
|
||||
SCU_OSC->OSCHPCTRL &= ~(SCU_OSC_HP_MODE); /*enable the OSC_HP*/
|
||||
/* setup OSC WDG devider */
|
||||
SCU_OSC->OSCHPCTRL |= (SCU_OSCHPWDGDIV<<16);
|
||||
/* select external OSC as PLL input */
|
||||
SCU_PLL->PLLCON2 &= ~SCU_PLL_PLLCON2_PINSEL_Msk;
|
||||
/* restart OSC Watchdog */
|
||||
SCU_PLL->PLLCON0 &= ~SCU_PLL_PLLCON0_OSCRES_Msk;
|
||||
|
||||
/* Timeout for wait loop ~150ms */
|
||||
/********************************/
|
||||
SysTick->LOAD = ((5000000+100) & SysTick_LOAD_RELOAD_Msk) - 1;/* set reload register */
|
||||
SysTick->VAL = 0; /* Load the SysTick Counter Value */
|
||||
SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk |
|
||||
SysTick_CTRL_ENABLE_Msk; /* Enable SysTick IRQ and SysTick Timer */
|
||||
do
|
||||
{
|
||||
;/* wait for ~150ms */
|
||||
}while((((SCU_PLL->PLLSTAT) & (SCU_PLL_PLLSTAT_PLLHV_Msk | SCU_PLL_PLLSTAT_PLLLV_Msk |SCU_PLL_PLLSTAT_PLLSP_Msk)) != 0x380)&&(SysTick->VAL >= 500));
|
||||
|
||||
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk; /* Stop SysTick Timer */
|
||||
if (((SCU_PLL->PLLSTAT) & (SCU_PLL_PLLSTAT_PLLHV_Msk | SCU_PLL_PLLSTAT_PLLLV_Msk |SCU_PLL_PLLSTAT_PLLSP_Msk)) != 0x380)
|
||||
return(0);/* Return Error */
|
||||
|
||||
}
|
||||
}
|
||||
else if (SCU_PLL_CLOCK_INPUT == SCU_CLOCK_BACK_UP_FACTORY)
|
||||
{
|
||||
/********************************************************************************************************************/
|
||||
/* Use factory trimming Back-up clock for PLL clock input */
|
||||
/********************************************************************************************************************/
|
||||
/* PLL Back up clock selected */
|
||||
SCU_PLL->PLLCON2 |= SCU_PLL_PLLCON2_PINSEL_Msk;
|
||||
|
||||
}
|
||||
else if (SCU_PLL_CLOCK_INPUT == SCU_CLOCK_BACK_UP_AUTOMATIC)
|
||||
{
|
||||
/********************************************************************************************************************/
|
||||
/* Use automatic trimming Back-up clock for PLL clock input */
|
||||
/********************************************************************************************************************/
|
||||
/* check for HIB Domain enabled */
|
||||
if((SCU_POWER->PWRSTAT & SCU_POWER_PWRSTAT_HIBEN_Msk) == 0)
|
||||
SCU_POWER->PWRSET |= SCU_POWER_PWRSET_HIB_Msk; /*enable Hibernate domain*/
|
||||
|
||||
/* check for HIB Domain is not in reset state */
|
||||
if ((SCU_RESET->RSTSTAT & SCU_RESET_RSTSTAT_HIBRS_Msk)== 1)
|
||||
SCU_RESET->RSTCLR |= SCU_RESET_RSTCLR_HIBRS_Msk; /*de-assert hibernate reset*/
|
||||
|
||||
/* PLL Back up clock selected */
|
||||
SCU_PLL->PLLCON2 |= SCU_PLL_PLLCON2_PINSEL_Msk;
|
||||
|
||||
if (SCU_STANDBY_CLOCK == HIB_CLOCK_FOSI)
|
||||
{
|
||||
/****************************************************************************************************************/
|
||||
/* Use fOSI as source of the standby clock */
|
||||
/****************************************************************************************************************/
|
||||
SCU_HIBERNATE->HDCR &= ~SCU_HIBERNATE_HDCR_STDBYSEL_Msk;
|
||||
|
||||
SCU_PLL->PLLCON0 &= ~SCU_PLL_PLLCON0_FOTR_Msk;
|
||||
for(temp=0;temp<=0xFFFF;temp++);
|
||||
|
||||
SCU_PLL->PLLCON0 |= SCU_PLL_PLLCON0_AOTREN_Msk;
|
||||
}
|
||||
else if (SCU_STANDBY_CLOCK == HIB_CLOCK_OSCULP)
|
||||
{
|
||||
/****************************************************************************************************************/
|
||||
/* Use fULP as source of the standby clock */
|
||||
/****************************************************************************************************************/
|
||||
/*check OSCUL if running correct*/
|
||||
if ((SCU_HIBERNATE->OSCULCTRL & SCU_HIBERNATE_OSCULCTRL_MODE_Msk)!= 0)
|
||||
{
|
||||
while (SCU_GENERAL->MIRRSTS & SCU_GENERAL_MIRRSTS_OSCULCTRL_Msk);
|
||||
|
||||
SCU_HIBERNATE->OSCULCTRL &= ~SCU_HIBERNATE_OSCULCTRL_MODE_Msk; /*enable OSCUL*/
|
||||
/*now ceck if the clock is OK using OSCULP Oscillator Watchdog (ULPWDG)*/
|
||||
/* select OSCUL clock for RTC*/
|
||||
SCU_HIBERNATE->HDCR |= SCU_HIBERNATE_HDCR_RCS_Msk;
|
||||
while (SCU_GENERAL->MIRRSTS & SCU_GENERAL_MIRRSTS_HDCR_Msk);
|
||||
/*enable OSCULP WDG Alarm Enable*/
|
||||
SCU_HIBERNATE->HDCR |= SCU_HIBERNATE_HDCR_ULPWDGEN_Msk;
|
||||
while (SCU_GENERAL->MIRRSTS & SCU_GENERAL_MIRRSTS_HDCR_Msk);
|
||||
/*wait now for clock is stable */
|
||||
do
|
||||
{
|
||||
SCU_HIBERNATE->HDCLR |= SCU_HIBERNATE_HDCLR_ULPWDG_Msk;
|
||||
while (SCU_GENERAL->MIRRSTS & SCU_GENERAL_MIRRSTS_HDCLR_Msk);
|
||||
for(temp=0;temp<=0xFFFF;temp++);
|
||||
}
|
||||
while ((SCU_HIBERNATE->HDSTAT & SCU_HIBERNATE_HDSTAT_ULPWDG_Msk)==SCU_HIBERNATE_HDSTAT_ULPWDG_Msk);
|
||||
|
||||
SCU_HIBERNATE->HDCLR |= SCU_HIBERNATE_HDCLR_ULPWDG_Msk;
|
||||
while (SCU_GENERAL->MIRRSTS & SCU_GENERAL_MIRRSTS_HDCLR_Msk);
|
||||
}
|
||||
// now OSCULP is running and can be used
|
||||
SCU_HIBERNATE->HDCR |= SCU_HIBERNATE_HDCR_STDBYSEL_Msk;
|
||||
while (SCU_GENERAL->MIRRSTS & SCU_GENERAL_MIRRSTS_HDCR_Msk);
|
||||
|
||||
SCU_PLL->PLLCON0 &= ~SCU_PLL_PLLCON0_FOTR_Msk;
|
||||
/*TRIAL for delay loop*/
|
||||
for(temp=0;temp<=0xFFFF;temp++);
|
||||
|
||||
SCU_PLL->PLLCON0 |= SCU_PLL_PLLCON0_AOTREN_Msk;
|
||||
/*TRIAL for delay loop*/
|
||||
for(temp=0;temp<=0xFFFF;temp++);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/********************************************************************************************************************/
|
||||
/* Setup and look the main PLL */
|
||||
/********************************************************************************************************************/
|
||||
|
||||
if (!(SCU_PLL->PLLSTAT & SCU_PLL_PLLSTAT_VCOLOCK_Msk)){
|
||||
/* Systen is still running from internal clock */
|
||||
/* select FOFI as system clock */
|
||||
if((SCU_CLK->SYSCLKCR & SCU_CLK_SYSCLKCR_SYSSEL_Msk) != 0x0)SCU_CLK->SYSCLKCR &= ~SCU_CLK_SYSCLKCR_SYSSEL_Msk; /*Select FOFI*/
|
||||
|
||||
|
||||
/*calulation for stepping*/
|
||||
if (SCU_PLL_CLOCK_INPUT == SCU_CLOCK_CRYSTAL)VCO = (CLOCK_CRYSTAL_FREQUENCY/(SCU_PLL_PDIV+1))*(SCU_PLL_NDIV+1);
|
||||
if ((SCU_PLL_CLOCK_INPUT == SCU_CLOCK_BACK_UP_AUTOMATIC) ||(SCU_PLL_CLOCK_INPUT == SCU_CLOCK_BACK_UP_FACTORY))
|
||||
VCO = (CLOCK_BACK_UP/(SCU_PLL_PDIV+1))*(SCU_PLL_NDIV+1);
|
||||
|
||||
stepping_K2DIV = (VCO/24000000)-1;
|
||||
/* Go to bypass the Main PLL */
|
||||
SCU_PLL->PLLCON0 |= SCU_PLL_PLLCON0_VCOBYP_Msk;
|
||||
|
||||
/* disconnect OSC_HP to PLL */
|
||||
SCU_PLL->PLLCON0 |= SCU_PLL_PLLCON0_FINDIS_Msk;
|
||||
|
||||
/* Setup devider settings for main PLL */
|
||||
SCU_PLL->PLLCON1 = ((PLL_K1DIV) | (PLL_NDIV<<8) |
|
||||
(PLL_K2DIV_STEP_1<<16) | (PLL_PDIV<<24));
|
||||
|
||||
SCU_PLL->PLLCON1 = ((SCU_PLL_K1DIV) | (SCU_PLL_NDIV<<8) | (stepping_K2DIV<<16) | (SCU_PLL_PDIV<<24));
|
||||
/* we may have to set OSCDISCDIS */
|
||||
SCU_PLL->PLLCON0 |= SCU_PLL_PLLCON0_OSCDISCDIS_Msk;
|
||||
|
||||
/* connect OSC_HP to PLL */
|
||||
SCU_PLL->PLLCON0 &= ~SCU_PLL_PLLCON0_FINDIS_Msk;
|
||||
|
||||
/* restart PLL Lock detection */
|
||||
SCU_PLL->PLLCON0 |= SCU_PLL_PLLCON0_RESLD_Msk;
|
||||
|
||||
/* wait for PLL Lock */
|
||||
while (!(SCU_PLL->PLLSTAT & SCU_PLL_PLLSTAT_VCOLOCK_Msk));
|
||||
/* setup time out loop */
|
||||
/* Timeout for wait loo ~150ms */
|
||||
/********************************/
|
||||
SysTick->LOAD = ((5000000+100) & SysTick_LOAD_RELOAD_Msk) - 1;/* set reload register */
|
||||
SysTick->VAL = 0; /* Load the SysTick Counter Value */
|
||||
SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk |
|
||||
SysTick_CTRL_ENABLE_Msk; /* Enable SysTick IRQ and SysTick Timer */
|
||||
|
||||
while ((!(SCU_PLL->PLLSTAT & SCU_PLL_PLLSTAT_VCOLOCK_Msk))&&(SysTick->VAL >= 500));
|
||||
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk; /* Stop SysTick Timer */
|
||||
|
||||
if ((SCU_PLL->PLLSTAT & SCU_PLL_PLLSTAT_VCOLOCK_Msk)==SCU_PLL_PLLSTAT_VCOLOCK_Msk)
|
||||
{
|
||||
/* Go back to the Main PLL */
|
||||
SCU_PLL->PLLCON0 &= ~SCU_PLL_PLLCON0_VCOBYP_Msk;
|
||||
}
|
||||
else return(0);
|
||||
|
||||
|
||||
/*********************************************************
|
||||
here we need to setup the system clock divider
|
||||
|
@ -281,81 +531,100 @@ static int SystemClockSetup(void)
|
|||
SCU_CLK->PBCLKCR = SCU_PBCLKCR_DIV;
|
||||
SCU_CLK->CCUCLKCR = SCU_CCUCLKCR_DIV;
|
||||
|
||||
|
||||
/* Switch system clock to PLL */
|
||||
SCU_CLK->SYSCLKCR |= 0x00010000;
|
||||
|
||||
/*********************************************************
|
||||
here the ramp up of the system clock starts
|
||||
*********************************************************/
|
||||
/* we may have to reset OSCDISCDIS */
|
||||
SCU_PLL->PLLCON0 &= ~SCU_PLL_PLLCON0_OSCDISCDIS_Msk;
|
||||
|
||||
|
||||
/*********************************************************/
|
||||
/* Delay for next K2 step ~50µs */
|
||||
/********************************/
|
||||
/* Set reload register */
|
||||
SysTick->LOAD = ((1250+100) & SysTick_LOAD_RELOAD_Msk) - 1;
|
||||
|
||||
/* Load the SysTick Counter Value */
|
||||
SysTick->VAL = 0;
|
||||
|
||||
/* Enable SysTick IRQ and SysTick Timer */
|
||||
/*********************************************************/
|
||||
SysTick->LOAD = ((1250+100) & SysTick_LOAD_RELOAD_Msk) - 1;/* set reload register */
|
||||
SysTick->VAL = 0; /* Load the SysTick Counter Value */
|
||||
SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk |
|
||||
SysTick_CTRL_ENABLE_Msk;
|
||||
SysTick_CTRL_ENABLE_Msk; /* Enable SysTick IRQ and SysTick Timer */
|
||||
|
||||
/* wait for ~50µs */
|
||||
while (SysTick->VAL >= 100);
|
||||
while (SysTick->VAL >= 100); /* wait for ~50µs */
|
||||
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk; /* Stop SysTick Timer */
|
||||
/*********************************************************/
|
||||
|
||||
/* Stop SysTick Timer */
|
||||
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
|
||||
/********************************/
|
||||
/*********************************************************
|
||||
here the ramp up of the system clock starts FSys < 60MHz
|
||||
*********************************************************/
|
||||
if (CLOCK_FSYS > 60000000){
|
||||
/*calulation for stepping*/
|
||||
if (SCU_PLL_CLOCK_INPUT == SCU_CLOCK_CRYSTAL)VCO = (CLOCK_CRYSTAL_FREQUENCY/(SCU_PLL_PDIV+1))*(SCU_PLL_NDIV+1);
|
||||
if ((SCU_PLL_CLOCK_INPUT == SCU_CLOCK_BACK_UP_AUTOMATIC) ||(SCU_PLL_CLOCK_INPUT == SCU_CLOCK_BACK_UP_FACTORY))
|
||||
VCO = (CLOCK_BACK_UP/(SCU_PLL_PDIV+1))*(SCU_PLL_NDIV+1);
|
||||
|
||||
stepping_K2DIV = (VCO/60000000)-1;
|
||||
|
||||
/* Setup devider settings for main PLL */
|
||||
SCU_PLL->PLLCON1 = ((PLL_K1DIV) | (PLL_NDIV<<8) |
|
||||
(PLL_K2DIV_STEP_2<<16) | (PLL_PDIV<<24));
|
||||
SCU_PLL->PLLCON1 = ((SCU_PLL_K1DIV) | (SCU_PLL_NDIV<<8) | (stepping_K2DIV<<16) | (SCU_PLL_PDIV<<24));
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Setup devider settings for main PLL */
|
||||
SCU_PLL->PLLCON1 = ((SCU_PLL_K1DIV) | (SCU_PLL_NDIV<<8) | (SCU_PLL_K2DIV<<16) | (SCU_PLL_PDIV<<24));
|
||||
SCU_TRAP->TRAPCLR = SCU_TRAP_TRAPCLR_SOSCWDGT_Msk | SCU_TRAP_TRAPCLR_SVCOLCKT_Msk; /* clear request for System OCS Watchdog Trap and System VCO Lock Trap */
|
||||
return(1);
|
||||
}
|
||||
|
||||
/*********************************************************/
|
||||
/* Delay for next K2 step ~50µs */
|
||||
/********************************/
|
||||
/*********************************************************/
|
||||
SysTick->LOAD = ((3000+100) & SysTick_LOAD_RELOAD_Msk) - 1;
|
||||
SysTick->VAL = 0; /* Load the SysTick Counter Value */
|
||||
SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk |
|
||||
SysTick_CTRL_ENABLE_Msk; /* Enable SysTick IRQ and SysTick Timer */
|
||||
|
||||
/* Load the SysTick Counter Value */
|
||||
SysTick->VAL = 0;
|
||||
|
||||
/* Enable SysTick IRQ and SysTick Timer */
|
||||
SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_ENABLE_Msk;
|
||||
|
||||
/* Wait for ~50µs */
|
||||
while (SysTick->VAL >= 100);
|
||||
|
||||
/* Stop SysTick Timer */
|
||||
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
|
||||
while (SysTick->VAL >= 100); /* wait for ~50µs */
|
||||
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk; /* Stop SysTick Timer */
|
||||
/********************************/
|
||||
|
||||
/* Setup devider settings for main PLL */
|
||||
SCU_PLL->PLLCON1 = ((PLL_K1DIV) | (PLL_NDIV<<8) |
|
||||
(PLL_K2DIV_STEP_3<<16) | (PLL_PDIV<<24));
|
||||
/*********************************************************
|
||||
here the ramp up of the system clock starts FSys < 90MHz
|
||||
*********************************************************/
|
||||
if (CLOCK_FSYS > 90000000){
|
||||
/*calulation for stepping*/
|
||||
if (SCU_PLL_CLOCK_INPUT == SCU_CLOCK_CRYSTAL)VCO = (CLOCK_CRYSTAL_FREQUENCY/(SCU_PLL_PDIV+1))*(SCU_PLL_NDIV+1);
|
||||
if ((SCU_PLL_CLOCK_INPUT == SCU_CLOCK_BACK_UP_AUTOMATIC) ||(SCU_PLL_CLOCK_INPUT == SCU_CLOCK_BACK_UP_FACTORY))
|
||||
VCO = (CLOCK_BACK_UP/(SCU_PLL_PDIV+1))*(SCU_PLL_NDIV+1);
|
||||
|
||||
stepping_K2DIV = (VCO/90000000)-1;
|
||||
|
||||
/* Setup devider settings for main PLL */
|
||||
SCU_PLL->PLLCON1 = ((SCU_PLL_K1DIV) | (SCU_PLL_NDIV<<8) | (stepping_K2DIV<<16) | (SCU_PLL_PDIV<<24));
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Setup devider settings for main PLL */
|
||||
SCU_PLL->PLLCON1 = ((SCU_PLL_K1DIV) | (SCU_PLL_NDIV<<8) | (SCU_PLL_K2DIV<<16) | (SCU_PLL_PDIV<<24));
|
||||
SCU_TRAP->TRAPCLR = SCU_TRAP_TRAPCLR_SOSCWDGT_Msk | SCU_TRAP_TRAPCLR_SVCOLCKT_Msk; /* clear request for System OCS Watchdog Trap and System VCO Lock Trap */
|
||||
return(1);
|
||||
}
|
||||
|
||||
/*********************************************************/
|
||||
/* Delay for next K2 step ~50µs */
|
||||
/********************************/
|
||||
/*********************************************************/
|
||||
SysTick->LOAD = ((4800+100) & SysTick_LOAD_RELOAD_Msk) - 1;
|
||||
SysTick->VAL = 0; /* Load the SysTick Counter Value */
|
||||
SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk |
|
||||
SysTick_CTRL_ENABLE_Msk; /* Enable SysTick IRQ and SysTick Timer */
|
||||
|
||||
/* Load the SysTick Counter Value */
|
||||
SysTick->VAL = 0;
|
||||
|
||||
/* Enable SysTick IRQ and SysTick Timer */
|
||||
SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_ENABLE_Msk;
|
||||
|
||||
/* Wait for ~50µs */
|
||||
while (SysTick->VAL >= 100);
|
||||
|
||||
/* Stop SysTick Timer */
|
||||
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
|
||||
while (SysTick->VAL >= 100); /* wait for ~50µs */
|
||||
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk; /* Stop SysTick Timer */
|
||||
/********************************/
|
||||
|
||||
/* Setup devider settings for main PLL */
|
||||
SCU_PLL->PLLCON1 = ((PLL_K1DIV) | (PLL_NDIV<<8) | (PLL_K2DIV<<16) |
|
||||
(PLL_PDIV<<24));
|
||||
|
||||
/* clear request for System OCS Watchdog Trap and System VCO Lock Trap */
|
||||
SCU_TRAP->TRAPCLR = SCU_TRAP_TRAPCLR_SOSCWDGT_Msk |
|
||||
SCU_TRAP_TRAPCLR_SVCOLCKT_Msk;
|
||||
SCU_PLL->PLLCON1 = ((SCU_PLL_K1DIV) | (SCU_PLL_NDIV<<8) | (SCU_PLL_K2DIV<<16) | (SCU_PLL_PDIV<<24));
|
||||
|
||||
SCU_TRAP->TRAPCLR = SCU_TRAP_TRAPCLR_SOSCWDGT_Msk | SCU_TRAP_TRAPCLR_SVCOLCKT_Msk; /* clear request for System OCS Watchdog Trap and System VCO Lock Trap */
|
||||
}
|
||||
}/* end this weak function enables DAVE3 clock App usage */
|
||||
return(1);
|
||||
|
||||
}
|
||||
|
@ -368,35 +637,45 @@ static int SystemClockSetup(void)
|
|||
* @retval None
|
||||
*/
|
||||
#if (SCU_USB_CLOCK_SETUP == 1)
|
||||
static void USBClockSetup(void)
|
||||
static int USBClockSetup(void)
|
||||
{
|
||||
/* this weak function enables DAVE3 clock App usage */
|
||||
if(AllowPLLInitByStartup()){
|
||||
|
||||
/* check if PLL is switched on */
|
||||
if ((SCU_PLL->USBPLLCON &(SCU_PLL_USBPLLCON_VCOPWD_Msk | SCU_PLL_USBPLLCON_PLLPWD_Msk)) != 0){
|
||||
/* enable PLL first */
|
||||
SCU_PLL->USBPLLCON &= ~(SCU_PLL_USBPLLCON_VCOPWD_Msk |
|
||||
SCU_PLL_USBPLLCON_PLLPWD_Msk);
|
||||
SCU_PLL->USBPLLCON &= ~(SCU_PLL_USBPLLCON_VCOPWD_Msk | SCU_PLL_USBPLLCON_PLLPWD_Msk);
|
||||
}
|
||||
|
||||
/* check and if not already running enable OSC_HP */
|
||||
if(!((SCU_PLL->PLLSTAT) &
|
||||
(SCU_PLL_PLLSTAT_PLLHV_Msk |
|
||||
SCU_PLL_PLLSTAT_PLLLV_Msk |SCU_PLL_PLLSTAT_PLLSP_Msk)))
|
||||
{
|
||||
if (SCU_PLL_CLOCK_INPUT == SCU_CLOCK_CRYSTAL)
|
||||
{
|
||||
|
||||
SCU_OSC->OSCHPCTRL = (OSC_HP_MODE<<4); /*enable the OSC_HP*/
|
||||
if (SCU_OSC->OSCHPCTRL & SCU_OSC_OSCHPCTRL_MODE_Msk){
|
||||
/* check if Main PLL is switched on for OSC WD*/
|
||||
if ((SCU_PLL->PLLCON0 &(SCU_PLL_PLLCON0_VCOPWD_Msk | SCU_PLL_PLLCON0_PLLPWD_Msk)) != 0){
|
||||
/* enable PLL first */
|
||||
SCU_PLL->PLLCON0 &= ~(SCU_PLL_PLLCON0_VCOPWD_Msk | SCU_PLL_PLLCON0_PLLPWD_Msk);
|
||||
}
|
||||
SCU_OSC->OSCHPCTRL &= ~(SCU_OSC_HP_MODE); /*enable the OSC_HP*/
|
||||
/* setup OSC WDG devider */
|
||||
SCU_OSC->OSCHPCTRL |= (OSCHPWDGDIV<<16);
|
||||
/* select external OSC as PLL input */
|
||||
SCU_PLL->PLLCON2 &= ~SCU_PLL_PLLCON2_PINSEL_Msk;
|
||||
SCU_OSC->OSCHPCTRL |= (SCU_OSCHPWDGDIV<<16);
|
||||
/* restart OSC Watchdog */
|
||||
SCU_PLL->PLLCON0 &= ~SCU_PLL_PLLCON0_OSCRES_Msk;
|
||||
|
||||
/* Timeout for wait loop ~150ms */
|
||||
/********************************/
|
||||
SysTick->LOAD = ((5000000+100) & SysTick_LOAD_RELOAD_Msk) - 1;/* set reload register */
|
||||
SysTick->VAL = 0; /* Load the SysTick Counter Value */
|
||||
SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk |
|
||||
SysTick_CTRL_ENABLE_Msk; /* Enable SysTick IRQ and SysTick Timer */
|
||||
do
|
||||
{
|
||||
; /* here a timeout need to be added */
|
||||
}while(!((SCU_PLL->PLLSTAT) & (SCU_PLL_PLLSTAT_PLLHV_Msk |
|
||||
SCU_PLL_PLLSTAT_PLLLV_Msk |SCU_PLL_PLLSTAT_PLLSP_Msk)));
|
||||
;/* wait for ~150ms */
|
||||
}while((((SCU_PLL->PLLSTAT) & (SCU_PLL_PLLSTAT_PLLHV_Msk | SCU_PLL_PLLSTAT_PLLLV_Msk |SCU_PLL_PLLSTAT_PLLSP_Msk)) != 0x380)&&(SysTick->VAL >= 500));
|
||||
|
||||
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk; /* Stop SysTick Timer */
|
||||
if (((SCU_PLL->PLLSTAT) & (SCU_PLL_PLLSTAT_PLLHV_Msk | SCU_PLL_PLLSTAT_PLLLV_Msk |SCU_PLL_PLLSTAT_PLLSP_Msk)) != 0x380)
|
||||
return(0);/* Return Error */
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -406,7 +685,9 @@ static void USBClockSetup(void)
|
|||
/* disconnect OSC_FI to PLL */
|
||||
SCU_PLL->USBPLLCON |= SCU_PLL_USBPLLCON_FINDIS_Msk;
|
||||
/* Setup devider settings for main PLL */
|
||||
SCU_PLL->USBPLLCON = ((USBPLL_NDIV<<8) | (USBPLL_PDIV<<24));
|
||||
SCU_PLL->USBPLLCON = ((SCU_USBPLL_NDIV<<8) | (SCU_USBPLL_PDIV<<24));
|
||||
/* Setup USBDIV settings USB clock */
|
||||
SCU_CLK->USBCLKCR = SCU_USBDIV;
|
||||
/* we may have to set OSCDISCDIS */
|
||||
SCU_PLL->USBPLLCON |= SCU_PLL_USBPLLCON_OSCDISCDIS_Msk;
|
||||
/* connect OSC_FI to PLL */
|
||||
|
@ -415,5 +696,10 @@ static void USBClockSetup(void)
|
|||
SCU_PLL->USBPLLCON |= SCU_PLL_USBPLLCON_RESLD_Msk;
|
||||
/* wait for PLL Lock */
|
||||
while (!(SCU_PLL->USBPLLSTAT & SCU_PLL_USBPLLSTAT_VCOLOCK_Msk));
|
||||
|
||||
}/* end this weak function enables DAVE3 clock App usage */
|
||||
return(1);
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -96,6 +96,10 @@
|
|||
#include "XMC4500.h"
|
||||
#include "System_XMC4500.h"
|
||||
|
||||
/* Standard demo includes. */
|
||||
#include "QueueSet.h"
|
||||
#include "QueueOverwrite.h"
|
||||
|
||||
/* Set mainCREATE_SIMPLE_BLINKY_DEMO_ONLY to one to run the simple blinky demo,
|
||||
or 0 to run the more comprehensive test and demo application. */
|
||||
#define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY 0
|
||||
|
@ -139,13 +143,7 @@ int main( void )
|
|||
|
||||
static void prvSetupHardware( void )
|
||||
{
|
||||
extern void SystemCoreClockUpdate( void );
|
||||
|
||||
/* Ensure SystemCoreClock variable is set. */
|
||||
SystemCoreClockUpdate();
|
||||
|
||||
/* Configure pin P3.9 for the LED. */
|
||||
PORT3->IOCR8 = 0x00008000;
|
||||
configCONFIGURE_LED();
|
||||
|
||||
/* Ensure all priority bits are assigned as preemption priority bits. */
|
||||
NVIC_SetPriorityGrouping( 0 );
|
||||
|
@ -209,6 +207,17 @@ void vApplicationTickHook( void )
|
|||
added here, but the tick hook is called from an interrupt context, so
|
||||
code must not attempt to block, and only the interrupt safe FreeRTOS API
|
||||
functions can be used (those that end in FromISR()). */
|
||||
|
||||
#if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 0
|
||||
{
|
||||
/* Write to a queue that is in use as part of the queue set demo to
|
||||
demonstrate using queue sets from an ISR. */
|
||||
vQueueSetAccessQueueSetFromISR();
|
||||
|
||||
/* Test the ISR safe queue overwrite functions. */
|
||||
vQueueOverwritePeriodicISRDemo();
|
||||
}
|
||||
#endif /* mainCREATE_SIMPLE_BLINKY_DEMO_ONLY */
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
|
|
|
@ -129,9 +129,6 @@ functionality. */
|
|||
#define mainQUEUE_SEND_PARAMETER ( 0x1111UL )
|
||||
#define mainQUEUE_RECEIVE_PARAMETER ( 0x22UL )
|
||||
|
||||
/* To toggle the single LED */
|
||||
#define mainTOGGLE_LED() ( PORT3->OMR = 0x02000200 )
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
/*
|
||||
|
@ -146,11 +143,6 @@ static void prvQueueSendTask( void *pvParameters );
|
|||
*/
|
||||
void main_blinky( void );
|
||||
|
||||
/*
|
||||
* The hardware only has a single LED. Simply toggle it.
|
||||
*/
|
||||
extern void vMainToggleLED( void );
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
/* The queue used by both tasks. */
|
||||
|
@ -238,7 +230,7 @@ unsigned long ulReceivedValue;
|
|||
is it the expected value? If it is, toggle the LED. */
|
||||
if( ulReceivedValue == 100UL )
|
||||
{
|
||||
mainTOGGLE_LED();
|
||||
configTOGGLE_LED();
|
||||
ulReceivedValue = 0U;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -113,16 +113,14 @@
|
|||
|
||||
/* Standard demo application includes. */
|
||||
#include "flop.h"
|
||||
#include "integer.h"
|
||||
#include "PollQ.h"
|
||||
#include "semtest.h"
|
||||
#include "dynamic.h"
|
||||
#include "BlockQ.h"
|
||||
#include "blocktim.h"
|
||||
#include "countsem.h"
|
||||
#include "GenQTest.h"
|
||||
#include "recmutex.h"
|
||||
#include "death.h"
|
||||
#include "QueueSet.h"
|
||||
#include "QueueOverwrite.h"
|
||||
|
||||
/* Hardware includes. */
|
||||
#include "XMC4500.h"
|
||||
|
@ -135,9 +133,6 @@
|
|||
#define mainCREATOR_TASK_PRIORITY ( tskIDLE_PRIORITY + 3UL )
|
||||
#define mainFLOP_TASK_PRIORITY ( tskIDLE_PRIORITY )
|
||||
|
||||
/* To toggle the single LED */
|
||||
#define mainTOGGLE_LED() ( PORT3->OMR = 0x02000200 )
|
||||
|
||||
/* A block time of zero simply means "don't block". */
|
||||
#define mainDONT_BLOCK ( 0UL )
|
||||
|
||||
|
@ -183,15 +178,12 @@ xTimerHandle xCheckTimer = NULL;
|
|||
/* Start all the other standard demo/test tasks. The have not particular
|
||||
functionality, but do demonstrate how to use the FreeRTOS API and test the
|
||||
kernel port. */
|
||||
vStartIntegerMathTasks( tskIDLE_PRIORITY );
|
||||
vStartQueueSetTasks();
|
||||
vStartQueueOverwriteTask( tskIDLE_PRIORITY );
|
||||
vStartDynamicPriorityTasks();
|
||||
vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
|
||||
vCreateBlockTimeTasks();
|
||||
vStartCountingSemaphoreTasks();
|
||||
vStartGenericQueueTasks( tskIDLE_PRIORITY );
|
||||
vStartRecursiveMutexTasks();
|
||||
vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
|
||||
vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
|
||||
vStartMathTasks( mainFLOP_TASK_PRIORITY );
|
||||
|
||||
/* Create the register check tasks, as described at the top of this
|
||||
|
@ -213,11 +205,6 @@ xTimerHandle xCheckTimer = NULL;
|
|||
xTimerStart( xCheckTimer, mainDONT_BLOCK );
|
||||
}
|
||||
|
||||
/* The set of tasks created by the following function call have to be
|
||||
created last as they keep account of the number of tasks they expect to see
|
||||
running. */
|
||||
vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );
|
||||
|
||||
/* Start the scheduler. */
|
||||
vTaskStartScheduler();
|
||||
|
||||
|
@ -247,21 +234,11 @@ unsigned long ulErrorFound = pdFALSE;
|
|||
ulErrorFound = pdTRUE;
|
||||
}
|
||||
|
||||
if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
|
||||
{
|
||||
ulErrorFound = pdTRUE;
|
||||
}
|
||||
|
||||
if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
|
||||
{
|
||||
ulErrorFound = pdTRUE;
|
||||
}
|
||||
|
||||
if( xAreBlockingQueuesStillRunning() != pdTRUE )
|
||||
{
|
||||
ulErrorFound = pdTRUE;
|
||||
}
|
||||
|
||||
if ( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
|
||||
{
|
||||
ulErrorFound = pdTRUE;
|
||||
|
@ -277,17 +254,12 @@ unsigned long ulErrorFound = pdFALSE;
|
|||
ulErrorFound = pdTRUE;
|
||||
}
|
||||
|
||||
if( xIsCreateTaskStillRunning() != pdTRUE )
|
||||
if( xAreQueueSetTasksStillRunning() != pdTRUE )
|
||||
{
|
||||
ulErrorFound = pdTRUE;
|
||||
}
|
||||
|
||||
if( xArePollingQueuesStillRunning() != pdTRUE )
|
||||
{
|
||||
ulErrorFound = pdTRUE;
|
||||
}
|
||||
|
||||
if( xAreSemaphoreTasksStillRunning() != pdTRUE )
|
||||
if( xIsQueueOverwriteTaskStillRunning() != pdTRUE )
|
||||
{
|
||||
ulErrorFound = pdTRUE;
|
||||
}
|
||||
|
@ -309,7 +281,7 @@ unsigned long ulErrorFound = pdFALSE;
|
|||
/* Toggle the check LED to give an indication of the system status. If
|
||||
the LED toggles every mainCHECK_TIMER_PERIOD_MS milliseconds then
|
||||
everything is ok. A faster toggle indicates an error. */
|
||||
mainTOGGLE_LED();
|
||||
configTOGGLE_LED();
|
||||
|
||||
/* Have any errors been latch in ulErrorFound? If so, shorten the
|
||||
period of the check timer to mainERROR_CHECK_TIMER_PERIOD_MS milliseconds.
|
||||
|
@ -664,6 +636,12 @@ static void vRegTest2Task( void *pvParameters )
|
|||
" ldr r1, [r0] \n"
|
||||
" adds r1, r1, #1 \n"
|
||||
" str r1, [r0] \n"
|
||||
" \n"
|
||||
" movs r0, #0x01 \n" /* Yield to increase test coverage. */
|
||||
" ldr r1, =0xe000ed04 \n" /*NVIC_INT_CTRL */
|
||||
" lsl r0, r0, #28 \n" /* Shift to PendSV bit */
|
||||
" str r0, [r1] \n"
|
||||
" dsb \n"
|
||||
" pop { r0-r1 } \n"
|
||||
" \n"
|
||||
" b reg2_loop \n" /* Start again. */
|
||||
|
|
Loading…
Reference in a new issue