Flash programming

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

Flash programming

4,830 Views
eitanm
Contributor I

 

Hello,

 

I have to be able to load onto the { K60, K40, K10 } devices I'm working on 2 applications.

The first is a loader that will use 16K starting at address 0;

The other is the main application starting at the end address of the loader. 

My hardware does not include FlexNVM. The loader application should be able to get external data (from a UART or from a file system loaded on the SD card) and program the main application section on flash.

 

I need some guidance here, what to read, how to approach this..

 

Thanks,

Eitan.

 

0 Kudos
Reply
15 Replies

2,439 Views
Nana
Contributor II

Hi Igordlx,

 

I'm trying to do same job like you done on K60, I try to copy from an SPI flash a firmware and put it in program flash of K60 from where to run the code !

I have managed to do entire new SPI Flash read and writte an flash LongWord Writtening because I don't want to use MQX drivers. Can u share yours code with me to see what u made! I want to copy the content of the spi flash in ram and from there to writte the hole block memory !

Thank You,

Alexandru Nan

Embedded Software Engineer

0 Kudos
Reply

2,439 Views
FirmEE
Contributor II

Hello Eitan,

Did you get any help with this as yet?  I'm in a similar situation now. I need to be able to program the upper half of the flash while my application isin the lower half.  I cannot find any library support that writes to FLASH on the K60 part.

 

Mike B

0 Kudos
Reply

2,439 Views
Dekiru
Contributor IV

Freescale has a flash driver software here: http://www.freescale.com/webapp/sps/site/prod_summary.jsp?code=K60&nodeId=01624698C9&fpsp=1&tab=Desi...

 

You should use the API that is provided there because it is maintained by Freescale and common for many different platforms.

 

Regards

0 Kudos
Reply

2,439 Views
igor-imx
Contributor IV

Thank you very much for posting the links to the driver software.

I have downloaded it and tried the demos, they do exctly what im looking for except one thing.

The demo code is designed to run from ram.

Does anyone have any experience with the IAR compiler on how can i make all the driver functions relocatable?

The scenario im working with is a K60 with MQX running.

I have a routine that allows me to upload a new FW file to the spi flash chip i have one the custom board.

What i need to accomplish is read the data from the spi flash and program the K60 Flash with the new image.

this requires all the driver functions to be run from RAM.

I was reading the IAR documents regarding the code placement in ROM and then moving it to RAM but still can't figure it out.

 

I have also read all the posts on here regarding the topic and https://community.freescale.com/message/73480#73480 give a general idea on how to accomplish this if you are doing everything from within one function.

I want to utilize the driver provided by Freescale to write to K60 flash thus i need to figure out how to put it all from ROM to RAM and then run the functions i need from ram.

 

Any help or example code would be really appriciated.

 

0 Kudos
Reply

2,439 Views
LuisCasado
NXP Employee
NXP Employee

Hello Igordlx,

 

MQX includes the flashx driver. In your case with MQX, perhaps is the best option.

 

Yo should run flash routines in one flash bank if you are writting to the other flash bank, otherwise, you must run the flash routines in RAM.

 

 

Best Regards,

 

Luis

0 Kudos
Reply

2,439 Views
igor-imx
Contributor IV

Hi Luis

Thank you for your post.

In my scenario i will be overwring the whole K60 flash which effectively contains MQX as well so i know have to run the upgrade functions from ram.

My promlem is that i still can't seem to figure out how to do exactly that:

1. link certain code at the certain ROM location

2. Copy it to ram when it needs to get executed

3. Execute it from RAM to upgrade the rom

 

If you have any example linker files and/or code that does this, share it on here please.

 

Regards

 

Igor

0 Kudos
Reply

2,439 Views
igor-imx
Contributor IV

So i read IAR documentation more and in one of the sections:

 

Sometimes, an application copies pieces of code from flash/ROM to RAM. This can be easily achieved by ILINK for whole code regions. However, for individual functions, the __ramfunc keyword can be used, see Execution in RAM, page 32.

Part 1. Using the build tools

81

Linking considerations

List the code sections that should be initialized in an initialize directive and then place the initializer and initialized sections in ROM and RAM, respectively.

