我正试着在我的stm32f4发现上闪烁leds。不知怎么的,它粘在了延迟函数上。我已将SysTick中断优先级更改为0,并添加了IncTick()、GetTick()功能。我遗漏了什么?
#include "stm32f4xx.h" // Device header
#include "stm32f4xx_hal.h" // Keil::Device:STM32Cube HAL:Common
int main(){
HAL_Init();
__HAL_RCC_GPIOD_CLK_ENABLE();
GPIO_InitTypeDef GPIO_InitStruct;
GPIO_InitStruct.Pin = GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15, GPIO_PIN_SET);
HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
HAL_IncTick();
HAL_GetTick();
HAL_Delay(100);
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15, GPIO_PIN_RESET);
}发布于 2017-09-06 15:34:26
函数HAL_IncTick()是从SysTick_Handler()中断调用的,该中断通常在stm32f4xx_it.c中实现。你不能在你的代码中调用这个函数!
void SysTick_Handler(void)
{
HAL_IncTick();
}函数HAL_Init()将SysTick定时器初始化为1毫秒间隔,并使能相关中断。因此,在调用HAL_Init()之后,函数HAL_Delay()应该可以正常工作。
备注:STM32硬件抽象层允许你覆盖(参见 __weak)函数:
HAL_InitTick()HAL_IncTick()HAL_GetTick()HAL_Delay()因此,如果你想使用默认的延迟机制,你不应该在你的代码中实现这些函数!
https://stackoverflow.com/questions/46062122
复制相似问题