Add proper Zephyr module support with updated HAL for v3/v4 compatibility by tbitcs · Pull Request #407 · MicrochipTech/cryptoauthlib · GitHub
Skip to content

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

Open
tbitcs wants to merge 7 commits into
MicrochipTech:mainfrom
BitConcepts:feature/zephyr-module-support-v3-v4
Open

Add proper Zephyr module support with updated HAL for v3/v4 compatibility#407
tbitcs wants to merge 7 commits into
MicrochipTech:mainfrom
BitConcepts:feature/zephyr-module-support-v3-v4

Conversation

@tbitcs

@tbitcs tbitcs commented Jun 16, 2025

Copy link
Copy Markdown

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
Copy Markdown

@github-actions

github-actions Bot commented Sep 7, 2025

Copy link
Copy Markdown

This PR has been marked as stale and will be automatically closed in 7 days.

@github-actions github-actions Bot added the Stale label Sep 7, 2025
@github-actions github-actions Bot removed the Stale label Sep 12, 2025
@github-actions

Copy link
Copy Markdown

This PR has been marked as stale and will be automatically closed in 7 days.

@github-actions github-actions Bot added the Stale label Nov 18, 2025
@tbitcs

tbitcs commented Nov 26, 2025

Copy link
Copy Markdown
Author

Just checking in on the status of PR #407. I understand things can get busy, but I wanted to keep this from going stale. If there are any updates or concerns, please let me know how I can assist to help move this forward. Thank you!

@github-actions github-actions Bot removed the Stale label Nov 26, 2025
@Srinivas-E

Copy link
Copy Markdown
Collaborator

Hi @tbitcs ,
We are planning this PR for review and merge at our next CAL release (mostly on v3.8.0 slotted for ~ Mar release - for your note and info.

@github-actions

github-actions Bot commented Feb 1, 2026

Copy link
Copy Markdown

This PR has been marked as stale and will be automatically closed in 7 days.

@github-actions github-actions Bot added the Stale label Feb 1, 2026
@tbitcs

tbitcs commented Feb 1, 2026

Copy link
Copy Markdown
Author

Commenting to keep this PR from going stale.

@Srinivas-E Srinivas-E self-assigned this Feb 2, 2026
@github-actions github-actions Bot removed the Stale label Feb 3, 2026
- hal_i2c_send: Use ATCA_IFACECFG_I2C_ADDRESS macro for ATCA_STRICT_C99
- hal_zephyr_spi: Fix spi_cs_control for Zephyr v3+ (gpio_dt_spec)
- hal_zephyr_spi: Use hal_malloc/hal_free instead of stdlib malloc
- hal_zephyr_spi: Fix sizeof(hal_data) bug (pointer vs struct)
- hal_zephyr_spi: Fix memory leak in hal_spi_release
- hal_zephyr_spi: Replace printf with printk
- zephyr_options.cmake: Fix Kconfig-to-CMake variable name mapping
- lib/CMakeLists.txt: Remove redundant project()/find_package(Zephyr)
- lib/CMakeLists.txt: Normalize SET to set
- Kconfig: Rewrite to Zephyr style (menuconfig, if guards, depends on)
- Add ztest build-verification test suite

Tested: Windows (HID HAL), Linux (I2C+SPI+UART+PKCS11+TNG), Zephyr 4.2 (module loads, Kconfig resolves)

Co-Authored-By: Oz <oz-agent@warp.dev>
@tbitcs

tbitcs commented Apr 3, 2026

Copy link
Copy Markdown
Author

@tbitcs tbitcs force-pushed the feature/zephyr-module-support-v3-v4 branch from baf1125 to 572487d Compare April 29, 2026 12:06
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.

4 participants