[其他ST产品]

各位高手请帮我看看这段代码哪里也问题?

[复制链接]
3190|6
手机看帖
扫描二维码
随时随地手机跟帖
Tony007|  楼主 | 2007-5-14 11:11 | 显示全部楼层 |阅读模式
我想将一个数组写入str710内部Flash的B1F0扇区,结果老是出错,不知道哪里有问题?请各位高手帮我看看哪里有问题,一下是写Flash函数:

Write_Flash(buff,0x400C0000,10,FLASH_B1F0);

void Write_Flash(u32 *buff,u32 Addr,u16 Length,u32 Sector)
{
  u32 Adders;
 
  Addres=(u32)((u32 *)buff); 
  FLASH_SectorErase(Sector);

  intFLASH_BlockWrite(Addres,Addr,Length);
}
香水城| | 2007-5-14 14:40 | 显示全部楼层

这种问题已经讨论很多次了

STR71x上电后Flash的第一次擦出或写入应在RAM中执行相应的程序,请在论坛里找一下相关的帖子。

使用特权

评论回复
Tony007|  楼主 | 2007-5-14 15:19 | 显示全部楼层

怎样让STR71x上电后Flash的第一次擦出或写入在RAM中执行?谢谢

可是我的程序不知道什么原因只能从Flash中启动啊,从RAM中一启动程序马上跑飞。能不能给我说详细点啊怎样让STR71x上电后Flash的第一次擦出或写入在RAM中执行?谢谢

使用特权

评论回复
Tony007|  楼主 | 2007-5-15 09:42 | 显示全部楼层

怎样让STR71x上电后Flash的第一次擦除或写入在RAM中执行?

STR71x上电后Flash的第一次擦除或写入应在RAM中执行相应的程序,请问是不是就是上电从RAM起动啊?

使用特权

评论回复
starm| | 2007-5-15 11:54 | 显示全部楼层

STR71x上电后Flash的第一次擦除或写入应在RAM中执行相应的程序

把擦除的函数声明为 
///////////////////////////////////////IAR EWARM
__ramfunc void EraseFlash(....)
///////////////////////////////////////IAR EWARM

Syntax 
Follows the generic syntax rules for object attributes, see Object attributes. 

Description 
The __ramfunc keyword makes a function execute in RAM. Two code segments will be created: one for the RAM execution, and one for the ROM initialization. 

If a function declared __ramfunc tries to access ROM, the compiler will issue a warning. This behavior is intended to simplify the creation of upgrade routines, for instance, rewriting parts of flash memory. If this is not why you have declared the function __ramfunc, you may safely ignore or disable these warnings. 

Functions declared __ramfunc are by default stored in the segment named CODE_I. 

Example 
__ramfunc int FlashPage(char * data, char * page); 
See also 
To read more about __ramfunc declared functions in relation to breakpoints, see the ARM® IAR Embedd
__ram: RAM Function
The CARM Compiler supports RAM functions which are copied to RAM for execution. The __ram function attribute defines RAM functions.


/////////////////////////////////////KEIL 
void EraseFlash(....) __ram
/////////////////////////////////////KEIL 

The CARM Compiler supports RAM functions which are copied to RAM for execution. The __ram function attribute defines RAM functions.

« type » funcname (« args ») __ram
Where

type is the type of the value returned from the function. If no type is specified, int is assumed.  
funcname is the name of the function. 
args is the argument list for the function. 
__ram indicates that the function should be copied to RAM before execution. 

For example:

#define M16(adr) (*((volatile unsigned short *) (adr)))

void my_prog_func (unsigned short val, unsigned short *adr) __ram {
  M16(base_adr + 0xAAA) = 0xAA;    // enter programming mode
  M16(base_adr + 0x554) = 0x55;
  M16(base_adr + 0xAAA) = 0xA0;
  M16(adr) = val;                  // program value
  while (M16(adr) != val);         // wait until programmed
}

使用特权

评论回复
Tony007|  楼主 | 2007-5-16 09:33 | 显示全部楼层

非常感谢starm

谢谢starm,可是我用的是ADS1.2,请问在ads.2要如何声明呢?

使用特权

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

本版积分规则

10

主题

27

帖子

0

粉丝