The example flexnvm code is not working on our processor : MK50DX256CLL10

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

The example flexnvm code is not working on our processor : MK50DX256CLL10

1,345 次查看
shridharrao
Contributor II

Actually the example section in MQX 4.2 doesn't have support for this processor but we modified the code accordingly to our processor - when we run the code, the very first  fopen("flashx:flexram0", NULL);. fails. And we are unable to do anything after that. So we tried writing our own code.

The data written to FlexNVM is disappearing after a power reset if we try our own code  (just a simple sequence of commands to partition the FlexNVM and enable EEE and use direct read/writes to FlexRAM memory). I have tried opening Service requests but I only got answers that work on barebones but don't work with MQX.

Our need is to use FlexRAM to back some critical data inside E-Flash (FlexNVM) with MQX on MK50DX256CLL10. I suspect that MQX is erasing the Flash during boot. Because with our code, we are able to read and write to FlexNVM portion (through FlexRAM/EEE) when the power is retained. But after the processor boots after a power cycle, the data written to FlexNVM is lost. Our code is pasted below:

#include "derivative.h" /* include peripheral declarations */

#define LONGWORD_COUNTER_ADDR 0x14000000

#define WORD_COUNTER_ADDR 0x14000004

#define BYTE_COUNTER_ADDR 0x14000006

#define REG_READ(address)             ((unsigned char)(*(volatile unsigned char*)(address)))

#define WRITE8(address,value)         (*(volatile unsigned char*)(address) = (value))

#define READ8(address)                ((unsigned char)(*(volatile unsigned char*)(address)))

int partition_flash(int eeprom_size, int dflash_size)

{

      if ((SIM_FCFG1 & SIM_FCFG1_DEPART(0xF)) != 0x00000F00)

      {

          return 0;

      }

     

      /* clear RDCOLERR & ACCERR & FPVIOL flag in flash status register */

      FTFL_FSTAT = (0x40|0x20|0x10);

      /* Write the FCCOB registers */

      FTFL_FCCOB0 = FTFL_FCCOB0_CCOBn(0x80);

  

   FTFL_FCCOB1 = 0x00;

      FTFL_FCCOB2 = 0x00;

      FTFL_FCCOB3 = 0x00;

      FTFL_FCCOB4 = eeprom_size;

      FTFL_FCCOB5 = dflash_size;

   FTFL_FSTAT = FTFL_FSTAT_CCIF_MASK;

      while(!(FTFL_FSTAT & FTFL_FSTAT_CCIF_MASK));

      return 1;

}

void EEEWrite(unsigned long destination,unsigned long size,unsigned long source)

{

    if((FTFL_FCNFG & 0x01)==0x01)

    {

            while(size > 0)

            {   

                while(0 == (FTFL_FCNFG & 0x01))

                {

                //delay

                }

                WRITE8(destination,READ8(source));

       

                if(REG_READ(FTFL_FSTAT & 0x10))

                {

                }

       

                destination += 1;

                size -= 1;

                source += 1;

            }

        }

}

void EEE_read_data(char *buffer, int length,int offset) {

  uint32_t receive_byte = 0;

  for (receive_byte = 0; receive_byte < length; receive_byte++) {

         buffer[receive_byte] = *((uint8_t *)(offset + receive_byte));

     }

}

uint32_t temp_val_long_word = 0;

uint16_t temp_val_word = 0;

uint8_t temp_val_byte = 0;

int main(void)

{

    unsigned long source;

    unsigned long address;

    unsigned long size;

    unsigned char buffer[0x20] = {0x33,0x44,0x55,0x66,0x77,0x88};

    unsigned char dataread[0x20] = {0};

    //address = 0x14000000;

    //EEE_read_data(dataread,6,address);

  SCB_SHCSR|=SCB_SHCSR_BUSFAULTENA_MASK|SCB_SHCSR_MEMFAULTENA_MASK|SCB_SHCSR_USGFAULTENA_MASK;

  if (partition_flash( 0x38, 0x5))

  {

  *((uint32_t *)(LONGWORD_COUNTER_ADDR)) = 0x0;

  while(!(FTFL_FCNFG & FTFL_FCNFG_EEERDY_MASK));

  *((uint16_t *)(WORD_COUNTER_ADDR)) = 0x0;

  while(!(FTFL_FCNFG & FTFL_FCNFG_EEERDY_MASK));

  *((uint8_t *)(BYTE_COUNTER_ADDR)) = 0x0;

  while(!(FTFL_FCNFG & FTFL_FCNFG_EEERDY_MASK));

  }

    address = 0x14000000;

    size = 0x06;

    source = (unsigned int)buffer;

    EEEWrite(address, size, source);

   // EEE_read_data(dataread,6,address);

   

    return 0;

}

标签 (1)
标记 (2)
0 项奖励
回复
1 回复

907 次查看
danielchen
NXP TechSupport
NXP TechSupport

Hi

For full EEPROM, MQX has an example for Kinetis FTFL flash (for example twrk20d72 BSP).

The flexNVM example for this hardware is

c:\Freescale\Freescale_MQX_4_0\mqx\examples\flexnvm\flexnvm_demo.c

The low level Kinetis MQX FTFE driver:

c:\Freescale\Freescale_MQX_4_0\mqx\source\io\flashx\freescale\flash_ftfe.c

will need to be customized for flexnvm (add flexnvm_ ioctl commands as in flash_ftfl.c).

I think you can port it to your BSP, you can refer to the following link

MQX FlashX driver – how to write FlexNVM?


Have a nice day,
Daniel

0 项奖励
回复