samples: pmci: mctp: Add i2c+gpio endpoint sample
Adds sample showing i2c+gpio endpoint bindings in use. Provides an overlay for the frdm-mcxn947 development board using JP8 pins for i2c and gpio connectivity. The sample periodically sends a "ping" message to the bus controller and prints out any messages it receives itself. Signed-off-by: Tom Burdick <thomas.burdick@intel.com>
This commit is contained in:
parent
84583ee6c6
commit
7d9fffaeb9
@ -0,0 +1,6 @@
|
||||
cmake_minimum_required(VERSION 3.20.0)
|
||||
|
||||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
|
||||
project(mctp_i2c_gpio_bus_endpoint)
|
||||
|
||||
target_sources(app PRIVATE src/main.c)
|
||||
32
samples/modules/pmci/mctp/i2c_gpio_bus_endpoint/README.rst
Normal file
32
samples/modules/pmci/mctp/i2c_gpio_bus_endpoint/README.rst
Normal file
@ -0,0 +1,32 @@
|
||||
.. zephyr:code-sample:: mctp_i2c_bus_endpoint
|
||||
:name: MCTP I2C GPIO Endpoint Node Sample
|
||||
|
||||
Create an MCTP endpoint node controlling I2C with GPIO signaling.
|
||||
|
||||
Overview
|
||||
********
|
||||
Sets up an MCTP endpoint node that may talk to a top node and peer to other MCTP endpoints.
|
||||
|
||||
Requirements
|
||||
************
|
||||
Board with an I2C and a GPIO used for signaling the top node to read the target device.
|
||||
|
||||
Wiring
|
||||
******
|
||||
A common I2C bus SDA/SCL pair connected to any number of boards (setup in devicetree)
|
||||
along with a GPIO for signaling endpoint write requests.
|
||||
|
||||
Building and Running
|
||||
********************
|
||||
|
||||
.. zephyr-app-commands::
|
||||
:zephyr-app: samples/modules/pmci/mctp/i2c_gpio_bus_endpoint
|
||||
:host-os: unix
|
||||
:board: frdm_mcxn947_mcxn947_cpu0
|
||||
:goals: run
|
||||
:compact:
|
||||
|
||||
References
|
||||
**********
|
||||
|
||||
`MCTP Base Specification 2019 <https://www.dmtf.org/sites/default/files/standards/documents/DSP0236_1.3.1.pdf>`_
|
||||
@ -0,0 +1,36 @@
|
||||
#include <zephyr/dt-bindings/gpio/gpio.h>
|
||||
|
||||
/* Sets up I2C and a GPIO on JP8 to use as our i2c bus for MCTP */
|
||||
|
||||
|
||||
&nxp_lcd_8080_connector {
|
||||
status = "disabled";
|
||||
};
|
||||
|
||||
&flexio0 {
|
||||
status = "disabled";
|
||||
};
|
||||
|
||||
&gpio0 {
|
||||
status = "okay";
|
||||
};
|
||||
|
||||
&flexcomm2 {
|
||||
status = "okay";
|
||||
};
|
||||
|
||||
&flexcomm2_lpi2c2 {
|
||||
status = "okay";
|
||||
clock-frequency = <I2C_BITRATE_STANDARD>;
|
||||
};
|
||||
|
||||
|
||||
/ {
|
||||
mctp_i2c: mctp_i2c {
|
||||
compatible = "zephyr,mctp-i2c-gpio-target";
|
||||
i2c = <&flexcomm2_lpi2c2>;
|
||||
i2c-addr = <70>;
|
||||
endpoint-id = <11>;
|
||||
endpoint-gpios = <&gpio0 7 GPIO_ACTIVE_HIGH>;
|
||||
};
|
||||
};
|
||||
8
samples/modules/pmci/mctp/i2c_gpio_bus_endpoint/prj.conf
Normal file
8
samples/modules/pmci/mctp/i2c_gpio_bus_endpoint/prj.conf
Normal file
@ -0,0 +1,8 @@
|
||||
CONFIG_I2C=y
|
||||
CONFIG_I2C_TARGET=y
|
||||
CONFIG_MCTP=y
|
||||
CONFIG_MCTP_I2C_GPIO_TARGET=y
|
||||
CONFIG_MCTP_LOG_LEVEL_DBG=y
|
||||
CONFIG_LOG=y
|
||||
#CONFIG_LOG_MODE_IMMEDIATE=y
|
||||
CONFIG_LOG_BUFFER_SIZE=4096
|
||||
56
samples/modules/pmci/mctp/i2c_gpio_bus_endpoint/src/main.c
Normal file
56
samples/modules/pmci/mctp/i2c_gpio_bus_endpoint/src/main.c
Normal file
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (c) 2025 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
#include <unistd.h>
|
||||
#include <zephyr/types.h>
|
||||
#include <zephyr/kernel.h>
|
||||
#include <libmctp.h>
|
||||
#include <zephyr/pmci/mctp/mctp_i2c_gpio_target.h>
|
||||
|
||||
#include <zephyr/logging/log.h>
|
||||
LOG_MODULE_REGISTER(mctp_i2c_gpio_bus_endpoint);
|
||||
|
||||
MCTP_I2C_GPIO_TARGET_DT_DEFINE(mctp_i2c_ctrl, DT_NODELABEL(mctp_i2c));
|
||||
|
||||
static void rx_message(uint8_t eid, bool tag_owner, uint8_t msg_tag, void *data, void *msg,
|
||||
size_t len)
|
||||
{
|
||||
LOG_INF("received message \"%s\" from endpoint %d, msg_tag %d, len %zu", (char *)msg, eid,
|
||||
msg_tag, len);
|
||||
}
|
||||
|
||||
#define BUS_OWNER_ID 20
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int rc;
|
||||
struct mctp *mctp_ctx;
|
||||
|
||||
LOG_INF("MCTP Host EID:%d on %s\n", mctp_i2c_ctrl.endpoint_id, CONFIG_BOARD_TARGET);
|
||||
|
||||
mctp_ctx = mctp_init();
|
||||
__ASSERT_NO_MSG(mctp_ctx != NULL);
|
||||
mctp_register_bus(mctp_ctx, &mctp_i2c_ctrl.binding, mctp_i2c_ctrl.endpoint_id);
|
||||
mctp_set_rx_all(mctp_ctx, rx_message, NULL);
|
||||
|
||||
/*
|
||||
* 1. MCTP poll loop, send "ping" to each endpoint and get "pong" back
|
||||
* 2. Then send a broadcast "hello" to each endpoint and get a "from endoint %d" back
|
||||
*/
|
||||
while (true) {
|
||||
rc = mctp_message_tx(mctp_ctx, BUS_OWNER_ID, false,
|
||||
0, "ping", sizeof("ping"));
|
||||
if (rc != 0) {
|
||||
LOG_WRN("Failed to send message \"ping\", errno %d\n", rc);
|
||||
}
|
||||
k_msleep(500);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user