In the linker configuration file, it can look like this:

/* Split the .textrw section into a readonly and a readwrite section */ initialize by copy { section .textrw };
/* Place both in a block */ define block RamCode { section .textrw }; define block RamCodeInit { section .textrw_init };
/* Place them in ROM and RAM */ place in ROM { block RamCodeInit }; place in RAM { block RamCode };

The block definitions makes it possible to refer to the start and end of the blocks from the application. 

 

and i have did just that.

Now, in the other section it says in regards to the #pragma location:

 

Use this pragma directive to specify the location—the absolute address—of the global or static variable whose declaration follows the pragma directive. The variable must be declared __no_init. Alternatively, the directive can take a string specifying a section for placing either a variable or a function whose declaration follows the pragma directive. Do not place variables declared as __no_init and variables declared as const in the same named section. 

 

I then created a test function and place #pragma location directive at the start of the file like below:

 

#pragma location = "RAMCODE"

void int test(void)

{

uint32 iTest = 0;

iTest++;

}

 

however when the debugger hits the breakpoint set inside the test function i can't step through it.

What am i doing wrong here?

Basicall all im trying to do it to run the test function from ram instead of ROM


Best Regards

 

Igor



0 Kudos
Reply

2,439 Views
igor-imx
Contributor IV

Here is another link Exactyly what im trying to accomplish solved but with Keil tools for different micro.

http://www.keil.com/appnotes/files/apnt_138.pdf

Any idea how to do this with K60 and IAR ???

 

Thanx

 

Igor

0 Kudos
Reply

2,439 Views
igor-imx
Contributor IV

So i managed to accomplish running the upgrade function as well as several dunctions from the Flash Access API from RAM by utilizing the overlays in IAR linker.

However, no i have another issue.

After i write the new image to the Program Flash of the K60, it  doesn't start up after the upgrade and when i try to flash the K60 using the debugger, it says that the processor has security enabled and that it needs to wipe the whole program flash first.

I have verified that the image that is getting writen to the program flash is correct and all the offsets are correct as well.

Do i need to do something more than just upload and write the binary file producted by IAR into the program flash?

Any ideas on what to look for?

 

 

0 Kudos
Reply

2,439 Views
igor-imx
Contributor IV

Please disregard the previous post, that was an error on my side.

I finally got end to end FW upgrade though the web working solid and fast. :smileyvery-happy:

0 Kudos
Reply

2,439 Views
artur73
Contributor I

Hi Igor-imx,

Do you use flash swap feature?

My current task - have possibility to update the K60's firmware via WEB and swap active and uploaded fw images. Can you provide me with some examples, how to do that?

Thanks in advance.

0 Kudos
Reply

2,439 Views
Tim_X
Contributor I

Hi ,Igordlx

 

i guess that you have got FW upgrade through the tftp.

 

Just now i am using the same mode to boot  and faceing a serious problem.  In the FNET, when the app program upgraded , the  PC will jump  to entrance of the app ,  but the hard fault Interrupt was occurced. what can i do,please tell me.THX:smileysad:

0 Kudos
Reply

2,439 Views
igor-imx
Contributor IV

Just to add to the above, i found the how-to but for the different tool chain here :http://www.tasking.com/support/c166-classic/AN019-13_v8.PDF

 

It examplains the exact behavior that im trying to achive.

Hope there are some IAR gurus on here to help out with this :smileywink:

0 Kudos
Reply

2,439 Views
egoodii
Senior Contributor III

Actual erase/write to flash is the 'easy part'; code below.  The hard part is setting up the tools to understand the bootloader/application-space setup, determining 'validness' of application image, and other such implementation details.  One thing to keep in mind:  You can't erase/write the 'bank' you're running in!  For applications that truly 'ping pong' between two half-flash-sized full memory code images, the latest 1.2 (and higher) silicon implements a fairly robust flash control mechanism for updating the 'opposite bank' with hooks to recover failed attempts.  For the case with 16K 'low boot', rest 'APP' -- that matches my world, and for that the IAR linker provides some help in that I allow it to link the bootloader code to RAM addresses and its startup copies it all out there and runs from there, freeing any concern over Flash bank execution restrictions.  I use the IAR linker also to fill unused Flash space with SVC 0xDF interrupts, and place a CRC32 at the end which I check using the Kinetis CRC module.

 

