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/11/26 00:56:26 UTC

[1/7] incubator-mynewt-larva git commit: Fix __assert_func() prototype. Line number is unsigned int.

Repository: incubator-mynewt-larva
Updated Branches:
  refs/heads/master 1d1aea351 -> b544c2a12


Fix __assert_func() prototype. Line number is unsigned int.


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/4fb0b661
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/4fb0b661
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/4fb0b661

Branch: refs/heads/master
Commit: 4fb0b66163e8dfe55194808993defae28513db8c
Parents: 1d1aea3
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Wed Nov 25 15:43:26 2015 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Wed Nov 25 15:43:26 2015 -0800

----------------------------------------------------------------------
 libs/baselibc/include/assert.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/4fb0b661/libs/baselibc/include/assert.h
----------------------------------------------------------------------
diff --git a/libs/baselibc/include/assert.h b/libs/baselibc/include/assert.h
index 6177190..273058f 100644
--- a/libs/baselibc/include/assert.h
+++ b/libs/baselibc/include/assert.h
@@ -16,8 +16,10 @@
 #define assert(x) ((void)(0))
 
 #else
+#include <stddef.h>
 
-extern void __assert_func(const char *, unsigned int, const char *, const char *);
+extern void __assert_func(const char *, int, const char *, const char *)
+    __attribute((noreturn));
 
 #define assert(x) ((x) ? (void)0 : __assert_func(__FILE__, __LINE__, NULL, NULL))
 


[3/7] incubator-mynewt-larva git commit: Move initial stack to CCMRAM from end of RAM.

Posted by ma...@apache.org.
Move initial stack to CCMRAM from end of RAM.


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/110883b8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/110883b8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/110883b8

Branch: refs/heads/master
Commit: 110883b8201bc6c06a9fb7d11129edcf7a7444d1
Parents: 7ede884
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Wed Nov 25 15:45:50 2015 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Wed Nov 25 15:45:50 2015 -0800

----------------------------------------------------------------------
 hw/bsp/stm32f3discovery/src/sbrk.c          | 13 +++----------
 hw/bsp/stm32f3discovery/stm32f3discovery.ld | 20 ++++++++++++--------
 2 files changed, 15 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/110883b8/hw/bsp/stm32f3discovery/src/sbrk.c
----------------------------------------------------------------------
diff --git a/hw/bsp/stm32f3discovery/src/sbrk.c b/hw/bsp/stm32f3discovery/src/sbrk.c
index f1bbba9..73abc2f 100644
--- a/hw/bsp/stm32f3discovery/src/sbrk.c
+++ b/hw/bsp/stm32f3discovery/src/sbrk.c
@@ -17,7 +17,7 @@
 #include <errno.h>
 
 extern char _end;
-extern char _estack;
+extern char _user_heap_end;
 
 void *
 _sbrk(int incr)
