Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions boards/ambiq/apollo4p_blue_kxr_evb/apollo4p_blue_kxr_evb.dts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
sw1 = &button1;
rtc = &rtc0;
pwm-led0 = &pwm_led0;
crc0 = &crc32;
};

leds {
Expand Down Expand Up @@ -189,6 +190,10 @@ zephyr_udc0: &usb {
status = "okay";
};

&crc32 {
status = "okay";
};

&gpio0_31 {
status = "okay";
};
Expand Down
7 changes: 0 additions & 7 deletions boards/ambiq/apollo4p_evb/apollo4p_evb-pinctrl.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,4 @@
ambiq,pull-up-ohms = <12000>;
};
};
pwm2_default: pwm2_default{
group1 {
pinmux = <CT30_P30>;
drive-open-drain;
drive-strength = "0.5";
};
};
};
5 changes: 5 additions & 0 deletions boards/ambiq/apollo4p_evb/apollo4p_evb.dts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
rtc = &rtc0;
sdhc0 = &sdio0;
pwm-led0 = &pwm_led0;
crc0 = &crc32;
};

leds {
Expand Down Expand Up @@ -187,6 +188,10 @@
};
};

&crc32 {
status = "okay";
};

zephyr_udc0: &usb {
vddusb33-gpios = <&gpio96_127 7 (GPIO_PULL_UP)>;
vddusb0p9-gpios = <&gpio96_127 5 (GPIO_PULL_UP)>;
Expand Down
5 changes: 5 additions & 0 deletions boards/ambiq/apollo510_eb/apollo510_eb.dts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
sdhc0 = &sdio0;
sdhc1 = &sdio1;
eeprom-0 = &i2c_eeprom;
crc0 = &crc32;
};

sram0: memory@SSRAM_BASE_NAME {
Expand Down Expand Up @@ -354,3 +355,7 @@ zephyr_udc0: &usb {
};
};
};

&crc32 {
status = "okay";
};
5 changes: 5 additions & 0 deletions boards/ambiq/apollo510_evb/apollo510_evb.dts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
sw0 = &button0;
sw1 = &button1;
pwm-led0 = &pwm_led0;
crc0 = &crc32;
};

sram0: memory@SSRAM_BASE_NAME {
Expand Down Expand Up @@ -341,3 +342,7 @@ zephyr_udc0: &usb {
};
};
};

&crc32 {
status = "okay";
};
1 change: 1 addition & 0 deletions drivers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ add_subdirectory_ifdef(CONFIG_COMPARATOR comparator)
add_subdirectory_ifdef(CONFIG_CONSOLE console)
add_subdirectory_ifdef(CONFIG_COREDUMP_DEVICE coredump)
add_subdirectory_ifdef(CONFIG_COUNTER counter)
add_subdirectory_ifdef(CONFIG_CRC crc)
add_subdirectory_ifdef(CONFIG_CRYPTO crypto)
add_subdirectory_ifdef(CONFIG_DAC dac)
add_subdirectory_ifdef(CONFIG_DAI dai)
Expand Down
1 change: 1 addition & 0 deletions drivers/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ source "drivers/comparator/Kconfig"
source "drivers/console/Kconfig"
source "drivers/coredump/Kconfig"
source "drivers/counter/Kconfig"
source "drivers/crc/Kconfig"
source "drivers/crypto/Kconfig"
source "drivers/dac/Kconfig"
source "drivers/dai/Kconfig"
Expand Down
4 changes: 4 additions & 0 deletions drivers/crc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# SPDX-License-Identifier: Apache-2.0

zephyr_library()
zephyr_library_sources_ifdef(CONFIG_CRC_AMBIQ crc_ambiq.c)
26 changes: 26 additions & 0 deletions drivers/crc/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# CRC configuration options

# Copyright (c) 2025, Ambiq
# SPDX-License-Identifier: Apache-2.0

menuconfig CRC
bool "CRC drivers"
help
Enable CRC (Cyclic Redundancy Check) driver support.

if CRC

# Ensure Ambiq-specific CRC Kconfig is included
source "drivers/crc/Kconfig.ambiq"

config CRC_INIT_PRIORITY
int "CRC devices init priority"
default 90
help
CRC devices initialization priority.

