AT91SAM7SE能不能不用那个PLL,只用外部的4M晶振作为MSCK?
本帖最后由 fiaanull 于 2013-10-23 15:32 编辑大神们,对于AT91SAM7SE32能不能不用那个PLL倍频啊,功耗太高了,USB从不使用,怎么关闭掉呢?
还是在开始启动时就不配置就行了?能不能用外部的4M晶振作为MSCK啊?应该怎么操作呢?现在对时钟配置这块头都大了!
这是 SAM7_FLASH.mac文件:{:biggrin:}
//-----------------------------------------------------------------------------
// ATMEL Microcontroller Software Support-ROUSSET-
//-----------------------------------------------------------------------------
// DISCLAIMER:THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
// DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
// OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//-----------------------------------------------------------------------------
//File Name : SAM7_FLASH.mac
//Object : Generic Macro File for IAR
// Hardware Reset
// Init PLL at 48 MHz
// Init EFC with 2 Wait State
// Check Flash at 0
// Enable User Reset
// Stop watch dog
//1.0 11/May/06 JPP : Creation
//1.1 19/May/06 JPP : Add __emulatorSpeed(30000) in execUserPreload
//-----------------------------------------------------------------------------
__var __mac_i;
__var __mac_mem;
__var __mac_next;
/*********************************************************************
*
* _CheckRemap()
*
* Function description
* Check the Remap.
*/
_CheckRemap()
{
//* Read the value at 0x0
__mac_mem =__readMemory32(0x00000000,"Memory");
__mac_i =__mac_mem+1;
__writeMemory32(__mac_i,0x00,"Memory");
__mac_next =__readMemory32(0x00000000,"Memory");
if (__mac_i == __mac_next) {
__writeMemory32( __mac_mem,0x00000000,"Memory");
__message "RAM at0x0000 0000";
} else {
__message "Flash or Rom at 0x0000 0000";
}
}
/*********************************************************************
*
* _MapFlashAt0()
*
* Function description
* Maps RAM at 0.
*/
_MapFlashAt0(){
__message "No Changing mapping: Flash mapped to 0";
_CheckRemap();
}
/*********************************************************************
*
* _InitRSTC()
*
* Function description
* Initializes the RSTC (Reset controller).
* This makes sense since the default is to not allow user resets,
* which makes it impossible to apply a second RESET via J-Link
*/
_InitRSTC() {
// Allow user reset
__writeMemory32(0xA5000001, 0xFFFFFD08,"Memory");
}
/*********************************************************************
*
* _Watchdog()
*
* Function description
* Clear Watchdog
*/
_Watchdog()
{
//* Watchdog Disable
// AT91C_BASE_WDTC->WDTC_WDMR= AT91C_WDTC_WDDIS;
__writeMemory32(0x00008000,0xFFFFFD44,"Memory");
__message " Watchdog Disable ";
}
/*********************************************************************
*
* _EFC()
*
* Function description
* Set EFC Wait state
*/
_EFC()
{
__message " Flash Initialization (EFC0) 2 WS 48 Mhz";
__writeMemory32(0x00480200,0xFFFFFF60,"Memory");
__mac_i=__readMemory32(0xFFFFF240,"Memory");
if ( __mac_i == 0x272A0A40){
__mac_i=__readMemory32(0xFFFFFF7C,"Memory");
__message " Flash (EFC1) Version 0x",__mac_i:%X;
__message " Flash Initialization (EFC1) 2 WS 48 Mhz";
__writeMemory32(0x00480200,0xFFFFFF70,"Memory");
}
}
/*********************************************************************
*
* _InitPLL()
* Function description
* Initializes the PMC.
* 1. Enable the Main Oscillator
* 2. Configure PLL to 96MHz
* 3. Switch Master Clock (MCK) on PLL/2 = 48MHz
*/
_InitPLL() {
__message "Enable Main Oscillator";
__writeMemory32(0x00004001,0xFFFFFc20,"Memory"); // MOSC
while( !(__readMemory32(0xFFFFFc68,"Memory") & 0x1));
__message "Set PLL to 96MHz";
__writeMemory32(0x1048100e,0xFFFFFc2c,"Memory"); // LOCK
while( !(__readMemory32(0xFFFFFc68,"Memory") & 0x4));
__message "Set Master Clock to 48MHz";
__writeMemory32(0x00000004,0xFFFFFc30,"Memory"); // MCKRDY
while( !(__readMemory32(0xFFFFFc68,"Memory") & 0x8));
__writeMemory32(0x00000007,0xFFFFFc30,"Memory"); // MCKRDY
while( !(__readMemory32(0xFFFFFc68,"Memory") & 0x8));
}
//-----------------------------------------------------------------------------
// Reset the Interrupt Controller
//-------------------------------
// Normally, the code is executed only if a reset has been actually performed.
// So, the AIC initialization resumes at setting up the default vectors.
//-----------------------------------------------------------------------------
AIC()
{
// Mask All interrupt pAic->AIC_IDCR = 0xFFFFFFFF;
__writeMemory32(0xffffffff,0xFFFFF124,"Memory");
__writeMemory32(0xffffffff,0xFFFFF128,"Memory");
// disable peripheral clockPeripheral Clock Disable Register
__writeMemory32(0xffffffff,0xFFFFFC14,"Memory");
// #define AT91C_TC0_SR ((AT91_REG *) 0xFFFA0020) // (TC0) Status Register
// #define AT91C_TC1_SR ((AT91_REG *) 0xFFFA0060) // (TC1) Status Register
// #define AT91C_TC2_SR ((AT91_REG *) 0xFFFA00A0) // (TC2) Status Register
__readMemory32(0xFFFA0020,"Memory");
__readMemory32(0xFFFA0060,"Memory");
__readMemory32(0xFFFA00A0,"Memory");
for (__mac_i=0;__mac_i < 8; __mac_i++)
{
// AT91C_BASE_AIC->AIC_EOICR
__mac_pt=__readMemory32(0xFFFFF130,"Memory");
}
__message "------------------------------- AIC 2 INIT ---------------------------------------------";
}
/*********************************************************************
*
* execUserReset() : JTAG set initially to Full Speed
*/
execUserReset() {
__message "execUserReset()";
__emulatorSpeed(30000);// Set JTAG speed to 30kHz to make a hardware reset
__hwReset(0); // Hardware Reset: CPU is automatically halted after the reset (JTAG is already configured to 32kHz)
_InitPLL(); // Allow to debug at JTAG Full Speed
_EFC(); // Allow EFC read speed
_InitRSTC(); // Enable User Reset to allow execUserReset() execution
_Watchdog(); // Stop watch dog
_MapFlashAt0(); // Check the flash at 0
AIC();
__emulatorSpeed(0); // Set JTAG speed to full speed
}
/*********************************************************************
*
* execUserPreload() : JTAG set initially to 32kHz
*/
execUserPreload() {
__message "execUserPreload()";
__emulatorSpeed(30000);// Set JTAG speed to 30kHz to make a hardware reset
//*Get the Chip ID (AT91C_DBGU_C1R & AT91C_DBGU_C2R
__mac_i=__readMemory32(0xFFFFF240,"Memory");
__message " -------------------------------- Chip ID 0x",__mac_i:%X;
if ( __mac_i == 0x27280340){__message " Chip ID for AT91SAM7SE32";}
if ( __mac_i == 0x272A0940){__message " Chip ID for AT91SAM7SE256";}
if ( __mac_i == 0x272A0A40){__message " Chip ID for AT91SAM7SE512";}
__mac_i=__readMemory32(0xFFFFF244,"Memory");
__message " Extention 0x",__mac_i:%X;
__mac_i=__readMemory32(0xFFFFFF6C,"Memory");
__message " Flash Version 0x",__mac_i:%X;
__mac_i=__readMemory32(0xFFFFF240,"Memory");
__hwReset(0); // Hardware Reset: CPU is automatically halted after the reset
_InitPLL(); // Allow to load Code at JTAG Full Speed
_EFC(); // Allow EFC read speed
_MapFlashAt0(); // Check the flash at 0
_InitRSTC(); // Enable User Reset to allow execUserReset() execution
_Watchdog(); // Stop watch dog
AIC();
__emulatorSpeed(0); // Set JTAG speed to full speed
}
这是 Cstartup_SAM7.c文件:{:biggrin:}
//-----------------------------------------------------------------------------
// ATMEL Microcontroller Software Support-ROUSSET-
//-----------------------------------------------------------------------------
// DISCLAIMER:THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
// DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
// OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//-----------------------------------------------------------------------------
// File Name : Cstartup_SAM7.c
// Object : Low level initialisations written in C for Tools
// For AT91SAM7SE512 with 2 flash plane
// Creation : JPP09-May-2006
//-----------------------------------------------------------------------------
#include "project.h"
//The following functions must be write in ARM mode this function called
// directly by exception vector
extern void AT91F_Spurious_handler(void);
extern void AT91F_Default_IRQ_handler(void);
extern void AT91F_Default_FIQ_handler(void);
//*----------------------------------------------------------------------------
//* \fn AT91F_LowLevelInit
//* \brief This function performs very low level HW initialization
//* this function can use a Stack, depending the compilation
//* optimization mode
//*----------------------------------------------------------------------------
void AT91F_LowLevelInit(void)
{
unsigned char i;
///////////////////////////////////////////////////////////////////////////
// EFC Init
///////////////////////////////////////////////////////////////////////////
AT91C_BASE_MC->MC0_FMR = AT91C_MC_FWS_2FWS;// 2 Wait State to work at 48MHz
AT91C_BASE_MC->MC1_FMR = AT91C_MC_FWS_2FWS;// 2 Wait State to work at 48MHz
///////////////////////////////////////////////////////////////////////////
// Init PMC Step 1. Enable Main Oscillator
// Main Oscillator startup time is board specific:
// Main Oscillator Startup Time worst case (3MHz) corresponds to 15ms
// (0x40 for AT91C_CKGR_OSCOUNT field)
///////////////////////////////////////////////////////////////////////////
AT91C_BASE_PMC->PMC_MOR = (( AT91C_CKGR_OSCOUNT & (0x40 <<8) | AT91C_CKGR_MOSCEN ));
// Wait Main Oscillator stabilization
while(!(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MOSCS));
///////////////////////////////////////////////////////////////////////////
// Init PMC Step 2.
// Set PLL to 96MHz (96,109MHz) and UDP Clock to 48MHz
// PLL Startup time depends on PLL RC filter: worst case is choosen
// UDP Clock (48,058MHz) is compliant with the Universal Serial Bus
// Specification (+/- 0.25% for full speed)
///////////////////////////////////////////////////////////////////////////
AT91C_BASE_PMC->PMC_PLLR = AT91C_CKGR_USBDIV_1 |
AT91C_CKGR_OUT_0 |
(16 << 8) |
(AT91C_CKGR_MUL & (72 << 16)) |
(AT91C_CKGR_DIV & 14);
// Wait for PLL stabilization
while( !(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_LOCK) );
// Wait until the master clock is established for the case we already
// turn on the PLL
while( !(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY) );
///////////////////////////////////////////////////////////////////////////
// Init PMC Step 3.
// Selection of Master Clock MCK equal to (Processor Clock PCK) PLL/2=48MHz
// The PMC_MCKR register must not be programmed in a single write operation
// (see. Product Errata Sheet)
///////////////////////////////////////////////////////////////////////////
AT91C_BASE_PMC->PMC_MCKR = AT91C_PMC_PRES_CLK_2;
// Wait until the master clock is established
while( !(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY) );
AT91C_BASE_PMC->PMC_MCKR |= AT91C_PMC_CSS_PLL_CLK;
// Wait until the master clock is established
while( !(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY) );
///////////////////////////////////////////////////////////////////////////
//Disable Watchdog (write once register)
///////////////////////////////////////////////////////////////////////////
AT91C_BASE_WDTC->WDTC_WDMR = AT91C_WDTC_WDDIS;
///////////////////////////////////////////////////////////////////////////
//Init AIC: assign corresponding handler for each interrupt source
///////////////////////////////////////////////////////////////////////////
AT91C_BASE_AIC->AIC_SVR = (int) AT91F_Default_FIQ_handler ;
for (i = 1; i < 31; i++) {
AT91C_BASE_AIC->AIC_SVR = (int) AT91F_Default_IRQ_handler ;
}
AT91C_BASE_AIC->AIC_SPU = (unsigned int) AT91F_Spurious_handler;
}
这是LED.c文件{:biggrin:}
#define __inline inline
#include "AT91SAM7SE512.h"
#include "lib_AT91SAM7SE512.h"
#define LED1 (unsigned int)(1<<31) //定义控制LED 的IO;位于PA口的PA1脚
void delay(unsigned int ms)
{
unsigned int i,j;
for(j=0;j<ms;j++)
{
for(i=0;i<500;i++);
}
}
int main(void)
{
//设置LED1和LED2对应的IO为输出
AT91F_PIO_CfgOutput( AT91C_BASE_PIOA, LED1) ;
while(1)
{
AT91F_PIO_ClearOutput( AT91C_BASE_PIOA, LED1); //亮所有LED1
delay(500);
AT91F_PIO_SetOutput( AT91C_BASE_PIOA, LED1); //熄灭LED1
delay(500);
}
}
还请大牛们帮帮忙,看下应该怎么改啊{:tongue:}
页:
[1]