Problems with EEPROM write failing and initialization

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
RuPi_283656
Level 4
Level 4
10 sign-ins First solution authored 25 replies posted

I cannot get the EEPROM working right in my program.  I ran the EEPROM demo project and it works but I cannot use the same code because the compiler rejects it:

RuPi_283656_0-1672371898775.png

That is really tiny, hope it is readable.  Anyway the compiler says that it cannot assign to the userFlashStartAddr.  Maybe this has something to do with it being const, but in the example this works.  After some trial I discovered that the example was using EEPROM version 2.0 and I was using 2.2 - Aha! I said, but changing to 2.0 makes no difference.

if I instead use EEPROM_Init ((uint32_t)EEPROM_em_EepromStorage). the init returns success, but every attempt to write to the EEPROM fails with the failure return value.  

So  It seems that I have to use the middleware Cy_ functions, but the complier will not accept the start address...

(Oh, and I am enabling global interrupts before the init function is called.)

Any help???

Thanks, Russ

 

0 Likes
1 Solution

Russ,

I'm glad you're up and working.

Knowing what was causing your grief would be instructive to you and to others who encounter the same/similar issue.

However, life goes on.  Sometimes the answer is not evident or easy to achieve.

If you're willing to share the 'original' project with the forum, maybe someone will pickup the challenge.

Len
"Engineering is an Art. The Art of Compromise."

View solution in original post

0 Likes
9 Replies
pblemel
Level 4
Level 4
25 replies posted 25 sign-ins First like received

Russ,

Edited:  I found this solution, which might work for you: https://community.infineon.com/t5/PSoC-6/PSOC-6-EmEeprom-error/td-p/264759

I am only getting started with the EEPROM emulation, but I suggest looking at the data sheet, which says

EEPROM storage can be allocated at a fixed address in flash. To do this, you must modify the
linker control file (linker script).

Hope that's helpful!

0 Likes
Len_CONSULTRON
Level 9
Level 9
Beta tester 500 solutions authored 1000 replies posted

Russ,

Try changing out the offending code line with:

EEPROM_config.userFlashStartAddr = EEPROM_em_EepromStorage;

Len
"Engineering is an Art. The Art of Compromise."
0 Likes

Hi Len. Thanks for the suggestion.  I had already tried that and it does not work, just changes the error message slightly.  And I looked up the cy_stc_eeprom_config_t (of which EEPROM_config is an instance).  and the user address is declared as uint32_t, so the cast is needed. 

But then I noticed that EEPROM_config is declared as a const, so I tried modifying that declaration to be not const (of course I know that is not a long term solution because as soon as I do a full build again the EEPROM.h header will be rebuilt, but I wanted to see if it would work that way.)

So, then the initialization error went away and I was able to finish compiling without error.  But in testing, I get the same result as when using the API calls, every write attempt results in a CY_EM_EEPROM_WRITE_FAIL return.

Now it is interesting that the data sheet (and every other document that I can find) states that there is no API for EEPROM except for the middleware PDL calls.  Yet the generated EEPROM.h file contains a function declaration for EEPROM_init (uint32_t startAddress), and defines for EEPROM_Write, EEPROM_Read, EEPROM_Erase, and EEPROM_NumWrites, each calling the corresponding PDL call, and just adding the EEPROM_Context item in the call.

These EEPROM.h API calls are what I was using when I initially found the write failure.  And using the PDL calls results in the same error once I removed the const declaration from the cy_stc_eeprom_config_t  instance.

SO, I think the bottom line is that there is some difference in the way my program is compiled (or written) than that of the example.  But I cannot find a difference.  I do have a lot of other code in my program, UART, A/D, timer interrupt, etc., but the EEPROM initialization, and the write failure,  are done before any of those are enabled, and none of those routines read or write to the EEPROM.

I guess my next step will be to start adding elements of my program to the example and see if any of them cause the EEPROM writes to start failing.  Unless you have any other ideas??

Thanks, Russ

0 Likes

Russ,

I'm trying to reproduce your results using PSoC Creator with no luck. 

You provided minimal clues to the structure of your code.  I'm making certain assumptions.

Based on these assumptions here is my code fragment with NO COMPILER COMPLAINTS.

#include "project.h"

const uint8_t EEPROM_em_EepromStorage[52];
cy_en_em_eeprom_status_t   eeRv;
cy_stc_eeprom_config_t EEPROM_config;

int main(void)
{
    __enable_irq(); /* Enable global interrupts. */

    /* Place your initialization/startup code here (e.g. MyInst_Start()) */
	EEPROM_config.userFlashStartAddr = (uint32_t) EEPROM_em_EepromStorage;

    for(;;)
    {
        /* Place your application code here. */
    }
}

Can you provide your project to the forum?   At least can you provide a minimized version of your project with the EEPROM components?

Len
"Engineering is an Art. The Art of Compromise."
0 Likes

Thanks Len.  That is exactly like how the example program is coded, and it works on my system if I use it.  But when I take the same code and add it to my program I have the errors.

I have tested with everything in my program disabled except the EEPROM and still the same problems.  I think there has to be some kind of compile directive or other setup problem but have been unable to find it as yet.  I am in the middle of checking something else out, but will send a project package soon.

Thanks. Russ

0 Likes

Hi again Len.  Well, I have it working.  I really do not know what the problem was.  I started adding code from my program to the example program that was working.  When I had added it all, the EEPROM was still working.  Going back to the original program the EEPROM still would not work.

The one difference I could see is that when the generated header file (EEPROM.h) was created with my original program, the declaration for the EEPROM config structure instance is declared as const.  With the example and my new version, const is not there.  Of course this happens 'behind the scenes', during the build process, so I don't know what causes it.  I did a side by side comparison of the header files and that is the only difference.  But changing it to not be const in the original program does not fix the problem.

I also compared the build settings for both programs and found no differences.

I'm satisfied that I have a working program now, but have no clue as to what went wrong...

Regards, Russ

0 Likes

Russ,

I'm glad you're up and working.

Knowing what was causing your grief would be instructive to you and to others who encounter the same/similar issue.

However, life goes on.  Sometimes the answer is not evident or easy to achieve.

If you're willing to share the 'original' project with the forum, maybe someone will pickup the challenge.

Len
"Engineering is an Art. The Art of Compromise."
0 Likes

Based, on the post I linked to previously, I am wondering if the "Config data in flash" checkbox setting is the same on both designs?  According to that post, that setting is what generates the 'const'.

0 Likes

pbleml, you are exactly right!  I don't ever recall user settings being in the 'Built in' tab, so I never looked there!  Thanks for figuring this out!

Regards, Russ

0 Likes