EXAMPLE: S32K144 EEEPROM usage - No SDK

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

EXAMPLE: S32K144 EEEPROM usage - No SDK

EXAMPLE: S32K144 EEEPROM usage - No SDK

This example shows how to use EEEPROM without SDK. The example is very similar to this one 

Example: S32K144 EEEPROM usage 

DFLASH partitioning is done by EEE_Init() function. If the MCU is already partitioned - please check Preserve partitioning for the device checkbox. 

- NOTE - there is bug in PE Micro script and this option causes pegdbserver crash. 

pastedImage_1.png

Target MCU: S32K144

Debugger: OpenSDA

Attachments
Comments

@Jiri Kral

Thaks for your updates,

I have another question,

Please, can you guide me how should I make sure,  Data which I have written to FLEXRAM, those data have been copied to  D-Flash bu background process?

Because after Write to FlexRAM once reset those data not available in RAM Location,

Ex:

EEE_Write_int32(123456,&eeerom_data.i1);

Reset

EEE_Read_init32(&eeprom_data);

Data this location FFFFFFFF

Plase can you guide me how can verify the written data?

Thanks,

Sakthivel k 

Hi, 

Sorry for confusion - I don't have much time for testing - I put logical instead binary & operator in EEE_Init(). The EEE_Init() was not working. In attachment is updated example. 

with the Example EEE_Init() function - data are loaded automatically into EEERAM mapped structure. By reset you mean pressing Reset button on EVB or Re-Flashing by PE Micro? With re-flashing without memory preservation is DFLASH area erased. 

Jiri

Thanks for your update,

By Reset means both the way,(EVB Reset Button and Reflashing by PE)

Note: I have done PE Configuration as mentioned in Example: S32K144 EEEPROM usage 

Please verify my Program sequence,

1.EEE_Write

2.EEE_Read (Verify)

3. Stop Debug 

4.Comment the EEE_Write Function

5.Run Debugger 

6.EEE_Read (Set Breakpoint) to verify be already written Data Available?

This sequence has an issue?

My project Requirement,

User Configuration via CAN  to EEPROM, Once Reset Happens My application should read the user parameter and store to local for my checking process.

Will above sequence work for my requirements? 

Thanks,

Sakthivel K

It should be okay. But be sure that there is no Emergency kinetis recovery enabled and there is preserved memory range from 0x10000000-0x1000FFFF. 

The EEE_Read function does what? Normally are data available without any special reading. Variables mapped into EEERAM area (0x14000000+) behaves like initialized variables. On startup there is last stored value. 

Jiri

Thanks for your response, Let me check the sequence soon today.

 

Is that this functin nessary to read the contane from the spectify memory?

int EEE_Read_int32(int* target)
{
uint32_t data;
while ((FTFC->FSTAT & FTFC_FSTAT_CCIF_MASK) == 0){}
data = *(uint32_t *)target;
return data;
}

Important  Note:: Is that possible to use the GENY Generation CAN Drive with S32k144 MCU.? As we are supporting OEMs so our application should include the GENY Generation CAN Drive and Diagnostic Drive to support the CAN Communication.

Is my question that possible to use GENY Drive with S32K144 MCU?

Thanks,

Sakthivel k

Um - it depends. If you have special section in linker file and you are using for example some structure like in EEE_RAM_usage example - the EEE_Read is not necessary. The current data are already in variable present. 

Have no experience with GENY Generation CAN drive. Technically - if it is generic C code which can fit into S32K144 resources - you can use it. You need to implement the interface between GENY driver and HW CAN bus layer - this is chip specific part. 

Jiri

Please check, Below sequence and configuration

1) PE Configuration

pastedImage_2.pngpastedImage_7.png

2) UART Output

pastedImage_1.png

3) Firmware.

pastedImage_6.png

Main()

pastedImage_3.png

pastedImage_5.png

Init_EEPROM()

pastedImage_4.png

Problem:

When Write-Read Sequence OK

When only Read Sequence -NOK

Please, can your tell me anything I'm Missed out?

