<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>nRF5340 - Accessing Shared Memory</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/89972/nrf5340---accessing-shared-memory</link><description>Hello. I am just getting started with nRF5340 development using the u-Blox NORA-B106 dev kit. I am trying to use the peripheral_uart code example to understand how the two processors use the shared memory space to communicate. I am able to send data over</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 29 Mar 2023 13:33:47 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/89972/nrf5340---accessing-shared-memory" /><item><title>RE: nRF5340 - Accessing Shared Memory</title><link>https://devzone.nordicsemi.com/thread/418125?ContentTypeID=1</link><pubDate>Wed, 29 Mar 2023 13:33:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ce86d0fb-3a5a-4636-a118-b2c2d9a286cd</guid><dc:creator>Elfving</dc:creator><description>&lt;p&gt;Hello and sorry about the delay. I must&amp;#39;ve overlooked this case for a while.&lt;/p&gt;
[quote user="jmilliken"]So now we have established a shared memory region, okay, so far so good.[/quote]
&lt;p&gt;Yes, this is where it is defined.&lt;/p&gt;
&lt;p&gt;The documentation on what is mentioned in the snippets you have from device tree there could arguably be improved, but there is a lot available. &lt;a href="https://docs.zephyrproject.org/3.1.0/build/dts/api/bindings/ipc/zephyr%2Cipc-openamp-static-vrings.html"&gt;Here is a bit on the &amp;quot;ipc-openamp-static-vrings&lt;/a&gt;&amp;quot; devicetree &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.0.0/zephyr/build/dts/bindings.html#dt-bindings"&gt;binding,&lt;/a&gt; and there is apparently also a &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.2.0/zephyr/samples/subsys/ipc/ipc_service/static_vrings/README.html"&gt;sample&lt;/a&gt; on it. And here is a bit on the &lt;a href="https://docs.zephyrproject.org/latest/hardware/peripherals/mbox.html"&gt;mboxes&lt;/a&gt;.&lt;/p&gt;
[quote user="jmilliken"]also, where are the linker files?[/quote]
&lt;p&gt;Build/zephyr/&lt;/p&gt;
[quote user="jmilliken"]How do each of the programs use this memory region?[/quote]
&lt;p&gt;Well that depends. IPC might be the most common, though here is also an example of something a bit more basic: &lt;a href="https://github.com/nrfconnect/sdk-nrf/blob/main/subsys/pcd/src/pcd.c"&gt;this module&lt;/a&gt; is used to write a single struct to a RAM area which is known by both cores. The appcore writes &lt;a href="https://github.com/nrfconnect/sdk-mcuboot/blob/master/boot/bootutil/src/loader.c#L798"&gt;here&lt;/a&gt;, and the netcore reads &lt;a href="https://github.com/nrfconnect/sdk-nrf/blob/master/samples/nrf5340/netboot/src/main.c#L47"&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;In the case of IPC, the &lt;a href="https://infocenter.nordicsemi.com/pdf/nRF5340_PS_v1.3.pdf"&gt;PS&lt;/a&gt; probably describes this best (Section 7.16).&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The IPC indicates to the other core that there is new data available to pick up. The actual data exchange is handled by Open Asymmetric Multi-Processing (OpenAMP). Zephyr includes the OpenAMP library, which provides a complete solution for exchanging messages between the cores. The IPC peripheral is presented to Zephyr as an Interprocessor Mailbox (IPM) device. The OpenAMP library uses the IPM SHIM layer, which in turn uses the IPC driver in nrfx.&lt;/p&gt;
[quote user="jmilliken"]&lt;span&gt;const&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;struct&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;device&lt;/span&gt;&lt;span&gt; *&lt;/span&gt;&lt;span&gt;hci_ipc_instance&lt;/span&gt;&lt;span&gt; = &lt;/span&gt;&lt;span&gt;DEVICE_DT_GET&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;DT_NODELABEL&lt;/span&gt;&lt;span&gt;(ipc0));&lt;/span&gt;[/quote]
&lt;p&gt;That creates a pointer to the device driver. There is more on that &lt;a href="https://academy.nordicsemi.com/topic/device-driver-model/"&gt;here&lt;/a&gt;.&lt;/p&gt;
[quote user="jmilliken"]How is peripheral_uart using the ipc system and the shared memory?[/quote]
&lt;p&gt;I believe this happens in the dts file nrf5340_cpuapp_common.dts:&lt;img style="max-height:240px;max-width:320px;" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1680096820143v2.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;REgards,&lt;/p&gt;
&lt;p&gt;Elfving&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF5340 - Accessing Shared Memory</title><link>https://devzone.nordicsemi.com/thread/414796?ContentTypeID=1</link><pubDate>Mon, 13 Mar 2023 01:47:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:049fcac7-9e42-49a9-abae-81d3dfa2f61e</guid><dc:creator>jmilliken</dc:creator><description>&lt;p&gt;Another notable thing - looking at both zephyr.map files, neither file seems to have any data structures living in the shared memory range. Shouldn&amp;#39;t I see some overlapping variables at 0x20070000 vicinity?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF5340 - Accessing Shared Memory</title><link>https://devzone.nordicsemi.com/thread/414781?ContentTypeID=1</link><pubDate>Sun, 12 Mar 2023 20:54:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6d10b0b5-698e-4aac-8729-c328d213d5a3</guid><dc:creator>jmilliken</dc:creator><description>&lt;p&gt;Hello. I am revisiting this topic lately and still need some clarification. I am looking at the device tree includes and can see that both the peripheral_uart project and the hci_rpmsg project eventually include &amp;quot;nrf5340_shared_sram_planning_conf.dts&amp;quot; which gives the following:&lt;/p&gt;
&lt;p&gt;chosen {&lt;br /&gt;&amp;nbsp; &amp;nbsp;/* shared memory reserved for the inter-processor communication */&lt;br /&gt;&amp;nbsp; &amp;nbsp;zephyr,ipc_shm = &amp;amp;sram0_shared;&lt;br /&gt; };&lt;/p&gt;
&lt;p&gt;reserved-memory {&lt;br /&gt;&amp;nbsp; &amp;nbsp;#address-cells = &amp;lt;1&amp;gt;;&lt;br /&gt;&amp;nbsp; &amp;nbsp;#size-cells = &amp;lt;1&amp;gt;;&lt;br /&gt;&amp;nbsp; &amp;nbsp;ranges;&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp;sram0_shared: memory@20070000 {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; /* SRAM allocated to shared memory */&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; reg = &amp;lt;0x20070000 0x10000&amp;gt;;&lt;br /&gt;&amp;nbsp; &amp;nbsp;};&lt;br /&gt; };&lt;/p&gt;
&lt;p&gt;So now we have established a shared memory region, okay, so far so good. Next, I see in each device tree, somewhere the following eventually gets included:&lt;/p&gt;
&lt;p&gt;ipc0: ipc0 {&lt;br /&gt;&amp;nbsp; &amp;nbsp;compatible = &amp;quot;zephyr,ipc-openamp-static-vrings&amp;quot;;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp;memory-region = &amp;lt;&amp;amp;sram0_shared&amp;gt;;&lt;br /&gt;&amp;nbsp; &amp;nbsp;mboxes = &amp;lt;&amp;amp;mbox 0&amp;gt;, &amp;lt;&amp;amp;mbox 1&amp;gt;;&lt;br /&gt;&amp;nbsp; &amp;nbsp;mbox-names = &amp;quot;tx&amp;quot;, &amp;quot;rx&amp;quot;;&lt;br /&gt;&amp;nbsp; &amp;nbsp;role = &amp;quot;host&amp;quot;;&lt;br /&gt;&amp;nbsp; &amp;nbsp;status = &amp;quot;okay&amp;quot;;&lt;br /&gt;};&lt;/p&gt;
&lt;p&gt;So now we have the ipc module attached to the shared memory region. However, here is where I get lost. How do each of the programs use this memory region? Normally I would expect to see something like __attribute__ used in front of a variable to denote that it should be placed in that region by the linker (also, where are the linker files?).&lt;/p&gt;
&lt;p&gt;In the hci_rpmsg main.c, I can at least see some references to this, such as:&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;const&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;struct&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;device&lt;/span&gt;&lt;span&gt; *&lt;/span&gt;&lt;span&gt;hci_ipc_instance&lt;/span&gt;&lt;span&gt; = &lt;/span&gt;&lt;span&gt;DEVICE_DT_GET&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;DT_NODELABEL&lt;/span&gt;&lt;span&gt;(ipc0));&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;and:&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;const&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;struct&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;device&lt;/span&gt;&lt;span&gt; *&lt;/span&gt;&lt;span&gt;hci_ipc_instance&lt;/span&gt;&lt;span&gt; = &lt;/span&gt;&lt;span&gt;DEVICE_DT_GET&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;DT_NODELABEL&lt;/span&gt;&lt;span&gt;(ipc0));&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;But how does this link back to the sram0_shared region? Also, how are the mailboxes used in this context? How large are the mailboxes (i.e. where is the mailbox size determined).&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;Now, on the other end, the main.c from the peripheral_uart project, I don&amp;#39;t see any references to the ipc system at all. This leads me to believe that the bt_nus is somehow uses this information behind the scenes, but I&amp;#39;m so far unable to follow the function calls back through to anything that makes this explicit. How is peripheral_uart using the ipc system and the shared memory?&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;-Jamie&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF5340 - Accessing Shared Memory</title><link>https://devzone.nordicsemi.com/thread/377742?ContentTypeID=1</link><pubDate>Wed, 20 Jul 2022 00:59:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6c743721-ee76-437d-82ea-499e2ba34ff7</guid><dc:creator>jmilliken</dc:creator><description>&lt;p&gt;Thank you. the DevAcademy link looks like a very good starting point. I will work my way through that.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF5340 - Accessing Shared Memory</title><link>https://devzone.nordicsemi.com/thread/377627?ContentTypeID=1</link><pubDate>Tue, 19 Jul 2022 12:35:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:35238f37-dcb6-4e1c-84a4-0a7b3deda883</guid><dc:creator>Elfving</dc:creator><description>&lt;p&gt;Hello again,&lt;/p&gt;
[quote user=""]Coming from STM32 and FreeRTOS, so the Zephyr learning curve is feeling steep so far. Any help is appreciated.[/quote]
&lt;p&gt;That is very understandable. To start off, I would recommend you to take a look at our &lt;a href="https://academy.nordicsemi.com/"&gt;DevAcademy&lt;/a&gt;, which will give you a basic understanding of Zephyr.&lt;/p&gt;
&lt;p&gt;You are right in that the inter-core communication is happening using shared memory. This is unfortunately a complex topic, and difficult to give basic example of. The documentation on the &lt;a href="https://infocenter.nordicsemi.com/index.jsp?topic=%2Fps_nrf5340%2Fchapters%2Fsoc_overview%2Fdoc%2Fsoc_overview.html&amp;amp;cp=3_0_0_2_1&amp;amp;anchor=memory"&gt;nRF5340&lt;/a&gt; and the &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.0.0/nrf/ug_nrf5340.html"&gt;documentation on working with it&lt;/a&gt; describes a little bit about it. &lt;a href="https://devzone.nordicsemi.com/support-private/support/290919#permalink=767640"&gt;And this previous case of mine describes a bit more&lt;/a&gt;. Taking a look at the examples I linked to there will probably be beneficial, and answer your second question.&lt;/p&gt;
&lt;p&gt;When it comes to how this is done in a project like the peripheral_uart sample, I would have to get back to you.&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Elfving&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF5340 - Accessing Shared Memory</title><link>https://devzone.nordicsemi.com/thread/376923?ContentTypeID=1</link><pubDate>Thu, 14 Jul 2022 10:23:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f350fc1e-27c4-4e7c-8a89-9a7c368c6990</guid><dc:creator>Elfving</dc:creator><description>&lt;p&gt;Hello Jamie,&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I will get back to you on this. Note that w&lt;/span&gt;&lt;span&gt;e have entered the summer holiday period in Norway so staffing is low, some delayed response time should be expected.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Regards,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Elfving&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>