问题描述
我被HAL_Delay()函数困住了.当我调用此函数HAL_Delay()时,控件陷入无限循环.在寻找问题时,我发现了这个问题
I am stuck with HAL_Delay() function. When i call this function HAL_Delay() , control stuck in infinite loop.While searching for the problem, I found this
http://www.openstm32.org/forumthread2145#threadId2146
在此特别声明中,我引述链接器文件存在问题,请使用所附的链接器.您需要分别映射两排内存,因此首先是SRAM1 96K,然后是32K SRAM2.我认为应该报告作为CubeMX中的错误,因为它会生成错误的链接器文件."还有两个扩展名为.ld的文件.
In this particular comment which states and i quote "There is problem with linker file please use the one attached. You need to map two banks of memory separately so first SRAM1 96K and then SRAM2 of 32K. I think this should be reported as bug in CubeMX as it generates bad linker file." and there are two files with .ld extension.
我正在寻找的是如何在项目中使用此文件,或者如何使用其他更好的选项来解决此问题.
PS.我正在使用stm32l476发现板,Cube Mx 5.0.0和Attolic True Studio.
PS. I am using stm32l476 discovery board, Cube Mx 5.0.0 and Attolic True Studio.
编辑
我的项目正在进行RS485通讯,我从那里获取数据,并处理两个数据,将其显示在MAX7219显示屏上,并使用sim800 gsm模块将其发送到互联网.
My project is having an RS485 communication where from where i take data and i have two task with that data, display it on MAX7219 display and send it to internet using sim800 gsm module.
控件卡住的代码.请注意,只有在执行GSM任务时才会调用此函数.
The code where the control is stuck. note that this function is only called when it is doing GSM tasks.
void vMyDelay(uint16_t ms)
{
HAL_UART_Transmit(&huart2, (uint8_t*)"\r\n", strlen("\r\n"), 1000);
HAL_UART_Transmit(&huart2, (uint8_t*)"In Delay", strlen("In Delay"), 1000);
HAL_UART_Transmit(&huart2, (uint8_t*)"\r\n", strlen("\r\n"), 1000);
for (int i = 0; i < ms; i++ ) HAL_Delay(1);
HAL_UART_Transmit(&huart2, (uint8_t*)"\r\n", strlen("\r\n"), 1000);
HAL_UART_Transmit(&huart2, (uint8_t*)"Out Delay", strlen("Out Delay"), 1000);
HAL_UART_Transmit(&huart2, (uint8_t*)"\r\n", strlen("\r\n"), 1000);
}
此功能在终端上写入 In Delay
,但不显示 Out Delay
.但是我还有一个定时器,每2秒调用一次以在MAX72219上显示数据.
This function writes In Delay
on the terminal but Out Delay
is not displayed. But i am also having a timer which invokes every 2 sec to display the data on MAX72219.
以下代码是
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
HAL_UART_Transmit(&huart2, (uint8_t*)"\r\n", strlen("\r\n"), 1000);
HAL_UART_Transmit(&huart2, (uint8_t*)"HAL_TIM_PeriodElapsedCallback()", strlen("vRS485_CollectInverterData()"), 1000);
HAL_UART_Transmit(&huart2, (uint8_t*)"\r\n", strlen("\r\n"), 1000);
if (htim->Instance == htim3.Instance)
{
vMax7219_ClearDisplay();
switch (uiMax7219Index)
{
case 0: vMax7219_SendNumberToString(ucFreq7219,1); break;
case 1: vMax7219_SendNumberToString(ucInVolt7219,1); break;
case 2: vMax7219_SendNumberToString(ucOutVolt7219,1); break;
case 3: vMax7219_SendNumberToString(ucOutCurr7219,1); break;
case 4: vMax7219_SendNumberToString(ucLoadSpd7219,1); break;
case 5: vMax7219_SendNumberToString(ucOutPwr7219,1); break;
}
uiMax7219Index++;
if (uiMax7219Index > 5) uiMax7219Index = 0;
}
}
控件卡住后,此功能始终在2秒钟后触发.因此得出的结论是,控件被卡在 HAL_Delay()
中.
After the control stuck, this function is always fires after 2 sec. An thus the conclusion that somehow the control is stuck in HAL_Delay()
.
重要的事情
问题每次都会发生,但没有特定的时间,即控件可能在5分钟,10分钟或15分钟后卡住.它不会因特定功能而卡住.功能可能有所不同.也就是说,有时它可能会因函数名称 getIMEI()
而卡住,或者有时它可能是我获取服务提供商
the problem happens everytime but there is no specific time i.e the control might stuck after 5mins and 10 mins or 15mins. It doesnt stuck from a specific function. The functions might be different. i.e sometimes it might get stuck from function name getIMEI()
or sometime it might me get service provider
推荐答案
所有延迟和超时HAL函数都依赖于 SysTick
处理程序中递增的计数器.如果在另一个中断中使用这些功能中的任何一个,则必须确保 SysTick
中断具有比该中断更高的优先级.否则,将永远不会调用 SysTick
处理程序,并且由于计数器永远不会增加,您将陷入无限循环.
All delay and timeout HAL functions rely on a counter incremented in the SysTick
handler. If you are using any of these functions in another interrupt, you have to make sure that the SysTick
interrupt has a higher priority than that interrupt. Otherwise, the SysTick
handler is never called and you will end up in an infinite loop, as the counter will never be increased.
这篇关于HAL_Delay()陷入无限循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!