2025-10-02 3:42 PM - last edited on 2025-10-03 2:44 AM by mƎALLEm
Post edited by ST moderator to be inline with the community rules especially with the code sharing. In next time please use </> button to paste your code. Please read this post: How to insert source code
HI
I am having an issue with starting measurements using the on-board microphone. Everything has been configured based on the BSP code, but set up from scratch using CubeMX. The problem is that when I start the DMA Receive
if (HAL_SAI_Receive_DMA(&hsai_BlockA4, (uint8_t*)PDM_Buffer, PDM_BUF_SIZE) != HAL_OK)
{
printf("SAI RX start error!\r\n");
}
else
{
printf("SAI RX started OK");
}
//callbacks:
void HAL_SAI_RxHalfCpltCallback(SAI_HandleTypeDef *hsai)
{
printf("HAL_SAI_RxHalfCpltCallback\n");
}
void HAL_SAI_RxCpltCallback(SAI_HandleTypeDef *hsai)
{
printf("HAL_SAI_RxCpltCallback\n");
}
void HAL_SAI_ErrorCallback(SAI_HandleTypeDef *hsai)
{
printf("SAI error: 0x%08lx\n", hsai->ErrorCode);
}
I immediately get an interrupt reporting a DMA error (128 eror code in decimal).
I have already tried changing the clock frequencies, tried running it on a different core, and also tested with different data sizes, but none of this helped.
My config below:
2025-10-03 4:06 AM
Hello @Patryk_Kucia
@Patryk_Kucia wrote:I immediately get an interrupt reporting a DMA error (128 eror code in decimal).
Please could you specify which flag that generate this?
2025-10-03 5:43 AM - edited 2025-10-03 5:57 AM
HI
IDK if it's what you meant but i did it like this :
void HAL_SAI_ErrorCallback(SAI_HandleTypeDef *hsai)
{
printf("SAI error: 0x%08lx\n", hsai->ErrorCode);
if (hsai->ErrorCode & HAL_SAI_ERROR_OVR) printf(" -> Overrun error\n");
if (hsai->ErrorCode & HAL_SAI_ERROR_UDR) printf(" -> Underrun error\n");
if (hsai->ErrorCode & HAL_SAI_ERROR_DMA) printf(" -> DMA transfer error\n");
if (hsai->ErrorCode & HAL_SAI_ERROR_TIMEOUT) printf(" -> Timeout error\n");
}
and got:
-> DMA transfer error
so i went deeper:
if (hsai->ErrorCode & HAL_SAI_ERROR_DMA)
{
if (hsai->hdmarx != NULL)
printf(" -> DMA RX error: 0x%08lx\n", hsai->hdmarx->ErrorCode);
if (hsai->hdmatx != NULL)
printf(" -> DMA TX error: 0x%08lx\n", hsai->hdmatx->ErrorCode);
}
and interestingly enough I got:
DMA TX error: 0x00000001
#define HAL_DMA_ERROR_TE (0x00000001U) /*!< Transfer error */
but why is there a sending error if I only want to save?