Skip to content

UARTClass.begin -> UARTClass.end -> pinMode fails to change MUX mode back #241

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
celskeggs opened this issue Jul 15, 2016 · 1 comment
Closed
Labels
Milestone

Comments

@celskeggs
Copy link

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.

@eriknyquist eriknyquist self-assigned this Jul 15, 2016
@eriknyquist
Copy link
Contributor

Hi @celskeggs, thanks for bringing this to our attention. I'll take a look at this and notify you as soon as it's fixed.

eriknyquist added a commit to eriknyquist/corelibs-arduino101 that referenced this issue Jul 15, 2016
UARTClass::init() muxes out the UART pins to Arduino header pins 0/1.
Reset the mux on UARTClass::end() so that pins 0/1 can be used as GPIOs
again.
@kitsunami kitsunami added this to the Castor milestone Jul 18, 2016
sgbihu pushed a commit to sgbihu/corelibs-arduino101 that referenced this issue Jul 29, 2016
UARTClass::init() muxes out the UART pins to Arduino header pins 0/1.
Reset the mux on UARTClass::end() so that pins 0/1 can be used as GPIOs
again.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants