12 Replies Latest reply on Jun 12, 2015 10:49 AM by ibrahima.tandian

    emulated EEPROM placement in Flash area

    vinay.dand

      Hello,

         

      In PSoC4 we have to use emulated EEPROM component to use flash portion as EEPROM area. One limitation of the Em_EEPROM component of PSoC4 is, it automatically places EEPROM space in flash. This location may changes with different build cycle. This may create an tricky issue during security protection of flash (usually employed for IP protection of your firmware).

         

      As you have to get the address of flash area allocated after a new build and change Flash Security file flags appropriately to allow Em_EEPROM to work within otherwise protected flash area. This is a tedious task and not intuitive as PSoC1 EEPOM component.

         
          One solution - as suggested in other forum post - is to define a fixed EEPROM area in flash using linker directive.   
         
              
         
          An example tried by me:   
         
              
         
          In global section define a variable to store emulated EEPROM data in flash as,   
         
              
         
                static const uint8  eepStrg[6]   __attribute__ ((section (".EEPROMDATA"))) = {0,0,0,0,0,0} ;   
         
              
         
          Here, const ensures that varaible will be allocated in ROM area.   
         
          section directive will creat a seperate section name to be allocated.   
         
          Note, it is must to initialize the EEPROM area with some data, for Em_EEPROM component to be allocated properly.   
         
              
         
          Next:   
         
          open project's linker script file (under Workspace Explorer - Source Tab - Generated Source - cm0gcc.ld)   
         
          in .ld file   
         
          add following lines   
         
          after ROM section  (one suggested location, after SECTION { ... ... ... } >rom )   
         
              
         
             .EEPROMDATA 0x00007f80 :   
         
             {   
         
               KEEP (*(.EEPROMDATA))   
         
             } >rom   
         
              
         
          Address 0x00007f80 is selected since it is last block of Flash - but can be other address not used by your firmware code.   
         
              
         
          Build project.   
         
              
         
          You should verify the allocation of emulated EEPROM space at the specified address in Flash ROM area, by searching the    
         
          generated map file (in Workspace Explorer under Results tab, 'Project name'.map file)   
         
              
         
          Now We can protect the Flash area excluding emulated EEPROM space by changing appropriate flag at Flash Security tab under cydwr file.   
         
              
         
          This approach has one draw back:   
         
          Whenever application is re-generated (due to change of component etc.) It generates new linker file. Needs editing the .ld    
         
          file again. (Software only change and build preserves the linker settings)   
         
              
         
          I will apreciate any     help towards,   
         
              
         
           1) Is there a method to preserve or automatically add section in linker script file?   
         
              
         
           2) Any other method to allocate EEPROM area at specific location to ease flash security allocation.   
         
              
         
          Best Regards,   
         
          Vinay   
         
              
        • 1. Re: emulated EEPROM placement in Flash area
          user_78878863

          There is a FAQ answer here: http://www.cypress.com/?id=4&rID=57109 , which leads to you here http://www.cypress.com/?rid=91945 for the PSoC5LP / PSoC4 (see page 30).

          • 2. Re: emulated EEPROM placement in Flash area
            vinay.dand

             HLI,

               

            Thanks for pointing AN89610.

               

            I have got the initial idea of modifying linker script file after reading AN89610 itself.

               

            After re-reading AN89610, (specially around page 23), My another work around solution is, copy generated linker script file, modify it to add custom EEPROM section at needed address. Rename the linker file. Store it in project source root folder and add it back to project. As mentioned in AN89610 :

               

            "Note Linker  script  files  are  automatically  generated  by 

               

            PSoC Creator at  project  build time, and changes that you 

               

            make to  those files  may be overwritten on the next build. 

               

            You can instruct PSoC Creator to use a  custom script  file, 

               

            using  the  PSoC  Creator  menu  Project >  Build  Settings > 

               

            Linker > General > Custom Linker Script.

               

            If you use  a custom linker script file, it is a best  practice to 

               

            add  it  to the project  (menu Project > Existing Item…)  and 

               

            save  it  in  the  project  folder."

               

             

               

            This solves issue of over written linker script file.

               

            But I am not a GCC expert. And reading GCC documentation and creating fully custom linker script file is not easy. I would request experienced people to validate my solution, though it is working with this project.

               

            Regards,

               

            Vinay

            • 3. Re: emulated EEPROM placement in Flash area
              user_78878863

              Oh now I see the mistake I made :(

                 

              The solution I thought was so neat only works for the MDK compiler, not for gcc. There the one you are looking at seems to be the only solution.

              • 4. Re: emulated EEPROM placement in Flash area
                user_78878863

                Oh, Google gave me a better answer after looking around. Its possible to set symbol addresses via the command line, see e.g. https://stackoverflow.com/questions/495262/linking-symbols-to-fixed-addresses-on-linux

                   

                So you can use e.g.

                   
                extern struct FooBar foobar;
                   

                in your code, the then call gcc with

                   
                gcc -Wl,--defsym,foobar=0x76543210 file.c
                   

                Or you use a so-called symbol file, storing the addresses of the variables you need placed (see the same link). Both should work without modifying the linker file.

                • 5. Re: emulated EEPROM placement in Flash area
                  vinay.dand

                   HLI,

                     

                   

                     

                  Thanks, for giving a nice tip.

                     

                  I will try it out and post my result to complete the solution.

                     

                   

                     

                  Regards,

                     

                  Vinay

                  • 6. Re: emulated EEPROM placement in Flash area
                    vinay.dand

                     Hello,

                       

                     

                       

                    --defsym defines sysmbol as specified address value.

                       

                    But linker does not allocate the eeprom flash locations at that address.

                       

                     

                       

                    --section commands works well.

                       

                    example as:

                       

                    -Wl,--section-start=.EEPROMDATA=0x00007f80

                       

                     

                       

                    I am repeating the solution of defining Em_EEPROM allocation at user specified location on flash memory with out modifying 

                       

                     

                       

                    linker script file as below:

                       

                     

                       

                    1) In global section define a variable to store emulated EEPROM data in flash as,

                       

                     

                       

                    static const uint8  eepStrg[6]   __attribute__ ((section (".EEPROMDATA"))) = {0,0,0,0,0,0} ;

                       

                     

                       

                    Here, const ensures that variable will be allocated in ROM area.

                       

                    section directive will create a separate section name to be allocated.

                       

                    Note, it is must to initialize the EEPROM area with some data, for Em_EEPROM component to be allocated properly.

                       

                     

                       

                    2) specify custom linker flag on command line as

                       

                     

                       

                    -Wl,--section-start=.EEPROMDATA=0x00007f80

                       

                     

                       

                    (Address 0x00007f80 is selected since it is last block of Flash - but can be other address not used by your firmware code.

                       

                    )

                       

                    Go to Project->Build Settings->ARM GCC x.x.x->Linker->Command Line->Custom Flags->add -Wl,--section-

                       

                     

                       

                    start=.EEPROMDATA=0x00007f80

                       

                     

                       

                    You can verify .EEPROMDATA section allocated at 0x7f70 flash location in project's map file.

                       

                    Also attaching a sample project for the same.

                       

                    You can step through the code using MiniProg3 on a CY8CKit-049-42xx

                       

                     

                       

                    Hope this may be useful towards IP protecting flash while keeping Em_EEPROM area seperate as unproteced block using Flash 

                       

                     

                       

                    Security file.

                       

                     

                       

                    Regards,

                       

                    Vinay

                    • 7. Re: emulated EEPROM placement in Flash area
                      user_78878863

                      Glad you got this working. And thanks for reporting back!

                      • 8. Re: emulated EEPROM placement in Flash area
                        ibrahima.tandian

                         Hello

                           

                        Can someone please explain the EM_EEPROM to me. All the exemples work well untill I unpleg and replug my dev kit. The data I saved is then lost , yet the datasheet states 

                           

                        "The Emulated EEPROM component should be used when:

                           

                         Data needs to be preserved across power cycles, and the target device does not have

                           

                        dedicated EEPROM memory."

                           

                        but I loose all my data at each power cycle. 

                           

                        Help please

                           

                        Thanks

                        • 9. Re: emulated EEPROM placement in Flash area
                          user_14586677

                          Some questions -

                             

                           

                             

                          1) What dev kit are you using ?

                             

                          2) How are you powering the devkit ?

                             

                          3) How are you debugging, what interface are you using ?

                             

                           

                             

                          You are not reprogramming the part and expecting the data to still

                             

                          reside ? Like a build /  program / debug cycle ?

                             

                           

                             

                          Some considerations -

                             

                           

                             

                          www.cypress.com/

                             

                           

                             

                          www.cypress.com/

                             

                           

                             

                          www.cypress.com/

                             

                           

                             

                          Regards, Dana.

                          • 10. Re: emulated EEPROM placement in Flash area
                            user_388353959

                            >> Can someone please explain the EM_EEPROM to me. All the exemples work well untill I unpleg and replug my dev kit. The >> data I saved is then lost , yet the datasheet states 

                               
                                Here you can found some examples:   
                                   
                                    
                               
                                    
                               
                                Reiner   
                               
                                    
                            • 11. Re: emulated EEPROM placement in Flash area
                              user_1377889

                              @it

                                 

                              Can you post your actual complete project, so that we all can have a look at all of your settings? To do so, use
                              Creator->File->Create Workspace Bundle (minimal)
                              and attach the resulting file.



                              Bob
                               

                              • 12. Re: emulated EEPROM placement in Flash area
                                ibrahima.tandian

                                 Problem solved, Thanks all for your pointers. I forgot that when you debug it reprograms the whole device as hinted by Dana.

                                   

                                   

                                new to PSOC and loving it so far.