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

📄 evalstb3.c

📁 boot loader示范程序
💻 C
📖 第 1 页 / 共 2 页
字号:
/* Flash programming routines for 4MBytes FLASH provided by M28F411 devices
 * in a STB3EVAL box: TP3 & MC2 
 **************************************************************************
 */

#include <string.h>
#include <debug.h>
#include "flashprg.h"

#define FLASH_TIMEOUT           300000       /* Approx. timeout for erase/program */

/* =============================General defines================================ */
/*
 * Macros to handle various levels of reporting to screen and logfile
 */

#define         MFR_ID_1        0x89898989          /* Intel mfr_id for 4 chips    */
#define         DEV_ID_1        0x79797979          /* Intel 28F004BX-BL dev_id for 4 chips */
#define         DEV_ID_2        0x78787878          /* Intel 28F004BX-TL dev_id for 4 chips     */

#define         MFR_ID_2        0x20202020          /* SGS-THOMSON mfr_id           */
#define         DEV_ID_3        0xf6f6f6f6          /* ST M28F411                   */
#define         DEV_ID_4        0xf2f2f2f2          /* ST M28F410                   */

/* for some reason the STB3EVAL uses same Vp switch location as PaulE's board */
#ifndef PAULS_BOARD
  #define         VPP_ENABLE_0    0x50d00000                  /* Vpp Enable address FlashRom bank 0    */
  #define         VPP_ENABLE_1    0x50e00000                  /* Vpp Enable address FlashRom bank 1    */
#else /* STBEVAL3 */
  #define         VPP_ENABLE_0    0x50340000                  /* Vpp Enable address FlashRom bank 0    */
  #define         VPP_ENABLE_1    0x50380000                  /* Vpp Enable address FlashRom bank 1    */
#endif

#define         VPP_HIGH        0xffffffff                  /* value to be written to set Vpp high   */
#define         VPP_LOW         0x00000000                  /* value to be written to set Vpp low    */
#define         VPP_DELAY       100 /* was 2  peva 15/5/98 */                             /* Delay period in st20 ticks */

#define         PEC_READY_L     0x80808080          /* b6 indicates the P/E.C status as ready */
#define         PEC_READY_B     0x00000080          /* b6 indicates the P/E.C status as ready */
#define         VPP_STATUS      0x08080808          /* b3 indicates Vpp Satus                 */


/* ===========  Flash chip id addreses   ==================== */

#define         MFGID_OFFSET    0                           /* manufacturer's id address */
#define         DEVID_OFFSET    1                       /* device id address */

/* ===========  Flash top boot block  version  ============ */

#define         BANK_SIZE       0x200000            /* Size of a memory bank - 2Mb */

#define         BANK_1_BOT      0x7fc00000
#define         BANK_1_TOP      (BANK_1_BOT -1 + BANK_SIZE )
#define         BANK_0_BOT      0X7fe00000
#define         BANK_0_TOP      (BANK_0_BOT -1 + BANK_SIZE )

/* ============= Block Offsets within the flash memory space ==============*/

#define         MBLK1_OFFSET    0x000000            /* start main_blk_1  */
#define         MBLK2_OFFSET    0x080000            /* start main_blk_2  */
#define         MBLK3_OFFSET    0x100000            /* start main_blk_3  */
#define         MBLK4_OFFSET    0x1c0000            /* start main_blk_4  */
#define         PBLK1_OFFSET    0x1e0000            /* start para_blk_1  */
#define         PBLK2_OFFSET    0x1e8000            /* start para_blk_2  */
#define         BTBLK_OFFSET    0x1f0000            /* start boot_blk    */

/* =============================Flash cui_commands defines=================== */

#define         ERASE_SETUP     0x20202020          /* erase_setup command          */
#define         ERASE_CONFIRM   0xd0d0d0d0          /* erase_confirm command        */
#define         ERASE_SUSPEND   0xb0b0b0b0          /* erase_suspend command        */
#define         ERASE_RESUME    0xd0d0d0d0          /* erase_confirm command        */
#define         PROGRAM_SETUP   0x40404040          /* program_setup command        */
#define         CLEAR_SREG      0x50505050          /* clear status_reg command     */
#define         READ_SREG       0x70707070          /* read status_reg command      */
#define         READ_IDENT      0x90909090          /* read flash_rom ident command */
#define         READ_ARRAY      0xffffffff          /* read flash_rom_array command */


void ProcWait( int timeDelay )
{
  int i, j, k;
  for (i=0; i<timeDelay; i++) {
    for (j=0; j<5; j++) {
      k++ ;
    }
  }
}

/************************************************************************
Function    : ReturnBankId
Description : Calculates the flash bank from the address.

Returns     : 0 or 1 for the bank. 
************************************************************************/
UBYTE ReturnBank (ULONG address)
{
   UBYTE bank = 99;

   if ((address >= (ULONG) BANK_0_BOT) && (address <= (ULONG) BANK_0_TOP)) {
      bank = 0;
   }
   else if ((address >= (ULONG)BANK_1_BOT) && (address <= (ULONG)BANK_1_TOP)) {
      bank = 1;
   }

   return bank;
}

