Information Center for ARM

Example description

  
BKP_Domain RTC Backup domain example
  
Example Description 

This example demonstrates and explains how to use the peripherals available on
Backup Domain. These peripherals are: the RCC BDCR register containing the LSE Osc 
configuration and the RTC Clock enable/disable bits. It embeds also the RTC 
peripheral with its associated Backup Data registers. And finally the Backup SRAM (4KB)
with its low power regulator allowing to preserve its contents when the 
product is powered by VBAT pin.

As an application example, it demonstrates how to setup the RTC hardware calendar,
RTC Backup Data registers read/write and BKPSRAM read/write operations. 

One from the following clock can be used as RTC clock source (uncomment the
corresponding define in main.c): 
  - LSE oscillator clock usually delivered by a 32.768 kHz quartz.
  - LSI oscillator clock
  
The Backup (BKP) domain, still powered by VBAT when VDD is switched off, so its
content is not lost if a battery is connected to the VBAT pin. 
A key value is written in backup data register 0 to indicate if the Backup Domain
is already configured.

The program behaves as follows:

1. After startup the program checks the backup data register 0 value:
    - BKP_DR0 value not correct: (RTC_BKP_DR0 value is not correct or has not yet
      been programmed when the program is executed for the first time) the RTC is
      configured and the user is asked to set the time and date (entered on 
      TFT-LCD) and the RTC Backup Data registers and BKPSRAM are written.
    
    - BKP_DR0 value correct: this means that the RTC is configured and the time
      and date are displayed on LCD. The content of RTC Backup Data registers 
      and BKPSRAM is checked and the result is displayed on color LCD.

2. When an External Reset occurs the BKP domain is not reset.

3. When power on reset occurs:
    - If a battery is connected to the VBAT pin: the BKP domain is not reset and
      the RTC configuration is not lost.
      
    - If no battery is connected to the VBAT pin: the BKP domain is reset and the
      RTC configuration is lost.

4. When an RTC Wakeup event occurs the RTC Wakeup interrupt is generated and the
   current Time/Date is refreshed on LCD.
   
The example uses TFT-LCD and push-button to configure the RTC clock and display
the current calendar:
 
 - When the Backup domain is not yet configured:
    - The RCC BDCR Register value is displayed on LCD before and after the Backup
      domain configuration.
    - All RTC Backup Data Registers are written and checked.
    - All BKP SRAM content is written and checked.
    - User asked for RTC Calendar Configuration using the Tamper/Wakeup/Key buttons:
       - Use WAKEUP button to decrement the current value.
       - Use TAMPER button to increment the current value.
       - Use KEY button to validate the current value.
    - Once configured, the RTC Calendar is displayed on the LCD each second using
      the RTC Wakeup Interrupt.

 - When the Backup domain is already configured:
    - No need to reconfigure the RTC Clock and Calendar.
    - All RTC Backup Data Registers are checked.
    - All BKP SRAM content is checked. If the Low power regulator is enabled, the
      BKPSRAM content is not lost.
    - The RTC Calendar is displayed on the LCD each second using
      the RTC Wakeup Interrupt.

Directory contents 

  - RTC/BKP_Domain/system_stm32f2xx.c   STM32F2xx system clock configuration file
  - RTC/BKP_Domain/stm32f2xx_conf.h     Library Configuration file
  - RTC/BKP_Domain/stm32f2xx_it.c       Interrupt handlers
  - RTC/BKP_Domain/stm32f2xx_it.h       Header for stm32f2xx_it.c
  - RTC/BKP_Domain/main.c               Main program
  - RTC/BKP_Domain/main.h               Main header file
  - RTC/BKP_Domain/lcd_log_conf.h       lcd_log configuration file

	  The "system_stm32f2xx.c" is generated by an automatic clock configuration 
      tool and can be easily customized to your own configuration. 
      To select different clock setup, use the "STM32F2xx_Clock_Configuration_V1.0.0.xls" tool.
	  
