Issue with Writing to Serial Port in Sensor Driver

I am having some difficulties with writing to a serial port in a sensor driver that I am developing. Using a microcontroller connected to the serial port, I see that no output exists on the serial port when I write to it in the sensor driver. However, the call to ::write returns without errors until it has been called exactly 1500 times (with one byte “written” in each call), and it then only returns -1 with errno 22: EINVAL (as seen through the system console).

Hardware: Pixhawk 4
Firmware version: 1.13.2
Serial port: TELEM1

Debugging done so far:

  1. Verified that the serial connection works correctly when mavlink messages are streamed across the telem1 port using mav_0_config - I see the data show up on my microcontroller.
  2. Tried to setup the lightware_laser_serial driver on telem1. This fails in the same manner as above - calls to write to the port do not raise any errors until ::write has been called 1500 times (1 byte “written” per call), but further calls then fail with errno 22. The microcontroller connected to the port does not receive any data.

Any advice would be much appreciated. It seems that calls to ::write(file_descriptor,&data,sizeof(data)) result in data getting stored in a buffer somewhere (which is getting filled up) instead of getting written to the serial port.

Edit: I am seeing similar behavior with other rangefinder drivers as well - every serial rangefinder driver that I have tried seems not to send any data over serial that I can pick up with my microcontroller. However, GPS, FRSKY telemetry, and mavlink all send data over the serial connection. Still unsure as to what I am doing wrong. Is there a state machine check somewhere that disables output from rangefinder sensor drivers while the system is grounded?


The issue was that RTS/CTS flow control had to be disabled for the UART:

termios uart_config = {};
uart_config.c_cflag &= ~(CSTOPB | PARENB | CRTSCTS);

The CRTSCTS flag was the important one to disable.