cancel
Showing results for 
Search instead for 
Did you mean: 

Could use some help getting a UART working in interrupt mode on a Nucleo H7A3ZI-Q

magene
Senior II

I've had some success getting UARTs to work on a Nucleo 413ZH board but am struggling to get the same code working on a Nucleo H7A3ZI-Q board. I have a logic analyzer connected to the TX and RX pins on the Nucleo boards. The HAL_UART_Transmit line (line 72) works fine and I can see the whole txBuffer on the logic analyzer. But the HAL_UART_Transmit_IT line (line 73) only transmits the first 2 characters of the txBuffer according to what I see on my logic analyzer.

I'm sure I don't have something in one of the interrupt routines configured correctly but I sure can't figure it out and would appreciate any help.

Thanks

#include <stm32h7xx_hal.h>
#include <stm32_hal_legacy.h>
 
#ifdef __cplusplus
extern "C"
#endif
void SysTick_Handler(void)
{
	HAL_IncTick();
	HAL_SYSTICK_IRQHandler();
}
 
static UART_HandleTypeDef s_UARTHandle = UART_HandleTypeDef();
 
extern "C" void USART2_IRQHandler()
{
	HAL_UART_IRQHandler(&s_UARTHandle);
}
 
void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart)
{
	HAL_Delay(1);
}
 
static uint8_t rxBuffer[10];
static uint8_t msgBuffer[256];
static uint8_t msgIndex = 0;
 
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
	HAL_Delay(1);
}
 
 
int main(void)
{
	HAL_Init();
	
	__USART2_CLK_ENABLE();
	__GPIOD_CLK_ENABLE();
    
	GPIO_InitTypeDef uartGPIO_InitStructure;
 
	//TX
	uartGPIO_InitStructure.Pin = GPIO_PIN_5;
	uartGPIO_InitStructure.Mode = GPIO_MODE_AF_PP;
	uartGPIO_InitStructure.Alternate = GPIO_AF7_USART2;
	uartGPIO_InitStructure.Speed = GPIO_SPEED_HIGH;
	uartGPIO_InitStructure.Pull = GPIO_NOPULL;
	HAL_GPIO_Init(GPIOD, &uartGPIO_InitStructure);
    
	//RX
	uartGPIO_InitStructure.Pin = GPIO_PIN_6;
	uartGPIO_InitStructure.Mode = GPIO_MODE_AF_OD;
	HAL_GPIO_Init(GPIOD, &uartGPIO_InitStructure);
 
	s_UARTHandle.Instance        = USART2;
	s_UARTHandle.Init.BaudRate   = 9600;
	s_UARTHandle.Init.WordLength = UART_WORDLENGTH_8B;
	s_UARTHandle.Init.StopBits   = UART_STOPBITS_1;
	s_UARTHandle.Init.Parity     = UART_PARITY_NONE;
	s_UARTHandle.Init.HwFlowCtl  = UART_HWCONTROL_NONE;
	s_UARTHandle.Init.Mode       = UART_MODE_TX_RX;
    
	if (HAL_UART_Init(&s_UARTHandle) != HAL_OK)
		asm("bkpt 255");
	
	NVIC_EnableIRQ(USART2_IRQn);
 
	uint8_t txBuffer[] = "this is a test of the vgdb UART example";
	
	HAL_UART_Transmit(&s_UARTHandle, (uint8_t*)txBuffer, sizeof(txBuffer), HAL_MAX_DELAY);
	HAL_UART_Transmit_IT(&s_UARTHandle, (uint8_t*)txBuffer, sizeof(txBuffer));
	
	HAL_Delay(1000);
}

1 ACCEPTED SOLUTION

Accepted Solutions
Pavel A.
Evangelist III
17 REPLIES 17
magene
Senior II

And I should have mentioned, the HAL_UART_TxCpltCallback routine never gets called. I also tried running the ST Micro provided UART_IT example and get the same result, only the first 2 characters or txBuffer are sent by the HAL_UART_Transmit_IT command.

magene
Senior II

Still struggling with this and hoping someone can suggest what I might be doing wrong. This is basically the same code I use successfully on the F413. Is there something different about interrupt driven UARTs with the H7 family?

SThir.4
Associate II

Hi,

Maybe you should try first to use an example which works with UART like "UART_TwoBoards_ComIT" for your MCU and modified the code step by step, like the code in the hal_msp.c file.

I don't know if doing that is good or not :

HAL_UART_Transmit(&s_UARTHandle, (uint8_t*)txBuffer, sizeof(txBuffer), HAL_MAX_DELAY);
HAL_UART_Transmit_IT(&s_UARTHandle, (uint8_t*)txBuffer, sizeof(txBuffer));

Ons KOOLI
Senior III

Hi @magene​ ,

You can refer to the STM32CubeH7 Package FW, under directory : Projects\NUCLEO-H7A3ZI-Q\Examples\UART\UART_TwoBoards_ComIT

Best Regards,

Ons.

magene
Senior II

I mentioned in a previous message that I get the same result with the "ST Micro provided UART_IT example". That is in fact the UART_TwoBoards_ComIT example that you refer to. I work in the Visual GDB IDE but I've also run the example in the STM32CubeIDE. Is it correct to assume that someone at ST Micro has run this example on the Nucleo H7A3 board?

I'm still working on this issue and I think I've narrowed it down to this subroutine static void UART_TxISR_8BIT(UART_HandleTypeDef *huart) in stm22H7xx_hal_uart.c (see below). I'm still trying to figure out what's going on in more detail and any suggestions will be greatly appreciated.

static void UART_TxISR_8BIT(UART_HandleTypeDef *huart)
{
  /* Check that a Tx process is ongoing */
  if (huart->gState == HAL_UART_STATE_BUSY_TX)
  {
    if (huart->TxXferCount == 0U)
    {
      /* Disable the UART Transmit Data Register Empty Interrupt */
      CLEAR_BIT(huart->Instance->CR1, USART_CR1_TXEIE_TXFNFIE);
 
      /* Enable the UART Transmit Complete Interrupt */
      SET_BIT(huart->Instance->CR1, USART_CR1_TCIE);
    }
    else
    {
      huart->Instance->TDR = (uint8_t)(*huart->pTxBuffPtr & (uint8_t)0xFF);
      huart->pTxBuffPtr++;
      huart->TxXferCount--;
    }
  }
}

Pavel A.
Evangelist III

.

SThir.4
Associate II

I cannot say for 7A3 but serial examples (Pooling, IT or DMA) are working on Nucleo ZI and Eval2 for H743/753 series.

Your decision but you would be more efficient or time saving by installing another IDE like Keil, compile the example code provided and check the serial communication through the STLink with a serial software like Docklight.

And if it's working, maybe you can start to compare both IDE.

magene
Senior II

With all you help, I think I fixed the problem. Some combination of uncommenting this line in stm32h7xx_hal_conf.h

/* #define HAL_USART_MODULE_ENABLED */

And making sure I didn't have a break point in a place that might have hung the interrupt process. Unfortunately, I changed both those things at the same time and haven't been able to recreate the problem so I don't know which one was the fix.

Thanks for all the help including @Pavel A.​ . Even though his original suggestion wasn't exactly right, it did get me thinking about the fact that I have to make sure both UART and USART functionality is enabled.

I doubt that uncommenting HAL_USART_MODULE_ENABLED solved the problem.