This is an automated email from the ASF dual-hosted git repository.

mgorecki pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git

commit 11d13cc1a4621160e045d612ebba3031b50d9d95
Author: Michal Gorecki <[email protected]>
AuthorDate: Fri Jun 21 14:57:39 2024 +0200

    hw/mcu/nordic: Add common flash HAL
---
 hw/bsp/ada_feather_nrf52/src/hal_bsp.c             |   2 +-
 hw/bsp/arduino_primo_nrf52/src/hal_bsp.c           |   2 +-
 hw/bsp/bbc_microbit/src/hal_bsp.c                  |   2 +-
 hw/bsp/ble400/src/hal_bsp.c                        |   2 +-
 hw/bsp/bmd200/src/hal_bsp.c                        |   2 +-
 hw/bsp/bmd300eval/src/hal_bsp.c                    |   2 +-
 hw/bsp/calliope_mini/src/hal_bsp.c                 |   2 +-
 hw/bsp/dwm1001-dev/src/hal_bsp.c                   |   2 +-
 hw/bsp/fanstel-ev-bt840/src/hal_bsp.c              |   2 +-
 hw/bsp/nina-b1/src/hal_bsp.c                       |   2 +-
 hw/bsp/nordic_pca10028-16k/src/hal_bsp.c           |   2 +-
 hw/bsp/nordic_pca10028/src/hal_bsp.c               |   2 +-
 hw/bsp/nordic_pca10040/src/hal_bsp.c               |   4 +-
 hw/bsp/nordic_pca10056/src/hal_bsp.c               |   2 +-
 hw/bsp/nordic_pca10059/src/hal_bsp.c               |   2 +-
 hw/bsp/nordic_pca10090/src/hal_bsp.c               |   2 +-
 hw/bsp/nordic_pca10095/src/hal_bsp.c               |   2 +-
 hw/bsp/nordic_pca10095_net/src/hal_bsp.c           |   2 +-
 hw/bsp/nordic_pca10121/net/src/hal_bsp.c           |   2 +-
 hw/bsp/nordic_pca10121/src/hal_bsp.c               |   2 +-
 hw/bsp/nordic_pca20020/src/hal_bsp.c               |   2 +-
 hw/bsp/nordic_thingy53/src/hal_bsp.c               |   2 +-
 hw/bsp/nrf51-arduino_101/src/hal_bsp.c             |   2 +-
 hw/bsp/nrf51-blenano/src/hal_bsp.c                 |   2 +-
 hw/bsp/pinetime/src/hal_bsp.c                      |   2 +-
 hw/bsp/puckjs/src/hal_bsp.c                        |   2 +-
 hw/bsp/rb-blend2/src/hal_bsp.c                     |   2 +-
 hw/bsp/rb-nano2/src/hal_bsp.c                      |   2 +-
 hw/bsp/reel_board/src/hal_bsp.c                    |   2 +-
 hw/bsp/ruuvitag_rev_b/src/hal_bsp.c                |   2 +-
 hw/bsp/telee02/src/hal_bsp.c                       |   2 +-
 hw/bsp/ublox_bmd_345/src/hal_bsp.c                 |   2 +-
 hw/bsp/vbluno51/src/hal_bsp.c                      |   2 +-
 hw/bsp/vbluno52/src/hal_bsp.c                      |   2 +-
 .../ipc_nrf5340_flash/src/ipc_nrf5340_flash.c      |   2 +-
 hw/mcu/nordic/nrf51xxx/include/mcu/nrf51_hal.h     |   4 +-
 hw/mcu/nordic/nrf51xxx/include/nrfx_config_nrf51.h |   1 +
 hw/mcu/nordic/nrf51xxx/src/hal_flash.c             | 193 -----------------
 hw/mcu/nordic/nrf52xxx/include/mcu/nrf52_hal.h     |   3 +-
 .../nordic/nrf52xxx/include/nrfx_config_nrf52810.h |   2 +-
 .../nordic/nrf52xxx/include/nrfx_config_nrf52811.h |   2 +-
 .../nordic/nrf52xxx/include/nrfx_config_nrf52832.h |   2 +-
 .../nordic/nrf52xxx/include/nrfx_config_nrf52840.h |   2 +-
 hw/mcu/nordic/nrf52xxx/src/hal_flash.c             | 221 -------------------
 hw/mcu/nordic/nrf5340/include/mcu/nrf5340_hal.h    |   2 -
 .../include/nrfx_config_nrf5340_application.h      |   2 +-
 hw/mcu/nordic/nrf5340/src/hal_flash.c              | 221 -------------------
 .../nrf5340_net/include/mcu/nrf5340_net_hal.h      |   1 -
 .../include/nrfx_config_nrf5340_network.h          |   2 +-
 hw/mcu/nordic/nrf5340_net/src/hal_flash.c          | 205 ------------------
 hw/mcu/nordic/nrf5340_net/src/hal_vflash.c         |   2 +-
 hw/mcu/nordic/nrf91xx/include/mcu/nrf91_hal.h      |   3 +-
 hw/mcu/nordic/nrf91xx/include/nrfx_config_nrf91.h  |   2 +-
 hw/mcu/nordic/nrf91xx/src/hal_flash.c              | 237 ---------------------
 hw/mcu/nordic/nrf_common/include/nrf_hal.h         |   3 +
 hw/mcu/nordic/nrf_common/src/hal_flash.c           | 114 ++++++++++
 56 files changed, 165 insertions(+), 1131 deletions(-)

diff --git a/hw/bsp/ada_feather_nrf52/src/hal_bsp.c 
b/hw/bsp/ada_feather_nrf52/src/hal_bsp.c
index d49d805a1..09d2ae6e2 100644
--- a/hw/bsp/ada_feather_nrf52/src/hal_bsp.c
+++ b/hw/bsp/ada_feather_nrf52/src/hal_bsp.c
@@ -49,7 +49,7 @@ hal_bsp_flash_dev(uint8_t id)
      * Internal flash mapped to id 0.
      */
     if (id == 0) {
-        return &nrf52k_flash_dev;
+        return &nrf_flash_dev;
     }
 
     return NULL;
diff --git a/hw/bsp/arduino_primo_nrf52/src/hal_bsp.c 
b/hw/bsp/arduino_primo_nrf52/src/hal_bsp.c
index 2a464dd52..6ee29a601 100644
--- a/hw/bsp/arduino_primo_nrf52/src/hal_bsp.c
+++ b/hw/bsp/arduino_primo_nrf52/src/hal_bsp.c
@@ -51,7 +51,7 @@ hal_bsp_flash_dev(uint8_t id)
     if (id != 0) {
         return NULL;
     }
-    return &nrf52k_flash_dev;
+    return &nrf_flash_dev;
 }
 
 const struct hal_bsp_mem_dump *
diff --git a/hw/bsp/bbc_microbit/src/hal_bsp.c 
b/hw/bsp/bbc_microbit/src/hal_bsp.c
index e09a2692e..458484993 100644
--- a/hw/bsp/bbc_microbit/src/hal_bsp.c
+++ b/hw/bsp/bbc_microbit/src/hal_bsp.c
@@ -115,7 +115,7 @@ hal_bsp_flash_dev(uint8_t id)
     if (id != 0) {
         return NULL;
     }
-    return &nrf51_flash_dev;
+    return &nrf_flash_dev;
 }
 
 const struct hal_bsp_mem_dump *
diff --git a/hw/bsp/ble400/src/hal_bsp.c b/hw/bsp/ble400/src/hal_bsp.c
index 7a897d2bb..b7949007d 100644
--- a/hw/bsp/ble400/src/hal_bsp.c
+++ b/hw/bsp/ble400/src/hal_bsp.c
@@ -116,7 +116,7 @@ hal_bsp_flash_dev(uint8_t id)
     if (id != 0) {
         return NULL;
     }
-    return &nrf51_flash_dev;
+    return &nrf_flash_dev;
 }
 
 const struct hal_bsp_mem_dump *
diff --git a/hw/bsp/bmd200/src/hal_bsp.c b/hw/bsp/bmd200/src/hal_bsp.c
index 7a897d2bb..b7949007d 100644
--- a/hw/bsp/bmd200/src/hal_bsp.c
+++ b/hw/bsp/bmd200/src/hal_bsp.c
@@ -116,7 +116,7 @@ hal_bsp_flash_dev(uint8_t id)
     if (id != 0) {
         return NULL;
     }
-    return &nrf51_flash_dev;
+    return &nrf_flash_dev;
 }
 
 const struct hal_bsp_mem_dump *
diff --git a/hw/bsp/bmd300eval/src/hal_bsp.c b/hw/bsp/bmd300eval/src/hal_bsp.c
index 2156debba..964d774d2 100644
--- a/hw/bsp/bmd300eval/src/hal_bsp.c
+++ b/hw/bsp/bmd300eval/src/hal_bsp.c
@@ -52,7 +52,7 @@ hal_bsp_flash_dev(uint8_t id)
     if (id != 0) {
         return NULL;
     }
-    return &nrf52k_flash_dev;
+    return &nrf_flash_dev;
 }
 
 const struct hal_bsp_mem_dump *
diff --git a/hw/bsp/calliope_mini/src/hal_bsp.c 
b/hw/bsp/calliope_mini/src/hal_bsp.c
index 70f5da2f9..deb122c1a 100644
--- a/hw/bsp/calliope_mini/src/hal_bsp.c
+++ b/hw/bsp/calliope_mini/src/hal_bsp.c
@@ -117,7 +117,7 @@ hal_bsp_flash_dev(uint8_t id)
     if (id != 0) {
         return NULL;
     }
-    return &nrf51_flash_dev;
+    return &nrf_flash_dev;
 }
 
 const struct hal_bsp_mem_dump *
diff --git a/hw/bsp/dwm1001-dev/src/hal_bsp.c b/hw/bsp/dwm1001-dev/src/hal_bsp.c
index 2e53db04b..0284e47da 100644
--- a/hw/bsp/dwm1001-dev/src/hal_bsp.c
+++ b/hw/bsp/dwm1001-dev/src/hal_bsp.c
@@ -53,7 +53,7 @@ hal_bsp_flash_dev(uint8_t id)
     if (id != 0) {
         return NULL;
     }
