Skip to content

Commit e4f2ef0

Browse files
committed
Merge branch 'master' of github.com:insane-adding-machines/libopencm3-examples
2 parents 8924042 + 55f3fdf commit e4f2ef0

File tree

8 files changed

+303
-0
lines changed

8 files changed

+303
-0
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ TARGETS += lpc/lpc13xx lpc/lpc17xx #lpc/lpc43xx
2525
TARGETS += tiva/lm3s tiva/lm4f
2626
TARGETS += efm32/efm32tg efm32/efm32g efm32/efm32lg efm32/efm32gg
2727
TARGETS += vf6xx
28+
TARGETS += qemu
2829

2930
# Be silent per default, but 'make V=1' will show all compiler calls.
3031
ifneq ($(V),1)

examples/qemu/Makefile.include

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
##
2+
## This file is part of the libopencm3 project.
3+
##
4+
## Copyright (C) 2016 Daniele Lacamera <[email protected]>
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+
LIBNAME = opencm3_lm3s
21+
DEFS += -DLM3S
22+
23+
FP_FLAGS ?= -mfloat-abi=soft
24+
ARCH_FLAGS = -mthumb -mcpu=cortex-m3 $(FP_FLAGS)
25+
26+
################################################################################
27+
# OpenOCD specific variables
28+
29+
OOCD ?= openocd
30+
OOCD_BOARD ?= lm3s6965
31+
32+
################################################################################
33+
# Black Magic Probe specific variables
34+
# Set the BMP_PORT to a serial port and then BMP is used for flashing
35+
BMP_PORT ?=
36+
37+
################################################################################
38+
# texane/stlink specific variables
39+
#STLINK_PORT ?= :4242
40+
41+
42+
include ../../../Makefile.rules
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
##
2+
## This file is part of the libopencm3 project.
3+
##
4+
## Copyright (C) 2016 Daniele Lacamera <[email protected]>
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 = qemu-lm3s
21+
22+
LDSCRIPT = lm3s6965.ld
23+
24+
include ../../Makefile.include
25+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
This project is used as a demonstrator on how to run a small baremetal application
2+
on a LM3S6965 board, which can be emulated on qemu as well (using qemu-system-arm
3+
with -M lm3s6965evb).
4+
5+
For this reason, this application is not portable to other platforms at the moment.
6+
7+
To execute in qemu run:
8+
9+
`make qemu`
10+
11+
To debug using gcc run:
12+
13+
`make qemu-dbg`
14+
15+
and then attach a gdb to localhost tcp port 3333.
16+
17+
Requirements:
18+
qemu-system-arm
19+
openocd
20+
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/*
2+
* This file is part of the libopencm3 project.
3+
*
4+
* Copyright (C) 2009 Uwe Hermann <[email protected]>
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+
/* Generic linker script for LM3S targets using libopencm3. */
21+
22+
/* Memory regions must be defined in the ld script which includes this one. */
23+
24+
/* Enforce emmition of the vector table. */
25+
EXTERN (vector_table)
26+
27+
/* Define the entry point of the output file. */
28+
ENTRY(reset_handler)
29+
30+
/* Define sections. */
31+
SECTIONS
32+
{
33+
.text : {
34+
*(.vectors) /* Vector table */
35+
*(.text*) /* Program code */
36+
. = ALIGN(4);
37+
*(.rodata*) /* Read-only data */
38+
. = ALIGN(4);
39+
} >rom
40+
41+
/* C++ Static constructors/destructors, also used for __attribute__
42+
* ((constructor)) and the likes */
43+
.preinit_array : {
44+
. = ALIGN(4);
45+
__preinit_array_start = .;
46+
KEEP (*(.preinit_array))
47+
__preinit_array_end = .;
48+
} >rom
49+
.init_array : {
50+
. = ALIGN(4);
51+
__init_array_start = .;
52+
KEEP (*(SORT(.init_array.*)))
53+
KEEP (*(.init_array))
54+
__init_array_end = .;
55+
} >rom
56+
.fini_array : {
57+
. = ALIGN(4);
58+
__fini_array_start = .;
59+
KEEP (*(.fini_array))
60+
KEEP (*(SORT(.fini_array.*)))
61+
__fini_array_end = .;
62+
} >rom
63+
64+
/*
65+
* Another section used by C++ stuff, appears when using newlib with
66+
* 64bit (long long) printf support
67+
*/
68+
.ARM.extab : {
69+
*(.ARM.extab*)
70+
} >rom
71+
.ARM.exidx : {
72+
__exidx_start = .;
73+
*(.ARM.exidx*)
74+
__exidx_end = .;
75+
} >rom
76+
77+
. = ALIGN(4);
78+
_etext = .;
79+
80+
.data : {
81+
_data = .;
82+
*(.data*) /* Read-write initialized data */
83+
. = ALIGN(4);
84+
_edata = .;
85+
} >ram AT >rom
86+
_data_loadaddr = LOADADDR(.data);
87+
88+
.bss : {
89+
*(.bss*) /* Read-write zero initialized data */
90+
*(COMMON)
91+
. = ALIGN(4);
92+
_ebss = .;
93+
} >ram
94+
95+
/*
96+
* The .eh_frame section appears to be used for C++ exception handling.
97+
* You may need to fix this if you're using C++.
98+
*/
99+
/DISCARD/ : { *(.eh_frame) }
100+
101+
. = ALIGN(4);
102+
end = .;
103+
}
104+
105+
PROVIDE(_stack = ORIGIN(ram) + LENGTH(ram));
106+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* This file is part of the libopencm3 project.
3+
*
4+
* Copyright (C) 2016 Daniele Lacamera <[email protected]>
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+
/* Linker script for the LM3S6965 chip (256K flash, 64K RAM). */
21+
22+
/* Define memory regions. */
23+
MEMORY
24+
{
25+
rom (rx) : ORIGIN = 0x00000000, LENGTH = 256K
26+
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 64K
27+
}
28+
29+
/* Include the common ld script. */
30+
INCLUDE libopencm3_lm3s.ld
31+
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* This file is part of the libopencm3 project.
3+
*
4+
* Copyright (C) 2016 Daniele Lacamera <[email protected]>
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+
#include <libopencm3/cm3/nvic.h>
20+
#include <libopencm3/cm3/systick.h>
21+
#include <libopencmsis/core_cm3.h>
22+
23+
24+
/* LM3S Specifics, usart and RCC */
25+
#include <libopencm3/lm3s/rcc.h>
26+
#include <libopencm3/lm3s/usart.h>
27+
28+
static volatile uint32_t jiffies = 0u;
29+
30+
static void printbanner(void)
31+
{
32+
char msg[] = "One second elapsed!\r\n";
33+
char *c = msg;
34+
while (*c != 0) {
35+
usart_send(USART0_BASE, (uint16_t )*c);
36+
c++;
37+
}
38+
}
39+
40+
void sys_tick_handler(void)
41+
{
42+
jiffies++;
43+
}
44+
45+
static inline uint32_t systick_app_config(uint32_t n_ticks)
46+
{
47+
/* constant from systick_set_reload -- as this returns something that's
48+
* * not void, this is the only possible error condition */
49+
if (n_ticks & ~0x00FFFFFF) {
50+
return 1;
51+
}
52+
53+
systick_set_reload(n_ticks);
54+
systick_set_clocksource(1);
55+
systick_interrupt_enable();
56+
systick_counter_enable();
57+
58+
return 0;
59+
}
60+
61+
#define HZ 1000
62+
63+
int main(void)
64+
{
65+
rcc_clock_setup_in_xtal_8mhz_out_50mhz();
66+
systick_app_config(HZ);
67+
68+
nvic_set_priority(NVIC_SYSTICK_IRQ, 0);
69+
jiffies = 0;
70+
while(1) {
71+
if (jiffies > HZ) {
72+
printbanner();
73+
jiffies = 0;
74+
}
75+
}
76+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/sh
2+
qemu-system-arm -semihosting -M lm3s6965evb --kernel ./qemu-lm3s.elf -serial stdio

0 commit comments

Comments
 (0)