flashx example Help

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

flashx example Help

Jump to solution
3,653 Views
MQXuser
Contributor III

  write_buffer = allocate_buffer(read_write_size, k, "write");
  old_buffer = allocate_buffer(read_write_size, k, "old");
    
     /* fill data to write buffer */
     for ( i = 0; i < read_write_size; i++ ) { 
        write_buffer[i] = i;
     } /* Endfor */


     seek_location = 0x0007E000;

     /*read*/
     fseek(flash_hdl, seek_location, IO_SEEK_SET);
     i = read(flash_hdl, old_buffer, read_write_size);
     size_compare(flash_hdl, i, read_write_size);
    
     /*erase*/        
     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();
     }   

     /*write*/
     printf("\nSeek to sector and modify (may take a while)");
     fseek(flash_hdl, seek_location, IO_SEEK_SET);
     i = write(flash_hdl, write_buffer, read_write_size );
     size_compare(flash_hdl, i, read_write_size);

 

I am trying to write and read a "sector" in M52259, but I dont know how to do it. I tried using the code above which comes with the flashx example but it doesnt work. Question is:

 

what doest seek_location means and how to relate that number with an address?

How many bytes does a sector contain?

 

Hope someone can help me.

0 Kudos
1 Solution
933 Views
PavelM
NXP Employee
NXP Employee

Ensure you have in user_config.h file

#define BSPCFG_ENABLE_FLASHX  1

 

check, if you have defined the BSPCFG_FLASHX_SIZE. This value is used in flashx init function - _mcf52259_internal_flash_install which is called form init_bsp.c

 

View solution in original post

0 Kudos
8 Replies
933 Views
PavelM
NXP Employee
NXP Employee

seek_location mean the address in flashx space.

I suppose you used the internal flash target. In this demo is internal flash separated into two parts - code and flashx space. The flashx size is depend on code size, flashxsize = total flash size - code size, the size is counted in function _mcf52259_internal_flash_install. Definitions like FLASHX_SECT_SIZE, FLASHX_START_ADDR are defined in intflash.lcf file. See details in that file.

 

In this case is the sector size 0x1000.

 

It is possible, in your example, the flashx size is smaller than 0x0007E000, and you are out of the range.

0 Kudos
933 Views
MQXuser
Contributor III

   Thanks for your answer. I am not sure I completely understand, in intflash.lcf file I read

 

 

    ___FLASHX_START_ADDR = (_flashx_start + 0xfff) / 0x1000 * 0x1000;
    ___FLASHX_END_ADDR = ___INTERNAL_FLASH_BASE + ___INTERNAL_FLASH_SIZE;

 

 

    and
   

    ___INTERNAL_FLASH_BASE = 0x00000000;
    ___INTERNAL_FLASH_SIZE = 0x00080000;

 

    thus, the flashx end is at 0x00080000 and I am not trying to write in locations greater than that
    (in my example I try at 0x0007E000).
   
    then, I found
   

        _flashx_start = __COPY_OF_DATA + SIZEOF(.main_application_data) +
                SIZEOF(.romp);

 

    I figured this is the size of the program code, and although I dont know the actual number,
    I am almost sure the code program does not use memory after 0x0007E000(because the program is small).
   
    Then, what could be causing the error?, How come I never see flash changing when debugging(even without changing the example to 0x0007E000. If the examples writes at 0x2400 I go to that address with the view memory option and I dont see anything changing.)?
   
I also found this definition at BSP libraries:
   
  
 BSPCFG_FLASHX_SIZE = 0x4000

 

    Why do I have to define that if it is already defined in intflash.lcf file?

Hope you can help me. Regards.

 

0 Kudos
933 Views
PavelM
NXP Employee
NXP Employee

The actual FLASHX_START_ADDR addres you can find in the project *.xMAP file. In internal flashx example you can find in intflash_d.elf.xMAP file followed lines:

#>0000F3A8          _flashx_start (linker command file)#>00010000          ___FLASHX_START_ADDR (linker command file)#>00080000          ___FLASHX_END_ADDR (linker command file)

 

 

