2025-01-07 02:17 PM
We are working on STM32C071KBU6
In STM example TIM_DMA, I see it uses PA10 - TIM1_CH3 with DMA channel 5, but I could not find anything about this. Anyone know how to find this information? I would like to use different pins but don't know what DMA channel mapped to them.
All I found is, in user manual, tim1_ch3_dma stick with 22, not sure what it means.
2025-01-07 02:35 PM
The STM32C0 doesn't have DMA channels the way than the STM32F7 does. Instead, the mapping is done through the DMAMUX. In this case, input 22 is TIM1 channel 3.
2025-01-08 05:43 AM - last edited on 2025-01-08 06:00 AM by SofLit
Can you a bit more specific?
Here is a piece of my code and I already get it working on PA1 which is TIM1_CH2
I understand input 22 is TIM1 channel 3, 21 is TIM1_CH2, but my code, I don't need to know this number. All I need to know is channel to set to Instance, enable interrupt, example:
hdma_tim1_ch3.Instance = DMA1_Channel5;
I don't see how to use input "22" anywhere in ST example, how to use input "22"? what is relationship "input22" to DMA1_Channel5?
__HAL_RCC_DMA1_CLK_ENABLE();
__HAL_RCC_TIM1_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
HAL_NVIC_SetPriority(DMAMUX1_DMA1_CH4_5_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(DMAMUX1_DMA1_CH4_5_IRQn);
Gpio_EnablePin(1, GPIO_MODE_AF_PP, GPIO_AF5_TIM1, GPIO_NOPULL, GPIO_SPEED_FREQ_VERY_HIGH);
htim_tim1_ch3.Instance = TIM1;
htim_tim1_ch3.Init.Period = 100;
htim_tim1_ch3.Init.Prescaler = 17;//(SystemCoreClock / 2500000) - 1; // 1us
htim_tim1_ch3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim_tim1_ch3.Init.CounterMode = TIM_COUNTERMODE_UP;
__HAL_RCC_TIM1_FORCE_RESET();
__HAL_RCC_TIM1_RELEASE_RESET();
if (HAL_TIM_OC_Init(&htim_tim1_ch3) != HAL_OK)
{
return ;
}
TIM_OC_InitTypeDef sConfig = { 0 };
sConfig.OCMode = TIM_OCMODE_TOGGLE;
sConfig.OCPolarity = TIM_OCPOLARITY_LOW;//TIM_OCPOLARITY_HIGH;// : TIM_OCPOLARITY_LOW;
sConfig.Pulse = time_data[0];
if (HAL_TIM_OC_ConfigChannel(&htim_tim1_ch3, &sConfig, TIM_CHANNEL_2) != HAL_OK)
{
return ;
}
hdma_tim1_ch3.Init.Direction = DMA_MEMORY_TO_PERIPH;
hdma_tim1_ch3.Init.PeriphInc = DMA_PINC_DISABLE;
hdma_tim1_ch3.Init.MemInc = DMA_MINC_ENABLE;
hdma_tim1_ch3.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD;
hdma_tim1_ch3.Init.MemDataAlignment = DMA_MDATAALIGN_WORD;
hdma_tim1_ch3.Init.Mode = 0;
hdma_tim1_ch3.Init.Priority = DMA_PRIORITY_LOW;
hdma_tim1_ch3.Init.Request = LL_DMAMUX_REQ_TIM1_CH2;
hdma_tim1_ch3.Instance = DMA1_Channel5;
if (HAL_DMA_Init(&hdma_tim1_ch3) != HAL_OK) {
return;
}
__HAL_LINKDMA(&htim_tim1_ch3,hdma[TIM_DMA_ID_CC2], hdma_tim1_ch3);
htim_tim1_ch3.Instance->CNT = 0;
__HAL_TIM_ENABLE_IT(&htim_tim1_ch3, TIM_IT_UPDATE);
if (HAL_TIM_OC_Start_DMA(&htim_tim1_ch3, TIM_CHANNEL_2, &time_data[1], sizeof(time_data)/4 - 1) != HAL_OK) {
return;
}
2025-01-08 05:59 AM
2025-01-08 07:22 AM
Read the Reference Manual, DMAMUX section, Table 42.
2025-01-08 08:00 AM
The DMAMUX mapping in the example is done on this line:
LL_DMA_SetPeriphRequest(DMA1, LL_DMA_CHANNEL_5, LL_DMAMUX_REQ_TIM1_UP);
You can use any DMA channel you want for this as long as the DMAMUX sets that channel's input to the correct request.