Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] zephyr: virtio i2c ram example #20

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
22 changes: 22 additions & 0 deletions examples/zephyr/virtio_i2c_ram/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
cmake_minimum_required(VERSION 3.13.1)
# Copyright (c) 2023 STMicroelectronics
#
# SPDX-License-Identifier: Apache-2.0
#

include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)

project(virtio_i2c_ram)

zephyr_compile_definitions(
-DMETAL_MAX_DEVICE_REGIONS=2
-DVIRTIO_SLAVE_ONLY
)

target_include_directories(app PRIVATE $ENV{ZEPHYR_BASE}/drivers)
target_include_directories(app PRIVATE ${LIBMETAL_INCLUDE_DIR} ${OPENAMP_INCLUDE_DIR} ${PLATFORM_DIR})

target_sources(app PRIVATE src/main_remote.c)
target_sources(app PRIVATE src/mmio_table.c)

target_include_directories(app PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/..)
89 changes: 89 additions & 0 deletions examples/zephyr/virtio_i2c_ram/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
.. _openAMP_sample:

OpenAMP Sample Application
##########################

Overview
********

This application demonstrates how to use of virtio mmio to share an I2C bus between
Zephyr and a remote processor. It is designed to implement an memory device
connected on an I2C virtio bus.

Currently this implementation don't use the OpenAMP virtio as not ready.

requested Hardware
*************************

- compatible with:
- STM32MP115c-dk2 board

Zephyr
======

.. code-block:: console

west build -b <target board> openamp-system-reference/examples/zephyr/virtio_i2c_ram

Copy the binary file on the SDCard

Linux console
=============

Open a serial Linux terminal (minicom, putty, etc.) and connect the board with the
following settings:

- Speed: 115200
- Data: 8 bits
- Parity: odd
- Stop bits: 1

Load and start the firmware:

.. code-block:: console

echo -n <firmware_name.elf> > /sys/class/remoteproc/remoteproc0/firmware
echo start >/sys/class/remoteproc/remoteproc0/state


This is the Linux console:

1. Verify that the virtio I2C bus is preent

.. code-block:: console

root@stm32mp1-disco-oss:~# i2cdetect -l
i2c-0 i2c STM32F7 I2C(0x40012000) I2C adapter
i2c-1 i2c STM32F7 I2C(0x5c002000) I2C adapter
i2c-2 i2c i2c-0-mux (chan_id 0) I2C adapter
i2c-3 i2c i2c_virtio at virtio bus 0 I2C adapter

2. list devices on the virtio bus

Two memory devices should be connected:
- one 20 bytes memory at address 0x54 initialized with "123456789abcdefghij"
- one 20 bytes memory at address 0x56 initialized with "klmnopqrstuvwxyz!:;"
Verify that the virtio I2C bus is present

.. code-block:: console

root@stm32mp1-disco-oss:~# i2cdetect -y 3
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- 54 -- 56 -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

3. Update RAM device 0x54 at address 0x14 with value 4

.. code-block:: console

root@stm32mp1-disco-oss:~# i2cget -y 3 0x54 14
0x66
root@stm32mp1-disco-oss:~# i2cset -y 3 0x54 14 0x25
root@stm32mp1-disco-oss:~# i2cget -y 3 0x54 14
0x25
24 changes: 24 additions & 0 deletions examples/zephyr/virtio_i2c_ram/boards/stm32mp157c_dk2.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright (c) 2023, STMICROLECTRONICS
*
* SPDX-License-Identifier: Apache-2.0
*/

/ {
chosen {
/*
* shared memory reserved for the inter-processor communication
*/
zephyr,ipc_shm = &mcusram3;
zephyr,ipc = &mailbox;
};

mcusram3: memory1@10050000 {
compatible = "mmio-sram";
reg = <0x10050000 DT_SIZE_K(64)>;
};
};

&mcusram {
reg = <0x10000000 DT_SIZE_K(256)>;
};
9 changes: 9 additions & 0 deletions examples/zephyr/virtio_i2c_ram/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CONFIG_KERNEL_BIN_NAME="zephyr_virtio_i2c_eeprom"
CONFIG_PRINTK=n
CONFIG_IPM=y
CONFIG_PLATFORM_SPECIFIC_INIT=n
CONFIG_MAIN_STACK_SIZE=4096
CONFIG_HEAP_MEM_POOL_SIZE=16384
CONFIG_OPENAMP=y
CONFIG_OPENAMP_MASTER=n
CONFIG_OPENAMP_RSC_TABLE=y
Loading