@@ -28,17 +28,10 @@ _sbrk(int incr)
 
     if (incr < 0) {
         /* Returning memory to the heap. */
-        incr = -incr;
-        if (brk - incr < &_estack) {
-            prev_brk = (void *)-1;
-            errno = EINVAL;
-        } else {
-            prev_brk = brk;
-            brk -= incr;
-        }
+        prev_brk = (void *)-1;
     } else {
         /* Allocating memory from the heap. */
-        if (&_estack - brk >= incr) {
+        if (&_user_heap_end - brk >= incr) {
             prev_brk = brk;
             brk += incr;
         } else {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/110883b8/hw/bsp/stm32f3discovery/stm32f3discovery.ld
----------------------------------------------------------------------
diff --git a/hw/bsp/stm32f3discovery/stm32f3discovery.ld b/hw/bsp/stm32f3discovery/stm32f3discovery.ld
index cd770b5..2b6b536 100755
--- a/hw/bsp/stm32f3discovery/stm32f3discovery.ld
+++ b/hw/bsp/stm32f3discovery/stm32f3discovery.ld
@@ -46,7 +46,7 @@
 ENTRY(Reset_Handler)
 
 /* Highest address of the user mode stack */
-_estack = 0x20009FFF;    /* end of RAM */
+_estack = 0x10002000;    /* end of CCMRAM */
 
 /* Generate a link error if heap and stack don't fit into RAM */
 _Min_Heap_Size = 0x200;      /* required amount of heap  */
@@ -55,9 +55,9 @@ _Min_Stack_Size = 0x200; /* required amount of stack */
 /* Specify the memory areas */
 MEMORY
 {
-FLASH (rx)      : ORIGIN = 0x8000000, LENGTH = 256K
-RAM (xrw)      : ORIGIN = 0x20000000, LENGTH = 40K
-CCMRAM (rw)      : ORIGIN = 0x10000000, LENGTH = 8K
+	FLASH (rx)      : ORIGIN = 0x8000000, LENGTH = 256K
+	RAM (xrw)      : ORIGIN = 0x20000000, LENGTH = 40K
+	CCMRAM (rw)      : ORIGIN = 0x10000000, LENGTH = 8K
 }
 
 /* Define output sections */
@@ -187,17 +187,21 @@ SECTIONS
   } >RAM
 
   /* User_heap_stack section, used to check that there is enough RAM left */
-  ._user_heap_stack :
+  ._user_heap :
   {
     . = ALIGN(4);
     PROVIDE ( end = . );
     PROVIDE ( _end = . );
     . = . + _Min_Heap_Size;
-    . = . + _Min_Stack_Size;
     . = ALIGN(4);
-  } >RAM
+  } >RAM  
 
-  
+  _user_heap_end = ORIGIN(RAM) + LENGTH(RAM);
+
+  .stack_dummy :
+  {
+    . = . + _Min_Stack_Size;
+  } > CCMRAM
 
   /* Remove information from the standard libraries */
   /DISCARD/ :


[2/7] incubator-mynewt-larva git commit: Return from _sbrk is -1 on failure, not 0.

Posted by ma...@apache.org.
Return from _sbrk is -1 on failure, not 0.


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/7ede884f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/7ede884f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/7ede884f

Branch: refs/heads/master
Commit: 7ede884fbedc3f13d049ce9d3c003f3e70aeff7d
Parents: 4fb0b66
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Wed Nov 25 15:44:07 2015 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Wed Nov 25 15:44:07 2015 -0800

----------------------------------------------------------------------
 libs/baselibc/src/malloc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/7ede884f/libs/baselibc/src/malloc.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/malloc.c b/libs/baselibc/src/malloc.c
index 1d56de4..3ef5089 100644
--- a/libs/baselibc/src/malloc.c
+++ b/libs/baselibc/src/malloc.c
@@ -169,7 +169,7 @@ retry_alloc:
 	}
         if (result == NULL) {
             more_mem = _sbrk(size);
-            if (more_mem) {
+            if (more_mem != (void *)-1) {
                 add_malloc_block(more_mem, size);
                 goto retry_alloc;
             }


[6/7] incubator-mynewt-larva git commit: Change bsp_flash_dev to return const struct hal_flash *. Change HAL flash interface to have a routine which reports info about sector start/size, as opposed to an array of sector start address (STM32F3 has 2K sect

Posted by ma...@apache.org.
Change bsp_flash_dev to return const struct hal_flash *.
Change HAL flash interface to have a routine which reports
info about sector start/size, as opposed to an array of sector
start address (STM32F3 has 2K sectors, so array would be quite
large).


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/0364a00f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/0364a00f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/0364a00f

Branch: refs/heads/master
Commit: 0364a00fd293ee8db413b4d7c9136ac3b14043d4
Parents: 47c7037
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Wed Nov 25 15:51:22 2015 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Wed Nov 25 15:51:22 2015 -0800

----------------------------------------------------------------------
 hw/bsp/native/src/hal_bsp.c                     |  4 +-
 hw/bsp/olimex_stm32-e407_devboard/src/hal_bsp.c |  2 +-
 hw/hal/include/hal/hal_flash_int.h              |  7 ++--
 hw/hal/src/hal_flash.c                          | 40 ++++++++++----------
 hw/mcu/native/src/hal_flash.c                   | 14 ++++++-
 hw/mcu/stm/stm32f4xx/src/hal_flash.c            | 19 ++++++++--
 libs/util/src/flash_map.c                       | 22 ++++++-----
 libs/util/src/test/flash_map_test.c             |  2 +-
 8 files changed, 69 insertions(+), 41 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/0364a00f/hw/bsp/native/src/hal_bsp.c
----------------------------------------------------------------------
diff --git a/hw/bsp/native/src/hal_bsp.c b/hw/bsp/native/src/hal_bsp.c
index 6ece5e9..389c49a 100644
--- a/hw/bsp/native/src/hal_bsp.c
+++ b/hw/bsp/native/src/hal_bsp.c
@@ -21,7 +21,7 @@
 #include "hal/hal_flash_int.h"
 #include "mcu/native_bsp.h"
 
-struct hal_flash *
+const struct hal_flash *
 bsp_flash_dev(uint8_t id)
 {
     /*
@@ -30,5 +30,5 @@ bsp_flash_dev(uint8_t id)
     if (id != 0) {
         return NULL;
     }
-    return (struct hal_flash *)&native_flash_dev;
+    return &native_flash_dev;
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/0364a00f/hw/bsp/olimex_stm32-e407_devboard/src/hal_bsp.c
----------------------------------------------------------------------
diff --git a/hw/bsp/olimex_stm32-e407_devboard/src/hal_bsp.c b/hw/bsp/olimex_stm32-e407_devboard/src/hal_bsp.c
index b83c60a..7cf530e 100644
--- a/hw/bsp/olimex_stm32-e407_devboard/src/hal_bsp.c
+++ b/hw/bsp/olimex_stm32-e407_devboard/src/hal_bsp.c
@@ -42,7 +42,7 @@ bsp_uart_config(int port)
     return &uart_cfg[port];
 }
 
-struct hal_flash *
+const struct hal_flash *
 bsp_flash_dev(uint8_t id)
 {
     /*

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/0364a00f/hw/hal/include/hal/hal_flash_int.h
----------------------------------------------------------------------
diff --git a/hw/hal/include/hal/hal_flash_int.h b/hw/hal/include/hal/hal_flash_int.h
index 30b74b0..ab7e159 100644
--- a/hw/hal/include/hal/hal_flash_int.h
+++ b/hw/hal/include/hal/hal_flash_int.h
@@ -25,22 +25,23 @@ struct hal_flash_funcs {
     int (*hff_read)(uint32_t address, void *dst, uint32_t num_bytes);
     int (*hff_write)(uint32_t address, const void *src, uint32_t num_bytes);
     int (*hff_erase_sector)(uint32_t sector_address);
+    int (*hff_sector_info)(int idx, uint32_t *address, uint32_t *size);
     int (*hff_init)(void);
 };
 
 struct hal_flash {
     const struct hal_flash_funcs *hf_itf;
+    uint32_t hf_base_addr;
     uint32_t hf_size;
     int hf_sector_cnt;
-    const uint32_t *hf_sectors;
 };
 
 /*
  * Return size of the flash sector. sec_idx is index to hf_sectors array.
  */
-uint32_t hal_flash_sector_size(struct hal_flash *hf, int sec_idx);
+uint32_t hal_flash_sector_size(const struct hal_flash *hf, int sec_idx);
 
 /* External function prototype supplied by BSP */
-struct hal_flash *bsp_flash_dev(uint8_t flash_id);
+const struct hal_flash *bsp_flash_dev(uint8_t flash_id);
 
 #endif /* H_HAL_FLASH_INT */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/0364a00f/hw/hal/src/hal_flash.c
----------------------------------------------------------------------
diff --git a/hw/hal/src/hal_flash.c b/hw/hal/src/hal_flash.c
index a921fb6..90fd985 100644
--- a/hw/hal/src/hal_flash.c
+++ b/hw/hal/src/hal_flash.c
@@ -14,6 +14,7 @@
  * limitations under the License.
  */
 #include <inttypes.h>
+#include <assert.h>
 #include <bsp/bsp.h>
 
 #include "hal/hal_flash.h"
@@ -22,7 +23,7 @@
 int
 hal_flash_init(void)
 {
-    struct hal_flash *hf;
+    const struct hal_flash *hf;
     uint8_t i;
     int rc = 0;
 
@@ -39,22 +40,21 @@ hal_flash_init(void)
 }
 
 uint32_t
-hal_flash_sector_size(struct hal_flash *hf, int sec_idx)
+hal_flash_sector_size(const struct hal_flash *hf, int sec_idx)
 {
-    uint32_t end;
+    uint32_t size;
+    uint32_t start;
 
-    if (sec_idx < hf->hf_sector_cnt - 1) {
-        end = hf->hf_sectors[sec_idx + 1];
-    } else {
-        end = hf->hf_sectors[0] + hf->hf_size;
+    if (hf->hf_itf->hff_sector_info(sec_idx, &start, &size)) {
+        return 0;
     }
-    return end - hf->hf_sectors[sec_idx];
+    return size;
 }
 
 static int
-hal_flash_check_addr(struct hal_flash *hf, uint32_t addr)
+hal_flash_check_addr(const struct hal_flash *hf, uint32_t addr)
 {
-    if (addr < hf->hf_sectors[0] || addr > hf->hf_sectors[0] + hf->hf_size) {
+    if (addr < hf->hf_base_addr || addr > hf->hf_base_addr + hf->hf_size) {
         return -1;
     }
     return 0;
@@ -63,7 +63,7 @@ hal_flash_check_addr(struct hal_flash *hf, uint32_t addr)
 int
 hal_flash_read(uint8_t id, uint32_t address, void *dst, uint32_t num_bytes)
 {
-    struct hal_flash *hf;
+    const struct hal_flash *hf;
 
     hf = bsp_flash_dev(id);
     if (!hf) {
@@ -80,7 +80,7 @@ int
 hal_flash_write(uint8_t id, uint32_t address, const void *src,
   uint32_t num_bytes)
 {
-    struct hal_flash *hf;
+    const struct hal_flash *hf;
 
     hf = bsp_flash_dev(id);
     if (!hf) {
@@ -96,7 +96,7 @@ hal_flash_write(uint8_t id, uint32_t address, const void *src,
 int
 hal_flash_erase_sector(uint8_t id, uint32_t sector_address)
 {
-    struct hal_flash *hf;
+    const struct hal_flash *hf;
 
     hf = bsp_flash_dev(id);
     if (!hf) {
@@ -111,11 +111,12 @@ hal_flash_erase_sector(uint8_t id, uint32_t sector_address)
 int
 hal_flash_erase(uint8_t id, uint32_t address, uint32_t num_bytes)
 {
-    struct hal_flash *hf;
+    const struct hal_flash *hf;
+    uint32_t start, size;
     uint32_t end;
     uint32_t end_area;
-    const uint32_t *area;
     int i;
+    int rc;
 
     hf = bsp_flash_dev(id);
     if (!hf) {
@@ -133,16 +134,17 @@ hal_flash_erase(uint8_t id, uint32_t address, uint32_t num_bytes)
          */
         return -1;
     }
-    area = hf->hf_sectors;
 
     for (i = 0; i < hf->hf_sector_cnt; i++) {
-        end_area = area[i] + hal_flash_sector_size(hf, i);
-        if (address < end_area && end > area[i]) {
+        rc = hf->hf_itf->hff_sector_info(i, &start, &size);
+        assert(rc == 0);
+        end_area = start + size;
+        if (address < end_area && end > start) {
             /*
              * If some region of eraseable area falls inside sector,
              * erase the sector.
              */
-            if (hf->hf_itf->hff_erase_sector(area[i])) {
+            if (hf->hf_itf->hff_erase_sector(start)) {
                 return -1;
             }
         }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/0364a00f/hw/mcu/native/src/hal_flash.c
----------------------------------------------------------------------
diff --git a/hw/mcu/native/src/hal_flash.c b/hw/mcu/native/src/hal_flash.c
index 64ff1f1..98eb6df 100644
--- a/hw/mcu/native/src/hal_flash.c
+++ b/hw/mcu/native/src/hal_flash.c
@@ -32,11 +32,13 @@ static int native_flash_read(uint32_t address, void *dst, uint32_t length);
 static int native_flash_write(uint32_t address, const void *src,
   uint32_t length);
 static int native_flash_erase_sector(uint32_t sector_address);
+static int native_flash_sector_info(int idx, uint32_t *address, uint32_t *size);
 
 static const struct hal_flash_funcs native_flash_funcs = {
     .hff_read = native_flash_read,
     .hff_write = native_flash_write,
     .hff_erase_sector = native_flash_erase_sector,
+    .hff_sector_info = native_flash_sector_info,
     .hff_init = native_flash_init
 };
 
@@ -60,9 +62,9 @@ static const uint32_t native_flash_sectors[] = {
 
 const struct hal_flash native_flash_dev = {
     .hf_itf = &native_flash_funcs,
+    .hf_base_addr = 0,
     .hf_size = 1024 * 1024,
     .hf_sector_cnt = FLASH_NUM_AREAS,
-    .hf_sectors = native_flash_sectors
 };
 
 static void
@@ -217,6 +219,16 @@ native_flash_erase_sector(uint32_t sector_address)
 }
 
 static int
+native_flash_sector_info(int idx, uint32_t *address, uint32_t *size)
+{
+    assert(idx < FLASH_NUM_AREAS);
+
+    *address = native_flash_sectors[idx];
+    *size = flash_sector_len(idx);
+    return 0;
+}
+
+static int
 native_flash_init(void)
 {
     if (native_flash_file) {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/0364a00f/hw/mcu/stm/stm32f4xx/src/hal_flash.c
----------------------------------------------------------------------
diff --git a/hw/mcu/stm/stm32f4xx/src/hal_flash.c b/hw/mcu/stm/stm32f4xx/src/hal_flash.c
index ba93941..522e6b7 100644
--- a/hw/mcu/stm/stm32f4xx/src/hal_flash.c
+++ b/hw/mcu/stm/stm32f4xx/src/hal_flash.c
@@ -24,12 +24,14 @@ static int stm32f4_flash_read(uint32_t address, void *dst, uint32_t num_bytes);
 static int stm32f4_flash_write(uint32_t address, const void *src,
   uint32_t num_bytes);
 static int stm32f4_flash_erase_sector(uint32_t sector_address);
+static int stm32f4_flash_sector_info(int idx, uint32_t *address, uint32_t *sz);
 static int stm32f4_flash_init(void);
 
 static const struct hal_flash_funcs stm32f4_flash_funcs = {
     .hff_read = stm32f4_flash_read,
     .hff_write = stm32f4_flash_write,
     .hff_erase_sector = stm32f4_flash_erase_sector,
+    .hff_sector_info = stm32f4_flash_sector_info,
     .hff_init = stm32f4_flash_init
 };
 
@@ -45,7 +47,8 @@ static const uint32_t stm32f4_flash_sectors[] = {
     0x08080000,
     0x080a0000,
     0x080c0000,
-    0x080e0000
+    0x080e0000,
+    0x08100000		/* End of flash */
 };
 
 #define STM32F4_FLASH_NUM_AREAS                                         \
@@ -54,9 +57,9 @@ static const uint32_t stm32f4_flash_sectors[] = {
 
 const struct hal_flash stm32f4_flash_dev = {
     .hf_itf = &stm32f4_flash_funcs,
+    .hf_base_addr = 0x08000000,
     .hf_size = 1024 * 1024,
-    .hf_sector_cnt = STM32F4_FLASH_NUM_AREAS,
-    .hf_sectors = stm32f4_flash_sectors
+    .hf_sector_cnt = STM32F4_FLASH_NUM_AREAS - 1,
 };
 
 static int
@@ -102,7 +105,7 @@ stm32f4_flash_erase_sector(uint32_t sector_address)
 {
     int i;
 
-    for (i = 0; i < STM32F4_FLASH_NUM_AREAS; i++) {
+    for (i = 0; i < STM32F4_FLASH_NUM_AREAS - 1; i++) {
         if (stm32f4_flash_sectors[i] == sector_address) {
             stm32f4_flash_erase_sector_id(i);
             return 0;
@@ -113,6 +116,14 @@ stm32f4_flash_erase_sector(uint32_t sector_address)
 }
 
 static int
+stm32f4_flash_sector_info(int idx, uint32_t *address, uint32_t *sz)
+{
+    *address = stm32f4_flash_sectors[idx];
+    *sz = stm32f4_flash_sectors[idx + 1] - stm32f4_flash_sectors[idx];
+    return 0;
+}
+
+static int
 stm32f4_flash_init(void)
 {
     HAL_FLASH_Unlock();

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/0364a00f/libs/util/src/flash_map.c
----------------------------------------------------------------------
diff --git a/libs/util/src/flash_map.c b/libs/util/src/flash_map.c
index b035b78..28f26c9 100644
--- a/libs/util/src/flash_map.c
+++ b/libs/util/src/flash_map.c
@@ -55,8 +55,9 @@ int
 flash_area_to_sectors(int idx, int *cnt, struct flash_area *ret)
 {
     int i;
-    struct hal_flash *hf;
+    const struct hal_flash *hf;
     const struct flash_area *fa;
+    uint32_t start, size;
 
     if (!flash_map || idx >= flash_map_entries) {
         return -1;
@@ -66,12 +67,12 @@ flash_area_to_sectors(int idx, int *cnt, struct flash_area *ret)
 
     hf = bsp_flash_dev(fa->fa_flash_id);
     for (i = 0; i < hf->hf_sector_cnt; i++) {
-        if (hf->hf_sectors[i] >= fa->fa_off &&
-          hf->hf_sectors[i] < fa->fa_off + fa->fa_size) {
+        hf->hf_itf->hff_sector_info(i, &start, &size);
+        if (start >= fa->fa_off && start < fa->fa_off + fa->fa_size) {
             if (ret) {
                 ret->fa_flash_id = fa->fa_flash_id;
-                ret->fa_off = hf->hf_sectors[i];
-                ret->fa_size = hal_flash_sector_size(hf, i);
+                ret->fa_off = start;
+                ret->fa_size = size;
                 ret++;
             }
             *cnt = *cnt + 1;
@@ -85,8 +86,9 @@ int
 flash_area_to_nffs_desc(int idx, int *cnt, struct nffs_area_desc *nad)
 {
     int i;
-    struct hal_flash *hf;
+    const struct hal_flash *hf;
     const struct flash_area *fa;
+    uint32_t start, size;
 
     if (!flash_map || idx >= flash_map_entries) {
         return -1;
@@ -96,12 +98,12 @@ flash_area_to_nffs_desc(int idx, int *cnt, struct nffs_area_desc *nad)
 
     hf = bsp_flash_dev(fa->fa_flash_id);
     for (i = 0; i < hf->hf_sector_cnt; i++) {
-        if (hf->hf_sectors[i] >= fa->fa_off &&
-          hf->hf_sectors[i] < fa->fa_off + fa->fa_size) {
+        hf->hf_itf->hff_sector_info(i, &start, &size);
+        if (start >= fa->fa_off && start < fa->fa_off + fa->fa_size) {
             if (nad) {
                 nad->nad_flash_id = fa->fa_flash_id;
-                nad->nad_offset = hf->hf_sectors[i];
-                nad->nad_length = hal_flash_sector_size(hf, i);
+                nad->nad_offset = start;
+                nad->nad_length = size;
                 nad++;
             }
             *cnt = *cnt + 1;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/0364a00f/libs/util/src/test/flash_map_test.c
----------------------------------------------------------------------
diff --git a/libs/util/src/test/flash_map_test.c b/libs/util/src/test/flash_map_test.c
index ab7cef2..005139c 100644
--- a/libs/util/src/test/flash_map_test.c
+++ b/libs/util/src/test/flash_map_test.c
@@ -31,7 +31,7 @@ TEST_CASE(flash_map_test_case_1)
     const struct flash_area *fa;
     int areas_checked = 0;
     int i, j, rc;
-    struct hal_flash *hf;
+    const struct hal_flash *hf;
     struct flash_area my_secs[32];
     int my_sec_cnt;
     uint32_t end;


[7/7] incubator-mynewt-larva git commit: First take on HAL flash implementation for STM32F3.

Posted by ma...@apache.org.
First take on HAL flash implementation for STM32F3.


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/b544c2a1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/b544c2a1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/b544c2a1

Branch: refs/heads/master
Commit: b544c2a12e958ac3585f72a0ac2546f10eaeee65
Parents: 0364a00
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Wed Nov 25 15:54:54 2015 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Wed Nov 25 15:54:54 2015 -0800

----------------------------------------------------------------------
 hw/bsp/stm32f3discovery/src/hal_bsp.c          |  18 ++-
 hw/bsp/stm32f3discovery/src/os_bsp.c           |  20 ++++
 hw/mcu/stm/stm32f3xx/include/mcu/stm32f3_bsp.h |   3 +
 hw/mcu/stm/stm32f3xx/src/hal_flash.c           | 122 ++++++++++++++++++++
 4 files changed, 162 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b544c2a1/hw/bsp/stm32f3discovery/src/hal_bsp.c
----------------------------------------------------------------------
diff --git a/hw/bsp/stm32f3discovery/src/hal_bsp.c b/hw/bsp/stm32f3discovery/src/hal_bsp.c
index 74c468c..bcdd8b9 100644
--- a/hw/bsp/stm32f3discovery/src/hal_bsp.c
+++ b/hw/bsp/stm32f3discovery/src/hal_bsp.c
@@ -13,7 +13,10 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+#include <stddef.h>
+
 #include "hal/hal_gpio.h"
+#include "hal/hal_flash_int.h"
 #include "mcu/stm32f30x.h"
 #include "mcu/stm32f30x_rcc.h"
 #include "mcu/stm32f30x_gpio.h"
@@ -34,8 +37,21 @@ static const struct stm32f3_uart_cfg uart_cfg[UART_CNT] = {
     }
 };
 
-const struct stm32f3_uart_cfg *bsp_uart_config(int port)
+const struct stm32f3_uart_cfg *
+bsp_uart_config(int port)
 {
     assert(port < UART_CNT);
     return &uart_cfg[port];
 }
+
+const struct hal_flash *
+bsp_flash_dev(uint8_t id)
+{
+    /*
+     * Internal flash mapped to id 0.
+     */
+    if (id != 0) {
+        return NULL;
+    }
+    return &stm32f3_flash_dev;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b544c2a1/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 865b804..aa69c45 100644
--- a/hw/bsp/stm32f3discovery/src/os_bsp.c
+++ b/hw/bsp/stm32f3discovery/src/os_bsp.c
@@ -16,6 +16,24 @@
 void *_sbrk(int incr);
 void _close(int fd);
 
+/*
+ * XXXX for now have it here.
+ */
+#include <util/flash_map.h>
+
+static struct flash_area bsp_flash_areas[] = {
+    [FLASH_AREA_IMAGE_0] = {
+        .fa_flash_id = 0,
+        .fa_off = 0x08000000,
+        .fa_size = (192 * 1024)
+    },
+    [FLASH_AREA_NFFS] = {
+        .fa_flash_id = 0,
+        .fa_off = 0x08030000,
+        .fa_size = (32 * 1024)
+    }
+};
+
 void
 os_bsp_init(void)
 {
@@ -24,4 +42,6 @@ os_bsp_init(void)
      */
     _sbrk(0);
     _close(0);
+    flash_area_init(bsp_flash_areas,
+      sizeof(bsp_flash_areas) / sizeof(bsp_flash_areas[0]));
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b544c2a1/hw/mcu/stm/stm32f3xx/include/mcu/stm32f3_bsp.h
----------------------------------------------------------------------
diff --git a/hw/mcu/stm/stm32f3xx/include/mcu/stm32f3_bsp.h b/hw/mcu/stm/stm32f3xx/include/mcu/stm32f3_bsp.h
index 58023fb..d9871d4 100644
--- a/hw/mcu/stm/stm32f3xx/include/mcu/stm32f3_bsp.h
+++ b/hw/mcu/stm/stm32f3xx/include/mcu/stm32f3_bsp.h
@@ -39,4 +39,7 @@ const struct stm32f3_uart_cfg *bsp_uart_config(int port);
  */
 int hal_gpio_init_af(int pin, uint8_t af_type, enum gpio_pull pull);
 
+struct hal_flash;
+extern const struct hal_flash stm32f3_flash_dev;
+
 #endif /* __MCU_STM32F3_BSP_H_ */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b544c2a1/hw/mcu/stm/stm32f3xx/src/hal_flash.c
----------------------------------------------------------------------
diff --git a/hw/mcu/stm/stm32f3xx/src/hal_flash.c b/hw/mcu/stm/stm32f3xx/src/hal_flash.c
new file mode 100644
index 0000000..35cc31b
--- /dev/null
+++ b/hw/mcu/stm/stm32f3xx/src/hal_flash.c
@@ -0,0 +1,122 @@
+/**
+ * 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.
+ */
+
+/*
+ * Internal flash for STM32F3.
+ * Size of the flash depends on the MCU model, flash is memory mapped
+ * and is divided to 2k sectors throughout.
+ * Programming is done 2 bytes at a time.
+ */
+#include <string.h>
+#include <assert.h>
+#include <hal/hal_flash_int.h>
+
+#include "mcu/stm32f30x.h"
+#include "mcu/stm32f30x_flash.h"
+
+#define STM32F3_BASE_ADDR               0x08000000
+#define STM32F3_ADDR_2_SEC_IDX(a)       (((a) - STM32F3_BASE_ADDR) / 2048)
+#define STM32F3_SEC_IDX_2_ADDR(idx)     (STM32F3_BASE_ADDR + ((idx) * 2048))
+
+static int stm32f3_flash_read(uint32_t address, void *dst, uint32_t num_bytes);
+static int stm32f3_flash_write(uint32_t address, const void *src,
+  uint32_t num_bytes);
+static int stm32f3_flash_erase_sector(uint32_t sector_address);
+static int stm32f3_flash_sector_info(int idx, uint32_t *addr, uint32_t *sz);
+static int stm32f3_flash_init(void);
+
+static const struct hal_flash_funcs stm32f3_flash_funcs = {
+    .hff_read = stm32f3_flash_read,
+    .hff_write = stm32f3_flash_write,
+    .hff_erase_sector = stm32f3_flash_erase_sector,
+    .hff_sector_info = stm32f3_flash_sector_info,
+    .hff_init = stm32f3_flash_init
+};
+
+const struct hal_flash stm32f3_flash_dev = {
+    .hf_itf = &stm32f3_flash_funcs,
+    .hf_base_addr = STM32F3_BASE_ADDR,
+#ifdef STM32F303xC
+    .hf_size = 256 * 1024,
+    .hf_sector_cnt = 128
+#endif
+};
+
+static int
+stm32f3_flash_read(uint32_t address, void *dst, uint32_t num_bytes)
+{
+    memcpy(dst, (void *)address, num_bytes);
+    return 0;
+}
+
+static int
+stm32f3_flash_write(uint32_t address, const void *src, uint32_t len)
+{
+    FLASH_Status rc;
+    int num_half_words;
+    int i;
+    uint16_t *src16 = (uint16_t *)src;
+
+    if (address % sizeof(uint16_t)) {
+        /*
+         * Unaligned write.
+         */
+        return -1;
+    }
+    num_half_words = len / 2;
+
+    for (i = 0; i < num_half_words; i++) {
+        rc = FLASH_ProgramHalfWord(address, src16[i]);
+        if (rc != FLASH_COMPLETE) {
+            goto err;
+        }
+        address += 2;
+    }
+    if (num_half_words * 2 != len) {
+        rc = FLASH_ProgramHalfWord(address, ((uint8_t *)src)[len] << 8);
+        if (rc != FLASH_COMPLETE) {
+            goto err;
+        }
+    }
+    return 0;
+err:
+    return -1;
+}
+
+static int
+stm32f3_flash_erase_sector(uint32_t sector_address)
+{
+    if (FLASH_ErasePage(sector_address) == FLASH_COMPLETE) {
+        return 0;
+    }
+    return -1;
+}
+
+static int
+stm32f3_flash_sector_info(int idx, uint32_t *addr, uint32_t *sz)
+{
+    assert(idx < stm32f3_flash_dev.hf_sector_cnt);
+    *addr = STM32F3_SEC_IDX_2_ADDR(idx);
+    *sz = 2048;
+    return 0;
+}
+
+static int
+stm32f3_flash_init(void)
+{
+    FLASH_Unlock();
+    return 0;
+}


[4/7] incubator-mynewt-larva git commit: Adjust luatest stack size to be 8k instead of 32k.

Posted by ma...@apache.org.
Adjust luatest stack size to be 8k instead of 32k.


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/52e3cf31
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/52e3cf31
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/52e3cf31

Branch: refs/heads/master
Commit: 52e3cf31952b7918e06572cb971b11a2c6c87716
Parents: 110883b
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Wed Nov 25 15:46:29 2015 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Wed Nov 25 15:46:29 2015 -0800

----------------------------------------------------------------------
 project/luatest/src/main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/52e3cf31/project/luatest/src/main.c
----------------------------------------------------------------------
diff --git a/project/luatest/src/main.c b/project/luatest/src/main.c
index 44e0d10..05282bd 100755
--- a/project/luatest/src/main.c
+++ b/project/luatest/src/main.c
@@ -32,7 +32,7 @@ int init_tasks(void);
 
 /* Shell */
 #define SHELL_TASK_PRIO      (8)
-#define SHELL_TASK_STACK_SIZE (OS_STACK_ALIGN(8192))
+#define SHELL_TASK_STACK_SIZE (OS_STACK_ALIGN(1024))
 static os_stack_t shell_stack[SHELL_TASK_STACK_SIZE];
 static struct shell_cmd lua_shell_cmd;
 


[5/7] incubator-mynewt-larva git commit: Baselibc printf does not take fancy formatting used by trap reporter. Simplify the format.

Posted by ma...@apache.org.
Baselibc printf does not take fancy formatting used by trap reporter.
Simplify the format.


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/47c7037a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/47c7037a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/47c7037a

Branch: refs/heads/master
Commit: 47c7037acc3e75b0ca8c5609339dbf07350c1bf0
Parents: 52e3cf3
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Wed Nov 25 15:47:10 2015 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Wed Nov 25 15:47:10 2015 -0800

----------------------------------------------------------------------
 libs/os/src/arch/cortex_m4/os_fault.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/47c7037a/libs/os/src/arch/cortex_m4/os_fault.c
----------------------------------------------------------------------
diff --git a/libs/os/src/arch/cortex_m4/os_fault.c b/libs/os/src/arch/cortex_m4/os_fault.c
index c9983d5..55adc5b 100644
--- a/libs/os/src/arch/cortex_m4/os_fault.c
+++ b/libs/os/src/arch/cortex_m4/os_fault.c
@@ -68,18 +68,18 @@ void
 os_default_irq(struct trap_frame *tf)
 {
     console_blocking_mode();
-    console_printf("Unhandled interrupt (%d), exception sp %8.8x\n",
+    console_printf("Unhandled interrupt (%d), exception sp 0x%x\n",
       SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk, (uint32_t)tf->ef);
-    console_printf(" r0:%8.8x  r1:%8.8x  r2:%8.8x  r3:%8.8x\n",
+    console_printf(" r0:0x%x  r1:0x%x  r2:0x%x  r3:0x%x\n",
       tf->ef->r0, tf->ef->r1, tf->ef->r2, tf->ef->r3);
-    console_printf(" r4:%8.8x  r5:%8.8x  r6:%8.8x  r7:%8.8x\n",
+    console_printf(" r4:0x%x  r5:0x%x  r6:0x%x  r7:0x%x\n",
       tf->r4, tf->r5, tf->r6, tf->r7);
-    console_printf(" r8:%8.8x  r9:%8.8x r10:%8.8x r11:%8.8x\n",
+    console_printf(" r8:0x%x  r9:0x%x  r10:0x%x  r11:0x%x\n",
       tf->r8, tf->r9, tf->r10, tf->r11);
-    console_printf("r12:%8.8x  lr:%8.8x  pc:%8.8x psr:%8.8x\n",
+    console_printf("r12:0x%x  lr:0x%x  pc:0x%x  psr:0x%x\n",
       tf->ef->r12, tf->ef->lr, tf->ef->pc, tf->ef->psr);
-    console_printf("ICSR:%8.8x HFSR:%8.8x CFSR:%8.8x\n",
+    console_printf("ICSR:0x%x  HFSR:0x%x  CFSR:0x%x\n",
       SCB->ICSR, SCB->HFSR, SCB->CFSR);
-    console_printf("BFAR:%8.8x MMFAR:%8.8x\n", SCB->BFAR, SCB->MMFAR);
+    console_printf("BFAR:0x%x  MMFAR:0x%x\n", SCB->BFAR, SCB->MMFAR);
     system_reset();
 }