Reorganize examples with STM32 and new frameworks

This commit is contained in:
Valeriy Koval
2015-02-03 14:43:27 +02:00
parent c402cc7c62
commit 423dc248bc
14 changed files with 488 additions and 1 deletions

View File

@ -0,0 +1,24 @@
#
# Project Configuration File
#
# A detailed documentation with the EXAMPLES is located here:
# http://docs.platformio.org/en/latest/projectconf.html
#
# A sign `#` at the beginning of the line indicates a comment
# Comment lines are ignored.
# Simple and base environment
# [env:mybaseenv]
# platform = %INSTALLED_PLATFORM_NAME_HERE%
# framework =
# board =
#
# Automatic targets - enable auto-uploading
# targets = upload
[env:stm32]
platform = stm32
framework = cmsis
board = stm32ldiscovery

View File

@ -0,0 +1,27 @@
#include "stm32l1xx.h"
void ms_delay(int ms)
{
while (ms-- > 0) {
volatile int x=500;
while (x-- > 0)
__asm("nop");
}
}
//Alternates blue and green LEDs quickly
int main(void)
{
RCC->AHBENR |= RCC_AHBENR_GPIOBEN; // enable the clock to GPIOB
GPIOB->MODER |= (1 << 12); // set pin 6 to be general purpose output
GPIOB->MODER |= (1 << 14); // set pin 7 to be general purpose output
GPIOB->ODR |= (1 << 7); // Set the pin 7 high
for (;;) {
ms_delay(100);
GPIOB->ODR ^= (1 << 6); // Toggle the pin
GPIOB->ODR ^= (1 << 7); // Toggle the pin
}
}

View File

@ -0,0 +1,23 @@
#
# Project Configuration File
#
# A detailed documentation with the EXAMPLES is located here:
# http://docs.platformio.org/en/latest/projectconf.html
#
# A sign `#` at the beginning of the line indicates a comment
# Comment lines are ignored.
# Simple and base environment
# [env:mybaseenv]
# platform = %INSTALLED_PLATFORM_NAME_HERE%
# framework =
# board =
#
# Automatic targets - enable auto-uploading
# targets = upload
[env:stm32]
platform = stm32
board = stm32ldiscovery
framework = opencm3

View File

@ -0,0 +1,70 @@
/*
* This file is part of the libopencm3 project.
*
* Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
* Copyright (C) 2011 Stephen Caudle <scaudle@doceme.com>
* Copyright (C) 2012 Karl Palsson <karlp@tweak.net.au>
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include <libopencm3/stm32/rcc.h>
#include <libopencm3/stm32/gpio.h>
static void gpio_setup(void)
{
/* Enable GPIOB clock. */
/* Manually: */
//RCC_AHBENR |= RCC_AHBENR_GPIOBEN;
/* Using API functions: */
rcc_periph_clock_enable(RCC_GPIOB);
/* Set GPIO6 (in GPIO port B) to 'output push-pull'. */
/* Using API functions: */
gpio_mode_setup(GPIOB, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO6);
}
int main(void)
{
int i;
gpio_setup();
/* Blink the LED (PB6) on the board. */
while (1) {
/* Manually: */
// GPIOB_BSRR = GPIO6; /* LED off */
// for (i = 0; i < 1000000; i++) /* Wait a bit. */
// __asm__("nop");
// GPIOB_BRR = GPIO6; /* LED on */
// for (i = 0; i < 1000000; i++) /* Wait a bit. */
// __asm__("nop");
/* Using API functions gpio_set()/gpio_clear(): */
// gpio_set(GPIOB, GPIO6); /* LED off */
// for (i = 0; i < 1000000; i++) /* Wait a bit. */
// __asm__("nop");
// gpio_clear(GPIOB, GPIO6); /* LED on */
// for (i = 0; i < 1000000; i++) /* Wait a bit. */
// __asm__("nop");
/* Using API function gpio_toggle(): */
gpio_toggle(GPIOB, GPIO6); /* LED on/off */
for (i = 0; i < 1000000; i++) { /* Wait a bit. */
__asm__("nop");
}
}
return 0;
}

View File

@ -0,0 +1,24 @@
#
# Project Configuration File
#
# A detailed documentation with the EXAMPLES is located here:
# http://docs.platformio.org/en/latest/projectconf.html
#
# A sign `#` at the beginning of the line indicates a comment
# Comment lines are ignored.
# Simple and base environment
# [env:mybaseenv]
# platform = %INSTALLED_PLATFORM_NAME_HERE%
# framework =
# board =
#
# Automatic targets - enable auto-uploading
# targets = upload
[env:stm32]
platform = stm32
framework = cmsis,spl
board = stm32ldiscovery

