MFS using FlashX on a TWRK60N512

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

MFS using FlashX on a TWRK60N512

2,549 Views
myke_predko
Senior Contributor III

Hey folks,

 

Hopefully this is an easy one - I am trying to set up a Flash Drive on a K60N512 running MQX 3.8.1 with specific libraries and then check to see what was created. 

 

Code follows:

void initMFS() {int_32                      errorCode;uint_32                     mfsStatus;uint_32                     space;MFS_SEARCH_DATA             searchData;MFS_SEARCH_PARAM            search;char_ptr                    filePath = "*.*";                   if (NULL == (pf_IntFlash = fopen("flashx:", NULL))) {  printf("Error open internal flash device!\n");     fflush(stdout);     _mqx_exit(0); } else if (MFS_NO_ERROR != (mfsStatus = _io_mfs_install(pf_IntFlash, "c:", (_file_size)0))) {  printf("MFS install failed!\n");  fflush(stdout);  _mqx_exit(0); } else {  pf_fd = fopen("c:", NULL);  if (MFS_NO_ERROR == (errorCode = ferror(pf_fd))) {   printf("Internal flash device initialized.\n");   fflush(stdout);  }  else if (MFS_NOT_A_DOS_DISK == errorCode) {   printf("Formating internal flash drive...\n");   fflush(stdout);   if (MFS_NO_ERROR == (errorCode = ioctl(pf_fd, IO_IOCTL_DEFAULT_FORMAT, NULL))) {    if (MFS_NO_ERROR != (errorCode = ioctl(pf_fd, IO_IOCTL_CREATE_SUBDIR, (uint_32_ptr)"\\subdir1"))) {     printf("Unable to create \"\\subdir1\" (0x%04X)\n", errorCode);     fflush(stdout);     _mqx_exit(0);    }    if (MFS_NO_ERROR != (errorCode = ioctl(pf_fd, IO_IOCTL_CREATE_SUBDIR, (uint_32_ptr)"\\subdir2"))) {     if (MFS_CANNOT_CREATE_DIRECTORY == errorCode) {      printf("MFS Cannot Create \"\\subdir2\"\n");      fflush(stdout);     }     printf("Unable to create \"\\subdir2\" (0x%04X)\n", errorCode);     fflush(stdout);    }        search.ATTRIBUTE = MFS_SEARCH_NORMAL;    search.WILDCARD = filePath;    search.SEARCH_DATA_PTR = &searchData;        errorCode = ioctl(pf_fd, IO_IOCTL_FIND_FIRST_FILE, (uint_32_ptr)&search);    while (MFS_NO_ERROR == errorCode) {     printf("%-12.12s %61u\n", searchData.NAME, searchData.FILE_SIZE);                    fflush(stdout);     errorCode = ioctl(pf_fd, IO_IOCTL_FIND_NEXT_FILE, (uint_32_ptr)&search);    }   }   else {    printf("IntFlash format error!(%X)\n", errorCode);    fflush(stdout);    _mqx_exit(0);   }  }  else {   printf("Error while opening c:\\ (%s)\n", MFS_Error_text((uint_32)(uint_32)errorCode));   fflush(stdout);   _mqx_exit(0);  }  space = ioctl(pf_fd, IO_IOCTL_FREE_SPACE, NULL);  printf("\n%i Bytes available in drive c:\n", space);  fflush(stdout);

        }
}

 

Going through the steps:

1.  flashx open takes place without any problems.

2.  MFS Install executes without any problems

3.1.  If the first time through, disk not formatted recognized and format executes without any problems

3.2.  If a second time through, disk is recognized as being formatted

4.  First subdir create works without any problems

5.  Second and about 2/3rds of the subsequent subdir creates fail.  Note that they don't return with "MFS_CANNOT_CREATE_SUBDIRECTORY" which is strange.  The error code doesn't match what's listed in the MFS User Guide. 

6.  When I try to read through the file system to see the created folders, the find first file fails.  The error code does not match what's listed in the MFS User Guide

7.  When I loko at the total space available to the file system, it is greater than 440k, which makes sense for the device. 

 

Anybody have any ideas why the create subdirectory and file system reads fail?  I can't really find any example code for what I'm trying to do - if you can point me in the right direction, it would be greatly appreciated.

 

Thanx!

 

myke

Labels (1)
Tags (1)
15 Replies

1,091 Views
Martin_
NXP Employee
NXP Employee

Hello,

partial sector overwrite (when destination flash memory sector is non-blank) should be enabled in the flashx device:

----

/* Enable sector cache */

error_code = ioctl(flashx_dev_handle, FLASH_IOCTL_ENABLE_SECTOR_CACHE, NULL);

if(MQX_OK == error_code)

{

  printf("\nFlash sector cache enabled.");

}

else

{

  printf("\nError in ioctl ENABLE_SECTOR_CACHE");

  _task_block();

}

---

With the flashx configuration above, you can modify for example the MQX MFS ramdisk example to be used on a flashx device.

I think the MFS is not intended to be used on a flash memory without a wear leveling layer (as FAT table is frequently updated, the internal flash could wear out due to too many Program/Erase cycles).

Regards,

Martin


1,091 Views
rudra
Contributor II

Hi Martin

     I read your reply regarding MFS installation in internal flash. You stated "I think the MFS is not intended to be used on a flash memory without a wear leveling layer (as FAT table is frequently updated, the internal flash could wear out due to too many Program/Erase cycles)". I read about wear leveling layer but i can't understand how to find my MCU flash is with wear leveling layer or not.I am using MK60DN512VLQ10 MCU. please help regarding that.

I am also looking for way to determine how much extra code memory required to install MFS on internal Flash??

Thanks

0 Kudos

1,091 Views
Martin_
NXP Employee
NXP Employee

