UART mixed flow control
Hello all,
I have a device connected to a stm32l496rg on a custom via uart.
At system startup, the remote uart may or may not have hardware flow control enabled, so what I want to do is configure the MCU UART for no hardware flow control and put the
RTS and CTS lines in a state which, if it turns out to be in hardware flow control mode, will convince the remote UART that it can send and receive.
the MCU UART is configured initially in cubemx to use hardware flow control, so I use the following function to switch:
static bool rtscts = true; // uart is configured to RTS/CTS in cubemx
static void set_rtscts(bool value) {
/* reconfigure the uart */
HAL_UART_DeInit(&huart2);
huart2.Init.HwFlowCtl = value? UART_HWCONTROL_RTS_CTS: UART_HWCONTROL_NONE;
HAL_UART_Init(&huart2);
if(!value) { /* override RTS and CTS control pins */
GPIO_InitTypeDef gpio = {
.Pin = 0,
.Mode = 0,
.Pull = GPIO_NOPULL,
.Speed = GPIO_SPEED_FREQ_VERY_HIGH,
.Alternate = 0,
};
gpio.Pin = BL_RTS_Pin; gpio.Mode = ??; HAL_GPIO_Init(GPIOA, &gpio);
gpio.Pin = BL_CTS_Pin; gpio.Mode = ??; HAL_GPIO_Init(GPIOA, &gpio);
// set some initial values on rts/cts?
}
}The first thing I'll do is send a command to the remote device to set it to hardware flow control then switch my local uart back and carry on from there.
What configuration and values of the RTS and CTS pins do I need to use to convince the remote UART that it can send and receive if it turns out that it was already in hardware flow control mode?
Thanks