5 Replies Latest reply on May 18, 2020 2:06 PM by MoTa_728816

    Emulated EEPROM with PSOC4

    ReMa_3807036

      Hi,

      I'm using PSoC Creator 4.3 with device PSOC4100S  CY8C4125AXI-S433, in my design I'm using Flash to emulate EEprom and I'm following the relative code example, and here I have a problem, the variable "Em_EEPROM_em_EepromStorage" within the generated file Em_EEPROM.c, is declarated only if defined "CY_PSOC6", and it is not here the case.

       

      #if ((CY_PSOC6) && (Em_EEPROM_1_STORAGE_EM_EEPROM))

       

          CY_SECTION(".cy_em_eeprom") CY_ALIGN(CY_FLASH_SIZEOF_ROW)

          const uint8 Em_EEPROM_1_em_EepromStorage[Em_EEPROM_1_ACTUAL_SIZE] = {0u};

       

      #endif /* ((CY_PSOC6) && (Em_EEPROM_1_STORAGE_EM_EEPROM)) */

       

       

      Probably I'm wrong ... Have you any suggestions?

       

      Thanks

      Renato

        • 1. Re: Emulated EEPROM with PSOC4
          MoTa_728816

          Hi,

           

          I just tried generate a similar project and in the Em_EEPROM.c

          in the comment of Em_EEPROM_Int, it is written.

           

          =====================

          * Fills the start address of the EEPROM to the component configuration structure

          * and invokes Cy_Em_EEPROM_Init() function. In case of PSoC 6 the function

          * is located in Cy_Em_EEPROM middleware library which is part of PDL. In case if

          * it is utilized in the design based on non-PSOC 6 device the function is

          * located in internal design wide resource component - Em_EEPROM_Dynamic.

          =====================

           

          So, I think that even if you are not using PSoC 6, Em_EEPROM will work with your project.

           

          Have you built and tried the project?

           

          moto

          • 2. Re: Emulated EEPROM with PSOC4
            ReMa_3807036

            Thanks Moto, but I have not solved...

            Yes I have built the project (not yet tried), it shows the following error:

             

            Build error: undefined reference to `Em_EEPROM_1_em_EepromStorage'

             

            (please note that my module name is Em_EEPROM_1)

             

            Really this error is correct because the 'Em_EEPROM_1_em_EepromStorage' is not declared,

             

            In Em_EEPROM_1.c file it is conditioned by CY_PSOC6 define, but I'm not using PSOC6 but PSOC4, so it is false.

             

            #if ((CY_PSOC6) && (Em_EEPROM_1_STORAGE_EM_EEPROM))

             

                CY_SECTION(".cy_em_eeprom") CY_ALIGN(CY_FLASH_SIZEOF_ROW)

                const uint8 Em_EEPROM_1_em_EepromStorage[Em_EEPROM_1_ACTUAL_SIZE] = {0u};

             

            #endif /* ((CY_PSOC6) && (Em_EEPROM_1_STORAGE_EM_EEPROM)) */

             

            Really if I force that declaration i.e. with

             

            CY_SECTION(".cy_em_eeprom") CY_ALIGN(CY_FLASH_SIZEOF_ROW)

                const uint8 Em_EEPROM_1_em_EepromStorage[Em_EEPROM_1_ACTUAL_SIZE] = {0u};

             

            the ERROR disappear (then I do not know it work ).

             

            In any case, I prefer to avoid any forcing... the automatic code generation should work!

            I'm following the code example "CE195313 – PSoC Emulated EEPROM".

            • 3. Re: Emulated EEPROM with PSOC4
              MoTa_728816

              Hi,

               

              I found a sample I (?) wrote a while ago.

              It was for fixed address Em_EEPROM, but I modified it to be without linker script.

              Then I changed the device to CY8C4146LQI-S433, (TSoC) as it is the only 4100S I have.

               

              schematic

              001-schematic.JPG

              Tera Term Out

              tera_term_log.JPG

              main.c

              =============

              #include "project.h"

              #include "stdio.h"

               

              static const uint8_t store[Em_EEPROM_PHYSICAL_SIZE]

              __ALIGNED(CY_FLASH_SIZEOF_ROW) = { 0u } ;

               

              cy_en_em_eeprom_status_t status ;

               

              char str[128] ; /* print buffer */

              void print(char *str)

              {

                  UART_UartPutString(str) ;

              }

               

              void print_em_eprom_error(cy_en_em_eeprom_status_t status)

              {

                  switch(status) {

                  case CY_EM_EEPROM_SUCCESS:      print("No Error\n") ; break ;

                  case CY_EM_EEPROM_BAD_PARAM:    print("The input parameter is invalid\n") ; break ;

                  case CY_EM_EEPROM_BAD_CHECKSUM: print("The data in EEPROM is correupted\n") ; break ;

                  case CY_EM_EEPROM_BAD_DATA:     print("Failed to place the EEPROM in flash\n") ; break ;

                  case CY_EM_EEPROM_WRITE_FAIL:   print("Write to EEPROM failed\n") ; break ;

                  default:

                      sprintf(str, "EEPROM Unknown Error %d\n", status) ;

                      print(str) ;

                      break ;

                  }

              }

               

              void init_hardware(void)

              {

                  CyGlobalIntEnable; /* Enable global interrupts. */

               

                  UART_Start() ;

                 

                  status = Em_EEPROM_Init((uint32_t)store) ;

                  if (status != CY_EM_EEPROM_SUCCESS) {

                      print_em_eprom_error(status) ;

                  }

              }

               

              void splash(void)

              {

                  sprintf(str, "Emulated EEPROM Test (%s %s)\n", __DATE__, __TIME__) ;

                  print(str) ;

              }

               

              int main(void)

              {

                  unsigned int i ;

                  unsigned int test_size = 16 ;

                 

                  uint8 zustand[Em_EEPROM_EEPROM_SIZE] = {} ;

                  init_hardware() ;

                 

                  splash() ;

                 

                  sprintf(str, "EEPROM SIZE = %d\n", Em_EEPROM_EEPROM_SIZE) ;

                  print(str) ;

                 

                  print("Store:\n") ;

                  for (i = 0 ; i < test_size * 2 ; i++ ) {

                      sprintf(str, "%02X ", store[i]) ;

                      print(str) ;

                      if (i == 0xF) {

                          print("\n") ;

                      }

                  }

                  print("\n") ;

               

                  print("Values to be written:\n") ;

                  for (i = 0 ; i < test_size ; i++) {

                      zustand[i] = 0xF0 + i ;

                      sprintf(str, "%02X ", zustand[i]) ;

                      print(str) ;

                  }

                  print("\n") ;

                 

                  CyDelay(10) ;

                 

                  status = Em_EEPROM_Write((uint32)0, (void*)zustand, test_size) ;

                  if (status != CY_EM_EEPROM_SUCCESS) {

                      print_em_eprom_error(status) ;

                  }

                 

                 

                  print("Store:\n") ;

                  for (i = 0 ; i < test_size * 2 ; i++ ) {

                      sprintf(str, "%02X ", store[i]) ;

                      print(str) ;

                      if (i == 0xF) {

                          print("\n") ;

                      }

                  }

                  print("\n") ;

                     

                  for (i = 0 ; i < test_size ; i++ ) {

                      zustand[i] = 0 ;

                  }

                 

                  status = Em_EEPROM_Read((uint32)0, zustand, test_size) ;

                  if (status != CY_EM_EEPROM_SUCCESS) {

                      print_em_eprom_error(status) ;

                  }

                 

                  print("Values read:\n") ;

                  for (i = 0 ; i < test_size ; i++ ) {

                      sprintf(str, "%02X ", zustand[i]) ;

                      print(str) ;

                  }

                  print("\n") ;

               

               

                  for(;;)

                  {

                      /* Place your application code here. */

                  }

              }

              =============

               

              Attached is the project with device target changed to CY8C4125AXI-S433.

              I was compile-able, but I have not tested it on the real device.

               

              moto

              • 4. Re: Emulated EEPROM with PSOC4
                ReMa_3807036

                Hi Moto,

                thanks for your answer.

                I will follow your example, even if you go over the problem because in main.c you declare   "store" (then used in Em_EEPROM_Init(..) function)

                 

                static const uint8_t store[Em_EEPROM_PHYSICAL_SIZE]

                 

                instead to use "Em_EEPROM_em_EepromStorage" as in the code example within PSoc Creator 4.3, it is declared also in your example at line 40 of Em_EEPROM.c file, but it is not reachable ... (as already written).

                 

                Best Regards

                Renato

                 

                • 5. Re: Emulated EEPROM with PSOC4
                  MoTa_728816

                  Dear Renato-san,

                   

                  Please READ the datasheet of Em_EEPROM.

                  In the page 2 it is written

                  002-Datasheet-Page2.JPG

                  Please read carefully after the line "For non-PSoC 6 devices,.."

                   

                  Best Regards,

                  19-May-2020

                  moto