forked from platformio/platformio-core
Update STM32 examples
This commit is contained in:
@@ -1,16 +1,21 @@
|
||||
#ifdef STM32L1
|
||||
#include <stm32l1xx_gpio.h>
|
||||
#include <stm32l1xx_rcc.h>
|
||||
#include <misc.h>
|
||||
#else
|
||||
#ifdef STM32F3
|
||||
#include <stm32f30x_gpio.h>
|
||||
#include <stm32f30x_rcc.h>
|
||||
#else
|
||||
#include <stm32f4xx_gpio.h>
|
||||
#include <stm32f4xx_rcc.h>
|
||||
#include <misc.h>
|
||||
#endif
|
||||
#include <stm32l1xx_gpio.h>
|
||||
#include <stm32l1xx_rcc.h>
|
||||
#define LEDPORT (GPIOB)
|
||||
#define LEDPIN (GPIO_Pin_7)
|
||||
#define ENABLE_GPIO_CLOCK (RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE))
|
||||
#elif STM32F3
|
||||
#include <stm32f30x_gpio.h>
|
||||
#include <stm32f30x_rcc.h>
|
||||
#define LEDPORT (GPIOE)
|
||||
#define LEDPIN (GPIO_Pin_8)
|
||||
#define ENABLE_GPIO_CLOCK (RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOE, ENABLE))
|
||||
#elif STM32F4
|
||||
#include <stm32f4xx_gpio.h>
|
||||
#include <stm32f4xx_rcc.h>
|
||||
#define LEDPORT (GPIOD)
|
||||
#define LEDPIN (GPIO_Pin_12)
|
||||
#define ENABLE_GPIO_CLOCK (RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE))
|
||||
#endif
|
||||
|
||||
/* timing is not guaranteed :) */
|
||||
@@ -27,30 +32,26 @@ int main(void)
|
||||
{
|
||||
/* gpio init struct */
|
||||
GPIO_InitTypeDef gpio;
|
||||
|
||||
/* reset rcc */
|
||||
RCC_DeInit();
|
||||
|
||||
/* enable clock to GPIOB */
|
||||
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
|
||||
|
||||
/* use pin 7 */
|
||||
gpio.GPIO_Pin = GPIO_Pin_7;
|
||||
/* enable clock GPIO */
|
||||
ENABLE_GPIO_CLOCK;
|
||||
/* use LED pin */
|
||||
gpio.GPIO_Pin = LEDPIN;
|
||||
/* mode: output */
|
||||
gpio.GPIO_Mode = GPIO_Mode_OUT;
|
||||
/* output type: push-pull */
|
||||
gpio.GPIO_OType = GPIO_OType_PP;
|
||||
/* apply configuration */
|
||||
GPIO_Init(GPIOB, &gpio);
|
||||
|
||||
GPIO_Init(LEDPORT, &gpio);
|
||||
/* main program loop */
|
||||
for (;;) {
|
||||
/* set led on */
|
||||
GPIO_SetBits(GPIOB, GPIO_Pin_7);
|
||||
GPIO_SetBits(LEDPORT, LEDPIN);
|
||||
/* delay */
|
||||
simple_delay(100000);
|
||||
/* clear led */
|
||||
GPIO_ResetBits(GPIOB, GPIO_Pin_7);
|
||||
GPIO_ResetBits(LEDPORT, LEDPIN);
|
||||
/* delay */
|
||||
simple_delay(100000);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user