NorthernWidget / DS3231

Communicates between Arduino-programmed AVR and Maxim DS3231 RTC: splice of Ayars' (http://hacks.ayars.org/2011/04/ds3231-real-time-clock.html) and Jeelabs/Ladyada's (https://github.com/adafruit/RTClib) libraries
The Unlicense
186 stars 81 forks source link

DateTime constructor crashes SAMD21 #81

Open IowaDave opened 1 year ago

IowaDave commented 1 year ago

The following constructor caused a hard fault on a SAMD21 device:

DateTime (const char* date, const char* time);

The following minimal snippet illustrates the trouble:

#include <DS3231.h>
DateTime trouble("Jan 12 2023", "12:07:00");
void setup() {
  ;
}
void loop() {
  ;
}

Immediately after uploading, the device loses its Serial connection to the computer. The connection must be restored with a quick double-tap of the reset button before code can be uploaded again.

The other constructors, that use numeric parameters, do not cause this problem in a declaration statement. However, I might have seen a similar result when using the RTClib::now() function farther along in a program. Can't remember.

Perhaps DateTime should be approached with caution on SAMD21 hardware because this repo was written for 8-bit AVR chips. I wonder whether an attempt to read or write some memory location that is not 32-bit aligned may be causing a hard fault which hangs up the CPU.

In the interest of preserving compactness when compiled for AVRs, it may be desirable to create an alternate code body for DateTime to be compiled for the SAMD21G18A architecture. Putting this issue out there for the community to consider. Hope someone who knows the DateTime code intimately can address this issue with skill, before I try to wrap my amateurish hands around it.

David

hasenradball commented 1 year ago

Hi @IowaDave,

how are you? This issue sounds interesting do you need help?