00001 /****************************************************************************** 00002 ** Copyright (C) 2011 Pablo Garcia 00003 ** 00004 ** This library is free software; you can redistribute it and/or 00005 ** modify it under the terms of the GNU Lesser General Public 00006 ** License as published by the Free Software Foundation; either 00007 ** version 2.1 of the License, or (at your option) any later version. 00008 00009 ** This library is distributed in the hope that it will be useful, 00010 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 ** Lesser General Public License for more details. 00013 00014 ** You should have received a copy of the GNU Lesser General Public 00015 ** License along with this library; if not, write to the Free Software 00016 ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00017 ******************************************************************************/ 00018 00019 // -------------------------------------------------------------------------- 00020 // Includes 00021 // -------------------------------------------------------------------------- 00022 #include "flash.h" 00023 00024 // Functions that will be run from RAM need to be assigned to 00025 // a different section. This section will then be mapped to a load and 00026 // run address using the linker cmd file. 00027 00028 #pragma CODE_SECTION(InitFlash, "ramfuncs"); 00029 00030 // This function initializes the Flash Control registers 00031 00032 // CAUTION 00033 // This function MUST be executed out of RAM. Executing it 00034 // out of OTP/Flash will yield unpredictable results 00035 00036 //--------------------------------------------------------------------------- 00037 00038 void InitFlash(void) 00039 { 00040 EALLOW; 00041 //Enable Flash Pipeline mode to improve performance 00042 //of code executed from Flash. 00043 FlashRegs.FOPT.bit.ENPIPE = 1; 00044 00045 // CAUTION 00046 //Minimum waitstates required for the flash operating 00047 //at a given CPU rate must be characterized by TI. 00048 //Refer to the datasheet for the latest information. 00049 #if CPU_FRQ_150MHZ 00050 //Set the Paged Waitstate for the Flash 00051 FlashRegs.FBANKWAIT.bit.PAGEWAIT = 5; 00052 00053 //Set the Random Waitstate for the Flash 00054 FlashRegs.FBANKWAIT.bit.RANDWAIT = 5; 00055 00056 //Set the Waitstate for the OTP 00057 FlashRegs.FOTPWAIT.bit.OTPWAIT = 8; 00058 #endif 00059 00060 #if CPU_FRQ_100MHZ 00061 //Set the Paged Waitstate for the Flash 00062 FlashRegs.FBANKWAIT.bit.PAGEWAIT = 3; 00063 00064 //Set the Random Waitstate for the Flash 00065 FlashRegs.FBANKWAIT.bit.RANDWAIT = 3; 00066 00067 //Set the Waitstate for the OTP 00068 FlashRegs.FOTPWAIT.bit.OTPWAIT = 5; 00069 #endif 00070 // CAUTION 00071 //ONLY THE DEFAULT VALUE FOR THESE 2 REGISTERS SHOULD BE USED 00072 FlashRegs.FSTDBYWAIT.bit.STDBYWAIT = 0x01FF; 00073 FlashRegs.FACTIVEWAIT.bit.ACTIVEWAIT = 0x01FF; 00074 EDIS; 00075 00076 //Force a pipeline flush to ensure that the write to 00077 //the last register configured occurs before returning. 00078 00079 asm(" RPT #7 || NOP"); 00080 } 00081 00082 //--------------------------------------------------------------------------- 00083 00084 00085 //----------------------------------------------------------------------------- 00086 // End Of File 00087 //-----------------------------------------------------------------------------