2025-03-13 10:46 PM
here i generate pulse using pwm generation.. where i need to stop at n th pulse.. so i use RCR register to stop it..
where my mcu handle only 8 bit data to the RCR register.. so i split the data into array "RCR_Data" and stores as source destination
i call the DMA to get the value from Source to destination as "&htim1.Instance->RCR" address... once DMA complete the process
it should says to end the timer generation.. but here i can't get the interrupt handling to call the callback function and stop the timer...
Thanks for advance.. please lets us help to solve this problem...
void MyDMA_TransferComplete(DMA_HandleTypeDef *hdma) {
if (hdma->Instance == hdma_tim1_ch1.Instance) {
// Disable everything in sequence
__HAL_TIM_DISABLE_DMA(&htim1, TIM_DMA_UPDATE);
TIM1->CR1 &= ~TIM_CR1_CEN; // Force disable timer
TIM1->CCER &= ~TIM_CCER_CC1E; // Force disable channel output
// Standard cleanup
HAL_TIM_PWM_Stop(&htim1, TIM_CHANNEL_1);
__HAL_TIM_DISABLE(&htim1);
HAL_DMA_Abort(hdma);
// Visual indication
HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5); // Use PA5 which is configured as output
}
}
uint8_t RCR_Data[] = {10,20,30,40,50};
void Start_DMA_RCR_Update(void) {
// Register callback
HAL_DMA_RegisterCallback(&hdma_tim1_ch1, HAL_DMA_XFER_CPLT_CB_ID, MyDMA_TransferComplete);
// Calculate direct address to RCR register (RCR is at offset 0x30 from TIM base)
uint32_t rcrAddress = (uint32_t)&htim1.Instance->RCR;
// Make sure DMA uses proper alignment
HAL_DMA_Start_IT(&hdma_tim1_ch1, (uint32_t)RCR_Data, rcrAddress, 5);
// Enable update DMA request
__HAL_TIM_ENABLE_DMA(&htim1, TIM_DMA_UPDATE);
// Start PWM
HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_1);
}
2025-03-14 7:07 AM
Might be more precise to use a master/slave timer setup which turns off the timer after an exact number of pulses. If your PWM frequency is high, you'll probably get another pulse before the callback actually fires and stops the timer.
As for why it's not working, is the NVIC interrupt enabled? Is the DMA IRQ handler defined and does it call HAL_DMA_IRQHandler?