<?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>How to use hal external module with Zephyr?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/91433/how-to-use-hal-external-module-with-zephyr</link><description>I&amp;#39;m trying to create a HAL library to use it with zephyr application 
 From what I have read I need to create another module . 
 I can&amp;#39;t figure out how to set up the module and how to compile it. 
 for the moment I have only 1 module to add with the following</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 31 Aug 2022 08:52:11 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/91433/how-to-use-hal-external-module-with-zephyr" /><item><title>RE: How to use hal external module with Zephyr?</title><link>https://devzone.nordicsemi.com/thread/384074?ContentTypeID=1</link><pubDate>Wed, 31 Aug 2022 08:52:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4832679f-7329-4b9e-82d3-da61d2a936e1</guid><dc:creator>mourad</dc:creator><description>&lt;p&gt;I found the problem:&lt;/p&gt;
&lt;p&gt;I should change &lt;span&gt;module_repo/CMakeLists&amp;nbsp;&lt;/span&gt;&lt;span&gt;to:&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;add_subdirectory(drivers/foo)&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to use hal external module with Zephyr?</title><link>https://devzone.nordicsemi.com/thread/384067?ContentTypeID=1</link><pubDate>Wed, 31 Aug 2022 08:16:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:94d3cbc1-662e-45bb-8cd9-009e07fa392b</guid><dc:creator>Einarh</dc:creator><description>[quote user="mourad"]&lt;p&gt;yes my intention is the first option&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;[/quote]
&lt;p&gt;Ah ok. I don&amp;#39;t see anything obvious missing in what you&amp;#39;ve done here.&lt;/p&gt;
&lt;p&gt;You might have more luck if you get in touch with the Zephyr community directly, they probably have more experience with this:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://discord.com/invite/Ck7jw53nU2"&gt;Zephyr on Discord&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/zephyrproject-rtos/zephyr/issues"&gt;Zephyr on Github&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to use hal external module with Zephyr?</title><link>https://devzone.nordicsemi.com/thread/383975?ContentTypeID=1</link><pubDate>Tue, 30 Aug 2022 15:36:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:723f4386-cb30-4adc-9389-abf006345f90</guid><dc:creator>mourad</dc:creator><description>&lt;p&gt;yes my intention is the first option&lt;/p&gt;
&lt;p&gt;I still get some problem,&lt;/p&gt;
&lt;p&gt;here is what I did:&lt;/p&gt;
&lt;p&gt;added module to the west.yml file&lt;/p&gt;
&lt;p&gt;and this is the structure of the module:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;&amp;lt;module_repo&amp;gt;
├── CMakeLists.txt
├── prj.conf
├── zephyr
    └── module.yml
└── drivers
    └── foo
        ├── hal_flash.c
        ├── CMakeLists.txt
        ├── Kconfig
        └──include
           └──hal_flash.h&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;module_repo/CMakeLists&amp;nbsp; contains&lt;pre class="ui-code" data-mode="text"&gt;set(ZEPHYR_EXTRA_MODULES drivers/foo)
zephyr_include_directories(${ZEPHYR_EXTRA_MODULES})
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;module_repo/prj.conf contains&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;CONFIG_FOO=y&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;in module_repo/drivers/foo/CMakeLists.txt :&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;zephyr_library()
zephyr_include_directories(include)
zephyr_library_sources_ifdef(CONFIG_FOO hal_flash.c)&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;in module_repo/drivers/foo/Kconfig :&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;menuconfig FOO
        bool &amp;quot;foo driver&amp;quot;
        default y
        help
          Enable support for foo driver

if FOO

module = FOO
module-str = foo
source &amp;quot;subsys/logging/Kconfig.template.log_config&amp;quot;

endif&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;and&amp;nbsp;module_repo/zephyr/module.yml :&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;build:
  cmake: .
  kconfig: drivers/foo/Kconfig
