<?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>Sample project to demonstrate kernel space and user space</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/93253/sample-project-to-demonstrate-kernel-space-and-user-space</link><description>Hi, 
 
 I am using a nrf528409dk for my application development using nCS. I have various features from which I need to understand how to add some high priority features into kernel space and some low priority features into user space. 
 Kindly share</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Sat, 29 Oct 2022 12:17:21 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/93253/sample-project-to-demonstrate-kernel-space-and-user-space" /><item><title>RE: Sample project to demonstrate kernel space and user space</title><link>https://devzone.nordicsemi.com/thread/393106?ContentTypeID=1</link><pubDate>Sat, 29 Oct 2022 12:17:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:742b8e70-3f3e-4160-b349-7acb88d50720</guid><dc:creator>Ubaid_M</dc:creator><description>&lt;p&gt;Sure,Thanks&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sample project to demonstrate kernel space and user space</title><link>https://devzone.nordicsemi.com/thread/392839?ContentTypeID=1</link><pubDate>Thu, 27 Oct 2022 12:56:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3e377e60-95a7-4202-853d-8a21fc128e12</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;I&amp;#39;m not sure about this question. I will be gone now for a long time, so would you be able to open a new DevZone ticket about this?&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sample project to demonstrate kernel space and user space</title><link>https://devzone.nordicsemi.com/thread/392812?ContentTypeID=1</link><pubDate>Thu, 27 Oct 2022 11:58:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b648ee8c-f821-4abd-94f0-edae0f6fe3c0</guid><dc:creator>Ubaid_M</dc:creator><description>&lt;p&gt;Thanks&amp;nbsp;&lt;a class="internal-link view-user-profile" href="https://devzone.nordicsemi.com/members/simoniversen"&gt;Simon&lt;/a&gt;, That was largely helpful.&lt;br /&gt;&lt;br /&gt;As a last query of mine, if we take an example of nrf52840dk, which has onboard QSPI external flash.&lt;/p&gt;
