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

17 REPLIES 17
milamber
Associate II

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

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?

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.

btw what was Pavel's A answer? i only see a . in his answer

I'm guessing that Pavel A. removed his answer because, if I remember correctly, it wasn't strictrly correct. Regardless, It did start me down the path that finally led to a solution. I agree with your comments about HAL but I haven't found a vendor that offers so many uControllers that work for my various projects and nothing like the H7A3 anywhere. The other thing I'm trying is using STM32IDE and the integrated MXCube functionality to create a base project with all the devices I'm interested in using. I've gone that far and the IDE sets up a program that initializes all the peripherals but doesn't add any application code to use the peripherals. I'm hoping I'll be able to add the application code based on what I learned from the examples and what understaning I've been able to glean from the manuals. This is a background task for me so I don't get to work on it very often which adds to my frustration.

BTW, I've been trying to find a good STM32 consultant to get us up the learning curve faster that me bashing my head against the wall. If anyone knows of someone I can contact, that would be greatly appreciated.

What IDE are you using?

@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

i am using visualgdb with their cubemx project integration. what is your projects high level specs? we want to use 11 uarts + 1 i2c4 at 9600

We're porting code written in C# with the .NET Micro Framework to C/C++ on a H7A3 board. I'm starting with the NucleoH7A3 but am designing a custom board in parallel. My custom board is basically a respin of the H7A3 Nucleo and H7B3 eval board with my additional proejct specific circuitry. I think I mentioned I use VGDB also. We need 6 UARTs running at 9600 to 115K with a few spares for future expansion. We have at least 6 I2C devices a few of which share the same address. SDMMC for uSD card, external flash and RAM. And 1 SPI device. I work for an oceanographic research institute and resources are extremely valuable so I'm looking hard for a consultant to help with this project.