Keil5中Manage Run-Time Environment中HAL_Delay死机

2019-07-20 01:33发布

本帖最后由 Sweet 于 2016-5-9 16:36 编辑

最近调试了一个程序,使用的是keil5中Manage Run-Time Environment搭建的库。但是里面的延时函数就是个bug。函数原型与定义如下:
void HAL_Delay(__IO uint32_t Delay);
/**
  * @brief This function provides accurate delay (in milliseconds) based
  *        on variable incremented.
  * @note In the default implementation , SysTick timer is the source of time base.
  *       It is used to generate interrupts at regular time intervals where uwTick
  *       is incremented.
  * @note This function is declared as __weak to be overwritten in case of other
  *       implementations in user file.
  * @param Delay: specifies the delay time length, in milliseconds.
  * @retval None
  */
__weak void HAL_Delay(__IO uint32_t Delay)
{
  uint32_t tickstart = 0;
  tickstart = HAL_GetTick();
  while((HAL_GetTick() - tickstart) < Delay)
  {
  }
}

/**
  * @brief Provides a tick value in millisecond.
  * @note This function is declared as __weak to be overwritten in case of other
  *       implementations in user file.
  * @retval tick value
  */
__weak uint32_t HAL_GetTick(void)
{
  return uwTick;
}

一调用HAL_Delay,CPU就会死机。我在原子的库中重新定义了HAL_Delay,依然死机。但是keil自带的库上面依然有很多函数在调用这个函数。比如SPI,I2C等。这就意味着如果这个问题不解决,那么keil本身的很多外设的驱动就不能直接调用,还要从底层重新写。所以我想解决这个问题。求指教。


友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
6条回答
Sweet
1楼-- · 2019-07-20 06:12
 精彩回答 2  元偷偷看……
taizonglai
2楼-- · 2019-07-20 09:14
滴答定时器没处理好
Sweet
3楼-- · 2019-07-20 11:01
zuozhongkai 发表于 2016-5-9 15:04
滴答定时器没处理好

一般来说怎样处理呢?HAL定时器与原子的Delay定时器是冲突的。我看了原子的底层有启用定时器,关闭定时器。
Sweet
4楼-- · 2019-07-20 16:36
 精彩回答 2  元偷偷看……
正点原子
5楼-- · 2019-07-20 19:19
HAL的延时用的是中断方式延时,很蛋疼。。。
中断里面一定不要调用,否则就死。
情系半生
6楼-- · 2019-07-20 19:40
 精彩回答 2  元偷偷看……

一周热门 更多>