aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorDenis Shienkov <denis.shienkov@gmail.com>2020-04-27 17:39:23 +0300
committerDenis Shienkov <denis.shienkov@gmail.com>2020-04-28 08:56:35 +0000
commit13041c808e31c7435206fc526bce4aeaddac2e61 (patch)
treeebe62c1a5c788fa05384a18365b32dd5a883a005 /examples
parent13eefe53430631382d6a34efd2ec750fcf90a5a9 (diff)
baremetal: Add GCC toolchain support to pca10040 example
Change-Id: I7a482296ecbcddc91d6ab430155d6a45e32a2cc7 Reviewed-by: Ivan Komissarov <ABBAPOH@gmail.com> Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Diffstat (limited to 'examples')
-rw-r--r--examples/baremetal/pca10040/greenblink/README.md1
-rw-r--r--examples/baremetal/pca10040/greenblink/gcc/flash.ld151
-rw-r--r--examples/baremetal/pca10040/greenblink/gcc/startup.s253
-rw-r--r--examples/baremetal/pca10040/greenblink/greenblink.qbs33
4 files changed, 437 insertions, 1 deletions
diff --git a/examples/baremetal/pca10040/greenblink/README.md b/examples/baremetal/pca10040/greenblink/README.md
index 84c49fff1..8b08365f8 100644
--- a/examples/baremetal/pca10040/greenblink/README.md
+++ b/examples/baremetal/pca10040/greenblink/README.md
@@ -5,4 +5,5 @@ LED on the board.
The following toolchains are supported:
+ * GNU Arm Embedded Toolchain
* KEIL Microcontroller Development Kit
diff --git a/examples/baremetal/pca10040/greenblink/gcc/flash.ld b/examples/baremetal/pca10040/greenblink/gcc/flash.ld
new file mode 100644
index 000000000..b998618ae
--- /dev/null
+++ b/examples/baremetal/pca10040/greenblink/gcc/flash.ld
@@ -0,0 +1,151 @@
+/****************************************************************************
+**
+** Copyright (C) 2020 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$
+**
+****************************************************************************/
+
+ENTRY(reset_handler)
+
+MEMORY
+{
+ FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x80000
+ RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x10000
+ CODE_RAM (rwx) : ORIGIN = 0x800000, LENGTH = 0x10000
+}
+
+SECTIONS {
+ .text : {
+ KEEP(*(.isr_vector))
+ *(.text*)
+ KEEP(*(.init))
+ KEEP(*(.fini))
+ /* .ctors */
+ *crtbegin.o(.ctors)
+ *crtbegin?.o(.ctors)
+ *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors)
+ *(SORT(.ctors.*))
+ *(.ctors)
+ /* .dtors */
+ *crtbegin.o(.dtors)
+ *crtbegin?.o(.dtors)
+ *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors)
+ *(SORT(.dtors.*))
+ *(.dtors)
+ *(.rodata*)
+ *(.eh_frame*)
+ . = ALIGN(4);
+ } > FLASH
+
+ .ARM.extab : {
+ *(.ARM.extab* .gnu.linkonce.armextab.*)
+ . = ALIGN(4);
+ } > FLASH
+
+ _start_of_exidx_section = .;
+ .ARM.exidx : {
+ *(.ARM.exidx* .gnu.linkonce.armexidx.*)
+ . = ALIGN(4);
+ } > FLASH
+ _end_of_exidx_section = .;
+
+ _end_of_code_section = .;
+
+ .data : AT (_end_of_code_section) {
+ _start_of_data_section = .;
+ *(vtable)
+ *(.data*)
+ . = ALIGN(4);
+ /* preinit data */
+ PROVIDE_HIDDEN(__preinit_array_start = .);
+ *(.preinit_array)
+ PROVIDE_HIDDEN(__preinit_array_end = .);
+ . = ALIGN(4);
+ /* init data */
+ PROVIDE_HIDDEN(__init_array_start = .);
+ *(SORT(.init_array.*))
+ *(.init_array)
+ PROVIDE_HIDDEN(__init_array_end = .);
+ . = ALIGN(4);
+ /* finit data */
+ PROVIDE_HIDDEN(__fini_array_start = .);
+ *(SORT(.fini_array.*))
+ *(.fini_array)
+ PROVIDE_HIDDEN(__fini_array_end = .);
+ *(.jcr)
+ . = ALIGN(4);
+ /* All data end */
+ _end_of_data_section = .;
+ } > RAM
+
+ .bss : {
+ . = ALIGN(4);
+ __bss_start__ = .;
+ *(.bss*)
+ *(COMMON)
+ . = ALIGN(4);
+ __bss_end__ = .;
+ } > RAM
+
+ .heap (COPY): {
+ __end__ = .;
+ end = __end__;
+ *(.heap*)
+ _heap_limit = .;
+ } > RAM
+
+ .stack_dummy (COPY): {
+ *(.stack*)
+ } > RAM
+
+ /* Set stack top to end of RAM, and stack limit move down by size of stack_dummy section. */
+ _end_of_stack = ORIGIN(RAM) + LENGTH(RAM);
+ _stack_limit = _end_of_stack - SIZEOF(.stack_dummy);
+ PROVIDE(__stack = _end_of_stack);
+
+ /* Check if data + heap + stack exceeds RAM limit */
+ ASSERT(_stack_limit >= _heap_limit, "region RAM overflowed with stack")
+}
diff --git a/examples/baremetal/pca10040/greenblink/gcc/startup.s b/examples/baremetal/pca10040/greenblink/gcc/startup.s
new file mode 100644
index 000000000..d1fe7e9de
--- /dev/null
+++ b/examples/baremetal/pca10040/greenblink/gcc/startup.s
@@ -0,0 +1,253 @@
+/****************************************************************************
+**
+** Copyright (C) 2020 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$
+**
+****************************************************************************/
+
+.syntax unified
+.arch armv7e-m
+.thumb
+
+// Define the stack.
+.section .stack
+.align 3
+.equ _size_of_stack, 8192
+.globl _end_of_stack
+.globl _stack_limit
+_stack_limit:
+.space _size_of_stack
+.size _stack_limit, . - _stack_limit
+_end_of_stack:
+.size _end_of_stack, . - _end_of_stack
+
+// Define the heap.
+.section .heap
+.align 3
+.equ _size_of_heap, 8192
+.globl _end_of_heap
+.globl _heap_limit
+_end_of_heap:
+.space _size_of_heap
+.size _end_of_heap, . - _end_of_heap
+_heap_limit:
+.size _heap_limit, . - _heap_limit
+
+// Define the empty vectors table.
+.section .isr_vector, "ax"
+.align 2
+.globl _vectors_table
+_vectors_table:
+ // Generic interrupts offset.
+ .word _end_of_stack // Initial stack pointer value.
+ .word reset_handler // Reset.
+ .word 0 // NMI.
+ .word 0 // Hard fault.
+ .word 0 // Memory management fault.
+ .word 0 // Bus fault.
+ .word 0 // Usage fault.
+ .word 0 // Reserved.
+ .word 0 // Reserved.
+ .word 0 // Reserved.
+ .word 0 // Reserved.
+ .word 0 // SVC.
+ .word 0 // Debug monitor.
+ .word 0 // Reserved.
+ .word 0 // PendSV.
+ .word 0 // SysTick.
+
+ // External interrupts offset.
+ .word 0 // POWER CLOCK.
+ .word 0 // RADIO.
+ .word 0 // UARTE0/UART0
+ .word 0 // SPIM0/SPIS0/TWIM0/TWIS0/SPI0/TWI0.
+ .word 0 // SPIM1/SPIS1/TWIM1/TWIS1/SPI1/TWI1.
+ .word 0 // NFCT.
+ .word 0 // GPIOTE.
+ .word 0 // SAADC.
+ .word 0 // TIMER0.
+ .word 0 // TIMER1.
+ .word 0 // TIMER2.
+ .word 0 // RTC0.
+ .word 0 // TEMP.
+ .word 0 // RNG.
+ .word 0 // ECB.
+ .word 0 // CCM_AAR.
+ .word 0 // WDT.
+ .word 0 // RTC1.
+ .word 0 // QDEC.
+ .word 0 // COMP_LPCOMP.
+ .word 0 // SWI0_EGU0.
+ .word 0 // SWI1_EGU1.
+ .word 0 // SWI2_EGU2.
+ .word 0 // SWI3_EGU3.
+ .word 0 // SWI4_EGU4.
+ .word 0 // SWI5_EGU5.
+ .word 0 // TIMER3.
+ .word 0 // TIMER4.
+ .word 0 // PWM0.
+ .word 0 // PDM.
+ .word 0 // Reserved.
+ .word 0 // Reserved.
+ .word 0 // MWU.
+ .word 0 // PWM1.
+ .word 0 // PWM2.
+ .word 0 // SPIM2/SPIS2/SPI2.
+ .word 0 // RTC2.
+ .word 0 // I2S.
+ .word 0 // FPU.
+ .word 0 // Reserved.
+ .word 0 // Reserved.
+ .word 0 // Reserved.
+ .word 0 // Reserved.
+ .word 0 // Reserved.
+ .word 0 // Reserved.
+ .word 0 // Reserved.
+ .word 0 // Reserved.
+ .word 0 // Reserved.
+ .word 0 // Reserved.
+ .word 0 // Reserved.
+ .word 0 // Reserved.
+ .word 0 // Reserved.
+ .word 0 // Reserved.
+ .word 0 // Reserved.
+ .word 0 // Reserved.
+ .word 0 // Reserved.
+ .word 0 // Reserved.
+ .word 0 // Reserved.
+ .word 0 // Reserved.
+ .word 0 // Reserved.
+ .word 0 // Reserved.
+ .word 0 // Reserved.
+ .word 0 // Reserved.
+ .word 0 // Reserved.
+ .word 0 // Reserved.
+ .word 0 // Reserved.
+ .word 0 // Reserved.
+ .word 0 // Reserved.
+ .word 0 // Reserved.
+ .word 0 // Reserved.
+ .word 0 // Reserved.
+ .word 0 // Reserved.
+ .word 0 // Reserved.
+ .word 0 // Reserved.
+ .word 0 // Reserved.
+ .word 0 // Reserved.
+ .word 0 // Reserved.
+ .word 0 // Reserved.
+ .word 0 // Reserved.
+ .word 0 // Reserved.
+ .word 0 // Reserved.
+ .word 0 // Reserved.
+ .word 0 // Reserved.
+ .word 0 // Reserved.
+ .word 0 // Reserved.
+ .word 0 // Reserved.
+ .word 0 // Reserved.
+ .word 0 // Reserved.
+ .word 0 // Reserved.
+ .word 0 // Reserved.
+ .word 0 // Reserved.
+ .word 0 // Reserved.
+ .word 0 // Reserved.
+ .word 0 // Reserved.
+ .word 0 // Reserved.
+ .word 0 // Reserved.
+ .word 0 // Reserved.
+ .word 0 // Reserved.
+ .word 0 // Reserved.
+ .word 0 // Reserved.
+ .word 0 // Reserved.
+ .word 0 // Reserved.
+ .word 0 // Reserved.
+ .word 0 // Reserved.
+ .word 0 // Reserved.
+ .word 0 // Reserved.
+ .word 0 // Reserved.
+ .word 0 // Reserved.
+ .word 0 // Reserved.
+ .word 0 // Reserved.
+ .word 0 // Reserved.
+ .word 0 // Reserved.
+.size _vectors_table, . - _vectors_table
+
+// Define the 'reset_handler' function, which is an entry point.
+.text
+.thumb
+.thumb_func
+.align 1
+.globl reset_handler
+.type reset_handler, %function
+reset_handler:
+ // Loop to copy data from read only memory to RAM.
+ ldr r1, =_end_of_code_section
+ ldr r2, =_start_of_data_section
+ ldr r3, =__bss_start__
+ subs r3, r3, r2
+ ble _copy_data_init_done
+_copy_data_init:
+ subs r3, r3, #4
+ ldr r0, [r1,r3]
+ str r0, [r2,r3]
+ bgt _copy_data_init
+_copy_data_init_done:
+ // Zero fill the bss segment.
+ ldr r1, =__bss_start__
+ ldr r2, =__bss_end__
+ movs r0, 0
+ subs r2, r2, r1
+ ble _loop_fill_zero_bss_done
+
+_loop_fill_zero_bss:
+ subs r2, r2, #4
+ str r0, [r1, r2]
+ bgt _loop_fill_zero_bss
+
+_loop_fill_zero_bss_done:
+ // Call the application's entry point.
+ bl main
+ bx lr
+.size reset_handler, . - reset_handler
diff --git a/examples/baremetal/pca10040/greenblink/greenblink.qbs b/examples/baremetal/pca10040/greenblink/greenblink.qbs
index 8f1c7650c..04a592aee 100644
--- a/examples/baremetal/pca10040/greenblink/greenblink.qbs
+++ b/examples/baremetal/pca10040/greenblink/greenblink.qbs
@@ -54,13 +54,44 @@ CppApplication {
condition: {
if (!qbs.architecture.startsWith("arm"))
return false;
- return qbs.toolchain.contains("keil")
+ return qbs.toolchain.contains("gcc")
+ || qbs.toolchain.contains("keil")
}
name: "pca10040-greenblink"
cpp.cLanguageVersion: "c99"
cpp.positionIndependentCode: false
//
+ // GCC-specific properties and sources.
+ //
+
+ Properties {
+ condition: qbs.toolchain.contains("gcc")
+ cpp.driverFlags: [
+ "-mcpu=cortex-m4",
+ "-mfloat-abi=hard",
+ "-mfpu=fpv4-sp-d16",
+ "-specs=nosys.specs"
+ ]
+ }
+
+ Group {
+ condition: qbs.toolchain.contains("gcc")
+ name: "GCC"
+ prefix: "gcc/"
+ Group {
+ name: "Startup"
+ fileTags: ["asm"]
+ files: ["startup.s"]
+ }
+ Group {
+ name: "Linker Script"
+ fileTags: ["linkerscript"]
+ files: ["flash.ld"]
+ }
+ }
+
+ //
// KEIL-specific properties and sources.
//