___FLASHX_SECT_SIZE does not match data sheet..?

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

___FLASHX_SECT_SIZE does not match data sheet..?

Jump to solution
920 Views
CarlFST60L
Senior Contributor II

Hi,

 

I am using hte MCF52259 processor with MQX3.6..2.

 

From the 52259 reference manual:

 

"23.4.1.8 Sector Erase
The Sector Erase command erases the contents of a 2-Kbyte space of flash memory. "

 

From the lcf file

 

   # Flashx configurations
   ___FLASHX_SECT_SIZE = 0x1000; (this is 4K)

 

Can I just update ___FLASHX_SECT_SIZE to 0x800 to match the data sheet? Will this then allow me to erase the minimum sector size of 0x800? Or is there some other reason MQX only allows you to erase 4K blocks instead of 2K blocks?

 

Carl.

0 Kudos
1 Solution
615 Views
DavidS
NXP Employee
NXP Employee

Hi Carl,

Flash sector size is based on the total flash size divided by 32 (since flash protection register has 32-bits).

For the MCF52259 with 512Kbyte divided by 32 gives 4Kbyte(0x1000) erase sector size.

Hope this helps.

Regards,

David

View solution in original post

0 Kudos
7 Replies
616 Views
DavidS
NXP Employee
NXP Employee

Hi Carl,

Flash sector size is based on the total flash size divided by 32 (since flash protection register has 32-bits).

For the MCF52259 with 512Kbyte divided by 32 gives 4Kbyte(0x1000) erase sector size.

Hope this helps.

Regards,

David

0 Kudos
615 Views
CarlFST60L
Senior Contributor II

Hi David, thanks for the response.

 

So, basically, MQX does not support the minimum erase size of 2048KB (based on the data sheet quote above) due to the configuration of the flash protection? Does this mean I can make my sector size 2048 and flash protection just wont work properly?

 

Memory size is far more important that protection for our application. 

 

Regards,

Carl Norman

 

 

0 Kudos
614 Views
DavidS
NXP Employee
NXP Employee

Hi Carl,

The flash sector and page size chnage depending on the total flash size implemented with the MCU.

With the MCF52259 that has 512KB the sector size is 16KBytes(0x4000) and therefore we have 32 so that one 32-bit flash protection register my be used.

Each 16KB sectoris made up of 4 pages that are 4KB(0x1000).

Flash Erase operation can erase on a page by page basis or erase the total flash (mass erase).

 

With flash writing you can actually write individual 32-bit values as an example of data logging to flash....though this is bad example since there is no wear leveling implemented.  Better example would be updating and storing system configuration information to one page of flash.  So to update you would read in that page to SRAM, update the system information in SRAM, erase the page, then write the page to flash.

Hope this helps.

Regards,

David

0 Kudos
615 Views
CarlFST60L
Senior Contributor II

Hi,

 

Thanks for taking the time to respond.

 

I don't think I am being clear. What we are trying to work out is can MQX be configured to erase the minimum flash page size specified by the 52259 data sheet? The data sheet states the minimum flash erase size is 0x1000, yet MQX only allows you to erase 0x4000 and 0x4000 is far to large for your application.

0 Kudos
615 Views
DavidS
NXP Employee
NXP Employee

Hi Carl,

I often don't hear what people are asking!  Sorry.

Yes you can erase 0x1000 with FSLMQX.

I cannot attach file for some dumb reason...will hassle our IT people...but hear is copy-n-paste of it.

 

