Commit e5dbc1d1 authored by Duy Vo's avatar Duy Vo Committed by Benjamin Cabé
Browse files

samples: subsys: crc: add samples for CRC subsystem



Add samples for CRC subsystem

Signed-off-by: default avatarDuy Vo <duy.vo.xc@bp.renesas.com>
parent 121aeab9
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
# SPDX-License-Identifier: Apache-2.0

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

target_sources(app PRIVATE src/main.c)
+57 −0
Original line number Diff line number Diff line
.. zephyr:code-sample:: crc_subsys
   :name: Cyclic Redundancy Check Subsystem (CRC Subsys)

   Compute and verify a CRC computation using the CRC subsys API.

Overview
********

This sample demonstrates how to use the Cyclic Redundancy Check Subsystem

Configuration Options
*********************

This sample uses the following Kconfig options:

- ``CONFIG_CRC``: Enable CRC functionality.
- ``CONFIG_CRC*``: Use software-based CRC if a chosen node is present; otherwise, hardware acceleration is used.

These options can be modified in the project's ``prj.conf`` file or passed via CMake arguments.

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

Building and Running for Renesas RA8M1
======================================

The sample can be built and executed for the
:zephyr:board:`ek_ra8m1` as follows:

.. zephyr-app-commands::
   :zephyr-app: samples/subsys/crc
   :board: ek_ra8m1
   :goals: build flash
   :compact:

To build for another board, change "ek_ra8m1" above to that board's name.

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

.. code-block:: console

   subsys_crc_example: Result of CRC32 IEEE: 0xCEA4A6C2
   subsys_crc_example: Result of CRC8 CCITT: 0x96
   subsys_crc_example: CRC computation completed successfully

.. note::
   If the board does not support a hardware CRC driver, the computation will fall
   back to a software-based implementation.

Expected Behavior
*****************

When the sample runs, it should:

1. Compute the CRC32 and CRC8 values of predefined data.
2. Print the computed CRC values.
+2 −0
Original line number Diff line number Diff line
CONFIG_CRC=y
CONFIG_LOG=y
+13 −0
Original line number Diff line number Diff line
sample:
  name: CRC Subsystem
tests:
  samples.subsys.crc:
    depends_on: crc
    tags:
      - subsys
      - crc
    harness: console
    harness_config:
      type: one_line
      regex:
        - "CRC computation completed successfully"
+28 −0
Original line number Diff line number Diff line
/*
 * Copyright (c) 2025 Renesas Electronics Corporation
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(subsys_crc_example, CONFIG_LOG_DEFAULT_LEVEL);

#include <zephyr/sys/crc.h>

int main(void)
{
	uint32_t result;
	uint8_t data[8] = {0x0A, 0x2B, 0x4C, 0x6D, 0x8E, 0x49, 0x00, 0xC4};

	/* CRC computation */
	result = crc32_ieee(data, sizeof(data));
	LOG_INF("Result of CRC32 IEEE: 0x%08X", result);

	/* CRC computation */
	result = (uint8_t)crc8_ccitt(0xFF, data, sizeof(data));
	LOG_INF("Result of CRC8 CCITT: 0x%02X", result & 0xFF);

	LOG_INF("CRC computation completed successfully");

	return 0;
}