Skip to main content
Associate II
May 22, 2024
Solved

Simple UART problem STM32H753

  • May 22, 2024
  • 4 replies
  • 3585 views

Hi,
I'm relatively new to the STM32 world and I'm becoming frustrated that I can't make a simple UART work. No DMA, no interrupts just trying to send bytes out of the UART and then receive them. Here is my setup code:

 

 

 

 

 

 

void UART7_Init(void)
{

	GPIO_InitTypeDef GPIO_InitStruct;

		HAL_Init();


	 /* Peripheral clock enable */
 __HAL_RCC_UART7_CLK_ENABLE();
 __HAL_RCC_GPIOF_CLK_ENABLE();

 /**UART7 GPIO Configuration
 PF6 ------> UART7_RX
 PF7 ------> UART7_TX
 PF8 ------> UART7_RTS
 PF9 ------> UART7_CTS
 */
 GPIO_InitStruct.Pin = U7_PAY_RX_SPI5_NSS_Pin|U7_PAY_TX_SPI5_SCK_Pin;
 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
 GPIO_InitStruct.Pull = GPIO_NOPULL;
 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
 GPIO_InitStruct.Alternate = GPIO_AF7_UART7;
 HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);


 huart7.Instance = UART7;
 huart7.Init.BaudRate = 115200;
 huart7.Init.WordLength = UART_WORDLENGTH_8B;
 huart7.Init.StopBits = UART_STOPBITS_1;
 huart7.Init.Parity = UART_PARITY_NONE;
 huart7.Init.Mode = UART_MODE_TX_RX;
 huart7.Init.HwFlowCtl = UART_HWCONTROL_NONE;
 huart7.Init.OverSampling = UART_OVERSAMPLING_16;
 huart7.Init.OneBitSampling = UART_ONEBIT_SAMPLING_DISABLED;
 huart7.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;

 	if(HAL_UART_Init(&huart7) != HAL_OK)
 	{
 		asm("bkpt 255"); // Just for degugging
 		Error_Handler();
 	}

 /* UART7 interrupt Init */
 //HAL_NVIC_SetPriority(UART7_IRQn, 5, 0);
 //HAL_NVIC_EnableIRQ(UART7_IRQn);
 /* USER CODE BEGIN UART7_MspInit 1 */

 /* USER CODE END UART7_MspInit 1 */
 }

 

 

 

 

And here is the actual transmit code:

 

 

 

do
	{
	drv_led_toggle(DRV_LED_ID_AMBER);
	HAL_UART_Transmit(&huart7, receiveBuffer, sizeof(receiveBuffer), TIMEOUT);
	HAL_Delay(300);
	//HAL_UART_Receive(&huart7, receiveBuffer, 1, TIMEOUT);
	drv_led_toggle(DRV_LED_ID_AMBER);
	HAL_Delay(300);

	if(UART7->ISR & (1<<5))
	 {
		HAL_UART_Receive(&huart7, receiveBuffer , 1 /*sizeof(receiveBuffer)*/, TIMEOUT);
	 }

	if(i%2)drv_led_toggle(DRV_LED_ID_AMBER);


	} while(i<5);

 

 

 

 

I'm pretty sure that it's something simple and I'm just missing it. Any advice is appreciated.

Thanks.

Best answer by GlennH

Thank you all for the suggestions. I found that I was looking at the wrong pins on the PC-104 connector. It's working fine now!

 

Thanks again,

Glenn

 

4 replies

Andrew Neil
Super User
May 22, 2024

How are you attempting to observe the transmitted bytes?

Is this on an ST board?

  • If yes, which one?
  • If not, please provide schematics.
A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
GlennHAuthor
Associate II
May 22, 2024

I'm observing the output on an Analog discovery pro as a Logic analyzer. I have also hooked up a basic USB to serial TX pin on another channel as a sanity check that it is working.

It is not on an ST eval board it is on a proprietary CubeSat "On Board Computer".

 

Thanks!

 

mƎALLEm
ST Technical Moderator
May 22, 2024

Hello,

just trying to send bytes out of the UART and then receive them. Here is my setup code:

Send receive to which device? a PC HyperTerminal or what? or looping back Tx/Rx?

Need to give more details ..

To give better visibility on the answered topics, please click "Best answer" on the reply which solved your issue or answered your question.
GlennHAuthor
Associate II
May 22, 2024

Currently, I'm observing the TX pin on a logic analyzer. Just want to see it actually transmit something right now.

Thanks.

 

Tesla DeLorean
Guru
May 22, 2024

Send known patterns. 0x55 would be good for checking baud rates at 8N1

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
Tesla DeLorean
Guru
May 22, 2024

Send a readable string first, check on terminal.

For receive need to make sure any kind of receive error is cleared, ie noise, framing, parity, etc

PF6/PF7 AF7 for UART7 seem correct

Polled method are inherently half-duplex, there aren't deep buffers, not going to capture standing waves from signals transmitted 300 ms earlier. Even if TX/RX looped back.

Transmit a continuous 0x55 'U' pattern, confirm baud / bit timing with a scope.

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
GlennHAuthorBest answer
Associate II
May 22, 2024

Thank you all for the suggestions. I found that I was looking at the wrong pins on the PC-104 connector. It's working fine now!

 

Thanks again,

Glenn