&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;and when I test my application (with CONF_FOO=y in prj.conf of the app) I got this error :&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;src/main.c:9: undefined reference to `hal_flash_flush&amp;#39;&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to use hal external module with Zephyr?</title><link>https://devzone.nordicsemi.com/thread/383966?ContentTypeID=1</link><pubDate>Tue, 30 Aug 2022 14:33:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:249f8078-975e-4bda-8487-f84a1a9e234c</guid><dc:creator>Einarh</dc:creator><description>&lt;p&gt;Is you intention to make an official Zephyr module? In that case you can find info about how to do that here:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://docs.zephyrproject.org/latest/develop/modules.html"&gt;https://docs.zephyrproject.org/latest/develop/modules.html&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;If not, I would recommend simply including your library/driver files in the src directory in each of your projects.&lt;/p&gt;
&lt;p&gt;You can find most of the info you&amp;#39;ll need about the configuration- and build system here:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://docs.zephyrproject.org/latest/develop/application/index.html"&gt;https://docs.zephyrproject.org/latest/develop/application/index.html&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;-Einar&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to use hal external module with Zephyr?</title><link>https://devzone.nordicsemi.com/thread/383957?ContentTypeID=1</link><pubDate>Tue, 30 Aug 2022 13:49:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5101370e-befd-4616-9be8-ae44ad8c5902</guid><dc:creator>mourad</dc:creator><description>&lt;p&gt;it will be used in many application so it&amp;#39;s more practical to make it as module&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to use hal external module with Zephyr?</title><link>https://devzone.nordicsemi.com/thread/383952?ContentTypeID=1</link><pubDate>Tue, 30 Aug 2022 13:40:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:62d14419-d879-42d9-ba00-0e2806cebbf2</guid><dc:creator>Einarh</dc:creator><description>&lt;p&gt;In your application you can include a header file from your src directory as&lt;/p&gt;
&lt;pre&gt;#include &amp;quot;hal_xxx.h&amp;quot;&lt;/pre&gt;
&lt;p&gt;Look at how it&amp;#39;s done in one of the more complicated samples such as for example the Asset Tracker v2 application.&lt;/p&gt;
&lt;p&gt;-Einar&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to use hal external module with Zephyr?</title><link>https://devzone.nordicsemi.com/thread/383927?ContentTypeID=1</link><pubDate>Tue, 30 Aug 2022 12:56:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bdd57612-86ea-4dfa-90fc-68028c4e7b4b</guid><dc:creator>mourad</dc:creator><description>&lt;p&gt;Hi Einarh&lt;/p&gt;
&lt;p&gt;Thanks for helping&lt;/p&gt;
&lt;p&gt;I want to create external module with my own hal files.&lt;/p&gt;
&lt;p&gt;then when creating an application I just want only to include the hal&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;#include &amp;lt;hal_xxx.h&amp;gt;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;and add this in prj.conf&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;CONFIG_hal_xxx=y&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to use hal external module with Zephyr?</title><link>https://devzone.nordicsemi.com/thread/383921?ContentTypeID=1</link><pubDate>Tue, 30 Aug 2022 12:47:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7a4a7c3d-2d2a-4877-8acc-b16fe9ba862a</guid><dc:creator>Einarh</dc:creator><description>&lt;p&gt;Hello&lt;/p&gt;
&lt;p&gt;Any reason you&amp;#39;re trying to put your driver into the nrfx tree?&lt;/p&gt;
&lt;p&gt;If I wanted to include my own driver in a project I would just put the files under src/ in the application folder.&lt;/p&gt;
&lt;p&gt;Then you&amp;#39;ll just need to add your drivers as sources in CMakeLists, see for example the Asset Tracker v2 sample in NCS as an example of how this is done.&lt;/p&gt;
&lt;p&gt;The error you&amp;#39;re getting means that your CONFIG_NRFX_FLASH symbol isn&amp;#39;t defined properly.&lt;/p&gt;
&lt;p&gt;I&amp;#39;m not entirely sure what you&amp;#39;ll have to do to make Kconfig recognize your config symbol, but I can look into it.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Einar&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to use hal external module with Zephyr?</title><link>https://devzone.nordicsemi.com/thread/383832?ContentTypeID=1</link><pubDate>Tue, 30 Aug 2022 09:17:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fc487a59-62ff-435b-834e-7bbf221b65fe</guid><dc:creator>mourad</dc:creator><description>&lt;p&gt;I used this project as reference&amp;nbsp;&lt;a id="" href="https://github.com/zephyrproject-rtos/hal_nrfx"&gt;https://github.com/zephyrproject-rtos/hal_nrfx&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I made those changes:&lt;/p&gt;
&lt;p&gt;and added flash.h file to &amp;quot;nrfx/drivers/include&amp;quot; and flash.c to &amp;quot;&lt;span&gt;nrfx/drivers/src/&lt;/span&gt;&amp;quot;&lt;/p&gt;
&lt;p&gt;and changed the CMakeLists and added this line&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;zephyr_sources_ifdef(CONFIG_NRFX_FLASH   nrfx/drivers/src/hal_flash.c)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;and for the test I created an app folder with this structure&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;hal_nrfx/app
├── CMakeLists.txt
├── prj.conf
└── src
    └── main.c
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;in main i include&amp;nbsp;&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;#include&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;&amp;lt;hal_flash.h&amp;gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;In the prj.conf I added&amp;nbsp;&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;CONFIG_NRFX_FLASH&lt;/span&gt;&lt;span&gt;=y&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 I keep getting this error when I try to build with &amp;quot;west build -p auto -b nrf9160dk_nrf9160_ns .&amp;quot;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;img style="max-height:240px;max-width:320px;" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1661851017357v1.png" alt=" " /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>