As I mentioned - there is bug in the Init_EEPROM (current example version is fixed). Please use binary & instead logical one:

if ((FTFC->FCNFG & FTFC_FCNFG_EEERDY_MASK) == 0U)

Emergency kinetis device recovery overrides Memory preservation - So don't use it. Also don't use Partitioning - it will be done by Init_EEPROM. 

For me is settings from example working okay. Debug settings:

pastedImage_1.png

Newly started debug session - one step after WDOG_Disable() (just after last one when partitioning was performed):

pastedImage_2.png

You can also check data

pastedImage_3.png

Hope it helps. 

Jiri

sorry to ask again,

Please help me,

One stop In Debugger,(No partition, NO RAM Data Update) 

Note: Unchecked: Emergency kinetis device recovery(not used) , does not use a partition in PE configuration 

pastedImage_1.png

Once EEE_Write Function executed then update the RAM Location

pastedImage_2.png

I have used same as attached Example EEE_Init();

@starup I'm not getting updates the RAM structure location 

Thanks,

Sakthivel K

Please check if the FTFC->FCNFG->EEERDY bit is set to 1 before you run EEE_Write. It looks like that in your config is EEERAM area used as standard RAM. 

Jiri 

Thanks for your Info,

Now I can able to get back the Written data in FlexRAM, But I have another problem is that Re-Flashing  will erase the Written Data,

what should I do for overcoming this issue?

Should I modify the linker file?  which part of the linker file has to change?

Sakthivel K

Hi, 

If you have preserved DFLASH memory (full DFLASH is from 0x10000000-0x1000FFFF) - PE Micro doesn't rewrite your stored data.

pastedImage_1.png

Also be sure that there is unchecked Emergency kinetis device recovery and you didn't perform partitioning via PE Micro. 

Jiri

Yes below my setting,

The sequence is that,

►Write FlexRAM (14000000)

►Reset 

►verify the structure variable mapped to EEPROM.(14000000) -OK

►Modfity the Application Build and Flash by OPENSDA on EVB Board.

►Reset

►Verify the structure variable mapped to EEPROM(14000000) data will be erased. -NOK

I have preserved the D-Flash Range, why data has been overwritten?

My Requirement is that

if the user configured the data only once should not be erased by updating the Program(Re-flash).This just program update not the configuration data update.

pastedImage_1.png

Hi, 

well - that's exactly for what memory preservation is used - and is working okay. There must be different issue with your project. The fundamental is - EEERAM partitioned as emulated EEPROM (FTFC->FCNFG->EEERDY = 1 ), and memory preservation. The example at very top is working for you? If it is possible - can you please share your project with me? I'll look at it. 

Jiri

I have shared my project @" jiri.kral@nxp.com" <admin@community.nxp.com>, because I can't find the attachment in the comment loop. 

Please have a look and let me know your comments.

Thanks,

Sakthivel K

Hi, 

I didn't receive the project yet. Please send it again - or you can create new community thread related to your memory preservation issue. 

Jiri 

Hi,

Please find the project from this  Drive Link,

https://drive.google.com/open?id=1y6wSOSQxKFGRDP5BbzGReuhgXhI0t98n

Please let me know any setting Problems or EEE_Init Problems.

Thanks,

Sakthivel K

Hi, 

finally - I can reproduce the issue - thank you for keep going this thread. I didn't realize that in my case there was not change in the code. So - when there is code change, the DFLASH is preserved, but the emulated EEPROM partition is removed -> stored data are gone. I tried use partition with PE Micro, but for some reason pegdbserver always crashes. I'll try to findout some workaround. 

Jiri 

The preserve partitioning should do the trick - but it failed because of PE Micro bug:

pastedImage_1.png

I'm going to create bug ticket for PE Micro. 

Jiri 

How can i select this option "preserve partitioning of the device" if i am flashing my .elf file on to s32k144 board using command line ?

Hello, I need to write the data received by the UART into the EEPROM. I don't understand how to write the instructions. Can you help me? Thank you.

/*
* main implementation: use this 'C' sample to create your own application
*
*/


