关于.net 未能加载文件或程序集 的另一种解决方法 错误信息:genasm.exe(1) : error There was an error initializing

关于.net 未能加载文件或程序集 的另一种解决方法 错误信息:genasm.exe(1) : error There was an error initializing.  未能加载文件或程序集“System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=969db8053d3322ac, Retargetable=Yes”或它的某一个依赖项。系统找不到指定的文件。

 

 

去C:\WINDOWS\assembly下查看是否存在和错误提示中 名字、 版本、 公钥标记都相同的程序集
如果没有 去项目->属性->引用里查看引用的dll的位置 然后拖拽到assembly文件夹里 程序集会自动注册
再回来编译项目, 是不是通过了?
/* ## Cypress USB 3.0 Platform source file (cyfxslfifosync.c) ## =========================== ## ## Copyright Cypress Semiconductor Corporation, 2010-2018, ## All Rights Reserved ## UNPUBLISHED, LICENSED SOFTWARE. ## ## CONFIDENTIAL AND PROPRIETARY INFORMATION ## WHICH IS THE PROPERTY OF CYPRESS. ## ## Use of this file is governed ## by the license agreement included in the file ## ## <install>/license/license.txt ## ## where <install> is the Cypress software ## installation root directory path. ## ## =========================== */ /* This file illustrates the Slave FIFO Synchronous mode example */ /* This example comprises of two USB bulk endpoints. A bulk OUT endpoint acts as the producer of data from the host. A bulk IN endpoint acts as the consumer of data to the host. Appropriate vendor class USB enumeration descriptors with these two bulk endpoints are implemented. The GPIF configuration data for the Synchronous Slave FIFO operation is loaded onto the appropriate GPIF registers. The p-port data transfers are done via the producer p-port socket and the consumer p-port socket. This example implements two DMA Channels in MANUAL mode one for P to U data transfer and one for U to P data transfer. The U to P DMA channel connects the USB producer (OUT) endpoint to the consumer p-port socket. And the P to U DMA channel connects the producer p-port socket to the USB consumer (IN) endpoint. Upon every reception of data in the DMA buffer from the host or from the p-port, the CPU is signalled using DMA callbacks. There are two DMA callback functions implemented each for U to P and P to U data paths. The CPU then commits the DMA buffer received so that the data is transferred to the consumer. The DMA buffer size for each channel is defined based on the USB speed. 64 for full speed, 512 for high speed and 1024 for super speed. CY_FX_SLFIFO_DMA_BUF_COUNT in the header file defines the number of DMA buffers per channel. The constant CY_FX_SLFIFO_GPIF_16_32BIT_CONF_SELECT in the header file is used to select 16bit or 32bit GPIF data bus configuration. */ #include "cyu3system.h" #include "cyu3os.h" #include "cyu3dma.h" #include "cyu3error.h" #include "cyu3usb.h" #include "cyu3uart.h" #include "cyfxslfifosync.h" #include "cyu3gpif.h" #include "cyu3pib.h" #include "cyu3utils.h" #include "pib_regs.h" #include <cyu3gpio.h> #include "cyu3spi.h" /* This file should be included only once as it contains * structure definitions. Including it in multiple places * can result in linker error. */ #include "sync_slave_fifo_2bit_tekwin.cydsn/cyfxgpif2config.h" //#include "cyfxgpif2config_RAW.h"//Bulk In/Out OK CyU3PThread slFifoAppThread; /* Slave FIFO application thread structure */ CyU3PDmaChannel glChHandleSlFifoUtoP; /* DMA Channel handle for U2P transfer. */ CyU3PDmaChannel glChHandleSlFifoPtoU; /* DMA Channel handle for P2U transfer. */ uint32_t glDMARxCount = 0; /* Counter to track the number of buffers received from USB. */ uint32_t glDMATxCount = 0; /* Counter to track the number of buffers sent to USB. */ CyBool_t glIsApplnActive = CyFalse; /* Whether the loopback application is active or not. */ uint8_t burstLength = 0; uint8_t glEp0Buffer[4096] __attribute__ ((aligned (32))); uint16_t glSpiPageSize = 0x100; /* SPI Page size to be used for transfers. */ CyU3PDmaChannel glI2cTxHandle; /* I2C Tx channel handle */ CyU3PDmaChannel glI2cRxHandle; /* I2C Rx channel handle */ CyU3PDmaChannel glSpiTxHandle; /* SPI Tx channel handle */ CyU3PDmaChannel glSpiRxHandle; /* SPI Rx channel handle */ volatile CyBool_t g_eraseInProgress = CyFalse; // 擦除进行中标志 volatile uint32_t g_eraseSector = 0; // 当前擦除的扇区号 CyU3PThread g_eraseThread = {0}; // 独立擦除监控线程 /* 如果别的地方要调用软复位,也可以放这里 */ static void TanhoCam_SoftResetP2U(void); /* Application Error Handler */ void CyFxAppErrorHandler ( CyU3PReturnStatus_t apiRetStatus /* API return status */ ) { /* Application failed with the error code apiRetStatus */ /* Add custom debug or recovery actions here */ /* Loop Indefinitely */ for (;;) { /* Thread sleep : 100 ms */ CyU3PThreadSleep (100); } } /* This function initializes the debug module. The debug prints * are routed to the UART and can be seen using a UART console * running at 115200 baud rate. */ void CyFxSlFifoApplnDebugInit (void) { CyU3PUartConfig_t uartConfig; CyU3PReturnStatus_t apiRetStatus = CY_U3P_SUCCESS; /* Initialize the UART for printing debug messages */ apiRetStatus = CyU3PUartInit(); if (apiRetStatus != CY_U3P_SUCCESS) { /* Error handling */ CyFxAppErrorHandler(apiRetStatus); } /* Set UART configuration */ CyU3PMemSet ((uint8_t *)&uartConfig, 0, sizeof (uartConfig)); uartConfig.baudRate = CY_U3P_UART_BAUDRATE_115200; uartConfig.stopBit = CY_U3P_UART_ONE_STOP_BIT; uartConfig.parity = CY_U3P_UART_NO_PARITY; uartConfig.txEnable = CyTrue; uartConfig.rxEnable = CyFalse; uartConfig.flowCtrl = CyFalse; uartConfig.isDma = CyTrue; apiRetStatus = CyU3PUartSetConfig (&uartConfig, NULL); if (apiRetStatus != CY_U3P_SUCCESS) { CyFxAppErrorHandler(apiRetStatus); } /* Set the UART transfer to a really large value. */ apiRetStatus = CyU3PUartTxSetBlockXfer (0xFFFFFFFF); if (apiRetStatus != CY_U3P_SUCCESS) { CyFxAppErrorHandler(apiRetStatus); } /* Initialize the debug module. */ apiRetStatus = CyU3PDebugInit (CY_U3P_LPP_SOCKET_UART_CONS, 8); if (apiRetStatus != CY_U3P_SUCCESS) { CyFxAppErrorHandler(apiRetStatus); } } /* DMA callback function to handle the produce events for U to P transfers. */ void CyFxSlFifoUtoPDmaCallback ( CyU3PDmaChannel *chHandle, CyU3PDmaCbType_t type, CyU3PDmaCBInput_t *input ) { CyU3PReturnStatus_t status = CY_U3P_SUCCESS; if (type == CY_U3P_DMA_CB_PROD_EVENT) { /* This is a produce event notification to the CPU. This notification is * received upon reception of every buffer. The buffer will not be sent * out unless it is explicitly committed. The call shall fail if there * is a bus reset / usb disconnect or if there is any application error. */ status = CyU3PDmaChannelCommitBuffer (chHandle, input->buffer_p.count, 0); if (status != CY_U3P_SUCCESS) { CyU3PDebugPrint (4, "CyU3PDmaChannelCommitBuffer failed, Error code = %d\n", status); } /* Increment the counter. */ glDMARxCount++; } } /* DMA callback function to handle the produce events for P to U transfers. */ void CyFxSlFifoPtoUDmaCallback ( CyU3PDmaChannel *chHandle, CyU3PDmaCbType_t type, CyU3PDmaCBInput_t *input ) { int retry=0; CyU3PReturnStatus_t status = CY_U3P_SUCCESS; if (type == CY_U3P_DMA_CB_PROD_EVENT) { /* This is a produce event notification to the CPU. This notification is * received upon reception of every buffer. The buffer will not be sent * out unless it is explicitly committed. The call shall fail if there * is a bus reset / usb disconnect or if there is any application error. */ do{ if (input->buffer_p.count == 0) { CyU3PDebugPrint(4, "Drop ZLP, len=0\n"); return; // 直接退出回调 } uint32_t sendLen = input->buffer_p.count; if (sendLen >= 16384 + 16) // 确保是完整帧 sendLen = 16384; status = CyU3PDmaChannelCommitBuffer (chHandle, sendLen, 0); if (status != CY_U3P_SUCCESS) { CyU3PDebugPrint(4, "P2U commit fail %d, reset EP\n", status); TanhoCam_SoftResetP2U(); retry++; } } while (status != CY_U3P_SUCCESS && retry < 3); if (status != CY_U3P_SUCCESS) { CyU3PDebugPrint (4, "CyU3PDmaChannelCommitBuffer failed, Error code = %d\n", status); } /* Increment the counter. */ if (status == CY_U3P_SUCCESS) glDMATxCount++; } } static void TanhoCam_SoftResetP2U(void) { CyU3PUsbSetEpNak(CY_FX_EP_CONSUMER, CyTrue); CyU3PBusyWait(125); CyU3PDmaChannelReset(&glChHandleSlFifoPtoU); CyU3PUsbFlushEp(CY_FX_EP_CONSUMER); CyU3PUsbResetEp(CY_FX_EP_CONSUMER); CyU3PDmaChannelSetXfer(&glChHandleSlFifoPtoU, CY_FX_SLFIFO_DMA_RX_SIZE); CyU3PUsbSetEpNak(CY_FX_EP_CONSUMER, CyFalse); } /* This function starts the slave FIFO loop application. This is called * when a SET_CONF event is received from the USB host. The endpoints * are configured and the DMA pipe is setup in this function. */ void CyFxSlFifoApplnStart ( void) { uint16_t size = 0; CyU3PEpConfig_t epCfg; CyU3PDmaChannelConfig_t dmaCfg; CyU3PReturnStatus_t apiRetStatus = CY_U3P_SUCCESS; CyU3PUSBSpeed_t usbSpeed = CyU3PUsbGetSpeed(); /* First identify the usb speed. Once that is identified, * create a DMA channel and start the transfer on this. */ /* Based on the Bus Speed configure the endpoint packet size */ switch (usbSpeed) { case CY_U3P_FULL_SPEED: size = 64; break; case CY_U3P_HIGH_SPEED: size = 512; burstLength=1; break; case CY_U3P_SUPER_SPEED: size = 1024; burstLength=4; break; default: CyU3PDebugPrint (4, "Error! Invalid USB speed.\n"); CyFxAppErrorHandler (CY_U3P_ERROR_FAILURE); break; } CyU3PMemSet ((uint8_t *)&epCfg, 0, sizeof (epCfg)); epCfg.enable = CyTrue; epCfg.epType = CY_U3P_USB_EP_BULK; epCfg.burstLen = burstLength; epCfg.streams = 0; epCfg.pcktSize = size; /* Producer endpoint configuration */ apiRetStatus = CyU3PSetEpConfig(CY_FX_EP_PRODUCER, &epCfg); if (apiRetStatus != CY_U3P_SUCCESS) { CyU3PDebugPrint (4, "CyU3PSetEpConfig failed, Error code = %d\n", apiRetStatus); CyFxAppErrorHandler (apiRetStatus); } /* Consumer endpoint configuration */ apiRetStatus = CyU3PSetEpConfig(CY_FX_EP_CONSUMER, &epCfg); if (apiRetStatus != CY_U3P_SUCCESS) { CyU3PDebugPrint (4, "CyU3PSetEpConfig failed, Error code = %d\n", apiRetStatus); CyFxAppErrorHandler (apiRetStatus); } /* Create a DMA MANUAL channel for U2P transfer. * DMA size is set based on the USB speed. */ dmaCfg.size = DMA_BUF_SIZE*size+16; //dmaCfg.count = CY_FX_SLFIFO_DMA_BUF_COUNT; dmaCfg.count = CY_FX_SLFIFO_DMA_BUF_COUNT_U_2_P; // increase buffer count for higher performance dmaCfg.prodSckId = CY_FX_PRODUCER_USB_SOCKET; dmaCfg.consSckId = CY_FX_CONSUMER_PPORT_SOCKET; dmaCfg.dmaMode = CY_U3P_DMA_MODE_BYTE; /* Enabling the callback for produce event. */ dmaCfg.notification = CY_U3P_DMA_CB_PROD_EVENT; dmaCfg.cb = CyFxSlFifoUtoPDmaCallback; dmaCfg.prodHeader = 0; dmaCfg.prodFooter = 0; dmaCfg.consHeader = 0; dmaCfg.prodAvailCount = 0; apiRetStatus = CyU3PDmaChannelCreate (&glChHandleSlFifoUtoP, CY_U3P_DMA_TYPE_MANUAL, &dmaCfg); if (apiRetStatus != CY_U3P_SUCCESS) { CyU3PDebugPrint (4, "CyU3PDmaChannelCreate failed, Error code = %d\n", apiRetStatus); CyFxAppErrorHandler(apiRetStatus); } /* Create a DMA MANUAL channel for P2U transfer. */ dmaCfg.size = DMA_BUF_SIZE*size+16; dmaCfg.count = CY_FX_SLFIFO_DMA_BUF_COUNT_P_2_U; dmaCfg.prodSckId = CY_FX_PRODUCER_PPORT_SOCKET; dmaCfg.consSckId = CY_FX_CONSUMER_USB_SOCKET; dmaCfg.cb = CyFxSlFifoPtoUDmaCallback; apiRetStatus = CyU3PDmaChannelCreate (&glChHandleSlFifoPtoU, CY_U3P_DMA_TYPE_MANUAL, &dmaCfg); if (apiRetStatus != CY_U3P_SUCCESS) { CyU3PDebugPrint (4, "CyU3PDmaChannelCreate failed, Error code = %d\n", apiRetStatus); CyFxAppErrorHandler(apiRetStatus); } /* Flush the Endpoint memory */ CyU3PUsbFlushEp(CY_FX_EP_PRODUCER); CyU3PUsbFlushEp(CY_FX_EP_CONSUMER); /* Set DMA channel transfer size. */ apiRetStatus = CyU3PDmaChannelSetXfer (&glChHandleSlFifoUtoP, CY_FX_SLFIFO_DMA_TX_SIZE); if (apiRetStatus != CY_U3P_SUCCESS) { CyU3PDebugPrint (4, "CyU3PDmaChannelSetXfer Failed, Error code = %d\n", apiRetStatus); CyFxAppErrorHandler(apiRetStatus); } apiRetStatus = CyU3PDmaChannelSetXfer (&glChHandleSlFifoPtoU, CY_FX_SLFIFO_DMA_RX_SIZE); if (apiRetStatus != CY_U3P_SUCCESS) { CyU3PDebugPrint (4, "CyU3PDmaChannelSetXfer Failed, Error code = %d\n", apiRetStatus); CyFxAppErrorHandler(apiRetStatus); } /* Update the status flag. */ glIsApplnActive = CyTrue; CyU3PGpioSetValue (59, CyFalse); } /* This function stops the slave FIFO loop application. This shall be called * whenever a RESET or DISCONNECT event is received from the USB host. The * endpoints are disabled and the DMA pipe is destroyed by this function. */ void CyFxSlFifoApplnStop ( void) { CyU3PEpConfig_t epCfg; CyU3PReturnStatus_t apiRetStatus = CY_U3P_SUCCESS; /* Update the flag. */ glIsApplnActive = CyFalse; /* Flush the endpoint memory */ CyU3PUsbFlushEp(CY_FX_EP_PRODUCER); CyU3PUsbFlushEp(CY_FX_EP_CONSUMER); /* Destroy the channel */ CyU3PDmaChannelDestroy (&glChHandleSlFifoUtoP); CyU3PDmaChannelDestroy (&glChHandleSlFifoPtoU); /* Disable endpoints. */ CyU3PMemSet ((uint8_t *)&epCfg, 0, sizeof (epCfg)); epCfg.enable = CyFalse; /* Producer endpoint configuration. */ apiRetStatus = CyU3PSetEpConfig(CY_FX_EP_PRODUCER, &epCfg); if (apiRetStatus != CY_U3P_SUCCESS) { CyU3PDebugPrint (4, "CyU3PSetEpConfig failed, Error code = %d\n", apiRetStatus); CyFxAppErrorHandler (apiRetStatus); } /* Consumer endpoint configuration. */ apiRetStatus = CyU3PSetEpConfig(CY_FX_EP_CONSUMER, &epCfg); if (apiRetStatus != CY_U3P_SUCCESS) { CyU3PDebugPrint (4, "CyU3PSetEpConfig failed, Error code = %d\n", apiRetStatus); CyFxAppErrorHandler (apiRetStatus); } } static CyU3PReturnStatus_t CyFxFlashProgEraseSector ( CyBool_t isErase, uint8_t sector, uint8_t *wip) { uint32_t temp = 0; uint8_t location[4], rdBuf[2]; CyU3PReturnStatus_t status = CY_U3P_SUCCESS; location[0] = 0x06; /* Write enable. */ CyU3PSpiSetSsnLine (CyFalse); status = CyU3PSpiTransferWords (location, 1, 0, 0); CyU3PSpiSetSsnLine (CyTrue); location[0] = 0x60; /* Chip Erase. */ CyU3PSpiSetSsnLine (CyFalse); status = CyU3PSpiTransferWords (location, 1, 0, 0); CyU3PSpiSetSsnLine (CyTrue); return status; if ((!isErase) && (wip == NULL)) { return CY_U3P_ERROR_BAD_ARGUMENT; } location[0] = 0x06; /* Write enable. */ CyU3PSpiSetSsnLine (CyFalse); status = CyU3PSpiTransferWords (location, 1, 0, 0); CyU3PSpiSetSsnLine (CyTrue); if (status != CY_U3P_SUCCESS) return status; if (isErase) { location[0] = 0x20; /* Sector erase. */ temp = sector * 0x10000; location[1] = (temp >> 16) & 0xFF; location[2] = (temp >> 8) & 0xFF; location[3] = temp & 0xFF; CyU3PSpiSetSsnLine (CyFalse); status = CyU3PSpiTransferWords (location, 4, 0, 0); CyU3PSpiSetSsnLine (CyTrue); } else { location[0] = 0x05; /* Read status */ CyU3PSpiSetSsnLine (CyFalse); status = CyU3PSpiTransferWords (location, 1, 0, 0); if (status != CY_U3P_SUCCESS) { CyU3PSpiSetSsnLine (CyTrue); return status; } status = CyU3PSpiTransferWords (0, 0, rdBuf, 2); CyU3PSpiSetSsnLine (CyTrue); *wip = rdBuf[0] & 0x1; } return status; } /* Callback to handle the USB setup requests. */ CyBool_t CyFxSlFifoApplnUSBSetupCB ( uint32_t setupdat0, uint32_t setupdat1 ) { /* Fast enumeration is used. Only requests addressed to the interface, class, * vendor and unknown control requests are received by this function. * This application does not support any class or vendor requests. */ uint8_t i2cAddr = 0; uint32_t *addr = NULL; int32_t offset = 0; uint8_t bRequest, bReqType; uint8_t bType, bTarget; uint16_t wValue, wIndex, wLength; CyBool_t isHandled = CyFalse; CyU3PReturnStatus_t status = CY_U3P_SUCCESS; /* Decode the fields from the setup request. */ bReqType = (setupdat0 & CY_U3P_USB_REQUEST_TYPE_MASK); bType = (bReqType & CY_U3P_USB_TYPE_MASK); bTarget = (bReqType & CY_U3P_USB_TARGET_MASK); bRequest = ((setupdat0 & CY_U3P_USB_REQUEST_MASK) >> CY_U3P_USB_REQUEST_POS); wValue = ((setupdat0 & CY_U3P_USB_VALUE_MASK) >> CY_U3P_USB_VALUE_POS); wIndex = ((setupdat1 & CY_U3P_USB_INDEX_MASK) >> CY_U3P_USB_INDEX_POS); wLength = ((setupdat1 & CY_U3P_USB_LENGTH_MASK) >> CY_U3P_USB_LENGTH_POS); CyU3PDebugPrint (4, "CyFxUSBSetupCB\r\n"); if (bType == CY_U3P_USB_STANDARD_RQT) { /* Handle SET_FEATURE(FUNCTION_SUSPEND) and CLEAR_FEATURE(FUNCTION_SUSPEND) * requests here. It should be allowed to pass if the device is in configured * state and failed otherwise. */ if ((bTarget == CY_U3P_USB_TARGET_INTF) && ((bRequest == CY_U3P_USB_SC_SET_FEATURE) || (bRequest == CY_U3P_USB_SC_CLEAR_FEATURE)) && (wValue == 0)) { if (glIsApplnActive) CyU3PUsbAckSetup (); else CyU3PUsbStall (0, CyTrue, CyFalse); isHandled = CyTrue; } } /* Handle supported vendor requests. */ if (bType == CY_U3P_USB_VENDOR_RQT) { isHandled = CyTrue; switch (bRequest) { case CY_FX_RQT_SPI_FLASH_ERASE_POLL: status = CyFxFlashProgEraseSector (CyTrue, 0, glEp0Buffer); CyU3PUsbAckSetup(); break; } /* If there was any error, return not handled so that the library will * stall the request. Alternatively EP0 can be stalled here and return * CyTrue. */ if (status != CY_U3P_SUCCESS) { isHandled = CyFalse; } } return isHandled; } /* This is the callback function to handle the USB events. */ void CyFxSlFifoApplnUSBEventCB ( CyU3PUsbEventType_t evtype, uint16_t evdata ) { switch (evtype) { case CY_U3P_USB_EVENT_SETCONF: /* Disable the low power entry to optimize USB throughput */ CyU3PUsbLPMDisable(); /* Stop the application before re-starting. */ if (glIsApplnActive) { CyFxSlFifoApplnStop (); } /* Start the loop back function. */ CyFxSlFifoApplnStart (); break; case CY_U3P_USB_EVENT_RESET: case CY_U3P_USB_EVENT_DISCONNECT: /* Stop the loop back function. */ if (glIsApplnActive) { CyFxSlFifoApplnStop (); } break; default: break; } } /* Callback function to handle LPM requests from the USB 3.0 host. This function is invoked by the API whenever a state change from U0 -> U1 or U0 -> U2 happens. If we return CyTrue from this function, the FX3 device is retained in the low power state. If we return CyFalse, the FX3 device immediately tries to trigger an exit back to U0. This application does not have any state in which we should not allow U1/U2 transitions; and therefore the function always return CyTrue. */ CyBool_t CyFxApplnLPMRqtCB ( CyU3PUsbLinkPowerMode link_mode) { return CyTrue; } /* SPI initialization for flash programmer application. */ CyU3PReturnStatus_t CyFxFlashProgSpiInit (uint16_t pageLen) { CyU3PReturnStatus_t status = CY_U3P_SUCCESS; CyU3PSpiConfig_t spiConfig; CyU3PDmaChannelConfig_t dmaConfig; /* Start the SPI module and configure the master. */ status = CyU3PSpiInit(); if (status != CY_U3P_SUCCESS) { return status; } /* Start the SPI master block. Run the SPI clock at 8MHz * and configure the word length to 8 bits. Also configure * the slave select using FW. * * Note: This application uses the DMA mode of transfer to read/write data from/to * the SPI flash device. The DMA transfer mode does not work correctly when the clock * frequency is lower than 4 MHz. Please change the CyFxFlashProgSpiTransfer() function * to use the register mode (CyU3PSpiTransferWords) if the * clock frequency is being dropped below 4 MHz. */ CyU3PMemSet ((uint8_t *)&spiConfig, 0, sizeof(spiConfig)); spiConfig.isLsbFirst = CyFalse; spiConfig.cpol = CyTrue; spiConfig.ssnPol = CyFalse; spiConfig.cpha = CyTrue; spiConfig.leadTime = CY_U3P_SPI_SSN_LAG_LEAD_HALF_CLK; spiConfig.lagTime = CY_U3P_SPI_SSN_LAG_LEAD_HALF_CLK; spiConfig.ssnCtrl = CY_U3P_SPI_SSN_CTRL_FW; spiConfig.clock = 8000000; spiConfig.wordLen = 8; status = CyU3PSpiSetConfig (&spiConfig, NULL); if (status != CY_U3P_SUCCESS) { return status; } /* Create the DMA channels for SPI write and read. */ CyU3PMemSet ((uint8_t *)&dmaConfig, 0, sizeof(dmaConfig)); dmaConfig.size = pageLen; /* No buffers need to be allocated as this channel * will be used only in override mode. */ dmaConfig.count = 0; dmaConfig.prodAvailCount = 0; dmaConfig.dmaMode = CY_U3P_DMA_MODE_BYTE; dmaConfig.prodHeader = 0; dmaConfig.prodFooter = 0; dmaConfig.consHeader = 0; dmaConfig.notification = 0; dmaConfig.cb = NULL; /* Channel to write to SPI flash. */ dmaConfig.prodSckId = CY_U3P_CPU_SOCKET_PROD; dmaConfig.consSckId = CY_U3P_LPP_SOCKET_SPI_CONS; status = CyU3PDmaChannelCreate (&glSpiTxHandle, CY_U3P_DMA_TYPE_MANUAL_OUT, &dmaConfig); if (status != CY_U3P_SUCCESS) { return status; } /* Channel to read from SPI flash. */ dmaConfig.prodSckId = CY_U3P_LPP_SOCKET_SPI_PROD; dmaConfig.consSckId = CY_U3P_CPU_SOCKET_CONS; status = CyU3PDmaChannelCreate (&glSpiRxHandle, CY_U3P_DMA_TYPE_MANUAL_IN, &dmaConfig); if (status == CY_U3P_SUCCESS) { glSpiPageSize = pageLen; } return status; } /* This function initializes the GPIF interface and initializes * the USB interface. */ void CyFxSlFifoApplnInit (void) { CyU3PPibClock_t pibClock; CyU3PReturnStatus_t apiRetStatus = CY_U3P_SUCCESS; CyU3PGpioClock_t gpioClock; CyU3PGpioSimpleConfig_t gpioConfig; /* Initialize the p-port block. */ pibClock.clkDiv = 2; pibClock.clkSrc = CY_U3P_SYS_CLK; pibClock.isHalfDiv = CyFalse; /* Disable DLL for sync GPIF */ pibClock.isDllEnable = CyFalse; apiRetStatus = CyU3PPibInit(CyTrue, &pibClock); if (apiRetStatus != CY_U3P_SUCCESS) { CyU3PDebugPrint (4, "P-port Initialization failed, Error Code = %d\n",apiRetStatus); CyFxAppErrorHandler(apiRetStatus); } /* Load the GPIF configuration for Slave FIFO sync mode. */ apiRetStatus = CyU3PGpifLoad (&CyFxGpifConfig); if (apiRetStatus != CY_U3P_SUCCESS) { CyU3PDebugPrint (4, "CyU3PGpifLoad failed, Error Code = %d\n",apiRetStatus); CyFxAppErrorHandler(apiRetStatus); } CyU3PGpifSocketConfigure (0,CY_U3P_PIB_SOCKET_0,3,CyFalse,1); CyU3PGpifSocketConfigure (3,CY_U3P_PIB_SOCKET_3,2,CyFalse,1); /* Start the state machine. */ apiRetStatus = CyU3PGpifSMStart (RESET, ALPHA_RESET); if (apiRetStatus != CY_U3P_SUCCESS) { CyU3PDebugPrint (4, "CyU3PGpifSMStart failed, Error Code = %d\n",apiRetStatus); CyFxAppErrorHandler(apiRetStatus); } /* Init the GPIO module */ gpioClock.fastClkDiv = 2; gpioClock.slowClkDiv = 0; gpioClock.simpleDiv = CY_U3P_GPIO_SIMPLE_DIV_BY_2; gpioClock.clkSrc = CY_U3P_SYS_CLK; gpioClock.halfDiv = 0; apiRetStatus = CyU3PGpioInit(&gpioClock, NULL); if (apiRetStatus != 0) { /* Error Handling */ CyU3PDebugPrint (4, "CyU3PGpioInit failed, error code = %d\n", apiRetStatus); CyFxAppErrorHandler(apiRetStatus); } /* Configure GPIO 59 as output */ gpioConfig.outValue = CyTrue; gpioConfig.driveLowEn = CyTrue; gpioConfig.driveHighEn = CyTrue; gpioConfig.inputEn = CyFalse; gpioConfig.intrMode = CY_U3P_GPIO_NO_INTR; apiRetStatus = CyU3PGpioSetSimpleConfig(59, &gpioConfig); if (apiRetStatus != CY_U3P_SUCCESS) { /* Error handling */ CyU3PDebugPrint (4, "CyU3PGpioSetSimpleConfig failed, error code = %d\n",apiRetStatus); CyFxAppErrorHandler(apiRetStatus); } /* Start the USB functionality. */ apiRetStatus = CyU3PUsbStart(); if (apiRetStatus != CY_U3P_SUCCESS) { CyU3PDebugPrint (4, "CyU3PUsbStart failed to Start, Error code = %d\n", apiRetStatus); CyFxAppErrorHandler(apiRetStatus); } CyFxFlashProgSpiInit(0x100); /* The fast enumeration is the easiest way to setup a USB connection, * where all enumeration phase is handled by the library. Only the * class / vendor requests need to be handled by the application. */ CyU3PUsbRegisterSetupCallback(CyFxSlFifoApplnUSBSetupCB, CyTrue); /* Setup the callback to handle the USB events. */ CyU3PUsbRegisterEventCallback(CyFxSlFifoApplnUSBEventCB); /* Register a callback to handle LPM requests from the USB 3.0 host. */ CyU3PUsbRegisterLPMRequestCallback(CyFxApplnLPMRqtCB); /* Set the USB Enumeration descriptors */ /* Super speed device descriptor. */ apiRetStatus = CyU3PUsbSetDesc(CY_U3P_USB_SET_SS_DEVICE_DESCR, 0, (uint8_t *)CyFxUSB30DeviceDscr); if (apiRetStatus != CY_U3P_SUCCESS) { CyU3PDebugPrint (4, "USB set device descriptor failed, Error code = %d\n", apiRetStatus); CyFxAppErrorHandler(apiRetStatus); } /* High speed device descriptor. */ apiRetStatus = CyU3PUsbSetDesc(CY_U3P_USB_SET_HS_DEVICE_DESCR, 0, (uint8_t *)CyFxUSB20DeviceDscr); if (apiRetStatus != CY_U3P_SUCCESS) { CyU3PDebugPrint (4, "USB set device descriptor failed, Error code = %d\n", apiRetStatus); CyFxAppErrorHandler(apiRetStatus); } /* BOS descriptor */ apiRetStatus = CyU3PUsbSetDesc(CY_U3P_USB_SET_SS_BOS_DESCR, 0, (uint8_t *)CyFxUSBBOSDscr); if (apiRetStatus != CY_U3P_SUCCESS) { CyU3PDebugPrint (4, "USB set configuration descriptor failed, Error code = %d\n", apiRetStatus); CyFxAppErrorHandler(apiRetStatus); } /* Device qualifier descriptor */ apiRetStatus = CyU3PUsbSetDesc(CY_U3P_USB_SET_DEVQUAL_DESCR, 0, (uint8_t *)CyFxUSBDeviceQualDscr); if (apiRetStatus != CY_U3P_SUCCESS) { CyU3PDebugPrint (4, "USB set device qualifier descriptor failed, Error code = %d\n", apiRetStatus); CyFxAppErrorHandler(apiRetStatus); } /* Super speed configuration descriptor */ apiRetStatus = CyU3PUsbSetDesc(CY_U3P_USB_SET_SS_CONFIG_DESCR, 0, (uint8_t *)CyFxUSBSSConfigDscr); if (apiRetStatus != CY_U3P_SUCCESS) { CyU3PDebugPrint (4, "USB set configuration descriptor failed, Error code = %d\n", apiRetStatus); CyFxAppErrorHandler(apiRetStatus); } /* High speed configuration descriptor */ apiRetStatus = CyU3PUsbSetDesc(CY_U3P_USB_SET_HS_CONFIG_DESCR, 0, (uint8_t *)CyFxUSBHSConfigDscr); if (apiRetStatus != CY_U3P_SUCCESS) { CyU3PDebugPrint (4, "USB Set Other Speed Descriptor failed, Error Code = %d\n", apiRetStatus); CyFxAppErrorHandler(apiRetStatus); } /* Full speed configuration descriptor */ apiRetStatus = CyU3PUsbSetDesc(CY_U3P_USB_SET_FS_CONFIG_DESCR, 0, (uint8_t *)CyFxUSBFSConfigDscr); if (apiRetStatus != CY_U3P_SUCCESS) { CyU3PDebugPrint (4, "USB Set Configuration Descriptor failed, Error Code = %d\n", apiRetStatus); CyFxAppErrorHandler(apiRetStatus); } /* String descriptor 0 */ apiRetStatus = CyU3PUsbSetDesc(CY_U3P_USB_SET_STRING_DESCR, 0, (uint8_t *)CyFxUSBStringLangIDDscr); if (apiRetStatus != CY_U3P_SUCCESS) { CyU3PDebugPrint (4, "USB set string descriptor failed, Error code = %d\n", apiRetStatus); CyFxAppErrorHandler(apiRetStatus); } /* String descriptor 1 */ apiRetStatus = CyU3PUsbSetDesc(CY_U3P_USB_SET_STRING_DESCR, 1, (uint8_t *)CyFxUSBManufactureDscr); if (apiRetStatus != CY_U3P_SUCCESS) { CyU3PDebugPrint (4, "USB set string descriptor failed, Error code = %d\n", apiRetStatus); CyFxAppErrorHandler(apiRetStatus); } /* String descriptor 2 */ apiRetStatus = CyU3PUsbSetDesc(CY_U3P_USB_SET_STRING_DESCR, 2, (uint8_t *)CyFxUSBProductDscr); if (apiRetStatus != CY_U3P_SUCCESS) { CyU3PDebugPrint (4, "USB set string descriptor failed, Error code = %d\n", apiRetStatus); CyFxAppErrorHandler(apiRetStatus); } /* Connect the USB Pins with super speed operation enabled. */ apiRetStatus = CyU3PConnectState(CyTrue, CyTrue); if (apiRetStatus != CY_U3P_SUCCESS) { CyU3PDebugPrint (4, "USB Connect failed, Error code = %d\n", apiRetStatus); CyFxAppErrorHandler(apiRetStatus); } } /* Entry function for the slFifoAppThread. */ void SlFifoAppThread_Entry ( uint32_t input) { /* Initialize the debug module */ CyFxSlFifoApplnDebugInit(); /* Initialize the slave FIFO application */ CyFxSlFifoApplnInit(); for (;;) { CyU3PThreadSleep (1000); if (glIsApplnActive) { /* Print the number of buffers received so far from the USB host. */ CyU3PDebugPrint (6, "Data tracker: buffers received: %d, buffers sent: %d.\n", glDMARxCount, glDMATxCount); } } } /* Application define function which creates the threads. */ void CyFxApplicationDefine ( void) { void *ptr = NULL; uint32_t retThrdCreate = CY_U3P_SUCCESS; /* Allocate the memory for the thread */ ptr = CyU3PMemAlloc (CY_FX_SLFIFO_THREAD_STACK); /* Create the thread for the application */ retThrdCreate = CyU3PThreadCreate (&slFifoAppThread, /* Slave FIFO app thread structure */ "21:Slave_FIFO_sync", /* Thread ID and thread name */ SlFifoAppThread_Entry, /* Slave FIFO app thread entry function */ 0, /* No input parameter to thread */ ptr, /* Pointer to the allocated thread stack */ CY_FX_SLFIFO_THREAD_STACK, /* App Thread stack size */ CY_FX_SLFIFO_THREAD_PRIORITY, /* App Thread priority */ CY_FX_SLFIFO_THREAD_PRIORITY, /* App Thread pre-emption threshold */ CYU3P_NO_TIME_SLICE, /* No time slice for the application thread */ CYU3P_AUTO_START /* Start the thread immediately */ ); /* Check the return code */ if (retThrdCreate != 0) { /* Thread Creation failed with the error code retThrdCreate */ /* Add custom recovery or debug actions here */ /* Application cannot continue */ /* Loop indefinitely */ while(1); } } /* * Main function */ int main (void) { CyU3PIoMatrixConfig_t io_cfg; CyU3PReturnStatus_t status = CY_U3P_SUCCESS; CyU3PSysClockConfig_t clockConfig; /* When the GPIF data bus is configured as 32-bits wide and running at 100 MHz (synchronous), the FX3 system clock has to be set to a frequency greater than 400 MHz. */ #if (CY_FX_SLFIFO_GPIF_16_32BIT_CONF_SELECT == 0) clockConfig.setSysClk400 = CyFalse; #else clockConfig.setSysClk400 = CyTrue; #endif clockConfig.cpuClkDiv = 2; clockConfig.dmaClkDiv = 2; clockConfig.mmioClkDiv = 2; clockConfig.useStandbyClk = CyFalse; clockConfig.clkSrc = CY_U3P_SYS_CLK; status = CyU3PDeviceInit (&clockConfig); if (status != CY_U3P_SUCCESS) { goto handle_fatal_error; } /* Initialize the caches. Enable both Instruction and Data Caches. */ status = CyU3PDeviceCacheControl (CyTrue, CyFalse, CyFalse); if (status != CY_U3P_SUCCESS) { goto handle_fatal_error; } /* Configure the IO matrix for the device. On the FX3 DVK board, the COM port * is connected to the IO(53:56). This means that either DQ32 mode should be * selected or lppMode should be set to UART_ONLY. Here we are choosing * UART_ONLY configuration for 16 bit slave FIFO configuration and setting * isDQ32Bit for 32-bit slave FIFO configuration. */ io_cfg.s0Mode = CY_U3P_SPORT_INACTIVE; io_cfg.s1Mode = CY_U3P_SPORT_INACTIVE; io_cfg.useUart = CyTrue; io_cfg.useI2C = CyFalse; io_cfg.useI2S = CyFalse; io_cfg.useSpi = CyFalse; #if (CY_FX_SLFIFO_GPIF_16_32BIT_CONF_SELECT == 0) io_cfg.isDQ32Bit = CyFalse; io_cfg.lppMode = CY_U3P_IO_MATRIX_LPP_UART_ONLY; #else io_cfg.isDQ32Bit = CyTrue; io_cfg.lppMode = CY_U3P_IO_MATRIX_LPP_DEFAULT; #endif /* No GPIOs are enabled. */ io_cfg.gpioSimpleEn[0] = 0; io_cfg.gpioSimpleEn[1] = 0x08000000; io_cfg.gpioComplexEn[0] = 0; io_cfg.gpioComplexEn[1] = 0; status = CyU3PDeviceConfigureIOMatrix (&io_cfg); if (status != CY_U3P_SUCCESS) { goto handle_fatal_error; } /* This is a non returnable call for initializing the RTOS kernel */ CyU3PKernelEntry (); /* Dummy return to make the compiler happy */ return 0; handle_fatal_error: /* Cannot recover from this error. */ while (1); } /* [ ] */ 为什么擦除不了Flash
最新发布
10-10
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值