21ic电子技术开发论坛 单片机与嵌入式系统 ARM技术论坛 参考论坛上一个帖子用ULINK烧写AM29LV160DB成功
发新帖我要提问
返回列表
打印

参考论坛上一个帖子用ULINK烧写AM29LV160DB成功

[复制链接]
4798|6
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
微风|  楼主 | 2007-5-11 22:58 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
发个修改后可用的程序来,请大家指正。

使用方法,在keil安装目录中的ARMFLASH目录中新建一个目录,从FLASH目录下的其他目录(如AM29F160DB)中拷贝所有文件到这个新建的目录中,然后修改项目名称。打开项目,将里面的FlashPrg.C和FlashDev.C替换掉,修改项目option中的output的名字和user中的文件名,编译后就可以选择使用AM29LV160DB了。
/***********************************************************************/
/*  This file is part of the ARM Toolchain package                     */
/*  Copyright KEIL ELEKTRONIK GmbH 2003 - 2004                         */
/***********************************************************************/
/*                                                                     */
/*  FlashPrg.C:  Flash Programming Functions adapted                   */
/*               for AM29LV160DB (16-bit Bus)                           */
/*                                                                     */
/***********************************************************************/

#include "..FlashOS.H"        // FlashOS Structures

#define M8(adr)  (*((volatile unsigned char  *) (adr)))
#define M16(adr) (*((volatile unsigned short *) (adr)))
#define M32(adr) (*((volatile unsigned long  *) (adr)))

#define STACK_SIZE   64        // Stack Size


union fsreg {                  // Flash Status Register
  struct b  {
    unsigned int q0:1;
    unsigned int q1:1;
    unsigned int q2:1;
    unsigned int q3:1;
    unsigned int q4:1;
    unsigned int q5:1;
    unsigned int q6:1;
    unsigned int q7:1;
  } b;
  unsigned int v;
} fsr;

unsigned long base_adr;


/*
* Check if Program/Erase completed
*    Parameter:      adr:  Block Start Address
*    Return Value:   0 - OK,  1 - Failed
*/

/*int Polling (unsigned long adr) {
  unsigned int q6;

  fsr.v = M16(adr);
  q6 = fsr.b.q6;
  do {
    fsr.v = M16(adr);
    if (fsr.b.q6 == q6) return (0);  // Done
    q6 = fsr.b.q6;
  } while (fsr.b.q5 == 0);           // Check for Timeout
  fsr.v = M16(adr);
  q6 = fsr.b.q6;
  fsr.v = M16(adr);
  if (fsr.b.q6 == q6) return (0);    // Done
  M16(adr) = 0xF0;                   // Reset Device
  return (1);                        // Failed
} */
int Polling (unsigned long adr) {
  unsigned int q6;

  // Check Toggle Bit
  do {
    fsr.v = M16(adr);
    q6 = fsr.b.q6;
    fsr.v = M16(adr);
  } while (fsr.b.q6 != q6);
  return (0);                  // Done
}


/*
*  Initialize Flash Programming Functions
*    Parameter:      adr:  Device Base Address
*                    clk:  Clock Frequency (Hz)
*    Return Value:   0 - OK,  1 - Failed
*/

int Init (unsigned long adr, unsigned long clk,unsigned long fnc)  {
  base_adr = adr;
  return (0);
}


/*
*  De-Initialize Flash Programming Functions
*    Return Value:   0 - OK,  1 - Failed
*/

int UnInit (unsigned long fnc) {
  return (0);
}


/*
*  Erase complete Flash Memory 
*    Return Value:   0 - OK,  1 - Failed
*/

int EraseChip (void) {

  // Start Chip Erase Command
  M16(base_adr + (0x555<<1)) = 0xAA;
  M16(base_adr + (0x2AA<<1)) = 0x55;
  M16(base_adr + (0x555<<1)) = 0x80;
  M16(base_adr + (0x555<<1)) = 0xAA;
  M16(base_adr + (0x2AA<<1)) = 0x55;
  M16(base_adr + (0x555<<1)) = 0x10;

  return (Polling(base_adr));  // Wait until Erase completed
}


/*
*  Erase Sector in Flash Memory
*    Parameter:      adr:  Sector Address
*    Return Value:   0 - OK,  1 - Failed
*/

int EraseSector (unsigned long adr) {

  // Start Erase Sector Command
  M16(base_adr + (0x555<<1)) = 0xAA;
  M16(base_adr + (0x2AA<<1)) = 0x55;
  M16(base_adr + (0x555<<1)) = 0x80;
  M16(base_adr + (0x555<<1)) = 0xAA;
  M16(base_adr + (0x2AA<<1)) = 0x55;
  M16(adr) = 0x30;

  do {
    fsr.v = M16(adr);
  } while (fsr.b.q3 == 0);     // Wait for Sector Erase Timeout

  return (Polling(adr));       // Wait until Erase completed
}


/*
*  Program Page in Flash Memory
*    Parameter:      adr:  Page Start Address
*                    sz:   Page Size
*                    buf:  Page Data
*    Return Value:   0 - OK,  1 - Failed
*/

