nRF5340 Custom BLE in Both Cores

I have custom nRF5340 code that includes application and bootloader for both cores. For reliability reasons, I need to run bluetooth behaviour from both the netcore application before the appcore application runs, and in the appcore application.

It seems that the standard way to do this is to use RPMSG with the appcore as the master (CONFIG_RPMSG_SERVICE_MODE_MASTER=y) and the netcore as the remote (CONFIG_RPMSG_SERVICE_MODE_REMOTE=y). However, when I enable RPMSG in the netcore, it blocks until the appcore application runs (It gets blocked in "rpmsg_service_init -> rpmsg_init_vdev -> rpmsg_virtio_wait_remote_ready"). This is not acceptable as I need to be able to interact with the netcore application prior to the appcore application commencing. 

I cannot add RPMSG to the appcore bootloader as it is a single-threaded bootloader (CONFIG_MULTITHREADING=n).

I have tried using SYS_INIT to start my bluetooth behaviour and make sure that it's priority is after CONFIG_KERNEL_INIT_PRIORITY_DEVICE but before CONFIG_RPMSG_SERVICE_INIT_PRIORITY so that bt_enable will work, but this causes crashes under some BLE behaviour.

Is there a way to enable RPMSG in the netcore application without waiting for the appcore application starting?

  • The remote rpmsg needs to wait for the master rpmsg to initialize first since the master initializes the shared buffers.

    I have tried using SYS_INIT to start my bluetooth behaviour and make sure that it's priority is after CONFIG_KERNEL_INIT_PRIORITY_DEVICE but before CONFIG_RPMSG_SERVICE_INIT_PRIORITY so that bt_enable will work, but this causes crashes under some BLE behaviour.

    I am not sure if I understand this correctly but bluetooth cannot start first before rpmsg are initialized since the bluetooth uses rpmsg to communicate with the netcore.

    Is there a way to enable RPMSG in the netcore application without waiting for the appcore application starting?

    No, not when netcore is remote. You try to change the code of the rpmsg_virtio.c so that the remote initializes the buffer and the master waits for the remote to finish initializes the buffer. But this would need changing rpmsg_init_vdev and I do not know if there are any sideeffects of this.

Related