Your device has no wear leveling in hardware, as it has Program flash only.

(there are devices with FlexMemory - K60DX in the part number - they have wear leveling = 4 KB of EEPROM emulation in hardware).

If you use MFS mainly for read and your application writes to MFS only seldom, you can forget wear leveling. But if your application updates MFS frequently you will need wear leveling layer in software. You will need to develop a software, which sits between MFS and flashx driver and which spreads the program/erase load of the internal flash sectors equally. (By the way, common use case of MFS on SD card employs wear leveling algorithms inside the SD card itself).

For code size, you can build mfs_ramdisk example application and check the result footprint.

1,091 Views
rudra
Contributor II

Hi Martin

Thanks for reply.

Just one query. I read in forums and one online pdf ( sharing link https://publications.theseus.fi/bitstream/handle/10024/48325/Kangasharju_Teemu.pdf?sequence=1) that "The creation of the file system is possible when the chip packet has Flex NVM memory" as u can see from data sheet MK60DN512VLQ10 MCU don't have Flex NVM memory, still can i use MFS on it ??

My application has one requirement,

I want to store system configuration (such as ip)run time entered by user, store them to persistent memory and use them at booting time to initialize my device. Any suggestion ??

Thanks.

0 Kudos

1,091 Views
Martin_
NXP Employee
NXP Employee

MFS can talk directly to flashx driver, flashx driver can program/erase Kinetis Program flash. It is possible.

However, for your application (store and read just couple of bytes of data), MFS might be an unnecessary overhead. You can use the MQX flashx driver to write and read data structures directly to/from internal flash of your Kinetis device, without using MFS. Source code example for this can be found in

c:\Freescale\Freescale_MQX_4_0\mqx\examples\flashx\flash_demo.c

This example application shows how to write some data bytes to last sector of the internal flash. You can store your parameters to a data structure in RAM, and use _io_write("flashx:",....) to program the data structure to internal flash from an MQX task.

1,091 Views
rudra
Contributor II

Hi Martin

Thanks for reply

I looked into flash_demo.c, i have some query regarding example.

1. In example we open bank 0 of flash,  fseek to end,  back several bytes and then write our data. Is it necessary to seek to end ??

2. can i write to start immediately opening flash bank 0 ??

3. In one of application bootloader pdf i read that last 4KB of flash is reserved for bootloader parameter. If i seek to end and then write data, is there a possibility that my data may corrupt bootloader parameter memory ?? should i take care of bootloader 4KB offset also???

please reply.

0 Kudos

1,091 Views
Martin_
NXP Employee
NXP Employee

Ad 1. No, it is not necessary to fseek to the end. But it is necessary to fseek to the location where you wish start reading/writing.

Ad 2. Yes

Ad 3. Yes

0 Kudos

1,091 Views
rudra
Contributor II

Hi Martin

I need to write some values to the bootloader parammeter area that in my case starts from 0x0007F000 and ends at 0x0007FFFF.

Also this memory area mentioned above comes in Flash Bank1.

Please provide some pointers to read/write this area.

I can successfully read/write in Flashx Bank0.

Thanks.

0 Kudos

1,091 Views
Martin_
NXP Employee
NXP Employee

for example:

const FLASHX_FILE_BLOCK _bsp_flashx_file_blocks[] =

{  

    { ""    , 0x0, 0x7FFFF },

    { NULL  , 0, 0 }

};

file_ptr = fopen("flashx:",0);

ioctl(file_ptr, FLASH_IOCTL_ENABLE_SECTOR_CACHE, NULL);

fseek(file_ptr, 0x7F000, IO_SEEK_SET);

write(file_ptr, buffer, size);

0 Kudos

1,091 Views
rudra
Contributor II

Thanks for reply.

I have written some data in the user flash memory area and it has been written successfully, can i see the data written in Flash using IAR. I have tried the the same but found that memory shown in IAR is virtual memory not the actual flash. How can I see those flash values??

0 Kudos

1,091 Views
myke_predko
Senior Contributor III

Sorry Martin,

No Joy - I have updated the service request.  I have attached the updated initMFS as per your suggestion.

NOTE: the partition manager still fails, so this is commented out.

If anybody sees what I'm doing wrong, I would appreciate it,

myke

0 Kudos

1,091 Views
timias
Contributor IV

I think you need to install the partition manager over flashx , and mfs onto the partion manager.

Not MFS directly onto the FlashX Driver, as you have.

I am not 100% certain as I am using the SD Card, not FLASHX but I think it works the same way.

 

 

0 Kudos

1,091 Views
myke_predko
Senior Contributor III

Hi Timias,

 

Thank you for the suggestion. 

 

I tried to come up with the code for implementing partitions (attached) for both partition 0 and 1 only to have it fail when validating the partition with a "PMGR INVALID PARTITION" error. 

 

I tried commenting out the partition validation step only to fail on opening the filesystem ("c:") with an "UNKNOWN ERROR !!!".

 

Anybody have any suggestions as to what I am doing wrong? 

 

Thanx!

 

myke

0 Kudos

1,091 Views
timias
Contributor IV

I only use a single partition, but my partition number that I pass through to the IOCTL function is 1 not 0.

partition_number = 1;

error_code =

_io_ioctl(partman_handle, IO_IOCTL_VAL_PART, &partition_number);

0 Kudos

1,091 Views
myke_predko
Senior Contributor III

Hi Timias,

 

Sorry, I should have been more clear in my previous reply to you, I did try both "0" and "1" for "partition" but sent the code that still had "partition = 0;". 

 

When I set "partition = 1;", I get basically the same error as if it were equal to zero:

 

"Error validating partition 1: PMGR INVALID PARTITION"

 

Any suggestions where I should be looking? 

 

Thanx for taking the time to help,

 

myke

0 Kudos