Hi,
For my application, I need to read and write certain data from the s32k144 EEEPROM. I'm using EEEPROM code without SDK.
Configuration on debugger advanced option.
I just manually modified these lines in the S32K144_64_flash.ld file.
I'm just trying to write to EEEPROM using the code below.
/*
* main implementation: use this 'C' sample to create your own application
*
*/
#include "S32K144.h" /* include peripheral declarations S32K144 */
//#include "EEEPROM_io_control.h"
#include "clocks_and_modes.h"
#define USER_DATA_SIZE 32u
#define EEE_SUCCESS 0
#define EEE_ALREADY_ENABLED -1
#define DISABLE_INTERRUPTS() __asm volatile ("cpsid i" : : : "memory");
#define ENABLE_INTERRUPTS() __asm volatile ("cpsie i" : : : "memory");
typedef struct
{
float p1;
float p2;
float p3;
float p4;
char ch;
double d1;
double d2;
unsigned long runtime_sec;
int i1;
char user_data[USER_DATA_SIZE];
} eeerom_data_t;
__attribute__ ((section(".eeeprom"))) eeerom_data_t eeerom_data;
int EEE_Init()
{
if ((FTFC->FCNFG & FTFC_FCNFG_EEERDY_MASK) == 0U)
{
volatile int timeout;
FTFC->FCCOB[3]=0x80; // Program Partition command
FTFC->FCCOB[2]=0x00; // CSEc key size
FTFC->FCCOB[1]=0x00; // Security flag extension - User Key verify only disabled
FTFC->FCCOB[0]=0x00; // Load data int EEERAM in reset sequence
FTFC->FCCOB[7]=0x02; // EEPROM data set size code - 4k
FTFC->FCCOB[6]=0x08; // EEPROM backup size - 64k
FTFC->FSTAT |= FTFC_FSTAT_CCIF_MASK;
while ((FTFC->FSTAT & FTFC_FSTAT_CCIF_MASK) == 0U)
{
timeout++;
}
/*FTFC->FCCOB[3]=0x81; // Progran command
FTFC->FCCOB[2]=0x00; // FlexRAM used as EEEPROM
FTFC->FSTAT |= FTFC_FSTAT_CCIF_MASK;
while ((FTFC->FSTAT & FTFC_FSTAT_CCIF_MASK) == 0U);
{
timeout++;
}*/
}
else
return EEE_ALREADY_ENABLED;
return EEE_SUCCESS;
}
int EEE_Write_int32(int data, int* target)
{
while ((FTFC->FSTAT & FTFC_FSTAT_CCIF_MASK) == 0){}
*target=data;
return 0;
}
void WDOG_disable (void){
WDOG->CNT=0xD928C520; /*Unlock watchdog*/
WDOG->TOVAL=0x0000FFFF; /*Maximum timeout value*/
WDOG->CS = 0x00002100; /*Disable watchdog*/
}
int main(void)
{
WDOG_disable();
SOSC_init_8MHz(); /* Initialize system oscilator for 8 MHz xtal */
SPLL_init_160MHz(); /* Initialize SPLL to 160 MHz with 8 MHz SOSC */
NormalRUNmode_80MHz(); /* Init clocks: 80 MHz sysclk & core, 40 MHz bus, 20 MHz flash */
EEE_Init();
DISABLE_INTERRUPTS();
EEE_Write_int32(123456,&eeerom_data.i1);
ENABLE_INTERRUPTS();
while(1){}
return 0;
}
Assist me in implementing a solution to write data into the EEEPROM and provide a function for retrieving data from it.
Thank you in advance.
Hi @Yuvashree,
The MCU should be partitioned only once in the lifetime of the device.
It can be done using the PE Micro debugger as you showed.
Please check the SIM_FCFG1[DEPART] register to confirm the partitioning.
If you decide to do it in the code, first read the DEPART register, and lauch the command only if the NVM has not been partitioned yet.
Also, the command must be launched from SRAM.
Regards,
Daniel