硬汉嵌入式论坛

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

[Flash] 【求助】STM32H743使用指针按4字节访问FLASH时,由PRECISERR引起hardfault

[复制链接]
回帖奖励 4 个金币 回复本帖可获得 1 个金币奖励! 每人限 1 次

1

主题

9

回帖

12

积分

新手上路

积分
12
发表于 2024-12-12 15:53:44 | 显示全部楼层 |阅读模式
我在使用STM32H743运行openBLT程序boot部分时,在下载的检测阶段执行了FLASH读取函数,目的是检查FLASH是否为空。

在读取扇区0x08020000到0x0803FFFF的过程中,程序进入hardfault。
以下贴出flash检查程序:
[C] 纯文本查看 复制代码
static blt_bool FlashEmptyCheckSector(blt_int8u sector_idx)
{
  blt_bool   result = BLT_TRUE;
  blt_addr   sectorAddr;
  blt_int32u sectorSize;
  blt_int32u wordCnt;
  blt_int32u volatile const * wordPtr;

  /* retrieve sector info */
  sectorAddr = flashLayout[sector_idx].sector_start;
  sectorSize = flashLayout[sector_idx].sector_size;

  /* sanity check. sector base address should be 32-bit aligned and the size
   * should be a multiple of 32-bits.
   */
  ASSERT_RT(((sectorAddr % sizeof(blt_int32u)) == 0) &&
            ((sectorSize % sizeof(blt_int32u)) == 0));

  /* initialize the pointer to the first word in the sector */
  wordPtr = (blt_int32u volatile const *)sectorAddr;
  /* read sector 32-bits at a time */
  for (wordCnt = 0; wordCnt < (sectorSize/sizeof(blt_int32u)); wordCnt++)
  {
    /* service the watchdog every 256th loop iteration */
    if ((wordCnt % 256) == 0)
    {
      CopService();
    }
    /* word not in the erased state? */
    if (*wordPtr != 0xFFFFFFFFu)
    {
      /* sector not empty, update the result accordingly */
      result = BLT_FALSE;
      /* no point in continuing the sector empty check */
      break;
    }
    /* set pointer to the next word in the sector */
    wordPtr++;
  }
  /* give the result back to the caller. */
  return result;
} /*** end of FlashEmptyCheckSector ***/

DEBUG查看Fault Report有:

想求助该问题引发的原因。
---
本工程由cubeMX生成,时钟为480MHz,MPU等为默认配置。外部时钟25MHz,仅使用了USART1,GPIO外设。
回复

使用道具 举报

1万

主题

7万

回帖

11万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
117529
QQ
发表于 2024-12-13 00:25:08 | 显示全部楼层

回帖奖励 +1 个金币

不使用这个组件,单纯读取地址0x08020000到0x0803FFFF释放还会异常
回复

使用道具 举报

1

主题

9

回帖

12

积分

新手上路

积分
12
 楼主| 发表于 2024-12-13 09:42:19 | 显示全部楼层
eric2013 发表于 2024-12-13 00:25
不使用这个组件,单纯读取地址0x08020000到0x0803FFFF释放还会异常

是的,我新建了一个cubemx工程,并只运行使用指针read flash的操作。附上main.c和H743II的cubeMX工程文件,您如果有时间,方便的话,帮我也试一试。
[C] 纯文本查看 复制代码
void read_flash_test()
{
  uint32_t sectorAddr;
  uint32_t sectorSize;
  uint32_t wordCnt;
  uint32_t volatile const * wordPtr;
  uint32_t readWord;

  /* retrieve sector info */
  sectorAddr = 0x8020000;
  sectorSize = 0x20000;

  /* initialize the pointer to the first word in the sector */
  wordPtr = (uint32_t volatile const *)sectorAddr;
  for (wordCnt = 0; wordCnt < (sectorSize/sizeof(uint32_t)); wordCnt++)
  {
    /* service the watchdog every 256th loop iteration */
    readWord = *wordPtr;
    /* word not in the erased state? */
    if (readWord != 0xFFFFFFFFu)
    {
      /* no point in continuing the sector empty check */
      break;
    }
    /* set pointer to the next word in the sector */
    wordPtr++;
  }
}
int main(){  
/* USER CODE BEGIN WHILE */
  while (1)
  {
    /* USER CODE END WHILE */
    read_flash_test();
      HAL_Delay(1000);
    /* USER CODE BEGIN 3 */
  }
}

FLASH_READ_TEST.zip

4.32 KB, 下载次数: 0

回复

使用道具 举报

1

主题

9

回帖

12

积分

新手上路

积分
12
 楼主| 发表于 2024-12-13 09:58:38 | 显示全部楼层
我还发现一个现象就是,对bank2(即0x8100000)做相同的读操作不会引起PRECISERR上访hardfault。对bank2的读操作size为0x0100000,每次4byte,即全页读取。
回复

使用道具 举报

1

主题

9

回帖

12

积分

新手上路

积分
12
 楼主| 发表于 2024-12-13 10:15:23 | 显示全部楼层
[已解决]原因未知,我做了一次正片擦除之后,再对0x08020000等各flash地址的读操作,都没有再出现PRECISERR错误了。
回复

使用道具 举报

1万

主题

7万

回帖

11万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
117529
QQ
发表于 2024-12-14 01:35:17 | 显示全部楼层
CAizg294 发表于 2024-12-13 10:15
[已解决]原因未知,我做了一次正片擦除之后,再对0x08020000等各flash地址的读操作,都没有再出现PRECISE ...

这个确实诡异,谢谢告知最终原因
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-8-12 11:07 , Processed in 0.070622 second(s), 33 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

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