arduino / ArduinoCore-renesas

MIT License
109 stars 74 forks source link

After reset pin 13 is configured as an output #57

Open technoblogy opened 1 year ago

technoblogy commented 1 year ago

On the Uno R4 Minima and Uno R4 WiFi, pin 13 is made an output after reset, so if you do:

void setup() {
  Serial.begin(9600);
  delay(5000);
}

void loop () {
  Serial.println(digitalRead(13));
  delay(1000);
}

and apply 5V to the pin (via a resistor for safety), you still get 0.

The usual Arduino convention is that all digital pins are inputs after reset, and to make a pin an output you have to call pinMode(13, OUTPUT), for example. As far as I know no other Arduino board does this.

The way it is currently working is undesirable, because you might have pin 13 connected to a voltage input; an accidental reset could then cause excessive dissipation in the output driver.

Note: Originally posted on the Early Access Program forum, but still an issue.

paulvha commented 1 year ago

This is done in initvariant(), part of variant.cpp. This function is called from main.cpp during startup.

  // bootloader configures LED_BUILTIN as PWM output, deconfigure it to avoid spurious signals
  pinMode(LED_BUILTIN, OUTPUT);
  //pinMode(LEDB, OUTPUT);
  //pinMode(LEDR, OUTPUT);
  digitalWrite(LED_BUILTIN, LOW);

The led pin is defined in pins_arduino.h as :

#define PIN_LED     (13u)
#define LED_BUILTIN PIN_LED

It would be better to set as INPUT.

That said the tinyusb-bootloader seems / could be using the status led. So maybe it is a good idea to document a warning to the users that D13 could be used during startup and for status Led from a sketch (like with Blink)

technoblogy commented 1 year ago

Thanks for your post. A couple of comments:

paulvha commented 1 year ago

thanks Maybe I was not clear, but I fully agree with you.