DAC-USB Implementation Problem
- June 19, 2019
- 4 replies
- 1722 views
Hi, I am using Nucleo F303re with STM32 HAL Libraries built by STMCubeMX in order to implement an USB Audio player with bulk transfers. I changed the USB-CDC code a little bit to implement my application. I receive the data in the CDC-Receive-FS function and copy the data in there to a buffer used by DAC in DMA Circular mode. But everytime DMA starts to read the buffer from the beginning again i get an error equivelant to 16 samples of data. I am posting the error and the code here. My data is being sent with libusb in 480bytes chunks in regular timing. My array supplied to the DAC on the board is 19200 bytes and even if i change the size of the array it always happens at the beginning of the buffer. If i make it 9600 bytes error happens every 9600 bytes. If i make it 19200 or even 38400 it happens at every 19200 or 38400 bytes.
static int8_t CDC_Receive_FS(uint8_t* Buf, uint32_t *Len)
{
/* USER CODE BEGIN 6 */
// if(move_cnt >= PACK_SIZE){
// move_cnt =0;
//
// }
// memcpy(&RxBuf[move_cnt],Buf,*Len);
// move_cnt += *Len;
//
for(uint16_t i =0; i<*Len ; i++){
RxBuf[byte_cnt] = Buf[i];
byte_cnt++;
if(byte_cnt>=PACK_SIZE){
byte_cnt=0;
}
}
if(pack_cnt==0){
rx_cb();
}
pack_cnt++;
USBD_CDC_SetRxBuffer(&hUsbDeviceFS, &Buf[0]);
USBD_CDC_ReceivePacket(&hUsbDeviceFS);
// for (uint8_t i =0; i<*Len;i++){
// RxBuf[rx_ptr] =Buf[i] ;
// rx_ptr++;
// if(rx_ptr>=479){
// rx_ptr = 0;
//}
//}
return (USBD_OK);
/* USER CODE END 6 */
}void rx_cb(void){
HAL_TIM_Base_Start(&htim6);
HAL_DAC_Start(&hdac1,DAC_CHANNEL_1);
HAL_DAC_Start_DMA(&hdac1,DAC_CHANNEL_1,(uint32_t*)RxBuf,PACK_SIZE,DAC_ALIGN_8B_R);
}