View File

@ -0,0 +1,49 @@
#include <stm32l1xx_gpio.h>
#include <stm32l1xx_rcc.h>
#include <misc.h>
/* timing is not guaranteed :) */
void simple_delay(uint32_t us)
{
/* simple delay loop */
while (us--) {
asm volatile ("nop");
}
}
/* system entry point */
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;
/* mode: output */
gpio.GPIO_Mode = GPIO_Mode_OUT;
/* output type: push-pull */
gpio.GPIO_OType = GPIO_OType_PP;
/* apply configuration */
GPIO_Init(GPIOB, &gpio);
/* main program loop */
for (;;) {
/* set led on */
GPIO_SetBits(GPIOB, GPIO_Pin_7);
/* delay */
simple_delay(100000);
/* clear led */
GPIO_ResetBits(GPIOB, GPIO_Pin_7);
/* delay */
simple_delay(100000);
}
/* never reached */
return 0;
}

View File

@ -0,0 +1,23 @@
#
# Project Configuration File
#
# A detailed documentation with the EXAMPLES is located here:
# http://docs.platformio.org/en/latest/projectconf.html
#
# A sign `#` at the beginning of the line indicates a comment
# Comment lines are ignored.
# Simple and base environment
# [env:mybaseenv]
# platform = %INSTALLED_PLATFORM_NAME_HERE%
# framework =
# board =
#
# Automatic targets - enable auto-uploading
# targets = upload
[env:launchpad_tm4c1230c3pm]
platform = titiva
framework = energia
board = lptm4c1230c3pm

View File

@ -0,0 +1,19 @@
/**
* Copyright (C) Ivan Kravets <me@ikravets.com>
* See LICENSE for details.
*/
#include "Energia.h"
void setup()
{
pinMode(GREEN_LED, OUTPUT); // set pin as output
}
void loop()
{
digitalWrite(GREEN_LED, HIGH); // set the LED on
delay(1000); // wait for a second
digitalWrite(GREEN_LED, LOW); // set the LED off
delay(1000); // wait for a second
}

View File

Before

Width:  |  Height:  |  Size: 2.0 MiB

After

Width:  |  Height:  |  Size: 2.0 MiB

View File

@ -21,4 +21,3 @@
platform = titiva
framework = energia
board = lplm4f120h5qr
targets = upload

View File

@ -0,0 +1,23 @@
#
# Project Configuration File
#
# A detailed documentation with the EXAMPLES is located here:
# http://docs.platformio.org/en/latest/projectconf.html
#
# A sign `#` at the beginning of the line indicates a comment
# Comment lines are ignored.
# Simple and base environment
# [env:mybaseenv]
# platform = %INSTALLED_PLATFORM_NAME_HERE%
# framework =
# board =
#
# Automatic targets - enable auto-uploading
# targets = upload
[env:launchpad_lm4f120]
platform = titiva
framework = opencm3
board = lplm4f120h5qr

View File

