虽然STM32F3XX Hardfault处理程序内的循环并不能像预期的那样永远执行
我想找到我在项目中看到的神秘微控制器的原因。我正在使用的微控制器是带有STM32F3XX驱动程序库的STM32F3设备。
我的设置还包括一个J-Link Ultra+调试器,但是令人沮丧的是,我尚未弄清楚如何重现重置。它们几乎总是在离开设备运行12个小时后发生,并且在旨在与调试器接口的编程夹具上连接时似乎不会发生。
我相信,当重置发生时,将调用硬故障处理程序。我有许多这样的设备,并且鉴于我无法将它们全部连接到调试器,并且重置在不合时宜的时间发生,我希望能够通过Hardfault Handler的串行线发送一些信息。然后,外部设备将观察到串行线。
更复杂的事情是缺乏未使用的UART引脚。我试图通过在硬故障处理程序中打开和关闭GPIO来创建一个穷人的UART,并在两者之间进行延迟。首先,我只想弄清楚如何以50%的占空比来触发这一领导。我的代码当前看起来像这样:
/**
* @brief This function handles Hard fault interrupt.
*/
void HardFault_Handler(void)
{
/* USER CODE BEGIN HardFault_IRQn 0 */
GPIO_InitTypeDef GPIO_InitStruct = {LED_Pin, GPIO_MODE_OUTPUT_PP,
GPIO_NOPULL, GPIO_SPEED_FREQ_LOW, 0};
HAL_GPIO_Init(LED_Port, &GPIO_InitStruct);
/* USER CODE END HardFault_IRQn 0 */
while (1)
{
/* USER CODE BEGIN W1_HardFault_IRQn 0 */
HAL_GPIO_WritePin(LED_Port, LED_Pin, GPIO_PIN_RESET);
HAL_Delay(10);
HAL_GPIO_WritePin(LED_Port, LED_Pin, GPIO_PIN_SET);
HAL_Delay(10);
/* USER CODE END W1_HardFault_IRQn 0 */
}
}
我正在通过触发零零重置的分隔符来测试。我已经禁用了所有看门狗,但我发现,当输入循环时,它并非永远,实际上,当设备首次击中hal_delay()命令时,该设备会重新启动。
问题:
- 到达HAL_DELAY()时可能导致重置是什么?
- 我可以无限期地执行指令在硬故障处理程序中,还是在重置之前必须做一些有限的时间?
- 我可以在硬故障处理程序中使用计时器吗?
非常感谢您的帮助。
I would like to find the cause of mysterious microcontroller resets that I am seeing in my project. The microcontroller I am using is an STM32F3 device with STM32F3xx driver library.
My setup also includes a J-link Ultra+ debugger, however frustratingly I have not yet figured out how to reproduce the resets. They occur almost always after leaving the device running for 12+ hours, and do not seem to occur when connected on a programming jig designed to interface with the debugger.
I believe that when the resets occur, the HardFault handler will be called. I have a number of these devices, and given I cannot connect them all to the debugger and the resets occur at inopportune times, I would like to be able to send some information via a serial line from the HardFault handler. The serial line would then be observed by an external device.
Further complicating things is the lack of unused UART pins. I am attempting to create a poor man's UART by flicking a GPIO on and off in the hard fault handler, with delays in between. To begin with, I just want to figure out how to flick this LED on and off with 50% duty cycle. My code currently looks something like this:
/**
* @brief This function handles Hard fault interrupt.
*/
void HardFault_Handler(void)
{
/* USER CODE BEGIN HardFault_IRQn 0 */
GPIO_InitTypeDef GPIO_InitStruct = {LED_Pin, GPIO_MODE_OUTPUT_PP,
GPIO_NOPULL, GPIO_SPEED_FREQ_LOW, 0};
HAL_GPIO_Init(LED_Port, &GPIO_InitStruct);
/* USER CODE END HardFault_IRQn 0 */
while (1)
{
/* USER CODE BEGIN W1_HardFault_IRQn 0 */
HAL_GPIO_WritePin(LED_Port, LED_Pin, GPIO_PIN_RESET);
HAL_Delay(10);
HAL_GPIO_WritePin(LED_Port, LED_Pin, GPIO_PIN_SET);
HAL_Delay(10);
/* USER CODE END W1_HardFault_IRQn 0 */
}
}
I am testing this by triggering a divide-by-zero reset. I have disabled all watchdogs yet I am finding that when this while loop is entered, it does not while forever, in fact the device restarts when it first hits a HAL_Delay() command.
Questions:
- What might be causing the resets upon reaching HAL_Delay()?
- Can I execute instructions indefinitely in the HardFault handler, or is there a limited amount of time I have to do things before a reset occurs?
- Can I use timers in the hard fault handler?
Thanks very much for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
hal_delay(10);
使用Systick中断。当在HF中,您将不会受到任何中断,并且此功能将永远等待,并且您的二极管不会闪烁。您需要延迟另一种方式,例如:是的,只要您需要,您就可以呆在那里。但是没有中断!
是的,但是没有计时器中断。基本上,如果需要,您可以使用所有外围设备。
很难说。您启用了看门狗吗?
基本上
不使用
hf中的Hal ,因为大多数功能都在内部使用hal_delay
。编程裸寄存器HAL_Delay(10);
uses systick interrupt. When in HF you will not get any interrupts and this function will wait forever and your diodes will not flash. You need to delay another way, for example:Yes you can stay there as long as you wish. But no interrupts!!!!
Yes, but no timer interrupts. Basically, you can use all the peripherals if you wish.
Hard to say. Did you enable watchdog?
Basically
do not use
HAL in HF as most of the functions useHAL_Delay
internally. Program bare registers instead