Skip to content

Commit ffdd7f9

Browse files
committed
[Bsp][stm32f4xx-hal]修复I2C在开启优化时出现延时异常的问题
1 parent d7b70ee commit ffdd7f9

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

bsp/stm32f4xx-HAL/drivers/drv_i2c.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,12 @@ static rt_int32_t drv_get_scl(void *data)
7878

7979
static void drv_udelay(rt_uint32_t us)
8080
{
81-
int i = (HAL_RCC_GetHCLKFreq() / 4000000 * us);
82-
while (i)
81+
__IO uint32_t Delay = us * (SystemCoreClock / 8U / 1000000U);
82+
do
8383
{
84-
i--;
85-
}
84+
__NOP();
85+
}
86+
while (Delay --);
8687
}
8788

8889
static const struct rt_i2c_bit_ops drv_bit_ops =

0 commit comments

Comments
 (0)