#include "S32K144.h" /* include peripheral declarations S32K144 */
#include "EEEPROM_io_control.h"

#define USER_DATA_SIZE 32u
#define DISABLE_INTERRUPTS() __asm volatile ("cpsid i" : : : "memory");
#include "s32_core_cm4.h"
void SOSC_init_8MHz(void)
{
SCG->SOSCDIV=0x00000101; //SOSCDIV1 & SOSCDIV2 =1: 分频/1
SCG->SOSCCFG=0x00000024; //Range=2: 选择晶体振荡器的中频范围 (SOSC 1MHz-8MHz)
// HGO=0: 控制晶体振荡器的工作功率模式 --低功率模式
// EREFS=1: 外部参考选择OSC内部晶体振荡器
while(SCG->SOSCCSR & SCG_SOSCCSR_LK_MASK); //等待SOSCCSR解锁 寄存器解锁后才可写入
SCG->SOSCCSR=0x00000001; // LK=0: SOSCCSR可以写
// SOSCCM=0: 系统OSC时钟监视器被禁用
// SOSCEN=1: 启用系统OSC
while(!(SCG->SOSCCSR & SCG_SOSCCSR_SOSCVLD_MASK)); //等待系统OSC成功启用,输出时钟有效
}


void SPLL_init_160MHz(void)
{
while(SCG->SPLLCSR & SCG_SPLLCSR_LK_MASK); //等待SPLLCSR寄存器解锁 寄存器解锁后才可写入
SCG->SPLLCSR = 0x00000000; // LK=0: SPLLCSR可以写入
// SPLLEN=0: SPLL禁用
SCG->SPLLDIV = 0x00000302; // SPLLDIV1 分频/2; SPLLDIV2 分频/4
SCG->SPLLCFG = 0x00180000; // PREDIV=0: 锁相环参考时钟分频因子
// MULT=24: SPLL时钟频率的乘法因子
// SPLL_CLK = 8MHz / 1 * 40 / 2 = 160 MHz SPLL_CLK = (VCO_CLK)/2 VCO_CLK = SPLL_SOURCE/(PREDIV+1)*(MULT+16)
while(SCG->SPLLCSR & SCG_SPLLCSR_LK_MASK); //等待SPLLCSR寄存器解锁 寄存器解锁后才可写入
SCG->SPLLCSR = 0x00000001; // LK=0: SPLLCSR可以写入
// SPLLCM=0: SPLL时钟监视器被禁用
// SPLLEN=1: 开启SPLL
while(!(SCG->SPLLCSR & SCG_SPLLCSR_SPLLVLD_MASK)); //等待SPLL成功启用,输出时钟有效
}