uint_32 app_flash_erase
   (
      uint_32 initial_data
   )
{
 
   FLASHX_BLOCK_INFO_STRUCT_PTR info_ptr;
   FILE_PTR       flash_hdl;
   _mqx_uint      error_code=FALSE;
   _mem_size      base_addr;
   _mqx_uint      num_sectors;
   _mqx_uint      num_blocks;
   _mqx_uint      width;
   _mem_size      total_size = 0;
   _mem_size      block_boundary_addr = 0;
   uchar_ptr      read_buffer;
   _mqx_int       i, k;
   _mem_size      seek_location;
   _mem_size      read_write_size = 0;
   _mqx_uint      ident_arr[3];
   boolean        test_completed = FALSE;     

   puts("\n\nMQX Flash Erase Program");
  
   /* Open the flash device */
   flash_hdl = flash_open(FLASH_NAME);
  
   _io_ioctl(flash_hdl, IO_IOCTL_DEVICE_IDENTIFY, &ident_arr[0]);
   printf("\nFlash Device Identity: %#010x, %#010x, %#010x",
             ident_arr[0], ident_arr[1], ident_arr[2]);
     
   error_code = ioctl(flash_hdl, FLASH_IOCTL_GET_BASE_ADDRESS, &base_addr); //DES base_addr=Start Address of Application Code
   if (error_code != MQX_OK) {
      printf("\nFLASH_IOCTL_GET_BASE_ADDRESS failed.");
      _task_block();
   } else {
      printf("\nThe BASE_ADDRESS: 0x%x", base_addr);
   } /* Endif */
    
   error_code = ioctl(flash_hdl, FLASH_IOCTL_GET_NUM_SECTORS, &num_sectors);
   if (error_code != MQX_OK) {
      printf("\nFLASH_IOCTL_GET_NUM_SECTORS failed.");
      _task_block();
   } else {
      printf("\nNumber of sectors: %d", num_sectors);
   } /* Endif */

   error_code = ioctl(flash_hdl, FLASH_IOCTL_GET_WIDTH, &width);
   if (error_code != MQX_OK) {
      printf("\nFLASH_IOCTL_GET_WIDTH failed.");
      _task_block();
   } else {
      printf("\nThe WIDTH: %d", width);
   } /* Endif */

   error_code = ioctl(flash_hdl, FLASH_IOCTL_GET_BLOCK_MAP,
      (uint_32 _PTR_)&info_ptr);     
   if (error_code != MQX_OK) {
      printf("\nFLASH_IOCTL_GET_BLOCK_MAP failed.");
      _task_block();
   } /* Endif */
           
   error_code = ioctl(flash_hdl, FLASH_IOCTL_GET_BLOCK_GROUPS, &num_blocks);
   if (error_code != MQX_OK) {
      printf("\nFLASH_IOCTL_GET_NUM_BLOCKS failed");
      _task_block();
   } /* Endif */

   for ( i = 0; i < num_blocks; i++ ) {
       printf("\nThere are %d sectors in Block %d", info_ptr[i].NUM_SECTORS,
          (i + 1));
       printf("\nBlock %d Sector Size: %d (0x%x)", (i + 1),
          info_ptr[i].SECT_SIZE, info_ptr[i].SECT_SIZE);
       total_size += (info_ptr[i].SECT_SIZE * info_ptr[i].NUM_SECTORS);
   } /* Endfor */
     
   printf("\nApplication size of the Flash to erase is: %d (0x%08x) bytes", total_size,
      total_size);
  
   #if WRITE_PROTECT_TEST
     flash_write_ptotect_test(flash_hdl);  
   #endif

   read_write_size = info_ptr[num_blocks-1].SECT_SIZE; //DES get "page" size to erase
   read_buffer = allocate_buffer(read_write_size, read_write_size, "read");  //DES
   if (read_buffer == 0 ) {
     printf("\n\tFailed to acquire memory");
        _task_block();
} /* Endif */

   seek_location = 0;
     
   for ( k = 0; k < num_sectors; k++) {

      /* Seek to sector, and erase it */
//DES         printf("\nTesting _io_ioctl erase_sector: %d (0x%x)", seek_location, seek_location);
         fseek(flash_hdl, seek_location, IO_SEEK_SET);
         error_code = _io_ioctl(flash_hdl, FLASH_IOCTL_ERASE_SECTOR, NULL);
         if (error_code != MQX_OK) {
            printf("\nFLASH_IOCTL_ERASE_SECTOR failed.");
            _task_block();
         } /* Endif */
     
         /* Seek to erased sector, and read it */
         fseek(flash_hdl, seek_location, IO_SEEK_SET);
         i = read(flash_hdl, read_buffer, read_write_size);
         if (i != read_write_size ) {
            printf("\nFailed to read flash, 0x%x", _task_get_error());
         } /* Endif */
         /* Check if all ff's */
         for ( i = 0; i < read_write_size; i++ ) { 
            if (read_buffer[i] != 0xff) {
               printf("\nFailed to erase flash at index %d  Seek location %d (0x%x)", i, seek_location, seek_location);
               _task_block();
            } /* Endif */
         } /* Endfor */
         seek_location+=0x1000;  //DES increment pointer to next relative sector address to erase
     
   } /* Endfor */

 /* Close device */
 flash_close(flash_hdl);


 /* end */
 printf("\n\tErase finshed");
 return(error_code);  //DES-USBStick
}

 

Hope this helps.

Regards,

David

0 Kudos
615 Views
CarlFST60L
Senior Contributor II

Hi David,

 

Thanks again, greatly appreciated.

 

I made a mistake in my last post, the data sheet says the minimum size for erase is 0x0800 (2048), I said 0x1000 (4096) by mistake. Can I just change the above code to 0x0800 instead of 0x1000 to make FSLMQX erase the minimum size?

 

Regards,

Carl Norman.

0 Kudos
615 Views
DavidS
NXP Employee
NXP Employee

Hi Carl,

I think 0x1000 is minimum but will try to verify that ....soon.  Currently on the road but back next week.

Regards,

David

0 Kudos