stm32duino / STM32RTC

Arduino RTC library for STM32.
127 stars 48 forks source link

STM32RTC in any mode halts CPU when used EEPROM in sketch too. #23

Closed HamidSaffari closed 4 years ago

HamidSaffari commented 4 years ago

Hi, It is weird but when I use EEPROM funcs with RTC, CPU hangs and freeze after trying to write EEPROM in loop(). and even restart do not bring it to the loop (maybe because have Attached battery) until I remove the rtc.begin() line once and then start and then write the rtc.begin() to repeat the same problem. Both EEPROM and RTC work fine without other ones in sketch. I even use lesser flash and shift EEPROM FLASH_BASE_ADDRESS back and forth but still the same. After crashes it's hang on the EEPROM.write(addr,_byte) in my setup(); I used STM32F103RC and version 1.8.0 core and the last STM32RTC version. Here is my code:

`

include

include

include

define LED_PIN PA8

STM32RTC& rtc = STM32RTC::getInstance(); uint8_t value = 10; uint32_t lasttime;

void setup() {

pinMode(LED_PIN, OUTPUT);

rtc.setClockSource(STM32RTC::LSE_CLOCK); rtc.begin(); // initialize RTC 24H format

}

void loop() {

Heartbeat(LED_PIN,2);

if(millis()-lasttime >= 2000){ if(value>=255) value=0; else value++; EEPROM.write(0, value); lasttime=millis(); }

}

void Heartbeat(byte _ledPin, uint8_t ReduceSpeedFactor){ static LightChrono heartbeatChrono; static unsigned long interval_millis = 50*ReduceSpeedFactor; static int counter = 0; static bool ledState = false;

if(heartbeatChrono.hasPassed(interval_millis,true)){
    if(counter == 1){
        digitalWrite(_ledPin, ledState);
        interval_millis =(50*ReduceSpeedFactor);
        ledState = !ledState;
    }
    else if(counter == 2){
        digitalWrite(_ledPin, ledState);
        interval_millis =(200*ReduceSpeedFactor);
        ledState = !ledState;
    }
    else if(counter == 3){
        digitalWrite(_ledPin, ledState);
        interval_millis =(50*ReduceSpeedFactor);
        ledState = !ledState;
    }
    else{
        digitalWrite(_ledPin, ledState);
        interval_millis =(750*ReduceSpeedFactor);
        ledState = !ledState;
        counter = 0;
    }
    counter++;
}

} `

code.zip

fpistm commented 4 years ago

Hi @HamidSaffari you don't need to open the same issue in different repo. I've answered you here: https://github.com/stm32duino/Arduino_Core_STM32/issues/1038