Skip to main content
magene
Senior
May 15, 2021
Solved

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

  • May 15, 2021
  • 9 replies
  • 3777 views

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

This topic has been closed for replies.
Best answer by Pavel A.

.

9 replies

magene
mageneAuthor
Senior
May 15, 2021

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
mageneAuthor
Senior
May 19, 2021

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
May 19, 2021

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
Associate
May 19, 2021

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
mageneAuthor
Senior
June 17, 2021

@Ons KOOLI​ I'm still working on this and making slow progress. I'd very much like to find a consultant experienced with the STM32H7A3 to get us up the learning curve more quckly than I can by myself. Can you recommend anyone? And if they know VisualGDB that would be icing on the cake.

Thanks

magene
mageneAuthor
Senior
May 19, 2021

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.
Pavel A.Best answer
Super User
May 19, 2021

.

SThir.4
Associate
May 20, 2021

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
mageneAuthor
Senior
May 20, 2021

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.

Pavel A.
Super User
May 20, 2021

I doubt that uncommenting HAL_USART_MODULE_ENABLED solved the problem.

milamber
Associate II
June 12, 2021

Is there a solution to this? i have the same problem both in a nucleo and in a custom h7a3 board. when i try to read multiple uarts at low speeds with parity (9600) i can get anything to work

magene
mageneAuthor
Senior
June 16, 2021

As I mentioned, I was able to get the STM provided IT and DMA examples working. Currently I'm only working iwth 1 UART but will eventually have to talk to a bunch. My first step will be to modify my working 1 UART example to work with the second UART port I want to work with. Then I'd combine those 2 single UART programs into 1 program that hopefully talks to 2 UARTs. Have you tried something like that?

milamber
Associate II
June 17, 2021

Good luck. You will realize that its not as easy as it sounds. I am using stm32h7a3 and after spending 3 weeks I managed to get 2 uarts with IT and DMA firing their interrupts every single character, working. Every single effort to have the fire after a number of chars were received, failed. The moment I added a third uart things started falling apart. I wasnt able to make any of their examples work on their nucleo-144. Perhaps they work in their M0 models. I have 7 more uarts and 1 i2c to go. Most likely we will ditch the stm32 series. Very poor support, lack of documentation and proper examples, and a lot of bugs in their hal libraries isnt reassuring. I have seen chinese cpu manufacturers providing considerably better support for their product. Quite a few people are suggesting to move away from HAL to LL but i am not convince that its really worth the trouble investing in something like that.