MPC5646C

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

MPC5646C

4,984 次查看
mikibart
Contributor II


Hi,

 

Does anyone know what steps needs to be taken to execute a function from RAM for MPC5646C micro ?

Or.. points to a document that explains how to do it.

 

I would really appreciate any help.

 

Thanks

标签 (1)
0 项奖励
回复
9 回复数

3,228 次查看
jatinarora
Contributor I

Hello Lukas,

Thanx for reply, I have figured out the issue.

Now I am trying to save some data (acquired from sensors) in DFLASH using the following program. (the  main calls the program void writesamplestoflash (void) at regular intervals)

I am successful at saving same data to the memory but I am facing a small problem.

When I see the memory (dflash) through memory window in debugger, some locations appear as XX and also I am not able to read the data at these locations.

I have also attached an image of memory window from debugger.

Can you tell me the reason for this. Also tell me if I can save data in some better way.

*initially I kept a as 0x0080C000 ( the starting address of block B0F3)

void writesamplestoflash (void)

{

DFLASH.MCR.B.PGM = 1;

*(unsigned int *)(a) = ADC_data[0]; // interlock write 

*(unsigned int *)(a+4) =ADC_data[1] ;

DFLASH.MCR.B.EHV = 1;

while(DFLASH.MCR.B.DONE != 1){}

DFLASH.MCR.B.EHV = 0;

DFLASH.MCR.B.PGM = 0;

DFLASH.MCR.B.PGM = 1;

*(unsigned int *)(a+8) = period;

DFLASH.MCR.B.EHV = 1;

while(DFLASH.MCR.B.DONE != 1){}

DFLASH.MCR.B.EHV = 0;

*(unsigned int *)(a+12) = period_measured;

DFLASH.MCR.B.EHV = 1;

while(DFLASH.MCR.B.DONE != 1){}

DFLASH.MCR.B.EHV = 0;

DFLASH.MCR.B.PGM = 0;

a=a+16;

}

memory window.jpg

0 项奖励
回复

3,228 次查看
lukaszadrapa
NXP TechSupport
NXP TechSupport

Hi,

"XX" in PEmicro debugger means that there are bus errors - in this case ECC errors.

Copied from reference manual:

"ECC is handled on a 64-bit boundary. Thus, if only one word in any given 64-bit ECC segment is

programmed, the adjoining word (in that segment) should not be programmed since ECC calculation has

already completed for that 64-bit segment. Attempts to program the adjoining word will probably result in

an operation failure. It is recommended that all programming operations be of 64 bits. The programming

operation should completely fill selected ECC segments within the Double Word.

Programming changes the value stored in an array bit from logic 1 to logic 0 only. Programming cannot

change a stored logic 0 to a logic 1."

So, if you want to change any double word that is already programmed, it is necessary to erase whole block.

Best Regards,

Lukas

0 项奖励
回复

3,228 次查看
jatinarora
Contributor I

Hello,

I am trying to put some data in the data flash of my uC and I tried the above program. After this program I wrote the following lines and checked values of a1-8.

But, the value of all a1-8 comes 0xFF. Is there any other way to read the DFLASH.

a1=*(unsigned int *)(0x00010000);

a2=*(unsigned int *)(0x00010001);

a3=*(unsigned int *)(0x00010002);

a4=*(unsigned int *)(0x00010003);

a5=*(unsigned int *)(0x00010004);

a6=*(unsigned int *)(0x00010005);

a7=*(unsigned int *)(0x00010006);

a8=*(unsigned int *)(0x00010007);

Thanks in advance.

0 项奖励
回复

3,228 次查看
jatinarora
Contributor I

I also checked the address through memory window, it shows 0xFF.

This is my complete program

#include "MPC5604B_M27V.h"

void initPeriClkGen(void) {

  CGM.SC_DC[0].R = 0x80;

  CGM.SC_DC[2].R = 0x80;       

  }

void initModesAndClock(void) {

  ME.MER.R = 0x0000001D;         

  CGM.FMPLL_CR.R = 0x02400100;   

  ME.RUN[0].R = 0x001F0074;      

  ME.RUNPC[1].R = 0x00000010;

  ME.PCTL[68].R = 0x01;   

    ME.MCTL.R = 0x40005AF0;       

  ME.MCTL.R = 0x4000A50F;          

  while (ME.GS.B.S_MTRANS) {}   

  while(ME.GS.B.S_CURRENTMODE != 4) {}

}

void disableWatchdog(void) {

  SWT.SR.R = 0x0000c520;   

  SWT.SR.R = 0x0000d928;

  SWT.CR.R = 0x8000010A;   

}

