platformio / platform-renesas-ra

Renesas RA: development platform for PlatformIO
https://registry.platformio.org/platforms/platformio/renesas-ra
Apache License 2.0
10 stars 4 forks source link

RTC.begin() deadlocks processor #10

Closed maxgerhardt closed 1 year ago

maxgerhardt commented 1 year ago

See https://github.com/arduino/ArduinoCore-renesas/issues/88.

The Arduino framework code has a bug / undefined behavior in which the RTClass::begin() function, when compiled by the here used ARM GCC 10.3.1. produces wrong assembly in such a way that it causes an infinite loop at the is_initialized = false statement. Calling RTC.begin(); is a game-over.

Broke a user trying to use an Arduino IoT sketch with the Uno R4 WiFi at https://community.platformio.org/t/cant-connect-to-arduino-iot-cloud-with-platformio/35087.

This either needs a minimal package update with just the patch or (sadly) a downgrade of the compiler version to exactly match the Arduino IDE's behavior (7.0.1). In the last case I cannot however guarantee whether a certain set of compiler / optimization switches also ends up producing the wrong assembly code in 7.0.1.

maxgerhardt commented 1 year ago

ANOTHER Bug of the same kind, a missing return of a boolean value, causes a Usage fault crash of the processor in the WiFiUDP::read_needed() function, as explained in the topic.

This bug is however not present in the 1.0.2 version of the core (function has been renamed to read_if_needed and is void now), but it's present in the 1.0.1 version that PlatformIO is using.

Edit 2: WiFiSSLClient::read_needed() suffers from the same bug in 1.0.1, but is fixed in 1.0.2.

valeros commented 1 year ago

Thanks for pointing it out. I've uploaded v1.0.2 with your patch fix included.