I need to save a small number of configurations on the s32k146. After reading in the manual and doing some online searches, I decided that the FlexRAM was located at address 0x14000000 and that it could be accessed simply by reading and writing to it. I thought this was working, but now I find that this isn't retaining its value across a power cycle.
I've read through the manual at length, but get lost in all the options. Can someone point me in the right direction to figure this out?
By a small amount of data, I mean about 40 bytes. Infrequently it will be written to, but will be read from a lot.
Solved! Go to Solution.
If you use FlexRAM as EEPROM, then you need to partition FlexNVM first, set the backup size of EEPROM, and then you still needs to set FlexRAM.
You can refer to AN11983 for these steps, I will put the link below
https://www.nxp.com/search?keyword=AN11983&start=0
Secondly, you can also refer to the SDK routines(flash_partitioning_s32k146). Quick write is not used here, but the process is the same.
and your code: I'm not quite sure what the meaning of your writing is, it shouldn't be correct.
if ((FTFC->FCNFG & (FTFC_FCNFG_RAMRDY_MASK + FTFC_FCNFG_EEERDY_MASK)) == FTFC_FCNFG_RAMRDY_MASK)
please take a look at the article below.
Thanks Senlent. That looks like it would just put some constant data into the program code where it couldn't be modified. I need to be able to modify it on occasions. I have been looking at implementing FlexRAM for quick writes, but I only get errors and can't tell what the error means. I executed this code:
if ((FTFC->FCNFG & (FTFC_FCNFG_RAMRDY_MASK + FTFC_FCNFG_EEERDY_MASK)) == FTFC_FCNFG_RAMRDY_MASK)
{
FTFC->FCCOB[0] = kSETRAMCommand;
FTFC->FCCOB[1] = kEmulateControlCode;
FTFC->FCCOB[4] = 0; //256 BYTES
FTFC->FCCOB[5] = 4;
FTFC->FSTAT |= FTFC_FSTAT_CCIF_MASK; //clear CCIF by writing 1 to it
while ((FTFC->FSTAT & FTFC_FSTAT_CCIF_MASK) == 0)
{}
}
When it completes, the FSTAT[ACCERR] bit is set which could have any of the following meanings:
Command not available in current mode/security
FlexRAM Function Control Code is not defined
FlexRAM Function Control Code is set to make the FlexRAM available for emulated
EEPROM, but FlexNVM is not partitioned for emulated EEPROM
Set if FlexRAM Function Control Code is set to 0xAA, 0x77 or 0x55 but FCNFG.[EEERDY] =0
(FlexRAM not in emulated EEPROM mode)
Set if FlexRAM is in EEPROM quick write mode, i.e. all EEPROM quick writes to the
FlexRAM have not been completed
Set if FlexRAM Function Control Code is set to make FlexRAM available for EEPROM quick
writes but the number of bytes allocated for quick write is less than 16, more than 512, or not
divisible by 4 (only 32-bit quick writes are allowed)
Set if emulated EEPROM system is in quick write mode and writes to the FlexRAM are not
32-bits
I've correct my code some, but it still doesn't work and the same error flag is set:
if ((FTFC->FCNFG & (FTFC_FCNFG_RAMRDY_MASK + FTFC_FCNFG_EEERDY_MASK)) == FTFC_FCNFG_RAMRDY_MASK)
{
FTFC->FCCOB[3] = 0x81;
FTFC->FCCOB[2] = 0x55;
FTFC->FCCOB[7] = 1; //256 BYTES
FTFC->FCCOB[6] = 0;
FTFC->FSTAT |= FTFC_FSTAT_CCIF_MASK; //clear CCIF by writing 1 to it
while ((FTFC->FSTAT & FTFC_FSTAT_CCIF_MASK) == 0)
{}
If you use FlexRAM as EEPROM, then you need to partition FlexNVM first, set the backup size of EEPROM, and then you still needs to set FlexRAM.
You can refer to AN11983 for these steps, I will put the link below
https://www.nxp.com/search?keyword=AN11983&start=0
Secondly, you can also refer to the SDK routines(flash_partitioning_s32k146). Quick write is not used here, but the process is the same.
and your code: I'm not quite sure what the meaning of your writing is, it shouldn't be correct.
if ((FTFC->FCNFG & (FTFC_FCNFG_RAMRDY_MASK + FTFC_FCNFG_EEERDY_MASK)) == FTFC_FCNFG_RAMRDY_MASK)
I found sample code, I assume it's that which you were referring to, for flash memory. Hopefully I'll have this figured out soon.
Thanks Senlent.
I found AN11983, but I haven't found any sample code dealing with the flash memory. Searching on flash_partitioning_s32k146 hasn't turned anything up. Do you have a link for this?
The if statement just checks the two bits RAMRDY and EEERDY to decide if the setup needs to be done. The RAMRDY flag is always set and that part of the code works.
Is there any part or mode of the flash memory that is enabled from the start? I don't really care, or even understand well enough the different options (in spite of hours of reading the manuals).
It appears that to enable quick writes, you first have to enable EEPROM and to enable that you have to do the partition command and to do that, I've seen that you have to erase the flash memory first (although I don't know why, since it should be empty.) Erasing the memory appears to cause problems because the code is running from flash memory and I don't know far this chain of problems is going to go. I've tried all the commands from partitioning the memory on, and they all return errors and don't work. I haven't tried erasing yet.