void NormalRUNmode_40MHz (void)
{
SCG->RCCR=SCG_RCCR_SCS(6) // SPLL做为系统时钟源
|SCG_RCCR_DIVCORE(0b11) // DIVCORE=3, 分频/4: Core clock = 160/4 MHz = 40 MHz
|SCG_RCCR_DIVBUS(0b11) // DIVBUS=3, 分频/4: bus clock = 160/4 MHz = 40 MHz
|SCG_RCCR_DIVSLOW(0b111); // DIVSLOW=7, 分频/8: SCG slow, flash clock= 160/8 MHz = 20MHZ
while (((SCG->CSR & SCG_CSR_SCS_MASK) >> SCG_CSR_SCS_SHIFT ) != 6) {}//等待系统时钟源成功选择SPLL
}
void UART2_NVIC_init_IRQs(void)
{
S32_NVIC->ICPR[1] = 1 << (35 % 32); /* IRQ48-UART2: clr any pending IRQ*/
S32_NVIC->ISER[(uint32_t)(LPUART2_RxTx_IRQn) >> 5U] = (uint32_t)(1UL << ((uint32_t)(LPUART2_RxTx_IRQn) & (uint32_t)0x1FU));
S32_NVIC->IP[35] = 0x7; /* IRQ48-UART2: priority 7 of 0-15*/
}
void UART2_PORT_init (void)
{
PCC->PCCn[PCC_PORTA_INDEX ] |= PCC_PCCn_CGC_MASK; //使能PTA端口时钟
PORTA->PCR[8] |= PORT_PCR_MUX(2); // Port A8: MUX = ALT2,UART2 RX PTA8复用为RX
PORTA->PCR[9] |= PORT_PCR_MUX(2); // Port A9: MUX = ALT2,UART2 TX PTA9复用为TX
}
//波特率: 9600 , 1停止位, 8个数据位, 无奇偶校验
void UART2_init(void)
{
PCC->PCCn[PCC_LPUART2_INDEX] &= ~PCC_PCCn_CGC_MASK; //禁LPUART2时钟
PCC->PCCn[PCC_LPUART2_INDEX] |= PCC_PCCn_PCS(0b001) //选择时钟 Clock Src= 1 (SOSCDIV2_CLK)
| PCC_PCCn_CGC_MASK; //使能LPUART2时钟

LPUART2->BAUD = 0x0F000034; //配置波特率为9600,1停止位
// SBR=52 (0x34): 波特率模数除数 = 8M/9600/16 = ~52
// OSR=15: 采样率 = 15+1=16
// SBNS=0: 1个停止位
// BOTHEDGE=0: 接收端使用波特率时钟上升沿采样输入数据
// M10=0: 接收机和发射机使用7位到9位的数据字符
// RESYNCDIS=0: 支持在接收数据字期间重新同步
// LBKDIE, RXEDGIE=0: 禁用LIN中断,RX收入边缘中断

LPUART2->CTRL=0x000C0000 | (1<<21);
// RE=1,TE=1: 使能接收及发送
// PE=0: 无奇偶校验
// M7,M,R8T9,R9T8=0: 8个数据位
// DOZEEN=0: 睡眠模式下LPUART正常启用
// ORIE,NEIE,FEIE,PEIE,TIE,TCIE,ILIE,MA1IE,MA2IE=0,RIE=1: 接收中断
// TXINV=0: 传输数据不是反向的
// IDLCFG=0: 1个空闲字符
// ILT=0: 空闲字符位计数在开始位之后开始
}
/*********************************************************************
* 函数原型:void UART2_transmit_char(char send)
* 功 能:UART2发送一个BYTE的数据
* 输入参数:send--需要发送的字符数据
* 返回参数:无
*
* 其他说明:
*********************************************************************/
void UART2_transmit_char(char send)
{ /* Function to Transmit single Char */
while((LPUART2->STAT & LPUART_STAT_TDRE_MASK)>>LPUART_STAT_TDRE_SHIFT==0);
/* Wait for transmit buffer to be empty */
LPUART2->DATA=send; /* Send data */
}

void UART2_transmit_string(char data_string[],int len)
{
uint32_t i=0;
for(i=0;i<len;i++)
{
UART2_transmit_char(data_string[i]);
}
UART2_transmit_char('\n'); /* New line */
UART2_transmit_char('\r'); /* Return */
}

void _printf(char data_string[])
{
UART2_transmit_string(data_string,strlen(data_string));

UART2_transmit_char('\n'); /* New line */
UART2_transmit_char('\r'); /* Return */
}
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;

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_40MHz();/* Init clocks: 80 MHz sysclk & core, 40 MHz bus, 20 MHz flash */

//DISABLE_INTERRUPTS();

UART2_init(); //配置UART2 波特率9600 1个停止数 无校验位
UART2_NVIC_init_IRQs(); //配置中断优先级
UART2_PORT_init (); //配置GPIO复用为TX、RX

//_printf("just do it!");

EEE_Init();

//EEE_Write_int32(123456,&eeerom_data.i1);
//EEE_Write_ByteArray(char* source,char* target,unsigned int size)
//EEE_Write_Byte(rev,&eeerom_data.ch);
while(1)
{

}


/* to avoid the warning message for GHS and IAR: statement is unreachable*/
//#if defined (__ghs__)
//#pragma ghs nowarning 111
//#endif
//#if defined (__ICCARM__)
//#pragma diag_suppress=Pe111
//#endif
return 0;
}

