Skip to content

RTC.begin() crashes whole processor #88

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
maxgerhardt opened this issue Aug 6, 2023 · 1 comment
Closed

RTC.begin() crashes whole processor #88

maxgerhardt opened this issue Aug 6, 2023 · 1 comment
Labels
conclusion: resolved Issue was resolved topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project

Comments

@maxgerhardt
Copy link
Contributor

maxgerhardt commented Aug 6, 2023

This function is declared to have return value bool

bool RTClock::begin() {
if(openRtc()) {
is_initialized = true;
}
else {
is_initialized = false;
}
}

but there's not a single return keyword in that function. It ought to do return is_initialized; at the end.

This incorrect code causes some compilers (arm-none-eabi-gcc 10.3.1) to emit assembly that causes an infinite loop. Any sketch using RTC.begin(); deadlocks forever. Specifically, the assembly is

69eaa3dda954d333495272a5404b777435d6a9a7

(Notice how there is no pop {..., pc} to facilitate any returning in that function. After writing true, the code immediately writes false and jumps back to the beginingo of the code that writes false, thus being stuck forever at that line of C++ code). When I fix the code

eaed625b41282401253b94e15c48a04dd1e1fdcd

It does nicely return.

This code is undefined behavior which does happpen to work on the compiler version used in the Arduino IDE (7.0.1), however, the higher version one used in PlatformIO (10.3.1) breaks with it. (We upgraded it because, what could possible go wrong? Well, this). And of course, if this core ever decides to upgrade its compiler, this unfixed code is a ticking timebomb.

maxgerhardt added a commit to maxgerhardt/ArduinoCore-renesas that referenced this issue Aug 6, 2023
Resolves compilers generating the wrong assembly per arduino#88
@per1234 per1234 added type: imperfection Perceived defect in any part of project topic: code Related to content of the project itself labels Aug 6, 2023
@maxgerhardt
Copy link
Contributor Author

Fixed by merged PR, should be in next release.

@per1234 per1234 added the conclusion: resolved Issue was resolved label Aug 7, 2023
pennam pushed a commit to pennam/ArduinoCore-renesas that referenced this issue Jan 5, 2024
Enable lwip memory allocator to reduce RAM fragmentation
cristidragomir97 pushed a commit to cristidragomir97/ArduinoCore-renesas that referenced this issue May 20, 2024
Enable lwip memory allocator to reduce RAM fragmentation

Former-commit-id: 51fbfb7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
conclusion: resolved Issue was resolved topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project
Projects
None yet
Development

No branches or pull requests

2 participants