aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorDenis Shienkov <denis.shienkov@gmail.com>2019-04-16 12:13:55 +0300
committerDenis Shienkov <denis.shienkov@gmail.com>2019-04-17 18:24:43 +0000
commitb8724729191957066ce19786d6de9ee9ccf045e8 (patch)
tree48fff14732abed1bc75f7992bf09763775d47fbb /examples
parent1264505bec44fa7766fc42c4c07344acd50f821c (diff)
bare-metal: Add example for OLIMEX AVR-CAN board
This commit adds a simple example for the AVR-based microcontroller which blinking of the red LED and can be built for different toolchains: * GCC * IAR EW Change-Id: If2c1695f55cf5ed36dcc288f272e5972d4fab3c9 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Diffstat (limited to 'examples')
-rw-r--r--examples/baremetal/at90can128olimex/at90can128olimex.qbs58
-rw-r--r--examples/baremetal/at90can128olimex/redblink/README.md9
-rw-r--r--examples/baremetal/at90can128olimex/redblink/gpio.c76
-rw-r--r--examples/baremetal/at90can128olimex/redblink/gpio.h65
-rw-r--r--examples/baremetal/at90can128olimex/redblink/main.c69
-rw-r--r--examples/baremetal/at90can128olimex/redblink/redblink.qbs130
-rw-r--r--examples/baremetal/baremetal.qbs3
7 files changed, 409 insertions, 1 deletions
diff --git a/examples/baremetal/at90can128olimex/at90can128olimex.qbs b/examples/baremetal/at90can128olimex/at90can128olimex.qbs
new file mode 100644
index 000000000..dc1760fe9
--- /dev/null
+++ b/examples/baremetal/at90can128olimex/at90can128olimex.qbs
@@ -0,0 +1,58 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 Denis Shienkov <denis.shienkov@gmail.com>
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the examples of Qbs.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import qbs
+
+Project {
+ name: "Examples for Olimex AVR-CAN board"
+ references: [
+ "redblink/redblink.qbs"
+ ]
+}
diff --git a/examples/baremetal/at90can128olimex/redblink/README.md b/examples/baremetal/at90can128olimex/redblink/README.md
new file mode 100644
index 000000000..0e9710e57
--- /dev/null
+++ b/examples/baremetal/at90can128olimex/redblink/README.md
@@ -0,0 +1,9 @@
+This examples demonstrates how to build a bare-metal application using
+different AVR toolchains. It is designed for the OLIMEX AVR-CAN target
+board (based on at90can128 chip) and simply flashes the red LED on the
+board.
+
+The following toolchains are supported:
+
+ * GCC
+ * IAR Embedded Workbench
diff --git a/examples/baremetal/at90can128olimex/redblink/gpio.c b/examples/baremetal/at90can128olimex/redblink/gpio.c
new file mode 100644
index 000000000..543e31a8d
--- /dev/null
+++ b/examples/baremetal/at90can128olimex/redblink/gpio.c
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 Denis Shienkov <denis.shienkov@gmail.com>
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the examples of Qbs.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "gpio.h"
+
+#if defined(__GNUC__)
+#include <avr/io.h>
+#elif defined (__ICCAVR__)
+#include <ioavr.h>
+#else
+#error "Unsupported toolchain"
+#endif
+
+// LED pin number.
+#define GPIO_RED_LED_PIN_POS (4u)
+// LED port direction.
+#define GPIO_RED_LED_PORT_DIR (DDRE)
+// LED output port.
+#define GPIO_RED_LED_PORT_OUT (PORTE)
+
+void gpio_init_red_led(void)
+{
+ GPIO_RED_LED_PORT_DIR = 0xFF;
+}
+
+void gpio_toggle_red_led(void)
+{
+ GPIO_RED_LED_PORT_OUT ^= (1u << GPIO_RED_LED_PIN_POS);
+}
diff --git a/examples/baremetal/at90can128olimex/redblink/gpio.h b/examples/baremetal/at90can128olimex/redblink/gpio.h
new file mode 100644
index 000000000..246eab860
--- /dev/null
+++ b/examples/baremetal/at90can128olimex/redblink/gpio.h
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 Denis Shienkov <denis.shienkov@gmail.com>
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the examples of Qbs.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef GPIO_H
+#define GPIO_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void gpio_init_red_led(void);
+void gpio_toggle_red_led(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // GPIO_H
diff --git a/examples/baremetal/at90can128olimex/redblink/main.c b/examples/baremetal/at90can128olimex/redblink/main.c
new file mode 100644
index 000000000..d62f90350
--- /dev/null
+++ b/examples/baremetal/at90can128olimex/redblink/main.c
@@ -0,0 +1,69 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 Denis Shienkov <denis.shienkov@gmail.com>
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the examples of Qbs.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "gpio.h"
+
+#include <stdint.h>
+
+static void some_delay(uint32_t counts)
+{
+ for (uint32_t index = 0u; index < counts; ++index)
+ __asm("nop");
+}
+
+int main(void)
+{
+ gpio_init_red_led();
+
+ while (1) {
+ gpio_toggle_red_led();
+ some_delay(100000u);
+ }
+}
diff --git a/examples/baremetal/at90can128olimex/redblink/redblink.qbs b/examples/baremetal/at90can128olimex/redblink/redblink.qbs
new file mode 100644
index 000000000..bbc0d7261
--- /dev/null
+++ b/examples/baremetal/at90can128olimex/redblink/redblink.qbs
@@ -0,0 +1,130 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 Denis Shienkov <denis.shienkov@gmail.com>
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the examples of Qbs.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import qbs
+
+CppApplication {
+ condition: {
+ if (!qbs.architecture.contains("avr"))
+ return false;
+ return qbs.toolchain.contains("gcc")
+ || qbs.toolchain.contains("iar")
+ }
+ name: "redblink"
+ cpp.cLanguageVersion: "c99"
+ cpp.positionIndependentCode: false
+
+ //
+ // GCC-specific properties and sources.
+ //
+
+ Properties {
+ condition: qbs.toolchain.contains("gcc")
+ cpp.driverFlags: ["-mmcu=at90can128"]
+ }
+
+ // Note: We implicitly use the startup file and the linker script
+ // which are already linked into the avr-gcc toolchain runtime.
+
+ //
+ // IAR-specific properties and sources.
+ //
+
+ Properties {
+ condition: qbs.toolchain.contains("iar")
+ cpp.driverFlags: ["--cpu=can128", "-ms"]
+ cpp.entryPoint: "__program_start"
+ cpp.driverLinkerFlags: [
+ "-D_..X_HEAP_SIZE=0",
+ "-D_..X_NEAR_HEAP_SIZE=20",
+ "-D_..X_CSTACK_SIZE=20",
+ "-D_..X_RSTACK_SIZE=20",
+ "-D_..X_FLASH_CODE_END=1FFFF",
+ "-D_..X_FLASH_BASE=_..X_INTVEC_SIZE",
+ "-D_..X_EXT_SRAM_BASE=_..X_SRAM_END",
+ "-D_..X_EXT_ROM_BASE=_..X_SRAM_END",
+ "-D_..X_EXT_NV_BASE=_..X_SRAM_END",
+ "-D_..X_CSTACK_BASE=_..X_SRAM_BASE",
+ "-D_..X_CSTACK_END=_..X_SRAM_END",
+ "-D_..X_RSTACK_BASE=_..X_SRAM_BASE",
+ "-D_..X_RSTACK_END=_..X_SRAM_END",
+ "-h'1895'(CODE)0-(_..X_INTVEC_SIZE-1)",
+ ]
+ cpp.staticLibraries: [
+ // Explicitly link with the runtime dlib library (which contains
+ // all required startup code and other stuff).
+ cpp.toolchainInstallPath + "/../lib/dlib/dlAVR-3s-ec_mul-n.r90"
+ ]
+ }
+
+ Group {
+ condition: qbs.toolchain.contains("iar")
+ name: "IAR"
+ prefix: "iar/"
+ Group {
+ name: "Linker Script"
+ prefix: cpp.toolchainInstallPath + "/../src/template/"
+ fileTags: ["linkerscript"]
+ // Explicitly use the default linker scripts for current target.
+ files: ["cfg3soim.xcl", "cfgcan128.xcl"]
+ }
+ }
+
+ //
+ // Common code.
+ //
+
+ Group {
+ name: "Gpio"
+ files: ["gpio.c", "gpio.h"]
+ }
+
+ files: ["main.c"]
+}
diff --git a/examples/baremetal/baremetal.qbs b/examples/baremetal/baremetal.qbs
index f7b74925a..947eba23b 100644
--- a/examples/baremetal/baremetal.qbs
+++ b/examples/baremetal/baremetal.qbs
@@ -53,6 +53,7 @@ import qbs
Project {
name: "BareMetal"
references: [
- "stm32f4discovery/stm32f4discovery.qbs"
+ "stm32f4discovery/stm32f4discovery.qbs",
+ "at90can128olimex/at90can128olimex.qbs"
]
}