Skip to content

Commit 1e980ec

Browse files
Duy Vothenguyenyf
authored andcommitted
samples: subsys: crc: add samples for CRC subsystem
Add samples for CRC subsystem Signed-off-by: Duy Vo <duy.vo.xc@bp.renesas.com>
1 parent 8e64ac5 commit 1e980ec

File tree

5 files changed

+107
-0
lines changed

5 files changed

+107
-0
lines changed

samples/subsys/crc/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
cmake_minimum_required(VERSION 3.20.0)
4+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
5+
project(subsys_crc_example)
6+
7+
target_sources(app PRIVATE src/main.c)

samples/subsys/crc/README.rst

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
.. zephyr:code-sample:: crc_subsys
2+
:name: Cyclic Redundancy Check Subsystem (CRC Subsys)
3+
4+
Compute and verify a CRC computation using the CRC subsys API.
5+
6+
Overview
7+
********
8+
9+
This sample demonstrates how to use the Cyclic Redundancy Check Subsystem
10+
11+
Configuration Options
12+
*********************
13+
14+
This sample supports the following Kconfig options:
15+
16+
- ``CONFIG_CRC``: Enable CRC functionality.
17+
- ``CONFIG_CRC*``: Use software-based CRC if a chosen node is present; otherwise, hardware acceleration is used.
18+
19+
These options can be modified in the project's ``prj.conf`` file or passed via CMake arguments.
20+
21+
Building and Running
22+
********************
23+
24+
Building and Running for Renesas RA8M1
25+
======================================
26+
27+
The sample can be built and executed for the
28+
:zephyr:board:`ek_ra8m1` as follows:
29+
30+
.. zephyr-app-commands::
31+
:zephyr-app: samples/subsys/crc
32+
:board: ek_ra8m1
33+
:goals: build flash
34+
:compact:
35+
36+
To build for another board, change "ek_ra8m1" above to that board's name.
37+
38+
Sample Output
39+
=============
40+
41+
.. code-block:: console
42+
43+
subsys_crc_example: Result of CRC32 IEEE: 0xCEA4A6C2
44+
subsys_crc_example: Result of CRC8 CCITT: 0x96
45+
subsys_crc_example: CRC computation completed successfully
46+
47+
.. note::
48+
If the board does not support a hardware CRC driver, the computation will fall
49+
back to a software-based implementation.
50+
51+
Expected Behavior
52+
*****************
53+
54+
When the sample runs, it should:
55+
56+
1. Compute the CRC32 and CRC8 values of predefined data.
57+
2. Print the computed CRC values.

samples/subsys/crc/prj.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CONFIG_CRC=y
2+
CONFIG_LOG=y

samples/subsys/crc/sample.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
sample:
2+
name: CRC Subsystem
3+
tests:
4+
samples.subsys.crc:
5+
depends_on: crc
6+
tags:
7+
- subsys
8+
- crc
9+
harness: console
10+
harness_config:
11+
type: one_line
12+
regex:
13+
- "CRC computation completed successfully"

samples/subsys/crc/src/main.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright (c) 2025 Renesas Electronics Corporation
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/logging/log.h>
8+
LOG_MODULE_REGISTER(subsys_crc_example, CONFIG_LOG_DEFAULT_LEVEL);
9+
10+
#include <zephyr/sys/crc.h>
11+
12+
int main(void)
13+
{
14+
uint32_t result;
15+
uint8_t data[8] = {0x0A, 0x2B, 0x4C, 0x6D, 0x8E, 0x49, 0x00, 0xC4};
16+
17+
/* CRC computation */
18+
result = crc32_ieee(data, sizeof(data));
19+
LOG_INF("Result of CRC32 IEEE: 0x%08X", result);
20+
21+
/* CRC computation */
22+
result = (uint8_t)crc8_ccitt(0xFF, data, sizeof(data));
23+
LOG_INF("Result of CRC8 CCITT: 0x%02X", result & 0xFF);
24+
25+
LOG_INF("CRC computation completed successfully");
26+
27+
return 0;
28+
}

0 commit comments

Comments
 (0)