Hardware flow control for USART2 port on STM32F103RC

Post here all questions related to STM32 core if you can't find a relevant section!
Post Reply
razvitm
Posts: 25
Joined: Sat Apr 11, 2020 12:35 pm

Hardware flow control for USART2 port on STM32F103RC

Post by razvitm »

How can I enable hardware flow control RTS CTS in Arduino using the official ST core?
If I configure STM32CubeMx for hardware flow control, in the generated files \src\stm32f1xx_hal_msp.c file, I see that it initializes the RTS CTS pins as output and input together with the RX and TX pins, I'll copy-paste the code below:

else if(huart->Instance==USART2)
{
/* USER CODE BEGIN USART2_MspInit 0 */

/* USER CODE END USART2_MspInit 0 */
/* Peripheral clock enable */
__HAL_RCC_USART2_CLK_ENABLE();

__HAL_RCC_GPIOA_CLK_ENABLE();
/**USART2 GPIO Configuration
PA0-WKUP ------> USART2_CTS
PA1 ------> USART2_RTS
PA2 ------> USART2_TX
PA3 ------> USART2_RX
*/
GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_3;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

GPIO_InitStruct.Pin = GPIO_PIN_1|GPIO_PIN_2;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

/* USER CODE BEGIN USART2_MspInit 1 */

/* USER CODE END USART2_MspInit 1 */
}

Also, there is a mention of hardware flow control in the uart.c file in this location, in the official STM32 core, could I enable HW flow control from here?
c:\Users\Razvan\AppData\Local\Arduino15\packages\STM32\hardware\stm32\1.8.0\libraries\SrcWrapper\src\stm32\uart.c
The line 308 in the file says:
huart->Init.HwFlowCtl = UART_HWCONTROL_NONE;

stas2z
Posts: 123
Joined: Mon Feb 24, 2020 8:17 pm
Answers: 8

Re: Hardware flow control for USART2 port on STM32F103RC

Post by stas2z »

Flow control doesnt supported by core yet

razvitm
Posts: 25
Joined: Sat Apr 11, 2020 12:35 pm

Re: Hardware flow control for USART2 port on STM32F103RC

Post by razvitm »

I just edited the file:
c:\Users\Razvan\AppData\Local\Arduino15\packages\STM32\hardware\stm32\1.8.0\libraries\SrcWrapper\src\stm32\uart.c
i modified line 308 as:
huart->Init.HwFlowCtl = UART_HWCONTROL_RTS_CTS;
Made a simple arduino sketch with some text printing on Serial2 in loop and hardware flow control is working. I have to pull PA0 to GND and the STM32F103RC starts printing on Serial2 port. If I pull CTS(PA0) to 3v3, communication stops.

razvitm
Posts: 25
Joined: Sat Apr 11, 2020 12:35 pm

Re: Hardware flow control for USART2 port on STM32F103RC

Post by razvitm »

Is there a more elegant way of enabling hardware flow control than editing a file in the core?
Like the way we can modify clock speed by copying some lines from what cubemx generates into the arduino sketch?

User avatar
fpiSTM
Posts: 478
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 15
Location: Le Mans
Contact:

Re: Hardware flow control for USART2 port on STM32F103RC

Post by fpiSTM »

Currently not.
I guess the best way would be to add or extend API to be enable the hw flow control

razvitm
Posts: 25
Joined: Sat Apr 11, 2020 12:35 pm

Re: Hardware flow control for USART2 port on STM32F103RC

Post by razvitm »

fpiSTM wrote:
Thu May 21, 2020 12:20 pm
Currently not.
I guess the best way would be to add or extend API to be enable the hw flow control
Well, can't someone modify the Serial.begin() function of the official STM32 arduino core to accept more input parameters that set HW flow control on or off? And also make it backwards compatible by allowing variable number of input parameters so you can ommit the flow control parameter?
The library in the core has flow control capability, someone just needs to add a way for the user to use it in the sketch.

Post Reply

Return to “General discussion”