mirror of
https://github.com/espressif/esp-modbus.git
synced 2025-07-30 10:27:16 +02:00
esp-modbus: update esp-idf component structure
This commit is contained in:
49
.gitignore
vendored
Normal file
49
.gitignore
vendored
Normal file
@ -0,0 +1,49 @@
|
||||
.config
|
||||
*.o
|
||||
*.pyc
|
||||
|
||||
# gtags
|
||||
GTAGS
|
||||
GRTAGS
|
||||
GPATH
|
||||
|
||||
# emacs
|
||||
.dir-locals.el
|
||||
|
||||
# emacs temp file suffixes
|
||||
*~
|
||||
.#*
|
||||
\#*#
|
||||
|
||||
# eclipse setting
|
||||
.settings
|
||||
|
||||
# MacOS directory files
|
||||
.DS_Store
|
||||
|
||||
# Test files
|
||||
test/build
|
||||
test/sdkconfig
|
||||
test/sdkconfig.old
|
||||
|
||||
# Doc build artifacts
|
||||
docs/_build/
|
||||
docs/doxygen-warning-log.txt
|
||||
docs/sphinx-warning-log.txt
|
||||
docs/sphinx-warning-log-sanitized.txt
|
||||
docs/xml/
|
||||
docs/xml_in/
|
||||
docs/man/
|
||||
docs/doxygen_sqlite3.db
|
||||
|
||||
TEST_LOGS
|
||||
|
||||
|
||||
# gcov coverage reports
|
||||
*.gcda
|
||||
*.gcno
|
||||
coverage.info
|
||||
coverage_report/
|
||||
|
||||
# VS Code Settings
|
||||
.vscode/
|
121
.gitlab-ci.yml
Normal file
121
.gitlab-ci.yml
Normal file
@ -0,0 +1,121 @@
|
||||
stages:
|
||||
- build
|
||||
- deploy
|
||||
|
||||
variables:
|
||||
# System environment
|
||||
ESP_DOCS_ENV_IMAGE: "$CI_DOCKER_REGISTRY/esp-idf-doc-env-v5.0:2-2"
|
||||
ESP_DOCS_PATH: "$CI_PROJECT_DIR"
|
||||
|
||||
# GitLab-CI environment
|
||||
GET_SOURCES_ATTEMPTS: "10"
|
||||
ARTIFACT_DOWNLOAD_ATTEMPTS: "10"
|
||||
GIT_SUBMODULE_STRATEGY: none
|
||||
|
||||
ESP_IDF_GIT: "https://gitlab-ci-token:${CI_JOB_TOKEN}@${GITLAB_HTTPS_SERVER}/espressif/esp-idf.git"
|
||||
|
||||
.setup_idf_tools: &setup_idf_tools |
|
||||
tools/idf_tools.py --non-interactive install && eval "$(tools/idf_tools.py --non-interactive export)" || exit 1
|
||||
|
||||
.add_gh_key_remote: &add_gh_key_remote |
|
||||
command -v ssh-agent >/dev/null || exit 1
|
||||
eval $(ssh-agent -s)
|
||||
printf '%s\n' "${GH_PUSH_KEY}" | tr -d '\r' | ssh-add - > /dev/null
|
||||
mkdir -p ~/.ssh && chmod 700 ~/.ssh
|
||||
[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config || ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts
|
||||
git remote remove github || true
|
||||
git remote add github ${GH_PUSH_REPO}
|
||||
|
||||
after_script:
|
||||
# Just for cleaning space, no other causes
|
||||
- git clean -ffdx
|
||||
|
||||
|
||||
# This template gets expanded multiple times, once for every IDF version.
|
||||
# IDF version is specified by setting the espressif/idf image tag.
|
||||
#
|
||||
# EXAMPLE_TARGETS sets the list of IDF_TARGET values to build examples for.
|
||||
# It should be equal to the list of targets supported by the specific IDF version.
|
||||
#
|
||||
# TEST_TARGETS sets the list of IDF_TARGET values to build the test_app for.
|
||||
# It should contain only the targets with optimized assembly implementations.
|
||||
#
|
||||
.build_template:
|
||||
stage: build
|
||||
tags:
|
||||
- build
|
||||
- internet
|
||||
script:
|
||||
- ./build_all.sh
|
||||
variables:
|
||||
EXAMPLE_TARGETS: "esp32"
|
||||
TEST_TARGETS: "esp32"
|
||||
|
||||
build_idf_v4.1:
|
||||
extends: .build_template
|
||||
image: espressif/idf:release-v4.1
|
||||
|
||||
build_idf_v4.2:
|
||||
extends: .build_template
|
||||
image: espressif/idf:release-v4.2
|
||||
variables:
|
||||
EXAMPLE_TARGETS: "esp32 esp32s2"
|
||||
|
||||
build_idf_v4.3:
|
||||
extends: .build_template
|
||||
image: espressif/idf:release-v4.3
|
||||
variables:
|
||||
EXAMPLE_TARGETS: "esp32 esp32s2 esp32c3"
|
||||
|
||||
build_idf_v4.4:
|
||||
extends: .build_template
|
||||
image: espressif/idf:release-v4.4
|
||||
variables:
|
||||
EXAMPLE_TARGETS: "esp32 esp32s2 esp32s3 esp32c3"
|
||||
TEST_TARGETS: "esp32 esp32s3"
|
||||
|
||||
build_idf_latest:
|
||||
extends: .build_template
|
||||
image: espressif/idf:latest
|
||||
variables:
|
||||
EXAMPLE_TARGETS: "esp32 esp32s2 esp32s3 esp32c3"
|
||||
TEST_TARGETS: "esp32 esp32s3"
|
||||
|
||||
push_master_to_github:
|
||||
stage: deploy
|
||||
tags:
|
||||
- deploy
|
||||
only:
|
||||
- master
|
||||
- /^release\/v/
|
||||
- /^v\d+\.\d+(\.\d+)?($|-)/
|
||||
when: on_success
|
||||
script:
|
||||
- git clone --depth 1 ${ESP_IDF_GIT} esp-idf
|
||||
- *add_gh_key_remote
|
||||
- esp-idf/tools/ci/push_to_github.sh
|
||||
|
||||
upload_to_component_manager:
|
||||
stage: deploy
|
||||
tags:
|
||||
- deploy
|
||||
only:
|
||||
- master
|
||||
- /^release\/v/
|
||||
- /^v\d+\.\d+(\.\d+)?($|-)/
|
||||
when: on_success
|
||||
script:
|
||||
- git clone --depth 1 ${ESP_IDF_GIT} esp-idf
|
||||
- export IDF_PATH=$PWD/esp-idf
|
||||
- cd esp-idf
|
||||
- ./tools/idf_tools.py --non-interactive install-python-env
|
||||
- ./tools/idf_tools.py --non-interactive install
|
||||
- idf_exports=$(${IDF_PATH}/tools/idf_tools.py --non-interactive export)
|
||||
- eval "${idf_exports}"
|
||||
- cd ..
|
||||
- git clone $PWD esp-modbus
|
||||
- cd esp-modbus
|
||||
- pip install --upgrade idf-component-manager
|
||||
- idf.py --help
|
||||
- export IDF_COMPONENT_API_TOKEN=${ESP_MODBUS_API_KEY}
|
||||
- idf.py upload-component --name=esp-modbus --namespace=espressif || true
|
@ -1,3 +1,5 @@
|
||||
# The following five lines of boilerplate have to be in your project's
|
||||
# CMakeLists in this exact order for cmake to work correctly
|
||||
set(srcs
|
||||
"common/esp_modbus_master.c"
|
||||
"common/esp_modbus_slave.c"
|
||||
@ -44,14 +46,20 @@ set(srcs
|
||||
set(include_dirs common/include)
|
||||
|
||||
set(priv_include_dirs common port modbus modbus/ascii modbus/functions
|
||||
modbus/rtu modbus/tcp modbus/include)
|
||||
modbus/rtu modbus/tcp modbus/include)
|
||||
|
||||
list(APPEND priv_include_dirs serial_slave/port serial_slave/modbus_controller
|
||||
serial_master/port serial_master/modbus_controller
|
||||
tcp_slave/port tcp_slave/modbus_controller
|
||||
tcp_master/port tcp_master/modbus_controller)
|
||||
serial_master/port serial_master/modbus_controller
|
||||
tcp_slave/port tcp_slave/modbus_controller
|
||||
tcp_master/port tcp_master/modbus_controller)
|
||||
|
||||
add_prefix(srcs "${CMAKE_CURRENT_LIST_DIR}/freemodbus/" ${srcs})
|
||||
add_prefix(include_dirs "${CMAKE_CURRENT_LIST_DIR}/freemodbus/" ${include_dirs})
|
||||
add_prefix(priv_include_dirs "${CMAKE_CURRENT_LIST_DIR}/freemodbus/" ${priv_include_dirs})
|
||||
|
||||
message(STATUS "DEBUG: Use esp-modbus component folder: ${CMAKE_CURRENT_LIST_DIR}.")
|
||||
|
||||
idf_component_register(SRCS "${srcs}"
|
||||
INCLUDE_DIRS "${include_dirs}"
|
||||
PRIV_INCLUDE_DIRS "${priv_include_dirs}"
|
||||
REQUIRES driver)
|
||||
REQUIRES driver lwip)
|
||||
|
72
build_all.sh
Executable file
72
build_all.sh
Executable file
@ -0,0 +1,72 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Build the test app and all examples from the examples directory.
|
||||
# Expects TEST_TARGETS environment variables to be set.
|
||||
# Each variable is the list of IDF_TARGET values to build the examples and
|
||||
# the test app for, respectively.
|
||||
#
|
||||
# -----------------------------------------------------------------------------
|
||||
# Safety settings (see https://gist.github.com/ilg-ul/383869cbb01f61a51c4d).
|
||||
|
||||
if [[ -n "${DEBUG_SHELL}" ]]
|
||||
then
|
||||
set -x # Activate the expand mode if DEBUG is anything but empty.
|
||||
fi
|
||||
|
||||
if [[ -z "${TEST_TARGETS}" ]]
|
||||
then
|
||||
echo "TEST_TARGETS environment variable must be set before calling this script"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
set -o errexit # Exit if command failed.
|
||||
set -o pipefail # Exit if pipe failed.
|
||||
set -o nounset # Exit if variable not set.
|
||||
|
||||
|
||||
STARS='***************************************************'
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
die() {
|
||||
echo "${1:-"Unknown Error"}" 1>&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
# build_for_targets <target list>
|
||||
# call this in the project directory
|
||||
function build_for_targets
|
||||
{
|
||||
target_list="$1"
|
||||
for IDF_TARGET in ${target_list}
|
||||
do
|
||||
export IDF_TARGET
|
||||
echo "${STARS}"
|
||||
echo "Building in $PWD with CMake for ${IDF_TARGET}"
|
||||
idf.py set-target "${IDF_TARGET}"
|
||||
idf.py build || die "CMake build in ${PWD} has failed for ${IDF_TARGET}"
|
||||
idf.py fullclean
|
||||
done
|
||||
}
|
||||
|
||||
function build_folders
|
||||
{
|
||||
pushd "$1"
|
||||
EXAMPLES=$(find . -maxdepth 1 -mindepth 1 -type d | cut -d '/' -f 2)
|
||||
for NAME in ${EXAMPLES}
|
||||
do
|
||||
cd "${NAME}"
|
||||
build_for_targets "${TEST_TARGETS}"
|
||||
cd ..
|
||||
done
|
||||
popd
|
||||
}
|
||||
|
||||
echo "${STARS}"
|
||||
# Build the tests
|
||||
build_folders test/serial
|
||||
echo "${STARS}"
|
||||
# Build the tests
|
||||
build_folders test/tcp
|
||||
echo "${STARS}"
|
||||
|
@ -15,6 +15,7 @@ extern "C" {
|
||||
|
||||
#if __has_include("esp_check.h")
|
||||
#include "esp_check.h"
|
||||
#include "esp_log.h"
|
||||
|
||||
#define MB_RETURN_ON_FALSE(a, err_code, tag, format, ...) ESP_RETURN_ON_FALSE(a, err_code, tag, format __VA_OPT__(,) __VA_ARGS__)
|
||||
|
||||
@ -24,7 +25,7 @@ extern "C" {
|
||||
|
||||
#define MB_RETURN_ON_FALSE(a, err_code, tag, format, ...) do { \
|
||||
if (!(a)) { \
|
||||
MB_LOGE(tag, "%s(%d): " format, __FUNCTION__, __LINE__ __VA_OPT__(,) __VA_ARGS__); \
|
||||
ESP_LOGE(tag, "%s(%d): " format, __FUNCTION__, __LINE__ __VA_OPT__(,) __VA_ARGS__); \
|
||||
return err_code; \
|
||||
} \
|
||||
} while(0)
|
||||
|
5
idf_component.yml
Normal file
5
idf_component.yml
Normal file
@ -0,0 +1,5 @@
|
||||
version: "0.1.0"
|
||||
description: ESP-MODBUS is the official Modbus library for Espressif SoCs.
|
||||
dependencies:
|
||||
idf: ">=4.1"
|
||||
|
7
test/README.md
Normal file
7
test/README.md
Normal file
@ -0,0 +1,7 @@
|
||||
# Test Apps
|
||||
|
||||
This directory contains a set of ESP-IDF projects to be used as tests only, which aim to exercise various
|
||||
configuration of components to check completely arbitrary functionality should it be building only, executing under
|
||||
various conditions or combination with other components, including custom test frameworks.
|
||||
|
||||
The test apps are not intended to demonstrate the ESP-IDF functionality in any way.
|
@ -3,4 +3,4 @@
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
idf_component_register(SRCS "modbus_params.c"
|
||||
INCLUDE_DIRS "include"
|
||||
PRIV_REQUIRES freemodbus)
|
||||
PRIV_REQUIRES esp-modbus)
|
||||
|
5
test/mb_example_common/component.mk
Normal file
5
test/mb_example_common/component.mk
Normal file
@ -0,0 +1,5 @@
|
||||
#
|
||||
# Component Makefile
|
||||
#
|
||||
COMPONENT_ADD_INCLUDEDIRS := include
|
||||
COMPONENT_SRCDIRS := .
|
@ -2,7 +2,12 @@
|
||||
# in this exact order for cmake to work correctly
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
set(EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/examples/protocols/modbus/mb_example_common)
|
||||
set(EXTRA_COMPONENT_DIRS "../../../")
|
||||
set(EXCLUDE_COMPONENTS examples test_app test freemodbus)
|
||||
|
||||
# Include parameters from common modbus folder
|
||||
set(MB_PARAMS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../mb_example_common")
|
||||
list(APPEND EXTRA_COMPONENT_DIRS "${MB_PARAMS_DIR}")
|
||||
|
||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||
project(modbus_master)
|
||||
|
@ -2,7 +2,12 @@
|
||||
# in this exact order for cmake to work correctly
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
set(EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/examples/protocols/modbus/mb_example_common)
|
||||
set(EXTRA_COMPONENT_DIRS "../../../")
|
||||
set(EXCLUDE_COMPONENTS examples test_app test freemodbus)
|
||||
|
||||
# Include parameters from common modbus folder
|
||||
set(MB_PARAMS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../mb_example_common")
|
||||
list(APPEND EXTRA_COMPONENT_DIRS "${MB_PARAMS_DIR}")
|
||||
|
||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||
|
||||
|
9
test/serial/mb_serial_slave/dependencies.lock
Normal file
9
test/serial/mb_serial_slave/dependencies.lock
Normal file
@ -0,0 +1,9 @@
|
||||
dependencies:
|
||||
idf:
|
||||
component_hash: null
|
||||
source:
|
||||
type: idf
|
||||
version: 5.0.0
|
||||
manifest_hash: ef92ef397dcb09fa7a851b483306296fee18dfca839e1a68e8190dad2ed66a64
|
||||
target: esp32
|
||||
version: 1.0.0
|
@ -2,7 +2,13 @@
|
||||
# in this exact order for cmake to work correctly
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
set(EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/examples/protocols/modbus/mb_example_common)
|
||||
set(EXTRA_COMPONENT_DIRS "../../../")
|
||||
set(EXCLUDE_COMPONENTS examples test_app test freemodbus)
|
||||
|
||||
# Include parameters from common modbus folder
|
||||
set(MB_PARAMS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../mb_example_common")
|
||||
list(APPEND EXTRA_COMPONENT_DIRS "${MB_PARAMS_DIR}")
|
||||
|
||||
# (Not part of the boilerplate)
|
||||
# This example uses an extra component for common functions such as Wi-Fi and Ethernet connection.
|
||||
list(APPEND EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/examples/common_components/protocol_examples_common)
|
||||
|
@ -2,8 +2,12 @@
|
||||
# in this exact order for cmake to work correctly
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
# This component includes modbus example common definitions
|
||||
set(EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/examples/protocols/modbus/mb_example_common)
|
||||
set(EXTRA_COMPONENT_DIRS "../../../")
|
||||
set(EXCLUDE_COMPONENTS examples test_app test freemodbus)
|
||||
|
||||
# Include parameters from common modbus folder
|
||||
set(MB_PARAMS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../mb_example_common")
|
||||
list(APPEND EXTRA_COMPONENT_DIRS "${MB_PARAMS_DIR}")
|
||||
|
||||
# (Not part of the boilerplate)
|
||||
# This example uses an extra component for common functions such as Wi-Fi and Ethernet connection.
|
||||
|
@ -4,8 +4,8 @@
|
||||
# Modbus Slave Example
|
||||
|
||||
This example demonstrates using of FreeModbus TCP slave stack port implementation for supported ESP32 target chips. The external Modbus host is able to read/write device parameters using Modbus protocol transport. The parameters accessible thorough Modbus are located in `mb_example_common/modbus_params.h\c` files and can be updated by user.
|
||||
These are represented in structures holding_reg_params, input_reg_params, coil_reg_params, discrete_reg_params for holding registers, input parameters, coils and discrete inputs accordingly. The app_main application demonstrates how to setup Modbus stack and use notifications about parameters change from host system.
|
||||
The FreeModbus stack located in `components/freemodbus` folder and contain `/port` folder inside which contains FreeModbus stack port for ESP32 target chips. There are some parameters that can be configured in KConfig file to start stack correctly (See description below for more information).
|
||||
These are represented in structures holding_reg_params, input_reg_params, coil_reg_params, discrete_reg_params for holding registers, input parameters, coils and discrete inputs accordingly. The app_main application demonstrates how to setup Modbus stack and use notifications about parameters change from host system.
|
||||
The FreeModbus stack located in `components/freemodbus` folder and contain `/port` folder inside which contains FreeModbus stack port for ESP32. There are some parameters that can be configured in KConfig file to start stack correctly (See description below for more information).
|
||||
|
||||
The slave example uses shared parameter structures defined in ```examples/protocols/modbus/mb_example_common``` folder.
|
||||
|
||||
@ -37,7 +37,7 @@ Configure the external Modbus master software according to port configuration pa
|
||||
As an example the Modbus Poll application can be used with this example.
|
||||
Option 2:
|
||||
Setup ESP32 based development board and set modbus_tcp_master example configuration as described in its README.md file.
|
||||
Setup one or more slave boards and connect them into the same Modbus segment (See configuration above).
|
||||
Setup one or more slave boards and connect them into the same Modbus segment (See configuration above).
|
||||
|
||||
### Build and flash software
|
||||
Build the project and flash it to the board, then run monitor tool to view serial output:
|
||||
|
Reference in New Issue
Block a user