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/04/22 07:49:28 UTC

[mynewt-core] 01/05: mcu/nrf5340: Setup virtual flash on app core

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 097bd83a4def0adde5806c33d1e6293bab70de52
Author: Jerzy Kasenberg <je...@codecoup.pl>
AuthorDate: Fri Apr 9 11:41:03 2021 +0200

    mcu/nrf5340: Setup virtual flash on app core
    
    For combine build of app and net core application side
    IPC driver sets up image placement and size so network core
    bootloader virtual flash driver can use it to read image.
    
    It uses IPC GPMEM[0..1] registers to pass it to net core.
    Those registers were not used for anything else yet.
    
    For now network core IPC clears those registers once net core
    application start so app core can proceed.
    
    This wait can be later removed when app will not send several hci
    reset commands in a row.
---
 hw/drivers/ipc_nrf5340/src/ipc_nrf5340.c | 56 ++++++++++++++++++++++++++++++++
 1 file changed, 56 insertions(+)

diff --git a/hw/drivers/ipc_nrf5340/src/ipc_nrf5340.c b/hw/drivers/ipc_nrf5340/src/ipc_nrf5340.c
index 55e8fc8..786a85a 100644
--- a/hw/drivers/ipc_nrf5340/src/ipc_nrf5340.c
+++ b/hw/drivers/ipc_nrf5340/src/ipc_nrf5340.c
@@ -31,6 +31,19 @@
 #define IPC_MAX_CHANS MYNEWT_VAL(IPC_NRF5340_CHANNELS)
 #define IPC_BUF_SIZE MYNEWT_VAL(IPC_NRF5340_BUF_SZ)
 
+#if MYNEWT_VAL(MCU_APP_CORE) && MYNEWT_VAL(NRF5340_EMBED_NET_CORE)
+/*
+ * For combine build (app and net) network core image will be included in application
+ * image only if it is referenced. Those to symbols are used to force linker to
+ * include network core image.
+ * Those are used also to provide net core image data (and its size) to virtual
+ * flash driver that is used by bootloader to bring network image from application
+ * flash to network flash slot 1.
+ */
+extern uint8_t _binary_net_core_img_start;
+extern uint8_t _binary_net_core_img_end;
+#endif
+
 struct ipc_channel {
     ipc_nrf5340_recv_cb cb;
     void *user_data;
@@ -153,6 +166,18 @@ ipc_nrf5340_init(void)
     NRF_GPIO_Type *nrf_gpio;
 #endif
 
+#if MYNEWT_VAL(MCU_APP_CORE) && MYNEWT_VAL(NRF5340_EMBED_NET_CORE)
+    /*
+     * Get network core image size and placement in application flash.
+     * Then pass those two values in NRF_IPC GPMEM registers to be used
+     * by virtual flash driver on network side.
+     */
+    if (&_binary_net_core_img_end - &_binary_net_core_img_start > 32) {
+        NRF_IPC->GPMEM[0] = (uint32_t)&_binary_net_core_img_start;
+        NRF_IPC->GPMEM[1] = &_binary_net_core_img_end - &_binary_net_core_img_start;
+    }
+#endif
+
     /* Make sure network core if off when we set up IPC */
     NRF_RESET_S->NETWORK.FORCEOFF = RESET_NETWORK_FORCEOFF_FORCEOFF_Hold;
     memset(shms, 0, sizeof(shms));
@@ -167,6 +192,19 @@ ipc_nrf5340_init(void)
 #endif
 #endif
 
+#if MYNEWT_VAL(MCU_NET_CORE)
+    /*
+     * When network core IPCs starts it clears GPMEM from APP core registers
+     * So IPC nows that netcore is running.
+     * This is a workaround that is needed till application side code waits
+     * on IPC for network core controller to sent NOP first.
+     */
+#define NRF_APP_IPC_NS                  ((NRF_IPC_Type *)0x4002A000)
+#define NRF_APP_IPC_S                   ((NRF_IPC_Type *)0x5002A000)
+    NRF_APP_IPC_S->GPMEM[0] = 0;
+    NRF_APP_IPC_S->GPMEM[1] = 0;
+#endif
+
     /* Enable IPC channels */
     for (i = 0; i < IPC_MAX_CHANS; i++) {
         NRF_IPC->SEND_CNF[i] = (0x01UL << i);
@@ -185,6 +223,24 @@ ipc_nrf5340_init(void)
     /* Start Network Core */
     NRF_RESET_S->NETWORK.FORCEOFF = RESET_NETWORK_FORCEOFF_FORCEOFF_Release;
 #endif
+#if MYNEWT_VAL(MCU_APP_CORE) && MYNEWT_VAL(NRF5340_EMBED_NET_CORE)
+    /*
+     * TODO: Remove below workaround:
+     * For now app core waits for NET core to start.
+     * It is needed for case when network core was updated with new
+     * image and due to several second delay caused by bootloader
+     * copy image application starts to send HCI reset requests via
+     * IPC and network HCI transport is not really ready to handle
+     * more then one command.
+     */
+    if (&_binary_net_core_img_end - &_binary_net_core_img_start > 32) {
+        /*
+         * Application side prepared image for net core.
+         * When net core starts it's ipc_nrf5340_init() will clear those.
+         */
+        while (NRF_IPC->GPMEM[1]);
+    }
+#endif
 }
 
 void