-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
ESP-IDF support #745
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
Open
fedepell
wants to merge
2
commits into
stephane:master
Choose a base branch
from
fedepell:esp32_serial_support
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
ESP-IDF support #745
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| # 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 | ||
| "src/modbus-data.c" | ||
| "src/modbus-rtu.c" | ||
| "src/modbus-tcp.c" | ||
| "src/modbus.c") | ||
|
|
||
| set(include_dirs src) | ||
|
|
||
| set(priv_include_dirs ../) | ||
|
|
||
| list(APPEND priv_include_dirs) | ||
|
|
||
| add_prefix(srcs "${CMAKE_CURRENT_LIST_DIR}/libmodbus/" ${srcs}) | ||
| add_prefix(include_dirs "${CMAKE_CURRENT_LIST_DIR}/libmodbus/" ${include_dirs}) | ||
| add_prefix(priv_include_dirs "${CMAKE_CURRENT_LIST_DIR}/libmodbus/" ${priv_include_dirs}) | ||
|
|
||
| message(STATUS "DEBUG: Using libmodbus component folder: ${CMAKE_CURRENT_LIST_DIR}.") | ||
|
|
||
| idf_component_register(SRCS "${srcs}" | ||
| INCLUDE_DIRS "${include_dirs}" | ||
| PRIV_INCLUDE_DIRS "${priv_include_dirs}" | ||
| PRIV_REQUIRES driver vfs) | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| # Instructions to use with Espressif IoT Development Framework (ESP-IDF) | ||
|
|
||
| ## Adding libmodbus as a component | ||
|
|
||
| - Create a subdirectory at the top level of your ESP-IDF project where you will | ||
| place this and create a component, ie. `libmodbus`. This directory will be | ||
| referred as *component directory* further down in this text. | ||
|
|
||
| - Download the latest version of libmodbus with the method of your choice and | ||
| unpack it under component directory in a subdirectory `libmodbus` | ||
|
|
||
| - Copy the files supplied in this documentation directory to the component directory, | ||
| namely: | ||
| - `CMakeLists.txt`: the CMake script that enumerates files and directories used | ||
| in the build as well as defines needed dependencies | ||
| - `component.mk`: the component build definition | ||
| - `config.h`: the library configuration, especially tailored for ESP-IDF. This is | ||
| usually generated with the autoconf tool, but this is not present in ESP-IDF and | ||
| is therefore manually prepared and customized | ||
| - `idf_component.yml`: the component description file | ||
|
|
||
| - Add a reference from your main project in the project top level `CMakeLists.txt` to | ||
| the newly added module with something like: `set(EXTRA_COMPONENT_DIRS libmodbus/)`. | ||
| If you already have other components you may just add the reference to the newly | ||
| added component. | ||
|
|
||
| - As the ESP-IDF does not provide a `nanosleep` function in its SDK, you should add | ||
| this in your project so you will be able to find it at linking time, for example: | ||
|
|
||
| ``` | ||
| int nanosleep(const struct timespec *req, struct timespec *_Nullable rem) { | ||
| return usleep(req->tv_sec*1000 + req->tv_nsec / 1000); | ||
| } | ||
| ``` | ||
|
|
||
| Now you are almost ready to use libmodbus in your project! | ||
|
|
||
| If you desire to use the library for serial communication, you will need to do a few | ||
| more hardware configuration steps before using the `modbus_new_rtu` call, namely: | ||
|
|
||
| - Configure, if needed, any pins for the used uart via `uart_set_pin` | ||
|
|
||
| - Install the uart driver via the `uart_driver_install` | ||
fedepell marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| - Configure, if needed, the uart mode (ie. set it to half duplex) via `uart_set_mode` | ||
fedepell marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| These configurations are not included in libmodbus as they are highly hardware specific | ||
| and would require a heavy change in the library interface. | ||
|
|
||
| ## Other details using libmodbus with ESP-IDF | ||
|
|
||
| - The serial driver is implemented using the `vfs` virtual filesystem component. This | ||
| makes the changes needed for the library minimal, but may not be the most performant | ||
| solution. Be aware that if you are not using the UART0 as console (ie. you are | ||
| disabling console or you are using the USB Serial/JTAG Controller) you may need to | ||
| explicitly initialize UART VFS in your main program as well just by calling | ||
| `uart_vfs_dev_register()` (from `driver/uart_vfs.h`). | ||
|
|
||
| - The serial name (first parameter to `modbus_new_rtu`) should be a string containing | ||
| only the serial index (ie. `"1"` or `"2"`). | ||
|
|
||
| - When using the TCP version be aware of the maximum number of sockets that can be | ||
| open on the platform: this is by default 10 and can be possibly raised to 16 in | ||
| a standard configuration. Please check the `LWIP_MAX_SOCKETS` configuration | ||
| variable. | ||
|
|
||
| - Older versions (<=5.3.1) of ESP-IDF contain a buglet in the serial read code that | ||
| may cause some packet loss under certain circumstances (when line ending | ||
| chars are present), see also: https://github.com/espressif/esp-idf/issues/14155 | ||
| Please use a newer version of ESP-IDF if you see this behavior. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| INCLUDEDIRS := src | ||
| PRIV_INCLUDEDIRS := ../ | ||
| SRCDIRS := src | ||
|
|
||
| COMPONENT_PRIV_INCLUDEDIRS = $(addprefix libmodbus/, \ | ||
| $(PRIV_INCLUDEDIRS) \ | ||
| ) | ||
|
|
||
| COMPONENT_SRCDIRS = $(addprefix libmodbus/, \ | ||
| $(SRCDIRS) \ | ||
| ) | ||
|
|
||
| COMPONENT_ADD_INCLUDEDIRS = $(addprefix libmodbus/, \ | ||
| $(INCLUDEDIRS) \ | ||
| ) | ||
|
|
||
|
|
||
|
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.