AnsweredAssumed Answered

UART Receive Interrupt on STM32f0 using CubeMX / Keil (how?)

Question asked by burkhardt.simon on Feb 16, 2016
Latest reply on Feb 18, 2016 by markt
My tools:
STM32f072rb (NUCLEO)
MCP2200 uart to usb board
STM32CubeMX (4.12.0)
Keil uVision 5 (5.17)

What I'm trying to do:
Running a program in the main loop and reading UART transmission into a ring buffer.
(as soon as Rx signal is present, an interrupt is triggered which reads the incomming data)

Init code was generated using CubeMX, setting up
UART2, 8Bits 9600 Baud, no HW flow control, on STLink debugger
UART1, 8Bits 9600 Baud, no HW flow control, on MCP2200

One attempt of mine was connecting the Rx2 pin to EXTI6, triggering a GPIO interrupt and readingfrom there.
(Receiving char on UART2, echo it to UART1)
This worked well for only one char and is imo. a really dirty solution.

In CubeMX, under NVIC the UART2 global interrupt through EXTI line 26 is selected, and the USART2_IRQHandler() is generated into stm32f0xx_it.c
When trying to test it by toggling the LD2 led, nothing happens on an incomming Rx signal. It does work when calling HAL_UART_Transmit_IT()

void USART2_IRQHandler(void)
{
  /* USER CODE BEGIN USART2_IRQn 0 */
    HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5);

  /* USER CODE END USART2_IRQn 0 */
  HAL_UART_IRQHandler(&huart2);
  /* USER CODE BEGIN USART2_IRQn 1 */

  /* USER CODE END USART2_IRQn 1 */
}

After hours of googling, there seems to be a possible solution using Rx interrupts.
However I have not found a way to implement it with the tools I am using.
Some attempts use NVIC

NVIC_InitTypeDef NVIC_InitStructure;
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);


However the NVIC_InitTypeDef is not present within the HAL libraries.

Does anyone see any obvious flaws?

Thanks in advance

Attachments

Outcomes