[STM] Tutorial: Getting started with STM32F3 Discovery board
Posted: 11-Nov-2014, 19:55
Lesson #1.
This guide briefly describes how to get started programming SMT32F3 board using IAR Embedded Workbench.
First tutorial shows how to create a simple blinking LEDs firmware for this board.
Comments to the code:
1) Include header files from SPL-library.
2) Enable Port_E with RCC_AHBPeriphClockCmd() function call.
3) Configure Port_E pins 8 and 9 (LEDs are connected to this pins). This requires to initialize GPIO_InitTypeDef structure with default values, then we set Mode and Pin fields and finally call GPIO_StructInit().
In the endless 'while(1)' loop pins Pin_8 and Pin_9 are switched on and off thus making LEDs blink.
This guide briefly describes how to get started programming SMT32F3 board using IAR Embedded Workbench.
First tutorial shows how to create a simple blinking LEDs firmware for this board.
Code: Select all
#include <stm32f30x.h>
#include <stm32f30x_rcc.h>
#include <stm32f30x_gpio.h>
int main()
{
GPIO_InitTypeDef gpio;
//Reset and Clock Control (Enable PortE, LEDS 8-15)
RCC_AHBPeriphClockCmd( RCC_AHBPeriph_GPIOE, ENABLE );
// Init PortE (LEDS)
GPIO_StructInit( &gpio );
gpio.GPIO_Mode = GPIO_Mode_OUT;
gpio.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9;
GPIO_Init( GPIOE, &gpio );
// Blinking LEDS
while(1)
{
// On
GPIO_SetBits( GPIOE, GPIO_Pin_8 );
Delay(500000);
GPIO_SetBits( GPIOE, GPIO_Pin_9 );
Delay(500000);
// All off
GPIO_ResetBits( GPIOE, GPIO_Pin_8 |GPIO_Pin_9 );
Delay(1000000);
}
}
void Delay(unsigned long i)
{
while( i-- > 0 ) ;
}
1) Include header files from SPL-library.
2) Enable Port_E with RCC_AHBPeriphClockCmd() function call.
3) Configure Port_E pins 8 and 9 (LEDs are connected to this pins). This requires to initialize GPIO_InitTypeDef structure with default values, then we set Mode and Pin fields and finally call GPIO_StructInit().
In the endless 'while(1)' loop pins Pin_8 and Pin_9 are switched on and off thus making LEDs blink.