2 Replies Latest reply on Jan 31, 2017 8:48 AM by jrow

    Saving Device Name to Flash

    rich.soennichsen_1592346

      I am trying to save, and read back, the device name from flash without success.  I am using this code:

         

       

         

      /* Flash Config */
      #define FLASH_SIZE 128

         

      /* Flash constants */
      #define FLASH_ROW_SIZE_BYTES            128
      #define FLASH_ALIGNED __attribute__ ((aligned (FLASH_ROW_SIZE_BYTES)))

         

      static const char FLASH_DEVICE_NAME[FLASH_SIZE] = {0}; // Flash space for device name
      char device_name[FLASH_SIZE];   // User input device name

         


      /* Flash data write constants */
      #define FLASH_DATA_BASE_ADDRESS_BYTE    (uint32) (&FLASH_DEVICE_NAME)
      #define FLASH_DATA_BASE_ADDRESS_ROW     FLASH_DATA_BASE_ADDRESS_BYTE / FLASH_ROW_SIZE_BYTES

         

       

         

      void ReadNameInFlash()
      {
          uint8 i;

         

          // Read device from Flash
          for (i = 0; i < FLASH_SIZE; i++) {
              device_name[i] = FLASH_DEVICE_NAME[i];
          }
          //CyBle_GapSetLocalName(device_name); 
      }

         

      void SaveNameInFlash(const uint8 device_name[])
      {
          
          CySysFlashSetWaitCycles(48);
          
          CySysFlashWriteRow(FLASH_DATA_BASE_ADDRESS_ROW, device_name);
          
         // CyBle_GapSetLocalName((const char *)device_name);
          
      }

         

       

         

      I have commented out the CyBLE calls as the BLE stack is not initialized at this point.  The call to CySysFlashWriteRow results in a return code of CY_SYS_FLASH_SUCCESS.

         

       

         

      The read of flash returns all zeros....

         

       

         

      Thanks for the help.

         

       

         

      Rich