Merge branch 'release/v0.1.3-release'
This commit is contained in:
commit
e2ae719a3e
|
@ -10,18 +10,18 @@ jobs:
|
|||
runs-on: ubuntu-18.04
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
submodules: recursive
|
||||
|
||||
- name: before_install
|
||||
run: |
|
||||
sudo apt update
|
||||
sudo apt install -y gcc git wget make libncurses-dev flex bison python python-serial ninja-build
|
||||
sudo apt install -y gcc git wget make libncurses-dev flex bison python python-setuptools python-serial ninja-build
|
||||
wget https://dl.espressif.com/dl/xtensa-lx106-elf-linux64-1.22.0-100-ge567ec7-5.2.0.tar.gz
|
||||
|
||||
- name: install
|
||||
run: |
|
||||
tar -xzf ./xtensa-lx106-elf-linux64-1.22.0-100-ge567ec7-5.2.0.tar.gz
|
||||
wget https://github.com/espressif/ESP8266_RTOS_SDK/releases/download/v3.3-rc1/ESP8266_RTOS_SDK-v3.3-rc1.zip
|
||||
unzip ESP8266_RTOS_SDK-v3.3-rc1.zip
|
||||
python -m pip install --user -r ./ESP8266_RTOS_SDK/requirements.txt
|
||||
|
||||
- name: script
|
||||
|
@ -41,6 +41,13 @@ jobs:
|
|||
echo "::set-output name=release_tag::UserBuild_$(date +"%Y.%m.%d_%H-%M")"
|
||||
echo "::set-output name=status::success"
|
||||
|
||||
- name: Merge bin files
|
||||
if: steps.tag.outputs.status == 'success' && !cancelled()
|
||||
run: |
|
||||
git clone https://github.com/espressif/esptool.git
|
||||
./esptool/esptool.py --chip esp8266 merge_bin -o build/esp8266_dap_full.bin 0x0 build/bootloader/bootloader.bin 0x8000 build/partition_table/partition-table.bin 0x10000 build/esp8266_dap.bin
|
||||
mv build/esp8266_dap.bin build/esp8266_dap_app.bin
|
||||
|
||||
- name: Release user firmware
|
||||
uses: softprops/action-gh-release@v1
|
||||
if: steps.tag.outputs.status == 'success' && !cancelled()
|
||||
|
@ -48,5 +55,9 @@ jobs:
|
|||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
tag_name: ${{ steps.tag.outputs.release_tag }}
|
||||
files: ${{ env.FIRMWARE }}/esp8266_dap.bin
|
||||
files: |
|
||||
${{ env.FIRMWARE }}/esp8266_dap_full.bin
|
||||
${{ env.FIRMWARE }}/esp8266_dap_app.bin
|
||||
${{ env.FIRMWARE }}/bootloader/bootloader.bin
|
||||
${{ env.FIRMWARE }}/partition_table/partition-table.bin
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
.vscode/
|
||||
build/
|
||||
tmp/
|
||||
tmp/
|
||||
.history/
|
|
@ -0,0 +1,3 @@
|
|||
[submodule "ESP8266_RTOS_SDK"]
|
||||
path = ESP8266_RTOS_SDK
|
||||
url = https://github.com/espressif/ESP8266_RTOS_SDK
|
|
@ -1,9 +1,6 @@
|
|||
# The following five lines of boilerplate have to be in your project's
|
||||
# CMakeLists in this exact order for cmake to work correctly
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
#set(COMPONENT_DIRS "${IDF_PATH}/components ${PROJECT_PATH}/components")
|
||||
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/main)
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||
project(esp8266_dap)
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Subproject commit 1be2289fcd68672f5d6bf6aafa4f4b57b20527a4
|
9
Makefile
9
Makefile
|
@ -1,9 +0,0 @@
|
|||
#
|
||||
# This is a project Makefile. It is assumed the directory this Makefile resides in is a
|
||||
# project subdirectory.
|
||||
#
|
||||
|
||||
PROJECT_NAME := tcp_server
|
||||
|
||||
include $(IDF_PATH)/make/project.mk
|
||||
|
19
README.md
19
README.md
|
@ -1,4 +1,4 @@
|
|||
<p align="center"><img src="https://user-images.githubusercontent.com/17078589/107881245-7d7d5580-6f1e-11eb-9f66-6ac589e5f95c.png"/></p>
|
||||
<p align="center"><img src="https://user-images.githubusercontent.com/17078589/120061980-49274280-c092-11eb-9916-4965f6c48388.png"/></p>
|
||||
|
||||

|
||||
|
||||
|
@ -17,7 +17,7 @@ Realized by USBIP and CMSIS-DAP protocol stack.
|
|||
|
||||
> 👉 5m distance, 100kb size firmware(Hex) flash test:
|
||||
|
||||
<p align="center"><img src="https://user-images.githubusercontent.com/17078589/107896674-e5a95700-6f71-11eb-90f7-bf7362045537.gif"/></p>
|
||||
<p align="center"><img src="https://user-images.githubusercontent.com/17078589/120925694-4bca0d80-c70c-11eb-91b7-ffa54770faea.gif"/></p>
|
||||
|
||||
## Feature
|
||||
|
||||
|
@ -49,6 +49,10 @@ The default connected WIFI SSID is `DAP` , password `12345678`
|
|||
|
||||
You can change `WIFI_SSID` and ` WIFI_PASS` in [wifi_configuration.h](main/wifi_configuration.h)
|
||||
|
||||
You can also specify your IP in the above file (We recommend using the static address binding feature of the router).
|
||||
|
||||

|
||||
|
||||
### Debugger
|
||||
|
||||
|
||||
|
@ -57,8 +61,7 @@ You can change `WIFI_SSID` and ` WIFI_PASS` in [wifi_configuration.h](main/wifi_
|
|||
| SWD | |
|
||||
|----------------|--------|
|
||||
| SWCLK | GPIO14 |
|
||||
| SWDIO | GPIO12 |
|
||||
| SWDIO_MOSI | GPIO13 |
|
||||
| SWDIO | GPIO13 |
|
||||
| LED\_CONNECTED | GPIO2 |
|
||||
| LED\_RUNNING | GPIO15 |
|
||||
| TVCC | 3V3 |
|
||||
|
@ -184,7 +187,7 @@ When you select max clock, we will take the following actions:
|
|||
|
||||
1. Use WinUSB Mode(enabled by default):
|
||||
|
||||
change `USE_WINUSB` macor in [USBd_config.h](components/USBIP/USBd_config.h)
|
||||
change `USE_WINUSB` macor in [dap_configuration.h](main/dap_configuration.h)
|
||||
|
||||
|
||||
|
||||
|
@ -234,9 +237,9 @@ Credits to the following project, people and organizations:
|
|||
> - https://github.com/cezanne/usbip-win for usbip windows
|
||||
|
||||
|
||||
- @HeavenSpree
|
||||
- @Zy19930907
|
||||
- @caiguang1997
|
||||
- [@HeavenSpree](https://www.github.com/HeavenSpree)
|
||||
- [@Zy19930907](https://www.github.com/Zy19930907)
|
||||
- [@caiguang1997](https://www.github.com/caiguang1997)
|
||||
|
||||
|
||||
## License
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
set(COMPONENT_ADD_INCLUDEDIRS "config include $ENV{IDF_PATH}/components/esp8266/include/esp8266/ $ENV{IDF_PATH}//components/esp_ringbuf/include/")
|
||||
set(COMPONENT_ADD_INCLUDEDIRS "config include $ENV{IDF_PATH}/components/esp8266/include/esp8266/ $ENV{IDF_PATH}/components/esp_ringbuf/include/")
|
||||
set(COMPONENT_SRCS "./source/DAP.c ./source/DAP_vendor.c ./source/JTAG_DP.c ./source/SW_DP.c ./source/SWO.c ./source/uart_modify.c ./source/spi_op.c ./source/spi_switch.c ./source/dap_utility.c")
|
||||
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -273,8 +273,8 @@ extern void SWO_TransferComplete (void);
|
|||
extern uint32_t UART_SWO_Mode (uint32_t enable);
|
||||
extern uint32_t UART_SWO_Baudrate (uint32_t baudrate);
|
||||
extern uint32_t UART_SWO_Control (uint32_t active);
|
||||
extern void UART_SWO_Capture (uint8_t *buf, uint32_t num);
|
||||
extern uint32_t UART_SWO_GetCount (void);
|
||||
// extern void UART_SWO_Capture (uint8_t *buf, uint32_t num);
|
||||
// extern uint32_t UART_SWO_GetCount (void);
|
||||
|
||||
extern uint32_t Manchester_SWO_Mode (uint32_t enable);
|
||||
extern uint32_t Manchester_SWO_Baudrate (uint32_t baudrate);
|
||||
|
|
|
@ -2,13 +2,13 @@
|
|||
#define __CMSIS_COMPILER_H__
|
||||
|
||||
#ifndef __STATIC_FORCEINLINE
|
||||
#define __STATIC_FORCEINLINE static inline __attribute__((always_inline))
|
||||
#define __STATIC_FORCEINLINE static inline __attribute__((always_inline))
|
||||
#endif
|
||||
#ifndef __STATIC_INLINE
|
||||
#define __STATIC_INLINE static inline __attribute__((always_inline))
|
||||
#endif
|
||||
#ifndef __FORCEINLINE
|
||||
#define __FORCEINLINE inline __attribute__((always_inline))
|
||||
#define __FORCEINLINE inline __attribute__((always_inline))
|
||||
#endif
|
||||
#ifndef __WEAK
|
||||
#define __WEAK __attribute__((weak))
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include <stdint.h>
|
||||
|
||||
#ifndef __STATIC_FORCEINLINE
|
||||
#define __STATIC_FORCEINLINE static inline __attribute__((always_inline))
|
||||
#define __STATIC_FORCEINLINE static inline __attribute__((always_inline))
|
||||
#endif
|
||||
#ifndef __STATIC_INLINE
|
||||
#define __STATIC_INLINE static inline __attribute__((always_inline))
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
#ifndef __GPIO_OP_H__
|
||||
#define __GPIO_OP_H__
|
||||
|
||||
#include "cmsis_compiler.h"
|
||||
#include "components/DAP/include/cmsis_compiler.h"
|
||||
|
||||
#include "gpio.h"
|
||||
#include "gpio_struct.h"
|
||||
#include "timer_struct.h"
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
#ifndef __SWO_H__
|
||||
#define __SWO_H__
|
||||
|
||||
typedef void * EventGroupHandle_t;
|
||||
|
||||
// event group bits
|
||||
#define SWO_GOT_DATA 0x00000001
|
||||
#define UART_GOT_DATA 0x00000002
|
||||
#define SWO_ERROR_TIME_OUT 0x00000004
|
||||
|
||||
extern EventGroupHandle_t kSwoThreadEventGroup;
|
||||
extern volatile uint8_t kSwoTransferBusy;
|
||||
|
||||
|
||||
void SetTraceError(uint8_t flag); // Use in the uart handler
|
||||
|
||||
#endif
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
* @brief Made some simple modifications to the official UART
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
// Copyright 2018-2025 Espressif Systems (Shanghai) PTE LTD
|
||||
|
@ -27,7 +27,15 @@ extern "C" {
|
|||
|
||||
#include "esp_err.h"
|
||||
#include "esp_log.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/queue.h"
|
||||
#include "freertos/semphr.h"
|
||||
|
||||
// SWO modify
|
||||
extern volatile uint32_t kSWO_read_index;
|
||||
extern volatile uint32_t kSWO_read_num;
|
||||
extern volatile uint8_t kSWO_uart_notify_enable;
|
||||
extern SemaphoreHandle_t kSWO_read_mux;
|
||||
|
||||
#define UART_FIFO_LEN (128) /*!< Length of the hardware FIFO buffers */
|
||||
#define UART_INTR_MASK 0x1ff /*!< Mask of all UART interrupts */
|
||||
|
@ -428,7 +436,7 @@ esp_err_t my_uart_intr_config(uart_port_t uart_num, uart_intr_config_t *uart_int
|
|||
* @param uart_queue UART event queue handle (out param). On success, a new queue handle is written here to provide
|
||||
* access to UART events. If set to NULL, driver will not use an event queue.
|
||||
* @param no_use Invalid parameters, just to fit some modules.
|
||||
*
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
|
@ -558,6 +566,30 @@ esp_err_t my_uart_get_buffered_data_len(uart_port_t uart_num, size_t *size);
|
|||
*/
|
||||
esp_err_t my_uart_set_rx_timeout(uart_port_t uart_num, const uint8_t tout_thresh);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Asynchronously read bytes to swo buffer
|
||||
* @note This function only serves as a notification,
|
||||
* and will initiate a callback when the buffer reaches the length since we modify the uart
|
||||
* @param index buffer index to read
|
||||
* @param length data length
|
||||
* @return esp_err_t
|
||||
* - ESP_OK Success
|
||||
* - ESP_FAIL There are still unfinished requests
|
||||
*/
|
||||
esp_err_t my_uart_read_bytes_async_swo(uint32_t index, uint32_t length);
|
||||
|
||||
|
||||
/**
|
||||
* @brief UART get RX ring buffer cached data length
|
||||
* @note This function is basically equivalent to \ref my_uart_get_buffered_data_len
|
||||
* @param uart_num UART port number.
|
||||
*
|
||||
* @return data length
|
||||
*/
|
||||
int my_uart_get_rx_buffered_data_len(uart_port_t uart_num);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -26,10 +26,10 @@
|
|||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#include <string.h>
|
||||
#include "DAP_config.h"
|
||||
#include "DAP.h"
|
||||
|
||||
#include "spi_switch.h"
|
||||
#include "components/DAP/config/DAP_config.h"
|
||||
#include "components/DAP/include/DAP.h"
|
||||
#include "components/DAP/include/spi_switch.h"
|
||||
|
||||
|
||||
#if (DAP_PACKET_SIZE < 64U)
|
||||
|
@ -385,10 +385,15 @@ static uint32_t DAP_SWJ_Clock(const uint8_t *request, uint8_t *response) {
|
|||
|
||||
// clock >= 10MHz -> use 40MHz SPI
|
||||
if (clock >= 10000000) {
|
||||
DAP_SPI_Init();
|
||||
if (DAP_Data.debug_port != DAP_PORT_JTAG) {
|
||||
DAP_SPI_Init();
|
||||
SWD_TransferSpeed = kTransfer_SPI;
|
||||
} else {
|
||||
SWD_TransferSpeed = kTransfer_GPIO_fast;
|
||||
}
|
||||
DAP_Data.fast_clock = 1U;
|
||||
DAP_Data.clock_delay = 1U;
|
||||
SWD_TransferSpeed = kTransfer_SPI;
|
||||
|
||||
} else if (clock >= 2000000) {
|
||||
// clock >= 2MHz -> Use GPIO with no program delay
|
||||
DAP_SPI_Deinit();
|
||||
|
|
|
@ -24,18 +24,18 @@
|
|||
* Title: DAP_vendor.c CMSIS-DAP Vendor Commands
|
||||
*
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "DAP_config.h"
|
||||
#include "DAP.h"
|
||||
|
||||
#include "components/DAP/config/DAP_config.h"
|
||||
#include "components/DAP/include/DAP.h"
|
||||
|
||||
//**************************************************************************************************
|
||||
/**
|
||||
/**
|
||||
\defgroup DAP_Vendor_Adapt_gr Adapt Vendor Commands
|
||||
\ingroup DAP_Vendor_gr
|
||||
\ingroup DAP_Vendor_gr
|
||||
@{
|
||||
|
||||
The file DAP_vendor.c provides template source code for extension of a Debug Unit with
|
||||
Vendor Commands. Copy this file to the project folder of the Debug Unit and add the
|
||||
The file DAP_vendor.c provides template source code for extension of a Debug Unit with
|
||||
Vendor Commands. Copy this file to the project folder of the Debug Unit and add the
|
||||
file to the MDK-ARM project under the file group Configuration.
|
||||
*/
|
||||
|
||||
|
|
|
@ -25,8 +25,8 @@
|
|||
*
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "DAP_config.h"
|
||||
#include "DAP.h"
|
||||
#include "components/DAP/config/DAP_config.h"
|
||||
#include "components/DAP/include/DAP.h"
|
||||
|
||||
|
||||
// JTAG Macros
|
||||
|
|
|
@ -1,6 +1,14 @@
|
|||
/**
|
||||
* @brief Modify this file to fit esp8266 Uart
|
||||
*
|
||||
* @file SWO.c
|
||||
* @author windowsair
|
||||
* @brief SWO support
|
||||
* @change: 2021-02-17: Add basic functions
|
||||
* @version 0.2
|
||||
*
|
||||
* @date 2021-02-17
|
||||
*
|
||||
* @copyright Copyright (c) 2021
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
|
@ -30,22 +38,18 @@
|
|||
*
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "DAP_config.h"
|
||||
#include "DAP.h"
|
||||
#include "components/DAP/config/DAP_config.h"
|
||||
#include "components/DAP/include/DAP.h"
|
||||
#include "components/DAP/include/uart_modify.h"
|
||||
#include "components/DAP/include/swo.h"
|
||||
|
||||
#include "esp_err.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/event_groups.h"
|
||||
#include "uart_modify.h"
|
||||
|
||||
|
||||
EventGroupHandle_t kSWO_Thread_event_group;
|
||||
EventGroupHandle_t kUART_Monitoe_event_group;
|
||||
#define SWO_GOT_DATA BIT0
|
||||
#define SWO_ERROR_TIME_OUT BIT1
|
||||
|
||||
#define UART_GOT_DATA BIT0
|
||||
EventGroupHandle_t kSwoThreadEventGroup;
|
||||
|
||||
|
||||
#if (SWO_STREAM != 0)
|
||||
|
@ -61,14 +65,14 @@ EventGroupHandle_t kUART_Monitoe_event_group;
|
|||
#endif
|
||||
|
||||
|
||||
|
||||
// use in baudrate setting
|
||||
static uint8_t USART_Ready = 0U;
|
||||
|
||||
#endif /* (SWO_UART != 0) */
|
||||
|
||||
#if ((SWO_UART != 0) || (SWO_MANCHESTER != 0))
|
||||
|
||||
#define SWO_STREAM_TIMEOUT (50 / portTICK_RATE_MS) /* Stream timeout in ms */
|
||||
#define SWO_STREAM_TIMEOUT pdMS_TO_TICKS(50) /* Stream timeout in ms */
|
||||
|
||||
#define USB_BLOCK_SIZE 512U /* USB Block Size */
|
||||
#define TRACE_BLOCK_SIZE 64U /* Trace Block Size (2^n: 32...512) */
|
||||
|
@ -81,7 +85,7 @@ static uint8_t TraceError[2] = {0U, 0U}; /* Trace Error flags (banked) */
|
|||
static uint8_t TraceError_n = 0U; /* Active Trace Error bank */
|
||||
|
||||
// Trace Buffer
|
||||
static uint8_t TraceBuf[SWO_BUFFER_SIZE]; /* Trace Buffer (must be 2^n) */
|
||||
static uint8_t kSwoTraceBuf[SWO_BUFFER_SIZE]; /* Trace Buffer (must be 2^n) */
|
||||
static volatile uint32_t TraceIndexI = 0U; /* Incoming Trace Index */
|
||||
static volatile uint32_t TraceIndexO = 0U; /* Outgoing Trace Index */
|
||||
static volatile uint8_t TraceUpdate; /* Trace Update Flag */
|
||||
|
@ -101,105 +105,35 @@ static void ClearTrace(void);
|
|||
static void ResumeTrace(void);
|
||||
static uint32_t GetTraceCount(void);
|
||||
static uint8_t GetTraceStatus(void);
|
||||
void SetTraceError(uint8_t flag);
|
||||
|
||||
#if (SWO_STREAM != 0)
|
||||
|
||||
static volatile uint8_t TransferBusy = 0U; /* Transfer Busy Flag */
|
||||
static uint32_t TransferSize; /* Current Transfer Size */
|
||||
volatile uint8_t kSwoTransferBusy = 0U; /* Transfer Busy Flag */
|
||||
static uint32_t TransferSize; /* Current Transfer Size */
|
||||
#endif
|
||||
|
||||
#if (SWO_UART != 0)
|
||||
|
||||
|
||||
void usart_monitor_task(void *argument)
|
||||
{
|
||||
uint32_t index_i;
|
||||
uint32_t index_o;
|
||||
uint32_t count;
|
||||
uint32_t num;
|
||||
uint32_t flags;
|
||||
|
||||
kUART_Monitoe_event_group = xEventGroupCreate();
|
||||
for (;;)
|
||||
{
|
||||
flags = xEventGroupWaitBits(kUART_Monitoe_event_group, UART_GOT_DATA,
|
||||
pdTRUE, pdFALSE, portMAX_DELAY);
|
||||
if (flags & UART_GOT_DATA)
|
||||
{
|
||||
#if (TIMESTAMP_CLOCK != 0U)
|
||||
TraceTimestamp.tick = TIMESTAMP_GET();
|
||||
#endif
|
||||
index_o = TraceIndexO;
|
||||
index_i = TraceIndexI;
|
||||
index_i += TraceBlockSize;
|
||||
TraceIndexI = index_i;
|
||||
#if (TIMESTAMP_CLOCK != 0U)
|
||||
TraceTimestamp.index = index_i;
|
||||
#endif
|
||||
|
||||
num = TRACE_BLOCK_SIZE - (index_i & (TRACE_BLOCK_SIZE - 1U));
|
||||
// num is the number of bytes we need to read
|
||||
// (to achieve the size of TRACE_BLOCK_SIZE)
|
||||
count = index_i - index_o;
|
||||
// Amount of data that has not been processed yet
|
||||
|
||||
// (SWO_BUFFER_SIZE-num): the remaining usable length of the buffer after reading this data
|
||||
if (count <= (SWO_BUFFER_SIZE - num))
|
||||
{
|
||||
index_i &= SWO_BUFFER_SIZE - 1U;
|
||||
TraceBlockSize = num;
|
||||
my_uart_read_bytes(USART_PORT, &TraceBuf[index_i], num, 20 / portTICK_RATE_MS);
|
||||
//pUSART->Receive(&TraceBuf[index_i], num);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Not enough buffers
|
||||
TraceStatus = DAP_SWO_CAPTURE_ACTIVE | DAP_SWO_CAPTURE_PAUSED;
|
||||
}
|
||||
TraceUpdate = 1U;
|
||||
#if (SWO_STREAM != 0)
|
||||
if (TraceTransport == 2U)
|
||||
{
|
||||
if (count >= (USB_BLOCK_SIZE - (index_o & (USB_BLOCK_SIZE - 1U))))
|
||||
{
|
||||
xEventGroupSetBits(kSWO_Thread_event_group, SWO_GOT_DATA);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
// if (event & ARM_USART_EVENT_RX_OVERFLOW)
|
||||
// {
|
||||
// SetTraceError(DAP_SWO_BUFFER_OVERRUN);
|
||||
// }
|
||||
// if (event & (ARM_USART_EVENT_RX_BREAK |
|
||||
// ARM_USART_EVENT_RX_FRAMING_ERROR |
|
||||
// ARM_USART_EVENT_RX_PARITY_ERROR))
|
||||
// {
|
||||
// SetTraceError(DAP_SWO_STREAM_ERROR);
|
||||
// }
|
||||
}
|
||||
|
||||
// Enable or disable UART SWO Mode
|
||||
// enable: enable flag
|
||||
// return: 1 - Success, 0 - Error
|
||||
__WEAK uint32_t UART_SWO_Mode(uint32_t enable)
|
||||
uint32_t UART_SWO_Mode(uint32_t enable)
|
||||
{
|
||||
int32_t status;
|
||||
|
||||
USART_Ready = 0U;
|
||||
uart_config_t uart_config = {
|
||||
.baud_rate = 115200,
|
||||
.baud_rate = 74880,
|
||||
.data_bits = UART_DATA_8_BITS,
|
||||
.parity = UART_PARITY_DISABLE,
|
||||
.stop_bits = UART_STOP_BITS_1,
|
||||
.flow_ctrl = UART_HW_FLOWCTRL_DISABLE};
|
||||
my_uart_param_config(USART_PORT, &uart_config);
|
||||
my_uart_param_config(USART_PORT, &uart_config); // register setting
|
||||
|
||||
#define BUF_SIZE (1024)
|
||||
my_uart_driver_install(USART_PORT, BUF_SIZE, 0, 0, NULL, 0);
|
||||
//// TODO: remove this
|
||||
|
||||
if (enable != 0U)
|
||||
{
|
||||
|
@ -207,6 +141,7 @@ __WEAK uint32_t UART_SWO_Mode(uint32_t enable)
|
|||
status = my_uart_driver_install(USART_PORT, BUF_SIZE, 0, 0, NULL, 0);
|
||||
if (status != ESP_OK)
|
||||
{
|
||||
my_uart_driver_delete(USART_PORT);
|
||||
return (0U);
|
||||
}
|
||||
}
|
||||
|
@ -214,6 +149,7 @@ __WEAK uint32_t UART_SWO_Mode(uint32_t enable)
|
|||
{
|
||||
my_uart_driver_delete(USART_PORT);
|
||||
}
|
||||
|
||||
return (1U);
|
||||
|
||||
|
||||
|
@ -222,11 +158,12 @@ __WEAK uint32_t UART_SWO_Mode(uint32_t enable)
|
|||
// Configure UART SWO Baudrate
|
||||
// baudrate: requested baudrate
|
||||
// return: actual baudrate or 0 when not configured
|
||||
__WEAK uint32_t UART_SWO_Baudrate(uint32_t baudrate)
|
||||
uint32_t UART_SWO_Baudrate(uint32_t baudrate)
|
||||
{
|
||||
int32_t status;
|
||||
//// TODO: There may be bugs.
|
||||
//int32_t status;
|
||||
uint32_t index;
|
||||
uint32_t num;
|
||||
uint32_t remain_trace_block_size;
|
||||
|
||||
if (baudrate > SWO_UART_MAX_BAUDRATE)
|
||||
{
|
||||
|
@ -235,10 +172,8 @@ __WEAK uint32_t UART_SWO_Baudrate(uint32_t baudrate)
|
|||
|
||||
if (TraceStatus & DAP_SWO_CAPTURE_ACTIVE)
|
||||
{
|
||||
size_t len = 0;
|
||||
my_uart_get_buffered_data_len(USART_PORT, &len);
|
||||
TraceIndexI += my_uart_get_rx_buffered_data_len(USART_PORT);
|
||||
my_uart_flush(USART_PORT);
|
||||
TraceIndexI += len;
|
||||
// pUSART->Control(ARM_USART_CONTROL_RX, 0U);
|
||||
// if (pUSART->GetStatus().rx_busy)
|
||||
// {
|
||||
|
@ -248,29 +183,21 @@ __WEAK uint32_t UART_SWO_Baudrate(uint32_t baudrate)
|
|||
}
|
||||
|
||||
/////////////
|
||||
status = my_uart_set_baudrate(USART_PORT, baudrate);
|
||||
my_uart_set_baudrate(USART_PORT, baudrate);
|
||||
|
||||
USART_Ready = 1U;
|
||||
|
||||
if (status == ESP_OK)
|
||||
{
|
||||
USART_Ready = 1U;
|
||||
}
|
||||
else
|
||||
{
|
||||
USART_Ready = 0U;
|
||||
return (0U);
|
||||
}
|
||||
|
||||
if (TraceStatus & DAP_SWO_CAPTURE_ACTIVE)
|
||||
{
|
||||
if ((TraceStatus & DAP_SWO_CAPTURE_PAUSED) == 0U)
|
||||
{
|
||||
index = TraceIndexI & (SWO_BUFFER_SIZE - 1U);
|
||||
num = TRACE_BLOCK_SIZE - (index & (TRACE_BLOCK_SIZE - 1U));
|
||||
TraceBlockSize = num;
|
||||
//pUSART->Receive(&TraceBuf[index], num);
|
||||
my_uart_read_bytes(USART_PORT, &TraceBuf[index], num, 20 / portTICK_RATE_MS);
|
||||
index = TraceIndexI & (SWO_BUFFER_SIZE - 1U); // TraceIndexI % SWO_BUFFER_SIZE
|
||||
remain_trace_block_size = TRACE_BLOCK_SIZE - (index & (TRACE_BLOCK_SIZE - 1U)); // index % TRACE_BLOCK_SIZE
|
||||
TraceBlockSize = remain_trace_block_size;
|
||||
//pUSART->Receive(&kSwoTraceBuf[index], num);
|
||||
my_uart_read_bytes_async_swo(index, remain_trace_block_size);
|
||||
}
|
||||
//pUSART->Control(ARM_USART_CONTROL_RX, 1U); ////TODO:
|
||||
//pUSART->Control(ARM_USART_CONTROL_RX, 1U);
|
||||
}
|
||||
|
||||
return (baudrate);
|
||||
|
@ -279,7 +206,7 @@ __WEAK uint32_t UART_SWO_Baudrate(uint32_t baudrate)
|
|||
// Control UART SWO Capture
|
||||
// active: active flag
|
||||
// return: 1 - Success, 0 - Error
|
||||
__WEAK uint32_t UART_SWO_Control(uint32_t active)
|
||||
uint32_t UART_SWO_Control(uint32_t active)
|
||||
{
|
||||
int32_t status;
|
||||
|
||||
|
@ -290,7 +217,8 @@ __WEAK uint32_t UART_SWO_Control(uint32_t active)
|
|||
return (0U);
|
||||
}
|
||||
TraceBlockSize = 1U;
|
||||
status = my_uart_read_bytes(USART_PORT, &TraceBuf[0], 1U, 20 / portTICK_RATE_MS);
|
||||
status = my_uart_read_bytes_async_swo(0, 1U);
|
||||
|
||||
if (status == ESP_FAIL)
|
||||
{
|
||||
return (0U);
|
||||
|
@ -299,14 +227,13 @@ __WEAK uint32_t UART_SWO_Control(uint32_t active)
|
|||
// if (status != ARM_DRIVER_OK)
|
||||
// {
|
||||
// return (0U);
|
||||
// } ////TODO:
|
||||
// }
|
||||
}
|
||||
else
|
||||
{
|
||||
size_t len = 0;
|
||||
my_uart_get_buffered_data_len(USART_PORT, &len);
|
||||
// no active
|
||||
TraceIndexI += my_uart_get_rx_buffered_data_len(USART_PORT);
|
||||
my_uart_flush(USART_PORT);
|
||||
TraceIndexI += len;
|
||||
// pUSART->Control(ARM_USART_CONTROL_RX, 0U);
|
||||
// if (pUSART->GetStatus().rx_busy)
|
||||
// {
|
||||
|
@ -318,20 +245,19 @@ __WEAK uint32_t UART_SWO_Control(uint32_t active)
|
|||
}
|
||||
|
||||
// Start UART SWO Capture
|
||||
// buf: pointer to buffer for capturing
|
||||
// index: trace buffer index to read
|
||||
// num: number of bytes to capture
|
||||
__WEAK void UART_SWO_Capture(uint8_t *buf, uint32_t num)
|
||||
static void UART_SWO_Capture(uint32_t index, uint32_t num)
|
||||
{
|
||||
TraceBlockSize = num;
|
||||
my_uart_read_bytes(USART_PORT, buf, num, 20 / portTICK_RATE_MS);
|
||||
my_uart_read_bytes_async_swo(index, num);
|
||||
}
|
||||
|
||||
// Get UART SWO Pending Trace Count
|
||||
// return: number of pending trace data bytes
|
||||
__WEAK uint32_t UART_SWO_GetCount(void)
|
||||
static uint32_t UART_SWO_GetCount(void)
|
||||
{
|
||||
uint32_t count;
|
||||
|
||||
//// TODO: There may be bugs.
|
||||
// if (pUSART->GetStatus().rx_busy)
|
||||
// {
|
||||
// count = pUSART->GetRxCount();
|
||||
|
@ -340,65 +266,31 @@ __WEAK uint32_t UART_SWO_GetCount(void)
|
|||
// {
|
||||
// count = 0U;
|
||||
// }
|
||||
my_uart_get_buffered_data_len(USART_PORT, &count);
|
||||
return (count);
|
||||
return my_uart_get_rx_buffered_data_len(USART_PORT);
|
||||
|
||||
}
|
||||
|
||||
#endif /* (SWO_UART != 0) */
|
||||
|
||||
#if (SWO_MANCHESTER != 0)
|
||||
|
||||
// Enable or disable Manchester SWO Mode
|
||||
// enable: enable flag
|
||||
// return: 1 - Success, 0 - Error
|
||||
__WEAK uint32_t Manchester_SWO_Mode(uint32_t enable)
|
||||
{
|
||||
return (0U);
|
||||
}
|
||||
|
||||
// Configure Manchester SWO Baudrate
|
||||
// baudrate: requested baudrate
|
||||
// return: actual baudrate or 0 when not configured
|
||||
__WEAK uint32_t Manchester_SWO_Baudrate(uint32_t baudrate)
|
||||
{
|
||||
return (0U);
|
||||
}
|
||||
//
|
||||
// Trace status helper functions
|
||||
//
|
||||
|
||||
// Control Manchester SWO Capture
|
||||
// active: active flag
|
||||
// return: 1 - Success, 0 - Error
|
||||
__WEAK uint32_t Manchester_SWO_Control(uint32_t active)
|
||||
{
|
||||
return (0U);
|
||||
}
|
||||
|
||||
// Start Manchester SWO Capture
|
||||
// buf: pointer to buffer for capturing
|
||||
// num: number of bytes to capture
|
||||
__WEAK void Manchester_SWO_Capture(uint8_t *buf, uint32_t num)
|
||||
{
|
||||
}
|
||||
|
||||
// Get Manchester SWO Pending Trace Count
|
||||
// return: number of pending trace data bytes
|
||||
__WEAK uint32_t Manchester_SWO_GetCount(void)
|
||||
{
|
||||
return (0U);
|
||||
}
|
||||
|
||||
#endif /* (SWO_MANCHESTER != 0) */
|
||||
|
||||
// Clear Trace Errors and Data
|
||||
static void ClearTrace(void)
|
||||
{
|
||||
|
||||
#if (SWO_STREAM != 0)
|
||||
if (TraceTransport == 2U)
|
||||
if (TraceTransport == 2U) // Indicates that we use WinUSB for transfer.
|
||||
{
|
||||
if (TransferBusy != 0U)
|
||||
if (kSwoTransferBusy != 0U)
|
||||
{
|
||||
SWO_AbortTransfer();
|
||||
TransferBusy = 0U;
|
||||
// Unfortunately, we cannot abort the transmission
|
||||
// SWO_AbortTransfer();
|
||||
kSwoTransferBusy = 0U;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -430,18 +322,10 @@ static void ResumeTrace(void)
|
|||
index_i &= SWO_BUFFER_SIZE - 1U;
|
||||
switch (TraceMode)
|
||||
{
|
||||
#if (SWO_UART != 0)
|
||||
case DAP_SWO_UART:
|
||||
TraceStatus = DAP_SWO_CAPTURE_ACTIVE;
|
||||
UART_SWO_Capture(&TraceBuf[index_i], 1U);
|
||||
UART_SWO_Capture(index_i, 1U);
|
||||
break;
|
||||
#endif
|
||||
#if (SWO_MANCHESTER != 0)
|
||||
case DAP_SWO_MANCHESTER:
|
||||
TraceStatus = DAP_SWO_CAPTURE_ACTIVE;
|
||||
Manchester_SWO_Capture(&TraceBuf[index_i], 1U);
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -463,20 +347,15 @@ static uint32_t GetTraceCount(void)
|
|||
count = TraceIndexI - TraceIndexO;
|
||||
switch (TraceMode)
|
||||
{
|
||||
#if (SWO_UART != 0)
|
||||
case DAP_SWO_UART:
|
||||
count += UART_SWO_GetCount();
|
||||
break;
|
||||
#endif
|
||||
#if (SWO_MANCHESTER != 0)
|
||||
case DAP_SWO_MANCHESTER:
|
||||
count += Manchester_SWO_GetCount();
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
break;
|
||||
}
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
} while (TraceUpdate != 0U);
|
||||
// Synchronously wait for the data to complete
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -541,14 +420,7 @@ uint32_t SWO_Transport(const uint8_t *request, uint8_t *response)
|
|||
result = 0U;
|
||||
}
|
||||
|
||||
if (result != 0U)
|
||||
{
|
||||
*response = DAP_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
*response = DAP_ERROR;
|
||||
}
|
||||
*response = result ? DAP_OK : DAP_ERROR;
|
||||
|
||||
return ((1U << 16) | 1U);
|
||||
}
|
||||
|
@ -565,6 +437,7 @@ uint32_t SWO_Mode(const uint8_t *request, uint8_t *response)
|
|||
|
||||
mode = *request;
|
||||
|
||||
// disable swo mode
|
||||
switch (TraceMode)
|
||||
{
|
||||
#if (SWO_UART != 0)
|
||||
|
@ -572,11 +445,7 @@ uint32_t SWO_Mode(const uint8_t *request, uint8_t *response)
|
|||
UART_SWO_Mode(0U);
|
||||
break;
|
||||
#endif
|
||||
#if (SWO_MANCHESTER != 0)
|
||||
case DAP_SWO_MANCHESTER:
|
||||
Manchester_SWO_Mode(0U);
|
||||
break;
|
||||
#endif
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -591,34 +460,18 @@ uint32_t SWO_Mode(const uint8_t *request, uint8_t *response)
|
|||
result = UART_SWO_Mode(1U);
|
||||
break;
|
||||
#endif
|
||||
#if (SWO_MANCHESTER != 0)
|
||||
case DAP_SWO_MANCHESTER:
|
||||
result = Manchester_SWO_Mode(1U);
|
||||
break;
|
||||
#endif
|
||||
|
||||
default:
|
||||
result = 0U;
|
||||
break;
|
||||
}
|
||||
if (result != 0U)
|
||||
{
|
||||
TraceMode = mode;
|
||||
}
|
||||
else
|
||||
{
|
||||
TraceMode = DAP_SWO_OFF;
|
||||
}
|
||||
|
||||
// DAP_SWO_OFF -> has error
|
||||
TraceMode = result ? mode : DAP_SWO_OFF;
|
||||
|
||||
TraceStatus = 0U;
|
||||
|
||||
if (result != 0U)
|
||||
{
|
||||
*response = DAP_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
*response = DAP_ERROR;
|
||||
}
|
||||
*response = result ? DAP_OK : DAP_ERROR;
|
||||
|
||||
return ((1U << 16) | 1U);
|
||||
}
|
||||
|
@ -644,11 +497,7 @@ uint32_t SWO_Baudrate(const uint8_t *request, uint8_t *response)
|
|||
baudrate = UART_SWO_Baudrate(baudrate);
|
||||
break;
|
||||
#endif
|
||||
#if (SWO_MANCHESTER != 0)
|
||||
case DAP_SWO_MANCHESTER:
|
||||
baudrate = Manchester_SWO_Baudrate(baudrate);
|
||||
break;
|
||||
#endif
|
||||
|
||||
default:
|
||||
baudrate = 0U;
|
||||
break;
|
||||
|
@ -681,7 +530,9 @@ uint32_t SWO_Control(const uint8_t *request, uint8_t *response)
|
|||
|
||||
if (active != (TraceStatus & DAP_SWO_CAPTURE_ACTIVE))
|
||||
{
|
||||
if (active)
|
||||
// active status: request != now status
|
||||
|
||||
if (active) // request: active
|
||||
{
|
||||
ClearTrace();
|
||||
}
|
||||
|
@ -692,39 +543,32 @@ uint32_t SWO_Control(const uint8_t *request, uint8_t *response)
|
|||
result = UART_SWO_Control(active);
|
||||
break;
|
||||
#endif
|
||||
#if (SWO_MANCHESTER != 0)
|
||||
case DAP_SWO_MANCHESTER:
|
||||
result = Manchester_SWO_Control(active);
|
||||
break;
|
||||
#endif
|
||||
|
||||
default:
|
||||
result = 0U;
|
||||
break;
|
||||
}
|
||||
|
||||
if (result != 0U)
|
||||
{
|
||||
// success done
|
||||
TraceStatus = active;
|
||||
#if (SWO_STREAM != 0)
|
||||
if (TraceTransport == 2U)
|
||||
if (TraceTransport == 2U) // Indicates that we use WinUSB for transfer.
|
||||
{
|
||||
xEventGroupSetBits(kSWO_Thread_event_group, SWO_GOT_DATA);
|
||||
xEventGroupSetBits(kSwoThreadEventGroup, SWO_GOT_DATA);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// request: active but already actived
|
||||
result = 1U;
|
||||
}
|
||||
|
||||
if (result != 0U)
|
||||
{
|
||||
*response = DAP_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
*response = DAP_ERROR;
|
||||
}
|
||||
|
||||
*response = result ? DAP_OK : DAP_ERROR;
|
||||
|
||||
return ((1U << 16) | 1U);
|
||||
}
|
||||
|
@ -793,6 +637,7 @@ uint32_t SWO_ExtendedStatus(const uint8_t *request, uint8_t *response)
|
|||
TraceUpdate = 0U;
|
||||
index = TraceTimestamp.index;
|
||||
tick = TraceTimestamp.tick;
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
} while (TraceUpdate != 0U);
|
||||
*response++ = (uint8_t)(index >> 0);
|
||||
*response++ = (uint8_t)(index >> 8);
|
||||
|
@ -824,6 +669,8 @@ uint32_t SWO_Data(const uint8_t *request, uint8_t *response)
|
|||
status = GetTraceStatus();
|
||||
count = GetTraceCount();
|
||||
|
||||
// transport 1: use DAP SWO command
|
||||
// transport 2: WinUSB
|
||||
if (TraceTransport == 1U)
|
||||
{
|
||||
n = (uint32_t)(*(request + 0) << 0) |
|
||||
|
@ -839,6 +686,7 @@ uint32_t SWO_Data(const uint8_t *request, uint8_t *response)
|
|||
}
|
||||
else
|
||||
{
|
||||
// if use winusb, then nothing to do.
|
||||
count = 0U;
|
||||
}
|
||||
|
||||
|
@ -852,7 +700,7 @@ uint32_t SWO_Data(const uint8_t *request, uint8_t *response)
|
|||
for (i = index, n = count; n; n--)
|
||||
{
|
||||
i &= SWO_BUFFER_SIZE - 1U;
|
||||
*response++ = TraceBuf[i++];
|
||||
*response++ = kSwoTraceBuf[i++];
|
||||
}
|
||||
TraceIndexO = index + count;
|
||||
ResumeTrace();
|
||||
|
@ -867,78 +715,171 @@ uint32_t SWO_Data(const uint8_t *request, uint8_t *response)
|
|||
void SWO_TransferComplete(void)
|
||||
{
|
||||
TraceIndexO += TransferSize;
|
||||
TransferBusy = 0U;
|
||||
kSwoTransferBusy = 0U;
|
||||
ResumeTrace();
|
||||
xEventGroupSetBits(kSWO_Thread_event_group, SWO_GOT_DATA);
|
||||
xEventGroupSetBits(kSwoThreadEventGroup, SWO_GOT_DATA);
|
||||
}
|
||||
|
||||
// SWO Thread
|
||||
void SWO_Thread(void *argument)
|
||||
void SWO_Thread()
|
||||
{
|
||||
uint32_t timeout;
|
||||
uint32_t flags;
|
||||
uint32_t count;
|
||||
uint32_t index;
|
||||
uint32_t i, n;
|
||||
(void)argument;
|
||||
|
||||
timeout = portMAX_DELAY;
|
||||
|
||||
kSWO_Thread_event_group = xEventGroupCreate();
|
||||
uint32_t index_i;
|
||||
uint32_t index_o;
|
||||
uint32_t remain_trace_block_size;
|
||||
|
||||
TickType_t timeout = portMAX_DELAY;
|
||||
|
||||
kSwoThreadEventGroup = xEventGroupCreate();
|
||||
for (;;)
|
||||
{
|
||||
flags = xEventGroupWaitBits(kSWO_Thread_event_group, SWO_GOT_DATA | SWO_ERROR_TIME_OUT,
|
||||
/*
|
||||
Here, our event group handles two main types of events:
|
||||
1. `SWO_GOT_DATA` : The SWO package may be ready to send.
|
||||
2. `UART_GOT_DATA` : The uart transfer event is complete and we can start reading.
|
||||
|
||||
Note that the `SWO_ERROR_TIME_OUT` flag is only used for internal processing, only when the status is
|
||||
inactive can it be set.
|
||||
|
||||
We deal with uart events first.
|
||||
Currently, SWO events are always handled.
|
||||
*/
|
||||
flags = xEventGroupWaitBits(kSwoThreadEventGroup, SWO_GOT_DATA | UART_GOT_DATA | SWO_ERROR_TIME_OUT,
|
||||
pdTRUE, pdFALSE, timeout);
|
||||
if (TraceStatus & DAP_SWO_CAPTURE_ACTIVE)
|
||||
|
||||
if (!(flags & UART_GOT_DATA) && !(flags & SWO_GOT_DATA))
|
||||
{
|
||||
timeout = SWO_STREAM_TIMEOUT;
|
||||
if (TraceMode != DAP_SWO_OFF && my_uart_get_rx_buffered_data_len(USART_PORT) >= kSWO_read_num)
|
||||
{
|
||||
flags = UART_GOT_DATA;
|
||||
}
|
||||
}
|
||||
|
||||
if (flags & UART_GOT_DATA)
|
||||
{
|
||||
// The data is still in the uart buffer,
|
||||
// and the data in the uart needs to be read into the SWO buffer
|
||||
my_uart_read_bytes(USART_PORT, &kSwoTraceBuf[kSWO_read_index], kSWO_read_num, pdMS_TO_TICKS(20));
|
||||
|
||||
|
||||
index_o = TraceIndexO;
|
||||
|
||||
TraceIndexI += TraceBlockSize;
|
||||
index_i = TraceIndexI;
|
||||
|
||||
#if (TIMESTAMP_CLOCK != 0U)
|
||||
TraceTimestamp.tick = TIMESTAMP_GET();
|
||||
TraceTimestamp.index = index_i;
|
||||
#endif
|
||||
remain_trace_block_size = TRACE_BLOCK_SIZE - (index_i & (TRACE_BLOCK_SIZE - 1U));
|
||||
// remain_trace_block_size is the number of bytes we need to read
|
||||
// (to achieve the size of TRACE_BLOCK_SIZE)
|
||||
count = index_i - index_o;
|
||||
// Amount of data that has not been processed yet
|
||||
|
||||
// (SWO_BUFFER_SIZE-num): the remaining usable length of the buffer after reading this data
|
||||
if (count <= (SWO_BUFFER_SIZE - remain_trace_block_size))
|
||||
{
|
||||
// index_i % 4096
|
||||
index_i &= SWO_BUFFER_SIZE - 1U;
|
||||
TraceBlockSize = remain_trace_block_size;
|
||||
my_uart_read_bytes_async_swo(index_i, remain_trace_block_size);
|
||||
//pUSART->Receive(&kSwoTraceBuf[index_i], num);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Not enough buffers
|
||||
TraceStatus = DAP_SWO_CAPTURE_ACTIVE | DAP_SWO_CAPTURE_PAUSED;
|
||||
}
|
||||
TraceUpdate = 1U;
|
||||
#if (SWO_STREAM != 0)
|
||||
if (TraceTransport == 2U) // Indicates that we use WinUSB for transfer.
|
||||
{
|
||||
// unsent length >= remaining length of the USB block
|
||||
//// TODO: may be we can remove this
|
||||
if (count >= (USB_BLOCK_SIZE - (index_o & (USB_BLOCK_SIZE - 1U))))
|
||||
{
|
||||
flags = SWO_GOT_DATA;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// xEventGroupClearBits
|
||||
|
||||
/*
|
||||
`SWO_GOT_DATA` may be set in the following situations:
|
||||
- The SWO status requested by `SWD_contorl` is different from the current SWO status.
|
||||
- When `SWO_TransferComplete` is called, and there may be potentially unsent data in the buffer.
|
||||
- monitor task believes we need to send data that is already long enough.
|
||||
|
||||
Note: The processing of the following code segment will always be executed,
|
||||
and should be ensured to be stable enough.
|
||||
|
||||
|
||||
TODO: The time interval for executing the code is not guaranteed.
|
||||
*/
|
||||
|
||||
if (!(TraceStatus & DAP_SWO_CAPTURE_ACTIVE))
|
||||
{
|
||||
flags = SWO_ERROR_TIME_OUT;
|
||||
timeout = portMAX_DELAY;
|
||||
}
|
||||
else
|
||||
{
|
||||
timeout = portMAX_DELAY;
|
||||
flags = SWO_ERROR_TIME_OUT;
|
||||
timeout = pdMS_TO_TICKS(150);
|
||||
}
|
||||
if (TransferBusy == 0U)
|
||||
|
||||
if (kSwoTransferBusy)
|
||||
{
|
||||
count = GetTraceCount();
|
||||
if (count != 0U)
|
||||
continue;
|
||||
}
|
||||
|
||||
count = GetTraceCount();
|
||||
if (count != 0U)
|
||||
{
|
||||
index = TraceIndexO & (SWO_BUFFER_SIZE - 1U);
|
||||
n = SWO_BUFFER_SIZE - index;
|
||||
if (count > n)
|
||||
{
|
||||
index = TraceIndexO & (SWO_BUFFER_SIZE - 1U);
|
||||
n = SWO_BUFFER_SIZE - index;
|
||||
if (count > n)
|
||||
count = n;
|
||||
}
|
||||
if ((flags & SWO_ERROR_TIME_OUT) == 0)
|
||||
{
|
||||
i = index & (USB_BLOCK_SIZE - 1U);
|
||||
if (i == 0U)
|
||||
{
|
||||
count = n;
|
||||
count &= ~(USB_BLOCK_SIZE - 1U); // Take down to the nearest number that is a multiple of USB_BLOCK_SIZE
|
||||
}
|
||||
if ((flags & SWO_ERROR_TIME_OUT) == 0)
|
||||
else
|
||||
{
|
||||
i = index & (USB_BLOCK_SIZE - 1U);
|
||||
if (i == 0U)
|
||||
n = USB_BLOCK_SIZE - i;
|
||||
if (count >= n)
|
||||
{
|
||||
count &= ~(USB_BLOCK_SIZE - 1U);
|
||||
// Take down to the nearest number that is a multiple of USB_BLOCK_SIZE
|
||||
count = n; // The number of bytes to be sent exceeds the remain USB block size.
|
||||
}
|
||||
else
|
||||
{
|
||||
n = USB_BLOCK_SIZE - i;
|
||||
if (count >= n)
|
||||
{
|
||||
count = n;
|
||||
}
|
||||
else
|
||||
{
|
||||
count = 0U;
|
||||
}
|
||||
count = 0U; // Haven't received a full USB block yet.
|
||||
}
|
||||
}
|
||||
if (count != 0U)
|
||||
{
|
||||
TransferSize = count;
|
||||
TransferBusy = 1U;
|
||||
SWO_QueueTransfer(&TraceBuf[index], count); //through USB
|
||||
}
|
||||
}
|
||||
// Notify that there is data available for transmission
|
||||
if (count != 0U)
|
||||
{
|
||||
TransferSize = count;
|
||||
kSwoTransferBusy = 1U;
|
||||
SWO_QueueTransfer(&kSwoTraceBuf[index], count); // through USB
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// For all exceptions, we have handled them directly in the interrupt handlers.
|
||||
}
|
||||
|
||||
#endif /* (SWO_STREAM != 0) */
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,6 +1,6 @@
|
|||
#include "dap_utility.h"
|
||||
#include "components/DAP/include/dap_utility.h"
|
||||
|
||||
const uint8_t kParityByteTable[256] =
|
||||
const uint8_t kParityByteTable[256] =
|
||||
{
|
||||
#define P2(n) n, n^1, n^1, n
|
||||
#define P4(n) P2(n), P2(n^1), P2(n^1), P2(n)
|
||||
|
|
|
@ -4,17 +4,23 @@
|
|||
* @brief Using SPI for common transfer operations
|
||||
* @change: 2020-11-25 first version
|
||||
* 2021-2-11 Support SWD sequence
|
||||
* @version 0.2
|
||||
* @date 2021-2-11
|
||||
* 2021-3-10 Support 3-wire SPI
|
||||
* @version 0.3
|
||||
* @date 2021-3-10
|
||||
*
|
||||
* @copyright Copyright (c) 2021
|
||||
*
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "main/dap_configuration.h"
|
||||
|
||||
#include "components/DAP/include/cmsis_compiler.h"
|
||||
#include "components/DAP/include/spi_op.h"
|
||||
|
||||
#include "esp8266/spi_struct.h"
|
||||
#include "cmsis_compiler.h"
|
||||
#include "spi_op.h"
|
||||
|
||||
|
||||
#define DAP_SPI SPI1
|
||||
|
||||
|
@ -83,7 +89,7 @@ void DAP_SPI_WriteBits(const uint8_t count, const uint8_t *buf)
|
|||
// Start transmission
|
||||
DAP_SPI.cmd.usr = 1;
|
||||
// Wait for sending to complete
|
||||
while (DAP_SPI.cmd.usr);
|
||||
while (DAP_SPI.cmd.usr) continue;
|
||||
}
|
||||
|
||||
|
||||
|
@ -103,12 +109,20 @@ void DAP_SPI_ReadBits(const uint8_t count, uint8_t *buf) {
|
|||
DAP_SPI.user.usr_mosi = 0;
|
||||
DAP_SPI.user.usr_miso = 1;
|
||||
|
||||
#if (USE_SPI_SIO == 1)
|
||||
DAP_SPI.user.sio = true;
|
||||
#endif
|
||||
|
||||
DAP_SPI.user1.usr_miso_bitlen = count - 1U;
|
||||
|
||||
// Start transmission
|
||||
DAP_SPI.cmd.usr = 1;
|
||||
// Wait for reading to complete
|
||||
while (DAP_SPI.cmd.usr);
|
||||
while (DAP_SPI.cmd.usr) continue;
|
||||
|
||||
#if (USE_SPI_SIO == 1)
|
||||
DAP_SPI.user.sio = false;
|
||||
#endif
|
||||
|
||||
data_buf[0] = DAP_SPI.data_buf[0];
|
||||
data_buf[1] = DAP_SPI.data_buf[1];
|
||||
|
@ -139,6 +153,10 @@ __FORCEINLINE void DAP_SPI_Send_Header(const uint8_t packetHeaderData, uint8_t *
|
|||
|
||||
DAP_SPI.user.usr_miso = 1;
|
||||
|
||||
#if (USE_SPI_SIO == 1)
|
||||
DAP_SPI.user.sio = true;
|
||||
#endif
|
||||
|
||||
// 1 bit Trn(Before ACK) + 3bits ACK + TrnAferACK - 1(prescribed)
|
||||
DAP_SPI.user1.usr_miso_bitlen = 1U + 3U + TrnAfterACK - 1U;
|
||||
|
||||
|
@ -148,7 +166,11 @@ __FORCEINLINE void DAP_SPI_Send_Header(const uint8_t packetHeaderData, uint8_t *
|
|||
// Start transmission
|
||||
DAP_SPI.cmd.usr = 1;
|
||||
// Wait for sending to complete
|
||||
while (DAP_SPI.cmd.usr);
|
||||
while (DAP_SPI.cmd.usr) continue;
|
||||
|
||||
#if (USE_SPI_SIO == 1)
|
||||
DAP_SPI.user.sio = false;
|
||||
#endif
|
||||
|
||||
dataBuf = DAP_SPI.data_buf[0];
|
||||
*ack = (dataBuf >> 1) & 0b111;
|
||||
|
@ -163,19 +185,27 @@ __FORCEINLINE void DAP_SPI_Send_Header(const uint8_t packetHeaderData, uint8_t *
|
|||
*/
|
||||
__FORCEINLINE void DAP_SPI_Read_Data(uint32_t *resData, uint8_t *resParity)
|
||||
{
|
||||
uint64_t dataBuf;
|
||||
volatile uint64_t dataBuf;
|
||||
uint32_t *pU32Data = (uint32_t *)&dataBuf;
|
||||
|
||||
DAP_SPI.user.usr_mosi = 0;
|
||||
DAP_SPI.user.usr_miso = 1;
|
||||
|
||||
#if (USE_SPI_SIO == 1)
|
||||
DAP_SPI.user.sio = true;
|
||||
#endif
|
||||
|
||||
// 1 bit Trn(End) + 3bits ACK + 32bis data + 1bit parity - 1(prescribed)
|
||||
DAP_SPI.user1.usr_miso_bitlen = 1U + 32U + 1U - 1U;
|
||||
|
||||
// Start transmission
|
||||
DAP_SPI.cmd.usr = 1;
|
||||
// Wait for sending to complete
|
||||
while (DAP_SPI.cmd.usr);
|
||||
while (DAP_SPI.cmd.usr) continue;
|
||||
|
||||
#if (USE_SPI_SIO == 1)
|
||||
DAP_SPI.user.sio = false;
|
||||
#endif
|
||||
|
||||
pU32Data[0] = DAP_SPI.data_buf[0];
|
||||
pU32Data[1] = DAP_SPI.data_buf[1];
|
||||
|
@ -204,7 +234,7 @@ __FORCEINLINE void DAP_SPI_Write_Data(uint32_t data, uint8_t parity)
|
|||
// Start transmission
|
||||
DAP_SPI.cmd.usr = 1;
|
||||
// Wait for sending to complete
|
||||
while (DAP_SPI.cmd.usr);
|
||||
while (DAP_SPI.cmd.usr) continue;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -221,8 +251,10 @@ __FORCEINLINE void DAP_SPI_Generate_Cycle(uint8_t num)
|
|||
|
||||
DAP_SPI.data_buf[0] = 0x00000000U;
|
||||
|
||||
// Start transmission
|
||||
DAP_SPI.cmd.usr = 1;
|
||||
while (DAP_SPI.cmd.usr);
|
||||
// Wait for sending to complete
|
||||
while (DAP_SPI.cmd.usr) continue;
|
||||
}
|
||||
|
||||
|
||||
|
@ -239,8 +271,10 @@ __FORCEINLINE void DAP_SPI_Protocol_Error_Read()
|
|||
DAP_SPI.data_buf[0] = 0xFFFFFFFFU;
|
||||
DAP_SPI.data_buf[1] = 0xFFFFFFFFU;
|
||||
|
||||
// Start transmission
|
||||
DAP_SPI.cmd.usr = 1;
|
||||
while (DAP_SPI.cmd.usr);
|
||||
// Wait for sending to complete
|
||||
while (DAP_SPI.cmd.usr) continue;
|
||||
}
|
||||
|
||||
|
||||
|
@ -257,6 +291,8 @@ __FORCEINLINE void DAP_SPI_Protocol_Error_Write()
|
|||
DAP_SPI.data_buf[0] = 0xFFFFFFFFU;
|
||||
DAP_SPI.data_buf[1] = 0xFFFFFFFFU;
|
||||
|
||||
// Start transmission
|
||||
DAP_SPI.cmd.usr = 1;
|
||||
while (DAP_SPI.cmd.usr);
|
||||
// Wait for sending to complete
|
||||
while (DAP_SPI.cmd.usr) continue;
|
||||
}
|
||||
|
|
|
@ -12,13 +12,13 @@
|
|||
*/
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "components/DAP/include/cmsis_compiler.h"
|
||||
#include "components/DAP/include/spi_switch.h"
|
||||
|
||||
#include "esp8266/spi_struct.h"
|
||||
#include "esp8266/pin_mux_register.h"
|
||||
#include "esp8266/gpio_struct.h"
|
||||
|
||||
#include "cmsis_compiler.h"
|
||||
#include "spi_switch.h"
|
||||
|
||||
|
||||
#define DAP_SPI SPI1
|
||||
|
||||
|
@ -106,11 +106,13 @@ void DAP_SPI_Init()
|
|||
pin_reg.pullup = 0;
|
||||
WRITE_PERI_REG(GPIO_PIN_REG(13), pin_reg.val);
|
||||
|
||||
#if (USE_SPI_SIO != 1)
|
||||
PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDI_U, FUNC_HSPIQ_MISO); // GPIO12 is SPI MISO pin (Master Data In)
|
||||
// esp8266 in is always connected
|
||||
pin_reg.val = READ_PERI_REG(GPIO_PIN_REG(12));
|
||||
pin_reg.pullup = 0;
|
||||
WRITE_PERI_REG(GPIO_PIN_REG(12), pin_reg.val);
|
||||
#endif // (USE_SPI_SIO != 1)
|
||||
|
||||
|
||||
|
||||
|
@ -136,10 +138,12 @@ __FORCEINLINE void DAP_SPI_Deinit()
|
|||
{
|
||||
PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTMS_U, FUNC_GPIO14);
|
||||
PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTCK_U, FUNC_GPIO13); // MOSI
|
||||
#if (USE_SPI_SIO != 1)
|
||||
PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDI_U, FUNC_GPIO12); // MISO
|
||||
|
||||
// disable MISO output connect
|
||||
GPIO.enable_w1tc |= (0x1 << 12);
|
||||
#endif // (USE_SPI_SIO != 1)
|
||||
|
||||
gpio_pin_reg_t pin_reg;
|
||||
GPIO.enable_w1ts |= (0x1 << 13);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
* @brief Made some simple modifications to the official UART
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
// Copyright 2018-2025 Espressif Systems (Shanghai) PTE LTD
|
||||
|
@ -19,6 +19,11 @@
|
|||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "components/DAP/config/DAP_config.h"
|
||||
#include "components/DAP/include/uart_modify.h"
|
||||
#include "components/DAP/include/swo.h"
|
||||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/queue.h"
|
||||
|
@ -26,12 +31,9 @@
|
|||
#include "freertos/ringbuf.h"
|
||||
#include "freertos/event_groups.h"
|
||||
|
||||
#include "esp_err.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_attr.h"
|
||||
|
||||
// SWO modify
|
||||
#include "DAP_config.h"
|
||||
#include "esp8266/uart_struct.h"
|
||||
#include "esp8266/uart_register.h"
|
||||
#include "esp8266/pin_mux_register.h"
|
||||
|
@ -39,8 +41,6 @@
|
|||
#include "esp8266/rom_functions.h"
|
||||
|
||||
#include "rom/ets_sys.h"
|
||||
|
||||
#include "uart_modify.h"
|
||||
#include "driver/uart_select.h"
|
||||
|
||||
#define portYIELD_FROM_ISR() taskYIELD()
|
||||
|
@ -70,6 +70,11 @@ typedef struct
|
|||
} tx_data;
|
||||
} uart_tx_data_t;
|
||||
|
||||
|
||||
|
||||
// read:
|
||||
// hardware FIFO -> `rx_data_buf` -> `rx_ring_buf` -> user buf
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uart_port_t uart_num; /*!< UART port number*/
|
||||
|
@ -118,18 +123,21 @@ typedef struct
|
|||
static uart_isr_func_t uart_isr_func[UART_NUM_MAX];
|
||||
|
||||
// SWO modify
|
||||
extern EventGroupHandle_t kUART_Monitoe_event_group;
|
||||
#define UART_GOT_DATA BIT0
|
||||
extern void SetTraceError(uint8_t flag);
|
||||
#define DAP_SWO_CAPTURE_ACTIVE (1U << 0)
|
||||
#define DAP_SWO_CAPTURE_PAUSED (1U << 1)
|
||||
#define DAP_SWO_STREAM_ERROR (1U << 6)
|
||||
#define DAP_SWO_BUFFER_OVERRUN (1U << 7)
|
||||
//
|
||||
|
||||
// non thread safe
|
||||
volatile uint32_t kSWO_read_index = 0;
|
||||
volatile uint32_t kSWO_read_num = 0;
|
||||
volatile uint8_t kSWO_uart_notify_enable = 1;
|
||||
SemaphoreHandle_t kSWO_read_mux = NULL;
|
||||
|
||||
|
||||
|
||||
esp_err_t my_uart_set_word_length(uart_port_t uart_num, uart_word_length_t data_bit)
|
||||
{
|
||||
UART_CHECK((uart_num < UART_NUM_MAX), "uart_num error", ESP_ERR_INVALID_ARG);
|
||||
UART_CHECK((data_bit < UART_DATA_BITS_MAX), "data bit error", ESP_ERR_INVALID_ARG);
|
||||
|
||||
UART_ENTER_CRITICAL();
|
||||
|
@ -140,7 +148,6 @@ esp_err_t my_uart_set_word_length(uart_port_t uart_num, uart_word_length_t data_
|
|||
|
||||
esp_err_t my_uart_get_word_length(uart_port_t uart_num, uart_word_length_t *data_bit)
|
||||
{
|
||||
UART_CHECK((uart_num < UART_NUM_MAX), "uart_num error", ESP_ERR_INVALID_ARG);
|
||||
UART_CHECK((data_bit), "empty pointer", ESP_FAIL);
|
||||
|
||||
*(data_bit) = UART[uart_num]->conf0.bit_num;
|
||||
|
@ -149,7 +156,6 @@ esp_err_t my_uart_get_word_length(uart_port_t uart_num, uart_word_length_t *data
|
|||
|
||||
esp_err_t my_uart_set_stop_bits(uart_port_t uart_num, uart_stop_bits_t stop_bit)
|
||||
{
|
||||
UART_CHECK((uart_num < UART_NUM_MAX), "uart_num error", ESP_ERR_INVALID_ARG);
|
||||
UART_CHECK((stop_bit < UART_STOP_BITS_MAX), "stop bit error", ESP_ERR_INVALID_ARG);
|
||||
|
||||
UART_ENTER_CRITICAL();
|
||||
|
@ -160,7 +166,6 @@ esp_err_t my_uart_set_stop_bits(uart_port_t uart_num, uart_stop_bits_t stop_bit)
|
|||
|
||||
esp_err_t my_uart_get_stop_bits(uart_port_t uart_num, uart_stop_bits_t *stop_bit)
|
||||
{
|
||||
UART_CHECK((uart_num < UART_NUM_MAX), "uart_num error", ESP_ERR_INVALID_ARG);
|
||||
UART_CHECK((stop_bit), "empty pointer", ESP_FAIL);
|
||||
|
||||
(*stop_bit) = UART[uart_num]->conf0.stop_bit_num;
|
||||
|
@ -169,7 +174,6 @@ esp_err_t my_uart_get_stop_bits(uart_port_t uart_num, uart_stop_bits_t *stop_bit
|
|||
|
||||
esp_err_t my_uart_set_parity(uart_port_t uart_num, uart_parity_t parity_mode)
|
||||
{
|
||||
UART_CHECK((uart_num < UART_NUM_MAX), "uart_num error", ESP_ERR_INVALID_ARG);
|
||||
UART_CHECK(((parity_mode == UART_PARITY_DISABLE) || (parity_mode == UART_PARITY_EVEN) || (parity_mode == UART_PARITY_ODD)),
|
||||
"parity_mode error", ESP_ERR_INVALID_ARG);
|
||||
|
||||
|
@ -182,7 +186,6 @@ esp_err_t my_uart_set_parity(uart_port_t uart_num, uart_parity_t parity_mode)
|
|||
|
||||
esp_err_t my_uart_get_parity(uart_port_t uart_num, uart_parity_t *parity_mode)
|
||||
{
|
||||
UART_CHECK((uart_num < UART_NUM_MAX), "uart_num error", ESP_ERR_INVALID_ARG);
|
||||
UART_CHECK((parity_mode), "empty pointer", ESP_ERR_INVALID_ARG);
|
||||
|
||||
UART_ENTER_CRITICAL();
|
||||
|
@ -209,8 +212,6 @@ esp_err_t my_uart_get_parity(uart_port_t uart_num, uart_parity_t *parity_mode)
|
|||
|
||||
esp_err_t my_uart_set_baudrate(uart_port_t uart_num, uint32_t baud_rate)
|
||||
{
|
||||
UART_CHECK((uart_num < UART_NUM_MAX), "uart_num error", ESP_ERR_INVALID_ARG);
|
||||
|
||||
UART_ENTER_CRITICAL();
|
||||
UART[uart_num]->clk_div.val = (uint32_t)(UART_CLK_FREQ / baud_rate) & 0xFFFFF;
|
||||
UART_EXIT_CRITICAL();
|
||||
|
@ -219,7 +220,6 @@ esp_err_t my_uart_set_baudrate(uart_port_t uart_num, uint32_t baud_rate)
|
|||
|
||||
esp_err_t my_uart_get_baudrate(uart_port_t uart_num, uint32_t *baudrate)
|
||||
{
|
||||
UART_CHECK((uart_num < UART_NUM_MAX), "uart_num error", ESP_ERR_INVALID_ARG);
|
||||
UART_CHECK((baudrate), "empty pointer", ESP_ERR_INVALID_ARG);
|
||||
|
||||
(*baudrate) = (UART_CLK_FREQ / (UART[uart_num]->clk_div.val & 0xFFFFF));
|
||||
|
@ -228,7 +228,6 @@ esp_err_t my_uart_get_baudrate(uart_port_t uart_num, uint32_t *baudrate)
|
|||
|
||||
esp_err_t my_uart_set_line_inverse(uart_port_t uart_num, uint32_t inverse_mask)
|
||||
{
|
||||
UART_CHECK((uart_num < UART_NUM_MAX), "uart_num error", ESP_ERR_INVALID_ARG);
|
||||
UART_CHECK((((inverse_mask & ~UART_LINE_INV_MASK) == 0) || (inverse_mask == 0)), "inverse_mask error", ESP_ERR_INVALID_ARG);
|
||||
|
||||
UART_ENTER_CRITICAL();
|
||||
|
@ -377,6 +376,7 @@ static esp_err_t uart_reset_rx_fifo(uart_port_t uart_num)
|
|||
return ESP_OK;
|
||||
}
|
||||
|
||||
// Clear uart interrupts status.
|
||||
esp_err_t my_uart_clear_intr_status(uart_port_t uart_num, uint32_t mask)
|
||||
{
|
||||
UART_CHECK((uart_num < UART_NUM_MAX), "uart_num error", ESP_ERR_INVALID_ARG);
|
||||
|
@ -387,6 +387,7 @@ esp_err_t my_uart_clear_intr_status(uart_port_t uart_num, uint32_t mask)
|
|||
return ESP_OK;
|
||||
}
|
||||
|
||||
// Set UART interrupt enable
|
||||
esp_err_t my_uart_enable_intr_mask(uart_port_t uart_num, uint32_t enable_mask)
|
||||
{
|
||||
UART_CHECK((uart_num < UART_NUM_MAX), "uart_num error", ESP_ERR_INVALID_ARG);
|
||||
|
@ -407,6 +408,9 @@ esp_err_t my_uart_disable_intr_mask(uart_port_t uart_num, uint32_t disable_mask)
|
|||
return ESP_OK;
|
||||
}
|
||||
|
||||
|
||||
// helper function
|
||||
|
||||
esp_err_t my_uart_enable_rx_intr(uart_port_t uart_num)
|
||||
{
|
||||
return my_uart_enable_intr_mask(uart_num, UART_RXFIFO_FULL_INT_ENA | UART_RXFIFO_TOUT_INT_ENA);
|
||||
|
@ -435,6 +439,9 @@ esp_err_t my_uart_enable_tx_intr(uart_port_t uart_num, int enable, int thresh)
|
|||
return ESP_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
static void uart_intr_service(void *arg)
|
||||
{
|
||||
// UART intr process
|
||||
|
@ -460,6 +467,7 @@ static void uart_intr_service(void *arg)
|
|||
} while (++uart_num < UART_NUM_MAX);
|
||||
}
|
||||
|
||||
// setting isr function
|
||||
esp_err_t my_uart_isr_register(uart_port_t uart_num, void (*fn)(void *), void *arg)
|
||||
{
|
||||
UART_CHECK((uart_num < UART_NUM_MAX), "uart_num error", ESP_ERR_INVALID_ARG);
|
||||
|
@ -552,7 +560,7 @@ static void uart_rx_intr_handler_default(void *param)
|
|||
uart_obj_t *p_uart = (uart_obj_t *)param;
|
||||
uint8_t uart_num = p_uart->uart_num;
|
||||
uart_dev_t *uart_reg = UART[uart_num];
|
||||
int rx_fifo_len = uart_reg->status.rxfifo_cnt;
|
||||
int rx_fifo_len = uart_reg->status.rxfifo_cnt;
|
||||
uint8_t buf_idx = 0;
|
||||
uint32_t uart_intr_status = UART[uart_num]->int_st.val;
|
||||
uart_event_t uart_event;
|
||||
|
@ -718,7 +726,17 @@ static void uart_rx_intr_handler_default(void *param)
|
|||
else
|
||||
{
|
||||
p_uart->rx_buffered_len += p_uart->rx_stash_len;
|
||||
xEventGroupSetBitsFromISR(kUART_Monitoe_event_group, UART_GOT_DATA, pdFALSE);
|
||||
// SWO modify
|
||||
if (kSWO_read_num && p_uart->rx_buffered_len >= kSWO_read_num)
|
||||
{
|
||||
if (kSWO_uart_notify_enable)
|
||||
{
|
||||
kSWO_uart_notify_enable = 0;
|
||||
xEventGroupSetBitsFromISR(kSwoThreadEventGroup, UART_GOT_DATA, pdFALSE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
notify = UART_SELECT_READ_NOTIF;
|
||||
|
@ -744,7 +762,7 @@ static void uart_rx_intr_handler_default(void *param)
|
|||
// SWO modify
|
||||
// Unfortunately, Overflow occurs usually there is no flow control.
|
||||
// Although the overflow situation often occurs,
|
||||
// the buffer stability of the serial port is better,
|
||||
// the buffer stability of the serial port is better,
|
||||
// and there is basically no data loss.
|
||||
////TODO: Can we get rid of this code?
|
||||
SetTraceError(DAP_SWO_BUFFER_OVERRUN);
|
||||
|
@ -804,6 +822,7 @@ static void uart_rx_intr_handler_default(void *param)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
// Fill UART tx_fifo and return a number,
|
||||
// This function by itself is not thread-safe, always call from within a muxed section.
|
||||
static int uart_fill_fifo(uart_port_t uart_num, const char *buffer, uint32_t len)
|
||||
|
@ -904,6 +923,8 @@ int my_uart_write_bytes(uart_port_t uart_num, const char *src, size_t size)
|
|||
return uart_tx_all(uart_num, src, size);
|
||||
}
|
||||
|
||||
|
||||
// return min(length, data length in ring buffer)
|
||||
int my_uart_read_bytes(uart_port_t uart_num, uint8_t *buf, uint32_t length, TickType_t ticks_to_wait)
|
||||
{
|
||||
UART_CHECK((uart_num < UART_NUM_MAX), "uart_num error", (-1));
|
||||
|
@ -934,6 +955,7 @@ int my_uart_read_bytes(uart_port_t uart_num, uint8_t *buf, uint32_t length, Tick
|
|||
}
|
||||
else
|
||||
{
|
||||
// nothing receive
|
||||
xSemaphoreGive(p_uart_obj[uart_num]->rx_mux);
|
||||
return copy_len;
|
||||
}
|
||||
|
@ -974,6 +996,15 @@ int my_uart_read_bytes(uart_port_t uart_num, uint8_t *buf, uint32_t length, Tick
|
|||
p_uart_obj[uart_num]->rx_buffer_full_flg = false;
|
||||
UART_EXIT_CRITICAL();
|
||||
my_uart_enable_rx_intr(p_uart_obj[uart_num]->uart_num);
|
||||
// SWO modify
|
||||
if (uart_num == 0 && kSWO_read_num && p_uart_obj[0]->rx_buffered_len >= kSWO_read_num)
|
||||
{
|
||||
if (kSWO_uart_notify_enable)
|
||||
{
|
||||
kSWO_uart_notify_enable = 0;
|
||||
xEventGroupSetBitsFromISR(kSwoThreadEventGroup, UART_GOT_DATA, pdFALSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -994,6 +1025,7 @@ esp_err_t my_uart_get_buffered_data_len(uart_port_t uart_num, size_t *size)
|
|||
|
||||
esp_err_t my_uart_flush(uart_port_t uart_num) __attribute__((alias("my_uart_flush_input")));
|
||||
|
||||
// flush RX buffer
|
||||
esp_err_t my_uart_flush_input(uart_port_t uart_num)
|
||||
{
|
||||
UART_CHECK((uart_num < UART_NUM_MAX), "uart_num error", ESP_ERR_INVALID_ARG);
|
||||
|
@ -1051,6 +1083,15 @@ esp_err_t my_uart_flush_input(uart_port_t uart_num)
|
|||
p_uart_obj[uart_num]->rx_buffered_len += p_uart_obj[uart_num]->rx_stash_len;
|
||||
p_uart_obj[uart_num]->rx_buffer_full_flg = false;
|
||||
UART_EXIT_CRITICAL();
|
||||
// SWO modify
|
||||
if (uart_num == 0 && kSWO_read_num && p_uart_obj[0]->rx_buffered_len >= kSWO_read_num)
|
||||
{
|
||||
if (kSWO_uart_notify_enable)
|
||||
{
|
||||
kSWO_uart_notify_enable = 0;
|
||||
xEventGroupSetBitsFromISR(kSwoThreadEventGroup, UART_GOT_DATA, pdFALSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1058,7 +1099,7 @@ esp_err_t my_uart_flush_input(uart_port_t uart_num)
|
|||
p_uart->rx_ptr = NULL;
|
||||
p_uart->rx_cur_remain = 0;
|
||||
p_uart->rx_head_ptr = NULL;
|
||||
uart_reset_rx_fifo(uart_num);
|
||||
uart_reset_rx_fifo(uart_num); // reset hardware FIFO
|
||||
my_uart_enable_rx_intr(p_uart_obj[uart_num]->uart_num);
|
||||
xSemaphoreGive(p_uart->rx_mux);
|
||||
return ESP_OK;
|
||||
|
@ -1096,6 +1137,14 @@ esp_err_t my_uart_driver_install(uart_port_t uart_num, int rx_buffer_size, int t
|
|||
p_uart_obj[uart_num]->rx_buffered_len = 0;
|
||||
p_uart_obj[uart_num]->wait_tx_done_flg = false;
|
||||
|
||||
// SWO modify
|
||||
if (uart_num == 0)
|
||||
{
|
||||
kSWO_read_index = 0;
|
||||
kSWO_read_num = 0;
|
||||
kSWO_read_mux = xSemaphoreCreateMutex();
|
||||
}
|
||||
|
||||
if (uart_queue)
|
||||
{
|
||||
p_uart_obj[uart_num]->xQueueUart = xQueueCreate(queue_size, sizeof(uart_event_t));
|
||||
|
@ -1176,6 +1225,12 @@ esp_err_t my_uart_driver_delete(uart_port_t uart_num)
|
|||
my_uart_disable_tx_intr(uart_num);
|
||||
_xt_isr_mask(0x1 << ETS_UART_INUM);
|
||||
|
||||
// SWO modify
|
||||
if (uart_num == 0 && kSWO_read_mux)
|
||||
{
|
||||
vSemaphoreDelete(kSWO_read_mux);
|
||||
}
|
||||
|
||||
if (p_uart_obj[uart_num]->tx_fifo_sem)
|
||||
{
|
||||
vSemaphoreDelete(p_uart_obj[uart_num]->tx_fifo_sem);
|
||||
|
@ -1254,3 +1309,27 @@ esp_err_t my_uart_set_rx_timeout(uart_port_t uart_num, const uint8_t tout_thresh
|
|||
UART_EXIT_CRITICAL();
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
// SWO modify
|
||||
esp_err_t my_uart_read_bytes_async_swo(uint32_t index, uint32_t length)
|
||||
{
|
||||
if (kSWO_read_num > 0) {
|
||||
return ESP_FAIL;
|
||||
}
|
||||
xSemaphoreTake(kSWO_read_mux, (portTickType)portMAX_DELAY);
|
||||
kSWO_read_num = length;
|
||||
kSWO_read_index = index;
|
||||
kSWO_uart_notify_enable = 1;
|
||||
xSemaphoreGive(kSWO_read_mux);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
|
||||
int my_uart_get_rx_buffered_data_len(uart_port_t uart_num)
|
||||
{
|
||||
UART_CHECK((uart_num < UART_NUM_MAX), "uart_num error", ESP_ERR_INVALID_ARG);
|
||||
UART_CHECK((p_uart_obj[uart_num]), "uart driver error", ESP_ERR_INVALID_ARG);
|
||||
|
||||
return p_uart_obj[uart_num]->rx_buffered_len;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
set(COMPONENT_ADD_INCLUDEDIRS ". ../../main")
|
||||
set(COMPONENT_SRCS "MSOS20Descriptors.c USB_handle.c USBd_config.c")
|
||||
set(COMPONENT_SRCS "MSOS20_descriptor.c usb_handle.c usb_descriptor.c")
|
||||
|
||||
register_component()
|
|
@ -1,84 +1,112 @@
|
|||
/**
|
||||
* @file MSOS20Descriptors.c
|
||||
* @author windowsair
|
||||
* @brief Store related data of Microsoft OS 2.0 descriptor
|
||||
* @version 0.1
|
||||
* @date 2019-11-21
|
||||
*
|
||||
* @copyright Copyright (c) 2019
|
||||
*
|
||||
*/
|
||||
|
||||
////TODO: refactoring into structure
|
||||
|
||||
#include <stdint.h>
|
||||
#include "MSOS20Descriptors.h"
|
||||
|
||||
#define USBShort(ui16Value) ((ui16Value) & 0xff), ((ui16Value) >> 8) //((ui16Value) & 0xFF),(((ui16Value) >> 8) & 0xFF)
|
||||
|
||||
|
||||
|
||||
// Microsoft OS 2.0 descriptor set header
|
||||
const uint8_t msOs20DescriptorSetHeader[kLengthOfMsOS20] =
|
||||
{
|
||||
// Microsoft OS 2.0 Descriptor Set header (Table 10)
|
||||
0x0A, 0x00, // wLength (Shall be set to 0x0A)
|
||||
MS_OS_20_SET_HEADER_DESCRIPTOR, 0x00,
|
||||
0x00, 0x00, 0x03, 0x06, // dwWindowsVersion: Windows 8.1 (NTDDI_WINBLUE)
|
||||
USBShort(kLengthOfMsOS20), // wTotalLength
|
||||
|
||||
// Support WinUSB
|
||||
// See https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/automatic-installation-of-winusb
|
||||
|
||||
// Microsoft OS 2.0 compatible ID descriptor (Table 13)
|
||||
0x14, 0x00, // wLength
|
||||
USBShort(MS_OS_20_FEATURE_COMPATIBLE_ID), // wDescriptorType
|
||||
'W', 'I', 'N', 'U', 'S', 'B', 0x00, 0x00, // compatibleID
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // subCompatibleID
|
||||
|
||||
// Microsoft OS 2.0 registry property descriptor (Table 14)
|
||||
0x84, 0x00, // wLength
|
||||
USBShort(MS_OS_20_FEATURE_REG_PROPERTY),
|
||||
0x07, 0x00, // wPropertyDataType: REG_MULTI_SZ (Unicode Strings)
|
||||
0x2A, 0x00, // wPropertyNameLength
|
||||
'D',0,'e',0,'v',0,'i',0,'c',0,'e',0,'I',0,'n',0,'t',0,'e',0,'r',0,
|
||||
'f',0,'a',0,'c',0,'e',0,'G',0,'U',0,'I',0,'D',0,'s',0,0,0,
|
||||
// Set to "DeviceInterfaceGUID" to support WinUSB
|
||||
0x50, 0x00, // wPropertyDataLength
|
||||
// WinUSB GUID
|
||||
'{',0,'C',0,'D',0,'B',0,'3',0,'B',0,'5',0,'A',0,'D',0,'-',0,
|
||||
'2',0,'9',0,'3',0,'B',0,'-',0,'4',0,'6',0,'6',0,'3',0,'-',0,
|
||||
'A',0,'A',0,'3',0,'6',0,'-',0,'1',0,'A',0,'A',0,'E',0,'4',0,
|
||||
'6',0,'4',0,'6',0,'3',0,'7',0,'7',0,'6',0,'}',0,0,0,0,0,
|
||||
// identify a CMSIS-DAP V2 configuration,
|
||||
// must set to "{CDB3B5AD-293B-4663-AA36-1AAE46463776}"
|
||||
|
||||
};
|
||||
|
||||
const uint8_t bosDescriptor[kLengthOfBos] =
|
||||
{
|
||||
// Universal Serial Bus 3.0 Specification, Table 9-9.
|
||||
0x05, // bLength of this descriptor
|
||||
USB_DESCRIPTOR_TYPE_BOS, // BOS Descriptor type(Constant)
|
||||
USBShort(kLengthOfBos), // wLength
|
||||
0x01, // bNumDeviceCaps -> only 0x01 for OS2.0 descriptor
|
||||
|
||||
// Microsoft OS 2.0 platform capability descriptor header (Table 4)
|
||||
// See also:
|
||||
// Universal Serial Bus 3.0 Specification : Format of a Device Capability Descriptor, Table 9-10.
|
||||
|
||||
0x1C, // bLength of this first device capability descriptor
|
||||
// bLength -> The total length of the remaining arrays containing this field
|
||||
USB_DESCRIPTOR_TYPE_DEVICE_CAPABILITY, // bDescriptorType
|
||||
USB_DEVICE_CAPABILITY_TYPE_PLATFORM, // bDevCapabilityType
|
||||
|
||||
// Capability-Dependent (See USB3.0 Specification Table 9-10.)
|
||||
0x00, // bReserved
|
||||
USB_DEVICE_CAPABILITY_UUID, // MS_OS_20_Platform_Capability_ID
|
||||
|
||||
0x00, 0x00, 0x03, 0x06, // dwWindowsVersion: Windows 8.1 (NTDDI_WINBLUE)
|
||||
USBShort(kLengthOfMsOS20), // wMSOSDescriptorSetTotalLength(length of descriptor set header)
|
||||
kValueOfbMS_VendorCode, // bMS_VendorCode (0x01 will be ok)
|
||||
////TODO:change this
|
||||
0, // bAltEnumCode
|
||||
/**
|
||||
* @file MSOS20_descriptor.c
|
||||
* @author windowsair
|
||||
* @brief Store related data of Microsoft OS 2.0 descriptor
|
||||
* @change: 2021-5-12 Add support for USB 3.0
|
||||
* @version 0.2
|
||||
* @date 2021-5-12
|
||||
*
|
||||
* @copyright Copyright (c) 2021
|
||||
*
|
||||
*/
|
||||
|
||||
////TODO: refactoring into structure
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "components/USBIP/MSOS20_descriptor.h"
|
||||
|
||||
#define USBShort(ui16Value) ((ui16Value) & 0xff), ((ui16Value) >> 8) //((ui16Value) & 0xFF),(((ui16Value) >> 8) & 0xFF)
|
||||
|
||||
|
||||
|
||||
// Microsoft OS 2.0 descriptor set header
|
||||
const uint8_t msOs20DescriptorSetHeader[kLengthOfMsOS20] =
|
||||
{
|
||||
// Microsoft OS 2.0 Descriptor Set header (Table 10)
|
||||
0x0A, 0x00, // wLength (Shall be set to 0x0A)
|
||||
MS_OS_20_SET_HEADER_DESCRIPTOR, 0x00,
|
||||
0x00, 0x00, 0x03, 0x06, // dwWindowsVersion: Windows 8.1 (NTDDI_WINBLUE)
|
||||
USBShort(kLengthOfMsOS20), // wTotalLength
|
||||
|
||||
// Support WinUSB
|
||||
// See https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/automatic-installation-of-winusb
|
||||
|
||||
// Microsoft OS 2.0 compatible ID descriptor (Table 13)
|
||||
0x14, 0x00, // wLength
|
||||
USBShort(MS_OS_20_FEATURE_COMPATIBLE_ID), // wDescriptorType
|
||||
'W', 'I', 'N', 'U', 'S', 'B', 0x00, 0x00, // compatibleID
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // subCompatibleID
|
||||
|
||||
// Microsoft OS 2.0 registry property descriptor (Table 14)
|
||||
0x84, 0x00, // wLength
|
||||
USBShort(MS_OS_20_FEATURE_REG_PROPERTY),
|
||||
0x07, 0x00, // wPropertyDataType: REG_MULTI_SZ (Unicode Strings)
|
||||
0x2A, 0x00, // wPropertyNameLength
|
||||
'D',0,'e',0,'v',0,'i',0,'c',0,'e',0,'I',0,'n',0,'t',0,'e',0,'r',0,
|
||||
'f',0,'a',0,'c',0,'e',0,'G',0,'U',0,'I',0,'D',0,'s',0,0,0,
|
||||
// Set to "DeviceInterfaceGUID" to support WinUSB
|
||||
0x50, 0x00, // wPropertyDataLength
|
||||
// WinUSB GUID
|
||||
'{',0,'C',0,'D',0,'B',0,'3',0,'B',0,'5',0,'A',0,'D',0,'-',0,
|
||||
'2',0,'9',0,'3',0,'B',0,'-',0,'4',0,'6',0,'6',0,'3',0,'-',0,
|
||||
'A',0,'A',0,'3',0,'6',0,'-',0,'1',0,'A',0,'A',0,'E',0,'4',0,
|
||||
'6',0,'4',0,'6',0,'3',0,'7',0,'7',0,'6',0,'}',0,0,0,0,0,
|
||||
// identify a CMSIS-DAP V2 configuration,
|
||||
// must set to "{CDB3B5AD-293B-4663-AA36-1AAE46463776}"
|
||||
|
||||
};
|
||||
|
||||
const uint8_t bosDescriptor[kLengthOfBos] =
|
||||
{
|
||||
// USB 3.0 Specification, Table 9-9.
|
||||
0x05, // bLength of this descriptor
|
||||
USB_DESCRIPTOR_TYPE_BOS, // BOS Descriptor type(Constant)
|
||||
USBShort(kLengthOfBos), // wLength
|
||||
|
||||
|
||||
#if (USE_USB_3_0 == 1)
|
||||
0x03, // bNumDeviceCaps -> USB2.0 extension & SuperSpeed USB Device & OS2.0 descriptor
|
||||
#else
|
||||
0x01, // bNumDeviceCaps -> only 0x01 for OS2.0 descriptor
|
||||
#endif // USE_USB_3_0 == 1
|
||||
|
||||
#if (USE_USB_3_0 == 1)
|
||||
// USB 2.0 extension, USB 3.0 Specification, Table 9-12.
|
||||
0x07, // bLength of this descriptor
|
||||
USB_DESCRIPTOR_TYPE_DEVICE_CAPABILITY, // DEVICE CAPABILITY Descriptor type
|
||||
USB_DEVICE_CAPABILITY_TYPE_USB2_0_EXTENSION, // Capability type: USB 2.0 EXTENSION
|
||||
0x02, 0x00, 0x00, 0x00, // bmAttributes -> LPM Support
|
||||
|
||||
// SuperSpeed USB Device, USB 3.0 Specification, Table 9-13.
|
||||
0x0A, // bLength of this descriptor
|
||||
USB_DESCRIPTOR_TYPE_DEVICE_CAPABILITY, // DEVICE CAPABILITY Descriptor type
|
||||
USB_DEVICE_CAPABILITY_TYPE_SUPERSPEED_USB, // Capability type: SUPERSPEED_USB
|
||||
0x00, // bmAttributes -> LTM Capable
|
||||
0x08, 0x00, // wSpeedsSupported -> only support SuperSpeed
|
||||
0x03, // bFunctionalitySupport
|
||||
0x00, // bU1DevExitLat -> 0 may be ok
|
||||
0x00, 0x00, // wU2DevExitLat -> 0 may be ok
|
||||
#endif // USE_USB_3_0 == 1
|
||||
|
||||
|
||||
|
||||
// Microsoft OS 2.0 platform capability descriptor header (Table 4)
|
||||
// See also:
|
||||
// USB 3.0 Specification : Format of a Device Capability Descriptor, Table 9-10.
|
||||
|
||||
0x1C, // bLength of this first device capability descriptor
|
||||
// bLength -> The total length of the remaining arrays containing this field
|
||||
USB_DESCRIPTOR_TYPE_DEVICE_CAPABILITY, // bDescriptorType
|
||||
USB_DEVICE_CAPABILITY_TYPE_PLATFORM, // bDevCapabilityType
|
||||
|
||||
// Capability-Dependent (See USB 3.0 Specification Table 9-10.)
|
||||
0x00, // bReserved
|
||||
USB_DEVICE_CAPABILITY_UUID, // MS_OS_20_Platform_Capability_ID
|
||||
|
||||
0x00, 0x00, 0x03, 0x06, // dwWindowsVersion: Windows 8.1 (NTDDI_WINBLUE)
|
||||
USBShort(kLengthOfMsOS20), // wMSOSDescriptorSetTotalLength(length of descriptor set header)
|
||||
kValueOfbMS_VendorCode, // bMS_VendorCode (0x01 will be ok)
|
||||
////TODO:change this
|
||||
0, // bAltEnumCode
|
||||
};
|
|
@ -1,81 +1,93 @@
|
|||
/**
|
||||
* @file MSOS20Descriptors.h
|
||||
* @author windowsair
|
||||
* @brief
|
||||
* @version 0.1
|
||||
* @date 2019-11-21
|
||||
*
|
||||
* @copyright Copyright (c) 2019
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __MSOS20DESCRIPTORS_H__
|
||||
#define __MSOS20DESCRIPTORS_H__
|
||||
|
||||
#define kLengthOfMsOS20 0xA2
|
||||
#define kLengthOfBos 0x21
|
||||
#define kValueOfbMS_VendorCode 0x01// Just set to 0x01
|
||||
extern const uint8_t bosDescriptor[kLengthOfBos];
|
||||
extern const uint8_t msOs20DescriptorSetHeader[kLengthOfMsOS20];
|
||||
|
||||
/* Microsoft OS 2.0 Descriptors BEGIN */
|
||||
|
||||
// Platform capability BOS descriptor, Table 1.
|
||||
#define USB_DEVICE_CAPABILITY_TYPE_PLATFORM 5
|
||||
|
||||
// Platform capability UUID, Table 3.
|
||||
// {D8DD60DF-4589-4CC7-9CD2-659D9E648A9F}
|
||||
#define USB_DEVICE_CAPABILITY_UUID 0xDF, 0x60, 0xDD, 0xD8, 0x89, 0x45, 0xC7, 0x4C, 0x9C, 0xD2, 0x65, 0x9D, 0x9E, 0x64, 0x8A, 0x9F
|
||||
|
||||
|
||||
// Microsoft OS 2.0 descriptor wIndex values enum, Table 8.
|
||||
#define MS_OS_20_DESCRIPTOR_INDEX 7
|
||||
#define MS_OS_20_SET_ALT_ENUMERATION 8
|
||||
|
||||
|
||||
// Microsoft OS 2.0 descriptor types enum for wDescriptorType values, Table 9.
|
||||
#define MS_OS_20_SET_HEADER_DESCRIPTOR 0x00
|
||||
#define MS_OS_20_SUBSET_HEADER_CONFIGURATION 0x01
|
||||
#define MS_OS_20_SUBSET_HEADER_FUNCTION 0x02
|
||||
#define MS_OS_20_FEATURE_COMPATIBLE_ID 0x03
|
||||
#define MS_OS_20_FEATURE_REG_PROPERTY 0x04
|
||||
#define MS_OS_20_FEATURE_MIN_RESUME_TIME 0x05
|
||||
#define MS_OS_20_FEATURE_MODEL_ID 0x06
|
||||
#define MS_OS_20_FEATURE_CCGP_DEVICE 0x07
|
||||
|
||||
/* Microsoft OS 2.0 Descriptors END */
|
||||
|
||||
|
||||
|
||||
/* Wireless USB Standard Extension Descriptor Types BEGIN */
|
||||
|
||||
// Wireless USB Specification 1.1 revison 1.1, Table 7-21.
|
||||
#define USB_DESCRIPTOR_TYPE_SECURITY 12
|
||||
#define USB_DESCRIPTOR_TYPE_KEY 13
|
||||
#define USB_DESCRIPTOR_TYPE_ENCRYPTION_TYPE 14
|
||||
#define USB_DESCRIPTOR_TYPE_BOS 15
|
||||
#define USB_DESCRIPTOR_TYPE_DEVICE_CAPABILITY 16
|
||||
#define USB_DESCRIPTOR_TYPE_WIRELESS_ENDPOINT_COMPANION 17
|
||||
|
||||
/* Wireless USB Standard Extension Descriptor Types END */
|
||||
|
||||
|
||||
/* Microsoft Extended Compat ID OS Feature Descriptor BEGIN */
|
||||
|
||||
#define USB_MS_EXTENDED_COMPAT_ID_VERSION 0x0100
|
||||
#define USB_MS_EXTENDED_COMPAT_ID_TYPE 0x04
|
||||
|
||||
#define USB_COMPATID_NONE {0}
|
||||
#define USB_SUBCOMPATID_NONE {0}
|
||||
#define USB_COMPATID_WINUSB "WINUSB\0"
|
||||
#define USB_COMPATID_RNDIS "RNDIS\0\0"
|
||||
#define USB_COMPATID_PTP "PTP\0\0\0\0"
|
||||
#define USB_COMPATID_MTP "MTP\0\0\0\0"
|
||||
#define USB_COMPATID_BLUETOOTH "BLUTUTH"
|
||||
#define USB_SUBCOMPATID_BT_V11 "11\0\0\0\0\0"
|
||||
#define USB_SUBCOMPATID_BT_V12 "12\0\0\0\0\0"
|
||||
#define USB_SUBCOMPATID_BT_V20EDR "EDR\0\0\0\0"
|
||||
|
||||
/* Microsoft Extended Compat ID OS Feature Descriptor END */
|
||||
|
||||
/**
|
||||
* @file MSOS20_descriptor.h
|
||||
* @author windowsair
|
||||
* @brief
|
||||
* @version 0.2
|
||||
* @date 2021-5-12
|
||||
*
|
||||
* @copyright Copyright (c) 2021
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __MSOS20_DESCRIPTOR_H__
|
||||
#define __MSOS20_DESCRIPTOR_H__
|
||||
|
||||
|
||||
#define kLengthOfMsOS20 0xA2
|
||||
|
||||
#if (USE_USB_3_0 == 1)
|
||||
#define kLengthOfBos 0x32
|
||||
#else
|
||||
#define kLengthOfBos 0x21
|
||||
#endif // USE_USB_3_0 == 1
|
||||
|
||||
#define kValueOfbMS_VendorCode 0x01// Just set to 0x01
|
||||
extern const uint8_t bosDescriptor[kLengthOfBos];
|
||||
extern const uint8_t msOs20DescriptorSetHeader[kLengthOfMsOS20];
|
||||
|
||||
/* Microsoft OS 2.0 Descriptors BEGIN */
|
||||
|
||||
// Platform capability BOS descriptor, Table 1.
|
||||
#define USB_DEVICE_CAPABILITY_TYPE_PLATFORM 5
|
||||
|
||||
// USB 2.0 Extension Descriptor, USB3.0 Specification Table 9-11
|
||||
#define USB_DEVICE_CAPABILITY_TYPE_USB2_0_EXTENSION 2
|
||||
// SuperSpeed USB specific device level capabilities, USB3.0 Specification Table 9-11
|
||||
#define USB_DEVICE_CAPABILITY_TYPE_SUPERSPEED_USB 3
|
||||
|
||||
// Platform capability UUID, Table 3.
|
||||
// {D8DD60DF-4589-4CC7-9CD2-659D9E648A9F}
|
||||
#define USB_DEVICE_CAPABILITY_UUID 0xDF, 0x60, 0xDD, 0xD8, 0x89, 0x45, 0xC7, 0x4C, 0x9C, 0xD2, 0x65, 0x9D, 0x9E, 0x64, 0x8A, 0x9F
|
||||
|
||||
|
||||
// Microsoft OS 2.0 descriptor wIndex values enum, Table 8.
|
||||
#define MS_OS_20_DESCRIPTOR_INDEX 7
|
||||
#define MS_OS_20_SET_ALT_ENUMERATION 8
|
||||
|
||||
|
||||
// Microsoft OS 2.0 descriptor types enum for wDescriptorType values, Table 9.
|
||||
#define MS_OS_20_SET_HEADER_DESCRIPTOR 0x00
|
||||
#define MS_OS_20_SUBSET_HEADER_CONFIGURATION 0x01
|
||||
#define MS_OS_20_SUBSET_HEADER_FUNCTION 0x02
|
||||
#define MS_OS_20_FEATURE_COMPATIBLE_ID 0x03
|
||||
#define MS_OS_20_FEATURE_REG_PROPERTY 0x04
|
||||
#define MS_OS_20_FEATURE_MIN_RESUME_TIME 0x05
|
||||
#define MS_OS_20_FEATURE_MODEL_ID 0x06
|
||||
#define MS_OS_20_FEATURE_CCGP_DEVICE 0x07
|
||||
|
||||
/* Microsoft OS 2.0 Descriptors END */
|
||||
|
||||
|
||||
|
||||
/* Wireless USB Standard Extension Descriptor Types BEGIN */
|
||||
|
||||
// Wireless USB Specification 1.1 revison 1.1, Table 7-21.
|
||||
#define USB_DESCRIPTOR_TYPE_SECURITY 12
|
||||
#define USB_DESCRIPTOR_TYPE_KEY 13
|
||||
#define USB_DESCRIPTOR_TYPE_ENCRYPTION_TYPE 14
|
||||
#define USB_DESCRIPTOR_TYPE_BOS 15
|
||||
#define USB_DESCRIPTOR_TYPE_DEVICE_CAPABILITY 16
|
||||
#define USB_DESCRIPTOR_TYPE_WIRELESS_ENDPOINT_COMPANION 17
|
||||
|
||||
/* Wireless USB Standard Extension Descriptor Types END */
|
||||
|
||||
|
||||
/* Microsoft Extended Compat ID OS Feature Descriptor BEGIN */
|
||||
|
||||
#define USB_MS_EXTENDED_COMPAT_ID_VERSION 0x0100
|
||||
#define USB_MS_EXTENDED_COMPAT_ID_TYPE 0x04
|
||||
|
||||
#define USB_COMPATID_NONE {0}
|
||||
#define USB_SUBCOMPATID_NONE {0}
|
||||
#define USB_COMPATID_WINUSB "WINUSB\0"
|
||||
#define USB_COMPATID_RNDIS "RNDIS\0\0"
|
||||
#define USB_COMPATID_PTP "PTP\0\0\0\0"
|
||||
#define USB_COMPATID_MTP "MTP\0\0\0\0"
|
||||
#define USB_COMPATID_BLUETOOTH "BLUTUTH"
|
||||
#define USB_SUBCOMPATID_BT_V11 "11\0\0\0\0\0"
|
||||
#define USB_SUBCOMPATID_BT_V12 "12\0\0\0\0\0"
|
||||
#define USB_SUBCOMPATID_BT_V20EDR "EDR\0\0\0\0"
|
||||
|
||||
/* Microsoft Extended Compat ID OS Feature Descriptor END */
|
||||
|
||||
#endif
|
|
@ -3,9 +3,9 @@
|
|||
* @brief Modify
|
||||
* @version 0.1
|
||||
* @date 2020-01-22
|
||||
*
|
||||
*
|
||||
* @copyright Copyright (c) 2020
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
//
|
||||
|
@ -119,6 +119,7 @@ typedef struct
|
|||
#define USB_DT_OTHER_SPEED_CONFIGURATION 7
|
||||
#define USB_DT_INTERFACE_POWER 8
|
||||
#define USB_DT_BOS 15
|
||||
#define USB_DT_SUPERSPEED_USB_ENDPOINT_COMPANION 48
|
||||
/* From ECNs */
|
||||
#define USB_DT_OTG 9
|
||||
#define USB_DT_DEBUG 10
|
||||
|
@ -234,7 +235,7 @@ typedef struct
|
|||
|
||||
///////////////////////////////////////////////////////////////
|
||||
/* USB Standard Endpoint Descriptor - Table 9-13 */
|
||||
typedef struct
|
||||
typedef struct
|
||||
{
|
||||
uint8_t bLength;
|
||||
uint8_t bDescriptorType;
|
||||
|
|
|
@ -1,24 +1,26 @@
|
|||
////TODO: refactoring into structure
|
||||
/**
|
||||
* @file USBd_config.c
|
||||
* @file usb_descriptor.c
|
||||
* @brief Standard USB Descriptor Definitions
|
||||
fix bugs 2020-1-23
|
||||
* @change: 2020-1-23 : fix bugs
|
||||
* 2021-5-12 : Add support for USB 3.0
|
||||
* @version 0.2
|
||||
* @date 2020-1-23
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "USBd_config.h"
|
||||
#include "usb_defs.h"
|
||||
|
||||
#define USBShort(ui16Value) ((ui16Value) & 0xff), ((ui16Value) >> 8) //((ui16Value) & 0xFF),(((ui16Value) >> 8) & 0xFF)
|
||||
#include "components/USBIP/usb_descriptor.h"
|
||||
#include "components/USBIP/usb_defs.h"
|
||||
|
||||
#define USBShort(ui16Value) ((ui16Value) & 0xff), ((ui16Value) >> 8)
|
||||
|
||||
|
||||
/**
|
||||
* @brief step 1. Build Standard Device Descriptor
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
// Standard Device Descriptor
|
||||
|
@ -28,18 +30,28 @@ const uint8_t kUSBd0DeviceDescriptor[0x12] =
|
|||
USB_DT_DEVICE, // bDescriptorType
|
||||
|
||||
#if (USE_WINUSB == 1)
|
||||
USBShort(0x0210), // bcdUSB
|
||||
|
||||
#if (USE_USB_3_0 == 1)
|
||||
USBShort(0x0300), // bcdUSB
|
||||
#else
|
||||
USBShort(0x0200), // bcdUSB
|
||||
#endif
|
||||
USBShort(0x210), // bcdUSB
|
||||
#endif // USE_USB_3_0 == 1
|
||||
|
||||
#else
|
||||
USBShort(0x0200), // bcdUSB
|
||||
#endif // (USE_WINUSB == 1)
|
||||
////TODO: Is it also available elsewhere?
|
||||
|
||||
// We need to use a device other than the USB-IF standard, set to 0x00
|
||||
0x00, // bDeviceClass
|
||||
0x00, // bDeviceSubClass
|
||||
0x00, // bDeviceProtocol
|
||||
|
||||
|
||||
#if (USE_USB_3_0 == 1)
|
||||
0x09, // bMaxPacketSize0, for USB 3.0 must set to 0x09(2^9)
|
||||
#else
|
||||
USBD0_MAX_PACKET0, // bMaxPacketSize0 Maximum packet size for default pipe.
|
||||
#endif
|
||||
USBShort(USBD0_DEV_DESC_IDVENDOR), // idVendor Vendor ID (VID).
|
||||
USBShort(USBD0_DEV_DESC_IDPRODUCT), // idProduct Product ID (PID).
|
||||
USBShort(USBD0_DEV_DESC_BCDDEVICE), // bcdDevice Device Version BCD.
|
||||
|
@ -54,25 +66,25 @@ const uint8_t kUSBd0DeviceDescriptor[0x12] =
|
|||
|
||||
/**
|
||||
* @brief step 2. Buid Standard Configuration Descriptor
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
// Standard Interface Descriptor
|
||||
|
||||
#if (USE_WINUSB ==1)
|
||||
const uint8_t kUSBd0InterfaceDescriptor[0x1E]=
|
||||
const uint8_t kUSBd0InterfaceDescriptor[]=
|
||||
{
|
||||
0x09, // bLength
|
||||
USB_DT_INTERFACE, // bDescriptorType
|
||||
USBD_CUSTOM_CLASS0_IF0_NUM, // bInterfaceNumber
|
||||
USBD_CUSTOM_CLASS0_IF0_ALT, // bAlternateSetting
|
||||
USBD_CUSTOM_CLASS0_IF0_NUM, // bInterfaceNumber
|
||||
USBD_CUSTOM_CLASS0_IF0_ALT, // bAlternateSetting
|
||||
0x03, // bNumEndpoints(we will use 3 endpoints)
|
||||
//
|
||||
USBD_CUSTOM_CLASS0_IF0_CLASS, // bInterfaceClass
|
||||
USBD_CUSTOM_CLASS0_IF0_SUBCLASS, // bInterfaceSubClass
|
||||
//
|
||||
USBD_CUSTOM_CLASS0_IF0_CLASS, // bInterfaceClass
|
||||
USBD_CUSTOM_CLASS0_IF0_SUBCLASS, // bInterfaceSubClass
|
||||
USBD_CUSTOM_CLASS0_IF0_PROTOCOL, // bInterfaceProtocol
|
||||
0x00, // iInterface
|
||||
0x00, // iInterface
|
||||
// Index of string descriptor describing this interface
|
||||
////TODO: fix this 0x04 ?
|
||||
|
||||
|
@ -82,46 +94,73 @@ const uint8_t kUSBd0InterfaceDescriptor[0x1E]=
|
|||
// Endpoint 1: Bulk Out – used for commands received from host PC.
|
||||
// Endpoint 2: Bulk In – used for responses send to host PC.
|
||||
// Endpoint 3: Bulk In (optional) – used for streaming SWO trace
|
||||
|
||||
// ATTENTION:
|
||||
|
||||
// ATTENTION:
|
||||
// physical endpoint 1 indeed included two "endpoints": Bulk OUT and Bulk IN
|
||||
// physical endpoint 1 -> Endpoint 1 & Endpoint 2
|
||||
// physical endpoint 2 -> Endpoint 3
|
||||
|
||||
// See also :
|
||||
// http://www.keil.com/pack/doc/CMSIS/DAP/html/group__DAP__ConfigUSB__gr.html
|
||||
|
||||
// http://www.keil.com/pack/doc/CMSIS/DAP/html/group__DAP__ConfigUSB__gr.html
|
||||
|
||||
/* Pysical endpoint 1 */
|
||||
|
||||
// "Endpoint 1: Bulk Out – used for commands received from host PC." PC -> Device
|
||||
0x07, // bLength
|
||||
USB_DT_ENDPOINT, // bDescriptorType
|
||||
0x07, // bLength
|
||||
USB_DT_ENDPOINT, // bDescriptorType
|
||||
0x01, // bEndpointAddress
|
||||
USB_ENDPOINT_ATTR_BULK, // bmAttributes
|
||||
USBShort(512), // wMaxPacketSize
|
||||
// We assume that it always runs in High Speed.
|
||||
0x00, // bInterval
|
||||
USB_ENDPOINT_ATTR_BULK, // bmAttributes
|
||||
USBShort(USB_ENDPOINT_SIZE), // wMaxPacketSize
|
||||
0x00, // bInterval
|
||||
|
||||
/* SuperSpeed Endpoint Companion */
|
||||
#if (USE_USB_3_0 == 1)
|
||||
0x06, // bLength
|
||||
USB_DT_SUPERSPEED_USB_ENDPOINT_COMPANION, // bDescriptorType
|
||||
0x00, // bMaxBurst
|
||||
0x00, // bmAttributes(MaxStream for Bulk)
|
||||
0x00, 0x00, // wBytesPerInterval -> 0 for Bulk
|
||||
#endif // USE_USB_3_0 == 1
|
||||
|
||||
|
||||
/* Pysical endpoint 1 */
|
||||
|
||||
|
||||
// "Endpoint 2: Bulk In – used for responses send to host PC." Device -> PC
|
||||
0x07, // bLength
|
||||
USB_DT_ENDPOINT, // bDescriptorType
|
||||
0x07, // bLength
|
||||
USB_DT_ENDPOINT, // bDescriptorType
|
||||
0x81, // bEndpointAddress
|
||||
USB_ENDPOINT_ATTR_BULK, // bmAttributes
|
||||
USBShort(512), // wMaxPacketSize
|
||||
0x00, // bInterval
|
||||
USB_ENDPOINT_ATTR_BULK, // bmAttributes
|
||||
USBShort(USB_ENDPOINT_SIZE), // wMaxPacketSize
|
||||
0x00, // bInterval
|
||||
|
||||
/* SuperSpeed Endpoint Companion */
|
||||
#if (USE_USB_3_0 == 1)
|
||||
0x06, // bLength
|
||||
USB_DT_SUPERSPEED_USB_ENDPOINT_COMPANION, // bDescriptorType
|
||||
0x00, // bMaxBurst
|
||||
0x00, // bmAttributes(MaxStream for Bulk)
|
||||
0x00, 0x00, // wBytesPerInterval -> 0 for Bulk
|
||||
#endif // USE_USB_3_0 == 1
|
||||
|
||||
|
||||
/* Pysical endpoint 2 */
|
||||
|
||||
// "Endpoint 3: Bulk In (optional) – used for streaming SWO trace" Device -> PC
|
||||
0x07, // bLength
|
||||
USB_DT_ENDPOINT, // bDescriptorType
|
||||
0x82, // bEndpointAddress
|
||||
USB_ENDPOINT_ATTR_BULK, // bmAttributes
|
||||
USBShort(512), // wMaxPacketSize
|
||||
0x00, // bInterval
|
||||
|
||||
// "Endpoint 3: Bulk In (optional) – used for streaming SWO trace" Device -> PC
|
||||
0x07, // bLength
|
||||
USB_DT_ENDPOINT, // bDescriptorType
|
||||
0x82, // bEndpointAddress
|
||||
USB_ENDPOINT_ATTR_BULK, // bmAttributes
|
||||
USBShort(USB_ENDPOINT_SIZE), // wMaxPacketSize
|
||||
0x00, // bInterval
|
||||
|
||||
/* SuperSpeed Endpoint Companion */
|
||||
#if (USE_USB_3_0 == 1)
|
||||
0x06, // bLength
|
||||
USB_DT_SUPERSPEED_USB_ENDPOINT_COMPANION, // bDescriptorType
|
||||
0x00, // bMaxBurst
|
||||
0x00, // bmAttributes(MaxStream for Bulk)
|
||||
0x00, 0x00, // wBytesPerInterval -> 0 for Bulk
|
||||
#endif // USE_USB_3_0 == 1
|
||||
|
||||
};
|
||||
|
||||
|
@ -130,16 +169,16 @@ const uint8_t kUSBd0InterfaceDescriptor[0x20]=
|
|||
{
|
||||
0x09, // bLength
|
||||
USB_DT_INTERFACE, // bDescriptorType
|
||||
USBD_CUSTOM_CLASS0_IF0_NUM, // bInterfaceNumber
|
||||
USBD_CUSTOM_CLASS0_IF0_ALT, // bAlternateSetting
|
||||
USBD_CUSTOM_CLASS0_IF0_NUM, // bInterfaceNumber
|
||||
USBD_CUSTOM_CLASS0_IF0_ALT, // bAlternateSetting
|
||||
0x02, // bNumEndpoints ----> 2 endpoint for USB HID
|
||||
//
|
||||
USBD_CUSTOM_CLASS0_IF0_CLASS, // bInterfaceClass
|
||||
USBD_CUSTOM_CLASS0_IF0_SUBCLASS, // bInterfaceSubClass
|
||||
//
|
||||
USBD_CUSTOM_CLASS0_IF0_CLASS, // bInterfaceClass
|
||||
USBD_CUSTOM_CLASS0_IF0_SUBCLASS, // bInterfaceSubClass
|
||||
USBD_CUSTOM_CLASS0_IF0_PROTOCOL, // bInterfaceProtocol
|
||||
0x00, // iInterface
|
||||
0x00, // iInterface
|
||||
// Index of string descriptor describing this interface
|
||||
|
||||
|
||||
// HID Descriptor
|
||||
0x09, // bLength
|
||||
0x21, // bDescriptorType
|
||||
|
@ -147,29 +186,29 @@ const uint8_t kUSBd0InterfaceDescriptor[0x20]=
|
|||
0x00, // bCountryCode
|
||||
0x01, // bNumDescriptors
|
||||
0x22, // bDescriptorType1
|
||||
0x21, 0x00, // wDescriptorLength1
|
||||
0x21, 0x00, // wDescriptorLength1
|
||||
|
||||
// Standard Endpoint Descriptor
|
||||
|
||||
// We perform all transfer operations on Pysical endpoint 1.
|
||||
|
||||
|
||||
/* Pysical endpoint 1 */
|
||||
|
||||
0x07, // bLength
|
||||
USB_DT_ENDPOINT, // bDescriptorType
|
||||
0x07, // bLength
|
||||
USB_DT_ENDPOINT, // bDescriptorType
|
||||
0x81, // bEndpointAddress
|
||||
USB_ENDPOINT_ATTR_INTERRUPT, // bmAttributes
|
||||
USBShort(64), // wMaxPacketSize
|
||||
0x01, // bInterval
|
||||
USB_ENDPOINT_ATTR_INTERRUPT, // bmAttributes
|
||||
USBShort(64), // wMaxPacketSize
|
||||
0x01, // bInterval
|
||||
|
||||
/* Pysical endpoint 1 */
|
||||
|
||||
0x07, // bLength
|
||||
USB_DT_ENDPOINT, // bDescriptorType
|
||||
|
||||
0x07, // bLength
|
||||
USB_DT_ENDPOINT, // bDescriptorType
|
||||
0x01, // bEndpointAddress
|
||||
USB_ENDPOINT_ATTR_INTERRUPT, // bmAttributes
|
||||
USBShort(64), // wMaxPacketSize
|
||||
0x01, // bInterval
|
||||
USB_ENDPOINT_ATTR_INTERRUPT, // bmAttributes
|
||||
USBShort(64), // wMaxPacketSize
|
||||
0x01, // bInterval
|
||||
};
|
||||
#endif
|
||||
|
||||
|
@ -182,12 +221,12 @@ const uint8_t kUSBd0ConfigDescriptor[LENGTHOFCONFIGDESCRIPTOR] =
|
|||
// Configuration descriptor header.
|
||||
|
||||
0x09, // bLength
|
||||
USB_DT_CONFIGURATION, // bDescriptorType
|
||||
|
||||
USBShort((sizeof(kUSBd0InterfaceDescriptor)) + (LENGTHOFCONFIGDESCRIPTOR)),
|
||||
USB_DT_CONFIGURATION, // bDescriptorType
|
||||
|
||||
USBShort((sizeof(kUSBd0InterfaceDescriptor)) + (LENGTHOFCONFIGDESCRIPTOR)),
|
||||
// wTotalLength
|
||||
|
||||
0x01, // bNumInterfaces
|
||||
0x01, // bNumInterfaces
|
||||
// There is only one interface in the CMSIS-DAP project
|
||||
0x01, // bConfigurationValue: 0x01 is used to select this configuration */
|
||||
0x00, // iConfiguration: no string to describe this configuration */
|
||||
|
@ -202,12 +241,12 @@ const uint8_t kUSBd0ConfigDescriptor[LENGTHOFCONFIGDESCRIPTOR] =
|
|||
// Configuration descriptor header.
|
||||
|
||||
0x09, // bLength
|
||||
USB_DT_CONFIGURATION, // bDescriptorType
|
||||
|
||||
USBShort((sizeof(kUSBd0InterfaceDescriptor)) + (LENGTHOFCONFIGDESCRIPTOR)),
|
||||
USB_DT_CONFIGURATION, // bDescriptorType
|
||||
|
||||
USBShort((sizeof(kUSBd0InterfaceDescriptor)) + (LENGTHOFCONFIGDESCRIPTOR)),
|
||||
// wTotalLength
|
||||
|
||||
0x01, // bNumInterfaces
|
||||
0x01, // bNumInterfaces
|
||||
// There is only one interface in the CMSIS-DAP project
|
||||
0x01, // bConfigurationValue: 0x01 is used to select this configuration */
|
||||
0x00, // iConfiguration: no string to describe this configuration */
|
||||
|
@ -246,7 +285,7 @@ const uint8_t kHidReportDescriptor[0x21] = {
|
|||
|
||||
/**
|
||||
* @brief step 3. Build String Descriptor
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
@ -265,7 +304,7 @@ const uint8_t kLangDescriptor[0x04] =
|
|||
* 3. Serial number string -> "0001A0000000"
|
||||
* 4. Interface string -> "LPC-Link-II CMSIS-DAP"
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
const uint8_t kManufacturerString[0x28] =
|
||||
|
@ -286,7 +325,7 @@ const uint8_t kProductString[0x18] =
|
|||
'I', 0
|
||||
};
|
||||
|
||||
const uint8_t kSerialNumberString[0x1A] =
|
||||
const uint8_t kSerialNumberString[0x1A] =
|
||||
{
|
||||
0x1A, // bLength
|
||||
0x03, // bDescriptorType
|
||||
|
@ -301,7 +340,7 @@ const uint8_t kInterfaceString[0x2C] =
|
|||
0x03, // bDescriptorType
|
||||
// "LPC-Link-II CMSIS-DAP"
|
||||
'L', 0, 'P', 0, 'C', 0, '-', 0, 'L', 0, 'i', 0, 'n', 0, 'k', 0, '-', 0, 'I', 0,
|
||||
'I', 0, ' ', 0, 'C', 0, 'M', 0, 'S', 0, 'I', 0, 'S', 0, '-', 0, 'D', 0, 'A', 0,
|
||||
'I', 0, ' ', 0, 'C', 0, 'M', 0, 'S', 0, 'I', 0, 'S', 0, '-', 0, 'D', 0, 'A', 0,
|
||||
'P', 0
|
||||
};
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef __USBD_CONFIG_H__
|
||||
#define __USBD_CONFIG_H__
|
||||
#ifndef __USB_DESCRIPTOR_H__
|
||||
#define __USB_DESCRIPTOR_H__
|
||||
|
||||
#include "dap_configuration.h"
|
||||
#include "main/dap_configuration.h"
|
||||
|
||||
// Vendor ID assigned by USB-IF (idVendor).
|
||||
#define USBD0_DEV_DESC_IDVENDOR 0xC251
|
||||
|
@ -51,7 +51,13 @@ extern const uint8_t kProductString[0x18];
|
|||
extern const uint8_t kSerialNumberString[0x1A];
|
||||
|
||||
#if (USE_WINUSB == 1)
|
||||
|
||||
#if (USE_USB_3_0 == 1)
|
||||
extern const uint8_t kUSBd0InterfaceDescriptor[0x30];
|
||||
#else
|
||||
extern const uint8_t kUSBd0InterfaceDescriptor[0x1E];
|
||||
#endif // USE_USB_3_0 == 1
|
||||
|
||||
extern const uint8_t kUSBd0ConfigDescriptor[0x09];
|
||||
extern const uint8_t kInterfaceString[0x2C];
|
||||
|
|
@ -3,21 +3,23 @@
|
|||
* @brief Handle all Standard Device Requests on endpoint 0
|
||||
* @version 0.1
|
||||
* @date 2020-01-23
|
||||
*
|
||||
*
|
||||
* @copyright Copyright (c) 2020
|
||||
*
|
||||
*
|
||||
*/
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "main/usbip_server.h"
|
||||
|
||||
#include "components/USBIP/usb_handle.h"
|
||||
#include "components/USBIP/usb_descriptor.h"
|
||||
#include "components/USBIP/MSOS20_descriptor.h"
|
||||
|
||||
#include "lwip/err.h"
|
||||
#include "lwip/sockets.h"
|
||||
#include "lwip/sys.h"
|
||||
#include <lwip/netdb.h>
|
||||
#include "USB_handle.h"
|
||||
#include "USBd_config.h"
|
||||
#include "usbip_server.h"
|
||||
#include "usb_defs.h"
|
||||
#include "MSOS20Descriptors.h"
|
||||
|
||||
|
||||
const char *strings_list[] = {
|
||||
|
@ -263,7 +265,7 @@ static void handleGetDescriptor(usbip_stage2_header *header)
|
|||
for (int i = 0; i < slen; i++)
|
||||
{
|
||||
desc->wData[i] = strings_list[header->u.cmd_submit.request.wValue.u8lo][i];
|
||||
|
||||
|
||||
}
|
||||
send_stage2_submit_data(header, 0, (uint8_t *)temp_buff, buff_len);
|
||||
}
|
|
@ -1,7 +1,8 @@
|
|||
#ifndef __USB_HANDLE_H__
|
||||
#define __USB_HANDLE_H__
|
||||
|
||||
#include "usbip_defs.h"
|
||||
#include "components/USBIP/usbip_defs.h"
|
||||
|
||||
void handleUSBControlRequest(usbip_stage2_header *header);
|
||||
|
||||
#endif
|
|
@ -3,9 +3,9 @@
|
|||
* @brief Simple modification
|
||||
* @version 0.1
|
||||
* @date 2020-01-22
|
||||
*
|
||||
*
|
||||
* @copyright Copyright (c) 2020
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
// Focus on the following structures in this file:
|
||||
|
@ -20,7 +20,8 @@
|
|||
#define __USBIP_DEFS_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include "usb_defs.h"
|
||||
|
||||
#include "components/USBIP/usb_defs.h"
|
||||
|
||||
#define USBIP_SYSFS_PATH_SIZE 256
|
||||
#define USBIP_BUSID_SIZE 32
|
||||
|
@ -33,7 +34,7 @@ enum usbip_stage1_command
|
|||
};
|
||||
|
||||
enum usbip_stager2_command
|
||||
{
|
||||
{
|
||||
//Offset 0
|
||||
USBIP_STAGE2_REQ_SUBMIT = 0x0001,
|
||||
USBIP_STAGE2_REQ_UNLINK = 0x0002,
|
||||
|
@ -106,7 +107,7 @@ typedef struct
|
|||
/**
|
||||
* struct usbip_header_basic - data pertinent to every URB request
|
||||
* RESPONSE & REQUEST
|
||||
*
|
||||
*
|
||||
* @command: the usbip request type
|
||||
* @seqnum: sequential number that identifies requests; incremented per
|
||||
* connection
|
||||
|
@ -127,7 +128,7 @@ typedef struct
|
|||
/**
|
||||
* struct usbip_header_cmd_submit - USBIP_CMD_SUBMIT packet header
|
||||
* >>>REQUEST
|
||||
*
|
||||
*
|
||||
* @transfer_flags: URB flags
|
||||
* @transfer_buffer_length: the data size for (in) or (out) transfer
|
||||
* @start_frame: initial frame for isochronous or interrupt transfers
|
||||
|
@ -154,7 +155,7 @@ typedef struct
|
|||
/**
|
||||
* struct usbip_header_ret_submit - USBIP_RET_SUBMIT packet header
|
||||
* <<<RESPONSE
|
||||
*
|
||||
*
|
||||
* @status: return status of a non-iso request
|
||||
* @actual_length: number of bytes transferred
|
||||
* @start_frame: initial frame for isochronous or interrupt transfers
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
set(COMPONENT_ADD_INCLUDEDIRS ". $ENV{IDF_PATH}/components/esp8266/include/esp8266/ ../components/USBIP")
|
||||
set(COMPONENT_ADD_INCLUDEDIRS "${PROJECT_PATH}")
|
||||
set(COMPONENT_SRCS "main.c timer.c tcp_server.c usbip_server.c DAP_handle.c")
|
||||
|
||||
register_component()
|
||||
|
|
|
@ -1,286 +1,268 @@
|
|||
/**
|
||||
* @file DAP_handle.c
|
||||
* @brief Handle DAP packets and transaction push
|
||||
* @version 0.3
|
||||
* @date 2020-02-04 first version
|
||||
* 2020-11-11 support WinUSB mode
|
||||
*
|
||||
* @copyright Copyright (c) 2020
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include "usbip_server.h"
|
||||
#include "DAP_handle.h"
|
||||
#include "DAP.h"
|
||||
#include "esp_libc.h"
|
||||
#include "USBd_config.h"
|
||||
#include "dap_configuration.h"
|
||||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/ringbuf.h"
|
||||
#include "freertos/semphr.h"
|
||||
|
||||
#include "lwip/err.h"
|
||||
#include "lwip/sockets.h"
|
||||
#include "lwip/sys.h"
|
||||
#include <lwip/netdb.h>
|
||||
|
||||
extern int kSock;
|
||||
extern TaskHandle_t kDAPTaskHandle;
|
||||
|
||||
int kRestartDAPHandle = 0;
|
||||
|
||||
|
||||
#if (USE_WINUSB == 1)
|
||||
typedef struct
|
||||
{
|
||||
uint32_t length;
|
||||
uint8_t buf[DAP_PACKET_SIZE];
|
||||
} DAPPacetDataType;
|
||||
#else
|
||||
typedef struct
|
||||
{
|
||||
uint8_t buf[DAP_PACKET_SIZE];
|
||||
} DAPPacetDataType;
|
||||
#endif
|
||||
|
||||
|
||||
#define DAP_HANDLE_SIZE (sizeof(DAPPacetDataType))
|
||||
|
||||
static DAPPacetDataType DAPDataProcessed;
|
||||
static int dap_respond = 0;
|
||||
|
||||
|
||||
// SWO Trace
|
||||
static int swo_trace_respond = 0;
|
||||
static uint8_t *swo_data_to_send;
|
||||
static uint32_t num_swo_data;
|
||||
|
||||
static RingbufHandle_t dap_dataIN_handle = NULL;
|
||||
static RingbufHandle_t dap_dataOUT_handle = NULL;
|
||||
static SemaphoreHandle_t data_response_mux = NULL;
|
||||
|
||||
static void unpack(void *data, int size);
|
||||
|
||||
void handle_dap_data_request(usbip_stage2_header *header, uint32_t length)
|
||||
{
|
||||
uint8_t *data_in = (uint8_t *)header;
|
||||
data_in = &(data_in[sizeof(usbip_stage2_header)]);
|
||||
// Point to the beginning of the URB packet
|
||||
|
||||
#if (USE_WINUSB == 1)
|
||||
send_stage2_submit(header, 0, 0);
|
||||
|
||||
// always send constant size buf -> cuz we don't care about the IN packet size
|
||||
// and to unify the style, we set aside the length of the section
|
||||
xRingbufferSend(dap_dataIN_handle, data_in - sizeof(uint32_t), DAP_HANDLE_SIZE, portMAX_DELAY);
|
||||
xTaskNotifyGive(kDAPTaskHandle);
|
||||
|
||||
#else
|
||||
send_stage2_submit(header, 0, 0);
|
||||
|
||||
xRingbufferSend(dap_dataIN_handle, data_in, DAP_HANDLE_SIZE, portMAX_DELAY);
|
||||
xTaskNotifyGive(kDAPTaskHandle);
|
||||
|
||||
#endif
|
||||
|
||||
// dap_respond = DAP_ProcessCommand((uint8_t *)data_in, (uint8_t *)data_out);
|
||||
// //handle_dap_data_response(header);
|
||||
// send_stage2_submit(header, 0, 0);
|
||||
}
|
||||
|
||||
void handle_dap_data_response(usbip_stage2_header *header)
|
||||
{
|
||||
return;
|
||||
// int resLength = dap_respond & 0xFFFF;
|
||||
// if (resLength)
|
||||
// {
|
||||
|
||||
// send_stage2_submit_data(header, 0, (void *)DAPDataProcessed.buf, resLength);
|
||||
// dap_respond = 0;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// send_stage2_submit(header, 0, 0);
|
||||
// }
|
||||
}
|
||||
|
||||
void handle_swo_trace_response(usbip_stage2_header *header)
|
||||
{
|
||||
// TODO:
|
||||
send_stage2_submit(header, 0, 0);
|
||||
return;
|
||||
|
||||
if (swo_trace_respond)
|
||||
{
|
||||
swo_trace_respond = 0;
|
||||
//send_stage2_submit_data(header, 0, (void *)DAPDataProcessed.buf, DAP_PACKET_SIZE);
|
||||
}
|
||||
else
|
||||
{
|
||||
send_stage2_submit(header, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
// SWO Data Queue Transfer
|
||||
// buf: pointer to buffer with data
|
||||
// num: number of bytes to transfer
|
||||
void SWO_QueueTransfer(uint8_t *buf, uint32_t num)
|
||||
{
|
||||
swo_data_to_send = buf;
|
||||
num_swo_data = num;
|
||||
swo_trace_respond = 1;
|
||||
}
|
||||
|
||||
// SWO Data Abort Transfer
|
||||
void SWO_AbortTransfer(void)
|
||||
{
|
||||
//USBD_EndpointAbort(0U, USB_ENDPOINT_IN(2U));
|
||||
////TODO: unlink might be useful ...
|
||||
}
|
||||
|
||||
void DAP_Thread(void *argument)
|
||||
{
|
||||
dap_dataIN_handle = xRingbufferCreate(DAP_HANDLE_SIZE * 20, RINGBUF_TYPE_BYTEBUF);
|
||||
dap_dataOUT_handle = xRingbufferCreate(DAP_HANDLE_SIZE * 20, RINGBUF_TYPE_BYTEBUF);
|
||||
data_response_mux = xSemaphoreCreateMutex();
|
||||
size_t packetSize;
|
||||
int resLength;
|
||||
DAPPacetDataType *item;
|
||||
|
||||
if (dap_dataIN_handle == NULL || dap_dataIN_handle == NULL ||
|
||||
data_response_mux == NULL)
|
||||
{
|
||||
os_printf("Can not create DAP ringbuf/mux!\r\n");
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
for (;;)
|
||||
{
|
||||
|
||||
while (1)
|
||||
{
|
||||
if (kRestartDAPHandle)
|
||||
{
|
||||
vRingbufferDelete(dap_dataIN_handle);
|
||||
vRingbufferDelete(dap_dataOUT_handle);
|
||||
dap_dataIN_handle = dap_dataOUT_handle = NULL;
|
||||
|
||||
dap_dataIN_handle = xRingbufferCreate(DAP_HANDLE_SIZE * 20, RINGBUF_TYPE_BYTEBUF);
|
||||
dap_dataOUT_handle = xRingbufferCreate(DAP_HANDLE_SIZE * 20, RINGBUF_TYPE_BYTEBUF);
|
||||
if (dap_dataIN_handle == NULL || dap_dataIN_handle == NULL)
|
||||
{
|
||||
os_printf("Can not create DAP ringbuf/mux!\r\n");
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
kRestartDAPHandle = 0;
|
||||
}
|
||||
|
||||
ulTaskNotifyTake(pdFALSE, portMAX_DELAY);
|
||||
packetSize = 0;
|
||||
item = (DAPPacetDataType *)xRingbufferReceiveUpTo(dap_dataIN_handle, &packetSize,
|
||||
(1 / portTICK_RATE_MS), DAP_HANDLE_SIZE);
|
||||
if (packetSize == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
else if (packetSize < DAP_HANDLE_SIZE)
|
||||
{
|
||||
os_printf("Wrong data in packet size:%d , data in remain: %d\r\n", packetSize, (int)xRingbufferGetMaxItemSize(dap_dataIN_handle));
|
||||
vRingbufferReturnItem(dap_dataIN_handle, (void *)item);
|
||||
break;
|
||||
// This may not happen because there is a semaphore acquisition
|
||||
}
|
||||
|
||||
if (item->buf[0] == ID_DAP_QueueCommands)
|
||||
{
|
||||
item->buf[0] = ID_DAP_ExecuteCommands;
|
||||
}
|
||||
|
||||
resLength = DAP_ProcessCommand((uint8_t *)item->buf, (uint8_t *)DAPDataProcessed.buf); // use first 4 byte to save length
|
||||
resLength &= 0xFFFF; // res length in lower 16 bits
|
||||
|
||||
vRingbufferReturnItem(dap_dataIN_handle, (void *)item); // process done.
|
||||
|
||||
// now prepare to reply
|
||||
#if (USE_WINUSB == 1)
|
||||
DAPDataProcessed.length = resLength;
|
||||
#endif
|
||||
xRingbufferSend(dap_dataOUT_handle, (void *)&DAPDataProcessed, DAP_HANDLE_SIZE, portMAX_DELAY);
|
||||
|
||||
if (xSemaphoreTake(data_response_mux, portMAX_DELAY) == pdTRUE)
|
||||
{
|
||||
++dap_respond;
|
||||
xSemaphoreGive(data_response_mux);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int fast_reply(uint8_t *buf, uint32_t length)
|
||||
{
|
||||
if (length == 48 && buf[3] == 1 && buf[15] == 1 && buf[19] == 1)
|
||||
{
|
||||
if (dap_respond > 0)
|
||||
{
|
||||
DAPPacetDataType *item;
|
||||
size_t packetSize = 0;
|
||||
item = (DAPPacetDataType *)xRingbufferReceiveUpTo(dap_dataOUT_handle, &packetSize,
|
||||
(10 / portTICK_RATE_MS), DAP_HANDLE_SIZE);
|
||||
if (packetSize == DAP_HANDLE_SIZE)
|
||||
{
|
||||
unpack((uint32_t *)buf, sizeof(usbip_stage2_header));
|
||||
|
||||
#if (USE_WINUSB == 1)
|
||||
uint32_t resLength = item->length;
|
||||
send_stage2_submit_data((usbip_stage2_header *)buf, 0, item->buf, resLength);
|
||||
#else
|
||||
send_stage2_submit_data((usbip_stage2_header *)buf, 0, item->buf, DAP_HANDLE_SIZE);
|
||||
#endif
|
||||
|
||||
|
||||
if (xSemaphoreTake(data_response_mux, portMAX_DELAY) == pdTRUE)
|
||||
{
|
||||
--dap_respond;
|
||||
xSemaphoreGive(data_response_mux);
|
||||
}
|
||||
|
||||
vRingbufferReturnItem(dap_dataOUT_handle, (void *)item);
|
||||
return 1;
|
||||
}
|
||||
else if (packetSize > 0)
|
||||
{
|
||||
os_printf("Wrong data out packet size:%d!\r\n", packetSize);
|
||||
}
|
||||
////TODO: fast reply
|
||||
}
|
||||
else
|
||||
{
|
||||
//// TODO: ep0 dir 0 ?
|
||||
buf[0x3] = 0x3; // command
|
||||
buf[0xF] = 0; // direction
|
||||
buf[0x16] = 0;
|
||||
buf[0x17] = 0;
|
||||
buf[27] = 0;
|
||||
buf[39] = 0;
|
||||
send(kSock, buf, 48, 0);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void unpack(void *data, int size)
|
||||
{
|
||||
// Ignore the setup field
|
||||
int sz = (size / sizeof(uint32_t)) - 2;
|
||||
uint32_t *ptr = (uint32_t *)data;
|
||||
|
||||
for (int i = 0; i < sz; i++)
|
||||
{
|
||||
ptr[i] = ntohl(ptr[i]);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @file DAP_handle.c
|
||||
* @brief Handle DAP packets and transaction push
|
||||
* @version 0.4
|
||||
* @change: 2020.02.04 first version
|
||||
* 2020.11.11 support WinUSB mode
|
||||
* 2021.02.17 support SWO
|
||||
*
|
||||
* @copyright Copyright (c) 2021
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "main/usbip_server.h"
|
||||
#include "main/DAP_handle.h"
|
||||
#include "main/dap_configuration.h"
|
||||
|
||||
#include "components/USBIP/usb_descriptor.h"
|
||||
#include "components/DAP/include/DAP.h"
|
||||
#include "components/DAP/include/swo.h"
|
||||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/ringbuf.h"
|
||||
#include "freertos/semphr.h"
|
||||
|
||||
#include "lwip/err.h"
|
||||
#include "lwip/sockets.h"
|
||||
#include "lwip/sys.h"
|
||||
#include <lwip/netdb.h>
|
||||
|
||||
#if (USE_WINUSB == 1)
|
||||
typedef struct
|
||||
{
|
||||
uint32_t length;
|
||||
uint8_t buf[DAP_PACKET_SIZE];
|
||||
} DapPacket_t;
|
||||
#else
|
||||
typedef struct
|
||||
{
|
||||
uint8_t buf[DAP_PACKET_SIZE];
|
||||
} DapPacket_t;
|
||||
#endif
|
||||
|
||||
#define DAP_HANDLE_SIZE (sizeof(DapPacket_t))
|
||||
|
||||
|
||||
extern int kSock;
|
||||
extern TaskHandle_t kDAPTaskHandle;
|
||||
|
||||
int kRestartDAPHandle = 0;
|
||||
|
||||
|
||||
static DapPacket_t DAPDataProcessed;
|
||||
static int dap_respond = 0;
|
||||
|
||||
// SWO Trace
|
||||
static uint8_t *swo_data_to_send = NULL;
|
||||
static uint32_t swo_data_num;
|
||||
|
||||
// DAP handle
|
||||
static RingbufHandle_t dap_dataIN_handle = NULL;
|
||||
static RingbufHandle_t dap_dataOUT_handle = NULL;
|
||||
static SemaphoreHandle_t data_response_mux = NULL;
|
||||
|
||||
|
||||
void handle_dap_data_request(usbip_stage2_header *header, uint32_t length)
|
||||
{
|
||||
uint8_t *data_in = (uint8_t *)header;
|
||||
data_in = &(data_in[sizeof(usbip_stage2_header)]);
|
||||
// Point to the beginning of the URB packet
|
||||
|
||||
#if (USE_WINUSB == 1)
|
||||
send_stage2_submit(header, 0, 0);
|
||||
|
||||
// always send constant size buf -> cuz we don't care about the IN packet size
|
||||
// and to unify the style, we set aside the length of the section
|
||||
xRingbufferSend(dap_dataIN_handle, data_in - sizeof(uint32_t), DAP_HANDLE_SIZE, portMAX_DELAY);
|
||||
xTaskNotifyGive(kDAPTaskHandle);
|
||||
|
||||
#else
|
||||
send_stage2_submit(header, 0, 0);
|
||||
|
||||
xRingbufferSend(dap_dataIN_handle, data_in, DAP_HANDLE_SIZE, portMAX_DELAY);
|
||||
xTaskNotifyGive(kDAPTaskHandle);
|
||||
|
||||
#endif
|
||||
|
||||
// dap_respond = DAP_ProcessCommand((uint8_t *)data_in, (uint8_t *)data_out);
|
||||
// //handle_dap_data_response(header);
|
||||
// send_stage2_submit(header, 0, 0);
|
||||
}
|
||||
|
||||
void handle_dap_data_response(usbip_stage2_header *header)
|
||||
{
|
||||
return;
|
||||
// int resLength = dap_respond & 0xFFFF;
|
||||
// if (resLength)
|
||||
// {
|
||||
|
||||
// send_stage2_submit_data(header, 0, (void *)DAPDataProcessed.buf, resLength);
|
||||
// dap_respond = 0;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// send_stage2_submit(header, 0, 0);
|
||||
// }
|
||||
}
|
||||
|
||||
void handle_swo_trace_response(usbip_stage2_header *header)
|
||||
{
|
||||
#if (SWO_FUNCTION_ENABLE == 1)
|
||||
if (kSwoTransferBusy)
|
||||
{
|
||||
// busy indicates that there is data to be send
|
||||
printf("swo use data\r\n");
|
||||
send_stage2_submit_data(header, 0, (void *)swo_data_to_send, swo_data_num);
|
||||
SWO_TransferComplete();
|
||||
}
|
||||
else
|
||||
{
|
||||
// nothing to send.
|
||||
send_stage2_submit(header, 0, 0);
|
||||
}
|
||||
#else
|
||||
send_stage2_submit(header, 0, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
// SWO Data Queue Transfer
|
||||
// buf: pointer to buffer with data
|
||||
// num: number of bytes to transfer
|
||||
void SWO_QueueTransfer(uint8_t *buf, uint32_t num)
|
||||
{
|
||||
swo_data_to_send = buf;
|
||||
swo_data_num = num;
|
||||
}
|
||||
|
||||
void DAP_Thread(void *argument)
|
||||
{
|
||||
dap_dataIN_handle = xRingbufferCreate(DAP_HANDLE_SIZE * 20, RINGBUF_TYPE_BYTEBUF);
|
||||
dap_dataOUT_handle = xRingbufferCreate(DAP_HANDLE_SIZE * 20, RINGBUF_TYPE_BYTEBUF);
|
||||
data_response_mux = xSemaphoreCreateMutex();
|
||||
size_t packetSize;
|
||||
int resLength;
|
||||
DapPacket_t *item;
|
||||
|
||||
if (dap_dataIN_handle == NULL || dap_dataIN_handle == NULL ||
|
||||
data_response_mux == NULL)
|
||||
{
|
||||
os_printf("Can not create DAP ringbuf/mux!\r\n");
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
for (;;)
|
||||
{
|
||||
|
||||
while (1)
|
||||
{
|
||||
if (kRestartDAPHandle)
|
||||
{
|
||||
vRingbufferDelete(dap_dataIN_handle);
|
||||
vRingbufferDelete(dap_dataOUT_handle);
|
||||
dap_dataIN_handle = dap_dataOUT_handle = NULL;
|
||||
|
||||
dap_dataIN_handle = xRingbufferCreate(DAP_HANDLE_SIZE * 20, RINGBUF_TYPE_BYTEBUF);
|
||||
dap_dataOUT_handle = xRingbufferCreate(DAP_HANDLE_SIZE * 20, RINGBUF_TYPE_BYTEBUF);
|
||||
if (dap_dataIN_handle == NULL || dap_dataIN_handle == NULL)
|
||||
{
|
||||
os_printf("Can not create DAP ringbuf/mux!\r\n");
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
kRestartDAPHandle = 0;
|
||||
}
|
||||
|
||||
ulTaskNotifyTake(pdFALSE, portMAX_DELAY);
|
||||
packetSize = 0;
|
||||
item = (DapPacket_t *)xRingbufferReceiveUpTo(dap_dataIN_handle, &packetSize,
|
||||
pdMS_TO_TICKS(1), DAP_HANDLE_SIZE);
|
||||
if (packetSize == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
else if (packetSize < DAP_HANDLE_SIZE)
|
||||
{
|
||||
os_printf("Wrong data in packet size:%d , data in remain: %d\r\n", packetSize, (int)xRingbufferGetMaxItemSize(dap_dataIN_handle));
|
||||
vRingbufferReturnItem(dap_dataIN_handle, (void *)item);
|
||||
break;
|
||||
// This may not happen because there is a semaphore acquisition
|
||||
}
|
||||
|
||||
if (item->buf[0] == ID_DAP_QueueCommands)
|
||||
{
|
||||
item->buf[0] = ID_DAP_ExecuteCommands;
|
||||
}
|
||||
|
||||
resLength = DAP_ProcessCommand((uint8_t *)item->buf, (uint8_t *)DAPDataProcessed.buf); // use first 4 byte to save length
|
||||
resLength &= 0xFFFF; // res length in lower 16 bits
|
||||
|
||||
vRingbufferReturnItem(dap_dataIN_handle, (void *)item); // process done.
|
||||
|
||||
// now prepare to reply
|
||||
#if (USE_WINUSB == 1)
|
||||
DAPDataProcessed.length = resLength;
|
||||
#endif
|
||||
xRingbufferSend(dap_dataOUT_handle, (void *)&DAPDataProcessed, DAP_HANDLE_SIZE, portMAX_DELAY);
|
||||
|
||||
if (xSemaphoreTake(data_response_mux, portMAX_DELAY) == pdTRUE)
|
||||
{
|
||||
++dap_respond;
|
||||
xSemaphoreGive(data_response_mux);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int fast_reply(uint8_t *buf, uint32_t length)
|
||||
{
|
||||
usbip_stage2_header *buf_header = (usbip_stage2_header *)buf;
|
||||
if (length == 48 &&
|
||||
buf_header->base.command == PP_HTONL(USBIP_STAGE2_REQ_SUBMIT) &&
|
||||
buf_header->base.direction == PP_HTONL(USBIP_DIR_IN) &&
|
||||
buf_header->base.ep == PP_HTONL(1))
|
||||
{
|
||||
if (dap_respond > 0)
|
||||
{
|
||||
DapPacket_t *item;
|
||||
size_t packetSize = 0;
|
||||
item = (DapPacket_t *)xRingbufferReceiveUpTo(dap_dataOUT_handle, &packetSize,
|
||||
pdMS_TO_TICKS(10), DAP_HANDLE_SIZE);
|
||||
if (packetSize == DAP_HANDLE_SIZE)
|
||||
{
|
||||
#if (USE_WINUSB == 1)
|
||||
send_stage2_submit_data_fast((usbip_stage2_header *)buf, item->buf, item->length);
|
||||
#else
|
||||
send_stage2_submit_data_fast((usbip_stage2_header *)buf, item->buf, DAP_HANDLE_SIZE);
|
||||
#endif
|
||||
|
||||
if (xSemaphoreTake(data_response_mux, portMAX_DELAY) == pdTRUE)
|
||||
{
|
||||
--dap_respond;
|
||||
xSemaphoreGive(data_response_mux);
|
||||
}
|
||||
|
||||
vRingbufferReturnItem(dap_dataOUT_handle, (void *)item);
|
||||
return 1;
|
||||
}
|
||||
else if (packetSize > 0)
|
||||
{
|
||||
os_printf("Wrong data out packet size:%d!\r\n", packetSize);
|
||||
}
|
||||
////TODO: fast reply
|
||||
}
|
||||
else
|
||||
{
|
||||
buf_header->base.command = PP_HTONL(USBIP_STAGE2_RSP_SUBMIT);
|
||||
buf_header->base.direction = PP_HTONL(USBIP_DIR_OUT);
|
||||
buf_header->u.ret_submit.status = 0;
|
||||
buf_header->u.ret_submit.data_length = 0;
|
||||
buf_header->u.ret_submit.error_count = 0;
|
||||
send(kSock, buf, 48, 0);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef __DAP_HANDLE_H__
|
||||
#define __DAP_HANDLE_H__
|
||||
|
||||
#include "usbip_defs.h"
|
||||
#include "components/USBIP/usbip_defs.h"
|
||||
|
||||
void handle_dap_data_request(usbip_stage2_header *header, uint32_t length);
|
||||
void handle_dap_data_response(usbip_stage2_header *header);
|
||||
|
|
|
@ -3,10 +3,31 @@
|
|||
|
||||
/**
|
||||
* @brief Specify the use of WINUSB
|
||||
*
|
||||
*
|
||||
*/
|
||||
#define USE_WINUSB 1
|
||||
|
||||
/**
|
||||
* @brief Enable this option, no need to physically connect MOSI and MISO
|
||||
*
|
||||
*/
|
||||
#define USE_SPI_SIO 1
|
||||
|
||||
|
||||
/**
|
||||
* @brief Specify to enable USB 3.0
|
||||
*
|
||||
*/
|
||||
#define USE_USB_3_0 0
|
||||
|
||||
|
||||
// For USB 3.0, it must be 1024 byte.
|
||||
#if (USE_USB_3_0 == 1)
|
||||
#define USB_ENDPOINT_SIZE 1024U
|
||||
#else
|
||||
#define USB_ENDPOINT_SIZE 512U
|
||||
#endif
|
||||
|
||||
/// Maximum Package Size for Command and Response data.
|
||||
/// This configuration settings is used to optimize the communication performance with the
|
||||
/// debugger and depends on the USB peripheral. Typical vales are 64 for Full-speed USB HID or WinUSB,
|
||||
|
|
323
main/main.c
323
main/main.c
|
@ -1,142 +1,181 @@
|
|||
/* BSD Socket API Example
|
||||
|
||||
This example code is in the Public Domain (or CC0 licensed, at your option.)
|
||||
|
||||
Unless required by applicable law or agreed to in writing, this
|
||||
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
CONDITIONS OF ANY KIND, either express or implied.
|
||||
*/
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/param.h>
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/event_groups.h"
|
||||
#include "esp_system.h"
|
||||
#include "esp_wifi.h"
|
||||
#include "esp_event_loop.h"
|
||||
#include "esp_log.h"
|
||||
#include "nvs_flash.h"
|
||||
|
||||
#include "lwip/err.h"
|
||||
#include "lwip/sockets.h"
|
||||
#include "lwip/sys.h"
|
||||
#include <lwip/netdb.h>
|
||||
|
||||
#include "tcp_server.h"
|
||||
#include "timer.h"
|
||||
#include "wifi_configuration.h"
|
||||
|
||||
|
||||
extern void SWO_Thread(void *argument);
|
||||
extern void usart_monitor_task(void *argument);
|
||||
extern void DAP_Setup(void);
|
||||
extern void DAP_Thread(void *argument);
|
||||
|
||||
/* FreeRTOS event group to signal when we are connected & ready to make a request */
|
||||
static EventGroupHandle_t wifi_event_group;
|
||||
TaskHandle_t kDAPTaskHandle = NULL;
|
||||
|
||||
const int IPV4_GOTIP_BIT = BIT0;
|
||||
#ifdef CONFIG_EXAMPLE_IPV6
|
||||
const int IPV6_GOTIP_BIT = BIT1;
|
||||
#endif
|
||||
|
||||
|
||||
static esp_err_t event_handler(void *ctx, system_event_t *event)
|
||||
{
|
||||
/* For accessing reason codes in case of disconnection */
|
||||
system_event_info_t *info = &event->event_info;
|
||||
|
||||
switch (event->event_id)
|
||||
{
|
||||
case SYSTEM_EVENT_STA_START:
|
||||
esp_wifi_connect();
|
||||
os_printf("SYSTEM_EVENT_STA_START\r\n");
|
||||
break;
|
||||
case SYSTEM_EVENT_STA_CONNECTED:
|
||||
#ifdef CONFIG_EXAMPLE_IPV6
|
||||
/* enable ipv6 */
|
||||
tcpip_adapter_create_ip6_linklocal(TCPIP_ADAPTER_IF_STA);
|
||||
#endif
|
||||
break;
|
||||
case SYSTEM_EVENT_STA_GOT_IP:
|
||||
xEventGroupSetBits(wifi_event_group, IPV4_GOTIP_BIT);
|
||||
os_printf("SYSTEM EVENT STA GOT IP : %s\r\n", ip4addr_ntoa(&event->event_info.got_ip.ip_info.ip));
|
||||
break;
|
||||
case SYSTEM_EVENT_STA_DISCONNECTED:
|
||||
os_printf("Disconnect reason : %d\r\n", info->disconnected.reason);
|
||||
if (info->disconnected.reason == WIFI_REASON_BASIC_RATE_NOT_SUPPORT)
|
||||
{
|
||||
/*Switch to 802.11 bgn mode */
|
||||
esp_wifi_set_protocol(ESP_IF_WIFI_STA, WIFI_PROTOCOL_11B | WIFI_PROTOCOL_11G | WIFI_PROTOCOL_11N);
|
||||
}
|
||||
esp_wifi_connect();
|
||||
xEventGroupClearBits(wifi_event_group, IPV4_GOTIP_BIT);
|
||||
#ifdef CONFIG_EXAMPLE_IPV6
|
||||
xEventGroupClearBits(wifi_event_group, IPV6_GOTIP_BIT);
|
||||
#endif
|
||||
break;
|
||||
case SYSTEM_EVENT_AP_STA_GOT_IP6:
|
||||
#ifdef CONFIG_EXAMPLE_IPV6
|
||||
xEventGroupSetBits(wifi_event_group, IPV6_GOTIP_BIT);
|
||||
os_printf("SYSTEM_EVENT_STA_GOT_IP6\r\n");
|
||||
|
||||
char *ip6 = ip6addr_ntoa(&event->event_info.got_ip6.ip6_info.ip);
|
||||
os_printf("IPv6: %s\r\n", ip6);
|
||||
#endif
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static void initialise_wifi(void)
|
||||
{
|
||||
tcpip_adapter_init();
|
||||
wifi_event_group = xEventGroupCreate();
|
||||
|
||||
ESP_ERROR_CHECK(esp_event_loop_init(event_handler, NULL));
|
||||
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
||||
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
|
||||
ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_RAM));
|
||||
wifi_config_t wifi_config = {
|
||||
.sta = {
|
||||
.ssid = WIFI_SSID,
|
||||
.password = WIFI_PASS,
|
||||
},
|
||||
};
|
||||
os_printf("Setting WiFi configuration SSID %s...\r\n", wifi_config.sta.ssid);
|
||||
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
|
||||
ESP_ERROR_CHECK(esp_wifi_set_config(ESP_IF_WIFI_STA, &wifi_config));
|
||||
ESP_ERROR_CHECK(esp_wifi_start());
|
||||
}
|
||||
|
||||
static void wait_for_ip()
|
||||
{
|
||||
#ifdef CONFIG_EXAMPLE_IPV6
|
||||
uint32_t bits = IPV4_GOTIP_BIT | IPV6_GOTIP_BIT;
|
||||
#else
|
||||
uint32_t bits = IPV4_GOTIP_BIT;
|
||||
#endif
|
||||
|
||||
os_printf("Waiting for AP connection...\r\n");
|
||||
xEventGroupWaitBits(wifi_event_group, bits, false, true, portMAX_DELAY);
|
||||
os_printf("Connected to AP\r\n");
|
||||
}
|
||||
|
||||
|
||||
void app_main()
|
||||
{
|
||||
ESP_ERROR_CHECK(nvs_flash_init());
|
||||
initialise_wifi();
|
||||
wait_for_ip();
|
||||
DAP_Setup(); // DAP Setup
|
||||
|
||||
xTaskCreate(timer_create_task, "timer_create", 512, NULL, 10, NULL);
|
||||
xTaskCreate(tcp_server_task, "tcp_server", 4096, NULL, 14, NULL);
|
||||
xTaskCreate(DAP_Thread, "DAP_Task", 2048, NULL, 10, &kDAPTaskHandle);
|
||||
// SWO Trace Task
|
||||
//xTaskCreate(SWO_Thread, "swo_task", 1024, NULL, 6, NULL);
|
||||
//xTaskCreate(usart_monitor_task, "uart_task", 512, NULL, 6, NULL);
|
||||
}
|
||||
/* BSD Socket API Example
|
||||
|
||||
This example code is in the Public Domain (or CC0 licensed, at your option.)
|
||||
|
||||
Unless required by applicable law or agreed to in writing, this
|
||||
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
CONDITIONS OF ANY KIND, either express or implied.
|
||||
*/
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/param.h>
|
||||
|
||||
#include "main/tcp_server.h"
|
||||
#include "main/timer.h"
|
||||
#include "main/wifi_configuration.h"
|
||||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/event_groups.h"
|
||||
#include "esp_system.h"
|
||||
#include "esp_wifi.h"
|
||||
#include "esp_event_loop.h"
|
||||
#include "esp_log.h"
|
||||
#include "nvs_flash.h"
|
||||
|
||||
#include "lwip/err.h"
|
||||
#include "lwip/sockets.h"
|
||||
#include "lwip/sys.h"
|
||||
#include <lwip/netdb.h>
|
||||
|
||||
|
||||
extern void DAP_Setup(void);
|
||||
extern void DAP_Thread(void *argument);
|
||||
extern void SWO_Thread();
|
||||
|
||||
TaskHandle_t kDAPTaskHandle = NULL;
|
||||
|
||||
|
||||
|
||||
/* FreeRTOS event group to signal when we are connected & ready to make a request */
|
||||
static EventGroupHandle_t wifi_event_group;
|
||||
|
||||
const int IPV4_GOTIP_BIT = BIT0;
|
||||
#ifdef CONFIG_EXAMPLE_IPV6
|
||||
const int IPV6_GOTIP_BIT = BIT1;
|
||||
#endif
|
||||
|
||||
|
||||
static esp_err_t event_handler(void *ctx, system_event_t *event)
|
||||
{
|
||||
/* For accessing reason codes in case of disconnection */
|
||||
system_event_info_t *info = &event->event_info;
|
||||
|
||||
switch (event->event_id)
|
||||
{
|
||||
case SYSTEM_EVENT_STA_START:
|
||||
esp_wifi_connect();
|
||||
os_printf("SYSTEM_EVENT_STA_START\r\n");
|
||||
break;
|
||||
case SYSTEM_EVENT_STA_CONNECTED:
|
||||
#ifdef CONFIG_EXAMPLE_IPV6
|
||||
/* enable ipv6 */
|
||||
tcpip_adapter_create_ip6_linklocal(TCPIP_ADAPTER_IF_STA);
|
||||
#endif
|
||||
break;
|
||||
case SYSTEM_EVENT_STA_GOT_IP:
|
||||
xEventGroupSetBits(wifi_event_group, IPV4_GOTIP_BIT);
|
||||
os_printf("SYSTEM EVENT STA GOT IP : %s\r\n", ip4addr_ntoa(&event->event_info.got_ip.ip_info.ip));
|
||||
break;
|
||||
case SYSTEM_EVENT_STA_DISCONNECTED:
|
||||
os_printf("Disconnect reason : %d\r\n", info->disconnected.reason);
|
||||
if (info->disconnected.reason == WIFI_REASON_BASIC_RATE_NOT_SUPPORT)
|
||||
{
|
||||
/*Switch to 802.11 bgn mode */
|
||||
esp_wifi_set_protocol(ESP_IF_WIFI_STA, WIFI_PROTOCOL_11B | WIFI_PROTOCOL_11G | WIFI_PROTOCOL_11N);
|
||||
}
|
||||
esp_wifi_connect();
|
||||
xEventGroupClearBits(wifi_event_group, IPV4_GOTIP_BIT);
|
||||
#ifdef CONFIG_EXAMPLE_IPV6
|
||||
xEventGroupClearBits(wifi_event_group, IPV6_GOTIP_BIT);
|
||||
#endif
|
||||
break;
|
||||
case SYSTEM_EVENT_AP_STA_GOT_IP6:
|
||||
#ifdef CONFIG_EXAMPLE_IPV6
|
||||
xEventGroupSetBits(wifi_event_group, IPV6_GOTIP_BIT);
|
||||
os_printf("SYSTEM_EVENT_STA_GOT_IP6\r\n");
|
||||
|
||||
char *ip6 = ip6addr_ntoa(&event->event_info.got_ip6.ip6_info.ip);
|
||||
os_printf("IPv6: %s\r\n", ip6);
|
||||
#endif
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static void initialise_wifi(void)
|
||||
{
|
||||
tcpip_adapter_init();
|
||||
|
||||
#if (USE_STATIC_IP == 1)
|
||||
tcpip_adapter_dhcps_stop(TCPIP_ADAPTER_IF_STA);
|
||||
|
||||
tcpip_adapter_ip_info_t ip_info;
|
||||
|
||||
#define MY_IP4_ADDR(...) IP4_ADDR(__VA_ARGS__)
|
||||
MY_IP4_ADDR(&ip_info.ip, DAP_IP_ADDRESS);
|
||||
MY_IP4_ADDR(&ip_info.gw, DAP_IP_GATEWAY);
|
||||
MY_IP4_ADDR(&ip_info.netmask, DAP_IP_NETMASK);
|
||||
#undef MY_IP4_ADDR
|
||||
|
||||
tcpip_adapter_set_ip_info(TCPIP_ADAPTER_IF_STA, &ip_info);
|
||||
#endif // (USE_STATIC_IP == 1)
|
||||
|
||||
|
||||
wifi_event_group = xEventGroupCreate();
|
||||
|
||||
ESP_ERROR_CHECK(esp_event_loop_init(event_handler, NULL));
|
||||
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
||||
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
|
||||
ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_RAM));
|
||||
wifi_config_t wifi_config = {
|
||||
.sta = {
|
||||
.ssid = WIFI_SSID,
|
||||
.password = WIFI_PASS,
|
||||
},
|
||||
};
|
||||
os_printf("Setting WiFi configuration SSID %s...\r\n", wifi_config.sta.ssid);
|
||||
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
|
||||
ESP_ERROR_CHECK(esp_wifi_set_config(ESP_IF_WIFI_STA, &wifi_config));
|
||||
ESP_ERROR_CHECK(esp_wifi_start());
|
||||
}
|
||||
|
||||
static void wait_for_ip()
|
||||
{
|
||||
#ifdef CONFIG_EXAMPLE_IPV6
|
||||
uint32_t bits = IPV4_GOTIP_BIT | IPV6_GOTIP_BIT;
|
||||
#else
|
||||
uint32_t bits = IPV4_GOTIP_BIT;
|
||||
#endif
|
||||
|
||||
os_printf("Waiting for AP connection...\r\n");
|
||||
xEventGroupWaitBits(wifi_event_group, bits, false, true, portMAX_DELAY);
|
||||
os_printf("Connected to AP\r\n");
|
||||
}
|
||||
|
||||
|
||||
void app_main()
|
||||
{
|
||||
// struct rst_info *rtc_info = system_get_rst_info();
|
||||
|
||||
// os_printf("reset reason: %x\n", rtc_info->reason);
|
||||
|
||||
// if (rtc_info->reason == REASON_WDT_RST ||
|
||||
// rtc_info->reason == REASON_EXCEPTION_RST ||
|
||||
// rtc_info->reason == REASON_SOFT_WDT_RST)
|
||||
// {
|
||||
// if (rtc_info->reason == REASON_EXCEPTION_RST)
|
||||
// {
|
||||
// os_printf("Fatal exception (%d):\n", rtc_info->exccause);
|
||||
// }
|
||||
// os_printf("epc1=0x%08x, epc2=0x%08x, epc3=0x%08x,excvaddr=0x%08x, depc=0x%08x\n",
|
||||
// rtc_info->epc1, rtc_info->epc2, rtc_info->epc3,
|
||||
// rtc_info->excvaddr, rtc_info->depc);
|
||||
// }
|
||||
|
||||
ESP_ERROR_CHECK(nvs_flash_init());
|
||||
initialise_wifi();
|
||||
wait_for_ip();
|
||||
DAP_Setup();
|
||||
timer_init();
|
||||
|
||||
|
||||
xTaskCreate(tcp_server_task, "tcp_server", 4096, NULL, 14, NULL);
|
||||
xTaskCreate(DAP_Thread, "DAP_Task", 2048, NULL, 10, &kDAPTaskHandle);
|
||||
// SWO Trace Task
|
||||
#if (SWO_FUNCTION_ENABLE == 1)
|
||||
xTaskCreate(SWO_Thread, "SWO_Task", 512, NULL, 10, NULL);
|
||||
#endif
|
||||
// It seems that the task is overly stressful...
|
||||
}
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "esp_system.h"
|
||||
|
||||
void esp_print_tasks(void)
|
||||
{
|
||||
char *pbuffer = (char *)calloc(1, 2048);
|
||||
printf("--------------- heap:%u ---------------------\r\n", esp_get_free_heap_size());
|
||||
vTaskGetRunTimeStats(pbuffer);
|
||||
printf("%s", pbuffer);
|
||||
printf("----------------------------------------------\r\n");
|
||||
free(pbuffer);
|
||||
}
|
||||
|
||||
void monitor_task()
|
||||
{
|
||||
while(1) {
|
||||
esp_print_tasks();
|
||||
vTaskDelay(3000 / portTICK_RATE_MS);
|
||||
}
|
||||
}
|
|
@ -1,181 +1,182 @@
|
|||
/**
|
||||
* @file tcp_server.c
|
||||
* @brief Handle main tcp tasks
|
||||
* @version 0.1
|
||||
* @date 2020-01-22
|
||||
*
|
||||
* @copyright Copyright (c) 2020
|
||||
*
|
||||
*/
|
||||
#include "tcp_server.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/param.h>
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/event_groups.h"
|
||||
#include "esp_system.h"
|
||||
#include "esp_wifi.h"
|
||||
#include "esp_event_loop.h"
|
||||
#include "esp_log.h"
|
||||
#include "nvs_flash.h"
|
||||
|
||||
#include "lwip/err.h"
|
||||
#include "lwip/sockets.h"
|
||||
#include "lwip/sys.h"
|
||||
#include <lwip/netdb.h>
|
||||
|
||||
#include "wifi_configuration.h"
|
||||
#include "usbip_server.h"
|
||||
|
||||
extern TaskHandle_t kDAPTaskHandle;
|
||||
extern int kRestartDAPHandle;
|
||||
|
||||
uint8_t kState = ACCEPTING;
|
||||
int kSock = -1;
|
||||
|
||||
void tcp_server_task(void *pvParameters)
|
||||
{
|
||||
uint8_t tcp_rx_buffer[1024];
|
||||
char addr_str[128];
|
||||
int addr_family;
|
||||
int ip_protocol;
|
||||
|
||||
int on = 1;
|
||||
while (1)
|
||||
{
|
||||
|
||||
#ifdef CONFIG_EXAMPLE_IPV4
|
||||
struct sockaddr_in destAddr;
|
||||
destAddr.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
destAddr.sin_family = AF_INET;
|
||||
destAddr.sin_port = htons(PORT);
|
||||
addr_family = AF_INET;
|
||||
ip_protocol = IPPROTO_IP;
|
||||
inet_ntoa_r(destAddr.sin_addr, addr_str, sizeof(addr_str) - 1);
|
||||
#else // IPV6
|
||||
struct sockaddr_in6 destAddr;
|
||||
bzero(&destAddr.sin6_addr.un, sizeof(destAddr.sin6_addr.un));
|
||||
destAddr.sin6_family = AF_INET6;
|
||||
destAddr.sin6_port = htons(PORT);
|
||||
addr_family = AF_INET6;
|
||||
ip_protocol = IPPROTO_IPV6;
|
||||
inet6_ntoa_r(destAddr.sin6_addr, addr_str, sizeof(addr_str) - 1);
|
||||
#endif
|
||||
|
||||
int listen_sock = socket(addr_family, SOCK_STREAM, ip_protocol);
|
||||
if (listen_sock < 0)
|
||||
{
|
||||
os_printf("Unable to create socket: errno %d\r\n", errno);
|
||||
break;
|
||||
}
|
||||
os_printf("Socket created\r\n");
|
||||
|
||||
setsockopt(listen_sock, SOL_SOCKET, SO_KEEPALIVE, (void *)&on, sizeof(on));
|
||||
setsockopt(listen_sock, IPPROTO_TCP, TCP_NODELAY, (void *)&on, sizeof(on));
|
||||
|
||||
int err = bind(listen_sock, (struct sockaddr *)&destAddr, sizeof(destAddr));
|
||||
if (err != 0)
|
||||
{
|
||||
os_printf("Socket unable to bind: errno %d\r\n", errno);
|
||||
break;
|
||||
}
|
||||
os_printf("Socket binded\r\n");
|
||||
|
||||
err = listen(listen_sock, 1);
|
||||
if (err != 0)
|
||||
{
|
||||
os_printf("Error occured during listen: errno %d\r\n", errno);
|
||||
break;
|
||||
}
|
||||
os_printf("Socket listening\r\n");
|
||||
|
||||
#ifdef CONFIG_EXAMPLE_IPV6
|
||||
struct sockaddr_in6 sourceAddr; // Large enough for both IPv4 or IPv6
|
||||
#else
|
||||
struct sockaddr_in sourceAddr;
|
||||
#endif
|
||||
uint32_t addrLen = sizeof(sourceAddr);
|
||||
while (1)
|
||||
{
|
||||
kSock = accept(listen_sock, (struct sockaddr *)&sourceAddr, &addrLen);
|
||||
if (kSock < 0)
|
||||
{
|
||||
os_printf("Unable to accept connection: errno %d\r\n", errno);
|
||||
break;
|
||||
}
|
||||
setsockopt(kSock, SOL_SOCKET, SO_KEEPALIVE, (void *)&on, sizeof(on));
|
||||
setsockopt(kSock, IPPROTO_TCP, TCP_NODELAY, (void *)&on, sizeof(on));
|
||||
os_printf("Socket accepted\r\n");
|
||||
|
||||
while (1)
|
||||
{
|
||||
int len = recv(kSock, tcp_rx_buffer, sizeof(tcp_rx_buffer), 0);
|
||||
// Error occured during receiving
|
||||
if (len < 0)
|
||||
{
|
||||
os_printf("recv failed: errno %d\r\n", errno);
|
||||
break;
|
||||
}
|
||||
// Connection closed
|
||||
else if (len == 0)
|
||||
{
|
||||
os_printf("Connection closed\r\n");
|
||||
break;
|
||||
}
|
||||
// Data received
|
||||
else
|
||||
{
|
||||
// #ifdef CONFIG_EXAMPLE_IPV6
|
||||
// // Get the sender's ip address as string
|
||||
// if (sourceAddr.sin6_family == PF_INET)
|
||||
// {
|
||||
// inet_ntoa_r(((struct sockaddr_in *)&sourceAddr)->sin_addr.s_addr, addr_str, sizeof(addr_str) - 1);
|
||||
// }
|
||||
// else if (sourceAddr.sin6_family == PF_INET6)
|
||||
// {
|
||||
// inet6_ntoa_r(sourceAddr.sin6_addr, addr_str, sizeof(addr_str) - 1);
|
||||
// }
|
||||
// #else
|
||||
// inet_ntoa_r(((struct sockaddr_in *)&sourceAddr)->sin_addr.s_addr, addr_str, sizeof(addr_str) - 1);
|
||||
// #endif
|
||||
|
||||
switch (kState)
|
||||
{
|
||||
case ACCEPTING:
|
||||
kState = ATTACHING;
|
||||
|
||||
case ATTACHING:
|
||||
attach(tcp_rx_buffer, len);
|
||||
break;
|
||||
|
||||
case EMULATING:
|
||||
emulate(tcp_rx_buffer, len);
|
||||
break;
|
||||
default:
|
||||
os_printf("unkonw kstate!\r\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
// kState = ACCEPTING;
|
||||
if (kSock != -1)
|
||||
{
|
||||
os_printf("Shutting down socket and restarting...\r\n");
|
||||
//shutdown(kSock, 0);
|
||||
close(kSock);
|
||||
if (kState == EMULATING)
|
||||
kState = ACCEPTING;
|
||||
|
||||
// Restart DAP Handle
|
||||
kRestartDAPHandle = 1;
|
||||
xTaskNotifyGive(kDAPTaskHandle);
|
||||
|
||||
//shutdown(listen_sock, 0);
|
||||
//close(listen_sock);
|
||||
//vTaskDelay(5);
|
||||
}
|
||||
}
|
||||
}
|
||||
vTaskDelete(NULL);
|
||||
/**
|
||||
* @file tcp_server.c
|
||||
* @brief Handle main tcp tasks
|
||||
* @version 0.1
|
||||
* @date 2020-01-22
|
||||
*
|
||||
* @copyright Copyright (c) 2020
|
||||
*
|
||||
*/
|
||||
#include "tcp_server.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/param.h>
|
||||
|
||||
#include "main/wifi_configuration.h"
|
||||
#include "main/usbip_server.h"
|
||||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/event_groups.h"
|
||||
#include "esp_system.h"
|
||||
#include "esp_wifi.h"
|
||||
#include "esp_event_loop.h"
|
||||
#include "esp_log.h"
|
||||
#include "nvs_flash.h"
|
||||
|
||||
#include "lwip/err.h"
|
||||
#include "lwip/sockets.h"
|
||||
#include "lwip/sys.h"
|
||||
#include <lwip/netdb.h>
|
||||
|
||||
extern TaskHandle_t kDAPTaskHandle;
|
||||
extern int kRestartDAPHandle;
|
||||
|
||||
uint8_t kState = ACCEPTING;
|
||||
int kSock = -1;
|
||||
|
||||
void tcp_server_task(void *pvParameters)
|
||||
{
|
||||
uint8_t tcp_rx_buffer[1500];
|
||||
char addr_str[128];
|
||||
int addr_family;
|
||||
int ip_protocol;
|
||||
|
||||
int on = 1;
|
||||
while (1)
|
||||
{
|
||||
|
||||
#ifdef CONFIG_EXAMPLE_IPV4
|
||||
struct sockaddr_in destAddr;
|
||||
destAddr.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
destAddr.sin_family = AF_INET;
|
||||
destAddr.sin_port = htons(PORT);
|
||||
addr_family = AF_INET;
|
||||
ip_protocol = IPPROTO_IP;
|
||||
inet_ntoa_r(destAddr.sin_addr, addr_str, sizeof(addr_str) - 1);
|
||||
#else // IPV6
|
||||
struct sockaddr_in6 destAddr;
|
||||
bzero(&destAddr.sin6_addr.un, sizeof(destAddr.sin6_addr.un));
|
||||
destAddr.sin6_family = AF_INET6;
|
||||
destAddr.sin6_port = htons(PORT);
|
||||
addr_family = AF_INET6;
|
||||
ip_protocol = IPPROTO_IPV6;
|
||||
inet6_ntoa_r(destAddr.sin6_addr, addr_str, sizeof(addr_str) - 1);
|
||||
#endif
|
||||
|
||||
int listen_sock = socket(addr_family, SOCK_STREAM, ip_protocol);
|
||||
if (listen_sock < 0)
|
||||
{
|
||||
os_printf("Unable to create socket: errno %d\r\n", errno);
|
||||
break;
|
||||
}
|
||||
os_printf("Socket created\r\n");
|
||||
|
||||
setsockopt(listen_sock, SOL_SOCKET, SO_KEEPALIVE, (void *)&on, sizeof(on));
|
||||
setsockopt(listen_sock, IPPROTO_TCP, TCP_NODELAY, (void *)&on, sizeof(on));
|
||||
|
||||
int err = bind(listen_sock, (struct sockaddr *)&destAddr, sizeof(destAddr));
|
||||
if (err != 0)
|
||||
{
|
||||
os_printf("Socket unable to bind: errno %d\r\n", errno);
|
||||
break;
|
||||
}
|
||||
os_printf("Socket binded\r\n");
|
||||
|
||||
err = listen(listen_sock, 1);
|
||||
if (err != 0)
|
||||
{
|
||||
os_printf("Error occured during listen: errno %d\r\n", errno);
|
||||
break;
|
||||
}
|
||||
os_printf("Socket listening\r\n");
|
||||
|
||||
#ifdef CONFIG_EXAMPLE_IPV6
|
||||
struct sockaddr_in6 sourceAddr; // Large enough for both IPv4 or IPv6
|
||||
#else
|
||||
struct sockaddr_in sourceAddr;
|
||||
#endif
|
||||
uint32_t addrLen = sizeof(sourceAddr);
|
||||
while (1)
|
||||
{
|
||||
kSock = accept(listen_sock, (struct sockaddr *)&sourceAddr, &addrLen);
|
||||
if (kSock < 0)
|
||||
{
|
||||
os_printf("Unable to accept connection: errno %d\r\n", errno);
|
||||
break;
|
||||
}
|
||||
setsockopt(kSock, SOL_SOCKET, SO_KEEPALIVE, (void *)&on, sizeof(on));
|
||||
setsockopt(kSock, IPPROTO_TCP, TCP_NODELAY, (void *)&on, sizeof(on));
|
||||
os_printf("Socket accepted\r\n");
|
||||
|
||||
while (1)
|
||||
{
|
||||
int len = recv(kSock, tcp_rx_buffer, sizeof(tcp_rx_buffer), 0);
|
||||
// Error occured during receiving
|
||||
if (len < 0)
|
||||
{
|
||||
os_printf("recv failed: errno %d\r\n", errno);
|
||||
break;
|
||||
}
|
||||
// Connection closed
|
||||
else if (len == 0)
|
||||
{
|
||||
os_printf("Connection closed\r\n");
|
||||
break;
|
||||
}
|
||||
// Data received
|
||||
else
|
||||
{
|
||||
// #ifdef CONFIG_EXAMPLE_IPV6
|
||||
// // Get the sender's ip address as string
|
||||
// if (sourceAddr.sin6_family == PF_INET)
|
||||
// {
|
||||
// inet_ntoa_r(((struct sockaddr_in *)&sourceAddr)->sin_addr.s_addr, addr_str, sizeof(addr_str) - 1);
|
||||
// }
|
||||
// else if (sourceAddr.sin6_family == PF_INET6)
|
||||
// {
|
||||
// inet6_ntoa_r(sourceAddr.sin6_addr, addr_str, sizeof(addr_str) - 1);
|
||||
// }
|
||||
// #else
|
||||
// inet_ntoa_r(((struct sockaddr_in *)&sourceAddr)->sin_addr.s_addr, addr_str, sizeof(addr_str) - 1);
|
||||
// #endif
|
||||
|
||||
switch (kState)
|
||||
{
|
||||
case ACCEPTING:
|
||||
kState = ATTACHING;
|
||||
|
||||
case ATTACHING:
|
||||
attach(tcp_rx_buffer, len);
|
||||
break;
|
||||
|
||||
case EMULATING:
|
||||
emulate(tcp_rx_buffer, len);
|
||||
break;
|
||||
default:
|
||||
os_printf("unkonw kstate!\r\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
// kState = ACCEPTING;
|
||||
if (kSock != -1)
|
||||
{
|
||||
os_printf("Shutting down socket and restarting...\r\n");
|
||||
//shutdown(kSock, 0);
|
||||
close(kSock);
|
||||
if (kState == EMULATING)
|
||||
kState = ACCEPTING;
|
||||
|
||||
// Restart DAP Handle
|
||||
kRestartDAPHandle = 1;
|
||||
xTaskNotifyGive(kDAPTaskHandle);
|
||||
|
||||
//shutdown(listen_sock, 0);
|
||||
//close(listen_sock);
|
||||
//vTaskDelay(5);
|
||||
}
|
||||
}
|
||||
}
|
||||
vTaskDelete(NULL);
|
||||
}
|
|
@ -3,4 +3,4 @@
|
|||
|
||||
void tcp_server_task(void *pvParameters);
|
||||
|
||||
#endif
|
||||
#endif
|
48
main/timer.c
48
main/timer.c
|
@ -1,29 +1,49 @@
|
|||
/**
|
||||
* @file timer.c
|
||||
* @brief Hardware timer for DAP timestamp
|
||||
* @version 0.1
|
||||
* @change: 2021-02-18 Using the FRC2 timer
|
||||
*
|
||||
* @version 0.2
|
||||
* @date 2020-01-22
|
||||
*
|
||||
* @copyright Copyright (c) 2020
|
||||
*
|
||||
*
|
||||
* @copyright Copyright (c) 2021
|
||||
*
|
||||
*/
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "timer.h"
|
||||
|
||||
#include "main/timer.h"
|
||||
|
||||
#include "hw_timer.h"
|
||||
#include "timer_struct.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/event_groups.h"
|
||||
void timer_create_task()
|
||||
|
||||
/*
|
||||
Note:
|
||||
System bus frequency is 80MHz, will not be affected by CPU frequency. The
|
||||
frequency of UART, SPI, or other peripheral devices, are divided from system
|
||||
bus frequency, so they will not be affected by CPU frequency either.
|
||||
|
||||
*/
|
||||
|
||||
#define TIMER_BASE 0x60000600
|
||||
volatile frc2_struct_t * frc2 = (frc2_struct_t *)(TIMER_BASE + (1) * 0x20);
|
||||
|
||||
void timer_init()
|
||||
{
|
||||
// FRC1 frequency 80MHz
|
||||
vPortEnterCritical();
|
||||
frc1.ctrl.div = TIMER_CLKDIV_16; // 80MHz / 16 = 5MHz
|
||||
frc1.ctrl.intr_type = TIMER_EDGE_INT;
|
||||
frc1.ctrl.reload = 0x01;
|
||||
frc1.load.data = 0x7FFFFF; // 23bit??
|
||||
frc1.ctrl.en = 0x01;
|
||||
frc2->ctrl.div = TIMER_CLKDIV_16; // 80MHz / 16 = 5MHz
|
||||
frc2->ctrl.intr_type = TIMER_EDGE_INT;
|
||||
frc2->ctrl.reload = 0x01; // enable auto reload
|
||||
frc2->load.val = 0x7FFFFFFF; // 31bit max
|
||||
frc2->ctrl.en = 0x01;
|
||||
vPortExitCritical();
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
// Timing up to 2147483647(0x7FFFFFFF) / 5000000(5MHz) = 429s
|
||||
// 0.2 micro-second resolution
|
||||
uint32_t get_timer_count()
|
||||
{
|
||||
return (uint32_t)frc2->count.data;
|
||||
}
|
69
main/timer.h
69
main/timer.h
|
@ -1,6 +1,71 @@
|
|||
/**
|
||||
* @file timer.h
|
||||
* @author windowsair
|
||||
* @brief esp8266 hardware timer
|
||||
* @change: 2021-02-18 Add frc2 timer
|
||||
* @note
|
||||
* FRC2 is not officially documented. There is no guarantee of its behavior.
|
||||
* FRC2 may be used for RTC functions. May be reserved for other functions in the future.
|
||||
*
|
||||
*
|
||||
* @version 0.1
|
||||
* @date 2021-02-18
|
||||
*
|
||||
* @copyright Copyright (c) 2021
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef __TIMER_H__
|
||||
#define __TIMER_H__
|
||||
|
||||
void timer_create_task();
|
||||
#include <stdint.h>
|
||||
|
||||
#endif
|
||||
|
||||
// FRC2 is a 32-bit countup timer
|
||||
typedef struct {
|
||||
union {
|
||||
struct {
|
||||
uint32_t data: 32;
|
||||
};
|
||||
uint32_t val;
|
||||
} load;
|
||||
|
||||
union {
|
||||
struct {
|
||||
uint32_t data: 31;
|
||||
uint32_t reserved23: 1;
|
||||
};
|
||||
uint32_t val;
|
||||
} count;
|
||||
|
||||
union {
|
||||
struct {
|
||||
uint32_t div: 6;
|
||||
uint32_t reload: 1;
|
||||
uint32_t en: 1;
|
||||
uint32_t intr_type: 1;
|
||||
uint32_t reserved24: 23;
|
||||
};
|
||||
uint32_t val;
|
||||
} ctrl;
|
||||
|
||||
union {
|
||||
struct {
|
||||
uint32_t clr: 1;
|
||||
uint32_t reserved1: 31;
|
||||
};
|
||||
uint32_t val;
|
||||
} intr;
|
||||
} frc2_struct_t;
|
||||
|
||||
extern volatile frc2_struct_t* frc2;
|
||||
|
||||
extern void timer_init();
|
||||
extern uint32_t get_timer_count();
|
||||
|
||||
#endif
|
|
@ -1,17 +1,17 @@
|
|||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "main/usbip_server.h"
|
||||
#include "main/DAP_handle.h"
|
||||
|
||||
#include "components/USBIP/usb_handle.h"
|
||||
#include "components/USBIP/usb_descriptor.h"
|
||||
|
||||
#include "lwip/err.h"
|
||||
#include "lwip/sockets.h"
|
||||
#include "lwip/sys.h"
|
||||
#include <lwip/netdb.h>
|
||||
|
||||
#include "usbip_server.h"
|
||||
#include "usbip_defs.h"
|
||||
#include "usb_defs.h"
|
||||
#include "USBd_config.h"
|
||||
#include "DAP_handle.h"
|
||||
#include "USB_handle.h"
|
||||
#include "USBd_config.h"
|
||||
|
||||
// attach helper function
|
||||
static int read_stage1_command(uint8_t *buffer, uint32_t length);
|
||||
|
@ -190,7 +190,7 @@ int emulate(uint8_t *buffer, uint32_t length)
|
|||
int command = read_stage2_command((usbip_stage2_header *)buffer, length);
|
||||
if (command < 0)
|
||||
{
|
||||
return -1;
|
||||
return -1;
|
||||
}
|
||||
|
||||
switch (command)
|
||||
|
@ -229,7 +229,7 @@ static int read_stage2_command(usbip_stage2_header *header, uint32_t length)
|
|||
* - ret_submit
|
||||
* - cmd_unlink
|
||||
* - ret_unlink
|
||||
*
|
||||
*
|
||||
* @param data Point to packets header
|
||||
* @param size Packets header size
|
||||
*/
|
||||
|
@ -253,7 +253,7 @@ static void pack(void *data, int size)
|
|||
* - ret_submit
|
||||
* - cmd_unlink
|
||||
* - ret_unlink
|
||||
*
|
||||
*
|
||||
* @param data Point to packets header
|
||||
* @param size packets header size
|
||||
*/
|
||||
|
@ -339,7 +339,7 @@ void send_stage2_submit(usbip_stage2_header *req_header, int32_t status, int32_t
|
|||
|
||||
req_header->u.ret_submit.status = status;
|
||||
req_header->u.ret_submit.data_length = data_length;
|
||||
|
||||
// already unpacked
|
||||
pack(req_header, sizeof(usbip_stage2_header));
|
||||
send(kSock, req_header, sizeof(usbip_stage2_header), 0);
|
||||
}
|
||||
|
@ -355,6 +355,23 @@ void send_stage2_submit_data(usbip_stage2_header *req_header, int32_t status, co
|
|||
}
|
||||
}
|
||||
|
||||
void send_stage2_submit_data_fast(usbip_stage2_header *req_header, const void *const data, int32_t data_length)
|
||||
{
|
||||
uint8_t * send_buf = (uint8_t *)req_header;
|
||||
|
||||
req_header->base.command = PP_HTONL(USBIP_STAGE2_RSP_SUBMIT);
|
||||
req_header->base.direction = htonl(!(req_header->base.direction));
|
||||
|
||||
memset(&(req_header->u.ret_submit), 0, sizeof(usbip_stage2_header_ret_submit));
|
||||
req_header->u.ret_submit.data_length = htonl(data_length);
|
||||
|
||||
|
||||
// payload
|
||||
memcpy(&send_buf[sizeof(usbip_stage2_header)], data, data_length);
|
||||
send(kSock, send_buf, sizeof(usbip_stage2_header) + data_length, 0);
|
||||
}
|
||||
|
||||
|
||||
static void handle_unlink(usbip_stage2_header *header)
|
||||
{
|
||||
os_printf("s2 handling cmd unlink...\r\n");
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
#ifndef __USBIP_SERVER_H__
|
||||
#define __USBIP_SERVER_H__
|
||||
#include <stdint.h>
|
||||
#include "usbip_defs.h"
|
||||
|
||||
#include "components/USBIP/usbip_defs.h"
|
||||
|
||||
enum state_t
|
||||
{
|
||||
ACCEPTING,
|
||||
|
@ -15,5 +17,7 @@ int attach(uint8_t *buffer, uint32_t length);
|
|||
int emulate(uint8_t *buffer, uint32_t length);
|
||||
void send_stage2_submit_data(usbip_stage2_header *req_header, int32_t status, const void * const data, int32_t data_length);
|
||||
void send_stage2_submit(usbip_stage2_header *req_header, int32_t status, int32_t data_length);
|
||||
void send_stage2_submit_data_fast(usbip_stage2_header *req_header, const void *const data, int32_t data_length);
|
||||
|
||||
|
||||
#endif
|
|
@ -3,9 +3,9 @@
|
|||
* @brief Fill in your wifi configuration information here.
|
||||
* @version 0.1
|
||||
* @date 2020-01-22
|
||||
*
|
||||
*
|
||||
* @copyright Copyright (c) 2020
|
||||
*
|
||||
*
|
||||
*/
|
||||
#ifndef __WIFI_CONFIGURATION__
|
||||
#define __WIFI_CONFIGURATION__
|
||||
|
@ -13,8 +13,15 @@
|
|||
#define WIFI_SSID "DAP"
|
||||
#define WIFI_PASS "12345678"
|
||||
|
||||
#define PORT 3240
|
||||
|
||||
#define USE_STATIC_IP 1
|
||||
// If you don't want to specify the ip configuration, then ignore the following items.
|
||||
#define DAP_IP_ADDRESS 192, 168, 137, 123
|
||||
#define DAP_IP_GATEWAY 192, 168, 137, 1
|
||||
#define DAP_IP_NETMASK 255, 255, 255, 0
|
||||
|
||||
// DO NOT CHANGE
|
||||
#define PORT 3240
|
||||
#define CONFIG_EXAMPLE_IPV4 1
|
||||
|
||||
#endif
|
||||
#endif
|
340
sdkconfig
340
sdkconfig
|
@ -10,6 +10,8 @@ CONFIG_IDF_TARGET="esp8266"
|
|||
#
|
||||
CONFIG_SDK_TOOLPREFIX="xtensa-lx106-elf-"
|
||||
CONFIG_BOOTLOADER_INIT_SPI_FLASH=y
|
||||
# CONFIG_BOOTLOADER_DISABLE_JTAG_IO is not set
|
||||
# CONFIG_BOOTLOADER_FAST_BOOT is not set
|
||||
# CONFIG_LOG_BOOTLOADER_LEVEL_NONE is not set
|
||||
# CONFIG_LOG_BOOTLOADER_LEVEL_ERROR is not set
|
||||
# CONFIG_LOG_BOOTLOADER_LEVEL_WARN is not set
|
||||
|
@ -18,6 +20,7 @@ CONFIG_LOG_BOOTLOADER_LEVEL_INFO=y
|
|||
# CONFIG_LOG_BOOTLOADER_LEVEL_VERBOSE is not set
|
||||
CONFIG_LOG_BOOTLOADER_LEVEL=3
|
||||
# CONFIG_BOOTLOADER_APP_TEST is not set
|
||||
CONFIG_BOOTLOADER_STORE_OFFSET=0x0
|
||||
CONFIG_ESPTOOLPY_PORT="/dev/ttyS5"
|
||||
# CONFIG_ESPTOOLPY_BAUD_115200B is not set
|
||||
# CONFIG_ESPTOOLPY_BAUD_230400B is not set
|
||||
|
@ -83,14 +86,18 @@ CONFIG_COMPILER_STACK_CHECK_MODE_NONE=y
|
|||
# CONFIG_COMPILER_WARN_WRITE_STRINGS is not set
|
||||
CONFIG_APP_UPDATE_CHECK_APP_SUM=y
|
||||
CONFIG_APP_UPDATE_CHECK_APP_HASH=y
|
||||
# CONFIG_AWS_IOT_SDK is not set
|
||||
# CONFIG_USING_ESP_CONSOLE is not set
|
||||
CONFIG_APP_COMPILE_TIME_DATE=y
|
||||
# CONFIG_APP_EXCLUDE_PROJECT_VER_VAR is not set
|
||||
# CONFIG_APP_EXCLUDE_PROJECT_NAME_VAR is not set
|
||||
# CONFIG_APP_PROJECT_VER_FROM_CONFIG is not set
|
||||
# CONFIG_ENABLE_COAP is not set
|
||||
CONFIG_ESP_TLS_USING_MBEDTLS=y
|
||||
# CONFIG_ESP_TLS_USING_WOLFSSL is not set
|
||||
# CONFIG_ESP_TLS_SERVER is not set
|
||||
# CONFIG_ESP_TLS_PSK_VERIFICATION is not set
|
||||
# CONFIG_ESP_WOLFSSL_INTERNAL is not set
|
||||
# CONFIG_WOLFSSL_DEBUG is not set
|
||||
# CONFIG_ESP8266_NMI_WDT is not set
|
||||
# CONFIG_ESP8266_DEFAULT_CPU_FREQ_80 is not set
|
||||
CONFIG_ESP8266_DEFAULT_CPU_FREQ_160=y
|
||||
CONFIG_ESP8266_DEFAULT_CPU_FREQ_MHZ=160
|
||||
|
@ -102,38 +109,26 @@ CONFIG_ESP_FILENAME_MACRO_NO_PATH=y
|
|||
# CONFIG_ESP_FILENAME_MACRO_NULL is not set
|
||||
CONFIG_USING_NEW_ETS_VPRINTF=y
|
||||
# CONFIG_LINK_ETS_PRINTF_TO_IRAM is not set
|
||||
CONFIG_ETS_PRINTF_EXIT_WHEN_FLASH_RW=y
|
||||
CONFIG_SOC_FULL_ICACHE=y
|
||||
CONFIG_SOC_IRAM_SIZE=0x8000
|
||||
CONFIG_CONSOLE_UART_DEFAULT=y
|
||||
# CONFIG_CONSOLE_UART_CUSTOM is not set
|
||||
# CONFIG_CONSOLE_UART_NONE is not set
|
||||
CONFIG_CONSOLE_UART_NUM=0
|
||||
CONFIG_CONSOLE_UART_BAUDRATE=74880
|
||||
# CONFIG_UART0_SWAP_IO is not set
|
||||
# CONFIG_DISABLE_ROM_UART_PRINT is not set
|
||||
# CONFIG_PANIC_FULL_STACK is not set
|
||||
# CONFIG_ESP_PANIC_PRINT_HALT is not set
|
||||
CONFIG_ESP_PANIC_PRINT_REBOOT=y
|
||||
# CONFIG_ESP_PANIC_SILENT_REBOOT is not set
|
||||
CONFIG_MAIN_TASK_STACK_SIZE=3584
|
||||
CONFIG_TASK_WDT=y
|
||||
CONFIG_TASK_WDT_PANIC=y
|
||||
# CONFIG_TASK_WDT_TIMEOUT_13N is not set
|
||||
# CONFIG_TASK_WDT_TIMEOUT_14N is not set
|
||||
CONFIG_TASK_WDT_TIMEOUT_15N=y
|
||||
CONFIG_TASK_WDT_TIMEOUT_S=15
|
||||
# CONFIG_ESP_PANIC_GDBSTUB is not set
|
||||
CONFIG_RESET_REASON=y
|
||||
CONFIG_WIFI_PPT_TASKSTACK_SIZE=4096
|
||||
CONFIG_EVENT_LOOP_STACK_SIZE=4096
|
||||
# CONFIG_ESP8266_OTA_FROM_OLD is not set
|
||||
# CONFIG_ESP8266_BOOT_COPY_APP is not set
|
||||
CONFIG_ESP_ERR_TO_NAME_LOOKUP=y
|
||||
CONFIG_ESP8266_TIME_SYSCALL_USE_FRC1=y
|
||||
# CONFIG_ESP8266_TIME_SYSCALL_USE_NONE is not set
|
||||
# CONFIG_PM_ENABLE is not set
|
||||
CONFIG_SCAN_AP_MAX=99
|
||||
CONFIG_WIFI_TX_RATE_SEQUENCE_FROM_HIGH=y
|
||||
# CONFIG_ESP8266_WIFI_QOS_ENABLED is not set
|
||||
# CONFIG_ESP8266_WIFI_AMPDU_RX_ENABLED is not set
|
||||
CONFIG_ESP8266_WIFI_AMPDU_RX_ENABLED=y
|
||||
CONFIG_ESP8266_WIFI_RX_BA_WIN_SIZE=6
|
||||
# CONFIG_ESP8266_WIFI_AMSDU_ENABLED is not set
|
||||
CONFIG_ESP8266_WIFI_RX_BUFFER_NUM=28
|
||||
CONFIG_ESP8266_WIFI_LEFT_CONTINUOUS_RX_BUFFER_NUM=8
|
||||
|
@ -141,21 +136,91 @@ CONFIG_ESP8266_WIFI_RX_PKT_NUM=16
|
|||
CONFIG_ESP8266_WIFI_TX_PKT_NUM=6
|
||||
CONFIG_ESP8266_WIFI_NVS_ENABLED=y
|
||||
CONFIG_ESP8266_WIFI_CONNECT_OPEN_ROUTER_WHEN_PWD_IS_SET=y
|
||||
CONFIG_ESP8266_WIFI_ENABLE_WPA3_SAE=y
|
||||
# CONFIG_ESP8266_WIFI_DEBUG_LOG_ENABLE is not set
|
||||
CONFIG_ESP_PHY_CALIBRATION_AND_DATA_STORAGE=y
|
||||
# CONFIG_ESP_PHY_INIT_DATA_IN_PARTITION is not set
|
||||
CONFIG_ESP_PHY_INIT_DATA_VDD33_CONST=33
|
||||
CONFIG_ESP8266_PHY_MAX_WIFI_TX_POWER=21
|
||||
CONFIG_ESP8266_HSPI_HIGH_THROUGHPUT=y
|
||||
# CONFIG_ESP_ERR_TO_NAME_LOOKUP is not set
|
||||
CONFIG_ESP_SYSTEM_EVENT_QUEUE_SIZE=32
|
||||
CONFIG_ESP_SYSTEM_EVENT_TASK_STACK_SIZE=2048
|
||||
CONFIG_ESP_MAIN_TASK_STACK_SIZE=3584
|
||||
CONFIG_ESP_TIMER_TASK_STACK_SIZE=2048
|
||||
CONFIG_ESP_CONSOLE_UART_DEFAULT=y
|
||||
# CONFIG_ESP_CONSOLE_UART_CUSTOM is not set
|
||||
# CONFIG_ESP_CONSOLE_UART_NONE is not set
|
||||
CONFIG_ESP_CONSOLE_UART_NUM=0
|
||||
CONFIG_ESP_CONSOLE_UART_BAUDRATE=74880
|
||||
# CONFIG_ESP_UART0_SWAP_IO is not set
|
||||
# CONFIG_ESP_TASK_WDT is not set
|
||||
# CONFIG_ESP_TASK_WDT_TIMEOUT_13N is not set
|
||||
# CONFIG_ESP_TASK_WDT_TIMEOUT_14N is not set
|
||||
CONFIG_ESP_TASK_WDT_TIMEOUT_15N=y
|
||||
CONFIG_ESP_TASK_WDT_TIMEOUT_S=15
|
||||
# CONFIG_ESP_EVENT_LOOP_PROFILING is not set
|
||||
CONFIG_ESP_EVENT_POST_FROM_ISR=y
|
||||
CONFIG_ESP_HTTP_CLIENT_ENABLE_HTTPS=y
|
||||
# CONFIG_ESP_HTTP_CLIENT_ENABLE_BASIC_AUTH is not set
|
||||
CONFIG_HTTP_BUF_SIZE=512
|
||||
CONFIG_HTTPD_MAX_REQ_HDR_LEN=512
|
||||
CONFIG_HTTPD_MAX_URI_LEN=512
|
||||
CONFIG_OTA_BUF_SIZE=256
|
||||
# CONFIG_OTA_ALLOW_HTTP is not set
|
||||
# CONFIG_FATFS_CODEPAGE_DYNAMIC is not set
|
||||
CONFIG_FATFS_CODEPAGE_437=y
|
||||
# CONFIG_FATFS_CODEPAGE_720 is not set
|
||||
# CONFIG_FATFS_CODEPAGE_737 is not set
|
||||
# CONFIG_FATFS_CODEPAGE_771 is not set
|
||||
# CONFIG_FATFS_CODEPAGE_775 is not set
|
||||
# CONFIG_FATFS_CODEPAGE_850 is not set
|
||||
# CONFIG_FATFS_CODEPAGE_852 is not set
|
||||
# CONFIG_FATFS_CODEPAGE_855 is not set
|
||||
# CONFIG_FATFS_CODEPAGE_857 is not set
|
||||
# CONFIG_FATFS_CODEPAGE_860 is not set
|
||||
# CONFIG_FATFS_CODEPAGE_861 is not set
|
||||
# CONFIG_FATFS_CODEPAGE_862 is not set
|
||||
# CONFIG_FATFS_CODEPAGE_863 is not set
|
||||
# CONFIG_FATFS_CODEPAGE_864 is not set
|
||||
# CONFIG_FATFS_CODEPAGE_865 is not set
|
||||
# CONFIG_FATFS_CODEPAGE_866 is not set
|
||||
# CONFIG_FATFS_CODEPAGE_869 is not set
|
||||
# CONFIG_FATFS_CODEPAGE_932 is not set
|
||||
# CONFIG_FATFS_CODEPAGE_936 is not set
|
||||
# CONFIG_FATFS_CODEPAGE_949 is not set
|
||||
# CONFIG_FATFS_CODEPAGE_950 is not set
|
||||
CONFIG_FATFS_CODEPAGE=437
|
||||
CONFIG_FATFS_LFN_NONE=y
|
||||
# CONFIG_FATFS_LFN_HEAP is not set
|
||||
# CONFIG_FATFS_LFN_STACK is not set
|
||||
CONFIG_FATFS_FS_LOCK=0
|
||||
CONFIG_FATFS_TIMEOUT_MS=10000
|
||||
CONFIG_FATFS_PER_FILE_CACHE=y
|
||||
CONFIG_FMB_COMM_MODE_TCP_EN=y
|
||||
CONFIG_FMB_TCP_PORT_DEFAULT=502
|
||||
CONFIG_FMB_TCP_PORT_MAX_CONN=5
|
||||
CONFIG_FMB_TCP_CONNECTION_TOUT_SEC=20
|
||||
CONFIG_FMB_MASTER_TIMEOUT_MS_RESPOND=150
|
||||
CONFIG_FMB_MASTER_DELAY_MS_CONVERT=200
|
||||
CONFIG_FMB_QUEUE_LENGTH=20
|
||||
CONFIG_FMB_PORT_TASK_STACK_SIZE=4096
|
||||
CONFIG_FMB_SERIAL_BUF_SIZE=256
|
||||
CONFIG_FMB_PORT_TASK_PRIO=10
|
||||
CONFIG_FMB_CONTROLLER_SLAVE_ID_SUPPORT=y
|
||||
CONFIG_FMB_CONTROLLER_SLAVE_ID=0x00112233
|
||||
CONFIG_FMB_CONTROLLER_NOTIFY_TIMEOUT=20
|
||||
CONFIG_FMB_CONTROLLER_NOTIFY_QUEUE_SIZE=20
|
||||
CONFIG_FMB_CONTROLLER_STACK_SIZE=4096
|
||||
CONFIG_FMB_EVENT_QUEUE_TIMEOUT=20
|
||||
CONFIG_FMB_TIMER_GROUP=0
|
||||
CONFIG_FMB_TIMER_INDEX=0
|
||||
# CONFIG_FMB_TIMER_ISR_IN_IRAM is not set
|
||||
# CONFIG_DISABLE_FREERTOS is not set
|
||||
CONFIG_FREERTOS_UNICORE=y
|
||||
# CONFIG_FREERTOS_ENABLE_REENT is not set
|
||||
CONFIG_FREERTOS_HZ=100
|
||||
CONFIG_FREERTOS_NO_AFFINITY=0x7FFFFFFF
|
||||
CONFIG_FREERTOS_HZ=1000
|
||||
CONFIG_FREERTOS_MAX_HOOK=2
|
||||
CONFIG_FREERTOS_IDLE_TASK_STACKSIZE=1024
|
||||
CONFIG_FREERTOS_ISR_STACKSIZE=512
|
||||
|
@ -167,7 +232,10 @@ CONFIG_TASK_SWITCH_FASTER=y
|
|||
# CONFIG_ENABLE_FREERTOS_SLEEP is not set
|
||||
# CONFIG_FREERTOS_USE_TRACE_FACILITY is not set
|
||||
# CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS is not set
|
||||
CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK=y
|
||||
CONFIG_HEAP_DISABLE_IRAM=y
|
||||
# CONFIG_HEAP_TRACING is not set
|
||||
CONFIG_LIBSODIUM_USE_MBEDTLS_SHA=y
|
||||
# CONFIG_LOG_DEFAULT_LEVEL_NONE is not set
|
||||
CONFIG_LOG_DEFAULT_LEVEL_ERROR=y
|
||||
# CONFIG_LOG_DEFAULT_LEVEL_WARN is not set
|
||||
|
@ -177,73 +245,84 @@ CONFIG_LOG_DEFAULT_LEVEL_ERROR=y
|
|||
CONFIG_LOG_DEFAULT_LEVEL=1
|
||||
CONFIG_LOG_COLORS=y
|
||||
# CONFIG_LOG_SET_LEVEL is not set
|
||||
CONFIG_LWIP_USE_IRAM=y
|
||||
CONFIG_LWIP_HIGH_THROUGHPUT=y
|
||||
CONFIG_TCPIP_RECVMBOX_SIZE=64
|
||||
CONFIG_LWIP_ARP_TABLE_SIZE=10
|
||||
CONFIG_LWIP_ARP_MAXAGE=300
|
||||
# CONFIG_LWIP_ESP_GRATUITOUS_ARP is not set
|
||||
# CONFIG_LWIP_SOCKET_MULTITHREAD is not set
|
||||
CONFIG_ENABLE_NONBLOCK_SPEEDUP=y
|
||||
CONFIG_ESP_UDP_SYNC_SEND=y
|
||||
CONFIG_ESP_UDP_SYNC_RETRY_MAX=5
|
||||
CONFIG_LWIP_LOCAL_HOSTNAME="espressif"
|
||||
CONFIG_LWIP_DNS_SUPPORT_MDNS_QUERIES=y
|
||||
# CONFIG_LWIP_L2_TO_L3_COPY is not set
|
||||
CONFIG_LWIP_IRAM_OPTIMIZATION=y
|
||||
CONFIG_LWIP_TIMERS_ONDEMAND=y
|
||||
CONFIG_LWIP_MAX_SOCKETS=10
|
||||
# CONFIG_LWIP_USE_ONLY_LWIP_SELECT is not set
|
||||
# CONFIG_LWIP_SO_LINGER is not set
|
||||
CONFIG_LWIP_SO_REUSE=y
|
||||
CONFIG_LWIP_SO_REUSE_RXTOALL=y
|
||||
# CONFIG_LWIP_SO_RCVBUF is not set
|
||||
CONFIG_LWIP_RECV_BUFSIZE_DEFAULT=11680
|
||||
CONFIG_LWIP_TCP_CLOSE_TIMEOUT_MS_DEFAULT=10000
|
||||
CONFIG_LWIP_IP_FRAG=y
|
||||
CONFIG_LWIP_IP_REASSEMBLY=y
|
||||
CONFIG_LWIP_IP_REASS_MAX_PBUFS=10
|
||||
# CONFIG_LWIP_IP_SOF_BROADCAST is not set
|
||||
# CONFIG_LWIP_IP_SOF_BROADCAST_RECV is not set
|
||||
CONFIG_LWIP_ICMP=y
|
||||
# CONFIG_LWIP_MULTICAST_PING is not set
|
||||
# CONFIG_LWIP_BROADCAST_PING is not set
|
||||
# CONFIG_LWIP_RAW is not set
|
||||
# CONFIG_LWIP_NETBUF_RECVINFO is not set
|
||||
CONFIG_LWIP_IP4_FRAG=y
|
||||
# CONFIG_LWIP_IP6_FRAG is not set
|
||||
# CONFIG_LWIP_IP4_REASSEMBLY is not set
|
||||
# CONFIG_LWIP_IP6_REASSEMBLY is not set
|
||||
# CONFIG_LWIP_IP_FORWARD is not set
|
||||
# CONFIG_LWIP_STATS is not set
|
||||
# CONFIG_LWIP_ETHARP_TRUST_IP_MAC is not set
|
||||
# CONFIG_LWIP_ESP_GRATUITOUS_ARP is not set
|
||||
CONFIG_LWIP_TCPIP_RECVMBOX_SIZE=64
|
||||
CONFIG_LWIP_DHCP_DOES_ARP_CHECK=y
|
||||
CONFIG_LWIP_DHCP_MAX_NTP_SERVERS=1
|
||||
# CONFIG_LWIP_DHCP_RESTORE_LAST_IP is not set
|
||||
CONFIG_LWIP_DHCPS_LEASE_UNIT=60
|
||||
CONFIG_LWIP_DHCPS_MAX_STATION_NUM=8
|
||||
CONFIG_LWIP_DHCP_DISCOVER_RETRANSMISSION_INTERVAL=250
|
||||
# CONFIG_LWIP_AUTOIP is not set
|
||||
CONFIG_LWIP_IGMP=y
|
||||
CONFIG_ESP_DNS=y
|
||||
CONFIG_DNS_MAX_SERVERS=3
|
||||
# CONFIG_LWIP_IPV6_AUTOCONFIG is not set
|
||||
# CONFIG_LWIP_NETIF_LOOPBACK is not set
|
||||
CONFIG_TCP_HIGH_SPEED_RETRANSMISSION=y
|
||||
CONFIG_LWIP_MAX_ACTIVE_TCP=16
|
||||
CONFIG_LWIP_MAX_LISTENING_TCP=8
|
||||
CONFIG_TCP_MAXRTX=12
|
||||
CONFIG_TCP_SYNMAXRTX=6
|
||||
CONFIG_TCP_MSS=1460
|
||||
CONFIG_TCP_SND_BUF_DEFAULT=2920
|
||||
CONFIG_TCP_WND_DEFAULT=10240
|
||||
CONFIG_TCP_RECVMBOX_SIZE=16
|
||||
CONFIG_TCP_QUEUE_OOSEQ=y
|
||||
CONFIG_TCP_OVERSIZE_MSS=y
|
||||
# CONFIG_TCP_OVERSIZE_QUARTER_MSS is not set
|
||||
# CONFIG_TCP_OVERSIZE_DISABLE is not set
|
||||
# CONFIG_LWIP_TCP_TIMESTAMPS is not set
|
||||
CONFIG_LWIP_TCP_MAXRTX=12
|
||||
CONFIG_LWIP_TCP_SYNMAXRTX=6
|
||||
CONFIG_LWIP_TCP_MSS=1460
|
||||
CONFIG_LWIP_TCP_TMR_INTERVAL=250
|
||||
CONFIG_LWIP_TCP_MSL=60000
|
||||
CONFIG_LWIP_TCP_SND_BUF_DEFAULT=11680
|
||||
CONFIG_LWIP_TCP_WND_DEFAULT=10240
|
||||
CONFIG_LWIP_TCP_RECVMBOX_SIZE=16
|
||||
CONFIG_LWIP_TCP_QUEUE_OOSEQ=y
|
||||
# CONFIG_LWIP_TCP_SACK_OUT is not set
|
||||
# CONFIG_LWIP_TCP_KEEP_CONNECTION_WHEN_IP_CHANGES is not set
|
||||
CONFIG_LWIP_TCP_OVERSIZE_MSS=y
|
||||
# CONFIG_LWIP_TCP_OVERSIZE_QUARTER_MSS is not set
|
||||
# CONFIG_LWIP_TCP_OVERSIZE_DISABLE is not set
|
||||
CONFIG_LWIP_TCP_RTO_TIME=3000
|
||||
CONFIG_LWIP_MAX_UDP_PCBS=4
|
||||
CONFIG_UDP_RECVMBOX_SIZE=6
|
||||
CONFIG_TCPIP_TASK_STACK_SIZE=4096
|
||||
CONFIG_LWIP_UDP_RECVMBOX_SIZE=6
|
||||
CONFIG_LWIP_TCPIP_TASK_STACK_SIZE=4096
|
||||
CONFIG_LWIP_TCPIP_TASK_AFFINITY_NO_AFFINITY=y
|
||||
# CONFIG_LWIP_TCPIP_TASK_AFFINITY_CPU0 is not set
|
||||
CONFIG_LWIP_TCPIP_TASK_AFFINITY=0x7FFFFFFF
|
||||
# CONFIG_LWIP_PPP_SUPPORT is not set
|
||||
CONFIG_LWIP_IPV6_MEMP_NUM_ND6_QUEUE=3
|
||||
CONFIG_LWIP_IPV6_ND6_NUM_NEIGHBORS=5
|
||||
# CONFIG_LWIP_MULTICAST_PING is not set
|
||||
# CONFIG_LWIP_BROADCAST_PING is not set
|
||||
CONFIG_LWIP_MAX_RAW_PCBS=4
|
||||
# CONFIG_LWIP_IPV6 is not set
|
||||
# CONFIG_LWIP_STATS is not set
|
||||
# CONFIG_ESP_LWIP_MEM_DBG is not set
|
||||
# CONFIG_LWIP_DEBUG is not set
|
||||
CONFIG_LWIP_DHCP_MAX_NTP_SERVERS=1
|
||||
CONFIG_LWIP_SNTP_UPDATE_DELAY=3600000
|
||||
CONFIG_LWIP_ESP_LWIP_ASSERT=y
|
||||
# CONFIG_LWIP_NETIF_DEBUG is not set
|
||||
# CONFIG_LWIP_PBUF_DEBUG is not set
|
||||
# CONFIG_LWIP_ETHARP_DEBUG is not set
|
||||
# CONFIG_LWIP_API_LIB_DEBUG is not set
|
||||
# CONFIG_LWIP_SOCKETS_DEBUG is not set
|
||||
# CONFIG_LWIP_IP_DEBUG is not set
|
||||
# CONFIG_LWIP_ICMP_DEBUG is not set
|
||||
# CONFIG_LWIP_IP6_DEBUG is not set
|
||||
# CONFIG_LWIP_ICMP6_DEBUG is not set
|
||||
CONFIG_MBEDTLS_INTERNAL_MEM_ALLOC=y
|
||||
# CONFIG_MBEDTLS_DEFAULT_MEM_ALLOC is not set
|
||||
# CONFIG_MBEDTLS_CUSTOM_MEM_ALLOC is not set
|
||||
CONFIG_MBEDTLS_ASYMMETRIC_CONTENT_LEN=y
|
||||
CONFIG_MBEDTLS_SSL_IN_CONTENT_LEN=16384
|
||||
CONFIG_MBEDTLS_SSL_OUT_CONTENT_LEN=4096
|
||||
# CONFIG_MBEDTLS_DYNAMIC_BUFFER is not set
|
||||
# CONFIG_MBEDTLS_DEBUG is not set
|
||||
CONFIG_MBEDTLS_HARDWARE_AES=y
|
||||
# CONFIG_MBEDTLS_HARDWARE_MPI is not set
|
||||
CONFIG_MBEDTLS_HARDWARE_SHA=y
|
||||
CONFIG_MBEDTLS_HAVE_TIME=y
|
||||
# CONFIG_MBEDTLS_HAVE_TIME_DATE is not set
|
||||
CONFIG_MBEDTLS_TLS_SERVER_AND_CLIENT=y
|
||||
|
@ -301,29 +380,19 @@ CONFIG_MBEDTLS_ECP_DP_BP384R1_ENABLED=y
|
|||
CONFIG_MBEDTLS_ECP_DP_BP512R1_ENABLED=y
|
||||
CONFIG_MBEDTLS_ECP_DP_CURVE25519_ENABLED=y
|
||||
CONFIG_MBEDTLS_ECP_NIST_OPTIM=y
|
||||
# CONFIG_util_assert is not set
|
||||
CONFIG_ESP_SHA=y
|
||||
CONFIG_ESP_AES=y
|
||||
CONFIG_ESP_MD5=y
|
||||
CONFIG_ESP_ARC4=y
|
||||
# CONFIG_ENABLE_MDNS is not set
|
||||
# CONFIG_MQTT_USING_ESP is not set
|
||||
CONFIG_MQTT_USING_IBM=y
|
||||
CONFIG_V3_1=y
|
||||
# CONFIG_V3_1_1 is not set
|
||||
CONFIG_DEFAULT_MQTT_VERSION=3
|
||||
CONFIG_MQTT_CLIENT_ID="espressif_sample"
|
||||
CONFIG_MQTT_KEEP_ALIVE=30
|
||||
CONFIG_MQTT_USERNAME="espressif"
|
||||
CONFIG_MQTT_PASSWORD="admin"
|
||||
CONFIG_CLEAN_SESSION=y
|
||||
# CONFIG_KEEP_SESSION is not set
|
||||
CONFIG_DEFAULT_MQTT_SESSION=1
|
||||
CONFIG_NO_TLS=y
|
||||
# CONFIG_TLS_VERIFY_NONE is not set
|
||||
# CONFIG_TLS_VERIFY_PEER is not set
|
||||
# CONFIG_TLS_VERIFY_CLIENT is not set
|
||||
CONFIG_DEFAULT_MQTT_SECURITY=0
|
||||
CONFIG_MQTT_SEND_BUFFER=2048
|
||||
CONFIG_MQTT_RECV_BUFFER=2048
|
||||
CONFIG_MQTT_SEND_CYCLE=30000
|
||||
CONFIG_MQTT_RECV_CYCLE=0
|
||||
CONFIG_MQTT_PING_TIMEOUT=3000
|
||||
CONFIG_MQTT_PROTOCOL_311=y
|
||||
CONFIG_MQTT_TRANSPORT_SSL=y
|
||||
CONFIG_MQTT_TRANSPORT_WEBSOCKET=y
|
||||
CONFIG_MQTT_TRANSPORT_WEBSOCKET_SECURE=y
|
||||
# CONFIG_MQTT_USE_CUSTOM_CONFIG is not set
|
||||
# CONFIG_MQTT_TASK_CORE_SELECTION_ENABLED is not set
|
||||
# CONFIG_MQTT_CUSTOM_OUTBOX is not set
|
||||
# CONFIG_NEWLIB_LIBRARY_LEVEL_NORMAL is not set
|
||||
# CONFIG_NEWLIB_LIBRARY_LEVEL_NANO is not set
|
||||
CONFIG_NEWLIB_LIBRARY_LEVEL_FLOAT_NANO=y
|
||||
|
@ -331,17 +400,45 @@ CONFIG_NEWLIB_LIBRARY_LEVEL_FLOAT_NANO=y
|
|||
# CONFIG_OPENSSL_DEBUG is not set
|
||||
CONFIG_OPENSSL_ASSERT_DO_NOTHING=y
|
||||
# CONFIG_OPENSSL_ASSERT_EXIT is not set
|
||||
# CONFIG_ENABLE_PTHREAD is not set
|
||||
# CONFIG_USING_SPIFFS is not set
|
||||
CONFIG_ENABLE_PTHREAD=y
|
||||
CONFIG_PTHREAD_TASK_PRIO_DEFAULT=5
|
||||
CONFIG_PTHREAD_TASK_STACK_SIZE_DEFAULT=3072
|
||||
CONFIG_PTHREAD_STACK_MIN=768
|
||||
CONFIG_PTHREAD_TASK_NAME_DEFAULT="pthread"
|
||||
CONFIG_SPIFFS_MAX_PARTITIONS=3
|
||||
CONFIG_SPIFFS_CACHE=y
|
||||
CONFIG_SPIFFS_CACHE_WR=y
|
||||
# CONFIG_SPIFFS_CACHE_STATS is not set
|
||||
CONFIG_SPIFFS_PAGE_CHECK=y
|
||||
CONFIG_SPIFFS_GC_MAX_RUNS=10
|
||||
# CONFIG_SPIFFS_GC_STATS is not set
|
||||
CONFIG_SPIFFS_PAGE_SIZE=256
|
||||
CONFIG_SPIFFS_OBJ_NAME_LEN=32
|
||||
CONFIG_SPIFFS_USE_MAGIC=y
|
||||
CONFIG_SPIFFS_USE_MAGIC_LENGTH=y
|
||||
CONFIG_SPIFFS_META_LENGTH=4
|
||||
CONFIG_SPIFFS_USE_MTIME=y
|
||||
# CONFIG_SPIFFS_DBG is not set
|
||||
# CONFIG_SPIFFS_API_DBG is not set
|
||||
# CONFIG_SPIFFS_GC_DBG is not set
|
||||
# CONFIG_SPIFFS_CACHE_DBG is not set
|
||||
# CONFIG_SPIFFS_CHECK_DBG is not set
|
||||
# CONFIG_SPIFFS_TEST_VISUALISATION is not set
|
||||
CONFIG_IP_LOST_TIMER_INTERVAL=120
|
||||
# CONFIG_util_assert is not set
|
||||
CONFIG_ESP_SHA=y
|
||||
CONFIG_ESP_AES=y
|
||||
CONFIG_ESP_MD5=y
|
||||
CONFIG_ESP_ARC4=y
|
||||
# CONFIG_USING_ESP_VFS is not set
|
||||
CONFIG_VFS_SUPPRESS_SELECT_DEBUG_OUTPUT=y
|
||||
CONFIG_VFS_SUPPORT_TERMIOS=y
|
||||
CONFIG_SEMIHOSTFS_MAX_MOUNT_POINTS=1
|
||||
CONFIG_SEMIHOSTFS_HOST_PATH_MAX_LEN=128
|
||||
# CONFIG_WL_SECTOR_SIZE_512 is not set
|
||||
CONFIG_WL_SECTOR_SIZE_4096=y
|
||||
CONFIG_WL_SECTOR_SIZE=4096
|
||||
# CONFIG_ENABLE_UNIFIED_PROVISIONING is not set
|
||||
CONFIG_LTM_FAST=y
|
||||
CONFIG_WPA_MBEDTLS_CRYPTO=y
|
||||
# CONFIG_WPA_DEBUG_PRINT is not set
|
||||
# CONFIG_WPA_TESTING_OPTIONS is not set
|
||||
# CONFIG_WPA_WPS_WARS is not set
|
||||
# CONFIG_WPA_11KV_SUPPORT is not set
|
||||
|
||||
# Deprecated options for backward compatibility
|
||||
CONFIG_TARGET_PLATFORM="esp8266"
|
||||
|
@ -372,4 +469,55 @@ CONFIG_STACK_CHECK_NONE=y
|
|||
# CONFIG_STACK_CHECK_ALL is not set
|
||||
# CONFIG_STACK_CHECK is not set
|
||||
# CONFIG_WARN_WRITE_STRINGS is not set
|
||||
CONFIG_MAIN_TASK_STACK_SIZE=3584
|
||||
CONFIG_CONSOLE_UART_DEFAULT=y
|
||||
# CONFIG_CONSOLE_UART_CUSTOM is not set
|
||||
# CONFIG_CONSOLE_UART_NONE is not set
|
||||
CONFIG_CONSOLE_UART_NUM=0
|
||||
CONFIG_CONSOLE_UART_BAUDRATE=74880
|
||||
# CONFIG_UART0_SWAP_IO is not set
|
||||
# CONFIG_TASK_WDT is not set
|
||||
CONFIG_TASK_WDT_TIMEOUT_S=15
|
||||
CONFIG_MB_MASTER_TIMEOUT_MS_RESPOND=150
|
||||
CONFIG_MB_MASTER_DELAY_MS_CONVERT=200
|
||||
CONFIG_MB_QUEUE_LENGTH=20
|
||||
CONFIG_MB_SERIAL_TASK_STACK_SIZE=4096
|
||||
CONFIG_MB_SERIAL_BUF_SIZE=256
|
||||
CONFIG_MB_SERIAL_TASK_PRIO=10
|
||||
CONFIG_MB_CONTROLLER_SLAVE_ID_SUPPORT=y
|
||||
CONFIG_MB_CONTROLLER_SLAVE_ID=0x00112233
|
||||
CONFIG_MB_CONTROLLER_NOTIFY_TIMEOUT=20
|
||||
CONFIG_MB_CONTROLLER_NOTIFY_QUEUE_SIZE=20
|
||||
CONFIG_MB_CONTROLLER_STACK_SIZE=4096
|
||||
CONFIG_MB_EVENT_QUEUE_TIMEOUT=20
|
||||
CONFIG_MB_TIMER_GROUP=0
|
||||
CONFIG_MB_TIMER_INDEX=0
|
||||
# CONFIG_L2_TO_L3_COPY is not set
|
||||
# CONFIG_USE_ONLY_LWIP_SELECT is not set
|
||||
# CONFIG_ESP_GRATUITOUS_ARP is not set
|
||||
CONFIG_TCPIP_RECVMBOX_SIZE=64
|
||||
CONFIG_TCP_MAXRTX=12
|
||||
CONFIG_TCP_SYNMAXRTX=6
|
||||
CONFIG_TCP_MSS=1460
|
||||
CONFIG_TCP_MSL=60000
|
||||
CONFIG_TCP_SND_BUF_DEFAULT=11680
|
||||
CONFIG_TCP_WND_DEFAULT=10240
|
||||
CONFIG_TCP_RECVMBOX_SIZE=16
|
||||
CONFIG_TCP_QUEUE_OOSEQ=y
|
||||
# CONFIG_ESP_TCP_KEEP_CONNECTION_WHEN_IP_CHANGES is not set
|
||||
CONFIG_TCP_OVERSIZE_MSS=y
|
||||
# CONFIG_TCP_OVERSIZE_QUARTER_MSS is not set
|
||||
# CONFIG_TCP_OVERSIZE_DISABLE is not set
|
||||
CONFIG_UDP_RECVMBOX_SIZE=6
|
||||
CONFIG_TCPIP_TASK_STACK_SIZE=4096
|
||||
CONFIG_TCPIP_TASK_AFFINITY_NO_AFFINITY=y
|
||||
# CONFIG_TCPIP_TASK_AFFINITY_CPU0 is not set
|
||||
CONFIG_TCPIP_TASK_AFFINITY=0x7FFFFFFF
|
||||
# CONFIG_PPP_SUPPORT is not set
|
||||
CONFIG_ESP32_PTHREAD_TASK_PRIO_DEFAULT=5
|
||||
CONFIG_ESP32_PTHREAD_TASK_STACK_SIZE_DEFAULT=3072
|
||||
CONFIG_ESP32_PTHREAD_STACK_MIN=768
|
||||
CONFIG_ESP32_PTHREAD_TASK_NAME_DEFAULT="pthread"
|
||||
CONFIG_SUPPRESS_SELECT_DEBUG_OUTPUT=y
|
||||
CONFIG_SUPPORT_TERMIOS=y
|
||||
# End of deprecated options
|
||||
|
|
Loading…
Reference in New Issue