From cb1a315ee546aa9b3f2378c16bd918a02d0a8dc4 Mon Sep 17 00:00:00 2001 From: Alex Lisitsyn Date: Thu, 12 Jan 2023 02:10:03 +0800 Subject: [PATCH] Add support for esp32c2 target --- .gitlab-ci.yml | 4 ++-- freemodbus/port/portserial.c | 6 +++++- freemodbus/port/portserial_m.c | 4 ++++ test/serial/mb_serial_master/README.md | 6 +++--- test/serial/mb_serial_master/main/Kconfig.projbuild | 13 ++++++++----- test/serial/mb_serial_slave/README.md | 6 +++--- test/serial/mb_serial_slave/main/Kconfig.projbuild | 13 ++++++++----- test/tcp/mb_tcp_master/README.md | 4 ++-- test/tcp/mb_tcp_slave/README.md | 4 ++-- 9 files changed, 37 insertions(+), 23 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index af1bb8e..2616e9a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -77,8 +77,8 @@ build_idf_latest: extends: .build_template image: espressif/idf:latest variables: - EXAMPLE_TARGETS: "esp32 esp32s2 esp32s3 esp32c3" - TEST_TARGETS: "esp32 esp32s3" + EXAMPLE_TARGETS: "esp32 esp32s2 esp32s3 esp32c3 esp32c2" + TEST_TARGETS: "esp32 esp32s3 esp32c2" # GNU Make based build system is not supported starting from IDF v5.0 SKIP_GNU_MAKE_BUILD: 1 diff --git a/freemodbus/port/portserial.c b/freemodbus/port/portserial.c index dbc148d..adffe6d 100644 --- a/freemodbus/port/portserial.c +++ b/freemodbus/port/portserial.c @@ -222,7 +222,11 @@ BOOL xMBPortSerialInit(UCHAR ucPORT, ULONG ulBaudRate, .stop_bits = UART_STOP_BITS_1, .flow_ctrl = UART_HW_FLOWCTRL_DISABLE, .rx_flow_ctrl_thresh = 2, - .source_clk = UART_SCLK_APB +#if (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)) + .source_clk = UART_SCLK_DEFAULT, +#else + .source_clk = UART_SCLK_APB, +#endif }; // Set UART config xErr = uart_param_config(ucUartNumber, &xUartConfig); diff --git a/freemodbus/port/portserial_m.c b/freemodbus/port/portserial_m.c index cc37f51..78e3ff0 100644 --- a/freemodbus/port/portserial_m.c +++ b/freemodbus/port/portserial_m.c @@ -293,7 +293,11 @@ BOOL xMBMasterPortSerialInit( UCHAR ucPORT, ULONG ulBaudRate, UCHAR ucDataBits, .stop_bits = UART_STOP_BITS_1, .flow_ctrl = UART_HW_FLOWCTRL_DISABLE, .rx_flow_ctrl_thresh = 2, +#if (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)) + .source_clk = UART_SCLK_DEFAULT, +#else .source_clk = UART_SCLK_APB, +#endif }; // Set UART config xErr = uart_param_config(ucUartNumber, &xUartConfig); diff --git a/test/serial/mb_serial_master/README.md b/test/serial/mb_serial_master/README.md index 107d72a..01e65ce 100644 --- a/test/serial/mb_serial_master/README.md +++ b/test/serial/mb_serial_master/README.md @@ -1,5 +1,5 @@ -| Supported Targets | ESP32 | ESP32-S2 | ESP32-S3 | ESP32-C3 | -| ----------------- | ----- | -------- | -------- | -------- | +| Supported Targets | ESP32 | ESP32-S2 | ESP32-S3 | ESP32-C3 | ESP32-C2 | +| ----------------- | ----- | -------- | -------- | -------- | -------- | # Modbus Master Example @@ -97,7 +97,7 @@ Configure the slave address for each slave in the Modbus segment (the CONFIG_MB_ ``` -------------------------------------------------------------------------------------------------------------------------- | UART Interface | #define | Default ESP32 Pin | Default pins for | External RS485 Driver Pin | - | | | | ESP32-S2(S3, C3) | | + | | | | ESP32-S2(S3, C3, C2) | | | ----------------------|--------------------|-----------------------|-----------------------|---------------------------| | Transmit Data (TxD) | CONFIG_MB_UART_TXD | GPIO23 | GPIO9 | DI | | Receive Data (RxD) | CONFIG_MB_UART_RXD | GPIO22 | GPIO8 | RO | diff --git a/test/serial/mb_serial_master/main/Kconfig.projbuild b/test/serial/mb_serial_master/main/Kconfig.projbuild index b923e15..eae846f 100644 --- a/test/serial/mb_serial_master/main/Kconfig.projbuild +++ b/test/serial/mb_serial_master/main/Kconfig.projbuild @@ -4,8 +4,8 @@ menu "Modbus Example Configuration" int "UART port number" range 0 2 if IDF_TARGET_ESP32 || IDF_TARGET_ESP32S3 default 2 if IDF_TARGET_ESP32 || IDF_TARGET_ESP32S3 - range 0 1 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32C3 - default 1 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32C3 + range 0 1 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32C2 + default 1 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32C2 help UART communication port number for Modbus example. @@ -23,7 +23,8 @@ menu "Modbus Example Configuration" range 0 46 if IDF_TARGET_ESP32S2 range 0 47 if IDF_TARGET_ESP32S3 range 0 19 if IDF_TARGET_ESP32C3 - default 8 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3 || IDF_TARGET_ESP32C3 + range 0 20 if IDF_TARGET_ESP32C2 + default 8 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3 || IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32C2 help GPIO number for UART RX pin. See UART documentation for more information about available pin numbers for UART. @@ -35,7 +36,8 @@ menu "Modbus Example Configuration" range 0 46 if IDF_TARGET_ESP32S2 range 0 47 if IDF_TARGET_ESP32S3 range 0 19 if IDF_TARGET_ESP32C3 - default 9 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3 || IDF_TARGET_ESP32C3 + range 0 20 if IDF_TARGET_ESP32C2 + default 9 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3 || IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32C2 help GPIO number for UART TX pin. See UART documentation for more information about available pin numbers for UART. @@ -47,7 +49,8 @@ menu "Modbus Example Configuration" range 0 46 if IDF_TARGET_ESP32S2 range 0 47 if IDF_TARGET_ESP32S3 range 0 19 if IDF_TARGET_ESP32C3 - default 10 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3 || IDF_TARGET_ESP32C3 + range 0 20 if IDF_TARGET_ESP32C2 + default 10 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3 || IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32C2 help GPIO number for UART RTS pin. This pin is connected to ~RE/DE pin of RS485 transceiver to switch direction. diff --git a/test/serial/mb_serial_slave/README.md b/test/serial/mb_serial_slave/README.md index be327fa..5d5515f 100644 --- a/test/serial/mb_serial_slave/README.md +++ b/test/serial/mb_serial_slave/README.md @@ -1,5 +1,5 @@ -| Supported Targets | ESP32 | ESP32-S2 | ESP32-S3 | ESP32-C3 | -| ----------------- | ----- | -------- | -------- | -------- | +| Supported Targets | ESP32 | ESP32-S2 | ESP32-S3 | ESP32-C3 | ESP32-C2 | +| ----------------- | ----- | -------- | -------- | -------- | -------- | # Modbus Slave Example @@ -47,7 +47,7 @@ Configure the UART pins used for modbus communication using the command and tabl ``` -------------------------------------------------------------------------------------------------------------------------- | UART Interface | #define | Default ESP32 Pin | Default pins for | External RS485 Driver Pin | - | | | | ESP32-S2(S3, C3) | | + | | | | ESP32-S2(S3, C3, C2) | | | ----------------------|--------------------|-----------------------|-----------------------|---------------------------| | Transmit Data (TxD) | CONFIG_MB_UART_TXD | GPIO23 | GPIO9 | DI | | Receive Data (RxD) | CONFIG_MB_UART_RXD | GPIO22 | GPIO8 | RO | diff --git a/test/serial/mb_serial_slave/main/Kconfig.projbuild b/test/serial/mb_serial_slave/main/Kconfig.projbuild index 884a1b8..b249c4e 100644 --- a/test/serial/mb_serial_slave/main/Kconfig.projbuild +++ b/test/serial/mb_serial_slave/main/Kconfig.projbuild @@ -4,8 +4,8 @@ menu "Modbus Example Configuration" int "UART port number" range 0 2 if IDF_TARGET_ESP32 || IDF_TARGET_ESP32S3 default 2 if IDF_TARGET_ESP32 || IDF_TARGET_ESP32S3 - range 0 1 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32C3 - default 1 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32C3 + range 0 1 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32C2 + default 1 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32C2 help UART communication port number for Modbus example. @@ -23,7 +23,8 @@ menu "Modbus Example Configuration" range 0 46 if IDF_TARGET_ESP32S2 range 0 47 if IDF_TARGET_ESP32S3 range 0 19 if IDF_TARGET_ESP32C3 - default 8 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3 || IDF_TARGET_ESP32C3 + range 0 20 if IDF_TARGET_ESP32C2 + default 8 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3 || IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32C2 help GPIO number for UART RX pin. See UART documentation for more information about available pin numbers for UART. @@ -35,7 +36,8 @@ menu "Modbus Example Configuration" range 0 46 if IDF_TARGET_ESP32S2 range 0 47 if IDF_TARGET_ESP32S3 range 0 19 if IDF_TARGET_ESP32C3 - default 9 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3 || IDF_TARGET_ESP32C3 + range 0 20 if IDF_TARGET_ESP32C2 + default 9 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3 || IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32C2 help GPIO number for UART TX pin. See UART documentation for more information about available pin numbers for UART. @@ -47,7 +49,8 @@ menu "Modbus Example Configuration" range 0 46 if IDF_TARGET_ESP32S2 range 0 47 if IDF_TARGET_ESP32S3 range 0 19 if IDF_TARGET_ESP32C3 - default 10 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3 || IDF_TARGET_ESP32C3 + range 0 20 if IDF_TARGET_ESP32C2 + default 10 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3 || IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32C2 help GPIO number for UART RTS pin. This pin is connected to ~RE/DE pin of RS485 transceiver to switch direction. diff --git a/test/tcp/mb_tcp_master/README.md b/test/tcp/mb_tcp_master/README.md index 8673580..eaffef5 100644 --- a/test/tcp/mb_tcp_master/README.md +++ b/test/tcp/mb_tcp_master/README.md @@ -1,5 +1,5 @@ -| Supported Targets | ESP32 | ESP32-S2 | ESP32-S3 | ESP32-C3 | -| ----------------- | ----- | -------- | -------- | -------- | +| Supported Targets | ESP32 | ESP32-S2 | ESP32-S3 | ESP32-C3 | ESP32-C2 | +| ----------------- | ----- | -------- | -------- | -------- | -------- | # Modbus TCP Master Example diff --git a/test/tcp/mb_tcp_slave/README.md b/test/tcp/mb_tcp_slave/README.md index 0fcebb8..126119c 100644 --- a/test/tcp/mb_tcp_slave/README.md +++ b/test/tcp/mb_tcp_slave/README.md @@ -1,5 +1,5 @@ -| Supported Targets | ESP32 | ESP32-S2 | ESP32-S3 | ESP32-C3 | -| ----------------- | ----- | -------- | -------- | -------- | +| Supported Targets | ESP32 | ESP32-S2 | ESP32-S3 | ESP32-C3 | ESP32-C2 | +| ----------------- | ----- | -------- | -------- | -------- | -------- | # Modbus Slave Example