@ -0,0 +1,206 @@
/*
* This file is part of the libopencm3 project.
*
* Copyright (C) 2011 Gareth McMullin <gareth@blacksphere.co.nz>
* Copyright (C) 2012-2013 Alexandru Gagniuc <mr.nuke.me@gmail.com>
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* \addtogroup Examples
*
* Flashes the Red, Green and Blue diodes on the board, in order.
*
* RED controlled by PF1
* Green controlled by PF3
* Blue controlled by PF2
*/
#include <libopencm3/cm3/nvic.h>
#include <libopencm3/lm4f/systemcontrol.h>
#include <libopencm3/lm4f/rcc.h>
#include <libopencm3/lm4f/gpio.h>
#include <libopencm3/lm4f/nvic.h>
#include <stdbool.h>
#include <stdio.h>
/* This is how the RGB LED is connected on the stellaris launchpad */
#define RGB_PORT GPIOF
enum {
LED_R = GPIO1,
LED_G = GPIO3,
LED_B = GPIO2,
};
/* This is how the user switches are connected to GPIOF */
enum {
USR_SW1 = GPIO4,
USR_SW2 = GPIO0,
};
/* The divisors we loop through when the user presses SW2 */
enum {
PLL_DIV_80MHZ = 5,
PLL_DIV_57MHZ = 7,
PLL_DIV_40MHZ = 10,
PLL_DIV_20MHZ = 20,
PLL_DIV_16MHZ = 25,
};
static const uint8_t plldiv[] = {
PLL_DIV_80MHZ,
PLL_DIV_57MHZ,
PLL_DIV_40MHZ,
PLL_DIV_20MHZ,
PLL_DIV_16MHZ,
0
};
/* The PLL divisor we are currently on */
static size_t ipll = 0;
/* Are we bypassing the PLL, or not? */
static bool bypass = false;
/*
* Clock setup:
* Take the main crystal oscillator at 16MHz, run it through the PLL, and divide
* the 400MHz PLL clock to get a system clock of 80MHz.
*/
static void clock_setup(void)
{
rcc_sysclk_config(OSCSRC_MOSC, XTAL_16M, PLL_DIV_80MHZ);
}
/*
* GPIO setup:
* Enable the pins driving the RGB LED as outputs.
*/
static void gpio_setup(void)
{
/*
* Configure GPIOF
* This port is used to control the RGB LED
*/
periph_clock_enable(RCC_GPIOF);
const uint32_t outpins = (LED_R | LED_G | LED_B);
gpio_mode_setup(RGB_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, outpins);
gpio_set_output_config(RGB_PORT, GPIO_OTYPE_PP, GPIO_DRIVE_2MA, outpins);
/*
* Now take care of our buttons
*/
const uint32_t btnpins = USR_SW1 | USR_SW2;
/*
* PF0 is a locked by default. We need to unlock it before we can
* re-purpose it as a GPIO pin.
*/
gpio_unlock_commit(GPIOF, USR_SW2);
/* Configure pins as inputs, with pull-up. */
gpio_mode_setup(GPIOF, GPIO_MODE_INPUT, GPIO_PUPD_PULLUP, btnpins);
}
/*
* IRQ setup:
* Trigger an interrupt whenever a button is depressed.
*/
static void irq_setup(void)
{
const uint32_t btnpins = USR_SW1 | USR_SW2;
/* Trigger interrupt on rising-edge (when button is depressed) */
gpio_configure_trigger(GPIOF, GPIO_TRIG_EDGE_RISE, btnpins);
/* Finally, Enable interrupt */
gpio_enable_interrupts(GPIOF, btnpins);
/* Enable the interrupt in the NVIC as well */
nvic_enable_irq(NVIC_GPIOF_IRQ);
}
#define FLASH_DELAY 800000
static void delay(void)
{
int i;
for (i = 0; i < FLASH_DELAY; i++) /* Wait a bit. */
__asm__("nop");
}
int main(void)
{
gpio_enable_ahb_aperture();
clock_setup();
gpio_setup();
irq_setup();
/* Blink each color of the RGB LED in order. */
while (1) {
/*
* Flash the Red diode
*/
gpio_set(RGB_PORT, LED_R);
delay(); /* Wait a bit. */
gpio_clear(RGB_PORT, LED_R);
delay(); /* Wait a bit. */
/*
* Flash the Green diode
*/
gpio_set(RGB_PORT, LED_G);
delay(); /* Wait a bit. */
gpio_clear(RGB_PORT, LED_G);
delay(); /* Wait a bit. */
/*
* Flash the Blue diode
*/
gpio_set(RGB_PORT, LED_B);
delay(); /* Wait a bit. */
gpio_clear(RGB_PORT, LED_B);
delay(); /* Wait a bit. */
}
return 0;
}
void gpiof_isr(void)
{
if (gpio_is_interrupt_source(GPIOF, USR_SW1)) {
/* SW1 was just depressed */
bypass = !bypass;
if (bypass) {
rcc_pll_bypass_enable();
/*
* The divisor is still applied to the raw clock.
* Disable the divisor, or we'll divide the raw clock.
*/
SYSCTL_RCC &= ~SYSCTL_RCC_USESYSDIV;
}
else
{
rcc_change_pll_divisor(plldiv[ipll]);
}
/* Clear interrupt source */
gpio_clear_interrupt_flag(GPIOF, USR_SW1);
}
if (gpio_is_interrupt_source(GPIOF, USR_SW2)) {
/* SW2 was just depressed */
if (!bypass) {
if (plldiv[++ipll] == 0)
ipll = 0;
rcc_change_pll_divisor(plldiv[ipll]);
}
/* Clear interrupt source */
gpio_clear_interrupt_flag(GPIOF, USR_SW2);
}
}