Hello, I have an external SRAM on the EMC of LPC4357FET256, the model is IS61WV5128EDBLL-10TLI.
I found a very strange problem when I finished writing the driver debugging.
As shown in the figure, I wrote a functional verification program. It is normal for external SRAM to write data sequentially, write data out of order, and directly fill data.
When using pointer operation in the program, if the address %64<32, changing the data of this address will also change the data of this address +32. If address %64>=32, changing the data of this address will also change the data of this address -32. This resulted in all the wrong data I wrote.
I've checked my EMC configuration, data width, timing, trying to close the buffers, nothing solves the problem.
What I'm thinking is that if my EMC is misconfigured, it should also be wrong to write data directly through the address in the first place. There should also be problems with random writes to memory and sequential writes. So I wonder if this is a BUG of the LPC43xx microcontroller, or a BUG of the Keil MDK?
Does anyone have a similar situation and can provide some guidance? thank you
解決済! 解決策の投稿を見る。
Hi, Captain,
Regarding your question, I think the code is incorrect.
for(unsigned int i=0; i<num; i++)
{
volatile unsigned int Add=0x1c00_0000+i;
volatile unsigned char data=*(ptr+i);
__asm("NOP");
*(volatile uint32_t *)Add=data;
}
for the *(volatile uint32_t *)Add=data; because the Add address is uint_32 type, the Add address can be 0x1c00_0000; 0x1c00_0004; 0x1c00_0008; 0x1c00_000C; but it can not be 0x1c00_0001;0x1c00_0002; 0x1c00_0003, otherwise, unalignment error will happen.
You can use the code like:
uint32_t temp;
unsigned char c0,c1,c2,c3;
for(unsigned int i=0; i<num/4; i+4)
{
volatile unsigned int Add=0x1c00_0000+i;
c0=*(ptr+i);
c1=*(ptr+i+1);
c2=*(ptr+i+2);
c3=*(ptr+i+3);
temp=c3<<24|c2<<16|c1<<8|c0;
__asm("NOP");
*(volatile uint32_t *)Add=temp;
}
Pls have a try.
Hope it can help you
BR
XiangJun Rong
Hi, Captain,
Regarding your question, I think the code is incorrect.
for(unsigned int i=0; i<num; i++)
{
volatile unsigned int Add=0x1c00_0000+i;
volatile unsigned char data=*(ptr+i);
__asm("NOP");
*(volatile uint32_t *)Add=data;
}
for the *(volatile uint32_t *)Add=data; because the Add address is uint_32 type, the Add address can be 0x1c00_0000; 0x1c00_0004; 0x1c00_0008; 0x1c00_000C; but it can not be 0x1c00_0001;0x1c00_0002; 0x1c00_0003, otherwise, unalignment error will happen.
You can use the code like:
uint32_t temp;
unsigned char c0,c1,c2,c3;
for(unsigned int i=0; i<num/4; i+4)
{
volatile unsigned int Add=0x1c00_0000+i;
c0=*(ptr+i);
c1=*(ptr+i+1);
c2=*(ptr+i+2);
c3=*(ptr+i+3);
temp=c3<<24|c2<<16|c1<<8|c0;
__asm("NOP");
*(volatile uint32_t *)Add=temp;
}
Pls have a try.
Hope it can help you
BR
XiangJun Rong
Hi, Captain,
谢谢
XiangJun Rong