Hardware and Software environment 

  - This example runs on STM32F2xx Devices.
  
  - This example has been tested with STM322xG-EVAL RevB and can be easily tailored
    to any other development board. 

  - STM322xG-EVAL Set-up
    - Use the TAMPER push button connected to PC.13 pin (EXTI Line13).
    - Use the KEY push button connected to PG.15 pin (EXTI Line15).
    - Use the WAKEUP push button connected to PA.00 pin (EXTI Line0).
    - All messages are displayed on the TFT-LCD.
    - Make sure that jumper JP19 is in position 2-3 to connect the 3V battery to VBAT pin

===============================================================================

HW_Calendar RTC Hardware Calendar example
  
Example Description 

This example demonstrates and explains how to use the RTC peripheral.
As an application example, it demonstrates how to setup the RTC peripheral, in 
terms of prescaler and interrupts, to be used to keep time and to generate 
alarm interrupt. 

One from the following clock can be used as RTC clock source (uncomment the
corresponding define in main.c): 
  - LSE oscillator clock usually delivered by a 32.768 kHz quartz.
  - LSI oscillator clock
  
The RTC is in the backup (BKP) domain, still powered by VBAT when VDD is switched off,
so the RTC configuration is not lost if a battery is connected to the VBAT pin. 
A key value is written in backup data register 0 to indicate if the RTC is already
configured.

The program behaves as follows:

1. After startup the program checks the backup data register 0 value:
    - BKP_DR0 value not correct: (RTC_BKP_DR0 value is not correct or has not yet
      been programmed when the program is executed for the first time) the RTC is
      configured and the user is asked to set the time and alarm (entered on 
      HyperTerminal).
    
    - BKP_DR0 value correct: this means that the RTC is configured and the time
      and Alarm A are displayed on HyperTerminal.

2. When an External Reset occurs the BKP domain is not reset and the RTC configuration
   is not lost.

3. When power on reset occurs:
    - If a battery is connected to the VBAT pin: the BKP domain is not reset and
      the RTC configuration is not lost.
      
    - If no battery is connected to the VBAT pin: the BKP domain is reset and the
      RTC configuration is lost.

4. When an RTC Alarm A event occurs the RTC Alarm interrupt is generated and the
   LED1 is toggled.
   
The example uses HyperTerminal to configure the RTC clock and display the current time:
 - When Tamper button is pressed, a menu is displayed to configure the RTC Time 
   and Alarm A registers.
 - When Key button is pressed, the current time is displayed.
 - When WakeUp button is pressed, the current alarm A is displayed. 

LED2 is truned ON when the RTC configuration is done correctly.

Directory contents 

  - RTC/HW_Calendar/system_stm32f2xx.c   STM32F2xx system clock configuration file
  - RTC/HW_Calendar/stm32f2xx_conf.h     Library Configuration file
  - RTC/HW_Calendar/stm32f2xx_it.c       Interrupt handlers
  - RTC/HW_Calendar/stm32f2xx_it.h       Header for stm32f2xx_it.c
  - RTC/HW_Calendar/main.c               Main program
  - RTC/HW_Calendar/main.h               Main header file

	  The "system_stm32f2xx.c" is generated by an automatic clock configuration 
      tool and can be easily customized to your own configuration. 
      To select different clock setup, use the "STM32F2xx_Clock_Configuration_V1.0.0.xls" tool.

Hardware and Software environment 

  - This example runs on STM32F2xx Devices.
  
  - This example has been tested with STM322xG-EVAL RevB and can be easily tailored
    to any other development board. 

  - STM322xG-EVAL Set-up
    - Use LED1 led connected respectively to PG.06 pins.
    - Use the TAMPER push button connected to PC.13 pin (EXTI Line13).
    - Use the KEY push button connected to PG.15 pin (EXTI Line15).
    - Use the WAKEUP push button connected to PA.00 pin (EXTI Line0).
    - Make sure that jumper JP19 is in position 1-2 to connect the 3V battery to VBAT pin
    - Connect a null-modem female/female RS232 cable between the DB9 connector 
      CN16 (USART3) and PC serial port if you want to display data on the HyperTerminal.
	  Make sure that jumper JP22 is in position 1-2
      
  - Hyperterminal configuration:
    - Word Length = 8 Bits
    - One Stop Bit
    - No parity
    - BaudRate = 115200 baud
    - flow control: None

===============================================================================

