I have a file stored in SPI flash ROM, and need to transfer to the host after boot up.
I'm using two DMA channels working with end points. One is for receiving host command, the other is for data out transfer.
After command come in, the DMA callback will explain the command, read data from SPI flash and do the steps below:
CyU3PDmaChannelGetBuffer(&DCITxChHandle, &txBuffer, 0);
CyU3PMemCopy(txBuffer.buffer, (uint8_t*)TxBuffer, tx_length);
CyU3PDmaChannelCommitBuffer (&DCITxChHandle, tx_length, 0);
Now my situation is if I don't manipulate the SPI module in the callback, just transfer any data in the ram, the firmware works fine. if I want to write the flash in the callback function, no matter how many data should write to the flash, it still works fine.
But when I read data from flash and send to the host, it will stuck after certain packages. It looks like that when stuck begin, first command had been received, but the commit buffer stay in somewhere din't been sent out, and then the second command. When the third command came in, the first stuck buffer begin to really sent out, and then the 4th command came in, the second commit buffer go out, and so on.
I tried different DMA size and different DMA count, the symptoms are the same. except that large DMA size and the large count looks could transfer more correct echo data.
In callback function, I manipulate the SPI like this
if (!(aStatus & SPI_ENABLE)) // SPI Module disabled
aStatus &= ~DQ32_ENABLE;
aStatus |= SPI_ENABLE;
status = hwspi_flash_read (FlashAddress, data, data_length);
CyU3PReturnStatus_t hwspi_flash_read (uint32_t addr, uint8_t* buf, uint16_t len)
CyU3PReturnStatus_t status = CY_U3P_SUCCESS;
if (len == 0) return CY_U3P_SUCCESS;
Command = 0x03; // read command
Command = (addr >> 16) & 0xFF;
Command = (addr >> 8) & 0xFF;
Command = addr & 0xFF;
status = CyU3PSpiTransmitWords (Command, 4);
if (status == CY_U3P_SUCCESS)
status = CyU3PSpiReceiveWords (buf, len); // read data
I trid using Events in callback and Thread to handle command explanation, so that all the procedure calling will out of the call. Don't fix the problem.
Any suggesting will welcome.