Skip to main content
JGusl.1
Associate
November 9, 2022
Question

I am trying to setup UART on an STM32L072CZTX. I am using interrupt mode and the interrupt seems to be firing due to a pause in main loop execution but nothing inside the interrupt seems to be occurring

  • November 9, 2022
  • 18 replies
  • 2783 views

I am trying to setup UART on an STM32L072CZTX. In the ioc file I have setup the pins, RX is set to AF4 pullup, and TX is AF4 nopull. The interrupt is set to 0 and enabled. I have redefined the RxCpltCallback in the main and have events occur in there that work when run from main. I can see a pause in main execution (a simple blinking light) but nothing inside the interrupt seems to be happening, flags being set or a different LED blinking.

This topic has been closed for replies.

18 replies

Karl Yamashita
Principal
November 9, 2022

You don't say what mode you're using to receive data. Are you polling, interrupt or DMA?

If a reply has proven helpful, click on Accept as Solution so that it'll show at top of the post.CAN Jammer an open source CAN bus hacking toolCANableV3 Open Source
JGusl.1
JGusl.1Author
Associate
November 9, 2022

"I am using interrupt mode"

Karl Yamashita
Principal
November 9, 2022

post your code for RxCpltCallback().

If a reply has proven helpful, click on Accept as Solution so that it'll show at top of the post.CAN Jammer an open source CAN bus hacking toolCANableV3 Open Source
JGusl.1
JGusl.1Author
Associate
November 9, 2022
volatile uint8_t flag = 0;
 
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
	flag = 1;
	//HAL_UART_Transmit(&huart1, UART_RX_BUFFER, sizeof(UART_RX_BUFFER), 100);
	//HAL_Delay(500);
	HAL_UART_Receive_IT(&huart1, UART_RX_BUFFER, 20); //restart the interrupt reception
}
main (void)
{
HAL_UART_Receive_IT(&huart1, UART_RX_BUFFER, 20);
 while (1)
	{
		if (flag == 1)
		{
 
			HAL_GPIO_WritePin(GPIOB, RED_LED, GPIO_PIN_SET);
			HAL_Delay(250);
			HAL_GPIO_WritePin(GPIOB, RED_LED, GPIO_PIN_RESET);
			HAL_Delay(250);
 
			flag = 0;
		}
		else
		{
 
			HAL_GPIO_WritePin(GPIOB, GREEN_LED, GPIO_PIN_SET);
			HAL_Delay(250);
			HAL_GPIO_WritePin(GPIOB, GREEN_LED, GPIO_PIN_RESET);
			HAL_Delay(250);
 
		}
}

JGusl.1
JGusl.1Author
Associate
November 9, 2022

That main loop never changes to the RED_LED loop

Karl Yamashita
Principal
November 9, 2022

what kind of UART data are you expecting?

If a reply has proven helpful, click on Accept as Solution so that it'll show at top of the post.CAN Jammer an open source CAN bus hacking toolCANableV3 Open Source
JGusl.1
JGusl.1Author
Associate
November 9, 2022

Just strings. I'm trying to inject them temporarily using a serial monitor. Im sending strings longer than 20 bytes

Karl Yamashita
Principal
November 9, 2022

Your code looks like it should toggle the red led then back to blinking the green led. I have to drive to work now. When I get there I can try it on a dev board. What STM32 are you using and what pins are the leds on?

If a reply has proven helpful, click on Accept as Solution so that it'll show at top of the post.CAN Jammer an open source CAN bus hacking toolCANableV3 Open Source
JGusl.1
JGusl.1Author
Associate
November 9, 2022

STM32L072CZTX, im using PB8 and PB9, but its a custom board, not a dev board

waclawek.jan
Super User
November 9, 2022

Polled UART Rx works?

A simple test, in main loop reading the UART Rx pin input state and setting/clearing LED accordingly, works?

LED blinky alone, works?

JW