Skip to content

Commit

Permalink
Merge branch 'update/add_esp_vfs_console_component' into 'master'
Browse files Browse the repository at this point in the history
fix(esp_vfs_console): add esp_vfs_console component

Closes IDFGH-11900

See merge request espressif/esp-idf!28655
  • Loading branch information
RathiSonika committed Mar 12, 2024
2 parents eeb71ca + e162903 commit a7d1da9
Show file tree
Hide file tree
Showing 17 changed files with 159 additions and 149 deletions.
2 changes: 1 addition & 1 deletion components/console/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ idf_component_register(SRCS ${srcs}
${argtable_srcs}
INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}
PRIV_INCLUDE_DIRS private_include
REQUIRES vfs
REQUIRES vfs esp_vfs_console
PRIV_REQUIRES esp_driver_uart
esp_driver_usb_serial_jtag
)
Expand Down
27 changes: 27 additions & 0 deletions components/esp_driver_uart/include/driver/esp_private/uart_vfs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/

#pragma once

#include "esp_vfs.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
* @brief get pointer of uart vfs.
*
* This function is called in vfs_console in order to get the vfs implementation
* of uart.
*
* @return pointer to structure esp_vfs_t
*/
const esp_vfs_t *esp_vfs_uart_get_vfs(void);

#ifdef __cplusplus
}
#endif
10 changes: 7 additions & 3 deletions components/esp_driver_uart/src/uart_vfs.c
Original file line number Diff line number Diff line change
@@ -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
*/
Expand All @@ -19,7 +19,6 @@
#include "esp_rom_uart.h"
#include "hal/uart_ll.h"
#include "soc/soc_caps.h"
#include "esp_private/esp_vfs_console.h"
#include "esp_vfs_dev.h" // Old headers for the aliasing functions
#include "esp_private/startup_internal.h"

Expand Down Expand Up @@ -1010,6 +1009,11 @@ static const esp_vfs_t uart_vfs = {
#endif // CONFIG_VFS_SUPPORT_TERMIOS
};

const esp_vfs_t *esp_vfs_uart_get_vfs(void)
{
return &uart_vfs;
}

void uart_vfs_dev_register(void)
{
ESP_ERROR_CHECK(esp_vfs_register("/dev/uart", &uart_vfs, NULL));
Expand Down Expand Up @@ -1074,7 +1078,7 @@ void uart_vfs_dev_use_driver(int uart_num)
#if CONFIG_ESP_CONSOLE_UART
ESP_SYSTEM_INIT_FN(init_vfs_uart, CORE, BIT(0), 110)
{
esp_vfs_set_primary_dev_vfs_def_struct(&uart_vfs);
uart_vfs_dev_register();
return ESP_OK;
}
#endif
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/

#pragma once

#include "esp_vfs.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
* @brief get pointer of usb_serial_jtag vfs.
*
* This function is called in vfs_console in order to get the vfs implementation
* of usb_serial_jtag.
*
* @return pointer to structure esp_vfs_t
*/
const esp_vfs_t *esp_vfs_usb_serial_jtag_get_vfs(void);

#ifdef __cplusplus
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include "esp_vfs.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_log.h"
#include "sdkconfig.h"
Expand Down Expand Up @@ -395,15 +394,16 @@ esp_err_t usb_serial_jtag_vfs_register(void)
#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);
usb_serial_jtag_vfs_register();
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);
// "/dev/seccondary_usb_serial_jtag" unfortunately is too long for vfs
esp_vfs_register("/dev/secondary", &usj_vfs, NULL);
return ESP_OK;
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion components/esp_system/system_init_fn.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ CORE: 105: init_newlib_time in components/esp_system/startup_funcs.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/esp_vfs_console/vfs_console.c on BIT(0)
CORE: 115: init_newlib_stdio in components/newlib/newlib_init.c on BIT(0)

CORE: 120: init_pthread in components/pthread/pthread.c on BIT(0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ TEST_CASE_MULTIPLE_STAGES("reset reason ESP_RST_BROWNOUT after brownout event",
#include "xt_instr_macros.h"
#include "xtensa/config/specreg.h"

static int size_stack = 1024 * 3;
static int size_stack = 1024 * 4;
static StackType_t *start_addr_stack;

static int fibonacci(int n, void* func(void))
Expand Down
22 changes: 22 additions & 0 deletions components/esp_vfs_console/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
idf_build_get_property(target IDF_TARGET)

if(${target} STREQUAL "linux")
return() # This component is not supported by the POSIX/Linux simulator
endif()

set(srcs "vfs_console.c")

idf_component_register(SRCS ${srcs}
INCLUDE_DIRS include
PRIV_REQUIRES vfs esp_driver_uart esp_driver_usb_serial_jtag
)

if(CONFIG_ESP_CONSOLE_USB_CDC)
target_sources(${COMPONENT_LIB} PRIVATE "vfs_cdcacm.c")
endif()

if(CONFIG_VFS_SUPPORT_IO)
target_link_libraries(${COMPONENT_LIB} PUBLIC idf::vfs)
# Make sure esp_vfs_console_register gets called at startup stage
target_link_libraries(${COMPONENT_LIB} INTERFACE "-u esp_vfs_include_console_register")
endif()
27 changes: 27 additions & 0 deletions components/esp_vfs_console/include/esp_private/esp_vfs_cdcacm.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/

#pragma once

#include "esp_vfs.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
* @brief get pointer of cdcacm vfs.
*
* This function is called in vfs_console in order to get the vfs implementation
* of cdcacm.
*
* @return pointer to structure esp_vfs_t
*/
const esp_vfs_t *esp_vfs_cdcacm_get_vfs(void);

#ifdef __cplusplus
}
#endif
Original file line number Diff line number Diff line change
@@ -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
*/
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ static ssize_t cdcacm_read(int fd, void *data, size_t size)
xSemaphoreTake(s_rx_semaphore, portMAX_DELAY);
}


if (s_rx_mode == ESP_LINE_ENDINGS_CR || s_rx_mode == ESP_LINE_ENDINGS_LF) {
/* This is easy. Just receive, and if needed replace \r by \n. */
received = esp_usb_console_read_buf(data_c, size);
Expand Down Expand Up @@ -266,7 +265,6 @@ static int cdcacm_disable_blocking(void)
return 0;
}


static int cdcacm_fcntl(int fd, int cmd, int arg)
{
assert(fd == 0);
Expand Down
Loading

0 comments on commit a7d1da9

Please sign in to comment.