refactor(usb_serial_jtag): make usb_serial_jtag as component

This commit is contained in:
Cao Sen Miao 2024-01-02 18:08:35 +08:00
parent 32e2101c0d
commit 3dc76e9360
33 changed files with 244 additions and 168 deletions

View File

@ -29,5 +29,5 @@ idf_component_register(SRCS "commands.c"
INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR} INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}
REQUIRES vfs REQUIRES vfs
PRIV_REQUIRES esp_driver_uart PRIV_REQUIRES esp_driver_uart
driver # to be replaced by esp_driver_usj esp_driver_usb_serial_jtag
) )

View File

@ -12,9 +12,8 @@
#include "esp_err.h" #include "esp_err.h"
#include "esp_log.h" #include "esp_log.h"
#include "esp_console.h" #include "esp_console.h"
#include "esp_vfs_dev.h"
#include "esp_vfs_cdcacm.h" #include "esp_vfs_cdcacm.h"
#include "esp_vfs_usb_serial_jtag.h" #include "driver/usb_serial_jtag_vfs.h"
#include "freertos/FreeRTOS.h" #include "freertos/FreeRTOS.h"
#include "freertos/task.h" #include "freertos/task.h"
#include "driver/uart.h" #include "driver/uart.h"
@ -144,9 +143,9 @@ esp_err_t esp_console_new_repl_usb_serial_jtag(const esp_console_dev_usb_serial_
} }
/* Minicom, screen, idf_monitor send CR when ENTER key is pressed */ /* Minicom, screen, idf_monitor send CR when ENTER key is pressed */
esp_vfs_dev_usb_serial_jtag_set_rx_line_endings(ESP_LINE_ENDINGS_CR); usb_serial_jtag_vfs_set_rx_line_endings(ESP_LINE_ENDINGS_CR);
/* Move the caret to the beginning of the next line on '\n' */ /* Move the caret to the beginning of the next line on '\n' */
esp_vfs_dev_usb_serial_jtag_set_tx_line_endings(ESP_LINE_ENDINGS_CRLF); usb_serial_jtag_vfs_set_tx_line_endings(ESP_LINE_ENDINGS_CRLF);
/* Enable blocking mode on stdin and stdout */ /* Enable blocking mode on stdin and stdout */
fcntl(fileno(stdout), F_SETFL, 0); fcntl(fileno(stdout), F_SETFL, 0);
@ -167,7 +166,7 @@ esp_err_t esp_console_new_repl_usb_serial_jtag(const esp_console_dev_usb_serial_
} }
/* Tell vfs to use usb-serial-jtag driver */ /* Tell vfs to use usb-serial-jtag driver */
esp_vfs_usb_serial_jtag_use_driver(); usb_serial_jtag_vfs_use_driver();
// setup history // setup history
ret = esp_console_setup_history(repl_config->history_save_path, repl_config->max_history_len, &usb_serial_jtag_repl->repl_com); ret = esp_console_setup_history(repl_config->history_save_path, repl_config->max_history_len, &usb_serial_jtag_repl->repl_com);
@ -466,7 +465,7 @@ static esp_err_t esp_console_repl_usb_serial_jtag_delete(esp_console_repl_t *rep
} }
repl_com->state = CONSOLE_REPL_STATE_DEINIT; repl_com->state = CONSOLE_REPL_STATE_DEINIT;
esp_console_deinit(); esp_console_deinit();
esp_vfs_usb_serial_jtag_use_nonblocking(); usb_serial_jtag_vfs_use_nonblocking();
usb_serial_jtag_driver_uninstall(); usb_serial_jtag_driver_uninstall();
free(usb_serial_jtag_repl); free(usb_serial_jtag_repl);
_exit: _exit:

View File

@ -11,8 +11,7 @@ set(srcs)
set(includes "deprecated" set(includes "deprecated"
"i2c/include" "i2c/include"
"touch_sensor/include" "touch_sensor/include"
"twai/include" "twai/include")
"usb_serial_jtag/include")
# Always included linker fragments # Always included linker fragments
set(ldfragments "") set(ldfragments "")
@ -86,12 +85,6 @@ if(CONFIG_SOC_TWAI_SUPPORTED)
list(APPEND ldfragments "twai/linker.lf") list(APPEND ldfragments "twai/linker.lf")
endif() endif()
# USB Serial JTAG related source files
if(CONFIG_SOC_USB_SERIAL_JTAG_SUPPORTED)
list(APPEND srcs "usb_serial_jtag/usb_serial_jtag.c"
"usb_serial_jtag/usb_serial_jtag_connection_monitor.c")
endif()
# Other source files # Other source files
if(${target} STREQUAL "esp32") if(${target} STREQUAL "esp32")
list(APPEND srcs "deprecated/adc_i2s_deprecated.c") list(APPEND srcs "deprecated/adc_i2s_deprecated.c")
@ -113,14 +106,7 @@ else()
esp_driver_gpio esp_driver_pcnt esp_driver_gptimer esp_driver_spi esp_driver_mcpwm esp_driver_gpio esp_driver_pcnt esp_driver_gptimer esp_driver_spi esp_driver_mcpwm
esp_driver_ana_cmpr esp_driver_i2s esp_driver_sdmmc esp_driver_sdspi esp_driver_sdio esp_driver_ana_cmpr esp_driver_i2s esp_driver_sdmmc esp_driver_sdspi esp_driver_sdio
esp_driver_dac esp_driver_rmt esp_driver_tsens esp_driver_sdm esp_driver_i2c esp_driver_dac esp_driver_rmt esp_driver_tsens esp_driver_sdm esp_driver_i2c
esp_driver_uart esp_driver_ledc esp_driver_parlio esp_driver_uart esp_driver_ledc esp_driver_parlio esp_driver_usb_serial_jtag
LDFRAGMENTS ${ldfragments} LDFRAGMENTS ${ldfragments}
) )
endif() endif()
# If system needs to monitor USJ connection status, then usb_serial_jtag_connection_monitor object file has to be linked
# to the binary, to allow tick hook to be registered
if(CONFIG_USJ_NO_AUTO_LS_ON_CONNECTION OR
(CONFIG_SOC_USB_SERIAL_JTAG_SUPPORT_LIGHT_SLEEP AND CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG_ENABLED))
target_link_libraries(${COMPONENT_LIB} INTERFACE "-u usb_serial_jtag_connection_monitor_include")
endif()

View File

@ -64,21 +64,4 @@ menu "Driver Configurations"
orsource "./twai/Kconfig.twai" orsource "./twai/Kconfig.twai"
menu "USB Serial/JTAG Configuration"
depends on SOC_USB_SERIAL_JTAG_SUPPORTED
config USJ_NO_AUTO_LS_ON_CONNECTION
bool "Don't enter the automatic light sleep when USB Serial/JTAG port is connected"
depends on PM_ENABLE && ESP_CONSOLE_USB_SERIAL_JTAG_ENABLED && !SOC_USB_SERIAL_JTAG_SUPPORT_LIGHT_SLEEP
default n
help
If enabled, the chip will constantly monitor the connection status of the USB Serial/JTAG port. As long
as the USB Serial/JTAG is connected, a ESP_PM_NO_LIGHT_SLEEP power management lock will be acquired to
prevent the system from entering light sleep.
This option can be useful if serial monitoring is needed via USB Serial/JTAG while power management is
enabled, as the USB Serial/JTAG cannot work under light sleep and after waking up from light sleep.
Note. This option can only control the automatic Light-Sleep behavior. If esp_light_sleep_start() is
called manually from the program, enabling this option will not prevent light sleep entry even if the
USB Serial/JTAG is in use.
endmenu # USB Serial/JTAG Configuration
endmenu # Driver configurations endmenu # Driver configurations

