STM32L1xx Standard Peripherals Library: Peripheral’s examples

 

Copyright 2010 STMicroelectronics

 

The STM32L1xx Standard Peripherals library provides a rich set of examples covering the main features of each peripheral. All the examples are independent from the software toolchain. These examples run on STMicroelectronics STM32L152-EVAL (Ultra Low Power Medium-density) evaluation board and can be easily tailored to any other supported device and development board. Only source files are provided for each example and user can tailor the provided project template to run the selected example with his preferred toolchain.

How to proceed?

  • Copy the files main.c, main.h (if exists), stm32l1xx_it.c, system_stm32l1xx.c, stm32l1xx_it.h, stm32l1xx_conf.h and any other source files from the specified example to your toolchain folder under Project\STM32L1xx_StdPeriph_Template. This project folder contains already all toolchain files needed for creating projects for STM32L1xx microcontrollers.

  • Open your preferred toolchain

  • If needed, add in the project list the additional files required to run the example (refer to your example readme file)

  • Rebuild all files and load your image into target memory

  • Run the example

STM32L1xx  StdPeriph_Lib Examples

The package contains the following examples:

ADC - COMP - CortexM3 - CRC - DAC - DMA - EXTI - FLASH - GPIO - I2C - IWDG - LCD - Lib_DEBUG - NVIC - PWR - RCC - RTC - SPI - SysTick - TIM - USART - WWDG


IP

Module

Example

Name

Brief Description

ADC

AnalogWatchdog

This example describes how to use the ADC analog watchdog to guard continuously an ADC channel.

ADC_DMA

This example describes how to use the ADC1 and DMA to transfer continuously converted data from ADC1 to memory.

ADC_Freeze

This example provides a short description of how to use the ADC peripheral Freeze and PowerDown modes. The System is clocked by a 512kHz frequency (fsystem) (see system_stm32l1xx.c file). Since the ADC is clocked by a HSI (16MHz) frequency, and the sampling time is 4 Cycles, so the ADC conversion frequency (fADCconv) is 1MHz.

IDDMeas

This example provides a short description of how to use the ADC peripheral to measure IDD in Run mode. The Measured IDD value is displayed continuously on LCD GLASS in mA.

COMP

AnalogVoltageMonitoring

In this example, COMP2 is used to monitor the analog voltage while the MCU is in stop mode and to wake-up the system if a predefined threshold is crossed. When the analog voltage crosses the threshold, the COMP2 is powered-off and ADC1 is powered-on to perform continuous conversion.

COMP_AnalogWatchdog

This example shows how to make an analog watchdog using the STM32L1xx COMPs peripherals in window mode: If the input voltage is above the higher threshold, LD3 and LD1 are turned On. If the input voltage is under the lower threshold, LD2 and LD4 are turned On. If the input voltage is within the thresholds, the MCU remains in STOP mode and all leds are turned Off.

COMP_Interrupt

This example shows how to configure the COMP peripheral to compare the external voltage applied on PB12 with the Internal Voltage Reference. And when the comparator 1 non inverting input (which is connected to PB12) crosses (either rising or falling edges) the internal reference voltage VREFINT (1.22V), the comparator 1 generates an interrupt and toggles LED1.

PulseWidthMeasurement

