UART receive detection
Use a timer, in the UART receive interrupt you write the timer update flag, TIMx_EGR->UG.

Enable TIMx_CR1->URS, update request source, to disable interrupt generation when software triggers an update event via the UG bit.

When you write UG (write only bit) the timer is reloaded with TIMx_ARR, auto reload value, which is your maximum communication timeout.
When the timer expires, as in it over or underflows, it fires the timer interrupt telling you the communication has expired.
All timers can do this, little math required to compute ARR with the basic timers since these have no countdown mode.

You could also use the Windowed Watchdog Timer for this.



Other option is to look at the signal levels after the RS-232 driver, or use the hardware flow control signals.
Note that TTL level uart is not intended for operation over a cable.