OBauck / stm32_wav_player

2 stars 1 forks source link

HAL_TIM_PWM_PulseHalfFinishedCallback is never called #1

Closed joric closed 4 years ago

joric commented 4 years ago

I was trying to port your project for BluePill (see https://github.com/joric/ts80player), figures out HAL_TIM_PWM_PulseHalfFinishedCallback is never called. Also it looks like you really fill only the quarter of the buffer not the half as expected. So what's up with that. Have you really got a decent sound quality from that? I'm getting a lot of crackling.

That callback is never called, I wonder why: htim1.hdma[TIM_DMA_ID_CC1]->XferHalfCpltCallback = HAL_TIM_PWM_PulseHalfFinishedCallback;

This code clearly offsets only for a quarter of the buffer (FATFS_BUFFER_SIZE/2), not a half:

#define PWM_DMA_BUFFER_SIZE 1024
__IO uint16_t pwm_dma_buffer[PWM_DMA_BUFFER_SIZE];
#define FATFS_BUFFER_SIZE 512
uint8_t fatfs_buffer[FATFS_BUFFER_SIZE];
...
void pwm_dma_fill_buffer(uint8_t *wav_data, uint16_t data_size, bool lower_half)
{
    int32_t pcm_value;
    uint16_t buffer_start = lower_half ? 0 : FATFS_BUFFER_SIZE/2;

    for(uint16_t i = 0; i < data_size; i+=2)
    {
        pcm_value = (int32_t)(wav_data[i] + (wav_data[i+1]<<8));
        pwm_dma_buffer[i/2 + buffer_start] = ((uint16_t)(pcm_value + 32768))>>5;
    }
}

...
res = f_read(&MyFile, fatfs_buffer, FATFS_BUFFER_SIZE, (UINT*)&bytesread);
pwm_dma_fill_buffer(fatfs_buffer, bytesread, pwm_dma_lower_half);
...

So what's up with that?

joric commented 4 years ago

I guess it was external crystal thingy, no miniware hardware has xtal.