RTC_LSI RTC Hardware Calendar example
  
Example Description 

This example demonstrates and explains how to use the LSI clock source auto
calibration to get a precise RTC clock. 
As an application example, it demonstrates how to configure the TIM5 timer
internally connected to LSI clock output, in order to adjust the RTC prescaler. 

The Low Speed Internal (LSI) clock is used as RTC clock source.
After reset, the RTC prescaler (asynchronous and synchronous) is set with the 
default LSI frequency (32KHz). 
The RTC WakeUp is configured to generate an interrupt each 1s. The WakeUp counter
is clocked by the RTC CK_SPRE signal (1Hz) and its counter is set to 0x0.
LED1 connected to PG.06 is toggled inside the RTC WakeUp interrupt each 1s.

The inaccuracy of the LSI clock causes the RTC WakeUp Interrupt to be inaccurate.
The RTC CK_SPRE signal can be monitored by LED1 which is toggled into the RTC 
Wakeup interrupt service routine.

The program waits until Key Push button is pressed to begin the auto calibration 
procedure:
 - Configure the TIM5 to remap internally the TIM5 Channel 4 Input Capture to 
   the LSI clock output.
 - Enable the TIM5 Input Capture interrupt: after one cycle of LSI clock, the
   period value is stored in a variable and compared to the HCLK clock to get
   its real value.
 - The RTC prescaler is adjusted with this LSI frequency value so that the RTC
   CK_SPRE value become more accurate.
 - When calibration is done a led connected to PG.08 is turned ON to indicate the
   end of this operation.

Directory contents 

  - RTC/RTC_LSI/system_stm32f2xx.c   STM32F2xx system clock configuration file
  - RTC/RTC_LSI/stm32f2xx_conf.h     Library Configuration file
  - RTC/RTC_LSI/stm32f2xx_it.c       Interrupt handlers
  - RTC/RTC_LSI/stm32f2xx_it.h       Header for stm32f2xx_it.c
  - RTC/RTC_LSI/main.c               Main program

	  The "system_stm32f2xx.c" is generated by an automatic clock configuration 
      tool and can be easily customized to your own configuration. 
      To select different clock setup, use the "STM32F2xx_Clock_Configuration_V1.0.0.xls" tool.

Hardware and Software environment 

  - This example runs on STM32F2xx Devices.
  
  - This example has been tested with STM322xG-EVAL RevB and can be easily tailored
    to any other development board. 

  - STM322xG-EVAL Set-up
    - Use LD1 and LD2 leds connected respectively to PG.06 and PG.08 pins.
    - Use the KEY push button connected to PG.15 pin (EXTI Line15).

===============================================================================

RTC_Tamper RTC Tamper example
  
Example Description 

This example shows how to write/read data to/from RTC Backup data registers and 
demonstrates the Tamper detection feature.

One from the following clock can be used as RTC clock source (uncomment the
corresponding define in main.c):
  - LSE oscillator clock usually delivered by a 32.768 kHz quartz.
  - LSI oscillator clock

The associated firmware performs the following:
1. It configures the RTC_AF1 pin Tamper to be falling edge, and enables the Tamper 
   interrupt.
2. It writes the data to all RTC Backup data registers, then check whether the 
   data were correctly written. If yes, LED1 turns on, otherwise LED3 turns on.
3. On applying a low level on the RTC_AF1 pin (PC.13), the RTC backup data registers
   are reset and the Tamper interrupt is generated. The corresponding ISR then checks
   whether the RTC Backup data registers are cleared. If yes LED2 turns ON,
   otherwise LED4 turns ON.

Directory contents 

  - RTC/Tamper/system_stm32f2xx.c   STM32F2xx system clock configuration file
  - RTC/Tamper/stm32f2xx_conf.h     Library Configuration file
  - RTC/Tamper/stm32f2xx_it.c       Interrupt handlers
  - RTC/Tamper/stm32f2xx_it.h       Header for stm32f2xx_it.c
  - RTC/Tamper/main.c               Main program
  - RTC/Tamper/main.h               Main header file

	  The "system_stm32f2xx.c" is generated by an automatic clock configuration 
      tool and can be easily customized to your own configuration. 
      To select different clock setup, use the "STM32F2xx_Clock_Configuration_V1.0.0.xls" tool.

