0
\$\begingroup\$

I have a PIC24FJ MCU with an FT232RL USB to UART controller. My design has end users opening a serial connection to my MCU to set parameters and get debug information.

My question is: How can I tell when the end user has opened screen/PuTTY/etc to my device's COM port?

From what I have read, the DTR signal is not a good way to go about this as the OS decides when to raise DTR.

My use case is that I would like to display a banner with help commands as soon as the COM port is opened.

\$\endgroup\$
3
\$\begingroup\$

You are correct that DTR can be overridden by OS, but in practice, it is actually a pretty good indicator. And in Linux, it is pretty hard to disable [0].

If you have USB support in your chip, you can implement CDC class serial device natively. This usually does not require any drivers, and gives you full information, including when the port is open. Once very nice property in using on-chip CDC implementation (as opposed to external FTDI chip), is that you can ignore baudrate completely -- so user will be able to talk to your device no matter which speed they choose in putty settings.

[0] https://unix.stackexchange.com/questions/446088/how-to-prevent-dtr-on-open-for-cdc-acm

\$\endgroup\$
  • \$\begingroup\$ Thanks! I will give the DTR pin on the FT232RL a go. Unfortunately, I need the FT232 to interface with another IC on the board for which I have no other means of communication in order to upgrade it's firmware. \$\endgroup\$ – t3ddftw Oct 1 at 3:08
  • 2
    \$\begingroup\$ @t3ddftw - if you implement USB directly in your MCU you could also implement a USB to serial bridge on behalf of that other target on the board. \$\endgroup\$ – Chris Stratton Oct 1 at 3:32
  • \$\begingroup\$ @ChrisStratton - That's something I hadn't really put much thought into. I'll definitely have a look at that as it could save me a decent amount of parts on the BOM. Thanks! \$\endgroup\$ – t3ddftw Oct 1 at 15:14
2
\$\begingroup\$

I don't think you can rely on the handshaking lines to signal that a user is connected to a serial port. I don't think I've ever made a serial cable with more than RX, TX and GND. You will probably have to wait for the user to hit a key, then respond to that with your banner.

\$\endgroup\$
  • 1
    \$\begingroup\$ OP does not have a serial port, they have FT232RL controller. So no serial cables are involved, and there is no opportunity for end user to omit any signals. \$\endgroup\$ – theamk Oct 1 at 1:59
  • 1
    \$\begingroup\$ Regardless of wiring, the host's issuance of USB operations to set modem control signals, while typical, is not truly deterministic unless you control it's software stack. \$\endgroup\$ – Chris Stratton Oct 1 at 2:52
1
\$\begingroup\$

Use DTR that's what it's for!

All regular terminal software will raise DTR.

It's true that the OS (and even application software) can manipulate the DTR signal, but unless there is some vulnerability exposed by having them connected while DTR is not asserted there will be no motivation to de-assert DTR, an no problem caused by that ability.

Many terminal softwares can briefly disable DTR by pressing a hot-key (traditionally alt-h for "hang-up")

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.