/**
* @brief  This function will erase the memory region.
* @param  uint32_t *NVMparam: The pointer to the memory region.
*         uint8_t Wordlength: The word length.
* @retval None
*/
void WMBus_PhyEraseNVMParam(uint32_t *NVMparam, uint8_t Wordlength)
{
  DATA_EEPROM_Unlock();
  for(uint8_t temp=0x00; temp<Wordlength;temp++)
    DATA_EEPROM_EraseWord(((uint32_t)EEPROM_NVM_BASE)+temp);
  DATA_EEPROM_Lock();
}
/**
* @brief  This function writes data to internal EEPROM.
* @param  uint8_t *NVMparam: The pointer to the data to be written.
*         - uint8_t length: The length of the data to be written.  
* @retval None.
*/
void WMBus_PhyWriteNVMParam(uint8_t *NVMparam, uint8_t length)
{
  DATA_EEPROM_Unlock();
  for(uint8_t temp=0x00; temp<length;temp++)
    DATA_EEPROM_ProgramByte(EEPROM_NVM_BASE+temp, *(NVMparam+temp));
  DATA_EEPROM_Lock();
}
예제 #3
0
void Internal_EE_Write8(uint16_t position, uint8_t data){
	DATA_EEPROM_Unlock();
	FLASH_ClearFlag(FLASH_FLAG_EOP|FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR
                  | FLASH_FLAG_SIZERR | FLASH_FLAG_OPTVERR | FLASH_FLAG_OPTVERRUSR);	
	DATA_EEPROM_ProgramByte(INTERNAL_8BIT_START_ADDRESS+position, data);
	DATA_EEPROM_Lock();
}
예제 #4
0
파일: eeprom.c 프로젝트: htol/ultramicron
//**************************************************************************
void eeprom_erase(void)
{
  DATA_EEPROM_Unlock(); // разблокировка перед записью
  
  /* Clear all pending flags */      
  FLASH_ClearFlag(FLASH_FLAG_EOP|FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR
                  | FLASH_FLAG_SIZERR | FLASH_FLAG_OPTVERR | FLASH_FLAG_OPTVERRUSR);	
  
  /*  Data EEPROM Fast Word program of FAST_DATA_32 at addresses defined by 
  DATA_EEPROM_START_ADDR and DATA_EEPROM_END_ADDR */  
  Address = DATA_EEPROM_START_ADDR;
  
  NbrOfPage = ((DATA_EEPROM_END_ADDR - Address) + 1 ) >> 2; 
  
  /* Erase the Data EEPROM Memory pages by Word (32-bit) */
  for(j = 0; j < NbrOfPage; j++)
  {
    FLASHStatus = DATA_EEPROM_EraseWord(Address + (4 * j));
  }
  DATA_EEPROM_Lock();
  
  /* Check the correctness of written data */
  while(Address < DATA_EEPROM_END_ADDR)
  {
    if(*(__IO uint32_t*)Address != 0x0)
    {
      DataMemoryProgramStatus = FAILED;
      //ОШИБКА стирания !!!!
      return;
    }
    Address = Address + 4;
  }
  
}
/**
* @brief  This function writes data to internal EEPROM.
* @param  uint8_t *buff: The pointer to the data to be written.
*         - uint16_t length: The length of the data to be written.  
* @retval None.
*/
void WMBus_WriteMeterDatabaseToEEPROM(uint8_t *buff, uint16_t length, uint32_t Saddress)
{
  DATA_EEPROM_Unlock();
  for(uint16_t temp=0x00; temp<length;temp++)
    DATA_EEPROM_ProgramByte(Saddress+temp, *(buff+temp));
  DATA_EEPROM_Lock();
}
예제 #6
0
void Internal_EE_Erase8(uint16_t position){
	DATA_EEPROM_Unlock();
	/* Clear all pending flags */      
  FLASH_ClearFlag(FLASH_FLAG_EOP|FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR
                  | FLASH_FLAG_SIZERR | FLASH_FLAG_OPTVERR | FLASH_FLAG_OPTVERRUSR);	
	DATA_EEPROM_EraseByte(INTERNAL_8BIT_START_ADDRESS+position);
	DATA_EEPROM_Lock();
}
/**
* @brief  This function will erase the memory region.
* @param  uint32_t Saddress: The strating address to perform action on.
*         uint8_t length: The data length to be deleted.
* @retval None
*/
void WMBus_EraseMeterDatabaseFromEEPROM1(uint32_t Saddress, uint8_t Wordlength)
{
  DATA_EEPROM_Unlock();
  for(uint8_t temp=0x00; temp<Wordlength;temp++)
  {
    DATA_EEPROM_EraseWord(((uint32_t)Saddress)+(temp*4));
  }
  
  DATA_EEPROM_Lock();
}
예제 #8
0
파일: flash.c 프로젝트: agent-0007/H4ck33D
/* flash unlock */
void FLASH_Unlock(void)
{
	if (FLASH->PECR & FLASH_PECR_PRGLOCK) {
		/* Unlocking the data memory and FLASH_PECR register access */
		DATA_EEPROM_Unlock();

		/* Unlocking the program memory access */
		FLASH->PRGKEYR = FLASH_PRGKEY1;
		FLASH->PRGKEYR = FLASH_PRGKEY2;
	}
}
예제 #9
0
파일: flash.c 프로젝트: agent-0007/H4ck33D
/* unlock option bytes */
void FLASH_OB_Unlock(void)
{
	if (FLASH->PECR & FLASH_PECR_OPTLOCK) {
		/* Unlocking the data memory and FLASH_PECR register access */
		DATA_EEPROM_Unlock();

		/* Unlocking the option bytes block access */
		FLASH->OPTKEYR = FLASH_OPTKEY1;
		FLASH->OPTKEYR = FLASH_OPTKEY2;
	}
}
예제 #10
0
void Internal_EE_EraseM8(uint16_t start_position, uint16_t NbrOfPositions){
	uint16_t i = 0;
	DATA_EEPROM_Unlock();
	/* Clear all pending flags */      
  FLASH_ClearFlag(FLASH_FLAG_EOP|FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR
                  | FLASH_FLAG_SIZERR | FLASH_FLAG_OPTVERR | FLASH_FLAG_OPTVERRUSR);	
	for(i=0; i<NbrOfPositions; i++){
		DATA_EEPROM_EraseByte(INTERNAL_8BIT_START_ADDRESS+start_position+i);
	}
	DATA_EEPROM_Lock();
}
예제 #11
0
/** 
 ===============================================================================
              ##### 8 BITS #####
 ===============================================================================
 */
void Internal_EE_EraseAll8(void){
	uint16_t i = 0;
	uint16_t NbrOfPagesToErase = 0;
	NbrOfPagesToErase = ((INTERNAL_8BIT_END_ADDRESS - INTERNAL_8BIT_START_ADDRESS)+1)>>2;
	DATA_EEPROM_Unlock();
	FLASH_ClearFlag(FLASH_FLAG_EOP|FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR
                  | FLASH_FLAG_SIZERR | FLASH_FLAG_OPTVERR | FLASH_FLAG_OPTVERRUSR);
	for(i = 0; i<NbrOfPagesToErase; i++){
		DATA_EEPROM_EraseWord(INTERNAL_8BIT_START_ADDRESS+4*i);
	}
	DATA_EEPROM_Lock();
}
예제 #12
0
/**
  * @brief  Writes selected block of option structure memory to EEPROM.
  * @param  offset: beginning of block to write, length of block.
  * @retval void
  */
void WriteBlock(uint16_t offset, uint8_t len)
{
   uint8_t i;
   uint32_t eeprom_addr = DATA_EEPROM_START_ADDR + offset;
   uint8_t* ram_addr    = (uint8_t*)&options + offset;

   DATA_EEPROM_Unlock();
   for (i=0; i<len; i++)                                 // Erase
     DATA_EEPROM_EraseByte(eeprom_addr+i);
   for (i=0; i<len; i++)                                 // Program
     DATA_EEPROM_ProgramByte(eeprom_addr+i, *ram_addr++);
   DATA_EEPROM_Lock();
}
예제 #13
0
void Internal_EE_WriteM8(uint16_t start_position, uint8_t* data, uint16_t length){
	uint16_t i = 0;
	__IO FLASH_Status FLASHStatus = FLASH_COMPLETE;
	DATA_EEPROM_Unlock();
	FLASH_ClearFlag(FLASH_FLAG_EOP|FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR
                  | FLASH_FLAG_SIZERR | FLASH_FLAG_OPTVERR | FLASH_FLAG_OPTVERRUSR);	
	while(i<length){
		FLASHStatus = DATA_EEPROM_ProgramByte(INTERNAL_8BIT_START_ADDRESS+start_position+i, data[i]);
		if(FLASHStatus == FLASH_COMPLETE){
			i++;
		}else{
			FLASH_ClearFlag(FLASH_FLAG_EOP|FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR
                           | FLASH_FLAG_SIZERR | FLASH_FLAG_OPTVERR);
		}
	}
	DATA_EEPROM_Lock();
}
예제 #14
0
파일: eeprom.c 프로젝트: htol/ultramicron
void eeprom_write(uint32_t address_of_read, uint32_t data)
{
  
  DATA_EEPROM_Unlock(); // разблокировка перед записью
  
  /* Clear all pending flags */      
  FLASH_ClearFlag(FLASH_FLAG_EOP|FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR
                  | FLASH_FLAG_SIZERR | FLASH_FLAG_OPTVERR | FLASH_FLAG_OPTVERRUSR);	
  
  /*  Data EEPROM Fast Word program of FAST_DATA_32 at addresses defined by 
  DATA_EEPROM_START_ADDR and DATA_EEPROM_END_ADDR */  
  Address = DATA_EEPROM_START_ADDR+address_of_read;
  if(Address > DATA_EEPROM_END_ADDR)
  {
    // ОШИБКА вне диапазона eeprom !!!!
    DATA_EEPROM_Lock();
    return;
  }
  
  // Запись данных по адресу
  FLASHStatus = DATA_EEPROM_ProgramWord(Address, data);
  DATA_EEPROM_Lock();  
  
  if(FLASHStatus != FLASH_COMPLETE)
  {
    // ОШИБКА записи eeprom !!!!
    return;
  }
  FLASH_ClearFlag(FLASH_FLAG_EOP|FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR
                  | FLASH_FLAG_SIZERR | FLASH_FLAG_OPTVERR);
  
  
  // Проверка записанных данных 
  if(*(__IO uint32_t*)Address != data)
  {
    DataMemoryProgramStatus = FAILED;
    // ОШИБКА записи !!!!!
    return;
  }
  
  
  
}
예제 #15
0
파일: main.c 프로젝트: david-kooi/eval
/**
  * @brief  Function used to reset the DFU MODE flag on E2PROM.
  * @param  None
  * @retval None
  */
void SdkDfuResetDfuFlag(void){

  /* Unlock the FLASH PECR register and Data EEPROM memory */
  DATA_EEPROM_Unlock();

  /* Clear all pending flags */
  FLASH_ClearFlag(FLASH_FLAG_EOP|FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR
                  | FLASH_FLAG_SIZERR | FLASH_FLAG_OPTVERR);

  /* Write 0 on the E2PROM data address 0x08080000 */
  FLASH_Status FLASHStatus = DATA_EEPROM_ProgramByte(DATA_EEPROM_START_ADDR, 0);

  /* Clear all the Flash flags */
  if(FLASHStatus != FLASH_COMPLETE)
    FLASH_ClearFlag(FLASH_FLAG_EOP|FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR
                    | FLASH_FLAG_SIZERR | FLASH_FLAG_OPTVERR);


  /* Lock the FLASH PECR register and Data EEPROM memory */
  DATA_EEPROM_Lock();

}
예제 #16
0
ot_u8 vworm_write(vaddr addr, ot_u16 data) {
    ot_u32 Address;
    FLASH_Status status;

#ifdef RADIO_DEBUG   // 18
    debug_printf("vworm_write(%x, %x)\r\n", addr, data);
#endif /* RADIO_DEBUG */
    DATA_EEPROM_Unlock();

    /* Clear all pending flags */
    FLASH_ClearFlag(FLASH_FLAG_EOP|FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR |
                            FLASH_FLAG_SIZERR | FLASH_FLAG_OPTVERR);
    Address = EEPROM_START_ADDR + addr;
    status = DATA_EEPROM_ProgramHalfWord(Address, data);

    DATA_EEPROM_Lock();

    if (status == FLASH_COMPLETE)
        return 0;
    else
        return 1;   // return non-zero on fault
}
예제 #17
0
파일: adc.c 프로젝트: tarasii/BMP085
void  writeCalibData(CALIB_TypeDef* calibStruct)
{
	__IO FLASH_Status FLASHStatus = FLASH_COMPLETE; 

  uint32_t  Address = 0;
  uint32_t  dataToWrite;
  
  /* Unlock the FLASH PECR register and Data EEPROM memory */
  DATA_EEPROM_Unlock();
  
  /* Clear all pending flags */      
  FLASH_ClearFlag(FLASH_FLAG_EOP|FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR
                  | FLASH_FLAG_SIZERR | FLASH_FLAG_OPTVERR);	
  
  /*  Data EEPROM Fast Word program of FAST_DATA_32 at addresses defined by 
      DATA_EEPROM_START_ADDR and DATA_EEPROM_END_ADDR */  
 
  Address = (uint32_t) USER_CALIB_DATA;


  dataToWrite = 0x00;
  dataToWrite = (uint32_t)(calibStruct->TS_CAL_COLD) << 16;
  
  FLASHStatus = DATA_EEPROM_ProgramWord(Address, dataToWrite);

  if(FLASHStatus != FLASH_COMPLETE)
  {
    while(1); /* stay in loop in case of crittical programming error */
  }

  Address += 4;

  dataToWrite = 0x00;
  dataToWrite = (uint32_t)(calibStruct->TS_CAL_HOT) << 16;
  
  FLASHStatus = DATA_EEPROM_ProgramWord(Address, dataToWrite);
  
}
예제 #18
0
/**
  * @brief  Function stores all options in EEPROM memory.
  * @param  void
  * @retval verification status
  */
