硬汉嵌入式论坛

 找回密码
 立即注册
查看: 1894|回复: 4
收起左侧

V6-009_CPU内部Flash读写例程

[复制链接]

7

主题

22

回帖

43

积分

新手上路

积分
43
发表于 2018-5-1 10:58:33 | 显示全部楼层 |阅读模式
请教个问题, 如果我把这里的测试地址  设置为块2 的
#define ADDR_FLASH_SECTOR_12     ((uint32_t)0x08100000) /* Base @ of Sector 12, 16 Kbytes */
#define ADDR_FLASH_SECTOR_13     ((uint32_t)0x08104000) /* Base @ of Sector 13, 16 Kbytes */
#define ADDR_FLASH_SECTOR_14     ((uint32_t)0x08108000) /* Base @ of Sector 14, 16 Kbytes */
#define ADDR_FLASH_SECTOR_15     ((uint32_t)0x0810C000) /* Base @ of Sector 15, 16 Kbytes */
#define ADDR_FLASH_SECTOR_16     ((uint32_t)0x08110000) /* Base @ of Sector 16, 64 Kbytes */
#define ADDR_FLASH_SECTOR_17     ((uint32_t)0x08120000) /* Base @ of Sector 17, 128 Kbytes */
#define ADDR_FLASH_SECTOR_18     ((uint32_t)0x08140000) /* Base @ of Sector 18, 128 Kbytes */
#define ADDR_FLASH_SECTOR_19     ((uint32_t)0x08160000) /* Base @ of Sector 19, 128 Kbytes */
#define ADDR_FLASH_SECTOR_20     ((uint32_t)0x08180000) /* Base @ of Sector 20, 128 Kbytes */
#define ADDR_FLASH_SECTOR_21     ((uint32_t)0x081A0000) /* Base @ of Sector 21, 128 Kbytes */
#define ADDR_FLASH_SECTOR_22     ((uint32_t)0x081C0000) /* Base @ of Sector 22, 128 Kbytes */
#define ADDR_FLASH_SECTOR_23     ((uint32_t)0x081E0000) /* Base @ of Sector 23, 128 Kbytes */


数据写了一次之后  再写其他的数据就写不进去了,这是什么原因
回复

使用道具 举报

7

主题

22

回帖

43

积分

新手上路

积分
43
 楼主| 发表于 2018-5-1 10:59:51 | 显示全部楼层
如果是块1的
回复

使用道具 举报

7

主题

22

回帖

43

积分

新手上路

积分
43
 楼主| 发表于 2018-5-1 11:00:36 | 显示全部楼层
#define ADDR_FLASH_SECTOR_0     ((uint32_t)0x08000000) /* Base @ of Sector 0, 16 Kbytes */ #define ADDR_FLASH_SECTOR_1     ((uint32_t)0x08004000) /* Base @ of Sector 1, 16 Kbytes */ #define ADDR_FLASH_SECTOR_2     ((uint32_t)0x08008000) /* Base @ of Sector 2, 16 Kbytes */ #define ADDR_FLASH_SECTOR_3     ((uint32_t)0x0800C000) /* Base @ of Sector 3, 16 Kbytes */ #define ADDR_FLASH_SECTOR_4     ((uint32_t)0x08010000) /* Base @ of Sector 4, 64 Kbytes */ #define ADDR_FLASH_SECTOR_5     ((uint32_t)0x08020000) /* Base @ of Sector 5, 128 Kbytes */ #define ADDR_FLASH_SECTOR_6     ((uint32_t)0x08040000) /* Base @ of Sector 6, 128 Kbytes */ #define ADDR_FLASH_SECTOR_7     ((uint32_t)0x08060000) /* Base @ of Sector 7, 128 Kbytes */ #define ADDR_FLASH_SECTOR_8     ((uint32_t)0x08080000) /* Base @ of Sector 8, 128 Kbytes */ #define ADDR_FLASH_SECTOR_9     ((uint32_t)0x080A0000) /* Base @ of Sector 9, 128 Kbytes */ #define ADDR_FLASH_SECTOR_10    ((uint32_t)0x080C0000) /* Base @ of Sector 10, 128 Kbytes */ #define ADDR_FLASH_SECTOR_11    ((uint32_t)0x080E0000) /* Base @ of Sector 11, 128 Kbytes */测试没问题
回复

