K82 : erase and write internal flash memory with User privileges

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

K82 : erase and write internal flash memory with User privileges

572 Views
EugeneHiihtaja
Senior Contributor I

Hello !

I need to use routines for erase/write internal flash memory in Task what running with user privileges.

I have added executable rights for RAM buffer what used for poll flash operation complete status and add access in user mode to FMC and FTRA controllers by using AIPS registers.. All code is executable without Busfault ( MPU configured properly ) and other problems.

Also I should disable interrupts because some peripherals and Tick timer are interrupt driven.

But some code can't run in user mode and reason is unknown. It generate HardFault .

All lines looks quite safe and Status register can be read/write in user mode without problem.

Can it be something and not so documented about accesses to FTRA controller.

Look function : static status_t ftfx_command_sequence(ftfx_config_t *config) in file fsl_ftfx_controller.c

Code what run without problem:

SUPERVISOR_MODE_START();
asm volatile ("cpsid i");
callFtfxRunCommand((FTFx_REG8_ACCESS_TYPE)(&FTFx->FSTAT));
asm volatile ("cpsie i");
SUPERVISOR_MODE_END();

It is expected to run RAM code in user mode e.g :

SUPERVISOR_MODE_START();
asm volatile ("cpsid i");
SUPERVISOR_MODE_END();


callFtfxRunCommand((FTFx_REG8_ACCESS_TYPE)(&FTFx->FSTAT));


SUPERVISOR_MODE_START();
asm volatile ("cpsie i");
SUPERVISOR_MODE_END();

May be some other tricks should be used ?

Regards,

Eugene

0 Kudos
4 Replies

420 Views
jeremyzhou
NXP Employee
NXP Employee

Hi Eugene Hiihtaja,

Thank you for your interest in NXP Semiconductor products and the opportunity to serve you.
To provide the fastest possible support, I'd highly recommend you to refer to the flash demo in the SDK library, please download the SDK via the below link.
https://www.nxp.com/support/developer-resources/software-development-tools/mcuxpresso-software-and-t...


Have a great day,
TIC

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

420 Views
EugeneHiihtaja
Senior Contributor I

Hello !

Yes , I have used original pflash example from latest SDK as example. It work fine.

But I need more pracical details to usage that routines in RTOS-MPU enabled environment.

System have a lot of interrupts from peripherals and code should be executed with User privileges.

I can see in RM , that Write access to some FMC registers are possible only in Supervisor mode. Even AIPS0 can grant access to those

Interrupts should be disabled because poll of STAT register is executed in RAM.

All FTFA accesses also should be possible with User privileges.

But I can't run loop callFtfxRunCommand((FTFx_REG8_ACCESS_TYPE)(&FTFx->FSTAT)); with user privileges for unknown reason.

And may be some FTF resisters can be accessed in Supervisor mode only ?

Regards,

Eugene

0 Kudos

420 Views
jeremyzhou
NXP Employee
NXP Employee

Hi Eugene,
It seems a bit weird.
According to your statement, after MCU enter to user privilege mode from the supervisor mode, MCU would read or write FTFA registers, is it right?
If yes, I was wondering if you can share a compile-able demo which can replicate this phenomenon, as I'd like to confirm it on my site.
Have a great day,
TIC

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

420 Views
EugeneHiihtaja
Senior Contributor I

Hello !

I can't share that code.

But it work fine with other peripherals.

For have access to FlashMemory registers, I have enabled APIS0 settings.

AIPS0->PACRD), 0x00000001ul  // Enable FMC, User RW
AIPS0->PACRE), 0x10000000ul  // Enable FlashMemoryModule ( FTFA ), User RW

And buffer for poll Flash status is marked in MPU as to have rwx for user and supervisor mode.

Not all registers can be accessible with user privileges  and in case of FMC it is clearly listed in RM.

And they executed in Supervisor mode where it is need.

So only loop for poll FTFx->FSTAT register in RAM is cause problem.

Busfault is not happens, it means MPU settings are right.

But hardfault is happens due unknown reason in User mode but Supervisor mode is OK.

And I just wondering what is difference for this exact code.

Regards,

Eugene

0 Kudos