首页 | 新闻 | 新品 | 文库 | 方案 | 视频 | 下载 | 商城 | 开发板 | 数据中心 | 座谈新版 | 培训 | 工具 | 博客 | 论坛 | 百科 | GEC | 活动 | 主题月 | 电子展
返回列表 回复 发帖

P128 flash擦写,请斑竹指教啊

P128 flash擦写,请斑竹指教啊

P128的flash擦写,擦写的过程完全按照手册上的流程图来做的。擦写FLASH的函数COPY到RAM运行的,RPM文件中用RELOCATE to重定位到RAM中的方法实现跳转。程序烧写到片子后,有时莫名其妙的跑飞。
unsigned char FlashWriteWordGlobalAdd(unsigned int *far far_address, unsigned int data)
{
        unsigned char errflag = ERR_OK;
        unsigned long GlobalAdd;
        unsigned char i ;


        /* misaligned address */
        if((unsigned long)far_address & 0x00000001u)
        {
                return ERR_RANGE;
        }

        /* test CBEIF flag to ensure that address/data/command buffers are empty.*/
        while ((FSTAT & 0x80) != 0x80)
        {
            ;
        }
       
        /* check ACCERR and PVIOL is set */
        if(FSTAT & 0x30 != 0x00)
        {
                /* verify all ACCERR and PVIOL flag in the FSTAT are cleared. */
                FSTAT = FSTAT_FPVIOL_MASK|FSTAT_ACCERR_MASK;  
        }

        GlobalAdd = (unsigned long)far_address & 0xfffffff8; /* clear lowest 3 bits address */

        /* write sector erase P-FLASH command to registers */
        FCCOBIX = 0x00;
        FCCOBHI = FLASH_CMD_PROGRAM_PFLASH;
        FCCOBLO = ((unsigned char)(GlobalAdd >> 16))  & 0x03; /* global address[17:16]*/
       
        /* write  erased address to registers */
        FCCOBIX = 0x01;
        FCCOB = (unsigned int)(GlobalAdd) ;

        /* write 4 int data to flash */
        for(i = 0x00; i < 0x04; i++)
        {
                FCCOBIX = i + 0x02;       
                if(GlobalAdd == (unsigned long)far_address)
                {
                        FCCOB = data;       
                }
                else
                {
                        FCCOB = *((unsigned int *far) (GlobalAdd ));               
                }

                GlobalAdd += 2;
               
        }

        FSTAT |= 0x80;
       
        /* test CBEIF flag to ensure that address/data/command buffers are empty.*/
        while ((FSTAT & 0x80) != 0x80)
        {
            ;
        }
       
        return errflag;
}

/*****************************************************************************
* Function Name   : FlashEraseSectorGlobalAdd
* Description     : Erases a given Flash sector using global address
*                   passed from calling function.
*
******************************************************************************/
unsigned char FlashEraseSectorGlobalAdd(unsigned int *far far_address)
{  
        unsigned char errflag = ERR_OK;
        unsigned long GlobalAdd;

        GlobalAdd = (unsigned long)far_address;
               
        /* test CBEIF flag to ensure that address/data/command buffers are empty.*/
        while ((FSTAT & 0x80) != 0x80)
        {
            ;
        }

        /* check ACCERR and PVIOL is set */
        if(FSTAT & 0x30 != 0x00)
        {
                /* verify all ACCERR and PVIOL flag in the FSTAT are cleared. */
                FSTAT = FSTAT_FPVIOL_MASK|FSTAT_ACCERR_MASK;  
        }
               
        /* write sector erase P-FLASH command to registers */
        FCCOBIX = 0x00;
        FCCOBHI = FLASH_CMD_ERASE_PFLASH_SECTOR;
        FCCOBLO = ((unsigned char)(GlobalAdd >> 16))  & 0x03; /* global address[17:16]*/

        /* write  erased address to registers */
        FCCOBIX = 0x01;
        FCCOB = (unsigned int)GlobalAdd;

        FSTAT |= 0x80;
       
        /* test CBEIF flag to ensure that address/data/command buffers are empty.*/
        while ((FSTAT & 0x80) != 0x80)
        {
            ;
        }
       
        return errflag;
       
}

上面是擦一个sector和写一个字的程序,各位帮忙看看,有什么问题,下面再把PRM文件和主程序发上来
void main(void)
{
  unsigned int data = 0X5577;
   unsigned int data1 = 0X1122;
  unsigned char *page;
  unsigned int *address;

  init_target();
  
#if FLASH_COPYTO_RAM == 1
        copy_to_ram((unsigned char*)FLASH_RAM_ADD, (unsigned char*)0xF900u, FLASH_RAM_LENGTH);
#endif

  FlashInit(0x00);
  
  ConvertGlobalToPageFlash(0x33f00,page,address);
  
  FlashEraseSectorGlobalAdd((unsigned int *far)0x33f00);
  
  FlashWriteWordGlobalAdd((unsigned int *far)0x33f00,data);
  
  FlashErase((unsigned int *far)0x33000,10);

  


  for(;;)
  {
    //FlashEraseSectorGlobalAdd((unsigned int *far)0x33f00);
  
    //FlashWriteWordGlobalAdd((unsigned int *far)0x33f00,data);
   
    wait_for_1ms(10);

  }
  
}
这是主程序,先把FLASH驱动拷贝到RAM中。
SEGMENTS  /* Here all RAM/ROM areas of the device are listed. Used in PLACEMENT below. */

