cancel
Showing results for 
Search instead for 
Did you mean: 

stm32f10x eeprom emulation

FLast.11
Associate III
Posted on December 29, 2015 at 03:51

Hello, i gone through AN2954 and to make it simple,

i just get out the eeprom write  & read (don't am i correct to do so)

EEprom write:

uint16_t EE_WriteVariable(uint16_t VirtAddress, uint16_t Data)

{

  uint16_t Status = 0;

  /* Write the variable virtual address and value in the EEPROM */

  Status = EE_VerifyPageFullWriteVariable(VirtAddress, Data);

  /* In case the EEPROM active page is full */

  if (Status == PAGE_FULL)

  {

    /* Perform Page transfer */

    Status = EE_PageTransfer(VirtAddress, Data);

  }

  /* Return last operation status */

  return Status;

}

//===================

EEPROM READ

uint32_t EEPROM_Read(uint16_t Address)

{

    uint32_t readValue;

    FLASH_Unlock();

//    Address = BANK1_WRITE_START_ADDR;

    readValue = (*(__IO uint16_t*) Address);

    FLASH_Lock();

    return readValue;

}

However,

when i process to do

 EE_WriteVariable(200, 14);

          

           FLASH_Unlock();

           test_3 = EEPROM_Read(200);

i cannot get the correct value in test_3.

Can anyone help?

Thanks
2 REPLIES 2
Posted on December 29, 2015 at 06:05

Can anyone help?

Look, it's a 32-bit processor, you can't take a 16-bit variable and cast it into an address and expect it to function properly.

You'll need to use the EEPROM abstraction to go retrieve your value, I don't think it exists at some linear memory address.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
FLast.11
Associate III
Posted on December 29, 2015 at 07:17

Thanks clive, can you explain more as i am new to 32bit world.

what i do is take the core out from the following

uint16_t EE_ReadVariable(uint16_t VirtAddress, uint16_t* Data);

uint16_t EE_WriteVariable(uint16_t VirtAddress, uint16_t Data);

and in the readvariable function 

//=========

uint16_t EE_ReadVariable(uint16_t VirtAddress, uint16_t* Data)

{

  uint16_t ValidPage = PAGE0;

  uint16_t AddressValue = 0x5555, ReadStatus = 1;

  uint32_t Address = 0x08010000, PageStartAddress = 0x08010000;

  /* Get active Page for read operation */

  ValidPage = EE_FindValidPage(READ_FROM_VALID_PAGE);

  /* Check if there is no valid page */

  if (ValidPage == NO_VALID_PAGE)

  {

    return  NO_VALID_PAGE;

  }

  /* Get the valid Page start Address */

  PageStartAddress = (uint32_t)(EEPROM_START_ADDRESS + (uint32_t)(ValidPage * PAGE_SIZE));

  /* Get the valid Page end Address */

  Address = (uint32_t)((EEPROM_START_ADDRESS - 2) + (uint32_t)((1 + ValidPage) * PAGE_SIZE));

  /* Check each active page address starting from end */

  while (Address > (PageStartAddress + 2))

  {

    /* Get the current location content to be compared with virtual address */

    AddressValue = (*(__IO uint16_t*)Address);

    /* Compare the read address with the virtual address */

    if (AddressValue == VirtAddress)

    {

      /* Get content of Address-2 which is variable value */

      *Data = (*(__IO uint16_t*)(Address - 2));

      /* In case variable value is read, reset ReadStatus flag */

      ReadStatus = 0;

      break;

    }

    else

    {

      /* Next address location */

      Address = Address - 4;

    }

  }

  /* Return ReadStatus value: (0: variable exist, 1: variable doesn't exist) */

  return ReadStatus;

}

and i just take this out

 /* Get content of Address-2 which is variable value */

      *Data = (*(__IO uint16_t*)(Address - 2));

//=========

i search from internet but no example show the eeprom read.

it would be great if someone help.

Thanks

Jeff