This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Problem trying updating firmware through SCI using Flash API

Hi all:

I am trying to implement a firmware update function using Flash API similar to the example that comes with Flash API document.

  1. The firmware is executing normally until is receives a certain command that requests an update is received from the SCI port.
  2. Once the command is received, the WD disabled, DINT, and  the MemCopy() is run to copy Flash API  and then MemCopy() to copy custom functions to the secured LO memory.
  3. the main function UpdateFrm() is called ( it 's run from LO memory)
  4. Inside the UpdatedFrm() function Flash2812_Erase( AllSectors) is called.
  5. SendStatus(" Flash Memory Erased \n\r") is called.

                   Problem happens here.

  1. A BlockProcess() function is called (similar to one from the example) to copy image file to the flash memory.

Problem: Inside the SendStatus(char* msg) function the message msg points to NULL after Flash2812_Erase has run.  It looks like the Flash2812_Erase erases something like stack or similar.

Did somebody had similar problem?

Is possible to erase all the flash memory sectors and then upload a new image? (when the Flash API is part of the firmware).

Thanks,

Yvon.

  • Yvon Carlsson said:
    1. SendStatus(" Flash Memory Erased \n\r") is called.

                       Problem happens here.

    1. A BlockProcess() function is called (similar to one from the example) to copy image file to the flash memory.

    Problem: Inside the SendStatus(char* msg) function the message msg points to NULL after Flash2812_Erase has run.  It looks like the Flash2812_Erase erases something like stack or similar.

    The most likely cause of this is that the string "Flash Memory Erased \n\r" and/or its pointer are in Flash (and are thus erased by the previous step).  I think it is likely that the string is stored in .econst which must reside in Flash.  One way to ensure this doesn't happen is to do something similar to the following:

    1) Make a constant array:

    char ErasedString[] = "Flash Memory Erased \n\r";

    2) Give it a data section: #pragma DATA_SECTION(ErasedString, "strings")

    3) In the linker command file assign section strings to be in flash but to run in RAM.

    4) When updating, copy the string to RAM like you do with the code.'

    5) Call SendStatus(ErasedString);

    I think this will make sure the string is in RAM when you need to call it and it should hopefully work,

    Tim

  • Hi Tim.

    Thanks for your help!!!

    The whole project works now. If strings are defined like "my string" , they are stored in the .econst flash just as you explained and erased.

    what interesting if  a string is defined like this:

    #pragma DATA_SECTION(SomeString, 'strings") where strings are in LO SARAM, for example.

    char* SomeString = "example string";  The pointer will be kept in the LO memory and points to data in the flash (.econst?).

    If a string defined like Tim suggested:

    char SomeString[] = "example string"  It will be stored in the LO SARAM.

     

    Thanks,

    Yvon.