/* Register space  */
/*    IO_SEG        = PAGED         0x0000 TO   0x03FF; intentionally not defined */

/* RAM */
      RAM           = READ_WRITE    0x3000 TO   0x3FFF;

/* D-Flash */
      DFLASH        = READ_ONLY   0x010400 TO 0x0113FF;

/* non-paged FLASHs */
      ROM_1400      = READ_ONLY     0x1400 TO   0x27FF;
      ROM_4000      = READ_ONLY     0x4000 TO   0x7FFF;
      ROM_C000      = READ_ONLY     0xC000 TO   0xf8ff;
      
      BOOT_SEGMENT  = READ_ONLY  0xf900 TO 0xFEFF RELOCATE_TO 0x2800;   //1228 Bytes
/*   VECTORS       = READ_ONLY     0xFF00 TO   0xFFFF; intentionally not defined: used for VECTOR commands below */
   //OSVECTORS      = READ_ONLY     0xFF8C TO   0xFFFF;   /* OSEK interrupt vectors (use your vector.o) */

/* paged FLASH:                     0x8000 TO   0xBFFF; addressed through PPAGE */
      PAGE_08       = READ_ONLY   0x088000 TO 0x08BFFF;
      PAGE_09       = READ_ONLY   0x098000 TO 0x09BFFF;
      PAGE_0A       = READ_ONLY   0x0A8000 TO 0x0ABFFF;
      PAGE_0B       = READ_ONLY   0x0B8000 TO 0x0BBFFF;
      PAGE_0C       = READ_ONLY   0x0C8000 TO 0x0C93FF;
      PAGE_0C_A800  = READ_ONLY   0x0CA800 TO 0x0CBFFF;
      PAGE_0E       = READ_ONLY   0x0E8000 TO 0x0EBFFF;
/*    PAGE_0D       = READ_ONLY   0x0D8000 TO 0x0DBFFF; not used: equivalent to ROM_4000 */
/*    PAGE_0F       = READ_ONLY   0x0F8000 TO 0x0FBEFF; not used: equivalent to ROM_C000 */
END

PLACEMENT /* here all predefined and user segments are placed into the SEGMENTS defined above. */
      _PRESTART,              /* Used in HIWARE format: jump to _Startup at the code start */
      STARTUP,                /* startup data structures */
      ROM_VAR,                /* constant variables */
      STRINGS,                /* string literals */
      VIRTUAL_TABLE_SEGMENT,  /* C++ virtual table segment */
    //.ostext,                /* OSEK */
      NON_BANKED,             /* runtime routines which must not be banked */
      COPY                    /* copy down information: how to initialize variables */
                              /* in case you want to use ROM_4000 here as well, make sure
                                 that all files (incl. library files) are compiled with the
                                 option: -OnB=b */
                        INTO  ROM_C000/*, ROM_1400, ROM_4000*/;

BOOT_SEGMENT  = READ_ONLY  0xf900 TO 0xFEFF RELOCATE_TO 0x2800;   //1228 Bytes这个是把FLASH的驱动的存储位置,然后重定位到RAM的地址是0x2800

      DEFAULT_ROM       INTO  /*PAGE_08, PAGE_09, PAGE_0A, PAGE_0B, PAGE_0C, PAGE_0C_A800,*/ PAGE_0E                  ;

    //.stackstart,            /* eventually used for OSEK kernel awareness: Main-Stack Start */
      SSTACK,                 /* allocate stack first to avoid overwriting variables on overflow */
    //.stackend,              /* eventually used for OSEK kernel awareness: Main-Stack End */
    DEFAULT_RAM         INTO  RAM;
    BOOT_SEG            INTO  BOOT_SEGMENT;

  //.vectors            INTO  OSVECTORS; /* OSEK */
END


STACKSIZE 0x100

VECTOR 0 _Startup /* reset vector: this is the default entry point for a C/C++ application. */
//VECTOR 0 Entry  /* reset vector: this is the default entry point for an Assembly application. */
//INIT Entry      /* for assembly applications: that this is as well the initialization entry point */
p1水货现在好像没新机了都是翻新机除了少许的行货,价格大概在2300左右水货1650吧
LS的啥子意思
将代码写入到RAM中然后跳转到RAM中执行此代码,都是需要程序运行来做的事情,用PRM文件是实现不了的。
海纳百川  有容乃大
BOOT_SEGMENT  = READ_ONLY  0xf900 TO 0xFEFF RELOCATE_TO 0x2800;   //1228 Bytes这个是把FLASH的驱动的存储位置,然后重定位到RAM的地址是0x2800

程序里面实现跳转到RAM地址呢
斑竹,怎么实现写P-FLASH只写一个字呢?一般调用一次写命令写8个字节,我现在想实现写一个字,怎么实现啊
返回列表