Description
I'm running the UART (Serial1) port for a length of time, then turning it off and trying to use it as an output, but this fails silently. I expect to be able to set the mode to OUTPUT and write values to it after Serial1.end()
has been called.
The reason that this fails is that UARTClass::init
includes this code:
SET_PIN_MODE(17, UART_MUX_MODE); // Rdx SOC PIN (Arduino header pin 0)
SET_PIN_MODE(16, UART_MUX_MODE); // Txd SOC PIN (Arduino header pin 1)
Notably, this doesn't update ulPinMode
in g_APinDescription[0]
and g_APinDescription[1]
.
pinMode()
does contain code that is supposed to change the MUX mode back to the correct value:
if (p->ulPinMode != GPIO_MUX_MODE) {
SET_PIN_MODE(p->ulSocPin, GPIO_MUX_MODE);
p->ulPinMode = GPIO_MUX_MODE;
}
Unfortunately, this code assumes that ulPinMode
is up-to-date. In combination with the missing update in UARTClass::init
, this means that pinMode()
falsely assumes that it doesn't need to change the MUX mode of the pin.
Expected behavior: pinMode
should change the MUX mode of a pin, even if it was previously used by the UART.
Suggested fix, if I understand correctly: Update g_APinDescription[0].ulPinMode
and g_APinDescription[1].ulPinMode
in UARTClass::init
.