You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2018/11/21 11:32:36 UTC

[GitHub] utzig closed pull request #1484: Brought struct hal_flash calling in parity with other bsp

utzig closed pull request #1484: Brought struct hal_flash calling in parity with other bsp
URL: https://github.com/apache/mynewt-core/pull/1484
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/hw/bsp/nucleo-f303k8/src/hal_bsp.c b/hw/bsp/nucleo-f303k8/src/hal_bsp.c
index 28e6cf61b9..f665799a7c 100644
--- a/hw/bsp/nucleo-f303k8/src/hal_bsp.c
+++ b/hw/bsp/nucleo-f303k8/src/hal_bsp.c
@@ -145,7 +145,7 @@ hal_bsp_flash_dev(uint8_t id)
     if (id != 0) {
         return NULL;
     }
-    return stm32f3_flash_dev();
+    return &stm32f3_flash_dev;
 }
 
 const struct hal_bsp_mem_dump *
diff --git a/hw/bsp/nucleo-f303re/src/hal_bsp.c b/hw/bsp/nucleo-f303re/src/hal_bsp.c
index f667c57f3c..babec25477 100644
--- a/hw/bsp/nucleo-f303re/src/hal_bsp.c
+++ b/hw/bsp/nucleo-f303re/src/hal_bsp.c
@@ -145,7 +145,7 @@ hal_bsp_flash_dev(uint8_t id)
     if (id != 0) {
         return NULL;
     }
-    return stm32f3_flash_dev();
+    return &stm32f3_flash_dev;
 }
 
 const struct hal_bsp_mem_dump *
diff --git a/hw/mcu/stm/stm32f1xx/src/hal_flash.c b/hw/mcu/stm/stm32f1xx/src/hal_flash.c
index 78a29ba652..22b568de2c 100644
--- a/hw/mcu/stm/stm32f1xx/src/hal_flash.c
+++ b/hw/mcu/stm/stm32f1xx/src/hal_flash.c
@@ -124,4 +124,4 @@ stm32f1_flash_init(const struct hal_flash *dev)
 {
     HAL_FLASH_Unlock();
     return 0;
-}
+}
\ No newline at end of file
diff --git a/hw/mcu/stm/stm32f3xx/include/mcu/stm32f3_bsp.h b/hw/mcu/stm/stm32f3xx/include/mcu/stm32f3_bsp.h
index f04ce098d0..8a5573c159 100644
--- a/hw/mcu/stm/stm32f3xx/include/mcu/stm32f3_bsp.h
+++ b/hw/mcu/stm/stm32f3xx/include/mcu/stm32f3_bsp.h
@@ -49,7 +49,7 @@ int hal_gpio_init_af(int pin, uint8_t af_type, enum hal_gpio_pull pull, uint8_t
 od);
 
 struct hal_flash;
-struct hal_flash* stm32f3_flash_dev(void);
+extern const struct hal_flash stm32f3_flash_dev;
 
 #ifdef __cplusplus
 }
diff --git a/hw/mcu/stm/stm32f3xx/src/hal_flash.c b/hw/mcu/stm/stm32f3xx/src/hal_flash.c
index 98d8fe8cec..8babbc9ce6 100644
--- a/hw/mcu/stm/stm32f3xx/src/hal_flash.c
+++ b/hw/mcu/stm/stm32f3xx/src/hal_flash.c
@@ -49,7 +49,14 @@ static const struct hal_flash_funcs stm32f3_flash_funcs = {
     .hff_init = stm32f3_flash_init
 };
 
-struct hal_flash stm32f3_flash_dev_;
+const struct hal_flash stm32f3_flash_dev = {
+    .hf_itf = &stm32f3_flash_funcs,
+    .hf_base_addr = FLASH_BASE,
+    .hf_size = HAL_FLASH_SIZE,
+    .hf_sector_cnt = HAL_FLASH_SIZE / HAL_FLASH_SECTOR_SIZE,
+    .hf_align = 2,
+    .hf_erased_val = 0xff,
+};
 
 static int
 stm32f3_flash_read(const struct hal_flash *dev, uint32_t address, void *dst,
@@ -116,18 +123,4 @@ stm32f3_flash_init(const struct hal_flash *dev)
 {
     HAL_FLASH_Lock();
     return 0;
-}
-
-struct hal_flash*
-stm32f3_flash_dev()
-{
-    if (0 == stm32f3_flash_dev_.hf_itf) {
-        stm32f3_flash_dev_.hf_itf = &stm32f3_flash_funcs;
-        stm32f3_flash_dev_.hf_base_addr = FLASH_BASE;
-        stm32f3_flash_dev_.hf_size = HAL_FLASH_SIZE;
-        stm32f3_flash_dev_.hf_sector_cnt = HAL_FLASH_SIZE / HAL_FLASH_SECTOR_SIZE;
-        stm32f3_flash_dev_.hf_align = 2;
-        stm32f3_flash_dev_.hf_erased_val = 0xff;
-    }
-    return &stm32f3_flash_dev_;
-}
+}
\ No newline at end of file


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services