The Keil MDK-ARM Development Tools download includes several example
programs that are configured for the Keil MCBSTM32 Board.
All examples are configured for two µVision targets:
Simulator - where the program runs in the software
MCBSTM32 - where the program runs from internal Flash
located on the microcontroller.
All examples use the same file structure:
Abstract.txt contains a short description of the
STM32F10x.s contains the startup code for the
STM32_Init.[c,h] contain the initialization of the
- Example dependent source code.
STMicroelectronics provides a firmware library with sample code
(C sources) but the examples described here do not use this library
to keep the executable as small as possible.
Each example program is stored in a separate folder in
\KEIL\ARM\BOARDS\KEIL\MCBSTM32\ along with project files that
help you quickly build the project and run the program.
The following example programs are installed automatically:
The Blinky project shows the combination of configuring peripherals
via STM32_Init.c and own initialization functions. GPIO, USART and
timer are configured via STM32_Init.c. DMA and ADC are set up with
a seperate initialisation function. The LEDs blink with a speed
depending on potentiometer position. SysTimer is used in interrupt
mode and ticks every 10ms. Character LCD display shows init message
and bargraph depending on potentiometer position. AD value is
output onto serial port USART1 (115200 baud, 8 data bits, no
parity, 1 stop bit). AD is used with DMA and 12 bit
The GPIO project demonstrates the use of the GPIO ports. Pins
PB8..PB15 (LEDs) are configured as output and the pins PA0 (S2) and
PC13 (S3) are configured as input. By pressing buttons S2 or S3 the
lit LED moves to the left or to the right.
The IWDG project demonstrates the use of the Independent Watchdog.
The independent watchdog is configured to fire after 2 seconds. LED
PB15 indicates that the IWDG is no longer reloaded and is now going
to reset the board. LED PB12 is lit when the restart was caused by
Project RTC demonstrates the use of the Realtime Clock in interrupt
mode. The RTC is configured to generate an interrupt every second
and also when the alarmtime is reached. Time is set to 12:00:00 and
alarmtime to 12:00:20. LED PB8 blinks in a second interval and PB10
is lit upon an alarm interrupt.
TIM1 is configured to generate an update interrupt every 250 ms.
The lit LED moves on every timer tick. TIM1 is configured without
the use of detailed settings.
Project PWM_1 uses the PWM (Pulse Width Modulation) function with
timer TIM4. To use the PWM function it is necessary to configure
the detailed settings of TIM4. TIM4 is configured to tick every
second. Channel 3, connected to PB8, has a duty cicle of 50% and
channel 4, connected tp PB9, has a duty cicle of 25%. LEDs PB8, PB9
are lit during the channel's duty cicle.
Project PWM_2 uses the PWM (Pulse Width Modulation) function with
timer TIM4 in interrupt mode. To use the PWM function it is
necessary to configure the detailed settings of TIM4. TIM4 is
configured to generate an update interrupt every 100 ms. On every
update interrupt the duty cicles of channel 3 and channel 4 are
changed. The result is that the LEDs PB8 and PB9 are
The USART_Pol project shows the use of USART1 in polling mode. The
configuration of USART1 is 9600 Baud, 8 data bits, 1 stop bit, no
parity and no flow control. Retargetting is used to read a
character over the serial input and to print out a string to the
The USART_Irq project demonstrates the use of USART1 in interrupt
driven mode. The configuration of USART1 is 9600 Baud, 8 data bits,
1 stop bit, no parity and no flow control. Retargetting is used to
read a character over the serial input and to print out a string to
the serial output. A buffer handling is implemented for transmit /
The EXTI project is a simple program which demonstrates the use of
external interrupts. Button S2 (pin PA0) and button S3 (pin PC13)
are configured to generate an external interrupt. By pressing
buttons S2 or S3 the LED PB8 toggles.
The Tamper project is a simple program which demonstrates the use
of Tamper detection BKP_DR1 and BKP_DR2 are set to specific values.
Tamper pin is configured to generate an interrupt. LED PB9 is lit
if BKP_DR1, BKP_DR2 are cleared upon a tamper event, LED PB8 is lit
if BKP_DR1, BKP_DR2 are not cleared
The CAN project demonstrates the use of the CAN peripheral. The CAN
controller is initialized for 500 kbit/s. A converted analog value
is send in the first byte of a CAN message. Received and
transmitted byte values are displayed on LCD.
The Measure project shows the combination of configuring
peripherals via STM32_Init.c and own initialisation functions.
GPIO, USART and timer are configured via STM32_Init.c. DMA and ADC
are set up with a seperate initialization function. The Measure
program uses analog and digital inputs to simulate a datalogger. A
help menue is displayed using the serial port USART1. The value of
analog input POT1 and the state of S2, S3 Buttons are logged. Timer
TIM3 is used in interrupt mode and ticks every 1ms. Serial port
USART1 (115200 baud, 8 data bits, no parity, 1 stop bit) is used in
polling mode. AD is used with DMA and 12 bit resolution.
RTX_Blinky is a simple RTX Kernel based example which simulates a
step-motor driver. Four LEDs are blinking simulating the activation
of the four output driver stages.
The RTX_Traffic project demonstrates the control of a traffic
light. The traffic light is timed and lets cars pass during a
specific time period. There is a pedestrial crossing button (S3)
that lets pedestrians cross. The lights are connected to GPIO Port
B. This program uses RTX Kernel. Serial I/O is interrupt and event
driven using USART1. USART1 settings are 9600 baud, 8 data bits, no
parity, 1 stop bit.
The SVC project shows how to implement software interrupt
functions. It includes the file SVC.c which implements the SVC
handler. The SVC function declarations and implementations are
demonstrated in the file Test.c.
The USBHID project is a demo for a USB Human Interface Device. The
USB HID is recognized by the host PC running Windows which will
load a generic HID driver. The board LEDs (PB8..PB15) and Push
Buttons (S2, S3) can then be accessed from the PC through a custom
HID Client Program.
See also Application Note 195: Developing HID USB
Device Drivers For Embedded Systems.
The USB Memory project is a demo program for an USB Memory based on
USB Mass Storage Class. The USB Memory is automatically recognized
by the host PC running Windows which will load a generic Mass
Storage driver. Read / write access is displayed using the board
More example projects and programs are available
These projects and programs let you start programming other
features of the STM32F10x device, such as Interrupt-driven SIO, PWM