Skip to content

Add proper Zephyr module support with updated HAL for v3/v4 compatibility #407

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

tbitcs
Copy link

@tbitcs tbitcs commented Jun 16, 2025

Summary

This PR introduces first-class support for integrating CryptoAuthLib as a Zephyr module, compatible with Zephyr v3 and v4. It enables seamless integration into modern Zephyr-based applications using CMake and Kconfig, and updates the I2C and SPI HALs to align with Zephyr's evolving include path conventions.

Note: This change breaks compatibility with Zephyr v2.x due to header path and module resolution changes.


Key Changes

  • Added module.yml to enable Zephyr module recognition via west.
  • Introduced ATCA_ZEPHYR_SUPPORT CMake option to toggle Zephyr build mode.
  • Created zephyr_options.cmake to map CONFIG_ATCA_* Kconfig options to internal CMake flags.
  • Refactored HAL sources (I2C, SPI) to use updated Zephyr include paths (zephyr/drivers/...) required in Zephyr ≥ v3.
  • Updated top-level CMakeLists to:
  • Detect Zephyr toolchain
  • Build as a zephyr_library() when enabled
  • Export include paths and config headers for Zephyr apps

Integration Instructions

To include CryptoAuthLib as a Zephyr module:

Option 1: In-tree

Place CryptoAuthLib under modules/lib/cryptoauthlib and it will be automatically detected.

Option 2: Out-of-tree

If using a separate path:

# Add this line before find_package(Zephyr)
set(EXTRA_ZEPHYR_MODULES ${CMAKE_CURRENT_SOURCE_DIR}/../modules/lib/cryptoauthlib)

Kconfig Support

Once integrated, you can configure CryptoAuthLib via prj.conf using new symbols:

CONFIG_ATCA_HAL_I2C=y
CONFIG_ATCA_CRYPTO_MBEDTLS=y
CONFIG_ATCA_DEVICE_SUPPORT_ECC608=y

These options automatically propagate to the CMake build system, enabling or disabling relevant sources and flags.


Compatibility Notes

  • Verified working on Zephyr v3.5 and v4.1.0
  • Breaks backward compatibility with Zephyr v2.x
  • No functional changes for non-Zephyr builds (Linux/MPLAB/Harmony remain unaffected)

Request

If possible, please test against MPLAB Harmony and existing Linux builds to ensure continued compatibility. Feedback and improvements welcome!

Feature branch: https://github.com/BitConcepts/cryptoauthlib/tree/feature/zephyr-module-support-v3-v4

tbitcs and others added 4 commits June 13, 2025 18:21
Introduce ATCA_ZEPHYR_SUPPORT CMake option to enable proper Zephyr module builds

Map Kconfig CONFIG_ATCA_* symbols into ATCA_* CMake variables

Refresh I2C and SPI HAL drivers to use Zephyr 3 include locations

Build CryptoAuthLib as a Zephyr library when enabled

Incompatible with Zephyr v2 due to changed include paths
Provides instructions on how to incorporate CryptoAuthLib as a Zephyr module, including out-of-tree and in-tree application setups.

Explains how to configure available Kconfig options and how they are mapped into CMake options and the atca_config.h file for seamless Zephyr integration.
@ElectroInnovator
Copy link

Follow-Up Update: I2C Send Function Refactored for Zephyr HAL

This follow-up commit introduces a significant improvement to the I2C HAL layer for Zephyr:

Summary

Refactors hal_i2c_send in hal_zephyr_i2c.c to support word-address-based I2C transfers and improve compatibility with Zephyr's I2C API.

Key Changes

  • Updated function signature: uses word_address instead of address for semantic clarity.

  • Reads device address from ATCAIfaceCfg, supporting both atcai2c->slave_address and cfg->dev_addr for backward compatibility.

  • Implements a two-message I2C transfer:

    • First message transmits the word address.
    • Second (optional) message transmits the data buffer, if data is provided.
  • Uses i2c_transfer() instead of i2c_write() for explicit control over transaction flags.

  • Sets appropriate I2C flags:

    • I2C_MSG_WRITE
    • I2C_MSG_STOP only after the final message
  • Adds parameter validation for both the Zephyr I2C device and the provided config structure.

Motivation

Many I2C peripherals require a separate word address phase before sending data. This update ensures broader device compatibility and aligns our I2C send logic with Zephyr HAL best practices.

Impact

  • Increases robustness and configurability of I2C transactions.
  • No API change for external callers of hal_i2c_send(), aside from the renamed argument.
  • Improves support for devices with word-addressed registers (e.g., EEPROMs, secure elements).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants