Exemplo n.º 1
0
extern hal_result_t hal_eeprom_write(hal_eeprom_t eep, uint32_t addr, uint32_t size, void *data)
{
    hal_result_t res = hal_res_NOK_generic;
    uint32_t rr = 0;

    if(hal_true != s_hal_eeprom_initted_is(eep))
    {
        return(hal_res_NOK_generic);
    }

    if((NULL == data)  || (size == 0))
    {
         return(hal_res_NOK_generic);
    }

    if(hal_false == hal_eeprom_address_is_valid(eep, addr))
    {   // cannot write at the address the first bytes
        return(hal_res_NOK_generic);
    }

    if(hal_false == hal_eeprom_address_is_valid(eep, addr+size-1))
    {   // cannot write at the address the last bytes
        return(hal_res_NOK_generic);
    }    

    
    switch(eep)
    {
        case hal_eeprom_emulatedflash:
        {
            res = s_hal_eeprom_writeflash(addr, size, data);
        } break;

        case hal_eeprom_i2c_01:
        {
            hal_brdcfg_eeprom__writeprotection_disable();
        	rr = sEE_WriteBuffer((uint8_t*)data, (uint16_t)addr, (uint16_t)size);
            hal_brdcfg_eeprom__writeprotection_enable();
            if(sEE_OK != rr)     res = hal_res_NOK_generic;
            else                 res = hal_res_OK;
        } break;

        default:
        {
            res = hal_res_NOK_generic;
        } break;

    }


    return(res);
}
Exemplo n.º 2
0
void PFO_EXTI(void)
{
	uint8_t i = 0;
	if(EXTI_GetITStatus(PFO_EXTI_LINE) != RESET)
	{
		EXTI_ClearITPendingBit(PFO_EXTI_LINE);
		Led_Drive(0x0F);
//		while(1)
//		{
//			i++;
//			printf("%d",i);	
//		}
			sEE_WriteBuffer(gl_Store,sEE_WRITE_ADDRESS1,BUFFER_SIZE);
	
			sEE_WaitEepromStandbyState();

	}
}
Exemplo n.º 3
0
void EEPROM_Write(uint16_t offset, uint8_t* pData, uint16_t length)
{
	sEE_WriteBuffer(pData, offset, length);
}
Exemplo n.º 4
0
extern hal_result_t hal_eeprom_erase(hal_eeprom_t eep, uint32_t addr, uint32_t size)
{   
    hal_result_t res = hal_res_NOK_generic;
    // must be static const to be used within any shared library
    static const uint64_t value8[4] = {0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF};
    #define factor 32
    uint32_t num8 = 0;
    uint32_t rem8 = 0;
    uint32_t i = 0;
    uint32_t rr = 0;
    
    if(hal_true != s_hal_eeprom_initted_is(eep))
    {
        return(hal_res_NOK_generic);
    }

    if(size == 0)
    {
         return(hal_res_NOK_generic);
    }
    
    if(hal_false == hal_eeprom_address_is_valid(eep, addr))
    {   // cannot write at the address the first bytes
        return(hal_res_NOK_generic);
    }

    if(hal_false == hal_eeprom_address_is_valid(eep, addr+size-1))
    {   // cannot write at the address the last bytes
        return(hal_res_NOK_generic);
    }    

    // marker: evaluate the kind of eeprom
    
    switch(eep)
    {
        case hal_eeprom_emulatedflash:
        {
            res = s_hal_eeprom_eraseflash(addr, size);
        } break;

        case hal_eeprom_i2c_01:
        {
            num8 = size / factor;
            rem8 = size % factor;
            hal_brdcfg_eeprom__writeprotection_disable();

            for(i=0; i<num8; i++)
            {
                rr = sEE_WriteBuffer((uint8_t*)&value8, (uint16_t)addr, (uint16_t)factor);
                if(sEE_OK != rr) return(hal_res_NOK_generic);
                addr += factor;
            }

            if(0 != rem8)
            {
                rr = sEE_WriteBuffer((uint8_t*)&value8, (uint16_t)addr, (uint16_t)rem8);
                if(sEE_OK != rr) return(hal_res_NOK_generic);
            }

            hal_brdcfg_eeprom__writeprotection_enable();

//#if 0 // acemor on 14 ott 2011: it does not work.
//    hal_brdcfg_eeprom__writeprotection_disable();
//
//    for(end = addr + size; addr < end; addr++)
//    {
//	    sEE_WriteByte(&value, (uint16_t)addr);
//    }
//
//    hal_brdcfg_eeprom__writeprotection_enable();
//#endif

        } break;

        default:
        {
            res = hal_res_NOK_generic;
        } break;

    }


    return(res);
}
Exemplo n.º 5
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
void SPI_EEPROM_Example(void)
{
  /*!< At this stage the microcontroller clock setting is already configured,
       this is done through SystemInit() function which is called from startup
       file (startup_stm32f30x.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f30x.c file
     */

  /* Initialize the SPI EEPROM driver ----------------------------------------*/
  sEE_Init();

  /* First write in the memory followed by a read of the written data --------*/
  /* Write on SPI EEPROM from sEE_WRITE_ADDRESS1 */
  sEE_WriteBuffer(Tx1Buffer, sEE_WRITE_ADDRESS1, BUFFER_SIZE1);

  /* Wait for EEPROM standby state */
  sEE_WaitEepromStandbyState();

  /* Set the Number of data to be read */
  NumDataRead = BUFFER_SIZE1;

  /* Read from SPI EEPROM from sEE_READ_ADDRESS1 */
  sEE_ReadBuffer(Rx1Buffer, sEE_READ_ADDRESS1, (uint16_t *)(&NumDataRead));

  /* Check if the data written to the memory is read correctly */
  TransferStatus1 = Buffercmp(Tx1Buffer, Rx1Buffer, BUFFER_SIZE1);

  /* Second write in the memory followed by a read of the written data -------*/
  /* Write on SPI EEPROM from sEE_WRITE_ADDRESS2 */
  sEE_WriteBuffer(Tx2Buffer, sEE_WRITE_ADDRESS2, BUFFER_SIZE2);

  /* Wait for EEPROM standby state */
  sEE_WaitEepromStandbyState();

  /* Set the Number of data to be read */
  NumDataRead = BUFFER_SIZE2;

  /* Read from SPI EEPROM from sEE_READ_ADDRESS2 */
  sEE_ReadBuffer(Rx2Buffer, sEE_READ_ADDRESS2, (uint16_t *)(&NumDataRead));

  /* Check if the data written to the memory is read correctly */
  TransferStatus2 = Buffercmp(Tx2Buffer, Rx2Buffer, BUFFER_SIZE2);

#ifdef ENABLE_LCD_MSG_DISPLAY
  /* Initialize the LCD screen for information display */
  STM32303C_LCD_Init();
  LCD_Clear(LCD_COLOR_BLUE);
  LCD_SetBackColor(LCD_COLOR_BLUE);
  LCD_SetTextColor(LCD_COLOR_WHITE);
  LCD_DisplayStringLine(LCD_LINE_0, "SMT32F30x FW Library");
  LCD_DisplayStringLine(LCD_LINE_1, "   EEPROM Example   ");

  /* TransferStatus1 = PASSED, if the transmitted and received data
  to/from the EEPROM are the same */
  /* TransferStatus1 = FAILED, if the transmitted and received data
     to/from the EEPROM are different */
  if (TransferStatus1 == PASSED)
  {
    LCD_DisplayStringLine(LCD_LINE_3, " Transfer 1 PASSED  ");
  }
  else
  {
    LCD_DisplayStringLine(LCD_LINE_3, " Transfer 1 FAILED  ");
  }

  /* TransferStatus2 = PASSED, if the transmitted and received data
  to/from the EEPROM are the same */
  /* TransferStatus2 = FAILED, if the transmitted and received data
  to/from the EEPROM are different */
  if (TransferStatus2 == PASSED)
  {
    LCD_DisplayStringLine(LCD_LINE_5, " Transfer 2 PASSED  ");
  }
  else
  {
    LCD_DisplayStringLine(LCD_LINE_5, " Transfer 2 FAILED  ");
  }
#endif /* ENABLE_LCD_MSG_DISPLAY */

  /* Free all used resources */
  sEE_DeInit();

  while (1)
  {
  }
}
Exemplo n.º 6
0
/**
  * @brief   Main program
  * @param  None
  * @retval None
*/
int main(void)
{
  /*!< At this stage the microcontroller clock setting is already configured, 
       this is done through SystemInit() function which is called from startup
       file (startup_stm32l1xx_xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32l1xx.c file
     */    

#ifdef ENABLE_LCD_MSG_DISPLAY
  /* Initialize the LCD screen for information display */
#ifdef USE_STM32L152D_EVAL
  STM32L152D_LCD_Init();
#else
  STM32L152_LCD_Init();
#endif 
  LCD_Clear(LCD_COLOR_BLUE);  
  LCD_SetBackColor(LCD_COLOR_BLUE);
  LCD_SetTextColor(LCD_COLOR_WHITE);
  LCD_DisplayStringLine(LCD_LINE_0, "SMT32L1xx FW Library");
  LCD_DisplayStringLine(LCD_LINE_1, "   EEPROM Example   ");
#endif /* ENABLE_LCD_MSG_DISPLAY */  
  
  /* Initialize the I2C EEPROM driver ----------------------------------------*/
  sEE_Init();  

  /* First write in the memory followed by a read of the written data --------*/
  /* Write on I2C EEPROM from sEE_WRITE_ADDRESS1 */
  sEE_WriteBuffer(Tx1_Buffer, sEE_WRITE_ADDRESS1, BUFFER_SIZE1); 

  /* Wait for EEPROM standby state */
  sEE_WaitEepromStandbyState();  
  
  /* Set the Number of data to be read */
  NumDataRead = BUFFER_SIZE1;
  
  /* Read from I2C EEPROM from sEE_READ_ADDRESS1 */
  sEE_ReadBuffer(Rx1_Buffer, sEE_READ_ADDRESS1, (uint16_t *)(&NumDataRead)); 


  /* Starting from this point, if the requested number of data is higher than 1, 
     then only the DMA is managing the data transfer. Meanwhile, CPU is free to 
     perform other tasks:
  
    // Add your code here: 
    //...
    //...

     For simplicity reasons, this example is just waiting till the end of the 
     transfer. */
 
#ifdef ENABLE_LCD_MSG_DISPLAY  
  LCD_DisplayStringLine(LCD_LINE_3, " Transfer 1 Ongoing ");
#endif /* ENABLE_LCD_MSG_DISPLAY */ 
  
  /* Wait till DMA transfer is compelete (Tranfer complete interrupt handler 
    resets the variable holding the number of data to be read) */
  while (NumDataRead > 0)
  {}  
  
  /* Check if the data written to the memory is read correctly */
  TransferStatus1 = Buffercmp(Tx1_Buffer, Rx1_Buffer, BUFFER_SIZE1);
  /* TransferStatus1 = PASSED, if the transmitted and received data 
     to/from the EEPROM are the same */
  /* TransferStatus1 = FAILED, if the transmitted and received data 
     to/from the EEPROM are different */
#ifdef ENABLE_LCD_MSG_DISPLAY  
  if (TransferStatus1 == PASSED)
  {
    LCD_DisplayStringLine(LCD_LINE_3, " Transfer 1 PASSED  ");
  }
  else
  {
    LCD_DisplayStringLine(LCD_LINE_3, " Transfer 1 FAILED  ");
  }  
#endif /* ENABLE_LCD_MSG_DISPLAY */  

  /* Second write in the memory followed by a read of the written data -------*/
  /* Write on I2C EEPROM from sEE_WRITE_ADDRESS2 */
  sEE_WriteBuffer(Tx2_Buffer, sEE_WRITE_ADDRESS2, BUFFER_SIZE2); 

  /* Wait for EEPROM standby state */
  sEE_WaitEepromStandbyState();  
  
  /* Set the Number of data to be read */
  NumDataRead = BUFFER_SIZE2;  
  
  /* Read from I2C EEPROM from sEE_READ_ADDRESS2 */
  sEE_ReadBuffer(Rx2_Buffer, sEE_READ_ADDRESS2, (uint16_t *)(&NumDataRead));


  /* Starting from this point, if the requested number of data is higher than 1, 
     then only the DMA is managing the data transfer. Meanwhile, CPU is free to 
     perform other tasks:
     
    // Add your code here: 
    //...
    //...

     For simplicity reasons, this example is just waiting till the end of the 
     transfer. */

#ifdef ENABLE_LCD_MSG_DISPLAY   
  LCD_DisplayStringLine(LCD_LINE_5, " Transfer 2 Ongoing ");
#endif /* ENABLE_LCD_MSG_DISPLAY */  
  
  /* Wait till DMA transfer is compelete (Tranfer complete interrupt handler 
    resets the variable holding the number of data to be read) */
  while (NumDataRead > 0)
  {}
  
  /* Check if the data written to the memory is read correctly */
  TransferStatus2 = Buffercmp(Tx2_Buffer, Rx2_Buffer, BUFFER_SIZE2);
  /* TransferStatus2 = PASSED, if the transmitted and received data 
     to/from the EEPROM are the same */
  /* TransferStatus2 = FAILED, if the transmitted and received data 
     to/from the EEPROM are different */
#ifdef ENABLE_LCD_MSG_DISPLAY   
  if (TransferStatus2 == PASSED)
  {
    LCD_DisplayStringLine(LCD_LINE_5, " Transfer 2 PASSED  ");
  }
  else
  {
    LCD_DisplayStringLine(LCD_LINE_5, " Transfer 2 FAILED  ");
  }  
#endif /* ENABLE_LCD_MSG_DISPLAY */
  
  /* Free all used resources */
  sEE_DeInit();

  while (1)
  {
  }
}
Exemplo n.º 7
0
int main(void){
	
	//configure push-button interrupts
	PB_Config();
	
	 /* LCD initiatization */
  LCD_Init();
  
  /* LCD Layer initiatization */
  LCD_LayerInit();
    
  /* Enable the LTDC */
  LTDC_Cmd(ENABLE);
  
  /* Set LCD foreground layer */
  LCD_SetLayer(LCD_FOREGROUND_LAYER);

	
	
	//======You need to develop the following functions======
	//Note: these are just placeholders; function definitions are at bottom of this file
	//configure real-time clock
	RTC_Config();
	
	//configure external push-buttons and interrupts
	ExtPB_Config();
	ExtPBNum2();
	
	
	//main program
	
	LCD_Clear(LCD_COLOR_WHITE);
		
	//line=0;
	//Display a string in one line, on the first line (line=0)
	//LCD_DisplayStringLine(LINE(line),  (uint8_t *) "Init EEPROM...");
	//line++;
	
	//i2c_init(); //initialize the i2c chip
	sEE_Init();  

	
	//LCD_DisplayStringLine(LINE(line),  (uint8_t *) "done..."); 
	//line++;
	
	//LCD_DisplayStringLine(LINE(line),  (uint8_t *) "Writing...");
	//line++;
	
	
	/* First write in the memory followed by a read of the written data --------*/
  /* Write on I2C EEPROM from memLocation */
  //sEE_WriteBuffer(&Tx1_Buffer, memLocation,1); 

  /* Wait for EEPROM standby state */
  //sEE_WaitEepromStandbyState();  
 
  
	//LCD_DisplayStringLine(LINE(line),  (uint8_t *) "Reading...");
  /* Read from I2C EEPROM from memLocation */
  //sEE_ReadBuffer(&Rx1_Buffer, memLocation, (uint16_t *)(&NumDataRead)); 
	//line++;
	
	//LCD_DisplayStringLine(LINE(line),  (uint8_t *) "Comparing...");  
	//line++;
	
	
	//if(Tx1_Buffer== Rx1_Buffer){
		//LCD_DisplayStringLine(LINE(line),  (uint8_t *) "Success!");  
	//}else{
		//LCD_DisplayStringLine(LINE(line),  (uint8_t *) "Mismatch!"); 
	//}
	
	//main loop
	while(1){
		RTC_GetTime(RTC_Format_BIN,&RTC_TimeStructure);
		hours = RTC_TimeStructure.RTC_Hours;
		minutes = RTC_TimeStructure.RTC_Minutes;
		seconds = RTC_TimeStructure.RTC_Seconds;

		sprintf(time,"%0.2d:%0.2d:%0.2d",hours,minutes,seconds);
		LCD_DisplayStringLine(LINE(6),  (uint8_t *) time); 
		
		if(UBPressed == 1){
			
			toBeSaved = time[7];
			sEE_WriteBuffer(&toBeSaved, memLocation+1,1); 
			sEE_WaitEepromStandbyState();  
			
			sEE_ReadBuffer(&Rx1_Buffer, memLocation+1, (uint16_t *)(&NumDataRead)); 
			saved[0] = Rx1_Buffer;

			
			
			LCD_DisplayStringLine(LINE(7),  (uint8_t *) saved);
			
			UBPressed = 0;
			PB_Config();
			
		}
		if(EB1Pressed == 1 && state == 0){
			state = 1;
			EB1Pressed = 0;
			ExtPB_Config();
		}
		if(EB1Pressed == 1 && state == 1){
			state = 2;
			EB1Pressed = 0;
			ExtPB_Config();
			
		}
		if(EB1Pressed == 1 && state == 2){
			state = 3;
			EB1Pressed = 0;
			ExtPB_Config();
			
		}
		if(EB1Pressed == 1 && state == 3){
			state = 0;
			EB1Pressed = 0;
			ExtPB_Config();
			
		}
		if(EB2Pressed == 1 && state == 1){
			
			RTC_TimeStructure.RTC_Hours = hours + 1;
			RTC_SetTime(RTC_Format_BCD, &RTC_TimeStructure);
			EB2Pressed = 0;
			ExtPBNum2();
		}
		if(EB2Pressed == 1 && state == 2){
			
			RTC_TimeStructure.RTC_Minutes = minutes + 1;
			RTC_SetTime(RTC_Format_BCD, &RTC_TimeStructure);
			EB2Pressed = 0;
			ExtPBNum2();
		}
		if(EB2Pressed == 1 && state == 3){
			
			RTC_TimeStructure.RTC_Seconds = seconds + 1;
			RTC_SetTime(RTC_Format_BCD, &RTC_TimeStructure);
			EB2Pressed = 0;
			ExtPBNum2();
		}
		
	}
}