Getting Hard Fault Error in LPC54606 while using EEPROM_Write

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

Getting Hard Fault Error in LPC54606 while using EEPROM_Write

3,532 次查看
emb02
Contributor IV

Hi,

I'm testing internal EEPROM of LPC54606 in which I want to write 64 bytes using EEPROM_Write() function. But after calling this function controller goes in Hardfault handler and then not able to write data into EEPROM.

hardfault.PNG

I have referred lpcxpresso54628_eeprom example project.

I'm attaching my test project for reference.

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

2,612 次查看
rjleiser
Contributor II

// can pass struct or arrays, should work.

void Write(uint32_t address, void* data, uint32_t size)

{

if ((size % 4) != 0)

printf("ERROR: eeprom write, size align not 4 bytes\n");

 

// Combine four bytes from the buffer to a 32-bits word

uint32_t* buffer = (uint32_t*)data;

 

for (uint16_t i = 0, j = 0; i < size; i+=4, j++)

EEPROM_WriteWord(EEPROM, address + i, buffer[j]);

}

0 项奖励
回复

2,613 次查看
rjleiser
Contributor II

I have the exact same problem. I am also using a 54606.

If I single step the interal code for EEPROM_Write() then it works. 

If you just normally run EEPROM_Write() then I get a hardfault.

So it must be an underlying timing issue.

The short answer (not previously given) is to use EEPROM_WriteWord(); (with multiple calls) instead.

 

0 项奖励
回复

3,512 次查看
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,

I have checked your code, I suppose that byou have modified the SDK example code.

If you use the SDK example code without any modification, do you have any issue?

BR

XiangJun Rong

0 项奖励
回复

3,509 次查看
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,

for your code:

for (i = 0; i < 1; i++)
{
EEPROM_Write(EXAMPLE_EEPROM, u16Address, data, u16BytesToWrite);

for (j = 0; j < u16BytesToWrite / 4; j++)
{
eeprom_data = *((uint32_t *)(FSL_FEATURE_EEPROM_BASE_ADDRESS + i * u16BytesToWrite + j * 4));
if (eeprom_data != data[j])
{
err++;
PRINTF("Page %d offset %d is wrong, data is %x \r\n", i, (j * 4), eeprom_data);
}
}
PRINTF("Page %d program finished!\r\n", i);

u16Address += u16BytesToWrite;
}

The EEPROM page size is 0x4000/128=128 bytes, if you define u16BytesToWrite as 128, the EEPROM_Write() function will become page program.

Pls have a try

Generally, the wrong address will leads to hardfault error.

BR

XiangJun Rong

0 项奖励
回复

3,505 次查看
emb02
Contributor IV

Hi @xiangjun_rong 

If you use the SDK example code without any modification, do you have any issue?

-> No I don't get any error if using EEPROM_WritePage() to write data into EEPROM. 

But I don't want to write all 128 bytes (1 page) hence not using EEPROM_WritePage().

The EEPROM page size is 0x4000/128=128 bytes, if you define u16BytesToWrite as 128, the EEPROM_Write() function will become page program.

-> If I change u16BytesToWrite to 128 then also I'm getting hardfault error.

Is there any mistake in my test routine?

Can you run this code and will let me know if there is no hardfault error?

 

0 项奖励
回复

3,499 次查看
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,

Hi,

I have not LPC54628-EVK board on hand, pls try to test. If you still have issue, I will test on Tuesday next week.

Pls try to execute the line, and check which line leads to the hardfault

EEPROM_Write(EXAMPLE_EEPROM, u16Address, data, u16BytesToWrite);

for (j = 0; j < u16BytesToWrite / 4; j++)
{
eeprom_data = *((uint32_t *)(FSL_FEATURE_EEPROM_BASE_ADDRESS + i * u16BytesToWrite + j * 4));
if (eeprom_data != data[j])
{
err++;
PRINTF("Page %d offset %d is wrong, data is %x \r\n", i, (j * 4), eeprom_data);
}

BR

XiangJun Rong

0 项奖励
回复

3,495 次查看
emb02
Contributor IV

Hi @xiangjun_rong 

Pls try to execute the line, and check which line leads to the hardfault

-> I don't get error while debugging (step in).

eeprom out.PNG

But in runtime MCU goes in hardfault handler.

Not able to understand this.

 

 

 

 

 

0 项奖励
回复

3,466 次查看
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,

I suppose that you can not write EEPROM in a forever loop.

BR

XiangJun Rong

0 项奖励
回复

3,384 次查看
emb02
Contributor IV
Hi,
This is only for testing purpose.
Did you tested same code on your board?
0 项奖励
回复

3,245 次查看
emb02
Contributor IV

Hi @xiangjun_rong 

I'm still not able to write data into EEPROM. I'm getting Hardfault error.

In Chapter 47: LPC546xx EEPROM memory (UM10912) AUTOPROG mode is mentioned.

I'm using AUTOPROG = 01: Writing a single word to the page starts the erase/program cycle
automatically. This mode is useful store small data items (word) on random locations.

But I'm not able to get steps to do the same.

Can you provide example code for this configuration (AUTOPROG = 01) using EEPROM_Write().

I have also attached my test project please guide me with this.

 

 

0 项奖励
回复