cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H747 Discovery - DMA not starting

DBrow
Associate II

Hi,

I tried to translate my 32F746 Discovery Audio program (SAI with DMA DB Mode) to the STM32H747 Discovery Board (using the M7). SAI and DMA are correct configured. I am not able to start DMA1 Stream 0 or to set the S0CR EN Bit manually. SAI is started (SAIXEN and DMAEN of SAI1A are set) . What am I doing wrong ?

regards

Dave

3 REPLIES 3
TDK
Guru

> SAI and DMA are correct configured

Maybe they're not. Post the contents of these registers, or post some code.

If you feel a post has answered your question, please click "Accept as Solution".
DBrow
Associate II

Hi TDK,

here is the are functions from main:

static void MX_SAI1_Init(void)
{
  hsai_BlockA1.Instance = SAI1_Block_A;
  hsai_BlockA1.Init.AudioMode = SAI_MODEMASTER_TX;
  hsai_BlockA1.Init.Synchro = SAI_ASYNCHRONOUS;
  hsai_BlockA1.Init.OutputDrive = SAI_OUTPUTDRIVE_DISABLE;
  hsai_BlockA1.Init.NoDivider = SAI_MASTERDIVIDER_ENABLE;
  hsai_BlockA1.Init.FIFOThreshold = SAI_FIFOTHRESHOLD_EMPTY;
  hsai_BlockA1.Init.AudioFrequency = SAI_AUDIO_FREQUENCY_48K;
  hsai_BlockA1.Init.SynchroExt = SAI_SYNCEXT_DISABLE;
  hsai_BlockA1.Init.MonoStereoMode = SAI_STEREOMODE;
  hsai_BlockA1.Init.CompandingMode = SAI_NOCOMPANDING;
  hsai_BlockA1.Init.TriState = SAI_OUTPUT_NOTRELEASED;
  if (HAL_SAI_InitProtocol(&hsai_BlockA1, SAI_I2S_STANDARD, SAI_PROTOCOL_DATASIZE_16BIT, 2) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN SAI1_Init 2 */
 
  /* USER CODE END SAI1_Init 2 */
 
}
 
/** 
  * Enable DMA controller clock
  */
static void MX_DMA_Init(void) 
{
 
  /* DMA controller clock enable */
  __HAL_RCC_DMA1_CLK_ENABLE();
 
  /* DMA interrupt init */
  /* DMA1_Stream0_IRQn interrupt configuration */
  HAL_NVIC_SetPriority(DMA1_Stream0_IRQn, 0, 0);
  HAL_NVIC_EnableIRQ(DMA1_Stream0_IRQn);
  //((DMA_Stream_TypeDef *)&hdma_sai1_a)->CR & DMA_SxCR_CT) = SET;	
 
}

and here is the part from hal_msp:

extern DMA_HandleTypeDef hdma_sai1_a;
 
static uint32_t SAI1_client =0;
 
void HAL_SAI_MspInit(SAI_HandleTypeDef* hsai)
{
 
  GPIO_InitTypeDef GPIO_InitStruct;
/* SAI1 */
    if(hsai->Instance==SAI1_Block_A)
    {
    /* Peripheral clock enable */
    if (SAI1_client == 0)
    {
       __HAL_RCC_SAI1_CLK_ENABLE();
    }
    SAI1_client ++;
    
    /**SAI1_A_Block_A GPIO Configuration    
    PD6     ------> SAI1_SD_A
    PE5     ------> SAI1_SCK_A
    PE4     ------> SAI1_FS_A
    PG7     ------> SAI1_MCLK_A 
    */
    GPIO_InitStruct.Pin = GPIO_PIN_6;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
    GPIO_InitStruct.Alternate = GPIO_AF6_SAI1;
    HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
 
    GPIO_InitStruct.Pin = GPIO_PIN_5|GPIO_PIN_4;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
    GPIO_InitStruct.Alternate = GPIO_AF6_SAI1;
    HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
 
    GPIO_InitStruct.Pin = GPIO_PIN_7;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
    GPIO_InitStruct.Alternate = GPIO_AF6_SAI1;
    HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);
 
    /* Peripheral DMA init*/
    
    hdma_sai1_a.Instance = DMA1_Stream0;
    hdma_sai1_a.Init.Request = DMA_REQUEST_SAI1_A;
    hdma_sai1_a.Init.Direction = DMA_MEMORY_TO_PERIPH;
    hdma_sai1_a.Init.PeriphInc = DMA_PINC_DISABLE;
    hdma_sai1_a.Init.MemInc = DMA_MINC_ENABLE;
    hdma_sai1_a.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD;
    hdma_sai1_a.Init.MemDataAlignment = DMA_MDATAALIGN_WORD;
    hdma_sai1_a.Init.Mode = DMA_CIRCULAR;
    hdma_sai1_a.Init.Priority = DMA_PRIORITY_HIGH;
    hdma_sai1_a.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
    if (HAL_DMA_Init(&hdma_sai1_a) != HAL_OK)
    {
      Error_Handler();
    }
 
    /* Several peripheral DMA handle pointers point to the same DMA handle.
     Be aware that there is only one channel to perform all the requested DMAs. */
    __HAL_LINKDMA(hsai,hdmarx,hdma_sai1_a);
 
    __HAL_LINKDMA(hsai,hdmatx,hdma_sai1_a);
 
    }
}

finally I start the SAI/DMA with :

void StartAudioDMA(void){
__HAL_DMA_ENABLE_IT(&hdma_sai1_a, DMA_IT_TC);
dma_error = HAL_DMAEx_MultiBufferStart(&hdma_sai1_a, (uint32_t)(&buff_01), (uint32_t)(SAI1_BASE + 0x20),(uint32_t)(&buff_02), 192);		
SET_BIT(SAI1_Block_A->CR1, SAI_xCR1_DMAEN);
__HAL_SAI_ENABLE(&hsai_BlockA1);
}

dma_error = 0;

DBrow
Associate II

Hi,

I found the reason, the DMA on the STM32H7 cannot access the standard RAM Region 0x20000000 . You have to switch to 0x24000000  to get the DMA working. See this great article about the problem: https://community.st.com/s/article/FAQ-DMA-is-not-working-on-STM32H7-devices

regards

Dave