UART RTS/CTS not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-05-03 5:17 AM
Dear Sir.
I am trying to test for rts/cts , I use a program that transmit a 16 byte data
every 1 ms .
Tying rts or cts to gnd or 3.3v makes no impact on the TX output.
How do I insure that the code works with RTS\CTS ?
Pleas advise
Solved! Go to Solution.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-05-07 5:41 AM
That looks credible to me. (Disclaimer: I don't use HAL).
So my next thoughts are that it could be one of:
- A bug in HAL and (e.g.) ST didn't correctly code that UART4 supports hardware handshaking. So it ignored your request of UART_HWCONTROL_RTS_CTS. Can you check that U(S)ART4->CR3 has the appropriate bit(s) set after HAL_UART_Init(). (If in doubt check the Reference Manual).
- A problem with your test board, perhaps GPIOB7 isn't soldered or doesn't go to where you expect on your test board. Can you program that pin to be output and see that it goes high / low when you want. Also program it to be input and verify that you can read the logic level.
- A problem with the stm32U575, and CTS isn't correctly routed to GPIOB7. I don't see mention of it in the errata, but if the chip is sufficiently new then maybe you're the first to hit this problem. Can you read the (inverted) state of CTS in U(S)ART4->ISR?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-05-03 5:58 AM
Hep us to help you. Show us what you've done so far:
- What board you're using, which pins you expect for TXD, RXD, CTS, RTS
- Your source code, including how you enable the handshaking.
With that, we might be able to give you pointers as to what you might have done wrong.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-05-03 6:19 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-05-07 3:45 AM
Please post the source code in text form in a reply.
And images of schematics where appropriate.
An entire project is way too big for us to wade through and might contain malware so many people won't bother to look.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-05-07 4:09 AM
Hi
Attached some code inn text and c files,
Thanks
Main
usart.c
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file usart.c
* @brief This file provides code for the configuration
* of the USART instances.
******************************************************************************
* @attention
*
* Copyright (c) 2024 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "usart.h"
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
UART_HandleTypeDef huart4;
/* UART4 init function */
void MX_UART4_Init(void)
{
/* USER CODE BEGIN UART4_Init 0 */
/* USER CODE END UART4_Init 0 */
/* USER CODE BEGIN UART4_Init 1 */
/* USER CODE END UART4_Init 1 */
huart4.Instance = UART4;
huart4.Init.BaudRate = 115200;
huart4.Init.WordLength = UART_WORDLENGTH_8B;
huart4.Init.StopBits = UART_STOPBITS_2;
huart4.Init.Parity = UART_PARITY_NONE;
huart4.Init.Mode = UART_MODE_TX_RX;
huart4.Init.HwFlowCtl = UART_HWCONTROL_RTS_CTS;
huart4.Init.OverSampling = UART_OVERSAMPLING_16;
huart4.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
huart4.Init.ClockPrescaler = UART_PRESCALER_DIV1;
huart4.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
if (HAL_UART_Init(&huart4) != HAL_OK)
{
Error_Handler();
}
if (HAL_UARTEx_SetTxFifoThreshold(&huart4, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK)
{
Error_Handler();
}
if (HAL_UARTEx_SetRxFifoThreshold(&huart4, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK)
{
Error_Handler();
}
if (HAL_UARTEx_DisableFifoMode(&huart4) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN UART4_Init 2 */
/* USER CODE END UART4_Init 2 */
}
void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
if(uartHandle->Instance==UART4)
{
/* USER CODE BEGIN UART4_MspInit 0 */
/* USER CODE END UART4_MspInit 0 */
/** Initializes the peripherals clock
*/
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_UART4;
PeriphClkInit.Uart4ClockSelection = RCC_UART4CLKSOURCE_PCLK1;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
{
Error_Handler();
}
/* UART4 clock enable */
__HAL_RCC_UART4_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
/**UART4 GPIO Configuration
PA0 ------> UART4_TX
PA1 ------> UART4_RX
PA15 (JTDI) ------> UART4_RTS
PB7 ------> UART4_CTS
*/
GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_15;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.Alternate = GPIO_AF8_UART4;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
GPIO_InitStruct.Pin = GPIO_PIN_7;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.Alternate = GPIO_AF8_UART4;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
/* USER CODE BEGIN UART4_MspInit 1 */
/* USER CODE END UART4_MspInit 1 */
}
}
void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle)
{
if(uartHandle->Instance==UART4)
{
/* USER CODE BEGIN UART4_MspDeInit 0 */
/* USER CODE END UART4_MspDeInit 0 */
/* Peripheral clock disable */
__HAL_RCC_UART4_CLK_DISABLE();
/**UART4 GPIO Configuration
PA0 ------> UART4_TX
PA1 ------> UART4_RX
PA15 (JTDI) ------> UART4_RTS
PB7 ------> UART4_CTS
*/
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_15);
HAL_GPIO_DeInit(GPIOB, GPIO_PIN_7);
/* USER CODE BEGIN UART4_MspDeInit 1 */
/* USER CODE END UART4_MspDeInit 1 */
}
}
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-05-07 5:41 AM
That looks credible to me. (Disclaimer: I don't use HAL).
So my next thoughts are that it could be one of:
- A bug in HAL and (e.g.) ST didn't correctly code that UART4 supports hardware handshaking. So it ignored your request of UART_HWCONTROL_RTS_CTS. Can you check that U(S)ART4->CR3 has the appropriate bit(s) set after HAL_UART_Init(). (If in doubt check the Reference Manual).
- A problem with your test board, perhaps GPIOB7 isn't soldered or doesn't go to where you expect on your test board. Can you program that pin to be output and see that it goes high / low when you want. Also program it to be input and verify that you can read the logic level.
- A problem with the stm32U575, and CTS isn't correctly routed to GPIOB7. I don't see mention of it in the errata, but if the chip is sufficiently new then maybe you're the first to hit this problem. Can you read the (inverted) state of CTS in U(S)ART4->ISR?