Hardware and Software environment 

  - This example runs on STM32F2xx Devices.
  
  - This example has been tested with STM322xG-EVAL RevB and can be easily tailored
    to any other development board. 

  - STM322xG-EVAL Set-up
    - Use LD1, LD2, LD3 and LD4 leds connected respectively to PG.06, PG.08, PI.09 
      and PC.07 pins.
    - Use the TAMPER push button connected to PC.13 pin (EXTI Line13).

===============================================================================

RTC_TimeStamp RTC TimeStamp example
  
Example Description 

This example provides a short description of how to use the RTC peripheral and 
the Time Stamp feature.

One from the following clock can be used as RTC clock source (uncomment the
corresponding define in main.c):
  - LSE oscillator clock usually delivered by a 32.768 kHz quartz.
  - LSI oscillator clock

The program behaves as follows:

1. After startup the program checks the backup data register 0 value:
    - BKP_DR0 value not correct: (RTC_BKP_DR0 value is not correct or has not yet
      been programmed when the program is executed for the first time) the RTC is
      configured and the user is asked to set the time and date (entered on 
      HyperTerminal).
    
    - BKP_DR0 value correct: this means that the RTC is configured and the time
      date and timestamp (time and date) are displayed on HyperTerminal.

2. When an External Reset occurs the BKP domain is not reset and the RTC configuration
   is not lost.

3. When power on reset occurs:
    - If a battery is connected to the VBAT pin: the BKP domain is not reset and
      the RTC configuration is not lost.
      
    - If no battery is connected to the VBAT pin: the BKP domain is reset and the
      RTC configuration is lost.

4. It configures the RTC_AF1 pin TimeStamp to be falling edge and enables the
TimeStamp detection.

5. On applying a low level on the RTC_AF1 pin (PC.13), the calendar is saved in 
the time-stamp registers thanks to the timestamp event detection.
   
The example uses HyperTerminal to configure the RTC clock, display the current 
time and timestamp registers contents:
 - pressing TAMPER push button, the current time and date are saved in RTC TSTR
   and TSDR registers.
 - When pressing WAKEUP push button, the TimeStamp Calendar is cleared.
 - When pressing KEY push button, the current RTC Calendar (Time and date) and
   RTC TimeStamp Calendar (Time and date) are displayed.

	  The RTC_Year member in the TimeStamp Date is always 00 (no years in the RTC_TSDR register)
 
Directory contents 

  - RTC/TimeStamp/system_stm32f2xx.c   STM32F2xx system clock configuration file
  - RTC/TimeStamp/stm32f2xx_conf.h     Library Configuration file
  - RTC/TimeStamp/stm32f2xx_it.c       Interrupt handlers
  - RTC/TimeStamp/stm32f2xx_it.h       Header for stm32f2xx_it.c
  - RTC/TimeStamp/main.c               Main program
  - RTC/TimeStamp/main.h               Main header file
  
	  The "system_stm32f2xx.c" is generated by an automatic clock configuration 
      tool and can be easily customized to your own configuration. 
      To select different clock setup, use the "STM32F2xx_Clock_Configuration_V1.0.0.xls" tool.

Hardware and Software environment 

  - This example runs on STM32F2xx Devices.
  
  - This example has been tested with STM322xG-EVAL RevB and can be easily tailored
    to any other development board. 

  - STM322xG-EVAL Set-up
    - Use the TAMPER push button connected to PC.13 pin (EXTI Line13).
    - Use the KEY push button connected to PG.15 pin (EXTI Line15).
    - Use the WAKEUP push button connected to PA.00 pin (EXTI Line0).
    - Make sure that jumper JP19 is in position 1-2 to connect the 3V battery to VBAT pin
    - Connect a null-modem female/female RS232 cable between the DB9 connector 
      CN16 (USART3) and PC serial port if you want to display data on the HyperTerminal.
	  Make sure that jumper JP22 is in position 1-2     
      
  - Hyperterminal configuration:
    - Word Length = 8 Bits
    - One Stop Bit
    - No parity
    - BaudRate = 115200 baud
    - flow control: None