--ERGII

 

static int fnFlashNow(uint8_t ucCommand, uint32_t ptrWord, uint32_t ulWord)

{

  do{

  }while (!(FTFL_FSTAT & FTFL_FSTAT_CCIF_MASK)); // wait for previous commands to complete

  if (FTFL_FSTAT & (FTFL_FSTAT_ACCERR_MASK | FTFL_FSTAT_FPVIOL_MASK)) { // check for errors in previous command

    FTFL_FSTAT = (FTFL_FSTAT_ACCERR_MASK | FTFL_FSTAT_FPVIOL_MASK); // clear old errors

  }

  switch (FTFL_FCCOB0 = ucCommand) { // enter the command sequence

  case FCMD_ERASE_ALL_BLOCKS: // single command word required with the erase all blocks command

    break;

  case FCMD_SWAP_CONTROL:

    FTFL_FCCOB6 = 0xFF; //Clear these status bytes, in case of fault

    FTFL_FCCOB7 = 0xFF;

  case FCMD_PROGRAM_SECTION:

    if( ucCommand == FCMD_PROGRAM_SECTION )

      ulWord >>= 3; //Convert to dual-dword count

    FTFL_FCCOB4 = (u8_t)(ulWord >> 8);

    FTFL_FCCOB5 = (u8_t)(ulWord);

  case FCMD_ERASE_FLASH_SECTOR:

    FTFL_FCCOB1 = (u8_t)(((CAST_POINTER_ARITHMETIC)ptrWord) >> 16);

    FTFL_FCCOB2 = (u8_t)(((CAST_POINTER_ARITHMETIC)ptrWord) >> 8);

    FTFL_FCCOB3 = (u8_t)((CAST_POINTER_ARITHMETIC)ptrWord);

    break;

  }

  Disable_Interrupt(); // protect this region from interrupts

  FTFL_FSTAT = FTFL_FSTAT_CCIF_MASK; // launch the command - this clears the FTFL_STAT_CCIF flag (register is FTFL_FSTAT)

  while (!(FTFL_FSTAT & FTFL_FSTAT_CCIF_MASK)) {} // wait for the command to terminate

  return (FTFL_FSTAT & (FTFL_FSTAT_ACCERR_MASK | FTFL_FSTAT_FPVIOL_MASK 

                |  FTFL_FSTAT_MGSTAT0_MASK)); // if there was an error this will be non-zero

}

 

And a block copy of one memory area to flash is just:

 

bool_t fnCopyBoot( uint32_t srcptr, uint32_t dstptr )

{

  uint16_t file_length = APP_START; //This example moves a whole bootloader image size

  uint16_t usBlockSize = BLOCK_SIZE;       //This is 2K, of course

 

  while (file_length) {

    if (file_length < BLOCK_SIZE) {

      usBlockSize = (u16_t)file_length; // last block smaller than full block size

    }

    Memcpy_long((uint32_t *)&FlashRAM, (uint32_t *)srcptr, (uint32_t)usBlockSize); //Copy current code to burn-RAM

    if( fnFlashNow(FCMD_ERASE_FLASH_SECTOR, dstptr, usBlockSize) ) {

      return FALSE; // error

    }

    fnFlashNow(FCMD_PROGRAM_SECTION, dstptr, usBlockSize);

    srcptr += usBlockSize;

    dstptr += usBlockSize;

    file_length -= usBlockSize;

  }

  return TRUE;

}

 

0 Kudos
Reply

2,439 Views
mjbcswitzerland
Specialist V

Eitan

 

The uTasker serial loader includes all required support for SREC and USB boot loading:

- http://www.utasker.com/docs/uTasker/uTaskerSerialLoader.PDF 

It can be seen here too:

- http://www.youtube.com/watch?v=H4TYM9jY2-g

 

Regards

 

Mark

 

 

 

0 Kudos
Reply