Hi,
I'm to ST MCUs. I'm using a Timer and DMA to produce a variable PWM signal. So the idea is to start a DMA burst to load the pwm values in each period of the timer. It works well but it doesn't stop, it does the burst perfectly but then it keeps sending the last value instead of stop. The DMA is configured as Normal (Not circular). This is the configuraction:
dma_tim3_ch1_trig.Instance = DMA1_Channel4;
hdma_tim3_ch1_trig.Init.Direction = DMA_MEMORY_TO_PERIPH;
hdma_tim3_ch1_trig.Init.PeriphInc = DMA_PINC_DISABLE;
hdma_tim3_ch1_trig.Init.MemInc = DMA_MINC_ENABLE;
hdma_tim3_ch1_trig.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD;
hdma_tim3_ch1_trig.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
hdma_tim3_ch1_trig.Init.Mode = DMA_NORMAL;//DMA_CIRCULAR;
hdma_tim3_ch1_trig.Init.Priority = DMA_PRIORITY_HIGH;
if (HAL_DMA_Init(&hdma_tim3_ch1_trig) != 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(htim_pwm,hdma[TIM_DMA_ID_CC1],hdma_tim3_ch1_trig);
__HAL_LINKDMA(htim_pwm,hdma[TIM_DMA_ID_TRIGGER],hdma_tim3_ch1_trig);
I'm using a STM32F0 with HAL librarÃes and the LED toggle in the main function works as expected.
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "stm32f0xx_hal.h"
#include "usb_device.h"
ADC_HandleTypeDef hadc;
I2C_HandleTypeDef hi2c1;
TIM_HandleTypeDef htim3;
DMA_HandleTypeDef hdma_tim3_ch1_trig;
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
void Error_Handler(void);
static void MX_GPIO_Init(void);
static void MX_DMA_Init(void);
static void MX_ADC_Init(void);
static void MX_I2C1_Init(void);
static void MX_TIM3_Init(void);
void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim);
int main(void)
{
HAL_Init();
/* Configure the system clock */
SystemClock_Config();
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_DMA_Init();
MX_ADC_Init();
MX_I2C1_Init();
MX_TIM3_Init();
MX_USB_DEVICE_Init();
uint8_t buffer[10] = {10,20,30,40,50}
HAL_TIM_PWM_Start_DMA(&htim3, TIM_CHANNEL_1, (uint32_t *) buffer,5);
while(1){
HAL_Delay(100);
HAL_GPIO_TogglePin(LD2_GPIO_Port,LD2_Pin);
}
}
I tried debugging and I get the Interrupt when the transfer is finished.
Do I need to clear a flag or something in the interrupt routine?
Thanks!