X
首页
技术
模拟电子
单片机
半导体
电源管理
嵌入式
传感器
最能打国产芯
应用
汽车电子
工业控制
家用电子
手机便携
安防电子
医疗电子
网络通信
测试测量
物联网
最能打国产芯
大学堂
首页
直播
专题
TI 培训
论坛
汽车电子
国产芯片
电机驱动控制
电源技术
单片机
模拟电子
PCB设计
电子竞赛
DIY/开源
嵌入式系统
医疗电子
颁奖专区
【厂商专区】
【电子技术】
【创意与实践】
【行业应用】
【休息一下】
最能打国产芯
活动中心
直播
发现活动
颁奖区
电子头条
参考设计
下载中心
分类资源
文集
排行榜
电路图
Datasheet
最能打国产芯
stm32/stm8
[讨论] STM32F --- 用USB
dontium
2017-3-31 12:08
楼主
上位机用VC++编程,STM32F用USB与其对接,如果上位机应用程序想读STM32F的内部寄存器或存储器, ------ 不用虚拟串口,
这样的程序怎么做呢?(包括VC++及STM32F)
-----用STM32CubeMX时不知道选择哪个:
上位机用VC++时,更是没有方向
点赞
回复评论 (1)
沙发
le062
我用libusb就很好做(不过我的代码和官方例程无关),完整的测试代码,你参考下
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <time.h>
#include "libusb.h"
#define VL1602ED_VID 0xB58A
#define VL1602ED_PID 0xC200
#define VLLOGIC_REQUESET_REG_RW 0x00
struct ctrl_regs_t
{
// read only area
uint32_t version;
uint32_t board_in_channels_mask;
uint32_t board_out_channels_mask;
uint32_t status_mask;
// read write area
uint32_t command;
#define VLLOGIC_CMD_NOP 0
#define VLLOGIC_CMD_START 0x10000000
#define VLLOGIC_CMD_STOP 0x10000001
uint32_t mode;
#define VLLOGIC_MODE_NOP 0
#define VLLOGIC_MODE_IN (0x1 << 0)
#define VLLOGIC_MODE_OUT (0x1 << 1)
// channel parameter
uint32_t sum_l32;
uint32_t sum_h32;
uint32_t rate;
/*
bit function
[0, 15] digital channels enable mask
[16, 17] analog channels enable mask
*/
uint32_t channels_in_enable_mask;
/*
bit function
[0, 15] low level trigger enable mask
[16, 32] high level trigger enable mask
*/
uint32_t digital_channels_level_trigger_mask;
/*
bit function
[0, 15] falling edge trigger enable mask
[16, 32] rising edge trigger enable mask
*/
uint32_t digital_channels_edge_trigger_mask;
/*
bit function
[0, 15] digital channels enable mask
[16, 17] analog channels enable mask
*/
uint32_t channels_out_enable_mask;
};
uint8_t buf_20k[20 * 1024 * 1024];
static int vl1602ed_vllogic_test(libusb_device_handle *handle)
{
int r;
struct ctrl_regs_t regs;
// control test
r = libusb_control_transfer(handle, LIBUSB_ENDPOINT_IN | LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_INTERFACE,
VLLOGIC_REQUESET_REG_RW, 0, 0, (uint8_t *)®s, sizeof(struct ctrl_regs_t), 100);
if (r != sizeof(struct ctrl_regs_t))
{
printf("Get Regs Fail\n");
return;
}
regs.rate = 240000000;
libusb_control_transfer(handle, LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_INTERFACE,
VLLOGIC_REQUESET_REG_RW, 0, 0, (uint8_t *)®s, sizeof(struct ctrl_regs_t), 100);
memset(®s, 0, sizeof(struct ctrl_regs_t));
r = libusb_control_transfer(handle, LIBUSB_ENDPOINT_IN | LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_INTERFACE,
VLLOGIC_REQUESET_REG_RW, 0, 0, (uint8_t *)®s, sizeof(struct ctrl_regs_t), 100);
if (r != sizeof(struct ctrl_regs_t))
{
printf("Get Regs Fail\n");
return;
}
//while (1)
{
int transfer_len = 0, sum = 0;
clock_t start, end;
start = clock();
printf("\n20k Block Test \n");
printf("Start Clock %d\n", start);
while (sum < 100 * 1024 * 1024)
{
r = libusb_bulk_transfer(handle, 0x80 | 0x1, buf_20k, 20 * 1024, &transfer_len, 1000);
if (r == LIBUSB_ERROR_PIPE) {
libusb_clear_halt(handle, 1);
printf("Get 20k buffer Fail\n");
break;
}
else if (transfer_len == 20 * 1024)
{
sum += transfer_len;
}
else
{
printf("Get buffer %d\n", transfer_len);
break;
}
}
end = clock();
printf("End Clock %d\n", end);
float speed = 100000.0 / (end - start);
printf("Speed %f MB/S\n", speed);
}
{
int transfer_len = 0, sum = 0;
clock_t start, end;
start = clock();
printf("\n1MB Block Test \n");
printf("Start Clock %d\n", start);
while (sum < 100 * 1024 * 1024)
{
r = libusb_bulk_transfer(handle, 0x80 | 0x1, buf_20k, 1024 * 1024, &transfer_len, 1000);
if (r == LIBUSB_ERROR_PIPE) {
libusb_clear_halt(handle, 1);
printf("Get 20k buffer Fail\n");
break;
}
else if (transfer_len == 1024 * 1024)
{
sum += transfer_len;
}
else
{
printf("Get buffer %d\n", transfer_len);
break;
}
}
end = clock();
printf("End Clock %d\n", end);
float speed = 100000.0 / (end - start);
printf("Speed %f MB/S\n", speed);
}
{
int transfer_len = 0, sum = 0;
clock_t start, end;
start = clock();
printf("\n10MB Block Test \n");
printf("Start Clock %d\n", start);
while (sum < 100 * 1024 * 1024)
{
r = libusb_bulk_transfer(handle, 0x80 | 0x1, buf_20k, 10 * 1024 * 1024, &transfer_len, 1000);
if (r == LIBUSB_ERROR_PIPE) {
libusb_clear_halt(handle, 1);
printf("Get 20k buffer Fail\n");
break;
}
else if (transfer_len == 10 * 1024 * 1024)
{
sum += transfer_len;
}
else
{
printf("Get buffer %d\n", transfer_len);
break;
}
}
end = clock();
printf("End Clock %d\n", end);
float speed = 100000.0 / (end - start);
printf("Speed %f MB/S\n", speed);
}
{
int transfer_len = 0, sum = 0;
clock_t start, end;
start = clock();
printf("\n20MB Block Test \n");
printf("Start Clock %d\n", start);
while (sum < 100 * 1024 * 1024)
{
r = libusb_bulk_transfer(handle, 0x80 | 0x1, buf_20k, 20 * 1024 * 1024, &transfer_len, 1000);
if (r == LIBUSB_ERROR_PIPE) {
libusb_clear_halt(handle, 1);
printf("Get 20k buffer Fail\n");
break;
}
else if (transfer_len == 20 * 1024 * 1024)
{
sum += transfer_len;
}
else
{
printf("Get buffer %d\n", transfer_len);
break;
}
}
end = clock();
printf("End Clock %d\n", end);
float speed = 100000.0 / (end - start);
printf("Speed %f MB/S\n", speed);
}
}
static int vl1602ed_test(void)
{
int r;
libusb_device_handle *handle;
libusb_device *dev;
printf("Opening device %04X:%04X...\n", VL1602ED_VID, VL1602ED_PID);
handle = libusb_open_device_with_vid_pid(NULL, VL1602ED_VID, VL1602ED_PID);
if (handle == NULL)
{
printf(" Open Failed.\n");
return -1;
}
else
printf(" Find Device.\n");
dev = libusb_get_device(handle);
libusb_set_auto_detach_kernel_driver(handle, 1);
printf("Claim Interface 0\n");
r = libusb_claim_interface(handle, 0);
if (r != LIBUSB_SUCCESS)
{
printf(" Failed.\n");
}
else
{
r = libusb_claim_interface(handle, 1);
if (r == LIBUSB_SUCCESS)
{
printf(" Success.\n");
vl1602ed_vllogic_test(handle);
}
}
//printf("Claim Interface 1\n");
//r = libusb_claim_interface(handle, 0);
//if (r != LIBUSB_SUCCESS)
//{
// printf(" Failed.\n");
//}
printf("Closing device...\n");
libusb_close(handle);
}
int main(int argc, char** argv)
{
int j, r;
const struct libusb_version* version;
version = libusb_get_version();
printf("Using libusb v%d.%d.%d.%d\n\n", version->major, version->minor, version->micro, version->nano);
r = libusb_init(NULL);
if (r < 0)
return r;
vl1602ed_test();
libusb_exit(NULL);
return 0;
}
要666
点赞
2017-3-31 15:58
最新活动
报名直播赢【双肩包、京东卡、水杯】| 高可靠性IGBT的新选择——安世半导体650V IGBT
30套RV1106 Linux开发板(带摄像头),邀您动手挑战边缘AI~
安世半导体理想二极管与负载开关,保障物联网应用的稳健高效运行
免费申请 | 上百份MPS MIE模块,免费试用还有礼!
PI 电源小课堂|无 DC-DC 变换实现多路高精度输出反激电源
2024 瑞萨电子MCU/MPU工业技术研讨会——深圳、上海站, 火热报名中
随便看看
关于运放电路饱和问题
uboot调试过程中的环境变量 问题
为什么ARM的TCK脚烧几次程序就报废??
adafruit的micropython液晶驱动
我的lm3s811探访之路(初)
求助各位大神
嵌入式相关的实体书
beaglebone编译u-boot
南京万利,请保证我们ST-LINK-II用户的权益
跟夏老师学FPGA(8)verilog中reg和wire的不同点
一帧数据怎么按字节从低位到高位发送?
10个计算机算法,可以了解主导物联
P0赋值问题
EEWORLD大学堂----【中英字幕】什么是引力波
晒晒我们的电子古董吧!
EEPROM
2.4的内核上移植yaffs2文件系统
usb转ttl的串口接板子导致不开机
IGBT驱动板电源的脉冲变压器
wince GPRS自动拨号问题(C#)
电子工程世界版权所有
京B2-20211791
京ICP备10001474号-1
京公网安备 11010802033920号
回复
写回复
收藏
回复