⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sam7_flash.mac

📁 AT91SAM7SE系列IAR编程中外扩NAND的源码。
💻 MAC
字号:
//-----------------------------------------------------------------------------
//          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)  );
}

/*********************************************************************
*
*       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
    __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
    __emulatorSpeed(0);      // Set JTAG speed to full speed

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -