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

📄 evalstb3.c

📁 boot loader示范程序
💻 C
📖 第 1 页 / 共 2 页
字号:
     if (*sector_p == 0x80a88080){
 	     FULL_REP_MSG((printBuf, "\nVPP level to BYTE 2 flash device, not present\n"));
       return FALSE ;
	   }
     if (*sector_p == 0x8080a880){
       FULL_REP_MSG((printBuf, "\nVPP level to BYTE 1 flash device, not present\n"));
       return FALSE ;
     }
     if (*sector_p == 0x808080a8){
       FULL_REP_MSG((printBuf, "\nVPP level to BYTE 0 flash device, not present\n"));
       return FALSE ;
     }
   }

   if ((*sector_p & 0x10101010) != 0x00){      /* test s_reg comseq_error_flag             */
      FULL_REP_MSG((printBuf, "Command_Error in Flash erase\n"));
      return FALSE ;
   }

   if ((*sector_p & 0x20202020) != 0x00){      /* test s_reg comseq_error_flag */
      FULL_REP_MSG((printBuf, "Block_Erase_Error in Flash erase\n"));
      return FALSE ;
   }

   if ((*sector_p & 0x40404040) != 0x00){      /* test s_reg ers_suspend_flag  */
      FULL_REP_MSG((printBuf, "Erase_Suspend in Flash erase\n"));
      return FALSE ;
   }

   VppLow ((ULONG) flash_data_p);
   ProcWait (VPP_DELAY);                      /* delay for about 1s */

  return TRUE;
}

/************************************************************************
Function    : EraseFlashBank
Description : Erases the entire contents of a bank of flash memory. Erasure 
	      of the 28F411-TL Flash is achieved by using the automated 
	      erase routine, which erases entire blocks in one instruction, 
	      and (using the status register) flags any errors. Erase  
	      verification (data = FFh) begins at rom_address 0 and continues 
	      through the array to the last address, or until data other than
	      FFh is encountered.

	      Derived from HDI function ....EraseInactiveFlash

Returns     : Returns False - failed, True - OK;
************************************************************************/

int EraseFlashBank(int Bank )
{
   volatile UBYTE *BankBase;
   int      offset;
   volatile UBYTE  *mem_p;
   ULONG    mem_pl;                        /* used to avoid pointer overflow */

   if ((Bank != 0) && (Bank != 1 )) {

      FULL_REP_MSG((printBuf, "Error in Flash Erase \n"));
      FULL_REP_MSG((printBuf, "Invalid Bank No. \n"));
      return FALSE ;
   }
   else {
      /* Check the idents then erase each sector/block in turn. */  
      /* check idents does not return if in error               */

      if (Bank == 0){
        FULL_REP_MSG((printBuf, "\nErasing BANK 0\n"));
        BankBase = (UBYTE*)BANK_0_BOT;
      }
      else {
        BankBase = (UBYTE*)BANK_1_BOT;
        FULL_REP_MSG((printBuf, "\nErasing BANK 1\n"));
      }

      if (!check_idents( (ULONG) BankBase))
        return FALSE ;

      /* Erase each sector of the memory in turn */

      FULL_REP_MSG((printBuf, "Starting Flash Erase\n"));

      FULL_REP_MSG((printBuf, "Erasing Main Block 1\n"));
      if (!EraseSector((UBYTE*) (BankBase+ MBLK1_OFFSET)))
        return FALSE ;

      FULL_REP_MSG((printBuf, "Erasing Main Block 2\n"));
      if (!EraseSector((UBYTE*) (BankBase+MBLK2_OFFSET)))
        return FALSE ;

      FULL_REP_MSG((printBuf, "Erasing Main Block 3\n"));
      if (!EraseSector((UBYTE*) (BankBase+MBLK3_OFFSET)))
        return FALSE ;

      FULL_REP_MSG((printBuf, "Erasing Main Block 4\n"));
      if (!EraseSector((UBYTE*) (BankBase+MBLK4_OFFSET)))
        return FALSE ;

      FULL_REP_MSG((printBuf, "Erasing Parameter Block 1\n"));
      if (!EraseSector((UBYTE*) (BankBase+PBLK1_OFFSET)))
        return FALSE ;

      FULL_REP_MSG((printBuf, "Erasing Parameter Block 2\n"));
      if (!EraseSector((UBYTE*) (BankBase+PBLK2_OFFSET)))
        return FALSE ;

      FULL_REP_MSG((printBuf, "Erasing Top Boot Block\n"));
      if (!EraseSector((UBYTE*) (BankBase+ BTBLK_OFFSET)))
        return FALSE ;

      FULL_REP_MSG((printBuf, "Flash erased with no errors..\n"));
 
      /* =====================check array is erased================== */

      mem_pl = (ULONG) BankBase;

      FULL_REP_MSG((printBuf, "Checking array is erased."));
      for (offset = 0; offset < BANK_SIZE; offset++) {
	      mem_p  = (UBYTE*) mem_pl;
	      *mem_p = (UBYTE) READ_ARRAY;
	      if (((UBYTE) *mem_p) != (UBYTE) 0xff){       /* check all bits are set to 1          */
          FULL_REP_MSG((printBuf, "ERRORS in Flash ERASE.\n"));
          return FALSE ;
	      }
	      mem_pl++;   /* ulong can wrap around but not pointers */
      }

      FULL_REP_MSG((printBuf, "\nFlash is fully erased and verified.\n"));
   }        
   return TRUE ;
}

