Exemplo n.º 1
0
/**
  * @brief How to Read / Write / Erase one Byte on FLASH memory.
  * @par   Examples description
  *        - Read one byte at address 0x40A5
  *        - Write its complement value at adress + 1
  *        - Check programed value
  *        - Erase 2 byte (address 40A5 & 40A6)
  *        - Check the 2 bytes value is 0x00.
  * @param  None
  * @retval None
  */
void main(void)
{

    uint8_t val = 0x00, val_comp = 0x00;
    uint32_t add = 0x00;

    /* Define FLASH programming time */
    FLASH_SetProgrammingTime(FLASH_PROGRAMTIME_STANDARD);

    /* Unlock Data memory */
    FLASH_Unlock(FLASH_MEMTYPE_DATA);

    /* Read a byte at a specified address */
    add = 0x40A5;
    val = FLASH_ReadByte(add);

    /* Program complement value (of previous read byte) at previous address + 1 */
    val_comp = (uint8_t)(~val);
    FLASH_ProgramByte((add + 1), val_comp);

    /* Check program action */
    val = FLASH_ReadByte((add + 1));
    if (val != val_comp)
    {
        /* Error */
        OperationStatus = FAILED;
        /* OperationStatus = PASSED, if the data written/read to/from DATA EEPROM memory is correct */
        /* OperationStatus = FAILED, if the data written/read to/from DATA EEPROM memory is corrupted */
        while (1)
        {
        }
    }

    /* Erase byte at a specified address & address + 1 */
    FLASH_EraseByte(add);
    FLASH_EraseByte((add + 1));
    /* Erase action */
    val = FLASH_ReadByte(add);
    val_comp = FLASH_ReadByte((add + 1));
    if ((val != 0x00) & (val_comp != 0x00))
    {
        /* Error */
        OperationStatus = FAILED;
        /* OperationStatus = PASSED, if the data written/read to/from DATA EEPROM memory is correct */
        /* OperationStatus = FAILED, if the data written/read to/from DATA EEPROM memory is corrupted */
        while (1)
        {
        }
    }

    /* Pass */
    OperationStatus = PASSED;
    /* OperationStatus = PASSED, if the data written/read to/from DATA EEPROM memory is correct */
    /* OperationStatus = FAILED, if the data written/read to/from DATA EEPROM memory is corrupted */
    while (1)
    {
    }
}
Exemplo n.º 2
0
void BTN1_Released()
{
  if(BTN1_press_timer < BTN1_DELETE_ID_THR)
  {
    /* Button press was shorter than 3 seconds */
    if(!LrnModeActive)
    {
      if(Receivers.NumLrndRcv < MAX_NUM_RECEIVERS)
      {
        LrnModeActive = TRUE;
        BLINK_GREENLED(255);
      }
      else
      {
        BLINK_REDLED(2);
      }
    }
    else
    {
      LrnModeActive = FALSE;
      BLINKSTOP_GREENLED;
    }
  }
  else
  {
    /* Button press was longer than 3 seconds */
    u8 i;
    u8* adr;
    LED_RED_ON;
    flash_erase_timing_test = 1;
    FLASH_Unlock(FLASH_MemType_Program);
    adr = (u8*)&Receivers;
    for(i = 0; i < sizeof(Receivers); i++)
    {
      FLASH_EraseByte((u16)(adr++));
    }
    FLASH_Lock(FLASH_MemType_Program);
    flash_erase_timing_test = 2;
    /* Check if erase was successfull */
    Errors_ResetError(ERROR_FLASH_ERASE);
    adr = (u8*)&Receivers;
    for(i = 0; i < sizeof(Receivers); i++)
    {
      if(*(adr++))
      {
        Errors_SetError(ERROR_FLASH_ERASE);
        break;
      }
    }
    flash_erase_timing_test = 3;
    LED_OFF;
  }
  BTN1_press_timer = 0;
}
Exemplo n.º 3
0
void write_array_to_eeprom(uint32_t addr,uint8_t* array)
{
      uint8_t i = 0;
      while(array[i] != '\0')
      {
        FLASH_EraseByte(addr);
        FLASH_ProgramByte((addr),array[i]);
        addr++;
        i++;
      }
}