You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by je...@apache.org on 2021/10/26 17:04:14 UTC

[mynewt-core] 03/10: mcu/nrf5340: Add non-secure flash access

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

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

commit b2bbe46e408281ea002feede583a7e6d322c896c
Author: Jerzy Kasenberg <je...@codecoup.pl>
AuthorDate: Wed Oct 20 10:38:59 2021 +0200

    mcu/nrf5340: Add non-secure flash access
    
    Flash secure and non-secure peripheral differs slightly.
    
    This adds support for non-secure access depending on build configuration.
---
 hw/mcu/nordic/nrf5340/src/hal_flash.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/hw/mcu/nordic/nrf5340/src/hal_flash.c b/hw/mcu/nordic/nrf5340/src/hal_flash.c
index 659dda1..9e4fe5b 100644
--- a/hw/mcu/nordic/nrf5340/src/hal_flash.c
+++ b/hw/mcu/nordic/nrf5340/src/hal_flash.c
@@ -33,7 +33,7 @@ nrf5340_flash_wait_ready(void)
     int i;
 
     for (i = 0; i < 100000; i++) {
-        if (NRF_NVMC_S->READY == NVMC_READY_READY_Ready) {
+        if (NRF_NVMC->READY == NVMC_READY_READY_Ready) {
             return 0;
         }
     }
@@ -65,7 +65,11 @@ nrf5340_flash_write(const struct hal_flash *dev, uint32_t address,
         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()) {
@@ -113,7 +117,11 @@ nrf5340_flash_write(const struct hal_flash *dev, uint32_t address,
 
     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;
 }
@@ -131,12 +139,20 @@ nrf5340_flash_erase_sector(const struct hal_flash *dev, uint32_t sector_address)
     }
     __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;