View File

@ -97,14 +97,3 @@ components/driver/test_apps/twai:
- components/driver/twai/**/* - components/driver/twai/**/*
depends_components: depends_components:
- esp_driver_gpio - esp_driver_gpio
components/driver/test_apps/usb_serial_jtag:
disable:
- if: SOC_USB_SERIAL_JTAG_SUPPORTED != 1
depends_filepatterns:
- components/driver/usb_serial_jtag/**/*
depends_components:
- hal
- esp_hw_support # for clock
- vfs
- esp_driver_gpio

View File

@ -1071,7 +1071,7 @@ void uart_vfs_dev_use_driver(int uart_num)
_lock_release_recursive(&s_ctx[uart_num]->read_lock); _lock_release_recursive(&s_ctx[uart_num]->read_lock);
} }
#if CONFIG_VFS_SUPPORT_IO && CONFIG_ESP_CONSOLE_UART #if CONFIG_ESP_CONSOLE_UART
ESP_SYSTEM_INIT_FN(init_vfs_uart, CORE, BIT(0), 110) ESP_SYSTEM_INIT_FN(init_vfs_uart, CORE, BIT(0), 110)
{ {
esp_vfs_set_primary_dev_vfs_def_struct(&uart_vfs); esp_vfs_set_primary_dev_vfs_def_struct(&uart_vfs);

View File

@ -0,0 +1,25 @@
set(srcs)
set(include "include")
# USB Serial JTAG related source files
if(CONFIG_SOC_USB_SERIAL_JTAG_SUPPORTED)
list(APPEND srcs "src/usb_serial_jtag.c"
"src/usb_serial_jtag_connection_monitor.c")
endif()
idf_component_register(SRCS ${srcs}
INCLUDE_DIRS ${include}
PRIV_REQUIRES esp_driver_gpio esp_ringbuf esp_pm esp_timer
)
if(CONFIG_VFS_SUPPORT_IO AND CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG_ENABLED)
target_link_libraries(${COMPONENT_LIB} PUBLIC idf::vfs)
target_sources(${COMPONENT_LIB} PRIVATE "src/usb_serial_jtag_vfs.c")
target_link_libraries(${COMPONENT_LIB} INTERFACE "-u usb_serial_jtag_vfs_include_dev_init")
endif()
# If system needs to monitor USJ connection status, then usb_serial_jtag_connection_monitor object file has to be linked
# to the binary, to allow tick hook to be registered
if(CONFIG_USJ_NO_AUTO_LS_ON_CONNECTION OR CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG_ENABLED)
target_link_libraries(${COMPONENT_LIB} INTERFACE "-u usb_serial_jtag_connection_monitor_include")
endif()

View File

@ -0,0 +1,16 @@
menu "ESP-Driver:USB Serial/JTAG Configuration"
depends on SOC_USB_SERIAL_JTAG_SUPPORTED
config USJ_NO_AUTO_LS_ON_CONNECTION
bool "Don't enter the automatic light sleep when USB Serial/JTAG port is connected"
depends on PM_ENABLE && ESP_CONSOLE_USB_SERIAL_JTAG_ENABLED && !SOC_USB_SERIAL_JTAG_SUPPORT_LIGHT_SLEEP
default n
help
If enabled, the chip will constantly monitor the connection status of the USB Serial/JTAG port. As long
as the USB Serial/JTAG is connected, a ESP_PM_NO_LIGHT_SLEEP power management lock will be acquired to
prevent the system from entering light sleep.
This option can be useful if serial monitoring is needed via USB Serial/JTAG while power management is
enabled, as the USB Serial/JTAG cannot work under light sleep and after waking up from light sleep.
Note. This option can only control the automatic Light-Sleep behavior. If esp_light_sleep_start() is
called manually from the program, enabling this option will not prevent light sleep entry even if the
USB Serial/JTAG is in use.
endmenu # USB Serial/JTAG Configuration

View File

@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */

View File

@ -0,0 +1,72 @@
/*
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include "esp_err.h"
#include "esp_vfs.h"
#include "esp_vfs_common.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief add /dev/usbserjtag virtual filesystem driver
*
* This function is called from startup code to enable console output
*/
esp_err_t usb_serial_jtag_vfs_register(void);
/**
* @brief Set the line endings expected to be received
*
* This specifies the conversion between line endings received and
* newlines ('\n', LF) passed into stdin:
*
* - ESP_LINE_ENDINGS_CRLF: convert CRLF to LF
* - ESP_LINE_ENDINGS_CR: convert CR to LF
* - ESP_LINE_ENDINGS_LF: no modification
*
* @note this function is not thread safe w.r.t. reading
*
* @param mode line endings expected
*/
void usb_serial_jtag_vfs_set_rx_line_endings(esp_line_endings_t mode);
/**
* @brief Set the line endings to sent
*
* This specifies the conversion between newlines ('\n', LF) on stdout and line
* endings sent:
*
* - ESP_LINE_ENDINGS_CRLF: convert LF to CRLF
* - ESP_LINE_ENDINGS_CR: convert LF to CR
* - ESP_LINE_ENDINGS_LF: no modification
*
* @note this function is not thread safe w.r.t. writing
*
* @param mode line endings to send
*/
void usb_serial_jtag_vfs_set_tx_line_endings(esp_line_endings_t mode);
/**
* @brief set VFS to use USB-SERIAL-JTAG driver for reading and writing
* @note application must configure USB-SERIAL-JTAG driver before calling these functions
* With these functions, read and write are blocking and interrupt-driven.
*/
void usb_serial_jtag_vfs_use_driver(void);
/**
* @brief set VFS to use simple functions for reading and writing UART
* Read is non-blocking, write is busy waiting until TX FIFO has enough space.
* These functions are used by default.
*/
void usb_serial_jtag_vfs_use_nonblocking(void);
#ifdef __cplusplus
}
#endif

View File

@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@ -35,7 +35,7 @@ typedef enum {
#define USB_SER_JTAG_ENDP_SIZE (64) #define USB_SER_JTAG_ENDP_SIZE (64)
#define USB_SER_JTAG_RX_MAX_SIZE (64) #define USB_SER_JTAG_RX_MAX_SIZE (64)
typedef struct{ typedef struct {
intr_handle_t intr_handle; /*!< USB-SERIAL-JTAG interrupt handler */ intr_handle_t intr_handle; /*!< USB-SERIAL-JTAG interrupt handler */
portMUX_TYPE spinlock; /*!< Spinlock for usb_serial_jtag */ portMUX_TYPE spinlock; /*!< Spinlock for usb_serial_jtag */
_Atomic fifo_status_t fifo_status; /*!< Record the status of fifo */ _Atomic fifo_status_t fifo_status; /*!< Record the status of fifo */
@ -63,7 +63,8 @@ static size_t usb_serial_jtag_write_and_flush(const uint8_t *buf, uint32_t wr_le
return size; return size;
} }
static void usb_serial_jtag_isr_handler_default(void *arg) { static void usb_serial_jtag_isr_handler_default(void *arg)
{
BaseType_t xTaskWoken = 0; BaseType_t xTaskWoken = 0;
uint32_t usbjtag_intr_status = 0; uint32_t usbjtag_intr_status = 0;
usbjtag_intr_status = usb_serial_jtag_ll_get_intsts_mask(); usbjtag_intr_status = usb_serial_jtag_ll_get_intsts_mask();
@ -154,7 +155,7 @@ esp_err_t usb_serial_jtag_driver_install(usb_serial_jtag_driver_config_t *usb_se
ESP_RETURN_ON_FALSE((usb_serial_jtag_config->rx_buffer_size > 0), ESP_ERR_INVALID_ARG, USB_SERIAL_JTAG_TAG, "RX buffer is not prepared"); ESP_RETURN_ON_FALSE((usb_serial_jtag_config->rx_buffer_size > 0), ESP_ERR_INVALID_ARG, USB_SERIAL_JTAG_TAG, "RX buffer is not prepared");
ESP_RETURN_ON_FALSE((usb_serial_jtag_config->rx_buffer_size > USB_SER_JTAG_RX_MAX_SIZE), ESP_ERR_INVALID_ARG, USB_SERIAL_JTAG_TAG, "RX buffer prepared is so small, should larger than 64"); ESP_RETURN_ON_FALSE((usb_serial_jtag_config->rx_buffer_size > USB_SER_JTAG_RX_MAX_SIZE), ESP_ERR_INVALID_ARG, USB_SERIAL_JTAG_TAG, "RX buffer prepared is so small, should larger than 64");
ESP_RETURN_ON_FALSE((usb_serial_jtag_config->tx_buffer_size > 0), ESP_ERR_INVALID_ARG, USB_SERIAL_JTAG_TAG, "TX buffer is not prepared"); ESP_RETURN_ON_FALSE((usb_serial_jtag_config->tx_buffer_size > 0), ESP_ERR_INVALID_ARG, USB_SERIAL_JTAG_TAG, "TX buffer is not prepared");
p_usb_serial_jtag_obj = (usb_serial_jtag_obj_t*) heap_caps_calloc(1, sizeof(usb_serial_jtag_obj_t), MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); p_usb_serial_jtag_obj = (usb_serial_jtag_obj_t*) heap_caps_calloc(1, sizeof(usb_serial_jtag_obj_t), MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
p_usb_serial_jtag_obj->rx_buf_size = usb_serial_jtag_config->rx_buffer_size; p_usb_serial_jtag_obj->rx_buf_size = usb_serial_jtag_config->rx_buffer_size;
p_usb_serial_jtag_obj->tx_buf_size = usb_serial_jtag_config->tx_buffer_size; p_usb_serial_jtag_obj->tx_buf_size = usb_serial_jtag_config->tx_buffer_size;
p_usb_serial_jtag_obj->tx_stash_cnt = 0; p_usb_serial_jtag_obj->tx_stash_cnt = 0;
@ -188,9 +189,9 @@ esp_err_t usb_serial_jtag_driver_install(usb_serial_jtag_driver_config_t *usb_se
// Configure PHY // Configure PHY
usb_fsls_phy_ll_int_jtag_enable(&USB_SERIAL_JTAG); usb_fsls_phy_ll_int_jtag_enable(&USB_SERIAL_JTAG);
usb_serial_jtag_ll_clr_intsts_mask(USB_SERIAL_JTAG_INTR_SERIAL_IN_EMPTY| usb_serial_jtag_ll_clr_intsts_mask(USB_SERIAL_JTAG_INTR_SERIAL_IN_EMPTY |
USB_SERIAL_JTAG_INTR_SERIAL_OUT_RECV_PKT); USB_SERIAL_JTAG_INTR_SERIAL_OUT_RECV_PKT);
usb_serial_jtag_ll_ena_intr_mask(USB_SERIAL_JTAG_INTR_SERIAL_IN_EMPTY| usb_serial_jtag_ll_ena_intr_mask(USB_SERIAL_JTAG_INTR_SERIAL_IN_EMPTY |
USB_SERIAL_JTAG_INTR_SERIAL_OUT_RECV_PKT); USB_SERIAL_JTAG_INTR_SERIAL_OUT_RECV_PKT);
err = esp_intr_alloc(ETS_USB_SERIAL_JTAG_INTR_SOURCE, 0, usb_serial_jtag_isr_handler_default, NULL, &p_usb_serial_jtag_obj->intr_handle); err = esp_intr_alloc(ETS_USB_SERIAL_JTAG_INTR_SOURCE, 0, usb_serial_jtag_isr_handler_default, NULL, &p_usb_serial_jtag_obj->intr_handle);
@ -245,7 +246,7 @@ int usb_serial_jtag_write_bytes(const void* src, size_t size, TickType_t ticks_t
// Blocking method, Sending data to ringbuffer, and handle the data in ISR. // Blocking method, Sending data to ringbuffer, and handle the data in ISR.
if (size - sent_data > 0) { if (size - sent_data > 0) {
result = xRingbufferSend(p_usb_serial_jtag_obj->tx_ring_buf, (void*) (buff+sent_data), size-sent_data, ticks_to_wait); result = xRingbufferSend(p_usb_serial_jtag_obj->tx_ring_buf, (void*)(buff + sent_data), size - sent_data, ticks_to_wait);
} else { } else {
atomic_store(&p_usb_serial_jtag_obj->fifo_status, FIFO_IDLE); atomic_store(&p_usb_serial_jtag_obj->fifo_status, FIFO_IDLE);
} }
@ -255,7 +256,7 @@ int usb_serial_jtag_write_bytes(const void* src, size_t size, TickType_t ticks_t
esp_err_t usb_serial_jtag_driver_uninstall(void) esp_err_t usb_serial_jtag_driver_uninstall(void)
{ {
if(p_usb_serial_jtag_obj == NULL) { if (p_usb_serial_jtag_obj == NULL) {
ESP_LOGI(USB_SERIAL_JTAG_TAG, "ALREADY NULL"); ESP_LOGI(USB_SERIAL_JTAG_TAG, "ALREADY NULL");
return ESP_OK; return ESP_OK;
} }
@ -265,11 +266,11 @@ esp_err_t usb_serial_jtag_driver_uninstall(void)
usb_serial_jtag_ll_disable_intr_mask(USB_SERIAL_JTAG_INTR_SERIAL_IN_EMPTY | USB_SERIAL_JTAG_INTR_SERIAL_OUT_RECV_PKT); usb_serial_jtag_ll_disable_intr_mask(USB_SERIAL_JTAG_INTR_SERIAL_IN_EMPTY | USB_SERIAL_JTAG_INTR_SERIAL_OUT_RECV_PKT);
esp_intr_free(p_usb_serial_jtag_obj->intr_handle); esp_intr_free(p_usb_serial_jtag_obj->intr_handle);
if(p_usb_serial_jtag_obj->rx_ring_buf) { if (p_usb_serial_jtag_obj->rx_ring_buf) {
vRingbufferDelete(p_usb_serial_jtag_obj->rx_ring_buf); vRingbufferDelete(p_usb_serial_jtag_obj->rx_ring_buf);
p_usb_serial_jtag_obj->rx_ring_buf = NULL; p_usb_serial_jtag_obj->rx_ring_buf = NULL;
} }
if(p_usb_serial_jtag_obj->tx_ring_buf) { if (p_usb_serial_jtag_obj->tx_ring_buf) {
vRingbufferDelete(p_usb_serial_jtag_obj->tx_ring_buf); vRingbufferDelete(p_usb_serial_jtag_obj->tx_ring_buf);
p_usb_serial_jtag_obj->tx_ring_buf = NULL; p_usb_serial_jtag_obj->tx_ring_buf = NULL;
} }

View File

@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@ -29,7 +29,6 @@ static uint32_t remaining_allowed_no_sof_ticks;
static __attribute__((unused)) const char *USB_SERIAL_JTAG_CONN_MONITOR_TAG = "usb_serial_jtag"; static __attribute__((unused)) const char *USB_SERIAL_JTAG_CONN_MONITOR_TAG = "usb_serial_jtag";
bool usb_serial_jtag_is_connected(void) bool usb_serial_jtag_is_connected(void)
{ {
return s_usb_serial_jtag_conn_status; return s_usb_serial_jtag_conn_status;
@ -76,7 +75,7 @@ ESP_SYSTEM_INIT_FN(usb_serial_jtag_conn_status_init, SECONDARY, BIT(0), 230)
{ {
#if CONFIG_USJ_NO_AUTO_LS_ON_CONNECTION #if CONFIG_USJ_NO_AUTO_LS_ON_CONNECTION
ESP_RETURN_ON_ERROR(esp_pm_lock_create(ESP_PM_NO_LIGHT_SLEEP, 0, "usb_serial_jtag", &s_usb_serial_jtag_pm_lock), ESP_RETURN_ON_ERROR(esp_pm_lock_create(ESP_PM_NO_LIGHT_SLEEP, 0, "usb_serial_jtag", &s_usb_serial_jtag_pm_lock),
USB_SERIAL_JTAG_CONN_MONITOR_TAG, "create NO_LIGHT_SLEEP lock failed"); USB_SERIAL_JTAG_CONN_MONITOR_TAG, "create NO_LIGHT_SLEEP lock failed");
// We always assume it is connected at first, so acquires the lock to avoid auto light sleep // We always assume it is connected at first, so acquires the lock to avoid auto light sleep
esp_pm_lock_acquire(s_usb_serial_jtag_pm_lock); esp_pm_lock_acquire(s_usb_serial_jtag_pm_lock);
#endif #endif

View File

@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@ -16,14 +16,17 @@
#include <sys/param.h> #include <sys/param.h>
#include "esp_timer.h" #include "esp_timer.h"
#include "esp_vfs.h" #include "esp_vfs.h"
#include "esp_vfs_dev.h" #include "esp_vfs_dev.h" // Old headers for the aliasing functions
#include "esp_vfs_usb_serial_jtag.h" // Old headers for the aliasing functions
#include "esp_private/esp_vfs_console.h"
#include "esp_attr.h" #include "esp_attr.h"
#include "esp_log.h" #include "esp_log.h"
#include "sdkconfig.h" #include "sdkconfig.h"
#include "soc/soc_caps.h" #include "soc/soc_caps.h"
#include "hal/usb_serial_jtag_ll.h" #include "hal/usb_serial_jtag_ll.h"
#include "esp_vfs_usb_serial_jtag.h" #include "driver/usb_serial_jtag_vfs.h"
#include "driver/usb_serial_jtag.h" #include "driver/usb_serial_jtag.h"
#include "esp_private/startup_internal.h"
// Token signifying that no character is available // Token signifying that no character is available
#define NONE -1 #define NONE -1
@ -53,7 +56,6 @@ typedef int (*rx_func_t)(int);
static void usb_serial_jtag_tx_char(int fd, int c); static void usb_serial_jtag_tx_char(int fd, int c);
static int usb_serial_jtag_rx_char(int fd); static int usb_serial_jtag_rx_char(int fd);
//If no host is listening to the CDCACM port, the TX buffer //If no host is listening to the CDCACM port, the TX buffer
//will never be able to flush to the host. Instead of the Tx //will never be able to flush to the host. Instead of the Tx
//routines waiting forever, if the buffer hasn't been flushed //routines waiting forever, if the buffer hasn't been flushed
@ -89,11 +91,11 @@ typedef struct {
rx_func_t rx_func; rx_func_t rx_func;
// Timestamp of last time we managed to write something to the tx buffer // Timestamp of last time we managed to write something to the tx buffer
int64_t last_tx_ts; int64_t last_tx_ts;
} vfs_usb_serial_jtag_context_t; } usb_serial_jtag_vfs_context_t;
//If the context should be dynamically initialized, remove this structure //If the context should be dynamically initialized, remove this structure
//and point s_ctx to allocated data. //and point s_ctx to allocated data.
static vfs_usb_serial_jtag_context_t s_ctx = { static usb_serial_jtag_vfs_context_t s_ctx = {
.peek_char = NONE, .peek_char = NONE,
.tx_mode = DEFAULT_TX_MODE, .tx_mode = DEFAULT_TX_MODE,
.rx_mode = DEFAULT_RX_MODE, .rx_mode = DEFAULT_RX_MODE,
@ -109,7 +111,7 @@ static int usb_serial_jtag_open(const char * path, int flags, int mode)
static void usb_serial_jtag_tx_char(int fd, int c) static void usb_serial_jtag_tx_char(int fd, int c)
{ {
uint8_t cc=(uint8_t)c; uint8_t cc = (uint8_t)c;
// Try to write to the buffer as long as we still expect the buffer to have // Try to write to the buffer as long as we still expect the buffer to have
// a chance of being emptied by an active host. Just drop the data if there's // a chance of being emptied by an active host. Just drop the data if there's
// no chance anymore. // no chance anymore.
@ -163,7 +165,6 @@ static ssize_t usb_serial_jtag_write(int fd, const void * data, size_t size)
return size; return size;
} }
/* Helper function which returns a previous character or reads a new one from /* Helper function which returns a previous character or reads a new one from
* the port. Previous character can be returned ("pushed back") using * the port. Previous character can be returned ("pushed back") using
* usb_serial_jtag_return_char function. * usb_serial_jtag_return_char function.
@ -281,7 +282,6 @@ static int usb_serial_jtag_fsync(int fd)
return 0; return 0;
} }
#ifdef CONFIG_VFS_SUPPORT_TERMIOS #ifdef CONFIG_VFS_SUPPORT_TERMIOS
static int usb_serial_jtag_tcsetattr(int fd, int optional_actions, const struct termios *p) static int usb_serial_jtag_tcsetattr(int fd, int optional_actions, const struct termios *p)
{ {
@ -291,18 +291,18 @@ static int usb_serial_jtag_tcsetattr(int fd, int optional_actions, const struct
} }
switch (optional_actions) { switch (optional_actions) {
case TCSANOW: case TCSANOW:
// nothing to do // nothing to do
break; break;
case TCSADRAIN: case TCSADRAIN:
usb_serial_jtag_fsync(fd); usb_serial_jtag_fsync(fd);
break; break;
case TCSAFLUSH: case TCSAFLUSH:
// Not applicable. // Not applicable.
break; break;
default: default:
errno = EINVAL; errno = EINVAL;
return -1; return -1;
} }
if (p->c_iflag & IGNCR) { if (p->c_iflag & IGNCR) {
@ -354,17 +354,17 @@ static int usb_serial_jtag_tcflush(int fd, int select)
} }
#endif // CONFIG_VFS_SUPPORT_TERMIOS #endif // CONFIG_VFS_SUPPORT_TERMIOS
void esp_vfs_dev_usb_serial_jtag_set_tx_line_endings(esp_line_endings_t mode) void usb_serial_jtag_vfs_set_tx_line_endings(esp_line_endings_t mode)
{ {
s_ctx.tx_mode = mode; s_ctx.tx_mode = mode;
} }
void esp_vfs_dev_usb_serial_jtag_set_rx_line_endings(esp_line_endings_t mode) void usb_serial_jtag_vfs_set_rx_line_endings(esp_line_endings_t mode)
{ {
s_ctx.rx_mode = mode; s_ctx.rx_mode = mode;
} }
static const esp_vfs_t vfs = { static const esp_vfs_t usj_vfs = {
.flags = ESP_VFS_FLAG_DEFAULT, .flags = ESP_VFS_FLAG_DEFAULT,
.write = &usb_serial_jtag_write, .write = &usb_serial_jtag_write,
.open = &usb_serial_jtag_open, .open = &usb_serial_jtag_open,
@ -383,15 +383,31 @@ static const esp_vfs_t vfs = {
const esp_vfs_t* esp_vfs_usb_serial_jtag_get_vfs(void) const esp_vfs_t* esp_vfs_usb_serial_jtag_get_vfs(void)
{ {
return &vfs; return &usj_vfs;
} }
esp_err_t esp_vfs_dev_usb_serial_jtag_register(void) esp_err_t usb_serial_jtag_vfs_register(void)
{ {
// "/dev/usb_serial_jtag" unfortunately is too long for vfs // "/dev/usb_serial_jtag" unfortunately is too long for vfs
return esp_vfs_register("/dev/usbserjtag", &vfs, NULL); return esp_vfs_register("/dev/usbserjtag", &usj_vfs, NULL);
} }
#if CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG
ESP_SYSTEM_INIT_FN(init_vfs_usj, CORE, BIT(0), 111)
{
esp_vfs_set_primary_dev_vfs_def_struct(&usj_vfs);
return ESP_OK;
}
#endif
#if CONFIG_ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG
ESP_SYSTEM_INIT_FN(init_vfs_usj_sec, CORE, BIT(0), 112)
{
esp_vfs_set_secondary_dev_vfs_def_struct(&usj_vfs);
return ESP_OK;
}
#endif
/*********************************************************** /***********************************************************
* VFS uses USB-SERIAL-JTAG driver part. * VFS uses USB-SERIAL-JTAG driver part.
**********************************************************/ **********************************************************/
@ -425,7 +441,7 @@ static void usbjtag_tx_char_via_driver(int fd, int c)
} }
} }
void esp_vfs_usb_serial_jtag_use_nonblocking(void) void usb_serial_jtag_vfs_use_nonblocking(void)
{ {
_lock_acquire_recursive(&s_ctx.read_lock); _lock_acquire_recursive(&s_ctx.read_lock);
_lock_acquire_recursive(&s_ctx.write_lock); _lock_acquire_recursive(&s_ctx.write_lock);
@ -435,7 +451,7 @@ void esp_vfs_usb_serial_jtag_use_nonblocking(void)
_lock_release_recursive(&s_ctx.read_lock); _lock_release_recursive(&s_ctx.read_lock);
} }
void esp_vfs_usb_serial_jtag_use_driver(void) void usb_serial_jtag_vfs_use_driver(void)
{ {
_lock_acquire_recursive(&s_ctx.read_lock); _lock_acquire_recursive(&s_ctx.read_lock);
_lock_acquire_recursive(&s_ctx.write_lock); _lock_acquire_recursive(&s_ctx.write_lock);
@ -444,3 +460,20 @@ void esp_vfs_usb_serial_jtag_use_driver(void)
_lock_release_recursive(&s_ctx.write_lock); _lock_release_recursive(&s_ctx.write_lock);
_lock_release_recursive(&s_ctx.read_lock); _lock_release_recursive(&s_ctx.read_lock);
} }
void usb_serial_jtag_vfs_include_dev_init(void)
{
// Linker hook function, exists to make the linker examine this file
}
// -------------------------- esp_vfs_usb_serial_jtag_xxx ALIAS (deprecated) ----------------------------
esp_err_t esp_vfs_dev_usb_serial_jtag_register(void) __attribute__((alias("usb_serial_jtag_vfs_register")));
void esp_vfs_dev_usb_serial_jtag_set_rx_line_endings(esp_line_endings_t mode) __attribute__((alias("usb_serial_jtag_vfs_set_rx_line_endings")));
void esp_vfs_dev_usb_serial_jtag_set_tx_line_endings(esp_line_endings_t mode) __attribute__((alias("usb_serial_jtag_vfs_set_tx_line_endings")));
void esp_vfs_usb_serial_jtag_use_nonblocking(void) __attribute__((alias("usb_serial_jtag_vfs_use_nonblocking")));
void esp_vfs_usb_serial_jtag_use_driver(void) __attribute__((alias("usb_serial_jtag_vfs_use_driver")));

View File

@ -0,0 +1,9 @@
# Documentation: .gitlab/ci/README.md#manifest-file-to-control-the-buildtest-apps
components/esp_driver_usb_serial_jtag/test_apps/usb_serial_jtag:
disable:
- if: SOC_USB_SERIAL_JTAG_SUPPORTED != 1
depends_components:
- vfs
- esp_driver_gpio
- esp_driver_usb_serial_jtag

View File

@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@ -10,7 +10,7 @@
#include "driver/usb_serial_jtag.h" #include "driver/usb_serial_jtag.h"
#include "esp_log.h" #include "esp_log.h"
#include "esp_vfs_dev.h" #include "esp_vfs_dev.h"
#include "esp_vfs_usb_serial_jtag.h" #include "driver/usb_serial_jtag_vfs.h"
#include "driver/usb_serial_jtag.h" #include "driver/usb_serial_jtag.h"
#include <freertos/FreeRTOS.h> #include <freertos/FreeRTOS.h>
#include <freertos/semphr.h> #include <freertos/semphr.h>
@ -41,7 +41,6 @@ static void test_task_driver2(void *pvParameters)
vTaskDelete(NULL); vTaskDelete(NULL);
} }
TEST_CASE("test print via usb_serial_jtag driver multiple times in different tasks", "[usb_serial_jtag]") TEST_CASE("test print via usb_serial_jtag driver multiple times in different tasks", "[usb_serial_jtag]")
{ {
usb_serial_jtag_driver_config_t cfg = USB_SERIAL_JTAG_DRIVER_CONFIG_DEFAULT(); usb_serial_jtag_driver_config_t cfg = USB_SERIAL_JTAG_DRIVER_CONFIG_DEFAULT();
@ -50,7 +49,7 @@ TEST_CASE("test print via usb_serial_jtag driver multiple times in different tas
TEST_ESP_OK(usb_serial_jtag_driver_install(&cfg)); TEST_ESP_OK(usb_serial_jtag_driver_install(&cfg));
// Tell vfs to use usb-serial-jtag driver // Tell vfs to use usb-serial-jtag driver
esp_vfs_usb_serial_jtag_use_driver(); usb_serial_jtag_vfs_use_driver();
xTaskCreate(test_task_driver2, "usj_print_1", 4096, sem, 10, NULL); xTaskCreate(test_task_driver2, "usj_print_1", 4096, sem, 10, NULL);
xTaskCreate(test_task_driver1, "usj_print_2", 4096, sem, 10, NULL); xTaskCreate(test_task_driver1, "usj_print_2", 4096, sem, 10, NULL);
@ -61,6 +60,6 @@ TEST_CASE("test print via usb_serial_jtag driver multiple times in different tas
vSemaphoreDelete(sem); vSemaphoreDelete(sem);
vTaskDelay(5); vTaskDelay(5);
esp_vfs_usb_serial_jtag_use_nonblocking(); usb_serial_jtag_vfs_use_nonblocking();
usb_serial_jtag_driver_uninstall(); usb_serial_jtag_driver_uninstall();
} }

View File

@ -45,6 +45,8 @@ CORE: 105: init_newlib_time in components/esp_system/startup_funcs.c on BIT(0)
# Peripheral-specific implementation operators should be filled first # Peripheral-specific implementation operators should be filled first
# Then register vfs console, and follow by newlib stdio initialization # Then register vfs console, and follow by newlib stdio initialization
CORE: 110: init_vfs_uart in components/esp_driver_uart/src/uart_vfs.c on BIT(0) CORE: 110: init_vfs_uart in components/esp_driver_uart/src/uart_vfs.c on BIT(0)
CORE: 111: init_vfs_usj in components/esp_driver_usb_serial_jtag/src/usb_serial_jtag_vfs.c on BIT(0)
CORE: 112: init_vfs_usj_sec in components/esp_driver_usb_serial_jtag/src/usb_serial_jtag_vfs.c on BIT(0)
CORE: 114: init_vfs_console in components/vfs/vfs_console.c on BIT(0) CORE: 114: init_vfs_console in components/vfs/vfs_console.c on BIT(0)
CORE: 115: init_newlib_stdio in components/newlib/newlib_init.c on BIT(0) CORE: 115: init_newlib_stdio in components/newlib/newlib_init.c on BIT(0)
@ -88,7 +90,7 @@ SECONDARY: 220: esp_usb_console_init_restart_timer in components/esp_system/port
# usb_serial_jtag needs to create and acquire a PM lock at startup. # usb_serial_jtag needs to create and acquire a PM lock at startup.
# This makes more sense to be done after esp_pm_impl_init (called from init_pm). # This makes more sense to be done after esp_pm_impl_init (called from init_pm).
SECONDARY: 230: usb_serial_jtag_conn_status_init in components/driver/usb_serial_jtag/usb_serial_jtag_connection_monitor.c on BIT(0) SECONDARY: 230: usb_serial_jtag_conn_status_init in components/esp_driver_usb_serial_jtag/src/usb_serial_jtag_connection_monitor.c on BIT(0)
# Has to be the last step! # Has to be the last step!
# Now that the application is about to start, disable boot watchdog # Now that the application is about to start, disable boot watchdog

View File

@ -22,7 +22,7 @@
#include "driver/uart.h" #include "driver/uart.h"
#include "driver/uart_vfs.h" #include "driver/uart_vfs.h"
#include "utils/uart.h" #include "utils/uart.h"
#include "esp_vfs_usb_serial_jtag.h" #include "driver/usb_serial_jtag_vfs.h"
#include "driver/usb_serial_jtag.h" #include "driver/usb_serial_jtag.h"
static int s_uart_port; static int s_uart_port;
@ -81,16 +81,16 @@ esp_err_t esp_openthread_host_cli_usb_init(const esp_openthread_platform_config_
setvbuf(stdin, NULL, _IONBF, 0); setvbuf(stdin, NULL, _IONBF, 0);
/* Minicom, screen, idf_monitor send CR when ENTER key is pressed */ /* Minicom, screen, idf_monitor send CR when ENTER key is pressed */
esp_vfs_dev_usb_serial_jtag_set_rx_line_endings(ESP_LINE_ENDINGS_CR); usb_serial_jtag_vfs_set_rx_line_endings(ESP_LINE_ENDINGS_CR);
/* Move the caret to the beginning of the next line on '\n' */ /* Move the caret to the beginning of the next line on '\n' */
esp_vfs_dev_usb_serial_jtag_set_tx_line_endings(ESP_LINE_ENDINGS_CRLF); usb_serial_jtag_vfs_set_tx_line_endings(ESP_LINE_ENDINGS_CRLF);
/* Enable non-blocking mode on stdin and stdout */ /* Enable non-blocking mode on stdin and stdout */
fcntl(fileno(stdout), F_SETFL, O_NONBLOCK); fcntl(fileno(stdout), F_SETFL, O_NONBLOCK);
fcntl(fileno(stdin), F_SETFL, O_NONBLOCK); fcntl(fileno(stdin), F_SETFL, O_NONBLOCK);
ret = usb_serial_jtag_driver_install((usb_serial_jtag_driver_config_t *)&config->host_config.host_usb_config); ret = usb_serial_jtag_driver_install((usb_serial_jtag_driver_config_t *)&config->host_config.host_usb_config);
esp_vfs_usb_serial_jtag_use_driver(); usb_serial_jtag_vfs_use_driver();
uart_vfs_dev_register(); uart_vfs_dev_register();
return ret; return ret;
} }

View File

@ -10,10 +10,9 @@ list(APPEND sources "vfs.c"
"vfs_console.c" "vfs_console.c"
) )
list(APPEND pr driver list(APPEND pr esp_timer
esp_timer
# for backwards compatibility (TODO: IDF-8799) # for backwards compatibility (TODO: IDF-8799)
esp_driver_uart esp_driver_uart esp_driver_usb_serial_jtag
) )
idf_component_register(SRCS ${sources} idf_component_register(SRCS ${sources}
@ -26,10 +25,6 @@ if(CONFIG_ESP_CONSOLE_USB_CDC)
target_sources(${COMPONENT_LIB} PRIVATE "vfs_cdcacm.c") target_sources(${COMPONENT_LIB} PRIVATE "vfs_cdcacm.c")
endif() endif()
if(CONFIG_ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG OR CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG)
target_sources(${COMPONENT_LIB} PRIVATE "vfs_usb_serial_jtag.c")
endif()
# Some newlib syscalls are implemented in vfs.c, make sure these are always # Some newlib syscalls are implemented in vfs.c, make sure these are always
# seen by the linker # seen by the linker
target_link_libraries(${COMPONENT_LIB} INTERFACE "-u vfs_include_syscalls_impl") target_link_libraries(${COMPONENT_LIB} INTERFACE "-u vfs_include_syscalls_impl")

View File

@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@ -60,14 +60,14 @@ void esp_vfs_dev_uart_set_tx_line_endings(esp_line_endings_t mode) __attribute__
* @note application must configure USB-SERIAL-JTAG driver before calling these functions * @note application must configure USB-SERIAL-JTAG driver before calling these functions
* With these functions, read and write are blocking and interrupt-driven. * With these functions, read and write are blocking and interrupt-driven.
*/ */
void esp_vfs_usb_serial_jtag_use_driver(void); void esp_vfs_usb_serial_jtag_use_driver(void) __attribute__((deprecated("Please use usb_serial_jtag_vfs_use_driver() instead")));
/** /**
* @brief set VFS to use simple functions for reading and writing UART * @brief set VFS to use simple functions for reading and writing UART
* Read is non-blocking, write is busy waiting until TX FIFO has enough space. * Read is non-blocking, write is busy waiting until TX FIFO has enough space.
* These functions are used by default. * These functions are used by default.
*/ */
void esp_vfs_usb_serial_jtag_use_nonblocking(void); void esp_vfs_usb_serial_jtag_use_nonblocking(void) __attribute__((deprecated("Please use usb_serial_jtag_vfs_use_nonblocking() instead")));
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@ -14,44 +14,11 @@
extern "C" { extern "C" {
#endif #endif
/** esp_err_t esp_vfs_dev_usb_serial_jtag_register(void) __attribute__((deprecated("Please use usb_serial_jtag_vfs_register instead")));
* @brief add /dev/usbserjtag virtual filesystem driver
*
* This function is called from startup code to enable console output
*/
esp_err_t esp_vfs_dev_usb_serial_jtag_register(void);
/** void esp_vfs_dev_usb_serial_jtag_set_rx_line_endings(esp_line_endings_t mode) __attribute__((deprecated("Please use usb_serial_jtag_vfs_set_rx_line_endings instead")));
* @brief Set the line endings expected to be received
*
* This specifies the conversion between line endings received and
* newlines ('\n', LF) passed into stdin:
*
* - ESP_LINE_ENDINGS_CRLF: convert CRLF to LF
* - ESP_LINE_ENDINGS_CR: convert CR to LF
* - ESP_LINE_ENDINGS_LF: no modification
*
* @note this function is not thread safe w.r.t. reading
*
* @param mode line endings expected
*/
void esp_vfs_dev_usb_serial_jtag_set_rx_line_endings(esp_line_endings_t mode);
/** void esp_vfs_dev_usb_serial_jtag_set_tx_line_endings(esp_line_endings_t mode) __attribute__((deprecated("Please use usb_serial_jtag_vfs_set_tx_line_endings instead")));
* @brief Set the line endings to sent
*
* This specifies the conversion between newlines ('\n', LF) on stdout and line
* endings sent:
*
* - ESP_LINE_ENDINGS_CRLF: convert LF to CRLF
* - ESP_LINE_ENDINGS_CR: convert LF to CR
* - ESP_LINE_ENDINGS_LF: no modification
*
* @note this function is not thread safe w.r.t. writing
*
* @param mode line endings to send
*/
void esp_vfs_dev_usb_serial_jtag_set_tx_line_endings(esp_line_endings_t mode);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@ -8,7 +8,6 @@
#include "esp_rom_sys.h" #include "esp_rom_sys.h"
#include "esp_vfs_cdcacm.h" #include "esp_vfs_cdcacm.h"
#include "esp_vfs_private.h" #include "esp_vfs_private.h"
#include "esp_vfs_usb_serial_jtag.h"
#include "esp_private/usb_console.h" #include "esp_private/usb_console.h"
#include "esp_vfs_console.h" #include "esp_vfs_console.h"
#include "esp_private/esp_vfs_console.h" #include "esp_private/esp_vfs_console.h"
@ -59,7 +58,7 @@ int console_open(const char * path, int flags, int mode)
#if CONFIG_ESP_CONSOLE_UART #if CONFIG_ESP_CONSOLE_UART
vfs_console.fd_primary = get_vfs_for_path(primary_path)->vfs.open("/"STRINGIFY(CONFIG_ESP_CONSOLE_UART_NUM), flags, mode); vfs_console.fd_primary = get_vfs_for_path(primary_path)->vfs.open("/"STRINGIFY(CONFIG_ESP_CONSOLE_UART_NUM), flags, mode);
#elif CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG #elif CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG
vfs_console.fd_primary = esp_vfs_usb_serial_jtag_get_vfs()->open("/", flags, mode); vfs_console.fd_primary = get_vfs_for_path(primary_path)->vfs.open("/", flags, mode);
#elif CONFIG_ESP_CONSOLE_USB_CDC #elif CONFIG_ESP_CONSOLE_USB_CDC
vfs_console.fd_primary = esp_vfs_cdcacm_get_vfs()->open("/", flags, mode); vfs_console.fd_primary = esp_vfs_cdcacm_get_vfs()->open("/", flags, mode);
#endif #endif
@ -199,7 +198,7 @@ esp_err_t esp_vfs_console_register(void)
{ {
esp_err_t err = ESP_OK; esp_err_t err = ESP_OK;
// Primary register part. // Primary register part.
#ifdef CONFIG_ESP_CONSOLE_UART #if CONFIG_ESP_CONSOLE_UART || CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG
assert(primary_vfs); assert(primary_vfs);
#elif CONFIG_ESP_CONSOLE_USB_CDC #elif CONFIG_ESP_CONSOLE_USB_CDC
primary_vfs = esp_vfs_cdcacm_get_vfs(); primary_vfs = esp_vfs_cdcacm_get_vfs();
@ -207,9 +206,7 @@ esp_err_t esp_vfs_console_register(void)
if (err != ESP_OK) { if (err != ESP_OK) {
return err; return err;
} }
#elif CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG #endif
primary_vfs = esp_vfs_usb_serial_jtag_get_vfs();
#endif // CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG
err = esp_vfs_register_common(primary_path, strlen(primary_path), primary_vfs, NULL, &primary_vfs_index); err = esp_vfs_register_common(primary_path, strlen(primary_path), primary_vfs, NULL, &primary_vfs_index);
if (err != ESP_OK) { if (err != ESP_OK) {
return err; return err;
@ -217,7 +214,7 @@ esp_err_t esp_vfs_console_register(void)
// Secondary register part. // Secondary register part.
#if CONFIG_ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG #if CONFIG_ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG
secondary_vfs = esp_vfs_usb_serial_jtag_get_vfs(); assert(secondary_vfs);
err = esp_vfs_register_common(secondary_path, strlen(secondary_path), secondary_vfs, NULL, &secondary_vfs_index); err = esp_vfs_register_common(secondary_path, strlen(secondary_path), secondary_vfs, NULL, &secondary_vfs_index);
if(err != ESP_OK) { if(err != ESP_OK) {
return err; return err;

View File

@ -26,6 +26,7 @@ In order to control the dependence of other components on drivers at a smaller g
- `esp_driver_uart` - Driver for UART - `esp_driver_uart` - Driver for UART
- `esp_driver_ledc` - Driver for LEDC - `esp_driver_ledc` - Driver for LEDC
- `esp_driver_parlio` - Driver for Parallel IO - `esp_driver_parlio` - Driver for Parallel IO
- `esp_driver_usb_serial_jtag` - Driver for USB_SERIAL_JTAG
For compatibility, the original `driver`` component is still treated as an all-in-one component by registering these `esp_driver_xyz`` components as its public dependencies. In other words, you do not need to modify the CMake file of an existing project, but you now have a way to specify the specific peripheral driver that your project depends on. For compatibility, the original `driver`` component is still treated as an all-in-one component by registering these `esp_driver_xyz`` components as its public dependencies. In other words, you do not need to modify the CMake file of an existing project, but you now have a way to specify the specific peripheral driver that your project depends on.

View File

@ -26,6 +26,7 @@
- `esp_driver_uart` - UART 驱动 - `esp_driver_uart` - UART 驱动
- `esp_driver_ledc` - LEDC 驱动 - `esp_driver_ledc` - LEDC 驱动
- `esp_driver_parlio` - 并行 IO 驱动 - `esp_driver_parlio` - 并行 IO 驱动
- `esp_driver_usb_serial_jtag` - USB_SERIAL_JTAG 驱动
为了兼容性,原来的 `driver` 组件仍然存在,并作为一个 “all-in-one" 的组件,将以上这些 `esp_driver_xyz` 组件注册成自己的公共依赖。换句话说,你无需修改既有项目的 CMake 文件,但是你现在多了一个途径去指定你项目依赖的具体的外设驱动。 为了兼容性,原来的 `driver` 组件仍然存在,并作为一个 “all-in-one" 的组件,将以上这些 `esp_driver_xyz` 组件注册成自己的公共依赖。换句话说,你无需修改既有项目的 CMake 文件,但是你现在多了一个途径去指定你项目依赖的具体的外设驱动。

View File

@ -453,3 +453,5 @@ examples/peripherals/usb_serial_jtag/usb_serial_jtag_echo:
- if: IDF_TARGET not in ["esp32c6"] - if: IDF_TARGET not in ["esp32c6"]
temporary: true temporary: true
reason: lack of runners. Hardware is similar, test on one target is enough currently. reason: lack of runners. Hardware is similar, test on one target is enough currently.
depends_components:
- esp_driver_usb_serial_jtag

View File

@ -45,7 +45,7 @@
#include "esp_spiffs.h" #include "esp_spiffs.h"
#include "esp_vfs_eventfd.h" #include "esp_vfs_eventfd.h"
#include "esp_vfs_dev.h" #include "esp_vfs_dev.h"
#include "esp_vfs_usb_serial_jtag.h" #include "driver/usb_serial_jtag_vfs.h"
#include "driver/uart_vfs.h" #include "driver/uart_vfs.h"
#include "esp_wifi.h" #include "esp_wifi.h"
#include "nvs_flash.h" #include "nvs_flash.h"
@ -67,9 +67,9 @@ esp_err_t esp_zb_gateway_console_init(void)
setvbuf(stdin, NULL, _IONBF, 0); setvbuf(stdin, NULL, _IONBF, 0);
/* Minicom, screen, idf_monitor send CR when ENTER key is pressed */ /* Minicom, screen, idf_monitor send CR when ENTER key is pressed */
esp_vfs_dev_usb_serial_jtag_set_rx_line_endings(ESP_LINE_ENDINGS_CR); usb_serial_jtag_vfs_set_rx_line_endings(ESP_LINE_ENDINGS_CR);
/* Move the caret to the beginning of the next line on '\n' */ /* Move the caret to the beginning of the next line on '\n' */
esp_vfs_dev_usb_serial_jtag_set_tx_line_endings(ESP_LINE_ENDINGS_CRLF); usb_serial_jtag_vfs_set_tx_line_endings(ESP_LINE_ENDINGS_CRLF);
/* Enable non-blocking mode on stdin and stdout */ /* Enable non-blocking mode on stdin and stdout */
fcntl(fileno(stdout), F_SETFL, O_NONBLOCK); fcntl(fileno(stdout), F_SETFL, O_NONBLOCK);
@ -77,7 +77,7 @@ esp_err_t esp_zb_gateway_console_init(void)
usb_serial_jtag_driver_config_t usb_serial_jtag_config = USB_SERIAL_JTAG_DRIVER_CONFIG_DEFAULT(); usb_serial_jtag_driver_config_t usb_serial_jtag_config = USB_SERIAL_JTAG_DRIVER_CONFIG_DEFAULT();
ret = usb_serial_jtag_driver_install(&usb_serial_jtag_config); ret = usb_serial_jtag_driver_install(&usb_serial_jtag_config);
esp_vfs_usb_serial_jtag_use_driver(); usb_serial_jtag_vfs_use_driver();
uart_vfs_dev_register(); uart_vfs_dev_register();
return ret; return ret;
} }

View File

@ -12,9 +12,9 @@ set(include_dirs
"${IDF_PATH}/components/esp_driver_rmt/include/driver" "${IDF_PATH}/components/esp_driver_rmt/include/driver"
"${IDF_PATH}/components/esp_driver_rmt/include" "${IDF_PATH}/components/esp_driver_rmt/include"
"${original_driver_dir}/i2c/include/driver" "${original_driver_dir}/i2c/include/driver"
"${original_driver_dir}/usb_serial_jtag/include/driver" "${IDF_PATH}/components/esp_driver_usb_serial_jtag/include/driver"
"${original_driver_dir}/i2c/include" "${original_driver_dir}/i2c/include"
"${original_driver_dir}/usb_serial_jtag/include") "${IDF_PATH}/components/esp_driver_usb_serial_jtag/include")
# Note: "hal" and "soc" are only required for corresponding header files and their definitions # Note: "hal" and "soc" are only required for corresponding header files and their definitions
# here, they don't provide functionality when built for running on the host. # here, they don't provide functionality when built for running on the host.
@ -29,4 +29,4 @@ idf_component_mock(INCLUDE_DIRS ${include_dirs}
${IDF_PATH}/components/esp_driver_rmt/include/driver/rmt_common.h ${IDF_PATH}/components/esp_driver_rmt/include/driver/rmt_common.h
${IDF_PATH}/components/esp_driver_rmt/include/driver/rmt_encoder.h ${IDF_PATH}/components/esp_driver_rmt/include/driver/rmt_encoder.h
${original_driver_dir}/i2c/include/driver/i2c.h ${original_driver_dir}/i2c/include/driver/i2c.h
${original_driver_dir}/usb_serial_jtag/include/driver/usb_serial_jtag.h) ${IDF_PATH}/components/esp_driver_usb_serial_jtag/include/driver/usb_serial_jtag.h)