void LPUART2_RxTx_IRQHandler(void)
{
char rev;
if (LPUART2->STAT & 0x00200000)
{
rev = LPUART2->DATA;
//EEE_Write_int32(123456,&eeerom_data.i1);
//EEE_Write_Byte(rev,&eeerom_data.ch);
//UART2_transmit_char(eeerom_data.i1);
if((LPUART2->STAT & LPUART_STAT_TDRE_MASK)>>LPUART_STAT_TDRE_SHIFT!=0) //判断发射是否空闲
{
LPUART2->DATA = rev;
}
}

}

jiri.kral@nxp.com‌,

I am quite confused about EEE_int() function in this example (S32K144 EEPROM usage - No SDK)

As my understand (based on AN11983 document : using the S32K1xx EEPROM Funtionality) :

After flexNVM is DEPARTitioned to emulated EEPROM (4KB flexRAM)  [ 3.1.1 S32K1xx program partition comman] : 

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

We need setting FlexRAM used as RAM [ 3.2.1.1 FlexRAM used as RAM ] :

FTFC->FCCOB[3]=0x81; // Progran command

FTFC->FCCOB[2]=0x00; // FlexRAM used asEEEPROM 

To use FlexRAM as emulated EEPROM (can write/read data in FlexRAM and this data then will be recorded)

But in your example, Setting FlexRAM used as RAM was commented out (so, data still is written normally).

Could you tell me why is that ? Thank you first.

Hi, 

sorry for delay. Well - there is nothing special about this commented code - I just forgot to clean it (it remains there from some testing stuff). It is a while when I did this example, but if I remember it correctly - by default is FlexRAM enabled just as normal RAM without Flash Backup. If you set it as Emulated EEPROM - FTFC->FSTAT->RAMRDY is set to 0:

pastedImage_1.png

Do you have some issue with this example? I tested it right now - and it works as expected. 

Jiri

Hi Jiri!

Is this "preserve partitioning PE Micro" bug solved yet?

Or is there any other working solution?

Just installed S32DS 2.2, and fully updated (also all PE Micro up to date) but no luck! (Same on S32DS-18)

Same problem on 2 computers Win7 64bit...

Tested with both OpenSDA and Multilink Universal.

I'm using the other SDK EEPROM example. (Referred in top post)

Everything seems to work, except when you use "preserve memory range", the pegdbserver always crashes, and can not load/flash the target successfully.

With OpenSDA:

Connection from "127.0.0.1" via 127.0.0.1. Connection from port "57803" to 6224
Connection from "127.0.0.1" via 127.0.0.1. Connection from port "57804" to 7224
Searching for FreeRTOS Kernel Symbols...
rsp_qC - qSymbol: 707843757272656E74544342
pxCurrentTCB not found. FreeRTOS analysis not enabled.
Copyright 2018 P&E Microcomputer Systems,Inc.
Command Line :C:\NXP\S32DS_ARM_v2.2\eclipse\plugins\com.pemicro.debug.gdbjtag.pne.expansion_4.5.3.202002032127\win32\pegdbserver_console -device=NXP_S32K1xx_S32K144F512M15 -startserver -singlesession -serverport=7224 -gdbmiport=6224 -interface=OPENSDA -sL
OpenSDA detected - Flash Version 1.19

CMD>RE

Initializing.
Target has been RESET and is active.
CMD>CM C:\NXP\S32DS_ARM_v2.2\eclipse\plugins\com.pemicro.debug.gdbjtag.pne.expansion_4.5.3.202002032127\win32\gdi\P&E\supportFiles_ARM\NXP\S32K1xx\freescale_s32k144f512m15_pflash_dflash_eeprom.arp

Initializing.
Initialized.

;version 1.05, 12/03/2019, Copyright 2019 P&E Microcomputer Systems, Inc. All rights reserved. www.pemicro.com [s32k144f512m15_x_pflash_dflash_eeprom_rev2]

;device freescale, s32k144f512m15, pflash_dflash_eeprom

;begin_cs device=$00000000, length=$14001000, ram=$20000000