This example shows how to configure the COMP2 peripheral to measure pulse width. This method (measuring signal pulse using comparator is interesting when external signal doesn't respect the VIL and VIH levels).

PWMSignalControl

This example shows how to configure COMP2 peripheral to hold on safe state (low level) TIM2 channels as soon as COMP2 output is set at high level.

    CortexM3

BitBand

This example shows how to use CortexM3 Bit-Band access to perform atomic read-modify-write and read operations on a variable in SRAM.

Mode_Privilege

This example shows how to modify CortexM3 Thread mode privilege access and stack. CortexM3 Thread mode is entered on Reset, and can be entered as a result of an exception return.

MPU

This example presents the MPU features on STM32L1xx Ultra Low Medium-density devices and it can be easily ported to any other STM32 device supporting MPU. The example purpose (ACCESS_PERMISSION) is to configure a memory region as privileged read only region and tries to perform read and write operation in different mode.

CRC

CRC_Calculation

This example shows how to use CRC (cyclic redundancy check) calculation unit to get a CRC code of a given buffer of data word (32-bit), based on a fixed generator polynomial (0x4C11DB7).

DAC

DAC_ADC

This example describes how to use the ADC1 and DAC to output on DAC_OUT1 sampled values of ADC1. The ADC1 is configured to convert continuously ADC1 channel18 (PB12). The End Of Conversion (EOC) interrupt is enabled and the conversion is triggered by software.

DAC_SignalsGeneration

This example provides a short description of how to use the DAC peripheral to generate several signals using DMA controller. When the user presses the KEY push-button, DMA transfers the two selected waveforms to DAC.

DMA

ADC_TIM2

This example provides a description of how to use a DMA channel to transfer continuously a data from a peripheral (ADC1) to another peripheral (TIM2) supporting DMA transfer.

FLASH_RAM

This example provides a description of how to use a DMA channel to transfer a word data buffer from FLASH memory to embedded SRAM memory.

RAM_DAC

This example provides a description of how to use a DMA channel to transfer data buffer from RAM memory to DAC.

EXTI

Example

This example shows how to configure an external interrupt line. In this example, an EXTI line is configured to generate an interrupt on each falling edge. In the interrupt routine a led connected to a specific GPIO pin is toggled.

   FLASH

Data_ Program

This example provides a description of how to program the STM32L1xx data memory.

HalfPage

This example provides a description of how to program the STM32L1xx FLASH program memory using half page write operation. The Halfpage operation is possible only from SRAM.

Write_Protection

This example provides a description of how to enable and disable the write protection for the STM32L1xx FLASH.

GPIO

IOToggle

This example describes how to use GPIO BSRR (Port bit set/reset register) for IO toggling max frequency.

I2C

I2C_EEPROM

This firmware provides a basic example of how to use the I2C firmware library and an associate I2C EEPROM driver to communicate with an I2C EEPROM device (here the example is interfacing with M24C64 EEPROM)

I2C_TSENSOR

This example provides a description of how to use the I2C to communicate with an STLM75 (or a compatible device) I2C temperature sensor is mounted on the STM32L152-EVAL board and used to get instantaneous external temperature (-55°C to +125°C).

DataExchangeDMA

This is a typical example of how to use the I2C software library to ensure the steps of an I2C communication between slave Receiver/transmitter and master transmitter/receiver using DMA.

DataExchangeInterrupt

This is a typical example of how to use the I2C software library to ensure the steps of an I2C communication between slave Receiver/transmitter and master transmitter/receiver using interrupt.

MasterReceiverInterrupt

This is a typical example of how to use the I2C software library to ensure the steps of an I2C communication between slave transmitter and master receiver using interrupt.

MasterTransmitterInterrupt

This example provides a small application in which joystick buttons are used to trigger I2C communication and though using I2C firmware library.

IWDG

Example

This example shows how to update at regular period the IWDG reload counter and how to simulate a software fault generating an MCU IWDG reset on expiry of a programmed time period.

LCD

Blink Frequency

This example provides a description of how to use the STM32L1xx embedded LCD controller and how to configure the LCD Blink mode and Blink frequency.

Contrast Control

This example provides a description of how to use the STM32L1xx embedded LCD controller and how to Configure the LCD Contrast.

Segments Drive

This example provides a description of how to use the STM32L1xx LCD embedded controller to drive the Pacific Display LCD glass (PD-878) mounted on STM32L152-EVAL board.

LIB_DEBUG

Example

This example demonstrates how to declare dynamic peripherals pointers used for Debug mode.

NVIC

DMA_WFIMode

This example shows how to enter the system to WFI mode with DMA transfer enabled and wake-up from this mode by the DMA End of Transfer interrupt.

IRQ_Mask

This example demonstrates the use of the Nested Vectored Interrupt Controller (NVIC) IRQ Channels configuration and how to mask/activate different IRQs.

IRQ_Priority

This example demonstrates the use of the Nested Vectored Interrupt Controller (NVIC).

VectorTable_Relocation

This example describes how to set the CortexM3 vector table in a specific address other than default using the NVIC_SetVectorTable function from the misc.h/.c driver.

PWR

STANDBY

This example shows how to enter the system to STANDBY mode and wake-up from this mode using: external RESET, RTC Alarm or WKUP pin.

STOP

This example shows how to enter the system to STOP mode and wake-up using EXTI Line interrupts. The EXTI Line sources are PC.13 and RTC Alarm.

BOR

This example shows how to configure the programmable BOR thresholds using the FLASH option bytes.

CurrentConsumption

This example shows how to configure the STM32L1xx system to measure different Ultra Low Power modes current consumption.

PVD

This example shows how to configure the programmable voltage detector using an external interrupt line. In this example, EXTI line 16 is configured to generate an interrupt on each rising or falling edge of the PVD output signal (which indicates that the Vdd voltage is below the PVD threshold).

RCC

Example

This example demonstrates how to switch the System clock from one source to another.

RTC

Calendar

This example provides a short description of how to use the RTC peripheral. By default, the Calendar Time (initialized in main.c file) is displayed on LCD glass. When the user press KEY button, the Calendar Date (initialized
in main.c file) is displayed on LCD glass. After each switch between Calendar time and Calendar date, the LED 1 toggle.

TimeStamp

This example provides a short description of how to use the RTC peripheral and the timeStamp Feature.

Tamper

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

RTC_LSI

This example demonstrates and explains how to use the LSI clock source auto calibration to get a precise RTC clock.

SPI

MSD

This example provides a basic example of how to use the SPI firmware library and an associate SPI SDcard driver to communicate with an SDcard available on The eval board.

DataExchangeDMA

This example provides a small application in which joystick buttons are used to trigger SPI communication and though using SPI firmware library.

DataExchangeInterrupt

This example provides a small application in which joystick buttons are used to trigger SPI communication and though using SPI firmware library.

SysTick

Example

This example shows how to configure the SysTick to generate a time base equal to 1 ms. The system clock is set to 32 MHz, the SysTick is clocked by the AHB clock (HCLK).

TIM

InputCapture

This example shows how to use the TIM peripheral to measure the frequency of an external signal, The measured Frequency is displayed on the LCD Glass.

InputCaptureRouting

This example shows how configure the Routing Interface to map TIM4 channel 2 to PE13 in order to measure the frequency of an external signal, the measured frequency is displayed on the LCD Glass.

TIM9_ETR_LSE

This example explains how to configure TIM9 time base that works completely independently of the system clock. This allows the scheduling of tasks without having to take into account the processor state (the processor may be stopped or executing at low, medium or full speed). For this purpose, the LSE clock is internally redirected to the TIM9 ETR input.

TIM9_OCToggle

This example shows how to configure the TIM9 peripheral to generate two different signals with two different frequencies.

TIM11_PWM_Output

This example shows how to configure the TIM peripheral in PWM (Pulse Width Modulation) mode.  The TIM11CLK frequency is set to SystemCoreClock.

TimeBase

This example shows how to configure the TIM peripheral in Output Compare Timing mode with the corresponding Interrupt requests for each channel in order to generate 4 different time bases.

ExternalTrigger_Synchro

This example shows how to synchronize TIM peripherals in cascade mode with an external trigger.

Cascade_Synchro

This example shows how to synchronize TIM peripherals in cascade mode.

Parallel_Synchro

This example shows how to synchronize TIM peripherals in parallel mode.

PWM_Input

This example shows how to use the TIM peripheral to measure the frequency and duty cycle of an external signal.

OnePulse

This example shows how to use the TIM peripheral to generate a One pulse Mode after a Rising edge of an external signal is received in Timer Input pin.

OCActive

This example shows how to configure the TIM peripheral to generate four different signals with four different delays.

OCInactive

This example shows how to configure the TIM peripheral in Output Compare Inactive mode with the corresponding Interrupt requests for each channel.

OCToggle

This example shows how to configure the TIM3 peripheral to generate four different signals with four different frequencies.

PWM_Output

This example shows how to configure the TIM peripheral in PWM (Pulse Width Modulation) mode.

USART

Printf

This example shows how to retarget the C library printf function to the USART. This implementation output the printf message on the HyperTerminal using USARTx. USARTx can be USART2 or USART3 depending on the EVAL board you are using.

Hyperterminal_Interrupt

This example provides a description of how to use the EVAL_COM1 Transmit and Receive interrupts to communicate with the HyperTerminal. EVAL_COM1 can be USART2 or USART3 depending on the STMicroelectronics EVAL board you are using.

DataExchangeDMA

This example provides a small application in which joystick buttons are used to trigger UART communication and though using UART firmware library.

DataExchangeInterrupt

This example provides a small application in which joystick buttons are used to trigger UART communication and though using UART firmware library.

WWDG

Example

This example shows how to update at regular period the WWDG counter and how to simulate a software fault generating an MCU WWDG reset on expiry of a programmed time period.








































Back to Top

 

 

For complete documentation on STM32L(CORTEX M3) 32-bit Microcontrollers platform visit www.st.com/STM32L