Hi, this is the function that I call to transmit USB
static unsigned long
Transmit_USB(USBbuffer Data,int size)
{
unsigned long ulLoop, ulCount,ulLoop_buff;
unsigned long ulWriteIndex;
uint32_t buffer_stockage;
volatile int shiftage;
tUSBRingBufObject sTxRing;
//
// Get the current buffer information to allow us to write directly to
// the transmit buffer (we already have enough information from the
// parameters to access the receive buffer directly).
//
USBBufferInfoGet(&g_sTxBuffer, &sTxRing);
//
// How many characters can we process this time round?
//
ulCount = size;
//
// Set up to process the characters by directly accessing the USB buffers.
//
ulWriteIndex = sTxRing.ulWriteIndex;
for(ulLoop = 0 ; ulLoop < ulCount ;ulLoop = ulLoop + 4)
{
for(ulLoop_buff = 0 ; ulLoop_buff < 4; ulLoop_buff++){
buffer_stockage = Data.data[ulLoop+ulLoop_buff];
shiftage = 32 - ( ulLoop_buff + 1 ) * 8;
if(shiftage < 0){
shiftage = 0;
}
buffer_stockage = buffer_stockage<<shiftage;
}
//
// Move to the next character taking care to adjust the pointer for
// the buffer wrap if necessary.
//
g_pucUSBTxBuffer[ulWriteIndex] = buffer_stockage;
ulWriteIndex = ulWriteIndex + 4;
ulWriteIndex = (ulWriteIndex == BULK_BUFFER_SIZE) ? 0 : ulWriteIndex;
}
USBBufferDataWritten(&g_sTxBuffer,size);
return(ulCount);
}
The function seem to be working because if I check the Txbuffer into the debugger, he got fill with char. But eventually, the MCU fall into FaultISR error and I would like to know why.