int ProgramPage (unsigned long adr, unsigned long sz, unsigned char *buf) {
  int i;

  for (i = 0; i < ((sz+1)/2); i++)  {
    // Start Program Command
    M16(base_adr + (0x555<<1)) = 0xAA;
    M16(base_adr + (0x2AA<<1)) = 0x55;
    M16(base_adr + (0x555<<1)) = 0xA0;
    M16(adr) = *((unsigned short *) buf);
    if (Polling(adr) != 0) return (1);
    buf += 2;
    adr += 2;
  }
  return (0);
}


/***********************************************************************/
/*  This file is part of the ARM Toolchain package                     */
/*  Copyright KEIL ELEKTRONIK GmbH 2003 - 2004                         */
/***********************************************************************/
/*                                                                     */
/*  FlashDev.C:  Device Description for AM29LV160DB (16-bit Bus)        */
/*                                                                     */
/***********************************************************************/

#include "..FlashOS.H"        // FlashOS Structures


struct FlashDevice const FlashDevice  =  {
   FLASH_DRV_VERS,             // Driver Version, do not modify!
   "AM29LV160DB Flash",         // Device Name
   EXT16BIT,                   // Device Type
   0x000000,                   // Device Start Address
   0x200000,                   // Device Size in Bytes (2MB)
   1024,                       // Programming Page Size
   0,                          // Reserved, must be 0
   0xFF,                       // Initial Content of Erased Memory
   100,                        // Program Page Timeout 100 mSec
   3000,                       // Erase Sector Timeout 3000 mSec

// Specify Size and Address of Sectors
   0x10000, 0x000000,          // Sector Size 64kB (31 Sectors)
   0x08000, 0x1F0000,          // Sector Size 32kB (1 Sector)
   0x02000, 0x1F8000,          // Sector Size  8kB (2 Sectors)
   0x04000, 0x1FC000,          // Sector Size 16kB (1 Sector)
   SECTOR_END
};

相关帖子

沙发
computer00| | 2007-5-11 23:15 | 只看该作者

keil不是本来就可以通过Ulink烧29LV160DB吗?

我没有搞什么程序,直接选择一个FLASH型号就可以烧了。然后我在我自己的程序里,
写了一个IAP 29LV160DB的,先要把自己复制到RAM,然后再对FLASH编程,这样就可以通过
网口或者串口烧录程序了。

我是拿网上下载的44B0 的BIOS修改的,原来的FLASH好象是39LV什么的。


参看:


http://computer00.21ic.org/user1/2198/archives/2007/37838.html


https://bbs.21ic.com/club/bbs/list.asp?boardid=35&t=2496814&tp=%u5F7B%u5E95%u5012%u584C%u4E86%7E%7E%7Ekeil%u7684CARM%u7F16%u8BD1%u5668%u597D%u8C61%u4E0D%u80FD%u8BBE%u7F6E%u751F%u6210%u76F8%u5BF9%u8DF3%u8F6C%u4EE3%u7801%uFF1F

使用特权

评论回复
板凳
微风|  楼主 | 2007-5-11 23:22 | 只看该作者

不知道为什么,我这里选别的型号会出错

搞不明白

使用特权

评论回复
地板
kyoko| | 2010-8-19 10:29 | 只看该作者
楼主,我按你的方法进行编译,采用MDK V4.10,但是出现如下错误,编译不成功。能否给个编译后的文件包,谢谢

compiling FlashDev.c...
linking...
AM29LV160DB.axf: Error: L6265E: Non-PI Section flashprg.o(.data) cannot be assigned to PI Exec region PrgData.
AM29LV160DB.axf: Error: L6248E: flashprg.o(.text) in PI region 'PrgCode' cannot have address type relocation to .data in PI region 'PrgData'.
AM29LV160DB.axf: Error: L6285E: Non-relocatable Load region PRG contains R-Type dynamic relocations. First R-Type dynamic relocation found in flashprg.o(.text) at offset 0x194.
AM29LV160DB.axf: Finished: 0 information, 0 warning and 3 error messages.
Target not created

就算是直接打开自带的AM29F160DB项目文件进行编译,也出现相同的错误

使用特权

评论回复
5
fangang0313| | 2010-12-31 21:47 | 只看该作者
我也碰到相同的问题。。不知道为什么呢?

使用特权

评论回复
6
ha0xiang| | 2010-12-31 21:52 | 只看该作者
搞不明白

使用特权

评论回复
7
fangang0313| | 2010-12-31 22:35 | 只看该作者
原因我找到了。。Target.lin 文件里 加上 ABSOLUTE 就 OK 了 像这样
PRG 0 PI               ; Programming Functions
{
  PrgCode +0           ; Code
  {
    * (+RO)
  }
  PrgData +0  ABSOLUTE         ; Data
  {
    * (+RW,+ZI)
  }
}

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

32

主题

682

帖子

4

粉丝
关闭 热门推荐
快速回复 在线客服 返回列表 返回顶部