After failing to get my ESP8266 NodeMCU board working with rubyserial on OS X, I noticed it worked fine with ser2net and the -RTSCTS flag. The dev board has the RTS pin of the USB UART connected to the the ESP8266 GPIO0 which is held low to put it into flashing mode. rubyserial does this for some reason when it connects.
After digging around in some termios source files for Darwin, I figured out that I need to clear bit 0x10000 from c_cflag to get the equivalent of the ser2net behavior. After trying to figure out where that bit was being set in the first place, and why it was defaulting to ON, I realized it was coming from OR-ing the baud rate (115200 in my case) into c_cflag. The most significant bit of 115200 converted to binary is the same bit in question.
I could be wrong about this, but I don't think the baud rates are supposed to be masked into c_cflag the way they are for Linux. In osx_constants.rb each baud rate maps back to itself as an integer. Compare this to Linux where the last 4 bits of c_cflag map to specific baud rates, and one other bit is a flag to access higher values. For OS X, bits that would control settings overlap with bits that would set the baud rate. Doesn't seem right at all.
The fix in this PR solves my problem where the RTS pin was being toggled, so the NodeMCU works over its built in USB port now and, as far as I can tell, doesn't break any functionality.
After failing to get my ESP8266 NodeMCU board working with
rubyserial
on OS X, I noticed it worked fine withser2net
and the-RTSCTS
flag. The dev board has the RTS pin of the USB UART connected to the the ESP8266 GPIO0 which is held low to put it into flashing mode.rubyserial
does this for some reason when it connects.After digging around in some
termios
source files for Darwin, I figured out that I need to clear bit 0x10000 fromc_cflag
to get the equivalent of theser2net
behavior. After trying to figure out where that bit was being set in the first place, and why it was defaulting to ON, I realized it was coming from OR-ing the baud rate (115200 in my case) intoc_cflag
. The most significant bit of 115200 converted to binary is the same bit in question.I could be wrong about this, but I don't think the baud rates are supposed to be masked into
c_cflag
the way they are for Linux. Inosx_constants.rb
each baud rate maps back to itself as an integer. Compare this to Linux where the last 4 bits ofc_cflag
map to specific baud rates, and one other bit is a flag to access higher values. For OS X, bits that would control settings overlap with bits that would set the baud rate. Doesn't seem right at all.The fix in this PR solves my problem where the RTS pin was being toggled, so the NodeMCU works over its built in USB port now and, as far as I can tell, doesn't break any functionality.