Power Mode Switch Demo for iMXRT1052 + FreeRTOS

cancel
Showing results for 
Search instead for 
Did you mean: 

Power Mode Switch Demo for iMXRT1052 + FreeRTOS

Jump to solution
1,501 Views
variable_andrew
Senior Contributor I

What modification is necessary to run the Power Mode Switch Demo for iMXRT1052 in FreeRTOS assuming FreeRTOS is running in low power tickless mode?

I'm trying to do this - but code is crashing when I add the following to my application after Board Clock / Peripheral init:

LPM_Init();
 LPM_OverDriveRun();

1. Does altering the clocks w/ the LPM code breaks the freertos low power tickless logic (ie - low power tickless timer executes and tries to run WFI when the device might already be in low power state?

2. Does the Power Mode Switch Demo doesn't account for other peripherals? Our device is using lpspi, lpuart, lpi2c, usb, semc, flexspi...  Do I need to do extra stuff just to run in LPM_OverDriveRun? (I want to eventually run in LPM_PowerModeSysIdle mode)

3. Any insight regarding restrictions if using LPM code from the ^^^ demo in a FreeRTOS project would be much appreciated. 

3a. Should I freeze all tasks / timers before changing LPM modes?

3b. Do I need to completely de-init all peripherals and re-init just to change modes from run to idle?

4. Does LPM_EnableWakeupSource need to be executed every time you want to go to sleep, or can it just be executed once @ startup assuming you have a dedicated push button.

Can you use the same GPIO IRQ for wake up and standard ISR code? (ie - is it OK for me to override void GPIO1_Combined_16_31_IRQHandler(void) in my code - this won't break the wake-up logic?)

5. I noticed the Power Mode Switch Demo actually alters the USB related PLLs - I thought this was NOT recommended when running code from XIP? (as per here from clock_config.c):Screen Shot 2020-06-23 at 7.19.04 PM.png

Labels (1)
1 Solution
1,155 Views
danielchen
NXP TechSupport
NXP TechSupport

Hi  variable_andrew

Sorry, this is not an IDE issue.

Please use the attached specific.c

I tested with RT1050 on board QSPI flash. It worked on my side.  could you please check on your side?

You can use MCUXpresso IDE.

Regards

Daniel

View solution in original post

12 Replies
1,155 Views
variable_andrew
Senior Contributor I

On further investigation - it seems the crash is happening after 

LPM_OverDriveRun

runs and code jumps back to code located in FLASH, ie - LPM_OverDriveRun is breaking the flash for me.

I don't understand how the power mode switch demo can even work as is - as no code is specifically allocated to RAM, so you're trying to run code that turns off Flash (SwitchSystemClocks) from FLASH memory - which seems very unsafe.

Is this line supposed to guarantee that the function will be cached and run from ITC/DTC?

AT_QUICKACCESS_SECTION_CODE(void SwitchSystemClocks(lpm_power_mode_t power_mode));

Dissassembly view is showing this running from FLASH, and this code causes the debugger to jumped to random memory after running this SwitchSystemClocks from FLASH, so I tried moving this to RAM, which fixed the issue of the PC jumping to random memory locations...

__RAMFUNC(RAM) void SwitchSystemClocks(lpm_power_mode_t power_mode)

BUT this still didn't fix my issue of crashing after jumping back to code in FLASH after finishing all the clock updates.

0 Kudos
1,155 Views
danielchen
NXP TechSupport
NXP TechSupport

Hi variable_andrew:

Please the following document first,  How to use i.MX RT Low power feature. inlcuding FreeRTOS  and Power mode switch example

https://www.nxp.com/docs/en/application-note/AN12085.pdf 

What version you are using?  

Are you using the EVKB-RT1050 board or your custom board?

Regards

Daniel

0 Kudos
1,155 Views
variable_andrew
Senior Contributor I

One further update, danielchen@fsl‌:

i've updated the demo on github to run on the Arch Mix Seeed board now.

The same issue happens on there:

so I"m thinking it's something related to that this demo is meant only for hyperflash and i'm missing a step for regular 133MHz NOR FLASH.

Do you have a Seeed board you can test with there?

Or know what's missing in the demo when ported for qspi NOR FLASH?

0 Kudos
1,155 Views
danielchen
NXP TechSupport
NXP TechSupport

Hi

Sorry I don't have Seeed board, I have RT1050 EVK board.

I think changing the xip flash type is OK.

Could you please attach your error message here?

Regards

Daniel

0 Kudos
1,155 Views
variable_andrew
Senior Contributor I

Hi danielchen@fsl‌,


On the Seeed board:

The the evkbimxrt1050_power_mode_switch_ca demo works without any error if I Link Application to RAM, so it appears the issue is specifically related to running from FLASH.

Can you confirm the demo works for you on the RT1050 EVK board when linked to flash?

Are you able to test the RT1050 EVK w/ QSPI NOR FLASH (like the one from the RT1020EVK)?


For the errors I'm seeing when running from FLASH:

When I update specific.c for what I believe to be proper FlexSPI Speeds for this board (133MHz), and then run, AFTER I choose a mode which requires changing the clocks ->  I get the error I put in the image in the previous post, segfault:

Active Fault @ power_mode_switch.c line 413;

BFARVALID (7) BusFault Address Register BFAR valid flag

PRECISERR (1) Precise data bus error

FORCED (30) - forced hard fault

Register LR is at LPM_FullSpeedRun() at memory location 0x60002ABB

Register PC is at PowerModeSwitchTask() at memory location 0x600039A8

Here's teh screenshot again:

Screen Shot 2020-06-29 at 11.04.41 AM.png

If I DON'T change the FlexSPI div settings in specific.c (which would mean overclocking the FlexSPI FLASH by 2x) - also an imprecise data bus error (2) forced hard fault, LR at 0x600026A9.

Could you please confirm the demo works for you from FLASH - like the IS25LP064A-BLE FLASH used on the rt1020evk?

0 Kudos
1,155 Views
danielchen
NXP TechSupport
NXP TechSupport

Hi Variable:

Today I replaced the hyper flash with a qspi flash on my EVK-RT1050 board, the power mode switch demo can not run on my board. I am checking this issue, and will let you know my results.

Regards

Daniel

1,155 Views
variable_andrew
Senior Contributor I

Hi danielchen@fsl‌,

Have you been able to make progress there? Perhaps anything ideas from design?   

0 Kudos
1,155 Views
danielchen
NXP TechSupport
NXP TechSupport

Hi variable_andrew

I verified this demo with IAR project, it can work on my side. Could you please check this on your side?

So it seems this is a MCUXpresso IDE issue.

Regards

Daniel

1,155 Views
variable_andrew
Senior Contributor I

Hi danielchen@fsl‌,

Porting everything to IAR isn't an option for us. 

That said, I downloaded the latest IAR and got a trial license so I could test this.

Can you confirm you tested with code linked to FLASH, not RAM?

The default IAR demo links code to RAM and doesn't do anything in FLASH.... (so it doesn't test our problem)

That works fine for me in both IAR and MCUXpresso.

But in IAR I cant even get code to download to the board's FLASH. 

(I updated xip files and board.h as I did in the MCUXpresso version of the project, tried updating IAR Debugger settings, etc) - but couldn't debug flash on this board.

If you're able to get the power mode switch demo to work from NOR FLASH ( IS25 QSPI NOR FLASH 8MB like on the RT1020EVK), and you want me to test that on IAR - could you provide the FLASH config / debugger config files for flashing the RT1050 w/ that FLASH part?

As noted - we are working in MCUXpresso - so really need to get this running over there. But for testing purposes - I can confirm here if needed, tho I'm thinking that IAR shouldn't be any different from MCUXpresso with this bug.

0 Kudos
1,156 Views
danielchen
NXP TechSupport
NXP TechSupport

Hi  variable_andrew

Sorry, this is not an IDE issue.

Please use the attached specific.c

I tested with RT1050 on board QSPI flash. It worked on my side.  could you please check on your side?

You can use MCUXpresso IDE.

Regards

Daniel

1,155 Views
variable_andrew
Senior Contributor I

Thanks danielchen@fsl‌!!!!!

It is working now!

Some of the changes I understand, but could you help me understand ones like...

1. Why was LPM_EnterCritical removed everywhere?

2. In SwitchSystemClocks(): Was DLL stuff what was causing bus errors on FlexSPI? Is that Hyperflash specific?

In the github repo I was working on - here's a list of changes from what I had before:

specific.c update from NXP - demo appears to be working · andrewrt/rt1052-power_mode_switch_ca@6f555... 

 

edited:

I previously asked about App_PrintRunFrequency discrepancy.

I then realized - the app starts w/ UsbPll1 pfd0 == 22 from clock config by default, and doesn't update that setting in code on init because of an #if XIP lin in clock config.

So you won't see the actual frequency preferred by specific.c until changing modes AWAY from overrun, and then back to overrun. Then everything lines up.

As such - I deleted that part of the question

0 Kudos
1,155 Views
variable_andrew
Senior Contributor I

Hi danielchen@fsl‌,

Yes - I am following that AppNote:

I had followed the AppNote notes for FreeRTOS in my own project, but that led to a different problem - an incorrect tick setup, so I started a separate thread for that problem last week.

Regarding the SDK demo software:

I also found there is a FreeRTOS versions of the power mode switch demo, ending in "CA".

If i try to run low power mode code on my board, modified for the FLASH we have on our board it crashes.

Our board has a 64MB QSPI NOR FLASH, not the hyperflash from the RT1052EVK)- the code crashes when trying to jump back to FLASH.

The NOR FLASH we use is similar to the RT1020EVK, or the RT1052 ArchSEED board, just more capacity.

This board is functional - FLASH read/write, SDRAM, all peripherals confirmed as working for our main application, we're just trying to add low power modes in now as the final step.

I know I need to modify the demo project for the different flash size & speed - so I updated:

clock_config - modified for 133MHz max NOR FLASH

xip files - flash type - copied from rt1020evk & modified for 64MB size

board.h - flash size -> 64MB

demo code (specific.c) -> modified clock dividers to limit FLASH to 133MHz.

You can see the code I have (just this demo modified as noted above) at this link.

Can you help me understand:
1. Is there something else I need to do for FLASH?

2. Why isn't the demo code forcing itself to be allocated to internal RAM when modifying FLASH configuration?

0 Kudos