打印

如何将一常量放置在FLASH的指定位置

[复制链接]
4916|7
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
leewen|  楼主 | 2011-4-1 17:08 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
请教一下,在STM32 ,IAR编译时,如果想将一常量const unsigned char str[10]="1234567890";放置在FLASH的地址0x08001000起始位置中,如何操作
沙发
Cube| | 2011-4-2 03:04 | 只看该作者
如果使用的是3.X的库的话

可以使用

                FLASH_Unlock();
                FLASH_ProgramWord(地址,数据);
                FLASH_Lock();

完成flash的写操作

但是注意,清空时候只能以页为单位清空

                FLASH_Unlock();
                FLASH_ErasePage(地址);
                FLASH_Lock();

这些都是从

  ******************************************************************************
  * @file  stm32f10x_flash.c
  * @author  MCD Application Team
  * @version  V3.0.0
  * @date  04/06/2009
  * @brief  This file provides all the FLASH firmware functions.
  ******************************************************************************

中找到的,可以参考库函数说明文档里面有这几个函数的解释

使用特权

评论回复
板凳
airwill| | 2011-4-2 10:29 | 只看该作者
请教一下,在STM32 ,IAR编译时,如果想将一常量const unsigned char str[10]="1234567890";放置在FLASH的地址0x08001000起始位置中,如何操作
leewen 发表于 2011-4-1 17:08


在前面做个申明:
const unsigned char str[] __attribute__((at(0x08001000)));
就可以了

使用特权

评论回复
地板
Cube| | 2011-4-2 13:10 | 只看该作者
哈哈,是常量~看错了的

使用特权

评论回复
5
clz918| | 2011-4-2 13:39 | 只看该作者
#define  ADDR_BASE         0x08010000


void SaveData(unsigned int *in_data, unsigned int length)
{
unsigned int addr_use=0;
unsigned int data1=0;
unsigned long address_cpu=0;

  FLASH_Unlock();                               
  FLASH_ErasePage(ADDR_BASE);      
   for(addr_use=0;addr_use<length;addr_use++)
   {

   data1=addr_use>>9;
   address_cpu=ADDR_BASE+1024*data1;
   data1=(addr_use%512)*2;

   FLASH_ProgramHalfWord(address_cpu+data1,in_data[addr_use]);
   FLASH->CR=FLASH->CR&0xfffd;

   }
  FLASH_Lock();                                       

}

刚调试完的,

使用特权

评论回复
6
leewen|  楼主 | 2011-4-6 12:07 | 只看该作者
在前面做个申明:
const unsigned char str[] __attribute__((at(0x08001000)));
就可以了
airwill 发表于 2011-4-2 10:29

编译出错,
Error[Pe065]:expected a";"

使用特权

评论回复
7
CC2530| | 2011-4-6 12:52 | 只看该作者
本帖最后由 CC2530 于 2011-4-6 12:55 编辑

Placing a section at a specific address in memory
To place a section at a specific address in memory, use the place at directive, for
example:
/* Place section .vectors at address 0 */
place at address Mem:[0] {readonly section .vectors};
Placing a section first or last in a region
To place a section first or last in a region is similar, for example:
/* Place section .vectors at start of ROM */
place at start of ROM {readonly section .vectors};
Declare and place your own sections
To declare new sections!ain addition to theones used by the IAR build tools!ato hold
specific parts of your code or data, use mechanisms in the compiler and assembler. For
example:
/* Places a variable in your own section MyOwnSection. */
const int MyVariable @ "MyOwnSection" = 5;
            name    createSection
            /* Create a section */
            section myOwnSection:CONST
            /* And fill it with constant bytes */
            dcb     5, 6, 7, 8
            end
To place your new section, the original place in ROM {readonly}; directive is
sufficient.
However, to place the section MyOwnSection explicitly, update the linker configuratio
file with a
place in directive, for example:
/* Place MyOwnSection in the ROM region */
place in ROM {readonly section MyOwnSection};

使用特权

评论回复
8
smithlin| | 2011-10-27 21:44 | 只看该作者
5# clz918

感谢5楼clz918,按照你的例子,成功实现读写Flash.

多谢!

使用特权

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

本版积分规则

45

主题

102

帖子

2

粉丝