Skip to content

Conversation

@radimkarnis
Copy link
Member

@radimkarnis radimkarnis commented Dec 5, 2025

Description

  • Adds transport layer selection support (ready for USB-OTG expansion)
  • Adds USB-Serial/JTAG suport

Related

Testing

  • ESP32-C3 both in UART and USB-Serial/JTAG modes works

TODOs

  • Update esp-stub-lib when support for other targets is added
  • Fix failing ESP8266 build

@github-actions
Copy link

github-actions bot commented Dec 5, 2025

Messages
📖 🎉 Good Job! All checks are passing!

👋 Hello radimkarnis, we appreciate your contribution to this project!


Click to see more instructions ...


This automated output is generated by the PR linter DangerJS, which checks if your Pull Request meets the project's requirements and helps you fix potential issues.

DangerJS is triggered with each push event to a Pull Request and modify the contents of this comment.

Please consider the following:
- Danger mainly focuses on the PR structure and formatting and can't understand the meaning behind your code or changes.
- Danger is not a substitute for human code reviews; it's still important to request a code review from your colleagues.
- To manually retry these Danger checks, please navigate to the Actions tab and re-run last Danger workflow.

Review and merge process you can expect ...


We do welcome contributions in the form of bug reports, feature requests and pull requests.

1. An internal issue has been created for the PR, we assign it to the relevant engineer.
2. They review the PR and either approve it or ask you for changes or clarifications.
3. Once the GitHub PR is approved we do the final review, collect approvals from core owners and make sure all the automated tests are passing.
- At this point we may do some adjustments to the proposed change, or extend it by adding tests or documentation.
4. If the change is approved and passes the tests it is merged into the default branch.

Generated by 🚫 dangerJS against c69f5f9

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces transport layer abstraction to support multiple communication interfaces (UART and USB-Serial/JTAG). The changes enable the stub to automatically detect and configure the appropriate transport layer at runtime.

  • Adds transport layer abstraction with runtime selection between UART and USB-Serial/JTAG
  • Implements USB-Serial/JTAG interrupt handler alongside existing UART handler
  • Refactors SLIP layer to use configurable TX function pointer instead of hardcoded UART calls

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/transport.h Declares transport initialization and interrupt handler interfaces
src/transport.c Implements transport detection logic and configures interrupt handlers for both UART and USB-Serial/JTAG
src/slip.h Adds public API for registering transport-specific TX functions
src/slip.c Replaces direct UART calls with configurable function pointer
src/main.c Refactors to use new transport abstraction by removing UART-specific initialization
src/CMakeLists.txt Adds transport.c to build
esp-stub-lib Updates submodule to version with USB-Serial/JTAG support

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

stub_lib_usb_serial_jtag_get_intr_flags();

while (stub_lib_usb_serial_jtag_is_data_available()) {
slip_recv_byte(stub_lib_usb_serial_jtag_read_rxfifo_byte());
Copy link

Copilot AI Dec 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The USB-Serial/JTAG interrupt handler processes all available bytes without checking for frame completion or errors. This differs from the UART handler (lines 21-29) which breaks on slip_is_frame_complete() or slip_is_frame_error(). This inconsistency could lead to buffer overflow or incorrect frame processing. Add the same frame completion check as in the UART handler.

Suggested change
slip_recv_byte(stub_lib_usb_serial_jtag_read_rxfifo_byte());
slip_recv_byte(stub_lib_usb_serial_jtag_read_rxfifo_byte());
// Cannot process more bytes until frame is processed
if (slip_is_frame_complete() || slip_is_frame_error()) {
break;
}

Copilot uses AI. Check for mistakes.
void stub_transport_init(void)
{
if (stub_lib_usb_serial_jtag_is_active()) {
stub_lib_usb_serial_jtag_rominit_intr_attach(17, usb_jtag_serial_interrupt_handler, USB_SERIAL_JTAG_SERIAL_OUT_RECV_PKT_INT_ENA);
Copy link

Copilot AI Dec 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The magic number 17 for the interrupt number should be defined as a named constant (e.g., USB_SERIAL_JTAG_INTR_NUM) to improve code clarity and maintainability, similar to how UART_NUM_0 and 5 are used for UART configuration.

Copilot uses AI. Check for mistakes.
slip_set_tx_fn(stub_lib_usb_serial_jtag_tx_one_char);
} else {
stub_lib_uart_wait_idle(UART_NUM_0); // Wait until ROM sends response to last command
stub_lib_uart_rominit_intr_attach(UART_NUM_0, 5, uart_rx_interrupt_handler, UART_INTR_RXFIFO_FULL | UART_INTR_RXFIFO_TOUT);
Copy link

Copilot AI Dec 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The magic number 5 for the UART interrupt number should be defined as a named constant (e.g., UART_INTR_NUM) to improve code clarity and maintainability.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants