Skip to main content
Maximilian Pohl
Associate III
May 6, 2021
Question

STM32F411 EEPROM Emulation -> Hard Fault Error

  • May 6, 2021
  • 8 replies
  • 1519 views

Hello, i just implemented the EEPROM Emulation example. It worked a few days perfectly.

The i added a ADC via CubeMX. Now i always enter the hard fault handler after EE_Init() was called.

Any idea? Thanks a lot

This topic has been closed for replies.

8 replies

waclawek.jan
Super User
May 7, 2021

Debug the fault as usually, i.e. from the stack content find out where do the fault occur.

JW

Maximilian Pohl
Associate III
May 7, 2021

I am not able to handle this error according this informations.

Maximilian Pohl
Associate III
May 7, 2021

0693W00000ANdFfQAL.png

waclawek.jan
Super User
May 7, 2021

>I am not able to handle this error according this informations.

Then learn it. It's a useful skill. Clive @Community member​  has posted hints and guidelines on this forum many times, search.

Undfined instruction execution may be trickier, though, maybe result of stack overflow, incorrectly used function pointer, etc. Usual debugging techniques apply, e.g. blocking out parts of code to find out where's the culprit, observing registers and stack to find the execution path before the fault, etc.

That you used some ready-made code doesn't mean you shouldn't to debug it as your own.

JW

Maximilian Pohl
Associate III
May 7, 2021

Thank you. Yes i want to learn it for shure. But without asking i am not able to handle this error right now.

I use the EEPROM_Emulation example. When i remove the EE_Init everything works fine.

This kind of errors are out of my range right now.

waclawek.jan
Super User
May 7, 2021

I understand, but guessing what happens in *your* code is akin to reading from crystal cube.

But I'll try: how did you partition the FLASH? Isn't your code overlapping the FLASH pages assigned to the EEPROM emulation?

@note
Before using the application, ensure that dedicated sectors for EEPROM (FLASH_SECTOR_2 and FLASH_SECTOR_3) 
are erased to avoid a match with a valid page OPCODE.
 
Following picture illustrates the situation in program memory:
 
 Top Flash Memory address /-------------------------------------------\ 0x08080000
 | |
 | |
 | |
 | |
 | |
 | Sector 4 - Sector 7 |
 | |
 |-------------------------------------------| 0x08010000
 Sector 3 (16KB) | |
 | |
 | Flash used for EEPROM emulation mechanism | 0x0800C000
 Sector 2 (16KB) | |
 | |
 |-------------------------------------------| 0x08008000
 Sector 1 (16KB) | |
 | |
 |-------------------------------------------| 0x08004000
 | |
 Sector 0 (32KB) | flash used for implement the EEPROM |
 | emulation mechanism(6KB) |
 \-------------------------------------------/	 0x08000000
 

JW

Maximilian Pohl
Associate III
May 7, 2021

Hi, yes you are right. i know that its a bit stupid.

I erased the chip manually before loading the program. Do i need to block the flash sector in the linker scipt or will the compiler do the job.

I dont find any hints in the reference manual for that.

waclawek.jan
Super User
May 7, 2021

> Do i need to block the flash sector in the linker scipt

Yes.

You need to move the bulk of your application to above the FLASH area allocated for the EEPROM emulation.

This basically is something like when you try to do a bootloader - you may find hints here on the forum.

> I dont find any hints in the reference manual for that.

Of course not, the EEPROM emulation is simply an application or part of an application, RM does not deal with this.

Read the materials which come with the example. Observe the linker scripts there and any method which moves code to above the FLASH emulation area (there may be none as the examples are simple and may fit below it).

JW