From bc6baf2d986f771926e0bfd8f188f270f2ad8baa Mon Sep 17 00:00:00 2001 From: Denis Shienkov Date: Mon, 18 Mar 2019 18:49:58 +0300 Subject: bare-metal: Add example for CC2540 USB dongle This commit adds a simple example for the 8051-based microcontroller which blinking of the green LED and can be built for different toolchains: * IAR EW * KEIL uVision Change-Id: I8c35594884c60b0980f5c8310f87dd0528ab8799 Reviewed-by: Richard Weickelt Reviewed-by: Christian Kandeler --- examples/baremetal/baremetal.qbs | 3 +- .../baremetal/cc2540usbdongle/cc2540usbdongle.qbs | 58 ++++++++++ .../baremetal/cc2540usbdongle/greenblink/README.md | 9 ++ .../baremetal/cc2540usbdongle/greenblink/gpio.c | 65 +++++++++++ .../baremetal/cc2540usbdongle/greenblink/gpio.h | 65 +++++++++++ .../cc2540usbdongle/greenblink/greenblink.qbs | 122 +++++++++++++++++++++ .../baremetal/cc2540usbdongle/greenblink/main.c | 69 ++++++++++++ .../baremetal/cc2540usbdongle/greenblink/system.h | 78 +++++++++++++ 8 files changed, 468 insertions(+), 1 deletion(-) create mode 100644 examples/baremetal/cc2540usbdongle/cc2540usbdongle.qbs create mode 100644 examples/baremetal/cc2540usbdongle/greenblink/README.md create mode 100644 examples/baremetal/cc2540usbdongle/greenblink/gpio.c create mode 100644 examples/baremetal/cc2540usbdongle/greenblink/gpio.h create mode 100644 examples/baremetal/cc2540usbdongle/greenblink/greenblink.qbs create mode 100644 examples/baremetal/cc2540usbdongle/greenblink/main.c create mode 100644 examples/baremetal/cc2540usbdongle/greenblink/system.h diff --git a/examples/baremetal/baremetal.qbs b/examples/baremetal/baremetal.qbs index 947eba23b..08d41793f 100644 --- a/examples/baremetal/baremetal.qbs +++ b/examples/baremetal/baremetal.qbs @@ -54,6 +54,7 @@ Project { name: "BareMetal" references: [ "stm32f4discovery/stm32f4discovery.qbs", - "at90can128olimex/at90can128olimex.qbs" + "at90can128olimex/at90can128olimex.qbs", + "cc2540usbdongle/cc2540usbdongle.qbs" ] } diff --git a/examples/baremetal/cc2540usbdongle/cc2540usbdongle.qbs b/examples/baremetal/cc2540usbdongle/cc2540usbdongle.qbs new file mode 100644 index 000000000..52e1948eb --- /dev/null +++ b/examples/baremetal/cc2540usbdongle/cc2540usbdongle.qbs @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2019 Denis Shienkov +** 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 cc2540usbdongle board" + references: [ + "greenblink/greenblink.qbs" + ] +} diff --git a/examples/baremetal/cc2540usbdongle/greenblink/README.md b/examples/baremetal/cc2540usbdongle/greenblink/README.md new file mode 100644 index 000000000..4e90293ed --- /dev/null +++ b/examples/baremetal/cc2540usbdongle/greenblink/README.md @@ -0,0 +1,9 @@ +This example demonstrates how to build a bare-metal application using +different MCS-51 toolchains. It is designed for the CC2540 usb dongle +target board (based on Texas Instruments CC2540 wireless MCU) and +simply flashes the green LED on the board. + +The following toolchains are supported: + + * IAR Embedded Workbench + * KEIL uVision diff --git a/examples/baremetal/cc2540usbdongle/greenblink/gpio.c b/examples/baremetal/cc2540usbdongle/greenblink/gpio.c new file mode 100644 index 000000000..a09471460 --- /dev/null +++ b/examples/baremetal/cc2540usbdongle/greenblink/gpio.c @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** Copyright (C) 2019 Denis Shienkov +** 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 "system.h" + +#define GPIO_GREEN_LED_PIN_POS (1u) + +void gpio_init_green_led(void) +{ + P0SEL = 0; // Choose the port. + P0DIR = 0x01; // Set pin0 to output mode. +} + +void gpio_toggle_green_led(void) +{ + P0 ^= GPIO_GREEN_LED_PIN_POS; +} diff --git a/examples/baremetal/cc2540usbdongle/greenblink/gpio.h b/examples/baremetal/cc2540usbdongle/greenblink/gpio.h new file mode 100644 index 000000000..ddeccad0e --- /dev/null +++ b/examples/baremetal/cc2540usbdongle/greenblink/gpio.h @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** Copyright (C) 2019 Denis Shienkov +** 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_green_led(void); +void gpio_toggle_green_led(void); + +#ifdef __cplusplus +} +#endif + +#endif // GPIO_H diff --git a/examples/baremetal/cc2540usbdongle/greenblink/greenblink.qbs b/examples/baremetal/cc2540usbdongle/greenblink/greenblink.qbs new file mode 100644 index 000000000..4dc400404 --- /dev/null +++ b/examples/baremetal/cc2540usbdongle/greenblink/greenblink.qbs @@ -0,0 +1,122 @@ +/**************************************************************************** +** +** Copyright (C) 2019 Denis Shienkov +** 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("mcs51")) + return false; + return qbs.toolchain.contains("iar") + || qbs.toolchain.contains("keil") + } + name: "greenblink" + cpp.positionIndependentCode: false + + // + // IAR-specific properties and sources. + // + + Properties { + condition: qbs.toolchain.contains("iar") + cpp.commonCompilerFlags: ["-e"] + cpp.driverLinkerFlags: [ + "-D_IDATA_STACK_SIZE=0x40", + "-D_PDATA_STACK_SIZE=0x00", + "-D_XDATA_STACK_SIZE=0x00", + "-D_XDATA_HEAP_SIZE=0x00", + "-D_EXTENDED_STACK_SIZE=0", + "-D_EXTENDED_STACK_START=0" + ] + cpp.staticLibraries: [ + cpp.toolchainInstallPath + "/../lib/clib/cl-pli-nsid-1e16x01" + ] + } + + Group { + condition: qbs.toolchain.contains("iar") + name: "IAR" + prefix: "iar/" + Group { + name: "Linker Script" + prefix: cpp.toolchainInstallPath + "/../config/devices/_generic/" + fileTags: ["linkerscript"] + files: ["lnk51ew_8051.xcl"] + } + } + + // + // KEIL-specific properties and sources. + // + + Properties { + condition: qbs.toolchain.contains("keil") + cpp.driverLinkerFlags: [ + "RAMSIZE(256)", + "CODE(0x0000-0xFFFF)" + ] + } + + // + // Common code. + // + + Group { + name: "Gpio" + files: ["gpio.c", "gpio.h"] + } + + Group { + name: "System" + files: ["system.h"] + } + + files: ["main.c"] +} diff --git a/examples/baremetal/cc2540usbdongle/greenblink/main.c b/examples/baremetal/cc2540usbdongle/greenblink/main.c new file mode 100644 index 000000000..88fae04ad --- /dev/null +++ b/examples/baremetal/cc2540usbdongle/greenblink/main.c @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2019 Denis Shienkov +** 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 "system.h" + +static void some_delay(unsigned long counts) +{ + unsigned long index = 0u; + for (index = 0u; index < counts; ++index) + system_nop(); +} + +int main(void) +{ + gpio_init_green_led(); + + while (1) { + gpio_toggle_green_led(); + some_delay(20000u); + } +} diff --git a/examples/baremetal/cc2540usbdongle/greenblink/system.h b/examples/baremetal/cc2540usbdongle/greenblink/system.h new file mode 100644 index 000000000..0b5027bf9 --- /dev/null +++ b/examples/baremetal/cc2540usbdongle/greenblink/system.h @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** Copyright (C) 2019 Denis Shienkov +** 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 SYSTEM_H +#define SYSTEM_H + +#ifdef __cplusplus +extern "C" { +#endif + +#if defined(__ICC8051__) +#include +# define system_nop() __no_operation() +# define SFR(name,addr) __sfr __no_init volatile unsigned char name @ addr; +#elif defined (__C51__) +#include +# define system_nop() _nop_() +# define SFR(name, addr) sfr name = addr; +#else +#error "Unsupported toolchain" +#endif + +SFR(P0 , 0x80u) // Port 0. +SFR(P0SEL, 0xF3u) // Port 0 function select. +SFR(P0DIR, 0xFDu) // Port 0 direction select. + +#ifdef __cplusplus +} +#endif + +#endif // SYSTEM_H -- cgit v1.2.3