int EraseFlashSTB3()
{
  if (!EraseFlashBank(0))
    return FALSE ;
  FULL_REP_MSG((printBuf, "Bank 0 Flash erased\n"));
  if (!EraseFlashBank(1))
    return FALSE ;
  FULL_REP_MSG((printBuf, "Bank 1 Flash erased\n"));
  return TRUE ;
}

/************************************************************************
Function    : ProgramFlash
Description : Programs a block of flash memory.  For simplicity it assumes
	      programming is perfromed on a byte by byte basis rather than
	      by a 32 bit access to memory however this gets round any
	      possible differences in chip performance.  It takes longer of
	      course. 

	      Derived from HDI function ....ProgramFlash

Returns     : Returns False - failed, True - OK;
************************************************************************/

int  ProgramFlashSTB3(UINT32 flash_addr,UBYTE *  source_data_p, ULONG length )
{
   volatile UBYTE* fp;                  /* ptr to position in flash */
   volatile UBYTE* sp;                  /* ptr to the source data   */
   ULONG fpl;
   int timeout;
   int index;

   if (length > 0){  /* length must be 1 or above */ 
      /* Enable Vpp now then program the specified number of bytes        */
      /* The programming could be speeded up by relocating the VppHigh    */
      /* and VppLow to before and after the entire programming operation. */

      VppHigh (flash_addr);
      ProcWait (VPP_DELAY);

      fpl = (ULONG)flash_addr;
      sp  = (UBYTE*)source_data_p ; 

      for (index = 0 ; index < length ; index += 1)  {
	      timeout = FLASH_TIMEOUT;
        fp = (UBYTE*)fpl;
        *fp = (UBYTE)CLEAR_SREG;                   /* clear status_register command        */
        *fp = (UBYTE)READ_SREG;                    /* read status_register setup command   */
        *fp = (UBYTE)PROGRAM_SETUP;                /* setup write word                     */
        *fp = (UBYTE)*sp;                          /* write byte to addressed location     */
        *fp = (UBYTE)READ_SREG;                    /* read status_register setup command   */

        while (((*fp  & PEC_READY_B) != PEC_READY_B) && (timeout > 0)){
          ProcWait(1);
          timeout--;
        }
        if (timeout == 0 ) {
          FULL_REP_MSG((printBuf, "Timeout error in Flash Program\n"));
          return FALSE ;
	      } 
	      if ((*fp & VPP_STATUS) != 0x00){        
          FULL_REP_MSG((printBuf, "VPP_Error detected, when programming 0x%x\n",(unsigned int)fp));
          return FALSE ;
        }
        if ((*fp & 0x10101010) != 0x00){        
          FULL_REP_MSG((printBuf, "Program_Error detected, when programming 0x%x\n",(unsigned int)fp));
          return FALSE ;
        }            
        *fp = (UBYTE)READ_ARRAY;   /* verify that the byte in flash is what we wanted to put there */

        if (*fp != *sp){            
          FULL_REP_MSG((printBuf, "Read_Error detected, when programming 0x%x\n",(unsigned int)fp));
          return FALSE ;
        } 
        sp++;               
        fpl++;               

      }      /* each byte */
   } /* for length */

   VppLow (flash_addr);
   return TRUE;
}

/************************************************************************
Function    : VerifyFlash
Description : Verifies a block of flash memory.  For simplicity it verifies 
	      on a pbyte by byte basis. 


Returns     : Returns False - failed, True - OK;
************************************************************************/

int  VerifyFlashSTB3(UINT32 flash_addr, UBYTE *  source_data_p, ULONG length )

{
   volatile UINT32* fpl = (UINT32*) flash_addr;     /* ptr to position in flash */
   volatile UBYTE*  fp  = (UBYTE*)  flash_addr;     /* ptr to position in flash */
   volatile UBYTE*  sp  = (UBYTE*)  source_data_p;  /* ptr to the source data   */

   *fpl = READ_ARRAY;     

   if (length > 0){  /* length must be 1 or above */ 
      for (; length>0 ; length-=1)  {
        if (*fp != *sp) { 
          FULL_REP_MSG((printBuf, "verify FAILED for address 0x%x: read 0x%x : expected 0x%x\n",(unsigned int)fp, *fp, *sp));
          FULL_REP_MSG((printBuf, "\n"));
          return FALSE ;
        } 
        sp++;               
        fp++;
      } /* each byte */
   } /* for length */
   return TRUE ;
}

⌨️ 快捷键说明

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