uint8_t WriteOptions(void)
{
   uint16_t i;
   uint32_t eeprom_addr = DATA_EEPROM_START_ADDR;
   uint8_t* ram_addr    = (uint8_t*)&options;
   uint8_t  options_len = sizeof(options);
   uint8_t  ver_status  = 0;
   //FLASH_Status FLASHStatus = FLASH_COMPLETE;

   DATA_EEPROM_Unlock();                                                   // Unlock the FLASH PECR register and Data EEPROM memory
   FLASH_ClearFlag(FLASH_FLAG_EOP|FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR    // Clear all pending flags
                  | FLASH_FLAG_SIZERR | FLASH_FLAG_OPTVERR | FLASH_FLAG_OPTVERRUSR);

   for (i=0; i<options_len; i++)                                           // Erase
     DATA_EEPROM_EraseByte(eeprom_addr+i);
   for (i=0; i<options_len; i++)                                           // Program
     DATA_EEPROM_ProgramByte(eeprom_addr+i, *ram_addr++);
   ram_addr = (uint8_t*)&options;
   for (i=0; i<options_len; i++)                                           // Verify
   { if (*ram_addr++ != *(uint8_t*)(eeprom_addr+i)) ver_status = 1; }

   DATA_EEPROM_Lock();
   return ver_status;
}
/**
* @brief  This function will erase the memory region.
* @param  uint32_t Saddress: The strating address to perform action on.
*         uint8_t length: The data length to be deleted.
* @retval None
*/
void WMBus_EraseMeterDatabaseFromEEPROM(uint8_t *buff, uint32_t Saddress, uint8_t Wordlength)
{
  for(uint8_t eeindex=0; eeindex<10; eeindex++)
  {
    switch(eeindex)
    {
    case 0:
      WMBus_PhyReadMeterDatabase(EEPROM_METER1_DATABASE_START,26, EEPROM_METER1_DATABASE_END);
      if(EEpromMtrData[0] == buff[0])
      {
        Saddress = EEPROM_METER1_DATABASE_START;
        DATA_EEPROM_Unlock();
        for(uint8_t temp=0x00; temp<Wordlength;temp++)
        {
          DATA_EEPROM_EraseWord(((uint32_t)Saddress)+(temp*4));
        }
        DATA_EEPROM_Lock();
        return;
      }
      break;
    case 1:
      WMBus_PhyReadMeterDatabase(EEPROM_METER2_DATABASE_START, 26, EEPROM_METER2_DATABASE_END);
      if(EEpromMtrData[0] == buff[0])
      {
        Saddress = EEPROM_METER2_DATABASE_START;
        DATA_EEPROM_Unlock();
        for(uint8_t temp=0x00; temp<Wordlength;temp++)
        {
          DATA_EEPROM_EraseWord(((uint32_t)Saddress)+(temp*4));
        }
        DATA_EEPROM_Lock();
        return;
      }
      break;
    case 2:
      WMBus_PhyReadMeterDatabase(EEPROM_METER3_DATABASE_START, 26, EEPROM_METER3_DATABASE_END);
      if(EEpromMtrData[0] == buff[0])
      {
        Saddress = EEPROM_METER3_DATABASE_START;
        DATA_EEPROM_Unlock();
        for(uint8_t temp=0x00; temp<Wordlength;temp++)
        {
          DATA_EEPROM_EraseWord(((uint32_t)Saddress)+(temp*4));
        }
        DATA_EEPROM_Lock();
        return;
      }
      break;
    case 3:
      WMBus_PhyReadMeterDatabase(EEPROM_METER4_DATABASE_START, 26, EEPROM_METER4_DATABASE_END);
      if(EEpromMtrData[0] == buff[0])
      {
        Saddress = EEPROM_METER4_DATABASE_START;
        DATA_EEPROM_Unlock();
        for(uint8_t temp=0x00; temp<Wordlength;temp++)
        {
          DATA_EEPROM_EraseWord(((uint32_t)Saddress)+(temp*4));
        }
        DATA_EEPROM_Lock();
        return;
      }
      break;
    case 4:
      WMBus_PhyReadMeterDatabase(EEPROM_METER5_DATABASE_START, 26, EEPROM_METER5_DATABASE_END);
      if(EEpromMtrData[0] == buff[0])
      {
        Saddress = EEPROM_METER5_DATABASE_START;
        DATA_EEPROM_Unlock();
        for(uint8_t temp=0x00; temp<Wordlength;temp++)
        {
          DATA_EEPROM_EraseWord(((uint32_t)Saddress)+(temp*4));
        }
        DATA_EEPROM_Lock();
        return;
      }
      break;
    case 5:
      WMBus_PhyReadMeterDatabase(EEPROM_METER6_DATABASE_START, 26, EEPROM_METER6_DATABASE_END);
      if(EEpromMtrData[0] == buff[0])
      {
        Saddress = EEPROM_METER6_DATABASE_START;
        DATA_EEPROM_Unlock();
        for(uint8_t temp=0x00; temp<Wordlength;temp++)
        {
          DATA_EEPROM_EraseWord(((uint32_t)Saddress)+(temp*4));
        }
        DATA_EEPROM_Lock();
        return;
      }
      break;
    case 6:
      WMBus_PhyReadMeterDatabase(EEPROM_METER7_DATABASE_START, 26, EEPROM_METER7_DATABASE_END);
      if(EEpromMtrData[0] == buff[0])
      {
        Saddress = EEPROM_METER7_DATABASE_START;
        DATA_EEPROM_Unlock();
        for(uint8_t temp=0x00; temp<Wordlength;temp++)
        {
          DATA_EEPROM_EraseWord(((uint32_t)Saddress)+(temp*4));
        }
        DATA_EEPROM_Lock();
        return;
      }
      break;
    case 7:
      WMBus_PhyReadMeterDatabase(EEPROM_METER8_DATABASE_START, 26, EEPROM_METER8_DATABASE_END);
      if(EEpromMtrData[0] == buff[0])
      {
        Saddress = EEPROM_METER8_DATABASE_START;
        DATA_EEPROM_Unlock();
        for(uint8_t temp=0x00; temp<Wordlength;temp++)
        {
          DATA_EEPROM_EraseWord(((uint32_t)Saddress)+(temp*4));
        }
        DATA_EEPROM_Lock();
        return;
      }
      break;
    case 8:
      WMBus_PhyReadMeterDatabase(EEPROM_METER9_DATABASE_START, 26, EEPROM_METER9_DATABASE_END);
      if(EEpromMtrData[0] == buff[0])
      {
        Saddress = EEPROM_METER9_DATABASE_START;
        DATA_EEPROM_Unlock();
        for(uint8_t temp=0x00; temp<Wordlength;temp++)
        {
          DATA_EEPROM_EraseWord(((uint32_t)Saddress)+(temp*4));
        }
        DATA_EEPROM_Lock();
        return;
      }
      break;
    case 9:
      WMBus_PhyReadMeterDatabase(EEPROM_METER_10_DATABASE_START, 26, EEPROM_METER_10_DATABASE_END);
      if(EEpromMtrData[0] == buff[0])
      {
        Saddress = EEPROM_METER_10_DATABASE_START;
        DATA_EEPROM_Unlock();
        for(uint8_t temp=0x00; temp<Wordlength;temp++)
        {
          DATA_EEPROM_EraseWord(((uint32_t)Saddress)+(temp*4));
        }
        DATA_EEPROM_Lock();
        return;
      }
      break;      
    default:
      break;
    }
  }
}
/**
* @brief  This function writes data to internal EEPROM.
* @param  uint8_t *buff: The pointer to the data to be written.
*         - uint16_t length: The length of the data to be written.  
* @retval None.
*/
void WMBus_PhyWriteMeterDatabase(uint8_t *buff, uint16_t length, uint32_t Saddress)
{
  for(uint8_t eindex=0; eindex<10; eindex++)
  {
    switch(eindex)
    {
    case 0:
      WMBus_PhyReadMeterDatabase(EEPROM_METER1_DATABASE_START,26, EEPROM_METER1_DATABASE_END);
      if(EEpromMtrData[0] == buff[0])
      {
        Saddress = EEPROM_METER1_DATABASE_START;
        DATA_EEPROM_Unlock();
        for(uint16_t temp=0x00; temp<length;temp++)
          DATA_EEPROM_ProgramByte(Saddress+temp, *(buff+temp));
        DATA_EEPROM_Lock();
        return;
      }
      if((!EEpromMtrData[0])&&(!EEpromMtrData[1]))
      {
        Saddress = EEPROM_METER1_DATABASE_START;
        DATA_EEPROM_Unlock();
        for(uint16_t temp=0x00; temp<length;temp++)
          DATA_EEPROM_ProgramByte(Saddress+temp, *(buff+temp));
        DATA_EEPROM_Lock();
        return;
      }
      break;
    case 1:
      WMBus_PhyReadMeterDatabase(EEPROM_METER2_DATABASE_START, 26, EEPROM_METER2_DATABASE_END);
      if(EEpromMtrData[0] == buff[0])
      {
        Saddress = EEPROM_METER2_DATABASE_START;
        DATA_EEPROM_Unlock();
        for(uint16_t temp=0x00; temp<length;temp++)
          DATA_EEPROM_ProgramByte(Saddress+temp, *(buff+temp));
        DATA_EEPROM_Lock();
        return;
      }
      if((!EEpromMtrData[0])&&(!EEpromMtrData[1]))
      {
        Saddress = EEPROM_METER2_DATABASE_START;
        DATA_EEPROM_Unlock();
        for(uint16_t temp=0x00; temp<length;temp++)
          DATA_EEPROM_ProgramByte(Saddress+temp, *(buff+temp));
        DATA_EEPROM_Lock();
        return;
      }
      break;
    case 2:
      WMBus_PhyReadMeterDatabase(EEPROM_METER3_DATABASE_START, 26, EEPROM_METER3_DATABASE_END);
      if(EEpromMtrData[0] == buff[0])
      {
        Saddress = EEPROM_METER3_DATABASE_START;
        DATA_EEPROM_Unlock();
        for(uint16_t temp=0x00; temp<length;temp++)
          DATA_EEPROM_ProgramByte(Saddress+temp, *(buff+temp));
        DATA_EEPROM_Lock();
        return;
      }
      if((!EEpromMtrData[0])&&(!EEpromMtrData[1]))
      {
        Saddress = EEPROM_METER3_DATABASE_START;
        DATA_EEPROM_Unlock();
        for(uint16_t temp=0x00; temp<length;temp++)
          DATA_EEPROM_ProgramByte(Saddress+temp, *(buff+temp));
        DATA_EEPROM_Lock();
        return;
      }
      break;
    case 3:
      WMBus_PhyReadMeterDatabase(EEPROM_METER4_DATABASE_START, 26, EEPROM_METER4_DATABASE_END);
      if(EEpromMtrData[0] == buff[0])
      {
        Saddress = EEPROM_METER4_DATABASE_START;
        DATA_EEPROM_Unlock();
        for(uint16_t temp=0x00; temp<length;temp++)
          DATA_EEPROM_ProgramByte(Saddress+temp, *(buff+temp));
        DATA_EEPROM_Lock();
        return;
      }
      if((!EEpromMtrData[0])&&(!EEpromMtrData[1]))
      {
        Saddress = EEPROM_METER4_DATABASE_START;
        DATA_EEPROM_Unlock();
        for(uint16_t temp=0x00; temp<length;temp++)
          DATA_EEPROM_ProgramByte(Saddress+temp, *(buff+temp));
        DATA_EEPROM_Lock();
        return;
      }
      break;
    case 4:
      WMBus_PhyReadMeterDatabase(EEPROM_METER5_DATABASE_START, 26, EEPROM_METER5_DATABASE_END);
      if(EEpromMtrData[0] == buff[0])
      {
        Saddress = EEPROM_METER5_DATABASE_START;
        DATA_EEPROM_Unlock();
        for(uint16_t temp=0x00; temp<length;temp++)
          DATA_EEPROM_ProgramByte(Saddress+temp, *(buff+temp));
        DATA_EEPROM_Lock();
        return;
      }
      if((!EEpromMtrData[0])&&(!EEpromMtrData[1]))
      {
        Saddress = EEPROM_METER5_DATABASE_START;
        DATA_EEPROM_Unlock();
        for(uint16_t temp=0x00; temp<length;temp++)
          DATA_EEPROM_ProgramByte(Saddress+temp, *(buff+temp));
        DATA_EEPROM_Lock();
        return;
      }
      break;
    case 5:
      WMBus_PhyReadMeterDatabase(EEPROM_METER6_DATABASE_START, 26, EEPROM_METER6_DATABASE_END);
      if(EEpromMtrData[0] == buff[0])
      {
        Saddress = EEPROM_METER6_DATABASE_START;
        DATA_EEPROM_Unlock();
        for(uint16_t temp=0x00; temp<length;temp++)
          DATA_EEPROM_ProgramByte(Saddress+temp, *(buff+temp));
        DATA_EEPROM_Lock();
        return;
      }
      if((!EEpromMtrData[0])&&(!EEpromMtrData[1]))
      {
        Saddress = EEPROM_METER6_DATABASE_START;
        DATA_EEPROM_Unlock();
        for(uint16_t temp=0x00; temp<length;temp++)
          DATA_EEPROM_ProgramByte(Saddress+temp, *(buff+temp));
        DATA_EEPROM_Lock();
        return;
      }
      break;
    case 6:
      WMBus_PhyReadMeterDatabase(EEPROM_METER7_DATABASE_START, 26, EEPROM_METER7_DATABASE_END);
      if(EEpromMtrData[0] == buff[0])
      {
        Saddress = EEPROM_METER7_DATABASE_START;
        DATA_EEPROM_Unlock();
        for(uint16_t temp=0x00; temp<length;temp++)
          DATA_EEPROM_ProgramByte(Saddress+temp, *(buff+temp));
        DATA_EEPROM_Lock();
        return;
      }
      if((!EEpromMtrData[0])&&(!EEpromMtrData[1]))
      {
        Saddress = EEPROM_METER7_DATABASE_START;
        DATA_EEPROM_Unlock();
        for(uint16_t temp=0x00; temp<length;temp++)
          DATA_EEPROM_ProgramByte(Saddress+temp, *(buff+temp));
        DATA_EEPROM_Lock();
        return;
      }      
      break;    
    case 7:
      WMBus_PhyReadMeterDatabase(EEPROM_METER8_DATABASE_START, 26, EEPROM_METER8_DATABASE_END);
      if(EEpromMtrData[0] == buff[0])
      {
        Saddress = EEPROM_METER8_DATABASE_START;
        DATA_EEPROM_Unlock();
        for(uint16_t temp=0x00; temp<length;temp++)
          DATA_EEPROM_ProgramByte(Saddress+temp, *(buff+temp));
        DATA_EEPROM_Lock();
        return;
      }
      if((!EEpromMtrData[0])&&(!EEpromMtrData[1]))
      {
        Saddress = EEPROM_METER8_DATABASE_START;
        DATA_EEPROM_Unlock();
        for(uint16_t temp=0x00; temp<length;temp++)
          DATA_EEPROM_ProgramByte(Saddress+temp, *(buff+temp));
        DATA_EEPROM_Lock();
        return;
      }      
      break;
    case 8:
      WMBus_PhyReadMeterDatabase(EEPROM_METER9_DATABASE_START, 26, EEPROM_METER9_DATABASE_END);
      if(EEpromMtrData[0] == buff[0])
      {
        Saddress = EEPROM_METER9_DATABASE_START;
        DATA_EEPROM_Unlock();
        for(uint16_t temp=0x00; temp<length;temp++)
          DATA_EEPROM_ProgramByte(Saddress+temp, *(buff+temp));
        DATA_EEPROM_Lock();
        return;
      }
      if((!EEpromMtrData[0])&&(!EEpromMtrData[1]))
      {
        Saddress = EEPROM_METER9_DATABASE_START;
        DATA_EEPROM_Unlock();
        for(uint16_t temp=0x00; temp<length;temp++)
          DATA_EEPROM_ProgramByte(Saddress+temp, *(buff+temp));
        DATA_EEPROM_Lock();
        return;
      }      
      break;
    case 9:
      WMBus_PhyReadMeterDatabase(EEPROM_METER_10_DATABASE_START, 26, EEPROM_METER_10_DATABASE_END);
      if(EEpromMtrData[0] == buff[0])
      {
        Saddress = EEPROM_METER_10_DATABASE_START;
        DATA_EEPROM_Unlock();
        for(uint16_t temp=0x00; temp<length;temp++)
          DATA_EEPROM_ProgramByte(Saddress+temp, *(buff+temp));
        DATA_EEPROM_Lock();
        return;
      }
      if((!EEpromMtrData[0])&&(!EEpromMtrData[1]))
      {
        Saddress = EEPROM_METER_10_DATABASE_START;
        DATA_EEPROM_Unlock();
        for(uint16_t temp=0x00; temp<length;temp++)
          DATA_EEPROM_ProgramByte(Saddress+temp, *(buff+temp));
        DATA_EEPROM_Lock();
        return;
      }      
      break;      
    default:
      break;
    }
  }
}
예제 #21
0
/**
  * @brief  Reset the Bias measurement value stored in Data EEPROM.
  * @param  None
  * @retval None
  */
