cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F407 stuck in RTC wakeup handler

David.Cheng
Associate II

platform:rtems

there is my setup, the RTC get time works fine

void rtc_wakeup_setup()
{
    
    rtc_write_enable();
    // set wakeup clock
    // Disable the wake-up counter
    printk("wakeup block begin\n");
    STM32F4_RTC_CR &= ~STM32F4_RTC_CR_WUTE;
 
    // Wait for the RTC WUTWF flag is set or timeout
    int wait = RTC_INIT_TIMEOUT;
    while (!(STM32F4_RTC_ISR & STM32F4_RTC_ISR_WUTWF) && --wait);
    if(!(STM32F4_RTC_ISR & STM32F4_RTC_ISR_WUTWF)) 
    {
        rtc_write_disable();
        rtc_clear_dbp();
 
        return 1;
    }
    
    printk("will sett wutr\n");
    STM32F4_RTC_WUTR = 2;
    //STM32F4_RTC_WUTR = 30;
    printk("before set CR %08X\n", STM32F4_RTC_CR);
    // disable alarm a 
    STM32F4_RTC_CR &= ~(1<<8);
    
    STM32F4_RTC_CR &= (uint32_t)~(7);  // clear lowest 3bits
    STM32F4_RTC_CR |= 0x00000005;
    printk("after clear alarma WUCKSEL CR value %08X\n", STM32F4_RTC_CR);
    
    printk("WUTR %08X\n", STM32F4_RTC_WUTR);
    
    STM32F4_RTC_ISR &= ~STM32F4_RTC_ISR_WUTF;  // clear Wakeup timer flag
    
    STM32F4_RTC_CR |= STM32F4_RTC_CR_WUTIE;
    STM32F4_RTC_CR |= STM32F4_RTC_CR_WUTE;  // enable wakeup timer
    STM32F4_RTC_CR &= ~(1<<12);
    
    printk("**CR %08X \n", STM32F4_RTC_CR);
    
    //STM32F4_RTC_ISR &= ~(1<<7);    // exit init mode
    printk("isr value %08x \n", STM32F4_RTC_ISR);
    
    
    uint32_t EXIT_PR = *(volatile uint32_t *)0x40013C14;
    EXIT_PR = (uint32_t)1<<22;
    printk("clear line 22 exit flag \n");
    
    (*(volatile uint32_t*)0x40013C00) |= (1<<22);
    (*(volatile uint32_t*)0x40013C08) |= (1<<22);
 
 
 
 
 
    (*(uint32_t*)0xE000ED0C) = 0x05FA0000 | 0x400;
    (*(uint8_t*)0xE000E403) = 0xe0;
    // nvic enable interrupter number
    // 0xE000E100
    (*(volatile uint32_t*)0xE000E100) |= (1<<3);    
 
    rtc_write_disable();        
}

the handler code

#pragma GCC push_options
#pragma GCC optimize ("O0")
rtems_isr rtc_wakeup_handler(rtems_vector_number vector)
{
	
    uint32_t STM32F4_RTC_ISR = (*(volatile uint32_t *)(0x4000280C));
    
    // clear 10bit
    if(STM32F4_RTC_ISR & (1<<10))
    {
        //printk("wak\n");
        STM32F4_RTC_ISR &= ~(1<<10);
        STM32F4_RTC_ISR &= 0xfffffbff;
    }
    
    volatile uint32_t EXIT_PR = *(volatile uint32_t*)0x40013C14;
    printk("before clr %08x\n", EXIT_PR);
    EXIT_PR |= 1<<22;
    
    int i;
    for(i = 0; i < 1000; i++) i = i + 1 - 1;
    printk(" %08x\n", EXIT_PR);
}
#pragma GCC pop_options

 once it enters wakeup handler, it stuck in it , output lot log here (wakeup interrupt happens too frequently). change RTC_WUTR does not effect log output speed.

i cant clear the EXIT_PR bit but i dont know why

2 REPLIES 2

Hi

I never used rtems, but i have checked RTC config and seems ok

Is it sure that the "vector" of the ISR concerns RTC and not some other interrupt?

Near the end of Log i observed some "illegal" characters . Is there enough stack? Stack usage checked at the beginning , not after the "ISR flood"

hello,

rtc_wakeup_handler is for wakeup interrupt

log some "illegal" characters because i power the board off,

volatile uint32_t EXIT_PR = *(volatile uint32_t*)0x40013C14;
    printk("before clr exit_pr %08x\n", EXIT_PR);
    if(EXIT_PR & (1<<22))
    {
        EXIT_PR |= 1<<22;
        EXIT_PR |= 1<<22;
        EXIT_PR |= 1<<22;
        int i;
        for(i = 0; i < 1000; i++) i = i + 1 - 1;
        printk("the test i %d\n", i);
        
    }
    
    printk(" %08x\n", EXIT_PR);

i cant clear the EXIT_PR bit but i dont know why