Some questions about Flash driver

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

Some questions about Flash driver

1,511 Views
phi
Contributor I

Hello Everybody,

I am working on S32K144 for software update, So i have some questions ,Could you please help me to clarify them, Thank you!

1) In my project, i already moved vector table and ISR handler on RAM. i only use 2 ISRs, that is FTM and UART interrupt. and So i always got system reset when executing the below function:

ret = pFlashCommandSequence(pSSDConfig);

And make sure the g_FlashLaunchCommand is excuted on RAM.

Note: for this case: i erase/write data into flash without disabling all interrupts

2) for this case:  erase/write data into flash with disabling all interrupts, then the system runs well. So with disabling all interrupts. i want to know that my timer can be run exactly define time or not? that means during erasing /writing flash,  we should disabling all interrupts. So maybe it can cause the timer run incorrectly with time which is configed before.

Best regards,

Phi Le

Labels (1)
0 Kudos
Reply
3 Replies

1,196 Views
danielmartynek
NXP TechSupport
NXP TechSupport

Hi,

If the vector table as well as the routines are in RAM, there should be no problem. I don't know what drivers you are using so it is difficult to say. But it triggers an exception so you can find out what exception it is and debug the code.

Fault handling on S32K144 

Regards,

Daniel  

0 Kudos
Reply

1,196 Views
phi
Contributor I

Hello Daniel,

Thank you for your response,

yes, I already move vector table to ram,

A) [Daniel] If the vector table as well as the routines are in RAM, there should be no problem

1) This is the code in linker file:

/*********************************************************************************/
/* ROM Area */
/*********************************************************************************/

.ROM.intc_vector ROM(.intc_vector) ALIGN(0x10) : > INT_VECTOR_TABLE_SWL

/*********************************************************************************/
/* RAM Area */
/*********************************************************************************/

    .intc_vector                       ABS ALIGN(4) : > int_sram

/* generate symbols used in start-up code to init .intc_vector section */


RC_INTC_VECTOR_SRC = ADDR(.ROM.intc_vector);
RC_INTC_VECTOR_DEST = ADDR(.intc_vector);
RC_INTC_VECTOR_SIZE = (SIZEOF(.ROM.intc_vector)+3) /4; // Copy 4 bytes at a time

2) This is the code in startup file:

.set VTOR_REG, 0xE000ED08

/* relocate vector table to RAM */
ldr r0, =VTOR_REG
ldr r1, =VTABLE
/* ;ldr r2, =(1 << 29)
;orr r1, r2 *//* r1 = r1 | r2 */
str r1,[r0]

/****************/
/* .intc_vector */
/****************/
ldr r3, = RC_INTC_VECTOR_SIZE
ldr r2, = RC_INTC_VECTOR_SRC
ldr r4, = RC_INTC_VECTOR_DEST
CopyRamVector:
ldr r5, [r2]
str r5, [r4]
add r2, r2, #4
add r4, r4, #4
sub r3, r3, #1
cmp r3, #0
bgt CopyRamVector

B) [Daniel] don't know what drivers you are using so it is difficult to say

 

I am using the \Freescale\Standard Software Driver v1.0.4\C90TFS lib

Below is my code how to use the lib:

#ifdef VUC_SWL
__attribute__((section(".ramcode")))
#endif
Bool ROM_EraseBlock(UInt8 First_BlockNo, UInt8 Last_BlockNo)
{
      uint32_t ret = FTFx_ERR_RANGE;
      uint32_t First_addr;
      uint32_t Last_addr;
      uint32_t dest;
      uint32_t size;
      uint16_t number;
      uint32_t i;

      DisableAllInterrupts();

      /* In S32K144, we erase Sectors */
      First_addr = flashSSDConfig.PFlashBlockBase + (UInt32)First_BlockNo * FTFx_PSECTOR_SIZE;
      Last_addr = flashSSDConfig.PFlashBlockBase + (UInt32)(Last_BlockNo + 1) * FTFx_PSECTOR_SIZE;

      if ((First_addr < (flashSSDConfig.PFlashBlockBase + flashSSDConfig.PFlashBlockSize)) && (Last_addr <       (flashSSDConfig.PFlashBlockBase + flashSSDConfig.PFlashBlockSize)))
      {
         dest = First_addr;
         while ((dest + BYTE2WORD(FTFx_PSECTOR_SIZE)) <= Last_addr)
         {
            size = FTFx_PSECTOR_SIZE;
            ret = FlashEraseSector(&flashSSDConfig, dest, size, g_FlashLaunchCommand);
            if (FTFx_OK != ret)
            {
                  ErrorTrap(ret);
            }

            /* Verify section for several sector of PFLASH */
            number = FTFx_PSECTOR_SIZE / PRD1SEC_ALIGN_SIZE;
            for(i = 0x0U; i < 0x2U; i++)
            {
                  ret = FlashVerifySection(&flashSSDConfig, dest, number, i, g_FlashLaunchCommand);
                  if (FTFx_OK != ret)
                  {
                        ErrorTrap(ret);
                  }
            }
            dest += BYTE2WORD(size);
         }
      }

      EnableAllInterrupts();

      return (FTFx_OK == ret);
}

Actually, i do not know that whether i should move C90TFS lib to RAM or not? please advice me

C) [Daniel] But it triggers an exception so you can find out what exception it is and debug the code.

Fault handling on S32K144 

In my baseline, i am using the sample to catch up all exceptions,So now i do not see any exceptions to analyze. only see system reset.

0 Kudos
Reply

1,196 Views
danielmartynek
NXP TechSupport
NXP TechSupport

Hi,

Only the code that launches the flash commands must be in RAM. That is:

FTFC->FSTAT = FTFC_FSTAT_CCIF_MASK;               // launch command
while((FTFC->FSTAT & FTFC_FSTAT_CCIF_MASK) == 0); // wait in RAM until complete‍‍

Please check the .map file if all interrupt routines and the the flash function is in RAM.

What is the location of your vector table in RAM. Check S32_SCB[VTOR] in register view. 

Make sure the interrupt routines do not access any data in Flash.

Regards,

Daniel

0 Kudos
Reply