fix: 🐛 letter shell的USB CDC打印问题
file: 📦 添加main_app,未验证
This commit is contained in:
parent
779eea97db
commit
cbaaace76b
6
.gitmodules
vendored
Normal file
6
.gitmodules
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
[submodule "main/utilities/imp_util_ring_queue"]
|
||||
path = main/utilities/imp_util_ring_queue
|
||||
url = ssh://git@192.168.124.23:222/Utilities/imp_util_ring_queue.git
|
||||
[submodule "main/utilities/imp_types"]
|
||||
path = main/utilities/imp_types
|
||||
url = ssh://git@192.168.124.23:222/Utilities/imp_types.git
|
||||
0
main/APP/README.md
Normal file
0
main/APP/README.md
Normal file
51
main/APP/main_app/main_app.c
Normal file
51
main/APP/main_app/main_app.c
Normal file
@ -0,0 +1,51 @@
|
||||
/**
|
||||
* @file main_app.c
|
||||
* @author Alvin Young (impressionyang@outlook.com)
|
||||
* @brief
|
||||
* @version 0.1
|
||||
* @date 2024-11-25
|
||||
*
|
||||
* _ _
|
||||
* (_)_ _ ___ _______ ___ ___ (_)__ ___ __ _____ ____ ___ _
|
||||
* / / ' \/ _ \/ __/ -_|_-<(_-</ / _ \/ _ \/ // / _ `/ _ \/ _ `/
|
||||
* /_/_/_/_/ .__/_/ \__/___/___/_/\___/_//_/\_, /\_,_/_//_/\_, /
|
||||
* /_/ /___/ /___/
|
||||
* @copyright Copyright (c) 2024 impressionyang
|
||||
*
|
||||
* @par 修改日志:
|
||||
* <table>
|
||||
* <tr><th>Date <th>Version <th>Author <th>Description
|
||||
* <tr><td>2024-11-25 <td>v1.0 <td>Alvin Young <td>首次创建
|
||||
* </table>
|
||||
*
|
||||
*/
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "main_app.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "esp_system.h"
|
||||
#include "esp_chip_info.h"
|
||||
#include "sdkconfig.h"
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "main_common.h"
|
||||
|
||||
/* define --------------------------------------------------------------------*/
|
||||
/* typedef -------------------------------------------------------------------*/
|
||||
/* variables -----------------------------------------------------------------*/
|
||||
/* Private function(only *.c) -----------------------------------------------*/
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
|
||||
uint8_t imp_main_app_task()
|
||||
{
|
||||
int i = 0;
|
||||
while (1) {
|
||||
cdc_printf("hello %d\r\n", i++);
|
||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/*
|
||||
* EOF
|
||||
*/
|
||||
47
main/APP/main_app/main_app.h
Normal file
47
main/APP/main_app/main_app.h
Normal file
@ -0,0 +1,47 @@
|
||||
/**
|
||||
* @file main_app.h
|
||||
* @author Alvin Young (impressionyang@outlook.com)
|
||||
* @brief
|
||||
* @version 0.1
|
||||
* @date 2024-11-25
|
||||
*
|
||||
* _ _
|
||||
* (_)_ _ ___ _______ ___ ___ (_)__ ___ __ _____ ____ ___ _
|
||||
* / / ' \/ _ \/ __/ -_|_-<(_-</ / _ \/ _ \/ // / _ `/ _ \/ _ `/
|
||||
* /_/_/_/_/ .__/_/ \__/___/___/_/\___/_//_/\_, /\_,_/_//_/\_, /
|
||||
* /_/ /___/ /___/
|
||||
* @copyright Copyright (c) 2024 impressionyang
|
||||
*
|
||||
* @par 修改日志:
|
||||
* <table>
|
||||
* <tr><th>Date <th>Version <th>Author <th>Description
|
||||
* <tr><td>2024-11-25 <td>v1.0 <td>Alvin Young <td>首次创建
|
||||
* </table>
|
||||
*
|
||||
*/
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __MAIN_APP_H__
|
||||
#define __MAIN_APP_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/* define --------------------------------------------------------------------*/
|
||||
/* typedef -------------------------------------------------------------------*/
|
||||
/* variables -----------------------------------------------------------------*/
|
||||
/* Private function(only *.c) -----------------------------------------------*/
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
|
||||
uint8_t imp_main_app_task();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif //__MAIN_APP_H__
|
||||
/*
|
||||
* EOF
|
||||
*/
|
||||
@ -8,13 +8,17 @@ idf_component_register(
|
||||
"utilities/usb_cherry/CherryUSB/class/cdc/"
|
||||
"utilities/usb_cherry/CherryUSB/class/msc/"
|
||||
"utilities/usb_cherry/CherryUSB/core/"
|
||||
"utilities/usb_cherry/CherryUSB/port/dwc2"
|
||||
"utilities/usb_cherry/CherryUSB/port/dwc2/"
|
||||
"utilities/imp_util_ring_queue/"
|
||||
"utilities/imp_types/"
|
||||
"APP/main_app/"
|
||||
|
||||
EXCLUDE_SRCS
|
||||
"utilities/usb_cherry/CherryUSB/class/cdc/usbh_cdc_acm.c"
|
||||
"utilities/usb_cherry/CherryUSB/class/msc/usbh_msc.c"
|
||||
"utilities/usb_cherry/CherryUSB/core/usbh_core.c"
|
||||
"utilities/usb_cherry/CherryUSB/port/dwc2/usb_hc_dwc2.c"
|
||||
"utilities/imp_util_ring_queue/ring_queue_test.c"
|
||||
|
||||
INCLUDE_DIRS
|
||||
"."
|
||||
@ -27,6 +31,9 @@ idf_component_register(
|
||||
"utilities/usb_cherry/CherryUSB/common"
|
||||
"utilities/usb_cherry/CherryUSB/core"
|
||||
"utilities/usb_cherry/CherryUSB/port/dwc2"
|
||||
"utilities/imp_util_ring_queue/"
|
||||
"APP/main_app/"
|
||||
"utilities/imp_types/"
|
||||
|
||||
LDFRAGMENTS
|
||||
"utilities/letter_shell/port/esp-idf/shell.lf"
|
||||
|
||||
20
main/main.c
20
main/main.c
@ -18,6 +18,8 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "shell_port.h"
|
||||
#include "main_app.h"
|
||||
#include "main_common.h"
|
||||
|
||||
static void _init_esp()
|
||||
{
|
||||
@ -31,18 +33,14 @@ static void _init_esp()
|
||||
ESP_ERROR_CHECK(ret);
|
||||
}
|
||||
|
||||
extern void cdc_acm_msc_init();
|
||||
extern int cdc_printf(const char* fmt, ...);
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
_init_esp();
|
||||
vTaskDelay(10);
|
||||
userShellInit();
|
||||
vTaskDelay(10);
|
||||
|
||||
printf("Hello world!\n");
|
||||
cdc_acm_msc_init();
|
||||
vTaskDelay(10);
|
||||
userShellInit();
|
||||
cdc_printf("Hello world!\n");
|
||||
|
||||
/* Print chip information */
|
||||
esp_chip_info_t chip_info;
|
||||
@ -76,11 +74,9 @@ void app_main(void)
|
||||
// printf("Restarting in %d seconds...\n", i);
|
||||
// vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||
// }
|
||||
int i = 0;
|
||||
while (1) {
|
||||
cdc_printf("hello %d\r\n", i++);
|
||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||
}
|
||||
cdc_printf("start run app:\r\n");
|
||||
imp_main_app_task();
|
||||
|
||||
printf("Restarting now.\n");
|
||||
fflush(stdout);
|
||||
esp_restart();
|
||||
|
||||
49
main/main_common.h
Normal file
49
main/main_common.h
Normal file
@ -0,0 +1,49 @@
|
||||
/**
|
||||
* @file main_common.h
|
||||
* @author Alvin Young (impressionyang@outlook.com)
|
||||
* @brief
|
||||
* @version 0.1
|
||||
* @date 2024-11-25
|
||||
*
|
||||
* _ _
|
||||
* (_)_ _ ___ _______ ___ ___ (_)__ ___ __ _____ ____ ___ _
|
||||
* / / ' \/ _ \/ __/ -_|_-<(_-</ / _ \/ _ \/ // / _ `/ _ \/ _ `/
|
||||
* /_/_/_/_/ .__/_/ \__/___/___/_/\___/_//_/\_, /\_,_/_//_/\_, /
|
||||
* /_/ /___/ /___/
|
||||
* @copyright Copyright (c) 2024 impressionyang
|
||||
*
|
||||
* @par 修改日志:
|
||||
* <table>
|
||||
* <tr><th>Date <th>Version <th>Author <th>Description
|
||||
* <tr><td>2024-11-25 <td>v1.0 <td>Alvin Young <td>首次创建
|
||||
* </table>
|
||||
*
|
||||
*/
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __MAIN_COMMON_H__
|
||||
#define __MAIN_COMMON_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
/* define --------------------------------------------------------------------*/
|
||||
/* typedef -------------------------------------------------------------------*/
|
||||
/* variables -----------------------------------------------------------------*/
|
||||
/* Private function(only *.c) -----------------------------------------------*/
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
|
||||
extern void cdc_acm_msc_init();
|
||||
extern int cdc_printf(const char* fmt, ...);
|
||||
extern signed short cdc_usb_read_bytes(char* data, unsigned short len);
|
||||
extern signed short cdc_usb_writ_bytes(char* data, unsigned short len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif //__MAIN_COMMON_H__
|
||||
|
||||
/*
|
||||
* EOF
|
||||
*/
|
||||
1
main/utilities/imp_types
Submodule
1
main/utilities/imp_types
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 6cf82b2d2c8f3c944dd93f079f9cc7f0eef6018c
|
||||
1
main/utilities/imp_util_ring_queue
Submodule
1
main/utilities/imp_util_ring_queue
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 61a122b22be15ef94e2d114a819aee8fb7f39e0d
|
||||
@ -124,7 +124,7 @@
|
||||
* @brief shell格式化输出的缓冲大小
|
||||
* 为0时不使用shell格式化输出
|
||||
*/
|
||||
#define SHELL_PRINT_BUFFER 128
|
||||
#define SHELL_PRINT_BUFFER 64
|
||||
|
||||
/**
|
||||
* @brief shell格式化输入的缓冲大小
|
||||
@ -171,13 +171,13 @@
|
||||
/**
|
||||
* @brief shell默认用户
|
||||
*/
|
||||
#define SHELL_DEFAULT_USER "letter"
|
||||
#define SHELL_DEFAULT_USER "alvin"
|
||||
|
||||
/**
|
||||
* @brief shell默认用户密码
|
||||
* 若默认用户不需要密码,设为""
|
||||
*/
|
||||
#define SHELL_DEFAULT_USER_PASSWORD ""
|
||||
#define SHELL_DEFAULT_USER_PASSWORD "passwd"
|
||||
|
||||
/**
|
||||
* @brief shell自动锁定超时
|
||||
|
||||
@ -12,6 +12,7 @@
|
||||
#include "shell.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "driver/uart.h"
|
||||
#include "main_common.h"
|
||||
|
||||
|
||||
#define SHELL_UART UART_NUM_0
|
||||
@ -29,7 +30,13 @@ char shellBuffer[512];
|
||||
*/
|
||||
unsigned short userShellWrite(char *data, unsigned short len)
|
||||
{
|
||||
return uart_write_bytes(SHELL_UART, (const char *)data, len);
|
||||
// return uart_write_bytes(SHELL_UART, (const char *)data, len);
|
||||
// return cdc_usb_writ_bytes(data, len);
|
||||
unsigned short ret = 0;
|
||||
ret = cdc_usb_writ_bytes(data, len);
|
||||
// cdc_printf("write need : %d, get %d\r\n", len, ret);
|
||||
// cdc_printf("%s", data);
|
||||
return len;
|
||||
}
|
||||
|
||||
|
||||
@ -43,7 +50,11 @@ unsigned short userShellWrite(char *data, unsigned short len)
|
||||
*/
|
||||
signed char userShellRead(char *data, unsigned short len)
|
||||
{
|
||||
return uart_read_bytes(SHELL_UART, (uint8_t *)data, len, portMAX_DELAY);
|
||||
// return uart_read_bytes(SHELL_UART, (uint8_t *)data, len, portMAX_DELAY);
|
||||
signed char ret = 0;
|
||||
ret = cdc_usb_read_bytes(data, len);
|
||||
// cdc_printf("read need : %d, get %d\r\n", len, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -3,6 +3,8 @@
|
||||
#include "usbd_msc.h"
|
||||
#include <stdarg.h>
|
||||
|
||||
#include "imp_util_ring_queue.h"
|
||||
|
||||
/*!< endpoint address */
|
||||
#define CDC_IN_EP 0x81
|
||||
#define CDC_OUT_EP 0x02
|
||||
@ -107,18 +109,27 @@ usbd_interface_t cdc_cmd_intf;
|
||||
/*!< interface two */
|
||||
usbd_interface_t cdc_data_intf;
|
||||
|
||||
imp_util_ring_queue_t ring_q_cdc_recv = {0};
|
||||
unsigned char ring_q_cdc_recv_swap_data[1024 + 1] = { 0 };
|
||||
|
||||
/* function ------------------------------------------------------------------*/
|
||||
int cdc_printf(const char *fmt, ...);
|
||||
|
||||
void usbd_cdc_acm_out(uint8_t ep)
|
||||
{
|
||||
uint8_t data[64];
|
||||
uint32_t read_byte;
|
||||
|
||||
usbd_ep_read(ep, data, 64, &read_byte);
|
||||
for (uint8_t i = 0; i < read_byte; i++) {
|
||||
USB_LOG_RAW("%02x ", data[i]);
|
||||
}
|
||||
USB_LOG_RAW("\r\n");
|
||||
USB_LOG_RAW("read len:%d\r\n", read_byte);
|
||||
imp_util_ring_queue_write(&ring_q_cdc_recv, data, read_byte);
|
||||
// for (uint8_t i = 0; i < read_byte; i++) {
|
||||
// USB_LOG_RAW("%02x ", data[i]);
|
||||
// cdc_printf("%02x ", data[i]);
|
||||
// }
|
||||
// USB_LOG_RAW("\r\n");
|
||||
// USB_LOG_RAW("read len:%d\r\n", read_byte);
|
||||
// cdc_printf("\r\n");
|
||||
// cdc_printf("read len:%d\r\n", read_byte);
|
||||
usbd_ep_read(ep, NULL, 0, NULL);
|
||||
}
|
||||
|
||||
@ -152,6 +163,9 @@ void cdc_acm_msc_init(void)
|
||||
// usbd_msc_class_init(MSC_OUT_EP, MSC_IN_EP);
|
||||
|
||||
usbd_initialize();
|
||||
|
||||
imp_util_ring_queue_init(&ring_q_cdc_recv, ring_q_cdc_recv_swap_data, 1025);
|
||||
|
||||
}
|
||||
|
||||
volatile uint8_t dtr_enable = 0;
|
||||
@ -173,9 +187,41 @@ void cdc_acm_data_send_with_dtr_test(void)
|
||||
}
|
||||
}
|
||||
|
||||
signed short cdc_usb_read_bytes(char* data, unsigned short len)
|
||||
{
|
||||
signed short ret = len;
|
||||
if (len >= 64) {
|
||||
ret = 64;
|
||||
}
|
||||
|
||||
if (imp_util_ring_queue_get_wlvl(&ring_q_cdc_recv) >= len) {
|
||||
imp_util_ring_queue_read(&ring_q_cdc_recv, (uint8_t*)data, len);
|
||||
}else {
|
||||
data[0] = 0;
|
||||
ret = 1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
signed short cdc_usb_writ_bytes(char* data, unsigned short len)
|
||||
{
|
||||
signed short n;
|
||||
char aBuffer[64] = { 0 };
|
||||
n = len >= 64 ? 64 : len;
|
||||
aBuffer[63] = '\n';
|
||||
strncpy(aBuffer, data, n);
|
||||
|
||||
if (dtr_enable) {
|
||||
usbd_ep_write(CDC_IN_EP, (uint8_t*)data, n, NULL);
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
int cdc_printf(const char *fmt, ...) {
|
||||
int n;
|
||||
char aBuffer[64];
|
||||
char aBuffer[64] = {0};
|
||||
va_list args;
|
||||
|
||||
va_start(args, fmt);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user