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/10 00:36:34 UTC

incubator-mynewt-larva git commit: Expose flash alignment restriction (if any).

Repository: incubator-mynewt-larva
Updated Branches:
  refs/heads/master 36b80fae3 -> 08dd780a1


Expose flash alignment restriction (if any).


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

Branch: refs/heads/master
Commit: 08dd780a15b11b763fd12f10561a265444bce158
Parents: 36b80fa
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Wed Dec 9 15:34:57 2015 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Wed Dec 9 15:34:57 2015 -0800

----------------------------------------------------------------------
 hw/hal/include/hal/hal_flash.h       |  1 +
 hw/hal/include/hal/hal_flash_int.h   |  1 +
 hw/hal/src/hal_flash.c               | 12 ++++++++++++
 hw/mcu/native/src/hal_flash.c        |  2 ++
 hw/mcu/stm/stm32f3xx/src/hal_flash.c |  3 ++-
 hw/mcu/stm/stm32f4xx/src/hal_flash.c |  1 +
 6 files changed, 19 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/08dd780a/hw/hal/include/hal/hal_flash.h
----------------------------------------------------------------------
diff --git a/hw/hal/include/hal/hal_flash.h b/hw/hal/include/hal/hal_flash.h
index be3b358..787e9c2 100644
--- a/hw/hal/include/hal/hal_flash.h
+++ b/hw/hal/include/hal/hal_flash.h
@@ -25,6 +25,7 @@ int hal_flash_write(uint8_t flash_id, uint32_t address, const void *src,
   uint32_t num_bytes);
 int hal_flash_erase_sector(uint8_t flash_id, uint32_t sector_address);
 int hal_flash_erase(uint8_t flash_id, uint32_t address, uint32_t num_bytes);
+uint8_t hal_flash_align(uint8_t flash_id);
 int hal_flash_init(void);
 
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/08dd780a/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 ab7e159..34cd2c4 100644
--- a/hw/hal/include/hal/hal_flash_int.h
+++ b/hw/hal/include/hal/hal_flash_int.h
@@ -34,6 +34,7 @@ struct hal_flash {
     uint32_t hf_base_addr;
     uint32_t hf_size;
     int hf_sector_cnt;
+    int hf_align;		/* Alignment requirement. 1 if unrestricted. */
 };
 
 /*

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/08dd780a/hw/hal/src/hal_flash.c
----------------------------------------------------------------------
diff --git a/hw/hal/src/hal_flash.c b/hw/hal/src/hal_flash.c
index 90fd985..ef4e35a 100644
--- a/hw/hal/src/hal_flash.c
+++ b/hw/hal/src/hal_flash.c
@@ -39,6 +39,18 @@ hal_flash_init(void)
     return rc;
 }
 
+uint8_t
+hal_flash_align(uint8_t flash_id)
+{
+    const struct hal_flash *hf;
+
+    hf = bsp_flash_dev(flash_id);
+    if (!hf) {
+        return 1;
+    }
+    return hf->hf_align;
+}
+
 uint32_t
 hal_flash_sector_size(const struct hal_flash *hf, int sec_idx)
 {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/08dd780a/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 c4a43c0..5fc3e6c 100644
--- a/hw/mcu/native/src/hal_flash.c
+++ b/hw/mcu/native/src/hal_flash.c
@@ -65,6 +65,7 @@ const struct hal_flash native_flash_dev = {
     .hf_base_addr = 0,
     .hf_size = 1024 * 1024,
     .hf_sector_cnt = FLASH_NUM_AREAS,
+    .hf_align = 1
 };
 
 static void
@@ -155,6 +156,7 @@ flash_native_write_internal(uint32_t address, const void *src, uint32_t length,
 static int
 native_flash_write(uint32_t address, const void *src, uint32_t length)
 {
+    assert(address % native_flash_dev.hf_align == 0);
     return flash_native_write_internal(address, src, length, 0);
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/08dd780a/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
index 35cc31b..9d91c7c 100644
--- a/hw/mcu/stm/stm32f3xx/src/hal_flash.c
+++ b/hw/mcu/stm/stm32f3xx/src/hal_flash.c
@@ -51,8 +51,9 @@ const struct hal_flash stm32f3_flash_dev = {
     .hf_base_addr = STM32F3_BASE_ADDR,
 #ifdef STM32F303xC
     .hf_size = 256 * 1024,
-    .hf_sector_cnt = 128
+    .hf_sector_cnt = 128,
 #endif
+    .hf_align = 2
 };
 
 static int

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/08dd780a/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 522e6b7..6ef6918 100644
--- a/hw/mcu/stm/stm32f4xx/src/hal_flash.c
+++ b/hw/mcu/stm/stm32f4xx/src/hal_flash.c
@@ -60,6 +60,7 @@ const struct hal_flash stm32f4_flash_dev = {
     .hf_base_addr = 0x08000000,
     .hf_size = 1024 * 1024,
     .hf_sector_cnt = STM32F4_FLASH_NUM_AREAS - 1,
+    .hf_align = 1
 };
 
 static int