void IDD_Measurement_Bias_Reset(void)
{
  uint8_t pressedkey = 0;
  
  /* Disable the JoyStick interrupts */
  Demo_IntExtOnOffConfig(DISABLE);
  
  LCD_Clear(LCD_COLOR_WHITE);
  LCD_SetBackColor(LCD_COLOR_BLUE);
  LCD_SetTextColor(LCD_COLOR_WHITE);

  LCD_Clear(LCD_COLOR_WHITE);
  LCD_SetBackColor(LCD_COLOR_BLUE);
  LCD_SetTextColor(LCD_COLOR_WHITE);

  LCD_DisplayStringLine(LCD_LINE_0, "Current Bias Value  "); 
  LCD_DisplayStringLine(LCD_LINE_1, "stored in DATAEEPROM");
  IDD_Measurement_ADC_DisplayValue((*(__IO uint16_t *)DATA_EEPROM_BIAS_ADDR), STM32L_MODE_BIAS);
  LCD_DisplayStringLine(LCD_LINE_2, Str);
  LCD_DisplayStringLine(LCD_LINE_5, "  To reset Bias     ");
  LCD_DisplayStringLine(LCD_LINE_6, "measurement press   ");  
  LCD_DisplayStringLine(LCD_LINE_7, "SEL push-button.    ");    
  LCD_DisplayStringLine(LCD_LINE_8, "Press JoyStick to   ");
  LCD_DisplayStringLine(LCD_LINE_9, "exit.               ");

  pressedkey = Menu_ReadKey();
  while (pressedkey == NOKEY)
  {
    pressedkey = Menu_ReadKey();
  }
   
  if (pressedkey != SEL)
  {
    /* Enable the JoyStick interrupts */
    Demo_IntExtOnOffConfig(ENABLE);
    /* Display the previous menu */
    Menu_DisplayMenu();
    return;
  }
 
  LCD_Clear(LCD_COLOR_WHITE);

  /* Unlock EEPROM write access. */
  DATA_EEPROM_Unlock();
  
  /* Store the value in EEPROM for application needs. */
  DATA_EEPROM_ProgramHalfWord(DATA_EEPROM_BIAS_ADDR, 0x0);
  
  /* Lock back EEPROM write access. */
  DATA_EEPROM_Lock();

  LCD_DisplayStringLine(LCD_LINE_1, "  Bias Measurement  ");
  LCD_DisplayStringLine(LCD_LINE_2, " Bias Value is reset");
  LCD_DisplayStringLine(LCD_LINE_3, " to 0x0.            ");
    
  LCD_DisplayStringLine(LCD_LINE_7, "Press JoyStick to   ");
  LCD_DisplayStringLine(LCD_LINE_8, "continue.           ");

  LCD_GLASS_DisplayString(" STM32L ");
  while (Menu_ReadKey() == NOKEY)
  {}

  /* Enable the JoyStick interrupts */
  Demo_IntExtOnOffConfig(ENABLE);
  
  /* Display the previous menu */
  Menu_DisplayMenu();
}
예제 #22
0
/**
  * @brief  Enter the MCU selected low power modes.
  * @param  lpmode: selected MCU low power modes. This parameter can be one of the
  *         following values:
  *              @arg STM32L_RUN: Run mode at 32MHz.
  *              @arg STM32L_RUN_1M: Run mode at 1MHz.
  *              @arg STM32L_RUN_LP: Low power Run mode at 32KHz.  
  *              @arg STM32L_SLEEP: Sleep mode at 16MHz.
  *              @arg STM32L_SLEEP_LP: Low power Sleep mode at 32KHz.
  *              @arg STM32L_STOP: Stop mode with or without RTC.
  *              @arg STM32L_STANDBY: Standby mode with or without RTC.
  * @param  RTCState: RTC peripheral state during low power modes. This parameter
  *         is valid only for STM32L_RUN_LP, STM32L_SLEEP_LP, STM32L_STOP and
  *         STM32L_STANDBY. This parameter can be one of the following values:
  *              @arg RTC_STATE_ON: RTC peripheral is ON during low power modes.
  *              @arg RTC_STATE_OFF: RTC peripheral is OFF during low power modes.
  * @param  CalibrationState: Bias Calibration mode selection state during low 
  *         power modes. 
  *         This parameter can be one of the following values:
  *              @arg BIAS_CALIB_OFF: Bias Calibration mode is selected during 
  *                   low power modes.
  *              @arg BIAS_CALIB_ON: Bias Calibration mode isn't selected during 
  *                   low power modes.
  * @retval None
*/
void IDD_Measurement(uint32_t lpmode, uint8_t RTCState, uint8_t CalibrationState)
{
  GPIO_InitTypeDef GPIO_InitStructure;
  uint16_t mode = STM32L_MODE_LP, adcdata, i;

  /* Disable the Wakeup Interrupt */
  RTC_ITConfig(RTC_IT_WUT, DISABLE);

  /* Disable the JoyStick interrupts */
  Demo_IntExtOnOffConfig(DISABLE);

  /* Disable Leds toggling */
  Demo_LedShow(DISABLE);

  /* Save the RCC configuration */
  RCC_AHBENR   = RCC->AHBENR;
  RCC_APB2ENR  = RCC->APB2ENR;
  RCC_APB1ENR  = RCC->APB1ENR;

  /* Disable PVD */
  PWR_PVDCmd(DISABLE);

  /* Wait until JoyStick is pressed */
  while (Menu_ReadKey() != NOKEY)
  {}

  /* Save the GPIO pins current configuration then put all GPIO pins in Analog
     Input mode ...*/
  IDD_Measurement_SaveContext();

  /* Clear Wake Up flag */
  PWR_ClearFlag(PWR_FLAG_WU);

  RCC->AHBENR = 0x05;
  RCC->APB2ENR = 0x00;
  RCC->APB1ENR = 0x10000000;  /* PWR APB1 Clock enable */
  
  switch(lpmode)
  {
    /*=========================================================================*
     *                        RUN MODE 32MHz (HSE + PLL)                       *
     *========================================================================*/
    case STM32L_RUN:
    {  
      mode = STM32L_MODE_RUN;
      /* Needed delay to have a correct value on capacitor C25.
        Running NOP during waiting loop will decrease the current consumption. */
      for (i = 0;i < 0xFFFF; i++) 
      {
        __NOP();  __NOP();    __NOP();  __NOP();
        __NOP();  __NOP();    __NOP();  __NOP();
        __NOP();  __NOP();    __NOP();  __NOP();
        __NOP();  __NOP();    __NOP();  __NOP();
        __NOP();  __NOP();    __NOP();  __NOP();
        __NOP();  __NOP();    __NOP();  __NOP();
        __NOP();  __NOP();    __NOP();  __NOP();
        __NOP();  __NOP();    __NOP();  __NOP();
        __NOP();  __NOP();    __NOP();  __NOP();
        __NOP();  __NOP();    __NOP();  __NOP();
        __NOP();  __NOP();    __NOP();  __NOP();
      }
    }
    break;

    /*=========================================================================*
     *                        RUN MODE MSI 1MHz                                *
     *========================================================================*/
    case STM32L_RUN_1M:
    {      
      mode = STM32L_MODE_RUN;
      
      /* Reconfigure the System Clock at MSI 1 MHz */
      SetHCLKToMSI_1MHz();
        
      /* Needed delay to have a correct value on capacitor C25.
        Running NOP during waiting loop will decrease the current consumption. */
      for (i = 0;i < 0x3FFF; i++) 
      {
        __NOP();  __NOP();    __NOP();  __NOP();
        __NOP();  __NOP();    __NOP();  __NOP();
        __NOP();  __NOP();    __NOP();  __NOP();
        __NOP();  __NOP();    __NOP();  __NOP();
        __NOP();  __NOP();    __NOP();  __NOP();
        __NOP();  __NOP();    __NOP();  __NOP();
        __NOP();  __NOP();    __NOP();  __NOP();
        __NOP();  __NOP();    __NOP();  __NOP();
        __NOP();  __NOP();    __NOP();  __NOP();
        __NOP();  __NOP();    __NOP();  __NOP();
        __NOP();  __NOP();    __NOP();  __NOP();
      }
    }
    break;

    /*=========================================================================*
     *                        RUN LOW POWER MODE MSI 32KHz                     *
     *========================================================================*/    
    case STM32L_RUN_LP:
    {                
      if(!RTCState)
      {  
        RCC_LSEConfig(RCC_LSE_OFF);
      }
      else
      {
        if (RTC_GetFlagStatus(RTC_FLAG_INITS) == RESET)
        {
          /* RTC Configuration ************************************************/
          /* Reset RTC Domain */
          RCC_RTCResetCmd(ENABLE);
          RCC_RTCResetCmd(DISABLE);
          
          /* Enable the LSE OSC */
          RCC_LSEConfig(RCC_LSE_ON);
          
          /* Wait till LSE is ready */
          while (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)
          {}
          
          /* Select the RTC Clock Source */
          RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
          
          /* Enable the RTC Clock */
          RCC_RTCCLKCmd(ENABLE);
          
          /* Wait for RTC APB registers synchronisation */
          RTC_WaitForSynchro();
        }        
      }
      /* Configure the System Clock at MSI 32 KHz */
      SetHCLKToMSI_64KHz(); 
      RCC_HCLKConfig(RCC_SYSCLK_Div2); 
      
      /* Clear IDD_CNT_EN pin */
      GPIO_ResetBits(IDD_CNT_EN_GPIO_PORT, IDD_CNT_EN_PIN);
      
      /* Enter low power run mode */
      PWR_EnterLowPowerRunMode(ENABLE);
      
      /* Waiting wake-up interrupt */
      /* Needed delay to have a correct value on capacitor C25.
        Running NOP during waiting loop will decrease the current consumption. */
      do 
      {
        __NOP();  __NOP();    __NOP();  __NOP();
        __NOP();  __NOP();    __NOP();  __NOP();
        __NOP();  __NOP();    __NOP();  __NOP();
        __NOP();  __NOP();    __NOP();  __NOP();
        __NOP();  __NOP();    __NOP();  __NOP();
        __NOP();  __NOP();    __NOP();  __NOP();
        __NOP();  __NOP();    __NOP();  __NOP();
        __NOP();  __NOP();    __NOP();  __NOP();
        __NOP();  __NOP();    __NOP();  __NOP();
        __NOP();  __NOP();    __NOP();  __NOP();
        __NOP();  __NOP();    __NOP();  __NOP();
      }while(LowPowerStatus == 0x00);

      /* Exit low power run mode before setting the clock to 32MHz */
      PWR_EnterLowPowerRunMode(DISABLE);
      while(PWR_GetFlagStatus(PWR_FLAG_REGLP) != RESET)
      {
      }  
    }       
    break;

    /*=========================================================================*
     *                        SLEEP MODE HSI 16MHz                             * 
     *========================================================================*/        
    case STM32L_SLEEP:
    {            
      mode = STM32L_MODE_RUN;      
      /* Enable Ultra low power mode */
      PWR_UltraLowPowerCmd(ENABLE);
      
      /* Diable FLASH during SLeep LP */
      FLASH_SLEEPPowerDownCmd(ENABLE);
            
      RCC_APB2PeriphClockLPModeCmd(RCC_APB2Periph_CLOCK, ENABLE);
      RCC_APB1PeriphClockLPModeCmd(RCC_APB1Periph_CLOCK, ENABLE);
      RCC_AHBPeriphClockLPModeCmd(RCC_AHBPeriph_CLOCK, ENABLE);
      
      /* Configure the System Clock to 16MHz */
      SetHCLKToHSI();
      
      Demo_SysTickConfig();
      Demo_Delay(5);
      
      /* Request to enter SLEEP mode with regulator on */
      PWR_EnterSleepMode(PWR_Regulator_ON, PWR_STOPEntry_WFI); 
    }   
    break;

    /*=========================================================================*
     *                      SLEEP LOW POWER MODE MSI 32KHz                     *
     *========================================================================*/     
    case STM32L_SLEEP_LP:
    {            
      if(!RTCState)
      {  
        RCC_LSEConfig(RCC_LSE_OFF);
      }
      else
      {
        if (RTC_GetFlagStatus(RTC_FLAG_INITS) == RESET)
        {
          /* RTC Configuration ************************************************/
          /* Reset RTC Domain */
          RCC_RTCResetCmd(ENABLE);
          RCC_RTCResetCmd(DISABLE);
          
          /* Enable the LSE OSC */
          RCC_LSEConfig(RCC_LSE_ON);
          
          /* Wait till LSE is ready */
          while (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)
          {}
          
          /* Select the RTC Clock Source */
          RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
          
          /* Enable the RTC Clock */
          RCC_RTCCLKCmd(ENABLE);
          
          /* Wait for RTC APB registers synchronisation */
          RTC_WaitForSynchro();
        }        
      }
      
      /* Enable Ultra low power mode */
      PWR_UltraLowPowerCmd(ENABLE);
      
      /* Diable FLASH during SLeep LP */
      FLASH_SLEEPPowerDownCmd(ENABLE);
      
      /* Disable HSI clock before entering Sleep LP mode */ 
      RCC_HSICmd(DISABLE);
      /* Disable HSE clock */
      RCC_HSEConfig(RCC_HSE_OFF);
      /* Disable LSI clock */
      RCC_LSICmd(DISABLE);
      
      RCC_APB2PeriphClockLPModeCmd(RCC_APB2Periph_CLOCK, ENABLE);
      RCC_APB1PeriphClockLPModeCmd(RCC_APB1Periph_CLOCK, ENABLE);
      RCC_AHBPeriphClockLPModeCmd(RCC_AHBPeriph_CLOCK, ENABLE);
      
      /* Clear IDD_CNT_EN pin */
      GPIO_ResetBits(IDD_CNT_EN_GPIO_PORT, IDD_CNT_EN_PIN);
      
      /* Reconfigure the System Clock at MSI 64 KHz */
      SetHCLKToMSI_64KHz();
      RCC_HCLKConfig(RCC_SYSCLK_Div2); 
      
      /* Request to enter SLEEP mode with regulator low power */
      PWR_EnterSleepMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI);        
    }
    break;
    
    /*=========================================================================*
     *                          STOP LOW POWER MODE                            *
     *========================================================================*/    
    case STM32L_STOP:
    {                 
      /* Enable Ultra low power mode */
      PWR_UltraLowPowerCmd(ENABLE);

      if(!RTCState)
      {  
        RCC_LSEConfig(RCC_LSE_OFF);
      }
      else
      {
        if (RTC_GetFlagStatus(RTC_FLAG_INITS) == RESET)
        {
          /* RTC Configuration ************************************************/
          /* Reset RTC Domain */
          RCC_RTCResetCmd(ENABLE);
          RCC_RTCResetCmd(DISABLE);
          
          /* Enable the LSE OSC */
          RCC_LSEConfig(RCC_LSE_ON);
          
          /* Wait till LSE is ready */
          while (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)
          {}
          
          /* Select the RTC Clock Source */
          RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
          
          /* Enable the RTC Clock */
          RCC_RTCCLKCmd(ENABLE);
          
          /* Wait for RTC APB registers synchronisation */
          RTC_WaitForSynchro();
        }        
      }
      
      /* Clear IDD_CNT_EN pin */
      GPIO_ResetBits(IDD_CNT_EN_GPIO_PORT, IDD_CNT_EN_PIN);
      
      /* Request to enter STOP mode with regulator in low power */
      PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI);
      
      /* Reset the counter by programming IDD_CNT_EN High in less than 70ms after
      the wakeup to avoid 1Kohm to be connected later on VDD_MCU */
      GPIO_SetBits(IDD_CNT_EN_GPIO_PORT, IDD_CNT_EN_PIN);
      
      /* Configures system clock after wake-up from STOP: enable HSE, PLL and select PLL
         as system clock source (HSE and PLL are disabled in STOP mode) */
      IDD_Measurement_SYSCLKConfig_STOP();      
    }
    break;

    /*=========================================================================*
     *                          STANDBY LOW POWER MODE                         *
     *========================================================================*/        
    case STM32L_STANDBY:
    {      
      if (RTC_GetFlagStatus(RTC_FLAG_INITS) == RESET)
      {
        /* RTC Configuration **************************************************/
        /* Reset RTC Domain */
        RCC_RTCResetCmd(ENABLE);
        RCC_RTCResetCmd(DISABLE);
        
        /* Enable the LSE OSC */
        RCC_LSEConfig(RCC_LSE_ON);
        
        /* Wait till LSE is ready */
        while (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)
        {}
        
        /* Select the RTC Clock Source */
        RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
        
        /* Enable the RTC Clock */
        RCC_RTCCLKCmd(ENABLE);
        
        /* Wait for RTC APB registers synchronisation */
        RTC_WaitForSynchro();
      } 
      
      RTC_OutputTypeConfig(RTC_OutputType_PushPull);
      RTC_OutputConfig(RTC_Output_WakeUp, RTC_OutputPolarity_High);  
      
      /* To configure PC13 WakeUP output */
      GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
      GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
      GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
      GPIO_InitStructure.GPIO_Speed = GPIO_Speed_400KHz;  
      GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
      GPIO_Init(GPIOC, &GPIO_InitStructure); 
      GPIO_PinAFConfig(GPIOC, GPIO_PinSource13, GPIO_AF_RTC_AF1);
      
      PWR_WakeUpPinCmd(PWR_WakeUpPin_1, ENABLE);
      
      PWR_UltraLowPowerCmd(ENABLE); 
      
      RTC_ClearFlag(RTC_FLAG_WUTF | RTC_FLAG_ALRBF | RTC_FLAG_ALRAF | RTC_FLAG_TAMP1F | RTC_FLAG_TSF); 
      RTC_ITConfig(RTC_IT_WUT, DISABLE);

      if(!RTCState)
      {  
        RCC_LSEConfig(RCC_LSE_OFF);
      }
      
      /* Clear Wake Up flag */
      PWR_ClearFlag(PWR_FLAG_WU);  
      
      /* Request to enter STANDBY mode (Wake Up flag is cleared in PWR_EnterSTANDBYMode function) */
      PWR_EnterSTANDBYMode();
    }     
    break; 
  }

  /* Configure the System Clock to 32MHz */
  SetHCLKTo32();
      
  /* Reset lowpower status variable*/  
  LowPowerStatus = 0x00;
      
  RCC->AHBENR = RCC_AHBENR;
  RCC->APB2ENR = RCC_APB2ENR;
  RCC->APB1ENR = RCC_APB1ENR;
      
  /* Reset the counter by programming IDD_CNT_EN High in less than 70ms after
     the wakeup to avoid 1Kohm to be connected later on VDD_MCU */
  GPIO_SetBits(IDD_CNT_EN_GPIO_PORT, IDD_CNT_EN_PIN);
  
  /* Measure the Voltage using the ADC */    
  adcdata = IDD_Measurement_ADC_ReadValue();
  
  /* Write the ADC converted value in the DATA EEPROM memory for Bias Measurement */
  if(CalibrationState == BIAS_CALIB_ON)
  {
    /* Unlock EEPROM write access*/
    DATA_EEPROM_Unlock();
  
    /* Store the value in EEPROM for application needs */
    DATA_EEPROM_ProgramHalfWord(DATA_EEPROM_BIAS_ADDR, adcdata);
  
    /* Lock back EEPROM write access */
    DATA_EEPROM_Lock(); 
  }

  IDD_Measurement_ADC_DisplayValue(adcdata, mode);
    
  /* Clear Wake Up flag */
  PWR_ClearFlag(PWR_FLAG_WU);
      
  /* Enable PVD */
  PWR_PVDCmd(ENABLE);
      
  /* Restore Demonstration Context. */
  IDD_Measurement_RestoreContext();
  
  LCD_SetBackColor(LCD_COLOR_GREEN);  
  LCD_DisplayStringLine(LCD_LINE_6, "STM32L LowPower Mode");          
  LCD_DisplayStringLine(LCD_LINE_7, Str);

  LCD_DisplayStringLine(LCD_LINE_8, "Press JoyStick to   ");
  LCD_DisplayStringLine(LCD_LINE_9, "continue.           ");  

  /* Wait until Joystick pressed. */
  while (Menu_ReadKey() == NOKEY)
  {} 
  
  /* Disable ADC1 */
  ADC_Cmd(ADC1, DISABLE);

  LCD_Clear(LCD_COLOR_WHITE);
  
  LCD_GLASS_DisplayString(" STM32L ");

  /* Enable the Wakeup Interrupt */
  RTC_ITConfig(RTC_IT_WUT, ENABLE);

  /* Enable the JoyStick interrupts */
  Demo_IntExtOnOffConfig(ENABLE);
  
  /* Display the previous menu */
  Menu_DisplayMenu(); 
}