cancel
Showing results for 
Search instead for 
Did you mean: 

Receive UART WWDG_IRQHandler infinite loop

Lorenzo Ruda
Associate
Posted on December 21, 2017 at 14:25

Good morning. I'v tried to perform an UART receive on stm32f407vg board using RXNE interrupt. But when i execute the code it is blocked on WWDG_IRQHandler infinite loop. I post my code:

#include 'stm32f4xx.h'

#include 'stm32f407xx.h'

#include 'stm32f4xx_hal_gpio.h'

#include 'stm32f4xx_hal_rcc.h'

#include 'stm32f4xx_hal.h'

#include 'stm32f4xx_hal_uart.h'

#include 'stm32f4xx_hal_cortex.h'

#include 'stm32f4xx_hal_pwr.h'

#include <stdio.h>

#include 'semihosting.h'

#define UART_BUFFER_SIZE 64

uint8_t UART_BUFFER[UART_BUFFER_SIZE];

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *uart_handle) {

    int i;

    for(i=0; i < UART_BUFFER_SIZE; i++)

        printf(uart_handle->pRxBuffPtr[i]);

}

int main() {

    __GPIOA_CLK_ENABLE();

    __UART4_CLK_ENABLE();

    __PWR_CLK_ENABLE();

    __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);

    RCC_OscInitTypeDef RCC_OscInitStruct;

    RCC_ClkInitTypeDef RCC_ClkInitStruct;

    RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;

    RCC_OscInitStruct.HSIState = RCC_HSI_ON;

    RCC_OscInitStruct.HSICalibrationValue = 16;

    RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;

    HAL_RCC_OscConfig(&RCC_OscInitStruct);

    RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK

                                  |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;

      RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;

      RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;

      RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;

      RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

      HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0);

      HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);

      HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);

    GPIO_InitTypeDef gpio_init;

    gpio_init.Pin=GPIO_PIN_1;

    gpio_init.Mode=GPIO_MODE_AF_PP;

    gpio_init.Pull=GPIO_PULLUP;

    gpio_init.Speed=GPIO_SPEED_MEDIUM;

    gpio_init.Alternate=GPIO_AF8_UART4;

    HAL_GPIO_Init(GPIOA, &gpio_init);

    UART_InitTypeDef uart_init;

    uart_init.BaudRate=9600;

    uart_init.HwFlowCtl=UART_HWCONTROL_NONE;

    uart_init.Mode=UART_MODE_RX;

    uart_init.OverSampling=UART_OVERSAMPLING_16;

    uart_init.Parity=UART_PARITY_NONE;

    uart_init.StopBits=UART_STOPBITS_1;

    uart_init.WordLength=UART_WORDLENGTH_8B;

    UART_HandleTypeDef uart_handle;

    uart_handle.Init=uart_init;

    uart_handle.Instance=UART4;

    uart_handle.RxXferCount=0;

    uart_handle.RxXferSize=UART_BUFFER_SIZE;

    uart_handle.pRxBuffPtr=UART_BUFFER;

    HAL_UART_Init(&uart_handle);

    HAL_NVIC_EnableIRQ(UART4_IRQn);

    HAL_NVIC_SetPriority(UART4_IRQn, 0, 0);

    __HAL_UART_ENABLE_IT(&uart_handle, UART_IT_RXNE);

    __HAL_UART_ENABLE(&uart_handle);

  while(1) {

      if(__HAL_UART_GET_IT_SOURCE(&uart_handle, UART_IT_RXNE) && __HAL_UART_GET_FLAG(&uart_handle, UART_FLAG_RXNE)) {

          HAL_UART_IRQHandler(&uart_handle);

                                                                                                                     }

}

}

Can you tell me if there is anything wrong? Suggests? Answers? Thank you very much. Goodbye.

0 REPLIES 0