diff options
author | Denis Shienkov <denis.shienkov@gmail.com> | 2019-03-11 16:29:42 +0300 |
---|---|---|
committer | Denis Shienkov <denis.shienkov@gmail.com> | 2019-04-15 16:32:20 +0000 |
commit | 73fd344ace14080b420f04e6f062e8ff8829162a (patch) | |
tree | 39acf0ec3310b6d6d080236242fd23fcbe18f6ec /examples | |
parent | 77218b44b1b12c2b18e4655e114ec0323285e303 (diff) |
bare-metal: Add example for STM32F4DISCOVERY board
This commit adds a simple example for the ARM-based microcontroller
which blinking of the blue LED and can be built for different toolchains:
* GCC
* IAR EW
* KEIL MDK
Change-Id: Icf9f1bb20356f5ccc532e895754ec0a7928ecdbc
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Diffstat (limited to 'examples')
-rw-r--r-- | examples/baremetal/baremetal.qbs | 58 | ||||
-rw-r--r-- | examples/baremetal/stm32f4discovery/blueblink/README.md | 10 | ||||
-rw-r--r-- | examples/baremetal/stm32f4discovery/blueblink/blueblink.qbs | 165 | ||||
-rw-r--r-- | examples/baremetal/stm32f4discovery/blueblink/gcc/flash.ld | 185 | ||||
-rw-r--r-- | examples/baremetal/stm32f4discovery/blueblink/gcc/startup.s | 211 | ||||
-rw-r--r-- | examples/baremetal/stm32f4discovery/blueblink/gpio.c | 79 | ||||
-rw-r--r-- | examples/baremetal/stm32f4discovery/blueblink/gpio.h | 65 | ||||
-rw-r--r-- | examples/baremetal/stm32f4discovery/blueblink/iar/flash.icf | 77 | ||||
-rw-r--r-- | examples/baremetal/stm32f4discovery/blueblink/iar/startup.s | 171 | ||||
-rw-r--r-- | examples/baremetal/stm32f4discovery/blueblink/keil/flash.sct | 64 | ||||
-rw-r--r-- | examples/baremetal/stm32f4discovery/blueblink/keil/startup.s | 184 | ||||
-rw-r--r-- | examples/baremetal/stm32f4discovery/blueblink/main.c | 69 | ||||
-rw-r--r-- | examples/baremetal/stm32f4discovery/blueblink/system.h | 129 | ||||
-rw-r--r-- | examples/baremetal/stm32f4discovery/stm32f4discovery.qbs | 58 | ||||
-rw-r--r-- | examples/examples.qbs | 1 |
15 files changed, 1526 insertions, 0 deletions
diff --git a/examples/baremetal/baremetal.qbs b/examples/baremetal/baremetal.qbs new file mode 100644 index 000000000..f7b74925a --- /dev/null +++ b/examples/baremetal/baremetal.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: "BareMetal" + references: [ + "stm32f4discovery/stm32f4discovery.qbs" + ] +} diff --git a/examples/baremetal/stm32f4discovery/blueblink/README.md b/examples/baremetal/stm32f4discovery/blueblink/README.md new file mode 100644 index 000000000..d15e12515 --- /dev/null +++ b/examples/baremetal/stm32f4discovery/blueblink/README.md @@ -0,0 +1,10 @@ +This example demonstrates how to build a bare-metal application using +different ARM toolchains. It is designed for the stm32f4discovery +evaluation kit (based on stm32f407vg MCU) and simply flashes the blue +LED on the board. + +The following toolchains are supported: + + * GNU Arm Embedded Toolchain + * IAR Embedded Workbench + * KEIL Microcontroller Development Kit diff --git a/examples/baremetal/stm32f4discovery/blueblink/blueblink.qbs b/examples/baremetal/stm32f4discovery/blueblink/blueblink.qbs new file mode 100644 index 000000000..9b131fa71 --- /dev/null +++ b/examples/baremetal/stm32f4discovery/blueblink/blueblink.qbs @@ -0,0 +1,165 @@ +/**************************************************************************** +** +** 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("arm")) + return false; + return qbs.toolchain.contains("gcc") + || qbs.toolchain.contains("iar") + || qbs.toolchain.contains("keil") + } + name: "blueblink" + 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"] + } + } + + // + // IAR-specific properties and sources. + // + + Properties { + condition: qbs.toolchain.contains("iar") + cpp.driverFlags: [ + "--cpu", "cortex-m4", + "--fpu", "vfpv4_sp" + ] + } + + Group { + condition: qbs.toolchain.contains("iar") + name: "IAR" + prefix: "iar/" + Group { + name: "Startup" + fileTags: ["asm"] + files: ["startup.s"] + } + Group { + name: "Linker Script" + fileTags: ["linkerscript"] + files: ["flash.icf"] + } + } + + // + // KEIL-specific properties and sources. + // + + Properties { + condition: qbs.toolchain.contains("keil") + cpp.driverFlags: [ + "--cpu", "cortex-m4.fp" + ] + } + + Group { + condition: qbs.toolchain.contains("keil") + name: "KEIL" + prefix: "keil/" + Group { + name: "Startup" + fileTags: ["asm"] + files: ["startup.s"] + } + Group { + name: "Linker Script" + fileTags: ["linkerscript"] + files: ["flash.sct"] + } + } + + // + // Common code. + // + + Group { + name: "Gpio" + files: ["gpio.c", "gpio.h"] + } + + Group { + name: "System" + files: ["system.h"] + } + + files: ["main.c"] +} diff --git a/examples/baremetal/stm32f4discovery/blueblink/gcc/flash.ld b/examples/baremetal/stm32f4discovery/blueblink/gcc/flash.ld new file mode 100644 index 000000000..2e1896f3f --- /dev/null +++ b/examples/baremetal/stm32f4discovery/blueblink/gcc/flash.ld @@ -0,0 +1,185 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +/* Entry point (defined in assembled file). */ +ENTRY(reset_handler) + +/* End of RAM, it is the user mode stack pointer address. */ +_end_of_stack = 0x20020000; + +/* Generate a link error if heap and stack don't fit into RAM. */ +_size_of_heap = 0x200; /* Required amount of heap. */ +_size_of_stack = 0x400; /* Required amount of stack. */ + +MEMORY { + RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K + CCMRAM (rw) : ORIGIN = 0x10000000, LENGTH = 64K + FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 1024K +} + +SECTIONS { + /* The vectors table goes into FLASH. */ + .isr_vector : { + . = ALIGN(4); + KEEP(*(.isr_vector)) /* Startup code. */ + . = ALIGN(4); + } > FLASH + + /* The program code and other data goes into FLASH. */ + .text : { + . = ALIGN(4); + *(.text) + *(.text*) + *(.glue_7) /* Glue arm to thumb code. */ + *(.glue_7t) /* Glue thumb to arm code. */ + *(.eh_frame) + KEEP(*(.init)) + KEEP(*(.fini)) + . = ALIGN(4); + _end_of_text_section = .; /* Export global symbol at end of code. */ + } > FLASH + + /* Constant data goes into FLASH. */ + .rodata : { + . = ALIGN(4); + *(.rodata) + *(.rodata*) + . = ALIGN(4); + } > FLASH + + .ARM.extab : { + *(.ARM.extab* .gnu.linkonce.armextab.*) + } > FLASH + + .ARM : { + __exidx_start = .; + *(.ARM.exidx*) + __exidx_end = .; + } > FLASH + + .preinit_array : { + PROVIDE_HIDDEN(__preinit_array_start = .); + KEEP(*(.preinit_array*)) + PROVIDE_HIDDEN(__preinit_array_end = .); + } > FLASH + + .init_array : { + PROVIDE_HIDDEN(__init_array_start = .); + KEEP(*(SORT(.init_array.*))) + KEEP(*(.init_array*)) + PROVIDE_HIDDEN(__init_array_end = .); + } > FLASH + + .fini_array : { + PROVIDE_HIDDEN(__fini_array_start = .); + KEEP(*(SORT(.fini_array.*))) + KEEP(*(.fini_array*)) + PROVIDE_HIDDEN(__fini_array_end = .); + } > FLASH + + _start_of_init_data_section = LOADADDR(.data); + + /* Initialized data sections goes into RAM, load LMA copy after code. */ + .data : { + . = ALIGN(4); + _start_of_data_section = .; /* Export global symbol at data start. */ + *(.data) + *(.data*) + . = ALIGN(4); + _end_of_data_section = .; /* Export global symbol at data end. */ + } > RAM AT > FLASH + + _start_of_iccm_ram_section = LOADADDR(.ccmram); + + /* CCM-RAM section. */ + .ccmram : { + . = ALIGN(4); + _start_of_ccmram_section = .; /* Export global symbol at ccmram start. */ + *(.ccmram) + *(.ccmram*) + . = ALIGN(4); + _end_of_ccmram_section = .; /* Export global symbol at ccmram end. */ + } > CCMRAM AT > FLASH + + /* Uninitialized data section. */ + . = ALIGN(4); + .bss : { + /* This is used by the startup in order to initialize the .bss secion. */ + _start_of_bss_section = .; /* Export global symbol at bss start. */ + __bss_start__ = _start_of_bss_section; + *(.bss) + *(.bss*) + *(COMMON) + . = ALIGN(4); + _end_of_bss_section = .; /* Export global symbol at bss end. */ + __bss_end__ = _end_of_bss_section; + } > RAM + + /* Used to check that there is enough RAM left. */ + ._user_heap_stack : { + . = ALIGN(4); + PROVIDE(end = .); + PROVIDE(_end = .); + . = . + _size_of_heap; + . = . + _size_of_stack; + . = ALIGN(4); + } > RAM + + /* Remove information from the standard libraries. */ + /DISCARD/ : { + libc.a ( * ) + libm.a ( * ) + libgcc.a ( * ) + } + + .ARM.attributes 0 : { + *(.ARM.attributes) + } +} diff --git a/examples/baremetal/stm32f4discovery/blueblink/gcc/startup.s b/examples/baremetal/stm32f4discovery/blueblink/gcc/startup.s new file mode 100644 index 000000000..d6a2104d1 --- /dev/null +++ b/examples/baremetal/stm32f4discovery/blueblink/gcc/startup.s @@ -0,0 +1,211 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +.syntax unified +.cpu cortex-m4 +.fpu softvfp +.thumb + +// These symbols are exported from the linker script. +.word _start_of_init_data_section +.word _start_of_data_section +.word _end_of_data_section +.word _start_of_bss_section +.word _end_of_bss_section +.word _end_of_stack + +// Define the 'reset_handler' function, which is an entry point. +.section .text.reset_handler +.weak reset_handler +.type reset_handler, %function +reset_handler: + // Set the stack pointer. + ldr sp, =_end_of_stack + + // Copy the data segment initializers from flash to SRAM. + movs r1, #0 + b _loop_copy_data_init +_copy_data_init: + ldr r3, =_start_of_init_data_section + ldr r3, [r3, r1] + str r3, [r0, r1] + adds r1, r1, #4 +_loop_copy_data_init: + ldr r0, =_start_of_data_section + ldr r3, =_end_of_data_section + adds r2, r0, r1 + cmp r2, r3 + bcc _copy_data_init + ldr r2, =_start_of_bss_section + b _loop_fill_zero_bss + + // Zero fill the bss segment. +_fill_zero_bss: + movs r3, #0 + str r3, [r2], #4 +_loop_fill_zero_bss: + ldr r3, = _end_of_bss_section + cmp r2, r3 + bcc _fill_zero_bss + + // Call the static constructors. + bl __libc_init_array + + // Call the application's entry point. + bl main + bx lr +.size reset_handler, .-reset_handler + +// Define the empty vectors table. +.section .isr_vector,"a",%progbits +.type _vectors_table, %object +.size _vectors_table, .-_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 // Window WatchDog. + .word 0 // PVD through EXTI Line detection. + .word 0 // Tamper and TimeStamps through the EXTI line. + .word 0 // RTC Wakeup through the EXTI line. + .word 0 // FLASH. + .word 0 // RCC. + .word 0 // EXTI Line0. + .word 0 // EXTI Line1. + .word 0 // EXTI Line2. + .word 0 // EXTI Line3. + .word 0 // EXTI Line4. + .word 0 // DMA1 Stream 0. + .word 0 // DMA1 Stream 1. + .word 0 // DMA1 Stream 2. + .word 0 // DMA1 Stream 3. + .word 0 // DMA1 Stream 4. + .word 0 // DMA1 Stream 5. + .word 0 // DMA1 Stream 6. + .word 0 // ADC1, ADC2 and ADC3s. + .word 0 // CAN1 TX. + .word 0 // CAN1 RX0. + .word 0 // CAN1 RX1. + .word 0 // CAN1 SCE. + .word 0 // External Line[9:5]s. + .word 0 // TIM1 Break and TIM9. + .word 0 // TIM1 Update and TIM10. + .word 0 // TIM1 Trigger and Commutation and TIM11. + .word 0 // TIM1 Capture Compare. + .word 0 // TIM2. + .word 0 // TIM3. + .word 0 // TIM4. + .word 0 // I2C1 Event. + .word 0 // I2C1 Error. + .word 0 // I2C2 Event. + .word 0 // I2C2 Error. + .word 0 // SPI1. + .word 0 // SPI2. + .word 0 // USART1. + .word 0 // USART2. + .word 0 // USART3. + .word 0 // External Line[15:10]s. + .word 0 // RTC Alarm (A and B) through EXTI Line. + .word 0 // USB OTG FS Wakeup through EXTI line. + .word 0 // TIM8 Break and TIM12. + .word 0 // TIM8 Update and TIM13. + .word 0 // TIM8 Trigger and Commutation and TIM14. + .word 0 // TIM8 Capture Compare. + .word 0 // DMA1 Stream7. + .word 0 // FSMC. + .word 0 // SDIO. + .word 0 // TIM5. + .word 0 // SPI3. + .word 0 // UART4. + .word 0 // UART5. + .word 0 // TIM6 and DAC1&2 underrun errors. + .word 0 // TIM7. + .word 0 // DMA2 Stream 0. + .word 0 // DMA2 Stream 1. + .word 0 // DMA2 Stream 2. + .word 0 // DMA2 Stream 3. + .word 0 // DMA2 Stream 4. + .word 0 // Ethernet. + .word 0 // Ethernet Wakeup through EXTI line. + .word 0 // CAN2 TX. + .word 0 // CAN2 RX0. + .word 0 // CAN2 RX1. + .word 0 // CAN2 SCE. + .word 0 // USB OTG FS. + .word 0 // DMA2 Stream 5. + .word 0 // DMA2 Stream 6. + .word 0 // DMA2 Stream 7. + .word 0 // USART6. + .word 0 // I2C3 event. + .word 0 // I2C3 error. + .word 0 // USB OTG HS End Point 1 Out. + .word 0 // USB OTG HS End Point 1 In. + .word 0 // USB OTG HS Wakeup through EXTI. + .word 0 // USB OTG HS. + .word 0 // DCMI. + .word 0 // CRYP crypto. + .word 0 // Hash and Rng. + .word 0 // FPU. diff --git a/examples/baremetal/stm32f4discovery/blueblink/gpio.c b/examples/baremetal/stm32f4discovery/blueblink/gpio.c new file mode 100644 index 000000000..e337f8d24 --- /dev/null +++ b/examples/baremetal/stm32f4discovery/blueblink/gpio.c @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** 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 "system.h" + +#define GPIO_BLUE_LED_PIN_POS (15u) +#define GPIO_BLUE_LED_PIN (1u << GPIO_BLUE_LED_PIN_POS) + +// Output push pull mode. +#define GPIO_MODE_OUTPUT_PP (0x00000001u) + +// Bit definition for RCC_AHB1ENR register. +#define RCC_AHB1ENR_GPIODEN (0x00000008u) +// Bits definition for GPIO_MODER register. +#define GPIO_MODER_MODE0 (0x00000003u) + +void gpio_init_blue_led(void) +{ + // Enable RCC clock on GPIOD port. + RCC_REGS_MAP->AHB1ENR |= RCC_AHB1ENR_GPIODEN; + // Configure GPIO pin #15 as an output. + uint32_t value = GPIOD_REGS_MAP->MODER; + value &= ~(GPIO_MODER_MODE0 << (GPIO_BLUE_LED_PIN_POS * 2u)); + value |= (GPIO_MODE_OUTPUT_PP << (GPIO_BLUE_LED_PIN_POS * 2u)); + GPIOD_REGS_MAP->MODER = value; +} + +void gpio_toggle_blue_led(void) +{ + GPIOD_REGS_MAP->ODR ^= GPIO_BLUE_LED_PIN; +} diff --git a/examples/baremetal/stm32f4discovery/blueblink/gpio.h b/examples/baremetal/stm32f4discovery/blueblink/gpio.h new file mode 100644 index 000000000..560dcbac7 --- /dev/null +++ b/examples/baremetal/stm32f4discovery/blueblink/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_blue_led(void); +void gpio_toggle_blue_led(void); + +#ifdef __cplusplus +} +#endif + +#endif // GPIO_H diff --git a/examples/baremetal/stm32f4discovery/blueblink/iar/flash.icf b/examples/baremetal/stm32f4discovery/blueblink/iar/flash.icf new file mode 100644 index 000000000..04cff04c4 --- /dev/null +++ b/examples/baremetal/stm32f4discovery/blueblink/iar/flash.icf @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +define symbol _start_of_intvec_section = 0x08000000; + +define symbol _start_of_ram_section = 0x20000000; +define symbol _end_of_ram_section = 0x2001FFFF; +define symbol _start_of_ccmram_section = 0x10000000; +define symbol _end_of_ccmram_section = 0x1000FFFF; +define symbol _start_of_flash_section = 0x08000000; +define symbol _end_of_flash_section = 0x080FFFFF; + +define symbol _min_stack_size = 0x400; +define symbol _min_heap_size = 0x200; + +define memory mem with size = 4G; +define region flash_section = mem:[from _start_of_flash_section to _end_of_flash_section]; +define region ram_section = mem:[from _start_of_ram_section to _end_of_ram_section]; +define region ccmram_section = mem:[from _start_of_ccmram_section to _end_of_ccmram_section]; + +define block CSTACK with alignment = 8, size = _min_stack_size { }; +define block HEAP with alignment = 8, size = _min_heap_size { }; + +initialize by copy { readwrite }; +do not initialize { section .noinit }; + +place at address mem:_start_of_intvec_section { readonly section .intvec }; + +place in flash_section { readonly }; +place in ram_section { readwrite, block CSTACK, block HEAP }; diff --git a/examples/baremetal/stm32f4discovery/blueblink/iar/startup.s b/examples/baremetal/stm32f4discovery/blueblink/iar/startup.s new file mode 100644 index 000000000..fe88e6bc8 --- /dev/null +++ b/examples/baremetal/stm32f4discovery/blueblink/iar/startup.s @@ -0,0 +1,171 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + + MODULE ?cstartup + + SECTION CSTACK:DATA:NOROOT(3) + SECTION .intvec:CODE:NOROOT(2) + + EXTERN __iar_program_start + + PUBLIC _vectors_table + DATA +_vectors_table + ;; Generic interrupts offset. + DCD sfe(CSTACK) ; Initial stack pointer value. + DCD reset_handler ; Reset. + DCD 0 ; NMI. + DCD 0 ; Hard fault. + DCD 0 ; Memory management fault. + DCD 0 ; Bus fault. + DCD 0 ; Usage fault. + DCD 0 ; Reserved. + DCD 0 ; Reserved. + DCD 0 ; Reserved. + DCD 0 ; Reserved. + DCD 0 ; SVC. + DCD 0 ; Debug monitor. + DCD 0 ; Reserved. + DCD 0 ; PendSV. + DCD 0 ; SysTick. + ;; External interrupts offset. + DCD 0 ; Window WatchDog. + DCD 0 ; PVD through EXTI Line detection. + DCD 0 ; Tamper and TimeStamps through the EXTI line. + DCD 0 ; RTC Wakeup through the EXTI line. + DCD 0 ; FLASH. + DCD 0 ; RCC. + DCD 0 ; EXTI Line0. + DCD 0 ; EXTI Line1. + DCD 0 ; EXTI Line2. + DCD 0 ; EXTI Line3. + DCD 0 ; EXTI Line4. + DCD 0 ; DMA1 Stream 0. + DCD 0 ; DMA1 Stream 1. + DCD 0 ; DMA1 Stream 2. + DCD 0 ; DMA1 Stream 3. + DCD 0 ; DMA1 Stream 4. + DCD 0 ; DMA1 Stream 5. + DCD 0 ; DMA1 Stream 6. + DCD 0 ; ADC1, ADC2 and ADC3s. + DCD 0 ; CAN1 TX. + DCD 0 ; CAN1 RX0. + DCD 0 ; CAN1 RX1. + DCD 0 ; CAN1 SCE. + DCD 0 ; External Line[9:5]s. + DCD 0 ; TIM1 Break and TIM9. + DCD 0 ; TIM1 Update and TIM10. + DCD 0 ; TIM1 Trigger and Commutation and TIM11. + DCD 0 ; TIM1 Capture Compare. + DCD 0 ; TIM2. + DCD 0 ; TIM3. + DCD 0 ; TIM4. + DCD 0 ; I2C1 Event. + DCD 0 ; I2C1 Error. + DCD 0 ; I2C2 Event. + DCD 0 ; I2C2 Error. + DCD 0 ; SPI1. + DCD 0 ; SPI2. + DCD 0 ; USART1. + DCD 0 ; USART2. + DCD 0 ; USART3. + DCD 0 ; External Line[15:10]s. + DCD 0 ; RTC Alarm (A and B) through EXTI Line. + DCD 0 ; USB OTG FS Wakeup through EXTI line. + DCD 0 ; TIM8 Break and TIM12. + DCD 0 ; TIM8 Update and TIM13. + DCD 0 ; TIM8 Trigger and Commutation and TIM14. + DCD 0 ; TIM8 Capture Compare. + DCD 0 ; DMA1 Stream7. + DCD 0 ; FSMC. + DCD 0 ; SDIO. + DCD 0 ; TIM5. + DCD 0 ; SPI3. + DCD 0 ; UART4. + DCD 0 ; UART5. + DCD 0 ; TIM6 and DAC1&2 underrun errors. + DCD 0 ; TIM7. + DCD 0 ; DMA2 Stream 0. + DCD 0 ; DMA2 Stream 1. + DCD 0 ; DMA2 Stream 2. + DCD 0 ; DMA2 Stream 3. + DCD 0 ; DMA2 Stream 4. + DCD 0 ; Ethernet. + DCD 0 ; Ethernet Wakeup through EXTI line. + DCD 0 ; CAN2 TX. + DCD 0 ; CAN2 RX0. + DCD 0 ; CAN2 RX1. + DCD 0 ; CAN2 SCE. + DCD 0 ; USB OTG FS. + DCD 0 ; DMA2 Stream 5. + DCD 0 ; DMA2 Stream 6. + DCD 0 ; DMA2 Stream 7. + DCD 0 ; USART6. + DCD 0 ; I2C3 event. + DCD 0 ; I2C3 error. + DCD 0 ; USB OTG HS End Point 1 Out. + DCD 0 ; USB OTG HS End Point 1 In. + DCD 0 ; USB OTG HS Wakeup through EXTI. + DCD 0 ; USB OTG HS. + DCD 0 ; DCMI. + DCD 0 ; CRYP crypto. + DCD 0 ; Hash and RNG. + DCD 0 ; FPU. + + ;; Reset handler. + THUMB + PUBWEAK reset_handler + SECTION .text:CODE:REORDER:NOROOT(2) +reset_handler + BLX R0 + LDR R0, =__iar_program_start + BX R0 + + END diff --git a/examples/baremetal/stm32f4discovery/blueblink/keil/flash.sct b/examples/baremetal/stm32f4discovery/blueblink/keil/flash.sct new file mode 100644 index 000000000..7a5500182 --- /dev/null +++ b/examples/baremetal/stm32f4discovery/blueblink/keil/flash.sct @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +;; Load region size_region. +LR_IROM1 0x08000000 0x00100000 { + ;; Load address = execution address. + ER_IROM1 0x08000000 0x00100000 { + *.o (RESET, +First) + *(InRoot$$Sections) + .ANY (+RO) + } + + ; RW data. + RW_IRAM1 0x20000000 0x00020000 { + .ANY (+RW +ZI) + } +} diff --git a/examples/baremetal/stm32f4discovery/blueblink/keil/startup.s b/examples/baremetal/stm32f4discovery/blueblink/keil/startup.s new file mode 100644 index 000000000..38e5b5058 --- /dev/null +++ b/examples/baremetal/stm32f4discovery/blueblink/keil/startup.s @@ -0,0 +1,184 @@ +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; +;; 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$ +;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +_size_of_stack EQU 0x400 +_size_of_heap EQU 0x200 + +;; Stack configuration. + AREA STACK, NOINIT, READWRITE, ALIGN=3 +_start_of_stack SPACE _size_of_stack +_end_of_stack + +;; Heap configuration. + AREA HEAP, NOINIT, READWRITE, ALIGN=3 +_start_of_heap SPACE _size_of_heap +_end_of_heap + + PRESERVE8 + THUMB + +;; Define the empty vectors table. + AREA RESET, DATA, READONLY +_vectors_table + ;; Generic interrupts offset. + DCD _end_of_stack ; Initial stack pointer value. + DCD reset_handler ; Reset. + DCD 0 ; NMI. + DCD 0 ; Hard fault. + DCD 0 ; Memory management fault. + DCD 0 ; Bus fault. + DCD 0 ; Usage fault. + DCD 0 ; Reserved. + DCD 0 ; Reserved. + DCD 0 ; Reserved. + DCD 0 ; Reserved. + DCD 0 ; SVC. + DCD 0 ; Debug monitor. + DCD 0 ; Reserved. + DCD 0 ; PendSV. + DCD 0 ; SysTick. + ;; External interrupts offset. + DCD 0 ; Window WatchDog. + DCD 0 ; PVD through EXTI Line detection. + DCD 0 ; Tamper and TimeStamps through the EXTI line. + DCD 0 ; RTC Wakeup through the EXTI line. + DCD 0 ; FLASH. + DCD 0 ; RCC. + DCD 0 ; EXTI Line0. + DCD 0 ; EXTI Line1. + DCD 0 ; EXTI Line2. + DCD 0 ; EXTI Line3. + DCD 0 ; EXTI Line4. + DCD 0 ; DMA1 Stream 0. + DCD 0 ; DMA1 Stream 1. + DCD 0 ; DMA1 Stream 2. + DCD 0 ; DMA1 Stream 3. + DCD 0 ; DMA1 Stream 4. + DCD 0 ; DMA1 Stream 5. + DCD 0 ; DMA1 Stream 6. + DCD 0 ; ADC1, ADC2 and ADC3s. + DCD 0 ; CAN1 TX. + DCD 0 ; CAN1 RX0. + DCD 0 ; CAN1 RX1. + DCD 0 ; CAN1 SCE. + DCD 0 ; External Line[9:5]s. + DCD 0 ; TIM1 Break and TIM9. + DCD 0 ; TIM1 Update and TIM10. + DCD 0 ; TIM1 Trigger and Commutation and TIM11. + DCD 0 ; TIM1 Capture Compare. + DCD 0 ; TIM2. + DCD 0 ; TIM3. + DCD 0 ; TIM4. + DCD 0 ; I2C1 Event. + DCD 0 ; I2C1 Error. + DCD 0 ; I2C2 Event. + DCD 0 ; I2C2 Error. + DCD 0 ; SPI1. + DCD 0 ; SPI2. + DCD 0 ; USART1. + DCD 0 ; USART2. + DCD 0 ; USART3. + DCD 0 ; External Line[15:10]s. + DCD 0 ; RTC Alarm (A and B) through EXTI Line. + DCD 0 ; USB OTG FS Wakeup through EXTI line. + DCD 0 ; TIM8 Break and TIM12. + DCD 0 ; TIM8 Update and TIM13. + DCD 0 ; TIM8 Trigger and Commutation and TIM14. + DCD 0 ; TIM8 Capture Compare. + DCD 0 ; DMA1 Stream7. + DCD 0 ; FMC. + DCD 0 ; SDIO. + DCD 0 ; TIM5. + DCD 0 ; SPI3. + DCD 0 ; UART4. + DCD 0 ; UART5. + DCD 0 ; TIM6 and DAC1&2 underrun errors. + DCD 0 ; TIM7. + DCD 0 ; DMA2 Stream 0. + DCD 0 ; DMA2 Stream 1. + DCD 0 ; DMA2 Stream 2. + DCD 0 ; DMA2 Stream 3. + DCD 0 ; DMA2 Stream 4. + DCD 0 ; Ethernet. + DCD 0 ; Ethernet Wakeup through EXTI line. + DCD 0 ; CAN2 TX. + DCD 0 ; CAN2 RX0. + DCD 0 ; CAN2 RX1. + DCD 0 ; CAN2 SCE. + DCD 0 ; USB OTG FS. + DCD 0 ; DMA2 Stream 5. + DCD 0 ; DMA2 Stream 6. + DCD 0 ; DMA2 Stream 7. + DCD 0 ; USART6. + DCD 0 ; I2C3 event. + DCD 0 ; I2C3 error. + DCD 0 ; USB OTG HS End Point 1 Out. + DCD 0 ; USB OTG HS End Point 1 In. + DCD 0 ; USB OTG HS Wakeup through EXTI. + DCD 0 ; USB OTG HS. + DCD 0 ; DCMI. + DCD 0 ; Reserved. + DCD 0 ; Hash and Rng. + DCD 0 ; FPU. +_end_of_vectors_table + +_size_of_vectors_table EQU _end_of_vectors_table - _vectors_table + + AREA |.text|, CODE, READONLY +;; Reset handler. +reset_handler PROC + EXPORT reset_handler [WEAK] + IMPORT main + LDR R0, =main + BX R0 + ENDP + ALIGN + + END diff --git a/examples/baremetal/stm32f4discovery/blueblink/main.c b/examples/baremetal/stm32f4discovery/blueblink/main.c new file mode 100644 index 000000000..ef69fc8e6 --- /dev/null +++ b/examples/baremetal/stm32f4discovery/blueblink/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_blue_led(); + + while (1) { + gpio_toggle_blue_led(); + some_delay(100000u); + } +} diff --git a/examples/baremetal/stm32f4discovery/blueblink/system.h b/examples/baremetal/stm32f4discovery/blueblink/system.h new file mode 100644 index 000000000..6e7190026 --- /dev/null +++ b/examples/baremetal/stm32f4discovery/blueblink/system.h @@ -0,0 +1,129 @@ +/**************************************************************************** +** +** 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 SYSTEM_H +#define SYSTEM_H + +#include <stdint.h> + +#ifdef __cplusplus +extern "C" { +#endif + +#define __IO volatile + +// General purpose input/output registers map. +struct gpio_regs_map { + __IO uint32_t MODER; + __IO uint32_t OTYPER; + __IO uint32_t OSPEEDR; + __IO uint32_t PUPDR; + __IO uint32_t IDR; + __IO uint32_t ODR; + __IO uint32_t BSRR; + __IO uint32_t LCKR; + __IO uint32_t AFR[2u]; +}; + +// Reset and clock control registers map. +struct rcc_regs_map { + __IO uint32_t CR; + __IO uint32_t PLLCFGR; + __IO uint32_t CFGR; + __IO uint32_t CIR; + __IO uint32_t AHB1RSTR; + __IO uint32_t AHB2RSTR; + __IO uint32_t AHB3RSTR; + uint32_t RESERVED0; + __IO uint32_t APB1RSTR; + __IO uint32_t APB2RSTR; + uint32_t RESERVED1[2u]; + __IO uint32_t AHB1ENR; + __IO uint32_t AHB2ENR; + __IO uint32_t AHB3ENR; + uint32_t RESERVED2; + __IO uint32_t APB1ENR; + __IO uint32_t APB2ENR; + uint32_t RESERVED3[2u]; + __IO uint32_t AHB1LPENR; + __IO uint32_t AHB2LPENR; + __IO uint32_t AHB3LPENR; + uint32_t RESERVED4; + __IO uint32_t APB1LPENR; + __IO uint32_t APB2LPENR; + uint32_t RESERVED5[2u]; + __IO uint32_t BDCR; + __IO uint32_t CSR; + uint32_t RESERVED6[2u]; + __IO uint32_t SSCGR; + __IO uint32_t PLLI2SCFGR; +}; + +#define PERIPH_ADDRESS (0x40000000u) + +#define APB2PERIPH_ADDRESS (PERIPH_ADDRESS + 0x00010000u) +#define AHB1PERIPH_ADDRESS (PERIPH_ADDRESS + 0x00020000u) + +// APB2 peripherals. +#define SYSCFG_REGS_ADDRESS (APB2PERIPH_ADDRESS + 0x3800u) +#define EXTI_REGS_ADDRESS (APB2PERIPH_ADDRESS + 0x3C00u) + +// AHB1 peripherals. +#define GPIOD_REGS_ADDRESS (AHB1PERIPH_ADDRESS + 0x0C00u) +#define RCC_REGS_ADDRESS (AHB1PERIPH_ADDRESS + 0x3800u) + +#define GPIOD_REGS_MAP ((struct gpio_regs_map *)GPIOD_REGS_ADDRESS) +#define RCC_REGS_MAP ((struct rcc_regs_map *)RCC_REGS_ADDRESS) + +#ifdef __cplusplus +} +#endif + +#endif // SYSTEM_H diff --git a/examples/baremetal/stm32f4discovery/stm32f4discovery.qbs b/examples/baremetal/stm32f4discovery/stm32f4discovery.qbs new file mode 100644 index 000000000..a402848ca --- /dev/null +++ b/examples/baremetal/stm32f4discovery/stm32f4discovery.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 stm32f4discovery board" + references: [ + "blueblink/blueblink.qbs" + ] +} diff --git a/examples/examples.qbs b/examples/examples.qbs index 4e51bdbaf..c6c1f4ac3 100644 --- a/examples/examples.qbs +++ b/examples/examples.qbs @@ -64,5 +64,6 @@ Project { "install-bundle/install-bundle.qbs", "protobuf/cpp/addressbook.qbs", "protobuf/objc/addressbook.qbs", + "baremetal/baremetal.qbs" ] } |