cortex-m3 m4 异常机制

 

文章写的很好,笔记

 

1.【STM32】HardFault问题详细分析及调试笔记

https://blog.csdn.net/m0_54916619/article/details/129979222

 需备注:

cortex m4:  实际行为是,寄存器按照编号从小到大的顺序在栈帧中从数值较小地址往数值较大的地址排列.    进入异常时自动入栈R0-R3 R12 LR PSR

 其实这里只是介绍了死机前的上一个函数的定位,并没有介绍,多级或者叫多层次,这种函数调用栈如何去追溯。

这玩意主要是一个arm汇编的问题,所以要想彻底搞清楚,汇编语言是要系统学习。

 

2.   stm32死机问题的处理

https://blog.csdn.net/qq_27087571/article/details/84580532

void hard_fault_handler_c(unsigned int * hardfault_args) 
{     
  static System_Crash_Info crash_info;
  memset(&crash_info, 0, sizeof(System_Crash_Info));
  
  crash_info.is_crash = 1;
  crash_info.crash_time = (unsigned int)HAL_GetTick();
  
  crash_info.stacked_r0 = ((unsigned long) hardfault_args[0]);  
  crash_info.stacked_r1 = ((unsigned long) hardfault_args[1]);  
  crash_info.stacked_r2 = ((unsigned long) hardfault_args[2]);  
  crash_info.stacked_r3 = ((unsigned long) hardfault_args[3]);  
  crash_info.stacked_r12 = ((unsigned long) hardfault_args[4]);    
  crash_info.stacked_lr = ((unsigned long) hardfault_args[5]);   
  crash_info.stacked_pc = ((unsigned long) hardfault_args[6]);  
  crash_info.stacked_psr = ((unsigned long) hardfault_args[7]); 

  crash_info.MFSR = (*((volatile unsigned char *)(0xE000ED28))); //存储器管理fault状态寄存器   
  crash_info.BFSR = (*((volatile unsigned char *)(0xE000ED29))); //总线fault状态寄存器   
  crash_info.UFSR = (*((volatile unsigned short int *)(0xE000ED2A)));//用法fault状态寄存器    
  crash_info.HFSR = (*((volatile unsigned long *)(0xE000ED2C)));  //硬fault状态寄存器     
  crash_info.DFSR = (*((volatile unsigned long *)(0xE000ED30))); //调试fault状态寄存器  
  crash_info.MMAR = (*((volatile unsigned long *)(0xE000ED34))); //存储管理地址寄存器  
  crash_info.BFAR = (*((volatile unsigned long *)(0xE000ED38))); //总线fault地址寄存器  
  
  u8 ret = STMFLASH_EraseSector(STMFLASH_GetFlashSector(SYS_CRASH_INFO_ADDR));
  u8 ret2 = STMFLASH_Write(SYS_CRASH_INFO_ADDR, (u32 *)(&crash_info), (3+sizeof(System_Crash_Info))/4);

  while (1);  
}

 这里的潜在意思是, ARM平台的C函数入参,按顺序,依次可以获取到R0 R1 R2 R3 等,所以可以通过静态的crash_info将其记录下来。

 

 

3.  RTOS任务切换和异常的相关性很大

基于STM32 F103 CM3内核 freeRTOS 任务切换原理

https://zhuanlan.zhihu.com/p/599020378 

 

 

 

 

 

.

 

posted @ 2024-09-14 10:09  一匹夫  阅读(34)  评论(0编辑  收藏  举报