S32k148 Flash erase and writing

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

S32k148 Flash erase and writing

2,558 Views
Kallappa
Contributor III

Hello,


I am working on the s32k148 and in my use case, I want to erase and write the data into the flash which is received via CAN by using UDS 36 service.
So is there any useful example so I can refer to that and start the implementation or any resource that can I refer to please let me know.
I am new in the flash erase and writing on NXP S32k148.
So help from NXP Community it will really helpful.

Thanks in Advance,


0 Kudos
8 Replies

2,539 Views
danielmartynek
NXP TechSupport
NXP TechSupport
0 Kudos

2,522 Views
Kallappa
Contributor III
Thanks Danial for the response,

I am able to establish the CAN and UDS on the S32k148 board and tested and its working,

But i am stuck at flash erasing
i am using the driver function called

*FUNCTION**********************************************************************
*
* Function Name : FLASH_DRV_EraseBlock
* Description : Erases all addresses in an individual P-Flash or D-Flash block.
* For the derivatives including multiply logical P-Flash or D-Flash blocks,
* this API erases a single block in a single call.
*
* Implements : FLASH_DRV_EraseBlock_Activity
*END**************************************************************************/
status_t FLASH_DRV_EraseBlock(const flash_ssd_config_t * pSSDConfig,
uint32_t dest)
 
here i am passing parameters as
pSSDConfig = {
.PFlashBase = 0x00000000U,
.PFlashSize = 0x00100000U,
.DFlashBase = 0x10000000U,
.EERAMBase = 0x14000000U,
/* If using callback, any code reachable from this function must not be placed in a Flash block targeted for a program/erase operation.*/
.CallBack = NULL_CALLBACK
};
and 
dest = 0x00080000
 
to erase second 512KB of PFlash from address 0x00080000
But after using this the complete memory is erasing (whole 1.5MB).

So if you helped me to erase the particular block of the S32k148's Pflash then it will really helpful.

Thanks in advance

2,483 Views
danielmartynek
NXP TechSupport
NXP TechSupport

Hello,

The PFlashSize should be 0x00180000, but this is not the issue here.

Can you place a breakpoint at

/* Calling flash command sequence function to execute the command */
ret = FLASH_DRV_CommandSequence(pSSDConfig);

and read the FCCOBx registers?


Regards,

Daniel

0 Kudos

2,476 Views
Kallappa
Contributor III

Memory_00000_Btldr.PNG

Memory_80000_Appl.PNG

Before_FTFC_COMMAND.PNG

   Hi Danial,
Thanks for your support,
As you suggested to check the register values PFA images for more details on the registers data.

is anything I missing?

Regards,
Kallappa


0 Kudos

2,430 Views
danielmartynek
NXP TechSupport
NXP TechSupport

Hi Kallappa,

Can you halt the execution right after the CCIF flag is set in the FLASH_DRV_CommandSequence(pSSDConfig) function.

danielmartynek_1-1614953472778.png

These are the error conditions that could be causing it:

danielmartynek_0-1614953406248.png

Thank you

BR, Daniel

0 Kudos

2,398 Views
Kallappa
Contributor III
Spoiler
 

Hi Daniel,
we are able to erase PFLASH memory from address 0x00080000 and able to protect the memory from address 0x00000000 to 0x0007FFFF to achive this what we have did is mentioned below points.

Project Scenario
We have Bootloader and application and We kept Bootloader at address 0x00000000 to 0x0007FFFF block and remaining 1MB PFLASH from 0x00080000
is used for Application

We are able to delete the PFLASH from 0x00080000 for that we used Function called FLASH_DRV_EraseBlock.

and while Flashing Bootloader it is erasing Application and Vice-Versa for that we used memory protection mechanism as shown below picture.

BootLoader_Preserv.png

Application_Preserv.png


So Please let us know whether we are doing correct or not?

Can we do the same thing via program/code itself?

Thanks for support

0 Kudos

2,365 Views
danielmartynek
NXP TechSupport
NXP TechSupport

Hi @Kallappa 

Thank you for the updates.

So, I understand the issue with the block erasing has been solved.

The advance option of the PE Micro plugin tells the programmer to not erase and reprogram certain part of the memory, but the bootloader or the application can modify the flash protected there.

You can however protect the flash part you want in the flash configuration field:

danielmartynek_0-1615294068169.png

danielmartynek_1-1615294100891.png

The flash is then protected out of reset.

During the system reset sequence, the content of the FPROTn bytes is moved to the FPROTn registers.

 

Regards,

Daniel

 

 

 

0 Kudos

2,400 Views
Kallappa
Contributor III

Hello Daniel,

As your suggestion, I halted the execution to check CCIF flag after set [Please refere below image], 

CCIF_FLAG_State.png

/* Check if an error is occurred */
if ((FTFx_FSTAT & (FTFx_FSTAT_MGSTAT0_MASK | FTFx_FSTAT_FPVIOL_MASK | FTFx_FSTAT_ACCERR_MASK | FTFx_FSTAT_RDCOLERR_MASK)) != 0U)
{
ret = STATUS_ERROR;
}

and 

we checked the errors at the above point of statement execution & didn't get any error

Thanks



0 Kudos