You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ma...@apache.org on 2015/12/04 23:03:11 UTC
[5/6] incubator-mynewt-larva git commit: Use bootloader with STM32F3
as well.
Use bootloader with STM32F3 as well.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/commit/14799154
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/14799154
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/14799154
Branch: refs/heads/master
Commit: 14799154f26545ea142f339474a3c3bc0d54e276
Parents: 9ee69e4
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Fri Dec 4 14:01:21 2015 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Fri Dec 4 14:01:21 2015 -0800
----------------------------------------------------------------------
.../stm32f3discovery/boot-stm32f3discovery.ld | 191 +++++++++++++++++++
hw/bsp/stm32f3discovery/src/os_bsp.c | 23 ++-
hw/bsp/stm32f3discovery/src/sbrk.c | 11 +-
hw/bsp/stm32f3discovery/stm32f3discovery.ld | 11 +-
.../stm32f3discovery_download.sh | 34 +++-
5 files changed, 254 insertions(+), 16 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/14799154/hw/bsp/stm32f3discovery/boot-stm32f3discovery.ld
----------------------------------------------------------------------
diff --git a/hw/bsp/stm32f3discovery/boot-stm32f3discovery.ld b/hw/bsp/stm32f3discovery/boot-stm32f3discovery.ld
new file mode 100755
index 0000000..dc01788
--- /dev/null
+++ b/hw/bsp/stm32f3discovery/boot-stm32f3discovery.ld
@@ -0,0 +1,191 @@
+/**
+ * Copyright (c) 2015 Runtime Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+*****************************************************************************
+**
+** File : stm32_flash.ld
+**
+** Abstract : Linker script for bootloader on STM32F303VC Device with
+** 256KByte FLASH, 40KByte RAM
+**
+** Set heap size, stack size and stack location according
+** to application requirements.
+**
+** Set memory bank area and size if external memory is used.
+**
+** Target : STMicroelectronics STM32
+**
+** Distribution: The file is distributed �as is,� without any warranty
+** of any kind.
+**
+** (c)Copyright Atollic AB.
+** You may use this file as-is or modify it according to the needs of your
+** project. This file may only be built (assembled or compiled and linked)
+** using the Atollic TrueSTUDIO(R) product. The use of this file together
+** with other tools than Atollic TrueSTUDIO(R) is not permitted.
+**
+*****************************************************************************
+*/
+
+/* Entry Point */
+ENTRY(Reset_Handler)
+
+/* Highest address of the user mode stack */
+_estack = 0x10002000; /* end of CCMRAM */
+
+/* Generate a link error if heap and stack don't fit into RAM */
+_Min_Heap_Size = 0x2000; /* required amount of heap */
+_Min_Stack_Size = 0x200; /* required amount of stack */
+
+/* Specify the memory areas */
+MEMORY
+{
+ FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 32K
+ RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 40K
+ CCMRAM (rw) : ORIGIN = 0x10000000, LENGTH = 8K
+}
+
+/* Define output sections */
+SECTIONS
+{
+ /* The startup code goes first into FLASH */
+ .isr_vector :
+ {
+ . = ALIGN(4);
+ __isr_vector = .;
+ KEEP(*(.isr_vector)) /* Startup code */
+ __isr_vector_end = .;
+ . = ALIGN(4);
+ } >FLASH
+
+ /* The program code and other data goes into FLASH */
+ .text :
+ {
+ . = ALIGN(4);
+ *(.text) /* .text sections (code) */
+ *(.text*) /* .text* sections (code) */
+ *(.glue_7) /* glue arm to thumb code */
+ *(.glue_7t) /* glue thumb to arm code */
+ *(.eh_frame)
+
+ KEEP (*(.init))
+ KEEP (*(.fini))
+
+ . = ALIGN(4);
+ _etext = .; /* define a global symbols at end of code */
+ } >FLASH
+
+ /* Constant data goes into FLASH */
+ .rodata :
+ {
+ . = ALIGN(4);
+ *(.rodata) /* .rodata sections (constants, strings, etc.) */
+ *(.rodata*) /* .rodata* sections (constants, strings, etc.) */
+ . = 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
+
+ /* used by the startup to initialize data */
+ _sidata = LOADADDR(.data);
+
+ .vector_relocation :
+ {
+ . = ALIGN(4);
+ __vector_tbl_reloc__ = .;
+ . = . + (__isr_vector_end - __isr_vector);
+ . = ALIGN(4);
+ } > CCMRAM
+
+ /* Initialized data sections goes into RAM, load LMA copy after code */
+ .data :
+ {
+ . = ALIGN(4);
+ _sdata = .; /* create a global symbol at data start */
+ *(.data) /* .data sections */
+ *(.data*) /* .data* sections */
+
+ . = ALIGN(4);
+ _edata = .; /* define a global symbol at data end */
+ _sccmram = .; /* create a global symbol at ccmram start */
+ *(.ccmram)
+ *(.ccmram*)
+
+ . = ALIGN(4);
+ _eccmram = .; /* create a 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 */
+ _sbss = .; /* define a global symbol at bss start */
+ __bss_start__ = _sbss;
+ *(.bss)
+ *(.bss*)
+ *(COMMON)
+
+ . = ALIGN(4);
+ _ebss = .; /* define a global symbol at bss end */
+ __bss_end__ = _ebss;
+ } >CCMRAM
+
+ /* User_heap_stack section, placed at the end of RAM */
+ PROVIDE(_user_heap_start = ORIGIN(RAM) + LENGTH(RAM) - _Min_Heap_Size);
+ PROVIDE(_user_heap_end = ORIGIN(RAM) + LENGTH(RAM));
+
+ .stack_dummy :
+ {
+ . = . + _Min_Stack_Size;
+ } > CCMRAM
+
+ /* Remove information from the standard libraries */
+ /DISCARD/ :
+ {
+ libc.a ( * )
+ libm.a ( * )
+ libgcc.a ( * )
+ }
+
+ .ARM.attributes 0 : { *(.ARM.attributes) }
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/14799154/hw/bsp/stm32f3discovery/src/os_bsp.c
----------------------------------------------------------------------
diff --git a/hw/bsp/stm32f3discovery/src/os_bsp.c b/hw/bsp/stm32f3discovery/src/os_bsp.c
index aa69c45..153a255 100644
--- a/hw/bsp/stm32f3discovery/src/os_bsp.c
+++ b/hw/bsp/stm32f3discovery/src/os_bsp.c
@@ -22,15 +22,30 @@ void _close(int fd);
#include <util/flash_map.h>
static struct flash_area bsp_flash_areas[] = {
+ [FLASH_AREA_BOOTLOADER] = {
+ .fa_flash_id = 0, /* internal flash */
+ .fa_off = 0x08000000, /* beginning */
+ .fa_size = (32 * 1024)
+ },
[FLASH_AREA_IMAGE_0] = {
.fa_flash_id = 0,
- .fa_off = 0x08000000,
- .fa_size = (192 * 1024)
+ .fa_off = 0x08008000,
+ .fa_size = (104 * 1024)
+ },
+ [FLASH_AREA_IMAGE_1] = {
+ .fa_flash_id = 0,
+ .fa_off = 0x08022000,
+ .fa_size = (104 * 1024)
+ },
+ [FLASH_AREA_IMAGE_SCRATCH] = {
+ .fa_flash_id = 0,
+ .fa_off = 0x0803c000,
+ .fa_size = (8 * 1024)
},
[FLASH_AREA_NFFS] = {
.fa_flash_id = 0,
- .fa_off = 0x08030000,
- .fa_size = (32 * 1024)
+ .fa_off = 0x0803e000,
+ .fa_size = (8 * 1024)
}
};
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/14799154/hw/bsp/stm32f3discovery/src/sbrk.c
----------------------------------------------------------------------
diff --git a/hw/bsp/stm32f3discovery/src/sbrk.c b/hw/bsp/stm32f3discovery/src/sbrk.c
index 73abc2f..c339bf4 100644
--- a/hw/bsp/stm32f3discovery/src/sbrk.c
+++ b/hw/bsp/stm32f3discovery/src/sbrk.c
@@ -16,14 +16,13 @@
#include <errno.h>
-extern char _end;
+extern char _user_heap_start;
extern char _user_heap_end;
+static char *_brk = &_user_heap_start;
void *
_sbrk(int incr)
{
- static char *brk = &_end;
-
void *prev_brk;
if (incr < 0) {
@@ -31,9 +30,9 @@ _sbrk(int incr)
prev_brk = (void *)-1;
} else {
/* Allocating memory from the heap. */
- if (&_user_heap_end - brk >= incr) {
- prev_brk = brk;
- brk += incr;
+ if (&_user_heap_end - _brk >= incr) {
+ prev_brk = _brk;
+ _brk += incr;
} else {
prev_brk = (void *)-1;
errno = ENOMEM;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/14799154/hw/bsp/stm32f3discovery/stm32f3discovery.ld
----------------------------------------------------------------------
diff --git a/hw/bsp/stm32f3discovery/stm32f3discovery.ld b/hw/bsp/stm32f3discovery/stm32f3discovery.ld
index 2b6b536..e9098d4 100755
--- a/hw/bsp/stm32f3discovery/stm32f3discovery.ld
+++ b/hw/bsp/stm32f3discovery/stm32f3discovery.ld
@@ -55,7 +55,7 @@ _Min_Stack_Size = 0x200; /* required amount of stack */
/* Specify the memory areas */
MEMORY
{
- FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 256K
+ FLASH (rx) : ORIGIN = 0x8008000, LENGTH = 104K
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 40K
CCMRAM (rw) : ORIGIN = 0x10000000, LENGTH = 8K
}
@@ -63,6 +63,12 @@ MEMORY
/* Define output sections */
SECTIONS
{
+ /* Reserve space at the start of the image for the header. */
+ .imghdr (NOLOAD):
+ {
+ . = . + 0x20;
+ } > FLASH
+
/* The startup code goes first into FLASH */
.isr_vector :
{
@@ -190,8 +196,7 @@ SECTIONS
._user_heap :
{
. = ALIGN(4);
- PROVIDE ( end = . );
- PROVIDE ( _end = . );
+ PROVIDE ( _user_heap_start = . );
. = . + _Min_Heap_Size;
. = ALIGN(4);
} >RAM
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/14799154/hw/bsp/stm32f3discovery/stm32f3discovery_download.sh
----------------------------------------------------------------------
diff --git a/hw/bsp/stm32f3discovery/stm32f3discovery_download.sh b/hw/bsp/stm32f3discovery/stm32f3discovery_download.sh
index 4682d56..abfa9cc 100755
--- a/hw/bsp/stm32f3discovery/stm32f3discovery_download.sh
+++ b/hw/bsp/stm32f3discovery/stm32f3discovery_download.sh
@@ -12,10 +12,38 @@ if [ $# -lt 1 ]; then
exit 1
fi
-FLASH_OFFSET=0x08000000
-FILE_NAME=$1.elf.bin
+BASENAME=$1
+IS_BOOTLOADER=0
+BIN2IMG=project/bin2img/bin/bin2img/bin2img.elf
+VER=11.22.3333.0
+VER_FILE=version.txt # or somewhere else
-echo "Downloading" $FILE_NAME
+# Look for 'bootloader' from 2nd arg onwards
+shift
+while [ $# -gt 0 ]; do
+ if [ $1 == "bootloader" ]; then
+ IS_BOOTLOADER=1
+ fi
+ shift
+done
+
+if [ $IS_BOOTLOADER -eq 1 ]; then
+ FLASH_OFFSET=0x08000000
+ FILE_NAME=$BASENAME.elf.bin
+else
+ FLASH_OFFSET=0x08008000
+ FILE_NAME=$BASENAME.elf.img
+ if [ -f $VER_FILE ]; then
+ VER=`echo $VER_FILE`
+ fi
+ echo "Version is >" $VER "<"
+ $BIN2IMG $BASENAME.elf.bin $FILE_NAME $VER
+ if [ "$?" -ne 0 ]; then
+ exit 1
+ fi
+fi
+
+echo "Downloading" $FILE_NAME "to" $FLASH_OFFSET
openocd -f board/stm32f3discovery.cfg -c init -c "reset halt" -c "flash write_image erase $FILE_NAME $FLASH_OFFSET" -c "reset run" -c shutdown