We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hallo
Im using the LPC2478 with 8 MB external memory. Im setting up the SDRAM from within the LPC2400.s file.
Everything is OK, until a NORMAL command is issued to the SDRAM (Right after dummy read)
LDR R4, =NORMAL_CMD ; Write NORMAL Command STR R4, [R0, #EMC_DYN_CTRL_OFS]
The last code line, overwrittes the EMCDynamicCfg0 register with a value resulting in selection of a wrong SDRAM type. Before the call the EMCDynamicConfig0 is 0x00001280 After the line its 0x07664448 ???
The values in R4, R0 and #EMC_DYN_CTRL_OFS are just fine.
Why does that code write to my EMCDynamicConfig0 register? It schould write to the EMCDynamicControl register instead. But it writes to both with a corrupted value?
/Thomas
My guess is that you are not doing same thing in startup as in C, no other explanation is possible. So, investigate starup, perhaps you are not setting the mode register in startup or something. Also, use the last available example from Keil for starting point.
I did. The startup file is from the latëst Blinky sample from Keil!!!
I have now tried to move the SDRAM init to C source.
And again, when the NOP command is issued the EMCDynamicConfig0 and EMCDynamicControl is messed up.!!!
// SDRAM Init PCONP |= 0x00000800; /* Turn on EMC PCLK */ EMC_CTRL = 0x00000001; EMC_CONFIG = 0x00000000;
PINSEL5 |= 0x05010115; PINSEL6 |= 0x55555555; // D0-15 PINSEL8 = 0x05555555; PINSEL9 = 0x50045555;//0x10040000;
// Setup Dynamic Memory Interface // 16 bit EMC_DYN_RP = 2; EMC_DYN_RAS = 3; EMC_DYN_SREX = 7; EMC_DYN_APR = 2; EMC_DYN_DAL = 5; EMC_DYN_WR = 1; EMC_DYN_RC = 5; EMC_DYN_RFC = 5; EMC_DYN_XSR = 7; EMC_DYN_RRD = 1; EMC_DYN_MRD = 2; EMC_DYN_RD_CFG = 1;
EMC_DYN_RASCAS0 = 0x00000303;
EMC_DYN_CFG0 = 0x00001280;
// Wait 0 for(i=0; i<0x100; i++);
// ERROR OCCURES HERE!!!! //Send command: NOP EMC_DYN_CTRL = 0x00000183; // ERROR END
// Wait 1 //wait 128 ABH clock cycles for(i=0; i<0x100; i++); //Send command: PRECHARGE-ALL, shortest possible refresh period EMC_DYN_CTRL = 0x00000103; EMC_DYN_RFSH = 0x00000002;
// Wait 2 //wait 128 ABH clock cycles for(i=0; i<0x40; i++);
//Set correct refresh period EMC_DYN_RFSH = 0x1C; //Send command: MODE EMC_DYN_CTRL = 0x00000083; //Send command: NORMAL EMC_DYN_CTRL = 0x00000000; //Enable buffer EMC_DYN_CFG0 |= 0x00080000; //0x00001280
//wait 128 ABH clock cycles for(i=0; i<0x10; i++);
The line "EMC_DYN_CTRL = 0x00000183", which schould write 0x183 to the EMCDynamicCOntrol register. But watching the External Memory Controller debug view in Keil, then the value 0x058C4448 is written to the EMCDynamicConfig0 and EMCDynamicControl register???
Why?
Thomas
Can you also post assembly code?
Do you mean the assembly of the compiled C source??
I have send the assembly code for the builded source:
64: // Wait 0 65: //wait 128 ABH clock cycles 0x0000054C E3A01D4A MOV R1,#0x00001280 0x00000550 E5801100 STR R1,[R0,#0x0100] 66: for(i=0; i<0x100; i++); 67: //Send command: NOP 0x00000554 E3A01000 MOV R1,#0x00000000 0x00000558 E3510C01 CMP R1,#0x00000100 0x0000055C 2A000001 BCS 0x00000568 0x00000560 E2811001 ADD R1,R1,#0x00000001 0x00000564 EAFFFFFB B 0x00000558 68: EMC_DYN_CTRL = 0x00000183; 69: 70: // Wait 1 71: //wait 128 ABH clock cycles 0x00000568 E59F108C LDR R1,[PC,#0x008C] 0x0000056C E5801020 STR R1,[R0,#0x0020] 72: for(i=0; i<0x100; i++); 73: //Send command: PRECHARGE-ALL, shortest possible refresh period 0x00000570 E3A01000 MOV R1,#0x00000000 0x00000574 E3510C01 CMP R1,#0x00000100 0x00000578 2A000001 BCS 0x00000584 0x0000057C E2811001 ADD R1,R1,#0x00000001 0x00000580 EAFFFFFB B 0x00000574 74: EMC_DYN_CTRL = 0x00000103; 0x00000584 E59F1074 LDR R1,[PC,#0x0074] 0x00000588 E5801020 STR R1,[R0,#0x0020]
As much as I see, you have not ported this code 100%, for example where is a dummy read in your code?
I have found the reason.
The for-loop, thats makes a delay between the commands, was not long enough.
Setting those to the right ones it works fine.
By the way, I cant see any reason for the dummy read???
Embedded forums everywhere constantly warns about dumb for loops for delay - they regularly hurts.
You realize that an empty for loop can be totally omitted, so you can't even be sure that it is enough to increase the stop criteria.
Another thing - why don't you post code as code? It is way easier to read if you do, since all line breaks in the source will survive.
I know. So I have just used a timer for the job instead. So any delays can be made by calling the same function
Reason for dummy read is setting the mode register of the SDRAM as this is set by address lines after mode command is issued.
Usually timings are very important in initializations, the way you ensure that delays are as necessary are not really important, also calculating it roughly by using instructions should be satisfactory.