From 580d25a84baaa160b0afdc096e9aa1e8ca1c2d2b Mon Sep 17 00:00:00 2001 From: Stephen Caudle Date: Mon, 31 Oct 2011 00:16:37 -0400 Subject: Move STM32 example projects in family specific folders --- examples/stm32/f1/stm32-h103/led_stripe/Makefile | 23 ++ .../stm32/f1/stm32-h103/led_stripe/led_stripe.c | 234 +++++++++++++++++++++ .../stm32/f1/stm32-h103/led_stripe/led_stripe.ld | 31 +++ 3 files changed, 288 insertions(+) create mode 100644 examples/stm32/f1/stm32-h103/led_stripe/Makefile create mode 100644 examples/stm32/f1/stm32-h103/led_stripe/led_stripe.c create mode 100644 examples/stm32/f1/stm32-h103/led_stripe/led_stripe.ld (limited to 'examples/stm32/f1/stm32-h103/led_stripe') diff --git a/examples/stm32/f1/stm32-h103/led_stripe/Makefile b/examples/stm32/f1/stm32-h103/led_stripe/Makefile new file mode 100644 index 0000000..60fd1ef --- /dev/null +++ b/examples/stm32/f1/stm32-h103/led_stripe/Makefile @@ -0,0 +1,23 @@ +## +## This file is part of the libopencm3 project. +## +## Copyright (C) 2009 Uwe Hermann +## +## This program is free software: you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation, either version 3 of the License, or +## (at your option) any later version. +## +## This program 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 General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program. If not, see . +## + +BINARY = led_stripe + +include ../../Makefile.include + diff --git a/examples/stm32/f1/stm32-h103/led_stripe/led_stripe.c b/examples/stm32/f1/stm32-h103/led_stripe/led_stripe.c new file mode 100644 index 0000000..1576866 --- /dev/null +++ b/examples/stm32/f1/stm32-h103/led_stripe/led_stripe.c @@ -0,0 +1,234 @@ +/* + * This file is part of the libopencm3 project. + * + * Copyright (C) 2011 Piotr Esden-Tempski + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/* + * This example is implementing the protocol of ZJ168 addressable led + * strips. These strips use the LPD6803 controller. You may be able to + * find the datasheet here: + * http://www.adafruit.com/datasheets/LPD6803.pdf + */ + +#include + +#include +#include + +#define SPI_BANK GPIOB +#define SCLK_PIN GPIO13 +#define MOSI_PIN GPIO15 + +#define SMALL_DELAY_VALUE 0 + +#define COLOR_COUNT 50 + +#define SCLK(VAL) \ + if (VAL) { \ + gpio_set(SPI_BANK, SCLK_PIN); \ + } else { \ + gpio_clear(SPI_BANK, SCLK_PIN); \ + } + +#define MOSI(VAL) \ + if (VAL) { \ + gpio_set(SPI_BANK, MOSI_PIN); \ + } else { \ + gpio_clear(SPI_BANK, MOSI_PIN); \ + } + +#define SMALL_DELAY() { \ + int j; \ + for (j = 0; j < SMALL_DELAY_VALUE; j++) \ + __asm__("nop"); \ + } + +struct color { + u8 r; + u8 g; + u8 b; +}; + +/* Set STM32 to 72 MHz. */ +void clock_setup(void) +{ + rcc_clock_setup_in_hse_8mhz_out_72mhz(); + + /* Enable GPIOC clock. */ + rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPCEN); + rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPBEN); + +} + +void gpio_setup(void) +{ + /* Set GPIO12 (in GPIO port C) to 'output push-pull'. */ + gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_50_MHZ, + GPIO_CNF_OUTPUT_PUSHPULL, GPIO12); + gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ, + GPIO_CNF_OUTPUT_PUSHPULL, GPIO13); + gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ, + GPIO_CNF_OUTPUT_PUSHPULL, GPIO15); +} + +void send_colors(struct color *colors, int count) { + int i, k; + + /* initialize spi pins */ + SCLK(0); + MOSI(0); + + /* start frame */ + for (i=0; i<32; i++) { + SCLK(1); + SMALL_DELAY(); + SCLK(0); + SMALL_DELAY(); + } + + /* color cell output */ + for (k = 0; k < count; k++) { + /* Start bit */ + MOSI(1); + SCLK(1); + SMALL_DELAY(); + SCLK(0); + SMALL_DELAY(); + + /* Blue */ + for (i=0; i<5; i++) { + MOSI(((colors[k].b & ((1 << 4) >> i)) != 0)); + SCLK(1); + SMALL_DELAY(); + SCLK(0); + SMALL_DELAY(); + } + /* Red */ + for (i=0; i<5; i++) { + MOSI(((colors[k].r & ((1 << 4) >> i)) != 0)); + SCLK(1); + SMALL_DELAY(); + SCLK(0); + SMALL_DELAY(); + } + /* Green */ + for (i=0; i<5; i++) { + MOSI(((colors[k].g & ((1 << 4) >> i)) != 0)); + SCLK(1); + SMALL_DELAY(); + SCLK(0); + SMALL_DELAY(); + } + } + + /* End frame */ + MOSI(0); + for (k=0; k < count; k++) { + SCLK(1); + SMALL_DELAY(); + SCLK(0); + SMALL_DELAY(); + } +} + +void reset_colors(struct color *colors, int count) { + int i; + + for (i=0; i + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/* Linker script for Olimex STM32-H103 (STM32F103RBT6, 128K flash, 20K RAM). */ + +/* Define memory regions. */ +MEMORY +{ + rom (rx) : ORIGIN = 0x08000000, LENGTH = 128K + ram (rwx) : ORIGIN = 0x20000000, LENGTH = 20K +} + +/* Include the common ld script. */ +INCLUDE libopencm3_stm32f1.ld + -- cgit v1.2.3