2020-02-12 10:12 PM
Hello,
I need to transfer 42 pulses (with 1 pin of a port) and read incoming bits from 1 pin of a port( such as SPI communication). As this forum member trained me I am curious to use DMA to generate 42 pulses with sending a specific value(10101...). I need to know
1)Is is possible to couple DMA with GPIO(one pin?)
2)Is there any delay between each byte(Such as SPI)?
3)Could you provide me a sample ?
2020-02-12 11:08 PM
Don't know or have code ready for STMF1xx, but in general:
1)Is is possible to couple DMA with GPIO(one pin?)
yes
2)Is there any delay between each byte(Such as SPI)?
no.
You setup a timer. The timer triggers a DMA. the DMA destination is the ODR register of a GPIO port. So, you cannot use other pins of that port for GPIO (maybe you can when using BSRR instead of ODR, didn't try that).
You have to check the reference manual for what timer event goes with what DMA channel.
Code snippets for STM32F042 using HAL:
__HAL_TIM_ENABLE_DMA(&htim3, TIM_DMA_CC3);
HAL_DMA_Start_IT( htim3.hdma[TIM_DMA_ID_CC3], (uint32_t)buffer, (uint32_t)&(GPIOA->ODR), BUFFER_LEN );
HAL_TIM_Base_Start(&htim3);
HAL_TIM_PWM_Start(&htim3,TIM_CHANNEL_3);
In this code, TIM3 CH3 was configured for PWM and DMA1 Channel 2 enabled in STMCubeIDE.
AFAIK similar topics have been discussed in the forum.
hth
KnarfB
2020-02-12 11:41 PM
Thank you KnarfB for your answer and your example. I appreciate.
Unfortunately. I have used all pins of my port so it is impossible to disable a port for just using DMA<->GPIO only for two pins.
2020-02-13 01:30 AM
1.)
uint32_t outputbuffer[] = {
0x00000020, 0x00200000,
0x00000020, 0x00200000,
0x00000020, 0x00200000,
0x00000020, 0x00200000,
0x00000020, 0x00200000,
0x00000020, 0x00200000,
/* ... */
};
Of course it's possible output on more pins of the same GPIO port, setting more bits at once.
To read a pin synchronized to the output above, you have to set up a timer channel DMA in addition to the above
2020-02-13 02:50 AM
To answer the 2nd question,
SPI should transmit without gaps if the transmit register is properly handled, but I'm not 100% sure of that.
The timer won't make any gaps, it is designed to generate equally timed periodic events. If you want to have a gap, include it in the bit pattern to be sent.
2020-02-13 01:14 PM
You still can use the other pins of that port for alternate functions (SPI,I2C,...) or GPIO when using BSRR register as described by @berendi below.
2020-02-14 04:03 AM
I really appreciate berendi your help and your complete explanation. And also KnarfB for cooperation in this question.
I got involved with the programming and I hope handle this problem by your help.
Thanks again for everything that you teach to me.