Skip to content

Commit 1ef9839

Browse files
committed
feat: Add UART support for slip frame receive
1 parent dc140ac commit 1ef9839

File tree

5 files changed

+32
-6
lines changed

5 files changed

+32
-6
lines changed

esp-stub-lib

Submodule esp-stub-lib updated 139 files

src/command_handler.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include <stdint.h>
77
#include <string.h>
88
#include <stdbool.h>
9-
#include "target/soc_utils.h"
9+
#include <esp-stub-lib/soc_utils.h>
1010
#include "slip.h"
1111
#include "commands.h"
1212
#include "command_handler.h"

src/command_handler.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
extern "C" {
1414
#endif
1515

16-
// 0x4000 is the maximum data size sent by esptool, so keeping for the compatibility
17-
#define ESPTOOL_MAX_DATA_SIZE 0x4000U
16+
// 0x4000 plus 0xFF is the maximum data size sent by esptool (WRITE_FLASH command), so keeping for the compatibility
17+
#define ESPTOOL_MAX_DATA_SIZE (0x4000U + 0xFFU)
1818
#define HEADER_SIZE 8U
1919
#define MAX_COMMAND_SIZE (HEADER_SIZE + ESPTOOL_MAX_DATA_SIZE)
2020

src/main.c

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55
*/
66

77
#include <stddef.h>
8+
#include <stdbool.h>
9+
#include <stdint.h>
810
#include <esp-stub-lib/flash.h>
11+
#include <esp-stub-lib/uart.h>
12+
#include <target/uart.h>
913
#include "slip.h"
1014
#include "command_handler.h"
1115

@@ -19,7 +23,25 @@ __asm__(
1923
"j esp_main;");
2024
#endif //ESP8266
2125

22-
static uint8_t s_command_buffer[MAX_COMMAND_SIZE] __attribute__((aligned(4)));
26+
static void uart_rx_interrupt_handler()
27+
{
28+
// This also resets the interrupt flags
29+
uint32_t intr_flags = stub_lib_uart_get_intr_flags(UART_NUM_0);
30+
31+
if ((intr_flags & UART_INTR_RXFIFO_FULL) || (intr_flags & UART_INTR_RXFIFO_TOUT)) {
32+
uint32_t count = stub_lib_uart_get_rxfifo_count(UART_NUM_0);
33+
34+
for (uint32_t i = 0; i < count; i++) {
35+
uint8_t byte = stub_lib_uart_read_rxfifo_byte(UART_NUM_0);
36+
stub_lib_uart_tx_one_char(byte);
37+
slip_recv_byte(byte);
38+
39+
if (slip_is_frame_complete() || slip_is_frame_error()) {
40+
break;
41+
}
42+
}
43+
}
44+
}
2345

2446
void esp_main(void)
2547
{
@@ -34,6 +56,10 @@ void esp_main(void)
3456
void *flash_state = NULL;
3557
stub_lib_flash_init(&flash_state);
3658

59+
stub_lib_uart_wait_idle(UART_NUM_0);
60+
stub_lib_uart_init(UART_NUM_0, 115200);
61+
stub_lib_uart_rominit_intr_attach(UART_NUM_0, 5, uart_rx_interrupt_handler, UART_INTR_RXFIFO_FULL | UART_INTR_RXFIFO_TOUT);
62+
3763
// Send OHAI greeting to signal stub is active
3864
const uint8_t greeting[4] = {'O', 'H', 'A', 'I'};
3965
slip_send_frame(&greeting, sizeof(greeting));

src/slip.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66

77
#include <stdint.h>
8-
#include <esp-stub-lib/rom_wrappers.h>
8+
#include <esp-stub-lib/uart.h>
99
#include "command_handler.h"
1010
#include "slip.h"
1111

0 commit comments

Comments
 (0)