Browse Source

Add miniblink (+f1).

flabbergast 1 year ago
parent
commit
ef9fd2db6a
7 changed files with 234 additions and 0 deletions
  1. 4
    0
      README.md
  2. 43
    0
      common.f1.mk
  3. 26
    0
      miniblink/Makefile.f0
  4. 26
    0
      miniblink/Makefile.f1
  5. 26
    0
      miniblink/Makefile.l0
  6. 27
    0
      miniblink/Makefile.l0btld
  7. 82
    0
      miniblink/miniblink.c

+ 4
- 0
README.md View File

@@ -6,6 +6,10 @@ They aren't too specific for the bat boards, except the usual pinout considerati
6 6
 
7 7
 ## Short summary for the examples
8 8
 
9
+### miniblink
10
+
11
+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).
12
+
9 13
 ### blink_btn
10 14
 
11 15
 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
- 0
common.f1.mk View File

@@ -0,0 +1,43 @@
1
+##
2
+## This file is part of the libopencm3 project.
3
+##
4
+## Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
5
+## Copyright (C) 2010 Piotr Esden-Tempski <piotr@esden.net>
6
+##
7
+## This library is free software: you can redistribute it and/or modify
8
+## it under the terms of the GNU Lesser General Public License as published by
9
+## the Free Software Foundation, either version 3 of the License, or
10
+## (at your option) any later version.
11
+##
12
+## This library is distributed in the hope that it will be useful,
13
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
+## GNU Lesser General Public License for more details.
16
+##
17
+## You should have received a copy of the GNU Lesser General Public License
18
+## along with this library.  If not, see <http://www.gnu.org/licenses/>.
19
+##
20
+
21
+LIBNAME		= opencm3_stm32f1
22
+DEFS		+= -DSTM32F1
23
+
24
+FP_FLAGS	?= -msoft-float
25
+ARCH_FLAGS	= -mthumb -mcpu=cortex-m3 $(FP_FLAGS) -mfix-cortex-m3-ldrd
26
+
27
+################################################################################
28
+# OpenOCD specific variables
29
+
30
+OOCD		?= openocd
31
+OOCD_INTERFACE	?= flossjtag
32
+OOCD_BOARD	?= olimex_stm32_h103
33
+
34
+################################################################################
35
+# Black Magic Probe specific variables
36
+# Set the BMP_PORT to a serial port and then BMP is used for flashing
37
+BMP_PORT	?=
38
+
39
+################################################################################
40
+# texane/stlink specific variables
41
+#STLINK_PORT	?= :4242
42
+
43
+include ../libopencm3.rules.mk

+ 26
- 0
miniblink/Makefile.f0 View File

@@ -0,0 +1,26 @@
1
+##
2
+## This file is part of the libopencm3 project.
3
+##
4
+## Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
5
+##
6
+## This library is free software: you can redistribute it and/or modify
7
+## it under the terms of the GNU Lesser General Public License as published by
8
+## the Free Software Foundation, either version 3 of the License, or
9
+## (at your option) any later version.
10
+##
11
+## This library is distributed in the hope that it will be useful,
12
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
+## GNU Lesser General Public License for more details.
15
+##
16
+## You should have received a copy of the GNU Lesser General Public License
17
+## along with this library.  If not, see <http://www.gnu.org/licenses/>.
18
+##
19
+
20
+BINARY = miniblink
21
+
22
+OPENCM3_DIR=../libopencm3
23
+LDSCRIPT = $(OPENCM3_DIR)/lib/stm32/f0/stm32f07xzb.ld
24
+
25
+include ../common.f0.mk
26
+

+ 26
- 0
miniblink/Makefile.f1 View File

@@ -0,0 +1,26 @@
1
+##
2
+## This file is part of the libopencm3 project.
3
+##
4
+## Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
5
+##
6
+## This library is free software: you can redistribute it and/or modify
7
+## it under the terms of the GNU Lesser General Public License as published by
8
+## the Free Software Foundation, either version 3 of the License, or
9
+## (at your option) any later version.
10
+##
11
+## This library is distributed in the hope that it will be useful,
12
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
+## GNU Lesser General Public License for more details.
15
+##
16
+## You should have received a copy of the GNU Lesser General Public License
17
+## along with this library.  If not, see <http://www.gnu.org/licenses/>.
18
+##
19
+
20
+BINARY = miniblink
21
+
22
+OPENCM3_DIR=../libopencm3
23
+LDSCRIPT = $(OPENCM3_DIR)/lib/stm32/f1/stm32f103x8.ld
24
+
25
+include ../common.f1.mk
26
+

+ 26
- 0
miniblink/Makefile.l0 View File

