Skip to content
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

Fix initialisation sequence of RTC #15184

Merged
merged 1 commit into from
Dec 7, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion targets/TARGET_Maxim/TARGET_MAX32630/rtc_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ time_t rtc_read(void)
//******************************************************************************
void lp_ticker_init(void)
{
init_rtc();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this order would matter? I would assume it should work either way (the 3 functions below are just setting nvic and interrupt.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm developing software for a MAX32630, and I was finding that the software ran as expected from a POR/power-cycle, but would never reach main() when I was using the DAPlink debugger. So I spent some time investigating this, and found that the init_rtc() function was also never reached. When the NVIC IRQ was enabled the ISR would fire, and never returned.
(Although I didn't debug this part in detail, I assume that instead of a normal return from the IRQ, this is being used to pass control to the RTOS scheduler. But in this case the main() function has not yet been added to the queue, so there is nothing to do, and the system is deadlocked.)
The reason for the difference in behaviour between POR and DAPlink debugger appears to be that the debugger issues a SYSRESET, and the RTC survives the SYSRESET. The RTC continues to generate interrupt conditions while the debugger is flashing the device and starting up.
I was able to resolve the problem by moving the call to init_rtc() to the start of lp_ticker_init(), after which I found that the breakpoint on main() would be hit as expected when using the debugger. The setup in init_rtc() puts the module into a safe state so that the NVIC interrupt can be enabled without being immediately triggered. There is no difference to the POR behaviour.
Our project is using a fork of the Mbed repo. Unfortunately I don't have time to run all of the Mbed test suites, but I thought I would offer this fix to the main project. As mentioned, this is an old device, and the issue would only affect use with a debugger, or reset due to watchdog or software trigger. Maybe these scenarios are not covered in testing, and have not been used in real projects?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mjh65 Thank you very much for your effort and contribution, As Maxim (Now part of ADI) we appreciate it.
Please let us think on it and run related test suites.
Regards.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ozersa Any update, did the tests fail?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related test suites passed for GCC_ARM. The change request is fine.
GCC_ARM_TestResult_For_PR_15184.txt

@mjh65 thanks for your contribution.

RTC_DisableINT(MXC_F_RTC_INTEN_COMP0);
NVIC_SetVector(RTC0_IRQn, (uint32_t)lp_ticker_irq_handler);
NVIC_EnableIRQ(RTC0_IRQn);
init_rtc();
}

//******************************************************************************
Expand Down