Commit b18895f5 authored by Wenxi XU's avatar Wenxi XU
Browse files

添加一个新通讯的简单实例

parent 2365a97a
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
cmake_minimum_required(VERSION 3.20.0)

find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(usb_bulk_test)

target_sources(app PRIVATE src/main.c)
+6 −0
Original line number Diff line number Diff line
/ {

};
&cdc_acm_uart0 {
	status = "disabled";
};
 No newline at end of file
+45 −0
Original line number Diff line number Diff line
# 启用 Zephyr USB 设备栈
CONFIG_USB_DEVICE_STACK=n

# 匹配自定义类驱动中的日志模块名

CONFIG_DUAL_PROPOSE_PROTOCOL=y
CONFIG_USB_BULK_INTERFACE=y

CONFIG_MAIN_STACK_SIZE=8192
CONFIG_LOG_PROCESS_THREAD_STACK_SIZE=8192
CONFIG_UDC_WORKQUEUE_STACK_SIZE=8192
CONFIG_UDC_STM32_STACK_SIZE=8192

CONFIG_USBD_THREAD_STACK_SIZE=2048

CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=8192

CONFIG_UDC_DRIVER_LOG_LEVEL_INF=y
CONFIG_ARES_USB_THREAD_STACK_SIZE=4096
CONFIG_USBD_LOG_LEVEL_DBG=y

# CONFIG_LOG_BLOCK_IN_THREAD=n
# CONFIG_LOG_SPEED=y
# CONFIG_LOG_MODE_OVERFLOW=y
# CONFIG_LOG_PROCESS_THREAD=y
# CONFIG_LOG_MODE_DEFERRED=y
# CONFIG_LOG_FRONTEND=y
# CONFIG_LOG_BUFFER_SIZE=16384
# CONFIG_LOG_BACKEND_UART=y
# CONFIG_LOG_BACKEND_UART_ASYNC=y
# CONFIG_UART_ASYNC_API=y

CONFIG_HW_STACK_PROTECTION=y
CONFIG_ARM_MPU=y
CONFIG_CONSOLE=y
CONFIG_UART_CONSOLE=y

CONFIG_USBD_MAX_UDC_MSG=24
CONFIG_USBD_MSG_SLAB_COUNT=24
CONFIG_UDC_BUF_COUNT=128
CONFIG_UDC_WORKQUEUE=y
CONFIG_UDC_WORKQUEUE_PRIORITY=0
CONFIG_UDC_BUF_POOL_SIZE=4096

CONFIG_MAIN_THREAD_PRIORITY=10
 No newline at end of file
+58 −0
Original line number Diff line number Diff line
// main.c
#include <zephyr/kernel.h>
#include <zephyr/logging/log.h>
#include <zephyr/net_buf.h>
#include <ares/interface/usb/usb_bulk.h>
#include <ares/protocol/dual/dual_protocol.h>
#include <ares/ares_comm.h>

#include <zephyr/debug/thread_analyzer.h>

LOG_MODULE_REGISTER(main_app, LOG_LEVEL_INF);

DUAL_PROPOSE_PROTOCOL_DEFINE(dual_protocol);
ARES_BULK_INTERFACE_DEFINE(usb_bulk_interface);

int cnt = 0;
void func_cb(uint32_t param1, uint32_t param2, uint32_t param3)
{
	cnt++;
	// LOG_INF("func_cb");
	// LOG_INF("params: %2x,%2x,%2x", param1, param2, param3);
}

uint8_t test[59] = {0};
int main(void)
{
	// Initialize the USB stack and our async pipeline.
	// Pass the function that will handle the data.
	// int err = ares_usbd_init(&usb_bulk_interface);
	int err = ares_bind_interface(&usb_bulk_interface, &dual_protocol);
	dual_func_add(&dual_protocol, 0x1, func_cb);
	sync_table_t *pack = dual_sync_add(&dual_protocol, 0x1, test, sizeof(test), func_cb);
	if (err) {
		LOG_ERR("Failed to initialize ARES USB device (%d)", err);
		return 0;
	}

	LOG_INF("ARES Async USB Bulk device is ready.");

	// The main thread is now free to do other things.
	// All USB data processing happens in the background.
	uint32_t prev_cnt = 0;
	uint32_t prev_time = k_uptime_get_32();
	while (1) {
		k_sleep(K_SECONDS(1));
		// dual_sync_flush(&dual_protocol, pack);
		if (prev_time + 1000 < k_uptime_get_32()) {
			// 	// thread_analyzer_print(NULL);
			LOG_INF("cnt: %d, delta: %d", cnt, cnt - prev_cnt);
			prev_time = k_uptime_get_32();
		}
		prev_cnt = cnt;

		// You can also call ares_usbd_write() from here to send data proactively.
	}

	return 0;
}
 No newline at end of file