&lt;p&gt;&lt;span style="text-decoration:underline;"&gt;&lt;em&gt;Can I treat the internal flash here in, to work on kernel space only, while having the&amp;nbsp;QSPI external flash to work on user space..?&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="text-decoration:underline;"&gt;&lt;/span&gt;If possible, has such a thing been done..?&lt;br /&gt;Please help me with any sample project available for the same.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sample project to demonstrate kernel space and user space</title><link>https://devzone.nordicsemi.com/thread/392810?ContentTypeID=1</link><pubDate>Thu, 27 Oct 2022 11:46:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8db53a0d-a440-42fa-9ace-9baca9377a93</guid><dc:creator>Simon</dc:creator><description>[quote user="Ubaid_M"]1. What would be the ideal way to communicate between kernel threads and user threads..? Is it message queues..?[/quote]
&lt;p&gt;Yes, that could work. See&amp;nbsp;&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/92202/recommended-best-practice-for-a-multithreaded-sensor/387456"&gt;RE: Recommended best practice for a multithreaded sensor&lt;/a&gt;&amp;nbsp;for other ways of thread communication.&lt;/p&gt;
[quote user="Ubaid_M"]2. Does it make sense if I treat all peripheral (SPI, I2C, UART etc,.) handlers as individual kernel space threads and all application algorithms that&amp;nbsp;consume the peripheral data as user space threads..?[/quote]
&lt;p&gt;That could work. Here are some example use cases of Zephyr&amp;#39; user mode feature:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;The kernel can protect against many unintentional programming errors which could otherwise silently or spectacularly corrupt the system.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The kernel can sandbox complex data parsers such as interpreters, network protocols, and filesystems such that malicious third-party code or data cannot compromise the kernel or other threads.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The kernel can support the notion of multiple logical “applications”, each with their own group of threads and private data structures, which are isolated from each other if one crashes or is otherwise compromised.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Read more in&amp;nbsp;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.1.0/zephyr/kernel/usermode/overview.html#overview"&gt;https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.1.0/zephyr/kernel/usermode/overview.html#overview&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sample project to demonstrate kernel space and user space</title><link>https://devzone.nordicsemi.com/thread/392696?ContentTypeID=1</link><pubDate>Wed, 26 Oct 2022 17:38:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a4a31dea-160d-4281-8d80-0b0b5d781d24</guid><dc:creator>Ubaid_M</dc:creator><description>&lt;p&gt;Thank you&amp;nbsp;&lt;a class="internal-link view-user-profile" href="https://devzone.nordicsemi.com/members/simoniversen"&gt;Simon&lt;/a&gt;,&lt;/p&gt;
&lt;p&gt;1. What would be the ideal way to communicate between kernel threads and user threads..? Is it message queues..?&lt;/p&gt;
&lt;p&gt;2. Does it make sense if I treat all peripheral (SPI, I2C, UART etc,.) handlers as individual kernel space threads and all application algorithms that&amp;nbsp;consume the peripheral data as user space threads..?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks,&lt;br /&gt;Ubaid&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sample project to demonstrate kernel space and user space</title><link>https://devzone.nordicsemi.com/thread/392678?ContentTypeID=1</link><pubDate>Wed, 26 Oct 2022 14:33:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:63348c0d-d623-4d26-bc45-a853cf0f7fa8</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;Just omit the K_USER option when creating the thread. See the following sample:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/user_5F00_supervisor_5F00_mode_5F00_test.zip"&gt;devzone.nordicsemi.com/.../user_5F00_supervisor_5F00_mode_5F00_test.zip&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;It should give the following output:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;*** Booting Zephyr OS build v3.1.99-ncs1  ***
user_function: UserSpace! (nrf52840dk_nrf52840)
supervisor_function: privileged mode. (nrf52840dk_nrf52840)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;
&lt;div style="left:282px;top:301.2px;"&gt;
&lt;div&gt;&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sample project to demonstrate kernel space and user space</title><link>https://devzone.nordicsemi.com/thread/392614?ContentTypeID=1</link><pubDate>Wed, 26 Oct 2022 12:09:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7f6b946b-0b6f-440c-b997-ecf4abc9d49f</guid><dc:creator>Ubaid_M</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;Can you point me towards thread creation in kernel space similarly.&lt;br /&gt;I want to have both kernel space and user space threads in my app.&lt;/p&gt;
[quote userid="72692" url="~/f/nordic-q-a/93253/sample-project-to-demonstrate-kernel-space-and-user-space/392611"]In order to&amp;nbsp;drop&amp;nbsp;a thread down to user mode[/quote]
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sample project to demonstrate kernel space and user space</title><link>https://devzone.nordicsemi.com/thread/392611?ContentTypeID=1</link><pubDate>Wed, 26 Oct 2022 12:05:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b4f81e2d-07d1-461a-aa2c-fef58d6f54c6</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;As mentioned in the &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.1.0/zephyr/kernel/services/threads/index.html#:~:text=%20by%20default%2C%20threads%20run%20in%20supervisor%20mode"&gt;zephyr thread documentation&lt;/a&gt;, &lt;span&gt;threads run in supervisor mode by default&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;In order to&amp;nbsp;drop&amp;nbsp;a thread down to user mode, set&amp;nbsp;&lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/v3.1.99-ncs1/arch/Kconfig#L261"&gt;CONFIG_USERSPACE&lt;/a&gt;=y in the prj.conf file and crete the thread like done in the&amp;nbsp;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/v3.1.99-ncs1/samples/userspace/hello_world_user/src/main.c#L25-L27"&gt;hello_world_user sample&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;You need to use the &lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/v3.1.99-ncs1/samples/userspace/hello_world_user/src/main.c#L27"&gt;K_USER&lt;/a&gt; option when creating the thread&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>