2017-09-05 5 views
0

J'essaye de cligner des leds sur ma découverte stm32f4. D'une manière ou d'une autre, il s'est bloqué sur la fonction de retard. J'ai changé la priorité d'interruption SysTick à 0 et ajouté les fonctions IncTick(), GetTick(). Qu'est-ce que je rate?Retard dans la bibliothèque HAL (HAL_Delay())

#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); 
} 

Répondre

1

Fonction HAL_IncTick(); doit appelé de SysTick_Handler d'interruption, généralement mis en œuvre dans le fichier stm32f4xx_it.c, vous ne l'appelez pas cette fonction de votre code!

void SysTick_Handler(void) 
{ 
    HAL_IncTick(); 
} 

La fonction minuterie HAL_Init(); Initialiser sysTick sur 1ms et activer interruption. Donc, après HAL_Init, HAL_Delay devrait fonctionner correctement.

REMARQUE: STM32HAL autorise les fonctions override (voir mot-clé __weak): HAL_InitTick, HAL_IncTick, HAL_GetTick HAL_Delay. Donc, si vous voulez utiliser le mécanisme de délai par défaut, vous ne devriez pas implémenter ces fonctions dans votre code!