How to use hal external module with Zephyr?

I'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'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 files hal_flash.c and hal_flash.h 

How can I add cmake files kconfig files to make it work with zephyr application

note: app on nRF9160

Parents Reply Children
  • yes my intention is the first option

    I still get some problem,

    here is what I did:

    added module to the west.yml file

    and this is the structure of the module:

    <module_repo>
    ├── CMakeLists.txt
    ├── prj.conf
    ├── zephyr
        └── module.yml
    └── drivers
        └── foo
            ├── hal_flash.c
            ├── CMakeLists.txt
            ├── Kconfig
            └──include
               └──hal_flash.h

    module_repo/CMakeLists  contains

    set(ZEPHYR_EXTRA_MODULES drivers/foo)
    zephyr_include_directories(${ZEPHYR_EXTRA_MODULES})
    find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})

    module_repo/prj.conf contains

    CONFIG_FOO=y

    in module_repo/drivers/foo/CMakeLists.txt : 

    zephyr_library()
    zephyr_include_directories(include)
    zephyr_library_sources_ifdef(CONFIG_FOO hal_flash.c)

    in module_repo/drivers/foo/Kconfig : 

    menuconfig FOO
            bool "foo driver"
            default y
            help
              Enable support for foo driver
    
    if FOO
    
    module = FOO
    module-str = foo
    source "subsys/logging/Kconfig.template.log_config"
    
    endif

    and module_repo/zephyr/module.yml : 

    build:
      cmake: .
      kconfig: drivers/foo/Kconfig
    

    and when I test my application (with CONF_FOO=y in prj.conf of the app) I got this error : 

    src/main.c:9: undefined reference to `hal_flash_flush'

  • mourad said:

    yes my intention is the first option

    Ah ok. I don't see anything obvious missing in what you've done here.

    You might have more luck if you get in touch with the Zephyr community directly, they probably have more experience with this:

    Zephyr on Discord

    Zephyr on Github

  • I found the problem:

    I should change module_repo/CMakeLists to: 

    add_subdirectory(drivers/foo)

Related