int main(void) {

  volatile int i = 0;

  uint8_t a1;

  uint8_t a2;

  uint8_t a3;

  uint8_t a4;

  uint8_t a5;

  uint8_t a6;

  uint8_t a7;

  uint8_t a8;

  initPeriClkGen();

  initPeriClkGen();

  disableWatchdog();

DFLASH.LML.R = 0xA1A11111; // write password

DFLASH.LML.R = 0x00100000; // unlock low and mid blocks primary

DFLASH.SLL.R = 0xC3C33333; // write password

DFLASH.SLL.R = 0x00100000; // unlock low and mid blocks secondary

DFLASH.HBL.R = 0xB2B22222; // write password

DFLASH.HBL.R = 0x00000000; // unlock high blocks

// erase block B0F3 (0x00010000 - 0x00017FFF)

DFLASH.MCR.B.ERS = 1;

DFLASH.LMS.R = 0x00000008; /* select B0F3 */

*(unsigned int *)0x00010000 = 0xFFFFFFFF; /* interlock write - write to any address in selected memory */

DFLASH.MCR.B.EHV = 1;

while(DFLASH.MCR.B.DONE != 1){}

DFLASH.MCR.B.EHV = 0;

DFLASH.MCR.B.ERS = 0;

/* program double word to B0F3 */

DFLASH.MCR.B.PGM = 1;

*(unsigned int *)0x00010000 = 0xAABBCCDD; /* interlock write */

*(unsigned int *)0x00010004 = 0x11223344; /* program data write */

DFLASH.MCR.B.EHV = 1;

while(DFLASH.MCR.B.DONE != 1){}

if(DFLASH.MCR.B.PEG==1) // check if PEG in MCR is 1

{

i=1;

//switch ON Led

}

DFLASH.MCR.B.EHV = 0;

DFLASH.MCR.B.PGM = 0;

a1=*(unsigned int *)(0x00010000);

a2=*(unsigned int *)(0x00010001);

a3=*(unsigned int *)(0x00010002);

a4=*(unsigned int *)(0x00010003);

a5=*(unsigned int *)(0x00010004);

a6=*(unsigned int *)(0x00010005);

a7=*(unsigned int *)(0x00010006);

a8=*(unsigned int *)(0x00010007);

while(1) {}

}

0 项奖励
回复

3,228 次查看
lukaszadrapa
NXP TechSupport
NXP TechSupport

Hi,

two things:

1. There are two flash blocks on MPC5604B. CFLASH and DFLASH. Address range of CFLASH is 0x0000_0000 - 0x0007_FFFF, address range of DFLASH is 0x0080_0000 - 0x0080_3FFF. These flash blocks are independent and both have own set of registers.

I can see that you are trying to program the addresses around 0x0001_0000 which belongs to CFLASH but you are using DFLASH registers. This will not work, of course, you have to use CFLASH registers.

2. Notice that Read-While-Write is supported only between banks. So, it is not possible to access the CFLASH while it is being erased/programmed. It is necessary to execute the code from RAM or from DFLASH.

Regards,

Lukas

0 项奖励
回复

3,228 次查看
lukaszadrapa
NXP TechSupport
NXP TechSupport

Hi,

attached you will find sample code. See main.c and linker file. It was written for MPC5607B but the principle is the same for all MPC5xxx.

Lukas

0 项奖励
回复

3,228 次查看
mikibart
Contributor II

Hello Lukas,

I thank you for your quick response.

I think you could help with some other issues too.

Here is the thing. I am trying to run two functions in RAM (one that erases Flash and one that programs Flash memory). Before I run those two functions I run unlock function, then erase, and finally program. After I did that I try to verify the content of the flash memory that was supposed to be programmed and it is NOT programmed - the content is
still 0xFFFFFFFF.

Do you have any idea what might be the issue here?

Thanks,

0 项奖励
回复

3,228 次查看
lukaszadrapa
NXP TechSupport
NXP TechSupport

Hi,

not sure what's wrong. You can try this piece of code that works:

/* unlock all blocks in bank 0 (0x0000_0000 - 0x0017_FFFF) */

  CFLASH_0.LML.R = 0xA1A11111; /* write password */

  CFLASH_0.LML.R = 0x00100000; /* unlock low and mid blocks primary */

  CFLASH_0.SLL.R = 0xC3C33333; /* write password */

  CFLASH_0.SLL.R = 0x00100000; /* unlock low and mid blocks secondary */

CFLASH_0.HBL.R = 0xB2B22222; /* write password */

CFLASH_0.HBL.R = 0x00000000;  /* unlock high blocks */

/* erase block B0F3 (0x0001_0000 - 0x0001_7FFF) */

CFLASH_0.MCR.B.ERS = 1;

CFLASH_0.LMS.R = 0x00000008; /* select B0F3 */

*(unsigned int *)0x00010000 = 0xFFFFFFFF; /* interlock write - write to any address in selected memory */

CFLASH_0.MCR.B.EHV = 1;

while(CFLASH_0.MCR.B.DONE == 0);

CFLASH_0.MCR.B.EHV = 0;

CFLASH_0.MCR.B.ERS = 0;

/* program double word to B0F3 */

CFLASH_0.MCR.B.PGM = 1; 

*(unsigned int *)0x00010000 = 0xAABBCCDD; /* interlock write */

*(unsigned int *)0x00010004 = 0x11223344; /* program data write */

CFLASH_0.MCR.B.EHV = 1;

while(CFLASH_0.MCR.B.DONE == 0);

CFLASH_0.MCR.B.EHV = 0;

CFLASH_0.MCR.B.PGM = 0;

This is for bank 0. If you want to program other banks, follow exactly the same procedure. The only difference is that you will use CFLASH_1 and DFLASH.

Next option is to use SSD flash drivers. These are for MPC5646C:

http://www.freescale.com/files/soft_dev_tools/software/device_drivers/MPC56XX_C90LC_JDP_SSD_100_DEVD...

0 项奖励
回复

3,228 次查看
mikibart
Contributor II

Hello Lukas,

I thank you for your quick reply.

The issue is resolved !

Basically, everything worked fine from the beginning except when I
downloaded a new application program the debugger erases complete flash memory –
so I couldn’t verify that I programmed the flash memory correctly.

Thanks

0 项奖励
回复