-    return &nrf52k_flash_dev;
+    return &nrf_flash_dev;
 }
 
 const struct hal_bsp_mem_dump *
diff --git a/hw/bsp/fanstel-ev-bt840/src/hal_bsp.c 
b/hw/bsp/fanstel-ev-bt840/src/hal_bsp.c
index 56f2592b3..69018ca39 100644
--- a/hw/bsp/fanstel-ev-bt840/src/hal_bsp.c
+++ b/hw/bsp/fanstel-ev-bt840/src/hal_bsp.c
@@ -43,7 +43,7 @@ const struct hal_flash *
 hal_bsp_flash_dev(uint8_t id)
 {
     if (id == 0) {
-        return &nrf52k_flash_dev;
+        return &nrf_flash_dev;
     }
 
     return NULL;
diff --git a/hw/bsp/nina-b1/src/hal_bsp.c b/hw/bsp/nina-b1/src/hal_bsp.c
index 3bb0c712c..09672b919 100644
--- a/hw/bsp/nina-b1/src/hal_bsp.c
+++ b/hw/bsp/nina-b1/src/hal_bsp.c
@@ -52,7 +52,7 @@ hal_bsp_flash_dev(uint8_t id)
     if (id != 0) {
         return NULL;
     }
-    return &nrf52k_flash_dev;
+    return &nrf_flash_dev;
 }
 
 const struct hal_bsp_mem_dump *
diff --git a/hw/bsp/nordic_pca10028-16k/src/hal_bsp.c 
b/hw/bsp/nordic_pca10028-16k/src/hal_bsp.c
index 6a7ff7d25..e8af4d525 100644
--- a/hw/bsp/nordic_pca10028-16k/src/hal_bsp.c
+++ b/hw/bsp/nordic_pca10028-16k/src/hal_bsp.c
@@ -116,7 +116,7 @@ hal_bsp_flash_dev(uint8_t id)
     if (id != 0) {
         return NULL;
     }
-    return &nrf51_flash_dev;
+    return &nrf_flash_dev;
 }
 
 const struct hal_bsp_mem_dump *
diff --git a/hw/bsp/nordic_pca10028/src/hal_bsp.c 
b/hw/bsp/nordic_pca10028/src/hal_bsp.c
index 8e7590639..3e5d6dfa2 100644
--- a/hw/bsp/nordic_pca10028/src/hal_bsp.c
+++ b/hw/bsp/nordic_pca10028/src/hal_bsp.c
@@ -118,7 +118,7 @@ hal_bsp_flash_dev(uint8_t id)
     if (id != 0) {
         return NULL;
     }
-    return &nrf51_flash_dev;
+    return &nrf_flash_dev;
 }
 
 const struct hal_bsp_mem_dump *
diff --git a/hw/bsp/nordic_pca10040/src/hal_bsp.c 
b/hw/bsp/nordic_pca10040/src/hal_bsp.c
index c7bd06f9c..e54a8c3d5 100644
--- a/hw/bsp/nordic_pca10040/src/hal_bsp.c
+++ b/hw/bsp/nordic_pca10040/src/hal_bsp.c
@@ -51,7 +51,7 @@ static sec_data_secret struct eflash_nrf5x_dev enc_flash_dev0 
= {
         .efd_hal = {
             .hf_itf = &enc_flash_funcs,
         },
-        .efd_hwdev = &nrf52k_flash_dev
+        .efd_hwdev = &nrf_flash_dev
     }
 };
 