module = CRC
module-str = CRC
source "subsys/logging/Kconfig.template.log_config"

endif # CRC
11 changes: 11 additions & 0 deletions drivers/crc/Kconfig.ambiq
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Ambiq CRC configuration options

# Copyright (c) 2025 Ambiq
# SPDX-License-Identifier: Apache-2.0

config CRC_AMBIQ
bool "Ambiq Apollo4P and Apollo510 CRC support"
default y
depends on SOC_SERIES_APOLLO4X || SOC_SERIES_APOLLO5X
help
Enable Ambiq Apollo4P and Apollo510 CRC support.
58 changes: 58 additions & 0 deletions drivers/crc/crc_ambiq.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright (c) 2025 Ambiq Micro, Inc.
*
* SPDX-License-Identifier: Apache-2.0
*/

#define DT_DRV_COMPAT ambiq_hw_crc32

#include <string.h>
#include "soc.h"
#include <zephyr/logging/log.h>
#include <zephyr/device.h>
#include <zephyr/drivers/crc/crc.h>

LOG_MODULE_REGISTER(ambiq_hw_crc32, CONFIG_KERNEL_LOG_LEVEL);

static int crc_ambiq_get_crc32(const struct device *dev, const void *startAddr, uint32_t sizeBytes,
uint32_t *pCrc)
{
ARG_UNUSED(dev);

/*
* Validate input parameters
*/
if (sizeBytes == 0 || startAddr == NULL || pCrc == NULL) {
return -EINVAL;
}

/*
* If the CRC is already running then return an error
*/
if (SECURITY->CTRL_b.ENABLE) {
return -EBUSY;
}

/*
* Generate the CRC
*/
am_hal_crc32((uint32_t)startAddr, sizeBytes, pCrc);

return 0;
}

static int crc_ambiq_init(const struct device *dev)
{
ARG_UNUSED(dev);

/* Any hardware init can be performed here if needed. */
return 0;
}

static const struct crc_driver_api crc_ambiq_api_funcs = {
.get_crc = crc_ambiq_get_crc32,
};

DEVICE_DT_INST_DEFINE(0, crc_ambiq_init, NULL, NULL, NULL, POST_KERNEL,
CONFIG_KERNEL_INIT_PRIORITY_DEFAULT,
Copy link

Copilot AI Sep 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The device definition uses hardcoded instance 0 and CONFIG_KERNEL_INIT_PRIORITY_DEFAULT. Consider using CONFIG_CRC_INIT_PRIORITY defined in drivers/crc/Kconfig for consistency with other driver subsystems.

Suggested change
CONFIG_KERNEL_INIT_PRIORITY_DEFAULT,
CONFIG_CRC_INIT_PRIORITY,

Copilot uses AI. Check for mistakes.
&crc_ambiq_api_funcs);
6 changes: 6 additions & 0 deletions dts/arm/ambiq/ambiq_apollo4p.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@
};
};

crc32: crc32@40030030 {
compatible = "ambiq,hw-crc32";
reg = <0x40030030 0x4>;
status = "disabled";
};

stimer0: stimer@40008800 {
compatible = "ambiq,stimer";
reg = <0x40008800 0x80>;
Expand Down
6 changes: 6 additions & 0 deletions dts/arm/ambiq/ambiq_apollo4p_blue.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,12 @@
status = "disabled";
};

crc32: crc32@40030030 {
compatible = "ambiq,hw-crc32";
reg = <0x40030030 0x4>;
status = "disabled";
};

};
};

Expand Down
6 changes: 6 additions & 0 deletions dts/arm/ambiq/ambiq_apollo510.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,12 @@
status = "disabled";
};

crc32: crc32@40030030 {
compatible = "ambiq,hw-crc32";
reg = <0x40030030 0x4>;
status = "disabled";
};