@@ -0,0 +1,26 @@
1
+##
2
+## This file is part of the libopencm3 project.
3
+##
4
+## Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
5
+##
6
+## This library is free software: you can redistribute it and/or modify
7
+## it under the terms of the GNU Lesser General Public License as published by
8
+## the Free Software Foundation, either version 3 of the License, or
9
+## (at your option) any later version.
10
+##
11
+## This library is distributed in the hope that it will be useful,
12
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
+## GNU Lesser General Public License for more details.
15
+##
16
+## You should have received a copy of the GNU Lesser General Public License
17
+## along with this library.  If not, see <http://www.gnu.org/licenses/>.
18
+##
19
+
20
+BINARY = miniblink
21
+
22
+OPENCM3_DIR=../libopencm3
23
+LDSCRIPT = $(OPENCM3_DIR)/lib/stm32/l0/stm32l0xx8.ld
24
+
25
+include ../common.l0.mk
26
+

+ 27
- 0
miniblink/Makefile.l0btld View File

@@ -0,0 +1,27 @@
1
+##
2
+## This file is part of the libopencm3 project.
3
+##
4
+## Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
5
+##
6
+## This library is free software: you can redistribute it and/or modify
7
+## it under the terms of the GNU Lesser General Public License as published by
8
+## the Free Software Foundation, either version 3 of the License, or
9
+## (at your option) any later version.
10
+##
11
+## This library is distributed in the hope that it will be useful,
12
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
+## GNU Lesser General Public License for more details.
15
+##
16
+## You should have received a copy of the GNU Lesser General Public License
17
+## along with this library.  If not, see <http://www.gnu.org/licenses/>.
18
+##
19
+
20
+BINARY = miniblink
21
+
22
+OPENCM3_DIR=../libopencm3
23
+LDSCRIPT = ../l052-bldr.ld
24
+DEFS += -DBOOTLOADER8K
25
+
26
+include ../common.l0.mk
27
+

+ 82
- 0
miniblink/miniblink.c View File

@@ -0,0 +1,82 @@
1
+/*
2
+ * This file is part of the libopencm3 project.
3
+ *
4
+ * Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
5
+ *
6
+ * This library is free software: you can redistribute it and/or modify
7
+ * it under the terms of the GNU Lesser General Public License as published by
8
+ * the Free Software Foundation, either version 3 of the License, or
9
+ * (at your option) any later version.
10
+ *
11
+ * This library is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
+ * GNU Lesser General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU Lesser General Public License
17
+ * along with this library.  If not, see <http://www.gnu.org/licenses/>.
18
+ */
19
+
20
+#include <libopencm3/stm32/rcc.h>
21
+#include <libopencm3/stm32/gpio.h>
22
+
23
+#define LED_GPIO GPIOA
24
+#define LED_PIN GPIO15
25
+#define LED_RCC_GPIO RCC_GPIOA
26
+
27
+// MCUs run at different speeds, so adjust to your liking
28
+#if defined(STM32F0)
29
+#define DELAY_CONSTANT 100000
30
+#elif defined(STM32L0)
31
+#define DELAY_CONSTANT 100000
32
+#elif defined(STM32F1)
33
+#define DELAY_CONSTANT 2000000
34
+#endif /* STM32F1 */
35
+
36
+static void gpio_setup(void)
37
+{
38
+	/* Enable the correct clock. */
39
+	/* Using API functions; for how to do it "manually" see libopencm3-examples/.../miniblink */
40
+	rcc_periph_clock_enable(LED_RCC_GPIO);
41
+
42
+	/* Set LED_PIN to 'output push-pull'. */
43
+#if defined(STM32F0) || defined(STM32L0)
44
+	gpio_mode_setup(LED_GPIO, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, LED_PIN);
45
+#elif defined(STM32F1)
46
+	gpio_set_mode(LED_GPIO, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, LED_PIN);
47
+#endif /* STM32F1 */
48
+}
49
+
50
+int main(void)
51
+{
52
+	int i;
53
+
54
+#if defined(BOOTLOADER8K)
55
+	// need to relocate the vector table if the bootloader is in flash
56
+#		define SCB_VTOR MMIO32(0xE000ED08)
57
+	SCB_VTOR = (uint32_t) 0x08002000;
58
+#endif
59
+
60
+#if defined(STM32F1)
61
+	// disable JTAG, leave SWD (the bat board has LED on one of the JTAG pins)
62
+	rcc_periph_clock_enable(RCC_AFIO);
63
+	AFIO_MAPR |= (1<<25); // not universal code; assumes RESET AFIO_MAPR state 
64
+
65
+	rcc_clock_setup_in_hse_16mhz_out_72mhz(); // also test if the ext crystal works
66
+#endif
67
+
68
+	gpio_setup();
69
+
70
+	/* Blink the LED on the board. */
71
+	while (1) {
72
+		gpio_toggle(LED_GPIO, LED_PIN);
73
+		// manually set: GPIOA_BRR = GPIO15;
74
+		// manually clear: GPIOA_BSRR = GPIO15;
75
+		for (i = 0; i < DELAY_CONSTANT; i++)
76
+			__asm__("nop");
77
+	}
78
+
79
+	return 0;
80
+}
81
+
82
+// vim: tabstop=4:shiftwidth=4:noexpandtab

Loading…
Cancel
Save