/************************************************************************
Function    : VppHigh
Description : Sets Vpp High .

Returns     : No return value.
************************************************************************/
void VppHigh(ULONG address)
{
   volatile ULONG* ep;
   switch (ReturnBank ( address)) {

      case 0 : ep  = (ULONG*)VPP_ENABLE_0; 
	       *ep = (ULONG) VPP_HIGH;     
			   break;

      case 1 : ep  = (ULONG*)VPP_ENABLE_1; 
	       *ep = (ULONG) VPP_HIGH;     
			   break;
      default: break;
   }
}

/************************************************************************
Function    : VppLow
Description : Sets Vpp LOW .

Returns     : No return value.
************************************************************************/
void VppLow(ULONG address)
{
   volatile ULONG* ep;

   switch (ReturnBank ( address)) {

      case 0 : ep  = (ULONG*)VPP_ENABLE_0; 
	       *ep = (ULONG) VPP_LOW;      
			   break;
      case 1 : ep  = (ULONG*)VPP_ENABLE_1; 
	       *ep = (ULONG) VPP_LOW;      
			   break;
      default: break;
   }
}

void RomClearupSTB3()
{
  /* Switch off the Vpp lines if fatal error detected */
  VppLow ((ULONG) BANK_0_BOT);
  ProcWait (VPP_DELAY);                        /* delay for about 1s */

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

/************************************************************************
Function    : check_idents
Description : Provides the manufacturing and device id of a bank of flash. 

Returns     : The manufacturer ID 
************************************************************************/
int check_idents (ULONG address)
{
   ULONG     *memory_p;
   int       mfr_id, dev_id;         /* read_back identification values      */
   BYTE      bank;

   FULL_REP_MSG((printBuf, "Checking Flash Identifiers...\n"));

   bank = ReturnBank (address);

   if ((bank==0) || (bank==1)) {
      if (bank ==0)
	  memory_p  = (ULONG*)BANK_0_BOT + MFGID_OFFSET; 
      else
	  memory_p  = (ULONG*)BANK_1_BOT + MFGID_OFFSET; 

      *memory_p = READ_IDENT;                  /* write read_ident command           */

      mfr_id    = (int) *memory_p;             /* read mfr_id                        */
      memory_p  = memory_p + DEVID_OFFSET; 
      dev_id    = (int) *memory_p;             /* read dev_id                        */
   } 

   FULL_REP_MSG((printBuf, "Manufacturer_ID = %x, Device_ID %x\n", mfr_id, dev_id));

   if (!(((mfr_id == MFR_ID_1) && (dev_id == DEV_ID_2)) ||
	 ((mfr_id == MFR_ID_2) && (dev_id == DEV_ID_3)) )) {
      FULL_REP_MSG((printBuf, "Error detected in Flash Identifiers..\n"));
      return FALSE ;
   }
   else {
      /* OK - flash_id's are those expected   */
      FULL_REP_MSG((printBuf, "Flash Identifiers are recognised, OK.\n"));
   }
   return TRUE ;
}

/************************************************************************
Function    : EraseSector
Description : Derived from HDI function ....EraseSector. Erases the sector
	      or block of Flash containing the byte pointed to by the 
	      flash_data_p.  A flash chip contains several such blocks.

Returns     : Boolean False - failed, True - successful.
************************************************************************/

int EraseSector(UBYTE *flash_data_p)
{
   volatile ULONG* sector_p;
   int             timeout  = FLASH_TIMEOUT;

   VppHigh ((ULONG)  flash_data_p);
   ProcWait (VPP_DELAY);                      /* delay for settling */

   sector_p = (ULONG*) flash_data_p;          /* point to block_start_add for erase        */
   *sector_p = CLEAR_SREG;                    /* clear status_register command            */
   *sector_p = ERASE_SETUP;                   /* write erase_setup command for block      */
   *sector_p = ERASE_CONFIRM;                 /* write erase_confm command for block      */
   *sector_p = READ_SREG;                     /* read status_register setup command       */


   while (((*sector_p  & PEC_READY_L) != PEC_READY_L) && (timeout > 0)){
      ProcWait(1);
      timeout--;                                  
   }

   if (timeout == 0 ) {
      FULL_REP_MSG((printBuf, "Timeout error in Flash erase\n"));
      return FALSE ;
   } 
   if ((*sector_p & VPP_STATUS) != 0x00){      /* test s_reg vpp_error_flag                */
     if (*sector_p == 0xa8a8a8a8){
	     FULL_REP_MSG((printBuf, "\nVPP level to ALL flash devices, not present in this bank\n"));
    	 FULL_REP_MSG((printBuf, "         Check the level on the board. Check the VPP level switch circuit\n"));
       return FALSE ;
  	 }
     if (*sector_p == 0xa8808080){
	     FULL_REP_MSG((printBuf, "\nVPP level to BYTE 3 flash device, not present\n"));
       return FALSE ;
	   }

⌨️ 快捷键说明

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