cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H723 Nucleo: UART4 not working

BrotherTheo
Associate II

I am stumped and frustrated. I wrote some test code to test UART4. It worked fine. Then I moved the test code over to my main project and now I get no UART interrupts. Both code sets run on the same hardware. I have checked to make sure the UART RX was on the right pin, checked the NVIC settings, even went into the UART registers looking for a difference. Any ideas? 

main code:

 

HAL_UART_Receive_IT(&huart4, rx_buff, 1);

 

IRQ handler:

 

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
	static uint8_t		MeasState=0;	//0=meas, 1=calc
	static uint32_t		OldSample;
	uint32_t			NewSample;
	//static uint32_t		OldTimerValue;
	uint32_t			NewTimerValue;

	if(rx_buff[0]==0xF8)
	{
		if(MeasState==0)
		{
			OldSample=__HAL_TIM_GET_COUNTER(&htim23);
			MeasState=1;
		} else
		{
			NewSample=__HAL_TIM_GET_COUNTER(&htim23);
			MeasState=0;
			NewTimerValue = (NewSample-OldSample)/2560;
			//TIM2->ARR = NewTimerValue;
			__HAL_TIM_SET_AUTORELOAD(&htim2,NewTimerValue);
		}
	}
	HAL_UART_Receive_IT(&huart4, rx_buff, 1);
}

 

 

7 REPLIES 7
Karl Yamashita
Principal

Which pins are you using? PA0/PA1? If so, PA1 is connected to the ethernet controller.

Try PD0 and PD1, or the other possible pin combinations for UART4.

Don't worry, I won't byte.
TimerCallback tutorial! | UART and DMA Idle tutorial!

If you find my solution useful, please click the Accept as Solution so others see the solution.

Using PD0/PD1. Also my test code runs on this hardware with the same pins.

You must be on the wrong pins on the Nucleo? 

 

I've tested UART4 using PD0 and PD1 and I get interrupts.

Here is just a simple code that I used to test receiving 0xF8 and replying back with 01 02 03

 

 

/*
 * PollingRoutine.c
 *
 *  Created on: Oct 24, 2023
 *      Author: karl.yamashita
 *
 *
 *      Template for projects.
 *
 *      The object of this PollingRoutine.c/h files is to not have to write code in main.c which already has a lot of generated code.
 *      It is cumbersome having to scroll through all the generated code for your own code and having to find a USER CODE section so your code is not erased when CubeMX re-generates code.
 *      
 *      Direction: Call PollingInit before the main while loop. Call PollingRoutine from within the main while loop
 * 
 *      Example;
        // USER CODE BEGIN WHILE
        PollingInit();
        while (1)
        {
            PollingRoutine();
            // USER CODE END WHILE

            // USER CODE BEGIN 3
        }
        // USER CODE END 3

 */


#include "main.h"


extern UART_HandleTypeDef huart4;

uint8_t uart4rxData[1] = {0};
uint8_t txData[] = {0x11,0x22,0x33,0x44,0x55};

volatile bool uart4Flag = false;

// called before main while loop
void PollingInit(void)
{
	HAL_UART_Receive_IT(&huart4, uart4rxData, 1);

	HAL_UART_Transmit_IT(&huart4, txData, 5);
}

// called from inside main while loop
void PollingRoutine(void)
{
	UART_CheckFlag();
}

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
	if(huart == &huart4)
	{
		uart4Flag = 1;
		HAL_UART_Receive_IT(&huart4, uart4rxData, 1);
	}
}

void UART_CheckFlag(void)
{
	if(uart4Flag)
	{
		uart4Flag = 0;
		if(uart4rxData[0] == 0xF8)
		{
			txData[0] = 1;
			txData[1] = 2;
			txData[2] = 3;
			HAL_UART_Transmit_IT(&huart4, txData, 3);
		}
	}
}

 

 

 

This is the output from Docklight

 

 

2/12/2025 18:37:53.375 [RX] - 11 22 33 44 55 
2/12/2025 18:37:57.417 [TX] - F8 
2/12/2025 18:37:57.432 [RX] - 01 02 03 
2/12/2025 18:38:05.903 [TX] - F8 
2/12/2025 18:38:05.915 [RX] - 01 02 03 
2/12/2025 18:38:12.999 [TX] - F8 
2/12/2025 18:38:13.008 [RX] - 01 02 03 

 

 

Are you sure you have PD0 as Rx? It's reversed compared to PA0/PA1 where PA1 is Rx. 

 

 

Don't worry, I won't byte.
TimerCallback tutorial! | UART and DMA Idle tutorial!

If you find my solution useful, please click the Accept as Solution so others see the solution.

Yes, PD0 is the RX line.

Do a loop back test short CN11-55 and CN11-57 together. Then transmit to see if you receive.

Or try receiving in polling mode.

Don't worry, I won't byte.
TimerCallback tutorial! | UART and DMA Idle tutorial!

If you find my solution useful, please click the Accept as Solution so others see the solution.
Karl Yamashita
Principal

Upload your ioc file

Don't worry, I won't byte.
TimerCallback tutorial! | UART and DMA Idle tutorial!

If you find my solution useful, please click the Accept as Solution so others see the solution.
mbarg.1
Senior

compare .ioc files - working vs non working.