-
Notifications
You must be signed in to change notification settings - Fork 0
feat(transport): Add USB-Serial/JTAG and transport layer selection support #29
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
Merged
+148
−42
Merged
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
Submodule esp-stub-lib
updated
76 files
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
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
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
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
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
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,67 @@ | ||
| /* | ||
| * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 OR MIT | ||
| */ | ||
|
|
||
| #include <stdint.h> | ||
| #include <esp-stub-lib/uart.h> | ||
| #include <esp-stub-lib/usb_serial_jtag.h> | ||
| #include "transport.h" | ||
| #include "slip.h" | ||
|
|
||
| void uart_rx_interrupt_handler() | ||
| { | ||
| // This also resets the interrupt flags | ||
| uint32_t intr_flags = stub_lib_uart_clear_intr_flags(UART_NUM_0); | ||
|
|
||
| if ((intr_flags & UART_INTR_RXFIFO_FULL) || (intr_flags & UART_INTR_RXFIFO_TOUT)) { | ||
| uint32_t count = stub_lib_uart_get_rxfifo_count(UART_NUM_0); | ||
|
|
||
| for (uint32_t i = 0; i < count; ++i) { | ||
| uint8_t byte = stub_lib_uart_read_rxfifo_byte(UART_NUM_0); | ||
| slip_recv_byte(byte); | ||
|
|
||
| // Cannot process more bytes until frame is processed | ||
| if (slip_is_frame_complete() || slip_is_frame_error()) { | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| void usb_jtag_serial_interrupt_handler() | ||
| { | ||
| stub_lib_usb_serial_jtag_clear_intr_flags(); | ||
|
|
||
| while (stub_lib_usb_serial_jtag_is_data_available()) { | ||
| slip_recv_byte(stub_lib_usb_serial_jtag_read_rxfifo_byte()); | ||
| } | ||
| } | ||
|
|
||
| uint8_t usb_serial_jtag_tx_one_char(uint8_t c) | ||
| { | ||
| // Flush every 63 bytes (some Windows drivers have issues with >= 64 bytes) | ||
| // or when a frame delimiter is sent | ||
| // TODO: Proper fix with zero-length packets | ||
| static unsigned short transferred_without_flush = 0; | ||
| stub_lib_usb_serial_jtag_tx_one_char(c); | ||
| ++transferred_without_flush; | ||
| if (c == SLIP_END || transferred_without_flush >= 63) { | ||
| stub_lib_usb_serial_jtag_tx_flush(); | ||
| transferred_without_flush = 0; | ||
| } | ||
| return 0; | ||
| } | ||
|
|
||
| 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_OUT_RECV_PKT_INT_ENA); | ||
| slip_set_tx_fn(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); | ||
radimkarnis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| slip_set_tx_fn(stub_lib_uart_tx_one_char); | ||
| } | ||
| } | ||
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,39 @@ | ||
| /* | ||
| * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 OR MIT | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <stdint.h> | ||
| #include <stddef.h> | ||
| #include <stdbool.h> | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" { | ||
| #endif | ||
|
|
||
| /** | ||
| * @brief Initialize the transport layer | ||
| */ | ||
| void stub_transport_init(void); | ||
|
|
||
| /** | ||
| * @brief UART interrupt handler | ||
| */ | ||
| void uart_rx_interrupt_handler(); | ||
|
|
||
| /** | ||
| * @brief USB-Serial/JTAG interrupt handler | ||
| */ | ||
| void usb_jtag_serial_interrupt_handler(); | ||
|
|
||
| /** | ||
| * @brief USB-Serial/JTAG transmit one character | ||
| */ | ||
| uint8_t usb_serial_jtag_tx_one_char(uint8_t c); | ||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif |
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
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
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.