fix: 🐛 APP运行正常配合USB CDC和letter shell

This commit is contained in:
Alvin Young 2024-11-25 12:27:26 +00:00
parent cbaaace76b
commit 604d356a99
6 changed files with 364 additions and 304 deletions

View File

@ -28,24 +28,46 @@
#include "esp_chip_info.h"
#include "sdkconfig.h"
#include <inttypes.h>
#include <stdio.h>
#include "main_common.h"
#include "shell_port.h"
/* define --------------------------------------------------------------------*/
/* typedef -------------------------------------------------------------------*/
/* variables -----------------------------------------------------------------*/
static uint8_t print_en = 0;
/* Private function(only *.c) -----------------------------------------------*/
uint8_t _set_print_en(int argc, char **argv)
{
if (argc < 2) {
cdc_printf("too few argv\r\n");
}
int en_v = atoi(argv[1]);
print_en = en_v;
return 0;
}
/* Exported functions --------------------------------------------------------*/
uint8_t imp_main_app_task()
{
int i = 0;
while (1) {
cdc_printf("hello %d\r\n", i++);
if (print_en) {
cdc_printf("hello %d\r\n", i++);
}
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
return 0;
}
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN),
main_pe, _set_print_en, set print value);
/*
* EOF
*/

View File

@ -46,14 +46,14 @@ void app_main(void)
esp_chip_info_t chip_info;
uint32_t flash_size;
esp_chip_info(&chip_info);
printf("This is %s chip with %d CPU core(s), %s%s%s%s, ", CONFIG_IDF_TARGET,
chip_info.cores,
(chip_info.features & CHIP_FEATURE_WIFI_BGN) ? "WiFi/" : "",
(chip_info.features & CHIP_FEATURE_BT) ? "BT" : "",
(chip_info.features & CHIP_FEATURE_BLE) ? "BLE" : "",
(chip_info.features & CHIP_FEATURE_IEEE802154)
? ", 802.15.4 (Zigbee/Thread)"
: "");
// printf("This is %s chip with %d CPU core(s), %s%s%s%s, ", CONFIG_IDF_TARGET,
// chip_info.cores,
// (chip_info.features & CHIP_FEATURE_WIFI_BGN) ? "WiFi/" : "",
// (chip_info.features & CHIP_FEATURE_BT) ? "BT" : "",
// (chip_info.features & CHIP_FEATURE_BLE) ? "BLE" : "",
// (chip_info.features & CHIP_FEATURE_IEEE802154)
// ? ", 802.15.4 (Zigbee/Thread)"
// : "");
unsigned major_rev = chip_info.revision / 100;
unsigned minor_rev = chip_info.revision % 100;
@ -75,7 +75,11 @@ void app_main(void)
// vTaskDelay(1000 / portTICK_PERIOD_MS);
// }
cdc_printf("start run app:\r\n");
imp_main_app_task();
xTaskCreate(imp_main_app_task, "main", 2048, NULL, 10, NULL);
while(1) {
// cdc_printf("start run app:\r\n");
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
printf("Restarting now.\n");
fflush(stdout);

View File

@ -177,7 +177,7 @@
* @brief shell默认用户密码
* ""
*/
#define SHELL_DEFAULT_USER_PASSWORD "passwd"
#define SHELL_DEFAULT_USER_PASSWORD ""
/**
* @brief shell自动锁定超时

View File

@ -51,6 +51,7 @@ 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);
vTaskDelay(10);
signed char ret = 0;
ret = cdc_usb_read_bytes(data, len);
// cdc_printf("read need : %d, get %d\r\n", len, ret);
@ -64,18 +65,18 @@ signed char userShellRead(char *data, unsigned short len)
*/
void userShellInit(void)
{
uart_config_t uartConfig = {
.baud_rate = 115200,
.data_bits = UART_DATA_8_BITS,
.parity = UART_PARITY_DISABLE,
.stop_bits = UART_STOP_BITS_1,
.flow_ctrl = UART_HW_FLOWCTRL_DISABLE
};
uart_param_config(SHELL_UART, &uartConfig);
uart_driver_install(SHELL_UART, 256 * 2, 0, 0, NULL, 0);
// uart_config_t uartConfig = {
// .baud_rate = 115200,
// .data_bits = UART_DATA_8_BITS,
// .parity = UART_PARITY_DISABLE,
// .stop_bits = UART_STOP_BITS_1,
// .flow_ctrl = UART_HW_FLOWCTRL_DISABLE
// };
// uart_param_config(SHELL_UART, &uartConfig);
// uart_driver_install(SHELL_UART, 256 * 2, 0, 0, NULL, 0);
shell.write = userShellWrite;
shell.read = userShellRead;
shellInit(&shell, shellBuffer, 512);
xTaskCreate(shellTask, "shell", 2048, &shell, 10, NULL);
xTaskCreate(shellTask, "shell", 2048, &shell, 8, NULL);
}

View File

@ -135,7 +135,7 @@ void usbd_cdc_acm_out(uint8_t ep)
void usbd_cdc_acm_in(uint8_t ep)
{
USB_LOG_RAW("in\r\n");
// USB_LOG_RAW("in\r\n");
}
/*!< endpoint call back */

File diff suppressed because it is too large Load Diff