2017-09-22 05:25 AM
Dear all,
I'm having a problem creating a arbitrary waveform using timer 1, MCU STM32L476RG. I use STM32CubeMX (4.21.0) to generate all initialization code after which I try to start a DMA transfer from memory to the timer 1 peripheral. I'm partly successful doing this.
I created a array of 6 words for two waveform patterns to be send to TIM1 channel 1 (TIM1_ARR, TIM1_RCR, TIM1_CCR1) This is how the basics look
uint32_t aSRC_Buffer[6] = { 100, 2, 15, 100, 8, 50 }; /// ARR, RCR, CCR1 x 2
HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_1) ;
HAL_TIM_DMABurst_WriteStart(&htim1, TIM_DMABASE_ARR, TIM_DMA_UPDATE, (uint32_t*) aSRC_Buffer, TIM_DMABURSTLENGTH_3TRANSFERS);With this code only the first pattern is generated. changing TIM_DMABURSTLENGTH_3TRANSFERS to TIM_DMABURSTLENGTH_6TRANSFERS does not work either (seems right if my assumption is correct, see below).
I don't understand the relation between the complete DMA buffer size (mem) and the TIM registers update. Right now I assume that setting TIM_DMABURSTLENGTH_3TRANSFERS means the three TIM registers starting at ARR are updated. But how do I set the total buffer size to use. I have tried to set DMA1_Channel6->CNDTR = 6; in the HAL_TIM_Base_MspInit routine but that didn't help either. I'm lost.... Is there anyone that can explain to me what I am missing here.
some cubemx settings are :
DMA1 -> DMA1 channel 6 -> memory to peripheral -> priority high
Mode normal Increment address -> memory only
Data width word
Partly generated code is
if(htim_base->Instance==TIM1)
{/* Peripheral clock enable */
__HAL_RCC_TIM1_CLK_ENABLE(); hdma_tim1_up.Instance = DMA1_Channel6; hdma_tim1_up.Init.Request = DMA_REQUEST_7; hdma_tim1_up.Init.Direction = DMA_MEMORY_TO_PERIPH; hdma_tim1_up.Init.PeriphInc = DMA_PINC_DISABLE; hdma_tim1_up.Init.MemInc = DMA_MINC_ENABLE; hdma_tim1_up.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD; hdma_tim1_up.Init.MemDataAlignment = DMA_MDATAALIGN_WORD; hdma_tim1_up.Init.Mode = DMA_NORMAL; hdma_tim1_up.Init.Priority = DMA_PRIORITY_HIGH; if (HAL_DMA_Init(&hdma_tim1_up) != HAL_OK) { _Error_Handler(__FILE__, __LINE__); } __HAL_LINKDMA(htim_base,hdma[TIM_DMA_ID_UPDATE],hdma_tim1_up);/* TIM1 interrupt Init */
HAL_NVIC_SetPriority(TIM1_UP_TIM16_IRQn, 0, 0); HAL_NVIC_EnableIRQ(TIM1_UP_TIM16_IRQn);}
Thanks in advance,
Wim
2018-12-04 05:10 AM
This doesn't work - static callback functions are not accessible from other modules. One has to patch the HAL sources.