@@ -64,7 +64,7 @@ hal_bsp_flash_dev(uint8_t id)
      * Internal flash mapped to id 0.
      */
     if (id == 0) {
-        return &nrf52k_flash_dev;
+        return &nrf_flash_dev;
     }
 #if MYNEWT_VAL(ENC_FLASH_DEV)
     if (id == 1) {
diff --git a/hw/bsp/nordic_pca10056/src/hal_bsp.c 
b/hw/bsp/nordic_pca10056/src/hal_bsp.c
index 5d1a289d6..dea15a696 100644
--- a/hw/bsp/nordic_pca10056/src/hal_bsp.c
+++ b/hw/bsp/nordic_pca10056/src/hal_bsp.c
@@ -48,7 +48,7 @@ hal_bsp_flash_dev(uint8_t id)
      * Internal flash mapped to id 0.
      */
     if (id == 0) {
-        return &nrf52k_flash_dev;
+        return &nrf_flash_dev;
     }
 #if MYNEWT_VAL(QSPI_ENABLE)
     if (id == 1) {
diff --git a/hw/bsp/nordic_pca10059/src/hal_bsp.c 
b/hw/bsp/nordic_pca10059/src/hal_bsp.c
index 5d1a289d6..dea15a696 100644
--- a/hw/bsp/nordic_pca10059/src/hal_bsp.c
+++ b/hw/bsp/nordic_pca10059/src/hal_bsp.c
@@ -48,7 +48,7 @@ hal_bsp_flash_dev(uint8_t id)
      * Internal flash mapped to id 0.
      */
     if (id == 0) {
-        return &nrf52k_flash_dev;
+        return &nrf_flash_dev;
     }
 #if MYNEWT_VAL(QSPI_ENABLE)
     if (id == 1) {
diff --git a/hw/bsp/nordic_pca10090/src/hal_bsp.c 
b/hw/bsp/nordic_pca10090/src/hal_bsp.c
index 21ee9fe5e..37c8bd30f 100644
--- a/hw/bsp/nordic_pca10090/src/hal_bsp.c
+++ b/hw/bsp/nordic_pca10090/src/hal_bsp.c
@@ -49,7 +49,7 @@ hal_bsp_flash_dev(uint8_t id)
      * Internal flash mapped to id 0.
      */
     if (id == 0) {
-        return &nrf91k_flash_dev;
+        return &nrf_flash_dev;
     }
 
     return NULL;
diff --git a/hw/bsp/nordic_pca10095/src/hal_bsp.c 
b/hw/bsp/nordic_pca10095/src/hal_bsp.c
index b52c095ae..c46b2ae10 100644
--- a/hw/bsp/nordic_pca10095/src/hal_bsp.c
+++ b/hw/bsp/nordic_pca10095/src/hal_bsp.c
@@ -54,7 +54,7 @@ hal_bsp_flash_dev(uint8_t id)
      * Internal flash mapped to id 0.
      */
     if (id == 0) {
-        return &nrf5340_flash_dev;
+        return &nrf_flash_dev;
     }
 #if MYNEWT_VAL(QSPI_ENABLE)
     if (id == 1) {
diff --git a/hw/bsp/nordic_pca10095_net/src/hal_bsp.c 
b/hw/bsp/nordic_pca10095_net/src/hal_bsp.c
index 7476031be..2f5a7bc76 100644
--- a/hw/bsp/nordic_pca10095_net/src/hal_bsp.c
+++ b/hw/bsp/nordic_pca10095_net/src/hal_bsp.c
@@ -55,7 +55,7 @@ hal_bsp_flash_dev(uint8_t id)
      * Internal flash mapped to id 0.
      */
     if (id == 0) {
-        return &nrf5340_flash_dev;
+        return &nrf_flash_dev;
     }
 #if MCUBOOT_MYNEWT
     if (id == 1) {
diff --git a/hw/bsp/nordic_pca10121/net/src/hal_bsp.c 
b/hw/bsp/nordic_pca10121/net/src/hal_bsp.c
index 7476031be..2f5a7bc76 100644
--- a/hw/bsp/nordic_pca10121/net/src/hal_bsp.c
+++ b/hw/bsp/nordic_pca10121/net/src/hal_bsp.c
@@ -55,7 +55,7 @@ hal_bsp_flash_dev(uint8_t id)
      * Internal flash mapped to id 0.
      */
     if (id == 0) {
-        return &nrf5340_flash_dev;
+        return &nrf_flash_dev;
     }
 #if MCUBOOT_MYNEWT
     if (id == 1) {
diff --git a/hw/bsp/nordic_pca10121/src/hal_bsp.c 
b/hw/bsp/nordic_pca10121/src/hal_bsp.c
index 4be822e72..57d4512b3 100644
--- a/hw/bsp/nordic_pca10121/src/hal_bsp.c
+++ b/hw/bsp/nordic_pca10121/src/hal_bsp.c
@@ -55,7 +55,7 @@ hal_bsp_flash_dev(uint8_t id)
      * Internal flash mapped to id 0.
      */
     if (id == 0) {
-        return &nrf5340_flash_dev;
+        return &nrf_flash_dev;
     }
 #if MYNEWT_VAL(QSPI_ENABLE)
     if (id == 1) {
diff --git a/hw/bsp/nordic_pca20020/src/hal_bsp.c 
b/hw/bsp/nordic_pca20020/src/hal_bsp.c
index c9a8c90bc..c70ca6e73 100644
--- a/hw/bsp/nordic_pca20020/src/hal_bsp.c
+++ b/hw/bsp/nordic_pca20020/src/hal_bsp.c
@@ -62,7 +62,7 @@ hal_bsp_flash_dev(uint8_t id)
      * Internal flash mapped to id 0.
      */
     if (id == 0) {
-        return &nrf52k_flash_dev;
+        return &nrf_flash_dev;
     }
 
     return NULL;
diff --git a/hw/bsp/nordic_thingy53/src/hal_bsp.c 
b/hw/bsp/nordic_thingy53/src/hal_bsp.c
index b52c095ae..c46b2ae10 100644
--- a/hw/bsp/nordic_thingy53/src/hal_bsp.c
+++ b/hw/bsp/nordic_thingy53/src/hal_bsp.c
@@ -54,7 +54,7 @@ hal_bsp_flash_dev(uint8_t id)
      * Internal flash mapped to id 0.
      */
     if (id == 0) {
-        return &nrf5340_flash_dev;
+        return &nrf_flash_dev;
     }
 #if MYNEWT_VAL(QSPI_ENABLE)
     if (id == 1) {
diff --git a/hw/bsp/nrf51-arduino_101/src/hal_bsp.c 
b/hw/bsp/nrf51-arduino_101/src/hal_bsp.c
index 7b3ad0069..a67309c33 100644
--- a/hw/bsp/nrf51-arduino_101/src/hal_bsp.c
+++ b/hw/bsp/nrf51-arduino_101/src/hal_bsp.c
@@ -119,7 +119,7 @@ hal_bsp_flash_dev(uint8_t id)
     if (id != 0) {
         return NULL;
     }
-    return &nrf51_flash_dev;
+    return &nrf_flash_dev;
 }
 
 const struct hal_bsp_mem_dump *
diff --git a/hw/bsp/nrf51-blenano/src/hal_bsp.c 
b/hw/bsp/nrf51-blenano/src/hal_bsp.c
index 6170f1c70..cb633c0ca 100644
--- a/hw/bsp/nrf51-blenano/src/hal_bsp.c
+++ b/hw/bsp/nrf51-blenano/src/hal_bsp.c
@@ -118,7 +118,7 @@ hal_bsp_flash_dev(uint8_t id)
     if (id != 0) {
         return NULL;
     }
-    return &nrf51_flash_dev;
+    return &nrf_flash_dev;
 }
 
 const struct hal_bsp_mem_dump *
diff --git a/hw/bsp/pinetime/src/hal_bsp.c b/hw/bsp/pinetime/src/hal_bsp.c
index 66bfe5bcb..b4951dc2a 100644
--- a/hw/bsp/pinetime/src/hal_bsp.c
+++ b/hw/bsp/pinetime/src/hal_bsp.c
@@ -71,7 +71,7 @@ struct bus_spi_node_cfg flash_spi_cfg = {
 
 static const struct hal_flash *flash_devs[] = {
     /* MCU internal flash. */
-    [0] = &nrf52k_flash_dev,
+    [0] = &nrf_flash_dev,
 #if MYNEWT_VAL(SPIFLASH)
     /* External SPI Flash. */
     [1] = &spiflash_dev.hal,
diff --git a/hw/bsp/puckjs/src/hal_bsp.c b/hw/bsp/puckjs/src/hal_bsp.c
index 2e53db04b..0284e47da 100644
--- a/hw/bsp/puckjs/src/hal_bsp.c
+++ b/hw/bsp/puckjs/src/hal_bsp.c
@@ -53,7 +53,7 @@ hal_bsp_flash_dev(uint8_t id)
     if (id != 0) {
         return NULL;
     }
-    return &nrf52k_flash_dev;
+    return &nrf_flash_dev;
 }
 
 const struct hal_bsp_mem_dump *
diff --git a/hw/bsp/rb-blend2/src/hal_bsp.c b/hw/bsp/rb-blend2/src/hal_bsp.c
index 9cb5ffec1..8977012ab 100644
--- a/hw/bsp/rb-blend2/src/hal_bsp.c
+++ b/hw/bsp/rb-blend2/src/hal_bsp.c
@@ -52,7 +52,7 @@ hal_bsp_flash_dev(uint8_t id)
     if (id != 0) {
         return NULL;
     }
-    return &nrf52k_flash_dev;
+    return &nrf_flash_dev;
 }
 
 const struct hal_bsp_mem_dump *
diff --git a/hw/bsp/rb-nano2/src/hal_bsp.c b/hw/bsp/rb-nano2/src/hal_bsp.c
index 2d0e4aff0..051f88962 100644
--- a/hw/bsp/rb-nano2/src/hal_bsp.c
+++ b/hw/bsp/rb-nano2/src/hal_bsp.c
@@ -51,7 +51,7 @@ hal_bsp_flash_dev(uint8_t id)
     if (id != 0) {
         return NULL;
     }
-    return &nrf52k_flash_dev;
+    return &nrf_flash_dev;
 }
 
 const struct hal_bsp_mem_dump *
diff --git a/hw/bsp/reel_board/src/hal_bsp.c b/hw/bsp/reel_board/src/hal_bsp.c
index 82c75c797..2ca4fdefe 100644
--- a/hw/bsp/reel_board/src/hal_bsp.c
+++ b/hw/bsp/reel_board/src/hal_bsp.c
@@ -44,7 +44,7 @@ const struct hal_flash *
 hal_bsp_flash_dev(uint8_t id)
 {
     if (id == 0) {
-        return &nrf52k_flash_dev;
+        return &nrf_flash_dev;
     }
 
     return NULL;
diff --git a/hw/bsp/ruuvitag_rev_b/src/hal_bsp.c 
b/hw/bsp/ruuvitag_rev_b/src/hal_bsp.c
index 337a199fc..9dfb147eb 100644
--- a/hw/bsp/ruuvitag_rev_b/src/hal_bsp.c
+++ b/hw/bsp/ruuvitag_rev_b/src/hal_bsp.c
@@ -76,7 +76,7 @@ hal_bsp_flash_dev(uint8_t id)
      * Internal flash mapped to id 0.
      */
     if (id == 0) {
-        return &nrf52k_flash_dev;
+        return &nrf_flash_dev;
     }
 
     return NULL;
diff --git a/hw/bsp/telee02/src/hal_bsp.c b/hw/bsp/telee02/src/hal_bsp.c
index ce0f4e1f0..ecabcd3bf 100644
--- a/hw/bsp/telee02/src/hal_bsp.c
+++ b/hw/bsp/telee02/src/hal_bsp.c
@@ -54,7 +54,7 @@ hal_bsp_flash_dev(uint8_t id)
     if (id != 0) {
         return NULL;
     }
-    return &nrf52k_flash_dev;
+    return &nrf_flash_dev;
 }
 
 const struct hal_bsp_mem_dump *
diff --git a/hw/bsp/ublox_bmd_345/src/hal_bsp.c 
b/hw/bsp/ublox_bmd_345/src/hal_bsp.c
index 43f06bf26..84aab2967 100644
--- a/hw/bsp/ublox_bmd_345/src/hal_bsp.c
+++ b/hw/bsp/ublox_bmd_345/src/hal_bsp.c
@@ -49,7 +49,7 @@ hal_bsp_flash_dev(uint8_t id)
      * Internal flash mapped to id 0.
      */
     if (id == 0) {
-        return &nrf52k_flash_dev;
+        return &nrf_flash_dev;
     }
 #if MYNEWT_VAL(QSPI_ENABLE)
     if (id == 1) {
diff --git a/hw/bsp/vbluno51/src/hal_bsp.c b/hw/bsp/vbluno51/src/hal_bsp.c
index 63119e4d8..76b617ade 100644
--- a/hw/bsp/vbluno51/src/hal_bsp.c
+++ b/hw/bsp/vbluno51/src/hal_bsp.c
@@ -116,7 +116,7 @@ hal_bsp_flash_dev(uint8_t id)
     if (id != 0) {
         return NULL;
     }
-    return &nrf51_flash_dev;
+    return &nrf_flash_dev;
 }
 
 const struct hal_bsp_mem_dump *
diff --git a/hw/bsp/vbluno52/src/hal_bsp.c b/hw/bsp/vbluno52/src/hal_bsp.c
index 2e53db04b..0284e47da 100644
--- a/hw/bsp/vbluno52/src/hal_bsp.c
+++ b/hw/bsp/vbluno52/src/hal_bsp.c
@@ -53,7 +53,7 @@ hal_bsp_flash_dev(uint8_t id)
     if (id != 0) {
         return NULL;
     }
-    return &nrf52k_flash_dev;
+    return &nrf_flash_dev;
 }
 
 const struct hal_bsp_mem_dump *
diff --git a/hw/drivers/flash/ipc_nrf5340_flash/src/ipc_nrf5340_flash.c 
b/hw/drivers/flash/ipc_nrf5340_flash/src/ipc_nrf5340_flash.c
index 35db78d38..8bf594e86 100644
--- a/hw/drivers/flash/ipc_nrf5340_flash/src/ipc_nrf5340_flash.c
+++ b/hw/drivers/flash/ipc_nrf5340_flash/src/ipc_nrf5340_flash.c
@@ -439,7 +439,7 @@ nrf5340_ipc_flash_std_resp(struct ipc_msg *req, int rc, 
void *data, uint32_t dat
 static int
 nrf5340_ipc_flash_info_resp(struct ipc_msg *req)
 {
-    return nrf5340_ipc_flash_std_resp(req, 0, (void *)&nrf5340_flash_dev, 
sizeof(nrf5340_flash_dev));
+    return nrf5340_ipc_flash_std_resp(req, 0, (void *)&nrf_flash_dev, 
sizeof(nrf_flash_dev));
 }
 
 static int
diff --git a/hw/mcu/nordic/nrf51xxx/include/mcu/nrf51_hal.h 
b/hw/mcu/nordic/nrf51xxx/include/mcu/nrf51_hal.h
index 50b4abeb7..eb6225ea5 100644
--- a/hw/mcu/nordic/nrf51xxx/include/mcu/nrf51_hal.h
+++ b/hw/mcu/nordic/nrf51xxx/include/mcu/nrf51_hal.h
@@ -32,6 +32,7 @@ struct nrf51_uart_cfg {
     int8_t suc_pin_rts;
     int8_t suc_pin_cts;
 };
+
 const struct nrf51_uart_cfg *bsp_uart_config(void);
 
 struct nrf51_hal_i2c_cfg {
@@ -48,9 +49,6 @@ struct nrf51_hal_spi_cfg {
     uint8_t ss_pin;
 };
 
-struct hal_flash;
-extern const struct hal_flash nrf51_flash_dev;
-
 #ifdef __cplusplus
 }
 #endif
diff --git a/hw/mcu/nordic/nrf51xxx/include/nrfx_config_nrf51.h 
b/hw/mcu/nordic/nrf51xxx/include/nrfx_config_nrf51.h
index 88f0f8e06..2c136cb6a 100644
--- a/hw/mcu/nordic/nrf51xxx/include/nrfx_config_nrf51.h
+++ b/hw/mcu/nordic/nrf51xxx/include/nrfx_config_nrf51.h
@@ -55,6 +55,7 @@
 #define NRFX_UART_ENABLED 0
 #define NRFX_UART0_ENABLED 0
 #define NRFX_WDT_ENABLED 0
+#define NRFX_NVMC_ENABLED 1
 
 #if MYNEWT_VAL(ADC_0)
 #define NRFX_ADC_ENABLED 1
diff --git a/hw/mcu/nordic/nrf51xxx/src/hal_flash.c 
b/hw/mcu/nordic/nrf51xxx/src/hal_flash.c
deleted file mode 100644
index 6ac0ceef9..000000000
--- a/hw/mcu/nordic/nrf51xxx/src/hal_flash.c
+++ /dev/null
@@ -1,193 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you 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.
- */
-
-#include <string.h>
-#include <assert.h>
-
-#include "nrf.h"
-#include "mcu/nrf51_hal.h"
-
-#include <hal/hal_flash_int.h>
-
-#define NRF51_FLASH_SECTOR_SZ  1024
-
-static int nrf51_flash_read(const struct hal_flash *dev, uint32_t address,
-        void *dst, uint32_t num_bytes);
-static int nrf51_flash_write(const struct hal_flash *dev, uint32_t address,
-        const void *src, uint32_t num_bytes);
-static int nrf51_flash_erase_sector(const struct hal_flash *dev,
-        uint32_t sector_address);
-static int nrf51_flash_sector_info(const struct hal_flash *dev, int idx,
-        uint32_t *address, uint32_t *sz);
-static int nrf51_flash_init(const struct hal_flash *dev);
-
-static const struct hal_flash_funcs nrf51_flash_funcs = {
-    .hff_read = nrf51_flash_read,
-    .hff_write = nrf51_flash_write,
-    .hff_erase_sector = nrf51_flash_erase_sector,
-    .hff_sector_info = nrf51_flash_sector_info,
-    .hff_init = nrf51_flash_init
-};
-
-const struct hal_flash nrf51_flash_dev = {
-    .hf_itf = &nrf51_flash_funcs,
-    .hf_base_addr = 0x00000000,
-    .hf_size = 256 * 1024,     /* XXX read from factory info? */
-    .hf_sector_cnt = 256,      /* XXX read from factory info? */
-    .hf_align = 1,
-    .hf_erased_val = 0xff,
-};
-
-#define NRF51_FLASH_READY() (NRF_NVMC->READY == NVMC_READY_READY_Ready)
-
-static int
-nrf51_flash_wait_ready(void)
-{
-    int i;
-
-    for (i = 0; i < 100000; i++) {
-        if (NRF_NVMC->READY == NVMC_READY_READY_Ready) {
-            return 0;
-        }
-    }
-    return -1;
-}
-
-static int
-nrf51_flash_read(const struct hal_flash *dev, uint32_t address, void *dst,
-        uint32_t num_bytes)
-{
-    memcpy(dst, (void *)address, num_bytes);
-    return 0;
-}
-
-/*
- * Flash write is done by writing 4 bytes at a time at a word boundary.
- */
-static int
-nrf51_flash_write(const struct hal_flash *dev, uint32_t address,
-        const void *src, uint32_t num_bytes)
-{
-    int sr;
-    int rc = -1;
-    uint32_t val;
-    int cnt;
-    uint32_t tmp;
-
-    if (nrf51_flash_wait_ready()) {
-        return -1;
-    }
-    __HAL_DISABLE_INTERRUPTS(sr);
-    NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen; /* Enable erase OP */
-    tmp = address & 0x3;
-    if (tmp) {
-        if (nrf51_flash_wait_ready()) {
-            goto out;
-        }
-        /*
-         * Starts at a non-word boundary. Read 4 bytes which were there
-         * before, update with new data, and write back.
-         */
-        val = *(uint32_t *)(address & ~0x3);
-        cnt = 4 - tmp;
-        if (cnt > num_bytes) {
-            cnt = num_bytes;
-        }
-        memcpy((uint8_t *)&val + tmp, src, cnt);
-        *(uint32_t *)(address & ~0x3) = val;
-        address += cnt;
-        num_bytes -= cnt;
-        src += cnt;
-    }
-
-    while (num_bytes >= sizeof(uint32_t)) {
-        /*
-         * Write data 4 bytes at a time.
-         */
-        if (nrf51_flash_wait_ready()) {
-            goto out;
-        }
-        memcpy(&val, src, sizeof(uint32_t));
-        *(uint32_t *)address = val;
-        address += sizeof(uint32_t);
-        src += sizeof(uint32_t);
-        num_bytes -= sizeof(uint32_t);
-    }
-    if (num_bytes) {
-        /*
-         * Deal with the trailing bytes.
-         */
-        val = *(uint32_t *)address;
-        memcpy(&val, src, num_bytes);
-        if (nrf51_flash_wait_ready()) {
-            goto out;
-        }
-        *(uint32_t *)address = val;
-    }
-    rc = 0;
-    if (nrf51_flash_wait_ready()) {
-        rc = -1;
-    }
-out:
-    NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren;
-    __HAL_ENABLE_INTERRUPTS(sr);
-    return rc;
-}
-
-static int
-nrf51_flash_erase_sector(const struct hal_flash *dev, uint32_t sector_address)
-{
-    int sr;
-    int rc = -1;
-
-    if (nrf51_flash_wait_ready()) {
-        return -1;
-    }
-    __HAL_DISABLE_INTERRUPTS(sr);
-    NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Een; /* Enable erase OP */
-    if (nrf51_flash_wait_ready()) {
-        goto out;
-    }
-
-    NRF_NVMC->ERASEPAGE = sector_address;
-    if (nrf51_flash_wait_ready()) {
-        goto out;
-    }
-    rc = 0;
-out:
-    NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren; /* Disable erase OP */
-    __HAL_ENABLE_INTERRUPTS(sr);
-    return rc;
-}
-
-static int
-nrf51_flash_sector_info(const struct hal_flash *dev, int idx,
-        uint32_t *address, uint32_t *sz)
-{
-    assert(idx < nrf51_flash_dev.hf_sector_cnt);
-    *address = idx * NRF51_FLASH_SECTOR_SZ;
-    *sz = NRF51_FLASH_SECTOR_SZ;
-    return 0;
-}
-
-static int
-nrf51_flash_init(const struct hal_flash *dev)
-{
-    return 0;
-}
diff --git a/hw/mcu/nordic/nrf52xxx/include/mcu/nrf52_hal.h 
b/hw/mcu/nordic/nrf52xxx/include/mcu/nrf52_hal.h
index e820214cf..f66501f63 100644
--- a/hw/mcu/nordic/nrf52xxx/include/mcu/nrf52_hal.h
+++ b/hw/mcu/nordic/nrf52xxx/include/mcu/nrf52_hal.h
@@ -39,8 +39,7 @@ struct nrf52_hal_i2c_cfg {
     int sda_pin;
     uint32_t i2c_frequency;
 };
-struct hal_flash;
-extern const struct hal_flash nrf52k_flash_dev;
+
 extern const struct hal_flash nrf52k_qspi_dev;
 
 /* SPI configuration (used for both master and slave) */
diff --git a/hw/mcu/nordic/nrf52xxx/include/nrfx_config_nrf52810.h 
b/hw/mcu/nordic/nrf52xxx/include/nrfx_config_nrf52810.h
index 30aada12d..db3ba1129 100644
--- a/hw/mcu/nordic/nrf52xxx/include/nrfx_config_nrf52810.h
+++ b/hw/mcu/nordic/nrf52xxx/include/nrfx_config_nrf52810.h
@@ -343,7 +343,7 @@
  * Boolean. Accepted values: 0 and 1.
  */
 #ifndef NRFX_NVMC_ENABLED
-#define NRFX_NVMC_ENABLED 0
+#define NRFX_NVMC_ENABLED 1
 #endif
 
 /**
diff --git a/hw/mcu/nordic/nrf52xxx/include/nrfx_config_nrf52811.h 
b/hw/mcu/nordic/nrf52xxx/include/nrfx_config_nrf52811.h
index 61eb59c2b..d00e3aaf9 100644
--- a/hw/mcu/nordic/nrf52xxx/include/nrfx_config_nrf52811.h
+++ b/hw/mcu/nordic/nrf52xxx/include/nrfx_config_nrf52811.h
@@ -343,7 +343,7 @@
  * Boolean. Accepted values: 0 and 1.
  */
 #ifndef NRFX_NVMC_ENABLED
-#define NRFX_NVMC_ENABLED 0
+#define NRFX_NVMC_ENABLED 1
 #endif
 
 /**
diff --git a/hw/mcu/nordic/nrf52xxx/include/nrfx_config_nrf52832.h 
b/hw/mcu/nordic/nrf52xxx/include/nrfx_config_nrf52832.h
index 3564108da..f8bed7efd 100644
--- a/hw/mcu/nordic/nrf52xxx/include/nrfx_config_nrf52832.h
+++ b/hw/mcu/nordic/nrf52xxx/include/nrfx_config_nrf52832.h
@@ -526,7 +526,7 @@
  * Boolean. Accepted values: 0 and 1.
  */
 #ifndef NRFX_NVMC_ENABLED
-#define NRFX_NVMC_ENABLED 0
+#define NRFX_NVMC_ENABLED 1
 #endif
 
 /**
diff --git a/hw/mcu/nordic/nrf52xxx/include/nrfx_config_nrf52840.h 
b/hw/mcu/nordic/nrf52xxx/include/nrfx_config_nrf52840.h
index fb4895268..9d8f6fb81 100644
--- a/hw/mcu/nordic/nrf52xxx/include/nrfx_config_nrf52840.h
+++ b/hw/mcu/nordic/nrf52xxx/include/nrfx_config_nrf52840.h
@@ -482,7 +482,7 @@
  * Boolean. Accepted values: 0 and 1.
  */
 #ifndef NRFX_NVMC_ENABLED
-#define NRFX_NVMC_ENABLED 0
+#define NRFX_NVMC_ENABLED 1
 #endif
 
 /**
diff --git a/hw/mcu/nordic/nrf52xxx/src/hal_flash.c 
b/hw/mcu/nordic/nrf52xxx/src/hal_flash.c
deleted file mode 100644
index c1d520ad4..000000000
--- a/hw/mcu/nordic/nrf52xxx/src/hal_flash.c
+++ /dev/null
@@ -1,221 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you 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.
- */
-
-#include <string.h>
-#include <assert.h>
-#include "nrf.h"
-#include "mcu/nrf52_hal.h"
-#include <hal/hal_flash_int.h>
-
-#define NRF52K_FLASH_SECTOR_SZ 4096
-
-static int nrf52k_flash_read(const struct hal_flash *dev, uint32_t address,
-        void *dst, uint32_t num_bytes);
-static int nrf52k_flash_write(const struct hal_flash *dev, uint32_t address,
-        const void *src, uint32_t num_bytes);
-static int nrf52k_flash_erase_sector(const struct hal_flash *dev,
-        uint32_t sector_address);
-static int nrf52k_flash_sector_info(const struct hal_flash *dev, int idx,
-        uint32_t *address, uint32_t *sz);
-static int nrf52k_flash_init(const struct hal_flash *dev);
-
-static const struct hal_flash_funcs nrf52k_flash_funcs = {
-    .hff_read = nrf52k_flash_read,
-    .hff_write = nrf52k_flash_write,
-    .hff_erase_sector = nrf52k_flash_erase_sector,
-    .hff_sector_info = nrf52k_flash_sector_info,
-    .hff_init = nrf52k_flash_init
-};
-
-#ifdef NRF52840_XXAA
-const struct hal_flash nrf52k_flash_dev = {
-    .hf_itf = &nrf52k_flash_funcs,
-    .hf_base_addr = 0x00000000,
-    .hf_size = 1024 * 1024,    /* XXX read from factory info? */
-    .hf_sector_cnt = 256,      /* XXX read from factory info? */
-    .hf_align = 1,
-    .hf_erased_val = 0xff,
-};
-#elif defined(NRF52810_XXAA)
-const struct hal_flash nrf52k_flash_dev = {
-    .hf_itf = &nrf52k_flash_funcs,
-    .hf_base_addr = 0x00000000,
-    .hf_size = 192 * 1024,  /* XXX read from factory info? */
-    .hf_sector_cnt = 48,   /* XXX read from factory info? */
-    .hf_align = 1,
-    .hf_erased_val = 0xff,
-};
-#elif defined(NRF52811_XXAA)
-const struct hal_flash nrf52k_flash_dev = {
-    .hf_itf = &nrf52k_flash_funcs,
-    .hf_base_addr = 0x00000000,
-    .hf_size = 192 * 1024,  /* XXX read from factory info? */
-    .hf_sector_cnt = 48,   /* XXX read from factory info? */
-    .hf_align = 1,
-    .hf_erased_val = 0xff,
-};
-#elif defined(NRF52832_XXAA)
-const struct hal_flash nrf52k_flash_dev = {
-    .hf_itf = &nrf52k_flash_funcs,
-    .hf_base_addr = 0x00000000,
-    .hf_size = 512 * 1024,     /* XXX read from factory info? */
-    .hf_sector_cnt = 128,      /* XXX read from factory info? */
-    .hf_align = 1,
-    .hf_erased_val = 0xff,
-};
-#else
-#error "Must define hal_flash struct for NRF52 type"
-#endif
-
-#define NRF52K_FLASH_READY() (NRF_NVMC->READY == NVMC_READY_READY_Ready)
-
-static int
-nrf52k_flash_wait_ready(void)
-{
-    int i;
-
-    for (i = 0; i < 100000; i++) {
-        if (NRF_NVMC->READY == NVMC_READY_READY_Ready) {
-            return 0;
-        }
-    }
-    return -1;
-}
-
-static int
-nrf52k_flash_read(const struct hal_flash *dev, uint32_t address, void *dst,
-        uint32_t num_bytes)
-{
-    memcpy(dst, (void *)address, num_bytes);
-    return 0;
-}
-
-/*
- * Flash write is done by writing 4 bytes at a time at a word boundary.
- */
-static int
-nrf52k_flash_write(const struct hal_flash *dev, uint32_t address,
-        const void *src, uint32_t num_bytes)
-{
-    int sr;
-    int rc = -1;
-    uint32_t val;
-    int cnt;
-    uint32_t tmp;
-
-    if (nrf52k_flash_wait_ready()) {
-        return -1;
-    }
-    __HAL_DISABLE_INTERRUPTS(sr);
-    NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen; /* Enable erase OP */
-    tmp = address & 0x3;
-    if (tmp) {
-        if (nrf52k_flash_wait_ready()) {
-            goto out;
-        }
-        /*
-         * Starts at a non-word boundary. Read 4 bytes which were there
-         * before, update with new data, and write back.
-         */
-        val = *(uint32_t *)(address & ~0x3);
-        cnt = 4 - tmp;
-        if (cnt > num_bytes) {
-            cnt = num_bytes;
-        }
-        memcpy((uint8_t *)&val + tmp, src, cnt);
-        *(uint32_t *)(address & ~0x3) = val;
-        address += cnt;
-        num_bytes -= cnt;
-        src += cnt;
-    }
-
-    while (num_bytes >= sizeof(uint32_t)) {
-        /*
-         * Write data 4 bytes at a time.
-         */
-        if (nrf52k_flash_wait_ready()) {
-            goto out;
-        }
-        *(uint32_t *)address = *(uint32_t *)src;
-        address += sizeof(uint32_t);
-        src += sizeof(uint32_t);
-        num_bytes -= sizeof(uint32_t);
-    }
-    if (num_bytes) {
-        /*
-         * Deal with the trailing bytes.
-         */
-        val = *(uint32_t *)address;
-        memcpy(&val, src, num_bytes);
-        if (nrf52k_flash_wait_ready()) {
-            goto out;
-        }
-        *(uint32_t *)address = val;
-    }
-    rc = 0;
-    if (nrf52k_flash_wait_ready()) {
-        rc = -1;
-    }
-out:
-    NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren;
-    __HAL_ENABLE_INTERRUPTS(sr);
-    return rc;
-}
-
-static int
-nrf52k_flash_erase_sector(const struct hal_flash *dev, uint32_t sector_address)
-{
-    int sr;
-    int rc = -1;
-
-    if (nrf52k_flash_wait_ready()) {
-        return -1;
-    }
-    __HAL_DISABLE_INTERRUPTS(sr);
-    NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Een; /* Enable erase OP */
-    if (nrf52k_flash_wait_ready()) {
-        goto out;
-    }
-
-    NRF_NVMC->ERASEPAGE = sector_address;
-    if (nrf52k_flash_wait_ready()) {
-        goto out;
-    }
-    rc = 0;
-out:
-    NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren; /* Disable erase OP */
-    __HAL_ENABLE_INTERRUPTS(sr);
-    return rc;
-}
-
-static int
-nrf52k_flash_sector_info(const struct hal_flash *dev, int idx,
-        uint32_t *address, uint32_t *sz)
-{
-    assert(idx < nrf52k_flash_dev.hf_sector_cnt);
-    *address = idx * NRF52K_FLASH_SECTOR_SZ;
-    *sz = NRF52K_FLASH_SECTOR_SZ;
-    return 0;
-}
-
-static int
-nrf52k_flash_init(const struct hal_flash *dev)
-{
-    return 0;
-}
diff --git a/hw/mcu/nordic/nrf5340/include/mcu/nrf5340_hal.h 
b/hw/mcu/nordic/nrf5340/include/mcu/nrf5340_hal.h
index ed4169351..0f459743f 100644
--- a/hw/mcu/nordic/nrf5340/include/mcu/nrf5340_hal.h
+++ b/hw/mcu/nordic/nrf5340/include/mcu/nrf5340_hal.h
@@ -35,8 +35,6 @@ struct nrf5340_uart_cfg {
 };
 const struct nrf5340_uart_cfg *bsp_uart_config(void);
 
-struct hal_flash;
-extern const struct hal_flash nrf5340_flash_dev;
 extern const struct hal_flash nrf5340_qspi_dev;
 extern const struct hal_flash *ipc_flash(void);
 
diff --git a/hw/mcu/nordic/nrf5340/include/nrfx_config_nrf5340_application.h 
b/hw/mcu/nordic/nrf5340/include/nrfx_config_nrf5340_application.h
index 7e4208581..5eda3f0c9 100644
--- a/hw/mcu/nordic/nrf5340/include/nrfx_config_nrf5340_application.h
+++ b/hw/mcu/nordic/nrf5340/include/nrfx_config_nrf5340_application.h
@@ -704,7 +704,7 @@
  * Boolean. Accepted values: 0 and 1.
  */
 #ifndef NRFX_NVMC_ENABLED
-#define NRFX_NVMC_ENABLED 0
+#define NRFX_NVMC_ENABLED 1
 #endif
 
 /**
diff --git a/hw/mcu/nordic/nrf5340/src/hal_flash.c 
b/hw/mcu/nordic/nrf5340/src/hal_flash.c
deleted file mode 100644
index 9e4fe5bbb..000000000
--- a/hw/mcu/nordic/nrf5340/src/hal_flash.c
+++ /dev/null
@@ -1,221 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you 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.
- */
-
-#include <string.h>
-#include <assert.h>
-#include <nrf.h>
-#include <mcu/nrf5340_hal.h>
-#include <hal/hal_flash_int.h>
-
-#define NRF5340_FLASH_SECTOR_SZ 4096
-
-#define NRF5340_FLASH_READY() (NRF_NVMC->READY == NVMC_READY_READY_Ready)
-
-static int
-nrf5340_flash_wait_ready(void)
-{
-    int i;
-
-    for (i = 0; i < 100000; i++) {
-        if (NRF_NVMC->READY == NVMC_READY_READY_Ready) {
-            return 0;
-        }
-    }
-    return -1;
-}
-
-static int
-nrf5340_flash_read(const struct hal_flash *dev, uint32_t address, void *dst,
-                   uint32_t num_bytes)
-{
-    memcpy(dst, (void *)address, num_bytes);
-    return 0;
-}
-
-/*
- * Flash write is done by writing 4 bytes at a time at a word boundary.
- */
-static int
-nrf5340_flash_write(const struct hal_flash *dev, uint32_t address,
-                    const void *src, uint32_t num_bytes)
-{
-    int sr;
-    int rc = -1;
-    uint32_t val;
-    int cnt;
-    uint32_t tmp;
-
-    if (nrf5340_flash_wait_ready()) {
-        return -1;
-    }
-    __HAL_DISABLE_INTERRUPTS(sr);
-#if MYNEWT_VAL(BOOT_LOADER) || MYNEWT_VAL(MCU_APP_SECURE)
-    NRF_NVMC_S->CONFIG = NVMC_CONFIG_WEN_Wen; /* Enable erase OP */
-#else
-    NRF_NVMC_NS->CONFIGNS = NVMC_CONFIGNS_WEN_Wen; /* Enable erase OP */
-#endif
-    tmp = address & 0x3;
-    if (tmp) {
-        if (nrf5340_flash_wait_ready()) {
-            goto out;
-        }
-        /*
-         * Starts at a non-word boundary. Read 4 bytes which were there
-         * before, update with new data, and write back.
-         */
-        val = *(uint32_t *)(address & ~0x3);
-        cnt = 4 - tmp;
-        if (cnt > num_bytes) {
-            cnt = num_bytes;
-        }
-        memcpy((uint8_t *)&val + tmp, src, cnt);
-        *(uint32_t *)(address & ~0x3) = val;
-        address += cnt;
-        num_bytes -= cnt;
-        src += cnt;
-    }
-
-    while (num_bytes >= sizeof(uint32_t)) {
-        /*
-         * Write data 4 bytes at a time.
-         */
-        if (nrf5340_flash_wait_ready()) {
-            goto out;
-        }
-        *(uint32_t *)address = *(uint32_t *)src;
-        address += sizeof(uint32_t);
-        src += sizeof(uint32_t);
-        num_bytes -= sizeof(uint32_t);
-    }
-    if (num_bytes) {
-        /*
-         * Deal with the trailing bytes.
-         */
-        val = *(uint32_t *)address;
-        memcpy(&val, src, num_bytes);
-        if (nrf5340_flash_wait_ready()) {
-            goto out;
-        }
-        *(uint32_t *)address = val;
-    }
-
-    rc = nrf5340_flash_wait_ready();
-out:
-#if MYNEWT_VAL(BOOT_LOADER) || MYNEWT_VAL(MCU_APP_SECURE)
-    NRF_NVMC_S->CONFIG = NVMC_CONFIG_WEN_Ren;
-#else
-    NRF_NVMC_NS->CONFIGNS = NVMC_CONFIGNS_WEN_Ren;
-#endif
-    __HAL_ENABLE_INTERRUPTS(sr);
-    return rc;
-}
-
-static int
-nrf5340_flash_erase_sector(const struct hal_flash *dev, uint32_t 
sector_address)
-{
-    int sr;
-    int rc;
-
-    sector_address &= ~(NRF5340_FLASH_SECTOR_SZ - 1);
-
-    if (nrf5340_flash_wait_ready()) {
-        return -1;
-    }
-    __HAL_DISABLE_INTERRUPTS(sr);
-
-#if MYNEWT_VAL(BOOT_LOADER) || MYNEWT_VAL(MCU_APP_SECURE)
-    NRF_NVMC_S->CONFIG = NVMC_CONFIG_WEN_Een; /* Enable erase OP */
-#else
-    NRF_NVMC_NS->CONFIGNS = NVMC_CONFIGNS_WEN_Een; /* Enable erase OP */
-#endif
-    *(uint32_t *)sector_address = 0xFFFFFFFF;
-
-    rc = nrf5340_flash_wait_ready();
-
-#if MYNEWT_VAL(BOOT_LOADER) || MYNEWT_VAL(MCU_APP_SECURE)
-    NRF_NVMC_S->CONFIG = NVMC_CONFIG_WEN_Ren;
-#else
-    NRF_NVMC_NS->CONFIGNS = NVMC_CONFIGNS_WEN_Ren;
-#endif
-    __HAL_ENABLE_INTERRUPTS(sr);
-
-    return rc;
-}
-
-static int
-nrf5340_flash_erase(const struct hal_flash *dev, uint32_t address,
-                    uint32_t num_bytes)
-{
-    uint32_t sector_address;
-
-    if (address + num_bytes < dev->hf_base_addr ||
-        address > dev->hf_base_addr + dev->hf_size) {
-        return -1;
-    }
-
-    sector_address = address & ~(NRF5340_FLASH_SECTOR_SZ - 1);
-    num_bytes += address - sector_address;
-    num_bytes = (num_bytes + NRF5340_FLASH_SECTOR_SZ - 1) & 
~(NRF5340_FLASH_SECTOR_SZ - 1);
-    if (sector_address < dev->hf_base_addr) {
-        num_bytes -= dev->hf_base_addr - sector_address;
-        sector_address = dev->hf_base_addr;
-    }
-
-    while (num_bytes > 0 && sector_address < dev->hf_base_addr + dev->hf_size) 
{
-        nrf5340_flash_erase_sector(dev, sector_address);
-        num_bytes -= NRF5340_FLASH_SECTOR_SZ;
-        sector_address += NRF5340_FLASH_SECTOR_SZ;
-    }
-
-    return 0;
-}
-
-static int
-nrf5340_flash_sector_info(const struct hal_flash *dev, int idx,
-                          uint32_t *address, uint32_t *sz)
-{
-    assert(idx < nrf5340_flash_dev.hf_sector_cnt);
-    *address = idx * NRF5340_FLASH_SECTOR_SZ;
-    *sz = NRF5340_FLASH_SECTOR_SZ;
-    return 0;
-}
-
-static int
-nrf5340_flash_init(const struct hal_flash *dev)
-{
-    return 0;
-}
-
-static const struct hal_flash_funcs nrf5340_flash_funcs = {
-    .hff_read = nrf5340_flash_read,
-    .hff_write = nrf5340_flash_write,
-    .hff_erase_sector = nrf5340_flash_erase_sector,
-    .hff_sector_info = nrf5340_flash_sector_info,
-    .hff_init = nrf5340_flash_init,
-    .hff_erase = nrf5340_flash_erase,
-};
-
-const struct hal_flash nrf5340_flash_dev = {
-    .hf_itf = &nrf5340_flash_funcs,
-    .hf_base_addr = 0x00000000,
-    .hf_size = 1024 * 1024, /* XXX read from factory info? */
-    .hf_sector_cnt = 256,   /* XXX read from factory info? */
-    .hf_align = 1,
-    .hf_erased_val = 0xff,
-};
diff --git a/hw/mcu/nordic/nrf5340_net/include/mcu/nrf5340_net_hal.h 
b/hw/mcu/nordic/nrf5340_net/include/mcu/nrf5340_net_hal.h
index d7f07ad92..3f21bca42 100644
--- a/hw/mcu/nordic/nrf5340_net/include/mcu/nrf5340_net_hal.h
+++ b/hw/mcu/nordic/nrf5340_net/include/mcu/nrf5340_net_hal.h
@@ -43,7 +43,6 @@ struct nrf5340_vflash {
 };
 extern struct nrf5340_vflash nrf5340_net_vflash_dev;
 
-extern const struct hal_flash nrf5340_flash_dev;
 extern const struct hal_flash *ipc_flash(void);
 
 /* SPI configuration (used for both master and slave) */
diff --git a/hw/mcu/nordic/nrf5340_net/include/nrfx_config_nrf5340_network.h 
b/hw/mcu/nordic/nrf5340_net/include/nrfx_config_nrf5340_network.h
index 0699d5ea3..a6e71c73f 100644
--- a/hw/mcu/nordic/nrf5340_net/include/nrfx_config_nrf5340_network.h
+++ b/hw/mcu/nordic/nrf5340_net/include/nrfx_config_nrf5340_network.h
@@ -295,7 +295,7 @@
  * Boolean. Accepted values: 0 and 1.
  */
 #ifndef NRFX_NVMC_ENABLED
-#define NRFX_NVMC_ENABLED 0
+#define NRFX_NVMC_ENABLED 1
 #endif
 
 /**
diff --git a/hw/mcu/nordic/nrf5340_net/src/hal_flash.c 
b/hw/mcu/nordic/nrf5340_net/src/hal_flash.c
deleted file mode 100644
index 0a42555e1..000000000
--- a/hw/mcu/nordic/nrf5340_net/src/hal_flash.c
+++ /dev/null
@@ -1,205 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you 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.
- */
-
-#include <string.h>
-#include <assert.h>
-#include <nrf.h>
-#include <mcu/nrf5340_net_hal.h>
-#include <hal/hal_flash_int.h>
-
-#define NRF5340_NET_FLASH_SECTOR_SZ 2048
-
-#define NRF5340_NET_FLASH_READY() (NRF_NVMC->READY == NVMC_READY_READY_Ready)
-
-static int
-nrf5340_net_flash_wait_ready(void)
-{
-    int i;
-
-    for (i = 0; i < 100000; i++) {
-        if (NRF_NVMC_NS->READY == NVMC_READY_READY_Ready) {
-            return 0;
-        }
-    }
-    return -1;
-}
-
-static int
-nrf5340_net_flash_read(const struct hal_flash *dev, uint32_t address, void 
*dst,
-                       uint32_t num_bytes)
-{
-    memcpy(dst, (void *)address, num_bytes);
-    return 0;
-}
-
-/*
- * Flash write is done by writing 4 bytes at a time at a word boundary.
- */
-static int
-nrf5340_net_flash_write(const struct hal_flash *dev, uint32_t address,
-                        const void *src, uint32_t num_bytes)
-{
-    int sr;
-    int rc = -1;
-    uint32_t val;
-    int cnt;
-    uint32_t tmp;
-
-    if (nrf5340_net_flash_wait_ready()) {
-        return -1;
-    }
-    __HAL_DISABLE_INTERRUPTS(sr);
-    NRF_NVMC_NS->CONFIG = NVMC_CONFIG_WEN_Wen; /* Enable erase OP */
-    tmp = address & 0x3;
-    if (tmp) {
-        if (nrf5340_net_flash_wait_ready()) {
-            goto out;
-        }
-        /*
-         * Starts at a non-word boundary. Read 4 bytes which were there
-         * before, update with new data, and write back.
-         */
-        val = *(uint32_t *)(address & ~0x3);
-        cnt = 4 - tmp;
-        if (cnt > num_bytes) {
-            cnt = num_bytes;
-        }
-        memcpy((uint8_t *)&val + tmp, src, cnt);
-        *(uint32_t *)(address & ~0x3) = val;
-        address += cnt;
-        num_bytes -= cnt;
-        src += cnt;
-    }
-
-    while (num_bytes >= sizeof(uint32_t)) {
-        /*
-         * Write data 4 bytes at a time.
-         */
-        if (nrf5340_net_flash_wait_ready()) {
-            goto out;
-        }
-        *(uint32_t *)address = *(uint32_t *)src;
-        address += sizeof(uint32_t);
-        src += sizeof(uint32_t);
-        num_bytes -= sizeof(uint32_t);
-    }
-    if (num_bytes) {
-        /*
-         * Deal with the trailing bytes.
-         */
-        val = *(uint32_t *)address;
-        memcpy(&val, src, num_bytes);
-        if (nrf5340_net_flash_wait_ready()) {
-            goto out;
-        }
-        *(uint32_t *)address = val;
-    }
-
-    rc = nrf5340_net_flash_wait_ready();
-out:
-    NRF_NVMC_NS->CONFIG = NVMC_CONFIG_WEN_Ren;
-    __HAL_ENABLE_INTERRUPTS(sr);
-    return rc;
-}
-
-static int
-nrf5340_net_flash_erase_sector(const struct hal_flash *dev, uint32_t 
sector_address)
-{
-    int sr;
-    int rc;
-
-    sector_address &= ~(NRF5340_NET_FLASH_SECTOR_SZ - 1);
-
-    if (nrf5340_net_flash_wait_ready()) {
-        return -1;
-    }
-    __HAL_DISABLE_INTERRUPTS(sr);
-
-    NRF_NVMC_NS->CONFIG = NVMC_CONFIG_WEN_Een; /* Enable erase OP */
-    *(uint32_t *)sector_address = 0xFFFFFFFF;
-
-    rc = nrf5340_net_flash_wait_ready();
-
-    NRF_NVMC_NS->CONFIG = NVMC_CONFIG_WEN_Ren;
-    __HAL_ENABLE_INTERRUPTS(sr);
-
-    return rc;
-}
-
-static int
-nrf5340_net_flash_erase(const struct hal_flash *dev, uint32_t address,
-                        uint32_t num_bytes)
-{
-    uint32_t sector_address;
-
-    if (address + num_bytes < dev->hf_base_addr ||
-        address > dev->hf_base_addr + dev->hf_size) {
-        return -1;
-    }
-
-    sector_address = address & ~(NRF5340_NET_FLASH_SECTOR_SZ - 1);
-    num_bytes += address - sector_address;
-    num_bytes = (num_bytes + NRF5340_NET_FLASH_SECTOR_SZ - 1) & 
~(NRF5340_NET_FLASH_SECTOR_SZ - 1);
-    if (sector_address < dev->hf_base_addr) {
-        num_bytes -= dev->hf_base_addr - sector_address;
-        sector_address = dev->hf_base_addr;
-    }
-
-    while (num_bytes > 0 && sector_address < dev->hf_base_addr + dev->hf_size) 
{
-        nrf5340_net_flash_erase_sector(dev, sector_address);
-        num_bytes -= NRF5340_NET_FLASH_SECTOR_SZ;
-        sector_address += NRF5340_NET_FLASH_SECTOR_SZ;
-    }
-
-    return 0;
-}
-
-static int
-nrf5340_net_flash_sector_info(const struct hal_flash *dev, int idx,
-                              uint32_t *address, uint32_t *sz)
-{
-    assert(idx < nrf5340_flash_dev.hf_sector_cnt);
-    *address = dev->hf_base_addr + idx * NRF5340_NET_FLASH_SECTOR_SZ;
-    *sz = NRF5340_NET_FLASH_SECTOR_SZ;
-    return 0;
-}
-
-static int
-nrf5340_net_flash_init(const struct hal_flash *dev)
-{
-    return 0;
-}
-
-static const struct hal_flash_funcs nrf5340_net_flash_funcs = {
-    .hff_read = nrf5340_net_flash_read,
-    .hff_write = nrf5340_net_flash_write,
-    .hff_erase_sector = nrf5340_net_flash_erase_sector,
-    .hff_sector_info = nrf5340_net_flash_sector_info,
-    .hff_init = nrf5340_net_flash_init,
-    .hff_erase = nrf5340_net_flash_erase,
-};
-
-const struct hal_flash nrf5340_flash_dev = {
-    .hf_itf = &nrf5340_net_flash_funcs,
-    .hf_base_addr = 0x01000000,
-    .hf_size = 256 * 1024, /* XXX read from factory info? */
-    .hf_sector_cnt = 128,   /* XXX read from factory info? */
-    .hf_align = 1,
-    .hf_erased_val = 0xff,
-};
diff --git a/hw/mcu/nordic/nrf5340_net/src/hal_vflash.c 
b/hw/mcu/nordic/nrf5340_net/src/hal_vflash.c
index 8024ce451..918da87c5 100644
--- a/hw/mcu/nordic/nrf5340_net/src/hal_vflash.c
+++ b/hw/mcu/nordic/nrf5340_net/src/hal_vflash.c
@@ -204,7 +204,7 @@ nrf5340_net_vflash_sector_info(const struct hal_flash *dev, 
int idx,
 {
     (void)dev;
 
-    assert(idx < nrf5340_flash_dev.hf_sector_cnt);
+    assert(idx < nrf_flash_dev.hf_sector_cnt);
     *address = idx * NRF5340_NET_VFLASH_SECTOR_SZ;
     *sz = NRF5340_NET_VFLASH_SECTOR_SZ;
 
diff --git a/hw/mcu/nordic/nrf91xx/include/mcu/nrf91_hal.h 
b/hw/mcu/nordic/nrf91xx/include/mcu/nrf91_hal.h
index b3de9146a..b3f985a7d 100644
--- a/hw/mcu/nordic/nrf91xx/include/mcu/nrf91_hal.h
+++ b/hw/mcu/nordic/nrf91xx/include/mcu/nrf91_hal.h
@@ -39,8 +39,7 @@ struct nrf91_hal_i2c_cfg {
     int sda_pin;
     uint32_t i2c_frequency;
 };
-struct hal_flash;
-extern const struct hal_flash nrf91k_flash_dev;
+
 extern const struct hal_flash nrf91k_qspi_dev;
 
 /* SPI configuration (used for both master and slave) */
diff --git a/hw/mcu/nordic/nrf91xx/include/nrfx_config_nrf91.h 
b/hw/mcu/nordic/nrf91xx/include/nrfx_config_nrf91.h
index 35afd45f6..d2a42ce05 100644
--- a/hw/mcu/nordic/nrf91xx/include/nrfx_config_nrf91.h
+++ b/hw/mcu/nordic/nrf91xx/include/nrfx_config_nrf91.h
@@ -420,7 +420,7 @@
  * Boolean. Accepted values: 0 and 1.
  */
 #ifndef NRFX_NVMC_ENABLED
-#define NRFX_NVMC_ENABLED 0
+#define NRFX_NVMC_ENABLED 1
 #endif
 
 /**
diff --git a/hw/mcu/nordic/nrf91xx/src/hal_flash.c 
b/hw/mcu/nordic/nrf91xx/src/hal_flash.c
deleted file mode 100644
index 00cbda63d..000000000
--- a/hw/mcu/nordic/nrf91xx/src/hal_flash.c
+++ /dev/null
@@ -1,237 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you 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.
- */
-
-#include <string.h>
-#include <assert.h>
-#include "nrf.h"
-#include "mcu/nrf91_hal.h"
-#include <hal/hal_flash_int.h>
-#include "nrfx_config.h"
-#include "nrf_nvmc.h"
-
-#define NRF91K_FLASH_SECTOR_SZ 4096
-
-static int nrf91k_flash_read(const struct hal_flash *dev, uint32_t address,
-                             void *dst, uint32_t num_bytes);
-static int nrf91k_flash_write(const struct hal_flash *dev, uint32_t address,
-                              const void *src, uint32_t num_bytes);
-static int nrf91k_flash_erase_sector(const struct hal_flash *dev,
-                                     uint32_t sector_address);
-static int nrf91k_flash_sector_info(const struct hal_flash *dev, int idx,
-                                    uint32_t *address, uint32_t *sz);
-static int nrf91k_flash_init(const struct hal_flash *dev);
-
-static const struct hal_flash_funcs nrf91k_flash_funcs = {
-    .hff_read = nrf91k_flash_read,
-    .hff_write = nrf91k_flash_write,
-    .hff_erase_sector = nrf91k_flash_erase_sector,
-    .hff_sector_info = nrf91k_flash_sector_info,
-    .hff_init = nrf91k_flash_init
-};
-
-#ifdef NRF9160_XXAA
-const struct hal_flash nrf91k_flash_dev = {
-    .hf_itf = &nrf91k_flash_funcs,
-    .hf_base_addr = 0x00000000,
-    .hf_size = 1024 * 1024,    /* XXX read from factory info? */
-    .hf_sector_cnt = 256,      /* XXX read from factory info? */
-    .hf_align = 1,
-    .hf_erased_val = 0xff,
-};
-#else
-#error "Must define hal_flash struct for NRF91 type"
-#endif
-
-#define NRF91K_FLASH_READY() (NRF_NVMC->READY == NVMC_READY_READY_Ready)
-
-static void
-hal_flash_readonly_mode_set(void)
-{
-#if defined(NVMC_CONFIGNS_WEN_Msk)
-    nrf_nvmc_nonsecure_mode_set(NRF_NVMC, NRF_NVMC_NS_MODE_READONLY);
-#endif
-#if !defined(NRF_TRUSTZONE_NONSECURE)
-    nrf_nvmc_mode_set(NRF_NVMC, NRF_NVMC_MODE_READONLY);
-#endif
-}
-
-static void
-hal_flash_write_mode_set(void)
-{
-#if defined(NVMC_CONFIGNS_WEN_Msk)
-    nrf_nvmc_nonsecure_mode_set(NRF_NVMC, NRF_NVMC_NS_MODE_WRITE);
-#endif
-#if !defined(NRF_TRUSTZONE_NONSECURE)
-    nrf_nvmc_mode_set(NRF_NVMC, NRF_NVMC_MODE_WRITE);
-#endif
-}
-
-static void
-hal_flash_erase_mode_set(void)
-{
-#if defined(NVMC_CONFIGNS_WEN_Msk)
-    nrf_nvmc_nonsecure_mode_set(NRF_NVMC, NRF_NVMC_NS_MODE_ERASE);
-#endif
-#if !defined(NRF_TRUSTZONE_NONSECURE)
-    nrf_nvmc_mode_set(NRF_NVMC, NRF_NVMC_MODE_ERASE);
-#endif
-}
-
-static int
-nrf91k_flash_wait_ready(void)
-{
-    int i;
-
-    for (i = 0; i < 100000; i++) {
-        if (NRF_NVMC->READY == NVMC_READY_READY_Ready) {
-            return 0;
-        }
-    }
-    return -1;
-}
-
-static int
-nrf91k_flash_read(const struct hal_flash *dev, uint32_t address, void *dst,
-                  uint32_t num_bytes)
-{
-    int sr;
-    __HAL_DISABLE_INTERRUPTS(sr);
-    hal_flash_readonly_mode_set();
-    __HAL_ENABLE_INTERRUPTS(sr);
-    memcpy(dst, (void *)address, num_bytes);
-    return 0;
-}
-
-/*
- * Flash write is done by writing 4 bytes at a time at a word boundary.
- */
-static int
-nrf91k_flash_write(const struct hal_flash *dev, uint32_t address,
-                   const void *src, uint32_t num_bytes)
-{
-    int sr;
-    int rc = -1;
-    uint32_t val;
-    int cnt;
-    uint32_t tmp;
-
-    if (nrf91k_flash_wait_ready()) {
-        return -1;
-    }
-    __HAL_DISABLE_INTERRUPTS(sr);
-    hal_flash_write_mode_set();
-    NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen; /* Enable erase OP */
-    tmp = address & 0x3;
-    if (tmp) {
-        if (nrf91k_flash_wait_ready()) {
-            goto out;
-        }
-        /*
-         * Starts at a non-word boundary. Read 4 bytes which were there
-         * before, update with new data, and write back.
-         */
-        val = *(uint32_t *)(address & ~0x3);
-        cnt = 4 - tmp;
-        if (cnt > num_bytes) {
-            cnt = num_bytes;
-        }
-        memcpy((uint8_t *)&val + tmp, src, cnt);
-        *(uint32_t *)(address & ~0x3) = val;
-        address += cnt;
-        num_bytes -= cnt;
-        src += cnt;
-    }
-
-    while (num_bytes >= sizeof(uint32_t)) {
-        /*
-         * Write data 4 bytes at a time.
-         */
-        if (nrf91k_flash_wait_ready()) {
-            goto out;
-        }
-        *(uint32_t *)address = *(uint32_t *)src;
-        address += sizeof(uint32_t);
-        src += sizeof(uint32_t);
-        num_bytes -= sizeof(uint32_t);
-    }
-    if (num_bytes) {
-        /*
-         * Deal with the trailing bytes.
-         */
-        val = *(uint32_t *)address;
-        memcpy(&val, src, num_bytes);
-        if (nrf91k_flash_wait_ready()) {
-            goto out;
-        }
-        *(uint32_t *)address = val;
-    }
-    rc = 0;
-    if (nrf91k_flash_wait_ready()) {
-        rc = -1;
-    }
-out:
-    NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren;
-    hal_flash_readonly_mode_set();
-    __HAL_ENABLE_INTERRUPTS(sr);
-    return rc;
-}
-
-static int
-nrf91k_flash_erase_sector(const struct hal_flash *dev, uint32_t sector_address)
-{
-    int sr;
-    int rc = -1;
-
-    if (nrf91k_flash_wait_ready()) {
-        return -1;
-    }
-    __HAL_DISABLE_INTERRUPTS(sr);
-    hal_flash_erase_mode_set();
-    NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Een; /* Enable erase OP */
-    if (nrf91k_flash_wait_ready()) {
-        goto out;
-    }
-
-    NRF_NVMC->ERASEPAGEPARTIALCFG = sector_address;
-    if (nrf91k_flash_wait_ready()) {
-        goto out;
-    }
-    rc = 0;
-out:
-    NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren; /* Disable erase OP */
-    hal_flash_readonly_mode_set();
-    __HAL_ENABLE_INTERRUPTS(sr);
-    return rc;
-}
-
-static int
-nrf91k_flash_sector_info(const struct hal_flash *dev, int idx,
-                         uint32_t *address, uint32_t *sz)
-{
-    assert(idx < nrf91k_flash_dev.hf_sector_cnt);
-    *address = idx * NRF91K_FLASH_SECTOR_SZ;
-    *sz = NRF91K_FLASH_SECTOR_SZ;
-    return 0;
-}
-
-static int
-nrf91k_flash_init(const struct hal_flash *dev)
-{
-    return 0;
-}
diff --git a/hw/mcu/nordic/nrf_common/include/nrf_hal.h 
b/hw/mcu/nordic/nrf_common/include/nrf_hal.h
index b86322bd9..57656c779 100644
--- a/hw/mcu/nordic/nrf_common/include/nrf_hal.h
+++ b/hw/mcu/nordic/nrf_common/include/nrf_hal.h
@@ -38,6 +38,9 @@
         }                                               \
     } while(0);
 
+struct hal_flash;
+extern const struct hal_flash nrf_flash_dev;
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/hw/mcu/nordic/nrf_common/src/hal_flash.c 
b/hw/mcu/nordic/nrf_common/src/hal_flash.c
new file mode 100644
index 000000000..ced982311
--- /dev/null
+++ b/hw/mcu/nordic/nrf_common/src/hal_flash.c
@@ -0,0 +1,114 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+#include <string.h>
+#include <assert.h>
+#include <hal/hal_flash_int.h>
+#include <nrf.h>
+#include <nrf_hal.h>
+#include <nrfx_nvmc.h>
+
+#ifdef NRF51
+#define NRF_FLASH_SECTOR_SZ 1024
+#else
+#define NRF_FLASH_SECTOR_SZ 4096
+#endif
+
+#define NRF_FLASH_SECTOR_CNT (NRF_MEMORY_FLASH_SIZE / NRF_FLASH_SECTOR_SZ)
+
+static int nrf_flash_read(const struct hal_flash *dev, uint32_t address,
+                          void *dst, uint32_t num_bytes);
+static int nrf_flash_write(const struct hal_flash *dev, uint32_t address,
+                           const void *src, uint32_t num_bytes);
+static int nrf_flash_erase_sector(const struct hal_flash *dev,
+                                  uint32_t sector_address);
+static int nrf_flash_sector_info(const struct hal_flash *dev, int idx,
+                                 uint32_t *address, uint32_t *sz);
+static int nrf_flash_init(const struct hal_flash *dev);
+
+static const struct hal_flash_funcs nrf_flash_funcs = {
+    .hff_read = nrf_flash_read,
+    .hff_write = nrf_flash_write,
+    .hff_erase_sector = nrf_flash_erase_sector,
+    .hff_sector_info = nrf_flash_sector_info,
+    .hff_init = nrf_flash_init
+};
+
+const struct hal_flash nrf_flash_dev = {
+    .hf_itf = &nrf_flash_funcs,
+    .hf_base_addr = NRF_MEMORY_FLASH_BASE,
+    .hf_size = NRF_MEMORY_FLASH_SIZE,
+    .hf_sector_cnt = NRF_FLASH_SECTOR_CNT,
+    .hf_align = MYNEWT_VAL(MCU_FLASH_MIN_WRITE_SIZE),
+    .hf_erased_val = 0xff,
+};
+
+static int
+nrf_flash_read(const struct hal_flash *dev, uint32_t address, void *dst,
+               uint32_t num_bytes)
+{
+    memcpy(dst, (void *)address, num_bytes);
+    return 0;
+}
+
+static int
+nrf_flash_write(const struct hal_flash *dev, uint32_t address,
+                const void *src, uint32_t num_bytes)
+{
+    int sr;
+
+    __HAL_DISABLE_INTERRUPTS(sr);
+    nrfx_nvmc_bytes_write(address, src, num_bytes);
+    __HAL_ENABLE_INTERRUPTS(sr);
+
+    return 0;
+}
+
+static int
+nrf_flash_erase_sector(const struct hal_flash *dev, uint32_t sector_address)
+{
+    int sr;
+    int rc;
+
+    __HAL_DISABLE_INTERRUPTS(sr);
+    rc = nrfx_nvmc_page_erase(sector_address);
+    __HAL_ENABLE_INTERRUPTS(sr);
+
+    if (rc != NRFX_SUCCESS) {
+        return -1;
+    } else {
+        return 0;
+    }
+}
+
+static int
+nrf_flash_sector_info(const struct hal_flash *dev, int idx,
+                      uint32_t *address, uint32_t *sz)
+{
+    assert(idx < nrf_flash_dev.hf_sector_cnt);
+    *address = dev->hf_base_addr + idx * NRF_FLASH_SECTOR_SZ;
+    *sz = NRF_FLASH_SECTOR_SZ;
+    return 0;
+}
+
+static int
+nrf_flash_init(const struct hal_flash *dev)
+{
+    return 0;
+}

Reply via email to