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本身的很多外设的驱动就不能直接调用,还要从底层重新写。所以我想解决这个问题。求指教。


友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。