调用Ram Flashdrv 进入hardfault
-
发现如果不SuspendAllInterrupts ,调用FLASH_DRV_EraseSector会进入hardfault.
SCB信息如下:
Expression Value Location Type
mySCB 0xE000'ED00 0x1fff'2278 SCB_Type *
CPUID 1'091'555'860 0xe000'ed00 uint32 volatile const
ICSR 3 0xe000'ed04 uint32 volatile
VTOR 536'805'376 0xe000'ed08 uint32 volatile
AIRCR 4'194'639'872 0xe000'ed0c uint32 volatile
SCR 0 0xe000'ed10 uint32 volatile
CCR 513 0xe000'ed14 uint32 volatile
SHPR <array>"" 0xe000'ed18 uint8 (volatile)[12]
SHCSR 65'540 0xe000'ed24 uint32 volatile
CFSR 65'536 0xe000'ed28 uint32 volatile
HFSR 0x4000'0000 0xe000'ed2c uint32 volatile
DFSR 2 0xe000'ed30 uint32 volatile
MMFAR 0x2000'ff1c 0xe000'ed34 uint32 volatile
BFAR 536'936'220 0xe000'ed38 uint32 volatile
AFSR 0 0xe000'ed3c uint32 volatile
ID_PFR <array> 0xe000'ed40 uint32 (volatile const)[2]
ID_DFR 2'097'152 0xe000'ed48 uint32 volatile const
ID_AFR 0 0xe000'ed4c uint32 volatile const
ID_MMFR <array> 0xe000'ed50 uint32 (volatile const)[4]
ID_ISAR <array> 0xe000'ed60 uint32 (volatile const)[6]
CLIDR 0 0xe000'ed78 uint32 volatile const
CTR 2'147'532'800 0xe000'ed7c uint32 volatile const
CCSIDR 0 0xe000'ed80 uint32 volatile const
CSSELR 0 0xe000'ed84 uint32 volatile
CPACR 15'728'640 0xe000'ed88 uint32 volatile
NSACR 0 0xe000'ed8c uint32 volatile
RESERVED7 <array> 0xe000'ed90 uint32[21]
SFSR 0 0xe000'ede4 uint32 volatile
SFAR 0 0xe000'ede8 uint32 volatile
RESERVED3 <array> 0xe000'edec uint32[69]
STIR 0 0xe000'ef00 uint32 volatile
RESERVED4 <array> 0xe000'ef04 uint32[15]
MVFR0 269'549'601 0xe000'ef40 uint32 volatile const
MVFR1 285'212'689 0xe000'ef44 uint32 volatile const
MVFR2 64 0xe000'ef48 uint32 volatile const
RESERVED5 <array> 0xe000'ef4c uint32[1]
ICIALLU 0 0xe000'ef50 uint32 volatile
RESERVED6 <array> 0xe000'ef54 uint32[1]
ICIMVAU 0 0xe000'ef58 uint32 volatile
DCIMVAC 0 0xe000'ef5c uint32 volatile
DCISW 0 0xe000'ef60 uint32 volatile
DCCMVAU 0 0xe000'ef64 uint32 volatile
DCCMVAC 0 0xe000'ef68 uint32 volatile
DCCSW 0 0xe000'ef6c uint32 volatile
DCCIMVAC 0 0xe000'ef70 uint32 volatile
DCCISW 0 0xe000'ef74 uint32 volatile
BPIALL 0 0xe000'ef78 uint32 volatile -
通过您提供的 SCB 寄存器信息分析可知:
- HFSR=0x4000_0000 → FORCED 位有效,说明是低优先级 Fault 升级来的 HardFault。
- CFSR=0x0001_0000 → Bus Fault 的 PRECISERR 位置 1,即精确的数据总线访问错误。
- BFAR=0x2000_FF1C → 故障地址在 SRAM 顶部栈区附近。
完整的故障路径是:
Flash Erase 执行中 → 此时来了一个中断 → CPU 响应中断,自动压栈(写 SRAM) → SP 落到 0x2000_FF1C 附近 → Flash Erase 期间 AHB Bus 可能暂停/限制 SRAM 并发写 → 栈写操作失败 → PRECISERR → HardFault结论:Flash Erase 期间发生中断,中断响应的压栈操作在 Flash 操作占用的 AHB Bus 上失败了。
建议:Flash Erase/Program 前必须调用 SuspendAllInterrupts() 关全局中断,这是标准做法,不是规避 bug 的 workaround。
快速上手云途开发生态
发帖前请查看
帮助改进和优化YT CONFIG TOOL,有机会抽取YTM32B1ME0 EVB哦...