使用道具 举报

1万

主题

7万

回帖

11万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
115661
QQ
发表于 2018-5-1 11:19:37 | 显示全部楼层
程序里面没做支持。看下面这个函数,你修正下即可:

  1. /*
  2. *********************************************************************************************************
  3. *        函 数 名: bsp_GetSector
  4. *        功能说明: 根据地址计算扇区首地址
  5. *        形    参:  无
  6. *        返 回 值: 扇区首地址
  7. *********************************************************************************************************
  8. */
  9. uint32_t bsp_GetSector(uint32_t Address)
  10. {
  11.         uint32_t sector = 0;

  12.         if((Address < ADDR_FLASH_SECTOR_1) && (Address >= ADDR_FLASH_SECTOR_0))
  13.         {
  14.                 sector = FLASH_Sector_0;
  15.         }
  16.         else if((Address < ADDR_FLASH_SECTOR_2) && (Address >= ADDR_FLASH_SECTOR_1))
  17.         {
  18.                 sector = FLASH_Sector_1;
  19.         }
  20.         else if((Address < ADDR_FLASH_SECTOR_3) && (Address >= ADDR_FLASH_SECTOR_2))
  21.         {
  22.                 sector = FLASH_Sector_2;
  23.         }
  24.         else if((Address < ADDR_FLASH_SECTOR_4) && (Address >= ADDR_FLASH_SECTOR_3))
  25.         {
  26.                 sector = FLASH_Sector_3;
  27.         }
  28.         else if((Address < ADDR_FLASH_SECTOR_5) && (Address >= ADDR_FLASH_SECTOR_4))
  29.         {
  30.                 sector = FLASH_Sector_4;
  31.         }
  32.         else if((Address < ADDR_FLASH_SECTOR_6) && (Address >= ADDR_FLASH_SECTOR_5))
  33.         {
  34.                 sector = FLASH_Sector_5;
  35.         }
  36.         else if((Address < ADDR_FLASH_SECTOR_7) && (Address >= ADDR_FLASH_SECTOR_6))
  37.         {
  38.                 sector = FLASH_Sector_6;
  39.         }
  40.         else if((Address < ADDR_FLASH_SECTOR_8) && (Address >= ADDR_FLASH_SECTOR_7))
  41.         {
  42.                 sector = FLASH_Sector_7;
  43.         }
  44.         else if((Address < ADDR_FLASH_SECTOR_9) && (Address >= ADDR_FLASH_SECTOR_8))
  45.         {
  46.                 sector = FLASH_Sector_8;
  47.         }
  48.         else if((Address < ADDR_FLASH_SECTOR_10) && (Address >= ADDR_FLASH_SECTOR_9))
  49.         {
  50.                 sector = FLASH_Sector_9;
  51.         }
  52.         else if((Address < ADDR_FLASH_SECTOR_11) && (Address >= ADDR_FLASH_SECTOR_10))
  53.         {
  54.                 sector = FLASH_Sector_10;
  55.         }
  56.         else        /*(Address < FLASH_END_ADDR) && (Address >= ADDR_FLASH_SECTOR_11))*/
  57.         {
  58.                 sector = FLASH_Sector_11;
  59.         }

  60.         return sector;
  61. }
复制代码


回复

使用道具 举报

7

主题

22

回帖

43

积分

新手上路

积分
43
 楼主| 发表于 2018-5-1 11:33:27 | 显示全部楼层
没注意看这里,  问题已经解决,感谢
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|硬汉嵌入式论坛

GMT+8, 2025-5-10 10:57 , Processed in 0.228826 second(s), 24 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表