Loading programming algorithm ...
Done.
CMD>PA 0204

Started.
Done.
Programming sequency is : erase, blank check, program, and verify {default}
CMD>VC
Verifying object file CRC-16 to device ranges ...
block 00000000-000019EF ...
Calculated CRC-16 does not match block. (File = $186D, Device = $9EBD)
Current content of flash does not match application to be programmed

CMD>EM // Get stuck here for ~50s.
Preserving data range $10000000-$1000FFFF before erase ...
Done.

Erasing.
Module has been erased.
Reloading programming algorithm ...
done.
Re-programming preserved data range $10000000-$1000FFFF ...
Done.
Error communicating to target processor - try a RESET.

CMD>PM

Programming.
Processing Object File Data ...


.
Programmed.
Error communicating to target processor - try a RESET.

CMD>VC
Error loading CRC-16 algorithm.

Error loading CRC-16 algorithm.
Error loading CRC-16 Algorithm.
Error verifying flash of device
Error occured during Flash programming.

PEmicro GDB Launch Failure : Error during flash programming. Terminating debug session.

pegdbserver crashes...

With Multilink Universal:

Connection from "127.0.0.1" via 127.0.0.1. Connection from port "57868" to 6224
Connection from "127.0.0.1" via 127.0.0.1. Connection from port "57869" to 7224
Searching for FreeRTOS Kernel Symbols...
rsp_qC - qSymbol: 707843757272656E74544342
pxCurrentTCB not found. FreeRTOS analysis not enabled.
Copyright 2018 P&E Microcomputer Systems,Inc.
Command Line :C:\NXP\S32DS_ARM_v2.2\eclipse\plugins\com.pemicro.debug.gdbjtag.pne.expansion_4.5.3.202002032127\win32\pegdbserver_console -device=NXP_S32K1xx_S32K144F512M15 -startserver -singlesession -serverport=7224 -gdbmiport=6224 -interface=USBMULTILIL
P&E Interface detected - Flash Version 10.42

CMD>RE

Initializing.
Target has been RESET and is active.
CMD>CM C:\NXP\S32DS_ARM_v2.2\eclipse\plugins\com.pemicro.debug.gdbjtag.pne.expansion_4.5.3.202002032127\win32\gdi\P&E\supportFiles_ARM\NXP\S32K1xx\freescale_s32k144f512m15_pflash_dflash_eeprom.arp

Initializing.
Initialized.

;version 1.05, 12/03/2019, Copyright 2019 P&E Microcomputer Systems, Inc. All rights reserved. www.pemicro.com [s32k144f512m15_x_pflash_dflash_eeprom_rev2]

;device freescale, s32k144f512m15, pflash_dflash_eeprom

;begin_cs device=$00000000, length=$14001000, ram=$20000000

Loading programming algorithm ...
Done.
CMD>PA 0204

Started.
Done.
Programming sequency is : erase, blank check, program, and verify {default}
CMD>VC
Verifying object file CRC-16 to device ranges ...
block 00000000-000019EF ...
Calculated CRC-16 does not match block. (File = $186D, Device = $9EBD)
Current content of flash does not match application to be programmed

CMD>EM // Get stuck here for ~25s.
Preserving data range $10000000-$1000FFFF before erase ...
Done.

Erasing.
Module has been erased.
Reloading programming algorithm ...
done.
Re-programming preserved data range $10000000-$1000FFFF ... // Get stuck here for ~5s.

Error! Last command failed.
Error Erasing flash of device
Error occured during Flash programming.

PEmicro GDB Launch Failure : Error during flash programming. Terminating debug session.

pegdbserver crashes...

Hi Jiri,

I'm going through this thread and finally understood there is a bug in PE Micro & you have raised a ticket for the same.

I would like to know the expected time to resolve this issue. Kindly share the same.

Raju

Hi, 

unfortunately PE Micro won't fix it. Here you can find more details: 
https://community.nxp.com/message/1269942 

Jiri

No ratings
Version history
Last update:
‎05-11-2018 03:30 AM
Updated by: