Add miniblink (+f1).

This commit is contained in:
flabbergast 2017-12-03 08:21:24 +00:00
parent bd937bc2a0
commit ef9fd2db6a
7 changed files with 234 additions and 0 deletions

View file

@ -6,6 +6,10 @@ They aren't too specific for the bat boards, except the usual pinout considerati
## Short summary for the examples
### miniblink
The onboard LED blinks. This is the classic miniblink from [libopencm3 examples], modified for the bat board, and the various MCUs I tested the board with (L052, F072, and the ubiquitous F103). Highights the code adjustments one needs for the different MCUs. Clock setup not implemented (except for F103, which just calls a library function, to test the crystal).
### blink_btn
The onboard LED blinks, holding the button slows the frequency somewhat. The clocks are set up to 48MHz on F072, 32MHz on L052 (max).

43
common.f1.mk Normal file
View file

@ -0,0 +1,43 @@
##
## This file is part of the libopencm3 project.
##
## Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
## Copyright (C) 2010 Piotr Esden-Tempski <piotr@esden.net>
##
## 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/>.
##
LIBNAME = opencm3_stm32f1
DEFS += -DSTM32F1
FP_FLAGS ?= -msoft-float
ARCH_FLAGS = -mthumb -mcpu=cortex-m3 $(FP_FLAGS) -mfix-cortex-m3-ldrd
################################################################################
# OpenOCD specific variables
OOCD ?= openocd
OOCD_INTERFACE ?= flossjtag
OOCD_BOARD ?= olimex_stm32_h103
################################################################################
# Black Magic Probe specific variables
# Set the BMP_PORT to a serial port and then BMP is used for flashing
BMP_PORT ?=
################################################################################
# texane/stlink specific variables
#STLINK_PORT ?= :4242
include ../libopencm3.rules.mk

26
miniblink/Makefile.f0 Normal file
View file

@ -0,0 +1,26 @@
##
## This file is part of the libopencm3 project.
##
## Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
##
## 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/>.
##
BINARY = miniblink
OPENCM3_DIR=../libopencm3
LDSCRIPT = $(OPENCM3_DIR)/lib/stm32/f0/stm32f07xzb.ld
include ../common.f0.mk

26
miniblink/Makefile.f1 Normal file
View file

@ -0,0 +1,26 @@
##
## This file is part of the libopencm3 project.
##
## Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
##
## 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/>.
##
BINARY = miniblink
OPENCM3_DIR=../libopencm3
LDSCRIPT = $(OPENCM3_DIR)/lib/stm32/f1/stm32f103x8.ld
include ../common.f1.mk

26
miniblink/Makefile.l0 Normal file
View file

@ -0,0 +1,26 @@
##
## This file is part of the libopencm3 project.
##
## Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
##
## 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/>.
##
BINARY = miniblink
OPENCM3_DIR=../libopencm3
LDSCRIPT = $(OPENCM3_DIR)/lib/stm32/l0/stm32l0xx8.ld
include ../common.l0.mk

27
miniblink/Makefile.l0btld Normal file
View file

@ -0,0 +1,27 @@
##
## This file is part of the libopencm3 project.
##
## Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
##
## 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/>.
##
BINARY = miniblink
OPENCM3_DIR=../libopencm3
LDSCRIPT = ../l052-bldr.ld
DEFS += -DBOOTLOADER8K
include ../common.l0.mk

82
miniblink/miniblink.c Normal file
View file

@ -0,0 +1,82 @@
/*
* This file is part of the libopencm3 project.
*
* Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
*
* 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>
#define LED_GPIO GPIOA
#define LED_PIN GPIO15
#define LED_RCC_GPIO RCC_GPIOA
// MCUs run at different speeds, so adjust to your liking
#if defined(STM32F0)
#define DELAY_CONSTANT 100000
#elif defined(STM32L0)
#define DELAY_CONSTANT 100000
#elif defined(STM32F1)
#define DELAY_CONSTANT 2000000
#endif /* STM32F1 */
static void gpio_setup(void)
{
/* Enable the correct clock. */
/* Using API functions; for how to do it "manually" see libopencm3-examples/.../miniblink */
rcc_periph_clock_enable(LED_RCC_GPIO);
/* Set LED_PIN to 'output push-pull'. */
#if defined(STM32F0) || defined(STM32L0)
gpio_mode_setup(LED_GPIO, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, LED_PIN);
#elif defined(STM32F1)
gpio_set_mode(LED_GPIO, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, LED_PIN);
#endif /* STM32F1 */
}
int main(void)
{
int i;
#if defined(BOOTLOADER8K)
// need to relocate the vector table if the bootloader is in flash
# define SCB_VTOR MMIO32(0xE000ED08)
SCB_VTOR = (uint32_t) 0x08002000;
#endif
#if defined(STM32F1)
// disable JTAG, leave SWD (the bat board has LED on one of the JTAG pins)
rcc_periph_clock_enable(RCC_AFIO);
AFIO_MAPR |= (1<<25); // not universal code; assumes RESET AFIO_MAPR state
rcc_clock_setup_in_hse_16mhz_out_72mhz(); // also test if the ext crystal works
#endif
gpio_setup();
/* Blink the LED on the board. */
while (1) {
gpio_toggle(LED_GPIO, LED_PIN);
// manually set: GPIOA_BRR = GPIO15;
// manually clear: GPIOA_BSRR = GPIO15;
for (i = 0; i < DELAY_CONSTANT; i++)
__asm__("nop");
}
return 0;
}
// vim: tabstop=4:shiftwidth=4:noexpandtab