gpt4 book ai didi

c - 用FT245同步方式写入芯片

转载 作者:太空宇宙 更新时间:2023-11-04 04:33:55 24 4
gpt4 key购买 nike

我正在使用连接到 FPGA 的 FT232H 设备,我正在尝试向其写入一些字节。读(转FPGA->PC)完美,写(转PC->FPGA)根本不行。我正在使用以下代码:

libusb_open(board, &board_handle);
if (libusb_kernel_driver_active(board_handle, 0) == 1) {
if(libusb_detach_kernel_driver(board_handle, 0) == 0);
}
libusb_set_configuration(board_handle, 1);
libusb_claim_interface(board_handle, 0);
libusb_control_transfer(board_handle, 0x40, 0x0B, 0x00FF, 0x01, NULL, 0, 5000);
libusb_control_transfer(board_handle, 0x40, 0x0B, 0x40FF, 0x01, NULL, 0, 5000);
libusb_bulk_transfer(board, 0x02, bufout, 3, &transfered, 5000);
bufin = calloc(512, 1);
libusb_bulk_transfer(board, 0x81, bufin, 512, &transfered, 5000);

Bufout 填充了数据。当我尝试将 FPGA 上生成的一些数据发送到 PC 时没有问题; bufin 填充了正确的数据。

但是当我尝试将一些数据发送到 FPGA,并将其显示在 LED 上或发回时,问题就出现了。

无论 bufout 内容如何,​​我在 FPGA 站点收到的每个字节都是 0xFF。 Bufoutbufin 都声明为 unsigned char *。

unsigned char *bufin, *bufout;

令人惊讶的是(或者不是)FPGA 接收到的字节数与 PC 发送的字节数匹配,但所有字节的值为 0xFF。

我做错了什么吗?

我试过使用 libftdi,但效果是一样的(我认为 libftdi 使用 libusb 作为引擎并不奇怪)。

也许我忘了在主机端调用一些重要的功能?

FPGA端的代码也很简单:

process(ftdi_clk, sys_rst)
begin
if sys_rst = '0'then
ftdi_wr <= '1';
ftdi_data <= "ZZZZZZZZ";
ftdi_rd <= '1';
ftdi_oe <= '1';
read <= '1';
elsif rising_edge(ftdi_clk) then
if ftdi_txe = '0' then
ftdi_wr <= '0';
ftdi_data <= buf;
else
ftdi_wr <= '1';
ftdi_data <= "ZZZZZZZZ";
end if;
if (read = '0') and (ftdi_rxf = '0') then
ftdi_rd <= '0';
buf <= ftdi_data;
else
ftdi_rd <= '1';
end if;
if ftdi_rxf = '0' then
ftdi_oe <= '0';
read <= '0';
else
ftdi_oe <= '1';
read <= '1';
end if;
end if;
end process;

编辑:我已经检查了所有可能的电气配置、上拉、I/O 电压,一切似乎都很好。从 FTDI 传输到 FPGA 的所有数据仍然是 2 个独立芯片上的数据,因此很可能是软件问题。我已经检查了模拟,甚至是适配后模拟,通信应该根据文档进行。

EDIT2:我尝试过使用原始供应商库。

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ftd2xx.h>

int main(){
FT_STATUS ftStatus;
FT_HANDLE ftHandle;
DWORD BytesWritten;
unsigned char data[512];
int i;
FT_PROGRAM_DATA ftData = {
0x00000000, 0xFFFFFFFF, // Headers
0x00000005, // Version (5 = 232H)
0x0403, 0x6014, // VID:PID
"StackOverflow", "Stack", "StackBoard", NULL,
500, 0, 1, 1, // MaxPower, PnP, SelfPowered, Remote WakeUp
// FT232B
0, 0, 0, 0, 0, 0, 0,
// FT2232
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
// FT232R
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
// FT2232H
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0,
// FT4232H
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0,
// FT232H
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0,
0, 0, 0, 0, 0, 0, 0,
};
ftStatus = FT_Open(0, &ftHandle);
ftStatus = FT_SetTimeouts(ftHandle, 5000, 5000);
ftStatus = FT_EE_Program(ftHandle, &ftData);
ftStatus = FT_EE_Program(ftHandle, &ftData);
ftStatus = FT_SetBitMode(ftHandle, 0xFF, FT_BITMODE_SYNC_FIFO);
for(i = 0; i<512; i++) data[i] = 0x02;
ftStatus = FT_Write(ftHandle, data, 512, &BytesWritten);
printf("%d bytes written\n", BytesWritten);
ftStatus = FT_Read(ftHandle, &data, 512, &BytesWritten);
printf("%d bytes read\n", BytesWritten);
for(i = 0; i<BytesWritten; i++) printf("%#2x ", data[i]);
FT_Close(ftHandle);
}

仍然是完全相同的行为。我已将 Linux 内核更新到最新版本 (4.2.3),但结果是一样的。遗憾的是,我检查了几台不同的机器和 3 种不同的芯片。

最佳答案

不确定这是否是您唯一的问题,但我认为您在 ftdi_data 上发生了一些短路。它可以在 ftdi_oe 处于事件状态的同时由 FPGA 驱动。

关于c - 用FT245同步方式写入芯片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33169125/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com