Is there a problem with the RTC's initialization in Processor Expert?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Is there a problem with the RTC's initialization in Processor Expert?

Jump to solution
1,377 Views
brunopaillard
Contributor III

Hi

I am trying to create a simple project in KDS, using processor expert and MQX Lite.

I have defined a single task, as well as configured the RTC to provide one interrupt a second. In the task, as well as in the ISR the only thing that happens is a change in LEDs that are driven... A simple project to exercise the processor expert drivers, as well as MQX Lite.

Whenever the RTC interrupt is auto-configured the task does not run. When debugging this, I see it block on a WFI instruction in the Dispatch.s function.

If I initialize the RTC at the beginning of the task, instead of auto-initialization before starting the scheduler, everything works fine (the task runs and the RTC interrupt runs as well).

What Am I missing?

Thanks

Bruno

0 Kudos
1 Solution
986 Views
marek_neuzil
NXP Employee
NXP Employee

Hi Bruno,

I have analyzed your issue and you are right. The RTC cannot be initialized automatically (properties Auto Initialization). When you use the MQXLite all interrupts of devices are served by the MQX RTOS. The MQX RTOS is started in the main() function after peripherals initialization (PE_low_level_init() function). In this case your code must guarantee that no interrupt occurs before the MQX RTOS is started. So you must enable (initialize) the RTC device in a MQX task.

After VBAT power-on reset the Time Invalid Interrupt flag is set and Time Invalid Interrupt is enabled (see reset values of RTC registers in the reference manual). When you enable RTC clock gate in RTC_Init() method the NVIC latch the RTC Time Invalid Flag. As soon as interrupts are enabled in CPU the RTC interrupt vector is invoked. But in the case of MQX Lite, the interrupt system  is not initialized yet. Therefore the application crash.

So the correct settings of the RTC component and initialization in your case is following:

RTC_with_MQXLite_init.png

Best Regards,

Marek Neuzil


View solution in original post

0 Kudos
4 Replies
986 Views
MVa
NXP Employee
NXP Employee

Hi Bruno,

can you post a simple project please? Thanks.

MVa

0 Kudos
987 Views
brunopaillard
Contributor III

Hi Marek

Here it is. This is a project for KDS, and for the FRDM K22F dev kit. The red LED is toggled at 5Hz in the main task, and the green LED is toggled at 1Hz in the RTC event function.

https://dl.dropboxusercontent.com/u/24636754/Test_PEx_NoKSDK.zip

I should add that it sometimes works (both LEDs toggle), but mostly not (only the green LED toggles and the main task does not seem to run)... Maybe a problem of timing during initialization of MQX...?

Thanks

Bruno

0 Kudos
987 Views
marek_neuzil
NXP Employee
NXP Employee

Hi Bruno,

I have analyzed your issue and you are right. The RTC cannot be initialized automatically (properties Auto Initialization). When you use the MQXLite all interrupts of devices are served by the MQX RTOS. The MQX RTOS is started in the main() function after peripherals initialization (PE_low_level_init() function). In this case your code must guarantee that no interrupt occurs before the MQX RTOS is started. So you must enable (initialize) the RTC device in a MQX task.

After VBAT power-on reset the Time Invalid Interrupt flag is set and Time Invalid Interrupt is enabled (see reset values of RTC registers in the reference manual). When you enable RTC clock gate in RTC_Init() method the NVIC latch the RTC Time Invalid Flag. As soon as interrupts are enabled in CPU the RTC interrupt vector is invoked. But in the case of MQX Lite, the interrupt system  is not initialized yet. Therefore the application crash.

So the correct settings of the RTC component and initialization in your case is following:

RTC_with_MQXLite_init.png

Best Regards,

Marek Neuzil


0 Kudos
987 Views
brunopaillard
Contributor III

Thanks Marek

That makes sense... Probably also an issue with other interrupts then. I will keep that in mind.

Thanks!

Bruno

0 Kudos