cancel
Showing results for 
Search instead for 
Did you mean: 

STM32WB55 acquire signal from GPIO using DMA and trigger TIM

juvann
Associate III

I have a board P-NucleoWB55 and I'm trying to acquire a signal with external clock, very similar to uart, I tried with usart in slave mode without succcess, I tried with spi slave without success.

Now I'm trying to trigger a DMA transfer with a timer and clock source ETR.

I'm following this thread but the code use old api and I don't understand how start the timer.

I configured TIM2 Clock Source ETR2 and Counter Period, DMA TIM2_UP.

I read the AN4666 but I don't understand very well the example.

I tested this code:

  HAL_TIM_Base_Start(&htim2);
  HAL_DMA_Start_IT(&hdma_tim2_up, GPIOB->IDR, (uint32_t)buf, sizeof(buf));

I receive interrupt for timer but not for dma.

Thank you for suggestions

4 REPLIES 4
RomainR.
ST Employee

Hello @juvann (Community Member)

Related to AN4666, in reception mode the external clock is received on a GPIO connected to a timer input channel (TIMx_CH) configured in Input Capture mode. The rising/falling edge events on external clock GPIO will trigger DMA request in peripheral to memory mode.

It seems your code just start a timer counter and then the DMA but after that ?

Have you downloaded the firmware expansion of the AN4666 and review the code for STM32L476 in reception mode ? I think it will help you to understand and port it to STM32WB55 using same peripherals.

https://www.st.com/en/embedded-software/x-cube-paral-com.html#overview

Regards,

Romain

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Hello @RomainR.​ ,

> but after that ?

After that, I expect an interrupt which notify me the transfer.

Input capture mode should be used when I want measure the time, rigth?

I just have to sampling the pin of GPIO.

Regards

juvann
Associate III

I have found a partial solution:

HAL_TIM_Base_Start(&htim2);
HAL_DMA_Start_IT(&hdma_tim2_up, (uint32_t)&GPIOC->IDR, (uint32_t)buf, 1);
SET_BIT(TIM2->DIER, TIM_DIER_UDE);

set size as sizeof(buf) is wrong is correct 1, so for every update 1 byte is transfered.

Bit TIM_DIER_UDE is not set in HAL.

juvann
Associate III

Also previous change doesn't work, I completly removed DMA and I use only interrupt on timer.

So in my HAL_TIM_PeriodElapsedCallback I read GPIO with (GPIOC->IDR & 1) and I compose byte with each bit.