Ejemplo n.º 1
0
/**
  * @brief  Programs the 8-bit EEPROM memory value.
  * @param  Address: The EEPROM memory byte address.
  * @param  BankSelector: Selects EEPROM Bank (Main Bank or Information Bank).
  *         This parameter can be one of the following values:
  *           @arg EEPROM_Main_Bank_Select:      The EEPROM Main Bank selector.
  *           @arg EEPROM_Info_Bank_Select:      The EEPROM Information Bank selector.
  * @param  Data: The data value to be programmed.
  * @retval None
  */
__RAMFUNC void EEPROM_ProgramByte(uint32_t Address, uint32_t BankSelector, uint32_t Data)
{
  uint32_t Mask;
  uint32_t Tmp;
  uint32_t Shift;

  assert_param(IS_EEPROM_BANK_SELECTOR(BankSelector));

  Shift = (Address & 3) * 8;
  Data = Data << Shift;
  Mask = 0xFF << Shift;
  Tmp = EEPROM_ReadWord(Address, BankSelector);
  EEPROM_ProgramWord(Address, BankSelector, (Tmp & ~Mask) | (Data & Mask));
}
Ejemplo n.º 2
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
void main (void)
{
uint32_t Address;
uint32_t BankSelector;
uint32_t Data;
int i;
uint8_t EraseErrMM=0;
uint8_t WriteErrMM=0;
uint8_t EraseErrIM=0;
uint8_t WriteErrIM=0;

  /* Enables the clock on PORTD */
  RST_CLK_PCLKcmd(RST_CLK_PCLK_PORTD, ENABLE);

  /* Enables the  clock on EEPROM */
  RST_CLK_PCLKcmd(RST_CLK_PCLK_EEPROM, ENABLE);

  /* Configure PORTD pins 10..14 for output to switch LEDs on/off */
  PORT_InitStructure.PORT_Pin   = (PORT_Pin_10 | PORT_Pin_11 | PORT_Pin_12 | PORT_Pin_13 | PORT_Pin_14);
  PORT_InitStructure.PORT_OE    = PORT_OE_OUT;
  PORT_InitStructure.PORT_FUNC  = PORT_FUNC_PORT;
  PORT_InitStructure.PORT_MODE  = PORT_MODE_DIGITAL;
  PORT_InitStructure.PORT_SPEED = PORT_SPEED_SLOW;
  PORT_Init(MDR_PORTD, &PORT_InitStructure);

  /* Erase main memory page 0 */
  Address = 0x08000000;
  BankSelector = 0;
  EEPROM_ErasePage (Address,BankSelector);

  /* Check main memory page 0 */
  Data = 0xFFFFFFFF;
  for (i=0;i<1024;i++)
  {
    if (EEPROM_ReadWord (Address+i*4,BankSelector) != Data) EraseErrMM = 1;
  }

  /* Indicate status of erasing main memory page 0*/
  if (EraseErrMM == 0)
  {
    PORT_SetBits(MDR_PORTD, PORT_Pin_10);
  }

  /* Fill main memory page 0 */
  Address = 0x08000000;
  BankSelector = 0;
  for (i=0;i<1024;i++)
  {
    Data = Pseudo_Rand (Address+i*4);
    EEPROM_ProgramWord (Address+i*4,BankSelector,Data);
  }

  /* Check main memory page 0 */
  Address = 0x08000000; BankSelector = 0;
  for (i=0;i<1024;i++)
  {
    Data = Pseudo_Rand (Address+i*4);
    if (EEPROM_ReadWord (Address+i*4,BankSelector) != Data)
    {
      WriteErrMM = 1;
    }
  }

  /* Indicate status of writing main memory page 0*/
  if (WriteErrMM == 0)
  {
    PORT_SetBits(MDR_PORTD, PORT_Pin_11);
  }

  /* Full Erase information memory */
  Address = 0x08000000;
  BankSelector = 1;
  EEPROM_EraseAllPages (BankSelector);

  /* Check information memory */
  Data = 0xFFFFFFFF;
  for (i=0;i<1024;i++)
  {
    if (EEPROM_ReadWord (Address+i*4,BankSelector) != Data)
    {
      EraseErrIM = 1;
    }
  }
  /* Indicate status of erasing information memory */
  if (EraseErrIM == 0)
  {
    PORT_SetBits(MDR_PORTD, PORT_Pin_12);
  }

  /* fill information memory */
  Address = 0x08000000;
  BankSelector = 1;
  for (i=0;i<1024;i++)
  {
    Data = Pseudo_Rand (Address+i*4);
    EEPROM_ProgramWord (Address+i*4,BankSelector,Data);
  }

  /* Check information memory */
  Address = 0x08000000;
  BankSelector = 1;
  for (i=0;i<1024;i++)
  {
    Data = Pseudo_Rand (Address+i*4);
    if(EEPROM_ReadWord (Address+i*4,BankSelector) != Data)
    {
      WriteErrIM = 1;
    }
  }

  /* Indicate status of writing information memory */
  if (WriteErrIM == 0)
  {
    PORT_SetBits(MDR_PORTD, PORT_Pin_13);
  }

  while (1)
  {
  }
}