K82 : erase and write internal flash memory and FreeRTOS

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

K82 : erase and write internal flash memory and FreeRTOS

2,075 次查看
EugeneHiihtaja
Senior Contributor I

Hello !

I can successfully run pflash SDK example on FRDM K82 board. After that I adopt this test for FreeRTOS environment

and it is also possible to pass erase/write/verify loop if all interrupts disabled.

E,g.

asm volatile ("cpsid f");
result = FLASH_Erase(&s_flashDriver, destAdrss, pflashSectorSize, kFTFx_ApiEraseKey);
asm volatile ("cpsie f");

asm volatile ("cpsid f");
result = FLASH_Program(&s_flashDriver, i, (uint8_t *) s_buffer, sizeof(s_buffer));

asm volatile ("cpsie f");

I have used last 4KB sector in flash memory.

But if I enable MPU this technique dosn't help and it cause BusFault if erase operation initiated

Even Task running in privileged mode and whole flash area set as rwx in MPU table.

But I think rwx is no need becouse flash memory accessed via controller peripheral registers.

I no need to run any special code in RAM, timing can wait.

But how to disable everything what is need when one sector of flash memory need to be erased ?

I have few different interrupts and FreeRTOS is MPU enabled.

Regards,

Eugene

6 回复数

1,887 次查看
jingpan
NXP TechSupport
NXP TechSupport

Hi,

I think it's not only MPU problem, it's relate to M4 core. Since instruction like " cpsid f" can only execute in privileged mode, you must switch to rtos supervisor mode and then disable interrupt and do flash erase/write.  

"cpsid f" disable all exception and interrupt except NMI. I think "CPSID I" is enough.

Regards,

Jing 

0 项奖励
回复

1,887 次查看
danielchen
NXP TechSupport
NXP TechSupport

Hi Eugene:

I would suggest you check

1. whether you have configure the MPU correctly.

2. whether you have execute the flash erase/program software subroutines from a different flash block than the one with the sectors being erased/programmed.

You also can share your project for further analyzing.

Regards

Daniel

0 项奖励
回复

1,887 次查看
EugeneHiihtaja
Senior Contributor I

Hi Daniel !

So if everything is correct,it shouldn't be any problem to execute asm volatile ("cpsid f"); disable/enable

?

Or  asm volatile ("cpsid i") ie enought ?

Regards,

Eugene

0 项奖励
回复

1,887 次查看
EugeneHiihtaja
Senior Contributor I

Hi Daniel !

I think it can work this way if code running in User mode, MPU and AIPS setting are correct.

Wait loop in fsl_ftfx_controller.c :

portENTER_CRITICAL();
callFtfxRunCommand((FTFx_REG8_ACCESS_TYPE)(&FTFx->FSTAT)); //
portEXIT_CRITICAL();

Wait loop in fsl_ftfx_cache.c :

SUPERVISOR_MODE_START();
// FMC_CACHE_REG can be written in Privileged mode only !
callftfxCommonBitOperation((FTFx_REG32_ACCESS_TYPE)&FMC_CACHE_REG, FMC_CACHE_CLEAR_MASK, FMC_CACHE_CLEAR_SHIFT, 0xFU);
SUPERVISOR_MODE_END();

Is this should work like this ?

Regards,

Eugene

0 项奖励
回复

1,887 次查看
danielchen
NXP TechSupport
NXP TechSupport

Hi Eugene:

Thank you for your update, let me do more tests on my side and I'll get it back to you when I have results.

Regards

Daniel

0 项奖励
回复

1,887 次查看
EugeneHiihtaja
Senior Contributor I

Hi Daniel !

I just try to say it is important to know how-to run all FSL components with User privileges.

All serious applications require MPU enabled RTOS, AIPS and User privileges.

Regards,

Eugene

0 项奖励
回复