If you will write to address 0x0007E000, the real address is 0x0007E000 + FLASHX_START_ADDR = 0x8E000, and this is out of flash borders in this example.

If you use the flashx driver, you address within the flashx driver's space, not in physical device address space.

 

The BSPCFG_FLASHX_SIZE  0x4000 is default value, if isn't defined in lcf file.

0 Kudos
933 Views
MQXuser
Contributor III

I need to change the start address of my flashX to 0x0007E000.

Inintflash.lcf there is:

 

    ___FLASHX_START_ADDR = (_flashx_start + 0xfff) / 0x1000 * 0x1000;

 

but as soon as I change it to

    ___FLASHX_START_ADDR = 0x0007E000;

 

MQX never initialize the FlashX IO device and I can never use flash. Does anybody knows which files do I ahve to change in order to define the start of flashX ??

0 Kudos
934 Views
PavelM
NXP Employee
NXP Employee

Ensure you have in user_config.h file

#define BSPCFG_ENABLE_FLASHX  1

 

check, if you have defined the BSPCFG_FLASHX_SIZE. This value is used in flashx init function - _mcf52259_internal_flash_install which is called form init_bsp.c

 

0 Kudos
933 Views
MQXuser
Contributor III

Thanks Pavel, I was forgetting to define the SIZE and since the default value is 0x4000, I was exceeding from the amount of total RAM. Now I set it to be 0x2000 and is working fine.

0x0007E000 + 0x4000 =  0x00082000  = Outside range.  

0x0007E000 + 0x2000 =  0x00080000  = Range is ok. 

Regards.

0 Kudos
933 Views
CarlFST60L
Senior Contributor II

I had some issues, from memory I think it just comes down to understanding the processor and MQX. For example, if you have MQX configured to store the vectors / cfm in ROM (0 - 420), when you run from MRAM, obviously CFM_PROT is not programmed and will not work as its protected depending on how flash is programmed (MQX doesnt really handle this error well either, from memory it calls an exception), so, move the vectors to ram and it will work I think! The example should not allow you to run MRAM debug if you do not have vectors running from RAM might be a good solution from MQX. I also changed the flashx from 0x00000000 to 0x00080000, and made the flash size 0x000800 them managed the memory myself.

 

I have developed our own BSP and changed much of the MQX configuration since testing the flashx example so I cannot recall exactly.

 

Hope this helps.

 

 

 

 

Message Edited by CarlFST60L on 2009-09-01 08:00 AM
0 Kudos
933 Views
MQXuser
Contributor III

I'm really having a hard time getting writing to flash to work...

 

I am also trying my own functions without the MQX driver but my application crashes in this function:

 

 

volatile int CFM_page_erase (unsigned int address)
{  
    /* Allocate space on stack to run flash command out of SRAM */
 char buf[100];
 int (*RunOnStack)(void) = (int(*)(void))buf;
 volatile CFM_REG_STRUCT_PTR  cfm_reg_ptr;
  
 memcpy(buf, (void*)SpSub, (char*)SpSubEnd - (char*)SpSub);
   
    cfm_reg_ptr = (pointer)(&((VMCF5225_STRUCT_PTR)_PSP_GET_IPSBAR())->CFM);
    
    (*(volatile vuint32 *)(FLASH_START_ADDRESS+address)) =  -1;

 cfm_reg_ptr->CFMCMD = MCF_CFM_CFMCMD_PAGE_ERASE;
 RunOnStack();

 /* Check for Errors */
 if (cfm_reg_ptr->CFMUSTAT & MCF_CFM_CFMUSTAT_ACCERR) {return 0;}
 if (cfm_reg_ptr->CFMUSTAT & MCF_CFM_CFMUSTAT_PVIOL)  {return 0;}
 return(1);

}

 

 When I make continous calls to this function an error shows in code warrior ( Exception vector name: Address Error ).

The error not always shows, I am making more tests, but what I would like to know is if I am missing something in the function I show above.

 

If somebody know about my question in the first post, please let me know.

 

Regards

 

 

 

Message Edited by MQXuser on 2009-08-28 02:39 AM
0 Kudos