stimer0: stimer@STIMER_BASE_NAME {
compatible = "ambiq,stimer";
reg = <STIMER_REG_BASE STIMER_REG_SIZE>;
Expand Down
1 change: 1 addition & 0 deletions dts/bindings/binding-types.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ comparator Comparator
coredump Core dump
counter Counter
cpu CPU (Central Processing Unit)
crc Cyclic Redundancy Check
crypto Cryptographic accelerator
dac DAC (Digital to Analog Converter)
dai DAI (Digital Audio Interface)
Expand Down
16 changes: 16 additions & 0 deletions dts/bindings/crc/ambiq,hw-crc32.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright (c) 2025, Ambiq
# Author, Richard S Wheatley
# SPDX-License-Identifier: Apache-2.0

description: |
Hardware CRC32 Cyclic Redundancy Check Module.

This module implements a hardware-based CRC32 calculation.

compatible: "ambiq,hw-crc32"

include: base.yaml

properties:
reg:
required: true
53 changes: 53 additions & 0 deletions include/zephyr/drivers/crc/crc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright (c) 2025, Ambiq Micro Inc. <www.ambiq.com>
*
* SPDX-License-Identifier: Apache-2.0
*/

#ifndef ZEPHYR_INCLUDE_DRIVERS_CRC_H_
#define ZEPHYR_INCLUDE_DRIVERS_CRC_H_

#include <zephyr/device.h>
#include <stdint.h>
#include <errno.h>

#ifdef __cplusplus
extern "C" {
#endif

/* Driver callback: compute CRC32 over a memory region */
typedef int (*crc_get_fn)(const struct device *dev,
const void *start_addr,
uint32_t size_bytes,
uint32_t *out_crc);

/* Public driver API struct */
struct crc_driver_api {
crc_get_fn get_crc;
};

/* Convenience inline wrapper that calls the device API */
static inline int crc_driver_get_crc(const struct device *dev,
const void *start_addr,
uint32_t size_bytes,
uint32_t *out_crc)
{
const struct crc_driver_api *api;

if (dev == NULL) {
return -EINVAL;
}

api = (const struct crc_driver_api *)dev->api;
if (!api || !api->get_crc) {
return -ENOSYS;
}

return api->get_crc(dev, start_addr, size_bytes, out_crc);
}

#ifdef __cplusplus
}
#endif

#endif /* ZEPHYR_INCLUDE_DRIVERS_CRC_H_ */
7 changes: 7 additions & 0 deletions samples/drivers/crc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.20.0)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(crc)

target_sources(app PRIVATE src/main.c)
46 changes: 46 additions & 0 deletions samples/drivers/crc/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
.. _crc-sample:

CRC Sample
##########

Overview
********

This sample demonstrates how to use the CRC (Cyclic Redundancy Check) driver API.
The sample calculates CRC32 checksums over test data and displays the results.

Building and Running
********************

This sample can be found under :zephyr_file:`samples/drivers/crc` in the Zephyr tree.

The sample will work on any board that has a CRC driver enabled and configured.
For Ambiq Apollo4P and Apollo510 boards, the sample uses the hardware CRC32 module.

Supported boards:
- apollo4p_evb
- apollo4p_blue_kxr_evb
- apollo510_evb
- apollo510_eb

.. zephyr-app-commands::
:zephyr-app: samples/drivers/crc
:board: apollo4p_evb
:goals: build flash
:compact:

Sample Output
=============

.. code-block:: console
*** Booting Zephyr OS build v3.x.x ***
[00:00:00.000,000] <inf> crc_sample: CRC Sample starting...
[00:00:00.000,000] <inf> crc_sample: Testing CRC device: crc32@40030030
[00:00:00.001,000] <inf> crc_sample: CRC32 of 256 bytes: 0x12345678
[00:00:00.002,000] <inf> crc_sample: CRC test completed successfully
References
**********

- :ref:`crc_api`
3 changes: 3 additions & 0 deletions samples/drivers/crc/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CONFIG_CRC=y
CONFIG_CRC_AMBIQ=y
CONFIG_LOG=y
20 changes: 20 additions & 0 deletions samples/drivers/crc/sample.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
sample:
name: CRC Sample
description: Sample application demonstrating CRC driver usage
common:
tags: crc drivers
platform_allow:
- apollo4p_evb
- apollo4p_blue_kxr_evb
- apollo510_evb
- apollo510_eb
integration_platforms:
- apollo4p_evb
tests:
sample.drivers.crc:
tags: crc drivers
platform_allow:
- apollo4p_evb
- apollo4p_blue_kxr_evb
- apollo510_evb
- apollo510_eb
Loading
Loading